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.

252257 lines
6.3MB

  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 1
  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 1
  152. #endif
  153. #ifndef JUCE_OPENGL
  154. #define JUCE_OPENGL 1
  155. #endif
  156. #ifndef JUCE_USE_FLAC
  157. #define JUCE_USE_FLAC 1
  158. #endif
  159. #ifndef JUCE_USE_OGGVORBIS
  160. #define JUCE_USE_OGGVORBIS 1
  161. #endif
  162. #if (! defined (JUCE_USE_CDBURNER)) && ! (JUCE_WINDOWS && ! JUCE_MSVC)
  163. #define JUCE_USE_CDBURNER 1
  164. #endif
  165. #ifndef JUCE_USE_CDREADER
  166. #define JUCE_USE_CDREADER 1
  167. #endif
  168. #if JUCE_QUICKTIME && ! defined (JUCE_USE_CAMERA)
  169. // #define JUCE_USE_CAMERA 1
  170. #endif
  171. #ifndef JUCE_ENABLE_REPAINT_DEBUGGING
  172. // #define JUCE_ENABLE_REPAINT_DEBUGGING 1
  173. #endif
  174. #ifndef JUCE_USE_XINERAMA
  175. #define JUCE_USE_XINERAMA 1
  176. #endif
  177. #ifndef JUCE_USE_XSHM
  178. #define JUCE_USE_XSHM 1
  179. #endif
  180. #ifndef JUCE_PLUGINHOST_VST
  181. // #define JUCE_PLUGINHOST_VST 1
  182. #endif
  183. #ifndef JUCE_PLUGINHOST_AU
  184. // #define JUCE_PLUGINHOST_AU 1
  185. #endif
  186. #ifndef JUCE_ONLY_BUILD_CORE_LIBRARY
  187. //#define JUCE_ONLY_BUILD_CORE_LIBRARY 1
  188. #endif
  189. #ifndef JUCE_WEB_BROWSER
  190. #define JUCE_WEB_BROWSER 1
  191. #endif
  192. #ifndef JUCE_SUPPORT_CARBON
  193. #define JUCE_SUPPORT_CARBON 1
  194. #endif
  195. #ifndef JUCE_INCLUDE_ZLIB_CODE
  196. #define JUCE_INCLUDE_ZLIB_CODE 1
  197. #endif
  198. #ifndef JUCE_INCLUDE_FLAC_CODE
  199. #define JUCE_INCLUDE_FLAC_CODE 1
  200. #endif
  201. #ifndef JUCE_INCLUDE_OGGVORBIS_CODE
  202. #define JUCE_INCLUDE_OGGVORBIS_CODE 1
  203. #endif
  204. #ifndef JUCE_INCLUDE_PNGLIB_CODE
  205. #define JUCE_INCLUDE_PNGLIB_CODE 1
  206. #endif
  207. #ifndef JUCE_INCLUDE_JPEGLIB_CODE
  208. #define JUCE_INCLUDE_JPEGLIB_CODE 1
  209. #endif
  210. #ifndef JUCE_CHECK_MEMORY_LEAKS
  211. #define JUCE_CHECK_MEMORY_LEAKS 1
  212. #endif
  213. #ifndef JUCE_CATCH_UNHANDLED_EXCEPTIONS
  214. #define JUCE_CATCH_UNHANDLED_EXCEPTIONS 1
  215. #endif
  216. // If only building the core classes, we can explicitly turn off some features to avoid including them:
  217. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  218. #undef JUCE_QUICKTIME
  219. #define JUCE_QUICKTIME 0
  220. #undef JUCE_OPENGL
  221. #define JUCE_OPENGL 0
  222. #undef JUCE_USE_CDBURNER
  223. #define JUCE_USE_CDBURNER 0
  224. #undef JUCE_USE_CDREADER
  225. #define JUCE_USE_CDREADER 0
  226. #undef JUCE_WEB_BROWSER
  227. #define JUCE_WEB_BROWSER 0
  228. #undef JUCE_PLUGINHOST_AU
  229. #define JUCE_PLUGINHOST_AU 0
  230. #undef JUCE_PLUGINHOST_VST
  231. #define JUCE_PLUGINHOST_VST 0
  232. #endif
  233. #endif
  234. /*** End of inlined file: juce_Config.h ***/
  235. // FORCE_AMALGAMATOR_INCLUDE
  236. #ifndef JUCE_BUILD_CORE
  237. #define JUCE_BUILD_CORE 1
  238. #endif
  239. #ifndef JUCE_BUILD_MISC
  240. #define JUCE_BUILD_MISC 1
  241. #endif
  242. #ifndef JUCE_BUILD_GUI
  243. #define JUCE_BUILD_GUI 1
  244. #endif
  245. #ifndef JUCE_BUILD_NATIVE
  246. #define JUCE_BUILD_NATIVE 1
  247. #endif
  248. #if JUCE_ONLY_BUILD_CORE_LIBRARY
  249. #undef JUCE_BUILD_MISC
  250. #undef JUCE_BUILD_GUI
  251. #endif
  252. //==============================================================================
  253. #if JUCE_BUILD_NATIVE || JUCE_BUILD_CORE || (JUCE_BUILD_MISC && (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_AU))
  254. #if JUCE_WINDOWS
  255. /*** Start of inlined file: juce_win32_NativeIncludes.h ***/
  256. #ifndef __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  257. #define __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  258. #ifndef STRICT
  259. #define STRICT 1
  260. #endif
  261. #undef WIN32_LEAN_AND_MEAN
  262. #define WIN32_LEAN_AND_MEAN 1
  263. #ifdef _MSC_VER
  264. #pragma warning (push)
  265. #pragma warning (disable : 4100 4201 4514 4312 4995)
  266. #endif
  267. #define _WIN32_WINNT 0x0500
  268. #define _UNICODE 1
  269. #define UNICODE 1
  270. #ifndef _WIN32_IE
  271. #define _WIN32_IE 0x0400
  272. #endif
  273. #include <windows.h>
  274. #include <windowsx.h>
  275. #include <commdlg.h>
  276. #include <shellapi.h>
  277. #include <mmsystem.h>
  278. #include <vfw.h>
  279. #include <tchar.h>
  280. #include <stddef.h>
  281. #include <ctime>
  282. #include <wininet.h>
  283. #include <nb30.h>
  284. #include <iphlpapi.h>
  285. #include <mapi.h>
  286. #include <float.h>
  287. #include <process.h>
  288. #include <Exdisp.h>
  289. #include <exdispid.h>
  290. #include <shlobj.h>
  291. #if ! JUCE_MINGW
  292. #include <crtdbg.h>
  293. #include <comutil.h>
  294. #endif
  295. #if JUCE_OPENGL
  296. #include <gl/gl.h>
  297. #endif
  298. #undef PACKED
  299. #if JUCE_ASIO
  300. #include "iasiodrv.h"
  301. #endif
  302. #if JUCE_USE_CDBURNER
  303. #include <imapi.h>
  304. #include <imapierror.h>
  305. #endif
  306. #if JUCE_USE_CAMERA
  307. #include <dshow.h>
  308. #include <qedit.h>
  309. #endif
  310. #if JUCE_WASAPI
  311. #include <MMReg.h>
  312. #include <mmdeviceapi.h>
  313. #include <Audioclient.h>
  314. #include <Avrt.h>
  315. #include <functiondiscoverykeys.h>
  316. #endif
  317. #if JUCE_QUICKTIME
  318. #include <Movies.h>
  319. #include <QTML.h>
  320. #include <QuickTimeComponents.h>
  321. #include <MediaHandlers.h>
  322. #include <ImageCodec.h>
  323. #import <QTOLibrary.dll>
  324. #import <QTOControl.dll>
  325. #endif
  326. #ifdef _MSC_VER
  327. #pragma warning (pop)
  328. #endif
  329. template <class T>
  330. class ComSmartPtr
  331. {
  332. public:
  333. ComSmartPtr() throw() : p (0) {}
  334. ComSmartPtr (T* const p_) : p (p_) { if (p_ != 0) p_->AddRef(); }
  335. ComSmartPtr (const ComSmartPtr<T>& p_) : p (p_.p) { if (p != 0) p->AddRef(); }
  336. ~ComSmartPtr() { if (p != 0) p->Release(); }
  337. operator T*() const throw() { return p; }
  338. T& operator*() const throw() { return *p; }
  339. T** operator&() throw() { return &p; }
  340. T* operator->() const throw() { return p; }
  341. T* operator= (T* const newP)
  342. {
  343. if (newP != 0)
  344. newP->AddRef();
  345. if (p != 0)
  346. p->Release();
  347. p = newP;
  348. return newP;
  349. }
  350. T* operator= (const ComSmartPtr<T>& newP) { return operator= (newP.p); }
  351. HRESULT CoCreateInstance (REFCLSID rclsid, DWORD dwClsContext)
  352. {
  353. #ifndef __MINGW32__
  354. operator= (0);
  355. return ::CoCreateInstance (rclsid, 0, dwClsContext, __uuidof(T), (void**) &p);
  356. #else
  357. return S_FALSE;
  358. #endif
  359. }
  360. T* p;
  361. };
  362. #endif // __JUCE_WIN32_NATIVEINCLUDES_JUCEHEADER__
  363. /*** End of inlined file: juce_win32_NativeIncludes.h ***/
  364. #elif JUCE_LINUX
  365. /*** Start of inlined file: juce_linux_NativeIncludes.h ***/
  366. #ifndef __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  367. #define __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  368. #include <sched.h>
  369. #include <pthread.h>
  370. #include <sys/time.h>
  371. #include <errno.h>
  372. #include <sys/stat.h>
  373. #include <sys/dir.h>
  374. #include <sys/ptrace.h>
  375. #include <sys/vfs.h>
  376. #include <sys/wait.h>
  377. #include <fnmatch.h>
  378. #include <utime.h>
  379. #include <pwd.h>
  380. #include <fcntl.h>
  381. #include <dlfcn.h>
  382. #include <netdb.h>
  383. #include <arpa/inet.h>
  384. #include <netinet/in.h>
  385. #include <sys/types.h>
  386. #include <sys/ioctl.h>
  387. #include <sys/socket.h>
  388. #include <linux/if.h>
  389. #include <sys/sysinfo.h>
  390. #include <sys/file.h>
  391. #include <signal.h>
  392. #include <ft2build.h>
  393. #include FT_FREETYPE_H
  394. #include <X11/Xlib.h>
  395. #include <X11/Xatom.h>
  396. #include <X11/Xresource.h>
  397. #include <X11/Xutil.h>
  398. #include <X11/Xmd.h>
  399. #include <X11/keysym.h>
  400. #include <X11/cursorfont.h>
  401. #if JUCE_USE_XINERAMA
  402. #include <X11/extensions/Xinerama.h>
  403. #endif
  404. #if JUCE_USE_XSHM
  405. #include <X11/extensions/XShm.h>
  406. #include <sys/shm.h>
  407. #include <sys/ipc.h>
  408. #endif
  409. #if JUCE_OPENGL
  410. #include <GL/glx.h>
  411. #endif
  412. #undef KeyPress
  413. #if JUCE_ALSA
  414. #include <alsa/asoundlib.h>
  415. #endif
  416. #if JUCE_JACK
  417. #include <jack/jack.h>
  418. //#include <jack/transport.h>
  419. #endif
  420. #undef SIZEOF
  421. #endif // __JUCE_LINUX_NATIVEINCLUDES_JUCEHEADER__
  422. /*** End of inlined file: juce_linux_NativeIncludes.h ***/
  423. #elif JUCE_MAC || JUCE_IPHONE
  424. /*** Start of inlined file: juce_mac_NativeIncludes.h ***/
  425. #ifndef __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  426. #define __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  427. #define USE_COREGRAPHICS_RENDERING 1
  428. #if JUCE_IPHONE
  429. #import <Foundation/Foundation.h>
  430. #import <UIKit/UIKit.h>
  431. #import <AudioToolbox/AudioToolbox.h>
  432. #import <AVFoundation/AVFoundation.h>
  433. #import <CoreData/CoreData.h>
  434. #import <MobileCoreServices/MobileCoreServices.h>
  435. #include <sys/fcntl.h>
  436. #else
  437. #import <Cocoa/Cocoa.h>
  438. #import <CoreAudio/HostTime.h>
  439. #import <CoreAudio/AudioHardware.h>
  440. #import <CoreMIDI/MIDIServices.h>
  441. #import <QTKit/QTKit.h>
  442. #import <WebKit/WebKit.h>
  443. #import <DiscRecording/DiscRecording.h>
  444. #import <IOKit/IOKitLib.h>
  445. #import <IOKit/IOCFPlugIn.h>
  446. #import <IOKit/hid/IOHIDLib.h>
  447. #import <IOKit/hid/IOHIDKeys.h>
  448. #import <IOKit/pwr_mgt/IOPMLib.h>
  449. #include <Carbon/Carbon.h>
  450. #include <sys/dir.h>
  451. #include <sys/socket.h>
  452. #endif
  453. #include <sys/sysctl.h>
  454. #include <sys/stat.h>
  455. #include <sys/param.h>
  456. #include <sys/mount.h>
  457. #include <fnmatch.h>
  458. #include <utime.h>
  459. #include <dlfcn.h>
  460. #include <ifaddrs.h>
  461. #include <net/if_dl.h>
  462. #include <mach/mach_time.h>
  463. #if MACOS_10_4_OR_EARLIER
  464. #include <GLUT/glut.h>
  465. #endif
  466. #if ! CGFLOAT_DEFINED
  467. #define CGFloat float
  468. #endif
  469. #endif // __JUCE_MAC_NATIVEINCLUDES_JUCEHEADER__
  470. /*** End of inlined file: juce_mac_NativeIncludes.h ***/
  471. #else
  472. #error "Unknown platform!"
  473. #endif
  474. #endif
  475. //==============================================================================
  476. #define DONT_SET_USING_JUCE_NAMESPACE 1
  477. #undef max
  478. #undef min
  479. #define NO_DUMMY_DECL
  480. #if JUCE_BUILD_NATIVE
  481. #include "juce_amalgamated.h" // FORCE_AMALGAMATOR_INCLUDE
  482. #endif
  483. #if (defined(_MSC_VER) && (_MSC_VER <= 1200))
  484. #pragma warning (disable: 4309 4305)
  485. #endif
  486. #if JUCE_MAC && JUCE_32BIT && JUCE_SUPPORT_CARBON && JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  487. BEGIN_JUCE_NAMESPACE
  488. /*** Start of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  489. #ifndef __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  490. #define __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  491. class CarbonViewWrapperComponent : public Component,
  492. public ComponentMovementWatcher,
  493. public Timer
  494. {
  495. public:
  496. CarbonViewWrapperComponent()
  497. : ComponentMovementWatcher (this),
  498. wrapperWindow (0),
  499. embeddedView (0),
  500. recursiveResize (false)
  501. {
  502. }
  503. virtual ~CarbonViewWrapperComponent()
  504. {
  505. jassert (embeddedView == 0); // must call deleteWindow() in the subclass's destructor!
  506. }
  507. virtual HIViewRef attachView (WindowRef windowRef, HIViewRef rootView) = 0;
  508. virtual void removeView (HIViewRef embeddedView) = 0;
  509. virtual void mouseDown (int x, int y) {}
  510. virtual void paint() {}
  511. virtual bool getEmbeddedViewSize (int& w, int& h)
  512. {
  513. if (embeddedView == 0)
  514. return false;
  515. HIRect bounds;
  516. HIViewGetBounds (embeddedView, &bounds);
  517. w = jmax (1, roundToInt (bounds.size.width));
  518. h = jmax (1, roundToInt (bounds.size.height));
  519. return true;
  520. }
  521. void createWindow()
  522. {
  523. if (wrapperWindow == 0)
  524. {
  525. Rect r;
  526. r.left = getScreenX();
  527. r.top = getScreenY();
  528. r.right = r.left + getWidth();
  529. r.bottom = r.top + getHeight();
  530. CreateNewWindow (kDocumentWindowClass,
  531. (WindowAttributes) (kWindowStandardHandlerAttribute | kWindowCompositingAttribute
  532. | kWindowNoShadowAttribute | kWindowNoTitleBarAttribute),
  533. &r, &wrapperWindow);
  534. jassert (wrapperWindow != 0);
  535. if (wrapperWindow == 0)
  536. return;
  537. NSWindow* carbonWindow = [[NSWindow alloc] initWithWindowRef: wrapperWindow];
  538. NSWindow* ownerWindow = [((NSView*) getWindowHandle()) window];
  539. [ownerWindow addChildWindow: carbonWindow
  540. ordered: NSWindowAbove];
  541. embeddedView = attachView (wrapperWindow, HIViewGetRoot (wrapperWindow));
  542. EventTypeSpec windowEventTypes[] = { { kEventClassWindow, kEventWindowGetClickActivation },
  543. { kEventClassWindow, kEventWindowHandleDeactivate } };
  544. EventHandlerUPP upp = NewEventHandlerUPP (carbonEventCallback);
  545. InstallWindowEventHandler (wrapperWindow, upp,
  546. sizeof (windowEventTypes) / sizeof (EventTypeSpec),
  547. windowEventTypes, this, &eventHandlerRef);
  548. setOurSizeToEmbeddedViewSize();
  549. setEmbeddedWindowToOurSize();
  550. creationTime = Time::getCurrentTime();
  551. }
  552. }
  553. void deleteWindow()
  554. {
  555. removeView (embeddedView);
  556. embeddedView = 0;
  557. if (wrapperWindow != 0)
  558. {
  559. RemoveEventHandler (eventHandlerRef);
  560. DisposeWindow (wrapperWindow);
  561. wrapperWindow = 0;
  562. }
  563. }
  564. void setOurSizeToEmbeddedViewSize()
  565. {
  566. int w, h;
  567. if (getEmbeddedViewSize (w, h))
  568. {
  569. if (w != getWidth() || h != getHeight())
  570. {
  571. startTimer (50);
  572. setSize (w, h);
  573. if (getParentComponent() != 0)
  574. getParentComponent()->setSize (w, h);
  575. }
  576. else
  577. {
  578. startTimer (jlimit (50, 500, getTimerInterval() + 20));
  579. }
  580. }
  581. else
  582. {
  583. stopTimer();
  584. }
  585. }
  586. void setEmbeddedWindowToOurSize()
  587. {
  588. if (! recursiveResize)
  589. {
  590. recursiveResize = true;
  591. if (embeddedView != 0)
  592. {
  593. HIRect r;
  594. r.origin.x = 0;
  595. r.origin.y = 0;
  596. r.size.width = (float) getWidth();
  597. r.size.height = (float) getHeight();
  598. HIViewSetFrame (embeddedView, &r);
  599. }
  600. if (wrapperWindow != 0)
  601. {
  602. Rect wr;
  603. wr.left = getScreenX();
  604. wr.top = getScreenY();
  605. wr.right = wr.left + getWidth();
  606. wr.bottom = wr.top + getHeight();
  607. SetWindowBounds (wrapperWindow, kWindowContentRgn, &wr);
  608. ShowWindow (wrapperWindow);
  609. }
  610. recursiveResize = false;
  611. }
  612. }
  613. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  614. {
  615. setEmbeddedWindowToOurSize();
  616. }
  617. void componentPeerChanged()
  618. {
  619. deleteWindow();
  620. createWindow();
  621. }
  622. void componentVisibilityChanged (Component&)
  623. {
  624. if (isShowing())
  625. createWindow();
  626. else
  627. deleteWindow();
  628. setEmbeddedWindowToOurSize();
  629. }
  630. static void recursiveHIViewRepaint (HIViewRef view)
  631. {
  632. HIViewSetNeedsDisplay (view, true);
  633. HIViewRef child = HIViewGetFirstSubview (view);
  634. while (child != 0)
  635. {
  636. recursiveHIViewRepaint (child);
  637. child = HIViewGetNextView (child);
  638. }
  639. }
  640. void timerCallback()
  641. {
  642. setOurSizeToEmbeddedViewSize();
  643. // To avoid strange overpainting problems when the UI is first opened, we'll
  644. // repaint it a few times during the first second that it's on-screen..
  645. if ((Time::getCurrentTime() - creationTime).inMilliseconds() < 1000)
  646. recursiveHIViewRepaint (HIViewGetRoot (wrapperWindow));
  647. }
  648. OSStatus carbonEventHandler (EventHandlerCallRef nextHandlerRef,
  649. EventRef event)
  650. {
  651. switch (GetEventKind (event))
  652. {
  653. case kEventWindowHandleDeactivate:
  654. ActivateWindow (wrapperWindow, TRUE);
  655. break;
  656. case kEventWindowGetClickActivation:
  657. {
  658. getTopLevelComponent()->toFront (false);
  659. ClickActivationResult howToHandleClick = kActivateAndHandleClick;
  660. SetEventParameter (event, kEventParamClickActivation, typeClickActivationResult,
  661. sizeof (ClickActivationResult), &howToHandleClick);
  662. HIViewSetNeedsDisplay (embeddedView, true);
  663. }
  664. break;
  665. }
  666. return noErr;
  667. }
  668. static pascal OSStatus carbonEventCallback (EventHandlerCallRef nextHandlerRef,
  669. EventRef event, void* userData)
  670. {
  671. return ((CarbonViewWrapperComponent*) userData)->carbonEventHandler (nextHandlerRef, event);
  672. }
  673. protected:
  674. WindowRef wrapperWindow;
  675. HIViewRef embeddedView;
  676. bool recursiveResize;
  677. Time creationTime;
  678. EventHandlerRef eventHandlerRef;
  679. };
  680. #endif // __JUCE_MAC_CARBONVIEWWRAPPERCOMPONENT_JUCEHEADER__
  681. /*** End of inlined file: juce_mac_CarbonViewWrapperComponent.h ***/
  682. END_JUCE_NAMESPACE
  683. #endif
  684. #define JUCE_AMALGAMATED_TEMPLATE 1
  685. //==============================================================================
  686. #if JUCE_BUILD_CORE
  687. /*** Start of inlined file: juce_FileLogger.cpp ***/
  688. BEGIN_JUCE_NAMESPACE
  689. FileLogger::FileLogger (const File& logFile_,
  690. const String& welcomeMessage,
  691. const int maxInitialFileSizeBytes)
  692. : logFile (logFile_)
  693. {
  694. if (maxInitialFileSizeBytes >= 0)
  695. trimFileSize (maxInitialFileSizeBytes);
  696. if (! logFile_.exists())
  697. {
  698. // do this so that the parent directories get created..
  699. logFile_.create();
  700. }
  701. logStream = logFile_.createOutputStream (256);
  702. jassert (logStream != 0);
  703. String welcome;
  704. welcome << "\r\n**********************************************************\r\n"
  705. << welcomeMessage
  706. << "\r\nLog started: " << Time::getCurrentTime().toString (true, true)
  707. << "\r\n";
  708. logMessage (welcome);
  709. }
  710. FileLogger::~FileLogger()
  711. {
  712. }
  713. void FileLogger::logMessage (const String& message)
  714. {
  715. if (logStream != 0)
  716. {
  717. DBG (message);
  718. const ScopedLock sl (logLock);
  719. (*logStream) << message << T("\r\n");
  720. logStream->flush();
  721. }
  722. }
  723. void FileLogger::trimFileSize (int maxFileSizeBytes) const
  724. {
  725. if (maxFileSizeBytes <= 0)
  726. {
  727. logFile.deleteFile();
  728. }
  729. else
  730. {
  731. const int64 fileSize = logFile.getSize();
  732. if (fileSize > maxFileSizeBytes)
  733. {
  734. ScopedPointer <FileInputStream> in (logFile.createInputStream());
  735. jassert (in != 0);
  736. if (in != 0)
  737. {
  738. in->setPosition (fileSize - maxFileSizeBytes);
  739. String content;
  740. {
  741. MemoryBlock contentToSave;
  742. contentToSave.setSize (maxFileSizeBytes + 4);
  743. contentToSave.fillWith (0);
  744. in->read (contentToSave.getData(), maxFileSizeBytes);
  745. in = 0;
  746. content = contentToSave.toString();
  747. }
  748. int newStart = 0;
  749. while (newStart < fileSize
  750. && content[newStart] != '\n'
  751. && content[newStart] != '\r')
  752. ++newStart;
  753. logFile.deleteFile();
  754. logFile.appendText (content.substring (newStart), false, false);
  755. }
  756. }
  757. }
  758. }
  759. FileLogger* FileLogger::createDefaultAppLogger (const String& logFileSubDirectoryName,
  760. const String& logFileName,
  761. const String& welcomeMessage,
  762. const int maxInitialFileSizeBytes)
  763. {
  764. #if JUCE_MAC
  765. File logFile ("~/Library/Logs");
  766. logFile = logFile.getChildFile (logFileSubDirectoryName)
  767. .getChildFile (logFileName);
  768. #else
  769. File logFile (File::getSpecialLocation (File::userApplicationDataDirectory));
  770. if (logFile.isDirectory())
  771. {
  772. logFile = logFile.getChildFile (logFileSubDirectoryName)
  773. .getChildFile (logFileName);
  774. }
  775. #endif
  776. return new FileLogger (logFile, welcomeMessage, maxInitialFileSizeBytes);
  777. }
  778. END_JUCE_NAMESPACE
  779. /*** End of inlined file: juce_FileLogger.cpp ***/
  780. /*** Start of inlined file: juce_Logger.cpp ***/
  781. BEGIN_JUCE_NAMESPACE
  782. Logger::Logger()
  783. {
  784. }
  785. Logger::~Logger()
  786. {
  787. }
  788. static Logger* currentLogger = 0;
  789. void Logger::setCurrentLogger (Logger* const newLogger,
  790. const bool deleteOldLogger)
  791. {
  792. Logger* const oldLogger = currentLogger;
  793. currentLogger = newLogger;
  794. if (deleteOldLogger)
  795. delete oldLogger;
  796. }
  797. void Logger::writeToLog (const String& message)
  798. {
  799. if (currentLogger != 0)
  800. currentLogger->logMessage (message);
  801. else
  802. outputDebugString (message);
  803. }
  804. #if JUCE_LOG_ASSERTIONS
  805. void JUCE_API juce_LogAssertion (const char* filename, const int lineNum) throw()
  806. {
  807. String m ("JUCE Assertion failure in ");
  808. m << filename << ", line " << lineNum;
  809. Logger::writeToLog (m);
  810. }
  811. #endif
  812. END_JUCE_NAMESPACE
  813. /*** End of inlined file: juce_Logger.cpp ***/
  814. /*** Start of inlined file: juce_Random.cpp ***/
  815. BEGIN_JUCE_NAMESPACE
  816. Random::Random (const int64 seedValue) throw()
  817. : seed (seedValue)
  818. {
  819. }
  820. Random::~Random() throw()
  821. {
  822. }
  823. void Random::setSeed (const int64 newSeed) throw()
  824. {
  825. seed = newSeed;
  826. }
  827. void Random::combineSeed (const int64 seedValue) throw()
  828. {
  829. seed ^= nextInt64() ^ seedValue;
  830. }
  831. void Random::setSeedRandomly()
  832. {
  833. combineSeed ((int64) (pointer_sized_int) this);
  834. combineSeed (Time::getMillisecondCounter());
  835. combineSeed (Time::getHighResolutionTicks());
  836. combineSeed (Time::getHighResolutionTicksPerSecond());
  837. combineSeed (Time::currentTimeMillis());
  838. }
  839. int Random::nextInt() throw()
  840. {
  841. seed = (seed * literal64bit (0x5deece66d) + 11) & literal64bit (0xffffffffffff);
  842. return (int) (seed >> 16);
  843. }
  844. int Random::nextInt (const int maxValue) throw()
  845. {
  846. jassert (maxValue > 0);
  847. return (nextInt() & 0x7fffffff) % maxValue;
  848. }
  849. int64 Random::nextInt64() throw()
  850. {
  851. return (((int64) nextInt()) << 32) | (int64) (uint64) (uint32) nextInt();
  852. }
  853. bool Random::nextBool() throw()
  854. {
  855. return (nextInt() & 0x80000000) != 0;
  856. }
  857. float Random::nextFloat() throw()
  858. {
  859. return ((uint32) nextInt()) / (float) 0xffffffff;
  860. }
  861. double Random::nextDouble() throw()
  862. {
  863. return ((uint32) nextInt()) / (double) 0xffffffff;
  864. }
  865. const BitArray Random::nextLargeNumber (const BitArray& maximumValue) throw()
  866. {
  867. BitArray n;
  868. do
  869. {
  870. fillBitsRandomly (n, 0, maximumValue.getHighestBit() + 1);
  871. }
  872. while (n.compare (maximumValue) >= 0);
  873. return n;
  874. }
  875. void Random::fillBitsRandomly (BitArray& arrayToChange, int startBit, int numBits) throw()
  876. {
  877. arrayToChange.setBit (startBit + numBits - 1, true); // to force the array to pre-allocate space
  878. while ((startBit & 31) != 0 && numBits > 0)
  879. {
  880. arrayToChange.setBit (startBit++, nextBool());
  881. --numBits;
  882. }
  883. while (numBits >= 32)
  884. {
  885. arrayToChange.setBitRangeAsInt (startBit, 32, (unsigned int) nextInt());
  886. startBit += 32;
  887. numBits -= 32;
  888. }
  889. while (--numBits >= 0)
  890. arrayToChange.setBit (startBit + numBits, nextBool());
  891. }
  892. Random& Random::getSystemRandom() throw()
  893. {
  894. static Random sysRand (1);
  895. return sysRand;
  896. }
  897. END_JUCE_NAMESPACE
  898. /*** End of inlined file: juce_Random.cpp ***/
  899. /*** Start of inlined file: juce_RelativeTime.cpp ***/
  900. BEGIN_JUCE_NAMESPACE
  901. RelativeTime::RelativeTime (const double seconds_) throw()
  902. : seconds (seconds_)
  903. {
  904. }
  905. RelativeTime::RelativeTime (const RelativeTime& other) throw()
  906. : seconds (other.seconds)
  907. {
  908. }
  909. RelativeTime::~RelativeTime() throw()
  910. {
  911. }
  912. const RelativeTime RelativeTime::milliseconds (const int milliseconds) throw()
  913. {
  914. return RelativeTime (milliseconds * 0.001);
  915. }
  916. const RelativeTime RelativeTime::milliseconds (const int64 milliseconds) throw()
  917. {
  918. return RelativeTime (milliseconds * 0.001);
  919. }
  920. const RelativeTime RelativeTime::minutes (const double numberOfMinutes) throw()
  921. {
  922. return RelativeTime (numberOfMinutes * 60.0);
  923. }
  924. const RelativeTime RelativeTime::hours (const double numberOfHours) throw()
  925. {
  926. return RelativeTime (numberOfHours * (60.0 * 60.0));
  927. }
  928. const RelativeTime RelativeTime::days (const double numberOfDays) throw()
  929. {
  930. return RelativeTime (numberOfDays * (60.0 * 60.0 * 24.0));
  931. }
  932. const RelativeTime RelativeTime::weeks (const double numberOfWeeks) throw()
  933. {
  934. return RelativeTime (numberOfWeeks * (60.0 * 60.0 * 24.0 * 7.0));
  935. }
  936. int64 RelativeTime::inMilliseconds() const throw()
  937. {
  938. return (int64)(seconds * 1000.0);
  939. }
  940. double RelativeTime::inMinutes() const throw()
  941. {
  942. return seconds / 60.0;
  943. }
  944. double RelativeTime::inHours() const throw()
  945. {
  946. return seconds / (60.0 * 60.0);
  947. }
  948. double RelativeTime::inDays() const throw()
  949. {
  950. return seconds / (60.0 * 60.0 * 24.0);
  951. }
  952. double RelativeTime::inWeeks() const throw()
  953. {
  954. return seconds / (60.0 * 60.0 * 24.0 * 7.0);
  955. }
  956. const String RelativeTime::getDescription (const String& returnValueForZeroTime) const throw()
  957. {
  958. if (seconds < 0.001 && seconds > -0.001)
  959. return returnValueForZeroTime;
  960. String result;
  961. if (seconds < 0)
  962. result = T("-");
  963. int fieldsShown = 0;
  964. int n = abs ((int) inWeeks());
  965. if (n > 0)
  966. {
  967. result << n << ((n == 1) ? TRANS(" week ")
  968. : TRANS(" weeks "));
  969. ++fieldsShown;
  970. }
  971. n = abs ((int) inDays()) % 7;
  972. if (n > 0)
  973. {
  974. result << n << ((n == 1) ? TRANS(" day ")
  975. : TRANS(" days "));
  976. ++fieldsShown;
  977. }
  978. if (fieldsShown < 2)
  979. {
  980. n = abs ((int) inHours()) % 24;
  981. if (n > 0)
  982. {
  983. result << n << ((n == 1) ? TRANS(" hr ")
  984. : TRANS(" hrs "));
  985. ++fieldsShown;
  986. }
  987. if (fieldsShown < 2)
  988. {
  989. n = abs ((int) inMinutes()) % 60;
  990. if (n > 0)
  991. {
  992. result << n << ((n == 1) ? TRANS(" min ")
  993. : TRANS(" mins "));
  994. ++fieldsShown;
  995. }
  996. if (fieldsShown < 2)
  997. {
  998. n = abs ((int) inSeconds()) % 60;
  999. if (n > 0)
  1000. {
  1001. result << n << ((n == 1) ? TRANS(" sec ")
  1002. : TRANS(" secs "));
  1003. ++fieldsShown;
  1004. }
  1005. if (fieldsShown < 1)
  1006. {
  1007. n = abs ((int) inMilliseconds()) % 1000;
  1008. if (n > 0)
  1009. {
  1010. result << n << TRANS(" ms");
  1011. ++fieldsShown;
  1012. }
  1013. }
  1014. }
  1015. }
  1016. }
  1017. return result.trimEnd();
  1018. }
  1019. RelativeTime& RelativeTime::operator= (const RelativeTime& other) throw()
  1020. {
  1021. seconds = other.seconds;
  1022. return *this;
  1023. }
  1024. bool RelativeTime::operator== (const RelativeTime& other) const throw()
  1025. {
  1026. return seconds == other.seconds;
  1027. }
  1028. bool RelativeTime::operator!= (const RelativeTime& other) const throw()
  1029. {
  1030. return seconds != other.seconds;
  1031. }
  1032. bool RelativeTime::operator> (const RelativeTime& other) const throw()
  1033. {
  1034. return seconds > other.seconds;
  1035. }
  1036. bool RelativeTime::operator< (const RelativeTime& other) const throw()
  1037. {
  1038. return seconds < other.seconds;
  1039. }
  1040. bool RelativeTime::operator>= (const RelativeTime& other) const throw()
  1041. {
  1042. return seconds >= other.seconds;
  1043. }
  1044. bool RelativeTime::operator<= (const RelativeTime& other) const throw()
  1045. {
  1046. return seconds <= other.seconds;
  1047. }
  1048. const RelativeTime RelativeTime::operator+ (const RelativeTime& timeToAdd) const throw()
  1049. {
  1050. return RelativeTime (seconds + timeToAdd.seconds);
  1051. }
  1052. const RelativeTime RelativeTime::operator- (const RelativeTime& timeToSubtract) const throw()
  1053. {
  1054. return RelativeTime (seconds - timeToSubtract.seconds);
  1055. }
  1056. const RelativeTime RelativeTime::operator+ (const double secondsToAdd) const throw()
  1057. {
  1058. return RelativeTime (seconds + secondsToAdd);
  1059. }
  1060. const RelativeTime RelativeTime::operator- (const double secondsToSubtract) const throw()
  1061. {
  1062. return RelativeTime (seconds - secondsToSubtract);
  1063. }
  1064. const RelativeTime& RelativeTime::operator+= (const RelativeTime& timeToAdd) throw()
  1065. {
  1066. seconds += timeToAdd.seconds;
  1067. return *this;
  1068. }
  1069. const RelativeTime& RelativeTime::operator-= (const RelativeTime& timeToSubtract) throw()
  1070. {
  1071. seconds -= timeToSubtract.seconds;
  1072. return *this;
  1073. }
  1074. const RelativeTime& RelativeTime::operator+= (const double secondsToAdd) throw()
  1075. {
  1076. seconds += secondsToAdd;
  1077. return *this;
  1078. }
  1079. const RelativeTime& RelativeTime::operator-= (const double secondsToSubtract) throw()
  1080. {
  1081. seconds -= secondsToSubtract;
  1082. return *this;
  1083. }
  1084. END_JUCE_NAMESPACE
  1085. /*** End of inlined file: juce_RelativeTime.cpp ***/
  1086. /*** Start of inlined file: juce_SystemStats.cpp ***/
  1087. BEGIN_JUCE_NAMESPACE
  1088. void juce_initialiseStrings();
  1089. const String SystemStats::getJUCEVersion() throw()
  1090. {
  1091. return "JUCE v" + String (JUCE_MAJOR_VERSION)
  1092. + "." + String (JUCE_MINOR_VERSION)
  1093. + "." + String (JUCE_BUILDNUMBER);
  1094. }
  1095. static bool juceInitialisedNonGUI = false;
  1096. void JUCE_PUBLIC_FUNCTION initialiseJuce_NonGUI()
  1097. {
  1098. if (! juceInitialisedNonGUI)
  1099. {
  1100. #if JUCE_MAC || JUCE_IPHONE
  1101. const ScopedAutoReleasePool pool;
  1102. #endif
  1103. #ifdef JUCE_DEBUG
  1104. {
  1105. // Some simple test code to keep an eye on things and make sure these functions
  1106. // work ok on all platforms. Let me know if any of these assertions fail!
  1107. static_jassert (sizeof (pointer_sized_int) == sizeof (void*));
  1108. char a1[7];
  1109. jassert (numElementsInArray(a1) == 7);
  1110. int a2[3];
  1111. jassert (numElementsInArray(a2) == 3);
  1112. int n = 1;
  1113. Atomic::increment (n);
  1114. jassert (Atomic::incrementAndReturn (n) == 3);
  1115. Atomic::decrement (n);
  1116. jassert (Atomic::decrementAndReturn (n) == 1);
  1117. jassert (ByteOrder::swap ((uint16) 0x1122) == 0x2211);
  1118. jassert (ByteOrder::swap ((uint32) 0x11223344) == 0x44332211);
  1119. // Some quick stream tests..
  1120. int randomInt = Random::getSystemRandom().nextInt();
  1121. int64 randomInt64 = Random::getSystemRandom().nextInt64();
  1122. double randomDouble = Random::getSystemRandom().nextDouble();
  1123. String randomString;
  1124. for (int i = 50; --i >= 0;)
  1125. randomString << (juce_wchar) (Random::getSystemRandom().nextInt() & 0xffff);
  1126. MemoryOutputStream mo;
  1127. mo.writeInt (randomInt);
  1128. mo.writeIntBigEndian (randomInt);
  1129. mo.writeCompressedInt (randomInt);
  1130. mo.writeString (randomString);
  1131. mo.writeInt64 (randomInt64);
  1132. mo.writeInt64BigEndian (randomInt64);
  1133. mo.writeDouble (randomDouble);
  1134. mo.writeDoubleBigEndian (randomDouble);
  1135. MemoryInputStream mi (mo.getData(), mo.getDataSize(), false);
  1136. jassert (mi.readInt() == randomInt);
  1137. jassert (mi.readIntBigEndian() == randomInt);
  1138. jassert (mi.readCompressedInt() == randomInt);
  1139. jassert (mi.readString() == randomString);
  1140. jassert (mi.readInt64() == randomInt64);
  1141. jassert (mi.readInt64BigEndian() == randomInt64);
  1142. jassert (mi.readDouble() == randomDouble);
  1143. jassert (mi.readDoubleBigEndian() == randomDouble);
  1144. }
  1145. #endif
  1146. // Now the real initialisation..
  1147. juceInitialisedNonGUI = true;
  1148. DBG (SystemStats::getJUCEVersion());
  1149. juce_initialiseStrings();
  1150. SystemStats::initialiseStats();
  1151. Random::getSystemRandom().setSeedRandomly(); // (mustn't call this before initialiseStats() because it relies on the time being set up)
  1152. }
  1153. }
  1154. #if JUCE_WINDOWS
  1155. // This is imported from the sockets code..
  1156. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  1157. extern juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib;
  1158. #endif
  1159. #if JUCE_DEBUG
  1160. extern void juce_CheckForDanglingStreams();
  1161. #endif
  1162. void JUCE_PUBLIC_FUNCTION shutdownJuce_NonGUI()
  1163. {
  1164. if (juceInitialisedNonGUI)
  1165. {
  1166. #if JUCE_MAC || JUCE_IPHONE
  1167. const ScopedAutoReleasePool pool;
  1168. #endif
  1169. #if JUCE_WINDOWS
  1170. // need to shut down sockets if they were used..
  1171. if (juce_CloseWin32SocketLib != 0)
  1172. (*juce_CloseWin32SocketLib)();
  1173. #endif
  1174. LocalisedStrings::setCurrentMappings (0);
  1175. Thread::stopAllThreads (3000);
  1176. #if JUCE_DEBUG
  1177. juce_CheckForDanglingStreams();
  1178. #endif
  1179. juceInitialisedNonGUI = false;
  1180. }
  1181. }
  1182. #ifdef JUCE_DLL
  1183. void* juce_Malloc (const int size)
  1184. {
  1185. return malloc (size);
  1186. }
  1187. void* juce_Calloc (const int size)
  1188. {
  1189. return calloc (1, size);
  1190. }
  1191. void* juce_Realloc (void* const block, const int size)
  1192. {
  1193. return realloc (block, size);
  1194. }
  1195. void juce_Free (void* const block)
  1196. {
  1197. free (block);
  1198. }
  1199. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  1200. void* juce_DebugMalloc (const int size, const char* file, const int line)
  1201. {
  1202. return _malloc_dbg (size, _NORMAL_BLOCK, file, line);
  1203. }
  1204. void* juce_DebugCalloc (const int size, const char* file, const int line)
  1205. {
  1206. return _calloc_dbg (1, size, _NORMAL_BLOCK, file, line);
  1207. }
  1208. void* juce_DebugRealloc (void* const block, const int size, const char* file, const int line)
  1209. {
  1210. return _realloc_dbg (block, size, _NORMAL_BLOCK, file, line);
  1211. }
  1212. void juce_DebugFree (void* const block)
  1213. {
  1214. _free_dbg (block, _NORMAL_BLOCK);
  1215. }
  1216. #endif
  1217. #endif
  1218. END_JUCE_NAMESPACE
  1219. /*** End of inlined file: juce_SystemStats.cpp ***/
  1220. /*** Start of inlined file: juce_Time.cpp ***/
  1221. #ifdef _MSC_VER
  1222. #pragma warning (disable: 4514)
  1223. #pragma warning (push)
  1224. #endif
  1225. #ifndef JUCE_WINDOWS
  1226. #include <sys/time.h>
  1227. #else
  1228. #include <ctime>
  1229. #endif
  1230. #include <sys/timeb.h>
  1231. BEGIN_JUCE_NAMESPACE
  1232. #ifdef _MSC_VER
  1233. #pragma warning (pop)
  1234. #ifdef _INC_TIME_INL
  1235. #define USE_NEW_SECURE_TIME_FNS
  1236. #endif
  1237. #endif
  1238. static void millisToLocal (const int64 millis, struct tm& result) throw()
  1239. {
  1240. const int64 seconds = millis / 1000;
  1241. if (seconds < literal64bit (86400) || seconds >= literal64bit (2145916800))
  1242. {
  1243. // use extended maths for dates beyond 1970 to 2037..
  1244. const int timeZoneAdjustment = 31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000);
  1245. const int64 jdm = seconds + timeZoneAdjustment + literal64bit (210866803200);
  1246. const int days = (int) (jdm / literal64bit (86400));
  1247. const int a = 32044 + days;
  1248. const int b = (4 * a + 3) / 146097;
  1249. const int c = a - (b * 146097) / 4;
  1250. const int d = (4 * c + 3) / 1461;
  1251. const int e = c - (d * 1461) / 4;
  1252. const int m = (5 * e + 2) / 153;
  1253. result.tm_mday = e - (153 * m + 2) / 5 + 1;
  1254. result.tm_mon = m + 2 - 12 * (m / 10);
  1255. result.tm_year = b * 100 + d - 6700 + (m / 10);
  1256. result.tm_wday = (days + 1) % 7;
  1257. result.tm_yday = -1;
  1258. int t = (int) (jdm % literal64bit (86400));
  1259. result.tm_hour = t / 3600;
  1260. t %= 3600;
  1261. result.tm_min = t / 60;
  1262. result.tm_sec = t % 60;
  1263. result.tm_isdst = -1;
  1264. }
  1265. else
  1266. {
  1267. time_t now = (time_t) (seconds);
  1268. #if JUCE_WINDOWS
  1269. #ifdef USE_NEW_SECURE_TIME_FNS
  1270. if (now >= 0 && now <= 0x793406fff)
  1271. localtime_s (&result, &now);
  1272. else
  1273. zeromem (&result, sizeof (result));
  1274. #else
  1275. result = *localtime (&now);
  1276. #endif
  1277. #else
  1278. // more thread-safe
  1279. localtime_r (&now, &result);
  1280. #endif
  1281. }
  1282. }
  1283. Time::Time() throw()
  1284. : millisSinceEpoch (0)
  1285. {
  1286. }
  1287. Time::Time (const Time& other) throw()
  1288. : millisSinceEpoch (other.millisSinceEpoch)
  1289. {
  1290. }
  1291. Time::Time (const int64 ms) throw()
  1292. : millisSinceEpoch (ms)
  1293. {
  1294. }
  1295. Time::Time (const int year,
  1296. const int month,
  1297. const int day,
  1298. const int hours,
  1299. const int minutes,
  1300. const int seconds,
  1301. const int milliseconds,
  1302. const bool useLocalTime) throw()
  1303. {
  1304. jassert (year > 100); // year must be a 4-digit version
  1305. if (year < 1971 || year >= 2038 || ! useLocalTime)
  1306. {
  1307. // use extended maths for dates beyond 1970 to 2037..
  1308. const int timeZoneAdjustment = useLocalTime ? (31536000 - (int) (Time (1971, 0, 1, 0, 0).toMilliseconds() / 1000))
  1309. : 0;
  1310. const int a = (13 - month) / 12;
  1311. const int y = year + 4800 - a;
  1312. const int jd = day + (153 * (month + 12 * a - 2) + 2) / 5
  1313. + (y * 365) + (y / 4) - (y / 100) + (y / 400)
  1314. - 32045;
  1315. const int64 s = ((int64) jd) * literal64bit (86400) - literal64bit (210866803200);
  1316. millisSinceEpoch = 1000 * (s + (hours * 3600 + minutes * 60 + seconds - timeZoneAdjustment))
  1317. + milliseconds;
  1318. }
  1319. else
  1320. {
  1321. struct tm t;
  1322. t.tm_year = year - 1900;
  1323. t.tm_mon = month;
  1324. t.tm_mday = day;
  1325. t.tm_hour = hours;
  1326. t.tm_min = minutes;
  1327. t.tm_sec = seconds;
  1328. t.tm_isdst = -1;
  1329. millisSinceEpoch = 1000 * (int64) mktime (&t);
  1330. if (millisSinceEpoch < 0)
  1331. millisSinceEpoch = 0;
  1332. else
  1333. millisSinceEpoch += milliseconds;
  1334. }
  1335. }
  1336. Time::~Time() throw()
  1337. {
  1338. }
  1339. Time& Time::operator= (const Time& other) throw()
  1340. {
  1341. millisSinceEpoch = other.millisSinceEpoch;
  1342. return *this;
  1343. }
  1344. int64 Time::currentTimeMillis() throw()
  1345. {
  1346. static uint32 lastCounterResult = 0xffffffff;
  1347. static int64 correction = 0;
  1348. const uint32 now = getMillisecondCounter();
  1349. // check the counter hasn't wrapped (also triggered the first time this function is called)
  1350. if (now < lastCounterResult)
  1351. {
  1352. // double-check it's actually wrapped, in case multi-cpu machines have timers that drift a bit.
  1353. if (lastCounterResult == 0xffffffff || now < lastCounterResult - 10)
  1354. {
  1355. // get the time once using normal library calls, and store the difference needed to
  1356. // turn the millisecond counter into a real time.
  1357. #if JUCE_WINDOWS
  1358. struct _timeb t;
  1359. #ifdef USE_NEW_SECURE_TIME_FNS
  1360. _ftime_s (&t);
  1361. #else
  1362. _ftime (&t);
  1363. #endif
  1364. correction = (((int64) t.time) * 1000 + t.millitm) - now;
  1365. #else
  1366. struct timeval tv;
  1367. struct timezone tz;
  1368. gettimeofday (&tv, &tz);
  1369. correction = (((int64) tv.tv_sec) * 1000 + tv.tv_usec / 1000) - now;
  1370. #endif
  1371. }
  1372. }
  1373. lastCounterResult = now;
  1374. return correction + now;
  1375. }
  1376. uint32 juce_millisecondsSinceStartup() throw();
  1377. static uint32 lastMSCounterValue = 0;
  1378. uint32 Time::getMillisecondCounter() throw()
  1379. {
  1380. const uint32 now = juce_millisecondsSinceStartup();
  1381. if (now < lastMSCounterValue)
  1382. {
  1383. // in multi-threaded apps this might be called concurrently, so
  1384. // make sure that our last counter value only increases and doesn't
  1385. // go backwards..
  1386. if (now < lastMSCounterValue - 1000)
  1387. lastMSCounterValue = now;
  1388. }
  1389. else
  1390. {
  1391. lastMSCounterValue = now;
  1392. }
  1393. return now;
  1394. }
  1395. uint32 Time::getApproximateMillisecondCounter() throw()
  1396. {
  1397. jassert (lastMSCounterValue != 0);
  1398. return lastMSCounterValue;
  1399. }
  1400. void Time::waitForMillisecondCounter (const uint32 targetTime) throw()
  1401. {
  1402. for (;;)
  1403. {
  1404. const uint32 now = getMillisecondCounter();
  1405. if (now >= targetTime)
  1406. break;
  1407. const int toWait = targetTime - now;
  1408. if (toWait > 2)
  1409. {
  1410. Thread::sleep (jmin (20, toWait >> 1));
  1411. }
  1412. else
  1413. {
  1414. // xxx should consider using mutex_pause on the mac as it apparently
  1415. // makes it seem less like a spinlock and avoids lowering the thread pri.
  1416. for (int i = 10; --i >= 0;)
  1417. Thread::yield();
  1418. }
  1419. }
  1420. }
  1421. double Time::highResolutionTicksToSeconds (const int64 ticks) throw()
  1422. {
  1423. return ticks / (double) getHighResolutionTicksPerSecond();
  1424. }
  1425. int64 Time::secondsToHighResolutionTicks (const double seconds) throw()
  1426. {
  1427. return (int64) (seconds * (double) getHighResolutionTicksPerSecond());
  1428. }
  1429. const Time JUCE_CALLTYPE Time::getCurrentTime() throw()
  1430. {
  1431. return Time (currentTimeMillis());
  1432. }
  1433. const String Time::toString (const bool includeDate,
  1434. const bool includeTime,
  1435. const bool includeSeconds,
  1436. const bool use24HourClock) const throw()
  1437. {
  1438. String result;
  1439. if (includeDate)
  1440. {
  1441. result << getDayOfMonth() << ' '
  1442. << getMonthName (true) << ' '
  1443. << getYear();
  1444. if (includeTime)
  1445. result << ' ';
  1446. }
  1447. if (includeTime)
  1448. {
  1449. if (includeSeconds)
  1450. {
  1451. result += String::formatted (T("%d:%02d:%02d "),
  1452. (use24HourClock) ? getHours()
  1453. : getHoursInAmPmFormat(),
  1454. getMinutes(),
  1455. getSeconds());
  1456. }
  1457. else
  1458. {
  1459. result += String::formatted (T("%d.%02d"),
  1460. (use24HourClock) ? getHours()
  1461. : getHoursInAmPmFormat(),
  1462. getMinutes());
  1463. }
  1464. if (! use24HourClock)
  1465. result << (isAfternoon() ? "pm" : "am");
  1466. }
  1467. return result.trimEnd();
  1468. }
  1469. const String Time::formatted (const tchar* const format) const throw()
  1470. {
  1471. String buffer;
  1472. int bufferSize = 128;
  1473. buffer.preallocateStorage (bufferSize);
  1474. struct tm t;
  1475. millisToLocal (millisSinceEpoch, t);
  1476. while (CharacterFunctions::ftime ((tchar*) (const tchar*) buffer, bufferSize, format, &t) <= 0)
  1477. {
  1478. bufferSize += 128;
  1479. buffer.preallocateStorage (bufferSize);
  1480. }
  1481. return buffer;
  1482. }
  1483. int Time::getYear() const throw()
  1484. {
  1485. struct tm t;
  1486. millisToLocal (millisSinceEpoch, t);
  1487. return t.tm_year + 1900;
  1488. }
  1489. int Time::getMonth() const throw()
  1490. {
  1491. struct tm t;
  1492. millisToLocal (millisSinceEpoch, t);
  1493. return t.tm_mon;
  1494. }
  1495. int Time::getDayOfMonth() const throw()
  1496. {
  1497. struct tm t;
  1498. millisToLocal (millisSinceEpoch, t);
  1499. return t.tm_mday;
  1500. }
  1501. int Time::getDayOfWeek() const throw()
  1502. {
  1503. struct tm t;
  1504. millisToLocal (millisSinceEpoch, t);
  1505. return t.tm_wday;
  1506. }
  1507. int Time::getHours() const throw()
  1508. {
  1509. struct tm t;
  1510. millisToLocal (millisSinceEpoch, t);
  1511. return t.tm_hour;
  1512. }
  1513. int Time::getHoursInAmPmFormat() const throw()
  1514. {
  1515. const int hours = getHours();
  1516. if (hours == 0)
  1517. return 12;
  1518. else if (hours <= 12)
  1519. return hours;
  1520. else
  1521. return hours - 12;
  1522. }
  1523. bool Time::isAfternoon() const throw()
  1524. {
  1525. return getHours() >= 12;
  1526. }
  1527. static int extendedModulo (const int64 value, const int modulo) throw()
  1528. {
  1529. return (int) (value >= 0 ? (value % modulo)
  1530. : (value - ((value / modulo) + 1) * modulo));
  1531. }
  1532. int Time::getMinutes() const throw()
  1533. {
  1534. struct tm t;
  1535. millisToLocal (millisSinceEpoch, t);
  1536. return t.tm_min;
  1537. }
  1538. int Time::getSeconds() const throw()
  1539. {
  1540. return extendedModulo (millisSinceEpoch / 1000, 60);
  1541. }
  1542. int Time::getMilliseconds() const throw()
  1543. {
  1544. return extendedModulo (millisSinceEpoch, 1000);
  1545. }
  1546. bool Time::isDaylightSavingTime() const throw()
  1547. {
  1548. struct tm t;
  1549. millisToLocal (millisSinceEpoch, t);
  1550. return t.tm_isdst != 0;
  1551. }
  1552. const String Time::getTimeZone() const throw()
  1553. {
  1554. String zone[2];
  1555. #if JUCE_WINDOWS
  1556. _tzset();
  1557. #ifdef USE_NEW_SECURE_TIME_FNS
  1558. {
  1559. char name [128];
  1560. size_t length;
  1561. for (int i = 0; i < 2; ++i)
  1562. {
  1563. zeromem (name, sizeof (name));
  1564. _get_tzname (&length, name, 127, i);
  1565. zone[i] = name;
  1566. }
  1567. }
  1568. #else
  1569. const char** const zonePtr = (const char**) _tzname;
  1570. zone[0] = zonePtr[0];
  1571. zone[1] = zonePtr[1];
  1572. #endif
  1573. #else
  1574. tzset();
  1575. const char** const zonePtr = (const char**) tzname;
  1576. zone[0] = zonePtr[0];
  1577. zone[1] = zonePtr[1];
  1578. #endif
  1579. if (isDaylightSavingTime())
  1580. {
  1581. zone[0] = zone[1];
  1582. if (zone[0].length() > 3
  1583. && zone[0].containsIgnoreCase (T("daylight"))
  1584. && zone[0].contains (T("GMT")))
  1585. zone[0] = "BST";
  1586. }
  1587. return zone[0].substring (0, 3);
  1588. }
  1589. const String Time::getMonthName (const bool threeLetterVersion) const throw()
  1590. {
  1591. return getMonthName (getMonth(), threeLetterVersion);
  1592. }
  1593. const String Time::getWeekdayName (const bool threeLetterVersion) const throw()
  1594. {
  1595. return getWeekdayName (getDayOfWeek(), threeLetterVersion);
  1596. }
  1597. const String Time::getMonthName (int monthNumber,
  1598. const bool threeLetterVersion) throw()
  1599. {
  1600. const char* const shortMonthNames[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
  1601. const char* const longMonthNames[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" };
  1602. monthNumber %= 12;
  1603. return TRANS (threeLetterVersion ? shortMonthNames [monthNumber]
  1604. : longMonthNames [monthNumber]);
  1605. }
  1606. const String Time::getWeekdayName (int day,
  1607. const bool threeLetterVersion) throw()
  1608. {
  1609. const char* const shortDayNames[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
  1610. const char* const longDayNames[] = { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" };
  1611. day %= 7;
  1612. return TRANS (threeLetterVersion ? shortDayNames [day]
  1613. : longDayNames [day]);
  1614. }
  1615. END_JUCE_NAMESPACE
  1616. /*** End of inlined file: juce_Time.cpp ***/
  1617. /*** Start of inlined file: juce_BitArray.cpp ***/
  1618. BEGIN_JUCE_NAMESPACE
  1619. BitArray::BitArray() throw()
  1620. : numValues (4),
  1621. highestBit (-1),
  1622. negative (false)
  1623. {
  1624. values.calloc (numValues + 1);
  1625. }
  1626. BitArray::BitArray (const int value) throw()
  1627. : numValues (4),
  1628. highestBit (31),
  1629. negative (value < 0)
  1630. {
  1631. values.calloc (numValues + 1);
  1632. values[0] = abs (value);
  1633. highestBit = getHighestBit();
  1634. }
  1635. BitArray::BitArray (int64 value) throw()
  1636. : numValues (4),
  1637. highestBit (63),
  1638. negative (value < 0)
  1639. {
  1640. values.calloc (numValues + 1);
  1641. if (value < 0)
  1642. value = -value;
  1643. values[0] = (unsigned int) value;
  1644. values[1] = (unsigned int) (value >> 32);
  1645. highestBit = getHighestBit();
  1646. }
  1647. BitArray::BitArray (const unsigned int value) throw()
  1648. : numValues (4),
  1649. highestBit (31),
  1650. negative (false)
  1651. {
  1652. values.calloc (numValues + 1);
  1653. values[0] = value;
  1654. highestBit = getHighestBit();
  1655. }
  1656. BitArray::BitArray (const BitArray& other) throw()
  1657. : numValues (jmax (4, (other.highestBit >> 5) + 1)),
  1658. highestBit (other.getHighestBit()),
  1659. negative (other.negative)
  1660. {
  1661. values.malloc (numValues + 1);
  1662. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1663. }
  1664. BitArray::~BitArray() throw()
  1665. {
  1666. }
  1667. BitArray& BitArray::operator= (const BitArray& other) throw()
  1668. {
  1669. if (this != &other)
  1670. {
  1671. highestBit = other.getHighestBit();
  1672. numValues = jmax (4, (highestBit >> 5) + 1);
  1673. negative = other.negative;
  1674. values.malloc (numValues + 1);
  1675. memcpy (values, other.values, sizeof (unsigned int) * (numValues + 1));
  1676. }
  1677. return *this;
  1678. }
  1679. // result == 0 = the same
  1680. // result < 0 = this number is smaller
  1681. // result > 0 = this number is bigger
  1682. int BitArray::compare (const BitArray& other) const throw()
  1683. {
  1684. if (isNegative() == other.isNegative())
  1685. {
  1686. const int absComp = compareAbsolute (other);
  1687. return isNegative() ? -absComp : absComp;
  1688. }
  1689. else
  1690. {
  1691. return isNegative() ? -1 : 1;
  1692. }
  1693. }
  1694. int BitArray::compareAbsolute (const BitArray& other) const throw()
  1695. {
  1696. const int h1 = getHighestBit();
  1697. const int h2 = other.getHighestBit();
  1698. if (h1 > h2)
  1699. return 1;
  1700. else if (h1 < h2)
  1701. return -1;
  1702. for (int i = (h1 >> 5) + 1; --i >= 0;)
  1703. if (values[i] != other.values[i])
  1704. return (values[i] > other.values[i]) ? 1 : -1;
  1705. return 0;
  1706. }
  1707. bool BitArray::operator== (const BitArray& other) const throw()
  1708. {
  1709. return compare (other) == 0;
  1710. }
  1711. bool BitArray::operator!= (const BitArray& other) const throw()
  1712. {
  1713. return compare (other) != 0;
  1714. }
  1715. bool BitArray::operator[] (const int bit) const throw()
  1716. {
  1717. return bit >= 0 && bit <= highestBit
  1718. && ((values [bit >> 5] & (1 << (bit & 31))) != 0);
  1719. }
  1720. bool BitArray::isEmpty() const throw()
  1721. {
  1722. return getHighestBit() < 0;
  1723. }
  1724. void BitArray::clear() throw()
  1725. {
  1726. if (numValues > 16)
  1727. {
  1728. numValues = 4;
  1729. values.calloc (numValues + 1);
  1730. }
  1731. else
  1732. {
  1733. zeromem (values, sizeof (unsigned int) * (numValues + 1));
  1734. }
  1735. highestBit = -1;
  1736. negative = false;
  1737. }
  1738. void BitArray::setBit (const int bit) throw()
  1739. {
  1740. if (bit >= 0)
  1741. {
  1742. if (bit > highestBit)
  1743. {
  1744. ensureSize (bit >> 5);
  1745. highestBit = bit;
  1746. }
  1747. values [bit >> 5] |= (1 << (bit & 31));
  1748. }
  1749. }
  1750. void BitArray::setBit (const int bit,
  1751. const bool shouldBeSet) throw()
  1752. {
  1753. if (shouldBeSet)
  1754. setBit (bit);
  1755. else
  1756. clearBit (bit);
  1757. }
  1758. void BitArray::clearBit (const int bit) throw()
  1759. {
  1760. if (bit >= 0 && bit <= highestBit)
  1761. values [bit >> 5] &= ~(1 << (bit & 31));
  1762. }
  1763. void BitArray::setRange (int startBit,
  1764. int numBits,
  1765. const bool shouldBeSet) throw()
  1766. {
  1767. while (--numBits >= 0)
  1768. setBit (startBit++, shouldBeSet);
  1769. }
  1770. void BitArray::insertBit (const int bit,
  1771. const bool shouldBeSet) throw()
  1772. {
  1773. if (bit >= 0)
  1774. shiftBits (1, bit);
  1775. setBit (bit, shouldBeSet);
  1776. }
  1777. void BitArray::andWith (const BitArray& other) throw()
  1778. {
  1779. // this operation will only work with the absolute values
  1780. jassert (isNegative() == other.isNegative());
  1781. int n = numValues;
  1782. while (n > other.numValues)
  1783. values[--n] = 0;
  1784. while (--n >= 0)
  1785. values[n] &= other.values[n];
  1786. if (other.highestBit < highestBit)
  1787. highestBit = other.highestBit;
  1788. highestBit = getHighestBit();
  1789. }
  1790. void BitArray::orWith (const BitArray& other) throw()
  1791. {
  1792. if (other.highestBit < 0)
  1793. return;
  1794. // this operation will only work with the absolute values
  1795. jassert (isNegative() == other.isNegative());
  1796. ensureSize (other.highestBit >> 5);
  1797. int n = (other.highestBit >> 5) + 1;
  1798. while (--n >= 0)
  1799. values[n] |= other.values[n];
  1800. if (other.highestBit > highestBit)
  1801. highestBit = other.highestBit;
  1802. highestBit = getHighestBit();
  1803. }
  1804. void BitArray::xorWith (const BitArray& other) throw()
  1805. {
  1806. if (other.highestBit < 0)
  1807. return;
  1808. // this operation will only work with the absolute values
  1809. jassert (isNegative() == other.isNegative());
  1810. ensureSize (other.highestBit >> 5);
  1811. int n = (other.highestBit >> 5) + 1;
  1812. while (--n >= 0)
  1813. values[n] ^= other.values[n];
  1814. if (other.highestBit > highestBit)
  1815. highestBit = other.highestBit;
  1816. highestBit = getHighestBit();
  1817. }
  1818. void BitArray::add (const BitArray& other) throw()
  1819. {
  1820. if (other.isNegative())
  1821. {
  1822. BitArray o (other);
  1823. o.negate();
  1824. subtract (o);
  1825. return;
  1826. }
  1827. if (isNegative())
  1828. {
  1829. if (compareAbsolute (other) < 0)
  1830. {
  1831. BitArray temp (*this);
  1832. temp.negate();
  1833. *this = other;
  1834. subtract (temp);
  1835. }
  1836. else
  1837. {
  1838. negate();
  1839. subtract (other);
  1840. negate();
  1841. }
  1842. return;
  1843. }
  1844. if (other.highestBit > highestBit)
  1845. highestBit = other.highestBit;
  1846. ++highestBit;
  1847. const int numInts = (highestBit >> 5) + 1;
  1848. ensureSize (numInts);
  1849. int64 remainder = 0;
  1850. for (int i = 0; i <= numInts; ++i)
  1851. {
  1852. if (i < numValues)
  1853. remainder += values[i];
  1854. if (i < other.numValues)
  1855. remainder += other.values[i];
  1856. values[i] = (unsigned int) remainder;
  1857. remainder >>= 32;
  1858. }
  1859. jassert (remainder == 0);
  1860. highestBit = getHighestBit();
  1861. }
  1862. void BitArray::subtract (const BitArray& other) throw()
  1863. {
  1864. if (other.isNegative())
  1865. {
  1866. BitArray o (other);
  1867. o.negate();
  1868. add (o);
  1869. return;
  1870. }
  1871. if (! isNegative())
  1872. {
  1873. if (compareAbsolute (other) < 0)
  1874. {
  1875. BitArray temp (*this);
  1876. *this = other;
  1877. subtract (temp);
  1878. negate();
  1879. return;
  1880. }
  1881. }
  1882. else
  1883. {
  1884. negate();
  1885. add (other);
  1886. negate();
  1887. return;
  1888. }
  1889. const int numInts = (highestBit >> 5) + 1;
  1890. const int maxOtherInts = (other.highestBit >> 5) + 1;
  1891. int64 amountToSubtract = 0;
  1892. for (int i = 0; i <= numInts; ++i)
  1893. {
  1894. if (i <= maxOtherInts)
  1895. amountToSubtract += (int64)other.values[i];
  1896. if (values[i] >= amountToSubtract)
  1897. {
  1898. values[i] = (unsigned int) (values[i] - amountToSubtract);
  1899. amountToSubtract = 0;
  1900. }
  1901. else
  1902. {
  1903. const int64 n = ((int64) values[i] + (((int64) 1) << 32)) - amountToSubtract;
  1904. values[i] = (unsigned int) n;
  1905. amountToSubtract = 1;
  1906. }
  1907. }
  1908. }
  1909. void BitArray::multiplyBy (const BitArray& other) throw()
  1910. {
  1911. BitArray total;
  1912. highestBit = getHighestBit();
  1913. const bool wasNegative = isNegative();
  1914. setNegative (false);
  1915. for (int i = 0; i <= highestBit; ++i)
  1916. {
  1917. if (operator[](i))
  1918. {
  1919. BitArray n (other);
  1920. n.setNegative (false);
  1921. n.shiftBits (i);
  1922. total.add (n);
  1923. }
  1924. }
  1925. *this = total;
  1926. negative = wasNegative ^ other.isNegative();
  1927. }
  1928. void BitArray::divideBy (const BitArray& divisor, BitArray& remainder) throw()
  1929. {
  1930. jassert (this != &remainder); // (can't handle passing itself in to get the remainder)
  1931. const int divHB = divisor.getHighestBit();
  1932. const int ourHB = getHighestBit();
  1933. if (divHB < 0 || ourHB < 0)
  1934. {
  1935. // division by zero
  1936. remainder.clear();
  1937. clear();
  1938. }
  1939. else
  1940. {
  1941. remainder = *this;
  1942. remainder.setNegative (false);
  1943. const bool wasNegative = isNegative();
  1944. clear();
  1945. BitArray temp (divisor);
  1946. temp.setNegative (false);
  1947. int leftShift = ourHB - divHB;
  1948. temp.shiftBits (leftShift);
  1949. while (leftShift >= 0)
  1950. {
  1951. if (remainder.compareAbsolute (temp) >= 0)
  1952. {
  1953. remainder.subtract (temp);
  1954. setBit (leftShift);
  1955. }
  1956. if (--leftShift >= 0)
  1957. temp.shiftBits (-1);
  1958. }
  1959. negative = wasNegative ^ divisor.isNegative();
  1960. remainder.setNegative (wasNegative);
  1961. }
  1962. }
  1963. void BitArray::modulo (const BitArray& divisor) throw()
  1964. {
  1965. BitArray remainder;
  1966. divideBy (divisor, remainder);
  1967. *this = remainder;
  1968. }
  1969. static const BitArray simpleGCD (BitArray* m, BitArray* n) throw()
  1970. {
  1971. while (! m->isEmpty())
  1972. {
  1973. if (n->compareAbsolute (*m) > 0)
  1974. swapVariables (m, n);
  1975. m->subtract (*n);
  1976. }
  1977. return *n;
  1978. }
  1979. const BitArray BitArray::findGreatestCommonDivisor (BitArray n) const throw()
  1980. {
  1981. BitArray m (*this);
  1982. while (! n.isEmpty())
  1983. {
  1984. if (abs (m.getHighestBit() - n.getHighestBit()) <= 16)
  1985. return simpleGCD (&m, &n);
  1986. BitArray temp1 (m), temp2;
  1987. temp1.divideBy (n, temp2);
  1988. m = n;
  1989. n = temp2;
  1990. }
  1991. return m;
  1992. }
  1993. void BitArray::exponentModulo (const BitArray& exponent,
  1994. const BitArray& modulus) throw()
  1995. {
  1996. BitArray exp (exponent);
  1997. exp.modulo (modulus);
  1998. BitArray value (*this);
  1999. value.modulo (modulus);
  2000. clear();
  2001. setBit (0);
  2002. while (! exp.isEmpty())
  2003. {
  2004. if (exp [0])
  2005. {
  2006. multiplyBy (value);
  2007. this->modulo (modulus);
  2008. }
  2009. value.multiplyBy (value);
  2010. value.modulo (modulus);
  2011. exp.shiftBits (-1);
  2012. }
  2013. }
  2014. void BitArray::inverseModulo (const BitArray& modulus) throw()
  2015. {
  2016. const BitArray one (1);
  2017. if (modulus == one || modulus.isNegative())
  2018. {
  2019. clear();
  2020. return;
  2021. }
  2022. if (isNegative() || compareAbsolute (modulus) >= 0)
  2023. this->modulo (modulus);
  2024. if (*this == one)
  2025. return;
  2026. if (! (*this)[0])
  2027. {
  2028. // not invertible
  2029. clear();
  2030. return;
  2031. }
  2032. BitArray a1 (modulus);
  2033. BitArray a2 (*this);
  2034. BitArray b1 (modulus);
  2035. BitArray b2 (1);
  2036. while (a2 != one)
  2037. {
  2038. BitArray temp1, temp2, multiplier (a1);
  2039. multiplier.divideBy (a2, temp1);
  2040. temp1 = a2;
  2041. temp1.multiplyBy (multiplier);
  2042. temp2 = a1;
  2043. temp2.subtract (temp1);
  2044. a1 = a2;
  2045. a2 = temp2;
  2046. temp1 = b2;
  2047. temp1.multiplyBy (multiplier);
  2048. temp2 = b1;
  2049. temp2.subtract (temp1);
  2050. b1 = b2;
  2051. b2 = temp2;
  2052. }
  2053. while (b2.isNegative())
  2054. b2.add (modulus);
  2055. b2.modulo (modulus);
  2056. *this = b2;
  2057. }
  2058. void BitArray::shiftBits (int bits, const int startBit) throw()
  2059. {
  2060. if (highestBit < 0)
  2061. return;
  2062. if (startBit > 0)
  2063. {
  2064. if (bits < 0)
  2065. {
  2066. // right shift
  2067. for (int i = startBit; i <= highestBit; ++i)
  2068. setBit (i, operator[] (i - bits));
  2069. highestBit = getHighestBit();
  2070. }
  2071. else if (bits > 0)
  2072. {
  2073. // left shift
  2074. for (int i = highestBit + 1; --i >= startBit;)
  2075. setBit (i + bits, operator[] (i));
  2076. while (--bits >= 0)
  2077. clearBit (bits + startBit);
  2078. }
  2079. }
  2080. else
  2081. {
  2082. if (bits < 0)
  2083. {
  2084. // right shift
  2085. bits = -bits;
  2086. if (bits > highestBit)
  2087. {
  2088. clear();
  2089. }
  2090. else
  2091. {
  2092. const int wordsToMove = bits >> 5;
  2093. int top = 1 + (highestBit >> 5) - wordsToMove;
  2094. highestBit -= bits;
  2095. if (wordsToMove > 0)
  2096. {
  2097. int i;
  2098. for (i = 0; i < top; ++i)
  2099. values [i] = values [i + wordsToMove];
  2100. for (i = 0; i < wordsToMove; ++i)
  2101. values [top + i] = 0;
  2102. bits &= 31;
  2103. }
  2104. if (bits != 0)
  2105. {
  2106. const int invBits = 32 - bits;
  2107. --top;
  2108. for (int i = 0; i < top; ++i)
  2109. values[i] = (values[i] >> bits) | (values [i + 1] << invBits);
  2110. values[top] = (values[top] >> bits);
  2111. }
  2112. highestBit = getHighestBit();
  2113. }
  2114. }
  2115. else if (bits > 0)
  2116. {
  2117. // left shift
  2118. ensureSize (((highestBit + bits) >> 5) + 1);
  2119. const int wordsToMove = bits >> 5;
  2120. int top = 1 + (highestBit >> 5);
  2121. highestBit += bits;
  2122. if (wordsToMove > 0)
  2123. {
  2124. int i;
  2125. for (i = top; --i >= 0;)
  2126. values [i + wordsToMove] = values [i];
  2127. for (i = 0; i < wordsToMove; ++i)
  2128. values [i] = 0;
  2129. bits &= 31;
  2130. }
  2131. if (bits != 0)
  2132. {
  2133. const int invBits = 32 - bits;
  2134. for (int i = top + 1 + wordsToMove; --i > wordsToMove;)
  2135. values[i] = (values[i] << bits) | (values [i - 1] >> invBits);
  2136. values [wordsToMove] = values [wordsToMove] << bits;
  2137. }
  2138. highestBit = getHighestBit();
  2139. }
  2140. }
  2141. }
  2142. const BitArray BitArray::getBitRange (int startBit, int numBits) const throw()
  2143. {
  2144. BitArray r;
  2145. numBits = jmin (numBits, getHighestBit() + 1 - startBit);
  2146. r.ensureSize (numBits >> 5);
  2147. r.highestBit = numBits;
  2148. int i = 0;
  2149. while (numBits > 0)
  2150. {
  2151. r.values[i++] = getBitRangeAsInt (startBit, jmin (32, numBits));
  2152. numBits -= 32;
  2153. startBit += 32;
  2154. }
  2155. r.highestBit = r.getHighestBit();
  2156. return r;
  2157. }
  2158. int BitArray::getBitRangeAsInt (const int startBit, int numBits) const throw()
  2159. {
  2160. if (numBits > 32)
  2161. {
  2162. jassertfalse // use getBitRange() if you need more than 32 bits..
  2163. numBits = 32;
  2164. }
  2165. numBits = jmin (numBits, highestBit + 1 - startBit);
  2166. if (numBits <= 0)
  2167. return 0;
  2168. const int pos = startBit >> 5;
  2169. const int offset = startBit & 31;
  2170. const int endSpace = 32 - numBits;
  2171. uint32 n = ((uint32) values [pos]) >> offset;
  2172. if (offset > endSpace)
  2173. n |= ((uint32) values [pos + 1]) << (32 - offset);
  2174. return (int) (n & (((uint32) 0xffffffff) >> endSpace));
  2175. }
  2176. void BitArray::setBitRangeAsInt (const int startBit, int numBits, unsigned int valueToSet) throw()
  2177. {
  2178. if (numBits > 32)
  2179. {
  2180. jassertfalse
  2181. numBits = 32;
  2182. }
  2183. for (int i = 0; i < numBits; ++i)
  2184. {
  2185. setBit (startBit + i, (valueToSet & 1) != 0);
  2186. valueToSet >>= 1;
  2187. }
  2188. }
  2189. bool BitArray::isNegative() const throw()
  2190. {
  2191. return negative && ! isEmpty();
  2192. }
  2193. void BitArray::setNegative (const bool neg) throw()
  2194. {
  2195. negative = neg;
  2196. }
  2197. void BitArray::negate() throw()
  2198. {
  2199. negative = (! negative) && ! isEmpty();
  2200. }
  2201. int BitArray::countNumberOfSetBits() const throw()
  2202. {
  2203. int total = 0;
  2204. for (int i = (highestBit >> 5) + 1; --i >= 0;)
  2205. {
  2206. unsigned int n = values[i];
  2207. if (n == 0xffffffff)
  2208. {
  2209. total += 32;
  2210. }
  2211. else
  2212. {
  2213. while (n != 0)
  2214. {
  2215. total += (n & 1);
  2216. n >>= 1;
  2217. }
  2218. }
  2219. }
  2220. return total;
  2221. }
  2222. int BitArray::getHighestBit() const throw()
  2223. {
  2224. for (int i = highestBit + 1; --i >= 0;)
  2225. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  2226. return i;
  2227. return -1;
  2228. }
  2229. int BitArray::findNextSetBit (int i) const throw()
  2230. {
  2231. for (; i <= highestBit; ++i)
  2232. if ((values [i >> 5] & (1 << (i & 31))) != 0)
  2233. return i;
  2234. return -1;
  2235. }
  2236. int BitArray::findNextClearBit (int i) const throw()
  2237. {
  2238. for (; i <= highestBit; ++i)
  2239. if ((values [i >> 5] & (1 << (i & 31))) == 0)
  2240. break;
  2241. return i;
  2242. }
  2243. void BitArray::ensureSize (const int numVals) throw()
  2244. {
  2245. if (numVals + 2 >= numValues)
  2246. {
  2247. int oldSize = numValues;
  2248. numValues = ((numVals + 2) * 3) / 2;
  2249. values.realloc (numValues + 1);
  2250. while (oldSize < numValues)
  2251. values [oldSize++] = 0;
  2252. }
  2253. }
  2254. const String BitArray::toString (const int base, const int minimumNumCharacters) const throw()
  2255. {
  2256. String s;
  2257. BitArray v (*this);
  2258. if (base == 2 || base == 8 || base == 16)
  2259. {
  2260. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2261. static const tchar* const hexDigits = T("0123456789abcdef");
  2262. for (;;)
  2263. {
  2264. const int remainder = v.getBitRangeAsInt (0, bits);
  2265. v.shiftBits (-bits);
  2266. if (remainder == 0 && v.isEmpty())
  2267. break;
  2268. s = String::charToString (hexDigits [remainder]) + s;
  2269. }
  2270. }
  2271. else if (base == 10)
  2272. {
  2273. const BitArray ten (10);
  2274. BitArray remainder;
  2275. for (;;)
  2276. {
  2277. v.divideBy (ten, remainder);
  2278. if (remainder.isEmpty() && v.isEmpty())
  2279. break;
  2280. s = String (remainder.getBitRangeAsInt (0, 8)) + s;
  2281. }
  2282. }
  2283. else
  2284. {
  2285. jassertfalse // can't do the specified base
  2286. return String::empty;
  2287. }
  2288. const int length = s.length();
  2289. if (length < minimumNumCharacters)
  2290. s = String::repeatedString (T("0"), minimumNumCharacters - length) + s;
  2291. return isNegative() ? T("-") + s : s;
  2292. }
  2293. void BitArray::parseString (const String& text,
  2294. const int base) throw()
  2295. {
  2296. clear();
  2297. const tchar* t = (const tchar*) text;
  2298. if (base == 2 || base == 8 || base == 16)
  2299. {
  2300. const int bits = (base == 2) ? 1 : (base == 8 ? 3 : 4);
  2301. for (;;)
  2302. {
  2303. const tchar c = *t++;
  2304. const int digit = CharacterFunctions::getHexDigitValue (c);
  2305. if (((unsigned int) digit) < (unsigned int) base)
  2306. {
  2307. shiftBits (bits);
  2308. add (digit);
  2309. }
  2310. else if (c == 0)
  2311. {
  2312. break;
  2313. }
  2314. }
  2315. }
  2316. else if (base == 10)
  2317. {
  2318. const BitArray ten ((unsigned int) 10);
  2319. for (;;)
  2320. {
  2321. const tchar c = *t++;
  2322. if (c >= T('0') && c <= T('9'))
  2323. {
  2324. multiplyBy (ten);
  2325. add ((int) (c - T('0')));
  2326. }
  2327. else if (c == 0)
  2328. {
  2329. break;
  2330. }
  2331. }
  2332. }
  2333. setNegative (text.trimStart().startsWithChar (T('-')));
  2334. }
  2335. const MemoryBlock BitArray::toMemoryBlock() const throw()
  2336. {
  2337. const int numBytes = (getHighestBit() + 8) >> 3;
  2338. MemoryBlock mb ((size_t) numBytes);
  2339. for (int i = 0; i < numBytes; ++i)
  2340. mb[i] = (uint8) getBitRangeAsInt (i << 3, 8);
  2341. return mb;
  2342. }
  2343. void BitArray::loadFromMemoryBlock (const MemoryBlock& data) throw()
  2344. {
  2345. clear();
  2346. for (int i = (int) data.getSize(); --i >= 0;)
  2347. this->setBitRangeAsInt ((int) (i << 3), 8, data [i]);
  2348. }
  2349. END_JUCE_NAMESPACE
  2350. /*** End of inlined file: juce_BitArray.cpp ***/
  2351. /*** Start of inlined file: juce_MemoryBlock.cpp ***/
  2352. BEGIN_JUCE_NAMESPACE
  2353. MemoryBlock::MemoryBlock() throw()
  2354. : size (0)
  2355. {
  2356. }
  2357. MemoryBlock::MemoryBlock (const size_t initialSize,
  2358. const bool initialiseToZero) throw()
  2359. {
  2360. if (initialSize > 0)
  2361. {
  2362. size = initialSize;
  2363. data.allocate (initialSize, initialiseToZero);
  2364. }
  2365. else
  2366. {
  2367. size = 0;
  2368. }
  2369. }
  2370. MemoryBlock::MemoryBlock (const MemoryBlock& other) throw()
  2371. : size (other.size)
  2372. {
  2373. if (size > 0)
  2374. {
  2375. jassert (other.data != 0);
  2376. data.malloc (size);
  2377. memcpy (data, other.data, size);
  2378. }
  2379. }
  2380. MemoryBlock::MemoryBlock (const void* const dataToInitialiseFrom,
  2381. const size_t sizeInBytes) throw()
  2382. : size (jmax ((size_t) 0, sizeInBytes))
  2383. {
  2384. jassert (sizeInBytes >= 0);
  2385. if (size > 0)
  2386. {
  2387. jassert (dataToInitialiseFrom != 0); // non-zero size, but a zero pointer passed-in?
  2388. data.malloc (size);
  2389. if (dataToInitialiseFrom != 0)
  2390. memcpy (data, dataToInitialiseFrom, size);
  2391. }
  2392. }
  2393. MemoryBlock::~MemoryBlock() throw()
  2394. {
  2395. jassert (size >= 0); // should never happen
  2396. jassert (size == 0 || data != 0); // non-zero size but no data allocated?
  2397. }
  2398. MemoryBlock& MemoryBlock::operator= (const MemoryBlock& other) throw()
  2399. {
  2400. if (this != &other)
  2401. {
  2402. setSize (other.size, false);
  2403. memcpy (data, other.data, size);
  2404. }
  2405. return *this;
  2406. }
  2407. bool MemoryBlock::operator== (const MemoryBlock& other) const throw()
  2408. {
  2409. return matches (other.data, other.size);
  2410. }
  2411. bool MemoryBlock::operator!= (const MemoryBlock& other) const throw()
  2412. {
  2413. return ! operator== (other);
  2414. }
  2415. bool MemoryBlock::matches (const void* dataToCompare, size_t dataSize) const throw()
  2416. {
  2417. return size == dataSize
  2418. && memcmp (data, dataToCompare, size) == 0;
  2419. }
  2420. // this will resize the block to this size
  2421. void MemoryBlock::setSize (const size_t newSize,
  2422. const bool initialiseToZero) throw()
  2423. {
  2424. if (size != newSize)
  2425. {
  2426. if (newSize <= 0)
  2427. {
  2428. data.free();
  2429. size = 0;
  2430. }
  2431. else
  2432. {
  2433. if (data != 0)
  2434. {
  2435. data.realloc (newSize);
  2436. if (initialiseToZero && (newSize > size))
  2437. zeromem (data + size, newSize - size);
  2438. }
  2439. else
  2440. {
  2441. data.allocate (newSize, initialiseToZero);
  2442. }
  2443. size = newSize;
  2444. }
  2445. }
  2446. }
  2447. void MemoryBlock::ensureSize (const size_t minimumSize,
  2448. const bool initialiseToZero) throw()
  2449. {
  2450. if (size < minimumSize)
  2451. setSize (minimumSize, initialiseToZero);
  2452. }
  2453. void MemoryBlock::swapWith (MemoryBlock& other) throw()
  2454. {
  2455. swapVariables (size, other.size);
  2456. data.swapWith (other.data);
  2457. }
  2458. void MemoryBlock::fillWith (const uint8 value) throw()
  2459. {
  2460. memset (data, (int) value, size);
  2461. }
  2462. void MemoryBlock::append (const void* const srcData,
  2463. const size_t numBytes) throw()
  2464. {
  2465. if (numBytes > 0)
  2466. {
  2467. const size_t oldSize = size;
  2468. setSize (size + numBytes);
  2469. memcpy (data + oldSize, srcData, numBytes);
  2470. }
  2471. }
  2472. void MemoryBlock::copyFrom (const void* const src, int offset, size_t num) throw()
  2473. {
  2474. const char* d = (const char*) src;
  2475. if (offset < 0)
  2476. {
  2477. d -= offset;
  2478. num -= offset;
  2479. offset = 0;
  2480. }
  2481. if (offset + num > size)
  2482. num = size - offset;
  2483. if (num > 0)
  2484. memcpy (data + offset, d, num);
  2485. }
  2486. void MemoryBlock::copyTo (void* const dst, int offset, size_t num) const throw()
  2487. {
  2488. char* d = (char*) dst;
  2489. if (offset < 0)
  2490. {
  2491. zeromem (d, -offset);
  2492. d -= offset;
  2493. num += offset;
  2494. offset = 0;
  2495. }
  2496. if (offset + num > size)
  2497. {
  2498. const size_t newNum = size - offset;
  2499. zeromem (d + newNum, num - newNum);
  2500. num = newNum;
  2501. }
  2502. if (num > 0)
  2503. memcpy (d, data + offset, num);
  2504. }
  2505. void MemoryBlock::removeSection (size_t startByte, size_t numBytesToRemove) throw()
  2506. {
  2507. if (startByte < 0)
  2508. {
  2509. numBytesToRemove += startByte;
  2510. startByte = 0;
  2511. }
  2512. if (startByte + numBytesToRemove >= size)
  2513. {
  2514. setSize (startByte);
  2515. }
  2516. else if (numBytesToRemove > 0)
  2517. {
  2518. memmove (data + startByte,
  2519. data + startByte + numBytesToRemove,
  2520. size - (startByte + numBytesToRemove));
  2521. setSize (size - numBytesToRemove);
  2522. }
  2523. }
  2524. const String MemoryBlock::toString() const throw()
  2525. {
  2526. return String ((const char*) data, size);
  2527. }
  2528. int MemoryBlock::getBitRange (const size_t bitRangeStart, size_t numBits) const throw()
  2529. {
  2530. int res = 0;
  2531. size_t byte = bitRangeStart >> 3;
  2532. int offsetInByte = bitRangeStart & 7;
  2533. size_t bitsSoFar = 0;
  2534. while (numBits > 0 && (size_t) byte < size)
  2535. {
  2536. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2537. const int mask = (0xff >> (8 - bitsThisTime)) << offsetInByte;
  2538. res |= (((data[byte] & mask) >> offsetInByte) << bitsSoFar);
  2539. bitsSoFar += bitsThisTime;
  2540. numBits -= bitsThisTime;
  2541. ++byte;
  2542. offsetInByte = 0;
  2543. }
  2544. return res;
  2545. }
  2546. void MemoryBlock::setBitRange (const size_t bitRangeStart, size_t numBits, int bitsToSet) throw()
  2547. {
  2548. size_t byte = bitRangeStart >> 3;
  2549. int offsetInByte = bitRangeStart & 7;
  2550. unsigned int mask = ~((((unsigned int)0xffffffff) << (32 - numBits)) >> (32 - numBits));
  2551. while (numBits > 0 && (size_t) byte < size)
  2552. {
  2553. const int bitsThisTime = jmin ((int) numBits, 8 - offsetInByte);
  2554. const unsigned int tempMask = (mask << offsetInByte) | ~((((unsigned int)0xffffffff) >> offsetInByte) << offsetInByte);
  2555. const unsigned int tempBits = bitsToSet << offsetInByte;
  2556. data[byte] = (char)((data[byte] & tempMask) | tempBits);
  2557. ++byte;
  2558. numBits -= bitsThisTime;
  2559. bitsToSet >>= bitsThisTime;
  2560. mask >>= bitsThisTime;
  2561. offsetInByte = 0;
  2562. }
  2563. }
  2564. void MemoryBlock::loadFromHexString (const String& hex) throw()
  2565. {
  2566. ensureSize (hex.length() >> 1);
  2567. char* dest = data;
  2568. int i = 0;
  2569. for (;;)
  2570. {
  2571. int byte = 0;
  2572. for (int loop = 2; --loop >= 0;)
  2573. {
  2574. byte <<= 4;
  2575. for (;;)
  2576. {
  2577. const tchar c = hex [i++];
  2578. if (c >= T('0') && c <= T('9'))
  2579. {
  2580. byte |= c - T('0');
  2581. break;
  2582. }
  2583. else if (c >= T('a') && c <= T('z'))
  2584. {
  2585. byte |= c - (T('a') - 10);
  2586. break;
  2587. }
  2588. else if (c >= T('A') && c <= T('Z'))
  2589. {
  2590. byte |= c - (T('A') - 10);
  2591. break;
  2592. }
  2593. else if (c == 0)
  2594. {
  2595. setSize ((int) (dest - data));
  2596. return;
  2597. }
  2598. }
  2599. }
  2600. *dest++ = (char) byte;
  2601. }
  2602. }
  2603. static const char* const encodingTable
  2604. = ".ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+";
  2605. const String MemoryBlock::toBase64Encoding() const throw()
  2606. {
  2607. const size_t numChars = ((size << 3) + 5) / 6;
  2608. String destString ((unsigned int) size); // store the length, followed by a '.', and then the data.
  2609. const int initialLen = destString.length();
  2610. destString.preallocateStorage (initialLen + 2 + numChars);
  2611. tchar* d = const_cast <tchar*> (((const tchar*) destString) + initialLen);
  2612. *d++ = T('.');
  2613. for (size_t i = 0; i < numChars; ++i)
  2614. *d++ = encodingTable [getBitRange (i * 6, 6)];
  2615. *d++ = 0;
  2616. return destString;
  2617. }
  2618. bool MemoryBlock::fromBase64Encoding (const String& s) throw()
  2619. {
  2620. const int startPos = s.indexOfChar (T('.')) + 1;
  2621. if (startPos <= 0)
  2622. return false;
  2623. const int numBytesNeeded = s.substring (0, startPos - 1).getIntValue();
  2624. setSize (numBytesNeeded, true);
  2625. const int numChars = s.length() - startPos;
  2626. const tchar* const srcChars = ((const tchar*) s) + startPos;
  2627. int pos = 0;
  2628. for (int i = 0; i < numChars; ++i)
  2629. {
  2630. const char c = (char) srcChars[i];
  2631. for (int j = 0; j < 64; ++j)
  2632. {
  2633. if (encodingTable[j] == c)
  2634. {
  2635. setBitRange (pos, 6, j);
  2636. pos += 6;
  2637. break;
  2638. }
  2639. }
  2640. }
  2641. return true;
  2642. }
  2643. END_JUCE_NAMESPACE
  2644. /*** End of inlined file: juce_MemoryBlock.cpp ***/
  2645. /*** Start of inlined file: juce_PropertySet.cpp ***/
  2646. BEGIN_JUCE_NAMESPACE
  2647. PropertySet::PropertySet (const bool ignoreCaseOfKeyNames) throw()
  2648. : properties (ignoreCaseOfKeyNames),
  2649. fallbackProperties (0),
  2650. ignoreCaseOfKeys (ignoreCaseOfKeyNames)
  2651. {
  2652. }
  2653. PropertySet::PropertySet (const PropertySet& other) throw()
  2654. : properties (other.properties),
  2655. fallbackProperties (other.fallbackProperties),
  2656. ignoreCaseOfKeys (other.ignoreCaseOfKeys)
  2657. {
  2658. }
  2659. PropertySet& PropertySet::operator= (const PropertySet& other) throw()
  2660. {
  2661. properties = other.properties;
  2662. fallbackProperties = other.fallbackProperties;
  2663. ignoreCaseOfKeys = other.ignoreCaseOfKeys;
  2664. propertyChanged();
  2665. return *this;
  2666. }
  2667. PropertySet::~PropertySet()
  2668. {
  2669. }
  2670. void PropertySet::clear()
  2671. {
  2672. const ScopedLock sl (lock);
  2673. if (properties.size() > 0)
  2674. {
  2675. properties.clear();
  2676. propertyChanged();
  2677. }
  2678. }
  2679. const String PropertySet::getValue (const String& keyName,
  2680. const String& defaultValue) const throw()
  2681. {
  2682. const ScopedLock sl (lock);
  2683. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2684. if (index >= 0)
  2685. return properties.getAllValues() [index];
  2686. return fallbackProperties != 0 ? fallbackProperties->getValue (keyName, defaultValue)
  2687. : defaultValue;
  2688. }
  2689. int PropertySet::getIntValue (const String& keyName,
  2690. const int defaultValue) const throw()
  2691. {
  2692. const ScopedLock sl (lock);
  2693. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2694. if (index >= 0)
  2695. return properties.getAllValues() [index].getIntValue();
  2696. return fallbackProperties != 0 ? fallbackProperties->getIntValue (keyName, defaultValue)
  2697. : defaultValue;
  2698. }
  2699. double PropertySet::getDoubleValue (const String& keyName,
  2700. const double defaultValue) const throw()
  2701. {
  2702. const ScopedLock sl (lock);
  2703. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2704. if (index >= 0)
  2705. return properties.getAllValues()[index].getDoubleValue();
  2706. return fallbackProperties != 0 ? fallbackProperties->getDoubleValue (keyName, defaultValue)
  2707. : defaultValue;
  2708. }
  2709. bool PropertySet::getBoolValue (const String& keyName,
  2710. const bool defaultValue) const throw()
  2711. {
  2712. const ScopedLock sl (lock);
  2713. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2714. if (index >= 0)
  2715. return properties.getAllValues() [index].getIntValue() != 0;
  2716. return fallbackProperties != 0 ? fallbackProperties->getBoolValue (keyName, defaultValue)
  2717. : defaultValue;
  2718. }
  2719. XmlElement* PropertySet::getXmlValue (const String& keyName) const
  2720. {
  2721. XmlDocument doc (getValue (keyName));
  2722. return doc.getDocumentElement();
  2723. }
  2724. void PropertySet::setValue (const String& keyName,
  2725. const String& value) throw()
  2726. {
  2727. jassert (keyName.isNotEmpty()); // shouldn't use an empty key name!
  2728. if (keyName.isNotEmpty())
  2729. {
  2730. const ScopedLock sl (lock);
  2731. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2732. if (index < 0 || properties.getAllValues() [index] != value)
  2733. {
  2734. properties.set (keyName, value);
  2735. propertyChanged();
  2736. }
  2737. }
  2738. }
  2739. void PropertySet::removeValue (const String& keyName) throw()
  2740. {
  2741. if (keyName.isNotEmpty())
  2742. {
  2743. const ScopedLock sl (lock);
  2744. const int index = properties.getAllKeys().indexOf (keyName, ignoreCaseOfKeys);
  2745. if (index >= 0)
  2746. {
  2747. properties.remove (keyName);
  2748. propertyChanged();
  2749. }
  2750. }
  2751. }
  2752. void PropertySet::setValue (const String& keyName, const tchar* const value) throw()
  2753. {
  2754. setValue (keyName, String (value));
  2755. }
  2756. void PropertySet::setValue (const String& keyName, const int value) throw()
  2757. {
  2758. setValue (keyName, String (value));
  2759. }
  2760. void PropertySet::setValue (const String& keyName, const double value) throw()
  2761. {
  2762. setValue (keyName, String (value));
  2763. }
  2764. void PropertySet::setValue (const String& keyName, const bool value) throw()
  2765. {
  2766. setValue (keyName, String ((value) ? T("1") : T("0")));
  2767. }
  2768. void PropertySet::setValue (const String& keyName, const XmlElement* const xml)
  2769. {
  2770. setValue (keyName, (xml == 0) ? String::empty
  2771. : xml->createDocument (String::empty, true));
  2772. }
  2773. bool PropertySet::containsKey (const String& keyName) const throw()
  2774. {
  2775. const ScopedLock sl (lock);
  2776. return properties.getAllKeys().contains (keyName, ignoreCaseOfKeys);
  2777. }
  2778. void PropertySet::setFallbackPropertySet (PropertySet* fallbackProperties_) throw()
  2779. {
  2780. const ScopedLock sl (lock);
  2781. fallbackProperties = fallbackProperties_;
  2782. }
  2783. XmlElement* PropertySet::createXml (const String& nodeName) const throw()
  2784. {
  2785. const ScopedLock sl (lock);
  2786. XmlElement* const xml = new XmlElement (nodeName);
  2787. for (int i = 0; i < properties.getAllKeys().size(); ++i)
  2788. {
  2789. XmlElement* const e = xml->createNewChildElement ("VALUE");
  2790. e->setAttribute (T("name"), properties.getAllKeys()[i]);
  2791. e->setAttribute (T("val"), properties.getAllValues()[i]);
  2792. }
  2793. return xml;
  2794. }
  2795. void PropertySet::restoreFromXml (const XmlElement& xml) throw()
  2796. {
  2797. const ScopedLock sl (lock);
  2798. clear();
  2799. forEachXmlChildElementWithTagName (xml, e, T("VALUE"))
  2800. {
  2801. if (e->hasAttribute (T("name"))
  2802. && e->hasAttribute (T("val")))
  2803. {
  2804. properties.set (e->getStringAttribute (T("name")),
  2805. e->getStringAttribute (T("val")));
  2806. }
  2807. }
  2808. if (properties.size() > 0)
  2809. propertyChanged();
  2810. }
  2811. void PropertySet::propertyChanged()
  2812. {
  2813. }
  2814. END_JUCE_NAMESPACE
  2815. /*** End of inlined file: juce_PropertySet.cpp ***/
  2816. /*** Start of inlined file: juce_Variant.cpp ***/
  2817. BEGIN_JUCE_NAMESPACE
  2818. var::var() throw()
  2819. : type (voidType)
  2820. {
  2821. value.doubleValue = 0;
  2822. }
  2823. var::~var() throw()
  2824. {
  2825. if (type == stringType)
  2826. delete value.stringValue;
  2827. else if (type == objectType && value.objectValue != 0)
  2828. value.objectValue->decReferenceCount();
  2829. }
  2830. const var var::null;
  2831. var::var (const var& valueToCopy)
  2832. : type (valueToCopy.type),
  2833. value (valueToCopy.value)
  2834. {
  2835. if (type == stringType)
  2836. value.stringValue = new String (*(value.stringValue));
  2837. else if (type == objectType && value.objectValue != 0)
  2838. value.objectValue->incReferenceCount();
  2839. }
  2840. var::var (const int value_) throw()
  2841. : type (intType)
  2842. {
  2843. value.intValue = value_;
  2844. }
  2845. var::var (const bool value_) throw()
  2846. : type (boolType)
  2847. {
  2848. value.boolValue = value_;
  2849. }
  2850. var::var (const double value_) throw()
  2851. : type (doubleType)
  2852. {
  2853. value.doubleValue = value_;
  2854. }
  2855. var::var (const String& value_)
  2856. : type (stringType)
  2857. {
  2858. value.stringValue = new String (value_);
  2859. }
  2860. var::var (const char* const value_)
  2861. : type (stringType)
  2862. {
  2863. value.stringValue = new String (value_);
  2864. }
  2865. var::var (const juce_wchar* const value_)
  2866. : type (stringType)
  2867. {
  2868. value.stringValue = new String (value_);
  2869. }
  2870. var::var (DynamicObject* const object)
  2871. : type (objectType)
  2872. {
  2873. value.objectValue = object;
  2874. if (object != 0)
  2875. object->incReferenceCount();
  2876. }
  2877. var::var (MethodFunction method_) throw()
  2878. : type (methodType)
  2879. {
  2880. value.methodValue = method_;
  2881. }
  2882. void var::swapWith (var& other) throw()
  2883. {
  2884. swapVariables (type, other.type);
  2885. swapVariables (value, other.value);
  2886. }
  2887. var& var::operator= (const var& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2888. var& var::operator= (int value_) { var newValue (value_); swapWith (newValue); return *this; }
  2889. var& var::operator= (bool value_) { var newValue (value_); swapWith (newValue); return *this; }
  2890. var& var::operator= (double value_) { var newValue (value_); swapWith (newValue); return *this; }
  2891. var& var::operator= (const char* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2892. var& var::operator= (const juce_wchar* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2893. var& var::operator= (const String& value_) { var newValue (value_); swapWith (newValue); return *this; }
  2894. var& var::operator= (DynamicObject* value_) { var newValue (value_); swapWith (newValue); return *this; }
  2895. var& var::operator= (MethodFunction value_) { var newValue (value_); swapWith (newValue); return *this; }
  2896. var::operator int() const
  2897. {
  2898. switch (type)
  2899. {
  2900. case voidType: break;
  2901. case intType: return value.intValue;
  2902. case boolType: return value.boolValue ? 1 : 0;
  2903. case doubleType: return (int) value.doubleValue;
  2904. case stringType: return value.stringValue->getIntValue();
  2905. case objectType: break;
  2906. default: jassertfalse; break;
  2907. }
  2908. return 0;
  2909. }
  2910. var::operator bool() const
  2911. {
  2912. switch (type)
  2913. {
  2914. case voidType: break;
  2915. case intType: return value.intValue != 0;
  2916. case boolType: return value.boolValue;
  2917. case doubleType: return value.doubleValue != 0;
  2918. case stringType: return value.stringValue->getIntValue() != 0
  2919. || value.stringValue->trim().equalsIgnoreCase (T("true"))
  2920. || value.stringValue->trim().equalsIgnoreCase (T("yes"));
  2921. case objectType: return value.objectValue != 0;
  2922. default: jassertfalse; break;
  2923. }
  2924. return false;
  2925. }
  2926. var::operator float() const
  2927. {
  2928. return (float) operator double();
  2929. }
  2930. var::operator double() const
  2931. {
  2932. switch (type)
  2933. {
  2934. case voidType: break;
  2935. case intType: return value.intValue;
  2936. case boolType: return value.boolValue ? 1.0 : 0.0;
  2937. case doubleType: return value.doubleValue;
  2938. case stringType: return value.stringValue->getDoubleValue();
  2939. case objectType: break;
  2940. default: jassertfalse; break;
  2941. }
  2942. return 0.0;
  2943. }
  2944. const String var::toString() const
  2945. {
  2946. switch (type)
  2947. {
  2948. case voidType: return String::empty;
  2949. case intType: return String (value.intValue);
  2950. case boolType: return value.boolValue ? T("1") : T("0");
  2951. case doubleType: return String (value.doubleValue);
  2952. case stringType: return *(value.stringValue);
  2953. case objectType: return "Object 0x" + String::toHexString ((int) (pointer_sized_int) value.objectValue);
  2954. case methodType: return "Method";
  2955. default: jassertfalse; break;
  2956. }
  2957. return String::empty;
  2958. }
  2959. var::operator const String() const
  2960. {
  2961. return toString();
  2962. }
  2963. DynamicObject* var::getObject() const
  2964. {
  2965. return type == objectType ? value.objectValue : 0;
  2966. }
  2967. bool var::operator== (const var& other) const throw()
  2968. {
  2969. switch (type)
  2970. {
  2971. case voidType: return other.isVoid();
  2972. case intType: return value.intValue == (int) other;
  2973. case boolType: return value.boolValue == (bool) other;
  2974. case doubleType: return value.doubleValue == (double) other;
  2975. case stringType: return (*(value.stringValue)) == other.toString();
  2976. case objectType: return value.objectValue == other.getObject();
  2977. case methodType: return value.methodValue == other.value.methodValue && other.isMethod();
  2978. default: jassertfalse; break;
  2979. }
  2980. return false;
  2981. }
  2982. bool var::operator!= (const var& other) const throw()
  2983. {
  2984. return ! operator== (other);
  2985. }
  2986. void var::writeToStream (OutputStream& output) const
  2987. {
  2988. switch (type)
  2989. {
  2990. case voidType: output.writeCompressedInt (0); break;
  2991. case intType: output.writeCompressedInt (5); output.writeByte (1); output.writeInt (value.intValue); break;
  2992. case boolType: output.writeCompressedInt (1); output.writeByte (value.boolValue ? 2 : 3); break;
  2993. case doubleType: output.writeCompressedInt (9); output.writeByte (4); output.writeDouble (value.doubleValue); break;
  2994. case stringType:
  2995. {
  2996. const int len = value.stringValue->getNumBytesAsUTF8() + 1;
  2997. output.writeCompressedInt (len + 1);
  2998. output.writeByte (5);
  2999. HeapBlock <uint8> temp (len);
  3000. value.stringValue->copyToUTF8 (temp, len);
  3001. output.write (temp, len);
  3002. break;
  3003. }
  3004. case objectType:
  3005. case methodType: output.writeCompressedInt (0); jassertfalse; break; // Can't write an object to a stream!
  3006. default: jassertfalse; break; // Is this a corrupted object?
  3007. }
  3008. }
  3009. const var var::readFromStream (InputStream& input)
  3010. {
  3011. const int numBytes = input.readCompressedInt();
  3012. if (numBytes > 0)
  3013. {
  3014. switch (input.readByte())
  3015. {
  3016. case 1: return var (input.readInt());
  3017. case 2: return var (true);
  3018. case 3: return var (false);
  3019. case 4: return var (input.readDouble());
  3020. case 5:
  3021. {
  3022. MemoryBlock mb;
  3023. input.readIntoMemoryBlock (mb, numBytes - 1);
  3024. return var (String::fromUTF8 ((const char*) mb.getData(), (int) mb.getSize()));
  3025. }
  3026. default: input.skipNextBytes (numBytes - 1); break;
  3027. }
  3028. }
  3029. return var::null;
  3030. }
  3031. const var var::operator[] (const var::identifier& propertyName) const
  3032. {
  3033. if (type == objectType && value.objectValue != 0)
  3034. return value.objectValue->getProperty (propertyName);
  3035. return var::null;
  3036. }
  3037. const var var::invoke (const var::identifier& method, const var* arguments, int numArguments) const
  3038. {
  3039. if (type == objectType && value.objectValue != 0)
  3040. return value.objectValue->invokeMethod (method, arguments, numArguments);
  3041. return var::null;
  3042. }
  3043. const var var::invoke (const var& targetObject, const var* arguments, int numArguments) const
  3044. {
  3045. if (isMethod())
  3046. {
  3047. DynamicObject* const target = targetObject.getObject();
  3048. if (target != 0)
  3049. return (target->*(value.methodValue)) (arguments, numArguments);
  3050. }
  3051. return var::null;
  3052. }
  3053. const var var::call (const var::identifier& method) const
  3054. {
  3055. return invoke (method, 0, 0);
  3056. }
  3057. const var var::call (const var::identifier& method, const var& arg1) const
  3058. {
  3059. return invoke (method, &arg1, 1);
  3060. }
  3061. const var var::call (const var::identifier& method, const var& arg1, const var& arg2) const
  3062. {
  3063. var args[] = { arg1, arg2 };
  3064. return invoke (method, args, 2);
  3065. }
  3066. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3)
  3067. {
  3068. var args[] = { arg1, arg2, arg3 };
  3069. return invoke (method, args, 3);
  3070. }
  3071. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4) const
  3072. {
  3073. var args[] = { arg1, arg2, arg3, arg4 };
  3074. return invoke (method, args, 4);
  3075. }
  3076. const var var::call (const var::identifier& method, const var& arg1, const var& arg2, const var& arg3, const var& arg4, const var& arg5) const
  3077. {
  3078. var args[] = { arg1, arg2, arg3, arg4, arg5 };
  3079. return invoke (method, args, 5);
  3080. }
  3081. var::identifier::identifier() throw()
  3082. : hashCode (0)
  3083. {
  3084. }
  3085. var::identifier::identifier (const String& name_)
  3086. : name (name_),
  3087. hashCode (name_.hashCode())
  3088. {
  3089. /* An identifier string must be suitable for use as a script variable or XML
  3090. attribute, so it can only contain this limited set of characters.. */
  3091. jassert (name.containsOnly (T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")) && name.isNotEmpty());
  3092. }
  3093. var::identifier::identifier (const char* const name_)
  3094. : name (name_),
  3095. hashCode (name.hashCode())
  3096. {
  3097. /* An identifier string must be suitable for use as a script variable or XML
  3098. attribute, so it can only contain this limited set of characters.. */
  3099. jassert (name.containsOnly (T("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_")) && name.isNotEmpty());
  3100. }
  3101. var::identifier::~identifier()
  3102. {
  3103. }
  3104. END_JUCE_NAMESPACE
  3105. /*** End of inlined file: juce_Variant.cpp ***/
  3106. /*** Start of inlined file: juce_NamedValueSet.cpp ***/
  3107. BEGIN_JUCE_NAMESPACE
  3108. NamedValueSet::NamedValue::NamedValue() throw()
  3109. {
  3110. }
  3111. inline NamedValueSet::NamedValue::NamedValue (const var::identifier& name_, const var& value_)
  3112. : name (name_), value (value_)
  3113. {
  3114. }
  3115. NamedValueSet::NamedValueSet() throw()
  3116. {
  3117. }
  3118. NamedValueSet::NamedValueSet (const NamedValueSet& other)
  3119. : values (other.values)
  3120. {
  3121. }
  3122. NamedValueSet& NamedValueSet::operator= (const NamedValueSet& other)
  3123. {
  3124. values = other.values;
  3125. return *this;
  3126. }
  3127. NamedValueSet::~NamedValueSet()
  3128. {
  3129. }
  3130. int NamedValueSet::size() const throw()
  3131. {
  3132. return values.size();
  3133. }
  3134. const var& NamedValueSet::operator[] (const var::identifier& name) const
  3135. {
  3136. for (int i = values.size(); --i >= 0;)
  3137. {
  3138. const NamedValue& v = values.getReference(i);
  3139. if (v.name == name)
  3140. return v.value;
  3141. }
  3142. return var::null;
  3143. }
  3144. const var NamedValueSet::getWithDefault (const var::identifier& name, const var& defaultReturnValue) const
  3145. {
  3146. const var* v = getItem (name);
  3147. return v != 0 ? *v : defaultReturnValue;
  3148. }
  3149. var* NamedValueSet::getItem (const var::identifier& name) const
  3150. {
  3151. for (int i = values.size(); --i >= 0;)
  3152. {
  3153. NamedValue& v = values.getReference(i);
  3154. if (v.name == name)
  3155. return &(v.value);
  3156. }
  3157. return 0;
  3158. }
  3159. bool NamedValueSet::set (const var::identifier& name, const var& newValue)
  3160. {
  3161. for (int i = values.size(); --i >= 0;)
  3162. {
  3163. NamedValue& v = values.getReference(i);
  3164. if (v.name == name)
  3165. {
  3166. if (v.value == newValue)
  3167. return false;
  3168. v.value = newValue;
  3169. return true;
  3170. }
  3171. }
  3172. values.add (NamedValue (name, newValue));
  3173. return true;
  3174. }
  3175. bool NamedValueSet::contains (const var::identifier& name) const
  3176. {
  3177. return getItem (name) != 0;
  3178. }
  3179. bool NamedValueSet::remove (const var::identifier& name)
  3180. {
  3181. for (int i = values.size(); --i >= 0;)
  3182. {
  3183. if (values.getReference(i).name == name)
  3184. {
  3185. values.remove (i);
  3186. return true;
  3187. }
  3188. }
  3189. return false;
  3190. }
  3191. const var::identifier NamedValueSet::getName (int index) const
  3192. {
  3193. jassert (((unsigned int) index) < (unsigned int) values.size());
  3194. return values [index].name;
  3195. }
  3196. void NamedValueSet::clear()
  3197. {
  3198. values.clear();
  3199. }
  3200. END_JUCE_NAMESPACE
  3201. /*** End of inlined file: juce_NamedValueSet.cpp ***/
  3202. /*** Start of inlined file: juce_DynamicObject.cpp ***/
  3203. BEGIN_JUCE_NAMESPACE
  3204. DynamicObject::DynamicObject()
  3205. {
  3206. }
  3207. DynamicObject::~DynamicObject()
  3208. {
  3209. }
  3210. bool DynamicObject::hasProperty (const var::identifier& propertyName) const
  3211. {
  3212. var* const v = properties.getItem (propertyName);
  3213. return v != 0 && ! v->isMethod();
  3214. }
  3215. const var DynamicObject::getProperty (const var::identifier& propertyName) const
  3216. {
  3217. return properties [propertyName];
  3218. }
  3219. void DynamicObject::setProperty (const var::identifier& propertyName, const var& newValue)
  3220. {
  3221. properties.set (propertyName, newValue);
  3222. }
  3223. void DynamicObject::removeProperty (const var::identifier& propertyName)
  3224. {
  3225. properties.remove (propertyName);
  3226. }
  3227. bool DynamicObject::hasMethod (const var::identifier& methodName) const
  3228. {
  3229. return getProperty (methodName).isMethod();
  3230. }
  3231. const var DynamicObject::invokeMethod (const var::identifier& methodName,
  3232. const var* parameters,
  3233. int numParameters)
  3234. {
  3235. return properties [methodName].invoke (var (this), parameters, numParameters);
  3236. }
  3237. void DynamicObject::setMethod (const var::identifier& name,
  3238. var::MethodFunction methodFunction)
  3239. {
  3240. properties.set (name, var (methodFunction));
  3241. }
  3242. void DynamicObject::clear()
  3243. {
  3244. properties.clear();
  3245. }
  3246. END_JUCE_NAMESPACE
  3247. /*** End of inlined file: juce_DynamicObject.cpp ***/
  3248. /*** Start of inlined file: juce_BlowFish.cpp ***/
  3249. BEGIN_JUCE_NAMESPACE
  3250. static const uint32 initialPValues [18] =
  3251. {
  3252. 0x243f6a88, 0x85a308d3, 0x13198a2e, 0x03707344,
  3253. 0xa4093822, 0x299f31d0, 0x082efa98, 0xec4e6c89,
  3254. 0x452821e6, 0x38d01377, 0xbe5466cf, 0x34e90c6c,
  3255. 0xc0ac29b7, 0xc97c50dd, 0x3f84d5b5, 0xb5470917,
  3256. 0x9216d5d9, 0x8979fb1b
  3257. };
  3258. static const uint32 initialSValues [4 * 256] =
  3259. {
  3260. 0xd1310ba6, 0x98dfb5ac, 0x2ffd72db, 0xd01adfb7,
  3261. 0xb8e1afed, 0x6a267e96, 0xba7c9045, 0xf12c7f99,
  3262. 0x24a19947, 0xb3916cf7, 0x0801f2e2, 0x858efc16,
  3263. 0x636920d8, 0x71574e69, 0xa458fea3, 0xf4933d7e,
  3264. 0x0d95748f, 0x728eb658, 0x718bcd58, 0x82154aee,
  3265. 0x7b54a41d, 0xc25a59b5, 0x9c30d539, 0x2af26013,
  3266. 0xc5d1b023, 0x286085f0, 0xca417918, 0xb8db38ef,
  3267. 0x8e79dcb0, 0x603a180e, 0x6c9e0e8b, 0xb01e8a3e,
  3268. 0xd71577c1, 0xbd314b27, 0x78af2fda, 0x55605c60,
  3269. 0xe65525f3, 0xaa55ab94, 0x57489862, 0x63e81440,
  3270. 0x55ca396a, 0x2aab10b6, 0xb4cc5c34, 0x1141e8ce,
  3271. 0xa15486af, 0x7c72e993, 0xb3ee1411, 0x636fbc2a,
  3272. 0x2ba9c55d, 0x741831f6, 0xce5c3e16, 0x9b87931e,
  3273. 0xafd6ba33, 0x6c24cf5c, 0x7a325381, 0x28958677,
  3274. 0x3b8f4898, 0x6b4bb9af, 0xc4bfe81b, 0x66282193,
  3275. 0x61d809cc, 0xfb21a991, 0x487cac60, 0x5dec8032,
  3276. 0xef845d5d, 0xe98575b1, 0xdc262302, 0xeb651b88,
  3277. 0x23893e81, 0xd396acc5, 0x0f6d6ff3, 0x83f44239,
  3278. 0x2e0b4482, 0xa4842004, 0x69c8f04a, 0x9e1f9b5e,
  3279. 0x21c66842, 0xf6e96c9a, 0x670c9c61, 0xabd388f0,
  3280. 0x6a51a0d2, 0xd8542f68, 0x960fa728, 0xab5133a3,
  3281. 0x6eef0b6c, 0x137a3be4, 0xba3bf050, 0x7efb2a98,
  3282. 0xa1f1651d, 0x39af0176, 0x66ca593e, 0x82430e88,
  3283. 0x8cee8619, 0x456f9fb4, 0x7d84a5c3, 0x3b8b5ebe,
  3284. 0xe06f75d8, 0x85c12073, 0x401a449f, 0x56c16aa6,
  3285. 0x4ed3aa62, 0x363f7706, 0x1bfedf72, 0x429b023d,
  3286. 0x37d0d724, 0xd00a1248, 0xdb0fead3, 0x49f1c09b,
  3287. 0x075372c9, 0x80991b7b, 0x25d479d8, 0xf6e8def7,
  3288. 0xe3fe501a, 0xb6794c3b, 0x976ce0bd, 0x04c006ba,
  3289. 0xc1a94fb6, 0x409f60c4, 0x5e5c9ec2, 0x196a2463,
  3290. 0x68fb6faf, 0x3e6c53b5, 0x1339b2eb, 0x3b52ec6f,
  3291. 0x6dfc511f, 0x9b30952c, 0xcc814544, 0xaf5ebd09,
  3292. 0xbee3d004, 0xde334afd, 0x660f2807, 0x192e4bb3,
  3293. 0xc0cba857, 0x45c8740f, 0xd20b5f39, 0xb9d3fbdb,
  3294. 0x5579c0bd, 0x1a60320a, 0xd6a100c6, 0x402c7279,
  3295. 0x679f25fe, 0xfb1fa3cc, 0x8ea5e9f8, 0xdb3222f8,
  3296. 0x3c7516df, 0xfd616b15, 0x2f501ec8, 0xad0552ab,
  3297. 0x323db5fa, 0xfd238760, 0x53317b48, 0x3e00df82,
  3298. 0x9e5c57bb, 0xca6f8ca0, 0x1a87562e, 0xdf1769db,
  3299. 0xd542a8f6, 0x287effc3, 0xac6732c6, 0x8c4f5573,
  3300. 0x695b27b0, 0xbbca58c8, 0xe1ffa35d, 0xb8f011a0,
  3301. 0x10fa3d98, 0xfd2183b8, 0x4afcb56c, 0x2dd1d35b,
  3302. 0x9a53e479, 0xb6f84565, 0xd28e49bc, 0x4bfb9790,
  3303. 0xe1ddf2da, 0xa4cb7e33, 0x62fb1341, 0xcee4c6e8,
  3304. 0xef20cada, 0x36774c01, 0xd07e9efe, 0x2bf11fb4,
  3305. 0x95dbda4d, 0xae909198, 0xeaad8e71, 0x6b93d5a0,
  3306. 0xd08ed1d0, 0xafc725e0, 0x8e3c5b2f, 0x8e7594b7,
  3307. 0x8ff6e2fb, 0xf2122b64, 0x8888b812, 0x900df01c,
  3308. 0x4fad5ea0, 0x688fc31c, 0xd1cff191, 0xb3a8c1ad,
  3309. 0x2f2f2218, 0xbe0e1777, 0xea752dfe, 0x8b021fa1,
  3310. 0xe5a0cc0f, 0xb56f74e8, 0x18acf3d6, 0xce89e299,
  3311. 0xb4a84fe0, 0xfd13e0b7, 0x7cc43b81, 0xd2ada8d9,
  3312. 0x165fa266, 0x80957705, 0x93cc7314, 0x211a1477,
  3313. 0xe6ad2065, 0x77b5fa86, 0xc75442f5, 0xfb9d35cf,
  3314. 0xebcdaf0c, 0x7b3e89a0, 0xd6411bd3, 0xae1e7e49,
  3315. 0x00250e2d, 0x2071b35e, 0x226800bb, 0x57b8e0af,
  3316. 0x2464369b, 0xf009b91e, 0x5563911d, 0x59dfa6aa,
  3317. 0x78c14389, 0xd95a537f, 0x207d5ba2, 0x02e5b9c5,
  3318. 0x83260376, 0x6295cfa9, 0x11c81968, 0x4e734a41,
  3319. 0xb3472dca, 0x7b14a94a, 0x1b510052, 0x9a532915,
  3320. 0xd60f573f, 0xbc9bc6e4, 0x2b60a476, 0x81e67400,
  3321. 0x08ba6fb5, 0x571be91f, 0xf296ec6b, 0x2a0dd915,
  3322. 0xb6636521, 0xe7b9f9b6, 0xff34052e, 0xc5855664,
  3323. 0x53b02d5d, 0xa99f8fa1, 0x08ba4799, 0x6e85076a,
  3324. 0x4b7a70e9, 0xb5b32944, 0xdb75092e, 0xc4192623,
  3325. 0xad6ea6b0, 0x49a7df7d, 0x9cee60b8, 0x8fedb266,
  3326. 0xecaa8c71, 0x699a17ff, 0x5664526c, 0xc2b19ee1,
  3327. 0x193602a5, 0x75094c29, 0xa0591340, 0xe4183a3e,
  3328. 0x3f54989a, 0x5b429d65, 0x6b8fe4d6, 0x99f73fd6,
  3329. 0xa1d29c07, 0xefe830f5, 0x4d2d38e6, 0xf0255dc1,
  3330. 0x4cdd2086, 0x8470eb26, 0x6382e9c6, 0x021ecc5e,
  3331. 0x09686b3f, 0x3ebaefc9, 0x3c971814, 0x6b6a70a1,
  3332. 0x687f3584, 0x52a0e286, 0xb79c5305, 0xaa500737,
  3333. 0x3e07841c, 0x7fdeae5c, 0x8e7d44ec, 0x5716f2b8,
  3334. 0xb03ada37, 0xf0500c0d, 0xf01c1f04, 0x0200b3ff,
  3335. 0xae0cf51a, 0x3cb574b2, 0x25837a58, 0xdc0921bd,
  3336. 0xd19113f9, 0x7ca92ff6, 0x94324773, 0x22f54701,
  3337. 0x3ae5e581, 0x37c2dadc, 0xc8b57634, 0x9af3dda7,
  3338. 0xa9446146, 0x0fd0030e, 0xecc8c73e, 0xa4751e41,
  3339. 0xe238cd99, 0x3bea0e2f, 0x3280bba1, 0x183eb331,
  3340. 0x4e548b38, 0x4f6db908, 0x6f420d03, 0xf60a04bf,
  3341. 0x2cb81290, 0x24977c79, 0x5679b072, 0xbcaf89af,
  3342. 0xde9a771f, 0xd9930810, 0xb38bae12, 0xdccf3f2e,
  3343. 0x5512721f, 0x2e6b7124, 0x501adde6, 0x9f84cd87,
  3344. 0x7a584718, 0x7408da17, 0xbc9f9abc, 0xe94b7d8c,
  3345. 0xec7aec3a, 0xdb851dfa, 0x63094366, 0xc464c3d2,
  3346. 0xef1c1847, 0x3215d908, 0xdd433b37, 0x24c2ba16,
  3347. 0x12a14d43, 0x2a65c451, 0x50940002, 0x133ae4dd,
  3348. 0x71dff89e, 0x10314e55, 0x81ac77d6, 0x5f11199b,
  3349. 0x043556f1, 0xd7a3c76b, 0x3c11183b, 0x5924a509,
  3350. 0xf28fe6ed, 0x97f1fbfa, 0x9ebabf2c, 0x1e153c6e,
  3351. 0x86e34570, 0xeae96fb1, 0x860e5e0a, 0x5a3e2ab3,
  3352. 0x771fe71c, 0x4e3d06fa, 0x2965dcb9, 0x99e71d0f,
  3353. 0x803e89d6, 0x5266c825, 0x2e4cc978, 0x9c10b36a,
  3354. 0xc6150eba, 0x94e2ea78, 0xa5fc3c53, 0x1e0a2df4,
  3355. 0xf2f74ea7, 0x361d2b3d, 0x1939260f, 0x19c27960,
  3356. 0x5223a708, 0xf71312b6, 0xebadfe6e, 0xeac31f66,
  3357. 0xe3bc4595, 0xa67bc883, 0xb17f37d1, 0x018cff28,
  3358. 0xc332ddef, 0xbe6c5aa5, 0x65582185, 0x68ab9802,
  3359. 0xeecea50f, 0xdb2f953b, 0x2aef7dad, 0x5b6e2f84,
  3360. 0x1521b628, 0x29076170, 0xecdd4775, 0x619f1510,
  3361. 0x13cca830, 0xeb61bd96, 0x0334fe1e, 0xaa0363cf,
  3362. 0xb5735c90, 0x4c70a239, 0xd59e9e0b, 0xcbaade14,
  3363. 0xeecc86bc, 0x60622ca7, 0x9cab5cab, 0xb2f3846e,
  3364. 0x648b1eaf, 0x19bdf0ca, 0xa02369b9, 0x655abb50,
  3365. 0x40685a32, 0x3c2ab4b3, 0x319ee9d5, 0xc021b8f7,
  3366. 0x9b540b19, 0x875fa099, 0x95f7997e, 0x623d7da8,
  3367. 0xf837889a, 0x97e32d77, 0x11ed935f, 0x16681281,
  3368. 0x0e358829, 0xc7e61fd6, 0x96dedfa1, 0x7858ba99,
  3369. 0x57f584a5, 0x1b227263, 0x9b83c3ff, 0x1ac24696,
  3370. 0xcdb30aeb, 0x532e3054, 0x8fd948e4, 0x6dbc3128,
  3371. 0x58ebf2ef, 0x34c6ffea, 0xfe28ed61, 0xee7c3c73,
  3372. 0x5d4a14d9, 0xe864b7e3, 0x42105d14, 0x203e13e0,
  3373. 0x45eee2b6, 0xa3aaabea, 0xdb6c4f15, 0xfacb4fd0,
  3374. 0xc742f442, 0xef6abbb5, 0x654f3b1d, 0x41cd2105,
  3375. 0xd81e799e, 0x86854dc7, 0xe44b476a, 0x3d816250,
  3376. 0xcf62a1f2, 0x5b8d2646, 0xfc8883a0, 0xc1c7b6a3,
  3377. 0x7f1524c3, 0x69cb7492, 0x47848a0b, 0x5692b285,
  3378. 0x095bbf00, 0xad19489d, 0x1462b174, 0x23820e00,
  3379. 0x58428d2a, 0x0c55f5ea, 0x1dadf43e, 0x233f7061,
  3380. 0x3372f092, 0x8d937e41, 0xd65fecf1, 0x6c223bdb,
  3381. 0x7cde3759, 0xcbee7460, 0x4085f2a7, 0xce77326e,
  3382. 0xa6078084, 0x19f8509e, 0xe8efd855, 0x61d99735,
  3383. 0xa969a7aa, 0xc50c06c2, 0x5a04abfc, 0x800bcadc,
  3384. 0x9e447a2e, 0xc3453484, 0xfdd56705, 0x0e1e9ec9,
  3385. 0xdb73dbd3, 0x105588cd, 0x675fda79, 0xe3674340,
  3386. 0xc5c43465, 0x713e38d8, 0x3d28f89e, 0xf16dff20,
  3387. 0x153e21e7, 0x8fb03d4a, 0xe6e39f2b, 0xdb83adf7,
  3388. 0xe93d5a68, 0x948140f7, 0xf64c261c, 0x94692934,
  3389. 0x411520f7, 0x7602d4f7, 0xbcf46b2e, 0xd4a20068,
  3390. 0xd4082471, 0x3320f46a, 0x43b7d4b7, 0x500061af,
  3391. 0x1e39f62e, 0x97244546, 0x14214f74, 0xbf8b8840,
  3392. 0x4d95fc1d, 0x96b591af, 0x70f4ddd3, 0x66a02f45,
  3393. 0xbfbc09ec, 0x03bd9785, 0x7fac6dd0, 0x31cb8504,
  3394. 0x96eb27b3, 0x55fd3941, 0xda2547e6, 0xabca0a9a,
  3395. 0x28507825, 0x530429f4, 0x0a2c86da, 0xe9b66dfb,
  3396. 0x68dc1462, 0xd7486900, 0x680ec0a4, 0x27a18dee,
  3397. 0x4f3ffea2, 0xe887ad8c, 0xb58ce006, 0x7af4d6b6,
  3398. 0xaace1e7c, 0xd3375fec, 0xce78a399, 0x406b2a42,
  3399. 0x20fe9e35, 0xd9f385b9, 0xee39d7ab, 0x3b124e8b,
  3400. 0x1dc9faf7, 0x4b6d1856, 0x26a36631, 0xeae397b2,
  3401. 0x3a6efa74, 0xdd5b4332, 0x6841e7f7, 0xca7820fb,
  3402. 0xfb0af54e, 0xd8feb397, 0x454056ac, 0xba489527,
  3403. 0x55533a3a, 0x20838d87, 0xfe6ba9b7, 0xd096954b,
  3404. 0x55a867bc, 0xa1159a58, 0xcca92963, 0x99e1db33,
  3405. 0xa62a4a56, 0x3f3125f9, 0x5ef47e1c, 0x9029317c,
  3406. 0xfdf8e802, 0x04272f70, 0x80bb155c, 0x05282ce3,
  3407. 0x95c11548, 0xe4c66d22, 0x48c1133f, 0xc70f86dc,
  3408. 0x07f9c9ee, 0x41041f0f, 0x404779a4, 0x5d886e17,
  3409. 0x325f51eb, 0xd59bc0d1, 0xf2bcc18f, 0x41113564,
  3410. 0x257b7834, 0x602a9c60, 0xdff8e8a3, 0x1f636c1b,
  3411. 0x0e12b4c2, 0x02e1329e, 0xaf664fd1, 0xcad18115,
  3412. 0x6b2395e0, 0x333e92e1, 0x3b240b62, 0xeebeb922,
  3413. 0x85b2a20e, 0xe6ba0d99, 0xde720c8c, 0x2da2f728,
  3414. 0xd0127845, 0x95b794fd, 0x647d0862, 0xe7ccf5f0,
  3415. 0x5449a36f, 0x877d48fa, 0xc39dfd27, 0xf33e8d1e,
  3416. 0x0a476341, 0x992eff74, 0x3a6f6eab, 0xf4f8fd37,
  3417. 0xa812dc60, 0xa1ebddf8, 0x991be14c, 0xdb6e6b0d,
  3418. 0xc67b5510, 0x6d672c37, 0x2765d43b, 0xdcd0e804,
  3419. 0xf1290dc7, 0xcc00ffa3, 0xb5390f92, 0x690fed0b,
  3420. 0x667b9ffb, 0xcedb7d9c, 0xa091cf0b, 0xd9155ea3,
  3421. 0xbb132f88, 0x515bad24, 0x7b9479bf, 0x763bd6eb,
  3422. 0x37392eb3, 0xcc115979, 0x8026e297, 0xf42e312d,
  3423. 0x6842ada7, 0xc66a2b3b, 0x12754ccc, 0x782ef11c,
  3424. 0x6a124237, 0xb79251e7, 0x06a1bbe6, 0x4bfb6350,
  3425. 0x1a6b1018, 0x11caedfa, 0x3d25bdd8, 0xe2e1c3c9,
  3426. 0x44421659, 0x0a121386, 0xd90cec6e, 0xd5abea2a,
  3427. 0x64af674e, 0xda86a85f, 0xbebfe988, 0x64e4c3fe,
  3428. 0x9dbc8057, 0xf0f7c086, 0x60787bf8, 0x6003604d,
  3429. 0xd1fd8346, 0xf6381fb0, 0x7745ae04, 0xd736fccc,
  3430. 0x83426b33, 0xf01eab71, 0xb0804187, 0x3c005e5f,
  3431. 0x77a057be, 0xbde8ae24, 0x55464299, 0xbf582e61,
  3432. 0x4e58f48f, 0xf2ddfda2, 0xf474ef38, 0x8789bdc2,
  3433. 0x5366f9c3, 0xc8b38e74, 0xb475f255, 0x46fcd9b9,
  3434. 0x7aeb2661, 0x8b1ddf84, 0x846a0e79, 0x915f95e2,
  3435. 0x466e598e, 0x20b45770, 0x8cd55591, 0xc902de4c,
  3436. 0xb90bace1, 0xbb8205d0, 0x11a86248, 0x7574a99e,
  3437. 0xb77f19b6, 0xe0a9dc09, 0x662d09a1, 0xc4324633,
  3438. 0xe85a1f02, 0x09f0be8c, 0x4a99a025, 0x1d6efe10,
  3439. 0x1ab93d1d, 0x0ba5a4df, 0xa186f20f, 0x2868f169,
  3440. 0xdcb7da83, 0x573906fe, 0xa1e2ce9b, 0x4fcd7f52,
  3441. 0x50115e01, 0xa70683fa, 0xa002b5c4, 0x0de6d027,
  3442. 0x9af88c27, 0x773f8641, 0xc3604c06, 0x61a806b5,
  3443. 0xf0177a28, 0xc0f586e0, 0x006058aa, 0x30dc7d62,
  3444. 0x11e69ed7, 0x2338ea63, 0x53c2dd94, 0xc2c21634,
  3445. 0xbbcbee56, 0x90bcb6de, 0xebfc7da1, 0xce591d76,
  3446. 0x6f05e409, 0x4b7c0188, 0x39720a3d, 0x7c927c24,
  3447. 0x86e3725f, 0x724d9db9, 0x1ac15bb4, 0xd39eb8fc,
  3448. 0xed545578, 0x08fca5b5, 0xd83d7cd3, 0x4dad0fc4,
  3449. 0x1e50ef5e, 0xb161e6f8, 0xa28514d9, 0x6c51133c,
  3450. 0x6fd5c7e7, 0x56e14ec4, 0x362abfce, 0xddc6c837,
  3451. 0xd79a3234, 0x92638212, 0x670efa8e, 0x406000e0,
  3452. 0x3a39ce37, 0xd3faf5cf, 0xabc27737, 0x5ac52d1b,
  3453. 0x5cb0679e, 0x4fa33742, 0xd3822740, 0x99bc9bbe,
  3454. 0xd5118e9d, 0xbf0f7315, 0xd62d1c7e, 0xc700c47b,
  3455. 0xb78c1b6b, 0x21a19045, 0xb26eb1be, 0x6a366eb4,
  3456. 0x5748ab2f, 0xbc946e79, 0xc6a376d2, 0x6549c2c8,
  3457. 0x530ff8ee, 0x468dde7d, 0xd5730a1d, 0x4cd04dc6,
  3458. 0x2939bbdb, 0xa9ba4650, 0xac9526e8, 0xbe5ee304,
  3459. 0xa1fad5f0, 0x6a2d519a, 0x63ef8ce2, 0x9a86ee22,
  3460. 0xc089c2b8, 0x43242ef6, 0xa51e03aa, 0x9cf2d0a4,
  3461. 0x83c061ba, 0x9be96a4d, 0x8fe51550, 0xba645bd6,
  3462. 0x2826a2f9, 0xa73a3ae1, 0x4ba99586, 0xef5562e9,
  3463. 0xc72fefd3, 0xf752f7da, 0x3f046f69, 0x77fa0a59,
  3464. 0x80e4a915, 0x87b08601, 0x9b09e6ad, 0x3b3ee593,
  3465. 0xe990fd5a, 0x9e34d797, 0x2cf0b7d9, 0x022b8b51,
  3466. 0x96d5ac3a, 0x017da67d, 0xd1cf3ed6, 0x7c7d2d28,
  3467. 0x1f9f25cf, 0xadf2b89b, 0x5ad6b472, 0x5a88f54c,
  3468. 0xe029ac71, 0xe019a5e6, 0x47b0acfd, 0xed93fa9b,
  3469. 0xe8d3c48d, 0x283b57cc, 0xf8d56629, 0x79132e28,
  3470. 0x785f0191, 0xed756055, 0xf7960e44, 0xe3d35e8c,
  3471. 0x15056dd4, 0x88f46dba, 0x03a16125, 0x0564f0bd,
  3472. 0xc3eb9e15, 0x3c9057a2, 0x97271aec, 0xa93a072a,
  3473. 0x1b3f6d9b, 0x1e6321f5, 0xf59c66fb, 0x26dcf319,
  3474. 0x7533d928, 0xb155fdf5, 0x03563482, 0x8aba3cbb,
  3475. 0x28517711, 0xc20ad9f8, 0xabcc5167, 0xccad925f,
  3476. 0x4de81751, 0x3830dc8e, 0x379d5862, 0x9320f991,
  3477. 0xea7a90c2, 0xfb3e7bce, 0x5121ce64, 0x774fbe32,
  3478. 0xa8b6e37e, 0xc3293d46, 0x48de5369, 0x6413e680,
  3479. 0xa2ae0810, 0xdd6db224, 0x69852dfd, 0x09072166,
  3480. 0xb39a460a, 0x6445c0dd, 0x586cdecf, 0x1c20c8ae,
  3481. 0x5bbef7dd, 0x1b588d40, 0xccd2017f, 0x6bb4e3bb,
  3482. 0xdda26a7e, 0x3a59ff45, 0x3e350a44, 0xbcb4cdd5,
  3483. 0x72eacea8, 0xfa6484bb, 0x8d6612ae, 0xbf3c6f47,
  3484. 0xd29be463, 0x542f5d9e, 0xaec2771b, 0xf64e6370,
  3485. 0x740e0d8d, 0xe75b1357, 0xf8721671, 0xaf537d5d,
  3486. 0x4040cb08, 0x4eb4e2cc, 0x34d2466a, 0x0115af84,
  3487. 0xe1b00428, 0x95983a1d, 0x06b89fb4, 0xce6ea048,
  3488. 0x6f3f3b82, 0x3520ab82, 0x011a1d4b, 0x277227f8,
  3489. 0x611560b1, 0xe7933fdc, 0xbb3a792b, 0x344525bd,
  3490. 0xa08839e1, 0x51ce794b, 0x2f32c9b7, 0xa01fbac9,
  3491. 0xe01cc87e, 0xbcc7d1f6, 0xcf0111c3, 0xa1e8aac7,
  3492. 0x1a908749, 0xd44fbd9a, 0xd0dadecb, 0xd50ada38,
  3493. 0x0339c32a, 0xc6913667, 0x8df9317c, 0xe0b12b4f,
  3494. 0xf79e59b7, 0x43f5bb3a, 0xf2d519ff, 0x27d9459c,
  3495. 0xbf97222c, 0x15e6fc2a, 0x0f91fc71, 0x9b941525,
  3496. 0xfae59361, 0xceb69ceb, 0xc2a86459, 0x12baa8d1,
  3497. 0xb6c1075e, 0xe3056a0c, 0x10d25065, 0xcb03a442,
  3498. 0xe0ec6e0e, 0x1698db3b, 0x4c98a0be, 0x3278e964,
  3499. 0x9f1f9532, 0xe0d392df, 0xd3a0342b, 0x8971f21e,
  3500. 0x1b0a7441, 0x4ba3348c, 0xc5be7120, 0xc37632d8,
  3501. 0xdf359f8d, 0x9b992f2e, 0xe60b6f47, 0x0fe3f11d,
  3502. 0xe54cda54, 0x1edad891, 0xce6279cf, 0xcd3e7e6f,
  3503. 0x1618b166, 0xfd2c1d05, 0x848fd2c5, 0xf6fb2299,
  3504. 0xf523f357, 0xa6327623, 0x93a83531, 0x56cccd02,
  3505. 0xacf08162, 0x5a75ebb5, 0x6e163697, 0x88d273cc,
  3506. 0xde966292, 0x81b949d0, 0x4c50901b, 0x71c65614,
  3507. 0xe6c6c7bd, 0x327a140a, 0x45e1d006, 0xc3f27b9a,
  3508. 0xc9aa53fd, 0x62a80f00, 0xbb25bfe2, 0x35bdd2f6,
  3509. 0x71126905, 0xb2040222, 0xb6cbcf7c, 0xcd769c2b,
  3510. 0x53113ec0, 0x1640e3d3, 0x38abbd60, 0x2547adf0,
  3511. 0xba38209c, 0xf746ce76, 0x77afa1c5, 0x20756060,
  3512. 0x85cbfe4e, 0x8ae88dd8, 0x7aaaf9b0, 0x4cf9aa7e,
  3513. 0x1948c25c, 0x02fb8a8c, 0x01c36ae4, 0xd6ebe1f9,
  3514. 0x90d4f869, 0xa65cdea0, 0x3f09252d, 0xc208e69f,
  3515. 0xb74e6132, 0xce77e25b, 0x578fdfe3, 0x3ac372e6
  3516. };
  3517. BlowFish::BlowFish (const uint8* keyData, int keyBytes)
  3518. {
  3519. memcpy (p, initialPValues, sizeof (p));
  3520. int i, j;
  3521. for (i = 4; --i >= 0;)
  3522. {
  3523. s[i].malloc (256);
  3524. memcpy (s[i], initialSValues + i * 256, 256 * sizeof (uint32));
  3525. }
  3526. j = 0;
  3527. for (i = 0; i < 18; ++i)
  3528. {
  3529. uint32 d = 0;
  3530. for (int k = 0; k < 4; ++k)
  3531. {
  3532. d = (d << 8) | keyData[j];
  3533. if (++j >= keyBytes)
  3534. j = 0;
  3535. }
  3536. p[i] = initialPValues[i] ^ d;
  3537. }
  3538. uint32 l = 0, r = 0;
  3539. for (i = 0; i < 18; i += 2)
  3540. {
  3541. encrypt (l, r);
  3542. p[i] = l;
  3543. p[i + 1] = r;
  3544. }
  3545. for (i = 0; i < 4; ++i)
  3546. {
  3547. for (j = 0; j < 256; j += 2)
  3548. {
  3549. encrypt (l, r);
  3550. s[i][j] = l;
  3551. s[i][j + 1] = r;
  3552. }
  3553. }
  3554. }
  3555. BlowFish::BlowFish (const BlowFish& other)
  3556. {
  3557. for (int i = 4; --i >= 0;)
  3558. s[i].malloc (256);
  3559. operator= (other);
  3560. }
  3561. BlowFish& BlowFish::operator= (const BlowFish& other)
  3562. {
  3563. memcpy (p, other.p, sizeof (p));
  3564. for (int i = 4; --i >= 0;)
  3565. memcpy (s[i], other.s[i], 256 * sizeof (uint32));
  3566. return *this;
  3567. }
  3568. BlowFish::~BlowFish()
  3569. {
  3570. }
  3571. uint32 BlowFish::F (uint32 x) const
  3572. {
  3573. uint16 a, b, c, d;
  3574. uint32 y;
  3575. d = (uint16) (x & 0xff);
  3576. x >>= 8;
  3577. c = (uint16) (x & 0xff);
  3578. x >>= 8;
  3579. b = (uint16) (x & 0xff);
  3580. x >>= 8;
  3581. a = (uint16) (x & 0xff);
  3582. y = s[0][a] + s[1][b];
  3583. y = y ^ s[2][c];
  3584. y = y + s[3][d];
  3585. return y;
  3586. }
  3587. void BlowFish::encrypt (uint32& data1,
  3588. uint32& data2) const
  3589. {
  3590. uint32 l = data1;
  3591. uint32 r = data2;
  3592. for (int i = 0; i < 16; ++i)
  3593. {
  3594. l = l ^ p[i];
  3595. r = F (l) ^ r;
  3596. const uint32 temp = l;
  3597. l = r;
  3598. r = temp;
  3599. }
  3600. const uint32 temp = l;
  3601. l = r;
  3602. r = temp;
  3603. r = r ^ p[16];
  3604. l = l ^ p[17];
  3605. data1 = l;
  3606. data2 = r;
  3607. }
  3608. void BlowFish::decrypt (uint32& data1,
  3609. uint32& data2) const
  3610. {
  3611. uint32 l = data1;
  3612. uint32 r = data2;
  3613. for (int i = 17; i > 1; --i)
  3614. {
  3615. l =l ^ p[i];
  3616. r = F (l) ^ r;
  3617. const uint32 temp = l;
  3618. l = r;
  3619. r = temp;
  3620. }
  3621. const uint32 temp = l;
  3622. l = r;
  3623. r = temp;
  3624. r = r ^ p[1];
  3625. l = l ^ p[0];
  3626. data1 = l;
  3627. data2 = r;
  3628. }
  3629. END_JUCE_NAMESPACE
  3630. /*** End of inlined file: juce_BlowFish.cpp ***/
  3631. /*** Start of inlined file: juce_MD5.cpp ***/
  3632. BEGIN_JUCE_NAMESPACE
  3633. MD5::MD5()
  3634. {
  3635. zerostruct (result);
  3636. }
  3637. MD5::MD5 (const MD5& other)
  3638. {
  3639. memcpy (result, other.result, sizeof (result));
  3640. }
  3641. MD5& MD5::operator= (const MD5& other)
  3642. {
  3643. memcpy (result, other.result, sizeof (result));
  3644. return *this;
  3645. }
  3646. MD5::MD5 (const MemoryBlock& data)
  3647. {
  3648. ProcessContext context;
  3649. context.processBlock ((const uint8*) data.getData(), data.getSize());
  3650. context.finish (result);
  3651. }
  3652. MD5::MD5 (const char* data, const size_t numBytes)
  3653. {
  3654. ProcessContext context;
  3655. context.processBlock ((const uint8*) data, numBytes);
  3656. context.finish (result);
  3657. }
  3658. MD5::MD5 (const String& text)
  3659. {
  3660. ProcessContext context;
  3661. const int len = text.length();
  3662. const juce_wchar* const t = text;
  3663. for (int i = 0; i < len; ++i)
  3664. {
  3665. // force the string into integer-sized unicode characters, to try to make it
  3666. // get the same results on all platforms + compilers.
  3667. uint32 unicodeChar = (uint32) t[i];
  3668. ByteOrder::swapIfBigEndian (unicodeChar);
  3669. context.processBlock ((const uint8*) &unicodeChar,
  3670. sizeof (unicodeChar));
  3671. }
  3672. context.finish (result);
  3673. }
  3674. void MD5::processStream (InputStream& input, int64 numBytesToRead)
  3675. {
  3676. ProcessContext context;
  3677. if (numBytesToRead < 0)
  3678. numBytesToRead = std::numeric_limits<int64>::max();
  3679. while (numBytesToRead > 0)
  3680. {
  3681. char tempBuffer [512];
  3682. const int bytesRead = input.read (tempBuffer, (int) jmin (numBytesToRead, (int64) sizeof (tempBuffer)));
  3683. if (bytesRead <= 0)
  3684. break;
  3685. numBytesToRead -= bytesRead;
  3686. context.processBlock ((const uint8*) tempBuffer, bytesRead);
  3687. }
  3688. context.finish (result);
  3689. }
  3690. MD5::MD5 (InputStream& input, int64 numBytesToRead)
  3691. {
  3692. processStream (input, numBytesToRead);
  3693. }
  3694. MD5::MD5 (const File& file)
  3695. {
  3696. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  3697. if (fin != 0)
  3698. processStream (*fin, -1);
  3699. else
  3700. zerostruct (result);
  3701. }
  3702. MD5::~MD5()
  3703. {
  3704. }
  3705. namespace MD5Functions
  3706. {
  3707. static void encode (uint8* const output, const uint32* const input, const int numBytes) throw()
  3708. {
  3709. uint32* const o = (uint32*) output;
  3710. for (int i = 0; i < (numBytes >> 2); ++i)
  3711. o[i] = ByteOrder::swapIfBigEndian (input [i]);
  3712. }
  3713. static void decode (uint32* const output, const uint8* const input, const int numBytes) throw()
  3714. {
  3715. for (int i = 0; i < (numBytes >> 2); ++i)
  3716. output[i] = ByteOrder::littleEndianInt ((const char*) input + (i << 2));
  3717. }
  3718. static inline uint32 F (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & y) | (~x & z); }
  3719. static inline uint32 G (const uint32 x, const uint32 y, const uint32 z) throw() { return (x & z) | (y & ~z); }
  3720. static inline uint32 H (const uint32 x, const uint32 y, const uint32 z) throw() { return x ^ y ^ z; }
  3721. static inline uint32 I (const uint32 x, const uint32 y, const uint32 z) throw() { return y ^ (x | ~z); }
  3722. static inline uint32 rotateLeft (const uint32 x, const uint32 n) throw() { return (x << n) | (x >> (32 - n)); }
  3723. static void FF (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3724. {
  3725. a += F (b, c, d) + x + ac;
  3726. a = rotateLeft (a, s) + b;
  3727. }
  3728. static void GG (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3729. {
  3730. a += G (b, c, d) + x + ac;
  3731. a = rotateLeft (a, s) + b;
  3732. }
  3733. static void HH (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3734. {
  3735. a += H (b, c, d) + x + ac;
  3736. a = rotateLeft (a, s) + b;
  3737. }
  3738. static void II (uint32& a, const uint32 b, const uint32 c, const uint32 d, const uint32 x, const uint32 s, const uint32 ac) throw()
  3739. {
  3740. a += I (b, c, d) + x + ac;
  3741. a = rotateLeft (a, s) + b;
  3742. }
  3743. }
  3744. MD5::ProcessContext::ProcessContext()
  3745. {
  3746. state[0] = 0x67452301;
  3747. state[1] = 0xefcdab89;
  3748. state[2] = 0x98badcfe;
  3749. state[3] = 0x10325476;
  3750. count[0] = 0;
  3751. count[1] = 0;
  3752. }
  3753. void MD5::ProcessContext::processBlock (const uint8* const data, size_t dataSize)
  3754. {
  3755. int bufferPos = ((count[0] >> 3) & 0x3F);
  3756. count[0] += (uint32) (dataSize << 3);
  3757. if (count[0] < ((uint32) dataSize << 3))
  3758. count[1]++;
  3759. count[1] += (uint32) (dataSize >> 29);
  3760. const size_t spaceLeft = 64 - bufferPos;
  3761. size_t i = 0;
  3762. if (dataSize >= spaceLeft)
  3763. {
  3764. memcpy (buffer + bufferPos, data, spaceLeft);
  3765. transform (buffer);
  3766. i = spaceLeft;
  3767. while (i + 64 <= dataSize)
  3768. {
  3769. transform (data + i);
  3770. i += 64;
  3771. }
  3772. bufferPos = 0;
  3773. }
  3774. memcpy (buffer + bufferPos, data + i, dataSize - i);
  3775. }
  3776. void MD5::ProcessContext::finish (uint8* const result)
  3777. {
  3778. unsigned char encodedLength[8];
  3779. MD5Functions::encode (encodedLength, count, 8);
  3780. // Pad out to 56 mod 64.
  3781. const int index = (uint32) ((count[0] >> 3) & 0x3f);
  3782. const int paddingLength = (index < 56) ? (56 - index)
  3783. : (120 - index);
  3784. uint8 paddingBuffer [64];
  3785. zeromem (paddingBuffer, paddingLength);
  3786. paddingBuffer [0] = 0x80;
  3787. processBlock (paddingBuffer, paddingLength);
  3788. processBlock (encodedLength, 8);
  3789. MD5Functions::encode (result, state, sizeof (result));
  3790. zerostruct (buffer);
  3791. }
  3792. void MD5::ProcessContext::transform (const uint8* const bufferToTransform)
  3793. {
  3794. using namespace MD5Functions;
  3795. uint32 a = state[0];
  3796. uint32 b = state[1];
  3797. uint32 c = state[2];
  3798. uint32 d = state[3];
  3799. uint32 x[16];
  3800. decode (x, bufferToTransform, 64);
  3801. enum Constants
  3802. {
  3803. S11 = 7, S12 = 12, S13 = 17, S14 = 22, S21 = 5, S22 = 9, S23 = 14, S24 = 20,
  3804. S31 = 4, S32 = 11, S33 = 16, S34 = 23, S41 = 6, S42 = 10, S43 = 15, S44 = 21
  3805. };
  3806. FF (a, b, c, d, x[ 0], S11, 0xd76aa478); /* 1 */
  3807. FF (d, a, b, c, x[ 1], S12, 0xe8c7b756); /* 2 */
  3808. FF (c, d, a, b, x[ 2], S13, 0x242070db); /* 3 */
  3809. FF (b, c, d, a, x[ 3], S14, 0xc1bdceee); /* 4 */
  3810. FF (a, b, c, d, x[ 4], S11, 0xf57c0faf); /* 5 */
  3811. FF (d, a, b, c, x[ 5], S12, 0x4787c62a); /* 6 */
  3812. FF (c, d, a, b, x[ 6], S13, 0xa8304613); /* 7 */
  3813. FF (b, c, d, a, x[ 7], S14, 0xfd469501); /* 8 */
  3814. FF (a, b, c, d, x[ 8], S11, 0x698098d8); /* 9 */
  3815. FF (d, a, b, c, x[ 9], S12, 0x8b44f7af); /* 10 */
  3816. FF (c, d, a, b, x[10], S13, 0xffff5bb1); /* 11 */
  3817. FF (b, c, d, a, x[11], S14, 0x895cd7be); /* 12 */
  3818. FF (a, b, c, d, x[12], S11, 0x6b901122); /* 13 */
  3819. FF (d, a, b, c, x[13], S12, 0xfd987193); /* 14 */
  3820. FF (c, d, a, b, x[14], S13, 0xa679438e); /* 15 */
  3821. FF (b, c, d, a, x[15], S14, 0x49b40821); /* 16 */
  3822. GG (a, b, c, d, x[ 1], S21, 0xf61e2562); /* 17 */
  3823. GG (d, a, b, c, x[ 6], S22, 0xc040b340); /* 18 */
  3824. GG (c, d, a, b, x[11], S23, 0x265e5a51); /* 19 */
  3825. GG (b, c, d, a, x[ 0], S24, 0xe9b6c7aa); /* 20 */
  3826. GG (a, b, c, d, x[ 5], S21, 0xd62f105d); /* 21 */
  3827. GG (d, a, b, c, x[10], S22, 0x2441453); /* 22 */
  3828. GG (c, d, a, b, x[15], S23, 0xd8a1e681); /* 23 */
  3829. GG (b, c, d, a, x[ 4], S24, 0xe7d3fbc8); /* 24 */
  3830. GG (a, b, c, d, x[ 9], S21, 0x21e1cde6); /* 25 */
  3831. GG (d, a, b, c, x[14], S22, 0xc33707d6); /* 26 */
  3832. GG (c, d, a, b, x[ 3], S23, 0xf4d50d87); /* 27 */
  3833. GG (b, c, d, a, x[ 8], S24, 0x455a14ed); /* 28 */
  3834. GG (a, b, c, d, x[13], S21, 0xa9e3e905); /* 29 */
  3835. GG (d, a, b, c, x[ 2], S22, 0xfcefa3f8); /* 30 */
  3836. GG (c, d, a, b, x[ 7], S23, 0x676f02d9); /* 31 */
  3837. GG (b, c, d, a, x[12], S24, 0x8d2a4c8a); /* 32 */
  3838. HH (a, b, c, d, x[ 5], S31, 0xfffa3942); /* 33 */
  3839. HH (d, a, b, c, x[ 8], S32, 0x8771f681); /* 34 */
  3840. HH (c, d, a, b, x[11], S33, 0x6d9d6122); /* 35 */
  3841. HH (b, c, d, a, x[14], S34, 0xfde5380c); /* 36 */
  3842. HH (a, b, c, d, x[ 1], S31, 0xa4beea44); /* 37 */
  3843. HH (d, a, b, c, x[ 4], S32, 0x4bdecfa9); /* 38 */
  3844. HH (c, d, a, b, x[ 7], S33, 0xf6bb4b60); /* 39 */
  3845. HH (b, c, d, a, x[10], S34, 0xbebfbc70); /* 40 */
  3846. HH (a, b, c, d, x[13], S31, 0x289b7ec6); /* 41 */
  3847. HH (d, a, b, c, x[ 0], S32, 0xeaa127fa); /* 42 */
  3848. HH (c, d, a, b, x[ 3], S33, 0xd4ef3085); /* 43 */
  3849. HH (b, c, d, a, x[ 6], S34, 0x4881d05); /* 44 */
  3850. HH (a, b, c, d, x[ 9], S31, 0xd9d4d039); /* 45 */
  3851. HH (d, a, b, c, x[12], S32, 0xe6db99e5); /* 46 */
  3852. HH (c, d, a, b, x[15], S33, 0x1fa27cf8); /* 47 */
  3853. HH (b, c, d, a, x[ 2], S34, 0xc4ac5665); /* 48 */
  3854. II (a, b, c, d, x[ 0], S41, 0xf4292244); /* 49 */
  3855. II (d, a, b, c, x[ 7], S42, 0x432aff97); /* 50 */
  3856. II (c, d, a, b, x[14], S43, 0xab9423a7); /* 51 */
  3857. II (b, c, d, a, x[ 5], S44, 0xfc93a039); /* 52 */
  3858. II (a, b, c, d, x[12], S41, 0x655b59c3); /* 53 */
  3859. II (d, a, b, c, x[ 3], S42, 0x8f0ccc92); /* 54 */
  3860. II (c, d, a, b, x[10], S43, 0xffeff47d); /* 55 */
  3861. II (b, c, d, a, x[ 1], S44, 0x85845dd1); /* 56 */
  3862. II (a, b, c, d, x[ 8], S41, 0x6fa87e4f); /* 57 */
  3863. II (d, a, b, c, x[15], S42, 0xfe2ce6e0); /* 58 */
  3864. II (c, d, a, b, x[ 6], S43, 0xa3014314); /* 59 */
  3865. II (b, c, d, a, x[13], S44, 0x4e0811a1); /* 60 */
  3866. II (a, b, c, d, x[ 4], S41, 0xf7537e82); /* 61 */
  3867. II (d, a, b, c, x[11], S42, 0xbd3af235); /* 62 */
  3868. II (c, d, a, b, x[ 2], S43, 0x2ad7d2bb); /* 63 */
  3869. II (b, c, d, a, x[ 9], S44, 0xeb86d391); /* 64 */
  3870. state[0] += a;
  3871. state[1] += b;
  3872. state[2] += c;
  3873. state[3] += d;
  3874. zerostruct (x);
  3875. }
  3876. const MemoryBlock MD5::getRawChecksumData() const
  3877. {
  3878. return MemoryBlock (result, sizeof (result));
  3879. }
  3880. const String MD5::toHexString() const
  3881. {
  3882. return String::toHexString (result, sizeof (result), 0);
  3883. }
  3884. bool MD5::operator== (const MD5& other) const
  3885. {
  3886. return memcmp (result, other.result, sizeof (result)) == 0;
  3887. }
  3888. bool MD5::operator!= (const MD5& other) const
  3889. {
  3890. return ! operator== (other);
  3891. }
  3892. END_JUCE_NAMESPACE
  3893. /*** End of inlined file: juce_MD5.cpp ***/
  3894. /*** Start of inlined file: juce_Primes.cpp ***/
  3895. BEGIN_JUCE_NAMESPACE
  3896. namespace PrimesHelpers
  3897. {
  3898. static void createSmallSieve (const int numBits, BitArray& result) throw()
  3899. {
  3900. result.setBit (numBits);
  3901. result.clearBit (numBits); // to enlarge the array
  3902. result.setBit (0);
  3903. int n = 2;
  3904. do
  3905. {
  3906. for (int i = n + n; i < numBits; i += n)
  3907. result.setBit (i);
  3908. n = result.findNextClearBit (n + 1);
  3909. }
  3910. while (n <= (numBits >> 1));
  3911. }
  3912. static void bigSieve (const BitArray& base,
  3913. const int numBits,
  3914. BitArray& result,
  3915. const BitArray& smallSieve,
  3916. const int smallSieveSize) throw()
  3917. {
  3918. jassert (! base[0]); // must be even!
  3919. result.setBit (numBits);
  3920. result.clearBit (numBits); // to enlarge the array
  3921. int index = smallSieve.findNextClearBit (0);
  3922. do
  3923. {
  3924. const int prime = (index << 1) + 1;
  3925. BitArray r (base);
  3926. BitArray remainder;
  3927. r.divideBy (prime, remainder);
  3928. int i = prime - remainder.getBitRangeAsInt (0, 32);
  3929. if (r.isEmpty())
  3930. i += prime;
  3931. if ((i & 1) == 0)
  3932. i += prime;
  3933. i = (i - 1) >> 1;
  3934. while (i < numBits)
  3935. {
  3936. result.setBit (i);
  3937. i += prime;
  3938. }
  3939. index = smallSieve.findNextClearBit (index + 1);
  3940. }
  3941. while (index < smallSieveSize);
  3942. }
  3943. static bool findCandidate (const BitArray& base,
  3944. const BitArray& sieve,
  3945. const int numBits,
  3946. BitArray& result,
  3947. const int certainty) throw()
  3948. {
  3949. for (int i = 0; i < numBits; ++i)
  3950. {
  3951. if (! sieve[i])
  3952. {
  3953. result = base;
  3954. result.add (BitArray ((unsigned int) ((i << 1) + 1)));
  3955. if (Primes::isProbablyPrime (result, certainty))
  3956. return true;
  3957. }
  3958. }
  3959. return false;
  3960. }
  3961. }
  3962. const BitArray Primes::createProbablePrime (const int bitLength,
  3963. const int certainty,
  3964. const int* randomSeeds,
  3965. int numRandomSeeds) throw()
  3966. {
  3967. using namespace PrimesHelpers;
  3968. int defaultSeeds [16];
  3969. if (numRandomSeeds <= 0)
  3970. {
  3971. randomSeeds = defaultSeeds;
  3972. numRandomSeeds = numElementsInArray (defaultSeeds);
  3973. Random r (0);
  3974. for (int j = 10; --j >= 0;)
  3975. {
  3976. r.setSeedRandomly();
  3977. for (int i = numRandomSeeds; --i >= 0;)
  3978. defaultSeeds[i] ^= r.nextInt() ^ Random::getSystemRandom().nextInt();
  3979. }
  3980. }
  3981. BitArray smallSieve;
  3982. const int smallSieveSize = 15000;
  3983. createSmallSieve (smallSieveSize, smallSieve);
  3984. BitArray p;
  3985. for (int i = numRandomSeeds; --i >= 0;)
  3986. {
  3987. BitArray p2;
  3988. Random r (randomSeeds[i]);
  3989. r.fillBitsRandomly (p2, 0, bitLength);
  3990. p.xorWith (p2);
  3991. }
  3992. p.setBit (bitLength - 1);
  3993. p.clearBit (0);
  3994. const int searchLen = jmax (1024, (bitLength / 20) * 64);
  3995. while (p.getHighestBit() < bitLength)
  3996. {
  3997. p.add (2 * searchLen);
  3998. BitArray sieve;
  3999. bigSieve (p, searchLen, sieve,
  4000. smallSieve, smallSieveSize);
  4001. BitArray candidate;
  4002. if (findCandidate (p, sieve, searchLen, candidate, certainty))
  4003. return candidate;
  4004. }
  4005. jassertfalse
  4006. return BitArray();
  4007. }
  4008. static bool passesMillerRabin (const BitArray& n, int iterations) throw()
  4009. {
  4010. using namespace PrimesHelpers;
  4011. const BitArray one (1);
  4012. const BitArray two (2);
  4013. BitArray nMinusOne (n);
  4014. nMinusOne.subtract (one);
  4015. BitArray d (nMinusOne);
  4016. const int s = d.findNextSetBit (0);
  4017. d.shiftBits (-s);
  4018. BitArray smallPrimes;
  4019. int numBitsInSmallPrimes = 0;
  4020. for (;;)
  4021. {
  4022. numBitsInSmallPrimes += 256;
  4023. createSmallSieve (numBitsInSmallPrimes, smallPrimes);
  4024. const int numPrimesFound = numBitsInSmallPrimes - smallPrimes.countNumberOfSetBits();
  4025. if (numPrimesFound > iterations + 1)
  4026. break;
  4027. }
  4028. int smallPrime = 2;
  4029. while (--iterations >= 0)
  4030. {
  4031. smallPrime = smallPrimes.findNextClearBit (smallPrime + 1);
  4032. BitArray r (smallPrime);
  4033. //r.createRandomNumber (nMinusOne);
  4034. r.exponentModulo (d, n);
  4035. if (! (r == one || r == nMinusOne))
  4036. {
  4037. for (int j = 0; j < s; ++j)
  4038. {
  4039. r.exponentModulo (two, n);
  4040. if (r == nMinusOne)
  4041. break;
  4042. }
  4043. if (r != nMinusOne)
  4044. return false;
  4045. }
  4046. }
  4047. return true;
  4048. }
  4049. bool Primes::isProbablyPrime (const BitArray& number,
  4050. const int certainty) throw()
  4051. {
  4052. if (! number[0])
  4053. return false;
  4054. if (number.getHighestBit() <= 10)
  4055. {
  4056. const int num = number.getBitRangeAsInt (0, 10);
  4057. for (int i = num / 2; --i > 1;)
  4058. if (num % i == 0)
  4059. return false;
  4060. return true;
  4061. }
  4062. else
  4063. {
  4064. const BitArray screen (2 * 3 * 5 * 7 * 11 * 13 * 17 * 19 * 23);
  4065. if (number.findGreatestCommonDivisor (screen) != BitArray (1))
  4066. return false;
  4067. return passesMillerRabin (number, certainty);
  4068. }
  4069. }
  4070. END_JUCE_NAMESPACE
  4071. /*** End of inlined file: juce_Primes.cpp ***/
  4072. /*** Start of inlined file: juce_RSAKey.cpp ***/
  4073. BEGIN_JUCE_NAMESPACE
  4074. RSAKey::RSAKey() throw()
  4075. {
  4076. }
  4077. RSAKey::RSAKey (const String& s) throw()
  4078. {
  4079. if (s.containsChar (T(',')))
  4080. {
  4081. part1.parseString (s.upToFirstOccurrenceOf (T(","), false, false), 16);
  4082. part2.parseString (s.fromFirstOccurrenceOf (T(","), false, false), 16);
  4083. }
  4084. else
  4085. {
  4086. // the string needs to be two hex numbers, comma-separated..
  4087. jassertfalse;
  4088. }
  4089. }
  4090. RSAKey::~RSAKey() throw()
  4091. {
  4092. }
  4093. const String RSAKey::toString() const throw()
  4094. {
  4095. return part1.toString (16) + T(",") + part2.toString (16);
  4096. }
  4097. bool RSAKey::applyToValue (BitArray& value) const throw()
  4098. {
  4099. if (part1.isEmpty() || part2.isEmpty()
  4100. || value.compare (0) <= 0)
  4101. {
  4102. jassertfalse // using an uninitialised key
  4103. value.clear();
  4104. return false;
  4105. }
  4106. BitArray result;
  4107. while (! value.isEmpty())
  4108. {
  4109. result.multiplyBy (part2);
  4110. BitArray remainder;
  4111. value.divideBy (part2, remainder);
  4112. remainder.exponentModulo (part1, part2);
  4113. result.add (remainder);
  4114. }
  4115. value = result;
  4116. return true;
  4117. }
  4118. static const BitArray findBestCommonDivisor (const BitArray& p,
  4119. const BitArray& q) throw()
  4120. {
  4121. const BitArray one (1);
  4122. // try 3, 5, 9, 17, etc first because these only contain 2 bits and so
  4123. // are fast to divide + multiply
  4124. for (int i = 2; i <= 65536; i *= 2)
  4125. {
  4126. const BitArray e (1 + i);
  4127. if (e.findGreatestCommonDivisor (p) == one
  4128. && e.findGreatestCommonDivisor (q) == one)
  4129. {
  4130. return e;
  4131. }
  4132. }
  4133. BitArray e (4);
  4134. while (! (e.findGreatestCommonDivisor (p) == one
  4135. && e.findGreatestCommonDivisor (q) == one))
  4136. {
  4137. e.add (one);
  4138. }
  4139. return e;
  4140. }
  4141. void RSAKey::createKeyPair (RSAKey& publicKey,
  4142. RSAKey& privateKey,
  4143. const int numBits,
  4144. const int* randomSeeds,
  4145. const int numRandomSeeds) throw()
  4146. {
  4147. jassert (numBits > 16); // not much point using less than this..
  4148. BitArray p (Primes::createProbablePrime (numBits / 2, 30, randomSeeds, numRandomSeeds));
  4149. BitArray q (Primes::createProbablePrime (numBits - numBits / 2, 30, randomSeeds, numRandomSeeds));
  4150. BitArray n (p);
  4151. n.multiplyBy (q); // n = pq
  4152. const BitArray one (1);
  4153. p.subtract (one);
  4154. q.subtract (one);
  4155. BitArray m (p);
  4156. m.multiplyBy (q); // m = (p - 1)(q - 1)
  4157. const BitArray e (findBestCommonDivisor (p, q));
  4158. BitArray d (e);
  4159. d.inverseModulo (m);
  4160. publicKey.part1 = e;
  4161. publicKey.part2 = n;
  4162. privateKey.part1 = d;
  4163. privateKey.part2 = n;
  4164. }
  4165. END_JUCE_NAMESPACE
  4166. /*** End of inlined file: juce_RSAKey.cpp ***/
  4167. /*** Start of inlined file: juce_InputStream.cpp ***/
  4168. BEGIN_JUCE_NAMESPACE
  4169. char InputStream::readByte()
  4170. {
  4171. char temp = 0;
  4172. read (&temp, 1);
  4173. return temp;
  4174. }
  4175. bool InputStream::readBool()
  4176. {
  4177. return readByte() != 0;
  4178. }
  4179. short InputStream::readShort()
  4180. {
  4181. char temp [2];
  4182. if (read (temp, 2) == 2)
  4183. return (short) ByteOrder::littleEndianShort (temp);
  4184. else
  4185. return 0;
  4186. }
  4187. short InputStream::readShortBigEndian()
  4188. {
  4189. char temp [2];
  4190. if (read (temp, 2) == 2)
  4191. return (short) ByteOrder::bigEndianShort (temp);
  4192. else
  4193. return 0;
  4194. }
  4195. int InputStream::readInt()
  4196. {
  4197. char temp [4];
  4198. if (read (temp, 4) == 4)
  4199. return (int) ByteOrder::littleEndianInt (temp);
  4200. else
  4201. return 0;
  4202. }
  4203. int InputStream::readIntBigEndian()
  4204. {
  4205. char temp [4];
  4206. if (read (temp, 4) == 4)
  4207. return (int) ByteOrder::bigEndianInt (temp);
  4208. else
  4209. return 0;
  4210. }
  4211. int InputStream::readCompressedInt()
  4212. {
  4213. const unsigned char sizeByte = readByte();
  4214. if (sizeByte == 0)
  4215. return 0;
  4216. const int numBytes = (sizeByte & 0x7f);
  4217. if (numBytes > 4)
  4218. {
  4219. jassertfalse // trying to read corrupt data - this method must only be used
  4220. // to read data that was written by OutputStream::writeCompressedInt()
  4221. return 0;
  4222. }
  4223. char bytes[4] = { 0, 0, 0, 0 };
  4224. if (read (bytes, numBytes) != numBytes)
  4225. return 0;
  4226. const int num = (int) ByteOrder::littleEndianInt (bytes);
  4227. return (sizeByte >> 7) ? -num : num;
  4228. }
  4229. int64 InputStream::readInt64()
  4230. {
  4231. char temp [8];
  4232. if (read (temp, 8) == 8)
  4233. return (int64) ByteOrder::swapIfBigEndian (*(uint64*) temp);
  4234. else
  4235. return 0;
  4236. }
  4237. int64 InputStream::readInt64BigEndian()
  4238. {
  4239. char temp [8];
  4240. if (read (temp, 8) == 8)
  4241. return (int64) ByteOrder::swapIfLittleEndian (*(uint64*) temp);
  4242. else
  4243. return 0;
  4244. }
  4245. float InputStream::readFloat()
  4246. {
  4247. union { int asInt; float asFloat; } n;
  4248. n.asInt = readInt();
  4249. return n.asFloat;
  4250. }
  4251. float InputStream::readFloatBigEndian()
  4252. {
  4253. union { int asInt; float asFloat; } n;
  4254. n.asInt = readIntBigEndian();
  4255. return n.asFloat;
  4256. }
  4257. double InputStream::readDouble()
  4258. {
  4259. union { int64 asInt; double asDouble; } n;
  4260. n.asInt = readInt64();
  4261. return n.asDouble;
  4262. }
  4263. double InputStream::readDoubleBigEndian()
  4264. {
  4265. union { int64 asInt; double asDouble; } n;
  4266. n.asInt = readInt64BigEndian();
  4267. return n.asDouble;
  4268. }
  4269. const String InputStream::readString()
  4270. {
  4271. MemoryBlock buffer (256);
  4272. char* data = (char*) buffer.getData();
  4273. size_t i = 0;
  4274. while ((data[i] = readByte()) != 0)
  4275. {
  4276. if (++i >= buffer.getSize())
  4277. {
  4278. buffer.setSize (buffer.getSize() + 512);
  4279. data = (char*) buffer.getData();
  4280. }
  4281. }
  4282. return String::fromUTF8 (data, (int) i);
  4283. }
  4284. const String InputStream::readNextLine()
  4285. {
  4286. MemoryBlock buffer (256);
  4287. char* data = (char*) buffer.getData();
  4288. size_t i = 0;
  4289. while ((data[i] = readByte()) != 0)
  4290. {
  4291. if (data[i] == '\n')
  4292. break;
  4293. if (data[i] == '\r')
  4294. {
  4295. const int64 lastPos = getPosition();
  4296. if (readByte() != '\n')
  4297. setPosition (lastPos);
  4298. break;
  4299. }
  4300. if (++i >= buffer.getSize())
  4301. {
  4302. buffer.setSize (buffer.getSize() + 512);
  4303. data = (char*) buffer.getData();
  4304. }
  4305. }
  4306. return String::fromUTF8 (data, (int) i);
  4307. }
  4308. int InputStream::readIntoMemoryBlock (MemoryBlock& block,
  4309. int numBytes)
  4310. {
  4311. const int64 totalLength = getTotalLength();
  4312. if (totalLength >= 0)
  4313. {
  4314. const int totalBytesRemaining = (int) jmin ((int64) 0x7fffffff,
  4315. totalLength - getPosition());
  4316. if (numBytes < 0)
  4317. numBytes = totalBytesRemaining;
  4318. else if (numBytes > 0)
  4319. numBytes = jmin (numBytes, totalBytesRemaining);
  4320. else
  4321. return 0;
  4322. }
  4323. const size_t originalBlockSize = block.getSize();
  4324. int totalBytesRead = 0;
  4325. if (numBytes > 0)
  4326. {
  4327. // know how many bytes we want, so we can resize the block first..
  4328. block.setSize (originalBlockSize + numBytes, false);
  4329. totalBytesRead = read (((char*) block.getData()) + originalBlockSize, numBytes);
  4330. }
  4331. else
  4332. {
  4333. // read until end of stram..
  4334. const int chunkSize = 32768;
  4335. for (;;)
  4336. {
  4337. block.ensureSize (originalBlockSize + totalBytesRead + chunkSize, false);
  4338. const int bytesJustIn = read (((char*) block.getData())
  4339. + originalBlockSize
  4340. + totalBytesRead,
  4341. chunkSize);
  4342. if (bytesJustIn == 0)
  4343. break;
  4344. totalBytesRead += bytesJustIn;
  4345. }
  4346. }
  4347. // trim off any excess left at the end
  4348. block.setSize (originalBlockSize + totalBytesRead, false);
  4349. return totalBytesRead;
  4350. }
  4351. const String InputStream::readEntireStreamAsString()
  4352. {
  4353. MemoryBlock mb;
  4354. const int size = readIntoMemoryBlock (mb);
  4355. return String::createStringFromData ((const char*) mb.getData(), size);
  4356. }
  4357. void InputStream::skipNextBytes (int64 numBytesToSkip)
  4358. {
  4359. if (numBytesToSkip > 0)
  4360. {
  4361. const int skipBufferSize = (int) jmin (numBytesToSkip, (int64) 16384);
  4362. HeapBlock <char> temp (skipBufferSize);
  4363. while (numBytesToSkip > 0 && ! isExhausted())
  4364. numBytesToSkip -= read (temp, (int) jmin (numBytesToSkip, (int64) skipBufferSize));
  4365. }
  4366. }
  4367. END_JUCE_NAMESPACE
  4368. /*** End of inlined file: juce_InputStream.cpp ***/
  4369. /*** Start of inlined file: juce_OutputStream.cpp ***/
  4370. BEGIN_JUCE_NAMESPACE
  4371. #if JUCE_DEBUG
  4372. static CriticalSection activeStreamLock;
  4373. static VoidArray activeStreams;
  4374. void juce_CheckForDanglingStreams()
  4375. {
  4376. /*
  4377. It's always a bad idea to leak any object, but if you're leaking output
  4378. streams, then there's a good chance that you're failing to flush a file
  4379. to disk properly, which could result in corrupted data and other similar
  4380. nastiness..
  4381. */
  4382. jassert (activeStreams.size() == 0);
  4383. };
  4384. #endif
  4385. OutputStream::OutputStream()
  4386. {
  4387. #if JUCE_DEBUG
  4388. const ScopedLock sl (activeStreamLock);
  4389. activeStreams.add (this);
  4390. #endif
  4391. }
  4392. OutputStream::~OutputStream()
  4393. {
  4394. #if JUCE_DEBUG
  4395. const ScopedLock sl (activeStreamLock);
  4396. activeStreams.removeValue (this);
  4397. #endif
  4398. }
  4399. void OutputStream::writeBool (bool b)
  4400. {
  4401. writeByte ((b) ? (char) 1
  4402. : (char) 0);
  4403. }
  4404. void OutputStream::writeByte (char byte)
  4405. {
  4406. write (&byte, 1);
  4407. }
  4408. void OutputStream::writeShort (short value)
  4409. {
  4410. const unsigned short v = ByteOrder::swapIfBigEndian ((unsigned short) value);
  4411. write (&v, 2);
  4412. }
  4413. void OutputStream::writeShortBigEndian (short value)
  4414. {
  4415. const unsigned short v = ByteOrder::swapIfLittleEndian ((unsigned short) value);
  4416. write (&v, 2);
  4417. }
  4418. void OutputStream::writeInt (int value)
  4419. {
  4420. const unsigned int v = ByteOrder::swapIfBigEndian ((unsigned int) value);
  4421. write (&v, 4);
  4422. }
  4423. void OutputStream::writeIntBigEndian (int value)
  4424. {
  4425. const unsigned int v = ByteOrder::swapIfLittleEndian ((unsigned int) value);
  4426. write (&v, 4);
  4427. }
  4428. void OutputStream::writeCompressedInt (int value)
  4429. {
  4430. unsigned int un = (value < 0) ? (unsigned int) -value
  4431. : (unsigned int) value;
  4432. uint8 data[5];
  4433. int num = 0;
  4434. while (un > 0)
  4435. {
  4436. data[++num] = (uint8) un;
  4437. un >>= 8;
  4438. }
  4439. data[0] = (uint8) num;
  4440. if (value < 0)
  4441. data[0] |= 0x80;
  4442. write (data, num + 1);
  4443. }
  4444. void OutputStream::writeInt64 (int64 value)
  4445. {
  4446. const uint64 v = ByteOrder::swapIfBigEndian ((uint64) value);
  4447. write (&v, 8);
  4448. }
  4449. void OutputStream::writeInt64BigEndian (int64 value)
  4450. {
  4451. const uint64 v = ByteOrder::swapIfLittleEndian ((uint64) value);
  4452. write (&v, 8);
  4453. }
  4454. void OutputStream::writeFloat (float value)
  4455. {
  4456. union { int asInt; float asFloat; } n;
  4457. n.asFloat = value;
  4458. writeInt (n.asInt);
  4459. }
  4460. void OutputStream::writeFloatBigEndian (float value)
  4461. {
  4462. union { int asInt; float asFloat; } n;
  4463. n.asFloat = value;
  4464. writeIntBigEndian (n.asInt);
  4465. }
  4466. void OutputStream::writeDouble (double value)
  4467. {
  4468. union { int64 asInt; double asDouble; } n;
  4469. n.asDouble = value;
  4470. writeInt64 (n.asInt);
  4471. }
  4472. void OutputStream::writeDoubleBigEndian (double value)
  4473. {
  4474. union { int64 asInt; double asDouble; } n;
  4475. n.asDouble = value;
  4476. writeInt64BigEndian (n.asInt);
  4477. }
  4478. void OutputStream::writeString (const String& text)
  4479. {
  4480. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  4481. // if lots of large, persistent strings were to be written to streams).
  4482. const int numBytes = text.getNumBytesAsUTF8() + 1;
  4483. HeapBlock<char> temp (numBytes);
  4484. text.copyToUTF8 (temp, numBytes);
  4485. write (temp, numBytes);
  4486. }
  4487. void OutputStream::writeText (const String& text, const bool asUnicode,
  4488. const bool writeUnicodeHeaderBytes)
  4489. {
  4490. if (asUnicode)
  4491. {
  4492. if (writeUnicodeHeaderBytes)
  4493. write ("\x0ff\x0fe", 2);
  4494. const juce_wchar* src = (const juce_wchar*) text;
  4495. bool lastCharWasReturn = false;
  4496. while (*src != 0)
  4497. {
  4498. if (*src == L'\n' && ! lastCharWasReturn)
  4499. writeShort ((short) L'\r');
  4500. lastCharWasReturn = (*src == L'\r');
  4501. writeShort ((short) *src++);
  4502. }
  4503. }
  4504. else
  4505. {
  4506. const char* src = text.toUTF8();
  4507. const char* t = src;
  4508. for (;;)
  4509. {
  4510. if (*t == '\n')
  4511. {
  4512. if (t > src)
  4513. write (src, (int) (t - src));
  4514. write ("\r\n", 2);
  4515. src = t + 1;
  4516. }
  4517. else if (*t == '\r')
  4518. {
  4519. if (t[1] == '\n')
  4520. ++t;
  4521. }
  4522. else if (*t == 0)
  4523. {
  4524. if (t > src)
  4525. write (src, (int) (t - src));
  4526. break;
  4527. }
  4528. ++t;
  4529. }
  4530. }
  4531. }
  4532. int OutputStream::writeFromInputStream (InputStream& source, int numBytesToWrite)
  4533. {
  4534. if (numBytesToWrite < 0)
  4535. numBytesToWrite = 0x7fffffff;
  4536. int numWritten = 0;
  4537. while (numBytesToWrite > 0 && ! source.isExhausted())
  4538. {
  4539. char buffer [8192];
  4540. const int num = source.read (buffer, (int) jmin ((size_t) numBytesToWrite, sizeof (buffer)));
  4541. if (num == 0)
  4542. break;
  4543. write (buffer, num);
  4544. numBytesToWrite -= num;
  4545. numWritten += num;
  4546. }
  4547. return numWritten;
  4548. }
  4549. OutputStream& JUCE_PUBLIC_FUNCTION operator<< (OutputStream& stream, const int number)
  4550. {
  4551. return stream << String (number);
  4552. }
  4553. OutputStream& JUCE_PUBLIC_FUNCTION operator<< (OutputStream& stream, const double number)
  4554. {
  4555. return stream << String (number);
  4556. }
  4557. OutputStream& JUCE_PUBLIC_FUNCTION operator<< (OutputStream& stream, const char character)
  4558. {
  4559. stream.writeByte (character);
  4560. return stream;
  4561. }
  4562. OutputStream& JUCE_PUBLIC_FUNCTION operator<< (OutputStream& stream, const char* const text)
  4563. {
  4564. stream.write (text, (int) strlen (text));
  4565. return stream;
  4566. }
  4567. END_JUCE_NAMESPACE
  4568. /*** End of inlined file: juce_OutputStream.cpp ***/
  4569. /*** Start of inlined file: juce_DirectoryIterator.cpp ***/
  4570. BEGIN_JUCE_NAMESPACE
  4571. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4572. bool* isDirectory, bool* isHidden, int64* fileSize,
  4573. Time* modTime, Time* creationTime, bool* isReadOnly);
  4574. bool juce_findFileNext (void* handle, String& resultFile,
  4575. bool* isDirectory, bool* isHidden, int64* fileSize,
  4576. Time* modTime, Time* creationTime, bool* isReadOnly);
  4577. void juce_findFileClose (void* handle);
  4578. DirectoryIterator::DirectoryIterator (const File& directory,
  4579. bool isRecursive,
  4580. const String& wc,
  4581. const int whatToLookFor_)
  4582. : wildCard (wc),
  4583. index (-1),
  4584. whatToLookFor (whatToLookFor_)
  4585. {
  4586. // you have to specify the type of files you're looking for!
  4587. jassert ((whatToLookFor_ & (File::findFiles | File::findDirectories)) != 0);
  4588. jassert (whatToLookFor_ > 0 && whatToLookFor_ <= 7);
  4589. String path (directory.getFullPathName());
  4590. if (! path.endsWithChar (File::separator))
  4591. path += File::separator;
  4592. String filename;
  4593. bool isDirectory, isHidden;
  4594. void* const handle = juce_findFileStart (path,
  4595. isRecursive ? T("*") : wc,
  4596. filename, &isDirectory, &isHidden, 0, 0, 0, 0);
  4597. if (handle != 0)
  4598. {
  4599. do
  4600. {
  4601. if (! filename.containsOnly (T(".")))
  4602. {
  4603. bool addToList = false;
  4604. if (isDirectory)
  4605. {
  4606. if (isRecursive
  4607. && ((whatToLookFor_ & File::ignoreHiddenFiles) == 0
  4608. || ! isHidden))
  4609. {
  4610. dirsFound.add (File (path + filename, 0));
  4611. }
  4612. addToList = (whatToLookFor_ & File::findDirectories) != 0;
  4613. }
  4614. else
  4615. {
  4616. addToList = (whatToLookFor_ & File::findFiles) != 0;
  4617. }
  4618. // if it's recursive, we're not relying on the OS iterator
  4619. // to do the wildcard match, so do it now..
  4620. if (isRecursive && addToList)
  4621. addToList = filename.matchesWildcard (wc, true);
  4622. if (addToList && (whatToLookFor_ & File::ignoreHiddenFiles) != 0)
  4623. addToList = ! isHidden;
  4624. if (addToList)
  4625. filesFound.add (File (path + filename, 0));
  4626. }
  4627. } while (juce_findFileNext (handle, filename, &isDirectory, &isHidden, 0, 0, 0, 0));
  4628. juce_findFileClose (handle);
  4629. }
  4630. }
  4631. DirectoryIterator::~DirectoryIterator()
  4632. {
  4633. }
  4634. bool DirectoryIterator::next()
  4635. {
  4636. if (subIterator != 0)
  4637. {
  4638. if (subIterator->next())
  4639. return true;
  4640. subIterator = 0;
  4641. }
  4642. if (index >= filesFound.size() + dirsFound.size() - 1)
  4643. return false;
  4644. ++index;
  4645. if (index >= filesFound.size())
  4646. {
  4647. subIterator = new DirectoryIterator (dirsFound.getReference (index - filesFound.size()),
  4648. true, wildCard, whatToLookFor);
  4649. return next();
  4650. }
  4651. return true;
  4652. }
  4653. const File DirectoryIterator::getFile() const
  4654. {
  4655. if (subIterator != 0)
  4656. return subIterator->getFile();
  4657. return filesFound [index];
  4658. }
  4659. float DirectoryIterator::getEstimatedProgress() const
  4660. {
  4661. if (filesFound.size() + dirsFound.size() == 0)
  4662. {
  4663. return 0.0f;
  4664. }
  4665. else
  4666. {
  4667. const float detailedIndex = (subIterator != 0) ? index + subIterator->getEstimatedProgress()
  4668. : (float) index;
  4669. return detailedIndex / (filesFound.size() + dirsFound.size());
  4670. }
  4671. }
  4672. END_JUCE_NAMESPACE
  4673. /*** End of inlined file: juce_DirectoryIterator.cpp ***/
  4674. /*** Start of inlined file: juce_File.cpp ***/
  4675. #ifdef _MSC_VER
  4676. #pragma warning (disable: 4514)
  4677. #pragma warning (push)
  4678. #endif
  4679. #if ! JUCE_WINDOWS
  4680. #include <pwd.h>
  4681. #endif
  4682. BEGIN_JUCE_NAMESPACE
  4683. #ifdef _MSC_VER
  4684. #pragma warning (pop)
  4685. #endif
  4686. void* juce_fileOpen (const String& path, bool forWriting);
  4687. void juce_fileClose (void* handle);
  4688. int juce_fileWrite (void* handle, const void* buffer, int size);
  4689. int64 juce_fileGetPosition (void* handle);
  4690. int64 juce_fileSetPosition (void* handle, int64 pos);
  4691. void juce_fileFlush (void* handle);
  4692. bool juce_fileExists (const String& fileName, const bool dontCountDirectories);
  4693. bool juce_isDirectory (const String& fileName);
  4694. int64 juce_getFileSize (const String& fileName);
  4695. bool juce_canWriteToFile (const String& fileName);
  4696. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly);
  4697. void juce_getFileTimes (const String& fileName, int64& modificationTime, int64& accessTime, int64& creationTime);
  4698. bool juce_setFileTimes (const String& fileName, int64 modificationTime, int64 accessTime, int64 creationTime);
  4699. bool juce_deleteFile (const String& fileName);
  4700. bool juce_copyFile (const String& source, const String& dest);
  4701. bool juce_moveFile (const String& source, const String& dest);
  4702. // this must also create all paths involved in the directory.
  4703. void juce_createDirectory (const String& fileName);
  4704. bool juce_launchFile (const String& fileName, const String& parameters);
  4705. const StringArray juce_getFileSystemRoots();
  4706. const String juce_getVolumeLabel (const String& filenameOnVolume, int& volumeSerialNumber);
  4707. // starts a directory search operation with a wildcard, returning a handle for
  4708. // use in calls to juce_findFileNext.
  4709. // juce_firstResultFile gets the name of the file (not the whole pathname) and
  4710. // the other pointers, if non-null, are set based on the properties of the file.
  4711. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  4712. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  4713. Time* creationTime, bool* isReadOnly);
  4714. // returns false when no more files are found
  4715. bool juce_findFileNext (void* handle, String& resultFile,
  4716. bool* isDirectory, bool* isHidden, int64* fileSize,
  4717. Time* modTime, Time* creationTime, bool* isReadOnly);
  4718. void juce_findFileClose (void* handle);
  4719. static const String juce_addTrailingSeparator (const String& path)
  4720. {
  4721. return path.endsWithChar (File::separator) ? path
  4722. : path + File::separator;
  4723. }
  4724. static const String parseAbsolutePath (String path)
  4725. {
  4726. if (path.isEmpty())
  4727. return String::empty;
  4728. #if JUCE_WINDOWS
  4729. // Windows..
  4730. path = path.replaceCharacter (T('/'), T('\\'));
  4731. if (path.startsWithChar (File::separator))
  4732. {
  4733. if (path[1] != File::separator)
  4734. {
  4735. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4736. If you're trying to parse a string that may be either a relative path or an absolute path,
  4737. you MUST provide a context against which the partial path can be evaluated - you can do
  4738. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4739. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4740. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4741. */
  4742. jassertfalse
  4743. path = File::getCurrentWorkingDirectory().getFullPathName().substring (0, 2) + path;
  4744. }
  4745. }
  4746. else if (path.indexOfChar (T(':')) < 0)
  4747. {
  4748. if (path.isEmpty())
  4749. return String::empty;
  4750. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4751. If you're trying to parse a string that may be either a relative path or an absolute path,
  4752. you MUST provide a context against which the partial path can be evaluated - you can do
  4753. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4754. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4755. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4756. */
  4757. jassertfalse
  4758. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4759. }
  4760. #else
  4761. // Mac or Linux..
  4762. path = path.replaceCharacter (T('\\'), T('/'));
  4763. if (path.startsWithChar (T('~')))
  4764. {
  4765. const char* homeDir = 0;
  4766. if (path[1] == File::separator || path[1] == 0)
  4767. {
  4768. // expand a name of the form "~/abc"
  4769. path = File::getSpecialLocation (File::userHomeDirectory).getFullPathName()
  4770. + path.substring (1);
  4771. }
  4772. else
  4773. {
  4774. // expand a name of type "~dave/abc"
  4775. const String userName (path.substring (1).upToFirstOccurrenceOf (T("/"), false, false));
  4776. struct passwd* const pw = getpwnam (userName.toUTF8());
  4777. if (pw != 0)
  4778. {
  4779. String home (homeDir);
  4780. if (home.endsWithChar (File::separator))
  4781. home [home.length() - 1] = 0;
  4782. path = String (pw->pw_dir)
  4783. + path.substring (userName.length());
  4784. }
  4785. }
  4786. }
  4787. else if (! path.startsWithChar (File::separator))
  4788. {
  4789. /* When you supply a raw string to the File object constructor, it must be an absolute path.
  4790. If you're trying to parse a string that may be either a relative path or an absolute path,
  4791. you MUST provide a context against which the partial path can be evaluated - you can do
  4792. this by simply using File::getChildFile() instead of the File constructor. E.g. saying
  4793. "File::getCurrentWorkingDirectory().getChildFile (myUnknownPath)" would return an absolute
  4794. path if that's what was supplied, or would evaluate a partial path relative to the CWD.
  4795. */
  4796. jassert (path.startsWith (T("./"))); // (assume that a path "./xyz" is deliberately intended to be relative to the CWD)
  4797. return File::getCurrentWorkingDirectory().getChildFile (path).getFullPathName();
  4798. }
  4799. #endif
  4800. int len = path.length();
  4801. while (--len > 0 && path [len] == File::separator)
  4802. path [len] = 0;
  4803. return path;
  4804. }
  4805. const File File::nonexistent;
  4806. File::File (const String& fullPathName)
  4807. : fullPath (parseAbsolutePath (fullPathName))
  4808. {
  4809. }
  4810. File::File (const String& path, int)
  4811. : fullPath (path)
  4812. {
  4813. }
  4814. const File File::createFileWithoutCheckingPath (const String& path)
  4815. {
  4816. return File (path, 0);
  4817. }
  4818. File::File (const File& other)
  4819. : fullPath (other.fullPath)
  4820. {
  4821. }
  4822. File& File::operator= (const String& newPath)
  4823. {
  4824. fullPath = parseAbsolutePath (newPath);
  4825. return *this;
  4826. }
  4827. File& File::operator= (const File& other)
  4828. {
  4829. fullPath = other.fullPath;
  4830. return *this;
  4831. }
  4832. #if JUCE_LINUX
  4833. #define NAMES_ARE_CASE_SENSITIVE 1
  4834. #endif
  4835. bool File::areFileNamesCaseSensitive()
  4836. {
  4837. #if NAMES_ARE_CASE_SENSITIVE
  4838. return true;
  4839. #else
  4840. return false;
  4841. #endif
  4842. }
  4843. bool File::operator== (const File& other) const
  4844. {
  4845. // case-insensitive on Windows, but not on linux.
  4846. #if NAMES_ARE_CASE_SENSITIVE
  4847. return fullPath == other.fullPath;
  4848. #else
  4849. return fullPath.equalsIgnoreCase (other.fullPath);
  4850. #endif
  4851. }
  4852. bool File::operator!= (const File& other) const
  4853. {
  4854. return ! operator== (other);
  4855. }
  4856. bool File::exists() const
  4857. {
  4858. return juce_fileExists (fullPath, false);
  4859. }
  4860. bool File::existsAsFile() const
  4861. {
  4862. return juce_fileExists (fullPath, true);
  4863. }
  4864. bool File::isDirectory() const
  4865. {
  4866. return juce_isDirectory (fullPath);
  4867. }
  4868. bool File::hasWriteAccess() const
  4869. {
  4870. if (exists())
  4871. return juce_canWriteToFile (fullPath);
  4872. #if ! JUCE_WINDOWS
  4873. else if ((! isDirectory()) && fullPath.containsChar (separator))
  4874. return getParentDirectory().hasWriteAccess();
  4875. else
  4876. return false;
  4877. #else
  4878. // on windows, it seems that even read-only directories can still be written into,
  4879. // so checking the parent directory's permissions would return the wrong result..
  4880. else
  4881. return true;
  4882. #endif
  4883. }
  4884. bool File::setReadOnly (const bool shouldBeReadOnly,
  4885. const bool applyRecursively) const
  4886. {
  4887. bool worked = true;
  4888. if (applyRecursively && isDirectory())
  4889. {
  4890. Array <File> subFiles;
  4891. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4892. for (int i = subFiles.size(); --i >= 0;)
  4893. worked = subFiles.getReference(i).setReadOnly (shouldBeReadOnly, true) && worked;
  4894. }
  4895. return juce_setFileReadOnly (fullPath, shouldBeReadOnly) && worked;
  4896. }
  4897. bool File::deleteFile() const
  4898. {
  4899. return (! exists())
  4900. || juce_deleteFile (fullPath);
  4901. }
  4902. bool File::deleteRecursively() const
  4903. {
  4904. bool worked = true;
  4905. if (isDirectory())
  4906. {
  4907. Array<File> subFiles;
  4908. findChildFiles (subFiles, File::findFilesAndDirectories, false);
  4909. for (int i = subFiles.size(); --i >= 0;)
  4910. worked = subFiles.getReference(i).deleteRecursively() && worked;
  4911. }
  4912. return deleteFile() && worked;
  4913. }
  4914. bool File::moveFileTo (const File& newFile) const
  4915. {
  4916. if (newFile.fullPath == fullPath)
  4917. return true;
  4918. #if ! NAMES_ARE_CASE_SENSITIVE
  4919. if (*this != newFile)
  4920. #endif
  4921. if (! newFile.deleteFile())
  4922. return false;
  4923. return juce_moveFile (fullPath, newFile.fullPath);
  4924. }
  4925. bool File::copyFileTo (const File& newFile) const
  4926. {
  4927. if (*this == newFile)
  4928. return true;
  4929. if (! newFile.deleteFile())
  4930. return false;
  4931. return juce_copyFile (fullPath, newFile.fullPath);
  4932. }
  4933. bool File::copyDirectoryTo (const File& newDirectory) const
  4934. {
  4935. if (isDirectory() && newDirectory.createDirectory())
  4936. {
  4937. Array<File> subFiles;
  4938. findChildFiles (subFiles, File::findFiles, false);
  4939. int i;
  4940. for (i = 0; i < subFiles.size(); ++i)
  4941. if (! subFiles.getReference(i).copyFileTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4942. return false;
  4943. subFiles.clear();
  4944. findChildFiles (subFiles, File::findDirectories, false);
  4945. for (i = 0; i < subFiles.size(); ++i)
  4946. if (! subFiles.getReference(i).copyDirectoryTo (newDirectory.getChildFile (subFiles.getReference(i).getFileName())))
  4947. return false;
  4948. return true;
  4949. }
  4950. return false;
  4951. }
  4952. const String File::getPathUpToLastSlash() const
  4953. {
  4954. const int lastSlash = fullPath.lastIndexOfChar (separator);
  4955. if (lastSlash > 0)
  4956. return fullPath.substring (0, lastSlash);
  4957. else if (lastSlash == 0)
  4958. return separatorString;
  4959. else
  4960. return fullPath;
  4961. }
  4962. const File File::getParentDirectory() const
  4963. {
  4964. return File (getPathUpToLastSlash());
  4965. }
  4966. const String File::getFileName() const
  4967. {
  4968. return fullPath.substring (fullPath.lastIndexOfChar (separator) + 1);
  4969. }
  4970. int File::hashCode() const
  4971. {
  4972. return fullPath.hashCode();
  4973. }
  4974. int64 File::hashCode64() const
  4975. {
  4976. return fullPath.hashCode64();
  4977. }
  4978. const String File::getFileNameWithoutExtension() const
  4979. {
  4980. const int lastSlash = fullPath.lastIndexOfChar (separator) + 1;
  4981. const int lastDot = fullPath.lastIndexOfChar (T('.'));
  4982. if (lastDot > lastSlash)
  4983. return fullPath.substring (lastSlash, lastDot);
  4984. else
  4985. return fullPath.substring (lastSlash);
  4986. }
  4987. bool File::isAChildOf (const File& potentialParent) const
  4988. {
  4989. if (potentialParent == File::nonexistent)
  4990. return false;
  4991. const String ourPath (getPathUpToLastSlash());
  4992. #if NAMES_ARE_CASE_SENSITIVE
  4993. if (potentialParent.fullPath == ourPath)
  4994. #else
  4995. if (potentialParent.fullPath.equalsIgnoreCase (ourPath))
  4996. #endif
  4997. {
  4998. return true;
  4999. }
  5000. else if (potentialParent.fullPath.length() >= ourPath.length())
  5001. {
  5002. return false;
  5003. }
  5004. else
  5005. {
  5006. return getParentDirectory().isAChildOf (potentialParent);
  5007. }
  5008. }
  5009. bool File::isAbsolutePath (const String& path)
  5010. {
  5011. return path.startsWithChar (T('/')) || path.startsWithChar (T('\\'))
  5012. #if JUCE_WINDOWS
  5013. || (path.isNotEmpty() && ((const String&) path)[1] == T(':'));
  5014. #else
  5015. || path.startsWithChar (T('~'));
  5016. #endif
  5017. }
  5018. const File File::getChildFile (String relativePath) const
  5019. {
  5020. if (isAbsolutePath (relativePath))
  5021. {
  5022. // the path is really absolute..
  5023. return File (relativePath);
  5024. }
  5025. else
  5026. {
  5027. // it's relative, so remove any ../ or ./ bits at the start.
  5028. String path (fullPath);
  5029. if (relativePath[0] == T('.'))
  5030. {
  5031. #if JUCE_WINDOWS
  5032. relativePath = relativePath.replaceCharacter (T('/'), T('\\')).trimStart();
  5033. #else
  5034. relativePath = relativePath.replaceCharacter (T('\\'), T('/')).trimStart();
  5035. #endif
  5036. while (relativePath[0] == T('.'))
  5037. {
  5038. if (relativePath[1] == T('.'))
  5039. {
  5040. if (relativePath [2] == 0 || relativePath[2] == separator)
  5041. {
  5042. const int lastSlash = path.lastIndexOfChar (separator);
  5043. if (lastSlash >= 0)
  5044. path = path.substring (0, lastSlash);
  5045. relativePath = relativePath.substring (3);
  5046. }
  5047. else
  5048. {
  5049. break;
  5050. }
  5051. }
  5052. else if (relativePath[1] == separator)
  5053. {
  5054. relativePath = relativePath.substring (2);
  5055. }
  5056. else
  5057. {
  5058. break;
  5059. }
  5060. }
  5061. }
  5062. return File (juce_addTrailingSeparator (path) + relativePath);
  5063. }
  5064. }
  5065. const File File::getSiblingFile (const String& fileName) const
  5066. {
  5067. return getParentDirectory().getChildFile (fileName);
  5068. }
  5069. int64 File::getSize() const
  5070. {
  5071. return juce_getFileSize (fullPath);
  5072. }
  5073. const String File::descriptionOfSizeInBytes (const int64 bytes)
  5074. {
  5075. if (bytes == 1)
  5076. {
  5077. return "1 byte";
  5078. }
  5079. else if (bytes < 1024)
  5080. {
  5081. return String ((int) bytes) + " bytes";
  5082. }
  5083. else if (bytes < 1024 * 1024)
  5084. {
  5085. return String (bytes / 1024.0, 1) + " KB";
  5086. }
  5087. else if (bytes < 1024 * 1024 * 1024)
  5088. {
  5089. return String (bytes / (1024.0 * 1024.0), 1) + " MB";
  5090. }
  5091. else
  5092. {
  5093. return String (bytes / (1024.0 * 1024.0 * 1024.0), 1) + " GB";
  5094. }
  5095. }
  5096. bool File::create() const
  5097. {
  5098. if (! exists())
  5099. {
  5100. const File parentDir (getParentDirectory());
  5101. if (parentDir == *this || ! parentDir.createDirectory())
  5102. return false;
  5103. void* const fh = juce_fileOpen (fullPath, true);
  5104. if (fh == 0)
  5105. return false;
  5106. juce_fileClose (fh);
  5107. }
  5108. return true;
  5109. }
  5110. bool File::createDirectory() const
  5111. {
  5112. if (! isDirectory())
  5113. {
  5114. const File parentDir (getParentDirectory());
  5115. if (parentDir == *this || ! parentDir.createDirectory())
  5116. return false;
  5117. String dir (fullPath);
  5118. while (dir.endsWithChar (separator))
  5119. dir [dir.length() - 1] = 0;
  5120. juce_createDirectory (dir);
  5121. return isDirectory();
  5122. }
  5123. return true;
  5124. }
  5125. const Time File::getCreationTime() const
  5126. {
  5127. int64 m, a, c;
  5128. juce_getFileTimes (fullPath, m, a, c);
  5129. return Time (c);
  5130. }
  5131. bool File::setCreationTime (const Time& t) const
  5132. {
  5133. return juce_setFileTimes (fullPath, 0, 0, t.toMilliseconds());
  5134. }
  5135. const Time File::getLastModificationTime() const
  5136. {
  5137. int64 m, a, c;
  5138. juce_getFileTimes (fullPath, m, a, c);
  5139. return Time (m);
  5140. }
  5141. bool File::setLastModificationTime (const Time& t) const
  5142. {
  5143. return juce_setFileTimes (fullPath, t.toMilliseconds(), 0, 0);
  5144. }
  5145. const Time File::getLastAccessTime() const
  5146. {
  5147. int64 m, a, c;
  5148. juce_getFileTimes (fullPath, m, a, c);
  5149. return Time (a);
  5150. }
  5151. bool File::setLastAccessTime (const Time& t) const
  5152. {
  5153. return juce_setFileTimes (fullPath, 0, t.toMilliseconds(), 0);
  5154. }
  5155. bool File::loadFileAsData (MemoryBlock& destBlock) const
  5156. {
  5157. if (! existsAsFile())
  5158. return false;
  5159. FileInputStream in (*this);
  5160. return getSize() == in.readIntoMemoryBlock (destBlock);
  5161. }
  5162. const String File::loadFileAsString() const
  5163. {
  5164. if (! existsAsFile())
  5165. return String::empty;
  5166. FileInputStream in (*this);
  5167. return in.readEntireStreamAsString();
  5168. }
  5169. static inline bool fileTypeMatches (const int whatToLookFor,
  5170. const bool isDir,
  5171. const bool isHidden)
  5172. {
  5173. return (whatToLookFor & (isDir ? File::findDirectories
  5174. : File::findFiles)) != 0
  5175. && ((! isHidden)
  5176. || (whatToLookFor & File::ignoreHiddenFiles) == 0);
  5177. }
  5178. int File::findChildFiles (Array<File>& results,
  5179. const int whatToLookFor,
  5180. const bool searchRecursively,
  5181. const String& wildCardPattern) const
  5182. {
  5183. // you have to specify the type of files you're looking for!
  5184. jassert ((whatToLookFor & (findFiles | findDirectories)) != 0);
  5185. int total = 0;
  5186. // find child files or directories in this directory first..
  5187. if (isDirectory())
  5188. {
  5189. const String path (juce_addTrailingSeparator (fullPath));
  5190. String filename;
  5191. bool itemIsDirectory, itemIsHidden;
  5192. void* const handle = juce_findFileStart (path, wildCardPattern, filename,
  5193. &itemIsDirectory, &itemIsHidden,
  5194. 0, 0, 0, 0);
  5195. if (handle != 0)
  5196. {
  5197. do
  5198. {
  5199. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5200. && ! filename.containsOnly (T(".")))
  5201. {
  5202. results.add (File (path + filename, 0));
  5203. ++total;
  5204. }
  5205. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5206. juce_findFileClose (handle);
  5207. }
  5208. }
  5209. else
  5210. {
  5211. // trying to search for files inside a non-directory?
  5212. //jassertfalse
  5213. }
  5214. // and recurse down if required.
  5215. if (searchRecursively)
  5216. {
  5217. Array<File> subDirectories;
  5218. findChildFiles (subDirectories, File::findDirectories, false);
  5219. for (int i = 0; i < subDirectories.size(); ++i)
  5220. {
  5221. total += subDirectories.getReference(i).findChildFiles (results, whatToLookFor,
  5222. true, wildCardPattern);
  5223. }
  5224. }
  5225. return total;
  5226. }
  5227. int File::getNumberOfChildFiles (const int whatToLookFor,
  5228. const String& wildCardPattern) const
  5229. {
  5230. // you have to specify the type of files you're looking for!
  5231. jassert (whatToLookFor > 0 && whatToLookFor <= 3);
  5232. int count = 0;
  5233. if (isDirectory())
  5234. {
  5235. String filename;
  5236. bool itemIsDirectory, itemIsHidden;
  5237. void* const handle = juce_findFileStart (fullPath, wildCardPattern, filename,
  5238. &itemIsDirectory, &itemIsHidden,
  5239. 0, 0, 0, 0);
  5240. if (handle != 0)
  5241. {
  5242. do
  5243. {
  5244. if (fileTypeMatches (whatToLookFor, itemIsDirectory, itemIsHidden)
  5245. && ! filename.containsOnly (T(".")))
  5246. {
  5247. ++count;
  5248. }
  5249. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5250. juce_findFileClose (handle);
  5251. }
  5252. }
  5253. else
  5254. {
  5255. // trying to search for files inside a non-directory?
  5256. jassertfalse
  5257. }
  5258. return count;
  5259. }
  5260. bool File::containsSubDirectories() const
  5261. {
  5262. bool result = false;
  5263. if (isDirectory())
  5264. {
  5265. String filename;
  5266. bool itemIsDirectory, itemIsHidden;
  5267. void* const handle = juce_findFileStart (juce_addTrailingSeparator (fullPath),
  5268. T("*"), filename,
  5269. &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0);
  5270. if (handle != 0)
  5271. {
  5272. do
  5273. {
  5274. if (itemIsDirectory)
  5275. {
  5276. result = true;
  5277. break;
  5278. }
  5279. } while (juce_findFileNext (handle, filename, &itemIsDirectory, &itemIsHidden, 0, 0, 0, 0));
  5280. juce_findFileClose (handle);
  5281. }
  5282. }
  5283. return result;
  5284. }
  5285. const File File::getNonexistentChildFile (const String& prefix_,
  5286. const String& suffix,
  5287. bool putNumbersInBrackets) const
  5288. {
  5289. File f (getChildFile (prefix_ + suffix));
  5290. if (f.exists())
  5291. {
  5292. int num = 2;
  5293. String prefix (prefix_);
  5294. // remove any bracketed numbers that may already be on the end..
  5295. if (prefix.trim().endsWithChar (T(')')))
  5296. {
  5297. putNumbersInBrackets = true;
  5298. const int openBracks = prefix.lastIndexOfChar (T('('));
  5299. const int closeBracks = prefix.lastIndexOfChar (T(')'));
  5300. if (openBracks > 0
  5301. && closeBracks > openBracks
  5302. && prefix.substring (openBracks + 1, closeBracks).containsOnly (T("0123456789")))
  5303. {
  5304. num = prefix.substring (openBracks + 1, closeBracks).getIntValue() + 1;
  5305. prefix = prefix.substring (0, openBracks);
  5306. }
  5307. }
  5308. // also use brackets if it ends in a digit.
  5309. putNumbersInBrackets = putNumbersInBrackets
  5310. || CharacterFunctions::isDigit (prefix.getLastCharacter());
  5311. do
  5312. {
  5313. if (putNumbersInBrackets)
  5314. f = getChildFile (prefix + T('(') + String (num++) + T(')') + suffix);
  5315. else
  5316. f = getChildFile (prefix + String (num++) + suffix);
  5317. } while (f.exists());
  5318. }
  5319. return f;
  5320. }
  5321. const File File::getNonexistentSibling (const bool putNumbersInBrackets) const
  5322. {
  5323. if (exists())
  5324. {
  5325. return getParentDirectory()
  5326. .getNonexistentChildFile (getFileNameWithoutExtension(),
  5327. getFileExtension(),
  5328. putNumbersInBrackets);
  5329. }
  5330. else
  5331. {
  5332. return *this;
  5333. }
  5334. }
  5335. const String File::getFileExtension() const
  5336. {
  5337. String ext;
  5338. if (! isDirectory())
  5339. {
  5340. const int indexOfDot = fullPath.lastIndexOfChar (T('.'));
  5341. if (indexOfDot > fullPath.lastIndexOfChar (separator))
  5342. ext = fullPath.substring (indexOfDot);
  5343. }
  5344. return ext;
  5345. }
  5346. bool File::hasFileExtension (const String& possibleSuffix) const
  5347. {
  5348. if (possibleSuffix.isEmpty())
  5349. return fullPath.lastIndexOfChar (T('.')) <= fullPath.lastIndexOfChar (separator);
  5350. const int semicolon = possibleSuffix.indexOfChar (0, T(';'));
  5351. if (semicolon >= 0)
  5352. {
  5353. return hasFileExtension (possibleSuffix.substring (0, semicolon).trimEnd())
  5354. || hasFileExtension (possibleSuffix.substring (semicolon + 1).trimStart());
  5355. }
  5356. else
  5357. {
  5358. if (fullPath.endsWithIgnoreCase (possibleSuffix))
  5359. {
  5360. if (possibleSuffix.startsWithChar (T('.')))
  5361. return true;
  5362. const int dotPos = fullPath.length() - possibleSuffix.length() - 1;
  5363. if (dotPos >= 0)
  5364. return fullPath [dotPos] == T('.');
  5365. }
  5366. }
  5367. return false;
  5368. }
  5369. const File File::withFileExtension (const String& newExtension) const
  5370. {
  5371. if (fullPath.isEmpty())
  5372. return File::nonexistent;
  5373. String filePart (getFileName());
  5374. int i = filePart.lastIndexOfChar (T('.'));
  5375. if (i < 0)
  5376. i = filePart.length();
  5377. String newExt (newExtension);
  5378. if (newExt.isNotEmpty() && ! newExt.startsWithChar (T('.')))
  5379. newExt = T(".") + newExt;
  5380. return getSiblingFile (filePart.substring (0, i) + newExt);
  5381. }
  5382. bool File::startAsProcess (const String& parameters) const
  5383. {
  5384. return exists()
  5385. && juce_launchFile (fullPath, parameters);
  5386. }
  5387. FileInputStream* File::createInputStream() const
  5388. {
  5389. if (existsAsFile())
  5390. return new FileInputStream (*this);
  5391. else
  5392. return 0;
  5393. }
  5394. FileOutputStream* File::createOutputStream (const int bufferSize) const
  5395. {
  5396. ScopedPointer <FileOutputStream> out (new FileOutputStream (*this, bufferSize));
  5397. if (out->failedToOpen())
  5398. return 0;
  5399. return out.release();
  5400. }
  5401. bool File::appendData (const void* const dataToAppend,
  5402. const int numberOfBytes) const
  5403. {
  5404. if (numberOfBytes > 0)
  5405. {
  5406. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5407. if (out == 0)
  5408. return false;
  5409. out->write (dataToAppend, numberOfBytes);
  5410. }
  5411. return true;
  5412. }
  5413. bool File::replaceWithData (const void* const dataToWrite,
  5414. const int numberOfBytes) const
  5415. {
  5416. jassert (numberOfBytes >= 0); // a negative number of bytes??
  5417. if (numberOfBytes <= 0)
  5418. return deleteFile();
  5419. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5420. tempFile.getFile().appendData (dataToWrite, numberOfBytes);
  5421. return tempFile.overwriteTargetFileWithTemporary();
  5422. }
  5423. bool File::appendText (const String& text,
  5424. const bool asUnicode,
  5425. const bool writeUnicodeHeaderBytes) const
  5426. {
  5427. const ScopedPointer <FileOutputStream> out (createOutputStream());
  5428. if (out != 0)
  5429. {
  5430. out->writeText (text, asUnicode, writeUnicodeHeaderBytes);
  5431. return true;
  5432. }
  5433. return false;
  5434. }
  5435. bool File::replaceWithText (const String& textToWrite,
  5436. const bool asUnicode,
  5437. const bool writeUnicodeHeaderBytes) const
  5438. {
  5439. TemporaryFile tempFile (*this, TemporaryFile::useHiddenFile);
  5440. tempFile.getFile().appendText (textToWrite, asUnicode, writeUnicodeHeaderBytes);
  5441. return tempFile.overwriteTargetFileWithTemporary();
  5442. }
  5443. const String File::createLegalPathName (const String& original)
  5444. {
  5445. String s (original);
  5446. String start;
  5447. if (s[1] == T(':'))
  5448. {
  5449. start = s.substring (0, 2);
  5450. s = s.substring (2);
  5451. }
  5452. return start + s.removeCharacters (T("\"#@,;:<>*^|?"))
  5453. .substring (0, 1024);
  5454. }
  5455. const String File::createLegalFileName (const String& original)
  5456. {
  5457. String s (original.removeCharacters (T("\"#@,;:<>*^|?\\/")));
  5458. const int maxLength = 128; // only the length of the filename, not the whole path
  5459. const int len = s.length();
  5460. if (len > maxLength)
  5461. {
  5462. const int lastDot = s.lastIndexOfChar (T('.'));
  5463. if (lastDot > jmax (0, len - 12))
  5464. {
  5465. s = s.substring (0, maxLength - (len - lastDot))
  5466. + s.substring (lastDot);
  5467. }
  5468. else
  5469. {
  5470. s = s.substring (0, maxLength);
  5471. }
  5472. }
  5473. return s;
  5474. }
  5475. const String File::getRelativePathFrom (const File& dir) const
  5476. {
  5477. String thisPath (fullPath);
  5478. {
  5479. int len = thisPath.length();
  5480. while (--len >= 0 && thisPath [len] == File::separator)
  5481. thisPath [len] = 0;
  5482. }
  5483. String dirPath (juce_addTrailingSeparator ((dir.existsAsFile()) ? dir.getParentDirectory().getFullPathName()
  5484. : dir.fullPath));
  5485. const int len = jmin (thisPath.length(), dirPath.length());
  5486. int commonBitLength = 0;
  5487. for (int i = 0; i < len; ++i)
  5488. {
  5489. #if NAMES_ARE_CASE_SENSITIVE
  5490. if (thisPath[i] != dirPath[i])
  5491. #else
  5492. if (CharacterFunctions::toLowerCase (thisPath[i])
  5493. != CharacterFunctions::toLowerCase (dirPath[i]))
  5494. #endif
  5495. {
  5496. break;
  5497. }
  5498. ++commonBitLength;
  5499. }
  5500. while (commonBitLength > 0 && thisPath [commonBitLength - 1] != File::separator)
  5501. --commonBitLength;
  5502. // if the only common bit is the root, then just return the full path..
  5503. if (commonBitLength <= 0
  5504. || (commonBitLength == 1 && thisPath [1] == File::separator))
  5505. return fullPath;
  5506. thisPath = thisPath.substring (commonBitLength);
  5507. dirPath = dirPath.substring (commonBitLength);
  5508. while (dirPath.isNotEmpty())
  5509. {
  5510. #if JUCE_WINDOWS
  5511. thisPath = T("..\\") + thisPath;
  5512. #else
  5513. thisPath = T("../") + thisPath;
  5514. #endif
  5515. const int sep = dirPath.indexOfChar (separator);
  5516. if (sep >= 0)
  5517. dirPath = dirPath.substring (sep + 1);
  5518. else
  5519. dirPath = String::empty;
  5520. }
  5521. return thisPath;
  5522. }
  5523. void File::findFileSystemRoots (Array<File>& destArray)
  5524. {
  5525. const StringArray roots (juce_getFileSystemRoots());
  5526. for (int i = 0; i < roots.size(); ++i)
  5527. destArray.add (File (roots[i]));
  5528. }
  5529. const String File::getVolumeLabel() const
  5530. {
  5531. int serialNum;
  5532. return juce_getVolumeLabel (fullPath, serialNum);
  5533. }
  5534. int File::getVolumeSerialNumber() const
  5535. {
  5536. int serialNum;
  5537. juce_getVolumeLabel (fullPath, serialNum);
  5538. return serialNum;
  5539. }
  5540. const File File::createTempFile (const String& fileNameEnding)
  5541. {
  5542. const File tempFile (getSpecialLocation (tempDirectory)
  5543. .getChildFile (T("temp_") + String (Random::getSystemRandom().nextInt()))
  5544. .withFileExtension (fileNameEnding));
  5545. if (tempFile.exists())
  5546. return createTempFile (fileNameEnding);
  5547. else
  5548. return tempFile;
  5549. }
  5550. END_JUCE_NAMESPACE
  5551. /*** End of inlined file: juce_File.cpp ***/
  5552. /*** Start of inlined file: juce_FileInputStream.cpp ***/
  5553. BEGIN_JUCE_NAMESPACE
  5554. void* juce_fileOpen (const String& path, bool forWriting);
  5555. void juce_fileClose (void* handle);
  5556. int juce_fileRead (void* handle, void* buffer, int size);
  5557. int64 juce_fileSetPosition (void* handle, int64 pos);
  5558. FileInputStream::FileInputStream (const File& f)
  5559. : file (f),
  5560. currentPosition (0),
  5561. needToSeek (true)
  5562. {
  5563. totalSize = f.getSize();
  5564. fileHandle = juce_fileOpen (f.getFullPathName(), false);
  5565. }
  5566. FileInputStream::~FileInputStream()
  5567. {
  5568. juce_fileClose (fileHandle);
  5569. }
  5570. int64 FileInputStream::getTotalLength()
  5571. {
  5572. return totalSize;
  5573. }
  5574. int FileInputStream::read (void* buffer, int bytesToRead)
  5575. {
  5576. int num = 0;
  5577. if (needToSeek)
  5578. {
  5579. if (juce_fileSetPosition (fileHandle, currentPosition) < 0)
  5580. return 0;
  5581. needToSeek = false;
  5582. }
  5583. num = juce_fileRead (fileHandle, buffer, bytesToRead);
  5584. currentPosition += num;
  5585. return num;
  5586. }
  5587. bool FileInputStream::isExhausted()
  5588. {
  5589. return currentPosition >= totalSize;
  5590. }
  5591. int64 FileInputStream::getPosition()
  5592. {
  5593. return currentPosition;
  5594. }
  5595. bool FileInputStream::setPosition (int64 pos)
  5596. {
  5597. pos = jlimit ((int64) 0, totalSize, pos);
  5598. needToSeek |= (currentPosition != pos);
  5599. currentPosition = pos;
  5600. return true;
  5601. }
  5602. END_JUCE_NAMESPACE
  5603. /*** End of inlined file: juce_FileInputStream.cpp ***/
  5604. /*** Start of inlined file: juce_FileOutputStream.cpp ***/
  5605. BEGIN_JUCE_NAMESPACE
  5606. void* juce_fileOpen (const String& path, bool forWriting);
  5607. void juce_fileClose (void* handle);
  5608. int juce_fileWrite (void* handle, const void* buffer, int size);
  5609. void juce_fileFlush (void* handle);
  5610. int64 juce_fileGetPosition (void* handle);
  5611. int64 juce_fileSetPosition (void* handle, int64 pos);
  5612. FileOutputStream::FileOutputStream (const File& f,
  5613. const int bufferSize_)
  5614. : file (f),
  5615. bufferSize (bufferSize_),
  5616. bytesInBuffer (0)
  5617. {
  5618. fileHandle = juce_fileOpen (f.getFullPathName(), true);
  5619. if (fileHandle != 0)
  5620. {
  5621. currentPosition = juce_fileGetPosition (fileHandle);
  5622. if (currentPosition < 0)
  5623. {
  5624. jassertfalse
  5625. juce_fileClose (fileHandle);
  5626. fileHandle = 0;
  5627. }
  5628. }
  5629. buffer.malloc (jmax (bufferSize_, 16));
  5630. }
  5631. FileOutputStream::~FileOutputStream()
  5632. {
  5633. flush();
  5634. juce_fileClose (fileHandle);
  5635. }
  5636. int64 FileOutputStream::getPosition()
  5637. {
  5638. return currentPosition;
  5639. }
  5640. bool FileOutputStream::setPosition (int64 newPosition)
  5641. {
  5642. if (newPosition != currentPosition)
  5643. {
  5644. flush();
  5645. currentPosition = juce_fileSetPosition (fileHandle, newPosition);
  5646. }
  5647. return newPosition == currentPosition;
  5648. }
  5649. void FileOutputStream::flush()
  5650. {
  5651. if (bytesInBuffer > 0)
  5652. {
  5653. juce_fileWrite (fileHandle, buffer, bytesInBuffer);
  5654. bytesInBuffer = 0;
  5655. }
  5656. juce_fileFlush (fileHandle);
  5657. }
  5658. bool FileOutputStream::write (const void* const src, const int numBytes)
  5659. {
  5660. if (bytesInBuffer + numBytes < bufferSize)
  5661. {
  5662. memcpy (buffer + bytesInBuffer, src, numBytes);
  5663. bytesInBuffer += numBytes;
  5664. currentPosition += numBytes;
  5665. }
  5666. else
  5667. {
  5668. if (bytesInBuffer > 0)
  5669. {
  5670. // flush the reservoir
  5671. const bool wroteOk = (juce_fileWrite (fileHandle, buffer, bytesInBuffer) == bytesInBuffer);
  5672. bytesInBuffer = 0;
  5673. if (! wroteOk)
  5674. return false;
  5675. }
  5676. if (numBytes < bufferSize)
  5677. {
  5678. memcpy (buffer + bytesInBuffer, src, numBytes);
  5679. bytesInBuffer += numBytes;
  5680. currentPosition += numBytes;
  5681. }
  5682. else
  5683. {
  5684. const int bytesWritten = juce_fileWrite (fileHandle, src, numBytes);
  5685. currentPosition += bytesWritten;
  5686. return bytesWritten == numBytes;
  5687. }
  5688. }
  5689. return true;
  5690. }
  5691. END_JUCE_NAMESPACE
  5692. /*** End of inlined file: juce_FileOutputStream.cpp ***/
  5693. /*** Start of inlined file: juce_FileSearchPath.cpp ***/
  5694. BEGIN_JUCE_NAMESPACE
  5695. FileSearchPath::FileSearchPath()
  5696. {
  5697. }
  5698. FileSearchPath::FileSearchPath (const String& path)
  5699. {
  5700. init (path);
  5701. }
  5702. FileSearchPath::FileSearchPath (const FileSearchPath& other)
  5703. : directories (other.directories)
  5704. {
  5705. }
  5706. FileSearchPath::~FileSearchPath()
  5707. {
  5708. }
  5709. FileSearchPath& FileSearchPath::operator= (const String& path)
  5710. {
  5711. init (path);
  5712. return *this;
  5713. }
  5714. void FileSearchPath::init (const String& path)
  5715. {
  5716. directories.clear();
  5717. directories.addTokens (path, T(";"), T("\""));
  5718. directories.trim();
  5719. directories.removeEmptyStrings();
  5720. for (int i = directories.size(); --i >= 0;)
  5721. directories.set (i, directories[i].unquoted());
  5722. }
  5723. int FileSearchPath::getNumPaths() const
  5724. {
  5725. return directories.size();
  5726. }
  5727. const File FileSearchPath::operator[] (const int index) const
  5728. {
  5729. return File (directories [index]);
  5730. }
  5731. const String FileSearchPath::toString() const
  5732. {
  5733. StringArray directories2 (directories);
  5734. for (int i = directories2.size(); --i >= 0;)
  5735. if (directories2[i].containsChar (T(';')))
  5736. directories2.set (i, directories2[i].quoted());
  5737. return directories2.joinIntoString (T(";"));
  5738. }
  5739. void FileSearchPath::add (const File& dir, const int insertIndex)
  5740. {
  5741. directories.insert (insertIndex, dir.getFullPathName());
  5742. }
  5743. void FileSearchPath::addIfNotAlreadyThere (const File& dir)
  5744. {
  5745. for (int i = 0; i < directories.size(); ++i)
  5746. if (File (directories[i]) == dir)
  5747. return;
  5748. add (dir);
  5749. }
  5750. void FileSearchPath::remove (const int index)
  5751. {
  5752. directories.remove (index);
  5753. }
  5754. void FileSearchPath::addPath (const FileSearchPath& other)
  5755. {
  5756. for (int i = 0; i < other.getNumPaths(); ++i)
  5757. addIfNotAlreadyThere (other[i]);
  5758. }
  5759. void FileSearchPath::removeRedundantPaths()
  5760. {
  5761. for (int i = directories.size(); --i >= 0;)
  5762. {
  5763. const File d1 (directories[i]);
  5764. for (int j = directories.size(); --j >= 0;)
  5765. {
  5766. const File d2 (directories[j]);
  5767. if ((i != j) && (d1.isAChildOf (d2) || d1 == d2))
  5768. {
  5769. directories.remove (i);
  5770. break;
  5771. }
  5772. }
  5773. }
  5774. }
  5775. void FileSearchPath::removeNonExistentPaths()
  5776. {
  5777. for (int i = directories.size(); --i >= 0;)
  5778. if (! File (directories[i]).isDirectory())
  5779. directories.remove (i);
  5780. }
  5781. int FileSearchPath::findChildFiles (Array<File>& results,
  5782. const int whatToLookFor,
  5783. const bool searchRecursively,
  5784. const String& wildCardPattern) const
  5785. {
  5786. int total = 0;
  5787. for (int i = 0; i < directories.size(); ++i)
  5788. total += operator[] (i).findChildFiles (results,
  5789. whatToLookFor,
  5790. searchRecursively,
  5791. wildCardPattern);
  5792. return total;
  5793. }
  5794. bool FileSearchPath::isFileInPath (const File& fileToCheck,
  5795. const bool checkRecursively) const
  5796. {
  5797. for (int i = directories.size(); --i >= 0;)
  5798. {
  5799. const File d (directories[i]);
  5800. if (checkRecursively)
  5801. {
  5802. if (fileToCheck.isAChildOf (d))
  5803. return true;
  5804. }
  5805. else
  5806. {
  5807. if (fileToCheck.getParentDirectory() == d)
  5808. return true;
  5809. }
  5810. }
  5811. return false;
  5812. }
  5813. END_JUCE_NAMESPACE
  5814. /*** End of inlined file: juce_FileSearchPath.cpp ***/
  5815. /*** Start of inlined file: juce_NamedPipe.cpp ***/
  5816. BEGIN_JUCE_NAMESPACE
  5817. NamedPipe::NamedPipe()
  5818. : internal (0)
  5819. {
  5820. }
  5821. NamedPipe::~NamedPipe()
  5822. {
  5823. close();
  5824. }
  5825. bool NamedPipe::openExisting (const String& pipeName)
  5826. {
  5827. currentPipeName = pipeName;
  5828. return openInternal (pipeName, false);
  5829. }
  5830. bool NamedPipe::createNewPipe (const String& pipeName)
  5831. {
  5832. currentPipeName = pipeName;
  5833. return openInternal (pipeName, true);
  5834. }
  5835. bool NamedPipe::isOpen() const
  5836. {
  5837. return internal != 0;
  5838. }
  5839. const String NamedPipe::getName() const
  5840. {
  5841. return currentPipeName;
  5842. }
  5843. // other methods for this class are implemented in the platform-specific files
  5844. END_JUCE_NAMESPACE
  5845. /*** End of inlined file: juce_NamedPipe.cpp ***/
  5846. /*** Start of inlined file: juce_TemporaryFile.cpp ***/
  5847. BEGIN_JUCE_NAMESPACE
  5848. TemporaryFile::TemporaryFile (const String& suffix, const int optionFlags)
  5849. {
  5850. createTempFile (File::getSpecialLocation (File::tempDirectory),
  5851. T("temp_") + String (Random::getSystemRandom().nextInt()),
  5852. suffix,
  5853. optionFlags);
  5854. }
  5855. TemporaryFile::TemporaryFile (const File& targetFile_, const int optionFlags)
  5856. : targetFile (targetFile_)
  5857. {
  5858. // If you use this constructor, you need to give it a valid target file!
  5859. jassert (targetFile != File::nonexistent);
  5860. createTempFile (targetFile.getParentDirectory(),
  5861. targetFile.getFileNameWithoutExtension() + T("_temp") + String (Random::getSystemRandom().nextInt()),
  5862. targetFile.getFileExtension(),
  5863. optionFlags);
  5864. }
  5865. void TemporaryFile::createTempFile (const File& parentDirectory, String name,
  5866. const String& suffix, const int optionFlags)
  5867. {
  5868. if ((optionFlags & useHiddenFile) != 0)
  5869. name = T(".") + name;
  5870. temporaryFile = parentDirectory.getNonexistentChildFile (name, suffix, (optionFlags & putNumbersInBrackets) != 0);
  5871. }
  5872. TemporaryFile::~TemporaryFile()
  5873. {
  5874. // Have a few attempts at deleting the file before giving up..
  5875. for (int i = 5; --i >= 0;)
  5876. {
  5877. if (temporaryFile.deleteFile())
  5878. return;
  5879. Thread::sleep (50);
  5880. }
  5881. // Failed to delete our temporary file! Check that you've deleted all the
  5882. // file output streams that were using it!
  5883. jassertfalse;
  5884. }
  5885. bool TemporaryFile::overwriteTargetFileWithTemporary() const
  5886. {
  5887. // This method only works if you created this object with the constructor
  5888. // that takes a target file!
  5889. jassert (targetFile != File::nonexistent);
  5890. if (temporaryFile.exists())
  5891. {
  5892. // Have a few attempts at overwriting the file before giving up..
  5893. for (int i = 5; --i >= 0;)
  5894. {
  5895. if (temporaryFile.moveFileTo (targetFile))
  5896. return true;
  5897. Thread::sleep (100);
  5898. }
  5899. // Failed to overwrite the new file! Make sure you've not left any
  5900. // file streams hanging around when you call this method!
  5901. jassertfalse
  5902. }
  5903. else
  5904. {
  5905. // There's no temporary file to use. If your write failed, you should
  5906. // probably check, and not bother calling this method.
  5907. jassertfalse
  5908. }
  5909. return false;
  5910. }
  5911. END_JUCE_NAMESPACE
  5912. /*** End of inlined file: juce_TemporaryFile.cpp ***/
  5913. /*** Start of inlined file: juce_Socket.cpp ***/
  5914. #if JUCE_WINDOWS
  5915. #include <winsock2.h>
  5916. #ifdef _MSC_VER
  5917. #pragma warning (disable : 4127 4389 4018)
  5918. #endif
  5919. #else
  5920. #if JUCE_LINUX
  5921. #include <sys/types.h>
  5922. #include <sys/socket.h>
  5923. #include <sys/errno.h>
  5924. #include <unistd.h>
  5925. #include <netinet/in.h>
  5926. #elif (MACOSX_DEPLOYMENT_TARGET <= MAC_OS_X_VERSION_10_4) && ! JUCE_IPHONE
  5927. #include <CoreServices/CoreServices.h>
  5928. #endif
  5929. #include <fcntl.h>
  5930. #include <netdb.h>
  5931. #include <arpa/inet.h>
  5932. #include <netinet/tcp.h>
  5933. #endif
  5934. BEGIN_JUCE_NAMESPACE
  5935. #if defined (JUCE_LINUX) || defined (JUCE_MAC) || defined (JUCE_IPHONE)
  5936. typedef socklen_t juce_socklen_t;
  5937. #else
  5938. typedef int juce_socklen_t;
  5939. #endif
  5940. #if JUCE_WINDOWS
  5941. typedef int (__stdcall juce_CloseWin32SocketLibCall) (void);
  5942. juce_CloseWin32SocketLibCall* juce_CloseWin32SocketLib = 0;
  5943. static void initWin32Sockets()
  5944. {
  5945. static CriticalSection lock;
  5946. const ScopedLock sl (lock);
  5947. if (juce_CloseWin32SocketLib == 0)
  5948. {
  5949. WSADATA wsaData;
  5950. const WORD wVersionRequested = MAKEWORD (1, 1);
  5951. WSAStartup (wVersionRequested, &wsaData);
  5952. juce_CloseWin32SocketLib = &WSACleanup;
  5953. }
  5954. }
  5955. #endif
  5956. static bool resetSocketOptions (const int handle, const bool isDatagram, const bool allowBroadcast) throw()
  5957. {
  5958. const int sndBufSize = 65536;
  5959. const int rcvBufSize = 65536;
  5960. const int one = 1;
  5961. return handle > 0
  5962. && setsockopt (handle, SOL_SOCKET, SO_RCVBUF, (const char*) &rcvBufSize, sizeof (rcvBufSize)) == 0
  5963. && setsockopt (handle, SOL_SOCKET, SO_SNDBUF, (const char*) &sndBufSize, sizeof (sndBufSize)) == 0
  5964. && (isDatagram ? ((! allowBroadcast) || setsockopt (handle, SOL_SOCKET, SO_BROADCAST, (const char*) &one, sizeof (one)) == 0)
  5965. : (setsockopt (handle, IPPROTO_TCP, TCP_NODELAY, (const char*) &one, sizeof (one)) == 0));
  5966. }
  5967. static bool bindSocketToPort (const int handle, const int port) throw()
  5968. {
  5969. if (handle <= 0 || port <= 0)
  5970. return false;
  5971. struct sockaddr_in servTmpAddr;
  5972. zerostruct (servTmpAddr);
  5973. servTmpAddr.sin_family = PF_INET;
  5974. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  5975. servTmpAddr.sin_port = htons ((uint16) port);
  5976. return bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) >= 0;
  5977. }
  5978. static int readSocket (const int handle,
  5979. void* const destBuffer, const int maxBytesToRead,
  5980. bool volatile& connected,
  5981. const bool blockUntilSpecifiedAmountHasArrived) throw()
  5982. {
  5983. int bytesRead = 0;
  5984. while (bytesRead < maxBytesToRead)
  5985. {
  5986. int bytesThisTime;
  5987. #if JUCE_WINDOWS
  5988. bytesThisTime = recv (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead, 0);
  5989. #else
  5990. while ((bytesThisTime = (int) ::read (handle, ((char*) destBuffer) + bytesRead, maxBytesToRead - bytesRead)) < 0
  5991. && errno == EINTR
  5992. && connected)
  5993. {
  5994. }
  5995. #endif
  5996. if (bytesThisTime <= 0 || ! connected)
  5997. {
  5998. if (bytesRead == 0)
  5999. bytesRead = -1;
  6000. break;
  6001. }
  6002. bytesRead += bytesThisTime;
  6003. if (! blockUntilSpecifiedAmountHasArrived)
  6004. break;
  6005. }
  6006. return bytesRead;
  6007. }
  6008. static int waitForReadiness (const int handle, const bool forReading,
  6009. const int timeoutMsecs) throw()
  6010. {
  6011. struct timeval timeout;
  6012. struct timeval* timeoutp;
  6013. if (timeoutMsecs >= 0)
  6014. {
  6015. timeout.tv_sec = timeoutMsecs / 1000;
  6016. timeout.tv_usec = (timeoutMsecs % 1000) * 1000;
  6017. timeoutp = &timeout;
  6018. }
  6019. else
  6020. {
  6021. timeoutp = 0;
  6022. }
  6023. fd_set rset, wset;
  6024. FD_ZERO (&rset);
  6025. FD_SET (handle, &rset);
  6026. FD_ZERO (&wset);
  6027. FD_SET (handle, &wset);
  6028. fd_set* const prset = forReading ? &rset : 0;
  6029. fd_set* const pwset = forReading ? 0 : &wset;
  6030. #if JUCE_WINDOWS
  6031. if (select (handle + 1, prset, pwset, 0, timeoutp) < 0)
  6032. return -1;
  6033. #else
  6034. {
  6035. int result;
  6036. while ((result = select (handle + 1, prset, pwset, 0, timeoutp)) < 0
  6037. && errno == EINTR)
  6038. {
  6039. }
  6040. if (result < 0)
  6041. return -1;
  6042. }
  6043. #endif
  6044. {
  6045. int opt;
  6046. juce_socklen_t len = sizeof (opt);
  6047. if (getsockopt (handle, SOL_SOCKET, SO_ERROR, (char*) &opt, &len) < 0
  6048. || opt != 0)
  6049. return -1;
  6050. }
  6051. if ((forReading && FD_ISSET (handle, &rset))
  6052. || ((! forReading) && FD_ISSET (handle, &wset)))
  6053. return 1;
  6054. return 0;
  6055. }
  6056. static bool setSocketBlockingState (const int handle, const bool shouldBlock) throw()
  6057. {
  6058. #if JUCE_WINDOWS
  6059. u_long nonBlocking = shouldBlock ? 0 : 1;
  6060. if (ioctlsocket (handle, FIONBIO, &nonBlocking) != 0)
  6061. return false;
  6062. #else
  6063. int socketFlags = fcntl (handle, F_GETFL, 0);
  6064. if (socketFlags == -1)
  6065. return false;
  6066. if (shouldBlock)
  6067. socketFlags &= ~O_NONBLOCK;
  6068. else
  6069. socketFlags |= O_NONBLOCK;
  6070. if (fcntl (handle, F_SETFL, socketFlags) != 0)
  6071. return false;
  6072. #endif
  6073. return true;
  6074. }
  6075. static bool connectSocket (int volatile& handle,
  6076. const bool isDatagram,
  6077. void** serverAddress,
  6078. const String& hostName,
  6079. const int portNumber,
  6080. const int timeOutMillisecs) throw()
  6081. {
  6082. struct hostent* const hostEnt = gethostbyname (hostName.toUTF8());
  6083. if (hostEnt == 0)
  6084. return false;
  6085. struct in_addr targetAddress;
  6086. memcpy (&targetAddress.s_addr,
  6087. *(hostEnt->h_addr_list),
  6088. sizeof (targetAddress.s_addr));
  6089. struct sockaddr_in servTmpAddr;
  6090. zerostruct (servTmpAddr);
  6091. servTmpAddr.sin_family = PF_INET;
  6092. servTmpAddr.sin_addr = targetAddress;
  6093. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6094. if (handle < 0)
  6095. handle = (int) socket (AF_INET, isDatagram ? SOCK_DGRAM : SOCK_STREAM, 0);
  6096. if (handle < 0)
  6097. return false;
  6098. if (isDatagram)
  6099. {
  6100. *serverAddress = new struct sockaddr_in();
  6101. *((struct sockaddr_in*) *serverAddress) = servTmpAddr;
  6102. return true;
  6103. }
  6104. setSocketBlockingState (handle, false);
  6105. const int result = ::connect (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in));
  6106. if (result < 0)
  6107. {
  6108. #if JUCE_WINDOWS
  6109. if (result == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK)
  6110. #else
  6111. if (errno == EINPROGRESS)
  6112. #endif
  6113. {
  6114. if (waitForReadiness (handle, false, timeOutMillisecs) != 1)
  6115. {
  6116. setSocketBlockingState (handle, true);
  6117. return false;
  6118. }
  6119. }
  6120. }
  6121. setSocketBlockingState (handle, true);
  6122. resetSocketOptions (handle, false, false);
  6123. return true;
  6124. }
  6125. StreamingSocket::StreamingSocket()
  6126. : portNumber (0),
  6127. handle (-1),
  6128. connected (false),
  6129. isListener (false)
  6130. {
  6131. #if JUCE_WINDOWS
  6132. initWin32Sockets();
  6133. #endif
  6134. }
  6135. StreamingSocket::StreamingSocket (const String& hostName_,
  6136. const int portNumber_,
  6137. const int handle_)
  6138. : hostName (hostName_),
  6139. portNumber (portNumber_),
  6140. handle (handle_),
  6141. connected (true),
  6142. isListener (false)
  6143. {
  6144. #if JUCE_WINDOWS
  6145. initWin32Sockets();
  6146. #endif
  6147. resetSocketOptions (handle_, false, false);
  6148. }
  6149. StreamingSocket::~StreamingSocket()
  6150. {
  6151. close();
  6152. }
  6153. int StreamingSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6154. {
  6155. return (connected && ! isListener) ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6156. : -1;
  6157. }
  6158. int StreamingSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6159. {
  6160. if (isListener || ! connected)
  6161. return -1;
  6162. #if JUCE_WINDOWS
  6163. return send (handle, (const char*) sourceBuffer, numBytesToWrite, 0);
  6164. #else
  6165. int result;
  6166. while ((result = (int) ::write (handle, sourceBuffer, numBytesToWrite)) < 0
  6167. && errno == EINTR)
  6168. {
  6169. }
  6170. return result;
  6171. #endif
  6172. }
  6173. int StreamingSocket::waitUntilReady (const bool readyForReading,
  6174. const int timeoutMsecs) const
  6175. {
  6176. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6177. : -1;
  6178. }
  6179. bool StreamingSocket::bindToPort (const int port)
  6180. {
  6181. return bindSocketToPort (handle, port);
  6182. }
  6183. bool StreamingSocket::connect (const String& remoteHostName,
  6184. const int remotePortNumber,
  6185. const int timeOutMillisecs)
  6186. {
  6187. if (isListener)
  6188. {
  6189. jassertfalse // a listener socket can't connect to another one!
  6190. return false;
  6191. }
  6192. if (connected)
  6193. close();
  6194. hostName = remoteHostName;
  6195. portNumber = remotePortNumber;
  6196. isListener = false;
  6197. connected = connectSocket (handle, false, 0, remoteHostName,
  6198. remotePortNumber, timeOutMillisecs);
  6199. if (! (connected && resetSocketOptions (handle, false, false)))
  6200. {
  6201. close();
  6202. return false;
  6203. }
  6204. return true;
  6205. }
  6206. void StreamingSocket::close()
  6207. {
  6208. #if JUCE_WINDOWS
  6209. closesocket (handle);
  6210. connected = false;
  6211. #else
  6212. if (connected)
  6213. {
  6214. connected = false;
  6215. if (isListener)
  6216. {
  6217. // need to do this to interrupt the accept() function..
  6218. StreamingSocket temp;
  6219. temp.connect ("localhost", portNumber, 1000);
  6220. }
  6221. }
  6222. ::close (handle);
  6223. #endif
  6224. hostName = String::empty;
  6225. portNumber = 0;
  6226. handle = -1;
  6227. isListener = false;
  6228. }
  6229. bool StreamingSocket::createListener (const int newPortNumber, const String& localHostName)
  6230. {
  6231. if (connected)
  6232. close();
  6233. hostName = "listener";
  6234. portNumber = newPortNumber;
  6235. isListener = true;
  6236. struct sockaddr_in servTmpAddr;
  6237. zerostruct (servTmpAddr);
  6238. servTmpAddr.sin_family = PF_INET;
  6239. servTmpAddr.sin_addr.s_addr = htonl (INADDR_ANY);
  6240. if (localHostName.isNotEmpty())
  6241. servTmpAddr.sin_addr.s_addr = ::inet_addr (localHostName.toUTF8());
  6242. servTmpAddr.sin_port = htons ((uint16) portNumber);
  6243. handle = (int) socket (AF_INET, SOCK_STREAM, 0);
  6244. if (handle < 0)
  6245. return false;
  6246. const int reuse = 1;
  6247. setsockopt (handle, SOL_SOCKET, SO_REUSEADDR, (const char*) &reuse, sizeof (reuse));
  6248. if (bind (handle, (struct sockaddr*) &servTmpAddr, sizeof (struct sockaddr_in)) < 0
  6249. || listen (handle, SOMAXCONN) < 0)
  6250. {
  6251. close();
  6252. return false;
  6253. }
  6254. connected = true;
  6255. return true;
  6256. }
  6257. StreamingSocket* StreamingSocket::waitForNextConnection() const
  6258. {
  6259. jassert (isListener || ! connected); // to call this method, you first have to use createListener() to
  6260. // prepare this socket as a listener.
  6261. if (connected && isListener)
  6262. {
  6263. struct sockaddr address;
  6264. juce_socklen_t len = sizeof (sockaddr);
  6265. const int newSocket = (int) accept (handle, &address, &len);
  6266. if (newSocket >= 0 && connected)
  6267. return new StreamingSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6268. portNumber, newSocket);
  6269. }
  6270. return 0;
  6271. }
  6272. bool StreamingSocket::isLocal() const throw()
  6273. {
  6274. return hostName == T("127.0.0.1");
  6275. }
  6276. DatagramSocket::DatagramSocket (const int localPortNumber, const bool allowBroadcast_)
  6277. : portNumber (0),
  6278. handle (-1),
  6279. connected (true),
  6280. allowBroadcast (allowBroadcast_),
  6281. serverAddress (0)
  6282. {
  6283. #if JUCE_WINDOWS
  6284. initWin32Sockets();
  6285. #endif
  6286. handle = (int) socket (AF_INET, SOCK_DGRAM, 0);
  6287. bindToPort (localPortNumber);
  6288. }
  6289. DatagramSocket::DatagramSocket (const String& hostName_, const int portNumber_,
  6290. const int handle_, const int localPortNumber)
  6291. : hostName (hostName_),
  6292. portNumber (portNumber_),
  6293. handle (handle_),
  6294. connected (true),
  6295. allowBroadcast (false),
  6296. serverAddress (0)
  6297. {
  6298. #if JUCE_WINDOWS
  6299. initWin32Sockets();
  6300. #endif
  6301. resetSocketOptions (handle_, true, allowBroadcast);
  6302. bindToPort (localPortNumber);
  6303. }
  6304. DatagramSocket::~DatagramSocket()
  6305. {
  6306. close();
  6307. delete ((struct sockaddr_in*) serverAddress);
  6308. serverAddress = 0;
  6309. }
  6310. void DatagramSocket::close()
  6311. {
  6312. #if JUCE_WINDOWS
  6313. closesocket (handle);
  6314. connected = false;
  6315. #else
  6316. connected = false;
  6317. ::close (handle);
  6318. #endif
  6319. hostName = String::empty;
  6320. portNumber = 0;
  6321. handle = -1;
  6322. }
  6323. bool DatagramSocket::bindToPort (const int port)
  6324. {
  6325. return bindSocketToPort (handle, port);
  6326. }
  6327. bool DatagramSocket::connect (const String& remoteHostName,
  6328. const int remotePortNumber,
  6329. const int timeOutMillisecs)
  6330. {
  6331. if (connected)
  6332. close();
  6333. hostName = remoteHostName;
  6334. portNumber = remotePortNumber;
  6335. connected = connectSocket (handle, true, &serverAddress,
  6336. remoteHostName, remotePortNumber,
  6337. timeOutMillisecs);
  6338. if (! (connected && resetSocketOptions (handle, true, allowBroadcast)))
  6339. {
  6340. close();
  6341. return false;
  6342. }
  6343. return true;
  6344. }
  6345. DatagramSocket* DatagramSocket::waitForNextConnection() const
  6346. {
  6347. struct sockaddr address;
  6348. juce_socklen_t len = sizeof (sockaddr);
  6349. while (waitUntilReady (true, -1) == 1)
  6350. {
  6351. char buf[1];
  6352. if (recvfrom (handle, buf, 0, 0, &address, &len) > 0)
  6353. {
  6354. return new DatagramSocket (inet_ntoa (((struct sockaddr_in*) &address)->sin_addr),
  6355. ntohs (((struct sockaddr_in*) &address)->sin_port),
  6356. -1, -1);
  6357. }
  6358. }
  6359. return 0;
  6360. }
  6361. int DatagramSocket::waitUntilReady (const bool readyForReading,
  6362. const int timeoutMsecs) const
  6363. {
  6364. return connected ? waitForReadiness (handle, readyForReading, timeoutMsecs)
  6365. : -1;
  6366. }
  6367. int DatagramSocket::read (void* destBuffer, const int maxBytesToRead, const bool blockUntilSpecifiedAmountHasArrived)
  6368. {
  6369. return connected ? readSocket (handle, destBuffer, maxBytesToRead, connected, blockUntilSpecifiedAmountHasArrived)
  6370. : -1;
  6371. }
  6372. int DatagramSocket::write (const void* sourceBuffer, const int numBytesToWrite)
  6373. {
  6374. // You need to call connect() first to set the server address..
  6375. jassert (serverAddress != 0 && connected);
  6376. return connected ? (int) sendto (handle, (const char*) sourceBuffer,
  6377. numBytesToWrite, 0,
  6378. (const struct sockaddr*) serverAddress,
  6379. sizeof (struct sockaddr_in))
  6380. : -1;
  6381. }
  6382. bool DatagramSocket::isLocal() const throw()
  6383. {
  6384. return hostName == T("127.0.0.1");
  6385. }
  6386. END_JUCE_NAMESPACE
  6387. /*** End of inlined file: juce_Socket.cpp ***/
  6388. /*** Start of inlined file: juce_URL.cpp ***/
  6389. BEGIN_JUCE_NAMESPACE
  6390. URL::URL()
  6391. {
  6392. }
  6393. URL::URL (const String& url_)
  6394. : url (url_)
  6395. {
  6396. int i = url.indexOfChar (T('?'));
  6397. if (i >= 0)
  6398. {
  6399. do
  6400. {
  6401. const int nextAmp = url.indexOfChar (i + 1, T('&'));
  6402. const int equalsPos = url.indexOfChar (i + 1, T('='));
  6403. if (equalsPos > i + 1)
  6404. {
  6405. if (nextAmp < 0)
  6406. {
  6407. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6408. removeEscapeChars (url.substring (equalsPos + 1)));
  6409. }
  6410. else if (nextAmp > 0 && equalsPos < nextAmp)
  6411. {
  6412. parameters.set (removeEscapeChars (url.substring (i + 1, equalsPos)),
  6413. removeEscapeChars (url.substring (equalsPos + 1, nextAmp)));
  6414. }
  6415. }
  6416. i = nextAmp;
  6417. }
  6418. while (i >= 0);
  6419. url = url.upToFirstOccurrenceOf (T("?"), false, false);
  6420. }
  6421. }
  6422. URL::URL (const URL& other)
  6423. : url (other.url),
  6424. postData (other.postData),
  6425. parameters (other.parameters),
  6426. filesToUpload (other.filesToUpload),
  6427. mimeTypes (other.mimeTypes)
  6428. {
  6429. }
  6430. URL& URL::operator= (const URL& other)
  6431. {
  6432. url = other.url;
  6433. postData = other.postData;
  6434. parameters = other.parameters;
  6435. filesToUpload = other.filesToUpload;
  6436. mimeTypes = other.mimeTypes;
  6437. return *this;
  6438. }
  6439. URL::~URL()
  6440. {
  6441. }
  6442. static const String getMangledParameters (const StringPairArray& parameters)
  6443. {
  6444. String p;
  6445. for (int i = 0; i < parameters.size(); ++i)
  6446. {
  6447. if (i > 0)
  6448. p += T("&");
  6449. p << URL::addEscapeChars (parameters.getAllKeys() [i], true)
  6450. << T("=")
  6451. << URL::addEscapeChars (parameters.getAllValues() [i], true);
  6452. }
  6453. return p;
  6454. }
  6455. const String URL::toString (const bool includeGetParameters) const
  6456. {
  6457. if (includeGetParameters && parameters.size() > 0)
  6458. return url + T("?") + getMangledParameters (parameters);
  6459. else
  6460. return url;
  6461. }
  6462. bool URL::isWellFormed() const
  6463. {
  6464. //xxx TODO
  6465. return url.isNotEmpty();
  6466. }
  6467. static int findStartOfDomain (const String& url)
  6468. {
  6469. int i = 0;
  6470. while (CharacterFunctions::isLetterOrDigit (url[i])
  6471. || CharacterFunctions::indexOfChar (T("+-."), url[i], false) >= 0)
  6472. ++i;
  6473. return url[i] == T(':') ? i + 1 : 0;
  6474. }
  6475. const String URL::getDomain() const
  6476. {
  6477. int start = findStartOfDomain (url);
  6478. while (url[start] == T('/'))
  6479. ++start;
  6480. const int end1 = url.indexOfChar (start, T('/'));
  6481. const int end2 = url.indexOfChar (start, T(':'));
  6482. const int end = (end1 < 0 || end2 < 0) ? jmax (end1, end2)
  6483. : jmin (end1, end2);
  6484. return url.substring (start, end);
  6485. }
  6486. const String URL::getSubPath() const
  6487. {
  6488. int start = findStartOfDomain (url);
  6489. while (url[start] == T('/'))
  6490. ++start;
  6491. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6492. return startOfPath <= 0 ? String::empty
  6493. : url.substring (startOfPath);
  6494. }
  6495. const String URL::getScheme() const
  6496. {
  6497. return url.substring (0, findStartOfDomain (url) - 1);
  6498. }
  6499. const URL URL::withNewSubPath (const String& newPath) const
  6500. {
  6501. int start = findStartOfDomain (url);
  6502. while (url[start] == T('/'))
  6503. ++start;
  6504. const int startOfPath = url.indexOfChar (start, T('/')) + 1;
  6505. URL u (*this);
  6506. if (startOfPath > 0)
  6507. u.url = url.substring (0, startOfPath);
  6508. if (! u.url.endsWithChar (T('/')))
  6509. u.url << '/';
  6510. if (newPath.startsWithChar (T('/')))
  6511. u.url << newPath.substring (1);
  6512. else
  6513. u.url << newPath;
  6514. return u;
  6515. }
  6516. bool URL::isProbablyAWebsiteURL (const String& possibleURL)
  6517. {
  6518. if (possibleURL.startsWithIgnoreCase (T("http:"))
  6519. || possibleURL.startsWithIgnoreCase (T("ftp:")))
  6520. return true;
  6521. if (possibleURL.startsWithIgnoreCase (T("file:"))
  6522. || possibleURL.containsChar (T('@'))
  6523. || possibleURL.endsWithChar (T('.'))
  6524. || (! possibleURL.containsChar (T('.'))))
  6525. return false;
  6526. if (possibleURL.startsWithIgnoreCase (T("www."))
  6527. && possibleURL.substring (5).containsChar (T('.')))
  6528. return true;
  6529. const char* commonTLDs[] = { "com", "net", "org", "uk", "de", "fr", "jp" };
  6530. for (int i = 0; i < numElementsInArray (commonTLDs); ++i)
  6531. if ((possibleURL + T("/")).containsIgnoreCase (T(".") + String (commonTLDs[i]) + T("/")))
  6532. return true;
  6533. return false;
  6534. }
  6535. bool URL::isProbablyAnEmailAddress (const String& possibleEmailAddress)
  6536. {
  6537. const int atSign = possibleEmailAddress.indexOfChar (T('@'));
  6538. return atSign > 0
  6539. && possibleEmailAddress.lastIndexOfChar (T('.')) > (atSign + 1)
  6540. && (! possibleEmailAddress.endsWithChar (T('.')));
  6541. }
  6542. void* juce_openInternetFile (const String& url,
  6543. const String& headers,
  6544. const MemoryBlock& optionalPostData,
  6545. const bool isPost,
  6546. URL::OpenStreamProgressCallback* callback,
  6547. void* callbackContext,
  6548. int timeOutMs);
  6549. void juce_closeInternetFile (void* handle);
  6550. int juce_readFromInternetFile (void* handle, void* dest, int bytesToRead);
  6551. int juce_seekInInternetFile (void* handle, int newPosition);
  6552. int64 juce_getInternetFileContentLength (void* handle);
  6553. class WebInputStream : public InputStream
  6554. {
  6555. public:
  6556. WebInputStream (const URL& url,
  6557. const bool isPost_,
  6558. URL::OpenStreamProgressCallback* const progressCallback_,
  6559. void* const progressCallbackContext_,
  6560. const String& extraHeaders,
  6561. int timeOutMs_)
  6562. : position (0),
  6563. finished (false),
  6564. isPost (isPost_),
  6565. progressCallback (progressCallback_),
  6566. progressCallbackContext (progressCallbackContext_),
  6567. timeOutMs (timeOutMs_)
  6568. {
  6569. server = url.toString (! isPost);
  6570. if (isPost_)
  6571. createHeadersAndPostData (url);
  6572. headers += extraHeaders;
  6573. if (! headers.endsWithChar (T('\n')))
  6574. headers << "\r\n";
  6575. handle = juce_openInternetFile (server, headers, postData, isPost,
  6576. progressCallback_, progressCallbackContext_,
  6577. timeOutMs);
  6578. }
  6579. ~WebInputStream()
  6580. {
  6581. juce_closeInternetFile (handle);
  6582. }
  6583. bool isError() const
  6584. {
  6585. return handle == 0;
  6586. }
  6587. int64 getTotalLength()
  6588. {
  6589. return juce_getInternetFileContentLength (handle);
  6590. }
  6591. bool isExhausted()
  6592. {
  6593. return finished;
  6594. }
  6595. int read (void* dest, int bytes)
  6596. {
  6597. if (finished || isError())
  6598. {
  6599. return 0;
  6600. }
  6601. else
  6602. {
  6603. const int bytesRead = juce_readFromInternetFile (handle, dest, bytes);
  6604. position += bytesRead;
  6605. if (bytesRead == 0)
  6606. finished = true;
  6607. return bytesRead;
  6608. }
  6609. }
  6610. int64 getPosition()
  6611. {
  6612. return position;
  6613. }
  6614. bool setPosition (int64 wantedPos)
  6615. {
  6616. if (wantedPos != position)
  6617. {
  6618. finished = false;
  6619. const int actualPos = juce_seekInInternetFile (handle, (int) wantedPos);
  6620. if (actualPos == wantedPos)
  6621. {
  6622. position = wantedPos;
  6623. }
  6624. else
  6625. {
  6626. if (wantedPos < position)
  6627. {
  6628. juce_closeInternetFile (handle);
  6629. position = 0;
  6630. finished = false;
  6631. handle = juce_openInternetFile (server, headers, postData, isPost,
  6632. progressCallback, progressCallbackContext,
  6633. timeOutMs);
  6634. }
  6635. skipNextBytes (wantedPos - position);
  6636. }
  6637. }
  6638. return true;
  6639. }
  6640. juce_UseDebuggingNewOperator
  6641. private:
  6642. String server, headers;
  6643. MemoryBlock postData;
  6644. int64 position;
  6645. bool finished;
  6646. const bool isPost;
  6647. void* handle;
  6648. URL::OpenStreamProgressCallback* const progressCallback;
  6649. void* const progressCallbackContext;
  6650. const int timeOutMs;
  6651. void createHeadersAndPostData (const URL& url)
  6652. {
  6653. if (url.getFilesToUpload().size() > 0)
  6654. {
  6655. // need to upload some files, so do it as multi-part...
  6656. String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
  6657. headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
  6658. appendUTF8ToPostData ("--" + boundary);
  6659. int i;
  6660. for (i = 0; i < url.getParameters().size(); ++i)
  6661. {
  6662. String s;
  6663. s << "\r\nContent-Disposition: form-data; name=\""
  6664. << url.getParameters().getAllKeys() [i]
  6665. << "\"\r\n\r\n"
  6666. << url.getParameters().getAllValues() [i]
  6667. << "\r\n--"
  6668. << boundary;
  6669. appendUTF8ToPostData (s);
  6670. }
  6671. for (i = 0; i < url.getFilesToUpload().size(); ++i)
  6672. {
  6673. const File f (url.getFilesToUpload().getAllValues() [i]);
  6674. const String paramName (url.getFilesToUpload().getAllKeys() [i]);
  6675. String s;
  6676. s << "\r\nContent-Disposition: form-data; name=\""
  6677. << paramName
  6678. << "\"; filename=\""
  6679. << f.getFileName()
  6680. << "\"\r\n";
  6681. const String mimeType (url.getMimeTypesOfUploadFiles()
  6682. .getValue (paramName, String::empty));
  6683. if (mimeType.isNotEmpty())
  6684. s << "Content-Type: " << mimeType << "\r\n";
  6685. s << "Content-Transfer-Encoding: binary\r\n\r\n";
  6686. appendUTF8ToPostData (s);
  6687. f.loadFileAsData (postData);
  6688. s = "\r\n--" + boundary;
  6689. appendUTF8ToPostData (s);
  6690. }
  6691. appendUTF8ToPostData ("--\r\n");
  6692. }
  6693. else
  6694. {
  6695. appendUTF8ToPostData (getMangledParameters (url.getParameters()));
  6696. appendUTF8ToPostData (url.getPostData());
  6697. // just a short text attachment, so use simple url encoding..
  6698. headers = "Content-Type: application/x-www-form-urlencoded\r\nContent-length: "
  6699. + String ((unsigned int) postData.getSize())
  6700. + "\r\n";
  6701. }
  6702. }
  6703. void appendUTF8ToPostData (const String& text)
  6704. {
  6705. postData.append (text.toUTF8(),
  6706. (int) strlen (text.toUTF8()));
  6707. }
  6708. WebInputStream (const WebInputStream&);
  6709. WebInputStream& operator= (const WebInputStream&);
  6710. };
  6711. InputStream* URL::createInputStream (const bool usePostCommand,
  6712. OpenStreamProgressCallback* const progressCallback,
  6713. void* const progressCallbackContext,
  6714. const String& extraHeaders,
  6715. const int timeOutMs) const
  6716. {
  6717. ScopedPointer <WebInputStream> wi (new WebInputStream (*this, usePostCommand,
  6718. progressCallback, progressCallbackContext,
  6719. extraHeaders,
  6720. timeOutMs));
  6721. return wi->isError() ? 0 : wi.release();
  6722. }
  6723. bool URL::readEntireBinaryStream (MemoryBlock& destData,
  6724. const bool usePostCommand) const
  6725. {
  6726. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6727. if (in != 0)
  6728. {
  6729. in->readIntoMemoryBlock (destData, -1);
  6730. return true;
  6731. }
  6732. return false;
  6733. }
  6734. const String URL::readEntireTextStream (const bool usePostCommand) const
  6735. {
  6736. const ScopedPointer <InputStream> in (createInputStream (usePostCommand));
  6737. if (in != 0)
  6738. return in->readEntireStreamAsString();
  6739. return String::empty;
  6740. }
  6741. XmlElement* URL::readEntireXmlStream (const bool usePostCommand) const
  6742. {
  6743. XmlDocument doc (readEntireTextStream (usePostCommand));
  6744. return doc.getDocumentElement();
  6745. }
  6746. const URL URL::withParameter (const String& parameterName,
  6747. const String& parameterValue) const
  6748. {
  6749. URL u (*this);
  6750. u.parameters.set (parameterName, parameterValue);
  6751. return u;
  6752. }
  6753. const URL URL::withFileToUpload (const String& parameterName,
  6754. const File& fileToUpload,
  6755. const String& mimeType) const
  6756. {
  6757. jassert (mimeType.isNotEmpty()); // You need to supply a mime type!
  6758. URL u (*this);
  6759. u.filesToUpload.set (parameterName, fileToUpload.getFullPathName());
  6760. u.mimeTypes.set (parameterName, mimeType);
  6761. return u;
  6762. }
  6763. const URL URL::withPOSTData (const String& postData_) const
  6764. {
  6765. URL u (*this);
  6766. u.postData = postData_;
  6767. return u;
  6768. }
  6769. const StringPairArray& URL::getParameters() const
  6770. {
  6771. return parameters;
  6772. }
  6773. const StringPairArray& URL::getFilesToUpload() const
  6774. {
  6775. return filesToUpload;
  6776. }
  6777. const StringPairArray& URL::getMimeTypesOfUploadFiles() const
  6778. {
  6779. return mimeTypes;
  6780. }
  6781. const String URL::removeEscapeChars (const String& s)
  6782. {
  6783. const int len = s.length();
  6784. HeapBlock <uint8> resultUTF8 (len * 4);
  6785. uint8* r = resultUTF8;
  6786. for (int i = 0; i < len; ++i)
  6787. {
  6788. char c = (char) s[i];
  6789. if (c == 0)
  6790. break;
  6791. if (c == '+')
  6792. {
  6793. c = ' ';
  6794. }
  6795. else if (c == '%')
  6796. {
  6797. c = (char) s.substring (i + 1, i + 3).getHexValue32();
  6798. i += 2;
  6799. }
  6800. *r++ = c;
  6801. }
  6802. return String::fromUTF8 (resultUTF8);
  6803. }
  6804. const String URL::addEscapeChars (const String& s, const bool isParameter)
  6805. {
  6806. String result;
  6807. result.preallocateStorage (s.length() + 8);
  6808. const char* utf8 = s.toUTF8();
  6809. const char* legalChars = isParameter ? "_-.*!'()"
  6810. : "_-$.*!'(),";
  6811. while (*utf8 != 0)
  6812. {
  6813. const char c = *utf8++;
  6814. if (CharacterFunctions::isLetterOrDigit (c)
  6815. || CharacterFunctions::indexOfChar (legalChars, c, false) >= 0)
  6816. {
  6817. result << c;
  6818. }
  6819. else
  6820. {
  6821. const int v = (int) (uint8) c;
  6822. if (v < 0x10)
  6823. result << T("%0");
  6824. else
  6825. result << T('%');
  6826. result << String::toHexString (v);
  6827. }
  6828. }
  6829. return result;
  6830. }
  6831. extern bool juce_launchFile (const String& fileName, const String& parameters);
  6832. bool URL::launchInDefaultBrowser() const
  6833. {
  6834. String u (toString (true));
  6835. if (u.contains (T("@")) && ! u.contains (T(":")))
  6836. u = "mailto:" + u;
  6837. return juce_launchFile (u, String::empty);
  6838. }
  6839. END_JUCE_NAMESPACE
  6840. /*** End of inlined file: juce_URL.cpp ***/
  6841. /*** Start of inlined file: juce_BufferedInputStream.cpp ***/
  6842. BEGIN_JUCE_NAMESPACE
  6843. BufferedInputStream::BufferedInputStream (InputStream* const source_,
  6844. const int bufferSize_,
  6845. const bool deleteSourceWhenDestroyed)
  6846. : source (source_),
  6847. sourceToDelete (deleteSourceWhenDestroyed ? source_ : 0),
  6848. bufferSize (jmax (256, bufferSize_)),
  6849. position (source_->getPosition()),
  6850. lastReadPos (0),
  6851. bufferOverlap (128)
  6852. {
  6853. const int sourceSize = (int) source_->getTotalLength();
  6854. if (sourceSize >= 0)
  6855. bufferSize = jmin (jmax (32, sourceSize), bufferSize);
  6856. bufferStart = position;
  6857. buffer.malloc (bufferSize);
  6858. }
  6859. BufferedInputStream::~BufferedInputStream()
  6860. {
  6861. }
  6862. int64 BufferedInputStream::getTotalLength()
  6863. {
  6864. return source->getTotalLength();
  6865. }
  6866. int64 BufferedInputStream::getPosition()
  6867. {
  6868. return position;
  6869. }
  6870. bool BufferedInputStream::setPosition (int64 newPosition)
  6871. {
  6872. position = jmax ((int64) 0, newPosition);
  6873. return true;
  6874. }
  6875. bool BufferedInputStream::isExhausted()
  6876. {
  6877. return (position >= lastReadPos)
  6878. && source->isExhausted();
  6879. }
  6880. void BufferedInputStream::ensureBuffered()
  6881. {
  6882. const int64 bufferEndOverlap = lastReadPos - bufferOverlap;
  6883. if (position < bufferStart || position >= bufferEndOverlap)
  6884. {
  6885. int bytesRead;
  6886. if (position < lastReadPos
  6887. && position >= bufferEndOverlap
  6888. && position >= bufferStart)
  6889. {
  6890. const int bytesToKeep = (int) (lastReadPos - position);
  6891. memmove (buffer, buffer + (int) (position - bufferStart), bytesToKeep);
  6892. bufferStart = position;
  6893. bytesRead = source->read (buffer + bytesToKeep,
  6894. bufferSize - bytesToKeep);
  6895. lastReadPos += bytesRead;
  6896. bytesRead += bytesToKeep;
  6897. }
  6898. else
  6899. {
  6900. bufferStart = position;
  6901. source->setPosition (bufferStart);
  6902. bytesRead = source->read (buffer, bufferSize);
  6903. lastReadPos = bufferStart + bytesRead;
  6904. }
  6905. while (bytesRead < bufferSize)
  6906. buffer [bytesRead++] = 0;
  6907. }
  6908. }
  6909. int BufferedInputStream::read (void* destBuffer, int maxBytesToRead)
  6910. {
  6911. if (position >= bufferStart
  6912. && position + maxBytesToRead <= lastReadPos)
  6913. {
  6914. memcpy (destBuffer, buffer + (int) (position - bufferStart), maxBytesToRead);
  6915. position += maxBytesToRead;
  6916. return maxBytesToRead;
  6917. }
  6918. else
  6919. {
  6920. if (position < bufferStart || position >= lastReadPos)
  6921. ensureBuffered();
  6922. int bytesRead = 0;
  6923. while (maxBytesToRead > 0)
  6924. {
  6925. const int bytesAvailable = jmin (maxBytesToRead, (int) (lastReadPos - position));
  6926. if (bytesAvailable > 0)
  6927. {
  6928. memcpy (destBuffer, buffer + (int) (position - bufferStart), bytesAvailable);
  6929. maxBytesToRead -= bytesAvailable;
  6930. bytesRead += bytesAvailable;
  6931. position += bytesAvailable;
  6932. destBuffer = (void*) (((char*) destBuffer) + bytesAvailable);
  6933. }
  6934. const int64 oldLastReadPos = lastReadPos;
  6935. ensureBuffered();
  6936. if (oldLastReadPos == lastReadPos)
  6937. break; // if ensureBuffered() failed to read any more data, bail out
  6938. if (isExhausted())
  6939. break;
  6940. }
  6941. return bytesRead;
  6942. }
  6943. }
  6944. const String BufferedInputStream::readString()
  6945. {
  6946. if (position >= bufferStart
  6947. && position < lastReadPos)
  6948. {
  6949. const int maxChars = (int) (lastReadPos - position);
  6950. const char* const src = buffer + (int) (position - bufferStart);
  6951. for (int i = 0; i < maxChars; ++i)
  6952. {
  6953. if (src[i] == 0)
  6954. {
  6955. position += i + 1;
  6956. return String::fromUTF8 (src, i);
  6957. }
  6958. }
  6959. }
  6960. return InputStream::readString();
  6961. }
  6962. END_JUCE_NAMESPACE
  6963. /*** End of inlined file: juce_BufferedInputStream.cpp ***/
  6964. /*** Start of inlined file: juce_FileInputSource.cpp ***/
  6965. BEGIN_JUCE_NAMESPACE
  6966. FileInputSource::FileInputSource (const File& file_)
  6967. : file (file_)
  6968. {
  6969. }
  6970. FileInputSource::~FileInputSource()
  6971. {
  6972. }
  6973. InputStream* FileInputSource::createInputStream()
  6974. {
  6975. return file.createInputStream();
  6976. }
  6977. InputStream* FileInputSource::createInputStreamFor (const String& relatedItemPath)
  6978. {
  6979. return file.getSiblingFile (relatedItemPath).createInputStream();
  6980. }
  6981. int64 FileInputSource::hashCode() const
  6982. {
  6983. return file.hashCode();
  6984. }
  6985. END_JUCE_NAMESPACE
  6986. /*** End of inlined file: juce_FileInputSource.cpp ***/
  6987. /*** Start of inlined file: juce_MemoryInputStream.cpp ***/
  6988. BEGIN_JUCE_NAMESPACE
  6989. MemoryInputStream::MemoryInputStream (const void* const sourceData,
  6990. const size_t sourceDataSize,
  6991. const bool keepInternalCopy)
  6992. : data ((const char*) sourceData),
  6993. dataSize (sourceDataSize),
  6994. position (0)
  6995. {
  6996. if (keepInternalCopy)
  6997. {
  6998. internalCopy.append (data, sourceDataSize);
  6999. data = (const char*) internalCopy.getData();
  7000. }
  7001. }
  7002. MemoryInputStream::~MemoryInputStream()
  7003. {
  7004. }
  7005. int64 MemoryInputStream::getTotalLength()
  7006. {
  7007. return dataSize;
  7008. }
  7009. int MemoryInputStream::read (void* buffer, int howMany)
  7010. {
  7011. jassert (howMany >= 0);
  7012. const int num = jmin (howMany, (int) (dataSize - position));
  7013. memcpy (buffer, data + position, num);
  7014. position += num;
  7015. return (int) num;
  7016. }
  7017. bool MemoryInputStream::isExhausted()
  7018. {
  7019. return (position >= dataSize);
  7020. }
  7021. bool MemoryInputStream::setPosition (int64 pos)
  7022. {
  7023. position = (int) jlimit ((int64) 0, (int64) dataSize, pos);
  7024. return true;
  7025. }
  7026. int64 MemoryInputStream::getPosition()
  7027. {
  7028. return position;
  7029. }
  7030. END_JUCE_NAMESPACE
  7031. /*** End of inlined file: juce_MemoryInputStream.cpp ***/
  7032. /*** Start of inlined file: juce_MemoryOutputStream.cpp ***/
  7033. BEGIN_JUCE_NAMESPACE
  7034. MemoryOutputStream::MemoryOutputStream (const size_t initialSize,
  7035. const size_t blockSizeToIncreaseBy,
  7036. MemoryBlock* const memoryBlockToWriteTo) throw()
  7037. : data (memoryBlockToWriteTo),
  7038. position (0),
  7039. size (0),
  7040. blockSize (jmax ((size_t) 16, blockSizeToIncreaseBy))
  7041. {
  7042. if (data == 0)
  7043. dataToDelete = data = new MemoryBlock (initialSize);
  7044. else
  7045. data->setSize (initialSize, false);
  7046. }
  7047. MemoryOutputStream::~MemoryOutputStream() throw()
  7048. {
  7049. flush();
  7050. }
  7051. void MemoryOutputStream::flush()
  7052. {
  7053. if (dataToDelete == 0)
  7054. data->setSize (size, false);
  7055. }
  7056. void MemoryOutputStream::reset() throw()
  7057. {
  7058. position = 0;
  7059. size = 0;
  7060. }
  7061. bool MemoryOutputStream::write (const void* buffer, int howMany)
  7062. {
  7063. if (howMany > 0)
  7064. {
  7065. size_t storageNeeded = position + howMany;
  7066. if (storageNeeded >= data->getSize())
  7067. {
  7068. // if we need more space, increase the block by at least 10%..
  7069. storageNeeded += jmax (blockSize, storageNeeded / 10);
  7070. storageNeeded = storageNeeded - (storageNeeded % blockSize) + blockSize;
  7071. data->ensureSize (storageNeeded);
  7072. }
  7073. data->copyFrom (buffer, (int) position, howMany);
  7074. position += howMany;
  7075. size = jmax (size, position);
  7076. }
  7077. return true;
  7078. }
  7079. const char* MemoryOutputStream::getData() const throw()
  7080. {
  7081. if (data->getSize() > size)
  7082. ((char*) data->getData()) [size] = 0;
  7083. return (const char*) data->getData();
  7084. }
  7085. size_t MemoryOutputStream::getDataSize() const throw()
  7086. {
  7087. return size;
  7088. }
  7089. int64 MemoryOutputStream::getPosition()
  7090. {
  7091. return position;
  7092. }
  7093. bool MemoryOutputStream::setPosition (int64 newPosition)
  7094. {
  7095. if (newPosition <= (int64) size)
  7096. {
  7097. // ok to seek backwards
  7098. position = jlimit ((size_t) 0, size, (size_t) newPosition);
  7099. return true;
  7100. }
  7101. else
  7102. {
  7103. // trying to make it bigger isn't a good thing to do..
  7104. return false;
  7105. }
  7106. }
  7107. END_JUCE_NAMESPACE
  7108. /*** End of inlined file: juce_MemoryOutputStream.cpp ***/
  7109. /*** Start of inlined file: juce_SubregionStream.cpp ***/
  7110. BEGIN_JUCE_NAMESPACE
  7111. SubregionStream::SubregionStream (InputStream* const sourceStream,
  7112. const int64 startPositionInSourceStream_,
  7113. const int64 lengthOfSourceStream_,
  7114. const bool deleteSourceWhenDestroyed) throw()
  7115. : source (sourceStream),
  7116. startPositionInSourceStream (startPositionInSourceStream_),
  7117. lengthOfSourceStream (lengthOfSourceStream_)
  7118. {
  7119. if (deleteSourceWhenDestroyed)
  7120. sourceToDelete = source;
  7121. setPosition (0);
  7122. }
  7123. SubregionStream::~SubregionStream() throw()
  7124. {
  7125. }
  7126. int64 SubregionStream::getTotalLength()
  7127. {
  7128. const int64 srcLen = source->getTotalLength() - startPositionInSourceStream;
  7129. return (lengthOfSourceStream >= 0) ? jmin (lengthOfSourceStream, srcLen)
  7130. : srcLen;
  7131. }
  7132. int64 SubregionStream::getPosition()
  7133. {
  7134. return source->getPosition() - startPositionInSourceStream;
  7135. }
  7136. bool SubregionStream::setPosition (int64 newPosition)
  7137. {
  7138. return source->setPosition (jmax ((int64) 0, newPosition + startPositionInSourceStream));
  7139. }
  7140. int SubregionStream::read (void* destBuffer, int maxBytesToRead)
  7141. {
  7142. if (lengthOfSourceStream < 0)
  7143. {
  7144. return source->read (destBuffer, maxBytesToRead);
  7145. }
  7146. else
  7147. {
  7148. maxBytesToRead = (int) jmin ((int64) maxBytesToRead, lengthOfSourceStream - getPosition());
  7149. if (maxBytesToRead <= 0)
  7150. return 0;
  7151. return source->read (destBuffer, maxBytesToRead);
  7152. }
  7153. }
  7154. bool SubregionStream::isExhausted()
  7155. {
  7156. if (lengthOfSourceStream >= 0)
  7157. return (getPosition() >= lengthOfSourceStream) || source->isExhausted();
  7158. else
  7159. return source->isExhausted();
  7160. }
  7161. END_JUCE_NAMESPACE
  7162. /*** End of inlined file: juce_SubregionStream.cpp ***/
  7163. /*** Start of inlined file: juce_PerformanceCounter.cpp ***/
  7164. BEGIN_JUCE_NAMESPACE
  7165. PerformanceCounter::PerformanceCounter (const String& name_,
  7166. int runsPerPrintout,
  7167. const File& loggingFile)
  7168. : name (name_),
  7169. numRuns (0),
  7170. runsPerPrint (runsPerPrintout),
  7171. totalTime (0),
  7172. outputFile (loggingFile)
  7173. {
  7174. if (outputFile != File::nonexistent)
  7175. {
  7176. String s ("**** Counter for \"");
  7177. s << name_ << "\" started at: "
  7178. << Time::getCurrentTime().toString (true, true)
  7179. << "\r\n";
  7180. outputFile.appendText (s, false, false);
  7181. }
  7182. }
  7183. PerformanceCounter::~PerformanceCounter()
  7184. {
  7185. printStatistics();
  7186. }
  7187. void PerformanceCounter::start()
  7188. {
  7189. started = Time::getHighResolutionTicks();
  7190. }
  7191. void PerformanceCounter::stop()
  7192. {
  7193. const int64 now = Time::getHighResolutionTicks();
  7194. totalTime += 1000.0 * Time::highResolutionTicksToSeconds (now - started);
  7195. if (++numRuns == runsPerPrint)
  7196. printStatistics();
  7197. }
  7198. void PerformanceCounter::printStatistics()
  7199. {
  7200. if (numRuns > 0)
  7201. {
  7202. String s ("Performance count for \"");
  7203. s << name << "\" - average over " << numRuns << " run(s) = ";
  7204. const int micros = (int) (totalTime * (1000.0 / numRuns));
  7205. if (micros > 10000)
  7206. s << (micros/1000) << " millisecs";
  7207. else
  7208. s << micros << " microsecs";
  7209. s << ", total = " << String (totalTime / 1000, 5) << " seconds";
  7210. Logger::outputDebugString (s);
  7211. s << "\r\n";
  7212. if (outputFile != File::nonexistent)
  7213. outputFile.appendText (s, false, false);
  7214. numRuns = 0;
  7215. totalTime = 0;
  7216. }
  7217. }
  7218. END_JUCE_NAMESPACE
  7219. /*** End of inlined file: juce_PerformanceCounter.cpp ***/
  7220. /*** Start of inlined file: juce_Uuid.cpp ***/
  7221. BEGIN_JUCE_NAMESPACE
  7222. Uuid::Uuid()
  7223. {
  7224. // Mix up any available MAC addresses with some time-based pseudo-random numbers
  7225. // to make it very very unlikely that two UUIDs will ever be the same..
  7226. static int64 macAddresses[2];
  7227. static bool hasCheckedMacAddresses = false;
  7228. if (! hasCheckedMacAddresses)
  7229. {
  7230. hasCheckedMacAddresses = true;
  7231. SystemStats::getMACAddresses (macAddresses, 2);
  7232. }
  7233. value.asInt64[0] = macAddresses[0];
  7234. value.asInt64[1] = macAddresses[1];
  7235. // We'll use both a local RNG that is re-seeded, plus the shared RNG,
  7236. // whose seed will carry over between calls to this method.
  7237. Random r (macAddresses[0] ^ macAddresses[1]
  7238. ^ Random::getSystemRandom().nextInt64());
  7239. for (int i = 4; --i >= 0;)
  7240. {
  7241. r.setSeedRandomly(); // calling this repeatedly improves randomness
  7242. value.asInt[i] ^= r.nextInt();
  7243. value.asInt[i] ^= Random::getSystemRandom().nextInt();
  7244. }
  7245. }
  7246. Uuid::~Uuid() throw()
  7247. {
  7248. }
  7249. Uuid::Uuid (const Uuid& other)
  7250. : value (other.value)
  7251. {
  7252. }
  7253. Uuid& Uuid::operator= (const Uuid& other)
  7254. {
  7255. value = other.value;
  7256. return *this;
  7257. }
  7258. bool Uuid::operator== (const Uuid& other) const
  7259. {
  7260. return memcmp (value.asBytes, other.value.asBytes, 16) == 0;
  7261. }
  7262. bool Uuid::operator!= (const Uuid& other) const
  7263. {
  7264. return ! operator== (other);
  7265. }
  7266. bool Uuid::isNull() const throw()
  7267. {
  7268. return (value.asInt64 [0] == 0) && (value.asInt64 [1] == 0);
  7269. }
  7270. const String Uuid::toString() const
  7271. {
  7272. return String::toHexString (value.asBytes, 16, 0);
  7273. }
  7274. Uuid::Uuid (const String& uuidString)
  7275. {
  7276. operator= (uuidString);
  7277. }
  7278. Uuid& Uuid::operator= (const String& uuidString)
  7279. {
  7280. int destIndex = 0;
  7281. int i = 0;
  7282. for (;;)
  7283. {
  7284. int byte = 0;
  7285. for (int loop = 2; --loop >= 0;)
  7286. {
  7287. byte <<= 4;
  7288. for (;;)
  7289. {
  7290. const tchar c = uuidString [i++];
  7291. if (c >= T('0') && c <= T('9'))
  7292. {
  7293. byte |= c - T('0');
  7294. break;
  7295. }
  7296. else if (c >= T('a') && c <= T('z'))
  7297. {
  7298. byte |= c - (T('a') - 10);
  7299. break;
  7300. }
  7301. else if (c >= T('A') && c <= T('Z'))
  7302. {
  7303. byte |= c - (T('A') - 10);
  7304. break;
  7305. }
  7306. else if (c == 0)
  7307. {
  7308. while (destIndex < 16)
  7309. value.asBytes [destIndex++] = 0;
  7310. return *this;
  7311. }
  7312. }
  7313. }
  7314. value.asBytes [destIndex++] = (uint8) byte;
  7315. }
  7316. }
  7317. Uuid::Uuid (const uint8* const rawData)
  7318. {
  7319. operator= (rawData);
  7320. }
  7321. Uuid& Uuid::operator= (const uint8* const rawData)
  7322. {
  7323. if (rawData != 0)
  7324. memcpy (value.asBytes, rawData, 16);
  7325. else
  7326. zeromem (value.asBytes, 16);
  7327. return *this;
  7328. }
  7329. END_JUCE_NAMESPACE
  7330. /*** End of inlined file: juce_Uuid.cpp ***/
  7331. /*** Start of inlined file: juce_ZipFile.cpp ***/
  7332. BEGIN_JUCE_NAMESPACE
  7333. class ZipFile::ZipEntryInfo
  7334. {
  7335. public:
  7336. ZipFile::ZipEntry entry;
  7337. int streamOffset;
  7338. int compressedSize;
  7339. bool compressed;
  7340. };
  7341. class ZipFile::ZipInputStream : public InputStream
  7342. {
  7343. public:
  7344. ZipInputStream (ZipFile& file_, ZipFile::ZipEntryInfo& zei)
  7345. : file (file_),
  7346. zipEntryInfo (zei),
  7347. pos (0),
  7348. headerSize (0),
  7349. inputStream (0)
  7350. {
  7351. inputStream = file_.inputStream;
  7352. if (file_.inputSource != 0)
  7353. {
  7354. inputStream = file.inputSource->createInputStream();
  7355. }
  7356. else
  7357. {
  7358. #ifdef JUCE_DEBUG
  7359. file_.numOpenStreams++;
  7360. #endif
  7361. }
  7362. char buffer [30];
  7363. if (inputStream != 0
  7364. && inputStream->setPosition (zei.streamOffset)
  7365. && inputStream->read (buffer, 30) == 30
  7366. && ByteOrder::littleEndianInt (buffer) == 0x04034b50)
  7367. {
  7368. headerSize = 30 + ByteOrder::littleEndianShort (buffer + 26)
  7369. + ByteOrder::littleEndianShort (buffer + 28);
  7370. }
  7371. }
  7372. ~ZipInputStream() throw()
  7373. {
  7374. #ifdef JUCE_DEBUG
  7375. if (inputStream != 0 && inputStream == file.inputStream)
  7376. file.numOpenStreams--;
  7377. #endif
  7378. if (inputStream != file.inputStream)
  7379. delete inputStream;
  7380. }
  7381. int64 getTotalLength() throw()
  7382. {
  7383. return zipEntryInfo.compressedSize;
  7384. }
  7385. int read (void* buffer, int howMany) throw()
  7386. {
  7387. if (headerSize <= 0)
  7388. return 0;
  7389. howMany = (int) jmin ((int64) howMany, zipEntryInfo.compressedSize - pos);
  7390. if (inputStream == 0)
  7391. return 0;
  7392. int num;
  7393. if (inputStream == file.inputStream)
  7394. {
  7395. const ScopedLock sl (file.lock);
  7396. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7397. num = inputStream->read (buffer, howMany);
  7398. }
  7399. else
  7400. {
  7401. inputStream->setPosition (pos + zipEntryInfo.streamOffset + headerSize);
  7402. num = inputStream->read (buffer, howMany);
  7403. }
  7404. pos += num;
  7405. return num;
  7406. }
  7407. bool isExhausted() throw()
  7408. {
  7409. return headerSize <= 0 || pos >= zipEntryInfo.compressedSize;
  7410. }
  7411. int64 getPosition() throw()
  7412. {
  7413. return pos;
  7414. }
  7415. bool setPosition (int64 newPos) throw()
  7416. {
  7417. pos = jlimit ((int64) 0, (int64) zipEntryInfo.compressedSize, newPos);
  7418. return true;
  7419. }
  7420. private:
  7421. ZipFile& file;
  7422. ZipEntryInfo zipEntryInfo;
  7423. int64 pos;
  7424. int headerSize;
  7425. InputStream* inputStream;
  7426. ZipInputStream (const ZipInputStream&);
  7427. ZipInputStream& operator= (const ZipInputStream&);
  7428. };
  7429. ZipFile::ZipFile (InputStream* const source_,
  7430. const bool deleteStreamWhenDestroyed) throw()
  7431. : inputStream (source_)
  7432. #ifdef JUCE_DEBUG
  7433. , numOpenStreams (0)
  7434. #endif
  7435. {
  7436. if (deleteStreamWhenDestroyed)
  7437. streamToDelete = inputStream;
  7438. init();
  7439. }
  7440. ZipFile::ZipFile (const File& file)
  7441. : inputStream (0)
  7442. #ifdef JUCE_DEBUG
  7443. , numOpenStreams (0)
  7444. #endif
  7445. {
  7446. inputSource = new FileInputSource (file);
  7447. init();
  7448. }
  7449. ZipFile::ZipFile (InputSource* const inputSource_)
  7450. : inputStream (0),
  7451. inputSource (inputSource_)
  7452. #ifdef JUCE_DEBUG
  7453. , numOpenStreams (0)
  7454. #endif
  7455. {
  7456. init();
  7457. }
  7458. ZipFile::~ZipFile() throw()
  7459. {
  7460. #ifdef JUCE_DEBUG
  7461. entries.clear();
  7462. // If you hit this assertion, it means you've created a stream to read
  7463. // one of the items in the zipfile, but you've forgotten to delete that
  7464. // stream object before deleting the file.. Streams can't be kept open
  7465. // after the file is deleted because they need to share the input
  7466. // stream that the file uses to read itself.
  7467. jassert (numOpenStreams == 0);
  7468. #endif
  7469. }
  7470. int ZipFile::getNumEntries() const throw()
  7471. {
  7472. return entries.size();
  7473. }
  7474. const ZipFile::ZipEntry* ZipFile::getEntry (const int index) const throw()
  7475. {
  7476. ZipEntryInfo* const zei = (ZipEntryInfo*) entries [index];
  7477. return (zei != 0) ? &(zei->entry)
  7478. : 0;
  7479. }
  7480. int ZipFile::getIndexOfFileName (const String& fileName) const throw()
  7481. {
  7482. for (int i = 0; i < entries.size(); ++i)
  7483. if (entries.getUnchecked (i)->entry.filename == fileName)
  7484. return i;
  7485. return -1;
  7486. }
  7487. const ZipFile::ZipEntry* ZipFile::getEntry (const String& fileName) const throw()
  7488. {
  7489. return getEntry (getIndexOfFileName (fileName));
  7490. }
  7491. InputStream* ZipFile::createStreamForEntry (const int index)
  7492. {
  7493. ZipEntryInfo* const zei = entries[index];
  7494. InputStream* stream = 0;
  7495. if (zei != 0)
  7496. {
  7497. stream = new ZipInputStream (*this, *zei);
  7498. if (zei->compressed)
  7499. {
  7500. stream = new GZIPDecompressorInputStream (stream, true, true,
  7501. zei->entry.uncompressedSize);
  7502. // (much faster to unzip in big blocks using a buffer..)
  7503. stream = new BufferedInputStream (stream, 32768, true);
  7504. }
  7505. }
  7506. return stream;
  7507. }
  7508. class ZipFile::ZipFilenameComparator
  7509. {
  7510. public:
  7511. int compareElements (const ZipFile::ZipEntryInfo* first, const ZipFile::ZipEntryInfo* second)
  7512. {
  7513. return first->entry.filename.compare (second->entry.filename);
  7514. }
  7515. };
  7516. void ZipFile::sortEntriesByFilename()
  7517. {
  7518. ZipFilenameComparator sorter;
  7519. entries.sort (sorter);
  7520. }
  7521. void ZipFile::init()
  7522. {
  7523. ScopedPointer <InputStream> toDelete;
  7524. InputStream* in = inputStream;
  7525. if (inputSource != 0)
  7526. {
  7527. in = inputSource->createInputStream();
  7528. toDelete = in;
  7529. }
  7530. if (in != 0)
  7531. {
  7532. int numEntries = 0;
  7533. int pos = findEndOfZipEntryTable (in, numEntries);
  7534. if (pos >= 0 && pos < in->getTotalLength())
  7535. {
  7536. const int size = (int) (in->getTotalLength() - pos);
  7537. in->setPosition (pos);
  7538. MemoryBlock headerData;
  7539. if (in->readIntoMemoryBlock (headerData, size) == size)
  7540. {
  7541. pos = 0;
  7542. for (int i = 0; i < numEntries; ++i)
  7543. {
  7544. if (pos + 46 > size)
  7545. break;
  7546. const char* const buffer = ((const char*) headerData.getData()) + pos;
  7547. const int fileNameLen = ByteOrder::littleEndianShort (buffer + 28);
  7548. if (pos + 46 + fileNameLen > size)
  7549. break;
  7550. ZipEntryInfo* const zei = new ZipEntryInfo();
  7551. zei->entry.filename = String::fromUTF8 (buffer + 46, fileNameLen);
  7552. const int time = ByteOrder::littleEndianShort (buffer + 12);
  7553. const int date = ByteOrder::littleEndianShort (buffer + 14);
  7554. const int year = 1980 + (date >> 9);
  7555. const int month = ((date >> 5) & 15) - 1;
  7556. const int day = date & 31;
  7557. const int hours = time >> 11;
  7558. const int minutes = (time >> 5) & 63;
  7559. const int seconds = (time & 31) << 1;
  7560. zei->entry.fileTime = Time (year, month, day, hours, minutes, seconds);
  7561. zei->compressed = ByteOrder::littleEndianShort (buffer + 10) != 0;
  7562. zei->compressedSize = ByteOrder::littleEndianInt (buffer + 20);
  7563. zei->entry.uncompressedSize = ByteOrder::littleEndianInt (buffer + 24);
  7564. zei->streamOffset = ByteOrder::littleEndianInt (buffer + 42);
  7565. entries.add (zei);
  7566. pos += 46 + fileNameLen
  7567. + ByteOrder::littleEndianShort (buffer + 30)
  7568. + ByteOrder::littleEndianShort (buffer + 32);
  7569. }
  7570. }
  7571. }
  7572. }
  7573. }
  7574. int ZipFile::findEndOfZipEntryTable (InputStream* input, int& numEntries)
  7575. {
  7576. BufferedInputStream in (input, 8192, false);
  7577. in.setPosition (in.getTotalLength());
  7578. int64 pos = in.getPosition();
  7579. const int64 lowestPos = jmax ((int64) 0, pos - 1024);
  7580. char buffer [32];
  7581. zeromem (buffer, sizeof (buffer));
  7582. while (pos > lowestPos)
  7583. {
  7584. in.setPosition (pos - 22);
  7585. pos = in.getPosition();
  7586. memcpy (buffer + 22, buffer, 4);
  7587. if (in.read (buffer, 22) != 22)
  7588. return 0;
  7589. for (int i = 0; i < 22; ++i)
  7590. {
  7591. if (ByteOrder::littleEndianInt (buffer + i) == 0x06054b50)
  7592. {
  7593. in.setPosition (pos + i);
  7594. in.read (buffer, 22);
  7595. numEntries = ByteOrder::littleEndianShort (buffer + 10);
  7596. return ByteOrder::littleEndianInt (buffer + 16);
  7597. }
  7598. }
  7599. }
  7600. return 0;
  7601. }
  7602. void ZipFile::uncompressTo (const File& targetDirectory,
  7603. const bool shouldOverwriteFiles)
  7604. {
  7605. for (int i = 0; i < entries.size(); ++i)
  7606. {
  7607. const ZipEntry& zei = entries.getUnchecked(i)->entry;
  7608. const File targetFile (targetDirectory.getChildFile (zei.filename));
  7609. if (zei.filename.endsWithChar (T('/')))
  7610. {
  7611. targetFile.createDirectory(); // (entry is a directory, not a file)
  7612. }
  7613. else
  7614. {
  7615. ScopedPointer <InputStream> in (createStreamForEntry (i));
  7616. if (in != 0)
  7617. {
  7618. if (shouldOverwriteFiles)
  7619. targetFile.deleteFile();
  7620. if ((! targetFile.exists())
  7621. && targetFile.getParentDirectory().createDirectory())
  7622. {
  7623. ScopedPointer <FileOutputStream> out (targetFile.createOutputStream());
  7624. if (out != 0)
  7625. {
  7626. out->writeFromInputStream (*in, -1);
  7627. out = 0;
  7628. targetFile.setCreationTime (zei.fileTime);
  7629. targetFile.setLastModificationTime (zei.fileTime);
  7630. targetFile.setLastAccessTime (zei.fileTime);
  7631. }
  7632. }
  7633. }
  7634. }
  7635. }
  7636. }
  7637. END_JUCE_NAMESPACE
  7638. /*** End of inlined file: juce_ZipFile.cpp ***/
  7639. /*** Start of inlined file: juce_CharacterFunctions.cpp ***/
  7640. #ifdef _MSC_VER
  7641. #pragma warning (disable: 4514 4996)
  7642. #pragma warning (push)
  7643. #endif
  7644. #include <cwctype>
  7645. #include <cctype>
  7646. #include <ctime>
  7647. #ifdef _MSC_VER
  7648. #pragma warning (pop)
  7649. #endif
  7650. BEGIN_JUCE_NAMESPACE
  7651. int CharacterFunctions::length (const char* const s) throw()
  7652. {
  7653. return (int) strlen (s);
  7654. }
  7655. int CharacterFunctions::length (const juce_wchar* const s) throw()
  7656. {
  7657. return (int) wcslen (s);
  7658. }
  7659. void CharacterFunctions::copy (char* dest, const char* src, const int maxChars) throw()
  7660. {
  7661. strncpy (dest, src, maxChars);
  7662. }
  7663. void CharacterFunctions::copy (juce_wchar* dest, const juce_wchar* src, int maxChars) throw()
  7664. {
  7665. wcsncpy (dest, src, maxChars);
  7666. }
  7667. void CharacterFunctions::copy (juce_wchar* dest, const char* src, const int maxChars) throw()
  7668. {
  7669. mbstowcs (dest, src, maxChars);
  7670. }
  7671. void CharacterFunctions::copy (char* dest, const juce_wchar* src, const int maxChars) throw()
  7672. {
  7673. wcstombs (dest, src, maxChars);
  7674. }
  7675. int CharacterFunctions::bytesRequiredForCopy (const juce_wchar* src) throw()
  7676. {
  7677. return (int) wcstombs (0, src, 0);
  7678. }
  7679. void CharacterFunctions::append (char* dest, const char* src) throw()
  7680. {
  7681. strcat (dest, src);
  7682. }
  7683. void CharacterFunctions::append (juce_wchar* dest, const juce_wchar* src) throw()
  7684. {
  7685. wcscat (dest, src);
  7686. }
  7687. int CharacterFunctions::compare (const char* const s1, const char* const s2) throw()
  7688. {
  7689. return strcmp (s1, s2);
  7690. }
  7691. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2) throw()
  7692. {
  7693. jassert (s1 != 0 && s2 != 0);
  7694. return wcscmp (s1, s2);
  7695. }
  7696. int CharacterFunctions::compare (const char* const s1, const char* const s2, const int maxChars) throw()
  7697. {
  7698. jassert (s1 != 0 && s2 != 0);
  7699. return strncmp (s1, s2, maxChars);
  7700. }
  7701. int CharacterFunctions::compare (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7702. {
  7703. jassert (s1 != 0 && s2 != 0);
  7704. return wcsncmp (s1, s2, maxChars);
  7705. }
  7706. int CharacterFunctions::compare (const juce_wchar* s1, const char* s2) throw()
  7707. {
  7708. jassert (s1 != 0 && s2 != 0);
  7709. for (;;)
  7710. {
  7711. const int diff = (int) (*s1 - (juce_wchar) (unsigned char) *s2);
  7712. if (diff != 0)
  7713. return diff;
  7714. else if (*s1 == 0)
  7715. break;
  7716. ++s1;
  7717. ++s2;
  7718. }
  7719. return 0;
  7720. }
  7721. int CharacterFunctions::compare (const char* s1, const juce_wchar* s2) throw()
  7722. {
  7723. return -compare (s2, s1);
  7724. }
  7725. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2) throw()
  7726. {
  7727. jassert (s1 != 0 && s2 != 0);
  7728. #if JUCE_WIN32
  7729. return stricmp (s1, s2);
  7730. #else
  7731. return strcasecmp (s1, s2);
  7732. #endif
  7733. }
  7734. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2) throw()
  7735. {
  7736. jassert (s1 != 0 && s2 != 0);
  7737. #if JUCE_WIN32
  7738. return _wcsicmp (s1, s2);
  7739. #else
  7740. for (;;)
  7741. {
  7742. if (*s1 != *s2)
  7743. {
  7744. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7745. if (diff != 0)
  7746. return diff < 0 ? -1 : 1;
  7747. }
  7748. else if (*s1 == 0)
  7749. break;
  7750. ++s1;
  7751. ++s2;
  7752. }
  7753. return 0;
  7754. #endif
  7755. }
  7756. int CharacterFunctions::compareIgnoreCase (const char* const s1, const char* const s2, const int maxChars) throw()
  7757. {
  7758. jassert (s1 != 0 && s2 != 0);
  7759. #if JUCE_WIN32
  7760. return strnicmp (s1, s2, maxChars);
  7761. #else
  7762. return strncasecmp (s1, s2, maxChars);
  7763. #endif
  7764. }
  7765. int CharacterFunctions::compareIgnoreCase (const juce_wchar* s1, const juce_wchar* s2, int maxChars) throw()
  7766. {
  7767. jassert (s1 != 0 && s2 != 0);
  7768. #if JUCE_WIN32
  7769. return _wcsnicmp (s1, s2, maxChars);
  7770. #else
  7771. while (--maxChars >= 0)
  7772. {
  7773. if (*s1 != *s2)
  7774. {
  7775. const int diff = toUpperCase (*s1) - toUpperCase (*s2);
  7776. if (diff != 0)
  7777. return diff < 0 ? -1 : 1;
  7778. }
  7779. else if (*s1 == 0)
  7780. break;
  7781. ++s1;
  7782. ++s2;
  7783. }
  7784. return 0;
  7785. #endif
  7786. }
  7787. const char* CharacterFunctions::find (const char* const haystack, const char* const needle) throw()
  7788. {
  7789. return strstr (haystack, needle);
  7790. }
  7791. const juce_wchar* CharacterFunctions::find (const juce_wchar* haystack, const juce_wchar* const needle) throw()
  7792. {
  7793. return wcsstr (haystack, needle);
  7794. }
  7795. int CharacterFunctions::indexOfChar (const char* const haystack, const char needle, const bool ignoreCase) throw()
  7796. {
  7797. if (haystack != 0)
  7798. {
  7799. int i = 0;
  7800. if (ignoreCase)
  7801. {
  7802. const char n1 = toLowerCase (needle);
  7803. const char n2 = toUpperCase (needle);
  7804. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7805. {
  7806. while (haystack[i] != 0)
  7807. {
  7808. if (haystack[i] == n1 || haystack[i] == n2)
  7809. return i;
  7810. ++i;
  7811. }
  7812. return -1;
  7813. }
  7814. jassert (n1 == needle);
  7815. }
  7816. while (haystack[i] != 0)
  7817. {
  7818. if (haystack[i] == needle)
  7819. return i;
  7820. ++i;
  7821. }
  7822. }
  7823. return -1;
  7824. }
  7825. int CharacterFunctions::indexOfChar (const juce_wchar* const haystack, const juce_wchar needle, const bool ignoreCase) throw()
  7826. {
  7827. if (haystack != 0)
  7828. {
  7829. int i = 0;
  7830. if (ignoreCase)
  7831. {
  7832. const juce_wchar n1 = toLowerCase (needle);
  7833. const juce_wchar n2 = toUpperCase (needle);
  7834. if (n1 != n2) // if the char is the same in upper/lower case, fall through to the normal search
  7835. {
  7836. while (haystack[i] != 0)
  7837. {
  7838. if (haystack[i] == n1 || haystack[i] == n2)
  7839. return i;
  7840. ++i;
  7841. }
  7842. return -1;
  7843. }
  7844. jassert (n1 == needle);
  7845. }
  7846. while (haystack[i] != 0)
  7847. {
  7848. if (haystack[i] == needle)
  7849. return i;
  7850. ++i;
  7851. }
  7852. }
  7853. return -1;
  7854. }
  7855. int CharacterFunctions::indexOfCharFast (const char* const haystack, const char needle) throw()
  7856. {
  7857. jassert (haystack != 0);
  7858. int i = 0;
  7859. while (haystack[i] != 0)
  7860. {
  7861. if (haystack[i] == needle)
  7862. return i;
  7863. ++i;
  7864. }
  7865. return -1;
  7866. }
  7867. int CharacterFunctions::indexOfCharFast (const juce_wchar* const haystack, const juce_wchar needle) throw()
  7868. {
  7869. jassert (haystack != 0);
  7870. int i = 0;
  7871. while (haystack[i] != 0)
  7872. {
  7873. if (haystack[i] == needle)
  7874. return i;
  7875. ++i;
  7876. }
  7877. return -1;
  7878. }
  7879. int CharacterFunctions::getIntialSectionContainingOnly (const char* const text, const char* const allowedChars) throw()
  7880. {
  7881. return allowedChars == 0 ? 0 : (int) strspn (text, allowedChars);
  7882. }
  7883. int CharacterFunctions::getIntialSectionContainingOnly (const juce_wchar* const text, const juce_wchar* const allowedChars) throw()
  7884. {
  7885. if (allowedChars == 0)
  7886. return 0;
  7887. int i = 0;
  7888. for (;;)
  7889. {
  7890. if (indexOfCharFast (allowedChars, text[i]) < 0)
  7891. break;
  7892. ++i;
  7893. }
  7894. return i;
  7895. }
  7896. int CharacterFunctions::ftime (char* const dest, const int maxChars, const char* const format, const struct tm* const tm) throw()
  7897. {
  7898. return (int) strftime (dest, maxChars, format, tm);
  7899. }
  7900. int CharacterFunctions::ftime (juce_wchar* const dest, const int maxChars, const juce_wchar* const format, const struct tm* const tm) throw()
  7901. {
  7902. return (int) wcsftime (dest, maxChars, format, tm);
  7903. }
  7904. int CharacterFunctions::getIntValue (const char* const s) throw()
  7905. {
  7906. return atoi (s);
  7907. }
  7908. int CharacterFunctions::getIntValue (const juce_wchar* s) throw()
  7909. {
  7910. #if JUCE_WIN32
  7911. return _wtoi (s);
  7912. #else
  7913. int v = 0;
  7914. while (isWhitespace (*s))
  7915. ++s;
  7916. const bool isNeg = *s == T('-');
  7917. if (isNeg)
  7918. ++s;
  7919. for (;;)
  7920. {
  7921. const wchar_t c = *s++;
  7922. if (c >= T('0') && c <= T('9'))
  7923. v = v * 10 + (int) (c - T('0'));
  7924. else
  7925. break;
  7926. }
  7927. return isNeg ? -v : v;
  7928. #endif
  7929. }
  7930. int64 CharacterFunctions::getInt64Value (const char* s) throw()
  7931. {
  7932. #if JUCE_LINUX
  7933. return atoll (s);
  7934. #elif defined (JUCE_WIN32)
  7935. return _atoi64 (s);
  7936. #else
  7937. int64 v = 0;
  7938. while (isWhitespace (*s))
  7939. ++s;
  7940. const bool isNeg = *s == T('-');
  7941. if (isNeg)
  7942. ++s;
  7943. for (;;)
  7944. {
  7945. const char c = *s++;
  7946. if (c >= '0' && c <= '9')
  7947. v = v * 10 + (int64) (c - '0');
  7948. else
  7949. break;
  7950. }
  7951. return isNeg ? -v : v;
  7952. #endif
  7953. }
  7954. int64 CharacterFunctions::getInt64Value (const juce_wchar* s) throw()
  7955. {
  7956. #if JUCE_WIN32
  7957. return _wtoi64 (s);
  7958. #else
  7959. int64 v = 0;
  7960. while (isWhitespace (*s))
  7961. ++s;
  7962. const bool isNeg = *s == T('-');
  7963. if (isNeg)
  7964. ++s;
  7965. for (;;)
  7966. {
  7967. const juce_wchar c = *s++;
  7968. if (c >= T('0') && c <= T('9'))
  7969. v = v * 10 + (int64) (c - T('0'));
  7970. else
  7971. break;
  7972. }
  7973. return isNeg ? -v : v;
  7974. #endif
  7975. }
  7976. static double juce_mulexp10 (const double value, int exponent) throw()
  7977. {
  7978. if (exponent == 0)
  7979. return value;
  7980. if (value == 0)
  7981. return 0;
  7982. const bool negative = (exponent < 0);
  7983. if (negative)
  7984. exponent = -exponent;
  7985. double result = 1.0, power = 10.0;
  7986. for (int bit = 1; exponent != 0; bit <<= 1)
  7987. {
  7988. if ((exponent & bit) != 0)
  7989. {
  7990. exponent ^= bit;
  7991. result *= power;
  7992. if (exponent == 0)
  7993. break;
  7994. }
  7995. power *= power;
  7996. }
  7997. return negative ? (value / result) : (value * result);
  7998. }
  7999. template <class CharType>
  8000. double juce_atof (const CharType* const original) throw()
  8001. {
  8002. double result[3] = { 0, 0, 0 }, accumulator[2] = { 0, 0 };
  8003. int exponentAdjustment[2] = { 0, 0 }, exponentAccumulator[2] = { -1, -1 };
  8004. int exponent = 0, decPointIndex = 0, digit = 0;
  8005. int lastDigit = 0, numSignificantDigits = 0;
  8006. bool isNegative = false, digitsFound = false;
  8007. const int maxSignificantDigits = 15 + 2;
  8008. const CharType* s = original;
  8009. while (CharacterFunctions::isWhitespace (*s))
  8010. ++s;
  8011. switch (*s)
  8012. {
  8013. case '-': isNegative = true; // fall-through..
  8014. case '+': ++s;
  8015. }
  8016. if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I')
  8017. return atof (String (original).toUTF8()); // Let the c library deal with NAN and INF
  8018. for (;;)
  8019. {
  8020. if (CharacterFunctions::isDigit (*s))
  8021. {
  8022. lastDigit = digit;
  8023. digit = *s++ - '0';
  8024. digitsFound = true;
  8025. if (decPointIndex != 0)
  8026. exponentAdjustment[1]++;
  8027. if (numSignificantDigits == 0 && digit == 0)
  8028. continue;
  8029. if (++numSignificantDigits > maxSignificantDigits)
  8030. {
  8031. if (digit > 5)
  8032. ++accumulator [decPointIndex];
  8033. else if (digit == 5 && (lastDigit & 1) != 0)
  8034. ++accumulator [decPointIndex];
  8035. if (decPointIndex > 0)
  8036. exponentAdjustment[1]--;
  8037. else
  8038. exponentAdjustment[0]++;
  8039. while (CharacterFunctions::isDigit (*s))
  8040. {
  8041. ++s;
  8042. if (decPointIndex == 0)
  8043. exponentAdjustment[0]++;
  8044. }
  8045. }
  8046. else
  8047. {
  8048. const double maxAccumulatorValue = (double) ((std::numeric_limits<unsigned int>::max() - 9) / 10);
  8049. if (accumulator [decPointIndex] > maxAccumulatorValue)
  8050. {
  8051. result [decPointIndex] = juce_mulexp10 (result [decPointIndex], exponentAccumulator [decPointIndex])
  8052. + accumulator [decPointIndex];
  8053. accumulator [decPointIndex] = 0;
  8054. exponentAccumulator [decPointIndex] = 0;
  8055. }
  8056. accumulator [decPointIndex] = accumulator[decPointIndex] * 10 + digit;
  8057. exponentAccumulator [decPointIndex]++;
  8058. }
  8059. }
  8060. else if (decPointIndex == 0 && *s == '.')
  8061. {
  8062. ++s;
  8063. decPointIndex = 1;
  8064. if (numSignificantDigits > maxSignificantDigits)
  8065. {
  8066. while (CharacterFunctions::isDigit (*s))
  8067. ++s;
  8068. break;
  8069. }
  8070. }
  8071. else
  8072. {
  8073. break;
  8074. }
  8075. }
  8076. result[0] = juce_mulexp10 (result[0], exponentAccumulator[0]) + accumulator[0];
  8077. if (decPointIndex != 0)
  8078. result[1] = juce_mulexp10 (result[1], exponentAccumulator[1]) + accumulator[1];
  8079. if ((*s == 'e' || *s == 'E') && digitsFound)
  8080. {
  8081. bool negativeExponent = false;
  8082. switch (*++s)
  8083. {
  8084. case '-': negativeExponent = true; // fall-through..
  8085. case '+': ++s;
  8086. }
  8087. while (CharacterFunctions::isDigit (*s))
  8088. exponent = (exponent * 10) + (*s++ - '0');
  8089. if (negativeExponent)
  8090. exponent = -exponent;
  8091. }
  8092. double r = juce_mulexp10 (result[0], exponent + exponentAdjustment[0]);
  8093. if (decPointIndex != 0)
  8094. r += juce_mulexp10 (result[1], exponent - exponentAdjustment[1]);
  8095. return isNegative ? -r : r;
  8096. }
  8097. double CharacterFunctions::getDoubleValue (const char* const s) throw()
  8098. {
  8099. return juce_atof <char> (s);
  8100. }
  8101. double CharacterFunctions::getDoubleValue (const juce_wchar* const s) throw()
  8102. {
  8103. return juce_atof <juce_wchar> (s);
  8104. }
  8105. char CharacterFunctions::toUpperCase (const char character) throw()
  8106. {
  8107. return (char) toupper (character);
  8108. }
  8109. juce_wchar CharacterFunctions::toUpperCase (const juce_wchar character) throw()
  8110. {
  8111. return towupper (character);
  8112. }
  8113. void CharacterFunctions::toUpperCase (char* s) throw()
  8114. {
  8115. #if JUCE_WIN32
  8116. strupr (s);
  8117. #else
  8118. while (*s != 0)
  8119. {
  8120. *s = toUpperCase (*s);
  8121. ++s;
  8122. }
  8123. #endif
  8124. }
  8125. void CharacterFunctions::toUpperCase (juce_wchar* s) throw()
  8126. {
  8127. #if JUCE_WIN32
  8128. _wcsupr (s);
  8129. #else
  8130. while (*s != 0)
  8131. {
  8132. *s = toUpperCase (*s);
  8133. ++s;
  8134. }
  8135. #endif
  8136. }
  8137. bool CharacterFunctions::isUpperCase (const char character) throw()
  8138. {
  8139. return isupper (character) != 0;
  8140. }
  8141. bool CharacterFunctions::isUpperCase (const juce_wchar character) throw()
  8142. {
  8143. #if JUCE_WIN32
  8144. return iswupper (character) != 0;
  8145. #else
  8146. return toLowerCase (character) != character;
  8147. #endif
  8148. }
  8149. char CharacterFunctions::toLowerCase (const char character) throw()
  8150. {
  8151. return (char) tolower (character);
  8152. }
  8153. juce_wchar CharacterFunctions::toLowerCase (const juce_wchar character) throw()
  8154. {
  8155. return towlower (character);
  8156. }
  8157. void CharacterFunctions::toLowerCase (char* s) throw()
  8158. {
  8159. #if JUCE_WIN32
  8160. strlwr (s);
  8161. #else
  8162. while (*s != 0)
  8163. {
  8164. *s = toLowerCase (*s);
  8165. ++s;
  8166. }
  8167. #endif
  8168. }
  8169. void CharacterFunctions::toLowerCase (juce_wchar* s) throw()
  8170. {
  8171. #if JUCE_WIN32
  8172. _wcslwr (s);
  8173. #else
  8174. while (*s != 0)
  8175. {
  8176. *s = toLowerCase (*s);
  8177. ++s;
  8178. }
  8179. #endif
  8180. }
  8181. bool CharacterFunctions::isLowerCase (const char character) throw()
  8182. {
  8183. return islower (character) != 0;
  8184. }
  8185. bool CharacterFunctions::isLowerCase (const juce_wchar character) throw()
  8186. {
  8187. #if JUCE_WIN32
  8188. return iswlower (character) != 0;
  8189. #else
  8190. return toUpperCase (character) != character;
  8191. #endif
  8192. }
  8193. bool CharacterFunctions::isWhitespace (const char character) throw()
  8194. {
  8195. return character == T(' ') || (character <= 13 && character >= 9);
  8196. }
  8197. bool CharacterFunctions::isWhitespace (const juce_wchar character) throw()
  8198. {
  8199. return iswspace (character) != 0;
  8200. }
  8201. bool CharacterFunctions::isDigit (const char character) throw()
  8202. {
  8203. return (character >= '0' && character <= '9');
  8204. }
  8205. bool CharacterFunctions::isDigit (const juce_wchar character) throw()
  8206. {
  8207. return iswdigit (character) != 0;
  8208. }
  8209. bool CharacterFunctions::isLetter (const char character) throw()
  8210. {
  8211. return (character >= 'a' && character <= 'z')
  8212. || (character >= 'A' && character <= 'Z');
  8213. }
  8214. bool CharacterFunctions::isLetter (const juce_wchar character) throw()
  8215. {
  8216. return iswalpha (character) != 0;
  8217. }
  8218. bool CharacterFunctions::isLetterOrDigit (const char character) throw()
  8219. {
  8220. return (character >= 'a' && character <= 'z')
  8221. || (character >= 'A' && character <= 'Z')
  8222. || (character >= '0' && character <= '9');
  8223. }
  8224. bool CharacterFunctions::isLetterOrDigit (const juce_wchar character) throw()
  8225. {
  8226. return iswalnum (character) != 0;
  8227. }
  8228. int CharacterFunctions::getHexDigitValue (const juce_wchar digit) throw()
  8229. {
  8230. if (digit >= '0' && digit <= '9')
  8231. return digit - '0';
  8232. else if (digit >= 'a' && digit <= 'f')
  8233. return digit - ('a' - 10);
  8234. else if (digit >= 'A' && digit <= 'F')
  8235. return digit - ('A' - 10);
  8236. return -1;
  8237. }
  8238. int CharacterFunctions::printf (char* const dest, const int maxLength, const char* const format, ...) throw()
  8239. {
  8240. va_list list;
  8241. va_start (list, format);
  8242. return vprintf (dest, maxLength, format, list);
  8243. }
  8244. int CharacterFunctions::printf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, ...) throw()
  8245. {
  8246. va_list list;
  8247. va_start (list, format);
  8248. return vprintf (dest, maxLength, format, list);
  8249. }
  8250. int CharacterFunctions::vprintf (char* const dest, const int maxLength, const char* const format, va_list& args) throw()
  8251. {
  8252. #if JUCE_WIN32
  8253. return (int) _vsnprintf (dest, maxLength, format, args);
  8254. #else
  8255. return (int) vsnprintf (dest, maxLength, format, args);
  8256. #endif
  8257. }
  8258. int CharacterFunctions::vprintf (juce_wchar* const dest, const int maxLength, const juce_wchar* const format, va_list& args) throw()
  8259. {
  8260. #if defined (JUCE_WIN32)
  8261. return (int) _vsnwprintf (dest, maxLength, format, args);
  8262. #else
  8263. return (int) vswprintf (dest, maxLength, format, args);
  8264. #endif
  8265. }
  8266. END_JUCE_NAMESPACE
  8267. /*** End of inlined file: juce_CharacterFunctions.cpp ***/
  8268. /*** Start of inlined file: juce_LocalisedStrings.cpp ***/
  8269. BEGIN_JUCE_NAMESPACE
  8270. LocalisedStrings::LocalisedStrings (const String& fileContents)
  8271. {
  8272. loadFromText (fileContents);
  8273. }
  8274. LocalisedStrings::LocalisedStrings (const File& fileToLoad)
  8275. {
  8276. loadFromText (fileToLoad.loadFileAsString());
  8277. }
  8278. LocalisedStrings::~LocalisedStrings()
  8279. {
  8280. }
  8281. const String LocalisedStrings::translate (const String& text) const
  8282. {
  8283. return translations.getValue (text, text);
  8284. }
  8285. static int findCloseQuote (const String& text, int startPos)
  8286. {
  8287. tchar lastChar = 0;
  8288. for (;;)
  8289. {
  8290. const tchar c = text [startPos];
  8291. if (c == 0 || (c == T('"') && lastChar != T('\\')))
  8292. break;
  8293. lastChar = c;
  8294. ++startPos;
  8295. }
  8296. return startPos;
  8297. }
  8298. static const String unescapeString (const String& s)
  8299. {
  8300. return s.replace (T("\\\""), T("\""))
  8301. .replace (T("\\\'"), T("\'"))
  8302. .replace (T("\\t"), T("\t"))
  8303. .replace (T("\\r"), T("\r"))
  8304. .replace (T("\\n"), T("\n"));
  8305. }
  8306. void LocalisedStrings::loadFromText (const String& fileContents)
  8307. {
  8308. StringArray lines;
  8309. lines.addLines (fileContents);
  8310. for (int i = 0; i < lines.size(); ++i)
  8311. {
  8312. String line (lines[i].trim());
  8313. if (line.startsWithChar (T('"')))
  8314. {
  8315. int closeQuote = findCloseQuote (line, 1);
  8316. const String originalText (unescapeString (line.substring (1, closeQuote)));
  8317. if (originalText.isNotEmpty())
  8318. {
  8319. const int openingQuote = findCloseQuote (line, closeQuote + 1);
  8320. closeQuote = findCloseQuote (line, openingQuote + 1);
  8321. const String newText (unescapeString (line.substring (openingQuote + 1, closeQuote)));
  8322. if (newText.isNotEmpty())
  8323. translations.set (originalText, newText);
  8324. }
  8325. }
  8326. else if (line.startsWithIgnoreCase (T("language:")))
  8327. {
  8328. languageName = line.substring (9).trim();
  8329. }
  8330. else if (line.startsWithIgnoreCase (T("countries:")))
  8331. {
  8332. countryCodes.addTokens (line.substring (10).trim(), true);
  8333. countryCodes.trim();
  8334. countryCodes.removeEmptyStrings();
  8335. }
  8336. }
  8337. }
  8338. void LocalisedStrings::setIgnoresCase (const bool shouldIgnoreCase)
  8339. {
  8340. translations.setIgnoresCase (shouldIgnoreCase);
  8341. }
  8342. static CriticalSection currentMappingsLock;
  8343. static LocalisedStrings* currentMappings = 0;
  8344. void LocalisedStrings::setCurrentMappings (LocalisedStrings* newTranslations)
  8345. {
  8346. const ScopedLock sl (currentMappingsLock);
  8347. delete currentMappings;
  8348. currentMappings = newTranslations;
  8349. }
  8350. LocalisedStrings* LocalisedStrings::getCurrentMappings()
  8351. {
  8352. return currentMappings;
  8353. }
  8354. const String LocalisedStrings::translateWithCurrentMappings (const String& text)
  8355. {
  8356. const ScopedLock sl (currentMappingsLock);
  8357. if (currentMappings != 0)
  8358. return currentMappings->translate (text);
  8359. return text;
  8360. }
  8361. const String LocalisedStrings::translateWithCurrentMappings (const char* text)
  8362. {
  8363. return translateWithCurrentMappings (String (text));
  8364. }
  8365. END_JUCE_NAMESPACE
  8366. /*** End of inlined file: juce_LocalisedStrings.cpp ***/
  8367. /*** Start of inlined file: juce_String.cpp ***/
  8368. #ifdef _MSC_VER
  8369. #pragma warning (disable: 4514)
  8370. #pragma warning (push)
  8371. #endif
  8372. #include <locale>
  8373. #if JUCE_MSVC
  8374. #include <float.h>
  8375. #endif
  8376. BEGIN_JUCE_NAMESPACE
  8377. #ifdef _MSC_VER
  8378. #pragma warning (pop)
  8379. #endif
  8380. #if defined (JUCE_STRINGS_ARE_UNICODE) && ! JUCE_STRINGS_ARE_UNICODE
  8381. #error "JUCE_STRINGS_ARE_UNICODE is deprecated! All strings are now unicode by default."
  8382. #endif
  8383. static const char* const emptyCharString = "\0\0\0\0JUCE";
  8384. static const int safeEmptyStringRefCount = 0x3fffffff;
  8385. String::InternalRefCountedStringHolder String::emptyString = { safeEmptyStringRefCount, 0, { 0 } };
  8386. static tchar decimalPoint = T('.');
  8387. void juce_initialiseStrings()
  8388. {
  8389. decimalPoint = String::fromUTF8 (localeconv()->decimal_point) [0];
  8390. }
  8391. void String::createInternal (const int numChars) throw()
  8392. {
  8393. jassert (numChars > 0);
  8394. text = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8395. + numChars * sizeof (tchar));
  8396. text->refCount = 1;
  8397. text->allocatedNumChars = numChars;
  8398. text->text[0] = 0;
  8399. }
  8400. void String::createInternal (const tchar* const t, const tchar* const textEnd) throw()
  8401. {
  8402. jassert (*(textEnd - 1) == 0); // must have a null terminator
  8403. const int numChars = (int) (textEnd - t);
  8404. createInternal (numChars - 1);
  8405. memcpy (text->text, t, numChars * sizeof (tchar));
  8406. }
  8407. void String::appendInternal (const tchar* const newText,
  8408. const int numExtraChars) throw()
  8409. {
  8410. if (numExtraChars > 0)
  8411. {
  8412. const int oldLen = CharacterFunctions::length (text->text);
  8413. const int newTotalLen = oldLen + numExtraChars;
  8414. if (text->refCount > 1)
  8415. {
  8416. // it's in use by other strings as well, so we need to make a private copy before messing with it..
  8417. InternalRefCountedStringHolder* const newTextHolder
  8418. = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8419. + newTotalLen * sizeof (tchar));
  8420. newTextHolder->refCount = 1;
  8421. newTextHolder->allocatedNumChars = newTotalLen;
  8422. memcpy (newTextHolder->text, text->text, oldLen * sizeof (tchar));
  8423. memcpy (newTextHolder->text + oldLen, newText, numExtraChars * sizeof (tchar));
  8424. InternalRefCountedStringHolder* const old = text;
  8425. text = newTextHolder;
  8426. if (Atomic::decrementAndReturn (old->refCount) == 0)
  8427. juce_free (old);
  8428. }
  8429. else
  8430. {
  8431. // no other strings using it, so just expand it if needed..
  8432. if (newTotalLen > text->allocatedNumChars)
  8433. {
  8434. text = (InternalRefCountedStringHolder*)
  8435. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8436. + newTotalLen * sizeof (tchar));
  8437. text->allocatedNumChars = newTotalLen;
  8438. }
  8439. memcpy (text->text + oldLen, newText, numExtraChars * sizeof (tchar));
  8440. }
  8441. text->text [newTotalLen] = 0;
  8442. }
  8443. }
  8444. void String::dupeInternalIfMultiplyReferenced() throw()
  8445. {
  8446. if (text->refCount > 1)
  8447. {
  8448. InternalRefCountedStringHolder* const old = text;
  8449. const int len = old->allocatedNumChars;
  8450. InternalRefCountedStringHolder* const newTextHolder
  8451. = (InternalRefCountedStringHolder*) juce_malloc (sizeof (InternalRefCountedStringHolder)
  8452. + len * sizeof (tchar));
  8453. newTextHolder->refCount = 1;
  8454. newTextHolder->allocatedNumChars = len;
  8455. memcpy (newTextHolder->text, old->text, (len + 1) * sizeof (tchar));
  8456. text = newTextHolder;
  8457. if (Atomic::decrementAndReturn (old->refCount) == 0)
  8458. juce_free (old);
  8459. }
  8460. }
  8461. const String String::empty;
  8462. String::String() throw()
  8463. : text (&emptyString)
  8464. {
  8465. }
  8466. String::String (const String& other) throw()
  8467. : text (other.text)
  8468. {
  8469. Atomic::increment (text->refCount);
  8470. }
  8471. String::String (const int numChars,
  8472. const int /*dummyVariable*/) throw()
  8473. {
  8474. createInternal (numChars);
  8475. }
  8476. String::String (const char* const t) throw()
  8477. {
  8478. if (t != 0 && *t != 0)
  8479. {
  8480. const int len = CharacterFunctions::length (t);
  8481. createInternal (len);
  8482. CharacterFunctions::copy (text->text, t, len + 1);
  8483. }
  8484. else
  8485. {
  8486. text = &emptyString;
  8487. emptyString.refCount = safeEmptyStringRefCount;
  8488. }
  8489. }
  8490. String::String (const juce_wchar* const t) throw()
  8491. {
  8492. if (t != 0 && *t != 0)
  8493. {
  8494. const int len = CharacterFunctions::length (t);
  8495. createInternal (len);
  8496. memcpy (text->text, t, (len + 1) * sizeof (tchar));
  8497. }
  8498. else
  8499. {
  8500. text = &emptyString;
  8501. emptyString.refCount = safeEmptyStringRefCount;
  8502. }
  8503. }
  8504. String::String (const char* const t,
  8505. const size_t maxChars) throw()
  8506. {
  8507. int i;
  8508. for (i = 0; (size_t) i < maxChars; ++i)
  8509. if (t[i] == 0)
  8510. break;
  8511. if (i > 0)
  8512. {
  8513. createInternal (i);
  8514. CharacterFunctions::copy (text->text, t, i);
  8515. text->text [i] = 0;
  8516. }
  8517. else
  8518. {
  8519. text = &emptyString;
  8520. emptyString.refCount = safeEmptyStringRefCount;
  8521. }
  8522. }
  8523. String::String (const juce_wchar* const t,
  8524. const size_t maxChars) throw()
  8525. {
  8526. int i;
  8527. for (i = 0; (size_t) i < maxChars; ++i)
  8528. if (t[i] == 0)
  8529. break;
  8530. if (i > 0)
  8531. {
  8532. createInternal (i);
  8533. memcpy (text->text, t, i * sizeof (tchar));
  8534. text->text [i] = 0;
  8535. }
  8536. else
  8537. {
  8538. text = &emptyString;
  8539. emptyString.refCount = safeEmptyStringRefCount;
  8540. }
  8541. }
  8542. const String String::charToString (const juce_wchar character) throw()
  8543. {
  8544. tchar temp[2];
  8545. temp[0] = character;
  8546. temp[1] = 0;
  8547. return String (temp);
  8548. }
  8549. namespace IntToCharConverters
  8550. {
  8551. // pass in a pointer to the END of a buffer..
  8552. static tchar* int64ToString (tchar* t, const int64 n) throw()
  8553. {
  8554. *--t = 0;
  8555. int64 v = (n >= 0) ? n : -n;
  8556. do
  8557. {
  8558. *--t = (tchar) (T('0') + (int) (v % 10));
  8559. v /= 10;
  8560. } while (v > 0);
  8561. if (n < 0)
  8562. *--t = T('-');
  8563. return t;
  8564. }
  8565. static tchar* uint64ToString (tchar* t, int64 v) throw()
  8566. {
  8567. *--t = 0;
  8568. do
  8569. {
  8570. *--t = (tchar) (T('0') + (int) (v % 10));
  8571. v /= 10;
  8572. } while (v > 0);
  8573. return t;
  8574. }
  8575. static tchar* intToString (tchar* t, const int n) throw()
  8576. {
  8577. if (n == (int) 0x80000000) // (would cause an overflow)
  8578. return int64ToString (t, n);
  8579. *--t = 0;
  8580. int v = abs (n);
  8581. do
  8582. {
  8583. *--t = (tchar) (T('0') + (v % 10));
  8584. v /= 10;
  8585. } while (v > 0);
  8586. if (n < 0)
  8587. *--t = T('-');
  8588. return t;
  8589. }
  8590. static tchar* uintToString (tchar* t, unsigned int v) throw()
  8591. {
  8592. *--t = 0;
  8593. do
  8594. {
  8595. *--t = (tchar) (T('0') + (v % 10));
  8596. v /= 10;
  8597. } while (v > 0);
  8598. return t;
  8599. }
  8600. }
  8601. String::String (const int number) throw()
  8602. {
  8603. tchar buffer [16];
  8604. tchar* const end = buffer + numElementsInArray (buffer);
  8605. createInternal (IntToCharConverters::intToString (end, number), end);
  8606. }
  8607. String::String (const unsigned int number) throw()
  8608. {
  8609. tchar buffer [16];
  8610. tchar* const end = buffer + numElementsInArray (buffer);
  8611. createInternal (IntToCharConverters::uintToString (end, number), end);
  8612. }
  8613. String::String (const short number) throw()
  8614. {
  8615. tchar buffer [16];
  8616. tchar* const end = buffer + numElementsInArray (buffer);
  8617. createInternal (IntToCharConverters::intToString (end, (int) number), end);
  8618. }
  8619. String::String (const unsigned short number) throw()
  8620. {
  8621. tchar buffer [16];
  8622. tchar* const end = buffer + numElementsInArray (buffer);
  8623. createInternal (IntToCharConverters::uintToString (end, (unsigned int) number), end);
  8624. }
  8625. String::String (const int64 number) throw()
  8626. {
  8627. tchar buffer [32];
  8628. tchar* const end = buffer + numElementsInArray (buffer);
  8629. createInternal (IntToCharConverters::int64ToString (end, number), end);
  8630. }
  8631. String::String (const uint64 number) throw()
  8632. {
  8633. tchar buffer [32];
  8634. tchar* const end = buffer + numElementsInArray (buffer);
  8635. createInternal (IntToCharConverters::uint64ToString (end, number), end);
  8636. }
  8637. // a double-to-string routine that actually uses the number of dec. places you asked for
  8638. // without resorting to exponent notation if the number's too big or small (which is what printf does).
  8639. void String::doubleToStringWithDecPlaces (double n, int numDecPlaces) throw()
  8640. {
  8641. const int bufSize = 80;
  8642. tchar buffer [bufSize];
  8643. int len;
  8644. tchar* t;
  8645. if (numDecPlaces > 0 && n > -1.0e20 && n < 1.0e20)
  8646. {
  8647. int64 v = (int64) (pow (10.0, numDecPlaces) * fabs (n) + 0.5);
  8648. t = buffer + bufSize;
  8649. *--t = (tchar) 0;
  8650. while (numDecPlaces >= 0 || v > 0)
  8651. {
  8652. if (numDecPlaces == 0)
  8653. *--t = decimalPoint;
  8654. *--t = (tchar) (T('0') + (v % 10));
  8655. v /= 10;
  8656. --numDecPlaces;
  8657. }
  8658. if (n < 0)
  8659. *--t = T('-');
  8660. len = (int) ((buffer + bufSize) - t);
  8661. }
  8662. else
  8663. {
  8664. len = CharacterFunctions::printf (buffer, bufSize, T("%.9g"), n) + 1;
  8665. t = buffer;
  8666. }
  8667. if (len > 1)
  8668. {
  8669. jassert (len < numElementsInArray (buffer));
  8670. createInternal (len - 1);
  8671. memcpy (text->text, t, len * sizeof (tchar));
  8672. }
  8673. else
  8674. {
  8675. jassert (*t == 0);
  8676. text = &emptyString;
  8677. emptyString.refCount = safeEmptyStringRefCount;
  8678. }
  8679. }
  8680. String::String (const float number,
  8681. const int numberOfDecimalPlaces) throw()
  8682. {
  8683. doubleToStringWithDecPlaces ((double) number,
  8684. numberOfDecimalPlaces);
  8685. }
  8686. String::String (const double number,
  8687. const int numberOfDecimalPlaces) throw()
  8688. {
  8689. doubleToStringWithDecPlaces (number,
  8690. numberOfDecimalPlaces);
  8691. }
  8692. String::~String() throw()
  8693. {
  8694. emptyString.refCount = safeEmptyStringRefCount;
  8695. if (Atomic::decrementAndReturn (text->refCount) == 0)
  8696. juce_free (text);
  8697. }
  8698. void String::preallocateStorage (const size_t numChars) throw()
  8699. {
  8700. if (numChars > (size_t) text->allocatedNumChars)
  8701. {
  8702. dupeInternalIfMultiplyReferenced();
  8703. text = (InternalRefCountedStringHolder*) juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  8704. + numChars * sizeof (tchar));
  8705. text->allocatedNumChars = (int) numChars;
  8706. }
  8707. }
  8708. int String::length() const throw()
  8709. {
  8710. return CharacterFunctions::length (text->text);
  8711. }
  8712. int String::hashCode() const throw()
  8713. {
  8714. const tchar* t = text->text;
  8715. int result = 0;
  8716. while (*t != (tchar) 0)
  8717. result = 31 * result + *t++;
  8718. return result;
  8719. }
  8720. int64 String::hashCode64() const throw()
  8721. {
  8722. const tchar* t = text->text;
  8723. int64 result = 0;
  8724. while (*t != (tchar) 0)
  8725. result = 101 * result + *t++;
  8726. return result;
  8727. }
  8728. String& String::operator= (const String& other) throw()
  8729. {
  8730. if (this != &other)
  8731. {
  8732. InternalRefCountedStringHolder* newText = other.text;
  8733. Atomic::increment (newText->refCount);
  8734. InternalRefCountedStringHolder* oldText
  8735. = (InternalRefCountedStringHolder*) Atomic::swapPointers ((void* volatile*) &text, newText);
  8736. if (Atomic::decrementAndReturn (oldText->refCount) == 0)
  8737. juce_free (oldText);
  8738. }
  8739. return *this;
  8740. }
  8741. bool JUCE_PUBLIC_FUNCTION operator== (const String& string1, const String& string2) throw()
  8742. {
  8743. return string1.compare (string2) == 0;
  8744. }
  8745. bool JUCE_PUBLIC_FUNCTION operator== (const String& string1, const char* string2) throw()
  8746. {
  8747. return string1.compare (string2) == 0;
  8748. }
  8749. bool JUCE_PUBLIC_FUNCTION operator== (const String& string1, const juce_wchar* string2) throw()
  8750. {
  8751. return string1.compare (string2) == 0;
  8752. }
  8753. bool JUCE_PUBLIC_FUNCTION operator!= (const String& string1, const String& string2) throw()
  8754. {
  8755. return string1.compare (string2) != 0;
  8756. }
  8757. bool JUCE_PUBLIC_FUNCTION operator!= (const String& string1, const char* string2) throw()
  8758. {
  8759. return string1.compare (string2) != 0;
  8760. }
  8761. bool JUCE_PUBLIC_FUNCTION operator!= (const String& string1, const juce_wchar* string2) throw()
  8762. {
  8763. return string1.compare (string2) != 0;
  8764. }
  8765. bool JUCE_PUBLIC_FUNCTION operator> (const String& string1, const String& string2) throw()
  8766. {
  8767. return string1.compare (string2) > 0;
  8768. }
  8769. bool JUCE_PUBLIC_FUNCTION operator< (const String& string1, const String& string2) throw()
  8770. {
  8771. return string1.compare (string2) < 0;
  8772. }
  8773. bool JUCE_PUBLIC_FUNCTION operator>= (const String& string1, const String& string2) throw()
  8774. {
  8775. return string1.compare (string2) >= 0;
  8776. }
  8777. bool JUCE_PUBLIC_FUNCTION operator<= (const String& string1, const String& string2) throw()
  8778. {
  8779. return string1.compare (string2) <= 0;
  8780. }
  8781. bool String::equalsIgnoreCase (const tchar* t) const throw()
  8782. {
  8783. return t != 0 ? CharacterFunctions::compareIgnoreCase (text->text, t) == 0
  8784. : isEmpty();
  8785. }
  8786. bool String::equalsIgnoreCase (const String& other) const throw()
  8787. {
  8788. return text == other.text
  8789. || CharacterFunctions::compareIgnoreCase (text->text, other.text->text) == 0;
  8790. }
  8791. int String::compare (const String& other) const throw()
  8792. {
  8793. return (text == other.text) ? 0 : CharacterFunctions::compare (text->text, other.text->text);
  8794. }
  8795. int String::compare (const char* other) const throw()
  8796. {
  8797. return other == 0 ? isEmpty() : CharacterFunctions::compare (text->text, other);
  8798. }
  8799. int String::compare (const juce_wchar* other) const throw()
  8800. {
  8801. return other == 0 ? isEmpty() : CharacterFunctions::compare (text->text, other);
  8802. }
  8803. int String::compareIgnoreCase (const String& other) const throw()
  8804. {
  8805. return (text == other.text) ? 0 : CharacterFunctions::compareIgnoreCase (text->text, other.text->text);
  8806. }
  8807. int String::compareLexicographically (const String& other) const throw()
  8808. {
  8809. const tchar* s1 = text->text;
  8810. while (*s1 != 0 && ! CharacterFunctions::isLetterOrDigit (*s1))
  8811. ++s1;
  8812. const tchar* s2 = other.text->text;
  8813. while (*s2 != 0 && ! CharacterFunctions::isLetterOrDigit (*s2))
  8814. ++s2;
  8815. return CharacterFunctions::compareIgnoreCase (s1, s2);
  8816. }
  8817. String& String::operator+= (const tchar* const t)
  8818. {
  8819. if (t != 0)
  8820. appendInternal (t, CharacterFunctions::length (t));
  8821. return *this;
  8822. }
  8823. String& String::operator+= (const String& other)
  8824. {
  8825. if (isEmpty())
  8826. operator= (other);
  8827. else
  8828. appendInternal (other.text->text, other.length());
  8829. return *this;
  8830. }
  8831. String& String::operator+= (const char ch)
  8832. {
  8833. const tchar asString[] = { (tchar) ch, 0 };
  8834. return operator+= ((const tchar*) asString);
  8835. }
  8836. String& String::operator+= (const juce_wchar ch)
  8837. {
  8838. const tchar asString[] = { (tchar) ch, 0 };
  8839. return operator+= ((const tchar*) asString);
  8840. }
  8841. String& String::operator+= (const int number)
  8842. {
  8843. tchar buffer [16];
  8844. tchar* const end = buffer + numElementsInArray (buffer);
  8845. tchar* const start = IntToCharConverters::intToString (end, number);
  8846. appendInternal (start, end - start);
  8847. return *this;
  8848. }
  8849. String& String::operator+= (const unsigned int number)
  8850. {
  8851. tchar buffer [16];
  8852. tchar* const end = buffer + numElementsInArray (buffer);
  8853. tchar* const start = IntToCharConverters::uintToString (end, number);
  8854. appendInternal (start, end - start);
  8855. return *this;
  8856. }
  8857. void String::append (const tchar* const other, const int howMany)
  8858. {
  8859. if (howMany > 0)
  8860. {
  8861. int i;
  8862. for (i = 0; i < howMany; ++i)
  8863. if (other[i] == 0)
  8864. break;
  8865. appendInternal (other, i);
  8866. }
  8867. }
  8868. const String JUCE_PUBLIC_FUNCTION operator+ (const char* const string1, const String& string2)
  8869. {
  8870. String s (string1);
  8871. return s += string2;
  8872. }
  8873. const String JUCE_PUBLIC_FUNCTION operator+ (const juce_wchar* const string1, const String& string2)
  8874. {
  8875. String s (string1);
  8876. return s += string2;
  8877. }
  8878. const String JUCE_PUBLIC_FUNCTION operator+ (const char string1, const String& string2)
  8879. {
  8880. return String::charToString (string1) + string2;
  8881. }
  8882. const String JUCE_PUBLIC_FUNCTION operator+ (const juce_wchar string1, const String& string2)
  8883. {
  8884. return String::charToString (string1) + string2;
  8885. }
  8886. const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const String& string2)
  8887. {
  8888. return string1 += string2;
  8889. }
  8890. const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const char* const string2)
  8891. {
  8892. return string1 += string2;
  8893. }
  8894. const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const juce_wchar* const string2)
  8895. {
  8896. return string1 += string2;
  8897. }
  8898. const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const char string2)
  8899. {
  8900. return string1 += string2;
  8901. }
  8902. const String JUCE_PUBLIC_FUNCTION operator+ (String string1, const juce_wchar string2)
  8903. {
  8904. return string1 += string2;
  8905. }
  8906. String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const char characterToAppend)
  8907. {
  8908. return string1 += characterToAppend;
  8909. }
  8910. String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const juce_wchar characterToAppend)
  8911. {
  8912. return string1 += characterToAppend;
  8913. }
  8914. String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const char* const string2)
  8915. {
  8916. return string1 += string2;
  8917. }
  8918. String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const juce_wchar* const string2)
  8919. {
  8920. return string1 += string2;
  8921. }
  8922. String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const String& string2)
  8923. {
  8924. return string1 += string2;
  8925. }
  8926. String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const short number)
  8927. {
  8928. return string1 += (int) number;
  8929. }
  8930. String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const int number)
  8931. {
  8932. return string1 += number;
  8933. }
  8934. String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const unsigned int number)
  8935. {
  8936. return string1 += number;
  8937. }
  8938. String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const long number)
  8939. {
  8940. return string1 += (int) number;
  8941. }
  8942. String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const unsigned long number)
  8943. {
  8944. return string1 += (unsigned int) number;
  8945. }
  8946. String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const float number)
  8947. {
  8948. return string1 += String (number);
  8949. }
  8950. String& JUCE_PUBLIC_FUNCTION operator<< (String& string1, const double number)
  8951. {
  8952. return string1 += String (number);
  8953. }
  8954. OutputStream& JUCE_PUBLIC_FUNCTION operator<< (OutputStream& stream, const String& text)
  8955. {
  8956. // (This avoids using toUTF8() to prevent the memory bloat that it would leave behind
  8957. // if lots of large, persistent strings were to be written to streams).
  8958. const int numBytes = text.getNumBytesAsUTF8();
  8959. HeapBlock<char> temp (numBytes + 1);
  8960. text.copyToUTF8 (temp, numBytes + 1);
  8961. stream.write (temp, numBytes);
  8962. return stream;
  8963. }
  8964. int String::indexOfChar (const tchar character) const throw()
  8965. {
  8966. const tchar* t = text->text;
  8967. for (;;)
  8968. {
  8969. if (*t == character)
  8970. return (int) (t - text->text);
  8971. if (*t++ == 0)
  8972. return -1;
  8973. }
  8974. }
  8975. int String::lastIndexOfChar (const tchar character) const throw()
  8976. {
  8977. for (int i = CharacterFunctions::length (text->text); --i >= 0;)
  8978. if (text->text[i] == character)
  8979. return i;
  8980. return -1;
  8981. }
  8982. int String::indexOf (const tchar* const t) const throw()
  8983. {
  8984. const tchar* const r = CharacterFunctions::find (text->text, t);
  8985. return (r == 0) ? -1
  8986. : (int) (r - text->text);
  8987. }
  8988. int String::indexOfChar (const int startIndex,
  8989. const tchar character) const throw()
  8990. {
  8991. if (startIndex >= 0 && startIndex >= CharacterFunctions::length (text->text))
  8992. return -1;
  8993. const tchar* t = text->text + jmax (0, startIndex);
  8994. for (;;)
  8995. {
  8996. if (*t == character)
  8997. return (int) (t - text->text);
  8998. if (*t++ == 0)
  8999. return -1;
  9000. }
  9001. }
  9002. int String::indexOfAnyOf (const tchar* const charactersToLookFor,
  9003. const int startIndex,
  9004. const bool ignoreCase) const throw()
  9005. {
  9006. if (charactersToLookFor == 0
  9007. || (startIndex >= 0 && startIndex >= CharacterFunctions::length (text->text)))
  9008. return -1;
  9009. const tchar* t = text->text + jmax (0, startIndex);
  9010. while (*t != 0)
  9011. {
  9012. if (CharacterFunctions::indexOfChar (charactersToLookFor, *t, ignoreCase) >= 0)
  9013. return (int) (t - text->text);
  9014. ++t;
  9015. }
  9016. return -1;
  9017. }
  9018. int String::indexOf (const int startIndex,
  9019. const tchar* const other) const throw()
  9020. {
  9021. if (other == 0 || startIndex >= CharacterFunctions::length (text->text))
  9022. return -1;
  9023. const tchar* const found = CharacterFunctions::find (text->text + jmax (0, startIndex),
  9024. other);
  9025. return (found == 0) ? -1
  9026. : (int) (found - text->text);
  9027. }
  9028. int String::indexOfIgnoreCase (const tchar* const other) const throw()
  9029. {
  9030. if (other != 0 && *other != 0)
  9031. {
  9032. const int len = CharacterFunctions::length (other);
  9033. const int end = CharacterFunctions::length (text->text) - len;
  9034. for (int i = 0; i <= end; ++i)
  9035. if (CharacterFunctions::compareIgnoreCase (text->text + i, other, len) == 0)
  9036. return i;
  9037. }
  9038. return -1;
  9039. }
  9040. int String::indexOfIgnoreCase (const int startIndex,
  9041. const tchar* const other) const throw()
  9042. {
  9043. if (other != 0 && *other != 0)
  9044. {
  9045. const int len = CharacterFunctions::length (other);
  9046. const int end = length() - len;
  9047. for (int i = jmax (0, startIndex); i <= end; ++i)
  9048. if (CharacterFunctions::compareIgnoreCase (text->text + i, other, len) == 0)
  9049. return i;
  9050. }
  9051. return -1;
  9052. }
  9053. int String::lastIndexOf (const tchar* const other) const throw()
  9054. {
  9055. if (other != 0 && *other != 0)
  9056. {
  9057. const int len = CharacterFunctions::length (other);
  9058. int i = length() - len;
  9059. if (i >= 0)
  9060. {
  9061. const tchar* n = text->text + i;
  9062. while (i >= 0)
  9063. {
  9064. if (CharacterFunctions::compare (n--, other, len) == 0)
  9065. return i;
  9066. --i;
  9067. }
  9068. }
  9069. }
  9070. return -1;
  9071. }
  9072. int String::lastIndexOfIgnoreCase (const tchar* const other) const throw()
  9073. {
  9074. if (other != 0 && *other != 0)
  9075. {
  9076. const int len = CharacterFunctions::length (other);
  9077. int i = length() - len;
  9078. if (i >= 0)
  9079. {
  9080. const tchar* n = text->text + i;
  9081. while (i >= 0)
  9082. {
  9083. if (CharacterFunctions::compareIgnoreCase (n--, other, len) == 0)
  9084. return i;
  9085. --i;
  9086. }
  9087. }
  9088. }
  9089. return -1;
  9090. }
  9091. int String::lastIndexOfAnyOf (const tchar* const charactersToLookFor,
  9092. const bool ignoreCase) const throw()
  9093. {
  9094. for (int i = CharacterFunctions::length (text->text); --i >= 0;)
  9095. if (CharacterFunctions::indexOfChar (charactersToLookFor, text->text [i], ignoreCase) >= 0)
  9096. return i;
  9097. return -1;
  9098. }
  9099. bool String::contains (const tchar* const other) const throw()
  9100. {
  9101. return indexOf (other) >= 0;
  9102. }
  9103. bool String::containsChar (const tchar character) const throw()
  9104. {
  9105. return indexOfChar (character) >= 0;
  9106. }
  9107. bool String::containsIgnoreCase (const tchar* const t) const throw()
  9108. {
  9109. return indexOfIgnoreCase (t) >= 0;
  9110. }
  9111. int String::indexOfWholeWord (const tchar* const word) const throw()
  9112. {
  9113. if (word != 0 && *word != 0)
  9114. {
  9115. const int wordLen = CharacterFunctions::length (word);
  9116. const int end = length() - wordLen;
  9117. const tchar* t = text->text;
  9118. for (int i = 0; i <= end; ++i)
  9119. {
  9120. if (CharacterFunctions::compare (t, word, wordLen) == 0
  9121. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9122. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9123. {
  9124. return i;
  9125. }
  9126. ++t;
  9127. }
  9128. }
  9129. return -1;
  9130. }
  9131. int String::indexOfWholeWordIgnoreCase (const tchar* const word) const throw()
  9132. {
  9133. if (word != 0 && *word != 0)
  9134. {
  9135. const int wordLen = CharacterFunctions::length (word);
  9136. const int end = length() - wordLen;
  9137. const tchar* t = text->text;
  9138. for (int i = 0; i <= end; ++i)
  9139. {
  9140. if (CharacterFunctions::compareIgnoreCase (t, word, wordLen) == 0
  9141. && (i == 0 || ! CharacterFunctions::isLetterOrDigit (* (t - 1)))
  9142. && ! CharacterFunctions::isLetterOrDigit (t [wordLen]))
  9143. {
  9144. return i;
  9145. }
  9146. ++t;
  9147. }
  9148. }
  9149. return -1;
  9150. }
  9151. bool String::containsWholeWord (const tchar* const wordToLookFor) const throw()
  9152. {
  9153. return indexOfWholeWord (wordToLookFor) >= 0;
  9154. }
  9155. bool String::containsWholeWordIgnoreCase (const tchar* const wordToLookFor) const throw()
  9156. {
  9157. return indexOfWholeWordIgnoreCase (wordToLookFor) >= 0;
  9158. }
  9159. static int indexOfMatch (const tchar* const wildcard,
  9160. const tchar* const test,
  9161. const bool ignoreCase) throw()
  9162. {
  9163. int start = 0;
  9164. while (test [start] != 0)
  9165. {
  9166. int i = 0;
  9167. for (;;)
  9168. {
  9169. const tchar wc = wildcard [i];
  9170. const tchar c = test [i + start];
  9171. if (wc == c
  9172. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9173. || (wc == T('?') && c != 0))
  9174. {
  9175. if (wc == 0)
  9176. return start;
  9177. ++i;
  9178. }
  9179. else
  9180. {
  9181. if (wc == T('*') && (wildcard [i + 1] == 0
  9182. || indexOfMatch (wildcard + i + 1,
  9183. test + start + i,
  9184. ignoreCase) >= 0))
  9185. {
  9186. return start;
  9187. }
  9188. break;
  9189. }
  9190. }
  9191. ++start;
  9192. }
  9193. return -1;
  9194. }
  9195. bool String::matchesWildcard (const tchar* wildcard, const bool ignoreCase) const throw()
  9196. {
  9197. int i = 0;
  9198. for (;;)
  9199. {
  9200. const tchar wc = wildcard [i];
  9201. const tchar c = text->text [i];
  9202. if (wc == c
  9203. || (ignoreCase && CharacterFunctions::toLowerCase (wc) == CharacterFunctions::toLowerCase (c))
  9204. || (wc == T('?') && c != 0))
  9205. {
  9206. if (wc == 0)
  9207. return true;
  9208. ++i;
  9209. }
  9210. else
  9211. {
  9212. return wc == T('*') && (wildcard [i + 1] == 0
  9213. || indexOfMatch (wildcard + i + 1,
  9214. text->text + i,
  9215. ignoreCase) >= 0);
  9216. }
  9217. }
  9218. }
  9219. void String::printf (const tchar* const pf, ...) throw()
  9220. {
  9221. va_list list;
  9222. va_start (list, pf);
  9223. vprintf (pf, list);
  9224. }
  9225. const String String::formatted (const tchar* const pf, ...) throw()
  9226. {
  9227. va_list list;
  9228. va_start (list, pf);
  9229. String result;
  9230. result.vprintf (pf, list);
  9231. return result;
  9232. }
  9233. void String::vprintf (const tchar* const pf, va_list& args) throw()
  9234. {
  9235. int bufferSize = 256;
  9236. String result (bufferSize, 0);
  9237. do
  9238. {
  9239. #if JUCE_LINUX && JUCE_64BIT
  9240. va_list tempArgs;
  9241. va_copy (tempArgs, args);
  9242. const int num = CharacterFunctions::vprintf (result.text->text, bufferSize - 1, pf, tempArgs);
  9243. va_end (tempArgs);
  9244. #else
  9245. const int num = CharacterFunctions::vprintf (result.text->text, bufferSize - 1, pf, args);
  9246. #endif
  9247. if (num > 0)
  9248. {
  9249. *this = result;
  9250. break;
  9251. }
  9252. else if (num == 0)
  9253. {
  9254. *this = String::empty;
  9255. break;
  9256. }
  9257. bufferSize += 256;
  9258. result.preallocateStorage (bufferSize);
  9259. }
  9260. while (bufferSize < 65536); // this is a sanity check to avoid situations where vprintf repeatedly
  9261. // returns -1 because of an error rather than because it needs more space.
  9262. }
  9263. const String String::repeatedString (const tchar* const stringToRepeat,
  9264. int numberOfTimesToRepeat) throw()
  9265. {
  9266. const int len = CharacterFunctions::length (stringToRepeat);
  9267. String result ((int) (len * numberOfTimesToRepeat + 1), (int) 0);
  9268. tchar* n = result.text->text;
  9269. n[0] = 0;
  9270. while (--numberOfTimesToRepeat >= 0)
  9271. {
  9272. CharacterFunctions::append (n, stringToRepeat);
  9273. n += len;
  9274. }
  9275. return result;
  9276. }
  9277. const String String::replaceSection (int index,
  9278. int numCharsToReplace,
  9279. const tchar* const stringToInsert) const throw()
  9280. {
  9281. if (index < 0)
  9282. {
  9283. // a negative index to replace from?
  9284. jassertfalse
  9285. index = 0;
  9286. }
  9287. if (numCharsToReplace < 0)
  9288. {
  9289. // replacing a negative number of characters?
  9290. numCharsToReplace = 0;
  9291. jassertfalse;
  9292. }
  9293. const int len = length();
  9294. if (index + numCharsToReplace > len)
  9295. {
  9296. if (index > len)
  9297. {
  9298. // replacing beyond the end of the string?
  9299. index = len;
  9300. jassertfalse
  9301. }
  9302. numCharsToReplace = len - index;
  9303. }
  9304. const int newStringLen = (stringToInsert != 0) ? CharacterFunctions::length (stringToInsert) : 0;
  9305. const int newTotalLen = len + newStringLen - numCharsToReplace;
  9306. if (newTotalLen <= 0)
  9307. return String::empty;
  9308. String result (newTotalLen, (int) 0);
  9309. memcpy (result.text->text,
  9310. text->text,
  9311. index * sizeof (tchar));
  9312. if (newStringLen > 0)
  9313. memcpy (result.text->text + index,
  9314. stringToInsert,
  9315. newStringLen * sizeof (tchar));
  9316. const int endStringLen = newTotalLen - (index + newStringLen);
  9317. if (endStringLen > 0)
  9318. memcpy (result.text->text + (index + newStringLen),
  9319. text->text + (index + numCharsToReplace),
  9320. endStringLen * sizeof (tchar));
  9321. result.text->text [newTotalLen] = 0;
  9322. return result;
  9323. }
  9324. const String String::replace (const tchar* const stringToReplace,
  9325. const tchar* const stringToInsert,
  9326. const bool ignoreCase) const throw()
  9327. {
  9328. const int stringToReplaceLen = CharacterFunctions::length (stringToReplace);
  9329. const int stringToInsertLen = CharacterFunctions::length (stringToInsert);
  9330. int i = 0;
  9331. String result (*this);
  9332. while ((i = (ignoreCase ? result.indexOfIgnoreCase (i, stringToReplace)
  9333. : result.indexOf (i, stringToReplace))) >= 0)
  9334. {
  9335. result = result.replaceSection (i, stringToReplaceLen, stringToInsert);
  9336. i += stringToInsertLen;
  9337. }
  9338. return result;
  9339. }
  9340. const String String::replaceCharacter (const tchar charToReplace,
  9341. const tchar charToInsert) const throw()
  9342. {
  9343. const int index = indexOfChar (charToReplace);
  9344. if (index < 0)
  9345. return *this;
  9346. String result (*this);
  9347. result.dupeInternalIfMultiplyReferenced();
  9348. tchar* t = result.text->text + index;
  9349. while (*t != 0)
  9350. {
  9351. if (*t == charToReplace)
  9352. *t = charToInsert;
  9353. ++t;
  9354. }
  9355. return result;
  9356. }
  9357. const String String::replaceCharacters (const String& charactersToReplace,
  9358. const tchar* const charactersToInsertInstead) const throw()
  9359. {
  9360. String result (*this);
  9361. result.dupeInternalIfMultiplyReferenced();
  9362. tchar* t = result.text->text;
  9363. const int len2 = CharacterFunctions::length (charactersToInsertInstead);
  9364. // the two strings passed in are supposed to be the same length!
  9365. jassert (len2 == charactersToReplace.length());
  9366. while (*t != 0)
  9367. {
  9368. const int index = charactersToReplace.indexOfChar (*t);
  9369. if (((unsigned int) index) < (unsigned int) len2)
  9370. *t = charactersToInsertInstead [index];
  9371. ++t;
  9372. }
  9373. return result;
  9374. }
  9375. bool String::startsWith (const tchar* const other) const throw()
  9376. {
  9377. return other != 0
  9378. && CharacterFunctions::compare (text->text, other, CharacterFunctions::length (other)) == 0;
  9379. }
  9380. bool String::startsWithIgnoreCase (const tchar* const other) const throw()
  9381. {
  9382. return other != 0
  9383. && CharacterFunctions::compareIgnoreCase (text->text, other, CharacterFunctions::length (other)) == 0;
  9384. }
  9385. bool String::startsWithChar (const tchar character) const throw()
  9386. {
  9387. jassert (character != 0); // strings can't contain a null character!
  9388. return text->text[0] == character;
  9389. }
  9390. bool String::endsWithChar (const tchar character) const throw()
  9391. {
  9392. jassert (character != 0); // strings can't contain a null character!
  9393. return text->text[0] != 0
  9394. && text->text [length() - 1] == character;
  9395. }
  9396. bool String::endsWith (const tchar* const other) const throw()
  9397. {
  9398. if (other == 0)
  9399. return false;
  9400. const int thisLen = length();
  9401. const int otherLen = CharacterFunctions::length (other);
  9402. return thisLen >= otherLen
  9403. && CharacterFunctions::compare (text->text + thisLen - otherLen, other) == 0;
  9404. }
  9405. bool String::endsWithIgnoreCase (const tchar* const other) const throw()
  9406. {
  9407. if (other == 0)
  9408. return false;
  9409. const int thisLen = length();
  9410. const int otherLen = CharacterFunctions::length (other);
  9411. return thisLen >= otherLen
  9412. && CharacterFunctions::compareIgnoreCase (text->text + thisLen - otherLen, other) == 0;
  9413. }
  9414. const String String::toUpperCase() const throw()
  9415. {
  9416. String result (*this);
  9417. result.dupeInternalIfMultiplyReferenced();
  9418. CharacterFunctions::toUpperCase (result.text->text);
  9419. return result;
  9420. }
  9421. const String String::toLowerCase() const throw()
  9422. {
  9423. String result (*this);
  9424. result.dupeInternalIfMultiplyReferenced();
  9425. CharacterFunctions::toLowerCase (result.text->text);
  9426. return result;
  9427. }
  9428. juce_wchar& String::operator[] (const int index) throw()
  9429. {
  9430. jassert (((unsigned int) index) <= (unsigned int) length());
  9431. dupeInternalIfMultiplyReferenced();
  9432. return text->text [index];
  9433. }
  9434. juce_wchar String::getLastCharacter() const throw()
  9435. {
  9436. return (isEmpty()) ? ((juce_wchar) 0)
  9437. : text->text [CharacterFunctions::length (text->text) - 1];
  9438. }
  9439. const String String::substring (int start, int end) const throw()
  9440. {
  9441. if (start < 0)
  9442. start = 0;
  9443. else if (end <= start)
  9444. return empty;
  9445. int len = 0;
  9446. const tchar* const t = text->text;
  9447. while (len <= end && t [len] != 0)
  9448. ++len;
  9449. if (end >= len)
  9450. {
  9451. if (start == 0)
  9452. return *this;
  9453. end = len;
  9454. }
  9455. return String (text->text + start,
  9456. end - start);
  9457. }
  9458. const String String::substring (const int start) const throw()
  9459. {
  9460. if (start <= 0)
  9461. return *this;
  9462. const int len = CharacterFunctions::length (text->text);
  9463. if (start >= len)
  9464. return empty;
  9465. else
  9466. return String (text->text + start,
  9467. len - start);
  9468. }
  9469. const String String::dropLastCharacters (const int numberToDrop) const throw()
  9470. {
  9471. return String (text->text,
  9472. jmax (0, CharacterFunctions::length (text->text) - numberToDrop));
  9473. }
  9474. const String String::getLastCharacters (const int numCharacters) const throw()
  9475. {
  9476. return String (text->text + jmax (0, CharacterFunctions::length (text->text) - jmax (0, numCharacters)));
  9477. }
  9478. const String String::fromFirstOccurrenceOf (const tchar* const sub,
  9479. const bool includeSubString,
  9480. const bool ignoreCase) const throw()
  9481. {
  9482. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9483. : indexOf (sub);
  9484. if (i < 0)
  9485. return empty;
  9486. else
  9487. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9488. }
  9489. const String String::fromLastOccurrenceOf (const tchar* const sub,
  9490. const bool includeSubString,
  9491. const bool ignoreCase) const throw()
  9492. {
  9493. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9494. : lastIndexOf (sub);
  9495. if (i < 0)
  9496. return *this;
  9497. else
  9498. return substring (includeSubString ? i : i + CharacterFunctions::length (sub));
  9499. }
  9500. const String String::upToFirstOccurrenceOf (const tchar* const sub,
  9501. const bool includeSubString,
  9502. const bool ignoreCase) const throw()
  9503. {
  9504. const int i = ignoreCase ? indexOfIgnoreCase (sub)
  9505. : indexOf (sub);
  9506. if (i < 0)
  9507. return *this;
  9508. else
  9509. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9510. }
  9511. const String String::upToLastOccurrenceOf (const tchar* const sub,
  9512. const bool includeSubString,
  9513. const bool ignoreCase) const throw()
  9514. {
  9515. const int i = ignoreCase ? lastIndexOfIgnoreCase (sub)
  9516. : lastIndexOf (sub);
  9517. if (i < 0)
  9518. return *this;
  9519. return substring (0, includeSubString ? i + CharacterFunctions::length (sub) : i);
  9520. }
  9521. bool String::isQuotedString() const throw()
  9522. {
  9523. const String trimmed (trimStart());
  9524. return trimmed[0] == T('"')
  9525. || trimmed[0] == T('\'');
  9526. }
  9527. const String String::unquoted() const throw()
  9528. {
  9529. String s (*this);
  9530. if (s[0] == T('"') || s[0] == T('\''))
  9531. s = s.substring (1);
  9532. const int lastCharIndex = s.length() - 1;
  9533. if (lastCharIndex >= 0
  9534. && (s [lastCharIndex] == T('"') || s[lastCharIndex] == T('\'')))
  9535. s [lastCharIndex] = 0;
  9536. return s;
  9537. }
  9538. const String String::quoted (const tchar quoteCharacter) const throw()
  9539. {
  9540. if (isEmpty())
  9541. return charToString (quoteCharacter) + quoteCharacter;
  9542. String t (*this);
  9543. if (! t.startsWithChar (quoteCharacter))
  9544. t = charToString (quoteCharacter) + t;
  9545. if (! t.endsWithChar (quoteCharacter))
  9546. t += quoteCharacter;
  9547. return t;
  9548. }
  9549. const String String::trim() const throw()
  9550. {
  9551. if (isEmpty())
  9552. return empty;
  9553. int start = 0;
  9554. while (CharacterFunctions::isWhitespace (text->text [start]))
  9555. ++start;
  9556. const int len = CharacterFunctions::length (text->text);
  9557. int end = len - 1;
  9558. while ((end >= start) && CharacterFunctions::isWhitespace (text->text [end]))
  9559. --end;
  9560. ++end;
  9561. if (end <= start)
  9562. return empty;
  9563. else if (start > 0 || end < len)
  9564. return String (text->text + start, end - start);
  9565. else
  9566. return *this;
  9567. }
  9568. const String String::trimStart() const throw()
  9569. {
  9570. if (isEmpty())
  9571. return empty;
  9572. const tchar* t = text->text;
  9573. while (CharacterFunctions::isWhitespace (*t))
  9574. ++t;
  9575. if (t == text->text)
  9576. return *this;
  9577. else
  9578. return String (t);
  9579. }
  9580. const String String::trimEnd() const throw()
  9581. {
  9582. if (isEmpty())
  9583. return empty;
  9584. const tchar* endT = text->text + (CharacterFunctions::length (text->text) - 1);
  9585. while ((endT >= text->text) && CharacterFunctions::isWhitespace (*endT))
  9586. --endT;
  9587. return String (text->text, (int) (++endT - text->text));
  9588. }
  9589. const String String::trimCharactersAtStart (const tchar* charactersToTrim) const throw()
  9590. {
  9591. jassert (charactersToTrim != 0);
  9592. if (isEmpty())
  9593. return empty;
  9594. const tchar* t = text->text;
  9595. while (CharacterFunctions::indexOfCharFast (charactersToTrim, *t) >= 0)
  9596. ++t;
  9597. if (t == text->text)
  9598. return *this;
  9599. else
  9600. return String (t);
  9601. }
  9602. const String String::trimCharactersAtEnd (const tchar* charactersToTrim) const throw()
  9603. {
  9604. jassert (charactersToTrim != 0);
  9605. if (isEmpty())
  9606. return empty;
  9607. const tchar* endT = text->text + (CharacterFunctions::length (text->text) - 1);
  9608. while ((endT >= text->text) && CharacterFunctions::indexOfCharFast (charactersToTrim, *endT) >= 0)
  9609. --endT;
  9610. return String (text->text, (int) (++endT - text->text));
  9611. }
  9612. const String String::retainCharacters (const tchar* const charactersToRetain) const throw()
  9613. {
  9614. jassert (charactersToRetain != 0);
  9615. if (isEmpty())
  9616. return empty;
  9617. String result (text->allocatedNumChars, (int) 0);
  9618. tchar* dst = result.text->text;
  9619. const tchar* src = text->text;
  9620. while (*src != 0)
  9621. {
  9622. if (CharacterFunctions::indexOfCharFast (charactersToRetain, *src) >= 0)
  9623. *dst++ = *src;
  9624. ++src;
  9625. }
  9626. *dst = 0;
  9627. return result;
  9628. }
  9629. const String String::removeCharacters (const tchar* const charactersToRemove) const throw()
  9630. {
  9631. jassert (charactersToRemove != 0);
  9632. if (isEmpty())
  9633. return empty;
  9634. String result (text->allocatedNumChars, (int) 0);
  9635. tchar* dst = result.text->text;
  9636. const tchar* src = text->text;
  9637. while (*src != 0)
  9638. {
  9639. if (CharacterFunctions::indexOfCharFast (charactersToRemove, *src) < 0)
  9640. *dst++ = *src;
  9641. ++src;
  9642. }
  9643. *dst = 0;
  9644. return result;
  9645. }
  9646. const String String::initialSectionContainingOnly (const tchar* const permittedCharacters) const throw()
  9647. {
  9648. return substring (0, CharacterFunctions::getIntialSectionContainingOnly (text->text, permittedCharacters));
  9649. }
  9650. const String String::initialSectionNotContaining (const tchar* const charactersToStopAt) const throw()
  9651. {
  9652. jassert (charactersToStopAt != 0);
  9653. const tchar* const t = text->text;
  9654. int i = 0;
  9655. while (t[i] != 0)
  9656. {
  9657. if (CharacterFunctions::indexOfCharFast (charactersToStopAt, t[i]) >= 0)
  9658. return String (text->text, i);
  9659. ++i;
  9660. }
  9661. return empty;
  9662. }
  9663. bool String::containsOnly (const tchar* const chars) const throw()
  9664. {
  9665. jassert (chars != 0);
  9666. const tchar* t = text->text;
  9667. while (*t != 0)
  9668. if (CharacterFunctions::indexOfCharFast (chars, *t++) < 0)
  9669. return false;
  9670. return true;
  9671. }
  9672. bool String::containsAnyOf (const tchar* const chars) const throw()
  9673. {
  9674. jassert (chars != 0);
  9675. const tchar* t = text->text;
  9676. while (*t != 0)
  9677. if (CharacterFunctions::indexOfCharFast (chars, *t++) >= 0)
  9678. return true;
  9679. return false;
  9680. }
  9681. bool String::containsNonWhitespaceChars() const throw()
  9682. {
  9683. const tchar* t = text->text;
  9684. while (*t != 0)
  9685. if (! CharacterFunctions::isWhitespace (*t++))
  9686. return true;
  9687. return false;
  9688. }
  9689. int String::getIntValue() const throw()
  9690. {
  9691. return CharacterFunctions::getIntValue (text->text);
  9692. }
  9693. int String::getTrailingIntValue() const throw()
  9694. {
  9695. int n = 0;
  9696. int mult = 1;
  9697. const tchar* t = text->text + length();
  9698. while (--t >= text->text)
  9699. {
  9700. const tchar c = *t;
  9701. if (! CharacterFunctions::isDigit (c))
  9702. {
  9703. if (c == T('-'))
  9704. n = -n;
  9705. break;
  9706. }
  9707. n += mult * (c - T('0'));
  9708. mult *= 10;
  9709. }
  9710. return n;
  9711. }
  9712. int64 String::getLargeIntValue() const throw()
  9713. {
  9714. return CharacterFunctions::getInt64Value (text->text);
  9715. }
  9716. float String::getFloatValue() const throw()
  9717. {
  9718. return (float) CharacterFunctions::getDoubleValue (text->text);
  9719. }
  9720. double String::getDoubleValue() const throw()
  9721. {
  9722. return CharacterFunctions::getDoubleValue (text->text);
  9723. }
  9724. static const tchar* const hexDigits = T("0123456789abcdef");
  9725. const String String::toHexString (const int number) throw()
  9726. {
  9727. tchar buffer[32];
  9728. tchar* const end = buffer + 32;
  9729. tchar* t = end;
  9730. *--t = 0;
  9731. unsigned int v = (unsigned int) number;
  9732. do
  9733. {
  9734. *--t = hexDigits [v & 15];
  9735. v >>= 4;
  9736. } while (v != 0);
  9737. return String (t, (int) (((char*) end) - (char*) t) - 1);
  9738. }
  9739. const String String::toHexString (const int64 number) throw()
  9740. {
  9741. tchar buffer[32];
  9742. tchar* const end = buffer + 32;
  9743. tchar* t = end;
  9744. *--t = 0;
  9745. uint64 v = (uint64) number;
  9746. do
  9747. {
  9748. *--t = hexDigits [(int) (v & 15)];
  9749. v >>= 4;
  9750. } while (v != 0);
  9751. return String (t, (int) (((char*) end) - (char*) t));
  9752. }
  9753. const String String::toHexString (const short number) throw()
  9754. {
  9755. return toHexString ((int) (unsigned short) number);
  9756. }
  9757. const String String::toHexString (const unsigned char* data,
  9758. const int size,
  9759. const int groupSize) throw()
  9760. {
  9761. if (size <= 0)
  9762. return empty;
  9763. int numChars = (size * 2) + 2;
  9764. if (groupSize > 0)
  9765. numChars += size / groupSize;
  9766. String s (numChars, (int) 0);
  9767. tchar* d = s.text->text;
  9768. for (int i = 0; i < size; ++i)
  9769. {
  9770. *d++ = hexDigits [(*data) >> 4];
  9771. *d++ = hexDigits [(*data) & 0xf];
  9772. ++data;
  9773. if (groupSize > 0 && (i % groupSize) == (groupSize - 1) && i < (size - 1))
  9774. *d++ = T(' ');
  9775. }
  9776. *d = 0;
  9777. return s;
  9778. }
  9779. int String::getHexValue32() const throw()
  9780. {
  9781. int result = 0;
  9782. const tchar* c = text->text;
  9783. for (;;)
  9784. {
  9785. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9786. if (hexValue >= 0)
  9787. result = (result << 4) | hexValue;
  9788. else if (*c == 0)
  9789. break;
  9790. ++c;
  9791. }
  9792. return result;
  9793. }
  9794. int64 String::getHexValue64() const throw()
  9795. {
  9796. int64 result = 0;
  9797. const tchar* c = text->text;
  9798. for (;;)
  9799. {
  9800. const int hexValue = CharacterFunctions::getHexDigitValue (*c);
  9801. if (hexValue >= 0)
  9802. result = (result << 4) | hexValue;
  9803. else if (*c == 0)
  9804. break;
  9805. ++c;
  9806. }
  9807. return result;
  9808. }
  9809. const String String::createStringFromData (const void* const data_,
  9810. const int size) throw()
  9811. {
  9812. const char* const data = (const char*) data_;
  9813. if (size <= 0 || data == 0)
  9814. {
  9815. return empty;
  9816. }
  9817. else if (size < 2)
  9818. {
  9819. return charToString (data[0]);
  9820. }
  9821. else if ((data[0] == (char)-2 && data[1] == (char)-1)
  9822. || (data[0] == (char)-1 && data[1] == (char)-2))
  9823. {
  9824. // assume it's 16-bit unicode
  9825. const bool bigEndian = (data[0] == (char)-2);
  9826. const int numChars = size / 2 - 1;
  9827. String result;
  9828. result.preallocateStorage (numChars + 2);
  9829. const uint16* const src = (const uint16*) (data + 2);
  9830. tchar* const dst = const_cast <tchar*> ((const tchar*) result);
  9831. if (bigEndian)
  9832. {
  9833. for (int i = 0; i < numChars; ++i)
  9834. dst[i] = (tchar) ByteOrder::swapIfLittleEndian (src[i]);
  9835. }
  9836. else
  9837. {
  9838. for (int i = 0; i < numChars; ++i)
  9839. dst[i] = (tchar) ByteOrder::swapIfBigEndian (src[i]);
  9840. }
  9841. dst [numChars] = 0;
  9842. return result;
  9843. }
  9844. else
  9845. {
  9846. return String::fromUTF8 (data, size);
  9847. }
  9848. }
  9849. const char* String::toUTF8() const
  9850. {
  9851. if (isEmpty())
  9852. {
  9853. return (const char*) emptyCharString;
  9854. }
  9855. else
  9856. {
  9857. String* const mutableThis = const_cast <String*> (this);
  9858. mutableThis->dupeInternalIfMultiplyReferenced();
  9859. const int currentLen = CharacterFunctions::length (text->text) + 1;
  9860. const int utf8BytesNeeded = getNumBytesAsUTF8() + 1;
  9861. mutableThis->text = (InternalRefCountedStringHolder*)
  9862. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  9863. + (currentLen * sizeof (juce_wchar) + utf8BytesNeeded));
  9864. char* const otherCopy = (char*) (text->text + currentLen);
  9865. copyToUTF8 (otherCopy, std::numeric_limits<int>::max());
  9866. return otherCopy;
  9867. }
  9868. }
  9869. int String::copyToUTF8 (char* const buffer, const int maxBufferSizeBytes) const throw()
  9870. {
  9871. jassert (maxBufferSizeBytes >= 0); // keep this value positive, or no characters will be copied!
  9872. int num = 0, index = 0;
  9873. for (;;)
  9874. {
  9875. const uint32 c = (uint32) text->text [index++];
  9876. if (c >= 0x80)
  9877. {
  9878. int numExtraBytes = 1;
  9879. if (c >= 0x800)
  9880. {
  9881. ++numExtraBytes;
  9882. if (c >= 0x10000)
  9883. {
  9884. ++numExtraBytes;
  9885. if (c >= 0x200000)
  9886. {
  9887. ++numExtraBytes;
  9888. if (c >= 0x4000000)
  9889. ++numExtraBytes;
  9890. }
  9891. }
  9892. }
  9893. if (buffer != 0)
  9894. {
  9895. if (num + numExtraBytes >= maxBufferSizeBytes)
  9896. {
  9897. buffer [num++] = 0;
  9898. break;
  9899. }
  9900. else
  9901. {
  9902. buffer [num++] = (uint8) ((0xff << (7 - numExtraBytes)) | (c >> (numExtraBytes * 6)));
  9903. while (--numExtraBytes >= 0)
  9904. buffer [num++] = (uint8) (0x80 | (0x3f & (c >> (numExtraBytes * 6))));
  9905. }
  9906. }
  9907. else
  9908. {
  9909. num += numExtraBytes + 1;
  9910. }
  9911. }
  9912. else
  9913. {
  9914. if (buffer != 0)
  9915. {
  9916. if (num + 1 >= maxBufferSizeBytes)
  9917. {
  9918. buffer [num++] = 0;
  9919. break;
  9920. }
  9921. buffer [num] = (uint8) c;
  9922. }
  9923. ++num;
  9924. }
  9925. if (c == 0)
  9926. break;
  9927. }
  9928. return num;
  9929. }
  9930. int String::getNumBytesAsUTF8() const throw()
  9931. {
  9932. int num = 0;
  9933. const juce_wchar* t = text->text;
  9934. for (;;)
  9935. {
  9936. const uint32 c = (uint32) *t;
  9937. if (c >= 0x80)
  9938. {
  9939. ++num;
  9940. if (c >= 0x800)
  9941. {
  9942. ++num;
  9943. if (c >= 0x10000)
  9944. {
  9945. ++num;
  9946. if (c >= 0x200000)
  9947. {
  9948. ++num;
  9949. if (c >= 0x4000000)
  9950. ++num;
  9951. }
  9952. }
  9953. }
  9954. }
  9955. else if (c == 0)
  9956. break;
  9957. ++num;
  9958. ++t;
  9959. }
  9960. return num;
  9961. }
  9962. const String String::fromUTF8 (const char* const buffer, int bufferSizeBytes)
  9963. {
  9964. if (buffer == 0)
  9965. return empty;
  9966. if (bufferSizeBytes < 0)
  9967. bufferSizeBytes = std::numeric_limits<int>::max();
  9968. size_t numBytes;
  9969. for (numBytes = 0; numBytes < (size_t) bufferSizeBytes; ++numBytes)
  9970. if (buffer [numBytes] == 0)
  9971. break;
  9972. String result ((int) numBytes + 1, 0);
  9973. juce_wchar* dest = result.text->text;
  9974. size_t i = 0;
  9975. while (i < numBytes)
  9976. {
  9977. const char c = buffer [i++];
  9978. if (c < 0)
  9979. {
  9980. unsigned int mask = 0x7f;
  9981. int bit = 0x40;
  9982. int numExtraValues = 0;
  9983. while (bit != 0 && (c & bit) != 0)
  9984. {
  9985. bit >>= 1;
  9986. mask >>= 1;
  9987. ++numExtraValues;
  9988. }
  9989. int n = (mask & (unsigned char) c);
  9990. while (--numExtraValues >= 0 && i < (size_t) bufferSizeBytes)
  9991. {
  9992. const char nextByte = buffer[i];
  9993. if ((nextByte & 0xc0) != 0x80)
  9994. break;
  9995. n <<= 6;
  9996. n |= (nextByte & 0x3f);
  9997. ++i;
  9998. }
  9999. *dest++ = (juce_wchar) n;
  10000. }
  10001. else
  10002. {
  10003. *dest++ = (juce_wchar) c;
  10004. }
  10005. }
  10006. *dest = 0;
  10007. return result;
  10008. }
  10009. const char* String::toCString() const
  10010. {
  10011. if (isEmpty())
  10012. {
  10013. return (const char*) emptyCharString;
  10014. }
  10015. else
  10016. {
  10017. String* const mutableThis = const_cast <String*> (this);
  10018. mutableThis->dupeInternalIfMultiplyReferenced();
  10019. int len = length() + 1;
  10020. mutableThis->text = (InternalRefCountedStringHolder*)
  10021. juce_realloc (text, sizeof (InternalRefCountedStringHolder)
  10022. + (len * sizeof (juce_wchar) + len));
  10023. char* otherCopy = (char*) (text->text + len);
  10024. --len;
  10025. CharacterFunctions::copy (otherCopy, text->text, len);
  10026. otherCopy [len] = 0;
  10027. return otherCopy;
  10028. }
  10029. }
  10030. int String::getNumBytesAsCString() const throw()
  10031. {
  10032. return (int) wcstombs (0, text->text, 0);
  10033. }
  10034. int String::copyToCString (char* destBuffer, const int maxBufferSizeBytes) const throw()
  10035. {
  10036. const int numBytes = (int) wcstombs (destBuffer, text->text, maxBufferSizeBytes);
  10037. if (destBuffer != 0 && numBytes >= 0)
  10038. destBuffer [numBytes] = 0;
  10039. return numBytes;
  10040. }
  10041. void String::copyToUnicode (juce_wchar* const destBuffer, const int maxCharsToCopy) const throw()
  10042. {
  10043. const int len = jmin (maxCharsToCopy, length());
  10044. memcpy (destBuffer, text->text, len * sizeof (juce_wchar));
  10045. destBuffer [len] = 0;
  10046. }
  10047. String::Concatenator::Concatenator (String& stringToAppendTo)
  10048. : result (stringToAppendTo),
  10049. nextIndex (stringToAppendTo.length())
  10050. {
  10051. }
  10052. String::Concatenator::~Concatenator()
  10053. {
  10054. }
  10055. void String::Concatenator::append (const String& s)
  10056. {
  10057. const int len = s.length();
  10058. if (len > 0)
  10059. {
  10060. result.preallocateStorage (nextIndex + len);
  10061. s.copyToUnicode (((juce_wchar*) result) + nextIndex, len);
  10062. nextIndex += len;
  10063. }
  10064. }
  10065. END_JUCE_NAMESPACE
  10066. /*** End of inlined file: juce_String.cpp ***/
  10067. /*** Start of inlined file: juce_StringArray.cpp ***/
  10068. BEGIN_JUCE_NAMESPACE
  10069. StringArray::StringArray() throw()
  10070. {
  10071. }
  10072. StringArray::StringArray (const StringArray& other)
  10073. : strings (other.strings)
  10074. {
  10075. }
  10076. StringArray::StringArray (const juce_wchar** const initialStrings,
  10077. const int numberOfStrings)
  10078. {
  10079. for (int i = 0; i < numberOfStrings; ++i)
  10080. add (initialStrings [i]);
  10081. }
  10082. StringArray::StringArray (const char** const initialStrings,
  10083. const int numberOfStrings)
  10084. {
  10085. for (int i = 0; i < numberOfStrings; ++i)
  10086. add (initialStrings [i]);
  10087. }
  10088. StringArray::StringArray (const juce_wchar** const initialStrings)
  10089. {
  10090. int i = 0;
  10091. while (initialStrings[i] != 0)
  10092. add (initialStrings [i++]);
  10093. }
  10094. StringArray::StringArray (const char** const initialStrings)
  10095. {
  10096. int i = 0;
  10097. while (initialStrings[i] != 0)
  10098. add (initialStrings [i++]);
  10099. }
  10100. StringArray& StringArray::operator= (const StringArray& other)
  10101. {
  10102. strings = other.strings;
  10103. return *this;
  10104. }
  10105. StringArray::~StringArray()
  10106. {
  10107. }
  10108. bool StringArray::operator== (const StringArray& other) const
  10109. {
  10110. if (other.size() != size())
  10111. return false;
  10112. for (int i = size(); --i >= 0;)
  10113. if (other.strings.getReference(i) != strings.getReference(i))
  10114. return false;
  10115. return true;
  10116. }
  10117. bool StringArray::operator!= (const StringArray& other) const
  10118. {
  10119. return ! operator== (other);
  10120. }
  10121. void StringArray::clear()
  10122. {
  10123. strings.clear();
  10124. }
  10125. const String& StringArray::operator[] (const int index) const throw()
  10126. {
  10127. if (((unsigned int) index) < (unsigned int) strings.size())
  10128. return strings.getReference (index);
  10129. return String::empty;
  10130. }
  10131. void StringArray::add (const String& newString)
  10132. {
  10133. strings.add (newString);
  10134. }
  10135. void StringArray::insert (const int index, const String& newString)
  10136. {
  10137. strings.insert (index, newString);
  10138. }
  10139. void StringArray::addIfNotAlreadyThere (const String& newString, const bool ignoreCase)
  10140. {
  10141. if (! contains (newString, ignoreCase))
  10142. add (newString);
  10143. }
  10144. void StringArray::addArray (const StringArray& otherArray, int startIndex, int numElementsToAdd)
  10145. {
  10146. if (startIndex < 0)
  10147. {
  10148. jassertfalse
  10149. startIndex = 0;
  10150. }
  10151. if (numElementsToAdd < 0 || startIndex + numElementsToAdd > otherArray.size())
  10152. numElementsToAdd = otherArray.size() - startIndex;
  10153. while (--numElementsToAdd >= 0)
  10154. strings.add (otherArray.strings.getReference (startIndex++));
  10155. }
  10156. void StringArray::set (const int index, const String& newString)
  10157. {
  10158. strings.set (index, newString);
  10159. }
  10160. bool StringArray::contains (const String& stringToLookFor, const bool ignoreCase) const
  10161. {
  10162. if (ignoreCase)
  10163. {
  10164. for (int i = size(); --i >= 0;)
  10165. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10166. return true;
  10167. }
  10168. else
  10169. {
  10170. for (int i = size(); --i >= 0;)
  10171. if (stringToLookFor == strings.getReference(i))
  10172. return true;
  10173. }
  10174. return false;
  10175. }
  10176. int StringArray::indexOf (const String& stringToLookFor, const bool ignoreCase, int i) const
  10177. {
  10178. if (i < 0)
  10179. i = 0;
  10180. const int numElements = size();
  10181. if (ignoreCase)
  10182. {
  10183. while (i < numElements)
  10184. {
  10185. if (strings.getReference(i).equalsIgnoreCase (stringToLookFor))
  10186. return i;
  10187. ++i;
  10188. }
  10189. }
  10190. else
  10191. {
  10192. while (i < numElements)
  10193. {
  10194. if (stringToLookFor == strings.getReference (i))
  10195. return i;
  10196. ++i;
  10197. }
  10198. }
  10199. return -1;
  10200. }
  10201. void StringArray::remove (const int index)
  10202. {
  10203. strings.remove (index);
  10204. }
  10205. void StringArray::removeString (const String& stringToRemove,
  10206. const bool ignoreCase)
  10207. {
  10208. if (ignoreCase)
  10209. {
  10210. for (int i = size(); --i >= 0;)
  10211. if (strings.getReference(i).equalsIgnoreCase (stringToRemove))
  10212. strings.remove (i);
  10213. }
  10214. else
  10215. {
  10216. for (int i = size(); --i >= 0;)
  10217. if (stringToRemove == strings.getReference (i))
  10218. strings.remove (i);
  10219. }
  10220. }
  10221. void StringArray::removeEmptyStrings (const bool removeWhitespaceStrings)
  10222. {
  10223. if (removeWhitespaceStrings)
  10224. {
  10225. for (int i = size(); --i >= 0;)
  10226. if (! strings.getReference(i).containsNonWhitespaceChars())
  10227. strings.remove (i);
  10228. }
  10229. else
  10230. {
  10231. for (int i = size(); --i >= 0;)
  10232. if (strings.getReference(i).isEmpty())
  10233. strings.remove (i);
  10234. }
  10235. }
  10236. void StringArray::trim()
  10237. {
  10238. for (int i = size(); --i >= 0;)
  10239. {
  10240. String& s = strings.getReference(i);
  10241. s = s.trim();
  10242. }
  10243. }
  10244. class InternalStringArrayComparator_CaseSensitive
  10245. {
  10246. public:
  10247. static int compareElements (String& first, String& second) { return first.compare (second); }
  10248. };
  10249. class InternalStringArrayComparator_CaseInsensitive
  10250. {
  10251. public:
  10252. static int compareElements (String& first, String& second) { return first.compareIgnoreCase (second); }
  10253. };
  10254. void StringArray::sort (const bool ignoreCase)
  10255. {
  10256. if (ignoreCase)
  10257. {
  10258. InternalStringArrayComparator_CaseInsensitive comp;
  10259. strings.sort (comp);
  10260. }
  10261. else
  10262. {
  10263. InternalStringArrayComparator_CaseSensitive comp;
  10264. strings.sort (comp);
  10265. }
  10266. }
  10267. void StringArray::move (const int currentIndex, int newIndex) throw()
  10268. {
  10269. strings.move (currentIndex, newIndex);
  10270. }
  10271. const String StringArray::joinIntoString (const String& separator, int start, int numberToJoin) const
  10272. {
  10273. const int last = (numberToJoin < 0) ? size()
  10274. : jmin (size(), start + numberToJoin);
  10275. if (start < 0)
  10276. start = 0;
  10277. if (start >= last)
  10278. return String::empty;
  10279. if (start == last - 1)
  10280. return strings.getReference (start);
  10281. const int separatorLen = separator.length();
  10282. int charsNeeded = separatorLen * (last - start - 1);
  10283. for (int i = start; i < last; ++i)
  10284. charsNeeded += strings.getReference(i).length();
  10285. String result;
  10286. result.preallocateStorage (charsNeeded);
  10287. juce_wchar* dest = (juce_wchar*) result;
  10288. while (start < last)
  10289. {
  10290. const String& s = strings.getReference (start);
  10291. const int len = s.length();
  10292. if (len > 0)
  10293. {
  10294. s.copyToUnicode (dest, len);
  10295. dest += len;
  10296. }
  10297. if (++start < last && separatorLen > 0)
  10298. {
  10299. separator.copyToUnicode (dest, separatorLen);
  10300. dest += separatorLen;
  10301. }
  10302. }
  10303. *dest = 0;
  10304. return result;
  10305. }
  10306. int StringArray::addTokens (const tchar* const text, const bool preserveQuotedStrings)
  10307. {
  10308. return addTokens (text,
  10309. T(" \n\r\t"),
  10310. preserveQuotedStrings ? T("\"") : 0);
  10311. }
  10312. int StringArray::addTokens (const tchar* const text, const tchar* breakCharacters, const tchar* quoteCharacters)
  10313. {
  10314. int num = 0;
  10315. if (text != 0 && *text != 0)
  10316. {
  10317. if (breakCharacters == 0)
  10318. breakCharacters = T("");
  10319. if (quoteCharacters == 0)
  10320. quoteCharacters = T("");
  10321. bool insideQuotes = false;
  10322. tchar currentQuoteChar = 0;
  10323. int i = 0;
  10324. int tokenStart = 0;
  10325. for (;;)
  10326. {
  10327. const tchar c = text[i];
  10328. bool isBreak = (c == 0);
  10329. if (! (insideQuotes || isBreak))
  10330. {
  10331. const tchar* b = breakCharacters;
  10332. while (*b != 0)
  10333. {
  10334. if (*b++ == c)
  10335. {
  10336. isBreak = true;
  10337. break;
  10338. }
  10339. }
  10340. }
  10341. if (! isBreak)
  10342. {
  10343. bool isQuote = false;
  10344. const tchar* q = quoteCharacters;
  10345. while (*q != 0)
  10346. {
  10347. if (*q++ == c)
  10348. {
  10349. isQuote = true;
  10350. break;
  10351. }
  10352. }
  10353. if (isQuote)
  10354. {
  10355. if (insideQuotes)
  10356. {
  10357. // only break out of quotes-mode if we find a matching quote to the
  10358. // one that we opened with..
  10359. if (currentQuoteChar == c)
  10360. insideQuotes = false;
  10361. }
  10362. else
  10363. {
  10364. insideQuotes = true;
  10365. currentQuoteChar = c;
  10366. }
  10367. }
  10368. }
  10369. else
  10370. {
  10371. add (String (text + tokenStart, i - tokenStart));
  10372. ++num;
  10373. tokenStart = i + 1;
  10374. }
  10375. if (c == 0)
  10376. break;
  10377. ++i;
  10378. }
  10379. }
  10380. return num;
  10381. }
  10382. int StringArray::addLines (const tchar* text)
  10383. {
  10384. int numLines = 0;
  10385. if (text != 0)
  10386. {
  10387. while (*text != 0)
  10388. {
  10389. const tchar* const startOfLine = text;
  10390. while (*text != 0)
  10391. {
  10392. if (*text == T('\r'))
  10393. {
  10394. ++text;
  10395. if (*text == T('\n'))
  10396. ++text;
  10397. break;
  10398. }
  10399. if (*text == T('\n'))
  10400. {
  10401. ++text;
  10402. break;
  10403. }
  10404. ++text;
  10405. }
  10406. const tchar* endOfLine = text;
  10407. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10408. --endOfLine;
  10409. if (endOfLine > startOfLine && (*(endOfLine - 1) == T('\r') || *(endOfLine - 1) == T('\n')))
  10410. --endOfLine;
  10411. add (String (startOfLine, jmax (0, (int) (endOfLine - startOfLine))));
  10412. ++numLines;
  10413. }
  10414. }
  10415. return numLines;
  10416. }
  10417. void StringArray::removeDuplicates (const bool ignoreCase)
  10418. {
  10419. for (int i = 0; i < size() - 1; ++i)
  10420. {
  10421. const String s (strings.getReference(i));
  10422. int nextIndex = i + 1;
  10423. for (;;)
  10424. {
  10425. nextIndex = indexOf (s, ignoreCase, nextIndex);
  10426. if (nextIndex < 0)
  10427. break;
  10428. strings.remove (nextIndex);
  10429. }
  10430. }
  10431. }
  10432. void StringArray::appendNumbersToDuplicates (const bool ignoreCase,
  10433. const bool appendNumberToFirstInstance,
  10434. const tchar* const preNumberString,
  10435. const tchar* const postNumberString)
  10436. {
  10437. for (int i = 0; i < size() - 1; ++i)
  10438. {
  10439. String& s = strings.getReference(i);
  10440. int nextIndex = indexOf (s, ignoreCase, i + 1);
  10441. if (nextIndex >= 0)
  10442. {
  10443. const String original (s);
  10444. int number = 0;
  10445. if (appendNumberToFirstInstance)
  10446. s = original + preNumberString + String (++number) + postNumberString;
  10447. else
  10448. ++number;
  10449. while (nextIndex >= 0)
  10450. {
  10451. set (nextIndex, (*this)[nextIndex] + preNumberString + String (++number) + postNumberString);
  10452. nextIndex = indexOf (original, ignoreCase, nextIndex + 1);
  10453. }
  10454. }
  10455. }
  10456. }
  10457. void StringArray::minimiseStorageOverheads()
  10458. {
  10459. strings.minimiseStorageOverheads();
  10460. }
  10461. END_JUCE_NAMESPACE
  10462. /*** End of inlined file: juce_StringArray.cpp ***/
  10463. /*** Start of inlined file: juce_StringPairArray.cpp ***/
  10464. BEGIN_JUCE_NAMESPACE
  10465. StringPairArray::StringPairArray (const bool ignoreCase_) throw()
  10466. : ignoreCase (ignoreCase_)
  10467. {
  10468. }
  10469. StringPairArray::StringPairArray (const StringPairArray& other) throw()
  10470. : keys (other.keys),
  10471. values (other.values),
  10472. ignoreCase (other.ignoreCase)
  10473. {
  10474. }
  10475. StringPairArray::~StringPairArray() throw()
  10476. {
  10477. }
  10478. StringPairArray& StringPairArray::operator= (const StringPairArray& other) throw()
  10479. {
  10480. keys = other.keys;
  10481. values = other.values;
  10482. return *this;
  10483. }
  10484. bool StringPairArray::operator== (const StringPairArray& other) const throw()
  10485. {
  10486. for (int i = keys.size(); --i >= 0;)
  10487. if (other [keys[i]] != values[i])
  10488. return false;
  10489. return true;
  10490. }
  10491. bool StringPairArray::operator!= (const StringPairArray& other) const throw()
  10492. {
  10493. return ! operator== (other);
  10494. }
  10495. const String& StringPairArray::operator[] (const String& key) const throw()
  10496. {
  10497. return values [keys.indexOf (key, ignoreCase)];
  10498. }
  10499. const String StringPairArray::getValue (const String& key, const String& defaultReturnValue) const
  10500. {
  10501. const int i = keys.indexOf (key, ignoreCase);
  10502. if (i >= 0)
  10503. return values[i];
  10504. return defaultReturnValue;
  10505. }
  10506. void StringPairArray::set (const String& key,
  10507. const String& value) throw()
  10508. {
  10509. const int i = keys.indexOf (key, ignoreCase);
  10510. if (i >= 0)
  10511. {
  10512. values.set (i, value);
  10513. }
  10514. else
  10515. {
  10516. keys.add (key);
  10517. values.add (value);
  10518. }
  10519. }
  10520. void StringPairArray::addArray (const StringPairArray& other)
  10521. {
  10522. for (int i = 0; i < other.size(); ++i)
  10523. set (other.keys[i], other.values[i]);
  10524. }
  10525. void StringPairArray::clear() throw()
  10526. {
  10527. keys.clear();
  10528. values.clear();
  10529. }
  10530. void StringPairArray::remove (const String& key) throw()
  10531. {
  10532. remove (keys.indexOf (key, ignoreCase));
  10533. }
  10534. void StringPairArray::remove (const int index) throw()
  10535. {
  10536. keys.remove (index);
  10537. values.remove (index);
  10538. }
  10539. void StringPairArray::setIgnoresCase (const bool shouldIgnoreCase) throw()
  10540. {
  10541. ignoreCase = shouldIgnoreCase;
  10542. }
  10543. const String StringPairArray::getDescription() const
  10544. {
  10545. String s;
  10546. for (int i = 0; i < keys.size(); ++i)
  10547. {
  10548. s << keys[i] << T(" = ") << values[i];
  10549. if (i < keys.size())
  10550. s << T(", ");
  10551. }
  10552. return s;
  10553. }
  10554. void StringPairArray::minimiseStorageOverheads() throw()
  10555. {
  10556. keys.minimiseStorageOverheads();
  10557. values.minimiseStorageOverheads();
  10558. }
  10559. END_JUCE_NAMESPACE
  10560. /*** End of inlined file: juce_StringPairArray.cpp ***/
  10561. /*** Start of inlined file: juce_XmlDocument.cpp ***/
  10562. BEGIN_JUCE_NAMESPACE
  10563. XmlDocument::XmlDocument (const String& documentText) throw()
  10564. : originalText (documentText),
  10565. ignoreEmptyTextElements (true)
  10566. {
  10567. }
  10568. XmlDocument::XmlDocument (const File& file)
  10569. {
  10570. inputSource = new FileInputSource (file);
  10571. }
  10572. XmlDocument::~XmlDocument() throw()
  10573. {
  10574. }
  10575. void XmlDocument::setInputSource (InputSource* const newSource) throw()
  10576. {
  10577. inputSource = newSource;
  10578. }
  10579. void XmlDocument::setEmptyTextElementsIgnored (const bool shouldBeIgnored) throw()
  10580. {
  10581. ignoreEmptyTextElements = shouldBeIgnored;
  10582. }
  10583. bool XmlDocument::isXmlIdentifierCharSlow (const tchar c) throw()
  10584. {
  10585. return CharacterFunctions::isLetterOrDigit (c)
  10586. || c == T('_')
  10587. || c == T('-')
  10588. || c == T(':')
  10589. || c == T('.');
  10590. }
  10591. inline bool XmlDocument::isXmlIdentifierChar (const tchar c) const throw()
  10592. {
  10593. return (c > 0 && c <= 127) ? identifierLookupTable [(int) c]
  10594. : isXmlIdentifierCharSlow (c);
  10595. }
  10596. XmlElement* XmlDocument::getDocumentElement (const bool onlyReadOuterDocumentElement)
  10597. {
  10598. String textToParse (originalText);
  10599. if (textToParse.isEmpty() && inputSource != 0)
  10600. {
  10601. ScopedPointer <InputStream> in (inputSource->createInputStream());
  10602. if (in != 0)
  10603. {
  10604. MemoryBlock data;
  10605. in->readIntoMemoryBlock (data, onlyReadOuterDocumentElement ? 8192 : -1);
  10606. if (data.getSize() >= 2
  10607. && ((data[0] == (char)-2 && data[1] == (char)-1)
  10608. || (data[0] == (char)-1 && data[1] == (char)-2)))
  10609. {
  10610. textToParse = String::createStringFromData ((const char*) data.getData(), (int) data.getSize());
  10611. }
  10612. else
  10613. {
  10614. textToParse = String::fromUTF8 ((const char*) data.getData(), (int) data.getSize());
  10615. }
  10616. if (! onlyReadOuterDocumentElement)
  10617. originalText = textToParse;
  10618. }
  10619. }
  10620. input = textToParse;
  10621. lastError = String::empty;
  10622. errorOccurred = false;
  10623. outOfData = false;
  10624. needToLoadDTD = true;
  10625. for (int i = 0; i < 128; ++i)
  10626. identifierLookupTable[i] = isXmlIdentifierCharSlow ((tchar) i);
  10627. if (textToParse.isEmpty())
  10628. {
  10629. lastError = "not enough input";
  10630. }
  10631. else
  10632. {
  10633. skipHeader();
  10634. if (input != 0)
  10635. {
  10636. ScopedPointer <XmlElement> result (readNextElement (! onlyReadOuterDocumentElement));
  10637. if (! errorOccurred)
  10638. return result.release();
  10639. }
  10640. else
  10641. {
  10642. lastError = "incorrect xml header";
  10643. }
  10644. }
  10645. return 0;
  10646. }
  10647. const String& XmlDocument::getLastParseError() const throw()
  10648. {
  10649. return lastError;
  10650. }
  10651. void XmlDocument::setLastError (const String& desc, const bool carryOn) throw()
  10652. {
  10653. lastError = desc;
  10654. errorOccurred = ! carryOn;
  10655. }
  10656. const String XmlDocument::getFileContents (const String& filename) const
  10657. {
  10658. if (inputSource != 0)
  10659. {
  10660. const ScopedPointer <InputStream> in (inputSource->createInputStreamFor (filename.trim().unquoted()));
  10661. if (in != 0)
  10662. return in->readEntireStreamAsString();
  10663. }
  10664. return String::empty;
  10665. }
  10666. tchar XmlDocument::readNextChar() throw()
  10667. {
  10668. if (*input != 0)
  10669. {
  10670. return *input++;
  10671. }
  10672. else
  10673. {
  10674. outOfData = true;
  10675. return 0;
  10676. }
  10677. }
  10678. int XmlDocument::findNextTokenLength() throw()
  10679. {
  10680. int len = 0;
  10681. tchar c = *input;
  10682. while (isXmlIdentifierChar (c))
  10683. c = input [++len];
  10684. return len;
  10685. }
  10686. void XmlDocument::skipHeader() throw()
  10687. {
  10688. const tchar* const found = CharacterFunctions::find (input, T("<?xml"));
  10689. if (found != 0)
  10690. {
  10691. input = found;
  10692. input = CharacterFunctions::find (input, T("?>"));
  10693. if (input == 0)
  10694. return;
  10695. input += 2;
  10696. }
  10697. skipNextWhiteSpace();
  10698. const tchar* docType = CharacterFunctions::find (input, T("<!DOCTYPE"));
  10699. if (docType == 0)
  10700. return;
  10701. input = docType + 9;
  10702. int n = 1;
  10703. while (n > 0)
  10704. {
  10705. const tchar c = readNextChar();
  10706. if (outOfData)
  10707. return;
  10708. if (c == T('<'))
  10709. ++n;
  10710. else if (c == T('>'))
  10711. --n;
  10712. }
  10713. docType += 9;
  10714. dtdText = String (docType, (int) (input - (docType + 1))).trim();
  10715. }
  10716. void XmlDocument::skipNextWhiteSpace() throw()
  10717. {
  10718. for (;;)
  10719. {
  10720. tchar c = *input;
  10721. while (CharacterFunctions::isWhitespace (c))
  10722. c = *++input;
  10723. if (c == 0)
  10724. {
  10725. outOfData = true;
  10726. break;
  10727. }
  10728. else if (c == T('<'))
  10729. {
  10730. if (input[1] == T('!')
  10731. && input[2] == T('-')
  10732. && input[3] == T('-'))
  10733. {
  10734. const tchar* const closeComment = CharacterFunctions::find (input, T("-->"));
  10735. if (closeComment == 0)
  10736. {
  10737. outOfData = true;
  10738. break;
  10739. }
  10740. input = closeComment + 3;
  10741. continue;
  10742. }
  10743. else if (input[1] == T('?'))
  10744. {
  10745. const tchar* const closeBracket = CharacterFunctions::find (input, T("?>"));
  10746. if (closeBracket == 0)
  10747. {
  10748. outOfData = true;
  10749. break;
  10750. }
  10751. input = closeBracket + 2;
  10752. continue;
  10753. }
  10754. }
  10755. break;
  10756. }
  10757. }
  10758. void XmlDocument::readQuotedString (String& result) throw()
  10759. {
  10760. const tchar quote = readNextChar();
  10761. while (! outOfData)
  10762. {
  10763. const tchar c = readNextChar();
  10764. if (c == quote)
  10765. break;
  10766. if (c == T('&'))
  10767. {
  10768. --input;
  10769. readEntity (result);
  10770. }
  10771. else
  10772. {
  10773. --input;
  10774. const tchar* const start = input;
  10775. for (;;)
  10776. {
  10777. const tchar character = *input;
  10778. if (character == quote)
  10779. {
  10780. result.append (start, (int) (input - start));
  10781. ++input;
  10782. return;
  10783. }
  10784. else if (character == T('&'))
  10785. {
  10786. result.append (start, (int) (input - start));
  10787. break;
  10788. }
  10789. else if (character == 0)
  10790. {
  10791. outOfData = true;
  10792. setLastError ("unmatched quotes", false);
  10793. break;
  10794. }
  10795. ++input;
  10796. }
  10797. }
  10798. }
  10799. }
  10800. XmlElement* XmlDocument::readNextElement (const bool alsoParseSubElements) throw()
  10801. {
  10802. XmlElement* node = 0;
  10803. skipNextWhiteSpace();
  10804. if (outOfData)
  10805. return 0;
  10806. input = CharacterFunctions::find (input, T("<"));
  10807. if (input != 0)
  10808. {
  10809. ++input;
  10810. int tagLen = findNextTokenLength();
  10811. if (tagLen == 0)
  10812. {
  10813. // no tag name - but allow for a gap after the '<' before giving an error
  10814. skipNextWhiteSpace();
  10815. tagLen = findNextTokenLength();
  10816. if (tagLen == 0)
  10817. {
  10818. setLastError ("tag name missing", false);
  10819. return node;
  10820. }
  10821. }
  10822. node = new XmlElement (String (input, tagLen));
  10823. input += tagLen;
  10824. XmlElement::XmlAttributeNode* lastAttribute = 0;
  10825. // look for attributes
  10826. for (;;)
  10827. {
  10828. skipNextWhiteSpace();
  10829. const tchar c = *input;
  10830. // empty tag..
  10831. if (c == T('/') && input[1] == T('>'))
  10832. {
  10833. input += 2;
  10834. break;
  10835. }
  10836. // parse the guts of the element..
  10837. if (c == T('>'))
  10838. {
  10839. ++input;
  10840. skipNextWhiteSpace();
  10841. if (alsoParseSubElements)
  10842. readChildElements (node);
  10843. break;
  10844. }
  10845. // get an attribute..
  10846. if (isXmlIdentifierChar (c))
  10847. {
  10848. const int attNameLen = findNextTokenLength();
  10849. if (attNameLen > 0)
  10850. {
  10851. const tchar* attNameStart = input;
  10852. input += attNameLen;
  10853. skipNextWhiteSpace();
  10854. if (readNextChar() == T('='))
  10855. {
  10856. skipNextWhiteSpace();
  10857. const tchar nextChar = *input;
  10858. if (nextChar == T('"') || nextChar == T('\''))
  10859. {
  10860. XmlElement::XmlAttributeNode* const newAtt
  10861. = new XmlElement::XmlAttributeNode (String (attNameStart, attNameLen),
  10862. String::empty);
  10863. readQuotedString (newAtt->value);
  10864. if (lastAttribute == 0)
  10865. node->attributes = newAtt;
  10866. else
  10867. lastAttribute->next = newAtt;
  10868. lastAttribute = newAtt;
  10869. continue;
  10870. }
  10871. }
  10872. }
  10873. }
  10874. else
  10875. {
  10876. if (! outOfData)
  10877. setLastError ("illegal character found in " + node->getTagName() + ": '" + c + "'", false);
  10878. }
  10879. break;
  10880. }
  10881. }
  10882. return node;
  10883. }
  10884. void XmlDocument::readChildElements (XmlElement* parent) throw()
  10885. {
  10886. XmlElement* lastChildNode = 0;
  10887. for (;;)
  10888. {
  10889. skipNextWhiteSpace();
  10890. if (outOfData)
  10891. {
  10892. setLastError ("unmatched tags", false);
  10893. break;
  10894. }
  10895. if (*input == T('<'))
  10896. {
  10897. if (input[1] == T('/'))
  10898. {
  10899. // our close tag..
  10900. input = CharacterFunctions::find (input, T(">"));
  10901. ++input;
  10902. break;
  10903. }
  10904. else if (input[1] == T('!')
  10905. && input[2] == T('[')
  10906. && input[3] == T('C')
  10907. && input[4] == T('D')
  10908. && input[5] == T('A')
  10909. && input[6] == T('T')
  10910. && input[7] == T('A')
  10911. && input[8] == T('['))
  10912. {
  10913. input += 9;
  10914. const tchar* const inputStart = input;
  10915. int len = 0;
  10916. for (;;)
  10917. {
  10918. if (*input == 0)
  10919. {
  10920. setLastError ("unterminated CDATA section", false);
  10921. outOfData = true;
  10922. break;
  10923. }
  10924. else if (input[0] == T(']')
  10925. && input[1] == T(']')
  10926. && input[2] == T('>'))
  10927. {
  10928. input += 3;
  10929. break;
  10930. }
  10931. ++input;
  10932. ++len;
  10933. }
  10934. XmlElement* const e = new XmlElement ((int) 0);
  10935. e->setText (String (inputStart, len));
  10936. if (lastChildNode != 0)
  10937. lastChildNode->nextElement = e;
  10938. else
  10939. parent->addChildElement (e);
  10940. lastChildNode = e;
  10941. }
  10942. else
  10943. {
  10944. // this is some other element, so parse and add it..
  10945. XmlElement* const n = readNextElement (true);
  10946. if (n != 0)
  10947. {
  10948. if (lastChildNode == 0)
  10949. parent->addChildElement (n);
  10950. else
  10951. lastChildNode->nextElement = n;
  10952. lastChildNode = n;
  10953. }
  10954. else
  10955. {
  10956. return;
  10957. }
  10958. }
  10959. }
  10960. else
  10961. {
  10962. // read character block..
  10963. XmlElement* const e = new XmlElement ((int)0);
  10964. if (lastChildNode != 0)
  10965. lastChildNode->nextElement = e;
  10966. else
  10967. parent->addChildElement (e);
  10968. lastChildNode = e;
  10969. String textElementContent;
  10970. for (;;)
  10971. {
  10972. const tchar c = *input;
  10973. if (c == T('<'))
  10974. break;
  10975. if (c == 0)
  10976. {
  10977. setLastError ("unmatched tags", false);
  10978. outOfData = true;
  10979. return;
  10980. }
  10981. if (c == T('&'))
  10982. {
  10983. String entity;
  10984. readEntity (entity);
  10985. if (entity.startsWithChar (T('<')) && entity [1] != 0)
  10986. {
  10987. const tchar* const oldInput = input;
  10988. const bool oldOutOfData = outOfData;
  10989. input = (const tchar*) entity;
  10990. outOfData = false;
  10991. for (;;)
  10992. {
  10993. XmlElement* const n = readNextElement (true);
  10994. if (n == 0)
  10995. break;
  10996. if (lastChildNode == 0)
  10997. parent->addChildElement (n);
  10998. else
  10999. lastChildNode->nextElement = n;
  11000. lastChildNode = n;
  11001. }
  11002. input = oldInput;
  11003. outOfData = oldOutOfData;
  11004. }
  11005. else
  11006. {
  11007. textElementContent += entity;
  11008. }
  11009. }
  11010. else
  11011. {
  11012. const tchar* start = input;
  11013. int len = 0;
  11014. for (;;)
  11015. {
  11016. const tchar nextChar = *input;
  11017. if (nextChar == T('<') || nextChar == T('&'))
  11018. {
  11019. break;
  11020. }
  11021. else if (nextChar == 0)
  11022. {
  11023. setLastError ("unmatched tags", false);
  11024. outOfData = true;
  11025. return;
  11026. }
  11027. ++input;
  11028. ++len;
  11029. }
  11030. textElementContent.append (start, len);
  11031. }
  11032. }
  11033. if (ignoreEmptyTextElements ? textElementContent.containsNonWhitespaceChars()
  11034. : textElementContent.isNotEmpty())
  11035. e->setText (textElementContent);
  11036. }
  11037. }
  11038. }
  11039. void XmlDocument::readEntity (String& result) throw()
  11040. {
  11041. // skip over the ampersand
  11042. ++input;
  11043. if (CharacterFunctions::compareIgnoreCase (input, T("amp;"), 4) == 0)
  11044. {
  11045. input += 4;
  11046. result += T("&");
  11047. }
  11048. else if (CharacterFunctions::compareIgnoreCase (input, T("quot;"), 5) == 0)
  11049. {
  11050. input += 5;
  11051. result += T("\"");
  11052. }
  11053. else if (CharacterFunctions::compareIgnoreCase (input, T("apos;"), 5) == 0)
  11054. {
  11055. input += 5;
  11056. result += T("\'");
  11057. }
  11058. else if (CharacterFunctions::compareIgnoreCase (input, T("lt;"), 3) == 0)
  11059. {
  11060. input += 3;
  11061. result += T("<");
  11062. }
  11063. else if (CharacterFunctions::compareIgnoreCase (input, T("gt;"), 3) == 0)
  11064. {
  11065. input += 3;
  11066. result += T(">");
  11067. }
  11068. else if (*input == T('#'))
  11069. {
  11070. int charCode = 0;
  11071. ++input;
  11072. if (*input == T('x') || *input == T('X'))
  11073. {
  11074. ++input;
  11075. int numChars = 0;
  11076. while (input[0] != T(';'))
  11077. {
  11078. const int hexValue = CharacterFunctions::getHexDigitValue (input[0]);
  11079. if (hexValue < 0 || ++numChars > 8)
  11080. {
  11081. setLastError ("illegal escape sequence", true);
  11082. break;
  11083. }
  11084. charCode = (charCode << 4) | hexValue;
  11085. ++input;
  11086. }
  11087. ++input;
  11088. }
  11089. else if (input[0] >= T('0') && input[0] <= T('9'))
  11090. {
  11091. int numChars = 0;
  11092. while (input[0] != T(';'))
  11093. {
  11094. if (++numChars > 12)
  11095. {
  11096. setLastError ("illegal escape sequence", true);
  11097. break;
  11098. }
  11099. charCode = charCode * 10 + (input[0] - T('0'));
  11100. ++input;
  11101. }
  11102. ++input;
  11103. }
  11104. else
  11105. {
  11106. setLastError ("illegal escape sequence", true);
  11107. result += T("&");
  11108. return;
  11109. }
  11110. result << (tchar) charCode;
  11111. }
  11112. else
  11113. {
  11114. const tchar* const entityNameStart = input;
  11115. const tchar* const closingSemiColon = CharacterFunctions::find (input, T(";"));
  11116. if (closingSemiColon == 0)
  11117. {
  11118. outOfData = true;
  11119. result += T("&");
  11120. }
  11121. else
  11122. {
  11123. input = closingSemiColon + 1;
  11124. result += expandExternalEntity (String (entityNameStart,
  11125. (int) (closingSemiColon - entityNameStart)));
  11126. }
  11127. }
  11128. }
  11129. const String XmlDocument::expandEntity (const String& ent)
  11130. {
  11131. if (ent.equalsIgnoreCase (T("amp")))
  11132. {
  11133. return T("&");
  11134. }
  11135. else if (ent.equalsIgnoreCase (T("quot")))
  11136. {
  11137. return T("\"");
  11138. }
  11139. else if (ent.equalsIgnoreCase (T("apos")))
  11140. {
  11141. return T("\'");
  11142. }
  11143. else if (ent.equalsIgnoreCase (T("lt")))
  11144. {
  11145. return T("<");
  11146. }
  11147. else if (ent.equalsIgnoreCase (T("gt")))
  11148. {
  11149. return T(">");
  11150. }
  11151. else if (ent[0] == T('#'))
  11152. {
  11153. if (ent[1] == T('x') || ent[1] == T('X'))
  11154. {
  11155. return String::charToString ((tchar) ent.substring (2).getHexValue32());
  11156. }
  11157. else if (ent[1] >= T('0') && ent[1] <= T('9'))
  11158. {
  11159. return String::charToString ((tchar) ent.substring (1).getIntValue());
  11160. }
  11161. setLastError ("illegal escape sequence", false);
  11162. return T("&");
  11163. }
  11164. else
  11165. {
  11166. return expandExternalEntity (ent);
  11167. }
  11168. }
  11169. const String XmlDocument::expandExternalEntity (const String& entity)
  11170. {
  11171. if (needToLoadDTD)
  11172. {
  11173. if (dtdText.isNotEmpty())
  11174. {
  11175. while (dtdText.endsWithChar (T('>')))
  11176. dtdText = dtdText.dropLastCharacters (1);
  11177. tokenisedDTD.addTokens (dtdText, true);
  11178. if (tokenisedDTD [tokenisedDTD.size() - 2].equalsIgnoreCase (T("system"))
  11179. && tokenisedDTD [tokenisedDTD.size() - 1].isQuotedString())
  11180. {
  11181. const String fn (tokenisedDTD [tokenisedDTD.size() - 1]);
  11182. tokenisedDTD.clear();
  11183. tokenisedDTD.addTokens (getFileContents (fn), true);
  11184. }
  11185. else
  11186. {
  11187. tokenisedDTD.clear();
  11188. const int openBracket = dtdText.indexOfChar (T('['));
  11189. if (openBracket > 0)
  11190. {
  11191. const int closeBracket = dtdText.lastIndexOfChar (T(']'));
  11192. if (closeBracket > openBracket)
  11193. tokenisedDTD.addTokens (dtdText.substring (openBracket + 1,
  11194. closeBracket), true);
  11195. }
  11196. }
  11197. for (int i = tokenisedDTD.size(); --i >= 0;)
  11198. {
  11199. if (tokenisedDTD[i].startsWithChar (T('%'))
  11200. && tokenisedDTD[i].endsWithChar (T(';')))
  11201. {
  11202. const String parsed (getParameterEntity (tokenisedDTD[i].substring (1, tokenisedDTD[i].length() - 1)));
  11203. StringArray newToks;
  11204. newToks.addTokens (parsed, true);
  11205. tokenisedDTD.remove (i);
  11206. for (int j = newToks.size(); --j >= 0;)
  11207. tokenisedDTD.insert (i, newToks[j]);
  11208. }
  11209. }
  11210. }
  11211. needToLoadDTD = false;
  11212. }
  11213. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11214. {
  11215. if (tokenisedDTD[i] == entity)
  11216. {
  11217. if (tokenisedDTD[i - 1].equalsIgnoreCase (T("<!entity")))
  11218. {
  11219. String ent (tokenisedDTD [i + 1]);
  11220. while (ent.endsWithChar (T('>')))
  11221. ent = ent.dropLastCharacters (1);
  11222. ent = ent.trim().unquoted();
  11223. // check for sub-entities..
  11224. int ampersand = ent.indexOfChar (T('&'));
  11225. while (ampersand >= 0)
  11226. {
  11227. const int semiColon = ent.indexOf (i + 1, T(";"));
  11228. if (semiColon < 0)
  11229. {
  11230. setLastError ("entity without terminating semi-colon", false);
  11231. break;
  11232. }
  11233. const String resolved (expandEntity (ent.substring (i + 1, semiColon)));
  11234. ent = ent.substring (0, ampersand)
  11235. + resolved
  11236. + ent.substring (semiColon + 1);
  11237. ampersand = ent.indexOfChar (semiColon + 1, T('&'));
  11238. }
  11239. return ent;
  11240. }
  11241. }
  11242. }
  11243. setLastError ("unknown entity", true);
  11244. return entity;
  11245. }
  11246. const String XmlDocument::getParameterEntity (const String& entity)
  11247. {
  11248. for (int i = 0; i < tokenisedDTD.size(); ++i)
  11249. {
  11250. if (tokenisedDTD[i] == entity)
  11251. {
  11252. if (tokenisedDTD [i - 1] == T("%")
  11253. && tokenisedDTD [i - 2].equalsIgnoreCase (T("<!entity")))
  11254. {
  11255. String ent (tokenisedDTD [i + 1]);
  11256. while (ent.endsWithChar (T('>')))
  11257. ent = ent.dropLastCharacters (1);
  11258. if (ent.equalsIgnoreCase (T("system")))
  11259. {
  11260. String filename (tokenisedDTD [i + 2]);
  11261. while (filename.endsWithChar (T('>')))
  11262. filename = filename.dropLastCharacters (1);
  11263. return getFileContents (filename);
  11264. }
  11265. else
  11266. {
  11267. return ent.trim().unquoted();
  11268. }
  11269. }
  11270. }
  11271. }
  11272. return entity;
  11273. }
  11274. END_JUCE_NAMESPACE
  11275. /*** End of inlined file: juce_XmlDocument.cpp ***/
  11276. /*** Start of inlined file: juce_XmlElement.cpp ***/
  11277. BEGIN_JUCE_NAMESPACE
  11278. XmlElement::XmlAttributeNode::XmlAttributeNode (const XmlAttributeNode& other) throw()
  11279. : name (other.name),
  11280. value (other.value),
  11281. next (0)
  11282. {
  11283. }
  11284. XmlElement::XmlAttributeNode::XmlAttributeNode (const String& name_,
  11285. const String& value_) throw()
  11286. : name (name_),
  11287. value (value_),
  11288. next (0)
  11289. {
  11290. }
  11291. XmlElement::XmlElement (const String& tagName_) throw()
  11292. : tagName (tagName_),
  11293. firstChildElement (0),
  11294. nextElement (0),
  11295. attributes (0)
  11296. {
  11297. // the tag name mustn't be empty, or it'll look like a text element!
  11298. jassert (tagName_.containsNonWhitespaceChars())
  11299. }
  11300. XmlElement::XmlElement (int /*dummy*/) throw()
  11301. : firstChildElement (0),
  11302. nextElement (0),
  11303. attributes (0)
  11304. {
  11305. }
  11306. XmlElement::XmlElement (const XmlElement& other) throw()
  11307. : tagName (other.tagName),
  11308. firstChildElement (0),
  11309. nextElement (0),
  11310. attributes (0)
  11311. {
  11312. copyChildrenAndAttributesFrom (other);
  11313. }
  11314. XmlElement& XmlElement::operator= (const XmlElement& other) throw()
  11315. {
  11316. if (this != &other)
  11317. {
  11318. removeAllAttributes();
  11319. deleteAllChildElements();
  11320. tagName = other.tagName;
  11321. copyChildrenAndAttributesFrom (other);
  11322. }
  11323. return *this;
  11324. }
  11325. void XmlElement::copyChildrenAndAttributesFrom (const XmlElement& other) throw()
  11326. {
  11327. XmlElement* child = other.firstChildElement;
  11328. XmlElement* lastChild = 0;
  11329. while (child != 0)
  11330. {
  11331. XmlElement* const copiedChild = new XmlElement (*child);
  11332. if (lastChild != 0)
  11333. lastChild->nextElement = copiedChild;
  11334. else
  11335. firstChildElement = copiedChild;
  11336. lastChild = copiedChild;
  11337. child = child->nextElement;
  11338. }
  11339. const XmlAttributeNode* att = other.attributes;
  11340. XmlAttributeNode* lastAtt = 0;
  11341. while (att != 0)
  11342. {
  11343. XmlAttributeNode* const newAtt = new XmlAttributeNode (*att);
  11344. if (lastAtt != 0)
  11345. lastAtt->next = newAtt;
  11346. else
  11347. attributes = newAtt;
  11348. lastAtt = newAtt;
  11349. att = att->next;
  11350. }
  11351. }
  11352. XmlElement::~XmlElement() throw()
  11353. {
  11354. XmlElement* child = firstChildElement;
  11355. while (child != 0)
  11356. {
  11357. XmlElement* const nextChild = child->nextElement;
  11358. delete child;
  11359. child = nextChild;
  11360. }
  11361. XmlAttributeNode* att = attributes;
  11362. while (att != 0)
  11363. {
  11364. XmlAttributeNode* const nextAtt = att->next;
  11365. delete att;
  11366. att = nextAtt;
  11367. }
  11368. }
  11369. namespace XmlOutputFunctions
  11370. {
  11371. static bool isLegalXmlChar (const uint32 c) throw()
  11372. {
  11373. static const unsigned char legalChars[] = { 0, 0, 0, 0, 171, 255, 255, 175, 255, 255, 255, 191, 254, 255, 255, 111 };
  11374. return c < sizeof (legalChars) * 8
  11375. && (legalChars [c >> 3] & (1 << (c & 7))) != 0;
  11376. }
  11377. static void escapeIllegalXmlChars (OutputStream& outputStream, const String& text, const bool changeNewLines)
  11378. {
  11379. const juce_wchar* t = (const juce_wchar*) text;
  11380. for (;;)
  11381. {
  11382. const juce_wchar character = *t++;
  11383. if (character == 0)
  11384. {
  11385. break;
  11386. }
  11387. else if (isLegalXmlChar ((uint32) character))
  11388. {
  11389. outputStream << (char) character;
  11390. }
  11391. else
  11392. {
  11393. switch (character)
  11394. {
  11395. case '&': outputStream << "&amp;"; break;
  11396. case '"': outputStream << "&quot;"; break;
  11397. case '>': outputStream << "&gt;"; break;
  11398. case '<': outputStream << "&lt;"; break;
  11399. case '\n':
  11400. if (changeNewLines)
  11401. outputStream << "&#10;";
  11402. else
  11403. outputStream << (char) character;
  11404. break;
  11405. case '\r':
  11406. if (changeNewLines)
  11407. outputStream << "&#13;";
  11408. else
  11409. outputStream << (char) character;
  11410. break;
  11411. default:
  11412. outputStream << "&#" << ((int) (unsigned int) character) << ';';
  11413. break;
  11414. }
  11415. }
  11416. }
  11417. }
  11418. static void writeSpaces (OutputStream& out, int numSpaces) throw()
  11419. {
  11420. if (numSpaces > 0)
  11421. {
  11422. const char* const blanks = " ";
  11423. const int blankSize = (int) sizeof (blanks) - 1;
  11424. while (numSpaces > blankSize)
  11425. {
  11426. out.write (blanks, blankSize);
  11427. numSpaces -= blankSize;
  11428. }
  11429. out.write (blanks, numSpaces);
  11430. }
  11431. }
  11432. }
  11433. void XmlElement::writeElementAsText (OutputStream& outputStream,
  11434. const int indentationLevel,
  11435. const int lineWrapLength) const throw()
  11436. {
  11437. using namespace XmlOutputFunctions;
  11438. writeSpaces (outputStream, indentationLevel);
  11439. if (! isTextElement())
  11440. {
  11441. outputStream.writeByte ('<');
  11442. outputStream << tagName;
  11443. const int attIndent = indentationLevel + tagName.length() + 1;
  11444. int lineLen = 0;
  11445. const XmlAttributeNode* att = attributes;
  11446. while (att != 0)
  11447. {
  11448. if (lineLen > lineWrapLength && indentationLevel >= 0)
  11449. {
  11450. outputStream.write ("\r\n", 2);
  11451. writeSpaces (outputStream, attIndent);
  11452. lineLen = 0;
  11453. }
  11454. const int64 startPos = outputStream.getPosition();
  11455. outputStream.writeByte (' ');
  11456. outputStream << att->name;
  11457. outputStream.write ("=\"", 2);
  11458. escapeIllegalXmlChars (outputStream, att->value, true);
  11459. outputStream.writeByte ('"');
  11460. lineLen += (int) (outputStream.getPosition() - startPos);
  11461. att = att->next;
  11462. }
  11463. if (firstChildElement != 0)
  11464. {
  11465. XmlElement* child = firstChildElement;
  11466. if (child->nextElement == 0 && child->isTextElement())
  11467. {
  11468. outputStream.writeByte ('>');
  11469. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11470. }
  11471. else
  11472. {
  11473. if (indentationLevel >= 0)
  11474. outputStream.write (">\r\n", 3);
  11475. else
  11476. outputStream.writeByte ('>');
  11477. bool lastWasTextNode = false;
  11478. while (child != 0)
  11479. {
  11480. if (child->isTextElement())
  11481. {
  11482. if ((! lastWasTextNode) && (indentationLevel >= 0))
  11483. writeSpaces (outputStream, indentationLevel + 2);
  11484. escapeIllegalXmlChars (outputStream, child->getText(), false);
  11485. lastWasTextNode = true;
  11486. }
  11487. else
  11488. {
  11489. if (indentationLevel >= 0)
  11490. {
  11491. if (lastWasTextNode)
  11492. outputStream.write ("\r\n", 2);
  11493. child->writeElementAsText (outputStream, indentationLevel + 2, lineWrapLength);
  11494. }
  11495. else
  11496. {
  11497. child->writeElementAsText (outputStream, indentationLevel, lineWrapLength);
  11498. }
  11499. lastWasTextNode = false;
  11500. }
  11501. child = child->nextElement;
  11502. }
  11503. if (indentationLevel >= 0)
  11504. {
  11505. if (lastWasTextNode)
  11506. outputStream.write ("\r\n", 2);
  11507. writeSpaces (outputStream, indentationLevel);
  11508. }
  11509. }
  11510. outputStream.write ("</", 2);
  11511. outputStream << tagName;
  11512. if (indentationLevel >= 0)
  11513. outputStream.write (">\r\n", 3);
  11514. else
  11515. outputStream.writeByte ('>');
  11516. }
  11517. else
  11518. {
  11519. if (indentationLevel >= 0)
  11520. outputStream.write ("/>\r\n", 4);
  11521. else
  11522. outputStream.write ("/>", 2);
  11523. }
  11524. }
  11525. else
  11526. {
  11527. if (indentationLevel >= 0)
  11528. writeSpaces (outputStream, indentationLevel + 2);
  11529. escapeIllegalXmlChars (outputStream, getText(), false);
  11530. }
  11531. }
  11532. const String XmlElement::createDocument (const String& dtdToUse,
  11533. const bool allOnOneLine,
  11534. const bool includeXmlHeader,
  11535. const String& encodingType,
  11536. const int lineWrapLength) const throw()
  11537. {
  11538. MemoryOutputStream mem (2048, 4096);
  11539. writeToStream (mem, dtdToUse, allOnOneLine, includeXmlHeader, encodingType, lineWrapLength);
  11540. return String (mem.getData(), mem.getDataSize());
  11541. }
  11542. void XmlElement::writeToStream (OutputStream& output,
  11543. const String& dtdToUse,
  11544. const bool allOnOneLine,
  11545. const bool includeXmlHeader,
  11546. const String& encodingType,
  11547. const int lineWrapLength) const throw()
  11548. {
  11549. if (includeXmlHeader)
  11550. {
  11551. output << "<?xml version=\"1.0\" encoding=\"" << encodingType;
  11552. if (allOnOneLine)
  11553. output << "\"?> ";
  11554. else
  11555. output << "\"?>\r\n\r\n";
  11556. }
  11557. if (dtdToUse.isNotEmpty())
  11558. {
  11559. output << dtdToUse;
  11560. if (allOnOneLine)
  11561. output << " ";
  11562. else
  11563. output << "\r\n";
  11564. }
  11565. writeElementAsText (output, allOnOneLine ? -1 : 0, lineWrapLength);
  11566. }
  11567. bool XmlElement::writeToFile (const File& file,
  11568. const String& dtdToUse,
  11569. const String& encodingType,
  11570. const int lineWrapLength) const throw()
  11571. {
  11572. if (file.hasWriteAccess())
  11573. {
  11574. TemporaryFile tempFile (file);
  11575. ScopedPointer <FileOutputStream> out (tempFile.getFile().createOutputStream());
  11576. if (out != 0)
  11577. {
  11578. writeToStream (*out, dtdToUse, false, true, encodingType, lineWrapLength);
  11579. out = 0;
  11580. return tempFile.overwriteTargetFileWithTemporary();
  11581. }
  11582. }
  11583. return false;
  11584. }
  11585. bool XmlElement::hasTagName (const String& tagNameWanted) const throw()
  11586. {
  11587. #ifdef JUCE_DEBUG
  11588. // if debugging, check that the case is actually the same, because
  11589. // valid xml is case-sensitive, and although this lets it pass, it's
  11590. // better not to..
  11591. if (tagName.equalsIgnoreCase (tagNameWanted))
  11592. {
  11593. jassert (tagName == tagNameWanted);
  11594. return true;
  11595. }
  11596. else
  11597. {
  11598. return false;
  11599. }
  11600. #else
  11601. return tagName.equalsIgnoreCase (tagNameWanted);
  11602. #endif
  11603. }
  11604. XmlElement* XmlElement::getNextElementWithTagName (const String& requiredTagName) const
  11605. {
  11606. XmlElement* e = nextElement;
  11607. while (e != 0 && ! e->hasTagName (requiredTagName))
  11608. e = e->nextElement;
  11609. return e;
  11610. }
  11611. int XmlElement::getNumAttributes() const throw()
  11612. {
  11613. const XmlAttributeNode* att = attributes;
  11614. int count = 0;
  11615. while (att != 0)
  11616. {
  11617. att = att->next;
  11618. ++count;
  11619. }
  11620. return count;
  11621. }
  11622. const String& XmlElement::getAttributeName (const int index) const throw()
  11623. {
  11624. const XmlAttributeNode* att = attributes;
  11625. int count = 0;
  11626. while (att != 0)
  11627. {
  11628. if (count == index)
  11629. return att->name;
  11630. att = att->next;
  11631. ++count;
  11632. }
  11633. return String::empty;
  11634. }
  11635. const String& XmlElement::getAttributeValue (const int index) const throw()
  11636. {
  11637. const XmlAttributeNode* att = attributes;
  11638. int count = 0;
  11639. while (att != 0)
  11640. {
  11641. if (count == index)
  11642. return att->value;
  11643. att = att->next;
  11644. ++count;
  11645. }
  11646. return String::empty;
  11647. }
  11648. bool XmlElement::hasAttribute (const String& attributeName) const throw()
  11649. {
  11650. const XmlAttributeNode* att = attributes;
  11651. while (att != 0)
  11652. {
  11653. if (att->name.equalsIgnoreCase (attributeName))
  11654. return true;
  11655. att = att->next;
  11656. }
  11657. return false;
  11658. }
  11659. const String XmlElement::getStringAttribute (const String& attributeName,
  11660. const String& defaultReturnValue) const throw()
  11661. {
  11662. const XmlAttributeNode* att = attributes;
  11663. while (att != 0)
  11664. {
  11665. if (att->name.equalsIgnoreCase (attributeName))
  11666. return att->value;
  11667. att = att->next;
  11668. }
  11669. return defaultReturnValue;
  11670. }
  11671. int XmlElement::getIntAttribute (const String& attributeName,
  11672. const int defaultReturnValue) const throw()
  11673. {
  11674. const XmlAttributeNode* att = attributes;
  11675. while (att != 0)
  11676. {
  11677. if (att->name.equalsIgnoreCase (attributeName))
  11678. return att->value.getIntValue();
  11679. att = att->next;
  11680. }
  11681. return defaultReturnValue;
  11682. }
  11683. double XmlElement::getDoubleAttribute (const String& attributeName,
  11684. const double defaultReturnValue) const throw()
  11685. {
  11686. const XmlAttributeNode* att = attributes;
  11687. while (att != 0)
  11688. {
  11689. if (att->name.equalsIgnoreCase (attributeName))
  11690. return att->value.getDoubleValue();
  11691. att = att->next;
  11692. }
  11693. return defaultReturnValue;
  11694. }
  11695. bool XmlElement::getBoolAttribute (const String& attributeName,
  11696. const bool defaultReturnValue) const throw()
  11697. {
  11698. const XmlAttributeNode* att = attributes;
  11699. while (att != 0)
  11700. {
  11701. if (att->name.equalsIgnoreCase (attributeName))
  11702. {
  11703. tchar firstChar = att->value[0];
  11704. if (CharacterFunctions::isWhitespace (firstChar))
  11705. firstChar = att->value.trimStart() [0];
  11706. return firstChar == T('1')
  11707. || firstChar == T('t')
  11708. || firstChar == T('y')
  11709. || firstChar == T('T')
  11710. || firstChar == T('Y');
  11711. }
  11712. att = att->next;
  11713. }
  11714. return defaultReturnValue;
  11715. }
  11716. bool XmlElement::compareAttribute (const String& attributeName,
  11717. const String& stringToCompareAgainst,
  11718. const bool ignoreCase) const throw()
  11719. {
  11720. const XmlAttributeNode* att = attributes;
  11721. while (att != 0)
  11722. {
  11723. if (att->name.equalsIgnoreCase (attributeName))
  11724. {
  11725. if (ignoreCase)
  11726. return att->value.equalsIgnoreCase (stringToCompareAgainst);
  11727. else
  11728. return att->value == stringToCompareAgainst;
  11729. }
  11730. att = att->next;
  11731. }
  11732. return false;
  11733. }
  11734. void XmlElement::setAttribute (const String& attributeName,
  11735. const String& value) throw()
  11736. {
  11737. #ifdef JUCE_DEBUG
  11738. // check the identifier being passed in is legal..
  11739. const tchar* t = attributeName;
  11740. while (*t != 0)
  11741. {
  11742. jassert (CharacterFunctions::isLetterOrDigit (*t)
  11743. || *t == T('_')
  11744. || *t == T('-')
  11745. || *t == T(':'));
  11746. ++t;
  11747. }
  11748. #endif
  11749. if (attributes == 0)
  11750. {
  11751. attributes = new XmlAttributeNode (attributeName, value);
  11752. }
  11753. else
  11754. {
  11755. XmlAttributeNode* att = attributes;
  11756. for (;;)
  11757. {
  11758. if (att->name.equalsIgnoreCase (attributeName))
  11759. {
  11760. att->value = value;
  11761. break;
  11762. }
  11763. else if (att->next == 0)
  11764. {
  11765. att->next = new XmlAttributeNode (attributeName, value);
  11766. break;
  11767. }
  11768. att = att->next;
  11769. }
  11770. }
  11771. }
  11772. void XmlElement::setAttribute (const String& attributeName,
  11773. const int number) throw()
  11774. {
  11775. setAttribute (attributeName, String (number));
  11776. }
  11777. void XmlElement::setAttribute (const String& attributeName,
  11778. const double number) throw()
  11779. {
  11780. setAttribute (attributeName, String (number));
  11781. }
  11782. void XmlElement::removeAttribute (const String& attributeName) throw()
  11783. {
  11784. XmlAttributeNode* att = attributes;
  11785. XmlAttributeNode* lastAtt = 0;
  11786. while (att != 0)
  11787. {
  11788. if (att->name.equalsIgnoreCase (attributeName))
  11789. {
  11790. if (lastAtt == 0)
  11791. attributes = att->next;
  11792. else
  11793. lastAtt->next = att->next;
  11794. delete att;
  11795. break;
  11796. }
  11797. lastAtt = att;
  11798. att = att->next;
  11799. }
  11800. }
  11801. void XmlElement::removeAllAttributes() throw()
  11802. {
  11803. while (attributes != 0)
  11804. {
  11805. XmlAttributeNode* const nextAtt = attributes->next;
  11806. delete attributes;
  11807. attributes = nextAtt;
  11808. }
  11809. }
  11810. int XmlElement::getNumChildElements() const throw()
  11811. {
  11812. int count = 0;
  11813. const XmlElement* child = firstChildElement;
  11814. while (child != 0)
  11815. {
  11816. ++count;
  11817. child = child->nextElement;
  11818. }
  11819. return count;
  11820. }
  11821. XmlElement* XmlElement::getChildElement (const int index) const throw()
  11822. {
  11823. int count = 0;
  11824. XmlElement* child = firstChildElement;
  11825. while (child != 0 && count < index)
  11826. {
  11827. child = child->nextElement;
  11828. ++count;
  11829. }
  11830. return child;
  11831. }
  11832. XmlElement* XmlElement::getChildByName (const String& childName) const throw()
  11833. {
  11834. XmlElement* child = firstChildElement;
  11835. while (child != 0)
  11836. {
  11837. if (child->hasTagName (childName))
  11838. break;
  11839. child = child->nextElement;
  11840. }
  11841. return child;
  11842. }
  11843. void XmlElement::addChildElement (XmlElement* const newNode) throw()
  11844. {
  11845. if (newNode != 0)
  11846. {
  11847. if (firstChildElement == 0)
  11848. {
  11849. firstChildElement = newNode;
  11850. }
  11851. else
  11852. {
  11853. XmlElement* child = firstChildElement;
  11854. while (child->nextElement != 0)
  11855. child = child->nextElement;
  11856. child->nextElement = newNode;
  11857. // if this is non-zero, then something's probably
  11858. // gone wrong..
  11859. jassert (newNode->nextElement == 0);
  11860. }
  11861. }
  11862. }
  11863. void XmlElement::insertChildElement (XmlElement* const newNode,
  11864. int indexToInsertAt) throw()
  11865. {
  11866. if (newNode != 0)
  11867. {
  11868. removeChildElement (newNode, false);
  11869. if (indexToInsertAt == 0)
  11870. {
  11871. newNode->nextElement = firstChildElement;
  11872. firstChildElement = newNode;
  11873. }
  11874. else
  11875. {
  11876. if (firstChildElement == 0)
  11877. {
  11878. firstChildElement = newNode;
  11879. }
  11880. else
  11881. {
  11882. if (indexToInsertAt < 0)
  11883. indexToInsertAt = std::numeric_limits<int>::max();
  11884. XmlElement* child = firstChildElement;
  11885. while (child->nextElement != 0 && --indexToInsertAt > 0)
  11886. child = child->nextElement;
  11887. newNode->nextElement = child->nextElement;
  11888. child->nextElement = newNode;
  11889. }
  11890. }
  11891. }
  11892. }
  11893. XmlElement* XmlElement::createNewChildElement (const String& tagName)
  11894. {
  11895. XmlElement* const newElement = new XmlElement (tagName);
  11896. addChildElement (newElement);
  11897. return newElement;
  11898. }
  11899. bool XmlElement::replaceChildElement (XmlElement* const currentChildElement,
  11900. XmlElement* const newNode) throw()
  11901. {
  11902. if (newNode != 0)
  11903. {
  11904. XmlElement* child = firstChildElement;
  11905. XmlElement* previousNode = 0;
  11906. while (child != 0)
  11907. {
  11908. if (child == currentChildElement)
  11909. {
  11910. if (child != newNode)
  11911. {
  11912. if (previousNode == 0)
  11913. firstChildElement = newNode;
  11914. else
  11915. previousNode->nextElement = newNode;
  11916. newNode->nextElement = child->nextElement;
  11917. delete child;
  11918. }
  11919. return true;
  11920. }
  11921. previousNode = child;
  11922. child = child->nextElement;
  11923. }
  11924. }
  11925. return false;
  11926. }
  11927. void XmlElement::removeChildElement (XmlElement* const childToRemove,
  11928. const bool shouldDeleteTheChild) throw()
  11929. {
  11930. if (childToRemove != 0)
  11931. {
  11932. if (firstChildElement == childToRemove)
  11933. {
  11934. firstChildElement = childToRemove->nextElement;
  11935. childToRemove->nextElement = 0;
  11936. }
  11937. else
  11938. {
  11939. XmlElement* child = firstChildElement;
  11940. XmlElement* last = 0;
  11941. while (child != 0)
  11942. {
  11943. if (child == childToRemove)
  11944. {
  11945. if (last == 0)
  11946. firstChildElement = child->nextElement;
  11947. else
  11948. last->nextElement = child->nextElement;
  11949. childToRemove->nextElement = 0;
  11950. break;
  11951. }
  11952. last = child;
  11953. child = child->nextElement;
  11954. }
  11955. }
  11956. if (shouldDeleteTheChild)
  11957. delete childToRemove;
  11958. }
  11959. }
  11960. bool XmlElement::isEquivalentTo (const XmlElement* const other,
  11961. const bool ignoreOrderOfAttributes) const throw()
  11962. {
  11963. if (this != other)
  11964. {
  11965. if (other == 0 || tagName != other->tagName)
  11966. {
  11967. return false;
  11968. }
  11969. if (ignoreOrderOfAttributes)
  11970. {
  11971. int totalAtts = 0;
  11972. const XmlAttributeNode* att = attributes;
  11973. while (att != 0)
  11974. {
  11975. if (! other->compareAttribute (att->name, att->value))
  11976. return false;
  11977. att = att->next;
  11978. ++totalAtts;
  11979. }
  11980. if (totalAtts != other->getNumAttributes())
  11981. return false;
  11982. }
  11983. else
  11984. {
  11985. const XmlAttributeNode* thisAtt = attributes;
  11986. const XmlAttributeNode* otherAtt = other->attributes;
  11987. for (;;)
  11988. {
  11989. if (thisAtt == 0 || otherAtt == 0)
  11990. {
  11991. if (thisAtt == otherAtt) // both 0, so it's a match
  11992. break;
  11993. return false;
  11994. }
  11995. if (thisAtt->name != otherAtt->name
  11996. || thisAtt->value != otherAtt->value)
  11997. {
  11998. return false;
  11999. }
  12000. thisAtt = thisAtt->next;
  12001. otherAtt = otherAtt->next;
  12002. }
  12003. }
  12004. const XmlElement* thisChild = firstChildElement;
  12005. const XmlElement* otherChild = other->firstChildElement;
  12006. for (;;)
  12007. {
  12008. if (thisChild == 0 || otherChild == 0)
  12009. {
  12010. if (thisChild == otherChild) // both 0, so it's a match
  12011. break;
  12012. return false;
  12013. }
  12014. if (! thisChild->isEquivalentTo (otherChild, ignoreOrderOfAttributes))
  12015. return false;
  12016. thisChild = thisChild->nextElement;
  12017. otherChild = otherChild->nextElement;
  12018. }
  12019. }
  12020. return true;
  12021. }
  12022. void XmlElement::deleteAllChildElements() throw()
  12023. {
  12024. while (firstChildElement != 0)
  12025. {
  12026. XmlElement* const nextChild = firstChildElement->nextElement;
  12027. delete firstChildElement;
  12028. firstChildElement = nextChild;
  12029. }
  12030. }
  12031. void XmlElement::deleteAllChildElementsWithTagName (const String& name) throw()
  12032. {
  12033. XmlElement* child = firstChildElement;
  12034. while (child != 0)
  12035. {
  12036. if (child->hasTagName (name))
  12037. {
  12038. XmlElement* const nextChild = child->nextElement;
  12039. removeChildElement (child, true);
  12040. child = nextChild;
  12041. }
  12042. else
  12043. {
  12044. child = child->nextElement;
  12045. }
  12046. }
  12047. }
  12048. bool XmlElement::containsChildElement (const XmlElement* const possibleChild) const throw()
  12049. {
  12050. const XmlElement* child = firstChildElement;
  12051. while (child != 0)
  12052. {
  12053. if (child == possibleChild)
  12054. return true;
  12055. child = child->nextElement;
  12056. }
  12057. return false;
  12058. }
  12059. XmlElement* XmlElement::findParentElementOf (const XmlElement* const elementToLookFor) throw()
  12060. {
  12061. if (this == elementToLookFor || elementToLookFor == 0)
  12062. return 0;
  12063. XmlElement* child = firstChildElement;
  12064. while (child != 0)
  12065. {
  12066. if (elementToLookFor == child)
  12067. return this;
  12068. XmlElement* const found = child->findParentElementOf (elementToLookFor);
  12069. if (found != 0)
  12070. return found;
  12071. child = child->nextElement;
  12072. }
  12073. return 0;
  12074. }
  12075. void XmlElement::getChildElementsAsArray (XmlElement** elems) const throw()
  12076. {
  12077. XmlElement* e = firstChildElement;
  12078. while (e != 0)
  12079. {
  12080. *elems++ = e;
  12081. e = e->nextElement;
  12082. }
  12083. }
  12084. void XmlElement::reorderChildElements (XmlElement** const elems, const int num) throw()
  12085. {
  12086. XmlElement* e = firstChildElement = elems[0];
  12087. for (int i = 1; i < num; ++i)
  12088. {
  12089. e->nextElement = elems[i];
  12090. e = e->nextElement;
  12091. }
  12092. e->nextElement = 0;
  12093. }
  12094. bool XmlElement::isTextElement() const throw()
  12095. {
  12096. return tagName.isEmpty();
  12097. }
  12098. static const tchar* const juce_xmltextContentAttributeName = T("text");
  12099. const String XmlElement::getText() const throw()
  12100. {
  12101. jassert (isTextElement()); // you're trying to get the text from an element that
  12102. // isn't actually a text element.. If this contains text sub-nodes, you
  12103. // probably want to use getAllSubText instead.
  12104. return getStringAttribute (juce_xmltextContentAttributeName);
  12105. }
  12106. void XmlElement::setText (const String& newText) throw()
  12107. {
  12108. if (isTextElement())
  12109. {
  12110. setAttribute (juce_xmltextContentAttributeName, newText);
  12111. }
  12112. else
  12113. {
  12114. jassertfalse // you can only change the text in a text element, not a normal one.
  12115. }
  12116. }
  12117. const String XmlElement::getAllSubText() const throw()
  12118. {
  12119. String result;
  12120. String::Concatenator concatenator (result);
  12121. const XmlElement* child = firstChildElement;
  12122. while (child != 0)
  12123. {
  12124. if (child->isTextElement())
  12125. concatenator.append (child->getText());
  12126. child = child->nextElement;
  12127. }
  12128. return result;
  12129. }
  12130. const String XmlElement::getChildElementAllSubText (const String& childTagName,
  12131. const String& defaultReturnValue) const throw()
  12132. {
  12133. const XmlElement* const child = getChildByName (childTagName);
  12134. if (child != 0)
  12135. return child->getAllSubText();
  12136. return defaultReturnValue;
  12137. }
  12138. XmlElement* XmlElement::createTextElement (const String& text) throw()
  12139. {
  12140. XmlElement* const e = new XmlElement ((int) 0);
  12141. e->setAttribute (juce_xmltextContentAttributeName, text);
  12142. return e;
  12143. }
  12144. void XmlElement::addTextElement (const String& text) throw()
  12145. {
  12146. addChildElement (createTextElement (text));
  12147. }
  12148. void XmlElement::deleteAllTextElements() throw()
  12149. {
  12150. XmlElement* child = firstChildElement;
  12151. while (child != 0)
  12152. {
  12153. XmlElement* const next = child->nextElement;
  12154. if (child->isTextElement())
  12155. removeChildElement (child, true);
  12156. child = next;
  12157. }
  12158. }
  12159. END_JUCE_NAMESPACE
  12160. /*** End of inlined file: juce_XmlElement.cpp ***/
  12161. /*** Start of inlined file: juce_InterProcessLock.cpp ***/
  12162. BEGIN_JUCE_NAMESPACE
  12163. // (implemented in the platform-specific code files)
  12164. END_JUCE_NAMESPACE
  12165. /*** End of inlined file: juce_InterProcessLock.cpp ***/
  12166. /*** Start of inlined file: juce_ReadWriteLock.cpp ***/
  12167. BEGIN_JUCE_NAMESPACE
  12168. ReadWriteLock::ReadWriteLock() throw()
  12169. : numWaitingWriters (0),
  12170. numWriters (0),
  12171. writerThreadId (0)
  12172. {
  12173. }
  12174. ReadWriteLock::~ReadWriteLock() throw()
  12175. {
  12176. jassert (readerThreads.size() == 0);
  12177. jassert (numWriters == 0);
  12178. }
  12179. void ReadWriteLock::enterRead() const throw()
  12180. {
  12181. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12182. const ScopedLock sl (accessLock);
  12183. for (;;)
  12184. {
  12185. jassert (readerThreads.size() % 2 == 0);
  12186. int i;
  12187. for (i = 0; i < readerThreads.size(); i += 2)
  12188. if (readerThreads.getUnchecked(i) == threadId)
  12189. break;
  12190. if (i < readerThreads.size()
  12191. || numWriters + numWaitingWriters == 0
  12192. || (threadId == writerThreadId && numWriters > 0))
  12193. {
  12194. if (i < readerThreads.size())
  12195. {
  12196. readerThreads.set (i + 1, (Thread::ThreadID) (1 + (pointer_sized_int) readerThreads.getUnchecked (i + 1)));
  12197. }
  12198. else
  12199. {
  12200. readerThreads.add (threadId);
  12201. readerThreads.add ((Thread::ThreadID) 1);
  12202. }
  12203. return;
  12204. }
  12205. const ScopedUnlock ul (accessLock);
  12206. waitEvent.wait (100);
  12207. }
  12208. }
  12209. void ReadWriteLock::exitRead() const throw()
  12210. {
  12211. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12212. const ScopedLock sl (accessLock);
  12213. for (int i = 0; i < readerThreads.size(); i += 2)
  12214. {
  12215. if (readerThreads.getUnchecked(i) == threadId)
  12216. {
  12217. const pointer_sized_int newCount = ((pointer_sized_int) readerThreads.getUnchecked (i + 1)) - 1;
  12218. if (newCount == 0)
  12219. {
  12220. readerThreads.removeRange (i, 2);
  12221. waitEvent.signal();
  12222. }
  12223. else
  12224. {
  12225. readerThreads.set (i + 1, (Thread::ThreadID) newCount);
  12226. }
  12227. return;
  12228. }
  12229. }
  12230. jassertfalse // unlocking a lock that wasn't locked..
  12231. }
  12232. void ReadWriteLock::enterWrite() const throw()
  12233. {
  12234. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12235. const ScopedLock sl (accessLock);
  12236. for (;;)
  12237. {
  12238. if (readerThreads.size() + numWriters == 0
  12239. || threadId == writerThreadId
  12240. || (readerThreads.size() == 2
  12241. && readerThreads.getUnchecked(0) == threadId))
  12242. {
  12243. writerThreadId = threadId;
  12244. ++numWriters;
  12245. break;
  12246. }
  12247. ++numWaitingWriters;
  12248. accessLock.exit();
  12249. waitEvent.wait (100);
  12250. accessLock.enter();
  12251. --numWaitingWriters;
  12252. }
  12253. }
  12254. bool ReadWriteLock::tryEnterWrite() const throw()
  12255. {
  12256. const Thread::ThreadID threadId = Thread::getCurrentThreadId();
  12257. const ScopedLock sl (accessLock);
  12258. if (readerThreads.size() + numWriters == 0
  12259. || threadId == writerThreadId
  12260. || (readerThreads.size() == 2
  12261. && readerThreads.getUnchecked(0) == threadId))
  12262. {
  12263. writerThreadId = threadId;
  12264. ++numWriters;
  12265. return true;
  12266. }
  12267. return false;
  12268. }
  12269. void ReadWriteLock::exitWrite() const throw()
  12270. {
  12271. const ScopedLock sl (accessLock);
  12272. // check this thread actually had the lock..
  12273. jassert (numWriters > 0 && writerThreadId == Thread::getCurrentThreadId());
  12274. if (--numWriters == 0)
  12275. {
  12276. writerThreadId = 0;
  12277. waitEvent.signal();
  12278. }
  12279. }
  12280. END_JUCE_NAMESPACE
  12281. /*** End of inlined file: juce_ReadWriteLock.cpp ***/
  12282. /*** Start of inlined file: juce_Thread.cpp ***/
  12283. BEGIN_JUCE_NAMESPACE
  12284. // these functions are implemented in the platform-specific code.
  12285. void* juce_createThread (void* userData);
  12286. void juce_killThread (void* handle);
  12287. bool juce_setThreadPriority (void* handle, int priority);
  12288. void juce_setCurrentThreadName (const String& name);
  12289. #if JUCE_WIN32
  12290. void juce_CloseThreadHandle (void* handle);
  12291. #endif
  12292. void Thread::threadEntryPoint (Thread* const thread)
  12293. {
  12294. {
  12295. const ScopedLock sl (runningThreadsLock);
  12296. runningThreads.add (thread);
  12297. }
  12298. JUCE_TRY
  12299. {
  12300. thread->threadId_ = Thread::getCurrentThreadId();
  12301. if (thread->threadName_.isNotEmpty())
  12302. juce_setCurrentThreadName (thread->threadName_);
  12303. if (thread->startSuspensionEvent_.wait (10000))
  12304. {
  12305. if (thread->affinityMask_ != 0)
  12306. setCurrentThreadAffinityMask (thread->affinityMask_);
  12307. thread->run();
  12308. }
  12309. }
  12310. JUCE_CATCH_ALL_ASSERT
  12311. {
  12312. const ScopedLock sl (runningThreadsLock);
  12313. jassert (runningThreads.contains (thread));
  12314. runningThreads.removeValue (thread);
  12315. }
  12316. #if JUCE_WIN32
  12317. juce_CloseThreadHandle (thread->threadHandle_);
  12318. #endif
  12319. thread->threadHandle_ = 0;
  12320. thread->threadId_ = 0;
  12321. }
  12322. // used to wrap the incoming call from the platform-specific code
  12323. void JUCE_API juce_threadEntryPoint (void* userData)
  12324. {
  12325. Thread::threadEntryPoint ((Thread*) userData);
  12326. }
  12327. Thread::Thread (const String& threadName)
  12328. : threadName_ (threadName),
  12329. threadHandle_ (0),
  12330. threadPriority_ (5),
  12331. threadId_ (0),
  12332. affinityMask_ (0),
  12333. threadShouldExit_ (false)
  12334. {
  12335. }
  12336. Thread::~Thread()
  12337. {
  12338. stopThread (100);
  12339. }
  12340. void Thread::startThread()
  12341. {
  12342. const ScopedLock sl (startStopLock);
  12343. threadShouldExit_ = false;
  12344. if (threadHandle_ == 0)
  12345. {
  12346. threadHandle_ = juce_createThread ((void*) this);
  12347. juce_setThreadPriority (threadHandle_, threadPriority_);
  12348. startSuspensionEvent_.signal();
  12349. }
  12350. }
  12351. void Thread::startThread (const int priority)
  12352. {
  12353. const ScopedLock sl (startStopLock);
  12354. if (threadHandle_ == 0)
  12355. {
  12356. threadPriority_ = priority;
  12357. startThread();
  12358. }
  12359. else
  12360. {
  12361. setPriority (priority);
  12362. }
  12363. }
  12364. bool Thread::isThreadRunning() const
  12365. {
  12366. return threadHandle_ != 0;
  12367. }
  12368. void Thread::signalThreadShouldExit()
  12369. {
  12370. threadShouldExit_ = true;
  12371. }
  12372. bool Thread::waitForThreadToExit (const int timeOutMilliseconds) const
  12373. {
  12374. // Doh! So how exactly do you expect this thread to wait for itself to stop??
  12375. jassert (getThreadId() != getCurrentThreadId());
  12376. const int sleepMsPerIteration = 5;
  12377. int count = timeOutMilliseconds / sleepMsPerIteration;
  12378. while (isThreadRunning())
  12379. {
  12380. if (timeOutMilliseconds > 0 && --count < 0)
  12381. return false;
  12382. sleep (sleepMsPerIteration);
  12383. }
  12384. return true;
  12385. }
  12386. void Thread::stopThread (const int timeOutMilliseconds)
  12387. {
  12388. // agh! You can't stop the thread that's calling this method! How on earth
  12389. // would that work??
  12390. jassert (getCurrentThreadId() != getThreadId());
  12391. const ScopedLock sl (startStopLock);
  12392. if (isThreadRunning())
  12393. {
  12394. signalThreadShouldExit();
  12395. notify();
  12396. if (timeOutMilliseconds != 0)
  12397. waitForThreadToExit (timeOutMilliseconds);
  12398. if (isThreadRunning())
  12399. {
  12400. // very bad karma if this point is reached, as
  12401. // there are bound to be locks and events left in
  12402. // silly states when a thread is killed by force..
  12403. jassertfalse
  12404. Logger::writeToLog ("!! killing thread by force !!");
  12405. juce_killThread (threadHandle_);
  12406. threadHandle_ = 0;
  12407. threadId_ = 0;
  12408. const ScopedLock sl2 (runningThreadsLock);
  12409. runningThreads.removeValue (this);
  12410. }
  12411. }
  12412. }
  12413. bool Thread::setPriority (const int priority)
  12414. {
  12415. const ScopedLock sl (startStopLock);
  12416. const bool worked = juce_setThreadPriority (threadHandle_, priority);
  12417. if (worked)
  12418. threadPriority_ = priority;
  12419. return worked;
  12420. }
  12421. bool Thread::setCurrentThreadPriority (const int priority)
  12422. {
  12423. return juce_setThreadPriority (0, priority);
  12424. }
  12425. void Thread::setAffinityMask (const uint32 affinityMask)
  12426. {
  12427. affinityMask_ = affinityMask;
  12428. }
  12429. bool Thread::wait (const int timeOutMilliseconds) const
  12430. {
  12431. return defaultEvent_.wait (timeOutMilliseconds);
  12432. }
  12433. void Thread::notify() const
  12434. {
  12435. defaultEvent_.signal();
  12436. }
  12437. int Thread::getNumRunningThreads()
  12438. {
  12439. return runningThreads.size();
  12440. }
  12441. Thread* Thread::getCurrentThread()
  12442. {
  12443. const ThreadID thisId = getCurrentThreadId();
  12444. const ScopedLock sl (runningThreadsLock);
  12445. for (int i = runningThreads.size(); --i >= 0;)
  12446. {
  12447. Thread* const t = runningThreads.getUnchecked(i);
  12448. if (t->threadId_ == thisId)
  12449. return t;
  12450. }
  12451. return 0;
  12452. }
  12453. void Thread::stopAllThreads (const int timeOutMilliseconds)
  12454. {
  12455. {
  12456. const ScopedLock sl (runningThreadsLock);
  12457. for (int i = runningThreads.size(); --i >= 0;)
  12458. runningThreads.getUnchecked(i)->signalThreadShouldExit();
  12459. }
  12460. for (;;)
  12461. {
  12462. Thread* firstThread;
  12463. {
  12464. const ScopedLock sl (runningThreadsLock);
  12465. firstThread = runningThreads.getFirst();
  12466. }
  12467. if (firstThread == 0)
  12468. break;
  12469. firstThread->stopThread (timeOutMilliseconds);
  12470. }
  12471. }
  12472. Array<Thread*> Thread::runningThreads;
  12473. CriticalSection Thread::runningThreadsLock;
  12474. END_JUCE_NAMESPACE
  12475. /*** End of inlined file: juce_Thread.cpp ***/
  12476. /*** Start of inlined file: juce_ThreadPool.cpp ***/
  12477. BEGIN_JUCE_NAMESPACE
  12478. ThreadPoolJob::ThreadPoolJob (const String& name)
  12479. : jobName (name),
  12480. pool (0),
  12481. shouldStop (false),
  12482. isActive (false),
  12483. shouldBeDeleted (false)
  12484. {
  12485. }
  12486. ThreadPoolJob::~ThreadPoolJob()
  12487. {
  12488. // you mustn't delete a job while it's still in a pool! Use ThreadPool::removeJob()
  12489. // to remove it first!
  12490. jassert (pool == 0 || ! pool->contains (this));
  12491. }
  12492. const String ThreadPoolJob::getJobName() const
  12493. {
  12494. return jobName;
  12495. }
  12496. void ThreadPoolJob::setJobName (const String& newName)
  12497. {
  12498. jobName = newName;
  12499. }
  12500. void ThreadPoolJob::signalJobShouldExit()
  12501. {
  12502. shouldStop = true;
  12503. }
  12504. class ThreadPool::ThreadPoolThread : public Thread
  12505. {
  12506. public:
  12507. ThreadPoolThread (ThreadPool& pool_)
  12508. : Thread (T("Pool")),
  12509. pool (pool_),
  12510. busy (false)
  12511. {
  12512. }
  12513. ~ThreadPoolThread()
  12514. {
  12515. }
  12516. void run()
  12517. {
  12518. while (! threadShouldExit())
  12519. {
  12520. if (! pool.runNextJob())
  12521. wait (500);
  12522. }
  12523. }
  12524. private:
  12525. ThreadPool& pool;
  12526. bool volatile busy;
  12527. ThreadPoolThread (const ThreadPoolThread&);
  12528. ThreadPoolThread& operator= (const ThreadPoolThread&);
  12529. };
  12530. ThreadPool::ThreadPool (const int numThreads,
  12531. const bool startThreadsOnlyWhenNeeded,
  12532. const int stopThreadsWhenNotUsedTimeoutMs)
  12533. : threadStopTimeout (stopThreadsWhenNotUsedTimeoutMs),
  12534. priority (5)
  12535. {
  12536. jassert (numThreads > 0); // not much point having one of these with no threads in it.
  12537. for (int i = jmax (1, numThreads); --i >= 0;)
  12538. threads.add (new ThreadPoolThread (*this));
  12539. if (! startThreadsOnlyWhenNeeded)
  12540. for (int i = threads.size(); --i >= 0;)
  12541. threads.getUnchecked(i)->startThread (priority);
  12542. }
  12543. ThreadPool::~ThreadPool()
  12544. {
  12545. removeAllJobs (true, 4000);
  12546. int i;
  12547. for (i = threads.size(); --i >= 0;)
  12548. threads.getUnchecked(i)->signalThreadShouldExit();
  12549. for (i = threads.size(); --i >= 0;)
  12550. threads.getUnchecked(i)->stopThread (500);
  12551. }
  12552. void ThreadPool::addJob (ThreadPoolJob* const job)
  12553. {
  12554. jassert (job != 0);
  12555. jassert (job->pool == 0);
  12556. if (job->pool == 0)
  12557. {
  12558. job->pool = this;
  12559. job->shouldStop = false;
  12560. job->isActive = false;
  12561. {
  12562. const ScopedLock sl (lock);
  12563. jobs.add (job);
  12564. int numRunning = 0;
  12565. for (int i = threads.size(); --i >= 0;)
  12566. if (threads.getUnchecked(i)->isThreadRunning() && ! threads.getUnchecked(i)->threadShouldExit())
  12567. ++numRunning;
  12568. if (numRunning < threads.size())
  12569. {
  12570. bool startedOne = false;
  12571. int n = 1000;
  12572. while (--n >= 0 && ! startedOne)
  12573. {
  12574. for (int i = threads.size(); --i >= 0;)
  12575. {
  12576. if (! threads.getUnchecked(i)->isThreadRunning())
  12577. {
  12578. threads.getUnchecked(i)->startThread (priority);
  12579. startedOne = true;
  12580. break;
  12581. }
  12582. }
  12583. if (! startedOne)
  12584. Thread::sleep (2);
  12585. }
  12586. }
  12587. }
  12588. for (int i = threads.size(); --i >= 0;)
  12589. threads.getUnchecked(i)->notify();
  12590. }
  12591. }
  12592. int ThreadPool::getNumJobs() const
  12593. {
  12594. return jobs.size();
  12595. }
  12596. ThreadPoolJob* ThreadPool::getJob (const int index) const
  12597. {
  12598. const ScopedLock sl (lock);
  12599. return (ThreadPoolJob*) jobs [index];
  12600. }
  12601. bool ThreadPool::contains (const ThreadPoolJob* const job) const
  12602. {
  12603. const ScopedLock sl (lock);
  12604. return jobs.contains (const_cast <ThreadPoolJob*> (job));
  12605. }
  12606. bool ThreadPool::isJobRunning (const ThreadPoolJob* const job) const
  12607. {
  12608. const ScopedLock sl (lock);
  12609. return jobs.contains (const_cast <ThreadPoolJob*> (job)) && job->isActive;
  12610. }
  12611. bool ThreadPool::waitForJobToFinish (const ThreadPoolJob* const job,
  12612. const int timeOutMs) const
  12613. {
  12614. if (job != 0)
  12615. {
  12616. const uint32 start = Time::getMillisecondCounter();
  12617. while (contains (job))
  12618. {
  12619. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12620. return false;
  12621. jobFinishedSignal.wait (2);
  12622. }
  12623. }
  12624. return true;
  12625. }
  12626. bool ThreadPool::removeJob (ThreadPoolJob* const job,
  12627. const bool interruptIfRunning,
  12628. const int timeOutMs)
  12629. {
  12630. bool dontWait = true;
  12631. if (job != 0)
  12632. {
  12633. const ScopedLock sl (lock);
  12634. if (jobs.contains (job))
  12635. {
  12636. if (job->isActive)
  12637. {
  12638. if (interruptIfRunning)
  12639. job->signalJobShouldExit();
  12640. dontWait = false;
  12641. }
  12642. else
  12643. {
  12644. jobs.removeValue (job);
  12645. }
  12646. }
  12647. }
  12648. return dontWait || waitForJobToFinish (job, timeOutMs);
  12649. }
  12650. bool ThreadPool::removeAllJobs (const bool interruptRunningJobs,
  12651. const int timeOutMs,
  12652. const bool deleteInactiveJobs,
  12653. ThreadPool::JobSelector* selectedJobsToRemove)
  12654. {
  12655. Array <ThreadPoolJob*> jobsToWaitFor;
  12656. {
  12657. const ScopedLock sl (lock);
  12658. for (int i = jobs.size(); --i >= 0;)
  12659. {
  12660. ThreadPoolJob* const job = jobs.getUnchecked(i);
  12661. if (selectedJobsToRemove == 0 || selectedJobsToRemove->isJobSuitable (job))
  12662. {
  12663. if (job->isActive)
  12664. {
  12665. jobsToWaitFor.add (job);
  12666. if (interruptRunningJobs)
  12667. job->signalJobShouldExit();
  12668. }
  12669. else
  12670. {
  12671. jobs.remove (i);
  12672. if (deleteInactiveJobs)
  12673. delete job;
  12674. }
  12675. }
  12676. }
  12677. }
  12678. const uint32 start = Time::getMillisecondCounter();
  12679. for (;;)
  12680. {
  12681. for (int i = jobsToWaitFor.size(); --i >= 0;)
  12682. if (! isJobRunning (jobsToWaitFor.getUnchecked (i)))
  12683. jobsToWaitFor.remove (i);
  12684. if (jobsToWaitFor.size() == 0)
  12685. break;
  12686. if (timeOutMs >= 0 && Time::getMillisecondCounter() >= start + timeOutMs)
  12687. return false;
  12688. jobFinishedSignal.wait (20);
  12689. }
  12690. return true;
  12691. }
  12692. const StringArray ThreadPool::getNamesOfAllJobs (const bool onlyReturnActiveJobs) const
  12693. {
  12694. StringArray s;
  12695. const ScopedLock sl (lock);
  12696. for (int i = 0; i < jobs.size(); ++i)
  12697. {
  12698. const ThreadPoolJob* const job = jobs.getUnchecked(i);
  12699. if (job->isActive || ! onlyReturnActiveJobs)
  12700. s.add (job->getJobName());
  12701. }
  12702. return s;
  12703. }
  12704. bool ThreadPool::setThreadPriorities (const int newPriority)
  12705. {
  12706. bool ok = true;
  12707. if (priority != newPriority)
  12708. {
  12709. priority = newPriority;
  12710. for (int i = threads.size(); --i >= 0;)
  12711. if (! threads.getUnchecked(i)->setPriority (newPriority))
  12712. ok = false;
  12713. }
  12714. return ok;
  12715. }
  12716. bool ThreadPool::runNextJob()
  12717. {
  12718. ThreadPoolJob* job = 0;
  12719. {
  12720. const ScopedLock sl (lock);
  12721. for (int i = 0; i < jobs.size(); ++i)
  12722. {
  12723. job = jobs[i];
  12724. if (job != 0 && ! (job->isActive || job->shouldStop))
  12725. break;
  12726. job = 0;
  12727. }
  12728. if (job != 0)
  12729. job->isActive = true;
  12730. }
  12731. if (job != 0)
  12732. {
  12733. JUCE_TRY
  12734. {
  12735. ThreadPoolJob::JobStatus result = job->runJob();
  12736. lastJobEndTime = Time::getApproximateMillisecondCounter();
  12737. const ScopedLock sl (lock);
  12738. if (jobs.contains (job))
  12739. {
  12740. job->isActive = false;
  12741. if (result != ThreadPoolJob::jobNeedsRunningAgain || job->shouldStop)
  12742. {
  12743. job->pool = 0;
  12744. job->shouldStop = true;
  12745. jobs.removeValue (job);
  12746. if (result == ThreadPoolJob::jobHasFinishedAndShouldBeDeleted)
  12747. delete job;
  12748. jobFinishedSignal.signal();
  12749. }
  12750. else
  12751. {
  12752. // move the job to the end of the queue if it wants another go
  12753. jobs.move (jobs.indexOf (job), -1);
  12754. }
  12755. }
  12756. }
  12757. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  12758. catch (...)
  12759. {
  12760. const ScopedLock sl (lock);
  12761. jobs.removeValue (job);
  12762. }
  12763. #endif
  12764. }
  12765. else
  12766. {
  12767. if (threadStopTimeout > 0
  12768. && Time::getApproximateMillisecondCounter() > lastJobEndTime + threadStopTimeout)
  12769. {
  12770. const ScopedLock sl (lock);
  12771. if (jobs.size() == 0)
  12772. for (int i = threads.size(); --i >= 0;)
  12773. threads.getUnchecked(i)->signalThreadShouldExit();
  12774. }
  12775. else
  12776. {
  12777. return false;
  12778. }
  12779. }
  12780. return true;
  12781. }
  12782. END_JUCE_NAMESPACE
  12783. /*** End of inlined file: juce_ThreadPool.cpp ***/
  12784. /*** Start of inlined file: juce_TimeSliceThread.cpp ***/
  12785. BEGIN_JUCE_NAMESPACE
  12786. TimeSliceThread::TimeSliceThread (const String& threadName)
  12787. : Thread (threadName),
  12788. index (0),
  12789. clientBeingCalled (0),
  12790. clientsChanged (false)
  12791. {
  12792. }
  12793. TimeSliceThread::~TimeSliceThread()
  12794. {
  12795. stopThread (2000);
  12796. }
  12797. void TimeSliceThread::addTimeSliceClient (TimeSliceClient* const client)
  12798. {
  12799. const ScopedLock sl (listLock);
  12800. clients.addIfNotAlreadyThere (client);
  12801. clientsChanged = true;
  12802. notify();
  12803. }
  12804. void TimeSliceThread::removeTimeSliceClient (TimeSliceClient* const client)
  12805. {
  12806. const ScopedLock sl1 (listLock);
  12807. clientsChanged = true;
  12808. // if there's a chance we're in the middle of calling this client, we need to
  12809. // also lock the outer lock..
  12810. if (clientBeingCalled == client)
  12811. {
  12812. const ScopedUnlock ul (listLock); // unlock first to get the order right..
  12813. const ScopedLock sl2 (callbackLock);
  12814. const ScopedLock sl3 (listLock);
  12815. clients.removeValue (client);
  12816. }
  12817. else
  12818. {
  12819. clients.removeValue (client);
  12820. }
  12821. }
  12822. int TimeSliceThread::getNumClients() const
  12823. {
  12824. return clients.size();
  12825. }
  12826. TimeSliceClient* TimeSliceThread::getClient (const int i) const
  12827. {
  12828. const ScopedLock sl (listLock);
  12829. return clients [i];
  12830. }
  12831. void TimeSliceThread::run()
  12832. {
  12833. int numCallsSinceBusy = 0;
  12834. while (! threadShouldExit())
  12835. {
  12836. int timeToWait = 500;
  12837. {
  12838. const ScopedLock sl (callbackLock);
  12839. {
  12840. const ScopedLock sl2 (listLock);
  12841. if (clients.size() > 0)
  12842. {
  12843. index = (index + 1) % clients.size();
  12844. clientBeingCalled = clients [index];
  12845. }
  12846. else
  12847. {
  12848. index = 0;
  12849. clientBeingCalled = 0;
  12850. }
  12851. if (clientsChanged)
  12852. {
  12853. clientsChanged = false;
  12854. numCallsSinceBusy = 0;
  12855. }
  12856. }
  12857. if (clientBeingCalled != 0)
  12858. {
  12859. if (clientBeingCalled->useTimeSlice())
  12860. numCallsSinceBusy = 0;
  12861. else
  12862. ++numCallsSinceBusy;
  12863. if (numCallsSinceBusy >= clients.size())
  12864. timeToWait = 500;
  12865. else if (index == 0)
  12866. timeToWait = 1; // throw in an occasional pause, to stop everything locking up
  12867. else
  12868. timeToWait = 0;
  12869. }
  12870. }
  12871. if (timeToWait > 0)
  12872. wait (timeToWait);
  12873. }
  12874. }
  12875. END_JUCE_NAMESPACE
  12876. /*** End of inlined file: juce_TimeSliceThread.cpp ***/
  12877. #endif
  12878. #if JUCE_BUILD_MISC
  12879. /*** Start of inlined file: juce_ValueTree.cpp ***/
  12880. BEGIN_JUCE_NAMESPACE
  12881. class ValueTreeSetPropertyAction : public UndoableAction
  12882. {
  12883. public:
  12884. ValueTreeSetPropertyAction (const ValueTree::SharedObjectPtr& target_, const var::identifier& name_,
  12885. const var& newValue_, const bool isAddingNewProperty_, const bool isDeletingProperty_)
  12886. : target (target_), name (name_), newValue (newValue_),
  12887. isAddingNewProperty (isAddingNewProperty_),
  12888. isDeletingProperty (isDeletingProperty_)
  12889. {
  12890. if (! isAddingNewProperty)
  12891. oldValue = target_->getProperty (name_);
  12892. }
  12893. ~ValueTreeSetPropertyAction() {}
  12894. bool perform()
  12895. {
  12896. jassert (! (isAddingNewProperty && target->hasProperty (name)));
  12897. if (isDeletingProperty)
  12898. target->removeProperty (name, 0);
  12899. else
  12900. target->setProperty (name, newValue, 0);
  12901. return true;
  12902. }
  12903. bool undo()
  12904. {
  12905. if (isAddingNewProperty)
  12906. target->removeProperty (name, 0);
  12907. else
  12908. target->setProperty (name, oldValue, 0);
  12909. return true;
  12910. }
  12911. int getSizeInUnits()
  12912. {
  12913. return (int) sizeof (*this); //xxx should be more accurate
  12914. }
  12915. private:
  12916. const ValueTree::SharedObjectPtr target;
  12917. const var::identifier name;
  12918. const var newValue;
  12919. var oldValue;
  12920. const bool isAddingNewProperty, isDeletingProperty;
  12921. ValueTreeSetPropertyAction (const ValueTreeSetPropertyAction&);
  12922. ValueTreeSetPropertyAction& operator= (const ValueTreeSetPropertyAction&);
  12923. };
  12924. class ValueTreeChildChangeAction : public UndoableAction
  12925. {
  12926. public:
  12927. ValueTreeChildChangeAction (const ValueTree::SharedObjectPtr& target_, const int childIndex_,
  12928. const ValueTree::SharedObjectPtr& newChild_)
  12929. : target (target_),
  12930. child (newChild_ != 0 ? newChild_ : target_->children [childIndex_]),
  12931. childIndex (childIndex_),
  12932. isDeleting (newChild_ == 0)
  12933. {
  12934. jassert (child != 0);
  12935. }
  12936. ~ValueTreeChildChangeAction() {}
  12937. bool perform()
  12938. {
  12939. if (isDeleting)
  12940. target->removeChild (childIndex, 0);
  12941. else
  12942. target->addChild (child, childIndex, 0);
  12943. return true;
  12944. }
  12945. bool undo()
  12946. {
  12947. if (isDeleting)
  12948. target->addChild (child, childIndex, 0);
  12949. else
  12950. target->removeChild (childIndex, 0);
  12951. return true;
  12952. }
  12953. int getSizeInUnits()
  12954. {
  12955. return (int) sizeof (*this); //xxx should be more accurate
  12956. }
  12957. private:
  12958. const ValueTree::SharedObjectPtr target, child;
  12959. const int childIndex;
  12960. const bool isDeleting;
  12961. ValueTreeChildChangeAction (const ValueTreeChildChangeAction&);
  12962. ValueTreeChildChangeAction& operator= (const ValueTreeChildChangeAction&);
  12963. };
  12964. ValueTree::SharedObject::SharedObject (const String& type_)
  12965. : type (type_), parent (0)
  12966. {
  12967. }
  12968. ValueTree::SharedObject::SharedObject (const SharedObject& other)
  12969. : type (other.type), properties (other.properties), parent (0)
  12970. {
  12971. for (int i = 0; i < other.children.size(); ++i)
  12972. children.add (new SharedObject (*other.children.getUnchecked(i)));
  12973. }
  12974. ValueTree::SharedObject::~SharedObject()
  12975. {
  12976. jassert (parent == 0); // this should never happen unless something isn't obeying the ref-counting!
  12977. for (int i = children.size(); --i >= 0;)
  12978. {
  12979. const SharedObjectPtr c (children.getUnchecked(i));
  12980. c->parent = 0;
  12981. children.remove (i);
  12982. c->sendParentChangeMessage();
  12983. }
  12984. }
  12985. void ValueTree::deliverPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  12986. {
  12987. for (int i = listeners.size(); --i >= 0;)
  12988. {
  12989. ValueTree::Listener* const l = listeners[i];
  12990. if (l != 0)
  12991. l->valueTreePropertyChanged (tree, property);
  12992. }
  12993. }
  12994. void ValueTree::SharedObject::sendPropertyChangeMessage (ValueTree& tree, const var::identifier& property)
  12995. {
  12996. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  12997. {
  12998. ValueTree* const v = valueTreesWithListeners[i];
  12999. if (v != 0)
  13000. v->deliverPropertyChangeMessage (tree, property);
  13001. }
  13002. }
  13003. void ValueTree::SharedObject::sendPropertyChangeMessage (const var::identifier& property)
  13004. {
  13005. ValueTree tree (this);
  13006. ValueTree::SharedObject* t = this;
  13007. while (t != 0)
  13008. {
  13009. t->sendPropertyChangeMessage (tree, property);
  13010. t = t->parent;
  13011. }
  13012. }
  13013. void ValueTree::deliverChildChangeMessage (ValueTree& tree)
  13014. {
  13015. for (int i = listeners.size(); --i >= 0;)
  13016. {
  13017. ValueTree::Listener* const l = listeners[i];
  13018. if (l != 0)
  13019. l->valueTreeChildrenChanged (tree);
  13020. }
  13021. }
  13022. void ValueTree::SharedObject::sendChildChangeMessage (ValueTree& tree)
  13023. {
  13024. for (int i = valueTreesWithListeners.size(); --i >= 0;)
  13025. {
  13026. ValueTree* const v = valueTreesWithListeners[i];
  13027. if (v != 0)
  13028. v->deliverChildChangeMessage (tree);
  13029. }
  13030. }
  13031. void ValueTree::SharedObject::sendChildChangeMessage()
  13032. {
  13033. ValueTree tree (this);
  13034. ValueTree::SharedObject* t = this;
  13035. while (t != 0)
  13036. {
  13037. t->sendChildChangeMessage (tree);
  13038. t = t->parent;
  13039. }
  13040. }
  13041. void ValueTree::deliverParentChangeMessage (ValueTree& tree)
  13042. {
  13043. for (int i = listeners.size(); --i >= 0;)
  13044. {
  13045. ValueTree::Listener* const l = listeners[i];
  13046. if (l != 0)
  13047. l->valueTreeParentChanged (tree);
  13048. }
  13049. }
  13050. void ValueTree::SharedObject::sendParentChangeMessage()
  13051. {
  13052. ValueTree tree (this);
  13053. int i;
  13054. for (i = children.size(); --i >= 0;)
  13055. {
  13056. SharedObject* const t = children[i];
  13057. if (t != 0)
  13058. t->sendParentChangeMessage();
  13059. }
  13060. for (i = valueTreesWithListeners.size(); --i >= 0;)
  13061. {
  13062. ValueTree* const v = valueTreesWithListeners[i];
  13063. if (v != 0)
  13064. v->deliverParentChangeMessage (tree);
  13065. }
  13066. }
  13067. const var& ValueTree::SharedObject::getProperty (const var::identifier& name) const
  13068. {
  13069. return properties [name];
  13070. }
  13071. void ValueTree::SharedObject::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13072. {
  13073. if (undoManager == 0)
  13074. {
  13075. if (properties.set (name, newValue))
  13076. sendPropertyChangeMessage (name);
  13077. }
  13078. else
  13079. {
  13080. var* const existingValue = properties.getItem (name);
  13081. if (existingValue != 0)
  13082. {
  13083. if (*existingValue != newValue)
  13084. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, false, false));
  13085. }
  13086. else
  13087. {
  13088. undoManager->perform (new ValueTreeSetPropertyAction (this, name, newValue, true, false));
  13089. }
  13090. }
  13091. }
  13092. bool ValueTree::SharedObject::hasProperty (const var::identifier& name) const
  13093. {
  13094. return properties.contains (name);
  13095. }
  13096. void ValueTree::SharedObject::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13097. {
  13098. if (undoManager == 0)
  13099. {
  13100. if (properties.remove (name))
  13101. sendPropertyChangeMessage (name);
  13102. }
  13103. else
  13104. {
  13105. if (properties.contains (name))
  13106. undoManager->perform (new ValueTreeSetPropertyAction (this, name, var::null, false, true));
  13107. }
  13108. }
  13109. void ValueTree::SharedObject::removeAllProperties (UndoManager* const undoManager)
  13110. {
  13111. if (undoManager == 0)
  13112. {
  13113. while (properties.size() > 0)
  13114. {
  13115. const var::identifier name (properties.getName (properties.size() - 1));
  13116. properties.remove (name);
  13117. sendPropertyChangeMessage (name);
  13118. }
  13119. }
  13120. else
  13121. {
  13122. for (int i = properties.size(); --i >= 0;)
  13123. undoManager->perform (new ValueTreeSetPropertyAction (this, properties.getName(i), var::null, false, true));
  13124. }
  13125. }
  13126. ValueTree ValueTree::SharedObject::getChildWithName (const String& typeToMatch) const
  13127. {
  13128. for (int i = 0; i < children.size(); ++i)
  13129. if (children.getUnchecked(i)->type == typeToMatch)
  13130. return (SharedObject*) children.getUnchecked(i);
  13131. return (SharedObject*) 0;
  13132. }
  13133. ValueTree ValueTree::SharedObject::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13134. {
  13135. for (int i = 0; i < children.size(); ++i)
  13136. if (children.getUnchecked(i)->getProperty (propertyName) == propertyValue)
  13137. return (SharedObject*) children.getUnchecked(i);
  13138. return (SharedObject*) 0;
  13139. }
  13140. bool ValueTree::SharedObject::isAChildOf (const SharedObject* const possibleParent) const
  13141. {
  13142. const SharedObject* p = parent;
  13143. while (p != 0)
  13144. {
  13145. if (p == possibleParent)
  13146. return true;
  13147. p = p->parent;
  13148. }
  13149. return false;
  13150. }
  13151. void ValueTree::SharedObject::addChild (SharedObject* child, int index, UndoManager* const undoManager)
  13152. {
  13153. if (child != 0 && child->parent != this)
  13154. {
  13155. if (child != this && ! isAChildOf (child))
  13156. {
  13157. // You should always make sure that a child is removed from its previous parent before
  13158. // adding it somewhere else - otherwise, it's ambiguous as to whether a different
  13159. // undomanager should be used when removing it from its current parent..
  13160. jassert (child->parent == 0);
  13161. if (child->parent != 0)
  13162. {
  13163. jassert (child->parent->children.indexOf (child) >= 0);
  13164. child->parent->removeChild (child->parent->children.indexOf (child), undoManager);
  13165. }
  13166. if (undoManager == 0)
  13167. {
  13168. children.insert (index, child);
  13169. child->parent = this;
  13170. sendChildChangeMessage();
  13171. child->sendParentChangeMessage();
  13172. }
  13173. else
  13174. {
  13175. undoManager->perform (new ValueTreeChildChangeAction (this, index, child));
  13176. }
  13177. }
  13178. else
  13179. {
  13180. // You're attempting to create a recursive loop! A node
  13181. // can't be a child of one of its own children!
  13182. jassertfalse
  13183. }
  13184. }
  13185. }
  13186. void ValueTree::SharedObject::removeChild (const int childIndex, UndoManager* const undoManager)
  13187. {
  13188. const SharedObjectPtr child (children [childIndex]);
  13189. if (child != 0)
  13190. {
  13191. if (undoManager == 0)
  13192. {
  13193. children.remove (childIndex);
  13194. child->parent = 0;
  13195. sendChildChangeMessage();
  13196. child->sendParentChangeMessage();
  13197. }
  13198. else
  13199. {
  13200. undoManager->perform (new ValueTreeChildChangeAction (this, childIndex, 0));
  13201. }
  13202. }
  13203. }
  13204. void ValueTree::SharedObject::removeAllChildren (UndoManager* const undoManager)
  13205. {
  13206. while (children.size() > 0)
  13207. removeChild (children.size() - 1, undoManager);
  13208. }
  13209. ValueTree::ValueTree (const String& type_)
  13210. : object (new ValueTree::SharedObject (type_))
  13211. {
  13212. jassert (type_.isNotEmpty()); // All objects should be given a sensible type name!
  13213. }
  13214. ValueTree::ValueTree (SharedObject* const object_)
  13215. : object (object_)
  13216. {
  13217. }
  13218. ValueTree::ValueTree (const ValueTree& other)
  13219. : object (other.object)
  13220. {
  13221. }
  13222. ValueTree& ValueTree::operator= (const ValueTree& other)
  13223. {
  13224. if (listeners.size() > 0)
  13225. {
  13226. if (object != 0)
  13227. object->valueTreesWithListeners.removeValue (this);
  13228. if (other.object != 0)
  13229. other.object->valueTreesWithListeners.add (this);
  13230. }
  13231. object = other.object;
  13232. return *this;
  13233. }
  13234. ValueTree::~ValueTree()
  13235. {
  13236. if (listeners.size() > 0 && object != 0)
  13237. object->valueTreesWithListeners.removeValue (this);
  13238. }
  13239. bool ValueTree::operator== (const ValueTree& other) const
  13240. {
  13241. return object == other.object;
  13242. }
  13243. bool ValueTree::operator!= (const ValueTree& other) const
  13244. {
  13245. return object != other.object;
  13246. }
  13247. ValueTree ValueTree::createCopy() const
  13248. {
  13249. return ValueTree (object != 0 ? new SharedObject (*object) : 0);
  13250. }
  13251. bool ValueTree::hasType (const String& typeName) const
  13252. {
  13253. return object != 0 && object->type == typeName;
  13254. }
  13255. const String ValueTree::getType() const
  13256. {
  13257. return object != 0 ? object->type : String::empty;
  13258. }
  13259. ValueTree ValueTree::getParent() const
  13260. {
  13261. return object != 0 ? ValueTree (object->parent) : ValueTree ((SharedObject*) 0);
  13262. }
  13263. const var& ValueTree::operator[] (const var::identifier& name) const
  13264. {
  13265. return object == 0 ? var::null : object->getProperty (name);
  13266. }
  13267. const var& ValueTree::getProperty (const var::identifier& name) const
  13268. {
  13269. return object == 0 ? var::null : object->getProperty (name);
  13270. }
  13271. void ValueTree::setProperty (const var::identifier& name, const var& newValue, UndoManager* const undoManager)
  13272. {
  13273. jassert (name.name.isNotEmpty());
  13274. if (object != 0 && name.name.isNotEmpty())
  13275. object->setProperty (name, newValue, undoManager);
  13276. }
  13277. bool ValueTree::hasProperty (const var::identifier& name) const
  13278. {
  13279. return object != 0 && object->hasProperty (name);
  13280. }
  13281. void ValueTree::removeProperty (const var::identifier& name, UndoManager* const undoManager)
  13282. {
  13283. if (object != 0)
  13284. object->removeProperty (name, undoManager);
  13285. }
  13286. void ValueTree::removeAllProperties (UndoManager* const undoManager)
  13287. {
  13288. if (object != 0)
  13289. object->removeAllProperties (undoManager);
  13290. }
  13291. int ValueTree::getNumProperties() const
  13292. {
  13293. return object == 0 ? 0 : object->properties.size();
  13294. }
  13295. const var::identifier ValueTree::getPropertyName (int index) const
  13296. {
  13297. return (object == 0) ? var::identifier()
  13298. : object->properties.getName (index);
  13299. }
  13300. class ValueTreePropertyValueSource : public Value::ValueSource,
  13301. public ValueTree::Listener
  13302. {
  13303. public:
  13304. ValueTreePropertyValueSource (const ValueTree& tree_,
  13305. const var::identifier& property_,
  13306. UndoManager* const undoManager_)
  13307. : tree (tree_),
  13308. property (property_),
  13309. undoManager (undoManager_)
  13310. {
  13311. tree.addListener (this);
  13312. }
  13313. ~ValueTreePropertyValueSource()
  13314. {
  13315. tree.removeListener (this);
  13316. }
  13317. const var getValue() const
  13318. {
  13319. return tree [property];
  13320. }
  13321. void setValue (const var& newValue)
  13322. {
  13323. tree.setProperty (property, newValue, undoManager);
  13324. }
  13325. void valueTreePropertyChanged (ValueTree& treeWhosePropertyHasChanged, const var::identifier& changedProperty)
  13326. {
  13327. if (tree == treeWhosePropertyHasChanged && property == changedProperty)
  13328. sendChangeMessage (false);
  13329. }
  13330. void valueTreeChildrenChanged (ValueTree&) {}
  13331. void valueTreeParentChanged (ValueTree&) {}
  13332. private:
  13333. ValueTree tree;
  13334. const var::identifier property;
  13335. UndoManager* const undoManager;
  13336. ValueTreePropertyValueSource& operator= (const ValueTreePropertyValueSource&);
  13337. };
  13338. Value ValueTree::getPropertyAsValue (const var::identifier& name, UndoManager* const undoManager) const
  13339. {
  13340. return Value (new ValueTreePropertyValueSource (*this, name, undoManager));
  13341. }
  13342. int ValueTree::getNumChildren() const
  13343. {
  13344. return object == 0 ? 0 : object->children.size();
  13345. }
  13346. ValueTree ValueTree::getChild (int index) const
  13347. {
  13348. return object != 0 ? (SharedObject*) object->children [index] : ValueTree ((SharedObject*) 0);
  13349. }
  13350. ValueTree ValueTree::getChildWithName (const String& type) const
  13351. {
  13352. return object != 0 ? object->getChildWithName (type) : ValueTree ((SharedObject*) 0);
  13353. }
  13354. ValueTree ValueTree::getChildWithProperty (const var::identifier& propertyName, const var& propertyValue) const
  13355. {
  13356. return object != 0 ? object->getChildWithProperty (propertyName, propertyValue) : ValueTree ((SharedObject*) 0);
  13357. }
  13358. bool ValueTree::isAChildOf (const ValueTree& possibleParent) const
  13359. {
  13360. return object != 0 && object->isAChildOf (possibleParent.object);
  13361. }
  13362. void ValueTree::addChild (ValueTree child, int index, UndoManager* const undoManager)
  13363. {
  13364. if (object != 0)
  13365. object->addChild (child.object, index, undoManager);
  13366. }
  13367. void ValueTree::removeChild (const int childIndex, UndoManager* const undoManager)
  13368. {
  13369. if (object != 0)
  13370. object->removeChild (childIndex, undoManager);
  13371. }
  13372. void ValueTree::removeChild (ValueTree& child, UndoManager* const undoManager)
  13373. {
  13374. if (object != 0)
  13375. object->removeChild (object->children.indexOf (child.object), undoManager);
  13376. }
  13377. void ValueTree::removeAllChildren (UndoManager* const undoManager)
  13378. {
  13379. if (object != 0)
  13380. object->removeAllChildren (undoManager);
  13381. }
  13382. void ValueTree::addListener (Listener* listener)
  13383. {
  13384. if (listener != 0)
  13385. {
  13386. if (listeners.size() == 0 && object != 0)
  13387. object->valueTreesWithListeners.add (this);
  13388. listeners.add (listener);
  13389. }
  13390. }
  13391. void ValueTree::removeListener (Listener* listener)
  13392. {
  13393. listeners.removeValue (listener);
  13394. if (listeners.size() == 0 && object != 0)
  13395. object->valueTreesWithListeners.removeValue (this);
  13396. }
  13397. XmlElement* ValueTree::SharedObject::createXml() const
  13398. {
  13399. XmlElement* xml = new XmlElement (type);
  13400. int i;
  13401. for (i = 0; i < properties.size(); ++i)
  13402. {
  13403. var::identifier name (properties.getName(i));
  13404. const var& v = properties [name];
  13405. jassert (! v.isObject()); // DynamicObjects can't be stored as XML!
  13406. xml->setAttribute (name.name, v.toString());
  13407. }
  13408. for (i = 0; i < children.size(); ++i)
  13409. xml->addChildElement (children.getUnchecked(i)->createXml());
  13410. return xml;
  13411. }
  13412. XmlElement* ValueTree::createXml() const
  13413. {
  13414. return object != 0 ? object->createXml() : 0;
  13415. }
  13416. ValueTree ValueTree::fromXml (const XmlElement& xml)
  13417. {
  13418. ValueTree v (xml.getTagName());
  13419. const int numAtts = xml.getNumAttributes(); // xxx inefficient - should write an att iterator..
  13420. for (int i = 0; i < numAtts; ++i)
  13421. v.setProperty (xml.getAttributeName (i), var (xml.getAttributeValue (i)), 0);
  13422. forEachXmlChildElement (xml, e)
  13423. {
  13424. v.addChild (fromXml (*e), -1, 0);
  13425. }
  13426. return v;
  13427. }
  13428. void ValueTree::writeToStream (OutputStream& output)
  13429. {
  13430. output.writeString (getType());
  13431. const int numProps = getNumProperties();
  13432. output.writeCompressedInt (numProps);
  13433. int i;
  13434. for (i = 0; i < numProps; ++i)
  13435. {
  13436. const var::identifier name (getPropertyName(i));
  13437. output.writeString (name.name);
  13438. getProperty(name).writeToStream (output);
  13439. }
  13440. const int numChildren = getNumChildren();
  13441. output.writeCompressedInt (numChildren);
  13442. for (i = 0; i < numChildren; ++i)
  13443. getChild (i).writeToStream (output);
  13444. }
  13445. ValueTree ValueTree::readFromStream (InputStream& input)
  13446. {
  13447. String type (input.readString());
  13448. if (type.isEmpty())
  13449. return ValueTree ((SharedObject*) 0);
  13450. ValueTree v (type);
  13451. const int numProps = input.readCompressedInt();
  13452. if (numProps < 0)
  13453. {
  13454. jassertfalse // trying to read corrupted data!
  13455. return v;
  13456. }
  13457. int i;
  13458. for (i = 0; i < numProps; ++i)
  13459. {
  13460. const String name (input.readString());
  13461. jassert (name.isNotEmpty());
  13462. const var value (var::readFromStream (input));
  13463. v.setProperty (name, value, 0);
  13464. }
  13465. const int numChildren = input.readCompressedInt();
  13466. for (i = 0; i < numChildren; ++i)
  13467. v.addChild (readFromStream (input), -1, 0);
  13468. return v;
  13469. }
  13470. END_JUCE_NAMESPACE
  13471. /*** End of inlined file: juce_ValueTree.cpp ***/
  13472. /*** Start of inlined file: juce_Value.cpp ***/
  13473. BEGIN_JUCE_NAMESPACE
  13474. Value::ValueSource::ValueSource()
  13475. {
  13476. }
  13477. Value::ValueSource::~ValueSource()
  13478. {
  13479. }
  13480. void Value::ValueSource::sendChangeMessage (const bool synchronous)
  13481. {
  13482. if (synchronous)
  13483. {
  13484. for (int i = valuesWithListeners.size(); --i >= 0;)
  13485. {
  13486. Value* const v = valuesWithListeners[i];
  13487. if (v != 0)
  13488. v->callListeners();
  13489. }
  13490. }
  13491. else
  13492. {
  13493. triggerAsyncUpdate();
  13494. }
  13495. }
  13496. void Value::ValueSource::handleAsyncUpdate()
  13497. {
  13498. sendChangeMessage (true);
  13499. }
  13500. class SimpleValueSource : public Value::ValueSource
  13501. {
  13502. public:
  13503. SimpleValueSource()
  13504. {
  13505. }
  13506. SimpleValueSource (const var& initialValue)
  13507. : value (initialValue)
  13508. {
  13509. }
  13510. ~SimpleValueSource()
  13511. {
  13512. }
  13513. const var getValue() const
  13514. {
  13515. return value;
  13516. }
  13517. void setValue (const var& newValue)
  13518. {
  13519. if (newValue != value)
  13520. {
  13521. value = newValue;
  13522. sendChangeMessage (false);
  13523. }
  13524. }
  13525. private:
  13526. var value;
  13527. SimpleValueSource (const SimpleValueSource&);
  13528. SimpleValueSource& operator= (const SimpleValueSource&);
  13529. };
  13530. Value::Value()
  13531. : value (new SimpleValueSource())
  13532. {
  13533. }
  13534. Value::Value (ValueSource* const value_)
  13535. : value (value_)
  13536. {
  13537. jassert (value_ != 0);
  13538. }
  13539. Value::Value (const var& initialValue)
  13540. : value (new SimpleValueSource (initialValue))
  13541. {
  13542. }
  13543. Value::Value (const Value& other)
  13544. : value (other.value)
  13545. {
  13546. }
  13547. Value& Value::operator= (const Value& other)
  13548. {
  13549. value = other.value;
  13550. return *this;
  13551. }
  13552. Value::~Value()
  13553. {
  13554. if (listeners.size() > 0)
  13555. value->valuesWithListeners.removeValue (this);
  13556. }
  13557. const var Value::getValue() const
  13558. {
  13559. return value->getValue();
  13560. }
  13561. void Value::setValue (const var& newValue)
  13562. {
  13563. value->setValue (newValue);
  13564. }
  13565. const String Value::toString() const
  13566. {
  13567. return value->getValue().toString();
  13568. }
  13569. Value& Value::operator= (const var& newValue)
  13570. {
  13571. value->setValue (newValue);
  13572. return *this;
  13573. }
  13574. void Value::referTo (const Value& valueToReferTo)
  13575. {
  13576. if (valueToReferTo.value != value)
  13577. {
  13578. if (listeners.size() > 0)
  13579. {
  13580. value->valuesWithListeners.removeValue (this);
  13581. valueToReferTo.value->valuesWithListeners.add (this);
  13582. }
  13583. value = valueToReferTo.value;
  13584. callListeners();
  13585. }
  13586. }
  13587. bool Value::refersToSameSourceAs (const Value& other) const
  13588. {
  13589. return value == other.value;
  13590. }
  13591. bool Value::operator== (const Value& other) const
  13592. {
  13593. return value == other.value || value->getValue() == other.getValue();
  13594. }
  13595. bool Value::operator!= (const Value& other) const
  13596. {
  13597. return value != other.value && value->getValue() != other.getValue();
  13598. }
  13599. void Value::addListener (Listener* const listener)
  13600. {
  13601. if (listener != 0)
  13602. {
  13603. if (listeners.size() == 0)
  13604. value->valuesWithListeners.add (this);
  13605. listeners.add (listener);
  13606. }
  13607. }
  13608. void Value::removeListener (Listener* const listener)
  13609. {
  13610. listeners.removeValue (listener);
  13611. if (listeners.size() == 0)
  13612. value->valuesWithListeners.removeValue (this);
  13613. }
  13614. void Value::callListeners()
  13615. {
  13616. Value valueCopy (*this); // Use a copy in case this object gets deleted by a callback
  13617. for (int i = listeners.size(); --i >= 0;)
  13618. {
  13619. Listener* const l = listeners[i];
  13620. if (l != 0)
  13621. l->valueChanged (valueCopy);
  13622. }
  13623. }
  13624. END_JUCE_NAMESPACE
  13625. /*** End of inlined file: juce_Value.cpp ***/
  13626. /*** Start of inlined file: juce_Application.cpp ***/
  13627. #if JUCE_MSVC
  13628. #pragma warning (push)
  13629. #pragma warning (disable: 4245 4514 4100)
  13630. #include <crtdbg.h>
  13631. #pragma warning (pop)
  13632. #endif
  13633. BEGIN_JUCE_NAMESPACE
  13634. void juce_setCurrentThreadName (const String& name);
  13635. static JUCEApplication* appInstance = 0;
  13636. JUCEApplication::JUCEApplication()
  13637. : appReturnValue (0),
  13638. stillInitialising (true)
  13639. {
  13640. }
  13641. JUCEApplication::~JUCEApplication()
  13642. {
  13643. if (appLock != 0)
  13644. {
  13645. appLock->exit();
  13646. appLock = 0;
  13647. }
  13648. }
  13649. JUCEApplication* JUCEApplication::getInstance() throw()
  13650. {
  13651. return appInstance;
  13652. }
  13653. bool JUCEApplication::isInitialising() const throw()
  13654. {
  13655. return stillInitialising;
  13656. }
  13657. const String JUCEApplication::getApplicationVersion()
  13658. {
  13659. return String::empty;
  13660. }
  13661. bool JUCEApplication::moreThanOneInstanceAllowed()
  13662. {
  13663. return true;
  13664. }
  13665. void JUCEApplication::anotherInstanceStarted (const String&)
  13666. {
  13667. }
  13668. void JUCEApplication::systemRequestedQuit()
  13669. {
  13670. quit();
  13671. }
  13672. void JUCEApplication::quit()
  13673. {
  13674. MessageManager::getInstance()->stopDispatchLoop();
  13675. }
  13676. void JUCEApplication::setApplicationReturnValue (const int newReturnValue) throw()
  13677. {
  13678. appReturnValue = newReturnValue;
  13679. }
  13680. void JUCEApplication::unhandledException (const std::exception*,
  13681. const String&,
  13682. const int)
  13683. {
  13684. jassertfalse
  13685. }
  13686. void JUCEApplication::sendUnhandledException (const std::exception* const e,
  13687. const char* const sourceFile,
  13688. const int lineNumber)
  13689. {
  13690. if (appInstance != 0)
  13691. appInstance->unhandledException (e, sourceFile, lineNumber);
  13692. }
  13693. ApplicationCommandTarget* JUCEApplication::getNextCommandTarget()
  13694. {
  13695. return 0;
  13696. }
  13697. void JUCEApplication::getAllCommands (Array <CommandID>& commands)
  13698. {
  13699. commands.add (StandardApplicationCommandIDs::quit);
  13700. }
  13701. void JUCEApplication::getCommandInfo (const CommandID commandID, ApplicationCommandInfo& result)
  13702. {
  13703. if (commandID == StandardApplicationCommandIDs::quit)
  13704. {
  13705. result.setInfo (TRANS("Quit"),
  13706. TRANS("Quits the application"),
  13707. "Application",
  13708. 0);
  13709. result.defaultKeypresses.add (KeyPress (T('q'), ModifierKeys::commandModifier, 0));
  13710. }
  13711. }
  13712. bool JUCEApplication::perform (const InvocationInfo& info)
  13713. {
  13714. if (info.commandID == StandardApplicationCommandIDs::quit)
  13715. {
  13716. systemRequestedQuit();
  13717. return true;
  13718. }
  13719. return false;
  13720. }
  13721. int JUCEApplication::main (String& commandLine, JUCEApplication* const app)
  13722. {
  13723. if (! app->initialiseApp (commandLine))
  13724. return 0;
  13725. // now loop until a quit message is received..
  13726. JUCE_TRY
  13727. {
  13728. MessageManager::getInstance()->runDispatchLoop();
  13729. }
  13730. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13731. catch (const std::exception& e)
  13732. {
  13733. app->unhandledException (&e, __FILE__, __LINE__);
  13734. }
  13735. catch (...)
  13736. {
  13737. app->unhandledException (0, __FILE__, __LINE__);
  13738. }
  13739. #endif
  13740. return shutdownAppAndClearUp();
  13741. }
  13742. bool JUCEApplication::initialiseApp (String& commandLine)
  13743. {
  13744. jassert (appInstance == 0);
  13745. appInstance = this;
  13746. commandLineParameters = commandLine.trim();
  13747. commandLine = String::empty;
  13748. initialiseJuce_GUI();
  13749. #if ! JUCE_IPHONE
  13750. jassert (appLock == 0); // initialiseApp must only be called once!
  13751. if (! moreThanOneInstanceAllowed())
  13752. {
  13753. appLock = new InterProcessLock ("juceAppLock_" + getApplicationName());
  13754. if (! appLock->enter(0))
  13755. {
  13756. MessageManager::broadcastMessage (getApplicationName() + "/" + commandLineParameters);
  13757. delete appInstance;
  13758. appInstance = 0;
  13759. DBG ("Another instance is running - quitting...");
  13760. return false;
  13761. }
  13762. }
  13763. #endif
  13764. // let the app do its setting-up..
  13765. initialise (commandLineParameters);
  13766. // register for broadcast new app messages
  13767. MessageManager::getInstance()->registerBroadcastListener (this);
  13768. stillInitialising = false;
  13769. return true;
  13770. }
  13771. int JUCEApplication::shutdownAppAndClearUp()
  13772. {
  13773. jassert (appInstance != 0);
  13774. ScopedPointer<JUCEApplication> app (appInstance);
  13775. int returnValue = 0;
  13776. MessageManager::getInstance()->deregisterBroadcastListener ((JUCEApplication*) app);
  13777. static bool reentrancyCheck = false;
  13778. if (! reentrancyCheck)
  13779. {
  13780. reentrancyCheck = true;
  13781. JUCE_TRY
  13782. {
  13783. // give the app a chance to clean up..
  13784. app->shutdown();
  13785. }
  13786. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  13787. catch (const std::exception& e)
  13788. {
  13789. app->unhandledException (&e, __FILE__, __LINE__);
  13790. }
  13791. catch (...)
  13792. {
  13793. app->unhandledException (0, __FILE__, __LINE__);
  13794. }
  13795. #endif
  13796. JUCE_TRY
  13797. {
  13798. shutdownJuce_GUI();
  13799. returnValue = app->getApplicationReturnValue();
  13800. appInstance = 0;
  13801. app = 0;
  13802. }
  13803. JUCE_CATCH_ALL_ASSERT
  13804. reentrancyCheck = false;
  13805. }
  13806. return returnValue;
  13807. }
  13808. #if JUCE_IPHONE
  13809. extern int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app);
  13810. #endif
  13811. #if ! JUCE_WINDOWS
  13812. extern const char* juce_Argv0;
  13813. #endif
  13814. int JUCEApplication::main (int argc, const char* argv[], JUCEApplication* const newApp)
  13815. {
  13816. #if ! JUCE_WINDOWS
  13817. juce_Argv0 = argv[0];
  13818. #endif
  13819. #if JUCE_IPHONE
  13820. const ScopedAutoReleasePool pool;
  13821. return juce_IPhoneMain (argc, argv, newApp);
  13822. #else
  13823. #if JUCE_MAC
  13824. const ScopedAutoReleasePool pool;
  13825. #endif
  13826. String cmd;
  13827. for (int i = 1; i < argc; ++i)
  13828. cmd << argv[i] << ' ';
  13829. return JUCEApplication::main (cmd, newApp);
  13830. #endif
  13831. }
  13832. void JUCEApplication::actionListenerCallback (const String& message)
  13833. {
  13834. if (message.startsWith (getApplicationName() + "/"))
  13835. anotherInstanceStarted (message.substring (getApplicationName().length() + 1));
  13836. }
  13837. static bool juceInitialisedGUI = false;
  13838. void JUCE_PUBLIC_FUNCTION initialiseJuce_GUI()
  13839. {
  13840. if (! juceInitialisedGUI)
  13841. {
  13842. #if JUCE_MAC || JUCE_IPHONE
  13843. const ScopedAutoReleasePool pool;
  13844. #endif
  13845. juceInitialisedGUI = true;
  13846. initialiseJuce_NonGUI();
  13847. MessageManager::getInstance();
  13848. LookAndFeel::setDefaultLookAndFeel (0);
  13849. juce_setCurrentThreadName ("Juce Message Thread");
  13850. #if JUCE_WINDOWS && JUCE_DEBUG
  13851. // This section is just for catching people who mess up their project settings and
  13852. // turn RTTI off..
  13853. try
  13854. {
  13855. TextButton tb (String::empty);
  13856. Component* c = &tb;
  13857. // Got an exception here? Then TURN ON RTTI in your compiler settings!!
  13858. c = dynamic_cast <Button*> (c);
  13859. }
  13860. catch (...)
  13861. {
  13862. // Ended up here? If so, TURN ON RTTI in your compiler settings!! And if you
  13863. // got as far as this catch statement, then why haven't you got exception catching
  13864. // turned on in the debugger???
  13865. jassertfalse
  13866. }
  13867. #endif
  13868. }
  13869. }
  13870. void JUCE_PUBLIC_FUNCTION shutdownJuce_GUI()
  13871. {
  13872. if (juceInitialisedGUI)
  13873. {
  13874. #if JUCE_MAC
  13875. const ScopedAutoReleasePool pool;
  13876. #endif
  13877. {
  13878. DeletedAtShutdown::deleteAll();
  13879. LookAndFeel::clearDefaultLookAndFeel();
  13880. }
  13881. delete MessageManager::getInstance();
  13882. shutdownJuce_NonGUI();
  13883. juceInitialisedGUI = false;
  13884. }
  13885. }
  13886. END_JUCE_NAMESPACE
  13887. /*** End of inlined file: juce_Application.cpp ***/
  13888. /*** Start of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13889. BEGIN_JUCE_NAMESPACE
  13890. ApplicationCommandInfo::ApplicationCommandInfo (const CommandID commandID_) throw()
  13891. : commandID (commandID_),
  13892. flags (0)
  13893. {
  13894. }
  13895. void ApplicationCommandInfo::setInfo (const String& shortName_,
  13896. const String& description_,
  13897. const String& categoryName_,
  13898. const int flags_) throw()
  13899. {
  13900. shortName = shortName_;
  13901. description = description_;
  13902. categoryName = categoryName_;
  13903. flags = flags_;
  13904. }
  13905. void ApplicationCommandInfo::setActive (const bool b) throw()
  13906. {
  13907. if (b)
  13908. flags &= ~isDisabled;
  13909. else
  13910. flags |= isDisabled;
  13911. }
  13912. void ApplicationCommandInfo::setTicked (const bool b) throw()
  13913. {
  13914. if (b)
  13915. flags |= isTicked;
  13916. else
  13917. flags &= ~isTicked;
  13918. }
  13919. void ApplicationCommandInfo::addDefaultKeypress (const int keyCode, const ModifierKeys& modifiers) throw()
  13920. {
  13921. defaultKeypresses.add (KeyPress (keyCode, modifiers, 0));
  13922. }
  13923. END_JUCE_NAMESPACE
  13924. /*** End of inlined file: juce_ApplicationCommandInfo.cpp ***/
  13925. /*** Start of inlined file: juce_ApplicationCommandManager.cpp ***/
  13926. BEGIN_JUCE_NAMESPACE
  13927. ApplicationCommandManager::ApplicationCommandManager()
  13928. : firstTarget (0)
  13929. {
  13930. keyMappings = new KeyPressMappingSet (this);
  13931. Desktop::getInstance().addFocusChangeListener (this);
  13932. }
  13933. ApplicationCommandManager::~ApplicationCommandManager()
  13934. {
  13935. Desktop::getInstance().removeFocusChangeListener (this);
  13936. keyMappings = 0;
  13937. }
  13938. void ApplicationCommandManager::clearCommands()
  13939. {
  13940. commands.clear();
  13941. keyMappings->clearAllKeyPresses();
  13942. triggerAsyncUpdate();
  13943. }
  13944. void ApplicationCommandManager::registerCommand (const ApplicationCommandInfo& newCommand)
  13945. {
  13946. // zero isn't a valid command ID!
  13947. jassert (newCommand.commandID != 0);
  13948. // the name isn't optional!
  13949. jassert (newCommand.shortName.isNotEmpty());
  13950. if (getCommandForID (newCommand.commandID) == 0)
  13951. {
  13952. ApplicationCommandInfo* const newInfo = new ApplicationCommandInfo (newCommand);
  13953. newInfo->flags &= ~ApplicationCommandInfo::isTicked;
  13954. commands.add (newInfo);
  13955. keyMappings->resetToDefaultMapping (newCommand.commandID);
  13956. triggerAsyncUpdate();
  13957. }
  13958. else
  13959. {
  13960. // trying to re-register the same command with different parameters?
  13961. jassert (newCommand.shortName == getCommandForID (newCommand.commandID)->shortName
  13962. && (newCommand.description == getCommandForID (newCommand.commandID)->description || newCommand.description.isEmpty())
  13963. && newCommand.categoryName == getCommandForID (newCommand.commandID)->categoryName
  13964. && newCommand.defaultKeypresses == getCommandForID (newCommand.commandID)->defaultKeypresses
  13965. && (newCommand.flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor))
  13966. == (getCommandForID (newCommand.commandID)->flags & (ApplicationCommandInfo::wantsKeyUpDownCallbacks | ApplicationCommandInfo::hiddenFromKeyEditor | ApplicationCommandInfo::readOnlyInKeyEditor)));
  13967. }
  13968. }
  13969. void ApplicationCommandManager::registerAllCommandsForTarget (ApplicationCommandTarget* target)
  13970. {
  13971. if (target != 0)
  13972. {
  13973. Array <CommandID> commandIDs;
  13974. target->getAllCommands (commandIDs);
  13975. for (int i = 0; i < commandIDs.size(); ++i)
  13976. {
  13977. ApplicationCommandInfo info (commandIDs.getUnchecked(i));
  13978. target->getCommandInfo (info.commandID, info);
  13979. registerCommand (info);
  13980. }
  13981. }
  13982. }
  13983. void ApplicationCommandManager::removeCommand (const CommandID commandID)
  13984. {
  13985. for (int i = commands.size(); --i >= 0;)
  13986. {
  13987. if (commands.getUnchecked (i)->commandID == commandID)
  13988. {
  13989. commands.remove (i);
  13990. triggerAsyncUpdate();
  13991. const Array <KeyPress> keys (keyMappings->getKeyPressesAssignedToCommand (commandID));
  13992. for (int j = keys.size(); --j >= 0;)
  13993. keyMappings->removeKeyPress (keys.getReference (j));
  13994. }
  13995. }
  13996. }
  13997. void ApplicationCommandManager::commandStatusChanged()
  13998. {
  13999. triggerAsyncUpdate();
  14000. }
  14001. const ApplicationCommandInfo* ApplicationCommandManager::getCommandForID (const CommandID commandID) const throw()
  14002. {
  14003. for (int i = commands.size(); --i >= 0;)
  14004. if (commands.getUnchecked(i)->commandID == commandID)
  14005. return commands.getUnchecked(i);
  14006. return 0;
  14007. }
  14008. const String ApplicationCommandManager::getNameOfCommand (const CommandID commandID) const throw()
  14009. {
  14010. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  14011. return (ci != 0) ? ci->shortName : String::empty;
  14012. }
  14013. const String ApplicationCommandManager::getDescriptionOfCommand (const CommandID commandID) const throw()
  14014. {
  14015. const ApplicationCommandInfo* const ci = getCommandForID (commandID);
  14016. return (ci != 0) ? (ci->description.isNotEmpty() ? ci->description : ci->shortName)
  14017. : String::empty;
  14018. }
  14019. const StringArray ApplicationCommandManager::getCommandCategories() const throw()
  14020. {
  14021. StringArray s;
  14022. for (int i = 0; i < commands.size(); ++i)
  14023. s.addIfNotAlreadyThere (commands.getUnchecked(i)->categoryName, false);
  14024. return s;
  14025. }
  14026. const Array <CommandID> ApplicationCommandManager::getCommandsInCategory (const String& categoryName) const throw()
  14027. {
  14028. Array <CommandID> results;
  14029. for (int i = 0; i < commands.size(); ++i)
  14030. if (commands.getUnchecked(i)->categoryName == categoryName)
  14031. results.add (commands.getUnchecked(i)->commandID);
  14032. return results;
  14033. }
  14034. bool ApplicationCommandManager::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14035. {
  14036. ApplicationCommandTarget::InvocationInfo info (commandID);
  14037. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14038. return invoke (info, asynchronously);
  14039. }
  14040. bool ApplicationCommandManager::invoke (const ApplicationCommandTarget::InvocationInfo& info_, const bool asynchronously)
  14041. {
  14042. // This call isn't thread-safe for use from a non-UI thread without locking the message
  14043. // manager first..
  14044. jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  14045. ApplicationCommandTarget* const target = getFirstCommandTarget (info_.commandID);
  14046. if (target == 0)
  14047. return false;
  14048. ApplicationCommandInfo commandInfo (0);
  14049. target->getCommandInfo (info_.commandID, commandInfo);
  14050. ApplicationCommandTarget::InvocationInfo info (info_);
  14051. info.commandFlags = commandInfo.flags;
  14052. sendListenerInvokeCallback (info);
  14053. const bool ok = target->invoke (info, asynchronously);
  14054. commandStatusChanged();
  14055. return ok;
  14056. }
  14057. ApplicationCommandTarget* ApplicationCommandManager::getFirstCommandTarget (const CommandID)
  14058. {
  14059. return firstTarget != 0 ? firstTarget
  14060. : findDefaultComponentTarget();
  14061. }
  14062. void ApplicationCommandManager::setFirstCommandTarget (ApplicationCommandTarget* const newTarget) throw()
  14063. {
  14064. firstTarget = newTarget;
  14065. }
  14066. ApplicationCommandTarget* ApplicationCommandManager::getTargetForCommand (const CommandID commandID,
  14067. ApplicationCommandInfo& upToDateInfo)
  14068. {
  14069. ApplicationCommandTarget* target = getFirstCommandTarget (commandID);
  14070. if (target == 0)
  14071. target = JUCEApplication::getInstance();
  14072. if (target != 0)
  14073. target = target->getTargetForCommand (commandID);
  14074. if (target != 0)
  14075. target->getCommandInfo (commandID, upToDateInfo);
  14076. return target;
  14077. }
  14078. ApplicationCommandTarget* ApplicationCommandManager::findTargetForComponent (Component* c)
  14079. {
  14080. ApplicationCommandTarget* target = dynamic_cast <ApplicationCommandTarget*> (c);
  14081. if (target == 0 && c != 0)
  14082. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  14083. target = c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  14084. return target;
  14085. }
  14086. ApplicationCommandTarget* ApplicationCommandManager::findDefaultComponentTarget()
  14087. {
  14088. Component* c = Component::getCurrentlyFocusedComponent();
  14089. if (c == 0)
  14090. {
  14091. TopLevelWindow* const activeWindow = TopLevelWindow::getActiveTopLevelWindow();
  14092. if (activeWindow != 0)
  14093. {
  14094. c = activeWindow->getPeer()->getLastFocusedSubcomponent();
  14095. if (c == 0)
  14096. c = activeWindow;
  14097. }
  14098. }
  14099. if (c == 0 && Process::isForegroundProcess())
  14100. {
  14101. // getting a bit desperate now - try all desktop comps..
  14102. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  14103. {
  14104. ApplicationCommandTarget* const target
  14105. = findTargetForComponent (Desktop::getInstance().getComponent (i)
  14106. ->getPeer()->getLastFocusedSubcomponent());
  14107. if (target != 0)
  14108. return target;
  14109. }
  14110. }
  14111. if (c != 0)
  14112. {
  14113. ResizableWindow* const resizableWindow = dynamic_cast <ResizableWindow*> (c);
  14114. // if we're focused on a ResizableWindow, chances are that it's the content
  14115. // component that really should get the event. And if not, the event will
  14116. // still be passed up to the top level window anyway, so let's send it to the
  14117. // content comp.
  14118. if (resizableWindow != 0 && resizableWindow->getContentComponent() != 0)
  14119. c = resizableWindow->getContentComponent();
  14120. ApplicationCommandTarget* const target = findTargetForComponent (c);
  14121. if (target != 0)
  14122. return target;
  14123. }
  14124. return JUCEApplication::getInstance();
  14125. }
  14126. void ApplicationCommandManager::addListener (ApplicationCommandManagerListener* const listener) throw()
  14127. {
  14128. jassert (listener != 0);
  14129. if (listener != 0)
  14130. listeners.add (listener);
  14131. }
  14132. void ApplicationCommandManager::removeListener (ApplicationCommandManagerListener* const listener) throw()
  14133. {
  14134. listeners.removeValue (listener);
  14135. }
  14136. void ApplicationCommandManager::sendListenerInvokeCallback (const ApplicationCommandTarget::InvocationInfo& info) const
  14137. {
  14138. for (int i = listeners.size(); --i >= 0;)
  14139. {
  14140. ((ApplicationCommandManagerListener*) listeners.getUnchecked (i))->applicationCommandInvoked (info);
  14141. i = jmin (i, listeners.size());
  14142. }
  14143. }
  14144. void ApplicationCommandManager::handleAsyncUpdate()
  14145. {
  14146. for (int i = listeners.size(); --i >= 0;)
  14147. {
  14148. ((ApplicationCommandManagerListener*) listeners.getUnchecked (i))->applicationCommandListChanged();
  14149. i = jmin (i, listeners.size());
  14150. }
  14151. }
  14152. void ApplicationCommandManager::globalFocusChanged (Component*)
  14153. {
  14154. commandStatusChanged();
  14155. }
  14156. END_JUCE_NAMESPACE
  14157. /*** End of inlined file: juce_ApplicationCommandManager.cpp ***/
  14158. /*** Start of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14159. BEGIN_JUCE_NAMESPACE
  14160. ApplicationCommandTarget::ApplicationCommandTarget()
  14161. {
  14162. }
  14163. ApplicationCommandTarget::~ApplicationCommandTarget()
  14164. {
  14165. messageInvoker = 0;
  14166. }
  14167. bool ApplicationCommandTarget::tryToInvoke (const InvocationInfo& info, const bool async)
  14168. {
  14169. if (isCommandActive (info.commandID))
  14170. {
  14171. if (async)
  14172. {
  14173. if (messageInvoker == 0)
  14174. messageInvoker = new CommandTargetMessageInvoker (this);
  14175. messageInvoker->postMessage (new Message (0, 0, 0, new ApplicationCommandTarget::InvocationInfo (info)));
  14176. return true;
  14177. }
  14178. else
  14179. {
  14180. const bool success = perform (info);
  14181. jassert (success); // hmm - your target should have been able to perform this command. If it can't
  14182. // do it at the moment for some reason, it should clear the 'isActive' flag when it
  14183. // returns the command's info.
  14184. return success;
  14185. }
  14186. }
  14187. return false;
  14188. }
  14189. ApplicationCommandTarget* ApplicationCommandTarget::findFirstTargetParentComponent()
  14190. {
  14191. Component* c = dynamic_cast <Component*> (this);
  14192. if (c != 0)
  14193. // (unable to use the syntax findParentComponentOfClass <ApplicationCommandTarget> () because of a VC6 compiler bug)
  14194. return c->findParentComponentOfClass ((ApplicationCommandTarget*) 0);
  14195. return 0;
  14196. }
  14197. ApplicationCommandTarget* ApplicationCommandTarget::getTargetForCommand (const CommandID commandID)
  14198. {
  14199. ApplicationCommandTarget* target = this;
  14200. int depth = 0;
  14201. while (target != 0)
  14202. {
  14203. Array <CommandID> commandIDs;
  14204. target->getAllCommands (commandIDs);
  14205. if (commandIDs.contains (commandID))
  14206. return target;
  14207. target = target->getNextCommandTarget();
  14208. ++depth;
  14209. jassert (depth < 100); // could be a recursive command chain??
  14210. jassert (target != this); // definitely a recursive command chain!
  14211. if (depth > 100 || target == this)
  14212. break;
  14213. }
  14214. if (target == 0)
  14215. {
  14216. target = JUCEApplication::getInstance();
  14217. if (target != 0)
  14218. {
  14219. Array <CommandID> commandIDs;
  14220. target->getAllCommands (commandIDs);
  14221. if (commandIDs.contains (commandID))
  14222. return target;
  14223. }
  14224. }
  14225. return 0;
  14226. }
  14227. bool ApplicationCommandTarget::isCommandActive (const CommandID commandID)
  14228. {
  14229. ApplicationCommandInfo info (commandID);
  14230. info.flags = ApplicationCommandInfo::isDisabled;
  14231. getCommandInfo (commandID, info);
  14232. return (info.flags & ApplicationCommandInfo::isDisabled) == 0;
  14233. }
  14234. bool ApplicationCommandTarget::invoke (const InvocationInfo& info, const bool async)
  14235. {
  14236. ApplicationCommandTarget* target = this;
  14237. int depth = 0;
  14238. while (target != 0)
  14239. {
  14240. if (target->tryToInvoke (info, async))
  14241. return true;
  14242. target = target->getNextCommandTarget();
  14243. ++depth;
  14244. jassert (depth < 100); // could be a recursive command chain??
  14245. jassert (target != this); // definitely a recursive command chain!
  14246. if (depth > 100 || target == this)
  14247. break;
  14248. }
  14249. if (target == 0)
  14250. {
  14251. target = JUCEApplication::getInstance();
  14252. if (target != 0)
  14253. return target->tryToInvoke (info, async);
  14254. }
  14255. return false;
  14256. }
  14257. bool ApplicationCommandTarget::invokeDirectly (const CommandID commandID, const bool asynchronously)
  14258. {
  14259. ApplicationCommandTarget::InvocationInfo info (commandID);
  14260. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::direct;
  14261. return invoke (info, asynchronously);
  14262. }
  14263. ApplicationCommandTarget::InvocationInfo::InvocationInfo (const CommandID commandID_) throw()
  14264. : commandID (commandID_),
  14265. commandFlags (0),
  14266. invocationMethod (direct),
  14267. originatingComponent (0),
  14268. isKeyDown (false),
  14269. millisecsSinceKeyPressed (0)
  14270. {
  14271. }
  14272. ApplicationCommandTarget::CommandTargetMessageInvoker::CommandTargetMessageInvoker (ApplicationCommandTarget* const owner_)
  14273. : owner (owner_)
  14274. {
  14275. }
  14276. ApplicationCommandTarget::CommandTargetMessageInvoker::~CommandTargetMessageInvoker()
  14277. {
  14278. }
  14279. void ApplicationCommandTarget::CommandTargetMessageInvoker::handleMessage (const Message& message)
  14280. {
  14281. const ScopedPointer <InvocationInfo> info ((InvocationInfo*) message.pointerParameter);
  14282. owner->tryToInvoke (*info, false);
  14283. }
  14284. END_JUCE_NAMESPACE
  14285. /*** End of inlined file: juce_ApplicationCommandTarget.cpp ***/
  14286. /*** Start of inlined file: juce_ApplicationProperties.cpp ***/
  14287. BEGIN_JUCE_NAMESPACE
  14288. juce_ImplementSingleton (ApplicationProperties)
  14289. ApplicationProperties::ApplicationProperties() throw()
  14290. : msBeforeSaving (3000),
  14291. options (PropertiesFile::storeAsBinary),
  14292. commonSettingsAreReadOnly (0)
  14293. {
  14294. }
  14295. ApplicationProperties::~ApplicationProperties()
  14296. {
  14297. closeFiles();
  14298. clearSingletonInstance();
  14299. }
  14300. void ApplicationProperties::setStorageParameters (const String& applicationName,
  14301. const String& fileNameSuffix,
  14302. const String& folderName_,
  14303. const int millisecondsBeforeSaving,
  14304. const int propertiesFileOptions) throw()
  14305. {
  14306. appName = applicationName;
  14307. fileSuffix = fileNameSuffix;
  14308. folderName = folderName_;
  14309. msBeforeSaving = millisecondsBeforeSaving;
  14310. options = propertiesFileOptions;
  14311. }
  14312. bool ApplicationProperties::testWriteAccess (const bool testUserSettings,
  14313. const bool testCommonSettings,
  14314. const bool showWarningDialogOnFailure)
  14315. {
  14316. const bool userOk = (! testUserSettings) || getUserSettings()->save();
  14317. const bool commonOk = (! testCommonSettings) || getCommonSettings (false)->save();
  14318. if (! (userOk && commonOk))
  14319. {
  14320. if (showWarningDialogOnFailure)
  14321. {
  14322. String filenames;
  14323. if (userProps != 0 && ! userOk)
  14324. filenames << '\n' << userProps->getFile().getFullPathName();
  14325. if (commonProps != 0 && ! commonOk)
  14326. filenames << '\n' << commonProps->getFile().getFullPathName();
  14327. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14328. appName + TRANS(" - Unable to save settings"),
  14329. TRANS("An error occurred when trying to save the application's settings file...\n\nIn order to save and restore its settings, ")
  14330. + appName + TRANS(" needs to be able to write to the following files:\n")
  14331. + filenames
  14332. + TRANS("\n\nMake sure that these files aren't read-only, and that the disk isn't full."));
  14333. }
  14334. return false;
  14335. }
  14336. return true;
  14337. }
  14338. void ApplicationProperties::openFiles() throw()
  14339. {
  14340. // You need to call setStorageParameters() before trying to get hold of the
  14341. // properties!
  14342. jassert (appName.isNotEmpty());
  14343. if (appName.isNotEmpty())
  14344. {
  14345. if (userProps == 0)
  14346. userProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14347. false, msBeforeSaving, options);
  14348. if (commonProps == 0)
  14349. commonProps = PropertiesFile::createDefaultAppPropertiesFile (appName, fileSuffix, folderName,
  14350. true, msBeforeSaving, options);
  14351. userProps->setFallbackPropertySet (commonProps);
  14352. }
  14353. }
  14354. PropertiesFile* ApplicationProperties::getUserSettings() throw()
  14355. {
  14356. if (userProps == 0)
  14357. openFiles();
  14358. return userProps;
  14359. }
  14360. PropertiesFile* ApplicationProperties::getCommonSettings (const bool returnUserPropsIfReadOnly) throw()
  14361. {
  14362. if (commonProps == 0)
  14363. openFiles();
  14364. if (returnUserPropsIfReadOnly)
  14365. {
  14366. if (commonSettingsAreReadOnly == 0)
  14367. commonSettingsAreReadOnly = commonProps->save() ? -1 : 1;
  14368. if (commonSettingsAreReadOnly > 0)
  14369. return userProps;
  14370. }
  14371. return commonProps;
  14372. }
  14373. bool ApplicationProperties::saveIfNeeded()
  14374. {
  14375. return (userProps == 0 || userProps->saveIfNeeded())
  14376. && (commonProps == 0 || commonProps->saveIfNeeded());
  14377. }
  14378. void ApplicationProperties::closeFiles()
  14379. {
  14380. userProps = 0;
  14381. commonProps = 0;
  14382. }
  14383. END_JUCE_NAMESPACE
  14384. /*** End of inlined file: juce_ApplicationProperties.cpp ***/
  14385. /*** Start of inlined file: juce_DeletedAtShutdown.cpp ***/
  14386. BEGIN_JUCE_NAMESPACE
  14387. static VoidArray objectsToDelete;
  14388. static CriticalSection lock;
  14389. DeletedAtShutdown::DeletedAtShutdown()
  14390. {
  14391. const ScopedLock sl (lock);
  14392. objectsToDelete.add (this);
  14393. }
  14394. DeletedAtShutdown::~DeletedAtShutdown()
  14395. {
  14396. const ScopedLock sl (lock);
  14397. objectsToDelete.removeValue (this);
  14398. }
  14399. void DeletedAtShutdown::deleteAll()
  14400. {
  14401. // make a local copy of the array, so it can't get into a loop if something
  14402. // creates another DeletedAtShutdown object during its destructor.
  14403. VoidArray localCopy;
  14404. {
  14405. const ScopedLock sl (lock);
  14406. localCopy = objectsToDelete;
  14407. }
  14408. for (int i = localCopy.size(); --i >= 0;)
  14409. {
  14410. JUCE_TRY
  14411. {
  14412. DeletedAtShutdown* deletee = (DeletedAtShutdown*) localCopy.getUnchecked(i);
  14413. // double-check that it's not already been deleted during another object's destructor.
  14414. {
  14415. const ScopedLock sl (lock);
  14416. if (! objectsToDelete.contains (deletee))
  14417. deletee = 0;
  14418. }
  14419. delete deletee;
  14420. }
  14421. JUCE_CATCH_EXCEPTION
  14422. }
  14423. // if no objects got re-created during shutdown, this should have been emptied by their
  14424. // destructors
  14425. jassert (objectsToDelete.size() == 0);
  14426. objectsToDelete.clear(); // just to make sure the array doesn't have any memory still allocated
  14427. }
  14428. END_JUCE_NAMESPACE
  14429. /*** End of inlined file: juce_DeletedAtShutdown.cpp ***/
  14430. /*** Start of inlined file: juce_PropertiesFile.cpp ***/
  14431. BEGIN_JUCE_NAMESPACE
  14432. static const int propFileMagicNumber = ((int) ByteOrder::littleEndianInt ("PROP"));
  14433. static const int propFileMagicNumberCompressed = ((int) ByteOrder::littleEndianInt ("CPRP"));
  14434. static const tchar* const propertyFileXmlTag = T("PROPERTIES");
  14435. static const tchar* const propertyTagName = T("VALUE");
  14436. PropertiesFile::PropertiesFile (const File& f,
  14437. const int millisecondsBeforeSaving,
  14438. const int options_)
  14439. : PropertySet (ignoreCaseOfKeyNames),
  14440. file (f),
  14441. timerInterval (millisecondsBeforeSaving),
  14442. options (options_),
  14443. needsWriting (false)
  14444. {
  14445. // You need to correctly specify just one storage format for the file
  14446. jassert ((options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsBinary
  14447. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsCompressedBinary
  14448. || (options_ & (storeAsBinary | storeAsCompressedBinary | storeAsXML)) == storeAsXML);
  14449. ScopedPointer <InputStream> fileStream (f.createInputStream());
  14450. if (fileStream != 0)
  14451. {
  14452. int magicNumber = fileStream->readInt();
  14453. if (magicNumber == propFileMagicNumberCompressed)
  14454. {
  14455. fileStream = new GZIPDecompressorInputStream (new SubregionStream (fileStream.release(), 4, -1, true),
  14456. true);
  14457. magicNumber = propFileMagicNumber;
  14458. }
  14459. if (magicNumber == propFileMagicNumber)
  14460. {
  14461. BufferedInputStream in (fileStream.release(), 2048, true);
  14462. int numValues = in.readInt();
  14463. while (--numValues >= 0 && ! in.isExhausted())
  14464. {
  14465. const String key (in.readString());
  14466. const String value (in.readString());
  14467. jassert (key.isNotEmpty());
  14468. if (key.isNotEmpty())
  14469. getAllProperties().set (key, value);
  14470. }
  14471. }
  14472. else
  14473. {
  14474. // Not a binary props file - let's see if it's XML..
  14475. fileStream = 0;
  14476. XmlDocument parser (f);
  14477. ScopedPointer <XmlElement> doc (parser.getDocumentElement (true));
  14478. if (doc != 0 && doc->hasTagName (propertyFileXmlTag))
  14479. {
  14480. doc = parser.getDocumentElement();
  14481. if (doc != 0)
  14482. {
  14483. forEachXmlChildElementWithTagName (*doc, e, propertyTagName)
  14484. {
  14485. const String name (e->getStringAttribute (T("name")));
  14486. if (name.isNotEmpty())
  14487. {
  14488. getAllProperties().set (name,
  14489. e->getFirstChildElement() != 0
  14490. ? e->getFirstChildElement()->createDocument (String::empty, true)
  14491. : e->getStringAttribute (T("val")));
  14492. }
  14493. }
  14494. }
  14495. else
  14496. {
  14497. // must be a pretty broken XML file we're trying to parse here!
  14498. jassertfalse
  14499. }
  14500. }
  14501. }
  14502. }
  14503. }
  14504. PropertiesFile::~PropertiesFile()
  14505. {
  14506. saveIfNeeded();
  14507. }
  14508. bool PropertiesFile::saveIfNeeded()
  14509. {
  14510. const ScopedLock sl (getLock());
  14511. return (! needsWriting) || save();
  14512. }
  14513. bool PropertiesFile::needsToBeSaved() const
  14514. {
  14515. const ScopedLock sl (getLock());
  14516. return needsWriting;
  14517. }
  14518. bool PropertiesFile::save()
  14519. {
  14520. const ScopedLock sl (getLock());
  14521. stopTimer();
  14522. if (file == File::nonexistent
  14523. || file.isDirectory()
  14524. || ! file.getParentDirectory().createDirectory())
  14525. return false;
  14526. if ((options & storeAsXML) != 0)
  14527. {
  14528. XmlElement doc (propertyFileXmlTag);
  14529. for (int i = 0; i < getAllProperties().size(); ++i)
  14530. {
  14531. XmlElement* const e = doc.createNewChildElement (propertyTagName);
  14532. e->setAttribute (T("name"), getAllProperties().getAllKeys() [i]);
  14533. // if the value seems to contain xml, store it as such..
  14534. XmlDocument xmlContent (getAllProperties().getAllValues() [i]);
  14535. XmlElement* const childElement = xmlContent.getDocumentElement();
  14536. if (childElement != 0)
  14537. e->addChildElement (childElement);
  14538. else
  14539. e->setAttribute (T("val"), getAllProperties().getAllValues() [i]);
  14540. }
  14541. return doc.writeToFile (file, String::empty);
  14542. }
  14543. else
  14544. {
  14545. TemporaryFile tempFile (file);
  14546. ScopedPointer <OutputStream> out (tempFile.getFile().createOutputStream());
  14547. if (out != 0)
  14548. {
  14549. if ((options & storeAsCompressedBinary) != 0)
  14550. {
  14551. out->writeInt (propFileMagicNumberCompressed);
  14552. out->flush();
  14553. out = new GZIPCompressorOutputStream (out.release(), 9, true);
  14554. }
  14555. else
  14556. {
  14557. // have you set up the storage option flags correctly?
  14558. jassert ((options & storeAsBinary) != 0);
  14559. out->writeInt (propFileMagicNumber);
  14560. }
  14561. const int numProperties = getAllProperties().size();
  14562. out->writeInt (numProperties);
  14563. for (int i = 0; i < numProperties; ++i)
  14564. {
  14565. out->writeString (getAllProperties().getAllKeys() [i]);
  14566. out->writeString (getAllProperties().getAllValues() [i]);
  14567. }
  14568. out = 0;
  14569. if (tempFile.overwriteTargetFileWithTemporary())
  14570. {
  14571. needsWriting = false;
  14572. return true;
  14573. }
  14574. }
  14575. }
  14576. return false;
  14577. }
  14578. void PropertiesFile::timerCallback()
  14579. {
  14580. saveIfNeeded();
  14581. }
  14582. void PropertiesFile::propertyChanged()
  14583. {
  14584. sendChangeMessage (this);
  14585. needsWriting = true;
  14586. if (timerInterval > 0)
  14587. startTimer (timerInterval);
  14588. else if (timerInterval == 0)
  14589. saveIfNeeded();
  14590. }
  14591. const File PropertiesFile::getDefaultAppSettingsFile (const String& applicationName,
  14592. const String& fileNameSuffix,
  14593. const String& folderName,
  14594. const bool commonToAllUsers)
  14595. {
  14596. // mustn't have illegal characters in this name..
  14597. jassert (applicationName == File::createLegalFileName (applicationName));
  14598. #if JUCE_MAC || JUCE_IPHONE
  14599. File dir (commonToAllUsers ? "/Library/Preferences"
  14600. : "~/Library/Preferences");
  14601. if (folderName.isNotEmpty())
  14602. dir = dir.getChildFile (folderName);
  14603. #endif
  14604. #ifdef JUCE_LINUX
  14605. const File dir ((commonToAllUsers ? T("/var/") : T("~/"))
  14606. + (folderName.isNotEmpty() ? folderName
  14607. : (T(".") + applicationName)));
  14608. #endif
  14609. #if JUCE_WIN32
  14610. File dir (File::getSpecialLocation (commonToAllUsers ? File::commonApplicationDataDirectory
  14611. : File::userApplicationDataDirectory));
  14612. if (dir == File::nonexistent)
  14613. return File::nonexistent;
  14614. dir = dir.getChildFile (folderName.isNotEmpty() ? folderName
  14615. : applicationName);
  14616. #endif
  14617. return dir.getChildFile (applicationName)
  14618. .withFileExtension (fileNameSuffix);
  14619. }
  14620. PropertiesFile* PropertiesFile::createDefaultAppPropertiesFile (const String& applicationName,
  14621. const String& fileNameSuffix,
  14622. const String& folderName,
  14623. const bool commonToAllUsers,
  14624. const int millisecondsBeforeSaving,
  14625. const int propertiesFileOptions)
  14626. {
  14627. const File file (getDefaultAppSettingsFile (applicationName,
  14628. fileNameSuffix,
  14629. folderName,
  14630. commonToAllUsers));
  14631. jassert (file != File::nonexistent);
  14632. if (file == File::nonexistent)
  14633. return 0;
  14634. return new PropertiesFile (file, millisecondsBeforeSaving, propertiesFileOptions);
  14635. }
  14636. END_JUCE_NAMESPACE
  14637. /*** End of inlined file: juce_PropertiesFile.cpp ***/
  14638. /*** Start of inlined file: juce_FileBasedDocument.cpp ***/
  14639. BEGIN_JUCE_NAMESPACE
  14640. FileBasedDocument::FileBasedDocument (const String& fileExtension_,
  14641. const String& fileWildcard_,
  14642. const String& openFileDialogTitle_,
  14643. const String& saveFileDialogTitle_)
  14644. : changedSinceSave (false),
  14645. fileExtension (fileExtension_),
  14646. fileWildcard (fileWildcard_),
  14647. openFileDialogTitle (openFileDialogTitle_),
  14648. saveFileDialogTitle (saveFileDialogTitle_)
  14649. {
  14650. }
  14651. FileBasedDocument::~FileBasedDocument()
  14652. {
  14653. }
  14654. void FileBasedDocument::setChangedFlag (const bool hasChanged)
  14655. {
  14656. changedSinceSave = hasChanged;
  14657. }
  14658. void FileBasedDocument::changed()
  14659. {
  14660. changedSinceSave = true;
  14661. sendChangeMessage (this);
  14662. }
  14663. void FileBasedDocument::setFile (const File& newFile)
  14664. {
  14665. if (documentFile != newFile)
  14666. {
  14667. documentFile = newFile;
  14668. changedSinceSave = true;
  14669. }
  14670. }
  14671. bool FileBasedDocument::loadFrom (const File& newFile,
  14672. const bool showMessageOnFailure)
  14673. {
  14674. MouseCursor::showWaitCursor();
  14675. const File oldFile (documentFile);
  14676. documentFile = newFile;
  14677. String error;
  14678. if (newFile.existsAsFile())
  14679. {
  14680. error = loadDocument (newFile);
  14681. if (error.isEmpty())
  14682. {
  14683. setChangedFlag (false);
  14684. MouseCursor::hideWaitCursor();
  14685. setLastDocumentOpened (newFile);
  14686. return true;
  14687. }
  14688. }
  14689. else
  14690. {
  14691. error = "The file doesn't exist";
  14692. }
  14693. documentFile = oldFile;
  14694. MouseCursor::hideWaitCursor();
  14695. if (showMessageOnFailure)
  14696. {
  14697. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14698. TRANS("Failed to open file..."),
  14699. TRANS("There was an error while trying to load the file:\n\n")
  14700. + newFile.getFullPathName()
  14701. + T("\n\n")
  14702. + error);
  14703. }
  14704. return false;
  14705. }
  14706. bool FileBasedDocument::loadFromUserSpecifiedFile (const bool showMessageOnFailure)
  14707. {
  14708. FileChooser fc (openFileDialogTitle,
  14709. getLastDocumentOpened(),
  14710. fileWildcard);
  14711. if (fc.browseForFileToOpen())
  14712. return loadFrom (fc.getResult(), showMessageOnFailure);
  14713. return false;
  14714. }
  14715. FileBasedDocument::SaveResult FileBasedDocument::save (const bool askUserForFileIfNotSpecified,
  14716. const bool showMessageOnFailure)
  14717. {
  14718. return saveAs (documentFile,
  14719. false,
  14720. askUserForFileIfNotSpecified,
  14721. showMessageOnFailure);
  14722. }
  14723. FileBasedDocument::SaveResult FileBasedDocument::saveAs (const File& newFile,
  14724. const bool warnAboutOverwritingExistingFiles,
  14725. const bool askUserForFileIfNotSpecified,
  14726. const bool showMessageOnFailure)
  14727. {
  14728. if (newFile == File::nonexistent)
  14729. {
  14730. if (askUserForFileIfNotSpecified)
  14731. {
  14732. return saveAsInteractive (true);
  14733. }
  14734. else
  14735. {
  14736. // can't save to an unspecified file
  14737. jassertfalse
  14738. return failedToWriteToFile;
  14739. }
  14740. }
  14741. if (warnAboutOverwritingExistingFiles && newFile.exists())
  14742. {
  14743. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14744. TRANS("File already exists"),
  14745. TRANS("There's already a file called:\n\n")
  14746. + newFile.getFullPathName()
  14747. + TRANS("\n\nAre you sure you want to overwrite it?"),
  14748. TRANS("overwrite"),
  14749. TRANS("cancel")))
  14750. {
  14751. return userCancelledSave;
  14752. }
  14753. }
  14754. MouseCursor::showWaitCursor();
  14755. const File oldFile (documentFile);
  14756. documentFile = newFile;
  14757. String error (saveDocument (newFile));
  14758. if (error.isEmpty())
  14759. {
  14760. setChangedFlag (false);
  14761. MouseCursor::hideWaitCursor();
  14762. return savedOk;
  14763. }
  14764. documentFile = oldFile;
  14765. MouseCursor::hideWaitCursor();
  14766. if (showMessageOnFailure)
  14767. {
  14768. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  14769. TRANS("Error writing to file..."),
  14770. TRANS("An error occurred while trying to save \"")
  14771. + getDocumentTitle()
  14772. + TRANS("\" to the file:\n\n")
  14773. + newFile.getFullPathName()
  14774. + T("\n\n")
  14775. + error);
  14776. }
  14777. return failedToWriteToFile;
  14778. }
  14779. FileBasedDocument::SaveResult FileBasedDocument::saveIfNeededAndUserAgrees()
  14780. {
  14781. if (! hasChangedSinceSaved())
  14782. return savedOk;
  14783. const int r = AlertWindow::showYesNoCancelBox (AlertWindow::QuestionIcon,
  14784. TRANS("Closing document..."),
  14785. TRANS("Do you want to save the changes to \"")
  14786. + getDocumentTitle() + T("\"?"),
  14787. TRANS("save"),
  14788. TRANS("discard changes"),
  14789. TRANS("cancel"));
  14790. if (r == 1)
  14791. {
  14792. // save changes
  14793. return save (true, true);
  14794. }
  14795. else if (r == 2)
  14796. {
  14797. // discard changes
  14798. return savedOk;
  14799. }
  14800. return userCancelledSave;
  14801. }
  14802. FileBasedDocument::SaveResult FileBasedDocument::saveAsInteractive (const bool warnAboutOverwritingExistingFiles)
  14803. {
  14804. File f;
  14805. if (documentFile.existsAsFile())
  14806. f = documentFile;
  14807. else
  14808. f = getLastDocumentOpened();
  14809. String legalFilename (File::createLegalFileName (getDocumentTitle()));
  14810. if (legalFilename.isEmpty())
  14811. legalFilename = "unnamed";
  14812. if (f.existsAsFile() || f.getParentDirectory().isDirectory())
  14813. f = f.getSiblingFile (legalFilename);
  14814. else
  14815. f = File::getSpecialLocation (File::userDocumentsDirectory).getChildFile (legalFilename);
  14816. f = f.withFileExtension (fileExtension)
  14817. .getNonexistentSibling (true);
  14818. FileChooser fc (saveFileDialogTitle, f, fileWildcard);
  14819. if (fc.browseForFileToSave (warnAboutOverwritingExistingFiles))
  14820. {
  14821. setLastDocumentOpened (fc.getResult());
  14822. File chosen (fc.getResult());
  14823. if (chosen.getFileExtension().isEmpty())
  14824. {
  14825. chosen = chosen.withFileExtension (fileExtension);
  14826. if (chosen.exists())
  14827. {
  14828. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  14829. TRANS("File already exists"),
  14830. TRANS("There's already a file called:\n\n")
  14831. + chosen.getFullPathName()
  14832. + T("\n\nAre you sure you want to overwrite it?"),
  14833. TRANS("overwrite"),
  14834. TRANS("cancel")))
  14835. {
  14836. return userCancelledSave;
  14837. }
  14838. }
  14839. }
  14840. return saveAs (chosen, false, false, true);
  14841. }
  14842. return userCancelledSave;
  14843. }
  14844. END_JUCE_NAMESPACE
  14845. /*** End of inlined file: juce_FileBasedDocument.cpp ***/
  14846. /*** Start of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14847. BEGIN_JUCE_NAMESPACE
  14848. RecentlyOpenedFilesList::RecentlyOpenedFilesList()
  14849. : maxNumberOfItems (10)
  14850. {
  14851. }
  14852. RecentlyOpenedFilesList::~RecentlyOpenedFilesList()
  14853. {
  14854. }
  14855. void RecentlyOpenedFilesList::setMaxNumberOfItems (const int newMaxNumber)
  14856. {
  14857. maxNumberOfItems = jmax (1, newMaxNumber);
  14858. while (getNumFiles() > maxNumberOfItems)
  14859. files.remove (getNumFiles() - 1);
  14860. }
  14861. int RecentlyOpenedFilesList::getNumFiles() const
  14862. {
  14863. return files.size();
  14864. }
  14865. const File RecentlyOpenedFilesList::getFile (const int index) const
  14866. {
  14867. return File (files [index]);
  14868. }
  14869. void RecentlyOpenedFilesList::clear()
  14870. {
  14871. files.clear();
  14872. }
  14873. void RecentlyOpenedFilesList::addFile (const File& file)
  14874. {
  14875. const String path (file.getFullPathName());
  14876. files.removeString (path, true);
  14877. files.insert (0, path);
  14878. setMaxNumberOfItems (maxNumberOfItems);
  14879. }
  14880. void RecentlyOpenedFilesList::removeNonExistentFiles()
  14881. {
  14882. for (int i = getNumFiles(); --i >= 0;)
  14883. if (! getFile(i).exists())
  14884. files.remove (i);
  14885. }
  14886. int RecentlyOpenedFilesList::createPopupMenuItems (PopupMenu& menuToAddTo,
  14887. const int baseItemId,
  14888. const bool showFullPaths,
  14889. const bool dontAddNonExistentFiles,
  14890. const File** filesToAvoid)
  14891. {
  14892. int num = 0;
  14893. for (int i = 0; i < getNumFiles(); ++i)
  14894. {
  14895. const File f (getFile(i));
  14896. if ((! dontAddNonExistentFiles) || f.exists())
  14897. {
  14898. bool needsAvoiding = false;
  14899. if (filesToAvoid != 0)
  14900. {
  14901. const File** avoid = filesToAvoid;
  14902. while (*avoid != 0)
  14903. {
  14904. if (f == **avoid)
  14905. {
  14906. needsAvoiding = true;
  14907. break;
  14908. }
  14909. ++avoid;
  14910. }
  14911. }
  14912. if (! needsAvoiding)
  14913. {
  14914. menuToAddTo.addItem (baseItemId + i,
  14915. showFullPaths ? f.getFullPathName()
  14916. : f.getFileName());
  14917. ++num;
  14918. }
  14919. }
  14920. }
  14921. return num;
  14922. }
  14923. const String RecentlyOpenedFilesList::toString() const
  14924. {
  14925. return files.joinIntoString (T("\n"));
  14926. }
  14927. void RecentlyOpenedFilesList::restoreFromString (const String& stringifiedVersion)
  14928. {
  14929. clear();
  14930. files.addLines (stringifiedVersion);
  14931. setMaxNumberOfItems (maxNumberOfItems);
  14932. }
  14933. END_JUCE_NAMESPACE
  14934. /*** End of inlined file: juce_RecentlyOpenedFilesList.cpp ***/
  14935. /*** Start of inlined file: juce_UndoManager.cpp ***/
  14936. BEGIN_JUCE_NAMESPACE
  14937. UndoManager::UndoManager (const int maxNumberOfUnitsToKeep,
  14938. const int minimumTransactions)
  14939. : totalUnitsStored (0),
  14940. nextIndex (0),
  14941. newTransaction (true),
  14942. reentrancyCheck (false)
  14943. {
  14944. setMaxNumberOfStoredUnits (maxNumberOfUnitsToKeep,
  14945. minimumTransactions);
  14946. }
  14947. UndoManager::~UndoManager()
  14948. {
  14949. clearUndoHistory();
  14950. }
  14951. void UndoManager::clearUndoHistory()
  14952. {
  14953. transactions.clear();
  14954. transactionNames.clear();
  14955. totalUnitsStored = 0;
  14956. nextIndex = 0;
  14957. sendChangeMessage (this);
  14958. }
  14959. int UndoManager::getNumberOfUnitsTakenUpByStoredCommands() const
  14960. {
  14961. return totalUnitsStored;
  14962. }
  14963. void UndoManager::setMaxNumberOfStoredUnits (const int maxNumberOfUnitsToKeep,
  14964. const int minimumTransactions)
  14965. {
  14966. maxNumUnitsToKeep = jmax (1, maxNumberOfUnitsToKeep);
  14967. minimumTransactionsToKeep = jmax (1, minimumTransactions);
  14968. }
  14969. bool UndoManager::perform (UndoableAction* const command, const String& actionName)
  14970. {
  14971. if (command != 0)
  14972. {
  14973. if (actionName.isNotEmpty())
  14974. currentTransactionName = actionName;
  14975. if (reentrancyCheck)
  14976. {
  14977. jassertfalse // don't call perform() recursively from the UndoableAction::perform() or
  14978. // undo() methods, or else these actions won't actually get done.
  14979. return false;
  14980. }
  14981. else
  14982. {
  14983. bool success = false;
  14984. JUCE_TRY
  14985. {
  14986. success = command->perform();
  14987. }
  14988. JUCE_CATCH_EXCEPTION
  14989. jassert (success);
  14990. if (success)
  14991. {
  14992. if (nextIndex > 0 && ! newTransaction)
  14993. {
  14994. OwnedArray<UndoableAction>* commandSet = transactions [nextIndex - 1];
  14995. jassert (commandSet != 0);
  14996. if (commandSet == 0)
  14997. return false;
  14998. commandSet->add (command);
  14999. }
  15000. else
  15001. {
  15002. OwnedArray<UndoableAction>* commandSet = new OwnedArray<UndoableAction>();
  15003. commandSet->add (command);
  15004. transactions.insert (nextIndex, commandSet);
  15005. transactionNames.insert (nextIndex, currentTransactionName);
  15006. ++nextIndex;
  15007. }
  15008. totalUnitsStored += command->getSizeInUnits();
  15009. newTransaction = false;
  15010. }
  15011. while (nextIndex < transactions.size())
  15012. {
  15013. const OwnedArray <UndoableAction>* const lastSet = transactions.getLast();
  15014. for (int i = lastSet->size(); --i >= 0;)
  15015. totalUnitsStored -= lastSet->getUnchecked (i)->getSizeInUnits();
  15016. transactions.removeLast();
  15017. transactionNames.remove (transactionNames.size() - 1);
  15018. }
  15019. while (nextIndex > 0
  15020. && totalUnitsStored > maxNumUnitsToKeep
  15021. && transactions.size() > minimumTransactionsToKeep)
  15022. {
  15023. const OwnedArray <UndoableAction>* const firstSet = transactions.getFirst();
  15024. for (int i = firstSet->size(); --i >= 0;)
  15025. totalUnitsStored -= firstSet->getUnchecked (i)->getSizeInUnits();
  15026. jassert (totalUnitsStored >= 0); // something fishy going on if this fails!
  15027. transactions.remove (0);
  15028. transactionNames.remove (0);
  15029. --nextIndex;
  15030. }
  15031. sendChangeMessage (this);
  15032. return success;
  15033. }
  15034. }
  15035. return false;
  15036. }
  15037. void UndoManager::beginNewTransaction (const String& actionName)
  15038. {
  15039. newTransaction = true;
  15040. currentTransactionName = actionName;
  15041. }
  15042. void UndoManager::setCurrentTransactionName (const String& newName)
  15043. {
  15044. currentTransactionName = newName;
  15045. }
  15046. bool UndoManager::canUndo() const
  15047. {
  15048. return nextIndex > 0;
  15049. }
  15050. bool UndoManager::canRedo() const
  15051. {
  15052. return nextIndex < transactions.size();
  15053. }
  15054. const String UndoManager::getUndoDescription() const
  15055. {
  15056. return transactionNames [nextIndex - 1];
  15057. }
  15058. const String UndoManager::getRedoDescription() const
  15059. {
  15060. return transactionNames [nextIndex];
  15061. }
  15062. bool UndoManager::undo()
  15063. {
  15064. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15065. if (commandSet == 0)
  15066. return false;
  15067. reentrancyCheck = true;
  15068. bool failed = false;
  15069. for (int i = commandSet->size(); --i >= 0;)
  15070. {
  15071. if (! commandSet->getUnchecked(i)->undo())
  15072. {
  15073. jassertfalse
  15074. failed = true;
  15075. break;
  15076. }
  15077. }
  15078. reentrancyCheck = false;
  15079. if (failed)
  15080. {
  15081. clearUndoHistory();
  15082. }
  15083. else
  15084. {
  15085. --nextIndex;
  15086. }
  15087. beginNewTransaction();
  15088. sendChangeMessage (this);
  15089. return true;
  15090. }
  15091. bool UndoManager::redo()
  15092. {
  15093. const OwnedArray<UndoableAction>* const commandSet = transactions [nextIndex];
  15094. if (commandSet == 0)
  15095. return false;
  15096. reentrancyCheck = true;
  15097. bool failed = false;
  15098. for (int i = 0; i < commandSet->size(); ++i)
  15099. {
  15100. if (! commandSet->getUnchecked(i)->perform())
  15101. {
  15102. jassertfalse
  15103. failed = true;
  15104. break;
  15105. }
  15106. }
  15107. reentrancyCheck = false;
  15108. if (failed)
  15109. {
  15110. clearUndoHistory();
  15111. }
  15112. else
  15113. {
  15114. ++nextIndex;
  15115. }
  15116. beginNewTransaction();
  15117. sendChangeMessage (this);
  15118. return true;
  15119. }
  15120. bool UndoManager::undoCurrentTransactionOnly()
  15121. {
  15122. return newTransaction ? false
  15123. : undo();
  15124. }
  15125. void UndoManager::getActionsInCurrentTransaction (Array <const UndoableAction*>& actionsFound) const
  15126. {
  15127. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15128. if (commandSet != 0 && ! newTransaction)
  15129. {
  15130. for (int i = 0; i < commandSet->size(); ++i)
  15131. actionsFound.add (commandSet->getUnchecked(i));
  15132. }
  15133. }
  15134. int UndoManager::getNumActionsInCurrentTransaction() const
  15135. {
  15136. const OwnedArray <UndoableAction>* const commandSet = transactions [nextIndex - 1];
  15137. if (commandSet != 0 && ! newTransaction)
  15138. return commandSet->size();
  15139. return 0;
  15140. }
  15141. END_JUCE_NAMESPACE
  15142. /*** End of inlined file: juce_UndoManager.cpp ***/
  15143. /*** Start of inlined file: juce_AiffAudioFormat.cpp ***/
  15144. BEGIN_JUCE_NAMESPACE
  15145. static const char* const aiffFormatName = "AIFF file";
  15146. static const tchar* const aiffExtensions[] = { T(".aiff"), T(".aif"), 0 };
  15147. class AiffAudioFormatReader : public AudioFormatReader
  15148. {
  15149. public:
  15150. int bytesPerFrame;
  15151. int64 dataChunkStart;
  15152. bool littleEndian;
  15153. AiffAudioFormatReader (InputStream* in)
  15154. : AudioFormatReader (in, TRANS (aiffFormatName))
  15155. {
  15156. if (input->readInt() == chunkName ("FORM"))
  15157. {
  15158. const int len = input->readIntBigEndian();
  15159. const int64 end = input->getPosition() + len;
  15160. const int nextType = input->readInt();
  15161. if (nextType == chunkName ("AIFF") || nextType == chunkName ("AIFC"))
  15162. {
  15163. bool hasGotVer = false;
  15164. bool hasGotData = false;
  15165. bool hasGotType = false;
  15166. while (input->getPosition() < end)
  15167. {
  15168. const int type = input->readInt();
  15169. const uint32 length = (uint32) input->readIntBigEndian();
  15170. const int64 chunkEnd = input->getPosition() + length;
  15171. if (type == chunkName ("FVER"))
  15172. {
  15173. hasGotVer = true;
  15174. const int ver = input->readIntBigEndian();
  15175. if (ver != 0 && ver != (int)0xa2805140)
  15176. break;
  15177. }
  15178. else if (type == chunkName ("COMM"))
  15179. {
  15180. hasGotType = true;
  15181. numChannels = (unsigned int)input->readShortBigEndian();
  15182. lengthInSamples = input->readIntBigEndian();
  15183. bitsPerSample = input->readShortBigEndian();
  15184. bytesPerFrame = (numChannels * bitsPerSample) >> 3;
  15185. unsigned char sampleRateBytes[10];
  15186. input->read (sampleRateBytes, 10);
  15187. const int byte0 = sampleRateBytes[0];
  15188. if ((byte0 & 0x80) != 0
  15189. || byte0 <= 0x3F || byte0 > 0x40
  15190. || (byte0 == 0x40 && sampleRateBytes[1] > 0x1C))
  15191. break;
  15192. unsigned int sampRate = ByteOrder::bigEndianInt ((char*) sampleRateBytes + 2);
  15193. sampRate >>= (16414 - ByteOrder::bigEndianShort ((char*) sampleRateBytes));
  15194. sampleRate = (int) sampRate;
  15195. if (length <= 18)
  15196. {
  15197. // some types don't have a chunk large enough to include a compression
  15198. // type, so assume it's just big-endian pcm
  15199. littleEndian = false;
  15200. }
  15201. else
  15202. {
  15203. const int compType = input->readInt();
  15204. if (compType == chunkName ("NONE") || compType == chunkName ("twos"))
  15205. {
  15206. littleEndian = false;
  15207. }
  15208. else if (compType == chunkName ("sowt"))
  15209. {
  15210. littleEndian = true;
  15211. }
  15212. else
  15213. {
  15214. sampleRate = 0;
  15215. break;
  15216. }
  15217. }
  15218. }
  15219. else if (type == chunkName ("SSND"))
  15220. {
  15221. hasGotData = true;
  15222. const int offset = input->readIntBigEndian();
  15223. dataChunkStart = input->getPosition() + 4 + offset;
  15224. lengthInSamples = (bytesPerFrame > 0) ? jmin (lengthInSamples, (int64) (length / bytesPerFrame)) : 0;
  15225. }
  15226. else if ((hasGotVer && hasGotData && hasGotType)
  15227. || chunkEnd < input->getPosition()
  15228. || input->isExhausted())
  15229. {
  15230. break;
  15231. }
  15232. input->setPosition (chunkEnd);
  15233. }
  15234. }
  15235. }
  15236. }
  15237. ~AiffAudioFormatReader()
  15238. {
  15239. }
  15240. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15241. int64 startSampleInFile, int numSamples)
  15242. {
  15243. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  15244. if (samplesAvailable < numSamples)
  15245. {
  15246. for (int i = numDestChannels; --i >= 0;)
  15247. if (destSamples[i] != 0)
  15248. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  15249. numSamples = (int) samplesAvailable;
  15250. }
  15251. if (numSamples <= 0)
  15252. return true;
  15253. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  15254. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  15255. char tempBuffer [tempBufSize];
  15256. while (numSamples > 0)
  15257. {
  15258. int* left = destSamples[0];
  15259. if (left != 0)
  15260. left += startOffsetInDestBuffer;
  15261. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  15262. if (right != 0)
  15263. right += startOffsetInDestBuffer;
  15264. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  15265. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  15266. if (bytesRead < numThisTime * bytesPerFrame)
  15267. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  15268. if (bitsPerSample == 16)
  15269. {
  15270. if (littleEndian)
  15271. {
  15272. const short* src = (const short*) tempBuffer;
  15273. if (numChannels > 1)
  15274. {
  15275. if (left == 0)
  15276. {
  15277. for (int i = numThisTime; --i >= 0;)
  15278. {
  15279. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15280. ++src;
  15281. }
  15282. }
  15283. else if (right == 0)
  15284. {
  15285. for (int i = numThisTime; --i >= 0;)
  15286. {
  15287. ++src;
  15288. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15289. }
  15290. }
  15291. else
  15292. {
  15293. for (int i = numThisTime; --i >= 0;)
  15294. {
  15295. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15296. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15297. }
  15298. }
  15299. }
  15300. else
  15301. {
  15302. for (int i = numThisTime; --i >= 0;)
  15303. {
  15304. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  15305. }
  15306. }
  15307. }
  15308. else
  15309. {
  15310. const char* src = (const char*) tempBuffer;
  15311. if (numChannels > 1)
  15312. {
  15313. if (left == 0)
  15314. {
  15315. for (int i = numThisTime; --i >= 0;)
  15316. {
  15317. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15318. src += 4;
  15319. }
  15320. }
  15321. else if (right == 0)
  15322. {
  15323. for (int i = numThisTime; --i >= 0;)
  15324. {
  15325. src += 2;
  15326. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15327. src += 2;
  15328. }
  15329. }
  15330. else
  15331. {
  15332. for (int i = numThisTime; --i >= 0;)
  15333. {
  15334. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15335. src += 2;
  15336. *right++ = ByteOrder::bigEndianShort (src) << 16;
  15337. src += 2;
  15338. }
  15339. }
  15340. }
  15341. else
  15342. {
  15343. for (int i = numThisTime; --i >= 0;)
  15344. {
  15345. *left++ = ByteOrder::bigEndianShort (src) << 16;
  15346. src += 2;
  15347. }
  15348. }
  15349. }
  15350. }
  15351. else if (bitsPerSample == 24)
  15352. {
  15353. const char* src = (const char*)tempBuffer;
  15354. if (littleEndian)
  15355. {
  15356. if (numChannels > 1)
  15357. {
  15358. if (left == 0)
  15359. {
  15360. for (int i = numThisTime; --i >= 0;)
  15361. {
  15362. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15363. src += 6;
  15364. }
  15365. }
  15366. else if (right == 0)
  15367. {
  15368. for (int i = numThisTime; --i >= 0;)
  15369. {
  15370. src += 3;
  15371. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15372. src += 3;
  15373. }
  15374. }
  15375. else
  15376. {
  15377. for (int i = numThisTime; --i >= 0;)
  15378. {
  15379. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15380. src += 3;
  15381. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  15382. src += 3;
  15383. }
  15384. }
  15385. }
  15386. else
  15387. {
  15388. for (int i = numThisTime; --i >= 0;)
  15389. {
  15390. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  15391. src += 3;
  15392. }
  15393. }
  15394. }
  15395. else
  15396. {
  15397. if (numChannels > 1)
  15398. {
  15399. if (left == 0)
  15400. {
  15401. for (int i = numThisTime; --i >= 0;)
  15402. {
  15403. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15404. src += 6;
  15405. }
  15406. }
  15407. else if (right == 0)
  15408. {
  15409. for (int i = numThisTime; --i >= 0;)
  15410. {
  15411. src += 3;
  15412. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15413. src += 3;
  15414. }
  15415. }
  15416. else
  15417. {
  15418. for (int i = numThisTime; --i >= 0;)
  15419. {
  15420. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15421. src += 3;
  15422. *right++ = ByteOrder::bigEndian24Bit (src) << 8;
  15423. src += 3;
  15424. }
  15425. }
  15426. }
  15427. else
  15428. {
  15429. for (int i = numThisTime; --i >= 0;)
  15430. {
  15431. *left++ = ByteOrder::bigEndian24Bit (src) << 8;
  15432. src += 3;
  15433. }
  15434. }
  15435. }
  15436. }
  15437. else if (bitsPerSample == 32)
  15438. {
  15439. const unsigned int* src = (const unsigned int*) tempBuffer;
  15440. unsigned int* l = (unsigned int*) left;
  15441. unsigned int* r = (unsigned int*) right;
  15442. if (littleEndian)
  15443. {
  15444. if (numChannels > 1)
  15445. {
  15446. if (l == 0)
  15447. {
  15448. for (int i = numThisTime; --i >= 0;)
  15449. {
  15450. ++src;
  15451. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15452. }
  15453. }
  15454. else if (r == 0)
  15455. {
  15456. for (int i = numThisTime; --i >= 0;)
  15457. {
  15458. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15459. ++src;
  15460. }
  15461. }
  15462. else
  15463. {
  15464. for (int i = numThisTime; --i >= 0;)
  15465. {
  15466. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15467. *r++ = ByteOrder::swapIfBigEndian (*src++);
  15468. }
  15469. }
  15470. }
  15471. else
  15472. {
  15473. for (int i = numThisTime; --i >= 0;)
  15474. {
  15475. *l++ = ByteOrder::swapIfBigEndian (*src++);
  15476. }
  15477. }
  15478. }
  15479. else
  15480. {
  15481. if (numChannels > 1)
  15482. {
  15483. if (l == 0)
  15484. {
  15485. for (int i = numThisTime; --i >= 0;)
  15486. {
  15487. ++src;
  15488. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15489. }
  15490. }
  15491. else if (r == 0)
  15492. {
  15493. for (int i = numThisTime; --i >= 0;)
  15494. {
  15495. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15496. ++src;
  15497. }
  15498. }
  15499. else
  15500. {
  15501. for (int i = numThisTime; --i >= 0;)
  15502. {
  15503. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15504. *r++ = ByteOrder::swapIfLittleEndian (*src++);
  15505. }
  15506. }
  15507. }
  15508. else
  15509. {
  15510. for (int i = numThisTime; --i >= 0;)
  15511. {
  15512. *l++ = ByteOrder::swapIfLittleEndian (*src++);
  15513. }
  15514. }
  15515. }
  15516. left = (int*) l;
  15517. right = (int*) r;
  15518. }
  15519. else if (bitsPerSample == 8)
  15520. {
  15521. const char* src = (const char*) tempBuffer;
  15522. if (numChannels > 1)
  15523. {
  15524. if (left == 0)
  15525. {
  15526. for (int i = numThisTime; --i >= 0;)
  15527. {
  15528. *right++ = ((int) *src++) << 24;
  15529. ++src;
  15530. }
  15531. }
  15532. else if (right == 0)
  15533. {
  15534. for (int i = numThisTime; --i >= 0;)
  15535. {
  15536. ++src;
  15537. *left++ = ((int) *src++) << 24;
  15538. }
  15539. }
  15540. else
  15541. {
  15542. for (int i = numThisTime; --i >= 0;)
  15543. {
  15544. *left++ = ((int) *src++) << 24;
  15545. *right++ = ((int) *src++) << 24;
  15546. }
  15547. }
  15548. }
  15549. else
  15550. {
  15551. for (int i = numThisTime; --i >= 0;)
  15552. {
  15553. *left++ = ((int) *src++) << 24;
  15554. }
  15555. }
  15556. }
  15557. startOffsetInDestBuffer += numThisTime;
  15558. numSamples -= numThisTime;
  15559. }
  15560. if (numSamples > 0)
  15561. {
  15562. for (int i = numDestChannels; --i >= 0;)
  15563. if (destSamples[i] != 0)
  15564. zeromem (destSamples[i] + startOffsetInDestBuffer,
  15565. sizeof (int) * numSamples);
  15566. }
  15567. return true;
  15568. }
  15569. juce_UseDebuggingNewOperator
  15570. private:
  15571. AiffAudioFormatReader (const AiffAudioFormatReader&);
  15572. AiffAudioFormatReader& operator= (const AiffAudioFormatReader&);
  15573. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15574. };
  15575. class AiffAudioFormatWriter : public AudioFormatWriter
  15576. {
  15577. MemoryBlock tempBlock;
  15578. uint32 lengthInSamples, bytesWritten;
  15579. int64 headerPosition;
  15580. bool writeFailed;
  15581. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  15582. AiffAudioFormatWriter (const AiffAudioFormatWriter&);
  15583. AiffAudioFormatWriter& operator= (const AiffAudioFormatWriter&);
  15584. void writeHeader()
  15585. {
  15586. const bool couldSeekOk = output->setPosition (headerPosition);
  15587. (void) couldSeekOk;
  15588. // if this fails, you've given it an output stream that can't seek! It needs
  15589. // to be able to seek back to write the header
  15590. jassert (couldSeekOk);
  15591. const int headerLen = 54;
  15592. int audioBytes = lengthInSamples * ((bitsPerSample * numChannels) / 8);
  15593. audioBytes += (audioBytes & 1);
  15594. output->writeInt (chunkName ("FORM"));
  15595. output->writeIntBigEndian (headerLen + audioBytes - 8);
  15596. output->writeInt (chunkName ("AIFF"));
  15597. output->writeInt (chunkName ("COMM"));
  15598. output->writeIntBigEndian (18);
  15599. output->writeShortBigEndian ((short) numChannels);
  15600. output->writeIntBigEndian (lengthInSamples);
  15601. output->writeShortBigEndian ((short) bitsPerSample);
  15602. uint8 sampleRateBytes[10];
  15603. zeromem (sampleRateBytes, 10);
  15604. if (sampleRate <= 1)
  15605. {
  15606. sampleRateBytes[0] = 0x3f;
  15607. sampleRateBytes[1] = 0xff;
  15608. sampleRateBytes[2] = 0x80;
  15609. }
  15610. else
  15611. {
  15612. int mask = 0x40000000;
  15613. sampleRateBytes[0] = 0x40;
  15614. if (sampleRate >= mask)
  15615. {
  15616. jassertfalse
  15617. sampleRateBytes[1] = 0x1d;
  15618. }
  15619. else
  15620. {
  15621. int n = (int) sampleRate;
  15622. int i;
  15623. for (i = 0; i <= 32 ; ++i)
  15624. {
  15625. if ((n & mask) != 0)
  15626. break;
  15627. mask >>= 1;
  15628. }
  15629. n = n << (i + 1);
  15630. sampleRateBytes[1] = (uint8) (29 - i);
  15631. sampleRateBytes[2] = (uint8) ((n >> 24) & 0xff);
  15632. sampleRateBytes[3] = (uint8) ((n >> 16) & 0xff);
  15633. sampleRateBytes[4] = (uint8) ((n >> 8) & 0xff);
  15634. sampleRateBytes[5] = (uint8) (n & 0xff);
  15635. }
  15636. }
  15637. output->write (sampleRateBytes, 10);
  15638. output->writeInt (chunkName ("SSND"));
  15639. output->writeIntBigEndian (audioBytes + 8);
  15640. output->writeInt (0);
  15641. output->writeInt (0);
  15642. jassert (output->getPosition() == headerLen);
  15643. }
  15644. public:
  15645. AiffAudioFormatWriter (OutputStream* out,
  15646. const double sampleRate_,
  15647. const unsigned int chans,
  15648. const int bits)
  15649. : AudioFormatWriter (out,
  15650. TRANS (aiffFormatName),
  15651. sampleRate_,
  15652. chans,
  15653. bits),
  15654. lengthInSamples (0),
  15655. bytesWritten (0),
  15656. writeFailed (false)
  15657. {
  15658. headerPosition = out->getPosition();
  15659. writeHeader();
  15660. }
  15661. ~AiffAudioFormatWriter()
  15662. {
  15663. if ((bytesWritten & 1) != 0)
  15664. output->writeByte (0);
  15665. writeHeader();
  15666. }
  15667. bool write (const int** data, int numSamples)
  15668. {
  15669. if (writeFailed)
  15670. return false;
  15671. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  15672. tempBlock.ensureSize (bytes, false);
  15673. char* buffer = (char*) tempBlock.getData();
  15674. const int* left = data[0];
  15675. const int* right = data[1];
  15676. if (right == 0)
  15677. right = left;
  15678. if (bitsPerSample == 16)
  15679. {
  15680. short* b = (short*) buffer;
  15681. if (numChannels > 1)
  15682. {
  15683. for (int i = numSamples; --i >= 0;)
  15684. {
  15685. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15686. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*right++ >> 16));
  15687. }
  15688. }
  15689. else
  15690. {
  15691. for (int i = numSamples; --i >= 0;)
  15692. {
  15693. *b++ = (short) ByteOrder::swapIfLittleEndian ((uint16) (*left++ >> 16));
  15694. }
  15695. }
  15696. }
  15697. else if (bitsPerSample == 24)
  15698. {
  15699. char* b = (char*) buffer;
  15700. if (numChannels > 1)
  15701. {
  15702. for (int i = numSamples; --i >= 0;)
  15703. {
  15704. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15705. b += 3;
  15706. ByteOrder::bigEndian24BitToChars (*right++ >> 8, b);
  15707. b += 3;
  15708. }
  15709. }
  15710. else
  15711. {
  15712. for (int i = numSamples; --i >= 0;)
  15713. {
  15714. ByteOrder::bigEndian24BitToChars (*left++ >> 8, b);
  15715. b += 3;
  15716. }
  15717. }
  15718. }
  15719. else if (bitsPerSample == 32)
  15720. {
  15721. uint32* b = (uint32*) buffer;
  15722. if (numChannels > 1)
  15723. {
  15724. for (int i = numSamples; --i >= 0;)
  15725. {
  15726. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15727. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *right++);
  15728. }
  15729. }
  15730. else
  15731. {
  15732. for (int i = numSamples; --i >= 0;)
  15733. {
  15734. *b++ = ByteOrder::swapIfLittleEndian ((uint32) *left++);
  15735. }
  15736. }
  15737. }
  15738. else if (bitsPerSample == 8)
  15739. {
  15740. char* b = (char*) buffer;
  15741. if (numChannels > 1)
  15742. {
  15743. for (int i = numSamples; --i >= 0;)
  15744. {
  15745. *b++ = (char) (*left++ >> 24);
  15746. *b++ = (char) (*right++ >> 24);
  15747. }
  15748. }
  15749. else
  15750. {
  15751. for (int i = numSamples; --i >= 0;)
  15752. {
  15753. *b++ = (char) (*left++ >> 24);
  15754. }
  15755. }
  15756. }
  15757. if (bytesWritten + bytes >= (uint32) 0xfff00000
  15758. || ! output->write (buffer, bytes))
  15759. {
  15760. // failed to write to disk, so let's try writing the header.
  15761. // If it's just run out of disk space, then if it does manage
  15762. // to write the header, we'll still have a useable file..
  15763. writeHeader();
  15764. writeFailed = true;
  15765. return false;
  15766. }
  15767. else
  15768. {
  15769. bytesWritten += bytes;
  15770. lengthInSamples += numSamples;
  15771. return true;
  15772. }
  15773. }
  15774. juce_UseDebuggingNewOperator
  15775. };
  15776. AiffAudioFormat::AiffAudioFormat()
  15777. : AudioFormat (TRANS (aiffFormatName), (const tchar**) aiffExtensions)
  15778. {
  15779. }
  15780. AiffAudioFormat::~AiffAudioFormat()
  15781. {
  15782. }
  15783. const Array <int> AiffAudioFormat::getPossibleSampleRates()
  15784. {
  15785. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  15786. return Array <int> (rates);
  15787. }
  15788. const Array <int> AiffAudioFormat::getPossibleBitDepths()
  15789. {
  15790. const int depths[] = { 8, 16, 24, 0 };
  15791. return Array <int> (depths);
  15792. }
  15793. bool AiffAudioFormat::canDoStereo()
  15794. {
  15795. return true;
  15796. }
  15797. bool AiffAudioFormat::canDoMono()
  15798. {
  15799. return true;
  15800. }
  15801. #if JUCE_MAC
  15802. bool AiffAudioFormat::canHandleFile (const File& f)
  15803. {
  15804. if (AudioFormat::canHandleFile (f))
  15805. return true;
  15806. const OSType type = PlatformUtilities::getTypeOfFile (f.getFullPathName());
  15807. return type == 'AIFF' || type == 'AIFC'
  15808. || type == 'aiff' || type == 'aifc';
  15809. }
  15810. #endif
  15811. AudioFormatReader* AiffAudioFormat::createReaderFor (InputStream* sourceStream,
  15812. const bool deleteStreamIfOpeningFails)
  15813. {
  15814. ScopedPointer <AiffAudioFormatReader> w (new AiffAudioFormatReader (sourceStream));
  15815. if (w->sampleRate != 0)
  15816. return w.release();
  15817. if (! deleteStreamIfOpeningFails)
  15818. w->input = 0;
  15819. return 0;
  15820. }
  15821. AudioFormatWriter* AiffAudioFormat::createWriterFor (OutputStream* out,
  15822. double sampleRate,
  15823. unsigned int chans,
  15824. int bitsPerSample,
  15825. const StringPairArray& /*metadataValues*/,
  15826. int /*qualityOptionIndex*/)
  15827. {
  15828. if (getPossibleBitDepths().contains (bitsPerSample))
  15829. {
  15830. return new AiffAudioFormatWriter (out,
  15831. sampleRate,
  15832. chans,
  15833. bitsPerSample);
  15834. }
  15835. return 0;
  15836. }
  15837. END_JUCE_NAMESPACE
  15838. /*** End of inlined file: juce_AiffAudioFormat.cpp ***/
  15839. /*** Start of inlined file: juce_AudioCDReader.cpp ***/
  15840. BEGIN_JUCE_NAMESPACE
  15841. #if JUCE_MAC && JUCE_USE_CDREADER
  15842. // Mac version doesn't need any native code because it's all done with files..
  15843. // Windows + Linux versions are in the platform-dependent code sections.
  15844. static void findCDs (Array<File>& cds)
  15845. {
  15846. File volumes ("/Volumes");
  15847. volumes.findChildFiles (cds, File::findDirectories, false);
  15848. for (int i = cds.size(); --i >= 0;)
  15849. if (! cds.getReference(i).getChildFile (".TOC.plist").exists())
  15850. cds.remove (i);
  15851. }
  15852. const StringArray AudioCDReader::getAvailableCDNames()
  15853. {
  15854. Array<File> cds;
  15855. findCDs (cds);
  15856. StringArray names;
  15857. for (int i = 0; i < cds.size(); ++i)
  15858. names.add (cds.getReference(i).getFileName());
  15859. return names;
  15860. }
  15861. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  15862. {
  15863. Array<File> cds;
  15864. findCDs (cds);
  15865. if (cds[index] != File::nonexistent)
  15866. return new AudioCDReader (cds[index]);
  15867. else
  15868. return 0;
  15869. }
  15870. AudioCDReader::AudioCDReader (const File& volume)
  15871. : AudioFormatReader (0, "CD Audio"),
  15872. volumeDir (volume),
  15873. currentReaderTrack (-1),
  15874. reader (0)
  15875. {
  15876. sampleRate = 44100.0;
  15877. bitsPerSample = 16;
  15878. numChannels = 2;
  15879. usesFloatingPointData = false;
  15880. refreshTrackLengths();
  15881. }
  15882. AudioCDReader::~AudioCDReader()
  15883. {
  15884. }
  15885. static int getTrackNumber (const File& file)
  15886. {
  15887. return file.getFileName()
  15888. .initialSectionContainingOnly (T("0123456789"))
  15889. .getIntValue();
  15890. }
  15891. int AudioCDReader::compareElements (const File& first, const File& second)
  15892. {
  15893. const int firstTrack = getTrackNumber (first);
  15894. const int secondTrack = getTrackNumber (second);
  15895. jassert (firstTrack > 0 && secondTrack > 0);
  15896. return firstTrack - secondTrack;
  15897. }
  15898. void AudioCDReader::refreshTrackLengths()
  15899. {
  15900. tracks.clear();
  15901. trackStartSamples.clear();
  15902. volumeDir.findChildFiles (tracks, File::findFiles | File::ignoreHiddenFiles, false, T("*.aiff"));
  15903. tracks.sort (*this);
  15904. AiffAudioFormat format;
  15905. int sample = 0;
  15906. for (int i = 0; i < tracks.size(); ++i)
  15907. {
  15908. trackStartSamples.add (sample);
  15909. FileInputStream* const in = tracks.getReference(i).createInputStream();
  15910. if (in != 0)
  15911. {
  15912. ScopedPointer <AudioFormatReader> r (format.createReaderFor (in, true));
  15913. if (r != 0)
  15914. sample += (int) r->lengthInSamples;
  15915. }
  15916. }
  15917. trackStartSamples.add (sample);
  15918. lengthInSamples = sample;
  15919. }
  15920. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  15921. int64 startSampleInFile, int numSamples)
  15922. {
  15923. while (numSamples > 0)
  15924. {
  15925. int track = -1;
  15926. for (int i = 0; i < trackStartSamples.size() - 1; ++i)
  15927. {
  15928. if (startSampleInFile < trackStartSamples.getUnchecked (i + 1))
  15929. {
  15930. track = i;
  15931. break;
  15932. }
  15933. }
  15934. if (track < 0)
  15935. return false;
  15936. if (track != currentReaderTrack)
  15937. {
  15938. reader = 0;
  15939. FileInputStream* const in = tracks [track].createInputStream();
  15940. if (in != 0)
  15941. {
  15942. BufferedInputStream* const bin = new BufferedInputStream (in, 65536, true);
  15943. AiffAudioFormat format;
  15944. reader = format.createReaderFor (bin, true);
  15945. if (reader == 0)
  15946. currentReaderTrack = -1;
  15947. else
  15948. currentReaderTrack = track;
  15949. }
  15950. }
  15951. if (reader == 0)
  15952. return false;
  15953. const int startPos = (int) (startSampleInFile - trackStartSamples.getUnchecked (track));
  15954. const int numAvailable = (int) jmin ((int64) numSamples, reader->lengthInSamples - startPos);
  15955. reader->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer, startPos, numAvailable);
  15956. numSamples -= numAvailable;
  15957. startSampleInFile += numAvailable;
  15958. }
  15959. return true;
  15960. }
  15961. bool AudioCDReader::isCDStillPresent() const
  15962. {
  15963. return volumeDir.exists();
  15964. }
  15965. int AudioCDReader::getNumTracks() const
  15966. {
  15967. return tracks.size();
  15968. }
  15969. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  15970. {
  15971. return trackStartSamples [trackNum];
  15972. }
  15973. bool AudioCDReader::isTrackAudio (int trackNum) const
  15974. {
  15975. return tracks [trackNum] != File::nonexistent;
  15976. }
  15977. void AudioCDReader::enableIndexScanning (bool b)
  15978. {
  15979. // any way to do this on a Mac??
  15980. }
  15981. int AudioCDReader::getLastIndex() const
  15982. {
  15983. return 0;
  15984. }
  15985. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  15986. {
  15987. return Array <int>();
  15988. }
  15989. int AudioCDReader::getCDDBId()
  15990. {
  15991. return 0; //xxx
  15992. }
  15993. #endif
  15994. END_JUCE_NAMESPACE
  15995. /*** End of inlined file: juce_AudioCDReader.cpp ***/
  15996. /*** Start of inlined file: juce_AudioFormat.cpp ***/
  15997. BEGIN_JUCE_NAMESPACE
  15998. AudioFormatReader::AudioFormatReader (InputStream* const in,
  15999. const String& formatName_)
  16000. : sampleRate (0),
  16001. bitsPerSample (0),
  16002. lengthInSamples (0),
  16003. numChannels (0),
  16004. usesFloatingPointData (false),
  16005. input (in),
  16006. formatName (formatName_)
  16007. {
  16008. }
  16009. AudioFormatReader::~AudioFormatReader()
  16010. {
  16011. delete input;
  16012. }
  16013. bool AudioFormatReader::read (int** destSamples,
  16014. int numDestChannels,
  16015. int64 startSampleInSource,
  16016. int numSamplesToRead,
  16017. const bool fillLeftoverChannelsWithCopies)
  16018. {
  16019. jassert (numDestChannels > 0); // you have to actually give this some channels to work with!
  16020. int startOffsetInDestBuffer = 0;
  16021. if (startSampleInSource < 0)
  16022. {
  16023. const int silence = (int) jmin (-startSampleInSource, (int64) numSamplesToRead);
  16024. for (int i = numDestChannels; --i >= 0;)
  16025. if (destSamples[i] != 0)
  16026. zeromem (destSamples[i], sizeof (int) * silence);
  16027. startOffsetInDestBuffer += silence;
  16028. numSamplesToRead -= silence;
  16029. startSampleInSource = 0;
  16030. }
  16031. if (numSamplesToRead <= 0)
  16032. return true;
  16033. if (! readSamples (destSamples, jmin ((int) numChannels, numDestChannels), startOffsetInDestBuffer,
  16034. startSampleInSource, numSamplesToRead))
  16035. return false;
  16036. if (numDestChannels > (int) numChannels)
  16037. {
  16038. if (fillLeftoverChannelsWithCopies)
  16039. {
  16040. int* lastFullChannel = destSamples[0];
  16041. for (int i = numDestChannels; --i > 0;)
  16042. {
  16043. if (destSamples[i] != 0)
  16044. {
  16045. lastFullChannel = destSamples[i];
  16046. break;
  16047. }
  16048. }
  16049. if (lastFullChannel != 0)
  16050. for (int i = numChannels; i < numDestChannels; ++i)
  16051. if (destSamples[i] != 0)
  16052. memcpy (destSamples[i], lastFullChannel, sizeof (int) * numSamplesToRead);
  16053. }
  16054. else
  16055. {
  16056. for (int i = numChannels; i < numDestChannels; ++i)
  16057. if (destSamples[i] != 0)
  16058. zeromem (destSamples[i], sizeof (int) * numSamplesToRead);
  16059. }
  16060. }
  16061. return true;
  16062. }
  16063. static void findAudioBufferMaxMin (const float* const buffer, const int num, float& maxVal, float& minVal) throw()
  16064. {
  16065. float mn = buffer[0];
  16066. float mx = mn;
  16067. for (int i = 1; i < num; ++i)
  16068. {
  16069. const float s = buffer[i];
  16070. if (s > mx) mx = s;
  16071. if (s < mn) mn = s;
  16072. }
  16073. maxVal = mx;
  16074. minVal = mn;
  16075. }
  16076. void AudioFormatReader::readMaxLevels (int64 startSampleInFile,
  16077. int64 numSamples,
  16078. float& lowestLeft, float& highestLeft,
  16079. float& lowestRight, float& highestRight)
  16080. {
  16081. if (numSamples <= 0)
  16082. {
  16083. lowestLeft = 0;
  16084. lowestRight = 0;
  16085. highestLeft = 0;
  16086. highestRight = 0;
  16087. return;
  16088. }
  16089. const int bufferSize = (int) jmin (numSamples, (int64) 4096);
  16090. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  16091. int* tempBuffer[3];
  16092. tempBuffer[0] = (int*) tempSpace.getData();
  16093. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  16094. tempBuffer[2] = 0;
  16095. if (usesFloatingPointData)
  16096. {
  16097. float lmin = 1.0e6f;
  16098. float lmax = -lmin;
  16099. float rmin = lmin;
  16100. float rmax = lmax;
  16101. while (numSamples > 0)
  16102. {
  16103. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  16104. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  16105. numSamples -= numToDo;
  16106. startSampleInFile += numToDo;
  16107. float bufmin, bufmax;
  16108. findAudioBufferMaxMin ((float*) tempBuffer[0], numToDo, bufmax, bufmin);
  16109. lmin = jmin (lmin, bufmin);
  16110. lmax = jmax (lmax, bufmax);
  16111. if (numChannels > 1)
  16112. {
  16113. findAudioBufferMaxMin ((float*) tempBuffer[1], numToDo, bufmax, bufmin);
  16114. rmin = jmin (rmin, bufmin);
  16115. rmax = jmax (rmax, bufmax);
  16116. }
  16117. }
  16118. if (numChannels <= 1)
  16119. {
  16120. rmax = lmax;
  16121. rmin = lmin;
  16122. }
  16123. lowestLeft = lmin;
  16124. highestLeft = lmax;
  16125. lowestRight = rmin;
  16126. highestRight = rmax;
  16127. }
  16128. else
  16129. {
  16130. int lmax = std::numeric_limits<int>::min();
  16131. int lmin = std::numeric_limits<int>::max();
  16132. int rmax = std::numeric_limits<int>::min();
  16133. int rmin = std::numeric_limits<int>::max();
  16134. while (numSamples > 0)
  16135. {
  16136. const int numToDo = (int) jmin (numSamples, (int64) bufferSize);
  16137. read ((int**) tempBuffer, 2, startSampleInFile, numToDo, false);
  16138. numSamples -= numToDo;
  16139. startSampleInFile += numToDo;
  16140. for (int j = numChannels; --j >= 0;)
  16141. {
  16142. int bufMax = std::numeric_limits<int>::min();
  16143. int bufMin = std::numeric_limits<int>::max();
  16144. const int* const b = tempBuffer[j];
  16145. for (int i = 0; i < numToDo; ++i)
  16146. {
  16147. const int samp = b[i];
  16148. if (samp < bufMin)
  16149. bufMin = samp;
  16150. if (samp > bufMax)
  16151. bufMax = samp;
  16152. }
  16153. if (j == 0)
  16154. {
  16155. lmax = jmax (lmax, bufMax);
  16156. lmin = jmin (lmin, bufMin);
  16157. }
  16158. else
  16159. {
  16160. rmax = jmax (rmax, bufMax);
  16161. rmin = jmin (rmin, bufMin);
  16162. }
  16163. }
  16164. }
  16165. if (numChannels <= 1)
  16166. {
  16167. rmax = lmax;
  16168. rmin = lmin;
  16169. }
  16170. lowestLeft = lmin / (float) std::numeric_limits<int>::max();
  16171. highestLeft = lmax / (float) std::numeric_limits<int>::max();
  16172. lowestRight = rmin / (float) std::numeric_limits<int>::max();
  16173. highestRight = rmax / (float) std::numeric_limits<int>::max();
  16174. }
  16175. }
  16176. int64 AudioFormatReader::searchForLevel (int64 startSample,
  16177. int64 numSamplesToSearch,
  16178. const double magnitudeRangeMinimum,
  16179. const double magnitudeRangeMaximum,
  16180. const int minimumConsecutiveSamples)
  16181. {
  16182. if (numSamplesToSearch == 0)
  16183. return -1;
  16184. const int bufferSize = 4096;
  16185. MemoryBlock tempSpace (bufferSize * sizeof (int) * 2 + 64);
  16186. int* tempBuffer[3];
  16187. tempBuffer[0] = (int*) tempSpace.getData();
  16188. tempBuffer[1] = ((int*) tempSpace.getData()) + bufferSize;
  16189. tempBuffer[2] = 0;
  16190. int consecutive = 0;
  16191. int64 firstMatchPos = -1;
  16192. jassert (magnitudeRangeMaximum > magnitudeRangeMinimum);
  16193. const double doubleMin = jlimit (0.0, (double) std::numeric_limits<int>::max(), magnitudeRangeMinimum * std::numeric_limits<int>::max());
  16194. const double doubleMax = jlimit (doubleMin, (double) std::numeric_limits<int>::max(), magnitudeRangeMaximum * std::numeric_limits<int>::max());
  16195. const int intMagnitudeRangeMinimum = roundToInt (doubleMin);
  16196. const int intMagnitudeRangeMaximum = roundToInt (doubleMax);
  16197. while (numSamplesToSearch != 0)
  16198. {
  16199. const int numThisTime = (int) jmin (abs64 (numSamplesToSearch), (int64) bufferSize);
  16200. int64 bufferStart = startSample;
  16201. if (numSamplesToSearch < 0)
  16202. bufferStart -= numThisTime;
  16203. if (bufferStart >= (int) lengthInSamples)
  16204. break;
  16205. read ((int**) tempBuffer, 2, bufferStart, numThisTime, false);
  16206. int num = numThisTime;
  16207. while (--num >= 0)
  16208. {
  16209. if (numSamplesToSearch < 0)
  16210. --startSample;
  16211. bool matches = false;
  16212. const int index = (int) (startSample - bufferStart);
  16213. if (usesFloatingPointData)
  16214. {
  16215. const float sample1 = fabsf (((float*) tempBuffer[0]) [index]);
  16216. if (sample1 >= magnitudeRangeMinimum
  16217. && sample1 <= magnitudeRangeMaximum)
  16218. {
  16219. matches = true;
  16220. }
  16221. else if (numChannels > 1)
  16222. {
  16223. const float sample2 = fabsf (((float*) tempBuffer[1]) [index]);
  16224. matches = (sample2 >= magnitudeRangeMinimum
  16225. && sample2 <= magnitudeRangeMaximum);
  16226. }
  16227. }
  16228. else
  16229. {
  16230. const int sample1 = abs (tempBuffer[0] [index]);
  16231. if (sample1 >= intMagnitudeRangeMinimum
  16232. && sample1 <= intMagnitudeRangeMaximum)
  16233. {
  16234. matches = true;
  16235. }
  16236. else if (numChannels > 1)
  16237. {
  16238. const int sample2 = abs (tempBuffer[1][index]);
  16239. matches = (sample2 >= intMagnitudeRangeMinimum
  16240. && sample2 <= intMagnitudeRangeMaximum);
  16241. }
  16242. }
  16243. if (matches)
  16244. {
  16245. if (firstMatchPos < 0)
  16246. firstMatchPos = startSample;
  16247. if (++consecutive >= minimumConsecutiveSamples)
  16248. {
  16249. if (firstMatchPos < 0 || firstMatchPos >= lengthInSamples)
  16250. return -1;
  16251. return firstMatchPos;
  16252. }
  16253. }
  16254. else
  16255. {
  16256. consecutive = 0;
  16257. firstMatchPos = -1;
  16258. }
  16259. if (numSamplesToSearch > 0)
  16260. ++startSample;
  16261. }
  16262. if (numSamplesToSearch > 0)
  16263. numSamplesToSearch -= numThisTime;
  16264. else
  16265. numSamplesToSearch += numThisTime;
  16266. }
  16267. return -1;
  16268. }
  16269. AudioFormatWriter::AudioFormatWriter (OutputStream* const out,
  16270. const String& formatName_,
  16271. const double rate,
  16272. const unsigned int numChannels_,
  16273. const unsigned int bitsPerSample_)
  16274. : sampleRate (rate),
  16275. numChannels (numChannels_),
  16276. bitsPerSample (bitsPerSample_),
  16277. usesFloatingPointData (false),
  16278. output (out),
  16279. formatName (formatName_)
  16280. {
  16281. }
  16282. AudioFormatWriter::~AudioFormatWriter()
  16283. {
  16284. delete output;
  16285. }
  16286. bool AudioFormatWriter::writeFromAudioReader (AudioFormatReader& reader,
  16287. int64 startSample,
  16288. int64 numSamplesToRead)
  16289. {
  16290. const int bufferSize = 16384;
  16291. const int maxChans = 128;
  16292. AudioSampleBuffer tempBuffer (reader.numChannels, bufferSize);
  16293. int* buffers [maxChans];
  16294. for (int i = maxChans; --i >= 0;)
  16295. buffers[i] = 0;
  16296. if (numSamplesToRead < 0)
  16297. numSamplesToRead = reader.lengthInSamples;
  16298. while (numSamplesToRead > 0)
  16299. {
  16300. const int numToDo = (int) jmin (numSamplesToRead, (int64) bufferSize);
  16301. for (int i = tempBuffer.getNumChannels(); --i >= 0;)
  16302. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16303. if (! reader.read (buffers, maxChans, startSample, numToDo, false))
  16304. return false;
  16305. if (reader.usesFloatingPointData != isFloatingPoint())
  16306. {
  16307. int** bufferChan = buffers;
  16308. while (*bufferChan != 0)
  16309. {
  16310. int* b = *bufferChan++;
  16311. if (isFloatingPoint())
  16312. {
  16313. // int -> float
  16314. const double factor = 1.0 / std::numeric_limits<int>::max();
  16315. for (int i = 0; i < numToDo; ++i)
  16316. ((float*) b)[i] = (float) (factor * b[i]);
  16317. }
  16318. else
  16319. {
  16320. // float -> int
  16321. for (int i = 0; i < numToDo; ++i)
  16322. {
  16323. const double samp = *(const float*) b;
  16324. if (samp <= -1.0)
  16325. *b++ = std::numeric_limits<int>::min();
  16326. else if (samp >= 1.0)
  16327. *b++ = std::numeric_limits<int>::max();
  16328. else
  16329. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16330. }
  16331. }
  16332. }
  16333. }
  16334. if (! write ((const int**) buffers, numToDo))
  16335. return false;
  16336. numSamplesToRead -= numToDo;
  16337. startSample += numToDo;
  16338. }
  16339. return true;
  16340. }
  16341. bool AudioFormatWriter::writeFromAudioSource (AudioSource& source,
  16342. int numSamplesToRead,
  16343. const int samplesPerBlock)
  16344. {
  16345. const int maxChans = 128;
  16346. AudioSampleBuffer tempBuffer (getNumChannels(), samplesPerBlock);
  16347. int* buffers [maxChans];
  16348. while (numSamplesToRead > 0)
  16349. {
  16350. const int numToDo = jmin (numSamplesToRead, samplesPerBlock);
  16351. AudioSourceChannelInfo info;
  16352. info.buffer = &tempBuffer;
  16353. info.startSample = 0;
  16354. info.numSamples = numToDo;
  16355. info.clearActiveBufferRegion();
  16356. source.getNextAudioBlock (info);
  16357. int i;
  16358. for (i = maxChans; --i >= 0;)
  16359. buffers[i] = 0;
  16360. for (i = tempBuffer.getNumChannels(); --i >= 0;)
  16361. buffers[i] = (int*) tempBuffer.getSampleData (i, 0);
  16362. if (! isFloatingPoint())
  16363. {
  16364. int** bufferChan = buffers;
  16365. while (*bufferChan != 0)
  16366. {
  16367. int* b = *bufferChan++;
  16368. // float -> int
  16369. for (int j = numToDo; --j >= 0;)
  16370. {
  16371. const double samp = *(const float*) b;
  16372. if (samp <= -1.0)
  16373. *b++ = std::numeric_limits<int>::min();
  16374. else if (samp >= 1.0)
  16375. *b++ = std::numeric_limits<int>::max();
  16376. else
  16377. *b++ = roundToInt (std::numeric_limits<int>::max() * samp);
  16378. }
  16379. }
  16380. }
  16381. if (! write ((const int**) buffers, numToDo))
  16382. return false;
  16383. numSamplesToRead -= numToDo;
  16384. }
  16385. return true;
  16386. }
  16387. AudioFormat::AudioFormat (const String& name,
  16388. const tchar** const extensions)
  16389. : formatName (name),
  16390. fileExtensions (extensions)
  16391. {
  16392. }
  16393. AudioFormat::~AudioFormat()
  16394. {
  16395. }
  16396. const String& AudioFormat::getFormatName() const
  16397. {
  16398. return formatName;
  16399. }
  16400. const StringArray& AudioFormat::getFileExtensions() const
  16401. {
  16402. return fileExtensions;
  16403. }
  16404. bool AudioFormat::canHandleFile (const File& f)
  16405. {
  16406. for (int i = 0; i < fileExtensions.size(); ++i)
  16407. if (f.hasFileExtension (fileExtensions[i]))
  16408. return true;
  16409. return false;
  16410. }
  16411. bool AudioFormat::isCompressed()
  16412. {
  16413. return false;
  16414. }
  16415. const StringArray AudioFormat::getQualityOptions()
  16416. {
  16417. return StringArray();
  16418. }
  16419. END_JUCE_NAMESPACE
  16420. /*** End of inlined file: juce_AudioFormat.cpp ***/
  16421. /*** Start of inlined file: juce_AudioFormatManager.cpp ***/
  16422. BEGIN_JUCE_NAMESPACE
  16423. AudioFormatManager::AudioFormatManager()
  16424. : defaultFormatIndex (0)
  16425. {
  16426. }
  16427. AudioFormatManager::~AudioFormatManager()
  16428. {
  16429. clearFormats();
  16430. clearSingletonInstance();
  16431. }
  16432. juce_ImplementSingleton (AudioFormatManager);
  16433. void AudioFormatManager::registerFormat (AudioFormat* newFormat,
  16434. const bool makeThisTheDefaultFormat)
  16435. {
  16436. jassert (newFormat != 0);
  16437. if (newFormat != 0)
  16438. {
  16439. #ifdef JUCE_DEBUG
  16440. for (int i = getNumKnownFormats(); --i >= 0;)
  16441. {
  16442. if (getKnownFormat (i)->getFormatName() == newFormat->getFormatName())
  16443. {
  16444. jassertfalse // trying to add the same format twice!
  16445. }
  16446. }
  16447. #endif
  16448. if (makeThisTheDefaultFormat)
  16449. defaultFormatIndex = knownFormats.size();
  16450. knownFormats.add (newFormat);
  16451. }
  16452. }
  16453. void AudioFormatManager::registerBasicFormats()
  16454. {
  16455. #if JUCE_MAC
  16456. registerFormat (new AiffAudioFormat(), true);
  16457. registerFormat (new WavAudioFormat(), false);
  16458. #else
  16459. registerFormat (new WavAudioFormat(), true);
  16460. registerFormat (new AiffAudioFormat(), false);
  16461. #endif
  16462. #if JUCE_USE_FLAC
  16463. registerFormat (new FlacAudioFormat(), false);
  16464. #endif
  16465. #if JUCE_USE_OGGVORBIS
  16466. registerFormat (new OggVorbisAudioFormat(), false);
  16467. #endif
  16468. }
  16469. void AudioFormatManager::clearFormats()
  16470. {
  16471. for (int i = getNumKnownFormats(); --i >= 0;)
  16472. delete getKnownFormat(i);
  16473. knownFormats.clear();
  16474. defaultFormatIndex = 0;
  16475. }
  16476. int AudioFormatManager::getNumKnownFormats() const
  16477. {
  16478. return knownFormats.size();
  16479. }
  16480. AudioFormat* AudioFormatManager::getKnownFormat (const int index) const
  16481. {
  16482. return (AudioFormat*) knownFormats [index];
  16483. }
  16484. AudioFormat* AudioFormatManager::getDefaultFormat() const
  16485. {
  16486. return getKnownFormat (defaultFormatIndex);
  16487. }
  16488. AudioFormat* AudioFormatManager::findFormatForFileExtension (const String& fileExtension) const
  16489. {
  16490. String e (fileExtension);
  16491. if (! e.startsWithChar (T('.')))
  16492. e = T(".") + e;
  16493. for (int i = 0; i < getNumKnownFormats(); ++i)
  16494. if (getKnownFormat(i)->getFileExtensions().contains (e, true))
  16495. return getKnownFormat(i);
  16496. return 0;
  16497. }
  16498. const String AudioFormatManager::getWildcardForAllFormats() const
  16499. {
  16500. StringArray allExtensions;
  16501. int i;
  16502. for (i = 0; i < getNumKnownFormats(); ++i)
  16503. allExtensions.addArray (getKnownFormat (i)->getFileExtensions());
  16504. allExtensions.trim();
  16505. allExtensions.removeEmptyStrings();
  16506. String s;
  16507. for (i = 0; i < allExtensions.size(); ++i)
  16508. {
  16509. s << T('*');
  16510. if (! allExtensions[i].startsWithChar (T('.')))
  16511. s << T('.');
  16512. s << allExtensions[i];
  16513. if (i < allExtensions.size() - 1)
  16514. s << T(';');
  16515. }
  16516. return s;
  16517. }
  16518. AudioFormatReader* AudioFormatManager::createReaderFor (const File& file)
  16519. {
  16520. // you need to actually register some formats before the manager can
  16521. // use them to open a file!
  16522. jassert (knownFormats.size() > 0);
  16523. for (int i = 0; i < getNumKnownFormats(); ++i)
  16524. {
  16525. AudioFormat* const af = getKnownFormat(i);
  16526. if (af->canHandleFile (file))
  16527. {
  16528. InputStream* const in = file.createInputStream();
  16529. if (in != 0)
  16530. {
  16531. AudioFormatReader* const r = af->createReaderFor (in, true);
  16532. if (r != 0)
  16533. return r;
  16534. }
  16535. }
  16536. }
  16537. return 0;
  16538. }
  16539. AudioFormatReader* AudioFormatManager::createReaderFor (InputStream* audioFileStream)
  16540. {
  16541. // you need to actually register some formats before the manager can
  16542. // use them to open a file!
  16543. jassert (knownFormats.size() > 0);
  16544. ScopedPointer <InputStream> in (audioFileStream);
  16545. if (in != 0)
  16546. {
  16547. const int64 originalStreamPos = in->getPosition();
  16548. for (int i = 0; i < getNumKnownFormats(); ++i)
  16549. {
  16550. AudioFormatReader* const r = getKnownFormat(i)->createReaderFor (in, false);
  16551. if (r != 0)
  16552. {
  16553. in.release();
  16554. return r;
  16555. }
  16556. in->setPosition (originalStreamPos);
  16557. // the stream that is passed-in must be capable of being repositioned so
  16558. // that all the formats can have a go at opening it.
  16559. jassert (in->getPosition() == originalStreamPos);
  16560. }
  16561. }
  16562. return 0;
  16563. }
  16564. END_JUCE_NAMESPACE
  16565. /*** End of inlined file: juce_AudioFormatManager.cpp ***/
  16566. /*** Start of inlined file: juce_AudioSubsectionReader.cpp ***/
  16567. BEGIN_JUCE_NAMESPACE
  16568. AudioSubsectionReader::AudioSubsectionReader (AudioFormatReader* const source_,
  16569. const int64 startSample_,
  16570. const int64 length_,
  16571. const bool deleteSourceWhenDeleted_)
  16572. : AudioFormatReader (0, source_->getFormatName()),
  16573. source (source_),
  16574. startSample (startSample_),
  16575. deleteSourceWhenDeleted (deleteSourceWhenDeleted_)
  16576. {
  16577. length = jmin (jmax ((int64) 0, source->lengthInSamples - startSample), length_);
  16578. sampleRate = source->sampleRate;
  16579. bitsPerSample = source->bitsPerSample;
  16580. lengthInSamples = length;
  16581. numChannels = source->numChannels;
  16582. usesFloatingPointData = source->usesFloatingPointData;
  16583. }
  16584. AudioSubsectionReader::~AudioSubsectionReader()
  16585. {
  16586. if (deleteSourceWhenDeleted)
  16587. delete source;
  16588. }
  16589. bool AudioSubsectionReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  16590. int64 startSampleInFile, int numSamples)
  16591. {
  16592. if (startSampleInFile + numSamples > length)
  16593. {
  16594. for (int i = numDestChannels; --i >= 0;)
  16595. if (destSamples[i] != 0)
  16596. zeromem (destSamples[i], sizeof (int) * numSamples);
  16597. numSamples = jmin (numSamples, (int) (length - startSampleInFile));
  16598. if (numSamples <= 0)
  16599. return true;
  16600. }
  16601. return source->readSamples (destSamples, numDestChannels, startOffsetInDestBuffer,
  16602. startSampleInFile + startSample, numSamples);
  16603. }
  16604. void AudioSubsectionReader::readMaxLevels (int64 startSampleInFile,
  16605. int64 numSamples,
  16606. float& lowestLeft,
  16607. float& highestLeft,
  16608. float& lowestRight,
  16609. float& highestRight)
  16610. {
  16611. startSampleInFile = jmax ((int64) 0, startSampleInFile);
  16612. numSamples = jmax ((int64) 0, jmin (numSamples, length - startSampleInFile));
  16613. source->readMaxLevels (startSampleInFile + startSample,
  16614. numSamples,
  16615. lowestLeft,
  16616. highestLeft,
  16617. lowestRight,
  16618. highestRight);
  16619. }
  16620. END_JUCE_NAMESPACE
  16621. /*** End of inlined file: juce_AudioSubsectionReader.cpp ***/
  16622. /*** Start of inlined file: juce_AudioThumbnail.cpp ***/
  16623. BEGIN_JUCE_NAMESPACE
  16624. const int timeBeforeDeletingReader = 2000;
  16625. struct AudioThumbnailDataFormat
  16626. {
  16627. char thumbnailMagic[4];
  16628. int samplesPerThumbSample;
  16629. int64 totalSamples; // source samples
  16630. int64 numFinishedSamples; // source samples
  16631. int numThumbnailSamples;
  16632. int numChannels;
  16633. int sampleRate;
  16634. char future[16];
  16635. char data[1];
  16636. void swapEndiannessIfNeeded() throw()
  16637. {
  16638. #if JUCE_BIG_ENDIAN
  16639. flip (samplesPerThumbSample);
  16640. flip (totalSamples);
  16641. flip (numFinishedSamples);
  16642. flip (numThumbnailSamples);
  16643. flip (numChannels);
  16644. flip (sampleRate);
  16645. #endif
  16646. }
  16647. private:
  16648. #if JUCE_BIG_ENDIAN
  16649. static void flip (int& n) { n = (int) ByteOrder::swap ((uint32) n); }
  16650. static void flip (int64& n) { n = (int64) ByteOrder::swap ((uint64) n); }
  16651. #endif
  16652. };
  16653. AudioThumbnail::AudioThumbnail (const int orginalSamplesPerThumbnailSample_,
  16654. AudioFormatManager& formatManagerToUse_,
  16655. AudioThumbnailCache& cacheToUse)
  16656. : formatManagerToUse (formatManagerToUse_),
  16657. cache (cacheToUse),
  16658. orginalSamplesPerThumbnailSample (orginalSamplesPerThumbnailSample_)
  16659. {
  16660. clear();
  16661. }
  16662. AudioThumbnail::~AudioThumbnail()
  16663. {
  16664. cache.removeThumbnail (this);
  16665. const ScopedLock sl (readerLock);
  16666. reader = 0;
  16667. }
  16668. void AudioThumbnail::setSource (InputSource* const newSource)
  16669. {
  16670. cache.removeThumbnail (this);
  16671. timerCallback(); // stops the timer and deletes the reader
  16672. source = newSource;
  16673. clear();
  16674. if (newSource != 0
  16675. && ! (cache.loadThumb (*this, newSource->hashCode())
  16676. && isFullyLoaded()))
  16677. {
  16678. {
  16679. const ScopedLock sl (readerLock);
  16680. reader = createReader();
  16681. }
  16682. if (reader != 0)
  16683. {
  16684. initialiseFromAudioFile (*reader);
  16685. cache.addThumbnail (this);
  16686. }
  16687. }
  16688. sendChangeMessage (this);
  16689. }
  16690. bool AudioThumbnail::useTimeSlice()
  16691. {
  16692. const ScopedLock sl (readerLock);
  16693. if (isFullyLoaded())
  16694. {
  16695. if (reader != 0)
  16696. startTimer (timeBeforeDeletingReader);
  16697. cache.removeThumbnail (this);
  16698. return false;
  16699. }
  16700. if (reader == 0)
  16701. reader = createReader();
  16702. if (reader != 0)
  16703. {
  16704. readNextBlockFromAudioFile (*reader);
  16705. stopTimer();
  16706. sendChangeMessage (this);
  16707. const bool justFinished = isFullyLoaded();
  16708. if (justFinished)
  16709. cache.storeThumb (*this, source->hashCode());
  16710. return ! justFinished;
  16711. }
  16712. return false;
  16713. }
  16714. AudioFormatReader* AudioThumbnail::createReader() const
  16715. {
  16716. if (source != 0)
  16717. {
  16718. InputStream* const audioFileStream = source->createInputStream();
  16719. if (audioFileStream != 0)
  16720. return formatManagerToUse.createReaderFor (audioFileStream);
  16721. }
  16722. return 0;
  16723. }
  16724. void AudioThumbnail::timerCallback()
  16725. {
  16726. stopTimer();
  16727. const ScopedLock sl (readerLock);
  16728. reader = 0;
  16729. }
  16730. void AudioThumbnail::clear()
  16731. {
  16732. data.setSize (sizeof (AudioThumbnailDataFormat) + 3);
  16733. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16734. d->thumbnailMagic[0] = 'j';
  16735. d->thumbnailMagic[1] = 'a';
  16736. d->thumbnailMagic[2] = 't';
  16737. d->thumbnailMagic[3] = 'm';
  16738. d->samplesPerThumbSample = orginalSamplesPerThumbnailSample;
  16739. d->totalSamples = 0;
  16740. d->numFinishedSamples = 0;
  16741. d->numThumbnailSamples = 0;
  16742. d->numChannels = 0;
  16743. d->sampleRate = 0;
  16744. numSamplesCached = 0;
  16745. cacheNeedsRefilling = true;
  16746. }
  16747. void AudioThumbnail::loadFrom (InputStream& input)
  16748. {
  16749. const ScopedLock sl (readerLock);
  16750. data.setSize (0);
  16751. input.readIntoMemoryBlock (data);
  16752. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16753. d->swapEndiannessIfNeeded();
  16754. if (! (d->thumbnailMagic[0] == 'j'
  16755. && d->thumbnailMagic[1] == 'a'
  16756. && d->thumbnailMagic[2] == 't'
  16757. && d->thumbnailMagic[3] == 'm'))
  16758. {
  16759. clear();
  16760. }
  16761. numSamplesCached = 0;
  16762. cacheNeedsRefilling = true;
  16763. }
  16764. void AudioThumbnail::saveTo (OutputStream& output) const
  16765. {
  16766. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16767. d->swapEndiannessIfNeeded();
  16768. output.write (data.getData(), (int) data.getSize());
  16769. d->swapEndiannessIfNeeded();
  16770. }
  16771. bool AudioThumbnail::initialiseFromAudioFile (AudioFormatReader& fileReader)
  16772. {
  16773. AudioThumbnailDataFormat* d = (AudioThumbnailDataFormat*) data.getData();
  16774. d->totalSamples = fileReader.lengthInSamples;
  16775. d->numChannels = jmin ((uint32) 2, fileReader.numChannels);
  16776. d->numFinishedSamples = 0;
  16777. d->sampleRate = roundToInt (fileReader.sampleRate);
  16778. d->numThumbnailSamples = (int) (d->totalSamples / d->samplesPerThumbSample) + 1;
  16779. data.setSize (sizeof (AudioThumbnailDataFormat) + 3 + d->numThumbnailSamples * d->numChannels * 2);
  16780. d = (AudioThumbnailDataFormat*) data.getData();
  16781. zeromem (&(d->data[0]), d->numThumbnailSamples * d->numChannels * 2);
  16782. return d->totalSamples > 0;
  16783. }
  16784. bool AudioThumbnail::readNextBlockFromAudioFile (AudioFormatReader& fileReader)
  16785. {
  16786. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16787. if (d->numFinishedSamples < d->totalSamples)
  16788. {
  16789. const int numToDo = (int) jmin ((int64) 65536, d->totalSamples - d->numFinishedSamples);
  16790. generateSection (fileReader,
  16791. d->numFinishedSamples,
  16792. numToDo);
  16793. d->numFinishedSamples += numToDo;
  16794. }
  16795. cacheNeedsRefilling = true;
  16796. return (d->numFinishedSamples < d->totalSamples);
  16797. }
  16798. int AudioThumbnail::getNumChannels() const throw()
  16799. {
  16800. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16801. jassert (d != 0);
  16802. return d->numChannels;
  16803. }
  16804. double AudioThumbnail::getTotalLength() const throw()
  16805. {
  16806. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16807. jassert (d != 0);
  16808. if (d->sampleRate > 0)
  16809. return d->totalSamples / (double)d->sampleRate;
  16810. else
  16811. return 0.0;
  16812. }
  16813. void AudioThumbnail::generateSection (AudioFormatReader& fileReader,
  16814. int64 startSample,
  16815. int numSamples)
  16816. {
  16817. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16818. jassert (d != 0);
  16819. int firstDataPos = (int) (startSample / d->samplesPerThumbSample);
  16820. int lastDataPos = (int) ((startSample + numSamples) / d->samplesPerThumbSample);
  16821. char* l = getChannelData (0);
  16822. char* r = getChannelData (1);
  16823. for (int i = firstDataPos; i < lastDataPos; ++i)
  16824. {
  16825. const int sourceStart = i * d->samplesPerThumbSample;
  16826. const int sourceEnd = sourceStart + d->samplesPerThumbSample;
  16827. float lowestLeft, highestLeft, lowestRight, highestRight;
  16828. fileReader.readMaxLevels (sourceStart,
  16829. sourceEnd - sourceStart,
  16830. lowestLeft,
  16831. highestLeft,
  16832. lowestRight,
  16833. highestRight);
  16834. int n = i * 2;
  16835. if (r != 0)
  16836. {
  16837. l [n] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16838. r [n++] = (char) jlimit (-128.0f, 127.0f, lowestRight * 127.0f);
  16839. l [n] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16840. r [n++] = (char) jlimit (-128.0f, 127.0f, highestRight * 127.0f);
  16841. }
  16842. else
  16843. {
  16844. l [n++] = (char) jlimit (-128.0f, 127.0f, lowestLeft * 127.0f);
  16845. l [n++] = (char) jlimit (-128.0f, 127.0f, highestLeft * 127.0f);
  16846. }
  16847. }
  16848. }
  16849. char* AudioThumbnail::getChannelData (int channel) const
  16850. {
  16851. AudioThumbnailDataFormat* const d = (AudioThumbnailDataFormat*) data.getData();
  16852. jassert (d != 0);
  16853. if (channel >= 0 && channel < d->numChannels)
  16854. return d->data + (channel * 2 * d->numThumbnailSamples);
  16855. return 0;
  16856. }
  16857. bool AudioThumbnail::isFullyLoaded() const throw()
  16858. {
  16859. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16860. jassert (d != 0);
  16861. return d->numFinishedSamples >= d->totalSamples;
  16862. }
  16863. void AudioThumbnail::refillCache (const int numSamples,
  16864. double startTime,
  16865. const double timePerPixel)
  16866. {
  16867. const AudioThumbnailDataFormat* const d = (const AudioThumbnailDataFormat*) data.getData();
  16868. jassert (d != 0);
  16869. if (numSamples <= 0
  16870. || timePerPixel <= 0.0
  16871. || d->sampleRate <= 0)
  16872. {
  16873. numSamplesCached = 0;
  16874. cacheNeedsRefilling = true;
  16875. return;
  16876. }
  16877. if (numSamples == numSamplesCached
  16878. && numChannelsCached == d->numChannels
  16879. && startTime == cachedStart
  16880. && timePerPixel == cachedTimePerPixel
  16881. && ! cacheNeedsRefilling)
  16882. {
  16883. return;
  16884. }
  16885. numSamplesCached = numSamples;
  16886. numChannelsCached = d->numChannels;
  16887. cachedStart = startTime;
  16888. cachedTimePerPixel = timePerPixel;
  16889. cachedLevels.ensureSize (2 * numChannelsCached * numSamples);
  16890. const bool needExtraDetail = (timePerPixel * d->sampleRate <= d->samplesPerThumbSample);
  16891. const ScopedLock sl (readerLock);
  16892. cacheNeedsRefilling = false;
  16893. if (needExtraDetail && reader == 0)
  16894. reader = createReader();
  16895. if (reader != 0 && timePerPixel * d->sampleRate <= d->samplesPerThumbSample)
  16896. {
  16897. startTimer (timeBeforeDeletingReader);
  16898. char* cacheData = (char*) cachedLevels.getData();
  16899. int sample = roundToInt (startTime * d->sampleRate);
  16900. for (int i = numSamples; --i >= 0;)
  16901. {
  16902. const int nextSample = roundToInt ((startTime + timePerPixel) * d->sampleRate);
  16903. if (sample >= 0)
  16904. {
  16905. if (sample >= reader->lengthInSamples)
  16906. break;
  16907. float lmin, lmax, rmin, rmax;
  16908. reader->readMaxLevels (sample,
  16909. jmax (1, nextSample - sample),
  16910. lmin, lmax, rmin, rmax);
  16911. cacheData[0] = (char) jlimit (-128, 127, roundFloatToInt (lmin * 127.0f));
  16912. cacheData[1] = (char) jlimit (-128, 127, roundFloatToInt (lmax * 127.0f));
  16913. if (numChannelsCached > 1)
  16914. {
  16915. cacheData[2] = (char) jlimit (-128, 127, roundFloatToInt (rmin * 127.0f));
  16916. cacheData[3] = (char) jlimit (-128, 127, roundFloatToInt (rmax * 127.0f));
  16917. }
  16918. cacheData += 2 * numChannelsCached;
  16919. }
  16920. startTime += timePerPixel;
  16921. sample = nextSample;
  16922. }
  16923. }
  16924. else
  16925. {
  16926. for (int channelNum = 0; channelNum < numChannelsCached; ++channelNum)
  16927. {
  16928. char* const channelData = getChannelData (channelNum);
  16929. char* cacheData = ((char*) cachedLevels.getData()) + channelNum * 2;
  16930. const double timeToThumbSampleFactor = d->sampleRate / (double) d->samplesPerThumbSample;
  16931. startTime = cachedStart;
  16932. int sample = roundToInt (startTime * timeToThumbSampleFactor);
  16933. const int numFinished = (int) (d->numFinishedSamples / d->samplesPerThumbSample);
  16934. for (int i = numSamples; --i >= 0;)
  16935. {
  16936. const int nextSample = roundToInt ((startTime + timePerPixel) * timeToThumbSampleFactor);
  16937. if (sample >= 0 && channelData != 0)
  16938. {
  16939. char mx = -128;
  16940. char mn = 127;
  16941. while (sample <= nextSample)
  16942. {
  16943. if (sample >= numFinished)
  16944. break;
  16945. const int n = sample << 1;
  16946. const char sampMin = channelData [n];
  16947. const char sampMax = channelData [n + 1];
  16948. if (sampMin < mn)
  16949. mn = sampMin;
  16950. if (sampMax > mx)
  16951. mx = sampMax;
  16952. ++sample;
  16953. }
  16954. if (mn <= mx)
  16955. {
  16956. cacheData[0] = mn;
  16957. cacheData[1] = mx;
  16958. }
  16959. else
  16960. {
  16961. cacheData[0] = 1;
  16962. cacheData[1] = 0;
  16963. }
  16964. }
  16965. else
  16966. {
  16967. cacheData[0] = 1;
  16968. cacheData[1] = 0;
  16969. }
  16970. cacheData += numChannelsCached * 2;
  16971. startTime += timePerPixel;
  16972. sample = nextSample;
  16973. }
  16974. }
  16975. }
  16976. }
  16977. void AudioThumbnail::drawChannel (Graphics& g,
  16978. int x, int y, int w, int h,
  16979. double startTime,
  16980. double endTime,
  16981. int channelNum,
  16982. const float verticalZoomFactor)
  16983. {
  16984. refillCache (w, startTime, (endTime - startTime) / w);
  16985. if (numSamplesCached >= w
  16986. && channelNum >= 0
  16987. && channelNum < numChannelsCached)
  16988. {
  16989. const float topY = (float) y;
  16990. const float bottomY = topY + h;
  16991. const float midY = topY + h * 0.5f;
  16992. const float vscale = verticalZoomFactor * h / 256.0f;
  16993. const Rectangle<int> clip (g.getClipBounds());
  16994. const int skipLeft = jlimit (0, w, clip.getX() - x);
  16995. w -= skipLeft;
  16996. x += skipLeft;
  16997. const char* cacheData = ((const char*) cachedLevels.getData())
  16998. + (channelNum << 1)
  16999. + skipLeft * (numChannelsCached << 1);
  17000. while (--w >= 0)
  17001. {
  17002. const char mn = cacheData[0];
  17003. const char mx = cacheData[1];
  17004. cacheData += numChannelsCached << 1;
  17005. if (mn <= mx) // if the wrong way round, signifies that the sample's not yet known
  17006. g.drawLine ((float) x, jmax (midY - mx * vscale - 0.3f, topY),
  17007. (float) x, jmin (midY - mn * vscale + 0.3f, bottomY));
  17008. ++x;
  17009. if (x >= clip.getRight())
  17010. break;
  17011. }
  17012. }
  17013. }
  17014. END_JUCE_NAMESPACE
  17015. /*** End of inlined file: juce_AudioThumbnail.cpp ***/
  17016. /*** Start of inlined file: juce_AudioThumbnailCache.cpp ***/
  17017. BEGIN_JUCE_NAMESPACE
  17018. struct ThumbnailCacheEntry
  17019. {
  17020. int64 hash;
  17021. uint32 lastUsed;
  17022. MemoryBlock data;
  17023. juce_UseDebuggingNewOperator
  17024. };
  17025. AudioThumbnailCache::AudioThumbnailCache (const int maxNumThumbsToStore_)
  17026. : TimeSliceThread (T("thumb cache")),
  17027. maxNumThumbsToStore (maxNumThumbsToStore_)
  17028. {
  17029. startThread (2);
  17030. }
  17031. AudioThumbnailCache::~AudioThumbnailCache()
  17032. {
  17033. }
  17034. bool AudioThumbnailCache::loadThumb (AudioThumbnail& thumb, const int64 hashCode)
  17035. {
  17036. for (int i = thumbs.size(); --i >= 0;)
  17037. {
  17038. if (thumbs[i]->hash == hashCode)
  17039. {
  17040. MemoryInputStream in ((const char*) thumbs[i]->data.getData(),
  17041. thumbs[i]->data.getSize(),
  17042. false);
  17043. thumb.loadFrom (in);
  17044. thumbs[i]->lastUsed = Time::getMillisecondCounter();
  17045. return true;
  17046. }
  17047. }
  17048. return false;
  17049. }
  17050. void AudioThumbnailCache::storeThumb (const AudioThumbnail& thumb,
  17051. const int64 hashCode)
  17052. {
  17053. MemoryOutputStream out;
  17054. thumb.saveTo (out);
  17055. ThumbnailCacheEntry* te = 0;
  17056. for (int i = thumbs.size(); --i >= 0;)
  17057. {
  17058. if (thumbs[i]->hash == hashCode)
  17059. {
  17060. te = thumbs[i];
  17061. break;
  17062. }
  17063. }
  17064. if (te == 0)
  17065. {
  17066. te = new ThumbnailCacheEntry();
  17067. te->hash = hashCode;
  17068. if (thumbs.size() < maxNumThumbsToStore)
  17069. {
  17070. thumbs.add (te);
  17071. }
  17072. else
  17073. {
  17074. int oldest = 0;
  17075. unsigned int oldestTime = Time::getMillisecondCounter() + 1;
  17076. int i;
  17077. for (i = thumbs.size(); --i >= 0;)
  17078. if (thumbs[i]->lastUsed < oldestTime)
  17079. oldest = i;
  17080. thumbs.set (i, te);
  17081. }
  17082. }
  17083. te->lastUsed = Time::getMillisecondCounter();
  17084. te->data.setSize (0);
  17085. te->data.append (out.getData(), out.getDataSize());
  17086. }
  17087. void AudioThumbnailCache::clear()
  17088. {
  17089. thumbs.clear();
  17090. }
  17091. void AudioThumbnailCache::addThumbnail (AudioThumbnail* const thumb)
  17092. {
  17093. addTimeSliceClient (thumb);
  17094. }
  17095. void AudioThumbnailCache::removeThumbnail (AudioThumbnail* const thumb)
  17096. {
  17097. removeTimeSliceClient (thumb);
  17098. }
  17099. END_JUCE_NAMESPACE
  17100. /*** End of inlined file: juce_AudioThumbnailCache.cpp ***/
  17101. /*** Start of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17102. #if JUCE_QUICKTIME && ! (JUCE_64BIT || JUCE_IPHONE)
  17103. #if ! JUCE_WINDOWS
  17104. #include <QuickTime/Movies.h>
  17105. #include <QuickTime/QTML.h>
  17106. #include <QuickTime/QuickTimeComponents.h>
  17107. #include <QuickTime/MediaHandlers.h>
  17108. #include <QuickTime/ImageCodec.h>
  17109. #else
  17110. #if JUCE_MSVC
  17111. #pragma warning (push)
  17112. #pragma warning (disable : 4100)
  17113. #endif
  17114. #include <Movies.h>
  17115. #include <QTML.h>
  17116. #include <QuickTimeComponents.h>
  17117. #include <MediaHandlers.h>
  17118. #include <ImageCodec.h>
  17119. #if JUCE_MSVC
  17120. #pragma warning (pop)
  17121. #endif
  17122. #endif
  17123. BEGIN_JUCE_NAMESPACE
  17124. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  17125. static const char* const quickTimeFormatName = "QuickTime file";
  17126. static const tchar* const quickTimeExtensions[] = { T(".mov"), T(".mp3"), T(".mp4"), 0 };
  17127. class QTAudioReader : public AudioFormatReader
  17128. {
  17129. public:
  17130. QTAudioReader (InputStream* const input_, const int trackNum_)
  17131. : AudioFormatReader (input_, TRANS (quickTimeFormatName)),
  17132. ok (false),
  17133. movie (0),
  17134. trackNum (trackNum_),
  17135. lastSampleRead (0),
  17136. lastThreadId (0),
  17137. extractor (0),
  17138. dataHandle (0)
  17139. {
  17140. bufferList.calloc (256, 1);
  17141. #ifdef WIN32
  17142. if (InitializeQTML (0) != noErr)
  17143. return;
  17144. #endif
  17145. if (EnterMovies() != noErr)
  17146. return;
  17147. bool opened = juce_OpenQuickTimeMovieFromStream (input_, movie, dataHandle);
  17148. if (! opened)
  17149. return;
  17150. {
  17151. const int numTracks = GetMovieTrackCount (movie);
  17152. int trackCount = 0;
  17153. for (int i = 1; i <= numTracks; ++i)
  17154. {
  17155. track = GetMovieIndTrack (movie, i);
  17156. media = GetTrackMedia (track);
  17157. OSType mediaType;
  17158. GetMediaHandlerDescription (media, &mediaType, 0, 0);
  17159. if (mediaType == SoundMediaType
  17160. && trackCount++ == trackNum_)
  17161. {
  17162. ok = true;
  17163. break;
  17164. }
  17165. }
  17166. }
  17167. if (! ok)
  17168. return;
  17169. ok = false;
  17170. lengthInSamples = GetMediaDecodeDuration (media);
  17171. usesFloatingPointData = false;
  17172. samplesPerFrame = (int) (GetMediaDecodeDuration (media) / GetMediaSampleCount (media));
  17173. trackUnitsPerFrame = GetMovieTimeScale (movie) * samplesPerFrame
  17174. / GetMediaTimeScale (media);
  17175. OSStatus err = MovieAudioExtractionBegin (movie, 0, &extractor);
  17176. unsigned long output_layout_size;
  17177. err = MovieAudioExtractionGetPropertyInfo (extractor,
  17178. kQTPropertyClass_MovieAudioExtraction_Audio,
  17179. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17180. 0, &output_layout_size, 0);
  17181. if (err != noErr)
  17182. return;
  17183. HeapBlock <AudioChannelLayout> qt_audio_channel_layout;
  17184. qt_audio_channel_layout.calloc (output_layout_size, 1);
  17185. err = MovieAudioExtractionGetProperty (extractor,
  17186. kQTPropertyClass_MovieAudioExtraction_Audio,
  17187. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17188. output_layout_size, qt_audio_channel_layout, 0);
  17189. qt_audio_channel_layout[0].mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  17190. err = MovieAudioExtractionSetProperty (extractor,
  17191. kQTPropertyClass_MovieAudioExtraction_Audio,
  17192. kQTMovieAudioExtractionAudioPropertyID_AudioChannelLayout,
  17193. output_layout_size,
  17194. qt_audio_channel_layout);
  17195. err = MovieAudioExtractionGetProperty (extractor,
  17196. kQTPropertyClass_MovieAudioExtraction_Audio,
  17197. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17198. sizeof (inputStreamDesc),
  17199. &inputStreamDesc, 0);
  17200. if (err != noErr)
  17201. return;
  17202. inputStreamDesc.mFormatFlags = kAudioFormatFlagIsSignedInteger
  17203. | kAudioFormatFlagIsPacked
  17204. | kAudioFormatFlagsNativeEndian;
  17205. inputStreamDesc.mBitsPerChannel = sizeof (SInt16) * 8;
  17206. inputStreamDesc.mChannelsPerFrame = jmin ((UInt32) 2, inputStreamDesc.mChannelsPerFrame);
  17207. inputStreamDesc.mBytesPerFrame = sizeof (SInt16) * inputStreamDesc.mChannelsPerFrame;
  17208. inputStreamDesc.mBytesPerPacket = inputStreamDesc.mBytesPerFrame;
  17209. err = MovieAudioExtractionSetProperty (extractor,
  17210. kQTPropertyClass_MovieAudioExtraction_Audio,
  17211. kQTMovieAudioExtractionAudioPropertyID_AudioStreamBasicDescription,
  17212. sizeof (inputStreamDesc),
  17213. &inputStreamDesc);
  17214. if (err != noErr)
  17215. return;
  17216. Boolean allChannelsDiscrete = false;
  17217. err = MovieAudioExtractionSetProperty (extractor,
  17218. kQTPropertyClass_MovieAudioExtraction_Movie,
  17219. kQTMovieAudioExtractionMoviePropertyID_AllChannelsDiscrete,
  17220. sizeof (allChannelsDiscrete),
  17221. &allChannelsDiscrete);
  17222. if (err != noErr)
  17223. return;
  17224. bufferList->mNumberBuffers = 1;
  17225. bufferList->mBuffers[0].mNumberChannels = inputStreamDesc.mChannelsPerFrame;
  17226. bufferList->mBuffers[0].mDataByteSize = (UInt32) (samplesPerFrame * inputStreamDesc.mBytesPerFrame) + 16;
  17227. bufferList->mBuffers[0].mData = malloc (bufferList->mBuffers[0].mDataByteSize);
  17228. sampleRate = inputStreamDesc.mSampleRate;
  17229. bitsPerSample = 16;
  17230. numChannels = inputStreamDesc.mChannelsPerFrame;
  17231. detachThread();
  17232. ok = true;
  17233. }
  17234. ~QTAudioReader()
  17235. {
  17236. if (dataHandle != 0)
  17237. DisposeHandle (dataHandle);
  17238. if (extractor != 0)
  17239. {
  17240. MovieAudioExtractionEnd (extractor);
  17241. extractor = 0;
  17242. }
  17243. checkThreadIsAttached();
  17244. DisposeMovie (movie);
  17245. juce_free (bufferList->mBuffers[0].mData);
  17246. #if JUCE_MAC
  17247. ExitMoviesOnThread ();
  17248. #endif
  17249. }
  17250. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17251. int64 startSampleInFile, int numSamples)
  17252. {
  17253. checkThreadIsAttached();
  17254. while (numSamples > 0)
  17255. {
  17256. if (! loadFrame ((int) startSampleInFile))
  17257. return false;
  17258. const int numToDo = jmin (numSamples, samplesPerFrame);
  17259. for (int j = numDestChannels; --j >= 0;)
  17260. {
  17261. if (destSamples[j] != 0)
  17262. {
  17263. const short* const src = ((const short*) bufferList->mBuffers[0].mData) + j;
  17264. for (int i = 0; i < numToDo; ++i)
  17265. destSamples[j][startOffsetInDestBuffer + i] = src [i << 1] << 16;
  17266. }
  17267. }
  17268. startOffsetInDestBuffer += numToDo;
  17269. startSampleInFile += numToDo;
  17270. numSamples -= numToDo;
  17271. }
  17272. detachThread();
  17273. return true;
  17274. }
  17275. bool loadFrame (const int sampleNum)
  17276. {
  17277. if (lastSampleRead != sampleNum)
  17278. {
  17279. TimeRecord time;
  17280. time.scale = (TimeScale) inputStreamDesc.mSampleRate;
  17281. time.base = 0;
  17282. time.value.hi = 0;
  17283. time.value.lo = (UInt32) sampleNum;
  17284. OSStatus err = MovieAudioExtractionSetProperty (extractor,
  17285. kQTPropertyClass_MovieAudioExtraction_Movie,
  17286. kQTMovieAudioExtractionMoviePropertyID_CurrentTime,
  17287. sizeof (time), &time);
  17288. if (err != noErr)
  17289. return false;
  17290. }
  17291. bufferList->mBuffers[0].mDataByteSize = inputStreamDesc.mBytesPerFrame * samplesPerFrame;
  17292. UInt32 outFlags = 0;
  17293. UInt32 actualNumSamples = samplesPerFrame;
  17294. OSStatus err = MovieAudioExtractionFillBuffer (extractor, &actualNumSamples,
  17295. bufferList, &outFlags);
  17296. lastSampleRead = sampleNum + samplesPerFrame;
  17297. return err == noErr;
  17298. }
  17299. juce_UseDebuggingNewOperator
  17300. bool ok;
  17301. private:
  17302. Movie movie;
  17303. Media media;
  17304. Track track;
  17305. const int trackNum;
  17306. double trackUnitsPerFrame;
  17307. int samplesPerFrame;
  17308. int lastSampleRead;
  17309. Thread::ThreadID lastThreadId;
  17310. MovieAudioExtractionRef extractor;
  17311. AudioStreamBasicDescription inputStreamDesc;
  17312. HeapBlock <AudioBufferList> bufferList;
  17313. Handle dataHandle;
  17314. void checkThreadIsAttached()
  17315. {
  17316. #if JUCE_MAC
  17317. if (Thread::getCurrentThreadId() != lastThreadId)
  17318. EnterMoviesOnThread (0);
  17319. AttachMovieToCurrentThread (movie);
  17320. #endif
  17321. }
  17322. void detachThread()
  17323. {
  17324. #if JUCE_MAC
  17325. DetachMovieFromCurrentThread (movie);
  17326. #endif
  17327. }
  17328. };
  17329. QuickTimeAudioFormat::QuickTimeAudioFormat()
  17330. : AudioFormat (TRANS (quickTimeFormatName), (const tchar**) quickTimeExtensions)
  17331. {
  17332. }
  17333. QuickTimeAudioFormat::~QuickTimeAudioFormat()
  17334. {
  17335. }
  17336. const Array <int> QuickTimeAudioFormat::getPossibleSampleRates()
  17337. {
  17338. return Array<int>();
  17339. }
  17340. const Array <int> QuickTimeAudioFormat::getPossibleBitDepths()
  17341. {
  17342. return Array<int>();
  17343. }
  17344. bool QuickTimeAudioFormat::canDoStereo()
  17345. {
  17346. return true;
  17347. }
  17348. bool QuickTimeAudioFormat::canDoMono()
  17349. {
  17350. return true;
  17351. }
  17352. AudioFormatReader* QuickTimeAudioFormat::createReaderFor (InputStream* sourceStream,
  17353. const bool deleteStreamIfOpeningFails)
  17354. {
  17355. ScopedPointer <QTAudioReader> r (new QTAudioReader (sourceStream, 0));
  17356. if (r->ok)
  17357. return r.release();
  17358. if (! deleteStreamIfOpeningFails)
  17359. r->input = 0;
  17360. return 0;
  17361. }
  17362. AudioFormatWriter* QuickTimeAudioFormat::createWriterFor (OutputStream* /*streamToWriteTo*/,
  17363. double /*sampleRateToUse*/,
  17364. unsigned int /*numberOfChannels*/,
  17365. int /*bitsPerSample*/,
  17366. const StringPairArray& /*metadataValues*/,
  17367. int /*qualityOptionIndex*/)
  17368. {
  17369. jassertfalse // not yet implemented!
  17370. return 0;
  17371. }
  17372. END_JUCE_NAMESPACE
  17373. #endif
  17374. /*** End of inlined file: juce_QuickTimeAudioFormat.cpp ***/
  17375. /*** Start of inlined file: juce_WavAudioFormat.cpp ***/
  17376. BEGIN_JUCE_NAMESPACE
  17377. static const char* const wavFormatName = "WAV file";
  17378. static const tchar* const wavExtensions[] = { T(".wav"), T(".bwf"), 0 };
  17379. const tchar* const WavAudioFormat::bwavDescription = T("bwav description");
  17380. const tchar* const WavAudioFormat::bwavOriginator = T("bwav originator");
  17381. const tchar* const WavAudioFormat::bwavOriginatorRef = T("bwav originator ref");
  17382. const tchar* const WavAudioFormat::bwavOriginationDate = T("bwav origination date");
  17383. const tchar* const WavAudioFormat::bwavOriginationTime = T("bwav origination time");
  17384. const tchar* const WavAudioFormat::bwavTimeReference = T("bwav time reference");
  17385. const tchar* const WavAudioFormat::bwavCodingHistory = T("bwav coding history");
  17386. const StringPairArray WavAudioFormat::createBWAVMetadata (const String& description,
  17387. const String& originator,
  17388. const String& originatorRef,
  17389. const Time& date,
  17390. const int64 timeReferenceSamples,
  17391. const String& codingHistory)
  17392. {
  17393. StringPairArray m;
  17394. m.set (bwavDescription, description);
  17395. m.set (bwavOriginator, originator);
  17396. m.set (bwavOriginatorRef, originatorRef);
  17397. m.set (bwavOriginationDate, date.formatted (T("%Y-%m-%d")));
  17398. m.set (bwavOriginationTime, date.formatted (T("%H:%M:%S")));
  17399. m.set (bwavTimeReference, String (timeReferenceSamples));
  17400. m.set (bwavCodingHistory, codingHistory);
  17401. return m;
  17402. }
  17403. #if JUCE_MSVC
  17404. #pragma pack (push, 1)
  17405. #define PACKED
  17406. #elif JUCE_GCC
  17407. #define PACKED __attribute__((packed))
  17408. #else
  17409. #define PACKED
  17410. #endif
  17411. struct BWAVChunk
  17412. {
  17413. char description [256];
  17414. char originator [32];
  17415. char originatorRef [32];
  17416. char originationDate [10];
  17417. char originationTime [8];
  17418. uint32 timeRefLow;
  17419. uint32 timeRefHigh;
  17420. uint16 version;
  17421. uint8 umid[64];
  17422. uint8 reserved[190];
  17423. char codingHistory[1];
  17424. void copyTo (StringPairArray& values) const
  17425. {
  17426. values.set (WavAudioFormat::bwavDescription, String::fromUTF8 (description, 256));
  17427. values.set (WavAudioFormat::bwavOriginator, String::fromUTF8 (originator, 32));
  17428. values.set (WavAudioFormat::bwavOriginatorRef, String::fromUTF8 (originatorRef, 32));
  17429. values.set (WavAudioFormat::bwavOriginationDate, String::fromUTF8 (originationDate, 10));
  17430. values.set (WavAudioFormat::bwavOriginationTime, String::fromUTF8 (originationTime, 8));
  17431. const uint32 timeLow = ByteOrder::swapIfBigEndian (timeRefLow);
  17432. const uint32 timeHigh = ByteOrder::swapIfBigEndian (timeRefHigh);
  17433. const int64 time = (((int64)timeHigh) << 32) + timeLow;
  17434. values.set (WavAudioFormat::bwavTimeReference, String (time));
  17435. values.set (WavAudioFormat::bwavCodingHistory, String::fromUTF8 (codingHistory));
  17436. }
  17437. static MemoryBlock createFrom (const StringPairArray& values)
  17438. {
  17439. const size_t sizeNeeded = sizeof (BWAVChunk) + values [WavAudioFormat::bwavCodingHistory].getNumBytesAsUTF8();
  17440. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17441. data.fillWith (0);
  17442. BWAVChunk* b = (BWAVChunk*) data.getData();
  17443. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17444. // as they get called in the right order..
  17445. values [WavAudioFormat::bwavDescription].copyToUTF8 (b->description, 257);
  17446. values [WavAudioFormat::bwavOriginator].copyToUTF8 (b->originator, 33);
  17447. values [WavAudioFormat::bwavOriginatorRef].copyToUTF8 (b->originatorRef, 33);
  17448. values [WavAudioFormat::bwavOriginationDate].copyToUTF8 (b->originationDate, 11);
  17449. values [WavAudioFormat::bwavOriginationTime].copyToUTF8 (b->originationTime, 9);
  17450. const int64 time = values [WavAudioFormat::bwavTimeReference].getLargeIntValue();
  17451. b->timeRefLow = ByteOrder::swapIfBigEndian ((uint32) (time & 0xffffffff));
  17452. b->timeRefHigh = ByteOrder::swapIfBigEndian ((uint32) (time >> 32));
  17453. values [WavAudioFormat::bwavCodingHistory].copyToUTF8 (b->codingHistory, 0x7fffffff);
  17454. if (b->description[0] != 0
  17455. || b->originator[0] != 0
  17456. || b->originationDate[0] != 0
  17457. || b->originationTime[0] != 0
  17458. || b->codingHistory[0] != 0
  17459. || time != 0)
  17460. {
  17461. return data;
  17462. }
  17463. return MemoryBlock();
  17464. }
  17465. } PACKED;
  17466. struct SMPLChunk
  17467. {
  17468. struct SampleLoop
  17469. {
  17470. uint32 identifier;
  17471. uint32 type;
  17472. uint32 start;
  17473. uint32 end;
  17474. uint32 fraction;
  17475. uint32 playCount;
  17476. } PACKED;
  17477. uint32 manufacturer;
  17478. uint32 product;
  17479. uint32 samplePeriod;
  17480. uint32 midiUnityNote;
  17481. uint32 midiPitchFraction;
  17482. uint32 smpteFormat;
  17483. uint32 smpteOffset;
  17484. uint32 numSampleLoops;
  17485. uint32 samplerData;
  17486. SampleLoop loops[1];
  17487. void copyTo (StringPairArray& values, const int totalSize) const
  17488. {
  17489. values.set ("Manufacturer", String (ByteOrder::swapIfBigEndian (manufacturer)));
  17490. values.set ("Product", String (ByteOrder::swapIfBigEndian (product)));
  17491. values.set ("SamplePeriod", String (ByteOrder::swapIfBigEndian (samplePeriod)));
  17492. values.set ("MidiUnityNote", String (ByteOrder::swapIfBigEndian (midiUnityNote)));
  17493. values.set ("MidiPitchFraction", String (ByteOrder::swapIfBigEndian (midiPitchFraction)));
  17494. values.set ("SmpteFormat", String (ByteOrder::swapIfBigEndian (smpteFormat)));
  17495. values.set ("SmpteOffset", String (ByteOrder::swapIfBigEndian (smpteOffset)));
  17496. values.set ("NumSampleLoops", String (ByteOrder::swapIfBigEndian (numSampleLoops)));
  17497. values.set ("SamplerData", String (ByteOrder::swapIfBigEndian (samplerData)));
  17498. for (uint32 i = 0; i < numSampleLoops; ++i)
  17499. {
  17500. if ((uint8*) (loops + (i + 1)) > ((uint8*) this) + totalSize)
  17501. break;
  17502. const String prefix ("Loop" + String(i));
  17503. values.set (prefix + "Identifier", String (ByteOrder::swapIfBigEndian (loops[i].identifier)));
  17504. values.set (prefix + "Type", String (ByteOrder::swapIfBigEndian (loops[i].type)));
  17505. values.set (prefix + "Start", String (ByteOrder::swapIfBigEndian (loops[i].start)));
  17506. values.set (prefix + "End", String (ByteOrder::swapIfBigEndian (loops[i].end)));
  17507. values.set (prefix + "Fraction", String (ByteOrder::swapIfBigEndian (loops[i].fraction)));
  17508. values.set (prefix + "PlayCount", String (ByteOrder::swapIfBigEndian (loops[i].playCount)));
  17509. }
  17510. }
  17511. static MemoryBlock createFrom (const StringPairArray& values)
  17512. {
  17513. const int numLoops = jmin (64, values.getValue ("NumSampleLoops", "0").getIntValue());
  17514. if (numLoops <= 0)
  17515. return MemoryBlock();
  17516. const size_t sizeNeeded = sizeof (SMPLChunk) + (numLoops - 1) * sizeof (SampleLoop);
  17517. MemoryBlock data ((sizeNeeded + 3) & ~3);
  17518. data.fillWith (0);
  17519. SMPLChunk* s = (SMPLChunk*) data.getData();
  17520. // Allow these calls to overwrite an extra byte at the end, which is fine as long
  17521. // as they get called in the right order..
  17522. s->manufacturer = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Manufacturer", "0").getIntValue());
  17523. s->product = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("Product", "0").getIntValue());
  17524. s->samplePeriod = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplePeriod", "0").getIntValue());
  17525. s->midiUnityNote = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiUnityNote", "60").getIntValue());
  17526. s->midiPitchFraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("MidiPitchFraction", "0").getIntValue());
  17527. s->smpteFormat = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteFormat", "0").getIntValue());
  17528. s->smpteOffset = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SmpteOffset", "0").getIntValue());
  17529. s->numSampleLoops = ByteOrder::swapIfBigEndian ((uint32) numLoops);
  17530. s->samplerData = ByteOrder::swapIfBigEndian ((uint32) values.getValue ("SamplerData", "0").getIntValue());
  17531. for (int i = 0; i < numLoops; ++i)
  17532. {
  17533. const String prefix ("Loop" + String(i));
  17534. s->loops[i].identifier = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Identifier", "0").getIntValue());
  17535. s->loops[i].type = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Type", "0").getIntValue());
  17536. s->loops[i].start = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Start", "0").getIntValue());
  17537. s->loops[i].end = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "End", "0").getIntValue());
  17538. s->loops[i].fraction = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "Fraction", "0").getIntValue());
  17539. s->loops[i].playCount = ByteOrder::swapIfBigEndian ((uint32) values.getValue (prefix + "PlayCount", "0").getIntValue());
  17540. }
  17541. return data;
  17542. }
  17543. } PACKED;
  17544. struct ExtensibleWavSubFormat
  17545. {
  17546. uint32 data1;
  17547. uint16 data2;
  17548. uint16 data3;
  17549. uint8 data4[8];
  17550. } PACKED;
  17551. #if JUCE_MSVC
  17552. #pragma pack (pop)
  17553. #endif
  17554. #undef PACKED
  17555. class WavAudioFormatReader : public AudioFormatReader
  17556. {
  17557. int bytesPerFrame;
  17558. int64 dataChunkStart, dataLength;
  17559. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17560. WavAudioFormatReader (const WavAudioFormatReader&);
  17561. WavAudioFormatReader& operator= (const WavAudioFormatReader&);
  17562. public:
  17563. int64 bwavChunkStart, bwavSize;
  17564. WavAudioFormatReader (InputStream* const in)
  17565. : AudioFormatReader (in, TRANS (wavFormatName)),
  17566. dataLength (0),
  17567. bwavChunkStart (0),
  17568. bwavSize (0)
  17569. {
  17570. if (input->readInt() == chunkName ("RIFF"))
  17571. {
  17572. const uint32 len = (uint32) input->readInt();
  17573. const int64 end = input->getPosition() + len;
  17574. bool hasGotType = false;
  17575. bool hasGotData = false;
  17576. if (input->readInt() == chunkName ("WAVE"))
  17577. {
  17578. while (input->getPosition() < end
  17579. && ! input->isExhausted())
  17580. {
  17581. const int chunkType = input->readInt();
  17582. uint32 length = (uint32) input->readInt();
  17583. const int64 chunkEnd = input->getPosition() + length + (length & 1);
  17584. if (chunkType == chunkName ("fmt "))
  17585. {
  17586. // read the format chunk
  17587. const unsigned short format = input->readShort();
  17588. const short numChans = input->readShort();
  17589. sampleRate = input->readInt();
  17590. const int bytesPerSec = input->readInt();
  17591. numChannels = numChans;
  17592. bytesPerFrame = bytesPerSec / (int)sampleRate;
  17593. bitsPerSample = 8 * bytesPerFrame / numChans;
  17594. if (format == 3)
  17595. {
  17596. usesFloatingPointData = true;
  17597. }
  17598. else if (format == 0xfffe /*WAVE_FORMAT_EXTENSIBLE*/)
  17599. {
  17600. if (length < 40) // too short
  17601. {
  17602. bytesPerFrame = 0;
  17603. }
  17604. else
  17605. {
  17606. input->skipNextBytes (12); // skip over blockAlign, bitsPerSample and speakerPosition mask
  17607. ExtensibleWavSubFormat subFormat;
  17608. subFormat.data1 = input->readInt();
  17609. subFormat.data2 = input->readShort();
  17610. subFormat.data3 = input->readShort();
  17611. input->read (subFormat.data4, sizeof (subFormat.data4));
  17612. const ExtensibleWavSubFormat pcmFormat
  17613. = { 0x00000001, 0x0000, 0x0010, { 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71 } };
  17614. if (memcmp (&subFormat, &pcmFormat, sizeof (subFormat)) != 0)
  17615. {
  17616. const ExtensibleWavSubFormat ambisonicFormat
  17617. = { 0x00000001, 0x0721, 0x11d3, { 0x86, 0x44, 0xC8, 0xC1, 0xCA, 0x00, 0x00, 0x00 } };
  17618. if (memcmp (&subFormat, &ambisonicFormat, sizeof (subFormat)) != 0)
  17619. bytesPerFrame = 0;
  17620. }
  17621. }
  17622. }
  17623. else if (format != 1)
  17624. {
  17625. bytesPerFrame = 0;
  17626. }
  17627. hasGotType = true;
  17628. }
  17629. else if (chunkType == chunkName ("data"))
  17630. {
  17631. // get the data chunk's position
  17632. dataLength = length;
  17633. dataChunkStart = input->getPosition();
  17634. lengthInSamples = (bytesPerFrame > 0) ? (dataLength / bytesPerFrame) : 0;
  17635. hasGotData = true;
  17636. }
  17637. else if (chunkType == chunkName ("bext"))
  17638. {
  17639. bwavChunkStart = input->getPosition();
  17640. bwavSize = length;
  17641. // Broadcast-wav extension chunk..
  17642. HeapBlock <BWAVChunk> bwav;
  17643. bwav.calloc (jmax ((size_t) length + 1, sizeof (BWAVChunk)), 1);
  17644. input->read (bwav, length);
  17645. bwav->copyTo (metadataValues);
  17646. }
  17647. else if (chunkType == chunkName ("smpl"))
  17648. {
  17649. HeapBlock <SMPLChunk> smpl;
  17650. smpl.calloc (jmax ((size_t) length + 1, sizeof (SMPLChunk)), 1);
  17651. input->read (smpl, length);
  17652. smpl->copyTo (metadataValues, length);
  17653. }
  17654. else if (chunkEnd <= input->getPosition())
  17655. {
  17656. break;
  17657. }
  17658. input->setPosition (chunkEnd);
  17659. }
  17660. }
  17661. }
  17662. }
  17663. ~WavAudioFormatReader()
  17664. {
  17665. }
  17666. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  17667. int64 startSampleInFile, int numSamples)
  17668. {
  17669. const int64 samplesAvailable = lengthInSamples - startSampleInFile;
  17670. if (samplesAvailable < numSamples)
  17671. {
  17672. for (int i = numDestChannels; --i >= 0;)
  17673. if (destSamples[i] != 0)
  17674. zeromem (destSamples[i] + startOffsetInDestBuffer, sizeof (int) * numSamples);
  17675. numSamples = (int) samplesAvailable;
  17676. }
  17677. if (numSamples <= 0)
  17678. return true;
  17679. input->setPosition (dataChunkStart + startSampleInFile * bytesPerFrame);
  17680. const int tempBufSize = 480 * 3 * 4; // (keep this a multiple of 3)
  17681. char tempBuffer [tempBufSize];
  17682. while (numSamples > 0)
  17683. {
  17684. int* left = destSamples[0];
  17685. if (left != 0)
  17686. left += startOffsetInDestBuffer;
  17687. int* right = numDestChannels > 1 ? destSamples[1] : 0;
  17688. if (right != 0)
  17689. right += startOffsetInDestBuffer;
  17690. const int numThisTime = jmin (tempBufSize / bytesPerFrame, numSamples);
  17691. const int bytesRead = input->read (tempBuffer, numThisTime * bytesPerFrame);
  17692. if (bytesRead < numThisTime * bytesPerFrame)
  17693. zeromem (tempBuffer + bytesRead, numThisTime * bytesPerFrame - bytesRead);
  17694. if (bitsPerSample == 16)
  17695. {
  17696. const short* src = (const short*) tempBuffer;
  17697. if (numChannels > 1)
  17698. {
  17699. if (left == 0)
  17700. {
  17701. for (int i = numThisTime; --i >= 0;)
  17702. {
  17703. ++src;
  17704. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17705. }
  17706. }
  17707. else if (right == 0)
  17708. {
  17709. for (int i = numThisTime; --i >= 0;)
  17710. {
  17711. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17712. ++src;
  17713. }
  17714. }
  17715. else
  17716. {
  17717. for (int i = numThisTime; --i >= 0;)
  17718. {
  17719. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17720. *right++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17721. }
  17722. }
  17723. }
  17724. else
  17725. {
  17726. for (int i = numThisTime; --i >= 0;)
  17727. {
  17728. *left++ = (int) ByteOrder::swapIfBigEndian ((unsigned short) *src++) << 16;
  17729. }
  17730. }
  17731. }
  17732. else if (bitsPerSample == 24)
  17733. {
  17734. const char* src = (const char*) tempBuffer;
  17735. if (numChannels > 1)
  17736. {
  17737. if (left == 0)
  17738. {
  17739. for (int i = numThisTime; --i >= 0;)
  17740. {
  17741. src += 3;
  17742. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17743. src += 3;
  17744. }
  17745. }
  17746. else if (right == 0)
  17747. {
  17748. for (int i = numThisTime; --i >= 0;)
  17749. {
  17750. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17751. src += 6;
  17752. }
  17753. }
  17754. else
  17755. {
  17756. for (int i = 0; i < numThisTime; ++i)
  17757. {
  17758. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17759. src += 3;
  17760. *right++ = ByteOrder::littleEndian24Bit (src) << 8;
  17761. src += 3;
  17762. }
  17763. }
  17764. }
  17765. else
  17766. {
  17767. for (int i = 0; i < numThisTime; ++i)
  17768. {
  17769. *left++ = ByteOrder::littleEndian24Bit (src) << 8;
  17770. src += 3;
  17771. }
  17772. }
  17773. }
  17774. else if (bitsPerSample == 32)
  17775. {
  17776. const unsigned int* src = (const unsigned int*) tempBuffer;
  17777. unsigned int* l = (unsigned int*) left;
  17778. unsigned int* r = (unsigned int*) right;
  17779. if (numChannels > 1)
  17780. {
  17781. if (l == 0)
  17782. {
  17783. for (int i = numThisTime; --i >= 0;)
  17784. {
  17785. ++src;
  17786. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17787. }
  17788. }
  17789. else if (r == 0)
  17790. {
  17791. for (int i = numThisTime; --i >= 0;)
  17792. {
  17793. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17794. ++src;
  17795. }
  17796. }
  17797. else
  17798. {
  17799. for (int i = numThisTime; --i >= 0;)
  17800. {
  17801. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17802. *r++ = ByteOrder::swapIfBigEndian (*src++);
  17803. }
  17804. }
  17805. }
  17806. else
  17807. {
  17808. for (int i = numThisTime; --i >= 0;)
  17809. {
  17810. *l++ = ByteOrder::swapIfBigEndian (*src++);
  17811. }
  17812. }
  17813. left = (int*)l;
  17814. right = (int*)r;
  17815. }
  17816. else if (bitsPerSample == 8)
  17817. {
  17818. const unsigned char* src = (const unsigned char*) tempBuffer;
  17819. if (numChannels > 1)
  17820. {
  17821. if (left == 0)
  17822. {
  17823. for (int i = numThisTime; --i >= 0;)
  17824. {
  17825. ++src;
  17826. *right++ = ((int) *src++ - 128) << 24;
  17827. }
  17828. }
  17829. else if (right == 0)
  17830. {
  17831. for (int i = numThisTime; --i >= 0;)
  17832. {
  17833. *left++ = ((int) *src++ - 128) << 24;
  17834. ++src;
  17835. }
  17836. }
  17837. else
  17838. {
  17839. for (int i = numThisTime; --i >= 0;)
  17840. {
  17841. *left++ = ((int) *src++ - 128) << 24;
  17842. *right++ = ((int) *src++ - 128) << 24;
  17843. }
  17844. }
  17845. }
  17846. else
  17847. {
  17848. for (int i = numThisTime; --i >= 0;)
  17849. {
  17850. *left++ = ((int)*src++ - 128) << 24;
  17851. }
  17852. }
  17853. }
  17854. startOffsetInDestBuffer += numThisTime;
  17855. numSamples -= numThisTime;
  17856. }
  17857. if (numSamples > 0)
  17858. {
  17859. for (int i = numDestChannels; --i >= 0;)
  17860. if (destSamples[i] != 0)
  17861. zeromem (destSamples[i] + startOffsetInDestBuffer,
  17862. sizeof (int) * numSamples);
  17863. }
  17864. return true;
  17865. }
  17866. juce_UseDebuggingNewOperator
  17867. };
  17868. class WavAudioFormatWriter : public AudioFormatWriter
  17869. {
  17870. MemoryBlock tempBlock, bwavChunk, smplChunk;
  17871. uint32 lengthInSamples, bytesWritten;
  17872. int64 headerPosition;
  17873. bool writeFailed;
  17874. static inline int chunkName (const char* const name) { return (int) ByteOrder::littleEndianInt (name); }
  17875. WavAudioFormatWriter (const WavAudioFormatWriter&);
  17876. WavAudioFormatWriter& operator= (const WavAudioFormatWriter&);
  17877. void writeHeader()
  17878. {
  17879. const bool seekedOk = output->setPosition (headerPosition);
  17880. (void) seekedOk;
  17881. // if this fails, you've given it an output stream that can't seek! It needs
  17882. // to be able to seek back to write the header
  17883. jassert (seekedOk);
  17884. const int bytesPerFrame = numChannels * bitsPerSample / 8;
  17885. output->writeInt (chunkName ("RIFF"));
  17886. output->writeInt ((int) (lengthInSamples * bytesPerFrame
  17887. + ((bwavChunk.getSize() > 0) ? (44 + bwavChunk.getSize()) : 36)));
  17888. output->writeInt (chunkName ("WAVE"));
  17889. output->writeInt (chunkName ("fmt "));
  17890. output->writeInt (16);
  17891. output->writeShort ((bitsPerSample < 32) ? (short) 1 /*WAVE_FORMAT_PCM*/
  17892. : (short) 3 /*WAVE_FORMAT_IEEE_FLOAT*/);
  17893. output->writeShort ((short) numChannels);
  17894. output->writeInt ((int) sampleRate);
  17895. output->writeInt (bytesPerFrame * (int) sampleRate);
  17896. output->writeShort ((short) bytesPerFrame);
  17897. output->writeShort ((short) bitsPerSample);
  17898. if (bwavChunk.getSize() > 0)
  17899. {
  17900. output->writeInt (chunkName ("bext"));
  17901. output->writeInt ((int) bwavChunk.getSize());
  17902. output->write (bwavChunk.getData(), (int) bwavChunk.getSize());
  17903. }
  17904. if (smplChunk.getSize() > 0)
  17905. {
  17906. output->writeInt (chunkName ("smpl"));
  17907. output->writeInt ((int) smplChunk.getSize());
  17908. output->write (smplChunk.getData(), (int) smplChunk.getSize());
  17909. }
  17910. output->writeInt (chunkName ("data"));
  17911. output->writeInt (lengthInSamples * bytesPerFrame);
  17912. usesFloatingPointData = (bitsPerSample == 32);
  17913. }
  17914. public:
  17915. WavAudioFormatWriter (OutputStream* const out,
  17916. const double sampleRate_,
  17917. const unsigned int numChannels_,
  17918. const int bits,
  17919. const StringPairArray& metadataValues)
  17920. : AudioFormatWriter (out,
  17921. TRANS (wavFormatName),
  17922. sampleRate_,
  17923. numChannels_,
  17924. bits),
  17925. lengthInSamples (0),
  17926. bytesWritten (0),
  17927. writeFailed (false)
  17928. {
  17929. if (metadataValues.size() > 0)
  17930. {
  17931. bwavChunk = BWAVChunk::createFrom (metadataValues);
  17932. smplChunk = SMPLChunk::createFrom (metadataValues);
  17933. }
  17934. headerPosition = out->getPosition();
  17935. writeHeader();
  17936. }
  17937. ~WavAudioFormatWriter()
  17938. {
  17939. writeHeader();
  17940. }
  17941. bool write (const int** data, int numSamples)
  17942. {
  17943. if (writeFailed)
  17944. return false;
  17945. const int bytes = numChannels * numSamples * bitsPerSample / 8;
  17946. tempBlock.ensureSize (bytes, false);
  17947. char* buffer = (char*) tempBlock.getData();
  17948. const int* left = data[0];
  17949. const int* right = data[1];
  17950. if (right == 0)
  17951. right = left;
  17952. if (bitsPerSample == 16)
  17953. {
  17954. short* b = (short*) buffer;
  17955. if (numChannels > 1)
  17956. {
  17957. for (int i = numSamples; --i >= 0;)
  17958. {
  17959. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17960. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*right++ >> 16));
  17961. }
  17962. }
  17963. else
  17964. {
  17965. for (int i = numSamples; --i >= 0;)
  17966. {
  17967. *b++ = (short) ByteOrder::swapIfBigEndian ((unsigned short) (*left++ >> 16));
  17968. }
  17969. }
  17970. }
  17971. else if (bitsPerSample == 24)
  17972. {
  17973. char* b = (char*) buffer;
  17974. if (numChannels > 1)
  17975. {
  17976. for (int i = numSamples; --i >= 0;)
  17977. {
  17978. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17979. b += 3;
  17980. ByteOrder::littleEndian24BitToChars ((*right++) >> 8, b);
  17981. b += 3;
  17982. }
  17983. }
  17984. else
  17985. {
  17986. for (int i = numSamples; --i >= 0;)
  17987. {
  17988. ByteOrder::littleEndian24BitToChars ((*left++) >> 8, b);
  17989. b += 3;
  17990. }
  17991. }
  17992. }
  17993. else if (bitsPerSample == 32)
  17994. {
  17995. unsigned int* b = (unsigned int*) buffer;
  17996. if (numChannels > 1)
  17997. {
  17998. for (int i = numSamples; --i >= 0;)
  17999. {
  18000. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  18001. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *right++);
  18002. }
  18003. }
  18004. else
  18005. {
  18006. for (int i = numSamples; --i >= 0;)
  18007. {
  18008. *b++ = ByteOrder::swapIfBigEndian ((unsigned int) *left++);
  18009. }
  18010. }
  18011. }
  18012. else if (bitsPerSample == 8)
  18013. {
  18014. unsigned char* b = (unsigned char*) buffer;
  18015. if (numChannels > 1)
  18016. {
  18017. for (int i = numSamples; --i >= 0;)
  18018. {
  18019. *b++ = (unsigned char) (128 + (*left++ >> 24));
  18020. *b++ = (unsigned char) (128 + (*right++ >> 24));
  18021. }
  18022. }
  18023. else
  18024. {
  18025. for (int i = numSamples; --i >= 0;)
  18026. {
  18027. *b++ = (unsigned char) (128 + (*left++ >> 24));
  18028. }
  18029. }
  18030. }
  18031. if (bytesWritten + bytes >= (uint32) 0xfff00000
  18032. || ! output->write (buffer, bytes))
  18033. {
  18034. // failed to write to disk, so let's try writing the header.
  18035. // If it's just run out of disk space, then if it does manage
  18036. // to write the header, we'll still have a useable file..
  18037. writeHeader();
  18038. writeFailed = true;
  18039. return false;
  18040. }
  18041. else
  18042. {
  18043. bytesWritten += bytes;
  18044. lengthInSamples += numSamples;
  18045. return true;
  18046. }
  18047. }
  18048. juce_UseDebuggingNewOperator
  18049. };
  18050. WavAudioFormat::WavAudioFormat()
  18051. : AudioFormat (TRANS (wavFormatName), (const tchar**) wavExtensions)
  18052. {
  18053. }
  18054. WavAudioFormat::~WavAudioFormat()
  18055. {
  18056. }
  18057. const Array <int> WavAudioFormat::getPossibleSampleRates()
  18058. {
  18059. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  18060. return Array <int> (rates);
  18061. }
  18062. const Array <int> WavAudioFormat::getPossibleBitDepths()
  18063. {
  18064. const int depths[] = { 8, 16, 24, 32, 0 };
  18065. return Array <int> (depths);
  18066. }
  18067. bool WavAudioFormat::canDoStereo()
  18068. {
  18069. return true;
  18070. }
  18071. bool WavAudioFormat::canDoMono()
  18072. {
  18073. return true;
  18074. }
  18075. AudioFormatReader* WavAudioFormat::createReaderFor (InputStream* sourceStream,
  18076. const bool deleteStreamIfOpeningFails)
  18077. {
  18078. ScopedPointer <WavAudioFormatReader> r (new WavAudioFormatReader (sourceStream));
  18079. if (r->sampleRate != 0)
  18080. return r.release();
  18081. if (! deleteStreamIfOpeningFails)
  18082. r->input = 0;
  18083. return 0;
  18084. }
  18085. AudioFormatWriter* WavAudioFormat::createWriterFor (OutputStream* out,
  18086. double sampleRate,
  18087. unsigned int numChannels,
  18088. int bitsPerSample,
  18089. const StringPairArray& metadataValues,
  18090. int /*qualityOptionIndex*/)
  18091. {
  18092. if (getPossibleBitDepths().contains (bitsPerSample))
  18093. {
  18094. return new WavAudioFormatWriter (out,
  18095. sampleRate,
  18096. numChannels,
  18097. bitsPerSample,
  18098. metadataValues);
  18099. }
  18100. return 0;
  18101. }
  18102. static bool juce_slowCopyOfWavFileWithNewMetadata (const File& file, const StringPairArray& metadata)
  18103. {
  18104. TemporaryFile tempFile (file);
  18105. WavAudioFormat wav;
  18106. ScopedPointer <AudioFormatReader> reader (wav.createReaderFor (file.createInputStream(), true));
  18107. if (reader != 0)
  18108. {
  18109. ScopedPointer <OutputStream> outStream (tempFile.getFile().createOutputStream());
  18110. if (outStream != 0)
  18111. {
  18112. ScopedPointer <AudioFormatWriter> writer (wav.createWriterFor (outStream, reader->sampleRate,
  18113. reader->numChannels, reader->bitsPerSample,
  18114. metadata, 0));
  18115. if (writer != 0)
  18116. {
  18117. outStream.release();
  18118. bool ok = writer->writeFromAudioReader (*reader, 0, -1);
  18119. writer = 0;
  18120. reader = 0;
  18121. return ok && tempFile.overwriteTargetFileWithTemporary();
  18122. }
  18123. }
  18124. }
  18125. return false;
  18126. }
  18127. bool WavAudioFormat::replaceMetadataInFile (const File& wavFile, const StringPairArray& newMetadata)
  18128. {
  18129. ScopedPointer <WavAudioFormatReader> reader ((WavAudioFormatReader*) createReaderFor (wavFile.createInputStream(), true));
  18130. if (reader != 0)
  18131. {
  18132. const int64 bwavPos = reader->bwavChunkStart;
  18133. const int64 bwavSize = reader->bwavSize;
  18134. reader = 0;
  18135. if (bwavSize > 0)
  18136. {
  18137. MemoryBlock chunk = BWAVChunk::createFrom (newMetadata);
  18138. if (chunk.getSize() <= (size_t) bwavSize)
  18139. {
  18140. // the new one will fit in the space available, so write it directly..
  18141. const int64 oldSize = wavFile.getSize();
  18142. {
  18143. ScopedPointer <FileOutputStream> out (wavFile.createOutputStream());
  18144. out->setPosition (bwavPos);
  18145. out->write (chunk.getData(), (int) chunk.getSize());
  18146. out->setPosition (oldSize);
  18147. }
  18148. jassert (wavFile.getSize() == oldSize);
  18149. return true;
  18150. }
  18151. }
  18152. }
  18153. return juce_slowCopyOfWavFileWithNewMetadata (wavFile, newMetadata);
  18154. }
  18155. END_JUCE_NAMESPACE
  18156. /*** End of inlined file: juce_WavAudioFormat.cpp ***/
  18157. /*** Start of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18158. BEGIN_JUCE_NAMESPACE
  18159. AudioFormatReaderSource::AudioFormatReaderSource (AudioFormatReader* const reader_,
  18160. const bool deleteReaderWhenThisIsDeleted)
  18161. : reader (reader_),
  18162. deleteReader (deleteReaderWhenThisIsDeleted),
  18163. nextPlayPos (0),
  18164. looping (false)
  18165. {
  18166. jassert (reader != 0);
  18167. }
  18168. AudioFormatReaderSource::~AudioFormatReaderSource()
  18169. {
  18170. releaseResources();
  18171. if (deleteReader)
  18172. delete reader;
  18173. }
  18174. void AudioFormatReaderSource::setNextReadPosition (int newPosition)
  18175. {
  18176. nextPlayPos = newPosition;
  18177. }
  18178. void AudioFormatReaderSource::setLooping (const bool shouldLoop) throw()
  18179. {
  18180. looping = shouldLoop;
  18181. }
  18182. int AudioFormatReaderSource::getNextReadPosition() const
  18183. {
  18184. return (looping) ? (nextPlayPos % (int) reader->lengthInSamples)
  18185. : nextPlayPos;
  18186. }
  18187. int AudioFormatReaderSource::getTotalLength() const
  18188. {
  18189. return (int) reader->lengthInSamples;
  18190. }
  18191. void AudioFormatReaderSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  18192. double /*sampleRate*/)
  18193. {
  18194. }
  18195. void AudioFormatReaderSource::releaseResources()
  18196. {
  18197. }
  18198. void AudioFormatReaderSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18199. {
  18200. if (info.numSamples > 0)
  18201. {
  18202. const int start = nextPlayPos;
  18203. if (looping)
  18204. {
  18205. const int newStart = start % (int) reader->lengthInSamples;
  18206. const int newEnd = (start + info.numSamples) % (int) reader->lengthInSamples;
  18207. if (newEnd > newStart)
  18208. {
  18209. info.buffer->readFromAudioReader (reader,
  18210. info.startSample,
  18211. newEnd - newStart,
  18212. newStart,
  18213. true, true);
  18214. }
  18215. else
  18216. {
  18217. const int endSamps = (int) reader->lengthInSamples - newStart;
  18218. info.buffer->readFromAudioReader (reader,
  18219. info.startSample,
  18220. endSamps,
  18221. newStart,
  18222. true, true);
  18223. info.buffer->readFromAudioReader (reader,
  18224. info.startSample + endSamps,
  18225. newEnd,
  18226. 0,
  18227. true, true);
  18228. }
  18229. nextPlayPos = newEnd;
  18230. }
  18231. else
  18232. {
  18233. info.buffer->readFromAudioReader (reader,
  18234. info.startSample,
  18235. info.numSamples,
  18236. start,
  18237. true, true);
  18238. nextPlayPos += info.numSamples;
  18239. }
  18240. }
  18241. }
  18242. END_JUCE_NAMESPACE
  18243. /*** End of inlined file: juce_AudioFormatReaderSource.cpp ***/
  18244. /*** Start of inlined file: juce_AudioSourcePlayer.cpp ***/
  18245. BEGIN_JUCE_NAMESPACE
  18246. AudioSourcePlayer::AudioSourcePlayer()
  18247. : source (0),
  18248. sampleRate (0),
  18249. bufferSize (0),
  18250. tempBuffer (2, 8),
  18251. lastGain (1.0f),
  18252. gain (1.0f)
  18253. {
  18254. }
  18255. AudioSourcePlayer::~AudioSourcePlayer()
  18256. {
  18257. setSource (0);
  18258. }
  18259. void AudioSourcePlayer::setSource (AudioSource* newSource)
  18260. {
  18261. if (source != newSource)
  18262. {
  18263. AudioSource* const oldSource = source;
  18264. if (newSource != 0 && bufferSize > 0 && sampleRate > 0)
  18265. newSource->prepareToPlay (bufferSize, sampleRate);
  18266. {
  18267. const ScopedLock sl (readLock);
  18268. source = newSource;
  18269. }
  18270. if (oldSource != 0)
  18271. oldSource->releaseResources();
  18272. }
  18273. }
  18274. void AudioSourcePlayer::setGain (const float newGain) throw()
  18275. {
  18276. gain = newGain;
  18277. }
  18278. void AudioSourcePlayer::audioDeviceIOCallback (const float** inputChannelData,
  18279. int totalNumInputChannels,
  18280. float** outputChannelData,
  18281. int totalNumOutputChannels,
  18282. int numSamples)
  18283. {
  18284. // these should have been prepared by audioDeviceAboutToStart()...
  18285. jassert (sampleRate > 0 && bufferSize > 0);
  18286. const ScopedLock sl (readLock);
  18287. if (source != 0)
  18288. {
  18289. AudioSourceChannelInfo info;
  18290. int i, numActiveChans = 0, numInputs = 0, numOutputs = 0;
  18291. // messy stuff needed to compact the channels down into an array
  18292. // of non-zero pointers..
  18293. for (i = 0; i < totalNumInputChannels; ++i)
  18294. {
  18295. if (inputChannelData[i] != 0)
  18296. {
  18297. inputChans [numInputs++] = inputChannelData[i];
  18298. if (numInputs >= numElementsInArray (inputChans))
  18299. break;
  18300. }
  18301. }
  18302. for (i = 0; i < totalNumOutputChannels; ++i)
  18303. {
  18304. if (outputChannelData[i] != 0)
  18305. {
  18306. outputChans [numOutputs++] = outputChannelData[i];
  18307. if (numOutputs >= numElementsInArray (outputChans))
  18308. break;
  18309. }
  18310. }
  18311. if (numInputs > numOutputs)
  18312. {
  18313. // if there aren't enough output channels for the number of
  18314. // inputs, we need to create some temporary extra ones (can't
  18315. // use the input data in case it gets written to)
  18316. tempBuffer.setSize (numInputs - numOutputs, numSamples,
  18317. false, false, true);
  18318. for (i = 0; i < numOutputs; ++i)
  18319. {
  18320. channels[numActiveChans] = outputChans[i];
  18321. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18322. ++numActiveChans;
  18323. }
  18324. for (i = numOutputs; i < numInputs; ++i)
  18325. {
  18326. channels[numActiveChans] = tempBuffer.getSampleData (i - numOutputs, 0);
  18327. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18328. ++numActiveChans;
  18329. }
  18330. }
  18331. else
  18332. {
  18333. for (i = 0; i < numInputs; ++i)
  18334. {
  18335. channels[numActiveChans] = outputChans[i];
  18336. memcpy (channels[numActiveChans], inputChans[i], sizeof (float) * numSamples);
  18337. ++numActiveChans;
  18338. }
  18339. for (i = numInputs; i < numOutputs; ++i)
  18340. {
  18341. channels[numActiveChans] = outputChans[i];
  18342. zeromem (channels[numActiveChans], sizeof (float) * numSamples);
  18343. ++numActiveChans;
  18344. }
  18345. }
  18346. AudioSampleBuffer buffer (channels, numActiveChans, numSamples);
  18347. info.buffer = &buffer;
  18348. info.startSample = 0;
  18349. info.numSamples = numSamples;
  18350. source->getNextAudioBlock (info);
  18351. for (i = info.buffer->getNumChannels(); --i >= 0;)
  18352. info.buffer->applyGainRamp (i, info.startSample, info.numSamples, lastGain, gain);
  18353. lastGain = gain;
  18354. }
  18355. else
  18356. {
  18357. for (int i = 0; i < totalNumOutputChannels; ++i)
  18358. if (outputChannelData[i] != 0)
  18359. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  18360. }
  18361. }
  18362. void AudioSourcePlayer::audioDeviceAboutToStart (AudioIODevice* device)
  18363. {
  18364. sampleRate = device->getCurrentSampleRate();
  18365. bufferSize = device->getCurrentBufferSizeSamples();
  18366. zeromem (channels, sizeof (channels));
  18367. if (source != 0)
  18368. source->prepareToPlay (bufferSize, sampleRate);
  18369. }
  18370. void AudioSourcePlayer::audioDeviceStopped()
  18371. {
  18372. if (source != 0)
  18373. source->releaseResources();
  18374. sampleRate = 0.0;
  18375. bufferSize = 0;
  18376. tempBuffer.setSize (2, 8);
  18377. }
  18378. END_JUCE_NAMESPACE
  18379. /*** End of inlined file: juce_AudioSourcePlayer.cpp ***/
  18380. /*** Start of inlined file: juce_AudioTransportSource.cpp ***/
  18381. BEGIN_JUCE_NAMESPACE
  18382. AudioTransportSource::AudioTransportSource()
  18383. : source (0),
  18384. resamplerSource (0),
  18385. bufferingSource (0),
  18386. positionableSource (0),
  18387. masterSource (0),
  18388. gain (1.0f),
  18389. lastGain (1.0f),
  18390. playing (false),
  18391. stopped (true),
  18392. sampleRate (44100.0),
  18393. sourceSampleRate (0.0),
  18394. blockSize (128),
  18395. readAheadBufferSize (0),
  18396. isPrepared (false),
  18397. inputStreamEOF (false)
  18398. {
  18399. }
  18400. AudioTransportSource::~AudioTransportSource()
  18401. {
  18402. setSource (0);
  18403. releaseResources();
  18404. }
  18405. void AudioTransportSource::setSource (PositionableAudioSource* const newSource,
  18406. int readAheadBufferSize_,
  18407. double sourceSampleRateToCorrectFor)
  18408. {
  18409. if (source == newSource)
  18410. {
  18411. if (source == 0)
  18412. return;
  18413. setSource (0, 0, 0); // deselect and reselect to avoid releasing resources wrongly
  18414. }
  18415. readAheadBufferSize = readAheadBufferSize_;
  18416. sourceSampleRate = sourceSampleRateToCorrectFor;
  18417. ResamplingAudioSource* newResamplerSource = 0;
  18418. BufferingAudioSource* newBufferingSource = 0;
  18419. PositionableAudioSource* newPositionableSource = 0;
  18420. AudioSource* newMasterSource = 0;
  18421. ScopedPointer <ResamplingAudioSource> oldResamplerSource (resamplerSource);
  18422. ScopedPointer <BufferingAudioSource> oldBufferingSource (bufferingSource);
  18423. AudioSource* oldMasterSource = masterSource;
  18424. if (newSource != 0)
  18425. {
  18426. newPositionableSource = newSource;
  18427. if (readAheadBufferSize_ > 0)
  18428. newPositionableSource = newBufferingSource
  18429. = new BufferingAudioSource (newPositionableSource, false, readAheadBufferSize_);
  18430. newPositionableSource->setNextReadPosition (0);
  18431. if (sourceSampleRateToCorrectFor != 0)
  18432. newMasterSource = newResamplerSource
  18433. = new ResamplingAudioSource (newPositionableSource, false);
  18434. else
  18435. newMasterSource = newPositionableSource;
  18436. if (isPrepared)
  18437. {
  18438. if (newResamplerSource != 0 && sourceSampleRate > 0 && sampleRate > 0)
  18439. newResamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18440. newMasterSource->prepareToPlay (blockSize, sampleRate);
  18441. }
  18442. }
  18443. {
  18444. const ScopedLock sl (callbackLock);
  18445. source = newSource;
  18446. resamplerSource = newResamplerSource;
  18447. bufferingSource = newBufferingSource;
  18448. masterSource = newMasterSource;
  18449. positionableSource = newPositionableSource;
  18450. playing = false;
  18451. }
  18452. if (oldMasterSource != 0)
  18453. oldMasterSource->releaseResources();
  18454. }
  18455. void AudioTransportSource::start()
  18456. {
  18457. if ((! playing) && masterSource != 0)
  18458. {
  18459. {
  18460. const ScopedLock sl (callbackLock);
  18461. playing = true;
  18462. stopped = false;
  18463. inputStreamEOF = false;
  18464. }
  18465. sendChangeMessage (this);
  18466. }
  18467. }
  18468. void AudioTransportSource::stop()
  18469. {
  18470. if (playing)
  18471. {
  18472. {
  18473. const ScopedLock sl (callbackLock);
  18474. playing = false;
  18475. }
  18476. int n = 500;
  18477. while (--n >= 0 && ! stopped)
  18478. Thread::sleep (2);
  18479. sendChangeMessage (this);
  18480. }
  18481. }
  18482. void AudioTransportSource::setPosition (double newPosition)
  18483. {
  18484. if (sampleRate > 0.0)
  18485. setNextReadPosition (roundToInt (newPosition * sampleRate));
  18486. }
  18487. double AudioTransportSource::getCurrentPosition() const
  18488. {
  18489. if (sampleRate > 0.0)
  18490. return getNextReadPosition() / sampleRate;
  18491. else
  18492. return 0.0;
  18493. }
  18494. void AudioTransportSource::setNextReadPosition (int newPosition)
  18495. {
  18496. if (positionableSource != 0)
  18497. {
  18498. if (sampleRate > 0 && sourceSampleRate > 0)
  18499. newPosition = roundToInt (newPosition * sourceSampleRate / sampleRate);
  18500. positionableSource->setNextReadPosition (newPosition);
  18501. }
  18502. }
  18503. int AudioTransportSource::getNextReadPosition() const
  18504. {
  18505. if (positionableSource != 0)
  18506. {
  18507. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18508. return roundToInt (positionableSource->getNextReadPosition() * ratio);
  18509. }
  18510. return 0;
  18511. }
  18512. int AudioTransportSource::getTotalLength() const
  18513. {
  18514. const ScopedLock sl (callbackLock);
  18515. if (positionableSource != 0)
  18516. {
  18517. const double ratio = (sampleRate > 0 && sourceSampleRate > 0) ? sampleRate / sourceSampleRate : 1.0;
  18518. return roundToInt (positionableSource->getTotalLength() * ratio);
  18519. }
  18520. return 0;
  18521. }
  18522. bool AudioTransportSource::isLooping() const
  18523. {
  18524. const ScopedLock sl (callbackLock);
  18525. return positionableSource != 0
  18526. && positionableSource->isLooping();
  18527. }
  18528. void AudioTransportSource::setGain (const float newGain) throw()
  18529. {
  18530. gain = newGain;
  18531. }
  18532. void AudioTransportSource::prepareToPlay (int samplesPerBlockExpected,
  18533. double sampleRate_)
  18534. {
  18535. const ScopedLock sl (callbackLock);
  18536. sampleRate = sampleRate_;
  18537. blockSize = samplesPerBlockExpected;
  18538. if (masterSource != 0)
  18539. masterSource->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18540. if (resamplerSource != 0 && sourceSampleRate != 0)
  18541. resamplerSource->setResamplingRatio (sourceSampleRate / sampleRate);
  18542. isPrepared = true;
  18543. }
  18544. void AudioTransportSource::releaseResources()
  18545. {
  18546. const ScopedLock sl (callbackLock);
  18547. if (masterSource != 0)
  18548. masterSource->releaseResources();
  18549. isPrepared = false;
  18550. }
  18551. void AudioTransportSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18552. {
  18553. const ScopedLock sl (callbackLock);
  18554. inputStreamEOF = false;
  18555. if (masterSource != 0 && ! stopped)
  18556. {
  18557. masterSource->getNextAudioBlock (info);
  18558. if (! playing)
  18559. {
  18560. // just stopped playing, so fade out the last block..
  18561. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18562. info.buffer->applyGainRamp (i, info.startSample, jmin (256, info.numSamples), 1.0f, 0.0f);
  18563. if (info.numSamples > 256)
  18564. info.buffer->clear (info.startSample + 256, info.numSamples - 256);
  18565. }
  18566. if (positionableSource->getNextReadPosition() > positionableSource->getTotalLength() + 1
  18567. && ! positionableSource->isLooping())
  18568. {
  18569. playing = false;
  18570. inputStreamEOF = true;
  18571. sendChangeMessage (this);
  18572. }
  18573. stopped = ! playing;
  18574. for (int i = info.buffer->getNumChannels(); --i >= 0;)
  18575. {
  18576. info.buffer->applyGainRamp (i, info.startSample, info.numSamples,
  18577. lastGain, gain);
  18578. }
  18579. }
  18580. else
  18581. {
  18582. info.clearActiveBufferRegion();
  18583. stopped = true;
  18584. }
  18585. lastGain = gain;
  18586. }
  18587. END_JUCE_NAMESPACE
  18588. /*** End of inlined file: juce_AudioTransportSource.cpp ***/
  18589. /*** Start of inlined file: juce_BufferingAudioSource.cpp ***/
  18590. BEGIN_JUCE_NAMESPACE
  18591. class SharedBufferingAudioSourceThread : public DeletedAtShutdown,
  18592. public Thread,
  18593. private Timer
  18594. {
  18595. public:
  18596. SharedBufferingAudioSourceThread()
  18597. : Thread ("Audio Buffer")
  18598. {
  18599. }
  18600. ~SharedBufferingAudioSourceThread()
  18601. {
  18602. stopThread (10000);
  18603. clearSingletonInstance();
  18604. }
  18605. juce_DeclareSingleton (SharedBufferingAudioSourceThread, false)
  18606. void addSource (BufferingAudioSource* source)
  18607. {
  18608. const ScopedLock sl (lock);
  18609. if (! sources.contains ((void*) source))
  18610. {
  18611. sources.add ((void*) source);
  18612. startThread();
  18613. stopTimer();
  18614. }
  18615. notify();
  18616. }
  18617. void removeSource (BufferingAudioSource* source)
  18618. {
  18619. const ScopedLock sl (lock);
  18620. sources.removeValue ((void*) source);
  18621. if (sources.size() == 0)
  18622. startTimer (5000);
  18623. }
  18624. private:
  18625. VoidArray sources;
  18626. CriticalSection lock;
  18627. void run()
  18628. {
  18629. while (! threadShouldExit())
  18630. {
  18631. bool busy = false;
  18632. for (int i = sources.size(); --i >= 0;)
  18633. {
  18634. if (threadShouldExit())
  18635. return;
  18636. const ScopedLock sl (lock);
  18637. BufferingAudioSource* const b = (BufferingAudioSource*) sources[i];
  18638. if (b != 0 && b->readNextBufferChunk())
  18639. busy = true;
  18640. }
  18641. if (! busy)
  18642. wait (500);
  18643. }
  18644. }
  18645. void timerCallback()
  18646. {
  18647. stopTimer();
  18648. if (sources.size() == 0)
  18649. deleteInstance();
  18650. }
  18651. SharedBufferingAudioSourceThread (const SharedBufferingAudioSourceThread&);
  18652. SharedBufferingAudioSourceThread& operator= (const SharedBufferingAudioSourceThread&);
  18653. };
  18654. juce_ImplementSingleton (SharedBufferingAudioSourceThread)
  18655. BufferingAudioSource::BufferingAudioSource (PositionableAudioSource* source_,
  18656. const bool deleteSourceWhenDeleted_,
  18657. int numberOfSamplesToBuffer_)
  18658. : source (source_),
  18659. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18660. numberOfSamplesToBuffer (jmax (1024, numberOfSamplesToBuffer_)),
  18661. buffer (2, 0),
  18662. bufferValidStart (0),
  18663. bufferValidEnd (0),
  18664. nextPlayPos (0),
  18665. wasSourceLooping (false)
  18666. {
  18667. jassert (source_ != 0);
  18668. jassert (numberOfSamplesToBuffer_ > 1024); // not much point using this class if you're
  18669. // not using a larger buffer..
  18670. }
  18671. BufferingAudioSource::~BufferingAudioSource()
  18672. {
  18673. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18674. if (thread != 0)
  18675. thread->removeSource (this);
  18676. if (deleteSourceWhenDeleted)
  18677. delete source;
  18678. }
  18679. void BufferingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate_)
  18680. {
  18681. source->prepareToPlay (samplesPerBlockExpected, sampleRate_);
  18682. sampleRate = sampleRate_;
  18683. buffer.setSize (2, jmax (samplesPerBlockExpected * 2, numberOfSamplesToBuffer));
  18684. buffer.clear();
  18685. bufferValidStart = 0;
  18686. bufferValidEnd = 0;
  18687. SharedBufferingAudioSourceThread::getInstance()->addSource (this);
  18688. while (bufferValidEnd - bufferValidStart < jmin (((int) sampleRate_) / 4,
  18689. buffer.getNumSamples() / 2))
  18690. {
  18691. SharedBufferingAudioSourceThread::getInstance()->notify();
  18692. Thread::sleep (5);
  18693. }
  18694. }
  18695. void BufferingAudioSource::releaseResources()
  18696. {
  18697. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18698. if (thread != 0)
  18699. thread->removeSource (this);
  18700. buffer.setSize (2, 0);
  18701. source->releaseResources();
  18702. }
  18703. void BufferingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  18704. {
  18705. const ScopedLock sl (bufferStartPosLock);
  18706. const int validStart = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos) - nextPlayPos;
  18707. const int validEnd = jlimit (bufferValidStart, bufferValidEnd, nextPlayPos + info.numSamples) - nextPlayPos;
  18708. if (validStart == validEnd)
  18709. {
  18710. // total cache miss
  18711. info.clearActiveBufferRegion();
  18712. }
  18713. else
  18714. {
  18715. if (validStart > 0)
  18716. info.buffer->clear (info.startSample, validStart); // partial cache miss at start
  18717. if (validEnd < info.numSamples)
  18718. info.buffer->clear (info.startSample + validEnd,
  18719. info.numSamples - validEnd); // partial cache miss at end
  18720. if (validStart < validEnd)
  18721. {
  18722. for (int chan = jmin (2, info.buffer->getNumChannels()); --chan >= 0;)
  18723. {
  18724. const int startBufferIndex = (validStart + nextPlayPos) % buffer.getNumSamples();
  18725. const int endBufferIndex = (validEnd + nextPlayPos) % buffer.getNumSamples();
  18726. if (startBufferIndex < endBufferIndex)
  18727. {
  18728. info.buffer->copyFrom (chan, info.startSample + validStart,
  18729. buffer,
  18730. chan, startBufferIndex,
  18731. validEnd - validStart);
  18732. }
  18733. else
  18734. {
  18735. const int initialSize = buffer.getNumSamples() - startBufferIndex;
  18736. info.buffer->copyFrom (chan, info.startSample + validStart,
  18737. buffer,
  18738. chan, startBufferIndex,
  18739. initialSize);
  18740. info.buffer->copyFrom (chan, info.startSample + validStart + initialSize,
  18741. buffer,
  18742. chan, 0,
  18743. (validEnd - validStart) - initialSize);
  18744. }
  18745. }
  18746. }
  18747. nextPlayPos += info.numSamples;
  18748. if (source->isLooping() && nextPlayPos > 0)
  18749. nextPlayPos %= source->getTotalLength();
  18750. }
  18751. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18752. if (thread != 0)
  18753. thread->notify();
  18754. }
  18755. int BufferingAudioSource::getNextReadPosition() const
  18756. {
  18757. return (source->isLooping() && nextPlayPos > 0)
  18758. ? nextPlayPos % source->getTotalLength()
  18759. : nextPlayPos;
  18760. }
  18761. void BufferingAudioSource::setNextReadPosition (int newPosition)
  18762. {
  18763. const ScopedLock sl (bufferStartPosLock);
  18764. nextPlayPos = newPosition;
  18765. SharedBufferingAudioSourceThread* const thread = SharedBufferingAudioSourceThread::getInstanceWithoutCreating();
  18766. if (thread != 0)
  18767. thread->notify();
  18768. }
  18769. bool BufferingAudioSource::readNextBufferChunk()
  18770. {
  18771. int newBVS, newBVE, sectionToReadStart, sectionToReadEnd;
  18772. {
  18773. const ScopedLock sl (bufferStartPosLock);
  18774. if (wasSourceLooping != isLooping())
  18775. {
  18776. wasSourceLooping = isLooping();
  18777. bufferValidStart = 0;
  18778. bufferValidEnd = 0;
  18779. }
  18780. newBVS = jmax (0, nextPlayPos);
  18781. newBVE = newBVS + buffer.getNumSamples() - 4;
  18782. sectionToReadStart = 0;
  18783. sectionToReadEnd = 0;
  18784. const int maxChunkSize = 2048;
  18785. if (newBVS < bufferValidStart || newBVS >= bufferValidEnd)
  18786. {
  18787. newBVE = jmin (newBVE, newBVS + maxChunkSize);
  18788. sectionToReadStart = newBVS;
  18789. sectionToReadEnd = newBVE;
  18790. bufferValidStart = 0;
  18791. bufferValidEnd = 0;
  18792. }
  18793. else if (abs (newBVS - bufferValidStart) > 512
  18794. || abs (newBVE - bufferValidEnd) > 512)
  18795. {
  18796. newBVE = jmin (newBVE, bufferValidEnd + maxChunkSize);
  18797. sectionToReadStart = bufferValidEnd;
  18798. sectionToReadEnd = newBVE;
  18799. bufferValidStart = newBVS;
  18800. bufferValidEnd = jmin (bufferValidEnd, newBVE);
  18801. }
  18802. }
  18803. if (sectionToReadStart != sectionToReadEnd)
  18804. {
  18805. const int bufferIndexStart = sectionToReadStart % buffer.getNumSamples();
  18806. const int bufferIndexEnd = sectionToReadEnd % buffer.getNumSamples();
  18807. if (bufferIndexStart < bufferIndexEnd)
  18808. {
  18809. readBufferSection (sectionToReadStart,
  18810. sectionToReadEnd - sectionToReadStart,
  18811. bufferIndexStart);
  18812. }
  18813. else
  18814. {
  18815. const int initialSize = buffer.getNumSamples() - bufferIndexStart;
  18816. readBufferSection (sectionToReadStart,
  18817. initialSize,
  18818. bufferIndexStart);
  18819. readBufferSection (sectionToReadStart + initialSize,
  18820. (sectionToReadEnd - sectionToReadStart) - initialSize,
  18821. 0);
  18822. }
  18823. const ScopedLock sl2 (bufferStartPosLock);
  18824. bufferValidStart = newBVS;
  18825. bufferValidEnd = newBVE;
  18826. return true;
  18827. }
  18828. else
  18829. {
  18830. return false;
  18831. }
  18832. }
  18833. void BufferingAudioSource::readBufferSection (int start, int length, int bufferOffset)
  18834. {
  18835. if (source->getNextReadPosition() != start)
  18836. source->setNextReadPosition (start);
  18837. AudioSourceChannelInfo info;
  18838. info.buffer = &buffer;
  18839. info.startSample = bufferOffset;
  18840. info.numSamples = length;
  18841. source->getNextAudioBlock (info);
  18842. }
  18843. END_JUCE_NAMESPACE
  18844. /*** End of inlined file: juce_BufferingAudioSource.cpp ***/
  18845. /*** Start of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18846. BEGIN_JUCE_NAMESPACE
  18847. ChannelRemappingAudioSource::ChannelRemappingAudioSource (AudioSource* const source_,
  18848. const bool deleteSourceWhenDeleted_)
  18849. : requiredNumberOfChannels (2),
  18850. source (source_),
  18851. deleteSourceWhenDeleted (deleteSourceWhenDeleted_),
  18852. buffer (2, 16)
  18853. {
  18854. remappedInfo.buffer = &buffer;
  18855. remappedInfo.startSample = 0;
  18856. }
  18857. ChannelRemappingAudioSource::~ChannelRemappingAudioSource()
  18858. {
  18859. if (deleteSourceWhenDeleted)
  18860. delete source;
  18861. }
  18862. void ChannelRemappingAudioSource::setNumberOfChannelsToProduce (const int requiredNumberOfChannels_) throw()
  18863. {
  18864. const ScopedLock sl (lock);
  18865. requiredNumberOfChannels = requiredNumberOfChannels_;
  18866. }
  18867. void ChannelRemappingAudioSource::clearAllMappings() throw()
  18868. {
  18869. const ScopedLock sl (lock);
  18870. remappedInputs.clear();
  18871. remappedOutputs.clear();
  18872. }
  18873. void ChannelRemappingAudioSource::setInputChannelMapping (const int destIndex, const int sourceIndex) throw()
  18874. {
  18875. const ScopedLock sl (lock);
  18876. while (remappedInputs.size() < destIndex)
  18877. remappedInputs.add (-1);
  18878. remappedInputs.set (destIndex, sourceIndex);
  18879. }
  18880. void ChannelRemappingAudioSource::setOutputChannelMapping (const int sourceIndex, const int destIndex) throw()
  18881. {
  18882. const ScopedLock sl (lock);
  18883. while (remappedOutputs.size() < sourceIndex)
  18884. remappedOutputs.add (-1);
  18885. remappedOutputs.set (sourceIndex, destIndex);
  18886. }
  18887. int ChannelRemappingAudioSource::getRemappedInputChannel (const int inputChannelIndex) const throw()
  18888. {
  18889. const ScopedLock sl (lock);
  18890. if (inputChannelIndex >= 0 && inputChannelIndex < remappedInputs.size())
  18891. return remappedInputs.getUnchecked (inputChannelIndex);
  18892. return -1;
  18893. }
  18894. int ChannelRemappingAudioSource::getRemappedOutputChannel (const int outputChannelIndex) const throw()
  18895. {
  18896. const ScopedLock sl (lock);
  18897. if (outputChannelIndex >= 0 && outputChannelIndex < remappedOutputs.size())
  18898. return remappedOutputs .getUnchecked (outputChannelIndex);
  18899. return -1;
  18900. }
  18901. void ChannelRemappingAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18902. {
  18903. source->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18904. }
  18905. void ChannelRemappingAudioSource::releaseResources()
  18906. {
  18907. source->releaseResources();
  18908. }
  18909. void ChannelRemappingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  18910. {
  18911. const ScopedLock sl (lock);
  18912. buffer.setSize (requiredNumberOfChannels, bufferToFill.numSamples, false, false, true);
  18913. const int numChans = bufferToFill.buffer->getNumChannels();
  18914. int i;
  18915. for (i = 0; i < buffer.getNumChannels(); ++i)
  18916. {
  18917. const int remappedChan = getRemappedInputChannel (i);
  18918. if (remappedChan >= 0 && remappedChan < numChans)
  18919. {
  18920. buffer.copyFrom (i, 0, *bufferToFill.buffer,
  18921. remappedChan,
  18922. bufferToFill.startSample,
  18923. bufferToFill.numSamples);
  18924. }
  18925. else
  18926. {
  18927. buffer.clear (i, 0, bufferToFill.numSamples);
  18928. }
  18929. }
  18930. remappedInfo.numSamples = bufferToFill.numSamples;
  18931. source->getNextAudioBlock (remappedInfo);
  18932. bufferToFill.clearActiveBufferRegion();
  18933. for (i = 0; i < requiredNumberOfChannels; ++i)
  18934. {
  18935. const int remappedChan = getRemappedOutputChannel (i);
  18936. if (remappedChan >= 0 && remappedChan < numChans)
  18937. {
  18938. bufferToFill.buffer->addFrom (remappedChan, bufferToFill.startSample,
  18939. buffer, i, 0, bufferToFill.numSamples);
  18940. }
  18941. }
  18942. }
  18943. XmlElement* ChannelRemappingAudioSource::createXml() const throw()
  18944. {
  18945. XmlElement* e = new XmlElement (T("MAPPINGS"));
  18946. String ins, outs;
  18947. int i;
  18948. const ScopedLock sl (lock);
  18949. for (i = 0; i < remappedInputs.size(); ++i)
  18950. ins << remappedInputs.getUnchecked(i) << T(' ');
  18951. for (i = 0; i < remappedOutputs.size(); ++i)
  18952. outs << remappedOutputs.getUnchecked(i) << T(' ');
  18953. e->setAttribute (T("inputs"), ins.trimEnd());
  18954. e->setAttribute (T("outputs"), outs.trimEnd());
  18955. return e;
  18956. }
  18957. void ChannelRemappingAudioSource::restoreFromXml (const XmlElement& e) throw()
  18958. {
  18959. if (e.hasTagName (T("MAPPINGS")))
  18960. {
  18961. const ScopedLock sl (lock);
  18962. clearAllMappings();
  18963. StringArray ins, outs;
  18964. ins.addTokens (e.getStringAttribute (T("inputs")), false);
  18965. outs.addTokens (e.getStringAttribute (T("outputs")), false);
  18966. int i;
  18967. for (i = 0; i < ins.size(); ++i)
  18968. remappedInputs.add (ins[i].getIntValue());
  18969. for (i = 0; i < outs.size(); ++i)
  18970. remappedOutputs.add (outs[i].getIntValue());
  18971. }
  18972. }
  18973. END_JUCE_NAMESPACE
  18974. /*** End of inlined file: juce_ChannelRemappingAudioSource.cpp ***/
  18975. /*** Start of inlined file: juce_IIRFilterAudioSource.cpp ***/
  18976. BEGIN_JUCE_NAMESPACE
  18977. IIRFilterAudioSource::IIRFilterAudioSource (AudioSource* const inputSource,
  18978. const bool deleteInputWhenDeleted_)
  18979. : input (inputSource),
  18980. deleteInputWhenDeleted (deleteInputWhenDeleted_)
  18981. {
  18982. jassert (inputSource != 0);
  18983. for (int i = 2; --i >= 0;)
  18984. iirFilters.add (new IIRFilter());
  18985. }
  18986. IIRFilterAudioSource::~IIRFilterAudioSource()
  18987. {
  18988. if (deleteInputWhenDeleted)
  18989. delete input;
  18990. }
  18991. void IIRFilterAudioSource::setFilterParameters (const IIRFilter& newSettings)
  18992. {
  18993. for (int i = iirFilters.size(); --i >= 0;)
  18994. iirFilters.getUnchecked(i)->copyCoefficientsFrom (newSettings);
  18995. }
  18996. void IIRFilterAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  18997. {
  18998. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  18999. for (int i = iirFilters.size(); --i >= 0;)
  19000. iirFilters.getUnchecked(i)->reset();
  19001. }
  19002. void IIRFilterAudioSource::releaseResources()
  19003. {
  19004. input->releaseResources();
  19005. }
  19006. void IIRFilterAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& bufferToFill)
  19007. {
  19008. input->getNextAudioBlock (bufferToFill);
  19009. const int numChannels = bufferToFill.buffer->getNumChannels();
  19010. while (numChannels > iirFilters.size())
  19011. iirFilters.add (new IIRFilter (*iirFilters.getUnchecked (0)));
  19012. for (int i = 0; i < numChannels; ++i)
  19013. iirFilters.getUnchecked(i)
  19014. ->processSamples (bufferToFill.buffer->getSampleData (i, bufferToFill.startSample),
  19015. bufferToFill.numSamples);
  19016. }
  19017. END_JUCE_NAMESPACE
  19018. /*** End of inlined file: juce_IIRFilterAudioSource.cpp ***/
  19019. /*** Start of inlined file: juce_MixerAudioSource.cpp ***/
  19020. BEGIN_JUCE_NAMESPACE
  19021. MixerAudioSource::MixerAudioSource()
  19022. : tempBuffer (2, 0),
  19023. currentSampleRate (0.0),
  19024. bufferSizeExpected (0)
  19025. {
  19026. }
  19027. MixerAudioSource::~MixerAudioSource()
  19028. {
  19029. removeAllInputs();
  19030. }
  19031. void MixerAudioSource::addInputSource (AudioSource* input, const bool deleteWhenRemoved)
  19032. {
  19033. if (input != 0 && ! inputs.contains (input))
  19034. {
  19035. double localRate;
  19036. int localBufferSize;
  19037. {
  19038. const ScopedLock sl (lock);
  19039. localRate = currentSampleRate;
  19040. localBufferSize = bufferSizeExpected;
  19041. }
  19042. if (localRate != 0.0)
  19043. input->prepareToPlay (localBufferSize, localRate);
  19044. const ScopedLock sl (lock);
  19045. inputsToDelete.setBit (inputs.size(), deleteWhenRemoved);
  19046. inputs.add (input);
  19047. }
  19048. }
  19049. void MixerAudioSource::removeInputSource (AudioSource* input, const bool deleteInput)
  19050. {
  19051. if (input != 0)
  19052. {
  19053. int index;
  19054. {
  19055. const ScopedLock sl (lock);
  19056. index = inputs.indexOf ((void*) input);
  19057. if (index >= 0)
  19058. {
  19059. inputsToDelete.shiftBits (index, 1);
  19060. inputs.remove (index);
  19061. }
  19062. }
  19063. if (index >= 0)
  19064. {
  19065. input->releaseResources();
  19066. if (deleteInput)
  19067. delete input;
  19068. }
  19069. }
  19070. }
  19071. void MixerAudioSource::removeAllInputs()
  19072. {
  19073. VoidArray inputsCopy;
  19074. BitArray inputsToDeleteCopy;
  19075. {
  19076. const ScopedLock sl (lock);
  19077. inputsCopy = inputs;
  19078. inputsToDeleteCopy = inputsToDelete;
  19079. }
  19080. for (int i = inputsCopy.size(); --i >= 0;)
  19081. if (inputsToDeleteCopy[i])
  19082. delete (AudioSource*) inputsCopy[i];
  19083. }
  19084. void MixerAudioSource::prepareToPlay (int samplesPerBlockExpected, double sampleRate)
  19085. {
  19086. tempBuffer.setSize (2, samplesPerBlockExpected);
  19087. const ScopedLock sl (lock);
  19088. currentSampleRate = sampleRate;
  19089. bufferSizeExpected = samplesPerBlockExpected;
  19090. for (int i = inputs.size(); --i >= 0;)
  19091. ((AudioSource*) inputs.getUnchecked(i))->prepareToPlay (samplesPerBlockExpected,
  19092. sampleRate);
  19093. }
  19094. void MixerAudioSource::releaseResources()
  19095. {
  19096. const ScopedLock sl (lock);
  19097. for (int i = inputs.size(); --i >= 0;)
  19098. ((AudioSource*) inputs.getUnchecked(i))->releaseResources();
  19099. tempBuffer.setSize (2, 0);
  19100. currentSampleRate = 0;
  19101. bufferSizeExpected = 0;
  19102. }
  19103. void MixerAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19104. {
  19105. const ScopedLock sl (lock);
  19106. if (inputs.size() > 0)
  19107. {
  19108. ((AudioSource*) inputs.getUnchecked(0))->getNextAudioBlock (info);
  19109. if (inputs.size() > 1)
  19110. {
  19111. tempBuffer.setSize (jmax (1, info.buffer->getNumChannels()),
  19112. info.buffer->getNumSamples());
  19113. AudioSourceChannelInfo info2;
  19114. info2.buffer = &tempBuffer;
  19115. info2.numSamples = info.numSamples;
  19116. info2.startSample = 0;
  19117. for (int i = 1; i < inputs.size(); ++i)
  19118. {
  19119. ((AudioSource*) inputs.getUnchecked(i))->getNextAudioBlock (info2);
  19120. for (int chan = 0; chan < info.buffer->getNumChannels(); ++chan)
  19121. info.buffer->addFrom (chan, info.startSample, tempBuffer, chan, 0, info.numSamples);
  19122. }
  19123. }
  19124. }
  19125. else
  19126. {
  19127. info.clearActiveBufferRegion();
  19128. }
  19129. }
  19130. END_JUCE_NAMESPACE
  19131. /*** End of inlined file: juce_MixerAudioSource.cpp ***/
  19132. /*** Start of inlined file: juce_ResamplingAudioSource.cpp ***/
  19133. BEGIN_JUCE_NAMESPACE
  19134. ResamplingAudioSource::ResamplingAudioSource (AudioSource* const inputSource,
  19135. const bool deleteInputWhenDeleted_)
  19136. : input (inputSource),
  19137. deleteInputWhenDeleted (deleteInputWhenDeleted_),
  19138. ratio (1.0),
  19139. lastRatio (1.0),
  19140. buffer (2, 0),
  19141. sampsInBuffer (0)
  19142. {
  19143. jassert (input != 0);
  19144. }
  19145. ResamplingAudioSource::~ResamplingAudioSource()
  19146. {
  19147. if (deleteInputWhenDeleted)
  19148. delete input;
  19149. }
  19150. void ResamplingAudioSource::setResamplingRatio (const double samplesInPerOutputSample)
  19151. {
  19152. jassert (samplesInPerOutputSample > 0);
  19153. const ScopedLock sl (ratioLock);
  19154. ratio = jmax (0.0, samplesInPerOutputSample);
  19155. }
  19156. void ResamplingAudioSource::prepareToPlay (int samplesPerBlockExpected,
  19157. double sampleRate)
  19158. {
  19159. const ScopedLock sl (ratioLock);
  19160. input->prepareToPlay (samplesPerBlockExpected, sampleRate);
  19161. buffer.setSize (2, roundToInt (samplesPerBlockExpected * ratio) + 32);
  19162. buffer.clear();
  19163. sampsInBuffer = 0;
  19164. bufferPos = 0;
  19165. subSampleOffset = 0.0;
  19166. createLowPass (ratio);
  19167. resetFilters();
  19168. }
  19169. void ResamplingAudioSource::releaseResources()
  19170. {
  19171. input->releaseResources();
  19172. buffer.setSize (2, 0);
  19173. }
  19174. void ResamplingAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19175. {
  19176. const ScopedLock sl (ratioLock);
  19177. if (lastRatio != ratio)
  19178. {
  19179. createLowPass (ratio);
  19180. lastRatio = ratio;
  19181. }
  19182. const int sampsNeeded = roundToInt (info.numSamples * ratio) + 2;
  19183. int bufferSize = buffer.getNumSamples();
  19184. if (bufferSize < sampsNeeded + 8)
  19185. {
  19186. bufferPos %= bufferSize;
  19187. bufferSize = sampsNeeded + 32;
  19188. buffer.setSize (buffer.getNumChannels(), bufferSize, true, true);
  19189. }
  19190. bufferPos %= bufferSize;
  19191. int endOfBufferPos = bufferPos + sampsInBuffer;
  19192. while (sampsNeeded > sampsInBuffer)
  19193. {
  19194. endOfBufferPos %= bufferSize;
  19195. int numToDo = jmin (sampsNeeded - sampsInBuffer,
  19196. bufferSize - endOfBufferPos);
  19197. AudioSourceChannelInfo readInfo;
  19198. readInfo.buffer = &buffer;
  19199. readInfo.numSamples = numToDo;
  19200. readInfo.startSample = endOfBufferPos;
  19201. input->getNextAudioBlock (readInfo);
  19202. if (ratio > 1.0001)
  19203. {
  19204. // for down-sampling, pre-apply the filter..
  19205. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19206. applyFilter (buffer.getSampleData (i, endOfBufferPos), numToDo, filterStates[i]);
  19207. }
  19208. sampsInBuffer += numToDo;
  19209. endOfBufferPos += numToDo;
  19210. }
  19211. float* dl = info.buffer->getSampleData (0, info.startSample);
  19212. float* dr = (info.buffer->getNumChannels() > 1) ? info.buffer->getSampleData (1, info.startSample) : 0;
  19213. const float* const bl = buffer.getSampleData (0, 0);
  19214. const float* const br = buffer.getSampleData (1, 0);
  19215. int nextPos = (bufferPos + 1) % bufferSize;
  19216. for (int m = info.numSamples; --m >= 0;)
  19217. {
  19218. const float alpha = (float) subSampleOffset;
  19219. const float invAlpha = 1.0f - alpha;
  19220. *dl++ = bl [bufferPos] * invAlpha + bl [nextPos] * alpha;
  19221. if (dr != 0)
  19222. *dr++ = br [bufferPos] * invAlpha + br [nextPos] * alpha;
  19223. subSampleOffset += ratio;
  19224. jassert (sampsInBuffer > 0);
  19225. while (subSampleOffset >= 1.0)
  19226. {
  19227. if (++bufferPos >= bufferSize)
  19228. bufferPos = 0;
  19229. --sampsInBuffer;
  19230. nextPos = (bufferPos + 1) % bufferSize;
  19231. subSampleOffset -= 1.0;
  19232. }
  19233. }
  19234. if (ratio < 0.9999)
  19235. {
  19236. // for up-sampling, apply the filter after transposing..
  19237. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19238. applyFilter (info.buffer->getSampleData (i, info.startSample), info.numSamples, filterStates[i]);
  19239. }
  19240. else if (ratio <= 1.0001)
  19241. {
  19242. // if the filter's not currently being applied, keep it stoked with the last couple of samples to avoid discontinuities
  19243. for (int i = jmin (2, info.buffer->getNumChannels()); --i >= 0;)
  19244. {
  19245. const float* const endOfBuffer = info.buffer->getSampleData (i, info.startSample + info.numSamples - 1);
  19246. FilterState& fs = filterStates[i];
  19247. if (info.numSamples > 1)
  19248. {
  19249. fs.y2 = fs.x2 = *(endOfBuffer - 1);
  19250. }
  19251. else
  19252. {
  19253. fs.y2 = fs.y1;
  19254. fs.x2 = fs.x1;
  19255. }
  19256. fs.y1 = fs.x1 = *endOfBuffer;
  19257. }
  19258. }
  19259. jassert (sampsInBuffer >= 0);
  19260. }
  19261. void ResamplingAudioSource::createLowPass (const double frequencyRatio)
  19262. {
  19263. const double proportionalRate = (frequencyRatio > 1.0) ? 0.5 / frequencyRatio
  19264. : 0.5 * frequencyRatio;
  19265. const double n = 1.0 / tan (double_Pi * jmax (0.001, proportionalRate));
  19266. const double nSquared = n * n;
  19267. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  19268. setFilterCoefficients (c1,
  19269. c1 * 2.0f,
  19270. c1,
  19271. 1.0,
  19272. c1 * 2.0 * (1.0 - nSquared),
  19273. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  19274. }
  19275. void ResamplingAudioSource::setFilterCoefficients (double c1, double c2, double c3, double c4, double c5, double c6)
  19276. {
  19277. const double a = 1.0 / c4;
  19278. c1 *= a;
  19279. c2 *= a;
  19280. c3 *= a;
  19281. c5 *= a;
  19282. c6 *= a;
  19283. coefficients[0] = c1;
  19284. coefficients[1] = c2;
  19285. coefficients[2] = c3;
  19286. coefficients[3] = c4;
  19287. coefficients[4] = c5;
  19288. coefficients[5] = c6;
  19289. }
  19290. void ResamplingAudioSource::resetFilters()
  19291. {
  19292. zeromem (filterStates, sizeof (filterStates));
  19293. }
  19294. void ResamplingAudioSource::applyFilter (float* samples, int num, FilterState& fs)
  19295. {
  19296. while (--num >= 0)
  19297. {
  19298. const double in = *samples;
  19299. double out = coefficients[0] * in
  19300. + coefficients[1] * fs.x1
  19301. + coefficients[2] * fs.x2
  19302. - coefficients[4] * fs.y1
  19303. - coefficients[5] * fs.y2;
  19304. #if JUCE_INTEL
  19305. if (! (out < -1.0e-8 || out > 1.0e-8))
  19306. out = 0;
  19307. #endif
  19308. fs.x2 = fs.x1;
  19309. fs.x1 = in;
  19310. fs.y2 = fs.y1;
  19311. fs.y1 = out;
  19312. *samples++ = (float) out;
  19313. }
  19314. }
  19315. END_JUCE_NAMESPACE
  19316. /*** End of inlined file: juce_ResamplingAudioSource.cpp ***/
  19317. /*** Start of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19318. BEGIN_JUCE_NAMESPACE
  19319. ToneGeneratorAudioSource::ToneGeneratorAudioSource()
  19320. : frequency (1000.0),
  19321. sampleRate (44100.0),
  19322. currentPhase (0.0),
  19323. phasePerSample (0.0),
  19324. amplitude (0.5f)
  19325. {
  19326. }
  19327. ToneGeneratorAudioSource::~ToneGeneratorAudioSource()
  19328. {
  19329. }
  19330. void ToneGeneratorAudioSource::setAmplitude (const float newAmplitude)
  19331. {
  19332. amplitude = newAmplitude;
  19333. }
  19334. void ToneGeneratorAudioSource::setFrequency (const double newFrequencyHz)
  19335. {
  19336. frequency = newFrequencyHz;
  19337. phasePerSample = 0.0;
  19338. }
  19339. void ToneGeneratorAudioSource::prepareToPlay (int /*samplesPerBlockExpected*/,
  19340. double sampleRate_)
  19341. {
  19342. currentPhase = 0.0;
  19343. phasePerSample = 0.0;
  19344. sampleRate = sampleRate_;
  19345. }
  19346. void ToneGeneratorAudioSource::releaseResources()
  19347. {
  19348. }
  19349. void ToneGeneratorAudioSource::getNextAudioBlock (const AudioSourceChannelInfo& info)
  19350. {
  19351. if (phasePerSample == 0.0)
  19352. phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  19353. for (int i = 0; i < info.numSamples; ++i)
  19354. {
  19355. const float sample = amplitude * (float) sin (currentPhase);
  19356. currentPhase += phasePerSample;
  19357. for (int j = info.buffer->getNumChannels(); --j >= 0;)
  19358. *info.buffer->getSampleData (j, info.startSample + i) = sample;
  19359. }
  19360. }
  19361. END_JUCE_NAMESPACE
  19362. /*** End of inlined file: juce_ToneGeneratorAudioSource.cpp ***/
  19363. /*** Start of inlined file: juce_AudioDeviceManager.cpp ***/
  19364. BEGIN_JUCE_NAMESPACE
  19365. AudioDeviceManager::AudioDeviceSetup::AudioDeviceSetup()
  19366. : sampleRate (0),
  19367. bufferSize (0),
  19368. useDefaultInputChannels (true),
  19369. useDefaultOutputChannels (true)
  19370. {
  19371. }
  19372. bool AudioDeviceManager::AudioDeviceSetup::operator== (const AudioDeviceManager::AudioDeviceSetup& other) const
  19373. {
  19374. return outputDeviceName == other.outputDeviceName
  19375. && inputDeviceName == other.inputDeviceName
  19376. && sampleRate == other.sampleRate
  19377. && bufferSize == other.bufferSize
  19378. && inputChannels == other.inputChannels
  19379. && useDefaultInputChannels == other.useDefaultInputChannels
  19380. && outputChannels == other.outputChannels
  19381. && useDefaultOutputChannels == other.useDefaultOutputChannels;
  19382. }
  19383. AudioDeviceManager::AudioDeviceManager()
  19384. : currentAudioDevice (0),
  19385. numInputChansNeeded (0),
  19386. numOutputChansNeeded (2),
  19387. listNeedsScanning (true),
  19388. useInputNames (false),
  19389. inputLevelMeasurementEnabledCount (0),
  19390. inputLevel (0),
  19391. tempBuffer (2, 2),
  19392. defaultMidiOutput (0),
  19393. cpuUsageMs (0),
  19394. timeToCpuScale (0)
  19395. {
  19396. callbackHandler.owner = this;
  19397. }
  19398. AudioDeviceManager::~AudioDeviceManager()
  19399. {
  19400. currentAudioDevice = 0;
  19401. defaultMidiOutput = 0;
  19402. }
  19403. void AudioDeviceManager::createDeviceTypesIfNeeded()
  19404. {
  19405. if (availableDeviceTypes.size() == 0)
  19406. {
  19407. createAudioDeviceTypes (availableDeviceTypes);
  19408. while (lastDeviceTypeConfigs.size() < availableDeviceTypes.size())
  19409. lastDeviceTypeConfigs.add (new AudioDeviceSetup());
  19410. if (availableDeviceTypes.size() > 0)
  19411. currentDeviceType = availableDeviceTypes.getUnchecked(0)->getTypeName();
  19412. }
  19413. }
  19414. const OwnedArray <AudioIODeviceType>& AudioDeviceManager::getAvailableDeviceTypes()
  19415. {
  19416. scanDevicesIfNeeded();
  19417. return availableDeviceTypes;
  19418. }
  19419. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio();
  19420. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio();
  19421. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI();
  19422. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound();
  19423. AudioIODeviceType* juce_createAudioIODeviceType_ASIO();
  19424. AudioIODeviceType* juce_createAudioIODeviceType_ALSA();
  19425. AudioIODeviceType* juce_createAudioIODeviceType_JACK();
  19426. void AudioDeviceManager::createAudioDeviceTypes (OwnedArray <AudioIODeviceType>& list)
  19427. {
  19428. #if JUCE_WINDOWS
  19429. #if JUCE_WASAPI
  19430. if (SystemStats::getOperatingSystemType() >= SystemStats::WinVista)
  19431. list.add (juce_createAudioIODeviceType_WASAPI());
  19432. #endif
  19433. #if JUCE_DIRECTSOUND
  19434. list.add (juce_createAudioIODeviceType_DirectSound());
  19435. #endif
  19436. #if JUCE_ASIO
  19437. list.add (juce_createAudioIODeviceType_ASIO());
  19438. #endif
  19439. #endif
  19440. #if JUCE_MAC
  19441. list.add (juce_createAudioIODeviceType_CoreAudio());
  19442. #endif
  19443. #if JUCE_IPHONE
  19444. list.add (juce_createAudioIODeviceType_iPhoneAudio());
  19445. #endif
  19446. #if JUCE_LINUX && JUCE_ALSA
  19447. list.add (juce_createAudioIODeviceType_ALSA());
  19448. #endif
  19449. #if JUCE_LINUX && JUCE_JACK
  19450. list.add (juce_createAudioIODeviceType_JACK());
  19451. #endif
  19452. }
  19453. const String AudioDeviceManager::initialise (const int numInputChannelsNeeded,
  19454. const int numOutputChannelsNeeded,
  19455. const XmlElement* const e,
  19456. const bool selectDefaultDeviceOnFailure,
  19457. const String& preferredDefaultDeviceName,
  19458. const AudioDeviceSetup* preferredSetupOptions)
  19459. {
  19460. scanDevicesIfNeeded();
  19461. numInputChansNeeded = numInputChannelsNeeded;
  19462. numOutputChansNeeded = numOutputChannelsNeeded;
  19463. if (e != 0 && e->hasTagName (T("DEVICESETUP")))
  19464. {
  19465. lastExplicitSettings = new XmlElement (*e);
  19466. String error;
  19467. AudioDeviceSetup setup;
  19468. if (preferredSetupOptions != 0)
  19469. setup = *preferredSetupOptions;
  19470. if (e->getStringAttribute (T("audioDeviceName")).isNotEmpty())
  19471. {
  19472. setup.inputDeviceName = setup.outputDeviceName
  19473. = e->getStringAttribute (T("audioDeviceName"));
  19474. }
  19475. else
  19476. {
  19477. setup.inputDeviceName = e->getStringAttribute (T("audioInputDeviceName"));
  19478. setup.outputDeviceName = e->getStringAttribute (T("audioOutputDeviceName"));
  19479. }
  19480. currentDeviceType = e->getStringAttribute (T("deviceType"));
  19481. if (currentDeviceType.isEmpty())
  19482. {
  19483. AudioIODeviceType* const type = findType (setup.inputDeviceName, setup.outputDeviceName);
  19484. if (type != 0)
  19485. currentDeviceType = type->getTypeName();
  19486. else if (availableDeviceTypes.size() > 0)
  19487. currentDeviceType = availableDeviceTypes[0]->getTypeName();
  19488. }
  19489. setup.bufferSize = e->getIntAttribute (T("audioDeviceBufferSize"));
  19490. setup.sampleRate = e->getDoubleAttribute (T("audioDeviceRate"));
  19491. setup.inputChannels.parseString (e->getStringAttribute (T("audioDeviceInChans"), T("11")), 2);
  19492. setup.outputChannels.parseString (e->getStringAttribute (T("audioDeviceOutChans"), T("11")), 2);
  19493. setup.useDefaultInputChannels = ! e->hasAttribute (T("audioDeviceInChans"));
  19494. setup.useDefaultOutputChannels = ! e->hasAttribute (T("audioDeviceOutChans"));
  19495. error = setAudioDeviceSetup (setup, true);
  19496. midiInsFromXml.clear();
  19497. forEachXmlChildElementWithTagName (*e, c, T("MIDIINPUT"))
  19498. midiInsFromXml.add (c->getStringAttribute (T("name")));
  19499. const StringArray allMidiIns (MidiInput::getDevices());
  19500. for (int i = allMidiIns.size(); --i >= 0;)
  19501. setMidiInputEnabled (allMidiIns[i], midiInsFromXml.contains (allMidiIns[i]));
  19502. if (error.isNotEmpty() && selectDefaultDeviceOnFailure)
  19503. error = initialise (numInputChannelsNeeded, numOutputChannelsNeeded, 0,
  19504. false, preferredDefaultDeviceName);
  19505. setDefaultMidiOutput (e->getStringAttribute (T("defaultMidiOutput")));
  19506. return error;
  19507. }
  19508. else
  19509. {
  19510. AudioDeviceSetup setup;
  19511. if (preferredSetupOptions != 0)
  19512. {
  19513. setup = *preferredSetupOptions;
  19514. }
  19515. else if (preferredDefaultDeviceName.isNotEmpty())
  19516. {
  19517. for (int j = availableDeviceTypes.size(); --j >= 0;)
  19518. {
  19519. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(j);
  19520. StringArray outs (type->getDeviceNames (false));
  19521. int i;
  19522. for (i = 0; i < outs.size(); ++i)
  19523. {
  19524. if (outs[i].matchesWildcard (preferredDefaultDeviceName, true))
  19525. {
  19526. setup.outputDeviceName = outs[i];
  19527. break;
  19528. }
  19529. }
  19530. StringArray ins (type->getDeviceNames (true));
  19531. for (i = 0; i < ins.size(); ++i)
  19532. {
  19533. if (ins[i].matchesWildcard (preferredDefaultDeviceName, true))
  19534. {
  19535. setup.inputDeviceName = ins[i];
  19536. break;
  19537. }
  19538. }
  19539. }
  19540. }
  19541. insertDefaultDeviceNames (setup);
  19542. return setAudioDeviceSetup (setup, false);
  19543. }
  19544. }
  19545. void AudioDeviceManager::insertDefaultDeviceNames (AudioDeviceSetup& setup) const
  19546. {
  19547. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19548. if (type != 0)
  19549. {
  19550. if (setup.outputDeviceName.isEmpty())
  19551. setup.outputDeviceName = type->getDeviceNames (false) [type->getDefaultDeviceIndex (false)];
  19552. if (setup.inputDeviceName.isEmpty())
  19553. setup.inputDeviceName = type->getDeviceNames (true) [type->getDefaultDeviceIndex (true)];
  19554. }
  19555. }
  19556. XmlElement* AudioDeviceManager::createStateXml() const
  19557. {
  19558. return lastExplicitSettings != 0 ? new XmlElement (*lastExplicitSettings) : 0;
  19559. }
  19560. void AudioDeviceManager::scanDevicesIfNeeded()
  19561. {
  19562. if (listNeedsScanning)
  19563. {
  19564. listNeedsScanning = false;
  19565. createDeviceTypesIfNeeded();
  19566. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19567. availableDeviceTypes.getUnchecked(i)->scanForDevices();
  19568. }
  19569. }
  19570. AudioIODeviceType* AudioDeviceManager::findType (const String& inputName, const String& outputName)
  19571. {
  19572. scanDevicesIfNeeded();
  19573. for (int i = availableDeviceTypes.size(); --i >= 0;)
  19574. {
  19575. AudioIODeviceType* const type = availableDeviceTypes.getUnchecked(i);
  19576. if ((inputName.isNotEmpty() && type->getDeviceNames (true).contains (inputName, true))
  19577. || (outputName.isNotEmpty() && type->getDeviceNames (false).contains (outputName, true)))
  19578. {
  19579. return type;
  19580. }
  19581. }
  19582. return 0;
  19583. }
  19584. void AudioDeviceManager::getAudioDeviceSetup (AudioDeviceSetup& setup)
  19585. {
  19586. setup = currentSetup;
  19587. }
  19588. void AudioDeviceManager::deleteCurrentDevice()
  19589. {
  19590. currentAudioDevice = 0;
  19591. currentSetup.inputDeviceName = String::empty;
  19592. currentSetup.outputDeviceName = String::empty;
  19593. }
  19594. void AudioDeviceManager::setCurrentAudioDeviceType (const String& type,
  19595. const bool treatAsChosenDevice)
  19596. {
  19597. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19598. {
  19599. if (availableDeviceTypes.getUnchecked(i)->getTypeName() == type
  19600. && currentDeviceType != type)
  19601. {
  19602. currentDeviceType = type;
  19603. AudioDeviceSetup s (*lastDeviceTypeConfigs.getUnchecked(i));
  19604. insertDefaultDeviceNames (s);
  19605. setAudioDeviceSetup (s, treatAsChosenDevice);
  19606. sendChangeMessage (this);
  19607. break;
  19608. }
  19609. }
  19610. }
  19611. AudioIODeviceType* AudioDeviceManager::getCurrentDeviceTypeObject() const
  19612. {
  19613. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19614. if (availableDeviceTypes[i]->getTypeName() == currentDeviceType)
  19615. return availableDeviceTypes[i];
  19616. return availableDeviceTypes[0];
  19617. }
  19618. const String AudioDeviceManager::setAudioDeviceSetup (const AudioDeviceSetup& newSetup,
  19619. const bool treatAsChosenDevice)
  19620. {
  19621. jassert (&newSetup != &currentSetup); // this will have no effect
  19622. if (newSetup == currentSetup && currentAudioDevice != 0)
  19623. return String::empty;
  19624. if (! (newSetup == currentSetup))
  19625. sendChangeMessage (this);
  19626. stopDevice();
  19627. const String newInputDeviceName (numInputChansNeeded == 0 ? String::empty : newSetup.inputDeviceName);
  19628. const String newOutputDeviceName (numOutputChansNeeded == 0 ? String::empty : newSetup.outputDeviceName);
  19629. String error;
  19630. AudioIODeviceType* type = getCurrentDeviceTypeObject();
  19631. if (type == 0 || (newInputDeviceName.isEmpty() && newOutputDeviceName.isEmpty()))
  19632. {
  19633. deleteCurrentDevice();
  19634. if (treatAsChosenDevice)
  19635. updateXml();
  19636. return String::empty;
  19637. }
  19638. if (currentSetup.inputDeviceName != newInputDeviceName
  19639. || currentSetup.outputDeviceName != newOutputDeviceName
  19640. || currentAudioDevice == 0)
  19641. {
  19642. deleteCurrentDevice();
  19643. scanDevicesIfNeeded();
  19644. if (newOutputDeviceName.isNotEmpty()
  19645. && ! type->getDeviceNames (false).contains (newOutputDeviceName))
  19646. {
  19647. return "No such device: " + newOutputDeviceName;
  19648. }
  19649. if (newInputDeviceName.isNotEmpty()
  19650. && ! type->getDeviceNames (true).contains (newInputDeviceName))
  19651. {
  19652. return "No such device: " + newInputDeviceName;
  19653. }
  19654. currentAudioDevice = type->createDevice (newOutputDeviceName, newInputDeviceName);
  19655. if (currentAudioDevice == 0)
  19656. 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!";
  19657. else
  19658. error = currentAudioDevice->getLastError();
  19659. if (error.isNotEmpty())
  19660. {
  19661. deleteCurrentDevice();
  19662. return error;
  19663. }
  19664. if (newSetup.useDefaultInputChannels)
  19665. {
  19666. inputChannels.clear();
  19667. inputChannels.setRange (0, numInputChansNeeded, true);
  19668. }
  19669. if (newSetup.useDefaultOutputChannels)
  19670. {
  19671. outputChannels.clear();
  19672. outputChannels.setRange (0, numOutputChansNeeded, true);
  19673. }
  19674. if (newInputDeviceName.isEmpty())
  19675. inputChannels.clear();
  19676. if (newOutputDeviceName.isEmpty())
  19677. outputChannels.clear();
  19678. }
  19679. if (! newSetup.useDefaultInputChannels)
  19680. inputChannels = newSetup.inputChannels;
  19681. if (! newSetup.useDefaultOutputChannels)
  19682. outputChannels = newSetup.outputChannels;
  19683. currentSetup = newSetup;
  19684. currentSetup.sampleRate = chooseBestSampleRate (newSetup.sampleRate);
  19685. error = currentAudioDevice->open (inputChannels,
  19686. outputChannels,
  19687. currentSetup.sampleRate,
  19688. currentSetup.bufferSize);
  19689. if (error.isEmpty())
  19690. {
  19691. currentDeviceType = currentAudioDevice->getTypeName();
  19692. currentAudioDevice->start (&callbackHandler);
  19693. currentSetup.sampleRate = currentAudioDevice->getCurrentSampleRate();
  19694. currentSetup.bufferSize = currentAudioDevice->getCurrentBufferSizeSamples();
  19695. currentSetup.inputChannels = currentAudioDevice->getActiveInputChannels();
  19696. currentSetup.outputChannels = currentAudioDevice->getActiveOutputChannels();
  19697. for (int i = 0; i < availableDeviceTypes.size(); ++i)
  19698. if (availableDeviceTypes.getUnchecked (i)->getTypeName() == currentDeviceType)
  19699. *(lastDeviceTypeConfigs.getUnchecked (i)) = currentSetup;
  19700. if (treatAsChosenDevice)
  19701. updateXml();
  19702. }
  19703. else
  19704. {
  19705. deleteCurrentDevice();
  19706. }
  19707. return error;
  19708. }
  19709. double AudioDeviceManager::chooseBestSampleRate (double rate) const
  19710. {
  19711. jassert (currentAudioDevice != 0);
  19712. if (rate > 0)
  19713. {
  19714. bool ok = false;
  19715. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19716. {
  19717. const double sr = currentAudioDevice->getSampleRate (i);
  19718. if (sr == rate)
  19719. ok = true;
  19720. }
  19721. if (! ok)
  19722. rate = 0;
  19723. }
  19724. if (rate == 0)
  19725. {
  19726. double lowestAbove44 = 0.0;
  19727. for (int i = currentAudioDevice->getNumSampleRates(); --i >= 0;)
  19728. {
  19729. const double sr = currentAudioDevice->getSampleRate (i);
  19730. if (sr >= 44100.0 && (lowestAbove44 == 0 || sr < lowestAbove44))
  19731. lowestAbove44 = sr;
  19732. }
  19733. if (lowestAbove44 == 0.0)
  19734. rate = currentAudioDevice->getSampleRate (0);
  19735. else
  19736. rate = lowestAbove44;
  19737. }
  19738. return rate;
  19739. }
  19740. void AudioDeviceManager::stopDevice()
  19741. {
  19742. if (currentAudioDevice != 0)
  19743. currentAudioDevice->stop();
  19744. testSound = 0;
  19745. }
  19746. void AudioDeviceManager::closeAudioDevice()
  19747. {
  19748. stopDevice();
  19749. currentAudioDevice = 0;
  19750. }
  19751. void AudioDeviceManager::restartLastAudioDevice()
  19752. {
  19753. if (currentAudioDevice == 0)
  19754. {
  19755. if (currentSetup.inputDeviceName.isEmpty()
  19756. && currentSetup.outputDeviceName.isEmpty())
  19757. {
  19758. // This method will only reload the last device that was running
  19759. // before closeAudioDevice() was called - you need to actually open
  19760. // one first, with setAudioDevice().
  19761. jassertfalse
  19762. return;
  19763. }
  19764. AudioDeviceSetup s (currentSetup);
  19765. setAudioDeviceSetup (s, false);
  19766. }
  19767. }
  19768. void AudioDeviceManager::updateXml()
  19769. {
  19770. lastExplicitSettings = new XmlElement ("DEVICESETUP");
  19771. lastExplicitSettings->setAttribute ("deviceType", currentDeviceType);
  19772. lastExplicitSettings->setAttribute ("audioOutputDeviceName", currentSetup.outputDeviceName);
  19773. lastExplicitSettings->setAttribute ("audioInputDeviceName", currentSetup.inputDeviceName);
  19774. if (currentAudioDevice != 0)
  19775. {
  19776. lastExplicitSettings->setAttribute ("audioDeviceRate", currentAudioDevice->getCurrentSampleRate());
  19777. if (currentAudioDevice->getDefaultBufferSize() != currentAudioDevice->getCurrentBufferSizeSamples())
  19778. lastExplicitSettings->setAttribute ("audioDeviceBufferSize", currentAudioDevice->getCurrentBufferSizeSamples());
  19779. if (! currentSetup.useDefaultInputChannels)
  19780. lastExplicitSettings->setAttribute ("audioDeviceInChans", currentSetup.inputChannels.toString (2));
  19781. if (! currentSetup.useDefaultOutputChannels)
  19782. lastExplicitSettings->setAttribute ("audioDeviceOutChans", currentSetup.outputChannels.toString (2));
  19783. }
  19784. for (int i = 0; i < enabledMidiInputs.size(); ++i)
  19785. {
  19786. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19787. m->setAttribute ("name", enabledMidiInputs[i]->getName());
  19788. }
  19789. if (midiInsFromXml.size() > 0)
  19790. {
  19791. // Add any midi devices that have been enabled before, but which aren't currently
  19792. // open because the device has been disconnected.
  19793. const StringArray availableMidiDevices (MidiInput::getDevices());
  19794. for (int i = 0; i < midiInsFromXml.size(); ++i)
  19795. {
  19796. if (! availableMidiDevices.contains (midiInsFromXml[i], true))
  19797. {
  19798. XmlElement* const m = lastExplicitSettings->createNewChildElement ("MIDIINPUT");
  19799. m->setAttribute ("name", midiInsFromXml[i]);
  19800. }
  19801. }
  19802. }
  19803. if (defaultMidiOutputName.isNotEmpty())
  19804. lastExplicitSettings->setAttribute ("defaultMidiOutput", defaultMidiOutputName);
  19805. }
  19806. void AudioDeviceManager::addAudioCallback (AudioIODeviceCallback* newCallback)
  19807. {
  19808. {
  19809. const ScopedLock sl (audioCallbackLock);
  19810. if (callbacks.contains (newCallback))
  19811. return;
  19812. }
  19813. if (currentAudioDevice != 0 && newCallback != 0)
  19814. newCallback->audioDeviceAboutToStart (currentAudioDevice);
  19815. const ScopedLock sl (audioCallbackLock);
  19816. callbacks.add (newCallback);
  19817. }
  19818. void AudioDeviceManager::removeAudioCallback (AudioIODeviceCallback* callback)
  19819. {
  19820. if (callback != 0)
  19821. {
  19822. bool needsDeinitialising = currentAudioDevice != 0;
  19823. {
  19824. const ScopedLock sl (audioCallbackLock);
  19825. needsDeinitialising = needsDeinitialising && callbacks.contains (callback);
  19826. callbacks.removeValue (callback);
  19827. }
  19828. if (needsDeinitialising)
  19829. callback->audioDeviceStopped();
  19830. }
  19831. }
  19832. void AudioDeviceManager::audioDeviceIOCallbackInt (const float** inputChannelData,
  19833. int numInputChannels,
  19834. float** outputChannelData,
  19835. int numOutputChannels,
  19836. int numSamples)
  19837. {
  19838. const ScopedLock sl (audioCallbackLock);
  19839. if (inputLevelMeasurementEnabledCount > 0)
  19840. {
  19841. for (int j = 0; j < numSamples; ++j)
  19842. {
  19843. float s = 0;
  19844. for (int i = 0; i < numInputChannels; ++i)
  19845. s += fabsf (inputChannelData[i][j]);
  19846. s /= numInputChannels;
  19847. const double decayFactor = 0.99992;
  19848. if (s > inputLevel)
  19849. inputLevel = s;
  19850. else if (inputLevel > 0.001f)
  19851. inputLevel *= decayFactor;
  19852. else
  19853. inputLevel = 0;
  19854. }
  19855. }
  19856. if (callbacks.size() > 0)
  19857. {
  19858. const double callbackStartTime = Time::getMillisecondCounterHiRes();
  19859. tempBuffer.setSize (jmax (1, numOutputChannels), jmax (1, numSamples), false, false, true);
  19860. callbacks.getUnchecked(0)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19861. outputChannelData, numOutputChannels, numSamples);
  19862. float** const tempChans = tempBuffer.getArrayOfChannels();
  19863. for (int i = callbacks.size(); --i > 0;)
  19864. {
  19865. callbacks.getUnchecked(i)->audioDeviceIOCallback (inputChannelData, numInputChannels,
  19866. tempChans, numOutputChannels, numSamples);
  19867. for (int chan = 0; chan < numOutputChannels; ++chan)
  19868. {
  19869. const float* const src = tempChans [chan];
  19870. float* const dst = outputChannelData [chan];
  19871. if (src != 0 && dst != 0)
  19872. for (int j = 0; j < numSamples; ++j)
  19873. dst[j] += src[j];
  19874. }
  19875. }
  19876. const double msTaken = Time::getMillisecondCounterHiRes() - callbackStartTime;
  19877. const double filterAmount = 0.2;
  19878. cpuUsageMs += filterAmount * (msTaken - cpuUsageMs);
  19879. }
  19880. else
  19881. {
  19882. for (int i = 0; i < numOutputChannels; ++i)
  19883. zeromem (outputChannelData[i], sizeof (float) * numSamples);
  19884. }
  19885. if (testSound != 0)
  19886. {
  19887. const int numSamps = jmin (numSamples, testSound->getNumSamples() - testSoundPosition);
  19888. const float* const src = testSound->getSampleData (0, testSoundPosition);
  19889. for (int i = 0; i < numOutputChannels; ++i)
  19890. for (int j = 0; j < numSamps; ++j)
  19891. outputChannelData [i][j] += src[j];
  19892. testSoundPosition += numSamps;
  19893. if (testSoundPosition >= testSound->getNumSamples())
  19894. testSound = 0;
  19895. }
  19896. }
  19897. void AudioDeviceManager::audioDeviceAboutToStartInt (AudioIODevice* const device)
  19898. {
  19899. cpuUsageMs = 0;
  19900. const double sampleRate = device->getCurrentSampleRate();
  19901. const int blockSize = device->getCurrentBufferSizeSamples();
  19902. if (sampleRate > 0.0 && blockSize > 0)
  19903. {
  19904. const double msPerBlock = 1000.0 * blockSize / sampleRate;
  19905. timeToCpuScale = (msPerBlock > 0.0) ? (1.0 / msPerBlock) : 0.0;
  19906. }
  19907. {
  19908. const ScopedLock sl (audioCallbackLock);
  19909. for (int i = callbacks.size(); --i >= 0;)
  19910. callbacks.getUnchecked(i)->audioDeviceAboutToStart (device);
  19911. }
  19912. sendChangeMessage (this);
  19913. }
  19914. void AudioDeviceManager::audioDeviceStoppedInt()
  19915. {
  19916. cpuUsageMs = 0;
  19917. timeToCpuScale = 0;
  19918. sendChangeMessage (this);
  19919. const ScopedLock sl (audioCallbackLock);
  19920. for (int i = callbacks.size(); --i >= 0;)
  19921. callbacks.getUnchecked(i)->audioDeviceStopped();
  19922. }
  19923. double AudioDeviceManager::getCpuUsage() const
  19924. {
  19925. return jlimit (0.0, 1.0, timeToCpuScale * cpuUsageMs);
  19926. }
  19927. void AudioDeviceManager::setMidiInputEnabled (const String& name,
  19928. const bool enabled)
  19929. {
  19930. if (enabled != isMidiInputEnabled (name))
  19931. {
  19932. if (enabled)
  19933. {
  19934. const int index = MidiInput::getDevices().indexOf (name);
  19935. if (index >= 0)
  19936. {
  19937. MidiInput* const min = MidiInput::openDevice (index, &callbackHandler);
  19938. if (min != 0)
  19939. {
  19940. enabledMidiInputs.add (min);
  19941. min->start();
  19942. }
  19943. }
  19944. }
  19945. else
  19946. {
  19947. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19948. if (enabledMidiInputs[i]->getName() == name)
  19949. enabledMidiInputs.remove (i);
  19950. }
  19951. updateXml();
  19952. sendChangeMessage (this);
  19953. }
  19954. }
  19955. bool AudioDeviceManager::isMidiInputEnabled (const String& name) const
  19956. {
  19957. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19958. if (enabledMidiInputs[i]->getName() == name)
  19959. return true;
  19960. return false;
  19961. }
  19962. void AudioDeviceManager::addMidiInputCallback (const String& name,
  19963. MidiInputCallback* callback)
  19964. {
  19965. removeMidiInputCallback (name, callback);
  19966. if (name.isEmpty())
  19967. {
  19968. midiCallbacks.add (callback);
  19969. midiCallbackDevices.add (0);
  19970. }
  19971. else
  19972. {
  19973. for (int i = enabledMidiInputs.size(); --i >= 0;)
  19974. {
  19975. if (enabledMidiInputs[i]->getName() == name)
  19976. {
  19977. const ScopedLock sl (midiCallbackLock);
  19978. midiCallbacks.add (callback);
  19979. midiCallbackDevices.add (enabledMidiInputs[i]);
  19980. break;
  19981. }
  19982. }
  19983. }
  19984. }
  19985. void AudioDeviceManager::removeMidiInputCallback (const String& name,
  19986. MidiInputCallback* /*callback*/)
  19987. {
  19988. const ScopedLock sl (midiCallbackLock);
  19989. for (int i = midiCallbacks.size(); --i >= 0;)
  19990. {
  19991. String devName;
  19992. if (midiCallbackDevices.getUnchecked(i) != 0)
  19993. devName = midiCallbackDevices.getUnchecked(i)->getName();
  19994. if (devName == name)
  19995. {
  19996. midiCallbacks.remove (i);
  19997. midiCallbackDevices.remove (i);
  19998. }
  19999. }
  20000. }
  20001. void AudioDeviceManager::handleIncomingMidiMessageInt (MidiInput* source,
  20002. const MidiMessage& message)
  20003. {
  20004. if (! message.isActiveSense())
  20005. {
  20006. const bool isDefaultSource = (source == 0 || source == enabledMidiInputs.getFirst());
  20007. const ScopedLock sl (midiCallbackLock);
  20008. for (int i = midiCallbackDevices.size(); --i >= 0;)
  20009. {
  20010. MidiInput* const md = midiCallbackDevices.getUnchecked(i);
  20011. if (md == source || (md == 0 && isDefaultSource))
  20012. midiCallbacks.getUnchecked(i)->handleIncomingMidiMessage (source, message);
  20013. }
  20014. }
  20015. }
  20016. void AudioDeviceManager::setDefaultMidiOutput (const String& deviceName)
  20017. {
  20018. if (defaultMidiOutputName != deviceName)
  20019. {
  20020. SortedSet <AudioIODeviceCallback*> oldCallbacks;
  20021. {
  20022. const ScopedLock sl (audioCallbackLock);
  20023. oldCallbacks = callbacks;
  20024. callbacks.clear();
  20025. }
  20026. if (currentAudioDevice != 0)
  20027. for (int i = oldCallbacks.size(); --i >= 0;)
  20028. oldCallbacks.getUnchecked(i)->audioDeviceStopped();
  20029. defaultMidiOutput = 0;
  20030. defaultMidiOutputName = deviceName;
  20031. if (deviceName.isNotEmpty())
  20032. defaultMidiOutput = MidiOutput::openDevice (MidiOutput::getDevices().indexOf (deviceName));
  20033. if (currentAudioDevice != 0)
  20034. for (int i = oldCallbacks.size(); --i >= 0;)
  20035. oldCallbacks.getUnchecked(i)->audioDeviceAboutToStart (currentAudioDevice);
  20036. {
  20037. const ScopedLock sl (audioCallbackLock);
  20038. callbacks = oldCallbacks;
  20039. }
  20040. updateXml();
  20041. sendChangeMessage (this);
  20042. }
  20043. }
  20044. void AudioDeviceManager::CallbackHandler::audioDeviceIOCallback (const float** inputChannelData,
  20045. int numInputChannels,
  20046. float** outputChannelData,
  20047. int numOutputChannels,
  20048. int numSamples)
  20049. {
  20050. owner->audioDeviceIOCallbackInt (inputChannelData, numInputChannels, outputChannelData, numOutputChannels, numSamples);
  20051. }
  20052. void AudioDeviceManager::CallbackHandler::audioDeviceAboutToStart (AudioIODevice* device)
  20053. {
  20054. owner->audioDeviceAboutToStartInt (device);
  20055. }
  20056. void AudioDeviceManager::CallbackHandler::audioDeviceStopped()
  20057. {
  20058. owner->audioDeviceStoppedInt();
  20059. }
  20060. void AudioDeviceManager::CallbackHandler::handleIncomingMidiMessage (MidiInput* source, const MidiMessage& message)
  20061. {
  20062. owner->handleIncomingMidiMessageInt (source, message);
  20063. }
  20064. void AudioDeviceManager::playTestSound()
  20065. {
  20066. { // cunningly nested to swap, unlock and delete in that order.
  20067. ScopedPointer <AudioSampleBuffer> oldSound;
  20068. {
  20069. const ScopedLock sl (audioCallbackLock);
  20070. oldSound = testSound;
  20071. }
  20072. }
  20073. testSoundPosition = 0;
  20074. if (currentAudioDevice != 0)
  20075. {
  20076. const double sampleRate = currentAudioDevice->getCurrentSampleRate();
  20077. const int soundLength = (int) sampleRate;
  20078. AudioSampleBuffer* const newSound = new AudioSampleBuffer (1, soundLength);
  20079. float* samples = newSound->getSampleData (0);
  20080. const double frequency = MidiMessage::getMidiNoteInHertz (80);
  20081. const float amplitude = 0.5f;
  20082. const double phasePerSample = double_Pi * 2.0 / (sampleRate / frequency);
  20083. for (int i = 0; i < soundLength; ++i)
  20084. samples[i] = amplitude * (float) sin (i * phasePerSample);
  20085. newSound->applyGainRamp (0, 0, soundLength / 10, 0.0f, 1.0f);
  20086. newSound->applyGainRamp (0, soundLength - soundLength / 4, soundLength / 4, 1.0f, 0.0f);
  20087. const ScopedLock sl (audioCallbackLock);
  20088. testSound = newSound;
  20089. }
  20090. }
  20091. void AudioDeviceManager::enableInputLevelMeasurement (const bool enableMeasurement)
  20092. {
  20093. const ScopedLock sl (audioCallbackLock);
  20094. if (enableMeasurement)
  20095. ++inputLevelMeasurementEnabledCount;
  20096. else
  20097. --inputLevelMeasurementEnabledCount;
  20098. inputLevel = 0;
  20099. }
  20100. double AudioDeviceManager::getCurrentInputLevel() const
  20101. {
  20102. jassert (inputLevelMeasurementEnabledCount > 0); // you need to call enableInputLevelMeasurement() before using this!
  20103. return inputLevel;
  20104. }
  20105. END_JUCE_NAMESPACE
  20106. /*** End of inlined file: juce_AudioDeviceManager.cpp ***/
  20107. /*** Start of inlined file: juce_AudioIODevice.cpp ***/
  20108. BEGIN_JUCE_NAMESPACE
  20109. AudioIODevice::AudioIODevice (const String& deviceName, const String& typeName_)
  20110. : name (deviceName),
  20111. typeName (typeName_)
  20112. {
  20113. }
  20114. AudioIODevice::~AudioIODevice()
  20115. {
  20116. }
  20117. bool AudioIODevice::hasControlPanel() const
  20118. {
  20119. return false;
  20120. }
  20121. bool AudioIODevice::showControlPanel()
  20122. {
  20123. jassertfalse // this should only be called for devices which return true from
  20124. // their hasControlPanel() method.
  20125. return false;
  20126. }
  20127. END_JUCE_NAMESPACE
  20128. /*** End of inlined file: juce_AudioIODevice.cpp ***/
  20129. /*** Start of inlined file: juce_AudioIODeviceType.cpp ***/
  20130. BEGIN_JUCE_NAMESPACE
  20131. AudioIODeviceType::AudioIODeviceType (const tchar* const name)
  20132. : typeName (name)
  20133. {
  20134. }
  20135. AudioIODeviceType::~AudioIODeviceType()
  20136. {
  20137. }
  20138. END_JUCE_NAMESPACE
  20139. /*** End of inlined file: juce_AudioIODeviceType.cpp ***/
  20140. /*** Start of inlined file: juce_MidiOutput.cpp ***/
  20141. BEGIN_JUCE_NAMESPACE
  20142. MidiOutput::MidiOutput() throw()
  20143. : Thread ("midi out"),
  20144. internal (0),
  20145. firstMessage (0)
  20146. {
  20147. }
  20148. MidiOutput::PendingMessage::PendingMessage (const uint8* const data,
  20149. const int len,
  20150. const double sampleNumber) throw()
  20151. : message (data, len, sampleNumber)
  20152. {
  20153. }
  20154. void MidiOutput::sendBlockOfMessages (const MidiBuffer& buffer,
  20155. const double millisecondCounterToStartAt,
  20156. double samplesPerSecondForBuffer) throw()
  20157. {
  20158. // You've got to call startBackgroundThread() for this to actually work..
  20159. jassert (isThreadRunning());
  20160. // this needs to be a value in the future - RTFM for this method!
  20161. jassert (millisecondCounterToStartAt > 0);
  20162. const double timeScaleFactor = 1000.0 / samplesPerSecondForBuffer;
  20163. MidiBuffer::Iterator i (buffer);
  20164. const uint8* data;
  20165. int len, time;
  20166. while (i.getNextEvent (data, len, time))
  20167. {
  20168. const double eventTime = millisecondCounterToStartAt + timeScaleFactor * time;
  20169. PendingMessage* const m
  20170. = new PendingMessage (data, len, eventTime);
  20171. const ScopedLock sl (lock);
  20172. if (firstMessage == 0 || firstMessage->message.getTimeStamp() > eventTime)
  20173. {
  20174. m->next = firstMessage;
  20175. firstMessage = m;
  20176. }
  20177. else
  20178. {
  20179. PendingMessage* mm = firstMessage;
  20180. while (mm->next != 0 && mm->next->message.getTimeStamp() <= eventTime)
  20181. mm = mm->next;
  20182. m->next = mm->next;
  20183. mm->next = m;
  20184. }
  20185. }
  20186. notify();
  20187. }
  20188. void MidiOutput::clearAllPendingMessages() throw()
  20189. {
  20190. const ScopedLock sl (lock);
  20191. while (firstMessage != 0)
  20192. {
  20193. PendingMessage* const m = firstMessage;
  20194. firstMessage = firstMessage->next;
  20195. delete m;
  20196. }
  20197. }
  20198. void MidiOutput::startBackgroundThread() throw()
  20199. {
  20200. startThread (9);
  20201. }
  20202. void MidiOutput::stopBackgroundThread() throw()
  20203. {
  20204. stopThread (5000);
  20205. }
  20206. void MidiOutput::run()
  20207. {
  20208. while (! threadShouldExit())
  20209. {
  20210. uint32 now = Time::getMillisecondCounter();
  20211. uint32 eventTime = 0;
  20212. uint32 timeToWait = 500;
  20213. PendingMessage* message;
  20214. {
  20215. const ScopedLock sl (lock);
  20216. message = firstMessage;
  20217. if (message != 0)
  20218. {
  20219. eventTime = roundToInt (message->message.getTimeStamp());
  20220. if (eventTime > now + 20)
  20221. {
  20222. timeToWait = eventTime - (now + 20);
  20223. message = 0;
  20224. }
  20225. else
  20226. {
  20227. firstMessage = message->next;
  20228. }
  20229. }
  20230. }
  20231. if (message != 0)
  20232. {
  20233. if (eventTime > now)
  20234. {
  20235. Time::waitForMillisecondCounter (eventTime);
  20236. if (threadShouldExit())
  20237. break;
  20238. }
  20239. if (eventTime > now - 200)
  20240. sendMessageNow (message->message);
  20241. delete message;
  20242. }
  20243. else
  20244. {
  20245. jassert (timeToWait < 1000 * 30);
  20246. wait (timeToWait);
  20247. }
  20248. }
  20249. clearAllPendingMessages();
  20250. }
  20251. END_JUCE_NAMESPACE
  20252. /*** End of inlined file: juce_MidiOutput.cpp ***/
  20253. /*** Start of inlined file: juce_AudioDataConverters.cpp ***/
  20254. BEGIN_JUCE_NAMESPACE
  20255. void AudioDataConverters::convertFloatToInt16LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20256. {
  20257. const double maxVal = (double) 0x7fff;
  20258. char* intData = (char*) dest;
  20259. if (dest != (void*) source || destBytesPerSample <= 4)
  20260. {
  20261. for (int i = 0; i < numSamples; ++i)
  20262. {
  20263. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20264. intData += destBytesPerSample;
  20265. }
  20266. }
  20267. else
  20268. {
  20269. intData += destBytesPerSample * numSamples;
  20270. for (int i = numSamples; --i >= 0;)
  20271. {
  20272. intData -= destBytesPerSample;
  20273. *(uint16*)intData = ByteOrder::swapIfBigEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20274. }
  20275. }
  20276. }
  20277. void AudioDataConverters::convertFloatToInt16BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20278. {
  20279. const double maxVal = (double) 0x7fff;
  20280. char* intData = (char*) dest;
  20281. if (dest != (void*) source || destBytesPerSample <= 4)
  20282. {
  20283. for (int i = 0; i < numSamples; ++i)
  20284. {
  20285. *(uint16*) intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20286. intData += destBytesPerSample;
  20287. }
  20288. }
  20289. else
  20290. {
  20291. intData += destBytesPerSample * numSamples;
  20292. for (int i = numSamples; --i >= 0;)
  20293. {
  20294. intData -= destBytesPerSample;
  20295. *(uint16*)intData = ByteOrder::swapIfLittleEndian ((uint16) (short) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20296. }
  20297. }
  20298. }
  20299. void AudioDataConverters::convertFloatToInt24LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20300. {
  20301. const double maxVal = (double) 0x7fffff;
  20302. char* intData = (char*) dest;
  20303. if (dest != (void*) source || destBytesPerSample <= 4)
  20304. {
  20305. for (int i = 0; i < numSamples; ++i)
  20306. {
  20307. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20308. intData += destBytesPerSample;
  20309. }
  20310. }
  20311. else
  20312. {
  20313. intData += destBytesPerSample * numSamples;
  20314. for (int i = numSamples; --i >= 0;)
  20315. {
  20316. intData -= destBytesPerSample;
  20317. ByteOrder::littleEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20318. }
  20319. }
  20320. }
  20321. void AudioDataConverters::convertFloatToInt24BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20322. {
  20323. const double maxVal = (double) 0x7fffff;
  20324. char* intData = (char*) dest;
  20325. if (dest != (void*) source || destBytesPerSample <= 4)
  20326. {
  20327. for (int i = 0; i < numSamples; ++i)
  20328. {
  20329. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20330. intData += destBytesPerSample;
  20331. }
  20332. }
  20333. else
  20334. {
  20335. intData += destBytesPerSample * numSamples;
  20336. for (int i = numSamples; --i >= 0;)
  20337. {
  20338. intData -= destBytesPerSample;
  20339. ByteOrder::bigEndian24BitToChars ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])), intData);
  20340. }
  20341. }
  20342. }
  20343. void AudioDataConverters::convertFloatToInt32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20344. {
  20345. const double maxVal = (double) 0x7fffffff;
  20346. char* intData = (char*) dest;
  20347. if (dest != (void*) source || destBytesPerSample <= 4)
  20348. {
  20349. for (int i = 0; i < numSamples; ++i)
  20350. {
  20351. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20352. intData += destBytesPerSample;
  20353. }
  20354. }
  20355. else
  20356. {
  20357. intData += destBytesPerSample * numSamples;
  20358. for (int i = numSamples; --i >= 0;)
  20359. {
  20360. intData -= destBytesPerSample;
  20361. *(uint32*)intData = ByteOrder::swapIfBigEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20362. }
  20363. }
  20364. }
  20365. void AudioDataConverters::convertFloatToInt32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20366. {
  20367. const double maxVal = (double) 0x7fffffff;
  20368. char* intData = (char*) dest;
  20369. if (dest != (void*) source || destBytesPerSample <= 4)
  20370. {
  20371. for (int i = 0; i < numSamples; ++i)
  20372. {
  20373. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20374. intData += destBytesPerSample;
  20375. }
  20376. }
  20377. else
  20378. {
  20379. intData += destBytesPerSample * numSamples;
  20380. for (int i = numSamples; --i >= 0;)
  20381. {
  20382. intData -= destBytesPerSample;
  20383. *(uint32*)intData = ByteOrder::swapIfLittleEndian ((uint32) roundToInt (jlimit (-maxVal, maxVal, maxVal * source[i])));
  20384. }
  20385. }
  20386. }
  20387. void AudioDataConverters::convertFloatToFloat32LE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20388. {
  20389. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20390. char* d = (char*) dest;
  20391. for (int i = 0; i < numSamples; ++i)
  20392. {
  20393. *(float*) d = source[i];
  20394. #if JUCE_BIG_ENDIAN
  20395. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20396. #endif
  20397. d += destBytesPerSample;
  20398. }
  20399. }
  20400. void AudioDataConverters::convertFloatToFloat32BE (const float* source, void* dest, int numSamples, const int destBytesPerSample)
  20401. {
  20402. jassert (dest != (void*) source || destBytesPerSample <= 4); // This op can't be performed on in-place data!
  20403. char* d = (char*) dest;
  20404. for (int i = 0; i < numSamples; ++i)
  20405. {
  20406. *(float*) d = source[i];
  20407. #if JUCE_LITTLE_ENDIAN
  20408. *(uint32*) d = ByteOrder::swap (*(uint32*) d);
  20409. #endif
  20410. d += destBytesPerSample;
  20411. }
  20412. }
  20413. void AudioDataConverters::convertInt16LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20414. {
  20415. const float scale = 1.0f / 0x7fff;
  20416. const char* intData = (const char*) source;
  20417. if (source != (void*) dest || srcBytesPerSample >= 4)
  20418. {
  20419. for (int i = 0; i < numSamples; ++i)
  20420. {
  20421. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20422. intData += srcBytesPerSample;
  20423. }
  20424. }
  20425. else
  20426. {
  20427. intData += srcBytesPerSample * numSamples;
  20428. for (int i = numSamples; --i >= 0;)
  20429. {
  20430. intData -= srcBytesPerSample;
  20431. dest[i] = scale * (short) ByteOrder::swapIfBigEndian (*(uint16*)intData);
  20432. }
  20433. }
  20434. }
  20435. void AudioDataConverters::convertInt16BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20436. {
  20437. const float scale = 1.0f / 0x7fff;
  20438. const char* intData = (const char*) source;
  20439. if (source != (void*) dest || srcBytesPerSample >= 4)
  20440. {
  20441. for (int i = 0; i < numSamples; ++i)
  20442. {
  20443. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20444. intData += srcBytesPerSample;
  20445. }
  20446. }
  20447. else
  20448. {
  20449. intData += srcBytesPerSample * numSamples;
  20450. for (int i = numSamples; --i >= 0;)
  20451. {
  20452. intData -= srcBytesPerSample;
  20453. dest[i] = scale * (short) ByteOrder::swapIfLittleEndian (*(uint16*)intData);
  20454. }
  20455. }
  20456. }
  20457. void AudioDataConverters::convertInt24LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20458. {
  20459. const float scale = 1.0f / 0x7fffff;
  20460. const char* intData = (const char*) source;
  20461. if (source != (void*) dest || srcBytesPerSample >= 4)
  20462. {
  20463. for (int i = 0; i < numSamples; ++i)
  20464. {
  20465. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20466. intData += srcBytesPerSample;
  20467. }
  20468. }
  20469. else
  20470. {
  20471. intData += srcBytesPerSample * numSamples;
  20472. for (int i = numSamples; --i >= 0;)
  20473. {
  20474. intData -= srcBytesPerSample;
  20475. dest[i] = scale * (short) ByteOrder::littleEndian24Bit (intData);
  20476. }
  20477. }
  20478. }
  20479. void AudioDataConverters::convertInt24BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20480. {
  20481. const float scale = 1.0f / 0x7fffff;
  20482. const char* intData = (const char*) source;
  20483. if (source != (void*) dest || srcBytesPerSample >= 4)
  20484. {
  20485. for (int i = 0; i < numSamples; ++i)
  20486. {
  20487. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20488. intData += srcBytesPerSample;
  20489. }
  20490. }
  20491. else
  20492. {
  20493. intData += srcBytesPerSample * numSamples;
  20494. for (int i = numSamples; --i >= 0;)
  20495. {
  20496. intData -= srcBytesPerSample;
  20497. dest[i] = scale * (short) ByteOrder::bigEndian24Bit (intData);
  20498. }
  20499. }
  20500. }
  20501. void AudioDataConverters::convertInt32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20502. {
  20503. const float scale = 1.0f / 0x7fffffff;
  20504. const char* intData = (const char*) source;
  20505. if (source != (void*) dest || srcBytesPerSample >= 4)
  20506. {
  20507. for (int i = 0; i < numSamples; ++i)
  20508. {
  20509. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20510. intData += srcBytesPerSample;
  20511. }
  20512. }
  20513. else
  20514. {
  20515. intData += srcBytesPerSample * numSamples;
  20516. for (int i = numSamples; --i >= 0;)
  20517. {
  20518. intData -= srcBytesPerSample;
  20519. dest[i] = scale * (int) ByteOrder::swapIfBigEndian (*(uint32*) intData);
  20520. }
  20521. }
  20522. }
  20523. void AudioDataConverters::convertInt32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20524. {
  20525. const float scale = 1.0f / 0x7fffffff;
  20526. const char* intData = (const char*) source;
  20527. if (source != (void*) dest || srcBytesPerSample >= 4)
  20528. {
  20529. for (int i = 0; i < numSamples; ++i)
  20530. {
  20531. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20532. intData += srcBytesPerSample;
  20533. }
  20534. }
  20535. else
  20536. {
  20537. intData += srcBytesPerSample * numSamples;
  20538. for (int i = numSamples; --i >= 0;)
  20539. {
  20540. intData -= srcBytesPerSample;
  20541. dest[i] = scale * (int) ByteOrder::swapIfLittleEndian (*(uint32*) intData);
  20542. }
  20543. }
  20544. }
  20545. void AudioDataConverters::convertFloat32LEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20546. {
  20547. const char* s = (const char*) source;
  20548. for (int i = 0; i < numSamples; ++i)
  20549. {
  20550. dest[i] = *(float*)s;
  20551. #if JUCE_BIG_ENDIAN
  20552. uint32* const d = (uint32*) (dest + i);
  20553. *d = ByteOrder::swap (*d);
  20554. #endif
  20555. s += srcBytesPerSample;
  20556. }
  20557. }
  20558. void AudioDataConverters::convertFloat32BEToFloat (const void* const source, float* const dest, int numSamples, const int srcBytesPerSample)
  20559. {
  20560. const char* s = (const char*) source;
  20561. for (int i = 0; i < numSamples; ++i)
  20562. {
  20563. dest[i] = *(float*)s;
  20564. #if JUCE_LITTLE_ENDIAN
  20565. uint32* const d = (uint32*) (dest + i);
  20566. *d = ByteOrder::swap (*d);
  20567. #endif
  20568. s += srcBytesPerSample;
  20569. }
  20570. }
  20571. void AudioDataConverters::convertFloatToFormat (const DataFormat destFormat,
  20572. const float* const source,
  20573. void* const dest,
  20574. const int numSamples)
  20575. {
  20576. switch (destFormat)
  20577. {
  20578. case int16LE:
  20579. convertFloatToInt16LE (source, dest, numSamples);
  20580. break;
  20581. case int16BE:
  20582. convertFloatToInt16BE (source, dest, numSamples);
  20583. break;
  20584. case int24LE:
  20585. convertFloatToInt24LE (source, dest, numSamples);
  20586. break;
  20587. case int24BE:
  20588. convertFloatToInt24BE (source, dest, numSamples);
  20589. break;
  20590. case int32LE:
  20591. convertFloatToInt32LE (source, dest, numSamples);
  20592. break;
  20593. case int32BE:
  20594. convertFloatToInt32BE (source, dest, numSamples);
  20595. break;
  20596. case float32LE:
  20597. convertFloatToFloat32LE (source, dest, numSamples);
  20598. break;
  20599. case float32BE:
  20600. convertFloatToFloat32BE (source, dest, numSamples);
  20601. break;
  20602. default:
  20603. jassertfalse
  20604. break;
  20605. }
  20606. }
  20607. void AudioDataConverters::convertFormatToFloat (const DataFormat sourceFormat,
  20608. const void* const source,
  20609. float* const dest,
  20610. const int numSamples)
  20611. {
  20612. switch (sourceFormat)
  20613. {
  20614. case int16LE:
  20615. convertInt16LEToFloat (source, dest, numSamples);
  20616. break;
  20617. case int16BE:
  20618. convertInt16BEToFloat (source, dest, numSamples);
  20619. break;
  20620. case int24LE:
  20621. convertInt24LEToFloat (source, dest, numSamples);
  20622. break;
  20623. case int24BE:
  20624. convertInt24BEToFloat (source, dest, numSamples);
  20625. break;
  20626. case int32LE:
  20627. convertInt32LEToFloat (source, dest, numSamples);
  20628. break;
  20629. case int32BE:
  20630. convertInt32BEToFloat (source, dest, numSamples);
  20631. break;
  20632. case float32LE:
  20633. convertFloat32LEToFloat (source, dest, numSamples);
  20634. break;
  20635. case float32BE:
  20636. convertFloat32BEToFloat (source, dest, numSamples);
  20637. break;
  20638. default:
  20639. jassertfalse
  20640. break;
  20641. }
  20642. }
  20643. void AudioDataConverters::interleaveSamples (const float** const source,
  20644. float* const dest,
  20645. const int numSamples,
  20646. const int numChannels)
  20647. {
  20648. for (int chan = 0; chan < numChannels; ++chan)
  20649. {
  20650. int i = chan;
  20651. const float* src = source [chan];
  20652. for (int j = 0; j < numSamples; ++j)
  20653. {
  20654. dest [i] = src [j];
  20655. i += numChannels;
  20656. }
  20657. }
  20658. }
  20659. void AudioDataConverters::deinterleaveSamples (const float* const source,
  20660. float** const dest,
  20661. const int numSamples,
  20662. const int numChannels)
  20663. {
  20664. for (int chan = 0; chan < numChannels; ++chan)
  20665. {
  20666. int i = chan;
  20667. float* dst = dest [chan];
  20668. for (int j = 0; j < numSamples; ++j)
  20669. {
  20670. dst [j] = source [i];
  20671. i += numChannels;
  20672. }
  20673. }
  20674. }
  20675. END_JUCE_NAMESPACE
  20676. /*** End of inlined file: juce_AudioDataConverters.cpp ***/
  20677. /*** Start of inlined file: juce_AudioSampleBuffer.cpp ***/
  20678. BEGIN_JUCE_NAMESPACE
  20679. AudioSampleBuffer::AudioSampleBuffer (const int numChannels_,
  20680. const int numSamples) throw()
  20681. : numChannels (numChannels_),
  20682. size (numSamples)
  20683. {
  20684. jassert (numSamples >= 0);
  20685. jassert (numChannels_ > 0);
  20686. allocateData();
  20687. }
  20688. AudioSampleBuffer::AudioSampleBuffer (const AudioSampleBuffer& other) throw()
  20689. : numChannels (other.numChannels),
  20690. size (other.size)
  20691. {
  20692. allocateData();
  20693. const size_t numBytes = size * sizeof (float);
  20694. for (int i = 0; i < numChannels; ++i)
  20695. memcpy (channels[i], other.channels[i], numBytes);
  20696. }
  20697. void AudioSampleBuffer::allocateData()
  20698. {
  20699. const size_t channelListSize = (numChannels + 1) * sizeof (float*);
  20700. allocatedBytes = (int) (numChannels * size * sizeof (float) + channelListSize + 32);
  20701. allocatedData.malloc (allocatedBytes);
  20702. channels = (float**) allocatedData;
  20703. float* chan = (float*) (allocatedData + channelListSize);
  20704. for (int i = 0; i < numChannels; ++i)
  20705. {
  20706. channels[i] = chan;
  20707. chan += size;
  20708. }
  20709. channels [numChannels] = 0;
  20710. }
  20711. AudioSampleBuffer::AudioSampleBuffer (float** dataToReferTo,
  20712. const int numChannels_,
  20713. const int numSamples) throw()
  20714. : numChannels (numChannels_),
  20715. size (numSamples),
  20716. allocatedBytes (0)
  20717. {
  20718. jassert (numChannels_ > 0);
  20719. allocateChannels (dataToReferTo);
  20720. }
  20721. void AudioSampleBuffer::setDataToReferTo (float** dataToReferTo,
  20722. const int newNumChannels,
  20723. const int newNumSamples) throw()
  20724. {
  20725. jassert (newNumChannels > 0);
  20726. allocatedBytes = 0;
  20727. allocatedData.free();
  20728. numChannels = newNumChannels;
  20729. size = newNumSamples;
  20730. allocateChannels (dataToReferTo);
  20731. }
  20732. void AudioSampleBuffer::allocateChannels (float** const dataToReferTo)
  20733. {
  20734. // (try to avoid doing a malloc here, as that'll blow up things like Pro-Tools)
  20735. if (numChannels < numElementsInArray (preallocatedChannelSpace))
  20736. {
  20737. channels = (float**) preallocatedChannelSpace;
  20738. }
  20739. else
  20740. {
  20741. allocatedData.malloc (numChannels + 1, sizeof (float*));
  20742. channels = (float**) allocatedData;
  20743. }
  20744. for (int i = 0; i < numChannels; ++i)
  20745. {
  20746. // you have to pass in the same number of valid pointers as numChannels
  20747. jassert (dataToReferTo[i] != 0);
  20748. channels[i] = dataToReferTo[i];
  20749. }
  20750. channels [numChannels] = 0;
  20751. }
  20752. AudioSampleBuffer& AudioSampleBuffer::operator= (const AudioSampleBuffer& other) throw()
  20753. {
  20754. if (this != &other)
  20755. {
  20756. setSize (other.getNumChannels(), other.getNumSamples(), false, false, false);
  20757. const size_t numBytes = size * sizeof (float);
  20758. for (int i = 0; i < numChannels; ++i)
  20759. memcpy (channels[i], other.channels[i], numBytes);
  20760. }
  20761. return *this;
  20762. }
  20763. AudioSampleBuffer::~AudioSampleBuffer() throw()
  20764. {
  20765. }
  20766. void AudioSampleBuffer::setSize (const int newNumChannels,
  20767. const int newNumSamples,
  20768. const bool keepExistingContent,
  20769. const bool clearExtraSpace,
  20770. const bool avoidReallocating) throw()
  20771. {
  20772. jassert (newNumChannels > 0);
  20773. if (newNumSamples != size || newNumChannels != numChannels)
  20774. {
  20775. const size_t channelListSize = (newNumChannels + 1) * sizeof (float*);
  20776. const size_t newTotalBytes = (newNumChannels * newNumSamples * sizeof (float)) + channelListSize + 32;
  20777. if (keepExistingContent)
  20778. {
  20779. HeapBlock <char> newData;
  20780. newData.allocate (newTotalBytes, clearExtraSpace);
  20781. const int numChansToCopy = jmin (numChannels, newNumChannels);
  20782. const size_t numBytesToCopy = sizeof (float) * jmin (newNumSamples, size);
  20783. float** const newChannels = (float**) newData;
  20784. float* newChan = (float*) (newData + channelListSize);
  20785. for (int i = 0; i < numChansToCopy; ++i)
  20786. {
  20787. memcpy (newChan, channels[i], numBytesToCopy);
  20788. newChannels[i] = newChan;
  20789. newChan += newNumSamples;
  20790. }
  20791. allocatedData.swapWith (newData);
  20792. allocatedBytes = (int) newTotalBytes;
  20793. channels = (float**) allocatedData;
  20794. }
  20795. else
  20796. {
  20797. if (avoidReallocating && allocatedBytes >= newTotalBytes)
  20798. {
  20799. if (clearExtraSpace)
  20800. zeromem (allocatedData, newTotalBytes);
  20801. }
  20802. else
  20803. {
  20804. allocatedBytes = newTotalBytes;
  20805. allocatedData.allocate (newTotalBytes, clearExtraSpace);
  20806. channels = (float**) allocatedData;
  20807. }
  20808. float* chan = (float*) (allocatedData + channelListSize);
  20809. for (int i = 0; i < newNumChannels; ++i)
  20810. {
  20811. channels[i] = chan;
  20812. chan += newNumSamples;
  20813. }
  20814. }
  20815. channels [newNumChannels] = 0;
  20816. size = newNumSamples;
  20817. numChannels = newNumChannels;
  20818. }
  20819. }
  20820. void AudioSampleBuffer::clear() throw()
  20821. {
  20822. for (int i = 0; i < numChannels; ++i)
  20823. zeromem (channels[i], size * sizeof (float));
  20824. }
  20825. void AudioSampleBuffer::clear (const int startSample,
  20826. const int numSamples) throw()
  20827. {
  20828. jassert (startSample >= 0 && startSample + numSamples <= size);
  20829. for (int i = 0; i < numChannels; ++i)
  20830. zeromem (channels [i] + startSample, numSamples * sizeof (float));
  20831. }
  20832. void AudioSampleBuffer::clear (const int channel,
  20833. const int startSample,
  20834. const int numSamples) throw()
  20835. {
  20836. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20837. jassert (startSample >= 0 && startSample + numSamples <= size);
  20838. zeromem (channels [channel] + startSample, numSamples * sizeof (float));
  20839. }
  20840. void AudioSampleBuffer::applyGain (const int channel,
  20841. const int startSample,
  20842. int numSamples,
  20843. const float gain) throw()
  20844. {
  20845. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20846. jassert (startSample >= 0 && startSample + numSamples <= size);
  20847. if (gain != 1.0f)
  20848. {
  20849. float* d = channels [channel] + startSample;
  20850. if (gain == 0.0f)
  20851. {
  20852. zeromem (d, sizeof (float) * numSamples);
  20853. }
  20854. else
  20855. {
  20856. while (--numSamples >= 0)
  20857. *d++ *= gain;
  20858. }
  20859. }
  20860. }
  20861. void AudioSampleBuffer::applyGainRamp (const int channel,
  20862. const int startSample,
  20863. int numSamples,
  20864. float startGain,
  20865. float endGain) throw()
  20866. {
  20867. if (startGain == endGain)
  20868. {
  20869. applyGain (channel, startSample, numSamples, startGain);
  20870. }
  20871. else
  20872. {
  20873. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  20874. jassert (startSample >= 0 && startSample + numSamples <= size);
  20875. const float increment = (endGain - startGain) / numSamples;
  20876. float* d = channels [channel] + startSample;
  20877. while (--numSamples >= 0)
  20878. {
  20879. *d++ *= startGain;
  20880. startGain += increment;
  20881. }
  20882. }
  20883. }
  20884. void AudioSampleBuffer::applyGain (const int startSample,
  20885. const int numSamples,
  20886. const float gain) throw()
  20887. {
  20888. for (int i = 0; i < numChannels; ++i)
  20889. applyGain (i, startSample, numSamples, gain);
  20890. }
  20891. void AudioSampleBuffer::addFrom (const int destChannel,
  20892. const int destStartSample,
  20893. const AudioSampleBuffer& source,
  20894. const int sourceChannel,
  20895. const int sourceStartSample,
  20896. int numSamples,
  20897. const float gain) throw()
  20898. {
  20899. jassert (&source != this || sourceChannel != destChannel);
  20900. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20901. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20902. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20903. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20904. if (gain != 0.0f && numSamples > 0)
  20905. {
  20906. float* d = channels [destChannel] + destStartSample;
  20907. const float* s = source.channels [sourceChannel] + sourceStartSample;
  20908. if (gain != 1.0f)
  20909. {
  20910. while (--numSamples >= 0)
  20911. *d++ += gain * *s++;
  20912. }
  20913. else
  20914. {
  20915. while (--numSamples >= 0)
  20916. *d++ += *s++;
  20917. }
  20918. }
  20919. }
  20920. void AudioSampleBuffer::addFrom (const int destChannel,
  20921. const int destStartSample,
  20922. const float* source,
  20923. int numSamples,
  20924. const float gain) throw()
  20925. {
  20926. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20927. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20928. jassert (source != 0);
  20929. if (gain != 0.0f && numSamples > 0)
  20930. {
  20931. float* d = channels [destChannel] + destStartSample;
  20932. if (gain != 1.0f)
  20933. {
  20934. while (--numSamples >= 0)
  20935. *d++ += gain * *source++;
  20936. }
  20937. else
  20938. {
  20939. while (--numSamples >= 0)
  20940. *d++ += *source++;
  20941. }
  20942. }
  20943. }
  20944. void AudioSampleBuffer::addFromWithRamp (const int destChannel,
  20945. const int destStartSample,
  20946. const float* source,
  20947. int numSamples,
  20948. float startGain,
  20949. const float endGain) throw()
  20950. {
  20951. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20952. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20953. jassert (source != 0);
  20954. if (startGain == endGain)
  20955. {
  20956. addFrom (destChannel,
  20957. destStartSample,
  20958. source,
  20959. numSamples,
  20960. startGain);
  20961. }
  20962. else
  20963. {
  20964. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  20965. {
  20966. const float increment = (endGain - startGain) / numSamples;
  20967. float* d = channels [destChannel] + destStartSample;
  20968. while (--numSamples >= 0)
  20969. {
  20970. *d++ += startGain * *source++;
  20971. startGain += increment;
  20972. }
  20973. }
  20974. }
  20975. }
  20976. void AudioSampleBuffer::copyFrom (const int destChannel,
  20977. const int destStartSample,
  20978. const AudioSampleBuffer& source,
  20979. const int sourceChannel,
  20980. const int sourceStartSample,
  20981. int numSamples) throw()
  20982. {
  20983. jassert (&source != this || sourceChannel != destChannel);
  20984. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  20985. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  20986. jassert (((unsigned int) sourceChannel) < (unsigned int) source.numChannels);
  20987. jassert (sourceStartSample >= 0 && sourceStartSample + numSamples <= source.size);
  20988. if (numSamples > 0)
  20989. {
  20990. memcpy (channels [destChannel] + destStartSample,
  20991. source.channels [sourceChannel] + sourceStartSample,
  20992. sizeof (float) * numSamples);
  20993. }
  20994. }
  20995. void AudioSampleBuffer::copyFrom (const int destChannel,
  20996. const int destStartSample,
  20997. const float* source,
  20998. int numSamples) throw()
  20999. {
  21000. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21001. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21002. jassert (source != 0);
  21003. if (numSamples > 0)
  21004. {
  21005. memcpy (channels [destChannel] + destStartSample,
  21006. source,
  21007. sizeof (float) * numSamples);
  21008. }
  21009. }
  21010. void AudioSampleBuffer::copyFrom (const int destChannel,
  21011. const int destStartSample,
  21012. const float* source,
  21013. int numSamples,
  21014. const float gain) throw()
  21015. {
  21016. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21017. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21018. jassert (source != 0);
  21019. if (numSamples > 0)
  21020. {
  21021. float* d = channels [destChannel] + destStartSample;
  21022. if (gain != 1.0f)
  21023. {
  21024. if (gain == 0)
  21025. {
  21026. zeromem (d, sizeof (float) * numSamples);
  21027. }
  21028. else
  21029. {
  21030. while (--numSamples >= 0)
  21031. *d++ = gain * *source++;
  21032. }
  21033. }
  21034. else
  21035. {
  21036. memcpy (d, source, sizeof (float) * numSamples);
  21037. }
  21038. }
  21039. }
  21040. void AudioSampleBuffer::copyFromWithRamp (const int destChannel,
  21041. const int destStartSample,
  21042. const float* source,
  21043. int numSamples,
  21044. float startGain,
  21045. float endGain) throw()
  21046. {
  21047. jassert (((unsigned int) destChannel) < (unsigned int) numChannels);
  21048. jassert (destStartSample >= 0 && destStartSample + numSamples <= size);
  21049. jassert (source != 0);
  21050. if (startGain == endGain)
  21051. {
  21052. copyFrom (destChannel,
  21053. destStartSample,
  21054. source,
  21055. numSamples,
  21056. startGain);
  21057. }
  21058. else
  21059. {
  21060. if (numSamples > 0 && (startGain != 0.0f || endGain != 0.0f))
  21061. {
  21062. const float increment = (endGain - startGain) / numSamples;
  21063. float* d = channels [destChannel] + destStartSample;
  21064. while (--numSamples >= 0)
  21065. {
  21066. *d++ = startGain * *source++;
  21067. startGain += increment;
  21068. }
  21069. }
  21070. }
  21071. }
  21072. void AudioSampleBuffer::findMinMax (const int channel,
  21073. const int startSample,
  21074. int numSamples,
  21075. float& minVal,
  21076. float& maxVal) const throw()
  21077. {
  21078. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21079. jassert (startSample >= 0 && startSample + numSamples <= size);
  21080. if (numSamples <= 0)
  21081. {
  21082. minVal = 0.0f;
  21083. maxVal = 0.0f;
  21084. }
  21085. else
  21086. {
  21087. const float* d = channels [channel] + startSample;
  21088. float mn = *d++;
  21089. float mx = mn;
  21090. while (--numSamples > 0) // (> 0 rather than >= 0 because we've already taken the first sample)
  21091. {
  21092. const float samp = *d++;
  21093. if (samp > mx)
  21094. mx = samp;
  21095. if (samp < mn)
  21096. mn = samp;
  21097. }
  21098. maxVal = mx;
  21099. minVal = mn;
  21100. }
  21101. }
  21102. float AudioSampleBuffer::getMagnitude (const int channel,
  21103. const int startSample,
  21104. const int numSamples) const throw()
  21105. {
  21106. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21107. jassert (startSample >= 0 && startSample + numSamples <= size);
  21108. float mn, mx;
  21109. findMinMax (channel, startSample, numSamples, mn, mx);
  21110. return jmax (mn, -mn, mx, -mx);
  21111. }
  21112. float AudioSampleBuffer::getMagnitude (const int startSample,
  21113. const int numSamples) const throw()
  21114. {
  21115. float mag = 0.0f;
  21116. for (int i = 0; i < numChannels; ++i)
  21117. mag = jmax (mag, getMagnitude (i, startSample, numSamples));
  21118. return mag;
  21119. }
  21120. float AudioSampleBuffer::getRMSLevel (const int channel,
  21121. const int startSample,
  21122. const int numSamples) const throw()
  21123. {
  21124. jassert (((unsigned int) channel) < (unsigned int) numChannels);
  21125. jassert (startSample >= 0 && startSample + numSamples <= size);
  21126. if (numSamples <= 0 || channel < 0 || channel >= numChannels)
  21127. return 0.0f;
  21128. const float* const data = channels [channel] + startSample;
  21129. double sum = 0.0;
  21130. for (int i = 0; i < numSamples; ++i)
  21131. {
  21132. const float sample = data [i];
  21133. sum += sample * sample;
  21134. }
  21135. return (float) sqrt (sum / numSamples);
  21136. }
  21137. void AudioSampleBuffer::readFromAudioReader (AudioFormatReader* reader,
  21138. const int startSample,
  21139. const int numSamples,
  21140. const int readerStartSample,
  21141. const bool useLeftChan,
  21142. const bool useRightChan) throw()
  21143. {
  21144. jassert (reader != 0);
  21145. jassert (startSample >= 0 && startSample + numSamples <= size);
  21146. if (numSamples > 0)
  21147. {
  21148. int* chans[3];
  21149. if (useLeftChan == useRightChan)
  21150. {
  21151. chans[0] = (int*) getSampleData (0, startSample);
  21152. chans[1] = (reader->numChannels > 1 && getNumChannels() > 1) ? (int*) getSampleData (1, startSample) : 0;
  21153. }
  21154. else if (useLeftChan || (reader->numChannels == 1))
  21155. {
  21156. chans[0] = (int*) getSampleData (0, startSample);
  21157. chans[1] = 0;
  21158. }
  21159. else if (useRightChan)
  21160. {
  21161. chans[0] = 0;
  21162. chans[1] = (int*) getSampleData (0, startSample);
  21163. }
  21164. chans[2] = 0;
  21165. reader->read (chans, 2, readerStartSample, numSamples, true);
  21166. if (! reader->usesFloatingPointData)
  21167. {
  21168. for (int j = 0; j < 2; ++j)
  21169. {
  21170. float* const d = (float*) (chans[j]);
  21171. if (d != 0)
  21172. {
  21173. const float multiplier = 1.0f / 0x7fffffff;
  21174. for (int i = 0; i < numSamples; ++i)
  21175. d[i] = *(int*)(d + i) * multiplier;
  21176. }
  21177. }
  21178. }
  21179. if (numChannels > 1 && (chans[0] == 0 || chans[1] == 0))
  21180. {
  21181. // if this is a stereo buffer and the source was mono, dupe the first channel..
  21182. memcpy (getSampleData (1, startSample),
  21183. getSampleData (0, startSample),
  21184. sizeof (float) * numSamples);
  21185. }
  21186. }
  21187. }
  21188. void AudioSampleBuffer::writeToAudioWriter (AudioFormatWriter* writer,
  21189. const int startSample,
  21190. const int numSamples) const throw()
  21191. {
  21192. jassert (startSample >= 0 && startSample + numSamples <= size);
  21193. if (numSamples > 0)
  21194. {
  21195. int* chans [3];
  21196. if (writer->isFloatingPoint())
  21197. {
  21198. chans[0] = (int*) getSampleData (0, startSample);
  21199. if (numChannels > 1)
  21200. chans[1] = (int*) getSampleData (1, startSample);
  21201. else
  21202. chans[1] = 0;
  21203. chans[2] = 0;
  21204. writer->write ((const int**) chans, numSamples);
  21205. }
  21206. else
  21207. {
  21208. HeapBlock <int> tempBuffer (numSamples * 2);
  21209. chans[0] = tempBuffer;
  21210. if (numChannels > 1)
  21211. chans[1] = chans[0] + numSamples;
  21212. else
  21213. chans[1] = 0;
  21214. chans[2] = 0;
  21215. for (int j = 0; j < 2; ++j)
  21216. {
  21217. int* const dest = chans[j];
  21218. if (dest != 0)
  21219. {
  21220. const float* const src = channels [j] + startSample;
  21221. for (int i = 0; i < numSamples; ++i)
  21222. {
  21223. const double samp = src[i];
  21224. if (samp <= -1.0)
  21225. dest[i] = std::numeric_limits<int>::min();
  21226. else if (samp >= 1.0)
  21227. dest[i] = std::numeric_limits<int>::max();
  21228. else
  21229. dest[i] = roundToInt (std::numeric_limits<int>::max() * samp);
  21230. }
  21231. }
  21232. }
  21233. writer->write ((const int**) chans, numSamples);
  21234. }
  21235. }
  21236. }
  21237. END_JUCE_NAMESPACE
  21238. /*** End of inlined file: juce_AudioSampleBuffer.cpp ***/
  21239. /*** Start of inlined file: juce_IIRFilter.cpp ***/
  21240. BEGIN_JUCE_NAMESPACE
  21241. IIRFilter::IIRFilter() throw()
  21242. : active (false)
  21243. {
  21244. reset();
  21245. }
  21246. IIRFilter::IIRFilter (const IIRFilter& other) throw()
  21247. : active (other.active)
  21248. {
  21249. const ScopedLock sl (other.processLock);
  21250. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21251. reset();
  21252. }
  21253. IIRFilter::~IIRFilter() throw()
  21254. {
  21255. }
  21256. void IIRFilter::reset() throw()
  21257. {
  21258. const ScopedLock sl (processLock);
  21259. x1 = 0;
  21260. x2 = 0;
  21261. y1 = 0;
  21262. y2 = 0;
  21263. }
  21264. float IIRFilter::processSingleSampleRaw (const float in) throw()
  21265. {
  21266. float out = coefficients[0] * in
  21267. + coefficients[1] * x1
  21268. + coefficients[2] * x2
  21269. - coefficients[4] * y1
  21270. - coefficients[5] * y2;
  21271. #if JUCE_INTEL
  21272. if (! (out < -1.0e-8 || out > 1.0e-8))
  21273. out = 0;
  21274. #endif
  21275. x2 = x1;
  21276. x1 = in;
  21277. y2 = y1;
  21278. y1 = out;
  21279. return out;
  21280. }
  21281. void IIRFilter::processSamples (float* const samples,
  21282. const int numSamples) throw()
  21283. {
  21284. const ScopedLock sl (processLock);
  21285. if (active)
  21286. {
  21287. for (int i = 0; i < numSamples; ++i)
  21288. {
  21289. const float in = samples[i];
  21290. float out = coefficients[0] * in
  21291. + coefficients[1] * x1
  21292. + coefficients[2] * x2
  21293. - coefficients[4] * y1
  21294. - coefficients[5] * y2;
  21295. #if JUCE_INTEL
  21296. if (! (out < -1.0e-8 || out > 1.0e-8))
  21297. out = 0;
  21298. #endif
  21299. x2 = x1;
  21300. x1 = in;
  21301. y2 = y1;
  21302. y1 = out;
  21303. samples[i] = out;
  21304. }
  21305. }
  21306. }
  21307. void IIRFilter::makeLowPass (const double sampleRate,
  21308. const double frequency) throw()
  21309. {
  21310. jassert (sampleRate > 0);
  21311. const double n = 1.0 / tan (double_Pi * frequency / sampleRate);
  21312. const double nSquared = n * n;
  21313. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21314. setCoefficients (c1,
  21315. c1 * 2.0f,
  21316. c1,
  21317. 1.0,
  21318. c1 * 2.0 * (1.0 - nSquared),
  21319. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21320. }
  21321. void IIRFilter::makeHighPass (const double sampleRate,
  21322. const double frequency) throw()
  21323. {
  21324. const double n = tan (double_Pi * frequency / sampleRate);
  21325. const double nSquared = n * n;
  21326. const double c1 = 1.0 / (1.0 + sqrt (2.0) * n + nSquared);
  21327. setCoefficients (c1,
  21328. c1 * -2.0f,
  21329. c1,
  21330. 1.0,
  21331. c1 * 2.0 * (nSquared - 1.0),
  21332. c1 * (1.0 - sqrt (2.0) * n + nSquared));
  21333. }
  21334. void IIRFilter::makeLowShelf (const double sampleRate,
  21335. const double cutOffFrequency,
  21336. const double Q,
  21337. const float gainFactor) throw()
  21338. {
  21339. jassert (sampleRate > 0);
  21340. jassert (Q > 0);
  21341. const double A = jmax (0.0f, gainFactor);
  21342. const double aminus1 = A - 1.0;
  21343. const double aplus1 = A + 1.0;
  21344. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21345. const double coso = cos (omega);
  21346. const double beta = sin (omega) * sqrt (A) / Q;
  21347. const double aminus1TimesCoso = aminus1 * coso;
  21348. setCoefficients (A * (aplus1 - aminus1TimesCoso + beta),
  21349. A * 2.0 * (aminus1 - aplus1 * coso),
  21350. A * (aplus1 - aminus1TimesCoso - beta),
  21351. aplus1 + aminus1TimesCoso + beta,
  21352. -2.0 * (aminus1 + aplus1 * coso),
  21353. aplus1 + aminus1TimesCoso - beta);
  21354. }
  21355. void IIRFilter::makeHighShelf (const double sampleRate,
  21356. const double cutOffFrequency,
  21357. const double Q,
  21358. const float gainFactor) throw()
  21359. {
  21360. jassert (sampleRate > 0);
  21361. jassert (Q > 0);
  21362. const double A = jmax (0.0f, gainFactor);
  21363. const double aminus1 = A - 1.0;
  21364. const double aplus1 = A + 1.0;
  21365. const double omega = (double_Pi * 2.0 * jmax (cutOffFrequency, 2.0)) / sampleRate;
  21366. const double coso = cos (omega);
  21367. const double beta = sin (omega) * sqrt (A) / Q;
  21368. const double aminus1TimesCoso = aminus1 * coso;
  21369. setCoefficients (A * (aplus1 + aminus1TimesCoso + beta),
  21370. A * -2.0 * (aminus1 + aplus1 * coso),
  21371. A * (aplus1 + aminus1TimesCoso - beta),
  21372. aplus1 - aminus1TimesCoso + beta,
  21373. 2.0 * (aminus1 - aplus1 * coso),
  21374. aplus1 - aminus1TimesCoso - beta);
  21375. }
  21376. void IIRFilter::makeBandPass (const double sampleRate,
  21377. const double centreFrequency,
  21378. const double Q,
  21379. const float gainFactor) throw()
  21380. {
  21381. jassert (sampleRate > 0);
  21382. jassert (Q > 0);
  21383. const double A = jmax (0.0f, gainFactor);
  21384. const double omega = (double_Pi * 2.0 * jmax (centreFrequency, 2.0)) / sampleRate;
  21385. const double alpha = 0.5 * sin (omega) / Q;
  21386. const double c2 = -2.0 * cos (omega);
  21387. const double alphaTimesA = alpha * A;
  21388. const double alphaOverA = alpha / A;
  21389. setCoefficients (1.0 + alphaTimesA,
  21390. c2,
  21391. 1.0 - alphaTimesA,
  21392. 1.0 + alphaOverA,
  21393. c2,
  21394. 1.0 - alphaOverA);
  21395. }
  21396. void IIRFilter::makeInactive() throw()
  21397. {
  21398. const ScopedLock sl (processLock);
  21399. active = false;
  21400. }
  21401. void IIRFilter::copyCoefficientsFrom (const IIRFilter& other) throw()
  21402. {
  21403. const ScopedLock sl (processLock);
  21404. memcpy (coefficients, other.coefficients, sizeof (coefficients));
  21405. active = other.active;
  21406. }
  21407. void IIRFilter::setCoefficients (double c1,
  21408. double c2,
  21409. double c3,
  21410. double c4,
  21411. double c5,
  21412. double c6) throw()
  21413. {
  21414. const double a = 1.0 / c4;
  21415. c1 *= a;
  21416. c2 *= a;
  21417. c3 *= a;
  21418. c5 *= a;
  21419. c6 *= a;
  21420. const ScopedLock sl (processLock);
  21421. coefficients[0] = (float) c1;
  21422. coefficients[1] = (float) c2;
  21423. coefficients[2] = (float) c3;
  21424. coefficients[3] = (float) c4;
  21425. coefficients[4] = (float) c5;
  21426. coefficients[5] = (float) c6;
  21427. active = true;
  21428. }
  21429. END_JUCE_NAMESPACE
  21430. /*** End of inlined file: juce_IIRFilter.cpp ***/
  21431. /*** Start of inlined file: juce_MidiBuffer.cpp ***/
  21432. BEGIN_JUCE_NAMESPACE
  21433. MidiBuffer::MidiBuffer() throw()
  21434. : bytesUsed (0)
  21435. {
  21436. }
  21437. MidiBuffer::MidiBuffer (const MidiMessage& message) throw()
  21438. : bytesUsed (0)
  21439. {
  21440. addEvent (message, 0);
  21441. }
  21442. MidiBuffer::MidiBuffer (const MidiBuffer& other) throw()
  21443. : data (other.data),
  21444. bytesUsed (other.bytesUsed)
  21445. {
  21446. }
  21447. MidiBuffer& MidiBuffer::operator= (const MidiBuffer& other) throw()
  21448. {
  21449. bytesUsed = other.bytesUsed;
  21450. data = other.data;
  21451. return *this;
  21452. }
  21453. void MidiBuffer::swap (MidiBuffer& other)
  21454. {
  21455. data.swapWith (other.data);
  21456. swapVariables <int> (bytesUsed, other.bytesUsed);
  21457. }
  21458. MidiBuffer::~MidiBuffer() throw()
  21459. {
  21460. }
  21461. void MidiBuffer::clear() throw()
  21462. {
  21463. bytesUsed = 0;
  21464. }
  21465. void MidiBuffer::clear (const int startSample,
  21466. const int numSamples) throw()
  21467. {
  21468. uint8* const start = findEventAfter (data, startSample - 1);
  21469. uint8* const end = findEventAfter (start, startSample + numSamples - 1);
  21470. if (end > start)
  21471. {
  21472. const size_t bytesToMove = (size_t) (bytesUsed - (end - (uint8*) data.getData()));
  21473. if (bytesToMove > 0)
  21474. memmove (start, end, bytesToMove);
  21475. bytesUsed -= (int) (end - start);
  21476. }
  21477. }
  21478. void MidiBuffer::addEvent (const MidiMessage& m,
  21479. const int sampleNumber) throw()
  21480. {
  21481. addEvent (m.getRawData(), m.getRawDataSize(), sampleNumber);
  21482. }
  21483. static int findActualEventLength (const uint8* const data,
  21484. const int maxBytes) throw()
  21485. {
  21486. unsigned int byte = (unsigned int) *data;
  21487. int size = 0;
  21488. if (byte == 0xf0 || byte == 0xf7)
  21489. {
  21490. const uint8* d = data + 1;
  21491. while (d < data + maxBytes)
  21492. if (*d++ == 0xf7)
  21493. break;
  21494. size = (int) (d - data);
  21495. }
  21496. else if (byte == 0xff)
  21497. {
  21498. int n;
  21499. const int bytesLeft = MidiMessage::readVariableLengthVal (data + 1, n);
  21500. size = jmin (maxBytes, n + 2 + bytesLeft);
  21501. }
  21502. else if (byte >= 0x80)
  21503. {
  21504. size = jmin (maxBytes, MidiMessage::getMessageLengthFromFirstByte ((uint8) byte));
  21505. }
  21506. return size;
  21507. }
  21508. void MidiBuffer::addEvent (const uint8* const newData,
  21509. const int maxBytes,
  21510. const int sampleNumber) throw()
  21511. {
  21512. const int numBytes = findActualEventLength (newData, maxBytes);
  21513. if (numBytes > 0)
  21514. {
  21515. int spaceNeeded = bytesUsed + numBytes + 6;
  21516. data.ensureSize ((spaceNeeded + spaceNeeded / 2 + 8) & ~7);
  21517. uint8* d = findEventAfter ((uint8*) data.getData(), sampleNumber);
  21518. const size_t bytesToMove = (size_t) (bytesUsed - (d - (uint8*) data.getData()));
  21519. if (bytesToMove > 0)
  21520. memmove (d + numBytes + 6,
  21521. d,
  21522. bytesToMove);
  21523. *(int*) d = sampleNumber;
  21524. d += 4;
  21525. *(uint16*) d = (uint16) numBytes;
  21526. d += 2;
  21527. memcpy (d, newData, numBytes);
  21528. bytesUsed += numBytes + 6;
  21529. }
  21530. }
  21531. void MidiBuffer::addEvents (const MidiBuffer& otherBuffer,
  21532. const int startSample,
  21533. const int numSamples,
  21534. const int sampleDeltaToAdd) throw()
  21535. {
  21536. Iterator i (otherBuffer);
  21537. i.setNextSamplePosition (startSample);
  21538. const uint8* eventData;
  21539. int eventSize, position;
  21540. while (i.getNextEvent (eventData, eventSize, position)
  21541. && (position < startSample + numSamples || numSamples < 0))
  21542. {
  21543. addEvent (eventData, eventSize, position + sampleDeltaToAdd);
  21544. }
  21545. }
  21546. bool MidiBuffer::isEmpty() const throw()
  21547. {
  21548. return bytesUsed == 0;
  21549. }
  21550. int MidiBuffer::getNumEvents() const throw()
  21551. {
  21552. int n = 0;
  21553. const uint8* d = (uint8*) data.getData();
  21554. const uint8* const end = d + bytesUsed;
  21555. while (d < end)
  21556. {
  21557. d += 4;
  21558. d += 2 + *(const uint16*) d;
  21559. ++n;
  21560. }
  21561. return n;
  21562. }
  21563. int MidiBuffer::getFirstEventTime() const throw()
  21564. {
  21565. return (bytesUsed > 0) ? *(const int*) data.getData() : 0;
  21566. }
  21567. int MidiBuffer::getLastEventTime() const throw()
  21568. {
  21569. if (bytesUsed == 0)
  21570. return 0;
  21571. const uint8* d = (uint8*) data.getData();
  21572. const uint8* const endData = d + bytesUsed;
  21573. for (;;)
  21574. {
  21575. const uint8* nextOne = d + 6 + * (const uint16*) (d + 4);
  21576. if (nextOne >= endData)
  21577. return *(const int*) d;
  21578. d = nextOne;
  21579. }
  21580. }
  21581. uint8* MidiBuffer::findEventAfter (uint8* d, const int samplePosition) const throw()
  21582. {
  21583. const uint8* const endData = ((uint8*) data.getData()) + bytesUsed;
  21584. while (d < endData && *(int*) d <= samplePosition)
  21585. {
  21586. d += 4;
  21587. d += 2 + *(uint16*) d;
  21588. }
  21589. return d;
  21590. }
  21591. MidiBuffer::Iterator::Iterator (const MidiBuffer& buffer_) throw()
  21592. : buffer (buffer_),
  21593. data ((uint8*) buffer_.data.getData())
  21594. {
  21595. }
  21596. MidiBuffer::Iterator::~Iterator() throw()
  21597. {
  21598. }
  21599. void MidiBuffer::Iterator::setNextSamplePosition (const int samplePosition) throw()
  21600. {
  21601. data = buffer.data;
  21602. const uint8* dataEnd = ((uint8*) buffer.data.getData()) + buffer.bytesUsed;
  21603. while (data < dataEnd && *(int*) data < samplePosition)
  21604. {
  21605. data += 4;
  21606. data += 2 + *(uint16*) data;
  21607. }
  21608. }
  21609. bool MidiBuffer::Iterator::getNextEvent (const uint8* &midiData,
  21610. int& numBytes,
  21611. int& samplePosition) throw()
  21612. {
  21613. if (data >= ((uint8*) buffer.data.getData()) + buffer.bytesUsed)
  21614. return false;
  21615. samplePosition = *(int*) data;
  21616. data += 4;
  21617. numBytes = *(uint16*) data;
  21618. data += 2;
  21619. midiData = data;
  21620. data += numBytes;
  21621. return true;
  21622. }
  21623. bool MidiBuffer::Iterator::getNextEvent (MidiMessage& result,
  21624. int& samplePosition) throw()
  21625. {
  21626. if (data >= ((uint8*) buffer.data.getData()) + buffer.bytesUsed)
  21627. return false;
  21628. samplePosition = *(int*) data;
  21629. data += 4;
  21630. const int numBytes = *(uint16*) data;
  21631. data += 2;
  21632. result = MidiMessage (data, numBytes, samplePosition);
  21633. data += numBytes;
  21634. return true;
  21635. }
  21636. END_JUCE_NAMESPACE
  21637. /*** End of inlined file: juce_MidiBuffer.cpp ***/
  21638. /*** Start of inlined file: juce_MidiFile.cpp ***/
  21639. BEGIN_JUCE_NAMESPACE
  21640. namespace MidiFileHelpers
  21641. {
  21642. static void writeVariableLengthInt (OutputStream& out, unsigned int v)
  21643. {
  21644. unsigned int buffer = v & 0x7F;
  21645. while ((v >>= 7) != 0)
  21646. {
  21647. buffer <<= 8;
  21648. buffer |= ((v & 0x7F) | 0x80);
  21649. }
  21650. for (;;)
  21651. {
  21652. out.writeByte ((char) buffer);
  21653. if (buffer & 0x80)
  21654. buffer >>= 8;
  21655. else
  21656. break;
  21657. }
  21658. }
  21659. static bool parseMidiHeader (const char* &data, short& timeFormat, short& fileType, short& numberOfTracks) throw()
  21660. {
  21661. unsigned int ch = (int) ByteOrder::bigEndianInt (data);
  21662. data += 4;
  21663. if (ch != ByteOrder::bigEndianInt ("MThd"))
  21664. {
  21665. bool ok = false;
  21666. if (ch == ByteOrder::bigEndianInt ("RIFF"))
  21667. {
  21668. for (int i = 0; i < 8; ++i)
  21669. {
  21670. ch = ByteOrder::bigEndianInt (data);
  21671. data += 4;
  21672. if (ch == ByteOrder::bigEndianInt ("MThd"))
  21673. {
  21674. ok = true;
  21675. break;
  21676. }
  21677. }
  21678. }
  21679. if (! ok)
  21680. return false;
  21681. }
  21682. unsigned int bytesRemaining = ByteOrder::bigEndianInt (data);
  21683. data += 4;
  21684. fileType = (short) ByteOrder::bigEndianShort (data);
  21685. data += 2;
  21686. numberOfTracks = (short) ByteOrder::bigEndianShort (data);
  21687. data += 2;
  21688. timeFormat = (short) ByteOrder::bigEndianShort (data);
  21689. data += 2;
  21690. bytesRemaining -= 6;
  21691. data += bytesRemaining;
  21692. return true;
  21693. }
  21694. static double convertTicksToSeconds (const double time,
  21695. const MidiMessageSequence& tempoEvents,
  21696. const int timeFormat)
  21697. {
  21698. if (timeFormat > 0)
  21699. {
  21700. int numer = 4, denom = 4;
  21701. double tempoTime = 0.0, correctedTempoTime = 0.0;
  21702. const double tickLen = 1.0 / (timeFormat & 0x7fff);
  21703. double secsPerTick = 0.5 * tickLen;
  21704. const int numEvents = tempoEvents.getNumEvents();
  21705. for (int i = 0; i < numEvents; ++i)
  21706. {
  21707. const MidiMessage& m = tempoEvents.getEventPointer(i)->message;
  21708. if (time <= m.getTimeStamp())
  21709. break;
  21710. if (timeFormat > 0)
  21711. {
  21712. correctedTempoTime = correctedTempoTime
  21713. + (m.getTimeStamp() - tempoTime) * secsPerTick;
  21714. }
  21715. else
  21716. {
  21717. correctedTempoTime = tickLen * m.getTimeStamp() / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21718. }
  21719. tempoTime = m.getTimeStamp();
  21720. if (m.isTempoMetaEvent())
  21721. secsPerTick = tickLen * m.getTempoSecondsPerQuarterNote();
  21722. else if (m.isTimeSignatureMetaEvent())
  21723. m.getTimeSignatureInfo (numer, denom);
  21724. while (i + 1 < numEvents)
  21725. {
  21726. const MidiMessage& m2 = tempoEvents.getEventPointer(i + 1)->message;
  21727. if (m2.getTimeStamp() == tempoTime)
  21728. {
  21729. ++i;
  21730. if (m2.isTempoMetaEvent())
  21731. secsPerTick = tickLen * m2.getTempoSecondsPerQuarterNote();
  21732. else if (m2.isTimeSignatureMetaEvent())
  21733. m2.getTimeSignatureInfo (numer, denom);
  21734. }
  21735. else
  21736. {
  21737. break;
  21738. }
  21739. }
  21740. }
  21741. return correctedTempoTime + (time - tempoTime) * secsPerTick;
  21742. }
  21743. else
  21744. {
  21745. return time / (((timeFormat & 0x7fff) >> 8) * (timeFormat & 0xff));
  21746. }
  21747. }
  21748. }
  21749. MidiFile::MidiFile() throw()
  21750. : timeFormat ((short) (unsigned short) 0xe728)
  21751. {
  21752. }
  21753. MidiFile::~MidiFile() throw()
  21754. {
  21755. clear();
  21756. }
  21757. void MidiFile::clear() throw()
  21758. {
  21759. tracks.clear();
  21760. }
  21761. int MidiFile::getNumTracks() const throw()
  21762. {
  21763. return tracks.size();
  21764. }
  21765. const MidiMessageSequence* MidiFile::getTrack (const int index) const throw()
  21766. {
  21767. return tracks [index];
  21768. }
  21769. void MidiFile::addTrack (const MidiMessageSequence& trackSequence) throw()
  21770. {
  21771. tracks.add (new MidiMessageSequence (trackSequence));
  21772. }
  21773. short MidiFile::getTimeFormat() const throw()
  21774. {
  21775. return timeFormat;
  21776. }
  21777. void MidiFile::setTicksPerQuarterNote (const int ticks) throw()
  21778. {
  21779. timeFormat = (short)ticks;
  21780. }
  21781. void MidiFile::setSmpteTimeFormat (const int framesPerSecond,
  21782. const int subframeResolution) throw()
  21783. {
  21784. timeFormat = (short) (((-framesPerSecond) << 8) | subframeResolution);
  21785. }
  21786. void MidiFile::findAllTempoEvents (MidiMessageSequence& tempoChangeEvents) const
  21787. {
  21788. for (int i = tracks.size(); --i >= 0;)
  21789. {
  21790. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21791. for (int j = 0; j < numEvents; ++j)
  21792. {
  21793. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21794. if (m.isTempoMetaEvent())
  21795. tempoChangeEvents.addEvent (m);
  21796. }
  21797. }
  21798. }
  21799. void MidiFile::findAllTimeSigEvents (MidiMessageSequence& timeSigEvents) const
  21800. {
  21801. for (int i = tracks.size(); --i >= 0;)
  21802. {
  21803. const int numEvents = tracks.getUnchecked(i)->getNumEvents();
  21804. for (int j = 0; j < numEvents; ++j)
  21805. {
  21806. const MidiMessage& m = tracks.getUnchecked(i)->getEventPointer (j)->message;
  21807. if (m.isTimeSignatureMetaEvent())
  21808. timeSigEvents.addEvent (m);
  21809. }
  21810. }
  21811. }
  21812. double MidiFile::getLastTimestamp() const
  21813. {
  21814. double t = 0.0;
  21815. for (int i = tracks.size(); --i >= 0;)
  21816. t = jmax (t, tracks.getUnchecked(i)->getEndTime());
  21817. return t;
  21818. }
  21819. bool MidiFile::readFrom (InputStream& sourceStream)
  21820. {
  21821. clear();
  21822. MemoryBlock data;
  21823. const int maxSensibleMidiFileSize = 2 * 1024 * 1024;
  21824. // (put a sanity-check on the file size, as midi files are generally small)
  21825. if (sourceStream.readIntoMemoryBlock (data, maxSensibleMidiFileSize))
  21826. {
  21827. size_t size = data.getSize();
  21828. const char* d = (char*) data.getData();
  21829. short fileType, expectedTracks;
  21830. if (size > 16 && MidiFileHelpers::parseMidiHeader (d, timeFormat, fileType, expectedTracks))
  21831. {
  21832. size -= (int) (d - (char*) data.getData());
  21833. int track = 0;
  21834. while (size > 0 && track < expectedTracks)
  21835. {
  21836. const int chunkType = (int) ByteOrder::bigEndianInt (d);
  21837. d += 4;
  21838. const int chunkSize = (int) ByteOrder::bigEndianInt (d);
  21839. d += 4;
  21840. if (chunkSize <= 0)
  21841. break;
  21842. if (size < 0)
  21843. return false;
  21844. if (chunkType == (int) ByteOrder::bigEndianInt ("MTrk"))
  21845. {
  21846. readNextTrack (d, chunkSize);
  21847. }
  21848. size -= chunkSize + 8;
  21849. d += chunkSize;
  21850. ++track;
  21851. }
  21852. return true;
  21853. }
  21854. }
  21855. return false;
  21856. }
  21857. // a comparator that puts all the note-offs before note-ons that have the same time
  21858. int MidiFile::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  21859. const MidiMessageSequence::MidiEventHolder* const second) throw()
  21860. {
  21861. const double diff = (first->message.getTimeStamp() - second->message.getTimeStamp());
  21862. if (diff == 0)
  21863. {
  21864. if (first->message.isNoteOff() && second->message.isNoteOn())
  21865. return -1;
  21866. else if (first->message.isNoteOn() && second->message.isNoteOff())
  21867. return 1;
  21868. else
  21869. return 0;
  21870. }
  21871. else
  21872. {
  21873. return (diff > 0) ? 1 : -1;
  21874. }
  21875. }
  21876. void MidiFile::readNextTrack (const char* data, int size)
  21877. {
  21878. double time = 0;
  21879. char lastStatusByte = 0;
  21880. MidiMessageSequence result;
  21881. while (size > 0)
  21882. {
  21883. int bytesUsed;
  21884. const int delay = MidiMessage::readVariableLengthVal ((const uint8*) data, bytesUsed);
  21885. data += bytesUsed;
  21886. size -= bytesUsed;
  21887. time += delay;
  21888. int messSize = 0;
  21889. const MidiMessage mm ((const uint8*) data, size, messSize, lastStatusByte, time);
  21890. if (messSize <= 0)
  21891. break;
  21892. size -= messSize;
  21893. data += messSize;
  21894. result.addEvent (mm);
  21895. const char firstByte = *(mm.getRawData());
  21896. if ((firstByte & 0xf0) != 0xf0)
  21897. lastStatusByte = firstByte;
  21898. }
  21899. // use a sort that puts all the note-offs before note-ons that have the same time
  21900. result.list.sort (*this, true);
  21901. result.updateMatchedPairs();
  21902. addTrack (result);
  21903. }
  21904. void MidiFile::convertTimestampTicksToSeconds()
  21905. {
  21906. MidiMessageSequence tempoEvents;
  21907. findAllTempoEvents (tempoEvents);
  21908. findAllTimeSigEvents (tempoEvents);
  21909. for (int i = 0; i < tracks.size(); ++i)
  21910. {
  21911. MidiMessageSequence& ms = *tracks.getUnchecked(i);
  21912. for (int j = ms.getNumEvents(); --j >= 0;)
  21913. {
  21914. MidiMessage& m = ms.getEventPointer(j)->message;
  21915. m.setTimeStamp (MidiFileHelpers::convertTicksToSeconds (m.getTimeStamp(),
  21916. tempoEvents,
  21917. timeFormat));
  21918. }
  21919. }
  21920. }
  21921. bool MidiFile::writeTo (OutputStream& out)
  21922. {
  21923. out.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MThd"));
  21924. out.writeIntBigEndian (6);
  21925. out.writeShortBigEndian (1); // type
  21926. out.writeShortBigEndian ((short) tracks.size());
  21927. out.writeShortBigEndian (timeFormat);
  21928. for (int i = 0; i < tracks.size(); ++i)
  21929. writeTrack (out, i);
  21930. out.flush();
  21931. return true;
  21932. }
  21933. void MidiFile::writeTrack (OutputStream& mainOut,
  21934. const int trackNum)
  21935. {
  21936. MemoryOutputStream out;
  21937. const MidiMessageSequence& ms = *tracks[trackNum];
  21938. int lastTick = 0;
  21939. char lastStatusByte = 0;
  21940. for (int i = 0; i < ms.getNumEvents(); ++i)
  21941. {
  21942. const MidiMessage& mm = ms.getEventPointer(i)->message;
  21943. const int tick = roundToInt (mm.getTimeStamp());
  21944. const int delta = jmax (0, tick - lastTick);
  21945. MidiFileHelpers::writeVariableLengthInt (out, delta);
  21946. lastTick = tick;
  21947. const char statusByte = *(mm.getRawData());
  21948. if ((statusByte == lastStatusByte)
  21949. && ((statusByte & 0xf0) != 0xf0)
  21950. && i > 0
  21951. && mm.getRawDataSize() > 1)
  21952. {
  21953. out.write (mm.getRawData() + 1, mm.getRawDataSize() - 1);
  21954. }
  21955. else
  21956. {
  21957. out.write (mm.getRawData(), mm.getRawDataSize());
  21958. }
  21959. lastStatusByte = statusByte;
  21960. }
  21961. out.writeByte (0);
  21962. const MidiMessage m (MidiMessage::endOfTrack());
  21963. out.write (m.getRawData(),
  21964. m.getRawDataSize());
  21965. mainOut.writeIntBigEndian ((int) ByteOrder::bigEndianInt ("MTrk"));
  21966. mainOut.writeIntBigEndian ((int) out.getDataSize());
  21967. mainOut.write (out.getData(), (int) out.getDataSize());
  21968. }
  21969. END_JUCE_NAMESPACE
  21970. /*** End of inlined file: juce_MidiFile.cpp ***/
  21971. /*** Start of inlined file: juce_MidiKeyboardState.cpp ***/
  21972. BEGIN_JUCE_NAMESPACE
  21973. MidiKeyboardState::MidiKeyboardState()
  21974. {
  21975. zeromem (noteStates, sizeof (noteStates));
  21976. }
  21977. MidiKeyboardState::~MidiKeyboardState()
  21978. {
  21979. }
  21980. void MidiKeyboardState::reset()
  21981. {
  21982. const ScopedLock sl (lock);
  21983. zeromem (noteStates, sizeof (noteStates));
  21984. eventsToAdd.clear();
  21985. }
  21986. bool MidiKeyboardState::isNoteOn (const int midiChannel, const int n) const throw()
  21987. {
  21988. jassert (midiChannel >= 0 && midiChannel <= 16);
  21989. return ((unsigned int) n) < 128
  21990. && (noteStates[n] & (1 << (midiChannel - 1))) != 0;
  21991. }
  21992. bool MidiKeyboardState::isNoteOnForChannels (const int midiChannelMask, const int n) const throw()
  21993. {
  21994. return ((unsigned int) n) < 128
  21995. && (noteStates[n] & midiChannelMask) != 0;
  21996. }
  21997. void MidiKeyboardState::noteOn (const int midiChannel, const int midiNoteNumber, const float velocity)
  21998. {
  21999. jassert (midiChannel >= 0 && midiChannel <= 16);
  22000. jassert (((unsigned int) midiNoteNumber) < 128);
  22001. const ScopedLock sl (lock);
  22002. if (((unsigned int) midiNoteNumber) < 128)
  22003. {
  22004. const int timeNow = (int) Time::getMillisecondCounter();
  22005. eventsToAdd.addEvent (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity), timeNow);
  22006. eventsToAdd.clear (0, timeNow - 500);
  22007. noteOnInternal (midiChannel, midiNoteNumber, velocity);
  22008. }
  22009. }
  22010. void MidiKeyboardState::noteOnInternal (const int midiChannel, const int midiNoteNumber, const float velocity)
  22011. {
  22012. if (((unsigned int) midiNoteNumber) < 128)
  22013. {
  22014. noteStates [midiNoteNumber] |= (1 << (midiChannel - 1));
  22015. for (int i = listeners.size(); --i >= 0;)
  22016. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  22017. ->handleNoteOn (this, midiChannel, midiNoteNumber, velocity);
  22018. }
  22019. }
  22020. void MidiKeyboardState::noteOff (const int midiChannel, const int midiNoteNumber)
  22021. {
  22022. const ScopedLock sl (lock);
  22023. if (isNoteOn (midiChannel, midiNoteNumber))
  22024. {
  22025. const int timeNow = (int) Time::getMillisecondCounter();
  22026. eventsToAdd.addEvent (MidiMessage::noteOff (midiChannel, midiNoteNumber), timeNow);
  22027. eventsToAdd.clear (0, timeNow - 500);
  22028. noteOffInternal (midiChannel, midiNoteNumber);
  22029. }
  22030. }
  22031. void MidiKeyboardState::noteOffInternal (const int midiChannel, const int midiNoteNumber)
  22032. {
  22033. if (isNoteOn (midiChannel, midiNoteNumber))
  22034. {
  22035. noteStates [midiNoteNumber] &= ~(1 << (midiChannel - 1));
  22036. for (int i = listeners.size(); --i >= 0;)
  22037. ((MidiKeyboardStateListener*) listeners.getUnchecked(i))
  22038. ->handleNoteOff (this, midiChannel, midiNoteNumber);
  22039. }
  22040. }
  22041. void MidiKeyboardState::allNotesOff (const int midiChannel)
  22042. {
  22043. const ScopedLock sl (lock);
  22044. if (midiChannel <= 0)
  22045. {
  22046. for (int i = 1; i <= 16; ++i)
  22047. allNotesOff (i);
  22048. }
  22049. else
  22050. {
  22051. for (int i = 0; i < 128; ++i)
  22052. noteOff (midiChannel, i);
  22053. }
  22054. }
  22055. void MidiKeyboardState::processNextMidiEvent (const MidiMessage& message)
  22056. {
  22057. if (message.isNoteOn())
  22058. {
  22059. noteOnInternal (message.getChannel(), message.getNoteNumber(), message.getFloatVelocity());
  22060. }
  22061. else if (message.isNoteOff())
  22062. {
  22063. noteOffInternal (message.getChannel(), message.getNoteNumber());
  22064. }
  22065. else if (message.isAllNotesOff())
  22066. {
  22067. for (int i = 0; i < 128; ++i)
  22068. noteOffInternal (message.getChannel(), i);
  22069. }
  22070. }
  22071. void MidiKeyboardState::processNextMidiBuffer (MidiBuffer& buffer,
  22072. const int startSample,
  22073. const int numSamples,
  22074. const bool injectIndirectEvents)
  22075. {
  22076. MidiBuffer::Iterator i (buffer);
  22077. MidiMessage message (0xf4, 0.0);
  22078. int time;
  22079. const ScopedLock sl (lock);
  22080. while (i.getNextEvent (message, time))
  22081. processNextMidiEvent (message);
  22082. if (injectIndirectEvents)
  22083. {
  22084. MidiBuffer::Iterator i2 (eventsToAdd);
  22085. const int firstEventToAdd = eventsToAdd.getFirstEventTime();
  22086. const double scaleFactor = numSamples / (double) (eventsToAdd.getLastEventTime() + 1 - firstEventToAdd);
  22087. while (i2.getNextEvent (message, time))
  22088. {
  22089. const int pos = jlimit (0, numSamples - 1, roundToInt ((time - firstEventToAdd) * scaleFactor));
  22090. buffer.addEvent (message, startSample + pos);
  22091. }
  22092. }
  22093. eventsToAdd.clear();
  22094. }
  22095. void MidiKeyboardState::addListener (MidiKeyboardStateListener* const listener) throw()
  22096. {
  22097. const ScopedLock sl (lock);
  22098. listeners.addIfNotAlreadyThere (listener);
  22099. }
  22100. void MidiKeyboardState::removeListener (MidiKeyboardStateListener* const listener) throw()
  22101. {
  22102. const ScopedLock sl (lock);
  22103. listeners.removeValue (listener);
  22104. }
  22105. END_JUCE_NAMESPACE
  22106. /*** End of inlined file: juce_MidiKeyboardState.cpp ***/
  22107. /*** Start of inlined file: juce_MidiMessage.cpp ***/
  22108. BEGIN_JUCE_NAMESPACE
  22109. int MidiMessage::readVariableLengthVal (const uint8* data,
  22110. int& numBytesUsed) throw()
  22111. {
  22112. numBytesUsed = 0;
  22113. int v = 0;
  22114. int i;
  22115. do
  22116. {
  22117. i = (int) *data++;
  22118. if (++numBytesUsed > 6)
  22119. break;
  22120. v = (v << 7) + (i & 0x7f);
  22121. } while (i & 0x80);
  22122. return v;
  22123. }
  22124. int MidiMessage::getMessageLengthFromFirstByte (const uint8 firstByte) throw()
  22125. {
  22126. // this method only works for valid starting bytes of a short midi message
  22127. jassert (firstByte >= 0x80
  22128. && firstByte != 0xf0
  22129. && firstByte != 0xf7);
  22130. static const char messageLengths[] =
  22131. {
  22132. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22133. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22134. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22135. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22136. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22137. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  22138. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  22139. 1, 2, 3, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
  22140. };
  22141. return messageLengths [firstByte & 0x7f];
  22142. }
  22143. MidiMessage::MidiMessage (const uint8* const d,
  22144. const int dataSize,
  22145. const double t) throw()
  22146. : timeStamp (t),
  22147. message (0),
  22148. size (dataSize)
  22149. {
  22150. jassert (dataSize > 0);
  22151. if (dataSize <= 4)
  22152. data = (uint8*) &message;
  22153. else
  22154. data = (uint8*) juce_malloc (dataSize);
  22155. memcpy (data, d, dataSize);
  22156. // check that the length matches the data..
  22157. jassert (size > 3 || *d >= 0xf0 || getMessageLengthFromFirstByte (*d) == size);
  22158. }
  22159. MidiMessage::MidiMessage (const int byte1,
  22160. const double t) throw()
  22161. : timeStamp (t),
  22162. data ((uint8*) &message),
  22163. size (1)
  22164. {
  22165. data[0] = (uint8) byte1;
  22166. // check that the length matches the data..
  22167. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 1);
  22168. }
  22169. MidiMessage::MidiMessage (const int byte1,
  22170. const int byte2,
  22171. const double t) throw()
  22172. : timeStamp (t),
  22173. data ((uint8*) &message),
  22174. size (2)
  22175. {
  22176. data[0] = (uint8) byte1;
  22177. data[1] = (uint8) byte2;
  22178. // check that the length matches the data..
  22179. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 2);
  22180. }
  22181. MidiMessage::MidiMessage (const int byte1,
  22182. const int byte2,
  22183. const int byte3,
  22184. const double t) throw()
  22185. : timeStamp (t),
  22186. data ((uint8*) &message),
  22187. size (3)
  22188. {
  22189. data[0] = (uint8) byte1;
  22190. data[1] = (uint8) byte2;
  22191. data[2] = (uint8) byte3;
  22192. // check that the length matches the data..
  22193. jassert (byte1 >= 0xf0 || getMessageLengthFromFirstByte ((uint8) byte1) == 3);
  22194. }
  22195. MidiMessage::MidiMessage (const MidiMessage& other) throw()
  22196. : timeStamp (other.timeStamp),
  22197. message (other.message),
  22198. size (other.size)
  22199. {
  22200. if (other.data != (uint8*) &other.message)
  22201. {
  22202. data = (uint8*) juce_malloc (size);
  22203. memcpy (data, other.data, size);
  22204. }
  22205. else
  22206. {
  22207. data = (uint8*) &message;
  22208. }
  22209. }
  22210. MidiMessage::MidiMessage (const MidiMessage& other,
  22211. const double newTimeStamp) throw()
  22212. : timeStamp (newTimeStamp),
  22213. message (other.message),
  22214. size (other.size)
  22215. {
  22216. if (other.data != (uint8*) &other.message)
  22217. {
  22218. data = (uint8*) juce_malloc (size);
  22219. memcpy (data, other.data, size);
  22220. }
  22221. else
  22222. {
  22223. data = (uint8*) &message;
  22224. }
  22225. }
  22226. MidiMessage::MidiMessage (const uint8* src,
  22227. int sz,
  22228. int& numBytesUsed,
  22229. const uint8 lastStatusByte,
  22230. double t) throw()
  22231. : timeStamp (t),
  22232. data ((uint8*) &message),
  22233. message (0)
  22234. {
  22235. unsigned int byte = (unsigned int) *src;
  22236. if (byte < 0x80)
  22237. {
  22238. byte = (unsigned int) (uint8) lastStatusByte;
  22239. numBytesUsed = -1;
  22240. }
  22241. else
  22242. {
  22243. numBytesUsed = 0;
  22244. --sz;
  22245. ++src;
  22246. }
  22247. if (byte >= 0x80)
  22248. {
  22249. if (byte == 0xf0)
  22250. {
  22251. const uint8* d = (const uint8*) src;
  22252. while (d < src + sz)
  22253. {
  22254. if (*d >= 0x80) // stop if we hit a status byte, and don't include it in this message
  22255. {
  22256. if (*d == 0xf7) // include an 0xf7 if we hit one
  22257. ++d;
  22258. break;
  22259. }
  22260. ++d;
  22261. }
  22262. size = 1 + (int) (d - src);
  22263. data = (uint8*) juce_malloc (size);
  22264. *data = (uint8) byte;
  22265. memcpy (data + 1, src, size - 1);
  22266. }
  22267. else if (byte == 0xff)
  22268. {
  22269. int n;
  22270. const int bytesLeft = readVariableLengthVal (src + 1, n);
  22271. size = jmin (sz + 1, n + 2 + bytesLeft);
  22272. data = (uint8*) juce_malloc (size);
  22273. *data = (uint8) byte;
  22274. memcpy (data + 1, src, size - 1);
  22275. }
  22276. else
  22277. {
  22278. size = getMessageLengthFromFirstByte ((uint8) byte);
  22279. *data = (uint8) byte;
  22280. if (size > 1)
  22281. {
  22282. data[1] = src[0];
  22283. if (size > 2)
  22284. data[2] = src[1];
  22285. }
  22286. }
  22287. numBytesUsed += size;
  22288. }
  22289. else
  22290. {
  22291. message = 0;
  22292. size = 0;
  22293. }
  22294. }
  22295. MidiMessage& MidiMessage::operator= (const MidiMessage& other) throw()
  22296. {
  22297. if (this != &other)
  22298. {
  22299. timeStamp = other.timeStamp;
  22300. size = other.size;
  22301. message = other.message;
  22302. if (data != (uint8*) &message)
  22303. juce_free (data);
  22304. if (other.data != (uint8*) &other.message)
  22305. {
  22306. data = (uint8*) juce_malloc (size);
  22307. memcpy (data, other.data, size);
  22308. }
  22309. else
  22310. {
  22311. data = (uint8*) &message;
  22312. }
  22313. }
  22314. return *this;
  22315. }
  22316. MidiMessage::~MidiMessage() throw()
  22317. {
  22318. if (data != (uint8*) &message)
  22319. juce_free (data);
  22320. }
  22321. int MidiMessage::getChannel() const throw()
  22322. {
  22323. if ((data[0] & 0xf0) != 0xf0)
  22324. return (data[0] & 0xf) + 1;
  22325. else
  22326. return 0;
  22327. }
  22328. bool MidiMessage::isForChannel (const int channel) const throw()
  22329. {
  22330. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22331. return ((data[0] & 0xf) == channel - 1)
  22332. && ((data[0] & 0xf0) != 0xf0);
  22333. }
  22334. void MidiMessage::setChannel (const int channel) throw()
  22335. {
  22336. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22337. if ((data[0] & 0xf0) != (uint8) 0xf0)
  22338. data[0] = (uint8) ((data[0] & (uint8)0xf0)
  22339. | (uint8)(channel - 1));
  22340. }
  22341. bool MidiMessage::isNoteOn (const bool returnTrueForVelocity0) const throw()
  22342. {
  22343. return ((data[0] & 0xf0) == 0x90)
  22344. && (returnTrueForVelocity0 || data[2] != 0);
  22345. }
  22346. bool MidiMessage::isNoteOff (const bool returnTrueForNoteOnVelocity0) const throw()
  22347. {
  22348. return ((data[0] & 0xf0) == 0x80)
  22349. || (returnTrueForNoteOnVelocity0 && (data[2] == 0) && ((data[0] & 0xf0) == 0x90));
  22350. }
  22351. bool MidiMessage::isNoteOnOrOff() const throw()
  22352. {
  22353. const int d = data[0] & 0xf0;
  22354. return (d == 0x90) || (d == 0x80);
  22355. }
  22356. int MidiMessage::getNoteNumber() const throw()
  22357. {
  22358. return data[1];
  22359. }
  22360. void MidiMessage::setNoteNumber (const int newNoteNumber) throw()
  22361. {
  22362. if (isNoteOnOrOff())
  22363. data[1] = (uint8) jlimit (0, 127, newNoteNumber);
  22364. }
  22365. uint8 MidiMessage::getVelocity() const throw()
  22366. {
  22367. if (isNoteOnOrOff())
  22368. return data[2];
  22369. else
  22370. return 0;
  22371. }
  22372. float MidiMessage::getFloatVelocity() const throw()
  22373. {
  22374. return getVelocity() * (1.0f / 127.0f);
  22375. }
  22376. void MidiMessage::setVelocity (const float newVelocity) throw()
  22377. {
  22378. if (isNoteOnOrOff())
  22379. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (newVelocity * 127.0f));
  22380. }
  22381. void MidiMessage::multiplyVelocity (const float scaleFactor) throw()
  22382. {
  22383. if (isNoteOnOrOff())
  22384. data[2] = (uint8) jlimit (0, 0x7f, roundToInt (scaleFactor * data[2]));
  22385. }
  22386. bool MidiMessage::isAftertouch() const throw()
  22387. {
  22388. return (data[0] & 0xf0) == 0xa0;
  22389. }
  22390. int MidiMessage::getAfterTouchValue() const throw()
  22391. {
  22392. return data[2];
  22393. }
  22394. const MidiMessage MidiMessage::aftertouchChange (const int channel,
  22395. const int noteNum,
  22396. const int aftertouchValue) throw()
  22397. {
  22398. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22399. jassert (((unsigned int) noteNum) <= 127);
  22400. jassert (((unsigned int) aftertouchValue) <= 127);
  22401. return MidiMessage (0xa0 | jlimit (0, 15, channel - 1),
  22402. noteNum & 0x7f,
  22403. aftertouchValue & 0x7f);
  22404. }
  22405. bool MidiMessage::isChannelPressure() const throw()
  22406. {
  22407. return (data[0] & 0xf0) == 0xd0;
  22408. }
  22409. int MidiMessage::getChannelPressureValue() const throw()
  22410. {
  22411. jassert (isChannelPressure());
  22412. return data[1];
  22413. }
  22414. const MidiMessage MidiMessage::channelPressureChange (const int channel,
  22415. const int pressure) throw()
  22416. {
  22417. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22418. jassert (((unsigned int) pressure) <= 127);
  22419. return MidiMessage (0xd0 | jlimit (0, 15, channel - 1),
  22420. pressure & 0x7f);
  22421. }
  22422. bool MidiMessage::isProgramChange() const throw()
  22423. {
  22424. return (data[0] & 0xf0) == 0xc0;
  22425. }
  22426. int MidiMessage::getProgramChangeNumber() const throw()
  22427. {
  22428. return data[1];
  22429. }
  22430. const MidiMessage MidiMessage::programChange (const int channel,
  22431. const int programNumber) throw()
  22432. {
  22433. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22434. return MidiMessage (0xc0 | jlimit (0, 15, channel - 1),
  22435. programNumber & 0x7f);
  22436. }
  22437. bool MidiMessage::isPitchWheel() const throw()
  22438. {
  22439. return (data[0] & 0xf0) == 0xe0;
  22440. }
  22441. int MidiMessage::getPitchWheelValue() const throw()
  22442. {
  22443. return data[1] | (data[2] << 7);
  22444. }
  22445. const MidiMessage MidiMessage::pitchWheel (const int channel,
  22446. const int position) throw()
  22447. {
  22448. jassert (channel > 0 && channel <= 16); // valid channels are numbered 1 to 16
  22449. jassert (((unsigned int) position) <= 0x3fff);
  22450. return MidiMessage (0xe0 | jlimit (0, 15, channel - 1),
  22451. position & 127,
  22452. (position >> 7) & 127);
  22453. }
  22454. bool MidiMessage::isController() const throw()
  22455. {
  22456. return (data[0] & 0xf0) == 0xb0;
  22457. }
  22458. int MidiMessage::getControllerNumber() const throw()
  22459. {
  22460. jassert (isController());
  22461. return data[1];
  22462. }
  22463. int MidiMessage::getControllerValue() const throw()
  22464. {
  22465. jassert (isController());
  22466. return data[2];
  22467. }
  22468. const MidiMessage MidiMessage::controllerEvent (const int channel,
  22469. const int controllerType,
  22470. const int value) throw()
  22471. {
  22472. // the channel must be between 1 and 16 inclusive
  22473. jassert (channel > 0 && channel <= 16);
  22474. return MidiMessage (0xb0 | jlimit (0, 15, channel - 1),
  22475. controllerType & 127,
  22476. value & 127);
  22477. }
  22478. const MidiMessage MidiMessage::noteOn (const int channel,
  22479. const int noteNumber,
  22480. const float velocity) throw()
  22481. {
  22482. return noteOn (channel, noteNumber, (uint8)(velocity * 127.0f));
  22483. }
  22484. const MidiMessage MidiMessage::noteOn (const int channel,
  22485. const int noteNumber,
  22486. const uint8 velocity) throw()
  22487. {
  22488. jassert (channel > 0 && channel <= 16);
  22489. jassert (((unsigned int) noteNumber) <= 127);
  22490. return MidiMessage (0x90 | jlimit (0, 15, channel - 1),
  22491. noteNumber & 127,
  22492. jlimit (0, 127, roundToInt (velocity)));
  22493. }
  22494. const MidiMessage MidiMessage::noteOff (const int channel,
  22495. const int noteNumber) throw()
  22496. {
  22497. jassert (channel > 0 && channel <= 16);
  22498. jassert (((unsigned int) noteNumber) <= 127);
  22499. return MidiMessage (0x80 | jlimit (0, 15, channel - 1), noteNumber & 127, 0);
  22500. }
  22501. const MidiMessage MidiMessage::allNotesOff (const int channel) throw()
  22502. {
  22503. jassert (channel > 0 && channel <= 16);
  22504. return controllerEvent (channel, 123, 0);
  22505. }
  22506. bool MidiMessage::isAllNotesOff() const throw()
  22507. {
  22508. return (data[0] & 0xf0) == 0xb0
  22509. && data[1] == 123;
  22510. }
  22511. const MidiMessage MidiMessage::allSoundOff (const int channel) throw()
  22512. {
  22513. return controllerEvent (channel, 120, 0);
  22514. }
  22515. bool MidiMessage::isAllSoundOff() const throw()
  22516. {
  22517. return (data[0] & 0xf0) == 0xb0
  22518. && data[1] == 120;
  22519. }
  22520. const MidiMessage MidiMessage::allControllersOff (const int channel) throw()
  22521. {
  22522. return controllerEvent (channel, 121, 0);
  22523. }
  22524. const MidiMessage MidiMessage::masterVolume (const float volume) throw()
  22525. {
  22526. const int vol = jlimit (0, 0x3fff, roundToInt (volume * 0x4000));
  22527. uint8 buf[8];
  22528. buf[0] = 0xf0;
  22529. buf[1] = 0x7f;
  22530. buf[2] = 0x7f;
  22531. buf[3] = 0x04;
  22532. buf[4] = 0x01;
  22533. buf[5] = (uint8) (vol & 0x7f);
  22534. buf[6] = (uint8) (vol >> 7);
  22535. buf[7] = 0xf7;
  22536. return MidiMessage (buf, 8);
  22537. }
  22538. bool MidiMessage::isSysEx() const throw()
  22539. {
  22540. return *data == 0xf0;
  22541. }
  22542. const MidiMessage MidiMessage::createSysExMessage (const uint8* sysexData,
  22543. const int dataSize) throw()
  22544. {
  22545. MemoryBlock mm (dataSize + 2);
  22546. uint8* const m = (uint8*) mm.getData();
  22547. m[0] = 0xf0;
  22548. memcpy (m + 1, sysexData, dataSize);
  22549. m[dataSize + 1] = 0xf7;
  22550. return MidiMessage (m, dataSize + 2);
  22551. }
  22552. const uint8* MidiMessage::getSysExData() const throw()
  22553. {
  22554. return (isSysEx()) ? getRawData() + 1
  22555. : 0;
  22556. }
  22557. int MidiMessage::getSysExDataSize() const throw()
  22558. {
  22559. return (isSysEx()) ? size - 2
  22560. : 0;
  22561. }
  22562. bool MidiMessage::isMetaEvent() const throw()
  22563. {
  22564. return *data == 0xff;
  22565. }
  22566. bool MidiMessage::isActiveSense() const throw()
  22567. {
  22568. return *data == 0xfe;
  22569. }
  22570. int MidiMessage::getMetaEventType() const throw()
  22571. {
  22572. if (*data != 0xff)
  22573. return -1;
  22574. else
  22575. return data[1];
  22576. }
  22577. int MidiMessage::getMetaEventLength() const throw()
  22578. {
  22579. if (*data == 0xff)
  22580. {
  22581. int n;
  22582. return jmin (size - 2, readVariableLengthVal (data + 2, n));
  22583. }
  22584. return 0;
  22585. }
  22586. const uint8* MidiMessage::getMetaEventData() const throw()
  22587. {
  22588. int n;
  22589. const uint8* d = data + 2;
  22590. readVariableLengthVal (d, n);
  22591. return d + n;
  22592. }
  22593. bool MidiMessage::isTrackMetaEvent() const throw()
  22594. {
  22595. return getMetaEventType() == 0;
  22596. }
  22597. bool MidiMessage::isEndOfTrackMetaEvent() const throw()
  22598. {
  22599. return getMetaEventType() == 47;
  22600. }
  22601. bool MidiMessage::isTextMetaEvent() const throw()
  22602. {
  22603. const int t = getMetaEventType();
  22604. return t > 0 && t < 16;
  22605. }
  22606. const String MidiMessage::getTextFromTextMetaEvent() const throw()
  22607. {
  22608. return String ((const char*) getMetaEventData(),
  22609. getMetaEventLength());
  22610. }
  22611. bool MidiMessage::isTrackNameEvent() const throw()
  22612. {
  22613. return (data[1] == 3)
  22614. && (*data == 0xff);
  22615. }
  22616. bool MidiMessage::isTempoMetaEvent() const throw()
  22617. {
  22618. return (data[1] == 81)
  22619. && (*data == 0xff);
  22620. }
  22621. bool MidiMessage::isMidiChannelMetaEvent() const throw()
  22622. {
  22623. return (data[1] == 0x20)
  22624. && (*data == 0xff)
  22625. && (data[2] == 1);
  22626. }
  22627. int MidiMessage::getMidiChannelMetaEventChannel() const throw()
  22628. {
  22629. return data[3] + 1;
  22630. }
  22631. double MidiMessage::getTempoSecondsPerQuarterNote() const throw()
  22632. {
  22633. if (! isTempoMetaEvent())
  22634. return 0.0;
  22635. const uint8* const d = getMetaEventData();
  22636. return (((unsigned int) d[0] << 16)
  22637. | ((unsigned int) d[1] << 8)
  22638. | d[2])
  22639. / 1000000.0;
  22640. }
  22641. double MidiMessage::getTempoMetaEventTickLength (const short timeFormat) const throw()
  22642. {
  22643. if (timeFormat > 0)
  22644. {
  22645. if (! isTempoMetaEvent())
  22646. return 0.5 / timeFormat;
  22647. return getTempoSecondsPerQuarterNote() / timeFormat;
  22648. }
  22649. else
  22650. {
  22651. const int frameCode = (-timeFormat) >> 8;
  22652. double framesPerSecond;
  22653. switch (frameCode)
  22654. {
  22655. case 24: framesPerSecond = 24.0; break;
  22656. case 25: framesPerSecond = 25.0; break;
  22657. case 29: framesPerSecond = 29.97; break;
  22658. case 30: framesPerSecond = 30.0; break;
  22659. default: framesPerSecond = 30.0; break;
  22660. }
  22661. return (1.0 / framesPerSecond) / (timeFormat & 0xff);
  22662. }
  22663. }
  22664. const MidiMessage MidiMessage::tempoMetaEvent (int microsecondsPerQuarterNote) throw()
  22665. {
  22666. uint8 d[8];
  22667. d[0] = 0xff;
  22668. d[1] = 81;
  22669. d[2] = 3;
  22670. d[3] = (uint8) (microsecondsPerQuarterNote >> 16);
  22671. d[4] = (uint8) ((microsecondsPerQuarterNote >> 8) & 0xff);
  22672. d[5] = (uint8) (microsecondsPerQuarterNote & 0xff);
  22673. return MidiMessage (d, 6, 0.0);
  22674. }
  22675. bool MidiMessage::isTimeSignatureMetaEvent() const throw()
  22676. {
  22677. return (data[1] == 0x58)
  22678. && (*data == (uint8) 0xff);
  22679. }
  22680. void MidiMessage::getTimeSignatureInfo (int& numerator,
  22681. int& denominator) const throw()
  22682. {
  22683. if (isTimeSignatureMetaEvent())
  22684. {
  22685. const uint8* const d = getMetaEventData();
  22686. numerator = d[0];
  22687. denominator = 1 << d[1];
  22688. }
  22689. else
  22690. {
  22691. numerator = 4;
  22692. denominator = 4;
  22693. }
  22694. }
  22695. const MidiMessage MidiMessage::timeSignatureMetaEvent (const int numerator,
  22696. const int denominator) throw()
  22697. {
  22698. uint8 d[8];
  22699. d[0] = 0xff;
  22700. d[1] = 0x58;
  22701. d[2] = 0x04;
  22702. d[3] = (uint8) numerator;
  22703. int n = 1;
  22704. int powerOfTwo = 0;
  22705. while (n < denominator)
  22706. {
  22707. n <<= 1;
  22708. ++powerOfTwo;
  22709. }
  22710. d[4] = (uint8) powerOfTwo;
  22711. d[5] = 0x01;
  22712. d[6] = 96;
  22713. return MidiMessage (d, 7, 0.0);
  22714. }
  22715. const MidiMessage MidiMessage::midiChannelMetaEvent (const int channel) throw()
  22716. {
  22717. uint8 d[8];
  22718. d[0] = 0xff;
  22719. d[1] = 0x20;
  22720. d[2] = 0x01;
  22721. d[3] = (uint8) jlimit (0, 0xff, channel - 1);
  22722. return MidiMessage (d, 4, 0.0);
  22723. }
  22724. bool MidiMessage::isKeySignatureMetaEvent() const throw()
  22725. {
  22726. return getMetaEventType() == 89;
  22727. }
  22728. int MidiMessage::getKeySignatureNumberOfSharpsOrFlats() const throw()
  22729. {
  22730. return (int) *getMetaEventData();
  22731. }
  22732. const MidiMessage MidiMessage::endOfTrack() throw()
  22733. {
  22734. return MidiMessage (0xff, 0x2f, 0, 0.0);
  22735. }
  22736. bool MidiMessage::isSongPositionPointer() const throw()
  22737. {
  22738. return *data == 0xf2;
  22739. }
  22740. int MidiMessage::getSongPositionPointerMidiBeat() const throw()
  22741. {
  22742. return data[1] | (data[2] << 7);
  22743. }
  22744. const MidiMessage MidiMessage::songPositionPointer (const int positionInMidiBeats) throw()
  22745. {
  22746. return MidiMessage (0xf2,
  22747. positionInMidiBeats & 127,
  22748. (positionInMidiBeats >> 7) & 127);
  22749. }
  22750. bool MidiMessage::isMidiStart() const throw()
  22751. {
  22752. return *data == 0xfa;
  22753. }
  22754. const MidiMessage MidiMessage::midiStart() throw()
  22755. {
  22756. return MidiMessage (0xfa);
  22757. }
  22758. bool MidiMessage::isMidiContinue() const throw()
  22759. {
  22760. return *data == 0xfb;
  22761. }
  22762. const MidiMessage MidiMessage::midiContinue() throw()
  22763. {
  22764. return MidiMessage (0xfb);
  22765. }
  22766. bool MidiMessage::isMidiStop() const throw()
  22767. {
  22768. return *data == 0xfc;
  22769. }
  22770. const MidiMessage MidiMessage::midiStop() throw()
  22771. {
  22772. return MidiMessage (0xfc);
  22773. }
  22774. bool MidiMessage::isMidiClock() const throw()
  22775. {
  22776. return *data == 0xf8;
  22777. }
  22778. const MidiMessage MidiMessage::midiClock() throw()
  22779. {
  22780. return MidiMessage (0xf8);
  22781. }
  22782. bool MidiMessage::isQuarterFrame() const throw()
  22783. {
  22784. return *data == 0xf1;
  22785. }
  22786. int MidiMessage::getQuarterFrameSequenceNumber() const throw()
  22787. {
  22788. return ((int) data[1]) >> 4;
  22789. }
  22790. int MidiMessage::getQuarterFrameValue() const throw()
  22791. {
  22792. return ((int) data[1]) & 0x0f;
  22793. }
  22794. const MidiMessage MidiMessage::quarterFrame (const int sequenceNumber,
  22795. const int value) throw()
  22796. {
  22797. return MidiMessage (0xf1, (sequenceNumber << 4) | value);
  22798. }
  22799. bool MidiMessage::isFullFrame() const throw()
  22800. {
  22801. return data[0] == 0xf0
  22802. && data[1] == 0x7f
  22803. && size >= 10
  22804. && data[3] == 0x01
  22805. && data[4] == 0x01;
  22806. }
  22807. void MidiMessage::getFullFrameParameters (int& hours,
  22808. int& minutes,
  22809. int& seconds,
  22810. int& frames,
  22811. MidiMessage::SmpteTimecodeType& timecodeType) const throw()
  22812. {
  22813. jassert (isFullFrame());
  22814. timecodeType = (SmpteTimecodeType) (data[5] >> 5);
  22815. hours = data[5] & 0x1f;
  22816. minutes = data[6];
  22817. seconds = data[7];
  22818. frames = data[8];
  22819. }
  22820. const MidiMessage MidiMessage::fullFrame (const int hours,
  22821. const int minutes,
  22822. const int seconds,
  22823. const int frames,
  22824. MidiMessage::SmpteTimecodeType timecodeType)
  22825. {
  22826. uint8 d[10];
  22827. d[0] = 0xf0;
  22828. d[1] = 0x7f;
  22829. d[2] = 0x7f;
  22830. d[3] = 0x01;
  22831. d[4] = 0x01;
  22832. d[5] = (uint8) ((hours & 0x01f) | (timecodeType << 5));
  22833. d[6] = (uint8) minutes;
  22834. d[7] = (uint8) seconds;
  22835. d[8] = (uint8) frames;
  22836. d[9] = 0xf7;
  22837. return MidiMessage (d, 10, 0.0);
  22838. }
  22839. bool MidiMessage::isMidiMachineControlMessage() const throw()
  22840. {
  22841. return data[0] == 0xf0
  22842. && data[1] == 0x7f
  22843. && data[3] == 0x06
  22844. && size > 5;
  22845. }
  22846. MidiMessage::MidiMachineControlCommand MidiMessage::getMidiMachineControlCommand() const throw()
  22847. {
  22848. jassert (isMidiMachineControlMessage());
  22849. return (MidiMachineControlCommand) data[4];
  22850. }
  22851. const MidiMessage MidiMessage::midiMachineControlCommand (MidiMessage::MidiMachineControlCommand command)
  22852. {
  22853. uint8 d[6];
  22854. d[0] = 0xf0;
  22855. d[1] = 0x7f;
  22856. d[2] = 0x00;
  22857. d[3] = 0x06;
  22858. d[4] = (uint8) command;
  22859. d[5] = 0xf7;
  22860. return MidiMessage (d, 6, 0.0);
  22861. }
  22862. bool MidiMessage::isMidiMachineControlGoto (int& hours,
  22863. int& minutes,
  22864. int& seconds,
  22865. int& frames) const throw()
  22866. {
  22867. if (size >= 12
  22868. && data[0] == 0xf0
  22869. && data[1] == 0x7f
  22870. && data[3] == 0x06
  22871. && data[4] == 0x44
  22872. && data[5] == 0x06
  22873. && data[6] == 0x01)
  22874. {
  22875. hours = data[7] % 24; // (that some machines send out hours > 24)
  22876. minutes = data[8];
  22877. seconds = data[9];
  22878. frames = data[10];
  22879. return true;
  22880. }
  22881. return false;
  22882. }
  22883. const MidiMessage MidiMessage::midiMachineControlGoto (int hours,
  22884. int minutes,
  22885. int seconds,
  22886. int frames)
  22887. {
  22888. uint8 d[12];
  22889. d[0] = 0xf0;
  22890. d[1] = 0x7f;
  22891. d[2] = 0x00;
  22892. d[3] = 0x06;
  22893. d[4] = 0x44;
  22894. d[5] = 0x06;
  22895. d[6] = 0x01;
  22896. d[7] = (uint8) hours;
  22897. d[8] = (uint8) minutes;
  22898. d[9] = (uint8) seconds;
  22899. d[10] = (uint8) frames;
  22900. d[11] = 0xf7;
  22901. return MidiMessage (d, 12, 0.0);
  22902. }
  22903. const String MidiMessage::getMidiNoteName (int note,
  22904. bool useSharps,
  22905. bool includeOctaveNumber,
  22906. int octaveNumForMiddleC) throw()
  22907. {
  22908. static const char* const sharpNoteNames[] = { "C", "C#", "D", "D#", "E",
  22909. "F", "F#", "G", "G#", "A",
  22910. "A#", "B" };
  22911. static const char* const flatNoteNames[] = { "C", "Db", "D", "Eb", "E",
  22912. "F", "Gb", "G", "Ab", "A",
  22913. "Bb", "B" };
  22914. if (((unsigned int) note) < 128)
  22915. {
  22916. const String s ((useSharps) ? sharpNoteNames [note % 12]
  22917. : flatNoteNames [note % 12]);
  22918. if (includeOctaveNumber)
  22919. return s + String (note / 12 + (octaveNumForMiddleC - 5));
  22920. else
  22921. return s;
  22922. }
  22923. return String::empty;
  22924. }
  22925. const double MidiMessage::getMidiNoteInHertz (int noteNumber) throw()
  22926. {
  22927. noteNumber -= 12 * 6 + 9; // now 0 = A440
  22928. return 440.0 * pow (2.0, noteNumber / 12.0);
  22929. }
  22930. const String MidiMessage::getGMInstrumentName (int n) throw()
  22931. {
  22932. const char *names[] =
  22933. {
  22934. "Acoustic Grand Piano", "Bright Acoustic Piano", "Electric Grand Piano", "Honky-tonk Piano",
  22935. "Electric Piano 1", "Electric Piano 2", "Harpsichord", "Clavinet", "Celesta", "Glockenspiel",
  22936. "Music Box", "Vibraphone", "Marimba", "Xylophone", "Tubular Bells", "Dulcimer", "Drawbar Organ",
  22937. "Percussive Organ", "Rock Organ", "Church Organ", "Reed Organ", "Accordion", "Harmonica",
  22938. "Tango Accordion", "Acoustic Guitar (nylon)", "Acoustic Guitar (steel)", "Electric Guitar (jazz)",
  22939. "Electric Guitar (clean)", "Electric Guitar (mute)", "Overdriven Guitar", "Distortion Guitar",
  22940. "Guitar Harmonics", "Acoustic Bass", "Electric Bass (finger)", "Electric Bass (pick)",
  22941. "Fretless Bass", "Slap Bass 1", "Slap Bass 2", "Synth Bass 1", "Synth Bass 2", "Violin",
  22942. "Viola", "Cello", "Contrabass", "Tremolo Strings", "Pizzicato Strings", "Orchestral Harp",
  22943. "Timpani", "String Ensemble 1", "String Ensemble 2", "SynthStrings 1", "SynthStrings 2",
  22944. "Choir Aahs", "Voice Oohs", "Synth Voice", "Orchestra Hit", "Trumpet", "Trombone", "Tuba",
  22945. "Muted Trumpet", "French Horn", "Brass Section", "SynthBrass 1", "SynthBrass 2", "Soprano Sax",
  22946. "Alto Sax", "Tenor Sax", "Baritone Sax", "Oboe", "English Horn", "Bassoon", "Clarinet",
  22947. "Piccolo", "Flute", "Recorder", "Pan Flute", "Blown Bottle", "Shakuhachi", "Whistle",
  22948. "Ocarina", "Lead 1 (square)", "Lead 2 (sawtooth)", "Lead 3 (calliope)", "Lead 4 (chiff)",
  22949. "Lead 5 (charang)", "Lead 6 (voice)", "Lead 7 (fifths)", "Lead 8 (bass+lead)", "Pad 1 (new age)",
  22950. "Pad 2 (warm)", "Pad 3 (polysynth)", "Pad 4 (choir)", "Pad 5 (bowed)", "Pad 6 (metallic)",
  22951. "Pad 7 (halo)", "Pad 8 (sweep)", "FX 1 (rain)", "FX 2 (soundtrack)", "FX 3 (crystal)",
  22952. "FX 4 (atmosphere)", "FX 5 (brightness)", "FX 6 (goblins)", "FX 7 (echoes)", "FX 8 (sci-fi)",
  22953. "Sitar", "Banjo", "Shamisen", "Koto", "Kalimba", "Bag pipe", "Fiddle", "Shanai", "Tinkle Bell",
  22954. "Agogo", "Steel Drums", "Woodblock", "Taiko Drum", "Melodic Tom", "Synth Drum", "Reverse Cymbal",
  22955. "Guitar Fret Noise", "Breath Noise", "Seashore", "Bird Tweet", "Telephone Ring", "Helicopter",
  22956. "Applause", "Gunshot"
  22957. };
  22958. return (((unsigned int) n) < 128) ? names[n]
  22959. : (const char*)0;
  22960. }
  22961. const String MidiMessage::getGMInstrumentBankName (int n) throw()
  22962. {
  22963. const char* names[] =
  22964. {
  22965. "Piano", "Chromatic Percussion", "Organ", "Guitar",
  22966. "Bass", "Strings", "Ensemble", "Brass",
  22967. "Reed", "Pipe", "Synth Lead", "Synth Pad",
  22968. "Synth Effects", "Ethnic", "Percussive", "Sound Effects"
  22969. };
  22970. return (((unsigned int) n) <= 15) ? names[n]
  22971. : (const char*)0;
  22972. }
  22973. const String MidiMessage::getRhythmInstrumentName (int n) throw()
  22974. {
  22975. const char* names[] =
  22976. {
  22977. "Acoustic Bass Drum", "Bass Drum 1", "Side Stick", "Acoustic Snare",
  22978. "Hand Clap", "Electric Snare", "Low Floor Tom", "Closed Hi-Hat", "High Floor Tom",
  22979. "Pedal Hi-Hat", "Low Tom", "Open Hi-Hat", "Low-Mid Tom", "Hi-Mid Tom", "Crash Cymbal 1",
  22980. "High Tom", "Ride Cymbal 1", "Chinese Cymbal", "Ride Bell", "Tambourine", "Splash Cymbal",
  22981. "Cowbell", "Crash Cymbal 2", "Vibraslap", "Ride Cymbal 2", "Hi Bongo", "Low Bongo",
  22982. "Mute Hi Conga", "Open Hi Conga", "Low Conga", "High Timbale", "Low Timbale", "High Agogo",
  22983. "Low Agogo", "Cabasa", "Maracas", "Short Whistle", "Long Whistle", "Short Guiro",
  22984. "Long Guiro", "Claves", "Hi Wood Block", "Low Wood Block", "Mute Cuica", "Open Cuica",
  22985. "Mute Triangle", "Open Triangle"
  22986. };
  22987. return (n >= 35 && n <= 81) ? names [n - 35]
  22988. : (const char*)0;
  22989. }
  22990. const String MidiMessage::getControllerName (int n) throw()
  22991. {
  22992. const char* names[] =
  22993. {
  22994. "Bank Select", "Modulation Wheel (coarse)", "Breath controller (coarse)",
  22995. 0, "Foot Pedal (coarse)", "Portamento Time (coarse)",
  22996. "Data Entry (coarse)", "Volume (coarse)", "Balance (coarse)",
  22997. 0, "Pan position (coarse)", "Expression (coarse)", "Effect Control 1 (coarse)",
  22998. "Effect Control 2 (coarse)", 0, 0, "General Purpose Slider 1", "General Purpose Slider 2",
  22999. "General Purpose Slider 3", "General Purpose Slider 4", 0, 0, 0, 0, 0, 0, 0, 0,
  23000. 0, 0, 0, 0, "Bank Select (fine)", "Modulation Wheel (fine)", "Breath controller (fine)",
  23001. 0, "Foot Pedal (fine)", "Portamento Time (fine)", "Data Entry (fine)", "Volume (fine)",
  23002. "Balance (fine)", 0, "Pan position (fine)", "Expression (fine)", "Effect Control 1 (fine)",
  23003. "Effect Control 2 (fine)", 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  23004. "Hold Pedal (on/off)", "Portamento (on/off)", "Sustenuto Pedal (on/off)", "Soft Pedal (on/off)",
  23005. "Legato Pedal (on/off)", "Hold 2 Pedal (on/off)", "Sound Variation", "Sound Timbre",
  23006. "Sound Release Time", "Sound Attack Time", "Sound Brightness", "Sound Control 6",
  23007. "Sound Control 7", "Sound Control 8", "Sound Control 9", "Sound Control 10",
  23008. "General Purpose Button 1 (on/off)", "General Purpose Button 2 (on/off)",
  23009. "General Purpose Button 3 (on/off)", "General Purpose Button 4 (on/off)",
  23010. 0, 0, 0, 0, 0, 0, 0, "Reverb Level", "Tremolo Level", "Chorus Level", "Celeste Level",
  23011. "Phaser Level", "Data Button increment", "Data Button decrement", "Non-registered Parameter (fine)",
  23012. "Non-registered Parameter (coarse)", "Registered Parameter (fine)", "Registered Parameter (coarse)",
  23013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "All Sound Off", "All Controllers Off",
  23014. "Local Keyboard (on/off)", "All Notes Off", "Omni Mode Off", "Omni Mode On", "Mono Operation",
  23015. "Poly Operation"
  23016. };
  23017. return (((unsigned int) n) < 128) ? names[n]
  23018. : (const char*)0;
  23019. }
  23020. END_JUCE_NAMESPACE
  23021. /*** End of inlined file: juce_MidiMessage.cpp ***/
  23022. /*** Start of inlined file: juce_MidiMessageCollector.cpp ***/
  23023. BEGIN_JUCE_NAMESPACE
  23024. MidiMessageCollector::MidiMessageCollector()
  23025. : lastCallbackTime (0),
  23026. sampleRate (44100.0001)
  23027. {
  23028. }
  23029. MidiMessageCollector::~MidiMessageCollector()
  23030. {
  23031. }
  23032. void MidiMessageCollector::reset (const double sampleRate_)
  23033. {
  23034. jassert (sampleRate_ > 0);
  23035. const ScopedLock sl (midiCallbackLock);
  23036. sampleRate = sampleRate_;
  23037. incomingMessages.clear();
  23038. lastCallbackTime = Time::getMillisecondCounterHiRes();
  23039. }
  23040. void MidiMessageCollector::addMessageToQueue (const MidiMessage& message)
  23041. {
  23042. // you need to call reset() to set the correct sample rate before using this object
  23043. jassert (sampleRate != 44100.0001);
  23044. // the messages that come in here need to be time-stamped correctly - see MidiInput
  23045. // for details of what the number should be.
  23046. jassert (message.getTimeStamp() != 0);
  23047. const ScopedLock sl (midiCallbackLock);
  23048. const int sampleNumber
  23049. = (int) ((message.getTimeStamp() - 0.001 * lastCallbackTime) * sampleRate);
  23050. incomingMessages.addEvent (message, sampleNumber);
  23051. // if the messages don't get used for over a second, we'd better
  23052. // get rid of any old ones to avoid the queue getting too big
  23053. if (sampleNumber > sampleRate)
  23054. incomingMessages.clear (0, sampleNumber - (int) sampleRate);
  23055. }
  23056. void MidiMessageCollector::removeNextBlockOfMessages (MidiBuffer& destBuffer,
  23057. const int numSamples)
  23058. {
  23059. // you need to call reset() to set the correct sample rate before using this object
  23060. jassert (sampleRate != 44100.0001);
  23061. const double timeNow = Time::getMillisecondCounterHiRes();
  23062. const double msElapsed = timeNow - lastCallbackTime;
  23063. const ScopedLock sl (midiCallbackLock);
  23064. lastCallbackTime = timeNow;
  23065. if (! incomingMessages.isEmpty())
  23066. {
  23067. int numSourceSamples = jmax (1, roundToInt (msElapsed * 0.001 * sampleRate));
  23068. int startSample = 0;
  23069. int scale = 1 << 16;
  23070. const uint8* midiData;
  23071. int numBytes, samplePosition;
  23072. MidiBuffer::Iterator iter (incomingMessages);
  23073. if (numSourceSamples > numSamples)
  23074. {
  23075. // if our list of events is longer than the buffer we're being
  23076. // asked for, scale them down to squeeze them all in..
  23077. const int maxBlockLengthToUse = numSamples << 5;
  23078. if (numSourceSamples > maxBlockLengthToUse)
  23079. {
  23080. startSample = numSourceSamples - maxBlockLengthToUse;
  23081. numSourceSamples = maxBlockLengthToUse;
  23082. iter.setNextSamplePosition (startSample);
  23083. }
  23084. scale = (numSamples << 10) / numSourceSamples;
  23085. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  23086. {
  23087. samplePosition = ((samplePosition - startSample) * scale) >> 10;
  23088. destBuffer.addEvent (midiData, numBytes,
  23089. jlimit (0, numSamples - 1, samplePosition));
  23090. }
  23091. }
  23092. else
  23093. {
  23094. // if our event list is shorter than the number we need, put them
  23095. // towards the end of the buffer
  23096. startSample = numSamples - numSourceSamples;
  23097. while (iter.getNextEvent (midiData, numBytes, samplePosition))
  23098. {
  23099. destBuffer.addEvent (midiData, numBytes,
  23100. jlimit (0, numSamples - 1, samplePosition + startSample));
  23101. }
  23102. }
  23103. incomingMessages.clear();
  23104. }
  23105. }
  23106. void MidiMessageCollector::handleNoteOn (MidiKeyboardState*, int midiChannel, int midiNoteNumber, float velocity)
  23107. {
  23108. MidiMessage m (MidiMessage::noteOn (midiChannel, midiNoteNumber, velocity));
  23109. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23110. addMessageToQueue (m);
  23111. }
  23112. void MidiMessageCollector::handleNoteOff (MidiKeyboardState*, int midiChannel, int midiNoteNumber)
  23113. {
  23114. MidiMessage m (MidiMessage::noteOff (midiChannel, midiNoteNumber));
  23115. m.setTimeStamp (Time::getMillisecondCounterHiRes() * 0.001);
  23116. addMessageToQueue (m);
  23117. }
  23118. void MidiMessageCollector::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  23119. {
  23120. addMessageToQueue (message);
  23121. }
  23122. END_JUCE_NAMESPACE
  23123. /*** End of inlined file: juce_MidiMessageCollector.cpp ***/
  23124. /*** Start of inlined file: juce_MidiMessageSequence.cpp ***/
  23125. BEGIN_JUCE_NAMESPACE
  23126. MidiMessageSequence::MidiMessageSequence()
  23127. {
  23128. }
  23129. MidiMessageSequence::MidiMessageSequence (const MidiMessageSequence& other)
  23130. {
  23131. list.ensureStorageAllocated (other.list.size());
  23132. for (int i = 0; i < other.list.size(); ++i)
  23133. list.add (new MidiEventHolder (other.list.getUnchecked(i)->message));
  23134. }
  23135. MidiMessageSequence& MidiMessageSequence::operator= (const MidiMessageSequence& other)
  23136. {
  23137. MidiMessageSequence otherCopy (other);
  23138. swapWith (otherCopy);
  23139. return *this;
  23140. }
  23141. void MidiMessageSequence::swapWith (MidiMessageSequence& other) throw()
  23142. {
  23143. list.swapWithArray (other.list);
  23144. }
  23145. MidiMessageSequence::~MidiMessageSequence()
  23146. {
  23147. }
  23148. void MidiMessageSequence::clear()
  23149. {
  23150. list.clear();
  23151. }
  23152. int MidiMessageSequence::getNumEvents() const
  23153. {
  23154. return list.size();
  23155. }
  23156. MidiMessageSequence::MidiEventHolder* MidiMessageSequence::getEventPointer (const int index) const
  23157. {
  23158. return list [index];
  23159. }
  23160. double MidiMessageSequence::getTimeOfMatchingKeyUp (const int index) const
  23161. {
  23162. const MidiEventHolder* const meh = list [index];
  23163. if (meh != 0 && meh->noteOffObject != 0)
  23164. return meh->noteOffObject->message.getTimeStamp();
  23165. else
  23166. return 0.0;
  23167. }
  23168. int MidiMessageSequence::getIndexOfMatchingKeyUp (const int index) const
  23169. {
  23170. const MidiEventHolder* const meh = list [index];
  23171. return (meh != 0) ? list.indexOf (meh->noteOffObject) : -1;
  23172. }
  23173. int MidiMessageSequence::getIndexOf (MidiEventHolder* const event) const
  23174. {
  23175. return list.indexOf (event);
  23176. }
  23177. int MidiMessageSequence::getNextIndexAtTime (const double timeStamp) const
  23178. {
  23179. const int numEvents = list.size();
  23180. int i;
  23181. for (i = 0; i < numEvents; ++i)
  23182. if (list.getUnchecked(i)->message.getTimeStamp() >= timeStamp)
  23183. break;
  23184. return i;
  23185. }
  23186. double MidiMessageSequence::getStartTime() const
  23187. {
  23188. if (list.size() > 0)
  23189. return list.getUnchecked(0)->message.getTimeStamp();
  23190. else
  23191. return 0;
  23192. }
  23193. double MidiMessageSequence::getEndTime() const
  23194. {
  23195. if (list.size() > 0)
  23196. return list.getLast()->message.getTimeStamp();
  23197. else
  23198. return 0;
  23199. }
  23200. double MidiMessageSequence::getEventTime (const int index) const
  23201. {
  23202. if (((unsigned int) index) < (unsigned int) list.size())
  23203. return list.getUnchecked (index)->message.getTimeStamp();
  23204. return 0.0;
  23205. }
  23206. void MidiMessageSequence::addEvent (const MidiMessage& newMessage,
  23207. double timeAdjustment)
  23208. {
  23209. MidiEventHolder* const newOne = new MidiEventHolder (newMessage);
  23210. timeAdjustment += newMessage.getTimeStamp();
  23211. newOne->message.setTimeStamp (timeAdjustment);
  23212. int i;
  23213. for (i = list.size(); --i >= 0;)
  23214. if (list.getUnchecked(i)->message.getTimeStamp() <= timeAdjustment)
  23215. break;
  23216. list.insert (i + 1, newOne);
  23217. }
  23218. void MidiMessageSequence::deleteEvent (const int index,
  23219. const bool deleteMatchingNoteUp)
  23220. {
  23221. if (((unsigned int) index) < (unsigned int) list.size())
  23222. {
  23223. if (deleteMatchingNoteUp)
  23224. deleteEvent (getIndexOfMatchingKeyUp (index), false);
  23225. list.remove (index);
  23226. }
  23227. }
  23228. void MidiMessageSequence::addSequence (const MidiMessageSequence& other,
  23229. double timeAdjustment,
  23230. double firstAllowableTime,
  23231. double endOfAllowableDestTimes)
  23232. {
  23233. firstAllowableTime -= timeAdjustment;
  23234. endOfAllowableDestTimes -= timeAdjustment;
  23235. for (int i = 0; i < other.list.size(); ++i)
  23236. {
  23237. const MidiMessage& m = other.list.getUnchecked(i)->message;
  23238. const double t = m.getTimeStamp();
  23239. if (t >= firstAllowableTime && t < endOfAllowableDestTimes)
  23240. {
  23241. MidiEventHolder* const newOne = new MidiEventHolder (m);
  23242. newOne->message.setTimeStamp (timeAdjustment + t);
  23243. list.add (newOne);
  23244. }
  23245. }
  23246. sort();
  23247. }
  23248. int MidiMessageSequence::compareElements (const MidiMessageSequence::MidiEventHolder* const first,
  23249. const MidiMessageSequence::MidiEventHolder* const second) throw()
  23250. {
  23251. const double diff = first->message.getTimeStamp()
  23252. - second->message.getTimeStamp();
  23253. return (diff > 0) - (diff < 0);
  23254. }
  23255. void MidiMessageSequence::sort()
  23256. {
  23257. list.sort (*this, true);
  23258. }
  23259. void MidiMessageSequence::updateMatchedPairs()
  23260. {
  23261. for (int i = 0; i < list.size(); ++i)
  23262. {
  23263. const MidiMessage& m1 = list.getUnchecked(i)->message;
  23264. if (m1.isNoteOn())
  23265. {
  23266. list.getUnchecked(i)->noteOffObject = 0;
  23267. const int note = m1.getNoteNumber();
  23268. const int chan = m1.getChannel();
  23269. const int len = list.size();
  23270. for (int j = i + 1; j < len; ++j)
  23271. {
  23272. const MidiMessage& m = list.getUnchecked(j)->message;
  23273. if (m.getNoteNumber() == note && m.getChannel() == chan)
  23274. {
  23275. if (m.isNoteOff())
  23276. {
  23277. list.getUnchecked(i)->noteOffObject = list[j];
  23278. break;
  23279. }
  23280. else if (m.isNoteOn())
  23281. {
  23282. list.insert (j, new MidiEventHolder (MidiMessage::noteOff (chan, note)));
  23283. list.getUnchecked(j)->message.setTimeStamp (m.getTimeStamp());
  23284. list.getUnchecked(i)->noteOffObject = list[j];
  23285. break;
  23286. }
  23287. }
  23288. }
  23289. }
  23290. }
  23291. }
  23292. void MidiMessageSequence::addTimeToMessages (const double delta)
  23293. {
  23294. for (int i = list.size(); --i >= 0;)
  23295. list.getUnchecked (i)->message.setTimeStamp (list.getUnchecked (i)->message.getTimeStamp()
  23296. + delta);
  23297. }
  23298. void MidiMessageSequence::extractMidiChannelMessages (const int channelNumberToExtract,
  23299. MidiMessageSequence& destSequence,
  23300. const bool alsoIncludeMetaEvents) const
  23301. {
  23302. for (int i = 0; i < list.size(); ++i)
  23303. {
  23304. const MidiMessage& mm = list.getUnchecked(i)->message;
  23305. if (mm.isForChannel (channelNumberToExtract)
  23306. || (alsoIncludeMetaEvents && mm.isMetaEvent()))
  23307. {
  23308. destSequence.addEvent (mm);
  23309. }
  23310. }
  23311. }
  23312. void MidiMessageSequence::extractSysExMessages (MidiMessageSequence& destSequence) const
  23313. {
  23314. for (int i = 0; i < list.size(); ++i)
  23315. {
  23316. const MidiMessage& mm = list.getUnchecked(i)->message;
  23317. if (mm.isSysEx())
  23318. destSequence.addEvent (mm);
  23319. }
  23320. }
  23321. void MidiMessageSequence::deleteMidiChannelMessages (const int channelNumberToRemove)
  23322. {
  23323. for (int i = list.size(); --i >= 0;)
  23324. if (list.getUnchecked(i)->message.isForChannel (channelNumberToRemove))
  23325. list.remove(i);
  23326. }
  23327. void MidiMessageSequence::deleteSysExMessages()
  23328. {
  23329. for (int i = list.size(); --i >= 0;)
  23330. if (list.getUnchecked(i)->message.isSysEx())
  23331. list.remove(i);
  23332. }
  23333. void MidiMessageSequence::createControllerUpdatesForTime (const int channelNumber,
  23334. const double time,
  23335. OwnedArray<MidiMessage>& dest)
  23336. {
  23337. bool doneProg = false;
  23338. bool donePitchWheel = false;
  23339. Array <int> doneControllers;
  23340. doneControllers.ensureStorageAllocated (32);
  23341. for (int i = list.size(); --i >= 0;)
  23342. {
  23343. const MidiMessage& mm = list.getUnchecked(i)->message;
  23344. if (mm.isForChannel (channelNumber)
  23345. && mm.getTimeStamp() <= time)
  23346. {
  23347. if (mm.isProgramChange())
  23348. {
  23349. if (! doneProg)
  23350. {
  23351. dest.add (new MidiMessage (mm, 0.0));
  23352. doneProg = true;
  23353. }
  23354. }
  23355. else if (mm.isController())
  23356. {
  23357. if (! doneControllers.contains (mm.getControllerNumber()))
  23358. {
  23359. dest.add (new MidiMessage (mm, 0.0));
  23360. doneControllers.add (mm.getControllerNumber());
  23361. }
  23362. }
  23363. else if (mm.isPitchWheel())
  23364. {
  23365. if (! donePitchWheel)
  23366. {
  23367. dest.add (new MidiMessage (mm, 0.0));
  23368. donePitchWheel = true;
  23369. }
  23370. }
  23371. }
  23372. }
  23373. }
  23374. MidiMessageSequence::MidiEventHolder::MidiEventHolder (const MidiMessage& message_)
  23375. : message (message_),
  23376. noteOffObject (0)
  23377. {
  23378. }
  23379. MidiMessageSequence::MidiEventHolder::~MidiEventHolder()
  23380. {
  23381. }
  23382. END_JUCE_NAMESPACE
  23383. /*** End of inlined file: juce_MidiMessageSequence.cpp ***/
  23384. /*** Start of inlined file: juce_AudioPluginFormat.cpp ***/
  23385. BEGIN_JUCE_NAMESPACE
  23386. AudioPluginFormat::AudioPluginFormat() throw()
  23387. {
  23388. }
  23389. AudioPluginFormat::~AudioPluginFormat()
  23390. {
  23391. }
  23392. END_JUCE_NAMESPACE
  23393. /*** End of inlined file: juce_AudioPluginFormat.cpp ***/
  23394. /*** Start of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23395. BEGIN_JUCE_NAMESPACE
  23396. AudioPluginFormatManager::AudioPluginFormatManager() throw()
  23397. {
  23398. }
  23399. AudioPluginFormatManager::~AudioPluginFormatManager() throw()
  23400. {
  23401. clearSingletonInstance();
  23402. }
  23403. juce_ImplementSingleton_SingleThreaded (AudioPluginFormatManager);
  23404. void AudioPluginFormatManager::addDefaultFormats()
  23405. {
  23406. #ifdef JUCE_DEBUG
  23407. // you should only call this method once!
  23408. for (int i = formats.size(); --i >= 0;)
  23409. {
  23410. #if JUCE_PLUGINHOST_VST
  23411. jassert (dynamic_cast <VSTPluginFormat*> (formats[i]) == 0);
  23412. #endif
  23413. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23414. jassert (dynamic_cast <AudioUnitPluginFormat*> (formats[i]) == 0);
  23415. #endif
  23416. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23417. jassert (dynamic_cast <DirectXPluginFormat*> (formats[i]) == 0);
  23418. #endif
  23419. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23420. jassert (dynamic_cast <LADSPAPluginFormat*> (formats[i]) == 0);
  23421. #endif
  23422. }
  23423. #endif
  23424. #if JUCE_PLUGINHOST_AU && JUCE_MAC
  23425. formats.add (new AudioUnitPluginFormat());
  23426. #endif
  23427. #if JUCE_PLUGINHOST_VST
  23428. formats.add (new VSTPluginFormat());
  23429. #endif
  23430. #if JUCE_PLUGINHOST_DX && JUCE_WIN32
  23431. formats.add (new DirectXPluginFormat());
  23432. #endif
  23433. #if JUCE_PLUGINHOST_LADSPA && JUCE_LINUX
  23434. formats.add (new LADSPAPluginFormat());
  23435. #endif
  23436. }
  23437. int AudioPluginFormatManager::getNumFormats() throw()
  23438. {
  23439. return formats.size();
  23440. }
  23441. AudioPluginFormat* AudioPluginFormatManager::getFormat (const int index) throw()
  23442. {
  23443. return formats [index];
  23444. }
  23445. void AudioPluginFormatManager::addFormat (AudioPluginFormat* const format) throw()
  23446. {
  23447. formats.add (format);
  23448. }
  23449. AudioPluginInstance* AudioPluginFormatManager::createPluginInstance (const PluginDescription& description,
  23450. String& errorMessage) const
  23451. {
  23452. AudioPluginInstance* result = 0;
  23453. for (int i = 0; i < formats.size(); ++i)
  23454. {
  23455. result = formats.getUnchecked(i)->createInstanceFromDescription (description);
  23456. if (result != 0)
  23457. break;
  23458. }
  23459. if (result == 0)
  23460. {
  23461. if (! doesPluginStillExist (description))
  23462. errorMessage = TRANS ("This plug-in file no longer exists");
  23463. else
  23464. errorMessage = TRANS ("This plug-in failed to load correctly");
  23465. }
  23466. return result;
  23467. }
  23468. bool AudioPluginFormatManager::doesPluginStillExist (const PluginDescription& description) const
  23469. {
  23470. for (int i = 0; i < formats.size(); ++i)
  23471. if (formats.getUnchecked(i)->getName() == description.pluginFormatName)
  23472. return formats.getUnchecked(i)->doesPluginStillExist (description);
  23473. return false;
  23474. }
  23475. END_JUCE_NAMESPACE
  23476. /*** End of inlined file: juce_AudioPluginFormatManager.cpp ***/
  23477. /*** Start of inlined file: juce_AudioPluginInstance.cpp ***/
  23478. #define JUCE_PLUGIN_HOST 1
  23479. BEGIN_JUCE_NAMESPACE
  23480. AudioPluginInstance::AudioPluginInstance()
  23481. {
  23482. }
  23483. AudioPluginInstance::~AudioPluginInstance()
  23484. {
  23485. }
  23486. END_JUCE_NAMESPACE
  23487. /*** End of inlined file: juce_AudioPluginInstance.cpp ***/
  23488. /*** Start of inlined file: juce_KnownPluginList.cpp ***/
  23489. BEGIN_JUCE_NAMESPACE
  23490. KnownPluginList::KnownPluginList()
  23491. {
  23492. }
  23493. KnownPluginList::~KnownPluginList()
  23494. {
  23495. }
  23496. void KnownPluginList::clear()
  23497. {
  23498. if (types.size() > 0)
  23499. {
  23500. types.clear();
  23501. sendChangeMessage (this);
  23502. }
  23503. }
  23504. PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifier) const throw()
  23505. {
  23506. for (int i = 0; i < types.size(); ++i)
  23507. if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier)
  23508. return types.getUnchecked(i);
  23509. return 0;
  23510. }
  23511. PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& identifierString) const throw()
  23512. {
  23513. for (int i = 0; i < types.size(); ++i)
  23514. if (types.getUnchecked(i)->createIdentifierString() == identifierString)
  23515. return types.getUnchecked(i);
  23516. return 0;
  23517. }
  23518. bool KnownPluginList::addType (const PluginDescription& type)
  23519. {
  23520. for (int i = types.size(); --i >= 0;)
  23521. {
  23522. if (types.getUnchecked(i)->isDuplicateOf (type))
  23523. {
  23524. // strange - found a duplicate plugin with different info..
  23525. jassert (types.getUnchecked(i)->name == type.name);
  23526. jassert (types.getUnchecked(i)->isInstrument == type.isInstrument);
  23527. *types.getUnchecked(i) = type;
  23528. return false;
  23529. }
  23530. }
  23531. types.add (new PluginDescription (type));
  23532. sendChangeMessage (this);
  23533. return true;
  23534. }
  23535. void KnownPluginList::removeType (const int index) throw()
  23536. {
  23537. types.remove (index);
  23538. sendChangeMessage (this);
  23539. }
  23540. static Time getFileModTime (const String& fileOrIdentifier) throw()
  23541. {
  23542. if (fileOrIdentifier.startsWithChar (T('/'))
  23543. || fileOrIdentifier[1] == T(':'))
  23544. {
  23545. return File (fileOrIdentifier).getLastModificationTime();
  23546. }
  23547. return Time (0);
  23548. }
  23549. static bool timesAreDifferent (const Time& t1, const Time& t2) throw()
  23550. {
  23551. return t1 != t2 || t1 == Time (0);
  23552. }
  23553. bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier) const throw()
  23554. {
  23555. if (getTypeForFile (fileOrIdentifier) == 0)
  23556. return false;
  23557. for (int i = types.size(); --i >= 0;)
  23558. {
  23559. const PluginDescription* const d = types.getUnchecked(i);
  23560. if (d->fileOrIdentifier == fileOrIdentifier
  23561. && timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23562. {
  23563. return false;
  23564. }
  23565. }
  23566. return true;
  23567. }
  23568. bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier,
  23569. const bool dontRescanIfAlreadyInList,
  23570. OwnedArray <PluginDescription>& typesFound,
  23571. AudioPluginFormat& format)
  23572. {
  23573. bool addedOne = false;
  23574. if (dontRescanIfAlreadyInList
  23575. && getTypeForFile (fileOrIdentifier) != 0)
  23576. {
  23577. bool needsRescanning = false;
  23578. for (int i = types.size(); --i >= 0;)
  23579. {
  23580. const PluginDescription* const d = types.getUnchecked(i);
  23581. if (d->fileOrIdentifier == fileOrIdentifier)
  23582. {
  23583. if (timesAreDifferent (d->lastFileModTime, getFileModTime (fileOrIdentifier)))
  23584. needsRescanning = true;
  23585. else
  23586. typesFound.add (new PluginDescription (*d));
  23587. }
  23588. }
  23589. if (! needsRescanning)
  23590. return false;
  23591. }
  23592. OwnedArray <PluginDescription> found;
  23593. format.findAllTypesForFile (found, fileOrIdentifier);
  23594. for (int i = 0; i < found.size(); ++i)
  23595. {
  23596. PluginDescription* const desc = found.getUnchecked(i);
  23597. jassert (desc != 0);
  23598. if (addType (*desc))
  23599. addedOne = true;
  23600. typesFound.add (new PluginDescription (*desc));
  23601. }
  23602. return addedOne;
  23603. }
  23604. void KnownPluginList::scanAndAddDragAndDroppedFiles (const StringArray& files,
  23605. OwnedArray <PluginDescription>& typesFound)
  23606. {
  23607. for (int i = 0; i < files.size(); ++i)
  23608. {
  23609. bool loaded = false;
  23610. for (int j = 0; j < AudioPluginFormatManager::getInstance()->getNumFormats(); ++j)
  23611. {
  23612. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (j);
  23613. if (scanAndAddFile (files[i], true, typesFound, *format))
  23614. loaded = true;
  23615. }
  23616. if (! loaded)
  23617. {
  23618. const File f (files[i]);
  23619. if (f.isDirectory())
  23620. {
  23621. StringArray s;
  23622. {
  23623. Array<File> subFiles;
  23624. f.findChildFiles (subFiles, File::findFilesAndDirectories, false);
  23625. for (int j = 0; j < subFiles.size(); ++j)
  23626. s.add (subFiles.getReference(j).getFullPathName());
  23627. }
  23628. scanAndAddDragAndDroppedFiles (s, typesFound);
  23629. }
  23630. }
  23631. }
  23632. }
  23633. class PluginSorter
  23634. {
  23635. public:
  23636. KnownPluginList::SortMethod method;
  23637. PluginSorter() throw() {}
  23638. int compareElements (const PluginDescription* const first,
  23639. const PluginDescription* const second) const throw()
  23640. {
  23641. int diff = 0;
  23642. if (method == KnownPluginList::sortByCategory)
  23643. diff = first->category.compareLexicographically (second->category);
  23644. else if (method == KnownPluginList::sortByManufacturer)
  23645. diff = first->manufacturerName.compareLexicographically (second->manufacturerName);
  23646. else if (method == KnownPluginList::sortByFileSystemLocation)
  23647. diff = first->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23648. .upToLastOccurrenceOf (T("/"), false, false)
  23649. .compare (second->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23650. .upToLastOccurrenceOf (T("/"), false, false));
  23651. if (diff == 0)
  23652. diff = first->name.compareLexicographically (second->name);
  23653. return diff;
  23654. }
  23655. };
  23656. void KnownPluginList::sort (const SortMethod method)
  23657. {
  23658. if (method != defaultOrder)
  23659. {
  23660. PluginSorter sorter;
  23661. sorter.method = method;
  23662. types.sort (sorter, true);
  23663. sendChangeMessage (this);
  23664. }
  23665. }
  23666. XmlElement* KnownPluginList::createXml() const
  23667. {
  23668. XmlElement* const e = new XmlElement (T("KNOWNPLUGINS"));
  23669. for (int i = 0; i < types.size(); ++i)
  23670. e->addChildElement (types.getUnchecked(i)->createXml());
  23671. return e;
  23672. }
  23673. void KnownPluginList::recreateFromXml (const XmlElement& xml)
  23674. {
  23675. clear();
  23676. if (xml.hasTagName (T("KNOWNPLUGINS")))
  23677. {
  23678. forEachXmlChildElement (xml, e)
  23679. {
  23680. PluginDescription info;
  23681. if (info.loadFromXml (*e))
  23682. addType (info);
  23683. }
  23684. }
  23685. }
  23686. const int menuIdBase = 0x324503f4;
  23687. // This is used to turn a bunch of paths into a nested menu structure.
  23688. struct PluginFilesystemTree
  23689. {
  23690. private:
  23691. String folder;
  23692. OwnedArray <PluginFilesystemTree> subFolders;
  23693. Array <PluginDescription*> plugins;
  23694. void addPlugin (PluginDescription* const pd, const String& path)
  23695. {
  23696. if (path.isEmpty())
  23697. {
  23698. plugins.add (pd);
  23699. }
  23700. else
  23701. {
  23702. const String firstSubFolder (path.upToFirstOccurrenceOf (T("/"), false, false));
  23703. const String remainingPath (path.fromFirstOccurrenceOf (T("/"), false, false));
  23704. for (int i = subFolders.size(); --i >= 0;)
  23705. {
  23706. if (subFolders.getUnchecked(i)->folder.equalsIgnoreCase (firstSubFolder))
  23707. {
  23708. subFolders.getUnchecked(i)->addPlugin (pd, remainingPath);
  23709. return;
  23710. }
  23711. }
  23712. PluginFilesystemTree* const newFolder = new PluginFilesystemTree();
  23713. newFolder->folder = firstSubFolder;
  23714. subFolders.add (newFolder);
  23715. newFolder->addPlugin (pd, remainingPath);
  23716. }
  23717. }
  23718. // removes any deeply nested folders that don't contain any actual plugins
  23719. void optimise()
  23720. {
  23721. for (int i = subFolders.size(); --i >= 0;)
  23722. {
  23723. PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23724. sub->optimise();
  23725. if (sub->plugins.size() == 0)
  23726. {
  23727. for (int j = 0; j < sub->subFolders.size(); ++j)
  23728. subFolders.add (sub->subFolders.getUnchecked(j));
  23729. sub->subFolders.clear (false);
  23730. subFolders.remove (i);
  23731. }
  23732. }
  23733. }
  23734. public:
  23735. void buildTree (const Array <PluginDescription*>& allPlugins)
  23736. {
  23737. for (int i = 0; i < allPlugins.size(); ++i)
  23738. {
  23739. String path (allPlugins.getUnchecked(i)
  23740. ->fileOrIdentifier.replaceCharacter (T('\\'), T('/'))
  23741. .upToLastOccurrenceOf (T("/"), false, false));
  23742. if (path.substring (1, 2) == T(":"))
  23743. path = path.substring (2);
  23744. addPlugin (allPlugins.getUnchecked(i), path);
  23745. }
  23746. optimise();
  23747. }
  23748. void addToMenu (PopupMenu& m, const OwnedArray <PluginDescription>& allPlugins) const
  23749. {
  23750. int i;
  23751. for (i = 0; i < subFolders.size(); ++i)
  23752. {
  23753. const PluginFilesystemTree* const sub = subFolders.getUnchecked(i);
  23754. PopupMenu subMenu;
  23755. sub->addToMenu (subMenu, allPlugins);
  23756. #if JUCE_MAC
  23757. // avoid the special AU formatting nonsense on Mac..
  23758. m.addSubMenu (sub->folder.fromFirstOccurrenceOf (T(":"), false, false), subMenu);
  23759. #else
  23760. m.addSubMenu (sub->folder, subMenu);
  23761. #endif
  23762. }
  23763. for (i = 0; i < plugins.size(); ++i)
  23764. {
  23765. PluginDescription* const plugin = plugins.getUnchecked(i);
  23766. m.addItem (allPlugins.indexOf (plugin) + menuIdBase,
  23767. plugin->name, true, false);
  23768. }
  23769. }
  23770. };
  23771. void KnownPluginList::addToMenu (PopupMenu& menu, const SortMethod sortMethod) const
  23772. {
  23773. Array <PluginDescription*> sorted;
  23774. {
  23775. PluginSorter sorter;
  23776. sorter.method = sortMethod;
  23777. for (int i = 0; i < types.size(); ++i)
  23778. sorted.addSorted (sorter, types.getUnchecked(i));
  23779. }
  23780. if (sortMethod == sortByCategory
  23781. || sortMethod == sortByManufacturer)
  23782. {
  23783. String lastSubMenuName;
  23784. PopupMenu sub;
  23785. for (int i = 0; i < sorted.size(); ++i)
  23786. {
  23787. const PluginDescription* const pd = sorted.getUnchecked(i);
  23788. String thisSubMenuName (sortMethod == sortByCategory ? pd->category
  23789. : pd->manufacturerName);
  23790. if (! thisSubMenuName.containsNonWhitespaceChars())
  23791. thisSubMenuName = T("Other");
  23792. if (thisSubMenuName != lastSubMenuName)
  23793. {
  23794. if (sub.getNumItems() > 0)
  23795. {
  23796. menu.addSubMenu (lastSubMenuName, sub);
  23797. sub.clear();
  23798. }
  23799. lastSubMenuName = thisSubMenuName;
  23800. }
  23801. sub.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23802. }
  23803. if (sub.getNumItems() > 0)
  23804. menu.addSubMenu (lastSubMenuName, sub);
  23805. }
  23806. else if (sortMethod == sortByFileSystemLocation)
  23807. {
  23808. PluginFilesystemTree root;
  23809. root.buildTree (sorted);
  23810. root.addToMenu (menu, types);
  23811. }
  23812. else
  23813. {
  23814. for (int i = 0; i < sorted.size(); ++i)
  23815. {
  23816. const PluginDescription* const pd = sorted.getUnchecked(i);
  23817. menu.addItem (types.indexOf (pd) + menuIdBase, pd->name, true, false);
  23818. }
  23819. }
  23820. }
  23821. int KnownPluginList::getIndexChosenByMenu (const int menuResultCode) const
  23822. {
  23823. const int i = menuResultCode - menuIdBase;
  23824. return (((unsigned int) i) < (unsigned int) types.size()) ? i : -1;
  23825. }
  23826. END_JUCE_NAMESPACE
  23827. /*** End of inlined file: juce_KnownPluginList.cpp ***/
  23828. /*** Start of inlined file: juce_PluginDescription.cpp ***/
  23829. BEGIN_JUCE_NAMESPACE
  23830. PluginDescription::PluginDescription() throw()
  23831. : uid (0),
  23832. isInstrument (false),
  23833. numInputChannels (0),
  23834. numOutputChannels (0)
  23835. {
  23836. }
  23837. PluginDescription::~PluginDescription() throw()
  23838. {
  23839. }
  23840. PluginDescription::PluginDescription (const PluginDescription& other) throw()
  23841. : name (other.name),
  23842. pluginFormatName (other.pluginFormatName),
  23843. category (other.category),
  23844. manufacturerName (other.manufacturerName),
  23845. version (other.version),
  23846. fileOrIdentifier (other.fileOrIdentifier),
  23847. lastFileModTime (other.lastFileModTime),
  23848. uid (other.uid),
  23849. isInstrument (other.isInstrument),
  23850. numInputChannels (other.numInputChannels),
  23851. numOutputChannels (other.numOutputChannels)
  23852. {
  23853. }
  23854. PluginDescription& PluginDescription::operator= (const PluginDescription& other) throw()
  23855. {
  23856. name = other.name;
  23857. pluginFormatName = other.pluginFormatName;
  23858. category = other.category;
  23859. manufacturerName = other.manufacturerName;
  23860. version = other.version;
  23861. fileOrIdentifier = other.fileOrIdentifier;
  23862. uid = other.uid;
  23863. isInstrument = other.isInstrument;
  23864. lastFileModTime = other.lastFileModTime;
  23865. numInputChannels = other.numInputChannels;
  23866. numOutputChannels = other.numOutputChannels;
  23867. return *this;
  23868. }
  23869. bool PluginDescription::isDuplicateOf (const PluginDescription& other) const
  23870. {
  23871. return fileOrIdentifier == other.fileOrIdentifier
  23872. && uid == other.uid;
  23873. }
  23874. const String PluginDescription::createIdentifierString() const throw()
  23875. {
  23876. return pluginFormatName
  23877. + T("-") + name
  23878. + T("-") + String::toHexString (fileOrIdentifier.hashCode())
  23879. + T("-") + String::toHexString (uid);
  23880. }
  23881. XmlElement* PluginDescription::createXml() const
  23882. {
  23883. XmlElement* const e = new XmlElement (T("PLUGIN"));
  23884. e->setAttribute (T("name"), name);
  23885. e->setAttribute (T("format"), pluginFormatName);
  23886. e->setAttribute (T("category"), category);
  23887. e->setAttribute (T("manufacturer"), manufacturerName);
  23888. e->setAttribute (T("version"), version);
  23889. e->setAttribute (T("file"), fileOrIdentifier);
  23890. e->setAttribute (T("uid"), String::toHexString (uid));
  23891. e->setAttribute (T("isInstrument"), isInstrument);
  23892. e->setAttribute (T("fileTime"), String::toHexString (lastFileModTime.toMilliseconds()));
  23893. e->setAttribute (T("numInputs"), numInputChannels);
  23894. e->setAttribute (T("numOutputs"), numOutputChannels);
  23895. return e;
  23896. }
  23897. bool PluginDescription::loadFromXml (const XmlElement& xml)
  23898. {
  23899. if (xml.hasTagName (T("PLUGIN")))
  23900. {
  23901. name = xml.getStringAttribute (T("name"));
  23902. pluginFormatName = xml.getStringAttribute (T("format"));
  23903. category = xml.getStringAttribute (T("category"));
  23904. manufacturerName = xml.getStringAttribute (T("manufacturer"));
  23905. version = xml.getStringAttribute (T("version"));
  23906. fileOrIdentifier = xml.getStringAttribute (T("file"));
  23907. uid = xml.getStringAttribute (T("uid")).getHexValue32();
  23908. isInstrument = xml.getBoolAttribute (T("isInstrument"), false);
  23909. lastFileModTime = Time (xml.getStringAttribute (T("fileTime")).getHexValue64());
  23910. numInputChannels = xml.getIntAttribute (T("numInputs"));
  23911. numOutputChannels = xml.getIntAttribute (T("numOutputs"));
  23912. return true;
  23913. }
  23914. return false;
  23915. }
  23916. END_JUCE_NAMESPACE
  23917. /*** End of inlined file: juce_PluginDescription.cpp ***/
  23918. /*** Start of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23919. BEGIN_JUCE_NAMESPACE
  23920. PluginDirectoryScanner::PluginDirectoryScanner (KnownPluginList& listToAddTo,
  23921. AudioPluginFormat& formatToLookFor,
  23922. FileSearchPath directoriesToSearch,
  23923. const bool recursive,
  23924. const File& deadMansPedalFile_)
  23925. : list (listToAddTo),
  23926. format (formatToLookFor),
  23927. deadMansPedalFile (deadMansPedalFile_),
  23928. nextIndex (0),
  23929. progress (0)
  23930. {
  23931. directoriesToSearch.removeRedundantPaths();
  23932. filesOrIdentifiersToScan = format.searchPathsForPlugins (directoriesToSearch, recursive);
  23933. // If any plugins have crashed recently when being loaded, move them to the
  23934. // end of the list to give the others a chance to load correctly..
  23935. const StringArray crashedPlugins (getDeadMansPedalFile());
  23936. for (int i = 0; i < crashedPlugins.size(); ++i)
  23937. {
  23938. const String f = crashedPlugins[i];
  23939. for (int j = filesOrIdentifiersToScan.size(); --j >= 0;)
  23940. if (f == filesOrIdentifiersToScan[j])
  23941. filesOrIdentifiersToScan.move (j, -1);
  23942. }
  23943. }
  23944. PluginDirectoryScanner::~PluginDirectoryScanner()
  23945. {
  23946. }
  23947. const String PluginDirectoryScanner::getNextPluginFileThatWillBeScanned() const throw()
  23948. {
  23949. return format.getNameOfPluginFromIdentifier (filesOrIdentifiersToScan [nextIndex]);
  23950. }
  23951. bool PluginDirectoryScanner::scanNextFile (const bool dontRescanIfAlreadyInList)
  23952. {
  23953. String file (filesOrIdentifiersToScan [nextIndex]);
  23954. if (file.isNotEmpty())
  23955. {
  23956. if (! list.isListingUpToDate (file))
  23957. {
  23958. OwnedArray <PluginDescription> typesFound;
  23959. // Add this plugin to the end of the dead-man's pedal list in case it crashes...
  23960. StringArray crashedPlugins (getDeadMansPedalFile());
  23961. crashedPlugins.removeString (file);
  23962. crashedPlugins.add (file);
  23963. setDeadMansPedalFile (crashedPlugins);
  23964. list.scanAndAddFile (file,
  23965. dontRescanIfAlreadyInList,
  23966. typesFound,
  23967. format);
  23968. // Managed to load without crashing, so remove it from the dead-man's-pedal..
  23969. crashedPlugins.removeString (file);
  23970. setDeadMansPedalFile (crashedPlugins);
  23971. if (typesFound.size() == 0)
  23972. failedFiles.add (file);
  23973. }
  23974. ++nextIndex;
  23975. progress = nextIndex / (float) filesOrIdentifiersToScan.size();
  23976. }
  23977. return nextIndex < filesOrIdentifiersToScan.size();
  23978. }
  23979. const StringArray PluginDirectoryScanner::getDeadMansPedalFile() throw()
  23980. {
  23981. StringArray lines;
  23982. if (deadMansPedalFile != File::nonexistent)
  23983. {
  23984. lines.addLines (deadMansPedalFile.loadFileAsString());
  23985. lines.removeEmptyStrings();
  23986. }
  23987. return lines;
  23988. }
  23989. void PluginDirectoryScanner::setDeadMansPedalFile (const StringArray& newContents) throw()
  23990. {
  23991. if (deadMansPedalFile != File::nonexistent)
  23992. deadMansPedalFile.replaceWithText (newContents.joinIntoString ("\n"), true, true);
  23993. }
  23994. END_JUCE_NAMESPACE
  23995. /*** End of inlined file: juce_PluginDirectoryScanner.cpp ***/
  23996. /*** Start of inlined file: juce_PluginListComponent.cpp ***/
  23997. BEGIN_JUCE_NAMESPACE
  23998. PluginListComponent::PluginListComponent (KnownPluginList& listToEdit,
  23999. const File& deadMansPedalFile_,
  24000. PropertiesFile* const propertiesToUse_)
  24001. : list (listToEdit),
  24002. deadMansPedalFile (deadMansPedalFile_),
  24003. propertiesToUse (propertiesToUse_)
  24004. {
  24005. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  24006. addAndMakeVisible (optionsButton = new TextButton ("Options..."));
  24007. optionsButton->addButtonListener (this);
  24008. optionsButton->setTriggeredOnMouseDown (true);
  24009. setSize (400, 600);
  24010. list.addChangeListener (this);
  24011. }
  24012. PluginListComponent::~PluginListComponent()
  24013. {
  24014. list.removeChangeListener (this);
  24015. deleteAllChildren();
  24016. }
  24017. void PluginListComponent::resized()
  24018. {
  24019. listBox->setBounds (0, 0, getWidth(), getHeight() - 30);
  24020. optionsButton->changeWidthToFitText (24);
  24021. optionsButton->setTopLeftPosition (8, getHeight() - 28);
  24022. }
  24023. void PluginListComponent::changeListenerCallback (void*)
  24024. {
  24025. listBox->updateContent();
  24026. listBox->repaint();
  24027. }
  24028. int PluginListComponent::getNumRows()
  24029. {
  24030. return list.getNumTypes();
  24031. }
  24032. void PluginListComponent::paintListBoxItem (int row,
  24033. Graphics& g,
  24034. int width, int height,
  24035. bool rowIsSelected)
  24036. {
  24037. if (rowIsSelected)
  24038. g.fillAll (findColour (TextEditor::highlightColourId));
  24039. const PluginDescription* const pd = list.getType (row);
  24040. if (pd != 0)
  24041. {
  24042. GlyphArrangement ga;
  24043. ga.addCurtailedLineOfText (Font (height * 0.7f, Font::bold), pd->name, 8.0f, height * 0.8f, width - 10.0f, true);
  24044. g.setColour (Colours::black);
  24045. ga.draw (g);
  24046. float x, y, r, b;
  24047. ga.getBoundingBox (0, -1, x, y, r, b, false);
  24048. String desc;
  24049. desc << pd->pluginFormatName
  24050. << (pd->isInstrument ? " instrument" : " effect")
  24051. << " - "
  24052. << pd->numInputChannels << (pd->numInputChannels == 1 ? " in" : " ins")
  24053. << " / "
  24054. << pd->numOutputChannels << (pd->numOutputChannels == 1 ? " out" : " outs");
  24055. if (pd->manufacturerName.isNotEmpty())
  24056. desc << " - " << pd->manufacturerName;
  24057. if (pd->version.isNotEmpty())
  24058. desc << " - " << pd->version;
  24059. if (pd->category.isNotEmpty())
  24060. desc << " - category: '" << pd->category << '\'';
  24061. g.setColour (Colours::grey);
  24062. ga.clear();
  24063. ga.addCurtailedLineOfText (Font (height * 0.6f), desc, r + 10.0f, height * 0.8f, width - r - 12.0f, true);
  24064. ga.draw (g);
  24065. }
  24066. }
  24067. void PluginListComponent::deleteKeyPressed (int lastRowSelected)
  24068. {
  24069. list.removeType (lastRowSelected);
  24070. }
  24071. void PluginListComponent::buttonClicked (Button* b)
  24072. {
  24073. if (optionsButton == b)
  24074. {
  24075. PopupMenu menu;
  24076. menu.addItem (1, TRANS("Clear list"));
  24077. menu.addItem (5, TRANS("Remove selected plugin from list"), listBox->getNumSelectedRows() > 0);
  24078. menu.addItem (6, TRANS("Show folder containing selected plugin"), listBox->getNumSelectedRows() > 0);
  24079. menu.addItem (7, TRANS("Remove any plugins whose files no longer exist"));
  24080. menu.addSeparator();
  24081. menu.addItem (2, TRANS("Sort alphabetically"));
  24082. menu.addItem (3, TRANS("Sort by category"));
  24083. menu.addItem (4, TRANS("Sort by manufacturer"));
  24084. menu.addSeparator();
  24085. for (int i = 0; i < AudioPluginFormatManager::getInstance()->getNumFormats(); ++i)
  24086. {
  24087. AudioPluginFormat* const format = AudioPluginFormatManager::getInstance()->getFormat (i);
  24088. if (format->getDefaultLocationsToSearch().getNumPaths() > 0)
  24089. menu.addItem (10 + i, "Scan for new or updated " + format->getName() + " plugins...");
  24090. }
  24091. const int r = menu.showAt (optionsButton);
  24092. if (r == 1)
  24093. {
  24094. list.clear();
  24095. }
  24096. else if (r == 2)
  24097. {
  24098. list.sort (KnownPluginList::sortAlphabetically);
  24099. }
  24100. else if (r == 3)
  24101. {
  24102. list.sort (KnownPluginList::sortByCategory);
  24103. }
  24104. else if (r == 4)
  24105. {
  24106. list.sort (KnownPluginList::sortByManufacturer);
  24107. }
  24108. else if (r == 5)
  24109. {
  24110. const SparseSet <int> selected (listBox->getSelectedRows());
  24111. for (int i = list.getNumTypes(); --i >= 0;)
  24112. if (selected.contains (i))
  24113. list.removeType (i);
  24114. }
  24115. else if (r == 6)
  24116. {
  24117. const PluginDescription* const desc = list.getType (listBox->getSelectedRow());
  24118. if (desc != 0)
  24119. {
  24120. if (File (desc->fileOrIdentifier).existsAsFile())
  24121. File (desc->fileOrIdentifier).getParentDirectory().startAsProcess();
  24122. }
  24123. }
  24124. else if (r == 7)
  24125. {
  24126. for (int i = list.getNumTypes(); --i >= 0;)
  24127. {
  24128. if (! AudioPluginFormatManager::getInstance()->doesPluginStillExist (*list.getType (i)))
  24129. {
  24130. list.removeType (i);
  24131. }
  24132. }
  24133. }
  24134. else if (r != 0)
  24135. {
  24136. typeToScan = r - 10;
  24137. startTimer (1);
  24138. }
  24139. }
  24140. }
  24141. void PluginListComponent::timerCallback()
  24142. {
  24143. stopTimer();
  24144. scanFor (AudioPluginFormatManager::getInstance()->getFormat (typeToScan));
  24145. }
  24146. bool PluginListComponent::isInterestedInFileDrag (const StringArray& /*files*/)
  24147. {
  24148. return true;
  24149. }
  24150. void PluginListComponent::filesDropped (const StringArray& files, int, int)
  24151. {
  24152. OwnedArray <PluginDescription> typesFound;
  24153. list.scanAndAddDragAndDroppedFiles (files, typesFound);
  24154. }
  24155. void PluginListComponent::scanFor (AudioPluginFormat* format)
  24156. {
  24157. if (format == 0)
  24158. return;
  24159. FileSearchPath path (format->getDefaultLocationsToSearch());
  24160. if (propertiesToUse != 0)
  24161. path = propertiesToUse->getValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24162. {
  24163. AlertWindow aw (TRANS("Select folders to scan..."), String::empty, AlertWindow::NoIcon);
  24164. FileSearchPathListComponent pathList;
  24165. pathList.setSize (500, 300);
  24166. pathList.setPath (path);
  24167. aw.addCustomComponent (&pathList);
  24168. aw.addButton (TRANS("Scan"), 1, KeyPress::returnKey);
  24169. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24170. if (aw.runModalLoop() == 0)
  24171. return;
  24172. path = pathList.getPath();
  24173. }
  24174. if (propertiesToUse != 0)
  24175. {
  24176. propertiesToUse->setValue ("lastPluginScanPath_" + format->getName(), path.toString());
  24177. propertiesToUse->saveIfNeeded();
  24178. }
  24179. double progress = 0.0;
  24180. AlertWindow aw (TRANS("Scanning for plugins..."),
  24181. TRANS("Searching for all possible plugin files..."), AlertWindow::NoIcon);
  24182. aw.addButton (TRANS("Cancel"), 0, KeyPress (KeyPress::escapeKey));
  24183. aw.addProgressBarComponent (progress);
  24184. aw.enterModalState();
  24185. MessageManager::getInstance()->runDispatchLoopUntil (300);
  24186. PluginDirectoryScanner scanner (list, *format, path, true, deadMansPedalFile);
  24187. for (;;)
  24188. {
  24189. aw.setMessage (TRANS("Testing:\n\n")
  24190. + scanner.getNextPluginFileThatWillBeScanned());
  24191. MessageManager::getInstance()->runDispatchLoopUntil (20);
  24192. if (! scanner.scanNextFile (true))
  24193. break;
  24194. if (! aw.isCurrentlyModal())
  24195. break;
  24196. progress = scanner.getProgress();
  24197. }
  24198. if (scanner.getFailedFiles().size() > 0)
  24199. {
  24200. StringArray shortNames;
  24201. for (int i = 0; i < scanner.getFailedFiles().size(); ++i)
  24202. shortNames.add (File (scanner.getFailedFiles()[i]).getFileName());
  24203. AlertWindow::showMessageBox (AlertWindow::InfoIcon,
  24204. TRANS("Scan complete"),
  24205. TRANS("Note that the following files appeared to be plugin files, but failed to load correctly:\n\n")
  24206. + shortNames.joinIntoString (", "));
  24207. }
  24208. }
  24209. END_JUCE_NAMESPACE
  24210. /*** End of inlined file: juce_PluginListComponent.cpp ***/
  24211. /*** Start of inlined file: juce_AudioUnitPluginFormat.mm ***/
  24212. #if JUCE_PLUGINHOST_AU && (! (defined (LINUX) || defined (_WIN32)))
  24213. #include <AudioUnit/AudioUnit.h>
  24214. #include <AudioUnit/AUCocoaUIView.h>
  24215. #include <CoreAudioKit/AUGenericView.h>
  24216. #if JUCE_SUPPORT_CARBON
  24217. #include <AudioToolbox/AudioUnitUtilities.h>
  24218. #include <AudioUnit/AudioUnitCarbonView.h>
  24219. #endif
  24220. BEGIN_JUCE_NAMESPACE
  24221. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  24222. #endif
  24223. #if JUCE_MAC
  24224. // Change this to disable logging of various activities
  24225. #ifndef AU_LOGGING
  24226. #define AU_LOGGING 1
  24227. #endif
  24228. #if AU_LOGGING
  24229. #define log(a) Logger::writeToLog(a);
  24230. #else
  24231. #define log(a)
  24232. #endif
  24233. static int insideCallback = 0;
  24234. static const String osTypeToString (OSType type) throw()
  24235. {
  24236. char s[4];
  24237. s[0] = (char) (((uint32) type) >> 24);
  24238. s[1] = (char) (((uint32) type) >> 16);
  24239. s[2] = (char) (((uint32) type) >> 8);
  24240. s[3] = (char) ((uint32) type);
  24241. return String (s, 4);
  24242. }
  24243. static OSType stringToOSType (const String& s1) throw()
  24244. {
  24245. const String s (s1 + " ");
  24246. return (((OSType) (unsigned char) s[0]) << 24)
  24247. | (((OSType) (unsigned char) s[1]) << 16)
  24248. | (((OSType) (unsigned char) s[2]) << 8)
  24249. | ((OSType) (unsigned char) s[3]);
  24250. }
  24251. static const tchar* auIdentifierPrefix = T("AudioUnit:");
  24252. static const String createAUPluginIdentifier (const ComponentDescription& desc)
  24253. {
  24254. jassert (osTypeToString ('abcd') == T("abcd")); // agh, must have got the endianness wrong..
  24255. jassert (stringToOSType ("abcd") == (OSType) 'abcd'); // ditto
  24256. String s (auIdentifierPrefix);
  24257. if (desc.componentType == kAudioUnitType_MusicDevice)
  24258. s << "Synths/";
  24259. else if (desc.componentType == kAudioUnitType_MusicEffect
  24260. || desc.componentType == kAudioUnitType_Effect)
  24261. s << "Effects/";
  24262. else if (desc.componentType == kAudioUnitType_Generator)
  24263. s << "Generators/";
  24264. else if (desc.componentType == kAudioUnitType_Panner)
  24265. s << "Panners/";
  24266. s << osTypeToString (desc.componentType)
  24267. << T(",")
  24268. << osTypeToString (desc.componentSubType)
  24269. << T(",")
  24270. << osTypeToString (desc.componentManufacturer);
  24271. return s;
  24272. }
  24273. static void getAUDetails (ComponentRecord* comp, String& name, String& manufacturer)
  24274. {
  24275. Handle componentNameHandle = NewHandle (sizeof (void*));
  24276. Handle componentInfoHandle = NewHandle (sizeof (void*));
  24277. if (componentNameHandle != 0 && componentInfoHandle != 0)
  24278. {
  24279. ComponentDescription desc;
  24280. if (GetComponentInfo (comp, &desc, componentNameHandle, componentInfoHandle, 0) == noErr)
  24281. {
  24282. ConstStr255Param nameString = (ConstStr255Param) (*componentNameHandle);
  24283. ConstStr255Param infoString = (ConstStr255Param) (*componentInfoHandle);
  24284. if (nameString != 0 && nameString[0] != 0)
  24285. {
  24286. const String all ((const char*) nameString + 1, nameString[0]);
  24287. DBG ("name: "+ all);
  24288. manufacturer = all.upToFirstOccurrenceOf (T(":"), false, false).trim();
  24289. name = all.fromFirstOccurrenceOf (T(":"), false, false).trim();
  24290. }
  24291. if (infoString != 0 && infoString[0] != 0)
  24292. {
  24293. const String all ((const char*) infoString + 1, infoString[0]);
  24294. DBG ("info: " + all);
  24295. }
  24296. if (name.isEmpty())
  24297. name = "<Unknown>";
  24298. }
  24299. DisposeHandle (componentNameHandle);
  24300. DisposeHandle (componentInfoHandle);
  24301. }
  24302. }
  24303. static bool getComponentDescFromIdentifier (const String& fileOrIdentifier, ComponentDescription& desc,
  24304. String& name, String& version, String& manufacturer)
  24305. {
  24306. zerostruct (desc);
  24307. if (fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  24308. {
  24309. String s (fileOrIdentifier.substring (jmax (fileOrIdentifier.lastIndexOfChar (T(':')),
  24310. fileOrIdentifier.lastIndexOfChar (T('/'))) + 1));
  24311. StringArray tokens;
  24312. tokens.addTokens (s, T(","), 0);
  24313. tokens.trim();
  24314. tokens.removeEmptyStrings();
  24315. if (tokens.size() == 3)
  24316. {
  24317. desc.componentType = stringToOSType (tokens[0]);
  24318. desc.componentSubType = stringToOSType (tokens[1]);
  24319. desc.componentManufacturer = stringToOSType (tokens[2]);
  24320. ComponentRecord* comp = FindNextComponent (0, &desc);
  24321. if (comp != 0)
  24322. {
  24323. getAUDetails (comp, name, manufacturer);
  24324. return true;
  24325. }
  24326. }
  24327. }
  24328. return false;
  24329. }
  24330. class AudioUnitPluginWindowCarbon;
  24331. class AudioUnitPluginWindowCocoa;
  24332. class AudioUnitPluginInstance : public AudioPluginInstance
  24333. {
  24334. public:
  24335. ~AudioUnitPluginInstance();
  24336. // AudioPluginInstance methods:
  24337. void fillInPluginDescription (PluginDescription& desc) const
  24338. {
  24339. desc.name = pluginName;
  24340. desc.fileOrIdentifier = createAUPluginIdentifier (componentDesc);
  24341. desc.uid = ((int) componentDesc.componentType)
  24342. ^ ((int) componentDesc.componentSubType)
  24343. ^ ((int) componentDesc.componentManufacturer);
  24344. desc.lastFileModTime = 0;
  24345. desc.pluginFormatName = "AudioUnit";
  24346. desc.category = getCategory();
  24347. desc.manufacturerName = manufacturer;
  24348. desc.version = version;
  24349. desc.numInputChannels = getNumInputChannels();
  24350. desc.numOutputChannels = getNumOutputChannels();
  24351. desc.isInstrument = (componentDesc.componentType == kAudioUnitType_MusicDevice);
  24352. }
  24353. const String getName() const { return pluginName; }
  24354. bool acceptsMidi() const { return wantsMidiMessages; }
  24355. bool producesMidi() const { return false; }
  24356. // AudioProcessor methods:
  24357. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  24358. void releaseResources();
  24359. void processBlock (AudioSampleBuffer& buffer,
  24360. MidiBuffer& midiMessages);
  24361. AudioProcessorEditor* createEditor();
  24362. const String getInputChannelName (const int index) const;
  24363. bool isInputChannelStereoPair (int index) const;
  24364. const String getOutputChannelName (const int index) const;
  24365. bool isOutputChannelStereoPair (int index) const;
  24366. int getNumParameters();
  24367. float getParameter (int index);
  24368. void setParameter (int index, float newValue);
  24369. const String getParameterName (int index);
  24370. const String getParameterText (int index);
  24371. bool isParameterAutomatable (int index) const;
  24372. int getNumPrograms();
  24373. int getCurrentProgram();
  24374. void setCurrentProgram (int index);
  24375. const String getProgramName (int index);
  24376. void changeProgramName (int index, const String& newName);
  24377. void getStateInformation (MemoryBlock& destData);
  24378. void getCurrentProgramStateInformation (MemoryBlock& destData);
  24379. void setStateInformation (const void* data, int sizeInBytes);
  24380. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  24381. juce_UseDebuggingNewOperator
  24382. private:
  24383. friend class AudioUnitPluginWindowCarbon;
  24384. friend class AudioUnitPluginWindowCocoa;
  24385. friend class AudioUnitPluginFormat;
  24386. ComponentDescription componentDesc;
  24387. String pluginName, manufacturer, version;
  24388. String fileOrIdentifier;
  24389. CriticalSection lock;
  24390. bool initialised, wantsMidiMessages, wasPlaying;
  24391. HeapBlock <AudioBufferList> outputBufferList;
  24392. AudioTimeStamp timeStamp;
  24393. AudioSampleBuffer* currentBuffer;
  24394. AudioUnit audioUnit;
  24395. Array <int> parameterIds;
  24396. bool getComponentDescFromFile (const String& fileOrIdentifier);
  24397. void initialise();
  24398. OSStatus renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24399. const AudioTimeStamp* inTimeStamp,
  24400. UInt32 inBusNumber,
  24401. UInt32 inNumberFrames,
  24402. AudioBufferList* ioData) const;
  24403. static OSStatus renderGetInputCallback (void* inRefCon,
  24404. AudioUnitRenderActionFlags* ioActionFlags,
  24405. const AudioTimeStamp* inTimeStamp,
  24406. UInt32 inBusNumber,
  24407. UInt32 inNumberFrames,
  24408. AudioBufferList* ioData)
  24409. {
  24410. return ((AudioUnitPluginInstance*) inRefCon)
  24411. ->renderGetInput (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  24412. }
  24413. OSStatus getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const;
  24414. OSStatus getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat, Float32* outTimeSig_Numerator,
  24415. UInt32* outTimeSig_Denominator, Float64* outCurrentMeasureDownBeat) const;
  24416. OSStatus getTransportState (Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24417. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24418. Float64* outCycleStartBeat, Float64* outCycleEndBeat);
  24419. static OSStatus getBeatAndTempoCallback (void* inHostUserData, Float64* outCurrentBeat, Float64* outCurrentTempo)
  24420. {
  24421. return ((AudioUnitPluginInstance*) inHostUserData)->getBeatAndTempo (outCurrentBeat, outCurrentTempo);
  24422. }
  24423. static OSStatus getMusicalTimeLocationCallback (void* inHostUserData, UInt32* outDeltaSampleOffsetToNextBeat,
  24424. Float32* outTimeSig_Numerator, UInt32* outTimeSig_Denominator,
  24425. Float64* outCurrentMeasureDownBeat)
  24426. {
  24427. return ((AudioUnitPluginInstance*) inHostUserData)
  24428. ->getMusicalTimeLocation (outDeltaSampleOffsetToNextBeat, outTimeSig_Numerator,
  24429. outTimeSig_Denominator, outCurrentMeasureDownBeat);
  24430. }
  24431. static OSStatus getTransportStateCallback (void* inHostUserData, Boolean* outIsPlaying, Boolean* outTransportStateChanged,
  24432. Float64* outCurrentSampleInTimeLine, Boolean* outIsCycling,
  24433. Float64* outCycleStartBeat, Float64* outCycleEndBeat)
  24434. {
  24435. return ((AudioUnitPluginInstance*) inHostUserData)
  24436. ->getTransportState (outIsPlaying, outTransportStateChanged,
  24437. outCurrentSampleInTimeLine, outIsCycling,
  24438. outCycleStartBeat, outCycleEndBeat);
  24439. }
  24440. void getNumChannels (int& numIns, int& numOuts)
  24441. {
  24442. numIns = 0;
  24443. numOuts = 0;
  24444. AUChannelInfo supportedChannels [128];
  24445. UInt32 supportedChannelsSize = sizeof (supportedChannels);
  24446. if (AudioUnitGetProperty (audioUnit, kAudioUnitProperty_SupportedNumChannels, kAudioUnitScope_Global,
  24447. 0, supportedChannels, &supportedChannelsSize) == noErr
  24448. && supportedChannelsSize > 0)
  24449. {
  24450. for (int i = 0; i < supportedChannelsSize / sizeof (AUChannelInfo); ++i)
  24451. {
  24452. numIns = jmax (numIns, (int) supportedChannels[i].inChannels);
  24453. numOuts = jmax (numOuts, (int) supportedChannels[i].outChannels);
  24454. }
  24455. }
  24456. else
  24457. {
  24458. // (this really means the plugin will take any number of ins/outs as long
  24459. // as they are the same)
  24460. numIns = numOuts = 2;
  24461. }
  24462. }
  24463. const String getCategory() const;
  24464. AudioUnitPluginInstance (const String& fileOrIdentifier);
  24465. };
  24466. AudioUnitPluginInstance::AudioUnitPluginInstance (const String& fileOrIdentifier)
  24467. : fileOrIdentifier (fileOrIdentifier),
  24468. initialised (false),
  24469. wantsMidiMessages (false),
  24470. audioUnit (0),
  24471. currentBuffer (0)
  24472. {
  24473. try
  24474. {
  24475. ++insideCallback;
  24476. log (T("Opening AU: ") + fileOrIdentifier);
  24477. if (getComponentDescFromFile (fileOrIdentifier))
  24478. {
  24479. ComponentRecord* const comp = FindNextComponent (0, &componentDesc);
  24480. if (comp != 0)
  24481. {
  24482. audioUnit = (AudioUnit) OpenComponent (comp);
  24483. wantsMidiMessages = componentDesc.componentType == kAudioUnitType_MusicDevice
  24484. || componentDesc.componentType == kAudioUnitType_MusicEffect;
  24485. }
  24486. }
  24487. --insideCallback;
  24488. }
  24489. catch (...)
  24490. {
  24491. --insideCallback;
  24492. }
  24493. }
  24494. AudioUnitPluginInstance::~AudioUnitPluginInstance()
  24495. {
  24496. {
  24497. const ScopedLock sl (lock);
  24498. jassert (insideCallback == 0);
  24499. if (audioUnit != 0)
  24500. {
  24501. AudioUnitUninitialize (audioUnit);
  24502. CloseComponent (audioUnit);
  24503. audioUnit = 0;
  24504. }
  24505. }
  24506. }
  24507. bool AudioUnitPluginInstance::getComponentDescFromFile (const String& fileOrIdentifier)
  24508. {
  24509. zerostruct (componentDesc);
  24510. if (getComponentDescFromIdentifier (fileOrIdentifier, componentDesc, pluginName, version, manufacturer))
  24511. return true;
  24512. const File file (fileOrIdentifier);
  24513. if (! file.hasFileExtension (T(".component")))
  24514. return false;
  24515. const char* const utf8 = fileOrIdentifier.toUTF8();
  24516. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  24517. strlen (utf8), file.isDirectory());
  24518. if (url != 0)
  24519. {
  24520. CFBundleRef bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  24521. CFRelease (url);
  24522. if (bundleRef != 0)
  24523. {
  24524. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  24525. if (name != 0 && CFGetTypeID (name) == CFStringGetTypeID())
  24526. pluginName = PlatformUtilities::cfStringToJuceString ((CFStringRef) name);
  24527. if (pluginName.isEmpty())
  24528. pluginName = file.getFileNameWithoutExtension();
  24529. CFTypeRef versionString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleVersion"));
  24530. if (versionString != 0 && CFGetTypeID (versionString) == CFStringGetTypeID())
  24531. version = PlatformUtilities::cfStringToJuceString ((CFStringRef) versionString);
  24532. CFTypeRef manuString = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleGetInfoString"));
  24533. if (manuString != 0 && CFGetTypeID (manuString) == CFStringGetTypeID())
  24534. manufacturer = PlatformUtilities::cfStringToJuceString ((CFStringRef) manuString);
  24535. short resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  24536. UseResFile (resFileId);
  24537. for (int i = 1; i <= Count1Resources ('thng'); ++i)
  24538. {
  24539. Handle h = Get1IndResource ('thng', i);
  24540. if (h != 0)
  24541. {
  24542. HLock (h);
  24543. const uint32* const types = (const uint32*) *h;
  24544. if (types[0] == kAudioUnitType_MusicDevice
  24545. || types[0] == kAudioUnitType_MusicEffect
  24546. || types[0] == kAudioUnitType_Effect
  24547. || types[0] == kAudioUnitType_Generator
  24548. || types[0] == kAudioUnitType_Panner)
  24549. {
  24550. componentDesc.componentType = types[0];
  24551. componentDesc.componentSubType = types[1];
  24552. componentDesc.componentManufacturer = types[2];
  24553. break;
  24554. }
  24555. HUnlock (h);
  24556. ReleaseResource (h);
  24557. }
  24558. }
  24559. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  24560. CFRelease (bundleRef);
  24561. }
  24562. }
  24563. return componentDesc.componentType != 0 && componentDesc.componentSubType != 0;
  24564. }
  24565. void AudioUnitPluginInstance::initialise()
  24566. {
  24567. if (initialised || audioUnit == 0)
  24568. return;
  24569. log (T("Initialising AU: ") + pluginName);
  24570. parameterIds.clear();
  24571. {
  24572. UInt32 paramListSize = 0;
  24573. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24574. 0, 0, &paramListSize);
  24575. if (paramListSize > 0)
  24576. {
  24577. parameterIds.insertMultiple (0, 0, paramListSize / sizeof (int));
  24578. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_ParameterList, kAudioUnitScope_Global,
  24579. 0, &parameterIds.getReference(0), &paramListSize);
  24580. }
  24581. }
  24582. {
  24583. AURenderCallbackStruct info;
  24584. zerostruct (info);
  24585. info.inputProcRefCon = this;
  24586. info.inputProc = renderGetInputCallback;
  24587. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input,
  24588. 0, &info, sizeof (info));
  24589. }
  24590. {
  24591. HostCallbackInfo info;
  24592. zerostruct (info);
  24593. info.hostUserData = this;
  24594. info.beatAndTempoProc = getBeatAndTempoCallback;
  24595. info.musicalTimeLocationProc = getMusicalTimeLocationCallback;
  24596. info.transportStateProc = getTransportStateCallback;
  24597. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_HostCallbacks, kAudioUnitScope_Global,
  24598. 0, &info, sizeof (info));
  24599. }
  24600. int numIns, numOuts;
  24601. getNumChannels (numIns, numOuts);
  24602. setPlayConfigDetails (numIns, numOuts, 0, 0);
  24603. initialised = AudioUnitInitialize (audioUnit) == noErr;
  24604. setLatencySamples (0);
  24605. }
  24606. void AudioUnitPluginInstance::prepareToPlay (double sampleRate_,
  24607. int samplesPerBlockExpected)
  24608. {
  24609. initialise();
  24610. if (initialised)
  24611. {
  24612. int numIns, numOuts;
  24613. getNumChannels (numIns, numOuts);
  24614. setPlayConfigDetails (numIns, numOuts, sampleRate_, samplesPerBlockExpected);
  24615. Float64 latencySecs = 0.0;
  24616. UInt32 latencySize = sizeof (latencySecs);
  24617. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_Latency, kAudioUnitScope_Global,
  24618. 0, &latencySecs, &latencySize);
  24619. setLatencySamples (roundToInt (latencySecs * sampleRate_));
  24620. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24621. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24622. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24623. AudioStreamBasicDescription stream;
  24624. zerostruct (stream);
  24625. stream.mSampleRate = sampleRate_;
  24626. stream.mFormatID = kAudioFormatLinearPCM;
  24627. stream.mFormatFlags = kAudioFormatFlagsNativeFloatPacked | kAudioFormatFlagIsNonInterleaved;
  24628. stream.mFramesPerPacket = 1;
  24629. stream.mBytesPerPacket = 4;
  24630. stream.mBytesPerFrame = 4;
  24631. stream.mBitsPerChannel = 32;
  24632. stream.mChannelsPerFrame = numIns;
  24633. OSStatus err = AudioUnitSetProperty (audioUnit,
  24634. kAudioUnitProperty_StreamFormat,
  24635. kAudioUnitScope_Input,
  24636. 0, &stream, sizeof (stream));
  24637. stream.mChannelsPerFrame = numOuts;
  24638. err = AudioUnitSetProperty (audioUnit,
  24639. kAudioUnitProperty_StreamFormat,
  24640. kAudioUnitScope_Output,
  24641. 0, &stream, sizeof (stream));
  24642. outputBufferList.calloc (sizeof (AudioBufferList) + sizeof (AudioBuffer) * (numOuts + 1), 1);
  24643. outputBufferList->mNumberBuffers = numOuts;
  24644. for (int i = numOuts; --i >= 0;)
  24645. outputBufferList->mBuffers[i].mNumberChannels = 1;
  24646. zerostruct (timeStamp);
  24647. timeStamp.mSampleTime = 0;
  24648. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24649. timeStamp.mFlags = kAudioTimeStampSampleTimeValid | kAudioTimeStampHostTimeValid;
  24650. currentBuffer = 0;
  24651. wasPlaying = false;
  24652. }
  24653. }
  24654. void AudioUnitPluginInstance::releaseResources()
  24655. {
  24656. if (initialised)
  24657. {
  24658. AudioUnitReset (audioUnit, kAudioUnitScope_Input, 0);
  24659. AudioUnitReset (audioUnit, kAudioUnitScope_Output, 0);
  24660. AudioUnitReset (audioUnit, kAudioUnitScope_Global, 0);
  24661. outputBufferList.free();
  24662. currentBuffer = 0;
  24663. }
  24664. }
  24665. OSStatus AudioUnitPluginInstance::renderGetInput (AudioUnitRenderActionFlags* ioActionFlags,
  24666. const AudioTimeStamp* inTimeStamp,
  24667. UInt32 inBusNumber,
  24668. UInt32 inNumberFrames,
  24669. AudioBufferList* ioData) const
  24670. {
  24671. if (inBusNumber == 0
  24672. && currentBuffer != 0)
  24673. {
  24674. jassert (inNumberFrames == currentBuffer->getNumSamples()); // if this ever happens, might need to add extra handling
  24675. for (int i = 0; i < ioData->mNumberBuffers; ++i)
  24676. {
  24677. if (i < currentBuffer->getNumChannels())
  24678. {
  24679. memcpy (ioData->mBuffers[i].mData,
  24680. currentBuffer->getSampleData (i, 0),
  24681. sizeof (float) * inNumberFrames);
  24682. }
  24683. else
  24684. {
  24685. zeromem (ioData->mBuffers[i].mData, sizeof (float) * inNumberFrames);
  24686. }
  24687. }
  24688. }
  24689. return noErr;
  24690. }
  24691. void AudioUnitPluginInstance::processBlock (AudioSampleBuffer& buffer,
  24692. MidiBuffer& midiMessages)
  24693. {
  24694. const int numSamples = buffer.getNumSamples();
  24695. if (initialised)
  24696. {
  24697. AudioUnitRenderActionFlags flags = 0;
  24698. timeStamp.mHostTime = AudioGetCurrentHostTime();
  24699. for (int i = getNumOutputChannels(); --i >= 0;)
  24700. {
  24701. outputBufferList->mBuffers[i].mDataByteSize = sizeof (float) * numSamples;
  24702. outputBufferList->mBuffers[i].mData = buffer.getSampleData (i, 0);
  24703. }
  24704. currentBuffer = &buffer;
  24705. if (wantsMidiMessages)
  24706. {
  24707. const uint8* midiEventData;
  24708. int midiEventSize, midiEventPosition;
  24709. MidiBuffer::Iterator i (midiMessages);
  24710. while (i.getNextEvent (midiEventData, midiEventSize, midiEventPosition))
  24711. {
  24712. if (midiEventSize <= 3)
  24713. MusicDeviceMIDIEvent (audioUnit,
  24714. midiEventData[0], midiEventData[1], midiEventData[2],
  24715. midiEventPosition);
  24716. else
  24717. MusicDeviceSysEx (audioUnit, midiEventData, midiEventSize);
  24718. }
  24719. midiMessages.clear();
  24720. }
  24721. AudioUnitRender (audioUnit, &flags, &timeStamp,
  24722. 0, numSamples, outputBufferList);
  24723. timeStamp.mSampleTime += numSamples;
  24724. }
  24725. else
  24726. {
  24727. // Not initialised, so just bypass..
  24728. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  24729. buffer.clear (i, 0, buffer.getNumSamples());
  24730. }
  24731. }
  24732. OSStatus AudioUnitPluginInstance::getBeatAndTempo (Float64* outCurrentBeat, Float64* outCurrentTempo) const
  24733. {
  24734. AudioPlayHead* const ph = getPlayHead();
  24735. AudioPlayHead::CurrentPositionInfo result;
  24736. if (ph != 0 && ph->getCurrentPosition (result))
  24737. {
  24738. if (outCurrentBeat != 0)
  24739. *outCurrentBeat = result.ppqPosition;
  24740. if (outCurrentTempo != 0)
  24741. *outCurrentTempo = result.bpm;
  24742. }
  24743. else
  24744. {
  24745. if (outCurrentBeat != 0)
  24746. *outCurrentBeat = 0;
  24747. if (outCurrentTempo != 0)
  24748. *outCurrentTempo = 120.0;
  24749. }
  24750. return noErr;
  24751. }
  24752. OSStatus AudioUnitPluginInstance::getMusicalTimeLocation (UInt32* outDeltaSampleOffsetToNextBeat,
  24753. Float32* outTimeSig_Numerator,
  24754. UInt32* outTimeSig_Denominator,
  24755. Float64* outCurrentMeasureDownBeat) const
  24756. {
  24757. AudioPlayHead* const ph = getPlayHead();
  24758. AudioPlayHead::CurrentPositionInfo result;
  24759. if (ph != 0 && ph->getCurrentPosition (result))
  24760. {
  24761. if (outTimeSig_Numerator != 0)
  24762. *outTimeSig_Numerator = result.timeSigNumerator;
  24763. if (outTimeSig_Denominator != 0)
  24764. *outTimeSig_Denominator = result.timeSigDenominator;
  24765. if (outDeltaSampleOffsetToNextBeat != 0)
  24766. *outDeltaSampleOffsetToNextBeat = 0; //xxx
  24767. if (outCurrentMeasureDownBeat != 0)
  24768. *outCurrentMeasureDownBeat = result.ppqPositionOfLastBarStart; //xxx wrong
  24769. }
  24770. else
  24771. {
  24772. if (outDeltaSampleOffsetToNextBeat != 0)
  24773. *outDeltaSampleOffsetToNextBeat = 0;
  24774. if (outTimeSig_Numerator != 0)
  24775. *outTimeSig_Numerator = 4;
  24776. if (outTimeSig_Denominator != 0)
  24777. *outTimeSig_Denominator = 4;
  24778. if (outCurrentMeasureDownBeat != 0)
  24779. *outCurrentMeasureDownBeat = 0;
  24780. }
  24781. return noErr;
  24782. }
  24783. OSStatus AudioUnitPluginInstance::getTransportState (Boolean* outIsPlaying,
  24784. Boolean* outTransportStateChanged,
  24785. Float64* outCurrentSampleInTimeLine,
  24786. Boolean* outIsCycling,
  24787. Float64* outCycleStartBeat,
  24788. Float64* outCycleEndBeat)
  24789. {
  24790. AudioPlayHead* const ph = getPlayHead();
  24791. AudioPlayHead::CurrentPositionInfo result;
  24792. if (ph != 0 && ph->getCurrentPosition (result))
  24793. {
  24794. if (outIsPlaying != 0)
  24795. *outIsPlaying = result.isPlaying;
  24796. if (outTransportStateChanged != 0)
  24797. {
  24798. *outTransportStateChanged = result.isPlaying != wasPlaying;
  24799. wasPlaying = result.isPlaying;
  24800. }
  24801. if (outCurrentSampleInTimeLine != 0)
  24802. *outCurrentSampleInTimeLine = roundToInt (result.timeInSeconds * getSampleRate());
  24803. if (outIsCycling != 0)
  24804. *outIsCycling = false;
  24805. if (outCycleStartBeat != 0)
  24806. *outCycleStartBeat = 0;
  24807. if (outCycleEndBeat != 0)
  24808. *outCycleEndBeat = 0;
  24809. }
  24810. else
  24811. {
  24812. if (outIsPlaying != 0)
  24813. *outIsPlaying = false;
  24814. if (outTransportStateChanged != 0)
  24815. *outTransportStateChanged = false;
  24816. if (outCurrentSampleInTimeLine != 0)
  24817. *outCurrentSampleInTimeLine = 0;
  24818. if (outIsCycling != 0)
  24819. *outIsCycling = false;
  24820. if (outCycleStartBeat != 0)
  24821. *outCycleStartBeat = 0;
  24822. if (outCycleEndBeat != 0)
  24823. *outCycleEndBeat = 0;
  24824. }
  24825. return noErr;
  24826. }
  24827. static VoidArray activeWindows;
  24828. class AudioUnitPluginWindowCocoa : public AudioProcessorEditor
  24829. {
  24830. public:
  24831. AudioUnitPluginWindowCocoa (AudioUnitPluginInstance& plugin_, const bool createGenericViewIfNeeded)
  24832. : AudioProcessorEditor (&plugin_),
  24833. plugin (plugin_),
  24834. wrapper (0)
  24835. {
  24836. addAndMakeVisible (wrapper = new NSViewComponent());
  24837. activeWindows.add (this);
  24838. setOpaque (true);
  24839. setVisible (true);
  24840. setSize (100, 100);
  24841. createView (createGenericViewIfNeeded);
  24842. }
  24843. ~AudioUnitPluginWindowCocoa()
  24844. {
  24845. const bool wasValid = isValid();
  24846. wrapper->setView (0);
  24847. activeWindows.removeValue (this);
  24848. if (wasValid)
  24849. plugin.editorBeingDeleted (this);
  24850. delete wrapper;
  24851. }
  24852. bool isValid() const { return wrapper->getView() != 0; }
  24853. void paint (Graphics& g)
  24854. {
  24855. g.fillAll (Colours::white);
  24856. }
  24857. void resized()
  24858. {
  24859. wrapper->setSize (getWidth(), getHeight());
  24860. }
  24861. private:
  24862. AudioUnitPluginInstance& plugin;
  24863. NSViewComponent* wrapper;
  24864. bool createView (const bool createGenericViewIfNeeded)
  24865. {
  24866. NSView* pluginView = 0;
  24867. UInt32 dataSize = 0;
  24868. Boolean isWritable = false;
  24869. if (AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24870. 0, &dataSize, &isWritable) == noErr
  24871. && dataSize != 0
  24872. && AudioUnitGetPropertyInfo (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24873. 0, &dataSize, &isWritable) == noErr)
  24874. {
  24875. HeapBlock <AudioUnitCocoaViewInfo> info;
  24876. info.calloc (dataSize, 1);
  24877. if (AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_CocoaUI, kAudioUnitScope_Global,
  24878. 0, info, &dataSize) == noErr)
  24879. {
  24880. NSString* viewClassName = (NSString*) (info->mCocoaAUViewClass[0]);
  24881. NSString* path = (NSString*) CFURLCopyPath (info->mCocoaAUViewBundleLocation);
  24882. NSBundle* viewBundle = [NSBundle bundleWithPath: [path autorelease]];
  24883. Class viewClass = [viewBundle classNamed: viewClassName];
  24884. if ([viewClass conformsToProtocol: @protocol (AUCocoaUIBase)]
  24885. && [viewClass instancesRespondToSelector: @selector (interfaceVersion)]
  24886. && [viewClass instancesRespondToSelector: @selector (uiViewForAudioUnit: withSize:)])
  24887. {
  24888. id factory = [[[viewClass alloc] init] autorelease];
  24889. pluginView = [factory uiViewForAudioUnit: plugin.audioUnit
  24890. withSize: NSMakeSize (getWidth(), getHeight())];
  24891. }
  24892. for (int i = (dataSize - sizeof (CFURLRef)) / sizeof (CFStringRef); --i >= 0;)
  24893. {
  24894. CFRelease (info->mCocoaAUViewClass[i]);
  24895. CFRelease (info->mCocoaAUViewBundleLocation);
  24896. }
  24897. }
  24898. }
  24899. if (createGenericViewIfNeeded && (pluginView == 0))
  24900. pluginView = [[AUGenericView alloc] initWithAudioUnit: plugin.audioUnit];
  24901. wrapper->setView (pluginView);
  24902. if (pluginView != 0)
  24903. setSize ([pluginView frame].size.width,
  24904. [pluginView frame].size.height);
  24905. return pluginView != 0;
  24906. }
  24907. };
  24908. #if JUCE_SUPPORT_CARBON
  24909. class AudioUnitPluginWindowCarbon : public AudioProcessorEditor
  24910. {
  24911. public:
  24912. AudioUnitPluginWindowCarbon (AudioUnitPluginInstance& plugin_)
  24913. : AudioProcessorEditor (&plugin_),
  24914. plugin (plugin_),
  24915. viewComponent (0)
  24916. {
  24917. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  24918. activeWindows.add (this);
  24919. setOpaque (true);
  24920. setVisible (true);
  24921. setSize (400, 300);
  24922. ComponentDescription viewList [16];
  24923. UInt32 viewListSize = sizeof (viewList);
  24924. AudioUnitGetProperty (plugin.audioUnit, kAudioUnitProperty_GetUIComponentList, kAudioUnitScope_Global,
  24925. 0, &viewList, &viewListSize);
  24926. componentRecord = FindNextComponent (0, &viewList[0]);
  24927. }
  24928. ~AudioUnitPluginWindowCarbon()
  24929. {
  24930. deleteAndZero (innerWrapper);
  24931. activeWindows.removeValue (this);
  24932. if (isValid())
  24933. plugin.editorBeingDeleted (this);
  24934. }
  24935. bool isValid() const throw() { return componentRecord != 0; }
  24936. void paint (Graphics& g)
  24937. {
  24938. g.fillAll (Colours::black);
  24939. }
  24940. void resized()
  24941. {
  24942. innerWrapper->setSize (getWidth(), getHeight());
  24943. }
  24944. bool keyStateChanged (const bool)
  24945. {
  24946. return false;
  24947. }
  24948. bool keyPressed (const KeyPress&)
  24949. {
  24950. return false;
  24951. }
  24952. void broughtToFront()
  24953. {
  24954. activeWindows.removeValue (this);
  24955. activeWindows.add (this);
  24956. }
  24957. AudioUnit getAudioUnit() const { return plugin.audioUnit; }
  24958. AudioUnitCarbonView getViewComponent()
  24959. {
  24960. if (viewComponent == 0 && componentRecord != 0)
  24961. viewComponent = (AudioUnitCarbonView) OpenComponent (componentRecord);
  24962. return viewComponent;
  24963. }
  24964. void closeViewComponent()
  24965. {
  24966. if (viewComponent != 0)
  24967. {
  24968. CloseComponent (viewComponent);
  24969. viewComponent = 0;
  24970. }
  24971. }
  24972. juce_UseDebuggingNewOperator
  24973. private:
  24974. AudioUnitPluginInstance& plugin;
  24975. ComponentRecord* componentRecord;
  24976. AudioUnitCarbonView viewComponent;
  24977. class InnerWrapperComponent : public CarbonViewWrapperComponent
  24978. {
  24979. public:
  24980. InnerWrapperComponent (AudioUnitPluginWindowCarbon* const owner_)
  24981. : owner (owner_)
  24982. {
  24983. }
  24984. ~InnerWrapperComponent()
  24985. {
  24986. deleteWindow();
  24987. }
  24988. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  24989. {
  24990. log (T("Opening AU GUI: ") + owner->plugin.getName());
  24991. AudioUnitCarbonView viewComponent = owner->getViewComponent();
  24992. if (viewComponent == 0)
  24993. return 0;
  24994. Float32Point pos = { 0, 0 };
  24995. Float32Point size = { 250, 200 };
  24996. HIViewRef pluginView = 0;
  24997. AudioUnitCarbonViewCreate (viewComponent,
  24998. owner->getAudioUnit(),
  24999. windowRef,
  25000. rootView,
  25001. &pos,
  25002. &size,
  25003. (ControlRef*) &pluginView);
  25004. return pluginView;
  25005. }
  25006. void removeView (HIViewRef)
  25007. {
  25008. log (T("Closing AU GUI: ") + owner->plugin.getName());
  25009. owner->closeViewComponent();
  25010. }
  25011. private:
  25012. AudioUnitPluginWindowCarbon* const owner;
  25013. };
  25014. friend class InnerWrapperComponent;
  25015. InnerWrapperComponent* innerWrapper;
  25016. };
  25017. #endif
  25018. AudioProcessorEditor* AudioUnitPluginInstance::createEditor()
  25019. {
  25020. ScopedPointer <AudioProcessorEditor> w (new AudioUnitPluginWindowCocoa (*this, false));
  25021. if (! ((AudioUnitPluginWindowCocoa*) w)->isValid())
  25022. w = 0;
  25023. #if JUCE_SUPPORT_CARBON
  25024. if (w == 0)
  25025. {
  25026. w = new AudioUnitPluginWindowCarbon (*this);
  25027. if (! ((AudioUnitPluginWindowCarbon*) w)->isValid())
  25028. w = 0;
  25029. }
  25030. #endif
  25031. if (w == 0)
  25032. w = new AudioUnitPluginWindowCocoa (*this, true); // use AUGenericView as a fallback
  25033. return w.release();
  25034. }
  25035. const String AudioUnitPluginInstance::getCategory() const
  25036. {
  25037. const char* result = 0;
  25038. switch (componentDesc.componentType)
  25039. {
  25040. case kAudioUnitType_Effect:
  25041. case kAudioUnitType_MusicEffect:
  25042. result = "Effect";
  25043. break;
  25044. case kAudioUnitType_MusicDevice:
  25045. result = "Synth";
  25046. break;
  25047. case kAudioUnitType_Generator:
  25048. result = "Generator";
  25049. break;
  25050. case kAudioUnitType_Panner:
  25051. result = "Panner";
  25052. break;
  25053. default:
  25054. break;
  25055. }
  25056. return result;
  25057. }
  25058. int AudioUnitPluginInstance::getNumParameters()
  25059. {
  25060. return parameterIds.size();
  25061. }
  25062. float AudioUnitPluginInstance::getParameter (int index)
  25063. {
  25064. const ScopedLock sl (lock);
  25065. Float32 value = 0.0f;
  25066. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  25067. {
  25068. AudioUnitGetParameter (audioUnit,
  25069. (UInt32) parameterIds.getUnchecked (index),
  25070. kAudioUnitScope_Global, 0,
  25071. &value);
  25072. }
  25073. return value;
  25074. }
  25075. void AudioUnitPluginInstance::setParameter (int index, float newValue)
  25076. {
  25077. const ScopedLock sl (lock);
  25078. if (audioUnit != 0 && ((unsigned int) index) < (unsigned int) parameterIds.size())
  25079. {
  25080. AudioUnitSetParameter (audioUnit,
  25081. (UInt32) parameterIds.getUnchecked (index),
  25082. kAudioUnitScope_Global, 0,
  25083. newValue, 0);
  25084. }
  25085. }
  25086. const String AudioUnitPluginInstance::getParameterName (int index)
  25087. {
  25088. AudioUnitParameterInfo info;
  25089. zerostruct (info);
  25090. UInt32 sz = sizeof (info);
  25091. String name;
  25092. if (AudioUnitGetProperty (audioUnit,
  25093. kAudioUnitProperty_ParameterInfo,
  25094. kAudioUnitScope_Global,
  25095. parameterIds [index], &info, &sz) == noErr)
  25096. {
  25097. if ((info.flags & kAudioUnitParameterFlag_HasCFNameString) != 0)
  25098. name = PlatformUtilities::cfStringToJuceString (info.cfNameString);
  25099. else
  25100. name = String (info.name, sizeof (info.name));
  25101. }
  25102. return name;
  25103. }
  25104. const String AudioUnitPluginInstance::getParameterText (int index)
  25105. {
  25106. return String (getParameter (index));
  25107. }
  25108. bool AudioUnitPluginInstance::isParameterAutomatable (int index) const
  25109. {
  25110. AudioUnitParameterInfo info;
  25111. UInt32 sz = sizeof (info);
  25112. if (AudioUnitGetProperty (audioUnit,
  25113. kAudioUnitProperty_ParameterInfo,
  25114. kAudioUnitScope_Global,
  25115. parameterIds [index], &info, &sz) == noErr)
  25116. {
  25117. return (info.flags & kAudioUnitParameterFlag_NonRealTime) == 0;
  25118. }
  25119. return true;
  25120. }
  25121. int AudioUnitPluginInstance::getNumPrograms()
  25122. {
  25123. CFArrayRef presets;
  25124. UInt32 sz = sizeof (CFArrayRef);
  25125. int num = 0;
  25126. if (AudioUnitGetProperty (audioUnit,
  25127. kAudioUnitProperty_FactoryPresets,
  25128. kAudioUnitScope_Global,
  25129. 0, &presets, &sz) == noErr)
  25130. {
  25131. num = (int) CFArrayGetCount (presets);
  25132. CFRelease (presets);
  25133. }
  25134. return num;
  25135. }
  25136. int AudioUnitPluginInstance::getCurrentProgram()
  25137. {
  25138. AUPreset current;
  25139. current.presetNumber = 0;
  25140. UInt32 sz = sizeof (AUPreset);
  25141. AudioUnitGetProperty (audioUnit,
  25142. kAudioUnitProperty_FactoryPresets,
  25143. kAudioUnitScope_Global,
  25144. 0, &current, &sz);
  25145. return current.presetNumber;
  25146. }
  25147. void AudioUnitPluginInstance::setCurrentProgram (int newIndex)
  25148. {
  25149. AUPreset current;
  25150. current.presetNumber = newIndex;
  25151. current.presetName = 0;
  25152. AudioUnitSetProperty (audioUnit,
  25153. kAudioUnitProperty_FactoryPresets,
  25154. kAudioUnitScope_Global,
  25155. 0, &current, sizeof (AUPreset));
  25156. }
  25157. const String AudioUnitPluginInstance::getProgramName (int index)
  25158. {
  25159. String s;
  25160. CFArrayRef presets;
  25161. UInt32 sz = sizeof (CFArrayRef);
  25162. if (AudioUnitGetProperty (audioUnit,
  25163. kAudioUnitProperty_FactoryPresets,
  25164. kAudioUnitScope_Global,
  25165. 0, &presets, &sz) == noErr)
  25166. {
  25167. for (CFIndex i = 0; i < CFArrayGetCount (presets); ++i)
  25168. {
  25169. const AUPreset* p = (const AUPreset*) CFArrayGetValueAtIndex (presets, i);
  25170. if (p != 0 && p->presetNumber == index)
  25171. {
  25172. s = PlatformUtilities::cfStringToJuceString (p->presetName);
  25173. break;
  25174. }
  25175. }
  25176. CFRelease (presets);
  25177. }
  25178. return s;
  25179. }
  25180. void AudioUnitPluginInstance::changeProgramName (int index, const String& newName)
  25181. {
  25182. jassertfalse // xxx not implemented!
  25183. }
  25184. const String AudioUnitPluginInstance::getInputChannelName (const int index) const
  25185. {
  25186. if (((unsigned int) index) < (unsigned int) getNumInputChannels())
  25187. return T("Input ") + String (index + 1);
  25188. return String::empty;
  25189. }
  25190. bool AudioUnitPluginInstance::isInputChannelStereoPair (int index) const
  25191. {
  25192. if (((unsigned int) index) >= (unsigned int) getNumInputChannels())
  25193. return false;
  25194. return true;
  25195. }
  25196. const String AudioUnitPluginInstance::getOutputChannelName (const int index) const
  25197. {
  25198. if (((unsigned int) index) < (unsigned int) getNumOutputChannels())
  25199. return T("Output ") + String (index + 1);
  25200. return String::empty;
  25201. }
  25202. bool AudioUnitPluginInstance::isOutputChannelStereoPair (int index) const
  25203. {
  25204. if (((unsigned int) index) >= (unsigned int) getNumOutputChannels())
  25205. return false;
  25206. return true;
  25207. }
  25208. void AudioUnitPluginInstance::getStateInformation (MemoryBlock& destData)
  25209. {
  25210. getCurrentProgramStateInformation (destData);
  25211. }
  25212. void AudioUnitPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  25213. {
  25214. CFPropertyListRef propertyList = 0;
  25215. UInt32 sz = sizeof (CFPropertyListRef);
  25216. if (AudioUnitGetProperty (audioUnit,
  25217. kAudioUnitProperty_ClassInfo,
  25218. kAudioUnitScope_Global,
  25219. 0, &propertyList, &sz) == noErr)
  25220. {
  25221. CFWriteStreamRef stream = CFWriteStreamCreateWithAllocatedBuffers (kCFAllocatorDefault, kCFAllocatorDefault);
  25222. CFWriteStreamOpen (stream);
  25223. CFIndex bytesWritten = CFPropertyListWriteToStream (propertyList, stream, kCFPropertyListBinaryFormat_v1_0, 0);
  25224. CFWriteStreamClose (stream);
  25225. CFDataRef data = (CFDataRef) CFWriteStreamCopyProperty (stream, kCFStreamPropertyDataWritten);
  25226. destData.setSize (bytesWritten);
  25227. destData.copyFrom (CFDataGetBytePtr (data), 0, destData.getSize());
  25228. CFRelease (data);
  25229. CFRelease (stream);
  25230. CFRelease (propertyList);
  25231. }
  25232. }
  25233. void AudioUnitPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  25234. {
  25235. setCurrentProgramStateInformation (data, sizeInBytes);
  25236. }
  25237. void AudioUnitPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  25238. {
  25239. CFReadStreamRef stream = CFReadStreamCreateWithBytesNoCopy (kCFAllocatorDefault,
  25240. (const UInt8*) data,
  25241. sizeInBytes,
  25242. kCFAllocatorNull);
  25243. CFReadStreamOpen (stream);
  25244. CFPropertyListFormat format = kCFPropertyListBinaryFormat_v1_0;
  25245. CFPropertyListRef propertyList = CFPropertyListCreateFromStream (kCFAllocatorDefault,
  25246. stream,
  25247. 0,
  25248. kCFPropertyListImmutable,
  25249. &format,
  25250. 0);
  25251. CFRelease (stream);
  25252. if (propertyList != 0)
  25253. AudioUnitSetProperty (audioUnit,
  25254. kAudioUnitProperty_ClassInfo,
  25255. kAudioUnitScope_Global,
  25256. 0, &propertyList, sizeof (propertyList));
  25257. }
  25258. AudioUnitPluginFormat::AudioUnitPluginFormat()
  25259. {
  25260. }
  25261. AudioUnitPluginFormat::~AudioUnitPluginFormat()
  25262. {
  25263. }
  25264. void AudioUnitPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  25265. const String& fileOrIdentifier)
  25266. {
  25267. if (! fileMightContainThisPluginType (fileOrIdentifier))
  25268. return;
  25269. PluginDescription desc;
  25270. desc.fileOrIdentifier = fileOrIdentifier;
  25271. desc.uid = 0;
  25272. try
  25273. {
  25274. ScopedPointer <AudioPluginInstance> createdInstance (createInstanceFromDescription (desc));
  25275. AudioUnitPluginInstance* const auInstance = dynamic_cast <AudioUnitPluginInstance*> ((AudioPluginInstance*) createdInstance);
  25276. if (auInstance != 0)
  25277. {
  25278. auInstance->fillInPluginDescription (desc);
  25279. results.add (new PluginDescription (desc));
  25280. }
  25281. }
  25282. catch (...)
  25283. {
  25284. // crashed while loading...
  25285. }
  25286. }
  25287. AudioPluginInstance* AudioUnitPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  25288. {
  25289. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  25290. {
  25291. ScopedPointer <AudioUnitPluginInstance> result (new AudioUnitPluginInstance (desc.fileOrIdentifier));
  25292. if (result->audioUnit != 0)
  25293. {
  25294. result->initialise();
  25295. return result.release();
  25296. }
  25297. }
  25298. return 0;
  25299. }
  25300. const StringArray AudioUnitPluginFormat::searchPathsForPlugins (const FileSearchPath& /*directoriesToSearch*/,
  25301. const bool /*recursive*/)
  25302. {
  25303. StringArray result;
  25304. ComponentRecord* comp = 0;
  25305. ComponentDescription desc;
  25306. zerostruct (desc);
  25307. for (;;)
  25308. {
  25309. zerostruct (desc);
  25310. comp = FindNextComponent (comp, &desc);
  25311. if (comp == 0)
  25312. break;
  25313. GetComponentInfo (comp, &desc, 0, 0, 0);
  25314. if (desc.componentType == kAudioUnitType_MusicDevice
  25315. || desc.componentType == kAudioUnitType_MusicEffect
  25316. || desc.componentType == kAudioUnitType_Effect
  25317. || desc.componentType == kAudioUnitType_Generator
  25318. || desc.componentType == kAudioUnitType_Panner)
  25319. {
  25320. const String s (createAUPluginIdentifier (desc));
  25321. DBG (s);
  25322. result.add (s);
  25323. }
  25324. }
  25325. return result;
  25326. }
  25327. bool AudioUnitPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  25328. {
  25329. ComponentDescription desc;
  25330. String name, version, manufacturer;
  25331. if (getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer))
  25332. return FindNextComponent (0, &desc) != 0;
  25333. const File f (fileOrIdentifier);
  25334. return f.hasFileExtension (T(".component"))
  25335. && f.isDirectory();
  25336. }
  25337. const String AudioUnitPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  25338. {
  25339. ComponentDescription desc;
  25340. String name, version, manufacturer;
  25341. getComponentDescFromIdentifier (fileOrIdentifier, desc, name, version, manufacturer);
  25342. if (name.isEmpty())
  25343. name = fileOrIdentifier;
  25344. return name;
  25345. }
  25346. bool AudioUnitPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  25347. {
  25348. if (desc.fileOrIdentifier.startsWithIgnoreCase (auIdentifierPrefix))
  25349. return fileMightContainThisPluginType (desc.fileOrIdentifier);
  25350. else
  25351. return File (desc.fileOrIdentifier).exists();
  25352. }
  25353. const FileSearchPath AudioUnitPluginFormat::getDefaultLocationsToSearch()
  25354. {
  25355. return FileSearchPath ("/(Default AudioUnit locations)");
  25356. }
  25357. #endif
  25358. END_JUCE_NAMESPACE
  25359. #undef log
  25360. #endif
  25361. /*** End of inlined file: juce_AudioUnitPluginFormat.mm ***/
  25362. /*** Start of inlined file: juce_VSTPluginFormat.mm ***/
  25363. // This file just wraps juce_VSTPluginFormat.cpp in an objective-C wrapper
  25364. #define JUCE_MAC_VST_INCLUDED 1
  25365. /*** Start of inlined file: juce_VSTPluginFormat.cpp ***/
  25366. #if JUCE_PLUGINHOST_VST
  25367. #if (defined (_WIN32) || defined (_WIN64))
  25368. #undef _WIN32_WINNT
  25369. #define _WIN32_WINNT 0x500
  25370. #undef STRICT
  25371. #define STRICT
  25372. #include <windows.h>
  25373. #include <float.h>
  25374. #pragma warning (disable : 4312 4355)
  25375. #elif defined (LINUX) || defined (__linux__)
  25376. #include <float.h>
  25377. #include <sys/time.h>
  25378. #include <X11/Xlib.h>
  25379. #include <X11/Xutil.h>
  25380. #include <X11/Xatom.h>
  25381. #undef Font
  25382. #undef KeyPress
  25383. #undef Drawable
  25384. #undef Time
  25385. #else
  25386. #ifndef JUCE_MAC_VST_INCLUDED
  25387. // On the mac, this file needs to be compiled indirectly, by using
  25388. // juce_VSTPluginFormat.mm instead - that wraps it as an objective-C file for cocoa
  25389. #error
  25390. #endif
  25391. #include <Cocoa/Cocoa.h>
  25392. #include <Carbon/Carbon.h>
  25393. #endif
  25394. #if ! (JUCE_MAC && JUCE_64BIT)
  25395. BEGIN_JUCE_NAMESPACE
  25396. #if JUCE_MAC && JUCE_SUPPORT_CARBON
  25397. #endif
  25398. #undef PRAGMA_ALIGN_SUPPORTED
  25399. #define VST_FORCE_DEPRECATED 0
  25400. #ifdef _MSC_VER
  25401. #pragma warning (push)
  25402. #pragma warning (disable: 4996)
  25403. #endif
  25404. #include "pluginterfaces/vst2.x/aeffectx.h"
  25405. #ifdef _MSC_VER
  25406. #pragma warning (pop)
  25407. #endif
  25408. #if JUCE_LINUX
  25409. #define Font JUCE_NAMESPACE::Font
  25410. #define KeyPress JUCE_NAMESPACE::KeyPress
  25411. #define Drawable JUCE_NAMESPACE::Drawable
  25412. #define Time JUCE_NAMESPACE::Time
  25413. #endif
  25414. /*** Start of inlined file: juce_VSTMidiEventList.h ***/
  25415. #ifdef __aeffect__
  25416. #ifndef __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25417. #define __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25418. class VSTMidiEventList
  25419. {
  25420. public:
  25421. VSTMidiEventList()
  25422. : numEventsUsed (0), numEventsAllocated (0)
  25423. {
  25424. }
  25425. ~VSTMidiEventList()
  25426. {
  25427. freeEvents();
  25428. }
  25429. void clear()
  25430. {
  25431. numEventsUsed = 0;
  25432. if (events != 0)
  25433. events->numEvents = 0;
  25434. }
  25435. void addEvent (const void* const midiData, const int numBytes, const int frameOffset)
  25436. {
  25437. ensureSize (numEventsUsed + 1);
  25438. VstMidiEvent* const e = (VstMidiEvent*) (events->events [numEventsUsed]);
  25439. events->numEvents = ++numEventsUsed;
  25440. if (numBytes <= 4)
  25441. {
  25442. if (e->type == kVstSysExType)
  25443. {
  25444. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25445. e->type = kVstMidiType;
  25446. e->byteSize = sizeof (VstMidiEvent);
  25447. e->noteLength = 0;
  25448. e->noteOffset = 0;
  25449. e->detune = 0;
  25450. e->noteOffVelocity = 0;
  25451. }
  25452. e->deltaFrames = frameOffset;
  25453. memcpy (e->midiData, midiData, numBytes);
  25454. }
  25455. else
  25456. {
  25457. VstMidiSysexEvent* const se = (VstMidiSysexEvent*) e;
  25458. if (se->type == kVstSysExType)
  25459. se->sysexDump = (char*) juce_realloc (se->sysexDump, numBytes);
  25460. else
  25461. se->sysexDump = (char*) juce_malloc (numBytes);
  25462. memcpy (se->sysexDump, midiData, numBytes);
  25463. se->type = kVstSysExType;
  25464. se->byteSize = sizeof (VstMidiSysexEvent);
  25465. se->deltaFrames = frameOffset;
  25466. se->flags = 0;
  25467. se->dumpBytes = numBytes;
  25468. se->resvd1 = 0;
  25469. se->resvd2 = 0;
  25470. }
  25471. }
  25472. // Handy method to pull the events out of an event buffer supplied by the host
  25473. // or plugin.
  25474. static void addEventsToMidiBuffer (const VstEvents* events, MidiBuffer& dest)
  25475. {
  25476. for (int i = 0; i < events->numEvents; ++i)
  25477. {
  25478. const VstEvent* const e = events->events[i];
  25479. if (e != 0)
  25480. {
  25481. if (e->type == kVstMidiType)
  25482. {
  25483. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiEvent*) e)->midiData,
  25484. 4, e->deltaFrames);
  25485. }
  25486. else if (e->type == kVstSysExType)
  25487. {
  25488. dest.addEvent ((const JUCE_NAMESPACE::uint8*) ((const VstMidiSysexEvent*) e)->sysexDump,
  25489. (int) ((const VstMidiSysexEvent*) e)->dumpBytes,
  25490. e->deltaFrames);
  25491. }
  25492. }
  25493. }
  25494. }
  25495. void ensureSize (int numEventsNeeded)
  25496. {
  25497. if (numEventsNeeded > numEventsAllocated)
  25498. {
  25499. numEventsNeeded = (numEventsNeeded + 32) & ~31;
  25500. const int size = 20 + sizeof (VstEvent*) * numEventsNeeded;
  25501. if (events == 0)
  25502. events.calloc (size, 1);
  25503. else
  25504. events.realloc (size, 1);
  25505. for (int i = numEventsAllocated; i < numEventsNeeded; ++i)
  25506. {
  25507. VstMidiEvent* const e = (VstMidiEvent*) juce_calloc (jmax ((int) sizeof (VstMidiEvent),
  25508. (int) sizeof (VstMidiSysexEvent)));
  25509. e->type = kVstMidiType;
  25510. e->byteSize = sizeof (VstMidiEvent);
  25511. events->events[i] = (VstEvent*) e;
  25512. }
  25513. numEventsAllocated = numEventsNeeded;
  25514. }
  25515. }
  25516. void freeEvents()
  25517. {
  25518. if (events != 0)
  25519. {
  25520. for (int i = numEventsAllocated; --i >= 0;)
  25521. {
  25522. VstMidiEvent* const e = (VstMidiEvent*) (events->events[i]);
  25523. if (e->type == kVstSysExType)
  25524. juce_free (((VstMidiSysexEvent*) e)->sysexDump);
  25525. juce_free (e);
  25526. }
  25527. events.free();
  25528. numEventsUsed = 0;
  25529. numEventsAllocated = 0;
  25530. }
  25531. }
  25532. HeapBlock <VstEvents> events;
  25533. private:
  25534. int numEventsUsed, numEventsAllocated;
  25535. };
  25536. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25537. #endif // __JUCE_VSTMIDIEVENTLIST_JUCEHEADER__
  25538. /*** End of inlined file: juce_VSTMidiEventList.h ***/
  25539. #if ! JUCE_WIN32
  25540. #define _fpreset()
  25541. #define _clearfp()
  25542. #endif
  25543. extern void juce_callAnyTimersSynchronously();
  25544. const int fxbVersionNum = 1;
  25545. struct fxProgram
  25546. {
  25547. long chunkMagic; // 'CcnK'
  25548. long byteSize; // of this chunk, excl. magic + byteSize
  25549. long fxMagic; // 'FxCk'
  25550. long version;
  25551. long fxID; // fx unique id
  25552. long fxVersion;
  25553. long numParams;
  25554. char prgName[28];
  25555. float params[1]; // variable no. of parameters
  25556. };
  25557. struct fxSet
  25558. {
  25559. long chunkMagic; // 'CcnK'
  25560. long byteSize; // of this chunk, excl. magic + byteSize
  25561. long fxMagic; // 'FxBk'
  25562. long version;
  25563. long fxID; // fx unique id
  25564. long fxVersion;
  25565. long numPrograms;
  25566. char future[128];
  25567. fxProgram programs[1]; // variable no. of programs
  25568. };
  25569. struct fxChunkSet
  25570. {
  25571. long chunkMagic; // 'CcnK'
  25572. long byteSize; // of this chunk, excl. magic + byteSize
  25573. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25574. long version;
  25575. long fxID; // fx unique id
  25576. long fxVersion;
  25577. long numPrograms;
  25578. char future[128];
  25579. long chunkSize;
  25580. char chunk[8]; // variable
  25581. };
  25582. struct fxProgramSet
  25583. {
  25584. long chunkMagic; // 'CcnK'
  25585. long byteSize; // of this chunk, excl. magic + byteSize
  25586. long fxMagic; // 'FxCh', 'FPCh', or 'FBCh'
  25587. long version;
  25588. long fxID; // fx unique id
  25589. long fxVersion;
  25590. long numPrograms;
  25591. char name[28];
  25592. long chunkSize;
  25593. char chunk[8]; // variable
  25594. };
  25595. static long vst_swap (const long x) throw()
  25596. {
  25597. #ifdef JUCE_LITTLE_ENDIAN
  25598. return (long) ByteOrder::swap ((uint32) x);
  25599. #else
  25600. return x;
  25601. #endif
  25602. }
  25603. static float vst_swapFloat (const float x) throw()
  25604. {
  25605. #ifdef JUCE_LITTLE_ENDIAN
  25606. union { uint32 asInt; float asFloat; } n;
  25607. n.asFloat = x;
  25608. n.asInt = ByteOrder::swap (n.asInt);
  25609. return n.asFloat;
  25610. #else
  25611. return x;
  25612. #endif
  25613. }
  25614. typedef AEffect* (*MainCall) (audioMasterCallback);
  25615. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt);
  25616. static int shellUIDToCreate = 0;
  25617. static int insideVSTCallback = 0;
  25618. class VSTPluginWindow;
  25619. // Change this to disable logging of various VST activities
  25620. #ifndef VST_LOGGING
  25621. #define VST_LOGGING 1
  25622. #endif
  25623. #if VST_LOGGING
  25624. #define log(a) Logger::writeToLog(a);
  25625. #else
  25626. #define log(a)
  25627. #endif
  25628. #if JUCE_MAC && JUCE_PPC
  25629. static void* NewCFMFromMachO (void* const machofp) throw()
  25630. {
  25631. void* result = juce_malloc (8);
  25632. ((void**) result)[0] = machofp;
  25633. ((void**) result)[1] = result;
  25634. return result;
  25635. }
  25636. #endif
  25637. #if JUCE_LINUX
  25638. extern Display* display;
  25639. extern XContext improbableNumber;
  25640. typedef void (*EventProcPtr) (XEvent* ev);
  25641. static bool xErrorTriggered;
  25642. static int temporaryErrorHandler (Display*, XErrorEvent*)
  25643. {
  25644. xErrorTriggered = true;
  25645. return 0;
  25646. }
  25647. static int getPropertyFromXWindow (Window handle, Atom atom)
  25648. {
  25649. XErrorHandler oldErrorHandler = XSetErrorHandler (temporaryErrorHandler);
  25650. xErrorTriggered = false;
  25651. int userSize;
  25652. unsigned long bytes, userCount;
  25653. unsigned char* data;
  25654. Atom userType;
  25655. XGetWindowProperty (display, handle, atom, 0, 1, false, AnyPropertyType,
  25656. &userType, &userSize, &userCount, &bytes, &data);
  25657. XSetErrorHandler (oldErrorHandler);
  25658. return (userCount == 1 && ! xErrorTriggered) ? *(int*) data
  25659. : 0;
  25660. }
  25661. static Window getChildWindow (Window windowToCheck)
  25662. {
  25663. Window rootWindow, parentWindow;
  25664. Window* childWindows;
  25665. unsigned int numChildren;
  25666. XQueryTree (display,
  25667. windowToCheck,
  25668. &rootWindow,
  25669. &parentWindow,
  25670. &childWindows,
  25671. &numChildren);
  25672. if (numChildren > 0)
  25673. return childWindows [0];
  25674. return 0;
  25675. }
  25676. static void translateJuceToXButtonModifiers (const MouseEvent& e, XEvent& ev) throw()
  25677. {
  25678. if (e.mods.isLeftButtonDown())
  25679. {
  25680. ev.xbutton.button = Button1;
  25681. ev.xbutton.state |= Button1Mask;
  25682. }
  25683. else if (e.mods.isRightButtonDown())
  25684. {
  25685. ev.xbutton.button = Button3;
  25686. ev.xbutton.state |= Button3Mask;
  25687. }
  25688. else if (e.mods.isMiddleButtonDown())
  25689. {
  25690. ev.xbutton.button = Button2;
  25691. ev.xbutton.state |= Button2Mask;
  25692. }
  25693. }
  25694. static void translateJuceToXMotionModifiers (const MouseEvent& e, XEvent& ev) throw()
  25695. {
  25696. if (e.mods.isLeftButtonDown())
  25697. ev.xmotion.state |= Button1Mask;
  25698. else if (e.mods.isRightButtonDown())
  25699. ev.xmotion.state |= Button3Mask;
  25700. else if (e.mods.isMiddleButtonDown())
  25701. ev.xmotion.state |= Button2Mask;
  25702. }
  25703. static void translateJuceToXCrossingModifiers (const MouseEvent& e, XEvent& ev) throw()
  25704. {
  25705. if (e.mods.isLeftButtonDown())
  25706. ev.xcrossing.state |= Button1Mask;
  25707. else if (e.mods.isRightButtonDown())
  25708. ev.xcrossing.state |= Button3Mask;
  25709. else if (e.mods.isMiddleButtonDown())
  25710. ev.xcrossing.state |= Button2Mask;
  25711. }
  25712. static void translateJuceToXMouseWheelModifiers (const MouseEvent& e, const float increment, XEvent& ev) throw()
  25713. {
  25714. if (increment < 0)
  25715. {
  25716. ev.xbutton.button = Button5;
  25717. ev.xbutton.state |= Button5Mask;
  25718. }
  25719. else if (increment > 0)
  25720. {
  25721. ev.xbutton.button = Button4;
  25722. ev.xbutton.state |= Button4Mask;
  25723. }
  25724. }
  25725. #endif
  25726. static VoidArray activeModules;
  25727. class ModuleHandle : public ReferenceCountedObject
  25728. {
  25729. public:
  25730. File file;
  25731. MainCall moduleMain;
  25732. String pluginName;
  25733. static ModuleHandle* findOrCreateModule (const File& file)
  25734. {
  25735. for (int i = activeModules.size(); --i >= 0;)
  25736. {
  25737. ModuleHandle* const module = (ModuleHandle*) activeModules.getUnchecked(i);
  25738. if (module->file == file)
  25739. return module;
  25740. }
  25741. _fpreset(); // (doesn't do any harm)
  25742. ++insideVSTCallback;
  25743. shellUIDToCreate = 0;
  25744. log ("Attempting to load VST: " + file.getFullPathName());
  25745. ScopedPointer <ModuleHandle> m (new ModuleHandle (file));
  25746. if (! m->open())
  25747. m = 0;
  25748. --insideVSTCallback;
  25749. _fpreset(); // (doesn't do any harm)
  25750. return m.release();
  25751. }
  25752. ModuleHandle (const File& file_)
  25753. : file (file_),
  25754. moduleMain (0),
  25755. #if JUCE_WIN32 || JUCE_LINUX
  25756. hModule (0)
  25757. #elif JUCE_MAC
  25758. fragId (0),
  25759. resHandle (0),
  25760. bundleRef (0),
  25761. resFileId (0)
  25762. #endif
  25763. {
  25764. activeModules.add (this);
  25765. #if JUCE_WIN32 || JUCE_LINUX
  25766. fullParentDirectoryPathName = file_.getParentDirectory().getFullPathName();
  25767. #elif JUCE_MAC
  25768. FSRef ref;
  25769. PlatformUtilities::makeFSRefFromPath (&ref, file_.getParentDirectory().getFullPathName());
  25770. FSGetCatalogInfo (&ref, kFSCatInfoNone, 0, 0, &parentDirFSSpec, 0);
  25771. #endif
  25772. }
  25773. ~ModuleHandle()
  25774. {
  25775. activeModules.removeValue (this);
  25776. close();
  25777. }
  25778. juce_UseDebuggingNewOperator
  25779. #if JUCE_WIN32 || JUCE_LINUX
  25780. void* hModule;
  25781. String fullParentDirectoryPathName;
  25782. bool open()
  25783. {
  25784. #if JUCE_WIN32
  25785. static bool timePeriodSet = false;
  25786. if (! timePeriodSet)
  25787. {
  25788. timePeriodSet = true;
  25789. timeBeginPeriod (2);
  25790. }
  25791. #endif
  25792. pluginName = file.getFileNameWithoutExtension();
  25793. hModule = PlatformUtilities::loadDynamicLibrary (file.getFullPathName());
  25794. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "VSTPluginMain");
  25795. if (moduleMain == 0)
  25796. moduleMain = (MainCall) PlatformUtilities::getProcedureEntryPoint (hModule, "main");
  25797. return moduleMain != 0;
  25798. }
  25799. void close()
  25800. {
  25801. _fpreset(); // (doesn't do any harm)
  25802. PlatformUtilities::freeDynamicLibrary (hModule);
  25803. }
  25804. void closeEffect (AEffect* eff)
  25805. {
  25806. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25807. }
  25808. #else
  25809. CFragConnectionID fragId;
  25810. Handle resHandle;
  25811. CFBundleRef bundleRef;
  25812. FSSpec parentDirFSSpec;
  25813. short resFileId;
  25814. bool open()
  25815. {
  25816. bool ok = false;
  25817. const String filename (file.getFullPathName());
  25818. if (file.hasFileExtension (T(".vst")))
  25819. {
  25820. const char* const utf8 = filename.toUTF8();
  25821. CFURLRef url = CFURLCreateFromFileSystemRepresentation (0, (const UInt8*) utf8,
  25822. strlen (utf8), file.isDirectory());
  25823. if (url != 0)
  25824. {
  25825. bundleRef = CFBundleCreate (kCFAllocatorDefault, url);
  25826. CFRelease (url);
  25827. if (bundleRef != 0)
  25828. {
  25829. if (CFBundleLoadExecutable (bundleRef))
  25830. {
  25831. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("main_macho"));
  25832. if (moduleMain == 0)
  25833. moduleMain = (MainCall) CFBundleGetFunctionPointerForName (bundleRef, CFSTR("VSTPluginMain"));
  25834. if (moduleMain != 0)
  25835. {
  25836. CFTypeRef name = CFBundleGetValueForInfoDictionaryKey (bundleRef, CFSTR("CFBundleName"));
  25837. if (name != 0)
  25838. {
  25839. if (CFGetTypeID (name) == CFStringGetTypeID())
  25840. {
  25841. char buffer[1024];
  25842. if (CFStringGetCString ((CFStringRef) name, buffer, sizeof (buffer), CFStringGetSystemEncoding()))
  25843. pluginName = buffer;
  25844. }
  25845. }
  25846. if (pluginName.isEmpty())
  25847. pluginName = file.getFileNameWithoutExtension();
  25848. resFileId = CFBundleOpenBundleResourceMap (bundleRef);
  25849. ok = true;
  25850. }
  25851. }
  25852. if (! ok)
  25853. {
  25854. CFBundleUnloadExecutable (bundleRef);
  25855. CFRelease (bundleRef);
  25856. bundleRef = 0;
  25857. }
  25858. }
  25859. }
  25860. }
  25861. #if JUCE_PPC
  25862. else
  25863. {
  25864. FSRef fn;
  25865. if (FSPathMakeRef ((UInt8*) (const char*) filename, &fn, 0) == noErr)
  25866. {
  25867. resFileId = FSOpenResFile (&fn, fsRdPerm);
  25868. if (resFileId != -1)
  25869. {
  25870. const int numEffs = Count1Resources ('aEff');
  25871. for (int i = 0; i < numEffs; ++i)
  25872. {
  25873. resHandle = Get1IndResource ('aEff', i + 1);
  25874. if (resHandle != 0)
  25875. {
  25876. OSType type;
  25877. Str255 name;
  25878. SInt16 id;
  25879. GetResInfo (resHandle, &id, &type, name);
  25880. pluginName = String ((const char*) name + 1, name[0]);
  25881. DetachResource (resHandle);
  25882. HLock (resHandle);
  25883. Ptr ptr;
  25884. Str255 errorText;
  25885. OSErr err = GetMemFragment (*resHandle, GetHandleSize (resHandle),
  25886. name, kPrivateCFragCopy,
  25887. &fragId, &ptr, errorText);
  25888. if (err == noErr)
  25889. {
  25890. moduleMain = (MainCall) newMachOFromCFM (ptr);
  25891. ok = true;
  25892. }
  25893. else
  25894. {
  25895. HUnlock (resHandle);
  25896. }
  25897. break;
  25898. }
  25899. }
  25900. if (! ok)
  25901. CloseResFile (resFileId);
  25902. }
  25903. }
  25904. }
  25905. #endif
  25906. return ok;
  25907. }
  25908. void close()
  25909. {
  25910. #if JUCE_PPC
  25911. if (fragId != 0)
  25912. {
  25913. if (moduleMain != 0)
  25914. disposeMachOFromCFM ((void*) moduleMain);
  25915. CloseConnection (&fragId);
  25916. HUnlock (resHandle);
  25917. if (resFileId != 0)
  25918. CloseResFile (resFileId);
  25919. }
  25920. else
  25921. #endif
  25922. if (bundleRef != 0)
  25923. {
  25924. CFBundleCloseBundleResourceMap (bundleRef, resFileId);
  25925. if (CFGetRetainCount (bundleRef) == 1)
  25926. CFBundleUnloadExecutable (bundleRef);
  25927. if (CFGetRetainCount (bundleRef) > 0)
  25928. CFRelease (bundleRef);
  25929. }
  25930. }
  25931. void closeEffect (AEffect* eff)
  25932. {
  25933. #if JUCE_PPC
  25934. if (fragId != 0)
  25935. {
  25936. VoidArray thingsToDelete;
  25937. thingsToDelete.add ((void*) eff->dispatcher);
  25938. thingsToDelete.add ((void*) eff->process);
  25939. thingsToDelete.add ((void*) eff->setParameter);
  25940. thingsToDelete.add ((void*) eff->getParameter);
  25941. thingsToDelete.add ((void*) eff->processReplacing);
  25942. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25943. for (int i = thingsToDelete.size(); --i >= 0;)
  25944. disposeMachOFromCFM (thingsToDelete[i]);
  25945. }
  25946. else
  25947. #endif
  25948. {
  25949. eff->dispatcher (eff, effClose, 0, 0, 0, 0);
  25950. }
  25951. }
  25952. #if JUCE_PPC
  25953. static void* newMachOFromCFM (void* cfmfp)
  25954. {
  25955. if (cfmfp == 0)
  25956. return 0;
  25957. UInt32* const mfp = (UInt32*) juce_malloc (sizeof (UInt32) * 6);
  25958. mfp[0] = 0x3d800000 | ((UInt32) cfmfp >> 16);
  25959. mfp[1] = 0x618c0000 | ((UInt32) cfmfp & 0xffff);
  25960. mfp[2] = 0x800c0000;
  25961. mfp[3] = 0x804c0004;
  25962. mfp[4] = 0x7c0903a6;
  25963. mfp[5] = 0x4e800420;
  25964. MakeDataExecutable (mfp, sizeof (UInt32) * 6);
  25965. return mfp;
  25966. }
  25967. static void disposeMachOFromCFM (void* ptr)
  25968. {
  25969. juce_free (ptr);
  25970. }
  25971. void coerceAEffectFunctionCalls (AEffect* eff)
  25972. {
  25973. if (fragId != 0)
  25974. {
  25975. eff->dispatcher = (AEffectDispatcherProc) newMachOFromCFM ((void*) eff->dispatcher);
  25976. eff->process = (AEffectProcessProc) newMachOFromCFM ((void*) eff->process);
  25977. eff->setParameter = (AEffectSetParameterProc) newMachOFromCFM ((void*) eff->setParameter);
  25978. eff->getParameter = (AEffectGetParameterProc) newMachOFromCFM ((void*) eff->getParameter);
  25979. eff->processReplacing = (AEffectProcessProc) newMachOFromCFM ((void*) eff->processReplacing);
  25980. }
  25981. }
  25982. #endif
  25983. #endif
  25984. };
  25985. class VSTPluginInstance : public AudioPluginInstance,
  25986. private Timer,
  25987. private AsyncUpdater
  25988. {
  25989. public:
  25990. ~VSTPluginInstance();
  25991. // AudioPluginInstance methods:
  25992. void fillInPluginDescription (PluginDescription& desc) const
  25993. {
  25994. desc.name = name;
  25995. desc.fileOrIdentifier = module->file.getFullPathName();
  25996. desc.uid = getUID();
  25997. desc.lastFileModTime = module->file.getLastModificationTime();
  25998. desc.pluginFormatName = "VST";
  25999. desc.category = getCategory();
  26000. {
  26001. char buffer [kVstMaxVendorStrLen + 8];
  26002. zerostruct (buffer);
  26003. dispatch (effGetVendorString, 0, 0, buffer, 0);
  26004. desc.manufacturerName = buffer;
  26005. }
  26006. desc.version = getVersion();
  26007. desc.numInputChannels = getNumInputChannels();
  26008. desc.numOutputChannels = getNumOutputChannels();
  26009. desc.isInstrument = (effect != 0 && (effect->flags & effFlagsIsSynth) != 0);
  26010. }
  26011. const String getName() const { return name; }
  26012. int getUID() const throw();
  26013. bool acceptsMidi() const { return wantsMidiMessages; }
  26014. bool producesMidi() const { return dispatch (effCanDo, 0, 0, (void*) "sendVstMidiEvent", 0) > 0; }
  26015. // AudioProcessor methods:
  26016. void prepareToPlay (double sampleRate, int estimatedSamplesPerBlock);
  26017. void releaseResources();
  26018. void processBlock (AudioSampleBuffer& buffer,
  26019. MidiBuffer& midiMessages);
  26020. AudioProcessorEditor* createEditor();
  26021. const String getInputChannelName (const int index) const;
  26022. bool isInputChannelStereoPair (int index) const;
  26023. const String getOutputChannelName (const int index) const;
  26024. bool isOutputChannelStereoPair (int index) const;
  26025. int getNumParameters() { return effect != 0 ? effect->numParams : 0; }
  26026. float getParameter (int index);
  26027. void setParameter (int index, float newValue);
  26028. const String getParameterName (int index);
  26029. const String getParameterText (int index);
  26030. bool isParameterAutomatable (int index) const;
  26031. int getNumPrograms() { return effect != 0 ? effect->numPrograms : 0; }
  26032. int getCurrentProgram() { return dispatch (effGetProgram, 0, 0, 0, 0); }
  26033. void setCurrentProgram (int index);
  26034. const String getProgramName (int index);
  26035. void changeProgramName (int index, const String& newName);
  26036. void getStateInformation (MemoryBlock& destData);
  26037. void getCurrentProgramStateInformation (MemoryBlock& destData);
  26038. void setStateInformation (const void* data, int sizeInBytes);
  26039. void setCurrentProgramStateInformation (const void* data, int sizeInBytes);
  26040. void timerCallback();
  26041. void handleAsyncUpdate();
  26042. VstIntPtr handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt);
  26043. juce_UseDebuggingNewOperator
  26044. private:
  26045. friend class VSTPluginWindow;
  26046. friend class VSTPluginFormat;
  26047. AEffect* effect;
  26048. String name;
  26049. CriticalSection lock;
  26050. bool wantsMidiMessages, initialised, isPowerOn;
  26051. mutable StringArray programNames;
  26052. AudioSampleBuffer tempBuffer;
  26053. CriticalSection midiInLock;
  26054. MidiBuffer incomingMidi;
  26055. VSTMidiEventList midiEventsToSend;
  26056. VstTimeInfo vstHostTime;
  26057. HeapBlock <float*> channels;
  26058. ReferenceCountedObjectPtr <ModuleHandle> module;
  26059. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const;
  26060. bool restoreProgramSettings (const fxProgram* const prog);
  26061. const String getCurrentProgramName();
  26062. void setParamsInProgramBlock (fxProgram* const prog) throw();
  26063. void updateStoredProgramNames();
  26064. void initialise();
  26065. void handleMidiFromPlugin (const VstEvents* const events);
  26066. void createTempParameterStore (MemoryBlock& dest);
  26067. void restoreFromTempParameterStore (const MemoryBlock& mb);
  26068. const String getParameterLabel (int index) const;
  26069. bool usesChunks() const throw() { return effect != 0 && (effect->flags & effFlagsProgramChunks) != 0; }
  26070. void getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const;
  26071. void setChunkData (const char* data, int size, bool isPreset);
  26072. bool loadFromFXBFile (const void* data, int numBytes);
  26073. bool saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB);
  26074. int getVersionNumber() const throw() { return effect != 0 ? effect->version : 0; }
  26075. const String getVersion() const throw();
  26076. const String getCategory() const throw();
  26077. bool hasEditor() const throw() { return effect != 0 && (effect->flags & effFlagsHasEditor) != 0; }
  26078. void setPower (const bool on);
  26079. VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module);
  26080. };
  26081. VSTPluginInstance::VSTPluginInstance (const ReferenceCountedObjectPtr <ModuleHandle>& module_)
  26082. : effect (0),
  26083. wantsMidiMessages (false),
  26084. initialised (false),
  26085. isPowerOn (false),
  26086. tempBuffer (1, 1),
  26087. module (module_)
  26088. {
  26089. try
  26090. {
  26091. _fpreset();
  26092. ++insideVSTCallback;
  26093. name = module->pluginName;
  26094. log (T("Creating VST instance: ") + name);
  26095. #if JUCE_MAC
  26096. if (module->resFileId != 0)
  26097. UseResFile (module->resFileId);
  26098. #if JUCE_PPC
  26099. if (module->fragId != 0)
  26100. {
  26101. static void* audioMasterCoerced = 0;
  26102. if (audioMasterCoerced == 0)
  26103. audioMasterCoerced = NewCFMFromMachO ((void*) &audioMaster);
  26104. effect = module->moduleMain ((audioMasterCallback) audioMasterCoerced);
  26105. }
  26106. else
  26107. #endif
  26108. #endif
  26109. {
  26110. effect = module->moduleMain (&audioMaster);
  26111. }
  26112. --insideVSTCallback;
  26113. if (effect != 0 && effect->magic == kEffectMagic)
  26114. {
  26115. #if JUCE_PPC
  26116. module->coerceAEffectFunctionCalls (effect);
  26117. #endif
  26118. jassert (effect->resvd2 == 0);
  26119. jassert (effect->object != 0);
  26120. _fpreset(); // some dodgy plugs fuck around with this
  26121. }
  26122. else
  26123. {
  26124. effect = 0;
  26125. }
  26126. }
  26127. catch (...)
  26128. {
  26129. --insideVSTCallback;
  26130. }
  26131. }
  26132. VSTPluginInstance::~VSTPluginInstance()
  26133. {
  26134. {
  26135. const ScopedLock sl (lock);
  26136. jassert (insideVSTCallback == 0);
  26137. if (effect != 0 && effect->magic == kEffectMagic)
  26138. {
  26139. try
  26140. {
  26141. #if JUCE_MAC
  26142. if (module->resFileId != 0)
  26143. UseResFile (module->resFileId);
  26144. #endif
  26145. // Must delete any editors before deleting the plugin instance!
  26146. jassert (getActiveEditor() == 0);
  26147. _fpreset(); // some dodgy plugs fuck around with this
  26148. module->closeEffect (effect);
  26149. }
  26150. catch (...)
  26151. {}
  26152. }
  26153. module = 0;
  26154. effect = 0;
  26155. }
  26156. }
  26157. void VSTPluginInstance::initialise()
  26158. {
  26159. if (initialised || effect == 0)
  26160. return;
  26161. log (T("Initialising VST: ") + module->pluginName);
  26162. initialised = true;
  26163. dispatch (effIdentify, 0, 0, 0, 0);
  26164. // this code would ask the plugin for its name, but so few plugins
  26165. // actually bother implementing this correctly, that it's better to
  26166. // just ignore it and use the file name instead.
  26167. if (getSampleRate() > 0)
  26168. dispatch (effSetSampleRate, 0, 0, 0, (float) getSampleRate());
  26169. if (getBlockSize() > 0)
  26170. dispatch (effSetBlockSize, 0, jmax (32, getBlockSize()), 0, 0);
  26171. dispatch (effOpen, 0, 0, 0, 0);
  26172. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26173. getSampleRate(), getBlockSize());
  26174. if (getNumPrograms() > 1)
  26175. setCurrentProgram (0);
  26176. else
  26177. dispatch (effSetProgram, 0, 0, 0, 0);
  26178. int i;
  26179. for (i = effect->numInputs; --i >= 0;)
  26180. dispatch (effConnectInput, i, 1, 0, 0);
  26181. for (i = effect->numOutputs; --i >= 0;)
  26182. dispatch (effConnectOutput, i, 1, 0, 0);
  26183. updateStoredProgramNames();
  26184. wantsMidiMessages = dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0;
  26185. setLatencySamples (effect->initialDelay);
  26186. }
  26187. void VSTPluginInstance::prepareToPlay (double sampleRate_,
  26188. int samplesPerBlockExpected)
  26189. {
  26190. setPlayConfigDetails (effect->numInputs, effect->numOutputs,
  26191. sampleRate_, samplesPerBlockExpected);
  26192. setLatencySamples (effect->initialDelay);
  26193. channels.calloc (jmax (16, getNumOutputChannels(), getNumInputChannels()) + 2);
  26194. vstHostTime.tempo = 120.0;
  26195. vstHostTime.timeSigNumerator = 4;
  26196. vstHostTime.timeSigDenominator = 4;
  26197. vstHostTime.sampleRate = sampleRate_;
  26198. vstHostTime.samplePos = 0;
  26199. vstHostTime.flags = kVstNanosValid; /*| kVstTransportPlaying | kVstTempoValid | kVstTimeSigValid*/;
  26200. initialise();
  26201. if (initialised)
  26202. {
  26203. wantsMidiMessages = wantsMidiMessages
  26204. || (dispatch (effCanDo, 0, 0, (void*) "receiveVstMidiEvent", 0) > 0);
  26205. if (wantsMidiMessages)
  26206. midiEventsToSend.ensureSize (256);
  26207. else
  26208. midiEventsToSend.freeEvents();
  26209. incomingMidi.clear();
  26210. dispatch (effSetSampleRate, 0, 0, 0, (float) sampleRate_);
  26211. dispatch (effSetBlockSize, 0, jmax (16, samplesPerBlockExpected), 0, 0);
  26212. tempBuffer.setSize (jmax (1, effect->numOutputs), samplesPerBlockExpected);
  26213. if (! isPowerOn)
  26214. setPower (true);
  26215. // dodgy hack to force some plugins to initialise the sample rate..
  26216. if ((! hasEditor()) && getNumParameters() > 0)
  26217. {
  26218. const float old = getParameter (0);
  26219. setParameter (0, (old < 0.5f) ? 1.0f : 0.0f);
  26220. setParameter (0, old);
  26221. }
  26222. dispatch (effStartProcess, 0, 0, 0, 0);
  26223. }
  26224. }
  26225. void VSTPluginInstance::releaseResources()
  26226. {
  26227. if (initialised)
  26228. {
  26229. dispatch (effStopProcess, 0, 0, 0, 0);
  26230. setPower (false);
  26231. }
  26232. tempBuffer.setSize (1, 1);
  26233. incomingMidi.clear();
  26234. midiEventsToSend.freeEvents();
  26235. channels.free();
  26236. }
  26237. void VSTPluginInstance::processBlock (AudioSampleBuffer& buffer,
  26238. MidiBuffer& midiMessages)
  26239. {
  26240. const int numSamples = buffer.getNumSamples();
  26241. if (initialised)
  26242. {
  26243. AudioPlayHead* playHead = getPlayHead();
  26244. if (playHead != 0)
  26245. {
  26246. AudioPlayHead::CurrentPositionInfo position;
  26247. playHead->getCurrentPosition (position);
  26248. vstHostTime.tempo = position.bpm;
  26249. vstHostTime.timeSigNumerator = position.timeSigNumerator;
  26250. vstHostTime.timeSigDenominator = position.timeSigDenominator;
  26251. vstHostTime.ppqPos = position.ppqPosition;
  26252. vstHostTime.barStartPos = position.ppqPositionOfLastBarStart;
  26253. vstHostTime.flags |= kVstTempoValid | kVstTimeSigValid | kVstPpqPosValid | kVstBarsValid;
  26254. if (position.isPlaying)
  26255. vstHostTime.flags |= kVstTransportPlaying;
  26256. else
  26257. vstHostTime.flags &= ~kVstTransportPlaying;
  26258. }
  26259. #if JUCE_WIN32
  26260. vstHostTime.nanoSeconds = timeGetTime() * 1000000.0;
  26261. #elif JUCE_LINUX
  26262. timeval micro;
  26263. gettimeofday (&micro, 0);
  26264. vstHostTime.nanoSeconds = micro.tv_usec * 1000.0;
  26265. #elif JUCE_MAC
  26266. UnsignedWide micro;
  26267. Microseconds (&micro);
  26268. vstHostTime.nanoSeconds = micro.lo * 1000.0;
  26269. #endif
  26270. if (wantsMidiMessages)
  26271. {
  26272. midiEventsToSend.clear();
  26273. midiEventsToSend.ensureSize (1);
  26274. MidiBuffer::Iterator iter (midiMessages);
  26275. const uint8* midiData;
  26276. int numBytesOfMidiData, samplePosition;
  26277. while (iter.getNextEvent (midiData, numBytesOfMidiData, samplePosition))
  26278. {
  26279. midiEventsToSend.addEvent (midiData, numBytesOfMidiData,
  26280. jlimit (0, numSamples - 1, samplePosition));
  26281. }
  26282. try
  26283. {
  26284. effect->dispatcher (effect, effProcessEvents, 0, 0, midiEventsToSend.events, 0);
  26285. }
  26286. catch (...)
  26287. {}
  26288. }
  26289. int i;
  26290. const int maxChans = jmax (effect->numInputs, effect->numOutputs);
  26291. for (i = 0; i < maxChans; ++i)
  26292. channels[i] = buffer.getSampleData (i);
  26293. channels [maxChans] = 0;
  26294. _clearfp();
  26295. if ((effect->flags & effFlagsCanReplacing) != 0)
  26296. {
  26297. try
  26298. {
  26299. effect->processReplacing (effect, channels, channels, numSamples);
  26300. }
  26301. catch (...)
  26302. {}
  26303. }
  26304. else
  26305. {
  26306. tempBuffer.setSize (effect->numOutputs, numSamples);
  26307. tempBuffer.clear();
  26308. float* outs [64];
  26309. for (i = effect->numOutputs; --i >= 0;)
  26310. outs[i] = tempBuffer.getSampleData (i);
  26311. outs [effect->numOutputs] = 0;
  26312. try
  26313. {
  26314. effect->process (effect, channels, outs, numSamples);
  26315. }
  26316. catch (...)
  26317. {}
  26318. for (i = effect->numOutputs; --i >= 0;)
  26319. buffer.copyFrom (i, 0, outs[i], numSamples);
  26320. }
  26321. }
  26322. else
  26323. {
  26324. // Not initialised, so just bypass..
  26325. for (int i = getNumInputChannels(); i < getNumOutputChannels(); ++i)
  26326. buffer.clear (i, 0, buffer.getNumSamples());
  26327. }
  26328. {
  26329. // copy any incoming midi..
  26330. const ScopedLock sl (midiInLock);
  26331. midiMessages = incomingMidi;
  26332. incomingMidi.clear();
  26333. }
  26334. }
  26335. void VSTPluginInstance::handleMidiFromPlugin (const VstEvents* const events)
  26336. {
  26337. if (events != 0)
  26338. {
  26339. const ScopedLock sl (midiInLock);
  26340. VSTMidiEventList::addEventsToMidiBuffer (events, incomingMidi);
  26341. }
  26342. }
  26343. static Array <VSTPluginWindow*> activeVSTWindows;
  26344. class VSTPluginWindow : public AudioProcessorEditor,
  26345. #if ! JUCE_MAC
  26346. public ComponentMovementWatcher,
  26347. #endif
  26348. public Timer
  26349. {
  26350. public:
  26351. VSTPluginWindow (VSTPluginInstance& plugin_)
  26352. : AudioProcessorEditor (&plugin_),
  26353. #if ! JUCE_MAC
  26354. ComponentMovementWatcher (this),
  26355. #endif
  26356. plugin (plugin_),
  26357. isOpen (false),
  26358. wasShowing (false),
  26359. pluginRefusesToResize (false),
  26360. pluginWantsKeys (false),
  26361. alreadyInside (false),
  26362. recursiveResize (false)
  26363. {
  26364. #if JUCE_WIN32
  26365. sizeCheckCount = 0;
  26366. pluginHWND = 0;
  26367. #elif JUCE_LINUX
  26368. pluginWindow = None;
  26369. pluginProc = None;
  26370. #else
  26371. addAndMakeVisible (innerWrapper = new InnerWrapperComponent (this));
  26372. #endif
  26373. activeVSTWindows.add (this);
  26374. setSize (1, 1);
  26375. setOpaque (true);
  26376. setVisible (true);
  26377. }
  26378. ~VSTPluginWindow()
  26379. {
  26380. #if JUCE_MAC
  26381. innerWrapper = 0;
  26382. #else
  26383. closePluginWindow();
  26384. #endif
  26385. activeVSTWindows.removeValue (this);
  26386. plugin.editorBeingDeleted (this);
  26387. }
  26388. #if ! JUCE_MAC
  26389. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  26390. {
  26391. if (recursiveResize)
  26392. return;
  26393. Component* const topComp = getTopLevelComponent();
  26394. if (topComp->getPeer() != 0)
  26395. {
  26396. const Point<int> pos (relativePositionToOtherComponent (topComp, Point<int>()));
  26397. recursiveResize = true;
  26398. #if JUCE_WIN32
  26399. if (pluginHWND != 0)
  26400. MoveWindow (pluginHWND, pos.getX(), pos.getY(), getWidth(), getHeight(), TRUE);
  26401. #elif JUCE_LINUX
  26402. if (pluginWindow != 0)
  26403. {
  26404. XResizeWindow (display, pluginWindow, getWidth(), getHeight());
  26405. XMoveWindow (display, pluginWindow, pos.getX(), pos.getY());
  26406. XMapRaised (display, pluginWindow);
  26407. }
  26408. #endif
  26409. recursiveResize = false;
  26410. }
  26411. }
  26412. void componentVisibilityChanged (Component&)
  26413. {
  26414. const bool isShowingNow = isShowing();
  26415. if (wasShowing != isShowingNow)
  26416. {
  26417. wasShowing = isShowingNow;
  26418. if (isShowingNow)
  26419. openPluginWindow();
  26420. else
  26421. closePluginWindow();
  26422. }
  26423. componentMovedOrResized (true, true);
  26424. }
  26425. void componentPeerChanged()
  26426. {
  26427. closePluginWindow();
  26428. openPluginWindow();
  26429. }
  26430. #endif
  26431. bool keyStateChanged (const bool)
  26432. {
  26433. return pluginWantsKeys;
  26434. }
  26435. bool keyPressed (const KeyPress&)
  26436. {
  26437. return pluginWantsKeys;
  26438. }
  26439. #if JUCE_MAC
  26440. void paint (Graphics& g)
  26441. {
  26442. g.fillAll (Colours::black);
  26443. }
  26444. #else
  26445. void paint (Graphics& g)
  26446. {
  26447. if (isOpen)
  26448. {
  26449. ComponentPeer* const peer = getPeer();
  26450. if (peer != 0)
  26451. {
  26452. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26453. peer->addMaskedRegion (pos.getX(), pos.getY(), getWidth(), getHeight());
  26454. #if JUCE_LINUX
  26455. if (pluginWindow != 0)
  26456. {
  26457. const Rectangle<int> clip (g.getClipBounds());
  26458. XEvent ev;
  26459. zerostruct (ev);
  26460. ev.xexpose.type = Expose;
  26461. ev.xexpose.display = display;
  26462. ev.xexpose.window = pluginWindow;
  26463. ev.xexpose.x = clip.getX();
  26464. ev.xexpose.y = clip.getY();
  26465. ev.xexpose.width = clip.getWidth();
  26466. ev.xexpose.height = clip.getHeight();
  26467. sendEventToChild (&ev);
  26468. }
  26469. #endif
  26470. }
  26471. }
  26472. else
  26473. {
  26474. g.fillAll (Colours::black);
  26475. }
  26476. }
  26477. #endif
  26478. void timerCallback()
  26479. {
  26480. #if JUCE_WIN32
  26481. if (--sizeCheckCount <= 0)
  26482. {
  26483. sizeCheckCount = 10;
  26484. checkPluginWindowSize();
  26485. }
  26486. #endif
  26487. try
  26488. {
  26489. static bool reentrant = false;
  26490. if (! reentrant)
  26491. {
  26492. reentrant = true;
  26493. plugin.dispatch (effEditIdle, 0, 0, 0, 0);
  26494. reentrant = false;
  26495. }
  26496. }
  26497. catch (...)
  26498. {}
  26499. }
  26500. void mouseDown (const MouseEvent& e)
  26501. {
  26502. #if JUCE_LINUX
  26503. if (pluginWindow == 0)
  26504. return;
  26505. toFront (true);
  26506. XEvent ev;
  26507. zerostruct (ev);
  26508. ev.xbutton.display = display;
  26509. ev.xbutton.type = ButtonPress;
  26510. ev.xbutton.window = pluginWindow;
  26511. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26512. ev.xbutton.time = CurrentTime;
  26513. ev.xbutton.x = e.x;
  26514. ev.xbutton.y = e.y;
  26515. ev.xbutton.x_root = e.getScreenX();
  26516. ev.xbutton.y_root = e.getScreenY();
  26517. translateJuceToXButtonModifiers (e, ev);
  26518. sendEventToChild (&ev);
  26519. #elif JUCE_WIN32
  26520. (void) e;
  26521. toFront (true);
  26522. #endif
  26523. }
  26524. void broughtToFront()
  26525. {
  26526. activeVSTWindows.removeValue (this);
  26527. activeVSTWindows.add (this);
  26528. #if JUCE_MAC
  26529. dispatch (effEditTop, 0, 0, 0, 0);
  26530. #endif
  26531. }
  26532. juce_UseDebuggingNewOperator
  26533. private:
  26534. VSTPluginInstance& plugin;
  26535. bool isOpen, wasShowing, recursiveResize;
  26536. bool pluginWantsKeys, pluginRefusesToResize, alreadyInside;
  26537. #if JUCE_WIN32
  26538. HWND pluginHWND;
  26539. void* originalWndProc;
  26540. int sizeCheckCount;
  26541. #elif JUCE_LINUX
  26542. Window pluginWindow;
  26543. EventProcPtr pluginProc;
  26544. #endif
  26545. #if JUCE_MAC
  26546. void openPluginWindow (WindowRef parentWindow)
  26547. {
  26548. if (isOpen || parentWindow == 0)
  26549. return;
  26550. isOpen = true;
  26551. ERect* rect = 0;
  26552. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26553. dispatch (effEditOpen, 0, 0, parentWindow, 0);
  26554. // do this before and after like in the steinberg example
  26555. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26556. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26557. // Install keyboard hooks
  26558. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26559. // double-check it's not too tiny
  26560. int w = 250, h = 150;
  26561. if (rect != 0)
  26562. {
  26563. w = rect->right - rect->left;
  26564. h = rect->bottom - rect->top;
  26565. if (w == 0 || h == 0)
  26566. {
  26567. w = 250;
  26568. h = 150;
  26569. }
  26570. }
  26571. w = jmax (w, 32);
  26572. h = jmax (h, 32);
  26573. setSize (w, h);
  26574. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26575. repaint();
  26576. }
  26577. #else
  26578. void openPluginWindow()
  26579. {
  26580. if (isOpen || getWindowHandle() == 0)
  26581. return;
  26582. log (T("Opening VST UI: ") + plugin.name);
  26583. isOpen = true;
  26584. ERect* rect = 0;
  26585. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26586. dispatch (effEditOpen, 0, 0, getWindowHandle(), 0);
  26587. // do this before and after like in the steinberg example
  26588. dispatch (effEditGetRect, 0, 0, &rect, 0);
  26589. dispatch (effGetProgram, 0, 0, 0, 0); // also in steinberg code
  26590. // Install keyboard hooks
  26591. pluginWantsKeys = (dispatch (effKeysRequired, 0, 0, 0, 0) == 0);
  26592. #if JUCE_WIN32
  26593. originalWndProc = 0;
  26594. pluginHWND = GetWindow ((HWND) getWindowHandle(), GW_CHILD);
  26595. if (pluginHWND == 0)
  26596. {
  26597. isOpen = false;
  26598. setSize (300, 150);
  26599. return;
  26600. }
  26601. #pragma warning (push)
  26602. #pragma warning (disable: 4244)
  26603. originalWndProc = (void*) GetWindowLongPtr (pluginHWND, GWL_WNDPROC);
  26604. if (! pluginWantsKeys)
  26605. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) vstHookWndProc);
  26606. #pragma warning (pop)
  26607. int w, h;
  26608. RECT r;
  26609. GetWindowRect (pluginHWND, &r);
  26610. w = r.right - r.left;
  26611. h = r.bottom - r.top;
  26612. if (rect != 0)
  26613. {
  26614. const int rw = rect->right - rect->left;
  26615. const int rh = rect->bottom - rect->top;
  26616. if ((rw > 50 && rh > 50 && rw < 2000 && rh < 2000 && rw != w && rh != h)
  26617. || ((w == 0 && rw > 0) || (h == 0 && rh > 0)))
  26618. {
  26619. // very dodgy logic to decide which size is right.
  26620. if (abs (rw - w) > 350 || abs (rh - h) > 350)
  26621. {
  26622. SetWindowPos (pluginHWND, 0,
  26623. 0, 0, rw, rh,
  26624. SWP_NOMOVE | SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  26625. GetWindowRect (pluginHWND, &r);
  26626. w = r.right - r.left;
  26627. h = r.bottom - r.top;
  26628. pluginRefusesToResize = (w != rw) || (h != rh);
  26629. w = rw;
  26630. h = rh;
  26631. }
  26632. }
  26633. }
  26634. #elif JUCE_LINUX
  26635. pluginWindow = getChildWindow ((Window) getWindowHandle());
  26636. if (pluginWindow != 0)
  26637. pluginProc = (EventProcPtr) getPropertyFromXWindow (pluginWindow,
  26638. XInternAtom (display, "_XEventProc", False));
  26639. int w = 250, h = 150;
  26640. if (rect != 0)
  26641. {
  26642. w = rect->right - rect->left;
  26643. h = rect->bottom - rect->top;
  26644. if (w == 0 || h == 0)
  26645. {
  26646. w = 250;
  26647. h = 150;
  26648. }
  26649. }
  26650. if (pluginWindow != 0)
  26651. XMapRaised (display, pluginWindow);
  26652. #endif
  26653. // double-check it's not too tiny
  26654. w = jmax (w, 32);
  26655. h = jmax (h, 32);
  26656. setSize (w, h);
  26657. #if JUCE_WIN32
  26658. checkPluginWindowSize();
  26659. #endif
  26660. startTimer (18 + JUCE_NAMESPACE::Random::getSystemRandom().nextInt (5));
  26661. repaint();
  26662. }
  26663. #endif
  26664. #if ! JUCE_MAC
  26665. void closePluginWindow()
  26666. {
  26667. if (isOpen)
  26668. {
  26669. log (T("Closing VST UI: ") + plugin.getName());
  26670. isOpen = false;
  26671. dispatch (effEditClose, 0, 0, 0, 0);
  26672. #if JUCE_WIN32
  26673. #pragma warning (push)
  26674. #pragma warning (disable: 4244)
  26675. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26676. SetWindowLongPtr (pluginHWND, GWL_WNDPROC, (LONG_PTR) originalWndProc);
  26677. #pragma warning (pop)
  26678. stopTimer();
  26679. if (pluginHWND != 0 && IsWindow (pluginHWND))
  26680. DestroyWindow (pluginHWND);
  26681. pluginHWND = 0;
  26682. #elif JUCE_LINUX
  26683. stopTimer();
  26684. pluginWindow = 0;
  26685. pluginProc = 0;
  26686. #endif
  26687. }
  26688. }
  26689. #endif
  26690. int dispatch (const int opcode, const int index, const int value, void* const ptr, float opt)
  26691. {
  26692. return plugin.dispatch (opcode, index, value, ptr, opt);
  26693. }
  26694. #if JUCE_WIN32
  26695. void checkPluginWindowSize() throw()
  26696. {
  26697. RECT r;
  26698. GetWindowRect (pluginHWND, &r);
  26699. const int w = r.right - r.left;
  26700. const int h = r.bottom - r.top;
  26701. if (isShowing() && w > 0 && h > 0
  26702. && (w != getWidth() || h != getHeight())
  26703. && ! pluginRefusesToResize)
  26704. {
  26705. setSize (w, h);
  26706. sizeCheckCount = 0;
  26707. }
  26708. }
  26709. // hooks to get keyboard events from VST windows..
  26710. static LRESULT CALLBACK vstHookWndProc (HWND hW, UINT message, WPARAM wParam, LPARAM lParam)
  26711. {
  26712. for (int i = activeVSTWindows.size(); --i >= 0;)
  26713. {
  26714. const VSTPluginWindow* const w = (const VSTPluginWindow*) activeVSTWindows.getUnchecked (i);
  26715. if (w->pluginHWND == hW)
  26716. {
  26717. if (message == WM_CHAR
  26718. || message == WM_KEYDOWN
  26719. || message == WM_SYSKEYDOWN
  26720. || message == WM_KEYUP
  26721. || message == WM_SYSKEYUP
  26722. || message == WM_APPCOMMAND)
  26723. {
  26724. SendMessage ((HWND) w->getTopLevelComponent()->getWindowHandle(),
  26725. message, wParam, lParam);
  26726. }
  26727. return CallWindowProc ((WNDPROC) (w->originalWndProc),
  26728. (HWND) w->pluginHWND,
  26729. message,
  26730. wParam,
  26731. lParam);
  26732. }
  26733. }
  26734. return DefWindowProc (hW, message, wParam, lParam);
  26735. }
  26736. #endif
  26737. #if JUCE_LINUX
  26738. // overload mouse/keyboard events to forward them to the plugin's inner window..
  26739. void sendEventToChild (XEvent* event)
  26740. {
  26741. if (pluginProc != 0)
  26742. {
  26743. // if the plugin publishes an event procedure, pass the event directly..
  26744. pluginProc (event);
  26745. }
  26746. else if (pluginWindow != 0)
  26747. {
  26748. // if the plugin has a window, then send the event to the window so that
  26749. // its message thread will pick it up..
  26750. XSendEvent (display, pluginWindow, False, 0L, event);
  26751. XFlush (display);
  26752. }
  26753. }
  26754. void mouseEnter (const MouseEvent& e)
  26755. {
  26756. if (pluginWindow != 0)
  26757. {
  26758. XEvent ev;
  26759. zerostruct (ev);
  26760. ev.xcrossing.display = display;
  26761. ev.xcrossing.type = EnterNotify;
  26762. ev.xcrossing.window = pluginWindow;
  26763. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26764. ev.xcrossing.time = CurrentTime;
  26765. ev.xcrossing.x = e.x;
  26766. ev.xcrossing.y = e.y;
  26767. ev.xcrossing.x_root = e.getScreenX();
  26768. ev.xcrossing.y_root = e.getScreenY();
  26769. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26770. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26771. translateJuceToXCrossingModifiers (e, ev);
  26772. sendEventToChild (&ev);
  26773. }
  26774. }
  26775. void mouseExit (const MouseEvent& e)
  26776. {
  26777. if (pluginWindow != 0)
  26778. {
  26779. XEvent ev;
  26780. zerostruct (ev);
  26781. ev.xcrossing.display = display;
  26782. ev.xcrossing.type = LeaveNotify;
  26783. ev.xcrossing.window = pluginWindow;
  26784. ev.xcrossing.root = RootWindow (display, DefaultScreen (display));
  26785. ev.xcrossing.time = CurrentTime;
  26786. ev.xcrossing.x = e.x;
  26787. ev.xcrossing.y = e.y;
  26788. ev.xcrossing.x_root = e.getScreenX();
  26789. ev.xcrossing.y_root = e.getScreenY();
  26790. ev.xcrossing.mode = NotifyNormal; // NotifyGrab, NotifyUngrab
  26791. ev.xcrossing.detail = NotifyAncestor; // NotifyVirtual, NotifyInferior, NotifyNonlinear,NotifyNonlinearVirtual
  26792. ev.xcrossing.focus = hasKeyboardFocus (true); // TODO - yes ?
  26793. translateJuceToXCrossingModifiers (e, ev);
  26794. sendEventToChild (&ev);
  26795. }
  26796. }
  26797. void mouseMove (const MouseEvent& e)
  26798. {
  26799. if (pluginWindow != 0)
  26800. {
  26801. XEvent ev;
  26802. zerostruct (ev);
  26803. ev.xmotion.display = display;
  26804. ev.xmotion.type = MotionNotify;
  26805. ev.xmotion.window = pluginWindow;
  26806. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26807. ev.xmotion.time = CurrentTime;
  26808. ev.xmotion.is_hint = NotifyNormal;
  26809. ev.xmotion.x = e.x;
  26810. ev.xmotion.y = e.y;
  26811. ev.xmotion.x_root = e.getScreenX();
  26812. ev.xmotion.y_root = e.getScreenY();
  26813. sendEventToChild (&ev);
  26814. }
  26815. }
  26816. void mouseDrag (const MouseEvent& e)
  26817. {
  26818. if (pluginWindow != 0)
  26819. {
  26820. XEvent ev;
  26821. zerostruct (ev);
  26822. ev.xmotion.display = display;
  26823. ev.xmotion.type = MotionNotify;
  26824. ev.xmotion.window = pluginWindow;
  26825. ev.xmotion.root = RootWindow (display, DefaultScreen (display));
  26826. ev.xmotion.time = CurrentTime;
  26827. ev.xmotion.x = e.x ;
  26828. ev.xmotion.y = e.y;
  26829. ev.xmotion.x_root = e.getScreenX();
  26830. ev.xmotion.y_root = e.getScreenY();
  26831. ev.xmotion.is_hint = NotifyNormal;
  26832. translateJuceToXMotionModifiers (e, ev);
  26833. sendEventToChild (&ev);
  26834. }
  26835. }
  26836. void mouseUp (const MouseEvent& e)
  26837. {
  26838. if (pluginWindow != 0)
  26839. {
  26840. XEvent ev;
  26841. zerostruct (ev);
  26842. ev.xbutton.display = display;
  26843. ev.xbutton.type = ButtonRelease;
  26844. ev.xbutton.window = pluginWindow;
  26845. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26846. ev.xbutton.time = CurrentTime;
  26847. ev.xbutton.x = e.x;
  26848. ev.xbutton.y = e.y;
  26849. ev.xbutton.x_root = e.getScreenX();
  26850. ev.xbutton.y_root = e.getScreenY();
  26851. translateJuceToXButtonModifiers (e, ev);
  26852. sendEventToChild (&ev);
  26853. }
  26854. }
  26855. void mouseWheelMove (const MouseEvent& e,
  26856. float incrementX,
  26857. float incrementY)
  26858. {
  26859. if (pluginWindow != 0)
  26860. {
  26861. XEvent ev;
  26862. zerostruct (ev);
  26863. ev.xbutton.display = display;
  26864. ev.xbutton.type = ButtonPress;
  26865. ev.xbutton.window = pluginWindow;
  26866. ev.xbutton.root = RootWindow (display, DefaultScreen (display));
  26867. ev.xbutton.time = CurrentTime;
  26868. ev.xbutton.x = e.x;
  26869. ev.xbutton.y = e.y;
  26870. ev.xbutton.x_root = e.getScreenX();
  26871. ev.xbutton.y_root = e.getScreenY();
  26872. translateJuceToXMouseWheelModifiers (e, incrementY, ev);
  26873. sendEventToChild (&ev);
  26874. // TODO - put a usleep here ?
  26875. ev.xbutton.type = ButtonRelease;
  26876. sendEventToChild (&ev);
  26877. }
  26878. }
  26879. #endif
  26880. #if JUCE_MAC
  26881. #if ! JUCE_SUPPORT_CARBON
  26882. #error "To build VSTs, you need to enable the JUCE_SUPPORT_CARBON flag in your config!"
  26883. #endif
  26884. class InnerWrapperComponent : public CarbonViewWrapperComponent
  26885. {
  26886. public:
  26887. InnerWrapperComponent (VSTPluginWindow* const owner_)
  26888. : owner (owner_),
  26889. alreadyInside (false)
  26890. {
  26891. }
  26892. ~InnerWrapperComponent()
  26893. {
  26894. deleteWindow();
  26895. }
  26896. HIViewRef attachView (WindowRef windowRef, HIViewRef rootView)
  26897. {
  26898. owner->openPluginWindow (windowRef);
  26899. return 0;
  26900. }
  26901. void removeView (HIViewRef)
  26902. {
  26903. owner->dispatch (effEditClose, 0, 0, 0, 0);
  26904. owner->dispatch (effEditSleep, 0, 0, 0, 0);
  26905. }
  26906. bool getEmbeddedViewSize (int& w, int& h)
  26907. {
  26908. ERect* rect = 0;
  26909. owner->dispatch (effEditGetRect, 0, 0, &rect, 0);
  26910. w = rect->right - rect->left;
  26911. h = rect->bottom - rect->top;
  26912. return true;
  26913. }
  26914. void mouseDown (int x, int y)
  26915. {
  26916. if (! alreadyInside)
  26917. {
  26918. alreadyInside = true;
  26919. getTopLevelComponent()->toFront (true);
  26920. owner->dispatch (effEditMouse, x, y, 0, 0);
  26921. alreadyInside = false;
  26922. }
  26923. else
  26924. {
  26925. PostEvent (::mouseDown, 0);
  26926. }
  26927. }
  26928. void paint()
  26929. {
  26930. ComponentPeer* const peer = getPeer();
  26931. if (peer != 0)
  26932. {
  26933. const Point<int> pos (getScreenPosition() - peer->getScreenPosition());
  26934. ERect r;
  26935. r.left = pos.getX();
  26936. r.right = r.left + getWidth();
  26937. r.top = pos.getY();
  26938. r.bottom = r.top + getHeight();
  26939. owner->dispatch (effEditDraw, 0, 0, &r, 0);
  26940. }
  26941. }
  26942. private:
  26943. VSTPluginWindow* const owner;
  26944. bool alreadyInside;
  26945. };
  26946. friend class InnerWrapperComponent;
  26947. ScopedPointer <InnerWrapperComponent> innerWrapper;
  26948. void resized()
  26949. {
  26950. innerWrapper->setSize (getWidth(), getHeight());
  26951. }
  26952. #endif
  26953. };
  26954. AudioProcessorEditor* VSTPluginInstance::createEditor()
  26955. {
  26956. if (hasEditor())
  26957. return new VSTPluginWindow (*this);
  26958. return 0;
  26959. }
  26960. void VSTPluginInstance::handleAsyncUpdate()
  26961. {
  26962. // indicates that something about the plugin has changed..
  26963. updateHostDisplay();
  26964. }
  26965. bool VSTPluginInstance::restoreProgramSettings (const fxProgram* const prog)
  26966. {
  26967. if (vst_swap (prog->chunkMagic) == 'CcnK' && vst_swap (prog->fxMagic) == 'FxCk')
  26968. {
  26969. changeProgramName (getCurrentProgram(), prog->prgName);
  26970. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  26971. setParameter (i, vst_swapFloat (prog->params[i]));
  26972. return true;
  26973. }
  26974. return false;
  26975. }
  26976. bool VSTPluginInstance::loadFromFXBFile (const void* const data,
  26977. const int dataSize)
  26978. {
  26979. if (dataSize < 28)
  26980. return false;
  26981. const fxSet* const set = (const fxSet*) data;
  26982. if ((vst_swap (set->chunkMagic) != 'CcnK' && vst_swap (set->chunkMagic) != 'KncC')
  26983. || vst_swap (set->version) > fxbVersionNum)
  26984. return false;
  26985. if (vst_swap (set->fxMagic) == 'FxBk')
  26986. {
  26987. // bank of programs
  26988. if (vst_swap (set->numPrograms) >= 0)
  26989. {
  26990. const int oldProg = getCurrentProgram();
  26991. const int numParams = vst_swap (((const fxProgram*) (set->programs))->numParams);
  26992. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  26993. for (int i = 0; i < vst_swap (set->numPrograms); ++i)
  26994. {
  26995. if (i != oldProg)
  26996. {
  26997. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + i * progLen);
  26998. if (((const char*) prog) - ((const char*) set) >= dataSize)
  26999. return false;
  27000. if (vst_swap (set->numPrograms) > 0)
  27001. setCurrentProgram (i);
  27002. if (! restoreProgramSettings (prog))
  27003. return false;
  27004. }
  27005. }
  27006. if (vst_swap (set->numPrograms) > 0)
  27007. setCurrentProgram (oldProg);
  27008. const fxProgram* const prog = (const fxProgram*) (((const char*) (set->programs)) + oldProg * progLen);
  27009. if (((const char*) prog) - ((const char*) set) >= dataSize)
  27010. return false;
  27011. if (! restoreProgramSettings (prog))
  27012. return false;
  27013. }
  27014. }
  27015. else if (vst_swap (set->fxMagic) == 'FxCk')
  27016. {
  27017. // single program
  27018. const fxProgram* const prog = (const fxProgram*) data;
  27019. if (vst_swap (prog->chunkMagic) != 'CcnK')
  27020. return false;
  27021. changeProgramName (getCurrentProgram(), prog->prgName);
  27022. for (int i = 0; i < vst_swap (prog->numParams); ++i)
  27023. setParameter (i, vst_swapFloat (prog->params[i]));
  27024. }
  27025. else if (vst_swap (set->fxMagic) == 'FBCh' || vst_swap (set->fxMagic) == 'hCBF')
  27026. {
  27027. // non-preset chunk
  27028. const fxChunkSet* const cset = (const fxChunkSet*) data;
  27029. if (vst_swap (cset->chunkSize) + sizeof (fxChunkSet) - 8 > (unsigned int) dataSize)
  27030. return false;
  27031. setChunkData (cset->chunk, vst_swap (cset->chunkSize), false);
  27032. }
  27033. else if (vst_swap (set->fxMagic) == 'FPCh' || vst_swap (set->fxMagic) == 'hCPF')
  27034. {
  27035. // preset chunk
  27036. const fxProgramSet* const cset = (const fxProgramSet*) data;
  27037. if (vst_swap (cset->chunkSize) + sizeof (fxProgramSet) - 8 > (unsigned int) dataSize)
  27038. return false;
  27039. setChunkData (cset->chunk, vst_swap (cset->chunkSize), true);
  27040. changeProgramName (getCurrentProgram(), cset->name);
  27041. }
  27042. else
  27043. {
  27044. return false;
  27045. }
  27046. return true;
  27047. }
  27048. void VSTPluginInstance::setParamsInProgramBlock (fxProgram* const prog) throw()
  27049. {
  27050. const int numParams = getNumParameters();
  27051. prog->chunkMagic = vst_swap ('CcnK');
  27052. prog->byteSize = 0;
  27053. prog->fxMagic = vst_swap ('FxCk');
  27054. prog->version = vst_swap (fxbVersionNum);
  27055. prog->fxID = vst_swap (getUID());
  27056. prog->fxVersion = vst_swap (getVersionNumber());
  27057. prog->numParams = vst_swap (numParams);
  27058. getCurrentProgramName().copyToCString (prog->prgName, sizeof (prog->prgName) - 1);
  27059. for (int i = 0; i < numParams; ++i)
  27060. prog->params[i] = vst_swapFloat (getParameter (i));
  27061. }
  27062. bool VSTPluginInstance::saveToFXBFile (MemoryBlock& dest, bool isFXB, int maxSizeMB)
  27063. {
  27064. const int numPrograms = getNumPrograms();
  27065. const int numParams = getNumParameters();
  27066. if (usesChunks())
  27067. {
  27068. if (isFXB)
  27069. {
  27070. MemoryBlock chunk;
  27071. getChunkData (chunk, false, maxSizeMB);
  27072. const size_t totalLen = sizeof (fxChunkSet) + chunk.getSize() - 8;
  27073. dest.setSize (totalLen, true);
  27074. fxChunkSet* const set = (fxChunkSet*) dest.getData();
  27075. set->chunkMagic = vst_swap ('CcnK');
  27076. set->byteSize = 0;
  27077. set->fxMagic = vst_swap ('FBCh');
  27078. set->version = vst_swap (fxbVersionNum);
  27079. set->fxID = vst_swap (getUID());
  27080. set->fxVersion = vst_swap (getVersionNumber());
  27081. set->numPrograms = vst_swap (numPrograms);
  27082. set->chunkSize = vst_swap ((long) chunk.getSize());
  27083. chunk.copyTo (set->chunk, 0, chunk.getSize());
  27084. }
  27085. else
  27086. {
  27087. MemoryBlock chunk;
  27088. getChunkData (chunk, true, maxSizeMB);
  27089. const size_t totalLen = sizeof (fxProgramSet) + chunk.getSize() - 8;
  27090. dest.setSize (totalLen, true);
  27091. fxProgramSet* const set = (fxProgramSet*) dest.getData();
  27092. set->chunkMagic = vst_swap ('CcnK');
  27093. set->byteSize = 0;
  27094. set->fxMagic = vst_swap ('FPCh');
  27095. set->version = vst_swap (fxbVersionNum);
  27096. set->fxID = vst_swap (getUID());
  27097. set->fxVersion = vst_swap (getVersionNumber());
  27098. set->numPrograms = vst_swap (numPrograms);
  27099. set->chunkSize = vst_swap ((long) chunk.getSize());
  27100. getCurrentProgramName().copyToCString (set->name, sizeof (set->name) - 1);
  27101. chunk.copyTo (set->chunk, 0, chunk.getSize());
  27102. }
  27103. }
  27104. else
  27105. {
  27106. if (isFXB)
  27107. {
  27108. const int progLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27109. const int len = (sizeof (fxSet) - sizeof (fxProgram)) + progLen * jmax (1, numPrograms);
  27110. dest.setSize (len, true);
  27111. fxSet* const set = (fxSet*) dest.getData();
  27112. set->chunkMagic = vst_swap ('CcnK');
  27113. set->byteSize = 0;
  27114. set->fxMagic = vst_swap ('FxBk');
  27115. set->version = vst_swap (fxbVersionNum);
  27116. set->fxID = vst_swap (getUID());
  27117. set->fxVersion = vst_swap (getVersionNumber());
  27118. set->numPrograms = vst_swap (numPrograms);
  27119. const int oldProgram = getCurrentProgram();
  27120. MemoryBlock oldSettings;
  27121. createTempParameterStore (oldSettings);
  27122. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + oldProgram * progLen));
  27123. for (int i = 0; i < numPrograms; ++i)
  27124. {
  27125. if (i != oldProgram)
  27126. {
  27127. setCurrentProgram (i);
  27128. setParamsInProgramBlock ((fxProgram*) (((char*) (set->programs)) + i * progLen));
  27129. }
  27130. }
  27131. setCurrentProgram (oldProgram);
  27132. restoreFromTempParameterStore (oldSettings);
  27133. }
  27134. else
  27135. {
  27136. const int totalLen = sizeof (fxProgram) + (numParams - 1) * sizeof (float);
  27137. dest.setSize (totalLen, true);
  27138. setParamsInProgramBlock ((fxProgram*) dest.getData());
  27139. }
  27140. }
  27141. return true;
  27142. }
  27143. void VSTPluginInstance::getChunkData (MemoryBlock& mb, bool isPreset, int maxSizeMB) const
  27144. {
  27145. if (usesChunks())
  27146. {
  27147. void* data = 0;
  27148. const int bytes = dispatch (effGetChunk, isPreset ? 1 : 0, 0, &data, 0.0f);
  27149. if (data != 0 && bytes <= maxSizeMB * 1024 * 1024)
  27150. {
  27151. mb.setSize (bytes);
  27152. mb.copyFrom (data, 0, bytes);
  27153. }
  27154. }
  27155. }
  27156. void VSTPluginInstance::setChunkData (const char* data, int size, bool isPreset)
  27157. {
  27158. if (size > 0 && usesChunks())
  27159. {
  27160. dispatch (effSetChunk, isPreset ? 1 : 0, size, (void*) data, 0.0f);
  27161. if (! isPreset)
  27162. updateStoredProgramNames();
  27163. }
  27164. }
  27165. void VSTPluginInstance::timerCallback()
  27166. {
  27167. if (dispatch (effIdle, 0, 0, 0, 0) == 0)
  27168. stopTimer();
  27169. }
  27170. int VSTPluginInstance::dispatch (const int opcode, const int index, const int value, void* const ptr, float opt) const
  27171. {
  27172. const ScopedLock sl (lock);
  27173. ++insideVSTCallback;
  27174. int result = 0;
  27175. try
  27176. {
  27177. if (effect != 0)
  27178. {
  27179. #if JUCE_MAC
  27180. if (module->resFileId != 0)
  27181. UseResFile (module->resFileId);
  27182. CGrafPtr oldPort;
  27183. if (getActiveEditor() != 0)
  27184. {
  27185. const Point<int> pos (getActiveEditor()->relativePositionToOtherComponent (getActiveEditor()->getTopLevelComponent(), Point<int>()));
  27186. GetPort (&oldPort);
  27187. SetPortWindowPort ((WindowRef) getActiveEditor()->getWindowHandle());
  27188. SetOrigin (-pos.getX(), -pos.getY());
  27189. }
  27190. #endif
  27191. result = effect->dispatcher (effect, opcode, index, value, ptr, opt);
  27192. #if JUCE_MAC
  27193. if (getActiveEditor() != 0)
  27194. SetPort (oldPort);
  27195. module->resFileId = CurResFile();
  27196. #endif
  27197. --insideVSTCallback;
  27198. return result;
  27199. }
  27200. }
  27201. catch (...)
  27202. {
  27203. }
  27204. --insideVSTCallback;
  27205. return result;
  27206. }
  27207. // handles non plugin-specific callbacks..
  27208. static const int defaultVSTSampleRateValue = 16384;
  27209. static const int defaultVSTBlockSizeValue = 512;
  27210. static VstIntPtr handleGeneralCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27211. {
  27212. (void) index;
  27213. (void) value;
  27214. (void) opt;
  27215. switch (opcode)
  27216. {
  27217. case audioMasterCanDo:
  27218. {
  27219. static const char* canDos[] = { "supplyIdle",
  27220. "sendVstEvents",
  27221. "sendVstMidiEvent",
  27222. "sendVstTimeInfo",
  27223. "receiveVstEvents",
  27224. "receiveVstMidiEvent",
  27225. "supportShell",
  27226. "shellCategory" };
  27227. for (int i = 0; i < numElementsInArray (canDos); ++i)
  27228. if (strcmp (canDos[i], (const char*) ptr) == 0)
  27229. return 1;
  27230. return 0;
  27231. }
  27232. case audioMasterVersion:
  27233. return 0x2400;
  27234. case audioMasterCurrentId:
  27235. return shellUIDToCreate;
  27236. case audioMasterGetNumAutomatableParameters:
  27237. return 0;
  27238. case audioMasterGetAutomationState:
  27239. return 1;
  27240. case audioMasterGetVendorVersion:
  27241. return 0x0101;
  27242. case audioMasterGetVendorString:
  27243. case audioMasterGetProductString:
  27244. {
  27245. String hostName ("Juce VST Host");
  27246. if (JUCEApplication::getInstance() != 0)
  27247. hostName = JUCEApplication::getInstance()->getApplicationName();
  27248. hostName.copyToCString ((char*) ptr, jmin (kVstMaxVendorStrLen, kVstMaxProductStrLen) - 1);
  27249. }
  27250. break;
  27251. case audioMasterGetSampleRate:
  27252. return (VstIntPtr) defaultVSTSampleRateValue;
  27253. case audioMasterGetBlockSize:
  27254. return (VstIntPtr) defaultVSTBlockSizeValue;
  27255. case audioMasterSetOutputSampleRate:
  27256. return 0;
  27257. default:
  27258. DBG ("*** Unhandled VST Callback: " + String ((int) opcode));
  27259. break;
  27260. }
  27261. return 0;
  27262. }
  27263. // handles callbacks for a specific plugin
  27264. VstIntPtr VSTPluginInstance::handleCallback (VstInt32 opcode, VstInt32 index, VstInt32 value, void *ptr, float opt)
  27265. {
  27266. switch (opcode)
  27267. {
  27268. case audioMasterAutomate:
  27269. sendParamChangeMessageToListeners (index, opt);
  27270. break;
  27271. case audioMasterProcessEvents:
  27272. handleMidiFromPlugin ((const VstEvents*) ptr);
  27273. break;
  27274. case audioMasterGetTime:
  27275. #ifdef _MSC_VER
  27276. #pragma warning (push)
  27277. #pragma warning (disable: 4311)
  27278. #endif
  27279. return (VstIntPtr) &vstHostTime;
  27280. #ifdef _MSC_VER
  27281. #pragma warning (pop)
  27282. #endif
  27283. break;
  27284. case audioMasterIdle:
  27285. if (insideVSTCallback == 0 && MessageManager::getInstance()->isThisTheMessageThread())
  27286. {
  27287. ++insideVSTCallback;
  27288. #if JUCE_MAC
  27289. if (getActiveEditor() != 0)
  27290. dispatch (effEditIdle, 0, 0, 0, 0);
  27291. #endif
  27292. juce_callAnyTimersSynchronously();
  27293. handleUpdateNowIfNeeded();
  27294. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  27295. ComponentPeer::getPeer (i)->performAnyPendingRepaintsNow();
  27296. --insideVSTCallback;
  27297. }
  27298. break;
  27299. case audioMasterUpdateDisplay:
  27300. triggerAsyncUpdate();
  27301. break;
  27302. case audioMasterTempoAt:
  27303. // returns (10000 * bpm)
  27304. break;
  27305. case audioMasterNeedIdle:
  27306. startTimer (50);
  27307. break;
  27308. case audioMasterSizeWindow:
  27309. if (getActiveEditor() != 0)
  27310. getActiveEditor()->setSize (index, value);
  27311. return 1;
  27312. case audioMasterGetSampleRate:
  27313. return (VstIntPtr) (getSampleRate() > 0 ? getSampleRate() : defaultVSTSampleRateValue);
  27314. case audioMasterGetBlockSize:
  27315. return (VstIntPtr) (getBlockSize() > 0 ? getBlockSize() : defaultVSTBlockSizeValue);
  27316. case audioMasterWantMidi:
  27317. wantsMidiMessages = true;
  27318. break;
  27319. case audioMasterGetDirectory:
  27320. #if JUCE_MAC
  27321. return (VstIntPtr) (void*) &module->parentDirFSSpec;
  27322. #else
  27323. return (VstIntPtr) (pointer_sized_uint) module->fullParentDirectoryPathName.toUTF8();
  27324. #endif
  27325. case audioMasterGetAutomationState:
  27326. // returns 0: not supported, 1: off, 2:read, 3:write, 4:read/write
  27327. break;
  27328. // none of these are handled (yet)..
  27329. case audioMasterBeginEdit:
  27330. case audioMasterEndEdit:
  27331. case audioMasterSetTime:
  27332. case audioMasterPinConnected:
  27333. case audioMasterGetParameterQuantization:
  27334. case audioMasterIOChanged:
  27335. case audioMasterGetInputLatency:
  27336. case audioMasterGetOutputLatency:
  27337. case audioMasterGetPreviousPlug:
  27338. case audioMasterGetNextPlug:
  27339. case audioMasterWillReplaceOrAccumulate:
  27340. case audioMasterGetCurrentProcessLevel:
  27341. case audioMasterOfflineStart:
  27342. case audioMasterOfflineRead:
  27343. case audioMasterOfflineWrite:
  27344. case audioMasterOfflineGetCurrentPass:
  27345. case audioMasterOfflineGetCurrentMetaPass:
  27346. case audioMasterVendorSpecific:
  27347. case audioMasterSetIcon:
  27348. case audioMasterGetLanguage:
  27349. case audioMasterOpenWindow:
  27350. case audioMasterCloseWindow:
  27351. break;
  27352. default:
  27353. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27354. }
  27355. return 0;
  27356. }
  27357. // entry point for all callbacks from the plugin
  27358. static VstIntPtr VSTCALLBACK audioMaster (AEffect* effect, VstInt32 opcode, VstInt32 index, VstIntPtr value, void* ptr, float opt)
  27359. {
  27360. try
  27361. {
  27362. if (effect != 0 && effect->resvd2 != 0)
  27363. {
  27364. return ((VSTPluginInstance*)(effect->resvd2))
  27365. ->handleCallback (opcode, index, value, ptr, opt);
  27366. }
  27367. return handleGeneralCallback (opcode, index, value, ptr, opt);
  27368. }
  27369. catch (...)
  27370. {
  27371. return 0;
  27372. }
  27373. }
  27374. const String VSTPluginInstance::getVersion() const throw()
  27375. {
  27376. unsigned int v = dispatch (effGetVendorVersion, 0, 0, 0, 0);
  27377. String s;
  27378. if (v == 0 || v == -1)
  27379. v = getVersionNumber();
  27380. if (v != 0)
  27381. {
  27382. int versionBits[4];
  27383. int n = 0;
  27384. while (v != 0)
  27385. {
  27386. versionBits [n++] = (v & 0xff);
  27387. v >>= 8;
  27388. }
  27389. s << 'V';
  27390. while (n > 0)
  27391. {
  27392. s << versionBits [--n];
  27393. if (n > 0)
  27394. s << '.';
  27395. }
  27396. }
  27397. return s;
  27398. }
  27399. int VSTPluginInstance::getUID() const throw()
  27400. {
  27401. int uid = effect != 0 ? effect->uniqueID : 0;
  27402. if (uid == 0)
  27403. uid = module->file.hashCode();
  27404. return uid;
  27405. }
  27406. const String VSTPluginInstance::getCategory() const throw()
  27407. {
  27408. const char* result = 0;
  27409. switch (dispatch (effGetPlugCategory, 0, 0, 0, 0))
  27410. {
  27411. case kPlugCategEffect:
  27412. result = "Effect";
  27413. break;
  27414. case kPlugCategSynth:
  27415. result = "Synth";
  27416. break;
  27417. case kPlugCategAnalysis:
  27418. result = "Anaylsis";
  27419. break;
  27420. case kPlugCategMastering:
  27421. result = "Mastering";
  27422. break;
  27423. case kPlugCategSpacializer:
  27424. result = "Spacial";
  27425. break;
  27426. case kPlugCategRoomFx:
  27427. result = "Reverb";
  27428. break;
  27429. case kPlugSurroundFx:
  27430. result = "Surround";
  27431. break;
  27432. case kPlugCategRestoration:
  27433. result = "Restoration";
  27434. break;
  27435. case kPlugCategGenerator:
  27436. result = "Tone generation";
  27437. break;
  27438. default:
  27439. break;
  27440. }
  27441. return result;
  27442. }
  27443. float VSTPluginInstance::getParameter (int index)
  27444. {
  27445. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27446. {
  27447. try
  27448. {
  27449. const ScopedLock sl (lock);
  27450. return effect->getParameter (effect, index);
  27451. }
  27452. catch (...)
  27453. {
  27454. }
  27455. }
  27456. return 0.0f;
  27457. }
  27458. void VSTPluginInstance::setParameter (int index, float newValue)
  27459. {
  27460. if (effect != 0 && ((unsigned int) index) < (unsigned int) effect->numParams)
  27461. {
  27462. try
  27463. {
  27464. const ScopedLock sl (lock);
  27465. if (effect->getParameter (effect, index) != newValue)
  27466. effect->setParameter (effect, index, newValue);
  27467. }
  27468. catch (...)
  27469. {
  27470. }
  27471. }
  27472. }
  27473. const String VSTPluginInstance::getParameterName (int index)
  27474. {
  27475. if (effect != 0)
  27476. {
  27477. jassert (index >= 0 && index < effect->numParams);
  27478. char nm [256];
  27479. zerostruct (nm);
  27480. dispatch (effGetParamName, index, 0, nm, 0);
  27481. return String (nm).trim();
  27482. }
  27483. return String::empty;
  27484. }
  27485. const String VSTPluginInstance::getParameterLabel (int index) const
  27486. {
  27487. if (effect != 0)
  27488. {
  27489. jassert (index >= 0 && index < effect->numParams);
  27490. char nm [256];
  27491. zerostruct (nm);
  27492. dispatch (effGetParamLabel, index, 0, nm, 0);
  27493. return String (nm).trim();
  27494. }
  27495. return String::empty;
  27496. }
  27497. const String VSTPluginInstance::getParameterText (int index)
  27498. {
  27499. if (effect != 0)
  27500. {
  27501. jassert (index >= 0 && index < effect->numParams);
  27502. char nm [256];
  27503. zerostruct (nm);
  27504. dispatch (effGetParamDisplay, index, 0, nm, 0);
  27505. return String (nm).trim();
  27506. }
  27507. return String::empty;
  27508. }
  27509. bool VSTPluginInstance::isParameterAutomatable (int index) const
  27510. {
  27511. if (effect != 0)
  27512. {
  27513. jassert (index >= 0 && index < effect->numParams);
  27514. return dispatch (effCanBeAutomated, index, 0, 0, 0) != 0;
  27515. }
  27516. return false;
  27517. }
  27518. void VSTPluginInstance::createTempParameterStore (MemoryBlock& dest)
  27519. {
  27520. dest.setSize (64 + 4 * getNumParameters());
  27521. dest.fillWith (0);
  27522. getCurrentProgramName().copyToCString ((char*) dest.getData(), 63);
  27523. float* const p = (float*) (((char*) dest.getData()) + 64);
  27524. for (int i = 0; i < getNumParameters(); ++i)
  27525. p[i] = getParameter(i);
  27526. }
  27527. void VSTPluginInstance::restoreFromTempParameterStore (const MemoryBlock& m)
  27528. {
  27529. changeProgramName (getCurrentProgram(), (const char*) m.getData());
  27530. float* p = (float*) (((char*) m.getData()) + 64);
  27531. for (int i = 0; i < getNumParameters(); ++i)
  27532. setParameter (i, p[i]);
  27533. }
  27534. void VSTPluginInstance::setCurrentProgram (int newIndex)
  27535. {
  27536. if (getNumPrograms() > 0 && newIndex != getCurrentProgram())
  27537. dispatch (effSetProgram, 0, jlimit (0, getNumPrograms() - 1, newIndex), 0, 0);
  27538. }
  27539. const String VSTPluginInstance::getProgramName (int index)
  27540. {
  27541. if (index == getCurrentProgram())
  27542. {
  27543. return getCurrentProgramName();
  27544. }
  27545. else if (effect != 0)
  27546. {
  27547. char nm [256];
  27548. zerostruct (nm);
  27549. if (dispatch (effGetProgramNameIndexed,
  27550. jlimit (0, getNumPrograms(), index),
  27551. -1, nm, 0) != 0)
  27552. {
  27553. return String (nm).trim();
  27554. }
  27555. }
  27556. return programNames [index];
  27557. }
  27558. void VSTPluginInstance::changeProgramName (int index, const String& newName)
  27559. {
  27560. if (index == getCurrentProgram())
  27561. {
  27562. if (getNumPrograms() > 0 && newName != getCurrentProgramName())
  27563. dispatch (effSetProgramName, 0, 0, (void*) newName.substring (0, 24).toCString(), 0.0f);
  27564. }
  27565. else
  27566. {
  27567. jassertfalse // xxx not implemented!
  27568. }
  27569. }
  27570. void VSTPluginInstance::updateStoredProgramNames()
  27571. {
  27572. if (effect != 0 && getNumPrograms() > 0)
  27573. {
  27574. char nm [256];
  27575. zerostruct (nm);
  27576. // only do this if the plugin can't use indexed names..
  27577. if (dispatch (effGetProgramNameIndexed, 0, -1, nm, 0) == 0)
  27578. {
  27579. const int oldProgram = getCurrentProgram();
  27580. MemoryBlock oldSettings;
  27581. createTempParameterStore (oldSettings);
  27582. for (int i = 0; i < getNumPrograms(); ++i)
  27583. {
  27584. setCurrentProgram (i);
  27585. getCurrentProgramName(); // (this updates the list)
  27586. }
  27587. setCurrentProgram (oldProgram);
  27588. restoreFromTempParameterStore (oldSettings);
  27589. }
  27590. }
  27591. }
  27592. const String VSTPluginInstance::getCurrentProgramName()
  27593. {
  27594. if (effect != 0)
  27595. {
  27596. char nm [256];
  27597. zerostruct (nm);
  27598. dispatch (effGetProgramName, 0, 0, nm, 0);
  27599. const int index = getCurrentProgram();
  27600. if (programNames[index].isEmpty())
  27601. {
  27602. while (programNames.size() < index)
  27603. programNames.add (String::empty);
  27604. programNames.set (index, String (nm).trim());
  27605. }
  27606. return String (nm).trim();
  27607. }
  27608. return String::empty;
  27609. }
  27610. const String VSTPluginInstance::getInputChannelName (const int index) const
  27611. {
  27612. if (index >= 0 && index < getNumInputChannels())
  27613. {
  27614. VstPinProperties pinProps;
  27615. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27616. return String (pinProps.label, sizeof (pinProps.label));
  27617. }
  27618. return String::empty;
  27619. }
  27620. bool VSTPluginInstance::isInputChannelStereoPair (int index) const
  27621. {
  27622. if (index < 0 || index >= getNumInputChannels())
  27623. return false;
  27624. VstPinProperties pinProps;
  27625. if (dispatch (effGetInputProperties, index, 0, &pinProps, 0.0f) != 0)
  27626. return (pinProps.flags & kVstPinIsStereo) != 0;
  27627. return true;
  27628. }
  27629. const String VSTPluginInstance::getOutputChannelName (const int index) const
  27630. {
  27631. if (index >= 0 && index < getNumOutputChannels())
  27632. {
  27633. VstPinProperties pinProps;
  27634. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27635. return String (pinProps.label, sizeof (pinProps.label));
  27636. }
  27637. return String::empty;
  27638. }
  27639. bool VSTPluginInstance::isOutputChannelStereoPair (int index) const
  27640. {
  27641. if (index < 0 || index >= getNumOutputChannels())
  27642. return false;
  27643. VstPinProperties pinProps;
  27644. if (dispatch (effGetOutputProperties, index, 0, &pinProps, 0.0f) != 0)
  27645. return (pinProps.flags & kVstPinIsStereo) != 0;
  27646. return true;
  27647. }
  27648. void VSTPluginInstance::setPower (const bool on)
  27649. {
  27650. dispatch (effMainsChanged, 0, on ? 1 : 0, 0, 0);
  27651. isPowerOn = on;
  27652. }
  27653. const int defaultMaxSizeMB = 64;
  27654. void VSTPluginInstance::getStateInformation (MemoryBlock& destData)
  27655. {
  27656. saveToFXBFile (destData, true, defaultMaxSizeMB);
  27657. }
  27658. void VSTPluginInstance::getCurrentProgramStateInformation (MemoryBlock& destData)
  27659. {
  27660. saveToFXBFile (destData, false, defaultMaxSizeMB);
  27661. }
  27662. void VSTPluginInstance::setStateInformation (const void* data, int sizeInBytes)
  27663. {
  27664. loadFromFXBFile (data, sizeInBytes);
  27665. }
  27666. void VSTPluginInstance::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  27667. {
  27668. loadFromFXBFile (data, sizeInBytes);
  27669. }
  27670. VSTPluginFormat::VSTPluginFormat()
  27671. {
  27672. }
  27673. VSTPluginFormat::~VSTPluginFormat()
  27674. {
  27675. }
  27676. void VSTPluginFormat::findAllTypesForFile (OwnedArray <PluginDescription>& results,
  27677. const String& fileOrIdentifier)
  27678. {
  27679. if (! fileMightContainThisPluginType (fileOrIdentifier))
  27680. return;
  27681. PluginDescription desc;
  27682. desc.fileOrIdentifier = fileOrIdentifier;
  27683. desc.uid = 0;
  27684. ScopedPointer <VSTPluginInstance> instance (dynamic_cast <VSTPluginInstance*> (createInstanceFromDescription (desc)));
  27685. if (instance == 0)
  27686. return;
  27687. try
  27688. {
  27689. #if JUCE_MAC
  27690. if (instance->module->resFileId != 0)
  27691. UseResFile (instance->module->resFileId);
  27692. #endif
  27693. instance->fillInPluginDescription (desc);
  27694. VstPlugCategory category = (VstPlugCategory) instance->dispatch (effGetPlugCategory, 0, 0, 0, 0);
  27695. if (category != kPlugCategShell)
  27696. {
  27697. // Normal plugin...
  27698. results.add (new PluginDescription (desc));
  27699. ++insideVSTCallback;
  27700. instance->dispatch (effOpen, 0, 0, 0, 0);
  27701. --insideVSTCallback;
  27702. }
  27703. else
  27704. {
  27705. // It's a shell plugin, so iterate all the subtypes...
  27706. char shellEffectName [64];
  27707. for (;;)
  27708. {
  27709. zerostruct (shellEffectName);
  27710. const int uid = instance->dispatch (effShellGetNextPlugin, 0, 0, shellEffectName, 0);
  27711. if (uid == 0)
  27712. {
  27713. break;
  27714. }
  27715. else
  27716. {
  27717. desc.uid = uid;
  27718. desc.name = shellEffectName;
  27719. bool alreadyThere = false;
  27720. for (int i = results.size(); --i >= 0;)
  27721. {
  27722. PluginDescription* const d = results.getUnchecked(i);
  27723. if (d->isDuplicateOf (desc))
  27724. {
  27725. alreadyThere = true;
  27726. break;
  27727. }
  27728. }
  27729. if (! alreadyThere)
  27730. results.add (new PluginDescription (desc));
  27731. }
  27732. }
  27733. }
  27734. }
  27735. catch (...)
  27736. {
  27737. // crashed while loading...
  27738. }
  27739. }
  27740. AudioPluginInstance* VSTPluginFormat::createInstanceFromDescription (const PluginDescription& desc)
  27741. {
  27742. ScopedPointer <VSTPluginInstance> result;
  27743. if (fileMightContainThisPluginType (desc.fileOrIdentifier))
  27744. {
  27745. File file (desc.fileOrIdentifier);
  27746. const File previousWorkingDirectory (File::getCurrentWorkingDirectory());
  27747. file.getParentDirectory().setAsCurrentWorkingDirectory();
  27748. const ReferenceCountedObjectPtr <ModuleHandle> module (ModuleHandle::findOrCreateModule (file));
  27749. if (module != 0)
  27750. {
  27751. shellUIDToCreate = desc.uid;
  27752. result = new VSTPluginInstance (module);
  27753. if (result->effect != 0)
  27754. {
  27755. result->effect->resvd2 = (VstIntPtr) (pointer_sized_int) (VSTPluginInstance*) result;
  27756. result->initialise();
  27757. }
  27758. else
  27759. {
  27760. result = 0;
  27761. }
  27762. }
  27763. previousWorkingDirectory.setAsCurrentWorkingDirectory();
  27764. }
  27765. return result.release();
  27766. }
  27767. bool VSTPluginFormat::fileMightContainThisPluginType (const String& fileOrIdentifier)
  27768. {
  27769. const File f (fileOrIdentifier);
  27770. #if JUCE_MAC
  27771. if (f.isDirectory() && f.hasFileExtension (T(".vst")))
  27772. return true;
  27773. #if JUCE_PPC
  27774. FSRef fileRef;
  27775. if (PlatformUtilities::makeFSRefFromPath (&fileRef, f.getFullPathName()))
  27776. {
  27777. const short resFileId = FSOpenResFile (&fileRef, fsRdPerm);
  27778. if (resFileId != -1)
  27779. {
  27780. const int numEffects = Count1Resources ('aEff');
  27781. CloseResFile (resFileId);
  27782. if (numEffects > 0)
  27783. return true;
  27784. }
  27785. }
  27786. #endif
  27787. return false;
  27788. #elif JUCE_WIN32
  27789. return f.existsAsFile()
  27790. && f.hasFileExtension (T(".dll"));
  27791. #elif JUCE_LINUX
  27792. return f.existsAsFile()
  27793. && f.hasFileExtension (T(".so"));
  27794. #endif
  27795. }
  27796. const String VSTPluginFormat::getNameOfPluginFromIdentifier (const String& fileOrIdentifier)
  27797. {
  27798. return fileOrIdentifier;
  27799. }
  27800. bool VSTPluginFormat::doesPluginStillExist (const PluginDescription& desc)
  27801. {
  27802. return File (desc.fileOrIdentifier).exists();
  27803. }
  27804. const StringArray VSTPluginFormat::searchPathsForPlugins (const FileSearchPath& directoriesToSearch, const bool recursive)
  27805. {
  27806. StringArray results;
  27807. for (int j = 0; j < directoriesToSearch.getNumPaths(); ++j)
  27808. recursiveFileSearch (results, directoriesToSearch [j], recursive);
  27809. return results;
  27810. }
  27811. void VSTPluginFormat::recursiveFileSearch (StringArray& results, const File& dir, const bool recursive)
  27812. {
  27813. // avoid allowing the dir iterator to be recursive, because we want to avoid letting it delve inside
  27814. // .component or .vst directories.
  27815. DirectoryIterator iter (dir, false, "*", File::findFilesAndDirectories);
  27816. while (iter.next())
  27817. {
  27818. const File f (iter.getFile());
  27819. bool isPlugin = false;
  27820. if (fileMightContainThisPluginType (f.getFullPathName()))
  27821. {
  27822. isPlugin = true;
  27823. results.add (f.getFullPathName());
  27824. }
  27825. if (recursive && (! isPlugin) && f.isDirectory())
  27826. recursiveFileSearch (results, f, true);
  27827. }
  27828. }
  27829. const FileSearchPath VSTPluginFormat::getDefaultLocationsToSearch()
  27830. {
  27831. #if JUCE_MAC
  27832. return FileSearchPath ("~/Library/Audio/Plug-Ins/VST;/Library/Audio/Plug-Ins/VST");
  27833. #elif JUCE_WIN32
  27834. const String programFiles (File::getSpecialLocation (File::globalApplicationsDirectory).getFullPathName());
  27835. return FileSearchPath (programFiles + "\\Steinberg\\VstPlugins");
  27836. #elif JUCE_LINUX
  27837. return FileSearchPath ("/usr/lib/vst");
  27838. #endif
  27839. }
  27840. END_JUCE_NAMESPACE
  27841. #endif
  27842. #undef log
  27843. #endif
  27844. /*** End of inlined file: juce_VSTPluginFormat.cpp ***/
  27845. /*** End of inlined file: juce_VSTPluginFormat.mm ***/
  27846. /*** Start of inlined file: juce_AudioProcessor.cpp ***/
  27847. BEGIN_JUCE_NAMESPACE
  27848. AudioProcessor::AudioProcessor()
  27849. : playHead (0),
  27850. activeEditor (0),
  27851. sampleRate (0),
  27852. blockSize (0),
  27853. numInputChannels (0),
  27854. numOutputChannels (0),
  27855. latencySamples (0),
  27856. suspended (false),
  27857. nonRealtime (false)
  27858. {
  27859. }
  27860. AudioProcessor::~AudioProcessor()
  27861. {
  27862. // ooh, nasty - the editor should have been deleted before the filter
  27863. // that it refers to is deleted..
  27864. jassert (activeEditor == 0);
  27865. #ifdef JUCE_DEBUG
  27866. // This will fail if you've called beginParameterChangeGesture() for one
  27867. // or more parameters without having made a corresponding call to endParameterChangeGesture...
  27868. jassert (changingParams.countNumberOfSetBits() == 0);
  27869. #endif
  27870. }
  27871. void AudioProcessor::setPlayHead (AudioPlayHead* const newPlayHead) throw()
  27872. {
  27873. playHead = newPlayHead;
  27874. }
  27875. void AudioProcessor::addListener (AudioProcessorListener* const newListener) throw()
  27876. {
  27877. const ScopedLock sl (listenerLock);
  27878. listeners.addIfNotAlreadyThere (newListener);
  27879. }
  27880. void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRemove) throw()
  27881. {
  27882. const ScopedLock sl (listenerLock);
  27883. listeners.removeValue (listenerToRemove);
  27884. }
  27885. void AudioProcessor::setPlayConfigDetails (const int numIns,
  27886. const int numOuts,
  27887. const double sampleRate_,
  27888. const int blockSize_) throw()
  27889. {
  27890. numInputChannels = numIns;
  27891. numOutputChannels = numOuts;
  27892. sampleRate = sampleRate_;
  27893. blockSize = blockSize_;
  27894. }
  27895. void AudioProcessor::setNonRealtime (const bool nonRealtime_) throw()
  27896. {
  27897. nonRealtime = nonRealtime_;
  27898. }
  27899. void AudioProcessor::setLatencySamples (const int newLatency)
  27900. {
  27901. if (latencySamples != newLatency)
  27902. {
  27903. latencySamples = newLatency;
  27904. updateHostDisplay();
  27905. }
  27906. }
  27907. void AudioProcessor::setParameterNotifyingHost (const int parameterIndex,
  27908. const float newValue)
  27909. {
  27910. setParameter (parameterIndex, newValue);
  27911. sendParamChangeMessageToListeners (parameterIndex, newValue);
  27912. }
  27913. void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
  27914. {
  27915. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27916. for (int i = listeners.size(); --i >= 0;)
  27917. {
  27918. AudioProcessorListener* l;
  27919. {
  27920. const ScopedLock sl (listenerLock);
  27921. l = (AudioProcessorListener*) listeners [i];
  27922. }
  27923. if (l != 0)
  27924. l->audioProcessorParameterChanged (this, parameterIndex, newValue);
  27925. }
  27926. }
  27927. void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
  27928. {
  27929. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27930. #ifdef JUCE_DEBUG
  27931. // This means you've called beginParameterChangeGesture twice in succession without a matching
  27932. // call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
  27933. jassert (! changingParams [parameterIndex]);
  27934. changingParams.setBit (parameterIndex);
  27935. #endif
  27936. for (int i = listeners.size(); --i >= 0;)
  27937. {
  27938. AudioProcessorListener* l;
  27939. {
  27940. const ScopedLock sl (listenerLock);
  27941. l = (AudioProcessorListener*) listeners [i];
  27942. }
  27943. if (l != 0)
  27944. l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
  27945. }
  27946. }
  27947. void AudioProcessor::endParameterChangeGesture (int parameterIndex)
  27948. {
  27949. jassert (((unsigned int) parameterIndex) < (unsigned int) getNumParameters());
  27950. #ifdef JUCE_DEBUG
  27951. // This means you've called endParameterChangeGesture without having previously called
  27952. // endParameterChangeGesture. That might be fine in most hosts, but better to keep the
  27953. // calls matched correctly.
  27954. jassert (changingParams [parameterIndex]);
  27955. changingParams.clearBit (parameterIndex);
  27956. #endif
  27957. for (int i = listeners.size(); --i >= 0;)
  27958. {
  27959. AudioProcessorListener* l;
  27960. {
  27961. const ScopedLock sl (listenerLock);
  27962. l = (AudioProcessorListener*) listeners [i];
  27963. }
  27964. if (l != 0)
  27965. l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
  27966. }
  27967. }
  27968. void AudioProcessor::updateHostDisplay()
  27969. {
  27970. for (int i = listeners.size(); --i >= 0;)
  27971. {
  27972. AudioProcessorListener* l;
  27973. {
  27974. const ScopedLock sl (listenerLock);
  27975. l = (AudioProcessorListener*) listeners [i];
  27976. }
  27977. if (l != 0)
  27978. l->audioProcessorChanged (this);
  27979. }
  27980. }
  27981. bool AudioProcessor::isParameterAutomatable (int /*parameterIndex*/) const
  27982. {
  27983. return true;
  27984. }
  27985. bool AudioProcessor::isMetaParameter (int /*parameterIndex*/) const
  27986. {
  27987. return false;
  27988. }
  27989. void AudioProcessor::suspendProcessing (const bool shouldBeSuspended)
  27990. {
  27991. const ScopedLock sl (callbackLock);
  27992. suspended = shouldBeSuspended;
  27993. }
  27994. void AudioProcessor::reset()
  27995. {
  27996. }
  27997. void AudioProcessor::editorBeingDeleted (AudioProcessorEditor* const editor) throw()
  27998. {
  27999. const ScopedLock sl (callbackLock);
  28000. jassert (activeEditor == editor);
  28001. if (activeEditor == editor)
  28002. activeEditor = 0;
  28003. }
  28004. AudioProcessorEditor* AudioProcessor::createEditorIfNeeded()
  28005. {
  28006. if (activeEditor != 0)
  28007. return activeEditor;
  28008. AudioProcessorEditor* const ed = createEditor();
  28009. if (ed != 0)
  28010. {
  28011. // you must give your editor comp a size before returning it..
  28012. jassert (ed->getWidth() > 0 && ed->getHeight() > 0);
  28013. const ScopedLock sl (callbackLock);
  28014. activeEditor = ed;
  28015. }
  28016. return ed;
  28017. }
  28018. void AudioProcessor::getCurrentProgramStateInformation (JUCE_NAMESPACE::MemoryBlock& destData)
  28019. {
  28020. getStateInformation (destData);
  28021. }
  28022. void AudioProcessor::setCurrentProgramStateInformation (const void* data, int sizeInBytes)
  28023. {
  28024. setStateInformation (data, sizeInBytes);
  28025. }
  28026. // magic number to identify memory blocks that we've stored as XML
  28027. const uint32 magicXmlNumber = 0x21324356;
  28028. void AudioProcessor::copyXmlToBinary (const XmlElement& xml,
  28029. JUCE_NAMESPACE::MemoryBlock& destData)
  28030. {
  28031. const String xmlString (xml.createDocument (String::empty, true, false));
  28032. const int stringLength = xmlString.getNumBytesAsUTF8();
  28033. destData.setSize (stringLength + 10);
  28034. char* const d = (char*) destData.getData();
  28035. *(uint32*) d = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
  28036. *(uint32*) (d + 4) = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
  28037. xmlString.copyToUTF8 (d + 8, stringLength + 1);
  28038. }
  28039. XmlElement* AudioProcessor::getXmlFromBinary (const void* data,
  28040. const int sizeInBytes)
  28041. {
  28042. if (sizeInBytes > 8
  28043. && ByteOrder::littleEndianInt ((const char*) data) == magicXmlNumber)
  28044. {
  28045. const int stringLength = (int) ByteOrder::littleEndianInt (((const char*) data) + 4);
  28046. if (stringLength > 0)
  28047. {
  28048. XmlDocument doc (String::fromUTF8 (((const char*) data) + 8,
  28049. jmin ((sizeInBytes - 8), stringLength)));
  28050. return doc.getDocumentElement();
  28051. }
  28052. }
  28053. return 0;
  28054. }
  28055. void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int)
  28056. {
  28057. }
  28058. void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int)
  28059. {
  28060. }
  28061. END_JUCE_NAMESPACE
  28062. /*** End of inlined file: juce_AudioProcessor.cpp ***/
  28063. /*** Start of inlined file: juce_AudioProcessorEditor.cpp ***/
  28064. BEGIN_JUCE_NAMESPACE
  28065. AudioProcessorEditor::AudioProcessorEditor (AudioProcessor* const owner_)
  28066. : owner (owner_)
  28067. {
  28068. // the filter must be valid..
  28069. jassert (owner != 0);
  28070. }
  28071. AudioProcessorEditor::~AudioProcessorEditor()
  28072. {
  28073. // if this fails, then the wrapper hasn't called editorBeingDeleted() on the
  28074. // filter for some reason..
  28075. jassert (owner->getActiveEditor() != this);
  28076. }
  28077. END_JUCE_NAMESPACE
  28078. /*** End of inlined file: juce_AudioProcessorEditor.cpp ***/
  28079. /*** Start of inlined file: juce_AudioProcessorGraph.cpp ***/
  28080. BEGIN_JUCE_NAMESPACE
  28081. const int AudioProcessorGraph::midiChannelIndex = 0x1000;
  28082. AudioProcessorGraph::Node::Node (const uint32 id_, AudioProcessor* const processor_)
  28083. : id (id_),
  28084. processor (processor_),
  28085. isPrepared (false)
  28086. {
  28087. jassert (processor_ != 0);
  28088. }
  28089. AudioProcessorGraph::Node::~Node()
  28090. {
  28091. delete processor;
  28092. }
  28093. void AudioProcessorGraph::Node::prepare (const double sampleRate, const int blockSize,
  28094. AudioProcessorGraph* const graph)
  28095. {
  28096. if (! isPrepared)
  28097. {
  28098. isPrepared = true;
  28099. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28100. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (processor);
  28101. if (ioProc != 0)
  28102. ioProc->setParentGraph (graph);
  28103. processor->setPlayConfigDetails (processor->getNumInputChannels(),
  28104. processor->getNumOutputChannels(),
  28105. sampleRate, blockSize);
  28106. processor->prepareToPlay (sampleRate, blockSize);
  28107. }
  28108. }
  28109. void AudioProcessorGraph::Node::unprepare()
  28110. {
  28111. if (isPrepared)
  28112. {
  28113. isPrepared = false;
  28114. processor->releaseResources();
  28115. }
  28116. }
  28117. AudioProcessorGraph::AudioProcessorGraph()
  28118. : lastNodeId (0),
  28119. renderingBuffers (1, 1),
  28120. currentAudioOutputBuffer (1, 1)
  28121. {
  28122. }
  28123. AudioProcessorGraph::~AudioProcessorGraph()
  28124. {
  28125. clearRenderingSequence();
  28126. clear();
  28127. }
  28128. const String AudioProcessorGraph::getName() const
  28129. {
  28130. return "Audio Graph";
  28131. }
  28132. void AudioProcessorGraph::clear()
  28133. {
  28134. nodes.clear();
  28135. connections.clear();
  28136. triggerAsyncUpdate();
  28137. }
  28138. AudioProcessorGraph::Node* AudioProcessorGraph::getNodeForId (const uint32 nodeId) const
  28139. {
  28140. for (int i = nodes.size(); --i >= 0;)
  28141. if (nodes.getUnchecked(i)->id == nodeId)
  28142. return nodes.getUnchecked(i);
  28143. return 0;
  28144. }
  28145. AudioProcessorGraph::Node* AudioProcessorGraph::addNode (AudioProcessor* const newProcessor,
  28146. uint32 nodeId)
  28147. {
  28148. if (newProcessor == 0)
  28149. {
  28150. jassertfalse
  28151. return 0;
  28152. }
  28153. if (nodeId == 0)
  28154. {
  28155. nodeId = ++lastNodeId;
  28156. }
  28157. else
  28158. {
  28159. // you can't add a node with an id that already exists in the graph..
  28160. jassert (getNodeForId (nodeId) == 0);
  28161. removeNode (nodeId);
  28162. }
  28163. lastNodeId = nodeId;
  28164. Node* const n = new Node (nodeId, newProcessor);
  28165. nodes.add (n);
  28166. triggerAsyncUpdate();
  28167. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28168. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (n->processor);
  28169. if (ioProc != 0)
  28170. ioProc->setParentGraph (this);
  28171. return n;
  28172. }
  28173. bool AudioProcessorGraph::removeNode (const uint32 nodeId)
  28174. {
  28175. disconnectNode (nodeId);
  28176. for (int i = nodes.size(); --i >= 0;)
  28177. {
  28178. if (nodes.getUnchecked(i)->id == nodeId)
  28179. {
  28180. AudioProcessorGraph::AudioGraphIOProcessor* const ioProc
  28181. = dynamic_cast <AudioProcessorGraph::AudioGraphIOProcessor*> (nodes.getUnchecked(i)->processor);
  28182. if (ioProc != 0)
  28183. ioProc->setParentGraph (0);
  28184. nodes.remove (i);
  28185. triggerAsyncUpdate();
  28186. return true;
  28187. }
  28188. }
  28189. return false;
  28190. }
  28191. const AudioProcessorGraph::Connection* AudioProcessorGraph::getConnectionBetween (const uint32 sourceNodeId,
  28192. const int sourceChannelIndex,
  28193. const uint32 destNodeId,
  28194. const int destChannelIndex) const
  28195. {
  28196. for (int i = connections.size(); --i >= 0;)
  28197. {
  28198. const Connection* const c = connections.getUnchecked(i);
  28199. if (c->sourceNodeId == sourceNodeId
  28200. && c->destNodeId == destNodeId
  28201. && c->sourceChannelIndex == sourceChannelIndex
  28202. && c->destChannelIndex == destChannelIndex)
  28203. {
  28204. return c;
  28205. }
  28206. }
  28207. return 0;
  28208. }
  28209. bool AudioProcessorGraph::isConnected (const uint32 possibleSourceNodeId,
  28210. const uint32 possibleDestNodeId) const
  28211. {
  28212. for (int i = connections.size(); --i >= 0;)
  28213. {
  28214. const Connection* const c = connections.getUnchecked(i);
  28215. if (c->sourceNodeId == possibleSourceNodeId
  28216. && c->destNodeId == possibleDestNodeId)
  28217. {
  28218. return true;
  28219. }
  28220. }
  28221. return false;
  28222. }
  28223. bool AudioProcessorGraph::canConnect (const uint32 sourceNodeId,
  28224. const int sourceChannelIndex,
  28225. const uint32 destNodeId,
  28226. const int destChannelIndex) const
  28227. {
  28228. if (sourceChannelIndex < 0
  28229. || destChannelIndex < 0
  28230. || sourceNodeId == destNodeId
  28231. || (destChannelIndex == midiChannelIndex) != (sourceChannelIndex == midiChannelIndex))
  28232. return false;
  28233. const Node* const source = getNodeForId (sourceNodeId);
  28234. if (source == 0
  28235. || (sourceChannelIndex != midiChannelIndex && sourceChannelIndex >= source->processor->getNumOutputChannels())
  28236. || (sourceChannelIndex == midiChannelIndex && ! source->processor->producesMidi()))
  28237. return false;
  28238. const Node* const dest = getNodeForId (destNodeId);
  28239. if (dest == 0
  28240. || (destChannelIndex != midiChannelIndex && destChannelIndex >= dest->processor->getNumInputChannels())
  28241. || (destChannelIndex == midiChannelIndex && ! dest->processor->acceptsMidi()))
  28242. return false;
  28243. return getConnectionBetween (sourceNodeId, sourceChannelIndex,
  28244. destNodeId, destChannelIndex) == 0;
  28245. }
  28246. bool AudioProcessorGraph::addConnection (const uint32 sourceNodeId,
  28247. const int sourceChannelIndex,
  28248. const uint32 destNodeId,
  28249. const int destChannelIndex)
  28250. {
  28251. if (! canConnect (sourceNodeId, sourceChannelIndex, destNodeId, destChannelIndex))
  28252. return false;
  28253. Connection* const c = new Connection();
  28254. c->sourceNodeId = sourceNodeId;
  28255. c->sourceChannelIndex = sourceChannelIndex;
  28256. c->destNodeId = destNodeId;
  28257. c->destChannelIndex = destChannelIndex;
  28258. connections.add (c);
  28259. triggerAsyncUpdate();
  28260. return true;
  28261. }
  28262. void AudioProcessorGraph::removeConnection (const int index)
  28263. {
  28264. connections.remove (index);
  28265. triggerAsyncUpdate();
  28266. }
  28267. bool AudioProcessorGraph::removeConnection (const uint32 sourceNodeId, const int sourceChannelIndex,
  28268. const uint32 destNodeId, const int destChannelIndex)
  28269. {
  28270. bool doneAnything = false;
  28271. for (int i = connections.size(); --i >= 0;)
  28272. {
  28273. const Connection* const c = connections.getUnchecked(i);
  28274. if (c->sourceNodeId == sourceNodeId
  28275. && c->destNodeId == destNodeId
  28276. && c->sourceChannelIndex == sourceChannelIndex
  28277. && c->destChannelIndex == destChannelIndex)
  28278. {
  28279. removeConnection (i);
  28280. doneAnything = true;
  28281. triggerAsyncUpdate();
  28282. }
  28283. }
  28284. return doneAnything;
  28285. }
  28286. bool AudioProcessorGraph::disconnectNode (const uint32 nodeId)
  28287. {
  28288. bool doneAnything = false;
  28289. for (int i = connections.size(); --i >= 0;)
  28290. {
  28291. const Connection* const c = connections.getUnchecked(i);
  28292. if (c->sourceNodeId == nodeId || c->destNodeId == nodeId)
  28293. {
  28294. removeConnection (i);
  28295. doneAnything = true;
  28296. triggerAsyncUpdate();
  28297. }
  28298. }
  28299. return doneAnything;
  28300. }
  28301. bool AudioProcessorGraph::removeIllegalConnections()
  28302. {
  28303. bool doneAnything = false;
  28304. for (int i = connections.size(); --i >= 0;)
  28305. {
  28306. const Connection* const c = connections.getUnchecked(i);
  28307. const Node* const source = getNodeForId (c->sourceNodeId);
  28308. const Node* const dest = getNodeForId (c->destNodeId);
  28309. if (source == 0 || dest == 0
  28310. || (c->sourceChannelIndex != midiChannelIndex
  28311. && (((unsigned int) c->sourceChannelIndex) >= (unsigned int) source->processor->getNumOutputChannels()))
  28312. || (c->sourceChannelIndex == midiChannelIndex
  28313. && ! source->processor->producesMidi())
  28314. || (c->destChannelIndex != midiChannelIndex
  28315. && (((unsigned int) c->destChannelIndex) >= (unsigned int) dest->processor->getNumInputChannels()))
  28316. || (c->destChannelIndex == midiChannelIndex
  28317. && ! dest->processor->acceptsMidi()))
  28318. {
  28319. removeConnection (i);
  28320. doneAnything = true;
  28321. triggerAsyncUpdate();
  28322. }
  28323. }
  28324. return doneAnything;
  28325. }
  28326. namespace GraphRenderingOps
  28327. {
  28328. class AudioGraphRenderingOp
  28329. {
  28330. public:
  28331. AudioGraphRenderingOp() {}
  28332. virtual ~AudioGraphRenderingOp() {}
  28333. virtual void perform (AudioSampleBuffer& sharedBufferChans,
  28334. const OwnedArray <MidiBuffer>& sharedMidiBuffers,
  28335. const int numSamples) = 0;
  28336. juce_UseDebuggingNewOperator
  28337. };
  28338. class ClearChannelOp : public AudioGraphRenderingOp
  28339. {
  28340. public:
  28341. ClearChannelOp (const int channelNum_)
  28342. : channelNum (channelNum_)
  28343. {}
  28344. ~ClearChannelOp() {}
  28345. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28346. {
  28347. sharedBufferChans.clear (channelNum, 0, numSamples);
  28348. }
  28349. private:
  28350. const int channelNum;
  28351. ClearChannelOp (const ClearChannelOp&);
  28352. ClearChannelOp& operator= (const ClearChannelOp&);
  28353. };
  28354. class CopyChannelOp : public AudioGraphRenderingOp
  28355. {
  28356. public:
  28357. CopyChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28358. : srcChannelNum (srcChannelNum_),
  28359. dstChannelNum (dstChannelNum_)
  28360. {}
  28361. ~CopyChannelOp() {}
  28362. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28363. {
  28364. sharedBufferChans.copyFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28365. }
  28366. private:
  28367. const int srcChannelNum, dstChannelNum;
  28368. CopyChannelOp (const CopyChannelOp&);
  28369. CopyChannelOp& operator= (const CopyChannelOp&);
  28370. };
  28371. class AddChannelOp : public AudioGraphRenderingOp
  28372. {
  28373. public:
  28374. AddChannelOp (const int srcChannelNum_, const int dstChannelNum_)
  28375. : srcChannelNum (srcChannelNum_),
  28376. dstChannelNum (dstChannelNum_)
  28377. {}
  28378. ~AddChannelOp() {}
  28379. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>&, const int numSamples)
  28380. {
  28381. sharedBufferChans.addFrom (dstChannelNum, 0, sharedBufferChans, srcChannelNum, 0, numSamples);
  28382. }
  28383. private:
  28384. const int srcChannelNum, dstChannelNum;
  28385. AddChannelOp (const AddChannelOp&);
  28386. AddChannelOp& operator= (const AddChannelOp&);
  28387. };
  28388. class ClearMidiBufferOp : public AudioGraphRenderingOp
  28389. {
  28390. public:
  28391. ClearMidiBufferOp (const int bufferNum_)
  28392. : bufferNum (bufferNum_)
  28393. {}
  28394. ~ClearMidiBufferOp() {}
  28395. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28396. {
  28397. sharedMidiBuffers.getUnchecked (bufferNum)->clear();
  28398. }
  28399. private:
  28400. const int bufferNum;
  28401. ClearMidiBufferOp (const ClearMidiBufferOp&);
  28402. ClearMidiBufferOp& operator= (const ClearMidiBufferOp&);
  28403. };
  28404. class CopyMidiBufferOp : public AudioGraphRenderingOp
  28405. {
  28406. public:
  28407. CopyMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28408. : srcBufferNum (srcBufferNum_),
  28409. dstBufferNum (dstBufferNum_)
  28410. {}
  28411. ~CopyMidiBufferOp() {}
  28412. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int)
  28413. {
  28414. *sharedMidiBuffers.getUnchecked (dstBufferNum) = *sharedMidiBuffers.getUnchecked (srcBufferNum);
  28415. }
  28416. private:
  28417. const int srcBufferNum, dstBufferNum;
  28418. CopyMidiBufferOp (const CopyMidiBufferOp&);
  28419. CopyMidiBufferOp& operator= (const CopyMidiBufferOp&);
  28420. };
  28421. class AddMidiBufferOp : public AudioGraphRenderingOp
  28422. {
  28423. public:
  28424. AddMidiBufferOp (const int srcBufferNum_, const int dstBufferNum_)
  28425. : srcBufferNum (srcBufferNum_),
  28426. dstBufferNum (dstBufferNum_)
  28427. {}
  28428. ~AddMidiBufferOp() {}
  28429. void perform (AudioSampleBuffer&, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28430. {
  28431. sharedMidiBuffers.getUnchecked (dstBufferNum)
  28432. ->addEvents (*sharedMidiBuffers.getUnchecked (srcBufferNum), 0, numSamples, 0);
  28433. }
  28434. private:
  28435. const int srcBufferNum, dstBufferNum;
  28436. AddMidiBufferOp (const AddMidiBufferOp&);
  28437. AddMidiBufferOp& operator= (const AddMidiBufferOp&);
  28438. };
  28439. class ProcessBufferOp : public AudioGraphRenderingOp
  28440. {
  28441. public:
  28442. ProcessBufferOp (const AudioProcessorGraph::Node::Ptr& node_,
  28443. const Array <int>& audioChannelsToUse_,
  28444. const int totalChans_,
  28445. const int midiBufferToUse_)
  28446. : node (node_),
  28447. processor (node_->processor),
  28448. audioChannelsToUse (audioChannelsToUse_),
  28449. totalChans (jmax (1, totalChans_)),
  28450. midiBufferToUse (midiBufferToUse_)
  28451. {
  28452. channels.calloc (totalChans);
  28453. while (audioChannelsToUse.size() < totalChans)
  28454. audioChannelsToUse.add (0);
  28455. }
  28456. ~ProcessBufferOp()
  28457. {
  28458. }
  28459. void perform (AudioSampleBuffer& sharedBufferChans, const OwnedArray <MidiBuffer>& sharedMidiBuffers, const int numSamples)
  28460. {
  28461. for (int i = totalChans; --i >= 0;)
  28462. channels[i] = sharedBufferChans.getSampleData (audioChannelsToUse.getUnchecked (i), 0);
  28463. AudioSampleBuffer buffer (channels, totalChans, numSamples);
  28464. processor->processBlock (buffer, *sharedMidiBuffers.getUnchecked (midiBufferToUse));
  28465. }
  28466. const AudioProcessorGraph::Node::Ptr node;
  28467. AudioProcessor* const processor;
  28468. private:
  28469. Array <int> audioChannelsToUse;
  28470. HeapBlock <float*> channels;
  28471. int totalChans;
  28472. int midiBufferToUse;
  28473. ProcessBufferOp (const ProcessBufferOp&);
  28474. ProcessBufferOp& operator= (const ProcessBufferOp&);
  28475. };
  28476. class RenderingOpSequenceCalculator
  28477. {
  28478. public:
  28479. RenderingOpSequenceCalculator (AudioProcessorGraph& graph_,
  28480. const VoidArray& orderedNodes_,
  28481. VoidArray& renderingOps)
  28482. : graph (graph_),
  28483. orderedNodes (orderedNodes_)
  28484. {
  28485. nodeIds.add (-2); // first buffer is read-only zeros
  28486. channels.add (0);
  28487. midiNodeIds.add (-2);
  28488. for (int i = 0; i < orderedNodes.size(); ++i)
  28489. {
  28490. createRenderingOpsForNode ((AudioProcessorGraph::Node*) orderedNodes.getUnchecked(i),
  28491. renderingOps, i);
  28492. markAnyUnusedBuffersAsFree (i);
  28493. }
  28494. }
  28495. int getNumBuffersNeeded() const { return nodeIds.size(); }
  28496. int getNumMidiBuffersNeeded() const { return midiNodeIds.size(); }
  28497. juce_UseDebuggingNewOperator
  28498. private:
  28499. AudioProcessorGraph& graph;
  28500. const VoidArray& orderedNodes;
  28501. Array <int> nodeIds, channels, midiNodeIds;
  28502. void createRenderingOpsForNode (AudioProcessorGraph::Node* const node,
  28503. VoidArray& renderingOps,
  28504. const int ourRenderingIndex)
  28505. {
  28506. const int numIns = node->processor->getNumInputChannels();
  28507. const int numOuts = node->processor->getNumOutputChannels();
  28508. const int totalChans = jmax (numIns, numOuts);
  28509. Array <int> audioChannelsToUse;
  28510. int midiBufferToUse = -1;
  28511. for (int inputChan = 0; inputChan < numIns; ++inputChan)
  28512. {
  28513. // get a list of all the inputs to this node
  28514. Array <int> sourceNodes, sourceOutputChans;
  28515. for (int i = graph.getNumConnections(); --i >= 0;)
  28516. {
  28517. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28518. if (c->destNodeId == node->id && c->destChannelIndex == inputChan)
  28519. {
  28520. sourceNodes.add (c->sourceNodeId);
  28521. sourceOutputChans.add (c->sourceChannelIndex);
  28522. }
  28523. }
  28524. int bufIndex = -1;
  28525. if (sourceNodes.size() == 0)
  28526. {
  28527. // unconnected input channel
  28528. if (inputChan >= numOuts)
  28529. {
  28530. bufIndex = getReadOnlyEmptyBuffer();
  28531. jassert (bufIndex >= 0);
  28532. }
  28533. else
  28534. {
  28535. bufIndex = getFreeBuffer (false);
  28536. renderingOps.add (new ClearChannelOp (bufIndex));
  28537. }
  28538. }
  28539. else if (sourceNodes.size() == 1)
  28540. {
  28541. // channel with a straightforward single input..
  28542. const int srcNode = sourceNodes.getUnchecked(0);
  28543. const int srcChan = sourceOutputChans.getUnchecked(0);
  28544. bufIndex = getBufferContaining (srcNode, srcChan);
  28545. if (bufIndex < 0)
  28546. {
  28547. // if not found, this is probably a feedback loop
  28548. bufIndex = getReadOnlyEmptyBuffer();
  28549. jassert (bufIndex >= 0);
  28550. }
  28551. if (inputChan < numOuts
  28552. && isBufferNeededLater (ourRenderingIndex,
  28553. inputChan,
  28554. srcNode, srcChan))
  28555. {
  28556. // can't mess up this channel because it's needed later by another node, so we
  28557. // need to use a copy of it..
  28558. const int newFreeBuffer = getFreeBuffer (false);
  28559. renderingOps.add (new CopyChannelOp (bufIndex, newFreeBuffer));
  28560. bufIndex = newFreeBuffer;
  28561. }
  28562. }
  28563. else
  28564. {
  28565. // channel with a mix of several inputs..
  28566. // try to find a re-usable channel from our inputs..
  28567. int reusableInputIndex = -1;
  28568. for (int i = 0; i < sourceNodes.size(); ++i)
  28569. {
  28570. const int sourceBufIndex = getBufferContaining (sourceNodes.getUnchecked(i),
  28571. sourceOutputChans.getUnchecked(i));
  28572. if (sourceBufIndex >= 0
  28573. && ! isBufferNeededLater (ourRenderingIndex,
  28574. inputChan,
  28575. sourceNodes.getUnchecked(i),
  28576. sourceOutputChans.getUnchecked(i)))
  28577. {
  28578. // we've found one of our input chans that can be re-used..
  28579. reusableInputIndex = i;
  28580. bufIndex = sourceBufIndex;
  28581. break;
  28582. }
  28583. }
  28584. if (reusableInputIndex < 0)
  28585. {
  28586. // can't re-use any of our input chans, so get a new one and copy everything into it..
  28587. bufIndex = getFreeBuffer (false);
  28588. jassert (bufIndex != 0);
  28589. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked (0),
  28590. sourceOutputChans.getUnchecked (0));
  28591. if (srcIndex < 0)
  28592. {
  28593. // if not found, this is probably a feedback loop
  28594. renderingOps.add (new ClearChannelOp (bufIndex));
  28595. }
  28596. else
  28597. {
  28598. renderingOps.add (new CopyChannelOp (srcIndex, bufIndex));
  28599. }
  28600. reusableInputIndex = 0;
  28601. }
  28602. for (int j = 0; j < sourceNodes.size(); ++j)
  28603. {
  28604. if (j != reusableInputIndex)
  28605. {
  28606. const int srcIndex = getBufferContaining (sourceNodes.getUnchecked(j),
  28607. sourceOutputChans.getUnchecked(j));
  28608. if (srcIndex >= 0)
  28609. renderingOps.add (new AddChannelOp (srcIndex, bufIndex));
  28610. }
  28611. }
  28612. }
  28613. jassert (bufIndex >= 0);
  28614. audioChannelsToUse.add (bufIndex);
  28615. if (inputChan < numOuts)
  28616. markBufferAsContaining (bufIndex, node->id, inputChan);
  28617. }
  28618. for (int outputChan = numIns; outputChan < numOuts; ++outputChan)
  28619. {
  28620. const int bufIndex = getFreeBuffer (false);
  28621. jassert (bufIndex != 0);
  28622. audioChannelsToUse.add (bufIndex);
  28623. markBufferAsContaining (bufIndex, node->id, outputChan);
  28624. }
  28625. // Now the same thing for midi..
  28626. Array <int> midiSourceNodes;
  28627. for (int i = graph.getNumConnections(); --i >= 0;)
  28628. {
  28629. const AudioProcessorGraph::Connection* const c = graph.getConnection (i);
  28630. if (c->destNodeId == node->id && c->destChannelIndex == AudioProcessorGraph::midiChannelIndex)
  28631. midiSourceNodes.add (c->sourceNodeId);
  28632. }
  28633. if (midiSourceNodes.size() == 0)
  28634. {
  28635. // No midi inputs..
  28636. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28637. if (node->processor->acceptsMidi() || node->processor->producesMidi())
  28638. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28639. }
  28640. else if (midiSourceNodes.size() == 1)
  28641. {
  28642. // One midi input..
  28643. midiBufferToUse = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28644. AudioProcessorGraph::midiChannelIndex);
  28645. if (midiBufferToUse >= 0)
  28646. {
  28647. if (isBufferNeededLater (ourRenderingIndex,
  28648. AudioProcessorGraph::midiChannelIndex,
  28649. midiSourceNodes.getUnchecked(0),
  28650. AudioProcessorGraph::midiChannelIndex))
  28651. {
  28652. // can't mess up this channel because it's needed later by another node, so we
  28653. // need to use a copy of it..
  28654. const int newFreeBuffer = getFreeBuffer (true);
  28655. renderingOps.add (new CopyMidiBufferOp (midiBufferToUse, newFreeBuffer));
  28656. midiBufferToUse = newFreeBuffer;
  28657. }
  28658. }
  28659. else
  28660. {
  28661. // probably a feedback loop, so just use an empty one..
  28662. midiBufferToUse = getFreeBuffer (true); // need to pick a buffer even if the processor doesn't use midi
  28663. }
  28664. }
  28665. else
  28666. {
  28667. // More than one midi input being mixed..
  28668. int reusableInputIndex = -1;
  28669. for (int i = 0; i < midiSourceNodes.size(); ++i)
  28670. {
  28671. const int sourceBufIndex = getBufferContaining (midiSourceNodes.getUnchecked(i),
  28672. AudioProcessorGraph::midiChannelIndex);
  28673. if (sourceBufIndex >= 0
  28674. && ! isBufferNeededLater (ourRenderingIndex,
  28675. AudioProcessorGraph::midiChannelIndex,
  28676. midiSourceNodes.getUnchecked(i),
  28677. AudioProcessorGraph::midiChannelIndex))
  28678. {
  28679. // we've found one of our input buffers that can be re-used..
  28680. reusableInputIndex = i;
  28681. midiBufferToUse = sourceBufIndex;
  28682. break;
  28683. }
  28684. }
  28685. if (reusableInputIndex < 0)
  28686. {
  28687. // can't re-use any of our input buffers, so get a new one and copy everything into it..
  28688. midiBufferToUse = getFreeBuffer (true);
  28689. jassert (midiBufferToUse >= 0);
  28690. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(0),
  28691. AudioProcessorGraph::midiChannelIndex);
  28692. if (srcIndex >= 0)
  28693. renderingOps.add (new CopyMidiBufferOp (srcIndex, midiBufferToUse));
  28694. else
  28695. renderingOps.add (new ClearMidiBufferOp (midiBufferToUse));
  28696. reusableInputIndex = 0;
  28697. }
  28698. for (int j = 0; j < midiSourceNodes.size(); ++j)
  28699. {
  28700. if (j != reusableInputIndex)
  28701. {
  28702. const int srcIndex = getBufferContaining (midiSourceNodes.getUnchecked(j),
  28703. AudioProcessorGraph::midiChannelIndex);
  28704. if (srcIndex >= 0)
  28705. renderingOps.add (new AddMidiBufferOp (srcIndex, midiBufferToUse));
  28706. }
  28707. }
  28708. }
  28709. if (node->processor->producesMidi())
  28710. markBufferAsContaining (midiBufferToUse, node->id,
  28711. AudioProcessorGraph::midiChannelIndex);
  28712. renderingOps.add (new ProcessBufferOp (node, audioChannelsToUse,
  28713. totalChans, midiBufferToUse));
  28714. }
  28715. int getFreeBuffer (const bool forMidi)
  28716. {
  28717. if (forMidi)
  28718. {
  28719. for (int i = 1; i < midiNodeIds.size(); ++i)
  28720. if (midiNodeIds.getUnchecked(i) < 0)
  28721. return i;
  28722. midiNodeIds.add (-1);
  28723. return midiNodeIds.size() - 1;
  28724. }
  28725. else
  28726. {
  28727. for (int i = 1; i < nodeIds.size(); ++i)
  28728. if (nodeIds.getUnchecked(i) < 0)
  28729. return i;
  28730. nodeIds.add (-1);
  28731. channels.add (0);
  28732. return nodeIds.size() - 1;
  28733. }
  28734. }
  28735. int getReadOnlyEmptyBuffer() const
  28736. {
  28737. return 0;
  28738. }
  28739. int getBufferContaining (const int nodeId, const int outputChannel) const
  28740. {
  28741. if (outputChannel == AudioProcessorGraph::midiChannelIndex)
  28742. {
  28743. for (int i = midiNodeIds.size(); --i >= 0;)
  28744. if (midiNodeIds.getUnchecked(i) == nodeId)
  28745. return i;
  28746. }
  28747. else
  28748. {
  28749. for (int i = nodeIds.size(); --i >= 0;)
  28750. if (nodeIds.getUnchecked(i) == nodeId
  28751. && channels.getUnchecked(i) == outputChannel)
  28752. return i;
  28753. }
  28754. return -1;
  28755. }
  28756. void markAnyUnusedBuffersAsFree (const int stepIndex)
  28757. {
  28758. int i;
  28759. for (i = 0; i < nodeIds.size(); ++i)
  28760. {
  28761. if (nodeIds.getUnchecked(i) >= 0
  28762. && ! isBufferNeededLater (stepIndex, -1,
  28763. nodeIds.getUnchecked(i),
  28764. channels.getUnchecked(i)))
  28765. {
  28766. nodeIds.set (i, -1);
  28767. }
  28768. }
  28769. for (i = 0; i < midiNodeIds.size(); ++i)
  28770. {
  28771. if (midiNodeIds.getUnchecked(i) >= 0
  28772. && ! isBufferNeededLater (stepIndex, -1,
  28773. midiNodeIds.getUnchecked(i),
  28774. AudioProcessorGraph::midiChannelIndex))
  28775. {
  28776. midiNodeIds.set (i, -1);
  28777. }
  28778. }
  28779. }
  28780. bool isBufferNeededLater (int stepIndexToSearchFrom,
  28781. int inputChannelOfIndexToIgnore,
  28782. const int nodeId,
  28783. const int outputChanIndex) const
  28784. {
  28785. while (stepIndexToSearchFrom < orderedNodes.size())
  28786. {
  28787. const AudioProcessorGraph::Node* const node = (const AudioProcessorGraph::Node*) orderedNodes.getUnchecked (stepIndexToSearchFrom);
  28788. if (outputChanIndex == AudioProcessorGraph::midiChannelIndex)
  28789. {
  28790. if (inputChannelOfIndexToIgnore != AudioProcessorGraph::midiChannelIndex
  28791. && graph.getConnectionBetween (nodeId, AudioProcessorGraph::midiChannelIndex,
  28792. node->id, AudioProcessorGraph::midiChannelIndex) != 0)
  28793. return true;
  28794. }
  28795. else
  28796. {
  28797. for (int i = 0; i < node->processor->getNumInputChannels(); ++i)
  28798. if (i != inputChannelOfIndexToIgnore
  28799. && graph.getConnectionBetween (nodeId, outputChanIndex,
  28800. node->id, i) != 0)
  28801. return true;
  28802. }
  28803. inputChannelOfIndexToIgnore = -1;
  28804. ++stepIndexToSearchFrom;
  28805. }
  28806. return false;
  28807. }
  28808. void markBufferAsContaining (int bufferNum, int nodeId, int outputIndex)
  28809. {
  28810. if (outputIndex == AudioProcessorGraph::midiChannelIndex)
  28811. {
  28812. jassert (bufferNum > 0 && bufferNum < midiNodeIds.size());
  28813. midiNodeIds.set (bufferNum, nodeId);
  28814. }
  28815. else
  28816. {
  28817. jassert (bufferNum >= 0 && bufferNum < nodeIds.size());
  28818. nodeIds.set (bufferNum, nodeId);
  28819. channels.set (bufferNum, outputIndex);
  28820. }
  28821. }
  28822. RenderingOpSequenceCalculator (const RenderingOpSequenceCalculator&);
  28823. RenderingOpSequenceCalculator& operator= (const RenderingOpSequenceCalculator&);
  28824. };
  28825. }
  28826. void AudioProcessorGraph::clearRenderingSequence()
  28827. {
  28828. const ScopedLock sl (renderLock);
  28829. for (int i = renderingOps.size(); --i >= 0;)
  28830. {
  28831. GraphRenderingOps::AudioGraphRenderingOp* const r
  28832. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28833. renderingOps.remove (i);
  28834. delete r;
  28835. }
  28836. }
  28837. bool AudioProcessorGraph::isAnInputTo (const uint32 possibleInputId,
  28838. const uint32 possibleDestinationId,
  28839. const int recursionCheck) const
  28840. {
  28841. if (recursionCheck > 0)
  28842. {
  28843. for (int i = connections.size(); --i >= 0;)
  28844. {
  28845. const AudioProcessorGraph::Connection* const c = connections.getUnchecked (i);
  28846. if (c->destNodeId == possibleDestinationId
  28847. && (c->sourceNodeId == possibleInputId
  28848. || isAnInputTo (possibleInputId, c->sourceNodeId, recursionCheck - 1)))
  28849. return true;
  28850. }
  28851. }
  28852. return false;
  28853. }
  28854. void AudioProcessorGraph::buildRenderingSequence()
  28855. {
  28856. VoidArray newRenderingOps;
  28857. int numRenderingBuffersNeeded = 2;
  28858. int numMidiBuffersNeeded = 1;
  28859. {
  28860. MessageManagerLock mml;
  28861. VoidArray orderedNodes;
  28862. int i;
  28863. for (i = 0; i < nodes.size(); ++i)
  28864. {
  28865. Node* const node = nodes.getUnchecked(i);
  28866. node->prepare (getSampleRate(), getBlockSize(), this);
  28867. int j = 0;
  28868. for (; j < orderedNodes.size(); ++j)
  28869. if (isAnInputTo (node->id,
  28870. ((Node*) orderedNodes.getUnchecked (j))->id,
  28871. nodes.size() + 1))
  28872. break;
  28873. orderedNodes.insert (j, node);
  28874. }
  28875. GraphRenderingOps::RenderingOpSequenceCalculator calculator (*this, orderedNodes, newRenderingOps);
  28876. numRenderingBuffersNeeded = calculator.getNumBuffersNeeded();
  28877. numMidiBuffersNeeded = calculator.getNumMidiBuffersNeeded();
  28878. }
  28879. VoidArray oldRenderingOps (renderingOps);
  28880. {
  28881. // swap over to the new rendering sequence..
  28882. const ScopedLock sl (renderLock);
  28883. renderingBuffers.setSize (numRenderingBuffersNeeded, getBlockSize());
  28884. renderingBuffers.clear();
  28885. for (int i = midiBuffers.size(); --i >= 0;)
  28886. midiBuffers.getUnchecked(i)->clear();
  28887. while (midiBuffers.size() < numMidiBuffersNeeded)
  28888. midiBuffers.add (new MidiBuffer());
  28889. renderingOps = newRenderingOps;
  28890. }
  28891. for (int i = oldRenderingOps.size(); --i >= 0;)
  28892. delete (GraphRenderingOps::AudioGraphRenderingOp*) oldRenderingOps.getUnchecked(i);
  28893. }
  28894. void AudioProcessorGraph::handleAsyncUpdate()
  28895. {
  28896. buildRenderingSequence();
  28897. }
  28898. void AudioProcessorGraph::prepareToPlay (double /*sampleRate*/, int estimatedSamplesPerBlock)
  28899. {
  28900. currentAudioInputBuffer = 0;
  28901. currentAudioOutputBuffer.setSize (jmax (1, getNumOutputChannels()), estimatedSamplesPerBlock);
  28902. currentMidiInputBuffer = 0;
  28903. currentMidiOutputBuffer.clear();
  28904. clearRenderingSequence();
  28905. buildRenderingSequence();
  28906. }
  28907. void AudioProcessorGraph::releaseResources()
  28908. {
  28909. for (int i = 0; i < nodes.size(); ++i)
  28910. nodes.getUnchecked(i)->unprepare();
  28911. renderingBuffers.setSize (1, 1);
  28912. midiBuffers.clear();
  28913. currentAudioInputBuffer = 0;
  28914. currentAudioOutputBuffer.setSize (1, 1);
  28915. currentMidiInputBuffer = 0;
  28916. currentMidiOutputBuffer.clear();
  28917. }
  28918. void AudioProcessorGraph::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages)
  28919. {
  28920. const int numSamples = buffer.getNumSamples();
  28921. const ScopedLock sl (renderLock);
  28922. currentAudioInputBuffer = &buffer;
  28923. currentAudioOutputBuffer.setSize (jmax (1, buffer.getNumChannels()), numSamples);
  28924. currentAudioOutputBuffer.clear();
  28925. currentMidiInputBuffer = &midiMessages;
  28926. currentMidiOutputBuffer.clear();
  28927. int i;
  28928. for (i = 0; i < renderingOps.size(); ++i)
  28929. {
  28930. GraphRenderingOps::AudioGraphRenderingOp* const op
  28931. = (GraphRenderingOps::AudioGraphRenderingOp*) renderingOps.getUnchecked(i);
  28932. op->perform (renderingBuffers, midiBuffers, numSamples);
  28933. }
  28934. for (i = 0; i < buffer.getNumChannels(); ++i)
  28935. buffer.copyFrom (i, 0, currentAudioOutputBuffer, i, 0, numSamples);
  28936. midiMessages.clear();
  28937. midiMessages.addEvents (currentMidiOutputBuffer, 0, buffer.getNumSamples(), 0);
  28938. }
  28939. const String AudioProcessorGraph::getInputChannelName (const int channelIndex) const
  28940. {
  28941. return "Input " + String (channelIndex + 1);
  28942. }
  28943. const String AudioProcessorGraph::getOutputChannelName (const int channelIndex) const
  28944. {
  28945. return "Output " + String (channelIndex + 1);
  28946. }
  28947. bool AudioProcessorGraph::isInputChannelStereoPair (int /*index*/) const
  28948. {
  28949. return true;
  28950. }
  28951. bool AudioProcessorGraph::isOutputChannelStereoPair (int /*index*/) const
  28952. {
  28953. return true;
  28954. }
  28955. bool AudioProcessorGraph::acceptsMidi() const
  28956. {
  28957. return true;
  28958. }
  28959. bool AudioProcessorGraph::producesMidi() const
  28960. {
  28961. return true;
  28962. }
  28963. void AudioProcessorGraph::getStateInformation (JUCE_NAMESPACE::MemoryBlock& /*destData*/)
  28964. {
  28965. }
  28966. void AudioProcessorGraph::setStateInformation (const void* /*data*/, int /*sizeInBytes*/)
  28967. {
  28968. }
  28969. AudioProcessorGraph::AudioGraphIOProcessor::AudioGraphIOProcessor (const IODeviceType type_)
  28970. : type (type_),
  28971. graph (0)
  28972. {
  28973. }
  28974. AudioProcessorGraph::AudioGraphIOProcessor::~AudioGraphIOProcessor()
  28975. {
  28976. }
  28977. const String AudioProcessorGraph::AudioGraphIOProcessor::getName() const
  28978. {
  28979. switch (type)
  28980. {
  28981. case audioOutputNode:
  28982. return "Audio Output";
  28983. case audioInputNode:
  28984. return "Audio Input";
  28985. case midiOutputNode:
  28986. return "Midi Output";
  28987. case midiInputNode:
  28988. return "Midi Input";
  28989. default:
  28990. break;
  28991. }
  28992. return String::empty;
  28993. }
  28994. void AudioProcessorGraph::AudioGraphIOProcessor::fillInPluginDescription (PluginDescription& d) const
  28995. {
  28996. d.name = getName();
  28997. d.uid = d.name.hashCode();
  28998. d.category = "I/O devices";
  28999. d.pluginFormatName = "Internal";
  29000. d.manufacturerName = "Raw Material Software";
  29001. d.version = "1.0";
  29002. d.isInstrument = false;
  29003. d.numInputChannels = getNumInputChannels();
  29004. if (type == audioOutputNode && graph != 0)
  29005. d.numInputChannels = graph->getNumInputChannels();
  29006. d.numOutputChannels = getNumOutputChannels();
  29007. if (type == audioInputNode && graph != 0)
  29008. d.numOutputChannels = graph->getNumOutputChannels();
  29009. }
  29010. void AudioProcessorGraph::AudioGraphIOProcessor::prepareToPlay (double, int)
  29011. {
  29012. jassert (graph != 0);
  29013. }
  29014. void AudioProcessorGraph::AudioGraphIOProcessor::releaseResources()
  29015. {
  29016. }
  29017. void AudioProcessorGraph::AudioGraphIOProcessor::processBlock (AudioSampleBuffer& buffer,
  29018. MidiBuffer& midiMessages)
  29019. {
  29020. jassert (graph != 0);
  29021. switch (type)
  29022. {
  29023. case audioOutputNode:
  29024. {
  29025. for (int i = jmin (graph->currentAudioOutputBuffer.getNumChannels(),
  29026. buffer.getNumChannels()); --i >= 0;)
  29027. {
  29028. graph->currentAudioOutputBuffer.addFrom (i, 0, buffer, i, 0, buffer.getNumSamples());
  29029. }
  29030. break;
  29031. }
  29032. case audioInputNode:
  29033. {
  29034. for (int i = jmin (graph->currentAudioInputBuffer->getNumChannels(),
  29035. buffer.getNumChannels()); --i >= 0;)
  29036. {
  29037. buffer.copyFrom (i, 0, *graph->currentAudioInputBuffer, i, 0, buffer.getNumSamples());
  29038. }
  29039. break;
  29040. }
  29041. case midiOutputNode:
  29042. graph->currentMidiOutputBuffer.addEvents (midiMessages, 0, buffer.getNumSamples(), 0);
  29043. break;
  29044. case midiInputNode:
  29045. midiMessages.addEvents (*graph->currentMidiInputBuffer, 0, buffer.getNumSamples(), 0);
  29046. break;
  29047. default:
  29048. break;
  29049. }
  29050. }
  29051. bool AudioProcessorGraph::AudioGraphIOProcessor::acceptsMidi() const
  29052. {
  29053. return type == midiOutputNode;
  29054. }
  29055. bool AudioProcessorGraph::AudioGraphIOProcessor::producesMidi() const
  29056. {
  29057. return type == midiInputNode;
  29058. }
  29059. const String AudioProcessorGraph::AudioGraphIOProcessor::getInputChannelName (const int channelIndex) const
  29060. {
  29061. switch (type)
  29062. {
  29063. case audioOutputNode:
  29064. return "Output " + String (channelIndex + 1);
  29065. case midiOutputNode:
  29066. return "Midi Output";
  29067. default:
  29068. break;
  29069. }
  29070. return String::empty;
  29071. }
  29072. const String AudioProcessorGraph::AudioGraphIOProcessor::getOutputChannelName (const int channelIndex) const
  29073. {
  29074. switch (type)
  29075. {
  29076. case audioInputNode:
  29077. return "Input " + String (channelIndex + 1);
  29078. case midiInputNode:
  29079. return "Midi Input";
  29080. default:
  29081. break;
  29082. }
  29083. return String::empty;
  29084. }
  29085. bool AudioProcessorGraph::AudioGraphIOProcessor::isInputChannelStereoPair (int /*index*/) const
  29086. {
  29087. return type == audioInputNode || type == audioOutputNode;
  29088. }
  29089. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutputChannelStereoPair (int index) const
  29090. {
  29091. return isInputChannelStereoPair (index);
  29092. }
  29093. bool AudioProcessorGraph::AudioGraphIOProcessor::isInput() const
  29094. {
  29095. return type == audioInputNode || type == midiInputNode;
  29096. }
  29097. bool AudioProcessorGraph::AudioGraphIOProcessor::isOutput() const
  29098. {
  29099. return type == audioOutputNode || type == midiOutputNode;
  29100. }
  29101. AudioProcessorEditor* AudioProcessorGraph::AudioGraphIOProcessor::createEditor()
  29102. {
  29103. return 0;
  29104. }
  29105. int AudioProcessorGraph::AudioGraphIOProcessor::getNumParameters() { return 0; }
  29106. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterName (int) { return String::empty; }
  29107. float AudioProcessorGraph::AudioGraphIOProcessor::getParameter (int) { return 0.0f; }
  29108. const String AudioProcessorGraph::AudioGraphIOProcessor::getParameterText (int) { return String::empty; }
  29109. void AudioProcessorGraph::AudioGraphIOProcessor::setParameter (int, float) { }
  29110. int AudioProcessorGraph::AudioGraphIOProcessor::getNumPrograms() { return 0; }
  29111. int AudioProcessorGraph::AudioGraphIOProcessor::getCurrentProgram() { return 0; }
  29112. void AudioProcessorGraph::AudioGraphIOProcessor::setCurrentProgram (int) { }
  29113. const String AudioProcessorGraph::AudioGraphIOProcessor::getProgramName (int) { return String::empty; }
  29114. void AudioProcessorGraph::AudioGraphIOProcessor::changeProgramName (int, const String&) { }
  29115. void AudioProcessorGraph::AudioGraphIOProcessor::getStateInformation (JUCE_NAMESPACE::MemoryBlock&)
  29116. {
  29117. }
  29118. void AudioProcessorGraph::AudioGraphIOProcessor::setStateInformation (const void*, int)
  29119. {
  29120. }
  29121. void AudioProcessorGraph::AudioGraphIOProcessor::setParentGraph (AudioProcessorGraph* const newGraph)
  29122. {
  29123. graph = newGraph;
  29124. if (graph != 0)
  29125. {
  29126. setPlayConfigDetails (type == audioOutputNode ? graph->getNumOutputChannels() : 0,
  29127. type == audioInputNode ? graph->getNumInputChannels() : 0,
  29128. getSampleRate(),
  29129. getBlockSize());
  29130. updateHostDisplay();
  29131. }
  29132. }
  29133. END_JUCE_NAMESPACE
  29134. /*** End of inlined file: juce_AudioProcessorGraph.cpp ***/
  29135. /*** Start of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29136. BEGIN_JUCE_NAMESPACE
  29137. AudioProcessorPlayer::AudioProcessorPlayer()
  29138. : processor (0),
  29139. sampleRate (0),
  29140. blockSize (0),
  29141. isPrepared (false),
  29142. numInputChans (0),
  29143. numOutputChans (0),
  29144. tempBuffer (1, 1)
  29145. {
  29146. }
  29147. AudioProcessorPlayer::~AudioProcessorPlayer()
  29148. {
  29149. setProcessor (0);
  29150. }
  29151. void AudioProcessorPlayer::setProcessor (AudioProcessor* const processorToPlay)
  29152. {
  29153. if (processor != processorToPlay)
  29154. {
  29155. if (processorToPlay != 0 && sampleRate > 0 && blockSize > 0)
  29156. {
  29157. processorToPlay->setPlayConfigDetails (numInputChans, numOutputChans,
  29158. sampleRate, blockSize);
  29159. processorToPlay->prepareToPlay (sampleRate, blockSize);
  29160. }
  29161. AudioProcessor* oldOne;
  29162. {
  29163. const ScopedLock sl (lock);
  29164. oldOne = isPrepared ? processor : 0;
  29165. processor = processorToPlay;
  29166. isPrepared = true;
  29167. }
  29168. if (oldOne != 0)
  29169. oldOne->releaseResources();
  29170. }
  29171. }
  29172. void AudioProcessorPlayer::audioDeviceIOCallback (const float** inputChannelData,
  29173. int numInputChannels,
  29174. float** outputChannelData,
  29175. int numOutputChannels,
  29176. int numSamples)
  29177. {
  29178. // these should have been prepared by audioDeviceAboutToStart()...
  29179. jassert (sampleRate > 0 && blockSize > 0);
  29180. incomingMidi.clear();
  29181. messageCollector.removeNextBlockOfMessages (incomingMidi, numSamples);
  29182. int i, totalNumChans = 0;
  29183. if (numInputChannels > numOutputChannels)
  29184. {
  29185. // if there aren't enough output channels for the number of
  29186. // inputs, we need to create some temporary extra ones (can't
  29187. // use the input data in case it gets written to)
  29188. tempBuffer.setSize (numInputChannels - numOutputChannels, numSamples,
  29189. false, false, true);
  29190. for (i = 0; i < numOutputChannels; ++i)
  29191. {
  29192. channels[totalNumChans] = outputChannelData[i];
  29193. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29194. ++totalNumChans;
  29195. }
  29196. for (i = numOutputChannels; i < numInputChannels; ++i)
  29197. {
  29198. channels[totalNumChans] = tempBuffer.getSampleData (i - numOutputChannels, 0);
  29199. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29200. ++totalNumChans;
  29201. }
  29202. }
  29203. else
  29204. {
  29205. for (i = 0; i < numInputChannels; ++i)
  29206. {
  29207. channels[totalNumChans] = outputChannelData[i];
  29208. memcpy (channels[totalNumChans], inputChannelData[i], sizeof (float) * numSamples);
  29209. ++totalNumChans;
  29210. }
  29211. for (i = numInputChannels; i < numOutputChannels; ++i)
  29212. {
  29213. channels[totalNumChans] = outputChannelData[i];
  29214. zeromem (channels[totalNumChans], sizeof (float) * numSamples);
  29215. ++totalNumChans;
  29216. }
  29217. }
  29218. AudioSampleBuffer buffer (channels, totalNumChans, numSamples);
  29219. const ScopedLock sl (lock);
  29220. if (processor != 0)
  29221. processor->processBlock (buffer, incomingMidi);
  29222. }
  29223. void AudioProcessorPlayer::audioDeviceAboutToStart (AudioIODevice* device)
  29224. {
  29225. const ScopedLock sl (lock);
  29226. sampleRate = device->getCurrentSampleRate();
  29227. blockSize = device->getCurrentBufferSizeSamples();
  29228. numInputChans = device->getActiveInputChannels().countNumberOfSetBits();
  29229. numOutputChans = device->getActiveOutputChannels().countNumberOfSetBits();
  29230. messageCollector.reset (sampleRate);
  29231. zeromem (channels, sizeof (channels));
  29232. if (processor != 0)
  29233. {
  29234. if (isPrepared)
  29235. processor->releaseResources();
  29236. AudioProcessor* const oldProcessor = processor;
  29237. setProcessor (0);
  29238. setProcessor (oldProcessor);
  29239. }
  29240. }
  29241. void AudioProcessorPlayer::audioDeviceStopped()
  29242. {
  29243. const ScopedLock sl (lock);
  29244. if (processor != 0 && isPrepared)
  29245. processor->releaseResources();
  29246. sampleRate = 0.0;
  29247. blockSize = 0;
  29248. isPrepared = false;
  29249. tempBuffer.setSize (1, 1);
  29250. }
  29251. void AudioProcessorPlayer::handleIncomingMidiMessage (MidiInput*, const MidiMessage& message)
  29252. {
  29253. messageCollector.addMessageToQueue (message);
  29254. }
  29255. END_JUCE_NAMESPACE
  29256. /*** End of inlined file: juce_AudioProcessorPlayer.cpp ***/
  29257. /*** Start of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29258. BEGIN_JUCE_NAMESPACE
  29259. class ProcessorParameterPropertyComp : public PropertyComponent,
  29260. public AudioProcessorListener,
  29261. public AsyncUpdater
  29262. {
  29263. public:
  29264. ProcessorParameterPropertyComp (const String& name,
  29265. AudioProcessor* const owner_,
  29266. const int index_)
  29267. : PropertyComponent (name),
  29268. owner (owner_),
  29269. index (index_)
  29270. {
  29271. addAndMakeVisible (slider = new ParamSlider (owner_, index_));
  29272. owner_->addListener (this);
  29273. }
  29274. ~ProcessorParameterPropertyComp()
  29275. {
  29276. owner->removeListener (this);
  29277. deleteAllChildren();
  29278. }
  29279. void refresh()
  29280. {
  29281. slider->setValue (owner->getParameter (index), false);
  29282. }
  29283. void audioProcessorChanged (AudioProcessor*) {}
  29284. void audioProcessorParameterChanged (AudioProcessor*, int parameterIndex, float)
  29285. {
  29286. if (parameterIndex == index)
  29287. triggerAsyncUpdate();
  29288. }
  29289. void handleAsyncUpdate()
  29290. {
  29291. refresh();
  29292. }
  29293. juce_UseDebuggingNewOperator
  29294. private:
  29295. AudioProcessor* const owner;
  29296. const int index;
  29297. Slider* slider;
  29298. class ParamSlider : public Slider
  29299. {
  29300. public:
  29301. ParamSlider (AudioProcessor* const owner_, const int index_)
  29302. : Slider (String::empty),
  29303. owner (owner_),
  29304. index (index_)
  29305. {
  29306. setRange (0.0, 1.0, 0.0);
  29307. setSliderStyle (Slider::LinearBar);
  29308. setTextBoxIsEditable (false);
  29309. setScrollWheelEnabled (false);
  29310. }
  29311. ~ParamSlider()
  29312. {
  29313. }
  29314. void valueChanged()
  29315. {
  29316. const float newVal = (float) getValue();
  29317. if (owner->getParameter (index) != newVal)
  29318. owner->setParameter (index, newVal);
  29319. }
  29320. const String getTextFromValue (double /*value*/)
  29321. {
  29322. return owner->getParameterText (index);
  29323. }
  29324. juce_UseDebuggingNewOperator
  29325. private:
  29326. AudioProcessor* const owner;
  29327. const int index;
  29328. ParamSlider (const ParamSlider&);
  29329. ParamSlider& operator= (const ParamSlider&);
  29330. };
  29331. ProcessorParameterPropertyComp (const ProcessorParameterPropertyComp&);
  29332. ProcessorParameterPropertyComp& operator= (const ProcessorParameterPropertyComp&);
  29333. };
  29334. GenericAudioProcessorEditor::GenericAudioProcessorEditor (AudioProcessor* const owner_)
  29335. : AudioProcessorEditor (owner_)
  29336. {
  29337. setOpaque (true);
  29338. addAndMakeVisible (panel = new PropertyPanel());
  29339. Array <PropertyComponent*> params;
  29340. const int numParams = owner_->getNumParameters();
  29341. int totalHeight = 0;
  29342. for (int i = 0; i < numParams; ++i)
  29343. {
  29344. String name (owner_->getParameterName (i));
  29345. if (name.trim().isEmpty())
  29346. name = "Unnamed";
  29347. ProcessorParameterPropertyComp* const pc = new ProcessorParameterPropertyComp (name, owner_, i);
  29348. params.add (pc);
  29349. totalHeight += pc->getPreferredHeight();
  29350. }
  29351. panel->addProperties (params);
  29352. setSize (400, jlimit (25, 400, totalHeight));
  29353. }
  29354. GenericAudioProcessorEditor::~GenericAudioProcessorEditor()
  29355. {
  29356. deleteAllChildren();
  29357. }
  29358. void GenericAudioProcessorEditor::paint (Graphics& g)
  29359. {
  29360. g.fillAll (Colours::white);
  29361. }
  29362. void GenericAudioProcessorEditor::resized()
  29363. {
  29364. panel->setSize (getWidth(), getHeight());
  29365. }
  29366. END_JUCE_NAMESPACE
  29367. /*** End of inlined file: juce_GenericAudioProcessorEditor.cpp ***/
  29368. /*** Start of inlined file: juce_Sampler.cpp ***/
  29369. BEGIN_JUCE_NAMESPACE
  29370. SamplerSound::SamplerSound (const String& name_,
  29371. AudioFormatReader& source,
  29372. const BitArray& midiNotes_,
  29373. const int midiNoteForNormalPitch,
  29374. const double attackTimeSecs,
  29375. const double releaseTimeSecs,
  29376. const double maxSampleLengthSeconds)
  29377. : name (name_),
  29378. midiNotes (midiNotes_),
  29379. midiRootNote (midiNoteForNormalPitch)
  29380. {
  29381. sourceSampleRate = source.sampleRate;
  29382. if (sourceSampleRate <= 0 || source.lengthInSamples <= 0)
  29383. {
  29384. length = 0;
  29385. attackSamples = 0;
  29386. releaseSamples = 0;
  29387. }
  29388. else
  29389. {
  29390. length = jmin ((int) source.lengthInSamples,
  29391. (int) (maxSampleLengthSeconds * sourceSampleRate));
  29392. data = new AudioSampleBuffer (jmin (2, (int) source.numChannels), length + 4);
  29393. data->readFromAudioReader (&source, 0, length + 4, 0, true, true);
  29394. attackSamples = roundToInt (attackTimeSecs * sourceSampleRate);
  29395. releaseSamples = roundToInt (releaseTimeSecs * sourceSampleRate);
  29396. }
  29397. }
  29398. SamplerSound::~SamplerSound()
  29399. {
  29400. }
  29401. bool SamplerSound::appliesToNote (const int midiNoteNumber)
  29402. {
  29403. return midiNotes [midiNoteNumber];
  29404. }
  29405. bool SamplerSound::appliesToChannel (const int /*midiChannel*/)
  29406. {
  29407. return true;
  29408. }
  29409. SamplerVoice::SamplerVoice()
  29410. : pitchRatio (0.0),
  29411. sourceSamplePosition (0.0),
  29412. lgain (0.0f),
  29413. rgain (0.0f),
  29414. isInAttack (false),
  29415. isInRelease (false)
  29416. {
  29417. }
  29418. SamplerVoice::~SamplerVoice()
  29419. {
  29420. }
  29421. bool SamplerVoice::canPlaySound (SynthesiserSound* sound)
  29422. {
  29423. return dynamic_cast <const SamplerSound*> (sound) != 0;
  29424. }
  29425. void SamplerVoice::startNote (const int midiNoteNumber,
  29426. const float velocity,
  29427. SynthesiserSound* s,
  29428. const int /*currentPitchWheelPosition*/)
  29429. {
  29430. const SamplerSound* const sound = dynamic_cast <const SamplerSound*> (s);
  29431. jassert (sound != 0); // this object can only play SamplerSounds!
  29432. if (sound != 0)
  29433. {
  29434. const double targetFreq = MidiMessage::getMidiNoteInHertz (midiNoteNumber);
  29435. const double naturalFreq = MidiMessage::getMidiNoteInHertz (sound->midiRootNote);
  29436. pitchRatio = (targetFreq * sound->sourceSampleRate) / (naturalFreq * getSampleRate());
  29437. sourceSamplePosition = 0.0;
  29438. lgain = velocity;
  29439. rgain = velocity;
  29440. isInAttack = (sound->attackSamples > 0);
  29441. isInRelease = false;
  29442. if (isInAttack)
  29443. {
  29444. attackReleaseLevel = 0.0f;
  29445. attackDelta = (float) (pitchRatio / sound->attackSamples);
  29446. }
  29447. else
  29448. {
  29449. attackReleaseLevel = 1.0f;
  29450. attackDelta = 0.0f;
  29451. }
  29452. if (sound->releaseSamples > 0)
  29453. {
  29454. releaseDelta = (float) (-pitchRatio / sound->releaseSamples);
  29455. }
  29456. else
  29457. {
  29458. releaseDelta = 0.0f;
  29459. }
  29460. }
  29461. }
  29462. void SamplerVoice::stopNote (const bool allowTailOff)
  29463. {
  29464. if (allowTailOff)
  29465. {
  29466. isInAttack = false;
  29467. isInRelease = true;
  29468. }
  29469. else
  29470. {
  29471. clearCurrentNote();
  29472. }
  29473. }
  29474. void SamplerVoice::pitchWheelMoved (const int /*newValue*/)
  29475. {
  29476. }
  29477. void SamplerVoice::controllerMoved (const int /*controllerNumber*/,
  29478. const int /*newValue*/)
  29479. {
  29480. }
  29481. void SamplerVoice::renderNextBlock (AudioSampleBuffer& outputBuffer, int startSample, int numSamples)
  29482. {
  29483. const SamplerSound* const playingSound = (SamplerSound*) (SynthesiserSound*) getCurrentlyPlayingSound();
  29484. if (playingSound != 0)
  29485. {
  29486. const float* const inL = playingSound->data->getSampleData (0, 0);
  29487. const float* const inR = playingSound->data->getNumChannels() > 1
  29488. ? playingSound->data->getSampleData (1, 0) : 0;
  29489. float* outL = outputBuffer.getSampleData (0, startSample);
  29490. float* outR = outputBuffer.getNumChannels() > 1 ? outputBuffer.getSampleData (1, startSample) : 0;
  29491. while (--numSamples >= 0)
  29492. {
  29493. const int pos = (int) sourceSamplePosition;
  29494. const float alpha = (float) (sourceSamplePosition - pos);
  29495. const float invAlpha = 1.0f - alpha;
  29496. // just using a very simple linear interpolation here..
  29497. float l = (inL [pos] * invAlpha + inL [pos + 1] * alpha);
  29498. float r = (inR != 0) ? (inR [pos] * invAlpha + inR [pos + 1] * alpha)
  29499. : l;
  29500. l *= lgain;
  29501. r *= rgain;
  29502. if (isInAttack)
  29503. {
  29504. l *= attackReleaseLevel;
  29505. r *= attackReleaseLevel;
  29506. attackReleaseLevel += attackDelta;
  29507. if (attackReleaseLevel >= 1.0f)
  29508. {
  29509. attackReleaseLevel = 1.0f;
  29510. isInAttack = false;
  29511. }
  29512. }
  29513. else if (isInRelease)
  29514. {
  29515. l *= attackReleaseLevel;
  29516. r *= attackReleaseLevel;
  29517. attackReleaseLevel += releaseDelta;
  29518. if (attackReleaseLevel <= 0.0f)
  29519. {
  29520. stopNote (false);
  29521. break;
  29522. }
  29523. }
  29524. if (outR != 0)
  29525. {
  29526. *outL++ += l;
  29527. *outR++ += r;
  29528. }
  29529. else
  29530. {
  29531. *outL++ += (l + r) * 0.5f;
  29532. }
  29533. sourceSamplePosition += pitchRatio;
  29534. if (sourceSamplePosition > playingSound->length)
  29535. {
  29536. stopNote (false);
  29537. break;
  29538. }
  29539. }
  29540. }
  29541. }
  29542. END_JUCE_NAMESPACE
  29543. /*** End of inlined file: juce_Sampler.cpp ***/
  29544. /*** Start of inlined file: juce_Synthesiser.cpp ***/
  29545. BEGIN_JUCE_NAMESPACE
  29546. SynthesiserSound::SynthesiserSound()
  29547. {
  29548. }
  29549. SynthesiserSound::~SynthesiserSound()
  29550. {
  29551. }
  29552. SynthesiserVoice::SynthesiserVoice()
  29553. : currentSampleRate (44100.0),
  29554. currentlyPlayingNote (-1),
  29555. noteOnTime (0),
  29556. currentlyPlayingSound (0)
  29557. {
  29558. }
  29559. SynthesiserVoice::~SynthesiserVoice()
  29560. {
  29561. }
  29562. bool SynthesiserVoice::isPlayingChannel (const int midiChannel) const
  29563. {
  29564. return currentlyPlayingSound != 0
  29565. && currentlyPlayingSound->appliesToChannel (midiChannel);
  29566. }
  29567. void SynthesiserVoice::setCurrentPlaybackSampleRate (const double newRate)
  29568. {
  29569. currentSampleRate = newRate;
  29570. }
  29571. void SynthesiserVoice::clearCurrentNote()
  29572. {
  29573. currentlyPlayingNote = -1;
  29574. currentlyPlayingSound = 0;
  29575. }
  29576. Synthesiser::Synthesiser()
  29577. : sampleRate (0),
  29578. lastNoteOnCounter (0),
  29579. shouldStealNotes (true)
  29580. {
  29581. for (int i = 0; i < numElementsInArray (lastPitchWheelValues); ++i)
  29582. lastPitchWheelValues[i] = 0x2000;
  29583. }
  29584. Synthesiser::~Synthesiser()
  29585. {
  29586. }
  29587. SynthesiserVoice* Synthesiser::getVoice (const int index) const
  29588. {
  29589. const ScopedLock sl (lock);
  29590. return voices [index];
  29591. }
  29592. void Synthesiser::clearVoices()
  29593. {
  29594. const ScopedLock sl (lock);
  29595. voices.clear();
  29596. }
  29597. void Synthesiser::addVoice (SynthesiserVoice* const newVoice)
  29598. {
  29599. const ScopedLock sl (lock);
  29600. voices.add (newVoice);
  29601. }
  29602. void Synthesiser::removeVoice (const int index)
  29603. {
  29604. const ScopedLock sl (lock);
  29605. voices.remove (index);
  29606. }
  29607. void Synthesiser::clearSounds()
  29608. {
  29609. const ScopedLock sl (lock);
  29610. sounds.clear();
  29611. }
  29612. void Synthesiser::addSound (const SynthesiserSound::Ptr& newSound)
  29613. {
  29614. const ScopedLock sl (lock);
  29615. sounds.add (newSound);
  29616. }
  29617. void Synthesiser::removeSound (const int index)
  29618. {
  29619. const ScopedLock sl (lock);
  29620. sounds.remove (index);
  29621. }
  29622. void Synthesiser::setNoteStealingEnabled (const bool shouldStealNotes_)
  29623. {
  29624. shouldStealNotes = shouldStealNotes_;
  29625. }
  29626. void Synthesiser::setCurrentPlaybackSampleRate (const double newRate)
  29627. {
  29628. if (sampleRate != newRate)
  29629. {
  29630. const ScopedLock sl (lock);
  29631. allNotesOff (0, false);
  29632. sampleRate = newRate;
  29633. for (int i = voices.size(); --i >= 0;)
  29634. voices.getUnchecked (i)->setCurrentPlaybackSampleRate (newRate);
  29635. }
  29636. }
  29637. void Synthesiser::renderNextBlock (AudioSampleBuffer& outputBuffer,
  29638. const MidiBuffer& midiData,
  29639. int startSample,
  29640. int numSamples)
  29641. {
  29642. // must set the sample rate before using this!
  29643. jassert (sampleRate != 0);
  29644. const ScopedLock sl (lock);
  29645. MidiBuffer::Iterator midiIterator (midiData);
  29646. midiIterator.setNextSamplePosition (startSample);
  29647. MidiMessage m (0xf4, 0.0);
  29648. while (numSamples > 0)
  29649. {
  29650. int midiEventPos;
  29651. const bool useEvent = midiIterator.getNextEvent (m, midiEventPos)
  29652. && midiEventPos < startSample + numSamples;
  29653. const int numThisTime = useEvent ? midiEventPos - startSample
  29654. : numSamples;
  29655. if (numThisTime > 0)
  29656. {
  29657. for (int i = voices.size(); --i >= 0;)
  29658. voices.getUnchecked (i)->renderNextBlock (outputBuffer, startSample, numThisTime);
  29659. }
  29660. if (useEvent)
  29661. {
  29662. if (m.isNoteOn())
  29663. {
  29664. const int channel = m.getChannel();
  29665. noteOn (channel,
  29666. m.getNoteNumber(),
  29667. m.getFloatVelocity());
  29668. }
  29669. else if (m.isNoteOff())
  29670. {
  29671. noteOff (m.getChannel(),
  29672. m.getNoteNumber(),
  29673. true);
  29674. }
  29675. else if (m.isAllNotesOff() || m.isAllSoundOff())
  29676. {
  29677. allNotesOff (m.getChannel(), true);
  29678. }
  29679. else if (m.isPitchWheel())
  29680. {
  29681. const int channel = m.getChannel();
  29682. const int wheelPos = m.getPitchWheelValue();
  29683. lastPitchWheelValues [channel - 1] = wheelPos;
  29684. handlePitchWheel (channel, wheelPos);
  29685. }
  29686. else if (m.isController())
  29687. {
  29688. handleController (m.getChannel(),
  29689. m.getControllerNumber(),
  29690. m.getControllerValue());
  29691. }
  29692. }
  29693. startSample += numThisTime;
  29694. numSamples -= numThisTime;
  29695. }
  29696. }
  29697. void Synthesiser::noteOn (const int midiChannel,
  29698. const int midiNoteNumber,
  29699. const float velocity)
  29700. {
  29701. const ScopedLock sl (lock);
  29702. for (int i = sounds.size(); --i >= 0;)
  29703. {
  29704. SynthesiserSound* const sound = sounds.getUnchecked(i);
  29705. if (sound->appliesToNote (midiNoteNumber)
  29706. && sound->appliesToChannel (midiChannel))
  29707. {
  29708. startVoice (findFreeVoice (sound, shouldStealNotes),
  29709. sound, midiChannel, midiNoteNumber, velocity);
  29710. }
  29711. }
  29712. }
  29713. void Synthesiser::startVoice (SynthesiserVoice* const voice,
  29714. SynthesiserSound* const sound,
  29715. const int midiChannel,
  29716. const int midiNoteNumber,
  29717. const float velocity)
  29718. {
  29719. if (voice != 0 && sound != 0)
  29720. {
  29721. if (voice->currentlyPlayingSound != 0)
  29722. voice->stopNote (false);
  29723. voice->startNote (midiNoteNumber,
  29724. velocity,
  29725. sound,
  29726. lastPitchWheelValues [midiChannel - 1]);
  29727. voice->currentlyPlayingNote = midiNoteNumber;
  29728. voice->noteOnTime = ++lastNoteOnCounter;
  29729. voice->currentlyPlayingSound = sound;
  29730. }
  29731. }
  29732. void Synthesiser::noteOff (const int midiChannel,
  29733. const int midiNoteNumber,
  29734. const bool allowTailOff)
  29735. {
  29736. const ScopedLock sl (lock);
  29737. for (int i = voices.size(); --i >= 0;)
  29738. {
  29739. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29740. if (voice->getCurrentlyPlayingNote() == midiNoteNumber)
  29741. {
  29742. SynthesiserSound* const sound = voice->getCurrentlyPlayingSound();
  29743. if (sound != 0
  29744. && sound->appliesToNote (midiNoteNumber)
  29745. && sound->appliesToChannel (midiChannel))
  29746. {
  29747. voice->stopNote (allowTailOff);
  29748. // the subclass MUST call clearCurrentNote() if it's not tailing off! RTFM for stopNote()!
  29749. jassert (allowTailOff || (voice->getCurrentlyPlayingNote() < 0 && voice->getCurrentlyPlayingSound() == 0));
  29750. }
  29751. }
  29752. }
  29753. }
  29754. void Synthesiser::allNotesOff (const int midiChannel,
  29755. const bool allowTailOff)
  29756. {
  29757. const ScopedLock sl (lock);
  29758. for (int i = voices.size(); --i >= 0;)
  29759. {
  29760. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29761. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29762. voice->stopNote (allowTailOff);
  29763. }
  29764. }
  29765. void Synthesiser::handlePitchWheel (const int midiChannel,
  29766. const int wheelValue)
  29767. {
  29768. const ScopedLock sl (lock);
  29769. for (int i = voices.size(); --i >= 0;)
  29770. {
  29771. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29772. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29773. {
  29774. voice->pitchWheelMoved (wheelValue);
  29775. }
  29776. }
  29777. }
  29778. void Synthesiser::handleController (const int midiChannel,
  29779. const int controllerNumber,
  29780. const int controllerValue)
  29781. {
  29782. const ScopedLock sl (lock);
  29783. for (int i = voices.size(); --i >= 0;)
  29784. {
  29785. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29786. if (midiChannel <= 0 || voice->isPlayingChannel (midiChannel))
  29787. voice->controllerMoved (controllerNumber, controllerValue);
  29788. }
  29789. }
  29790. SynthesiserVoice* Synthesiser::findFreeVoice (SynthesiserSound* soundToPlay,
  29791. const bool stealIfNoneAvailable) const
  29792. {
  29793. const ScopedLock sl (lock);
  29794. for (int i = voices.size(); --i >= 0;)
  29795. if (voices.getUnchecked (i)->getCurrentlyPlayingNote() < 0
  29796. && voices.getUnchecked (i)->canPlaySound (soundToPlay))
  29797. return voices.getUnchecked (i);
  29798. if (stealIfNoneAvailable)
  29799. {
  29800. // currently this just steals the one that's been playing the longest, but could be made a bit smarter..
  29801. SynthesiserVoice* oldest = 0;
  29802. for (int i = voices.size(); --i >= 0;)
  29803. {
  29804. SynthesiserVoice* const voice = voices.getUnchecked (i);
  29805. if (voice->canPlaySound (soundToPlay)
  29806. && (oldest == 0 || oldest->noteOnTime > voice->noteOnTime))
  29807. oldest = voice;
  29808. }
  29809. jassert (oldest != 0);
  29810. return oldest;
  29811. }
  29812. return 0;
  29813. }
  29814. END_JUCE_NAMESPACE
  29815. /*** End of inlined file: juce_Synthesiser.cpp ***/
  29816. /*** Start of inlined file: juce_ActionBroadcaster.cpp ***/
  29817. BEGIN_JUCE_NAMESPACE
  29818. ActionBroadcaster::ActionBroadcaster() throw()
  29819. {
  29820. // are you trying to create this object before or after juce has been intialised??
  29821. jassert (MessageManager::instance != 0);
  29822. }
  29823. ActionBroadcaster::~ActionBroadcaster()
  29824. {
  29825. // all event-based objects must be deleted BEFORE juce is shut down!
  29826. jassert (MessageManager::instance != 0);
  29827. }
  29828. void ActionBroadcaster::addActionListener (ActionListener* const listener)
  29829. {
  29830. actionListenerList.addActionListener (listener);
  29831. }
  29832. void ActionBroadcaster::removeActionListener (ActionListener* const listener)
  29833. {
  29834. jassert (actionListenerList.isValidMessageListener());
  29835. if (actionListenerList.isValidMessageListener())
  29836. actionListenerList.removeActionListener (listener);
  29837. }
  29838. void ActionBroadcaster::removeAllActionListeners()
  29839. {
  29840. actionListenerList.removeAllActionListeners();
  29841. }
  29842. void ActionBroadcaster::sendActionMessage (const String& message) const
  29843. {
  29844. actionListenerList.sendActionMessage (message);
  29845. }
  29846. END_JUCE_NAMESPACE
  29847. /*** End of inlined file: juce_ActionBroadcaster.cpp ***/
  29848. /*** Start of inlined file: juce_ActionListenerList.cpp ***/
  29849. BEGIN_JUCE_NAMESPACE
  29850. // special message of our own with a string in it
  29851. class ActionMessage : public Message
  29852. {
  29853. public:
  29854. const String message;
  29855. ActionMessage (const String& messageText,
  29856. void* const listener_) throw()
  29857. : message (messageText)
  29858. {
  29859. pointerParameter = listener_;
  29860. }
  29861. ~ActionMessage() throw()
  29862. {
  29863. }
  29864. private:
  29865. ActionMessage (const ActionMessage&);
  29866. ActionMessage& operator= (const ActionMessage&);
  29867. };
  29868. ActionListenerList::ActionListenerList() throw()
  29869. {
  29870. }
  29871. ActionListenerList::~ActionListenerList() throw()
  29872. {
  29873. }
  29874. void ActionListenerList::addActionListener (ActionListener* const listener) throw()
  29875. {
  29876. const ScopedLock sl (actionListenerLock_);
  29877. jassert (listener != 0);
  29878. jassert (! actionListeners_.contains (listener)); // trying to add a listener to the list twice!
  29879. if (listener != 0)
  29880. actionListeners_.add (listener);
  29881. }
  29882. void ActionListenerList::removeActionListener (ActionListener* const listener) throw()
  29883. {
  29884. const ScopedLock sl (actionListenerLock_);
  29885. jassert (actionListeners_.contains (listener)); // trying to remove a listener that isn't on the list!
  29886. actionListeners_.removeValue (listener);
  29887. }
  29888. void ActionListenerList::removeAllActionListeners() throw()
  29889. {
  29890. const ScopedLock sl (actionListenerLock_);
  29891. actionListeners_.clear();
  29892. }
  29893. void ActionListenerList::sendActionMessage (const String& message) const
  29894. {
  29895. const ScopedLock sl (actionListenerLock_);
  29896. for (int i = actionListeners_.size(); --i >= 0;)
  29897. {
  29898. postMessage (new ActionMessage (message,
  29899. (ActionListener*) actionListeners_.getUnchecked(i)));
  29900. }
  29901. }
  29902. void ActionListenerList::handleMessage (const Message& message)
  29903. {
  29904. const ActionMessage& am = (const ActionMessage&) message;
  29905. if (actionListeners_.contains (am.pointerParameter))
  29906. ((ActionListener*) am.pointerParameter)->actionListenerCallback (am.message);
  29907. }
  29908. END_JUCE_NAMESPACE
  29909. /*** End of inlined file: juce_ActionListenerList.cpp ***/
  29910. /*** Start of inlined file: juce_AsyncUpdater.cpp ***/
  29911. BEGIN_JUCE_NAMESPACE
  29912. AsyncUpdater::AsyncUpdater() throw()
  29913. : asyncMessagePending (false)
  29914. {
  29915. internalAsyncHandler.owner = this;
  29916. }
  29917. AsyncUpdater::~AsyncUpdater()
  29918. {
  29919. }
  29920. void AsyncUpdater::triggerAsyncUpdate() throw()
  29921. {
  29922. if (! asyncMessagePending)
  29923. {
  29924. asyncMessagePending = true;
  29925. internalAsyncHandler.postMessage (new Message());
  29926. }
  29927. }
  29928. void AsyncUpdater::cancelPendingUpdate() throw()
  29929. {
  29930. asyncMessagePending = false;
  29931. }
  29932. void AsyncUpdater::handleUpdateNowIfNeeded()
  29933. {
  29934. if (asyncMessagePending)
  29935. {
  29936. asyncMessagePending = false;
  29937. handleAsyncUpdate();
  29938. }
  29939. }
  29940. void AsyncUpdater::AsyncUpdaterInternal::handleMessage (const Message&)
  29941. {
  29942. owner->handleUpdateNowIfNeeded();
  29943. }
  29944. END_JUCE_NAMESPACE
  29945. /*** End of inlined file: juce_AsyncUpdater.cpp ***/
  29946. /*** Start of inlined file: juce_ChangeBroadcaster.cpp ***/
  29947. BEGIN_JUCE_NAMESPACE
  29948. ChangeBroadcaster::ChangeBroadcaster() throw()
  29949. {
  29950. // are you trying to create this object before or after juce has been intialised??
  29951. jassert (MessageManager::instance != 0);
  29952. }
  29953. ChangeBroadcaster::~ChangeBroadcaster()
  29954. {
  29955. // all event-based objects must be deleted BEFORE juce is shut down!
  29956. jassert (MessageManager::instance != 0);
  29957. }
  29958. void ChangeBroadcaster::addChangeListener (ChangeListener* const listener) throw()
  29959. {
  29960. changeListenerList.addChangeListener (listener);
  29961. }
  29962. void ChangeBroadcaster::removeChangeListener (ChangeListener* const listener) throw()
  29963. {
  29964. jassert (changeListenerList.isValidMessageListener());
  29965. if (changeListenerList.isValidMessageListener())
  29966. changeListenerList.removeChangeListener (listener);
  29967. }
  29968. void ChangeBroadcaster::removeAllChangeListeners() throw()
  29969. {
  29970. changeListenerList.removeAllChangeListeners();
  29971. }
  29972. void ChangeBroadcaster::sendChangeMessage (void* objectThatHasChanged) throw()
  29973. {
  29974. changeListenerList.sendChangeMessage (objectThatHasChanged);
  29975. }
  29976. void ChangeBroadcaster::sendSynchronousChangeMessage (void* objectThatHasChanged)
  29977. {
  29978. changeListenerList.sendSynchronousChangeMessage (objectThatHasChanged);
  29979. }
  29980. void ChangeBroadcaster::dispatchPendingMessages()
  29981. {
  29982. changeListenerList.dispatchPendingMessages();
  29983. }
  29984. END_JUCE_NAMESPACE
  29985. /*** End of inlined file: juce_ChangeBroadcaster.cpp ***/
  29986. /*** Start of inlined file: juce_ChangeListenerList.cpp ***/
  29987. BEGIN_JUCE_NAMESPACE
  29988. ChangeListenerList::ChangeListenerList() throw()
  29989. : lastChangedObject (0),
  29990. messagePending (false)
  29991. {
  29992. }
  29993. ChangeListenerList::~ChangeListenerList() throw()
  29994. {
  29995. }
  29996. void ChangeListenerList::addChangeListener (ChangeListener* const listener) throw()
  29997. {
  29998. const ScopedLock sl (lock);
  29999. jassert (listener != 0);
  30000. if (listener != 0)
  30001. listeners.add (listener);
  30002. }
  30003. void ChangeListenerList::removeChangeListener (ChangeListener* const listener) throw()
  30004. {
  30005. const ScopedLock sl (lock);
  30006. listeners.removeValue (listener);
  30007. }
  30008. void ChangeListenerList::removeAllChangeListeners() throw()
  30009. {
  30010. const ScopedLock sl (lock);
  30011. listeners.clear();
  30012. }
  30013. void ChangeListenerList::sendChangeMessage (void* const objectThatHasChanged) throw()
  30014. {
  30015. const ScopedLock sl (lock);
  30016. if ((! messagePending) && (listeners.size() > 0))
  30017. {
  30018. lastChangedObject = objectThatHasChanged;
  30019. postMessage (new Message (0, 0, 0, objectThatHasChanged));
  30020. messagePending = true;
  30021. }
  30022. }
  30023. void ChangeListenerList::handleMessage (const Message& message)
  30024. {
  30025. sendSynchronousChangeMessage (message.pointerParameter);
  30026. }
  30027. void ChangeListenerList::sendSynchronousChangeMessage (void* const objectThatHasChanged)
  30028. {
  30029. const ScopedLock sl (lock);
  30030. messagePending = false;
  30031. for (int i = listeners.size(); --i >= 0;)
  30032. {
  30033. ChangeListener* const l = (ChangeListener*) listeners.getUnchecked (i);
  30034. {
  30035. const ScopedUnlock tempUnlocker (lock);
  30036. l->changeListenerCallback (objectThatHasChanged);
  30037. }
  30038. i = jmin (i, listeners.size());
  30039. }
  30040. }
  30041. void ChangeListenerList::dispatchPendingMessages()
  30042. {
  30043. if (messagePending)
  30044. sendSynchronousChangeMessage (lastChangedObject);
  30045. }
  30046. END_JUCE_NAMESPACE
  30047. /*** End of inlined file: juce_ChangeListenerList.cpp ***/
  30048. /*** Start of inlined file: juce_InterprocessConnection.cpp ***/
  30049. BEGIN_JUCE_NAMESPACE
  30050. InterprocessConnection::InterprocessConnection (const bool callbacksOnMessageThread,
  30051. const uint32 magicMessageHeaderNumber)
  30052. : Thread ("Juce IPC connection"),
  30053. callbackConnectionState (false),
  30054. useMessageThread (callbacksOnMessageThread),
  30055. magicMessageHeader (magicMessageHeaderNumber),
  30056. pipeReceiveMessageTimeout (-1)
  30057. {
  30058. }
  30059. InterprocessConnection::~InterprocessConnection()
  30060. {
  30061. callbackConnectionState = false;
  30062. disconnect();
  30063. }
  30064. bool InterprocessConnection::connectToSocket (const String& hostName,
  30065. const int portNumber,
  30066. const int timeOutMillisecs)
  30067. {
  30068. disconnect();
  30069. const ScopedLock sl (pipeAndSocketLock);
  30070. socket = new StreamingSocket();
  30071. if (socket->connect (hostName, portNumber, timeOutMillisecs))
  30072. {
  30073. connectionMadeInt();
  30074. startThread();
  30075. return true;
  30076. }
  30077. else
  30078. {
  30079. socket = 0;
  30080. return false;
  30081. }
  30082. }
  30083. bool InterprocessConnection::connectToPipe (const String& pipeName,
  30084. const int pipeReceiveMessageTimeoutMs)
  30085. {
  30086. disconnect();
  30087. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  30088. if (newPipe->openExisting (pipeName))
  30089. {
  30090. const ScopedLock sl (pipeAndSocketLock);
  30091. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  30092. initialiseWithPipe (newPipe.release());
  30093. return true;
  30094. }
  30095. return false;
  30096. }
  30097. bool InterprocessConnection::createPipe (const String& pipeName,
  30098. const int pipeReceiveMessageTimeoutMs)
  30099. {
  30100. disconnect();
  30101. ScopedPointer <NamedPipe> newPipe (new NamedPipe());
  30102. if (newPipe->createNewPipe (pipeName))
  30103. {
  30104. const ScopedLock sl (pipeAndSocketLock);
  30105. pipeReceiveMessageTimeout = pipeReceiveMessageTimeoutMs;
  30106. initialiseWithPipe (newPipe.release());
  30107. return true;
  30108. }
  30109. return false;
  30110. }
  30111. void InterprocessConnection::disconnect()
  30112. {
  30113. if (socket != 0)
  30114. socket->close();
  30115. if (pipe != 0)
  30116. {
  30117. pipe->cancelPendingReads();
  30118. pipe->close();
  30119. }
  30120. stopThread (4000);
  30121. {
  30122. const ScopedLock sl (pipeAndSocketLock);
  30123. socket = 0;
  30124. pipe = 0;
  30125. }
  30126. connectionLostInt();
  30127. }
  30128. bool InterprocessConnection::isConnected() const
  30129. {
  30130. const ScopedLock sl (pipeAndSocketLock);
  30131. return ((socket != 0 && socket->isConnected())
  30132. || (pipe != 0 && pipe->isOpen()))
  30133. && isThreadRunning();
  30134. }
  30135. const String InterprocessConnection::getConnectedHostName() const
  30136. {
  30137. if (pipe != 0)
  30138. {
  30139. return "localhost";
  30140. }
  30141. else if (socket != 0)
  30142. {
  30143. if (! socket->isLocal())
  30144. return socket->getHostName();
  30145. return "localhost";
  30146. }
  30147. return String::empty;
  30148. }
  30149. bool InterprocessConnection::sendMessage (const MemoryBlock& message)
  30150. {
  30151. uint32 messageHeader[2];
  30152. messageHeader [0] = ByteOrder::swapIfBigEndian (magicMessageHeader);
  30153. messageHeader [1] = ByteOrder::swapIfBigEndian ((uint32) message.getSize());
  30154. MemoryBlock messageData (sizeof (messageHeader) + message.getSize());
  30155. messageData.copyFrom (messageHeader, 0, sizeof (messageHeader));
  30156. messageData.copyFrom (message.getData(), sizeof (messageHeader), message.getSize());
  30157. size_t bytesWritten = 0;
  30158. const ScopedLock sl (pipeAndSocketLock);
  30159. if (socket != 0)
  30160. {
  30161. bytesWritten = socket->write (messageData.getData(), (int) messageData.getSize());
  30162. }
  30163. else if (pipe != 0)
  30164. {
  30165. bytesWritten = pipe->write (messageData.getData(), (int) messageData.getSize());
  30166. }
  30167. if (bytesWritten < 0)
  30168. {
  30169. // error..
  30170. return false;
  30171. }
  30172. return (bytesWritten == messageData.getSize());
  30173. }
  30174. void InterprocessConnection::initialiseWithSocket (StreamingSocket* const socket_)
  30175. {
  30176. jassert (socket == 0);
  30177. socket = socket_;
  30178. connectionMadeInt();
  30179. startThread();
  30180. }
  30181. void InterprocessConnection::initialiseWithPipe (NamedPipe* const pipe_)
  30182. {
  30183. jassert (pipe == 0);
  30184. pipe = pipe_;
  30185. connectionMadeInt();
  30186. startThread();
  30187. }
  30188. const int messageMagicNumber = 0xb734128b;
  30189. void InterprocessConnection::handleMessage (const Message& message)
  30190. {
  30191. if (message.intParameter1 == messageMagicNumber)
  30192. {
  30193. switch (message.intParameter2)
  30194. {
  30195. case 0:
  30196. {
  30197. ScopedPointer <MemoryBlock> data ((MemoryBlock*) message.pointerParameter);
  30198. messageReceived (*data);
  30199. break;
  30200. }
  30201. case 1:
  30202. connectionMade();
  30203. break;
  30204. case 2:
  30205. connectionLost();
  30206. break;
  30207. }
  30208. }
  30209. }
  30210. void InterprocessConnection::connectionMadeInt()
  30211. {
  30212. if (! callbackConnectionState)
  30213. {
  30214. callbackConnectionState = true;
  30215. if (useMessageThread)
  30216. postMessage (new Message (messageMagicNumber, 1, 0, 0));
  30217. else
  30218. connectionMade();
  30219. }
  30220. }
  30221. void InterprocessConnection::connectionLostInt()
  30222. {
  30223. if (callbackConnectionState)
  30224. {
  30225. callbackConnectionState = false;
  30226. if (useMessageThread)
  30227. postMessage (new Message (messageMagicNumber, 2, 0, 0));
  30228. else
  30229. connectionLost();
  30230. }
  30231. }
  30232. void InterprocessConnection::deliverDataInt (const MemoryBlock& data)
  30233. {
  30234. jassert (callbackConnectionState);
  30235. if (useMessageThread)
  30236. postMessage (new Message (messageMagicNumber, 0, 0, new MemoryBlock (data)));
  30237. else
  30238. messageReceived (data);
  30239. }
  30240. bool InterprocessConnection::readNextMessageInt()
  30241. {
  30242. const int maximumMessageSize = 1024 * 1024 * 10; // sanity check
  30243. uint32 messageHeader[2];
  30244. const int bytes = (socket != 0) ? socket->read (messageHeader, sizeof (messageHeader), true)
  30245. : pipe->read (messageHeader, sizeof (messageHeader), pipeReceiveMessageTimeout);
  30246. if (bytes == sizeof (messageHeader)
  30247. && ByteOrder::swapIfBigEndian (messageHeader[0]) == magicMessageHeader)
  30248. {
  30249. const int bytesInMessage = (int) ByteOrder::swapIfBigEndian (messageHeader[1]);
  30250. if (bytesInMessage > 0 && bytesInMessage < maximumMessageSize)
  30251. {
  30252. MemoryBlock messageData (bytesInMessage, true);
  30253. int bytesRead = 0;
  30254. while (bytesRead < bytesInMessage)
  30255. {
  30256. if (threadShouldExit())
  30257. return false;
  30258. const int numThisTime = jmin (bytesInMessage, 65536);
  30259. const int bytesIn = (socket != 0) ? socket->read (((char*) messageData.getData()) + bytesRead, numThisTime, true)
  30260. : pipe->read (((char*) messageData.getData()) + bytesRead, numThisTime,
  30261. pipeReceiveMessageTimeout);
  30262. if (bytesIn <= 0)
  30263. break;
  30264. bytesRead += bytesIn;
  30265. }
  30266. if (bytesRead >= 0)
  30267. deliverDataInt (messageData);
  30268. }
  30269. }
  30270. else if (bytes < 0)
  30271. {
  30272. {
  30273. const ScopedLock sl (pipeAndSocketLock);
  30274. socket = 0;
  30275. }
  30276. connectionLostInt();
  30277. return false;
  30278. }
  30279. return true;
  30280. }
  30281. void InterprocessConnection::run()
  30282. {
  30283. while (! threadShouldExit())
  30284. {
  30285. if (socket != 0)
  30286. {
  30287. const int ready = socket->waitUntilReady (true, 0);
  30288. if (ready < 0)
  30289. {
  30290. {
  30291. const ScopedLock sl (pipeAndSocketLock);
  30292. socket = 0;
  30293. }
  30294. connectionLostInt();
  30295. break;
  30296. }
  30297. else if (ready > 0)
  30298. {
  30299. if (! readNextMessageInt())
  30300. break;
  30301. }
  30302. else
  30303. {
  30304. Thread::sleep (2);
  30305. }
  30306. }
  30307. else if (pipe != 0)
  30308. {
  30309. if (! pipe->isOpen())
  30310. {
  30311. {
  30312. const ScopedLock sl (pipeAndSocketLock);
  30313. pipe = 0;
  30314. }
  30315. connectionLostInt();
  30316. break;
  30317. }
  30318. else
  30319. {
  30320. if (! readNextMessageInt())
  30321. break;
  30322. }
  30323. }
  30324. else
  30325. {
  30326. break;
  30327. }
  30328. }
  30329. }
  30330. END_JUCE_NAMESPACE
  30331. /*** End of inlined file: juce_InterprocessConnection.cpp ***/
  30332. /*** Start of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30333. BEGIN_JUCE_NAMESPACE
  30334. InterprocessConnectionServer::InterprocessConnectionServer()
  30335. : Thread ("Juce IPC server")
  30336. {
  30337. }
  30338. InterprocessConnectionServer::~InterprocessConnectionServer()
  30339. {
  30340. stop();
  30341. }
  30342. bool InterprocessConnectionServer::beginWaitingForSocket (const int portNumber)
  30343. {
  30344. stop();
  30345. socket = new StreamingSocket();
  30346. if (socket->createListener (portNumber))
  30347. {
  30348. startThread();
  30349. return true;
  30350. }
  30351. socket = 0;
  30352. return false;
  30353. }
  30354. void InterprocessConnectionServer::stop()
  30355. {
  30356. signalThreadShouldExit();
  30357. if (socket != 0)
  30358. socket->close();
  30359. stopThread (4000);
  30360. socket = 0;
  30361. }
  30362. void InterprocessConnectionServer::run()
  30363. {
  30364. while ((! threadShouldExit()) && socket != 0)
  30365. {
  30366. ScopedPointer <StreamingSocket> clientSocket (socket->waitForNextConnection());
  30367. if (clientSocket != 0)
  30368. {
  30369. InterprocessConnection* newConnection = createConnectionObject();
  30370. if (newConnection != 0)
  30371. newConnection->initialiseWithSocket (clientSocket.release());
  30372. }
  30373. }
  30374. }
  30375. END_JUCE_NAMESPACE
  30376. /*** End of inlined file: juce_InterprocessConnectionServer.cpp ***/
  30377. /*** Start of inlined file: juce_Message.cpp ***/
  30378. BEGIN_JUCE_NAMESPACE
  30379. Message::Message() throw()
  30380. {
  30381. }
  30382. Message::~Message() throw()
  30383. {
  30384. }
  30385. Message::Message (const int intParameter1_,
  30386. const int intParameter2_,
  30387. const int intParameter3_,
  30388. void* const pointerParameter_) throw()
  30389. : intParameter1 (intParameter1_),
  30390. intParameter2 (intParameter2_),
  30391. intParameter3 (intParameter3_),
  30392. pointerParameter (pointerParameter_)
  30393. {
  30394. }
  30395. END_JUCE_NAMESPACE
  30396. /*** End of inlined file: juce_Message.cpp ***/
  30397. /*** Start of inlined file: juce_MessageListener.cpp ***/
  30398. BEGIN_JUCE_NAMESPACE
  30399. MessageListener::MessageListener() throw()
  30400. {
  30401. // are you trying to create a messagelistener before or after juce has been intialised??
  30402. jassert (MessageManager::instance != 0);
  30403. if (MessageManager::instance != 0)
  30404. MessageManager::instance->messageListeners.add (this);
  30405. }
  30406. MessageListener::~MessageListener()
  30407. {
  30408. if (MessageManager::instance != 0)
  30409. MessageManager::instance->messageListeners.removeValue (this);
  30410. }
  30411. void MessageListener::postMessage (Message* const message) const throw()
  30412. {
  30413. message->messageRecipient = const_cast <MessageListener*> (this);
  30414. if (MessageManager::instance == 0)
  30415. MessageManager::getInstance();
  30416. MessageManager::instance->postMessageToQueue (message);
  30417. }
  30418. bool MessageListener::isValidMessageListener() const throw()
  30419. {
  30420. return (MessageManager::instance != 0)
  30421. && MessageManager::instance->messageListeners.contains (this);
  30422. }
  30423. END_JUCE_NAMESPACE
  30424. /*** End of inlined file: juce_MessageListener.cpp ***/
  30425. /*** Start of inlined file: juce_MessageManager.cpp ***/
  30426. BEGIN_JUCE_NAMESPACE
  30427. // platform-specific functions..
  30428. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages);
  30429. bool juce_postMessageToSystemQueue (void* message);
  30430. MessageManager* MessageManager::instance = 0;
  30431. static const int quitMessageId = 0xfffff321;
  30432. MessageManager::MessageManager() throw()
  30433. : quitMessagePosted (false),
  30434. quitMessageReceived (false),
  30435. threadWithLock (0)
  30436. {
  30437. messageThreadId = Thread::getCurrentThreadId();
  30438. }
  30439. MessageManager::~MessageManager() throw()
  30440. {
  30441. broadcastListeners = 0;
  30442. doPlatformSpecificShutdown();
  30443. jassert (instance == this);
  30444. instance = 0; // do this last in case this instance is still needed by doPlatformSpecificShutdown()
  30445. }
  30446. MessageManager* MessageManager::getInstance() throw()
  30447. {
  30448. if (instance == 0)
  30449. {
  30450. instance = new MessageManager();
  30451. doPlatformSpecificInitialisation();
  30452. }
  30453. return instance;
  30454. }
  30455. void MessageManager::postMessageToQueue (Message* const message)
  30456. {
  30457. if (quitMessagePosted || ! juce_postMessageToSystemQueue (message))
  30458. delete message;
  30459. }
  30460. CallbackMessage::CallbackMessage() throw() {}
  30461. CallbackMessage::~CallbackMessage() throw() {}
  30462. void CallbackMessage::post()
  30463. {
  30464. if (MessageManager::instance != 0)
  30465. MessageManager::instance->postCallbackMessage (this);
  30466. }
  30467. void MessageManager::postCallbackMessage (Message* const message)
  30468. {
  30469. message->messageRecipient = 0;
  30470. postMessageToQueue (message);
  30471. }
  30472. // not for public use..
  30473. void MessageManager::deliverMessage (void* message)
  30474. {
  30475. const ScopedPointer <Message> m ((Message*) message);
  30476. MessageListener* const recipient = m->messageRecipient;
  30477. JUCE_TRY
  30478. {
  30479. if (messageListeners.contains (recipient))
  30480. {
  30481. recipient->handleMessage (*m);
  30482. }
  30483. else if (recipient == 0)
  30484. {
  30485. if (m->intParameter1 == quitMessageId)
  30486. {
  30487. quitMessageReceived = true;
  30488. }
  30489. else
  30490. {
  30491. CallbackMessage* const cm = dynamic_cast <CallbackMessage*> ((Message*) m);
  30492. if (cm != 0)
  30493. cm->messageCallback();
  30494. }
  30495. }
  30496. }
  30497. JUCE_CATCH_EXCEPTION
  30498. }
  30499. #if ! (JUCE_MAC || JUCE_IPHONE)
  30500. void MessageManager::runDispatchLoop()
  30501. {
  30502. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30503. runDispatchLoopUntil (-1);
  30504. }
  30505. void MessageManager::stopDispatchLoop()
  30506. {
  30507. Message* const m = new Message (quitMessageId, 0, 0, 0);
  30508. m->messageRecipient = 0;
  30509. postMessageToQueue (m);
  30510. quitMessagePosted = true;
  30511. }
  30512. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  30513. {
  30514. jassert (isThisTheMessageThread()); // must only be called by the message thread
  30515. const int64 endTime = Time::currentTimeMillis() + millisecondsToRunFor;
  30516. while ((millisecondsToRunFor < 0 || endTime > Time::currentTimeMillis())
  30517. && ! quitMessageReceived)
  30518. {
  30519. JUCE_TRY
  30520. {
  30521. if (! juce_dispatchNextMessageOnSystemQueue (millisecondsToRunFor >= 0))
  30522. {
  30523. const int msToWait = (int) (endTime - Time::currentTimeMillis());
  30524. if (msToWait > 0)
  30525. Thread::sleep (jmin (5, msToWait));
  30526. }
  30527. }
  30528. JUCE_CATCH_EXCEPTION
  30529. }
  30530. return ! quitMessageReceived;
  30531. }
  30532. #endif
  30533. void MessageManager::deliverBroadcastMessage (const String& value)
  30534. {
  30535. if (broadcastListeners != 0)
  30536. broadcastListeners->sendActionMessage (value);
  30537. }
  30538. void MessageManager::registerBroadcastListener (ActionListener* const listener) throw()
  30539. {
  30540. if (broadcastListeners == 0)
  30541. broadcastListeners = new ActionListenerList();
  30542. broadcastListeners->addActionListener (listener);
  30543. }
  30544. void MessageManager::deregisterBroadcastListener (ActionListener* const listener) throw()
  30545. {
  30546. if (broadcastListeners != 0)
  30547. broadcastListeners->removeActionListener (listener);
  30548. }
  30549. bool MessageManager::isThisTheMessageThread() const throw()
  30550. {
  30551. return Thread::getCurrentThreadId() == messageThreadId;
  30552. }
  30553. void MessageManager::setCurrentThreadAsMessageThread()
  30554. {
  30555. if (messageThreadId != Thread::getCurrentThreadId())
  30556. {
  30557. messageThreadId = Thread::getCurrentThreadId();
  30558. // This is needed on windows to make sure the message window is created by this thread
  30559. doPlatformSpecificShutdown();
  30560. doPlatformSpecificInitialisation();
  30561. }
  30562. }
  30563. bool MessageManager::currentThreadHasLockedMessageManager() const throw()
  30564. {
  30565. const Thread::ThreadID thisThread = Thread::getCurrentThreadId();
  30566. return thisThread == messageThreadId || thisThread == threadWithLock;
  30567. }
  30568. class MessageManagerLock::SharedEvents : public ReferenceCountedObject
  30569. {
  30570. public:
  30571. SharedEvents() {}
  30572. ~SharedEvents() {}
  30573. WaitableEvent lockedEvent, releaseEvent;
  30574. private:
  30575. SharedEvents (const SharedEvents&);
  30576. SharedEvents& operator= (const SharedEvents&);
  30577. };
  30578. class MessageManagerLock::BlockingMessage : public CallbackMessage
  30579. {
  30580. public:
  30581. BlockingMessage (MessageManagerLock::SharedEvents* const events_) : events (events_) {}
  30582. ~BlockingMessage() throw() {}
  30583. void messageCallback()
  30584. {
  30585. events->lockedEvent.signal();
  30586. events->releaseEvent.wait();
  30587. }
  30588. juce_UseDebuggingNewOperator
  30589. private:
  30590. ReferenceCountedObjectPtr <MessageManagerLock::SharedEvents> events;
  30591. BlockingMessage (const BlockingMessage&);
  30592. BlockingMessage& operator= (const BlockingMessage&);
  30593. };
  30594. MessageManagerLock::MessageManagerLock (Thread* const threadToCheck) throw()
  30595. : sharedEvents (0),
  30596. locked (false)
  30597. {
  30598. init (threadToCheck, 0);
  30599. }
  30600. MessageManagerLock::MessageManagerLock (ThreadPoolJob* const jobToCheckForExitSignal) throw()
  30601. : sharedEvents (0),
  30602. locked (false)
  30603. {
  30604. init (0, jobToCheckForExitSignal);
  30605. }
  30606. void MessageManagerLock::init (Thread* const threadToCheck, ThreadPoolJob* const job) throw()
  30607. {
  30608. if (MessageManager::instance != 0)
  30609. {
  30610. if (MessageManager::instance->currentThreadHasLockedMessageManager())
  30611. {
  30612. locked = true; // either we're on the message thread, or this is a re-entrant call.
  30613. }
  30614. else
  30615. {
  30616. if (threadToCheck == 0 && job == 0)
  30617. {
  30618. MessageManager::instance->lockingLock.enter();
  30619. }
  30620. else
  30621. {
  30622. while (! MessageManager::instance->lockingLock.tryEnter())
  30623. {
  30624. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30625. || (job != 0 && job->shouldExit()))
  30626. return;
  30627. Thread::sleep (1);
  30628. }
  30629. }
  30630. sharedEvents = new SharedEvents();
  30631. sharedEvents->incReferenceCount();
  30632. (new BlockingMessage (sharedEvents))->post();
  30633. while (! sharedEvents->lockedEvent.wait (50))
  30634. {
  30635. if ((threadToCheck != 0 && threadToCheck->threadShouldExit())
  30636. || (job != 0 && job->shouldExit()))
  30637. {
  30638. sharedEvents->releaseEvent.signal();
  30639. sharedEvents->decReferenceCount();
  30640. sharedEvents = 0;
  30641. MessageManager::instance->lockingLock.exit();
  30642. return;
  30643. }
  30644. }
  30645. jassert (MessageManager::instance->threadWithLock == 0);
  30646. MessageManager::instance->threadWithLock = Thread::getCurrentThreadId();
  30647. locked = true;
  30648. }
  30649. }
  30650. }
  30651. MessageManagerLock::~MessageManagerLock() throw()
  30652. {
  30653. if (sharedEvents != 0)
  30654. {
  30655. jassert (MessageManager::instance == 0 || MessageManager::instance->currentThreadHasLockedMessageManager());
  30656. sharedEvents->releaseEvent.signal();
  30657. sharedEvents->decReferenceCount();
  30658. if (MessageManager::instance != 0)
  30659. {
  30660. MessageManager::instance->threadWithLock = 0;
  30661. MessageManager::instance->lockingLock.exit();
  30662. }
  30663. }
  30664. }
  30665. END_JUCE_NAMESPACE
  30666. /*** End of inlined file: juce_MessageManager.cpp ***/
  30667. /*** Start of inlined file: juce_MultiTimer.cpp ***/
  30668. BEGIN_JUCE_NAMESPACE
  30669. class MultiTimer::MultiTimerCallback : public Timer
  30670. {
  30671. public:
  30672. MultiTimerCallback (const int timerId_, MultiTimer& owner_)
  30673. : timerId (timerId_),
  30674. owner (owner_)
  30675. {
  30676. }
  30677. ~MultiTimerCallback()
  30678. {
  30679. }
  30680. void timerCallback()
  30681. {
  30682. owner.timerCallback (timerId);
  30683. }
  30684. const int timerId;
  30685. private:
  30686. MultiTimer& owner;
  30687. };
  30688. MultiTimer::MultiTimer() throw()
  30689. {
  30690. }
  30691. MultiTimer::MultiTimer (const MultiTimer&) throw()
  30692. {
  30693. }
  30694. MultiTimer::~MultiTimer()
  30695. {
  30696. const ScopedLock sl (timerListLock);
  30697. timers.clear();
  30698. }
  30699. void MultiTimer::startTimer (const int timerId, const int intervalInMilliseconds) throw()
  30700. {
  30701. const ScopedLock sl (timerListLock);
  30702. for (int i = timers.size(); --i >= 0;)
  30703. {
  30704. MultiTimerCallback* const t = timers.getUnchecked(i);
  30705. if (t->timerId == timerId)
  30706. {
  30707. t->startTimer (intervalInMilliseconds);
  30708. return;
  30709. }
  30710. }
  30711. MultiTimerCallback* const newTimer = new MultiTimerCallback (timerId, *this);
  30712. timers.add (newTimer);
  30713. newTimer->startTimer (intervalInMilliseconds);
  30714. }
  30715. void MultiTimer::stopTimer (const int timerId) throw()
  30716. {
  30717. const ScopedLock sl (timerListLock);
  30718. for (int i = timers.size(); --i >= 0;)
  30719. {
  30720. MultiTimerCallback* const t = timers.getUnchecked(i);
  30721. if (t->timerId == timerId)
  30722. t->stopTimer();
  30723. }
  30724. }
  30725. bool MultiTimer::isTimerRunning (const int timerId) const throw()
  30726. {
  30727. const ScopedLock sl (timerListLock);
  30728. for (int i = timers.size(); --i >= 0;)
  30729. {
  30730. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30731. if (t->timerId == timerId)
  30732. return t->isTimerRunning();
  30733. }
  30734. return false;
  30735. }
  30736. int MultiTimer::getTimerInterval (const int timerId) const throw()
  30737. {
  30738. const ScopedLock sl (timerListLock);
  30739. for (int i = timers.size(); --i >= 0;)
  30740. {
  30741. const MultiTimerCallback* const t = timers.getUnchecked(i);
  30742. if (t->timerId == timerId)
  30743. return t->getTimerInterval();
  30744. }
  30745. return 0;
  30746. }
  30747. END_JUCE_NAMESPACE
  30748. /*** End of inlined file: juce_MultiTimer.cpp ***/
  30749. /*** Start of inlined file: juce_Timer.cpp ***/
  30750. BEGIN_JUCE_NAMESPACE
  30751. class InternalTimerThread : private Thread,
  30752. private MessageListener,
  30753. private DeletedAtShutdown,
  30754. private AsyncUpdater
  30755. {
  30756. public:
  30757. InternalTimerThread()
  30758. : Thread ("Juce Timer"),
  30759. firstTimer (0),
  30760. callbackNeeded (false)
  30761. {
  30762. triggerAsyncUpdate();
  30763. }
  30764. ~InternalTimerThread() throw()
  30765. {
  30766. stopThread (4000);
  30767. jassert (instance == this || instance == 0);
  30768. if (instance == this)
  30769. instance = 0;
  30770. }
  30771. void run()
  30772. {
  30773. uint32 lastTime = Time::getMillisecondCounter();
  30774. while (! threadShouldExit())
  30775. {
  30776. const uint32 now = Time::getMillisecondCounter();
  30777. if (now <= lastTime)
  30778. {
  30779. wait (2);
  30780. continue;
  30781. }
  30782. const int elapsed = now - lastTime;
  30783. lastTime = now;
  30784. int timeUntilFirstTimer = 1000;
  30785. {
  30786. const ScopedLock sl (lock);
  30787. decrementAllCounters (elapsed);
  30788. if (firstTimer != 0)
  30789. timeUntilFirstTimer = firstTimer->countdownMs;
  30790. }
  30791. if (timeUntilFirstTimer <= 0)
  30792. {
  30793. if (callbackNeeded.set (true))
  30794. {
  30795. postMessage (new Message());
  30796. const uint32 messageDeliveryTimeout = now + 2000;
  30797. while (callbackNeeded.get())
  30798. {
  30799. wait (4);
  30800. if (threadShouldExit())
  30801. return;
  30802. if (Time::getMillisecondCounter() > messageDeliveryTimeout)
  30803. break;
  30804. }
  30805. }
  30806. }
  30807. else
  30808. {
  30809. // don't wait for too long because running this loop also helps keep the
  30810. // Time::getApproximateMillisecondTimer value stay up-to-date
  30811. wait (jlimit (1, 50, timeUntilFirstTimer));
  30812. }
  30813. }
  30814. }
  30815. void callTimers()
  30816. {
  30817. const ScopedLock sl (lock);
  30818. while (firstTimer != 0 && firstTimer->countdownMs <= 0)
  30819. {
  30820. Timer* const t = firstTimer;
  30821. t->countdownMs = t->periodMs;
  30822. removeTimer (t);
  30823. addTimer (t);
  30824. const ScopedUnlock ul (lock);
  30825. JUCE_TRY
  30826. {
  30827. t->timerCallback();
  30828. }
  30829. JUCE_CATCH_EXCEPTION
  30830. }
  30831. callbackNeeded.set (false);
  30832. }
  30833. void handleMessage (const Message&)
  30834. {
  30835. callTimers();
  30836. }
  30837. void callTimersSynchronously()
  30838. {
  30839. if (! isThreadRunning())
  30840. {
  30841. // (This is relied on by some plugins in cases where the MM has
  30842. // had to restart and the async callback never started)
  30843. cancelPendingUpdate();
  30844. triggerAsyncUpdate();
  30845. }
  30846. callTimers();
  30847. }
  30848. static void callAnyTimersSynchronously()
  30849. {
  30850. if (InternalTimerThread::instance != 0)
  30851. InternalTimerThread::instance->callTimersSynchronously();
  30852. }
  30853. static inline void add (Timer* const tim) throw()
  30854. {
  30855. if (instance == 0)
  30856. instance = new InternalTimerThread();
  30857. const ScopedLock sl (instance->lock);
  30858. instance->addTimer (tim);
  30859. }
  30860. static inline void remove (Timer* const tim) throw()
  30861. {
  30862. if (instance != 0)
  30863. {
  30864. const ScopedLock sl (instance->lock);
  30865. instance->removeTimer (tim);
  30866. }
  30867. }
  30868. static inline void resetCounter (Timer* const tim,
  30869. const int newCounter) throw()
  30870. {
  30871. if (instance != 0)
  30872. {
  30873. tim->countdownMs = newCounter;
  30874. tim->periodMs = newCounter;
  30875. if ((tim->next != 0 && tim->next->countdownMs < tim->countdownMs)
  30876. || (tim->previous != 0 && tim->previous->countdownMs > tim->countdownMs))
  30877. {
  30878. const ScopedLock sl (instance->lock);
  30879. instance->removeTimer (tim);
  30880. instance->addTimer (tim);
  30881. }
  30882. }
  30883. }
  30884. private:
  30885. friend class Timer;
  30886. static InternalTimerThread* instance;
  30887. static CriticalSection lock;
  30888. Timer* volatile firstTimer;
  30889. class AtomicBool
  30890. {
  30891. public:
  30892. AtomicBool (const bool value) throw() : value (static_cast<int32> (value)) {}
  30893. ~AtomicBool() throw() {}
  30894. bool get() const throw() { return value != 0; }
  30895. bool set (const bool newValue) { return Atomic::compareAndExchange (value, newValue ? 1 : 0, value) != 0; }
  30896. private:
  30897. int32 value;
  30898. AtomicBool (const AtomicBool&);
  30899. AtomicBool& operator= (const AtomicBool&);
  30900. };
  30901. AtomicBool callbackNeeded;
  30902. void addTimer (Timer* const t) throw()
  30903. {
  30904. #ifdef JUCE_DEBUG
  30905. Timer* tt = firstTimer;
  30906. while (tt != 0)
  30907. {
  30908. // trying to add a timer that's already here - shouldn't get to this point,
  30909. // so if you get this assertion, let me know!
  30910. jassert (tt != t);
  30911. tt = tt->next;
  30912. }
  30913. jassert (t->previous == 0 && t->next == 0);
  30914. #endif
  30915. Timer* i = firstTimer;
  30916. if (i == 0 || i->countdownMs > t->countdownMs)
  30917. {
  30918. t->next = firstTimer;
  30919. firstTimer = t;
  30920. }
  30921. else
  30922. {
  30923. while (i->next != 0 && i->next->countdownMs <= t->countdownMs)
  30924. i = i->next;
  30925. jassert (i != 0);
  30926. t->next = i->next;
  30927. t->previous = i;
  30928. i->next = t;
  30929. }
  30930. if (t->next != 0)
  30931. t->next->previous = t;
  30932. jassert ((t->next == 0 || t->next->countdownMs >= t->countdownMs)
  30933. && (t->previous == 0 || t->previous->countdownMs <= t->countdownMs));
  30934. notify();
  30935. }
  30936. void removeTimer (Timer* const t) throw()
  30937. {
  30938. #ifdef JUCE_DEBUG
  30939. Timer* tt = firstTimer;
  30940. bool found = false;
  30941. while (tt != 0)
  30942. {
  30943. if (tt == t)
  30944. {
  30945. found = true;
  30946. break;
  30947. }
  30948. tt = tt->next;
  30949. }
  30950. // trying to remove a timer that's not here - shouldn't get to this point,
  30951. // so if you get this assertion, let me know!
  30952. jassert (found);
  30953. #endif
  30954. if (t->previous != 0)
  30955. {
  30956. jassert (firstTimer != t);
  30957. t->previous->next = t->next;
  30958. }
  30959. else
  30960. {
  30961. jassert (firstTimer == t);
  30962. firstTimer = t->next;
  30963. }
  30964. if (t->next != 0)
  30965. t->next->previous = t->previous;
  30966. t->next = 0;
  30967. t->previous = 0;
  30968. }
  30969. void decrementAllCounters (const int numMillisecs) const
  30970. {
  30971. Timer* t = firstTimer;
  30972. while (t != 0)
  30973. {
  30974. t->countdownMs -= numMillisecs;
  30975. t = t->next;
  30976. }
  30977. }
  30978. void handleAsyncUpdate()
  30979. {
  30980. startThread (7);
  30981. }
  30982. InternalTimerThread (const InternalTimerThread&);
  30983. InternalTimerThread& operator= (const InternalTimerThread&);
  30984. };
  30985. InternalTimerThread* InternalTimerThread::instance = 0;
  30986. CriticalSection InternalTimerThread::lock;
  30987. void juce_callAnyTimersSynchronously()
  30988. {
  30989. InternalTimerThread::callAnyTimersSynchronously();
  30990. }
  30991. #ifdef JUCE_DEBUG
  30992. static SortedSet <Timer*> activeTimers;
  30993. #endif
  30994. Timer::Timer() throw()
  30995. : countdownMs (0),
  30996. periodMs (0),
  30997. previous (0),
  30998. next (0)
  30999. {
  31000. #ifdef JUCE_DEBUG
  31001. activeTimers.add (this);
  31002. #endif
  31003. }
  31004. Timer::Timer (const Timer&) throw()
  31005. : countdownMs (0),
  31006. periodMs (0),
  31007. previous (0),
  31008. next (0)
  31009. {
  31010. #ifdef JUCE_DEBUG
  31011. activeTimers.add (this);
  31012. #endif
  31013. }
  31014. Timer::~Timer()
  31015. {
  31016. stopTimer();
  31017. #ifdef JUCE_DEBUG
  31018. activeTimers.removeValue (this);
  31019. #endif
  31020. }
  31021. void Timer::startTimer (const int interval) throw()
  31022. {
  31023. const ScopedLock sl (InternalTimerThread::lock);
  31024. #ifdef JUCE_DEBUG
  31025. // this isn't a valid object! Your timer might be a dangling pointer or something..
  31026. jassert (activeTimers.contains (this));
  31027. #endif
  31028. if (periodMs == 0)
  31029. {
  31030. countdownMs = interval;
  31031. periodMs = jmax (1, interval);
  31032. InternalTimerThread::add (this);
  31033. }
  31034. else
  31035. {
  31036. InternalTimerThread::resetCounter (this, interval);
  31037. }
  31038. }
  31039. void Timer::stopTimer() throw()
  31040. {
  31041. const ScopedLock sl (InternalTimerThread::lock);
  31042. #ifdef JUCE_DEBUG
  31043. // this isn't a valid object! Your timer might be a dangling pointer or something..
  31044. jassert (activeTimers.contains (this));
  31045. #endif
  31046. if (periodMs > 0)
  31047. {
  31048. InternalTimerThread::remove (this);
  31049. periodMs = 0;
  31050. }
  31051. }
  31052. END_JUCE_NAMESPACE
  31053. /*** End of inlined file: juce_Timer.cpp ***/
  31054. #endif
  31055. #if JUCE_BUILD_GUI
  31056. /*** Start of inlined file: juce_Component.cpp ***/
  31057. BEGIN_JUCE_NAMESPACE
  31058. Component* Component::componentUnderMouse = 0;
  31059. Component* Component::currentlyFocusedComponent = 0;
  31060. static Array <Component*> modalComponentStack, modalComponentReturnValueKeys;
  31061. static Array <int> modalReturnValues;
  31062. static const int customCommandMessage = 0x7fff0001;
  31063. static const int exitModalStateMessage = 0x7fff0002;
  31064. static Point<int> unboundedMouseOffset;
  31065. static bool isUnboundedMouseModeOn = false;
  31066. static bool isCursorVisibleUntilOffscreen;
  31067. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  31068. static uint32 nextComponentUID = 0;
  31069. Component::Component() throw()
  31070. : parentComponent_ (0),
  31071. componentUID (++nextComponentUID),
  31072. numDeepMouseListeners (0),
  31073. lookAndFeel_ (0),
  31074. effect_ (0),
  31075. bufferedImage_ (0),
  31076. mouseListeners_ (0),
  31077. keyListeners_ (0),
  31078. componentListeners_ (0),
  31079. componentFlags_ (0)
  31080. {
  31081. }
  31082. Component::Component (const String& name) throw()
  31083. : componentName_ (name),
  31084. parentComponent_ (0),
  31085. componentUID (++nextComponentUID),
  31086. numDeepMouseListeners (0),
  31087. lookAndFeel_ (0),
  31088. effect_ (0),
  31089. bufferedImage_ (0),
  31090. mouseListeners_ (0),
  31091. keyListeners_ (0),
  31092. componentListeners_ (0),
  31093. componentFlags_ (0)
  31094. {
  31095. }
  31096. Component::~Component()
  31097. {
  31098. if (parentComponent_ != 0)
  31099. {
  31100. parentComponent_->removeChildComponent (this);
  31101. }
  31102. else if ((currentlyFocusedComponent == this)
  31103. || isParentOf (currentlyFocusedComponent))
  31104. {
  31105. giveAwayFocus();
  31106. }
  31107. if (componentUnderMouse == this)
  31108. componentUnderMouse = 0;
  31109. if (flags.hasHeavyweightPeerFlag)
  31110. removeFromDesktop();
  31111. modalComponentStack.removeValue (this);
  31112. for (int i = childComponentList_.size(); --i >= 0;)
  31113. childComponentList_.getUnchecked(i)->parentComponent_ = 0;
  31114. delete bufferedImage_;
  31115. delete mouseListeners_;
  31116. delete keyListeners_;
  31117. delete componentListeners_;
  31118. }
  31119. void Component::setName (const String& name)
  31120. {
  31121. // if component methods are being called from threads other than the message
  31122. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31123. checkMessageManagerIsLocked
  31124. if (componentName_ != name)
  31125. {
  31126. componentName_ = name;
  31127. if (flags.hasHeavyweightPeerFlag)
  31128. {
  31129. ComponentPeer* const peer = getPeer();
  31130. jassert (peer != 0);
  31131. if (peer != 0)
  31132. peer->setTitle (name);
  31133. }
  31134. if (componentListeners_ != 0)
  31135. {
  31136. const ComponentDeletionWatcher deletionChecker (this);
  31137. for (int i = componentListeners_->size(); --i >= 0;)
  31138. {
  31139. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31140. ->componentNameChanged (*this);
  31141. if (deletionChecker.hasBeenDeleted())
  31142. return;
  31143. i = jmin (i, componentListeners_->size());
  31144. }
  31145. }
  31146. }
  31147. }
  31148. void Component::setVisible (bool shouldBeVisible)
  31149. {
  31150. if (flags.visibleFlag != shouldBeVisible)
  31151. {
  31152. // if component methods are being called from threads other than the message
  31153. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31154. checkMessageManagerIsLocked
  31155. const ComponentDeletionWatcher deletionChecker (this);
  31156. flags.visibleFlag = shouldBeVisible;
  31157. internalRepaint (0, 0, getWidth(), getHeight());
  31158. sendFakeMouseMove();
  31159. if (! shouldBeVisible)
  31160. {
  31161. if (currentlyFocusedComponent == this
  31162. || isParentOf (currentlyFocusedComponent))
  31163. {
  31164. if (parentComponent_ != 0)
  31165. parentComponent_->grabKeyboardFocus();
  31166. else
  31167. giveAwayFocus();
  31168. }
  31169. }
  31170. sendVisibilityChangeMessage();
  31171. if ((! deletionChecker.hasBeenDeleted()) && flags.hasHeavyweightPeerFlag)
  31172. {
  31173. ComponentPeer* const peer = getPeer();
  31174. jassert (peer != 0);
  31175. if (peer != 0)
  31176. {
  31177. peer->setVisible (shouldBeVisible);
  31178. internalHierarchyChanged();
  31179. }
  31180. }
  31181. }
  31182. }
  31183. void Component::visibilityChanged()
  31184. {
  31185. }
  31186. void Component::sendVisibilityChangeMessage()
  31187. {
  31188. const ComponentDeletionWatcher deletionChecker (this);
  31189. visibilityChanged();
  31190. if ((! deletionChecker.hasBeenDeleted()) && componentListeners_ != 0)
  31191. {
  31192. for (int i = componentListeners_->size(); --i >= 0;)
  31193. {
  31194. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31195. ->componentVisibilityChanged (*this);
  31196. if (deletionChecker.hasBeenDeleted())
  31197. return;
  31198. i = jmin (i, componentListeners_->size());
  31199. }
  31200. }
  31201. }
  31202. bool Component::isShowing() const throw()
  31203. {
  31204. if (flags.visibleFlag)
  31205. {
  31206. if (parentComponent_ != 0)
  31207. {
  31208. return parentComponent_->isShowing();
  31209. }
  31210. else
  31211. {
  31212. const ComponentPeer* const peer = getPeer();
  31213. return peer != 0 && ! peer->isMinimised();
  31214. }
  31215. }
  31216. return false;
  31217. }
  31218. class FadeOutProxyComponent : public Component,
  31219. public Timer
  31220. {
  31221. public:
  31222. FadeOutProxyComponent (Component* comp,
  31223. const int fadeLengthMs,
  31224. const int deltaXToMove,
  31225. const int deltaYToMove,
  31226. const float scaleFactorAtEnd)
  31227. : lastTime (0),
  31228. alpha (1.0f),
  31229. scale (1.0f)
  31230. {
  31231. image = comp->createComponentSnapshot (Rectangle<int> (0, 0, comp->getWidth(), comp->getHeight()));
  31232. setBounds (comp->getBounds());
  31233. comp->getParentComponent()->addAndMakeVisible (this);
  31234. toBehind (comp);
  31235. alphaChangePerMs = -1.0f / (float)fadeLengthMs;
  31236. centreX = comp->getX() + comp->getWidth() * 0.5f;
  31237. xChangePerMs = deltaXToMove / (float)fadeLengthMs;
  31238. centreY = comp->getY() + comp->getHeight() * 0.5f;
  31239. yChangePerMs = deltaYToMove / (float)fadeLengthMs;
  31240. scaleChangePerMs = (scaleFactorAtEnd - 1.0f) / (float)fadeLengthMs;
  31241. setInterceptsMouseClicks (false, false);
  31242. // 30 fps is enough for a fade, but we need a higher rate if it's moving as well..
  31243. startTimer (1000 / ((deltaXToMove == 0 && deltaYToMove == 0) ? 30 : 50));
  31244. }
  31245. ~FadeOutProxyComponent()
  31246. {
  31247. delete image;
  31248. }
  31249. void paint (Graphics& g)
  31250. {
  31251. g.setOpacity (alpha);
  31252. g.drawImage (image,
  31253. 0, 0, getWidth(), getHeight(),
  31254. 0, 0, image->getWidth(), image->getHeight());
  31255. }
  31256. void timerCallback()
  31257. {
  31258. const uint32 now = Time::getMillisecondCounter();
  31259. if (lastTime == 0)
  31260. lastTime = now;
  31261. const int msPassed = (now > lastTime) ? now - lastTime : 0;
  31262. lastTime = now;
  31263. alpha += alphaChangePerMs * msPassed;
  31264. if (alpha > 0)
  31265. {
  31266. if (xChangePerMs != 0.0f || yChangePerMs != 0.0f || scaleChangePerMs != 0.0f)
  31267. {
  31268. centreX += xChangePerMs * msPassed;
  31269. centreY += yChangePerMs * msPassed;
  31270. scale += scaleChangePerMs * msPassed;
  31271. const int w = roundToInt (image->getWidth() * scale);
  31272. const int h = roundToInt (image->getHeight() * scale);
  31273. setBounds (roundToInt (centreX) - w / 2,
  31274. roundToInt (centreY) - h / 2,
  31275. w, h);
  31276. }
  31277. repaint();
  31278. }
  31279. else
  31280. {
  31281. delete this;
  31282. }
  31283. }
  31284. juce_UseDebuggingNewOperator
  31285. private:
  31286. Image* image;
  31287. uint32 lastTime;
  31288. float alpha, alphaChangePerMs;
  31289. float centreX, xChangePerMs;
  31290. float centreY, yChangePerMs;
  31291. float scale, scaleChangePerMs;
  31292. FadeOutProxyComponent (const FadeOutProxyComponent&);
  31293. FadeOutProxyComponent& operator= (const FadeOutProxyComponent&);
  31294. };
  31295. void Component::fadeOutComponent (const int millisecondsToFade,
  31296. const int deltaXToMove,
  31297. const int deltaYToMove,
  31298. const float scaleFactorAtEnd)
  31299. {
  31300. //xxx won't work for comps without parents
  31301. if (isShowing() && millisecondsToFade > 0)
  31302. new FadeOutProxyComponent (this, millisecondsToFade,
  31303. deltaXToMove, deltaYToMove, scaleFactorAtEnd);
  31304. setVisible (false);
  31305. }
  31306. bool Component::isValidComponent() const throw()
  31307. {
  31308. return (this != 0) && isValidMessageListener();
  31309. }
  31310. void* Component::getWindowHandle() const throw()
  31311. {
  31312. const ComponentPeer* const peer = getPeer();
  31313. if (peer != 0)
  31314. return peer->getNativeHandle();
  31315. return 0;
  31316. }
  31317. void Component::addToDesktop (int styleWanted, void* nativeWindowToAttachTo)
  31318. {
  31319. // if component methods are being called from threads other than the message
  31320. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31321. checkMessageManagerIsLocked
  31322. if (isOpaque())
  31323. styleWanted &= ~ComponentPeer::windowIsSemiTransparent;
  31324. else
  31325. styleWanted |= ComponentPeer::windowIsSemiTransparent;
  31326. int currentStyleFlags = 0;
  31327. // don't use getPeer(), so that we only get the peer that's specifically
  31328. // for this comp, and not for one of its parents.
  31329. ComponentPeer* peer = ComponentPeer::getPeerFor (this);
  31330. if (peer != 0)
  31331. currentStyleFlags = peer->getStyleFlags();
  31332. if (styleWanted != currentStyleFlags || ! flags.hasHeavyweightPeerFlag)
  31333. {
  31334. const ComponentDeletionWatcher deletionChecker (this);
  31335. #if JUCE_LINUX
  31336. // it's wise to give the component a non-zero size before
  31337. // putting it on the desktop, as X windows get confused by this, and
  31338. // a (1, 1) minimum size is enforced here.
  31339. setSize (jmax (1, getWidth()),
  31340. jmax (1, getHeight()));
  31341. #endif
  31342. const Point<int> topLeft (relativePositionToGlobal (Point<int> (0, 0)));
  31343. bool wasFullscreen = false;
  31344. bool wasMinimised = false;
  31345. ComponentBoundsConstrainer* currentConstainer = 0;
  31346. Rectangle<int> oldNonFullScreenBounds;
  31347. if (peer != 0)
  31348. {
  31349. wasFullscreen = peer->isFullScreen();
  31350. wasMinimised = peer->isMinimised();
  31351. currentConstainer = peer->getConstrainer();
  31352. oldNonFullScreenBounds = peer->getNonFullScreenBounds();
  31353. removeFromDesktop();
  31354. setTopLeftPosition (topLeft.getX(), topLeft.getY());
  31355. }
  31356. if (parentComponent_ != 0)
  31357. parentComponent_->removeChildComponent (this);
  31358. if (! deletionChecker.hasBeenDeleted())
  31359. {
  31360. flags.hasHeavyweightPeerFlag = true;
  31361. peer = createNewPeer (styleWanted, nativeWindowToAttachTo);
  31362. Desktop::getInstance().addDesktopComponent (this);
  31363. bounds_.setPosition (topLeft);
  31364. peer->setBounds (topLeft.getX(), topLeft.getY(), getWidth(), getHeight(), false);
  31365. peer->setVisible (isVisible());
  31366. if (wasFullscreen)
  31367. {
  31368. peer->setFullScreen (true);
  31369. peer->setNonFullScreenBounds (oldNonFullScreenBounds);
  31370. }
  31371. if (wasMinimised)
  31372. peer->setMinimised (true);
  31373. if (isAlwaysOnTop())
  31374. peer->setAlwaysOnTop (true);
  31375. peer->setConstrainer (currentConstainer);
  31376. repaint();
  31377. }
  31378. internalHierarchyChanged();
  31379. }
  31380. }
  31381. void Component::removeFromDesktop()
  31382. {
  31383. // if component methods are being called from threads other than the message
  31384. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31385. checkMessageManagerIsLocked
  31386. if (flags.hasHeavyweightPeerFlag)
  31387. {
  31388. ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31389. flags.hasHeavyweightPeerFlag = false;
  31390. jassert (peer != 0);
  31391. delete peer;
  31392. Desktop::getInstance().removeDesktopComponent (this);
  31393. }
  31394. }
  31395. bool Component::isOnDesktop() const throw()
  31396. {
  31397. return flags.hasHeavyweightPeerFlag;
  31398. }
  31399. void Component::userTriedToCloseWindow()
  31400. {
  31401. /* This means that the user's trying to get rid of your window with the 'close window' system
  31402. menu option (on windows) or possibly the task manager - you should really handle this
  31403. and delete or hide your component in an appropriate way.
  31404. If you want to ignore the event and don't want to trigger this assertion, just override
  31405. this method and do nothing.
  31406. */
  31407. jassertfalse
  31408. }
  31409. void Component::minimisationStateChanged (bool)
  31410. {
  31411. }
  31412. void Component::setOpaque (const bool shouldBeOpaque) throw()
  31413. {
  31414. if (shouldBeOpaque != flags.opaqueFlag)
  31415. {
  31416. flags.opaqueFlag = shouldBeOpaque;
  31417. if (flags.hasHeavyweightPeerFlag)
  31418. {
  31419. const ComponentPeer* const peer = ComponentPeer::getPeerFor (this);
  31420. if (peer != 0)
  31421. {
  31422. // to make it recreate the heavyweight window
  31423. addToDesktop (peer->getStyleFlags());
  31424. }
  31425. }
  31426. repaint();
  31427. }
  31428. }
  31429. bool Component::isOpaque() const throw()
  31430. {
  31431. return flags.opaqueFlag;
  31432. }
  31433. void Component::setBufferedToImage (const bool shouldBeBuffered) throw()
  31434. {
  31435. if (shouldBeBuffered != flags.bufferToImageFlag)
  31436. {
  31437. deleteAndZero (bufferedImage_);
  31438. flags.bufferToImageFlag = shouldBeBuffered;
  31439. }
  31440. }
  31441. void Component::toFront (const bool setAsForeground)
  31442. {
  31443. // if component methods are being called from threads other than the message
  31444. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31445. checkMessageManagerIsLocked
  31446. if (flags.hasHeavyweightPeerFlag)
  31447. {
  31448. ComponentPeer* const peer = getPeer();
  31449. if (peer != 0)
  31450. {
  31451. peer->toFront (setAsForeground);
  31452. if (setAsForeground && ! hasKeyboardFocus (true))
  31453. grabKeyboardFocus();
  31454. }
  31455. }
  31456. else if (parentComponent_ != 0)
  31457. {
  31458. if (parentComponent_->childComponentList_.getLast() != this)
  31459. {
  31460. const int index = parentComponent_->childComponentList_.indexOf (this);
  31461. if (index >= 0)
  31462. {
  31463. int insertIndex = -1;
  31464. if (! flags.alwaysOnTopFlag)
  31465. {
  31466. insertIndex = parentComponent_->childComponentList_.size() - 1;
  31467. while (insertIndex > 0
  31468. && parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31469. {
  31470. --insertIndex;
  31471. }
  31472. }
  31473. if (index != insertIndex)
  31474. {
  31475. parentComponent_->childComponentList_.move (index, insertIndex);
  31476. sendFakeMouseMove();
  31477. repaintParent();
  31478. }
  31479. }
  31480. }
  31481. if (setAsForeground)
  31482. {
  31483. internalBroughtToFront();
  31484. grabKeyboardFocus();
  31485. }
  31486. }
  31487. }
  31488. void Component::toBehind (Component* const other)
  31489. {
  31490. if (other != 0)
  31491. {
  31492. // the two components must belong to the same parent..
  31493. jassert (parentComponent_ == other->parentComponent_);
  31494. if (parentComponent_ != 0)
  31495. {
  31496. const int index = parentComponent_->childComponentList_.indexOf (this);
  31497. int otherIndex = parentComponent_->childComponentList_.indexOf (other);
  31498. if (index >= 0
  31499. && otherIndex >= 0
  31500. && index != otherIndex - 1
  31501. && other != this)
  31502. {
  31503. if (index < otherIndex)
  31504. --otherIndex;
  31505. parentComponent_->childComponentList_.move (index, otherIndex);
  31506. sendFakeMouseMove();
  31507. repaintParent();
  31508. }
  31509. }
  31510. else if (isOnDesktop())
  31511. {
  31512. jassert (other->isOnDesktop());
  31513. if (other->isOnDesktop())
  31514. {
  31515. ComponentPeer* const us = getPeer();
  31516. ComponentPeer* const them = other->getPeer();
  31517. jassert (us != 0 && them != 0);
  31518. if (us != 0 && them != 0)
  31519. us->toBehind (them);
  31520. }
  31521. }
  31522. }
  31523. }
  31524. void Component::toBack()
  31525. {
  31526. if (isOnDesktop())
  31527. {
  31528. jassertfalse //xxx need to add this to native window
  31529. }
  31530. else if (parentComponent_ != 0
  31531. && parentComponent_->childComponentList_.getFirst() != this)
  31532. {
  31533. const int index = parentComponent_->childComponentList_.indexOf (this);
  31534. if (index > 0)
  31535. {
  31536. int insertIndex = 0;
  31537. if (flags.alwaysOnTopFlag)
  31538. {
  31539. while (insertIndex < parentComponent_->childComponentList_.size()
  31540. && ! parentComponent_->childComponentList_.getUnchecked (insertIndex)->isAlwaysOnTop())
  31541. {
  31542. ++insertIndex;
  31543. }
  31544. }
  31545. if (index != insertIndex)
  31546. {
  31547. parentComponent_->childComponentList_.move (index, insertIndex);
  31548. sendFakeMouseMove();
  31549. repaintParent();
  31550. }
  31551. }
  31552. }
  31553. }
  31554. void Component::setAlwaysOnTop (const bool shouldStayOnTop)
  31555. {
  31556. if (shouldStayOnTop != flags.alwaysOnTopFlag)
  31557. {
  31558. flags.alwaysOnTopFlag = shouldStayOnTop;
  31559. if (isOnDesktop())
  31560. {
  31561. ComponentPeer* const peer = getPeer();
  31562. jassert (peer != 0);
  31563. if (peer != 0)
  31564. {
  31565. if (! peer->setAlwaysOnTop (shouldStayOnTop))
  31566. {
  31567. // some kinds of peer can't change their always-on-top status, so
  31568. // for these, we'll need to create a new window
  31569. const int oldFlags = peer->getStyleFlags();
  31570. removeFromDesktop();
  31571. addToDesktop (oldFlags);
  31572. }
  31573. }
  31574. }
  31575. if (shouldStayOnTop)
  31576. toFront (false);
  31577. internalHierarchyChanged();
  31578. }
  31579. }
  31580. bool Component::isAlwaysOnTop() const throw()
  31581. {
  31582. return flags.alwaysOnTopFlag;
  31583. }
  31584. int Component::proportionOfWidth (const float proportion) const throw()
  31585. {
  31586. return roundToInt (proportion * bounds_.getWidth());
  31587. }
  31588. int Component::proportionOfHeight (const float proportion) const throw()
  31589. {
  31590. return roundToInt (proportion * bounds_.getHeight());
  31591. }
  31592. int Component::getParentWidth() const throw()
  31593. {
  31594. return (parentComponent_ != 0) ? parentComponent_->getWidth()
  31595. : getParentMonitorArea().getWidth();
  31596. }
  31597. int Component::getParentHeight() const throw()
  31598. {
  31599. return (parentComponent_ != 0) ? parentComponent_->getHeight()
  31600. : getParentMonitorArea().getHeight();
  31601. }
  31602. int Component::getScreenX() const
  31603. {
  31604. return getScreenPosition().getX();
  31605. }
  31606. int Component::getScreenY() const
  31607. {
  31608. return getScreenPosition().getY();
  31609. }
  31610. const Point<int> Component::getScreenPosition() const
  31611. {
  31612. return (parentComponent_ != 0) ? parentComponent_->getScreenPosition() + getPosition()
  31613. : (flags.hasHeavyweightPeerFlag ? getPeer()->getScreenPosition()
  31614. : getPosition());
  31615. }
  31616. const Rectangle<int> Component::getScreenBounds() const
  31617. {
  31618. return bounds_.withPosition (getScreenPosition());
  31619. }
  31620. const Point<int> Component::relativePositionToGlobal (const Point<int>& relativePosition) const
  31621. {
  31622. const Component* c = this;
  31623. Point<int> p (relativePosition);
  31624. do
  31625. {
  31626. if (c->flags.hasHeavyweightPeerFlag)
  31627. return c->getPeer()->relativePositionToGlobal (p);
  31628. p += c->getPosition();
  31629. c = c->parentComponent_;
  31630. }
  31631. while (c != 0);
  31632. return p;
  31633. }
  31634. const Point<int> Component::globalPositionToRelative (const Point<int>& screenPosition) const
  31635. {
  31636. if (flags.hasHeavyweightPeerFlag)
  31637. {
  31638. return getPeer()->globalPositionToRelative (screenPosition);
  31639. }
  31640. else
  31641. {
  31642. if (parentComponent_ != 0)
  31643. return parentComponent_->globalPositionToRelative (screenPosition) - getPosition();
  31644. return screenPosition - getPosition();
  31645. }
  31646. }
  31647. const Point<int> Component::relativePositionToOtherComponent (const Component* const targetComponent, const Point<int>& positionRelativeToThis) const
  31648. {
  31649. Point<int> p (positionRelativeToThis);
  31650. if (targetComponent != 0)
  31651. {
  31652. const Component* c = this;
  31653. do
  31654. {
  31655. if (c == targetComponent)
  31656. return p;
  31657. if (c->flags.hasHeavyweightPeerFlag)
  31658. {
  31659. p = c->getPeer()->relativePositionToGlobal (p);
  31660. break;
  31661. }
  31662. p += c->getPosition();
  31663. c = c->parentComponent_;
  31664. }
  31665. while (c != 0);
  31666. p = targetComponent->globalPositionToRelative (p);
  31667. }
  31668. return p;
  31669. }
  31670. void Component::setBounds (int x, int y, int w, int h)
  31671. {
  31672. // if component methods are being called from threads other than the message
  31673. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31674. checkMessageManagerIsLocked
  31675. if (w < 0) w = 0;
  31676. if (h < 0) h = 0;
  31677. const bool wasResized = (getWidth() != w || getHeight() != h);
  31678. const bool wasMoved = (getX() != x || getY() != y);
  31679. #ifdef JUCE_DEBUG
  31680. // It's a very bad idea to try to resize a window during its paint() method!
  31681. jassert (! (flags.isInsidePaintCall && wasResized && isOnDesktop()));
  31682. #endif
  31683. if (wasMoved || wasResized)
  31684. {
  31685. if (flags.visibleFlag)
  31686. {
  31687. // send a fake mouse move to trigger enter/exit messages if needed..
  31688. sendFakeMouseMove();
  31689. if (! flags.hasHeavyweightPeerFlag)
  31690. repaintParent();
  31691. }
  31692. bounds_.setBounds (x, y, w, h);
  31693. if (wasResized)
  31694. repaint();
  31695. else if (! flags.hasHeavyweightPeerFlag)
  31696. repaintParent();
  31697. if (flags.hasHeavyweightPeerFlag)
  31698. {
  31699. ComponentPeer* const peer = getPeer();
  31700. if (peer != 0)
  31701. {
  31702. if (wasMoved && wasResized)
  31703. peer->setBounds (getX(), getY(), getWidth(), getHeight(), false);
  31704. else if (wasMoved)
  31705. peer->setPosition (getX(), getY());
  31706. else if (wasResized)
  31707. peer->setSize (getWidth(), getHeight());
  31708. }
  31709. }
  31710. sendMovedResizedMessages (wasMoved, wasResized);
  31711. }
  31712. }
  31713. void Component::sendMovedResizedMessages (const bool wasMoved, const bool wasResized)
  31714. {
  31715. JUCE_TRY
  31716. {
  31717. if (wasMoved)
  31718. moved();
  31719. if (wasResized)
  31720. {
  31721. resized();
  31722. for (int i = childComponentList_.size(); --i >= 0;)
  31723. {
  31724. childComponentList_.getUnchecked(i)->parentSizeChanged();
  31725. i = jmin (i, childComponentList_.size());
  31726. }
  31727. }
  31728. if (parentComponent_ != 0)
  31729. parentComponent_->childBoundsChanged (this);
  31730. if (componentListeners_ != 0)
  31731. {
  31732. const ComponentDeletionWatcher deletionChecker (this);
  31733. for (int i = componentListeners_->size(); --i >= 0;)
  31734. {
  31735. ((ComponentListener*) componentListeners_->getUnchecked (i))
  31736. ->componentMovedOrResized (*this, wasMoved, wasResized);
  31737. if (deletionChecker.hasBeenDeleted())
  31738. return;
  31739. i = jmin (i, componentListeners_->size());
  31740. }
  31741. }
  31742. }
  31743. JUCE_CATCH_EXCEPTION
  31744. }
  31745. void Component::setSize (const int w, const int h)
  31746. {
  31747. setBounds (getX(), getY(), w, h);
  31748. }
  31749. void Component::setTopLeftPosition (const int x, const int y)
  31750. {
  31751. setBounds (x, y, getWidth(), getHeight());
  31752. }
  31753. void Component::setTopRightPosition (const int x, const int y)
  31754. {
  31755. setTopLeftPosition (x - getWidth(), y);
  31756. }
  31757. void Component::setBounds (const Rectangle<int>& r)
  31758. {
  31759. setBounds (r.getX(),
  31760. r.getY(),
  31761. r.getWidth(),
  31762. r.getHeight());
  31763. }
  31764. void Component::setBoundsRelative (const float x, const float y,
  31765. const float w, const float h)
  31766. {
  31767. const int pw = getParentWidth();
  31768. const int ph = getParentHeight();
  31769. setBounds (roundToInt (x * pw),
  31770. roundToInt (y * ph),
  31771. roundToInt (w * pw),
  31772. roundToInt (h * ph));
  31773. }
  31774. void Component::setCentrePosition (const int x, const int y)
  31775. {
  31776. setTopLeftPosition (x - getWidth() / 2,
  31777. y - getHeight() / 2);
  31778. }
  31779. void Component::setCentreRelative (const float x, const float y)
  31780. {
  31781. setCentrePosition (roundToInt (getParentWidth() * x),
  31782. roundToInt (getParentHeight() * y));
  31783. }
  31784. void Component::centreWithSize (const int width, const int height)
  31785. {
  31786. setBounds ((getParentWidth() - width) / 2,
  31787. (getParentHeight() - height) / 2,
  31788. width,
  31789. height);
  31790. }
  31791. void Component::setBoundsInset (const BorderSize& borders)
  31792. {
  31793. setBounds (borders.getLeft(),
  31794. borders.getTop(),
  31795. getParentWidth() - (borders.getLeftAndRight()),
  31796. getParentHeight() - (borders.getTopAndBottom()));
  31797. }
  31798. void Component::setBoundsToFit (int x, int y, int width, int height,
  31799. const Justification& justification,
  31800. const bool onlyReduceInSize)
  31801. {
  31802. // it's no good calling this method unless both the component and
  31803. // target rectangle have a finite size.
  31804. jassert (getWidth() > 0 && getHeight() > 0 && width > 0 && height > 0);
  31805. if (getWidth() > 0 && getHeight() > 0
  31806. && width > 0 && height > 0)
  31807. {
  31808. int newW, newH;
  31809. if (onlyReduceInSize && getWidth() <= width && getHeight() <= height)
  31810. {
  31811. newW = getWidth();
  31812. newH = getHeight();
  31813. }
  31814. else
  31815. {
  31816. const double imageRatio = getHeight() / (double) getWidth();
  31817. const double targetRatio = height / (double) width;
  31818. if (imageRatio <= targetRatio)
  31819. {
  31820. newW = width;
  31821. newH = jmin (height, roundToInt (newW * imageRatio));
  31822. }
  31823. else
  31824. {
  31825. newH = height;
  31826. newW = jmin (width, roundToInt (newH / imageRatio));
  31827. }
  31828. }
  31829. if (newW > 0 && newH > 0)
  31830. {
  31831. int newX, newY;
  31832. justification.applyToRectangle (newX, newY, newW, newH,
  31833. x, y, width, height);
  31834. setBounds (newX, newY, newW, newH);
  31835. }
  31836. }
  31837. }
  31838. bool Component::hitTest (int x, int y)
  31839. {
  31840. if (! flags.ignoresMouseClicksFlag)
  31841. return true;
  31842. if (flags.allowChildMouseClicksFlag)
  31843. {
  31844. for (int i = getNumChildComponents(); --i >= 0;)
  31845. {
  31846. Component* const c = getChildComponent (i);
  31847. if (c->isVisible()
  31848. && c->bounds_.contains (x, y)
  31849. && c->hitTest (x - c->getX(),
  31850. y - c->getY()))
  31851. {
  31852. return true;
  31853. }
  31854. }
  31855. }
  31856. return false;
  31857. }
  31858. void Component::setInterceptsMouseClicks (const bool allowClicks,
  31859. const bool allowClicksOnChildComponents) throw()
  31860. {
  31861. flags.ignoresMouseClicksFlag = ! allowClicks;
  31862. flags.allowChildMouseClicksFlag = allowClicksOnChildComponents;
  31863. }
  31864. void Component::getInterceptsMouseClicks (bool& allowsClicksOnThisComponent,
  31865. bool& allowsClicksOnChildComponents) const throw()
  31866. {
  31867. allowsClicksOnThisComponent = ! flags.ignoresMouseClicksFlag;
  31868. allowsClicksOnChildComponents = flags.allowChildMouseClicksFlag;
  31869. }
  31870. bool Component::contains (const int x, const int y)
  31871. {
  31872. if (((unsigned int) x) < (unsigned int) getWidth()
  31873. && ((unsigned int) y) < (unsigned int) getHeight()
  31874. && hitTest (x, y))
  31875. {
  31876. if (parentComponent_ != 0)
  31877. {
  31878. return parentComponent_->contains (x + getX(),
  31879. y + getY());
  31880. }
  31881. else if (flags.hasHeavyweightPeerFlag)
  31882. {
  31883. const ComponentPeer* const peer = getPeer();
  31884. if (peer != 0)
  31885. return peer->contains (x, y, true);
  31886. }
  31887. }
  31888. return false;
  31889. }
  31890. bool Component::reallyContains (int x, int y, const bool returnTrueIfWithinAChild)
  31891. {
  31892. if (! contains (x, y))
  31893. return false;
  31894. Component* p = this;
  31895. while (p->parentComponent_ != 0)
  31896. {
  31897. x += p->getX();
  31898. y += p->getY();
  31899. p = p->parentComponent_;
  31900. }
  31901. const Component* const c = p->getComponentAt (x, y);
  31902. return (c == this) || (returnTrueIfWithinAChild && isParentOf (c));
  31903. }
  31904. Component* Component::getComponentAt (const Point<int>& position)
  31905. {
  31906. return getComponentAt (position.getX(), position.getY());
  31907. }
  31908. Component* Component::getComponentAt (const int x, const int y)
  31909. {
  31910. if (flags.visibleFlag
  31911. && ((unsigned int) x) < (unsigned int) getWidth()
  31912. && ((unsigned int) y) < (unsigned int) getHeight()
  31913. && hitTest (x, y))
  31914. {
  31915. for (int i = childComponentList_.size(); --i >= 0;)
  31916. {
  31917. Component* const child = childComponentList_.getUnchecked(i);
  31918. Component* const c = child->getComponentAt (x - child->getX(),
  31919. y - child->getY());
  31920. if (c != 0)
  31921. return c;
  31922. }
  31923. return this;
  31924. }
  31925. return 0;
  31926. }
  31927. void Component::addChildComponent (Component* const child, int zOrder)
  31928. {
  31929. // if component methods are being called from threads other than the message
  31930. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31931. checkMessageManagerIsLocked
  31932. if (child != 0 && child->parentComponent_ != this)
  31933. {
  31934. if (child->parentComponent_ != 0)
  31935. child->parentComponent_->removeChildComponent (child);
  31936. else
  31937. child->removeFromDesktop();
  31938. child->parentComponent_ = this;
  31939. if (child->isVisible())
  31940. child->repaintParent();
  31941. if (! child->isAlwaysOnTop())
  31942. {
  31943. if (zOrder < 0 || zOrder > childComponentList_.size())
  31944. zOrder = childComponentList_.size();
  31945. while (zOrder > 0)
  31946. {
  31947. if (! childComponentList_.getUnchecked (zOrder - 1)->isAlwaysOnTop())
  31948. break;
  31949. --zOrder;
  31950. }
  31951. }
  31952. childComponentList_.insert (zOrder, child);
  31953. child->internalHierarchyChanged();
  31954. internalChildrenChanged();
  31955. }
  31956. }
  31957. void Component::addAndMakeVisible (Component* const child, int zOrder)
  31958. {
  31959. if (child != 0)
  31960. {
  31961. child->setVisible (true);
  31962. addChildComponent (child, zOrder);
  31963. }
  31964. }
  31965. void Component::removeChildComponent (Component* const child)
  31966. {
  31967. removeChildComponent (childComponentList_.indexOf (child));
  31968. }
  31969. Component* Component::removeChildComponent (const int index)
  31970. {
  31971. // if component methods are being called from threads other than the message
  31972. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  31973. checkMessageManagerIsLocked
  31974. Component* const child = childComponentList_ [index];
  31975. if (child != 0)
  31976. {
  31977. sendFakeMouseMove();
  31978. child->repaintParent();
  31979. childComponentList_.remove (index);
  31980. child->parentComponent_ = 0;
  31981. JUCE_TRY
  31982. {
  31983. if ((currentlyFocusedComponent == child)
  31984. || child->isParentOf (currentlyFocusedComponent))
  31985. {
  31986. // get rid first to force the grabKeyboardFocus to change to us.
  31987. giveAwayFocus();
  31988. grabKeyboardFocus();
  31989. }
  31990. }
  31991. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  31992. catch (const std::exception& e)
  31993. {
  31994. currentlyFocusedComponent = 0;
  31995. Desktop::getInstance().triggerFocusCallback();
  31996. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  31997. }
  31998. catch (...)
  31999. {
  32000. currentlyFocusedComponent = 0;
  32001. Desktop::getInstance().triggerFocusCallback();
  32002. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  32003. }
  32004. #endif
  32005. child->internalHierarchyChanged();
  32006. internalChildrenChanged();
  32007. }
  32008. return child;
  32009. }
  32010. void Component::removeAllChildren()
  32011. {
  32012. for (int i = childComponentList_.size(); --i >= 0;)
  32013. removeChildComponent (i);
  32014. }
  32015. void Component::deleteAllChildren()
  32016. {
  32017. for (int i = childComponentList_.size(); --i >= 0;)
  32018. delete (removeChildComponent (i));
  32019. }
  32020. int Component::getNumChildComponents() const throw()
  32021. {
  32022. return childComponentList_.size();
  32023. }
  32024. Component* Component::getChildComponent (const int index) const throw()
  32025. {
  32026. return childComponentList_ [index];
  32027. }
  32028. int Component::getIndexOfChildComponent (const Component* const child) const throw()
  32029. {
  32030. return childComponentList_.indexOf (const_cast <Component*> (child));
  32031. }
  32032. Component* Component::getTopLevelComponent() const throw()
  32033. {
  32034. const Component* comp = this;
  32035. while (comp->parentComponent_ != 0)
  32036. comp = comp->parentComponent_;
  32037. return (Component*) comp;
  32038. }
  32039. bool Component::isParentOf (const Component* possibleChild) const throw()
  32040. {
  32041. while (possibleChild->isValidComponent())
  32042. {
  32043. possibleChild = possibleChild->parentComponent_;
  32044. if (possibleChild == this)
  32045. return true;
  32046. }
  32047. return false;
  32048. }
  32049. void Component::parentHierarchyChanged()
  32050. {
  32051. }
  32052. void Component::childrenChanged()
  32053. {
  32054. }
  32055. void Component::internalChildrenChanged()
  32056. {
  32057. const ComponentDeletionWatcher deletionChecker (this);
  32058. const bool hasListeners = componentListeners_ != 0;
  32059. childrenChanged();
  32060. if (hasListeners)
  32061. {
  32062. if (deletionChecker.hasBeenDeleted())
  32063. return;
  32064. for (int i = componentListeners_->size(); --i >= 0;)
  32065. {
  32066. ((ComponentListener*) componentListeners_->getUnchecked (i))
  32067. ->componentChildrenChanged (*this);
  32068. if (deletionChecker.hasBeenDeleted())
  32069. return;
  32070. i = jmin (i, componentListeners_->size());
  32071. }
  32072. }
  32073. }
  32074. void Component::internalHierarchyChanged()
  32075. {
  32076. parentHierarchyChanged();
  32077. const ComponentDeletionWatcher deletionChecker (this);
  32078. if (componentListeners_ != 0)
  32079. {
  32080. for (int i = componentListeners_->size(); --i >= 0;)
  32081. {
  32082. ((ComponentListener*) componentListeners_->getUnchecked (i))
  32083. ->componentParentHierarchyChanged (*this);
  32084. if (deletionChecker.hasBeenDeleted())
  32085. return;
  32086. i = jmin (i, componentListeners_->size());
  32087. }
  32088. }
  32089. for (int i = childComponentList_.size(); --i >= 0;)
  32090. {
  32091. childComponentList_.getUnchecked (i)->internalHierarchyChanged();
  32092. // you really shouldn't delete the parent component during a callback telling you
  32093. // that it's changed..
  32094. jassert (! deletionChecker.hasBeenDeleted());
  32095. if (deletionChecker.hasBeenDeleted())
  32096. return;
  32097. i = jmin (i, childComponentList_.size());
  32098. }
  32099. }
  32100. void* Component::runModalLoopCallback (void* userData)
  32101. {
  32102. return (void*) (pointer_sized_int) ((Component*) userData)->runModalLoop();
  32103. }
  32104. int Component::runModalLoop()
  32105. {
  32106. if (! MessageManager::getInstance()->isThisTheMessageThread())
  32107. {
  32108. // use a callback so this can be called from non-gui threads
  32109. return (int) (pointer_sized_int)
  32110. MessageManager::getInstance()
  32111. ->callFunctionOnMessageThread (&runModalLoopCallback, (void*) this);
  32112. }
  32113. Component* const prevFocused = getCurrentlyFocusedComponent();
  32114. ScopedPointer <ComponentDeletionWatcher> deletionChecker;
  32115. if (prevFocused != 0)
  32116. deletionChecker = new ComponentDeletionWatcher (prevFocused);
  32117. if (! isCurrentlyModal())
  32118. enterModalState();
  32119. JUCE_TRY
  32120. {
  32121. while (flags.currentlyModalFlag && flags.visibleFlag)
  32122. {
  32123. if (! MessageManager::getInstance()->runDispatchLoopUntil (20))
  32124. break;
  32125. // check whether this component was deleted during the last message
  32126. if (! isValidMessageListener())
  32127. break;
  32128. }
  32129. }
  32130. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  32131. catch (const std::exception& e)
  32132. {
  32133. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  32134. return 0;
  32135. }
  32136. catch (...)
  32137. {
  32138. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  32139. return 0;
  32140. }
  32141. #endif
  32142. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32143. int returnValue = 0;
  32144. if (modalIndex >= 0)
  32145. {
  32146. modalComponentReturnValueKeys.remove (modalIndex);
  32147. returnValue = modalReturnValues.remove (modalIndex);
  32148. }
  32149. modalComponentStack.removeValue (this);
  32150. if (deletionChecker != 0 && ! deletionChecker->hasBeenDeleted())
  32151. prevFocused->grabKeyboardFocus();
  32152. return returnValue;
  32153. }
  32154. void Component::enterModalState (const bool takeKeyboardFocus_)
  32155. {
  32156. // if component methods are being called from threads other than the message
  32157. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32158. checkMessageManagerIsLocked
  32159. // Check for an attempt to make a component modal when it already is!
  32160. // This can cause nasty problems..
  32161. jassert (! flags.currentlyModalFlag);
  32162. if (! isCurrentlyModal())
  32163. {
  32164. modalComponentStack.add (this);
  32165. modalComponentReturnValueKeys.add (this);
  32166. modalReturnValues.add (0);
  32167. flags.currentlyModalFlag = true;
  32168. setVisible (true);
  32169. if (takeKeyboardFocus_)
  32170. grabKeyboardFocus();
  32171. }
  32172. }
  32173. void Component::exitModalState (const int returnValue)
  32174. {
  32175. if (isCurrentlyModal())
  32176. {
  32177. if (MessageManager::getInstance()->isThisTheMessageThread())
  32178. {
  32179. const int modalIndex = modalComponentReturnValueKeys.indexOf (this);
  32180. if (modalIndex >= 0)
  32181. {
  32182. modalReturnValues.set (modalIndex, returnValue);
  32183. }
  32184. else
  32185. {
  32186. modalComponentReturnValueKeys.add (this);
  32187. modalReturnValues.add (returnValue);
  32188. }
  32189. modalComponentStack.removeValue (this);
  32190. flags.currentlyModalFlag = false;
  32191. bringModalComponentToFront();
  32192. }
  32193. else
  32194. {
  32195. postMessage (new Message (exitModalStateMessage, returnValue, 0, 0));
  32196. }
  32197. }
  32198. }
  32199. bool Component::isCurrentlyModal() const throw()
  32200. {
  32201. return flags.currentlyModalFlag
  32202. && getCurrentlyModalComponent() == this;
  32203. }
  32204. bool Component::isCurrentlyBlockedByAnotherModalComponent() const throw()
  32205. {
  32206. Component* const mc = getCurrentlyModalComponent();
  32207. return mc != 0
  32208. && mc != this
  32209. && (! mc->isParentOf (this))
  32210. && ! mc->canModalEventBeSentToComponent (this);
  32211. }
  32212. int JUCE_CALLTYPE Component::getNumCurrentlyModalComponents() throw()
  32213. {
  32214. return modalComponentStack.size();
  32215. }
  32216. Component* JUCE_CALLTYPE Component::getCurrentlyModalComponent (int index) throw()
  32217. {
  32218. Component* const c = (Component*) (modalComponentStack [modalComponentStack.size() - index - 1]);
  32219. return c->isValidComponent() ? c : 0;
  32220. }
  32221. void Component::bringModalComponentToFront()
  32222. {
  32223. ComponentPeer* lastOne = 0;
  32224. for (int i = 0; i < getNumCurrentlyModalComponents(); ++i)
  32225. {
  32226. Component* const c = getCurrentlyModalComponent (i);
  32227. if (c == 0)
  32228. break;
  32229. ComponentPeer* peer = c->getPeer();
  32230. if (peer != 0 && peer != lastOne)
  32231. {
  32232. if (lastOne == 0)
  32233. {
  32234. peer->toFront (true);
  32235. peer->grabFocus();
  32236. }
  32237. else
  32238. peer->toBehind (lastOne);
  32239. lastOne = peer;
  32240. }
  32241. }
  32242. }
  32243. void Component::setBroughtToFrontOnMouseClick (const bool shouldBeBroughtToFront) throw()
  32244. {
  32245. flags.bringToFrontOnClickFlag = shouldBeBroughtToFront;
  32246. }
  32247. bool Component::isBroughtToFrontOnMouseClick() const throw()
  32248. {
  32249. return flags.bringToFrontOnClickFlag;
  32250. }
  32251. void Component::setMouseCursor (const MouseCursor& cursor) throw()
  32252. {
  32253. cursor_ = cursor;
  32254. if (flags.visibleFlag)
  32255. {
  32256. const Point<int> mousePos (getMouseXYRelative());
  32257. if (flags.draggingFlag || reallyContains (mousePos.getX(), mousePos.getY(), false))
  32258. {
  32259. internalUpdateMouseCursor (false);
  32260. }
  32261. }
  32262. }
  32263. const MouseCursor Component::getMouseCursor()
  32264. {
  32265. return cursor_;
  32266. }
  32267. void Component::updateMouseCursor() const throw()
  32268. {
  32269. sendFakeMouseMove();
  32270. }
  32271. void Component::internalUpdateMouseCursor (bool forcedUpdate) throw()
  32272. {
  32273. ComponentPeer* const peer = getPeer();
  32274. if (peer != 0)
  32275. {
  32276. MouseCursor mc (getLookAndFeel().getMouseCursorFor (*this));
  32277. if (isUnboundedMouseModeOn
  32278. && ((! unboundedMouseOffset.isOrigin()) || ! isCursorVisibleUntilOffscreen))
  32279. {
  32280. mc = MouseCursor::NoCursor;
  32281. forcedUpdate = true;
  32282. }
  32283. static void* currentCursorHandle = 0;
  32284. if (forcedUpdate || mc.getHandle() != currentCursorHandle)
  32285. {
  32286. currentCursorHandle = mc.getHandle();
  32287. mc.showInWindow (peer);
  32288. }
  32289. }
  32290. }
  32291. void Component::setRepaintsOnMouseActivity (const bool shouldRepaint) throw()
  32292. {
  32293. flags.repaintOnMouseActivityFlag = shouldRepaint;
  32294. }
  32295. void Component::repaintParent() throw()
  32296. {
  32297. if (flags.visibleFlag)
  32298. internalRepaint (0, 0, getWidth(), getHeight());
  32299. }
  32300. void Component::repaint() throw()
  32301. {
  32302. repaint (0, 0, getWidth(), getHeight());
  32303. }
  32304. void Component::repaint (const int x, const int y,
  32305. const int w, const int h) throw()
  32306. {
  32307. deleteAndZero (bufferedImage_);
  32308. if (flags.visibleFlag)
  32309. internalRepaint (x, y, w, h);
  32310. }
  32311. void Component::internalRepaint (int x, int y, int w, int h)
  32312. {
  32313. // if component methods are being called from threads other than the message
  32314. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32315. checkMessageManagerIsLocked
  32316. if (x < 0)
  32317. {
  32318. w += x;
  32319. x = 0;
  32320. }
  32321. if (x + w > getWidth())
  32322. w = getWidth() - x;
  32323. if (w > 0)
  32324. {
  32325. if (y < 0)
  32326. {
  32327. h += y;
  32328. y = 0;
  32329. }
  32330. if (y + h > getHeight())
  32331. h = getHeight() - y;
  32332. if (h > 0)
  32333. {
  32334. if (parentComponent_ != 0)
  32335. {
  32336. x += getX();
  32337. y += getY();
  32338. if (parentComponent_->flags.visibleFlag)
  32339. parentComponent_->internalRepaint (x, y, w, h);
  32340. }
  32341. else if (flags.hasHeavyweightPeerFlag)
  32342. {
  32343. ComponentPeer* const peer = getPeer();
  32344. if (peer != 0)
  32345. peer->repaint (x, y, w, h);
  32346. }
  32347. }
  32348. }
  32349. }
  32350. void Component::paintEntireComponent (Graphics& originalContext)
  32351. {
  32352. jassert (! originalContext.isClipEmpty());
  32353. #ifdef JUCE_DEBUG
  32354. flags.isInsidePaintCall = true;
  32355. #endif
  32356. Graphics* g = &originalContext;
  32357. Image* effectImage = 0;
  32358. if (effect_ != 0)
  32359. {
  32360. effectImage = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32361. getWidth(), getHeight(),
  32362. ! flags.opaqueFlag);
  32363. g = new Graphics (*effectImage);
  32364. }
  32365. g->saveState();
  32366. clipObscuredRegions (*g, g->getClipBounds(), 0, 0);
  32367. if (! g->isClipEmpty())
  32368. {
  32369. if (bufferedImage_ != 0)
  32370. {
  32371. g->setColour (Colours::black);
  32372. g->drawImageAt (bufferedImage_, 0, 0);
  32373. }
  32374. else
  32375. {
  32376. if (flags.bufferToImageFlag)
  32377. {
  32378. if (bufferedImage_ == 0)
  32379. {
  32380. bufferedImage_ = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32381. getWidth(), getHeight(), ! flags.opaqueFlag);
  32382. Graphics imG (*bufferedImage_);
  32383. paint (imG);
  32384. }
  32385. g->setColour (Colours::black);
  32386. g->drawImageAt (bufferedImage_, 0, 0);
  32387. }
  32388. else
  32389. {
  32390. paint (*g);
  32391. g->resetToDefaultState();
  32392. }
  32393. }
  32394. }
  32395. g->restoreState();
  32396. for (int i = 0; i < childComponentList_.size(); ++i)
  32397. {
  32398. Component* const child = childComponentList_.getUnchecked (i);
  32399. if (child->isVisible())
  32400. {
  32401. g->saveState();
  32402. if (g->reduceClipRegion (child->getX(), child->getY(),
  32403. child->getWidth(), child->getHeight()))
  32404. {
  32405. for (int j = i + 1; j < childComponentList_.size(); ++j)
  32406. {
  32407. const Component* const sibling = childComponentList_.getUnchecked (j);
  32408. if (sibling->flags.opaqueFlag && sibling->isVisible())
  32409. g->excludeClipRegion (sibling->getX(), sibling->getY(),
  32410. sibling->getWidth(), sibling->getHeight());
  32411. }
  32412. if (! g->isClipEmpty())
  32413. {
  32414. g->setOrigin (child->getX(), child->getY());
  32415. child->paintEntireComponent (*g);
  32416. }
  32417. }
  32418. g->restoreState();
  32419. }
  32420. }
  32421. JUCE_TRY
  32422. {
  32423. g->saveState();
  32424. paintOverChildren (*g);
  32425. g->restoreState();
  32426. }
  32427. JUCE_CATCH_EXCEPTION
  32428. if (effect_ != 0)
  32429. {
  32430. delete g;
  32431. effect_->applyEffect (*effectImage, originalContext);
  32432. delete effectImage;
  32433. }
  32434. #ifdef JUCE_DEBUG
  32435. flags.isInsidePaintCall = false;
  32436. #endif
  32437. }
  32438. Image* Component::createComponentSnapshot (const Rectangle<int>& areaToGrab,
  32439. const bool clipImageToComponentBounds)
  32440. {
  32441. Rectangle<int> r (areaToGrab);
  32442. if (clipImageToComponentBounds)
  32443. r = r.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  32444. Image* const componentImage = Image::createNativeImage (flags.opaqueFlag ? Image::RGB : Image::ARGB,
  32445. jmax (1, r.getWidth()),
  32446. jmax (1, r.getHeight()),
  32447. true);
  32448. Graphics imageContext (*componentImage);
  32449. imageContext.setOrigin (-r.getX(),
  32450. -r.getY());
  32451. paintEntireComponent (imageContext);
  32452. return componentImage;
  32453. }
  32454. void Component::setComponentEffect (ImageEffectFilter* const effect)
  32455. {
  32456. if (effect_ != effect)
  32457. {
  32458. effect_ = effect;
  32459. repaint();
  32460. }
  32461. }
  32462. LookAndFeel& Component::getLookAndFeel() const throw()
  32463. {
  32464. const Component* c = this;
  32465. do
  32466. {
  32467. if (c->lookAndFeel_ != 0)
  32468. return *(c->lookAndFeel_);
  32469. c = c->parentComponent_;
  32470. }
  32471. while (c != 0);
  32472. return LookAndFeel::getDefaultLookAndFeel();
  32473. }
  32474. void Component::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  32475. {
  32476. if (lookAndFeel_ != newLookAndFeel)
  32477. {
  32478. lookAndFeel_ = newLookAndFeel;
  32479. sendLookAndFeelChange();
  32480. }
  32481. }
  32482. void Component::lookAndFeelChanged()
  32483. {
  32484. }
  32485. void Component::sendLookAndFeelChange()
  32486. {
  32487. repaint();
  32488. lookAndFeelChanged();
  32489. // (it's not a great idea to do anything that would delete this component
  32490. // during the lookAndFeelChanged() callback)
  32491. jassert (isValidComponent());
  32492. const ComponentDeletionWatcher deletionChecker (this);
  32493. for (int i = childComponentList_.size(); --i >= 0;)
  32494. {
  32495. childComponentList_.getUnchecked (i)->sendLookAndFeelChange();
  32496. if (deletionChecker.hasBeenDeleted())
  32497. return;
  32498. i = jmin (i, childComponentList_.size());
  32499. }
  32500. }
  32501. static const var::identifier getColourPropertyId (const int colourId)
  32502. {
  32503. String s;
  32504. s.preallocateStorage (18);
  32505. s << T("jcclr_") << colourId;
  32506. return s;
  32507. }
  32508. const Colour Component::findColour (const int colourId, const bool inheritFromParent) const throw()
  32509. {
  32510. var* v = properties.getItem (getColourPropertyId (colourId));
  32511. if (v != 0)
  32512. return Colour ((int) *v);
  32513. if (inheritFromParent && parentComponent_ != 0)
  32514. return parentComponent_->findColour (colourId, true);
  32515. return getLookAndFeel().findColour (colourId);
  32516. }
  32517. bool Component::isColourSpecified (const int colourId) const throw()
  32518. {
  32519. return properties.contains (getColourPropertyId (colourId));
  32520. }
  32521. void Component::removeColour (const int colourId)
  32522. {
  32523. if (properties.remove (getColourPropertyId (colourId)))
  32524. colourChanged();
  32525. }
  32526. void Component::setColour (const int colourId, const Colour& colour)
  32527. {
  32528. if (properties.set (getColourPropertyId (colourId), (int) colour.getARGB()))
  32529. colourChanged();
  32530. }
  32531. void Component::copyAllExplicitColoursTo (Component& target) const throw()
  32532. {
  32533. bool changed = false;
  32534. for (int i = properties.size(); --i >= 0;)
  32535. {
  32536. const var::identifier name (properties.getName(i));
  32537. if (name.name.startsWith (T("jcclr_")))
  32538. if (target.properties.set (name, properties [name]))
  32539. changed = true;
  32540. }
  32541. if (changed)
  32542. target.colourChanged();
  32543. }
  32544. void Component::colourChanged()
  32545. {
  32546. }
  32547. const Rectangle<int> Component::getUnclippedArea() const
  32548. {
  32549. int x = 0, y = 0, w = getWidth(), h = getHeight();
  32550. Component* p = parentComponent_;
  32551. int px = getX();
  32552. int py = getY();
  32553. while (p != 0)
  32554. {
  32555. if (! Rectangle<int>::intersectRectangles (x, y, w, h, -px, -py, p->getWidth(), p->getHeight()))
  32556. return Rectangle<int>();
  32557. px += p->getX();
  32558. py += p->getY();
  32559. p = p->parentComponent_;
  32560. }
  32561. return Rectangle<int> (x, y, w, h);
  32562. }
  32563. void Component::clipObscuredRegions (Graphics& g, const Rectangle<int>& clipRect,
  32564. const int deltaX, const int deltaY) const throw()
  32565. {
  32566. for (int i = childComponentList_.size(); --i >= 0;)
  32567. {
  32568. const Component* const c = childComponentList_.getUnchecked(i);
  32569. if (c->isVisible())
  32570. {
  32571. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32572. if (! newClip.isEmpty())
  32573. {
  32574. if (c->isOpaque())
  32575. {
  32576. g.excludeClipRegion (deltaX + newClip.getX(),
  32577. deltaY + newClip.getY(),
  32578. newClip.getWidth(),
  32579. newClip.getHeight());
  32580. }
  32581. else
  32582. {
  32583. newClip.translate (-c->getX(), -c->getY());
  32584. c->clipObscuredRegions (g, newClip,
  32585. c->getX() + deltaX,
  32586. c->getY() + deltaY);
  32587. }
  32588. }
  32589. }
  32590. }
  32591. }
  32592. void Component::getVisibleArea (RectangleList& result,
  32593. const bool includeSiblings) const
  32594. {
  32595. result.clear();
  32596. const Rectangle<int> unclipped (getUnclippedArea());
  32597. if (! unclipped.isEmpty())
  32598. {
  32599. result.add (unclipped);
  32600. if (includeSiblings)
  32601. {
  32602. const Component* const c = getTopLevelComponent();
  32603. c->subtractObscuredRegions (result, c->relativePositionToOtherComponent (this, Point<int>()),
  32604. Rectangle<int> (0, 0, c->getWidth(), c->getHeight()),
  32605. this);
  32606. }
  32607. subtractObscuredRegions (result, Point<int>(), unclipped, 0);
  32608. result.consolidate();
  32609. }
  32610. }
  32611. void Component::subtractObscuredRegions (RectangleList& result,
  32612. const Point<int>& delta,
  32613. const Rectangle<int>& clipRect,
  32614. const Component* const compToAvoid) const throw()
  32615. {
  32616. for (int i = childComponentList_.size(); --i >= 0;)
  32617. {
  32618. const Component* const c = childComponentList_.getUnchecked(i);
  32619. if (c != compToAvoid && c->isVisible())
  32620. {
  32621. if (c->isOpaque())
  32622. {
  32623. Rectangle<int> childBounds (c->bounds_.getIntersection (clipRect));
  32624. childBounds.translate (delta.getX(), delta.getY());
  32625. result.subtract (childBounds);
  32626. }
  32627. else
  32628. {
  32629. Rectangle<int> newClip (clipRect.getIntersection (c->bounds_));
  32630. newClip.translate (-c->getX(), -c->getY());
  32631. c->subtractObscuredRegions (result, c->getPosition() + delta,
  32632. newClip, compToAvoid);
  32633. }
  32634. }
  32635. }
  32636. }
  32637. void Component::mouseEnter (const MouseEvent&)
  32638. {
  32639. // base class does nothing
  32640. }
  32641. void Component::mouseExit (const MouseEvent&)
  32642. {
  32643. // base class does nothing
  32644. }
  32645. void Component::mouseDown (const MouseEvent&)
  32646. {
  32647. // base class does nothing
  32648. }
  32649. void Component::mouseUp (const MouseEvent&)
  32650. {
  32651. // base class does nothing
  32652. }
  32653. void Component::mouseDrag (const MouseEvent&)
  32654. {
  32655. // base class does nothing
  32656. }
  32657. void Component::mouseMove (const MouseEvent&)
  32658. {
  32659. // base class does nothing
  32660. }
  32661. void Component::mouseDoubleClick (const MouseEvent&)
  32662. {
  32663. // base class does nothing
  32664. }
  32665. void Component::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  32666. {
  32667. // the base class just passes this event up to its parent..
  32668. if (parentComponent_ != 0)
  32669. parentComponent_->mouseWheelMove (e.getEventRelativeTo (parentComponent_),
  32670. wheelIncrementX, wheelIncrementY);
  32671. }
  32672. void Component::resized()
  32673. {
  32674. // base class does nothing
  32675. }
  32676. void Component::moved()
  32677. {
  32678. // base class does nothing
  32679. }
  32680. void Component::childBoundsChanged (Component*)
  32681. {
  32682. // base class does nothing
  32683. }
  32684. void Component::parentSizeChanged()
  32685. {
  32686. // base class does nothing
  32687. }
  32688. void Component::addComponentListener (ComponentListener* const newListener) throw()
  32689. {
  32690. if (componentListeners_ == 0)
  32691. componentListeners_ = new VoidArray();
  32692. componentListeners_->addIfNotAlreadyThere (newListener);
  32693. }
  32694. void Component::removeComponentListener (ComponentListener* const listenerToRemove) throw()
  32695. {
  32696. jassert (isValidComponent());
  32697. if (componentListeners_ != 0)
  32698. componentListeners_->removeValue (listenerToRemove);
  32699. }
  32700. void Component::inputAttemptWhenModal()
  32701. {
  32702. bringModalComponentToFront();
  32703. getLookAndFeel().playAlertSound();
  32704. }
  32705. bool Component::canModalEventBeSentToComponent (const Component*)
  32706. {
  32707. return false;
  32708. }
  32709. void Component::internalModalInputAttempt()
  32710. {
  32711. Component* const current = getCurrentlyModalComponent();
  32712. if (current != 0)
  32713. current->inputAttemptWhenModal();
  32714. }
  32715. void Component::paint (Graphics&)
  32716. {
  32717. // all painting is done in the subclasses
  32718. jassert (! isOpaque()); // if your component's opaque, you've gotta paint it!
  32719. }
  32720. void Component::paintOverChildren (Graphics&)
  32721. {
  32722. // all painting is done in the subclasses
  32723. }
  32724. void Component::handleMessage (const Message& message)
  32725. {
  32726. if (message.intParameter1 == exitModalStateMessage)
  32727. {
  32728. exitModalState (message.intParameter2);
  32729. }
  32730. else if (message.intParameter1 == customCommandMessage)
  32731. {
  32732. handleCommandMessage (message.intParameter2);
  32733. }
  32734. }
  32735. void Component::postCommandMessage (const int commandId) throw()
  32736. {
  32737. postMessage (new Message (customCommandMessage, commandId, 0, 0));
  32738. }
  32739. void Component::handleCommandMessage (int)
  32740. {
  32741. // used by subclasses
  32742. }
  32743. void Component::addMouseListener (MouseListener* const newListener,
  32744. const bool wantsEventsForAllNestedChildComponents) throw()
  32745. {
  32746. // if component methods are being called from threads other than the message
  32747. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32748. checkMessageManagerIsLocked
  32749. if (mouseListeners_ == 0)
  32750. mouseListeners_ = new VoidArray();
  32751. if (! mouseListeners_->contains (newListener))
  32752. {
  32753. if (wantsEventsForAllNestedChildComponents)
  32754. {
  32755. mouseListeners_->insert (0, newListener);
  32756. ++numDeepMouseListeners;
  32757. }
  32758. else
  32759. {
  32760. mouseListeners_->add (newListener);
  32761. }
  32762. }
  32763. }
  32764. void Component::removeMouseListener (MouseListener* const listenerToRemove) throw()
  32765. {
  32766. // if component methods are being called from threads other than the message
  32767. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  32768. checkMessageManagerIsLocked
  32769. if (mouseListeners_ != 0)
  32770. {
  32771. const int index = mouseListeners_->indexOf (listenerToRemove);
  32772. if (index >= 0)
  32773. {
  32774. if (index < numDeepMouseListeners)
  32775. --numDeepMouseListeners;
  32776. mouseListeners_->remove (index);
  32777. }
  32778. }
  32779. }
  32780. void Component::internalMouseEnter (int x, int y, int64 time)
  32781. {
  32782. if (isCurrentlyBlockedByAnotherModalComponent())
  32783. {
  32784. // if something else is modal, always just show a normal mouse cursor
  32785. if (componentUnderMouse == this)
  32786. {
  32787. ComponentPeer* const peer = getPeer();
  32788. if (peer != 0)
  32789. {
  32790. MouseCursor mc (MouseCursor::NormalCursor);
  32791. mc.showInWindow (peer);
  32792. }
  32793. }
  32794. return;
  32795. }
  32796. if (isValidComponent() && ! flags.mouseInsideFlag)
  32797. {
  32798. flags.mouseInsideFlag = true;
  32799. flags.mouseOverFlag = true;
  32800. flags.draggingFlag = false;
  32801. const ComponentDeletionWatcher deletionChecker (this);
  32802. if (flags.repaintOnMouseActivityFlag)
  32803. repaint();
  32804. const MouseEvent me (Point<int> (x, y),
  32805. ModifierKeys::getCurrentModifiers(),
  32806. this,
  32807. Time (time),
  32808. Point<int> (x, y),
  32809. Time (time),
  32810. 0, false);
  32811. mouseEnter (me);
  32812. if (deletionChecker.hasBeenDeleted())
  32813. return;
  32814. Desktop::getInstance().resetTimer();
  32815. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32816. {
  32817. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseEnter (me);
  32818. if (deletionChecker.hasBeenDeleted())
  32819. return;
  32820. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32821. }
  32822. if (mouseListeners_ != 0)
  32823. {
  32824. for (int i = mouseListeners_->size(); --i >= 0;)
  32825. {
  32826. ((MouseListener*) mouseListeners_->getUnchecked(i))->mouseEnter (me);
  32827. if (deletionChecker.hasBeenDeleted())
  32828. return;
  32829. i = jmin (i, mouseListeners_->size());
  32830. }
  32831. }
  32832. const Component* p = parentComponent_;
  32833. while (p != 0)
  32834. {
  32835. const ComponentDeletionWatcher parentDeletionChecker (p);
  32836. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32837. {
  32838. ((MouseListener*) (p->mouseListeners_->getUnchecked(i)))->mouseEnter (me);
  32839. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  32840. return;
  32841. i = jmin (i, p->numDeepMouseListeners);
  32842. }
  32843. p = p->parentComponent_;
  32844. }
  32845. }
  32846. if (componentUnderMouse == this)
  32847. internalUpdateMouseCursor (true);
  32848. }
  32849. void Component::internalMouseExit (int x, int y, int64 time)
  32850. {
  32851. const ComponentDeletionWatcher deletionChecker (this);
  32852. if (flags.draggingFlag)
  32853. {
  32854. internalMouseUp (ModifierKeys::getCurrentModifiers().getRawFlags(), x, y, time);
  32855. if (deletionChecker.hasBeenDeleted())
  32856. return;
  32857. }
  32858. enableUnboundedMouseMovement (false);
  32859. if (flags.mouseInsideFlag || flags.mouseOverFlag)
  32860. {
  32861. flags.mouseInsideFlag = false;
  32862. flags.mouseOverFlag = false;
  32863. flags.draggingFlag = false;
  32864. if (flags.repaintOnMouseActivityFlag)
  32865. repaint();
  32866. const MouseEvent me (Point<int> (x, y),
  32867. ModifierKeys::getCurrentModifiers(),
  32868. this,
  32869. Time (time),
  32870. Point<int> (x, y),
  32871. Time (time),
  32872. 0, false);
  32873. mouseExit (me);
  32874. if (deletionChecker.hasBeenDeleted())
  32875. return;
  32876. Desktop::getInstance().resetTimer();
  32877. for (int i = Desktop::getInstance().mouseListeners.size(); --i >= 0;)
  32878. {
  32879. ((MouseListener*) Desktop::getInstance().mouseListeners[i])->mouseExit (me);
  32880. if (deletionChecker.hasBeenDeleted())
  32881. return;
  32882. i = jmin (i, Desktop::getInstance().mouseListeners.size());
  32883. }
  32884. if (mouseListeners_ != 0)
  32885. {
  32886. for (int i = mouseListeners_->size(); --i >= 0;)
  32887. {
  32888. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseExit (me);
  32889. if (deletionChecker.hasBeenDeleted())
  32890. return;
  32891. i = jmin (i, mouseListeners_->size());
  32892. }
  32893. }
  32894. const Component* p = parentComponent_;
  32895. while (p != 0)
  32896. {
  32897. const ComponentDeletionWatcher parentDeletionChecker (p);
  32898. for (int i = p->numDeepMouseListeners; --i >= 0;)
  32899. {
  32900. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseExit (me);
  32901. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  32902. return;
  32903. i = jmin (i, p->numDeepMouseListeners);
  32904. }
  32905. p = p->parentComponent_;
  32906. }
  32907. }
  32908. }
  32909. class InternalDragRepeater : public Timer
  32910. {
  32911. public:
  32912. InternalDragRepeater() {}
  32913. ~InternalDragRepeater() {}
  32914. void timerCallback()
  32915. {
  32916. Component* const c = Component::getComponentUnderMouse();
  32917. if (c != 0 && c->isMouseButtonDown())
  32918. {
  32919. const Point<int> mousePos (c->getMouseXYRelative());
  32920. // the offsets have been added on, so must be taken off before calling the
  32921. // drag.. otherwise they'll be added twice
  32922. c->internalMouseDrag (mousePos.getX() - unboundedMouseOffset.getX(),
  32923. mousePos.getY() - unboundedMouseOffset.getY(),
  32924. Time::currentTimeMillis());
  32925. }
  32926. }
  32927. juce_UseDebuggingNewOperator
  32928. private:
  32929. InternalDragRepeater (const InternalDragRepeater&);
  32930. InternalDragRepeater& operator= (const InternalDragRepeater&);
  32931. };
  32932. static InternalDragRepeater* dragRepeater = 0;
  32933. void Component::beginDragAutoRepeat (const int interval)
  32934. {
  32935. if (interval > 0)
  32936. {
  32937. if (dragRepeater == 0)
  32938. dragRepeater = new InternalDragRepeater();
  32939. if (dragRepeater->getTimerInterval() != interval)
  32940. dragRepeater->startTimer (interval);
  32941. }
  32942. else
  32943. {
  32944. deleteAndZero (dragRepeater);
  32945. }
  32946. }
  32947. void Component::internalMouseDown (const int x, const int y, const int64 time)
  32948. {
  32949. Desktop& desktop = Desktop::getInstance();
  32950. desktop.registerMouseDown (relativePositionToGlobal (Point<int> (x, y)), time, this);
  32951. const ComponentDeletionWatcher deletionChecker (this);
  32952. if (isCurrentlyBlockedByAnotherModalComponent())
  32953. {
  32954. internalModalInputAttempt();
  32955. if (deletionChecker.hasBeenDeleted())
  32956. return;
  32957. // If processing the input attempt has exited the modal loop, we'll allow the event
  32958. // to be delivered..
  32959. if (isCurrentlyBlockedByAnotherModalComponent())
  32960. {
  32961. // allow blocked mouse-events to go to global listeners..
  32962. const MouseEvent me (Point<int> (x, y),
  32963. ModifierKeys::getCurrentModifiers(),
  32964. this,
  32965. Time (time),
  32966. Point<int> (x, y),
  32967. desktop.getLastMouseDownTime(),
  32968. desktop.getNumberOfMultipleClicks(),
  32969. false);
  32970. desktop.resetTimer();
  32971. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  32972. {
  32973. ((MouseListener*) desktop.mouseListeners[i])->mouseDown (me);
  32974. if (deletionChecker.hasBeenDeleted())
  32975. return;
  32976. i = jmin (i, desktop.mouseListeners.size());
  32977. }
  32978. return;
  32979. }
  32980. }
  32981. {
  32982. Component* c = this;
  32983. while (c != 0)
  32984. {
  32985. if (c->isBroughtToFrontOnMouseClick())
  32986. {
  32987. c->toFront (true);
  32988. if (deletionChecker.hasBeenDeleted())
  32989. return;
  32990. }
  32991. c = c->parentComponent_;
  32992. }
  32993. }
  32994. if (! flags.dontFocusOnMouseClickFlag)
  32995. grabFocusInternal (focusChangedByMouseClick);
  32996. if (! deletionChecker.hasBeenDeleted())
  32997. {
  32998. flags.draggingFlag = true;
  32999. flags.mouseOverFlag = true;
  33000. if (flags.repaintOnMouseActivityFlag)
  33001. repaint();
  33002. const MouseEvent me (Point<int> (x, y),
  33003. ModifierKeys::getCurrentModifiers(),
  33004. this,
  33005. desktop.getLastMouseDownTime(),
  33006. Point<int> (x, y),
  33007. desktop.getLastMouseDownTime(),
  33008. desktop.getNumberOfMultipleClicks(),
  33009. false);
  33010. mouseDown (me);
  33011. if (deletionChecker.hasBeenDeleted())
  33012. return;
  33013. desktop.resetTimer();
  33014. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33015. {
  33016. ((MouseListener*) desktop.mouseListeners[i])->mouseDown (me);
  33017. if (deletionChecker.hasBeenDeleted())
  33018. return;
  33019. i = jmin (i, desktop.mouseListeners.size());
  33020. }
  33021. if (mouseListeners_ != 0)
  33022. {
  33023. for (int i = mouseListeners_->size(); --i >= 0;)
  33024. {
  33025. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDown (me);
  33026. if (deletionChecker.hasBeenDeleted())
  33027. return;
  33028. i = jmin (i, mouseListeners_->size());
  33029. }
  33030. }
  33031. const Component* p = parentComponent_;
  33032. while (p != 0)
  33033. {
  33034. const ComponentDeletionWatcher parentDeletionChecker (p);
  33035. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33036. {
  33037. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDown (me);
  33038. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33039. return;
  33040. i = jmin (i, p->numDeepMouseListeners);
  33041. }
  33042. p = p->parentComponent_;
  33043. }
  33044. }
  33045. }
  33046. void Component::internalMouseUp (const int oldModifiers, int x, int y, const int64 time)
  33047. {
  33048. if (isValidComponent() && flags.draggingFlag)
  33049. {
  33050. Desktop& desktop = Desktop::getInstance();
  33051. flags.draggingFlag = false;
  33052. deleteAndZero (dragRepeater);
  33053. x += unboundedMouseOffset.getX();
  33054. y += unboundedMouseOffset.getY();
  33055. desktop.registerMouseDrag (relativePositionToGlobal (Point<int> (x, y)));
  33056. const ComponentDeletionWatcher deletionChecker (this);
  33057. if (flags.repaintOnMouseActivityFlag)
  33058. repaint();
  33059. const Point<int> mouseDownPos (globalPositionToRelative (Desktop::getLastMouseDownPosition()));
  33060. const Time lastMouseDownTime (desktop.getLastMouseDownTime());
  33061. const MouseEvent me (Point<int> (x, y),
  33062. oldModifiers,
  33063. this,
  33064. Time (time),
  33065. mouseDownPos,
  33066. lastMouseDownTime,
  33067. desktop.getNumberOfMultipleClicks(),
  33068. desktop.mouseMovedSignificantlySincePressed
  33069. || time > lastMouseDownTime.toMilliseconds() + 300);
  33070. mouseUp (me);
  33071. if (deletionChecker.hasBeenDeleted())
  33072. return;
  33073. desktop.resetTimer();
  33074. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33075. {
  33076. ((MouseListener*) desktop.mouseListeners[i])->mouseUp (me);
  33077. if (deletionChecker.hasBeenDeleted())
  33078. return;
  33079. i = jmin (i, desktop.mouseListeners.size());
  33080. }
  33081. if (mouseListeners_ != 0)
  33082. {
  33083. for (int i = mouseListeners_->size(); --i >= 0;)
  33084. {
  33085. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseUp (me);
  33086. if (deletionChecker.hasBeenDeleted())
  33087. return;
  33088. i = jmin (i, mouseListeners_->size());
  33089. }
  33090. }
  33091. {
  33092. const Component* p = parentComponent_;
  33093. while (p != 0)
  33094. {
  33095. const ComponentDeletionWatcher parentDeletionChecker (p);
  33096. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33097. {
  33098. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseUp (me);
  33099. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33100. return;
  33101. i = jmin (i, p->numDeepMouseListeners);
  33102. }
  33103. p = p->parentComponent_;
  33104. }
  33105. }
  33106. // check for double-click
  33107. if (me.getNumberOfClicks() >= 2)
  33108. {
  33109. const int numListeners = (mouseListeners_ != 0) ? mouseListeners_->size() : 0;
  33110. mouseDoubleClick (me);
  33111. int i;
  33112. for (i = desktop.mouseListeners.size(); --i >= 0;)
  33113. {
  33114. ((MouseListener*) desktop.mouseListeners[i])->mouseDoubleClick (me);
  33115. if (deletionChecker.hasBeenDeleted())
  33116. return;
  33117. i = jmin (i, desktop.mouseListeners.size());
  33118. }
  33119. for (i = numListeners; --i >= 0;)
  33120. {
  33121. if (deletionChecker.hasBeenDeleted() || mouseListeners_ == 0)
  33122. return;
  33123. MouseListener* const ml = (MouseListener*)((*mouseListeners_)[i]);
  33124. if (ml != 0)
  33125. ml->mouseDoubleClick (me);
  33126. }
  33127. if (deletionChecker.hasBeenDeleted())
  33128. return;
  33129. const Component* p = parentComponent_;
  33130. while (p != 0)
  33131. {
  33132. const ComponentDeletionWatcher parentDeletionChecker (p);
  33133. for (i = p->numDeepMouseListeners; --i >= 0;)
  33134. {
  33135. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDoubleClick (me);
  33136. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33137. return;
  33138. i = jmin (i, p->numDeepMouseListeners);
  33139. }
  33140. p = p->parentComponent_;
  33141. }
  33142. }
  33143. }
  33144. enableUnboundedMouseMovement (false);
  33145. }
  33146. void Component::internalMouseDrag (int x, int y, const int64 time)
  33147. {
  33148. if (isValidComponent() && flags.draggingFlag)
  33149. {
  33150. Desktop& desktop = Desktop::getInstance();
  33151. flags.mouseOverFlag = reallyContains (x, y, false);
  33152. x += unboundedMouseOffset.getX();
  33153. y += unboundedMouseOffset.getY();
  33154. desktop.registerMouseDrag (relativePositionToGlobal (Point<int> (x, y)));
  33155. const ComponentDeletionWatcher deletionChecker (this);
  33156. const Point<int> mouseDownPos (globalPositionToRelative (Desktop::getLastMouseDownPosition()));
  33157. const Time lastMouseDownTime (desktop.getLastMouseDownTime());
  33158. const MouseEvent me (Point<int> (x, y),
  33159. ModifierKeys::getCurrentModifiers(),
  33160. this,
  33161. Time (time),
  33162. mouseDownPos,
  33163. lastMouseDownTime,
  33164. desktop.getNumberOfMultipleClicks(),
  33165. desktop.mouseMovedSignificantlySincePressed
  33166. || time > lastMouseDownTime.toMilliseconds() + 300);
  33167. mouseDrag (me);
  33168. if (deletionChecker.hasBeenDeleted())
  33169. return;
  33170. desktop.resetTimer();
  33171. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33172. {
  33173. ((MouseListener*) desktop.mouseListeners[i])->mouseDrag (me);
  33174. if (deletionChecker.hasBeenDeleted())
  33175. return;
  33176. i = jmin (i, desktop.mouseListeners.size());
  33177. }
  33178. if (mouseListeners_ != 0)
  33179. {
  33180. for (int i = mouseListeners_->size(); --i >= 0;)
  33181. {
  33182. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseDrag (me);
  33183. if (deletionChecker.hasBeenDeleted())
  33184. return;
  33185. i = jmin (i, mouseListeners_->size());
  33186. }
  33187. }
  33188. const Component* p = parentComponent_;
  33189. while (p != 0)
  33190. {
  33191. const ComponentDeletionWatcher parentDeletionChecker (p);
  33192. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33193. {
  33194. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseDrag (me);
  33195. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33196. return;
  33197. i = jmin (i, p->numDeepMouseListeners);
  33198. }
  33199. p = p->parentComponent_;
  33200. }
  33201. if (this == componentUnderMouse)
  33202. {
  33203. if (isUnboundedMouseModeOn)
  33204. {
  33205. Rectangle<int> screenArea (getParentMonitorArea().expanded (-2, -2));
  33206. Point<int> mousePos (Desktop::getMousePosition());
  33207. if (! screenArea.contains (mousePos))
  33208. {
  33209. int deltaX = 0, deltaY = 0;
  33210. if (mousePos.getX() <= screenArea.getX() || mousePos.getX() >= screenArea.getRight())
  33211. deltaX = getScreenX() + getWidth() / 2 - mousePos.getX();
  33212. if (mousePos.getY() <= screenArea.getY() || mousePos.getY() >= screenArea.getBottom())
  33213. deltaY = getScreenY() + getHeight() / 2 - mousePos.getY();
  33214. unboundedMouseOffset -= Point<int> (deltaX, deltaY);
  33215. Desktop::setMousePosition (mousePos + Point<int> (deltaX, deltaY));
  33216. }
  33217. else if (isCursorVisibleUntilOffscreen
  33218. && (! unboundedMouseOffset.isOrigin())
  33219. && screenArea.contains (mousePos + unboundedMouseOffset))
  33220. {
  33221. mousePos += unboundedMouseOffset;
  33222. unboundedMouseOffset = Point<int>();
  33223. Desktop::setMousePosition (mousePos);
  33224. }
  33225. }
  33226. internalUpdateMouseCursor (false);
  33227. }
  33228. }
  33229. }
  33230. void Component::internalMouseMove (const int x, const int y, const int64 time)
  33231. {
  33232. const ComponentDeletionWatcher deletionChecker (this);
  33233. if (isValidComponent())
  33234. {
  33235. Desktop& desktop = Desktop::getInstance();
  33236. const MouseEvent me (Point<int> (x, y),
  33237. ModifierKeys::getCurrentModifiers(),
  33238. this,
  33239. Time (time),
  33240. Point<int> (x, y),
  33241. Time (time),
  33242. 0, false);
  33243. if (isCurrentlyBlockedByAnotherModalComponent())
  33244. {
  33245. // allow blocked mouse-events to go to global listeners..
  33246. desktop.sendMouseMove();
  33247. }
  33248. else
  33249. {
  33250. if (this == componentUnderMouse)
  33251. internalUpdateMouseCursor (false);
  33252. flags.mouseOverFlag = true;
  33253. mouseMove (me);
  33254. if (deletionChecker.hasBeenDeleted())
  33255. return;
  33256. desktop.resetTimer();
  33257. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33258. {
  33259. ((MouseListener*) desktop.mouseListeners[i])->mouseMove (me);
  33260. if (deletionChecker.hasBeenDeleted())
  33261. return;
  33262. i = jmin (i, desktop.mouseListeners.size());
  33263. }
  33264. if (mouseListeners_ != 0)
  33265. {
  33266. for (int i = mouseListeners_->size(); --i >= 0;)
  33267. {
  33268. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseMove (me);
  33269. if (deletionChecker.hasBeenDeleted())
  33270. return;
  33271. i = jmin (i, mouseListeners_->size());
  33272. }
  33273. }
  33274. const Component* p = parentComponent_;
  33275. while (p != 0)
  33276. {
  33277. const ComponentDeletionWatcher parentDeletionChecker (p);
  33278. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33279. {
  33280. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseMove (me);
  33281. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33282. return;
  33283. i = jmin (i, p->numDeepMouseListeners);
  33284. }
  33285. p = p->parentComponent_;
  33286. }
  33287. }
  33288. }
  33289. }
  33290. void Component::internalMouseWheel (const int intAmountX, const int intAmountY, const int64 time)
  33291. {
  33292. Desktop& desktop = Desktop::getInstance();
  33293. const ComponentDeletionWatcher deletionChecker (this);
  33294. const float wheelIncrementX = intAmountX * (1.0f / 256.0f);
  33295. const float wheelIncrementY = intAmountY * (1.0f / 256.0f);
  33296. const Point<int> mousePos (getMouseXYRelative());
  33297. const MouseEvent me (mousePos,
  33298. ModifierKeys::getCurrentModifiers(),
  33299. this,
  33300. Time (time),
  33301. mousePos,
  33302. Time (time),
  33303. 0, false);
  33304. if (isCurrentlyBlockedByAnotherModalComponent())
  33305. {
  33306. // allow blocked mouse-events to go to global listeners..
  33307. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33308. {
  33309. ((MouseListener*) desktop.mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33310. if (deletionChecker.hasBeenDeleted())
  33311. return;
  33312. i = jmin (i, desktop.mouseListeners.size());
  33313. }
  33314. }
  33315. else
  33316. {
  33317. mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33318. if (deletionChecker.hasBeenDeleted())
  33319. return;
  33320. for (int i = desktop.mouseListeners.size(); --i >= 0;)
  33321. {
  33322. ((MouseListener*) desktop.mouseListeners[i])->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33323. if (deletionChecker.hasBeenDeleted())
  33324. return;
  33325. i = jmin (i, desktop.mouseListeners.size());
  33326. }
  33327. if (mouseListeners_ != 0)
  33328. {
  33329. for (int i = mouseListeners_->size(); --i >= 0;)
  33330. {
  33331. ((MouseListener*) mouseListeners_->getUnchecked (i))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33332. if (deletionChecker.hasBeenDeleted())
  33333. return;
  33334. i = jmin (i, mouseListeners_->size());
  33335. }
  33336. }
  33337. const Component* p = parentComponent_;
  33338. while (p != 0)
  33339. {
  33340. const ComponentDeletionWatcher parentDeletionChecker (p);
  33341. for (int i = p->numDeepMouseListeners; --i >= 0;)
  33342. {
  33343. ((MouseListener*) (p->mouseListeners_->getUnchecked (i)))->mouseWheelMove (me, wheelIncrementX, wheelIncrementY);
  33344. if (deletionChecker.hasBeenDeleted() || parentDeletionChecker.hasBeenDeleted())
  33345. return;
  33346. i = jmin (i, p->numDeepMouseListeners);
  33347. }
  33348. p = p->parentComponent_;
  33349. }
  33350. sendFakeMouseMove();
  33351. }
  33352. }
  33353. void Component::sendFakeMouseMove() const
  33354. {
  33355. ComponentPeer* const peer = getPeer();
  33356. if (peer != 0)
  33357. peer->sendFakeMouseMove();
  33358. }
  33359. void Component::broughtToFront()
  33360. {
  33361. }
  33362. void Component::internalBroughtToFront()
  33363. {
  33364. if (isValidComponent())
  33365. {
  33366. if (flags.hasHeavyweightPeerFlag)
  33367. Desktop::getInstance().componentBroughtToFront (this);
  33368. const ComponentDeletionWatcher deletionChecker (this);
  33369. broughtToFront();
  33370. if (deletionChecker.hasBeenDeleted())
  33371. return;
  33372. if (componentListeners_ != 0)
  33373. {
  33374. for (int i = componentListeners_->size(); --i >= 0;)
  33375. {
  33376. ((ComponentListener*) componentListeners_->getUnchecked (i))
  33377. ->componentBroughtToFront (*this);
  33378. if (deletionChecker.hasBeenDeleted())
  33379. return;
  33380. i = jmin (i, componentListeners_->size());
  33381. }
  33382. }
  33383. // when brought to the front and there's a modal component blocking this one,
  33384. // we need to bring the modal one to the front instead..
  33385. Component* const cm = getCurrentlyModalComponent();
  33386. if (cm != 0 && cm->getTopLevelComponent() != getTopLevelComponent())
  33387. bringModalComponentToFront();
  33388. }
  33389. }
  33390. void Component::focusGained (FocusChangeType)
  33391. {
  33392. // base class does nothing
  33393. }
  33394. void Component::internalFocusGain (const FocusChangeType cause)
  33395. {
  33396. const ComponentDeletionWatcher deletionChecker (this);
  33397. focusGained (cause);
  33398. if (! deletionChecker.hasBeenDeleted())
  33399. internalChildFocusChange (cause);
  33400. }
  33401. void Component::focusLost (FocusChangeType)
  33402. {
  33403. // base class does nothing
  33404. }
  33405. void Component::internalFocusLoss (const FocusChangeType cause)
  33406. {
  33407. const ComponentDeletionWatcher deletionChecker (this);
  33408. focusLost (focusChangedDirectly);
  33409. if (! deletionChecker.hasBeenDeleted())
  33410. internalChildFocusChange (cause);
  33411. }
  33412. void Component::focusOfChildComponentChanged (FocusChangeType /*cause*/)
  33413. {
  33414. // base class does nothing
  33415. }
  33416. void Component::internalChildFocusChange (FocusChangeType cause)
  33417. {
  33418. const bool childIsNowFocused = hasKeyboardFocus (true);
  33419. if (flags.childCompFocusedFlag != childIsNowFocused)
  33420. {
  33421. flags.childCompFocusedFlag = childIsNowFocused;
  33422. const ComponentDeletionWatcher deletionChecker (this);
  33423. focusOfChildComponentChanged (cause);
  33424. if (deletionChecker.hasBeenDeleted())
  33425. return;
  33426. }
  33427. if (parentComponent_ != 0)
  33428. parentComponent_->internalChildFocusChange (cause);
  33429. }
  33430. bool Component::isEnabled() const throw()
  33431. {
  33432. return (! flags.isDisabledFlag)
  33433. && (parentComponent_ == 0 || parentComponent_->isEnabled());
  33434. }
  33435. void Component::setEnabled (const bool shouldBeEnabled)
  33436. {
  33437. if (flags.isDisabledFlag == shouldBeEnabled)
  33438. {
  33439. flags.isDisabledFlag = ! shouldBeEnabled;
  33440. // if any parent components are disabled, setting our flag won't make a difference,
  33441. // so no need to send a change message
  33442. if (parentComponent_ == 0 || parentComponent_->isEnabled())
  33443. sendEnablementChangeMessage();
  33444. }
  33445. }
  33446. void Component::sendEnablementChangeMessage()
  33447. {
  33448. const ComponentDeletionWatcher deletionChecker (this);
  33449. enablementChanged();
  33450. if (deletionChecker.hasBeenDeleted())
  33451. return;
  33452. for (int i = getNumChildComponents(); --i >= 0;)
  33453. {
  33454. Component* const c = getChildComponent (i);
  33455. if (c != 0)
  33456. {
  33457. c->sendEnablementChangeMessage();
  33458. if (deletionChecker.hasBeenDeleted())
  33459. return;
  33460. }
  33461. }
  33462. }
  33463. void Component::enablementChanged()
  33464. {
  33465. }
  33466. void Component::setWantsKeyboardFocus (const bool wantsFocus) throw()
  33467. {
  33468. flags.wantsFocusFlag = wantsFocus;
  33469. }
  33470. void Component::setMouseClickGrabsKeyboardFocus (const bool shouldGrabFocus)
  33471. {
  33472. flags.dontFocusOnMouseClickFlag = ! shouldGrabFocus;
  33473. }
  33474. bool Component::getMouseClickGrabsKeyboardFocus() const throw()
  33475. {
  33476. return ! flags.dontFocusOnMouseClickFlag;
  33477. }
  33478. bool Component::getWantsKeyboardFocus() const throw()
  33479. {
  33480. return flags.wantsFocusFlag && ! flags.isDisabledFlag;
  33481. }
  33482. void Component::setFocusContainer (const bool shouldBeFocusContainer) throw()
  33483. {
  33484. flags.isFocusContainerFlag = shouldBeFocusContainer;
  33485. }
  33486. bool Component::isFocusContainer() const throw()
  33487. {
  33488. return flags.isFocusContainerFlag;
  33489. }
  33490. int Component::getExplicitFocusOrder() const throw()
  33491. {
  33492. return properties ["_jexfo"];
  33493. }
  33494. void Component::setExplicitFocusOrder (const int newFocusOrderIndex) throw()
  33495. {
  33496. properties.set ("_jexfo", newFocusOrderIndex);
  33497. }
  33498. KeyboardFocusTraverser* Component::createFocusTraverser()
  33499. {
  33500. if (flags.isFocusContainerFlag || parentComponent_ == 0)
  33501. return new KeyboardFocusTraverser();
  33502. return parentComponent_->createFocusTraverser();
  33503. }
  33504. void Component::takeKeyboardFocus (const FocusChangeType cause)
  33505. {
  33506. // give the focus to this component
  33507. if (currentlyFocusedComponent != this)
  33508. {
  33509. JUCE_TRY
  33510. {
  33511. // get the focus onto our desktop window
  33512. ComponentPeer* const peer = getPeer();
  33513. if (peer != 0)
  33514. {
  33515. const ComponentDeletionWatcher deletionChecker (this);
  33516. peer->grabFocus();
  33517. if (peer->isFocused() && currentlyFocusedComponent != this)
  33518. {
  33519. Component* const componentLosingFocus = currentlyFocusedComponent;
  33520. currentlyFocusedComponent = this;
  33521. Desktop::getInstance().triggerFocusCallback();
  33522. // call this after setting currentlyFocusedComponent so that the one that's
  33523. // losing it has a chance to see where focus is going
  33524. if (componentLosingFocus->isValidComponent())
  33525. componentLosingFocus->internalFocusLoss (cause);
  33526. if (currentlyFocusedComponent == this)
  33527. {
  33528. focusGained (cause);
  33529. if (! deletionChecker.hasBeenDeleted())
  33530. internalChildFocusChange (cause);
  33531. }
  33532. }
  33533. }
  33534. }
  33535. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  33536. catch (const std::exception& e)
  33537. {
  33538. currentlyFocusedComponent = 0;
  33539. Desktop::getInstance().triggerFocusCallback();
  33540. JUCEApplication::sendUnhandledException (&e, __FILE__, __LINE__);
  33541. }
  33542. catch (...)
  33543. {
  33544. currentlyFocusedComponent = 0;
  33545. Desktop::getInstance().triggerFocusCallback();
  33546. JUCEApplication::sendUnhandledException (0, __FILE__, __LINE__);
  33547. }
  33548. #endif
  33549. }
  33550. }
  33551. void Component::grabFocusInternal (const FocusChangeType cause, const bool canTryParent)
  33552. {
  33553. if (isShowing())
  33554. {
  33555. if (flags.wantsFocusFlag && (isEnabled() || parentComponent_ == 0))
  33556. {
  33557. takeKeyboardFocus (cause);
  33558. }
  33559. else
  33560. {
  33561. if (isParentOf (currentlyFocusedComponent)
  33562. && currentlyFocusedComponent->isShowing())
  33563. {
  33564. // do nothing if the focused component is actually a child of ours..
  33565. }
  33566. else
  33567. {
  33568. // find the default child component..
  33569. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33570. if (traverser != 0)
  33571. {
  33572. Component* const defaultComp = traverser->getDefaultComponent (this);
  33573. traverser = 0;
  33574. if (defaultComp != 0)
  33575. {
  33576. defaultComp->grabFocusInternal (cause, false);
  33577. return;
  33578. }
  33579. }
  33580. if (canTryParent && parentComponent_ != 0)
  33581. {
  33582. // if no children want it and we're allowed to try our parent comp,
  33583. // then pass up to parent, which will try our siblings.
  33584. parentComponent_->grabFocusInternal (cause, true);
  33585. }
  33586. }
  33587. }
  33588. }
  33589. }
  33590. void Component::grabKeyboardFocus()
  33591. {
  33592. // if component methods are being called from threads other than the message
  33593. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33594. checkMessageManagerIsLocked
  33595. grabFocusInternal (focusChangedDirectly);
  33596. }
  33597. void Component::moveKeyboardFocusToSibling (const bool moveToNext)
  33598. {
  33599. // if component methods are being called from threads other than the message
  33600. // thread, you'll need to use a MessageManagerLock object to make sure it's thread-safe.
  33601. checkMessageManagerIsLocked
  33602. if (parentComponent_ != 0)
  33603. {
  33604. ScopedPointer <KeyboardFocusTraverser> traverser (createFocusTraverser());
  33605. if (traverser != 0)
  33606. {
  33607. Component* const nextComp = moveToNext ? traverser->getNextComponent (this)
  33608. : traverser->getPreviousComponent (this);
  33609. traverser = 0;
  33610. if (nextComp != 0)
  33611. {
  33612. if (nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33613. {
  33614. const ComponentDeletionWatcher deletionChecker (nextComp);
  33615. internalModalInputAttempt();
  33616. if (deletionChecker.hasBeenDeleted()
  33617. || nextComp->isCurrentlyBlockedByAnotherModalComponent())
  33618. return;
  33619. }
  33620. nextComp->grabFocusInternal (focusChangedByTabKey);
  33621. return;
  33622. }
  33623. }
  33624. parentComponent_->moveKeyboardFocusToSibling (moveToNext);
  33625. }
  33626. }
  33627. bool Component::hasKeyboardFocus (const bool trueIfChildIsFocused) const throw()
  33628. {
  33629. return (currentlyFocusedComponent == this)
  33630. || (trueIfChildIsFocused && isParentOf (currentlyFocusedComponent));
  33631. }
  33632. Component* JUCE_CALLTYPE Component::getCurrentlyFocusedComponent() throw()
  33633. {
  33634. return currentlyFocusedComponent;
  33635. }
  33636. void Component::giveAwayFocus()
  33637. {
  33638. // use a copy so we can clear the value before the call
  33639. Component* const componentLosingFocus = currentlyFocusedComponent;
  33640. currentlyFocusedComponent = 0;
  33641. Desktop::getInstance().triggerFocusCallback();
  33642. if (componentLosingFocus->isValidComponent())
  33643. componentLosingFocus->internalFocusLoss (focusChangedDirectly);
  33644. }
  33645. bool Component::isMouseOver() const throw()
  33646. {
  33647. return flags.mouseOverFlag;
  33648. }
  33649. bool Component::isMouseButtonDown() const throw()
  33650. {
  33651. return flags.draggingFlag;
  33652. }
  33653. bool Component::isMouseOverOrDragging() const throw()
  33654. {
  33655. return flags.mouseOverFlag || flags.draggingFlag;
  33656. }
  33657. bool JUCE_CALLTYPE Component::isMouseButtonDownAnywhere() throw()
  33658. {
  33659. return ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown();
  33660. }
  33661. const Point<int> Component::getMouseXYRelative() const
  33662. {
  33663. return globalPositionToRelative (Desktop::getMousePosition()) + unboundedMouseOffset;
  33664. }
  33665. void Component::enableUnboundedMouseMovement (bool enable,
  33666. bool keepCursorVisibleUntilOffscreen) throw()
  33667. {
  33668. enable = enable && isMouseButtonDown();
  33669. isCursorVisibleUntilOffscreen = keepCursorVisibleUntilOffscreen;
  33670. if (enable != isUnboundedMouseModeOn)
  33671. {
  33672. if ((! enable) && ((! isCursorVisibleUntilOffscreen)
  33673. || ! unboundedMouseOffset.isOrigin()))
  33674. {
  33675. // when released, return the mouse to within the component's bounds
  33676. Desktop::setMousePosition (relativePositionToGlobal (Rectangle<int> (0, 0, getWidth(), getHeight())
  33677. .getConstrainedPoint (getMouseXYRelative())));
  33678. }
  33679. isUnboundedMouseModeOn = enable;
  33680. unboundedMouseOffset = Point<int>();
  33681. internalUpdateMouseCursor (true);
  33682. }
  33683. }
  33684. Component* JUCE_CALLTYPE Component::getComponentUnderMouse() throw()
  33685. {
  33686. return componentUnderMouse;
  33687. }
  33688. const Rectangle<int> Component::getParentMonitorArea() const throw()
  33689. {
  33690. return Desktop::getInstance()
  33691. .getMonitorAreaContaining (relativePositionToGlobal (Point<int> (getWidth() / 2,
  33692. getHeight() / 2)));
  33693. }
  33694. void Component::addKeyListener (KeyListener* const newListener) throw()
  33695. {
  33696. if (keyListeners_ == 0)
  33697. keyListeners_ = new VoidArray();
  33698. keyListeners_->addIfNotAlreadyThere (newListener);
  33699. }
  33700. void Component::removeKeyListener (KeyListener* const listenerToRemove) throw()
  33701. {
  33702. if (keyListeners_ != 0)
  33703. keyListeners_->removeValue (listenerToRemove);
  33704. }
  33705. bool Component::keyPressed (const KeyPress&)
  33706. {
  33707. return false;
  33708. }
  33709. bool Component::keyStateChanged (const bool /*isKeyDown*/)
  33710. {
  33711. return false;
  33712. }
  33713. void Component::modifierKeysChanged (const ModifierKeys& modifiers)
  33714. {
  33715. if (parentComponent_ != 0)
  33716. parentComponent_->modifierKeysChanged (modifiers);
  33717. }
  33718. void Component::internalModifierKeysChanged()
  33719. {
  33720. sendFakeMouseMove();
  33721. modifierKeysChanged (ModifierKeys::getCurrentModifiers());
  33722. }
  33723. ComponentPeer* Component::getPeer() const throw()
  33724. {
  33725. if (flags.hasHeavyweightPeerFlag)
  33726. return ComponentPeer::getPeerFor (this);
  33727. else if (parentComponent_ != 0)
  33728. return parentComponent_->getPeer();
  33729. else
  33730. return 0;
  33731. }
  33732. ComponentDeletionWatcher::ComponentDeletionWatcher (const Component* const componentToWatch_) throw()
  33733. : componentToWatch (componentToWatch_),
  33734. componentUID (componentToWatch_->getComponentUID())
  33735. {
  33736. // not possible to check on an already-deleted object..
  33737. jassert (componentToWatch_->isValidComponent());
  33738. }
  33739. ComponentDeletionWatcher::~ComponentDeletionWatcher() throw() {}
  33740. bool ComponentDeletionWatcher::hasBeenDeleted() const throw()
  33741. {
  33742. return ! (componentToWatch->isValidComponent()
  33743. && componentToWatch->getComponentUID() == componentUID);
  33744. }
  33745. const Component* ComponentDeletionWatcher::getComponent() const throw()
  33746. {
  33747. return hasBeenDeleted() ? 0 : componentToWatch;
  33748. }
  33749. END_JUCE_NAMESPACE
  33750. /*** End of inlined file: juce_Component.cpp ***/
  33751. /*** Start of inlined file: juce_ComponentListener.cpp ***/
  33752. BEGIN_JUCE_NAMESPACE
  33753. void ComponentListener::componentMovedOrResized (Component&, bool, bool)
  33754. {
  33755. }
  33756. void ComponentListener::componentBroughtToFront (Component&)
  33757. {
  33758. }
  33759. void ComponentListener::componentVisibilityChanged (Component&)
  33760. {
  33761. }
  33762. void ComponentListener::componentChildrenChanged (Component&)
  33763. {
  33764. }
  33765. void ComponentListener::componentParentHierarchyChanged (Component&)
  33766. {
  33767. }
  33768. void ComponentListener::componentNameChanged (Component&)
  33769. {
  33770. }
  33771. END_JUCE_NAMESPACE
  33772. /*** End of inlined file: juce_ComponentListener.cpp ***/
  33773. /*** Start of inlined file: juce_Desktop.cpp ***/
  33774. BEGIN_JUCE_NAMESPACE
  33775. Desktop::Desktop() throw()
  33776. : mouseClickCounter (0),
  33777. mouseMovedSignificantlySincePressed (false),
  33778. kioskModeComponent (0)
  33779. {
  33780. zerostruct (mouseDowns);
  33781. refreshMonitorSizes();
  33782. }
  33783. Desktop::~Desktop() throw()
  33784. {
  33785. jassert (instance == this);
  33786. instance = 0;
  33787. // doh! If you don't delete all your windows before exiting, you're going to
  33788. // be leaking memory!
  33789. jassert (desktopComponents.size() == 0);
  33790. }
  33791. Desktop& JUCE_CALLTYPE Desktop::getInstance() throw()
  33792. {
  33793. if (instance == 0)
  33794. instance = new Desktop();
  33795. return *instance;
  33796. }
  33797. Desktop* Desktop::instance = 0;
  33798. extern void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords,
  33799. const bool clipToWorkArea);
  33800. void Desktop::refreshMonitorSizes() throw()
  33801. {
  33802. const Array <Rectangle<int> > oldClipped (monitorCoordsClipped);
  33803. const Array <Rectangle<int> > oldUnclipped (monitorCoordsUnclipped);
  33804. monitorCoordsClipped.clear();
  33805. monitorCoordsUnclipped.clear();
  33806. juce_updateMultiMonitorInfo (monitorCoordsClipped, true);
  33807. juce_updateMultiMonitorInfo (monitorCoordsUnclipped, false);
  33808. jassert (monitorCoordsClipped.size() > 0
  33809. && monitorCoordsClipped.size() == monitorCoordsUnclipped.size());
  33810. if (oldClipped != monitorCoordsClipped
  33811. || oldUnclipped != monitorCoordsUnclipped)
  33812. {
  33813. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  33814. {
  33815. ComponentPeer* const p = ComponentPeer::getPeer (i);
  33816. if (p != 0)
  33817. p->handleScreenSizeChange();
  33818. }
  33819. }
  33820. }
  33821. int Desktop::getNumDisplayMonitors() const throw()
  33822. {
  33823. return monitorCoordsClipped.size();
  33824. }
  33825. const Rectangle<int> Desktop::getDisplayMonitorCoordinates (const int index, const bool clippedToWorkArea) const throw()
  33826. {
  33827. return clippedToWorkArea ? monitorCoordsClipped [index]
  33828. : monitorCoordsUnclipped [index];
  33829. }
  33830. const RectangleList Desktop::getAllMonitorDisplayAreas (const bool clippedToWorkArea) const throw()
  33831. {
  33832. RectangleList rl;
  33833. for (int i = 0; i < getNumDisplayMonitors(); ++i)
  33834. rl.addWithoutMerging (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33835. return rl;
  33836. }
  33837. const Rectangle<int> Desktop::getMainMonitorArea (const bool clippedToWorkArea) const throw()
  33838. {
  33839. return getDisplayMonitorCoordinates (0, clippedToWorkArea);
  33840. }
  33841. const Rectangle<int> Desktop::getMonitorAreaContaining (const Point<int>& position, const bool clippedToWorkArea) const throw()
  33842. {
  33843. Rectangle<int> best (getMainMonitorArea (clippedToWorkArea));
  33844. double bestDistance = 1.0e10;
  33845. for (int i = getNumDisplayMonitors(); --i >= 0;)
  33846. {
  33847. const Rectangle<int> rect (getDisplayMonitorCoordinates (i, clippedToWorkArea));
  33848. if (rect.contains (position))
  33849. return rect;
  33850. const double distance = rect.getCentre().getDistanceFrom (position);
  33851. if (distance < bestDistance)
  33852. {
  33853. bestDistance = distance;
  33854. best = rect;
  33855. }
  33856. }
  33857. return best;
  33858. }
  33859. int Desktop::getNumComponents() const throw()
  33860. {
  33861. return desktopComponents.size();
  33862. }
  33863. Component* Desktop::getComponent (const int index) const throw()
  33864. {
  33865. return desktopComponents [index];
  33866. }
  33867. Component* Desktop::findComponentAt (const Point<int>& screenPosition) const
  33868. {
  33869. for (int i = desktopComponents.size(); --i >= 0;)
  33870. {
  33871. Component* const c = desktopComponents.getUnchecked(i);
  33872. const Point<int> relative (c->globalPositionToRelative (screenPosition));
  33873. if (c->contains (relative.getX(), relative.getY()))
  33874. return c->getComponentAt (relative.getX(), relative.getY());
  33875. }
  33876. return 0;
  33877. }
  33878. void Desktop::addDesktopComponent (Component* const c) throw()
  33879. {
  33880. jassert (c != 0);
  33881. jassert (! desktopComponents.contains (c));
  33882. desktopComponents.addIfNotAlreadyThere (c);
  33883. }
  33884. void Desktop::removeDesktopComponent (Component* const c) throw()
  33885. {
  33886. desktopComponents.removeValue (c);
  33887. }
  33888. void Desktop::componentBroughtToFront (Component* const c) throw()
  33889. {
  33890. const int index = desktopComponents.indexOf (c);
  33891. jassert (index >= 0);
  33892. if (index >= 0)
  33893. {
  33894. int newIndex = -1;
  33895. if (! c->isAlwaysOnTop())
  33896. {
  33897. newIndex = desktopComponents.size();
  33898. while (newIndex > 0 && desktopComponents.getUnchecked (newIndex - 1)->isAlwaysOnTop())
  33899. --newIndex;
  33900. --newIndex;
  33901. }
  33902. desktopComponents.move (index, newIndex);
  33903. }
  33904. }
  33905. const Point<int> Desktop::getLastMouseDownPosition() throw()
  33906. {
  33907. return getInstance().mouseDowns[0].position;
  33908. }
  33909. int Desktop::getMouseButtonClickCounter() throw()
  33910. {
  33911. return getInstance().mouseClickCounter;
  33912. }
  33913. void Desktop::incrementMouseClickCounter() throw()
  33914. {
  33915. ++mouseClickCounter;
  33916. }
  33917. const Time Desktop::getLastMouseDownTime() const throw()
  33918. {
  33919. return Time (mouseDowns[0].time);
  33920. }
  33921. void Desktop::registerMouseDown (const Point<int>& position, int64 time, Component* component) throw()
  33922. {
  33923. for (int i = numElementsInArray (mouseDowns); --i > 0;)
  33924. mouseDowns[i] = mouseDowns[i - 1];
  33925. mouseDowns[0].position = position;
  33926. mouseDowns[0].time = time;
  33927. mouseDowns[0].component = component;
  33928. mouseMovedSignificantlySincePressed = false;
  33929. }
  33930. void Desktop::registerMouseDrag (const Point<int>& position) throw()
  33931. {
  33932. mouseMovedSignificantlySincePressed
  33933. = mouseMovedSignificantlySincePressed
  33934. || abs (mouseDowns[0].position.getX() - position.getX()) >= 4
  33935. || abs (mouseDowns[0].position.getY() - position.getY()) >= 4;
  33936. }
  33937. int Desktop::getNumberOfMultipleClicks() const throw()
  33938. {
  33939. int numClicks = 0;
  33940. if (mouseDowns[0].time != 0)
  33941. {
  33942. if (! mouseMovedSignificantlySincePressed)
  33943. ++numClicks;
  33944. for (int i = 1; i < numElementsInArray (mouseDowns); ++i)
  33945. {
  33946. if (mouseDowns[0].time - mouseDowns[i].time
  33947. < (int) (MouseEvent::getDoubleClickTimeout() * (1.0 + 0.25 * (i - 1)))
  33948. && abs (mouseDowns[0].position.getX() - mouseDowns[i].position.getX()) < 8
  33949. && abs (mouseDowns[0].position.getY() - mouseDowns[i].position.getY()) < 8
  33950. && mouseDowns[0].component == mouseDowns[i].component)
  33951. {
  33952. ++numClicks;
  33953. }
  33954. else
  33955. {
  33956. break;
  33957. }
  33958. }
  33959. }
  33960. return numClicks;
  33961. }
  33962. void Desktop::addGlobalMouseListener (MouseListener* const listener) throw()
  33963. {
  33964. jassert (listener != 0);
  33965. if (listener != 0)
  33966. {
  33967. mouseListeners.add (listener);
  33968. resetTimer();
  33969. }
  33970. }
  33971. void Desktop::removeGlobalMouseListener (MouseListener* const listener) throw()
  33972. {
  33973. mouseListeners.removeValue (listener);
  33974. resetTimer();
  33975. }
  33976. void Desktop::addFocusChangeListener (FocusChangeListener* const listener) throw()
  33977. {
  33978. jassert (listener != 0);
  33979. if (listener != 0)
  33980. focusListeners.add (listener);
  33981. }
  33982. void Desktop::removeFocusChangeListener (FocusChangeListener* const listener) throw()
  33983. {
  33984. focusListeners.removeValue (listener);
  33985. }
  33986. void Desktop::triggerFocusCallback() throw()
  33987. {
  33988. triggerAsyncUpdate();
  33989. }
  33990. void Desktop::handleAsyncUpdate()
  33991. {
  33992. for (int i = focusListeners.size(); --i >= 0;)
  33993. {
  33994. ((FocusChangeListener*) focusListeners.getUnchecked (i))->globalFocusChanged (Component::getCurrentlyFocusedComponent());
  33995. i = jmin (i, focusListeners.size());
  33996. }
  33997. }
  33998. void Desktop::timerCallback()
  33999. {
  34000. if (lastFakeMouseMove != getMousePosition())
  34001. sendMouseMove();
  34002. }
  34003. void Desktop::sendMouseMove()
  34004. {
  34005. if (mouseListeners.size() > 0)
  34006. {
  34007. startTimer (20);
  34008. lastFakeMouseMove = getMousePosition();
  34009. Component* const target = findComponentAt (lastFakeMouseMove);
  34010. if (target != 0)
  34011. {
  34012. ComponentDeletionWatcher deletionChecker (target);
  34013. const Point<int> pos (target->globalPositionToRelative (lastFakeMouseMove));
  34014. const Time now (Time::getCurrentTime());
  34015. const MouseEvent me (pos, ModifierKeys::getCurrentModifiers(),
  34016. target, now, pos, now, 0, false);
  34017. for (int i = mouseListeners.size(); --i >= 0;)
  34018. {
  34019. if (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  34020. ((MouseListener*) mouseListeners[i])->mouseDrag (me);
  34021. else
  34022. ((MouseListener*) mouseListeners[i])->mouseMove (me);
  34023. if (deletionChecker.hasBeenDeleted())
  34024. return;
  34025. i = jmin (i, mouseListeners.size());
  34026. }
  34027. }
  34028. }
  34029. }
  34030. void Desktop::resetTimer() throw()
  34031. {
  34032. if (mouseListeners.size() == 0)
  34033. stopTimer();
  34034. else
  34035. startTimer (100);
  34036. lastFakeMouseMove = getMousePosition();
  34037. }
  34038. extern void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars);
  34039. void Desktop::setKioskModeComponent (Component* componentToUse, const bool allowMenusAndBars)
  34040. {
  34041. if (kioskModeComponent != componentToUse)
  34042. {
  34043. // agh! Don't delete a component without first stopping it being the kiosk comp
  34044. jassert (kioskModeComponent == 0 || kioskModeComponent->isValidComponent());
  34045. // agh! Don't remove a component from the desktop if it's the kiosk comp!
  34046. jassert (kioskModeComponent == 0 || kioskModeComponent->isOnDesktop());
  34047. if (kioskModeComponent->isValidComponent())
  34048. {
  34049. juce_setKioskComponent (kioskModeComponent, false, allowMenusAndBars);
  34050. kioskModeComponent->setBounds (kioskComponentOriginalBounds);
  34051. }
  34052. kioskModeComponent = componentToUse;
  34053. if (kioskModeComponent != 0)
  34054. {
  34055. jassert (kioskModeComponent->isValidComponent());
  34056. // Only components that are already on the desktop can be put into kiosk mode!
  34057. jassert (kioskModeComponent->isOnDesktop());
  34058. kioskComponentOriginalBounds = kioskModeComponent->getBounds();
  34059. juce_setKioskComponent (kioskModeComponent, true, allowMenusAndBars);
  34060. }
  34061. }
  34062. }
  34063. END_JUCE_NAMESPACE
  34064. /*** End of inlined file: juce_Desktop.cpp ***/
  34065. /*** Start of inlined file: juce_ArrowButton.cpp ***/
  34066. BEGIN_JUCE_NAMESPACE
  34067. ArrowButton::ArrowButton (const String& name,
  34068. float arrowDirectionInRadians,
  34069. const Colour& arrowColour)
  34070. : Button (name),
  34071. colour (arrowColour)
  34072. {
  34073. path.lineTo (0.0f, 1.0f);
  34074. path.lineTo (1.0f, 0.5f);
  34075. path.closeSubPath();
  34076. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * arrowDirectionInRadians,
  34077. 0.5f, 0.5f));
  34078. setComponentEffect (&shadow);
  34079. buttonStateChanged();
  34080. }
  34081. ArrowButton::~ArrowButton()
  34082. {
  34083. }
  34084. void ArrowButton::paintButton (Graphics& g,
  34085. bool /*isMouseOverButton*/,
  34086. bool /*isButtonDown*/)
  34087. {
  34088. g.setColour (colour);
  34089. g.fillPath (path, path.getTransformToScaleToFit ((float) offset,
  34090. (float) offset,
  34091. (float) (getWidth() - 3),
  34092. (float) (getHeight() - 3),
  34093. false));
  34094. }
  34095. void ArrowButton::buttonStateChanged()
  34096. {
  34097. offset = (isDown()) ? 1 : 0;
  34098. shadow.setShadowProperties ((isDown()) ? 1.2f : 3.0f,
  34099. 0.3f, -1, 0);
  34100. }
  34101. END_JUCE_NAMESPACE
  34102. /*** End of inlined file: juce_ArrowButton.cpp ***/
  34103. /*** Start of inlined file: juce_Button.cpp ***/
  34104. BEGIN_JUCE_NAMESPACE
  34105. class Button::RepeatTimer : public Timer
  34106. {
  34107. public:
  34108. RepeatTimer (Button& owner_) : owner (owner_) {}
  34109. void timerCallback() { owner.repeatTimerCallback(); }
  34110. juce_UseDebuggingNewOperator
  34111. private:
  34112. Button& owner;
  34113. RepeatTimer (const RepeatTimer&);
  34114. RepeatTimer& operator= (const RepeatTimer&);
  34115. };
  34116. Button::Button (const String& name)
  34117. : Component (name),
  34118. keySource (0),
  34119. text (name),
  34120. buttonPressTime (0),
  34121. lastTimeCallbackTime (0),
  34122. commandManagerToUse (0),
  34123. autoRepeatDelay (-1),
  34124. autoRepeatSpeed (0),
  34125. autoRepeatMinimumDelay (-1),
  34126. radioGroupId (0),
  34127. commandID (0),
  34128. connectedEdgeFlags (0),
  34129. buttonState (buttonNormal),
  34130. lastToggleState (false),
  34131. clickTogglesState (false),
  34132. needsToRelease (false),
  34133. needsRepainting (false),
  34134. isKeyDown (false),
  34135. triggerOnMouseDown (false),
  34136. generateTooltip (false)
  34137. {
  34138. setWantsKeyboardFocus (true);
  34139. isOn.addListener (this);
  34140. }
  34141. Button::~Button()
  34142. {
  34143. isOn.removeListener (this);
  34144. if (commandManagerToUse != 0)
  34145. commandManagerToUse->removeListener (this);
  34146. repeatTimer = 0;
  34147. clearShortcuts();
  34148. }
  34149. void Button::setButtonText (const String& newText)
  34150. {
  34151. if (text != newText)
  34152. {
  34153. text = newText;
  34154. repaint();
  34155. }
  34156. }
  34157. void Button::setTooltip (const String& newTooltip)
  34158. {
  34159. SettableTooltipClient::setTooltip (newTooltip);
  34160. generateTooltip = false;
  34161. }
  34162. const String Button::getTooltip()
  34163. {
  34164. if (generateTooltip && commandManagerToUse != 0 && commandID != 0)
  34165. {
  34166. String tt (commandManagerToUse->getDescriptionOfCommand (commandID));
  34167. Array <KeyPress> keyPresses (commandManagerToUse->getKeyMappings()->getKeyPressesAssignedToCommand (commandID));
  34168. for (int i = 0; i < keyPresses.size(); ++i)
  34169. {
  34170. const String key (keyPresses.getReference(i).getTextDescription());
  34171. tt << " [";
  34172. if (key.length() == 1)
  34173. tt << TRANS("shortcut") << ": '" << key << "']";
  34174. else
  34175. tt << key << ']';
  34176. }
  34177. return tt;
  34178. }
  34179. return SettableTooltipClient::getTooltip();
  34180. }
  34181. void Button::setConnectedEdges (const int connectedEdgeFlags_)
  34182. {
  34183. if (connectedEdgeFlags != connectedEdgeFlags_)
  34184. {
  34185. connectedEdgeFlags = connectedEdgeFlags_;
  34186. repaint();
  34187. }
  34188. }
  34189. void Button::setToggleState (const bool shouldBeOn,
  34190. const bool sendChangeNotification)
  34191. {
  34192. if (shouldBeOn != lastToggleState)
  34193. {
  34194. const ComponentDeletionWatcher deletionWatcher (this);
  34195. isOn = shouldBeOn;
  34196. lastToggleState = shouldBeOn;
  34197. repaint();
  34198. if (sendChangeNotification)
  34199. sendClickMessage (ModifierKeys());
  34200. if ((! deletionWatcher.hasBeenDeleted()) && lastToggleState)
  34201. turnOffOtherButtonsInGroup (sendChangeNotification);
  34202. }
  34203. }
  34204. void Button::setClickingTogglesState (const bool shouldToggle) throw()
  34205. {
  34206. clickTogglesState = shouldToggle;
  34207. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34208. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34209. // it is that this button represents, and the button will update its state to reflect this
  34210. // in the applicationCommandListChanged() method.
  34211. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34212. }
  34213. bool Button::getClickingTogglesState() const throw()
  34214. {
  34215. return clickTogglesState;
  34216. }
  34217. void Button::valueChanged (Value& value)
  34218. {
  34219. if (value.refersToSameSourceAs (isOn))
  34220. setToggleState (isOn.getValue(), true);
  34221. }
  34222. void Button::setRadioGroupId (const int newGroupId)
  34223. {
  34224. if (radioGroupId != newGroupId)
  34225. {
  34226. radioGroupId = newGroupId;
  34227. if (lastToggleState)
  34228. turnOffOtherButtonsInGroup (true);
  34229. }
  34230. }
  34231. void Button::turnOffOtherButtonsInGroup (const bool sendChangeNotification)
  34232. {
  34233. Component* const p = getParentComponent();
  34234. if (p != 0 && radioGroupId != 0)
  34235. {
  34236. const ComponentDeletionWatcher deletionWatcher (this);
  34237. for (int i = p->getNumChildComponents(); --i >= 0;)
  34238. {
  34239. Component* const c = p->getChildComponent (i);
  34240. if (c != this)
  34241. {
  34242. Button* const b = dynamic_cast <Button*> (c);
  34243. if (b != 0 && b->getRadioGroupId() == radioGroupId)
  34244. {
  34245. b->setToggleState (false, sendChangeNotification);
  34246. if (deletionWatcher.hasBeenDeleted())
  34247. return;
  34248. }
  34249. }
  34250. }
  34251. }
  34252. }
  34253. void Button::enablementChanged()
  34254. {
  34255. updateState (0);
  34256. repaint();
  34257. }
  34258. Button::ButtonState Button::updateState (const MouseEvent* const e)
  34259. {
  34260. ButtonState state = buttonNormal;
  34261. if (isEnabled() && isVisible() && ! isCurrentlyBlockedByAnotherModalComponent())
  34262. {
  34263. Point<int> mousePos;
  34264. if (e == 0)
  34265. mousePos = getMouseXYRelative();
  34266. else
  34267. mousePos = e->getEventRelativeTo (this).getPosition();
  34268. const bool over = reallyContains (mousePos.getX(), mousePos.getY(), true);
  34269. const bool down = isMouseButtonDown();
  34270. if ((down && (over || (triggerOnMouseDown && buttonState == buttonDown))) || isKeyDown)
  34271. state = buttonDown;
  34272. else if (over)
  34273. state = buttonOver;
  34274. }
  34275. setState (state);
  34276. return state;
  34277. }
  34278. void Button::setState (const ButtonState newState)
  34279. {
  34280. if (buttonState != newState)
  34281. {
  34282. buttonState = newState;
  34283. repaint();
  34284. if (buttonState == buttonDown)
  34285. {
  34286. buttonPressTime = Time::getApproximateMillisecondCounter();
  34287. lastTimeCallbackTime = buttonPressTime;
  34288. }
  34289. sendStateMessage();
  34290. }
  34291. }
  34292. bool Button::isDown() const throw()
  34293. {
  34294. return buttonState == buttonDown;
  34295. }
  34296. bool Button::isOver() const throw()
  34297. {
  34298. return buttonState != buttonNormal;
  34299. }
  34300. void Button::buttonStateChanged()
  34301. {
  34302. }
  34303. uint32 Button::getMillisecondsSinceButtonDown() const throw()
  34304. {
  34305. const uint32 now = Time::getApproximateMillisecondCounter();
  34306. return now > buttonPressTime ? now - buttonPressTime : 0;
  34307. }
  34308. void Button::setTriggeredOnMouseDown (const bool isTriggeredOnMouseDown) throw()
  34309. {
  34310. triggerOnMouseDown = isTriggeredOnMouseDown;
  34311. }
  34312. void Button::clicked()
  34313. {
  34314. }
  34315. void Button::clicked (const ModifierKeys& /*modifiers*/)
  34316. {
  34317. clicked();
  34318. }
  34319. static const int clickMessageId = 0x2f3f4f99;
  34320. void Button::triggerClick()
  34321. {
  34322. postCommandMessage (clickMessageId);
  34323. }
  34324. void Button::internalClickCallback (const ModifierKeys& modifiers)
  34325. {
  34326. if (clickTogglesState)
  34327. setToggleState ((radioGroupId != 0) || ! lastToggleState, false);
  34328. sendClickMessage (modifiers);
  34329. }
  34330. void Button::flashButtonState()
  34331. {
  34332. if (isEnabled())
  34333. {
  34334. needsToRelease = true;
  34335. setState (buttonDown);
  34336. getRepeatTimer().startTimer (100);
  34337. }
  34338. }
  34339. void Button::handleCommandMessage (int commandId)
  34340. {
  34341. if (commandId == clickMessageId)
  34342. {
  34343. if (isEnabled())
  34344. {
  34345. flashButtonState();
  34346. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34347. }
  34348. }
  34349. else
  34350. {
  34351. Component::handleCommandMessage (commandId);
  34352. }
  34353. }
  34354. void Button::addButtonListener (ButtonListener* const newListener)
  34355. {
  34356. jassert (newListener != 0);
  34357. jassert (! buttonListeners.contains (newListener)); // trying to add a listener to the list twice!
  34358. if (newListener != 0)
  34359. buttonListeners.add (newListener);
  34360. }
  34361. void Button::removeButtonListener (ButtonListener* const listener)
  34362. {
  34363. jassert (buttonListeners.contains (listener)); // trying to remove a listener that isn't on the list!
  34364. buttonListeners.removeValue (listener);
  34365. }
  34366. void Button::sendClickMessage (const ModifierKeys& modifiers)
  34367. {
  34368. const ComponentDeletionWatcher cdw (this);
  34369. if (commandManagerToUse != 0 && commandID != 0)
  34370. {
  34371. ApplicationCommandTarget::InvocationInfo info (commandID);
  34372. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromButton;
  34373. info.originatingComponent = this;
  34374. commandManagerToUse->invoke (info, true);
  34375. }
  34376. clicked (modifiers);
  34377. if (! cdw.hasBeenDeleted())
  34378. {
  34379. for (int i = buttonListeners.size(); --i >= 0;)
  34380. {
  34381. ButtonListener* const bl = (ButtonListener*) buttonListeners[i];
  34382. if (bl != 0)
  34383. {
  34384. bl->buttonClicked (this);
  34385. if (cdw.hasBeenDeleted())
  34386. return;
  34387. }
  34388. }
  34389. }
  34390. }
  34391. void Button::sendStateMessage()
  34392. {
  34393. const ComponentDeletionWatcher cdw (this);
  34394. buttonStateChanged();
  34395. if (cdw.hasBeenDeleted())
  34396. return;
  34397. for (int i = buttonListeners.size(); --i >= 0;)
  34398. {
  34399. ButtonListener* const bl = (ButtonListener*) buttonListeners[i];
  34400. if (bl != 0)
  34401. {
  34402. bl->buttonStateChanged (this);
  34403. if (cdw.hasBeenDeleted())
  34404. return;
  34405. }
  34406. }
  34407. }
  34408. void Button::paint (Graphics& g)
  34409. {
  34410. if (needsToRelease && isEnabled())
  34411. {
  34412. needsToRelease = false;
  34413. needsRepainting = true;
  34414. }
  34415. paintButton (g, isOver(), isDown());
  34416. }
  34417. void Button::mouseEnter (const MouseEvent& e)
  34418. {
  34419. updateState (&e);
  34420. }
  34421. void Button::mouseExit (const MouseEvent& e)
  34422. {
  34423. updateState (&e);
  34424. }
  34425. void Button::mouseDown (const MouseEvent& e)
  34426. {
  34427. updateState (&e);
  34428. if (isDown())
  34429. {
  34430. if (autoRepeatDelay >= 0)
  34431. getRepeatTimer().startTimer (autoRepeatDelay);
  34432. if (triggerOnMouseDown)
  34433. internalClickCallback (e.mods);
  34434. }
  34435. }
  34436. void Button::mouseUp (const MouseEvent& e)
  34437. {
  34438. const bool wasDown = isDown();
  34439. updateState (&e);
  34440. if (wasDown && isOver() && ! triggerOnMouseDown)
  34441. internalClickCallback (e.mods);
  34442. }
  34443. void Button::mouseDrag (const MouseEvent& e)
  34444. {
  34445. const ButtonState oldState = buttonState;
  34446. updateState (&e);
  34447. if (autoRepeatDelay >= 0 && buttonState != oldState && isDown())
  34448. getRepeatTimer().startTimer (autoRepeatSpeed);
  34449. }
  34450. void Button::focusGained (FocusChangeType)
  34451. {
  34452. updateState (0);
  34453. repaint();
  34454. }
  34455. void Button::focusLost (FocusChangeType)
  34456. {
  34457. updateState (0);
  34458. repaint();
  34459. }
  34460. void Button::setVisible (bool shouldBeVisible)
  34461. {
  34462. if (shouldBeVisible != isVisible())
  34463. {
  34464. Component::setVisible (shouldBeVisible);
  34465. if (! shouldBeVisible)
  34466. needsToRelease = false;
  34467. updateState (0);
  34468. }
  34469. else
  34470. {
  34471. Component::setVisible (shouldBeVisible);
  34472. }
  34473. }
  34474. void Button::parentHierarchyChanged()
  34475. {
  34476. Component* const newKeySource = (shortcuts.size() == 0) ? 0 : getTopLevelComponent();
  34477. if (newKeySource != keySource)
  34478. {
  34479. if (keySource->isValidComponent())
  34480. keySource->removeKeyListener (this);
  34481. keySource = newKeySource;
  34482. if (keySource->isValidComponent())
  34483. keySource->addKeyListener (this);
  34484. }
  34485. }
  34486. void Button::setCommandToTrigger (ApplicationCommandManager* const commandManagerToUse_,
  34487. const int commandID_,
  34488. const bool generateTooltip_)
  34489. {
  34490. commandID = commandID_;
  34491. generateTooltip = generateTooltip_;
  34492. if (commandManagerToUse != commandManagerToUse_)
  34493. {
  34494. if (commandManagerToUse != 0)
  34495. commandManagerToUse->removeListener (this);
  34496. commandManagerToUse = commandManagerToUse_;
  34497. if (commandManagerToUse != 0)
  34498. commandManagerToUse->addListener (this);
  34499. // if you've got clickTogglesState turned on, you shouldn't also connect the button
  34500. // up to be a command invoker. Instead, your command handler must flip the state of whatever
  34501. // it is that this button represents, and the button will update its state to reflect this
  34502. // in the applicationCommandListChanged() method.
  34503. jassert (commandManagerToUse == 0 || ! clickTogglesState);
  34504. }
  34505. if (commandManagerToUse != 0)
  34506. applicationCommandListChanged();
  34507. else
  34508. setEnabled (true);
  34509. }
  34510. void Button::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  34511. {
  34512. if (info.commandID == commandID
  34513. && (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) == 0)
  34514. {
  34515. flashButtonState();
  34516. }
  34517. }
  34518. void Button::applicationCommandListChanged()
  34519. {
  34520. if (commandManagerToUse != 0)
  34521. {
  34522. ApplicationCommandInfo info (0);
  34523. ApplicationCommandTarget* const target = commandManagerToUse->getTargetForCommand (commandID, info);
  34524. setEnabled (target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0);
  34525. if (target != 0)
  34526. setToggleState ((info.flags & ApplicationCommandInfo::isTicked) != 0, false);
  34527. }
  34528. }
  34529. void Button::addShortcut (const KeyPress& key)
  34530. {
  34531. if (key.isValid())
  34532. {
  34533. jassert (! isRegisteredForShortcut (key)); // already registered!
  34534. shortcuts.add (key);
  34535. parentHierarchyChanged();
  34536. }
  34537. }
  34538. void Button::clearShortcuts()
  34539. {
  34540. shortcuts.clear();
  34541. parentHierarchyChanged();
  34542. }
  34543. bool Button::isShortcutPressed() const
  34544. {
  34545. if (! isCurrentlyBlockedByAnotherModalComponent())
  34546. {
  34547. for (int i = shortcuts.size(); --i >= 0;)
  34548. if (shortcuts.getReference(i).isCurrentlyDown())
  34549. return true;
  34550. }
  34551. return false;
  34552. }
  34553. bool Button::isRegisteredForShortcut (const KeyPress& key) const
  34554. {
  34555. for (int i = shortcuts.size(); --i >= 0;)
  34556. if (key == shortcuts.getReference(i))
  34557. return true;
  34558. return false;
  34559. }
  34560. bool Button::keyStateChanged (const bool, Component*)
  34561. {
  34562. if (! isEnabled())
  34563. return false;
  34564. const bool wasDown = isKeyDown;
  34565. isKeyDown = isShortcutPressed();
  34566. if (autoRepeatDelay >= 0 && (isKeyDown && ! wasDown))
  34567. getRepeatTimer().startTimer (autoRepeatDelay);
  34568. updateState (0);
  34569. if (isEnabled() && wasDown && ! isKeyDown)
  34570. {
  34571. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34572. // (return immediately - this button may now have been deleted)
  34573. return true;
  34574. }
  34575. return wasDown || isKeyDown;
  34576. }
  34577. bool Button::keyPressed (const KeyPress&, Component*)
  34578. {
  34579. // returning true will avoid forwarding events for keys that we're using as shortcuts
  34580. return isShortcutPressed();
  34581. }
  34582. bool Button::keyPressed (const KeyPress& key)
  34583. {
  34584. if (isEnabled() && key.isKeyCode (KeyPress::returnKey))
  34585. {
  34586. triggerClick();
  34587. return true;
  34588. }
  34589. return false;
  34590. }
  34591. void Button::setRepeatSpeed (const int initialDelayMillisecs,
  34592. const int repeatMillisecs,
  34593. const int minimumDelayInMillisecs) throw()
  34594. {
  34595. autoRepeatDelay = initialDelayMillisecs;
  34596. autoRepeatSpeed = repeatMillisecs;
  34597. autoRepeatMinimumDelay = jmin (autoRepeatSpeed, minimumDelayInMillisecs);
  34598. }
  34599. void Button::repeatTimerCallback()
  34600. {
  34601. if (needsRepainting)
  34602. {
  34603. getRepeatTimer().stopTimer();
  34604. updateState (0);
  34605. needsRepainting = false;
  34606. }
  34607. else if (autoRepeatSpeed > 0 && (isKeyDown || (updateState (0) == buttonDown)))
  34608. {
  34609. int repeatSpeed = autoRepeatSpeed;
  34610. if (autoRepeatMinimumDelay >= 0)
  34611. {
  34612. double timeHeldDown = jmin (1.0, getMillisecondsSinceButtonDown() / 4000.0);
  34613. timeHeldDown *= timeHeldDown;
  34614. repeatSpeed = repeatSpeed + (int) (timeHeldDown * (autoRepeatMinimumDelay - repeatSpeed));
  34615. }
  34616. repeatSpeed = jmax (1, repeatSpeed);
  34617. getRepeatTimer().startTimer (repeatSpeed);
  34618. const uint32 now = Time::getApproximateMillisecondCounter();
  34619. const int numTimesToCallback = (now > lastTimeCallbackTime) ? jmax (1, (int) (now - lastTimeCallbackTime) / repeatSpeed) : 1;
  34620. lastTimeCallbackTime = now;
  34621. const ComponentDeletionWatcher cdw (this);
  34622. for (int i = numTimesToCallback; --i >= 0;)
  34623. {
  34624. internalClickCallback (ModifierKeys::getCurrentModifiers());
  34625. if (cdw.hasBeenDeleted() || ! isDown())
  34626. return;
  34627. }
  34628. }
  34629. else if (! needsToRelease)
  34630. {
  34631. getRepeatTimer().stopTimer();
  34632. }
  34633. }
  34634. Button::RepeatTimer& Button::getRepeatTimer()
  34635. {
  34636. if (repeatTimer == 0)
  34637. repeatTimer = new RepeatTimer (*this);
  34638. return *repeatTimer;
  34639. }
  34640. END_JUCE_NAMESPACE
  34641. /*** End of inlined file: juce_Button.cpp ***/
  34642. /*** Start of inlined file: juce_DrawableButton.cpp ***/
  34643. BEGIN_JUCE_NAMESPACE
  34644. DrawableButton::DrawableButton (const String& name,
  34645. const DrawableButton::ButtonStyle buttonStyle)
  34646. : Button (name),
  34647. style (buttonStyle),
  34648. edgeIndent (3)
  34649. {
  34650. if (buttonStyle == ImageOnButtonBackground)
  34651. {
  34652. backgroundOff = Colour (0xffbbbbff);
  34653. backgroundOn = Colour (0xff3333ff);
  34654. }
  34655. else
  34656. {
  34657. backgroundOff = Colours::transparentBlack;
  34658. backgroundOn = Colour (0xaabbbbff);
  34659. }
  34660. }
  34661. DrawableButton::~DrawableButton()
  34662. {
  34663. deleteImages();
  34664. }
  34665. void DrawableButton::deleteImages()
  34666. {
  34667. }
  34668. void DrawableButton::setImages (const Drawable* normal,
  34669. const Drawable* over,
  34670. const Drawable* down,
  34671. const Drawable* disabled,
  34672. const Drawable* normalOn,
  34673. const Drawable* overOn,
  34674. const Drawable* downOn,
  34675. const Drawable* disabledOn)
  34676. {
  34677. deleteImages();
  34678. jassert (normal != 0); // you really need to give it at least a normal image..
  34679. if (normal != 0)
  34680. normalImage = normal->createCopy();
  34681. if (over != 0)
  34682. overImage = over->createCopy();
  34683. if (down != 0)
  34684. downImage = down->createCopy();
  34685. if (disabled != 0)
  34686. disabledImage = disabled->createCopy();
  34687. if (normalOn != 0)
  34688. normalImageOn = normalOn->createCopy();
  34689. if (overOn != 0)
  34690. overImageOn = overOn->createCopy();
  34691. if (downOn != 0)
  34692. downImageOn = downOn->createCopy();
  34693. if (disabledOn != 0)
  34694. disabledImageOn = disabledOn->createCopy();
  34695. repaint();
  34696. }
  34697. void DrawableButton::setButtonStyle (const DrawableButton::ButtonStyle newStyle)
  34698. {
  34699. if (style != newStyle)
  34700. {
  34701. style = newStyle;
  34702. repaint();
  34703. }
  34704. }
  34705. void DrawableButton::setBackgroundColours (const Colour& toggledOffColour,
  34706. const Colour& toggledOnColour)
  34707. {
  34708. if (backgroundOff != toggledOffColour
  34709. || backgroundOn != toggledOnColour)
  34710. {
  34711. backgroundOff = toggledOffColour;
  34712. backgroundOn = toggledOnColour;
  34713. repaint();
  34714. }
  34715. }
  34716. const Colour& DrawableButton::getBackgroundColour() const throw()
  34717. {
  34718. return getToggleState() ? backgroundOn
  34719. : backgroundOff;
  34720. }
  34721. void DrawableButton::setEdgeIndent (const int numPixelsIndent)
  34722. {
  34723. edgeIndent = numPixelsIndent;
  34724. repaint();
  34725. }
  34726. void DrawableButton::paintButton (Graphics& g,
  34727. bool isMouseOverButton,
  34728. bool isButtonDown)
  34729. {
  34730. Rectangle<int> imageSpace;
  34731. if (style == ImageOnButtonBackground)
  34732. {
  34733. const int insetX = getWidth() / 4;
  34734. const int insetY = getHeight() / 4;
  34735. imageSpace.setBounds (insetX, insetY, getWidth() - insetX * 2, getHeight() - insetY * 2);
  34736. getLookAndFeel().drawButtonBackground (g, *this,
  34737. getBackgroundColour(),
  34738. isMouseOverButton,
  34739. isButtonDown);
  34740. }
  34741. else
  34742. {
  34743. g.fillAll (getBackgroundColour());
  34744. const int textH = (style == ImageAboveTextLabel)
  34745. ? jmin (16, proportionOfHeight (0.25f))
  34746. : 0;
  34747. const int indentX = jmin (edgeIndent, proportionOfWidth (0.3f));
  34748. const int indentY = jmin (edgeIndent, proportionOfHeight (0.3f));
  34749. imageSpace.setBounds (indentX, indentY,
  34750. getWidth() - indentX * 2,
  34751. getHeight() - indentY * 2 - textH);
  34752. if (textH > 0)
  34753. {
  34754. g.setFont ((float) textH);
  34755. g.setColour (Colours::black.withAlpha (isEnabled() ? 1.0f : 0.4f));
  34756. g.drawFittedText (getButtonText(),
  34757. 2, getHeight() - textH - 1,
  34758. getWidth() - 4, textH,
  34759. Justification::centred, 1);
  34760. }
  34761. }
  34762. g.setImageResamplingQuality (Graphics::mediumResamplingQuality);
  34763. g.setOpacity (1.0f);
  34764. const Drawable* imageToDraw = 0;
  34765. if (isEnabled())
  34766. {
  34767. imageToDraw = getCurrentImage();
  34768. }
  34769. else
  34770. {
  34771. imageToDraw = getToggleState() ? disabledImageOn
  34772. : disabledImage;
  34773. if (imageToDraw == 0)
  34774. {
  34775. g.setOpacity (0.4f);
  34776. imageToDraw = getNormalImage();
  34777. }
  34778. }
  34779. if (imageToDraw != 0)
  34780. {
  34781. if (style == ImageRaw)
  34782. {
  34783. imageToDraw->draw (g, 1.0f);
  34784. }
  34785. else
  34786. {
  34787. imageToDraw->drawWithin (g,
  34788. imageSpace.getX(),
  34789. imageSpace.getY(),
  34790. imageSpace.getWidth(),
  34791. imageSpace.getHeight(),
  34792. RectanglePlacement::centred,
  34793. 1.0f);
  34794. }
  34795. }
  34796. }
  34797. const Drawable* DrawableButton::getCurrentImage() const throw()
  34798. {
  34799. if (isDown())
  34800. return getDownImage();
  34801. if (isOver())
  34802. return getOverImage();
  34803. return getNormalImage();
  34804. }
  34805. const Drawable* DrawableButton::getNormalImage() const throw()
  34806. {
  34807. return (getToggleState() && normalImageOn != 0) ? normalImageOn
  34808. : normalImage;
  34809. }
  34810. const Drawable* DrawableButton::getOverImage() const throw()
  34811. {
  34812. const Drawable* d = normalImage;
  34813. if (getToggleState())
  34814. {
  34815. if (overImageOn != 0)
  34816. d = overImageOn;
  34817. else if (normalImageOn != 0)
  34818. d = normalImageOn;
  34819. else if (overImage != 0)
  34820. d = overImage;
  34821. }
  34822. else
  34823. {
  34824. if (overImage != 0)
  34825. d = overImage;
  34826. }
  34827. return d;
  34828. }
  34829. const Drawable* DrawableButton::getDownImage() const throw()
  34830. {
  34831. const Drawable* d = normalImage;
  34832. if (getToggleState())
  34833. {
  34834. if (downImageOn != 0)
  34835. d = downImageOn;
  34836. else if (overImageOn != 0)
  34837. d = overImageOn;
  34838. else if (normalImageOn != 0)
  34839. d = normalImageOn;
  34840. else if (downImage != 0)
  34841. d = downImage;
  34842. else
  34843. d = getOverImage();
  34844. }
  34845. else
  34846. {
  34847. if (downImage != 0)
  34848. d = downImage;
  34849. else
  34850. d = getOverImage();
  34851. }
  34852. return d;
  34853. }
  34854. END_JUCE_NAMESPACE
  34855. /*** End of inlined file: juce_DrawableButton.cpp ***/
  34856. /*** Start of inlined file: juce_HyperlinkButton.cpp ***/
  34857. BEGIN_JUCE_NAMESPACE
  34858. HyperlinkButton::HyperlinkButton (const String& linkText,
  34859. const URL& linkURL)
  34860. : Button (linkText),
  34861. url (linkURL),
  34862. font (14.0f, Font::underlined),
  34863. resizeFont (true),
  34864. justification (Justification::centred)
  34865. {
  34866. setMouseCursor (MouseCursor::PointingHandCursor);
  34867. setTooltip (linkURL.toString (false));
  34868. }
  34869. HyperlinkButton::~HyperlinkButton()
  34870. {
  34871. }
  34872. void HyperlinkButton::setFont (const Font& newFont,
  34873. const bool resizeToMatchComponentHeight,
  34874. const Justification& justificationType)
  34875. {
  34876. font = newFont;
  34877. resizeFont = resizeToMatchComponentHeight;
  34878. justification = justificationType;
  34879. repaint();
  34880. }
  34881. void HyperlinkButton::setURL (const URL& newURL) throw()
  34882. {
  34883. url = newURL;
  34884. setTooltip (newURL.toString (false));
  34885. }
  34886. const Font HyperlinkButton::getFontToUse() const
  34887. {
  34888. Font f (font);
  34889. if (resizeFont)
  34890. f.setHeight (getHeight() * 0.7f);
  34891. return f;
  34892. }
  34893. void HyperlinkButton::changeWidthToFitText()
  34894. {
  34895. setSize (getFontToUse().getStringWidth (getName()) + 6, getHeight());
  34896. }
  34897. void HyperlinkButton::colourChanged()
  34898. {
  34899. repaint();
  34900. }
  34901. void HyperlinkButton::clicked()
  34902. {
  34903. if (url.isWellFormed())
  34904. url.launchInDefaultBrowser();
  34905. }
  34906. void HyperlinkButton::paintButton (Graphics& g,
  34907. bool isMouseOverButton,
  34908. bool isButtonDown)
  34909. {
  34910. const Colour textColour (findColour (textColourId));
  34911. if (isEnabled())
  34912. g.setColour ((isMouseOverButton) ? textColour.darker ((isButtonDown) ? 1.3f : 0.4f)
  34913. : textColour);
  34914. else
  34915. g.setColour (textColour.withMultipliedAlpha (0.4f));
  34916. g.setFont (getFontToUse());
  34917. g.drawText (getButtonText(),
  34918. 2, 0, getWidth() - 2, getHeight(),
  34919. justification.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  34920. true);
  34921. }
  34922. END_JUCE_NAMESPACE
  34923. /*** End of inlined file: juce_HyperlinkButton.cpp ***/
  34924. /*** Start of inlined file: juce_ImageButton.cpp ***/
  34925. BEGIN_JUCE_NAMESPACE
  34926. ImageButton::ImageButton (const String& text_)
  34927. : Button (text_),
  34928. scaleImageToFit (true),
  34929. preserveProportions (true),
  34930. alphaThreshold (0),
  34931. imageX (0),
  34932. imageY (0),
  34933. imageW (0),
  34934. imageH (0),
  34935. normalImage (0),
  34936. overImage (0),
  34937. downImage (0)
  34938. {
  34939. }
  34940. ImageButton::~ImageButton()
  34941. {
  34942. deleteImages();
  34943. }
  34944. void ImageButton::deleteImages()
  34945. {
  34946. ImageCache::releaseOrDelete (normalImage);
  34947. ImageCache::releaseOrDelete (overImage);
  34948. ImageCache::releaseOrDelete (downImage);
  34949. }
  34950. void ImageButton::setImages (const bool resizeButtonNowToFitThisImage,
  34951. const bool rescaleImagesWhenButtonSizeChanges,
  34952. const bool preserveImageProportions,
  34953. Image* const normalImage_,
  34954. const float imageOpacityWhenNormal,
  34955. const Colour& overlayColourWhenNormal,
  34956. Image* const overImage_,
  34957. const float imageOpacityWhenOver,
  34958. const Colour& overlayColourWhenOver,
  34959. Image* const downImage_,
  34960. const float imageOpacityWhenDown,
  34961. const Colour& overlayColourWhenDown,
  34962. const float hitTestAlphaThreshold)
  34963. {
  34964. deleteImages();
  34965. normalImage = normalImage_;
  34966. overImage = overImage_;
  34967. downImage = downImage_;
  34968. if (resizeButtonNowToFitThisImage && normalImage != 0)
  34969. {
  34970. imageW = normalImage->getWidth();
  34971. imageH = normalImage->getHeight();
  34972. setSize (imageW, imageH);
  34973. }
  34974. scaleImageToFit = rescaleImagesWhenButtonSizeChanges;
  34975. preserveProportions = preserveImageProportions;
  34976. normalOpacity = imageOpacityWhenNormal;
  34977. normalOverlay = overlayColourWhenNormal;
  34978. overOpacity = imageOpacityWhenOver;
  34979. overOverlay = overlayColourWhenOver;
  34980. downOpacity = imageOpacityWhenDown;
  34981. downOverlay = overlayColourWhenDown;
  34982. alphaThreshold = (unsigned char) jlimit (0, 0xff, roundToInt (255.0f * hitTestAlphaThreshold));
  34983. repaint();
  34984. }
  34985. Image* ImageButton::getCurrentImage() const
  34986. {
  34987. if (isDown() || getToggleState())
  34988. return getDownImage();
  34989. if (isOver())
  34990. return getOverImage();
  34991. return getNormalImage();
  34992. }
  34993. Image* ImageButton::getNormalImage() const throw()
  34994. {
  34995. return normalImage;
  34996. }
  34997. Image* ImageButton::getOverImage() const throw()
  34998. {
  34999. return (overImage != 0) ? overImage
  35000. : normalImage;
  35001. }
  35002. Image* ImageButton::getDownImage() const throw()
  35003. {
  35004. return (downImage != 0) ? downImage
  35005. : getOverImage();
  35006. }
  35007. void ImageButton::paintButton (Graphics& g,
  35008. bool isMouseOverButton,
  35009. bool isButtonDown)
  35010. {
  35011. if (! isEnabled())
  35012. {
  35013. isMouseOverButton = false;
  35014. isButtonDown = false;
  35015. }
  35016. Image* const im = getCurrentImage();
  35017. if (im != 0)
  35018. {
  35019. const int iw = im->getWidth();
  35020. const int ih = im->getHeight();
  35021. imageW = getWidth();
  35022. imageH = getHeight();
  35023. imageX = (imageW - iw) >> 1;
  35024. imageY = (imageH - ih) >> 1;
  35025. if (scaleImageToFit)
  35026. {
  35027. if (preserveProportions)
  35028. {
  35029. int newW, newH;
  35030. const float imRatio = ih / (float)iw;
  35031. const float destRatio = imageH / (float)imageW;
  35032. if (imRatio > destRatio)
  35033. {
  35034. newW = roundToInt (imageH / imRatio);
  35035. newH = imageH;
  35036. }
  35037. else
  35038. {
  35039. newW = imageW;
  35040. newH = roundToInt (imageW * imRatio);
  35041. }
  35042. imageX = (imageW - newW) / 2;
  35043. imageY = (imageH - newH) / 2;
  35044. imageW = newW;
  35045. imageH = newH;
  35046. }
  35047. else
  35048. {
  35049. imageX = 0;
  35050. imageY = 0;
  35051. }
  35052. }
  35053. if (! scaleImageToFit)
  35054. {
  35055. imageW = iw;
  35056. imageH = ih;
  35057. }
  35058. getLookAndFeel().drawImageButton (g, im, imageX, imageY, imageW, imageH,
  35059. isButtonDown ? downOverlay
  35060. : (isMouseOverButton ? overOverlay
  35061. : normalOverlay),
  35062. isButtonDown ? downOpacity
  35063. : (isMouseOverButton ? overOpacity
  35064. : normalOpacity),
  35065. *this);
  35066. }
  35067. }
  35068. bool ImageButton::hitTest (int x, int y)
  35069. {
  35070. if (alphaThreshold == 0)
  35071. return true;
  35072. Image* const im = getCurrentImage();
  35073. return im == 0
  35074. || (imageW > 0 && imageH > 0
  35075. && alphaThreshold < im->getPixelAt (((x - imageX) * im->getWidth()) / imageW,
  35076. ((y - imageY) * im->getHeight()) / imageH).getAlpha());
  35077. }
  35078. END_JUCE_NAMESPACE
  35079. /*** End of inlined file: juce_ImageButton.cpp ***/
  35080. /*** Start of inlined file: juce_ShapeButton.cpp ***/
  35081. BEGIN_JUCE_NAMESPACE
  35082. ShapeButton::ShapeButton (const String& text_,
  35083. const Colour& normalColour_,
  35084. const Colour& overColour_,
  35085. const Colour& downColour_)
  35086. : Button (text_),
  35087. normalColour (normalColour_),
  35088. overColour (overColour_),
  35089. downColour (downColour_),
  35090. maintainShapeProportions (false),
  35091. outlineWidth (0.0f)
  35092. {
  35093. }
  35094. ShapeButton::~ShapeButton()
  35095. {
  35096. }
  35097. void ShapeButton::setColours (const Colour& newNormalColour,
  35098. const Colour& newOverColour,
  35099. const Colour& newDownColour)
  35100. {
  35101. normalColour = newNormalColour;
  35102. overColour = newOverColour;
  35103. downColour = newDownColour;
  35104. }
  35105. void ShapeButton::setOutline (const Colour& newOutlineColour,
  35106. const float newOutlineWidth)
  35107. {
  35108. outlineColour = newOutlineColour;
  35109. outlineWidth = newOutlineWidth;
  35110. }
  35111. void ShapeButton::setShape (const Path& newShape,
  35112. const bool resizeNowToFitThisShape,
  35113. const bool maintainShapeProportions_,
  35114. const bool hasShadow)
  35115. {
  35116. shape = newShape;
  35117. maintainShapeProportions = maintainShapeProportions_;
  35118. shadow.setShadowProperties (3.0f, 0.5f, 0, 0);
  35119. setComponentEffect ((hasShadow) ? &shadow : 0);
  35120. if (resizeNowToFitThisShape)
  35121. {
  35122. Rectangle<float> bounds (shape.getBounds());
  35123. if (hasShadow)
  35124. bounds.expand (4.0f, 4.0f);
  35125. shape.applyTransform (AffineTransform::translation (-bounds.getX(), -bounds.getY()));
  35126. setSize (1 + (int) (bounds.getWidth() + outlineWidth),
  35127. 1 + (int) (bounds.getHeight() + outlineWidth));
  35128. }
  35129. }
  35130. void ShapeButton::paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  35131. {
  35132. if (! isEnabled())
  35133. {
  35134. isMouseOverButton = false;
  35135. isButtonDown = false;
  35136. }
  35137. g.setColour ((isButtonDown) ? downColour
  35138. : (isMouseOverButton) ? overColour
  35139. : normalColour);
  35140. int w = getWidth();
  35141. int h = getHeight();
  35142. if (getComponentEffect() != 0)
  35143. {
  35144. w -= 4;
  35145. h -= 4;
  35146. }
  35147. const float offset = (outlineWidth * 0.5f) + (isButtonDown ? 1.5f : 0.0f);
  35148. const AffineTransform trans (shape.getTransformToScaleToFit (offset, offset,
  35149. w - offset - outlineWidth,
  35150. h - offset - outlineWidth,
  35151. maintainShapeProportions));
  35152. g.fillPath (shape, trans);
  35153. if (outlineWidth > 0.0f)
  35154. {
  35155. g.setColour (outlineColour);
  35156. g.strokePath (shape, PathStrokeType (outlineWidth), trans);
  35157. }
  35158. }
  35159. END_JUCE_NAMESPACE
  35160. /*** End of inlined file: juce_ShapeButton.cpp ***/
  35161. /*** Start of inlined file: juce_TextButton.cpp ***/
  35162. BEGIN_JUCE_NAMESPACE
  35163. TextButton::TextButton (const String& name,
  35164. const String& toolTip)
  35165. : Button (name)
  35166. {
  35167. setTooltip (toolTip);
  35168. }
  35169. TextButton::~TextButton()
  35170. {
  35171. }
  35172. void TextButton::paintButton (Graphics& g,
  35173. bool isMouseOverButton,
  35174. bool isButtonDown)
  35175. {
  35176. getLookAndFeel().drawButtonBackground (g, *this,
  35177. findColour (getToggleState() ? buttonOnColourId
  35178. : buttonColourId),
  35179. isMouseOverButton,
  35180. isButtonDown);
  35181. getLookAndFeel().drawButtonText (g, *this,
  35182. isMouseOverButton,
  35183. isButtonDown);
  35184. }
  35185. void TextButton::colourChanged()
  35186. {
  35187. repaint();
  35188. }
  35189. const Font TextButton::getFont()
  35190. {
  35191. return Font (jmin (15.0f, getHeight() * 0.6f));
  35192. }
  35193. void TextButton::changeWidthToFitText (const int newHeight)
  35194. {
  35195. if (newHeight >= 0)
  35196. setSize (jmax (1, getWidth()), newHeight);
  35197. setSize (getFont().getStringWidth (getButtonText()) + getHeight(),
  35198. getHeight());
  35199. }
  35200. END_JUCE_NAMESPACE
  35201. /*** End of inlined file: juce_TextButton.cpp ***/
  35202. /*** Start of inlined file: juce_ToggleButton.cpp ***/
  35203. BEGIN_JUCE_NAMESPACE
  35204. ToggleButton::ToggleButton (const String& buttonText)
  35205. : Button (buttonText)
  35206. {
  35207. setClickingTogglesState (true);
  35208. }
  35209. ToggleButton::~ToggleButton()
  35210. {
  35211. }
  35212. void ToggleButton::paintButton (Graphics& g,
  35213. bool isMouseOverButton,
  35214. bool isButtonDown)
  35215. {
  35216. getLookAndFeel().drawToggleButton (g, *this,
  35217. isMouseOverButton,
  35218. isButtonDown);
  35219. }
  35220. void ToggleButton::changeWidthToFitText()
  35221. {
  35222. getLookAndFeel().changeToggleButtonWidthToFitText (*this);
  35223. }
  35224. void ToggleButton::colourChanged()
  35225. {
  35226. repaint();
  35227. }
  35228. END_JUCE_NAMESPACE
  35229. /*** End of inlined file: juce_ToggleButton.cpp ***/
  35230. /*** Start of inlined file: juce_ToolbarButton.cpp ***/
  35231. BEGIN_JUCE_NAMESPACE
  35232. ToolbarButton::ToolbarButton (const int itemId_,
  35233. const String& buttonText,
  35234. Drawable* const normalImage_,
  35235. Drawable* const toggledOnImage_)
  35236. : ToolbarItemComponent (itemId_, buttonText, true),
  35237. normalImage (normalImage_),
  35238. toggledOnImage (toggledOnImage_)
  35239. {
  35240. }
  35241. ToolbarButton::~ToolbarButton()
  35242. {
  35243. }
  35244. bool ToolbarButton::getToolbarItemSizes (int toolbarDepth,
  35245. bool /*isToolbarVertical*/,
  35246. int& preferredSize,
  35247. int& minSize, int& maxSize)
  35248. {
  35249. preferredSize = minSize = maxSize = toolbarDepth;
  35250. return true;
  35251. }
  35252. void ToolbarButton::paintButtonArea (Graphics& g,
  35253. int width, int height,
  35254. bool /*isMouseOver*/,
  35255. bool /*isMouseDown*/)
  35256. {
  35257. Drawable* d = normalImage;
  35258. if (getToggleState() && toggledOnImage != 0)
  35259. d = toggledOnImage;
  35260. if (! isEnabled())
  35261. {
  35262. Image im (Image::ARGB, width, height, true);
  35263. Graphics g2 (im);
  35264. d->drawWithin (g2, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  35265. im.desaturate();
  35266. g.drawImageAt (&im, 0, 0);
  35267. }
  35268. else
  35269. {
  35270. d->drawWithin (g, 0, 0, width, height, RectanglePlacement::centred, 1.0f);
  35271. }
  35272. }
  35273. void ToolbarButton::contentAreaChanged (const Rectangle<int>&)
  35274. {
  35275. }
  35276. END_JUCE_NAMESPACE
  35277. /*** End of inlined file: juce_ToolbarButton.cpp ***/
  35278. /*** Start of inlined file: juce_CodeDocument.cpp ***/
  35279. BEGIN_JUCE_NAMESPACE
  35280. class CodeDocumentLine
  35281. {
  35282. public:
  35283. CodeDocumentLine (const tchar* const line_,
  35284. const int lineLength_,
  35285. const int numNewLineChars,
  35286. const int lineStartInFile_)
  35287. : line (line_, lineLength_),
  35288. lineStartInFile (lineStartInFile_),
  35289. lineLength (lineLength_),
  35290. lineLengthWithoutNewLines (lineLength_ - numNewLineChars)
  35291. {
  35292. }
  35293. ~CodeDocumentLine()
  35294. {
  35295. }
  35296. static void createLines (Array <CodeDocumentLine*>& newLines, const String& text)
  35297. {
  35298. const tchar* const t = (const tchar*) text;
  35299. int pos = 0;
  35300. while (t [pos] != 0)
  35301. {
  35302. const int startOfLine = pos;
  35303. int numNewLineChars = 0;
  35304. while (t[pos] != 0)
  35305. {
  35306. if (t[pos] == T('\r'))
  35307. {
  35308. ++numNewLineChars;
  35309. ++pos;
  35310. if (t[pos] == T('\n'))
  35311. {
  35312. ++numNewLineChars;
  35313. ++pos;
  35314. }
  35315. break;
  35316. }
  35317. if (t[pos] == T('\n'))
  35318. {
  35319. ++numNewLineChars;
  35320. ++pos;
  35321. break;
  35322. }
  35323. ++pos;
  35324. }
  35325. newLines.add (new CodeDocumentLine (t + startOfLine, pos - startOfLine,
  35326. numNewLineChars, startOfLine));
  35327. }
  35328. jassert (pos == text.length());
  35329. }
  35330. bool endsWithLineBreak() const throw()
  35331. {
  35332. return lineLengthWithoutNewLines != lineLength;
  35333. }
  35334. void updateLength() throw()
  35335. {
  35336. lineLengthWithoutNewLines = lineLength = line.length();
  35337. while (lineLengthWithoutNewLines > 0
  35338. && (line [lineLengthWithoutNewLines - 1] == '\n'
  35339. || line [lineLengthWithoutNewLines - 1] == '\r'))
  35340. {
  35341. --lineLengthWithoutNewLines;
  35342. }
  35343. }
  35344. String line;
  35345. int lineStartInFile, lineLength, lineLengthWithoutNewLines;
  35346. };
  35347. CodeDocument::Iterator::Iterator (CodeDocument* const document_)
  35348. : document (document_),
  35349. currentLine (document_->lines[0]),
  35350. line (0),
  35351. position (0)
  35352. {
  35353. }
  35354. CodeDocument::Iterator::Iterator (const CodeDocument::Iterator& other)
  35355. : document (other.document),
  35356. currentLine (other.currentLine),
  35357. line (other.line),
  35358. position (other.position)
  35359. {
  35360. }
  35361. CodeDocument::Iterator& CodeDocument::Iterator::operator= (const CodeDocument::Iterator& other) throw()
  35362. {
  35363. document = other.document;
  35364. currentLine = other.currentLine;
  35365. line = other.line;
  35366. position = other.position;
  35367. return *this;
  35368. }
  35369. CodeDocument::Iterator::~Iterator() throw()
  35370. {
  35371. }
  35372. juce_wchar CodeDocument::Iterator::nextChar()
  35373. {
  35374. if (currentLine == 0)
  35375. return 0;
  35376. jassert (currentLine == document->lines.getUnchecked (line));
  35377. const juce_wchar result = currentLine->line [position - currentLine->lineStartInFile];
  35378. skip();
  35379. return result;
  35380. }
  35381. void CodeDocument::Iterator::skip()
  35382. {
  35383. if (currentLine != 0)
  35384. {
  35385. jassert (currentLine == document->lines.getUnchecked (line));
  35386. if (++position >= currentLine->lineStartInFile + currentLine->lineLength)
  35387. {
  35388. ++line;
  35389. currentLine = document->lines [line];
  35390. }
  35391. }
  35392. }
  35393. void CodeDocument::Iterator::skipToEndOfLine()
  35394. {
  35395. if (currentLine != 0)
  35396. {
  35397. jassert (currentLine == document->lines.getUnchecked (line));
  35398. ++line;
  35399. currentLine = document->lines [line];
  35400. if (currentLine != 0)
  35401. position = currentLine->lineStartInFile;
  35402. else
  35403. position = document->getNumCharacters();
  35404. }
  35405. }
  35406. juce_wchar CodeDocument::Iterator::peekNextChar() const
  35407. {
  35408. if (currentLine == 0)
  35409. return 0;
  35410. jassert (currentLine == document->lines.getUnchecked (line));
  35411. return currentLine->line [position - currentLine->lineStartInFile];
  35412. }
  35413. void CodeDocument::Iterator::skipWhitespace()
  35414. {
  35415. while (CharacterFunctions::isWhitespace (peekNextChar()))
  35416. skip();
  35417. }
  35418. bool CodeDocument::Iterator::isEOF() const throw()
  35419. {
  35420. return currentLine == 0;
  35421. }
  35422. CodeDocument::Position::Position() throw()
  35423. : owner (0), characterPos (0), line (0),
  35424. indexInLine (0), positionMaintained (false)
  35425. {
  35426. }
  35427. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35428. const int line_, const int indexInLine_) throw()
  35429. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35430. characterPos (0), line (line_),
  35431. indexInLine (indexInLine_), positionMaintained (false)
  35432. {
  35433. setLineAndIndex (line_, indexInLine_);
  35434. }
  35435. CodeDocument::Position::Position (const CodeDocument* const ownerDocument,
  35436. const int characterPos_) throw()
  35437. : owner (const_cast <CodeDocument*> (ownerDocument)),
  35438. positionMaintained (false)
  35439. {
  35440. setPosition (characterPos_);
  35441. }
  35442. CodeDocument::Position::Position (const Position& other) throw()
  35443. : owner (other.owner), characterPos (other.characterPos), line (other.line),
  35444. indexInLine (other.indexInLine), positionMaintained (false)
  35445. {
  35446. jassert (*this == other);
  35447. }
  35448. CodeDocument::Position::~Position() throw()
  35449. {
  35450. setPositionMaintained (false);
  35451. }
  35452. CodeDocument::Position& CodeDocument::Position::operator= (const Position& other) throw()
  35453. {
  35454. if (this != &other)
  35455. {
  35456. const bool wasPositionMaintained = positionMaintained;
  35457. if (owner != other.owner)
  35458. setPositionMaintained (false);
  35459. owner = other.owner;
  35460. line = other.line;
  35461. indexInLine = other.indexInLine;
  35462. characterPos = other.characterPos;
  35463. setPositionMaintained (wasPositionMaintained);
  35464. jassert (*this == other);
  35465. }
  35466. return *this;
  35467. }
  35468. bool CodeDocument::Position::operator== (const Position& other) const throw()
  35469. {
  35470. jassert ((characterPos == other.characterPos)
  35471. == (line == other.line && indexInLine == other.indexInLine));
  35472. return characterPos == other.characterPos
  35473. && line == other.line
  35474. && indexInLine == other.indexInLine
  35475. && owner == other.owner;
  35476. }
  35477. bool CodeDocument::Position::operator!= (const Position& other) const throw()
  35478. {
  35479. return ! operator== (other);
  35480. }
  35481. void CodeDocument::Position::setLineAndIndex (const int newLine, const int newIndexInLine) throw()
  35482. {
  35483. jassert (owner != 0);
  35484. if (owner->lines.size() == 0)
  35485. {
  35486. line = 0;
  35487. indexInLine = 0;
  35488. characterPos = 0;
  35489. }
  35490. else
  35491. {
  35492. if (newLine >= owner->lines.size())
  35493. {
  35494. line = owner->lines.size() - 1;
  35495. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35496. jassert (l != 0);
  35497. indexInLine = l->lineLengthWithoutNewLines;
  35498. characterPos = l->lineStartInFile + indexInLine;
  35499. }
  35500. else
  35501. {
  35502. line = jmax (0, newLine);
  35503. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35504. jassert (l != 0);
  35505. if (l->lineLengthWithoutNewLines > 0)
  35506. indexInLine = jlimit (0, l->lineLengthWithoutNewLines, newIndexInLine);
  35507. else
  35508. indexInLine = 0;
  35509. characterPos = l->lineStartInFile + indexInLine;
  35510. }
  35511. }
  35512. }
  35513. void CodeDocument::Position::setPosition (const int newPosition) throw()
  35514. {
  35515. jassert (owner != 0);
  35516. line = 0;
  35517. indexInLine = 0;
  35518. characterPos = 0;
  35519. if (newPosition > 0)
  35520. {
  35521. int lineStart = 0;
  35522. int lineEnd = owner->lines.size();
  35523. for (;;)
  35524. {
  35525. if (lineEnd - lineStart < 4)
  35526. {
  35527. for (int i = lineStart; i < lineEnd; ++i)
  35528. {
  35529. CodeDocumentLine* const l = owner->lines.getUnchecked (i);
  35530. int index = newPosition - l->lineStartInFile;
  35531. if (index >= 0 && (index < l->lineLength || i == lineEnd - 1))
  35532. {
  35533. line = i;
  35534. indexInLine = jmin (l->lineLengthWithoutNewLines, index);
  35535. characterPos = l->lineStartInFile + indexInLine;
  35536. }
  35537. }
  35538. break;
  35539. }
  35540. else
  35541. {
  35542. const int midIndex = (lineStart + lineEnd + 1) / 2;
  35543. CodeDocumentLine* const mid = owner->lines.getUnchecked (midIndex);
  35544. if (newPosition >= mid->lineStartInFile)
  35545. lineStart = midIndex;
  35546. else
  35547. lineEnd = midIndex;
  35548. }
  35549. }
  35550. }
  35551. }
  35552. void CodeDocument::Position::moveBy (int characterDelta) throw()
  35553. {
  35554. jassert (owner != 0);
  35555. if (characterDelta == 1)
  35556. {
  35557. setPosition (getPosition());
  35558. // If moving right, make sure we don't get stuck between the \r and \n characters..
  35559. if (line < owner->lines.size())
  35560. {
  35561. CodeDocumentLine* const l = owner->lines.getUnchecked (line);
  35562. if (indexInLine + characterDelta < l->lineLength
  35563. && indexInLine + characterDelta >= l->lineLengthWithoutNewLines + 1)
  35564. ++characterDelta;
  35565. }
  35566. }
  35567. setPosition (characterPos + characterDelta);
  35568. }
  35569. const CodeDocument::Position CodeDocument::Position::movedBy (const int characterDelta) const throw()
  35570. {
  35571. CodeDocument::Position p (*this);
  35572. p.moveBy (characterDelta);
  35573. return p;
  35574. }
  35575. const CodeDocument::Position CodeDocument::Position::movedByLines (const int deltaLines) const throw()
  35576. {
  35577. CodeDocument::Position p (*this);
  35578. p.setLineAndIndex (getLineNumber() + deltaLines, getIndexInLine());
  35579. return p;
  35580. }
  35581. const tchar CodeDocument::Position::getCharacter() const throw()
  35582. {
  35583. const CodeDocumentLine* const l = owner->lines [line];
  35584. return l == 0 ? 0 : l->line [getIndexInLine()];
  35585. }
  35586. const String CodeDocument::Position::getLineText() const throw()
  35587. {
  35588. const CodeDocumentLine* const l = owner->lines [line];
  35589. return l == 0 ? String::empty : l->line;
  35590. }
  35591. void CodeDocument::Position::setPositionMaintained (const bool isMaintained) throw()
  35592. {
  35593. if (isMaintained != positionMaintained)
  35594. {
  35595. positionMaintained = isMaintained;
  35596. if (owner != 0)
  35597. {
  35598. if (isMaintained)
  35599. {
  35600. jassert (! owner->positionsToMaintain.contains (this));
  35601. owner->positionsToMaintain.add (this);
  35602. }
  35603. else
  35604. {
  35605. jassert (owner->positionsToMaintain.contains (this));
  35606. owner->positionsToMaintain.removeValue (this);
  35607. }
  35608. }
  35609. }
  35610. }
  35611. CodeDocument::CodeDocument()
  35612. : undoManager (std::numeric_limits<int>::max(), 10000),
  35613. currentActionIndex (0),
  35614. indexOfSavedState (-1),
  35615. maximumLineLength (-1),
  35616. newLineChars ("\r\n")
  35617. {
  35618. }
  35619. CodeDocument::~CodeDocument()
  35620. {
  35621. }
  35622. const String CodeDocument::getAllContent() const throw()
  35623. {
  35624. return getTextBetween (Position (this, 0),
  35625. Position (this, lines.size(), 0));
  35626. }
  35627. const String CodeDocument::getTextBetween (const Position& start, const Position& end) const throw()
  35628. {
  35629. if (end.getPosition() <= start.getPosition())
  35630. return String::empty;
  35631. const int startLine = start.getLineNumber();
  35632. const int endLine = end.getLineNumber();
  35633. if (startLine == endLine)
  35634. {
  35635. CodeDocumentLine* const line = lines [startLine];
  35636. return (line == 0) ? String::empty : line->line.substring (start.getIndexInLine(), end.getIndexInLine());
  35637. }
  35638. String result;
  35639. result.preallocateStorage (end.getPosition() - start.getPosition() + 4);
  35640. String::Concatenator concatenator (result);
  35641. const int maxLine = jmin (lines.size() - 1, endLine);
  35642. for (int i = jmax (0, startLine); i <= maxLine; ++i)
  35643. {
  35644. const CodeDocumentLine* line = lines.getUnchecked(i);
  35645. int len = line->lineLength;
  35646. if (i == startLine)
  35647. {
  35648. const int index = start.getIndexInLine();
  35649. concatenator.append (line->line.substring (index, len));
  35650. }
  35651. else if (i == endLine)
  35652. {
  35653. len = end.getIndexInLine();
  35654. concatenator.append (line->line.substring (0, len));
  35655. }
  35656. else
  35657. {
  35658. concatenator.append (line->line);
  35659. }
  35660. }
  35661. return result;
  35662. }
  35663. int CodeDocument::getNumCharacters() const throw()
  35664. {
  35665. const CodeDocumentLine* const lastLine = lines.getLast();
  35666. return (lastLine == 0) ? 0 : lastLine->lineStartInFile + lastLine->lineLength;
  35667. }
  35668. const String CodeDocument::getLine (const int lineIndex) const throw()
  35669. {
  35670. const CodeDocumentLine* const line = lines [lineIndex];
  35671. return (line == 0) ? String::empty : line->line;
  35672. }
  35673. int CodeDocument::getMaximumLineLength() throw()
  35674. {
  35675. if (maximumLineLength < 0)
  35676. {
  35677. maximumLineLength = 0;
  35678. for (int i = lines.size(); --i >= 0;)
  35679. maximumLineLength = jmax (maximumLineLength, lines.getUnchecked(i)->lineLength);
  35680. }
  35681. return maximumLineLength;
  35682. }
  35683. void CodeDocument::deleteSection (const Position& startPosition, const Position& endPosition)
  35684. {
  35685. remove (startPosition.getPosition(), endPosition.getPosition(), true);
  35686. }
  35687. void CodeDocument::insertText (const Position& position, const String& text)
  35688. {
  35689. insert (text, position.getPosition(), true);
  35690. }
  35691. void CodeDocument::replaceAllContent (const String& newContent)
  35692. {
  35693. remove (0, getNumCharacters(), true);
  35694. insert (newContent, 0, true);
  35695. }
  35696. bool CodeDocument::loadFromStream (InputStream& stream)
  35697. {
  35698. replaceAllContent (stream.readEntireStreamAsString());
  35699. setSavePoint();
  35700. clearUndoHistory();
  35701. return true;
  35702. }
  35703. bool CodeDocument::writeToStream (OutputStream& stream)
  35704. {
  35705. for (int i = 0; i < lines.size(); ++i)
  35706. {
  35707. String temp (lines.getUnchecked(i)->line); // use a copy to avoid bloating the memory footprint of the stored string.
  35708. const char* utf8 = temp.toUTF8();
  35709. if (! stream.write (utf8, (int) strlen (utf8)))
  35710. return false;
  35711. }
  35712. return true;
  35713. }
  35714. void CodeDocument::setNewLineCharacters (const String& newLine) throw()
  35715. {
  35716. jassert (newLine == T("\r\n") || newLine == T("\n") || newLine == T("\r"));
  35717. newLineChars = newLine;
  35718. }
  35719. void CodeDocument::newTransaction()
  35720. {
  35721. undoManager.beginNewTransaction (String::empty);
  35722. }
  35723. void CodeDocument::undo()
  35724. {
  35725. newTransaction();
  35726. undoManager.undo();
  35727. }
  35728. void CodeDocument::redo()
  35729. {
  35730. undoManager.redo();
  35731. }
  35732. void CodeDocument::clearUndoHistory()
  35733. {
  35734. undoManager.clearUndoHistory();
  35735. }
  35736. void CodeDocument::setSavePoint() throw()
  35737. {
  35738. indexOfSavedState = currentActionIndex;
  35739. }
  35740. bool CodeDocument::hasChangedSinceSavePoint() const throw()
  35741. {
  35742. return currentActionIndex != indexOfSavedState;
  35743. }
  35744. static int getCodeCharacterCategory (const tchar character) throw()
  35745. {
  35746. return (CharacterFunctions::isLetterOrDigit (character) || character == '_')
  35747. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  35748. }
  35749. const CodeDocument::Position CodeDocument::findWordBreakAfter (const Position& position) const throw()
  35750. {
  35751. Position p (position);
  35752. const int maxDistance = 256;
  35753. int i = 0;
  35754. while (i < maxDistance
  35755. && CharacterFunctions::isWhitespace (p.getCharacter())
  35756. && (i == 0 || (p.getCharacter() != T('\n')
  35757. && p.getCharacter() != T('\r'))))
  35758. {
  35759. ++i;
  35760. p.moveBy (1);
  35761. }
  35762. if (i == 0)
  35763. {
  35764. const int type = getCodeCharacterCategory (p.getCharacter());
  35765. while (i < maxDistance && type == getCodeCharacterCategory (p.getCharacter()))
  35766. {
  35767. ++i;
  35768. p.moveBy (1);
  35769. }
  35770. while (i < maxDistance
  35771. && CharacterFunctions::isWhitespace (p.getCharacter())
  35772. && (i == 0 || (p.getCharacter() != T('\n')
  35773. && p.getCharacter() != T('\r'))))
  35774. {
  35775. ++i;
  35776. p.moveBy (1);
  35777. }
  35778. }
  35779. return p;
  35780. }
  35781. const CodeDocument::Position CodeDocument::findWordBreakBefore (const Position& position) const throw()
  35782. {
  35783. Position p (position);
  35784. const int maxDistance = 256;
  35785. int i = 0;
  35786. bool stoppedAtLineStart = false;
  35787. while (i < maxDistance)
  35788. {
  35789. const tchar c = p.movedBy (-1).getCharacter();
  35790. if (c == T('\r') || c == T('\n'))
  35791. {
  35792. stoppedAtLineStart = true;
  35793. if (i > 0)
  35794. break;
  35795. }
  35796. if (! CharacterFunctions::isWhitespace (c))
  35797. break;
  35798. p.moveBy (-1);
  35799. ++i;
  35800. }
  35801. if (i < maxDistance && ! stoppedAtLineStart)
  35802. {
  35803. const int type = getCodeCharacterCategory (p.movedBy (-1).getCharacter());
  35804. while (i < maxDistance && type == getCodeCharacterCategory (p.movedBy (-1).getCharacter()))
  35805. {
  35806. p.moveBy (-1);
  35807. ++i;
  35808. }
  35809. }
  35810. return p;
  35811. }
  35812. void CodeDocument::checkLastLineStatus()
  35813. {
  35814. while (lines.size() > 0
  35815. && lines.getLast()->lineLength == 0
  35816. && (lines.size() == 1 || ! lines.getUnchecked (lines.size() - 2)->endsWithLineBreak()))
  35817. {
  35818. // remove any empty lines at the end if the preceding line doesn't end in a newline.
  35819. lines.removeLast();
  35820. }
  35821. const CodeDocumentLine* const lastLine = lines.getLast();
  35822. if (lastLine != 0 && lastLine->endsWithLineBreak())
  35823. {
  35824. // check that there's an empty line at the end if the preceding one ends in a newline..
  35825. lines.add (new CodeDocumentLine (String::empty, 0, 0, lastLine->lineStartInFile + lastLine->lineLength));
  35826. }
  35827. }
  35828. void CodeDocument::addListener (CodeDocument::Listener* const listener) throw()
  35829. {
  35830. listeners.addIfNotAlreadyThere (listener);
  35831. }
  35832. void CodeDocument::removeListener (CodeDocument::Listener* const listener) throw()
  35833. {
  35834. listeners.removeValue (listener);
  35835. }
  35836. void CodeDocument::sendListenerChangeMessage (const int startLine, const int endLine)
  35837. {
  35838. const Position startPos (this, startLine, 0);
  35839. const Position endPos (this, endLine, 0);
  35840. for (int i = listeners.size(); --i >= 0;)
  35841. {
  35842. Listener* const l = (Listener*) listeners[i];
  35843. if (l != 0)
  35844. l->codeDocumentChanged (startPos, endPos);
  35845. }
  35846. }
  35847. class CodeDocumentInsertAction : public UndoableAction
  35848. {
  35849. CodeDocument& owner;
  35850. const String text;
  35851. int insertPos;
  35852. CodeDocumentInsertAction (const CodeDocumentInsertAction&);
  35853. CodeDocumentInsertAction& operator= (const CodeDocumentInsertAction&);
  35854. public:
  35855. CodeDocumentInsertAction (CodeDocument& owner_, const String& text_, const int insertPos_) throw()
  35856. : owner (owner_),
  35857. text (text_),
  35858. insertPos (insertPos_)
  35859. {
  35860. }
  35861. ~CodeDocumentInsertAction() {}
  35862. bool perform()
  35863. {
  35864. owner.currentActionIndex++;
  35865. owner.insert (text, insertPos, false);
  35866. return true;
  35867. }
  35868. bool undo()
  35869. {
  35870. owner.currentActionIndex--;
  35871. owner.remove (insertPos, insertPos + text.length(), false);
  35872. return true;
  35873. }
  35874. int getSizeInUnits() { return text.length() + 32; }
  35875. };
  35876. void CodeDocument::insert (const String& text, const int insertPos, const bool undoable)
  35877. {
  35878. if (text.isEmpty())
  35879. return;
  35880. if (undoable)
  35881. {
  35882. undoManager.perform (new CodeDocumentInsertAction (*this, text, insertPos));
  35883. }
  35884. else
  35885. {
  35886. Position pos (this, insertPos);
  35887. const int firstAffectedLine = pos.getLineNumber();
  35888. int lastAffectedLine = firstAffectedLine + 1;
  35889. CodeDocumentLine* const firstLine = lines [firstAffectedLine];
  35890. String textInsideOriginalLine (text);
  35891. if (firstLine != 0)
  35892. {
  35893. const int index = pos.getIndexInLine();
  35894. textInsideOriginalLine = firstLine->line.substring (0, index)
  35895. + textInsideOriginalLine
  35896. + firstLine->line.substring (index);
  35897. }
  35898. maximumLineLength = -1;
  35899. Array <CodeDocumentLine*> newLines;
  35900. CodeDocumentLine::createLines (newLines, textInsideOriginalLine);
  35901. jassert (newLines.size() > 0);
  35902. CodeDocumentLine* const newFirstLine = newLines.getUnchecked (0);
  35903. newFirstLine->lineStartInFile = firstLine != 0 ? firstLine->lineStartInFile : 0;
  35904. lines.set (firstAffectedLine, newFirstLine);
  35905. if (newLines.size() > 1)
  35906. {
  35907. for (int i = 1; i < newLines.size(); ++i)
  35908. {
  35909. CodeDocumentLine* const l = newLines.getUnchecked (i);
  35910. lines.insert (firstAffectedLine + i, l);
  35911. }
  35912. lastAffectedLine = lines.size();
  35913. }
  35914. int i, lineStart = newFirstLine->lineStartInFile;
  35915. for (i = firstAffectedLine; i < lines.size(); ++i)
  35916. {
  35917. CodeDocumentLine* const l = lines.getUnchecked (i);
  35918. l->lineStartInFile = lineStart;
  35919. lineStart += l->lineLength;
  35920. }
  35921. checkLastLineStatus();
  35922. const int newTextLength = text.length();
  35923. for (i = 0; i < positionsToMaintain.size(); ++i)
  35924. {
  35925. CodeDocument::Position* const p = positionsToMaintain.getUnchecked(i);
  35926. if (p->getPosition() >= insertPos)
  35927. p->setPosition (p->getPosition() + newTextLength);
  35928. }
  35929. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  35930. }
  35931. }
  35932. class CodeDocumentDeleteAction : public UndoableAction
  35933. {
  35934. CodeDocument& owner;
  35935. int startPos, endPos;
  35936. String removedText;
  35937. CodeDocumentDeleteAction (const CodeDocumentDeleteAction&);
  35938. CodeDocumentDeleteAction& operator= (const CodeDocumentDeleteAction&);
  35939. public:
  35940. CodeDocumentDeleteAction (CodeDocument& owner_, const int startPos_, const int endPos_) throw()
  35941. : owner (owner_),
  35942. startPos (startPos_),
  35943. endPos (endPos_)
  35944. {
  35945. removedText = owner.getTextBetween (CodeDocument::Position (&owner, startPos),
  35946. CodeDocument::Position (&owner, endPos));
  35947. }
  35948. ~CodeDocumentDeleteAction() {}
  35949. bool perform()
  35950. {
  35951. owner.currentActionIndex++;
  35952. owner.remove (startPos, endPos, false);
  35953. return true;
  35954. }
  35955. bool undo()
  35956. {
  35957. owner.currentActionIndex--;
  35958. owner.insert (removedText, startPos, false);
  35959. return true;
  35960. }
  35961. int getSizeInUnits() { return removedText.length() + 32; }
  35962. };
  35963. void CodeDocument::remove (const int startPos, const int endPos, const bool undoable)
  35964. {
  35965. if (endPos <= startPos)
  35966. return;
  35967. if (undoable)
  35968. {
  35969. undoManager.perform (new CodeDocumentDeleteAction (*this, startPos, endPos));
  35970. }
  35971. else
  35972. {
  35973. Position startPosition (this, startPos);
  35974. Position endPosition (this, endPos);
  35975. maximumLineLength = -1;
  35976. const int firstAffectedLine = startPosition.getLineNumber();
  35977. const int endLine = endPosition.getLineNumber();
  35978. int lastAffectedLine = firstAffectedLine + 1;
  35979. CodeDocumentLine* const firstLine = lines.getUnchecked (firstAffectedLine);
  35980. if (firstAffectedLine == endLine)
  35981. {
  35982. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35983. + firstLine->line.substring (endPosition.getIndexInLine());
  35984. firstLine->updateLength();
  35985. }
  35986. else
  35987. {
  35988. lastAffectedLine = lines.size();
  35989. CodeDocumentLine* const lastLine = lines.getUnchecked (endLine);
  35990. jassert (lastLine != 0);
  35991. firstLine->line = firstLine->line.substring (0, startPosition.getIndexInLine())
  35992. + lastLine->line.substring (endPosition.getIndexInLine());
  35993. firstLine->updateLength();
  35994. int numLinesToRemove = endLine - firstAffectedLine;
  35995. lines.removeRange (firstAffectedLine + 1, numLinesToRemove);
  35996. }
  35997. int i;
  35998. for (i = firstAffectedLine + 1; i < lines.size(); ++i)
  35999. {
  36000. CodeDocumentLine* const l = lines.getUnchecked (i);
  36001. const CodeDocumentLine* const previousLine = lines.getUnchecked (i - 1);
  36002. l->lineStartInFile = previousLine->lineStartInFile + previousLine->lineLength;
  36003. }
  36004. checkLastLineStatus();
  36005. const int totalChars = getNumCharacters();
  36006. for (i = 0; i < positionsToMaintain.size(); ++i)
  36007. {
  36008. CodeDocument::Position* p = positionsToMaintain.getUnchecked(i);
  36009. if (p->getPosition() > startPosition.getPosition())
  36010. p->setPosition (jmax (startPos, p->getPosition() + startPos - endPos));
  36011. if (p->getPosition() > totalChars)
  36012. p->setPosition (totalChars);
  36013. }
  36014. sendListenerChangeMessage (firstAffectedLine, lastAffectedLine);
  36015. }
  36016. }
  36017. END_JUCE_NAMESPACE
  36018. /*** End of inlined file: juce_CodeDocument.cpp ***/
  36019. /*** Start of inlined file: juce_CodeEditorComponent.cpp ***/
  36020. BEGIN_JUCE_NAMESPACE
  36021. class CaretComponent : public Component,
  36022. public Timer
  36023. {
  36024. public:
  36025. CaretComponent()
  36026. {
  36027. setAlwaysOnTop (true);
  36028. setInterceptsMouseClicks (false, false);
  36029. }
  36030. ~CaretComponent()
  36031. {
  36032. }
  36033. void paint (Graphics& g)
  36034. {
  36035. if (getParentComponent()->hasKeyboardFocus (true))
  36036. g.fillAll (findColour (CodeEditorComponent::caretColourId));
  36037. }
  36038. void timerCallback()
  36039. {
  36040. setVisible (! isVisible());
  36041. }
  36042. void updatePosition (CodeEditorComponent& owner)
  36043. {
  36044. startTimer (400);
  36045. setVisible (true);
  36046. const Rectangle<int> pos (owner.getCharacterBounds (owner.getCaretPos()));
  36047. setBounds (pos.getX(), pos.getY(), 2, pos.getHeight());
  36048. }
  36049. };
  36050. class CodeEditorComponent::CodeEditorLine
  36051. {
  36052. public:
  36053. CodeEditorLine() throw()
  36054. {
  36055. }
  36056. ~CodeEditorLine() throw()
  36057. {
  36058. }
  36059. bool update (CodeDocument& document, int lineNum,
  36060. CodeDocument::Iterator& source,
  36061. CodeTokeniser* analyser, const int spacesPerTab,
  36062. const CodeDocument::Position& selectionStart,
  36063. const CodeDocument::Position& selectionEnd)
  36064. {
  36065. Array <SyntaxToken> newTokens;
  36066. newTokens.ensureStorageAllocated (8);
  36067. if (analyser == 0)
  36068. {
  36069. newTokens.add (SyntaxToken (document.getLine (lineNum), -1));
  36070. }
  36071. else if (lineNum < document.getNumLines())
  36072. {
  36073. const CodeDocument::Position pos (&document, lineNum, 0);
  36074. createTokens (pos.getPosition(), pos.getLineText(),
  36075. source, analyser, newTokens);
  36076. }
  36077. replaceTabsWithSpaces (newTokens, spacesPerTab);
  36078. int newHighlightStart = 0;
  36079. int newHighlightEnd = 0;
  36080. if (selectionStart.getLineNumber() <= lineNum && selectionEnd.getLineNumber() >= lineNum)
  36081. {
  36082. const String line (document.getLine (lineNum));
  36083. CodeDocument::Position lineStart (&document, lineNum, 0), lineEnd (&document, lineNum + 1, 0);
  36084. newHighlightStart = indexToColumn (jmax (0, selectionStart.getPosition() - lineStart.getPosition()),
  36085. line, spacesPerTab);
  36086. newHighlightEnd = indexToColumn (jmin (lineEnd.getPosition() - lineStart.getPosition(), selectionEnd.getPosition() - lineStart.getPosition()),
  36087. line, spacesPerTab);
  36088. }
  36089. if (newHighlightStart != highlightColumnStart || newHighlightEnd != highlightColumnEnd)
  36090. {
  36091. highlightColumnStart = newHighlightStart;
  36092. highlightColumnEnd = newHighlightEnd;
  36093. }
  36094. else
  36095. {
  36096. if (tokens.size() == newTokens.size())
  36097. {
  36098. bool allTheSame = true;
  36099. for (int i = newTokens.size(); --i >= 0;)
  36100. {
  36101. if (tokens.getReference(i) != newTokens.getReference(i))
  36102. {
  36103. allTheSame = false;
  36104. break;
  36105. }
  36106. }
  36107. if (allTheSame)
  36108. return false;
  36109. }
  36110. }
  36111. tokens.swapWithArray (newTokens);
  36112. return true;
  36113. }
  36114. void draw (CodeEditorComponent& owner, Graphics& g, const Font& font,
  36115. float x, const int y, const int baselineOffset, const int lineHeight,
  36116. const Colour& highlightColour) const throw()
  36117. {
  36118. if (highlightColumnStart < highlightColumnEnd)
  36119. {
  36120. g.setColour (highlightColour);
  36121. g.fillRect (roundToInt (x + highlightColumnStart * owner.getCharWidth()), y,
  36122. roundToInt ((highlightColumnEnd - highlightColumnStart) * owner.getCharWidth()), lineHeight);
  36123. }
  36124. int lastType = std::numeric_limits<int>::min();
  36125. for (int i = 0; i < tokens.size(); ++i)
  36126. {
  36127. SyntaxToken& token = tokens.getReference(i);
  36128. if (lastType != token.tokenType)
  36129. {
  36130. lastType = token.tokenType;
  36131. g.setColour (owner.getColourForTokenType (lastType));
  36132. }
  36133. g.drawSingleLineText (token.text, roundToInt (x), y + baselineOffset);
  36134. if (i < tokens.size() - 1)
  36135. {
  36136. if (token.width < 0)
  36137. token.width = font.getStringWidthFloat (token.text);
  36138. x += token.width;
  36139. }
  36140. }
  36141. }
  36142. private:
  36143. struct SyntaxToken
  36144. {
  36145. String text;
  36146. int tokenType;
  36147. float width;
  36148. SyntaxToken (const String& text_, const int type) throw()
  36149. : text (text_), tokenType (type), width (-1.0f)
  36150. {
  36151. }
  36152. bool operator!= (const SyntaxToken& other) const throw()
  36153. {
  36154. return text != other.text || tokenType != other.tokenType;
  36155. }
  36156. };
  36157. Array <SyntaxToken> tokens;
  36158. int highlightColumnStart, highlightColumnEnd;
  36159. static void createTokens (int startPosition, const String& lineText,
  36160. CodeDocument::Iterator& source,
  36161. CodeTokeniser* analyser,
  36162. Array <SyntaxToken>& newTokens)
  36163. {
  36164. CodeDocument::Iterator lastIterator (source);
  36165. const int lineLength = lineText.length();
  36166. for (;;)
  36167. {
  36168. int tokenType = analyser->readNextToken (source);
  36169. int tokenStart = lastIterator.getPosition();
  36170. int tokenEnd = source.getPosition();
  36171. if (tokenEnd <= tokenStart)
  36172. break;
  36173. tokenEnd -= startPosition;
  36174. if (tokenEnd > 0)
  36175. {
  36176. tokenStart -= startPosition;
  36177. newTokens.add (SyntaxToken (lineText.substring (jmax (0, tokenStart), tokenEnd),
  36178. tokenType));
  36179. if (tokenEnd >= lineLength)
  36180. break;
  36181. }
  36182. lastIterator = source;
  36183. }
  36184. source = lastIterator;
  36185. }
  36186. static void replaceTabsWithSpaces (Array <SyntaxToken>& tokens, const int spacesPerTab) throw()
  36187. {
  36188. int x = 0;
  36189. for (int i = 0; i < tokens.size(); ++i)
  36190. {
  36191. SyntaxToken& t = tokens.getReference(i);
  36192. for (;;)
  36193. {
  36194. int tabPos = t.text.indexOfChar (T('\t'));
  36195. if (tabPos < 0)
  36196. break;
  36197. const int spacesNeeded = spacesPerTab - ((tabPos + x) % spacesPerTab);
  36198. t.text = t.text.replaceSection (tabPos, 1, String::repeatedString (T(" "), spacesNeeded));
  36199. }
  36200. x += t.text.length();
  36201. }
  36202. }
  36203. int indexToColumn (int index, const String& line, int spacesPerTab) const throw()
  36204. {
  36205. jassert (index <= line.length());
  36206. int col = 0;
  36207. for (int i = 0; i < index; ++i)
  36208. {
  36209. if (line[i] != T('\t'))
  36210. ++col;
  36211. else
  36212. col += spacesPerTab - (col % spacesPerTab);
  36213. }
  36214. return col;
  36215. }
  36216. };
  36217. CodeEditorComponent::CodeEditorComponent (CodeDocument& document_,
  36218. CodeTokeniser* const codeTokeniser_)
  36219. : document (document_),
  36220. firstLineOnScreen (0),
  36221. gutter (5),
  36222. spacesPerTab (4),
  36223. lineHeight (0),
  36224. linesOnScreen (0),
  36225. columnsOnScreen (0),
  36226. scrollbarThickness (16),
  36227. columnToTryToMaintain (-1),
  36228. useSpacesForTabs (false),
  36229. xOffset (0),
  36230. codeTokeniser (codeTokeniser_)
  36231. {
  36232. caretPos = CodeDocument::Position (&document_, 0, 0);
  36233. caretPos.setPositionMaintained (true);
  36234. selectionStart = CodeDocument::Position (&document_, 0, 0);
  36235. selectionStart.setPositionMaintained (true);
  36236. selectionEnd = CodeDocument::Position (&document_, 0, 0);
  36237. selectionEnd.setPositionMaintained (true);
  36238. setOpaque (true);
  36239. setMouseCursor (MouseCursor (MouseCursor::IBeamCursor));
  36240. setWantsKeyboardFocus (true);
  36241. addAndMakeVisible (verticalScrollBar = new ScrollBar (true));
  36242. verticalScrollBar->setSingleStepSize (1.0);
  36243. addAndMakeVisible (horizontalScrollBar = new ScrollBar (false));
  36244. horizontalScrollBar->setSingleStepSize (1.0);
  36245. addAndMakeVisible (caret = new CaretComponent());
  36246. Font f (12.0f);
  36247. f.setTypefaceName (Font::getDefaultMonospacedFontName());
  36248. setFont (f);
  36249. resetToDefaultColours();
  36250. verticalScrollBar->addListener (this);
  36251. horizontalScrollBar->addListener (this);
  36252. document.addListener (this);
  36253. }
  36254. CodeEditorComponent::~CodeEditorComponent()
  36255. {
  36256. document.removeListener (this);
  36257. deleteAllChildren();
  36258. }
  36259. void CodeEditorComponent::loadContent (const String& newContent)
  36260. {
  36261. clearCachedIterators (0);
  36262. document.replaceAllContent (newContent);
  36263. document.clearUndoHistory();
  36264. document.setSavePoint();
  36265. caretPos.setPosition (0);
  36266. selectionStart.setPosition (0);
  36267. selectionEnd.setPosition (0);
  36268. scrollToLine (0);
  36269. }
  36270. void CodeEditorComponent::codeDocumentChanged (const CodeDocument::Position& affectedTextStart,
  36271. const CodeDocument::Position& affectedTextEnd)
  36272. {
  36273. clearCachedIterators (affectedTextStart.getLineNumber());
  36274. triggerAsyncUpdate();
  36275. ((CaretComponent*) caret)->updatePosition (*this);
  36276. columnToTryToMaintain = -1;
  36277. if (affectedTextEnd.getPosition() >= selectionStart.getPosition()
  36278. && affectedTextStart.getPosition() <= selectionEnd.getPosition())
  36279. deselectAll();
  36280. if (caretPos.getPosition() > affectedTextEnd.getPosition()
  36281. || caretPos.getPosition() < affectedTextStart.getPosition())
  36282. moveCaretTo (affectedTextStart, false);
  36283. updateScrollBars();
  36284. }
  36285. void CodeEditorComponent::resized()
  36286. {
  36287. linesOnScreen = (getHeight() - scrollbarThickness) / lineHeight;
  36288. columnsOnScreen = (int) ((getWidth() - scrollbarThickness) / charWidth);
  36289. lines.clear();
  36290. rebuildLineTokens();
  36291. ((CaretComponent*) caret)->updatePosition (*this);
  36292. verticalScrollBar->setBounds (getWidth() - scrollbarThickness, 0, scrollbarThickness, getHeight() - scrollbarThickness);
  36293. horizontalScrollBar->setBounds (gutter, getHeight() - scrollbarThickness, getWidth() - scrollbarThickness - gutter, scrollbarThickness);
  36294. updateScrollBars();
  36295. }
  36296. void CodeEditorComponent::paint (Graphics& g)
  36297. {
  36298. handleUpdateNowIfNeeded();
  36299. g.fillAll (findColour (CodeEditorComponent::backgroundColourId));
  36300. g.reduceClipRegion (gutter, 0, verticalScrollBar->getX() - gutter, horizontalScrollBar->getY());
  36301. g.setFont (font);
  36302. const int baselineOffset = (int) font.getAscent();
  36303. const Colour defaultColour (findColour (CodeEditorComponent::defaultTextColourId));
  36304. const Colour highlightColour (findColour (CodeEditorComponent::highlightColourId));
  36305. const Rectangle<int> clip (g.getClipBounds());
  36306. const int firstLineToDraw = jmax (0, clip.getY() / lineHeight);
  36307. const int lastLineToDraw = jmin (lines.size(), clip.getBottom() / lineHeight + 1);
  36308. for (int j = firstLineToDraw; j < lastLineToDraw; ++j)
  36309. {
  36310. lines.getUnchecked(j)->draw (*this, g, font,
  36311. (float) (gutter - xOffset * charWidth),
  36312. lineHeight * j, baselineOffset, lineHeight,
  36313. highlightColour);
  36314. }
  36315. }
  36316. void CodeEditorComponent::setScrollbarThickness (const int thickness) throw()
  36317. {
  36318. if (scrollbarThickness != thickness)
  36319. {
  36320. scrollbarThickness = thickness;
  36321. resized();
  36322. }
  36323. }
  36324. void CodeEditorComponent::handleAsyncUpdate()
  36325. {
  36326. rebuildLineTokens();
  36327. }
  36328. void CodeEditorComponent::rebuildLineTokens()
  36329. {
  36330. cancelPendingUpdate();
  36331. const int numNeeded = linesOnScreen + 1;
  36332. int minLineToRepaint = numNeeded;
  36333. int maxLineToRepaint = 0;
  36334. if (numNeeded != lines.size())
  36335. {
  36336. lines.clear();
  36337. for (int i = numNeeded; --i >= 0;)
  36338. lines.add (new CodeEditorLine());
  36339. minLineToRepaint = 0;
  36340. maxLineToRepaint = numNeeded;
  36341. }
  36342. jassert (numNeeded == lines.size());
  36343. CodeDocument::Iterator source (&document);
  36344. getIteratorForPosition (CodeDocument::Position (&document, firstLineOnScreen, 0).getPosition(), source);
  36345. for (int i = 0; i < numNeeded; ++i)
  36346. {
  36347. CodeEditorLine* const line = lines.getUnchecked(i);
  36348. if (line->update (document, firstLineOnScreen + i, source, codeTokeniser, spacesPerTab,
  36349. selectionStart, selectionEnd))
  36350. {
  36351. minLineToRepaint = jmin (minLineToRepaint, i);
  36352. maxLineToRepaint = jmax (maxLineToRepaint, i);
  36353. }
  36354. }
  36355. if (minLineToRepaint <= maxLineToRepaint)
  36356. {
  36357. repaint (gutter, lineHeight * minLineToRepaint - 1,
  36358. verticalScrollBar->getX() - gutter,
  36359. lineHeight * (1 + maxLineToRepaint - minLineToRepaint) + 2);
  36360. }
  36361. }
  36362. void CodeEditorComponent::moveCaretTo (const CodeDocument::Position& newPos, const bool highlighting)
  36363. {
  36364. caretPos = newPos;
  36365. columnToTryToMaintain = -1;
  36366. if (highlighting)
  36367. {
  36368. if (dragType == notDragging)
  36369. {
  36370. if (abs (caretPos.getPosition() - selectionStart.getPosition())
  36371. < abs (caretPos.getPosition() - selectionEnd.getPosition()))
  36372. dragType = draggingSelectionStart;
  36373. else
  36374. dragType = draggingSelectionEnd;
  36375. }
  36376. if (dragType == draggingSelectionStart)
  36377. {
  36378. selectionStart = caretPos;
  36379. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36380. {
  36381. const CodeDocument::Position temp (selectionStart);
  36382. selectionStart = selectionEnd;
  36383. selectionEnd = temp;
  36384. dragType = draggingSelectionEnd;
  36385. }
  36386. }
  36387. else
  36388. {
  36389. selectionEnd = caretPos;
  36390. if (selectionEnd.getPosition() < selectionStart.getPosition())
  36391. {
  36392. const CodeDocument::Position temp (selectionStart);
  36393. selectionStart = selectionEnd;
  36394. selectionEnd = temp;
  36395. dragType = draggingSelectionStart;
  36396. }
  36397. }
  36398. triggerAsyncUpdate();
  36399. }
  36400. else
  36401. {
  36402. deselectAll();
  36403. }
  36404. ((CaretComponent*) caret)->updatePosition (*this);
  36405. scrollToKeepCaretOnScreen();
  36406. updateScrollBars();
  36407. }
  36408. void CodeEditorComponent::deselectAll()
  36409. {
  36410. if (selectionStart != selectionEnd)
  36411. triggerAsyncUpdate();
  36412. selectionStart = caretPos;
  36413. selectionEnd = caretPos;
  36414. }
  36415. void CodeEditorComponent::updateScrollBars()
  36416. {
  36417. verticalScrollBar->setRangeLimits (0, jmax (document.getNumLines(), firstLineOnScreen + linesOnScreen));
  36418. verticalScrollBar->setCurrentRange (firstLineOnScreen, linesOnScreen);
  36419. horizontalScrollBar->setRangeLimits (0, jmax ((double) document.getMaximumLineLength(), xOffset + columnsOnScreen));
  36420. horizontalScrollBar->setCurrentRange (xOffset, columnsOnScreen);
  36421. }
  36422. void CodeEditorComponent::scrollToLineInternal (int newFirstLineOnScreen)
  36423. {
  36424. newFirstLineOnScreen = jlimit (0, jmax (0, document.getNumLines() - 1),
  36425. newFirstLineOnScreen);
  36426. if (newFirstLineOnScreen != firstLineOnScreen)
  36427. {
  36428. firstLineOnScreen = newFirstLineOnScreen;
  36429. ((CaretComponent*) caret)->updatePosition (*this);
  36430. updateCachedIterators (firstLineOnScreen);
  36431. triggerAsyncUpdate();
  36432. }
  36433. }
  36434. void CodeEditorComponent::scrollToColumnInternal (double column)
  36435. {
  36436. const double newOffset = jlimit (0.0, document.getMaximumLineLength() + 3.0, column);
  36437. if (xOffset != newOffset)
  36438. {
  36439. xOffset = newOffset;
  36440. ((CaretComponent*) caret)->updatePosition (*this);
  36441. repaint();
  36442. }
  36443. }
  36444. void CodeEditorComponent::scrollToLine (int newFirstLineOnScreen)
  36445. {
  36446. scrollToLineInternal (newFirstLineOnScreen);
  36447. updateScrollBars();
  36448. }
  36449. void CodeEditorComponent::scrollToColumn (int newFirstColumnOnScreen)
  36450. {
  36451. scrollToColumnInternal (newFirstColumnOnScreen);
  36452. updateScrollBars();
  36453. }
  36454. void CodeEditorComponent::scrollBy (int deltaLines)
  36455. {
  36456. scrollToLine (firstLineOnScreen + deltaLines);
  36457. }
  36458. void CodeEditorComponent::scrollToKeepCaretOnScreen()
  36459. {
  36460. if (caretPos.getLineNumber() < firstLineOnScreen)
  36461. scrollBy (caretPos.getLineNumber() - firstLineOnScreen);
  36462. else if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36463. scrollBy (caretPos.getLineNumber() - (firstLineOnScreen + linesOnScreen - 1));
  36464. const int column = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36465. if (column >= xOffset + columnsOnScreen - 1)
  36466. scrollToColumn (column + 1 - columnsOnScreen);
  36467. else if (column < xOffset)
  36468. scrollToColumn (column);
  36469. }
  36470. const Rectangle<int> CodeEditorComponent::getCharacterBounds (const CodeDocument::Position& pos) const throw()
  36471. {
  36472. return Rectangle<int> (roundToInt ((gutter - xOffset * charWidth) + indexToColumn (pos.getLineNumber(), pos.getIndexInLine()) * charWidth),
  36473. (pos.getLineNumber() - firstLineOnScreen) * lineHeight,
  36474. roundToInt (charWidth),
  36475. lineHeight);
  36476. }
  36477. const CodeDocument::Position CodeEditorComponent::getPositionAt (int x, int y)
  36478. {
  36479. const int line = y / lineHeight + firstLineOnScreen;
  36480. const int column = roundToInt ((x - (gutter - xOffset * charWidth)) / charWidth);
  36481. const int index = columnToIndex (line, column);
  36482. return CodeDocument::Position (&document, line, index);
  36483. }
  36484. void CodeEditorComponent::insertTextAtCaret (const String& newText)
  36485. {
  36486. document.deleteSection (selectionStart, selectionEnd);
  36487. if (newText.isNotEmpty())
  36488. document.insertText (caretPos, newText);
  36489. scrollToKeepCaretOnScreen();
  36490. }
  36491. void CodeEditorComponent::insertTabAtCaret()
  36492. {
  36493. if (CharacterFunctions::isWhitespace (caretPos.getCharacter())
  36494. && caretPos.getLineNumber() == caretPos.movedBy (1).getLineNumber())
  36495. {
  36496. moveCaretTo (document.findWordBreakAfter (caretPos), false);
  36497. }
  36498. if (useSpacesForTabs)
  36499. {
  36500. const int caretCol = indexToColumn (caretPos.getLineNumber(), caretPos.getIndexInLine());
  36501. const int spacesNeeded = spacesPerTab - (caretCol % spacesPerTab);
  36502. insertTextAtCaret (String::repeatedString (T(" "), spacesNeeded));
  36503. }
  36504. else
  36505. {
  36506. insertTextAtCaret (T("\t"));
  36507. }
  36508. }
  36509. void CodeEditorComponent::cut()
  36510. {
  36511. insertTextAtCaret (String::empty);
  36512. }
  36513. void CodeEditorComponent::copy()
  36514. {
  36515. newTransaction();
  36516. const String selection (document.getTextBetween (selectionStart, selectionEnd));
  36517. if (selection.isNotEmpty())
  36518. SystemClipboard::copyTextToClipboard (selection);
  36519. }
  36520. void CodeEditorComponent::copyThenCut()
  36521. {
  36522. copy();
  36523. cut();
  36524. newTransaction();
  36525. }
  36526. void CodeEditorComponent::paste()
  36527. {
  36528. newTransaction();
  36529. const String clip (SystemClipboard::getTextFromClipboard());
  36530. if (clip.isNotEmpty())
  36531. insertTextAtCaret (clip);
  36532. newTransaction();
  36533. }
  36534. void CodeEditorComponent::cursorLeft (const bool moveInWholeWordSteps, const bool selecting)
  36535. {
  36536. newTransaction();
  36537. if (moveInWholeWordSteps)
  36538. moveCaretTo (document.findWordBreakBefore (caretPos), selecting);
  36539. else
  36540. moveCaretTo (caretPos.movedBy (-1), selecting);
  36541. }
  36542. void CodeEditorComponent::cursorRight (const bool moveInWholeWordSteps, const bool selecting)
  36543. {
  36544. newTransaction();
  36545. if (moveInWholeWordSteps)
  36546. moveCaretTo (document.findWordBreakAfter (caretPos), selecting);
  36547. else
  36548. moveCaretTo (caretPos.movedBy (1), selecting);
  36549. }
  36550. void CodeEditorComponent::moveLineDelta (const int delta, const bool selecting)
  36551. {
  36552. CodeDocument::Position pos (caretPos);
  36553. const int newLineNum = pos.getLineNumber() + delta;
  36554. if (columnToTryToMaintain < 0)
  36555. columnToTryToMaintain = indexToColumn (pos.getLineNumber(), pos.getIndexInLine());
  36556. pos.setLineAndIndex (newLineNum, columnToIndex (newLineNum, columnToTryToMaintain));
  36557. const int colToMaintain = columnToTryToMaintain;
  36558. moveCaretTo (pos, selecting);
  36559. columnToTryToMaintain = colToMaintain;
  36560. }
  36561. void CodeEditorComponent::cursorDown (const bool selecting)
  36562. {
  36563. newTransaction();
  36564. if (caretPos.getLineNumber() == document.getNumLines() - 1)
  36565. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36566. else
  36567. moveLineDelta (1, selecting);
  36568. }
  36569. void CodeEditorComponent::cursorUp (const bool selecting)
  36570. {
  36571. newTransaction();
  36572. if (caretPos.getLineNumber() == 0)
  36573. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36574. else
  36575. moveLineDelta (-1, selecting);
  36576. }
  36577. void CodeEditorComponent::pageDown (const bool selecting)
  36578. {
  36579. newTransaction();
  36580. scrollBy (jlimit (0, linesOnScreen, 1 + document.getNumLines() - firstLineOnScreen - linesOnScreen));
  36581. moveLineDelta (linesOnScreen, selecting);
  36582. }
  36583. void CodeEditorComponent::pageUp (const bool selecting)
  36584. {
  36585. newTransaction();
  36586. scrollBy (-linesOnScreen);
  36587. moveLineDelta (-linesOnScreen, selecting);
  36588. }
  36589. void CodeEditorComponent::scrollUp()
  36590. {
  36591. newTransaction();
  36592. scrollBy (1);
  36593. if (caretPos.getLineNumber() < firstLineOnScreen)
  36594. moveLineDelta (1, false);
  36595. }
  36596. void CodeEditorComponent::scrollDown()
  36597. {
  36598. newTransaction();
  36599. scrollBy (-1);
  36600. if (caretPos.getLineNumber() >= firstLineOnScreen + linesOnScreen)
  36601. moveLineDelta (-1, false);
  36602. }
  36603. void CodeEditorComponent::goToStartOfDocument (const bool selecting)
  36604. {
  36605. newTransaction();
  36606. moveCaretTo (CodeDocument::Position (&document, 0, 0), selecting);
  36607. }
  36608. static int findFirstNonWhitespaceChar (const String& line) throw()
  36609. {
  36610. const int len = line.length();
  36611. for (int i = 0; i < len; ++i)
  36612. if (! CharacterFunctions::isWhitespace (line [i]))
  36613. return i;
  36614. return 0;
  36615. }
  36616. void CodeEditorComponent::goToStartOfLine (const bool selecting)
  36617. {
  36618. newTransaction();
  36619. int index = findFirstNonWhitespaceChar (caretPos.getLineText());
  36620. if (index >= caretPos.getIndexInLine() && caretPos.getIndexInLine() > 0)
  36621. index = 0;
  36622. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), index), selecting);
  36623. }
  36624. void CodeEditorComponent::goToEndOfDocument (const bool selecting)
  36625. {
  36626. newTransaction();
  36627. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), selecting);
  36628. }
  36629. void CodeEditorComponent::goToEndOfLine (const bool selecting)
  36630. {
  36631. newTransaction();
  36632. moveCaretTo (CodeDocument::Position (&document, caretPos.getLineNumber(), std::numeric_limits<int>::max()), selecting);
  36633. }
  36634. void CodeEditorComponent::backspace (const bool moveInWholeWordSteps)
  36635. {
  36636. if (moveInWholeWordSteps)
  36637. {
  36638. cut(); // in case something is already highlighted
  36639. moveCaretTo (document.findWordBreakBefore (caretPos), true);
  36640. }
  36641. else
  36642. {
  36643. if (selectionStart == selectionEnd)
  36644. selectionStart.moveBy (-1);
  36645. }
  36646. cut();
  36647. }
  36648. void CodeEditorComponent::deleteForward (const bool moveInWholeWordSteps)
  36649. {
  36650. if (moveInWholeWordSteps)
  36651. {
  36652. cut(); // in case something is already highlighted
  36653. moveCaretTo (document.findWordBreakAfter (caretPos), true);
  36654. }
  36655. else
  36656. {
  36657. if (selectionStart == selectionEnd)
  36658. selectionEnd.moveBy (1);
  36659. else
  36660. newTransaction();
  36661. }
  36662. cut();
  36663. }
  36664. void CodeEditorComponent::selectAll()
  36665. {
  36666. newTransaction();
  36667. moveCaretTo (CodeDocument::Position (&document, std::numeric_limits<int>::max(), std::numeric_limits<int>::max()), false);
  36668. moveCaretTo (CodeDocument::Position (&document, 0, 0), true);
  36669. }
  36670. void CodeEditorComponent::undo()
  36671. {
  36672. document.undo();
  36673. scrollToKeepCaretOnScreen();
  36674. }
  36675. void CodeEditorComponent::redo()
  36676. {
  36677. document.redo();
  36678. scrollToKeepCaretOnScreen();
  36679. }
  36680. void CodeEditorComponent::newTransaction()
  36681. {
  36682. document.newTransaction();
  36683. startTimer (600);
  36684. }
  36685. void CodeEditorComponent::timerCallback()
  36686. {
  36687. newTransaction();
  36688. }
  36689. const Range<int> CodeEditorComponent::getHighlightedRegion() const
  36690. {
  36691. return Range<int> (selectionStart.getPosition(), selectionEnd.getPosition());
  36692. }
  36693. void CodeEditorComponent::setHighlightedRegion (const Range<int>& newRange)
  36694. {
  36695. moveCaretTo (CodeDocument::Position (&document, newRange.getStart()), false);
  36696. moveCaretTo (CodeDocument::Position (&document, newRange.getEnd()), true);
  36697. }
  36698. const String CodeEditorComponent::getTextInRange (const Range<int>& range) const
  36699. {
  36700. return document.getTextBetween (CodeDocument::Position (&document, range.getStart()),
  36701. CodeDocument::Position (&document, range.getEnd()));
  36702. }
  36703. bool CodeEditorComponent::keyPressed (const KeyPress& key)
  36704. {
  36705. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  36706. const bool shiftDown = key.getModifiers().isShiftDown();
  36707. if (key.isKeyCode (KeyPress::leftKey))
  36708. {
  36709. cursorLeft (moveInWholeWordSteps, shiftDown);
  36710. }
  36711. else if (key.isKeyCode (KeyPress::rightKey))
  36712. {
  36713. cursorRight (moveInWholeWordSteps, shiftDown);
  36714. }
  36715. else if (key.isKeyCode (KeyPress::upKey))
  36716. {
  36717. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36718. scrollDown();
  36719. #if JUCE_MAC
  36720. else if (key.getModifiers().isCommandDown())
  36721. goToStartOfDocument (shiftDown);
  36722. #endif
  36723. else
  36724. cursorUp (shiftDown);
  36725. }
  36726. else if (key.isKeyCode (KeyPress::downKey))
  36727. {
  36728. if (key.getModifiers().isCtrlDown() && ! shiftDown)
  36729. scrollUp();
  36730. #if JUCE_MAC
  36731. else if (key.getModifiers().isCommandDown())
  36732. goToEndOfDocument (shiftDown);
  36733. #endif
  36734. else
  36735. cursorDown (shiftDown);
  36736. }
  36737. else if (key.isKeyCode (KeyPress::pageDownKey))
  36738. {
  36739. pageDown (shiftDown);
  36740. }
  36741. else if (key.isKeyCode (KeyPress::pageUpKey))
  36742. {
  36743. pageUp (shiftDown);
  36744. }
  36745. else if (key.isKeyCode (KeyPress::homeKey))
  36746. {
  36747. if (moveInWholeWordSteps)
  36748. goToStartOfDocument (shiftDown);
  36749. else
  36750. goToStartOfLine (shiftDown);
  36751. }
  36752. else if (key.isKeyCode (KeyPress::endKey))
  36753. {
  36754. if (moveInWholeWordSteps)
  36755. goToEndOfDocument (shiftDown);
  36756. else
  36757. goToEndOfLine (shiftDown);
  36758. }
  36759. else if (key.isKeyCode (KeyPress::backspaceKey))
  36760. {
  36761. backspace (moveInWholeWordSteps);
  36762. }
  36763. else if (key.isKeyCode (KeyPress::deleteKey))
  36764. {
  36765. deleteForward (moveInWholeWordSteps);
  36766. }
  36767. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  36768. {
  36769. copy();
  36770. }
  36771. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  36772. {
  36773. copyThenCut();
  36774. }
  36775. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0))
  36776. {
  36777. paste();
  36778. }
  36779. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  36780. {
  36781. undo();
  36782. }
  36783. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0)
  36784. || key == KeyPress (T('z'), ModifierKeys::commandModifier | ModifierKeys::shiftModifier, 0))
  36785. {
  36786. redo();
  36787. }
  36788. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  36789. {
  36790. selectAll();
  36791. }
  36792. else if (key == KeyPress::tabKey || key.getTextCharacter() == '\t')
  36793. {
  36794. insertTabAtCaret();
  36795. }
  36796. else if (key == KeyPress::returnKey)
  36797. {
  36798. newTransaction();
  36799. insertTextAtCaret (document.getNewLineCharacters());
  36800. }
  36801. else if (key.isKeyCode (KeyPress::escapeKey))
  36802. {
  36803. newTransaction();
  36804. }
  36805. else if (key.getTextCharacter() >= ' ')
  36806. {
  36807. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  36808. }
  36809. else
  36810. {
  36811. return false;
  36812. }
  36813. return true;
  36814. }
  36815. void CodeEditorComponent::mouseDown (const MouseEvent& e)
  36816. {
  36817. newTransaction();
  36818. dragType = notDragging;
  36819. if (! e.mods.isPopupMenu())
  36820. {
  36821. beginDragAutoRepeat (100);
  36822. moveCaretTo (getPositionAt (e.x, e.y), e.mods.isShiftDown());
  36823. }
  36824. else
  36825. {
  36826. }
  36827. }
  36828. void CodeEditorComponent::mouseDrag (const MouseEvent& e)
  36829. {
  36830. if (! e.mods.isPopupMenu())
  36831. moveCaretTo (getPositionAt (e.x, e.y), true);
  36832. }
  36833. void CodeEditorComponent::mouseUp (const MouseEvent&)
  36834. {
  36835. newTransaction();
  36836. beginDragAutoRepeat (0);
  36837. dragType = notDragging;
  36838. }
  36839. void CodeEditorComponent::mouseDoubleClick (const MouseEvent& e)
  36840. {
  36841. CodeDocument::Position tokenStart (getPositionAt (e.x, e.y));
  36842. CodeDocument::Position tokenEnd (tokenStart);
  36843. if (e.getNumberOfClicks() > 2)
  36844. {
  36845. tokenStart.setLineAndIndex (tokenStart.getLineNumber(), 0);
  36846. tokenEnd.setLineAndIndex (tokenStart.getLineNumber() + 1, 0);
  36847. }
  36848. else
  36849. {
  36850. while (CharacterFunctions::isLetterOrDigit (tokenEnd.getCharacter()))
  36851. tokenEnd.moveBy (1);
  36852. tokenStart = tokenEnd;
  36853. while (tokenStart.getIndexInLine() > 0
  36854. && CharacterFunctions::isLetterOrDigit (tokenStart.movedBy (-1).getCharacter()))
  36855. tokenStart.moveBy (-1);
  36856. }
  36857. moveCaretTo (tokenEnd, false);
  36858. moveCaretTo (tokenStart, true);
  36859. }
  36860. void CodeEditorComponent::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  36861. {
  36862. verticalScrollBar->mouseWheelMove (e, 0, wheelIncrementY);
  36863. horizontalScrollBar->mouseWheelMove (e, wheelIncrementX, 0);
  36864. }
  36865. void CodeEditorComponent::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart)
  36866. {
  36867. if (scrollBarThatHasMoved == verticalScrollBar)
  36868. scrollToLineInternal ((int) newRangeStart);
  36869. else
  36870. scrollToColumnInternal (newRangeStart);
  36871. }
  36872. void CodeEditorComponent::setTabSize (const int numSpaces, const bool insertSpaces) throw()
  36873. {
  36874. useSpacesForTabs = insertSpaces;
  36875. if (spacesPerTab != numSpaces)
  36876. {
  36877. spacesPerTab = numSpaces;
  36878. triggerAsyncUpdate();
  36879. }
  36880. }
  36881. int CodeEditorComponent::indexToColumn (int lineNum, int index) const throw()
  36882. {
  36883. const String line (document.getLine (lineNum));
  36884. jassert (index <= line.length());
  36885. int col = 0;
  36886. for (int i = 0; i < index; ++i)
  36887. {
  36888. if (line[i] != T('\t'))
  36889. ++col;
  36890. else
  36891. col += getTabSize() - (col % getTabSize());
  36892. }
  36893. return col;
  36894. }
  36895. int CodeEditorComponent::columnToIndex (int lineNum, int column) const throw()
  36896. {
  36897. const String line (document.getLine (lineNum));
  36898. const int lineLength = line.length();
  36899. int i, col = 0;
  36900. for (i = 0; i < lineLength; ++i)
  36901. {
  36902. if (line[i] != T('\t'))
  36903. ++col;
  36904. else
  36905. col += getTabSize() - (col % getTabSize());
  36906. if (col > column)
  36907. break;
  36908. }
  36909. return i;
  36910. }
  36911. void CodeEditorComponent::setFont (const Font& newFont)
  36912. {
  36913. font = newFont;
  36914. charWidth = font.getStringWidthFloat (T("0"));
  36915. lineHeight = roundToInt (font.getHeight());
  36916. resized();
  36917. }
  36918. void CodeEditorComponent::resetToDefaultColours()
  36919. {
  36920. coloursForTokenCategories.clear();
  36921. if (codeTokeniser != 0)
  36922. {
  36923. for (int i = codeTokeniser->getTokenTypes().size(); --i >= 0;)
  36924. setColourForTokenType (i, codeTokeniser->getDefaultColour (i));
  36925. }
  36926. }
  36927. void CodeEditorComponent::setColourForTokenType (const int tokenType, const Colour& colour)
  36928. {
  36929. jassert (tokenType < 256);
  36930. while (coloursForTokenCategories.size() < tokenType)
  36931. coloursForTokenCategories.add (Colours::black);
  36932. coloursForTokenCategories.set (tokenType, colour);
  36933. repaint();
  36934. }
  36935. const Colour CodeEditorComponent::getColourForTokenType (const int tokenType) const throw()
  36936. {
  36937. if (((unsigned int) tokenType) >= (unsigned int) coloursForTokenCategories.size())
  36938. return findColour (CodeEditorComponent::defaultTextColourId);
  36939. return coloursForTokenCategories.getReference (tokenType);
  36940. }
  36941. void CodeEditorComponent::clearCachedIterators (const int firstLineToBeInvalid) throw()
  36942. {
  36943. int i;
  36944. for (i = cachedIterators.size(); --i >= 0;)
  36945. if (cachedIterators.getUnchecked (i)->getLine() < firstLineToBeInvalid)
  36946. break;
  36947. cachedIterators.removeRange (jmax (0, i - 1), cachedIterators.size());
  36948. }
  36949. void CodeEditorComponent::updateCachedIterators (int maxLineNum)
  36950. {
  36951. const int maxNumCachedPositions = 5000;
  36952. const int linesBetweenCachedSources = jmax (10, document.getNumLines() / maxNumCachedPositions);
  36953. if (cachedIterators.size() == 0)
  36954. cachedIterators.add (new CodeDocument::Iterator (&document));
  36955. if (codeTokeniser == 0)
  36956. return;
  36957. for (;;)
  36958. {
  36959. CodeDocument::Iterator* last = cachedIterators.getLast();
  36960. if (last->getLine() >= maxLineNum)
  36961. break;
  36962. CodeDocument::Iterator* t = new CodeDocument::Iterator (*last);
  36963. cachedIterators.add (t);
  36964. const int targetLine = last->getLine() + linesBetweenCachedSources;
  36965. for (;;)
  36966. {
  36967. codeTokeniser->readNextToken (*t);
  36968. if (t->getLine() >= targetLine)
  36969. break;
  36970. if (t->isEOF())
  36971. return;
  36972. }
  36973. }
  36974. }
  36975. void CodeEditorComponent::getIteratorForPosition (int position, CodeDocument::Iterator& source)
  36976. {
  36977. if (codeTokeniser == 0)
  36978. return;
  36979. for (int i = cachedIterators.size(); --i >= 0;)
  36980. {
  36981. CodeDocument::Iterator* t = cachedIterators.getUnchecked (i);
  36982. if (t->getPosition() <= position)
  36983. {
  36984. source = *t;
  36985. break;
  36986. }
  36987. }
  36988. while (source.getPosition() < position)
  36989. {
  36990. const CodeDocument::Iterator original (source);
  36991. codeTokeniser->readNextToken (source);
  36992. if (source.getPosition() > position || source.isEOF())
  36993. {
  36994. source = original;
  36995. break;
  36996. }
  36997. }
  36998. }
  36999. END_JUCE_NAMESPACE
  37000. /*** End of inlined file: juce_CodeEditorComponent.cpp ***/
  37001. /*** Start of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  37002. BEGIN_JUCE_NAMESPACE
  37003. CPlusPlusCodeTokeniser::CPlusPlusCodeTokeniser()
  37004. {
  37005. }
  37006. CPlusPlusCodeTokeniser::~CPlusPlusCodeTokeniser()
  37007. {
  37008. }
  37009. namespace CppTokeniser
  37010. {
  37011. static bool isIdentifierStart (const tchar c) throw()
  37012. {
  37013. return CharacterFunctions::isLetter (c)
  37014. || c == T('_') || c == T('@');
  37015. }
  37016. static bool isIdentifierBody (const tchar c) throw()
  37017. {
  37018. return CharacterFunctions::isLetter (c)
  37019. || CharacterFunctions::isDigit (c)
  37020. || c == T('_') || c == T('@');
  37021. }
  37022. static int parseIdentifier (CodeDocument::Iterator& source) throw()
  37023. {
  37024. static const tchar* keywords2Char[] =
  37025. { T("if"), T("do"), T("or"), 0 };
  37026. static const tchar* keywords3Char[] =
  37027. { T("for"), T("int"), T("new"), T("try"), T("xor"), T("and"), T("asm"), T("not"), 0 };
  37028. static const tchar* keywords4Char[] =
  37029. { T("bool"), T("void"), T("this"), T("true"), T("long"), T("else"), T("char"),
  37030. T("enum"), T("case"), T("goto"), T("auto"), 0 };
  37031. static const tchar* keywords5Char[] =
  37032. { T("while"), T("bitor"), T("break"), T("catch"), T("class"), T("compl"), T("const"), T("false"),
  37033. T("float"), T("short"), T("throw"), T("union"), T("using"), T("or_eq"), 0 };
  37034. static const tchar* keywords6Char[] =
  37035. { T("return"), T("struct"), T("and_eq"), T("bitand"), T("delete"), T("double"), T("extern"),
  37036. T("friend"), T("inline"), T("not_eq"), T("public"), T("sizeof"), T("static"), T("signed"),
  37037. T("switch"), T("typeid"), T("wchar_t"), T("xor_eq"), 0};
  37038. static const tchar* keywordsOther[] =
  37039. { T("const_cast"), T("continue"), T("default"), T("explicit"), T("mutable"), T("namespace"),
  37040. T("operator"), T("private"), T("protected"), T("register"), T("reinterpret_cast"), T("static_cast"),
  37041. T("template"), T("typedef"), T("typename"), T("unsigned"), T("virtual"), T("volatile"),
  37042. T("@implementation"), T("@interface"), T("@end"), T("@synthesize"), T("@dynamic"), T("@public"),
  37043. T("@private"), T("@property"), T("@protected"), T("@class"), 0 };
  37044. int tokenLength = 0;
  37045. tchar possibleIdentifier [19];
  37046. while (isIdentifierBody (source.peekNextChar()))
  37047. {
  37048. const tchar c = source.nextChar();
  37049. if (tokenLength < numElementsInArray (possibleIdentifier) - 1)
  37050. possibleIdentifier [tokenLength] = c;
  37051. ++tokenLength;
  37052. }
  37053. if (tokenLength > 1 && tokenLength <= 16)
  37054. {
  37055. possibleIdentifier [tokenLength] = 0;
  37056. const tchar** k;
  37057. switch (tokenLength)
  37058. {
  37059. case 2: k = keywords2Char; break;
  37060. case 3: k = keywords3Char; break;
  37061. case 4: k = keywords4Char; break;
  37062. case 5: k = keywords5Char; break;
  37063. case 6: k = keywords6Char; break;
  37064. default: k = keywordsOther; break;
  37065. }
  37066. int i = 0;
  37067. while (k[i] != 0)
  37068. {
  37069. if (k[i][0] == possibleIdentifier[0] && CharacterFunctions::compare (k[i], possibleIdentifier) == 0)
  37070. return CPlusPlusCodeTokeniser::tokenType_builtInKeyword;
  37071. ++i;
  37072. }
  37073. }
  37074. return CPlusPlusCodeTokeniser::tokenType_identifier;
  37075. }
  37076. static bool skipNumberSuffix (CodeDocument::Iterator& source)
  37077. {
  37078. const juce_wchar c = source.peekNextChar();
  37079. if (c == 'l' || c == 'L' || c == 'u' || c == 'U')
  37080. source.skip();
  37081. if (CharacterFunctions::isLetterOrDigit (source.peekNextChar()))
  37082. return false;
  37083. return true;
  37084. }
  37085. static bool isHexDigit (const juce_wchar c) throw()
  37086. {
  37087. return (c >= '0' && c <= '9')
  37088. || (c >= 'a' && c <= 'f')
  37089. || (c >= 'A' && c <= 'F');
  37090. }
  37091. static bool parseHexLiteral (CodeDocument::Iterator& source) throw()
  37092. {
  37093. if (source.nextChar() != '0')
  37094. return false;
  37095. juce_wchar c = source.nextChar();
  37096. if (c != 'x' && c != 'X')
  37097. return false;
  37098. int numDigits = 0;
  37099. while (isHexDigit (source.peekNextChar()))
  37100. {
  37101. ++numDigits;
  37102. source.skip();
  37103. }
  37104. if (numDigits == 0)
  37105. return false;
  37106. return skipNumberSuffix (source);
  37107. }
  37108. static bool isOctalDigit (const juce_wchar c) throw()
  37109. {
  37110. return c >= '0' && c <= '7';
  37111. }
  37112. static bool parseOctalLiteral (CodeDocument::Iterator& source) throw()
  37113. {
  37114. if (source.nextChar() != '0')
  37115. return false;
  37116. if (! isOctalDigit (source.nextChar()))
  37117. return false;
  37118. while (isOctalDigit (source.peekNextChar()))
  37119. source.skip();
  37120. return skipNumberSuffix (source);
  37121. }
  37122. static bool isDecimalDigit (const juce_wchar c) throw()
  37123. {
  37124. return c >= '0' && c <= '9';
  37125. }
  37126. static bool parseDecimalLiteral (CodeDocument::Iterator& source) throw()
  37127. {
  37128. int numChars = 0;
  37129. while (isDecimalDigit (source.peekNextChar()))
  37130. {
  37131. ++numChars;
  37132. source.skip();
  37133. }
  37134. if (numChars == 0)
  37135. return false;
  37136. return skipNumberSuffix (source);
  37137. }
  37138. static bool parseFloatLiteral (CodeDocument::Iterator& source) throw()
  37139. {
  37140. int numDigits = 0;
  37141. while (isDecimalDigit (source.peekNextChar()))
  37142. {
  37143. source.skip();
  37144. ++numDigits;
  37145. }
  37146. const bool hasPoint = (source.peekNextChar() == '.');
  37147. if (hasPoint)
  37148. {
  37149. source.skip();
  37150. while (isDecimalDigit (source.peekNextChar()))
  37151. {
  37152. source.skip();
  37153. ++numDigits;
  37154. }
  37155. }
  37156. if (numDigits == 0)
  37157. return false;
  37158. juce_wchar c = source.peekNextChar();
  37159. const bool hasExponent = (c == 'e' || c == 'E');
  37160. if (hasExponent)
  37161. {
  37162. source.skip();
  37163. c = source.peekNextChar();
  37164. if (c == '+' || c == '-')
  37165. source.skip();
  37166. int numExpDigits = 0;
  37167. while (isDecimalDigit (source.peekNextChar()))
  37168. {
  37169. source.skip();
  37170. ++numExpDigits;
  37171. }
  37172. if (numExpDigits == 0)
  37173. return false;
  37174. }
  37175. c = source.peekNextChar();
  37176. if (c == 'f' || c == 'F')
  37177. source.skip();
  37178. else if (! (hasExponent || hasPoint))
  37179. return false;
  37180. return true;
  37181. }
  37182. static int parseNumber (CodeDocument::Iterator& source)
  37183. {
  37184. const CodeDocument::Iterator original (source);
  37185. if (parseFloatLiteral (source))
  37186. return CPlusPlusCodeTokeniser::tokenType_floatLiteral;
  37187. source = original;
  37188. if (parseHexLiteral (source))
  37189. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37190. source = original;
  37191. if (parseOctalLiteral (source))
  37192. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37193. source = original;
  37194. if (parseDecimalLiteral (source))
  37195. return CPlusPlusCodeTokeniser::tokenType_integerLiteral;
  37196. source = original;
  37197. source.skip();
  37198. return CPlusPlusCodeTokeniser::tokenType_error;
  37199. }
  37200. static void skipQuotedString (CodeDocument::Iterator& source) throw()
  37201. {
  37202. const juce_wchar quote = source.nextChar();
  37203. for (;;)
  37204. {
  37205. const juce_wchar c = source.nextChar();
  37206. if (c == quote || c == 0)
  37207. break;
  37208. if (c == '\\')
  37209. source.skip();
  37210. }
  37211. }
  37212. static void skipComment (CodeDocument::Iterator& source) throw()
  37213. {
  37214. bool lastWasStar = false;
  37215. for (;;)
  37216. {
  37217. const juce_wchar c = source.nextChar();
  37218. if (c == 0 || (c == T('/') && lastWasStar))
  37219. break;
  37220. lastWasStar = (c == '*');
  37221. }
  37222. }
  37223. }
  37224. int CPlusPlusCodeTokeniser::readNextToken (CodeDocument::Iterator& source)
  37225. {
  37226. int result = tokenType_error;
  37227. source.skipWhitespace();
  37228. tchar firstChar = source.peekNextChar();
  37229. switch (firstChar)
  37230. {
  37231. case 0:
  37232. source.skip();
  37233. break;
  37234. case T('0'):
  37235. case T('1'):
  37236. case T('2'):
  37237. case T('3'):
  37238. case T('4'):
  37239. case T('5'):
  37240. case T('6'):
  37241. case T('7'):
  37242. case T('8'):
  37243. case T('9'):
  37244. result = CppTokeniser::parseNumber (source);
  37245. break;
  37246. case T('.'):
  37247. result = CppTokeniser::parseNumber (source);
  37248. if (result == tokenType_error)
  37249. result = tokenType_punctuation;
  37250. break;
  37251. case T(','):
  37252. case T(';'):
  37253. case T(':'):
  37254. source.skip();
  37255. result = tokenType_punctuation;
  37256. break;
  37257. case T('('):
  37258. case T(')'):
  37259. case T('{'):
  37260. case T('}'):
  37261. case T('['):
  37262. case T(']'):
  37263. source.skip();
  37264. result = tokenType_bracket;
  37265. break;
  37266. case T('"'):
  37267. case T('\''):
  37268. CppTokeniser::skipQuotedString (source);
  37269. result = tokenType_stringLiteral;
  37270. break;
  37271. case T('+'):
  37272. result = tokenType_operator;
  37273. source.skip();
  37274. if (source.peekNextChar() == T('+'))
  37275. source.skip();
  37276. else if (source.peekNextChar() == T('='))
  37277. source.skip();
  37278. break;
  37279. case T('-'):
  37280. source.skip();
  37281. result = CppTokeniser::parseNumber (source);
  37282. if (result == tokenType_error)
  37283. {
  37284. result = tokenType_operator;
  37285. if (source.peekNextChar() == T('-'))
  37286. source.skip();
  37287. else if (source.peekNextChar() == T('='))
  37288. source.skip();
  37289. }
  37290. break;
  37291. case T('*'):
  37292. case T('%'):
  37293. case T('='):
  37294. case T('!'):
  37295. result = tokenType_operator;
  37296. source.skip();
  37297. if (source.peekNextChar() == T('='))
  37298. source.skip();
  37299. break;
  37300. case T('/'):
  37301. result = tokenType_operator;
  37302. source.skip();
  37303. if (source.peekNextChar() == T('='))
  37304. {
  37305. source.skip();
  37306. }
  37307. else if (source.peekNextChar() == T('/'))
  37308. {
  37309. result = tokenType_comment;
  37310. source.skipToEndOfLine();
  37311. }
  37312. else if (source.peekNextChar() == T('*'))
  37313. {
  37314. source.skip();
  37315. result = tokenType_comment;
  37316. CppTokeniser::skipComment (source);
  37317. }
  37318. break;
  37319. case T('?'):
  37320. case T('~'):
  37321. source.skip();
  37322. result = tokenType_operator;
  37323. break;
  37324. case T('<'):
  37325. source.skip();
  37326. result = tokenType_operator;
  37327. if (source.peekNextChar() == T('='))
  37328. {
  37329. source.skip();
  37330. }
  37331. else if (source.peekNextChar() == T('<'))
  37332. {
  37333. source.skip();
  37334. if (source.peekNextChar() == T('='))
  37335. source.skip();
  37336. }
  37337. break;
  37338. case T('>'):
  37339. source.skip();
  37340. result = tokenType_operator;
  37341. if (source.peekNextChar() == T('='))
  37342. {
  37343. source.skip();
  37344. }
  37345. else if (source.peekNextChar() == T('<'))
  37346. {
  37347. source.skip();
  37348. if (source.peekNextChar() == T('='))
  37349. source.skip();
  37350. }
  37351. break;
  37352. case T('|'):
  37353. source.skip();
  37354. result = tokenType_operator;
  37355. if (source.peekNextChar() == T('='))
  37356. {
  37357. source.skip();
  37358. }
  37359. else if (source.peekNextChar() == T('|'))
  37360. {
  37361. source.skip();
  37362. if (source.peekNextChar() == T('='))
  37363. source.skip();
  37364. }
  37365. break;
  37366. case T('&'):
  37367. source.skip();
  37368. result = tokenType_operator;
  37369. if (source.peekNextChar() == T('='))
  37370. {
  37371. source.skip();
  37372. }
  37373. else if (source.peekNextChar() == T('&'))
  37374. {
  37375. source.skip();
  37376. if (source.peekNextChar() == T('='))
  37377. source.skip();
  37378. }
  37379. break;
  37380. case T('^'):
  37381. source.skip();
  37382. result = tokenType_operator;
  37383. if (source.peekNextChar() == T('='))
  37384. {
  37385. source.skip();
  37386. }
  37387. else if (source.peekNextChar() == T('^'))
  37388. {
  37389. source.skip();
  37390. if (source.peekNextChar() == T('='))
  37391. source.skip();
  37392. }
  37393. break;
  37394. case T('#'):
  37395. result = tokenType_preprocessor;
  37396. source.skipToEndOfLine();
  37397. break;
  37398. default:
  37399. if (CppTokeniser::isIdentifierStart (firstChar))
  37400. result = CppTokeniser::parseIdentifier (source);
  37401. else
  37402. source.skip();
  37403. break;
  37404. }
  37405. //jassert (result != tokenType_unknown);
  37406. return result;
  37407. }
  37408. const StringArray CPlusPlusCodeTokeniser::getTokenTypes()
  37409. {
  37410. StringArray s;
  37411. s.add ("Error");
  37412. s.add ("Comment");
  37413. s.add ("C++ keyword");
  37414. s.add ("Identifier");
  37415. s.add ("Integer literal");
  37416. s.add ("Float literal");
  37417. s.add ("String literal");
  37418. s.add ("Operator");
  37419. s.add ("Bracket");
  37420. s.add ("Punctuation");
  37421. s.add ("Preprocessor line");
  37422. return s;
  37423. }
  37424. const Colour CPlusPlusCodeTokeniser::getDefaultColour (const int tokenType)
  37425. {
  37426. const uint32 colours[] =
  37427. {
  37428. 0xffcc0000, // error
  37429. 0xff00aa00, // comment
  37430. 0xff0000cc, // keyword
  37431. 0xff000000, // identifier
  37432. 0xff880000, // int literal
  37433. 0xff885500, // float literal
  37434. 0xff990099, // string literal
  37435. 0xff225500, // operator
  37436. 0xff000055, // bracket
  37437. 0xff004400, // punctuation
  37438. 0xff660000 // preprocessor
  37439. };
  37440. if (tokenType >= 0 && tokenType < numElementsInArray (colours))
  37441. return Colour (colours [tokenType]);
  37442. return Colours::black;
  37443. }
  37444. END_JUCE_NAMESPACE
  37445. /*** End of inlined file: juce_CPlusPlusCodeTokeniser.cpp ***/
  37446. /*** Start of inlined file: juce_ComboBox.cpp ***/
  37447. BEGIN_JUCE_NAMESPACE
  37448. ComboBox::ComboBox (const String& name)
  37449. : Component (name),
  37450. lastCurrentId (0),
  37451. isButtonDown (false),
  37452. separatorPending (false),
  37453. menuActive (false),
  37454. label (0)
  37455. {
  37456. noChoicesMessage = TRANS("(no choices)");
  37457. setRepaintsOnMouseActivity (true);
  37458. lookAndFeelChanged();
  37459. currentId.addListener (this);
  37460. }
  37461. ComboBox::~ComboBox()
  37462. {
  37463. currentId.removeListener (this);
  37464. if (menuActive)
  37465. PopupMenu::dismissAllActiveMenus();
  37466. label = 0;
  37467. deleteAllChildren();
  37468. }
  37469. void ComboBox::setEditableText (const bool isEditable)
  37470. {
  37471. label->setEditable (isEditable, isEditable, false);
  37472. setWantsKeyboardFocus (! isEditable);
  37473. resized();
  37474. }
  37475. bool ComboBox::isTextEditable() const throw()
  37476. {
  37477. return label->isEditable();
  37478. }
  37479. void ComboBox::setJustificationType (const Justification& justification) throw()
  37480. {
  37481. label->setJustificationType (justification);
  37482. }
  37483. const Justification ComboBox::getJustificationType() const throw()
  37484. {
  37485. return label->getJustificationType();
  37486. }
  37487. void ComboBox::setTooltip (const String& newTooltip)
  37488. {
  37489. SettableTooltipClient::setTooltip (newTooltip);
  37490. label->setTooltip (newTooltip);
  37491. }
  37492. void ComboBox::addItem (const String& newItemText,
  37493. const int newItemId) throw()
  37494. {
  37495. // you can't add empty strings to the list..
  37496. jassert (newItemText.isNotEmpty());
  37497. // IDs must be non-zero, as zero is used to indicate a lack of selecion.
  37498. jassert (newItemId != 0);
  37499. // you shouldn't use duplicate item IDs!
  37500. jassert (getItemForId (newItemId) == 0);
  37501. if (newItemText.isNotEmpty() && newItemId != 0)
  37502. {
  37503. if (separatorPending)
  37504. {
  37505. separatorPending = false;
  37506. ItemInfo* const item = new ItemInfo();
  37507. item->itemId = 0;
  37508. item->isEnabled = false;
  37509. item->isHeading = false;
  37510. items.add (item);
  37511. }
  37512. ItemInfo* const item = new ItemInfo();
  37513. item->name = newItemText;
  37514. item->itemId = newItemId;
  37515. item->isEnabled = true;
  37516. item->isHeading = false;
  37517. items.add (item);
  37518. }
  37519. }
  37520. void ComboBox::addSeparator() throw()
  37521. {
  37522. separatorPending = (items.size() > 0);
  37523. }
  37524. void ComboBox::addSectionHeading (const String& headingName) throw()
  37525. {
  37526. // you can't add empty strings to the list..
  37527. jassert (headingName.isNotEmpty());
  37528. if (headingName.isNotEmpty())
  37529. {
  37530. if (separatorPending)
  37531. {
  37532. separatorPending = false;
  37533. ItemInfo* const item = new ItemInfo();
  37534. item->itemId = 0;
  37535. item->isEnabled = false;
  37536. item->isHeading = false;
  37537. items.add (item);
  37538. }
  37539. ItemInfo* const item = new ItemInfo();
  37540. item->name = headingName;
  37541. item->itemId = 0;
  37542. item->isEnabled = true;
  37543. item->isHeading = true;
  37544. items.add (item);
  37545. }
  37546. }
  37547. void ComboBox::setItemEnabled (const int itemId,
  37548. const bool shouldBeEnabled) throw()
  37549. {
  37550. ItemInfo* const item = getItemForId (itemId);
  37551. if (item != 0)
  37552. item->isEnabled = shouldBeEnabled;
  37553. }
  37554. void ComboBox::changeItemText (const int itemId,
  37555. const String& newText) throw()
  37556. {
  37557. ItemInfo* const item = getItemForId (itemId);
  37558. jassert (item != 0);
  37559. if (item != 0)
  37560. item->name = newText;
  37561. }
  37562. void ComboBox::clear (const bool dontSendChangeMessage)
  37563. {
  37564. items.clear();
  37565. separatorPending = false;
  37566. if (! label->isEditable())
  37567. setSelectedItemIndex (-1, dontSendChangeMessage);
  37568. }
  37569. bool ComboBox::ItemInfo::isSeparator() const throw()
  37570. {
  37571. return name.isEmpty();
  37572. }
  37573. bool ComboBox::ItemInfo::isRealItem() const throw()
  37574. {
  37575. return ! (isHeading || name.isEmpty());
  37576. }
  37577. ComboBox::ItemInfo* ComboBox::getItemForId (const int itemId) const throw()
  37578. {
  37579. if (itemId != 0)
  37580. {
  37581. for (int i = items.size(); --i >= 0;)
  37582. if (items.getUnchecked(i)->itemId == itemId)
  37583. return items.getUnchecked(i);
  37584. }
  37585. return 0;
  37586. }
  37587. ComboBox::ItemInfo* ComboBox::getItemForIndex (const int index) const throw()
  37588. {
  37589. int n = 0;
  37590. for (int i = 0; i < items.size(); ++i)
  37591. {
  37592. ItemInfo* const item = items.getUnchecked(i);
  37593. if (item->isRealItem())
  37594. if (n++ == index)
  37595. return item;
  37596. }
  37597. return 0;
  37598. }
  37599. int ComboBox::getNumItems() const throw()
  37600. {
  37601. int n = 0;
  37602. for (int i = items.size(); --i >= 0;)
  37603. if (items.getUnchecked(i)->isRealItem())
  37604. ++n;
  37605. return n;
  37606. }
  37607. const String ComboBox::getItemText (const int index) const throw()
  37608. {
  37609. const ItemInfo* const item = getItemForIndex (index);
  37610. if (item != 0)
  37611. return item->name;
  37612. return String::empty;
  37613. }
  37614. int ComboBox::getItemId (const int index) const throw()
  37615. {
  37616. const ItemInfo* const item = getItemForIndex (index);
  37617. return (item != 0) ? item->itemId : 0;
  37618. }
  37619. int ComboBox::indexOfItemId (const int itemId) const throw()
  37620. {
  37621. int n = 0;
  37622. for (int i = 0; i < items.size(); ++i)
  37623. {
  37624. const ItemInfo* const item = items.getUnchecked(i);
  37625. if (item->isRealItem())
  37626. {
  37627. if (item->itemId == itemId)
  37628. return n;
  37629. ++n;
  37630. }
  37631. }
  37632. return -1;
  37633. }
  37634. int ComboBox::getSelectedItemIndex() const throw()
  37635. {
  37636. int index = indexOfItemId (currentId.getValue());
  37637. if (getText() != getItemText (index))
  37638. index = -1;
  37639. return index;
  37640. }
  37641. void ComboBox::setSelectedItemIndex (const int index,
  37642. const bool dontSendChangeMessage) throw()
  37643. {
  37644. setSelectedId (getItemId (index), dontSendChangeMessage);
  37645. }
  37646. int ComboBox::getSelectedId() const throw()
  37647. {
  37648. const ItemInfo* const item = getItemForId (currentId.getValue());
  37649. return (item != 0 && getText() == item->name)
  37650. ? item->itemId
  37651. : 0;
  37652. }
  37653. void ComboBox::setSelectedId (const int newItemId,
  37654. const bool dontSendChangeMessage) throw()
  37655. {
  37656. const ItemInfo* const item = getItemForId (newItemId);
  37657. const String newItemText (item != 0 ? item->name : String::empty);
  37658. if (lastCurrentId != newItemId || label->getText() != newItemText)
  37659. {
  37660. if (! dontSendChangeMessage)
  37661. triggerAsyncUpdate();
  37662. label->setText (newItemText, false);
  37663. lastCurrentId = newItemId;
  37664. currentId = newItemId;
  37665. repaint(); // for the benefit of the 'none selected' text
  37666. }
  37667. }
  37668. void ComboBox::valueChanged (Value&)
  37669. {
  37670. if (lastCurrentId != (int) currentId.getValue())
  37671. setSelectedId (currentId.getValue(), false);
  37672. }
  37673. const String ComboBox::getText() const throw()
  37674. {
  37675. return label->getText();
  37676. }
  37677. void ComboBox::setText (const String& newText,
  37678. const bool dontSendChangeMessage) throw()
  37679. {
  37680. for (int i = items.size(); --i >= 0;)
  37681. {
  37682. const ItemInfo* const item = items.getUnchecked(i);
  37683. if (item->isRealItem()
  37684. && item->name == newText)
  37685. {
  37686. setSelectedId (item->itemId, dontSendChangeMessage);
  37687. return;
  37688. }
  37689. }
  37690. lastCurrentId = 0;
  37691. currentId = 0;
  37692. if (label->getText() != newText)
  37693. {
  37694. label->setText (newText, false);
  37695. if (! dontSendChangeMessage)
  37696. triggerAsyncUpdate();
  37697. }
  37698. repaint();
  37699. }
  37700. void ComboBox::showEditor()
  37701. {
  37702. jassert (isTextEditable()); // you probably shouldn't do this to a non-editable combo box?
  37703. label->showEditor();
  37704. }
  37705. void ComboBox::setTextWhenNothingSelected (const String& newMessage) throw()
  37706. {
  37707. textWhenNothingSelected = newMessage;
  37708. repaint();
  37709. }
  37710. const String ComboBox::getTextWhenNothingSelected() const throw()
  37711. {
  37712. return textWhenNothingSelected;
  37713. }
  37714. void ComboBox::setTextWhenNoChoicesAvailable (const String& newMessage) throw()
  37715. {
  37716. noChoicesMessage = newMessage;
  37717. }
  37718. const String ComboBox::getTextWhenNoChoicesAvailable() const throw()
  37719. {
  37720. return noChoicesMessage;
  37721. }
  37722. void ComboBox::paint (Graphics& g)
  37723. {
  37724. getLookAndFeel().drawComboBox (g,
  37725. getWidth(),
  37726. getHeight(),
  37727. isButtonDown,
  37728. label->getRight(),
  37729. 0,
  37730. getWidth() - label->getRight(),
  37731. getHeight(),
  37732. *this);
  37733. if (textWhenNothingSelected.isNotEmpty()
  37734. && label->getText().isEmpty()
  37735. && ! label->isBeingEdited())
  37736. {
  37737. g.setColour (findColour (textColourId).withMultipliedAlpha (0.5f));
  37738. g.setFont (label->getFont());
  37739. g.drawFittedText (textWhenNothingSelected,
  37740. label->getX() + 2, label->getY() + 1,
  37741. label->getWidth() - 4, label->getHeight() - 2,
  37742. label->getJustificationType(),
  37743. jmax (1, (int) (label->getHeight() / label->getFont().getHeight())));
  37744. }
  37745. }
  37746. void ComboBox::resized()
  37747. {
  37748. if (getHeight() > 0 && getWidth() > 0)
  37749. getLookAndFeel().positionComboBoxText (*this, *label);
  37750. }
  37751. void ComboBox::enablementChanged()
  37752. {
  37753. repaint();
  37754. }
  37755. void ComboBox::lookAndFeelChanged()
  37756. {
  37757. repaint();
  37758. Label* const newLabel = getLookAndFeel().createComboBoxTextBox (*this);
  37759. if (label != 0)
  37760. {
  37761. newLabel->setEditable (label->isEditable());
  37762. newLabel->setJustificationType (label->getJustificationType());
  37763. newLabel->setTooltip (label->getTooltip());
  37764. newLabel->setText (label->getText(), false);
  37765. }
  37766. label = newLabel;
  37767. addAndMakeVisible (newLabel);
  37768. newLabel->addListener (this);
  37769. newLabel->addMouseListener (this, false);
  37770. newLabel->setColour (Label::backgroundColourId, Colours::transparentBlack);
  37771. newLabel->setColour (Label::textColourId, findColour (ComboBox::textColourId));
  37772. newLabel->setColour (TextEditor::textColourId, findColour (ComboBox::textColourId));
  37773. newLabel->setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37774. newLabel->setColour (TextEditor::highlightColourId, findColour (TextEditor::highlightColourId));
  37775. newLabel->setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37776. resized();
  37777. }
  37778. void ComboBox::colourChanged()
  37779. {
  37780. lookAndFeelChanged();
  37781. }
  37782. bool ComboBox::keyPressed (const KeyPress& key)
  37783. {
  37784. bool used = false;
  37785. if (key.isKeyCode (KeyPress::upKey)
  37786. || key.isKeyCode (KeyPress::leftKey))
  37787. {
  37788. setSelectedItemIndex (jmax (0, getSelectedItemIndex() - 1));
  37789. used = true;
  37790. }
  37791. else if (key.isKeyCode (KeyPress::downKey)
  37792. || key.isKeyCode (KeyPress::rightKey))
  37793. {
  37794. setSelectedItemIndex (jmin (getSelectedItemIndex() + 1, getNumItems() - 1));
  37795. used = true;
  37796. }
  37797. else if (key.isKeyCode (KeyPress::returnKey))
  37798. {
  37799. showPopup();
  37800. used = true;
  37801. }
  37802. return used;
  37803. }
  37804. bool ComboBox::keyStateChanged (const bool isKeyDown)
  37805. {
  37806. // only forward key events that aren't used by this component
  37807. return isKeyDown
  37808. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  37809. || KeyPress::isKeyCurrentlyDown (KeyPress::leftKey)
  37810. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  37811. || KeyPress::isKeyCurrentlyDown (KeyPress::rightKey));
  37812. }
  37813. void ComboBox::focusGained (FocusChangeType)
  37814. {
  37815. repaint();
  37816. }
  37817. void ComboBox::focusLost (FocusChangeType)
  37818. {
  37819. repaint();
  37820. }
  37821. void ComboBox::labelTextChanged (Label*)
  37822. {
  37823. triggerAsyncUpdate();
  37824. }
  37825. void ComboBox::showPopup()
  37826. {
  37827. if (! menuActive)
  37828. {
  37829. const int selectedId = getSelectedId();
  37830. ComponentDeletionWatcher deletionWatcher (this);
  37831. PopupMenu menu;
  37832. menu.setLookAndFeel (&getLookAndFeel());
  37833. for (int i = 0; i < items.size(); ++i)
  37834. {
  37835. const ItemInfo* const item = items.getUnchecked(i);
  37836. if (item->isSeparator())
  37837. menu.addSeparator();
  37838. else if (item->isHeading)
  37839. menu.addSectionHeader (item->name);
  37840. else
  37841. menu.addItem (item->itemId, item->name,
  37842. item->isEnabled, item->itemId == selectedId);
  37843. }
  37844. if (items.size() == 0)
  37845. menu.addItem (1, noChoicesMessage, false);
  37846. const int itemHeight = jlimit (12, 24, getHeight());
  37847. menuActive = true;
  37848. const int resultId = menu.showAt (this, selectedId,
  37849. getWidth(), 1, itemHeight);
  37850. if (deletionWatcher.hasBeenDeleted())
  37851. return;
  37852. menuActive = false;
  37853. if (resultId != 0)
  37854. setSelectedId (resultId);
  37855. }
  37856. }
  37857. void ComboBox::mouseDown (const MouseEvent& e)
  37858. {
  37859. beginDragAutoRepeat (300);
  37860. isButtonDown = isEnabled();
  37861. if (isButtonDown
  37862. && (e.eventComponent == this || ! label->isEditable()))
  37863. {
  37864. showPopup();
  37865. }
  37866. }
  37867. void ComboBox::mouseDrag (const MouseEvent& e)
  37868. {
  37869. beginDragAutoRepeat (50);
  37870. if (isButtonDown && ! e.mouseWasClicked())
  37871. showPopup();
  37872. }
  37873. void ComboBox::mouseUp (const MouseEvent& e2)
  37874. {
  37875. if (isButtonDown)
  37876. {
  37877. isButtonDown = false;
  37878. repaint();
  37879. const MouseEvent e (e2.getEventRelativeTo (this));
  37880. if (reallyContains (e.x, e.y, true)
  37881. && (e2.eventComponent == this || ! label->isEditable()))
  37882. {
  37883. showPopup();
  37884. }
  37885. }
  37886. }
  37887. void ComboBox::addListener (ComboBoxListener* const listener) throw()
  37888. {
  37889. jassert (listener != 0);
  37890. if (listener != 0)
  37891. listeners.add (listener);
  37892. }
  37893. void ComboBox::removeListener (ComboBoxListener* const listener) throw()
  37894. {
  37895. listeners.removeValue (listener);
  37896. }
  37897. void ComboBox::handleAsyncUpdate()
  37898. {
  37899. for (int i = listeners.size(); --i >= 0;)
  37900. {
  37901. ((ComboBoxListener*) listeners.getUnchecked (i))->comboBoxChanged (this);
  37902. i = jmin (i, listeners.size());
  37903. }
  37904. }
  37905. END_JUCE_NAMESPACE
  37906. /*** End of inlined file: juce_ComboBox.cpp ***/
  37907. /*** Start of inlined file: juce_Label.cpp ***/
  37908. BEGIN_JUCE_NAMESPACE
  37909. Label::Label (const String& componentName,
  37910. const String& labelText)
  37911. : Component (componentName),
  37912. textValue (labelText),
  37913. lastTextValue (labelText),
  37914. font (15.0f),
  37915. justification (Justification::centredLeft),
  37916. ownerComponent (0),
  37917. horizontalBorderSize (5),
  37918. verticalBorderSize (1),
  37919. minimumHorizontalScale (0.7f),
  37920. editSingleClick (false),
  37921. editDoubleClick (false),
  37922. lossOfFocusDiscardsChanges (false)
  37923. {
  37924. setColour (TextEditor::textColourId, Colours::black);
  37925. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  37926. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  37927. textValue.addListener (this);
  37928. }
  37929. Label::~Label()
  37930. {
  37931. textValue.removeListener (this);
  37932. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37933. ownerComponent->removeComponentListener (this);
  37934. editor = 0;
  37935. }
  37936. void Label::setText (const String& newText,
  37937. const bool broadcastChangeMessage)
  37938. {
  37939. hideEditor (true);
  37940. if (lastTextValue != newText)
  37941. {
  37942. lastTextValue = newText;
  37943. textValue = newText;
  37944. repaint();
  37945. textWasChanged();
  37946. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37947. componentMovedOrResized (*ownerComponent, true, true);
  37948. if (broadcastChangeMessage)
  37949. callChangeListeners();
  37950. }
  37951. }
  37952. const String Label::getText (const bool returnActiveEditorContents) const throw()
  37953. {
  37954. return (returnActiveEditorContents && isBeingEdited())
  37955. ? editor->getText()
  37956. : textValue.toString();
  37957. }
  37958. void Label::valueChanged (Value&)
  37959. {
  37960. if (lastTextValue != textValue.toString())
  37961. setText (textValue.toString(), true);
  37962. }
  37963. void Label::setFont (const Font& newFont) throw()
  37964. {
  37965. font = newFont;
  37966. repaint();
  37967. }
  37968. const Font& Label::getFont() const throw()
  37969. {
  37970. return font;
  37971. }
  37972. void Label::setEditable (const bool editOnSingleClick,
  37973. const bool editOnDoubleClick,
  37974. const bool lossOfFocusDiscardsChanges_) throw()
  37975. {
  37976. editSingleClick = editOnSingleClick;
  37977. editDoubleClick = editOnDoubleClick;
  37978. lossOfFocusDiscardsChanges = lossOfFocusDiscardsChanges_;
  37979. setWantsKeyboardFocus (editOnSingleClick || editOnDoubleClick);
  37980. setFocusContainer (editOnSingleClick || editOnDoubleClick);
  37981. }
  37982. void Label::setJustificationType (const Justification& justification_) throw()
  37983. {
  37984. justification = justification_;
  37985. repaint();
  37986. }
  37987. void Label::setBorderSize (int h, int v)
  37988. {
  37989. horizontalBorderSize = h;
  37990. verticalBorderSize = v;
  37991. repaint();
  37992. }
  37993. void Label::attachToComponent (Component* owner,
  37994. const bool onLeft)
  37995. {
  37996. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  37997. ownerComponent->removeComponentListener (this);
  37998. deletionWatcher = 0;
  37999. ownerComponent = owner;
  38000. leftOfOwnerComp = onLeft;
  38001. if (ownerComponent != 0)
  38002. {
  38003. deletionWatcher = new ComponentDeletionWatcher (owner);
  38004. setVisible (owner->isVisible());
  38005. ownerComponent->addComponentListener (this);
  38006. componentParentHierarchyChanged (*ownerComponent);
  38007. componentMovedOrResized (*ownerComponent, true, true);
  38008. }
  38009. }
  38010. void Label::componentMovedOrResized (Component& component,
  38011. bool /*wasMoved*/,
  38012. bool /*wasResized*/)
  38013. {
  38014. if (leftOfOwnerComp)
  38015. {
  38016. setSize (jmin (getFont().getStringWidth (textValue.toString()) + 8, component.getX()),
  38017. component.getHeight());
  38018. setTopRightPosition (component.getX(), component.getY());
  38019. }
  38020. else
  38021. {
  38022. setSize (component.getWidth(),
  38023. 8 + roundToInt (getFont().getHeight()));
  38024. setTopLeftPosition (component.getX(), component.getY() - getHeight());
  38025. }
  38026. }
  38027. void Label::componentParentHierarchyChanged (Component& component)
  38028. {
  38029. if (component.getParentComponent() != 0)
  38030. component.getParentComponent()->addChildComponent (this);
  38031. }
  38032. void Label::componentVisibilityChanged (Component& component)
  38033. {
  38034. setVisible (component.isVisible());
  38035. }
  38036. void Label::textWasEdited()
  38037. {
  38038. }
  38039. void Label::textWasChanged()
  38040. {
  38041. }
  38042. void Label::showEditor()
  38043. {
  38044. if (editor == 0)
  38045. {
  38046. addAndMakeVisible (editor = createEditorComponent());
  38047. editor->setText (getText(), false);
  38048. editor->addListener (this);
  38049. editor->grabKeyboardFocus();
  38050. editor->setHighlightedRegion (Range<int> (0, textValue.toString().length()));
  38051. editor->addListener (this);
  38052. resized();
  38053. repaint();
  38054. editorShown (editor);
  38055. enterModalState();
  38056. editor->grabKeyboardFocus();
  38057. }
  38058. }
  38059. void Label::editorShown (TextEditor* /*editorComponent*/)
  38060. {
  38061. }
  38062. void Label::editorAboutToBeHidden (TextEditor* /*editorComponent*/)
  38063. {
  38064. }
  38065. bool Label::updateFromTextEditorContents()
  38066. {
  38067. jassert (editor != 0);
  38068. const String newText (editor->getText());
  38069. if (textValue.toString() != newText)
  38070. {
  38071. lastTextValue = newText;
  38072. textValue = newText;
  38073. repaint();
  38074. textWasChanged();
  38075. if (ownerComponent != 0 && ! deletionWatcher->hasBeenDeleted())
  38076. componentMovedOrResized (*ownerComponent, true, true);
  38077. return true;
  38078. }
  38079. return false;
  38080. }
  38081. void Label::hideEditor (const bool discardCurrentEditorContents)
  38082. {
  38083. if (editor != 0)
  38084. {
  38085. editorAboutToBeHidden (editor);
  38086. const bool changed = (! discardCurrentEditorContents)
  38087. && updateFromTextEditorContents();
  38088. editor = 0;
  38089. repaint();
  38090. if (changed)
  38091. textWasEdited();
  38092. exitModalState (0);
  38093. if (changed && isValidComponent())
  38094. callChangeListeners();
  38095. }
  38096. }
  38097. void Label::inputAttemptWhenModal()
  38098. {
  38099. if (editor != 0)
  38100. {
  38101. if (lossOfFocusDiscardsChanges)
  38102. textEditorEscapeKeyPressed (*editor);
  38103. else
  38104. textEditorReturnKeyPressed (*editor);
  38105. }
  38106. }
  38107. bool Label::isBeingEdited() const throw()
  38108. {
  38109. return editor != 0;
  38110. }
  38111. TextEditor* Label::createEditorComponent()
  38112. {
  38113. TextEditor* const ed = new TextEditor (getName());
  38114. ed->setFont (font);
  38115. // copy these colours from our own settings..
  38116. const int cols[] = { TextEditor::backgroundColourId,
  38117. TextEditor::textColourId,
  38118. TextEditor::highlightColourId,
  38119. TextEditor::highlightedTextColourId,
  38120. TextEditor::caretColourId,
  38121. TextEditor::outlineColourId,
  38122. TextEditor::focusedOutlineColourId,
  38123. TextEditor::shadowColourId };
  38124. for (int i = 0; i < numElementsInArray (cols); ++i)
  38125. ed->setColour (cols[i], findColour (cols[i]));
  38126. return ed;
  38127. }
  38128. void Label::paint (Graphics& g)
  38129. {
  38130. getLookAndFeel().drawLabel (g, *this);
  38131. }
  38132. void Label::mouseUp (const MouseEvent& e)
  38133. {
  38134. if (editSingleClick
  38135. && e.mouseWasClicked()
  38136. && contains (e.x, e.y)
  38137. && ! e.mods.isPopupMenu())
  38138. {
  38139. showEditor();
  38140. }
  38141. }
  38142. void Label::mouseDoubleClick (const MouseEvent& e)
  38143. {
  38144. if (editDoubleClick && ! e.mods.isPopupMenu())
  38145. showEditor();
  38146. }
  38147. void Label::resized()
  38148. {
  38149. if (editor != 0)
  38150. editor->setBoundsInset (BorderSize (0));
  38151. }
  38152. void Label::focusGained (FocusChangeType cause)
  38153. {
  38154. if (editSingleClick && cause == focusChangedByTabKey)
  38155. showEditor();
  38156. }
  38157. void Label::enablementChanged()
  38158. {
  38159. repaint();
  38160. }
  38161. void Label::colourChanged()
  38162. {
  38163. repaint();
  38164. }
  38165. void Label::setMinimumHorizontalScale (const float newScale)
  38166. {
  38167. if (minimumHorizontalScale != newScale)
  38168. {
  38169. minimumHorizontalScale = newScale;
  38170. repaint();
  38171. }
  38172. }
  38173. // We'll use a custom focus traverser here to make sure focus goes from the
  38174. // text editor to another component rather than back to the label itself.
  38175. class LabelKeyboardFocusTraverser : public KeyboardFocusTraverser
  38176. {
  38177. public:
  38178. LabelKeyboardFocusTraverser() {}
  38179. Component* getNextComponent (Component* current)
  38180. {
  38181. return KeyboardFocusTraverser::getNextComponent (dynamic_cast <TextEditor*> (current) != 0
  38182. ? current->getParentComponent() : current);
  38183. }
  38184. Component* getPreviousComponent (Component* current)
  38185. {
  38186. return KeyboardFocusTraverser::getPreviousComponent (dynamic_cast <TextEditor*> (current) != 0
  38187. ? current->getParentComponent() : current);
  38188. }
  38189. };
  38190. KeyboardFocusTraverser* Label::createFocusTraverser()
  38191. {
  38192. return new LabelKeyboardFocusTraverser();
  38193. }
  38194. void Label::addListener (LabelListener* const listener) throw()
  38195. {
  38196. jassert (listener != 0);
  38197. if (listener != 0)
  38198. listeners.add (listener);
  38199. }
  38200. void Label::removeListener (LabelListener* const listener) throw()
  38201. {
  38202. listeners.removeValue (listener);
  38203. }
  38204. void Label::callChangeListeners()
  38205. {
  38206. for (int i = listeners.size(); --i >= 0;)
  38207. {
  38208. ((LabelListener*) listeners.getUnchecked (i))->labelTextChanged (this);
  38209. i = jmin (i, listeners.size());
  38210. }
  38211. }
  38212. void Label::textEditorTextChanged (TextEditor& ed)
  38213. {
  38214. if (editor != 0)
  38215. {
  38216. jassert (&ed == editor);
  38217. if (! (hasKeyboardFocus (true) || isCurrentlyBlockedByAnotherModalComponent()))
  38218. {
  38219. if (lossOfFocusDiscardsChanges)
  38220. textEditorEscapeKeyPressed (ed);
  38221. else
  38222. textEditorReturnKeyPressed (ed);
  38223. }
  38224. }
  38225. }
  38226. void Label::textEditorReturnKeyPressed (TextEditor& ed)
  38227. {
  38228. if (editor != 0)
  38229. {
  38230. jassert (&ed == editor);
  38231. (void) ed;
  38232. const bool changed = updateFromTextEditorContents();
  38233. hideEditor (true);
  38234. if (changed)
  38235. {
  38236. textWasEdited();
  38237. if (isValidComponent())
  38238. callChangeListeners();
  38239. }
  38240. }
  38241. }
  38242. void Label::textEditorEscapeKeyPressed (TextEditor& ed)
  38243. {
  38244. if (editor != 0)
  38245. {
  38246. jassert (&ed == editor);
  38247. (void) ed;
  38248. editor->setText (textValue.toString(), false);
  38249. hideEditor (true);
  38250. }
  38251. }
  38252. void Label::textEditorFocusLost (TextEditor& ed)
  38253. {
  38254. textEditorTextChanged (ed);
  38255. }
  38256. END_JUCE_NAMESPACE
  38257. /*** End of inlined file: juce_Label.cpp ***/
  38258. /*** Start of inlined file: juce_ListBox.cpp ***/
  38259. BEGIN_JUCE_NAMESPACE
  38260. class ListBoxRowComponent : public Component,
  38261. public TooltipClient
  38262. {
  38263. public:
  38264. ListBoxRowComponent (ListBox& owner_)
  38265. : owner (owner_),
  38266. row (-1),
  38267. selected (false),
  38268. isDragging (false)
  38269. {
  38270. }
  38271. ~ListBoxRowComponent()
  38272. {
  38273. deleteAllChildren();
  38274. }
  38275. void paint (Graphics& g)
  38276. {
  38277. if (owner.getModel() != 0)
  38278. owner.getModel()->paintListBoxItem (row, g, getWidth(), getHeight(), selected);
  38279. }
  38280. void update (const int row_, const bool selected_)
  38281. {
  38282. if (row != row_ || selected != selected_)
  38283. {
  38284. repaint();
  38285. row = row_;
  38286. selected = selected_;
  38287. }
  38288. if (owner.getModel() != 0)
  38289. {
  38290. Component* const customComp = owner.getModel()->refreshComponentForRow (row_, selected_, getChildComponent (0));
  38291. if (customComp != 0)
  38292. {
  38293. addAndMakeVisible (customComp);
  38294. customComp->setBounds (0, 0, getWidth(), getHeight());
  38295. for (int i = getNumChildComponents(); --i >= 0;)
  38296. if (getChildComponent (i) != customComp)
  38297. delete getChildComponent (i);
  38298. }
  38299. else
  38300. {
  38301. deleteAllChildren();
  38302. }
  38303. }
  38304. }
  38305. void mouseDown (const MouseEvent& e)
  38306. {
  38307. isDragging = false;
  38308. selectRowOnMouseUp = false;
  38309. if (isEnabled())
  38310. {
  38311. if (! selected)
  38312. {
  38313. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  38314. if (owner.getModel() != 0)
  38315. owner.getModel()->listBoxItemClicked (row, e);
  38316. }
  38317. else
  38318. {
  38319. selectRowOnMouseUp = true;
  38320. }
  38321. }
  38322. }
  38323. void mouseUp (const MouseEvent& e)
  38324. {
  38325. if (isEnabled() && selectRowOnMouseUp && ! isDragging)
  38326. {
  38327. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  38328. if (owner.getModel() != 0)
  38329. owner.getModel()->listBoxItemClicked (row, e);
  38330. }
  38331. }
  38332. void mouseDoubleClick (const MouseEvent& e)
  38333. {
  38334. if (owner.getModel() != 0 && isEnabled())
  38335. owner.getModel()->listBoxItemDoubleClicked (row, e);
  38336. }
  38337. void mouseDrag (const MouseEvent& e)
  38338. {
  38339. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  38340. {
  38341. const SparseSet <int> selectedRows (owner.getSelectedRows());
  38342. if (selectedRows.size() > 0)
  38343. {
  38344. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  38345. if (dragDescription.isNotEmpty())
  38346. {
  38347. isDragging = true;
  38348. owner.startDragAndDrop (e, dragDescription);
  38349. }
  38350. }
  38351. }
  38352. }
  38353. void resized()
  38354. {
  38355. if (getNumChildComponents() > 0)
  38356. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  38357. }
  38358. const String getTooltip()
  38359. {
  38360. if (owner.getModel() != 0)
  38361. return owner.getModel()->getTooltipForRow (row);
  38362. return String::empty;
  38363. }
  38364. juce_UseDebuggingNewOperator
  38365. bool neededFlag;
  38366. private:
  38367. ListBox& owner;
  38368. int row;
  38369. bool selected, isDragging, selectRowOnMouseUp;
  38370. ListBoxRowComponent (const ListBoxRowComponent&);
  38371. ListBoxRowComponent& operator= (const ListBoxRowComponent&);
  38372. };
  38373. class ListViewport : public Viewport
  38374. {
  38375. public:
  38376. int firstIndex, firstWholeIndex, lastWholeIndex;
  38377. bool hasUpdated;
  38378. ListViewport (ListBox& owner_)
  38379. : owner (owner_)
  38380. {
  38381. setWantsKeyboardFocus (false);
  38382. setViewedComponent (new Component());
  38383. getViewedComponent()->addMouseListener (this, false);
  38384. getViewedComponent()->setWantsKeyboardFocus (false);
  38385. }
  38386. ~ListViewport()
  38387. {
  38388. getViewedComponent()->removeMouseListener (this);
  38389. getViewedComponent()->deleteAllChildren();
  38390. }
  38391. ListBoxRowComponent* getComponentForRow (const int row) const throw()
  38392. {
  38393. return (ListBoxRowComponent*) getViewedComponent()
  38394. ->getChildComponent (row % jmax (1, getViewedComponent()->getNumChildComponents()));
  38395. }
  38396. int getRowNumberOfComponent (Component* const rowComponent) const throw()
  38397. {
  38398. const int index = getIndexOfChildComponent (rowComponent);
  38399. const int num = getViewedComponent()->getNumChildComponents();
  38400. for (int i = num; --i >= 0;)
  38401. if (((firstIndex + i) % jmax (1, num)) == index)
  38402. return firstIndex + i;
  38403. return -1;
  38404. }
  38405. Component* getComponentForRowIfOnscreen (const int row) const throw()
  38406. {
  38407. return (row >= firstIndex && row < firstIndex + getViewedComponent()->getNumChildComponents())
  38408. ? getComponentForRow (row) : 0;
  38409. }
  38410. void visibleAreaChanged (int, int, int, int)
  38411. {
  38412. updateVisibleArea (true);
  38413. if (owner.getModel() != 0)
  38414. owner.getModel()->listWasScrolled();
  38415. }
  38416. void updateVisibleArea (const bool makeSureItUpdatesContent)
  38417. {
  38418. hasUpdated = false;
  38419. const int newX = getViewedComponent()->getX();
  38420. int newY = getViewedComponent()->getY();
  38421. const int newW = jmax (owner.minimumRowWidth, getMaximumVisibleWidth());
  38422. const int newH = owner.totalItems * owner.getRowHeight();
  38423. if (newY + newH < getMaximumVisibleHeight() && newH > getMaximumVisibleHeight())
  38424. newY = getMaximumVisibleHeight() - newH;
  38425. getViewedComponent()->setBounds (newX, newY, newW, newH);
  38426. if (makeSureItUpdatesContent && ! hasUpdated)
  38427. updateContents();
  38428. }
  38429. void updateContents()
  38430. {
  38431. hasUpdated = true;
  38432. const int rowHeight = owner.getRowHeight();
  38433. if (rowHeight > 0)
  38434. {
  38435. const int y = getViewPositionY();
  38436. const int w = getViewedComponent()->getWidth();
  38437. const int numNeeded = 2 + getMaximumVisibleHeight() / rowHeight;
  38438. while (numNeeded > getViewedComponent()->getNumChildComponents())
  38439. getViewedComponent()->addAndMakeVisible (new ListBoxRowComponent (owner));
  38440. jassert (numNeeded >= 0);
  38441. while (numNeeded < getViewedComponent()->getNumChildComponents())
  38442. {
  38443. Component* const rowToRemove
  38444. = getViewedComponent()->getChildComponent (getViewedComponent()->getNumChildComponents() - 1);
  38445. delete rowToRemove;
  38446. }
  38447. firstIndex = y / rowHeight;
  38448. firstWholeIndex = (y + rowHeight - 1) / rowHeight;
  38449. lastWholeIndex = (y + getMaximumVisibleHeight() - 1) / rowHeight;
  38450. for (int i = 0; i < numNeeded; ++i)
  38451. {
  38452. const int row = i + firstIndex;
  38453. ListBoxRowComponent* const rowComp = getComponentForRow (row);
  38454. if (rowComp != 0)
  38455. {
  38456. rowComp->setBounds (0, row * rowHeight, w, rowHeight);
  38457. rowComp->update (row, owner.isRowSelected (row));
  38458. }
  38459. }
  38460. }
  38461. if (owner.headerComponent != 0)
  38462. owner.headerComponent->setBounds (owner.outlineThickness + getViewedComponent()->getX(),
  38463. owner.outlineThickness,
  38464. jmax (owner.getWidth() - owner.outlineThickness * 2,
  38465. getViewedComponent()->getWidth()),
  38466. owner.headerComponent->getHeight());
  38467. }
  38468. void paint (Graphics& g)
  38469. {
  38470. if (isOpaque())
  38471. g.fillAll (owner.findColour (ListBox::backgroundColourId));
  38472. }
  38473. bool keyPressed (const KeyPress& key)
  38474. {
  38475. if (key.isKeyCode (KeyPress::upKey)
  38476. || key.isKeyCode (KeyPress::downKey)
  38477. || key.isKeyCode (KeyPress::pageUpKey)
  38478. || key.isKeyCode (KeyPress::pageDownKey)
  38479. || key.isKeyCode (KeyPress::homeKey)
  38480. || key.isKeyCode (KeyPress::endKey))
  38481. {
  38482. // we want to avoid these keypresses going to the viewport, and instead allow
  38483. // them to pass up to our listbox..
  38484. return false;
  38485. }
  38486. return Viewport::keyPressed (key);
  38487. }
  38488. juce_UseDebuggingNewOperator
  38489. private:
  38490. ListBox& owner;
  38491. ListViewport (const ListViewport&);
  38492. ListViewport& operator= (const ListViewport&);
  38493. };
  38494. ListBox::ListBox (const String& name, ListBoxModel* const model_)
  38495. : Component (name),
  38496. model (model_),
  38497. headerComponent (0),
  38498. totalItems (0),
  38499. rowHeight (22),
  38500. minimumRowWidth (0),
  38501. outlineThickness (0),
  38502. lastRowSelected (-1),
  38503. mouseMoveSelects (false),
  38504. multipleSelection (false),
  38505. hasDoneInitialUpdate (false)
  38506. {
  38507. addAndMakeVisible (viewport = new ListViewport (*this));
  38508. setWantsKeyboardFocus (true);
  38509. colourChanged();
  38510. }
  38511. ListBox::~ListBox()
  38512. {
  38513. deleteAllChildren();
  38514. }
  38515. void ListBox::setModel (ListBoxModel* const newModel)
  38516. {
  38517. if (model != newModel)
  38518. {
  38519. model = newModel;
  38520. updateContent();
  38521. }
  38522. }
  38523. void ListBox::setMultipleSelectionEnabled (bool b)
  38524. {
  38525. multipleSelection = b;
  38526. }
  38527. void ListBox::setMouseMoveSelectsRows (bool b)
  38528. {
  38529. mouseMoveSelects = b;
  38530. if (b)
  38531. addMouseListener (this, true);
  38532. }
  38533. void ListBox::paint (Graphics& g)
  38534. {
  38535. if (! hasDoneInitialUpdate)
  38536. updateContent();
  38537. g.fillAll (findColour (backgroundColourId));
  38538. }
  38539. void ListBox::paintOverChildren (Graphics& g)
  38540. {
  38541. if (outlineThickness > 0)
  38542. {
  38543. g.setColour (findColour (outlineColourId));
  38544. g.drawRect (0, 0, getWidth(), getHeight(), outlineThickness);
  38545. }
  38546. }
  38547. void ListBox::resized()
  38548. {
  38549. viewport->setBoundsInset (BorderSize (outlineThickness + ((headerComponent != 0) ? headerComponent->getHeight() : 0),
  38550. outlineThickness,
  38551. outlineThickness,
  38552. outlineThickness));
  38553. viewport->setSingleStepSizes (20, getRowHeight());
  38554. viewport->updateVisibleArea (false);
  38555. }
  38556. void ListBox::visibilityChanged()
  38557. {
  38558. viewport->updateVisibleArea (true);
  38559. }
  38560. Viewport* ListBox::getViewport() const throw()
  38561. {
  38562. return viewport;
  38563. }
  38564. void ListBox::updateContent()
  38565. {
  38566. hasDoneInitialUpdate = true;
  38567. totalItems = (model != 0) ? model->getNumRows() : 0;
  38568. bool selectionChanged = false;
  38569. if (selected [selected.size() - 1] >= totalItems)
  38570. {
  38571. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38572. lastRowSelected = getSelectedRow (0);
  38573. selectionChanged = true;
  38574. }
  38575. viewport->updateVisibleArea (isVisible());
  38576. viewport->resized();
  38577. if (selectionChanged && model != 0)
  38578. model->selectedRowsChanged (lastRowSelected);
  38579. }
  38580. void ListBox::selectRow (const int row,
  38581. bool dontScroll,
  38582. bool deselectOthersFirst)
  38583. {
  38584. selectRowInternal (row, dontScroll, deselectOthersFirst, false);
  38585. }
  38586. void ListBox::selectRowInternal (const int row,
  38587. bool dontScroll,
  38588. bool deselectOthersFirst,
  38589. bool isMouseClick)
  38590. {
  38591. if (! multipleSelection)
  38592. deselectOthersFirst = true;
  38593. if ((! isRowSelected (row))
  38594. || (deselectOthersFirst && getNumSelectedRows() > 1))
  38595. {
  38596. if (((unsigned int) row) < (unsigned int) totalItems)
  38597. {
  38598. if (deselectOthersFirst)
  38599. selected.clear();
  38600. selected.addRange (row, 1);
  38601. if (getHeight() == 0 || getWidth() == 0)
  38602. dontScroll = true;
  38603. viewport->hasUpdated = false;
  38604. if (row < viewport->firstWholeIndex && ! dontScroll)
  38605. {
  38606. viewport->setViewPosition (viewport->getViewPositionX(),
  38607. row * getRowHeight());
  38608. }
  38609. else if (row >= viewport->lastWholeIndex && ! dontScroll)
  38610. {
  38611. const int rowsOnScreen = viewport->lastWholeIndex - viewport->firstWholeIndex;
  38612. if (row >= lastRowSelected + rowsOnScreen
  38613. && rowsOnScreen < totalItems - 1
  38614. && ! isMouseClick)
  38615. {
  38616. viewport->setViewPosition (viewport->getViewPositionX(),
  38617. jlimit (0, jmax (0, totalItems - rowsOnScreen), row)
  38618. * getRowHeight());
  38619. }
  38620. else
  38621. {
  38622. viewport->setViewPosition (viewport->getViewPositionX(),
  38623. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38624. }
  38625. }
  38626. if (! viewport->hasUpdated)
  38627. viewport->updateContents();
  38628. lastRowSelected = row;
  38629. model->selectedRowsChanged (row);
  38630. }
  38631. else
  38632. {
  38633. if (deselectOthersFirst)
  38634. deselectAllRows();
  38635. }
  38636. }
  38637. }
  38638. void ListBox::deselectRow (const int row)
  38639. {
  38640. if (selected.contains (row))
  38641. {
  38642. selected.removeRange (row, 1);
  38643. if (row == lastRowSelected)
  38644. lastRowSelected = getSelectedRow (0);
  38645. viewport->updateContents();
  38646. model->selectedRowsChanged (lastRowSelected);
  38647. }
  38648. }
  38649. void ListBox::setSelectedRows (const SparseSet<int>& setOfRowsToBeSelected,
  38650. const bool sendNotificationEventToModel)
  38651. {
  38652. selected = setOfRowsToBeSelected;
  38653. selected.removeRange (totalItems, std::numeric_limits<int>::max() - totalItems);
  38654. if (! isRowSelected (lastRowSelected))
  38655. lastRowSelected = getSelectedRow (0);
  38656. viewport->updateContents();
  38657. if ((model != 0) && sendNotificationEventToModel)
  38658. model->selectedRowsChanged (lastRowSelected);
  38659. }
  38660. const SparseSet<int> ListBox::getSelectedRows() const
  38661. {
  38662. return selected;
  38663. }
  38664. void ListBox::selectRangeOfRows (int firstRow, int lastRow)
  38665. {
  38666. if (multipleSelection && (firstRow != lastRow))
  38667. {
  38668. const int numRows = totalItems - 1;
  38669. firstRow = jlimit (0, jmax (0, numRows), firstRow);
  38670. lastRow = jlimit (0, jmax (0, numRows), lastRow);
  38671. selected.addRange (jmin (firstRow, lastRow),
  38672. abs (firstRow - lastRow) + 1);
  38673. selected.removeRange (lastRow, 1);
  38674. }
  38675. selectRowInternal (lastRow, false, false, true);
  38676. }
  38677. void ListBox::flipRowSelection (const int row)
  38678. {
  38679. if (isRowSelected (row))
  38680. deselectRow (row);
  38681. else
  38682. selectRowInternal (row, false, false, true);
  38683. }
  38684. void ListBox::deselectAllRows()
  38685. {
  38686. if (! selected.isEmpty())
  38687. {
  38688. selected.clear();
  38689. lastRowSelected = -1;
  38690. viewport->updateContents();
  38691. if (model != 0)
  38692. model->selectedRowsChanged (lastRowSelected);
  38693. }
  38694. }
  38695. void ListBox::selectRowsBasedOnModifierKeys (const int row,
  38696. const ModifierKeys& mods)
  38697. {
  38698. if (multipleSelection && mods.isCommandDown())
  38699. {
  38700. flipRowSelection (row);
  38701. }
  38702. else if (multipleSelection && mods.isShiftDown() && lastRowSelected >= 0)
  38703. {
  38704. selectRangeOfRows (lastRowSelected, row);
  38705. }
  38706. else if ((! mods.isPopupMenu()) || ! isRowSelected (row))
  38707. {
  38708. selectRowInternal (row, false, true, true);
  38709. }
  38710. }
  38711. int ListBox::getNumSelectedRows() const
  38712. {
  38713. return selected.size();
  38714. }
  38715. int ListBox::getSelectedRow (const int index) const
  38716. {
  38717. return (((unsigned int) index) < (unsigned int) selected.size())
  38718. ? selected [index] : -1;
  38719. }
  38720. bool ListBox::isRowSelected (const int row) const
  38721. {
  38722. return selected.contains (row);
  38723. }
  38724. int ListBox::getLastRowSelected() const
  38725. {
  38726. return (isRowSelected (lastRowSelected)) ? lastRowSelected : -1;
  38727. }
  38728. int ListBox::getRowContainingPosition (const int x, const int y) const throw()
  38729. {
  38730. if (((unsigned int) x) < (unsigned int) getWidth())
  38731. {
  38732. const int row = (viewport->getViewPositionY() + y - viewport->getY()) / rowHeight;
  38733. if (((unsigned int) row) < (unsigned int) totalItems)
  38734. return row;
  38735. }
  38736. return -1;
  38737. }
  38738. int ListBox::getInsertionIndexForPosition (const int x, const int y) const throw()
  38739. {
  38740. if (((unsigned int) x) < (unsigned int) getWidth())
  38741. {
  38742. const int row = (viewport->getViewPositionY() + y + rowHeight / 2 - viewport->getY()) / rowHeight;
  38743. return jlimit (0, totalItems, row);
  38744. }
  38745. return -1;
  38746. }
  38747. Component* ListBox::getComponentForRowNumber (const int row) const throw()
  38748. {
  38749. Component* const listRowComp = viewport->getComponentForRowIfOnscreen (row);
  38750. return listRowComp != 0 ? listRowComp->getChildComponent (0) : 0;
  38751. }
  38752. int ListBox::getRowNumberOfComponent (Component* const rowComponent) const throw()
  38753. {
  38754. return viewport->getRowNumberOfComponent (rowComponent);
  38755. }
  38756. const Rectangle<int> ListBox::getRowPosition (const int rowNumber,
  38757. const bool relativeToComponentTopLeft) const throw()
  38758. {
  38759. const int rowHeight = getRowHeight();
  38760. int y = viewport->getY() + rowHeight * rowNumber;
  38761. if (relativeToComponentTopLeft)
  38762. y -= viewport->getViewPositionY();
  38763. return Rectangle<int> (viewport->getX(), y,
  38764. viewport->getViewedComponent()->getWidth(), rowHeight);
  38765. }
  38766. void ListBox::setVerticalPosition (const double proportion)
  38767. {
  38768. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38769. viewport->setViewPosition (viewport->getViewPositionX(),
  38770. jmax (0, roundToInt (proportion * offscreen)));
  38771. }
  38772. double ListBox::getVerticalPosition() const
  38773. {
  38774. const int offscreen = viewport->getViewedComponent()->getHeight() - viewport->getHeight();
  38775. return (offscreen > 0) ? viewport->getViewPositionY() / (double) offscreen
  38776. : 0;
  38777. }
  38778. int ListBox::getVisibleRowWidth() const throw()
  38779. {
  38780. return viewport->getViewWidth();
  38781. }
  38782. void ListBox::scrollToEnsureRowIsOnscreen (const int row)
  38783. {
  38784. if (row < viewport->firstWholeIndex)
  38785. {
  38786. viewport->setViewPosition (viewport->getViewPositionX(),
  38787. row * getRowHeight());
  38788. }
  38789. else if (row >= viewport->lastWholeIndex)
  38790. {
  38791. viewport->setViewPosition (viewport->getViewPositionX(),
  38792. jmax (0, (row + 1) * getRowHeight() - viewport->getMaximumVisibleHeight()));
  38793. }
  38794. }
  38795. bool ListBox::keyPressed (const KeyPress& key)
  38796. {
  38797. const int numVisibleRows = viewport->getHeight() / getRowHeight();
  38798. const bool multiple = multipleSelection
  38799. && (lastRowSelected >= 0)
  38800. && (key.getModifiers().isShiftDown()
  38801. || key.getModifiers().isCtrlDown()
  38802. || key.getModifiers().isCommandDown());
  38803. if (key.isKeyCode (KeyPress::upKey))
  38804. {
  38805. if (multiple)
  38806. selectRangeOfRows (lastRowSelected, lastRowSelected - 1);
  38807. else
  38808. selectRow (jmax (0, lastRowSelected - 1));
  38809. }
  38810. else if (key.isKeyCode (KeyPress::returnKey)
  38811. && isRowSelected (lastRowSelected))
  38812. {
  38813. if (model != 0)
  38814. model->returnKeyPressed (lastRowSelected);
  38815. }
  38816. else if (key.isKeyCode (KeyPress::pageUpKey))
  38817. {
  38818. if (multiple)
  38819. selectRangeOfRows (lastRowSelected, lastRowSelected - numVisibleRows);
  38820. else
  38821. selectRow (jmax (0, jmax (0, lastRowSelected) - numVisibleRows));
  38822. }
  38823. else if (key.isKeyCode (KeyPress::pageDownKey))
  38824. {
  38825. if (multiple)
  38826. selectRangeOfRows (lastRowSelected, lastRowSelected + numVisibleRows);
  38827. else
  38828. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + numVisibleRows));
  38829. }
  38830. else if (key.isKeyCode (KeyPress::homeKey))
  38831. {
  38832. if (multiple && key.getModifiers().isShiftDown())
  38833. selectRangeOfRows (lastRowSelected, 0);
  38834. else
  38835. selectRow (0);
  38836. }
  38837. else if (key.isKeyCode (KeyPress::endKey))
  38838. {
  38839. if (multiple && key.getModifiers().isShiftDown())
  38840. selectRangeOfRows (lastRowSelected, totalItems - 1);
  38841. else
  38842. selectRow (totalItems - 1);
  38843. }
  38844. else if (key.isKeyCode (KeyPress::downKey))
  38845. {
  38846. if (multiple)
  38847. selectRangeOfRows (lastRowSelected, lastRowSelected + 1);
  38848. else
  38849. selectRow (jmin (totalItems - 1, jmax (0, lastRowSelected) + 1));
  38850. }
  38851. else if ((key.isKeyCode (KeyPress::deleteKey) || key.isKeyCode (KeyPress::backspaceKey))
  38852. && isRowSelected (lastRowSelected))
  38853. {
  38854. if (model != 0)
  38855. model->deleteKeyPressed (lastRowSelected);
  38856. }
  38857. else if (multiple && key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  38858. {
  38859. selectRangeOfRows (0, std::numeric_limits<int>::max());
  38860. }
  38861. else
  38862. {
  38863. return false;
  38864. }
  38865. return true;
  38866. }
  38867. bool ListBox::keyStateChanged (const bool isKeyDown)
  38868. {
  38869. return isKeyDown
  38870. && (KeyPress::isKeyCurrentlyDown (KeyPress::upKey)
  38871. || KeyPress::isKeyCurrentlyDown (KeyPress::pageUpKey)
  38872. || KeyPress::isKeyCurrentlyDown (KeyPress::downKey)
  38873. || KeyPress::isKeyCurrentlyDown (KeyPress::pageDownKey)
  38874. || KeyPress::isKeyCurrentlyDown (KeyPress::homeKey)
  38875. || KeyPress::isKeyCurrentlyDown (KeyPress::endKey)
  38876. || KeyPress::isKeyCurrentlyDown (KeyPress::returnKey));
  38877. }
  38878. void ListBox::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  38879. {
  38880. getHorizontalScrollBar()->mouseWheelMove (e, wheelIncrementX, 0);
  38881. getVerticalScrollBar()->mouseWheelMove (e, 0, wheelIncrementY);
  38882. }
  38883. void ListBox::mouseMove (const MouseEvent& e)
  38884. {
  38885. if (mouseMoveSelects)
  38886. {
  38887. const MouseEvent e2 (e.getEventRelativeTo (this));
  38888. selectRow (getRowContainingPosition (e2.x, e2.y), true);
  38889. }
  38890. }
  38891. void ListBox::mouseExit (const MouseEvent& e)
  38892. {
  38893. mouseMove (e);
  38894. }
  38895. void ListBox::mouseUp (const MouseEvent& e)
  38896. {
  38897. if (e.mouseWasClicked() && model != 0)
  38898. model->backgroundClicked();
  38899. }
  38900. void ListBox::setRowHeight (const int newHeight)
  38901. {
  38902. rowHeight = jmax (1, newHeight);
  38903. viewport->setSingleStepSizes (20, rowHeight);
  38904. updateContent();
  38905. }
  38906. int ListBox::getNumRowsOnScreen() const throw()
  38907. {
  38908. return viewport->getMaximumVisibleHeight() / rowHeight;
  38909. }
  38910. void ListBox::setMinimumContentWidth (const int newMinimumWidth)
  38911. {
  38912. minimumRowWidth = newMinimumWidth;
  38913. updateContent();
  38914. }
  38915. int ListBox::getVisibleContentWidth() const throw()
  38916. {
  38917. return viewport->getMaximumVisibleWidth();
  38918. }
  38919. ScrollBar* ListBox::getVerticalScrollBar() const throw()
  38920. {
  38921. return viewport->getVerticalScrollBar();
  38922. }
  38923. ScrollBar* ListBox::getHorizontalScrollBar() const throw()
  38924. {
  38925. return viewport->getHorizontalScrollBar();
  38926. }
  38927. void ListBox::colourChanged()
  38928. {
  38929. setOpaque (findColour (backgroundColourId).isOpaque());
  38930. viewport->setOpaque (isOpaque());
  38931. repaint();
  38932. }
  38933. void ListBox::setOutlineThickness (const int outlineThickness_)
  38934. {
  38935. outlineThickness = outlineThickness_;
  38936. resized();
  38937. }
  38938. void ListBox::setHeaderComponent (Component* const newHeaderComponent)
  38939. {
  38940. if (headerComponent != newHeaderComponent)
  38941. {
  38942. delete headerComponent;
  38943. headerComponent = newHeaderComponent;
  38944. addAndMakeVisible (newHeaderComponent);
  38945. ListBox::resized();
  38946. }
  38947. }
  38948. void ListBox::repaintRow (const int rowNumber) throw()
  38949. {
  38950. const Rectangle<int> r (getRowPosition (rowNumber, true));
  38951. repaint (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  38952. }
  38953. Image* ListBox::createSnapshotOfSelectedRows (int& imageX, int& imageY)
  38954. {
  38955. Rectangle<int> imageArea;
  38956. const int firstRow = getRowContainingPosition (0, 0);
  38957. int i;
  38958. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38959. {
  38960. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38961. if (rowComp != 0 && isRowSelected (firstRow + i))
  38962. {
  38963. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38964. const Rectangle<int> rowRect (pos.getX(), pos.getY(), rowComp->getWidth(), rowComp->getHeight());
  38965. if (imageArea.isEmpty())
  38966. imageArea = rowRect;
  38967. else
  38968. imageArea = imageArea.getUnion (rowRect);
  38969. }
  38970. }
  38971. imageArea = imageArea.getIntersection (Rectangle<int> (0, 0, getWidth(), getHeight()));
  38972. imageX = imageArea.getX();
  38973. imageY = imageArea.getY();
  38974. Image* snapshot = Image::createNativeImage (Image::ARGB, imageArea.getWidth(), imageArea.getHeight(), true);
  38975. for (i = getNumRowsOnScreen() + 2; --i >= 0;)
  38976. {
  38977. Component* rowComp = viewport->getComponentForRowIfOnscreen (firstRow + i);
  38978. if (rowComp != 0 && isRowSelected (firstRow + i))
  38979. {
  38980. const Point<int> pos (rowComp->relativePositionToOtherComponent (this, Point<int>()));
  38981. Graphics g (*snapshot);
  38982. g.setOrigin (pos.getX() - imageX, pos.getY() - imageY);
  38983. if (g.reduceClipRegion (0, 0, rowComp->getWidth(), rowComp->getHeight()))
  38984. rowComp->paintEntireComponent (g);
  38985. }
  38986. }
  38987. return snapshot;
  38988. }
  38989. void ListBox::startDragAndDrop (const MouseEvent& e, const String& dragDescription)
  38990. {
  38991. DragAndDropContainer* const dragContainer
  38992. = DragAndDropContainer::findParentDragContainerFor (this);
  38993. if (dragContainer != 0)
  38994. {
  38995. int x, y;
  38996. Image* dragImage = createSnapshotOfSelectedRows (x, y);
  38997. dragImage->multiplyAllAlphas (0.6f);
  38998. MouseEvent e2 (e.getEventRelativeTo (this));
  38999. const Point<int> p (x - e2.x, y - e2.y);
  39000. dragContainer->startDragging (dragDescription, this, dragImage, true, &p);
  39001. }
  39002. else
  39003. {
  39004. // to be able to do a drag-and-drop operation, the listbox needs to
  39005. // be inside a component which is also a DragAndDropContainer.
  39006. jassertfalse
  39007. }
  39008. }
  39009. Component* ListBoxModel::refreshComponentForRow (int, bool, Component* existingComponentToUpdate)
  39010. {
  39011. (void) existingComponentToUpdate;
  39012. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  39013. return 0;
  39014. }
  39015. void ListBoxModel::listBoxItemClicked (int, const MouseEvent&)
  39016. {
  39017. }
  39018. void ListBoxModel::listBoxItemDoubleClicked (int, const MouseEvent&)
  39019. {
  39020. }
  39021. void ListBoxModel::backgroundClicked()
  39022. {
  39023. }
  39024. void ListBoxModel::selectedRowsChanged (int)
  39025. {
  39026. }
  39027. void ListBoxModel::deleteKeyPressed (int)
  39028. {
  39029. }
  39030. void ListBoxModel::returnKeyPressed (int)
  39031. {
  39032. }
  39033. void ListBoxModel::listWasScrolled()
  39034. {
  39035. }
  39036. const String ListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  39037. {
  39038. return String::empty;
  39039. }
  39040. const String ListBoxModel::getTooltipForRow (int)
  39041. {
  39042. return String::empty;
  39043. }
  39044. END_JUCE_NAMESPACE
  39045. /*** End of inlined file: juce_ListBox.cpp ***/
  39046. /*** Start of inlined file: juce_ProgressBar.cpp ***/
  39047. BEGIN_JUCE_NAMESPACE
  39048. ProgressBar::ProgressBar (double& progress_)
  39049. : progress (progress_),
  39050. displayPercentage (true),
  39051. lastCallbackTime (0)
  39052. {
  39053. currentValue = jlimit (0.0, 1.0, progress);
  39054. }
  39055. ProgressBar::~ProgressBar()
  39056. {
  39057. }
  39058. void ProgressBar::setPercentageDisplay (const bool shouldDisplayPercentage)
  39059. {
  39060. displayPercentage = shouldDisplayPercentage;
  39061. repaint();
  39062. }
  39063. void ProgressBar::setTextToDisplay (const String& text)
  39064. {
  39065. displayPercentage = false;
  39066. displayedMessage = text;
  39067. }
  39068. void ProgressBar::lookAndFeelChanged()
  39069. {
  39070. setOpaque (findColour (backgroundColourId).isOpaque());
  39071. }
  39072. void ProgressBar::colourChanged()
  39073. {
  39074. lookAndFeelChanged();
  39075. }
  39076. void ProgressBar::paint (Graphics& g)
  39077. {
  39078. String text;
  39079. if (displayPercentage)
  39080. {
  39081. if (currentValue >= 0 && currentValue <= 1.0)
  39082. text << roundToInt (currentValue * 100.0) << T("%");
  39083. }
  39084. else
  39085. {
  39086. text = displayedMessage;
  39087. }
  39088. getLookAndFeel().drawProgressBar (g, *this,
  39089. getWidth(), getHeight(),
  39090. currentValue, text);
  39091. }
  39092. void ProgressBar::visibilityChanged()
  39093. {
  39094. if (isVisible())
  39095. startTimer (30);
  39096. else
  39097. stopTimer();
  39098. }
  39099. void ProgressBar::timerCallback()
  39100. {
  39101. double newProgress = progress;
  39102. const uint32 now = Time::getMillisecondCounter();
  39103. const int timeSinceLastCallback = (int) (now - lastCallbackTime);
  39104. lastCallbackTime = now;
  39105. if (currentValue != newProgress
  39106. || newProgress < 0 || newProgress >= 1.0
  39107. || currentMessage != displayedMessage)
  39108. {
  39109. if (currentValue < newProgress
  39110. && newProgress >= 0 && newProgress < 1.0
  39111. && currentValue >= 0 && currentValue < 1.0)
  39112. {
  39113. newProgress = jmin (currentValue + 0.0008 * timeSinceLastCallback,
  39114. newProgress);
  39115. }
  39116. currentValue = newProgress;
  39117. currentMessage = displayedMessage;
  39118. repaint();
  39119. }
  39120. }
  39121. END_JUCE_NAMESPACE
  39122. /*** End of inlined file: juce_ProgressBar.cpp ***/
  39123. /*** Start of inlined file: juce_Slider.cpp ***/
  39124. BEGIN_JUCE_NAMESPACE
  39125. class SliderPopupDisplayComponent : public BubbleComponent
  39126. {
  39127. public:
  39128. SliderPopupDisplayComponent (Slider* const owner_)
  39129. : owner (owner_),
  39130. font (15.0f, Font::bold)
  39131. {
  39132. setAlwaysOnTop (true);
  39133. }
  39134. ~SliderPopupDisplayComponent()
  39135. {
  39136. }
  39137. void paintContent (Graphics& g, int w, int h)
  39138. {
  39139. g.setFont (font);
  39140. g.setColour (Colours::black);
  39141. g.drawFittedText (text, 0, 0, w, h, Justification::centred, 1);
  39142. }
  39143. void getContentSize (int& w, int& h)
  39144. {
  39145. w = font.getStringWidth (text) + 18;
  39146. h = (int) (font.getHeight() * 1.6f);
  39147. }
  39148. void updatePosition (const String& newText)
  39149. {
  39150. if (text != newText)
  39151. {
  39152. text = newText;
  39153. repaint();
  39154. }
  39155. BubbleComponent::setPosition (owner);
  39156. }
  39157. juce_UseDebuggingNewOperator
  39158. private:
  39159. Slider* owner;
  39160. Font font;
  39161. String text;
  39162. SliderPopupDisplayComponent (const SliderPopupDisplayComponent&);
  39163. SliderPopupDisplayComponent& operator= (const SliderPopupDisplayComponent&);
  39164. };
  39165. Slider::Slider (const String& name)
  39166. : Component (name),
  39167. lastCurrentValue (0),
  39168. lastValueMin (0),
  39169. lastValueMax (0),
  39170. minimum (0),
  39171. maximum (10),
  39172. interval (0),
  39173. skewFactor (1.0),
  39174. velocityModeSensitivity (1.0),
  39175. velocityModeOffset (0.0),
  39176. velocityModeThreshold (1),
  39177. rotaryStart (float_Pi * 1.2f),
  39178. rotaryEnd (float_Pi * 2.8f),
  39179. numDecimalPlaces (7),
  39180. sliderRegionStart (0),
  39181. sliderRegionSize (1),
  39182. sliderBeingDragged (-1),
  39183. pixelsForFullDragExtent (250),
  39184. style (LinearHorizontal),
  39185. textBoxPos (TextBoxLeft),
  39186. textBoxWidth (80),
  39187. textBoxHeight (20),
  39188. incDecButtonMode (incDecButtonsNotDraggable),
  39189. editableText (true),
  39190. doubleClickToValue (false),
  39191. isVelocityBased (false),
  39192. userKeyOverridesVelocity (true),
  39193. rotaryStop (true),
  39194. incDecButtonsSideBySide (false),
  39195. sendChangeOnlyOnRelease (false),
  39196. popupDisplayEnabled (false),
  39197. menuEnabled (false),
  39198. menuShown (false),
  39199. scrollWheelEnabled (true),
  39200. snapsToMousePos (true),
  39201. valueBox (0),
  39202. incButton (0),
  39203. decButton (0),
  39204. popupDisplay (0),
  39205. parentForPopupDisplay (0)
  39206. {
  39207. setWantsKeyboardFocus (false);
  39208. setRepaintsOnMouseActivity (true);
  39209. lookAndFeelChanged();
  39210. updateText();
  39211. currentValue.addListener (this);
  39212. valueMin.addListener (this);
  39213. valueMax.addListener (this);
  39214. }
  39215. Slider::~Slider()
  39216. {
  39217. currentValue.removeListener (this);
  39218. valueMin.removeListener (this);
  39219. valueMax.removeListener (this);
  39220. popupDisplay = 0;
  39221. deleteAllChildren();
  39222. }
  39223. void Slider::handleAsyncUpdate()
  39224. {
  39225. cancelPendingUpdate();
  39226. for (int i = listeners.size(); --i >= 0;)
  39227. {
  39228. ((SliderListener*) listeners.getUnchecked (i))->sliderValueChanged (this);
  39229. i = jmin (i, listeners.size());
  39230. }
  39231. }
  39232. void Slider::sendDragStart()
  39233. {
  39234. startedDragging();
  39235. for (int i = listeners.size(); --i >= 0;)
  39236. {
  39237. ((SliderListener*) listeners.getUnchecked (i))->sliderDragStarted (this);
  39238. i = jmin (i, listeners.size());
  39239. }
  39240. }
  39241. void Slider::sendDragEnd()
  39242. {
  39243. stoppedDragging();
  39244. sliderBeingDragged = -1;
  39245. for (int i = listeners.size(); --i >= 0;)
  39246. {
  39247. ((SliderListener*) listeners.getUnchecked (i))->sliderDragEnded (this);
  39248. i = jmin (i, listeners.size());
  39249. }
  39250. }
  39251. void Slider::addListener (SliderListener* const listener)
  39252. {
  39253. jassert (listener != 0);
  39254. if (listener != 0)
  39255. listeners.add (listener);
  39256. }
  39257. void Slider::removeListener (SliderListener* const listener)
  39258. {
  39259. listeners.removeValue (listener);
  39260. }
  39261. void Slider::setSliderStyle (const SliderStyle newStyle)
  39262. {
  39263. if (style != newStyle)
  39264. {
  39265. style = newStyle;
  39266. repaint();
  39267. lookAndFeelChanged();
  39268. }
  39269. }
  39270. void Slider::setRotaryParameters (const float startAngleRadians,
  39271. const float endAngleRadians,
  39272. const bool stopAtEnd)
  39273. {
  39274. // make sure the values are sensible..
  39275. jassert (rotaryStart >= 0 && rotaryEnd >= 0);
  39276. jassert (rotaryStart < float_Pi * 4.0f && rotaryEnd < float_Pi * 4.0f);
  39277. jassert (rotaryStart < rotaryEnd);
  39278. rotaryStart = startAngleRadians;
  39279. rotaryEnd = endAngleRadians;
  39280. rotaryStop = stopAtEnd;
  39281. }
  39282. void Slider::setVelocityBasedMode (const bool velBased)
  39283. {
  39284. isVelocityBased = velBased;
  39285. }
  39286. void Slider::setVelocityModeParameters (const double sensitivity,
  39287. const int threshold,
  39288. const double offset,
  39289. const bool userCanPressKeyToSwapMode)
  39290. {
  39291. jassert (threshold >= 0);
  39292. jassert (sensitivity > 0);
  39293. jassert (offset >= 0);
  39294. velocityModeSensitivity = sensitivity;
  39295. velocityModeOffset = offset;
  39296. velocityModeThreshold = threshold;
  39297. userKeyOverridesVelocity = userCanPressKeyToSwapMode;
  39298. }
  39299. void Slider::setSkewFactor (const double factor)
  39300. {
  39301. skewFactor = factor;
  39302. }
  39303. void Slider::setSkewFactorFromMidPoint (const double sliderValueToShowAtMidPoint)
  39304. {
  39305. if (maximum > minimum)
  39306. skewFactor = log (0.5) / log ((sliderValueToShowAtMidPoint - minimum)
  39307. / (maximum - minimum));
  39308. }
  39309. void Slider::setMouseDragSensitivity (const int distanceForFullScaleDrag)
  39310. {
  39311. jassert (distanceForFullScaleDrag > 0);
  39312. pixelsForFullDragExtent = distanceForFullScaleDrag;
  39313. }
  39314. void Slider::setIncDecButtonsMode (const IncDecButtonMode mode)
  39315. {
  39316. if (incDecButtonMode != mode)
  39317. {
  39318. incDecButtonMode = mode;
  39319. lookAndFeelChanged();
  39320. }
  39321. }
  39322. void Slider::setTextBoxStyle (const TextEntryBoxPosition newPosition,
  39323. const bool isReadOnly,
  39324. const int textEntryBoxWidth,
  39325. const int textEntryBoxHeight)
  39326. {
  39327. textBoxPos = newPosition;
  39328. editableText = ! isReadOnly;
  39329. textBoxWidth = textEntryBoxWidth;
  39330. textBoxHeight = textEntryBoxHeight;
  39331. repaint();
  39332. lookAndFeelChanged();
  39333. }
  39334. void Slider::setTextBoxIsEditable (const bool shouldBeEditable)
  39335. {
  39336. editableText = shouldBeEditable;
  39337. if (valueBox != 0)
  39338. valueBox->setEditable (shouldBeEditable && isEnabled());
  39339. }
  39340. void Slider::showTextBox()
  39341. {
  39342. jassert (editableText); // this should probably be avoided in read-only sliders.
  39343. if (valueBox != 0)
  39344. valueBox->showEditor();
  39345. }
  39346. void Slider::hideTextBox (const bool discardCurrentEditorContents)
  39347. {
  39348. if (valueBox != 0)
  39349. {
  39350. valueBox->hideEditor (discardCurrentEditorContents);
  39351. if (discardCurrentEditorContents)
  39352. updateText();
  39353. }
  39354. }
  39355. void Slider::setChangeNotificationOnlyOnRelease (const bool onlyNotifyOnRelease)
  39356. {
  39357. sendChangeOnlyOnRelease = onlyNotifyOnRelease;
  39358. }
  39359. void Slider::setSliderSnapsToMousePosition (const bool shouldSnapToMouse)
  39360. {
  39361. snapsToMousePos = shouldSnapToMouse;
  39362. }
  39363. void Slider::setPopupDisplayEnabled (const bool enabled,
  39364. Component* const parentComponentToUse)
  39365. {
  39366. popupDisplayEnabled = enabled;
  39367. parentForPopupDisplay = parentComponentToUse;
  39368. }
  39369. void Slider::colourChanged()
  39370. {
  39371. lookAndFeelChanged();
  39372. }
  39373. void Slider::lookAndFeelChanged()
  39374. {
  39375. const String previousTextBoxContent (valueBox != 0 ? valueBox->getText()
  39376. : getTextFromValue (currentValue.getValue()));
  39377. deleteAllChildren();
  39378. valueBox = 0;
  39379. LookAndFeel& lf = getLookAndFeel();
  39380. if (textBoxPos != NoTextBox)
  39381. {
  39382. addAndMakeVisible (valueBox = getLookAndFeel().createSliderTextBox (*this));
  39383. valueBox->setWantsKeyboardFocus (false);
  39384. valueBox->setText (previousTextBoxContent, false);
  39385. valueBox->setEditable (editableText && isEnabled());
  39386. valueBox->addListener (this);
  39387. if (style == LinearBar)
  39388. valueBox->addMouseListener (this, false);
  39389. valueBox->setTooltip (getTooltip());
  39390. }
  39391. if (style == IncDecButtons)
  39392. {
  39393. addAndMakeVisible (incButton = lf.createSliderButton (true));
  39394. incButton->addButtonListener (this);
  39395. addAndMakeVisible (decButton = lf.createSliderButton (false));
  39396. decButton->addButtonListener (this);
  39397. if (incDecButtonMode != incDecButtonsNotDraggable)
  39398. {
  39399. incButton->addMouseListener (this, false);
  39400. decButton->addMouseListener (this, false);
  39401. }
  39402. else
  39403. {
  39404. incButton->setRepeatSpeed (300, 100, 20);
  39405. incButton->addMouseListener (decButton, false);
  39406. decButton->setRepeatSpeed (300, 100, 20);
  39407. decButton->addMouseListener (incButton, false);
  39408. }
  39409. incButton->setTooltip (getTooltip());
  39410. decButton->setTooltip (getTooltip());
  39411. }
  39412. setComponentEffect (lf.getSliderEffect());
  39413. resized();
  39414. repaint();
  39415. }
  39416. void Slider::setRange (const double newMin,
  39417. const double newMax,
  39418. const double newInt)
  39419. {
  39420. if (minimum != newMin
  39421. || maximum != newMax
  39422. || interval != newInt)
  39423. {
  39424. minimum = newMin;
  39425. maximum = newMax;
  39426. interval = newInt;
  39427. // figure out the number of DPs needed to display all values at this
  39428. // interval setting.
  39429. numDecimalPlaces = 7;
  39430. if (newInt != 0)
  39431. {
  39432. int v = abs ((int) (newInt * 10000000));
  39433. while ((v % 10) == 0)
  39434. {
  39435. --numDecimalPlaces;
  39436. v /= 10;
  39437. }
  39438. }
  39439. // keep the current values inside the new range..
  39440. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39441. {
  39442. setValue (getValue(), false, false);
  39443. }
  39444. else
  39445. {
  39446. setMinValue (getMinValue(), false, false);
  39447. setMaxValue (getMaxValue(), false, false);
  39448. }
  39449. updateText();
  39450. }
  39451. }
  39452. void Slider::triggerChangeMessage (const bool synchronous)
  39453. {
  39454. if (synchronous)
  39455. handleAsyncUpdate();
  39456. else
  39457. triggerAsyncUpdate();
  39458. valueChanged();
  39459. }
  39460. void Slider::valueChanged (Value& value)
  39461. {
  39462. if (value.refersToSameSourceAs (currentValue))
  39463. {
  39464. if (style != TwoValueHorizontal && style != TwoValueVertical)
  39465. setValue (currentValue.getValue(), false, false);
  39466. }
  39467. else if (value.refersToSameSourceAs (valueMin))
  39468. setMinValue (valueMin.getValue(), false, false, true);
  39469. else if (value.refersToSameSourceAs (valueMax))
  39470. setMaxValue (valueMax.getValue(), false, false, true);
  39471. }
  39472. double Slider::getValue() const
  39473. {
  39474. // for a two-value style slider, you should use the getMinValue() and getMaxValue()
  39475. // methods to get the two values.
  39476. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39477. return currentValue.getValue();
  39478. }
  39479. void Slider::setValue (double newValue,
  39480. const bool sendUpdateMessage,
  39481. const bool sendMessageSynchronously)
  39482. {
  39483. // for a two-value style slider, you should use the setMinValue() and setMaxValue()
  39484. // methods to set the two values.
  39485. jassert (style != TwoValueHorizontal && style != TwoValueVertical);
  39486. newValue = constrainedValue (newValue);
  39487. if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39488. {
  39489. jassert ((double) valueMin.getValue() <= (double) valueMax.getValue());
  39490. newValue = jlimit ((double) valueMin.getValue(),
  39491. (double) valueMax.getValue(),
  39492. newValue);
  39493. }
  39494. if (newValue != lastCurrentValue)
  39495. {
  39496. if (valueBox != 0)
  39497. valueBox->hideEditor (true);
  39498. lastCurrentValue = newValue;
  39499. currentValue = newValue;
  39500. updateText();
  39501. repaint();
  39502. if (popupDisplay != 0)
  39503. {
  39504. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (newValue));
  39505. popupDisplay->repaint();
  39506. }
  39507. if (sendUpdateMessage)
  39508. triggerChangeMessage (sendMessageSynchronously);
  39509. }
  39510. }
  39511. double Slider::getMinValue() const
  39512. {
  39513. // The minimum value only applies to sliders that are in two- or three-value mode.
  39514. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39515. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39516. return valueMin.getValue();
  39517. }
  39518. double Slider::getMaxValue() const
  39519. {
  39520. // The maximum value only applies to sliders that are in two- or three-value mode.
  39521. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39522. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39523. return valueMax.getValue();
  39524. }
  39525. void Slider::setMinValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39526. {
  39527. // The minimum value only applies to sliders that are in two- or three-value mode.
  39528. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39529. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39530. newValue = constrainedValue (newValue);
  39531. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39532. {
  39533. if (allowNudgingOfOtherValues && newValue > (double) valueMax.getValue())
  39534. setMaxValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39535. newValue = jmin ((double) valueMax.getValue(), newValue);
  39536. }
  39537. else
  39538. {
  39539. if (allowNudgingOfOtherValues && newValue > lastCurrentValue)
  39540. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39541. newValue = jmin (lastCurrentValue, newValue);
  39542. }
  39543. if (lastValueMin != newValue)
  39544. {
  39545. lastValueMin = newValue;
  39546. valueMin = newValue;
  39547. repaint();
  39548. if (popupDisplay != 0)
  39549. {
  39550. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (newValue));
  39551. popupDisplay->repaint();
  39552. }
  39553. if (sendUpdateMessage)
  39554. triggerChangeMessage (sendMessageSynchronously);
  39555. }
  39556. }
  39557. void Slider::setMaxValue (double newValue, const bool sendUpdateMessage, const bool sendMessageSynchronously, const bool allowNudgingOfOtherValues)
  39558. {
  39559. // The maximum value only applies to sliders that are in two- or three-value mode.
  39560. jassert (style == TwoValueHorizontal || style == TwoValueVertical
  39561. || style == ThreeValueHorizontal || style == ThreeValueVertical);
  39562. newValue = constrainedValue (newValue);
  39563. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39564. {
  39565. if (allowNudgingOfOtherValues && newValue < (double) valueMin.getValue())
  39566. setMinValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39567. newValue = jmax ((double) valueMin.getValue(), newValue);
  39568. }
  39569. else
  39570. {
  39571. if (allowNudgingOfOtherValues && newValue < lastCurrentValue)
  39572. setValue (newValue, sendUpdateMessage, sendMessageSynchronously);
  39573. newValue = jmax (lastCurrentValue, newValue);
  39574. }
  39575. if (lastValueMax != newValue)
  39576. {
  39577. lastValueMax = newValue;
  39578. valueMax = newValue;
  39579. repaint();
  39580. if (popupDisplay != 0)
  39581. {
  39582. ((SliderPopupDisplayComponent*) popupDisplay)->updatePosition (getTextFromValue (valueMax.getValue()));
  39583. popupDisplay->repaint();
  39584. }
  39585. if (sendUpdateMessage)
  39586. triggerChangeMessage (sendMessageSynchronously);
  39587. }
  39588. }
  39589. void Slider::setDoubleClickReturnValue (const bool isDoubleClickEnabled,
  39590. const double valueToSetOnDoubleClick)
  39591. {
  39592. doubleClickToValue = isDoubleClickEnabled;
  39593. doubleClickReturnValue = valueToSetOnDoubleClick;
  39594. }
  39595. double Slider::getDoubleClickReturnValue (bool& isEnabled_) const
  39596. {
  39597. isEnabled_ = doubleClickToValue;
  39598. return doubleClickReturnValue;
  39599. }
  39600. void Slider::updateText()
  39601. {
  39602. if (valueBox != 0)
  39603. valueBox->setText (getTextFromValue (currentValue.getValue()), false);
  39604. }
  39605. void Slider::setTextValueSuffix (const String& suffix)
  39606. {
  39607. if (textSuffix != suffix)
  39608. {
  39609. textSuffix = suffix;
  39610. updateText();
  39611. }
  39612. }
  39613. const String Slider::getTextFromValue (double v)
  39614. {
  39615. if (numDecimalPlaces > 0)
  39616. return String (v, numDecimalPlaces) + textSuffix;
  39617. else
  39618. return String (roundToInt (v)) + textSuffix;
  39619. }
  39620. double Slider::getValueFromText (const String& text)
  39621. {
  39622. String t (text.trimStart());
  39623. if (t.endsWith (textSuffix))
  39624. t = t.substring (0, t.length() - textSuffix.length());
  39625. while (t.startsWithChar (T('+')))
  39626. t = t.substring (1).trimStart();
  39627. return t.initialSectionContainingOnly (T("0123456789.,-"))
  39628. .getDoubleValue();
  39629. }
  39630. double Slider::proportionOfLengthToValue (double proportion)
  39631. {
  39632. if (skewFactor != 1.0 && proportion > 0.0)
  39633. proportion = exp (log (proportion) / skewFactor);
  39634. return minimum + (maximum - minimum) * proportion;
  39635. }
  39636. double Slider::valueToProportionOfLength (double value)
  39637. {
  39638. const double n = (value - minimum) / (maximum - minimum);
  39639. return skewFactor == 1.0 ? n : pow (n, skewFactor);
  39640. }
  39641. double Slider::snapValue (double attemptedValue, const bool)
  39642. {
  39643. return attemptedValue;
  39644. }
  39645. void Slider::startedDragging()
  39646. {
  39647. }
  39648. void Slider::stoppedDragging()
  39649. {
  39650. }
  39651. void Slider::valueChanged()
  39652. {
  39653. }
  39654. void Slider::enablementChanged()
  39655. {
  39656. repaint();
  39657. }
  39658. void Slider::setPopupMenuEnabled (const bool menuEnabled_)
  39659. {
  39660. menuEnabled = menuEnabled_;
  39661. }
  39662. void Slider::setScrollWheelEnabled (const bool enabled)
  39663. {
  39664. scrollWheelEnabled = enabled;
  39665. }
  39666. void Slider::labelTextChanged (Label* label)
  39667. {
  39668. const double newValue = snapValue (getValueFromText (label->getText()), false);
  39669. if (newValue != (double) currentValue.getValue())
  39670. {
  39671. sendDragStart();
  39672. setValue (newValue, true, true);
  39673. sendDragEnd();
  39674. }
  39675. updateText(); // force a clean-up of the text, needed in case setValue() hasn't done this.
  39676. }
  39677. void Slider::buttonClicked (Button* button)
  39678. {
  39679. if (style == IncDecButtons)
  39680. {
  39681. sendDragStart();
  39682. if (button == incButton)
  39683. setValue (snapValue (getValue() + interval, false), true, true);
  39684. else if (button == decButton)
  39685. setValue (snapValue (getValue() - interval, false), true, true);
  39686. sendDragEnd();
  39687. }
  39688. }
  39689. double Slider::constrainedValue (double value) const
  39690. {
  39691. if (interval > 0)
  39692. value = minimum + interval * floor ((value - minimum) / interval + 0.5);
  39693. if (value <= minimum || maximum <= minimum)
  39694. value = minimum;
  39695. else if (value >= maximum)
  39696. value = maximum;
  39697. return value;
  39698. }
  39699. float Slider::getLinearSliderPos (const double value)
  39700. {
  39701. double sliderPosProportional;
  39702. if (maximum > minimum)
  39703. {
  39704. if (value < minimum)
  39705. {
  39706. sliderPosProportional = 0.0;
  39707. }
  39708. else if (value > maximum)
  39709. {
  39710. sliderPosProportional = 1.0;
  39711. }
  39712. else
  39713. {
  39714. sliderPosProportional = valueToProportionOfLength (value);
  39715. jassert (sliderPosProportional >= 0 && sliderPosProportional <= 1.0);
  39716. }
  39717. }
  39718. else
  39719. {
  39720. sliderPosProportional = 0.5;
  39721. }
  39722. if (isVertical() || style == IncDecButtons)
  39723. sliderPosProportional = 1.0 - sliderPosProportional;
  39724. return (float) (sliderRegionStart + sliderPosProportional * sliderRegionSize);
  39725. }
  39726. bool Slider::isHorizontal() const
  39727. {
  39728. return style == LinearHorizontal
  39729. || style == LinearBar
  39730. || style == TwoValueHorizontal
  39731. || style == ThreeValueHorizontal;
  39732. }
  39733. bool Slider::isVertical() const
  39734. {
  39735. return style == LinearVertical
  39736. || style == TwoValueVertical
  39737. || style == ThreeValueVertical;
  39738. }
  39739. bool Slider::incDecDragDirectionIsHorizontal() const
  39740. {
  39741. return incDecButtonMode == incDecButtonsDraggable_Horizontal
  39742. || (incDecButtonMode == incDecButtonsDraggable_AutoDirection && incDecButtonsSideBySide);
  39743. }
  39744. float Slider::getPositionOfValue (const double value)
  39745. {
  39746. if (isHorizontal() || isVertical())
  39747. {
  39748. return getLinearSliderPos (value);
  39749. }
  39750. else
  39751. {
  39752. jassertfalse // not a valid call on a slider that doesn't work linearly!
  39753. return 0.0f;
  39754. }
  39755. }
  39756. void Slider::paint (Graphics& g)
  39757. {
  39758. if (style != IncDecButtons)
  39759. {
  39760. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39761. {
  39762. const float sliderPos = (float) valueToProportionOfLength (lastCurrentValue);
  39763. jassert (sliderPos >= 0 && sliderPos <= 1.0f);
  39764. getLookAndFeel().drawRotarySlider (g,
  39765. sliderRect.getX(),
  39766. sliderRect.getY(),
  39767. sliderRect.getWidth(),
  39768. sliderRect.getHeight(),
  39769. sliderPos,
  39770. rotaryStart, rotaryEnd,
  39771. *this);
  39772. }
  39773. else
  39774. {
  39775. getLookAndFeel().drawLinearSlider (g,
  39776. sliderRect.getX(),
  39777. sliderRect.getY(),
  39778. sliderRect.getWidth(),
  39779. sliderRect.getHeight(),
  39780. getLinearSliderPos (lastCurrentValue),
  39781. getLinearSliderPos (lastValueMin),
  39782. getLinearSliderPos (lastValueMax),
  39783. style,
  39784. *this);
  39785. }
  39786. if (style == LinearBar && valueBox == 0)
  39787. {
  39788. g.setColour (findColour (Slider::textBoxOutlineColourId));
  39789. g.drawRect (0, 0, getWidth(), getHeight(), 1);
  39790. }
  39791. }
  39792. }
  39793. void Slider::resized()
  39794. {
  39795. int minXSpace = 0;
  39796. int minYSpace = 0;
  39797. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39798. minXSpace = 30;
  39799. else
  39800. minYSpace = 15;
  39801. const int tbw = jmax (0, jmin (textBoxWidth, getWidth() - minXSpace));
  39802. const int tbh = jmax (0, jmin (textBoxHeight, getHeight() - minYSpace));
  39803. if (style == LinearBar)
  39804. {
  39805. if (valueBox != 0)
  39806. valueBox->setBounds (0, 0, getWidth(), getHeight());
  39807. }
  39808. else
  39809. {
  39810. if (textBoxPos == NoTextBox)
  39811. {
  39812. sliderRect.setBounds (0, 0, getWidth(), getHeight());
  39813. }
  39814. else if (textBoxPos == TextBoxLeft)
  39815. {
  39816. valueBox->setBounds (0, (getHeight() - tbh) / 2, tbw, tbh);
  39817. sliderRect.setBounds (tbw, 0, getWidth() - tbw, getHeight());
  39818. }
  39819. else if (textBoxPos == TextBoxRight)
  39820. {
  39821. valueBox->setBounds (getWidth() - tbw, (getHeight() - tbh) / 2, tbw, tbh);
  39822. sliderRect.setBounds (0, 0, getWidth() - tbw, getHeight());
  39823. }
  39824. else if (textBoxPos == TextBoxAbove)
  39825. {
  39826. valueBox->setBounds ((getWidth() - tbw) / 2, 0, tbw, tbh);
  39827. sliderRect.setBounds (0, tbh, getWidth(), getHeight() - tbh);
  39828. }
  39829. else if (textBoxPos == TextBoxBelow)
  39830. {
  39831. valueBox->setBounds ((getWidth() - tbw) / 2, getHeight() - tbh, tbw, tbh);
  39832. sliderRect.setBounds (0, 0, getWidth(), getHeight() - tbh);
  39833. }
  39834. }
  39835. const int indent = getLookAndFeel().getSliderThumbRadius (*this);
  39836. if (style == LinearBar)
  39837. {
  39838. const int barIndent = 1;
  39839. sliderRegionStart = barIndent;
  39840. sliderRegionSize = getWidth() - barIndent * 2;
  39841. sliderRect.setBounds (sliderRegionStart, barIndent,
  39842. sliderRegionSize, getHeight() - barIndent * 2);
  39843. }
  39844. else if (isHorizontal())
  39845. {
  39846. sliderRegionStart = sliderRect.getX() + indent;
  39847. sliderRegionSize = jmax (1, sliderRect.getWidth() - indent * 2);
  39848. sliderRect.setBounds (sliderRegionStart, sliderRect.getY(),
  39849. sliderRegionSize, sliderRect.getHeight());
  39850. }
  39851. else if (isVertical())
  39852. {
  39853. sliderRegionStart = sliderRect.getY() + indent;
  39854. sliderRegionSize = jmax (1, sliderRect.getHeight() - indent * 2);
  39855. sliderRect.setBounds (sliderRect.getX(), sliderRegionStart,
  39856. sliderRect.getWidth(), sliderRegionSize);
  39857. }
  39858. else
  39859. {
  39860. sliderRegionStart = 0;
  39861. sliderRegionSize = 100;
  39862. }
  39863. if (style == IncDecButtons)
  39864. {
  39865. Rectangle<int> buttonRect (sliderRect);
  39866. if (textBoxPos == TextBoxLeft || textBoxPos == TextBoxRight)
  39867. buttonRect.expand (-2, 0);
  39868. else
  39869. buttonRect.expand (0, -2);
  39870. incDecButtonsSideBySide = buttonRect.getWidth() > buttonRect.getHeight();
  39871. if (incDecButtonsSideBySide)
  39872. {
  39873. decButton->setBounds (buttonRect.getX(),
  39874. buttonRect.getY(),
  39875. buttonRect.getWidth() / 2,
  39876. buttonRect.getHeight());
  39877. decButton->setConnectedEdges (Button::ConnectedOnRight);
  39878. incButton->setBounds (buttonRect.getCentreX(),
  39879. buttonRect.getY(),
  39880. buttonRect.getWidth() / 2,
  39881. buttonRect.getHeight());
  39882. incButton->setConnectedEdges (Button::ConnectedOnLeft);
  39883. }
  39884. else
  39885. {
  39886. incButton->setBounds (buttonRect.getX(),
  39887. buttonRect.getY(),
  39888. buttonRect.getWidth(),
  39889. buttonRect.getHeight() / 2);
  39890. incButton->setConnectedEdges (Button::ConnectedOnBottom);
  39891. decButton->setBounds (buttonRect.getX(),
  39892. buttonRect.getCentreY(),
  39893. buttonRect.getWidth(),
  39894. buttonRect.getHeight() / 2);
  39895. decButton->setConnectedEdges (Button::ConnectedOnTop);
  39896. }
  39897. }
  39898. }
  39899. void Slider::focusOfChildComponentChanged (FocusChangeType)
  39900. {
  39901. repaint();
  39902. }
  39903. void Slider::mouseDown (const MouseEvent& e)
  39904. {
  39905. mouseWasHidden = false;
  39906. incDecDragged = false;
  39907. mouseXWhenLastDragged = e.x;
  39908. mouseYWhenLastDragged = e.y;
  39909. mouseDragStartX = e.getMouseDownX();
  39910. mouseDragStartY = e.getMouseDownY();
  39911. if (isEnabled())
  39912. {
  39913. if (e.mods.isPopupMenu() && menuEnabled)
  39914. {
  39915. menuShown = true;
  39916. PopupMenu m;
  39917. m.setLookAndFeel (&getLookAndFeel());
  39918. m.addItem (1, TRANS ("velocity-sensitive mode"), true, isVelocityBased);
  39919. m.addSeparator();
  39920. if (style == Rotary || style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  39921. {
  39922. PopupMenu rotaryMenu;
  39923. rotaryMenu.addItem (2, TRANS ("use circular dragging"), true, style == Rotary);
  39924. rotaryMenu.addItem (3, TRANS ("use left-right dragging"), true, style == RotaryHorizontalDrag);
  39925. rotaryMenu.addItem (4, TRANS ("use up-down dragging"), true, style == RotaryVerticalDrag);
  39926. m.addSubMenu (TRANS ("rotary mode"), rotaryMenu);
  39927. }
  39928. const int r = m.show();
  39929. if (r == 1)
  39930. {
  39931. setVelocityBasedMode (! isVelocityBased);
  39932. }
  39933. else if (r == 2)
  39934. {
  39935. setSliderStyle (Rotary);
  39936. }
  39937. else if (r == 3)
  39938. {
  39939. setSliderStyle (RotaryHorizontalDrag);
  39940. }
  39941. else if (r == 4)
  39942. {
  39943. setSliderStyle (RotaryVerticalDrag);
  39944. }
  39945. }
  39946. else if (maximum > minimum)
  39947. {
  39948. menuShown = false;
  39949. if (valueBox != 0)
  39950. valueBox->hideEditor (true);
  39951. sliderBeingDragged = 0;
  39952. if (style == TwoValueHorizontal
  39953. || style == TwoValueVertical
  39954. || style == ThreeValueHorizontal
  39955. || style == ThreeValueVertical)
  39956. {
  39957. const float mousePos = (float) (isVertical() ? e.y : e.x);
  39958. const float normalPosDistance = fabsf (getLinearSliderPos (currentValue.getValue()) - mousePos);
  39959. const float minPosDistance = fabsf (getLinearSliderPos (valueMin.getValue()) - 0.1f - mousePos);
  39960. const float maxPosDistance = fabsf (getLinearSliderPos (valueMax.getValue()) + 0.1f - mousePos);
  39961. if (style == TwoValueHorizontal || style == TwoValueVertical)
  39962. {
  39963. if (maxPosDistance <= minPosDistance)
  39964. sliderBeingDragged = 2;
  39965. else
  39966. sliderBeingDragged = 1;
  39967. }
  39968. else if (style == ThreeValueHorizontal || style == ThreeValueVertical)
  39969. {
  39970. if (normalPosDistance >= minPosDistance && maxPosDistance >= minPosDistance)
  39971. sliderBeingDragged = 1;
  39972. else if (normalPosDistance >= maxPosDistance)
  39973. sliderBeingDragged = 2;
  39974. }
  39975. }
  39976. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  39977. lastAngle = rotaryStart + (rotaryEnd - rotaryStart)
  39978. * valueToProportionOfLength (currentValue.getValue());
  39979. valueWhenLastDragged = ((sliderBeingDragged == 2) ? valueMax
  39980. : ((sliderBeingDragged == 1) ? valueMin
  39981. : currentValue)).getValue();
  39982. valueOnMouseDown = valueWhenLastDragged;
  39983. if (popupDisplayEnabled)
  39984. {
  39985. SliderPopupDisplayComponent* const popup = new SliderPopupDisplayComponent (this);
  39986. popupDisplay = popup;
  39987. if (parentForPopupDisplay != 0)
  39988. {
  39989. parentForPopupDisplay->addChildComponent (popup);
  39990. }
  39991. else
  39992. {
  39993. popup->addToDesktop (0);
  39994. }
  39995. popup->setVisible (true);
  39996. }
  39997. sendDragStart();
  39998. mouseDrag (e);
  39999. }
  40000. }
  40001. }
  40002. void Slider::mouseUp (const MouseEvent&)
  40003. {
  40004. if (isEnabled()
  40005. && (! menuShown)
  40006. && (maximum > minimum)
  40007. && (style != IncDecButtons || incDecDragged))
  40008. {
  40009. restoreMouseIfHidden();
  40010. if (sendChangeOnlyOnRelease && valueOnMouseDown != (double) currentValue.getValue())
  40011. triggerChangeMessage (false);
  40012. sendDragEnd();
  40013. popupDisplay = 0;
  40014. if (style == IncDecButtons)
  40015. {
  40016. incButton->setState (Button::buttonNormal);
  40017. decButton->setState (Button::buttonNormal);
  40018. }
  40019. }
  40020. }
  40021. void Slider::restoreMouseIfHidden()
  40022. {
  40023. if (mouseWasHidden)
  40024. {
  40025. mouseWasHidden = false;
  40026. Component* c = Component::getComponentUnderMouse();
  40027. if (c == 0)
  40028. c = this;
  40029. c->enableUnboundedMouseMovement (false);
  40030. const double pos = (sliderBeingDragged == 2) ? getMaxValue()
  40031. : ((sliderBeingDragged == 1) ? getMinValue()
  40032. : (double) currentValue.getValue());
  40033. if (style == RotaryHorizontalDrag || style == RotaryVerticalDrag)
  40034. {
  40035. Point<int> mousePos (Desktop::getMousePosition());
  40036. const Point<int> lastMouseDown (Desktop::getLastMouseDownPosition());
  40037. if (style == RotaryHorizontalDrag)
  40038. {
  40039. const double posDiff = valueToProportionOfLength (pos) - valueToProportionOfLength (valueOnMouseDown);
  40040. mousePos = Point<int> (roundToInt (pixelsForFullDragExtent * posDiff + lastMouseDown.getX()),
  40041. lastMouseDown.getY());
  40042. }
  40043. else
  40044. {
  40045. const double posDiff = valueToProportionOfLength (valueOnMouseDown) - valueToProportionOfLength (pos);
  40046. mousePos = Point<int> (lastMouseDown.getX(),
  40047. roundToInt (pixelsForFullDragExtent * posDiff + lastMouseDown.getY()));
  40048. }
  40049. Desktop::setMousePosition (mousePos);
  40050. }
  40051. else
  40052. {
  40053. const int pixelPos = (int) getLinearSliderPos (pos);
  40054. const Point<int> pos (isHorizontal() ? pixelPos : (getWidth() / 2),
  40055. isVertical() ? pixelPos : (getHeight() / 2));
  40056. Desktop::setMousePosition (relativePositionToGlobal (pos));
  40057. }
  40058. }
  40059. }
  40060. void Slider::modifierKeysChanged (const ModifierKeys& modifiers)
  40061. {
  40062. if (isEnabled()
  40063. && style != IncDecButtons
  40064. && style != Rotary
  40065. && isVelocityBased == modifiers.isAnyModifierKeyDown())
  40066. {
  40067. restoreMouseIfHidden();
  40068. }
  40069. }
  40070. static double smallestAngleBetween (double a1, double a2)
  40071. {
  40072. return jmin (fabs (a1 - a2),
  40073. fabs (a1 + double_Pi * 2.0 - a2),
  40074. fabs (a2 + double_Pi * 2.0 - a1));
  40075. }
  40076. void Slider::mouseDrag (const MouseEvent& e)
  40077. {
  40078. if (isEnabled()
  40079. && (! menuShown)
  40080. && (maximum > minimum))
  40081. {
  40082. if (style == Rotary)
  40083. {
  40084. int dx = e.x - sliderRect.getCentreX();
  40085. int dy = e.y - sliderRect.getCentreY();
  40086. if (dx * dx + dy * dy > 25)
  40087. {
  40088. double angle = atan2 ((double) dx, (double) -dy);
  40089. while (angle < 0.0)
  40090. angle += double_Pi * 2.0;
  40091. if (rotaryStop && ! e.mouseWasClicked())
  40092. {
  40093. if (fabs (angle - lastAngle) > double_Pi)
  40094. {
  40095. if (angle >= lastAngle)
  40096. angle -= double_Pi * 2.0;
  40097. else
  40098. angle += double_Pi * 2.0;
  40099. }
  40100. if (angle >= lastAngle)
  40101. angle = jmin (angle, (double) jmax (rotaryStart, rotaryEnd));
  40102. else
  40103. angle = jmax (angle, (double) jmin (rotaryStart, rotaryEnd));
  40104. }
  40105. else
  40106. {
  40107. while (angle < rotaryStart)
  40108. angle += double_Pi * 2.0;
  40109. if (angle > rotaryEnd)
  40110. {
  40111. if (smallestAngleBetween (angle, rotaryStart) <= smallestAngleBetween (angle, rotaryEnd))
  40112. angle = rotaryStart;
  40113. else
  40114. angle = rotaryEnd;
  40115. }
  40116. }
  40117. const double proportion = (angle - rotaryStart) / (rotaryEnd - rotaryStart);
  40118. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, proportion));
  40119. lastAngle = angle;
  40120. }
  40121. }
  40122. else
  40123. {
  40124. if (style == LinearBar && e.mouseWasClicked()
  40125. && valueBox != 0 && valueBox->isEditable())
  40126. return;
  40127. if (style == IncDecButtons && ! incDecDragged)
  40128. {
  40129. if (e.getDistanceFromDragStart() < 10 || e.mouseWasClicked())
  40130. return;
  40131. incDecDragged = true;
  40132. mouseDragStartX = e.x;
  40133. mouseDragStartY = e.y;
  40134. }
  40135. if ((isVelocityBased == (userKeyOverridesVelocity ? e.mods.testFlags (ModifierKeys::ctrlModifier | ModifierKeys::commandModifier | ModifierKeys::altModifier)
  40136. : false))
  40137. || ((maximum - minimum) / sliderRegionSize < interval))
  40138. {
  40139. const int mousePos = (isHorizontal() || style == RotaryHorizontalDrag) ? e.x : e.y;
  40140. double scaledMousePos = (mousePos - sliderRegionStart) / (double) sliderRegionSize;
  40141. if (style == RotaryHorizontalDrag
  40142. || style == RotaryVerticalDrag
  40143. || style == IncDecButtons
  40144. || ((style == LinearHorizontal || style == LinearVertical || style == LinearBar)
  40145. && ! snapsToMousePos))
  40146. {
  40147. const int mouseDiff = (style == RotaryHorizontalDrag
  40148. || style == LinearHorizontal
  40149. || style == LinearBar
  40150. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  40151. ? e.x - mouseDragStartX
  40152. : mouseDragStartY - e.y;
  40153. double newPos = valueToProportionOfLength (valueOnMouseDown)
  40154. + mouseDiff * (1.0 / pixelsForFullDragExtent);
  40155. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, newPos));
  40156. if (style == IncDecButtons)
  40157. {
  40158. incButton->setState (mouseDiff < 0 ? Button::buttonNormal : Button::buttonDown);
  40159. decButton->setState (mouseDiff > 0 ? Button::buttonNormal : Button::buttonDown);
  40160. }
  40161. }
  40162. else
  40163. {
  40164. if (isVertical())
  40165. scaledMousePos = 1.0 - scaledMousePos;
  40166. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, scaledMousePos));
  40167. }
  40168. }
  40169. else
  40170. {
  40171. const int mouseDiff = (isHorizontal() || style == RotaryHorizontalDrag
  40172. || (style == IncDecButtons && incDecDragDirectionIsHorizontal()))
  40173. ? e.x - mouseXWhenLastDragged
  40174. : e.y - mouseYWhenLastDragged;
  40175. const double maxSpeed = jmax (200, sliderRegionSize);
  40176. double speed = jlimit (0.0, maxSpeed, (double) abs (mouseDiff));
  40177. if (speed != 0)
  40178. {
  40179. speed = 0.2 * velocityModeSensitivity
  40180. * (1.0 + sin (double_Pi * (1.5 + jmin (0.5, velocityModeOffset
  40181. + jmax (0.0, (double) (speed - velocityModeThreshold))
  40182. / maxSpeed))));
  40183. if (mouseDiff < 0)
  40184. speed = -speed;
  40185. if (isVertical() || style == RotaryVerticalDrag
  40186. || (style == IncDecButtons && ! incDecDragDirectionIsHorizontal()))
  40187. speed = -speed;
  40188. const double currentPos = valueToProportionOfLength (valueWhenLastDragged);
  40189. valueWhenLastDragged = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + speed));
  40190. e.originalComponent->enableUnboundedMouseMovement (true, false);
  40191. mouseWasHidden = true;
  40192. }
  40193. }
  40194. }
  40195. valueWhenLastDragged = jlimit (minimum, maximum, valueWhenLastDragged);
  40196. if (sliderBeingDragged == 0)
  40197. {
  40198. setValue (snapValue (valueWhenLastDragged, true),
  40199. ! sendChangeOnlyOnRelease, true);
  40200. }
  40201. else if (sliderBeingDragged == 1)
  40202. {
  40203. setMinValue (snapValue (valueWhenLastDragged, true),
  40204. ! sendChangeOnlyOnRelease, false, true);
  40205. if (e.mods.isShiftDown())
  40206. setMaxValue (getMinValue() + minMaxDiff, false, false, true);
  40207. else
  40208. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40209. }
  40210. else
  40211. {
  40212. jassert (sliderBeingDragged == 2);
  40213. setMaxValue (snapValue (valueWhenLastDragged, true),
  40214. ! sendChangeOnlyOnRelease, false, true);
  40215. if (e.mods.isShiftDown())
  40216. setMinValue (getMaxValue() - minMaxDiff, false, false, true);
  40217. else
  40218. minMaxDiff = (double) valueMax.getValue() - (double) valueMin.getValue();
  40219. }
  40220. mouseXWhenLastDragged = e.x;
  40221. mouseYWhenLastDragged = e.y;
  40222. }
  40223. }
  40224. void Slider::mouseDoubleClick (const MouseEvent&)
  40225. {
  40226. if (doubleClickToValue
  40227. && isEnabled()
  40228. && style != IncDecButtons
  40229. && minimum <= doubleClickReturnValue
  40230. && maximum >= doubleClickReturnValue)
  40231. {
  40232. sendDragStart();
  40233. setValue (doubleClickReturnValue, true, true);
  40234. sendDragEnd();
  40235. }
  40236. }
  40237. void Slider::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  40238. {
  40239. if (scrollWheelEnabled && isEnabled()
  40240. && style != TwoValueHorizontal
  40241. && style != TwoValueVertical)
  40242. {
  40243. if (maximum > minimum && ! isMouseButtonDownAnywhere())
  40244. {
  40245. if (valueBox != 0)
  40246. valueBox->hideEditor (false);
  40247. const double value = (double) currentValue.getValue();
  40248. const double proportionDelta = (wheelIncrementX != 0 ? -wheelIncrementX : wheelIncrementY) * 0.15f;
  40249. const double currentPos = valueToProportionOfLength (value);
  40250. const double newValue = proportionOfLengthToValue (jlimit (0.0, 1.0, currentPos + proportionDelta));
  40251. double delta = (newValue != value)
  40252. ? jmax (fabs (newValue - value), interval) : 0;
  40253. if (value > newValue)
  40254. delta = -delta;
  40255. sendDragStart();
  40256. setValue (snapValue (value + delta, false), true, true);
  40257. sendDragEnd();
  40258. }
  40259. }
  40260. else
  40261. {
  40262. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  40263. }
  40264. }
  40265. void SliderListener::sliderDragStarted (Slider*)
  40266. {
  40267. }
  40268. void SliderListener::sliderDragEnded (Slider*)
  40269. {
  40270. }
  40271. END_JUCE_NAMESPACE
  40272. /*** End of inlined file: juce_Slider.cpp ***/
  40273. /*** Start of inlined file: juce_TableHeaderComponent.cpp ***/
  40274. BEGIN_JUCE_NAMESPACE
  40275. class DragOverlayComp : public Component
  40276. {
  40277. public:
  40278. DragOverlayComp (Image* const image_)
  40279. : image (image_)
  40280. {
  40281. image->multiplyAllAlphas (0.8f);
  40282. setAlwaysOnTop (true);
  40283. }
  40284. ~DragOverlayComp()
  40285. {
  40286. }
  40287. void paint (Graphics& g)
  40288. {
  40289. g.drawImageAt (image, 0, 0);
  40290. }
  40291. private:
  40292. ScopedPointer <Image> image;
  40293. DragOverlayComp (const DragOverlayComp&);
  40294. DragOverlayComp& operator= (const DragOverlayComp&);
  40295. };
  40296. TableHeaderComponent::TableHeaderComponent()
  40297. : columnsChanged (false),
  40298. columnsResized (false),
  40299. sortChanged (false),
  40300. menuActive (true),
  40301. stretchToFit (false),
  40302. columnIdBeingResized (0),
  40303. columnIdBeingDragged (0),
  40304. columnIdUnderMouse (0),
  40305. lastDeliberateWidth (0)
  40306. {
  40307. }
  40308. TableHeaderComponent::~TableHeaderComponent()
  40309. {
  40310. dragOverlayComp = 0;
  40311. }
  40312. void TableHeaderComponent::setPopupMenuActive (const bool hasMenu)
  40313. {
  40314. menuActive = hasMenu;
  40315. }
  40316. bool TableHeaderComponent::isPopupMenuActive() const { return menuActive; }
  40317. int TableHeaderComponent::getNumColumns (const bool onlyCountVisibleColumns) const
  40318. {
  40319. if (onlyCountVisibleColumns)
  40320. {
  40321. int num = 0;
  40322. for (int i = columns.size(); --i >= 0;)
  40323. if (columns.getUnchecked(i)->isVisible())
  40324. ++num;
  40325. return num;
  40326. }
  40327. else
  40328. {
  40329. return columns.size();
  40330. }
  40331. }
  40332. const String TableHeaderComponent::getColumnName (const int columnId) const
  40333. {
  40334. const ColumnInfo* const ci = getInfoForId (columnId);
  40335. return ci != 0 ? ci->name : String::empty;
  40336. }
  40337. void TableHeaderComponent::setColumnName (const int columnId, const String& newName)
  40338. {
  40339. ColumnInfo* const ci = getInfoForId (columnId);
  40340. if (ci != 0 && ci->name != newName)
  40341. {
  40342. ci->name = newName;
  40343. sendColumnsChanged();
  40344. }
  40345. }
  40346. void TableHeaderComponent::addColumn (const String& columnName,
  40347. const int columnId,
  40348. const int width,
  40349. const int minimumWidth,
  40350. const int maximumWidth,
  40351. const int propertyFlags,
  40352. const int insertIndex)
  40353. {
  40354. // can't have a duplicate or null ID!
  40355. jassert (columnId != 0 && getIndexOfColumnId (columnId, false) < 0);
  40356. jassert (width > 0);
  40357. ColumnInfo* const ci = new ColumnInfo();
  40358. ci->name = columnName;
  40359. ci->id = columnId;
  40360. ci->width = width;
  40361. ci->lastDeliberateWidth = width;
  40362. ci->minimumWidth = minimumWidth;
  40363. ci->maximumWidth = maximumWidth;
  40364. if (ci->maximumWidth < 0)
  40365. ci->maximumWidth = std::numeric_limits<int>::max();
  40366. jassert (ci->maximumWidth >= ci->minimumWidth);
  40367. ci->propertyFlags = propertyFlags;
  40368. columns.insert (insertIndex, ci);
  40369. sendColumnsChanged();
  40370. }
  40371. void TableHeaderComponent::removeColumn (const int columnIdToRemove)
  40372. {
  40373. const int index = getIndexOfColumnId (columnIdToRemove, false);
  40374. if (index >= 0)
  40375. {
  40376. columns.remove (index);
  40377. sortChanged = true;
  40378. sendColumnsChanged();
  40379. }
  40380. }
  40381. void TableHeaderComponent::removeAllColumns()
  40382. {
  40383. if (columns.size() > 0)
  40384. {
  40385. columns.clear();
  40386. sendColumnsChanged();
  40387. }
  40388. }
  40389. void TableHeaderComponent::moveColumn (const int columnId, int newIndex)
  40390. {
  40391. const int currentIndex = getIndexOfColumnId (columnId, false);
  40392. newIndex = visibleIndexToTotalIndex (newIndex);
  40393. if (columns [currentIndex] != 0 && currentIndex != newIndex)
  40394. {
  40395. columns.move (currentIndex, newIndex);
  40396. sendColumnsChanged();
  40397. }
  40398. }
  40399. int TableHeaderComponent::getColumnWidth (const int columnId) const
  40400. {
  40401. const ColumnInfo* const ci = getInfoForId (columnId);
  40402. return ci != 0 ? ci->width : 0;
  40403. }
  40404. void TableHeaderComponent::setColumnWidth (const int columnId, const int newWidth)
  40405. {
  40406. ColumnInfo* const ci = getInfoForId (columnId);
  40407. if (ci != 0 && ci->width != newWidth)
  40408. {
  40409. const int numColumns = getNumColumns (true);
  40410. ci->lastDeliberateWidth = ci->width
  40411. = jlimit (ci->minimumWidth, ci->maximumWidth, newWidth);
  40412. if (stretchToFit)
  40413. {
  40414. const int index = getIndexOfColumnId (columnId, true) + 1;
  40415. if (((unsigned int) index) < (unsigned int) numColumns)
  40416. {
  40417. const int x = getColumnPosition (index).getX();
  40418. if (lastDeliberateWidth == 0)
  40419. lastDeliberateWidth = getTotalWidth();
  40420. resizeColumnsToFit (visibleIndexToTotalIndex (index), lastDeliberateWidth - x);
  40421. }
  40422. }
  40423. repaint();
  40424. columnsResized = true;
  40425. triggerAsyncUpdate();
  40426. }
  40427. }
  40428. int TableHeaderComponent::getIndexOfColumnId (const int columnId, const bool onlyCountVisibleColumns) const
  40429. {
  40430. int n = 0;
  40431. for (int i = 0; i < columns.size(); ++i)
  40432. {
  40433. if ((! onlyCountVisibleColumns) || columns.getUnchecked(i)->isVisible())
  40434. {
  40435. if (columns.getUnchecked(i)->id == columnId)
  40436. return n;
  40437. ++n;
  40438. }
  40439. }
  40440. return -1;
  40441. }
  40442. int TableHeaderComponent::getColumnIdOfIndex (int index, const bool onlyCountVisibleColumns) const
  40443. {
  40444. if (onlyCountVisibleColumns)
  40445. index = visibleIndexToTotalIndex (index);
  40446. const ColumnInfo* const ci = columns [index];
  40447. return (ci != 0) ? ci->id : 0;
  40448. }
  40449. const Rectangle<int> TableHeaderComponent::getColumnPosition (const int index) const
  40450. {
  40451. int x = 0, width = 0, n = 0;
  40452. for (int i = 0; i < columns.size(); ++i)
  40453. {
  40454. x += width;
  40455. if (columns.getUnchecked(i)->isVisible())
  40456. {
  40457. width = columns.getUnchecked(i)->width;
  40458. if (n++ == index)
  40459. break;
  40460. }
  40461. else
  40462. {
  40463. width = 0;
  40464. }
  40465. }
  40466. return Rectangle<int> (x, 0, width, getHeight());
  40467. }
  40468. int TableHeaderComponent::getColumnIdAtX (const int xToFind) const
  40469. {
  40470. if (xToFind >= 0)
  40471. {
  40472. int x = 0;
  40473. for (int i = 0; i < columns.size(); ++i)
  40474. {
  40475. const ColumnInfo* const ci = columns.getUnchecked(i);
  40476. if (ci->isVisible())
  40477. {
  40478. x += ci->width;
  40479. if (xToFind < x)
  40480. return ci->id;
  40481. }
  40482. }
  40483. }
  40484. return 0;
  40485. }
  40486. int TableHeaderComponent::getTotalWidth() const
  40487. {
  40488. int w = 0;
  40489. for (int i = columns.size(); --i >= 0;)
  40490. if (columns.getUnchecked(i)->isVisible())
  40491. w += columns.getUnchecked(i)->width;
  40492. return w;
  40493. }
  40494. void TableHeaderComponent::setStretchToFitActive (const bool shouldStretchToFit)
  40495. {
  40496. stretchToFit = shouldStretchToFit;
  40497. lastDeliberateWidth = getTotalWidth();
  40498. resized();
  40499. }
  40500. bool TableHeaderComponent::isStretchToFitActive() const
  40501. {
  40502. return stretchToFit;
  40503. }
  40504. void TableHeaderComponent::resizeAllColumnsToFit (int targetTotalWidth)
  40505. {
  40506. if (stretchToFit && getWidth() > 0
  40507. && columnIdBeingResized == 0 && columnIdBeingDragged == 0)
  40508. {
  40509. lastDeliberateWidth = targetTotalWidth;
  40510. resizeColumnsToFit (0, targetTotalWidth);
  40511. }
  40512. }
  40513. void TableHeaderComponent::resizeColumnsToFit (int firstColumnIndex, int targetTotalWidth)
  40514. {
  40515. targetTotalWidth = jmax (targetTotalWidth, 0);
  40516. StretchableObjectResizer sor;
  40517. int i;
  40518. for (i = firstColumnIndex; i < columns.size(); ++i)
  40519. {
  40520. ColumnInfo* const ci = columns.getUnchecked(i);
  40521. if (ci->isVisible())
  40522. sor.addItem (ci->lastDeliberateWidth, ci->minimumWidth, ci->maximumWidth);
  40523. }
  40524. sor.resizeToFit (targetTotalWidth);
  40525. int visIndex = 0;
  40526. for (i = firstColumnIndex; i < columns.size(); ++i)
  40527. {
  40528. ColumnInfo* const ci = columns.getUnchecked(i);
  40529. if (ci->isVisible())
  40530. {
  40531. const int newWidth = jlimit (ci->minimumWidth, ci->maximumWidth,
  40532. (int) floor (sor.getItemSize (visIndex++)));
  40533. if (newWidth != ci->width)
  40534. {
  40535. ci->width = newWidth;
  40536. repaint();
  40537. columnsResized = true;
  40538. triggerAsyncUpdate();
  40539. }
  40540. }
  40541. }
  40542. }
  40543. void TableHeaderComponent::setColumnVisible (const int columnId, const bool shouldBeVisible)
  40544. {
  40545. ColumnInfo* const ci = getInfoForId (columnId);
  40546. if (ci != 0 && shouldBeVisible != ci->isVisible())
  40547. {
  40548. if (shouldBeVisible)
  40549. ci->propertyFlags |= visible;
  40550. else
  40551. ci->propertyFlags &= ~visible;
  40552. sendColumnsChanged();
  40553. resized();
  40554. }
  40555. }
  40556. bool TableHeaderComponent::isColumnVisible (const int columnId) const
  40557. {
  40558. const ColumnInfo* const ci = getInfoForId (columnId);
  40559. return ci != 0 && ci->isVisible();
  40560. }
  40561. void TableHeaderComponent::setSortColumnId (const int columnId, const bool sortForwards)
  40562. {
  40563. if (getSortColumnId() != columnId || isSortedForwards() != sortForwards)
  40564. {
  40565. for (int i = columns.size(); --i >= 0;)
  40566. columns.getUnchecked(i)->propertyFlags &= ~(sortedForwards | sortedBackwards);
  40567. ColumnInfo* const ci = getInfoForId (columnId);
  40568. if (ci != 0)
  40569. ci->propertyFlags |= (sortForwards ? sortedForwards : sortedBackwards);
  40570. reSortTable();
  40571. }
  40572. }
  40573. int TableHeaderComponent::getSortColumnId() const
  40574. {
  40575. for (int i = columns.size(); --i >= 0;)
  40576. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40577. return columns.getUnchecked(i)->id;
  40578. return 0;
  40579. }
  40580. bool TableHeaderComponent::isSortedForwards() const
  40581. {
  40582. for (int i = columns.size(); --i >= 0;)
  40583. if ((columns.getUnchecked(i)->propertyFlags & (sortedForwards | sortedBackwards)) != 0)
  40584. return (columns.getUnchecked(i)->propertyFlags & sortedForwards) != 0;
  40585. return true;
  40586. }
  40587. void TableHeaderComponent::reSortTable()
  40588. {
  40589. sortChanged = true;
  40590. repaint();
  40591. triggerAsyncUpdate();
  40592. }
  40593. const String TableHeaderComponent::toString() const
  40594. {
  40595. String s;
  40596. XmlElement doc ("TABLELAYOUT");
  40597. doc.setAttribute ("sortedCol", getSortColumnId());
  40598. doc.setAttribute ("sortForwards", isSortedForwards());
  40599. for (int i = 0; i < columns.size(); ++i)
  40600. {
  40601. const ColumnInfo* const ci = columns.getUnchecked (i);
  40602. XmlElement* const e = doc.createNewChildElement ("COLUMN");
  40603. e->setAttribute ("id", ci->id);
  40604. e->setAttribute ("visible", ci->isVisible());
  40605. e->setAttribute ("width", ci->width);
  40606. }
  40607. return doc.createDocument (String::empty, true, false);
  40608. }
  40609. void TableHeaderComponent::restoreFromString (const String& storedVersion)
  40610. {
  40611. XmlDocument doc (storedVersion);
  40612. ScopedPointer <XmlElement> storedXml (doc.getDocumentElement());
  40613. int index = 0;
  40614. if (storedXml != 0 && storedXml->hasTagName ("TABLELAYOUT"))
  40615. {
  40616. forEachXmlChildElement (*storedXml, col)
  40617. {
  40618. const int tabId = col->getIntAttribute ("id");
  40619. ColumnInfo* const ci = getInfoForId (tabId);
  40620. if (ci != 0)
  40621. {
  40622. columns.move (columns.indexOf (ci), index);
  40623. ci->width = col->getIntAttribute ("width");
  40624. setColumnVisible (tabId, col->getBoolAttribute ("visible"));
  40625. }
  40626. ++index;
  40627. }
  40628. columnsResized = true;
  40629. sendColumnsChanged();
  40630. setSortColumnId (storedXml->getIntAttribute ("sortedCol"),
  40631. storedXml->getBoolAttribute ("sortForwards", true));
  40632. }
  40633. }
  40634. void TableHeaderComponent::addListener (TableHeaderListener* const newListener)
  40635. {
  40636. listeners.addIfNotAlreadyThere (newListener);
  40637. }
  40638. void TableHeaderComponent::removeListener (TableHeaderListener* const listenerToRemove)
  40639. {
  40640. listeners.removeValue (listenerToRemove);
  40641. }
  40642. void TableHeaderComponent::columnClicked (int columnId, const ModifierKeys& mods)
  40643. {
  40644. const ColumnInfo* const ci = getInfoForId (columnId);
  40645. if (ci != 0 && (ci->propertyFlags & sortable) != 0 && ! mods.isPopupMenu())
  40646. setSortColumnId (columnId, (ci->propertyFlags & sortedForwards) == 0);
  40647. }
  40648. void TableHeaderComponent::addMenuItems (PopupMenu& menu, const int /*columnIdClicked*/)
  40649. {
  40650. for (int i = 0; i < columns.size(); ++i)
  40651. {
  40652. const ColumnInfo* const ci = columns.getUnchecked(i);
  40653. if ((ci->propertyFlags & appearsOnColumnMenu) != 0)
  40654. menu.addItem (ci->id, ci->name,
  40655. (ci->propertyFlags & (sortedForwards | sortedBackwards)) == 0,
  40656. isColumnVisible (ci->id));
  40657. }
  40658. }
  40659. void TableHeaderComponent::reactToMenuItem (const int menuReturnId, const int /*columnIdClicked*/)
  40660. {
  40661. if (getIndexOfColumnId (menuReturnId, false) >= 0)
  40662. setColumnVisible (menuReturnId, ! isColumnVisible (menuReturnId));
  40663. }
  40664. void TableHeaderComponent::paint (Graphics& g)
  40665. {
  40666. LookAndFeel& lf = getLookAndFeel();
  40667. lf.drawTableHeaderBackground (g, *this);
  40668. const Rectangle<int> clip (g.getClipBounds());
  40669. int x = 0;
  40670. for (int i = 0; i < columns.size(); ++i)
  40671. {
  40672. const ColumnInfo* const ci = columns.getUnchecked(i);
  40673. if (ci->isVisible())
  40674. {
  40675. if (x + ci->width > clip.getX()
  40676. && (ci->id != columnIdBeingDragged
  40677. || dragOverlayComp == 0
  40678. || ! dragOverlayComp->isVisible()))
  40679. {
  40680. g.saveState();
  40681. g.setOrigin (x, 0);
  40682. g.reduceClipRegion (0, 0, ci->width, getHeight());
  40683. lf.drawTableHeaderColumn (g, ci->name, ci->id, ci->width, getHeight(),
  40684. ci->id == columnIdUnderMouse,
  40685. ci->id == columnIdUnderMouse && isMouseButtonDown(),
  40686. ci->propertyFlags);
  40687. g.restoreState();
  40688. }
  40689. x += ci->width;
  40690. if (x >= clip.getRight())
  40691. break;
  40692. }
  40693. }
  40694. }
  40695. void TableHeaderComponent::resized()
  40696. {
  40697. }
  40698. void TableHeaderComponent::mouseMove (const MouseEvent& e)
  40699. {
  40700. updateColumnUnderMouse (e.x, e.y);
  40701. }
  40702. void TableHeaderComponent::mouseEnter (const MouseEvent& e)
  40703. {
  40704. updateColumnUnderMouse (e.x, e.y);
  40705. }
  40706. void TableHeaderComponent::mouseExit (const MouseEvent& e)
  40707. {
  40708. updateColumnUnderMouse (e.x, e.y);
  40709. }
  40710. void TableHeaderComponent::mouseDown (const MouseEvent& e)
  40711. {
  40712. repaint();
  40713. columnIdBeingResized = 0;
  40714. columnIdBeingDragged = 0;
  40715. if (columnIdUnderMouse != 0)
  40716. {
  40717. draggingColumnOffset = e.x - getColumnPosition (getIndexOfColumnId (columnIdUnderMouse, true)).getX();
  40718. if (e.mods.isPopupMenu())
  40719. columnClicked (columnIdUnderMouse, e.mods);
  40720. }
  40721. if (menuActive && e.mods.isPopupMenu())
  40722. showColumnChooserMenu (columnIdUnderMouse);
  40723. }
  40724. void TableHeaderComponent::mouseDrag (const MouseEvent& e)
  40725. {
  40726. if (columnIdBeingResized == 0
  40727. && columnIdBeingDragged == 0
  40728. && ! (e.mouseWasClicked() || e.mods.isPopupMenu()))
  40729. {
  40730. dragOverlayComp = 0;
  40731. columnIdBeingResized = getResizeDraggerAt (e.getMouseDownX());
  40732. if (columnIdBeingResized != 0)
  40733. {
  40734. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40735. initialColumnWidth = ci->width;
  40736. }
  40737. else
  40738. {
  40739. beginDrag (e);
  40740. }
  40741. }
  40742. if (columnIdBeingResized != 0)
  40743. {
  40744. const ColumnInfo* const ci = getInfoForId (columnIdBeingResized);
  40745. if (ci != 0)
  40746. {
  40747. int w = jlimit (ci->minimumWidth, ci->maximumWidth,
  40748. initialColumnWidth + e.getDistanceFromDragStartX());
  40749. if (stretchToFit)
  40750. {
  40751. // prevent us dragging a column too far right if we're in stretch-to-fit mode
  40752. int minWidthOnRight = 0;
  40753. for (int i = getIndexOfColumnId (columnIdBeingResized, false) + 1; i < columns.size(); ++i)
  40754. if (columns.getUnchecked (i)->isVisible())
  40755. minWidthOnRight += columns.getUnchecked (i)->minimumWidth;
  40756. const Rectangle<int> currentPos (getColumnPosition (getIndexOfColumnId (columnIdBeingResized, true)));
  40757. w = jmax (ci->minimumWidth, jmin (w, getWidth() - minWidthOnRight - currentPos.getX()));
  40758. }
  40759. setColumnWidth (columnIdBeingResized, w);
  40760. }
  40761. }
  40762. else if (columnIdBeingDragged != 0)
  40763. {
  40764. if (e.y >= -50 && e.y < getHeight() + 50)
  40765. {
  40766. if (dragOverlayComp != 0)
  40767. {
  40768. dragOverlayComp->setVisible (true);
  40769. dragOverlayComp->setBounds (jlimit (0,
  40770. jmax (0, getTotalWidth() - dragOverlayComp->getWidth()),
  40771. e.x - draggingColumnOffset),
  40772. 0,
  40773. dragOverlayComp->getWidth(),
  40774. getHeight());
  40775. for (int i = columns.size(); --i >= 0;)
  40776. {
  40777. const int currentIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40778. int newIndex = currentIndex;
  40779. if (newIndex > 0)
  40780. {
  40781. // if the previous column isn't draggable, we can't move our column
  40782. // past it, because that'd change the undraggable column's position..
  40783. const ColumnInfo* const previous = columns.getUnchecked (newIndex - 1);
  40784. if ((previous->propertyFlags & draggable) != 0)
  40785. {
  40786. const int leftOfPrevious = getColumnPosition (newIndex - 1).getX();
  40787. const int rightOfCurrent = getColumnPosition (newIndex).getRight();
  40788. if (abs (dragOverlayComp->getX() - leftOfPrevious)
  40789. < abs (dragOverlayComp->getRight() - rightOfCurrent))
  40790. {
  40791. --newIndex;
  40792. }
  40793. }
  40794. }
  40795. if (newIndex < columns.size() - 1)
  40796. {
  40797. // if the next column isn't draggable, we can't move our column
  40798. // past it, because that'd change the undraggable column's position..
  40799. const ColumnInfo* const nextCol = columns.getUnchecked (newIndex + 1);
  40800. if ((nextCol->propertyFlags & draggable) != 0)
  40801. {
  40802. const int leftOfCurrent = getColumnPosition (newIndex).getX();
  40803. const int rightOfNext = getColumnPosition (newIndex + 1).getRight();
  40804. if (abs (dragOverlayComp->getX() - leftOfCurrent)
  40805. > abs (dragOverlayComp->getRight() - rightOfNext))
  40806. {
  40807. ++newIndex;
  40808. }
  40809. }
  40810. }
  40811. if (newIndex != currentIndex)
  40812. moveColumn (columnIdBeingDragged, newIndex);
  40813. else
  40814. break;
  40815. }
  40816. }
  40817. }
  40818. else
  40819. {
  40820. endDrag (draggingColumnOriginalIndex);
  40821. }
  40822. }
  40823. }
  40824. void TableHeaderComponent::beginDrag (const MouseEvent& e)
  40825. {
  40826. if (columnIdBeingDragged == 0)
  40827. {
  40828. columnIdBeingDragged = getColumnIdAtX (e.getMouseDownX());
  40829. const ColumnInfo* const ci = getInfoForId (columnIdBeingDragged);
  40830. if (ci == 0 || (ci->propertyFlags & draggable) == 0)
  40831. {
  40832. columnIdBeingDragged = 0;
  40833. }
  40834. else
  40835. {
  40836. draggingColumnOriginalIndex = getIndexOfColumnId (columnIdBeingDragged, true);
  40837. const Rectangle<int> columnRect (getColumnPosition (draggingColumnOriginalIndex));
  40838. const int temp = columnIdBeingDragged;
  40839. columnIdBeingDragged = 0;
  40840. addAndMakeVisible (dragOverlayComp = new DragOverlayComp (createComponentSnapshot (columnRect, false)));
  40841. columnIdBeingDragged = temp;
  40842. dragOverlayComp->setBounds (columnRect);
  40843. for (int i = listeners.size(); --i >= 0;)
  40844. {
  40845. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, columnIdBeingDragged);
  40846. i = jmin (i, listeners.size() - 1);
  40847. }
  40848. }
  40849. }
  40850. }
  40851. void TableHeaderComponent::endDrag (const int finalIndex)
  40852. {
  40853. if (columnIdBeingDragged != 0)
  40854. {
  40855. moveColumn (columnIdBeingDragged, finalIndex);
  40856. columnIdBeingDragged = 0;
  40857. repaint();
  40858. for (int i = listeners.size(); --i >= 0;)
  40859. {
  40860. listeners.getUnchecked(i)->tableColumnDraggingChanged (this, 0);
  40861. i = jmin (i, listeners.size() - 1);
  40862. }
  40863. }
  40864. }
  40865. void TableHeaderComponent::mouseUp (const MouseEvent& e)
  40866. {
  40867. mouseDrag (e);
  40868. for (int i = columns.size(); --i >= 0;)
  40869. if (columns.getUnchecked (i)->isVisible())
  40870. columns.getUnchecked (i)->lastDeliberateWidth = columns.getUnchecked (i)->width;
  40871. columnIdBeingResized = 0;
  40872. repaint();
  40873. endDrag (getIndexOfColumnId (columnIdBeingDragged, true));
  40874. updateColumnUnderMouse (e.x, e.y);
  40875. if (columnIdUnderMouse != 0 && e.mouseWasClicked() && ! e.mods.isPopupMenu())
  40876. columnClicked (columnIdUnderMouse, e.mods);
  40877. dragOverlayComp = 0;
  40878. }
  40879. const MouseCursor TableHeaderComponent::getMouseCursor()
  40880. {
  40881. if (columnIdBeingResized != 0 || (getResizeDraggerAt (getMouseXYRelative().getX()) != 0 && ! isMouseButtonDown()))
  40882. return MouseCursor (MouseCursor::LeftRightResizeCursor);
  40883. return Component::getMouseCursor();
  40884. }
  40885. bool TableHeaderComponent::ColumnInfo::isVisible() const
  40886. {
  40887. return (propertyFlags & TableHeaderComponent::visible) != 0;
  40888. }
  40889. TableHeaderComponent::ColumnInfo* TableHeaderComponent::getInfoForId (const int id) const
  40890. {
  40891. for (int i = columns.size(); --i >= 0;)
  40892. if (columns.getUnchecked(i)->id == id)
  40893. return columns.getUnchecked(i);
  40894. return 0;
  40895. }
  40896. int TableHeaderComponent::visibleIndexToTotalIndex (const int visibleIndex) const
  40897. {
  40898. int n = 0;
  40899. for (int i = 0; i < columns.size(); ++i)
  40900. {
  40901. if (columns.getUnchecked(i)->isVisible())
  40902. {
  40903. if (n == visibleIndex)
  40904. return i;
  40905. ++n;
  40906. }
  40907. }
  40908. return -1;
  40909. }
  40910. void TableHeaderComponent::sendColumnsChanged()
  40911. {
  40912. if (stretchToFit && lastDeliberateWidth > 0)
  40913. resizeAllColumnsToFit (lastDeliberateWidth);
  40914. repaint();
  40915. columnsChanged = true;
  40916. triggerAsyncUpdate();
  40917. }
  40918. void TableHeaderComponent::handleAsyncUpdate()
  40919. {
  40920. const bool changed = columnsChanged || sortChanged;
  40921. const bool sized = columnsResized || changed;
  40922. const bool sorted = sortChanged;
  40923. columnsChanged = false;
  40924. columnsResized = false;
  40925. sortChanged = false;
  40926. if (sorted)
  40927. {
  40928. for (int i = listeners.size(); --i >= 0;)
  40929. {
  40930. listeners.getUnchecked(i)->tableSortOrderChanged (this);
  40931. i = jmin (i, listeners.size() - 1);
  40932. }
  40933. }
  40934. if (changed)
  40935. {
  40936. for (int i = listeners.size(); --i >= 0;)
  40937. {
  40938. listeners.getUnchecked(i)->tableColumnsChanged (this);
  40939. i = jmin (i, listeners.size() - 1);
  40940. }
  40941. }
  40942. if (sized)
  40943. {
  40944. for (int i = listeners.size(); --i >= 0;)
  40945. {
  40946. listeners.getUnchecked(i)->tableColumnsResized (this);
  40947. i = jmin (i, listeners.size() - 1);
  40948. }
  40949. }
  40950. }
  40951. int TableHeaderComponent::getResizeDraggerAt (const int mouseX) const
  40952. {
  40953. if (((unsigned int) mouseX) < (unsigned int) getWidth())
  40954. {
  40955. const int draggableDistance = 3;
  40956. int x = 0;
  40957. for (int i = 0; i < columns.size(); ++i)
  40958. {
  40959. const ColumnInfo* const ci = columns.getUnchecked(i);
  40960. if (ci->isVisible())
  40961. {
  40962. if (abs (mouseX - (x + ci->width)) <= draggableDistance
  40963. && (ci->propertyFlags & resizable) != 0)
  40964. return ci->id;
  40965. x += ci->width;
  40966. }
  40967. }
  40968. }
  40969. return 0;
  40970. }
  40971. void TableHeaderComponent::updateColumnUnderMouse (int x, int y)
  40972. {
  40973. const int newCol = (reallyContains (x, y, true) && getResizeDraggerAt (x) == 0)
  40974. ? getColumnIdAtX (x) : 0;
  40975. if (newCol != columnIdUnderMouse)
  40976. {
  40977. columnIdUnderMouse = newCol;
  40978. repaint();
  40979. }
  40980. }
  40981. void TableHeaderComponent::showColumnChooserMenu (const int columnIdClicked)
  40982. {
  40983. PopupMenu m;
  40984. addMenuItems (m, columnIdClicked);
  40985. if (m.getNumItems() > 0)
  40986. {
  40987. m.setLookAndFeel (&getLookAndFeel());
  40988. const int result = m.show();
  40989. if (result != 0)
  40990. reactToMenuItem (result, columnIdClicked);
  40991. }
  40992. }
  40993. void TableHeaderListener::tableColumnDraggingChanged (TableHeaderComponent*, int)
  40994. {
  40995. }
  40996. END_JUCE_NAMESPACE
  40997. /*** End of inlined file: juce_TableHeaderComponent.cpp ***/
  40998. /*** Start of inlined file: juce_TableListBox.cpp ***/
  40999. BEGIN_JUCE_NAMESPACE
  41000. static const char* const tableColumnPropertyTag = "_tableColumnID";
  41001. class TableListRowComp : public Component,
  41002. public TooltipClient
  41003. {
  41004. public:
  41005. TableListRowComp (TableListBox& owner_)
  41006. : owner (owner_),
  41007. row (-1),
  41008. isSelected (false)
  41009. {
  41010. }
  41011. ~TableListRowComp()
  41012. {
  41013. deleteAllChildren();
  41014. }
  41015. void paint (Graphics& g)
  41016. {
  41017. TableListBoxModel* const model = owner.getModel();
  41018. if (model != 0)
  41019. {
  41020. const TableHeaderComponent* const header = owner.getHeader();
  41021. model->paintRowBackground (g, row, getWidth(), getHeight(), isSelected);
  41022. const int numColumns = header->getNumColumns (true);
  41023. for (int i = 0; i < numColumns; ++i)
  41024. {
  41025. if (! columnsWithComponents [i])
  41026. {
  41027. const int columnId = header->getColumnIdOfIndex (i, true);
  41028. Rectangle<int> columnRect (header->getColumnPosition (i));
  41029. columnRect.setSize (columnRect.getWidth(), getHeight());
  41030. g.saveState();
  41031. g.reduceClipRegion (columnRect);
  41032. g.setOrigin (columnRect.getX(), 0);
  41033. model->paintCell (g, row, columnId, columnRect.getWidth(), columnRect.getHeight(), isSelected);
  41034. g.restoreState();
  41035. }
  41036. }
  41037. }
  41038. }
  41039. void update (const int newRow, const bool isNowSelected)
  41040. {
  41041. if (newRow != row || isNowSelected != isSelected)
  41042. {
  41043. row = newRow;
  41044. isSelected = isNowSelected;
  41045. repaint();
  41046. }
  41047. if (row < owner.getNumRows())
  41048. {
  41049. jassert (row >= 0);
  41050. const var::identifier tagPropertyName ("_tableLastUseNum");
  41051. const int newTag = Random::getSystemRandom().nextInt();
  41052. const TableHeaderComponent* const header = owner.getHeader();
  41053. const int numColumns = header->getNumColumns (true);
  41054. int i;
  41055. columnsWithComponents.clear();
  41056. if (owner.getModel() != 0)
  41057. {
  41058. for (i = 0; i < numColumns; ++i)
  41059. {
  41060. const int columnId = header->getColumnIdOfIndex (i, true);
  41061. Component* const newComp
  41062. = owner.getModel()->refreshComponentForCell (row, columnId, isSelected,
  41063. findChildComponentForColumn (columnId));
  41064. if (newComp != 0)
  41065. {
  41066. addAndMakeVisible (newComp);
  41067. newComp->getProperties().set (tagPropertyName, newTag);
  41068. newComp->getProperties().set (tableColumnPropertyTag, columnId);
  41069. const Rectangle<int> columnRect (header->getColumnPosition (i));
  41070. newComp->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  41071. columnsWithComponents.setBit (i);
  41072. }
  41073. }
  41074. }
  41075. for (i = getNumChildComponents(); --i >= 0;)
  41076. {
  41077. Component* const c = getChildComponent (i);
  41078. if ((int) c->getProperties() [tagPropertyName] != newTag)
  41079. delete c;
  41080. }
  41081. }
  41082. else
  41083. {
  41084. columnsWithComponents.clear();
  41085. deleteAllChildren();
  41086. }
  41087. }
  41088. void resized()
  41089. {
  41090. for (int i = getNumChildComponents(); --i >= 0;)
  41091. {
  41092. Component* const c = getChildComponent (i);
  41093. const int columnId = c->getProperties() [tableColumnPropertyTag];
  41094. if (columnId != 0)
  41095. {
  41096. const Rectangle<int> columnRect (owner.getHeader()->getColumnPosition (owner.getHeader()->getIndexOfColumnId (columnId, true)));
  41097. c->setBounds (columnRect.getX(), 0, columnRect.getWidth(), getHeight());
  41098. }
  41099. }
  41100. }
  41101. void mouseDown (const MouseEvent& e)
  41102. {
  41103. isDragging = false;
  41104. selectRowOnMouseUp = false;
  41105. if (isEnabled())
  41106. {
  41107. if (! isSelected)
  41108. {
  41109. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  41110. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41111. if (columnId != 0 && owner.getModel() != 0)
  41112. owner.getModel()->cellClicked (row, columnId, e);
  41113. }
  41114. else
  41115. {
  41116. selectRowOnMouseUp = true;
  41117. }
  41118. }
  41119. }
  41120. void mouseDrag (const MouseEvent& e)
  41121. {
  41122. if (isEnabled() && owner.getModel() != 0 && ! (e.mouseWasClicked() || isDragging))
  41123. {
  41124. const SparseSet <int> selectedRows (owner.getSelectedRows());
  41125. if (selectedRows.size() > 0)
  41126. {
  41127. const String dragDescription (owner.getModel()->getDragSourceDescription (selectedRows));
  41128. if (dragDescription.isNotEmpty())
  41129. {
  41130. isDragging = true;
  41131. owner.startDragAndDrop (e, dragDescription);
  41132. }
  41133. }
  41134. }
  41135. }
  41136. void mouseUp (const MouseEvent& e)
  41137. {
  41138. if (selectRowOnMouseUp && e.mouseWasClicked() && isEnabled())
  41139. {
  41140. owner.selectRowsBasedOnModifierKeys (row, e.mods);
  41141. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41142. if (columnId != 0 && owner.getModel() != 0)
  41143. owner.getModel()->cellClicked (row, columnId, e);
  41144. }
  41145. }
  41146. void mouseDoubleClick (const MouseEvent& e)
  41147. {
  41148. const int columnId = owner.getHeader()->getColumnIdAtX (e.x);
  41149. if (columnId != 0 && owner.getModel() != 0)
  41150. owner.getModel()->cellDoubleClicked (row, columnId, e);
  41151. }
  41152. const String getTooltip()
  41153. {
  41154. const int columnId = owner.getHeader()->getColumnIdAtX (getMouseXYRelative().getX());
  41155. if (columnId != 0 && owner.getModel() != 0)
  41156. return owner.getModel()->getCellTooltip (row, columnId);
  41157. return String::empty;
  41158. }
  41159. juce_UseDebuggingNewOperator
  41160. private:
  41161. TableListBox& owner;
  41162. int row;
  41163. bool isSelected, isDragging, selectRowOnMouseUp;
  41164. BitArray columnsWithComponents;
  41165. Component* findChildComponentForColumn (const int columnId) const
  41166. {
  41167. for (int i = getNumChildComponents(); --i >= 0;)
  41168. {
  41169. Component* const c = getChildComponent (i);
  41170. if ((int) c->getProperties() [tableColumnPropertyTag] == columnId)
  41171. return c;
  41172. }
  41173. return 0;
  41174. }
  41175. TableListRowComp (const TableListRowComp&);
  41176. TableListRowComp& operator= (const TableListRowComp&);
  41177. };
  41178. class TableListBoxHeader : public TableHeaderComponent
  41179. {
  41180. public:
  41181. TableListBoxHeader (TableListBox& owner_)
  41182. : owner (owner_)
  41183. {
  41184. }
  41185. ~TableListBoxHeader()
  41186. {
  41187. }
  41188. void addMenuItems (PopupMenu& menu, const int columnIdClicked)
  41189. {
  41190. if (owner.isAutoSizeMenuOptionShown())
  41191. {
  41192. menu.addItem (0xf836743, TRANS("Auto-size this column"), columnIdClicked != 0);
  41193. menu.addItem (0xf836744, TRANS("Auto-size all columns"), owner.getHeader()->getNumColumns (true) > 0);
  41194. menu.addSeparator();
  41195. }
  41196. TableHeaderComponent::addMenuItems (menu, columnIdClicked);
  41197. }
  41198. void reactToMenuItem (const int menuReturnId, const int columnIdClicked)
  41199. {
  41200. if (menuReturnId == 0xf836743)
  41201. {
  41202. owner.autoSizeColumn (columnIdClicked);
  41203. }
  41204. else if (menuReturnId == 0xf836744)
  41205. {
  41206. owner.autoSizeAllColumns();
  41207. }
  41208. else
  41209. {
  41210. TableHeaderComponent::reactToMenuItem (menuReturnId, columnIdClicked);
  41211. }
  41212. }
  41213. juce_UseDebuggingNewOperator
  41214. private:
  41215. TableListBox& owner;
  41216. TableListBoxHeader (const TableListBoxHeader&);
  41217. TableListBoxHeader& operator= (const TableListBoxHeader&);
  41218. };
  41219. TableListBox::TableListBox (const String& name, TableListBoxModel* const model_)
  41220. : ListBox (name, 0),
  41221. model (model_),
  41222. autoSizeOptionsShown (true)
  41223. {
  41224. ListBox::model = this;
  41225. header = new TableListBoxHeader (*this);
  41226. header->setSize (100, 28);
  41227. header->addListener (this);
  41228. setHeaderComponent (header);
  41229. }
  41230. TableListBox::~TableListBox()
  41231. {
  41232. deleteAllChildren();
  41233. }
  41234. void TableListBox::setModel (TableListBoxModel* const newModel)
  41235. {
  41236. if (model != newModel)
  41237. {
  41238. model = newModel;
  41239. updateContent();
  41240. }
  41241. }
  41242. int TableListBox::getHeaderHeight() const
  41243. {
  41244. return header->getHeight();
  41245. }
  41246. void TableListBox::setHeaderHeight (const int newHeight)
  41247. {
  41248. header->setSize (header->getWidth(), newHeight);
  41249. resized();
  41250. }
  41251. void TableListBox::autoSizeColumn (const int columnId)
  41252. {
  41253. const int width = model != 0 ? model->getColumnAutoSizeWidth (columnId) : 0;
  41254. if (width > 0)
  41255. header->setColumnWidth (columnId, width);
  41256. }
  41257. void TableListBox::autoSizeAllColumns()
  41258. {
  41259. for (int i = 0; i < header->getNumColumns (true); ++i)
  41260. autoSizeColumn (header->getColumnIdOfIndex (i, true));
  41261. }
  41262. void TableListBox::setAutoSizeMenuOptionShown (const bool shouldBeShown)
  41263. {
  41264. autoSizeOptionsShown = shouldBeShown;
  41265. }
  41266. bool TableListBox::isAutoSizeMenuOptionShown() const
  41267. {
  41268. return autoSizeOptionsShown;
  41269. }
  41270. const Rectangle<int> TableListBox::getCellPosition (const int columnId,
  41271. const int rowNumber,
  41272. const bool relativeToComponentTopLeft) const
  41273. {
  41274. Rectangle<int> headerCell (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  41275. if (relativeToComponentTopLeft)
  41276. headerCell.translate (header->getX(), 0);
  41277. const Rectangle<int> row (getRowPosition (rowNumber, relativeToComponentTopLeft));
  41278. return Rectangle<int> (headerCell.getX(), row.getY(),
  41279. headerCell.getWidth(), row.getHeight());
  41280. }
  41281. void TableListBox::scrollToEnsureColumnIsOnscreen (const int columnId)
  41282. {
  41283. ScrollBar* const scrollbar = getHorizontalScrollBar();
  41284. if (scrollbar != 0)
  41285. {
  41286. const Rectangle<int> pos (header->getColumnPosition (header->getIndexOfColumnId (columnId, true)));
  41287. double x = scrollbar->getCurrentRangeStart();
  41288. const double w = scrollbar->getCurrentRangeSize();
  41289. if (pos.getX() < x)
  41290. x = pos.getX();
  41291. else if (pos.getRight() > x + w)
  41292. x += jmax (0.0, pos.getRight() - (x + w));
  41293. scrollbar->setCurrentRangeStart (x);
  41294. }
  41295. }
  41296. int TableListBox::getNumRows()
  41297. {
  41298. return model != 0 ? model->getNumRows() : 0;
  41299. }
  41300. void TableListBox::paintListBoxItem (int, Graphics&, int, int, bool)
  41301. {
  41302. }
  41303. Component* TableListBox::refreshComponentForRow (int rowNumber, bool isRowSelected_, Component* existingComponentToUpdate)
  41304. {
  41305. if (existingComponentToUpdate == 0)
  41306. existingComponentToUpdate = new TableListRowComp (*this);
  41307. ((TableListRowComp*) existingComponentToUpdate)->update (rowNumber, isRowSelected_);
  41308. return existingComponentToUpdate;
  41309. }
  41310. void TableListBox::selectedRowsChanged (int row)
  41311. {
  41312. if (model != 0)
  41313. model->selectedRowsChanged (row);
  41314. }
  41315. void TableListBox::deleteKeyPressed (int row)
  41316. {
  41317. if (model != 0)
  41318. model->deleteKeyPressed (row);
  41319. }
  41320. void TableListBox::returnKeyPressed (int row)
  41321. {
  41322. if (model != 0)
  41323. model->returnKeyPressed (row);
  41324. }
  41325. void TableListBox::backgroundClicked()
  41326. {
  41327. if (model != 0)
  41328. model->backgroundClicked();
  41329. }
  41330. void TableListBox::listWasScrolled()
  41331. {
  41332. if (model != 0)
  41333. model->listWasScrolled();
  41334. }
  41335. void TableListBox::tableColumnsChanged (TableHeaderComponent*)
  41336. {
  41337. setMinimumContentWidth (header->getTotalWidth());
  41338. repaint();
  41339. updateColumnComponents();
  41340. }
  41341. void TableListBox::tableColumnsResized (TableHeaderComponent*)
  41342. {
  41343. setMinimumContentWidth (header->getTotalWidth());
  41344. repaint();
  41345. updateColumnComponents();
  41346. }
  41347. void TableListBox::tableSortOrderChanged (TableHeaderComponent*)
  41348. {
  41349. if (model != 0)
  41350. model->sortOrderChanged (header->getSortColumnId(),
  41351. header->isSortedForwards());
  41352. }
  41353. void TableListBox::tableColumnDraggingChanged (TableHeaderComponent*, int columnIdNowBeingDragged_)
  41354. {
  41355. columnIdNowBeingDragged = columnIdNowBeingDragged_;
  41356. repaint();
  41357. }
  41358. void TableListBox::resized()
  41359. {
  41360. ListBox::resized();
  41361. header->resizeAllColumnsToFit (getVisibleContentWidth());
  41362. setMinimumContentWidth (header->getTotalWidth());
  41363. }
  41364. void TableListBox::updateColumnComponents() const
  41365. {
  41366. const int firstRow = getRowContainingPosition (0, 0);
  41367. for (int i = firstRow + getNumRowsOnScreen() + 2; --i >= firstRow;)
  41368. {
  41369. TableListRowComp* const rowComp = dynamic_cast <TableListRowComp*> (getComponentForRowNumber (i));
  41370. if (rowComp != 0)
  41371. rowComp->resized();
  41372. }
  41373. }
  41374. void TableListBoxModel::cellClicked (int, int, const MouseEvent&)
  41375. {
  41376. }
  41377. void TableListBoxModel::cellDoubleClicked (int, int, const MouseEvent&)
  41378. {
  41379. }
  41380. void TableListBoxModel::backgroundClicked()
  41381. {
  41382. }
  41383. void TableListBoxModel::sortOrderChanged (int, const bool)
  41384. {
  41385. }
  41386. int TableListBoxModel::getColumnAutoSizeWidth (int)
  41387. {
  41388. return 0;
  41389. }
  41390. void TableListBoxModel::selectedRowsChanged (int)
  41391. {
  41392. }
  41393. void TableListBoxModel::deleteKeyPressed (int)
  41394. {
  41395. }
  41396. void TableListBoxModel::returnKeyPressed (int)
  41397. {
  41398. }
  41399. void TableListBoxModel::listWasScrolled()
  41400. {
  41401. }
  41402. const String TableListBoxModel::getCellTooltip (int /*rowNumber*/, int /*columnId*/)
  41403. {
  41404. return String::empty;
  41405. }
  41406. const String TableListBoxModel::getDragSourceDescription (const SparseSet<int>&)
  41407. {
  41408. return String::empty;
  41409. }
  41410. Component* TableListBoxModel::refreshComponentForCell (int, int, bool, Component* existingComponentToUpdate)
  41411. {
  41412. (void) existingComponentToUpdate;
  41413. jassert (existingComponentToUpdate == 0); // indicates a failure in the code the recycles the components
  41414. return 0;
  41415. }
  41416. END_JUCE_NAMESPACE
  41417. /*** End of inlined file: juce_TableListBox.cpp ***/
  41418. /*** Start of inlined file: juce_TextEditor.cpp ***/
  41419. BEGIN_JUCE_NAMESPACE
  41420. // a word or space that can't be broken down any further
  41421. struct TextAtom
  41422. {
  41423. String atomText;
  41424. float width;
  41425. uint16 numChars;
  41426. bool isWhitespace() const { return CharacterFunctions::isWhitespace (atomText[0]); }
  41427. bool isNewLine() const { return atomText[0] == T('\r') || atomText[0] == T('\n'); }
  41428. const String getText (const tchar passwordCharacter) const
  41429. {
  41430. if (passwordCharacter == 0)
  41431. return atomText;
  41432. else
  41433. return String::repeatedString (String::charToString (passwordCharacter),
  41434. atomText.length());
  41435. }
  41436. const String getTrimmedText (const tchar passwordCharacter) const
  41437. {
  41438. if (passwordCharacter == 0)
  41439. return atomText.substring (0, numChars);
  41440. else if (isNewLine())
  41441. return String::empty;
  41442. else
  41443. return String::repeatedString (String::charToString (passwordCharacter), numChars);
  41444. }
  41445. };
  41446. // a run of text with a single font and colour
  41447. class UniformTextSection
  41448. {
  41449. public:
  41450. UniformTextSection (const String& text,
  41451. const Font& font_,
  41452. const Colour& colour_,
  41453. const tchar passwordCharacter)
  41454. : font (font_),
  41455. colour (colour_)
  41456. {
  41457. initialiseAtoms (text, passwordCharacter);
  41458. }
  41459. UniformTextSection (const UniformTextSection& other)
  41460. : font (other.font),
  41461. colour (other.colour)
  41462. {
  41463. atoms.ensureStorageAllocated (other.atoms.size());
  41464. for (int i = 0; i < other.atoms.size(); ++i)
  41465. atoms.add (new TextAtom (*(const TextAtom*) other.atoms.getUnchecked(i)));
  41466. }
  41467. ~UniformTextSection()
  41468. {
  41469. // (no need to delete the atoms, as they're explicitly deleted by the caller)
  41470. }
  41471. void clear()
  41472. {
  41473. for (int i = atoms.size(); --i >= 0;)
  41474. delete getAtom(i);
  41475. atoms.clear();
  41476. }
  41477. int getNumAtoms() const
  41478. {
  41479. return atoms.size();
  41480. }
  41481. TextAtom* getAtom (const int index) const
  41482. {
  41483. return (TextAtom*) atoms.getUnchecked (index);
  41484. }
  41485. void append (const UniformTextSection& other, const tchar passwordCharacter)
  41486. {
  41487. if (other.atoms.size() > 0)
  41488. {
  41489. TextAtom* const lastAtom = (TextAtom*) atoms.getLast();
  41490. int i = 0;
  41491. if (lastAtom != 0)
  41492. {
  41493. if (! CharacterFunctions::isWhitespace (lastAtom->atomText.getLastCharacter()))
  41494. {
  41495. TextAtom* const first = other.getAtom(0);
  41496. if (! CharacterFunctions::isWhitespace (first->atomText[0]))
  41497. {
  41498. lastAtom->atomText += first->atomText;
  41499. lastAtom->numChars = (uint16) (lastAtom->numChars + first->numChars);
  41500. lastAtom->width = font.getStringWidthFloat (lastAtom->getText (passwordCharacter));
  41501. delete first;
  41502. ++i;
  41503. }
  41504. }
  41505. }
  41506. atoms.ensureStorageAllocated (atoms.size() + other.atoms.size() - i);
  41507. while (i < other.atoms.size())
  41508. {
  41509. atoms.add (other.getAtom(i));
  41510. ++i;
  41511. }
  41512. }
  41513. }
  41514. UniformTextSection* split (const int indexToBreakAt,
  41515. const tchar passwordCharacter)
  41516. {
  41517. UniformTextSection* const section2 = new UniformTextSection (String::empty,
  41518. font, colour,
  41519. passwordCharacter);
  41520. int index = 0;
  41521. for (int i = 0; i < atoms.size(); ++i)
  41522. {
  41523. TextAtom* const atom = getAtom(i);
  41524. const int nextIndex = index + atom->numChars;
  41525. if (index == indexToBreakAt)
  41526. {
  41527. int j;
  41528. for (j = i; j < atoms.size(); ++j)
  41529. section2->atoms.add (getAtom (j));
  41530. for (j = atoms.size(); --j >= i;)
  41531. atoms.remove (j);
  41532. break;
  41533. }
  41534. else if (indexToBreakAt >= index && indexToBreakAt < nextIndex)
  41535. {
  41536. TextAtom* const secondAtom = new TextAtom();
  41537. secondAtom->atomText = atom->atomText.substring (indexToBreakAt - index);
  41538. secondAtom->width = font.getStringWidthFloat (secondAtom->getText (passwordCharacter));
  41539. secondAtom->numChars = (uint16) secondAtom->atomText.length();
  41540. section2->atoms.add (secondAtom);
  41541. atom->atomText = atom->atomText.substring (0, indexToBreakAt - index);
  41542. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41543. atom->numChars = (uint16) (indexToBreakAt - index);
  41544. int j;
  41545. for (j = i + 1; j < atoms.size(); ++j)
  41546. section2->atoms.add (getAtom (j));
  41547. for (j = atoms.size(); --j > i;)
  41548. atoms.remove (j);
  41549. break;
  41550. }
  41551. index = nextIndex;
  41552. }
  41553. return section2;
  41554. }
  41555. void appendAllText (String::Concatenator& concatenator) const
  41556. {
  41557. for (int i = 0; i < atoms.size(); ++i)
  41558. concatenator.append (getAtom(i)->atomText);
  41559. }
  41560. void appendSubstring (String::Concatenator& concatenator,
  41561. const Range<int>& range) const
  41562. {
  41563. int index = 0;
  41564. for (int i = 0; i < atoms.size(); ++i)
  41565. {
  41566. const TextAtom* const atom = getAtom (i);
  41567. const int nextIndex = index + atom->numChars;
  41568. if (range.getStart() < nextIndex)
  41569. {
  41570. if (range.getEnd() <= index)
  41571. break;
  41572. const Range<int> r ((range - index).getIntersectionWith (Range<int> (0, (int) atom->numChars)));
  41573. if (! r.isEmpty())
  41574. concatenator.append (atom->atomText.substring (r.getStart(), r.getEnd()));
  41575. }
  41576. index = nextIndex;
  41577. }
  41578. }
  41579. int getTotalLength() const
  41580. {
  41581. int total = 0;
  41582. for (int i = atoms.size(); --i >= 0;)
  41583. total += getAtom(i)->numChars;
  41584. return total;
  41585. }
  41586. void setFont (const Font& newFont,
  41587. const tchar passwordCharacter)
  41588. {
  41589. if (font != newFont)
  41590. {
  41591. font = newFont;
  41592. for (int i = atoms.size(); --i >= 0;)
  41593. {
  41594. TextAtom* const atom = (TextAtom*) atoms.getUnchecked(i);
  41595. atom->width = newFont.getStringWidthFloat (atom->getText (passwordCharacter));
  41596. }
  41597. }
  41598. }
  41599. juce_UseDebuggingNewOperator
  41600. Font font;
  41601. Colour colour;
  41602. private:
  41603. VoidArray atoms;
  41604. void initialiseAtoms (const String& textToParse,
  41605. const tchar passwordCharacter)
  41606. {
  41607. int i = 0;
  41608. const int len = textToParse.length();
  41609. const tchar* const text = (const tchar*) textToParse;
  41610. while (i < len)
  41611. {
  41612. int start = i;
  41613. // create a whitespace atom unless it starts with non-ws
  41614. if (CharacterFunctions::isWhitespace (text[i])
  41615. && text[i] != T('\r')
  41616. && text[i] != T('\n'))
  41617. {
  41618. while (i < len
  41619. && CharacterFunctions::isWhitespace (text[i])
  41620. && text[i] != T('\r')
  41621. && text[i] != T('\n'))
  41622. {
  41623. ++i;
  41624. }
  41625. }
  41626. else
  41627. {
  41628. if (text[i] == T('\r'))
  41629. {
  41630. ++i;
  41631. if ((i < len) && (text[i] == T('\n')))
  41632. {
  41633. ++start;
  41634. ++i;
  41635. }
  41636. }
  41637. else if (text[i] == T('\n'))
  41638. {
  41639. ++i;
  41640. }
  41641. else
  41642. {
  41643. while ((i < len) && ! CharacterFunctions::isWhitespace (text[i]))
  41644. ++i;
  41645. }
  41646. }
  41647. TextAtom* const atom = new TextAtom();
  41648. atom->atomText = String (text + start, i - start);
  41649. atom->width = font.getStringWidthFloat (atom->getText (passwordCharacter));
  41650. atom->numChars = (uint16) (i - start);
  41651. atoms.add (atom);
  41652. }
  41653. }
  41654. UniformTextSection& operator= (const UniformTextSection& other);
  41655. };
  41656. class TextEditorIterator
  41657. {
  41658. public:
  41659. TextEditorIterator (const VoidArray& sections_,
  41660. const float wordWrapWidth_,
  41661. const tchar passwordCharacter_)
  41662. : indexInText (0),
  41663. lineY (0),
  41664. lineHeight (0),
  41665. maxDescent (0),
  41666. atomX (0),
  41667. atomRight (0),
  41668. atom (0),
  41669. currentSection (0),
  41670. sections (sections_),
  41671. sectionIndex (0),
  41672. atomIndex (0),
  41673. wordWrapWidth (wordWrapWidth_),
  41674. passwordCharacter (passwordCharacter_)
  41675. {
  41676. jassert (wordWrapWidth_ > 0);
  41677. if (sections.size() > 0)
  41678. {
  41679. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41680. if (currentSection != 0)
  41681. beginNewLine();
  41682. }
  41683. }
  41684. TextEditorIterator (const TextEditorIterator& other)
  41685. : indexInText (other.indexInText),
  41686. lineY (other.lineY),
  41687. lineHeight (other.lineHeight),
  41688. maxDescent (other.maxDescent),
  41689. atomX (other.atomX),
  41690. atomRight (other.atomRight),
  41691. atom (other.atom),
  41692. currentSection (other.currentSection),
  41693. sections (other.sections),
  41694. sectionIndex (other.sectionIndex),
  41695. atomIndex (other.atomIndex),
  41696. wordWrapWidth (other.wordWrapWidth),
  41697. passwordCharacter (other.passwordCharacter),
  41698. tempAtom (other.tempAtom)
  41699. {
  41700. }
  41701. ~TextEditorIterator()
  41702. {
  41703. }
  41704. bool next()
  41705. {
  41706. if (atom == &tempAtom)
  41707. {
  41708. const int numRemaining = tempAtom.atomText.length() - tempAtom.numChars;
  41709. if (numRemaining > 0)
  41710. {
  41711. tempAtom.atomText = tempAtom.atomText.substring (tempAtom.numChars);
  41712. atomX = 0;
  41713. if (tempAtom.numChars > 0)
  41714. lineY += lineHeight;
  41715. indexInText += tempAtom.numChars;
  41716. GlyphArrangement g;
  41717. g.addLineOfText (currentSection->font, atom->getText (passwordCharacter), 0.0f, 0.0f);
  41718. int split;
  41719. for (split = 0; split < g.getNumGlyphs(); ++split)
  41720. if (shouldWrap (g.getGlyph (split).getRight()))
  41721. break;
  41722. if (split > 0 && split <= numRemaining)
  41723. {
  41724. tempAtom.numChars = (uint16) split;
  41725. tempAtom.width = g.getGlyph (split - 1).getRight();
  41726. atomRight = atomX + tempAtom.width;
  41727. return true;
  41728. }
  41729. }
  41730. }
  41731. bool forceNewLine = false;
  41732. if (sectionIndex >= sections.size())
  41733. {
  41734. moveToEndOfLastAtom();
  41735. return false;
  41736. }
  41737. else if (atomIndex >= currentSection->getNumAtoms() - 1)
  41738. {
  41739. if (atomIndex >= currentSection->getNumAtoms())
  41740. {
  41741. if (++sectionIndex >= sections.size())
  41742. {
  41743. moveToEndOfLastAtom();
  41744. return false;
  41745. }
  41746. atomIndex = 0;
  41747. currentSection = (const UniformTextSection*) sections.getUnchecked (sectionIndex);
  41748. }
  41749. else
  41750. {
  41751. const TextAtom* const lastAtom = currentSection->getAtom (atomIndex);
  41752. if (! lastAtom->isWhitespace())
  41753. {
  41754. // handle the case where the last atom in a section is actually part of the same
  41755. // word as the first atom of the next section...
  41756. float right = atomRight + lastAtom->width;
  41757. float lineHeight2 = lineHeight;
  41758. float maxDescent2 = maxDescent;
  41759. for (int section = sectionIndex + 1; section < sections.size(); ++section)
  41760. {
  41761. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked (section);
  41762. if (s->getNumAtoms() == 0)
  41763. break;
  41764. const TextAtom* const nextAtom = s->getAtom (0);
  41765. if (nextAtom->isWhitespace())
  41766. break;
  41767. right += nextAtom->width;
  41768. lineHeight2 = jmax (lineHeight2, s->font.getHeight());
  41769. maxDescent2 = jmax (maxDescent2, s->font.getDescent());
  41770. if (shouldWrap (right))
  41771. {
  41772. lineHeight = lineHeight2;
  41773. maxDescent = maxDescent2;
  41774. forceNewLine = true;
  41775. break;
  41776. }
  41777. if (s->getNumAtoms() > 1)
  41778. break;
  41779. }
  41780. }
  41781. }
  41782. }
  41783. if (atom != 0)
  41784. {
  41785. atomX = atomRight;
  41786. indexInText += atom->numChars;
  41787. if (atom->isNewLine())
  41788. beginNewLine();
  41789. }
  41790. atom = currentSection->getAtom (atomIndex);
  41791. atomRight = atomX + atom->width;
  41792. ++atomIndex;
  41793. if (shouldWrap (atomRight) || forceNewLine)
  41794. {
  41795. if (atom->isWhitespace())
  41796. {
  41797. // leave whitespace at the end of a line, but truncate it to avoid scrolling
  41798. atomRight = jmin (atomRight, wordWrapWidth);
  41799. }
  41800. else
  41801. {
  41802. atomRight = atom->width;
  41803. if (shouldWrap (atomRight)) // atom too big to fit on a line, so break it up..
  41804. {
  41805. tempAtom = *atom;
  41806. tempAtom.width = 0;
  41807. tempAtom.numChars = 0;
  41808. atom = &tempAtom;
  41809. if (atomX > 0)
  41810. beginNewLine();
  41811. return next();
  41812. }
  41813. beginNewLine();
  41814. return true;
  41815. }
  41816. }
  41817. return true;
  41818. }
  41819. void beginNewLine()
  41820. {
  41821. atomX = 0;
  41822. lineY += lineHeight;
  41823. int tempSectionIndex = sectionIndex;
  41824. int tempAtomIndex = atomIndex;
  41825. const UniformTextSection* section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41826. lineHeight = section->font.getHeight();
  41827. maxDescent = section->font.getDescent();
  41828. float x = (atom != 0) ? atom->width : 0;
  41829. while (! shouldWrap (x))
  41830. {
  41831. if (tempSectionIndex >= sections.size())
  41832. break;
  41833. bool checkSize = false;
  41834. if (tempAtomIndex >= section->getNumAtoms())
  41835. {
  41836. if (++tempSectionIndex >= sections.size())
  41837. break;
  41838. tempAtomIndex = 0;
  41839. section = (const UniformTextSection*) sections.getUnchecked (tempSectionIndex);
  41840. checkSize = true;
  41841. }
  41842. const TextAtom* const nextAtom = section->getAtom (tempAtomIndex);
  41843. if (nextAtom == 0)
  41844. break;
  41845. x += nextAtom->width;
  41846. if (shouldWrap (x) || nextAtom->isNewLine())
  41847. break;
  41848. if (checkSize)
  41849. {
  41850. lineHeight = jmax (lineHeight, section->font.getHeight());
  41851. maxDescent = jmax (maxDescent, section->font.getDescent());
  41852. }
  41853. ++tempAtomIndex;
  41854. }
  41855. }
  41856. void draw (Graphics& g, const UniformTextSection*& lastSection) const
  41857. {
  41858. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41859. {
  41860. if (lastSection != currentSection)
  41861. {
  41862. lastSection = currentSection;
  41863. g.setColour (currentSection->colour);
  41864. g.setFont (currentSection->font);
  41865. }
  41866. jassert (atom->getTrimmedText (passwordCharacter).isNotEmpty());
  41867. GlyphArrangement ga;
  41868. ga.addLineOfText (currentSection->font,
  41869. atom->getTrimmedText (passwordCharacter),
  41870. atomX,
  41871. (float) roundToInt (lineY + lineHeight - maxDescent));
  41872. ga.draw (g);
  41873. }
  41874. }
  41875. void drawSelection (Graphics& g,
  41876. const Range<int>& selection) const
  41877. {
  41878. const int startX = roundToInt (indexToX (selection.getStart()));
  41879. const int endX = roundToInt (indexToX (selection.getEnd()));
  41880. const int y = roundToInt (lineY);
  41881. const int nextY = roundToInt (lineY + lineHeight);
  41882. g.fillRect (startX, y, endX - startX, nextY - y);
  41883. }
  41884. void drawSelectedText (Graphics& g,
  41885. const Range<int>& selection,
  41886. const Colour& selectedTextColour) const
  41887. {
  41888. if (passwordCharacter != 0 || ! atom->isWhitespace())
  41889. {
  41890. GlyphArrangement ga;
  41891. ga.addLineOfText (currentSection->font,
  41892. atom->getTrimmedText (passwordCharacter),
  41893. atomX,
  41894. (float) roundToInt (lineY + lineHeight - maxDescent));
  41895. if (selection.getEnd() < indexInText + atom->numChars)
  41896. {
  41897. GlyphArrangement ga2 (ga);
  41898. ga2.removeRangeOfGlyphs (0, selection.getEnd() - indexInText);
  41899. ga.removeRangeOfGlyphs (selection.getEnd() - indexInText, -1);
  41900. g.setColour (currentSection->colour);
  41901. ga2.draw (g);
  41902. }
  41903. if (selection.getStart() > indexInText)
  41904. {
  41905. GlyphArrangement ga2 (ga);
  41906. ga2.removeRangeOfGlyphs (selection.getStart() - indexInText, -1);
  41907. ga.removeRangeOfGlyphs (0, selection.getStart() - indexInText);
  41908. g.setColour (currentSection->colour);
  41909. ga2.draw (g);
  41910. }
  41911. g.setColour (selectedTextColour);
  41912. ga.draw (g);
  41913. }
  41914. }
  41915. float indexToX (const int indexToFind) const
  41916. {
  41917. if (indexToFind <= indexInText)
  41918. return atomX;
  41919. if (indexToFind >= indexInText + atom->numChars)
  41920. return atomRight;
  41921. GlyphArrangement g;
  41922. g.addLineOfText (currentSection->font,
  41923. atom->getText (passwordCharacter),
  41924. atomX, 0.0f);
  41925. if (indexToFind - indexInText >= g.getNumGlyphs())
  41926. return atomRight;
  41927. return jmin (atomRight, g.getGlyph (indexToFind - indexInText).getLeft());
  41928. }
  41929. int xToIndex (const float xToFind) const
  41930. {
  41931. if (xToFind <= atomX || atom->isNewLine())
  41932. return indexInText;
  41933. if (xToFind >= atomRight)
  41934. return indexInText + atom->numChars;
  41935. GlyphArrangement g;
  41936. g.addLineOfText (currentSection->font,
  41937. atom->getText (passwordCharacter),
  41938. atomX, 0.0f);
  41939. int j;
  41940. for (j = 0; j < g.getNumGlyphs(); ++j)
  41941. if ((g.getGlyph(j).getLeft() + g.getGlyph(j).getRight()) / 2 > xToFind)
  41942. break;
  41943. return indexInText + j;
  41944. }
  41945. bool getCharPosition (const int index, float& cx, float& cy, float& lineHeight_)
  41946. {
  41947. while (next())
  41948. {
  41949. if (indexInText + atom->numChars > index)
  41950. {
  41951. cx = indexToX (index);
  41952. cy = lineY;
  41953. lineHeight_ = lineHeight;
  41954. return true;
  41955. }
  41956. }
  41957. cx = atomX;
  41958. cy = lineY;
  41959. lineHeight_ = lineHeight;
  41960. return false;
  41961. }
  41962. juce_UseDebuggingNewOperator
  41963. int indexInText;
  41964. float lineY, lineHeight, maxDescent;
  41965. float atomX, atomRight;
  41966. const TextAtom* atom;
  41967. const UniformTextSection* currentSection;
  41968. private:
  41969. const VoidArray& sections;
  41970. int sectionIndex, atomIndex;
  41971. const float wordWrapWidth;
  41972. const tchar passwordCharacter;
  41973. TextAtom tempAtom;
  41974. TextEditorIterator& operator= (const TextEditorIterator&);
  41975. void moveToEndOfLastAtom()
  41976. {
  41977. if (atom != 0)
  41978. {
  41979. atomX = atomRight;
  41980. if (atom->isNewLine())
  41981. {
  41982. atomX = 0.0f;
  41983. lineY += lineHeight;
  41984. }
  41985. }
  41986. }
  41987. bool shouldWrap (const float x) const
  41988. {
  41989. return (x - 0.0001f) >= wordWrapWidth;
  41990. }
  41991. };
  41992. class TextEditorInsertAction : public UndoableAction
  41993. {
  41994. TextEditor& owner;
  41995. const String text;
  41996. const int insertIndex, oldCaretPos, newCaretPos;
  41997. const Font font;
  41998. const Colour colour;
  41999. TextEditorInsertAction (const TextEditorInsertAction&);
  42000. TextEditorInsertAction& operator= (const TextEditorInsertAction&);
  42001. public:
  42002. TextEditorInsertAction (TextEditor& owner_,
  42003. const String& text_,
  42004. const int insertIndex_,
  42005. const Font& font_,
  42006. const Colour& colour_,
  42007. const int oldCaretPos_,
  42008. const int newCaretPos_)
  42009. : owner (owner_),
  42010. text (text_),
  42011. insertIndex (insertIndex_),
  42012. oldCaretPos (oldCaretPos_),
  42013. newCaretPos (newCaretPos_),
  42014. font (font_),
  42015. colour (colour_)
  42016. {
  42017. }
  42018. ~TextEditorInsertAction()
  42019. {
  42020. }
  42021. bool perform()
  42022. {
  42023. owner.insert (text, insertIndex, font, colour, 0, newCaretPos);
  42024. return true;
  42025. }
  42026. bool undo()
  42027. {
  42028. owner.remove (Range<int> (insertIndex, insertIndex + text.length()), 0, oldCaretPos);
  42029. return true;
  42030. }
  42031. int getSizeInUnits()
  42032. {
  42033. return text.length() + 16;
  42034. }
  42035. };
  42036. class TextEditorRemoveAction : public UndoableAction
  42037. {
  42038. TextEditor& owner;
  42039. const Range<int> range;
  42040. const int oldCaretPos, newCaretPos;
  42041. VoidArray removedSections;
  42042. TextEditorRemoveAction (const TextEditorRemoveAction&);
  42043. TextEditorRemoveAction& operator= (const TextEditorRemoveAction&);
  42044. public:
  42045. TextEditorRemoveAction (TextEditor& owner_,
  42046. const Range<int> range_,
  42047. const int oldCaretPos_,
  42048. const int newCaretPos_,
  42049. const VoidArray& removedSections_)
  42050. : owner (owner_),
  42051. range (range_),
  42052. oldCaretPos (oldCaretPos_),
  42053. newCaretPos (newCaretPos_),
  42054. removedSections (removedSections_)
  42055. {
  42056. }
  42057. ~TextEditorRemoveAction()
  42058. {
  42059. for (int i = removedSections.size(); --i >= 0;)
  42060. {
  42061. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  42062. section->clear();
  42063. delete section;
  42064. }
  42065. }
  42066. bool perform()
  42067. {
  42068. owner.remove (range, 0, newCaretPos);
  42069. return true;
  42070. }
  42071. bool undo()
  42072. {
  42073. owner.reinsert (range.getStart(), removedSections);
  42074. owner.moveCursorTo (oldCaretPos, false);
  42075. return true;
  42076. }
  42077. int getSizeInUnits()
  42078. {
  42079. int n = 0;
  42080. for (int i = removedSections.size(); --i >= 0;)
  42081. {
  42082. UniformTextSection* const section = (UniformTextSection*) removedSections.getUnchecked (i);
  42083. n += section->getTotalLength();
  42084. }
  42085. return n + 16;
  42086. }
  42087. };
  42088. class TextHolderComponent : public Component,
  42089. public Timer,
  42090. public Value::Listener
  42091. {
  42092. TextEditor& owner;
  42093. TextHolderComponent (const TextHolderComponent&);
  42094. TextHolderComponent& operator= (const TextHolderComponent&);
  42095. public:
  42096. TextHolderComponent (TextEditor& owner_)
  42097. : owner (owner_)
  42098. {
  42099. setWantsKeyboardFocus (false);
  42100. setInterceptsMouseClicks (false, true);
  42101. owner.getTextValue().addListener (this);
  42102. }
  42103. ~TextHolderComponent()
  42104. {
  42105. owner.getTextValue().removeListener (this);
  42106. }
  42107. void paint (Graphics& g)
  42108. {
  42109. owner.drawContent (g);
  42110. }
  42111. void timerCallback()
  42112. {
  42113. owner.timerCallbackInt();
  42114. }
  42115. const MouseCursor getMouseCursor()
  42116. {
  42117. return owner.getMouseCursor();
  42118. }
  42119. void valueChanged (Value&)
  42120. {
  42121. owner.textWasChangedByValue();
  42122. }
  42123. };
  42124. class TextEditorViewport : public Viewport
  42125. {
  42126. TextEditor* const owner;
  42127. float lastWordWrapWidth;
  42128. TextEditorViewport (const TextEditorViewport&);
  42129. TextEditorViewport& operator= (const TextEditorViewport&);
  42130. public:
  42131. TextEditorViewport (TextEditor* const owner_)
  42132. : owner (owner_),
  42133. lastWordWrapWidth (0)
  42134. {
  42135. }
  42136. ~TextEditorViewport()
  42137. {
  42138. }
  42139. void visibleAreaChanged (int, int, int, int)
  42140. {
  42141. const float wordWrapWidth = owner->getWordWrapWidth();
  42142. if (wordWrapWidth != lastWordWrapWidth)
  42143. {
  42144. lastWordWrapWidth = wordWrapWidth;
  42145. owner->updateTextHolderSize();
  42146. }
  42147. }
  42148. };
  42149. namespace TextEditorDefs
  42150. {
  42151. const int flashSpeedIntervalMs = 380;
  42152. const int textChangeMessageId = 0x10003001;
  42153. const int returnKeyMessageId = 0x10003002;
  42154. const int escapeKeyMessageId = 0x10003003;
  42155. const int focusLossMessageId = 0x10003004;
  42156. const int maxActionsPerTransaction = 100;
  42157. }
  42158. TextEditor::TextEditor (const String& name,
  42159. const tchar passwordCharacter_)
  42160. : Component (name),
  42161. borderSize (1, 1, 1, 3),
  42162. readOnly (false),
  42163. multiline (false),
  42164. wordWrap (false),
  42165. returnKeyStartsNewLine (false),
  42166. caretVisible (true),
  42167. popupMenuEnabled (true),
  42168. selectAllTextWhenFocused (false),
  42169. scrollbarVisible (true),
  42170. wasFocused (false),
  42171. caretFlashState (true),
  42172. keepCursorOnScreen (true),
  42173. tabKeyUsed (false),
  42174. menuActive (false),
  42175. valueTextNeedsUpdating (false),
  42176. cursorX (0),
  42177. cursorY (0),
  42178. cursorHeight (0),
  42179. maxTextLength (0),
  42180. leftIndent (4),
  42181. topIndent (4),
  42182. lastTransactionTime (0),
  42183. currentFont (14.0f),
  42184. totalNumChars (0),
  42185. caretPosition (0),
  42186. passwordCharacter (passwordCharacter_),
  42187. dragType (notDragging)
  42188. {
  42189. setOpaque (true);
  42190. addAndMakeVisible (viewport = new TextEditorViewport (this));
  42191. viewport->setViewedComponent (textHolder = new TextHolderComponent (*this));
  42192. viewport->setWantsKeyboardFocus (false);
  42193. viewport->setScrollBarsShown (false, false);
  42194. setMouseCursor (MouseCursor::IBeamCursor);
  42195. setWantsKeyboardFocus (true);
  42196. }
  42197. TextEditor::~TextEditor()
  42198. {
  42199. textValue.referTo (Value());
  42200. clearInternal (0);
  42201. viewport = 0;
  42202. textHolder = 0;
  42203. }
  42204. void TextEditor::newTransaction()
  42205. {
  42206. lastTransactionTime = Time::getApproximateMillisecondCounter();
  42207. undoManager.beginNewTransaction();
  42208. }
  42209. void TextEditor::doUndoRedo (const bool isRedo)
  42210. {
  42211. if (! isReadOnly())
  42212. {
  42213. if ((isRedo) ? undoManager.redo()
  42214. : undoManager.undo())
  42215. {
  42216. scrollToMakeSureCursorIsVisible();
  42217. repaint();
  42218. textChanged();
  42219. }
  42220. }
  42221. }
  42222. void TextEditor::setMultiLine (const bool shouldBeMultiLine,
  42223. const bool shouldWordWrap)
  42224. {
  42225. multiline = shouldBeMultiLine;
  42226. wordWrap = shouldWordWrap && shouldBeMultiLine;
  42227. setScrollbarsShown (scrollbarVisible);
  42228. viewport->setViewPosition (0, 0);
  42229. resized();
  42230. scrollToMakeSureCursorIsVisible();
  42231. }
  42232. bool TextEditor::isMultiLine() const
  42233. {
  42234. return multiline;
  42235. }
  42236. void TextEditor::setScrollbarsShown (bool enabled)
  42237. {
  42238. scrollbarVisible = enabled;
  42239. enabled = enabled && isMultiLine();
  42240. viewport->setScrollBarsShown (enabled, enabled);
  42241. }
  42242. void TextEditor::setReadOnly (const bool shouldBeReadOnly)
  42243. {
  42244. readOnly = shouldBeReadOnly;
  42245. enablementChanged();
  42246. }
  42247. bool TextEditor::isReadOnly() const
  42248. {
  42249. return readOnly || ! isEnabled();
  42250. }
  42251. void TextEditor::setReturnKeyStartsNewLine (const bool shouldStartNewLine)
  42252. {
  42253. returnKeyStartsNewLine = shouldStartNewLine;
  42254. }
  42255. void TextEditor::setTabKeyUsedAsCharacter (const bool shouldTabKeyBeUsed)
  42256. {
  42257. tabKeyUsed = shouldTabKeyBeUsed;
  42258. }
  42259. void TextEditor::setPopupMenuEnabled (const bool b)
  42260. {
  42261. popupMenuEnabled = b;
  42262. }
  42263. void TextEditor::setSelectAllWhenFocused (const bool b)
  42264. {
  42265. selectAllTextWhenFocused = b;
  42266. }
  42267. const Font TextEditor::getFont() const
  42268. {
  42269. return currentFont;
  42270. }
  42271. void TextEditor::setFont (const Font& newFont)
  42272. {
  42273. currentFont = newFont;
  42274. scrollToMakeSureCursorIsVisible();
  42275. }
  42276. void TextEditor::applyFontToAllText (const Font& newFont)
  42277. {
  42278. currentFont = newFont;
  42279. const Colour overallColour (findColour (textColourId));
  42280. for (int i = sections.size(); --i >= 0;)
  42281. {
  42282. UniformTextSection* const uts = (UniformTextSection*) sections.getUnchecked(i);
  42283. uts->setFont (newFont, passwordCharacter);
  42284. uts->colour = overallColour;
  42285. }
  42286. coalesceSimilarSections();
  42287. updateTextHolderSize();
  42288. scrollToMakeSureCursorIsVisible();
  42289. repaint();
  42290. }
  42291. void TextEditor::colourChanged()
  42292. {
  42293. setOpaque (findColour (backgroundColourId).isOpaque());
  42294. repaint();
  42295. }
  42296. void TextEditor::setCaretVisible (const bool shouldCaretBeVisible)
  42297. {
  42298. caretVisible = shouldCaretBeVisible;
  42299. if (shouldCaretBeVisible)
  42300. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42301. setMouseCursor (shouldCaretBeVisible ? MouseCursor::IBeamCursor
  42302. : MouseCursor::NormalCursor);
  42303. }
  42304. void TextEditor::setInputRestrictions (const int maxLen,
  42305. const String& chars)
  42306. {
  42307. maxTextLength = jmax (0, maxLen);
  42308. allowedCharacters = chars;
  42309. }
  42310. void TextEditor::setTextToShowWhenEmpty (const String& text, const Colour& colourToUse)
  42311. {
  42312. textToShowWhenEmpty = text;
  42313. colourForTextWhenEmpty = colourToUse;
  42314. }
  42315. void TextEditor::setPasswordCharacter (const tchar newPasswordCharacter)
  42316. {
  42317. if (passwordCharacter != newPasswordCharacter)
  42318. {
  42319. passwordCharacter = newPasswordCharacter;
  42320. resized();
  42321. repaint();
  42322. }
  42323. }
  42324. void TextEditor::setScrollBarThickness (const int newThicknessPixels)
  42325. {
  42326. viewport->setScrollBarThickness (newThicknessPixels);
  42327. }
  42328. void TextEditor::setScrollBarButtonVisibility (const bool buttonsVisible)
  42329. {
  42330. viewport->setScrollBarButtonVisibility (buttonsVisible);
  42331. }
  42332. void TextEditor::clear()
  42333. {
  42334. clearInternal (0);
  42335. updateTextHolderSize();
  42336. undoManager.clearUndoHistory();
  42337. }
  42338. void TextEditor::setText (const String& newText,
  42339. const bool sendTextChangeMessage)
  42340. {
  42341. const int newLength = newText.length();
  42342. if (newLength != getTotalNumChars() || getText() != newText)
  42343. {
  42344. const int oldCursorPos = caretPosition;
  42345. const bool cursorWasAtEnd = oldCursorPos >= getTotalNumChars();
  42346. clearInternal (0);
  42347. insert (newText, 0, currentFont, findColour (textColourId), 0, caretPosition);
  42348. // if you're adding text with line-feeds to a single-line text editor, it
  42349. // ain't gonna look right!
  42350. jassert (multiline || ! newText.containsAnyOf (T("\r\n")));
  42351. if (cursorWasAtEnd && ! isMultiLine())
  42352. moveCursorTo (getTotalNumChars(), false);
  42353. else
  42354. moveCursorTo (oldCursorPos, false);
  42355. if (sendTextChangeMessage)
  42356. textChanged();
  42357. repaint();
  42358. }
  42359. updateTextHolderSize();
  42360. scrollToMakeSureCursorIsVisible();
  42361. undoManager.clearUndoHistory();
  42362. }
  42363. Value& TextEditor::getTextValue()
  42364. {
  42365. if (valueTextNeedsUpdating)
  42366. {
  42367. valueTextNeedsUpdating = false;
  42368. textValue = getText();
  42369. }
  42370. return textValue;
  42371. }
  42372. void TextEditor::textWasChangedByValue()
  42373. {
  42374. if (textValue.getValueSource().getReferenceCount() > 1)
  42375. setText (textValue.getValue());
  42376. }
  42377. void TextEditor::textChanged()
  42378. {
  42379. updateTextHolderSize();
  42380. postCommandMessage (TextEditorDefs::textChangeMessageId);
  42381. if (textValue.getValueSource().getReferenceCount() > 1)
  42382. {
  42383. valueTextNeedsUpdating = false;
  42384. textValue = getText();
  42385. }
  42386. }
  42387. void TextEditor::returnPressed()
  42388. {
  42389. postCommandMessage (TextEditorDefs::returnKeyMessageId);
  42390. }
  42391. void TextEditor::escapePressed()
  42392. {
  42393. postCommandMessage (TextEditorDefs::escapeKeyMessageId);
  42394. }
  42395. void TextEditor::addListener (TextEditorListener* const newListener)
  42396. {
  42397. jassert (newListener != 0)
  42398. if (newListener != 0)
  42399. listeners.add (newListener);
  42400. }
  42401. void TextEditor::removeListener (TextEditorListener* const listenerToRemove)
  42402. {
  42403. listeners.removeValue (listenerToRemove);
  42404. }
  42405. void TextEditor::timerCallbackInt()
  42406. {
  42407. const bool newState = (! caretFlashState) && ! isCurrentlyBlockedByAnotherModalComponent();
  42408. if (caretFlashState != newState)
  42409. {
  42410. caretFlashState = newState;
  42411. if (caretFlashState)
  42412. wasFocused = true;
  42413. if (caretVisible
  42414. && hasKeyboardFocus (false)
  42415. && ! isReadOnly())
  42416. {
  42417. repaintCaret();
  42418. }
  42419. }
  42420. const unsigned int now = Time::getApproximateMillisecondCounter();
  42421. if (now > lastTransactionTime + 200)
  42422. newTransaction();
  42423. }
  42424. void TextEditor::repaintCaret()
  42425. {
  42426. if (! findColour (caretColourId).isTransparent())
  42427. repaint (borderSize.getLeft() + textHolder->getX() + leftIndent + roundToInt (cursorX) - 1,
  42428. borderSize.getTop() + textHolder->getY() + topIndent + roundToInt (cursorY) - 1,
  42429. 4,
  42430. roundToInt (cursorHeight) + 2);
  42431. }
  42432. void TextEditor::repaintText (const Range<int>& range)
  42433. {
  42434. if (! range.isEmpty())
  42435. {
  42436. float x = 0, y = 0, lh = currentFont.getHeight();
  42437. const float wordWrapWidth = getWordWrapWidth();
  42438. if (wordWrapWidth > 0)
  42439. {
  42440. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42441. i.getCharPosition (range.getStart(), x, y, lh);
  42442. const int y1 = (int) y;
  42443. int y2;
  42444. if (range.getEnd() >= getTotalNumChars())
  42445. {
  42446. y2 = getHeight();
  42447. }
  42448. else
  42449. {
  42450. i.getCharPosition (range.getEnd(), x, y, lh);
  42451. y2 = (int) (y + lh * 2.0f);
  42452. }
  42453. textHolder->repaint (0, y1, textHolder->getWidth(), y2 - y1);
  42454. }
  42455. }
  42456. }
  42457. void TextEditor::moveCaret (int newCaretPos)
  42458. {
  42459. if (newCaretPos < 0)
  42460. newCaretPos = 0;
  42461. else if (newCaretPos > getTotalNumChars())
  42462. newCaretPos = getTotalNumChars();
  42463. if (newCaretPos != getCaretPosition())
  42464. {
  42465. repaintCaret();
  42466. caretFlashState = true;
  42467. caretPosition = newCaretPos;
  42468. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42469. scrollToMakeSureCursorIsVisible();
  42470. repaintCaret();
  42471. }
  42472. }
  42473. void TextEditor::setCaretPosition (const int newIndex)
  42474. {
  42475. moveCursorTo (newIndex, false);
  42476. }
  42477. int TextEditor::getCaretPosition() const
  42478. {
  42479. return caretPosition;
  42480. }
  42481. void TextEditor::scrollEditorToPositionCaret (const int desiredCaretX,
  42482. const int desiredCaretY)
  42483. {
  42484. updateCaretPosition();
  42485. int vx = roundToInt (cursorX) - desiredCaretX;
  42486. int vy = roundToInt (cursorY) - desiredCaretY;
  42487. if (desiredCaretX < jmax (1, proportionOfWidth (0.05f)))
  42488. {
  42489. vx += desiredCaretX - proportionOfWidth (0.2f);
  42490. }
  42491. else if (desiredCaretX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42492. {
  42493. vx += desiredCaretX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42494. }
  42495. vx = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), vx);
  42496. if (! isMultiLine())
  42497. {
  42498. vy = viewport->getViewPositionY();
  42499. }
  42500. else
  42501. {
  42502. vy = jlimit (0, jmax (0, textHolder->getHeight() - viewport->getMaximumVisibleHeight()), vy);
  42503. const int curH = roundToInt (cursorHeight);
  42504. if (desiredCaretY < 0)
  42505. {
  42506. vy = jmax (0, desiredCaretY + vy);
  42507. }
  42508. else if (desiredCaretY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42509. {
  42510. vy += desiredCaretY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42511. }
  42512. }
  42513. viewport->setViewPosition (vx, vy);
  42514. }
  42515. const Rectangle<int> TextEditor::getCaretRectangle()
  42516. {
  42517. updateCaretPosition();
  42518. return Rectangle<int> (roundToInt (cursorX) - viewport->getX(),
  42519. roundToInt (cursorY) - viewport->getY(),
  42520. 1, roundToInt (cursorHeight));
  42521. }
  42522. float TextEditor::getWordWrapWidth() const
  42523. {
  42524. return (wordWrap) ? (float) (viewport->getMaximumVisibleWidth() - leftIndent - leftIndent / 2)
  42525. : 1.0e10f;
  42526. }
  42527. void TextEditor::updateTextHolderSize()
  42528. {
  42529. const float wordWrapWidth = getWordWrapWidth();
  42530. if (wordWrapWidth > 0)
  42531. {
  42532. float maxWidth = 0.0f;
  42533. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42534. while (i.next())
  42535. maxWidth = jmax (maxWidth, i.atomRight);
  42536. const int w = leftIndent + roundToInt (maxWidth);
  42537. const int h = topIndent + roundToInt (jmax (i.lineY + i.lineHeight,
  42538. currentFont.getHeight()));
  42539. textHolder->setSize (w + 1, h + 1);
  42540. }
  42541. }
  42542. int TextEditor::getTextWidth() const
  42543. {
  42544. return textHolder->getWidth();
  42545. }
  42546. int TextEditor::getTextHeight() const
  42547. {
  42548. return textHolder->getHeight();
  42549. }
  42550. void TextEditor::setIndents (const int newLeftIndent,
  42551. const int newTopIndent)
  42552. {
  42553. leftIndent = newLeftIndent;
  42554. topIndent = newTopIndent;
  42555. }
  42556. void TextEditor::setBorder (const BorderSize& border)
  42557. {
  42558. borderSize = border;
  42559. resized();
  42560. }
  42561. const BorderSize TextEditor::getBorder() const
  42562. {
  42563. return borderSize;
  42564. }
  42565. void TextEditor::setScrollToShowCursor (const bool shouldScrollToShowCursor)
  42566. {
  42567. keepCursorOnScreen = shouldScrollToShowCursor;
  42568. }
  42569. void TextEditor::updateCaretPosition()
  42570. {
  42571. cursorHeight = currentFont.getHeight(); // (in case the text is empty and the call below doesn't set this value)
  42572. getCharPosition (caretPosition, cursorX, cursorY, cursorHeight);
  42573. }
  42574. void TextEditor::scrollToMakeSureCursorIsVisible()
  42575. {
  42576. updateCaretPosition();
  42577. if (keepCursorOnScreen)
  42578. {
  42579. int x = viewport->getViewPositionX();
  42580. int y = viewport->getViewPositionY();
  42581. const int relativeCursorX = roundToInt (cursorX) - x;
  42582. const int relativeCursorY = roundToInt (cursorY) - y;
  42583. if (relativeCursorX < jmax (1, proportionOfWidth (0.05f)))
  42584. {
  42585. x += relativeCursorX - proportionOfWidth (0.2f);
  42586. }
  42587. else if (relativeCursorX > jmax (0, viewport->getMaximumVisibleWidth() - (wordWrap ? 2 : 10)))
  42588. {
  42589. x += relativeCursorX + (isMultiLine() ? proportionOfWidth (0.2f) : 10) - viewport->getMaximumVisibleWidth();
  42590. }
  42591. x = jlimit (0, jmax (0, textHolder->getWidth() + 8 - viewport->getMaximumVisibleWidth()), x);
  42592. if (! isMultiLine())
  42593. {
  42594. y = (getHeight() - textHolder->getHeight() - topIndent) / -2;
  42595. }
  42596. else
  42597. {
  42598. const int curH = roundToInt (cursorHeight);
  42599. if (relativeCursorY < 0)
  42600. {
  42601. y = jmax (0, relativeCursorY + y);
  42602. }
  42603. else if (relativeCursorY > jmax (0, viewport->getMaximumVisibleHeight() - topIndent - curH))
  42604. {
  42605. y += relativeCursorY + 2 + curH + topIndent - viewport->getMaximumVisibleHeight();
  42606. }
  42607. }
  42608. viewport->setViewPosition (x, y);
  42609. }
  42610. }
  42611. void TextEditor::moveCursorTo (const int newPosition,
  42612. const bool isSelecting)
  42613. {
  42614. if (isSelecting)
  42615. {
  42616. moveCaret (newPosition);
  42617. const Range<int> oldSelection (selection);
  42618. if (dragType == notDragging)
  42619. {
  42620. if (abs (getCaretPosition() - selection.getStart()) < abs (getCaretPosition() - selection.getEnd()))
  42621. dragType = draggingSelectionStart;
  42622. else
  42623. dragType = draggingSelectionEnd;
  42624. }
  42625. if (dragType == draggingSelectionStart)
  42626. {
  42627. if (getCaretPosition() >= selection.getEnd())
  42628. dragType = draggingSelectionEnd;
  42629. selection = Range<int>::between (getCaretPosition(), selection.getEnd());
  42630. }
  42631. else
  42632. {
  42633. if (getCaretPosition() < selection.getStart())
  42634. dragType = draggingSelectionStart;
  42635. selection = Range<int>::between (getCaretPosition(), selection.getStart());
  42636. }
  42637. repaintText (selection.getUnionWith (oldSelection));
  42638. }
  42639. else
  42640. {
  42641. dragType = notDragging;
  42642. repaintText (selection);
  42643. moveCaret (newPosition);
  42644. selection = Range<int>::emptyRange (getCaretPosition());
  42645. }
  42646. }
  42647. int TextEditor::getTextIndexAt (const int x,
  42648. const int y)
  42649. {
  42650. return indexAtPosition ((float) (x + viewport->getViewPositionX() - leftIndent),
  42651. (float) (y + viewport->getViewPositionY() - topIndent));
  42652. }
  42653. void TextEditor::insertTextAtCaret (const String& newText_)
  42654. {
  42655. String newText (newText_);
  42656. if (allowedCharacters.isNotEmpty())
  42657. newText = newText.retainCharacters (allowedCharacters);
  42658. if (! isMultiLine())
  42659. newText = newText.replaceCharacters (T("\r\n"), T(" "));
  42660. else
  42661. newText = newText.replace (T("\r\n"), T("\n"));
  42662. const int newCaretPos = selection.getStart() + newText.length();
  42663. const int insertIndex = selection.getStart();
  42664. remove (selection, &undoManager,
  42665. newText.isNotEmpty() ? newCaretPos - 1 : newCaretPos);
  42666. if (maxTextLength > 0)
  42667. newText = newText.substring (0, maxTextLength - getTotalNumChars());
  42668. if (newText.isNotEmpty())
  42669. insert (newText,
  42670. insertIndex,
  42671. currentFont,
  42672. findColour (textColourId),
  42673. &undoManager,
  42674. newCaretPos);
  42675. textChanged();
  42676. }
  42677. void TextEditor::setHighlightedRegion (const Range<int>& newSelection)
  42678. {
  42679. moveCursorTo (newSelection.getStart(), false);
  42680. moveCursorTo (newSelection.getEnd(), true);
  42681. }
  42682. void TextEditor::copy()
  42683. {
  42684. if (passwordCharacter == 0)
  42685. {
  42686. const String selection (getHighlightedText());
  42687. if (selection.isNotEmpty())
  42688. SystemClipboard::copyTextToClipboard (selection);
  42689. }
  42690. }
  42691. void TextEditor::paste()
  42692. {
  42693. if (! isReadOnly())
  42694. {
  42695. const String clip (SystemClipboard::getTextFromClipboard());
  42696. if (clip.isNotEmpty())
  42697. insertTextAtCaret (clip);
  42698. }
  42699. }
  42700. void TextEditor::cut()
  42701. {
  42702. if (! isReadOnly())
  42703. {
  42704. moveCaret (selection.getEnd());
  42705. insertTextAtCaret (String::empty);
  42706. }
  42707. }
  42708. void TextEditor::drawContent (Graphics& g)
  42709. {
  42710. const float wordWrapWidth = getWordWrapWidth();
  42711. if (wordWrapWidth > 0)
  42712. {
  42713. g.setOrigin (leftIndent, topIndent);
  42714. const Rectangle<int> clip (g.getClipBounds());
  42715. Colour selectedTextColour;
  42716. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  42717. while (i.lineY + 200.0 < clip.getY() && i.next())
  42718. {}
  42719. if (! selection.isEmpty())
  42720. {
  42721. g.setColour (findColour (highlightColourId)
  42722. .withMultipliedAlpha (hasKeyboardFocus (true) ? 1.0f : 0.5f));
  42723. selectedTextColour = findColour (highlightedTextColourId);
  42724. TextEditorIterator i2 (i);
  42725. while (i2.next() && i2.lineY < clip.getBottom())
  42726. {
  42727. if (i2.lineY + i2.lineHeight >= clip.getY()
  42728. && selection.intersects (Range<int> (i2.indexInText, i2.indexInText + i2.atom->numChars)))
  42729. {
  42730. i2.drawSelection (g, selection);
  42731. }
  42732. }
  42733. }
  42734. const UniformTextSection* lastSection = 0;
  42735. while (i.next() && i.lineY < clip.getBottom())
  42736. {
  42737. if (i.lineY + i.lineHeight >= clip.getY())
  42738. {
  42739. if (selection.intersects (Range<int> (i.indexInText, i.indexInText + i.atom->numChars)))
  42740. {
  42741. i.drawSelectedText (g, selection, selectedTextColour);
  42742. lastSection = 0;
  42743. }
  42744. else
  42745. {
  42746. i.draw (g, lastSection);
  42747. }
  42748. }
  42749. }
  42750. }
  42751. }
  42752. void TextEditor::paint (Graphics& g)
  42753. {
  42754. getLookAndFeel().fillTextEditorBackground (g, getWidth(), getHeight(), *this);
  42755. }
  42756. void TextEditor::paintOverChildren (Graphics& g)
  42757. {
  42758. if (caretFlashState
  42759. && hasKeyboardFocus (false)
  42760. && caretVisible
  42761. && ! isReadOnly())
  42762. {
  42763. g.setColour (findColour (caretColourId));
  42764. g.fillRect (borderSize.getLeft() + textHolder->getX() + leftIndent + cursorX,
  42765. borderSize.getTop() + textHolder->getY() + topIndent + cursorY,
  42766. 2.0f, cursorHeight);
  42767. }
  42768. if (textToShowWhenEmpty.isNotEmpty()
  42769. && (! hasKeyboardFocus (false))
  42770. && getTotalNumChars() == 0)
  42771. {
  42772. g.setColour (colourForTextWhenEmpty);
  42773. g.setFont (getFont());
  42774. if (isMultiLine())
  42775. {
  42776. g.drawText (textToShowWhenEmpty,
  42777. 0, 0, getWidth(), getHeight(),
  42778. Justification::centred, true);
  42779. }
  42780. else
  42781. {
  42782. g.drawText (textToShowWhenEmpty,
  42783. leftIndent, topIndent,
  42784. viewport->getWidth() - leftIndent,
  42785. viewport->getHeight() - topIndent,
  42786. Justification::centredLeft, true);
  42787. }
  42788. }
  42789. getLookAndFeel().drawTextEditorOutline (g, getWidth(), getHeight(), *this);
  42790. }
  42791. void TextEditor::mouseDown (const MouseEvent& e)
  42792. {
  42793. beginDragAutoRepeat (100);
  42794. newTransaction();
  42795. if (wasFocused || ! selectAllTextWhenFocused)
  42796. {
  42797. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42798. {
  42799. moveCursorTo (getTextIndexAt (e.x, e.y),
  42800. e.mods.isShiftDown());
  42801. }
  42802. else
  42803. {
  42804. PopupMenu m;
  42805. m.setLookAndFeel (&getLookAndFeel());
  42806. addPopupMenuItems (m, &e);
  42807. menuActive = true;
  42808. const int result = m.show();
  42809. menuActive = false;
  42810. if (result != 0)
  42811. performPopupMenuAction (result);
  42812. }
  42813. }
  42814. }
  42815. void TextEditor::mouseDrag (const MouseEvent& e)
  42816. {
  42817. if (wasFocused || ! selectAllTextWhenFocused)
  42818. {
  42819. if (! (popupMenuEnabled && e.mods.isPopupMenu()))
  42820. {
  42821. moveCursorTo (getTextIndexAt (e.x, e.y), true);
  42822. }
  42823. }
  42824. }
  42825. void TextEditor::mouseUp (const MouseEvent& e)
  42826. {
  42827. newTransaction();
  42828. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  42829. if (wasFocused || ! selectAllTextWhenFocused)
  42830. {
  42831. if (e.mouseWasClicked() && ! (popupMenuEnabled && e.mods.isPopupMenu()))
  42832. {
  42833. moveCaret (getTextIndexAt (e.x, e.y));
  42834. }
  42835. }
  42836. wasFocused = true;
  42837. }
  42838. void TextEditor::mouseDoubleClick (const MouseEvent& e)
  42839. {
  42840. int tokenEnd = getTextIndexAt (e.x, e.y);
  42841. int tokenStart = tokenEnd;
  42842. if (e.getNumberOfClicks() > 3)
  42843. {
  42844. tokenStart = 0;
  42845. tokenEnd = getTotalNumChars();
  42846. }
  42847. else
  42848. {
  42849. const String t (getText());
  42850. const int totalLength = getTotalNumChars();
  42851. while (tokenEnd < totalLength)
  42852. {
  42853. if (CharacterFunctions::isLetterOrDigit (t [tokenEnd]))
  42854. ++tokenEnd;
  42855. else
  42856. break;
  42857. }
  42858. tokenStart = tokenEnd;
  42859. while (tokenStart > 0)
  42860. {
  42861. if (CharacterFunctions::isLetterOrDigit (t [tokenStart - 1]))
  42862. --tokenStart;
  42863. else
  42864. break;
  42865. }
  42866. if (e.getNumberOfClicks() > 2)
  42867. {
  42868. while (tokenEnd < totalLength)
  42869. {
  42870. if (t [tokenEnd] != T('\r') && t [tokenEnd] != T('\n'))
  42871. ++tokenEnd;
  42872. else
  42873. break;
  42874. }
  42875. while (tokenStart > 0)
  42876. {
  42877. if (t [tokenStart - 1] != T('\r') && t [tokenStart - 1] != T('\n'))
  42878. --tokenStart;
  42879. else
  42880. break;
  42881. }
  42882. }
  42883. }
  42884. moveCursorTo (tokenEnd, false);
  42885. moveCursorTo (tokenStart, true);
  42886. }
  42887. void TextEditor::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  42888. {
  42889. if (! viewport->useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  42890. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  42891. }
  42892. bool TextEditor::keyPressed (const KeyPress& key)
  42893. {
  42894. if (isReadOnly() && key != KeyPress (T('c'), ModifierKeys::commandModifier, 0))
  42895. return false;
  42896. const bool moveInWholeWordSteps = key.getModifiers().isCtrlDown() || key.getModifiers().isAltDown();
  42897. if (key.isKeyCode (KeyPress::leftKey)
  42898. || key.isKeyCode (KeyPress::upKey))
  42899. {
  42900. newTransaction();
  42901. int newPos;
  42902. if (isMultiLine() && key.isKeyCode (KeyPress::upKey))
  42903. newPos = indexAtPosition (cursorX, cursorY - 1);
  42904. else if (moveInWholeWordSteps)
  42905. newPos = findWordBreakBefore (getCaretPosition());
  42906. else
  42907. newPos = getCaretPosition() - 1;
  42908. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42909. }
  42910. else if (key.isKeyCode (KeyPress::rightKey)
  42911. || key.isKeyCode (KeyPress::downKey))
  42912. {
  42913. newTransaction();
  42914. int newPos;
  42915. if (isMultiLine() && key.isKeyCode (KeyPress::downKey))
  42916. newPos = indexAtPosition (cursorX, cursorY + cursorHeight + 1);
  42917. else if (moveInWholeWordSteps)
  42918. newPos = findWordBreakAfter (getCaretPosition());
  42919. else
  42920. newPos = getCaretPosition() + 1;
  42921. moveCursorTo (newPos, key.getModifiers().isShiftDown());
  42922. }
  42923. else if (key.isKeyCode (KeyPress::pageDownKey) && isMultiLine())
  42924. {
  42925. newTransaction();
  42926. moveCursorTo (indexAtPosition (cursorX, cursorY + cursorHeight + viewport->getViewHeight()),
  42927. key.getModifiers().isShiftDown());
  42928. }
  42929. else if (key.isKeyCode (KeyPress::pageUpKey) && isMultiLine())
  42930. {
  42931. newTransaction();
  42932. moveCursorTo (indexAtPosition (cursorX, cursorY - viewport->getViewHeight()),
  42933. key.getModifiers().isShiftDown());
  42934. }
  42935. else if (key.isKeyCode (KeyPress::homeKey))
  42936. {
  42937. newTransaction();
  42938. if (isMultiLine() && ! moveInWholeWordSteps)
  42939. moveCursorTo (indexAtPosition (0.0f, cursorY),
  42940. key.getModifiers().isShiftDown());
  42941. else
  42942. moveCursorTo (0, key.getModifiers().isShiftDown());
  42943. }
  42944. else if (key.isKeyCode (KeyPress::endKey))
  42945. {
  42946. newTransaction();
  42947. if (isMultiLine() && ! moveInWholeWordSteps)
  42948. moveCursorTo (indexAtPosition ((float) textHolder->getWidth(), cursorY),
  42949. key.getModifiers().isShiftDown());
  42950. else
  42951. moveCursorTo (getTotalNumChars(), key.getModifiers().isShiftDown());
  42952. }
  42953. else if (key.isKeyCode (KeyPress::backspaceKey))
  42954. {
  42955. if (moveInWholeWordSteps)
  42956. {
  42957. moveCursorTo (findWordBreakBefore (getCaretPosition()), true);
  42958. }
  42959. else
  42960. {
  42961. if (selection.isEmpty() && selection.getStart() > 0)
  42962. selection.setStart (selection.getEnd() - 1);
  42963. }
  42964. cut();
  42965. }
  42966. else if (key.isKeyCode (KeyPress::deleteKey))
  42967. {
  42968. if (key.getModifiers().isShiftDown())
  42969. copy();
  42970. if (selection.isEmpty() && selection.getStart() < getTotalNumChars())
  42971. selection.setEnd (selection.getStart() + 1);
  42972. cut();
  42973. }
  42974. else if (key == KeyPress (T('c'), ModifierKeys::commandModifier, 0)
  42975. || key == KeyPress (KeyPress::insertKey, ModifierKeys::ctrlModifier, 0))
  42976. {
  42977. newTransaction();
  42978. copy();
  42979. }
  42980. else if (key == KeyPress (T('x'), ModifierKeys::commandModifier, 0))
  42981. {
  42982. newTransaction();
  42983. copy();
  42984. cut();
  42985. }
  42986. else if (key == KeyPress (T('v'), ModifierKeys::commandModifier, 0)
  42987. || key == KeyPress (KeyPress::insertKey, ModifierKeys::shiftModifier, 0))
  42988. {
  42989. newTransaction();
  42990. paste();
  42991. }
  42992. else if (key == KeyPress (T('z'), ModifierKeys::commandModifier, 0))
  42993. {
  42994. newTransaction();
  42995. doUndoRedo (false);
  42996. }
  42997. else if (key == KeyPress (T('y'), ModifierKeys::commandModifier, 0))
  42998. {
  42999. newTransaction();
  43000. doUndoRedo (true);
  43001. }
  43002. else if (key == KeyPress (T('a'), ModifierKeys::commandModifier, 0))
  43003. {
  43004. newTransaction();
  43005. moveCursorTo (getTotalNumChars(), false);
  43006. moveCursorTo (0, true);
  43007. }
  43008. else if (key == KeyPress::returnKey)
  43009. {
  43010. newTransaction();
  43011. if (returnKeyStartsNewLine)
  43012. insertTextAtCaret (T("\n"));
  43013. else
  43014. returnPressed();
  43015. }
  43016. else if (key.isKeyCode (KeyPress::escapeKey))
  43017. {
  43018. newTransaction();
  43019. moveCursorTo (getCaretPosition(), false);
  43020. escapePressed();
  43021. }
  43022. else if (key.getTextCharacter() >= ' '
  43023. || (tabKeyUsed && (key.getTextCharacter() == '\t')))
  43024. {
  43025. insertTextAtCaret (String::charToString (key.getTextCharacter()));
  43026. lastTransactionTime = Time::getApproximateMillisecondCounter();
  43027. }
  43028. else
  43029. {
  43030. return false;
  43031. }
  43032. return true;
  43033. }
  43034. bool TextEditor::keyStateChanged (const bool isKeyDown)
  43035. {
  43036. if (! isKeyDown)
  43037. return false;
  43038. #if JUCE_WIN32
  43039. if (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0).isCurrentlyDown())
  43040. return false; // We need to explicitly allow alt-F4 to pass through on Windows
  43041. #endif
  43042. // (overridden to avoid forwarding key events to the parent)
  43043. return ! ModifierKeys::getCurrentModifiers().isCommandDown();
  43044. }
  43045. const int baseMenuItemID = 0x7fff0000;
  43046. void TextEditor::addPopupMenuItems (PopupMenu& m, const MouseEvent*)
  43047. {
  43048. const bool writable = ! isReadOnly();
  43049. if (passwordCharacter == 0)
  43050. {
  43051. m.addItem (baseMenuItemID + 1, TRANS("cut"), writable);
  43052. m.addItem (baseMenuItemID + 2, TRANS("copy"), ! selection.isEmpty());
  43053. m.addItem (baseMenuItemID + 3, TRANS("paste"), writable);
  43054. }
  43055. m.addItem (baseMenuItemID + 4, TRANS("delete"), writable);
  43056. m.addSeparator();
  43057. m.addItem (baseMenuItemID + 5, TRANS("select all"));
  43058. m.addSeparator();
  43059. m.addItem (baseMenuItemID + 6, TRANS("undo"), undoManager.canUndo());
  43060. m.addItem (baseMenuItemID + 7, TRANS("redo"), undoManager.canRedo());
  43061. }
  43062. void TextEditor::performPopupMenuAction (const int menuItemID)
  43063. {
  43064. switch (menuItemID)
  43065. {
  43066. case baseMenuItemID + 1:
  43067. copy();
  43068. cut();
  43069. break;
  43070. case baseMenuItemID + 2:
  43071. copy();
  43072. break;
  43073. case baseMenuItemID + 3:
  43074. paste();
  43075. break;
  43076. case baseMenuItemID + 4:
  43077. cut();
  43078. break;
  43079. case baseMenuItemID + 5:
  43080. moveCursorTo (getTotalNumChars(), false);
  43081. moveCursorTo (0, true);
  43082. break;
  43083. case baseMenuItemID + 6:
  43084. doUndoRedo (false);
  43085. break;
  43086. case baseMenuItemID + 7:
  43087. doUndoRedo (true);
  43088. break;
  43089. default:
  43090. break;
  43091. }
  43092. }
  43093. void TextEditor::focusGained (FocusChangeType)
  43094. {
  43095. newTransaction();
  43096. caretFlashState = true;
  43097. if (selectAllTextWhenFocused)
  43098. {
  43099. moveCursorTo (0, false);
  43100. moveCursorTo (getTotalNumChars(), true);
  43101. }
  43102. repaint();
  43103. if (caretVisible)
  43104. textHolder->startTimer (TextEditorDefs::flashSpeedIntervalMs);
  43105. ComponentPeer* const peer = getPeer();
  43106. if (peer != 0 && ! isReadOnly())
  43107. peer->textInputRequired (getScreenPosition() - peer->getScreenPosition());
  43108. }
  43109. void TextEditor::focusLost (FocusChangeType)
  43110. {
  43111. newTransaction();
  43112. wasFocused = false;
  43113. textHolder->stopTimer();
  43114. caretFlashState = false;
  43115. postCommandMessage (TextEditorDefs::focusLossMessageId);
  43116. repaint();
  43117. }
  43118. void TextEditor::resized()
  43119. {
  43120. viewport->setBoundsInset (borderSize);
  43121. viewport->setSingleStepSizes (16, roundToInt (currentFont.getHeight()));
  43122. updateTextHolderSize();
  43123. if (! isMultiLine())
  43124. {
  43125. scrollToMakeSureCursorIsVisible();
  43126. }
  43127. else
  43128. {
  43129. updateCaretPosition();
  43130. }
  43131. }
  43132. void TextEditor::handleCommandMessage (const int commandId)
  43133. {
  43134. const ComponentDeletionWatcher deletionChecker (this);
  43135. for (int i = listeners.size(); --i >= 0;)
  43136. {
  43137. TextEditorListener* const tl = (TextEditorListener*) listeners [i];
  43138. if (tl != 0)
  43139. {
  43140. switch (commandId)
  43141. {
  43142. case TextEditorDefs::textChangeMessageId:
  43143. tl->textEditorTextChanged (*this);
  43144. break;
  43145. case TextEditorDefs::returnKeyMessageId:
  43146. tl->textEditorReturnKeyPressed (*this);
  43147. break;
  43148. case TextEditorDefs::escapeKeyMessageId:
  43149. tl->textEditorEscapeKeyPressed (*this);
  43150. break;
  43151. case TextEditorDefs::focusLossMessageId:
  43152. tl->textEditorFocusLost (*this);
  43153. break;
  43154. default:
  43155. jassertfalse
  43156. break;
  43157. }
  43158. if (i > 0 && deletionChecker.hasBeenDeleted())
  43159. return;
  43160. }
  43161. }
  43162. }
  43163. void TextEditor::enablementChanged()
  43164. {
  43165. setMouseCursor (MouseCursor (isReadOnly() ? MouseCursor::NormalCursor
  43166. : MouseCursor::IBeamCursor));
  43167. repaint();
  43168. }
  43169. void TextEditor::clearInternal (UndoManager* const um)
  43170. {
  43171. remove (Range<int> (0, getTotalNumChars()), um, caretPosition);
  43172. }
  43173. void TextEditor::insert (const String& text,
  43174. const int insertIndex,
  43175. const Font& font,
  43176. const Colour& colour,
  43177. UndoManager* const um,
  43178. const int caretPositionToMoveTo)
  43179. {
  43180. if (text.isNotEmpty())
  43181. {
  43182. if (um != 0)
  43183. {
  43184. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  43185. newTransaction();
  43186. um->perform (new TextEditorInsertAction (*this,
  43187. text,
  43188. insertIndex,
  43189. font,
  43190. colour,
  43191. caretPosition,
  43192. caretPositionToMoveTo));
  43193. }
  43194. else
  43195. {
  43196. repaintText (Range<int> (insertIndex, getTotalNumChars())); // must do this before and after changing the data, in case
  43197. // a line gets moved due to word wrap
  43198. int index = 0;
  43199. int nextIndex = 0;
  43200. for (int i = 0; i < sections.size(); ++i)
  43201. {
  43202. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43203. if (insertIndex == index)
  43204. {
  43205. sections.insert (i, new UniformTextSection (text,
  43206. font, colour,
  43207. passwordCharacter));
  43208. break;
  43209. }
  43210. else if (insertIndex > index && insertIndex < nextIndex)
  43211. {
  43212. splitSection (i, insertIndex - index);
  43213. sections.insert (i + 1, new UniformTextSection (text,
  43214. font, colour,
  43215. passwordCharacter));
  43216. break;
  43217. }
  43218. index = nextIndex;
  43219. }
  43220. if (nextIndex == insertIndex)
  43221. sections.add (new UniformTextSection (text,
  43222. font, colour,
  43223. passwordCharacter));
  43224. coalesceSimilarSections();
  43225. totalNumChars = -1;
  43226. valueTextNeedsUpdating = true;
  43227. moveCursorTo (caretPositionToMoveTo, false);
  43228. repaintText (Range<int> (insertIndex, getTotalNumChars()));
  43229. }
  43230. }
  43231. }
  43232. void TextEditor::reinsert (const int insertIndex,
  43233. const VoidArray& sectionsToInsert)
  43234. {
  43235. int index = 0;
  43236. int nextIndex = 0;
  43237. for (int i = 0; i < sections.size(); ++i)
  43238. {
  43239. nextIndex = index + ((UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43240. if (insertIndex == index)
  43241. {
  43242. for (int j = sectionsToInsert.size(); --j >= 0;)
  43243. sections.insert (i, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43244. break;
  43245. }
  43246. else if (insertIndex > index && insertIndex < nextIndex)
  43247. {
  43248. splitSection (i, insertIndex - index);
  43249. for (int j = sectionsToInsert.size(); --j >= 0;)
  43250. sections.insert (i + 1, new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43251. break;
  43252. }
  43253. index = nextIndex;
  43254. }
  43255. if (nextIndex == insertIndex)
  43256. {
  43257. for (int j = 0; j < sectionsToInsert.size(); ++j)
  43258. sections.add (new UniformTextSection (*(UniformTextSection*) sectionsToInsert.getUnchecked(j)));
  43259. }
  43260. coalesceSimilarSections();
  43261. totalNumChars = -1;
  43262. valueTextNeedsUpdating = true;
  43263. }
  43264. void TextEditor::remove (const Range<int>& range,
  43265. UndoManager* const um,
  43266. const int caretPositionToMoveTo)
  43267. {
  43268. if (! range.isEmpty())
  43269. {
  43270. int index = 0;
  43271. for (int i = 0; i < sections.size(); ++i)
  43272. {
  43273. const int nextIndex = index + ((UniformTextSection*) sections[i])->getTotalLength();
  43274. if (range.getStart() > index && range.getStart() < nextIndex)
  43275. {
  43276. splitSection (i, range.getStart() - index);
  43277. --i;
  43278. }
  43279. else if (range.getEnd() > index && range.getEnd() < nextIndex)
  43280. {
  43281. splitSection (i, range.getEnd() - index);
  43282. --i;
  43283. }
  43284. else
  43285. {
  43286. index = nextIndex;
  43287. if (index > range.getEnd())
  43288. break;
  43289. }
  43290. }
  43291. index = 0;
  43292. if (um != 0)
  43293. {
  43294. VoidArray removedSections;
  43295. for (int i = 0; i < sections.size(); ++i)
  43296. {
  43297. if (range.getEnd() <= range.getStart())
  43298. break;
  43299. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  43300. const int nextIndex = index + section->getTotalLength();
  43301. if (range.getStart() <= index && range.getEnd() >= nextIndex)
  43302. removedSections.add (new UniformTextSection (*section));
  43303. index = nextIndex;
  43304. }
  43305. if (um->getNumActionsInCurrentTransaction() > TextEditorDefs::maxActionsPerTransaction)
  43306. newTransaction();
  43307. um->perform (new TextEditorRemoveAction (*this,
  43308. range,
  43309. caretPosition,
  43310. caretPositionToMoveTo,
  43311. removedSections));
  43312. }
  43313. else
  43314. {
  43315. Range<int> remainingRange (range);
  43316. for (int i = 0; i < sections.size(); ++i)
  43317. {
  43318. UniformTextSection* const section = (UniformTextSection*) sections.getUnchecked (i);
  43319. const int nextIndex = index + section->getTotalLength();
  43320. if (remainingRange.getStart() <= index && remainingRange.getEnd() >= nextIndex)
  43321. {
  43322. sections.remove(i);
  43323. section->clear();
  43324. delete section;
  43325. remainingRange.setEnd (remainingRange.getEnd() - (nextIndex - index));
  43326. if (remainingRange.isEmpty())
  43327. break;
  43328. --i;
  43329. }
  43330. else
  43331. {
  43332. index = nextIndex;
  43333. }
  43334. }
  43335. coalesceSimilarSections();
  43336. totalNumChars = -1;
  43337. valueTextNeedsUpdating = true;
  43338. moveCursorTo (caretPositionToMoveTo, false);
  43339. repaintText (Range<int> (range.getStart(), getTotalNumChars()));
  43340. }
  43341. }
  43342. }
  43343. const String TextEditor::getText() const
  43344. {
  43345. String t;
  43346. t.preallocateStorage (getTotalNumChars());
  43347. String::Concatenator concatenator (t);
  43348. for (int i = 0; i < sections.size(); ++i)
  43349. ((const UniformTextSection*) sections.getUnchecked(i))->appendAllText (concatenator);
  43350. return t;
  43351. }
  43352. const String TextEditor::getTextInRange (const Range<int>& range) const
  43353. {
  43354. String t;
  43355. if (! range.isEmpty())
  43356. {
  43357. t.preallocateStorage (jmin (getTotalNumChars(), range.getLength()));
  43358. String::Concatenator concatenator (t);
  43359. int index = 0;
  43360. for (int i = 0; i < sections.size(); ++i)
  43361. {
  43362. const UniformTextSection* const s = (const UniformTextSection*) sections.getUnchecked(i);
  43363. const int nextIndex = index + s->getTotalLength();
  43364. if (range.getStart() < nextIndex)
  43365. {
  43366. if (range.getEnd() <= index)
  43367. break;
  43368. s->appendSubstring (concatenator, range - index);
  43369. }
  43370. index = nextIndex;
  43371. }
  43372. }
  43373. return t;
  43374. }
  43375. const String TextEditor::getHighlightedText() const
  43376. {
  43377. return getTextInRange (selection);
  43378. }
  43379. int TextEditor::getTotalNumChars() const
  43380. {
  43381. if (totalNumChars < 0)
  43382. {
  43383. totalNumChars = 0;
  43384. for (int i = sections.size(); --i >= 0;)
  43385. totalNumChars += ((const UniformTextSection*) sections.getUnchecked(i))->getTotalLength();
  43386. }
  43387. return totalNumChars;
  43388. }
  43389. bool TextEditor::isEmpty() const
  43390. {
  43391. return getTotalNumChars() == 0;
  43392. }
  43393. void TextEditor::getCharPosition (const int index, float& cx, float& cy, float& lineHeight) const
  43394. {
  43395. const float wordWrapWidth = getWordWrapWidth();
  43396. if (wordWrapWidth > 0 && sections.size() > 0)
  43397. {
  43398. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43399. i.getCharPosition (index, cx, cy, lineHeight);
  43400. }
  43401. else
  43402. {
  43403. cx = cy = 0;
  43404. lineHeight = currentFont.getHeight();
  43405. }
  43406. }
  43407. int TextEditor::indexAtPosition (const float x, const float y)
  43408. {
  43409. const float wordWrapWidth = getWordWrapWidth();
  43410. if (wordWrapWidth > 0)
  43411. {
  43412. TextEditorIterator i (sections, wordWrapWidth, passwordCharacter);
  43413. while (i.next())
  43414. {
  43415. if (i.lineY + i.lineHeight > y)
  43416. {
  43417. if (i.lineY > y)
  43418. return jmax (0, i.indexInText - 1);
  43419. if (i.atomX >= x)
  43420. return i.indexInText;
  43421. if (x < i.atomRight)
  43422. return i.xToIndex (x);
  43423. }
  43424. }
  43425. }
  43426. return getTotalNumChars();
  43427. }
  43428. static int getCharacterCategory (const tchar character)
  43429. {
  43430. return CharacterFunctions::isLetterOrDigit (character)
  43431. ? 2 : (CharacterFunctions::isWhitespace (character) ? 0 : 1);
  43432. }
  43433. int TextEditor::findWordBreakAfter (const int position) const
  43434. {
  43435. const String t (getTextInRange (Range<int> (position, position + 512)));
  43436. const int totalLength = t.length();
  43437. int i = 0;
  43438. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43439. ++i;
  43440. const int type = getCharacterCategory (t[i]);
  43441. while (i < totalLength && type == getCharacterCategory (t[i]))
  43442. ++i;
  43443. while (i < totalLength && CharacterFunctions::isWhitespace (t[i]))
  43444. ++i;
  43445. return position + i;
  43446. }
  43447. int TextEditor::findWordBreakBefore (const int position) const
  43448. {
  43449. if (position <= 0)
  43450. return 0;
  43451. const int startOfBuffer = jmax (0, position - 512);
  43452. const String t (getTextInRange (Range<int> (startOfBuffer, position)));
  43453. int i = position - startOfBuffer;
  43454. while (i > 0 && CharacterFunctions::isWhitespace (t [i - 1]))
  43455. --i;
  43456. if (i > 0)
  43457. {
  43458. const int type = getCharacterCategory (t [i - 1]);
  43459. while (i > 0 && type == getCharacterCategory (t [i - 1]))
  43460. --i;
  43461. }
  43462. jassert (startOfBuffer + i >= 0);
  43463. return startOfBuffer + i;
  43464. }
  43465. void TextEditor::splitSection (const int sectionIndex,
  43466. const int charToSplitAt)
  43467. {
  43468. jassert (sections[sectionIndex] != 0);
  43469. sections.insert (sectionIndex + 1,
  43470. ((UniformTextSection*) sections.getUnchecked (sectionIndex))
  43471. ->split (charToSplitAt, passwordCharacter));
  43472. }
  43473. void TextEditor::coalesceSimilarSections()
  43474. {
  43475. for (int i = 0; i < sections.size() - 1; ++i)
  43476. {
  43477. UniformTextSection* const s1 = (UniformTextSection*) sections.getUnchecked (i);
  43478. UniformTextSection* const s2 = (UniformTextSection*) sections.getUnchecked (i + 1);
  43479. if (s1->font == s2->font
  43480. && s1->colour == s2->colour)
  43481. {
  43482. s1->append (*s2, passwordCharacter);
  43483. sections.remove (i + 1);
  43484. delete s2;
  43485. --i;
  43486. }
  43487. }
  43488. }
  43489. END_JUCE_NAMESPACE
  43490. /*** End of inlined file: juce_TextEditor.cpp ***/
  43491. /*** Start of inlined file: juce_Toolbar.cpp ***/
  43492. BEGIN_JUCE_NAMESPACE
  43493. const tchar* const Toolbar::toolbarDragDescriptor = T("_toolbarItem_");
  43494. class ToolbarSpacerComp : public ToolbarItemComponent
  43495. {
  43496. public:
  43497. ToolbarSpacerComp (const int itemId_, const float fixedSize_, const bool drawBar_)
  43498. : ToolbarItemComponent (itemId_, String::empty, false),
  43499. fixedSize (fixedSize_),
  43500. drawBar (drawBar_)
  43501. {
  43502. }
  43503. ~ToolbarSpacerComp()
  43504. {
  43505. }
  43506. bool getToolbarItemSizes (int toolbarThickness, bool /*isToolbarVertical*/,
  43507. int& preferredSize, int& minSize, int& maxSize)
  43508. {
  43509. if (fixedSize <= 0)
  43510. {
  43511. preferredSize = toolbarThickness * 2;
  43512. minSize = 4;
  43513. maxSize = 32768;
  43514. }
  43515. else
  43516. {
  43517. maxSize = roundToInt (toolbarThickness * fixedSize);
  43518. minSize = drawBar ? maxSize : jmin (4, maxSize);
  43519. preferredSize = maxSize;
  43520. if (getEditingMode() == editableOnPalette)
  43521. preferredSize = maxSize = toolbarThickness / (drawBar ? 3 : 2);
  43522. }
  43523. return true;
  43524. }
  43525. void paintButtonArea (Graphics&, int, int, bool, bool)
  43526. {
  43527. }
  43528. void contentAreaChanged (const Rectangle<int>&)
  43529. {
  43530. }
  43531. int getResizeOrder() const throw()
  43532. {
  43533. return fixedSize <= 0 ? 0 : 1;
  43534. }
  43535. void paint (Graphics& g)
  43536. {
  43537. const int w = getWidth();
  43538. const int h = getHeight();
  43539. if (drawBar)
  43540. {
  43541. g.setColour (findColour (Toolbar::separatorColourId, true));
  43542. const float thickness = 0.2f;
  43543. if (isToolbarVertical())
  43544. g.fillRect (w * 0.1f, h * (0.5f - thickness * 0.5f), w * 0.8f, h * thickness);
  43545. else
  43546. g.fillRect (w * (0.5f - thickness * 0.5f), h * 0.1f, w * thickness, h * 0.8f);
  43547. }
  43548. if (getEditingMode() != normalMode && ! drawBar)
  43549. {
  43550. g.setColour (findColour (Toolbar::separatorColourId, true));
  43551. const int indentX = jmin (2, (w - 3) / 2);
  43552. const int indentY = jmin (2, (h - 3) / 2);
  43553. g.drawRect (indentX, indentY, w - indentX * 2, h - indentY * 2, 1);
  43554. if (fixedSize <= 0)
  43555. {
  43556. float x1, y1, x2, y2, x3, y3, x4, y4, hw, hl;
  43557. if (isToolbarVertical())
  43558. {
  43559. x1 = w * 0.5f;
  43560. y1 = h * 0.4f;
  43561. x2 = x1;
  43562. y2 = indentX * 2.0f;
  43563. x3 = x1;
  43564. y3 = h * 0.6f;
  43565. x4 = x1;
  43566. y4 = h - y2;
  43567. hw = w * 0.15f;
  43568. hl = w * 0.2f;
  43569. }
  43570. else
  43571. {
  43572. x1 = w * 0.4f;
  43573. y1 = h * 0.5f;
  43574. x2 = indentX * 2.0f;
  43575. y2 = y1;
  43576. x3 = w * 0.6f;
  43577. y3 = y1;
  43578. x4 = w - x2;
  43579. y4 = y1;
  43580. hw = h * 0.15f;
  43581. hl = h * 0.2f;
  43582. }
  43583. Path p;
  43584. p.addArrow (x1, y1, x2, y2, 1.5f, hw, hl);
  43585. p.addArrow (x3, y3, x4, y4, 1.5f, hw, hl);
  43586. g.fillPath (p);
  43587. }
  43588. }
  43589. }
  43590. juce_UseDebuggingNewOperator
  43591. private:
  43592. const float fixedSize;
  43593. const bool drawBar;
  43594. ToolbarSpacerComp (const ToolbarSpacerComp&);
  43595. ToolbarSpacerComp& operator= (const ToolbarSpacerComp&);
  43596. };
  43597. class MissingItemsComponent : public PopupMenuCustomComponent
  43598. {
  43599. public:
  43600. MissingItemsComponent (Toolbar& owner_, const int height_)
  43601. : PopupMenuCustomComponent (true),
  43602. owner (owner_),
  43603. height (height_)
  43604. {
  43605. for (int i = owner_.items.size(); --i >= 0;)
  43606. {
  43607. ToolbarItemComponent* const tc = owner_.items.getUnchecked(i);
  43608. if (dynamic_cast <ToolbarSpacerComp*> (tc) == 0 && ! tc->isVisible())
  43609. {
  43610. oldIndexes.insert (0, i);
  43611. addAndMakeVisible (tc, 0);
  43612. }
  43613. }
  43614. layout (400);
  43615. }
  43616. ~MissingItemsComponent()
  43617. {
  43618. // deleting the toolbar while its menu it open??
  43619. jassert (owner.isValidComponent());
  43620. for (int i = 0; i < getNumChildComponents(); ++i)
  43621. {
  43622. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43623. if (tc != 0)
  43624. {
  43625. tc->setVisible (false);
  43626. const int index = oldIndexes.remove (i);
  43627. owner.addChildComponent (tc, index);
  43628. --i;
  43629. }
  43630. }
  43631. owner.resized();
  43632. }
  43633. void layout (const int preferredWidth)
  43634. {
  43635. const int indent = 8;
  43636. int x = indent;
  43637. int y = indent;
  43638. int maxX = 0;
  43639. for (int i = 0; i < getNumChildComponents(); ++i)
  43640. {
  43641. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getChildComponent (i));
  43642. if (tc != 0)
  43643. {
  43644. int preferredSize = 1, minSize = 1, maxSize = 1;
  43645. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  43646. {
  43647. if (x + preferredSize > preferredWidth && x > indent)
  43648. {
  43649. x = indent;
  43650. y += height;
  43651. }
  43652. tc->setBounds (x, y, preferredSize, height);
  43653. x += preferredSize;
  43654. maxX = jmax (maxX, x);
  43655. }
  43656. }
  43657. }
  43658. setSize (maxX + 8, y + height + 8);
  43659. }
  43660. void getIdealSize (int& idealWidth, int& idealHeight)
  43661. {
  43662. idealWidth = getWidth();
  43663. idealHeight = getHeight();
  43664. }
  43665. juce_UseDebuggingNewOperator
  43666. private:
  43667. Toolbar& owner;
  43668. const int height;
  43669. Array <int> oldIndexes;
  43670. MissingItemsComponent (const MissingItemsComponent&);
  43671. MissingItemsComponent& operator= (const MissingItemsComponent&);
  43672. };
  43673. Toolbar::Toolbar()
  43674. : vertical (false),
  43675. isEditingActive (false),
  43676. toolbarStyle (Toolbar::iconsOnly)
  43677. {
  43678. addChildComponent (missingItemsButton = getLookAndFeel().createToolbarMissingItemsButton (*this));
  43679. missingItemsButton->setAlwaysOnTop (true);
  43680. missingItemsButton->addButtonListener (this);
  43681. }
  43682. Toolbar::~Toolbar()
  43683. {
  43684. animator.cancelAllAnimations (true);
  43685. deleteAllChildren();
  43686. }
  43687. void Toolbar::setVertical (const bool shouldBeVertical)
  43688. {
  43689. if (vertical != shouldBeVertical)
  43690. {
  43691. vertical = shouldBeVertical;
  43692. resized();
  43693. }
  43694. }
  43695. void Toolbar::clear()
  43696. {
  43697. for (int i = items.size(); --i >= 0;)
  43698. {
  43699. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43700. items.remove (i);
  43701. delete tc;
  43702. }
  43703. resized();
  43704. }
  43705. ToolbarItemComponent* Toolbar::createItem (ToolbarItemFactory& factory, const int itemId)
  43706. {
  43707. if (itemId == ToolbarItemFactory::separatorBarId)
  43708. return new ToolbarSpacerComp (itemId, 0.1f, true);
  43709. else if (itemId == ToolbarItemFactory::spacerId)
  43710. return new ToolbarSpacerComp (itemId, 0.5f, false);
  43711. else if (itemId == ToolbarItemFactory::flexibleSpacerId)
  43712. return new ToolbarSpacerComp (itemId, 0, false);
  43713. return factory.createItem (itemId);
  43714. }
  43715. void Toolbar::addItemInternal (ToolbarItemFactory& factory,
  43716. const int itemId,
  43717. const int insertIndex)
  43718. {
  43719. // An ID can't be zero - this might indicate a mistake somewhere?
  43720. jassert (itemId != 0);
  43721. ToolbarItemComponent* const tc = createItem (factory, itemId);
  43722. if (tc != 0)
  43723. {
  43724. #ifdef JUCE_DEBUG
  43725. Array <int> allowedIds;
  43726. factory.getAllToolbarItemIds (allowedIds);
  43727. // If your factory can create an item for a given ID, it must also return
  43728. // that ID from its getAllToolbarItemIds() method!
  43729. jassert (allowedIds.contains (itemId));
  43730. #endif
  43731. items.insert (insertIndex, tc);
  43732. addAndMakeVisible (tc, insertIndex);
  43733. }
  43734. }
  43735. void Toolbar::addItem (ToolbarItemFactory& factory,
  43736. const int itemId,
  43737. const int insertIndex)
  43738. {
  43739. addItemInternal (factory, itemId, insertIndex);
  43740. resized();
  43741. }
  43742. void Toolbar::addDefaultItems (ToolbarItemFactory& factoryToUse)
  43743. {
  43744. Array <int> ids;
  43745. factoryToUse.getDefaultItemSet (ids);
  43746. clear();
  43747. for (int i = 0; i < ids.size(); ++i)
  43748. addItemInternal (factoryToUse, ids.getUnchecked (i), -1);
  43749. resized();
  43750. }
  43751. void Toolbar::removeToolbarItem (const int itemIndex)
  43752. {
  43753. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43754. if (tc != 0)
  43755. {
  43756. items.removeValue (tc);
  43757. delete tc;
  43758. resized();
  43759. }
  43760. }
  43761. int Toolbar::getNumItems() const throw()
  43762. {
  43763. return items.size();
  43764. }
  43765. int Toolbar::getItemId (const int itemIndex) const throw()
  43766. {
  43767. ToolbarItemComponent* const tc = getItemComponent (itemIndex);
  43768. return tc != 0 ? tc->getItemId() : 0;
  43769. }
  43770. ToolbarItemComponent* Toolbar::getItemComponent (const int itemIndex) const throw()
  43771. {
  43772. return items [itemIndex];
  43773. }
  43774. ToolbarItemComponent* Toolbar::getNextActiveComponent (int index, const int delta) const
  43775. {
  43776. for (;;)
  43777. {
  43778. index += delta;
  43779. ToolbarItemComponent* const tc = getItemComponent (index);
  43780. if (tc == 0)
  43781. break;
  43782. if (tc->isActive)
  43783. return tc;
  43784. }
  43785. return 0;
  43786. }
  43787. void Toolbar::setStyle (const ToolbarItemStyle& newStyle)
  43788. {
  43789. if (toolbarStyle != newStyle)
  43790. {
  43791. toolbarStyle = newStyle;
  43792. updateAllItemPositions (false);
  43793. }
  43794. }
  43795. const String Toolbar::toString() const
  43796. {
  43797. String s (T("TB:"));
  43798. for (int i = 0; i < getNumItems(); ++i)
  43799. s << getItemId(i) << T(' ');
  43800. return s.trimEnd();
  43801. }
  43802. bool Toolbar::restoreFromString (ToolbarItemFactory& factoryToUse,
  43803. const String& savedVersion)
  43804. {
  43805. if (! savedVersion.startsWith (T("TB:")))
  43806. return false;
  43807. StringArray tokens;
  43808. tokens.addTokens (savedVersion.substring (3), false);
  43809. clear();
  43810. for (int i = 0; i < tokens.size(); ++i)
  43811. addItemInternal (factoryToUse, tokens[i].getIntValue(), -1);
  43812. resized();
  43813. return true;
  43814. }
  43815. void Toolbar::paint (Graphics& g)
  43816. {
  43817. getLookAndFeel().paintToolbarBackground (g, getWidth(), getHeight(), *this);
  43818. }
  43819. int Toolbar::getThickness() const throw()
  43820. {
  43821. return vertical ? getWidth() : getHeight();
  43822. }
  43823. int Toolbar::getLength() const throw()
  43824. {
  43825. return vertical ? getHeight() : getWidth();
  43826. }
  43827. void Toolbar::setEditingActive (const bool active)
  43828. {
  43829. if (isEditingActive != active)
  43830. {
  43831. isEditingActive = active;
  43832. updateAllItemPositions (false);
  43833. }
  43834. }
  43835. void Toolbar::resized()
  43836. {
  43837. updateAllItemPositions (false);
  43838. }
  43839. void Toolbar::updateAllItemPositions (const bool animate)
  43840. {
  43841. if (getWidth() > 0 && getHeight() > 0)
  43842. {
  43843. StretchableObjectResizer resizer;
  43844. int i;
  43845. for (i = 0; i < items.size(); ++i)
  43846. {
  43847. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43848. tc->setEditingMode (isEditingActive ? ToolbarItemComponent::editableOnToolbar
  43849. : ToolbarItemComponent::normalMode);
  43850. tc->setStyle (toolbarStyle);
  43851. ToolbarSpacerComp* const spacer = dynamic_cast <ToolbarSpacerComp*> (tc);
  43852. int preferredSize = 1, minSize = 1, maxSize = 1;
  43853. if (tc->getToolbarItemSizes (getThickness(), isVertical(),
  43854. preferredSize, minSize, maxSize))
  43855. {
  43856. tc->isActive = true;
  43857. resizer.addItem (preferredSize, minSize, maxSize,
  43858. spacer != 0 ? spacer->getResizeOrder() : 2);
  43859. }
  43860. else
  43861. {
  43862. tc->isActive = false;
  43863. tc->setVisible (false);
  43864. }
  43865. }
  43866. resizer.resizeToFit (getLength());
  43867. int totalLength = 0;
  43868. for (i = 0; i < resizer.getNumItems(); ++i)
  43869. totalLength += (int) resizer.getItemSize (i);
  43870. const bool itemsOffTheEnd = totalLength > getLength();
  43871. const int extrasButtonSize = getThickness() / 2;
  43872. missingItemsButton->setSize (extrasButtonSize, extrasButtonSize);
  43873. missingItemsButton->setVisible (itemsOffTheEnd);
  43874. missingItemsButton->setEnabled (! isEditingActive);
  43875. if (vertical)
  43876. missingItemsButton->setCentrePosition (getWidth() / 2,
  43877. getHeight() - 4 - extrasButtonSize / 2);
  43878. else
  43879. missingItemsButton->setCentrePosition (getWidth() - 4 - extrasButtonSize / 2,
  43880. getHeight() / 2);
  43881. const int maxLength = itemsOffTheEnd ? (vertical ? missingItemsButton->getY()
  43882. : missingItemsButton->getX()) - 4
  43883. : getLength();
  43884. int pos = 0, activeIndex = 0;
  43885. for (i = 0; i < items.size(); ++i)
  43886. {
  43887. ToolbarItemComponent* const tc = items.getUnchecked(i);
  43888. if (tc->isActive)
  43889. {
  43890. const int size = (int) resizer.getItemSize (activeIndex++);
  43891. Rectangle<int> newBounds;
  43892. if (vertical)
  43893. newBounds.setBounds (0, pos, getWidth(), size);
  43894. else
  43895. newBounds.setBounds (pos, 0, size, getHeight());
  43896. if (animate)
  43897. {
  43898. animator.animateComponent (tc, newBounds, 200, 3.0, 0.0);
  43899. }
  43900. else
  43901. {
  43902. animator.cancelAnimation (tc, false);
  43903. tc->setBounds (newBounds);
  43904. }
  43905. pos += size;
  43906. tc->setVisible (pos <= maxLength
  43907. && ((! tc->isBeingDragged)
  43908. || tc->getEditingMode() == ToolbarItemComponent::editableOnPalette));
  43909. }
  43910. }
  43911. }
  43912. }
  43913. void Toolbar::buttonClicked (Button*)
  43914. {
  43915. jassert (missingItemsButton->isShowing());
  43916. if (missingItemsButton->isShowing())
  43917. {
  43918. PopupMenu m;
  43919. m.addCustomItem (1, new MissingItemsComponent (*this, getThickness()));
  43920. m.showAt (missingItemsButton);
  43921. }
  43922. }
  43923. bool Toolbar::isInterestedInDragSource (const String& sourceDescription,
  43924. Component* /*sourceComponent*/)
  43925. {
  43926. return sourceDescription == toolbarDragDescriptor && isEditingActive;
  43927. }
  43928. void Toolbar::itemDragMove (const String&, Component* sourceComponent, int x, int y)
  43929. {
  43930. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  43931. if (tc != 0)
  43932. {
  43933. if (getNumItems() == 0)
  43934. {
  43935. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43936. {
  43937. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43938. if (palette != 0)
  43939. palette->replaceComponent (tc);
  43940. }
  43941. else
  43942. {
  43943. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43944. }
  43945. items.add (tc);
  43946. addChildComponent (tc);
  43947. updateAllItemPositions (false);
  43948. }
  43949. else
  43950. {
  43951. for (int i = getNumItems(); --i >= 0;)
  43952. {
  43953. int currentIndex = getIndexOfChildComponent (tc);
  43954. if (currentIndex < 0)
  43955. {
  43956. if (tc->getEditingMode() == ToolbarItemComponent::editableOnPalette)
  43957. {
  43958. ToolbarItemPalette* const palette = tc->findParentComponentOfClass ((ToolbarItemPalette*) 0);
  43959. if (palette != 0)
  43960. palette->replaceComponent (tc);
  43961. }
  43962. else
  43963. {
  43964. jassert (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar);
  43965. }
  43966. items.add (tc);
  43967. addChildComponent (tc);
  43968. currentIndex = getIndexOfChildComponent (tc);
  43969. updateAllItemPositions (true);
  43970. }
  43971. int newIndex = currentIndex;
  43972. const int dragObjectLeft = vertical ? (y - tc->dragOffsetY) : (x - tc->dragOffsetX);
  43973. const int dragObjectRight = dragObjectLeft + (vertical ? tc->getHeight() : tc->getWidth());
  43974. const Rectangle<int> current (animator.getComponentDestination (getChildComponent (newIndex)));
  43975. ToolbarItemComponent* const prev = getNextActiveComponent (newIndex, -1);
  43976. if (prev != 0)
  43977. {
  43978. const Rectangle<int> previousPos (animator.getComponentDestination (prev));
  43979. if (abs (dragObjectLeft - (vertical ? previousPos.getY() : previousPos.getX())
  43980. < abs (dragObjectRight - (vertical ? current.getBottom() : current.getRight()))))
  43981. {
  43982. newIndex = getIndexOfChildComponent (prev);
  43983. }
  43984. }
  43985. ToolbarItemComponent* const next = getNextActiveComponent (newIndex, 1);
  43986. if (next != 0)
  43987. {
  43988. const Rectangle<int> nextPos (animator.getComponentDestination (next));
  43989. if (abs (dragObjectLeft - (vertical ? current.getY() : current.getX())
  43990. > abs (dragObjectRight - (vertical ? nextPos.getBottom() : nextPos.getRight()))))
  43991. {
  43992. newIndex = getIndexOfChildComponent (next) + 1;
  43993. }
  43994. }
  43995. if (newIndex != currentIndex)
  43996. {
  43997. items.removeValue (tc);
  43998. removeChildComponent (tc);
  43999. addChildComponent (tc, newIndex);
  44000. items.insert (newIndex, tc);
  44001. updateAllItemPositions (true);
  44002. }
  44003. else
  44004. {
  44005. break;
  44006. }
  44007. }
  44008. }
  44009. }
  44010. }
  44011. void Toolbar::itemDragExit (const String&, Component* sourceComponent)
  44012. {
  44013. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (sourceComponent);
  44014. if (tc != 0)
  44015. {
  44016. if (isParentOf (tc))
  44017. {
  44018. items.removeValue (tc);
  44019. removeChildComponent (tc);
  44020. updateAllItemPositions (true);
  44021. }
  44022. }
  44023. }
  44024. void Toolbar::itemDropped (const String&, Component*, int, int)
  44025. {
  44026. }
  44027. void Toolbar::mouseDown (const MouseEvent& e)
  44028. {
  44029. if (e.mods.isPopupMenu())
  44030. {
  44031. }
  44032. }
  44033. class ToolbarCustomisationDialog : public DialogWindow
  44034. {
  44035. public:
  44036. ToolbarCustomisationDialog (ToolbarItemFactory& factory,
  44037. Toolbar* const toolbar_,
  44038. const int optionFlags)
  44039. : DialogWindow (TRANS("Add/remove items from toolbar"), Colours::white, true, true),
  44040. toolbar (toolbar_)
  44041. {
  44042. setContentComponent (new CustomiserPanel (factory, toolbar, optionFlags), true, true);
  44043. setResizable (true, true);
  44044. setResizeLimits (400, 300, 1500, 1000);
  44045. positionNearBar();
  44046. }
  44047. ~ToolbarCustomisationDialog()
  44048. {
  44049. setContentComponent (0, true);
  44050. }
  44051. void closeButtonPressed()
  44052. {
  44053. setVisible (false);
  44054. }
  44055. bool canModalEventBeSentToComponent (const Component* comp)
  44056. {
  44057. return toolbar->isParentOf (comp);
  44058. }
  44059. void positionNearBar()
  44060. {
  44061. const Rectangle<int> screenSize (toolbar->getParentMonitorArea());
  44062. const int tbx = toolbar->getScreenX();
  44063. const int tby = toolbar->getScreenY();
  44064. const int gap = 8;
  44065. int x, y;
  44066. if (toolbar->isVertical())
  44067. {
  44068. y = tby;
  44069. if (tbx > screenSize.getCentreX())
  44070. x = tbx - getWidth() - gap;
  44071. else
  44072. x = tbx + toolbar->getWidth() + gap;
  44073. }
  44074. else
  44075. {
  44076. x = tbx + (toolbar->getWidth() - getWidth()) / 2;
  44077. if (tby > screenSize.getCentreY())
  44078. y = tby - getHeight() - gap;
  44079. else
  44080. y = tby + toolbar->getHeight() + gap;
  44081. }
  44082. setTopLeftPosition (x, y);
  44083. }
  44084. private:
  44085. Toolbar* const toolbar;
  44086. class CustomiserPanel : public Component,
  44087. private ComboBoxListener,
  44088. private ButtonListener
  44089. {
  44090. public:
  44091. CustomiserPanel (ToolbarItemFactory& factory_,
  44092. Toolbar* const toolbar_,
  44093. const int optionFlags)
  44094. : factory (factory_),
  44095. toolbar (toolbar_),
  44096. styleBox (0),
  44097. defaultButton (0)
  44098. {
  44099. addAndMakeVisible (palette = new ToolbarItemPalette (factory, toolbar));
  44100. if ((optionFlags & (Toolbar::allowIconsOnlyChoice
  44101. | Toolbar::allowIconsWithTextChoice
  44102. | Toolbar::allowTextOnlyChoice)) != 0)
  44103. {
  44104. addAndMakeVisible (styleBox = new ComboBox (String::empty));
  44105. styleBox->setEditableText (false);
  44106. if ((optionFlags & Toolbar::allowIconsOnlyChoice) != 0)
  44107. styleBox->addItem (TRANS("Show icons only"), 1);
  44108. if ((optionFlags & Toolbar::allowIconsWithTextChoice) != 0)
  44109. styleBox->addItem (TRANS("Show icons and descriptions"), 2);
  44110. if ((optionFlags & Toolbar::allowTextOnlyChoice) != 0)
  44111. styleBox->addItem (TRANS("Show descriptions only"), 3);
  44112. if (toolbar_->getStyle() == Toolbar::iconsOnly)
  44113. styleBox->setSelectedId (1);
  44114. else if (toolbar_->getStyle() == Toolbar::iconsWithText)
  44115. styleBox->setSelectedId (2);
  44116. else if (toolbar_->getStyle() == Toolbar::textOnly)
  44117. styleBox->setSelectedId (3);
  44118. styleBox->addListener (this);
  44119. }
  44120. if ((optionFlags & Toolbar::showResetToDefaultsButton) != 0)
  44121. {
  44122. addAndMakeVisible (defaultButton = new TextButton (TRANS ("Restore to default set of items")));
  44123. defaultButton->addButtonListener (this);
  44124. }
  44125. addAndMakeVisible (instructions = new Label (String::empty,
  44126. 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.")));
  44127. instructions->setFont (Font (13.0f));
  44128. setSize (500, 300);
  44129. }
  44130. ~CustomiserPanel()
  44131. {
  44132. deleteAllChildren();
  44133. }
  44134. void comboBoxChanged (ComboBox*)
  44135. {
  44136. if (styleBox->getSelectedId() == 1)
  44137. toolbar->setStyle (Toolbar::iconsOnly);
  44138. else if (styleBox->getSelectedId() == 2)
  44139. toolbar->setStyle (Toolbar::iconsWithText);
  44140. else if (styleBox->getSelectedId() == 3)
  44141. toolbar->setStyle (Toolbar::textOnly);
  44142. palette->resized(); // to make it update the styles
  44143. }
  44144. void buttonClicked (Button*)
  44145. {
  44146. toolbar->addDefaultItems (factory);
  44147. }
  44148. void paint (Graphics& g)
  44149. {
  44150. Colour background;
  44151. DialogWindow* const dw = findParentComponentOfClass ((DialogWindow*) 0);
  44152. if (dw != 0)
  44153. background = dw->getBackgroundColour();
  44154. g.setColour (background.contrasting().withAlpha (0.3f));
  44155. g.fillRect (palette->getX(), palette->getBottom() - 1, palette->getWidth(), 1);
  44156. }
  44157. void resized()
  44158. {
  44159. palette->setBounds (0, 0, getWidth(), getHeight() - 120);
  44160. if (styleBox != 0)
  44161. styleBox->setBounds (10, getHeight() - 110, 200, 22);
  44162. if (defaultButton != 0)
  44163. {
  44164. defaultButton->changeWidthToFitText (22);
  44165. defaultButton->setTopLeftPosition (240, getHeight() - 110);
  44166. }
  44167. instructions->setBounds (10, getHeight() - 80, getWidth() - 20, 80);
  44168. }
  44169. private:
  44170. ToolbarItemFactory& factory;
  44171. Toolbar* const toolbar;
  44172. Label* instructions;
  44173. ToolbarItemPalette* palette;
  44174. ComboBox* styleBox;
  44175. TextButton* defaultButton;
  44176. };
  44177. };
  44178. void Toolbar::showCustomisationDialog (ToolbarItemFactory& factory, const int optionFlags)
  44179. {
  44180. setEditingActive (true);
  44181. ToolbarCustomisationDialog dw (factory, this, optionFlags);
  44182. dw.runModalLoop();
  44183. jassert (isValidComponent()); // ? deleting the toolbar while it's being edited?
  44184. setEditingActive (false);
  44185. }
  44186. END_JUCE_NAMESPACE
  44187. /*** End of inlined file: juce_Toolbar.cpp ***/
  44188. /*** Start of inlined file: juce_ToolbarItemComponent.cpp ***/
  44189. BEGIN_JUCE_NAMESPACE
  44190. ToolbarItemFactory::ToolbarItemFactory()
  44191. {
  44192. }
  44193. ToolbarItemFactory::~ToolbarItemFactory()
  44194. {
  44195. }
  44196. class ItemDragAndDropOverlayComponent : public Component
  44197. {
  44198. public:
  44199. ItemDragAndDropOverlayComponent()
  44200. : isDragging (false)
  44201. {
  44202. setAlwaysOnTop (true);
  44203. setRepaintsOnMouseActivity (true);
  44204. setMouseCursor (MouseCursor::DraggingHandCursor);
  44205. }
  44206. ~ItemDragAndDropOverlayComponent()
  44207. {
  44208. }
  44209. void paint (Graphics& g)
  44210. {
  44211. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44212. if (isMouseOverOrDragging()
  44213. && tc != 0
  44214. && tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44215. {
  44216. g.setColour (findColour (Toolbar::editingModeOutlineColourId, true));
  44217. g.drawRect (0, 0, getWidth(), getHeight(),
  44218. jmin (2, (getWidth() - 1) / 2, (getHeight() - 1) / 2));
  44219. }
  44220. }
  44221. void mouseDown (const MouseEvent& e)
  44222. {
  44223. isDragging = false;
  44224. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44225. if (tc != 0)
  44226. {
  44227. tc->dragOffsetX = e.x;
  44228. tc->dragOffsetY = e.y;
  44229. }
  44230. }
  44231. void mouseDrag (const MouseEvent& e)
  44232. {
  44233. if (! (isDragging || e.mouseWasClicked()))
  44234. {
  44235. isDragging = true;
  44236. DragAndDropContainer* const dnd = DragAndDropContainer::findParentDragContainerFor (this);
  44237. if (dnd != 0)
  44238. {
  44239. dnd->startDragging (Toolbar::toolbarDragDescriptor, getParentComponent(), 0, true);
  44240. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44241. if (tc != 0)
  44242. {
  44243. tc->isBeingDragged = true;
  44244. if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44245. tc->setVisible (false);
  44246. }
  44247. }
  44248. }
  44249. }
  44250. void mouseUp (const MouseEvent&)
  44251. {
  44252. isDragging = false;
  44253. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (getParentComponent());
  44254. if (tc != 0)
  44255. {
  44256. tc->isBeingDragged = false;
  44257. Toolbar* const tb = tc->getToolbar();
  44258. if (tb != 0)
  44259. tb->updateAllItemPositions (true);
  44260. else if (tc->getEditingMode() == ToolbarItemComponent::editableOnToolbar)
  44261. delete tc;
  44262. }
  44263. }
  44264. void parentSizeChanged()
  44265. {
  44266. setBounds (0, 0, getParentWidth(), getParentHeight());
  44267. }
  44268. juce_UseDebuggingNewOperator
  44269. private:
  44270. bool isDragging;
  44271. ItemDragAndDropOverlayComponent (const ItemDragAndDropOverlayComponent&);
  44272. ItemDragAndDropOverlayComponent& operator= (const ItemDragAndDropOverlayComponent&);
  44273. };
  44274. ToolbarItemComponent::ToolbarItemComponent (const int itemId_,
  44275. const String& labelText,
  44276. const bool isBeingUsedAsAButton_)
  44277. : Button (labelText),
  44278. itemId (itemId_),
  44279. mode (normalMode),
  44280. toolbarStyle (Toolbar::iconsOnly),
  44281. dragOffsetX (0),
  44282. dragOffsetY (0),
  44283. isActive (true),
  44284. isBeingDragged (false),
  44285. isBeingUsedAsAButton (isBeingUsedAsAButton_)
  44286. {
  44287. // Your item ID can't be 0!
  44288. jassert (itemId_ != 0);
  44289. }
  44290. ToolbarItemComponent::~ToolbarItemComponent()
  44291. {
  44292. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  44293. overlayComp = 0;
  44294. }
  44295. Toolbar* ToolbarItemComponent::getToolbar() const
  44296. {
  44297. return dynamic_cast <Toolbar*> (getParentComponent());
  44298. }
  44299. bool ToolbarItemComponent::isToolbarVertical() const
  44300. {
  44301. const Toolbar* const t = getToolbar();
  44302. return t != 0 && t->isVertical();
  44303. }
  44304. void ToolbarItemComponent::setStyle (const Toolbar::ToolbarItemStyle& newStyle)
  44305. {
  44306. if (toolbarStyle != newStyle)
  44307. {
  44308. toolbarStyle = newStyle;
  44309. repaint();
  44310. resized();
  44311. }
  44312. }
  44313. void ToolbarItemComponent::paintButton (Graphics& g, bool isMouseOver, bool isMouseDown)
  44314. {
  44315. if (isBeingUsedAsAButton)
  44316. getLookAndFeel().paintToolbarButtonBackground (g, getWidth(), getHeight(),
  44317. isMouseOver, isMouseDown, *this);
  44318. if (toolbarStyle != Toolbar::iconsOnly)
  44319. {
  44320. const int indent = contentArea.getX();
  44321. int y = indent;
  44322. int h = getHeight() - indent * 2;
  44323. if (toolbarStyle == Toolbar::iconsWithText)
  44324. {
  44325. y = contentArea.getBottom() + indent / 2;
  44326. h -= contentArea.getHeight();
  44327. }
  44328. getLookAndFeel().paintToolbarButtonLabel (g, indent, y, getWidth() - indent * 2, h,
  44329. getButtonText(), *this);
  44330. }
  44331. if (! contentArea.isEmpty())
  44332. {
  44333. g.saveState();
  44334. g.setOrigin (contentArea.getX(), contentArea.getY());
  44335. g.reduceClipRegion (0, 0, contentArea.getWidth(), contentArea.getHeight());
  44336. paintButtonArea (g, contentArea.getWidth(), contentArea.getHeight(), isMouseOver, isMouseDown);
  44337. g.restoreState();
  44338. }
  44339. }
  44340. void ToolbarItemComponent::resized()
  44341. {
  44342. if (toolbarStyle != Toolbar::textOnly)
  44343. {
  44344. const int indent = jmin (proportionOfWidth (0.08f),
  44345. proportionOfHeight (0.08f));
  44346. contentArea = Rectangle<int> (indent, indent,
  44347. getWidth() - indent * 2,
  44348. toolbarStyle == Toolbar::iconsWithText ? proportionOfHeight (0.55f)
  44349. : (getHeight() - indent * 2));
  44350. }
  44351. else
  44352. {
  44353. contentArea = Rectangle<int>();
  44354. }
  44355. contentAreaChanged (contentArea);
  44356. }
  44357. void ToolbarItemComponent::setEditingMode (const ToolbarEditingMode newMode)
  44358. {
  44359. if (mode != newMode)
  44360. {
  44361. mode = newMode;
  44362. repaint();
  44363. if (mode == normalMode)
  44364. {
  44365. jassert (overlayComp == 0 || overlayComp->isValidComponent());
  44366. overlayComp = 0;
  44367. }
  44368. else if (overlayComp == 0)
  44369. {
  44370. addAndMakeVisible (overlayComp = new ItemDragAndDropOverlayComponent());
  44371. overlayComp->parentSizeChanged();
  44372. }
  44373. resized();
  44374. }
  44375. }
  44376. END_JUCE_NAMESPACE
  44377. /*** End of inlined file: juce_ToolbarItemComponent.cpp ***/
  44378. /*** Start of inlined file: juce_ToolbarItemPalette.cpp ***/
  44379. BEGIN_JUCE_NAMESPACE
  44380. ToolbarItemPalette::ToolbarItemPalette (ToolbarItemFactory& factory_,
  44381. Toolbar* const toolbar_)
  44382. : factory (factory_),
  44383. toolbar (toolbar_)
  44384. {
  44385. Component* const itemHolder = new Component();
  44386. Array <int> allIds;
  44387. factory_.getAllToolbarItemIds (allIds);
  44388. for (int i = 0; i < allIds.size(); ++i)
  44389. {
  44390. ToolbarItemComponent* const tc = Toolbar::createItem (factory_, allIds.getUnchecked (i));
  44391. jassert (tc != 0);
  44392. if (tc != 0)
  44393. {
  44394. itemHolder->addAndMakeVisible (tc);
  44395. tc->setEditingMode (ToolbarItemComponent::editableOnPalette);
  44396. }
  44397. }
  44398. viewport = new Viewport();
  44399. viewport->setViewedComponent (itemHolder);
  44400. addAndMakeVisible (viewport);
  44401. }
  44402. ToolbarItemPalette::~ToolbarItemPalette()
  44403. {
  44404. viewport->getViewedComponent()->deleteAllChildren();
  44405. deleteAllChildren();
  44406. }
  44407. void ToolbarItemPalette::resized()
  44408. {
  44409. viewport->setBoundsInset (BorderSize (1));
  44410. Component* const itemHolder = viewport->getViewedComponent();
  44411. const int indent = 8;
  44412. const int preferredWidth = viewport->getWidth() - viewport->getScrollBarThickness() - indent;
  44413. const int height = toolbar->getThickness();
  44414. int x = indent;
  44415. int y = indent;
  44416. int maxX = 0;
  44417. for (int i = 0; i < itemHolder->getNumChildComponents(); ++i)
  44418. {
  44419. ToolbarItemComponent* const tc = dynamic_cast <ToolbarItemComponent*> (itemHolder->getChildComponent (i));
  44420. if (tc != 0)
  44421. {
  44422. tc->setStyle (toolbar->getStyle());
  44423. int preferredSize = 1, minSize = 1, maxSize = 1;
  44424. if (tc->getToolbarItemSizes (height, false, preferredSize, minSize, maxSize))
  44425. {
  44426. if (x + preferredSize > preferredWidth && x > indent)
  44427. {
  44428. x = indent;
  44429. y += height;
  44430. }
  44431. tc->setBounds (x, y, preferredSize, height);
  44432. x += preferredSize + 8;
  44433. maxX = jmax (maxX, x);
  44434. }
  44435. }
  44436. }
  44437. itemHolder->setSize (maxX, y + height + 8);
  44438. }
  44439. void ToolbarItemPalette::replaceComponent (ToolbarItemComponent* const comp)
  44440. {
  44441. ToolbarItemComponent* const tc = Toolbar::createItem (factory, comp->getItemId());
  44442. jassert (tc != 0);
  44443. if (tc != 0)
  44444. {
  44445. tc->setBounds (comp->getBounds());
  44446. tc->setStyle (toolbar->getStyle());
  44447. tc->setEditingMode (comp->getEditingMode());
  44448. viewport->getViewedComponent()->addAndMakeVisible (tc, getIndexOfChildComponent (comp));
  44449. }
  44450. }
  44451. END_JUCE_NAMESPACE
  44452. /*** End of inlined file: juce_ToolbarItemPalette.cpp ***/
  44453. /*** Start of inlined file: juce_TreeView.cpp ***/
  44454. BEGIN_JUCE_NAMESPACE
  44455. class TreeViewContentComponent : public Component,
  44456. public TooltipClient
  44457. {
  44458. public:
  44459. TreeViewContentComponent (TreeView* const owner_)
  44460. : owner (owner_),
  44461. buttonUnderMouse (0),
  44462. isDragging (false)
  44463. {
  44464. }
  44465. ~TreeViewContentComponent()
  44466. {
  44467. deleteAllChildren();
  44468. }
  44469. void mouseDown (const MouseEvent& e)
  44470. {
  44471. updateButtonUnderMouse (e);
  44472. isDragging = false;
  44473. needSelectionOnMouseUp = false;
  44474. Rectangle<int> pos;
  44475. TreeViewItem* const item = findItemAt (e.y, pos);
  44476. if (item == 0)
  44477. return;
  44478. // (if the open/close buttons are hidden, we'll treat clicks to the left of the item
  44479. // as selection clicks)
  44480. if (e.x < pos.getX() && owner->openCloseButtonsVisible)
  44481. {
  44482. if (e.x >= pos.getX() - owner->getIndentSize())
  44483. item->setOpen (! item->isOpen());
  44484. // (clicks to the left of an open/close button are ignored)
  44485. }
  44486. else
  44487. {
  44488. // mouse-down inside the body of the item..
  44489. if (! owner->isMultiSelectEnabled())
  44490. item->setSelected (true, true);
  44491. else if (item->isSelected())
  44492. needSelectionOnMouseUp = ! e.mods.isPopupMenu();
  44493. else
  44494. selectBasedOnModifiers (item, e.mods);
  44495. MouseEvent e2 (e);
  44496. e2.x -= pos.getX();
  44497. e2.y -= pos.getY();
  44498. if (e2.x >= 0)
  44499. item->itemClicked (e2);
  44500. }
  44501. }
  44502. void mouseUp (const MouseEvent& e)
  44503. {
  44504. updateButtonUnderMouse (e);
  44505. if (needSelectionOnMouseUp && e.mouseWasClicked())
  44506. {
  44507. Rectangle<int> pos;
  44508. TreeViewItem* const item = findItemAt (e.y, pos);
  44509. if (item != 0)
  44510. selectBasedOnModifiers (item, e.mods);
  44511. }
  44512. }
  44513. void mouseDoubleClick (const MouseEvent& e)
  44514. {
  44515. if (e.getNumberOfClicks() != 3) // ignore triple clicks
  44516. {
  44517. Rectangle<int> pos;
  44518. TreeViewItem* const item = findItemAt (e.y, pos);
  44519. if (item != 0 && (e.x >= pos.getX() || ! owner->openCloseButtonsVisible))
  44520. {
  44521. MouseEvent e2 (e);
  44522. e2.x -= pos.getX();
  44523. e2.y -= pos.getY();
  44524. item->itemDoubleClicked (e2);
  44525. }
  44526. }
  44527. }
  44528. void mouseDrag (const MouseEvent& e)
  44529. {
  44530. if (isEnabled()
  44531. && ! (isDragging || e.mouseWasClicked()
  44532. || e.getDistanceFromDragStart() < 5
  44533. || e.mods.isPopupMenu()))
  44534. {
  44535. isDragging = true;
  44536. Rectangle<int> pos;
  44537. TreeViewItem* const item = findItemAt (e.getMouseDownY(), pos);
  44538. if (item != 0 && e.getMouseDownX() >= pos.getX())
  44539. {
  44540. const String dragDescription (item->getDragSourceDescription());
  44541. if (dragDescription.isNotEmpty())
  44542. {
  44543. DragAndDropContainer* const dragContainer
  44544. = DragAndDropContainer::findParentDragContainerFor (this);
  44545. if (dragContainer != 0)
  44546. {
  44547. pos.setSize (pos.getWidth(), item->itemHeight);
  44548. Image* dragImage = Component::createComponentSnapshot (pos, true);
  44549. dragImage->multiplyAllAlphas (0.6f);
  44550. Point<int> imageOffset (pos.getX() - e.x, pos.getY() - e.y);
  44551. dragContainer->startDragging (dragDescription, owner, dragImage, true, &imageOffset);
  44552. }
  44553. else
  44554. {
  44555. // to be able to do a drag-and-drop operation, the treeview needs to
  44556. // be inside a component which is also a DragAndDropContainer.
  44557. jassertfalse
  44558. }
  44559. }
  44560. }
  44561. }
  44562. }
  44563. void mouseMove (const MouseEvent& e)
  44564. {
  44565. updateButtonUnderMouse (e);
  44566. }
  44567. void mouseExit (const MouseEvent& e)
  44568. {
  44569. updateButtonUnderMouse (e);
  44570. }
  44571. void paint (Graphics& g);
  44572. TreeViewItem* findItemAt (int y, Rectangle<int>& itemPosition) const;
  44573. void updateComponents()
  44574. {
  44575. const int visibleTop = -getY();
  44576. const int visibleBottom = visibleTop + getParentHeight();
  44577. BitArray itemsToKeep;
  44578. TreeViewItem* item = owner->rootItem;
  44579. int y = (item != 0 && !owner->rootItemVisible) ? -item->itemHeight : 0;
  44580. while (item != 0 && y < visibleBottom)
  44581. {
  44582. y += item->itemHeight;
  44583. if (y >= visibleTop)
  44584. {
  44585. const int index = rowComponentIds.indexOf (item->uid);
  44586. if (index < 0)
  44587. {
  44588. Component* const comp = item->createItemComponent();
  44589. if (comp != 0)
  44590. {
  44591. addAndMakeVisible (comp);
  44592. itemsToKeep.setBit (rowComponentItems.size());
  44593. rowComponentItems.add (item);
  44594. rowComponentIds.add (item->uid);
  44595. rowComponents.add (comp);
  44596. }
  44597. }
  44598. else
  44599. {
  44600. itemsToKeep.setBit (index);
  44601. }
  44602. }
  44603. item = item->getNextVisibleItem (true);
  44604. }
  44605. for (int i = rowComponentItems.size(); --i >= 0;)
  44606. {
  44607. Component* const comp = (Component*) rowComponents.getUnchecked(i);
  44608. bool keep = false;
  44609. if (isParentOf (comp))
  44610. {
  44611. if (itemsToKeep[i])
  44612. {
  44613. const TreeViewItem* const item = (TreeViewItem*) rowComponentItems.getUnchecked(i);
  44614. Rectangle<int> pos (item->getItemPosition (false));
  44615. pos.setSize (pos.getWidth(), item->itemHeight);
  44616. if (pos.getBottom() >= visibleTop && pos.getY() < visibleBottom)
  44617. {
  44618. keep = true;
  44619. comp->setBounds (pos);
  44620. }
  44621. }
  44622. if ((! keep)
  44623. && Component::isMouseButtonDownAnywhere()
  44624. && (comp == Component::getComponentUnderMouse()
  44625. || comp->isParentOf (Component::getComponentUnderMouse())))
  44626. {
  44627. keep = true;
  44628. comp->setSize (0, 0);
  44629. }
  44630. }
  44631. if (! keep)
  44632. {
  44633. delete comp;
  44634. rowComponents.remove (i);
  44635. rowComponentIds.remove (i);
  44636. rowComponentItems.remove (i);
  44637. }
  44638. }
  44639. }
  44640. void updateButtonUnderMouse (const MouseEvent& e)
  44641. {
  44642. TreeViewItem* newItem = 0;
  44643. if (owner->openCloseButtonsVisible)
  44644. {
  44645. Rectangle<int> pos;
  44646. TreeViewItem* item = findItemAt (e.y, pos);
  44647. if (item != 0 && e.x < pos.getX() && e.x >= pos.getX() - owner->getIndentSize())
  44648. {
  44649. newItem = item;
  44650. if (! newItem->mightContainSubItems())
  44651. newItem = 0;
  44652. }
  44653. }
  44654. if (buttonUnderMouse != newItem)
  44655. {
  44656. if (buttonUnderMouse != 0 && containsItem (buttonUnderMouse))
  44657. {
  44658. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44659. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44660. }
  44661. buttonUnderMouse = newItem;
  44662. if (buttonUnderMouse != 0)
  44663. {
  44664. const Rectangle<int> r (buttonUnderMouse->getItemPosition (false));
  44665. repaint (0, r.getY(), r.getX(), buttonUnderMouse->getItemHeight());
  44666. }
  44667. }
  44668. }
  44669. bool isMouseOverButton (TreeViewItem* item) const throw()
  44670. {
  44671. return item == buttonUnderMouse;
  44672. }
  44673. void resized()
  44674. {
  44675. owner->itemsChanged();
  44676. }
  44677. const String getTooltip()
  44678. {
  44679. Rectangle<int> pos;
  44680. TreeViewItem* const item = findItemAt (getMouseXYRelative().getY(), pos);
  44681. if (item != 0)
  44682. return item->getTooltip();
  44683. return owner->getTooltip();
  44684. }
  44685. juce_UseDebuggingNewOperator
  44686. private:
  44687. TreeView* const owner;
  44688. VoidArray rowComponentItems;
  44689. Array <int> rowComponentIds;
  44690. VoidArray rowComponents;
  44691. TreeViewItem* buttonUnderMouse;
  44692. bool isDragging, needSelectionOnMouseUp;
  44693. TreeViewContentComponent (const TreeViewContentComponent&);
  44694. TreeViewContentComponent& operator= (const TreeViewContentComponent&);
  44695. void selectBasedOnModifiers (TreeViewItem* const item, const ModifierKeys& modifiers)
  44696. {
  44697. TreeViewItem* firstSelected = 0;
  44698. if (modifiers.isShiftDown() && ((firstSelected = owner->getSelectedItem (0)) != 0))
  44699. {
  44700. TreeViewItem* const lastSelected = owner->getSelectedItem (owner->getNumSelectedItems() - 1);
  44701. jassert (lastSelected != 0);
  44702. int rowStart = firstSelected->getRowNumberInTree();
  44703. int rowEnd = lastSelected->getRowNumberInTree();
  44704. if (rowStart > rowEnd)
  44705. swapVariables (rowStart, rowEnd);
  44706. int ourRow = item->getRowNumberInTree();
  44707. int otherEnd = ourRow < rowEnd ? rowStart : rowEnd;
  44708. if (ourRow > otherEnd)
  44709. swapVariables (ourRow, otherEnd);
  44710. for (int i = ourRow; i <= otherEnd; ++i)
  44711. owner->getItemOnRow (i)->setSelected (true, false);
  44712. }
  44713. else
  44714. {
  44715. const bool cmd = modifiers.isCommandDown();
  44716. item->setSelected ((! cmd) || (! item->isSelected()), ! cmd);
  44717. }
  44718. }
  44719. bool containsItem (TreeViewItem* const item) const
  44720. {
  44721. for (int i = rowComponentItems.size(); --i >= 0;)
  44722. if ((TreeViewItem*) rowComponentItems.getUnchecked (i) == item)
  44723. return true;
  44724. return false;
  44725. }
  44726. };
  44727. class TreeViewport : public Viewport
  44728. {
  44729. public:
  44730. TreeViewport() throw() {}
  44731. ~TreeViewport() throw() {}
  44732. void updateComponents()
  44733. {
  44734. if (getViewedComponent() != 0)
  44735. ((TreeViewContentComponent*) getViewedComponent())->updateComponents();
  44736. repaint();
  44737. }
  44738. void visibleAreaChanged (int, int, int, int)
  44739. {
  44740. updateComponents();
  44741. }
  44742. juce_UseDebuggingNewOperator
  44743. private:
  44744. TreeViewport (const TreeViewport&);
  44745. TreeViewport& operator= (const TreeViewport&);
  44746. };
  44747. TreeView::TreeView (const String& componentName)
  44748. : Component (componentName),
  44749. rootItem (0),
  44750. dragInsertPointHighlight (0),
  44751. dragTargetGroupHighlight (0),
  44752. indentSize (24),
  44753. defaultOpenness (false),
  44754. needsRecalculating (true),
  44755. rootItemVisible (true),
  44756. multiSelectEnabled (false),
  44757. openCloseButtonsVisible (true)
  44758. {
  44759. addAndMakeVisible (viewport = new TreeViewport());
  44760. viewport->setViewedComponent (new TreeViewContentComponent (this));
  44761. viewport->setWantsKeyboardFocus (false);
  44762. setWantsKeyboardFocus (true);
  44763. }
  44764. TreeView::~TreeView()
  44765. {
  44766. if (rootItem != 0)
  44767. rootItem->setOwnerView (0);
  44768. deleteAllChildren();
  44769. }
  44770. void TreeView::setRootItem (TreeViewItem* const newRootItem)
  44771. {
  44772. if (rootItem != newRootItem)
  44773. {
  44774. if (newRootItem != 0)
  44775. {
  44776. jassert (newRootItem->ownerView == 0); // can't use a tree item in more than one tree at once..
  44777. if (newRootItem->ownerView != 0)
  44778. newRootItem->ownerView->setRootItem (0);
  44779. }
  44780. if (rootItem != 0)
  44781. rootItem->setOwnerView (0);
  44782. rootItem = newRootItem;
  44783. if (newRootItem != 0)
  44784. newRootItem->setOwnerView (this);
  44785. needsRecalculating = true;
  44786. handleAsyncUpdate();
  44787. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44788. {
  44789. rootItem->setOpen (false); // force a re-open
  44790. rootItem->setOpen (true);
  44791. }
  44792. }
  44793. }
  44794. void TreeView::deleteRootItem()
  44795. {
  44796. const ScopedPointer <TreeViewItem> deleter (rootItem);
  44797. setRootItem (0);
  44798. }
  44799. void TreeView::setRootItemVisible (const bool shouldBeVisible)
  44800. {
  44801. rootItemVisible = shouldBeVisible;
  44802. if (rootItem != 0 && (defaultOpenness || ! rootItemVisible))
  44803. {
  44804. rootItem->setOpen (false); // force a re-open
  44805. rootItem->setOpen (true);
  44806. }
  44807. itemsChanged();
  44808. }
  44809. void TreeView::colourChanged()
  44810. {
  44811. setOpaque (findColour (backgroundColourId).isOpaque());
  44812. repaint();
  44813. }
  44814. void TreeView::setIndentSize (const int newIndentSize)
  44815. {
  44816. if (indentSize != newIndentSize)
  44817. {
  44818. indentSize = newIndentSize;
  44819. resized();
  44820. }
  44821. }
  44822. void TreeView::setDefaultOpenness (const bool isOpenByDefault)
  44823. {
  44824. if (defaultOpenness != isOpenByDefault)
  44825. {
  44826. defaultOpenness = isOpenByDefault;
  44827. itemsChanged();
  44828. }
  44829. }
  44830. void TreeView::setMultiSelectEnabled (const bool canMultiSelect)
  44831. {
  44832. multiSelectEnabled = canMultiSelect;
  44833. }
  44834. void TreeView::setOpenCloseButtonsVisible (const bool shouldBeVisible)
  44835. {
  44836. if (openCloseButtonsVisible != shouldBeVisible)
  44837. {
  44838. openCloseButtonsVisible = shouldBeVisible;
  44839. itemsChanged();
  44840. }
  44841. }
  44842. void TreeView::clearSelectedItems()
  44843. {
  44844. if (rootItem != 0)
  44845. rootItem->deselectAllRecursively();
  44846. }
  44847. int TreeView::getNumSelectedItems() const throw()
  44848. {
  44849. return (rootItem != 0) ? rootItem->countSelectedItemsRecursively() : 0;
  44850. }
  44851. TreeViewItem* TreeView::getSelectedItem (const int index) const throw()
  44852. {
  44853. return (rootItem != 0) ? rootItem->getSelectedItemWithIndex (index) : 0;
  44854. }
  44855. int TreeView::getNumRowsInTree() const
  44856. {
  44857. if (rootItem != 0)
  44858. return rootItem->getNumRows() - (rootItemVisible ? 0 : 1);
  44859. return 0;
  44860. }
  44861. TreeViewItem* TreeView::getItemOnRow (int index) const
  44862. {
  44863. if (! rootItemVisible)
  44864. ++index;
  44865. if (rootItem != 0 && index >= 0)
  44866. return rootItem->getItemOnRow (index);
  44867. return 0;
  44868. }
  44869. TreeViewItem* TreeView::getItemAt (int y) const throw()
  44870. {
  44871. TreeViewContentComponent* const tc = (TreeViewContentComponent*) viewport->getViewedComponent();
  44872. Rectangle<int> pos;
  44873. return tc->findItemAt (relativePositionToOtherComponent (tc, Point<int> (0, y)).getY(), pos);
  44874. }
  44875. TreeViewItem* TreeView::findItemFromIdentifierString (const String& identifierString) const
  44876. {
  44877. if (rootItem == 0)
  44878. return 0;
  44879. return rootItem->findItemFromIdentifierString (identifierString);
  44880. }
  44881. XmlElement* TreeView::getOpennessState (const bool alsoIncludeScrollPosition) const
  44882. {
  44883. XmlElement* e = 0;
  44884. if (rootItem != 0)
  44885. {
  44886. e = rootItem->getOpennessState();
  44887. if (e != 0 && alsoIncludeScrollPosition)
  44888. e->setAttribute (T("scrollPos"), viewport->getViewPositionY());
  44889. }
  44890. return e;
  44891. }
  44892. void TreeView::restoreOpennessState (const XmlElement& newState)
  44893. {
  44894. if (rootItem != 0)
  44895. {
  44896. rootItem->restoreOpennessState (newState);
  44897. if (newState.hasAttribute (T("scrollPos")))
  44898. viewport->setViewPosition (viewport->getViewPositionX(),
  44899. newState.getIntAttribute (T("scrollPos")));
  44900. }
  44901. }
  44902. void TreeView::paint (Graphics& g)
  44903. {
  44904. g.fillAll (findColour (backgroundColourId));
  44905. }
  44906. void TreeView::resized()
  44907. {
  44908. viewport->setBounds (0, 0, getWidth(), getHeight());
  44909. itemsChanged();
  44910. handleAsyncUpdate();
  44911. }
  44912. void TreeView::enablementChanged()
  44913. {
  44914. repaint();
  44915. }
  44916. void TreeView::moveSelectedRow (int delta)
  44917. {
  44918. if (delta == 0)
  44919. return;
  44920. int rowSelected = 0;
  44921. TreeViewItem* const firstSelected = getSelectedItem (0);
  44922. if (firstSelected != 0)
  44923. rowSelected = firstSelected->getRowNumberInTree();
  44924. rowSelected = jlimit (0, getNumRowsInTree() - 1, rowSelected + delta);
  44925. for (;;)
  44926. {
  44927. TreeViewItem* item = getItemOnRow (rowSelected);
  44928. if (item != 0)
  44929. {
  44930. if (! item->canBeSelected())
  44931. {
  44932. // if the row we want to highlight doesn't allow it, try skipping
  44933. // to the next item..
  44934. const int nextRowToTry = jlimit (0, getNumRowsInTree() - 1,
  44935. rowSelected + (delta < 0 ? -1 : 1));
  44936. if (rowSelected != nextRowToTry)
  44937. {
  44938. rowSelected = nextRowToTry;
  44939. continue;
  44940. }
  44941. else
  44942. {
  44943. break;
  44944. }
  44945. }
  44946. item->setSelected (true, true);
  44947. scrollToKeepItemVisible (item);
  44948. }
  44949. break;
  44950. }
  44951. }
  44952. void TreeView::scrollToKeepItemVisible (TreeViewItem* item)
  44953. {
  44954. if (item != 0 && item->ownerView == this)
  44955. {
  44956. handleAsyncUpdate();
  44957. item = item->getDeepestOpenParentItem();
  44958. int y = item->y;
  44959. int viewTop = viewport->getViewPositionY();
  44960. if (y < viewTop)
  44961. {
  44962. viewport->setViewPosition (viewport->getViewPositionX(), y);
  44963. }
  44964. else if (y + item->itemHeight > viewTop + viewport->getViewHeight())
  44965. {
  44966. viewport->setViewPosition (viewport->getViewPositionX(),
  44967. (y + item->itemHeight) - viewport->getViewHeight());
  44968. }
  44969. }
  44970. }
  44971. bool TreeView::keyPressed (const KeyPress& key)
  44972. {
  44973. if (key.isKeyCode (KeyPress::upKey))
  44974. {
  44975. moveSelectedRow (-1);
  44976. }
  44977. else if (key.isKeyCode (KeyPress::downKey))
  44978. {
  44979. moveSelectedRow (1);
  44980. }
  44981. else if (key.isKeyCode (KeyPress::pageDownKey) || key.isKeyCode (KeyPress::pageUpKey))
  44982. {
  44983. if (rootItem != 0)
  44984. {
  44985. int rowsOnScreen = getHeight() / jmax (1, rootItem->itemHeight);
  44986. if (key.isKeyCode (KeyPress::pageUpKey))
  44987. rowsOnScreen = -rowsOnScreen;
  44988. moveSelectedRow (rowsOnScreen);
  44989. }
  44990. }
  44991. else if (key.isKeyCode (KeyPress::homeKey))
  44992. {
  44993. moveSelectedRow (-0x3fffffff);
  44994. }
  44995. else if (key.isKeyCode (KeyPress::endKey))
  44996. {
  44997. moveSelectedRow (0x3fffffff);
  44998. }
  44999. else if (key.isKeyCode (KeyPress::returnKey))
  45000. {
  45001. TreeViewItem* const firstSelected = getSelectedItem (0);
  45002. if (firstSelected != 0)
  45003. firstSelected->setOpen (! firstSelected->isOpen());
  45004. }
  45005. else if (key.isKeyCode (KeyPress::leftKey))
  45006. {
  45007. TreeViewItem* const firstSelected = getSelectedItem (0);
  45008. if (firstSelected != 0)
  45009. {
  45010. if (firstSelected->isOpen())
  45011. {
  45012. firstSelected->setOpen (false);
  45013. }
  45014. else
  45015. {
  45016. TreeViewItem* parent = firstSelected->parentItem;
  45017. if ((! rootItemVisible) && parent == rootItem)
  45018. parent = 0;
  45019. if (parent != 0)
  45020. {
  45021. parent->setSelected (true, true);
  45022. scrollToKeepItemVisible (parent);
  45023. }
  45024. }
  45025. }
  45026. }
  45027. else if (key.isKeyCode (KeyPress::rightKey))
  45028. {
  45029. TreeViewItem* const firstSelected = getSelectedItem (0);
  45030. if (firstSelected != 0)
  45031. {
  45032. if (firstSelected->isOpen() || ! firstSelected->mightContainSubItems())
  45033. moveSelectedRow (1);
  45034. else
  45035. firstSelected->setOpen (true);
  45036. }
  45037. }
  45038. else
  45039. {
  45040. return false;
  45041. }
  45042. return true;
  45043. }
  45044. void TreeView::itemsChanged() throw()
  45045. {
  45046. needsRecalculating = true;
  45047. repaint();
  45048. triggerAsyncUpdate();
  45049. }
  45050. void TreeView::handleAsyncUpdate()
  45051. {
  45052. if (needsRecalculating)
  45053. {
  45054. needsRecalculating = false;
  45055. const ScopedLock sl (nodeAlterationLock);
  45056. if (rootItem != 0)
  45057. rootItem->updatePositions (rootItemVisible ? 0 : -rootItem->itemHeight);
  45058. ((TreeViewport*) viewport)->updateComponents();
  45059. if (rootItem != 0)
  45060. {
  45061. viewport->getViewedComponent()
  45062. ->setSize (jmax (viewport->getMaximumVisibleWidth(), rootItem->totalWidth),
  45063. rootItem->totalHeight - (rootItemVisible ? 0 : rootItem->itemHeight));
  45064. }
  45065. else
  45066. {
  45067. viewport->getViewedComponent()->setSize (0, 0);
  45068. }
  45069. }
  45070. }
  45071. class TreeViewDragInsertPointHighlight : public Component
  45072. {
  45073. public:
  45074. TreeViewDragInsertPointHighlight()
  45075. : lastItem (0)
  45076. {
  45077. setSize (100, 12);
  45078. setAlwaysOnTop (true);
  45079. setInterceptsMouseClicks (false, false);
  45080. }
  45081. ~TreeViewDragInsertPointHighlight() {}
  45082. void setTargetPosition (TreeViewItem* const item, int insertIndex, const int x, const int y, const int width) throw()
  45083. {
  45084. lastItem = item;
  45085. lastIndex = insertIndex;
  45086. const int offset = getHeight() / 2;
  45087. setBounds (x - offset, y - offset, width - (x - offset), getHeight());
  45088. }
  45089. void paint (Graphics& g)
  45090. {
  45091. Path p;
  45092. const float h = (float) getHeight();
  45093. p.addEllipse (2.0f, 2.0f, h - 4.0f, h - 4.0f);
  45094. p.startNewSubPath (h - 2.0f, h / 2.0f);
  45095. p.lineTo ((float) getWidth(), h / 2.0f);
  45096. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  45097. g.strokePath (p, PathStrokeType (2.0f));
  45098. }
  45099. TreeViewItem* lastItem;
  45100. int lastIndex;
  45101. };
  45102. class TreeViewDragTargetGroupHighlight : public Component
  45103. {
  45104. public:
  45105. TreeViewDragTargetGroupHighlight()
  45106. {
  45107. setAlwaysOnTop (true);
  45108. setInterceptsMouseClicks (false, false);
  45109. }
  45110. ~TreeViewDragTargetGroupHighlight() {}
  45111. void setTargetPosition (TreeViewItem* const item) throw()
  45112. {
  45113. Rectangle<int> r (item->getItemPosition (true));
  45114. r.setHeight (item->getItemHeight());
  45115. setBounds (r);
  45116. }
  45117. void paint (Graphics& g)
  45118. {
  45119. g.setColour (findColour (TreeView::dragAndDropIndicatorColourId, true));
  45120. g.drawRoundedRectangle (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 3.0f, 2.0f);
  45121. }
  45122. };
  45123. void TreeView::showDragHighlight (TreeViewItem* item, int insertIndex, int x, int y) throw()
  45124. {
  45125. beginDragAutoRepeat (1000 / 30);
  45126. if (dragInsertPointHighlight == 0)
  45127. {
  45128. addAndMakeVisible (dragInsertPointHighlight = new TreeViewDragInsertPointHighlight());
  45129. addAndMakeVisible (dragTargetGroupHighlight = new TreeViewDragTargetGroupHighlight());
  45130. }
  45131. ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)
  45132. ->setTargetPosition (item, insertIndex, x, y, viewport->getViewWidth());
  45133. ((TreeViewDragTargetGroupHighlight*) dragTargetGroupHighlight)
  45134. ->setTargetPosition (item);
  45135. }
  45136. void TreeView::hideDragHighlight() throw()
  45137. {
  45138. deleteAndZero (dragInsertPointHighlight);
  45139. deleteAndZero (dragTargetGroupHighlight);
  45140. }
  45141. TreeViewItem* TreeView::getInsertPosition (int& x, int& y, int& insertIndex,
  45142. const StringArray& files, const String& sourceDescription,
  45143. Component* sourceComponent) const throw()
  45144. {
  45145. insertIndex = 0;
  45146. TreeViewItem* item = getItemAt (y);
  45147. if (item == 0)
  45148. return 0;
  45149. Rectangle<int> itemPos (item->getItemPosition (true));
  45150. insertIndex = item->getIndexInParent();
  45151. const int oldY = y;
  45152. y = itemPos.getY();
  45153. if (item->getNumSubItems() == 0 || ! item->isOpen())
  45154. {
  45155. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  45156. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45157. {
  45158. // Check if we're trying to drag into an empty group item..
  45159. if (oldY > itemPos.getY() + itemPos.getHeight() / 4
  45160. && oldY < itemPos.getBottom() - itemPos.getHeight() / 4)
  45161. {
  45162. insertIndex = 0;
  45163. x = itemPos.getX() + getIndentSize();
  45164. y = itemPos.getBottom();
  45165. return item;
  45166. }
  45167. }
  45168. }
  45169. if (oldY > itemPos.getCentreY())
  45170. {
  45171. y += item->getItemHeight();
  45172. while (item->isLastOfSiblings() && item->parentItem != 0
  45173. && item->parentItem->parentItem != 0)
  45174. {
  45175. if (x > itemPos.getX())
  45176. break;
  45177. item = item->parentItem;
  45178. itemPos = item->getItemPosition (true);
  45179. insertIndex = item->getIndexInParent();
  45180. }
  45181. ++insertIndex;
  45182. }
  45183. x = itemPos.getX();
  45184. return item->parentItem;
  45185. }
  45186. void TreeView::handleDrag (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  45187. {
  45188. const bool scrolled = viewport->autoScroll (x, y, 20, 10);
  45189. int insertIndex;
  45190. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  45191. if (item != 0)
  45192. {
  45193. if (scrolled || dragInsertPointHighlight == 0
  45194. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastItem != item
  45195. || ((TreeViewDragInsertPointHighlight*) dragInsertPointHighlight)->lastIndex != insertIndex)
  45196. {
  45197. if (files.size() > 0 ? item->isInterestedInFileDrag (files)
  45198. : item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45199. showDragHighlight (item, insertIndex, x, y);
  45200. else
  45201. hideDragHighlight();
  45202. }
  45203. }
  45204. else
  45205. {
  45206. hideDragHighlight();
  45207. }
  45208. }
  45209. void TreeView::handleDrop (const StringArray& files, const String& sourceDescription, Component* sourceComponent, int x, int y)
  45210. {
  45211. hideDragHighlight();
  45212. int insertIndex;
  45213. TreeViewItem* const item = getInsertPosition (x, y, insertIndex, files, sourceDescription, sourceComponent);
  45214. if (item != 0)
  45215. {
  45216. if (files.size() > 0)
  45217. {
  45218. if (item->isInterestedInFileDrag (files))
  45219. item->filesDropped (files, insertIndex);
  45220. }
  45221. else
  45222. {
  45223. if (item->isInterestedInDragSource (sourceDescription, sourceComponent))
  45224. item->itemDropped (sourceDescription, sourceComponent, insertIndex);
  45225. }
  45226. }
  45227. }
  45228. bool TreeView::isInterestedInFileDrag (const StringArray&)
  45229. {
  45230. return true;
  45231. }
  45232. void TreeView::fileDragEnter (const StringArray& files, int x, int y)
  45233. {
  45234. fileDragMove (files, x, y);
  45235. }
  45236. void TreeView::fileDragMove (const StringArray& files, int x, int y)
  45237. {
  45238. handleDrag (files, String::empty, 0, x, y);
  45239. }
  45240. void TreeView::fileDragExit (const StringArray&)
  45241. {
  45242. hideDragHighlight();
  45243. }
  45244. void TreeView::filesDropped (const StringArray& files, int x, int y)
  45245. {
  45246. handleDrop (files, String::empty, 0, x, y);
  45247. }
  45248. bool TreeView::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45249. {
  45250. return true;
  45251. }
  45252. void TreeView::itemDragEnter (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45253. {
  45254. itemDragMove (sourceDescription, sourceComponent, x, y);
  45255. }
  45256. void TreeView::itemDragMove (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45257. {
  45258. handleDrag (StringArray(), sourceDescription, sourceComponent, x, y);
  45259. }
  45260. void TreeView::itemDragExit (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45261. {
  45262. hideDragHighlight();
  45263. }
  45264. void TreeView::itemDropped (const String& sourceDescription, Component* sourceComponent, int x, int y)
  45265. {
  45266. handleDrop (StringArray(), sourceDescription, sourceComponent, x, y);
  45267. }
  45268. void TreeViewContentComponent::paint (Graphics& g)
  45269. {
  45270. if (owner->rootItem != 0)
  45271. {
  45272. owner->handleAsyncUpdate();
  45273. if (! owner->rootItemVisible)
  45274. g.setOrigin (0, -owner->rootItem->itemHeight);
  45275. owner->rootItem->paintRecursively (g, getWidth());
  45276. }
  45277. }
  45278. TreeViewItem* TreeViewContentComponent::findItemAt (int y, Rectangle<int>& itemPosition) const
  45279. {
  45280. if (owner->rootItem != 0)
  45281. {
  45282. owner->handleAsyncUpdate();
  45283. if (! owner->rootItemVisible)
  45284. y += owner->rootItem->itemHeight;
  45285. TreeViewItem* const ti = owner->rootItem->findItemRecursively (y);
  45286. if (ti != 0)
  45287. itemPosition = ti->getItemPosition (false);
  45288. return ti;
  45289. }
  45290. return 0;
  45291. }
  45292. enum TreeViewOpenness
  45293. {
  45294. opennessDefault = 0,
  45295. opennessClosed = 1,
  45296. opennessOpen = 2
  45297. };
  45298. TreeViewItem::TreeViewItem()
  45299. : ownerView (0),
  45300. parentItem (0),
  45301. y (0),
  45302. itemHeight (0),
  45303. totalHeight (0),
  45304. selected (false),
  45305. redrawNeeded (true),
  45306. drawLinesInside (true),
  45307. drawsInLeftMargin (false),
  45308. openness (opennessDefault)
  45309. {
  45310. static int nextUID = 0;
  45311. uid = nextUID++;
  45312. }
  45313. TreeViewItem::~TreeViewItem()
  45314. {
  45315. }
  45316. const String TreeViewItem::getUniqueName() const
  45317. {
  45318. return String::empty;
  45319. }
  45320. void TreeViewItem::itemOpennessChanged (bool)
  45321. {
  45322. }
  45323. int TreeViewItem::getNumSubItems() const throw()
  45324. {
  45325. return subItems.size();
  45326. }
  45327. TreeViewItem* TreeViewItem::getSubItem (const int index) const throw()
  45328. {
  45329. return subItems [index];
  45330. }
  45331. void TreeViewItem::clearSubItems()
  45332. {
  45333. if (subItems.size() > 0)
  45334. {
  45335. if (ownerView != 0)
  45336. {
  45337. const ScopedLock sl (ownerView->nodeAlterationLock);
  45338. subItems.clear();
  45339. treeHasChanged();
  45340. }
  45341. else
  45342. {
  45343. subItems.clear();
  45344. }
  45345. }
  45346. }
  45347. void TreeViewItem::addSubItem (TreeViewItem* const newItem, const int insertPosition)
  45348. {
  45349. if (newItem != 0)
  45350. {
  45351. newItem->parentItem = this;
  45352. newItem->setOwnerView (ownerView);
  45353. newItem->y = 0;
  45354. newItem->itemHeight = newItem->getItemHeight();
  45355. newItem->totalHeight = 0;
  45356. newItem->itemWidth = newItem->getItemWidth();
  45357. newItem->totalWidth = 0;
  45358. if (ownerView != 0)
  45359. {
  45360. const ScopedLock sl (ownerView->nodeAlterationLock);
  45361. subItems.insert (insertPosition, newItem);
  45362. treeHasChanged();
  45363. if (newItem->isOpen())
  45364. newItem->itemOpennessChanged (true);
  45365. }
  45366. else
  45367. {
  45368. subItems.insert (insertPosition, newItem);
  45369. if (newItem->isOpen())
  45370. newItem->itemOpennessChanged (true);
  45371. }
  45372. }
  45373. }
  45374. void TreeViewItem::removeSubItem (const int index, const bool deleteItem)
  45375. {
  45376. if (ownerView != 0)
  45377. {
  45378. const ScopedLock sl (ownerView->nodeAlterationLock);
  45379. if (((unsigned int) index) < (unsigned int) subItems.size())
  45380. {
  45381. subItems.remove (index, deleteItem);
  45382. treeHasChanged();
  45383. }
  45384. }
  45385. else
  45386. {
  45387. subItems.remove (index, deleteItem);
  45388. }
  45389. }
  45390. bool TreeViewItem::isOpen() const throw()
  45391. {
  45392. if (openness == opennessDefault)
  45393. return ownerView != 0 && ownerView->defaultOpenness;
  45394. else
  45395. return openness == opennessOpen;
  45396. }
  45397. void TreeViewItem::setOpen (const bool shouldBeOpen)
  45398. {
  45399. if (isOpen() != shouldBeOpen)
  45400. {
  45401. openness = shouldBeOpen ? opennessOpen
  45402. : opennessClosed;
  45403. treeHasChanged();
  45404. itemOpennessChanged (isOpen());
  45405. }
  45406. }
  45407. bool TreeViewItem::isSelected() const throw()
  45408. {
  45409. return selected;
  45410. }
  45411. void TreeViewItem::deselectAllRecursively()
  45412. {
  45413. setSelected (false, false);
  45414. for (int i = 0; i < subItems.size(); ++i)
  45415. subItems.getUnchecked(i)->deselectAllRecursively();
  45416. }
  45417. void TreeViewItem::setSelected (const bool shouldBeSelected,
  45418. const bool deselectOtherItemsFirst)
  45419. {
  45420. if (shouldBeSelected && ! canBeSelected())
  45421. return;
  45422. if (deselectOtherItemsFirst)
  45423. getTopLevelItem()->deselectAllRecursively();
  45424. if (shouldBeSelected != selected)
  45425. {
  45426. selected = shouldBeSelected;
  45427. if (ownerView != 0)
  45428. ownerView->repaint();
  45429. itemSelectionChanged (shouldBeSelected);
  45430. }
  45431. }
  45432. void TreeViewItem::paintItem (Graphics&, int, int)
  45433. {
  45434. }
  45435. void TreeViewItem::paintOpenCloseButton (Graphics& g, int width, int height, bool isMouseOver)
  45436. {
  45437. ownerView->getLookAndFeel()
  45438. .drawTreeviewPlusMinusBox (g, 0, 0, width, height, ! isOpen(), isMouseOver);
  45439. }
  45440. void TreeViewItem::itemClicked (const MouseEvent&)
  45441. {
  45442. }
  45443. void TreeViewItem::itemDoubleClicked (const MouseEvent&)
  45444. {
  45445. if (mightContainSubItems())
  45446. setOpen (! isOpen());
  45447. }
  45448. void TreeViewItem::itemSelectionChanged (bool)
  45449. {
  45450. }
  45451. const String TreeViewItem::getTooltip()
  45452. {
  45453. return String::empty;
  45454. }
  45455. const String TreeViewItem::getDragSourceDescription()
  45456. {
  45457. return String::empty;
  45458. }
  45459. bool TreeViewItem::isInterestedInFileDrag (const StringArray&)
  45460. {
  45461. return false;
  45462. }
  45463. void TreeViewItem::filesDropped (const StringArray& /*files*/, int /*insertIndex*/)
  45464. {
  45465. }
  45466. bool TreeViewItem::isInterestedInDragSource (const String& /*sourceDescription*/, Component* /*sourceComponent*/)
  45467. {
  45468. return false;
  45469. }
  45470. void TreeViewItem::itemDropped (const String& /*sourceDescription*/, Component* /*sourceComponent*/, int /*insertIndex*/)
  45471. {
  45472. }
  45473. const Rectangle<int> TreeViewItem::getItemPosition (const bool relativeToTreeViewTopLeft) const throw()
  45474. {
  45475. const int indentX = getIndentX();
  45476. int width = itemWidth;
  45477. if (ownerView != 0 && width < 0)
  45478. width = ownerView->viewport->getViewWidth() - indentX;
  45479. Rectangle<int> r (indentX, y, jmax (0, width), totalHeight);
  45480. if (relativeToTreeViewTopLeft)
  45481. r.setPosition (r.getX() - ownerView->viewport->getViewPositionX(),
  45482. r.getY() - ownerView->viewport->getViewPositionY());
  45483. return r;
  45484. }
  45485. void TreeViewItem::treeHasChanged() const throw()
  45486. {
  45487. if (ownerView != 0)
  45488. ownerView->itemsChanged();
  45489. }
  45490. void TreeViewItem::repaintItem() const
  45491. {
  45492. if (ownerView != 0 && areAllParentsOpen())
  45493. {
  45494. const Rectangle<int> r (getItemPosition (true));
  45495. ownerView->viewport->repaint (0, r.getY(), r.getRight(), r.getHeight());
  45496. }
  45497. }
  45498. bool TreeViewItem::areAllParentsOpen() const throw()
  45499. {
  45500. return parentItem == 0
  45501. || (parentItem->isOpen() && parentItem->areAllParentsOpen());
  45502. }
  45503. void TreeViewItem::updatePositions (int newY)
  45504. {
  45505. y = newY;
  45506. itemHeight = getItemHeight();
  45507. totalHeight = itemHeight;
  45508. itemWidth = getItemWidth();
  45509. totalWidth = jmax (itemWidth, 0) + getIndentX();
  45510. if (isOpen())
  45511. {
  45512. newY += totalHeight;
  45513. for (int i = 0; i < subItems.size(); ++i)
  45514. {
  45515. TreeViewItem* const ti = subItems.getUnchecked(i);
  45516. ti->updatePositions (newY);
  45517. newY += ti->totalHeight;
  45518. totalHeight += ti->totalHeight;
  45519. totalWidth = jmax (totalWidth, ti->totalWidth);
  45520. }
  45521. }
  45522. }
  45523. TreeViewItem* TreeViewItem::getDeepestOpenParentItem() throw()
  45524. {
  45525. TreeViewItem* result = this;
  45526. TreeViewItem* item = this;
  45527. while (item->parentItem != 0)
  45528. {
  45529. item = item->parentItem;
  45530. if (! item->isOpen())
  45531. result = item;
  45532. }
  45533. return result;
  45534. }
  45535. void TreeViewItem::setOwnerView (TreeView* const newOwner) throw()
  45536. {
  45537. ownerView = newOwner;
  45538. for (int i = subItems.size(); --i >= 0;)
  45539. subItems.getUnchecked(i)->setOwnerView (newOwner);
  45540. }
  45541. int TreeViewItem::getIndentX() const throw()
  45542. {
  45543. const int indentWidth = ownerView->getIndentSize();
  45544. int x = ownerView->rootItemVisible ? indentWidth : 0;
  45545. if (! ownerView->openCloseButtonsVisible)
  45546. x -= indentWidth;
  45547. TreeViewItem* p = parentItem;
  45548. while (p != 0)
  45549. {
  45550. x += indentWidth;
  45551. p = p->parentItem;
  45552. }
  45553. return x;
  45554. }
  45555. void TreeViewItem::setDrawsInLeftMargin (bool canDrawInLeftMargin) throw()
  45556. {
  45557. drawsInLeftMargin = canDrawInLeftMargin;
  45558. }
  45559. void TreeViewItem::paintRecursively (Graphics& g, int width)
  45560. {
  45561. jassert (ownerView != 0);
  45562. if (ownerView == 0)
  45563. return;
  45564. const int indent = getIndentX();
  45565. const int itemW = itemWidth < 0 ? width - indent : itemWidth;
  45566. g.setColour (ownerView->findColour (TreeView::linesColourId));
  45567. const float halfH = itemHeight * 0.5f;
  45568. int depth = 0;
  45569. TreeViewItem* p = parentItem;
  45570. while (p != 0)
  45571. {
  45572. ++depth;
  45573. p = p->parentItem;
  45574. }
  45575. if (! ownerView->rootItemVisible)
  45576. --depth;
  45577. const int indentWidth = ownerView->getIndentSize();
  45578. if (depth >= 0 && ownerView->openCloseButtonsVisible)
  45579. {
  45580. float x = (depth + 0.5f) * indentWidth;
  45581. if (depth >= 0)
  45582. {
  45583. if (parentItem != 0 && parentItem->drawLinesInside)
  45584. g.drawLine (x, 0, x, isLastOfSiblings() ? halfH : (float) itemHeight);
  45585. if ((parentItem != 0 && parentItem->drawLinesInside)
  45586. || (parentItem == 0 && drawLinesInside))
  45587. g.drawLine (x, halfH, x + indentWidth / 2, halfH);
  45588. }
  45589. p = parentItem;
  45590. int d = depth;
  45591. while (p != 0 && --d >= 0)
  45592. {
  45593. x -= (float) indentWidth;
  45594. if ((p->parentItem == 0 || p->parentItem->drawLinesInside)
  45595. && ! p->isLastOfSiblings())
  45596. {
  45597. g.drawLine (x, 0, x, (float) itemHeight);
  45598. }
  45599. p = p->parentItem;
  45600. }
  45601. if (mightContainSubItems())
  45602. {
  45603. g.saveState();
  45604. g.setOrigin (depth * indentWidth, 0);
  45605. g.reduceClipRegion (0, 0, indentWidth, itemHeight);
  45606. paintOpenCloseButton (g, indentWidth, itemHeight,
  45607. ((TreeViewContentComponent*) ownerView->viewport->getViewedComponent())
  45608. ->isMouseOverButton (this));
  45609. g.restoreState();
  45610. }
  45611. }
  45612. {
  45613. g.saveState();
  45614. g.setOrigin (indent, 0);
  45615. if (g.reduceClipRegion (drawsInLeftMargin ? -indent : 0, 0,
  45616. drawsInLeftMargin ? itemW + indent : itemW, itemHeight))
  45617. paintItem (g, itemW, itemHeight);
  45618. g.restoreState();
  45619. }
  45620. if (isOpen())
  45621. {
  45622. const Rectangle<int> clip (g.getClipBounds());
  45623. for (int i = 0; i < subItems.size(); ++i)
  45624. {
  45625. TreeViewItem* const ti = subItems.getUnchecked(i);
  45626. const int relY = ti->y - y;
  45627. if (relY >= clip.getBottom())
  45628. break;
  45629. if (relY + ti->totalHeight >= clip.getY())
  45630. {
  45631. g.saveState();
  45632. g.setOrigin (0, relY);
  45633. if (g.reduceClipRegion (0, 0, width, ti->totalHeight))
  45634. ti->paintRecursively (g, width);
  45635. g.restoreState();
  45636. }
  45637. }
  45638. }
  45639. }
  45640. bool TreeViewItem::isLastOfSiblings() const throw()
  45641. {
  45642. return parentItem == 0
  45643. || parentItem->subItems.getLast() == this;
  45644. }
  45645. int TreeViewItem::getIndexInParent() const throw()
  45646. {
  45647. if (parentItem == 0)
  45648. return 0;
  45649. return parentItem->subItems.indexOf (this);
  45650. }
  45651. TreeViewItem* TreeViewItem::getTopLevelItem() throw()
  45652. {
  45653. return (parentItem == 0) ? this
  45654. : parentItem->getTopLevelItem();
  45655. }
  45656. int TreeViewItem::getNumRows() const throw()
  45657. {
  45658. int num = 1;
  45659. if (isOpen())
  45660. {
  45661. for (int i = subItems.size(); --i >= 0;)
  45662. num += subItems.getUnchecked(i)->getNumRows();
  45663. }
  45664. return num;
  45665. }
  45666. TreeViewItem* TreeViewItem::getItemOnRow (int index) throw()
  45667. {
  45668. if (index == 0)
  45669. return this;
  45670. if (index > 0 && isOpen())
  45671. {
  45672. --index;
  45673. for (int i = 0; i < subItems.size(); ++i)
  45674. {
  45675. TreeViewItem* const item = subItems.getUnchecked(i);
  45676. if (index == 0)
  45677. return item;
  45678. const int numRows = item->getNumRows();
  45679. if (numRows > index)
  45680. return item->getItemOnRow (index);
  45681. index -= numRows;
  45682. }
  45683. }
  45684. return 0;
  45685. }
  45686. TreeViewItem* TreeViewItem::findItemRecursively (int targetY) throw()
  45687. {
  45688. if (((unsigned int) targetY) < (unsigned int) totalHeight)
  45689. {
  45690. const int h = itemHeight;
  45691. if (targetY < h)
  45692. return this;
  45693. if (isOpen())
  45694. {
  45695. targetY -= h;
  45696. for (int i = 0; i < subItems.size(); ++i)
  45697. {
  45698. TreeViewItem* const ti = subItems.getUnchecked(i);
  45699. if (targetY < ti->totalHeight)
  45700. return ti->findItemRecursively (targetY);
  45701. targetY -= ti->totalHeight;
  45702. }
  45703. }
  45704. }
  45705. return 0;
  45706. }
  45707. int TreeViewItem::countSelectedItemsRecursively() const throw()
  45708. {
  45709. int total = 0;
  45710. if (isSelected())
  45711. ++total;
  45712. for (int i = subItems.size(); --i >= 0;)
  45713. total += subItems.getUnchecked(i)->countSelectedItemsRecursively();
  45714. return total;
  45715. }
  45716. TreeViewItem* TreeViewItem::getSelectedItemWithIndex (int index) throw()
  45717. {
  45718. if (isSelected())
  45719. {
  45720. if (index == 0)
  45721. return this;
  45722. --index;
  45723. }
  45724. if (index >= 0)
  45725. {
  45726. for (int i = 0; i < subItems.size(); ++i)
  45727. {
  45728. TreeViewItem* const item = subItems.getUnchecked(i);
  45729. TreeViewItem* const found = item->getSelectedItemWithIndex (index);
  45730. if (found != 0)
  45731. return found;
  45732. index -= item->countSelectedItemsRecursively();
  45733. }
  45734. }
  45735. return 0;
  45736. }
  45737. int TreeViewItem::getRowNumberInTree() const throw()
  45738. {
  45739. if (parentItem != 0 && ownerView != 0)
  45740. {
  45741. int n = 1 + parentItem->getRowNumberInTree();
  45742. int ourIndex = parentItem->subItems.indexOf (this);
  45743. jassert (ourIndex >= 0);
  45744. while (--ourIndex >= 0)
  45745. n += parentItem->subItems [ourIndex]->getNumRows();
  45746. if (parentItem->parentItem == 0
  45747. && ! ownerView->rootItemVisible)
  45748. --n;
  45749. return n;
  45750. }
  45751. else
  45752. {
  45753. return 0;
  45754. }
  45755. }
  45756. void TreeViewItem::setLinesDrawnForSubItems (const bool drawLines) throw()
  45757. {
  45758. drawLinesInside = drawLines;
  45759. }
  45760. TreeViewItem* TreeViewItem::getNextVisibleItem (const bool recurse) const throw()
  45761. {
  45762. if (recurse && isOpen() && subItems.size() > 0)
  45763. return subItems [0];
  45764. if (parentItem != 0)
  45765. {
  45766. const int nextIndex = parentItem->subItems.indexOf (this) + 1;
  45767. if (nextIndex >= parentItem->subItems.size())
  45768. return parentItem->getNextVisibleItem (false);
  45769. return parentItem->subItems [nextIndex];
  45770. }
  45771. return 0;
  45772. }
  45773. const String TreeViewItem::getItemIdentifierString() const
  45774. {
  45775. String s;
  45776. if (parentItem != 0)
  45777. s = parentItem->getItemIdentifierString();
  45778. return s + T("/") + getUniqueName().replaceCharacter (T('/'), T('\\'));
  45779. }
  45780. TreeViewItem* TreeViewItem::findItemFromIdentifierString (const String& identifierString)
  45781. {
  45782. const String uid (getUniqueName());
  45783. if (uid == identifierString)
  45784. return this;
  45785. if (identifierString.startsWith (uid + T("/")))
  45786. {
  45787. const String remainingPath (identifierString.substring (uid.length() + 1));
  45788. bool wasOpen = isOpen();
  45789. setOpen (true);
  45790. for (int i = subItems.size(); --i >= 0;)
  45791. {
  45792. TreeViewItem* item = subItems.getUnchecked(i)->findItemFromIdentifierString (remainingPath);
  45793. if (item != 0)
  45794. return item;
  45795. }
  45796. setOpen (wasOpen);
  45797. }
  45798. return 0;
  45799. }
  45800. void TreeViewItem::restoreOpennessState (const XmlElement& e) throw()
  45801. {
  45802. if (e.hasTagName (T("CLOSED")))
  45803. {
  45804. setOpen (false);
  45805. }
  45806. else if (e.hasTagName (T("OPEN")))
  45807. {
  45808. setOpen (true);
  45809. forEachXmlChildElement (e, n)
  45810. {
  45811. const String id (n->getStringAttribute (T("id")));
  45812. for (int i = 0; i < subItems.size(); ++i)
  45813. {
  45814. TreeViewItem* const ti = subItems.getUnchecked(i);
  45815. if (ti->getUniqueName() == id)
  45816. {
  45817. ti->restoreOpennessState (*n);
  45818. break;
  45819. }
  45820. }
  45821. }
  45822. }
  45823. }
  45824. XmlElement* TreeViewItem::getOpennessState() const throw()
  45825. {
  45826. const String name (getUniqueName());
  45827. if (name.isNotEmpty())
  45828. {
  45829. XmlElement* e;
  45830. if (isOpen())
  45831. {
  45832. e = new XmlElement (T("OPEN"));
  45833. for (int i = 0; i < subItems.size(); ++i)
  45834. e->addChildElement (subItems.getUnchecked(i)->getOpennessState());
  45835. }
  45836. else
  45837. {
  45838. e = new XmlElement (T("CLOSED"));
  45839. }
  45840. e->setAttribute (T("id"), name);
  45841. return e;
  45842. }
  45843. else
  45844. {
  45845. // trying to save the openness for an element that has no name - this won't
  45846. // work because it needs the names to identify what to open.
  45847. jassertfalse
  45848. }
  45849. return 0;
  45850. }
  45851. END_JUCE_NAMESPACE
  45852. /*** End of inlined file: juce_TreeView.cpp ***/
  45853. /*** Start of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45854. BEGIN_JUCE_NAMESPACE
  45855. DirectoryContentsDisplayComponent::DirectoryContentsDisplayComponent (DirectoryContentsList& listToShow)
  45856. : fileList (listToShow)
  45857. {
  45858. }
  45859. DirectoryContentsDisplayComponent::~DirectoryContentsDisplayComponent()
  45860. {
  45861. }
  45862. FileBrowserListener::~FileBrowserListener()
  45863. {
  45864. }
  45865. void DirectoryContentsDisplayComponent::addListener (FileBrowserListener* const listener) throw()
  45866. {
  45867. jassert (listener != 0);
  45868. if (listener != 0)
  45869. listeners.add (listener);
  45870. }
  45871. void DirectoryContentsDisplayComponent::removeListener (FileBrowserListener* const listener) throw()
  45872. {
  45873. listeners.removeValue (listener);
  45874. }
  45875. void DirectoryContentsDisplayComponent::sendSelectionChangeMessage()
  45876. {
  45877. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45878. for (int i = listeners.size(); --i >= 0;)
  45879. {
  45880. ((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged();
  45881. if (deletionWatcher.hasBeenDeleted())
  45882. return;
  45883. i = jmin (i, listeners.size() - 1);
  45884. }
  45885. }
  45886. void DirectoryContentsDisplayComponent::sendMouseClickMessage (const File& file, const MouseEvent& e)
  45887. {
  45888. if (fileList.getDirectory().exists())
  45889. {
  45890. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45891. for (int i = listeners.size(); --i >= 0;)
  45892. {
  45893. ((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (file, e);
  45894. if (deletionWatcher.hasBeenDeleted())
  45895. return;
  45896. i = jmin (i, listeners.size() - 1);
  45897. }
  45898. }
  45899. }
  45900. void DirectoryContentsDisplayComponent::sendDoubleClickMessage (const File& file)
  45901. {
  45902. if (fileList.getDirectory().exists())
  45903. {
  45904. const ComponentDeletionWatcher deletionWatcher (dynamic_cast <Component*> (this));
  45905. for (int i = listeners.size(); --i >= 0;)
  45906. {
  45907. ((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (file);
  45908. if (deletionWatcher.hasBeenDeleted())
  45909. return;
  45910. i = jmin (i, listeners.size() - 1);
  45911. }
  45912. }
  45913. }
  45914. END_JUCE_NAMESPACE
  45915. /*** End of inlined file: juce_DirectoryContentsDisplayComponent.cpp ***/
  45916. /*** Start of inlined file: juce_DirectoryContentsList.cpp ***/
  45917. BEGIN_JUCE_NAMESPACE
  45918. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  45919. bool* isDirectory, bool* isHidden, int64* fileSize, Time* modTime,
  45920. Time* creationTime, bool* isReadOnly);
  45921. bool juce_findFileNext (void* handle, String& resultFile,
  45922. bool* isDirectory, bool* isHidden, int64* fileSize,
  45923. Time* modTime, Time* creationTime, bool* isReadOnly);
  45924. void juce_findFileClose (void* handle);
  45925. DirectoryContentsList::DirectoryContentsList (const FileFilter* const fileFilter_,
  45926. TimeSliceThread& thread_)
  45927. : fileFilter (fileFilter_),
  45928. thread (thread_),
  45929. includeDirectories (false),
  45930. includeFiles (false),
  45931. ignoreHiddenFiles (true),
  45932. fileFindHandle (0),
  45933. shouldStop (true)
  45934. {
  45935. }
  45936. DirectoryContentsList::~DirectoryContentsList()
  45937. {
  45938. clear();
  45939. }
  45940. void DirectoryContentsList::setIgnoresHiddenFiles (const bool shouldIgnoreHiddenFiles)
  45941. {
  45942. ignoreHiddenFiles = shouldIgnoreHiddenFiles;
  45943. }
  45944. const File& DirectoryContentsList::getDirectory() const
  45945. {
  45946. return root;
  45947. }
  45948. void DirectoryContentsList::setDirectory (const File& directory,
  45949. const bool includeDirectories_,
  45950. const bool includeFiles_)
  45951. {
  45952. if (directory != root
  45953. || includeDirectories != includeDirectories_
  45954. || includeFiles != includeFiles_)
  45955. {
  45956. clear();
  45957. root = directory;
  45958. includeDirectories = includeDirectories_;
  45959. includeFiles = includeFiles_;
  45960. refresh();
  45961. }
  45962. }
  45963. void DirectoryContentsList::clear()
  45964. {
  45965. shouldStop = true;
  45966. thread.removeTimeSliceClient (this);
  45967. if (fileFindHandle != 0)
  45968. {
  45969. juce_findFileClose (fileFindHandle);
  45970. fileFindHandle = 0;
  45971. }
  45972. if (files.size() > 0)
  45973. {
  45974. files.clear();
  45975. changed();
  45976. }
  45977. }
  45978. void DirectoryContentsList::refresh()
  45979. {
  45980. clear();
  45981. if (root.isDirectory())
  45982. {
  45983. String fileFound;
  45984. bool fileFoundIsDir, isHidden, isReadOnly;
  45985. int64 fileSize;
  45986. Time modTime, creationTime;
  45987. String path (root.getFullPathName());
  45988. if (! path.endsWithChar (File::separator))
  45989. path += File::separator;
  45990. jassert (fileFindHandle == 0);
  45991. fileFindHandle = juce_findFileStart (path, T("*"), fileFound,
  45992. &fileFoundIsDir,
  45993. &isHidden,
  45994. &fileSize,
  45995. &modTime,
  45996. &creationTime,
  45997. &isReadOnly);
  45998. if (fileFindHandle != 0 && fileFound.isNotEmpty())
  45999. {
  46000. if (addFile (fileFound, fileFoundIsDir, isHidden,
  46001. fileSize, modTime, creationTime, isReadOnly))
  46002. {
  46003. changed();
  46004. }
  46005. }
  46006. shouldStop = false;
  46007. thread.addTimeSliceClient (this);
  46008. }
  46009. }
  46010. int DirectoryContentsList::getNumFiles() const
  46011. {
  46012. return files.size();
  46013. }
  46014. bool DirectoryContentsList::getFileInfo (const int index,
  46015. FileInfo& result) const
  46016. {
  46017. const ScopedLock sl (fileListLock);
  46018. const FileInfo* const info = files [index];
  46019. if (info != 0)
  46020. {
  46021. result = *info;
  46022. return true;
  46023. }
  46024. return false;
  46025. }
  46026. const File DirectoryContentsList::getFile (const int index) const
  46027. {
  46028. const ScopedLock sl (fileListLock);
  46029. const FileInfo* const info = files [index];
  46030. if (info != 0)
  46031. return root.getChildFile (info->filename);
  46032. return File::nonexistent;
  46033. }
  46034. bool DirectoryContentsList::isStillLoading() const
  46035. {
  46036. return fileFindHandle != 0;
  46037. }
  46038. void DirectoryContentsList::changed()
  46039. {
  46040. sendChangeMessage (this);
  46041. }
  46042. bool DirectoryContentsList::useTimeSlice()
  46043. {
  46044. const uint32 startTime = Time::getApproximateMillisecondCounter();
  46045. bool hasChanged = false;
  46046. for (int i = 100; --i >= 0;)
  46047. {
  46048. if (! checkNextFile (hasChanged))
  46049. {
  46050. if (hasChanged)
  46051. changed();
  46052. return false;
  46053. }
  46054. if (shouldStop || (Time::getApproximateMillisecondCounter() > startTime + 150))
  46055. break;
  46056. }
  46057. if (hasChanged)
  46058. changed();
  46059. return true;
  46060. }
  46061. bool DirectoryContentsList::checkNextFile (bool& hasChanged)
  46062. {
  46063. if (fileFindHandle != 0)
  46064. {
  46065. String fileFound;
  46066. bool fileFoundIsDir, isHidden, isReadOnly;
  46067. int64 fileSize;
  46068. Time modTime, creationTime;
  46069. if (juce_findFileNext (fileFindHandle, fileFound,
  46070. &fileFoundIsDir, &isHidden,
  46071. &fileSize,
  46072. &modTime,
  46073. &creationTime,
  46074. &isReadOnly))
  46075. {
  46076. if (addFile (fileFound, fileFoundIsDir, isHidden, fileSize,
  46077. modTime, creationTime, isReadOnly))
  46078. {
  46079. hasChanged = true;
  46080. }
  46081. return true;
  46082. }
  46083. else
  46084. {
  46085. juce_findFileClose (fileFindHandle);
  46086. fileFindHandle = 0;
  46087. }
  46088. }
  46089. return false;
  46090. }
  46091. int DirectoryContentsList::compareElements (const DirectoryContentsList::FileInfo* const first,
  46092. const DirectoryContentsList::FileInfo* const second)
  46093. {
  46094. #if JUCE_WINDOWS
  46095. if (first->isDirectory != second->isDirectory)
  46096. return first->isDirectory ? -1 : 1;
  46097. #endif
  46098. return first->filename.compareIgnoreCase (second->filename);
  46099. }
  46100. bool DirectoryContentsList::addFile (const String& filename,
  46101. const bool isDir,
  46102. const bool isHidden,
  46103. const int64 fileSize,
  46104. const Time& modTime,
  46105. const Time& creationTime,
  46106. const bool isReadOnly)
  46107. {
  46108. if (filename == T("..")
  46109. || filename == T(".")
  46110. || (ignoreHiddenFiles && isHidden))
  46111. return false;
  46112. const File file (root.getChildFile (filename));
  46113. if (((isDir && includeDirectories) || ((! isDir) && includeFiles))
  46114. && (fileFilter == 0
  46115. || ((! isDir) && fileFilter->isFileSuitable (file))
  46116. || (isDir && fileFilter->isDirectorySuitable (file))))
  46117. {
  46118. ScopedPointer <FileInfo> info (new FileInfo());
  46119. info->filename = filename;
  46120. info->fileSize = fileSize;
  46121. info->modificationTime = modTime;
  46122. info->creationTime = creationTime;
  46123. info->isDirectory = isDir;
  46124. info->isReadOnly = isReadOnly;
  46125. const ScopedLock sl (fileListLock);
  46126. for (int i = files.size(); --i >= 0;)
  46127. if (files.getUnchecked(i)->filename == info->filename)
  46128. return false;
  46129. files.addSorted (*this, info.release());
  46130. return true;
  46131. }
  46132. return false;
  46133. }
  46134. END_JUCE_NAMESPACE
  46135. /*** End of inlined file: juce_DirectoryContentsList.cpp ***/
  46136. /*** Start of inlined file: juce_FileBrowserComponent.cpp ***/
  46137. BEGIN_JUCE_NAMESPACE
  46138. FileBrowserComponent::FileBrowserComponent (int flags_,
  46139. const File& initialFileOrDirectory,
  46140. const FileFilter* fileFilter_,
  46141. FilePreviewComponent* previewComp_)
  46142. : FileFilter (String::empty),
  46143. fileFilter (fileFilter_),
  46144. flags (flags_),
  46145. previewComp (previewComp_),
  46146. thread ("Juce FileBrowser")
  46147. {
  46148. // You need to specify one or other of the open/save flags..
  46149. jassert ((flags & (saveMode | openMode)) != 0);
  46150. jassert ((flags & (saveMode | openMode)) != (saveMode | openMode));
  46151. // You need to specify at least one of these flags..
  46152. jassert ((flags & (canSelectFiles | canSelectDirectories)) != 0);
  46153. String filename;
  46154. if (initialFileOrDirectory == File::nonexistent)
  46155. {
  46156. currentRoot = File::getCurrentWorkingDirectory();
  46157. }
  46158. else if (initialFileOrDirectory.isDirectory())
  46159. {
  46160. currentRoot = initialFileOrDirectory;
  46161. }
  46162. else
  46163. {
  46164. chosenFiles.add (initialFileOrDirectory);
  46165. currentRoot = initialFileOrDirectory.getParentDirectory();
  46166. filename = initialFileOrDirectory.getFileName();
  46167. }
  46168. fileList = new DirectoryContentsList (this, thread);
  46169. if ((flags & useTreeView) != 0)
  46170. {
  46171. FileTreeComponent* const tree = new FileTreeComponent (*fileList);
  46172. if ((flags & canSelectMultipleItems) != 0)
  46173. tree->setMultiSelectEnabled (true);
  46174. addAndMakeVisible (tree);
  46175. fileListComponent = tree;
  46176. }
  46177. else
  46178. {
  46179. FileListComponent* const list = new FileListComponent (*fileList);
  46180. list->setOutlineThickness (1);
  46181. if ((flags & canSelectMultipleItems) != 0)
  46182. list->setMultipleSelectionEnabled (true);
  46183. addAndMakeVisible (list);
  46184. fileListComponent = list;
  46185. }
  46186. fileListComponent->addListener (this);
  46187. addAndMakeVisible (currentPathBox = new ComboBox ("path"));
  46188. currentPathBox->setEditableText (true);
  46189. StringArray rootNames, rootPaths;
  46190. const BitArray separators (getRoots (rootNames, rootPaths));
  46191. for (int i = 0; i < rootNames.size(); ++i)
  46192. {
  46193. if (separators [i])
  46194. currentPathBox->addSeparator();
  46195. currentPathBox->addItem (rootNames[i], i + 1);
  46196. }
  46197. currentPathBox->addSeparator();
  46198. currentPathBox->addListener (this);
  46199. addAndMakeVisible (filenameBox = new TextEditor());
  46200. filenameBox->setMultiLine (false);
  46201. filenameBox->setSelectAllWhenFocused (true);
  46202. filenameBox->setText (filename, false);
  46203. filenameBox->addListener (this);
  46204. filenameBox->setReadOnly ((flags & (filenameBoxIsReadOnly | canSelectMultipleItems)) != 0);
  46205. Label* label = new Label ("f", TRANS("file:"));
  46206. addAndMakeVisible (label);
  46207. label->attachToComponent (filenameBox, true);
  46208. addAndMakeVisible (goUpButton = getLookAndFeel().createFileBrowserGoUpButton());
  46209. goUpButton->addButtonListener (this);
  46210. goUpButton->setTooltip (TRANS ("go up to parent directory"));
  46211. if (previewComp != 0)
  46212. addAndMakeVisible (previewComp);
  46213. setRoot (currentRoot);
  46214. thread.startThread (4);
  46215. }
  46216. FileBrowserComponent::~FileBrowserComponent()
  46217. {
  46218. if (previewComp != 0)
  46219. removeChildComponent (previewComp);
  46220. deleteAllChildren();
  46221. fileList = 0;
  46222. thread.stopThread (10000);
  46223. }
  46224. void FileBrowserComponent::addListener (FileBrowserListener* const newListener) throw()
  46225. {
  46226. jassert (newListener != 0)
  46227. if (newListener != 0)
  46228. listeners.add (newListener);
  46229. }
  46230. void FileBrowserComponent::removeListener (FileBrowserListener* const listener) throw()
  46231. {
  46232. listeners.removeValue (listener);
  46233. }
  46234. bool FileBrowserComponent::isSaveMode() const throw()
  46235. {
  46236. return (flags & saveMode) != 0;
  46237. }
  46238. int FileBrowserComponent::getNumSelectedFiles() const throw()
  46239. {
  46240. if (chosenFiles.size() == 0 && currentFileIsValid())
  46241. return 1;
  46242. return chosenFiles.size();
  46243. }
  46244. const File FileBrowserComponent::getSelectedFile (int index) const throw()
  46245. {
  46246. if (! filenameBox->isReadOnly())
  46247. return currentRoot.getChildFile (filenameBox->getText());
  46248. else
  46249. return chosenFiles[index];
  46250. }
  46251. bool FileBrowserComponent::currentFileIsValid() const
  46252. {
  46253. if (isSaveMode())
  46254. return ! getSelectedFile (0).isDirectory();
  46255. else
  46256. return getSelectedFile (0).exists();
  46257. }
  46258. const File FileBrowserComponent::getHighlightedFile() const throw()
  46259. {
  46260. return fileListComponent->getSelectedFile (0);
  46261. }
  46262. bool FileBrowserComponent::isFileSuitable (const File& file) const
  46263. {
  46264. return (flags & canSelectFiles) != 0 ? (fileFilter == 0 || fileFilter->isFileSuitable (file))
  46265. : false;
  46266. }
  46267. bool FileBrowserComponent::isDirectorySuitable (const File&) const
  46268. {
  46269. return true;
  46270. }
  46271. bool FileBrowserComponent::isFileOrDirSuitable (const File& f) const
  46272. {
  46273. if (f.isDirectory())
  46274. return (flags & canSelectDirectories) != 0 && (fileFilter == 0 || fileFilter->isDirectorySuitable (f));
  46275. return (flags & canSelectFiles) != 0 && f.exists()
  46276. && (fileFilter == 0 || fileFilter->isFileSuitable (f));
  46277. }
  46278. const File FileBrowserComponent::getRoot() const
  46279. {
  46280. return currentRoot;
  46281. }
  46282. void FileBrowserComponent::setRoot (const File& newRootDirectory)
  46283. {
  46284. if (currentRoot != newRootDirectory)
  46285. {
  46286. fileListComponent->scrollToTop();
  46287. String path (newRootDirectory.getFullPathName());
  46288. if (path.isEmpty())
  46289. path += File::separator;
  46290. StringArray rootNames, rootPaths;
  46291. getRoots (rootNames, rootPaths);
  46292. if (! rootPaths.contains (path, true))
  46293. {
  46294. bool alreadyListed = false;
  46295. for (int i = currentPathBox->getNumItems(); --i >= 0;)
  46296. {
  46297. if (currentPathBox->getItemText (i).equalsIgnoreCase (path))
  46298. {
  46299. alreadyListed = true;
  46300. break;
  46301. }
  46302. }
  46303. if (! alreadyListed)
  46304. currentPathBox->addItem (path, currentPathBox->getNumItems() + 2);
  46305. }
  46306. }
  46307. currentRoot = newRootDirectory;
  46308. fileList->setDirectory (currentRoot, true, true);
  46309. String currentRootName (currentRoot.getFullPathName());
  46310. if (currentRootName.isEmpty())
  46311. currentRootName += File::separator;
  46312. currentPathBox->setText (currentRootName, true);
  46313. goUpButton->setEnabled (currentRoot.getParentDirectory().isDirectory()
  46314. && currentRoot.getParentDirectory() != currentRoot);
  46315. }
  46316. void FileBrowserComponent::goUp()
  46317. {
  46318. setRoot (getRoot().getParentDirectory());
  46319. }
  46320. void FileBrowserComponent::refresh()
  46321. {
  46322. fileList->refresh();
  46323. }
  46324. const String FileBrowserComponent::getActionVerb() const
  46325. {
  46326. return isSaveMode() ? TRANS("Save") : TRANS("Open");
  46327. }
  46328. FilePreviewComponent* FileBrowserComponent::getPreviewComponent() const throw()
  46329. {
  46330. return previewComp;
  46331. }
  46332. void FileBrowserComponent::resized()
  46333. {
  46334. getLookAndFeel()
  46335. .layoutFileBrowserComponent (*this, fileListComponent,
  46336. previewComp, currentPathBox,
  46337. filenameBox, goUpButton);
  46338. }
  46339. void FileBrowserComponent::sendListenerChangeMessage()
  46340. {
  46341. ComponentDeletionWatcher deletionWatcher (this);
  46342. if (previewComp != 0)
  46343. previewComp->selectedFileChanged (getSelectedFile (0));
  46344. jassert (! deletionWatcher.hasBeenDeleted());
  46345. for (int i = listeners.size(); --i >= 0;)
  46346. {
  46347. ((FileBrowserListener*) listeners.getUnchecked (i))->selectionChanged();
  46348. if (deletionWatcher.hasBeenDeleted())
  46349. return;
  46350. i = jmin (i, listeners.size() - 1);
  46351. }
  46352. }
  46353. void FileBrowserComponent::selectionChanged()
  46354. {
  46355. StringArray newFilenames;
  46356. bool resetChosenFiles = true;
  46357. for (int i = 0; i < fileListComponent->getNumSelectedFiles(); ++i)
  46358. {
  46359. const File f (fileListComponent->getSelectedFile (i));
  46360. if (isFileOrDirSuitable (f))
  46361. {
  46362. if (resetChosenFiles)
  46363. {
  46364. chosenFiles.clear();
  46365. resetChosenFiles = false;
  46366. }
  46367. chosenFiles.add (f);
  46368. newFilenames.add (f.getRelativePathFrom (getRoot()));
  46369. }
  46370. }
  46371. if (newFilenames.size() > 0)
  46372. filenameBox->setText (newFilenames.joinIntoString (T(", ")), false);
  46373. sendListenerChangeMessage();
  46374. }
  46375. void FileBrowserComponent::fileClicked (const File& f, const MouseEvent& e)
  46376. {
  46377. ComponentDeletionWatcher deletionWatcher (this);
  46378. for (int i = listeners.size(); --i >= 0;)
  46379. {
  46380. ((FileBrowserListener*) listeners.getUnchecked (i))->fileClicked (f, e);
  46381. if (deletionWatcher.hasBeenDeleted())
  46382. return;
  46383. i = jmin (i, listeners.size() - 1);
  46384. }
  46385. }
  46386. void FileBrowserComponent::fileDoubleClicked (const File& f)
  46387. {
  46388. if (f.isDirectory())
  46389. {
  46390. setRoot (f);
  46391. }
  46392. else
  46393. {
  46394. ComponentDeletionWatcher deletionWatcher (this);
  46395. for (int i = listeners.size(); --i >= 0;)
  46396. {
  46397. ((FileBrowserListener*) listeners.getUnchecked (i))->fileDoubleClicked (f);
  46398. if (deletionWatcher.hasBeenDeleted())
  46399. return;
  46400. i = jmin (i, listeners.size() - 1);
  46401. }
  46402. }
  46403. }
  46404. bool FileBrowserComponent::keyPressed (const KeyPress& key)
  46405. {
  46406. #if JUCE_LINUX || JUCE_WINDOWS
  46407. if (key.getModifiers().isCommandDown()
  46408. && (key.getKeyCode() == 'H' || key.getKeyCode() == 'h'))
  46409. {
  46410. fileList->setIgnoresHiddenFiles (! fileList->ignoresHiddenFiles());
  46411. fileList->refresh();
  46412. return true;
  46413. }
  46414. #endif
  46415. return false;
  46416. }
  46417. void FileBrowserComponent::textEditorTextChanged (TextEditor&)
  46418. {
  46419. sendListenerChangeMessage();
  46420. }
  46421. void FileBrowserComponent::textEditorReturnKeyPressed (TextEditor&)
  46422. {
  46423. if (filenameBox->getText().containsChar (File::separator))
  46424. {
  46425. const File f (currentRoot.getChildFile (filenameBox->getText()));
  46426. if (f.isDirectory())
  46427. {
  46428. setRoot (f);
  46429. chosenFiles.clear();
  46430. filenameBox->setText (String::empty);
  46431. }
  46432. else
  46433. {
  46434. setRoot (f.getParentDirectory());
  46435. chosenFiles.clear();
  46436. chosenFiles.add (f);
  46437. filenameBox->setText (f.getFileName());
  46438. }
  46439. }
  46440. else
  46441. {
  46442. fileDoubleClicked (getSelectedFile (0));
  46443. }
  46444. }
  46445. void FileBrowserComponent::textEditorEscapeKeyPressed (TextEditor&)
  46446. {
  46447. }
  46448. void FileBrowserComponent::textEditorFocusLost (TextEditor&)
  46449. {
  46450. if (! isSaveMode())
  46451. selectionChanged();
  46452. }
  46453. void FileBrowserComponent::buttonClicked (Button*)
  46454. {
  46455. goUp();
  46456. }
  46457. void FileBrowserComponent::comboBoxChanged (ComboBox*)
  46458. {
  46459. const String newText (currentPathBox->getText().trim().unquoted());
  46460. if (newText.isNotEmpty())
  46461. {
  46462. const int index = currentPathBox->getSelectedId() - 1;
  46463. StringArray rootNames, rootPaths;
  46464. getRoots (rootNames, rootPaths);
  46465. if (rootPaths [index].isNotEmpty())
  46466. {
  46467. setRoot (File (rootPaths [index]));
  46468. }
  46469. else
  46470. {
  46471. File f (newText);
  46472. for (;;)
  46473. {
  46474. if (f.isDirectory())
  46475. {
  46476. setRoot (f);
  46477. break;
  46478. }
  46479. if (f.getParentDirectory() == f)
  46480. break;
  46481. f = f.getParentDirectory();
  46482. }
  46483. }
  46484. }
  46485. }
  46486. const BitArray FileBrowserComponent::getRoots (StringArray& rootNames, StringArray& rootPaths)
  46487. {
  46488. BitArray separators;
  46489. #if JUCE_WINDOWS
  46490. Array<File> roots;
  46491. File::findFileSystemRoots (roots);
  46492. rootPaths.clear();
  46493. for (int i = 0; i < roots.size(); ++i)
  46494. {
  46495. const File& drive = roots.getReference(i);
  46496. String name (drive.getFullPathName());
  46497. rootPaths.add (name);
  46498. if (drive.isOnHardDisk())
  46499. {
  46500. String volume (drive.getVolumeLabel());
  46501. if (volume.isEmpty())
  46502. volume = TRANS("Hard Drive");
  46503. name << " [" << drive.getVolumeLabel() << ']';
  46504. }
  46505. else if (drive.isOnCDRomDrive())
  46506. {
  46507. name << TRANS(" [CD/DVD drive]");
  46508. }
  46509. rootNames.add (name);
  46510. }
  46511. separators.setBit (rootPaths.size());
  46512. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46513. rootNames.add ("Documents");
  46514. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46515. rootNames.add ("Desktop");
  46516. #endif
  46517. #if JUCE_MAC
  46518. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46519. rootNames.add ("Home folder");
  46520. rootPaths.add (File::getSpecialLocation (File::userDocumentsDirectory).getFullPathName());
  46521. rootNames.add ("Documents");
  46522. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46523. rootNames.add ("Desktop");
  46524. separators.setBit (rootPaths.size());
  46525. Array <File> volumes;
  46526. File vol ("/Volumes");
  46527. vol.findChildFiles (volumes, File::findDirectories, false);
  46528. for (int i = 0; i < volumes.size(); ++i)
  46529. {
  46530. const File& volume = volumes.getReference(i);
  46531. if (volume.isDirectory() && ! volume.getFileName().startsWithChar (T('.')))
  46532. {
  46533. rootPaths.add (volume.getFullPathName());
  46534. rootNames.add (volume.getFileName());
  46535. }
  46536. }
  46537. #endif
  46538. #if JUCE_LINUX
  46539. rootPaths.add ("/");
  46540. rootNames.add ("/");
  46541. rootPaths.add (File::getSpecialLocation (File::userHomeDirectory).getFullPathName());
  46542. rootNames.add ("Home folder");
  46543. rootPaths.add (File::getSpecialLocation (File::userDesktopDirectory).getFullPathName());
  46544. rootNames.add ("Desktop");
  46545. #endif
  46546. return separators;
  46547. }
  46548. END_JUCE_NAMESPACE
  46549. /*** End of inlined file: juce_FileBrowserComponent.cpp ***/
  46550. /*** Start of inlined file: juce_FileChooser.cpp ***/
  46551. BEGIN_JUCE_NAMESPACE
  46552. FileChooser::FileChooser (const String& chooserBoxTitle,
  46553. const File& currentFileOrDirectory,
  46554. const String& fileFilters,
  46555. const bool useNativeDialogBox_)
  46556. : title (chooserBoxTitle),
  46557. filters (fileFilters),
  46558. startingFile (currentFileOrDirectory),
  46559. useNativeDialogBox (useNativeDialogBox_)
  46560. {
  46561. #if JUCE_LINUX
  46562. useNativeDialogBox = false;
  46563. #endif
  46564. if (! fileFilters.containsNonWhitespaceChars())
  46565. filters = T("*");
  46566. }
  46567. FileChooser::~FileChooser()
  46568. {
  46569. }
  46570. bool FileChooser::browseForFileToOpen (FilePreviewComponent* previewComponent)
  46571. {
  46572. return showDialog (false, true, false, false, false, previewComponent);
  46573. }
  46574. bool FileChooser::browseForMultipleFilesToOpen (FilePreviewComponent* previewComponent)
  46575. {
  46576. return showDialog (false, true, false, false, true, previewComponent);
  46577. }
  46578. bool FileChooser::browseForMultipleFilesOrDirectories (FilePreviewComponent* previewComponent)
  46579. {
  46580. return showDialog (true, true, false, false, true, previewComponent);
  46581. }
  46582. bool FileChooser::browseForFileToSave (const bool warnAboutOverwritingExistingFiles)
  46583. {
  46584. return showDialog (false, true, true, warnAboutOverwritingExistingFiles, false, 0);
  46585. }
  46586. bool FileChooser::browseForDirectory()
  46587. {
  46588. return showDialog (true, false, false, false, false, 0);
  46589. }
  46590. const File FileChooser::getResult() const
  46591. {
  46592. // if you've used a multiple-file select, you should use the getResults() method
  46593. // to retrieve all the files that were chosen.
  46594. jassert (results.size() <= 1);
  46595. return results.getFirst();
  46596. }
  46597. const Array<File>& FileChooser::getResults() const
  46598. {
  46599. return results;
  46600. }
  46601. bool FileChooser::showDialog (const bool selectsDirectories,
  46602. const bool selectsFiles,
  46603. const bool isSave,
  46604. const bool warnAboutOverwritingExistingFiles,
  46605. const bool selectMultipleFiles,
  46606. FilePreviewComponent* const previewComponent)
  46607. {
  46608. ScopedPointer <ComponentDeletionWatcher> currentlyFocusedChecker;
  46609. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  46610. if (currentlyFocused != 0)
  46611. currentlyFocusedChecker = new ComponentDeletionWatcher (currentlyFocused);
  46612. results.clear();
  46613. // the preview component needs to be the right size before you pass it in here..
  46614. jassert (previewComponent == 0 || (previewComponent->getWidth() > 10
  46615. && previewComponent->getHeight() > 10));
  46616. #if JUCE_WINDOWS
  46617. if (useNativeDialogBox && ! (selectsFiles && selectsDirectories))
  46618. #elif JUCE_MAC
  46619. if (useNativeDialogBox && (previewComponent == 0))
  46620. #else
  46621. if (false)
  46622. #endif
  46623. {
  46624. showPlatformDialog (results, title, startingFile, filters,
  46625. selectsDirectories, selectsFiles, isSave,
  46626. warnAboutOverwritingExistingFiles,
  46627. selectMultipleFiles,
  46628. previewComponent);
  46629. }
  46630. else
  46631. {
  46632. WildcardFileFilter wildcard (selectsFiles ? filters : String::empty,
  46633. selectsDirectories ? "*" : String::empty,
  46634. String::empty);
  46635. int flags = isSave ? FileBrowserComponent::saveMode
  46636. : FileBrowserComponent::openMode;
  46637. if (selectsFiles)
  46638. flags |= FileBrowserComponent::canSelectFiles;
  46639. if (selectsDirectories)
  46640. flags |= FileBrowserComponent::canSelectDirectories;
  46641. if (selectMultipleFiles)
  46642. flags |= FileBrowserComponent::canSelectMultipleItems;
  46643. FileBrowserComponent browserComponent (flags, startingFile, &wildcard, previewComponent);
  46644. FileChooserDialogBox box (title, String::empty,
  46645. browserComponent,
  46646. warnAboutOverwritingExistingFiles,
  46647. browserComponent.findColour (AlertWindow::backgroundColourId));
  46648. if (box.show())
  46649. {
  46650. for (int i = 0; i < browserComponent.getNumSelectedFiles(); ++i)
  46651. results.add (browserComponent.getSelectedFile (i));
  46652. }
  46653. }
  46654. if (currentlyFocused != 0 && ! currentlyFocusedChecker->hasBeenDeleted())
  46655. currentlyFocused->grabKeyboardFocus();
  46656. return results.size() > 0;
  46657. }
  46658. FilePreviewComponent::FilePreviewComponent()
  46659. {
  46660. }
  46661. FilePreviewComponent::~FilePreviewComponent()
  46662. {
  46663. }
  46664. END_JUCE_NAMESPACE
  46665. /*** End of inlined file: juce_FileChooser.cpp ***/
  46666. /*** Start of inlined file: juce_FileChooserDialogBox.cpp ***/
  46667. BEGIN_JUCE_NAMESPACE
  46668. FileChooserDialogBox::FileChooserDialogBox (const String& name,
  46669. const String& instructions,
  46670. FileBrowserComponent& chooserComponent,
  46671. const bool warnAboutOverwritingExistingFiles_,
  46672. const Colour& backgroundColour)
  46673. : ResizableWindow (name, backgroundColour, true),
  46674. warnAboutOverwritingExistingFiles (warnAboutOverwritingExistingFiles_)
  46675. {
  46676. content = new ContentComponent();
  46677. content->setName (name);
  46678. content->instructions = instructions;
  46679. content->chooserComponent = &chooserComponent;
  46680. content->addAndMakeVisible (&chooserComponent);
  46681. content->okButton = new TextButton (chooserComponent.getActionVerb());
  46682. content->addAndMakeVisible (content->okButton);
  46683. content->okButton->addButtonListener (this);
  46684. content->okButton->setEnabled (chooserComponent.currentFileIsValid());
  46685. content->okButton->addShortcut (KeyPress (KeyPress::returnKey, 0, 0));
  46686. content->cancelButton = new TextButton (TRANS("Cancel"));
  46687. content->addAndMakeVisible (content->cancelButton);
  46688. content->cancelButton->addButtonListener (this);
  46689. content->cancelButton->addShortcut (KeyPress (KeyPress::escapeKey, 0, 0));
  46690. setContentComponent (content);
  46691. setResizable (true, true);
  46692. setResizeLimits (300, 300, 1200, 1000);
  46693. content->chooserComponent->addListener (this);
  46694. }
  46695. FileChooserDialogBox::~FileChooserDialogBox()
  46696. {
  46697. content->chooserComponent->removeListener (this);
  46698. }
  46699. bool FileChooserDialogBox::show (int w, int h)
  46700. {
  46701. if (w <= 0)
  46702. {
  46703. Component* const previewComp = content->chooserComponent->getPreviewComponent();
  46704. if (previewComp != 0)
  46705. w = 400 + previewComp->getWidth();
  46706. else
  46707. w = 600;
  46708. }
  46709. if (h <= 0)
  46710. h = 500;
  46711. centreWithSize (w, h);
  46712. const bool ok = (runModalLoop() != 0);
  46713. setVisible (false);
  46714. return ok;
  46715. }
  46716. void FileChooserDialogBox::buttonClicked (Button* button)
  46717. {
  46718. if (button == content->okButton)
  46719. {
  46720. if (warnAboutOverwritingExistingFiles
  46721. && content->chooserComponent->isSaveMode()
  46722. && content->chooserComponent->getSelectedFile(0).exists())
  46723. {
  46724. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  46725. TRANS("File already exists"),
  46726. TRANS("There's already a file called:\n\n")
  46727. + content->chooserComponent->getSelectedFile(0).getFullPathName()
  46728. + T("\n\nAre you sure you want to overwrite it?"),
  46729. TRANS("overwrite"),
  46730. TRANS("cancel")))
  46731. {
  46732. return;
  46733. }
  46734. }
  46735. exitModalState (1);
  46736. }
  46737. else if (button == content->cancelButton)
  46738. closeButtonPressed();
  46739. }
  46740. void FileChooserDialogBox::closeButtonPressed()
  46741. {
  46742. setVisible (false);
  46743. }
  46744. void FileChooserDialogBox::selectionChanged()
  46745. {
  46746. content->okButton->setEnabled (content->chooserComponent->currentFileIsValid());
  46747. }
  46748. void FileChooserDialogBox::fileClicked (const File&, const MouseEvent&)
  46749. {
  46750. }
  46751. void FileChooserDialogBox::fileDoubleClicked (const File&)
  46752. {
  46753. selectionChanged();
  46754. content->okButton->triggerClick();
  46755. }
  46756. FileChooserDialogBox::ContentComponent::ContentComponent()
  46757. {
  46758. setInterceptsMouseClicks (false, true);
  46759. }
  46760. FileChooserDialogBox::ContentComponent::~ContentComponent()
  46761. {
  46762. delete okButton;
  46763. delete cancelButton;
  46764. }
  46765. void FileChooserDialogBox::ContentComponent::paint (Graphics& g)
  46766. {
  46767. g.setColour (getLookAndFeel().findColour (FileChooserDialogBox::titleTextColourId));
  46768. text.draw (g);
  46769. }
  46770. void FileChooserDialogBox::ContentComponent::resized()
  46771. {
  46772. getLookAndFeel().createFileChooserHeaderText (getName(), instructions, text, getWidth());
  46773. float left, top, right, bottom;
  46774. text.getBoundingBox (0, text.getNumGlyphs(), left, top, right, bottom, false);
  46775. const int y = roundToInt (bottom) + 10;
  46776. const int buttonHeight = 26;
  46777. const int buttonY = getHeight() - buttonHeight - 8;
  46778. chooserComponent->setBounds (0, y, getWidth(), buttonY - y - 20);
  46779. okButton->setBounds (proportionOfWidth (0.25f), buttonY,
  46780. proportionOfWidth (0.2f), buttonHeight);
  46781. cancelButton->setBounds (proportionOfWidth (0.55f), buttonY,
  46782. proportionOfWidth (0.2f), buttonHeight);
  46783. }
  46784. END_JUCE_NAMESPACE
  46785. /*** End of inlined file: juce_FileChooserDialogBox.cpp ***/
  46786. /*** Start of inlined file: juce_FileFilter.cpp ***/
  46787. BEGIN_JUCE_NAMESPACE
  46788. FileFilter::FileFilter (const String& filterDescription)
  46789. : description (filterDescription)
  46790. {
  46791. }
  46792. FileFilter::~FileFilter()
  46793. {
  46794. }
  46795. const String& FileFilter::getDescription() const throw()
  46796. {
  46797. return description;
  46798. }
  46799. END_JUCE_NAMESPACE
  46800. /*** End of inlined file: juce_FileFilter.cpp ***/
  46801. /*** Start of inlined file: juce_FileListComponent.cpp ***/
  46802. BEGIN_JUCE_NAMESPACE
  46803. Image* juce_createIconForFile (const File& file);
  46804. FileListComponent::FileListComponent (DirectoryContentsList& listToShow)
  46805. : ListBox (String::empty, 0),
  46806. DirectoryContentsDisplayComponent (listToShow)
  46807. {
  46808. setModel (this);
  46809. fileList.addChangeListener (this);
  46810. }
  46811. FileListComponent::~FileListComponent()
  46812. {
  46813. fileList.removeChangeListener (this);
  46814. deleteAllChildren();
  46815. }
  46816. int FileListComponent::getNumSelectedFiles() const
  46817. {
  46818. return getNumSelectedRows();
  46819. }
  46820. const File FileListComponent::getSelectedFile (int index) const
  46821. {
  46822. return fileList.getFile (getSelectedRow (index));
  46823. }
  46824. void FileListComponent::scrollToTop()
  46825. {
  46826. getVerticalScrollBar()->setCurrentRangeStart (0);
  46827. }
  46828. void FileListComponent::changeListenerCallback (void*)
  46829. {
  46830. updateContent();
  46831. if (lastDirectory != fileList.getDirectory())
  46832. {
  46833. lastDirectory = fileList.getDirectory();
  46834. deselectAllRows();
  46835. }
  46836. }
  46837. class FileListItemComponent : public Component,
  46838. public TimeSliceClient,
  46839. public AsyncUpdater
  46840. {
  46841. public:
  46842. FileListItemComponent (FileListComponent& owner_,
  46843. TimeSliceThread& thread_) throw()
  46844. : owner (owner_),
  46845. thread (thread_),
  46846. icon (0)
  46847. {
  46848. }
  46849. ~FileListItemComponent() throw()
  46850. {
  46851. thread.removeTimeSliceClient (this);
  46852. clearIcon();
  46853. }
  46854. void paint (Graphics& g)
  46855. {
  46856. getLookAndFeel().drawFileBrowserRow (g, getWidth(), getHeight(),
  46857. file.getFileName(),
  46858. icon,
  46859. fileSize, modTime,
  46860. isDirectory, highlighted,
  46861. index);
  46862. }
  46863. void mouseDown (const MouseEvent& e)
  46864. {
  46865. owner.selectRowsBasedOnModifierKeys (index, e.mods);
  46866. owner.sendMouseClickMessage (file, e);
  46867. }
  46868. void mouseDoubleClick (const MouseEvent&)
  46869. {
  46870. owner.sendDoubleClickMessage (file);
  46871. }
  46872. void update (const File& root,
  46873. const DirectoryContentsList::FileInfo* const fileInfo,
  46874. const int index_,
  46875. const bool highlighted_) throw()
  46876. {
  46877. thread.removeTimeSliceClient (this);
  46878. if (highlighted_ != highlighted
  46879. || index_ != index)
  46880. {
  46881. index = index_;
  46882. highlighted = highlighted_;
  46883. repaint();
  46884. }
  46885. File newFile;
  46886. String newFileSize;
  46887. String newModTime;
  46888. if (fileInfo != 0)
  46889. {
  46890. newFile = root.getChildFile (fileInfo->filename);
  46891. newFileSize = File::descriptionOfSizeInBytes (fileInfo->fileSize);
  46892. newModTime = fileInfo->modificationTime.formatted (T("%d %b '%y %H:%M"));
  46893. }
  46894. if (newFile != file
  46895. || fileSize != newFileSize
  46896. || modTime != newModTime)
  46897. {
  46898. file = newFile;
  46899. fileSize = newFileSize;
  46900. modTime = newModTime;
  46901. isDirectory = fileInfo != 0 && fileInfo->isDirectory;
  46902. repaint();
  46903. clearIcon();
  46904. }
  46905. if (file != File::nonexistent
  46906. && icon == 0 && ! isDirectory)
  46907. {
  46908. updateIcon (true);
  46909. if (icon == 0)
  46910. thread.addTimeSliceClient (this);
  46911. }
  46912. }
  46913. bool useTimeSlice()
  46914. {
  46915. updateIcon (false);
  46916. return false;
  46917. }
  46918. void handleAsyncUpdate()
  46919. {
  46920. repaint();
  46921. }
  46922. juce_UseDebuggingNewOperator
  46923. private:
  46924. FileListComponent& owner;
  46925. TimeSliceThread& thread;
  46926. bool highlighted;
  46927. int index;
  46928. File file;
  46929. String fileSize;
  46930. String modTime;
  46931. Image* icon;
  46932. bool isDirectory;
  46933. void clearIcon() throw()
  46934. {
  46935. ImageCache::release (icon);
  46936. icon = 0;
  46937. }
  46938. void updateIcon (const bool onlyUpdateIfCached) throw()
  46939. {
  46940. if (icon == 0)
  46941. {
  46942. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  46943. Image* im = ImageCache::getFromHashCode (hashCode);
  46944. if (im == 0 && ! onlyUpdateIfCached)
  46945. {
  46946. im = juce_createIconForFile (file);
  46947. if (im != 0)
  46948. ImageCache::addImageToCache (im, hashCode);
  46949. }
  46950. if (im != 0)
  46951. {
  46952. icon = im;
  46953. triggerAsyncUpdate();
  46954. }
  46955. }
  46956. }
  46957. };
  46958. int FileListComponent::getNumRows()
  46959. {
  46960. return fileList.getNumFiles();
  46961. }
  46962. void FileListComponent::paintListBoxItem (int, Graphics&, int, int, bool)
  46963. {
  46964. }
  46965. Component* FileListComponent::refreshComponentForRow (int row, bool isSelected, Component* existingComponentToUpdate)
  46966. {
  46967. FileListItemComponent* comp = dynamic_cast <FileListItemComponent*> (existingComponentToUpdate);
  46968. if (comp == 0)
  46969. {
  46970. delete existingComponentToUpdate;
  46971. comp = new FileListItemComponent (*this, fileList.getTimeSliceThread());
  46972. }
  46973. DirectoryContentsList::FileInfo fileInfo;
  46974. if (fileList.getFileInfo (row, fileInfo))
  46975. comp->update (fileList.getDirectory(), &fileInfo, row, isSelected);
  46976. else
  46977. comp->update (fileList.getDirectory(), 0, row, isSelected);
  46978. return comp;
  46979. }
  46980. void FileListComponent::selectedRowsChanged (int /*lastRowSelected*/)
  46981. {
  46982. sendSelectionChangeMessage();
  46983. }
  46984. void FileListComponent::deleteKeyPressed (int /*currentSelectedRow*/)
  46985. {
  46986. }
  46987. void FileListComponent::returnKeyPressed (int currentSelectedRow)
  46988. {
  46989. sendDoubleClickMessage (fileList.getFile (currentSelectedRow));
  46990. }
  46991. END_JUCE_NAMESPACE
  46992. /*** End of inlined file: juce_FileListComponent.cpp ***/
  46993. /*** Start of inlined file: juce_FilenameComponent.cpp ***/
  46994. BEGIN_JUCE_NAMESPACE
  46995. FilenameComponent::FilenameComponent (const String& name,
  46996. const File& currentFile,
  46997. const bool canEditFilename,
  46998. const bool isDirectory,
  46999. const bool isForSaving,
  47000. const String& fileBrowserWildcard,
  47001. const String& enforcedSuffix_,
  47002. const String& textWhenNothingSelected)
  47003. : Component (name),
  47004. maxRecentFiles (30),
  47005. isDir (isDirectory),
  47006. isSaving (isForSaving),
  47007. isFileDragOver (false),
  47008. wildcard (fileBrowserWildcard),
  47009. enforcedSuffix (enforcedSuffix_)
  47010. {
  47011. addAndMakeVisible (filenameBox = new ComboBox (T("fn")));
  47012. filenameBox->setEditableText (canEditFilename);
  47013. filenameBox->addListener (this);
  47014. filenameBox->setTextWhenNothingSelected (textWhenNothingSelected);
  47015. filenameBox->setTextWhenNoChoicesAvailable (TRANS("(no recently seleced files)"));
  47016. browseButton = 0;
  47017. setBrowseButtonText (T("..."));
  47018. setCurrentFile (currentFile, true);
  47019. }
  47020. FilenameComponent::~FilenameComponent()
  47021. {
  47022. deleteAllChildren();
  47023. }
  47024. void FilenameComponent::paintOverChildren (Graphics& g)
  47025. {
  47026. if (isFileDragOver)
  47027. {
  47028. g.setColour (Colours::red.withAlpha (0.2f));
  47029. g.drawRect (0, 0, getWidth(), getHeight(), 3);
  47030. }
  47031. }
  47032. void FilenameComponent::resized()
  47033. {
  47034. getLookAndFeel().layoutFilenameComponent (*this, filenameBox, browseButton);
  47035. }
  47036. void FilenameComponent::setBrowseButtonText (const String& newBrowseButtonText)
  47037. {
  47038. browseButtonText = newBrowseButtonText;
  47039. lookAndFeelChanged();
  47040. }
  47041. void FilenameComponent::lookAndFeelChanged()
  47042. {
  47043. deleteAndZero (browseButton);
  47044. addAndMakeVisible (browseButton = getLookAndFeel().createFilenameComponentBrowseButton (browseButtonText));
  47045. browseButton->setConnectedEdges (Button::ConnectedOnLeft);
  47046. resized();
  47047. browseButton->addButtonListener (this);
  47048. }
  47049. void FilenameComponent::setTooltip (const String& newTooltip)
  47050. {
  47051. SettableTooltipClient::setTooltip (newTooltip);
  47052. filenameBox->setTooltip (newTooltip);
  47053. }
  47054. void FilenameComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  47055. {
  47056. defaultBrowseFile = newDefaultDirectory;
  47057. }
  47058. void FilenameComponent::buttonClicked (Button*)
  47059. {
  47060. FileChooser fc (TRANS("Choose a new file"),
  47061. getCurrentFile() == File::nonexistent ? defaultBrowseFile
  47062. : getCurrentFile(),
  47063. wildcard);
  47064. if (isDir ? fc.browseForDirectory()
  47065. : (isSaving ? fc.browseForFileToSave (false)
  47066. : fc.browseForFileToOpen()))
  47067. {
  47068. setCurrentFile (fc.getResult(), true);
  47069. }
  47070. }
  47071. void FilenameComponent::comboBoxChanged (ComboBox*)
  47072. {
  47073. setCurrentFile (getCurrentFile(), true);
  47074. }
  47075. bool FilenameComponent::isInterestedInFileDrag (const StringArray&)
  47076. {
  47077. return true;
  47078. }
  47079. void FilenameComponent::filesDropped (const StringArray& filenames, int, int)
  47080. {
  47081. isFileDragOver = false;
  47082. repaint();
  47083. const File f (filenames[0]);
  47084. if (f.exists() && (f.isDirectory() == isDir))
  47085. setCurrentFile (f, true);
  47086. }
  47087. void FilenameComponent::fileDragEnter (const StringArray&, int, int)
  47088. {
  47089. isFileDragOver = true;
  47090. repaint();
  47091. }
  47092. void FilenameComponent::fileDragExit (const StringArray&)
  47093. {
  47094. isFileDragOver = false;
  47095. repaint();
  47096. }
  47097. const File FilenameComponent::getCurrentFile() const
  47098. {
  47099. File f (filenameBox->getText());
  47100. if (enforcedSuffix.isNotEmpty())
  47101. f = f.withFileExtension (enforcedSuffix);
  47102. return f;
  47103. }
  47104. void FilenameComponent::setCurrentFile (File newFile,
  47105. const bool addToRecentlyUsedList,
  47106. const bool sendChangeNotification)
  47107. {
  47108. if (enforcedSuffix.isNotEmpty())
  47109. newFile = newFile.withFileExtension (enforcedSuffix);
  47110. if (newFile.getFullPathName() != lastFilename)
  47111. {
  47112. lastFilename = newFile.getFullPathName();
  47113. if (addToRecentlyUsedList)
  47114. addRecentlyUsedFile (newFile);
  47115. filenameBox->setText (lastFilename, true);
  47116. if (sendChangeNotification)
  47117. triggerAsyncUpdate();
  47118. }
  47119. }
  47120. void FilenameComponent::setFilenameIsEditable (const bool shouldBeEditable)
  47121. {
  47122. filenameBox->setEditableText (shouldBeEditable);
  47123. }
  47124. const StringArray FilenameComponent::getRecentlyUsedFilenames() const
  47125. {
  47126. StringArray names;
  47127. for (int i = 0; i < filenameBox->getNumItems(); ++i)
  47128. names.add (filenameBox->getItemText (i));
  47129. return names;
  47130. }
  47131. void FilenameComponent::setRecentlyUsedFilenames (const StringArray& filenames)
  47132. {
  47133. if (filenames != getRecentlyUsedFilenames())
  47134. {
  47135. filenameBox->clear();
  47136. for (int i = 0; i < jmin (filenames.size(), maxRecentFiles); ++i)
  47137. filenameBox->addItem (filenames[i], i + 1);
  47138. }
  47139. }
  47140. void FilenameComponent::setMaxNumberOfRecentFiles (const int newMaximum)
  47141. {
  47142. maxRecentFiles = jmax (1, newMaximum);
  47143. setRecentlyUsedFilenames (getRecentlyUsedFilenames());
  47144. }
  47145. void FilenameComponent::addRecentlyUsedFile (const File& file)
  47146. {
  47147. StringArray files (getRecentlyUsedFilenames());
  47148. if (file.getFullPathName().isNotEmpty())
  47149. {
  47150. files.removeString (file.getFullPathName(), true);
  47151. files.insert (0, file.getFullPathName());
  47152. setRecentlyUsedFilenames (files);
  47153. }
  47154. }
  47155. void FilenameComponent::addListener (FilenameComponentListener* const listener) throw()
  47156. {
  47157. jassert (listener != 0);
  47158. if (listener != 0)
  47159. listeners.add (listener);
  47160. }
  47161. void FilenameComponent::removeListener (FilenameComponentListener* const listener) throw()
  47162. {
  47163. listeners.removeValue (listener);
  47164. }
  47165. void FilenameComponent::handleAsyncUpdate()
  47166. {
  47167. for (int i = listeners.size(); --i >= 0;)
  47168. {
  47169. ((FilenameComponentListener*) listeners.getUnchecked (i))->filenameComponentChanged (this);
  47170. i = jmin (i, listeners.size());
  47171. }
  47172. }
  47173. END_JUCE_NAMESPACE
  47174. /*** End of inlined file: juce_FilenameComponent.cpp ***/
  47175. /*** Start of inlined file: juce_FileSearchPathListComponent.cpp ***/
  47176. BEGIN_JUCE_NAMESPACE
  47177. FileSearchPathListComponent::FileSearchPathListComponent()
  47178. {
  47179. addAndMakeVisible (listBox = new ListBox (String::empty, this));
  47180. listBox->setColour (ListBox::backgroundColourId, Colours::black.withAlpha (0.02f));
  47181. listBox->setColour (ListBox::outlineColourId, Colours::black.withAlpha (0.1f));
  47182. listBox->setOutlineThickness (1);
  47183. addAndMakeVisible (addButton = new TextButton ("+"));
  47184. addButton->addButtonListener (this);
  47185. addButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  47186. addAndMakeVisible (removeButton = new TextButton ("-"));
  47187. removeButton->addButtonListener (this);
  47188. removeButton->setConnectedEdges (Button::ConnectedOnLeft | Button::ConnectedOnRight | Button::ConnectedOnBottom | Button::ConnectedOnTop);
  47189. addAndMakeVisible (changeButton = new TextButton (TRANS("change...")));
  47190. changeButton->addButtonListener (this);
  47191. addAndMakeVisible (upButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  47192. upButton->addButtonListener (this);
  47193. {
  47194. Path arrowPath;
  47195. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  47196. DrawablePath arrowImage;
  47197. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  47198. arrowImage.setPath (arrowPath);
  47199. ((DrawableButton*) upButton)->setImages (&arrowImage);
  47200. }
  47201. addAndMakeVisible (downButton = new DrawableButton (String::empty, DrawableButton::ImageOnButtonBackground));
  47202. downButton->addButtonListener (this);
  47203. {
  47204. Path arrowPath;
  47205. arrowPath.addArrow (50.0f, 0.0f, 50.0f, 100.0f, 40.0f, 100.0f, 50.0f);
  47206. DrawablePath arrowImage;
  47207. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  47208. arrowImage.setPath (arrowPath);
  47209. ((DrawableButton*) downButton)->setImages (&arrowImage);
  47210. }
  47211. updateButtons();
  47212. }
  47213. FileSearchPathListComponent::~FileSearchPathListComponent()
  47214. {
  47215. deleteAllChildren();
  47216. }
  47217. void FileSearchPathListComponent::updateButtons() throw()
  47218. {
  47219. const bool anythingSelected = listBox->getNumSelectedRows() > 0;
  47220. removeButton->setEnabled (anythingSelected);
  47221. changeButton->setEnabled (anythingSelected);
  47222. upButton->setEnabled (anythingSelected);
  47223. downButton->setEnabled (anythingSelected);
  47224. }
  47225. void FileSearchPathListComponent::changed() throw()
  47226. {
  47227. listBox->updateContent();
  47228. listBox->repaint();
  47229. updateButtons();
  47230. }
  47231. void FileSearchPathListComponent::setPath (const FileSearchPath& newPath)
  47232. {
  47233. if (newPath.toString() != path.toString())
  47234. {
  47235. path = newPath;
  47236. changed();
  47237. }
  47238. }
  47239. void FileSearchPathListComponent::setDefaultBrowseTarget (const File& newDefaultDirectory) throw()
  47240. {
  47241. defaultBrowseTarget = newDefaultDirectory;
  47242. }
  47243. int FileSearchPathListComponent::getNumRows()
  47244. {
  47245. return path.getNumPaths();
  47246. }
  47247. void FileSearchPathListComponent::paintListBoxItem (int rowNumber, Graphics& g, int width, int height, bool rowIsSelected)
  47248. {
  47249. if (rowIsSelected)
  47250. g.fillAll (findColour (TextEditor::highlightColourId));
  47251. g.setColour (findColour (ListBox::textColourId));
  47252. Font f (height * 0.7f);
  47253. f.setHorizontalScale (0.9f);
  47254. g.setFont (f);
  47255. g.drawText (path [rowNumber].getFullPathName(),
  47256. 4, 0, width - 6, height,
  47257. Justification::centredLeft, true);
  47258. }
  47259. void FileSearchPathListComponent::deleteKeyPressed (int row)
  47260. {
  47261. if (((unsigned int) row) < (unsigned int) path.getNumPaths())
  47262. {
  47263. path.remove (row);
  47264. changed();
  47265. }
  47266. }
  47267. void FileSearchPathListComponent::returnKeyPressed (int row)
  47268. {
  47269. FileChooser chooser (TRANS("Change folder..."), path [row], T("*"));
  47270. if (chooser.browseForDirectory())
  47271. {
  47272. path.remove (row);
  47273. path.add (chooser.getResult(), row);
  47274. changed();
  47275. }
  47276. }
  47277. void FileSearchPathListComponent::listBoxItemDoubleClicked (int row, const MouseEvent&)
  47278. {
  47279. returnKeyPressed (row);
  47280. }
  47281. void FileSearchPathListComponent::selectedRowsChanged (int)
  47282. {
  47283. updateButtons();
  47284. }
  47285. void FileSearchPathListComponent::paint (Graphics& g)
  47286. {
  47287. g.fillAll (findColour (backgroundColourId));
  47288. }
  47289. void FileSearchPathListComponent::resized()
  47290. {
  47291. const int buttonH = 22;
  47292. const int buttonY = getHeight() - buttonH - 4;
  47293. listBox->setBounds (2, 2, getWidth() - 4, buttonY - 5);
  47294. addButton->setBounds (2, buttonY, buttonH, buttonH);
  47295. removeButton->setBounds (addButton->getRight(), buttonY, buttonH, buttonH);
  47296. ((TextButton*) changeButton)->changeWidthToFitText (buttonH);
  47297. downButton->setSize (buttonH * 2, buttonH);
  47298. upButton->setSize (buttonH * 2, buttonH);
  47299. downButton->setTopRightPosition (getWidth() - 2, buttonY);
  47300. upButton->setTopRightPosition (downButton->getX() - 4, buttonY);
  47301. changeButton->setTopRightPosition (upButton->getX() - 8, buttonY);
  47302. }
  47303. bool FileSearchPathListComponent::isInterestedInFileDrag (const StringArray&)
  47304. {
  47305. return true;
  47306. }
  47307. void FileSearchPathListComponent::filesDropped (const StringArray& filenames, int, int mouseY)
  47308. {
  47309. for (int i = filenames.size(); --i >= 0;)
  47310. {
  47311. const File f (filenames[i]);
  47312. if (f.isDirectory())
  47313. {
  47314. const int row = listBox->getRowContainingPosition (0, mouseY - listBox->getY());
  47315. path.add (f, row);
  47316. changed();
  47317. }
  47318. }
  47319. }
  47320. void FileSearchPathListComponent::buttonClicked (Button* button)
  47321. {
  47322. const int currentRow = listBox->getSelectedRow();
  47323. if (button == removeButton)
  47324. {
  47325. deleteKeyPressed (currentRow);
  47326. }
  47327. else if (button == addButton)
  47328. {
  47329. File start (defaultBrowseTarget);
  47330. if (start == File::nonexistent)
  47331. start = path [0];
  47332. if (start == File::nonexistent)
  47333. start = File::getCurrentWorkingDirectory();
  47334. FileChooser chooser (TRANS("Add a folder..."), start, T("*"));
  47335. if (chooser.browseForDirectory())
  47336. {
  47337. path.add (chooser.getResult(), currentRow);
  47338. }
  47339. }
  47340. else if (button == changeButton)
  47341. {
  47342. returnKeyPressed (currentRow);
  47343. }
  47344. else if (button == upButton)
  47345. {
  47346. if (currentRow > 0 && currentRow < path.getNumPaths())
  47347. {
  47348. const File f (path[currentRow]);
  47349. path.remove (currentRow);
  47350. path.add (f, currentRow - 1);
  47351. listBox->selectRow (currentRow - 1);
  47352. }
  47353. }
  47354. else if (button == downButton)
  47355. {
  47356. if (currentRow >= 0 && currentRow < path.getNumPaths() - 1)
  47357. {
  47358. const File f (path[currentRow]);
  47359. path.remove (currentRow);
  47360. path.add (f, currentRow + 1);
  47361. listBox->selectRow (currentRow + 1);
  47362. }
  47363. }
  47364. changed();
  47365. }
  47366. END_JUCE_NAMESPACE
  47367. /*** End of inlined file: juce_FileSearchPathListComponent.cpp ***/
  47368. /*** Start of inlined file: juce_FileTreeComponent.cpp ***/
  47369. BEGIN_JUCE_NAMESPACE
  47370. Image* juce_createIconForFile (const File& file);
  47371. class FileListTreeItem : public TreeViewItem,
  47372. public TimeSliceClient,
  47373. public AsyncUpdater,
  47374. public ChangeListener
  47375. {
  47376. public:
  47377. FileListTreeItem (FileTreeComponent& owner_,
  47378. DirectoryContentsList* const parentContentsList_,
  47379. const int indexInContentsList_,
  47380. const File& file_,
  47381. TimeSliceThread& thread_) throw()
  47382. : file (file_),
  47383. owner (owner_),
  47384. parentContentsList (parentContentsList_),
  47385. indexInContentsList (indexInContentsList_),
  47386. subContentsList (0),
  47387. canDeleteSubContentsList (false),
  47388. thread (thread_),
  47389. icon (0)
  47390. {
  47391. DirectoryContentsList::FileInfo fileInfo;
  47392. if (parentContentsList_ != 0
  47393. && parentContentsList_->getFileInfo (indexInContentsList_, fileInfo))
  47394. {
  47395. fileSize = File::descriptionOfSizeInBytes (fileInfo.fileSize);
  47396. modTime = fileInfo.modificationTime.formatted (T("%d %b '%y %H:%M"));
  47397. isDirectory = fileInfo.isDirectory;
  47398. }
  47399. else
  47400. {
  47401. isDirectory = true;
  47402. }
  47403. }
  47404. ~FileListTreeItem() throw()
  47405. {
  47406. thread.removeTimeSliceClient (this);
  47407. clearSubItems();
  47408. ImageCache::release (icon);
  47409. if (canDeleteSubContentsList)
  47410. delete subContentsList;
  47411. }
  47412. bool mightContainSubItems() { return isDirectory; }
  47413. const String getUniqueName() const { return file.getFullPathName(); }
  47414. int getItemHeight() const { return 22; }
  47415. const String getDragSourceDescription() { return owner.getDragAndDropDescription(); }
  47416. void itemOpennessChanged (bool isNowOpen)
  47417. {
  47418. if (isNowOpen)
  47419. {
  47420. clearSubItems();
  47421. isDirectory = file.isDirectory();
  47422. if (isDirectory)
  47423. {
  47424. if (subContentsList == 0)
  47425. {
  47426. jassert (parentContentsList != 0);
  47427. DirectoryContentsList* const l = new DirectoryContentsList (parentContentsList->getFilter(), thread);
  47428. l->setDirectory (file, true, true);
  47429. setSubContentsList (l);
  47430. canDeleteSubContentsList = true;
  47431. }
  47432. changeListenerCallback (0);
  47433. }
  47434. }
  47435. }
  47436. void setSubContentsList (DirectoryContentsList* newList) throw()
  47437. {
  47438. jassert (subContentsList == 0);
  47439. subContentsList = newList;
  47440. newList->addChangeListener (this);
  47441. }
  47442. void changeListenerCallback (void*)
  47443. {
  47444. clearSubItems();
  47445. if (isOpen() && subContentsList != 0)
  47446. {
  47447. for (int i = 0; i < subContentsList->getNumFiles(); ++i)
  47448. {
  47449. FileListTreeItem* const item
  47450. = new FileListTreeItem (owner, subContentsList, i, subContentsList->getFile(i), thread);
  47451. addSubItem (item);
  47452. }
  47453. }
  47454. }
  47455. void paintItem (Graphics& g, int width, int height)
  47456. {
  47457. if (file != File::nonexistent)
  47458. {
  47459. updateIcon (true);
  47460. if (icon == 0)
  47461. thread.addTimeSliceClient (this);
  47462. }
  47463. owner.getLookAndFeel()
  47464. .drawFileBrowserRow (g, width, height,
  47465. file.getFileName(),
  47466. icon,
  47467. fileSize, modTime,
  47468. isDirectory, isSelected(),
  47469. indexInContentsList);
  47470. }
  47471. void itemClicked (const MouseEvent& e)
  47472. {
  47473. owner.sendMouseClickMessage (file, e);
  47474. }
  47475. void itemDoubleClicked (const MouseEvent& e)
  47476. {
  47477. TreeViewItem::itemDoubleClicked (e);
  47478. owner.sendDoubleClickMessage (file);
  47479. }
  47480. void itemSelectionChanged (bool)
  47481. {
  47482. owner.sendSelectionChangeMessage();
  47483. }
  47484. bool useTimeSlice()
  47485. {
  47486. updateIcon (false);
  47487. thread.removeTimeSliceClient (this);
  47488. return false;
  47489. }
  47490. void handleAsyncUpdate()
  47491. {
  47492. owner.repaint();
  47493. }
  47494. const File file;
  47495. juce_UseDebuggingNewOperator
  47496. private:
  47497. FileTreeComponent& owner;
  47498. DirectoryContentsList* parentContentsList;
  47499. int indexInContentsList;
  47500. DirectoryContentsList* subContentsList;
  47501. bool isDirectory, canDeleteSubContentsList;
  47502. TimeSliceThread& thread;
  47503. Image* icon;
  47504. String fileSize;
  47505. String modTime;
  47506. void updateIcon (const bool onlyUpdateIfCached) throw()
  47507. {
  47508. if (icon == 0)
  47509. {
  47510. const int hashCode = (file.getFullPathName() + T("_iconCacheSalt")).hashCode();
  47511. Image* im = ImageCache::getFromHashCode (hashCode);
  47512. if (im == 0 && ! onlyUpdateIfCached)
  47513. {
  47514. im = juce_createIconForFile (file);
  47515. if (im != 0)
  47516. ImageCache::addImageToCache (im, hashCode);
  47517. }
  47518. if (im != 0)
  47519. {
  47520. icon = im;
  47521. triggerAsyncUpdate();
  47522. }
  47523. }
  47524. }
  47525. };
  47526. FileTreeComponent::FileTreeComponent (DirectoryContentsList& listToShow)
  47527. : DirectoryContentsDisplayComponent (listToShow)
  47528. {
  47529. FileListTreeItem* const root
  47530. = new FileListTreeItem (*this, 0, 0, listToShow.getDirectory(),
  47531. listToShow.getTimeSliceThread());
  47532. root->setSubContentsList (&listToShow);
  47533. setRootItemVisible (false);
  47534. setRootItem (root);
  47535. }
  47536. FileTreeComponent::~FileTreeComponent()
  47537. {
  47538. deleteRootItem();
  47539. }
  47540. const File FileTreeComponent::getSelectedFile (const int index) const
  47541. {
  47542. const FileListTreeItem* const item = dynamic_cast <const FileListTreeItem*> (getSelectedItem (index));
  47543. if (item != 0)
  47544. return item->file;
  47545. return File::nonexistent;
  47546. }
  47547. void FileTreeComponent::scrollToTop()
  47548. {
  47549. getViewport()->getVerticalScrollBar()->setCurrentRangeStart (0);
  47550. }
  47551. void FileTreeComponent::setDragAndDropDescription (const String& description) throw()
  47552. {
  47553. dragAndDropDescription = description;
  47554. }
  47555. END_JUCE_NAMESPACE
  47556. /*** End of inlined file: juce_FileTreeComponent.cpp ***/
  47557. /*** Start of inlined file: juce_ImagePreviewComponent.cpp ***/
  47558. BEGIN_JUCE_NAMESPACE
  47559. ImagePreviewComponent::ImagePreviewComponent()
  47560. {
  47561. }
  47562. ImagePreviewComponent::~ImagePreviewComponent()
  47563. {
  47564. }
  47565. void ImagePreviewComponent::getThumbSize (int& w, int& h) const
  47566. {
  47567. const int availableW = proportionOfWidth (0.97f);
  47568. const int availableH = getHeight() - 13 * 4;
  47569. const double scale = jmin (1.0,
  47570. availableW / (double) w,
  47571. availableH / (double) h);
  47572. w = roundToInt (scale * w);
  47573. h = roundToInt (scale * h);
  47574. }
  47575. void ImagePreviewComponent::selectedFileChanged (const File& file)
  47576. {
  47577. if (fileToLoad != file)
  47578. {
  47579. fileToLoad = file;
  47580. startTimer (100);
  47581. }
  47582. }
  47583. void ImagePreviewComponent::timerCallback()
  47584. {
  47585. stopTimer();
  47586. currentThumbnail = 0;
  47587. currentDetails = String::empty;
  47588. repaint();
  47589. ScopedPointer <FileInputStream> in (fileToLoad.createInputStream());
  47590. if (in != 0)
  47591. {
  47592. ImageFileFormat* const format = ImageFileFormat::findImageFormatForStream (*in);
  47593. if (format != 0)
  47594. {
  47595. currentThumbnail = format->decodeImage (*in);
  47596. if (currentThumbnail != 0)
  47597. {
  47598. int w = currentThumbnail->getWidth();
  47599. int h = currentThumbnail->getHeight();
  47600. currentDetails
  47601. << fileToLoad.getFileName() << "\n"
  47602. << format->getFormatName() << "\n"
  47603. << w << " x " << h << " pixels\n"
  47604. << File::descriptionOfSizeInBytes (fileToLoad.getSize());
  47605. getThumbSize (w, h);
  47606. currentThumbnail = currentThumbnail->createCopy (w, h);
  47607. }
  47608. }
  47609. }
  47610. }
  47611. void ImagePreviewComponent::paint (Graphics& g)
  47612. {
  47613. if (currentThumbnail != 0)
  47614. {
  47615. g.setFont (13.0f);
  47616. int w = currentThumbnail->getWidth();
  47617. int h = currentThumbnail->getHeight();
  47618. getThumbSize (w, h);
  47619. const int numLines = 4;
  47620. const int totalH = 13 * numLines + h + 4;
  47621. const int y = (getHeight() - totalH) / 2;
  47622. g.drawImageWithin (currentThumbnail,
  47623. (getWidth() - w) / 2, y, w, h,
  47624. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  47625. false);
  47626. g.drawFittedText (currentDetails,
  47627. 0, y + h + 4, getWidth(), 100,
  47628. Justification::centredTop, numLines);
  47629. }
  47630. }
  47631. END_JUCE_NAMESPACE
  47632. /*** End of inlined file: juce_ImagePreviewComponent.cpp ***/
  47633. /*** Start of inlined file: juce_WildcardFileFilter.cpp ***/
  47634. BEGIN_JUCE_NAMESPACE
  47635. WildcardFileFilter::WildcardFileFilter (const String& fileWildcardPatterns,
  47636. const String& directoryWildcardPatterns,
  47637. const String& description_)
  47638. : FileFilter (description_.isEmpty() ? fileWildcardPatterns
  47639. : (description_ + T(" (") + fileWildcardPatterns + T(")")))
  47640. {
  47641. parse (fileWildcardPatterns, fileWildcards);
  47642. parse (directoryWildcardPatterns, directoryWildcards);
  47643. }
  47644. WildcardFileFilter::~WildcardFileFilter()
  47645. {
  47646. }
  47647. bool WildcardFileFilter::isFileSuitable (const File& file) const
  47648. {
  47649. return match (file, fileWildcards);
  47650. }
  47651. bool WildcardFileFilter::isDirectorySuitable (const File& file) const
  47652. {
  47653. return match (file, directoryWildcards);
  47654. }
  47655. void WildcardFileFilter::parse (const String& pattern, StringArray& result) throw()
  47656. {
  47657. result.addTokens (pattern.toLowerCase(), T(";,"), T("\"'"));
  47658. result.trim();
  47659. result.removeEmptyStrings();
  47660. // special case for *.*, because people use it to mean "any file", but it
  47661. // would actually ignore files with no extension.
  47662. for (int i = result.size(); --i >= 0;)
  47663. if (result[i] == T("*.*"))
  47664. result.set (i, T("*"));
  47665. }
  47666. bool WildcardFileFilter::match (const File& file, const StringArray& wildcards) throw()
  47667. {
  47668. const String filename (file.getFileName());
  47669. for (int i = wildcards.size(); --i >= 0;)
  47670. if (filename.matchesWildcard (wildcards[i], true))
  47671. return true;
  47672. return false;
  47673. }
  47674. END_JUCE_NAMESPACE
  47675. /*** End of inlined file: juce_WildcardFileFilter.cpp ***/
  47676. /*** Start of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47677. BEGIN_JUCE_NAMESPACE
  47678. KeyboardFocusTraverser::KeyboardFocusTraverser()
  47679. {
  47680. }
  47681. KeyboardFocusTraverser::~KeyboardFocusTraverser()
  47682. {
  47683. }
  47684. namespace KeyboardFocusHelpers
  47685. {
  47686. // This will sort a set of components, so that they are ordered in terms of
  47687. // left-to-right and then top-to-bottom.
  47688. class ScreenPositionComparator
  47689. {
  47690. public:
  47691. ScreenPositionComparator() {}
  47692. static int compareElements (const Component* const first, const Component* const second) throw()
  47693. {
  47694. int explicitOrder1 = first->getExplicitFocusOrder();
  47695. if (explicitOrder1 <= 0)
  47696. explicitOrder1 = std::numeric_limits<int>::max() / 2;
  47697. int explicitOrder2 = second->getExplicitFocusOrder();
  47698. if (explicitOrder2 <= 0)
  47699. explicitOrder2 = std::numeric_limits<int>::max() / 2;
  47700. if (explicitOrder1 != explicitOrder2)
  47701. return explicitOrder1 - explicitOrder2;
  47702. const int diff = first->getY() - second->getY();
  47703. return (diff == 0) ? first->getX() - second->getX()
  47704. : diff;
  47705. }
  47706. };
  47707. static void findAllFocusableComponents (Component* const parent, Array <Component*>& comps)
  47708. {
  47709. if (parent->getNumChildComponents() > 0)
  47710. {
  47711. Array <Component*> localComps;
  47712. ScreenPositionComparator comparator;
  47713. int i;
  47714. for (i = parent->getNumChildComponents(); --i >= 0;)
  47715. {
  47716. Component* const c = parent->getChildComponent (i);
  47717. if (c->isVisible() && c->isEnabled())
  47718. localComps.addSorted (comparator, c);
  47719. }
  47720. for (i = 0; i < localComps.size(); ++i)
  47721. {
  47722. Component* const c = localComps.getUnchecked (i);
  47723. if (c->getWantsKeyboardFocus())
  47724. comps.add (c);
  47725. if (! c->isFocusContainer())
  47726. findAllFocusableComponents (c, comps);
  47727. }
  47728. }
  47729. }
  47730. }
  47731. static Component* getIncrementedComponent (Component* const current, const int delta) throw()
  47732. {
  47733. Component* focusContainer = current->getParentComponent();
  47734. if (focusContainer != 0)
  47735. {
  47736. while (focusContainer->getParentComponent() != 0 && ! focusContainer->isFocusContainer())
  47737. focusContainer = focusContainer->getParentComponent();
  47738. if (focusContainer != 0)
  47739. {
  47740. Array <Component*> comps;
  47741. KeyboardFocusHelpers::findAllFocusableComponents (focusContainer, comps);
  47742. if (comps.size() > 0)
  47743. {
  47744. const int index = comps.indexOf (current);
  47745. return comps [(index + comps.size() + delta) % comps.size()];
  47746. }
  47747. }
  47748. }
  47749. return 0;
  47750. }
  47751. Component* KeyboardFocusTraverser::getNextComponent (Component* current)
  47752. {
  47753. return getIncrementedComponent (current, 1);
  47754. }
  47755. Component* KeyboardFocusTraverser::getPreviousComponent (Component* current)
  47756. {
  47757. return getIncrementedComponent (current, -1);
  47758. }
  47759. Component* KeyboardFocusTraverser::getDefaultComponent (Component* parentComponent)
  47760. {
  47761. Array <Component*> comps;
  47762. if (parentComponent != 0)
  47763. KeyboardFocusHelpers::findAllFocusableComponents (parentComponent, comps);
  47764. return comps.getFirst();
  47765. }
  47766. END_JUCE_NAMESPACE
  47767. /*** End of inlined file: juce_KeyboardFocusTraverser.cpp ***/
  47768. /*** Start of inlined file: juce_KeyListener.cpp ***/
  47769. BEGIN_JUCE_NAMESPACE
  47770. bool KeyListener::keyStateChanged (const bool, Component*)
  47771. {
  47772. return false;
  47773. }
  47774. END_JUCE_NAMESPACE
  47775. /*** End of inlined file: juce_KeyListener.cpp ***/
  47776. /*** Start of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  47777. BEGIN_JUCE_NAMESPACE
  47778. // N.B. these two includes are put here deliberately to avoid problems with
  47779. // old GCCs failing on long include paths
  47780. const int maxKeys = 3;
  47781. class KeyMappingChangeButton : public Button
  47782. {
  47783. public:
  47784. KeyMappingChangeButton (KeyMappingEditorComponent* const owner_,
  47785. const CommandID commandID_,
  47786. const String& keyName,
  47787. const int keyNum_)
  47788. : Button (keyName),
  47789. owner (owner_),
  47790. commandID (commandID_),
  47791. keyNum (keyNum_)
  47792. {
  47793. setWantsKeyboardFocus (false);
  47794. setTriggeredOnMouseDown (keyNum >= 0);
  47795. if (keyNum_ < 0)
  47796. setTooltip (TRANS("adds a new key-mapping"));
  47797. else
  47798. setTooltip (TRANS("click to change this key-mapping"));
  47799. }
  47800. ~KeyMappingChangeButton()
  47801. {
  47802. }
  47803. void paintButton (Graphics& g, bool /*isOver*/, bool /*isDown*/)
  47804. {
  47805. getLookAndFeel().drawKeymapChangeButton (g, getWidth(), getHeight(), *this,
  47806. keyNum >= 0 ? getName() : String::empty);
  47807. }
  47808. void clicked()
  47809. {
  47810. if (keyNum >= 0)
  47811. {
  47812. // existing key clicked..
  47813. PopupMenu m;
  47814. m.addItem (1, TRANS("change this key-mapping"));
  47815. m.addSeparator();
  47816. m.addItem (2, TRANS("remove this key-mapping"));
  47817. const int res = m.show();
  47818. if (res == 1)
  47819. {
  47820. owner->assignNewKey (commandID, keyNum);
  47821. }
  47822. else if (res == 2)
  47823. {
  47824. owner->getMappings()->removeKeyPress (commandID, keyNum);
  47825. }
  47826. }
  47827. else
  47828. {
  47829. // + button pressed..
  47830. owner->assignNewKey (commandID, -1);
  47831. }
  47832. }
  47833. void fitToContent (const int h) throw()
  47834. {
  47835. if (keyNum < 0)
  47836. {
  47837. setSize (h, h);
  47838. }
  47839. else
  47840. {
  47841. Font f (h * 0.6f);
  47842. setSize (jlimit (h * 4, h * 8, 6 + f.getStringWidth (getName())), h);
  47843. }
  47844. }
  47845. juce_UseDebuggingNewOperator
  47846. private:
  47847. KeyMappingEditorComponent* const owner;
  47848. const CommandID commandID;
  47849. const int keyNum;
  47850. KeyMappingChangeButton (const KeyMappingChangeButton&);
  47851. KeyMappingChangeButton& operator= (const KeyMappingChangeButton&);
  47852. };
  47853. class KeyMappingItemComponent : public Component
  47854. {
  47855. public:
  47856. KeyMappingItemComponent (KeyMappingEditorComponent* const owner_,
  47857. const CommandID commandID_)
  47858. : owner (owner_),
  47859. commandID (commandID_)
  47860. {
  47861. setInterceptsMouseClicks (false, true);
  47862. const bool isReadOnly = owner_->isCommandReadOnly (commandID);
  47863. const Array <KeyPress> keyPresses (owner_->getMappings()->getKeyPressesAssignedToCommand (commandID));
  47864. for (int i = 0; i < jmin (maxKeys, keyPresses.size()); ++i)
  47865. {
  47866. KeyMappingChangeButton* const kb
  47867. = new KeyMappingChangeButton (owner_, commandID,
  47868. owner_->getDescriptionForKeyPress (keyPresses.getReference (i)), i);
  47869. kb->setEnabled (! isReadOnly);
  47870. addAndMakeVisible (kb);
  47871. }
  47872. KeyMappingChangeButton* const kb
  47873. = new KeyMappingChangeButton (owner_, commandID, String::empty, -1);
  47874. addChildComponent (kb);
  47875. kb->setVisible (keyPresses.size() < maxKeys && ! isReadOnly);
  47876. }
  47877. ~KeyMappingItemComponent()
  47878. {
  47879. deleteAllChildren();
  47880. }
  47881. void paint (Graphics& g)
  47882. {
  47883. g.setFont (getHeight() * 0.7f);
  47884. g.setColour (findColour (KeyMappingEditorComponent::textColourId));
  47885. g.drawFittedText (owner->getMappings()->getCommandManager()->getNameOfCommand (commandID),
  47886. 4, 0, jmax (40, getChildComponent (0)->getX() - 5), getHeight(),
  47887. Justification::centredLeft, true);
  47888. }
  47889. void resized()
  47890. {
  47891. int x = getWidth() - 4;
  47892. for (int i = getNumChildComponents(); --i >= 0;)
  47893. {
  47894. KeyMappingChangeButton* const kb = dynamic_cast <KeyMappingChangeButton*> (getChildComponent (i));
  47895. kb->fitToContent (getHeight() - 2);
  47896. kb->setTopRightPosition (x, 1);
  47897. x -= kb->getWidth() + 5;
  47898. }
  47899. }
  47900. juce_UseDebuggingNewOperator
  47901. private:
  47902. KeyMappingEditorComponent* const owner;
  47903. const CommandID commandID;
  47904. KeyMappingItemComponent (const KeyMappingItemComponent&);
  47905. KeyMappingItemComponent& operator= (const KeyMappingItemComponent&);
  47906. };
  47907. class KeyMappingTreeViewItem : public TreeViewItem
  47908. {
  47909. public:
  47910. KeyMappingTreeViewItem (KeyMappingEditorComponent* const owner_,
  47911. const CommandID commandID_)
  47912. : owner (owner_),
  47913. commandID (commandID_)
  47914. {
  47915. }
  47916. ~KeyMappingTreeViewItem()
  47917. {
  47918. }
  47919. const String getUniqueName() const { return String ((int) commandID) + "_id"; }
  47920. bool mightContainSubItems() { return false; }
  47921. int getItemHeight() const { return 20; }
  47922. Component* createItemComponent()
  47923. {
  47924. return new KeyMappingItemComponent (owner, commandID);
  47925. }
  47926. juce_UseDebuggingNewOperator
  47927. private:
  47928. KeyMappingEditorComponent* const owner;
  47929. const CommandID commandID;
  47930. KeyMappingTreeViewItem (const KeyMappingTreeViewItem&);
  47931. KeyMappingTreeViewItem& operator= (const KeyMappingTreeViewItem&);
  47932. };
  47933. class KeyCategoryTreeViewItem : public TreeViewItem
  47934. {
  47935. public:
  47936. KeyCategoryTreeViewItem (KeyMappingEditorComponent* const owner_,
  47937. const String& name)
  47938. : owner (owner_),
  47939. categoryName (name)
  47940. {
  47941. }
  47942. ~KeyCategoryTreeViewItem()
  47943. {
  47944. }
  47945. const String getUniqueName() const { return categoryName + "_cat"; }
  47946. bool mightContainSubItems() { return true; }
  47947. int getItemHeight() const { return 28; }
  47948. void paintItem (Graphics& g, int width, int height)
  47949. {
  47950. g.setFont (height * 0.6f, Font::bold);
  47951. g.setColour (owner->findColour (KeyMappingEditorComponent::textColourId));
  47952. g.drawText (categoryName,
  47953. 2, 0, width - 2, height,
  47954. Justification::centredLeft, true);
  47955. }
  47956. void itemOpennessChanged (bool isNowOpen)
  47957. {
  47958. if (isNowOpen)
  47959. {
  47960. if (getNumSubItems() == 0)
  47961. {
  47962. Array <CommandID> commands (owner->getMappings()->getCommandManager()->getCommandsInCategory (categoryName));
  47963. for (int i = 0; i < commands.size(); ++i)
  47964. {
  47965. if (owner->shouldCommandBeIncluded (commands[i]))
  47966. addSubItem (new KeyMappingTreeViewItem (owner, commands[i]));
  47967. }
  47968. }
  47969. }
  47970. else
  47971. {
  47972. clearSubItems();
  47973. }
  47974. }
  47975. juce_UseDebuggingNewOperator
  47976. private:
  47977. KeyMappingEditorComponent* owner;
  47978. String categoryName;
  47979. KeyCategoryTreeViewItem (const KeyCategoryTreeViewItem&);
  47980. KeyCategoryTreeViewItem& operator= (const KeyCategoryTreeViewItem&);
  47981. };
  47982. KeyMappingEditorComponent::KeyMappingEditorComponent (KeyPressMappingSet* const mappingManager,
  47983. const bool showResetToDefaultButton)
  47984. : mappings (mappingManager)
  47985. {
  47986. jassert (mappingManager != 0); // can't be null!
  47987. mappingManager->addChangeListener (this);
  47988. setLinesDrawnForSubItems (false);
  47989. resetButton = 0;
  47990. if (showResetToDefaultButton)
  47991. {
  47992. addAndMakeVisible (resetButton = new TextButton (TRANS("reset to defaults")));
  47993. resetButton->addButtonListener (this);
  47994. }
  47995. addAndMakeVisible (tree = new TreeView());
  47996. tree->setColour (TreeView::backgroundColourId, findColour (backgroundColourId));
  47997. tree->setRootItemVisible (false);
  47998. tree->setDefaultOpenness (true);
  47999. tree->setRootItem (this);
  48000. }
  48001. KeyMappingEditorComponent::~KeyMappingEditorComponent()
  48002. {
  48003. mappings->removeChangeListener (this);
  48004. deleteAllChildren();
  48005. }
  48006. bool KeyMappingEditorComponent::mightContainSubItems()
  48007. {
  48008. return true;
  48009. }
  48010. const String KeyMappingEditorComponent::getUniqueName() const
  48011. {
  48012. return T("keys");
  48013. }
  48014. void KeyMappingEditorComponent::setColours (const Colour& mainBackground,
  48015. const Colour& textColour)
  48016. {
  48017. setColour (backgroundColourId, mainBackground);
  48018. setColour (textColourId, textColour);
  48019. tree->setColour (TreeView::backgroundColourId, mainBackground);
  48020. }
  48021. void KeyMappingEditorComponent::parentHierarchyChanged()
  48022. {
  48023. changeListenerCallback (0);
  48024. }
  48025. void KeyMappingEditorComponent::resized()
  48026. {
  48027. int h = getHeight();
  48028. if (resetButton != 0)
  48029. {
  48030. const int buttonHeight = 20;
  48031. h -= buttonHeight + 8;
  48032. int x = getWidth() - 8;
  48033. const int y = h + 6;
  48034. resetButton->changeWidthToFitText (buttonHeight);
  48035. resetButton->setTopRightPosition (x, y);
  48036. }
  48037. tree->setBounds (0, 0, getWidth(), h);
  48038. }
  48039. void KeyMappingEditorComponent::buttonClicked (Button* button)
  48040. {
  48041. if (button == resetButton)
  48042. {
  48043. if (AlertWindow::showOkCancelBox (AlertWindow::QuestionIcon,
  48044. TRANS("Reset to defaults"),
  48045. TRANS("Are you sure you want to reset all the key-mappings to their default state?"),
  48046. TRANS("Reset")))
  48047. {
  48048. mappings->resetToDefaultMappings();
  48049. }
  48050. }
  48051. }
  48052. void KeyMappingEditorComponent::changeListenerCallback (void*)
  48053. {
  48054. ScopedPointer <XmlElement> openness (tree->getOpennessState (true));
  48055. clearSubItems();
  48056. const StringArray categories (mappings->getCommandManager()->getCommandCategories());
  48057. for (int i = 0; i < categories.size(); ++i)
  48058. {
  48059. const Array <CommandID> commands (mappings->getCommandManager()->getCommandsInCategory (categories[i]));
  48060. int count = 0;
  48061. for (int j = 0; j < commands.size(); ++j)
  48062. if (shouldCommandBeIncluded (commands[j]))
  48063. ++count;
  48064. if (count > 0)
  48065. addSubItem (new KeyCategoryTreeViewItem (this, categories[i]));
  48066. }
  48067. if (openness != 0)
  48068. tree->restoreOpennessState (*openness);
  48069. }
  48070. class KeyEntryWindow : public AlertWindow
  48071. {
  48072. public:
  48073. KeyEntryWindow (KeyMappingEditorComponent* const owner_)
  48074. : AlertWindow (TRANS("New key-mapping"),
  48075. TRANS("Please press a key combination now..."),
  48076. AlertWindow::NoIcon),
  48077. owner (owner_)
  48078. {
  48079. addButton (TRANS("ok"), 1);
  48080. addButton (TRANS("cancel"), 0);
  48081. // (avoid return + escape keys getting processed by the buttons..)
  48082. for (int i = getNumChildComponents(); --i >= 0;)
  48083. getChildComponent (i)->setWantsKeyboardFocus (false);
  48084. setWantsKeyboardFocus (true);
  48085. grabKeyboardFocus();
  48086. }
  48087. ~KeyEntryWindow()
  48088. {
  48089. }
  48090. bool keyPressed (const KeyPress& key)
  48091. {
  48092. lastPress = key;
  48093. String message (TRANS("Key: ") + owner->getDescriptionForKeyPress (key));
  48094. const CommandID previousCommand = owner->getMappings()->findCommandForKeyPress (key);
  48095. if (previousCommand != 0)
  48096. {
  48097. message << "\n\n"
  48098. << TRANS("(Currently assigned to \"")
  48099. << owner->getMappings()->getCommandManager()->getNameOfCommand (previousCommand)
  48100. << "\")";
  48101. }
  48102. setMessage (message);
  48103. return true;
  48104. }
  48105. bool keyStateChanged (const bool)
  48106. {
  48107. return true;
  48108. }
  48109. KeyPress lastPress;
  48110. juce_UseDebuggingNewOperator
  48111. private:
  48112. KeyMappingEditorComponent* owner;
  48113. KeyEntryWindow (const KeyEntryWindow&);
  48114. KeyEntryWindow& operator= (const KeyEntryWindow&);
  48115. };
  48116. void KeyMappingEditorComponent::assignNewKey (const CommandID commandID, const int index)
  48117. {
  48118. KeyEntryWindow entryWindow (this);
  48119. if (entryWindow.runModalLoop() != 0)
  48120. {
  48121. entryWindow.setVisible (false);
  48122. if (entryWindow.lastPress.isValid())
  48123. {
  48124. const CommandID previousCommand = mappings->findCommandForKeyPress (entryWindow.lastPress);
  48125. if (previousCommand != 0)
  48126. {
  48127. if (! AlertWindow::showOkCancelBox (AlertWindow::WarningIcon,
  48128. TRANS("Change key-mapping"),
  48129. TRANS("This key is already assigned to the command \"")
  48130. + mappings->getCommandManager()->getNameOfCommand (previousCommand)
  48131. + TRANS("\"\n\nDo you want to re-assign it to this new command instead?"),
  48132. TRANS("re-assign"),
  48133. TRANS("cancel")))
  48134. {
  48135. return;
  48136. }
  48137. }
  48138. mappings->removeKeyPress (entryWindow.lastPress);
  48139. if (index >= 0)
  48140. mappings->removeKeyPress (commandID, index);
  48141. mappings->addKeyPress (commandID, entryWindow.lastPress, index);
  48142. }
  48143. }
  48144. }
  48145. bool KeyMappingEditorComponent::shouldCommandBeIncluded (const CommandID commandID)
  48146. {
  48147. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  48148. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::hiddenFromKeyEditor) == 0);
  48149. }
  48150. bool KeyMappingEditorComponent::isCommandReadOnly (const CommandID commandID)
  48151. {
  48152. const ApplicationCommandInfo* const ci = mappings->getCommandManager()->getCommandForID (commandID);
  48153. return (ci != 0) && ((ci->flags & ApplicationCommandInfo::readOnlyInKeyEditor) != 0);
  48154. }
  48155. const String KeyMappingEditorComponent::getDescriptionForKeyPress (const KeyPress& key)
  48156. {
  48157. return key.getTextDescription();
  48158. }
  48159. END_JUCE_NAMESPACE
  48160. /*** End of inlined file: juce_KeyMappingEditorComponent.cpp ***/
  48161. /*** Start of inlined file: juce_KeyPress.cpp ***/
  48162. BEGIN_JUCE_NAMESPACE
  48163. KeyPress::KeyPress() throw()
  48164. : keyCode (0),
  48165. mods (0),
  48166. textCharacter (0)
  48167. {
  48168. }
  48169. KeyPress::KeyPress (const int keyCode_,
  48170. const ModifierKeys& mods_,
  48171. const juce_wchar textCharacter_) throw()
  48172. : keyCode (keyCode_),
  48173. mods (mods_),
  48174. textCharacter (textCharacter_)
  48175. {
  48176. }
  48177. KeyPress::KeyPress (const int keyCode_) throw()
  48178. : keyCode (keyCode_),
  48179. textCharacter (0)
  48180. {
  48181. }
  48182. KeyPress::KeyPress (const KeyPress& other) throw()
  48183. : keyCode (other.keyCode),
  48184. mods (other.mods),
  48185. textCharacter (other.textCharacter)
  48186. {
  48187. }
  48188. KeyPress& KeyPress::operator= (const KeyPress& other) throw()
  48189. {
  48190. keyCode = other.keyCode;
  48191. mods = other.mods;
  48192. textCharacter = other.textCharacter;
  48193. return *this;
  48194. }
  48195. bool KeyPress::operator== (const KeyPress& other) const throw()
  48196. {
  48197. return mods.getRawFlags() == other.mods.getRawFlags()
  48198. && (textCharacter == other.textCharacter
  48199. || textCharacter == 0
  48200. || other.textCharacter == 0)
  48201. && (keyCode == other.keyCode
  48202. || (keyCode < 256
  48203. && other.keyCode < 256
  48204. && CharacterFunctions::toLowerCase ((tchar) keyCode)
  48205. == CharacterFunctions::toLowerCase ((tchar) other.keyCode)));
  48206. }
  48207. bool KeyPress::operator!= (const KeyPress& other) const throw()
  48208. {
  48209. return ! operator== (other);
  48210. }
  48211. bool KeyPress::isCurrentlyDown() const throw()
  48212. {
  48213. return isKeyCurrentlyDown (keyCode)
  48214. && (ModifierKeys::getCurrentModifiers().getRawFlags() & ModifierKeys::allKeyboardModifiers)
  48215. == (mods.getRawFlags() & ModifierKeys::allKeyboardModifiers);
  48216. }
  48217. struct KeyNameAndCode
  48218. {
  48219. const char* name;
  48220. int code;
  48221. };
  48222. static const KeyNameAndCode keyNameTranslations[] =
  48223. {
  48224. { "spacebar", KeyPress::spaceKey },
  48225. { "return", KeyPress::returnKey },
  48226. { "escape", KeyPress::escapeKey },
  48227. { "backspace", KeyPress::backspaceKey },
  48228. { "cursor left", KeyPress::leftKey },
  48229. { "cursor right", KeyPress::rightKey },
  48230. { "cursor up", KeyPress::upKey },
  48231. { "cursor down", KeyPress::downKey },
  48232. { "page up", KeyPress::pageUpKey },
  48233. { "page down", KeyPress::pageDownKey },
  48234. { "home", KeyPress::homeKey },
  48235. { "end", KeyPress::endKey },
  48236. { "delete", KeyPress::deleteKey },
  48237. { "insert", KeyPress::insertKey },
  48238. { "tab", KeyPress::tabKey },
  48239. { "play", KeyPress::playKey },
  48240. { "stop", KeyPress::stopKey },
  48241. { "fast forward", KeyPress::fastForwardKey },
  48242. { "rewind", KeyPress::rewindKey }
  48243. };
  48244. static const tchar* const numberPadPrefix = T("numpad ");
  48245. const KeyPress KeyPress::createFromDescription (const String& desc) throw()
  48246. {
  48247. int modifiers = 0;
  48248. if (desc.containsWholeWordIgnoreCase (T("ctrl"))
  48249. || desc.containsWholeWordIgnoreCase (T("control"))
  48250. || desc.containsWholeWordIgnoreCase (T("ctl")))
  48251. modifiers |= ModifierKeys::ctrlModifier;
  48252. if (desc.containsWholeWordIgnoreCase (T("shift"))
  48253. || desc.containsWholeWordIgnoreCase (T("shft")))
  48254. modifiers |= ModifierKeys::shiftModifier;
  48255. if (desc.containsWholeWordIgnoreCase (T("alt"))
  48256. || desc.containsWholeWordIgnoreCase (T("option")))
  48257. modifiers |= ModifierKeys::altModifier;
  48258. if (desc.containsWholeWordIgnoreCase (T("command"))
  48259. || desc.containsWholeWordIgnoreCase (T("cmd")))
  48260. modifiers |= ModifierKeys::commandModifier;
  48261. int key = 0;
  48262. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  48263. {
  48264. if (desc.containsWholeWordIgnoreCase (String (keyNameTranslations[i].name)))
  48265. {
  48266. key = keyNameTranslations[i].code;
  48267. break;
  48268. }
  48269. }
  48270. if (key == 0)
  48271. {
  48272. // see if it's a numpad key..
  48273. if (desc.containsIgnoreCase (numberPadPrefix))
  48274. {
  48275. const tchar lastChar = desc.trimEnd().getLastCharacter();
  48276. if (lastChar >= T('0') && lastChar <= T('9'))
  48277. key = numberPad0 + lastChar - T('0');
  48278. else if (lastChar == T('+'))
  48279. key = numberPadAdd;
  48280. else if (lastChar == T('-'))
  48281. key = numberPadSubtract;
  48282. else if (lastChar == T('*'))
  48283. key = numberPadMultiply;
  48284. else if (lastChar == T('/'))
  48285. key = numberPadDivide;
  48286. else if (lastChar == T('.'))
  48287. key = numberPadDecimalPoint;
  48288. else if (lastChar == T('='))
  48289. key = numberPadEquals;
  48290. else if (desc.endsWith (T("separator")))
  48291. key = numberPadSeparator;
  48292. else if (desc.endsWith (T("delete")))
  48293. key = numberPadDelete;
  48294. }
  48295. if (key == 0)
  48296. {
  48297. // see if it's a function key..
  48298. for (int i = 1; i <= 12; ++i)
  48299. if (desc.containsWholeWordIgnoreCase (T("f") + String (i)))
  48300. key = F1Key + i - 1;
  48301. if (key == 0)
  48302. {
  48303. // give up and use the hex code..
  48304. const int hexCode = desc.fromFirstOccurrenceOf (T("#"), false, false)
  48305. .toLowerCase()
  48306. .retainCharacters (T("0123456789abcdef"))
  48307. .getHexValue32();
  48308. if (hexCode > 0)
  48309. key = hexCode;
  48310. else
  48311. key = CharacterFunctions::toUpperCase (desc.getLastCharacter());
  48312. }
  48313. }
  48314. }
  48315. return KeyPress (key, ModifierKeys (modifiers), 0);
  48316. }
  48317. const String KeyPress::getTextDescription() const throw()
  48318. {
  48319. String desc;
  48320. if (keyCode > 0)
  48321. {
  48322. // some keyboard layouts use a shift-key to get the slash, but in those cases, we
  48323. // want to store it as being a slash, not shift+whatever.
  48324. if (textCharacter == T('/'))
  48325. return "/";
  48326. if (mods.isCtrlDown())
  48327. desc << "ctrl + ";
  48328. if (mods.isShiftDown())
  48329. desc << "shift + ";
  48330. #if JUCE_MAC
  48331. // only do this on the mac, because on Windows ctrl and command are the same,
  48332. // and this would get confusing
  48333. if (mods.isCommandDown())
  48334. desc << "command + ";
  48335. if (mods.isAltDown())
  48336. desc << "option + ";
  48337. #else
  48338. if (mods.isAltDown())
  48339. desc << "alt + ";
  48340. #endif
  48341. for (int i = 0; i < numElementsInArray (keyNameTranslations); ++i)
  48342. if (keyCode == keyNameTranslations[i].code)
  48343. return desc + keyNameTranslations[i].name;
  48344. if (keyCode >= F1Key && keyCode <= F16Key)
  48345. desc << 'F' << (1 + keyCode - F1Key);
  48346. else if (keyCode >= numberPad0 && keyCode <= numberPad9)
  48347. desc << numberPadPrefix << (keyCode - numberPad0);
  48348. else if (keyCode >= 33 && keyCode < 176)
  48349. desc += CharacterFunctions::toUpperCase ((tchar) keyCode);
  48350. else if (keyCode == numberPadAdd)
  48351. desc << numberPadPrefix << '+';
  48352. else if (keyCode == numberPadSubtract)
  48353. desc << numberPadPrefix << '-';
  48354. else if (keyCode == numberPadMultiply)
  48355. desc << numberPadPrefix << '*';
  48356. else if (keyCode == numberPadDivide)
  48357. desc << numberPadPrefix << '/';
  48358. else if (keyCode == numberPadSeparator)
  48359. desc << numberPadPrefix << "separator";
  48360. else if (keyCode == numberPadDecimalPoint)
  48361. desc << numberPadPrefix << '.';
  48362. else if (keyCode == numberPadDelete)
  48363. desc << numberPadPrefix << "delete";
  48364. else
  48365. desc << '#' << String::toHexString (keyCode);
  48366. }
  48367. return desc;
  48368. }
  48369. END_JUCE_NAMESPACE
  48370. /*** End of inlined file: juce_KeyPress.cpp ***/
  48371. /*** Start of inlined file: juce_KeyPressMappingSet.cpp ***/
  48372. BEGIN_JUCE_NAMESPACE
  48373. KeyPressMappingSet::KeyPressMappingSet (ApplicationCommandManager* const commandManager_) throw()
  48374. : commandManager (commandManager_)
  48375. {
  48376. // A manager is needed to get the descriptions of commands, and will be called when
  48377. // a command is invoked. So you can't leave this null..
  48378. jassert (commandManager_ != 0);
  48379. Desktop::getInstance().addFocusChangeListener (this);
  48380. }
  48381. KeyPressMappingSet::KeyPressMappingSet (const KeyPressMappingSet& other) throw()
  48382. : commandManager (other.commandManager)
  48383. {
  48384. Desktop::getInstance().addFocusChangeListener (this);
  48385. }
  48386. KeyPressMappingSet::~KeyPressMappingSet()
  48387. {
  48388. Desktop::getInstance().removeFocusChangeListener (this);
  48389. }
  48390. const Array <KeyPress> KeyPressMappingSet::getKeyPressesAssignedToCommand (const CommandID commandID) const throw()
  48391. {
  48392. for (int i = 0; i < mappings.size(); ++i)
  48393. if (mappings.getUnchecked(i)->commandID == commandID)
  48394. return mappings.getUnchecked (i)->keypresses;
  48395. return Array <KeyPress> ();
  48396. }
  48397. void KeyPressMappingSet::addKeyPress (const CommandID commandID,
  48398. const KeyPress& newKeyPress,
  48399. int insertIndex) throw()
  48400. {
  48401. // If you specify an upper-case letter but no shift key, how is the user supposed to press it!?
  48402. // Stick to lower-case letters when defining a keypress, to avoid ambiguity.
  48403. jassert (! (CharacterFunctions::isUpperCase (newKeyPress.getTextCharacter())
  48404. && ! newKeyPress.getModifiers().isShiftDown()));
  48405. if (findCommandForKeyPress (newKeyPress) != commandID)
  48406. {
  48407. removeKeyPress (newKeyPress);
  48408. if (newKeyPress.isValid())
  48409. {
  48410. for (int i = mappings.size(); --i >= 0;)
  48411. {
  48412. if (mappings.getUnchecked(i)->commandID == commandID)
  48413. {
  48414. mappings.getUnchecked(i)->keypresses.insert (insertIndex, newKeyPress);
  48415. sendChangeMessage (this);
  48416. return;
  48417. }
  48418. }
  48419. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48420. if (ci != 0)
  48421. {
  48422. CommandMapping* const cm = new CommandMapping();
  48423. cm->commandID = commandID;
  48424. cm->keypresses.add (newKeyPress);
  48425. cm->wantsKeyUpDownCallbacks = (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) != 0;
  48426. mappings.add (cm);
  48427. sendChangeMessage (this);
  48428. }
  48429. }
  48430. }
  48431. }
  48432. void KeyPressMappingSet::resetToDefaultMappings() throw()
  48433. {
  48434. mappings.clear();
  48435. for (int i = 0; i < commandManager->getNumCommands(); ++i)
  48436. {
  48437. const ApplicationCommandInfo* const ci = commandManager->getCommandForIndex (i);
  48438. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  48439. {
  48440. addKeyPress (ci->commandID,
  48441. ci->defaultKeypresses.getReference (j));
  48442. }
  48443. }
  48444. sendChangeMessage (this);
  48445. }
  48446. void KeyPressMappingSet::resetToDefaultMapping (const CommandID commandID) throw()
  48447. {
  48448. clearAllKeyPresses (commandID);
  48449. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48450. for (int j = 0; j < ci->defaultKeypresses.size(); ++j)
  48451. {
  48452. addKeyPress (ci->commandID,
  48453. ci->defaultKeypresses.getReference (j));
  48454. }
  48455. }
  48456. void KeyPressMappingSet::clearAllKeyPresses() throw()
  48457. {
  48458. if (mappings.size() > 0)
  48459. {
  48460. sendChangeMessage (this);
  48461. mappings.clear();
  48462. }
  48463. }
  48464. void KeyPressMappingSet::clearAllKeyPresses (const CommandID commandID) throw()
  48465. {
  48466. for (int i = mappings.size(); --i >= 0;)
  48467. {
  48468. if (mappings.getUnchecked(i)->commandID == commandID)
  48469. {
  48470. mappings.remove (i);
  48471. sendChangeMessage (this);
  48472. }
  48473. }
  48474. }
  48475. void KeyPressMappingSet::removeKeyPress (const KeyPress& keypress) throw()
  48476. {
  48477. if (keypress.isValid())
  48478. {
  48479. for (int i = mappings.size(); --i >= 0;)
  48480. {
  48481. CommandMapping* const cm = mappings.getUnchecked(i);
  48482. for (int j = cm->keypresses.size(); --j >= 0;)
  48483. {
  48484. if (keypress == cm->keypresses [j])
  48485. {
  48486. cm->keypresses.remove (j);
  48487. sendChangeMessage (this);
  48488. }
  48489. }
  48490. }
  48491. }
  48492. }
  48493. void KeyPressMappingSet::removeKeyPress (const CommandID commandID,
  48494. const int keyPressIndex) throw()
  48495. {
  48496. for (int i = mappings.size(); --i >= 0;)
  48497. {
  48498. if (mappings.getUnchecked(i)->commandID == commandID)
  48499. {
  48500. mappings.getUnchecked(i)->keypresses.remove (keyPressIndex);
  48501. sendChangeMessage (this);
  48502. break;
  48503. }
  48504. }
  48505. }
  48506. CommandID KeyPressMappingSet::findCommandForKeyPress (const KeyPress& keyPress) const throw()
  48507. {
  48508. for (int i = 0; i < mappings.size(); ++i)
  48509. if (mappings.getUnchecked(i)->keypresses.contains (keyPress))
  48510. return mappings.getUnchecked(i)->commandID;
  48511. return 0;
  48512. }
  48513. bool KeyPressMappingSet::containsMapping (const CommandID commandID,
  48514. const KeyPress& keyPress) const throw()
  48515. {
  48516. for (int i = mappings.size(); --i >= 0;)
  48517. if (mappings.getUnchecked(i)->commandID == commandID)
  48518. return mappings.getUnchecked(i)->keypresses.contains (keyPress);
  48519. return false;
  48520. }
  48521. void KeyPressMappingSet::invokeCommand (const CommandID commandID,
  48522. const KeyPress& key,
  48523. const bool isKeyDown,
  48524. const int millisecsSinceKeyPressed,
  48525. Component* const originatingComponent) const
  48526. {
  48527. ApplicationCommandTarget::InvocationInfo info (commandID);
  48528. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromKeyPress;
  48529. info.isKeyDown = isKeyDown;
  48530. info.keyPress = key;
  48531. info.millisecsSinceKeyPressed = millisecsSinceKeyPressed;
  48532. info.originatingComponent = originatingComponent;
  48533. commandManager->invoke (info, false);
  48534. }
  48535. bool KeyPressMappingSet::restoreFromXml (const XmlElement& xmlVersion)
  48536. {
  48537. if (xmlVersion.hasTagName (T("KEYMAPPINGS")))
  48538. {
  48539. if (xmlVersion.getBoolAttribute (T("basedOnDefaults"), true))
  48540. {
  48541. // if the XML was created as a set of differences from the default mappings,
  48542. // (i.e. by calling createXml (true)), then we need to first restore the defaults.
  48543. resetToDefaultMappings();
  48544. }
  48545. else
  48546. {
  48547. // if the XML was created calling createXml (false), then we need to clear all
  48548. // the keys and treat the xml as describing the entire set of mappings.
  48549. clearAllKeyPresses();
  48550. }
  48551. forEachXmlChildElement (xmlVersion, map)
  48552. {
  48553. const CommandID commandId = map->getStringAttribute (T("commandId")).getHexValue32();
  48554. if (commandId != 0)
  48555. {
  48556. const KeyPress key (KeyPress::createFromDescription (map->getStringAttribute (T("key"))));
  48557. if (map->hasTagName (T("MAPPING")))
  48558. {
  48559. addKeyPress (commandId, key);
  48560. }
  48561. else if (map->hasTagName (T("UNMAPPING")))
  48562. {
  48563. if (containsMapping (commandId, key))
  48564. removeKeyPress (key);
  48565. }
  48566. }
  48567. }
  48568. return true;
  48569. }
  48570. return false;
  48571. }
  48572. XmlElement* KeyPressMappingSet::createXml (const bool saveDifferencesFromDefaultSet) const
  48573. {
  48574. ScopedPointer <KeyPressMappingSet> defaultSet;
  48575. if (saveDifferencesFromDefaultSet)
  48576. {
  48577. defaultSet = new KeyPressMappingSet (commandManager);
  48578. defaultSet->resetToDefaultMappings();
  48579. }
  48580. XmlElement* const doc = new XmlElement (T("KEYMAPPINGS"));
  48581. doc->setAttribute (T("basedOnDefaults"), saveDifferencesFromDefaultSet);
  48582. int i;
  48583. for (i = 0; i < mappings.size(); ++i)
  48584. {
  48585. const CommandMapping* const cm = mappings.getUnchecked(i);
  48586. for (int j = 0; j < cm->keypresses.size(); ++j)
  48587. {
  48588. if (defaultSet == 0
  48589. || ! defaultSet->containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48590. {
  48591. XmlElement* const map = doc->createNewChildElement ("MAPPING");
  48592. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48593. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48594. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48595. }
  48596. }
  48597. }
  48598. if (defaultSet != 0)
  48599. {
  48600. for (i = 0; i < defaultSet->mappings.size(); ++i)
  48601. {
  48602. const CommandMapping* const cm = defaultSet->mappings.getUnchecked(i);
  48603. for (int j = 0; j < cm->keypresses.size(); ++j)
  48604. {
  48605. if (! containsMapping (cm->commandID, cm->keypresses.getReference (j)))
  48606. {
  48607. XmlElement* const map = doc->createNewChildElement ("UNMAPPING");
  48608. map->setAttribute (T("commandId"), String::toHexString ((int) cm->commandID));
  48609. map->setAttribute (T("description"), commandManager->getDescriptionOfCommand (cm->commandID));
  48610. map->setAttribute (T("key"), cm->keypresses.getReference (j).getTextDescription());
  48611. }
  48612. }
  48613. }
  48614. }
  48615. return doc;
  48616. }
  48617. bool KeyPressMappingSet::keyPressed (const KeyPress& key,
  48618. Component* originatingComponent)
  48619. {
  48620. bool used = false;
  48621. const CommandID commandID = findCommandForKeyPress (key);
  48622. const ApplicationCommandInfo* const ci = commandManager->getCommandForID (commandID);
  48623. if (ci != 0
  48624. && (ci->flags & ApplicationCommandInfo::wantsKeyUpDownCallbacks) == 0)
  48625. {
  48626. ApplicationCommandInfo info (0);
  48627. if (commandManager->getTargetForCommand (commandID, info) != 0
  48628. && (info.flags & ApplicationCommandInfo::isDisabled) == 0)
  48629. {
  48630. invokeCommand (commandID, key, true, 0, originatingComponent);
  48631. used = true;
  48632. }
  48633. else
  48634. {
  48635. if (originatingComponent != 0)
  48636. originatingComponent->getLookAndFeel().playAlertSound();
  48637. }
  48638. }
  48639. return used;
  48640. }
  48641. bool KeyPressMappingSet::keyStateChanged (const bool /*isKeyDown*/, Component* originatingComponent)
  48642. {
  48643. bool used = false;
  48644. const uint32 now = Time::getMillisecondCounter();
  48645. for (int i = mappings.size(); --i >= 0;)
  48646. {
  48647. CommandMapping* const cm = mappings.getUnchecked(i);
  48648. if (cm->wantsKeyUpDownCallbacks)
  48649. {
  48650. for (int j = cm->keypresses.size(); --j >= 0;)
  48651. {
  48652. const KeyPress key (cm->keypresses.getReference (j));
  48653. const bool isDown = key.isCurrentlyDown();
  48654. int keyPressEntryIndex = 0;
  48655. bool wasDown = false;
  48656. for (int k = keysDown.size(); --k >= 0;)
  48657. {
  48658. if (key == keysDown.getUnchecked(k)->key)
  48659. {
  48660. keyPressEntryIndex = k;
  48661. wasDown = true;
  48662. used = true;
  48663. break;
  48664. }
  48665. }
  48666. if (isDown != wasDown)
  48667. {
  48668. int millisecs = 0;
  48669. if (isDown)
  48670. {
  48671. KeyPressTime* const k = new KeyPressTime();
  48672. k->key = key;
  48673. k->timeWhenPressed = now;
  48674. keysDown.add (k);
  48675. }
  48676. else
  48677. {
  48678. const uint32 pressTime = keysDown.getUnchecked (keyPressEntryIndex)->timeWhenPressed;
  48679. if (now > pressTime)
  48680. millisecs = now - pressTime;
  48681. keysDown.remove (keyPressEntryIndex);
  48682. }
  48683. invokeCommand (cm->commandID, key, isDown, millisecs, originatingComponent);
  48684. used = true;
  48685. }
  48686. }
  48687. }
  48688. }
  48689. return used;
  48690. }
  48691. void KeyPressMappingSet::globalFocusChanged (Component* focusedComponent)
  48692. {
  48693. if (focusedComponent != 0)
  48694. focusedComponent->keyStateChanged (false);
  48695. }
  48696. END_JUCE_NAMESPACE
  48697. /*** End of inlined file: juce_KeyPressMappingSet.cpp ***/
  48698. /*** Start of inlined file: juce_ModifierKeys.cpp ***/
  48699. BEGIN_JUCE_NAMESPACE
  48700. ModifierKeys::ModifierKeys (const int flags_) throw()
  48701. : flags (flags_)
  48702. {
  48703. }
  48704. ModifierKeys::ModifierKeys (const ModifierKeys& other) throw()
  48705. : flags (other.flags)
  48706. {
  48707. }
  48708. ModifierKeys& ModifierKeys::operator= (const ModifierKeys& other) throw()
  48709. {
  48710. flags = other.flags;
  48711. return *this;
  48712. }
  48713. int ModifierKeys::currentModifierFlags = 0;
  48714. const ModifierKeys ModifierKeys::getCurrentModifiers() throw()
  48715. {
  48716. return ModifierKeys (currentModifierFlags);
  48717. }
  48718. int ModifierKeys::getNumMouseButtonsDown() const throw()
  48719. {
  48720. int num = 0;
  48721. if (isLeftButtonDown()) ++num;
  48722. if (isRightButtonDown()) ++num;
  48723. if (isMiddleButtonDown()) ++num;
  48724. return num;
  48725. }
  48726. END_JUCE_NAMESPACE
  48727. /*** End of inlined file: juce_ModifierKeys.cpp ***/
  48728. /*** Start of inlined file: juce_ComponentAnimator.cpp ***/
  48729. BEGIN_JUCE_NAMESPACE
  48730. struct AnimationTask
  48731. {
  48732. AnimationTask (Component* const comp)
  48733. : component (comp),
  48734. watcher (comp)
  48735. {
  48736. }
  48737. Component* component;
  48738. ComponentDeletionWatcher watcher;
  48739. Rectangle<int> destination;
  48740. int msElapsed, msTotal;
  48741. double startSpeed, midSpeed, endSpeed, lastProgress;
  48742. double left, top, right, bottom;
  48743. bool useTimeslice (const int elapsed)
  48744. {
  48745. if (watcher.hasBeenDeleted())
  48746. return false;
  48747. msElapsed += elapsed;
  48748. double newProgress = msElapsed / (double) msTotal;
  48749. if (newProgress >= 0 && newProgress < 1.0)
  48750. {
  48751. newProgress = timeToDistance (newProgress);
  48752. const double delta = (newProgress - lastProgress) / (1.0 - lastProgress);
  48753. jassert (newProgress >= lastProgress);
  48754. lastProgress = newProgress;
  48755. left += (destination.getX() - left) * delta;
  48756. top += (destination.getY() - top) * delta;
  48757. right += (destination.getRight() - right) * delta;
  48758. bottom += (destination.getBottom() - bottom) * delta;
  48759. if (delta < 1.0)
  48760. {
  48761. const Rectangle<int> newBounds (roundToInt (left),
  48762. roundToInt (top),
  48763. roundToInt (right - left),
  48764. roundToInt (bottom - top));
  48765. if (newBounds != destination)
  48766. {
  48767. component->setBounds (newBounds);
  48768. return true;
  48769. }
  48770. }
  48771. }
  48772. component->setBounds (destination);
  48773. return false;
  48774. }
  48775. void moveToFinalDestination()
  48776. {
  48777. if (! watcher.hasBeenDeleted())
  48778. component->setBounds (destination);
  48779. }
  48780. private:
  48781. inline double timeToDistance (const double time) const
  48782. {
  48783. return (time < 0.5) ? time * (startSpeed + time * (midSpeed - startSpeed))
  48784. : 0.5 * (startSpeed + 0.5 * (midSpeed - startSpeed))
  48785. + (time - 0.5) * (midSpeed + (time - 0.5) * (endSpeed - midSpeed));
  48786. }
  48787. };
  48788. ComponentAnimator::ComponentAnimator()
  48789. : lastTime (0)
  48790. {
  48791. }
  48792. ComponentAnimator::~ComponentAnimator()
  48793. {
  48794. cancelAllAnimations (false);
  48795. jassert (tasks.size() == 0);
  48796. }
  48797. void* ComponentAnimator::findTaskFor (Component* const component) const
  48798. {
  48799. for (int i = tasks.size(); --i >= 0;)
  48800. if (component == ((AnimationTask*) tasks.getUnchecked(i))->component)
  48801. return tasks.getUnchecked(i);
  48802. return 0;
  48803. }
  48804. void ComponentAnimator::animateComponent (Component* const component,
  48805. const Rectangle<int>& finalPosition,
  48806. const int millisecondsToSpendMoving,
  48807. const double startSpeed,
  48808. const double endSpeed)
  48809. {
  48810. if (component != 0)
  48811. {
  48812. AnimationTask* at = (AnimationTask*) findTaskFor (component);
  48813. if (at == 0)
  48814. {
  48815. at = new AnimationTask (component);
  48816. tasks.add (at);
  48817. sendChangeMessage (this);
  48818. }
  48819. at->msElapsed = 0;
  48820. at->lastProgress = 0;
  48821. at->msTotal = jmax (1, millisecondsToSpendMoving);
  48822. at->destination = finalPosition;
  48823. // the speeds must be 0 or greater!
  48824. jassert (startSpeed >= 0 && endSpeed >= 0)
  48825. const double invTotalDistance = 4.0 / (startSpeed + endSpeed + 2.0);
  48826. at->startSpeed = jmax (0.0, startSpeed * invTotalDistance);
  48827. at->midSpeed = invTotalDistance;
  48828. at->endSpeed = jmax (0.0, endSpeed * invTotalDistance);
  48829. at->left = component->getX();
  48830. at->top = component->getY();
  48831. at->right = component->getRight();
  48832. at->bottom = component->getBottom();
  48833. if (! isTimerRunning())
  48834. {
  48835. lastTime = Time::getMillisecondCounter();
  48836. startTimer (1000 / 50);
  48837. }
  48838. }
  48839. }
  48840. void ComponentAnimator::cancelAllAnimations (const bool moveComponentsToTheirFinalPositions)
  48841. {
  48842. for (int i = tasks.size(); --i >= 0;)
  48843. {
  48844. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48845. if (moveComponentsToTheirFinalPositions)
  48846. at->moveToFinalDestination();
  48847. delete at;
  48848. tasks.remove (i);
  48849. sendChangeMessage (this);
  48850. }
  48851. }
  48852. void ComponentAnimator::cancelAnimation (Component* const component,
  48853. const bool moveComponentToItsFinalPosition)
  48854. {
  48855. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48856. if (at != 0)
  48857. {
  48858. if (moveComponentToItsFinalPosition)
  48859. at->moveToFinalDestination();
  48860. tasks.removeValue (at);
  48861. delete at;
  48862. sendChangeMessage (this);
  48863. }
  48864. }
  48865. const Rectangle<int> ComponentAnimator::getComponentDestination (Component* const component)
  48866. {
  48867. AnimationTask* const at = (AnimationTask*) findTaskFor (component);
  48868. if (at != 0)
  48869. return at->destination;
  48870. else if (component != 0)
  48871. return component->getBounds();
  48872. return Rectangle<int>();
  48873. }
  48874. bool ComponentAnimator::isAnimating (Component* component) const
  48875. {
  48876. return findTaskFor (component) != 0;
  48877. }
  48878. void ComponentAnimator::timerCallback()
  48879. {
  48880. const uint32 timeNow = Time::getMillisecondCounter();
  48881. if (lastTime == 0 || lastTime == timeNow)
  48882. lastTime = timeNow;
  48883. const int elapsed = timeNow - lastTime;
  48884. for (int i = tasks.size(); --i >= 0;)
  48885. {
  48886. AnimationTask* const at = (AnimationTask*) tasks.getUnchecked(i);
  48887. if (! at->useTimeslice (elapsed))
  48888. {
  48889. tasks.remove (i);
  48890. delete at;
  48891. sendChangeMessage (this);
  48892. }
  48893. }
  48894. lastTime = timeNow;
  48895. if (tasks.size() == 0)
  48896. stopTimer();
  48897. }
  48898. END_JUCE_NAMESPACE
  48899. /*** End of inlined file: juce_ComponentAnimator.cpp ***/
  48900. /*** Start of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  48901. BEGIN_JUCE_NAMESPACE
  48902. ComponentBoundsConstrainer::ComponentBoundsConstrainer() throw()
  48903. : minW (0),
  48904. maxW (0x3fffffff),
  48905. minH (0),
  48906. maxH (0x3fffffff),
  48907. minOffTop (0),
  48908. minOffLeft (0),
  48909. minOffBottom (0),
  48910. minOffRight (0),
  48911. aspectRatio (0.0)
  48912. {
  48913. }
  48914. ComponentBoundsConstrainer::~ComponentBoundsConstrainer()
  48915. {
  48916. }
  48917. void ComponentBoundsConstrainer::setMinimumWidth (const int minimumWidth) throw()
  48918. {
  48919. minW = minimumWidth;
  48920. }
  48921. void ComponentBoundsConstrainer::setMaximumWidth (const int maximumWidth) throw()
  48922. {
  48923. maxW = maximumWidth;
  48924. }
  48925. void ComponentBoundsConstrainer::setMinimumHeight (const int minimumHeight) throw()
  48926. {
  48927. minH = minimumHeight;
  48928. }
  48929. void ComponentBoundsConstrainer::setMaximumHeight (const int maximumHeight) throw()
  48930. {
  48931. maxH = maximumHeight;
  48932. }
  48933. void ComponentBoundsConstrainer::setMinimumSize (const int minimumWidth, const int minimumHeight) throw()
  48934. {
  48935. jassert (maxW >= minimumWidth);
  48936. jassert (maxH >= minimumHeight);
  48937. jassert (minimumWidth > 0 && minimumHeight > 0);
  48938. minW = minimumWidth;
  48939. minH = minimumHeight;
  48940. if (minW > maxW)
  48941. maxW = minW;
  48942. if (minH > maxH)
  48943. maxH = minH;
  48944. }
  48945. void ComponentBoundsConstrainer::setMaximumSize (const int maximumWidth, const int maximumHeight) throw()
  48946. {
  48947. jassert (maximumWidth >= minW);
  48948. jassert (maximumHeight >= minH);
  48949. jassert (maximumWidth > 0 && maximumHeight > 0);
  48950. maxW = jmax (minW, maximumWidth);
  48951. maxH = jmax (minH, maximumHeight);
  48952. }
  48953. void ComponentBoundsConstrainer::setSizeLimits (const int minimumWidth,
  48954. const int minimumHeight,
  48955. const int maximumWidth,
  48956. const int maximumHeight) throw()
  48957. {
  48958. jassert (maximumWidth >= minimumWidth);
  48959. jassert (maximumHeight >= minimumHeight);
  48960. jassert (maximumWidth > 0 && maximumHeight > 0);
  48961. jassert (minimumWidth > 0 && minimumHeight > 0);
  48962. minW = jmax (0, minimumWidth);
  48963. minH = jmax (0, minimumHeight);
  48964. maxW = jmax (minW, maximumWidth);
  48965. maxH = jmax (minH, maximumHeight);
  48966. }
  48967. void ComponentBoundsConstrainer::setMinimumOnscreenAmounts (const int minimumWhenOffTheTop,
  48968. const int minimumWhenOffTheLeft,
  48969. const int minimumWhenOffTheBottom,
  48970. const int minimumWhenOffTheRight) throw()
  48971. {
  48972. minOffTop = minimumWhenOffTheTop;
  48973. minOffLeft = minimumWhenOffTheLeft;
  48974. minOffBottom = minimumWhenOffTheBottom;
  48975. minOffRight = minimumWhenOffTheRight;
  48976. }
  48977. void ComponentBoundsConstrainer::setFixedAspectRatio (const double widthOverHeight) throw()
  48978. {
  48979. aspectRatio = jmax (0.0, widthOverHeight);
  48980. }
  48981. double ComponentBoundsConstrainer::getFixedAspectRatio() const throw()
  48982. {
  48983. return aspectRatio;
  48984. }
  48985. void ComponentBoundsConstrainer::setBoundsForComponent (Component* const component,
  48986. const Rectangle<int>& targetBounds,
  48987. const bool isStretchingTop,
  48988. const bool isStretchingLeft,
  48989. const bool isStretchingBottom,
  48990. const bool isStretchingRight)
  48991. {
  48992. jassert (component != 0);
  48993. Rectangle<int> limits, bounds (targetBounds);
  48994. BorderSize border;
  48995. Component* const parent = component->getParentComponent();
  48996. if (parent == 0)
  48997. {
  48998. ComponentPeer* peer = component->getPeer();
  48999. if (peer != 0)
  49000. border = peer->getFrameSize();
  49001. limits = Desktop::getInstance().getMonitorAreaContaining (bounds.getCentre());
  49002. }
  49003. else
  49004. {
  49005. limits.setSize (parent->getWidth(), parent->getHeight());
  49006. }
  49007. border.addTo (bounds);
  49008. checkBounds (bounds,
  49009. border.addedTo (component->getBounds()), limits,
  49010. isStretchingTop, isStretchingLeft,
  49011. isStretchingBottom, isStretchingRight);
  49012. border.subtractFrom (bounds);
  49013. applyBoundsToComponent (component, bounds);
  49014. }
  49015. void ComponentBoundsConstrainer::checkComponentBounds (Component* component)
  49016. {
  49017. setBoundsForComponent (component, component->getBounds(),
  49018. false, false, false, false);
  49019. }
  49020. void ComponentBoundsConstrainer::applyBoundsToComponent (Component* component,
  49021. const Rectangle<int>& bounds)
  49022. {
  49023. component->setBounds (bounds);
  49024. }
  49025. void ComponentBoundsConstrainer::resizeStart()
  49026. {
  49027. }
  49028. void ComponentBoundsConstrainer::resizeEnd()
  49029. {
  49030. }
  49031. void ComponentBoundsConstrainer::checkBounds (Rectangle<int>& bounds,
  49032. const Rectangle<int>& old,
  49033. const Rectangle<int>& limits,
  49034. const bool isStretchingTop,
  49035. const bool isStretchingLeft,
  49036. const bool isStretchingBottom,
  49037. const bool isStretchingRight)
  49038. {
  49039. int x = bounds.getX();
  49040. int y = bounds.getY();
  49041. int w = bounds.getWidth();
  49042. int h = bounds.getHeight();
  49043. // constrain the size if it's being stretched..
  49044. if (isStretchingLeft)
  49045. {
  49046. x = jlimit (old.getRight() - maxW, old.getRight() - minW, x);
  49047. w = old.getRight() - x;
  49048. }
  49049. if (isStretchingRight)
  49050. {
  49051. w = jlimit (minW, maxW, w);
  49052. }
  49053. if (isStretchingTop)
  49054. {
  49055. y = jlimit (old.getBottom() - maxH, old.getBottom() - minH, y);
  49056. h = old.getBottom() - y;
  49057. }
  49058. if (isStretchingBottom)
  49059. {
  49060. h = jlimit (minH, maxH, h);
  49061. }
  49062. // constrain the aspect ratio if one has been specified..
  49063. if (aspectRatio > 0.0 && w > 0 && h > 0)
  49064. {
  49065. bool adjustWidth;
  49066. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  49067. {
  49068. adjustWidth = true;
  49069. }
  49070. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  49071. {
  49072. adjustWidth = false;
  49073. }
  49074. else
  49075. {
  49076. const double oldRatio = (old.getHeight() > 0) ? fabs (old.getWidth() / (double) old.getHeight()) : 0.0;
  49077. const double newRatio = fabs (w / (double) h);
  49078. adjustWidth = (oldRatio > newRatio);
  49079. }
  49080. if (adjustWidth)
  49081. {
  49082. w = roundToInt (h * aspectRatio);
  49083. if (w > maxW || w < minW)
  49084. {
  49085. w = jlimit (minW, maxW, w);
  49086. h = roundToInt (w / aspectRatio);
  49087. }
  49088. }
  49089. else
  49090. {
  49091. h = roundToInt (w / aspectRatio);
  49092. if (h > maxH || h < minH)
  49093. {
  49094. h = jlimit (minH, maxH, h);
  49095. w = roundToInt (h * aspectRatio);
  49096. }
  49097. }
  49098. if ((isStretchingTop || isStretchingBottom) && ! (isStretchingLeft || isStretchingRight))
  49099. {
  49100. x = old.getX() + (old.getWidth() - w) / 2;
  49101. }
  49102. else if ((isStretchingLeft || isStretchingRight) && ! (isStretchingTop || isStretchingBottom))
  49103. {
  49104. y = old.getY() + (old.getHeight() - h) / 2;
  49105. }
  49106. else
  49107. {
  49108. if (isStretchingLeft)
  49109. x = old.getRight() - w;
  49110. if (isStretchingTop)
  49111. y = old.getBottom() - h;
  49112. }
  49113. }
  49114. // ...and constrain the position if limits have been set for that.
  49115. if (minOffTop > 0 || minOffLeft > 0 || minOffBottom > 0 || minOffRight > 0)
  49116. {
  49117. if (minOffTop > 0)
  49118. {
  49119. const int limit = limits.getY() + jmin (minOffTop - h, 0);
  49120. if (y < limit)
  49121. {
  49122. if (isStretchingTop)
  49123. h -= (limit - y);
  49124. y = limit;
  49125. }
  49126. }
  49127. if (minOffLeft > 0)
  49128. {
  49129. const int limit = limits.getX() + jmin (minOffLeft - w, 0);
  49130. if (x < limit)
  49131. {
  49132. if (isStretchingLeft)
  49133. w -= (limit - x);
  49134. x = limit;
  49135. }
  49136. }
  49137. if (minOffBottom > 0)
  49138. {
  49139. const int limit = limits.getBottom() - jmin (minOffBottom, h);
  49140. if (y > limit)
  49141. {
  49142. if (isStretchingBottom)
  49143. h += (limit - y);
  49144. else
  49145. y = limit;
  49146. }
  49147. }
  49148. if (minOffRight > 0)
  49149. {
  49150. const int limit = limits.getRight() - jmin (minOffRight, w);
  49151. if (x > limit)
  49152. {
  49153. if (isStretchingRight)
  49154. w += (limit - x);
  49155. else
  49156. x = limit;
  49157. }
  49158. }
  49159. }
  49160. jassert (w >= 0 && h >= 0);
  49161. bounds = Rectangle<int> (x, y, w, h);
  49162. }
  49163. END_JUCE_NAMESPACE
  49164. /*** End of inlined file: juce_ComponentBoundsConstrainer.cpp ***/
  49165. /*** Start of inlined file: juce_ComponentMovementWatcher.cpp ***/
  49166. BEGIN_JUCE_NAMESPACE
  49167. ComponentMovementWatcher::ComponentMovementWatcher (Component* const component_)
  49168. : component (component_),
  49169. lastPeer (0),
  49170. reentrant (false)
  49171. {
  49172. jassert (component != 0); // can't use this with a null pointer..
  49173. #ifdef JUCE_DEBUG
  49174. deletionWatcher = new ComponentDeletionWatcher (component_);
  49175. #endif
  49176. component->addComponentListener (this);
  49177. registerWithParentComps();
  49178. }
  49179. ComponentMovementWatcher::~ComponentMovementWatcher()
  49180. {
  49181. component->removeComponentListener (this);
  49182. unregister();
  49183. }
  49184. void ComponentMovementWatcher::componentParentHierarchyChanged (Component&)
  49185. {
  49186. #ifdef JUCE_DEBUG
  49187. // agh! don't delete the target component without deleting this object first!
  49188. jassert (! deletionWatcher->hasBeenDeleted());
  49189. #endif
  49190. if (! reentrant)
  49191. {
  49192. reentrant = true;
  49193. ComponentPeer* const peer = component->getPeer();
  49194. if (peer != lastPeer)
  49195. {
  49196. ComponentDeletionWatcher watcher (component);
  49197. componentPeerChanged();
  49198. if (watcher.hasBeenDeleted())
  49199. return;
  49200. lastPeer = peer;
  49201. }
  49202. unregister();
  49203. registerWithParentComps();
  49204. reentrant = false;
  49205. componentMovedOrResized (*component, true, true);
  49206. }
  49207. }
  49208. void ComponentMovementWatcher::componentMovedOrResized (Component&, bool wasMoved, bool wasResized)
  49209. {
  49210. #ifdef JUCE_DEBUG
  49211. // agh! don't delete the target component without deleting this object first!
  49212. jassert (! deletionWatcher->hasBeenDeleted());
  49213. #endif
  49214. if (wasMoved)
  49215. {
  49216. const Point<int> pos (component->relativePositionToOtherComponent (component->getTopLevelComponent(), Point<int>()));
  49217. wasMoved = lastBounds.getPosition() != pos;
  49218. lastBounds.setPosition (pos);
  49219. }
  49220. wasResized = (lastBounds.getWidth() != component->getWidth() || lastBounds.getHeight() != component->getHeight());
  49221. lastBounds.setSize (component->getWidth(), component->getHeight());
  49222. if (wasMoved || wasResized)
  49223. componentMovedOrResized (wasMoved, wasResized);
  49224. }
  49225. void ComponentMovementWatcher::registerWithParentComps() throw()
  49226. {
  49227. Component* p = component->getParentComponent();
  49228. while (p != 0)
  49229. {
  49230. p->addComponentListener (this);
  49231. registeredParentComps.add (p);
  49232. p = p->getParentComponent();
  49233. }
  49234. }
  49235. void ComponentMovementWatcher::unregister() throw()
  49236. {
  49237. for (int i = registeredParentComps.size(); --i >= 0;)
  49238. ((Component*) registeredParentComps.getUnchecked(i))->removeComponentListener (this);
  49239. registeredParentComps.clear();
  49240. }
  49241. END_JUCE_NAMESPACE
  49242. /*** End of inlined file: juce_ComponentMovementWatcher.cpp ***/
  49243. /*** Start of inlined file: juce_GroupComponent.cpp ***/
  49244. BEGIN_JUCE_NAMESPACE
  49245. GroupComponent::GroupComponent (const String& componentName,
  49246. const String& labelText)
  49247. : Component (componentName),
  49248. text (labelText),
  49249. justification (Justification::left)
  49250. {
  49251. setInterceptsMouseClicks (false, true);
  49252. }
  49253. GroupComponent::~GroupComponent()
  49254. {
  49255. }
  49256. void GroupComponent::setText (const String& newText) throw()
  49257. {
  49258. if (text != newText)
  49259. {
  49260. text = newText;
  49261. repaint();
  49262. }
  49263. }
  49264. const String GroupComponent::getText() const throw()
  49265. {
  49266. return text;
  49267. }
  49268. void GroupComponent::setTextLabelPosition (const Justification& newJustification)
  49269. {
  49270. if (justification.getFlags() != newJustification.getFlags())
  49271. {
  49272. justification = newJustification;
  49273. repaint();
  49274. }
  49275. }
  49276. void GroupComponent::paint (Graphics& g)
  49277. {
  49278. getLookAndFeel()
  49279. .drawGroupComponentOutline (g, getWidth(), getHeight(),
  49280. text, justification,
  49281. *this);
  49282. }
  49283. void GroupComponent::enablementChanged()
  49284. {
  49285. repaint();
  49286. }
  49287. void GroupComponent::colourChanged()
  49288. {
  49289. repaint();
  49290. }
  49291. END_JUCE_NAMESPACE
  49292. /*** End of inlined file: juce_GroupComponent.cpp ***/
  49293. /*** Start of inlined file: juce_MultiDocumentPanel.cpp ***/
  49294. BEGIN_JUCE_NAMESPACE
  49295. MultiDocumentPanelWindow::MultiDocumentPanelWindow (const Colour& backgroundColour)
  49296. : DocumentWindow (String::empty, backgroundColour,
  49297. DocumentWindow::maximiseButton | DocumentWindow::closeButton, false)
  49298. {
  49299. }
  49300. MultiDocumentPanelWindow::~MultiDocumentPanelWindow()
  49301. {
  49302. }
  49303. void MultiDocumentPanelWindow::maximiseButtonPressed()
  49304. {
  49305. MultiDocumentPanel* const owner = getOwner();
  49306. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  49307. if (owner != 0)
  49308. owner->setLayoutMode (MultiDocumentPanel::MaximisedWindowsWithTabs);
  49309. }
  49310. void MultiDocumentPanelWindow::closeButtonPressed()
  49311. {
  49312. MultiDocumentPanel* const owner = getOwner();
  49313. jassert (owner != 0); // these windows are only designed to be used inside a MultiDocumentPanel!
  49314. if (owner != 0)
  49315. owner->closeDocument (getContentComponent(), true);
  49316. }
  49317. void MultiDocumentPanelWindow::activeWindowStatusChanged()
  49318. {
  49319. DocumentWindow::activeWindowStatusChanged();
  49320. updateOrder();
  49321. }
  49322. void MultiDocumentPanelWindow::broughtToFront()
  49323. {
  49324. DocumentWindow::broughtToFront();
  49325. updateOrder();
  49326. }
  49327. void MultiDocumentPanelWindow::updateOrder()
  49328. {
  49329. MultiDocumentPanel* const owner = getOwner();
  49330. if (owner != 0)
  49331. owner->updateOrder();
  49332. }
  49333. MultiDocumentPanel* MultiDocumentPanelWindow::getOwner() const throw()
  49334. {
  49335. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  49336. return findParentComponentOfClass ((MultiDocumentPanel*) 0);
  49337. }
  49338. class MDITabbedComponentInternal : public TabbedComponent
  49339. {
  49340. public:
  49341. MDITabbedComponentInternal()
  49342. : TabbedComponent (TabbedButtonBar::TabsAtTop)
  49343. {
  49344. }
  49345. ~MDITabbedComponentInternal()
  49346. {
  49347. }
  49348. void currentTabChanged (const int, const String&)
  49349. {
  49350. // (unable to use the syntax findParentComponentOfClass <MultiDocumentPanel> () because of a VC6 compiler bug)
  49351. MultiDocumentPanel* const owner = findParentComponentOfClass ((MultiDocumentPanel*) 0);
  49352. if (owner != 0)
  49353. owner->updateOrder();
  49354. }
  49355. };
  49356. MultiDocumentPanel::MultiDocumentPanel()
  49357. : mode (MaximisedWindowsWithTabs),
  49358. tabComponent (0),
  49359. backgroundColour (Colours::lightblue),
  49360. maximumNumDocuments (0),
  49361. numDocsBeforeTabsUsed (0)
  49362. {
  49363. setOpaque (true);
  49364. }
  49365. MultiDocumentPanel::~MultiDocumentPanel()
  49366. {
  49367. closeAllDocuments (false);
  49368. }
  49369. static bool shouldDeleteComp (Component* const c)
  49370. {
  49371. return c->getProperties() ["mdiDocumentDelete_"];
  49372. }
  49373. bool MultiDocumentPanel::closeAllDocuments (const bool checkItsOkToCloseFirst)
  49374. {
  49375. while (components.size() > 0)
  49376. if (! closeDocument (components.getLast(), checkItsOkToCloseFirst))
  49377. return false;
  49378. return true;
  49379. }
  49380. MultiDocumentPanelWindow* MultiDocumentPanel::createNewDocumentWindow()
  49381. {
  49382. return new MultiDocumentPanelWindow (backgroundColour);
  49383. }
  49384. void MultiDocumentPanel::addWindow (Component* component)
  49385. {
  49386. MultiDocumentPanelWindow* const dw = createNewDocumentWindow();
  49387. dw->setResizable (true, false);
  49388. dw->setContentComponent (component, false, true);
  49389. dw->setName (component->getName());
  49390. const var bkg (component->getProperties() ["mdiDocumentBkg_"]);
  49391. dw->setBackgroundColour (bkg.isVoid() ? backgroundColour : Colour ((int) bkg));
  49392. int x = 4;
  49393. Component* const topComp = getChildComponent (getNumChildComponents() - 1);
  49394. if (topComp != 0 && topComp->getX() == x && topComp->getY() == x)
  49395. x += 16;
  49396. dw->setTopLeftPosition (x, x);
  49397. const var pos (component->getProperties() ["mdiDocumentPos_"]);
  49398. if (pos.toString().isNotEmpty())
  49399. dw->restoreWindowStateFromString (pos.toString());
  49400. addAndMakeVisible (dw);
  49401. dw->toFront (true);
  49402. }
  49403. bool MultiDocumentPanel::addDocument (Component* const component,
  49404. const Colour& docColour,
  49405. const bool deleteWhenRemoved)
  49406. {
  49407. // If you try passing a full DocumentWindow or ResizableWindow in here, you'll end up
  49408. // with a frame-within-a-frame! Just pass in the bare content component.
  49409. jassert (dynamic_cast <ResizableWindow*> (component) == 0);
  49410. if (component == 0 || (maximumNumDocuments > 0 && components.size() >= maximumNumDocuments))
  49411. return false;
  49412. components.add (component);
  49413. component->getProperties().set ("mdiDocumentDelete_", deleteWhenRemoved);
  49414. component->getProperties().set ("mdiDocumentBkg_", (int) docColour.getARGB());
  49415. component->addComponentListener (this);
  49416. if (mode == FloatingWindows)
  49417. {
  49418. if (isFullscreenWhenOneDocument())
  49419. {
  49420. if (components.size() == 1)
  49421. {
  49422. addAndMakeVisible (component);
  49423. }
  49424. else
  49425. {
  49426. if (components.size() == 2)
  49427. addWindow (components.getFirst());
  49428. addWindow (component);
  49429. }
  49430. }
  49431. else
  49432. {
  49433. addWindow (component);
  49434. }
  49435. }
  49436. else
  49437. {
  49438. if (tabComponent == 0 && components.size() > numDocsBeforeTabsUsed)
  49439. {
  49440. addAndMakeVisible (tabComponent = new MDITabbedComponentInternal());
  49441. Array <Component*> temp (components);
  49442. for (int i = 0; i < temp.size(); ++i)
  49443. tabComponent->addTab (temp[i]->getName(), docColour, temp[i], false);
  49444. resized();
  49445. }
  49446. else
  49447. {
  49448. if (tabComponent != 0)
  49449. tabComponent->addTab (component->getName(), docColour, component, false);
  49450. else
  49451. addAndMakeVisible (component);
  49452. }
  49453. setActiveDocument (component);
  49454. }
  49455. resized();
  49456. activeDocumentChanged();
  49457. return true;
  49458. }
  49459. bool MultiDocumentPanel::closeDocument (Component* component,
  49460. const bool checkItsOkToCloseFirst)
  49461. {
  49462. if (components.contains (component))
  49463. {
  49464. if (checkItsOkToCloseFirst && ! tryToCloseDocument (component))
  49465. return false;
  49466. component->removeComponentListener (this);
  49467. const bool shouldDelete = shouldDeleteComp (component);
  49468. component->getProperties().remove ("mdiDocumentDelete_");
  49469. component->getProperties().remove ("mdiDocumentBkg_");
  49470. if (mode == FloatingWindows)
  49471. {
  49472. for (int i = getNumChildComponents(); --i >= 0;)
  49473. {
  49474. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49475. if (dw != 0 && dw->getContentComponent() == component)
  49476. {
  49477. dw->setContentComponent (0, false);
  49478. delete dw;
  49479. break;
  49480. }
  49481. }
  49482. if (shouldDelete)
  49483. delete component;
  49484. components.removeValue (component);
  49485. if (isFullscreenWhenOneDocument() && components.size() == 1)
  49486. {
  49487. for (int i = getNumChildComponents(); --i >= 0;)
  49488. {
  49489. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49490. if (dw != 0)
  49491. {
  49492. dw->setContentComponent (0, false);
  49493. delete dw;
  49494. }
  49495. }
  49496. addAndMakeVisible (components.getFirst());
  49497. }
  49498. }
  49499. else
  49500. {
  49501. jassert (components.indexOf (component) >= 0);
  49502. if (tabComponent != 0)
  49503. {
  49504. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49505. if (tabComponent->getTabContentComponent (i) == component)
  49506. tabComponent->removeTab (i);
  49507. }
  49508. else
  49509. {
  49510. removeChildComponent (component);
  49511. }
  49512. if (shouldDelete)
  49513. delete component;
  49514. if (tabComponent != 0 && tabComponent->getNumTabs() <= numDocsBeforeTabsUsed)
  49515. deleteAndZero (tabComponent);
  49516. components.removeValue (component);
  49517. if (components.size() > 0 && tabComponent == 0)
  49518. addAndMakeVisible (components.getFirst());
  49519. }
  49520. resized();
  49521. activeDocumentChanged();
  49522. }
  49523. else
  49524. {
  49525. jassertfalse
  49526. }
  49527. return true;
  49528. }
  49529. int MultiDocumentPanel::getNumDocuments() const throw()
  49530. {
  49531. return components.size();
  49532. }
  49533. Component* MultiDocumentPanel::getDocument (const int index) const throw()
  49534. {
  49535. return components [index];
  49536. }
  49537. Component* MultiDocumentPanel::getActiveDocument() const throw()
  49538. {
  49539. if (mode == FloatingWindows)
  49540. {
  49541. for (int i = getNumChildComponents(); --i >= 0;)
  49542. {
  49543. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49544. if (dw != 0 && dw->isActiveWindow())
  49545. return dw->getContentComponent();
  49546. }
  49547. }
  49548. return components.getLast();
  49549. }
  49550. void MultiDocumentPanel::setActiveDocument (Component* component)
  49551. {
  49552. if (mode == FloatingWindows)
  49553. {
  49554. component = getContainerComp (component);
  49555. if (component != 0)
  49556. component->toFront (true);
  49557. }
  49558. else if (tabComponent != 0)
  49559. {
  49560. jassert (components.indexOf (component) >= 0);
  49561. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49562. {
  49563. if (tabComponent->getTabContentComponent (i) == component)
  49564. {
  49565. tabComponent->setCurrentTabIndex (i);
  49566. break;
  49567. }
  49568. }
  49569. }
  49570. else
  49571. {
  49572. component->grabKeyboardFocus();
  49573. }
  49574. }
  49575. void MultiDocumentPanel::activeDocumentChanged()
  49576. {
  49577. }
  49578. void MultiDocumentPanel::setMaximumNumDocuments (const int newNumber)
  49579. {
  49580. maximumNumDocuments = newNumber;
  49581. }
  49582. void MultiDocumentPanel::useFullscreenWhenOneDocument (const bool shouldUseTabs)
  49583. {
  49584. numDocsBeforeTabsUsed = shouldUseTabs ? 1 : 0;
  49585. }
  49586. bool MultiDocumentPanel::isFullscreenWhenOneDocument() const throw()
  49587. {
  49588. return numDocsBeforeTabsUsed != 0;
  49589. }
  49590. void MultiDocumentPanel::setLayoutMode (const LayoutMode newLayoutMode)
  49591. {
  49592. if (mode != newLayoutMode)
  49593. {
  49594. mode = newLayoutMode;
  49595. if (mode == FloatingWindows)
  49596. {
  49597. deleteAndZero (tabComponent);
  49598. }
  49599. else
  49600. {
  49601. for (int i = getNumChildComponents(); --i >= 0;)
  49602. {
  49603. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49604. if (dw != 0)
  49605. {
  49606. dw->getContentComponent()->getProperties().set ("mdiDocumentPos_", dw->getWindowStateAsString());
  49607. dw->setContentComponent (0, false);
  49608. delete dw;
  49609. }
  49610. }
  49611. }
  49612. resized();
  49613. const Array <Component*> tempComps (components);
  49614. components.clear();
  49615. for (int i = 0; i < tempComps.size(); ++i)
  49616. {
  49617. Component* const c = tempComps.getUnchecked(i);
  49618. addDocument (c,
  49619. Colour ((int) c->getProperties().getWithDefault ("mdiDocumentBkg_", (int) Colours::white.getARGB())),
  49620. shouldDeleteComp (c));
  49621. }
  49622. }
  49623. }
  49624. void MultiDocumentPanel::setBackgroundColour (const Colour& newBackgroundColour)
  49625. {
  49626. if (backgroundColour != newBackgroundColour)
  49627. {
  49628. backgroundColour = newBackgroundColour;
  49629. setOpaque (newBackgroundColour.isOpaque());
  49630. repaint();
  49631. }
  49632. }
  49633. void MultiDocumentPanel::paint (Graphics& g)
  49634. {
  49635. g.fillAll (backgroundColour);
  49636. }
  49637. void MultiDocumentPanel::resized()
  49638. {
  49639. if (mode == MaximisedWindowsWithTabs || components.size() == numDocsBeforeTabsUsed)
  49640. {
  49641. for (int i = getNumChildComponents(); --i >= 0;)
  49642. getChildComponent (i)->setBounds (0, 0, getWidth(), getHeight());
  49643. }
  49644. setWantsKeyboardFocus (components.size() == 0);
  49645. }
  49646. Component* MultiDocumentPanel::getContainerComp (Component* c) const
  49647. {
  49648. if (mode == FloatingWindows)
  49649. {
  49650. for (int i = 0; i < getNumChildComponents(); ++i)
  49651. {
  49652. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49653. if (dw != 0 && dw->getContentComponent() == c)
  49654. {
  49655. c = dw;
  49656. break;
  49657. }
  49658. }
  49659. }
  49660. return c;
  49661. }
  49662. void MultiDocumentPanel::componentNameChanged (Component&)
  49663. {
  49664. if (mode == FloatingWindows)
  49665. {
  49666. for (int i = 0; i < getNumChildComponents(); ++i)
  49667. {
  49668. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49669. if (dw != 0)
  49670. dw->setName (dw->getContentComponent()->getName());
  49671. }
  49672. }
  49673. else if (tabComponent != 0)
  49674. {
  49675. for (int i = tabComponent->getNumTabs(); --i >= 0;)
  49676. tabComponent->setTabName (i, tabComponent->getTabContentComponent (i)->getName());
  49677. }
  49678. }
  49679. void MultiDocumentPanel::updateOrder()
  49680. {
  49681. const Array <Component*> oldList (components);
  49682. if (mode == FloatingWindows)
  49683. {
  49684. components.clear();
  49685. for (int i = 0; i < getNumChildComponents(); ++i)
  49686. {
  49687. MultiDocumentPanelWindow* const dw = dynamic_cast <MultiDocumentPanelWindow*> (getChildComponent (i));
  49688. if (dw != 0)
  49689. components.add (dw->getContentComponent());
  49690. }
  49691. }
  49692. else
  49693. {
  49694. if (tabComponent != 0)
  49695. {
  49696. Component* const current = tabComponent->getCurrentContentComponent();
  49697. if (current != 0)
  49698. {
  49699. components.removeValue (current);
  49700. components.add (current);
  49701. }
  49702. }
  49703. }
  49704. if (components != oldList)
  49705. activeDocumentChanged();
  49706. }
  49707. END_JUCE_NAMESPACE
  49708. /*** End of inlined file: juce_MultiDocumentPanel.cpp ***/
  49709. /*** Start of inlined file: juce_ResizableBorderComponent.cpp ***/
  49710. BEGIN_JUCE_NAMESPACE
  49711. const int zoneL = 1;
  49712. const int zoneR = 2;
  49713. const int zoneT = 4;
  49714. const int zoneB = 8;
  49715. ResizableBorderComponent::ResizableBorderComponent (Component* const componentToResize,
  49716. ComponentBoundsConstrainer* const constrainer_)
  49717. : component (componentToResize),
  49718. constrainer (constrainer_),
  49719. borderSize (5),
  49720. mouseZone (0)
  49721. {
  49722. }
  49723. ResizableBorderComponent::~ResizableBorderComponent()
  49724. {
  49725. }
  49726. void ResizableBorderComponent::paint (Graphics& g)
  49727. {
  49728. getLookAndFeel().drawResizableFrame (g, getWidth(), getHeight(), borderSize);
  49729. }
  49730. void ResizableBorderComponent::mouseEnter (const MouseEvent& e)
  49731. {
  49732. updateMouseZone (e);
  49733. }
  49734. void ResizableBorderComponent::mouseMove (const MouseEvent& e)
  49735. {
  49736. updateMouseZone (e);
  49737. }
  49738. void ResizableBorderComponent::mouseDown (const MouseEvent& e)
  49739. {
  49740. if (component->isValidComponent())
  49741. {
  49742. updateMouseZone (e);
  49743. originalX = component->getX();
  49744. originalY = component->getY();
  49745. originalW = component->getWidth();
  49746. originalH = component->getHeight();
  49747. if (constrainer != 0)
  49748. constrainer->resizeStart();
  49749. }
  49750. else
  49751. {
  49752. jassertfalse
  49753. }
  49754. }
  49755. void ResizableBorderComponent::mouseDrag (const MouseEvent& e)
  49756. {
  49757. if (! component->isValidComponent())
  49758. {
  49759. jassertfalse
  49760. return;
  49761. }
  49762. int x = originalX;
  49763. int y = originalY;
  49764. int w = originalW;
  49765. int h = originalH;
  49766. const int dx = e.getDistanceFromDragStartX();
  49767. const int dy = e.getDistanceFromDragStartY();
  49768. if ((mouseZone & zoneL) != 0)
  49769. {
  49770. x += dx;
  49771. w -= dx;
  49772. }
  49773. if ((mouseZone & zoneT) != 0)
  49774. {
  49775. y += dy;
  49776. h -= dy;
  49777. }
  49778. if ((mouseZone & zoneR) != 0)
  49779. w += dx;
  49780. if ((mouseZone & zoneB) != 0)
  49781. h += dy;
  49782. if (constrainer != 0)
  49783. constrainer->setBoundsForComponent (component,
  49784. Rectangle<int> (x, y, w, h),
  49785. (mouseZone & zoneT) != 0,
  49786. (mouseZone & zoneL) != 0,
  49787. (mouseZone & zoneB) != 0,
  49788. (mouseZone & zoneR) != 0);
  49789. else
  49790. component->setBounds (x, y, w, h);
  49791. }
  49792. void ResizableBorderComponent::mouseUp (const MouseEvent&)
  49793. {
  49794. if (constrainer != 0)
  49795. constrainer->resizeEnd();
  49796. }
  49797. bool ResizableBorderComponent::hitTest (int x, int y)
  49798. {
  49799. return x < borderSize.getLeft()
  49800. || x >= getWidth() - borderSize.getRight()
  49801. || y < borderSize.getTop()
  49802. || y >= getHeight() - borderSize.getBottom();
  49803. }
  49804. void ResizableBorderComponent::setBorderThickness (const BorderSize& newBorderSize) throw()
  49805. {
  49806. if (borderSize != newBorderSize)
  49807. {
  49808. borderSize = newBorderSize;
  49809. repaint();
  49810. }
  49811. }
  49812. const BorderSize ResizableBorderComponent::getBorderThickness() const throw()
  49813. {
  49814. return borderSize;
  49815. }
  49816. void ResizableBorderComponent::updateMouseZone (const MouseEvent& e) throw()
  49817. {
  49818. int newZone = 0;
  49819. if (ResizableBorderComponent::hitTest (e.x, e.y))
  49820. {
  49821. if (e.x < jmax (borderSize.getLeft(),
  49822. proportionOfWidth (0.1f),
  49823. jmin (10, proportionOfWidth (0.33f))))
  49824. newZone |= zoneL;
  49825. else if (e.x >= jmin (getWidth() - borderSize.getRight(),
  49826. proportionOfWidth (0.9f),
  49827. getWidth() - jmin (10, proportionOfWidth (0.33f))))
  49828. newZone |= zoneR;
  49829. if (e.y < jmax (borderSize.getTop(),
  49830. proportionOfHeight (0.1f),
  49831. jmin (10, proportionOfHeight (0.33f))))
  49832. newZone |= zoneT;
  49833. else if (e.y >= jmin (getHeight() - borderSize.getBottom(),
  49834. proportionOfHeight (0.9f),
  49835. getHeight() - jmin (10, proportionOfHeight (0.33f))))
  49836. newZone |= zoneB;
  49837. }
  49838. if (mouseZone != newZone)
  49839. {
  49840. mouseZone = newZone;
  49841. MouseCursor::StandardCursorType mc = MouseCursor::NormalCursor;
  49842. switch (newZone)
  49843. {
  49844. case (zoneL | zoneT):
  49845. mc = MouseCursor::TopLeftCornerResizeCursor;
  49846. break;
  49847. case zoneT:
  49848. mc = MouseCursor::TopEdgeResizeCursor;
  49849. break;
  49850. case (zoneR | zoneT):
  49851. mc = MouseCursor::TopRightCornerResizeCursor;
  49852. break;
  49853. case zoneL:
  49854. mc = MouseCursor::LeftEdgeResizeCursor;
  49855. break;
  49856. case zoneR:
  49857. mc = MouseCursor::RightEdgeResizeCursor;
  49858. break;
  49859. case (zoneL | zoneB):
  49860. mc = MouseCursor::BottomLeftCornerResizeCursor;
  49861. break;
  49862. case zoneB:
  49863. mc = MouseCursor::BottomEdgeResizeCursor;
  49864. break;
  49865. case (zoneR | zoneB):
  49866. mc = MouseCursor::BottomRightCornerResizeCursor;
  49867. break;
  49868. default:
  49869. break;
  49870. }
  49871. setMouseCursor (mc);
  49872. }
  49873. }
  49874. END_JUCE_NAMESPACE
  49875. /*** End of inlined file: juce_ResizableBorderComponent.cpp ***/
  49876. /*** Start of inlined file: juce_ResizableCornerComponent.cpp ***/
  49877. BEGIN_JUCE_NAMESPACE
  49878. ResizableCornerComponent::ResizableCornerComponent (Component* const componentToResize,
  49879. ComponentBoundsConstrainer* const constrainer_)
  49880. : component (componentToResize),
  49881. constrainer (constrainer_)
  49882. {
  49883. setRepaintsOnMouseActivity (true);
  49884. setMouseCursor (MouseCursor::BottomRightCornerResizeCursor);
  49885. }
  49886. ResizableCornerComponent::~ResizableCornerComponent()
  49887. {
  49888. }
  49889. void ResizableCornerComponent::paint (Graphics& g)
  49890. {
  49891. getLookAndFeel()
  49892. .drawCornerResizer (g, getWidth(), getHeight(),
  49893. isMouseOverOrDragging(),
  49894. isMouseButtonDown());
  49895. }
  49896. void ResizableCornerComponent::mouseDown (const MouseEvent&)
  49897. {
  49898. if (component->isValidComponent())
  49899. {
  49900. originalX = component->getX();
  49901. originalY = component->getY();
  49902. originalW = component->getWidth();
  49903. originalH = component->getHeight();
  49904. if (constrainer != 0)
  49905. constrainer->resizeStart();
  49906. }
  49907. else
  49908. {
  49909. jassertfalse
  49910. }
  49911. }
  49912. void ResizableCornerComponent::mouseDrag (const MouseEvent& e)
  49913. {
  49914. if (! component->isValidComponent())
  49915. {
  49916. jassertfalse
  49917. return;
  49918. }
  49919. int x = originalX;
  49920. int y = originalY;
  49921. int w = originalW + e.getDistanceFromDragStartX();
  49922. int h = originalH + e.getDistanceFromDragStartY();
  49923. if (constrainer != 0)
  49924. constrainer->setBoundsForComponent (component, Rectangle<int> (x, y, w, h),
  49925. false, false, true, true);
  49926. else
  49927. component->setBounds (x, y, w, h);
  49928. }
  49929. void ResizableCornerComponent::mouseUp (const MouseEvent&)
  49930. {
  49931. if (constrainer != 0)
  49932. constrainer->resizeStart();
  49933. }
  49934. bool ResizableCornerComponent::hitTest (int x, int y)
  49935. {
  49936. if (getWidth() <= 0)
  49937. return false;
  49938. const int yAtX = getHeight() - (getHeight() * x / getWidth());
  49939. return y >= yAtX - getHeight() / 4;
  49940. }
  49941. END_JUCE_NAMESPACE
  49942. /*** End of inlined file: juce_ResizableCornerComponent.cpp ***/
  49943. /*** Start of inlined file: juce_ScrollBar.cpp ***/
  49944. BEGIN_JUCE_NAMESPACE
  49945. class ScrollbarButton : public Button
  49946. {
  49947. public:
  49948. int direction;
  49949. ScrollbarButton (const int direction_,
  49950. ScrollBar& owner_) throw()
  49951. : Button (String::empty),
  49952. direction (direction_),
  49953. owner (owner_)
  49954. {
  49955. setWantsKeyboardFocus (false);
  49956. }
  49957. ~ScrollbarButton()
  49958. {
  49959. }
  49960. void paintButton (Graphics& g,
  49961. bool isMouseOver,
  49962. bool isMouseDown)
  49963. {
  49964. getLookAndFeel()
  49965. .drawScrollbarButton (g, owner,
  49966. getWidth(), getHeight(),
  49967. direction,
  49968. owner.isVertical(),
  49969. isMouseOver, isMouseDown);
  49970. }
  49971. void clicked()
  49972. {
  49973. owner.moveScrollbarInSteps ((direction == 1 || direction == 2) ? 1 : -1);
  49974. }
  49975. juce_UseDebuggingNewOperator
  49976. private:
  49977. ScrollBar& owner;
  49978. ScrollbarButton (const ScrollbarButton&);
  49979. ScrollbarButton& operator= (const ScrollbarButton&);
  49980. };
  49981. ScrollBar::ScrollBar (const bool vertical_,
  49982. const bool buttonsAreVisible)
  49983. : minimum (0.0),
  49984. maximum (1.0),
  49985. rangeStart (0.0),
  49986. rangeSize (0.1),
  49987. singleStepSize (0.1),
  49988. thumbAreaStart (0),
  49989. thumbAreaSize (0),
  49990. thumbStart (0),
  49991. thumbSize (0),
  49992. initialDelayInMillisecs (100),
  49993. repeatDelayInMillisecs (50),
  49994. minimumDelayInMillisecs (10),
  49995. vertical (vertical_),
  49996. isDraggingThumb (false),
  49997. alwaysVisible (false),
  49998. upButton (0),
  49999. downButton (0)
  50000. {
  50001. setButtonVisibility (buttonsAreVisible);
  50002. setRepaintsOnMouseActivity (true);
  50003. setFocusContainer (true);
  50004. }
  50005. ScrollBar::~ScrollBar()
  50006. {
  50007. deleteAllChildren();
  50008. }
  50009. void ScrollBar::setRangeLimits (const double newMinimum,
  50010. const double newMaximum) throw()
  50011. {
  50012. minimum = newMinimum;
  50013. maximum = newMaximum;
  50014. jassert (maximum >= minimum); // these can't be the wrong way round!
  50015. setCurrentRangeStart (rangeStart);
  50016. updateThumbPosition();
  50017. }
  50018. void ScrollBar::setCurrentRange (double newStart,
  50019. double newSize) throw()
  50020. {
  50021. newSize = jlimit (0.0, maximum - minimum, newSize);
  50022. newStart = jlimit (minimum, maximum - newSize, newStart);
  50023. if (rangeStart != newStart
  50024. || rangeSize != newSize)
  50025. {
  50026. rangeStart = newStart;
  50027. rangeSize = newSize;
  50028. updateThumbPosition();
  50029. triggerAsyncUpdate();
  50030. }
  50031. }
  50032. void ScrollBar::setCurrentRangeStart (double newStart) throw()
  50033. {
  50034. setCurrentRange (newStart, rangeSize);
  50035. }
  50036. void ScrollBar::setSingleStepSize (const double newSingleStepSize) throw()
  50037. {
  50038. singleStepSize = newSingleStepSize;
  50039. }
  50040. void ScrollBar::moveScrollbarInSteps (const int howManySteps) throw()
  50041. {
  50042. setCurrentRangeStart (rangeStart + howManySteps * singleStepSize);
  50043. }
  50044. void ScrollBar::moveScrollbarInPages (const int howManyPages) throw()
  50045. {
  50046. setCurrentRangeStart (rangeStart + howManyPages * rangeSize);
  50047. }
  50048. void ScrollBar::scrollToTop() throw()
  50049. {
  50050. setCurrentRangeStart (minimum);
  50051. }
  50052. void ScrollBar::scrollToBottom() throw()
  50053. {
  50054. setCurrentRangeStart (maximum - rangeSize);
  50055. }
  50056. void ScrollBar::setButtonRepeatSpeed (const int initialDelayInMillisecs_,
  50057. const int repeatDelayInMillisecs_,
  50058. const int minimumDelayInMillisecs_) throw()
  50059. {
  50060. initialDelayInMillisecs = initialDelayInMillisecs_;
  50061. repeatDelayInMillisecs = repeatDelayInMillisecs_;
  50062. minimumDelayInMillisecs = minimumDelayInMillisecs_;
  50063. if (upButton != 0)
  50064. {
  50065. upButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50066. downButton->setRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50067. }
  50068. }
  50069. void ScrollBar::addListener (ScrollBarListener* const listener) throw()
  50070. {
  50071. jassert (listener != 0);
  50072. if (listener != 0)
  50073. listeners.add (listener);
  50074. }
  50075. void ScrollBar::removeListener (ScrollBarListener* const listener) throw()
  50076. {
  50077. listeners.removeValue (listener);
  50078. }
  50079. void ScrollBar::handleAsyncUpdate()
  50080. {
  50081. const double value = getCurrentRangeStart();
  50082. for (int i = listeners.size(); --i >= 0;)
  50083. {
  50084. ((ScrollBarListener*) listeners.getUnchecked (i))->scrollBarMoved (this, value);
  50085. i = jmin (i, listeners.size());
  50086. }
  50087. }
  50088. void ScrollBar::updateThumbPosition() throw()
  50089. {
  50090. int newThumbSize = roundToInt ((maximum > minimum) ? (rangeSize * thumbAreaSize) / (maximum - minimum)
  50091. : thumbAreaSize);
  50092. if (newThumbSize < getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50093. newThumbSize = jmin (getLookAndFeel().getMinimumScrollbarThumbSize (*this), thumbAreaSize - 1);
  50094. if (newThumbSize > thumbAreaSize)
  50095. newThumbSize = thumbAreaSize;
  50096. int newThumbStart = thumbAreaStart;
  50097. if (maximum - minimum > rangeSize)
  50098. newThumbStart += roundToInt (((rangeStart - minimum) * (thumbAreaSize - newThumbSize))
  50099. / ((maximum - minimum) - rangeSize));
  50100. setVisible (alwaysVisible || (maximum - minimum > rangeSize && rangeSize > 0.0));
  50101. if (thumbStart != newThumbStart || thumbSize != newThumbSize)
  50102. {
  50103. const int repaintStart = jmin (thumbStart, newThumbStart) - 4;
  50104. const int repaintSize = jmax (thumbStart + thumbSize, newThumbStart + newThumbSize) + 8 - repaintStart;
  50105. if (vertical)
  50106. repaint (0, repaintStart, getWidth(), repaintSize);
  50107. else
  50108. repaint (repaintStart, 0, repaintSize, getHeight());
  50109. thumbStart = newThumbStart;
  50110. thumbSize = newThumbSize;
  50111. }
  50112. }
  50113. void ScrollBar::setOrientation (const bool shouldBeVertical) throw()
  50114. {
  50115. if (vertical != shouldBeVertical)
  50116. {
  50117. vertical = shouldBeVertical;
  50118. if (upButton != 0)
  50119. {
  50120. ((ScrollbarButton*) upButton)->direction = (vertical) ? 0 : 3;
  50121. ((ScrollbarButton*) downButton)->direction = (vertical) ? 2 : 1;
  50122. }
  50123. updateThumbPosition();
  50124. }
  50125. }
  50126. void ScrollBar::setButtonVisibility (const bool buttonsAreVisible)
  50127. {
  50128. deleteAndZero (upButton);
  50129. deleteAndZero (downButton);
  50130. if (buttonsAreVisible)
  50131. {
  50132. addAndMakeVisible (upButton = new ScrollbarButton ((vertical) ? 0 : 3, *this));
  50133. addAndMakeVisible (downButton = new ScrollbarButton ((vertical) ? 2 : 1, *this));
  50134. setButtonRepeatSpeed (initialDelayInMillisecs, repeatDelayInMillisecs, minimumDelayInMillisecs);
  50135. }
  50136. updateThumbPosition();
  50137. }
  50138. void ScrollBar::setAutoHide (const bool shouldHideWhenFullRange)
  50139. {
  50140. alwaysVisible = ! shouldHideWhenFullRange;
  50141. updateThumbPosition();
  50142. }
  50143. void ScrollBar::paint (Graphics& g)
  50144. {
  50145. if (thumbAreaSize > 0)
  50146. {
  50147. LookAndFeel& lf = getLookAndFeel();
  50148. const int thumb = (thumbAreaSize > lf.getMinimumScrollbarThumbSize (*this))
  50149. ? thumbSize : 0;
  50150. if (vertical)
  50151. {
  50152. lf.drawScrollbar (g, *this,
  50153. 0, thumbAreaStart,
  50154. getWidth(), thumbAreaSize,
  50155. vertical,
  50156. thumbStart, thumb,
  50157. isMouseOver(), isMouseButtonDown());
  50158. }
  50159. else
  50160. {
  50161. lf.drawScrollbar (g, *this,
  50162. thumbAreaStart, 0,
  50163. thumbAreaSize, getHeight(),
  50164. vertical,
  50165. thumbStart, thumb,
  50166. isMouseOver(), isMouseButtonDown());
  50167. }
  50168. }
  50169. }
  50170. void ScrollBar::lookAndFeelChanged()
  50171. {
  50172. setComponentEffect (getLookAndFeel().getScrollbarEffect());
  50173. }
  50174. void ScrollBar::resized()
  50175. {
  50176. const int length = ((vertical) ? getHeight() : getWidth());
  50177. const int buttonSize = (upButton != 0) ? jmin (getLookAndFeel().getScrollbarButtonSize (*this), (length >> 1))
  50178. : 0;
  50179. if (length < 32 + getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50180. {
  50181. thumbAreaStart = length >> 1;
  50182. thumbAreaSize = 0;
  50183. }
  50184. else
  50185. {
  50186. thumbAreaStart = buttonSize;
  50187. thumbAreaSize = length - (buttonSize << 1);
  50188. }
  50189. if (upButton != 0)
  50190. {
  50191. if (vertical)
  50192. {
  50193. upButton->setBounds (0, 0, getWidth(), buttonSize);
  50194. downButton->setBounds (0, thumbAreaStart + thumbAreaSize, getWidth(), buttonSize);
  50195. }
  50196. else
  50197. {
  50198. upButton->setBounds (0, 0, buttonSize, getHeight());
  50199. downButton->setBounds (thumbAreaStart + thumbAreaSize, 0, buttonSize, getHeight());
  50200. }
  50201. }
  50202. updateThumbPosition();
  50203. }
  50204. void ScrollBar::mouseDown (const MouseEvent& e)
  50205. {
  50206. isDraggingThumb = false;
  50207. lastMousePos = vertical ? e.y : e.x;
  50208. dragStartMousePos = lastMousePos;
  50209. dragStartRange = rangeStart;
  50210. if (dragStartMousePos < thumbStart)
  50211. {
  50212. moveScrollbarInPages (-1);
  50213. startTimer (400);
  50214. }
  50215. else if (dragStartMousePos >= thumbStart + thumbSize)
  50216. {
  50217. moveScrollbarInPages (1);
  50218. startTimer (400);
  50219. }
  50220. else
  50221. {
  50222. isDraggingThumb = (thumbAreaSize > getLookAndFeel().getMinimumScrollbarThumbSize (*this))
  50223. && (thumbAreaSize > thumbSize);
  50224. }
  50225. }
  50226. void ScrollBar::mouseDrag (const MouseEvent& e)
  50227. {
  50228. if (isDraggingThumb)
  50229. {
  50230. const int deltaPixels = ((vertical) ? e.y : e.x) - dragStartMousePos;
  50231. setCurrentRangeStart (dragStartRange
  50232. + deltaPixels * ((maximum - minimum) - rangeSize)
  50233. / (thumbAreaSize - thumbSize));
  50234. }
  50235. else
  50236. {
  50237. lastMousePos = (vertical) ? e.y : e.x;
  50238. }
  50239. }
  50240. void ScrollBar::mouseUp (const MouseEvent&)
  50241. {
  50242. isDraggingThumb = false;
  50243. stopTimer();
  50244. repaint();
  50245. }
  50246. void ScrollBar::mouseWheelMove (const MouseEvent&,
  50247. float wheelIncrementX,
  50248. float wheelIncrementY)
  50249. {
  50250. float increment = vertical ? wheelIncrementY : wheelIncrementX;
  50251. if (increment < 0)
  50252. increment = jmin (increment * 10.0f, -1.0f);
  50253. else if (increment > 0)
  50254. increment = jmax (increment * 10.0f, 1.0f);
  50255. setCurrentRangeStart (rangeStart - singleStepSize * increment);
  50256. }
  50257. void ScrollBar::timerCallback()
  50258. {
  50259. if (isMouseButtonDown())
  50260. {
  50261. startTimer (40);
  50262. if (lastMousePos < thumbStart)
  50263. setCurrentRangeStart (rangeStart - rangeSize);
  50264. else if (lastMousePos > thumbStart + thumbSize)
  50265. setCurrentRangeStart (rangeStart + rangeSize);
  50266. }
  50267. else
  50268. {
  50269. stopTimer();
  50270. }
  50271. }
  50272. bool ScrollBar::keyPressed (const KeyPress& key)
  50273. {
  50274. if (! isVisible())
  50275. return false;
  50276. if (key.isKeyCode (KeyPress::upKey) || key.isKeyCode (KeyPress::leftKey))
  50277. moveScrollbarInSteps (-1);
  50278. else if (key.isKeyCode (KeyPress::downKey) || key.isKeyCode (KeyPress::rightKey))
  50279. moveScrollbarInSteps (1);
  50280. else if (key.isKeyCode (KeyPress::pageUpKey))
  50281. moveScrollbarInPages (-1);
  50282. else if (key.isKeyCode (KeyPress::pageDownKey))
  50283. moveScrollbarInPages (1);
  50284. else if (key.isKeyCode (KeyPress::homeKey))
  50285. scrollToTop();
  50286. else if (key.isKeyCode (KeyPress::endKey))
  50287. scrollToBottom();
  50288. else
  50289. return false;
  50290. return true;
  50291. }
  50292. END_JUCE_NAMESPACE
  50293. /*** End of inlined file: juce_ScrollBar.cpp ***/
  50294. /*** Start of inlined file: juce_StretchableLayoutManager.cpp ***/
  50295. BEGIN_JUCE_NAMESPACE
  50296. StretchableLayoutManager::StretchableLayoutManager()
  50297. : totalSize (0)
  50298. {
  50299. }
  50300. StretchableLayoutManager::~StretchableLayoutManager()
  50301. {
  50302. }
  50303. void StretchableLayoutManager::clearAllItems()
  50304. {
  50305. items.clear();
  50306. totalSize = 0;
  50307. }
  50308. void StretchableLayoutManager::setItemLayout (const int itemIndex,
  50309. const double minimumSize,
  50310. const double maximumSize,
  50311. const double preferredSize)
  50312. {
  50313. ItemLayoutProperties* layout = getInfoFor (itemIndex);
  50314. if (layout == 0)
  50315. {
  50316. layout = new ItemLayoutProperties();
  50317. layout->itemIndex = itemIndex;
  50318. int i;
  50319. for (i = 0; i < items.size(); ++i)
  50320. if (items.getUnchecked (i)->itemIndex > itemIndex)
  50321. break;
  50322. items.insert (i, layout);
  50323. }
  50324. layout->minSize = minimumSize;
  50325. layout->maxSize = maximumSize;
  50326. layout->preferredSize = preferredSize;
  50327. layout->currentSize = 0;
  50328. }
  50329. bool StretchableLayoutManager::getItemLayout (const int itemIndex,
  50330. double& minimumSize,
  50331. double& maximumSize,
  50332. double& preferredSize) const
  50333. {
  50334. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50335. if (layout != 0)
  50336. {
  50337. minimumSize = layout->minSize;
  50338. maximumSize = layout->maxSize;
  50339. preferredSize = layout->preferredSize;
  50340. return true;
  50341. }
  50342. return false;
  50343. }
  50344. void StretchableLayoutManager::setTotalSize (const int newTotalSize)
  50345. {
  50346. totalSize = newTotalSize;
  50347. fitComponentsIntoSpace (0, items.size(), totalSize, 0);
  50348. }
  50349. int StretchableLayoutManager::getItemCurrentPosition (const int itemIndex) const
  50350. {
  50351. int pos = 0;
  50352. for (int i = 0; i < itemIndex; ++i)
  50353. {
  50354. const ItemLayoutProperties* const layout = getInfoFor (i);
  50355. if (layout != 0)
  50356. pos += layout->currentSize;
  50357. }
  50358. return pos;
  50359. }
  50360. int StretchableLayoutManager::getItemCurrentAbsoluteSize (const int itemIndex) const
  50361. {
  50362. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50363. if (layout != 0)
  50364. return layout->currentSize;
  50365. return 0;
  50366. }
  50367. double StretchableLayoutManager::getItemCurrentRelativeSize (const int itemIndex) const
  50368. {
  50369. const ItemLayoutProperties* const layout = getInfoFor (itemIndex);
  50370. if (layout != 0)
  50371. return -layout->currentSize / (double) totalSize;
  50372. return 0;
  50373. }
  50374. void StretchableLayoutManager::setItemPosition (const int itemIndex,
  50375. int newPosition)
  50376. {
  50377. for (int i = items.size(); --i >= 0;)
  50378. {
  50379. const ItemLayoutProperties* const layout = items.getUnchecked(i);
  50380. if (layout->itemIndex == itemIndex)
  50381. {
  50382. int realTotalSize = jmax (totalSize, getMinimumSizeOfItems (0, items.size()));
  50383. const int minSizeAfterThisComp = getMinimumSizeOfItems (i, items.size());
  50384. const int maxSizeAfterThisComp = getMaximumSizeOfItems (i + 1, items.size());
  50385. newPosition = jmax (newPosition, totalSize - maxSizeAfterThisComp - layout->currentSize);
  50386. newPosition = jmin (newPosition, realTotalSize - minSizeAfterThisComp);
  50387. int endPos = fitComponentsIntoSpace (0, i, newPosition, 0);
  50388. endPos += layout->currentSize;
  50389. fitComponentsIntoSpace (i + 1, items.size(), totalSize - endPos, endPos);
  50390. updatePrefSizesToMatchCurrentPositions();
  50391. break;
  50392. }
  50393. }
  50394. }
  50395. void StretchableLayoutManager::layOutComponents (Component** const components,
  50396. int numComponents,
  50397. int x, int y, int w, int h,
  50398. const bool vertically,
  50399. const bool resizeOtherDimension)
  50400. {
  50401. setTotalSize (vertically ? h : w);
  50402. int pos = vertically ? y : x;
  50403. for (int i = 0; i < numComponents; ++i)
  50404. {
  50405. const ItemLayoutProperties* const layout = getInfoFor (i);
  50406. if (layout != 0)
  50407. {
  50408. Component* const c = components[i];
  50409. if (c != 0)
  50410. {
  50411. if (i == numComponents - 1)
  50412. {
  50413. // if it's the last item, crop it to exactly fit the available space..
  50414. if (resizeOtherDimension)
  50415. {
  50416. if (vertically)
  50417. c->setBounds (x, pos, w, jmax (layout->currentSize, h - pos));
  50418. else
  50419. c->setBounds (pos, y, jmax (layout->currentSize, w - pos), h);
  50420. }
  50421. else
  50422. {
  50423. if (vertically)
  50424. c->setBounds (c->getX(), pos, c->getWidth(), jmax (layout->currentSize, h - pos));
  50425. else
  50426. c->setBounds (pos, c->getY(), jmax (layout->currentSize, w - pos), c->getHeight());
  50427. }
  50428. }
  50429. else
  50430. {
  50431. if (resizeOtherDimension)
  50432. {
  50433. if (vertically)
  50434. c->setBounds (x, pos, w, layout->currentSize);
  50435. else
  50436. c->setBounds (pos, y, layout->currentSize, h);
  50437. }
  50438. else
  50439. {
  50440. if (vertically)
  50441. c->setBounds (c->getX(), pos, c->getWidth(), layout->currentSize);
  50442. else
  50443. c->setBounds (pos, c->getY(), layout->currentSize, c->getHeight());
  50444. }
  50445. }
  50446. }
  50447. pos += layout->currentSize;
  50448. }
  50449. }
  50450. }
  50451. StretchableLayoutManager::ItemLayoutProperties* StretchableLayoutManager::getInfoFor (const int itemIndex) const
  50452. {
  50453. for (int i = items.size(); --i >= 0;)
  50454. if (items.getUnchecked(i)->itemIndex == itemIndex)
  50455. return items.getUnchecked(i);
  50456. return 0;
  50457. }
  50458. int StretchableLayoutManager::fitComponentsIntoSpace (const int startIndex,
  50459. const int endIndex,
  50460. const int availableSpace,
  50461. int startPos)
  50462. {
  50463. // calculate the total sizes
  50464. int i;
  50465. double totalIdealSize = 0.0;
  50466. int totalMinimums = 0;
  50467. for (i = startIndex; i < endIndex; ++i)
  50468. {
  50469. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50470. layout->currentSize = sizeToRealSize (layout->minSize, totalSize);
  50471. totalMinimums += layout->currentSize;
  50472. totalIdealSize += sizeToRealSize (layout->preferredSize, availableSpace);
  50473. }
  50474. if (totalIdealSize <= 0)
  50475. totalIdealSize = 1.0;
  50476. // now calc the best sizes..
  50477. int extraSpace = availableSpace - totalMinimums;
  50478. while (extraSpace > 0)
  50479. {
  50480. int numWantingMoreSpace = 0;
  50481. int numHavingTakenExtraSpace = 0;
  50482. // first figure out how many comps want a slice of the extra space..
  50483. for (i = startIndex; i < endIndex; ++i)
  50484. {
  50485. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50486. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  50487. const int bestSize = jlimit (layout->currentSize,
  50488. jmax (layout->currentSize,
  50489. sizeToRealSize (layout->maxSize, totalSize)),
  50490. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  50491. if (bestSize > layout->currentSize)
  50492. ++numWantingMoreSpace;
  50493. }
  50494. // ..share out the extra space..
  50495. for (i = startIndex; i < endIndex; ++i)
  50496. {
  50497. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50498. double sizeWanted = sizeToRealSize (layout->preferredSize, availableSpace);
  50499. int bestSize = jlimit (layout->currentSize,
  50500. jmax (layout->currentSize, sizeToRealSize (layout->maxSize, totalSize)),
  50501. roundToInt (sizeWanted * availableSpace / totalIdealSize));
  50502. const int extraWanted = bestSize - layout->currentSize;
  50503. if (extraWanted > 0)
  50504. {
  50505. const int extraAllowed = jmin (extraWanted,
  50506. extraSpace / jmax (1, numWantingMoreSpace));
  50507. if (extraAllowed > 0)
  50508. {
  50509. ++numHavingTakenExtraSpace;
  50510. --numWantingMoreSpace;
  50511. layout->currentSize += extraAllowed;
  50512. extraSpace -= extraAllowed;
  50513. }
  50514. }
  50515. }
  50516. if (numHavingTakenExtraSpace <= 0)
  50517. break;
  50518. }
  50519. // ..and calculate the end position
  50520. for (i = startIndex; i < endIndex; ++i)
  50521. {
  50522. ItemLayoutProperties* const layout = items.getUnchecked(i);
  50523. startPos += layout->currentSize;
  50524. }
  50525. return startPos;
  50526. }
  50527. int StretchableLayoutManager::getMinimumSizeOfItems (const int startIndex,
  50528. const int endIndex) const
  50529. {
  50530. int totalMinimums = 0;
  50531. for (int i = startIndex; i < endIndex; ++i)
  50532. totalMinimums += sizeToRealSize (items.getUnchecked (i)->minSize, totalSize);
  50533. return totalMinimums;
  50534. }
  50535. int StretchableLayoutManager::getMaximumSizeOfItems (const int startIndex, const int endIndex) const
  50536. {
  50537. int totalMaximums = 0;
  50538. for (int i = startIndex; i < endIndex; ++i)
  50539. totalMaximums += sizeToRealSize (items.getUnchecked (i)->maxSize, totalSize);
  50540. return totalMaximums;
  50541. }
  50542. void StretchableLayoutManager::updatePrefSizesToMatchCurrentPositions()
  50543. {
  50544. for (int i = 0; i < items.size(); ++i)
  50545. {
  50546. ItemLayoutProperties* const layout = items.getUnchecked (i);
  50547. layout->preferredSize
  50548. = (layout->preferredSize < 0) ? getItemCurrentRelativeSize (i)
  50549. : getItemCurrentAbsoluteSize (i);
  50550. }
  50551. }
  50552. int StretchableLayoutManager::sizeToRealSize (double size, int totalSpace)
  50553. {
  50554. if (size < 0)
  50555. size *= -totalSpace;
  50556. return roundToInt (size);
  50557. }
  50558. END_JUCE_NAMESPACE
  50559. /*** End of inlined file: juce_StretchableLayoutManager.cpp ***/
  50560. /*** Start of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50561. BEGIN_JUCE_NAMESPACE
  50562. StretchableLayoutResizerBar::StretchableLayoutResizerBar (StretchableLayoutManager* layout_,
  50563. const int itemIndex_,
  50564. const bool isVertical_)
  50565. : layout (layout_),
  50566. itemIndex (itemIndex_),
  50567. isVertical (isVertical_)
  50568. {
  50569. setRepaintsOnMouseActivity (true);
  50570. setMouseCursor (MouseCursor (isVertical_ ? MouseCursor::LeftRightResizeCursor
  50571. : MouseCursor::UpDownResizeCursor));
  50572. }
  50573. StretchableLayoutResizerBar::~StretchableLayoutResizerBar()
  50574. {
  50575. }
  50576. void StretchableLayoutResizerBar::paint (Graphics& g)
  50577. {
  50578. getLookAndFeel().drawStretchableLayoutResizerBar (g,
  50579. getWidth(), getHeight(),
  50580. isVertical,
  50581. isMouseOver(),
  50582. isMouseButtonDown());
  50583. }
  50584. void StretchableLayoutResizerBar::mouseDown (const MouseEvent&)
  50585. {
  50586. mouseDownPos = layout->getItemCurrentPosition (itemIndex);
  50587. }
  50588. void StretchableLayoutResizerBar::mouseDrag (const MouseEvent& e)
  50589. {
  50590. const int desiredPos = mouseDownPos + (isVertical ? e.getDistanceFromDragStartX()
  50591. : e.getDistanceFromDragStartY());
  50592. layout->setItemPosition (itemIndex, desiredPos);
  50593. hasBeenMoved();
  50594. }
  50595. void StretchableLayoutResizerBar::hasBeenMoved()
  50596. {
  50597. if (getParentComponent() != 0)
  50598. getParentComponent()->resized();
  50599. }
  50600. END_JUCE_NAMESPACE
  50601. /*** End of inlined file: juce_StretchableLayoutResizerBar.cpp ***/
  50602. /*** Start of inlined file: juce_StretchableObjectResizer.cpp ***/
  50603. BEGIN_JUCE_NAMESPACE
  50604. StretchableObjectResizer::StretchableObjectResizer()
  50605. {
  50606. }
  50607. StretchableObjectResizer::~StretchableObjectResizer()
  50608. {
  50609. }
  50610. void StretchableObjectResizer::addItem (const double size,
  50611. const double minSize, const double maxSize,
  50612. const int order)
  50613. {
  50614. // the order must be >= 0 but less than the maximum integer value.
  50615. jassert (order >= 0 && order < std::numeric_limits<int>::max());
  50616. Item* const item = new Item();
  50617. item->size = size;
  50618. item->minSize = minSize;
  50619. item->maxSize = maxSize;
  50620. item->order = order;
  50621. items.add (item);
  50622. }
  50623. double StretchableObjectResizer::getItemSize (const int index) const throw()
  50624. {
  50625. const Item* const it = items [index];
  50626. return it != 0 ? it->size : 0;
  50627. }
  50628. void StretchableObjectResizer::resizeToFit (const double targetSize)
  50629. {
  50630. int order = 0;
  50631. for (;;)
  50632. {
  50633. double currentSize = 0;
  50634. double minSize = 0;
  50635. double maxSize = 0;
  50636. int nextHighestOrder = std::numeric_limits<int>::max();
  50637. for (int i = 0; i < items.size(); ++i)
  50638. {
  50639. const Item* const it = items.getUnchecked(i);
  50640. currentSize += it->size;
  50641. if (it->order <= order)
  50642. {
  50643. minSize += it->minSize;
  50644. maxSize += it->maxSize;
  50645. }
  50646. else
  50647. {
  50648. minSize += it->size;
  50649. maxSize += it->size;
  50650. nextHighestOrder = jmin (nextHighestOrder, it->order);
  50651. }
  50652. }
  50653. const double thisIterationTarget = jlimit (minSize, maxSize, targetSize);
  50654. if (thisIterationTarget >= currentSize)
  50655. {
  50656. const double availableExtraSpace = maxSize - currentSize;
  50657. const double targetAmountOfExtraSpace = thisIterationTarget - currentSize;
  50658. const double scale = targetAmountOfExtraSpace / availableExtraSpace;
  50659. for (int i = 0; i < items.size(); ++i)
  50660. {
  50661. Item* const it = items.getUnchecked(i);
  50662. if (it->order <= order)
  50663. it->size = jmin (it->maxSize, it->size + (it->maxSize - it->size) * scale);
  50664. }
  50665. }
  50666. else
  50667. {
  50668. const double amountOfSlack = currentSize - minSize;
  50669. const double targetAmountOfSlack = thisIterationTarget - minSize;
  50670. const double scale = targetAmountOfSlack / amountOfSlack;
  50671. for (int i = 0; i < items.size(); ++i)
  50672. {
  50673. Item* const it = items.getUnchecked(i);
  50674. if (it->order <= order)
  50675. it->size = jmax (it->minSize, it->minSize + (it->size - it->minSize) * scale);
  50676. }
  50677. }
  50678. if (nextHighestOrder < std::numeric_limits<int>::max())
  50679. order = nextHighestOrder;
  50680. else
  50681. break;
  50682. }
  50683. }
  50684. END_JUCE_NAMESPACE
  50685. /*** End of inlined file: juce_StretchableObjectResizer.cpp ***/
  50686. /*** Start of inlined file: juce_TabbedButtonBar.cpp ***/
  50687. BEGIN_JUCE_NAMESPACE
  50688. TabBarButton::TabBarButton (const String& name,
  50689. TabbedButtonBar* const owner_,
  50690. const int index)
  50691. : Button (name),
  50692. owner (owner_),
  50693. tabIndex (index),
  50694. overlapPixels (0)
  50695. {
  50696. shadow.setShadowProperties (2.2f, 0.7f, 0, 0);
  50697. setComponentEffect (&shadow);
  50698. setWantsKeyboardFocus (false);
  50699. }
  50700. TabBarButton::~TabBarButton()
  50701. {
  50702. }
  50703. void TabBarButton::paintButton (Graphics& g,
  50704. bool isMouseOverButton,
  50705. bool isButtonDown)
  50706. {
  50707. int x, y, w, h;
  50708. getActiveArea (x, y, w, h);
  50709. g.setOrigin (x, y);
  50710. getLookAndFeel()
  50711. .drawTabButton (g, w, h,
  50712. owner->getTabBackgroundColour (tabIndex),
  50713. tabIndex, getButtonText(), *this,
  50714. owner->getOrientation(),
  50715. isMouseOverButton, isButtonDown,
  50716. getToggleState());
  50717. }
  50718. void TabBarButton::clicked (const ModifierKeys& mods)
  50719. {
  50720. if (mods.isPopupMenu())
  50721. owner->popupMenuClickOnTab (tabIndex, getButtonText());
  50722. else
  50723. owner->setCurrentTabIndex (tabIndex);
  50724. }
  50725. bool TabBarButton::hitTest (int mx, int my)
  50726. {
  50727. int x, y, w, h;
  50728. getActiveArea (x, y, w, h);
  50729. if (owner->getOrientation() == TabbedButtonBar::TabsAtLeft
  50730. || owner->getOrientation() == TabbedButtonBar::TabsAtRight)
  50731. {
  50732. if (((unsigned int) mx) < (unsigned int) getWidth()
  50733. && my >= y + overlapPixels
  50734. && my < y + h - overlapPixels)
  50735. return true;
  50736. }
  50737. else
  50738. {
  50739. if (mx >= x + overlapPixels && mx < x + w - overlapPixels
  50740. && ((unsigned int) my) < (unsigned int) getHeight())
  50741. return true;
  50742. }
  50743. Path p;
  50744. getLookAndFeel()
  50745. .createTabButtonShape (p, w, h, tabIndex, getButtonText(), *this,
  50746. owner->getOrientation(),
  50747. false, false, getToggleState());
  50748. return p.contains ((float) (mx - x),
  50749. (float) (my - y));
  50750. }
  50751. int TabBarButton::getBestTabLength (const int depth)
  50752. {
  50753. return jlimit (depth * 2,
  50754. depth * 7,
  50755. getLookAndFeel().getTabButtonBestWidth (tabIndex, getButtonText(), depth, *this));
  50756. }
  50757. void TabBarButton::getActiveArea (int& x, int& y, int& w, int& h)
  50758. {
  50759. x = 0;
  50760. y = 0;
  50761. int r = getWidth();
  50762. int b = getHeight();
  50763. const int spaceAroundImage = getLookAndFeel().getTabButtonSpaceAroundImage();
  50764. if (owner->getOrientation() != TabbedButtonBar::TabsAtLeft)
  50765. r -= spaceAroundImage;
  50766. if (owner->getOrientation() != TabbedButtonBar::TabsAtRight)
  50767. x += spaceAroundImage;
  50768. if (owner->getOrientation() != TabbedButtonBar::TabsAtBottom)
  50769. y += spaceAroundImage;
  50770. if (owner->getOrientation() != TabbedButtonBar::TabsAtTop)
  50771. b -= spaceAroundImage;
  50772. w = r - x;
  50773. h = b - y;
  50774. }
  50775. class TabAreaBehindFrontButtonComponent : public Component
  50776. {
  50777. public:
  50778. TabAreaBehindFrontButtonComponent (TabbedButtonBar* const owner_)
  50779. : owner (owner_)
  50780. {
  50781. setInterceptsMouseClicks (false, false);
  50782. }
  50783. ~TabAreaBehindFrontButtonComponent()
  50784. {
  50785. }
  50786. void paint (Graphics& g)
  50787. {
  50788. getLookAndFeel()
  50789. .drawTabAreaBehindFrontButton (g, getWidth(), getHeight(),
  50790. *owner, owner->getOrientation());
  50791. }
  50792. void enablementChanged()
  50793. {
  50794. repaint();
  50795. }
  50796. private:
  50797. TabbedButtonBar* const owner;
  50798. TabAreaBehindFrontButtonComponent (const TabAreaBehindFrontButtonComponent&);
  50799. TabAreaBehindFrontButtonComponent& operator= (const TabAreaBehindFrontButtonComponent&);
  50800. };
  50801. TabbedButtonBar::TabbedButtonBar (const Orientation orientation_)
  50802. : orientation (orientation_),
  50803. currentTabIndex (-1),
  50804. extraTabsButton (0)
  50805. {
  50806. setInterceptsMouseClicks (false, true);
  50807. addAndMakeVisible (behindFrontTab = new TabAreaBehindFrontButtonComponent (this));
  50808. setFocusContainer (true);
  50809. }
  50810. TabbedButtonBar::~TabbedButtonBar()
  50811. {
  50812. deleteAllChildren();
  50813. }
  50814. void TabbedButtonBar::setOrientation (const Orientation newOrientation)
  50815. {
  50816. orientation = newOrientation;
  50817. for (int i = getNumChildComponents(); --i >= 0;)
  50818. getChildComponent (i)->resized();
  50819. resized();
  50820. }
  50821. TabBarButton* TabbedButtonBar::createTabButton (const String& name, const int index)
  50822. {
  50823. return new TabBarButton (name, this, index);
  50824. }
  50825. void TabbedButtonBar::clearTabs()
  50826. {
  50827. tabs.clear();
  50828. tabColours.clear();
  50829. currentTabIndex = -1;
  50830. deleteAndZero (extraTabsButton);
  50831. removeChildComponent (behindFrontTab);
  50832. deleteAllChildren();
  50833. addChildComponent (behindFrontTab);
  50834. setCurrentTabIndex (-1);
  50835. }
  50836. void TabbedButtonBar::addTab (const String& tabName,
  50837. const Colour& tabBackgroundColour,
  50838. int insertIndex)
  50839. {
  50840. jassert (tabName.isNotEmpty()); // you have to give them all a name..
  50841. if (tabName.isNotEmpty())
  50842. {
  50843. if (((unsigned int) insertIndex) > (unsigned int) tabs.size())
  50844. insertIndex = tabs.size();
  50845. for (int i = tabs.size(); --i >= insertIndex;)
  50846. {
  50847. TabBarButton* const tb = getTabButton (i);
  50848. if (tb != 0)
  50849. tb->tabIndex++;
  50850. }
  50851. tabs.insert (insertIndex, tabName);
  50852. tabColours.insert (insertIndex, tabBackgroundColour);
  50853. TabBarButton* const tb = createTabButton (tabName, insertIndex);
  50854. jassert (tb != 0); // your createTabButton() mustn't return zero!
  50855. addAndMakeVisible (tb, insertIndex);
  50856. resized();
  50857. if (currentTabIndex < 0)
  50858. setCurrentTabIndex (0);
  50859. }
  50860. }
  50861. void TabbedButtonBar::setTabName (const int tabIndex,
  50862. const String& newName)
  50863. {
  50864. if (((unsigned int) tabIndex) < (unsigned int) tabs.size()
  50865. && tabs[tabIndex] != newName)
  50866. {
  50867. tabs.set (tabIndex, newName);
  50868. TabBarButton* const tb = getTabButton (tabIndex);
  50869. if (tb != 0)
  50870. tb->setButtonText (newName);
  50871. resized();
  50872. }
  50873. }
  50874. void TabbedButtonBar::removeTab (const int tabIndex)
  50875. {
  50876. if (((unsigned int) tabIndex) < (unsigned int) tabs.size())
  50877. {
  50878. const int oldTabIndex = currentTabIndex;
  50879. if (currentTabIndex == tabIndex)
  50880. currentTabIndex = -1;
  50881. tabs.remove (tabIndex);
  50882. tabColours.remove (tabIndex);
  50883. delete getTabButton (tabIndex);
  50884. for (int i = tabIndex + 1; i <= tabs.size(); ++i)
  50885. {
  50886. TabBarButton* const tb = getTabButton (i);
  50887. if (tb != 0)
  50888. tb->tabIndex--;
  50889. }
  50890. resized();
  50891. setCurrentTabIndex (jlimit (0, jmax (0, tabs.size() - 1), oldTabIndex));
  50892. }
  50893. }
  50894. void TabbedButtonBar::moveTab (const int currentIndex,
  50895. const int newIndex)
  50896. {
  50897. tabs.move (currentIndex, newIndex);
  50898. tabColours.move (currentIndex, newIndex);
  50899. resized();
  50900. }
  50901. int TabbedButtonBar::getNumTabs() const
  50902. {
  50903. return tabs.size();
  50904. }
  50905. const StringArray TabbedButtonBar::getTabNames() const
  50906. {
  50907. return tabs;
  50908. }
  50909. void TabbedButtonBar::setCurrentTabIndex (int newIndex, const bool sendChangeMessage_)
  50910. {
  50911. if (currentTabIndex != newIndex)
  50912. {
  50913. if (((unsigned int) newIndex) >= (unsigned int) tabs.size())
  50914. newIndex = -1;
  50915. currentTabIndex = newIndex;
  50916. for (int i = 0; i < getNumChildComponents(); ++i)
  50917. {
  50918. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50919. if (tb != 0)
  50920. tb->setToggleState (tb->tabIndex == newIndex, false);
  50921. }
  50922. resized();
  50923. if (sendChangeMessage_)
  50924. sendChangeMessage (this);
  50925. currentTabChanged (newIndex, newIndex >= 0 ? tabs [newIndex] : String::empty);
  50926. }
  50927. }
  50928. TabBarButton* TabbedButtonBar::getTabButton (const int index) const
  50929. {
  50930. for (int i = getNumChildComponents(); --i >= 0;)
  50931. {
  50932. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50933. if (tb != 0 && tb->tabIndex == index)
  50934. return tb;
  50935. }
  50936. return 0;
  50937. }
  50938. void TabbedButtonBar::lookAndFeelChanged()
  50939. {
  50940. deleteAndZero (extraTabsButton);
  50941. resized();
  50942. }
  50943. void TabbedButtonBar::resized()
  50944. {
  50945. const double minimumScale = 0.7;
  50946. int depth = getWidth();
  50947. int length = getHeight();
  50948. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50949. swapVariables (depth, length);
  50950. const int overlap = getLookAndFeel().getTabButtonOverlap (depth)
  50951. + getLookAndFeel().getTabButtonSpaceAroundImage() * 2;
  50952. int i, totalLength = overlap;
  50953. int numVisibleButtons = tabs.size();
  50954. for (i = 0; i < getNumChildComponents(); ++i)
  50955. {
  50956. TabBarButton* const tb = dynamic_cast <TabBarButton*> (getChildComponent (i));
  50957. if (tb != 0)
  50958. {
  50959. totalLength += tb->getBestTabLength (depth) - overlap;
  50960. tb->overlapPixels = overlap / 2;
  50961. }
  50962. }
  50963. double scale = 1.0;
  50964. if (totalLength > length)
  50965. scale = jmax (minimumScale, length / (double) totalLength);
  50966. const bool isTooBig = totalLength * scale > length;
  50967. int tabsButtonPos = 0;
  50968. if (isTooBig)
  50969. {
  50970. if (extraTabsButton == 0)
  50971. {
  50972. addAndMakeVisible (extraTabsButton = getLookAndFeel().createTabBarExtrasButton());
  50973. extraTabsButton->addButtonListener (this);
  50974. extraTabsButton->setAlwaysOnTop (true);
  50975. extraTabsButton->setTriggeredOnMouseDown (true);
  50976. }
  50977. const int buttonSize = jmin (proportionOfWidth (0.7f), proportionOfHeight (0.7f));
  50978. extraTabsButton->setSize (buttonSize, buttonSize);
  50979. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  50980. {
  50981. tabsButtonPos = getWidth() - buttonSize / 2 - 1;
  50982. extraTabsButton->setCentrePosition (tabsButtonPos, getHeight() / 2);
  50983. }
  50984. else
  50985. {
  50986. tabsButtonPos = getHeight() - buttonSize / 2 - 1;
  50987. extraTabsButton->setCentrePosition (getWidth() / 2, tabsButtonPos);
  50988. }
  50989. totalLength = 0;
  50990. for (i = 0; i < tabs.size(); ++i)
  50991. {
  50992. TabBarButton* const tb = getTabButton (i);
  50993. if (tb != 0)
  50994. {
  50995. const int newLength = totalLength + tb->getBestTabLength (depth);
  50996. if (i > 0 && newLength * minimumScale > tabsButtonPos)
  50997. {
  50998. totalLength += overlap;
  50999. break;
  51000. }
  51001. numVisibleButtons = i + 1;
  51002. totalLength = newLength - overlap;
  51003. }
  51004. }
  51005. scale = jmax (minimumScale, tabsButtonPos / (double) totalLength);
  51006. }
  51007. else
  51008. {
  51009. deleteAndZero (extraTabsButton);
  51010. }
  51011. int pos = 0;
  51012. TabBarButton* frontTab = 0;
  51013. for (i = 0; i < tabs.size(); ++i)
  51014. {
  51015. TabBarButton* const tb = getTabButton (i);
  51016. if (tb != 0)
  51017. {
  51018. const int bestLength = roundToInt (scale * tb->getBestTabLength (depth));
  51019. if (i < numVisibleButtons)
  51020. {
  51021. if (orientation == TabsAtTop || orientation == TabsAtBottom)
  51022. tb->setBounds (pos, 0, bestLength, getHeight());
  51023. else
  51024. tb->setBounds (0, pos, getWidth(), bestLength);
  51025. tb->toBack();
  51026. if (tb->tabIndex == currentTabIndex)
  51027. frontTab = tb;
  51028. tb->setVisible (true);
  51029. }
  51030. else
  51031. {
  51032. tb->setVisible (false);
  51033. }
  51034. pos += bestLength - overlap;
  51035. }
  51036. }
  51037. behindFrontTab->setBounds (0, 0, getWidth(), getHeight());
  51038. if (frontTab != 0)
  51039. {
  51040. frontTab->toFront (false);
  51041. behindFrontTab->toBehind (frontTab);
  51042. }
  51043. }
  51044. const Colour TabbedButtonBar::getTabBackgroundColour (const int tabIndex)
  51045. {
  51046. return tabColours [tabIndex];
  51047. }
  51048. void TabbedButtonBar::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  51049. {
  51050. if (((unsigned int) tabIndex) < (unsigned int) tabColours.size()
  51051. && tabColours [tabIndex] != newColour)
  51052. {
  51053. tabColours.set (tabIndex, newColour);
  51054. repaint();
  51055. }
  51056. }
  51057. void TabbedButtonBar::buttonClicked (Button* button)
  51058. {
  51059. if (extraTabsButton == button)
  51060. {
  51061. PopupMenu m;
  51062. for (int i = 0; i < tabs.size(); ++i)
  51063. {
  51064. TabBarButton* const tb = getTabButton (i);
  51065. if (tb != 0 && ! tb->isVisible())
  51066. m.addItem (tb->tabIndex + 1, tabs[i], true, i == currentTabIndex);
  51067. }
  51068. const int res = m.showAt (extraTabsButton);
  51069. if (res != 0)
  51070. setCurrentTabIndex (res - 1);
  51071. }
  51072. }
  51073. void TabbedButtonBar::currentTabChanged (const int, const String&)
  51074. {
  51075. }
  51076. void TabbedButtonBar::popupMenuClickOnTab (const int, const String&)
  51077. {
  51078. }
  51079. END_JUCE_NAMESPACE
  51080. /*** End of inlined file: juce_TabbedButtonBar.cpp ***/
  51081. /*** Start of inlined file: juce_TabbedComponent.cpp ***/
  51082. BEGIN_JUCE_NAMESPACE
  51083. class TabCompButtonBar : public TabbedButtonBar
  51084. {
  51085. public:
  51086. TabCompButtonBar (TabbedComponent* const owner_,
  51087. const TabbedButtonBar::Orientation orientation)
  51088. : TabbedButtonBar (orientation),
  51089. owner (owner_)
  51090. {
  51091. }
  51092. ~TabCompButtonBar()
  51093. {
  51094. }
  51095. void currentTabChanged (const int newCurrentTabIndex,
  51096. const String& newTabName)
  51097. {
  51098. owner->changeCallback (newCurrentTabIndex, newTabName);
  51099. }
  51100. void popupMenuClickOnTab (const int tabIndex,
  51101. const String& tabName)
  51102. {
  51103. owner->popupMenuClickOnTab (tabIndex, tabName);
  51104. }
  51105. const Colour getTabBackgroundColour (const int tabIndex)
  51106. {
  51107. return owner->tabs->getTabBackgroundColour (tabIndex);
  51108. }
  51109. TabBarButton* createTabButton (const String& tabName, const int tabIndex)
  51110. {
  51111. return owner->createTabButton (tabName, tabIndex);
  51112. }
  51113. juce_UseDebuggingNewOperator
  51114. private:
  51115. TabbedComponent* const owner;
  51116. TabCompButtonBar (const TabCompButtonBar&);
  51117. TabCompButtonBar& operator= (const TabCompButtonBar&);
  51118. };
  51119. TabbedComponent::TabbedComponent (const TabbedButtonBar::Orientation orientation)
  51120. : panelComponent (0),
  51121. tabDepth (30),
  51122. outlineThickness (1),
  51123. edgeIndent (0)
  51124. {
  51125. addAndMakeVisible (tabs = new TabCompButtonBar (this, orientation));
  51126. }
  51127. TabbedComponent::~TabbedComponent()
  51128. {
  51129. clearTabs();
  51130. delete tabs;
  51131. }
  51132. void TabbedComponent::setOrientation (const TabbedButtonBar::Orientation orientation)
  51133. {
  51134. tabs->setOrientation (orientation);
  51135. resized();
  51136. }
  51137. TabbedButtonBar::Orientation TabbedComponent::getOrientation() const throw()
  51138. {
  51139. return tabs->getOrientation();
  51140. }
  51141. void TabbedComponent::setTabBarDepth (const int newDepth)
  51142. {
  51143. if (tabDepth != newDepth)
  51144. {
  51145. tabDepth = newDepth;
  51146. resized();
  51147. }
  51148. }
  51149. TabBarButton* TabbedComponent::createTabButton (const String& tabName, const int tabIndex)
  51150. {
  51151. return new TabBarButton (tabName, tabs, tabIndex);
  51152. }
  51153. void TabbedComponent::clearTabs()
  51154. {
  51155. if (panelComponent != 0)
  51156. {
  51157. panelComponent->setVisible (false);
  51158. removeChildComponent (panelComponent);
  51159. panelComponent = 0;
  51160. }
  51161. tabs->clearTabs();
  51162. for (int i = contentComponents.size(); --i >= 0;)
  51163. {
  51164. Component* const c = contentComponents.getUnchecked(i);
  51165. // be careful not to delete these components until they've been removed from the tab component
  51166. jassert (c == 0 || c->isValidComponent());
  51167. if (c != 0 && c->getProperties() ["deleteByTabComp_"])
  51168. delete c;
  51169. }
  51170. contentComponents.clear();
  51171. }
  51172. void TabbedComponent::addTab (const String& tabName,
  51173. const Colour& tabBackgroundColour,
  51174. Component* const contentComponent,
  51175. const bool deleteComponentWhenNotNeeded,
  51176. const int insertIndex)
  51177. {
  51178. contentComponents.insert (insertIndex, contentComponent);
  51179. if (contentComponent != 0)
  51180. contentComponent->getProperties().set ("deleteByTabComp_", deleteComponentWhenNotNeeded);
  51181. tabs->addTab (tabName, tabBackgroundColour, insertIndex);
  51182. }
  51183. void TabbedComponent::setTabName (const int tabIndex,
  51184. const String& newName)
  51185. {
  51186. tabs->setTabName (tabIndex, newName);
  51187. }
  51188. void TabbedComponent::removeTab (const int tabIndex)
  51189. {
  51190. Component* const c = contentComponents [tabIndex];
  51191. if (c != 0 && c->getProperties() ["deleteByTabComp_"])
  51192. {
  51193. if (c == panelComponent)
  51194. panelComponent = 0;
  51195. delete c;
  51196. }
  51197. contentComponents.remove (tabIndex);
  51198. tabs->removeTab (tabIndex);
  51199. }
  51200. int TabbedComponent::getNumTabs() const
  51201. {
  51202. return tabs->getNumTabs();
  51203. }
  51204. const StringArray TabbedComponent::getTabNames() const
  51205. {
  51206. return tabs->getTabNames();
  51207. }
  51208. Component* TabbedComponent::getTabContentComponent (const int tabIndex) const throw()
  51209. {
  51210. return contentComponents [tabIndex];
  51211. }
  51212. const Colour TabbedComponent::getTabBackgroundColour (const int tabIndex) const throw()
  51213. {
  51214. return tabs->getTabBackgroundColour (tabIndex);
  51215. }
  51216. void TabbedComponent::setTabBackgroundColour (const int tabIndex, const Colour& newColour)
  51217. {
  51218. tabs->setTabBackgroundColour (tabIndex, newColour);
  51219. if (getCurrentTabIndex() == tabIndex)
  51220. repaint();
  51221. }
  51222. void TabbedComponent::setCurrentTabIndex (const int newTabIndex, const bool sendChangeMessage)
  51223. {
  51224. tabs->setCurrentTabIndex (newTabIndex, sendChangeMessage);
  51225. }
  51226. int TabbedComponent::getCurrentTabIndex() const
  51227. {
  51228. return tabs->getCurrentTabIndex();
  51229. }
  51230. const String& TabbedComponent::getCurrentTabName() const
  51231. {
  51232. return tabs->getCurrentTabName();
  51233. }
  51234. void TabbedComponent::setOutline (int thickness)
  51235. {
  51236. outlineThickness = thickness;
  51237. repaint();
  51238. }
  51239. void TabbedComponent::setIndent (const int indentThickness)
  51240. {
  51241. edgeIndent = indentThickness;
  51242. }
  51243. void TabbedComponent::paint (Graphics& g)
  51244. {
  51245. g.fillAll (findColour (backgroundColourId));
  51246. const TabbedButtonBar::Orientation o = getOrientation();
  51247. int x = 0;
  51248. int y = 0;
  51249. int r = getWidth();
  51250. int b = getHeight();
  51251. if (o == TabbedButtonBar::TabsAtTop)
  51252. y += tabDepth;
  51253. else if (o == TabbedButtonBar::TabsAtBottom)
  51254. b -= tabDepth;
  51255. else if (o == TabbedButtonBar::TabsAtLeft)
  51256. x += tabDepth;
  51257. else if (o == TabbedButtonBar::TabsAtRight)
  51258. r -= tabDepth;
  51259. g.reduceClipRegion (x, y, r - x, b - y);
  51260. g.fillAll (tabs->getTabBackgroundColour (getCurrentTabIndex()));
  51261. if (outlineThickness > 0)
  51262. {
  51263. if (o == TabbedButtonBar::TabsAtTop)
  51264. --y;
  51265. else if (o == TabbedButtonBar::TabsAtBottom)
  51266. ++b;
  51267. else if (o == TabbedButtonBar::TabsAtLeft)
  51268. --x;
  51269. else if (o == TabbedButtonBar::TabsAtRight)
  51270. ++r;
  51271. g.setColour (findColour (outlineColourId));
  51272. g.drawRect (x, y, r - x, b - y, outlineThickness);
  51273. }
  51274. }
  51275. void TabbedComponent::resized()
  51276. {
  51277. const TabbedButtonBar::Orientation o = getOrientation();
  51278. const int indent = edgeIndent + outlineThickness;
  51279. BorderSize indents (indent);
  51280. if (o == TabbedButtonBar::TabsAtTop)
  51281. {
  51282. tabs->setBounds (0, 0, getWidth(), tabDepth);
  51283. indents.setTop (tabDepth + edgeIndent);
  51284. }
  51285. else if (o == TabbedButtonBar::TabsAtBottom)
  51286. {
  51287. tabs->setBounds (0, getHeight() - tabDepth, getWidth(), tabDepth);
  51288. indents.setBottom (tabDepth + edgeIndent);
  51289. }
  51290. else if (o == TabbedButtonBar::TabsAtLeft)
  51291. {
  51292. tabs->setBounds (0, 0, tabDepth, getHeight());
  51293. indents.setLeft (tabDepth + edgeIndent);
  51294. }
  51295. else if (o == TabbedButtonBar::TabsAtRight)
  51296. {
  51297. tabs->setBounds (getWidth() - tabDepth, 0, tabDepth, getHeight());
  51298. indents.setRight (tabDepth + edgeIndent);
  51299. }
  51300. const Rectangle<int> bounds (indents.subtractedFrom (Rectangle<int> (0, 0, getWidth(), getHeight())));
  51301. for (int i = contentComponents.size(); --i >= 0;)
  51302. if (contentComponents.getUnchecked (i) != 0)
  51303. contentComponents.getUnchecked (i)->setBounds (bounds);
  51304. }
  51305. void TabbedComponent::lookAndFeelChanged()
  51306. {
  51307. for (int i = contentComponents.size(); --i >= 0;)
  51308. if (contentComponents.getUnchecked (i) != 0)
  51309. contentComponents.getUnchecked (i)->lookAndFeelChanged();
  51310. }
  51311. void TabbedComponent::changeCallback (const int newCurrentTabIndex,
  51312. const String& newTabName)
  51313. {
  51314. if (panelComponent != 0)
  51315. {
  51316. panelComponent->setVisible (false);
  51317. removeChildComponent (panelComponent);
  51318. panelComponent = 0;
  51319. }
  51320. if (getCurrentTabIndex() >= 0)
  51321. {
  51322. panelComponent = contentComponents [getCurrentTabIndex()];
  51323. if (panelComponent != 0)
  51324. {
  51325. // do these ops as two stages instead of addAndMakeVisible() so that the
  51326. // component has always got a parent when it gets the visibilityChanged() callback
  51327. addChildComponent (panelComponent);
  51328. panelComponent->setVisible (true);
  51329. panelComponent->toFront (true);
  51330. }
  51331. repaint();
  51332. }
  51333. resized();
  51334. currentTabChanged (newCurrentTabIndex, newTabName);
  51335. }
  51336. void TabbedComponent::currentTabChanged (const int, const String&)
  51337. {
  51338. }
  51339. void TabbedComponent::popupMenuClickOnTab (const int, const String&)
  51340. {
  51341. }
  51342. END_JUCE_NAMESPACE
  51343. /*** End of inlined file: juce_TabbedComponent.cpp ***/
  51344. /*** Start of inlined file: juce_Viewport.cpp ***/
  51345. BEGIN_JUCE_NAMESPACE
  51346. Viewport::Viewport (const String& componentName)
  51347. : Component (componentName),
  51348. contentComp (0),
  51349. lastVX (0),
  51350. lastVY (0),
  51351. lastVW (0),
  51352. lastVH (0),
  51353. scrollBarThickness (0),
  51354. singleStepX (16),
  51355. singleStepY (16),
  51356. showHScrollbar (true),
  51357. showVScrollbar (true)
  51358. {
  51359. // content holder is used to clip the contents so they don't overlap the scrollbars
  51360. addAndMakeVisible (contentHolder = new Component());
  51361. contentHolder->setInterceptsMouseClicks (false, true);
  51362. verticalScrollBar = new ScrollBar (true);
  51363. horizontalScrollBar = new ScrollBar (false);
  51364. addChildComponent (verticalScrollBar);
  51365. addChildComponent (horizontalScrollBar);
  51366. verticalScrollBar->addListener (this);
  51367. horizontalScrollBar->addListener (this);
  51368. setInterceptsMouseClicks (false, true);
  51369. setWantsKeyboardFocus (true);
  51370. }
  51371. Viewport::~Viewport()
  51372. {
  51373. contentHolder->deleteAllChildren();
  51374. deleteAllChildren();
  51375. }
  51376. void Viewport::visibleAreaChanged (int, int, int, int)
  51377. {
  51378. }
  51379. void Viewport::setViewedComponent (Component* const newViewedComponent)
  51380. {
  51381. if (contentComp != newViewedComponent)
  51382. {
  51383. if (contentComp->isValidComponent())
  51384. {
  51385. Component* const oldComp = contentComp;
  51386. contentComp = 0;
  51387. delete oldComp;
  51388. }
  51389. contentComp = newViewedComponent;
  51390. if (contentComp != 0)
  51391. {
  51392. contentComp->setTopLeftPosition (0, 0);
  51393. contentHolder->addAndMakeVisible (contentComp);
  51394. contentComp->addComponentListener (this);
  51395. }
  51396. updateVisibleRegion();
  51397. }
  51398. }
  51399. int Viewport::getMaximumVisibleWidth() const throw()
  51400. {
  51401. return jmax (0, getWidth() - (verticalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  51402. }
  51403. int Viewport::getMaximumVisibleHeight() const throw()
  51404. {
  51405. return jmax (0, getHeight() - (horizontalScrollBar->isVisible() ? getScrollBarThickness() : 0));
  51406. }
  51407. void Viewport::setViewPosition (const int xPixelsOffset,
  51408. const int yPixelsOffset)
  51409. {
  51410. if (contentComp != 0)
  51411. contentComp->setTopLeftPosition (-xPixelsOffset,
  51412. -yPixelsOffset);
  51413. }
  51414. void Viewport::setViewPositionProportionately (const double x,
  51415. const double y)
  51416. {
  51417. if (contentComp != 0)
  51418. setViewPosition (jmax (0, roundToInt (x * (contentComp->getWidth() - getWidth()))),
  51419. jmax (0, roundToInt (y * (contentComp->getHeight() - getHeight()))));
  51420. }
  51421. bool Viewport::autoScroll (int mouseX, int mouseY, int activeBorderThickness, int maximumSpeed)
  51422. {
  51423. if (contentComp != 0)
  51424. {
  51425. int dx = 0, dy = 0;
  51426. if (mouseX < activeBorderThickness)
  51427. dx = activeBorderThickness - mouseX;
  51428. else if (mouseX >= contentHolder->getWidth() - activeBorderThickness)
  51429. dx = (contentHolder->getWidth() - activeBorderThickness) - mouseX;
  51430. if (dx < 0)
  51431. dx = jmax (dx, -maximumSpeed, contentHolder->getWidth() - contentComp->getRight());
  51432. else
  51433. dx = jmin (dx, maximumSpeed, -contentComp->getX());
  51434. if (mouseY < activeBorderThickness)
  51435. dy = activeBorderThickness - mouseY;
  51436. else if (mouseY >= contentHolder->getHeight() - activeBorderThickness)
  51437. dy = (contentHolder->getHeight() - activeBorderThickness) - mouseY;
  51438. if (dy < 0)
  51439. dy = jmax (dy, -maximumSpeed, contentHolder->getHeight() - contentComp->getBottom());
  51440. else
  51441. dy = jmin (dy, maximumSpeed, -contentComp->getY());
  51442. if (dx != 0 || dy != 0)
  51443. {
  51444. contentComp->setTopLeftPosition (contentComp->getX() + dx,
  51445. contentComp->getY() + dy);
  51446. return true;
  51447. }
  51448. }
  51449. return false;
  51450. }
  51451. void Viewport::componentMovedOrResized (Component&, bool, bool)
  51452. {
  51453. updateVisibleRegion();
  51454. }
  51455. void Viewport::resized()
  51456. {
  51457. updateVisibleRegion();
  51458. }
  51459. void Viewport::updateVisibleRegion()
  51460. {
  51461. if (contentComp != 0)
  51462. {
  51463. const int newVX = -contentComp->getX();
  51464. const int newVY = -contentComp->getY();
  51465. if (newVX == 0 && newVY == 0
  51466. && contentComp->getWidth() <= getWidth()
  51467. && contentComp->getHeight() <= getHeight())
  51468. {
  51469. horizontalScrollBar->setVisible (false);
  51470. verticalScrollBar->setVisible (false);
  51471. }
  51472. horizontalScrollBar->setRangeLimits (0.0, contentComp->getWidth());
  51473. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51474. horizontalScrollBar->setSingleStepSize (singleStepX);
  51475. if (! (contentComp->getWidth() > 0 && showHScrollbar && getHeight() > getScrollBarThickness()))
  51476. horizontalScrollBar->setVisible (false);
  51477. verticalScrollBar->setRangeLimits (0.0, contentComp->getHeight());
  51478. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  51479. verticalScrollBar->setSingleStepSize (singleStepY);
  51480. if (! (contentComp->getHeight() > 0 && showVScrollbar && getWidth() > getScrollBarThickness()))
  51481. verticalScrollBar->setVisible (false);
  51482. if (verticalScrollBar->isVisible())
  51483. {
  51484. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51485. verticalScrollBar->setCurrentRange (newVY, getMaximumVisibleHeight());
  51486. verticalScrollBar
  51487. ->setBounds (getMaximumVisibleWidth(), 0,
  51488. getScrollBarThickness(), getMaximumVisibleHeight());
  51489. }
  51490. if (horizontalScrollBar->isVisible())
  51491. {
  51492. horizontalScrollBar->setCurrentRange (newVX, getMaximumVisibleWidth());
  51493. horizontalScrollBar
  51494. ->setBounds (0, getMaximumVisibleHeight(),
  51495. getMaximumVisibleWidth(), getScrollBarThickness());
  51496. }
  51497. contentHolder->setSize (getMaximumVisibleWidth(),
  51498. getMaximumVisibleHeight());
  51499. const int newVW = jmin (contentComp->getRight(), getMaximumVisibleWidth());
  51500. const int newVH = jmin (contentComp->getBottom(), getMaximumVisibleHeight());
  51501. if (newVX != lastVX
  51502. || newVY != lastVY
  51503. || newVW != lastVW
  51504. || newVH != lastVH)
  51505. {
  51506. lastVX = newVX;
  51507. lastVY = newVY;
  51508. lastVW = newVW;
  51509. lastVH = newVH;
  51510. visibleAreaChanged (newVX, newVY, newVW, newVH);
  51511. }
  51512. horizontalScrollBar->handleUpdateNowIfNeeded();
  51513. verticalScrollBar->handleUpdateNowIfNeeded();
  51514. }
  51515. else
  51516. {
  51517. horizontalScrollBar->setVisible (false);
  51518. verticalScrollBar->setVisible (false);
  51519. }
  51520. }
  51521. void Viewport::setSingleStepSizes (const int stepX,
  51522. const int stepY)
  51523. {
  51524. singleStepX = stepX;
  51525. singleStepY = stepY;
  51526. updateVisibleRegion();
  51527. }
  51528. void Viewport::setScrollBarsShown (const bool showVerticalScrollbarIfNeeded,
  51529. const bool showHorizontalScrollbarIfNeeded)
  51530. {
  51531. showVScrollbar = showVerticalScrollbarIfNeeded;
  51532. showHScrollbar = showHorizontalScrollbarIfNeeded;
  51533. updateVisibleRegion();
  51534. }
  51535. void Viewport::setScrollBarThickness (const int thickness)
  51536. {
  51537. scrollBarThickness = thickness;
  51538. updateVisibleRegion();
  51539. }
  51540. int Viewport::getScrollBarThickness() const throw()
  51541. {
  51542. return (scrollBarThickness > 0) ? scrollBarThickness
  51543. : getLookAndFeel().getDefaultScrollbarWidth();
  51544. }
  51545. void Viewport::setScrollBarButtonVisibility (const bool buttonsVisible)
  51546. {
  51547. verticalScrollBar->setButtonVisibility (buttonsVisible);
  51548. horizontalScrollBar->setButtonVisibility (buttonsVisible);
  51549. }
  51550. void Viewport::scrollBarMoved (ScrollBar* scrollBarThatHasMoved, const double newRangeStart)
  51551. {
  51552. if (scrollBarThatHasMoved == horizontalScrollBar)
  51553. {
  51554. setViewPosition (roundToInt (newRangeStart), getViewPositionY());
  51555. }
  51556. else if (scrollBarThatHasMoved == verticalScrollBar)
  51557. {
  51558. setViewPosition (getViewPositionX(), roundToInt (newRangeStart));
  51559. }
  51560. }
  51561. void Viewport::mouseWheelMove (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51562. {
  51563. if (! useMouseWheelMoveIfNeeded (e, wheelIncrementX, wheelIncrementY))
  51564. Component::mouseWheelMove (e, wheelIncrementX, wheelIncrementY);
  51565. }
  51566. bool Viewport::useMouseWheelMoveIfNeeded (const MouseEvent& e, float wheelIncrementX, float wheelIncrementY)
  51567. {
  51568. if (! (e.mods.isAltDown() || e.mods.isCtrlDown()))
  51569. {
  51570. const bool hasVertBar = verticalScrollBar->isVisible();
  51571. const bool hasHorzBar = horizontalScrollBar->isVisible();
  51572. if (hasHorzBar && (wheelIncrementX != 0 || e.mods.isShiftDown() || ! hasVertBar))
  51573. {
  51574. if (wheelIncrementX == 0 && ! hasVertBar)
  51575. wheelIncrementX = wheelIncrementY;
  51576. horizontalScrollBar->mouseWheelMove (e.getEventRelativeTo (horizontalScrollBar),
  51577. wheelIncrementX, wheelIncrementY);
  51578. return true;
  51579. }
  51580. else if (hasVertBar && wheelIncrementY != 0)
  51581. {
  51582. verticalScrollBar->mouseWheelMove (e.getEventRelativeTo (verticalScrollBar),
  51583. wheelIncrementX, wheelIncrementY);
  51584. return true;
  51585. }
  51586. }
  51587. return false;
  51588. }
  51589. bool Viewport::keyPressed (const KeyPress& key)
  51590. {
  51591. const bool isUpDownKey = key.isKeyCode (KeyPress::upKey)
  51592. || key.isKeyCode (KeyPress::downKey)
  51593. || key.isKeyCode (KeyPress::pageUpKey)
  51594. || key.isKeyCode (KeyPress::pageDownKey)
  51595. || key.isKeyCode (KeyPress::homeKey)
  51596. || key.isKeyCode (KeyPress::endKey);
  51597. if (verticalScrollBar->isVisible() && isUpDownKey)
  51598. return verticalScrollBar->keyPressed (key);
  51599. const bool isLeftRightKey = key.isKeyCode (KeyPress::leftKey)
  51600. || key.isKeyCode (KeyPress::rightKey);
  51601. if (horizontalScrollBar->isVisible() && (isUpDownKey || isLeftRightKey))
  51602. return horizontalScrollBar->keyPressed (key);
  51603. return false;
  51604. }
  51605. END_JUCE_NAMESPACE
  51606. /*** End of inlined file: juce_Viewport.cpp ***/
  51607. /*** Start of inlined file: juce_LookAndFeel.cpp ***/
  51608. BEGIN_JUCE_NAMESPACE
  51609. static const Colour createBaseColour (const Colour& buttonColour,
  51610. const bool hasKeyboardFocus,
  51611. const bool isMouseOverButton,
  51612. const bool isButtonDown) throw()
  51613. {
  51614. const float sat = hasKeyboardFocus ? 1.3f : 0.9f;
  51615. const Colour baseColour (buttonColour.withMultipliedSaturation (sat));
  51616. if (isButtonDown)
  51617. return baseColour.contrasting (0.2f);
  51618. else if (isMouseOverButton)
  51619. return baseColour.contrasting (0.1f);
  51620. return baseColour;
  51621. }
  51622. static String defaultSansName, defaultSerifName, defaultFixedName;
  51623. void clearUpDefaultFontNames() throw()
  51624. {
  51625. defaultSansName = String::empty;
  51626. defaultSerifName = String::empty;
  51627. defaultFixedName = String::empty;
  51628. }
  51629. LookAndFeel::LookAndFeel()
  51630. {
  51631. /* if this fails it means you're trying to create a LookAndFeel object before
  51632. the static Colours have been initialised. That ain't gonna work. It probably
  51633. means that you're using a static LookAndFeel object and that your compiler has
  51634. decided to intialise it before the Colours class.
  51635. */
  51636. jassert (Colours::white == Colour (0xffffffff));
  51637. // set up the standard set of colours..
  51638. const int textButtonColour = 0xffbbbbff;
  51639. const int textHighlightColour = 0x401111ee;
  51640. const int standardOutlineColour = 0xb2808080;
  51641. static const int standardColours[] =
  51642. {
  51643. TextButton::buttonColourId, textButtonColour,
  51644. TextButton::buttonOnColourId, 0xff4444ff,
  51645. TextButton::textColourOnId, 0xff000000,
  51646. TextButton::textColourOffId, 0xff000000,
  51647. ComboBox::buttonColourId, 0xffbbbbff,
  51648. ComboBox::outlineColourId, standardOutlineColour,
  51649. ToggleButton::textColourId, 0xff000000,
  51650. TextEditor::backgroundColourId, 0xffffffff,
  51651. TextEditor::textColourId, 0xff000000,
  51652. TextEditor::highlightColourId, textHighlightColour,
  51653. TextEditor::highlightedTextColourId, 0xff000000,
  51654. TextEditor::caretColourId, 0xff000000,
  51655. TextEditor::outlineColourId, 0x00000000,
  51656. TextEditor::focusedOutlineColourId, textButtonColour,
  51657. TextEditor::shadowColourId, 0x38000000,
  51658. Label::backgroundColourId, 0x00000000,
  51659. Label::textColourId, 0xff000000,
  51660. Label::outlineColourId, 0x00000000,
  51661. ScrollBar::backgroundColourId, 0x00000000,
  51662. ScrollBar::thumbColourId, 0xffffffff,
  51663. ScrollBar::trackColourId, 0xffffffff,
  51664. TreeView::linesColourId, 0x4c000000,
  51665. TreeView::backgroundColourId, 0x00000000,
  51666. TreeView::dragAndDropIndicatorColourId, 0x80ff0000,
  51667. PopupMenu::backgroundColourId, 0xffffffff,
  51668. PopupMenu::textColourId, 0xff000000,
  51669. PopupMenu::headerTextColourId, 0xff000000,
  51670. PopupMenu::highlightedTextColourId, 0xffffffff,
  51671. PopupMenu::highlightedBackgroundColourId, 0x991111aa,
  51672. ComboBox::textColourId, 0xff000000,
  51673. ComboBox::backgroundColourId, 0xffffffff,
  51674. ComboBox::arrowColourId, 0x99000000,
  51675. ListBox::backgroundColourId, 0xffffffff,
  51676. ListBox::outlineColourId, standardOutlineColour,
  51677. ListBox::textColourId, 0xff000000,
  51678. Slider::backgroundColourId, 0x00000000,
  51679. Slider::thumbColourId, textButtonColour,
  51680. Slider::trackColourId, 0x7fffffff,
  51681. Slider::rotarySliderFillColourId, 0x7f0000ff,
  51682. Slider::rotarySliderOutlineColourId, 0x66000000,
  51683. Slider::textBoxTextColourId, 0xff000000,
  51684. Slider::textBoxBackgroundColourId, 0xffffffff,
  51685. Slider::textBoxHighlightColourId, textHighlightColour,
  51686. Slider::textBoxOutlineColourId, standardOutlineColour,
  51687. ResizableWindow::backgroundColourId, 0xff777777,
  51688. //DocumentWindow::textColourId, 0xff000000, // (this is deliberately not set)
  51689. AlertWindow::backgroundColourId, 0xffededed,
  51690. AlertWindow::textColourId, 0xff000000,
  51691. AlertWindow::outlineColourId, 0xff666666,
  51692. ProgressBar::backgroundColourId, 0xffeeeeee,
  51693. ProgressBar::foregroundColourId, 0xffaaaaee,
  51694. TooltipWindow::backgroundColourId, 0xffeeeebb,
  51695. TooltipWindow::textColourId, 0xff000000,
  51696. TooltipWindow::outlineColourId, 0x4c000000,
  51697. TabbedComponent::backgroundColourId, 0x00000000,
  51698. TabbedComponent::outlineColourId, 0xff777777,
  51699. TabbedButtonBar::tabOutlineColourId, 0x80000000,
  51700. TabbedButtonBar::frontOutlineColourId, 0x90000000,
  51701. Toolbar::backgroundColourId, 0xfff6f8f9,
  51702. Toolbar::separatorColourId, 0x4c000000,
  51703. Toolbar::buttonMouseOverBackgroundColourId, 0x4c0000ff,
  51704. Toolbar::buttonMouseDownBackgroundColourId, 0x800000ff,
  51705. Toolbar::labelTextColourId, 0xff000000,
  51706. Toolbar::editingModeOutlineColourId, 0xffff0000,
  51707. HyperlinkButton::textColourId, 0xcc1111ee,
  51708. GroupComponent::outlineColourId, 0x66000000,
  51709. GroupComponent::textColourId, 0xff000000,
  51710. DirectoryContentsDisplayComponent::highlightColourId, textHighlightColour,
  51711. DirectoryContentsDisplayComponent::textColourId, 0xff000000,
  51712. 0x1000440, /*LassoComponent::lassoFillColourId*/ 0x66dddddd,
  51713. 0x1000441, /*LassoComponent::lassoOutlineColourId*/ 0x99111111,
  51714. MidiKeyboardComponent::whiteNoteColourId, 0xffffffff,
  51715. MidiKeyboardComponent::blackNoteColourId, 0xff000000,
  51716. MidiKeyboardComponent::keySeparatorLineColourId, 0x66000000,
  51717. MidiKeyboardComponent::mouseOverKeyOverlayColourId, 0x80ffff00,
  51718. MidiKeyboardComponent::keyDownOverlayColourId, 0xffb6b600,
  51719. MidiKeyboardComponent::textLabelColourId, 0xff000000,
  51720. MidiKeyboardComponent::upDownButtonBackgroundColourId, 0xffd3d3d3,
  51721. MidiKeyboardComponent::upDownButtonArrowColourId, 0xff000000,
  51722. CodeEditorComponent::backgroundColourId, 0xffffffff,
  51723. CodeEditorComponent::caretColourId, 0xff000000,
  51724. CodeEditorComponent::highlightColourId, textHighlightColour,
  51725. CodeEditorComponent::defaultTextColourId, 0xff000000,
  51726. ColourSelector::backgroundColourId, 0xffe5e5e5,
  51727. ColourSelector::labelTextColourId, 0xff000000,
  51728. KeyMappingEditorComponent::backgroundColourId, 0x00000000,
  51729. KeyMappingEditorComponent::textColourId, 0xff000000,
  51730. FileSearchPathListComponent::backgroundColourId, 0xffffffff,
  51731. FileChooserDialogBox::titleTextColourId, 0xff000000,
  51732. };
  51733. for (int i = 0; i < numElementsInArray (standardColours); i += 2)
  51734. setColour (standardColours [i], Colour (standardColours [i + 1]));
  51735. if (defaultSansName.isEmpty())
  51736. Font::getPlatformDefaultFontNames (defaultSansName, defaultSerifName, defaultFixedName);
  51737. defaultSans = defaultSansName;
  51738. defaultSerif = defaultSerifName;
  51739. defaultFixed = defaultFixedName;
  51740. }
  51741. LookAndFeel::~LookAndFeel()
  51742. {
  51743. }
  51744. const Colour LookAndFeel::findColour (const int colourId) const throw()
  51745. {
  51746. const int index = colourIds.indexOf (colourId);
  51747. if (index >= 0)
  51748. return colours [index];
  51749. jassertfalse
  51750. return Colours::black;
  51751. }
  51752. void LookAndFeel::setColour (const int colourId, const Colour& colour) throw()
  51753. {
  51754. const int index = colourIds.indexOf (colourId);
  51755. if (index >= 0)
  51756. colours.set (index, colour);
  51757. colourIds.add (colourId);
  51758. colours.add (colour);
  51759. }
  51760. bool LookAndFeel::isColourSpecified (const int colourId) const throw()
  51761. {
  51762. return colourIds.contains (colourId);
  51763. }
  51764. static LookAndFeel* defaultLF = 0;
  51765. static LookAndFeel* currentDefaultLF = 0;
  51766. LookAndFeel& LookAndFeel::getDefaultLookAndFeel() throw()
  51767. {
  51768. // if this happens, your app hasn't initialised itself properly.. if you're
  51769. // trying to hack your own main() function, have a look at
  51770. // JUCEApplication::initialiseForGUI()
  51771. jassert (currentDefaultLF != 0);
  51772. return *currentDefaultLF;
  51773. }
  51774. void LookAndFeel::setDefaultLookAndFeel (LookAndFeel* newDefaultLookAndFeel) throw()
  51775. {
  51776. if (newDefaultLookAndFeel == 0)
  51777. {
  51778. if (defaultLF == 0)
  51779. defaultLF = new LookAndFeel();
  51780. newDefaultLookAndFeel = defaultLF;
  51781. }
  51782. currentDefaultLF = newDefaultLookAndFeel;
  51783. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  51784. {
  51785. Component* const c = Desktop::getInstance().getComponent (i);
  51786. if (c != 0)
  51787. c->sendLookAndFeelChange();
  51788. }
  51789. }
  51790. void LookAndFeel::clearDefaultLookAndFeel() throw()
  51791. {
  51792. if (currentDefaultLF == defaultLF)
  51793. currentDefaultLF = 0;
  51794. deleteAndZero (defaultLF);
  51795. }
  51796. const Typeface::Ptr LookAndFeel::getTypefaceForFont (const Font& font)
  51797. {
  51798. String faceName (font.getTypefaceName());
  51799. if (faceName == Font::getDefaultSansSerifFontName())
  51800. faceName = defaultSans;
  51801. else if (faceName == Font::getDefaultSerifFontName())
  51802. faceName = defaultSerif;
  51803. else if (faceName == Font::getDefaultMonospacedFontName())
  51804. faceName = defaultFixed;
  51805. Font f (font);
  51806. f.setTypefaceName (faceName);
  51807. return Typeface::createSystemTypefaceFor (f);
  51808. }
  51809. void LookAndFeel::setDefaultSansSerifTypefaceName (const String& newName)
  51810. {
  51811. defaultSans = newName;
  51812. }
  51813. const MouseCursor LookAndFeel::getMouseCursorFor (Component& component)
  51814. {
  51815. return component.getMouseCursor();
  51816. }
  51817. void LookAndFeel::drawButtonBackground (Graphics& g,
  51818. Button& button,
  51819. const Colour& backgroundColour,
  51820. bool isMouseOverButton,
  51821. bool isButtonDown)
  51822. {
  51823. const int width = button.getWidth();
  51824. const int height = button.getHeight();
  51825. const float outlineThickness = button.isEnabled() ? ((isButtonDown || isMouseOverButton) ? 1.2f : 0.7f) : 0.4f;
  51826. const float halfThickness = outlineThickness * 0.5f;
  51827. const float indentL = button.isConnectedOnLeft() ? 0.1f : halfThickness;
  51828. const float indentR = button.isConnectedOnRight() ? 0.1f : halfThickness;
  51829. const float indentT = button.isConnectedOnTop() ? 0.1f : halfThickness;
  51830. const float indentB = button.isConnectedOnBottom() ? 0.1f : halfThickness;
  51831. const Colour baseColour (createBaseColour (backgroundColour,
  51832. button.hasKeyboardFocus (true),
  51833. isMouseOverButton, isButtonDown)
  51834. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51835. drawGlassLozenge (g,
  51836. indentL,
  51837. indentT,
  51838. width - indentL - indentR,
  51839. height - indentT - indentB,
  51840. baseColour, outlineThickness, -1.0f,
  51841. button.isConnectedOnLeft(),
  51842. button.isConnectedOnRight(),
  51843. button.isConnectedOnTop(),
  51844. button.isConnectedOnBottom());
  51845. }
  51846. const Font LookAndFeel::getFontForTextButton (TextButton& button)
  51847. {
  51848. return button.getFont();
  51849. }
  51850. void LookAndFeel::drawButtonText (Graphics& g, TextButton& button,
  51851. bool /*isMouseOverButton*/, bool /*isButtonDown*/)
  51852. {
  51853. Font font (getFontForTextButton (button));
  51854. g.setFont (font);
  51855. g.setColour (button.findColour (button.getToggleState() ? TextButton::textColourOnId
  51856. : TextButton::textColourOffId)
  51857. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  51858. const int yIndent = jmin (4, button.proportionOfHeight (0.3f));
  51859. const int cornerSize = jmin (button.getHeight(), button.getWidth()) / 2;
  51860. const int fontHeight = roundToInt (font.getHeight() * 0.6f);
  51861. const int leftIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnLeft() ? 4 : 2));
  51862. const int rightIndent = jmin (fontHeight, 2 + cornerSize / (button.isConnectedOnRight() ? 4 : 2));
  51863. g.drawFittedText (button.getButtonText(),
  51864. leftIndent,
  51865. yIndent,
  51866. button.getWidth() - leftIndent - rightIndent,
  51867. button.getHeight() - yIndent * 2,
  51868. Justification::centred, 2);
  51869. }
  51870. void LookAndFeel::drawTickBox (Graphics& g,
  51871. Component& component,
  51872. float x, float y, float w, float h,
  51873. const bool ticked,
  51874. const bool isEnabled,
  51875. const bool isMouseOverButton,
  51876. const bool isButtonDown)
  51877. {
  51878. const float boxSize = w * 0.7f;
  51879. drawGlassSphere (g, x, y + (h - boxSize) * 0.5f, boxSize,
  51880. createBaseColour (component.findColour (TextButton::buttonColourId)
  51881. .withMultipliedAlpha (isEnabled ? 1.0f : 0.5f),
  51882. true,
  51883. isMouseOverButton,
  51884. isButtonDown),
  51885. isEnabled ? ((isButtonDown || isMouseOverButton) ? 1.1f : 0.5f) : 0.3f);
  51886. if (ticked)
  51887. {
  51888. Path tick;
  51889. tick.startNewSubPath (1.5f, 3.0f);
  51890. tick.lineTo (3.0f, 6.0f);
  51891. tick.lineTo (6.0f, 0.0f);
  51892. g.setColour (isEnabled ? Colours::black : Colours::grey);
  51893. const AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f)
  51894. .translated (x, y));
  51895. g.strokePath (tick, PathStrokeType (2.5f), trans);
  51896. }
  51897. }
  51898. void LookAndFeel::drawToggleButton (Graphics& g,
  51899. ToggleButton& button,
  51900. bool isMouseOverButton,
  51901. bool isButtonDown)
  51902. {
  51903. if (button.hasKeyboardFocus (true))
  51904. {
  51905. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  51906. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  51907. }
  51908. float fontSize = jmin (15.0f, button.getHeight() * 0.75f);
  51909. const float tickWidth = fontSize * 1.1f;
  51910. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  51911. tickWidth, tickWidth,
  51912. button.getToggleState(),
  51913. button.isEnabled(),
  51914. isMouseOverButton,
  51915. isButtonDown);
  51916. g.setColour (button.findColour (ToggleButton::textColourId));
  51917. g.setFont (fontSize);
  51918. if (! button.isEnabled())
  51919. g.setOpacity (0.5f);
  51920. const int textX = (int) tickWidth + 5;
  51921. g.drawFittedText (button.getButtonText(),
  51922. textX, 0,
  51923. button.getWidth() - textX - 2, button.getHeight(),
  51924. Justification::centredLeft, 10);
  51925. }
  51926. void LookAndFeel::changeToggleButtonWidthToFitText (ToggleButton& button)
  51927. {
  51928. Font font (jmin (15.0f, button.getHeight() * 0.6f));
  51929. const int tickWidth = jmin (24, button.getHeight());
  51930. button.setSize (font.getStringWidth (button.getButtonText()) + tickWidth + 8,
  51931. button.getHeight());
  51932. }
  51933. AlertWindow* LookAndFeel::createAlertWindow (const String& title,
  51934. const String& message,
  51935. const String& button1,
  51936. const String& button2,
  51937. const String& button3,
  51938. AlertWindow::AlertIconType iconType,
  51939. int numButtons,
  51940. Component* associatedComponent)
  51941. {
  51942. AlertWindow* aw = new AlertWindow (title, message, iconType, associatedComponent);
  51943. if (numButtons == 1)
  51944. {
  51945. aw->addButton (button1, 0,
  51946. KeyPress (KeyPress::escapeKey, 0, 0),
  51947. KeyPress (KeyPress::returnKey, 0, 0));
  51948. }
  51949. else
  51950. {
  51951. const KeyPress button1ShortCut (CharacterFunctions::toLowerCase (button1[0]), 0, 0);
  51952. KeyPress button2ShortCut (CharacterFunctions::toLowerCase (button2[0]), 0, 0);
  51953. if (button1ShortCut == button2ShortCut)
  51954. button2ShortCut = KeyPress();
  51955. if (numButtons == 2)
  51956. {
  51957. aw->addButton (button1, 1, KeyPress (KeyPress::returnKey, 0, 0), button1ShortCut);
  51958. aw->addButton (button2, 0, KeyPress (KeyPress::escapeKey, 0, 0), button2ShortCut);
  51959. }
  51960. else if (numButtons == 3)
  51961. {
  51962. aw->addButton (button1, 1, button1ShortCut);
  51963. aw->addButton (button2, 2, button2ShortCut);
  51964. aw->addButton (button3, 0, KeyPress (KeyPress::escapeKey, 0, 0));
  51965. }
  51966. }
  51967. return aw;
  51968. }
  51969. void LookAndFeel::drawAlertBox (Graphics& g,
  51970. AlertWindow& alert,
  51971. const Rectangle<int>& textArea,
  51972. TextLayout& textLayout)
  51973. {
  51974. g.fillAll (alert.findColour (AlertWindow::backgroundColourId));
  51975. int iconSpaceUsed = 0;
  51976. Justification alignment (Justification::horizontallyCentred);
  51977. const int iconWidth = 80;
  51978. int iconSize = jmin (iconWidth + 50, alert.getHeight() + 20);
  51979. if (alert.containsAnyExtraComponents() || alert.getNumButtons() > 2)
  51980. iconSize = jmin (iconSize, textArea.getHeight() + 50);
  51981. const Rectangle<int> iconRect (iconSize / -10, iconSize / -10,
  51982. iconSize, iconSize);
  51983. if (alert.getAlertType() != AlertWindow::NoIcon)
  51984. {
  51985. Path icon;
  51986. uint32 colour;
  51987. char character;
  51988. if (alert.getAlertType() == AlertWindow::WarningIcon)
  51989. {
  51990. colour = 0x55ff5555;
  51991. character = '!';
  51992. icon.addTriangle (iconRect.getX() + iconRect.getWidth() * 0.5f, (float) iconRect.getY(),
  51993. (float) iconRect.getRight(), (float) iconRect.getBottom(),
  51994. (float) iconRect.getX(), (float) iconRect.getBottom());
  51995. icon = icon.createPathWithRoundedCorners (5.0f);
  51996. }
  51997. else
  51998. {
  51999. colour = alert.getAlertType() == AlertWindow::InfoIcon ? 0x605555ff : 0x40b69900;
  52000. character = alert.getAlertType() == AlertWindow::InfoIcon ? 'i' : '?';
  52001. icon.addEllipse ((float) iconRect.getX(), (float) iconRect.getY(),
  52002. (float) iconRect.getWidth(), (float) iconRect.getHeight());
  52003. }
  52004. GlyphArrangement ga;
  52005. ga.addFittedText (Font (iconRect.getHeight() * 0.9f, Font::bold),
  52006. String::charToString (character),
  52007. (float) iconRect.getX(), (float) iconRect.getY(),
  52008. (float) iconRect.getWidth(), (float) iconRect.getHeight(),
  52009. Justification::centred, false);
  52010. ga.createPath (icon);
  52011. icon.setUsingNonZeroWinding (false);
  52012. g.setColour (Colour (colour));
  52013. g.fillPath (icon);
  52014. iconSpaceUsed = iconWidth;
  52015. alignment = Justification::left;
  52016. }
  52017. g.setColour (alert.findColour (AlertWindow::textColourId));
  52018. textLayout.drawWithin (g,
  52019. textArea.getX() + iconSpaceUsed, textArea.getY(),
  52020. textArea.getWidth() - iconSpaceUsed, textArea.getHeight(),
  52021. alignment.getFlags() | Justification::top);
  52022. g.setColour (alert.findColour (AlertWindow::outlineColourId));
  52023. g.drawRect (0, 0, alert.getWidth(), alert.getHeight());
  52024. }
  52025. int LookAndFeel::getAlertBoxWindowFlags()
  52026. {
  52027. return ComponentPeer::windowAppearsOnTaskbar
  52028. | ComponentPeer::windowHasDropShadow;
  52029. }
  52030. int LookAndFeel::getAlertWindowButtonHeight()
  52031. {
  52032. return 28;
  52033. }
  52034. const Font LookAndFeel::getAlertWindowFont()
  52035. {
  52036. return Font (12.0f);
  52037. }
  52038. void LookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  52039. int width, int height,
  52040. double progress, const String& textToShow)
  52041. {
  52042. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  52043. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  52044. g.fillAll (background);
  52045. if (progress >= 0.0f && progress < 1.0f)
  52046. {
  52047. drawGlassLozenge (g, 1.0f, 1.0f,
  52048. (float) jlimit (0.0, width - 2.0, progress * (width - 2.0)),
  52049. (float) (height - 2),
  52050. foreground,
  52051. 0.5f, 0.0f,
  52052. true, true, true, true);
  52053. }
  52054. else
  52055. {
  52056. // spinning bar..
  52057. g.setColour (foreground);
  52058. const int stripeWidth = height * 2;
  52059. const int position = (Time::getMillisecondCounter() / 15) % stripeWidth;
  52060. Path p;
  52061. for (float x = (float) (- position); x < width + stripeWidth; x += stripeWidth)
  52062. p.addQuadrilateral (x, 0.0f,
  52063. x + stripeWidth * 0.5f, 0.0f,
  52064. x, (float) height,
  52065. x - stripeWidth * 0.5f, (float) height);
  52066. Image im (Image::ARGB, width, height, true);
  52067. {
  52068. Graphics g2 (im);
  52069. drawGlassLozenge (g2, 1.0f, 1.0f,
  52070. (float) (width - 2),
  52071. (float) (height - 2),
  52072. foreground,
  52073. 0.5f, 0.0f,
  52074. true, true, true, true);
  52075. }
  52076. g.setTiledImageFill (im, 0, 0, 0.85f);
  52077. g.fillPath (p);
  52078. }
  52079. if (textToShow.isNotEmpty())
  52080. {
  52081. g.setColour (Colour::contrasting (background, foreground));
  52082. g.setFont (height * 0.6f);
  52083. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  52084. }
  52085. }
  52086. void LookAndFeel::drawSpinningWaitAnimation (Graphics& g, const Colour& colour, int x, int y, int w, int h)
  52087. {
  52088. const float radius = jmin (w, h) * 0.4f;
  52089. const float thickness = radius * 0.15f;
  52090. Path p;
  52091. p.addRoundedRectangle (radius * 0.4f, thickness * -0.5f,
  52092. radius * 0.6f, thickness,
  52093. thickness * 0.5f);
  52094. const float cx = x + w * 0.5f;
  52095. const float cy = y + h * 0.5f;
  52096. const uint32 animationIndex = (Time::getMillisecondCounter() / (1000 / 10)) % 12;
  52097. for (int i = 0; i < 12; ++i)
  52098. {
  52099. const int n = (i + 12 - animationIndex) % 12;
  52100. g.setColour (colour.withMultipliedAlpha ((n + 1) / 12.0f));
  52101. g.fillPath (p, AffineTransform::rotation (i * (float_Pi / 6.0f))
  52102. .translated (cx, cy));
  52103. }
  52104. }
  52105. void LookAndFeel::drawScrollbarButton (Graphics& g,
  52106. ScrollBar& scrollbar,
  52107. int width, int height,
  52108. int buttonDirection,
  52109. bool /*isScrollbarVertical*/,
  52110. bool /*isMouseOverButton*/,
  52111. bool isButtonDown)
  52112. {
  52113. Path p;
  52114. if (buttonDirection == 0)
  52115. p.addTriangle (width * 0.5f, height * 0.2f,
  52116. width * 0.1f, height * 0.7f,
  52117. width * 0.9f, height * 0.7f);
  52118. else if (buttonDirection == 1)
  52119. p.addTriangle (width * 0.8f, height * 0.5f,
  52120. width * 0.3f, height * 0.1f,
  52121. width * 0.3f, height * 0.9f);
  52122. else if (buttonDirection == 2)
  52123. p.addTriangle (width * 0.5f, height * 0.8f,
  52124. width * 0.1f, height * 0.3f,
  52125. width * 0.9f, height * 0.3f);
  52126. else if (buttonDirection == 3)
  52127. p.addTriangle (width * 0.2f, height * 0.5f,
  52128. width * 0.7f, height * 0.1f,
  52129. width * 0.7f, height * 0.9f);
  52130. if (isButtonDown)
  52131. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId).contrasting (0.2f));
  52132. else
  52133. g.setColour (scrollbar.findColour (ScrollBar::thumbColourId));
  52134. g.fillPath (p);
  52135. g.setColour (Colour (0x80000000));
  52136. g.strokePath (p, PathStrokeType (0.5f));
  52137. }
  52138. void LookAndFeel::drawScrollbar (Graphics& g,
  52139. ScrollBar& scrollbar,
  52140. int x, int y,
  52141. int width, int height,
  52142. bool isScrollbarVertical,
  52143. int thumbStartPosition,
  52144. int thumbSize,
  52145. bool /*isMouseOver*/,
  52146. bool /*isMouseDown*/)
  52147. {
  52148. g.fillAll (scrollbar.findColour (ScrollBar::backgroundColourId));
  52149. Path slotPath, thumbPath;
  52150. const float slotIndent = jmin (width, height) > 15 ? 1.0f : 0.0f;
  52151. const float slotIndentx2 = slotIndent * 2.0f;
  52152. const float thumbIndent = slotIndent + 1.0f;
  52153. const float thumbIndentx2 = thumbIndent * 2.0f;
  52154. float gx1 = 0.0f, gy1 = 0.0f, gx2 = 0.0f, gy2 = 0.0f;
  52155. if (isScrollbarVertical)
  52156. {
  52157. slotPath.addRoundedRectangle (x + slotIndent,
  52158. y + slotIndent,
  52159. width - slotIndentx2,
  52160. height - slotIndentx2,
  52161. (width - slotIndentx2) * 0.5f);
  52162. if (thumbSize > 0)
  52163. thumbPath.addRoundedRectangle (x + thumbIndent,
  52164. thumbStartPosition + thumbIndent,
  52165. width - thumbIndentx2,
  52166. thumbSize - thumbIndentx2,
  52167. (width - thumbIndentx2) * 0.5f);
  52168. gx1 = (float) x;
  52169. gx2 = x + width * 0.7f;
  52170. }
  52171. else
  52172. {
  52173. slotPath.addRoundedRectangle (x + slotIndent,
  52174. y + slotIndent,
  52175. width - slotIndentx2,
  52176. height - slotIndentx2,
  52177. (height - slotIndentx2) * 0.5f);
  52178. if (thumbSize > 0)
  52179. thumbPath.addRoundedRectangle (thumbStartPosition + thumbIndent,
  52180. y + thumbIndent,
  52181. thumbSize - thumbIndentx2,
  52182. height - thumbIndentx2,
  52183. (height - thumbIndentx2) * 0.5f);
  52184. gy1 = (float) y;
  52185. gy2 = y + height * 0.7f;
  52186. }
  52187. const Colour thumbColour (scrollbar.findColour (ScrollBar::thumbColourId));
  52188. g.setGradientFill (ColourGradient (thumbColour.overlaidWith (Colour (0x44000000)), gx1, gy1,
  52189. thumbColour.overlaidWith (Colour (0x19000000)), gx2, gy2, false));
  52190. g.fillPath (slotPath);
  52191. if (isScrollbarVertical)
  52192. {
  52193. gx1 = x + width * 0.6f;
  52194. gx2 = (float) x + width;
  52195. }
  52196. else
  52197. {
  52198. gy1 = y + height * 0.6f;
  52199. gy2 = (float) y + height;
  52200. }
  52201. g.setGradientFill (ColourGradient (Colours::transparentBlack,gx1, gy1,
  52202. Colour (0x19000000), gx2, gy2, false));
  52203. g.fillPath (slotPath);
  52204. g.setColour (thumbColour);
  52205. g.fillPath (thumbPath);
  52206. g.setGradientFill (ColourGradient (Colour (0x10000000), gx1, gy1,
  52207. Colours::transparentBlack, gx2, gy2, false));
  52208. g.saveState();
  52209. if (isScrollbarVertical)
  52210. g.reduceClipRegion (x + width / 2, y, width, height);
  52211. else
  52212. g.reduceClipRegion (x, y + height / 2, width, height);
  52213. g.fillPath (thumbPath);
  52214. g.restoreState();
  52215. g.setColour (Colour (0x4c000000));
  52216. g.strokePath (thumbPath, PathStrokeType (0.4f));
  52217. }
  52218. ImageEffectFilter* LookAndFeel::getScrollbarEffect()
  52219. {
  52220. return 0;
  52221. }
  52222. int LookAndFeel::getMinimumScrollbarThumbSize (ScrollBar& scrollbar)
  52223. {
  52224. return jmin (scrollbar.getWidth(), scrollbar.getHeight()) * 2;
  52225. }
  52226. int LookAndFeel::getDefaultScrollbarWidth()
  52227. {
  52228. return 18;
  52229. }
  52230. int LookAndFeel::getScrollbarButtonSize (ScrollBar& scrollbar)
  52231. {
  52232. return 2 + (scrollbar.isVertical() ? scrollbar.getWidth()
  52233. : scrollbar.getHeight());
  52234. }
  52235. const Path LookAndFeel::getTickShape (const float height)
  52236. {
  52237. static const unsigned char tickShapeData[] =
  52238. {
  52239. 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,
  52240. 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,
  52241. 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,
  52242. 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,
  52243. 96,140,68,0,128,188,67,0,224,168,68,0,0,119,67,99,101
  52244. };
  52245. Path p;
  52246. p.loadPathFromData (tickShapeData, sizeof (tickShapeData));
  52247. p.scaleToFit (0, 0, height * 2.0f, height, true);
  52248. return p;
  52249. }
  52250. const Path LookAndFeel::getCrossShape (const float height)
  52251. {
  52252. static const unsigned char crossShapeData[] =
  52253. {
  52254. 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,
  52255. 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,
  52256. 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,
  52257. 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,
  52258. 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,
  52259. 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,
  52260. 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
  52261. };
  52262. Path p;
  52263. p.loadPathFromData (crossShapeData, sizeof (crossShapeData));
  52264. p.scaleToFit (0, 0, height * 2.0f, height, true);
  52265. return p;
  52266. }
  52267. void LookAndFeel::drawTreeviewPlusMinusBox (Graphics& g, int x, int y, int w, int h, bool isPlus, bool /*isMouseOver*/)
  52268. {
  52269. const int boxSize = ((jmin (16, w, h) << 1) / 3) | 1;
  52270. x += (w - boxSize) >> 1;
  52271. y += (h - boxSize) >> 1;
  52272. w = boxSize;
  52273. h = boxSize;
  52274. g.setColour (Colour (0xe5ffffff));
  52275. g.fillRect (x, y, w, h);
  52276. g.setColour (Colour (0x80000000));
  52277. g.drawRect (x, y, w, h);
  52278. const float size = boxSize / 2 + 1.0f;
  52279. const float centre = (float) (boxSize / 2);
  52280. g.fillRect (x + (w - size) * 0.5f, y + centre, size, 1.0f);
  52281. if (isPlus)
  52282. g.fillRect (x + centre, y + (h - size) * 0.5f, 1.0f, size);
  52283. }
  52284. void LookAndFeel::drawBubble (Graphics& g,
  52285. float tipX, float tipY,
  52286. float boxX, float boxY,
  52287. float boxW, float boxH)
  52288. {
  52289. int side = 0;
  52290. if (tipX < boxX)
  52291. side = 1;
  52292. else if (tipX > boxX + boxW)
  52293. side = 3;
  52294. else if (tipY > boxY + boxH)
  52295. side = 2;
  52296. const float indent = 2.0f;
  52297. Path p;
  52298. p.addBubble (boxX + indent,
  52299. boxY + indent,
  52300. boxW - indent * 2.0f,
  52301. boxH - indent * 2.0f,
  52302. 5.0f,
  52303. tipX, tipY,
  52304. side,
  52305. 0.5f,
  52306. jmin (15.0f, boxW * 0.3f, boxH * 0.3f));
  52307. //xxx need to take comp as param for colour
  52308. g.setColour (findColour (TooltipWindow::backgroundColourId).withAlpha (0.9f));
  52309. g.fillPath (p);
  52310. //xxx as above
  52311. g.setColour (findColour (TooltipWindow::textColourId).withAlpha (0.4f));
  52312. g.strokePath (p, PathStrokeType (1.33f));
  52313. }
  52314. const Font LookAndFeel::getPopupMenuFont()
  52315. {
  52316. return Font (17.0f);
  52317. }
  52318. void LookAndFeel::getIdealPopupMenuItemSize (const String& text,
  52319. const bool isSeparator,
  52320. int standardMenuItemHeight,
  52321. int& idealWidth,
  52322. int& idealHeight)
  52323. {
  52324. if (isSeparator)
  52325. {
  52326. idealWidth = 50;
  52327. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight / 2 : 10;
  52328. }
  52329. else
  52330. {
  52331. Font font (getPopupMenuFont());
  52332. if (standardMenuItemHeight > 0 && font.getHeight() > standardMenuItemHeight / 1.3f)
  52333. font.setHeight (standardMenuItemHeight / 1.3f);
  52334. idealHeight = standardMenuItemHeight > 0 ? standardMenuItemHeight : roundToInt (font.getHeight() * 1.3f);
  52335. idealWidth = font.getStringWidth (text) + idealHeight * 2;
  52336. }
  52337. }
  52338. void LookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  52339. {
  52340. const Colour background (findColour (PopupMenu::backgroundColourId));
  52341. g.fillAll (background);
  52342. g.setColour (background.overlaidWith (Colour (0x2badd8e6)));
  52343. for (int i = 0; i < height; i += 3)
  52344. g.fillRect (0, i, width, 1);
  52345. #if ! JUCE_MAC
  52346. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.6f));
  52347. g.drawRect (0, 0, width, height);
  52348. #endif
  52349. }
  52350. void LookAndFeel::drawPopupMenuUpDownArrow (Graphics& g,
  52351. int width, int height,
  52352. bool isScrollUpArrow)
  52353. {
  52354. const Colour background (findColour (PopupMenu::backgroundColourId));
  52355. g.setGradientFill (ColourGradient (background, 0.0f, height * 0.5f,
  52356. background.withAlpha (0.0f),
  52357. 0.0f, isScrollUpArrow ? ((float) height) : 0.0f,
  52358. false));
  52359. g.fillRect (1, 1, width - 2, height - 2);
  52360. const float hw = width * 0.5f;
  52361. const float arrowW = height * 0.3f;
  52362. const float y1 = height * (isScrollUpArrow ? 0.6f : 0.3f);
  52363. const float y2 = height * (isScrollUpArrow ? 0.3f : 0.6f);
  52364. Path p;
  52365. p.addTriangle (hw - arrowW, y1,
  52366. hw + arrowW, y1,
  52367. hw, y2);
  52368. g.setColour (findColour (PopupMenu::textColourId).withAlpha (0.5f));
  52369. g.fillPath (p);
  52370. }
  52371. void LookAndFeel::drawPopupMenuItem (Graphics& g,
  52372. int width, int height,
  52373. const bool isSeparator,
  52374. const bool isActive,
  52375. const bool isHighlighted,
  52376. const bool isTicked,
  52377. const bool hasSubMenu,
  52378. const String& text,
  52379. const String& shortcutKeyText,
  52380. Image* image,
  52381. const Colour* const textColourToUse)
  52382. {
  52383. const float halfH = height * 0.5f;
  52384. if (isSeparator)
  52385. {
  52386. const float separatorIndent = 5.5f;
  52387. g.setColour (Colour (0x33000000));
  52388. g.drawLine (separatorIndent, halfH, width - separatorIndent, halfH);
  52389. g.setColour (Colour (0x66ffffff));
  52390. g.drawLine (separatorIndent, halfH + 1.0f, width - separatorIndent, halfH + 1.0f);
  52391. }
  52392. else
  52393. {
  52394. Colour textColour (findColour (PopupMenu::textColourId));
  52395. if (textColourToUse != 0)
  52396. textColour = *textColourToUse;
  52397. if (isHighlighted)
  52398. {
  52399. g.setColour (findColour (PopupMenu::highlightedBackgroundColourId));
  52400. g.fillRect (1, 1, width - 2, height - 2);
  52401. g.setColour (findColour (PopupMenu::highlightedTextColourId));
  52402. }
  52403. else
  52404. {
  52405. g.setColour (textColour);
  52406. }
  52407. if (! isActive)
  52408. g.setOpacity (0.3f);
  52409. Font font (getPopupMenuFont());
  52410. if (font.getHeight() > height / 1.3f)
  52411. font.setHeight (height / 1.3f);
  52412. g.setFont (font);
  52413. const int leftBorder = (height * 5) / 4;
  52414. const int rightBorder = 4;
  52415. if (image != 0)
  52416. {
  52417. g.drawImageWithin (image,
  52418. 2, 1, leftBorder - 4, height - 2,
  52419. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize, false);
  52420. }
  52421. else if (isTicked)
  52422. {
  52423. const Path tick (getTickShape (1.0f));
  52424. const float th = font.getAscent();
  52425. const float ty = halfH - th * 0.5f;
  52426. g.fillPath (tick, tick.getTransformToScaleToFit (2.0f, ty, (float) (leftBorder - 4),
  52427. th, true));
  52428. }
  52429. g.drawFittedText (text,
  52430. leftBorder, 0,
  52431. width - (leftBorder + rightBorder), height,
  52432. Justification::centredLeft, 1);
  52433. if (shortcutKeyText.isNotEmpty())
  52434. {
  52435. Font f2 (font);
  52436. f2.setHeight (f2.getHeight() * 0.75f);
  52437. f2.setHorizontalScale (0.95f);
  52438. g.setFont (f2);
  52439. g.drawText (shortcutKeyText,
  52440. leftBorder,
  52441. 0,
  52442. width - (leftBorder + rightBorder + 4),
  52443. height,
  52444. Justification::centredRight,
  52445. true);
  52446. }
  52447. if (hasSubMenu)
  52448. {
  52449. const float arrowH = 0.6f * getPopupMenuFont().getAscent();
  52450. const float x = width - height * 0.6f;
  52451. Path p;
  52452. p.addTriangle (x, halfH - arrowH * 0.5f,
  52453. x, halfH + arrowH * 0.5f,
  52454. x + arrowH * 0.6f, halfH);
  52455. g.fillPath (p);
  52456. }
  52457. }
  52458. }
  52459. int LookAndFeel::getMenuWindowFlags()
  52460. {
  52461. return ComponentPeer::windowHasDropShadow;
  52462. }
  52463. void LookAndFeel::drawMenuBarBackground (Graphics& g, int width, int height,
  52464. bool, MenuBarComponent& menuBar)
  52465. {
  52466. const Colour baseColour (createBaseColour (menuBar.findColour (PopupMenu::backgroundColourId), false, false, false));
  52467. if (menuBar.isEnabled())
  52468. {
  52469. drawShinyButtonShape (g,
  52470. -4.0f, 0.0f,
  52471. width + 8.0f, (float) height,
  52472. 0.0f,
  52473. baseColour,
  52474. 0.4f,
  52475. true, true, true, true);
  52476. }
  52477. else
  52478. {
  52479. g.fillAll (baseColour);
  52480. }
  52481. }
  52482. const Font LookAndFeel::getMenuBarFont (MenuBarComponent& menuBar, int /*itemIndex*/, const String& /*itemText*/)
  52483. {
  52484. return Font (menuBar.getHeight() * 0.7f);
  52485. }
  52486. int LookAndFeel::getMenuBarItemWidth (MenuBarComponent& menuBar, int itemIndex, const String& itemText)
  52487. {
  52488. return getMenuBarFont (menuBar, itemIndex, itemText)
  52489. .getStringWidth (itemText) + menuBar.getHeight();
  52490. }
  52491. void LookAndFeel::drawMenuBarItem (Graphics& g,
  52492. int width, int height,
  52493. int itemIndex,
  52494. const String& itemText,
  52495. bool isMouseOverItem,
  52496. bool isMenuOpen,
  52497. bool /*isMouseOverBar*/,
  52498. MenuBarComponent& menuBar)
  52499. {
  52500. if (! menuBar.isEnabled())
  52501. {
  52502. g.setColour (menuBar.findColour (PopupMenu::textColourId)
  52503. .withMultipliedAlpha (0.5f));
  52504. }
  52505. else if (isMenuOpen || isMouseOverItem)
  52506. {
  52507. g.fillAll (menuBar.findColour (PopupMenu::highlightedBackgroundColourId));
  52508. g.setColour (menuBar.findColour (PopupMenu::highlightedTextColourId));
  52509. }
  52510. else
  52511. {
  52512. g.setColour (menuBar.findColour (PopupMenu::textColourId));
  52513. }
  52514. g.setFont (getMenuBarFont (menuBar, itemIndex, itemText));
  52515. g.drawFittedText (itemText, 0, 0, width, height, Justification::centred, 1);
  52516. }
  52517. void LookAndFeel::fillTextEditorBackground (Graphics& g, int /*width*/, int /*height*/,
  52518. TextEditor& textEditor)
  52519. {
  52520. g.fillAll (textEditor.findColour (TextEditor::backgroundColourId));
  52521. }
  52522. void LookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  52523. {
  52524. if (textEditor.isEnabled())
  52525. {
  52526. if (textEditor.hasKeyboardFocus (true) && ! textEditor.isReadOnly())
  52527. {
  52528. const int border = 2;
  52529. g.setColour (textEditor.findColour (TextEditor::focusedOutlineColourId));
  52530. g.drawRect (0, 0, width, height, border);
  52531. g.setOpacity (1.0f);
  52532. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId).withMultipliedAlpha (0.75f));
  52533. g.drawBevel (0, 0, width, height + 2, border + 2, shadowColour, shadowColour);
  52534. }
  52535. else
  52536. {
  52537. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  52538. g.drawRect (0, 0, width, height);
  52539. g.setOpacity (1.0f);
  52540. const Colour shadowColour (textEditor.findColour (TextEditor::shadowColourId));
  52541. g.drawBevel (0, 0, width, height + 2, 3, shadowColour, shadowColour);
  52542. }
  52543. }
  52544. }
  52545. void LookAndFeel::drawComboBox (Graphics& g, int width, int height,
  52546. const bool isButtonDown,
  52547. int buttonX, int buttonY,
  52548. int buttonW, int buttonH,
  52549. ComboBox& box)
  52550. {
  52551. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  52552. if (box.isEnabled() && box.hasKeyboardFocus (false))
  52553. {
  52554. g.setColour (box.findColour (TextButton::buttonColourId));
  52555. g.drawRect (0, 0, width, height, 2);
  52556. }
  52557. else
  52558. {
  52559. g.setColour (box.findColour (ComboBox::outlineColourId));
  52560. g.drawRect (0, 0, width, height);
  52561. }
  52562. const float outlineThickness = box.isEnabled() ? (isButtonDown ? 1.2f : 0.5f) : 0.3f;
  52563. const Colour baseColour (createBaseColour (box.findColour (ComboBox::buttonColourId),
  52564. box.hasKeyboardFocus (true),
  52565. false, isButtonDown)
  52566. .withMultipliedAlpha (box.isEnabled() ? 1.0f : 0.5f));
  52567. drawGlassLozenge (g,
  52568. buttonX + outlineThickness, buttonY + outlineThickness,
  52569. buttonW - outlineThickness * 2.0f, buttonH - outlineThickness * 2.0f,
  52570. baseColour, outlineThickness, -1.0f,
  52571. true, true, true, true);
  52572. if (box.isEnabled())
  52573. {
  52574. const float arrowX = 0.3f;
  52575. const float arrowH = 0.2f;
  52576. Path p;
  52577. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  52578. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  52579. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  52580. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  52581. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  52582. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  52583. g.setColour (box.findColour (ComboBox::arrowColourId));
  52584. g.fillPath (p);
  52585. }
  52586. }
  52587. const Font LookAndFeel::getComboBoxFont (ComboBox& box)
  52588. {
  52589. return Font (jmin (15.0f, box.getHeight() * 0.85f));
  52590. }
  52591. Label* LookAndFeel::createComboBoxTextBox (ComboBox&)
  52592. {
  52593. return new Label (String::empty, String::empty);
  52594. }
  52595. void LookAndFeel::positionComboBoxText (ComboBox& box, Label& label)
  52596. {
  52597. label.setBounds (1, 1,
  52598. box.getWidth() + 3 - box.getHeight(),
  52599. box.getHeight() - 2);
  52600. label.setFont (getComboBoxFont (box));
  52601. }
  52602. void LookAndFeel::drawLabel (Graphics& g, Label& label)
  52603. {
  52604. g.fillAll (label.findColour (Label::backgroundColourId));
  52605. if (! label.isBeingEdited())
  52606. {
  52607. const float alpha = label.isEnabled() ? 1.0f : 0.5f;
  52608. g.setColour (label.findColour (Label::textColourId).withMultipliedAlpha (alpha));
  52609. g.setFont (label.getFont());
  52610. g.drawFittedText (label.getText(),
  52611. label.getHorizontalBorderSize(),
  52612. label.getVerticalBorderSize(),
  52613. label.getWidth() - 2 * label.getHorizontalBorderSize(),
  52614. label.getHeight() - 2 * label.getVerticalBorderSize(),
  52615. label.getJustificationType(),
  52616. jmax (1, (int) (label.getHeight() / label.getFont().getHeight())),
  52617. label.getMinimumHorizontalScale());
  52618. g.setColour (label.findColour (Label::outlineColourId).withMultipliedAlpha (alpha));
  52619. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52620. }
  52621. else if (label.isEnabled())
  52622. {
  52623. g.setColour (label.findColour (Label::outlineColourId));
  52624. g.drawRect (0, 0, label.getWidth(), label.getHeight());
  52625. }
  52626. }
  52627. void LookAndFeel::drawLinearSliderBackground (Graphics& g,
  52628. int x, int y,
  52629. int width, int height,
  52630. float /*sliderPos*/,
  52631. float /*minSliderPos*/,
  52632. float /*maxSliderPos*/,
  52633. const Slider::SliderStyle /*style*/,
  52634. Slider& slider)
  52635. {
  52636. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52637. const Colour trackColour (slider.findColour (Slider::trackColourId));
  52638. const Colour gradCol1 (trackColour.overlaidWith (Colours::black.withAlpha (slider.isEnabled() ? 0.25f : 0.13f)));
  52639. const Colour gradCol2 (trackColour.overlaidWith (Colour (0x14000000)));
  52640. Path indent;
  52641. if (slider.isHorizontal())
  52642. {
  52643. const float iy = y + height * 0.5f - sliderRadius * 0.5f;
  52644. const float ih = sliderRadius;
  52645. g.setGradientFill (ColourGradient (gradCol1, 0.0f, iy,
  52646. gradCol2, 0.0f, iy + ih, false));
  52647. indent.addRoundedRectangle (x - sliderRadius * 0.5f, iy,
  52648. width + sliderRadius, ih,
  52649. 5.0f);
  52650. g.fillPath (indent);
  52651. }
  52652. else
  52653. {
  52654. const float ix = x + width * 0.5f - sliderRadius * 0.5f;
  52655. const float iw = sliderRadius;
  52656. g.setGradientFill (ColourGradient (gradCol1, ix, 0.0f,
  52657. gradCol2, ix + iw, 0.0f, false));
  52658. indent.addRoundedRectangle (ix, y - sliderRadius * 0.5f,
  52659. iw, height + sliderRadius,
  52660. 5.0f);
  52661. g.fillPath (indent);
  52662. }
  52663. g.setColour (Colour (0x4c000000));
  52664. g.strokePath (indent, PathStrokeType (0.5f));
  52665. }
  52666. void LookAndFeel::drawLinearSliderThumb (Graphics& g,
  52667. int x, int y,
  52668. int width, int height,
  52669. float sliderPos,
  52670. float minSliderPos,
  52671. float maxSliderPos,
  52672. const Slider::SliderStyle style,
  52673. Slider& slider)
  52674. {
  52675. const float sliderRadius = (float) (getSliderThumbRadius (slider) - 2);
  52676. Colour knobColour (createBaseColour (slider.findColour (Slider::thumbColourId),
  52677. slider.hasKeyboardFocus (false) && slider.isEnabled(),
  52678. slider.isMouseOverOrDragging() && slider.isEnabled(),
  52679. slider.isMouseButtonDown() && slider.isEnabled()));
  52680. const float outlineThickness = slider.isEnabled() ? 0.8f : 0.3f;
  52681. if (style == Slider::LinearHorizontal || style == Slider::LinearVertical)
  52682. {
  52683. float kx, ky;
  52684. if (style == Slider::LinearVertical)
  52685. {
  52686. kx = x + width * 0.5f;
  52687. ky = sliderPos;
  52688. }
  52689. else
  52690. {
  52691. kx = sliderPos;
  52692. ky = y + height * 0.5f;
  52693. }
  52694. drawGlassSphere (g,
  52695. kx - sliderRadius,
  52696. ky - sliderRadius,
  52697. sliderRadius * 2.0f,
  52698. knobColour, outlineThickness);
  52699. }
  52700. else
  52701. {
  52702. if (style == Slider::ThreeValueVertical)
  52703. {
  52704. drawGlassSphere (g, x + width * 0.5f - sliderRadius,
  52705. sliderPos - sliderRadius,
  52706. sliderRadius * 2.0f,
  52707. knobColour, outlineThickness);
  52708. }
  52709. else if (style == Slider::ThreeValueHorizontal)
  52710. {
  52711. drawGlassSphere (g,sliderPos - sliderRadius,
  52712. y + height * 0.5f - sliderRadius,
  52713. sliderRadius * 2.0f,
  52714. knobColour, outlineThickness);
  52715. }
  52716. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  52717. {
  52718. const float sr = jmin (sliderRadius, width * 0.4f);
  52719. drawGlassPointer (g, jmax (0.0f, x + width * 0.5f - sliderRadius * 2.0f),
  52720. minSliderPos - sliderRadius,
  52721. sliderRadius * 2.0f, knobColour, outlineThickness, 1);
  52722. drawGlassPointer (g, jmin (x + width - sliderRadius * 2.0f, x + width * 0.5f), maxSliderPos - sr,
  52723. sliderRadius * 2.0f, knobColour, outlineThickness, 3);
  52724. }
  52725. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  52726. {
  52727. const float sr = jmin (sliderRadius, height * 0.4f);
  52728. drawGlassPointer (g, minSliderPos - sr,
  52729. jmax (0.0f, y + height * 0.5f - sliderRadius * 2.0f),
  52730. sliderRadius * 2.0f, knobColour, outlineThickness, 2);
  52731. drawGlassPointer (g, maxSliderPos - sliderRadius,
  52732. jmin (y + height - sliderRadius * 2.0f, y + height * 0.5f),
  52733. sliderRadius * 2.0f, knobColour, outlineThickness, 4);
  52734. }
  52735. }
  52736. }
  52737. void LookAndFeel::drawLinearSlider (Graphics& g,
  52738. int x, int y,
  52739. int width, int height,
  52740. float sliderPos,
  52741. float minSliderPos,
  52742. float maxSliderPos,
  52743. const Slider::SliderStyle style,
  52744. Slider& slider)
  52745. {
  52746. g.fillAll (slider.findColour (Slider::backgroundColourId));
  52747. if (style == Slider::LinearBar)
  52748. {
  52749. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52750. Colour baseColour (createBaseColour (slider.findColour (Slider::thumbColourId)
  52751. .withMultipliedSaturation (slider.isEnabled() ? 1.0f : 0.5f),
  52752. false,
  52753. isMouseOver,
  52754. isMouseOver || slider.isMouseButtonDown()));
  52755. drawShinyButtonShape (g,
  52756. (float) x, (float) y, sliderPos - (float) x, (float) height, 0.0f,
  52757. baseColour,
  52758. slider.isEnabled() ? 0.9f : 0.3f,
  52759. true, true, true, true);
  52760. }
  52761. else
  52762. {
  52763. drawLinearSliderBackground (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52764. drawLinearSliderThumb (g, x, y, width, height, sliderPos, minSliderPos, maxSliderPos, style, slider);
  52765. }
  52766. }
  52767. int LookAndFeel::getSliderThumbRadius (Slider& slider)
  52768. {
  52769. return jmin (7,
  52770. slider.getHeight() / 2,
  52771. slider.getWidth() / 2) + 2;
  52772. }
  52773. void LookAndFeel::drawRotarySlider (Graphics& g,
  52774. int x, int y,
  52775. int width, int height,
  52776. float sliderPos,
  52777. const float rotaryStartAngle,
  52778. const float rotaryEndAngle,
  52779. Slider& slider)
  52780. {
  52781. const float radius = jmin (width / 2, height / 2) - 2.0f;
  52782. const float centreX = x + width * 0.5f;
  52783. const float centreY = y + height * 0.5f;
  52784. const float rx = centreX - radius;
  52785. const float ry = centreY - radius;
  52786. const float rw = radius * 2.0f;
  52787. const float angle = rotaryStartAngle + sliderPos * (rotaryEndAngle - rotaryStartAngle);
  52788. const bool isMouseOver = slider.isMouseOverOrDragging() && slider.isEnabled();
  52789. if (radius > 12.0f)
  52790. {
  52791. if (slider.isEnabled())
  52792. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52793. else
  52794. g.setColour (Colour (0x80808080));
  52795. const float thickness = 0.7f;
  52796. {
  52797. Path filledArc;
  52798. filledArc.addPieSegment (rx, ry, rw, rw,
  52799. rotaryStartAngle,
  52800. angle,
  52801. thickness);
  52802. g.fillPath (filledArc);
  52803. }
  52804. if (thickness > 0)
  52805. {
  52806. const float innerRadius = radius * 0.2f;
  52807. Path p;
  52808. p.addTriangle (-innerRadius, 0.0f,
  52809. 0.0f, -radius * thickness * 1.1f,
  52810. innerRadius, 0.0f);
  52811. p.addEllipse (-innerRadius, -innerRadius, innerRadius * 2.0f, innerRadius * 2.0f);
  52812. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52813. }
  52814. if (slider.isEnabled())
  52815. g.setColour (slider.findColour (Slider::rotarySliderOutlineColourId));
  52816. else
  52817. g.setColour (Colour (0x80808080));
  52818. Path outlineArc;
  52819. outlineArc.addPieSegment (rx, ry, rw, rw, rotaryStartAngle, rotaryEndAngle, thickness);
  52820. outlineArc.closeSubPath();
  52821. g.strokePath (outlineArc, PathStrokeType (slider.isEnabled() ? (isMouseOver ? 2.0f : 1.2f) : 0.3f));
  52822. }
  52823. else
  52824. {
  52825. if (slider.isEnabled())
  52826. g.setColour (slider.findColour (Slider::rotarySliderFillColourId).withAlpha (isMouseOver ? 1.0f : 0.7f));
  52827. else
  52828. g.setColour (Colour (0x80808080));
  52829. Path p;
  52830. p.addEllipse (-0.4f * rw, -0.4f * rw, rw * 0.8f, rw * 0.8f);
  52831. PathStrokeType (rw * 0.1f).createStrokedPath (p, p);
  52832. p.addLineSegment (0.0f, 0.0f, 0.0f, -radius, rw * 0.2f);
  52833. g.fillPath (p, AffineTransform::rotation (angle).translated (centreX, centreY));
  52834. }
  52835. }
  52836. Button* LookAndFeel::createSliderButton (const bool isIncrement)
  52837. {
  52838. return new TextButton (isIncrement ? "+" : "-", String::empty);
  52839. }
  52840. class SliderLabelComp : public Label
  52841. {
  52842. public:
  52843. SliderLabelComp() : Label (String::empty, String::empty) {}
  52844. ~SliderLabelComp() {}
  52845. void mouseWheelMove (const MouseEvent&, float, float) {}
  52846. };
  52847. Label* LookAndFeel::createSliderTextBox (Slider& slider)
  52848. {
  52849. Label* const l = new SliderLabelComp();
  52850. l->setJustificationType (Justification::centred);
  52851. l->setColour (Label::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52852. l->setColour (Label::backgroundColourId,
  52853. (slider.getSliderStyle() == Slider::LinearBar) ? Colours::transparentBlack
  52854. : slider.findColour (Slider::textBoxBackgroundColourId));
  52855. l->setColour (Label::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52856. l->setColour (TextEditor::textColourId, slider.findColour (Slider::textBoxTextColourId));
  52857. l->setColour (TextEditor::backgroundColourId,
  52858. slider.findColour (Slider::textBoxBackgroundColourId)
  52859. .withAlpha (slider.getSliderStyle() == Slider::LinearBar ? 0.7f : 1.0f));
  52860. l->setColour (TextEditor::outlineColourId, slider.findColour (Slider::textBoxOutlineColourId));
  52861. return l;
  52862. }
  52863. ImageEffectFilter* LookAndFeel::getSliderEffect()
  52864. {
  52865. return 0;
  52866. }
  52867. static const TextLayout layoutTooltipText (const String& text) throw()
  52868. {
  52869. const float tooltipFontSize = 12.0f;
  52870. const int maxToolTipWidth = 400;
  52871. const Font f (tooltipFontSize, Font::bold);
  52872. TextLayout tl (text, f);
  52873. tl.layout (maxToolTipWidth, Justification::left, true);
  52874. return tl;
  52875. }
  52876. void LookAndFeel::getTooltipSize (const String& tipText, int& width, int& height)
  52877. {
  52878. const TextLayout tl (layoutTooltipText (tipText));
  52879. width = tl.getWidth() + 14;
  52880. height = tl.getHeight() + 6;
  52881. }
  52882. void LookAndFeel::drawTooltip (Graphics& g, const String& text, int width, int height)
  52883. {
  52884. g.fillAll (findColour (TooltipWindow::backgroundColourId));
  52885. const Colour textCol (findColour (TooltipWindow::textColourId));
  52886. #if ! JUCE_MAC // The mac windows already have a non-optional 1 pix outline, so don't double it here..
  52887. g.setColour (findColour (TooltipWindow::outlineColourId));
  52888. g.drawRect (0, 0, width, height, 1);
  52889. #endif
  52890. const TextLayout tl (layoutTooltipText (text));
  52891. g.setColour (findColour (TooltipWindow::textColourId));
  52892. tl.drawWithin (g, 0, 0, width, height, Justification::centred);
  52893. }
  52894. Button* LookAndFeel::createFilenameComponentBrowseButton (const String& text)
  52895. {
  52896. return new TextButton (text, TRANS("click to browse for a different file"));
  52897. }
  52898. void LookAndFeel::layoutFilenameComponent (FilenameComponent& filenameComp,
  52899. ComboBox* filenameBox,
  52900. Button* browseButton)
  52901. {
  52902. browseButton->setSize (80, filenameComp.getHeight());
  52903. TextButton* const tb = dynamic_cast <TextButton*> (browseButton);
  52904. if (tb != 0)
  52905. tb->changeWidthToFitText();
  52906. browseButton->setTopRightPosition (filenameComp.getWidth(), 0);
  52907. filenameBox->setBounds (0, 0, browseButton->getX(), filenameComp.getHeight());
  52908. }
  52909. void LookAndFeel::drawImageButton (Graphics& g, Image* image,
  52910. int imageX, int imageY, int imageW, int imageH,
  52911. const Colour& overlayColour,
  52912. float imageOpacity,
  52913. ImageButton& button)
  52914. {
  52915. if (! button.isEnabled())
  52916. imageOpacity *= 0.3f;
  52917. if (! overlayColour.isOpaque())
  52918. {
  52919. g.setOpacity (imageOpacity);
  52920. g.drawImage (image, imageX, imageY, imageW, imageH,
  52921. 0, 0, image->getWidth(), image->getHeight(), false);
  52922. }
  52923. if (! overlayColour.isTransparent())
  52924. {
  52925. g.setColour (overlayColour);
  52926. g.drawImage (image, imageX, imageY, imageW, imageH,
  52927. 0, 0, image->getWidth(), image->getHeight(), true);
  52928. }
  52929. }
  52930. void LookAndFeel::drawCornerResizer (Graphics& g,
  52931. int w, int h,
  52932. bool /*isMouseOver*/,
  52933. bool /*isMouseDragging*/)
  52934. {
  52935. const float lineThickness = jmin (w, h) * 0.075f;
  52936. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  52937. {
  52938. g.setColour (Colours::lightgrey);
  52939. g.drawLine (w * i,
  52940. h + 1.0f,
  52941. w + 1.0f,
  52942. h * i,
  52943. lineThickness);
  52944. g.setColour (Colours::darkgrey);
  52945. g.drawLine (w * i + lineThickness,
  52946. h + 1.0f,
  52947. w + 1.0f,
  52948. h * i + lineThickness,
  52949. lineThickness);
  52950. }
  52951. }
  52952. void LookAndFeel::drawResizableFrame (Graphics&, int /*w*/, int /*h*/,
  52953. const BorderSize& /*borders*/)
  52954. {
  52955. }
  52956. void LookAndFeel::fillResizableWindowBackground (Graphics& g, int /*w*/, int /*h*/,
  52957. const BorderSize& /*border*/, ResizableWindow& window)
  52958. {
  52959. g.fillAll (window.getBackgroundColour());
  52960. }
  52961. void LookAndFeel::drawResizableWindowBorder (Graphics& g, int w, int h,
  52962. const BorderSize& border, ResizableWindow&)
  52963. {
  52964. g.setColour (Colour (0x80000000));
  52965. g.drawRect (0, 0, w, h);
  52966. g.setColour (Colour (0x19000000));
  52967. g.drawRect (border.getLeft() - 1,
  52968. border.getTop() - 1,
  52969. w + 2 - border.getLeftAndRight(),
  52970. h + 2 - border.getTopAndBottom());
  52971. }
  52972. void LookAndFeel::drawDocumentWindowTitleBar (DocumentWindow& window,
  52973. Graphics& g, int w, int h,
  52974. int titleSpaceX, int titleSpaceW,
  52975. const Image* icon,
  52976. bool drawTitleTextOnLeft)
  52977. {
  52978. const bool isActive = window.isActiveWindow();
  52979. g.setGradientFill (ColourGradient (window.getBackgroundColour(),
  52980. 0.0f, 0.0f,
  52981. window.getBackgroundColour().contrasting (isActive ? 0.15f : 0.05f),
  52982. 0.0f, (float) h, false));
  52983. g.fillAll();
  52984. Font font (h * 0.65f, Font::bold);
  52985. g.setFont (font);
  52986. int textW = font.getStringWidth (window.getName());
  52987. int iconW = 0;
  52988. int iconH = 0;
  52989. if (icon != 0)
  52990. {
  52991. iconH = (int) font.getHeight();
  52992. iconW = icon->getWidth() * iconH / icon->getHeight() + 4;
  52993. }
  52994. textW = jmin (titleSpaceW, textW + iconW);
  52995. int textX = drawTitleTextOnLeft ? titleSpaceX
  52996. : jmax (titleSpaceX, (w - textW) / 2);
  52997. if (textX + textW > titleSpaceX + titleSpaceW)
  52998. textX = titleSpaceX + titleSpaceW - textW;
  52999. if (icon != 0)
  53000. {
  53001. g.setOpacity (isActive ? 1.0f : 0.6f);
  53002. g.drawImageWithin (icon, textX, (h - iconH) / 2, iconW, iconH,
  53003. RectanglePlacement::centred, false);
  53004. textX += iconW;
  53005. textW -= iconW;
  53006. }
  53007. if (window.isColourSpecified (DocumentWindow::textColourId) || isColourSpecified (DocumentWindow::textColourId))
  53008. g.setColour (findColour (DocumentWindow::textColourId));
  53009. else
  53010. g.setColour (window.getBackgroundColour().contrasting (isActive ? 0.7f : 0.4f));
  53011. g.drawText (window.getName(), textX, 0, textW, h, Justification::centredLeft, true);
  53012. }
  53013. class GlassWindowButton : public Button
  53014. {
  53015. public:
  53016. GlassWindowButton (const String& name, const Colour& col,
  53017. const Path& normalShape_,
  53018. const Path& toggledShape_) throw()
  53019. : Button (name),
  53020. colour (col),
  53021. normalShape (normalShape_),
  53022. toggledShape (toggledShape_)
  53023. {
  53024. }
  53025. ~GlassWindowButton()
  53026. {
  53027. }
  53028. void paintButton (Graphics& g, bool isMouseOverButton, bool isButtonDown)
  53029. {
  53030. float alpha = isMouseOverButton ? (isButtonDown ? 1.0f : 0.8f) : 0.55f;
  53031. if (! isEnabled())
  53032. alpha *= 0.5f;
  53033. float x = 0, y = 0, diam;
  53034. if (getWidth() < getHeight())
  53035. {
  53036. diam = (float) getWidth();
  53037. y = (getHeight() - getWidth()) * 0.5f;
  53038. }
  53039. else
  53040. {
  53041. diam = (float) getHeight();
  53042. y = (getWidth() - getHeight()) * 0.5f;
  53043. }
  53044. x += diam * 0.05f;
  53045. y += diam * 0.05f;
  53046. diam *= 0.9f;
  53047. g.setGradientFill (ColourGradient (Colour::greyLevel (0.9f).withAlpha (alpha), 0, y + diam,
  53048. Colour::greyLevel (0.6f).withAlpha (alpha), 0, y, false));
  53049. g.fillEllipse (x, y, diam, diam);
  53050. x += 2.0f;
  53051. y += 2.0f;
  53052. diam -= 4.0f;
  53053. LookAndFeel::drawGlassSphere (g, x, y, diam, colour.withAlpha (alpha), 1.0f);
  53054. Path& p = getToggleState() ? toggledShape : normalShape;
  53055. const AffineTransform t (p.getTransformToScaleToFit (x + diam * 0.3f, y + diam * 0.3f,
  53056. diam * 0.4f, diam * 0.4f, true));
  53057. g.setColour (Colours::black.withAlpha (alpha * 0.6f));
  53058. g.fillPath (p, t);
  53059. }
  53060. juce_UseDebuggingNewOperator
  53061. private:
  53062. Colour colour;
  53063. Path normalShape, toggledShape;
  53064. GlassWindowButton (const GlassWindowButton&);
  53065. GlassWindowButton& operator= (const GlassWindowButton&);
  53066. };
  53067. Button* LookAndFeel::createDocumentWindowButton (int buttonType)
  53068. {
  53069. Path shape;
  53070. const float crossThickness = 0.25f;
  53071. if (buttonType == DocumentWindow::closeButton)
  53072. {
  53073. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, crossThickness * 1.4f);
  53074. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, crossThickness * 1.4f);
  53075. return new GlassWindowButton ("close", Colour (0xffdd1100), shape, shape);
  53076. }
  53077. else if (buttonType == DocumentWindow::minimiseButton)
  53078. {
  53079. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  53080. return new GlassWindowButton ("minimise", Colour (0xffaa8811), shape, shape);
  53081. }
  53082. else if (buttonType == DocumentWindow::maximiseButton)
  53083. {
  53084. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, crossThickness);
  53085. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, crossThickness);
  53086. Path fullscreenShape;
  53087. fullscreenShape.startNewSubPath (45.0f, 100.0f);
  53088. fullscreenShape.lineTo (0.0f, 100.0f);
  53089. fullscreenShape.lineTo (0.0f, 0.0f);
  53090. fullscreenShape.lineTo (100.0f, 0.0f);
  53091. fullscreenShape.lineTo (100.0f, 45.0f);
  53092. fullscreenShape.addRectangle (45.0f, 45.0f, 100.0f, 100.0f);
  53093. PathStrokeType (30.0f).createStrokedPath (fullscreenShape, fullscreenShape);
  53094. return new GlassWindowButton ("maximise", Colour (0xff119911), shape, fullscreenShape);
  53095. }
  53096. jassertfalse
  53097. return 0;
  53098. }
  53099. void LookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  53100. int titleBarX,
  53101. int titleBarY,
  53102. int titleBarW,
  53103. int titleBarH,
  53104. Button* minimiseButton,
  53105. Button* maximiseButton,
  53106. Button* closeButton,
  53107. bool positionTitleBarButtonsOnLeft)
  53108. {
  53109. const int buttonW = titleBarH - titleBarH / 8;
  53110. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  53111. : titleBarX + titleBarW - buttonW - buttonW / 4;
  53112. if (closeButton != 0)
  53113. {
  53114. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53115. x += positionTitleBarButtonsOnLeft ? buttonW : -(buttonW + buttonW / 4);
  53116. }
  53117. if (positionTitleBarButtonsOnLeft)
  53118. swapVariables (minimiseButton, maximiseButton);
  53119. if (maximiseButton != 0)
  53120. {
  53121. maximiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53122. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  53123. }
  53124. if (minimiseButton != 0)
  53125. minimiseButton->setBounds (x, titleBarY, buttonW, titleBarH);
  53126. }
  53127. int LookAndFeel::getDefaultMenuBarHeight()
  53128. {
  53129. return 24;
  53130. }
  53131. DropShadower* LookAndFeel::createDropShadowerForComponent (Component*)
  53132. {
  53133. return new DropShadower (0.4f, 1, 5, 10);
  53134. }
  53135. void LookAndFeel::drawStretchableLayoutResizerBar (Graphics& g,
  53136. int w, int h,
  53137. bool /*isVerticalBar*/,
  53138. bool isMouseOver,
  53139. bool isMouseDragging)
  53140. {
  53141. float alpha = 0.5f;
  53142. if (isMouseOver || isMouseDragging)
  53143. {
  53144. g.fillAll (Colour (0x190000ff));
  53145. alpha = 1.0f;
  53146. }
  53147. const float cx = w * 0.5f;
  53148. const float cy = h * 0.5f;
  53149. const float cr = jmin (w, h) * 0.4f;
  53150. g.setGradientFill (ColourGradient (Colours::white.withAlpha (alpha), cx + cr * 0.1f, cy + cr,
  53151. Colours::black.withAlpha (alpha), cx, cy - cr * 4.0f,
  53152. true));
  53153. g.fillEllipse (cx - cr, cy - cr, cr * 2.0f, cr * 2.0f);
  53154. }
  53155. void LookAndFeel::drawGroupComponentOutline (Graphics& g, int width, int height,
  53156. const String& text,
  53157. const Justification& position,
  53158. GroupComponent& group)
  53159. {
  53160. const float textH = 15.0f;
  53161. const float indent = 3.0f;
  53162. const float textEdgeGap = 4.0f;
  53163. float cs = 5.0f;
  53164. Font f (textH);
  53165. Path p;
  53166. float x = indent;
  53167. float y = f.getAscent() - 3.0f;
  53168. float w = jmax (0.0f, width - x * 2.0f);
  53169. float h = jmax (0.0f, height - y - indent);
  53170. cs = jmin (cs, w * 0.5f, h * 0.5f);
  53171. const float cs2 = 2.0f * cs;
  53172. float textW = text.isEmpty() ? 0 : jlimit (0.0f, jmax (0.0f, w - cs2 - textEdgeGap * 2), f.getStringWidth (text) + textEdgeGap * 2.0f);
  53173. float textX = cs + textEdgeGap;
  53174. if (position.testFlags (Justification::horizontallyCentred))
  53175. textX = cs + (w - cs2 - textW) * 0.5f;
  53176. else if (position.testFlags (Justification::right))
  53177. textX = w - cs - textW - textEdgeGap;
  53178. p.startNewSubPath (x + textX + textW, y);
  53179. p.lineTo (x + w - cs, y);
  53180. p.addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  53181. p.lineTo (x + w, y + h - cs);
  53182. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53183. p.lineTo (x + cs, y + h);
  53184. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53185. p.lineTo (x, y + cs);
  53186. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53187. p.lineTo (x + textX, y);
  53188. const float alpha = group.isEnabled() ? 1.0f : 0.5f;
  53189. g.setColour (group.findColour (GroupComponent::outlineColourId)
  53190. .withMultipliedAlpha (alpha));
  53191. g.strokePath (p, PathStrokeType (2.0f));
  53192. g.setColour (group.findColour (GroupComponent::textColourId)
  53193. .withMultipliedAlpha (alpha));
  53194. g.setFont (f);
  53195. g.drawText (text,
  53196. roundToInt (x + textX), 0,
  53197. roundToInt (textW),
  53198. roundToInt (textH),
  53199. Justification::centred, true);
  53200. }
  53201. int LookAndFeel::getTabButtonOverlap (int tabDepth)
  53202. {
  53203. return 1 + tabDepth / 3;
  53204. }
  53205. int LookAndFeel::getTabButtonSpaceAroundImage()
  53206. {
  53207. return 4;
  53208. }
  53209. void LookAndFeel::createTabButtonShape (Path& p,
  53210. int width, int height,
  53211. int /*tabIndex*/,
  53212. const String& /*text*/,
  53213. Button& /*button*/,
  53214. TabbedButtonBar::Orientation orientation,
  53215. const bool /*isMouseOver*/,
  53216. const bool /*isMouseDown*/,
  53217. const bool /*isFrontTab*/)
  53218. {
  53219. const float w = (float) width;
  53220. const float h = (float) height;
  53221. float length = w;
  53222. float depth = h;
  53223. if (orientation == TabbedButtonBar::TabsAtLeft
  53224. || orientation == TabbedButtonBar::TabsAtRight)
  53225. {
  53226. swapVariables (length, depth);
  53227. }
  53228. const float indent = (float) getTabButtonOverlap ((int) depth);
  53229. const float overhang = 4.0f;
  53230. if (orientation == TabbedButtonBar::TabsAtLeft)
  53231. {
  53232. p.startNewSubPath (w, 0.0f);
  53233. p.lineTo (0.0f, indent);
  53234. p.lineTo (0.0f, h - indent);
  53235. p.lineTo (w, h);
  53236. p.lineTo (w + overhang, h + overhang);
  53237. p.lineTo (w + overhang, -overhang);
  53238. }
  53239. else if (orientation == TabbedButtonBar::TabsAtRight)
  53240. {
  53241. p.startNewSubPath (0.0f, 0.0f);
  53242. p.lineTo (w, indent);
  53243. p.lineTo (w, h - indent);
  53244. p.lineTo (0.0f, h);
  53245. p.lineTo (-overhang, h + overhang);
  53246. p.lineTo (-overhang, -overhang);
  53247. }
  53248. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53249. {
  53250. p.startNewSubPath (0.0f, 0.0f);
  53251. p.lineTo (indent, h);
  53252. p.lineTo (w - indent, h);
  53253. p.lineTo (w, 0.0f);
  53254. p.lineTo (w + overhang, -overhang);
  53255. p.lineTo (-overhang, -overhang);
  53256. }
  53257. else
  53258. {
  53259. p.startNewSubPath (0.0f, h);
  53260. p.lineTo (indent, 0.0f);
  53261. p.lineTo (w - indent, 0.0f);
  53262. p.lineTo (w, h);
  53263. p.lineTo (w + overhang, h + overhang);
  53264. p.lineTo (-overhang, h + overhang);
  53265. }
  53266. p.closeSubPath();
  53267. p = p.createPathWithRoundedCorners (3.0f);
  53268. }
  53269. void LookAndFeel::fillTabButtonShape (Graphics& g,
  53270. const Path& path,
  53271. const Colour& preferredColour,
  53272. int /*tabIndex*/,
  53273. const String& /*text*/,
  53274. Button& button,
  53275. TabbedButtonBar::Orientation /*orientation*/,
  53276. const bool /*isMouseOver*/,
  53277. const bool /*isMouseDown*/,
  53278. const bool isFrontTab)
  53279. {
  53280. g.setColour (isFrontTab ? preferredColour
  53281. : preferredColour.withMultipliedAlpha (0.9f));
  53282. g.fillPath (path);
  53283. g.setColour (button.findColour (isFrontTab ? TabbedButtonBar::frontOutlineColourId
  53284. : TabbedButtonBar::tabOutlineColourId, false)
  53285. .withMultipliedAlpha (button.isEnabled() ? 1.0f : 0.5f));
  53286. g.strokePath (path, PathStrokeType (isFrontTab ? 1.0f : 0.5f));
  53287. }
  53288. void LookAndFeel::drawTabButtonText (Graphics& g,
  53289. int x, int y, int w, int h,
  53290. const Colour& preferredBackgroundColour,
  53291. int /*tabIndex*/,
  53292. const String& text,
  53293. Button& button,
  53294. TabbedButtonBar::Orientation orientation,
  53295. const bool isMouseOver,
  53296. const bool isMouseDown,
  53297. const bool isFrontTab)
  53298. {
  53299. int length = w;
  53300. int depth = h;
  53301. if (orientation == TabbedButtonBar::TabsAtLeft
  53302. || orientation == TabbedButtonBar::TabsAtRight)
  53303. {
  53304. swapVariables (length, depth);
  53305. }
  53306. Font font (depth * 0.6f);
  53307. font.setUnderline (button.hasKeyboardFocus (false));
  53308. GlyphArrangement textLayout;
  53309. textLayout.addFittedText (font, text.trim(),
  53310. 0.0f, 0.0f, (float) length, (float) depth,
  53311. Justification::centred,
  53312. jmax (1, depth / 12));
  53313. AffineTransform transform;
  53314. if (orientation == TabbedButtonBar::TabsAtLeft)
  53315. {
  53316. transform = transform.rotated (float_Pi * -0.5f)
  53317. .translated ((float) x, (float) (y + h));
  53318. }
  53319. else if (orientation == TabbedButtonBar::TabsAtRight)
  53320. {
  53321. transform = transform.rotated (float_Pi * 0.5f)
  53322. .translated ((float) (x + w), (float) y);
  53323. }
  53324. else
  53325. {
  53326. transform = transform.translated ((float) x, (float) y);
  53327. }
  53328. if (isFrontTab && (button.isColourSpecified (TabbedButtonBar::frontTextColourId) || isColourSpecified (TabbedButtonBar::frontTextColourId)))
  53329. g.setColour (findColour (TabbedButtonBar::frontTextColourId));
  53330. else if (button.isColourSpecified (TabbedButtonBar::tabTextColourId) || isColourSpecified (TabbedButtonBar::tabTextColourId))
  53331. g.setColour (findColour (TabbedButtonBar::tabTextColourId));
  53332. else
  53333. g.setColour (preferredBackgroundColour.contrasting());
  53334. if (! (isMouseOver || isMouseDown))
  53335. g.setOpacity (0.8f);
  53336. if (! button.isEnabled())
  53337. g.setOpacity (0.3f);
  53338. textLayout.draw (g, transform);
  53339. }
  53340. int LookAndFeel::getTabButtonBestWidth (int /*tabIndex*/,
  53341. const String& text,
  53342. int tabDepth,
  53343. Button&)
  53344. {
  53345. Font f (tabDepth * 0.6f);
  53346. return f.getStringWidth (text.trim()) + getTabButtonOverlap (tabDepth) * 2;
  53347. }
  53348. void LookAndFeel::drawTabButton (Graphics& g,
  53349. int w, int h,
  53350. const Colour& preferredColour,
  53351. int tabIndex,
  53352. const String& text,
  53353. Button& button,
  53354. TabbedButtonBar::Orientation orientation,
  53355. const bool isMouseOver,
  53356. const bool isMouseDown,
  53357. const bool isFrontTab)
  53358. {
  53359. int length = w;
  53360. int depth = h;
  53361. if (orientation == TabbedButtonBar::TabsAtLeft
  53362. || orientation == TabbedButtonBar::TabsAtRight)
  53363. {
  53364. swapVariables (length, depth);
  53365. }
  53366. Path tabShape;
  53367. createTabButtonShape (tabShape, w, h,
  53368. tabIndex, text, button, orientation,
  53369. isMouseOver, isMouseDown, isFrontTab);
  53370. fillTabButtonShape (g, tabShape, preferredColour,
  53371. tabIndex, text, button, orientation,
  53372. isMouseOver, isMouseDown, isFrontTab);
  53373. const int indent = getTabButtonOverlap (depth);
  53374. int x = 0, y = 0;
  53375. if (orientation == TabbedButtonBar::TabsAtLeft
  53376. || orientation == TabbedButtonBar::TabsAtRight)
  53377. {
  53378. y += indent;
  53379. h -= indent * 2;
  53380. }
  53381. else
  53382. {
  53383. x += indent;
  53384. w -= indent * 2;
  53385. }
  53386. drawTabButtonText (g, x, y, w, h, preferredColour,
  53387. tabIndex, text, button, orientation,
  53388. isMouseOver, isMouseDown, isFrontTab);
  53389. }
  53390. void LookAndFeel::drawTabAreaBehindFrontButton (Graphics& g,
  53391. int w, int h,
  53392. TabbedButtonBar& tabBar,
  53393. TabbedButtonBar::Orientation orientation)
  53394. {
  53395. const float shadowSize = 0.2f;
  53396. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  53397. Rectangle<int> shadowRect;
  53398. if (orientation == TabbedButtonBar::TabsAtLeft)
  53399. {
  53400. x1 = (float) w;
  53401. x2 = w * (1.0f - shadowSize);
  53402. shadowRect.setBounds ((int) x2, 0, w - (int) x2, h);
  53403. }
  53404. else if (orientation == TabbedButtonBar::TabsAtRight)
  53405. {
  53406. x2 = w * shadowSize;
  53407. shadowRect.setBounds (0, 0, (int) x2, h);
  53408. }
  53409. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53410. {
  53411. y2 = h * shadowSize;
  53412. shadowRect.setBounds (0, 0, w, (int) y2);
  53413. }
  53414. else
  53415. {
  53416. y1 = (float) h;
  53417. y2 = h * (1.0f - shadowSize);
  53418. shadowRect.setBounds (0, (int) y2, w, h - (int) y2);
  53419. }
  53420. g.setGradientFill (ColourGradient (Colours::black.withAlpha (tabBar.isEnabled() ? 0.3f : 0.15f), x1, y1,
  53421. Colours::transparentBlack, x2, y2, false));
  53422. shadowRect.expand (2, 2);
  53423. g.fillRect (shadowRect);
  53424. g.setColour (Colour (0x80000000));
  53425. if (orientation == TabbedButtonBar::TabsAtLeft)
  53426. {
  53427. g.fillRect (w - 1, 0, 1, h);
  53428. }
  53429. else if (orientation == TabbedButtonBar::TabsAtRight)
  53430. {
  53431. g.fillRect (0, 0, 1, h);
  53432. }
  53433. else if (orientation == TabbedButtonBar::TabsAtBottom)
  53434. {
  53435. g.fillRect (0, 0, w, 1);
  53436. }
  53437. else
  53438. {
  53439. g.fillRect (0, h - 1, w, 1);
  53440. }
  53441. }
  53442. Button* LookAndFeel::createTabBarExtrasButton()
  53443. {
  53444. const float thickness = 7.0f;
  53445. const float indent = 22.0f;
  53446. Path p;
  53447. p.addEllipse (-10.0f, -10.0f, 120.0f, 120.0f);
  53448. DrawablePath ellipse;
  53449. ellipse.setPath (p);
  53450. ellipse.setFill (Colour (0x99ffffff));
  53451. p.clear();
  53452. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53453. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53454. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53455. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53456. p.setUsingNonZeroWinding (false);
  53457. DrawablePath dp;
  53458. dp.setPath (p);
  53459. dp.setFill (Colour (0x59000000));
  53460. DrawableComposite normalImage;
  53461. normalImage.insertDrawable (ellipse);
  53462. normalImage.insertDrawable (dp);
  53463. dp.setFill (Colour (0xcc000000));
  53464. DrawableComposite overImage;
  53465. overImage.insertDrawable (ellipse);
  53466. overImage.insertDrawable (dp);
  53467. DrawableButton* db = new DrawableButton (T("tabs"), DrawableButton::ImageFitted);
  53468. db->setImages (&normalImage, &overImage, 0);
  53469. return db;
  53470. }
  53471. void LookAndFeel::drawTableHeaderBackground (Graphics& g, TableHeaderComponent& header)
  53472. {
  53473. g.fillAll (Colours::white);
  53474. const int w = header.getWidth();
  53475. const int h = header.getHeight();
  53476. g.setGradientFill (ColourGradient (Colour (0xffe8ebf9), 0.0f, h * 0.5f,
  53477. Colour (0xfff6f8f9), 0.0f, h - 1.0f,
  53478. false));
  53479. g.fillRect (0, h / 2, w, h);
  53480. g.setColour (Colour (0x33000000));
  53481. g.fillRect (0, h - 1, w, 1);
  53482. for (int i = header.getNumColumns (true); --i >= 0;)
  53483. g.fillRect (header.getColumnPosition (i).getRight() - 1, 0, 1, h - 1);
  53484. }
  53485. void LookAndFeel::drawTableHeaderColumn (Graphics& g, const String& columnName, int /*columnId*/,
  53486. int width, int height,
  53487. bool isMouseOver, bool isMouseDown,
  53488. int columnFlags)
  53489. {
  53490. if (isMouseDown)
  53491. g.fillAll (Colour (0x8899aadd));
  53492. else if (isMouseOver)
  53493. g.fillAll (Colour (0x5599aadd));
  53494. int rightOfText = width - 4;
  53495. if ((columnFlags & (TableHeaderComponent::sortedForwards | TableHeaderComponent::sortedBackwards)) != 0)
  53496. {
  53497. const float top = height * ((columnFlags & TableHeaderComponent::sortedForwards) != 0 ? 0.35f : (1.0f - 0.35f));
  53498. const float bottom = height - top;
  53499. const float w = height * 0.5f;
  53500. const float x = rightOfText - (w * 1.25f);
  53501. rightOfText = (int) x;
  53502. Path sortArrow;
  53503. sortArrow.addTriangle (x, bottom, x + w * 0.5f, top, x + w, bottom);
  53504. g.setColour (Colour (0x99000000));
  53505. g.fillPath (sortArrow);
  53506. }
  53507. g.setColour (Colours::black);
  53508. g.setFont (height * 0.5f, Font::bold);
  53509. const int textX = 4;
  53510. g.drawFittedText (columnName, textX, 0, rightOfText - textX, height, Justification::centredLeft, 1);
  53511. }
  53512. void LookAndFeel::paintToolbarBackground (Graphics& g, int w, int h, Toolbar& toolbar)
  53513. {
  53514. const Colour background (toolbar.findColour (Toolbar::backgroundColourId));
  53515. g.setGradientFill (ColourGradient (background, 0.0f, 0.0f,
  53516. background.darker (0.1f),
  53517. toolbar.isVertical() ? w - 1.0f : 0.0f,
  53518. toolbar.isVertical() ? 0.0f : h - 1.0f,
  53519. false));
  53520. g.fillAll();
  53521. }
  53522. Button* LookAndFeel::createToolbarMissingItemsButton (Toolbar& /*toolbar*/)
  53523. {
  53524. return createTabBarExtrasButton();
  53525. }
  53526. void LookAndFeel::paintToolbarButtonBackground (Graphics& g, int /*width*/, int /*height*/,
  53527. bool isMouseOver, bool isMouseDown,
  53528. ToolbarItemComponent& component)
  53529. {
  53530. if (isMouseDown)
  53531. g.fillAll (component.findColour (Toolbar::buttonMouseDownBackgroundColourId, true));
  53532. else if (isMouseOver)
  53533. g.fillAll (component.findColour (Toolbar::buttonMouseOverBackgroundColourId, true));
  53534. }
  53535. void LookAndFeel::paintToolbarButtonLabel (Graphics& g, int x, int y, int width, int height,
  53536. const String& text, ToolbarItemComponent& component)
  53537. {
  53538. g.setColour (component.findColour (Toolbar::labelTextColourId, true)
  53539. .withAlpha (component.isEnabled() ? 1.0f : 0.25f));
  53540. const float fontHeight = jmin (14.0f, height * 0.85f);
  53541. g.setFont (fontHeight);
  53542. g.drawFittedText (text,
  53543. x, y, width, height,
  53544. Justification::centred,
  53545. jmax (1, height / (int) fontHeight));
  53546. }
  53547. void LookAndFeel::drawPropertyPanelSectionHeader (Graphics& g, const String& name,
  53548. bool isOpen, int width, int height)
  53549. {
  53550. const int buttonSize = (height * 3) / 4;
  53551. const int buttonIndent = (height - buttonSize) / 2;
  53552. drawTreeviewPlusMinusBox (g, buttonIndent, buttonIndent, buttonSize, buttonSize, ! isOpen, false);
  53553. const int textX = buttonIndent * 2 + buttonSize + 2;
  53554. g.setColour (Colours::black);
  53555. g.setFont (height * 0.7f, Font::bold);
  53556. g.drawText (name, textX, 0, width - textX - 4, height, Justification::centredLeft, true);
  53557. }
  53558. void LookAndFeel::drawPropertyComponentBackground (Graphics& g, int width, int height,
  53559. PropertyComponent&)
  53560. {
  53561. g.setColour (Colour (0x66ffffff));
  53562. g.fillRect (0, 0, width, height - 1);
  53563. }
  53564. void LookAndFeel::drawPropertyComponentLabel (Graphics& g, int, int height,
  53565. PropertyComponent& component)
  53566. {
  53567. g.setColour (Colours::black);
  53568. if (! component.isEnabled())
  53569. g.setOpacity (0.6f);
  53570. g.setFont (jmin (height, 24) * 0.65f);
  53571. const Rectangle<int> r (getPropertyComponentContentPosition (component));
  53572. g.drawFittedText (component.getName(),
  53573. 3, r.getY(), r.getX() - 5, r.getHeight(),
  53574. Justification::centredLeft, 2);
  53575. }
  53576. const Rectangle<int> LookAndFeel::getPropertyComponentContentPosition (PropertyComponent& component)
  53577. {
  53578. return Rectangle<int> (component.getWidth() / 3, 1,
  53579. component.getWidth() - component.getWidth() / 3 - 1, component.getHeight() - 3);
  53580. }
  53581. void LookAndFeel::createFileChooserHeaderText (const String& title,
  53582. const String& instructions,
  53583. GlyphArrangement& text,
  53584. int width)
  53585. {
  53586. text.clear();
  53587. text.addJustifiedText (Font (17.0f, Font::bold), title,
  53588. 8.0f, 22.0f, width - 16.0f,
  53589. Justification::centred);
  53590. text.addJustifiedText (Font (14.0f), instructions,
  53591. 8.0f, 24.0f + 16.0f, width - 16.0f,
  53592. Justification::centred);
  53593. }
  53594. void LookAndFeel::drawFileBrowserRow (Graphics& g, int width, int height,
  53595. const String& filename, Image* icon,
  53596. const String& fileSizeDescription,
  53597. const String& fileTimeDescription,
  53598. const bool isDirectory,
  53599. const bool isItemSelected,
  53600. const int /*itemIndex*/)
  53601. {
  53602. if (isItemSelected)
  53603. g.fillAll (findColour (DirectoryContentsDisplayComponent::highlightColourId));
  53604. g.setColour (findColour (DirectoryContentsDisplayComponent::textColourId));
  53605. g.setFont (height * 0.7f);
  53606. Image* im = icon;
  53607. Image* toRelease = 0;
  53608. if (im == 0)
  53609. {
  53610. toRelease = im = (isDirectory ? getDefaultFolderImage()
  53611. : getDefaultDocumentFileImage());
  53612. }
  53613. const int x = 32;
  53614. if (im != 0)
  53615. {
  53616. g.drawImageWithin (im, 2, 2, x - 4, height - 4,
  53617. RectanglePlacement::centred | RectanglePlacement::onlyReduceInSize,
  53618. false);
  53619. ImageCache::release (toRelease);
  53620. }
  53621. if (width > 450 && ! isDirectory)
  53622. {
  53623. const int sizeX = roundToInt (width * 0.7f);
  53624. const int dateX = roundToInt (width * 0.8f);
  53625. g.drawFittedText (filename,
  53626. x, 0, sizeX - x, height,
  53627. Justification::centredLeft, 1);
  53628. g.setFont (height * 0.5f);
  53629. g.setColour (Colours::darkgrey);
  53630. if (! isDirectory)
  53631. {
  53632. g.drawFittedText (fileSizeDescription,
  53633. sizeX, 0, dateX - sizeX - 8, height,
  53634. Justification::centredRight, 1);
  53635. g.drawFittedText (fileTimeDescription,
  53636. dateX, 0, width - 8 - dateX, height,
  53637. Justification::centredRight, 1);
  53638. }
  53639. }
  53640. else
  53641. {
  53642. g.drawFittedText (filename,
  53643. x, 0, width - x, height,
  53644. Justification::centredLeft, 1);
  53645. }
  53646. }
  53647. Button* LookAndFeel::createFileBrowserGoUpButton()
  53648. {
  53649. DrawableButton* goUpButton = new DrawableButton ("up", DrawableButton::ImageOnButtonBackground);
  53650. Path arrowPath;
  53651. arrowPath.addArrow (50.0f, 100.0f, 50.0f, 0.0f, 40.0f, 100.0f, 50.0f);
  53652. DrawablePath arrowImage;
  53653. arrowImage.setFill (Colours::black.withAlpha (0.4f));
  53654. arrowImage.setPath (arrowPath);
  53655. goUpButton->setImages (&arrowImage);
  53656. return goUpButton;
  53657. }
  53658. void LookAndFeel::layoutFileBrowserComponent (FileBrowserComponent& browserComp,
  53659. DirectoryContentsDisplayComponent* fileListComponent,
  53660. FilePreviewComponent* previewComp,
  53661. ComboBox* currentPathBox,
  53662. TextEditor* filenameBox,
  53663. Button* goUpButton)
  53664. {
  53665. const int x = 8;
  53666. int w = browserComp.getWidth() - x - x;
  53667. if (previewComp != 0)
  53668. {
  53669. const int previewWidth = w / 3;
  53670. previewComp->setBounds (x + w - previewWidth, 0, previewWidth, browserComp.getHeight());
  53671. w -= previewWidth + 4;
  53672. }
  53673. int y = 4;
  53674. const int controlsHeight = 22;
  53675. const int bottomSectionHeight = controlsHeight + 8;
  53676. const int upButtonWidth = 50;
  53677. currentPathBox->setBounds (x, y, w - upButtonWidth - 6, controlsHeight);
  53678. goUpButton->setBounds (x + w - upButtonWidth, y, upButtonWidth, controlsHeight);
  53679. y += controlsHeight + 4;
  53680. Component* const listAsComp = dynamic_cast <Component*> (fileListComponent);
  53681. listAsComp->setBounds (x, y, w, browserComp.getHeight() - y - bottomSectionHeight);
  53682. y = listAsComp->getBottom() + 4;
  53683. filenameBox->setBounds (x + 50, y, w - 50, controlsHeight);
  53684. }
  53685. Image* LookAndFeel::getDefaultFolderImage()
  53686. {
  53687. 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,
  53688. 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,
  53689. 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,
  53690. 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,
  53691. 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,
  53692. 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,
  53693. 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,
  53694. 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,
  53695. 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,
  53696. 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,
  53697. 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,
  53698. 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,
  53699. 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,
  53700. 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,
  53701. 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,
  53702. 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,
  53703. 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,
  53704. 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,
  53705. 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,
  53706. 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,
  53707. 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,
  53708. 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,
  53709. 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,
  53710. 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,
  53711. 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,
  53712. 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,
  53713. 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,
  53714. 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,
  53715. 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,
  53716. 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,
  53717. 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,
  53718. 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,
  53719. 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,
  53720. 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,
  53721. 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,
  53722. 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,
  53723. 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,
  53724. 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,
  53725. 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,
  53726. 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,
  53727. 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,
  53728. 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,
  53729. 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,
  53730. 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};
  53731. return ImageCache::getFromMemory (foldericon_png, sizeof (foldericon_png));
  53732. }
  53733. Image* LookAndFeel::getDefaultDocumentFileImage()
  53734. {
  53735. 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,
  53736. 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,
  53737. 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,
  53738. 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,
  53739. 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,
  53740. 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,
  53741. 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,
  53742. 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,
  53743. 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,
  53744. 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,
  53745. 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,
  53746. 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,
  53747. 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,
  53748. 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,
  53749. 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,
  53750. 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,
  53751. 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,
  53752. 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,
  53753. 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,
  53754. 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,
  53755. 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,
  53756. 174,66,96,130,0,0};
  53757. return ImageCache::getFromMemory (fileicon_png, sizeof (fileicon_png));
  53758. }
  53759. void LookAndFeel::playAlertSound()
  53760. {
  53761. PlatformUtilities::beep();
  53762. }
  53763. void LookAndFeel::drawLevelMeter (Graphics& g, int width, int height, float level)
  53764. {
  53765. g.setColour (Colours::white.withAlpha (0.7f));
  53766. g.fillRoundedRectangle (0.0f, 0.0f, (float) width, (float) height, 3.0f);
  53767. g.setColour (Colours::black.withAlpha (0.2f));
  53768. g.drawRoundedRectangle (1.0f, 1.0f, width - 2.0f, height - 2.0f, 3.0f, 1.0f);
  53769. const int totalBlocks = 7;
  53770. const int numBlocks = roundToInt (totalBlocks * level);
  53771. const float w = (width - 6.0f) / (float) totalBlocks;
  53772. for (int i = 0; i < totalBlocks; ++i)
  53773. {
  53774. if (i >= numBlocks)
  53775. g.setColour (Colours::lightblue.withAlpha (0.6f));
  53776. else
  53777. g.setColour (i < totalBlocks - 1 ? Colours::blue.withAlpha (0.5f)
  53778. : Colours::red);
  53779. g.fillRoundedRectangle (3.0f + i * w + w * 0.1f, 3.0f, w * 0.8f, height - 6.0f, w * 0.4f);
  53780. }
  53781. }
  53782. void LookAndFeel::drawKeymapChangeButton (Graphics& g, int width, int height, Button& button, const String& keyDescription)
  53783. {
  53784. const Colour textColour (button.findColour (KeyMappingEditorComponent::textColourId, true));
  53785. if (keyDescription.isNotEmpty())
  53786. {
  53787. if (button.isEnabled())
  53788. {
  53789. const float alpha = button.isDown() ? 0.3f : (button.isOver() ? 0.15f : 0.08f);
  53790. g.fillAll (textColour.withAlpha (alpha));
  53791. g.setOpacity (0.3f);
  53792. g.drawBevel (0, 0, width, height, 2);
  53793. }
  53794. g.setColour (textColour);
  53795. g.setFont (height * 0.6f);
  53796. g.drawFittedText (keyDescription,
  53797. 3, 0, width - 6, height,
  53798. Justification::centred, 1);
  53799. }
  53800. else
  53801. {
  53802. const float thickness = 7.0f;
  53803. const float indent = 22.0f;
  53804. Path p;
  53805. p.addEllipse (0.0f, 0.0f, 100.0f, 100.0f);
  53806. p.addRectangle (indent, 50.0f - thickness, 100.0f - indent * 2.0f, thickness * 2.0f);
  53807. p.addRectangle (50.0f - thickness, indent, thickness * 2.0f, 50.0f - indent - thickness);
  53808. p.addRectangle (50.0f - thickness, 50.0f + thickness, thickness * 2.0f, 50.0f - indent - thickness);
  53809. p.setUsingNonZeroWinding (false);
  53810. g.setColour (textColour.withAlpha (button.isDown() ? 0.7f : (button.isOver() ? 0.5f : 0.3f)));
  53811. g.fillPath (p, p.getTransformToScaleToFit (2.0f, 2.0f, width - 4.0f, height - 4.0f, true));
  53812. }
  53813. if (button.hasKeyboardFocus (false))
  53814. {
  53815. g.setColour (textColour.withAlpha (0.4f));
  53816. g.drawRect (0, 0, width, height);
  53817. }
  53818. }
  53819. static void createRoundedPath (Path& p,
  53820. const float x, const float y,
  53821. const float w, const float h,
  53822. const float cs,
  53823. const bool curveTopLeft, const bool curveTopRight,
  53824. const bool curveBottomLeft, const bool curveBottomRight) throw()
  53825. {
  53826. const float cs2 = 2.0f * cs;
  53827. if (curveTopLeft)
  53828. {
  53829. p.startNewSubPath (x, y + cs);
  53830. p.addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f);
  53831. }
  53832. else
  53833. {
  53834. p.startNewSubPath (x, y);
  53835. }
  53836. if (curveTopRight)
  53837. {
  53838. p.lineTo (x + w - cs, y);
  53839. p.addArc (x + w - cs2, y, cs2, cs2, 0.0f, float_Pi * 0.5f);
  53840. }
  53841. else
  53842. {
  53843. p.lineTo (x + w, y);
  53844. }
  53845. if (curveBottomRight)
  53846. {
  53847. p.lineTo (x + w, y + h - cs);
  53848. p.addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  53849. }
  53850. else
  53851. {
  53852. p.lineTo (x + w, y + h);
  53853. }
  53854. if (curveBottomLeft)
  53855. {
  53856. p.lineTo (x + cs, y + h);
  53857. p.addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  53858. }
  53859. else
  53860. {
  53861. p.lineTo (x, y + h);
  53862. }
  53863. p.closeSubPath();
  53864. }
  53865. void LookAndFeel::drawShinyButtonShape (Graphics& g,
  53866. float x, float y, float w, float h,
  53867. float maxCornerSize,
  53868. const Colour& baseColour,
  53869. const float strokeWidth,
  53870. const bool flatOnLeft,
  53871. const bool flatOnRight,
  53872. const bool flatOnTop,
  53873. const bool flatOnBottom) throw()
  53874. {
  53875. if (w <= strokeWidth * 1.1f || h <= strokeWidth * 1.1f)
  53876. return;
  53877. const float cs = jmin (maxCornerSize, w * 0.5f, h * 0.5f);
  53878. Path outline;
  53879. createRoundedPath (outline, x, y, w, h, cs,
  53880. ! (flatOnLeft || flatOnTop),
  53881. ! (flatOnRight || flatOnTop),
  53882. ! (flatOnLeft || flatOnBottom),
  53883. ! (flatOnRight || flatOnBottom));
  53884. ColourGradient cg (baseColour, 0.0f, y,
  53885. baseColour.overlaidWith (Colour (0x070000ff)), 0.0f, y + h,
  53886. false);
  53887. cg.addColour (0.5, baseColour.overlaidWith (Colour (0x33ffffff)));
  53888. cg.addColour (0.51, baseColour.overlaidWith (Colour (0x110000ff)));
  53889. g.setGradientFill (cg);
  53890. g.fillPath (outline);
  53891. g.setColour (Colour (0x80000000));
  53892. g.strokePath (outline, PathStrokeType (strokeWidth));
  53893. }
  53894. void LookAndFeel::drawGlassSphere (Graphics& g,
  53895. const float x, const float y,
  53896. const float diameter,
  53897. const Colour& colour,
  53898. const float outlineThickness) throw()
  53899. {
  53900. if (diameter <= outlineThickness)
  53901. return;
  53902. Path p;
  53903. p.addEllipse (x, y, diameter, diameter);
  53904. {
  53905. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53906. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53907. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53908. g.setGradientFill (cg);
  53909. g.fillPath (p);
  53910. }
  53911. g.setGradientFill (ColourGradient (Colours::white, 0, y + diameter * 0.06f,
  53912. Colours::transparentWhite, 0, y + diameter * 0.3f, false));
  53913. g.fillEllipse (x + diameter * 0.2f, y + diameter * 0.05f, diameter * 0.6f, diameter * 0.4f);
  53914. ColourGradient cg (Colours::transparentBlack,
  53915. x + diameter * 0.5f, y + diameter * 0.5f,
  53916. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53917. x, y + diameter * 0.5f, true);
  53918. cg.addColour (0.7, Colours::transparentBlack);
  53919. cg.addColour (0.8, Colours::black.withAlpha (0.1f * outlineThickness));
  53920. g.setGradientFill (cg);
  53921. g.fillPath (p);
  53922. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53923. g.drawEllipse (x, y, diameter, diameter, outlineThickness);
  53924. }
  53925. void LookAndFeel::drawGlassPointer (Graphics& g,
  53926. const float x, const float y,
  53927. const float diameter,
  53928. const Colour& colour, const float outlineThickness,
  53929. const int direction) throw()
  53930. {
  53931. if (diameter <= outlineThickness)
  53932. return;
  53933. Path p;
  53934. p.startNewSubPath (x + diameter * 0.5f, y);
  53935. p.lineTo (x + diameter, y + diameter * 0.6f);
  53936. p.lineTo (x + diameter, y + diameter);
  53937. p.lineTo (x, y + diameter);
  53938. p.lineTo (x, y + diameter * 0.6f);
  53939. p.closeSubPath();
  53940. p.applyTransform (AffineTransform::rotation (direction * (float_Pi * 0.5f), x + diameter * 0.5f, y + diameter * 0.5f));
  53941. {
  53942. ColourGradient cg (Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y,
  53943. Colours::white.overlaidWith (colour.withMultipliedAlpha (0.3f)), 0, y + diameter, false);
  53944. cg.addColour (0.4, Colours::white.overlaidWith (colour));
  53945. g.setGradientFill (cg);
  53946. g.fillPath (p);
  53947. }
  53948. ColourGradient cg (Colours::transparentBlack,
  53949. x + diameter * 0.5f, y + diameter * 0.5f,
  53950. Colours::black.withAlpha (0.5f * outlineThickness * colour.getFloatAlpha()),
  53951. x - diameter * 0.2f, y + diameter * 0.5f, true);
  53952. cg.addColour (0.5, Colours::transparentBlack);
  53953. cg.addColour (0.7, Colours::black.withAlpha (0.07f * outlineThickness));
  53954. g.setGradientFill (cg);
  53955. g.fillPath (p);
  53956. g.setColour (Colours::black.withAlpha (0.5f * colour.getFloatAlpha()));
  53957. g.strokePath (p, PathStrokeType (outlineThickness));
  53958. }
  53959. void LookAndFeel::drawGlassLozenge (Graphics& g,
  53960. const float x, const float y,
  53961. const float width, const float height,
  53962. const Colour& colour,
  53963. const float outlineThickness,
  53964. const float cornerSize,
  53965. const bool flatOnLeft,
  53966. const bool flatOnRight,
  53967. const bool flatOnTop,
  53968. const bool flatOnBottom) throw()
  53969. {
  53970. if (width <= outlineThickness || height <= outlineThickness)
  53971. return;
  53972. const int intX = (int) x;
  53973. const int intY = (int) y;
  53974. const int intW = (int) width;
  53975. const int intH = (int) height;
  53976. const float cs = cornerSize < 0 ? jmin (width * 0.5f, height * 0.5f) : cornerSize;
  53977. const float edgeBlurRadius = height * 0.75f + (height - cs * 2.0f);
  53978. const int intEdge = (int) edgeBlurRadius;
  53979. Path outline;
  53980. createRoundedPath (outline, x, y, width, height, cs,
  53981. ! (flatOnLeft || flatOnTop),
  53982. ! (flatOnRight || flatOnTop),
  53983. ! (flatOnLeft || flatOnBottom),
  53984. ! (flatOnRight || flatOnBottom));
  53985. {
  53986. ColourGradient cg (colour.darker (0.2f), 0, y,
  53987. colour.darker (0.2f), 0, y + height, false);
  53988. cg.addColour (0.03, colour.withMultipliedAlpha (0.3f));
  53989. cg.addColour (0.4, colour);
  53990. cg.addColour (0.97, colour.withMultipliedAlpha (0.3f));
  53991. g.setGradientFill (cg);
  53992. g.fillPath (outline);
  53993. }
  53994. ColourGradient cg (Colours::transparentBlack, x + edgeBlurRadius, y + height * 0.5f,
  53995. colour.darker (0.2f), x, y + height * 0.5f, true);
  53996. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.5f) / edgeBlurRadius), Colours::transparentBlack);
  53997. cg.addColour (jlimit (0.0, 1.0, 1.0 - (cs * 0.25f) / edgeBlurRadius), colour.darker (0.2f).withMultipliedAlpha (0.3f));
  53998. if (! (flatOnLeft || flatOnTop || flatOnBottom))
  53999. {
  54000. g.saveState();
  54001. g.setGradientFill (cg);
  54002. g.reduceClipRegion (intX, intY, intEdge, intH);
  54003. g.fillPath (outline);
  54004. g.restoreState();
  54005. }
  54006. if (! (flatOnRight || flatOnTop || flatOnBottom))
  54007. {
  54008. cg.x1 = x + width - edgeBlurRadius;
  54009. cg.x2 = x + width;
  54010. g.saveState();
  54011. g.setGradientFill (cg);
  54012. g.reduceClipRegion (intX + intW - intEdge, intY, 2 + intEdge, intH);
  54013. g.fillPath (outline);
  54014. g.restoreState();
  54015. }
  54016. {
  54017. const float leftIndent = flatOnLeft ? 0.0f : cs * 0.4f;
  54018. const float rightIndent = flatOnRight ? 0.0f : cs * 0.4f;
  54019. Path highlight;
  54020. createRoundedPath (highlight,
  54021. x + leftIndent,
  54022. y + cs * 0.1f,
  54023. width - (leftIndent + rightIndent),
  54024. height * 0.4f, cs * 0.4f,
  54025. ! (flatOnLeft || flatOnTop),
  54026. ! (flatOnRight || flatOnTop),
  54027. ! (flatOnLeft || flatOnBottom),
  54028. ! (flatOnRight || flatOnBottom));
  54029. g.setGradientFill (ColourGradient (colour.brighter (10.0f), 0, y + height * 0.06f,
  54030. Colours::transparentWhite, 0, y + height * 0.4f, false));
  54031. g.fillPath (highlight);
  54032. }
  54033. g.setColour (colour.darker().withMultipliedAlpha (1.5f));
  54034. g.strokePath (outline, PathStrokeType (outlineThickness));
  54035. }
  54036. END_JUCE_NAMESPACE
  54037. /*** End of inlined file: juce_LookAndFeel.cpp ***/
  54038. /*** Start of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  54039. BEGIN_JUCE_NAMESPACE
  54040. OldSchoolLookAndFeel::OldSchoolLookAndFeel()
  54041. {
  54042. setColour (TextButton::buttonColourId, Colour (0xffbbbbff));
  54043. setColour (ListBox::outlineColourId, findColour (ComboBox::outlineColourId));
  54044. setColour (ScrollBar::thumbColourId, Colour (0xffbbbbdd));
  54045. setColour (ScrollBar::backgroundColourId, Colours::transparentBlack);
  54046. setColour (Slider::thumbColourId, Colours::white);
  54047. setColour (Slider::trackColourId, Colour (0x7f000000));
  54048. setColour (Slider::textBoxOutlineColourId, Colours::grey);
  54049. setColour (ProgressBar::backgroundColourId, Colours::white.withAlpha (0.6f));
  54050. setColour (ProgressBar::foregroundColourId, Colours::green.withAlpha (0.7f));
  54051. setColour (PopupMenu::backgroundColourId, Colour (0xffeef5f8));
  54052. setColour (PopupMenu::highlightedBackgroundColourId, Colour (0xbfa4c2ce));
  54053. setColour (PopupMenu::highlightedTextColourId, Colours::black);
  54054. setColour (TextEditor::focusedOutlineColourId, findColour (TextButton::buttonColourId));
  54055. scrollbarShadow.setShadowProperties (2.2f, 0.5f, 0, 0);
  54056. }
  54057. OldSchoolLookAndFeel::~OldSchoolLookAndFeel()
  54058. {
  54059. }
  54060. void OldSchoolLookAndFeel::drawButtonBackground (Graphics& g,
  54061. Button& button,
  54062. const Colour& backgroundColour,
  54063. bool isMouseOverButton,
  54064. bool isButtonDown)
  54065. {
  54066. const int width = button.getWidth();
  54067. const int height = button.getHeight();
  54068. const float indent = 2.0f;
  54069. const int cornerSize = jmin (roundToInt (width * 0.4f),
  54070. roundToInt (height * 0.4f));
  54071. Path p;
  54072. p.addRoundedRectangle (indent, indent,
  54073. width - indent * 2.0f,
  54074. height - indent * 2.0f,
  54075. (float) cornerSize);
  54076. Colour bc (backgroundColour.withMultipliedSaturation (0.3f));
  54077. if (isMouseOverButton)
  54078. {
  54079. if (isButtonDown)
  54080. bc = bc.brighter();
  54081. else if (bc.getBrightness() > 0.5f)
  54082. bc = bc.darker (0.1f);
  54083. else
  54084. bc = bc.brighter (0.1f);
  54085. }
  54086. g.setColour (bc);
  54087. g.fillPath (p);
  54088. g.setColour (bc.contrasting().withAlpha ((isMouseOverButton) ? 0.6f : 0.4f));
  54089. g.strokePath (p, PathStrokeType ((isMouseOverButton) ? 2.0f : 1.4f));
  54090. }
  54091. void OldSchoolLookAndFeel::drawTickBox (Graphics& g,
  54092. Component& /*component*/,
  54093. float x, float y, float w, float h,
  54094. const bool ticked,
  54095. const bool isEnabled,
  54096. const bool /*isMouseOverButton*/,
  54097. const bool isButtonDown)
  54098. {
  54099. Path box;
  54100. box.addRoundedRectangle (0.0f, 2.0f, 6.0f, 6.0f, 1.0f);
  54101. g.setColour (isEnabled ? Colours::blue.withAlpha (isButtonDown ? 0.3f : 0.1f)
  54102. : Colours::lightgrey.withAlpha (0.1f));
  54103. AffineTransform trans (AffineTransform::scale (w / 9.0f, h / 9.0f).translated (x, y));
  54104. g.fillPath (box, trans);
  54105. g.setColour (Colours::black.withAlpha (0.6f));
  54106. g.strokePath (box, PathStrokeType (0.9f), trans);
  54107. if (ticked)
  54108. {
  54109. Path tick;
  54110. tick.startNewSubPath (1.5f, 3.0f);
  54111. tick.lineTo (3.0f, 6.0f);
  54112. tick.lineTo (6.0f, 0.0f);
  54113. g.setColour (isEnabled ? Colours::black : Colours::grey);
  54114. g.strokePath (tick, PathStrokeType (2.5f), trans);
  54115. }
  54116. }
  54117. void OldSchoolLookAndFeel::drawToggleButton (Graphics& g,
  54118. ToggleButton& button,
  54119. bool isMouseOverButton,
  54120. bool isButtonDown)
  54121. {
  54122. if (button.hasKeyboardFocus (true))
  54123. {
  54124. g.setColour (button.findColour (TextEditor::focusedOutlineColourId));
  54125. g.drawRect (0, 0, button.getWidth(), button.getHeight());
  54126. }
  54127. const int tickWidth = jmin (20, button.getHeight() - 4);
  54128. drawTickBox (g, button, 4.0f, (button.getHeight() - tickWidth) * 0.5f,
  54129. (float) tickWidth, (float) tickWidth,
  54130. button.getToggleState(),
  54131. button.isEnabled(),
  54132. isMouseOverButton,
  54133. isButtonDown);
  54134. g.setColour (button.findColour (ToggleButton::textColourId));
  54135. g.setFont (jmin (15.0f, button.getHeight() * 0.6f));
  54136. if (! button.isEnabled())
  54137. g.setOpacity (0.5f);
  54138. const int textX = tickWidth + 5;
  54139. g.drawFittedText (button.getButtonText(),
  54140. textX, 4,
  54141. button.getWidth() - textX - 2, button.getHeight() - 8,
  54142. Justification::centredLeft, 10);
  54143. }
  54144. void OldSchoolLookAndFeel::drawProgressBar (Graphics& g, ProgressBar& progressBar,
  54145. int width, int height,
  54146. double progress, const String& textToShow)
  54147. {
  54148. if (progress < 0 || progress >= 1.0)
  54149. {
  54150. LookAndFeel::drawProgressBar (g, progressBar, width, height, progress, textToShow);
  54151. }
  54152. else
  54153. {
  54154. const Colour background (progressBar.findColour (ProgressBar::backgroundColourId));
  54155. const Colour foreground (progressBar.findColour (ProgressBar::foregroundColourId));
  54156. g.fillAll (background);
  54157. g.setColour (foreground);
  54158. g.fillRect (1, 1,
  54159. jlimit (0, width - 2, roundToInt (progress * (width - 2))),
  54160. height - 2);
  54161. if (textToShow.isNotEmpty())
  54162. {
  54163. g.setColour (Colour::contrasting (background, foreground));
  54164. g.setFont (height * 0.6f);
  54165. g.drawText (textToShow, 0, 0, width, height, Justification::centred, false);
  54166. }
  54167. }
  54168. }
  54169. void OldSchoolLookAndFeel::drawScrollbarButton (Graphics& g,
  54170. ScrollBar& bar,
  54171. int width, int height,
  54172. int buttonDirection,
  54173. bool isScrollbarVertical,
  54174. bool isMouseOverButton,
  54175. bool isButtonDown)
  54176. {
  54177. if (isScrollbarVertical)
  54178. width -= 2;
  54179. else
  54180. height -= 2;
  54181. Path p;
  54182. if (buttonDirection == 0)
  54183. p.addTriangle (width * 0.5f, height * 0.2f,
  54184. width * 0.1f, height * 0.7f,
  54185. width * 0.9f, height * 0.7f);
  54186. else if (buttonDirection == 1)
  54187. p.addTriangle (width * 0.8f, height * 0.5f,
  54188. width * 0.3f, height * 0.1f,
  54189. width * 0.3f, height * 0.9f);
  54190. else if (buttonDirection == 2)
  54191. p.addTriangle (width * 0.5f, height * 0.8f,
  54192. width * 0.1f, height * 0.3f,
  54193. width * 0.9f, height * 0.3f);
  54194. else if (buttonDirection == 3)
  54195. p.addTriangle (width * 0.2f, height * 0.5f,
  54196. width * 0.7f, height * 0.1f,
  54197. width * 0.7f, height * 0.9f);
  54198. if (isButtonDown)
  54199. g.setColour (Colours::white);
  54200. else if (isMouseOverButton)
  54201. g.setColour (Colours::white.withAlpha (0.7f));
  54202. else
  54203. g.setColour (bar.findColour (ScrollBar::thumbColourId).withAlpha (0.5f));
  54204. g.fillPath (p);
  54205. g.setColour (Colours::black.withAlpha (0.5f));
  54206. g.strokePath (p, PathStrokeType (0.5f));
  54207. }
  54208. void OldSchoolLookAndFeel::drawScrollbar (Graphics& g,
  54209. ScrollBar& bar,
  54210. int x, int y,
  54211. int width, int height,
  54212. bool isScrollbarVertical,
  54213. int thumbStartPosition,
  54214. int thumbSize,
  54215. bool isMouseOver,
  54216. bool isMouseDown)
  54217. {
  54218. g.fillAll (bar.findColour (ScrollBar::backgroundColourId));
  54219. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  54220. .withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.15f));
  54221. if (thumbSize > 0.0f)
  54222. {
  54223. Rectangle<int> thumb;
  54224. if (isScrollbarVertical)
  54225. {
  54226. width -= 2;
  54227. g.fillRect (x + roundToInt (width * 0.35f), y,
  54228. roundToInt (width * 0.3f), height);
  54229. thumb.setBounds (x + 1, thumbStartPosition,
  54230. width - 2, thumbSize);
  54231. }
  54232. else
  54233. {
  54234. height -= 2;
  54235. g.fillRect (x, y + roundToInt (height * 0.35f),
  54236. width, roundToInt (height * 0.3f));
  54237. thumb.setBounds (thumbStartPosition, y + 1,
  54238. thumbSize, height - 2);
  54239. }
  54240. g.setColour (bar.findColour (ScrollBar::thumbColourId)
  54241. .withAlpha ((isMouseOver || isMouseDown) ? 0.95f : 0.7f));
  54242. g.fillRect (thumb);
  54243. g.setColour (Colours::black.withAlpha ((isMouseOver || isMouseDown) ? 0.4f : 0.25f));
  54244. g.drawRect (thumb.getX(), thumb.getY(), thumb.getWidth(), thumb.getHeight());
  54245. if (thumbSize > 16)
  54246. {
  54247. for (int i = 3; --i >= 0;)
  54248. {
  54249. const float linePos = thumbStartPosition + thumbSize / 2 + (i - 1) * 4.0f;
  54250. g.setColour (Colours::black.withAlpha (0.15f));
  54251. if (isScrollbarVertical)
  54252. {
  54253. g.drawLine (x + width * 0.2f, linePos, width * 0.8f, linePos);
  54254. g.setColour (Colours::white.withAlpha (0.15f));
  54255. g.drawLine (width * 0.2f, linePos - 1, width * 0.8f, linePos - 1);
  54256. }
  54257. else
  54258. {
  54259. g.drawLine (linePos, height * 0.2f, linePos, height * 0.8f);
  54260. g.setColour (Colours::white.withAlpha (0.15f));
  54261. g.drawLine (linePos - 1, height * 0.2f, linePos - 1, height * 0.8f);
  54262. }
  54263. }
  54264. }
  54265. }
  54266. }
  54267. ImageEffectFilter* OldSchoolLookAndFeel::getScrollbarEffect()
  54268. {
  54269. return &scrollbarShadow;
  54270. }
  54271. void OldSchoolLookAndFeel::drawPopupMenuBackground (Graphics& g, int width, int height)
  54272. {
  54273. g.fillAll (findColour (PopupMenu::backgroundColourId));
  54274. g.setColour (Colours::black.withAlpha (0.6f));
  54275. g.drawRect (0, 0, width, height);
  54276. }
  54277. void OldSchoolLookAndFeel::drawMenuBarBackground (Graphics& g, int /*width*/, int /*height*/,
  54278. bool, MenuBarComponent& menuBar)
  54279. {
  54280. g.fillAll (menuBar.findColour (PopupMenu::backgroundColourId));
  54281. }
  54282. void OldSchoolLookAndFeel::drawTextEditorOutline (Graphics& g, int width, int height, TextEditor& textEditor)
  54283. {
  54284. if (textEditor.isEnabled())
  54285. {
  54286. g.setColour (textEditor.findColour (TextEditor::outlineColourId));
  54287. g.drawRect (0, 0, width, height);
  54288. }
  54289. }
  54290. void OldSchoolLookAndFeel::drawComboBox (Graphics& g, int width, int height,
  54291. const bool isButtonDown,
  54292. int buttonX, int buttonY,
  54293. int buttonW, int buttonH,
  54294. ComboBox& box)
  54295. {
  54296. g.fillAll (box.findColour (ComboBox::backgroundColourId));
  54297. g.setColour (box.findColour ((isButtonDown) ? ComboBox::buttonColourId
  54298. : ComboBox::backgroundColourId));
  54299. g.fillRect (buttonX, buttonY, buttonW, buttonH);
  54300. g.setColour (box.findColour (ComboBox::outlineColourId));
  54301. g.drawRect (0, 0, width, height);
  54302. const float arrowX = 0.2f;
  54303. const float arrowH = 0.3f;
  54304. if (box.isEnabled())
  54305. {
  54306. Path p;
  54307. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.45f - arrowH),
  54308. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.45f,
  54309. buttonX + buttonW * arrowX, buttonY + buttonH * 0.45f);
  54310. p.addTriangle (buttonX + buttonW * 0.5f, buttonY + buttonH * (0.55f + arrowH),
  54311. buttonX + buttonW * (1.0f - arrowX), buttonY + buttonH * 0.55f,
  54312. buttonX + buttonW * arrowX, buttonY + buttonH * 0.55f);
  54313. g.setColour (box.findColour ((isButtonDown) ? ComboBox::backgroundColourId
  54314. : ComboBox::buttonColourId));
  54315. g.fillPath (p);
  54316. }
  54317. }
  54318. const Font OldSchoolLookAndFeel::getComboBoxFont (ComboBox& box)
  54319. {
  54320. Font f (jmin (15.0f, box.getHeight() * 0.85f));
  54321. f.setHorizontalScale (0.9f);
  54322. return f;
  54323. }
  54324. static void drawTriangle (Graphics& g, float x1, float y1, float x2, float y2, float x3, float y3, const Colour& fill, const Colour& outline) throw()
  54325. {
  54326. Path p;
  54327. p.addTriangle (x1, y1, x2, y2, x3, y3);
  54328. g.setColour (fill);
  54329. g.fillPath (p);
  54330. g.setColour (outline);
  54331. g.strokePath (p, PathStrokeType (0.3f));
  54332. }
  54333. void OldSchoolLookAndFeel::drawLinearSlider (Graphics& g,
  54334. int x, int y,
  54335. int w, int h,
  54336. float sliderPos,
  54337. float minSliderPos,
  54338. float maxSliderPos,
  54339. const Slider::SliderStyle style,
  54340. Slider& slider)
  54341. {
  54342. g.fillAll (slider.findColour (Slider::backgroundColourId));
  54343. if (style == Slider::LinearBar)
  54344. {
  54345. g.setColour (slider.findColour (Slider::thumbColourId));
  54346. g.fillRect (x, y, (int) sliderPos - x, h);
  54347. g.setColour (slider.findColour (Slider::textBoxTextColourId).withMultipliedAlpha (0.5f));
  54348. g.drawRect (x, y, (int) sliderPos - x, h);
  54349. }
  54350. else
  54351. {
  54352. g.setColour (slider.findColour (Slider::trackColourId)
  54353. .withMultipliedAlpha (slider.isEnabled() ? 1.0f : 0.3f));
  54354. if (slider.isHorizontal())
  54355. {
  54356. g.fillRect (x, y + roundToInt (h * 0.6f),
  54357. w, roundToInt (h * 0.2f));
  54358. }
  54359. else
  54360. {
  54361. g.fillRect (x + roundToInt (w * 0.5f - jmin (3.0f, w * 0.1f)), y,
  54362. jmin (4, roundToInt (w * 0.2f)), h);
  54363. }
  54364. float alpha = 0.35f;
  54365. if (slider.isEnabled())
  54366. alpha = slider.isMouseOverOrDragging() ? 1.0f : 0.7f;
  54367. const Colour fill (slider.findColour (Slider::thumbColourId).withAlpha (alpha));
  54368. const Colour outline (Colours::black.withAlpha (slider.isEnabled() ? 0.7f : 0.35f));
  54369. if (style == Slider::TwoValueVertical || style == Slider::ThreeValueVertical)
  54370. {
  54371. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), minSliderPos,
  54372. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos - 7.0f,
  54373. x + w * 0.5f - jmin (8.0f, w * 0.4f), minSliderPos,
  54374. fill, outline);
  54375. drawTriangle (g, x + w * 0.5f + jmin (4.0f, w * 0.3f), maxSliderPos,
  54376. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos,
  54377. x + w * 0.5f - jmin (8.0f, w * 0.4f), maxSliderPos + 7.0f,
  54378. fill, outline);
  54379. }
  54380. else if (style == Slider::TwoValueHorizontal || style == Slider::ThreeValueHorizontal)
  54381. {
  54382. drawTriangle (g, minSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  54383. minSliderPos - 7.0f, y + h * 0.9f ,
  54384. minSliderPos, y + h * 0.9f,
  54385. fill, outline);
  54386. drawTriangle (g, maxSliderPos, y + h * 0.6f - jmin (4.0f, h * 0.3f),
  54387. maxSliderPos, y + h * 0.9f,
  54388. maxSliderPos + 7.0f, y + h * 0.9f,
  54389. fill, outline);
  54390. }
  54391. if (style == Slider::LinearHorizontal || style == Slider::ThreeValueHorizontal)
  54392. {
  54393. drawTriangle (g, sliderPos, y + h * 0.9f,
  54394. sliderPos - 7.0f, y + h * 0.2f,
  54395. sliderPos + 7.0f, y + h * 0.2f,
  54396. fill, outline);
  54397. }
  54398. else if (style == Slider::LinearVertical || style == Slider::ThreeValueVertical)
  54399. {
  54400. drawTriangle (g, x + w * 0.5f - jmin (4.0f, w * 0.3f), sliderPos,
  54401. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos - 7.0f,
  54402. x + w * 0.5f + jmin (8.0f, w * 0.4f), sliderPos + 7.0f,
  54403. fill, outline);
  54404. }
  54405. }
  54406. }
  54407. Button* OldSchoolLookAndFeel::createSliderButton (const bool isIncrement)
  54408. {
  54409. if (isIncrement)
  54410. return new ArrowButton ("u", 0.75f, Colours::white.withAlpha (0.8f));
  54411. else
  54412. return new ArrowButton ("d", 0.25f, Colours::white.withAlpha (0.8f));
  54413. }
  54414. ImageEffectFilter* OldSchoolLookAndFeel::getSliderEffect()
  54415. {
  54416. return &scrollbarShadow;
  54417. }
  54418. int OldSchoolLookAndFeel::getSliderThumbRadius (Slider&)
  54419. {
  54420. return 8;
  54421. }
  54422. void OldSchoolLookAndFeel::drawCornerResizer (Graphics& g,
  54423. int w, int h,
  54424. bool isMouseOver,
  54425. bool isMouseDragging)
  54426. {
  54427. g.setColour ((isMouseOver || isMouseDragging) ? Colours::lightgrey
  54428. : Colours::darkgrey);
  54429. const float lineThickness = jmin (w, h) * 0.1f;
  54430. for (float i = 0.0f; i < 1.0f; i += 0.3f)
  54431. {
  54432. g.drawLine (w * i,
  54433. h + 1.0f,
  54434. w + 1.0f,
  54435. h * i,
  54436. lineThickness);
  54437. }
  54438. }
  54439. Button* OldSchoolLookAndFeel::createDocumentWindowButton (int buttonType)
  54440. {
  54441. Path shape;
  54442. if (buttonType == DocumentWindow::closeButton)
  54443. {
  54444. shape.addLineSegment (0.0f, 0.0f, 1.0f, 1.0f, 0.35f);
  54445. shape.addLineSegment (1.0f, 0.0f, 0.0f, 1.0f, 0.35f);
  54446. ShapeButton* const b = new ShapeButton ("close",
  54447. Colour (0x7fff3333),
  54448. Colour (0xd7ff3333),
  54449. Colour (0xf7ff3333));
  54450. b->setShape (shape, true, true, true);
  54451. return b;
  54452. }
  54453. else if (buttonType == DocumentWindow::minimiseButton)
  54454. {
  54455. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  54456. DrawableButton* b = new DrawableButton ("minimise", DrawableButton::ImageFitted);
  54457. DrawablePath dp;
  54458. dp.setPath (shape);
  54459. dp.setFill (Colours::black.withAlpha (0.3f));
  54460. b->setImages (&dp);
  54461. return b;
  54462. }
  54463. else if (buttonType == DocumentWindow::maximiseButton)
  54464. {
  54465. shape.addLineSegment (0.5f, 0.0f, 0.5f, 1.0f, 0.25f);
  54466. shape.addLineSegment (0.0f, 0.5f, 1.0f, 0.5f, 0.25f);
  54467. DrawableButton* b = new DrawableButton ("maximise", DrawableButton::ImageFitted);
  54468. DrawablePath dp;
  54469. dp.setPath (shape);
  54470. dp.setFill (Colours::black.withAlpha (0.3f));
  54471. b->setImages (&dp);
  54472. return b;
  54473. }
  54474. jassertfalse
  54475. return 0;
  54476. }
  54477. void OldSchoolLookAndFeel::positionDocumentWindowButtons (DocumentWindow&,
  54478. int titleBarX,
  54479. int titleBarY,
  54480. int titleBarW,
  54481. int titleBarH,
  54482. Button* minimiseButton,
  54483. Button* maximiseButton,
  54484. Button* closeButton,
  54485. bool positionTitleBarButtonsOnLeft)
  54486. {
  54487. titleBarY += titleBarH / 8;
  54488. titleBarH -= titleBarH / 4;
  54489. const int buttonW = titleBarH;
  54490. int x = positionTitleBarButtonsOnLeft ? titleBarX + 4
  54491. : titleBarX + titleBarW - buttonW - 4;
  54492. if (closeButton != 0)
  54493. {
  54494. closeButton->setBounds (x, titleBarY, buttonW, titleBarH);
  54495. x += positionTitleBarButtonsOnLeft ? buttonW + buttonW / 5
  54496. : -(buttonW + buttonW / 5);
  54497. }
  54498. if (positionTitleBarButtonsOnLeft)
  54499. swapVariables (minimiseButton, maximiseButton);
  54500. if (maximiseButton != 0)
  54501. {
  54502. maximiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  54503. x += positionTitleBarButtonsOnLeft ? buttonW : -buttonW;
  54504. }
  54505. if (minimiseButton != 0)
  54506. minimiseButton->setBounds (x, titleBarY - 2, buttonW, titleBarH);
  54507. }
  54508. END_JUCE_NAMESPACE
  54509. /*** End of inlined file: juce_OldSchoolLookAndFeel.cpp ***/
  54510. /*** Start of inlined file: juce_MenuBarComponent.cpp ***/
  54511. BEGIN_JUCE_NAMESPACE
  54512. class DummyMenuComponent : public Component
  54513. {
  54514. DummyMenuComponent (const DummyMenuComponent&);
  54515. DummyMenuComponent& operator= (const DummyMenuComponent&);
  54516. public:
  54517. DummyMenuComponent() {}
  54518. ~DummyMenuComponent() {}
  54519. void inputAttemptWhenModal()
  54520. {
  54521. exitModalState (0);
  54522. }
  54523. };
  54524. MenuBarComponent::MenuBarComponent (MenuBarModel* model_)
  54525. : model (0),
  54526. itemUnderMouse (-1),
  54527. currentPopupIndex (-1),
  54528. indexToShowAgain (-1),
  54529. lastMouseX (0),
  54530. lastMouseY (0),
  54531. inModalState (false)
  54532. {
  54533. setRepaintsOnMouseActivity (true);
  54534. setWantsKeyboardFocus (false);
  54535. setMouseClickGrabsKeyboardFocus (false);
  54536. setModel (model_);
  54537. }
  54538. MenuBarComponent::~MenuBarComponent()
  54539. {
  54540. setModel (0);
  54541. Desktop::getInstance().removeGlobalMouseListener (this);
  54542. currentPopup = 0;
  54543. }
  54544. void MenuBarComponent::setModel (MenuBarModel* const newModel)
  54545. {
  54546. if (model != newModel)
  54547. {
  54548. if (model != 0)
  54549. model->removeListener (this);
  54550. model = newModel;
  54551. if (model != 0)
  54552. model->addListener (this);
  54553. repaint();
  54554. menuBarItemsChanged (0);
  54555. }
  54556. }
  54557. void MenuBarComponent::paint (Graphics& g)
  54558. {
  54559. const bool isMouseOverBar = currentPopupIndex >= 0 || itemUnderMouse >= 0 || isMouseOver();
  54560. getLookAndFeel().drawMenuBarBackground (g,
  54561. getWidth(),
  54562. getHeight(),
  54563. isMouseOverBar,
  54564. *this);
  54565. if (model != 0)
  54566. {
  54567. for (int i = 0; i < menuNames.size(); ++i)
  54568. {
  54569. g.saveState();
  54570. g.setOrigin (xPositions [i], 0);
  54571. g.reduceClipRegion (0, 0, xPositions[i + 1] - xPositions[i], getHeight());
  54572. getLookAndFeel().drawMenuBarItem (g,
  54573. xPositions[i + 1] - xPositions[i],
  54574. getHeight(),
  54575. i,
  54576. menuNames[i],
  54577. i == itemUnderMouse,
  54578. i == currentPopupIndex,
  54579. isMouseOverBar,
  54580. *this);
  54581. g.restoreState();
  54582. }
  54583. }
  54584. }
  54585. void MenuBarComponent::resized()
  54586. {
  54587. xPositions.clear();
  54588. int x = 2;
  54589. xPositions.add (x);
  54590. for (int i = 0; i < menuNames.size(); ++i)
  54591. {
  54592. x += getLookAndFeel().getMenuBarItemWidth (*this, i, menuNames[i]);
  54593. xPositions.add (x);
  54594. }
  54595. }
  54596. int MenuBarComponent::getItemAt (const int x, const int y)
  54597. {
  54598. for (int i = 0; i < xPositions.size(); ++i)
  54599. if (x >= xPositions[i] && x < xPositions[i + 1])
  54600. return reallyContains (x, y, true) ? i : -1;
  54601. return -1;
  54602. }
  54603. void MenuBarComponent::repaintMenuItem (int index)
  54604. {
  54605. if (((unsigned int) index) < (unsigned int) xPositions.size())
  54606. {
  54607. const int x1 = xPositions [index];
  54608. const int x2 = xPositions [index + 1];
  54609. repaint (x1 - 2, 0, x2 - x1 + 4, getHeight());
  54610. }
  54611. }
  54612. void MenuBarComponent::updateItemUnderMouse (int x, int y)
  54613. {
  54614. const int newItem = getItemAt (x, y);
  54615. if (itemUnderMouse != newItem)
  54616. {
  54617. repaintMenuItem (itemUnderMouse);
  54618. itemUnderMouse = newItem;
  54619. repaintMenuItem (itemUnderMouse);
  54620. }
  54621. }
  54622. void MenuBarComponent::hideCurrentMenu()
  54623. {
  54624. currentPopup = 0;
  54625. repaint();
  54626. }
  54627. void MenuBarComponent::showMenu (int index)
  54628. {
  54629. if (index != currentPopupIndex)
  54630. {
  54631. if (inModalState)
  54632. {
  54633. hideCurrentMenu();
  54634. indexToShowAgain = index;
  54635. return;
  54636. }
  54637. indexToShowAgain = -1;
  54638. currentPopupIndex = -1;
  54639. itemUnderMouse = index;
  54640. currentPopup = 0;
  54641. menuBarItemsChanged (0);
  54642. Component* const prevFocused = getCurrentlyFocusedComponent();
  54643. ScopedPointer <ComponentDeletionWatcher> prevCompDeletionChecker;
  54644. if (prevFocused != 0)
  54645. prevCompDeletionChecker = new ComponentDeletionWatcher (prevFocused);
  54646. ComponentDeletionWatcher deletionChecker (this);
  54647. enterModalState (false);
  54648. inModalState = true;
  54649. int result = 0;
  54650. ApplicationCommandManager* managerOfChosenCommand = 0;
  54651. Desktop::getInstance().addGlobalMouseListener (this);
  54652. for (;;)
  54653. {
  54654. const int x = getScreenX() + xPositions [itemUnderMouse];
  54655. const int w = xPositions [itemUnderMouse + 1] - xPositions [itemUnderMouse];
  54656. currentPopupIndex = itemUnderMouse;
  54657. indexToShowAgain = -1;
  54658. repaint();
  54659. if (((unsigned int) itemUnderMouse) < (unsigned int) menuNames.size())
  54660. {
  54661. PopupMenu m (model->getMenuForIndex (itemUnderMouse,
  54662. menuNames [itemUnderMouse]));
  54663. if (m.lookAndFeel == 0)
  54664. m.setLookAndFeel (&getLookAndFeel());
  54665. currentPopup = m.createMenuComponent (x, getScreenY(),
  54666. w, getHeight(),
  54667. 0, w, 0, 0,
  54668. true, this,
  54669. &managerOfChosenCommand,
  54670. this);
  54671. }
  54672. if (currentPopup == 0)
  54673. {
  54674. currentPopup = new DummyMenuComponent();
  54675. addAndMakeVisible (currentPopup);
  54676. }
  54677. currentPopup->enterModalState (false);
  54678. currentPopup->toFront (false); // need to do this after making it modal, or it could
  54679. // be stuck behind other comps that are already modal..
  54680. result = currentPopup->runModalLoop();
  54681. if (deletionChecker.hasBeenDeleted())
  54682. return;
  54683. const int lastPopupIndex = currentPopupIndex;
  54684. currentPopup = 0;
  54685. currentPopupIndex = -1;
  54686. if (result != 0)
  54687. {
  54688. topLevelIndexClicked = lastPopupIndex;
  54689. break;
  54690. }
  54691. else if (indexToShowAgain >= 0)
  54692. {
  54693. menuBarItemsChanged (0);
  54694. repaint();
  54695. itemUnderMouse = indexToShowAgain;
  54696. if (((unsigned int) itemUnderMouse) >= (unsigned int) menuNames.size())
  54697. break;
  54698. }
  54699. else
  54700. {
  54701. break;
  54702. }
  54703. }
  54704. Desktop::getInstance().removeGlobalMouseListener (this);
  54705. inModalState = false;
  54706. exitModalState (0);
  54707. if (prevCompDeletionChecker != 0 && ! prevCompDeletionChecker->hasBeenDeleted())
  54708. prevFocused->grabKeyboardFocus();
  54709. const Point<int> mousePos (getMouseXYRelative());
  54710. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54711. repaint();
  54712. if (result != 0)
  54713. {
  54714. if (managerOfChosenCommand != 0)
  54715. {
  54716. ApplicationCommandTarget::InvocationInfo info (result);
  54717. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  54718. managerOfChosenCommand->invoke (info, true);
  54719. }
  54720. postCommandMessage (result);
  54721. }
  54722. }
  54723. }
  54724. void MenuBarComponent::handleCommandMessage (int commandId)
  54725. {
  54726. if (model != 0)
  54727. model->menuItemSelected (commandId, topLevelIndexClicked);
  54728. }
  54729. void MenuBarComponent::mouseEnter (const MouseEvent& e)
  54730. {
  54731. if (e.eventComponent == this)
  54732. updateItemUnderMouse (e.x, e.y);
  54733. }
  54734. void MenuBarComponent::mouseExit (const MouseEvent& e)
  54735. {
  54736. if (e.eventComponent == this)
  54737. updateItemUnderMouse (e.x, e.y);
  54738. }
  54739. void MenuBarComponent::mouseDown (const MouseEvent& e)
  54740. {
  54741. if (currentPopupIndex < 0)
  54742. {
  54743. const MouseEvent e2 (e.getEventRelativeTo (this));
  54744. updateItemUnderMouse (e2.x, e2.y);
  54745. currentPopupIndex = -2;
  54746. showMenu (itemUnderMouse);
  54747. }
  54748. }
  54749. void MenuBarComponent::mouseDrag (const MouseEvent& e)
  54750. {
  54751. const MouseEvent e2 (e.getEventRelativeTo (this));
  54752. const int item = getItemAt (e2.x, e2.y);
  54753. if (item >= 0)
  54754. showMenu (item);
  54755. }
  54756. void MenuBarComponent::mouseUp (const MouseEvent& e)
  54757. {
  54758. const MouseEvent e2 (e.getEventRelativeTo (this));
  54759. updateItemUnderMouse (e2.x, e2.y);
  54760. if (itemUnderMouse < 0 && dynamic_cast <DummyMenuComponent*> ((Component*) currentPopup) != 0)
  54761. hideCurrentMenu();
  54762. }
  54763. void MenuBarComponent::mouseMove (const MouseEvent& e)
  54764. {
  54765. const MouseEvent e2 (e.getEventRelativeTo (this));
  54766. if (lastMouseX != e2.x || lastMouseY != e2.y)
  54767. {
  54768. if (currentPopupIndex >= 0)
  54769. {
  54770. const int item = getItemAt (e2.x, e2.y);
  54771. if (item >= 0)
  54772. showMenu (item);
  54773. }
  54774. else
  54775. {
  54776. updateItemUnderMouse (e2.x, e2.y);
  54777. }
  54778. lastMouseX = e2.x;
  54779. lastMouseY = e2.y;
  54780. }
  54781. }
  54782. bool MenuBarComponent::keyPressed (const KeyPress& key)
  54783. {
  54784. bool used = false;
  54785. const int numMenus = menuNames.size();
  54786. const int currentIndex = jlimit (0, menuNames.size() - 1, currentPopupIndex);
  54787. if (key.isKeyCode (KeyPress::leftKey))
  54788. {
  54789. showMenu ((currentIndex + numMenus - 1) % numMenus);
  54790. used = true;
  54791. }
  54792. else if (key.isKeyCode (KeyPress::rightKey))
  54793. {
  54794. showMenu ((currentIndex + 1) % numMenus);
  54795. used = true;
  54796. }
  54797. return used;
  54798. }
  54799. void MenuBarComponent::inputAttemptWhenModal()
  54800. {
  54801. hideCurrentMenu();
  54802. }
  54803. void MenuBarComponent::menuBarItemsChanged (MenuBarModel* /*menuBarModel*/)
  54804. {
  54805. StringArray newNames;
  54806. if (model != 0)
  54807. newNames = model->getMenuBarNames();
  54808. if (newNames != menuNames)
  54809. {
  54810. menuNames = newNames;
  54811. repaint();
  54812. resized();
  54813. }
  54814. }
  54815. void MenuBarComponent::menuCommandInvoked (MenuBarModel* /*menuBarModel*/,
  54816. const ApplicationCommandTarget::InvocationInfo& info)
  54817. {
  54818. if (model == 0
  54819. || (info.commandFlags & ApplicationCommandInfo::dontTriggerVisualFeedback) != 0)
  54820. return;
  54821. for (int i = 0; i < menuNames.size(); ++i)
  54822. {
  54823. const PopupMenu menu (model->getMenuForIndex (i, menuNames [i]));
  54824. if (menu.containsCommandItem (info.commandID))
  54825. {
  54826. itemUnderMouse = i;
  54827. repaintMenuItem (i);
  54828. startTimer (200);
  54829. break;
  54830. }
  54831. }
  54832. }
  54833. void MenuBarComponent::timerCallback()
  54834. {
  54835. stopTimer();
  54836. const Point<int> mousePos (getMouseXYRelative());
  54837. updateItemUnderMouse (mousePos.getX(), mousePos.getY());
  54838. }
  54839. END_JUCE_NAMESPACE
  54840. /*** End of inlined file: juce_MenuBarComponent.cpp ***/
  54841. /*** Start of inlined file: juce_MenuBarModel.cpp ***/
  54842. BEGIN_JUCE_NAMESPACE
  54843. MenuBarModel::MenuBarModel() throw()
  54844. : manager (0)
  54845. {
  54846. }
  54847. MenuBarModel::~MenuBarModel()
  54848. {
  54849. setApplicationCommandManagerToWatch (0);
  54850. }
  54851. void MenuBarModel::menuItemsChanged()
  54852. {
  54853. triggerAsyncUpdate();
  54854. }
  54855. void MenuBarModel::setApplicationCommandManagerToWatch (ApplicationCommandManager* const newManager) throw()
  54856. {
  54857. if (manager != newManager)
  54858. {
  54859. if (manager != 0)
  54860. manager->removeListener (this);
  54861. manager = newManager;
  54862. if (manager != 0)
  54863. manager->addListener (this);
  54864. }
  54865. }
  54866. void MenuBarModel::addListener (MenuBarModelListener* const newListener) throw()
  54867. {
  54868. jassert (newListener != 0);
  54869. jassert (! listeners.contains (newListener)); // trying to add a listener to the list twice!
  54870. if (newListener != 0)
  54871. listeners.add (newListener);
  54872. }
  54873. void MenuBarModel::removeListener (MenuBarModelListener* const listenerToRemove) throw()
  54874. {
  54875. // Trying to remove a listener that isn't on the list!
  54876. // If this assertion happens because this object is a dangling pointer, make sure you've not
  54877. // deleted this menu model while it's still being used by something (e.g. by a MenuBarComponent)
  54878. jassert (listeners.contains (listenerToRemove));
  54879. listeners.removeValue (listenerToRemove);
  54880. }
  54881. void MenuBarModel::handleAsyncUpdate()
  54882. {
  54883. for (int i = listeners.size(); --i >= 0;)
  54884. {
  54885. ((MenuBarModelListener*) listeners.getUnchecked (i))->menuBarItemsChanged (this);
  54886. i = jmin (i, listeners.size());
  54887. }
  54888. }
  54889. void MenuBarModel::applicationCommandInvoked (const ApplicationCommandTarget::InvocationInfo& info)
  54890. {
  54891. for (int i = listeners.size(); --i >= 0;)
  54892. {
  54893. ((MenuBarModelListener*) listeners.getUnchecked (i))->menuCommandInvoked (this, info);
  54894. i = jmin (i, listeners.size());
  54895. }
  54896. }
  54897. void MenuBarModel::applicationCommandListChanged()
  54898. {
  54899. menuItemsChanged();
  54900. }
  54901. END_JUCE_NAMESPACE
  54902. /*** End of inlined file: juce_MenuBarModel.cpp ***/
  54903. /*** Start of inlined file: juce_PopupMenu.cpp ***/
  54904. BEGIN_JUCE_NAMESPACE
  54905. class PopupMenu::Item
  54906. {
  54907. public:
  54908. Item()
  54909. : itemId (0), active (true), isSeparator (true), isTicked (false),
  54910. usesColour (false), customComp (0), commandManager (0)
  54911. {
  54912. }
  54913. Item (const int itemId_,
  54914. const String& text_,
  54915. const bool active_,
  54916. const bool isTicked_,
  54917. const Image* im,
  54918. const Colour& textColour_,
  54919. const bool usesColour_,
  54920. PopupMenuCustomComponent* const customComp_,
  54921. const PopupMenu* const subMenu_,
  54922. ApplicationCommandManager* const commandManager_)
  54923. : itemId (itemId_), text (text_), textColour (textColour_),
  54924. active (active_), isSeparator (false), isTicked (isTicked_),
  54925. usesColour (usesColour_), customComp (customComp_),
  54926. commandManager (commandManager_)
  54927. {
  54928. if (subMenu_ != 0)
  54929. subMenu = new PopupMenu (*subMenu_);
  54930. if (im != 0)
  54931. image = im->createCopy();
  54932. if (commandManager_ != 0 && itemId_ != 0)
  54933. {
  54934. String shortcutKey;
  54935. Array <KeyPress> keyPresses (commandManager_->getKeyMappings()
  54936. ->getKeyPressesAssignedToCommand (itemId_));
  54937. for (int i = 0; i < keyPresses.size(); ++i)
  54938. {
  54939. const String key (keyPresses.getReference(i).getTextDescription());
  54940. if (shortcutKey.isNotEmpty())
  54941. shortcutKey << ", ";
  54942. if (key.length() == 1)
  54943. shortcutKey << "shortcut: '" << key << '\'';
  54944. else
  54945. shortcutKey << key;
  54946. }
  54947. shortcutKey = shortcutKey.trim();
  54948. if (shortcutKey.isNotEmpty())
  54949. text << "<end>" << shortcutKey;
  54950. }
  54951. }
  54952. Item (const Item& other)
  54953. : itemId (other.itemId),
  54954. text (other.text),
  54955. textColour (other.textColour),
  54956. active (other.active),
  54957. isSeparator (other.isSeparator),
  54958. isTicked (other.isTicked),
  54959. usesColour (other.usesColour),
  54960. customComp (other.customComp),
  54961. commandManager (other.commandManager)
  54962. {
  54963. if (other.subMenu != 0)
  54964. subMenu = new PopupMenu (*(other.subMenu));
  54965. if (other.image != 0)
  54966. image = other.image->createCopy();
  54967. }
  54968. ~Item()
  54969. {
  54970. customComp = 0;
  54971. }
  54972. bool canBeTriggered() const throw()
  54973. {
  54974. return active && ! (isSeparator || (subMenu != 0));
  54975. }
  54976. bool hasActiveSubMenu() const throw()
  54977. {
  54978. return active && (subMenu != 0);
  54979. }
  54980. const int itemId;
  54981. String text;
  54982. const Colour textColour;
  54983. const bool active, isSeparator, isTicked, usesColour;
  54984. ScopedPointer <Image> image;
  54985. ReferenceCountedObjectPtr <PopupMenuCustomComponent> customComp;
  54986. ScopedPointer <PopupMenu> subMenu;
  54987. ApplicationCommandManager* const commandManager;
  54988. juce_UseDebuggingNewOperator
  54989. private:
  54990. Item& operator= (const Item&);
  54991. };
  54992. class PopupMenu::ItemComponent : public Component
  54993. {
  54994. public:
  54995. ItemComponent (const PopupMenu::Item& itemInfo_)
  54996. : itemInfo (itemInfo_),
  54997. isHighlighted (false)
  54998. {
  54999. if (itemInfo.customComp != 0)
  55000. addAndMakeVisible (itemInfo.customComp);
  55001. }
  55002. ~ItemComponent()
  55003. {
  55004. if (itemInfo.customComp != 0)
  55005. removeChildComponent (itemInfo.customComp);
  55006. }
  55007. void getIdealSize (int& idealWidth,
  55008. int& idealHeight,
  55009. const int standardItemHeight)
  55010. {
  55011. if (itemInfo.customComp != 0)
  55012. {
  55013. itemInfo.customComp->getIdealSize (idealWidth, idealHeight);
  55014. }
  55015. else
  55016. {
  55017. getLookAndFeel().getIdealPopupMenuItemSize (itemInfo.text,
  55018. itemInfo.isSeparator,
  55019. standardItemHeight,
  55020. idealWidth,
  55021. idealHeight);
  55022. }
  55023. }
  55024. void paint (Graphics& g)
  55025. {
  55026. if (itemInfo.customComp == 0)
  55027. {
  55028. String mainText (itemInfo.text);
  55029. String endText;
  55030. const int endIndex = mainText.indexOf (T("<end>"));
  55031. if (endIndex >= 0)
  55032. {
  55033. endText = mainText.substring (endIndex + 5).trim();
  55034. mainText = mainText.substring (0, endIndex);
  55035. }
  55036. getLookAndFeel()
  55037. .drawPopupMenuItem (g, getWidth(), getHeight(),
  55038. itemInfo.isSeparator,
  55039. itemInfo.active,
  55040. isHighlighted,
  55041. itemInfo.isTicked,
  55042. itemInfo.subMenu != 0,
  55043. mainText, endText,
  55044. itemInfo.image,
  55045. itemInfo.usesColour ? &(itemInfo.textColour) : 0);
  55046. }
  55047. }
  55048. void resized()
  55049. {
  55050. if (getNumChildComponents() > 0)
  55051. getChildComponent(0)->setBounds (2, 0, getWidth() - 4, getHeight());
  55052. }
  55053. void setHighlighted (bool shouldBeHighlighted)
  55054. {
  55055. shouldBeHighlighted = shouldBeHighlighted && itemInfo.active;
  55056. if (isHighlighted != shouldBeHighlighted)
  55057. {
  55058. isHighlighted = shouldBeHighlighted;
  55059. if (itemInfo.customComp != 0)
  55060. {
  55061. itemInfo.customComp->isHighlighted = shouldBeHighlighted;
  55062. itemInfo.customComp->repaint();
  55063. }
  55064. repaint();
  55065. }
  55066. }
  55067. PopupMenu::Item itemInfo;
  55068. juce_UseDebuggingNewOperator
  55069. private:
  55070. bool isHighlighted;
  55071. ItemComponent (const ItemComponent&);
  55072. ItemComponent& operator= (const ItemComponent&);
  55073. };
  55074. namespace PopupMenuSettings
  55075. {
  55076. static const int scrollZone = 24;
  55077. static const int borderSize = 2;
  55078. static const int timerInterval = 50;
  55079. static const int dismissCommandId = 0x6287345f;
  55080. }
  55081. class PopupMenu::Window : public Component,
  55082. private Timer
  55083. {
  55084. public:
  55085. Window()
  55086. : Component (T("menu")),
  55087. owner (0),
  55088. currentChild (0),
  55089. activeSubMenu (0),
  55090. menuBarComponent (0),
  55091. managerOfChosenCommand (0),
  55092. componentAttachedTo (0),
  55093. minimumWidth (0),
  55094. maximumNumColumns (7),
  55095. standardItemHeight (0),
  55096. isOver (false),
  55097. hasBeenOver (false),
  55098. isDown (false),
  55099. needsToScroll (false),
  55100. hideOnExit (false),
  55101. disableMouseMoves (false),
  55102. hasAnyJuceCompHadFocus (false),
  55103. numColumns (0),
  55104. contentHeight (0),
  55105. childYOffset (0),
  55106. timeEnteredCurrentChildComp (0),
  55107. scrollAcceleration (1.0)
  55108. {
  55109. menuCreationTime = lastFocused = lastScroll = Time::getMillisecondCounter();
  55110. setWantsKeyboardFocus (true);
  55111. setMouseClickGrabsKeyboardFocus (false);
  55112. setOpaque (true);
  55113. setAlwaysOnTop (true);
  55114. Desktop::getInstance().addGlobalMouseListener (this);
  55115. getActiveWindows().add (this);
  55116. }
  55117. ~Window()
  55118. {
  55119. getActiveWindows().removeValue (this);
  55120. Desktop::getInstance().removeGlobalMouseListener (this);
  55121. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55122. activeSubMenu = 0;
  55123. deleteAllChildren();
  55124. attachedCompWatcher = 0;
  55125. }
  55126. static Window* create (const PopupMenu& menu,
  55127. const bool dismissOnMouseUp,
  55128. Window* const owner_,
  55129. const int minX, const int maxX,
  55130. const int minY, const int maxY,
  55131. const int minimumWidth,
  55132. const int maximumNumColumns,
  55133. const int standardItemHeight,
  55134. const bool alignToRectangle,
  55135. const int itemIdThatMustBeVisible,
  55136. Component* const menuBarComponent,
  55137. ApplicationCommandManager** managerOfChosenCommand,
  55138. Component* const componentAttachedTo)
  55139. {
  55140. if (menu.items.size() > 0)
  55141. {
  55142. int totalItems = 0;
  55143. ScopedPointer <Window> mw (new Window());
  55144. mw->setLookAndFeel (menu.lookAndFeel);
  55145. mw->setWantsKeyboardFocus (false);
  55146. mw->minimumWidth = minimumWidth;
  55147. mw->maximumNumColumns = maximumNumColumns;
  55148. mw->standardItemHeight = standardItemHeight;
  55149. mw->dismissOnMouseUp = dismissOnMouseUp;
  55150. for (int i = 0; i < menu.items.size(); ++i)
  55151. {
  55152. PopupMenu::Item* const item = menu.items.getUnchecked(i);
  55153. mw->addItem (*item);
  55154. ++totalItems;
  55155. }
  55156. if (totalItems > 0)
  55157. {
  55158. mw->owner = owner_;
  55159. mw->menuBarComponent = menuBarComponent;
  55160. mw->managerOfChosenCommand = managerOfChosenCommand;
  55161. mw->componentAttachedTo = componentAttachedTo;
  55162. mw->attachedCompWatcher = componentAttachedTo != 0 ? new ComponentDeletionWatcher (componentAttachedTo) : 0;
  55163. mw->calculateWindowPos (minX, maxX, minY, maxY, alignToRectangle);
  55164. mw->setTopLeftPosition (mw->windowPos.getX(),
  55165. mw->windowPos.getY());
  55166. mw->updateYPositions();
  55167. if (itemIdThatMustBeVisible != 0)
  55168. {
  55169. const int y = minY - mw->windowPos.getY();
  55170. mw->ensureItemIsVisible (itemIdThatMustBeVisible,
  55171. (((unsigned int) y) < (unsigned int) mw->windowPos.getHeight()) ? y : -1);
  55172. }
  55173. mw->resizeToBestWindowPos();
  55174. mw->addToDesktop (ComponentPeer::windowIsTemporary
  55175. | mw->getLookAndFeel().getMenuWindowFlags());
  55176. return mw.release();
  55177. }
  55178. }
  55179. return 0;
  55180. }
  55181. void paint (Graphics& g)
  55182. {
  55183. getLookAndFeel().drawPopupMenuBackground (g, getWidth(), getHeight());
  55184. }
  55185. void paintOverChildren (Graphics& g)
  55186. {
  55187. if (isScrolling())
  55188. {
  55189. LookAndFeel& lf = getLookAndFeel();
  55190. if (isScrollZoneActive (false))
  55191. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, true);
  55192. if (isScrollZoneActive (true))
  55193. {
  55194. g.setOrigin (0, getHeight() - PopupMenuSettings::scrollZone);
  55195. lf.drawPopupMenuUpDownArrow (g, getWidth(), PopupMenuSettings::scrollZone, false);
  55196. }
  55197. }
  55198. }
  55199. bool isScrollZoneActive (bool bottomOne) const
  55200. {
  55201. return isScrolling()
  55202. && (bottomOne
  55203. ? childYOffset < contentHeight - windowPos.getHeight()
  55204. : childYOffset > 0);
  55205. }
  55206. void addItem (const PopupMenu::Item& item)
  55207. {
  55208. PopupMenu::ItemComponent* const mic = new PopupMenu::ItemComponent (item);
  55209. addAndMakeVisible (mic);
  55210. int itemW = 80;
  55211. int itemH = 16;
  55212. mic->getIdealSize (itemW, itemH, standardItemHeight);
  55213. mic->setSize (itemW, jlimit (2, 600, itemH));
  55214. mic->addMouseListener (this, false);
  55215. }
  55216. // hide this and all sub-comps
  55217. void hide (const PopupMenu::Item* const item)
  55218. {
  55219. if (isVisible())
  55220. {
  55221. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55222. activeSubMenu = 0;
  55223. currentChild = 0;
  55224. exitModalState (item != 0 ? item->itemId : 0);
  55225. setVisible (false);
  55226. if (item != 0
  55227. && item->commandManager != 0
  55228. && item->itemId != 0)
  55229. {
  55230. *managerOfChosenCommand = item->commandManager;
  55231. }
  55232. }
  55233. }
  55234. void dismissMenu (const PopupMenu::Item* const item)
  55235. {
  55236. if (owner != 0)
  55237. {
  55238. owner->dismissMenu (item);
  55239. }
  55240. else
  55241. {
  55242. if (item != 0)
  55243. {
  55244. // need a copy of this on the stack as the one passed in will get deleted during this call
  55245. const PopupMenu::Item mi (*item);
  55246. hide (&mi);
  55247. }
  55248. else
  55249. {
  55250. hide (0);
  55251. }
  55252. }
  55253. }
  55254. void mouseMove (const MouseEvent&)
  55255. {
  55256. timerCallback();
  55257. }
  55258. void mouseDown (const MouseEvent&)
  55259. {
  55260. timerCallback();
  55261. }
  55262. void mouseDrag (const MouseEvent&)
  55263. {
  55264. timerCallback();
  55265. }
  55266. void mouseUp (const MouseEvent&)
  55267. {
  55268. timerCallback();
  55269. }
  55270. void mouseWheelMove (const MouseEvent&, float /*amountX*/, float amountY)
  55271. {
  55272. alterChildYPos (roundToInt (-10.0f * amountY * PopupMenuSettings::scrollZone));
  55273. lastMouse = Point<int> (-1, -1);
  55274. }
  55275. bool keyPressed (const KeyPress& key)
  55276. {
  55277. if (key.isKeyCode (KeyPress::downKey))
  55278. {
  55279. selectNextItem (1);
  55280. }
  55281. else if (key.isKeyCode (KeyPress::upKey))
  55282. {
  55283. selectNextItem (-1);
  55284. }
  55285. else if (key.isKeyCode (KeyPress::leftKey))
  55286. {
  55287. Window* parentWindow = owner;
  55288. if (parentWindow != 0)
  55289. {
  55290. PopupMenu::ItemComponent* currentChildOfParent
  55291. = (parentWindow != 0) ? parentWindow->currentChild : 0;
  55292. hide (0);
  55293. if (parentWindow->isValidComponent())
  55294. parentWindow->setCurrentlyHighlightedChild (currentChildOfParent);
  55295. disableTimerUntilMouseMoves();
  55296. }
  55297. else if (menuBarComponent != 0)
  55298. {
  55299. menuBarComponent->keyPressed (key);
  55300. }
  55301. }
  55302. else if (key.isKeyCode (KeyPress::rightKey))
  55303. {
  55304. disableTimerUntilMouseMoves();
  55305. if (showSubMenuFor (currentChild))
  55306. {
  55307. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55308. if (activeSubMenu != 0 && activeSubMenu->isVisible())
  55309. activeSubMenu->selectNextItem (1);
  55310. }
  55311. else if (menuBarComponent != 0)
  55312. {
  55313. menuBarComponent->keyPressed (key);
  55314. }
  55315. }
  55316. else if (key.isKeyCode (KeyPress::returnKey))
  55317. {
  55318. triggerCurrentlyHighlightedItem();
  55319. }
  55320. else if (key.isKeyCode (KeyPress::escapeKey))
  55321. {
  55322. dismissMenu (0);
  55323. }
  55324. else
  55325. {
  55326. return false;
  55327. }
  55328. return true;
  55329. }
  55330. void inputAttemptWhenModal()
  55331. {
  55332. timerCallback();
  55333. if (! isOverAnyMenu())
  55334. {
  55335. if (componentAttachedTo != 0 && ! attachedCompWatcher->hasBeenDeleted())
  55336. {
  55337. // we want to dismiss the menu, but if we do it synchronously, then
  55338. // the mouse-click will be allowed to pass through. That's good, except
  55339. // when the user clicks on the button that orginally popped the menu up,
  55340. // as they'll expect the menu to go away, and in fact it'll just
  55341. // come back. So only dismiss synchronously if they're not on the original
  55342. // comp that we're attached to.
  55343. const Point<int> mousePos (componentAttachedTo->getMouseXYRelative());
  55344. if (componentAttachedTo->reallyContains (mousePos.getX(), mousePos.getY(), true))
  55345. {
  55346. postCommandMessage (PopupMenuSettings::dismissCommandId); // dismiss asynchrounously
  55347. return;
  55348. }
  55349. }
  55350. dismissMenu (0);
  55351. }
  55352. }
  55353. void handleCommandMessage (int commandId)
  55354. {
  55355. Component::handleCommandMessage (commandId);
  55356. if (commandId == PopupMenuSettings::dismissCommandId)
  55357. dismissMenu (0);
  55358. }
  55359. void timerCallback()
  55360. {
  55361. if (! isVisible())
  55362. return;
  55363. if (attachedCompWatcher != 0 && attachedCompWatcher->hasBeenDeleted())
  55364. {
  55365. dismissMenu (0);
  55366. return;
  55367. }
  55368. Window* currentlyModalWindow = dynamic_cast <Window*> (Component::getCurrentlyModalComponent());
  55369. if (currentlyModalWindow != 0 && ! treeContains (currentlyModalWindow))
  55370. return;
  55371. startTimer (PopupMenuSettings::timerInterval); // do this in case it was called from a mouse
  55372. // move rather than a real timer callback
  55373. const Point<int> globalMousePos (Desktop::getMousePosition());
  55374. const Point<int> localMousePos (globalPositionToRelative (globalMousePos));
  55375. const uint32 now = Time::getMillisecondCounter();
  55376. if (now > timeEnteredCurrentChildComp + 100
  55377. && reallyContains (localMousePos.getX(), localMousePos.getY(), true)
  55378. && currentChild->isValidComponent()
  55379. && (! disableMouseMoves)
  55380. && ! (activeSubMenu != 0 && activeSubMenu->isVisible()))
  55381. {
  55382. showSubMenuFor (currentChild);
  55383. }
  55384. if (globalMousePos != lastMouse || now > lastMouseMoveTime + 350)
  55385. {
  55386. highlightItemUnderMouse (globalMousePos, localMousePos);
  55387. }
  55388. bool overScrollArea = false;
  55389. if (isScrolling()
  55390. && (isOver || (isDown && ((unsigned int) localMousePos.getX()) < (unsigned int) getWidth()))
  55391. && ((isScrollZoneActive (false) && localMousePos.getY() < PopupMenuSettings::scrollZone)
  55392. || (isScrollZoneActive (true) && localMousePos.getY() > getHeight() - PopupMenuSettings::scrollZone)))
  55393. {
  55394. if (now > lastScroll + 20)
  55395. {
  55396. scrollAcceleration = jmin (4.0, scrollAcceleration * 1.04);
  55397. int amount = 0;
  55398. for (int i = 0; i < getNumChildComponents() && amount == 0; ++i)
  55399. amount = ((int) scrollAcceleration) * getChildComponent (i)->getHeight();
  55400. alterChildYPos (localMousePos.getY() < PopupMenuSettings::scrollZone ? -amount : amount);
  55401. lastScroll = now;
  55402. }
  55403. overScrollArea = true;
  55404. lastMouse = Point<int> (-1, -1); // trigger a mouse-move
  55405. }
  55406. else
  55407. {
  55408. scrollAcceleration = 1.0;
  55409. }
  55410. const bool wasDown = isDown;
  55411. bool isOverAny = isOverAnyMenu();
  55412. if (hideOnExit && hasBeenOver && (! isOverAny) && activeSubMenu != 0)
  55413. {
  55414. activeSubMenu->updateMouseOverStatus (globalMousePos);
  55415. isOverAny = isOverAnyMenu();
  55416. }
  55417. if (hideOnExit && hasBeenOver && ! isOverAny)
  55418. {
  55419. hide (0);
  55420. }
  55421. else
  55422. {
  55423. isDown = hasBeenOver
  55424. && (ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown()
  55425. || ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown());
  55426. bool anyFocused = Process::isForegroundProcess();
  55427. if (anyFocused && Component::getCurrentlyFocusedComponent() == 0)
  55428. {
  55429. // because no component at all may have focus, our test here will
  55430. // only be triggered when something has focus and then loses it.
  55431. anyFocused = ! hasAnyJuceCompHadFocus;
  55432. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  55433. {
  55434. if (ComponentPeer::getPeer (i)->isFocused())
  55435. {
  55436. anyFocused = true;
  55437. hasAnyJuceCompHadFocus = true;
  55438. break;
  55439. }
  55440. }
  55441. }
  55442. if (! anyFocused)
  55443. {
  55444. if (now > lastFocused + 10)
  55445. {
  55446. wasHiddenBecauseOfAppChange() = true;
  55447. dismissMenu (0);
  55448. return; // may have been deleted by the previous call..
  55449. }
  55450. }
  55451. else if (wasDown && now > menuCreationTime + 250
  55452. && ! (isDown || overScrollArea))
  55453. {
  55454. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  55455. if (isOver)
  55456. {
  55457. triggerCurrentlyHighlightedItem();
  55458. }
  55459. else if ((hasBeenOver || ! dismissOnMouseUp) && ! isOverAny)
  55460. {
  55461. dismissMenu (0);
  55462. }
  55463. return; // may have been deleted by the previous calls..
  55464. }
  55465. else
  55466. {
  55467. lastFocused = now;
  55468. }
  55469. }
  55470. }
  55471. static Array<Window*>& getActiveWindows()
  55472. {
  55473. static Array<Window*> activeMenuWindows;
  55474. return activeMenuWindows;
  55475. }
  55476. static bool& wasHiddenBecauseOfAppChange() throw()
  55477. {
  55478. static bool b = false;
  55479. return b;
  55480. }
  55481. juce_UseDebuggingNewOperator
  55482. private:
  55483. Window* owner;
  55484. PopupMenu::ItemComponent* currentChild;
  55485. ScopedPointer <Window> activeSubMenu;
  55486. Component* menuBarComponent;
  55487. ApplicationCommandManager** managerOfChosenCommand;
  55488. Component* componentAttachedTo;
  55489. ScopedPointer <ComponentDeletionWatcher> attachedCompWatcher;
  55490. Rectangle<int> windowPos;
  55491. Point<int> lastMouse;
  55492. int minimumWidth, maximumNumColumns, standardItemHeight;
  55493. bool isOver, hasBeenOver, isDown, needsToScroll;
  55494. bool dismissOnMouseUp, hideOnExit, disableMouseMoves, hasAnyJuceCompHadFocus;
  55495. int numColumns, contentHeight, childYOffset;
  55496. Array <int> columnWidths;
  55497. uint32 menuCreationTime, lastFocused, lastScroll, lastMouseMoveTime, timeEnteredCurrentChildComp;
  55498. double scrollAcceleration;
  55499. bool overlaps (const Rectangle<int>& r) const
  55500. {
  55501. return r.intersects (getBounds())
  55502. || (owner != 0 && owner->overlaps (r));
  55503. }
  55504. bool isOverAnyMenu() const
  55505. {
  55506. return (owner != 0) ? owner->isOverAnyMenu()
  55507. : isOverChildren();
  55508. }
  55509. bool isOverChildren() const
  55510. {
  55511. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55512. return isVisible()
  55513. && (isOver || (activeSubMenu != 0 && activeSubMenu->isOverChildren()));
  55514. }
  55515. void updateMouseOverStatus (const Point<int>& globalMousePos)
  55516. {
  55517. const Point<int> relPos (globalPositionToRelative (globalMousePos));
  55518. isOver = reallyContains (relPos.getX(), relPos.getY(), true);
  55519. if (activeSubMenu != 0)
  55520. activeSubMenu->updateMouseOverStatus (globalMousePos);
  55521. }
  55522. bool treeContains (const Window* const window) const throw()
  55523. {
  55524. const Window* mw = this;
  55525. while (mw->owner != 0)
  55526. mw = mw->owner;
  55527. while (mw != 0)
  55528. {
  55529. if (mw == window)
  55530. return true;
  55531. mw = mw->activeSubMenu;
  55532. }
  55533. return false;
  55534. }
  55535. void calculateWindowPos (const int minX, const int maxX,
  55536. const int minY, const int maxY,
  55537. const bool alignToRectangle)
  55538. {
  55539. const Rectangle<int> mon (Desktop::getInstance()
  55540. .getMonitorAreaContaining (Point<int> ((minX + maxX) / 2,
  55541. (minY + maxY) / 2),
  55542. #if JUCE_MAC
  55543. true));
  55544. #else
  55545. false)); // on windows, don't stop the menu overlapping the taskbar
  55546. #endif
  55547. int x, y, widthToUse, heightToUse;
  55548. layoutMenuItems (mon.getWidth() - 24, widthToUse, heightToUse);
  55549. if (alignToRectangle)
  55550. {
  55551. x = minX;
  55552. const int spaceUnder = mon.getHeight() - (maxY - mon.getY());
  55553. const int spaceOver = minY - mon.getY();
  55554. if (heightToUse < spaceUnder - 30 || spaceUnder >= spaceOver)
  55555. y = maxY;
  55556. else
  55557. y = minY - heightToUse;
  55558. }
  55559. else
  55560. {
  55561. bool tendTowardsRight = (minX + maxX) / 2 < mon.getCentreX();
  55562. if (owner != 0)
  55563. {
  55564. if (owner->owner != 0)
  55565. {
  55566. const bool ownerGoingRight = (owner->getX() + owner->getWidth() / 2
  55567. > owner->owner->getX() + owner->owner->getWidth() / 2);
  55568. if (ownerGoingRight && maxX + widthToUse < mon.getRight() - 4)
  55569. tendTowardsRight = true;
  55570. else if ((! ownerGoingRight) && minX > widthToUse + 4)
  55571. tendTowardsRight = false;
  55572. }
  55573. else if (maxX + widthToUse < mon.getRight() - 32)
  55574. {
  55575. tendTowardsRight = true;
  55576. }
  55577. }
  55578. const int biggestSpace = jmax (mon.getRight() - maxX,
  55579. minX - mon.getX()) - 32;
  55580. if (biggestSpace < widthToUse)
  55581. {
  55582. layoutMenuItems (biggestSpace + (maxX - minX) / 3, widthToUse, heightToUse);
  55583. if (numColumns > 1)
  55584. layoutMenuItems (biggestSpace - 4, widthToUse, heightToUse);
  55585. tendTowardsRight = (mon.getRight() - maxX) >= (minX - mon.getX());
  55586. }
  55587. if (tendTowardsRight)
  55588. x = jmin (mon.getRight() - widthToUse - 4, maxX);
  55589. else
  55590. x = jmax (mon.getX() + 4, minX - widthToUse);
  55591. y = minY;
  55592. if ((minY + maxY) / 2 > mon.getCentreY())
  55593. y = jmax (mon.getY(), maxY - heightToUse);
  55594. }
  55595. x = jmax (mon.getX() + 1, jmin (mon.getRight() - (widthToUse + 6), x));
  55596. y = jmax (mon.getY() + 1, jmin (mon.getBottom() - (heightToUse + 6), y));
  55597. windowPos.setBounds (x, y, widthToUse, heightToUse);
  55598. // sets this flag if it's big enough to obscure any of its parent menus
  55599. hideOnExit = (owner != 0)
  55600. && owner->windowPos.intersects (windowPos.expanded (-4, -4));
  55601. }
  55602. void layoutMenuItems (const int maxMenuW, int& width, int& height)
  55603. {
  55604. numColumns = 0;
  55605. contentHeight = 0;
  55606. const int maxMenuH = getParentHeight() - 24;
  55607. int totalW;
  55608. do
  55609. {
  55610. ++numColumns;
  55611. totalW = workOutBestSize (maxMenuW);
  55612. if (totalW > maxMenuW)
  55613. {
  55614. numColumns = jmax (1, numColumns - 1);
  55615. totalW = workOutBestSize (maxMenuW); // to update col widths
  55616. break;
  55617. }
  55618. else if (totalW > maxMenuW / 2 || contentHeight < maxMenuH)
  55619. {
  55620. break;
  55621. }
  55622. } while (numColumns < maximumNumColumns);
  55623. const int actualH = jmin (contentHeight, maxMenuH);
  55624. needsToScroll = contentHeight > actualH;
  55625. width = updateYPositions();
  55626. height = actualH + PopupMenuSettings::borderSize * 2;
  55627. }
  55628. int workOutBestSize (const int maxMenuW)
  55629. {
  55630. int totalW = 0;
  55631. contentHeight = 0;
  55632. int childNum = 0;
  55633. for (int col = 0; col < numColumns; ++col)
  55634. {
  55635. int i, colW = 50, colH = 0;
  55636. const int numChildren = jmin (getNumChildComponents() - childNum,
  55637. (getNumChildComponents() + numColumns - 1) / numColumns);
  55638. for (i = numChildren; --i >= 0;)
  55639. {
  55640. colW = jmax (colW, getChildComponent (childNum + i)->getWidth());
  55641. colH += getChildComponent (childNum + i)->getHeight();
  55642. }
  55643. colW = jmin (maxMenuW / jmax (1, numColumns - 2), colW + PopupMenuSettings::borderSize * 2);
  55644. columnWidths.set (col, colW);
  55645. totalW += colW;
  55646. contentHeight = jmax (contentHeight, colH);
  55647. childNum += numChildren;
  55648. }
  55649. if (totalW < minimumWidth)
  55650. {
  55651. totalW = minimumWidth;
  55652. for (int col = 0; col < numColumns; ++col)
  55653. columnWidths.set (0, totalW / numColumns);
  55654. }
  55655. return totalW;
  55656. }
  55657. void ensureItemIsVisible (const int itemId, int wantedY)
  55658. {
  55659. jassert (itemId != 0)
  55660. for (int i = getNumChildComponents(); --i >= 0;)
  55661. {
  55662. PopupMenu::ItemComponent* const m = (PopupMenu::ItemComponent*) getChildComponent (i);
  55663. if (m != 0
  55664. && m->itemInfo.itemId == itemId
  55665. && windowPos.getHeight() > PopupMenuSettings::scrollZone * 4)
  55666. {
  55667. const int currentY = m->getY();
  55668. if (wantedY > 0 || currentY < 0 || m->getBottom() > windowPos.getHeight())
  55669. {
  55670. if (wantedY < 0)
  55671. wantedY = jlimit (PopupMenuSettings::scrollZone,
  55672. jmax (PopupMenuSettings::scrollZone,
  55673. windowPos.getHeight() - (PopupMenuSettings::scrollZone + m->getHeight())),
  55674. currentY);
  55675. const Rectangle<int> mon (Desktop::getInstance().getMonitorAreaContaining (windowPos.getPosition(), true));
  55676. int deltaY = wantedY - currentY;
  55677. windowPos.setSize (jmin (windowPos.getWidth(), mon.getWidth()),
  55678. jmin (windowPos.getHeight(), mon.getHeight()));
  55679. const int newY = jlimit (mon.getY(),
  55680. mon.getBottom() - windowPos.getHeight(),
  55681. windowPos.getY() + deltaY);
  55682. deltaY -= newY - windowPos.getY();
  55683. childYOffset -= deltaY;
  55684. windowPos.setPosition (windowPos.getX(), newY);
  55685. updateYPositions();
  55686. }
  55687. break;
  55688. }
  55689. }
  55690. }
  55691. void resizeToBestWindowPos()
  55692. {
  55693. Rectangle<int> r (windowPos);
  55694. if (childYOffset < 0)
  55695. {
  55696. r.setBounds (r.getX(), r.getY() - childYOffset,
  55697. r.getWidth(), r.getHeight() + childYOffset);
  55698. }
  55699. else if (childYOffset > 0)
  55700. {
  55701. const int spaceAtBottom = r.getHeight() - (contentHeight - childYOffset);
  55702. if (spaceAtBottom > 0)
  55703. r.setSize (r.getWidth(), r.getHeight() - spaceAtBottom);
  55704. }
  55705. setBounds (r);
  55706. updateYPositions();
  55707. }
  55708. void alterChildYPos (const int delta)
  55709. {
  55710. if (isScrolling())
  55711. {
  55712. childYOffset += delta;
  55713. if (delta < 0)
  55714. {
  55715. childYOffset = jmax (childYOffset, 0);
  55716. }
  55717. else if (delta > 0)
  55718. {
  55719. childYOffset = jmin (childYOffset,
  55720. contentHeight - windowPos.getHeight() + PopupMenuSettings::borderSize);
  55721. }
  55722. updateYPositions();
  55723. }
  55724. else
  55725. {
  55726. childYOffset = 0;
  55727. }
  55728. resizeToBestWindowPos();
  55729. repaint();
  55730. }
  55731. int updateYPositions()
  55732. {
  55733. int x = 0;
  55734. int childNum = 0;
  55735. for (int col = 0; col < numColumns; ++col)
  55736. {
  55737. const int numChildren = jmin (getNumChildComponents() - childNum,
  55738. (getNumChildComponents() + numColumns - 1) / numColumns);
  55739. const int colW = columnWidths [col];
  55740. int y = PopupMenuSettings::borderSize - (childYOffset + (getY() - windowPos.getY()));
  55741. for (int i = 0; i < numChildren; ++i)
  55742. {
  55743. Component* const c = getChildComponent (childNum + i);
  55744. c->setBounds (x, y, colW, c->getHeight());
  55745. y += c->getHeight();
  55746. }
  55747. x += colW;
  55748. childNum += numChildren;
  55749. }
  55750. return x;
  55751. }
  55752. bool isScrolling() const throw()
  55753. {
  55754. return childYOffset != 0 || needsToScroll;
  55755. }
  55756. void setCurrentlyHighlightedChild (PopupMenu::ItemComponent* const child)
  55757. {
  55758. if (currentChild->isValidComponent())
  55759. currentChild->setHighlighted (false);
  55760. currentChild = child;
  55761. if (currentChild != 0)
  55762. {
  55763. currentChild->setHighlighted (true);
  55764. timeEnteredCurrentChildComp = Time::getApproximateMillisecondCounter();
  55765. }
  55766. }
  55767. bool showSubMenuFor (PopupMenu::ItemComponent* const childComp)
  55768. {
  55769. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent());
  55770. activeSubMenu = 0;
  55771. if (childComp->isValidComponent() && childComp->itemInfo.hasActiveSubMenu())
  55772. {
  55773. const Point<int> topLeft (childComp->relativePositionToGlobal (Point<int>()));
  55774. const Point<int> bottomRight (childComp->relativePositionToGlobal (Point<int> (childComp->getWidth(), childComp->getHeight())));
  55775. activeSubMenu = Window::create (*(childComp->itemInfo.subMenu),
  55776. dismissOnMouseUp,
  55777. this,
  55778. topLeft.getX(), bottomRight.getX(), topLeft.getY(), bottomRight.getY(),
  55779. 0, maximumNumColumns,
  55780. standardItemHeight,
  55781. false, 0, menuBarComponent,
  55782. managerOfChosenCommand,
  55783. componentAttachedTo);
  55784. if (activeSubMenu != 0)
  55785. {
  55786. activeSubMenu->setVisible (true);
  55787. activeSubMenu->enterModalState (false);
  55788. activeSubMenu->toFront (false);
  55789. return true;
  55790. }
  55791. }
  55792. return false;
  55793. }
  55794. void highlightItemUnderMouse (const Point<int>& globalMousePos, const Point<int>& localMousePos)
  55795. {
  55796. isOver = reallyContains (localMousePos.getX(), localMousePos.getY(), true);
  55797. if (isOver)
  55798. hasBeenOver = true;
  55799. if (lastMouse.getDistanceFrom (globalMousePos) > 2)
  55800. {
  55801. lastMouseMoveTime = Time::getApproximateMillisecondCounter();
  55802. if (disableMouseMoves && isOver)
  55803. disableMouseMoves = false;
  55804. }
  55805. if (disableMouseMoves)
  55806. return;
  55807. bool isMovingTowardsMenu = false;
  55808. jassert (activeSubMenu == 0 || activeSubMenu->isValidComponent())
  55809. if (isOver && (activeSubMenu != 0) && globalMousePos != lastMouse)
  55810. {
  55811. // try to intelligently guess whether the user is moving the mouse towards a currently-open
  55812. // submenu. To do this, look at whether the mouse stays inside a triangular region that
  55813. // extends from the last mouse pos to the submenu's rectangle..
  55814. float subX = (float) activeSubMenu->getScreenX();
  55815. if (activeSubMenu->getX() > getX())
  55816. {
  55817. lastMouse -= Point<int> (2, 0); // to enlarge the triangle a bit, in case the mouse only moves a couple of pixels
  55818. }
  55819. else
  55820. {
  55821. lastMouse += Point<int> (2, 0);
  55822. subX += activeSubMenu->getWidth();
  55823. }
  55824. Path areaTowardsSubMenu;
  55825. areaTowardsSubMenu.addTriangle ((float) lastMouse.getX(),
  55826. (float) lastMouse.getY(),
  55827. subX,
  55828. (float) activeSubMenu->getScreenY(),
  55829. subX,
  55830. (float) (activeSubMenu->getScreenY() + activeSubMenu->getHeight()));
  55831. isMovingTowardsMenu = areaTowardsSubMenu.contains ((float) globalMousePos.getX(), (float) globalMousePos.getY());
  55832. }
  55833. lastMouse = globalMousePos;
  55834. if (! isMovingTowardsMenu)
  55835. {
  55836. Component* c = getComponentAt (localMousePos.getX(), localMousePos.getY());
  55837. if (c == this)
  55838. c = 0;
  55839. PopupMenu::ItemComponent* mic = dynamic_cast <PopupMenu::ItemComponent*> (c);
  55840. if (mic == 0 && c != 0)
  55841. mic = c->findParentComponentOfClass ((PopupMenu::ItemComponent*) 0);
  55842. if (mic != currentChild
  55843. && (isOver || (activeSubMenu == 0) || ! activeSubMenu->isVisible()))
  55844. {
  55845. if (isOver && (c != 0) && (activeSubMenu != 0))
  55846. {
  55847. activeSubMenu->hide (0);
  55848. }
  55849. if (! isOver)
  55850. mic = 0;
  55851. setCurrentlyHighlightedChild (mic);
  55852. }
  55853. }
  55854. }
  55855. void triggerCurrentlyHighlightedItem()
  55856. {
  55857. if (currentChild->isValidComponent()
  55858. && currentChild->itemInfo.canBeTriggered()
  55859. && (currentChild->itemInfo.customComp == 0
  55860. || currentChild->itemInfo.customComp->isTriggeredAutomatically))
  55861. {
  55862. dismissMenu (&currentChild->itemInfo);
  55863. }
  55864. }
  55865. void selectNextItem (const int delta)
  55866. {
  55867. disableTimerUntilMouseMoves();
  55868. PopupMenu::ItemComponent* mic = 0;
  55869. bool wasLastOne = (currentChild == 0);
  55870. const int numItems = getNumChildComponents();
  55871. for (int i = 0; i < numItems + 1; ++i)
  55872. {
  55873. int index = (delta > 0) ? i : (numItems - 1 - i);
  55874. index = (index + numItems) % numItems;
  55875. mic = dynamic_cast <PopupMenu::ItemComponent*> (getChildComponent (index));
  55876. if (mic != 0 && (mic->itemInfo.canBeTriggered() || mic->itemInfo.hasActiveSubMenu())
  55877. && wasLastOne)
  55878. break;
  55879. if (mic == currentChild)
  55880. wasLastOne = true;
  55881. }
  55882. setCurrentlyHighlightedChild (mic);
  55883. }
  55884. void disableTimerUntilMouseMoves()
  55885. {
  55886. disableMouseMoves = true;
  55887. if (owner != 0)
  55888. owner->disableTimerUntilMouseMoves();
  55889. }
  55890. Window (const Window&);
  55891. Window& operator= (const Window&);
  55892. };
  55893. PopupMenu::PopupMenu()
  55894. : lookAndFeel (0),
  55895. separatorPending (false)
  55896. {
  55897. }
  55898. PopupMenu::PopupMenu (const PopupMenu& other)
  55899. : lookAndFeel (other.lookAndFeel),
  55900. separatorPending (false)
  55901. {
  55902. items.ensureStorageAllocated (other.items.size());
  55903. for (int i = 0; i < other.items.size(); ++i)
  55904. items.add (new Item (*other.items.getUnchecked(i)));
  55905. }
  55906. PopupMenu& PopupMenu::operator= (const PopupMenu& other)
  55907. {
  55908. if (this != &other)
  55909. {
  55910. lookAndFeel = other.lookAndFeel;
  55911. clear();
  55912. items.ensureStorageAllocated (other.items.size());
  55913. for (int i = 0; i < other.items.size(); ++i)
  55914. items.add (new Item (*other.items.getUnchecked(i)));
  55915. }
  55916. return *this;
  55917. }
  55918. PopupMenu::~PopupMenu()
  55919. {
  55920. clear();
  55921. }
  55922. void PopupMenu::clear()
  55923. {
  55924. items.clear();
  55925. separatorPending = false;
  55926. }
  55927. void PopupMenu::addSeparatorIfPending()
  55928. {
  55929. if (separatorPending)
  55930. {
  55931. separatorPending = false;
  55932. if (items.size() > 0)
  55933. items.add (new Item());
  55934. }
  55935. }
  55936. void PopupMenu::addItem (const int itemResultId,
  55937. const String& itemText,
  55938. const bool isActive,
  55939. const bool isTicked,
  55940. const Image* const iconToUse)
  55941. {
  55942. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55943. // didn't pick anything, so you shouldn't use it as the id
  55944. // for an item..
  55945. addSeparatorIfPending();
  55946. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55947. iconToUse, Colours::black, false, 0, 0, 0));
  55948. }
  55949. void PopupMenu::addCommandItem (ApplicationCommandManager* commandManager,
  55950. const int commandID,
  55951. const String& displayName)
  55952. {
  55953. jassert (commandManager != 0 && commandID != 0);
  55954. const ApplicationCommandInfo* const registeredInfo = commandManager->getCommandForID (commandID);
  55955. if (registeredInfo != 0)
  55956. {
  55957. ApplicationCommandInfo info (*registeredInfo);
  55958. ApplicationCommandTarget* const target = commandManager->getTargetForCommand (commandID, info);
  55959. addSeparatorIfPending();
  55960. items.add (new Item (commandID,
  55961. displayName.isNotEmpty() ? displayName
  55962. : info.shortName,
  55963. target != 0 && (info.flags & ApplicationCommandInfo::isDisabled) == 0,
  55964. (info.flags & ApplicationCommandInfo::isTicked) != 0,
  55965. 0,
  55966. Colours::black,
  55967. false,
  55968. 0, 0,
  55969. commandManager));
  55970. }
  55971. }
  55972. void PopupMenu::addColouredItem (const int itemResultId,
  55973. const String& itemText,
  55974. const Colour& itemTextColour,
  55975. const bool isActive,
  55976. const bool isTicked,
  55977. const Image* const iconToUse)
  55978. {
  55979. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55980. // didn't pick anything, so you shouldn't use it as the id
  55981. // for an item..
  55982. addSeparatorIfPending();
  55983. items.add (new Item (itemResultId, itemText, isActive, isTicked,
  55984. iconToUse, itemTextColour, true, 0, 0, 0));
  55985. }
  55986. void PopupMenu::addCustomItem (const int itemResultId,
  55987. PopupMenuCustomComponent* const customComponent)
  55988. {
  55989. jassert (itemResultId != 0); // 0 is used as a return value to indicate that the user
  55990. // didn't pick anything, so you shouldn't use it as the id
  55991. // for an item..
  55992. addSeparatorIfPending();
  55993. items.add (new Item (itemResultId, String::empty, true, false, 0,
  55994. Colours::black, false, customComponent, 0, 0));
  55995. }
  55996. class NormalComponentWrapper : public PopupMenuCustomComponent
  55997. {
  55998. public:
  55999. NormalComponentWrapper (Component* const comp,
  56000. const int w, const int h,
  56001. const bool triggerMenuItemAutomaticallyWhenClicked)
  56002. : PopupMenuCustomComponent (triggerMenuItemAutomaticallyWhenClicked),
  56003. width (w),
  56004. height (h)
  56005. {
  56006. addAndMakeVisible (comp);
  56007. }
  56008. ~NormalComponentWrapper() {}
  56009. void getIdealSize (int& idealWidth, int& idealHeight)
  56010. {
  56011. idealWidth = width;
  56012. idealHeight = height;
  56013. }
  56014. void resized()
  56015. {
  56016. if (getChildComponent(0) != 0)
  56017. getChildComponent(0)->setBounds (0, 0, getWidth(), getHeight());
  56018. }
  56019. juce_UseDebuggingNewOperator
  56020. private:
  56021. const int width, height;
  56022. NormalComponentWrapper (const NormalComponentWrapper&);
  56023. NormalComponentWrapper& operator= (const NormalComponentWrapper&);
  56024. };
  56025. void PopupMenu::addCustomItem (const int itemResultId,
  56026. Component* customComponent,
  56027. int idealWidth, int idealHeight,
  56028. const bool triggerMenuItemAutomaticallyWhenClicked)
  56029. {
  56030. addCustomItem (itemResultId,
  56031. new NormalComponentWrapper (customComponent,
  56032. idealWidth, idealHeight,
  56033. triggerMenuItemAutomaticallyWhenClicked));
  56034. }
  56035. void PopupMenu::addSubMenu (const String& subMenuName,
  56036. const PopupMenu& subMenu,
  56037. const bool isActive,
  56038. Image* const iconToUse,
  56039. const bool isTicked)
  56040. {
  56041. addSeparatorIfPending();
  56042. items.add (new Item (0, subMenuName, isActive && (subMenu.getNumItems() > 0), isTicked,
  56043. iconToUse, Colours::black, false, 0, &subMenu, 0));
  56044. }
  56045. void PopupMenu::addSeparator()
  56046. {
  56047. separatorPending = true;
  56048. }
  56049. class HeaderItemComponent : public PopupMenuCustomComponent
  56050. {
  56051. public:
  56052. HeaderItemComponent (const String& name)
  56053. : PopupMenuCustomComponent (false)
  56054. {
  56055. setName (name);
  56056. }
  56057. ~HeaderItemComponent()
  56058. {
  56059. }
  56060. void paint (Graphics& g)
  56061. {
  56062. Font f (getLookAndFeel().getPopupMenuFont());
  56063. f.setBold (true);
  56064. g.setFont (f);
  56065. g.setColour (findColour (PopupMenu::headerTextColourId));
  56066. g.drawFittedText (getName(),
  56067. 12, 0, getWidth() - 16, proportionOfHeight (0.8f),
  56068. Justification::bottomLeft, 1);
  56069. }
  56070. void getIdealSize (int& idealWidth,
  56071. int& idealHeight)
  56072. {
  56073. getLookAndFeel().getIdealPopupMenuItemSize (getName(), false, -1, idealWidth, idealHeight);
  56074. idealHeight += idealHeight / 2;
  56075. idealWidth += idealWidth / 4;
  56076. }
  56077. juce_UseDebuggingNewOperator
  56078. };
  56079. void PopupMenu::addSectionHeader (const String& title)
  56080. {
  56081. addCustomItem (0X4734a34f, new HeaderItemComponent (title));
  56082. }
  56083. Component* PopupMenu::createMenuComponent (const int x, const int y, const int w, const int h,
  56084. const int itemIdThatMustBeVisible,
  56085. const int minimumWidth,
  56086. const int maximumNumColumns,
  56087. const int standardItemHeight,
  56088. const bool alignToRectangle,
  56089. Component* menuBarComponent,
  56090. ApplicationCommandManager** managerOfChosenCommand,
  56091. Component* const componentAttachedTo)
  56092. {
  56093. Window* const pw
  56094. = Window::create (*this,
  56095. ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown(),
  56096. 0,
  56097. x, x + w,
  56098. y, y + h,
  56099. minimumWidth,
  56100. maximumNumColumns,
  56101. standardItemHeight,
  56102. alignToRectangle,
  56103. itemIdThatMustBeVisible,
  56104. menuBarComponent,
  56105. managerOfChosenCommand,
  56106. componentAttachedTo);
  56107. if (pw != 0)
  56108. pw->setVisible (true);
  56109. return pw;
  56110. }
  56111. int PopupMenu::showMenu (const int x, const int y, const int w, const int h,
  56112. const int itemIdThatMustBeVisible,
  56113. const int minimumWidth,
  56114. const int maximumNumColumns,
  56115. const int standardItemHeight,
  56116. const bool alignToRectangle,
  56117. Component* const componentAttachedTo)
  56118. {
  56119. Component* const prevFocused = Component::getCurrentlyFocusedComponent();
  56120. ScopedPointer <ComponentDeletionWatcher> deletionChecker[2];
  56121. if (prevFocused != 0)
  56122. deletionChecker[0] = new ComponentDeletionWatcher (prevFocused);
  56123. Component* const prevTopLevel = (prevFocused != 0) ? prevFocused->getTopLevelComponent() : 0;
  56124. if (prevTopLevel != 0)
  56125. deletionChecker[1] = new ComponentDeletionWatcher (prevTopLevel);
  56126. Window::wasHiddenBecauseOfAppChange() = false;
  56127. int result = 0;
  56128. ApplicationCommandManager* managerOfChosenCommand = 0;
  56129. ScopedPointer <Component> popupComp (createMenuComponent (x, y, w, h,
  56130. itemIdThatMustBeVisible,
  56131. minimumWidth,
  56132. maximumNumColumns > 0 ? maximumNumColumns : 7,
  56133. standardItemHeight,
  56134. alignToRectangle, 0,
  56135. &managerOfChosenCommand,
  56136. componentAttachedTo));
  56137. if (popupComp != 0)
  56138. {
  56139. popupComp->enterModalState (false);
  56140. popupComp->toFront (false); // need to do this after making it modal, or it could
  56141. // be stuck behind other comps that are already modal..
  56142. result = popupComp->runModalLoop();
  56143. popupComp = 0;
  56144. if (! Window::wasHiddenBecauseOfAppChange())
  56145. {
  56146. if (deletionChecker[1] != 0 && ! deletionChecker[1]->hasBeenDeleted())
  56147. prevTopLevel->toFront (true);
  56148. if (deletionChecker[0] != 0 && ! deletionChecker[0]->hasBeenDeleted())
  56149. prevFocused->grabKeyboardFocus();
  56150. }
  56151. }
  56152. if (managerOfChosenCommand != 0 && result != 0)
  56153. {
  56154. ApplicationCommandTarget::InvocationInfo info (result);
  56155. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  56156. managerOfChosenCommand->invoke (info, true);
  56157. }
  56158. return result;
  56159. }
  56160. int PopupMenu::show (const int itemIdThatMustBeVisible,
  56161. const int minimumWidth,
  56162. const int maximumNumColumns,
  56163. const int standardItemHeight)
  56164. {
  56165. const Point<int> mousePos (Desktop::getMousePosition());
  56166. return showAt (mousePos.getX(), mousePos.getY(),
  56167. itemIdThatMustBeVisible,
  56168. minimumWidth,
  56169. maximumNumColumns,
  56170. standardItemHeight);
  56171. }
  56172. int PopupMenu::showAt (const int screenX,
  56173. const int screenY,
  56174. const int itemIdThatMustBeVisible,
  56175. const int minimumWidth,
  56176. const int maximumNumColumns,
  56177. const int standardItemHeight)
  56178. {
  56179. return showMenu (screenX, screenY, 1, 1,
  56180. itemIdThatMustBeVisible,
  56181. minimumWidth, maximumNumColumns,
  56182. standardItemHeight,
  56183. false, 0);
  56184. }
  56185. int PopupMenu::showAt (Component* componentToAttachTo,
  56186. const int itemIdThatMustBeVisible,
  56187. const int minimumWidth,
  56188. const int maximumNumColumns,
  56189. const int standardItemHeight)
  56190. {
  56191. if (componentToAttachTo != 0)
  56192. {
  56193. return showMenu (componentToAttachTo->getScreenX(),
  56194. componentToAttachTo->getScreenY(),
  56195. componentToAttachTo->getWidth(),
  56196. componentToAttachTo->getHeight(),
  56197. itemIdThatMustBeVisible,
  56198. minimumWidth,
  56199. maximumNumColumns,
  56200. standardItemHeight,
  56201. true, componentToAttachTo);
  56202. }
  56203. else
  56204. {
  56205. return show (itemIdThatMustBeVisible,
  56206. minimumWidth,
  56207. maximumNumColumns,
  56208. standardItemHeight);
  56209. }
  56210. }
  56211. void JUCE_CALLTYPE PopupMenu::dismissAllActiveMenus()
  56212. {
  56213. for (int i = Window::getActiveWindows().size(); --i >= 0;)
  56214. {
  56215. Window* const pmw = Window::getActiveWindows()[i];
  56216. if (pmw != 0)
  56217. pmw->dismissMenu (0);
  56218. }
  56219. }
  56220. int PopupMenu::getNumItems() const throw()
  56221. {
  56222. int num = 0;
  56223. for (int i = items.size(); --i >= 0;)
  56224. if (! (items.getUnchecked(i))->isSeparator)
  56225. ++num;
  56226. return num;
  56227. }
  56228. bool PopupMenu::containsCommandItem (const int commandID) const
  56229. {
  56230. for (int i = items.size(); --i >= 0;)
  56231. {
  56232. const Item* mi = items.getUnchecked (i);
  56233. if ((mi->itemId == commandID && mi->commandManager != 0)
  56234. || (mi->subMenu != 0 && mi->subMenu->containsCommandItem (commandID)))
  56235. {
  56236. return true;
  56237. }
  56238. }
  56239. return false;
  56240. }
  56241. bool PopupMenu::containsAnyActiveItems() const throw()
  56242. {
  56243. for (int i = items.size(); --i >= 0;)
  56244. {
  56245. const Item* const mi = items.getUnchecked (i);
  56246. if (mi->subMenu != 0)
  56247. {
  56248. if (mi->subMenu->containsAnyActiveItems())
  56249. return true;
  56250. }
  56251. else if (mi->active)
  56252. {
  56253. return true;
  56254. }
  56255. }
  56256. return false;
  56257. }
  56258. void PopupMenu::setLookAndFeel (LookAndFeel* const newLookAndFeel)
  56259. {
  56260. lookAndFeel = newLookAndFeel;
  56261. }
  56262. PopupMenuCustomComponent::PopupMenuCustomComponent (const bool isTriggeredAutomatically_)
  56263. : isHighlighted (false),
  56264. isTriggeredAutomatically (isTriggeredAutomatically_)
  56265. {
  56266. }
  56267. PopupMenuCustomComponent::~PopupMenuCustomComponent()
  56268. {
  56269. }
  56270. void PopupMenuCustomComponent::triggerMenuItem()
  56271. {
  56272. PopupMenu::ItemComponent* const mic = dynamic_cast <PopupMenu::ItemComponent*> (getParentComponent());
  56273. if (mic != 0)
  56274. {
  56275. PopupMenu::Window* const pmw = dynamic_cast <PopupMenu::Window*> (mic->getParentComponent());
  56276. if (pmw != 0)
  56277. {
  56278. pmw->dismissMenu (&mic->itemInfo);
  56279. }
  56280. else
  56281. {
  56282. // something must have gone wrong with the component hierarchy if this happens..
  56283. jassertfalse
  56284. }
  56285. }
  56286. else
  56287. {
  56288. // why isn't this component inside a menu? Not much point triggering the item if
  56289. // there's no menu.
  56290. jassertfalse
  56291. }
  56292. }
  56293. PopupMenu::MenuItemIterator::MenuItemIterator (const PopupMenu& menu_)
  56294. : subMenu (0),
  56295. itemId (0),
  56296. isSeparator (false),
  56297. isTicked (false),
  56298. isEnabled (false),
  56299. isCustomComponent (false),
  56300. isSectionHeader (false),
  56301. customColour (0),
  56302. customImage (0),
  56303. menu (menu_),
  56304. index (0)
  56305. {
  56306. }
  56307. PopupMenu::MenuItemIterator::~MenuItemIterator()
  56308. {
  56309. }
  56310. bool PopupMenu::MenuItemIterator::next()
  56311. {
  56312. if (index >= menu.items.size())
  56313. return false;
  56314. const Item* const item = menu.items.getUnchecked (index);
  56315. ++index;
  56316. itemName = item->customComp != 0 ? item->customComp->getName() : item->text;
  56317. subMenu = item->subMenu;
  56318. itemId = item->itemId;
  56319. isSeparator = item->isSeparator;
  56320. isTicked = item->isTicked;
  56321. isEnabled = item->active;
  56322. isSectionHeader = dynamic_cast <HeaderItemComponent*> ((PopupMenuCustomComponent*) item->customComp) != 0;
  56323. isCustomComponent = (! isSectionHeader) && item->customComp != 0;
  56324. customColour = item->usesColour ? &(item->textColour) : 0;
  56325. customImage = item->image;
  56326. commandManager = item->commandManager;
  56327. return true;
  56328. }
  56329. END_JUCE_NAMESPACE
  56330. /*** End of inlined file: juce_PopupMenu.cpp ***/
  56331. /*** Start of inlined file: juce_ComponentDragger.cpp ***/
  56332. BEGIN_JUCE_NAMESPACE
  56333. ComponentDragger::ComponentDragger()
  56334. : constrainer (0)
  56335. {
  56336. }
  56337. ComponentDragger::~ComponentDragger()
  56338. {
  56339. }
  56340. void ComponentDragger::startDraggingComponent (Component* const componentToDrag,
  56341. ComponentBoundsConstrainer* const constrainer_)
  56342. {
  56343. jassert (componentToDrag->isValidComponent());
  56344. if (componentToDrag->isValidComponent())
  56345. {
  56346. constrainer = constrainer_;
  56347. originalPos = componentToDrag->relativePositionToGlobal (Point<int>());
  56348. }
  56349. }
  56350. void ComponentDragger::dragComponent (Component* const componentToDrag, const MouseEvent& e)
  56351. {
  56352. jassert (componentToDrag->isValidComponent());
  56353. jassert (e.mods.isAnyMouseButtonDown()); // (the event has to be a drag event..)
  56354. if (componentToDrag->isValidComponent())
  56355. {
  56356. Point<int> pos (originalPos);
  56357. int w = componentToDrag->getWidth();
  56358. int h = componentToDrag->getHeight();
  56359. const Component* const parentComp = componentToDrag->getParentComponent();
  56360. if (parentComp != 0)
  56361. pos = parentComp->globalPositionToRelative (pos);
  56362. pos += Point<int> (e.getDistanceFromDragStartX(),
  56363. e.getDistanceFromDragStartY());
  56364. if (constrainer != 0)
  56365. constrainer->setBoundsForComponent (componentToDrag, Rectangle<int> (pos.getX(), pos.getY(), w, h),
  56366. false, false, false, false);
  56367. else
  56368. componentToDrag->setBounds (pos.getX(), pos.getY(), w, h);
  56369. }
  56370. }
  56371. END_JUCE_NAMESPACE
  56372. /*** End of inlined file: juce_ComponentDragger.cpp ***/
  56373. /*** Start of inlined file: juce_DragAndDropContainer.cpp ***/
  56374. BEGIN_JUCE_NAMESPACE
  56375. bool juce_performDragDropFiles (const StringArray& files, const bool copyFiles, bool& shouldStop);
  56376. bool juce_performDragDropText (const String& text, bool& shouldStop);
  56377. class DragImageComponent : public Component,
  56378. public Timer
  56379. {
  56380. public:
  56381. DragImageComponent (Image* const im,
  56382. const String& desc,
  56383. Component* const s,
  56384. DragAndDropContainer* const o,
  56385. const Point<int>& imageOffset_)
  56386. : image (im),
  56387. source (s),
  56388. owner (o),
  56389. currentlyOver (0),
  56390. dragDesc (desc),
  56391. imageOffset (imageOffset_),
  56392. hasCheckedForExternalDrag (false),
  56393. drawImage (true)
  56394. {
  56395. setSize (im->getWidth(), im->getHeight());
  56396. sourceWatcher = new ComponentDeletionWatcher (source);
  56397. mouseDragSource = Component::getComponentUnderMouse();
  56398. if (mouseDragSource == 0)
  56399. mouseDragSource = source;
  56400. mouseDragSourceWatcher = new ComponentDeletionWatcher (mouseDragSource);
  56401. mouseDragSource->addMouseListener (this, false);
  56402. startTimer (200);
  56403. setInterceptsMouseClicks (false, false);
  56404. setAlwaysOnTop (true);
  56405. }
  56406. ~DragImageComponent()
  56407. {
  56408. if ((DragImageComponent*) owner->dragImageComponent == this)
  56409. owner->dragImageComponent.release();
  56410. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56411. {
  56412. mouseDragSource->removeMouseListener (this);
  56413. if (currentlyOverWatcher != 0 && ! currentlyOverWatcher->hasBeenDeleted())
  56414. if (currentlyOver->isInterestedInDragSource (dragDesc, source))
  56415. currentlyOver->itemDragExit (dragDesc, source);
  56416. }
  56417. }
  56418. void paint (Graphics& g)
  56419. {
  56420. if (isOpaque())
  56421. g.fillAll (Colours::white);
  56422. if (drawImage)
  56423. {
  56424. g.setOpacity (1.0f);
  56425. g.drawImageAt (image, 0, 0);
  56426. }
  56427. }
  56428. DragAndDropTarget* findTarget (const Point<int>& screenPos,
  56429. Point<int>& relativePos) const
  56430. {
  56431. Component* hit = getParentComponent();
  56432. if (hit == 0)
  56433. {
  56434. hit = Desktop::getInstance().findComponentAt (screenPos);
  56435. }
  56436. else
  56437. {
  56438. const Point<int> relPos (hit->globalPositionToRelative (screenPos));
  56439. hit = hit->getComponentAt (relPos.getX(), relPos.getY());
  56440. }
  56441. // (note: use a local copy of the dragDesc member in case the callback runs
  56442. // a modal loop and deletes this object before the method completes)
  56443. const String dragDescLocal (dragDesc);
  56444. while (hit != 0)
  56445. {
  56446. DragAndDropTarget* const ddt = dynamic_cast <DragAndDropTarget*> (hit);
  56447. if (ddt != 0 && ddt->isInterestedInDragSource (dragDescLocal, source))
  56448. {
  56449. relativePos = hit->globalPositionToRelative (screenPos);
  56450. return ddt;
  56451. }
  56452. hit = hit->getParentComponent();
  56453. }
  56454. return 0;
  56455. }
  56456. void mouseUp (const MouseEvent& e)
  56457. {
  56458. if (e.originalComponent != this)
  56459. {
  56460. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56461. mouseDragSource->removeMouseListener (this);
  56462. bool dropAccepted = false;
  56463. DragAndDropTarget* ddt = 0;
  56464. Point<int> relPos;
  56465. if (isVisible())
  56466. {
  56467. setVisible (false);
  56468. ddt = findTarget (e.getScreenPosition(), relPos);
  56469. // fade this component and remove it - it'll be deleted later by the timer callback
  56470. dropAccepted = ddt != 0;
  56471. setVisible (true);
  56472. if (dropAccepted || sourceWatcher->hasBeenDeleted())
  56473. {
  56474. fadeOutComponent (120);
  56475. }
  56476. else
  56477. {
  56478. const Point<int> target (source->relativePositionToGlobal (Point<int> (source->getWidth() / 2,
  56479. source->getHeight() / 2)));
  56480. const Point<int> ourCentre (relativePositionToGlobal (Point<int> (getWidth() / 2,
  56481. getHeight() / 2)));
  56482. fadeOutComponent (120,
  56483. target.getX() - ourCentre.getX(),
  56484. target.getY() - ourCentre.getY());
  56485. }
  56486. }
  56487. if (getParentComponent() != 0)
  56488. getParentComponent()->removeChildComponent (this);
  56489. if (dropAccepted && ddt != 0)
  56490. {
  56491. // (note: use a local copy of the dragDesc member in case the callback runs
  56492. // a modal loop and deletes this object before the method completes)
  56493. const String dragDescLocal (dragDesc);
  56494. currentlyOverWatcher = 0;
  56495. currentlyOver = 0;
  56496. ddt->itemDropped (dragDescLocal, source, relPos.getX(), relPos.getY());
  56497. }
  56498. // careful - this object could now be deleted..
  56499. }
  56500. }
  56501. void updateLocation (const bool canDoExternalDrag, const Point<int>& screenPos)
  56502. {
  56503. // (note: use a local copy of the dragDesc member in case the callback runs
  56504. // a modal loop and deletes this object before it returns)
  56505. const String dragDescLocal (dragDesc);
  56506. Point<int> newPos (screenPos + imageOffset);
  56507. if (getParentComponent() != 0)
  56508. newPos = getParentComponent()->globalPositionToRelative (newPos);
  56509. //if (newX != getX() || newY != getY())
  56510. {
  56511. setTopLeftPosition (newPos.getX(), newPos.getY());
  56512. Point<int> relPos;
  56513. DragAndDropTarget* const ddt = findTarget (screenPos, relPos);
  56514. drawImage = (ddt == 0) || ddt->shouldDrawDragImageWhenOver();
  56515. if (ddt != currentlyOver)
  56516. {
  56517. if (currentlyOverWatcher != 0 && ! currentlyOverWatcher->hasBeenDeleted())
  56518. {
  56519. Component* const over = dynamic_cast <Component*> (currentlyOver);
  56520. if (over != 0
  56521. && over->isValidComponent()
  56522. && ! (sourceWatcher->hasBeenDeleted())
  56523. && currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56524. {
  56525. currentlyOver->itemDragExit (dragDescLocal, source);
  56526. }
  56527. }
  56528. currentlyOver = ddt;
  56529. currentlyOverWatcher = 0;
  56530. if (ddt != 0)
  56531. {
  56532. currentlyOverWatcher = new ComponentDeletionWatcher (dynamic_cast <Component*> (ddt));
  56533. if (currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56534. currentlyOver->itemDragEnter (dragDescLocal, source, relPos.getX(), relPos.getY());
  56535. }
  56536. }
  56537. else if (currentlyOverWatcher != 0 && currentlyOverWatcher->hasBeenDeleted())
  56538. {
  56539. currentlyOver = 0;
  56540. currentlyOverWatcher = 0;
  56541. }
  56542. if (currentlyOver != 0
  56543. && currentlyOver->isInterestedInDragSource (dragDescLocal, source))
  56544. currentlyOver->itemDragMove (dragDescLocal, source, relPos.getX(), relPos.getY());
  56545. if (currentlyOver == 0
  56546. && canDoExternalDrag
  56547. && ! hasCheckedForExternalDrag)
  56548. {
  56549. if (Desktop::getInstance().findComponentAt (screenPos) == 0)
  56550. {
  56551. hasCheckedForExternalDrag = true;
  56552. StringArray files;
  56553. bool canMoveFiles = false;
  56554. if (owner->shouldDropFilesWhenDraggedExternally (dragDescLocal, source, files, canMoveFiles)
  56555. && files.size() > 0)
  56556. {
  56557. ComponentDeletionWatcher cdw (this);
  56558. setVisible (false);
  56559. if (ModifierKeys::getCurrentModifiersRealtime().isAnyMouseButtonDown())
  56560. DragAndDropContainer::performExternalDragDropOfFiles (files, canMoveFiles);
  56561. if (! cdw.hasBeenDeleted())
  56562. delete this;
  56563. return;
  56564. }
  56565. }
  56566. }
  56567. }
  56568. }
  56569. void mouseDrag (const MouseEvent& e)
  56570. {
  56571. if (e.originalComponent != this)
  56572. updateLocation (true, e.getScreenPosition());
  56573. }
  56574. void timerCallback()
  56575. {
  56576. if (sourceWatcher->hasBeenDeleted())
  56577. {
  56578. delete this;
  56579. }
  56580. else if (! isMouseButtonDownAnywhere())
  56581. {
  56582. if (! mouseDragSourceWatcher->hasBeenDeleted())
  56583. mouseDragSource->removeMouseListener (this);
  56584. delete this;
  56585. }
  56586. }
  56587. private:
  56588. ScopedPointer<Image> image;
  56589. Component* const source;
  56590. DragAndDropContainer* const owner;
  56591. ScopedPointer<ComponentDeletionWatcher> sourceWatcher, mouseDragSourceWatcher, currentlyOverWatcher;
  56592. Component* mouseDragSource;
  56593. DragAndDropTarget* currentlyOver;
  56594. String dragDesc;
  56595. const Point<int> imageOffset;
  56596. bool hasCheckedForExternalDrag, drawImage;
  56597. DragImageComponent (const DragImageComponent&);
  56598. DragImageComponent& operator= (const DragImageComponent&);
  56599. };
  56600. DragAndDropContainer::DragAndDropContainer()
  56601. {
  56602. }
  56603. DragAndDropContainer::~DragAndDropContainer()
  56604. {
  56605. dragImageComponent = 0;
  56606. }
  56607. void DragAndDropContainer::startDragging (const String& sourceDescription,
  56608. Component* sourceComponent,
  56609. Image* dragImage_,
  56610. const bool allowDraggingToExternalWindows,
  56611. const Point<int>* imageOffsetFromMouse)
  56612. {
  56613. ScopedPointer <Image> dragImage (dragImage_);
  56614. if (dragImageComponent == 0)
  56615. {
  56616. Component* const thisComp = dynamic_cast <Component*> (this);
  56617. if (thisComp != 0)
  56618. {
  56619. const Point<int> lastMouseDown (Desktop::getLastMouseDownPosition());
  56620. Point<int> imageOffset;
  56621. if (dragImage == 0)
  56622. {
  56623. dragImage = sourceComponent->createComponentSnapshot (Rectangle<int> (0, 0, sourceComponent->getWidth(), sourceComponent->getHeight()));
  56624. if (dragImage->getFormat() != Image::ARGB)
  56625. {
  56626. Image* newIm = Image::createNativeImage (Image::ARGB, dragImage->getWidth(), dragImage->getHeight(), true);
  56627. Graphics g2 (*newIm);
  56628. g2.drawImageAt (dragImage, 0, 0);
  56629. dragImage = newIm;
  56630. }
  56631. dragImage->multiplyAllAlphas (0.6f);
  56632. const int lo = 150;
  56633. const int hi = 400;
  56634. Point<int> relPos (sourceComponent->globalPositionToRelative (lastMouseDown));
  56635. Point<int> clipped (Rectangle<int> (0, 0, dragImage->getWidth(), dragImage->getHeight())
  56636. .getConstrainedPoint (relPos));
  56637. for (int y = dragImage->getHeight(); --y >= 0;)
  56638. {
  56639. const double dy = (y - clipped.getY()) * (y - clipped.getY());
  56640. for (int x = dragImage->getWidth(); --x >= 0;)
  56641. {
  56642. const int dx = x - clipped.getX();
  56643. const int distance = roundToInt (sqrt (dx * dx + dy));
  56644. if (distance > lo)
  56645. {
  56646. const float alpha = (distance > hi) ? 0
  56647. : (hi - distance) / (float) (hi - lo)
  56648. + Random::getSystemRandom().nextFloat() * 0.008f;
  56649. dragImage->multiplyAlphaAt (x, y, alpha);
  56650. }
  56651. }
  56652. }
  56653. imageOffset = -clipped;
  56654. }
  56655. else
  56656. {
  56657. if (imageOffsetFromMouse == 0)
  56658. imageOffset = Point<int> (dragImage->getWidth() / -2,
  56659. dragImage->getHeight() / -2);
  56660. else
  56661. imageOffset = *imageOffsetFromMouse;
  56662. }
  56663. dragImageComponent = new DragImageComponent (dragImage.release(), sourceDescription, sourceComponent,
  56664. this, imageOffset);
  56665. currentDragDesc = sourceDescription;
  56666. if (allowDraggingToExternalWindows)
  56667. {
  56668. if (! Desktop::canUseSemiTransparentWindows())
  56669. dragImageComponent->setOpaque (true);
  56670. dragImageComponent->addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  56671. | ComponentPeer::windowIsTemporary
  56672. | ComponentPeer::windowIgnoresKeyPresses);
  56673. }
  56674. else
  56675. thisComp->addChildComponent (dragImageComponent);
  56676. ((DragImageComponent*) dragImageComponent)->updateLocation (false, lastMouseDown);
  56677. dragImageComponent->setVisible (true);
  56678. }
  56679. else
  56680. {
  56681. // this class must only be implemented by an object that
  56682. // is also a Component.
  56683. jassertfalse
  56684. }
  56685. }
  56686. }
  56687. bool DragAndDropContainer::isDragAndDropActive() const
  56688. {
  56689. return dragImageComponent != 0;
  56690. }
  56691. const String DragAndDropContainer::getCurrentDragDescription() const
  56692. {
  56693. return (dragImageComponent != 0) ? currentDragDesc
  56694. : String::empty;
  56695. }
  56696. DragAndDropContainer* DragAndDropContainer::findParentDragContainerFor (Component* c)
  56697. {
  56698. if (c == 0)
  56699. return 0;
  56700. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  56701. return c->findParentComponentOfClass ((DragAndDropContainer*) 0);
  56702. }
  56703. bool DragAndDropContainer::shouldDropFilesWhenDraggedExternally (const String&, Component*, StringArray&, bool&)
  56704. {
  56705. return false;
  56706. }
  56707. void DragAndDropTarget::itemDragEnter (const String&, Component*, int, int)
  56708. {
  56709. }
  56710. void DragAndDropTarget::itemDragMove (const String&, Component*, int, int)
  56711. {
  56712. }
  56713. void DragAndDropTarget::itemDragExit (const String&, Component*)
  56714. {
  56715. }
  56716. bool DragAndDropTarget::shouldDrawDragImageWhenOver()
  56717. {
  56718. return true;
  56719. }
  56720. void FileDragAndDropTarget::fileDragEnter (const StringArray&, int, int)
  56721. {
  56722. }
  56723. void FileDragAndDropTarget::fileDragMove (const StringArray&, int, int)
  56724. {
  56725. }
  56726. void FileDragAndDropTarget::fileDragExit (const StringArray&)
  56727. {
  56728. }
  56729. END_JUCE_NAMESPACE
  56730. /*** End of inlined file: juce_DragAndDropContainer.cpp ***/
  56731. /*** Start of inlined file: juce_MouseCursor.cpp ***/
  56732. BEGIN_JUCE_NAMESPACE
  56733. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw();
  56734. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw();
  56735. // isStandard set depending on which interface was used to create the cursor
  56736. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw();
  56737. static CriticalSection activeCursorListLock;
  56738. static VoidArray activeCursors;
  56739. class SharedMouseCursorInternal : public ReferenceCountedObject
  56740. {
  56741. public:
  56742. SharedMouseCursorInternal (const MouseCursor::StandardCursorType type) throw()
  56743. : standardType (type),
  56744. isStandard (true)
  56745. {
  56746. handle = juce_createStandardMouseCursor (standardType);
  56747. activeCursors.add (this);
  56748. }
  56749. SharedMouseCursorInternal (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56750. : standardType (MouseCursor::NormalCursor),
  56751. isStandard (false)
  56752. {
  56753. handle = juce_createMouseCursorFromImage (image, hotSpotX, hotSpotY);
  56754. }
  56755. ~SharedMouseCursorInternal() throw()
  56756. {
  56757. juce_deleteMouseCursor (handle, isStandard);
  56758. activeCursors.removeValue (this);
  56759. }
  56760. void* getHandle() const throw()
  56761. {
  56762. return handle;
  56763. }
  56764. static SharedMouseCursorInternal* findInstance (MouseCursor::StandardCursorType type) throw()
  56765. {
  56766. for (int i = activeCursors.size(); --i >= 0;)
  56767. {
  56768. SharedMouseCursorInternal* const r = (SharedMouseCursorInternal*) activeCursors.getUnchecked(i);
  56769. if (r->standardType == type)
  56770. return r;
  56771. }
  56772. return new SharedMouseCursorInternal (type);
  56773. }
  56774. juce_UseDebuggingNewOperator
  56775. private:
  56776. void* handle;
  56777. const MouseCursor::StandardCursorType standardType;
  56778. const bool isStandard;
  56779. SharedMouseCursorInternal& operator= (const SharedMouseCursorInternal&);
  56780. };
  56781. MouseCursor::MouseCursor() throw()
  56782. {
  56783. const ScopedLock sl (activeCursorListLock);
  56784. cursorHandle = SharedMouseCursorInternal::findInstance (NormalCursor);
  56785. }
  56786. MouseCursor::MouseCursor (const StandardCursorType type) throw()
  56787. {
  56788. const ScopedLock sl (activeCursorListLock);
  56789. cursorHandle = SharedMouseCursorInternal::findInstance (type);
  56790. }
  56791. MouseCursor::MouseCursor (const Image& image, const int hotSpotX, const int hotSpotY) throw()
  56792. {
  56793. const ScopedLock sl (activeCursorListLock);
  56794. cursorHandle = new SharedMouseCursorInternal (image, hotSpotX, hotSpotY);
  56795. }
  56796. MouseCursor::MouseCursor (const MouseCursor& other) throw()
  56797. : cursorHandle (other.cursorHandle)
  56798. {
  56799. }
  56800. MouseCursor::~MouseCursor() throw()
  56801. {
  56802. }
  56803. MouseCursor& MouseCursor::operator= (const MouseCursor& other) throw()
  56804. {
  56805. cursorHandle = other.cursorHandle;
  56806. return *this;
  56807. }
  56808. bool MouseCursor::operator== (const MouseCursor& other) const throw()
  56809. {
  56810. return cursorHandle == other.cursorHandle;
  56811. }
  56812. bool MouseCursor::operator!= (const MouseCursor& other) const throw()
  56813. {
  56814. return cursorHandle != other.cursorHandle;
  56815. }
  56816. void* MouseCursor::getHandle() const throw()
  56817. {
  56818. return cursorHandle->getHandle();
  56819. }
  56820. void MouseCursor::showWaitCursor() throw()
  56821. {
  56822. const MouseCursor mc (MouseCursor::WaitCursor);
  56823. mc.showInAllWindows();
  56824. }
  56825. void MouseCursor::hideWaitCursor() throw()
  56826. {
  56827. Component* const c = Component::getComponentUnderMouse();
  56828. MouseCursor mc (c->isValidComponent() ? c->getLookAndFeel().getMouseCursorFor (*c)
  56829. : MouseCursor::NormalCursor);
  56830. mc.showInAllWindows();
  56831. }
  56832. END_JUCE_NAMESPACE
  56833. /*** End of inlined file: juce_MouseCursor.cpp ***/
  56834. /*** Start of inlined file: juce_MouseEvent.cpp ***/
  56835. BEGIN_JUCE_NAMESPACE
  56836. MouseEvent::MouseEvent (const Point<int>& position,
  56837. const ModifierKeys& mods_,
  56838. Component* const originator,
  56839. const Time& eventTime_,
  56840. const Point<int> mouseDownPos_,
  56841. const Time& mouseDownTime_,
  56842. const int numberOfClicks_,
  56843. const bool mouseWasDragged) throw()
  56844. : x (position.getX()),
  56845. y (position.getY()),
  56846. mods (mods_),
  56847. eventComponent (originator),
  56848. originalComponent (originator),
  56849. eventTime (eventTime_),
  56850. mouseDownPos (mouseDownPos_),
  56851. mouseDownTime (mouseDownTime_),
  56852. numberOfClicks (numberOfClicks_),
  56853. wasMovedSinceMouseDown (mouseWasDragged)
  56854. {
  56855. }
  56856. MouseEvent::~MouseEvent() throw()
  56857. {
  56858. }
  56859. bool MouseEvent::mouseWasClicked() const throw()
  56860. {
  56861. return ! wasMovedSinceMouseDown;
  56862. }
  56863. int MouseEvent::getMouseDownX() const throw()
  56864. {
  56865. return mouseDownPos.getX();
  56866. }
  56867. int MouseEvent::getMouseDownY() const throw()
  56868. {
  56869. return mouseDownPos.getY();
  56870. }
  56871. const Point<int> MouseEvent::getMouseDownPosition() const throw()
  56872. {
  56873. return mouseDownPos;
  56874. }
  56875. int MouseEvent::getDistanceFromDragStartX() const throw()
  56876. {
  56877. return x - mouseDownPos.getX();
  56878. }
  56879. int MouseEvent::getDistanceFromDragStartY() const throw()
  56880. {
  56881. return y - mouseDownPos.getY();
  56882. }
  56883. int MouseEvent::getDistanceFromDragStart() const throw()
  56884. {
  56885. return roundToInt (juce_hypot (getDistanceFromDragStartX(),
  56886. getDistanceFromDragStartY()));
  56887. }
  56888. int MouseEvent::getLengthOfMousePress() const throw()
  56889. {
  56890. if (mouseDownTime.toMilliseconds() > 0)
  56891. return jmax (0, (int) (eventTime - mouseDownTime).inMilliseconds());
  56892. return 0;
  56893. }
  56894. const Point<int> MouseEvent::getPosition() const throw()
  56895. {
  56896. return Point<int> (x, y);
  56897. }
  56898. int MouseEvent::getScreenX() const
  56899. {
  56900. return getScreenPosition().getX();
  56901. }
  56902. int MouseEvent::getScreenY() const
  56903. {
  56904. return getScreenPosition().getY();
  56905. }
  56906. const Point<int> MouseEvent::getScreenPosition() const
  56907. {
  56908. return eventComponent->relativePositionToGlobal (Point<int> (x, y));
  56909. }
  56910. int MouseEvent::getMouseDownScreenX() const
  56911. {
  56912. return getMouseDownScreenPosition().getX();
  56913. }
  56914. int MouseEvent::getMouseDownScreenY() const
  56915. {
  56916. return getMouseDownScreenPosition().getY();
  56917. }
  56918. const Point<int> MouseEvent::getMouseDownScreenPosition() const
  56919. {
  56920. return eventComponent->relativePositionToGlobal (mouseDownPos);
  56921. }
  56922. const MouseEvent MouseEvent::getEventRelativeTo (Component* const otherComponent) const throw()
  56923. {
  56924. if (otherComponent == 0)
  56925. {
  56926. jassertfalse
  56927. return *this;
  56928. }
  56929. return MouseEvent (eventComponent->relativePositionToOtherComponent (otherComponent, Point<int> (x, y)),
  56930. mods,
  56931. originalComponent,
  56932. eventTime,
  56933. eventComponent->relativePositionToOtherComponent (otherComponent, mouseDownPos),
  56934. mouseDownTime,
  56935. numberOfClicks,
  56936. wasMovedSinceMouseDown);
  56937. }
  56938. static int doubleClickTimeOutMs = 400;
  56939. void MouseEvent::setDoubleClickTimeout (const int newTime) throw()
  56940. {
  56941. doubleClickTimeOutMs = newTime;
  56942. }
  56943. int MouseEvent::getDoubleClickTimeout() throw()
  56944. {
  56945. return doubleClickTimeOutMs;
  56946. }
  56947. END_JUCE_NAMESPACE
  56948. /*** End of inlined file: juce_MouseEvent.cpp ***/
  56949. /*** Start of inlined file: juce_MouseHoverDetector.cpp ***/
  56950. BEGIN_JUCE_NAMESPACE
  56951. MouseHoverDetector::MouseHoverDetector (const int hoverTimeMillisecs_)
  56952. : source (0),
  56953. hoverTimeMillisecs (hoverTimeMillisecs_),
  56954. hasJustHovered (false)
  56955. {
  56956. internalTimer.owner = this;
  56957. }
  56958. MouseHoverDetector::~MouseHoverDetector()
  56959. {
  56960. setHoverComponent (0);
  56961. }
  56962. void MouseHoverDetector::setHoverTimeMillisecs (const int newTimeInMillisecs)
  56963. {
  56964. hoverTimeMillisecs = newTimeInMillisecs;
  56965. }
  56966. void MouseHoverDetector::setHoverComponent (Component* const newSourceComponent)
  56967. {
  56968. if (source != newSourceComponent)
  56969. {
  56970. internalTimer.stopTimer();
  56971. hasJustHovered = false;
  56972. if (source != 0)
  56973. {
  56974. // ! you need to delete the hover detector before deleting its component
  56975. jassert (source->isValidComponent());
  56976. source->removeMouseListener (&internalTimer);
  56977. }
  56978. source = newSourceComponent;
  56979. if (newSourceComponent != 0)
  56980. newSourceComponent->addMouseListener (&internalTimer, false);
  56981. }
  56982. }
  56983. void MouseHoverDetector::hoverTimerCallback()
  56984. {
  56985. internalTimer.stopTimer();
  56986. if (source != 0)
  56987. {
  56988. const Point<int> pos (source->getMouseXYRelative());
  56989. if (source->reallyContains (pos.getX(), pos.getY(), false))
  56990. {
  56991. hasJustHovered = true;
  56992. mouseHovered (pos.getX(), pos.getY());
  56993. }
  56994. }
  56995. }
  56996. void MouseHoverDetector::checkJustHoveredCallback()
  56997. {
  56998. if (hasJustHovered)
  56999. {
  57000. hasJustHovered = false;
  57001. mouseMovedAfterHover();
  57002. }
  57003. }
  57004. void MouseHoverDetector::HoverDetectorInternal::timerCallback()
  57005. {
  57006. owner->hoverTimerCallback();
  57007. }
  57008. void MouseHoverDetector::HoverDetectorInternal::mouseEnter (const MouseEvent&)
  57009. {
  57010. stopTimer();
  57011. owner->checkJustHoveredCallback();
  57012. }
  57013. void MouseHoverDetector::HoverDetectorInternal::mouseExit (const MouseEvent&)
  57014. {
  57015. stopTimer();
  57016. owner->checkJustHoveredCallback();
  57017. }
  57018. void MouseHoverDetector::HoverDetectorInternal::mouseDown (const MouseEvent&)
  57019. {
  57020. stopTimer();
  57021. owner->checkJustHoveredCallback();
  57022. }
  57023. void MouseHoverDetector::HoverDetectorInternal::mouseUp (const MouseEvent&)
  57024. {
  57025. stopTimer();
  57026. owner->checkJustHoveredCallback();
  57027. }
  57028. void MouseHoverDetector::HoverDetectorInternal::mouseMove (const MouseEvent& e)
  57029. {
  57030. if (lastX != e.x || lastY != e.y) // to avoid fake mouse-moves setting it off
  57031. {
  57032. lastX = e.x;
  57033. lastY = e.y;
  57034. if (owner->source != 0)
  57035. startTimer (owner->hoverTimeMillisecs);
  57036. owner->checkJustHoveredCallback();
  57037. }
  57038. }
  57039. void MouseHoverDetector::HoverDetectorInternal::mouseWheelMove (const MouseEvent&, float, float)
  57040. {
  57041. stopTimer();
  57042. owner->checkJustHoveredCallback();
  57043. }
  57044. END_JUCE_NAMESPACE
  57045. /*** End of inlined file: juce_MouseHoverDetector.cpp ***/
  57046. /*** Start of inlined file: juce_MouseListener.cpp ***/
  57047. BEGIN_JUCE_NAMESPACE
  57048. void MouseListener::mouseEnter (const MouseEvent&)
  57049. {
  57050. }
  57051. void MouseListener::mouseExit (const MouseEvent&)
  57052. {
  57053. }
  57054. void MouseListener::mouseDown (const MouseEvent&)
  57055. {
  57056. }
  57057. void MouseListener::mouseUp (const MouseEvent&)
  57058. {
  57059. }
  57060. void MouseListener::mouseDrag (const MouseEvent&)
  57061. {
  57062. }
  57063. void MouseListener::mouseMove (const MouseEvent&)
  57064. {
  57065. }
  57066. void MouseListener::mouseDoubleClick (const MouseEvent&)
  57067. {
  57068. }
  57069. void MouseListener::mouseWheelMove (const MouseEvent&, float, float)
  57070. {
  57071. }
  57072. END_JUCE_NAMESPACE
  57073. /*** End of inlined file: juce_MouseListener.cpp ***/
  57074. /*** Start of inlined file: juce_BooleanPropertyComponent.cpp ***/
  57075. BEGIN_JUCE_NAMESPACE
  57076. BooleanPropertyComponent::BooleanPropertyComponent (const String& name,
  57077. const String& buttonTextWhenTrue,
  57078. const String& buttonTextWhenFalse)
  57079. : PropertyComponent (name),
  57080. onText (buttonTextWhenTrue),
  57081. offText (buttonTextWhenFalse)
  57082. {
  57083. createButton();
  57084. button->addButtonListener (this);
  57085. }
  57086. BooleanPropertyComponent::BooleanPropertyComponent (const Value& valueToControl,
  57087. const String& name,
  57088. const String& buttonText)
  57089. : PropertyComponent (name),
  57090. onText (buttonText),
  57091. offText (buttonText)
  57092. {
  57093. createButton();
  57094. button->setButtonText (buttonText);
  57095. button->getToggleStateValue().referTo (valueToControl);
  57096. button->setClickingTogglesState (true);
  57097. }
  57098. BooleanPropertyComponent::~BooleanPropertyComponent()
  57099. {
  57100. deleteAllChildren();
  57101. }
  57102. void BooleanPropertyComponent::createButton()
  57103. {
  57104. addAndMakeVisible (button = new ToggleButton (String::empty));
  57105. button->setClickingTogglesState (false);
  57106. }
  57107. void BooleanPropertyComponent::setState (const bool newState)
  57108. {
  57109. button->setToggleState (newState, true);
  57110. }
  57111. bool BooleanPropertyComponent::getState() const
  57112. {
  57113. return button->getToggleState();
  57114. }
  57115. void BooleanPropertyComponent::paint (Graphics& g)
  57116. {
  57117. PropertyComponent::paint (g);
  57118. const Rectangle<int> r (button->getBounds());
  57119. g.setColour (Colours::white);
  57120. g.fillRect (r);
  57121. g.setColour (findColour (ComboBox::outlineColourId));
  57122. g.drawRect (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  57123. }
  57124. void BooleanPropertyComponent::refresh()
  57125. {
  57126. button->setToggleState (getState(), false);
  57127. button->setButtonText (button->getToggleState() ? onText : offText);
  57128. }
  57129. void BooleanPropertyComponent::buttonClicked (Button*)
  57130. {
  57131. setState (! getState());
  57132. }
  57133. END_JUCE_NAMESPACE
  57134. /*** End of inlined file: juce_BooleanPropertyComponent.cpp ***/
  57135. /*** Start of inlined file: juce_ButtonPropertyComponent.cpp ***/
  57136. BEGIN_JUCE_NAMESPACE
  57137. ButtonPropertyComponent::ButtonPropertyComponent (const String& name,
  57138. const bool triggerOnMouseDown)
  57139. : PropertyComponent (name)
  57140. {
  57141. addAndMakeVisible (button = new TextButton (String::empty));
  57142. button->setTriggeredOnMouseDown (triggerOnMouseDown);
  57143. button->addButtonListener (this);
  57144. }
  57145. ButtonPropertyComponent::~ButtonPropertyComponent()
  57146. {
  57147. deleteAllChildren();
  57148. }
  57149. void ButtonPropertyComponent::refresh()
  57150. {
  57151. button->setButtonText (getButtonText());
  57152. }
  57153. void ButtonPropertyComponent::buttonClicked (Button*)
  57154. {
  57155. buttonClicked();
  57156. }
  57157. END_JUCE_NAMESPACE
  57158. /*** End of inlined file: juce_ButtonPropertyComponent.cpp ***/
  57159. /*** Start of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57160. BEGIN_JUCE_NAMESPACE
  57161. ChoicePropertyComponent::ChoicePropertyComponent (const String& name)
  57162. : PropertyComponent (name),
  57163. comboBox (0)
  57164. {
  57165. }
  57166. ChoicePropertyComponent::ChoicePropertyComponent (const Value& valueToControl,
  57167. const String& name,
  57168. const StringArray& choices_,
  57169. const Array <int>* choiceIDs)
  57170. : PropertyComponent (name),
  57171. choices (choices_),
  57172. comboBox (0)
  57173. {
  57174. createComboBox (choiceIDs);
  57175. comboBox->getSelectedIdAsValue().referTo (valueToControl);
  57176. }
  57177. ChoicePropertyComponent::~ChoicePropertyComponent()
  57178. {
  57179. deleteAllChildren();
  57180. }
  57181. void ChoicePropertyComponent::createComboBox (const Array <int>* choiceIDs)
  57182. {
  57183. // The array of IDs must contain the same number of values as the choices list!
  57184. jassert (choiceIDs == 0 || choiceIDs->size() == choices.size());
  57185. addAndMakeVisible (comboBox = new ComboBox (String::empty));
  57186. for (int i = 0; i < choices.size(); ++i)
  57187. {
  57188. if (choices[i].isNotEmpty())
  57189. comboBox->addItem (choices[i], choiceIDs == 0 ? (i + 1)
  57190. : ((*choiceIDs)[i]));
  57191. else
  57192. comboBox->addSeparator();
  57193. }
  57194. comboBox->setEditableText (false);
  57195. }
  57196. void ChoicePropertyComponent::setIndex (const int newIndex)
  57197. {
  57198. comboBox->setSelectedId (comboBox->getItemId (newIndex));
  57199. }
  57200. int ChoicePropertyComponent::getIndex() const
  57201. {
  57202. return comboBox->getSelectedItemIndex();
  57203. }
  57204. const StringArray& ChoicePropertyComponent::getChoices() const
  57205. {
  57206. return choices;
  57207. }
  57208. void ChoicePropertyComponent::refresh()
  57209. {
  57210. if (comboBox == 0)
  57211. {
  57212. createComboBox (0);
  57213. comboBox->addListener (this);
  57214. }
  57215. comboBox->setSelectedId (getIndex() + 1, true);
  57216. }
  57217. void ChoicePropertyComponent::comboBoxChanged (ComboBox*)
  57218. {
  57219. const int newIndex = comboBox->getSelectedId() - 1;
  57220. if (newIndex != getIndex())
  57221. setIndex (newIndex);
  57222. }
  57223. END_JUCE_NAMESPACE
  57224. /*** End of inlined file: juce_ChoicePropertyComponent.cpp ***/
  57225. /*** Start of inlined file: juce_PropertyComponent.cpp ***/
  57226. BEGIN_JUCE_NAMESPACE
  57227. PropertyComponent::PropertyComponent (const String& name,
  57228. const int preferredHeight_)
  57229. : Component (name),
  57230. preferredHeight (preferredHeight_)
  57231. {
  57232. jassert (name.isNotEmpty());
  57233. }
  57234. PropertyComponent::~PropertyComponent()
  57235. {
  57236. }
  57237. void PropertyComponent::paint (Graphics& g)
  57238. {
  57239. getLookAndFeel().drawPropertyComponentBackground (g, getWidth(), getHeight(), *this);
  57240. getLookAndFeel().drawPropertyComponentLabel (g, getWidth(), getHeight(), *this);
  57241. }
  57242. void PropertyComponent::resized()
  57243. {
  57244. if (getNumChildComponents() > 0)
  57245. getChildComponent (0)->setBounds (getLookAndFeel().getPropertyComponentContentPosition (*this));
  57246. }
  57247. void PropertyComponent::enablementChanged()
  57248. {
  57249. repaint();
  57250. }
  57251. END_JUCE_NAMESPACE
  57252. /*** End of inlined file: juce_PropertyComponent.cpp ***/
  57253. /*** Start of inlined file: juce_PropertyPanel.cpp ***/
  57254. BEGIN_JUCE_NAMESPACE
  57255. class PropertyHolderComponent : public Component
  57256. {
  57257. public:
  57258. PropertyHolderComponent()
  57259. {
  57260. }
  57261. ~PropertyHolderComponent()
  57262. {
  57263. deleteAllChildren();
  57264. }
  57265. void paint (Graphics&)
  57266. {
  57267. }
  57268. void updateLayout (const int width);
  57269. void refreshAll() const;
  57270. };
  57271. class PropertySectionComponent : public Component
  57272. {
  57273. public:
  57274. PropertySectionComponent (const String& sectionTitle,
  57275. const Array <PropertyComponent*>& newProperties,
  57276. const bool open)
  57277. : Component (sectionTitle),
  57278. titleHeight (sectionTitle.isNotEmpty() ? 22 : 0),
  57279. isOpen_ (open)
  57280. {
  57281. for (int i = newProperties.size(); --i >= 0;)
  57282. {
  57283. addAndMakeVisible (newProperties.getUnchecked(i));
  57284. newProperties.getUnchecked(i)->refresh();
  57285. }
  57286. }
  57287. ~PropertySectionComponent()
  57288. {
  57289. deleteAllChildren();
  57290. }
  57291. void paint (Graphics& g)
  57292. {
  57293. if (titleHeight > 0)
  57294. getLookAndFeel().drawPropertyPanelSectionHeader (g, getName(), isOpen(), getWidth(), titleHeight);
  57295. }
  57296. void resized()
  57297. {
  57298. int y = titleHeight;
  57299. for (int i = getNumChildComponents(); --i >= 0;)
  57300. {
  57301. PropertyComponent* const pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57302. if (pec != 0)
  57303. {
  57304. const int prefH = pec->getPreferredHeight();
  57305. pec->setBounds (1, y, getWidth() - 2, prefH);
  57306. y += prefH;
  57307. }
  57308. }
  57309. }
  57310. int getPreferredHeight() const
  57311. {
  57312. int y = titleHeight;
  57313. if (isOpen())
  57314. {
  57315. for (int i = 0; i < getNumChildComponents(); ++i)
  57316. {
  57317. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57318. if (pec != 0)
  57319. y += pec->getPreferredHeight();
  57320. }
  57321. }
  57322. return y;
  57323. }
  57324. void setOpen (const bool open)
  57325. {
  57326. if (isOpen_ != open)
  57327. {
  57328. isOpen_ = open;
  57329. for (int i = 0; i < getNumChildComponents(); ++i)
  57330. {
  57331. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57332. if (pec != 0)
  57333. pec->setVisible (open);
  57334. }
  57335. // (unable to use the syntax findParentComponentOfClass <DragAndDropContainer> () because of a VC6 compiler bug)
  57336. PropertyPanel* const pp = findParentComponentOfClass ((PropertyPanel*) 0);
  57337. if (pp != 0)
  57338. pp->resized();
  57339. }
  57340. }
  57341. bool isOpen() const
  57342. {
  57343. return isOpen_;
  57344. }
  57345. void refreshAll() const
  57346. {
  57347. for (int i = 0; i < getNumChildComponents(); ++i)
  57348. {
  57349. PropertyComponent* pec = dynamic_cast <PropertyComponent*> (getChildComponent (i));
  57350. if (pec != 0)
  57351. pec->refresh();
  57352. }
  57353. }
  57354. void mouseDown (const MouseEvent&)
  57355. {
  57356. }
  57357. void mouseUp (const MouseEvent& e)
  57358. {
  57359. if (e.getMouseDownX() < titleHeight
  57360. && e.x < titleHeight
  57361. && e.y < titleHeight
  57362. && e.getNumberOfClicks() != 2)
  57363. {
  57364. setOpen (! isOpen());
  57365. }
  57366. }
  57367. void mouseDoubleClick (const MouseEvent& e)
  57368. {
  57369. if (e.y < titleHeight)
  57370. setOpen (! isOpen());
  57371. }
  57372. private:
  57373. int titleHeight;
  57374. bool isOpen_;
  57375. };
  57376. void PropertyHolderComponent::updateLayout (const int width)
  57377. {
  57378. int y = 0;
  57379. for (int i = getNumChildComponents(); --i >= 0;)
  57380. {
  57381. PropertySectionComponent* const section
  57382. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57383. if (section != 0)
  57384. {
  57385. const int prefH = section->getPreferredHeight();
  57386. section->setBounds (0, y, width, prefH);
  57387. y += prefH;
  57388. }
  57389. }
  57390. setSize (width, y);
  57391. repaint();
  57392. }
  57393. void PropertyHolderComponent::refreshAll() const
  57394. {
  57395. for (int i = getNumChildComponents(); --i >= 0;)
  57396. {
  57397. PropertySectionComponent* const section
  57398. = dynamic_cast <PropertySectionComponent*> (getChildComponent (i));
  57399. if (section != 0)
  57400. section->refreshAll();
  57401. }
  57402. }
  57403. PropertyPanel::PropertyPanel()
  57404. {
  57405. messageWhenEmpty = TRANS("(nothing selected)");
  57406. addAndMakeVisible (viewport = new Viewport());
  57407. viewport->setViewedComponent (propertyHolderComponent = new PropertyHolderComponent());
  57408. viewport->setFocusContainer (true);
  57409. }
  57410. PropertyPanel::~PropertyPanel()
  57411. {
  57412. clear();
  57413. deleteAllChildren();
  57414. }
  57415. void PropertyPanel::paint (Graphics& g)
  57416. {
  57417. if (propertyHolderComponent->getNumChildComponents() == 0)
  57418. {
  57419. g.setColour (Colours::black.withAlpha (0.5f));
  57420. g.setFont (14.0f);
  57421. g.drawText (messageWhenEmpty, 0, 0, getWidth(), 30,
  57422. Justification::centred, true);
  57423. }
  57424. }
  57425. void PropertyPanel::resized()
  57426. {
  57427. viewport->setBounds (0, 0, getWidth(), getHeight());
  57428. updatePropHolderLayout();
  57429. }
  57430. void PropertyPanel::clear()
  57431. {
  57432. if (propertyHolderComponent->getNumChildComponents() > 0)
  57433. {
  57434. propertyHolderComponent->deleteAllChildren();
  57435. repaint();
  57436. }
  57437. }
  57438. void PropertyPanel::addProperties (const Array <PropertyComponent*>& newProperties)
  57439. {
  57440. if (propertyHolderComponent->getNumChildComponents() == 0)
  57441. repaint();
  57442. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (String::empty,
  57443. newProperties,
  57444. true), 0);
  57445. updatePropHolderLayout();
  57446. }
  57447. void PropertyPanel::addSection (const String& sectionTitle,
  57448. const Array <PropertyComponent*>& newProperties,
  57449. const bool shouldBeOpen)
  57450. {
  57451. jassert (sectionTitle.isNotEmpty());
  57452. if (propertyHolderComponent->getNumChildComponents() == 0)
  57453. repaint();
  57454. propertyHolderComponent->addAndMakeVisible (new PropertySectionComponent (sectionTitle,
  57455. newProperties,
  57456. shouldBeOpen), 0);
  57457. updatePropHolderLayout();
  57458. }
  57459. void PropertyPanel::updatePropHolderLayout() const
  57460. {
  57461. const int maxWidth = viewport->getMaximumVisibleWidth();
  57462. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (maxWidth);
  57463. const int newMaxWidth = viewport->getMaximumVisibleWidth();
  57464. if (maxWidth != newMaxWidth)
  57465. {
  57466. // need to do this twice because of scrollbars changing the size, etc.
  57467. ((PropertyHolderComponent*) propertyHolderComponent)->updateLayout (newMaxWidth);
  57468. }
  57469. }
  57470. void PropertyPanel::refreshAll() const
  57471. {
  57472. ((PropertyHolderComponent*) propertyHolderComponent)->refreshAll();
  57473. }
  57474. const StringArray PropertyPanel::getSectionNames() const
  57475. {
  57476. StringArray s;
  57477. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57478. {
  57479. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57480. if (section != 0 && section->getName().isNotEmpty())
  57481. s.add (section->getName());
  57482. }
  57483. return s;
  57484. }
  57485. bool PropertyPanel::isSectionOpen (const int sectionIndex) const
  57486. {
  57487. int index = 0;
  57488. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57489. {
  57490. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57491. if (section != 0 && section->getName().isNotEmpty())
  57492. {
  57493. if (index == sectionIndex)
  57494. return section->isOpen();
  57495. ++index;
  57496. }
  57497. }
  57498. return false;
  57499. }
  57500. void PropertyPanel::setSectionOpen (const int sectionIndex, const bool shouldBeOpen)
  57501. {
  57502. int index = 0;
  57503. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57504. {
  57505. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57506. if (section != 0 && section->getName().isNotEmpty())
  57507. {
  57508. if (index == sectionIndex)
  57509. {
  57510. section->setOpen (shouldBeOpen);
  57511. break;
  57512. }
  57513. ++index;
  57514. }
  57515. }
  57516. }
  57517. void PropertyPanel::setSectionEnabled (const int sectionIndex, const bool shouldBeEnabled)
  57518. {
  57519. int index = 0;
  57520. for (int i = 0; i < propertyHolderComponent->getNumChildComponents(); ++i)
  57521. {
  57522. PropertySectionComponent* const section = dynamic_cast <PropertySectionComponent*> (propertyHolderComponent->getChildComponent (i));
  57523. if (section != 0 && section->getName().isNotEmpty())
  57524. {
  57525. if (index == sectionIndex)
  57526. {
  57527. section->setEnabled (shouldBeEnabled);
  57528. break;
  57529. }
  57530. ++index;
  57531. }
  57532. }
  57533. }
  57534. XmlElement* PropertyPanel::getOpennessState() const
  57535. {
  57536. XmlElement* const xml = new XmlElement (T("PROPERTYPANELSTATE"));
  57537. xml->setAttribute ("scrollPos", viewport->getViewPositionY());
  57538. const StringArray sections (getSectionNames());
  57539. for (int i = 0; i < sections.size(); ++i)
  57540. {
  57541. if (sections[i].isNotEmpty())
  57542. {
  57543. XmlElement* const e = xml->createNewChildElement ("SECTION");
  57544. e->setAttribute ("name", sections[i]);
  57545. e->setAttribute ("open", isSectionOpen (i) ? 1 : 0);
  57546. }
  57547. }
  57548. return xml;
  57549. }
  57550. void PropertyPanel::restoreOpennessState (const XmlElement& xml)
  57551. {
  57552. if (xml.hasTagName (T("PROPERTYPANELSTATE")))
  57553. {
  57554. const StringArray sections (getSectionNames());
  57555. forEachXmlChildElementWithTagName (xml, e, T("SECTION"))
  57556. {
  57557. setSectionOpen (sections.indexOf (e->getStringAttribute (T("name"))),
  57558. e->getBoolAttribute (T("open")));
  57559. }
  57560. viewport->setViewPosition (viewport->getViewPositionX(),
  57561. xml.getIntAttribute ("scrollPos", viewport->getViewPositionY()));
  57562. }
  57563. }
  57564. void PropertyPanel::setMessageWhenEmpty (const String& newMessage)
  57565. {
  57566. if (messageWhenEmpty != newMessage)
  57567. {
  57568. messageWhenEmpty = newMessage;
  57569. repaint();
  57570. }
  57571. }
  57572. const String& PropertyPanel::getMessageWhenEmpty() const
  57573. {
  57574. return messageWhenEmpty;
  57575. }
  57576. END_JUCE_NAMESPACE
  57577. /*** End of inlined file: juce_PropertyPanel.cpp ***/
  57578. /*** Start of inlined file: juce_SliderPropertyComponent.cpp ***/
  57579. BEGIN_JUCE_NAMESPACE
  57580. SliderPropertyComponent::SliderPropertyComponent (const String& name,
  57581. const double rangeMin,
  57582. const double rangeMax,
  57583. const double interval,
  57584. const double skewFactor)
  57585. : PropertyComponent (name)
  57586. {
  57587. addAndMakeVisible (slider = new Slider (name));
  57588. slider->setRange (rangeMin, rangeMax, interval);
  57589. slider->setSkewFactor (skewFactor);
  57590. slider->setSliderStyle (Slider::LinearBar);
  57591. slider->addListener (this);
  57592. }
  57593. SliderPropertyComponent::SliderPropertyComponent (Value& valueToControl,
  57594. const String& name,
  57595. const double rangeMin,
  57596. const double rangeMax,
  57597. const double interval,
  57598. const double skewFactor)
  57599. : PropertyComponent (name)
  57600. {
  57601. addAndMakeVisible (slider = new Slider (name));
  57602. slider->setRange (rangeMin, rangeMax, interval);
  57603. slider->setSkewFactor (skewFactor);
  57604. slider->setSliderStyle (Slider::LinearBar);
  57605. slider->getValueObject().referTo (valueToControl);
  57606. }
  57607. SliderPropertyComponent::~SliderPropertyComponent()
  57608. {
  57609. deleteAllChildren();
  57610. }
  57611. void SliderPropertyComponent::setValue (const double /*newValue*/)
  57612. {
  57613. }
  57614. const double SliderPropertyComponent::getValue() const
  57615. {
  57616. return slider->getValue();
  57617. }
  57618. void SliderPropertyComponent::refresh()
  57619. {
  57620. slider->setValue (getValue(), false);
  57621. }
  57622. void SliderPropertyComponent::sliderValueChanged (Slider*)
  57623. {
  57624. if (getValue() != slider->getValue())
  57625. setValue (slider->getValue());
  57626. }
  57627. END_JUCE_NAMESPACE
  57628. /*** End of inlined file: juce_SliderPropertyComponent.cpp ***/
  57629. /*** Start of inlined file: juce_TextPropertyComponent.cpp ***/
  57630. BEGIN_JUCE_NAMESPACE
  57631. class TextPropLabel : public Label
  57632. {
  57633. TextPropertyComponent& owner;
  57634. int maxChars;
  57635. bool isMultiline;
  57636. public:
  57637. TextPropLabel (TextPropertyComponent& owner_,
  57638. const int maxChars_, const bool isMultiline_)
  57639. : Label (String::empty, String::empty),
  57640. owner (owner_),
  57641. maxChars (maxChars_),
  57642. isMultiline (isMultiline_)
  57643. {
  57644. setEditable (true, true, false);
  57645. setColour (backgroundColourId, Colours::white);
  57646. setColour (outlineColourId, findColour (ComboBox::outlineColourId));
  57647. }
  57648. ~TextPropLabel()
  57649. {
  57650. }
  57651. TextEditor* createEditorComponent()
  57652. {
  57653. TextEditor* const textEditor = Label::createEditorComponent();
  57654. textEditor->setInputRestrictions (maxChars);
  57655. if (isMultiline)
  57656. {
  57657. textEditor->setMultiLine (true, true);
  57658. textEditor->setReturnKeyStartsNewLine (true);
  57659. }
  57660. return textEditor;
  57661. }
  57662. void textWasEdited()
  57663. {
  57664. owner.textWasEdited();
  57665. }
  57666. };
  57667. TextPropertyComponent::TextPropertyComponent (const String& name,
  57668. const int maxNumChars,
  57669. const bool isMultiLine)
  57670. : PropertyComponent (name)
  57671. {
  57672. createEditor (maxNumChars, isMultiLine);
  57673. }
  57674. TextPropertyComponent::TextPropertyComponent (const Value& valueToControl,
  57675. const String& name,
  57676. const int maxNumChars,
  57677. const bool isMultiLine)
  57678. : PropertyComponent (name)
  57679. {
  57680. createEditor (maxNumChars, isMultiLine);
  57681. textEditor->getTextValue().referTo (valueToControl);
  57682. }
  57683. TextPropertyComponent::~TextPropertyComponent()
  57684. {
  57685. deleteAllChildren();
  57686. }
  57687. void TextPropertyComponent::setText (const String& newText)
  57688. {
  57689. textEditor->setText (newText, true);
  57690. }
  57691. const String TextPropertyComponent::getText() const
  57692. {
  57693. return textEditor->getText();
  57694. }
  57695. void TextPropertyComponent::createEditor (const int maxNumChars, const bool isMultiLine)
  57696. {
  57697. addAndMakeVisible (textEditor = new TextPropLabel (*this, maxNumChars, isMultiLine));
  57698. if (isMultiLine)
  57699. {
  57700. textEditor->setJustificationType (Justification::topLeft);
  57701. preferredHeight = 120;
  57702. }
  57703. }
  57704. void TextPropertyComponent::refresh()
  57705. {
  57706. textEditor->setText (getText(), false);
  57707. }
  57708. void TextPropertyComponent::textWasEdited()
  57709. {
  57710. const String newText (textEditor->getText());
  57711. if (getText() != newText)
  57712. setText (newText);
  57713. }
  57714. END_JUCE_NAMESPACE
  57715. /*** End of inlined file: juce_TextPropertyComponent.cpp ***/
  57716. /*** Start of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  57717. BEGIN_JUCE_NAMESPACE
  57718. class SimpleDeviceManagerInputLevelMeter : public Component,
  57719. public Timer
  57720. {
  57721. public:
  57722. SimpleDeviceManagerInputLevelMeter (AudioDeviceManager* const manager_)
  57723. : manager (manager_),
  57724. level (0)
  57725. {
  57726. startTimer (50);
  57727. manager->enableInputLevelMeasurement (true);
  57728. }
  57729. ~SimpleDeviceManagerInputLevelMeter()
  57730. {
  57731. manager->enableInputLevelMeasurement (false);
  57732. }
  57733. void timerCallback()
  57734. {
  57735. const float newLevel = (float) manager->getCurrentInputLevel();
  57736. if (fabsf (level - newLevel) > 0.005f)
  57737. {
  57738. level = newLevel;
  57739. repaint();
  57740. }
  57741. }
  57742. void paint (Graphics& g)
  57743. {
  57744. getLookAndFeel().drawLevelMeter (g, getWidth(), getHeight(),
  57745. (float) exp (log (level) / 3.0)); // (add a bit of a skew to make the level more obvious)
  57746. }
  57747. private:
  57748. AudioDeviceManager* const manager;
  57749. float level;
  57750. };
  57751. class MidiInputSelectorComponentListBox : public ListBox,
  57752. public ListBoxModel
  57753. {
  57754. public:
  57755. MidiInputSelectorComponentListBox (AudioDeviceManager& deviceManager_,
  57756. const String& noItemsMessage_,
  57757. const int minNumber_,
  57758. const int maxNumber_)
  57759. : ListBox (String::empty, 0),
  57760. deviceManager (deviceManager_),
  57761. noItemsMessage (noItemsMessage_),
  57762. minNumber (minNumber_),
  57763. maxNumber (maxNumber_)
  57764. {
  57765. items = MidiInput::getDevices();
  57766. setModel (this);
  57767. setOutlineThickness (1);
  57768. }
  57769. ~MidiInputSelectorComponentListBox()
  57770. {
  57771. }
  57772. int getNumRows()
  57773. {
  57774. return items.size();
  57775. }
  57776. void paintListBoxItem (int row,
  57777. Graphics& g,
  57778. int width, int height,
  57779. bool rowIsSelected)
  57780. {
  57781. if (((unsigned int) row) < (unsigned int) items.size())
  57782. {
  57783. if (rowIsSelected)
  57784. g.fillAll (findColour (TextEditor::highlightColourId)
  57785. .withMultipliedAlpha (0.3f));
  57786. const String item (items [row]);
  57787. bool enabled = deviceManager.isMidiInputEnabled (item);
  57788. const int x = getTickX();
  57789. const float tickW = height * 0.75f;
  57790. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  57791. enabled, true, true, false);
  57792. g.setFont (height * 0.6f);
  57793. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  57794. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  57795. }
  57796. }
  57797. void listBoxItemClicked (int row, const MouseEvent& e)
  57798. {
  57799. selectRow (row);
  57800. if (e.x < getTickX())
  57801. flipEnablement (row);
  57802. }
  57803. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  57804. {
  57805. flipEnablement (row);
  57806. }
  57807. void returnKeyPressed (int row)
  57808. {
  57809. flipEnablement (row);
  57810. }
  57811. void paint (Graphics& g)
  57812. {
  57813. ListBox::paint (g);
  57814. if (items.size() == 0)
  57815. {
  57816. g.setColour (Colours::grey);
  57817. g.setFont (13.0f);
  57818. g.drawText (noItemsMessage,
  57819. 0, 0, getWidth(), getHeight() / 2,
  57820. Justification::centred, true);
  57821. }
  57822. }
  57823. int getBestHeight (const int preferredHeight)
  57824. {
  57825. const int extra = getOutlineThickness() * 2;
  57826. return jmax (getRowHeight() * 2 + extra,
  57827. jmin (getRowHeight() * getNumRows() + extra,
  57828. preferredHeight));
  57829. }
  57830. juce_UseDebuggingNewOperator
  57831. private:
  57832. AudioDeviceManager& deviceManager;
  57833. const String noItemsMessage;
  57834. StringArray items;
  57835. int minNumber, maxNumber;
  57836. void flipEnablement (const int row)
  57837. {
  57838. if (((unsigned int) row) < (unsigned int) items.size())
  57839. {
  57840. const String item (items [row]);
  57841. deviceManager.setMidiInputEnabled (item, ! deviceManager.isMidiInputEnabled (item));
  57842. }
  57843. }
  57844. int getTickX() const
  57845. {
  57846. return getRowHeight() + 5;
  57847. }
  57848. MidiInputSelectorComponentListBox (const MidiInputSelectorComponentListBox&);
  57849. MidiInputSelectorComponentListBox& operator= (const MidiInputSelectorComponentListBox&);
  57850. };
  57851. class AudioDeviceSettingsPanel : public Component,
  57852. public ComboBoxListener,
  57853. public ChangeListener,
  57854. public ButtonListener
  57855. {
  57856. public:
  57857. AudioDeviceSettingsPanel (AudioIODeviceType* type_,
  57858. AudioIODeviceType::DeviceSetupDetails& setup_,
  57859. const bool hideAdvancedOptionsWithButton)
  57860. : type (type_),
  57861. setup (setup_)
  57862. {
  57863. sampleRateDropDown = 0;
  57864. sampleRateLabel = 0;
  57865. bufferSizeDropDown = 0;
  57866. bufferSizeLabel = 0;
  57867. outputDeviceDropDown = 0;
  57868. outputDeviceLabel = 0;
  57869. inputDeviceDropDown = 0;
  57870. inputDeviceLabel = 0;
  57871. testButton = 0;
  57872. inputLevelMeter = 0;
  57873. showUIButton = 0;
  57874. inputChanList = 0;
  57875. outputChanList = 0;
  57876. inputChanLabel = 0;
  57877. outputChanLabel = 0;
  57878. showAdvancedSettingsButton = 0;
  57879. if (hideAdvancedOptionsWithButton)
  57880. {
  57881. addAndMakeVisible (showAdvancedSettingsButton = new TextButton (TRANS("Show advanced settings...")));
  57882. showAdvancedSettingsButton->addButtonListener (this);
  57883. }
  57884. type->scanForDevices();
  57885. setup.manager->addChangeListener (this);
  57886. changeListenerCallback (0);
  57887. }
  57888. ~AudioDeviceSettingsPanel()
  57889. {
  57890. setup.manager->removeChangeListener (this);
  57891. deleteAndZero (outputDeviceLabel);
  57892. deleteAndZero (inputDeviceLabel);
  57893. deleteAndZero (sampleRateLabel);
  57894. deleteAndZero (bufferSizeLabel);
  57895. deleteAndZero (showUIButton);
  57896. deleteAndZero (inputChanLabel);
  57897. deleteAndZero (outputChanLabel);
  57898. deleteAndZero (showAdvancedSettingsButton);
  57899. deleteAllChildren();
  57900. }
  57901. void resized()
  57902. {
  57903. const int lx = proportionOfWidth (0.35f);
  57904. const int w = proportionOfWidth (0.4f);
  57905. const int h = 24;
  57906. const int space = 6;
  57907. const int dh = h + space;
  57908. int y = 0;
  57909. if (outputDeviceDropDown != 0)
  57910. {
  57911. outputDeviceDropDown->setBounds (lx, y, w, h);
  57912. if (testButton != 0)
  57913. testButton->setBounds (proportionOfWidth (0.77f),
  57914. outputDeviceDropDown->getY(),
  57915. proportionOfWidth (0.18f),
  57916. h);
  57917. y += dh;
  57918. }
  57919. if (inputDeviceDropDown != 0)
  57920. {
  57921. inputDeviceDropDown->setBounds (lx, y, w, h);
  57922. inputLevelMeter->setBounds (proportionOfWidth (0.77f),
  57923. inputDeviceDropDown->getY(),
  57924. proportionOfWidth (0.18f),
  57925. h);
  57926. y += dh;
  57927. }
  57928. const int maxBoxHeight = 100;//(getHeight() - y - dh * 2) / numBoxes;
  57929. if (outputChanList != 0)
  57930. {
  57931. const int bh = outputChanList->getBestHeight (maxBoxHeight);
  57932. outputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57933. y += bh + space;
  57934. }
  57935. if (inputChanList != 0)
  57936. {
  57937. const int bh = inputChanList->getBestHeight (maxBoxHeight);
  57938. inputChanList->setBounds (lx, y, proportionOfWidth (0.55f), bh);
  57939. y += bh + space;
  57940. }
  57941. y += space * 2;
  57942. if (showAdvancedSettingsButton != 0)
  57943. {
  57944. showAdvancedSettingsButton->changeWidthToFitText (h);
  57945. showAdvancedSettingsButton->setTopLeftPosition (lx, y);
  57946. }
  57947. if (sampleRateDropDown != 0)
  57948. {
  57949. sampleRateDropDown->setVisible (showAdvancedSettingsButton == 0
  57950. || ! showAdvancedSettingsButton->isVisible());
  57951. sampleRateDropDown->setBounds (lx, y, w, h);
  57952. y += dh;
  57953. }
  57954. if (bufferSizeDropDown != 0)
  57955. {
  57956. bufferSizeDropDown->setVisible (showAdvancedSettingsButton == 0
  57957. || ! showAdvancedSettingsButton->isVisible());
  57958. bufferSizeDropDown->setBounds (lx, y, w, h);
  57959. y += dh;
  57960. }
  57961. if (showUIButton != 0)
  57962. {
  57963. showUIButton->setVisible (showAdvancedSettingsButton == 0
  57964. || ! showAdvancedSettingsButton->isVisible());
  57965. showUIButton->changeWidthToFitText (h);
  57966. showUIButton->setTopLeftPosition (lx, y);
  57967. }
  57968. }
  57969. void comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  57970. {
  57971. if (comboBoxThatHasChanged == 0)
  57972. return;
  57973. AudioDeviceManager::AudioDeviceSetup config;
  57974. setup.manager->getAudioDeviceSetup (config);
  57975. String error;
  57976. if (comboBoxThatHasChanged == outputDeviceDropDown
  57977. || comboBoxThatHasChanged == inputDeviceDropDown)
  57978. {
  57979. if (outputDeviceDropDown != 0)
  57980. config.outputDeviceName = outputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57981. : outputDeviceDropDown->getText();
  57982. if (inputDeviceDropDown != 0)
  57983. config.inputDeviceName = inputDeviceDropDown->getSelectedId() < 0 ? String::empty
  57984. : inputDeviceDropDown->getText();
  57985. if (! type->hasSeparateInputsAndOutputs())
  57986. config.inputDeviceName = config.outputDeviceName;
  57987. if (comboBoxThatHasChanged == inputDeviceDropDown)
  57988. config.useDefaultInputChannels = true;
  57989. else
  57990. config.useDefaultOutputChannels = true;
  57991. error = setup.manager->setAudioDeviceSetup (config, true);
  57992. showCorrectDeviceName (inputDeviceDropDown, true);
  57993. showCorrectDeviceName (outputDeviceDropDown, false);
  57994. updateControlPanelButton();
  57995. resized();
  57996. }
  57997. else if (comboBoxThatHasChanged == sampleRateDropDown)
  57998. {
  57999. if (sampleRateDropDown->getSelectedId() > 0)
  58000. {
  58001. config.sampleRate = sampleRateDropDown->getSelectedId();
  58002. error = setup.manager->setAudioDeviceSetup (config, true);
  58003. }
  58004. }
  58005. else if (comboBoxThatHasChanged == bufferSizeDropDown)
  58006. {
  58007. if (bufferSizeDropDown->getSelectedId() > 0)
  58008. {
  58009. config.bufferSize = bufferSizeDropDown->getSelectedId();
  58010. error = setup.manager->setAudioDeviceSetup (config, true);
  58011. }
  58012. }
  58013. if (error.isNotEmpty())
  58014. {
  58015. AlertWindow::showMessageBox (AlertWindow::WarningIcon,
  58016. T("Error when trying to open audio device!"),
  58017. error);
  58018. }
  58019. }
  58020. void buttonClicked (Button* button)
  58021. {
  58022. if (button == showAdvancedSettingsButton)
  58023. {
  58024. showAdvancedSettingsButton->setVisible (false);
  58025. resized();
  58026. }
  58027. else if (button == showUIButton)
  58028. {
  58029. AudioIODevice* const device = setup.manager->getCurrentAudioDevice();
  58030. if (device != 0 && device->showControlPanel())
  58031. {
  58032. setup.manager->closeAudioDevice();
  58033. setup.manager->restartLastAudioDevice();
  58034. getTopLevelComponent()->toFront (true);
  58035. }
  58036. }
  58037. else if (button == testButton && testButton != 0)
  58038. {
  58039. setup.manager->playTestSound();
  58040. }
  58041. }
  58042. void updateControlPanelButton()
  58043. {
  58044. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58045. deleteAndZero (showUIButton);
  58046. if (currentDevice != 0 && currentDevice->hasControlPanel())
  58047. {
  58048. addAndMakeVisible (showUIButton = new TextButton (TRANS ("show this device's control panel"),
  58049. TRANS ("opens the device's own control panel")));
  58050. showUIButton->addButtonListener (this);
  58051. }
  58052. resized();
  58053. }
  58054. void changeListenerCallback (void*)
  58055. {
  58056. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58057. if (setup.maxNumOutputChannels > 0 || ! type->hasSeparateInputsAndOutputs())
  58058. {
  58059. if (outputDeviceDropDown == 0)
  58060. {
  58061. outputDeviceDropDown = new ComboBox (String::empty);
  58062. outputDeviceDropDown->addListener (this);
  58063. addAndMakeVisible (outputDeviceDropDown);
  58064. outputDeviceLabel = new Label (String::empty,
  58065. type->hasSeparateInputsAndOutputs() ? TRANS ("output:")
  58066. : TRANS ("device:"));
  58067. outputDeviceLabel->attachToComponent (outputDeviceDropDown, true);
  58068. if (setup.maxNumOutputChannels > 0)
  58069. {
  58070. addAndMakeVisible (testButton = new TextButton (TRANS ("Test")));
  58071. testButton->addButtonListener (this);
  58072. }
  58073. }
  58074. addNamesToDeviceBox (*outputDeviceDropDown, false);
  58075. }
  58076. if (setup.maxNumInputChannels > 0 && type->hasSeparateInputsAndOutputs())
  58077. {
  58078. if (inputDeviceDropDown == 0)
  58079. {
  58080. inputDeviceDropDown = new ComboBox (String::empty);
  58081. inputDeviceDropDown->addListener (this);
  58082. addAndMakeVisible (inputDeviceDropDown);
  58083. inputDeviceLabel = new Label (String::empty, TRANS ("input:"));
  58084. inputDeviceLabel->attachToComponent (inputDeviceDropDown, true);
  58085. addAndMakeVisible (inputLevelMeter
  58086. = new SimpleDeviceManagerInputLevelMeter (setup.manager));
  58087. }
  58088. addNamesToDeviceBox (*inputDeviceDropDown, true);
  58089. }
  58090. updateControlPanelButton();
  58091. showCorrectDeviceName (inputDeviceDropDown, true);
  58092. showCorrectDeviceName (outputDeviceDropDown, false);
  58093. if (currentDevice != 0)
  58094. {
  58095. if (setup.maxNumOutputChannels > 0
  58096. && setup.minNumOutputChannels < setup.manager->getCurrentAudioDevice()->getOutputChannelNames().size())
  58097. {
  58098. if (outputChanList == 0)
  58099. {
  58100. addAndMakeVisible (outputChanList
  58101. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioOutputType,
  58102. TRANS ("(no audio output channels found)")));
  58103. outputChanLabel = new Label (String::empty, TRANS ("active output channels:"));
  58104. outputChanLabel->attachToComponent (outputChanList, true);
  58105. }
  58106. outputChanList->refresh();
  58107. }
  58108. else
  58109. {
  58110. deleteAndZero (outputChanLabel);
  58111. deleteAndZero (outputChanList);
  58112. }
  58113. if (setup.maxNumInputChannels > 0
  58114. && setup.minNumInputChannels < setup.manager->getCurrentAudioDevice()->getInputChannelNames().size())
  58115. {
  58116. if (inputChanList == 0)
  58117. {
  58118. addAndMakeVisible (inputChanList
  58119. = new ChannelSelectorListBox (setup, ChannelSelectorListBox::audioInputType,
  58120. TRANS ("(no audio input channels found)")));
  58121. inputChanLabel = new Label (String::empty, TRANS ("active input channels:"));
  58122. inputChanLabel->attachToComponent (inputChanList, true);
  58123. }
  58124. inputChanList->refresh();
  58125. }
  58126. else
  58127. {
  58128. deleteAndZero (inputChanLabel);
  58129. deleteAndZero (inputChanList);
  58130. }
  58131. // sample rate..
  58132. {
  58133. if (sampleRateDropDown == 0)
  58134. {
  58135. addAndMakeVisible (sampleRateDropDown = new ComboBox (String::empty));
  58136. sampleRateDropDown->addListener (this);
  58137. delete sampleRateLabel;
  58138. sampleRateLabel = new Label (String::empty, TRANS ("sample rate:"));
  58139. sampleRateLabel->attachToComponent (sampleRateDropDown, true);
  58140. }
  58141. else
  58142. {
  58143. sampleRateDropDown->clear();
  58144. sampleRateDropDown->removeListener (this);
  58145. }
  58146. const int numRates = currentDevice->getNumSampleRates();
  58147. for (int i = 0; i < numRates; ++i)
  58148. {
  58149. const int rate = roundToInt (currentDevice->getSampleRate (i));
  58150. sampleRateDropDown->addItem (String (rate) + T(" Hz"), rate);
  58151. }
  58152. sampleRateDropDown->setSelectedId (roundToInt (currentDevice->getCurrentSampleRate()), true);
  58153. sampleRateDropDown->addListener (this);
  58154. }
  58155. // buffer size
  58156. {
  58157. if (bufferSizeDropDown == 0)
  58158. {
  58159. addAndMakeVisible (bufferSizeDropDown = new ComboBox (String::empty));
  58160. bufferSizeDropDown->addListener (this);
  58161. delete bufferSizeLabel;
  58162. bufferSizeLabel = new Label (String::empty, TRANS ("audio buffer size:"));
  58163. bufferSizeLabel->attachToComponent (bufferSizeDropDown, true);
  58164. }
  58165. else
  58166. {
  58167. bufferSizeDropDown->clear();
  58168. }
  58169. const int numBufferSizes = currentDevice->getNumBufferSizesAvailable();
  58170. double currentRate = currentDevice->getCurrentSampleRate();
  58171. if (currentRate == 0)
  58172. currentRate = 48000.0;
  58173. for (int i = 0; i < numBufferSizes; ++i)
  58174. {
  58175. const int bs = currentDevice->getBufferSizeSamples (i);
  58176. bufferSizeDropDown->addItem (String (bs)
  58177. + T(" samples (")
  58178. + String (bs * 1000.0 / currentRate, 1)
  58179. + T(" ms)"),
  58180. bs);
  58181. }
  58182. bufferSizeDropDown->setSelectedId (currentDevice->getCurrentBufferSizeSamples(), true);
  58183. }
  58184. }
  58185. else
  58186. {
  58187. jassert (setup.manager->getCurrentAudioDevice() == 0); // not the correct device type!
  58188. deleteAndZero (sampleRateLabel);
  58189. deleteAndZero (bufferSizeLabel);
  58190. deleteAndZero (sampleRateDropDown);
  58191. deleteAndZero (bufferSizeDropDown);
  58192. if (outputDeviceDropDown != 0)
  58193. outputDeviceDropDown->setSelectedId (-1, true);
  58194. if (inputDeviceDropDown != 0)
  58195. inputDeviceDropDown->setSelectedId (-1, true);
  58196. }
  58197. resized();
  58198. setSize (getWidth(), getLowestY() + 4);
  58199. }
  58200. private:
  58201. AudioIODeviceType* const type;
  58202. const AudioIODeviceType::DeviceSetupDetails setup;
  58203. ComboBox* outputDeviceDropDown;
  58204. ComboBox* inputDeviceDropDown;
  58205. ComboBox* sampleRateDropDown;
  58206. ComboBox* bufferSizeDropDown;
  58207. Label* outputDeviceLabel;
  58208. Label* inputDeviceLabel;
  58209. Label* sampleRateLabel;
  58210. Label* bufferSizeLabel;
  58211. Label* inputChanLabel;
  58212. Label* outputChanLabel;
  58213. TextButton* testButton;
  58214. Component* inputLevelMeter;
  58215. TextButton* showUIButton;
  58216. TextButton* showAdvancedSettingsButton;
  58217. void showCorrectDeviceName (ComboBox* const box, const bool isInput)
  58218. {
  58219. if (box != 0)
  58220. {
  58221. AudioIODevice* const currentDevice = dynamic_cast <AudioIODevice*> (setup.manager->getCurrentAudioDevice());
  58222. const int index = type->getIndexOfDevice (currentDevice, isInput);
  58223. box->setSelectedId (index + 1, true);
  58224. if (testButton != 0 && ! isInput)
  58225. testButton->setEnabled (index >= 0);
  58226. }
  58227. }
  58228. void addNamesToDeviceBox (ComboBox& combo, bool isInputs)
  58229. {
  58230. const StringArray devs (type->getDeviceNames (isInputs));
  58231. combo.clear (true);
  58232. for (int i = 0; i < devs.size(); ++i)
  58233. combo.addItem (devs[i], i + 1);
  58234. combo.addItem (TRANS("<< none >>"), -1);
  58235. combo.setSelectedId (-1, true);
  58236. }
  58237. int getLowestY() const
  58238. {
  58239. int y = 0;
  58240. for (int i = getNumChildComponents(); --i >= 0;)
  58241. y = jmax (y, getChildComponent (i)->getBottom());
  58242. return y;
  58243. }
  58244. public:
  58245. class ChannelSelectorListBox : public ListBox,
  58246. public ListBoxModel
  58247. {
  58248. public:
  58249. enum BoxType
  58250. {
  58251. audioInputType,
  58252. audioOutputType
  58253. };
  58254. ChannelSelectorListBox (const AudioIODeviceType::DeviceSetupDetails& setup_,
  58255. const BoxType type_,
  58256. const String& noItemsMessage_)
  58257. : ListBox (String::empty, 0),
  58258. setup (setup_),
  58259. type (type_),
  58260. noItemsMessage (noItemsMessage_)
  58261. {
  58262. refresh();
  58263. setModel (this);
  58264. setOutlineThickness (1);
  58265. }
  58266. ~ChannelSelectorListBox()
  58267. {
  58268. }
  58269. void refresh()
  58270. {
  58271. items.clear();
  58272. AudioIODevice* const currentDevice = setup.manager->getCurrentAudioDevice();
  58273. if (currentDevice != 0)
  58274. {
  58275. if (type == audioInputType)
  58276. items = currentDevice->getInputChannelNames();
  58277. else if (type == audioOutputType)
  58278. items = currentDevice->getOutputChannelNames();
  58279. if (setup.useStereoPairs)
  58280. {
  58281. StringArray pairs;
  58282. for (int i = 0; i < items.size(); i += 2)
  58283. {
  58284. String name (items[i]);
  58285. String name2 (items[i + 1]);
  58286. String commonBit;
  58287. for (int j = 0; j < name.length(); ++j)
  58288. if (name.substring (0, j).equalsIgnoreCase (name2.substring (0, j)))
  58289. commonBit = name.substring (0, j);
  58290. pairs.add (name.trim()
  58291. + " + "
  58292. + name2.substring (commonBit.length()).trim());
  58293. }
  58294. items = pairs;
  58295. }
  58296. }
  58297. updateContent();
  58298. repaint();
  58299. }
  58300. int getNumRows()
  58301. {
  58302. return items.size();
  58303. }
  58304. void paintListBoxItem (int row,
  58305. Graphics& g,
  58306. int width, int height,
  58307. bool rowIsSelected)
  58308. {
  58309. if (((unsigned int) row) < (unsigned int) items.size())
  58310. {
  58311. if (rowIsSelected)
  58312. g.fillAll (findColour (TextEditor::highlightColourId)
  58313. .withMultipliedAlpha (0.3f));
  58314. const String item (items [row]);
  58315. bool enabled = false;
  58316. AudioDeviceManager::AudioDeviceSetup config;
  58317. setup.manager->getAudioDeviceSetup (config);
  58318. if (setup.useStereoPairs)
  58319. {
  58320. if (type == audioInputType)
  58321. enabled = config.inputChannels [row * 2] || config.inputChannels [row * 2 + 1];
  58322. else if (type == audioOutputType)
  58323. enabled = config.outputChannels [row * 2] || config.outputChannels [row * 2 + 1];
  58324. }
  58325. else
  58326. {
  58327. if (type == audioInputType)
  58328. enabled = config.inputChannels [row];
  58329. else if (type == audioOutputType)
  58330. enabled = config.outputChannels [row];
  58331. }
  58332. const int x = getTickX();
  58333. const float tickW = height * 0.75f;
  58334. getLookAndFeel().drawTickBox (g, *this, x - tickW, (height - tickW) / 2, tickW, tickW,
  58335. enabled, true, true, false);
  58336. g.setFont (height * 0.6f);
  58337. g.setColour (findColour (ListBox::textColourId, true).withMultipliedAlpha (enabled ? 1.0f : 0.6f));
  58338. g.drawText (item, x, 0, width - x - 2, height, Justification::centredLeft, true);
  58339. }
  58340. }
  58341. void listBoxItemClicked (int row, const MouseEvent& e)
  58342. {
  58343. selectRow (row);
  58344. if (e.x < getTickX())
  58345. flipEnablement (row);
  58346. }
  58347. void listBoxItemDoubleClicked (int row, const MouseEvent&)
  58348. {
  58349. flipEnablement (row);
  58350. }
  58351. void returnKeyPressed (int row)
  58352. {
  58353. flipEnablement (row);
  58354. }
  58355. void paint (Graphics& g)
  58356. {
  58357. ListBox::paint (g);
  58358. if (items.size() == 0)
  58359. {
  58360. g.setColour (Colours::grey);
  58361. g.setFont (13.0f);
  58362. g.drawText (noItemsMessage,
  58363. 0, 0, getWidth(), getHeight() / 2,
  58364. Justification::centred, true);
  58365. }
  58366. }
  58367. int getBestHeight (int maxHeight)
  58368. {
  58369. return getRowHeight() * jlimit (2, jmax (2, maxHeight / getRowHeight()),
  58370. getNumRows())
  58371. + getOutlineThickness() * 2;
  58372. }
  58373. juce_UseDebuggingNewOperator
  58374. private:
  58375. const AudioIODeviceType::DeviceSetupDetails setup;
  58376. const BoxType type;
  58377. const String noItemsMessage;
  58378. StringArray items;
  58379. void flipEnablement (const int row)
  58380. {
  58381. jassert (type == audioInputType || type == audioOutputType);
  58382. if (((unsigned int) row) < (unsigned int) items.size())
  58383. {
  58384. AudioDeviceManager::AudioDeviceSetup config;
  58385. setup.manager->getAudioDeviceSetup (config);
  58386. if (setup.useStereoPairs)
  58387. {
  58388. BitArray bits;
  58389. BitArray& original = (type == audioInputType ? config.inputChannels
  58390. : config.outputChannels);
  58391. int i;
  58392. for (i = 0; i < 256; i += 2)
  58393. bits.setBit (i / 2, original [i] || original [i + 1]);
  58394. if (type == audioInputType)
  58395. {
  58396. config.useDefaultInputChannels = false;
  58397. flipBit (bits, row, setup.minNumInputChannels / 2, setup.maxNumInputChannels / 2);
  58398. }
  58399. else
  58400. {
  58401. config.useDefaultOutputChannels = false;
  58402. flipBit (bits, row, setup.minNumOutputChannels / 2, setup.maxNumOutputChannels / 2);
  58403. }
  58404. for (i = 0; i < 256; ++i)
  58405. original.setBit (i, bits [i / 2]);
  58406. }
  58407. else
  58408. {
  58409. if (type == audioInputType)
  58410. {
  58411. config.useDefaultInputChannels = false;
  58412. flipBit (config.inputChannels, row, setup.minNumInputChannels, setup.maxNumInputChannels);
  58413. }
  58414. else
  58415. {
  58416. config.useDefaultOutputChannels = false;
  58417. flipBit (config.outputChannels, row, setup.minNumOutputChannels, setup.maxNumOutputChannels);
  58418. }
  58419. }
  58420. String error (setup.manager->setAudioDeviceSetup (config, true));
  58421. if (! error.isEmpty())
  58422. {
  58423. //xxx
  58424. }
  58425. }
  58426. }
  58427. static void flipBit (BitArray& chans, int index, int minNumber, int maxNumber)
  58428. {
  58429. const int numActive = chans.countNumberOfSetBits();
  58430. if (chans [index])
  58431. {
  58432. if (numActive > minNumber)
  58433. chans.setBit (index, false);
  58434. }
  58435. else
  58436. {
  58437. if (numActive >= maxNumber)
  58438. {
  58439. const int firstActiveChan = chans.findNextSetBit();
  58440. chans.setBit (index > firstActiveChan
  58441. ? firstActiveChan : chans.getHighestBit(),
  58442. false);
  58443. }
  58444. chans.setBit (index, true);
  58445. }
  58446. }
  58447. int getTickX() const
  58448. {
  58449. return getRowHeight() + 5;
  58450. }
  58451. ChannelSelectorListBox (const ChannelSelectorListBox&);
  58452. ChannelSelectorListBox& operator= (const ChannelSelectorListBox&);
  58453. };
  58454. private:
  58455. ChannelSelectorListBox* inputChanList;
  58456. ChannelSelectorListBox* outputChanList;
  58457. AudioDeviceSettingsPanel (const AudioDeviceSettingsPanel&);
  58458. AudioDeviceSettingsPanel& operator= (const AudioDeviceSettingsPanel&);
  58459. };
  58460. AudioDeviceSelectorComponent::AudioDeviceSelectorComponent (AudioDeviceManager& deviceManager_,
  58461. const int minInputChannels_,
  58462. const int maxInputChannels_,
  58463. const int minOutputChannels_,
  58464. const int maxOutputChannels_,
  58465. const bool showMidiInputOptions,
  58466. const bool showMidiOutputSelector,
  58467. const bool showChannelsAsStereoPairs_,
  58468. const bool hideAdvancedOptionsWithButton_)
  58469. : deviceManager (deviceManager_),
  58470. deviceTypeDropDown (0),
  58471. deviceTypeDropDownLabel (0),
  58472. audioDeviceSettingsComp (0),
  58473. minOutputChannels (minOutputChannels_),
  58474. maxOutputChannels (maxOutputChannels_),
  58475. minInputChannels (minInputChannels_),
  58476. maxInputChannels (maxInputChannels_),
  58477. showChannelsAsStereoPairs (showChannelsAsStereoPairs_),
  58478. hideAdvancedOptionsWithButton (hideAdvancedOptionsWithButton_)
  58479. {
  58480. jassert (minOutputChannels >= 0 && minOutputChannels <= maxOutputChannels);
  58481. jassert (minInputChannels >= 0 && minInputChannels <= maxInputChannels);
  58482. if (deviceManager_.getAvailableDeviceTypes().size() > 1)
  58483. {
  58484. deviceTypeDropDown = new ComboBox (String::empty);
  58485. for (int i = 0; i < deviceManager_.getAvailableDeviceTypes().size(); ++i)
  58486. {
  58487. deviceTypeDropDown
  58488. ->addItem (deviceManager_.getAvailableDeviceTypes().getUnchecked(i)->getTypeName(),
  58489. i + 1);
  58490. }
  58491. addAndMakeVisible (deviceTypeDropDown);
  58492. deviceTypeDropDown->addListener (this);
  58493. deviceTypeDropDownLabel = new Label (String::empty, TRANS ("audio device type:"));
  58494. deviceTypeDropDownLabel->setJustificationType (Justification::centredRight);
  58495. deviceTypeDropDownLabel->attachToComponent (deviceTypeDropDown, true);
  58496. }
  58497. if (showMidiInputOptions)
  58498. {
  58499. addAndMakeVisible (midiInputsList
  58500. = new MidiInputSelectorComponentListBox (deviceManager,
  58501. TRANS("(no midi inputs available)"),
  58502. 0, 0));
  58503. midiInputsLabel = new Label (String::empty, TRANS ("active midi inputs:"));
  58504. midiInputsLabel->setJustificationType (Justification::topRight);
  58505. midiInputsLabel->attachToComponent (midiInputsList, true);
  58506. }
  58507. else
  58508. {
  58509. midiInputsList = 0;
  58510. midiInputsLabel = 0;
  58511. }
  58512. if (showMidiOutputSelector)
  58513. {
  58514. addAndMakeVisible (midiOutputSelector = new ComboBox (String::empty));
  58515. midiOutputSelector->addListener (this);
  58516. midiOutputLabel = new Label ("lm", TRANS("Midi Output:"));
  58517. midiOutputLabel->attachToComponent (midiOutputSelector, true);
  58518. }
  58519. else
  58520. {
  58521. midiOutputSelector = 0;
  58522. midiOutputLabel = 0;
  58523. }
  58524. deviceManager_.addChangeListener (this);
  58525. changeListenerCallback (0);
  58526. }
  58527. AudioDeviceSelectorComponent::~AudioDeviceSelectorComponent()
  58528. {
  58529. deviceManager.removeChangeListener (this);
  58530. deleteAllChildren();
  58531. }
  58532. void AudioDeviceSelectorComponent::resized()
  58533. {
  58534. const int lx = proportionOfWidth (0.35f);
  58535. const int w = proportionOfWidth (0.4f);
  58536. const int h = 24;
  58537. const int space = 6;
  58538. const int dh = h + space;
  58539. int y = 15;
  58540. if (deviceTypeDropDown != 0)
  58541. {
  58542. deviceTypeDropDown->setBounds (lx, y, proportionOfWidth (0.3f), h);
  58543. y += dh + space * 2;
  58544. }
  58545. if (audioDeviceSettingsComp != 0)
  58546. {
  58547. audioDeviceSettingsComp->setBounds (0, y, getWidth(), audioDeviceSettingsComp->getHeight());
  58548. y += audioDeviceSettingsComp->getHeight() + space;
  58549. }
  58550. if (midiInputsList != 0)
  58551. {
  58552. const int bh = midiInputsList->getBestHeight (jmin (h * 8, getHeight() - y - space - h));
  58553. midiInputsList->setBounds (lx, y, w, bh);
  58554. y += bh + space;
  58555. }
  58556. if (midiOutputSelector != 0)
  58557. midiOutputSelector->setBounds (lx, y, w, h);
  58558. }
  58559. void AudioDeviceSelectorComponent::childBoundsChanged (Component* child)
  58560. {
  58561. if (child == audioDeviceSettingsComp)
  58562. resized();
  58563. }
  58564. void AudioDeviceSelectorComponent::buttonClicked (Button*)
  58565. {
  58566. AudioIODevice* const device = deviceManager.getCurrentAudioDevice();
  58567. if (device != 0 && device->hasControlPanel())
  58568. {
  58569. if (device->showControlPanel())
  58570. deviceManager.restartLastAudioDevice();
  58571. getTopLevelComponent()->toFront (true);
  58572. }
  58573. }
  58574. void AudioDeviceSelectorComponent::comboBoxChanged (ComboBox* comboBoxThatHasChanged)
  58575. {
  58576. if (comboBoxThatHasChanged == deviceTypeDropDown)
  58577. {
  58578. AudioIODeviceType* const type = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown->getSelectedId() - 1];
  58579. if (type != 0)
  58580. {
  58581. deleteAndZero (audioDeviceSettingsComp);
  58582. deviceManager.setCurrentAudioDeviceType (type->getTypeName(), true);
  58583. changeListenerCallback (0); // needed in case the type hasn't actally changed
  58584. }
  58585. }
  58586. else if (comboBoxThatHasChanged == midiOutputSelector)
  58587. {
  58588. deviceManager.setDefaultMidiOutput (midiOutputSelector->getText());
  58589. }
  58590. }
  58591. void AudioDeviceSelectorComponent::changeListenerCallback (void*)
  58592. {
  58593. if (deviceTypeDropDown != 0)
  58594. {
  58595. deviceTypeDropDown->setText (deviceManager.getCurrentAudioDeviceType(), false);
  58596. }
  58597. if (audioDeviceSettingsComp == 0
  58598. || audioDeviceSettingsCompType != deviceManager.getCurrentAudioDeviceType())
  58599. {
  58600. audioDeviceSettingsCompType = deviceManager.getCurrentAudioDeviceType();
  58601. deleteAndZero (audioDeviceSettingsComp);
  58602. AudioIODeviceType* const type
  58603. = deviceManager.getAvailableDeviceTypes() [deviceTypeDropDown == 0
  58604. ? 0 : deviceTypeDropDown->getSelectedId() - 1];
  58605. if (type != 0)
  58606. {
  58607. AudioIODeviceType::DeviceSetupDetails details;
  58608. details.manager = &deviceManager;
  58609. details.minNumInputChannels = minInputChannels;
  58610. details.maxNumInputChannels = maxInputChannels;
  58611. details.minNumOutputChannels = minOutputChannels;
  58612. details.maxNumOutputChannels = maxOutputChannels;
  58613. details.useStereoPairs = showChannelsAsStereoPairs;
  58614. audioDeviceSettingsComp = new AudioDeviceSettingsPanel (type, details, hideAdvancedOptionsWithButton);
  58615. if (audioDeviceSettingsComp != 0)
  58616. {
  58617. addAndMakeVisible (audioDeviceSettingsComp);
  58618. audioDeviceSettingsComp->resized();
  58619. }
  58620. }
  58621. }
  58622. if (midiInputsList != 0)
  58623. {
  58624. midiInputsList->updateContent();
  58625. midiInputsList->repaint();
  58626. }
  58627. if (midiOutputSelector != 0)
  58628. {
  58629. midiOutputSelector->clear();
  58630. const StringArray midiOuts (MidiOutput::getDevices());
  58631. midiOutputSelector->addItem (TRANS("<< none >>"), -1);
  58632. midiOutputSelector->addSeparator();
  58633. for (int i = 0; i < midiOuts.size(); ++i)
  58634. midiOutputSelector->addItem (midiOuts[i], i + 1);
  58635. int current = -1;
  58636. if (deviceManager.getDefaultMidiOutput() != 0)
  58637. current = 1 + midiOuts.indexOf (deviceManager.getDefaultMidiOutputName());
  58638. midiOutputSelector->setSelectedId (current, true);
  58639. }
  58640. resized();
  58641. }
  58642. END_JUCE_NAMESPACE
  58643. /*** End of inlined file: juce_AudioDeviceSelectorComponent.cpp ***/
  58644. /*** Start of inlined file: juce_BubbleComponent.cpp ***/
  58645. BEGIN_JUCE_NAMESPACE
  58646. BubbleComponent::BubbleComponent()
  58647. : side (0),
  58648. allowablePlacements (above | below | left | right),
  58649. arrowTipX (0.0f),
  58650. arrowTipY (0.0f)
  58651. {
  58652. setInterceptsMouseClicks (false, false);
  58653. shadow.setShadowProperties (5.0f, 0.35f, 0, 0);
  58654. setComponentEffect (&shadow);
  58655. }
  58656. BubbleComponent::~BubbleComponent()
  58657. {
  58658. }
  58659. void BubbleComponent::paint (Graphics& g)
  58660. {
  58661. int x = content.getX();
  58662. int y = content.getY();
  58663. int w = content.getWidth();
  58664. int h = content.getHeight();
  58665. int cw, ch;
  58666. getContentSize (cw, ch);
  58667. if (side == 3)
  58668. x += w - cw;
  58669. else if (side != 1)
  58670. x += (w - cw) / 2;
  58671. w = cw;
  58672. if (side == 2)
  58673. y += h - ch;
  58674. else if (side != 0)
  58675. y += (h - ch) / 2;
  58676. h = ch;
  58677. getLookAndFeel().drawBubble (g, arrowTipX, arrowTipY,
  58678. (float) x, (float) y,
  58679. (float) w, (float) h);
  58680. const int cx = x + (w - cw) / 2;
  58681. const int cy = y + (h - ch) / 2;
  58682. const int indent = 3;
  58683. g.setOrigin (cx + indent, cy + indent);
  58684. g.reduceClipRegion (0, 0, cw - indent * 2, ch - indent * 2);
  58685. paintContent (g, cw - indent * 2, ch - indent * 2);
  58686. }
  58687. void BubbleComponent::setAllowedPlacement (const int newPlacement)
  58688. {
  58689. allowablePlacements = newPlacement;
  58690. }
  58691. void BubbleComponent::setPosition (Component* componentToPointTo)
  58692. {
  58693. jassert (componentToPointTo->isValidComponent());
  58694. Point<int> pos;
  58695. if (getParentComponent() != 0)
  58696. pos = componentToPointTo->relativePositionToOtherComponent (getParentComponent(), pos);
  58697. else
  58698. pos = componentToPointTo->relativePositionToGlobal (pos);
  58699. setPosition (Rectangle<int> (pos.getX(), pos.getY(), componentToPointTo->getWidth(), componentToPointTo->getHeight()));
  58700. }
  58701. void BubbleComponent::setPosition (const int arrowTipX_,
  58702. const int arrowTipY_)
  58703. {
  58704. setPosition (Rectangle<int> (arrowTipX_, arrowTipY_, 1, 1));
  58705. }
  58706. void BubbleComponent::setPosition (const Rectangle<int>& rectangleToPointTo)
  58707. {
  58708. Rectangle<int> availableSpace;
  58709. if (getParentComponent() != 0)
  58710. {
  58711. availableSpace.setSize (getParentComponent()->getWidth(),
  58712. getParentComponent()->getHeight());
  58713. }
  58714. else
  58715. {
  58716. availableSpace = getParentMonitorArea();
  58717. }
  58718. int x = 0;
  58719. int y = 0;
  58720. int w = 150;
  58721. int h = 30;
  58722. getContentSize (w, h);
  58723. w += 30;
  58724. h += 30;
  58725. const float edgeIndent = 2.0f;
  58726. const int arrowLength = jmin (10, h / 3, w / 3);
  58727. int spaceAbove = ((allowablePlacements & above) != 0) ? jmax (0, rectangleToPointTo.getY() - availableSpace.getY()) : -1;
  58728. int spaceBelow = ((allowablePlacements & below) != 0) ? jmax (0, availableSpace.getBottom() - rectangleToPointTo.getBottom()) : -1;
  58729. int spaceLeft = ((allowablePlacements & left) != 0) ? jmax (0, rectangleToPointTo.getX() - availableSpace.getX()) : -1;
  58730. int spaceRight = ((allowablePlacements & right) != 0) ? jmax (0, availableSpace.getRight() - rectangleToPointTo.getRight()) : -1;
  58731. // look at whether the component is elongated, and if so, try to position next to its longer dimension.
  58732. if (rectangleToPointTo.getWidth() > rectangleToPointTo.getHeight() * 2
  58733. && (spaceAbove > h + 20 || spaceBelow > h + 20))
  58734. {
  58735. spaceLeft = spaceRight = 0;
  58736. }
  58737. else if (rectangleToPointTo.getWidth() < rectangleToPointTo.getHeight() / 2
  58738. && (spaceLeft > w + 20 || spaceRight > w + 20))
  58739. {
  58740. spaceAbove = spaceBelow = 0;
  58741. }
  58742. if (jmax (spaceAbove, spaceBelow) >= jmax (spaceLeft, spaceRight))
  58743. {
  58744. x = rectangleToPointTo.getX() + (rectangleToPointTo.getWidth() - w) / 2;
  58745. arrowTipX = w * 0.5f;
  58746. content.setSize (w, h - arrowLength);
  58747. if (spaceAbove >= spaceBelow)
  58748. {
  58749. // above
  58750. y = rectangleToPointTo.getY() - h;
  58751. content.setPosition (0, 0);
  58752. arrowTipY = h - edgeIndent;
  58753. side = 2;
  58754. }
  58755. else
  58756. {
  58757. // below
  58758. y = rectangleToPointTo.getBottom();
  58759. content.setPosition (0, arrowLength);
  58760. arrowTipY = edgeIndent;
  58761. side = 0;
  58762. }
  58763. }
  58764. else
  58765. {
  58766. y = rectangleToPointTo.getY() + (rectangleToPointTo.getHeight() - h) / 2;
  58767. arrowTipY = h * 0.5f;
  58768. content.setSize (w - arrowLength, h);
  58769. if (spaceLeft > spaceRight)
  58770. {
  58771. // on the left
  58772. x = rectangleToPointTo.getX() - w;
  58773. content.setPosition (0, 0);
  58774. arrowTipX = w - edgeIndent;
  58775. side = 3;
  58776. }
  58777. else
  58778. {
  58779. // on the right
  58780. x = rectangleToPointTo.getRight();
  58781. content.setPosition (arrowLength, 0);
  58782. arrowTipX = edgeIndent;
  58783. side = 1;
  58784. }
  58785. }
  58786. setBounds (x, y, w, h);
  58787. }
  58788. END_JUCE_NAMESPACE
  58789. /*** End of inlined file: juce_BubbleComponent.cpp ***/
  58790. /*** Start of inlined file: juce_BubbleMessageComponent.cpp ***/
  58791. BEGIN_JUCE_NAMESPACE
  58792. BubbleMessageComponent::BubbleMessageComponent (int fadeOutLengthMs)
  58793. : fadeOutLength (fadeOutLengthMs),
  58794. deleteAfterUse (false)
  58795. {
  58796. }
  58797. BubbleMessageComponent::~BubbleMessageComponent()
  58798. {
  58799. fadeOutComponent (fadeOutLength);
  58800. }
  58801. void BubbleMessageComponent::showAt (int x, int y,
  58802. const String& text,
  58803. const int numMillisecondsBeforeRemoving,
  58804. const bool removeWhenMouseClicked,
  58805. const bool deleteSelfAfterUse)
  58806. {
  58807. textLayout.clear();
  58808. textLayout.setText (text, Font (14.0f));
  58809. textLayout.layout (256, Justification::centredLeft, true);
  58810. setPosition (x, y);
  58811. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58812. }
  58813. void BubbleMessageComponent::showAt (Component* const component,
  58814. const String& text,
  58815. const int numMillisecondsBeforeRemoving,
  58816. const bool removeWhenMouseClicked,
  58817. const bool deleteSelfAfterUse)
  58818. {
  58819. textLayout.clear();
  58820. textLayout.setText (text, Font (14.0f));
  58821. textLayout.layout (256, Justification::centredLeft, true);
  58822. setPosition (component);
  58823. init (numMillisecondsBeforeRemoving, removeWhenMouseClicked, deleteSelfAfterUse);
  58824. }
  58825. void BubbleMessageComponent::init (const int numMillisecondsBeforeRemoving,
  58826. const bool removeWhenMouseClicked,
  58827. const bool deleteSelfAfterUse)
  58828. {
  58829. setVisible (true);
  58830. deleteAfterUse = deleteSelfAfterUse;
  58831. if (numMillisecondsBeforeRemoving > 0)
  58832. expiryTime = Time::getMillisecondCounter() + numMillisecondsBeforeRemoving;
  58833. else
  58834. expiryTime = 0;
  58835. startTimer (77);
  58836. mouseClickCounter = Desktop::getInstance().getMouseButtonClickCounter();
  58837. if (! (removeWhenMouseClicked && isShowing()))
  58838. mouseClickCounter += 0xfffff;
  58839. repaint();
  58840. }
  58841. void BubbleMessageComponent::getContentSize (int& w, int& h)
  58842. {
  58843. w = textLayout.getWidth() + 16;
  58844. h = textLayout.getHeight() + 16;
  58845. }
  58846. void BubbleMessageComponent::paintContent (Graphics& g, int w, int h)
  58847. {
  58848. g.setColour (findColour (TooltipWindow::textColourId));
  58849. textLayout.drawWithin (g, 0, 0, w, h, Justification::centred);
  58850. }
  58851. void BubbleMessageComponent::timerCallback()
  58852. {
  58853. if (Desktop::getInstance().getMouseButtonClickCounter() > mouseClickCounter)
  58854. {
  58855. stopTimer();
  58856. setVisible (false);
  58857. if (deleteAfterUse)
  58858. delete this;
  58859. }
  58860. else if (expiryTime != 0 && Time::getMillisecondCounter() > expiryTime)
  58861. {
  58862. stopTimer();
  58863. fadeOutComponent (fadeOutLength);
  58864. if (deleteAfterUse)
  58865. delete this;
  58866. }
  58867. }
  58868. END_JUCE_NAMESPACE
  58869. /*** End of inlined file: juce_BubbleMessageComponent.cpp ***/
  58870. /*** Start of inlined file: juce_ColourSelector.cpp ***/
  58871. BEGIN_JUCE_NAMESPACE
  58872. static const int swatchesPerRow = 8;
  58873. static const int swatchHeight = 22;
  58874. class ColourComponentSlider : public Slider
  58875. {
  58876. public:
  58877. ColourComponentSlider (const String& name)
  58878. : Slider (name)
  58879. {
  58880. setRange (0.0, 255.0, 1.0);
  58881. }
  58882. ~ColourComponentSlider()
  58883. {
  58884. }
  58885. const String getTextFromValue (double value)
  58886. {
  58887. return String::formatted (T("%02X"), (int) value);
  58888. }
  58889. double getValueFromText (const String& text)
  58890. {
  58891. return (double) text.getHexValue32();
  58892. }
  58893. private:
  58894. ColourComponentSlider (const ColourComponentSlider&);
  58895. ColourComponentSlider& operator= (const ColourComponentSlider&);
  58896. };
  58897. class ColourSpaceMarker : public Component
  58898. {
  58899. public:
  58900. ColourSpaceMarker()
  58901. {
  58902. setInterceptsMouseClicks (false, false);
  58903. }
  58904. ~ColourSpaceMarker()
  58905. {
  58906. }
  58907. void paint (Graphics& g)
  58908. {
  58909. g.setColour (Colour::greyLevel (0.1f));
  58910. g.drawEllipse (1.0f, 1.0f, getWidth() - 2.0f, getHeight() - 2.0f, 1.0f);
  58911. g.setColour (Colour::greyLevel (0.9f));
  58912. g.drawEllipse (2.0f, 2.0f, getWidth() - 4.0f, getHeight() - 4.0f, 1.0f);
  58913. }
  58914. private:
  58915. ColourSpaceMarker (const ColourSpaceMarker&);
  58916. ColourSpaceMarker& operator= (const ColourSpaceMarker&);
  58917. };
  58918. class ColourSpaceView : public Component
  58919. {
  58920. ColourSelector* const owner;
  58921. float& h;
  58922. float& s;
  58923. float& v;
  58924. float lastHue;
  58925. ColourSpaceMarker* marker;
  58926. const int edge;
  58927. public:
  58928. ColourSpaceView (ColourSelector* owner_,
  58929. float& h_, float& s_, float& v_,
  58930. const int edgeSize)
  58931. : owner (owner_),
  58932. h (h_), s (s_), v (v_),
  58933. lastHue (0.0f),
  58934. edge (edgeSize)
  58935. {
  58936. addAndMakeVisible (marker = new ColourSpaceMarker());
  58937. setMouseCursor (MouseCursor::CrosshairCursor);
  58938. }
  58939. ~ColourSpaceView()
  58940. {
  58941. deleteAllChildren();
  58942. }
  58943. void paint (Graphics& g)
  58944. {
  58945. if (colours == 0)
  58946. {
  58947. const int width = getWidth() / 2;
  58948. const int height = getHeight() / 2;
  58949. colours = new Image (Image::RGB, width, height, false);
  58950. Image::BitmapData pixels (*colours, 0, 0, width, height, true);
  58951. for (int y = 0; y < height; ++y)
  58952. {
  58953. const float v = 1.0f - y / (float) height;
  58954. for (int x = 0; x < width; ++x)
  58955. {
  58956. const float s = x / (float) width;
  58957. const Colour col (h, s, v, 1.0f);
  58958. PixelRGB* const pix = (PixelRGB*) pixels.getPixelPointer (x, y);
  58959. pix->set (col.getPixelARGB());
  58960. }
  58961. }
  58962. }
  58963. g.setOpacity (1.0f);
  58964. g.drawImage (colours, edge, edge, getWidth() - edge * 2, getHeight() - edge * 2,
  58965. 0, 0, colours->getWidth(), colours->getHeight());
  58966. }
  58967. void mouseDown (const MouseEvent& e)
  58968. {
  58969. mouseDrag (e);
  58970. }
  58971. void mouseDrag (const MouseEvent& e)
  58972. {
  58973. const float s = (e.x - edge) / (float) (getWidth() - edge * 2);
  58974. const float v = 1.0f - (e.y - edge) / (float) (getHeight() - edge * 2);
  58975. owner->setSV (s, v);
  58976. }
  58977. void updateIfNeeded()
  58978. {
  58979. if (lastHue != h)
  58980. {
  58981. lastHue = h;
  58982. colours = 0;
  58983. repaint();
  58984. }
  58985. updateMarker();
  58986. }
  58987. void resized()
  58988. {
  58989. colours = 0;
  58990. updateMarker();
  58991. }
  58992. private:
  58993. ScopedPointer <Image> colours;
  58994. void updateMarker() const throw()
  58995. {
  58996. marker->setBounds (roundToInt ((getWidth() - edge * 2) * s),
  58997. roundToInt ((getHeight() - edge * 2) * (1.0f - v)),
  58998. edge * 2, edge * 2);
  58999. }
  59000. ColourSpaceView (const ColourSpaceView&);
  59001. ColourSpaceView& operator= (const ColourSpaceView&);
  59002. };
  59003. class HueSelectorMarker : public Component
  59004. {
  59005. public:
  59006. HueSelectorMarker()
  59007. {
  59008. setInterceptsMouseClicks (false, false);
  59009. }
  59010. ~HueSelectorMarker()
  59011. {
  59012. }
  59013. void paint (Graphics& g)
  59014. {
  59015. Path p;
  59016. p.addTriangle (1.0f, 1.0f,
  59017. getWidth() * 0.3f, getHeight() * 0.5f,
  59018. 1.0f, getHeight() - 1.0f);
  59019. p.addTriangle (getWidth() - 1.0f, 1.0f,
  59020. getWidth() * 0.7f, getHeight() * 0.5f,
  59021. getWidth() - 1.0f, getHeight() - 1.0f);
  59022. g.setColour (Colours::white.withAlpha (0.75f));
  59023. g.fillPath (p);
  59024. g.setColour (Colours::black.withAlpha (0.75f));
  59025. g.strokePath (p, PathStrokeType (1.2f));
  59026. }
  59027. private:
  59028. HueSelectorMarker (const HueSelectorMarker&);
  59029. HueSelectorMarker& operator= (const HueSelectorMarker&);
  59030. };
  59031. class HueSelectorComp : public Component
  59032. {
  59033. public:
  59034. HueSelectorComp (ColourSelector* owner_,
  59035. float& h_, float& s_, float& v_,
  59036. const int edgeSize)
  59037. : owner (owner_),
  59038. h (h_), s (s_), v (v_),
  59039. lastHue (0.0f),
  59040. edge (edgeSize)
  59041. {
  59042. addAndMakeVisible (marker = new HueSelectorMarker());
  59043. }
  59044. ~HueSelectorComp()
  59045. {
  59046. deleteAllChildren();
  59047. }
  59048. void paint (Graphics& g)
  59049. {
  59050. const float yScale = 1.0f / (getHeight() - edge * 2);
  59051. const Rectangle<int> clip (g.getClipBounds());
  59052. for (int y = jmin (clip.getBottom(), getHeight() - edge); --y >= jmax (edge, clip.getY());)
  59053. {
  59054. g.setColour (Colour ((y - edge) * yScale, 1.0f, 1.0f, 1.0f));
  59055. g.fillRect (edge, y, getWidth() - edge * 2, 1);
  59056. }
  59057. }
  59058. void resized()
  59059. {
  59060. marker->setBounds (0, roundToInt ((getHeight() - edge * 2) * h),
  59061. getWidth(), edge * 2);
  59062. }
  59063. void mouseDown (const MouseEvent& e)
  59064. {
  59065. mouseDrag (e);
  59066. }
  59067. void mouseDrag (const MouseEvent& e)
  59068. {
  59069. const float hue = (e.y - edge) / (float) (getHeight() - edge * 2);
  59070. owner->setHue (hue);
  59071. }
  59072. void updateIfNeeded()
  59073. {
  59074. resized();
  59075. }
  59076. private:
  59077. ColourSelector* const owner;
  59078. float& h;
  59079. float& s;
  59080. float& v;
  59081. float lastHue;
  59082. HueSelectorMarker* marker;
  59083. const int edge;
  59084. HueSelectorComp (const HueSelectorComp&);
  59085. HueSelectorComp& operator= (const HueSelectorComp&);
  59086. };
  59087. class ColourSelector::SwatchComponent : public Component
  59088. {
  59089. public:
  59090. SwatchComponent (ColourSelector* owner_, int index_)
  59091. : owner (owner_),
  59092. index (index_)
  59093. {
  59094. }
  59095. ~SwatchComponent()
  59096. {
  59097. }
  59098. void paint (Graphics& g)
  59099. {
  59100. const Colour colour (owner->getSwatchColour (index));
  59101. g.fillCheckerBoard (0, 0, getWidth(), getHeight(),
  59102. 6, 6,
  59103. Colour (0xffdddddd).overlaidWith (colour),
  59104. Colour (0xffffffff).overlaidWith (colour));
  59105. }
  59106. void mouseDown (const MouseEvent&)
  59107. {
  59108. PopupMenu m;
  59109. m.addItem (1, TRANS("Use this swatch as the current colour"));
  59110. m.addSeparator();
  59111. m.addItem (2, TRANS("Set this swatch to the current colour"));
  59112. const int r = m.showAt (this);
  59113. if (r == 1)
  59114. {
  59115. owner->setCurrentColour (owner->getSwatchColour (index));
  59116. }
  59117. else if (r == 2)
  59118. {
  59119. if (owner->getSwatchColour (index) != owner->getCurrentColour())
  59120. {
  59121. owner->setSwatchColour (index, owner->getCurrentColour());
  59122. repaint();
  59123. }
  59124. }
  59125. }
  59126. private:
  59127. ColourSelector* const owner;
  59128. const int index;
  59129. SwatchComponent (const SwatchComponent&);
  59130. SwatchComponent& operator= (const SwatchComponent&);
  59131. };
  59132. ColourSelector::ColourSelector (const int flags_,
  59133. const int edgeGap_,
  59134. const int gapAroundColourSpaceComponent)
  59135. : colour (Colours::white),
  59136. flags (flags_),
  59137. topSpace (0),
  59138. edgeGap (edgeGap_)
  59139. {
  59140. // not much point having a selector with no components in it!
  59141. jassert ((flags_ & (showColourAtTop | showSliders | showColourspace)) != 0);
  59142. updateHSV();
  59143. if ((flags & showSliders) != 0)
  59144. {
  59145. addAndMakeVisible (sliders[0] = new ColourComponentSlider (TRANS ("red")));
  59146. addAndMakeVisible (sliders[1] = new ColourComponentSlider (TRANS ("green")));
  59147. addAndMakeVisible (sliders[2] = new ColourComponentSlider (TRANS ("blue")));
  59148. addChildComponent (sliders[3] = new ColourComponentSlider (TRANS ("alpha")));
  59149. sliders[3]->setVisible ((flags & showAlphaChannel) != 0);
  59150. for (int i = 4; --i >= 0;)
  59151. sliders[i]->addListener (this);
  59152. }
  59153. else
  59154. {
  59155. zeromem (sliders, sizeof (sliders));
  59156. }
  59157. if ((flags & showColourspace) != 0)
  59158. {
  59159. addAndMakeVisible (colourSpace = new ColourSpaceView (this, h, s, v, gapAroundColourSpaceComponent));
  59160. addAndMakeVisible (hueSelector = new HueSelectorComp (this, h, s, v, gapAroundColourSpaceComponent));
  59161. }
  59162. else
  59163. {
  59164. colourSpace = 0;
  59165. hueSelector = 0;
  59166. }
  59167. update();
  59168. }
  59169. ColourSelector::~ColourSelector()
  59170. {
  59171. dispatchPendingMessages();
  59172. swatchComponents.clear();
  59173. deleteAllChildren();
  59174. }
  59175. const Colour ColourSelector::getCurrentColour() const
  59176. {
  59177. return ((flags & showAlphaChannel) != 0) ? colour
  59178. : colour.withAlpha ((uint8) 0xff);
  59179. }
  59180. void ColourSelector::setCurrentColour (const Colour& c)
  59181. {
  59182. if (c != colour)
  59183. {
  59184. colour = ((flags & showAlphaChannel) != 0) ? c : c.withAlpha ((uint8) 0xff);
  59185. updateHSV();
  59186. update();
  59187. }
  59188. }
  59189. void ColourSelector::setHue (float newH)
  59190. {
  59191. newH = jlimit (0.0f, 1.0f, newH);
  59192. if (h != newH)
  59193. {
  59194. h = newH;
  59195. colour = Colour (h, s, v, colour.getFloatAlpha());
  59196. update();
  59197. }
  59198. }
  59199. void ColourSelector::setSV (float newS, float newV)
  59200. {
  59201. newS = jlimit (0.0f, 1.0f, newS);
  59202. newV = jlimit (0.0f, 1.0f, newV);
  59203. if (s != newS || v != newV)
  59204. {
  59205. s = newS;
  59206. v = newV;
  59207. colour = Colour (h, s, v, colour.getFloatAlpha());
  59208. update();
  59209. }
  59210. }
  59211. void ColourSelector::updateHSV()
  59212. {
  59213. colour.getHSB (h, s, v);
  59214. }
  59215. void ColourSelector::update()
  59216. {
  59217. if (sliders[0] != 0)
  59218. {
  59219. sliders[0]->setValue ((int) colour.getRed());
  59220. sliders[1]->setValue ((int) colour.getGreen());
  59221. sliders[2]->setValue ((int) colour.getBlue());
  59222. sliders[3]->setValue ((int) colour.getAlpha());
  59223. }
  59224. if (colourSpace != 0)
  59225. {
  59226. ((ColourSpaceView*) colourSpace)->updateIfNeeded();
  59227. ((HueSelectorComp*) hueSelector)->updateIfNeeded();
  59228. }
  59229. if ((flags & showColourAtTop) != 0)
  59230. repaint (0, edgeGap, getWidth(), topSpace - edgeGap);
  59231. sendChangeMessage (this);
  59232. }
  59233. void ColourSelector::paint (Graphics& g)
  59234. {
  59235. g.fillAll (findColour (backgroundColourId));
  59236. if ((flags & showColourAtTop) != 0)
  59237. {
  59238. const Colour colour (getCurrentColour());
  59239. g.fillCheckerBoard (edgeGap, edgeGap, getWidth() - edgeGap - edgeGap, topSpace - edgeGap - edgeGap,
  59240. 10, 10,
  59241. Colour (0xffdddddd).overlaidWith (colour),
  59242. Colour (0xffffffff).overlaidWith (colour));
  59243. g.setColour (Colours::white.overlaidWith (colour).contrasting());
  59244. g.setFont (14.0f, true);
  59245. g.drawText (((flags & showAlphaChannel) != 0)
  59246. ? String::formatted (T("#%02X%02X%02X%02X"),
  59247. (int) colour.getAlpha(),
  59248. (int) colour.getRed(),
  59249. (int) colour.getGreen(),
  59250. (int) colour.getBlue())
  59251. : String::formatted (T("#%02X%02X%02X"),
  59252. (int) colour.getRed(),
  59253. (int) colour.getGreen(),
  59254. (int) colour.getBlue()),
  59255. 0, edgeGap, getWidth(), topSpace - edgeGap * 2,
  59256. Justification::centred, false);
  59257. }
  59258. if ((flags & showSliders) != 0)
  59259. {
  59260. g.setColour (findColour (labelTextColourId));
  59261. g.setFont (11.0f);
  59262. for (int i = 4; --i >= 0;)
  59263. {
  59264. if (sliders[i]->isVisible())
  59265. g.drawText (sliders[i]->getName() + T(":"),
  59266. 0, sliders[i]->getY(),
  59267. sliders[i]->getX() - 8, sliders[i]->getHeight(),
  59268. Justification::centredRight, false);
  59269. }
  59270. }
  59271. }
  59272. void ColourSelector::resized()
  59273. {
  59274. const int numSliders = ((flags & showAlphaChannel) != 0) ? 4 : 3;
  59275. const int numSwatches = getNumSwatches();
  59276. const int swatchSpace = numSwatches > 0 ? edgeGap + swatchHeight * ((numSwatches + 7) / swatchesPerRow) : 0;
  59277. const int sliderSpace = ((flags & showSliders) != 0) ? jmin (22 * numSliders + edgeGap, proportionOfHeight (0.3f)) : 0;
  59278. topSpace = ((flags & showColourAtTop) != 0) ? jmin (30 + edgeGap * 2, proportionOfHeight (0.2f)) : edgeGap;
  59279. int y = topSpace;
  59280. if ((flags & showColourspace) != 0)
  59281. {
  59282. const int hueWidth = jmin (50, proportionOfWidth (0.15f));
  59283. colourSpace->setBounds (edgeGap, y,
  59284. getWidth() - hueWidth - edgeGap - 4,
  59285. getHeight() - topSpace - sliderSpace - swatchSpace - edgeGap);
  59286. hueSelector->setBounds (colourSpace->getRight() + 4, y,
  59287. getWidth() - edgeGap - (colourSpace->getRight() + 4),
  59288. colourSpace->getHeight());
  59289. y = getHeight() - sliderSpace - swatchSpace - edgeGap;
  59290. }
  59291. if ((flags & showSliders) != 0)
  59292. {
  59293. const int sliderHeight = jmax (4, sliderSpace / numSliders);
  59294. for (int i = 0; i < numSliders; ++i)
  59295. {
  59296. sliders[i]->setBounds (proportionOfWidth (0.2f), y,
  59297. proportionOfWidth (0.72f), sliderHeight - 2);
  59298. y += sliderHeight;
  59299. }
  59300. }
  59301. if (numSwatches > 0)
  59302. {
  59303. const int startX = 8;
  59304. const int xGap = 4;
  59305. const int yGap = 4;
  59306. const int swatchWidth = (getWidth() - startX * 2) / swatchesPerRow;
  59307. y += edgeGap;
  59308. if (swatchComponents.size() != numSwatches)
  59309. {
  59310. swatchComponents.clear();
  59311. for (int i = 0; i < numSwatches; ++i)
  59312. {
  59313. SwatchComponent* const sc = new SwatchComponent (this, i);
  59314. swatchComponents.add (sc);
  59315. addAndMakeVisible (sc);
  59316. }
  59317. }
  59318. int x = startX;
  59319. for (int i = 0; i < swatchComponents.size(); ++i)
  59320. {
  59321. SwatchComponent* const sc = swatchComponents.getUnchecked(i);
  59322. sc->setBounds (x + xGap / 2,
  59323. y + yGap / 2,
  59324. swatchWidth - xGap,
  59325. swatchHeight - yGap);
  59326. if (((i + 1) % swatchesPerRow) == 0)
  59327. {
  59328. x = startX;
  59329. y += swatchHeight;
  59330. }
  59331. else
  59332. {
  59333. x += swatchWidth;
  59334. }
  59335. }
  59336. }
  59337. }
  59338. void ColourSelector::sliderValueChanged (Slider*)
  59339. {
  59340. if (sliders[0] != 0)
  59341. setCurrentColour (Colour ((uint8) sliders[0]->getValue(),
  59342. (uint8) sliders[1]->getValue(),
  59343. (uint8) sliders[2]->getValue(),
  59344. (uint8) sliders[3]->getValue()));
  59345. }
  59346. int ColourSelector::getNumSwatches() const
  59347. {
  59348. return 0;
  59349. }
  59350. const Colour ColourSelector::getSwatchColour (const int) const
  59351. {
  59352. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59353. return Colours::black;
  59354. }
  59355. void ColourSelector::setSwatchColour (const int, const Colour&) const
  59356. {
  59357. jassertfalse // if you've overridden getNumSwatches(), you also need to implement this method
  59358. }
  59359. END_JUCE_NAMESPACE
  59360. /*** End of inlined file: juce_ColourSelector.cpp ***/
  59361. /*** Start of inlined file: juce_DropShadower.cpp ***/
  59362. BEGIN_JUCE_NAMESPACE
  59363. class ShadowWindow : public Component
  59364. {
  59365. Component* owner;
  59366. Image** shadowImageSections;
  59367. const int type; // 0 = left, 1 = right, 2 = top, 3 = bottom. left + right are full-height
  59368. public:
  59369. ShadowWindow (Component* const owner_,
  59370. const int type_,
  59371. Image** const shadowImageSections_)
  59372. : owner (owner_),
  59373. shadowImageSections (shadowImageSections_),
  59374. type (type_)
  59375. {
  59376. setInterceptsMouseClicks (false, false);
  59377. if (owner_->isOnDesktop())
  59378. {
  59379. setSize (1, 1); // to keep the OS happy by not having zero-size windows
  59380. addToDesktop (ComponentPeer::windowIgnoresMouseClicks
  59381. | ComponentPeer::windowIsTemporary
  59382. | ComponentPeer::windowIgnoresKeyPresses);
  59383. }
  59384. else if (owner_->getParentComponent() != 0)
  59385. {
  59386. owner_->getParentComponent()->addChildComponent (this);
  59387. }
  59388. }
  59389. ~ShadowWindow()
  59390. {
  59391. }
  59392. void paint (Graphics& g)
  59393. {
  59394. Image* const topLeft = shadowImageSections [type * 3];
  59395. Image* const bottomRight = shadowImageSections [type * 3 + 1];
  59396. Image* const filler = shadowImageSections [type * 3 + 2];
  59397. g.setOpacity (1.0f);
  59398. if (type < 2)
  59399. {
  59400. int imH = jmin (topLeft->getHeight(), getHeight() / 2);
  59401. g.drawImage (topLeft,
  59402. 0, 0, topLeft->getWidth(), imH,
  59403. 0, 0, topLeft->getWidth(), imH);
  59404. imH = jmin (bottomRight->getHeight(), getHeight() - getHeight() / 2);
  59405. g.drawImage (bottomRight,
  59406. 0, getHeight() - imH, bottomRight->getWidth(), imH,
  59407. 0, bottomRight->getHeight() - imH, bottomRight->getWidth(), imH);
  59408. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59409. g.fillRect (0, topLeft->getHeight(), getWidth(), getHeight() - (topLeft->getHeight() + bottomRight->getHeight()));
  59410. }
  59411. else
  59412. {
  59413. int imW = jmin (topLeft->getWidth(), getWidth() / 2);
  59414. g.drawImage (topLeft,
  59415. 0, 0, imW, topLeft->getHeight(),
  59416. 0, 0, imW, topLeft->getHeight());
  59417. imW = jmin (bottomRight->getWidth(), getWidth() - getWidth() / 2);
  59418. g.drawImage (bottomRight,
  59419. getWidth() - imW, 0, imW, bottomRight->getHeight(),
  59420. bottomRight->getWidth() - imW, 0, imW, bottomRight->getHeight());
  59421. g.setTiledImageFill (*filler, 0, 0, 1.0f);
  59422. g.fillRect (topLeft->getWidth(), 0, getWidth() - (topLeft->getWidth() + bottomRight->getWidth()), getHeight());
  59423. }
  59424. }
  59425. void resized()
  59426. {
  59427. repaint(); // (needed for correct repainting)
  59428. }
  59429. private:
  59430. ShadowWindow (const ShadowWindow&);
  59431. ShadowWindow& operator= (const ShadowWindow&);
  59432. };
  59433. DropShadower::DropShadower (const float alpha_,
  59434. const int xOffset_,
  59435. const int yOffset_,
  59436. const float blurRadius_)
  59437. : owner (0),
  59438. numShadows (0),
  59439. shadowEdge (jmax (xOffset_, yOffset_) + (int) blurRadius_),
  59440. xOffset (xOffset_),
  59441. yOffset (yOffset_),
  59442. alpha (alpha_),
  59443. blurRadius (blurRadius_),
  59444. inDestructor (false),
  59445. reentrant (false)
  59446. {
  59447. }
  59448. DropShadower::~DropShadower()
  59449. {
  59450. if (owner != 0)
  59451. owner->removeComponentListener (this);
  59452. inDestructor = true;
  59453. deleteShadowWindows();
  59454. }
  59455. void DropShadower::deleteShadowWindows()
  59456. {
  59457. if (numShadows > 0)
  59458. {
  59459. int i;
  59460. for (i = numShadows; --i >= 0;)
  59461. delete shadowWindows[i];
  59462. for (i = 12; --i >= 0;)
  59463. delete shadowImageSections[i];
  59464. numShadows = 0;
  59465. }
  59466. }
  59467. void DropShadower::setOwner (Component* componentToFollow)
  59468. {
  59469. if (componentToFollow != owner)
  59470. {
  59471. if (owner != 0)
  59472. owner->removeComponentListener (this);
  59473. // (the component can't be null)
  59474. jassert (componentToFollow != 0);
  59475. owner = componentToFollow;
  59476. jassert (owner != 0);
  59477. jassert (owner->isOpaque()); // doesn't work properly for semi-transparent comps!
  59478. owner->addComponentListener (this);
  59479. updateShadows();
  59480. }
  59481. }
  59482. void DropShadower::componentMovedOrResized (Component&, bool /*wasMoved*/, bool /*wasResized*/)
  59483. {
  59484. updateShadows();
  59485. }
  59486. void DropShadower::componentBroughtToFront (Component&)
  59487. {
  59488. bringShadowWindowsToFront();
  59489. }
  59490. void DropShadower::componentChildrenChanged (Component&)
  59491. {
  59492. }
  59493. void DropShadower::componentParentHierarchyChanged (Component&)
  59494. {
  59495. deleteShadowWindows();
  59496. updateShadows();
  59497. }
  59498. void DropShadower::componentVisibilityChanged (Component&)
  59499. {
  59500. updateShadows();
  59501. }
  59502. void DropShadower::updateShadows()
  59503. {
  59504. if (reentrant || inDestructor || (owner == 0))
  59505. return;
  59506. reentrant = true;
  59507. ComponentPeer* const nw = owner->getPeer();
  59508. const bool isOwnerVisible = owner->isVisible()
  59509. && (nw == 0 || ! nw->isMinimised());
  59510. const bool createShadowWindows = numShadows == 0
  59511. && owner->getWidth() > 0
  59512. && owner->getHeight() > 0
  59513. && isOwnerVisible
  59514. && (Desktop::canUseSemiTransparentWindows()
  59515. || owner->getParentComponent() != 0);
  59516. if (createShadowWindows)
  59517. {
  59518. // keep a cached version of the image to save doing the gaussian too often
  59519. String imageId;
  59520. imageId << shadowEdge << T(',')
  59521. << xOffset << T(',')
  59522. << yOffset << T(',')
  59523. << alpha;
  59524. const int hash = imageId.hashCode();
  59525. Image* bigIm = ImageCache::getFromHashCode (hash);
  59526. if (bigIm == 0)
  59527. {
  59528. bigIm = Image::createNativeImage (Image::ARGB, shadowEdge * 5, shadowEdge * 5, true);
  59529. Graphics bigG (*bigIm);
  59530. bigG.setColour (Colours::black.withAlpha (alpha));
  59531. bigG.fillRect (shadowEdge + xOffset,
  59532. shadowEdge + yOffset,
  59533. bigIm->getWidth() - (shadowEdge * 2),
  59534. bigIm->getHeight() - (shadowEdge * 2));
  59535. ImageConvolutionKernel blurKernel (roundToInt (blurRadius * 2.0f));
  59536. blurKernel.createGaussianBlur (blurRadius);
  59537. blurKernel.applyToImage (*bigIm, 0,
  59538. xOffset,
  59539. yOffset,
  59540. bigIm->getWidth(),
  59541. bigIm->getHeight());
  59542. ImageCache::addImageToCache (bigIm, hash);
  59543. }
  59544. const int iw = bigIm->getWidth();
  59545. const int ih = bigIm->getHeight();
  59546. const int shadowEdge2 = shadowEdge * 2;
  59547. setShadowImage (bigIm, 0, shadowEdge, shadowEdge2, 0, 0);
  59548. setShadowImage (bigIm, 1, shadowEdge, shadowEdge2, 0, ih - shadowEdge2);
  59549. setShadowImage (bigIm, 2, shadowEdge, shadowEdge, 0, shadowEdge2);
  59550. setShadowImage (bigIm, 3, shadowEdge, shadowEdge2, iw - shadowEdge, 0);
  59551. setShadowImage (bigIm, 4, shadowEdge, shadowEdge2, iw - shadowEdge, ih - shadowEdge2);
  59552. setShadowImage (bigIm, 5, shadowEdge, shadowEdge, iw - shadowEdge, shadowEdge2);
  59553. setShadowImage (bigIm, 6, shadowEdge, shadowEdge, shadowEdge, 0);
  59554. setShadowImage (bigIm, 7, shadowEdge, shadowEdge, iw - shadowEdge2, 0);
  59555. setShadowImage (bigIm, 8, shadowEdge, shadowEdge, shadowEdge2, 0);
  59556. setShadowImage (bigIm, 9, shadowEdge, shadowEdge, shadowEdge, ih - shadowEdge);
  59557. setShadowImage (bigIm, 10, shadowEdge, shadowEdge, iw - shadowEdge2, ih - shadowEdge);
  59558. setShadowImage (bigIm, 11, shadowEdge, shadowEdge, shadowEdge2, ih - shadowEdge);
  59559. ImageCache::release (bigIm);
  59560. for (int i = 0; i < 4; ++i)
  59561. {
  59562. shadowWindows[numShadows] = new ShadowWindow (owner, i, shadowImageSections);
  59563. ++numShadows;
  59564. }
  59565. }
  59566. if (numShadows > 0)
  59567. {
  59568. for (int i = numShadows; --i >= 0;)
  59569. {
  59570. shadowWindows[i]->setAlwaysOnTop (owner->isAlwaysOnTop());
  59571. shadowWindows[i]->setVisible (isOwnerVisible);
  59572. }
  59573. const int x = owner->getX();
  59574. const int y = owner->getY() - shadowEdge;
  59575. const int w = owner->getWidth();
  59576. const int h = owner->getHeight() + shadowEdge + shadowEdge;
  59577. shadowWindows[0]->setBounds (x - shadowEdge,
  59578. y,
  59579. shadowEdge,
  59580. h);
  59581. shadowWindows[1]->setBounds (x + w,
  59582. y,
  59583. shadowEdge,
  59584. h);
  59585. shadowWindows[2]->setBounds (x,
  59586. y,
  59587. w,
  59588. shadowEdge);
  59589. shadowWindows[3]->setBounds (x,
  59590. owner->getBottom(),
  59591. w,
  59592. shadowEdge);
  59593. }
  59594. reentrant = false;
  59595. if (createShadowWindows)
  59596. bringShadowWindowsToFront();
  59597. }
  59598. void DropShadower::setShadowImage (Image* const src,
  59599. const int num,
  59600. const int w,
  59601. const int h,
  59602. const int sx,
  59603. const int sy)
  59604. {
  59605. shadowImageSections[num] = new Image (Image::ARGB, w, h, true);
  59606. Graphics g (*shadowImageSections[num]);
  59607. g.drawImage (src, 0, 0, w, h, sx, sy, w, h);
  59608. }
  59609. void DropShadower::bringShadowWindowsToFront()
  59610. {
  59611. if (! (inDestructor || reentrant))
  59612. {
  59613. updateShadows();
  59614. reentrant = true;
  59615. for (int i = numShadows; --i >= 0;)
  59616. shadowWindows[i]->toBehind (owner);
  59617. reentrant = false;
  59618. }
  59619. }
  59620. END_JUCE_NAMESPACE
  59621. /*** End of inlined file: juce_DropShadower.cpp ***/
  59622. /*** Start of inlined file: juce_MagnifierComponent.cpp ***/
  59623. BEGIN_JUCE_NAMESPACE
  59624. class MagnifyingPeer : public ComponentPeer
  59625. {
  59626. public:
  59627. MagnifyingPeer (Component* const component_,
  59628. MagnifierComponent* const magnifierComp_)
  59629. : ComponentPeer (component_, 0),
  59630. magnifierComp (magnifierComp_)
  59631. {
  59632. }
  59633. ~MagnifyingPeer()
  59634. {
  59635. }
  59636. void* getNativeHandle() const { return 0; }
  59637. void setVisible (bool) {}
  59638. void setTitle (const String&) {}
  59639. void setPosition (int, int) {}
  59640. void setSize (int, int) {}
  59641. void setBounds (int, int, int, int, const bool) {}
  59642. void setMinimised (bool) {}
  59643. bool isMinimised() const { return false; }
  59644. void setFullScreen (bool) {}
  59645. bool isFullScreen() const { return false; }
  59646. const BorderSize getFrameSize() const { return BorderSize (0); }
  59647. bool setAlwaysOnTop (bool) { return true; }
  59648. void toFront (bool) {}
  59649. void toBehind (ComponentPeer*) {}
  59650. void setIcon (const Image&) {}
  59651. bool isFocused() const
  59652. {
  59653. return magnifierComp->hasKeyboardFocus (true);
  59654. }
  59655. void grabFocus()
  59656. {
  59657. ComponentPeer* peer = magnifierComp->getPeer();
  59658. if (peer != 0)
  59659. peer->grabFocus();
  59660. }
  59661. void textInputRequired (const Point<int>& position)
  59662. {
  59663. ComponentPeer* peer = magnifierComp->getPeer();
  59664. if (peer != 0)
  59665. peer->textInputRequired (position);
  59666. }
  59667. const Rectangle<int> getBounds() const
  59668. {
  59669. return Rectangle<int> (magnifierComp->getScreenX(), magnifierComp->getScreenY(),
  59670. component->getWidth(), component->getHeight());
  59671. }
  59672. const Point<int> getScreenPosition() const
  59673. {
  59674. return magnifierComp->getScreenPosition();
  59675. }
  59676. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  59677. {
  59678. const double zoom = magnifierComp->getScaleFactor();
  59679. return magnifierComp->relativePositionToGlobal (Point<int> (roundToInt (relativePosition.getX() * zoom),
  59680. roundToInt (relativePosition.getY() * zoom)));
  59681. }
  59682. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  59683. {
  59684. const Point<int> p (magnifierComp->globalPositionToRelative (screenPosition));
  59685. const double zoom = magnifierComp->getScaleFactor();
  59686. return Point<int> (roundToInt (p.getX() / zoom),
  59687. roundToInt (p.getY() / zoom));
  59688. }
  59689. bool contains (int x, int y, bool) const
  59690. {
  59691. return ((unsigned int) x) < (unsigned int) magnifierComp->getWidth()
  59692. && ((unsigned int) y) < (unsigned int) magnifierComp->getHeight();
  59693. }
  59694. void repaint (int x, int y, int w, int h)
  59695. {
  59696. const double zoom = magnifierComp->getScaleFactor();
  59697. magnifierComp->repaint ((int) (x * zoom),
  59698. (int) (y * zoom),
  59699. roundToInt (w * zoom) + 1,
  59700. roundToInt (h * zoom) + 1);
  59701. }
  59702. void performAnyPendingRepaintsNow()
  59703. {
  59704. }
  59705. juce_UseDebuggingNewOperator
  59706. private:
  59707. MagnifierComponent* const magnifierComp;
  59708. MagnifyingPeer (const MagnifyingPeer&);
  59709. MagnifyingPeer& operator= (const MagnifyingPeer&);
  59710. };
  59711. class PeerHolderComp : public Component
  59712. {
  59713. public:
  59714. PeerHolderComp (MagnifierComponent* const magnifierComp_)
  59715. : magnifierComp (magnifierComp_)
  59716. {
  59717. setVisible (true);
  59718. }
  59719. ~PeerHolderComp()
  59720. {
  59721. }
  59722. ComponentPeer* createNewPeer (int, void*)
  59723. {
  59724. return new MagnifyingPeer (this, magnifierComp);
  59725. }
  59726. void childBoundsChanged (Component* c)
  59727. {
  59728. if (c != 0)
  59729. {
  59730. setSize (c->getWidth(), c->getHeight());
  59731. magnifierComp->childBoundsChanged (this);
  59732. }
  59733. }
  59734. void mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59735. {
  59736. // unhandled mouse wheel moves can be referred upwards to the parent comp..
  59737. Component* const p = magnifierComp->getParentComponent();
  59738. if (p != 0)
  59739. p->mouseWheelMove (e.getEventRelativeTo (p), ix, iy);
  59740. }
  59741. private:
  59742. MagnifierComponent* const magnifierComp;
  59743. PeerHolderComp (const PeerHolderComp&);
  59744. PeerHolderComp& operator= (const PeerHolderComp&);
  59745. };
  59746. MagnifierComponent::MagnifierComponent (Component* const content_,
  59747. const bool deleteContentCompWhenNoLongerNeeded)
  59748. : content (content_),
  59749. scaleFactor (0.0),
  59750. peer (0),
  59751. deleteContent (deleteContentCompWhenNoLongerNeeded),
  59752. quality (Graphics::lowResamplingQuality)
  59753. {
  59754. holderComp = new PeerHolderComp (this);
  59755. setScaleFactor (1.0);
  59756. }
  59757. MagnifierComponent::~MagnifierComponent()
  59758. {
  59759. delete holderComp;
  59760. if (deleteContent)
  59761. delete content;
  59762. }
  59763. void MagnifierComponent::setScaleFactor (double newScaleFactor)
  59764. {
  59765. jassert (newScaleFactor > 0.0); // hmm - unlikely to work well with a negative scale factor
  59766. newScaleFactor = jlimit (1.0 / 8.0, 1000.0, newScaleFactor);
  59767. if (scaleFactor != newScaleFactor)
  59768. {
  59769. scaleFactor = newScaleFactor;
  59770. if (scaleFactor == 1.0)
  59771. {
  59772. holderComp->removeFromDesktop();
  59773. peer = 0;
  59774. addChildComponent (content);
  59775. childBoundsChanged (content);
  59776. }
  59777. else
  59778. {
  59779. holderComp->addAndMakeVisible (content);
  59780. holderComp->childBoundsChanged (content);
  59781. childBoundsChanged (holderComp);
  59782. holderComp->addToDesktop (0);
  59783. peer = holderComp->getPeer();
  59784. }
  59785. repaint();
  59786. }
  59787. }
  59788. void MagnifierComponent::setResamplingQuality (Graphics::ResamplingQuality newQuality)
  59789. {
  59790. quality = newQuality;
  59791. }
  59792. void MagnifierComponent::paint (Graphics& g)
  59793. {
  59794. const int w = holderComp->getWidth();
  59795. const int h = holderComp->getHeight();
  59796. if (w == 0 || h == 0)
  59797. return;
  59798. const Rectangle<int> r (g.getClipBounds());
  59799. const int srcX = (int) (r.getX() / scaleFactor);
  59800. const int srcY = (int) (r.getY() / scaleFactor);
  59801. int srcW = roundToInt (r.getRight() / scaleFactor) - srcX;
  59802. int srcH = roundToInt (r.getBottom() / scaleFactor) - srcY;
  59803. if (scaleFactor >= 1.0)
  59804. {
  59805. ++srcW;
  59806. ++srcH;
  59807. }
  59808. Image temp (Image::ARGB, jmax (w, srcX + srcW), jmax (h, srcY + srcH), false);
  59809. temp.clear (srcX, srcY, srcW, srcH);
  59810. {
  59811. Graphics g2 (temp);
  59812. g2.reduceClipRegion (srcX, srcY, srcW, srcH);
  59813. holderComp->paintEntireComponent (g2);
  59814. }
  59815. g.setImageResamplingQuality (quality);
  59816. g.drawImageTransformed (&temp, temp.getBounds(),
  59817. AffineTransform::scale ((float) scaleFactor, (float) scaleFactor),
  59818. false);
  59819. }
  59820. void MagnifierComponent::childBoundsChanged (Component* c)
  59821. {
  59822. if (c != 0)
  59823. setSize (roundToInt (c->getWidth() * scaleFactor),
  59824. roundToInt (c->getHeight() * scaleFactor));
  59825. }
  59826. void MagnifierComponent::mouseDown (const MouseEvent& e)
  59827. {
  59828. if (peer != 0)
  59829. peer->handleMouseDown (Point<int> (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds());
  59830. }
  59831. void MagnifierComponent::mouseUp (const MouseEvent& e)
  59832. {
  59833. if (peer != 0)
  59834. peer->handleMouseUp (e.mods.getRawFlags(), Point<int> (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds());
  59835. }
  59836. void MagnifierComponent::mouseDrag (const MouseEvent& e)
  59837. {
  59838. if (peer != 0)
  59839. peer->handleMouseDrag (Point<int> (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds());
  59840. }
  59841. void MagnifierComponent::mouseMove (const MouseEvent& e)
  59842. {
  59843. if (peer != 0)
  59844. peer->handleMouseMove (Point<int> (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds());
  59845. }
  59846. void MagnifierComponent::mouseEnter (const MouseEvent& e)
  59847. {
  59848. if (peer != 0)
  59849. peer->handleMouseEnter (Point<int> (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds());
  59850. }
  59851. void MagnifierComponent::mouseExit (const MouseEvent& e)
  59852. {
  59853. if (peer != 0)
  59854. peer->handleMouseExit (Point<int> (scaleInt (e.x), scaleInt (e.y)), e.eventTime.toMilliseconds());
  59855. }
  59856. void MagnifierComponent::mouseWheelMove (const MouseEvent& e, float ix, float iy)
  59857. {
  59858. if (peer != 0)
  59859. peer->handleMouseWheel (roundToInt (ix * 256.0f),
  59860. roundToInt (iy * 256.0f),
  59861. e.eventTime.toMilliseconds());
  59862. else
  59863. Component::mouseWheelMove (e, ix, iy);
  59864. }
  59865. int MagnifierComponent::scaleInt (const int n) const
  59866. {
  59867. return roundToInt (n / scaleFactor);
  59868. }
  59869. END_JUCE_NAMESPACE
  59870. /*** End of inlined file: juce_MagnifierComponent.cpp ***/
  59871. /*** Start of inlined file: juce_MidiKeyboardComponent.cpp ***/
  59872. BEGIN_JUCE_NAMESPACE
  59873. class MidiKeyboardUpDownButton : public Button
  59874. {
  59875. public:
  59876. MidiKeyboardUpDownButton (MidiKeyboardComponent* const owner_,
  59877. const int delta_)
  59878. : Button (String::empty),
  59879. owner (owner_),
  59880. delta (delta_)
  59881. {
  59882. setOpaque (true);
  59883. }
  59884. ~MidiKeyboardUpDownButton()
  59885. {
  59886. }
  59887. void clicked()
  59888. {
  59889. int note = owner->getLowestVisibleKey();
  59890. if (delta < 0)
  59891. note = (note - 1) / 12;
  59892. else
  59893. note = note / 12 + 1;
  59894. owner->setLowestVisibleKey (note * 12);
  59895. }
  59896. void paintButton (Graphics& g,
  59897. bool isMouseOverButton,
  59898. bool isButtonDown)
  59899. {
  59900. owner->drawUpDownButton (g, getWidth(), getHeight(),
  59901. isMouseOverButton, isButtonDown,
  59902. delta > 0);
  59903. }
  59904. private:
  59905. MidiKeyboardComponent* const owner;
  59906. const int delta;
  59907. MidiKeyboardUpDownButton (const MidiKeyboardUpDownButton&);
  59908. MidiKeyboardUpDownButton& operator= (const MidiKeyboardUpDownButton&);
  59909. };
  59910. MidiKeyboardComponent::MidiKeyboardComponent (MidiKeyboardState& state_,
  59911. const Orientation orientation_)
  59912. : state (state_),
  59913. xOffset (0),
  59914. blackNoteLength (1),
  59915. keyWidth (16.0f),
  59916. orientation (orientation_),
  59917. midiChannel (1),
  59918. midiInChannelMask (0xffff),
  59919. velocity (1.0f),
  59920. noteUnderMouse (-1),
  59921. mouseDownNote (-1),
  59922. rangeStart (0),
  59923. rangeEnd (127),
  59924. firstKey (12 * 4),
  59925. canScroll (true),
  59926. mouseDragging (false),
  59927. useMousePositionForVelocity (true),
  59928. keyMappingOctave (6),
  59929. octaveNumForMiddleC (3)
  59930. {
  59931. addChildComponent (scrollDown = new MidiKeyboardUpDownButton (this, -1));
  59932. addChildComponent (scrollUp = new MidiKeyboardUpDownButton (this, 1));
  59933. // initialise with a default set of querty key-mappings..
  59934. const char* const keymap = "awsedftgyhujkolp;";
  59935. for (int i = String (keymap).length(); --i >= 0;)
  59936. setKeyPressForNote (KeyPress (keymap[i], 0, 0), i);
  59937. setOpaque (true);
  59938. setWantsKeyboardFocus (true);
  59939. state.addListener (this);
  59940. }
  59941. MidiKeyboardComponent::~MidiKeyboardComponent()
  59942. {
  59943. state.removeListener (this);
  59944. jassert (mouseDownNote < 0 && keysPressed.countNumberOfSetBits() == 0); // leaving stuck notes!
  59945. deleteAllChildren();
  59946. }
  59947. void MidiKeyboardComponent::setKeyWidth (const float widthInPixels)
  59948. {
  59949. keyWidth = widthInPixels;
  59950. resized();
  59951. }
  59952. void MidiKeyboardComponent::setOrientation (const Orientation newOrientation)
  59953. {
  59954. if (orientation != newOrientation)
  59955. {
  59956. orientation = newOrientation;
  59957. resized();
  59958. }
  59959. }
  59960. void MidiKeyboardComponent::setAvailableRange (const int lowestNote,
  59961. const int highestNote)
  59962. {
  59963. jassert (lowestNote >= 0 && lowestNote <= 127);
  59964. jassert (highestNote >= 0 && highestNote <= 127);
  59965. jassert (lowestNote <= highestNote);
  59966. if (rangeStart != lowestNote || rangeEnd != highestNote)
  59967. {
  59968. rangeStart = jlimit (0, 127, lowestNote);
  59969. rangeEnd = jlimit (0, 127, highestNote);
  59970. firstKey = jlimit (rangeStart, rangeEnd, firstKey);
  59971. resized();
  59972. }
  59973. }
  59974. void MidiKeyboardComponent::setLowestVisibleKey (int noteNumber)
  59975. {
  59976. noteNumber = jlimit (rangeStart, rangeEnd, noteNumber);
  59977. if (noteNumber != firstKey)
  59978. {
  59979. firstKey = noteNumber;
  59980. sendChangeMessage (this);
  59981. resized();
  59982. }
  59983. }
  59984. void MidiKeyboardComponent::setScrollButtonsVisible (const bool canScroll_)
  59985. {
  59986. if (canScroll != canScroll_)
  59987. {
  59988. canScroll = canScroll_;
  59989. resized();
  59990. }
  59991. }
  59992. void MidiKeyboardComponent::colourChanged()
  59993. {
  59994. repaint();
  59995. }
  59996. void MidiKeyboardComponent::setMidiChannel (const int midiChannelNumber)
  59997. {
  59998. jassert (midiChannelNumber > 0 && midiChannelNumber <= 16);
  59999. if (midiChannel != midiChannelNumber)
  60000. {
  60001. resetAnyKeysInUse();
  60002. midiChannel = jlimit (1, 16, midiChannelNumber);
  60003. }
  60004. }
  60005. void MidiKeyboardComponent::setMidiChannelsToDisplay (const int midiChannelMask)
  60006. {
  60007. midiInChannelMask = midiChannelMask;
  60008. triggerAsyncUpdate();
  60009. }
  60010. void MidiKeyboardComponent::setVelocity (const float velocity_, const bool useMousePositionForVelocity_)
  60011. {
  60012. velocity = jlimit (0.0f, 1.0f, velocity_);
  60013. useMousePositionForVelocity = useMousePositionForVelocity_;
  60014. }
  60015. void MidiKeyboardComponent::getKeyPosition (int midiNoteNumber, const float keyWidth, int& x, int& w) const
  60016. {
  60017. jassert (midiNoteNumber >= 0 && midiNoteNumber < 128);
  60018. static const float blackNoteWidth = 0.7f;
  60019. static const float notePos[] = { 0.0f, 1 - blackNoteWidth * 0.6f,
  60020. 1.0f, 2 - blackNoteWidth * 0.4f,
  60021. 2.0f, 3.0f, 4 - blackNoteWidth * 0.7f,
  60022. 4.0f, 5 - blackNoteWidth * 0.5f,
  60023. 5.0f, 6 - blackNoteWidth * 0.3f,
  60024. 6.0f };
  60025. static const float widths[] = { 1.0f, blackNoteWidth,
  60026. 1.0f, blackNoteWidth,
  60027. 1.0f, 1.0f, blackNoteWidth,
  60028. 1.0f, blackNoteWidth,
  60029. 1.0f, blackNoteWidth,
  60030. 1.0f };
  60031. const int octave = midiNoteNumber / 12;
  60032. const int note = midiNoteNumber % 12;
  60033. x = roundToInt (octave * 7.0f * keyWidth + notePos [note] * keyWidth);
  60034. w = roundToInt (widths [note] * keyWidth);
  60035. }
  60036. void MidiKeyboardComponent::getKeyPos (int midiNoteNumber, int& x, int& w) const
  60037. {
  60038. getKeyPosition (midiNoteNumber, keyWidth, x, w);
  60039. int rx, rw;
  60040. getKeyPosition (rangeStart, keyWidth, rx, rw);
  60041. x -= xOffset + rx;
  60042. }
  60043. int MidiKeyboardComponent::getKeyStartPosition (const int midiNoteNumber) const
  60044. {
  60045. int x, y;
  60046. getKeyPos (midiNoteNumber, x, y);
  60047. return x;
  60048. }
  60049. static const uint8 whiteNotes[] = { 0, 2, 4, 5, 7, 9, 11 };
  60050. static const uint8 blackNotes[] = { 1, 3, 6, 8, 10 };
  60051. int MidiKeyboardComponent::xyToNote (const Point<int>& pos, float& mousePositionVelocity)
  60052. {
  60053. if (! reallyContains (pos.getX(), pos.getY(), false))
  60054. return -1;
  60055. Point<int> p (pos);
  60056. if (orientation != horizontalKeyboard)
  60057. {
  60058. p = Point<int> (p.getY(), p.getX());
  60059. if (orientation == verticalKeyboardFacingLeft)
  60060. p = Point<int> (p.getX(), getWidth() - p.getY());
  60061. else
  60062. p = Point<int> (getHeight() - p.getX(), p.getY());
  60063. }
  60064. return remappedXYToNote (p + Point<int> (xOffset, 0), mousePositionVelocity);
  60065. }
  60066. int MidiKeyboardComponent::remappedXYToNote (const Point<int>& pos, float& mousePositionVelocity) const
  60067. {
  60068. if (pos.getY() < blackNoteLength)
  60069. {
  60070. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  60071. {
  60072. for (int i = 0; i < 5; ++i)
  60073. {
  60074. const int note = octaveStart + blackNotes [i];
  60075. if (note >= rangeStart && note <= rangeEnd)
  60076. {
  60077. int kx, kw;
  60078. getKeyPos (note, kx, kw);
  60079. kx += xOffset;
  60080. if (pos.getX() >= kx && pos.getX() < kx + kw)
  60081. {
  60082. mousePositionVelocity = pos.getY() / (float) blackNoteLength;
  60083. return note;
  60084. }
  60085. }
  60086. }
  60087. }
  60088. }
  60089. for (int octaveStart = 12 * (rangeStart / 12); octaveStart <= rangeEnd; octaveStart += 12)
  60090. {
  60091. for (int i = 0; i < 7; ++i)
  60092. {
  60093. const int note = octaveStart + whiteNotes [i];
  60094. if (note >= rangeStart && note <= rangeEnd)
  60095. {
  60096. int kx, kw;
  60097. getKeyPos (note, kx, kw);
  60098. kx += xOffset;
  60099. if (pos.getX() >= kx && pos.getX() < kx + kw)
  60100. {
  60101. const int whiteNoteLength = (orientation == horizontalKeyboard) ? getHeight() : getWidth();
  60102. mousePositionVelocity = pos.getY() / (float) whiteNoteLength;
  60103. return note;
  60104. }
  60105. }
  60106. }
  60107. }
  60108. mousePositionVelocity = 0;
  60109. return -1;
  60110. }
  60111. void MidiKeyboardComponent::repaintNote (const int noteNum)
  60112. {
  60113. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60114. {
  60115. int x, w;
  60116. getKeyPos (noteNum, x, w);
  60117. if (orientation == horizontalKeyboard)
  60118. repaint (x, 0, w, getHeight());
  60119. else if (orientation == verticalKeyboardFacingLeft)
  60120. repaint (0, x, getWidth(), w);
  60121. else if (orientation == verticalKeyboardFacingRight)
  60122. repaint (0, getHeight() - x - w, getWidth(), w);
  60123. }
  60124. }
  60125. void MidiKeyboardComponent::paint (Graphics& g)
  60126. {
  60127. g.fillAll (Colours::white.overlaidWith (findColour (whiteNoteColourId)));
  60128. const Colour lineColour (findColour (keySeparatorLineColourId));
  60129. const Colour textColour (findColour (textLabelColourId));
  60130. int x, w, octave;
  60131. for (octave = 0; octave < 128; octave += 12)
  60132. {
  60133. for (int white = 0; white < 7; ++white)
  60134. {
  60135. const int noteNum = octave + whiteNotes [white];
  60136. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60137. {
  60138. getKeyPos (noteNum, x, w);
  60139. if (orientation == horizontalKeyboard)
  60140. drawWhiteNote (noteNum, g, x, 0, w, getHeight(),
  60141. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60142. noteUnderMouse == noteNum,
  60143. lineColour, textColour);
  60144. else if (orientation == verticalKeyboardFacingLeft)
  60145. drawWhiteNote (noteNum, g, 0, x, getWidth(), w,
  60146. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60147. noteUnderMouse == noteNum,
  60148. lineColour, textColour);
  60149. else if (orientation == verticalKeyboardFacingRight)
  60150. drawWhiteNote (noteNum, g, 0, getHeight() - x - w, getWidth(), w,
  60151. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60152. noteUnderMouse == noteNum,
  60153. lineColour, textColour);
  60154. }
  60155. }
  60156. }
  60157. float x1 = 0.0f, y1 = 0.0f, x2 = 0.0f, y2 = 0.0f;
  60158. if (orientation == verticalKeyboardFacingLeft)
  60159. {
  60160. x1 = getWidth() - 1.0f;
  60161. x2 = getWidth() - 5.0f;
  60162. }
  60163. else if (orientation == verticalKeyboardFacingRight)
  60164. x2 = 5.0f;
  60165. else
  60166. y2 = 5.0f;
  60167. g.setGradientFill (ColourGradient (Colours::black.withAlpha (0.3f), x1, y1,
  60168. Colours::transparentBlack, x2, y2, false));
  60169. getKeyPos (rangeEnd, x, w);
  60170. x += w;
  60171. if (orientation == verticalKeyboardFacingLeft)
  60172. g.fillRect (getWidth() - 5, 0, 5, x);
  60173. else if (orientation == verticalKeyboardFacingRight)
  60174. g.fillRect (0, 0, 5, x);
  60175. else
  60176. g.fillRect (0, 0, x, 5);
  60177. g.setColour (lineColour);
  60178. if (orientation == verticalKeyboardFacingLeft)
  60179. g.fillRect (0, 0, 1, x);
  60180. else if (orientation == verticalKeyboardFacingRight)
  60181. g.fillRect (getWidth() - 1, 0, 1, x);
  60182. else
  60183. g.fillRect (0, getHeight() - 1, x, 1);
  60184. const Colour blackNoteColour (findColour (blackNoteColourId));
  60185. for (octave = 0; octave < 128; octave += 12)
  60186. {
  60187. for (int black = 0; black < 5; ++black)
  60188. {
  60189. const int noteNum = octave + blackNotes [black];
  60190. if (noteNum >= rangeStart && noteNum <= rangeEnd)
  60191. {
  60192. getKeyPos (noteNum, x, w);
  60193. if (orientation == horizontalKeyboard)
  60194. drawBlackNote (noteNum, g, x, 0, w, blackNoteLength,
  60195. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60196. noteUnderMouse == noteNum,
  60197. blackNoteColour);
  60198. else if (orientation == verticalKeyboardFacingLeft)
  60199. drawBlackNote (noteNum, g, getWidth() - blackNoteLength, x, blackNoteLength, w,
  60200. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60201. noteUnderMouse == noteNum,
  60202. blackNoteColour);
  60203. else if (orientation == verticalKeyboardFacingRight)
  60204. drawBlackNote (noteNum, g, 0, getHeight() - x - w, blackNoteLength, w,
  60205. state.isNoteOnForChannels (midiInChannelMask, noteNum),
  60206. noteUnderMouse == noteNum,
  60207. blackNoteColour);
  60208. }
  60209. }
  60210. }
  60211. }
  60212. void MidiKeyboardComponent::drawWhiteNote (int midiNoteNumber,
  60213. Graphics& g, int x, int y, int w, int h,
  60214. bool isDown, bool isOver,
  60215. const Colour& lineColour,
  60216. const Colour& textColour)
  60217. {
  60218. Colour c (Colours::transparentWhite);
  60219. if (isDown)
  60220. c = findColour (keyDownOverlayColourId);
  60221. if (isOver)
  60222. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60223. g.setColour (c);
  60224. g.fillRect (x, y, w, h);
  60225. const String text (getWhiteNoteText (midiNoteNumber));
  60226. if (! text.isEmpty())
  60227. {
  60228. g.setColour (textColour);
  60229. Font f (jmin (12.0f, keyWidth * 0.9f));
  60230. f.setHorizontalScale (0.8f);
  60231. g.setFont (f);
  60232. Justification justification (Justification::centredBottom);
  60233. if (orientation == verticalKeyboardFacingLeft)
  60234. justification = Justification::centredLeft;
  60235. else if (orientation == verticalKeyboardFacingRight)
  60236. justification = Justification::centredRight;
  60237. g.drawFittedText (text, x + 2, y + 2, w - 4, h - 4, justification, 1);
  60238. }
  60239. g.setColour (lineColour);
  60240. if (orientation == horizontalKeyboard)
  60241. g.fillRect (x, y, 1, h);
  60242. else if (orientation == verticalKeyboardFacingLeft)
  60243. g.fillRect (x, y, w, 1);
  60244. else if (orientation == verticalKeyboardFacingRight)
  60245. g.fillRect (x, y + h - 1, w, 1);
  60246. if (midiNoteNumber == rangeEnd)
  60247. {
  60248. if (orientation == horizontalKeyboard)
  60249. g.fillRect (x + w, y, 1, h);
  60250. else if (orientation == verticalKeyboardFacingLeft)
  60251. g.fillRect (x, y + h, w, 1);
  60252. else if (orientation == verticalKeyboardFacingRight)
  60253. g.fillRect (x, y - 1, w, 1);
  60254. }
  60255. }
  60256. void MidiKeyboardComponent::drawBlackNote (int /*midiNoteNumber*/,
  60257. Graphics& g, int x, int y, int w, int h,
  60258. bool isDown, bool isOver,
  60259. const Colour& noteFillColour)
  60260. {
  60261. Colour c (noteFillColour);
  60262. if (isDown)
  60263. c = c.overlaidWith (findColour (keyDownOverlayColourId));
  60264. if (isOver)
  60265. c = c.overlaidWith (findColour (mouseOverKeyOverlayColourId));
  60266. g.setColour (c);
  60267. g.fillRect (x, y, w, h);
  60268. if (isDown)
  60269. {
  60270. g.setColour (noteFillColour);
  60271. g.drawRect (x, y, w, h);
  60272. }
  60273. else
  60274. {
  60275. const int xIndent = jmax (1, jmin (w, h) / 8);
  60276. g.setColour (c.brighter());
  60277. if (orientation == horizontalKeyboard)
  60278. g.fillRect (x + xIndent, y, w - xIndent * 2, 7 * h / 8);
  60279. else if (orientation == verticalKeyboardFacingLeft)
  60280. g.fillRect (x + w / 8, y + xIndent, w - w / 8, h - xIndent * 2);
  60281. else if (orientation == verticalKeyboardFacingRight)
  60282. g.fillRect (x, y + xIndent, 7 * w / 8, h - xIndent * 2);
  60283. }
  60284. }
  60285. void MidiKeyboardComponent::setOctaveForMiddleC (const int octaveNumForMiddleC_) throw()
  60286. {
  60287. octaveNumForMiddleC = octaveNumForMiddleC_;
  60288. repaint();
  60289. }
  60290. const String MidiKeyboardComponent::getWhiteNoteText (const int midiNoteNumber)
  60291. {
  60292. if (keyWidth > 14.0f && midiNoteNumber % 12 == 0)
  60293. return MidiMessage::getMidiNoteName (midiNoteNumber, true, true, octaveNumForMiddleC);
  60294. return String::empty;
  60295. }
  60296. void MidiKeyboardComponent::drawUpDownButton (Graphics& g, int w, int h,
  60297. const bool isMouseOver,
  60298. const bool isButtonDown,
  60299. const bool movesOctavesUp)
  60300. {
  60301. g.fillAll (findColour (upDownButtonBackgroundColourId));
  60302. float angle;
  60303. if (orientation == MidiKeyboardComponent::horizontalKeyboard)
  60304. angle = movesOctavesUp ? 0.0f : 0.5f;
  60305. else if (orientation == MidiKeyboardComponent::verticalKeyboardFacingLeft)
  60306. angle = movesOctavesUp ? 0.25f : 0.75f;
  60307. else
  60308. angle = movesOctavesUp ? 0.75f : 0.25f;
  60309. Path path;
  60310. path.lineTo (0.0f, 1.0f);
  60311. path.lineTo (1.0f, 0.5f);
  60312. path.closeSubPath();
  60313. path.applyTransform (AffineTransform::rotation (float_Pi * 2.0f * angle, 0.5f, 0.5f));
  60314. g.setColour (findColour (upDownButtonArrowColourId)
  60315. .withAlpha (isButtonDown ? 1.0f : (isMouseOver ? 0.6f : 0.4f)));
  60316. g.fillPath (path, path.getTransformToScaleToFit (1.0f, 1.0f,
  60317. w - 2.0f,
  60318. h - 2.0f,
  60319. true));
  60320. }
  60321. void MidiKeyboardComponent::resized()
  60322. {
  60323. int w = getWidth();
  60324. int h = getHeight();
  60325. if (w > 0 && h > 0)
  60326. {
  60327. if (orientation != horizontalKeyboard)
  60328. swapVariables (w, h);
  60329. blackNoteLength = roundToInt (h * 0.7f);
  60330. int kx2, kw2;
  60331. getKeyPos (rangeEnd, kx2, kw2);
  60332. kx2 += kw2;
  60333. if (firstKey != rangeStart)
  60334. {
  60335. int kx1, kw1;
  60336. getKeyPos (rangeStart, kx1, kw1);
  60337. if (kx2 - kx1 <= w)
  60338. {
  60339. firstKey = rangeStart;
  60340. sendChangeMessage (this);
  60341. repaint();
  60342. }
  60343. }
  60344. const bool showScrollButtons = canScroll && (firstKey > rangeStart || kx2 > w + xOffset * 2);
  60345. scrollDown->setVisible (showScrollButtons);
  60346. scrollUp->setVisible (showScrollButtons);
  60347. xOffset = 0;
  60348. if (showScrollButtons)
  60349. {
  60350. const int scrollButtonW = jmin (12, w / 2);
  60351. if (orientation == horizontalKeyboard)
  60352. {
  60353. scrollDown->setBounds (0, 0, scrollButtonW, getHeight());
  60354. scrollUp->setBounds (getWidth() - scrollButtonW, 0, scrollButtonW, getHeight());
  60355. }
  60356. else if (orientation == verticalKeyboardFacingLeft)
  60357. {
  60358. scrollDown->setBounds (0, 0, getWidth(), scrollButtonW);
  60359. scrollUp->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60360. }
  60361. else if (orientation == verticalKeyboardFacingRight)
  60362. {
  60363. scrollDown->setBounds (0, getHeight() - scrollButtonW, getWidth(), scrollButtonW);
  60364. scrollUp->setBounds (0, 0, getWidth(), scrollButtonW);
  60365. }
  60366. int endOfLastKey, kw;
  60367. getKeyPos (rangeEnd, endOfLastKey, kw);
  60368. endOfLastKey += kw;
  60369. float mousePositionVelocity;
  60370. const int spaceAvailable = w - scrollButtonW * 2;
  60371. const int lastStartKey = remappedXYToNote (Point<int> (endOfLastKey - spaceAvailable, 0), mousePositionVelocity) + 1;
  60372. if (lastStartKey >= 0 && firstKey > lastStartKey)
  60373. {
  60374. firstKey = jlimit (rangeStart, rangeEnd, lastStartKey);
  60375. sendChangeMessage (this);
  60376. }
  60377. int newOffset = 0;
  60378. getKeyPos (firstKey, newOffset, kw);
  60379. xOffset = newOffset - scrollButtonW;
  60380. }
  60381. else
  60382. {
  60383. firstKey = rangeStart;
  60384. }
  60385. timerCallback();
  60386. repaint();
  60387. }
  60388. }
  60389. void MidiKeyboardComponent::handleNoteOn (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/, float /*velocity*/)
  60390. {
  60391. triggerAsyncUpdate();
  60392. }
  60393. void MidiKeyboardComponent::handleNoteOff (MidiKeyboardState*, int /*midiChannel*/, int /*midiNoteNumber*/)
  60394. {
  60395. triggerAsyncUpdate();
  60396. }
  60397. void MidiKeyboardComponent::handleAsyncUpdate()
  60398. {
  60399. for (int i = rangeStart; i <= rangeEnd; ++i)
  60400. {
  60401. if (keysCurrentlyDrawnDown[i] != state.isNoteOnForChannels (midiInChannelMask, i))
  60402. {
  60403. keysCurrentlyDrawnDown.setBit (i, state.isNoteOnForChannels (midiInChannelMask, i));
  60404. repaintNote (i);
  60405. }
  60406. }
  60407. }
  60408. void MidiKeyboardComponent::resetAnyKeysInUse()
  60409. {
  60410. if (keysPressed.countNumberOfSetBits() > 0 || mouseDownNote > 0)
  60411. {
  60412. state.allNotesOff (midiChannel);
  60413. keysPressed.clear();
  60414. mouseDownNote = -1;
  60415. }
  60416. }
  60417. void MidiKeyboardComponent::updateNoteUnderMouse (const Point<int>& pos)
  60418. {
  60419. float mousePositionVelocity = 0.0f;
  60420. const int newNote = (mouseDragging || isMouseOver())
  60421. ? xyToNote (pos, mousePositionVelocity) : -1;
  60422. if (noteUnderMouse != newNote)
  60423. {
  60424. if (mouseDownNote >= 0)
  60425. {
  60426. state.noteOff (midiChannel, mouseDownNote);
  60427. mouseDownNote = -1;
  60428. }
  60429. if (mouseDragging && newNote >= 0)
  60430. {
  60431. if (! useMousePositionForVelocity)
  60432. mousePositionVelocity = 1.0f;
  60433. state.noteOn (midiChannel, newNote, mousePositionVelocity * velocity);
  60434. mouseDownNote = newNote;
  60435. }
  60436. repaintNote (noteUnderMouse);
  60437. noteUnderMouse = newNote;
  60438. repaintNote (noteUnderMouse);
  60439. }
  60440. else if (mouseDownNote >= 0 && ! mouseDragging)
  60441. {
  60442. state.noteOff (midiChannel, mouseDownNote);
  60443. mouseDownNote = -1;
  60444. }
  60445. }
  60446. void MidiKeyboardComponent::mouseMove (const MouseEvent& e)
  60447. {
  60448. updateNoteUnderMouse (e.getPosition());
  60449. stopTimer();
  60450. }
  60451. void MidiKeyboardComponent::mouseDrag (const MouseEvent& e)
  60452. {
  60453. float mousePositionVelocity;
  60454. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60455. if (newNote >= 0)
  60456. mouseDraggedToKey (newNote, e);
  60457. updateNoteUnderMouse (e.getPosition());
  60458. }
  60459. bool MidiKeyboardComponent::mouseDownOnKey (int /*midiNoteNumber*/, const MouseEvent&)
  60460. {
  60461. return true;
  60462. }
  60463. void MidiKeyboardComponent::mouseDraggedToKey (int /*midiNoteNumber*/, const MouseEvent&)
  60464. {
  60465. }
  60466. void MidiKeyboardComponent::mouseDown (const MouseEvent& e)
  60467. {
  60468. float mousePositionVelocity;
  60469. const int newNote = xyToNote (e.getPosition(), mousePositionVelocity);
  60470. mouseDragging = false;
  60471. if (newNote >= 0 && mouseDownOnKey (newNote, e))
  60472. {
  60473. repaintNote (noteUnderMouse);
  60474. noteUnderMouse = -1;
  60475. mouseDragging = true;
  60476. updateNoteUnderMouse (e.getPosition());
  60477. startTimer (500);
  60478. }
  60479. }
  60480. void MidiKeyboardComponent::mouseUp (const MouseEvent& e)
  60481. {
  60482. mouseDragging = false;
  60483. updateNoteUnderMouse (e.getPosition());
  60484. stopTimer();
  60485. }
  60486. void MidiKeyboardComponent::mouseEnter (const MouseEvent& e)
  60487. {
  60488. updateNoteUnderMouse (e.getPosition());
  60489. }
  60490. void MidiKeyboardComponent::mouseExit (const MouseEvent& e)
  60491. {
  60492. updateNoteUnderMouse (e.getPosition());
  60493. }
  60494. void MidiKeyboardComponent::mouseWheelMove (const MouseEvent&, float ix, float iy)
  60495. {
  60496. setLowestVisibleKey (getLowestVisibleKey() + roundToInt ((ix != 0 ? ix : iy) * 5.0f));
  60497. }
  60498. void MidiKeyboardComponent::timerCallback()
  60499. {
  60500. updateNoteUnderMouse (getMouseXYRelative());
  60501. }
  60502. void MidiKeyboardComponent::clearKeyMappings()
  60503. {
  60504. resetAnyKeysInUse();
  60505. keyPressNotes.clear();
  60506. keyPresses.clear();
  60507. }
  60508. void MidiKeyboardComponent::setKeyPressForNote (const KeyPress& key,
  60509. const int midiNoteOffsetFromC)
  60510. {
  60511. removeKeyPressForNote (midiNoteOffsetFromC);
  60512. keyPressNotes.add (midiNoteOffsetFromC);
  60513. keyPresses.add (key);
  60514. }
  60515. void MidiKeyboardComponent::removeKeyPressForNote (const int midiNoteOffsetFromC)
  60516. {
  60517. for (int i = keyPressNotes.size(); --i >= 0;)
  60518. {
  60519. if (keyPressNotes.getUnchecked (i) == midiNoteOffsetFromC)
  60520. {
  60521. keyPressNotes.remove (i);
  60522. keyPresses.remove (i);
  60523. }
  60524. }
  60525. }
  60526. void MidiKeyboardComponent::setKeyPressBaseOctave (const int newOctaveNumber)
  60527. {
  60528. jassert (newOctaveNumber >= 0 && newOctaveNumber <= 10);
  60529. keyMappingOctave = newOctaveNumber;
  60530. }
  60531. bool MidiKeyboardComponent::keyStateChanged (const bool /*isKeyDown*/)
  60532. {
  60533. bool keyPressUsed = false;
  60534. for (int i = keyPresses.size(); --i >= 0;)
  60535. {
  60536. const int note = 12 * keyMappingOctave + keyPressNotes.getUnchecked (i);
  60537. if (keyPresses.getReference(i).isCurrentlyDown())
  60538. {
  60539. if (! keysPressed [note])
  60540. {
  60541. keysPressed.setBit (note);
  60542. state.noteOn (midiChannel, note, velocity);
  60543. keyPressUsed = true;
  60544. }
  60545. }
  60546. else
  60547. {
  60548. if (keysPressed [note])
  60549. {
  60550. keysPressed.clearBit (note);
  60551. state.noteOff (midiChannel, note);
  60552. keyPressUsed = true;
  60553. }
  60554. }
  60555. }
  60556. return keyPressUsed;
  60557. }
  60558. void MidiKeyboardComponent::focusLost (FocusChangeType)
  60559. {
  60560. resetAnyKeysInUse();
  60561. }
  60562. END_JUCE_NAMESPACE
  60563. /*** End of inlined file: juce_MidiKeyboardComponent.cpp ***/
  60564. /*** Start of inlined file: juce_OpenGLComponent.cpp ***/
  60565. #if JUCE_OPENGL
  60566. BEGIN_JUCE_NAMESPACE
  60567. extern void juce_glViewport (const int w, const int h);
  60568. OpenGLPixelFormat::OpenGLPixelFormat (const int bitsPerRGBComponent,
  60569. const int alphaBits_,
  60570. const int depthBufferBits_,
  60571. const int stencilBufferBits_) throw()
  60572. : redBits (bitsPerRGBComponent),
  60573. greenBits (bitsPerRGBComponent),
  60574. blueBits (bitsPerRGBComponent),
  60575. alphaBits (alphaBits_),
  60576. depthBufferBits (depthBufferBits_),
  60577. stencilBufferBits (stencilBufferBits_),
  60578. accumulationBufferRedBits (0),
  60579. accumulationBufferGreenBits (0),
  60580. accumulationBufferBlueBits (0),
  60581. accumulationBufferAlphaBits (0),
  60582. fullSceneAntiAliasingNumSamples (0)
  60583. {
  60584. }
  60585. bool OpenGLPixelFormat::operator== (const OpenGLPixelFormat& other) const throw()
  60586. {
  60587. return memcmp (this, &other, sizeof (other)) == 0;
  60588. }
  60589. static VoidArray knownContexts;
  60590. OpenGLContext::OpenGLContext() throw()
  60591. {
  60592. knownContexts.add (this);
  60593. }
  60594. OpenGLContext::~OpenGLContext()
  60595. {
  60596. knownContexts.removeValue (this);
  60597. }
  60598. OpenGLContext* OpenGLContext::getCurrentContext()
  60599. {
  60600. for (int i = knownContexts.size(); --i >= 0;)
  60601. {
  60602. OpenGLContext* const oglc = (OpenGLContext*) knownContexts.getUnchecked(i);
  60603. if (oglc->isActive())
  60604. return oglc;
  60605. }
  60606. return 0;
  60607. }
  60608. class OpenGLComponent::OpenGLComponentWatcher : public ComponentMovementWatcher
  60609. {
  60610. public:
  60611. OpenGLComponentWatcher (OpenGLComponent* const owner_)
  60612. : ComponentMovementWatcher (owner_),
  60613. owner (owner_),
  60614. wasShowing (false)
  60615. {
  60616. }
  60617. ~OpenGLComponentWatcher() {}
  60618. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  60619. {
  60620. owner->updateContextPosition();
  60621. }
  60622. void componentPeerChanged()
  60623. {
  60624. const ScopedLock sl (owner->getContextLock());
  60625. owner->deleteContext();
  60626. }
  60627. void componentVisibilityChanged (Component&)
  60628. {
  60629. const bool isShowingNow = owner->isShowing();
  60630. if (wasShowing != isShowingNow)
  60631. {
  60632. wasShowing = isShowingNow;
  60633. owner->updateContextPosition();
  60634. }
  60635. }
  60636. juce_UseDebuggingNewOperator
  60637. private:
  60638. OpenGLComponent* const owner;
  60639. bool wasShowing;
  60640. };
  60641. OpenGLComponent::OpenGLComponent()
  60642. : context (0),
  60643. contextToShareListsWith (0),
  60644. needToUpdateViewport (true)
  60645. {
  60646. setOpaque (true);
  60647. componentWatcher = new OpenGLComponentWatcher (this);
  60648. }
  60649. OpenGLComponent::~OpenGLComponent()
  60650. {
  60651. deleteContext();
  60652. componentWatcher = 0;
  60653. }
  60654. void OpenGLComponent::deleteContext()
  60655. {
  60656. const ScopedLock sl (contextLock);
  60657. deleteAndZero (context);
  60658. }
  60659. void OpenGLComponent::updateContextPosition()
  60660. {
  60661. needToUpdateViewport = true;
  60662. if (getWidth() > 0 && getHeight() > 0)
  60663. {
  60664. Component* const topComp = getTopLevelComponent();
  60665. if (topComp->getPeer() != 0)
  60666. {
  60667. const ScopedLock sl (contextLock);
  60668. if (context != 0)
  60669. context->updateWindowPosition (getScreenX() - topComp->getScreenX(),
  60670. getScreenY() - topComp->getScreenY(),
  60671. getWidth(),
  60672. getHeight(),
  60673. topComp->getHeight());
  60674. }
  60675. }
  60676. }
  60677. const OpenGLPixelFormat OpenGLComponent::getPixelFormat() const
  60678. {
  60679. OpenGLPixelFormat pf;
  60680. const ScopedLock sl (contextLock);
  60681. if (context != 0)
  60682. pf = context->getPixelFormat();
  60683. return pf;
  60684. }
  60685. void OpenGLComponent::setPixelFormat (const OpenGLPixelFormat& formatToUse)
  60686. {
  60687. if (! (preferredPixelFormat == formatToUse))
  60688. {
  60689. const ScopedLock sl (contextLock);
  60690. deleteContext();
  60691. preferredPixelFormat = formatToUse;
  60692. }
  60693. }
  60694. void OpenGLComponent::shareWith (OpenGLContext* c)
  60695. {
  60696. if (contextToShareListsWith != c)
  60697. {
  60698. const ScopedLock sl (contextLock);
  60699. deleteContext();
  60700. contextToShareListsWith = c;
  60701. }
  60702. }
  60703. bool OpenGLComponent::makeCurrentContextActive()
  60704. {
  60705. if (context == 0)
  60706. {
  60707. const ScopedLock sl (contextLock);
  60708. if (isShowing() && getTopLevelComponent()->getPeer() != 0)
  60709. {
  60710. context = OpenGLContext::createContextForWindow (this,
  60711. preferredPixelFormat,
  60712. contextToShareListsWith);
  60713. if (context != 0)
  60714. {
  60715. updateContextPosition();
  60716. if (context->makeActive())
  60717. newOpenGLContextCreated();
  60718. }
  60719. }
  60720. }
  60721. return context != 0 && context->makeActive();
  60722. }
  60723. void OpenGLComponent::makeCurrentContextInactive()
  60724. {
  60725. if (context != 0)
  60726. context->makeInactive();
  60727. }
  60728. bool OpenGLComponent::isActiveContext() const throw()
  60729. {
  60730. return context != 0 && context->isActive();
  60731. }
  60732. void OpenGLComponent::swapBuffers()
  60733. {
  60734. if (context != 0)
  60735. context->swapBuffers();
  60736. }
  60737. void OpenGLComponent::paint (Graphics&)
  60738. {
  60739. if (renderAndSwapBuffers())
  60740. {
  60741. ComponentPeer* const peer = getPeer();
  60742. if (peer != 0)
  60743. {
  60744. const Point<int> topLeft (getScreenPosition() - peer->getScreenPosition());
  60745. peer->addMaskedRegion (topLeft.getX(), topLeft.getY(), getWidth(), getHeight());
  60746. }
  60747. }
  60748. }
  60749. bool OpenGLComponent::renderAndSwapBuffers()
  60750. {
  60751. const ScopedLock sl (contextLock);
  60752. if (! makeCurrentContextActive())
  60753. return false;
  60754. if (needToUpdateViewport)
  60755. {
  60756. needToUpdateViewport = false;
  60757. juce_glViewport (getWidth(), getHeight());
  60758. }
  60759. renderOpenGL();
  60760. swapBuffers();
  60761. return true;
  60762. }
  60763. void OpenGLComponent::internalRepaint (int x, int y, int w, int h)
  60764. {
  60765. Component::internalRepaint (x, y, w, h);
  60766. if (context != 0)
  60767. context->repaint();
  60768. }
  60769. END_JUCE_NAMESPACE
  60770. #endif
  60771. /*** End of inlined file: juce_OpenGLComponent.cpp ***/
  60772. /*** Start of inlined file: juce_PreferencesPanel.cpp ***/
  60773. BEGIN_JUCE_NAMESPACE
  60774. PreferencesPanel::PreferencesPanel()
  60775. : buttonSize (70)
  60776. {
  60777. }
  60778. PreferencesPanel::~PreferencesPanel()
  60779. {
  60780. currentPage = 0;
  60781. deleteAllChildren();
  60782. }
  60783. void PreferencesPanel::addSettingsPage (const String& title,
  60784. const Drawable* icon,
  60785. const Drawable* overIcon,
  60786. const Drawable* downIcon)
  60787. {
  60788. DrawableButton* button = new DrawableButton (title, DrawableButton::ImageAboveTextLabel);
  60789. button->setImages (icon, overIcon, downIcon);
  60790. button->setRadioGroupId (1);
  60791. button->addButtonListener (this);
  60792. button->setClickingTogglesState (true);
  60793. button->setWantsKeyboardFocus (false);
  60794. addAndMakeVisible (button);
  60795. resized();
  60796. if (currentPage == 0)
  60797. setCurrentPage (title);
  60798. }
  60799. void PreferencesPanel::addSettingsPage (const String& title,
  60800. const char* imageData,
  60801. const int imageDataSize)
  60802. {
  60803. DrawableImage icon, iconOver, iconDown;
  60804. icon.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60805. iconOver.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60806. iconOver.setOverlayColour (Colours::black.withAlpha (0.12f));
  60807. iconDown.setImage (ImageCache::getFromMemory (imageData, imageDataSize), true);
  60808. iconDown.setOverlayColour (Colours::black.withAlpha (0.25f));
  60809. addSettingsPage (title, &icon, &iconOver, &iconDown);
  60810. }
  60811. class PrefsDialogWindow : public DialogWindow
  60812. {
  60813. public:
  60814. PrefsDialogWindow (const String& dialogtitle,
  60815. const Colour& backgroundColour)
  60816. : DialogWindow (dialogtitle, backgroundColour, true)
  60817. {
  60818. }
  60819. ~PrefsDialogWindow()
  60820. {
  60821. }
  60822. void closeButtonPressed()
  60823. {
  60824. exitModalState (0);
  60825. }
  60826. private:
  60827. PrefsDialogWindow (const PrefsDialogWindow&);
  60828. PrefsDialogWindow& operator= (const PrefsDialogWindow&);
  60829. };
  60830. void PreferencesPanel::showInDialogBox (const String& dialogtitle,
  60831. int dialogWidth,
  60832. int dialogHeight,
  60833. const Colour& backgroundColour)
  60834. {
  60835. setSize (dialogWidth, dialogHeight);
  60836. PrefsDialogWindow dw (dialogtitle, backgroundColour);
  60837. dw.setContentComponent (this, true, true);
  60838. dw.centreAroundComponent (0, dw.getWidth(), dw.getHeight());
  60839. dw.runModalLoop();
  60840. dw.setContentComponent (0, false, false);
  60841. }
  60842. void PreferencesPanel::resized()
  60843. {
  60844. int x = 0;
  60845. for (int i = 0; i < getNumChildComponents(); ++i)
  60846. {
  60847. Component* c = getChildComponent (i);
  60848. if (dynamic_cast <DrawableButton*> (c) == 0)
  60849. {
  60850. c->setBounds (0, buttonSize + 5, getWidth(), getHeight() - buttonSize - 5);
  60851. }
  60852. else
  60853. {
  60854. c->setBounds (x, 0, buttonSize, buttonSize);
  60855. x += buttonSize;
  60856. }
  60857. }
  60858. }
  60859. void PreferencesPanel::paint (Graphics& g)
  60860. {
  60861. g.setColour (Colours::grey);
  60862. g.fillRect (0, buttonSize + 2, getWidth(), 1);
  60863. }
  60864. void PreferencesPanel::setCurrentPage (const String& pageName)
  60865. {
  60866. if (currentPageName != pageName)
  60867. {
  60868. currentPageName = pageName;
  60869. currentPage = 0;
  60870. currentPage = createComponentForPage (pageName);
  60871. if (currentPage != 0)
  60872. {
  60873. addAndMakeVisible (currentPage);
  60874. currentPage->toBack();
  60875. resized();
  60876. }
  60877. for (int i = 0; i < getNumChildComponents(); ++i)
  60878. {
  60879. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60880. if (db != 0 && db->getName() == pageName)
  60881. {
  60882. db->setToggleState (true, false);
  60883. break;
  60884. }
  60885. }
  60886. }
  60887. }
  60888. void PreferencesPanel::buttonClicked (Button*)
  60889. {
  60890. for (int i = 0; i < getNumChildComponents(); ++i)
  60891. {
  60892. DrawableButton* db = dynamic_cast <DrawableButton*> (getChildComponent (i));
  60893. if (db != 0 && db->getToggleState())
  60894. {
  60895. setCurrentPage (db->getName());
  60896. break;
  60897. }
  60898. }
  60899. }
  60900. END_JUCE_NAMESPACE
  60901. /*** End of inlined file: juce_PreferencesPanel.cpp ***/
  60902. /*** Start of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60903. #if JUCE_WINDOWS || JUCE_LINUX
  60904. BEGIN_JUCE_NAMESPACE
  60905. SystemTrayIconComponent::SystemTrayIconComponent()
  60906. {
  60907. addToDesktop (0);
  60908. }
  60909. SystemTrayIconComponent::~SystemTrayIconComponent()
  60910. {
  60911. }
  60912. END_JUCE_NAMESPACE
  60913. #endif
  60914. /*** End of inlined file: juce_SystemTrayIconComponent.cpp ***/
  60915. /*** Start of inlined file: juce_AlertWindow.cpp ***/
  60916. BEGIN_JUCE_NAMESPACE
  60917. static const int titleH = 24;
  60918. static const int iconWidth = 80;
  60919. class AlertWindowTextEditor : public TextEditor
  60920. {
  60921. public:
  60922. static const tchar passwordChar;
  60923. AlertWindowTextEditor (const String& name, const bool isPasswordBox)
  60924. : TextEditor (name, isPasswordBox ? passwordChar : 0)
  60925. {
  60926. setSelectAllWhenFocused (true);
  60927. }
  60928. ~AlertWindowTextEditor()
  60929. {
  60930. }
  60931. void returnPressed()
  60932. {
  60933. // pass these up the component hierarchy to be trigger the buttons
  60934. getParentComponent()->keyPressed (KeyPress (KeyPress::returnKey, 0, T('\n')));
  60935. }
  60936. void escapePressed()
  60937. {
  60938. // pass these up the component hierarchy to be trigger the buttons
  60939. getParentComponent()->keyPressed (KeyPress (KeyPress::escapeKey, 0, 0));
  60940. }
  60941. private:
  60942. AlertWindowTextEditor (const AlertWindowTextEditor&);
  60943. AlertWindowTextEditor& operator= (const AlertWindowTextEditor&);
  60944. };
  60945. #if JUCE_LINUX
  60946. const tchar AlertWindowTextEditor::passwordChar = 0x2022;
  60947. #else
  60948. const tchar AlertWindowTextEditor::passwordChar = 0x25cf;
  60949. #endif
  60950. AlertWindow::AlertWindow (const String& title,
  60951. const String& message,
  60952. AlertIconType iconType,
  60953. Component* associatedComponent_)
  60954. : TopLevelWindow (title, true),
  60955. alertIconType (iconType),
  60956. associatedComponent (associatedComponent_)
  60957. {
  60958. if (message.isEmpty())
  60959. text = T(" "); // to force an update if the message is empty
  60960. setMessage (message);
  60961. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  60962. {
  60963. Component* const c = Desktop::getInstance().getComponent (i);
  60964. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  60965. {
  60966. setAlwaysOnTop (true);
  60967. break;
  60968. }
  60969. }
  60970. if (JUCEApplication::getInstance() == 0)
  60971. setAlwaysOnTop (true); // for a plugin, make it always-on-top because the host windows are often top-level
  60972. lookAndFeelChanged();
  60973. constrainer.setMinimumOnscreenAmounts (0x10000, 0x10000, 0x10000, 0x10000);
  60974. }
  60975. AlertWindow::~AlertWindow()
  60976. {
  60977. for (int i = customComps.size(); --i >= 0;)
  60978. removeChildComponent ((Component*) customComps[i]);
  60979. deleteAllChildren();
  60980. }
  60981. void AlertWindow::userTriedToCloseWindow()
  60982. {
  60983. exitModalState (0);
  60984. }
  60985. void AlertWindow::setMessage (const String& message)
  60986. {
  60987. const String newMessage (message.substring (0, 2048));
  60988. if (text != newMessage)
  60989. {
  60990. text = newMessage;
  60991. font.setHeight (15.0f);
  60992. Font titleFont (font.getHeight() * 1.1f, Font::bold);
  60993. textLayout.setText (getName() + T("\n\n"), titleFont);
  60994. textLayout.appendText (text, font);
  60995. updateLayout (true);
  60996. repaint();
  60997. }
  60998. }
  60999. void AlertWindow::buttonClicked (Button* button)
  61000. {
  61001. for (int i = 0; i < buttons.size(); i++)
  61002. {
  61003. TextButton* const c = (TextButton*) buttons[i];
  61004. if (button->getName() == c->getName())
  61005. {
  61006. if (c->getParentComponent() != 0)
  61007. c->getParentComponent()->exitModalState (c->getCommandID());
  61008. break;
  61009. }
  61010. }
  61011. }
  61012. void AlertWindow::addButton (const String& name,
  61013. const int returnValue,
  61014. const KeyPress& shortcutKey1,
  61015. const KeyPress& shortcutKey2)
  61016. {
  61017. TextButton* const b = new TextButton (name, String::empty);
  61018. b->setWantsKeyboardFocus (true);
  61019. b->setMouseClickGrabsKeyboardFocus (false);
  61020. b->setCommandToTrigger (0, returnValue, false);
  61021. b->addShortcut (shortcutKey1);
  61022. b->addShortcut (shortcutKey2);
  61023. b->addButtonListener (this);
  61024. b->changeWidthToFitText (getLookAndFeel().getAlertWindowButtonHeight());
  61025. addAndMakeVisible (b, 0);
  61026. buttons.add (b);
  61027. updateLayout (false);
  61028. }
  61029. int AlertWindow::getNumButtons() const
  61030. {
  61031. return buttons.size();
  61032. }
  61033. void AlertWindow::addTextEditor (const String& name,
  61034. const String& initialContents,
  61035. const String& onScreenLabel,
  61036. const bool isPasswordBox)
  61037. {
  61038. AlertWindowTextEditor* const tc = new AlertWindowTextEditor (name, isPasswordBox);
  61039. tc->setColour (TextEditor::outlineColourId, findColour (ComboBox::outlineColourId));
  61040. tc->setFont (font);
  61041. tc->setText (initialContents);
  61042. tc->setCaretPosition (initialContents.length());
  61043. addAndMakeVisible (tc);
  61044. textBoxes.add (tc);
  61045. allComps.add (tc);
  61046. textboxNames.add (onScreenLabel);
  61047. updateLayout (false);
  61048. }
  61049. const String AlertWindow::getTextEditorContents (const String& nameOfTextEditor) const
  61050. {
  61051. for (int i = textBoxes.size(); --i >= 0;)
  61052. if (((TextEditor*)textBoxes[i])->getName() == nameOfTextEditor)
  61053. return ((TextEditor*)textBoxes[i])->getText();
  61054. return String::empty;
  61055. }
  61056. void AlertWindow::addComboBox (const String& name,
  61057. const StringArray& items,
  61058. const String& onScreenLabel)
  61059. {
  61060. ComboBox* const cb = new ComboBox (name);
  61061. for (int i = 0; i < items.size(); ++i)
  61062. cb->addItem (items[i], i + 1);
  61063. addAndMakeVisible (cb);
  61064. cb->setSelectedItemIndex (0);
  61065. comboBoxes.add (cb);
  61066. allComps.add (cb);
  61067. comboBoxNames.add (onScreenLabel);
  61068. updateLayout (false);
  61069. }
  61070. ComboBox* AlertWindow::getComboBoxComponent (const String& nameOfList) const
  61071. {
  61072. for (int i = comboBoxes.size(); --i >= 0;)
  61073. if (((ComboBox*) comboBoxes[i])->getName() == nameOfList)
  61074. return (ComboBox*) comboBoxes[i];
  61075. return 0;
  61076. }
  61077. class AlertTextComp : public TextEditor
  61078. {
  61079. public:
  61080. AlertTextComp (const String& message,
  61081. const Font& font)
  61082. {
  61083. setReadOnly (true);
  61084. setMultiLine (true, true);
  61085. setCaretVisible (false);
  61086. setScrollbarsShown (true);
  61087. lookAndFeelChanged();
  61088. setWantsKeyboardFocus (false);
  61089. setFont (font);
  61090. setText (message, false);
  61091. bestWidth = 2 * (int) sqrt (font.getHeight() * font.getStringWidth (message));
  61092. setColour (TextEditor::backgroundColourId, Colours::transparentBlack);
  61093. setColour (TextEditor::outlineColourId, Colours::transparentBlack);
  61094. setColour (TextEditor::shadowColourId, Colours::transparentBlack);
  61095. }
  61096. ~AlertTextComp()
  61097. {
  61098. }
  61099. int getPreferredWidth() const throw() { return bestWidth; }
  61100. void updateLayout (const int width)
  61101. {
  61102. TextLayout text;
  61103. text.appendText (getText(), getFont());
  61104. text.layout (width - 8, Justification::topLeft, true);
  61105. setSize (width, jmin (width, text.getHeight() + (int) getFont().getHeight()));
  61106. }
  61107. private:
  61108. int bestWidth;
  61109. AlertTextComp (const AlertTextComp&);
  61110. AlertTextComp& operator= (const AlertTextComp&);
  61111. };
  61112. void AlertWindow::addTextBlock (const String& text)
  61113. {
  61114. AlertTextComp* const c = new AlertTextComp (text, font);
  61115. textBlocks.add (c);
  61116. allComps.add (c);
  61117. addAndMakeVisible (c);
  61118. updateLayout (false);
  61119. }
  61120. void AlertWindow::addProgressBarComponent (double& progressValue)
  61121. {
  61122. ProgressBar* const pb = new ProgressBar (progressValue);
  61123. progressBars.add (pb);
  61124. allComps.add (pb);
  61125. addAndMakeVisible (pb);
  61126. updateLayout (false);
  61127. }
  61128. void AlertWindow::addCustomComponent (Component* const component)
  61129. {
  61130. customComps.add (component);
  61131. allComps.add (component);
  61132. addAndMakeVisible (component);
  61133. updateLayout (false);
  61134. }
  61135. int AlertWindow::getNumCustomComponents() const
  61136. {
  61137. return customComps.size();
  61138. }
  61139. Component* AlertWindow::getCustomComponent (const int index) const
  61140. {
  61141. return (Component*) customComps [index];
  61142. }
  61143. Component* AlertWindow::removeCustomComponent (const int index)
  61144. {
  61145. Component* const c = getCustomComponent (index);
  61146. if (c != 0)
  61147. {
  61148. customComps.removeValue (c);
  61149. allComps.removeValue (c);
  61150. removeChildComponent (c);
  61151. updateLayout (false);
  61152. }
  61153. return c;
  61154. }
  61155. void AlertWindow::paint (Graphics& g)
  61156. {
  61157. getLookAndFeel().drawAlertBox (g, *this, textArea, textLayout);
  61158. g.setColour (findColour (textColourId));
  61159. g.setFont (getLookAndFeel().getAlertWindowFont());
  61160. int i;
  61161. for (i = textBoxes.size(); --i >= 0;)
  61162. {
  61163. const TextEditor* const te = (TextEditor*) textBoxes[i];
  61164. g.drawFittedText (textboxNames[i],
  61165. te->getX(), te->getY() - 14,
  61166. te->getWidth(), 14,
  61167. Justification::centredLeft, 1);
  61168. }
  61169. for (i = comboBoxNames.size(); --i >= 0;)
  61170. {
  61171. const ComboBox* const cb = (ComboBox*) comboBoxes[i];
  61172. g.drawFittedText (comboBoxNames[i],
  61173. cb->getX(), cb->getY() - 14,
  61174. cb->getWidth(), 14,
  61175. Justification::centredLeft, 1);
  61176. }
  61177. for (i = customComps.size(); --i >= 0;)
  61178. {
  61179. const Component* const c = (Component*) customComps[i];
  61180. g.drawFittedText (c->getName(),
  61181. c->getX(), c->getY() - 14,
  61182. c->getWidth(), 14,
  61183. Justification::centredLeft, 1);
  61184. }
  61185. }
  61186. void AlertWindow::updateLayout (const bool onlyIncreaseSize)
  61187. {
  61188. const int wid = jmax (font.getStringWidth (text),
  61189. font.getStringWidth (getName()));
  61190. const int sw = (int) sqrt (font.getHeight() * wid);
  61191. int w = jmin (300 + sw * 2, (int) (getParentWidth() * 0.7f));
  61192. const int edgeGap = 10;
  61193. const int labelHeight = 18;
  61194. int iconSpace;
  61195. if (alertIconType == NoIcon)
  61196. {
  61197. textLayout.layout (w, Justification::horizontallyCentred, true);
  61198. iconSpace = 0;
  61199. }
  61200. else
  61201. {
  61202. textLayout.layout (w, Justification::left, true);
  61203. iconSpace = iconWidth;
  61204. }
  61205. w = jmax (350, textLayout.getWidth() + iconSpace + edgeGap * 4);
  61206. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61207. const int textLayoutH = textLayout.getHeight();
  61208. const int textBottom = 16 + titleH + textLayoutH;
  61209. int h = textBottom;
  61210. int buttonW = 40;
  61211. int i;
  61212. for (i = 0; i < buttons.size(); ++i)
  61213. buttonW += 16 + ((const TextButton*) buttons[i])->getWidth();
  61214. w = jmax (buttonW, w);
  61215. h += (textBoxes.size() + comboBoxes.size() + progressBars.size()) * 50;
  61216. if (buttons.size() > 0)
  61217. h += 20 + ((TextButton*) buttons[0])->getHeight();
  61218. for (i = customComps.size(); --i >= 0;)
  61219. {
  61220. Component* c = (Component*) customComps[i];
  61221. w = jmax (w, (c->getWidth() * 100) / 80);
  61222. h += 10 + c->getHeight();
  61223. if (c->getName().isNotEmpty())
  61224. h += labelHeight;
  61225. }
  61226. for (i = textBlocks.size(); --i >= 0;)
  61227. {
  61228. const AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61229. w = jmax (w, ac->getPreferredWidth());
  61230. }
  61231. w = jmin (w, (int) (getParentWidth() * 0.7f));
  61232. for (i = textBlocks.size(); --i >= 0;)
  61233. {
  61234. AlertTextComp* const ac = (AlertTextComp*) textBlocks[i];
  61235. ac->updateLayout ((int) (w * 0.8f));
  61236. h += ac->getHeight() + 10;
  61237. }
  61238. h = jmin (getParentHeight() - 50, h);
  61239. if (onlyIncreaseSize)
  61240. {
  61241. w = jmax (w, getWidth());
  61242. h = jmax (h, getHeight());
  61243. }
  61244. if (! isVisible())
  61245. {
  61246. centreAroundComponent (associatedComponent, w, h);
  61247. }
  61248. else
  61249. {
  61250. const int cx = getX() + getWidth() / 2;
  61251. const int cy = getY() + getHeight() / 2;
  61252. setBounds (cx - w / 2,
  61253. cy - h / 2,
  61254. w, h);
  61255. }
  61256. textArea.setBounds (edgeGap, edgeGap, w - (edgeGap * 2), h - edgeGap);
  61257. const int spacer = 16;
  61258. int totalWidth = -spacer;
  61259. for (i = buttons.size(); --i >= 0;)
  61260. totalWidth += ((TextButton*) buttons[i])->getWidth() + spacer;
  61261. int x = (w - totalWidth) / 2;
  61262. int y = (int) (getHeight() * 0.95f);
  61263. for (i = 0; i < buttons.size(); ++i)
  61264. {
  61265. TextButton* const c = (TextButton*) buttons[i];
  61266. int ny = proportionOfHeight (0.95f) - c->getHeight();
  61267. c->setTopLeftPosition (x, ny);
  61268. if (ny < y)
  61269. y = ny;
  61270. x += c->getWidth() + spacer;
  61271. c->toFront (false);
  61272. }
  61273. y = textBottom;
  61274. for (i = 0; i < allComps.size(); ++i)
  61275. {
  61276. Component* const c = (Component*) allComps[i];
  61277. int h = 22;
  61278. const int comboIndex = comboBoxes.indexOf (c);
  61279. if (comboIndex >= 0 && comboBoxNames [comboIndex].isNotEmpty())
  61280. y += labelHeight;
  61281. const int tbIndex = textBoxes.indexOf (c);
  61282. if (tbIndex >= 0 && textboxNames[tbIndex].isNotEmpty())
  61283. y += labelHeight;
  61284. if (customComps.contains (c))
  61285. {
  61286. if (c->getName().isNotEmpty())
  61287. y += labelHeight;
  61288. c->setTopLeftPosition (proportionOfWidth (0.1f), y);
  61289. h = c->getHeight();
  61290. }
  61291. else if (textBlocks.contains (c))
  61292. {
  61293. c->setTopLeftPosition ((getWidth() - c->getWidth()) / 2, y);
  61294. h = c->getHeight();
  61295. }
  61296. else
  61297. {
  61298. c->setBounds (proportionOfWidth (0.1f), y, proportionOfWidth (0.8f), h);
  61299. }
  61300. y += h + 10;
  61301. }
  61302. setWantsKeyboardFocus (getNumChildComponents() == 0);
  61303. }
  61304. bool AlertWindow::containsAnyExtraComponents() const
  61305. {
  61306. return textBoxes.size()
  61307. + comboBoxes.size()
  61308. + progressBars.size()
  61309. + customComps.size() > 0;
  61310. }
  61311. void AlertWindow::mouseDown (const MouseEvent&)
  61312. {
  61313. dragger.startDraggingComponent (this, &constrainer);
  61314. }
  61315. void AlertWindow::mouseDrag (const MouseEvent& e)
  61316. {
  61317. dragger.dragComponent (this, e);
  61318. }
  61319. bool AlertWindow::keyPressed (const KeyPress& key)
  61320. {
  61321. for (int i = buttons.size(); --i >= 0;)
  61322. {
  61323. TextButton* const b = (TextButton*) buttons[i];
  61324. if (b->isRegisteredForShortcut (key))
  61325. {
  61326. b->triggerClick();
  61327. return true;
  61328. }
  61329. }
  61330. if (key.isKeyCode (KeyPress::escapeKey) && buttons.size() == 0)
  61331. {
  61332. exitModalState (0);
  61333. return true;
  61334. }
  61335. else if (key.isKeyCode (KeyPress::returnKey) && buttons.size() == 1)
  61336. {
  61337. ((TextButton*) buttons.getFirst())->triggerClick();
  61338. return true;
  61339. }
  61340. return false;
  61341. }
  61342. void AlertWindow::lookAndFeelChanged()
  61343. {
  61344. const int flags = getLookAndFeel().getAlertBoxWindowFlags();
  61345. setUsingNativeTitleBar ((flags & ComponentPeer::windowHasTitleBar) != 0);
  61346. setDropShadowEnabled (isOpaque() && (flags & ComponentPeer::windowHasDropShadow) != 0);
  61347. }
  61348. int AlertWindow::getDesktopWindowStyleFlags() const
  61349. {
  61350. return getLookAndFeel().getAlertBoxWindowFlags();
  61351. }
  61352. struct AlertWindowInfo
  61353. {
  61354. String title, message, button1, button2, button3;
  61355. AlertWindow::AlertIconType iconType;
  61356. int numButtons;
  61357. Component* associatedComponent;
  61358. int run() const
  61359. {
  61360. return (int) (pointer_sized_int)
  61361. MessageManager::getInstance()->callFunctionOnMessageThread (showCallback, (void*) this);
  61362. }
  61363. private:
  61364. int show() const
  61365. {
  61366. jassert (associatedComponent == 0 || associatedComponent->isValidComponent()); // has your comp been deleted?
  61367. LookAndFeel& lf = associatedComponent->isValidComponent() ? associatedComponent->getLookAndFeel()
  61368. : LookAndFeel::getDefaultLookAndFeel();
  61369. ScopedPointer <Component> alertBox (lf.createAlertWindow (title, message, button1, button2, button3,
  61370. iconType, numButtons, associatedComponent));
  61371. jassert (alertBox != 0); // you have to return one of these!
  61372. return alertBox->runModalLoop();
  61373. }
  61374. static void* showCallback (void* userData)
  61375. {
  61376. return (void*) (pointer_sized_int) ((const AlertWindowInfo*) userData)->show();
  61377. }
  61378. };
  61379. void AlertWindow::showMessageBox (AlertIconType iconType,
  61380. const String& title,
  61381. const String& message,
  61382. const String& buttonText,
  61383. Component* associatedComponent)
  61384. {
  61385. AlertWindowInfo info;
  61386. info.title = title;
  61387. info.message = message;
  61388. info.button1 = buttonText.isEmpty() ? TRANS("ok") : buttonText;
  61389. info.iconType = iconType;
  61390. info.numButtons = 1;
  61391. info.associatedComponent = associatedComponent;
  61392. info.run();
  61393. }
  61394. bool AlertWindow::showOkCancelBox (AlertIconType iconType,
  61395. const String& title,
  61396. const String& message,
  61397. const String& button1Text,
  61398. const String& button2Text,
  61399. Component* associatedComponent)
  61400. {
  61401. AlertWindowInfo info;
  61402. info.title = title;
  61403. info.message = message;
  61404. info.button1 = button1Text.isEmpty() ? TRANS("ok") : button1Text;
  61405. info.button2 = button2Text.isEmpty() ? TRANS("cancel") : button2Text;
  61406. info.iconType = iconType;
  61407. info.numButtons = 2;
  61408. info.associatedComponent = associatedComponent;
  61409. return info.run() != 0;
  61410. }
  61411. int AlertWindow::showYesNoCancelBox (AlertIconType iconType,
  61412. const String& title,
  61413. const String& message,
  61414. const String& button1Text,
  61415. const String& button2Text,
  61416. const String& button3Text,
  61417. Component* associatedComponent)
  61418. {
  61419. AlertWindowInfo info;
  61420. info.title = title;
  61421. info.message = message;
  61422. info.button1 = button1Text.isEmpty() ? TRANS("yes") : button1Text;
  61423. info.button2 = button2Text.isEmpty() ? TRANS("no") : button2Text;
  61424. info.button3 = button3Text.isEmpty() ? TRANS("cancel") : button3Text;
  61425. info.iconType = iconType;
  61426. info.numButtons = 3;
  61427. info.associatedComponent = associatedComponent;
  61428. return info.run();
  61429. }
  61430. END_JUCE_NAMESPACE
  61431. /*** End of inlined file: juce_AlertWindow.cpp ***/
  61432. /*** Start of inlined file: juce_ComponentPeer.cpp ***/
  61433. BEGIN_JUCE_NAMESPACE
  61434. //#define JUCE_ENABLE_REPAINT_DEBUGGING 1
  61435. static const int fakeMouseMoveMessage = 0x7fff00ff;
  61436. static VoidArray heavyweightPeers;
  61437. ComponentPeer::ComponentPeer (Component* const component_,
  61438. const int styleFlags_) throw()
  61439. : component (component_),
  61440. styleFlags (styleFlags_),
  61441. lastPaintTime (0),
  61442. constrainer (0),
  61443. lastFocusedComponent (0),
  61444. lastDragAndDropCompUnderMouse (0),
  61445. fakeMouseMessageSent (false),
  61446. isWindowMinimised (false)
  61447. {
  61448. heavyweightPeers.add (this);
  61449. }
  61450. ComponentPeer::~ComponentPeer()
  61451. {
  61452. heavyweightPeers.removeValue (this);
  61453. Desktop::getInstance().triggerFocusCallback();
  61454. }
  61455. int ComponentPeer::getNumPeers() throw()
  61456. {
  61457. return heavyweightPeers.size();
  61458. }
  61459. ComponentPeer* ComponentPeer::getPeer (const int index) throw()
  61460. {
  61461. return (ComponentPeer*) heavyweightPeers [index];
  61462. }
  61463. ComponentPeer* ComponentPeer::getPeerFor (const Component* const component) throw()
  61464. {
  61465. for (int i = heavyweightPeers.size(); --i >= 0;)
  61466. {
  61467. ComponentPeer* const peer = (ComponentPeer*) heavyweightPeers.getUnchecked(i);
  61468. if (peer->getComponent() == component)
  61469. return peer;
  61470. }
  61471. return 0;
  61472. }
  61473. bool ComponentPeer::isValidPeer (const ComponentPeer* const peer) throw()
  61474. {
  61475. return heavyweightPeers.contains (const_cast <ComponentPeer*> (peer));
  61476. }
  61477. void ComponentPeer::updateCurrentModifiers() throw()
  61478. {
  61479. ModifierKeys::updateCurrentModifiers();
  61480. }
  61481. void ComponentPeer::handleMouseEnter (const Point<int>& position, const int64 time)
  61482. {
  61483. jassert (component->isValidComponent());
  61484. updateCurrentModifiers();
  61485. Component* c = component->getComponentAt (position);
  61486. const ComponentDeletionWatcher deletionChecker (component);
  61487. if (c != Component::componentUnderMouse && Component::componentUnderMouse != 0)
  61488. {
  61489. jassert (Component::componentUnderMouse->isValidComponent());
  61490. const Point<int> relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position));
  61491. Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time);
  61492. Component::componentUnderMouse = 0;
  61493. if (deletionChecker.hasBeenDeleted())
  61494. return;
  61495. c = component->getComponentAt (position);
  61496. }
  61497. Component::componentUnderMouse = c;
  61498. if (Component::componentUnderMouse != 0)
  61499. {
  61500. const Point<int> relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position));
  61501. Component::componentUnderMouse->internalMouseEnter (relPos.getX(), relPos.getY(), time);
  61502. }
  61503. }
  61504. void ComponentPeer::handleMouseMove (const Point<int>& position, const int64 time)
  61505. {
  61506. jassert (component->isValidComponent());
  61507. updateCurrentModifiers();
  61508. fakeMouseMessageSent = false;
  61509. const ComponentDeletionWatcher deletionChecker (component);
  61510. Component* c = component->getComponentAt (position);
  61511. if (c != Component::componentUnderMouse)
  61512. {
  61513. if (Component::componentUnderMouse != 0)
  61514. {
  61515. const Point<int> relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position));
  61516. Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time);
  61517. Component::componentUnderMouse = 0;
  61518. if (deletionChecker.hasBeenDeleted())
  61519. return; // if this window has just been deleted..
  61520. c = component->getComponentAt (position);
  61521. }
  61522. Component::componentUnderMouse = c;
  61523. if (c != 0)
  61524. {
  61525. const Point<int> relPos (component->relativePositionToOtherComponent (c, position));
  61526. c->internalMouseEnter (relPos.getX(), relPos.getY(), time);
  61527. if (deletionChecker.hasBeenDeleted())
  61528. return; // if this window has just been deleted..
  61529. }
  61530. }
  61531. if (Component::componentUnderMouse != 0)
  61532. {
  61533. const Point<int> relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position));
  61534. Component::componentUnderMouse->internalMouseMove (relPos.getX(), relPos.getY(), time);
  61535. }
  61536. }
  61537. void ComponentPeer::handleMouseDown (const Point<int>& position, const int64 time)
  61538. {
  61539. Desktop::getInstance().incrementMouseClickCounter();
  61540. updateCurrentModifiers();
  61541. if (ModifierKeys::getCurrentModifiers().getNumMouseButtonsDown() == 1)
  61542. {
  61543. Component::componentUnderMouse = component->getComponentAt (position);
  61544. if (Component::componentUnderMouse != 0)
  61545. {
  61546. const Point<int> relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position));
  61547. Component::componentUnderMouse->internalMouseDown (relPos.getX(), relPos.getY(), time);
  61548. }
  61549. }
  61550. }
  61551. void ComponentPeer::handleMouseDrag (const Point<int>& position, const int64 time)
  61552. {
  61553. updateCurrentModifiers();
  61554. if (Component::componentUnderMouse != 0)
  61555. {
  61556. const Point<int> relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position));
  61557. Component::componentUnderMouse->internalMouseDrag (relPos.getX(), relPos.getY(), time);
  61558. }
  61559. }
  61560. void ComponentPeer::handleMouseUp (const int oldModifiers, const Point<int>& position, const int64 time)
  61561. {
  61562. updateCurrentModifiers();
  61563. if (ModifierKeys (oldModifiers).getNumMouseButtonsDown() == 1)
  61564. {
  61565. const ComponentDeletionWatcher deletionChecker (component);
  61566. Component* c = component->getComponentAt (position);
  61567. if (c != Component::componentUnderMouse)
  61568. {
  61569. if (Component::componentUnderMouse != 0)
  61570. {
  61571. const Point<int> relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position));
  61572. Component::componentUnderMouse->internalMouseUp (oldModifiers, relPos.getX(), relPos.getY(), time);
  61573. if (Component::componentUnderMouse != 0)
  61574. Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time);
  61575. if (deletionChecker.hasBeenDeleted())
  61576. return;
  61577. c = component->getComponentAt (position);
  61578. }
  61579. Component::componentUnderMouse = c;
  61580. if (Component::componentUnderMouse != 0)
  61581. {
  61582. const Point<int> relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position));
  61583. Component::componentUnderMouse->internalMouseEnter (relPos.getX(), relPos.getY(), time);
  61584. }
  61585. }
  61586. else
  61587. {
  61588. if (Component::componentUnderMouse != 0)
  61589. {
  61590. const Point<int> relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position));
  61591. Component::componentUnderMouse->internalMouseUp (oldModifiers, relPos.getX(), relPos.getY(), time);
  61592. }
  61593. }
  61594. }
  61595. }
  61596. void ComponentPeer::handleMouseExit (const Point<int>& position, const int64 time)
  61597. {
  61598. jassert (component->isValidComponent());
  61599. updateCurrentModifiers();
  61600. if (Component::componentUnderMouse != 0)
  61601. {
  61602. const Point<int> relPos (component->relativePositionToOtherComponent (Component::componentUnderMouse, position));
  61603. Component::componentUnderMouse->internalMouseExit (relPos.getX(), relPos.getY(), time);
  61604. Component::componentUnderMouse = 0;
  61605. }
  61606. }
  61607. void ComponentPeer::handleMouseWheel (const int amountX, const int amountY, const int64 time)
  61608. {
  61609. updateCurrentModifiers();
  61610. if (Component::componentUnderMouse != 0)
  61611. Component::componentUnderMouse->internalMouseWheel (amountX, amountY, time);
  61612. }
  61613. void ComponentPeer::sendFakeMouseMove() throw()
  61614. {
  61615. if ((! fakeMouseMessageSent)
  61616. && component->flags.hasHeavyweightPeerFlag
  61617. && ! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  61618. {
  61619. if (! isMinimised())
  61620. component->bounds_ = getBounds();
  61621. const Point<int> pos (component->getMouseXYRelative());
  61622. if (((unsigned int) pos.getX()) < (unsigned int) component->getWidth()
  61623. && ((unsigned int) pos.getY()) < (unsigned int) component->getHeight()
  61624. && contains (pos.getX(), pos.getY(), false))
  61625. {
  61626. postMessage (new Message (fakeMouseMoveMessage, pos.getX(), pos.getY(), 0));
  61627. }
  61628. fakeMouseMessageSent = true;
  61629. }
  61630. }
  61631. void ComponentPeer::handleMessage (const Message& message)
  61632. {
  61633. if (message.intParameter1 == fakeMouseMoveMessage)
  61634. {
  61635. if (! ModifierKeys::getCurrentModifiers().isAnyMouseButtonDown())
  61636. handleMouseMove (Point<int> (message.intParameter2, message.intParameter3),
  61637. Time::currentTimeMillis());
  61638. }
  61639. }
  61640. void ComponentPeer::handlePaint (LowLevelGraphicsContext& contextToPaintTo)
  61641. {
  61642. Graphics g (&contextToPaintTo);
  61643. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61644. g.saveState();
  61645. #endif
  61646. JUCE_TRY
  61647. {
  61648. component->paintEntireComponent (g);
  61649. }
  61650. JUCE_CATCH_EXCEPTION
  61651. #if JUCE_ENABLE_REPAINT_DEBUGGING
  61652. // enabling this code will fill all areas that get repainted with a colour overlay, to show
  61653. // clearly when things are being repainted.
  61654. {
  61655. g.restoreState();
  61656. g.fillAll (Colour ((uint8) Random::getSystemRandom().nextInt (255),
  61657. (uint8) Random::getSystemRandom().nextInt (255),
  61658. (uint8) Random::getSystemRandom().nextInt (255),
  61659. (uint8) 0x50));
  61660. }
  61661. #endif
  61662. }
  61663. bool ComponentPeer::handleKeyPress (const int keyCode,
  61664. const juce_wchar textCharacter)
  61665. {
  61666. updateCurrentModifiers();
  61667. Component* target = Component::currentlyFocusedComponent->isValidComponent()
  61668. ? Component::currentlyFocusedComponent
  61669. : component;
  61670. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61671. {
  61672. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61673. if (currentModalComp != 0)
  61674. target = currentModalComp;
  61675. }
  61676. const KeyPress keyInfo (keyCode,
  61677. ModifierKeys::getCurrentModifiers().getRawFlags()
  61678. & ModifierKeys::allKeyboardModifiers,
  61679. textCharacter);
  61680. bool keyWasUsed = false;
  61681. while (target != 0)
  61682. {
  61683. const ComponentDeletionWatcher deletionChecker (target);
  61684. if (target->keyListeners_ != 0)
  61685. {
  61686. for (int i = target->keyListeners_->size(); --i >= 0;)
  61687. {
  61688. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyPressed (keyInfo, target);
  61689. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61690. return keyWasUsed;
  61691. i = jmin (i, target->keyListeners_->size());
  61692. }
  61693. }
  61694. keyWasUsed = target->keyPressed (keyInfo);
  61695. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61696. break;
  61697. if (keyInfo.isKeyCode (KeyPress::tabKey) && Component::getCurrentlyFocusedComponent() != 0)
  61698. {
  61699. Component* const currentlyFocused = Component::getCurrentlyFocusedComponent();
  61700. currentlyFocused->moveKeyboardFocusToSibling (! keyInfo.getModifiers().isShiftDown());
  61701. keyWasUsed = (currentlyFocused != Component::getCurrentlyFocusedComponent());
  61702. break;
  61703. }
  61704. target = target->parentComponent_;
  61705. }
  61706. return keyWasUsed;
  61707. }
  61708. bool ComponentPeer::handleKeyUpOrDown (const bool isKeyDown)
  61709. {
  61710. updateCurrentModifiers();
  61711. Component* target = Component::currentlyFocusedComponent->isValidComponent()
  61712. ? Component::currentlyFocusedComponent
  61713. : component;
  61714. if (target->isCurrentlyBlockedByAnotherModalComponent())
  61715. {
  61716. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  61717. if (currentModalComp != 0)
  61718. target = currentModalComp;
  61719. }
  61720. bool keyWasUsed = false;
  61721. while (target != 0)
  61722. {
  61723. const ComponentDeletionWatcher deletionChecker (target);
  61724. keyWasUsed = target->keyStateChanged (isKeyDown);
  61725. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61726. break;
  61727. if (target->keyListeners_ != 0)
  61728. {
  61729. for (int i = target->keyListeners_->size(); --i >= 0;)
  61730. {
  61731. keyWasUsed = ((KeyListener*) target->keyListeners_->getUnchecked(i))->keyStateChanged (isKeyDown, target);
  61732. if (keyWasUsed || deletionChecker.hasBeenDeleted())
  61733. return keyWasUsed;
  61734. i = jmin (i, target->keyListeners_->size());
  61735. }
  61736. }
  61737. target = target->parentComponent_;
  61738. }
  61739. return keyWasUsed;
  61740. }
  61741. void ComponentPeer::handleModifierKeysChange()
  61742. {
  61743. updateCurrentModifiers();
  61744. Component* target = Component::getComponentUnderMouse();
  61745. if (target == 0)
  61746. target = Component::getCurrentlyFocusedComponent();
  61747. if (target == 0)
  61748. target = component;
  61749. if (target->isValidComponent())
  61750. target->internalModifierKeysChanged();
  61751. }
  61752. TextInputTarget* ComponentPeer::findCurrentTextInputTarget()
  61753. {
  61754. Component* const c = Component::getCurrentlyFocusedComponent();
  61755. if (component->isParentOf (c))
  61756. return dynamic_cast <TextInputTarget*> (c);
  61757. return 0;
  61758. }
  61759. void ComponentPeer::handleBroughtToFront()
  61760. {
  61761. updateCurrentModifiers();
  61762. if (component != 0)
  61763. component->internalBroughtToFront();
  61764. }
  61765. void ComponentPeer::setConstrainer (ComponentBoundsConstrainer* const newConstrainer) throw()
  61766. {
  61767. constrainer = newConstrainer;
  61768. }
  61769. void ComponentPeer::handleMovedOrResized()
  61770. {
  61771. jassert (component->isValidComponent());
  61772. updateCurrentModifiers();
  61773. const bool nowMinimised = isMinimised();
  61774. if (component->flags.hasHeavyweightPeerFlag && ! nowMinimised)
  61775. {
  61776. const ComponentDeletionWatcher deletionChecker (component);
  61777. const Rectangle<int> newBounds (getBounds());
  61778. const bool wasMoved = (component->getPosition() != newBounds.getPosition());
  61779. const bool wasResized = (component->getWidth() != newBounds.getWidth() || component->getHeight() != newBounds.getHeight());
  61780. if (wasMoved || wasResized)
  61781. {
  61782. component->bounds_ = newBounds;
  61783. if (wasResized)
  61784. component->repaint();
  61785. component->sendMovedResizedMessages (wasMoved, wasResized);
  61786. if (deletionChecker.hasBeenDeleted())
  61787. return;
  61788. }
  61789. }
  61790. if (isWindowMinimised != nowMinimised)
  61791. {
  61792. isWindowMinimised = nowMinimised;
  61793. component->minimisationStateChanged (nowMinimised);
  61794. component->sendVisibilityChangeMessage();
  61795. }
  61796. if (! isFullScreen())
  61797. lastNonFullscreenBounds = component->getBounds();
  61798. }
  61799. void ComponentPeer::handleFocusGain()
  61800. {
  61801. updateCurrentModifiers();
  61802. if (component->isParentOf (lastFocusedComponent))
  61803. {
  61804. Component::currentlyFocusedComponent = lastFocusedComponent;
  61805. Desktop::getInstance().triggerFocusCallback();
  61806. lastFocusedComponent->internalFocusGain (Component::focusChangedDirectly);
  61807. }
  61808. else
  61809. {
  61810. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  61811. component->grabKeyboardFocus();
  61812. else
  61813. Component::bringModalComponentToFront();
  61814. }
  61815. }
  61816. void ComponentPeer::handleFocusLoss()
  61817. {
  61818. updateCurrentModifiers();
  61819. if (component->hasKeyboardFocus (true))
  61820. {
  61821. lastFocusedComponent = Component::currentlyFocusedComponent;
  61822. if (lastFocusedComponent != 0)
  61823. {
  61824. Component::currentlyFocusedComponent = 0;
  61825. Desktop::getInstance().triggerFocusCallback();
  61826. lastFocusedComponent->internalFocusLoss (Component::focusChangedByMouseClick);
  61827. }
  61828. }
  61829. }
  61830. Component* ComponentPeer::getLastFocusedSubcomponent() const throw()
  61831. {
  61832. return (component->isParentOf (lastFocusedComponent) && lastFocusedComponent->isShowing())
  61833. ? lastFocusedComponent
  61834. : component;
  61835. }
  61836. void ComponentPeer::handleScreenSizeChange()
  61837. {
  61838. updateCurrentModifiers();
  61839. component->parentSizeChanged();
  61840. handleMovedOrResized();
  61841. }
  61842. void ComponentPeer::setNonFullScreenBounds (const Rectangle<int>& newBounds) throw()
  61843. {
  61844. lastNonFullscreenBounds = newBounds;
  61845. }
  61846. const Rectangle<int>& ComponentPeer::getNonFullScreenBounds() const throw()
  61847. {
  61848. return lastNonFullscreenBounds;
  61849. }
  61850. static FileDragAndDropTarget* findDragAndDropTarget (Component* c,
  61851. const StringArray& files,
  61852. FileDragAndDropTarget* const lastOne)
  61853. {
  61854. while (c != 0)
  61855. {
  61856. FileDragAndDropTarget* const t = dynamic_cast <FileDragAndDropTarget*> (c);
  61857. if (t != 0 && (t == lastOne || t->isInterestedInFileDrag (files)))
  61858. return t;
  61859. c = c->getParentComponent();
  61860. }
  61861. return 0;
  61862. }
  61863. void ComponentPeer::handleFileDragMove (const StringArray& files, const Point<int>& position)
  61864. {
  61865. updateCurrentModifiers();
  61866. FileDragAndDropTarget* lastTarget = 0;
  61867. if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted())
  61868. lastTarget = const_cast <FileDragAndDropTarget*> (dynamic_cast <const FileDragAndDropTarget*> (dragAndDropTargetComponent->getComponent()));
  61869. FileDragAndDropTarget* newTarget = 0;
  61870. Component* const compUnderMouse = component->getComponentAt (position);
  61871. if (compUnderMouse != lastDragAndDropCompUnderMouse)
  61872. {
  61873. lastDragAndDropCompUnderMouse = compUnderMouse;
  61874. newTarget = findDragAndDropTarget (compUnderMouse, files, lastTarget);
  61875. if (newTarget != lastTarget)
  61876. {
  61877. if (lastTarget != 0)
  61878. lastTarget->fileDragExit (files);
  61879. dragAndDropTargetComponent = 0;
  61880. if (newTarget != 0)
  61881. {
  61882. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61883. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61884. dragAndDropTargetComponent = new ComponentDeletionWatcher (dynamic_cast <Component*> (newTarget));
  61885. newTarget->fileDragEnter (files, pos.getX(), pos.getY());
  61886. }
  61887. }
  61888. }
  61889. else
  61890. {
  61891. newTarget = lastTarget;
  61892. }
  61893. if (newTarget != 0)
  61894. {
  61895. Component* const targetComp = dynamic_cast <Component*> (newTarget);
  61896. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61897. newTarget->fileDragMove (files, pos.getX(), pos.getY());
  61898. }
  61899. }
  61900. void ComponentPeer::handleFileDragExit (const StringArray& files)
  61901. {
  61902. handleFileDragMove (files, Point<int> (-1, -1));
  61903. jassert (dragAndDropTargetComponent == 0);
  61904. lastDragAndDropCompUnderMouse = 0;
  61905. }
  61906. void ComponentPeer::handleFileDragDrop (const StringArray& files, const Point<int>& position)
  61907. {
  61908. handleFileDragMove (files, position);
  61909. if (dragAndDropTargetComponent != 0 && ! dragAndDropTargetComponent->hasBeenDeleted())
  61910. {
  61911. FileDragAndDropTarget* const target = const_cast <FileDragAndDropTarget*> (dynamic_cast <const FileDragAndDropTarget*> (dragAndDropTargetComponent->getComponent()));
  61912. dragAndDropTargetComponent = 0;
  61913. lastDragAndDropCompUnderMouse = 0;
  61914. if (target != 0)
  61915. {
  61916. Component* const targetComp = dynamic_cast <Component*> (target);
  61917. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61918. {
  61919. targetComp->internalModalInputAttempt();
  61920. if (targetComp->isCurrentlyBlockedByAnotherModalComponent())
  61921. return;
  61922. }
  61923. const Point<int> pos (component->relativePositionToOtherComponent (targetComp, position));
  61924. target->filesDropped (files, pos.getX(), pos.getY());
  61925. }
  61926. }
  61927. }
  61928. void ComponentPeer::handleUserClosingWindow()
  61929. {
  61930. updateCurrentModifiers();
  61931. component->userTriedToCloseWindow();
  61932. }
  61933. void ComponentPeer::bringModalComponentToFront()
  61934. {
  61935. Component::bringModalComponentToFront();
  61936. }
  61937. void ComponentPeer::clearMaskedRegion() throw()
  61938. {
  61939. maskedRegion.clear();
  61940. }
  61941. void ComponentPeer::addMaskedRegion (int x, int y, int w, int h) throw()
  61942. {
  61943. maskedRegion.add (x, y, w, h);
  61944. }
  61945. const StringArray ComponentPeer::getAvailableRenderingEngines() throw()
  61946. {
  61947. StringArray s;
  61948. s.add ("Software Renderer");
  61949. return s;
  61950. }
  61951. int ComponentPeer::getCurrentRenderingEngine() throw()
  61952. {
  61953. return 0;
  61954. }
  61955. void ComponentPeer::setCurrentRenderingEngine (int /*index*/) throw()
  61956. {
  61957. }
  61958. END_JUCE_NAMESPACE
  61959. /*** End of inlined file: juce_ComponentPeer.cpp ***/
  61960. /*** Start of inlined file: juce_DialogWindow.cpp ***/
  61961. BEGIN_JUCE_NAMESPACE
  61962. DialogWindow::DialogWindow (const String& name,
  61963. const Colour& backgroundColour_,
  61964. const bool escapeKeyTriggersCloseButton_,
  61965. const bool addToDesktop_)
  61966. : DocumentWindow (name, backgroundColour_, DocumentWindow::closeButton, addToDesktop_),
  61967. escapeKeyTriggersCloseButton (escapeKeyTriggersCloseButton_)
  61968. {
  61969. }
  61970. DialogWindow::~DialogWindow()
  61971. {
  61972. }
  61973. void DialogWindow::resized()
  61974. {
  61975. DocumentWindow::resized();
  61976. const KeyPress esc (KeyPress::escapeKey, 0, 0);
  61977. if (escapeKeyTriggersCloseButton
  61978. && getCloseButton() != 0
  61979. && ! getCloseButton()->isRegisteredForShortcut (esc))
  61980. {
  61981. getCloseButton()->addShortcut (esc);
  61982. }
  61983. }
  61984. class TempDialogWindow : public DialogWindow
  61985. {
  61986. public:
  61987. TempDialogWindow (const String& title, const Colour& colour, const bool escapeCloses)
  61988. : DialogWindow (title, colour, escapeCloses, true)
  61989. {
  61990. }
  61991. ~TempDialogWindow()
  61992. {
  61993. }
  61994. void closeButtonPressed()
  61995. {
  61996. setVisible (false);
  61997. }
  61998. private:
  61999. TempDialogWindow (const TempDialogWindow&);
  62000. TempDialogWindow& operator= (const TempDialogWindow&);
  62001. };
  62002. int DialogWindow::showModalDialog (const String& dialogTitle,
  62003. Component* contentComponent,
  62004. Component* componentToCentreAround,
  62005. const Colour& colour,
  62006. const bool escapeKeyTriggersCloseButton,
  62007. const bool shouldBeResizable,
  62008. const bool useBottomRightCornerResizer)
  62009. {
  62010. TempDialogWindow dw (dialogTitle, colour, escapeKeyTriggersCloseButton);
  62011. dw.setContentComponent (contentComponent, true, true);
  62012. dw.centreAroundComponent (componentToCentreAround, dw.getWidth(), dw.getHeight());
  62013. dw.setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62014. const int result = dw.runModalLoop();
  62015. dw.setContentComponent (0, false);
  62016. return result;
  62017. }
  62018. END_JUCE_NAMESPACE
  62019. /*** End of inlined file: juce_DialogWindow.cpp ***/
  62020. /*** Start of inlined file: juce_DocumentWindow.cpp ***/
  62021. BEGIN_JUCE_NAMESPACE
  62022. class DocumentWindow::ButtonListenerProxy : public ButtonListener
  62023. {
  62024. public:
  62025. ButtonListenerProxy (DocumentWindow& owner_)
  62026. : owner (owner_)
  62027. {
  62028. }
  62029. void buttonClicked (Button* button)
  62030. {
  62031. if (button == owner.getMinimiseButton())
  62032. owner.minimiseButtonPressed();
  62033. else if (button == owner.getMaximiseButton())
  62034. owner.maximiseButtonPressed();
  62035. else if (button == owner.getCloseButton())
  62036. owner.closeButtonPressed();
  62037. }
  62038. juce_UseDebuggingNewOperator
  62039. private:
  62040. DocumentWindow& owner;
  62041. ButtonListenerProxy (const ButtonListenerProxy&);
  62042. ButtonListenerProxy& operator= (const ButtonListenerProxy&);
  62043. };
  62044. DocumentWindow::DocumentWindow (const String& title,
  62045. const Colour& backgroundColour,
  62046. const int requiredButtons_,
  62047. const bool addToDesktop_)
  62048. : ResizableWindow (title, backgroundColour, addToDesktop_),
  62049. titleBarHeight (26),
  62050. menuBarHeight (24),
  62051. requiredButtons (requiredButtons_),
  62052. #if JUCE_MAC
  62053. positionTitleBarButtonsOnLeft (true),
  62054. #else
  62055. positionTitleBarButtonsOnLeft (false),
  62056. #endif
  62057. drawTitleTextCentred (true),
  62058. menuBarModel (0)
  62059. {
  62060. setResizeLimits (128, 128, 32768, 32768);
  62061. lookAndFeelChanged();
  62062. }
  62063. DocumentWindow::~DocumentWindow()
  62064. {
  62065. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  62066. titleBarButtons[i] = 0;
  62067. menuBar = 0;
  62068. }
  62069. void DocumentWindow::repaintTitleBar()
  62070. {
  62071. const Rectangle<int> titleBarArea (getTitleBarArea());
  62072. repaint (titleBarArea.getX(), titleBarArea.getY(),
  62073. titleBarArea.getWidth(), titleBarArea.getHeight());
  62074. }
  62075. void DocumentWindow::setName (const String& newName)
  62076. {
  62077. if (newName != getName())
  62078. {
  62079. Component::setName (newName);
  62080. repaintTitleBar();
  62081. }
  62082. }
  62083. void DocumentWindow::setIcon (const Image* imageToUse)
  62084. {
  62085. titleBarIcon = imageToUse != 0 ? imageToUse->createCopy() : 0;
  62086. repaintTitleBar();
  62087. }
  62088. void DocumentWindow::setTitleBarHeight (const int newHeight)
  62089. {
  62090. titleBarHeight = newHeight;
  62091. resized();
  62092. repaintTitleBar();
  62093. }
  62094. void DocumentWindow::setTitleBarButtonsRequired (const int requiredButtons_,
  62095. const bool positionTitleBarButtonsOnLeft_)
  62096. {
  62097. requiredButtons = requiredButtons_;
  62098. positionTitleBarButtonsOnLeft = positionTitleBarButtonsOnLeft_;
  62099. lookAndFeelChanged();
  62100. }
  62101. void DocumentWindow::setTitleBarTextCentred (const bool textShouldBeCentred)
  62102. {
  62103. drawTitleTextCentred = textShouldBeCentred;
  62104. repaintTitleBar();
  62105. }
  62106. void DocumentWindow::setMenuBar (MenuBarModel* menuBarModel_,
  62107. const int menuBarHeight_)
  62108. {
  62109. if (menuBarModel != menuBarModel_)
  62110. {
  62111. menuBar = 0;
  62112. menuBarModel = menuBarModel_;
  62113. menuBarHeight = (menuBarHeight_ > 0) ? menuBarHeight_
  62114. : getLookAndFeel().getDefaultMenuBarHeight();
  62115. if (menuBarModel != 0)
  62116. {
  62117. // (call the Component method directly to avoid the assertion in ResizableWindow)
  62118. Component::addAndMakeVisible (menuBar = new MenuBarComponent (menuBarModel));
  62119. menuBar->setEnabled (isActiveWindow());
  62120. }
  62121. resized();
  62122. }
  62123. }
  62124. void DocumentWindow::closeButtonPressed()
  62125. {
  62126. /* If you've got a close button, you have to override this method to get
  62127. rid of your window!
  62128. If the window is just a pop-up, you should override this method and make
  62129. it delete the window in whatever way is appropriate for your app. E.g. you
  62130. might just want to call "delete this".
  62131. If your app is centred around this window such that the whole app should quit when
  62132. the window is closed, then you will probably want to use this method as an opportunity
  62133. to call JUCEApplication::quit(), and leave the window to be deleted later by your
  62134. JUCEApplication::shutdown() method. (Doing it this way means that your window will
  62135. still get cleaned-up if the app is quit by some other means (e.g. a cmd-Q on the mac
  62136. or closing it via the taskbar icon on Windows).
  62137. */
  62138. jassertfalse
  62139. }
  62140. void DocumentWindow::minimiseButtonPressed()
  62141. {
  62142. setMinimised (true);
  62143. }
  62144. void DocumentWindow::maximiseButtonPressed()
  62145. {
  62146. setFullScreen (! isFullScreen());
  62147. }
  62148. void DocumentWindow::paint (Graphics& g)
  62149. {
  62150. ResizableWindow::paint (g);
  62151. if (resizableBorder == 0)
  62152. {
  62153. g.setColour (getBackgroundColour().overlaidWith (Colour (0x80000000)));
  62154. const BorderSize border (getBorderThickness());
  62155. g.fillRect (0, 0, getWidth(), border.getTop());
  62156. g.fillRect (0, border.getTop(), border.getLeft(), getHeight() - border.getTopAndBottom());
  62157. g.fillRect (getWidth() - border.getRight(), border.getTop(), border.getRight(), getHeight() - border.getTopAndBottom());
  62158. g.fillRect (0, getHeight() - border.getBottom(), getWidth(), border.getBottom());
  62159. }
  62160. const Rectangle<int> titleBarArea (getTitleBarArea());
  62161. g.setOrigin (titleBarArea.getX(), titleBarArea.getY());
  62162. g.reduceClipRegion (0, 0, titleBarArea.getWidth(), titleBarArea.getHeight());
  62163. int titleSpaceX1 = 6;
  62164. int titleSpaceX2 = titleBarArea.getWidth() - 6;
  62165. for (int i = 0; i < 3; ++i)
  62166. {
  62167. if (titleBarButtons[i] != 0)
  62168. {
  62169. if (positionTitleBarButtonsOnLeft)
  62170. titleSpaceX1 = jmax (titleSpaceX1, titleBarButtons[i]->getRight() + (getWidth() - titleBarButtons[i]->getRight()) / 8);
  62171. else
  62172. titleSpaceX2 = jmin (titleSpaceX2, titleBarButtons[i]->getX() - (titleBarButtons[i]->getX() / 8));
  62173. }
  62174. }
  62175. getLookAndFeel().drawDocumentWindowTitleBar (*this, g,
  62176. titleBarArea.getWidth(),
  62177. titleBarArea.getHeight(),
  62178. titleSpaceX1,
  62179. jmax (1, titleSpaceX2 - titleSpaceX1),
  62180. titleBarIcon,
  62181. ! drawTitleTextCentred);
  62182. }
  62183. void DocumentWindow::resized()
  62184. {
  62185. ResizableWindow::resized();
  62186. if (titleBarButtons[1] != 0)
  62187. titleBarButtons[1]->setToggleState (isFullScreen(), false);
  62188. const Rectangle<int> titleBarArea (getTitleBarArea());
  62189. getLookAndFeel()
  62190. .positionDocumentWindowButtons (*this,
  62191. titleBarArea.getX(), titleBarArea.getY(),
  62192. titleBarArea.getWidth(), titleBarArea.getHeight(),
  62193. titleBarButtons[0],
  62194. titleBarButtons[1],
  62195. titleBarButtons[2],
  62196. positionTitleBarButtonsOnLeft);
  62197. if (menuBar != 0)
  62198. menuBar->setBounds (titleBarArea.getX(), titleBarArea.getBottom(),
  62199. titleBarArea.getWidth(), menuBarHeight);
  62200. }
  62201. const BorderSize DocumentWindow::getBorderThickness()
  62202. {
  62203. return BorderSize ((isFullScreen() || isUsingNativeTitleBar())
  62204. ? 0 : (resizableBorder != 0 ? 4 : 1));
  62205. }
  62206. const BorderSize DocumentWindow::getContentComponentBorder()
  62207. {
  62208. BorderSize border (getBorderThickness());
  62209. border.setTop (border.getTop()
  62210. + (isUsingNativeTitleBar() ? 0 : titleBarHeight)
  62211. + (menuBar != 0 ? menuBarHeight : 0));
  62212. return border;
  62213. }
  62214. int DocumentWindow::getTitleBarHeight() const
  62215. {
  62216. return isUsingNativeTitleBar() ? 0 : jmin (titleBarHeight, getHeight() - 4);
  62217. }
  62218. const Rectangle<int> DocumentWindow::getTitleBarArea()
  62219. {
  62220. const BorderSize border (getBorderThickness());
  62221. return Rectangle<int> (border.getLeft(), border.getTop(),
  62222. getWidth() - border.getLeftAndRight(),
  62223. getTitleBarHeight());
  62224. }
  62225. Button* DocumentWindow::getCloseButton() const throw()
  62226. {
  62227. return titleBarButtons[2];
  62228. }
  62229. Button* DocumentWindow::getMinimiseButton() const throw()
  62230. {
  62231. return titleBarButtons[0];
  62232. }
  62233. Button* DocumentWindow::getMaximiseButton() const throw()
  62234. {
  62235. return titleBarButtons[1];
  62236. }
  62237. int DocumentWindow::getDesktopWindowStyleFlags() const
  62238. {
  62239. int flags = ResizableWindow::getDesktopWindowStyleFlags();
  62240. if ((requiredButtons & minimiseButton) != 0)
  62241. flags |= ComponentPeer::windowHasMinimiseButton;
  62242. if ((requiredButtons & maximiseButton) != 0)
  62243. flags |= ComponentPeer::windowHasMaximiseButton;
  62244. if ((requiredButtons & closeButton) != 0)
  62245. flags |= ComponentPeer::windowHasCloseButton;
  62246. return flags;
  62247. }
  62248. void DocumentWindow::lookAndFeelChanged()
  62249. {
  62250. int i;
  62251. for (i = numElementsInArray (titleBarButtons); --i >= 0;)
  62252. titleBarButtons[i] = 0;
  62253. if (! isUsingNativeTitleBar())
  62254. {
  62255. titleBarButtons[0] = ((requiredButtons & minimiseButton) != 0)
  62256. ? getLookAndFeel().createDocumentWindowButton (minimiseButton) : 0;
  62257. titleBarButtons[1] = ((requiredButtons & maximiseButton) != 0)
  62258. ? getLookAndFeel().createDocumentWindowButton (maximiseButton) : 0;
  62259. titleBarButtons[2] = ((requiredButtons & closeButton) != 0)
  62260. ? getLookAndFeel().createDocumentWindowButton (closeButton) : 0;
  62261. for (i = 0; i < 3; ++i)
  62262. {
  62263. if (titleBarButtons[i] != 0)
  62264. {
  62265. if (buttonListener == 0)
  62266. buttonListener = new ButtonListenerProxy (*this);
  62267. titleBarButtons[i]->addButtonListener (buttonListener);
  62268. titleBarButtons[i]->setWantsKeyboardFocus (false);
  62269. // (call the Component method directly to avoid the assertion in ResizableWindow)
  62270. Component::addAndMakeVisible (titleBarButtons[i]);
  62271. }
  62272. }
  62273. if (getCloseButton() != 0)
  62274. {
  62275. #if JUCE_MAC
  62276. getCloseButton()->addShortcut (KeyPress (T('w'), ModifierKeys::commandModifier, 0));
  62277. #else
  62278. getCloseButton()->addShortcut (KeyPress (KeyPress::F4Key, ModifierKeys::altModifier, 0));
  62279. #endif
  62280. }
  62281. }
  62282. activeWindowStatusChanged();
  62283. ResizableWindow::lookAndFeelChanged();
  62284. }
  62285. void DocumentWindow::parentHierarchyChanged()
  62286. {
  62287. lookAndFeelChanged();
  62288. }
  62289. void DocumentWindow::activeWindowStatusChanged()
  62290. {
  62291. ResizableWindow::activeWindowStatusChanged();
  62292. for (int i = numElementsInArray (titleBarButtons); --i >= 0;)
  62293. if (titleBarButtons[i] != 0)
  62294. titleBarButtons[i]->setEnabled (isActiveWindow());
  62295. if (menuBar != 0)
  62296. menuBar->setEnabled (isActiveWindow());
  62297. }
  62298. void DocumentWindow::mouseDoubleClick (const MouseEvent& e)
  62299. {
  62300. if (getTitleBarArea().contains (e.x, e.y)
  62301. && getMaximiseButton() != 0)
  62302. {
  62303. getMaximiseButton()->triggerClick();
  62304. }
  62305. }
  62306. void DocumentWindow::userTriedToCloseWindow()
  62307. {
  62308. closeButtonPressed();
  62309. }
  62310. END_JUCE_NAMESPACE
  62311. /*** End of inlined file: juce_DocumentWindow.cpp ***/
  62312. /*** Start of inlined file: juce_ResizableWindow.cpp ***/
  62313. BEGIN_JUCE_NAMESPACE
  62314. ResizableWindow::ResizableWindow (const String& name,
  62315. const bool addToDesktop_)
  62316. : TopLevelWindow (name, addToDesktop_),
  62317. resizeToFitContent (false),
  62318. fullscreen (false),
  62319. lastNonFullScreenPos (50, 50, 256, 256),
  62320. constrainer (0)
  62321. #ifdef JUCE_DEBUG
  62322. , hasBeenResized (false)
  62323. #endif
  62324. {
  62325. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62326. lastNonFullScreenPos.setBounds (50, 50, 256, 256);
  62327. if (addToDesktop_)
  62328. Component::addToDesktop (getDesktopWindowStyleFlags());
  62329. }
  62330. ResizableWindow::ResizableWindow (const String& name,
  62331. const Colour& backgroundColour_,
  62332. const bool addToDesktop_)
  62333. : TopLevelWindow (name, addToDesktop_),
  62334. resizeToFitContent (false),
  62335. fullscreen (false),
  62336. lastNonFullScreenPos (50, 50, 256, 256),
  62337. constrainer (0)
  62338. #ifdef JUCE_DEBUG
  62339. , hasBeenResized (false)
  62340. #endif
  62341. {
  62342. setBackgroundColour (backgroundColour_);
  62343. defaultConstrainer.setMinimumOnscreenAmounts (0x10000, 16, 24, 16);
  62344. if (addToDesktop_)
  62345. Component::addToDesktop (getDesktopWindowStyleFlags());
  62346. }
  62347. ResizableWindow::~ResizableWindow()
  62348. {
  62349. resizableCorner = 0;
  62350. resizableBorder = 0;
  62351. contentComponent = 0;
  62352. // have you been adding your own components directly to this window..? tut tut tut.
  62353. // Read the instructions for using a ResizableWindow!
  62354. jassert (getNumChildComponents() == 0);
  62355. }
  62356. int ResizableWindow::getDesktopWindowStyleFlags() const
  62357. {
  62358. int flags = TopLevelWindow::getDesktopWindowStyleFlags();
  62359. if (isResizable() && (flags & ComponentPeer::windowHasTitleBar) != 0)
  62360. flags |= ComponentPeer::windowIsResizable;
  62361. return flags;
  62362. }
  62363. void ResizableWindow::setContentComponent (Component* const newContentComponent,
  62364. const bool deleteOldOne,
  62365. const bool resizeToFit)
  62366. {
  62367. resizeToFitContent = resizeToFit;
  62368. if (newContentComponent != (Component*) contentComponent)
  62369. {
  62370. if (! deleteOldOne)
  62371. removeChildComponent (contentComponent.release());
  62372. contentComponent = newContentComponent;
  62373. Component::addAndMakeVisible (contentComponent);
  62374. }
  62375. if (resizeToFit)
  62376. childBoundsChanged (contentComponent);
  62377. resized(); // must always be called to position the new content comp
  62378. }
  62379. void ResizableWindow::setContentComponentSize (int width, int height)
  62380. {
  62381. jassert (width > 0 && height > 0); // not a great idea to give it a zero size..
  62382. const BorderSize border (getContentComponentBorder());
  62383. setSize (width + border.getLeftAndRight(),
  62384. height + border.getTopAndBottom());
  62385. }
  62386. const BorderSize ResizableWindow::getBorderThickness()
  62387. {
  62388. return BorderSize (isUsingNativeTitleBar() ? 0 : ((resizableBorder != 0 && ! isFullScreen()) ? 5 : 3));
  62389. }
  62390. const BorderSize ResizableWindow::getContentComponentBorder()
  62391. {
  62392. return getBorderThickness();
  62393. }
  62394. void ResizableWindow::moved()
  62395. {
  62396. updateLastPos();
  62397. }
  62398. void ResizableWindow::visibilityChanged()
  62399. {
  62400. TopLevelWindow::visibilityChanged();
  62401. updateLastPos();
  62402. }
  62403. void ResizableWindow::resized()
  62404. {
  62405. if (resizableBorder != 0)
  62406. {
  62407. resizableBorder->setVisible (! isFullScreen());
  62408. resizableBorder->setBorderThickness (getBorderThickness());
  62409. resizableBorder->setSize (getWidth(), getHeight());
  62410. resizableBorder->toBack();
  62411. }
  62412. if (resizableCorner != 0)
  62413. {
  62414. resizableCorner->setVisible (! isFullScreen());
  62415. const int resizerSize = 18;
  62416. resizableCorner->setBounds (getWidth() - resizerSize,
  62417. getHeight() - resizerSize,
  62418. resizerSize, resizerSize);
  62419. }
  62420. if (contentComponent != 0)
  62421. contentComponent->setBoundsInset (getContentComponentBorder());
  62422. updateLastPos();
  62423. #ifdef JUCE_DEBUG
  62424. hasBeenResized = true;
  62425. #endif
  62426. }
  62427. void ResizableWindow::childBoundsChanged (Component* child)
  62428. {
  62429. if ((child == contentComponent) && (child != 0) && resizeToFitContent)
  62430. {
  62431. // not going to look very good if this component has a zero size..
  62432. jassert (child->getWidth() > 0);
  62433. jassert (child->getHeight() > 0);
  62434. const BorderSize borders (getContentComponentBorder());
  62435. setSize (child->getWidth() + borders.getLeftAndRight(),
  62436. child->getHeight() + borders.getTopAndBottom());
  62437. }
  62438. }
  62439. void ResizableWindow::activeWindowStatusChanged()
  62440. {
  62441. const BorderSize borders (getContentComponentBorder());
  62442. repaint (0, 0, getWidth(), borders.getTop());
  62443. repaint (0, borders.getTop(), borders.getLeft(), getHeight() - borders.getBottom() - borders.getTop());
  62444. repaint (0, getHeight() - borders.getBottom(), getWidth(), borders.getBottom());
  62445. repaint (getWidth() - borders.getRight(), borders.getTop(), borders.getRight(), getHeight() - borders.getBottom() - borders.getTop());
  62446. }
  62447. void ResizableWindow::setResizable (const bool shouldBeResizable,
  62448. const bool useBottomRightCornerResizer)
  62449. {
  62450. if (shouldBeResizable)
  62451. {
  62452. if (useBottomRightCornerResizer)
  62453. {
  62454. resizableBorder = 0;
  62455. if (resizableCorner == 0)
  62456. {
  62457. Component::addChildComponent (resizableCorner = new ResizableCornerComponent (this, constrainer));
  62458. resizableCorner->setAlwaysOnTop (true);
  62459. }
  62460. }
  62461. else
  62462. {
  62463. resizableCorner = 0;
  62464. if (resizableBorder == 0)
  62465. Component::addChildComponent (resizableBorder = new ResizableBorderComponent (this, constrainer));
  62466. }
  62467. }
  62468. else
  62469. {
  62470. resizableCorner = 0;
  62471. resizableBorder = 0;
  62472. }
  62473. if (isUsingNativeTitleBar())
  62474. recreateDesktopWindow();
  62475. childBoundsChanged (contentComponent);
  62476. resized();
  62477. }
  62478. bool ResizableWindow::isResizable() const throw()
  62479. {
  62480. return resizableCorner != 0
  62481. || resizableBorder != 0;
  62482. }
  62483. void ResizableWindow::setResizeLimits (const int newMinimumWidth,
  62484. const int newMinimumHeight,
  62485. const int newMaximumWidth,
  62486. const int newMaximumHeight) throw()
  62487. {
  62488. // if you've set up a custom constrainer then these settings won't have any effect..
  62489. jassert (constrainer == &defaultConstrainer || constrainer == 0);
  62490. if (constrainer == 0)
  62491. setConstrainer (&defaultConstrainer);
  62492. defaultConstrainer.setSizeLimits (newMinimumWidth, newMinimumHeight,
  62493. newMaximumWidth, newMaximumHeight);
  62494. setBoundsConstrained (getBounds());
  62495. }
  62496. void ResizableWindow::setConstrainer (ComponentBoundsConstrainer* newConstrainer)
  62497. {
  62498. if (constrainer != newConstrainer)
  62499. {
  62500. constrainer = newConstrainer;
  62501. const bool useBottomRightCornerResizer = resizableCorner != 0;
  62502. const bool shouldBeResizable = useBottomRightCornerResizer || resizableBorder != 0;
  62503. resizableCorner = 0;
  62504. resizableBorder = 0;
  62505. setResizable (shouldBeResizable, useBottomRightCornerResizer);
  62506. ComponentPeer* const peer = getPeer();
  62507. if (peer != 0)
  62508. peer->setConstrainer (newConstrainer);
  62509. }
  62510. }
  62511. void ResizableWindow::setBoundsConstrained (const Rectangle<int>& bounds)
  62512. {
  62513. if (constrainer != 0)
  62514. constrainer->setBoundsForComponent (this, bounds, false, false, false, false);
  62515. else
  62516. setBounds (bounds);
  62517. }
  62518. void ResizableWindow::paint (Graphics& g)
  62519. {
  62520. getLookAndFeel().fillResizableWindowBackground (g, getWidth(), getHeight(),
  62521. getBorderThickness(), *this);
  62522. if (! isFullScreen())
  62523. {
  62524. getLookAndFeel().drawResizableWindowBorder (g, getWidth(), getHeight(),
  62525. getBorderThickness(), *this);
  62526. }
  62527. #ifdef JUCE_DEBUG
  62528. /* If this fails, then you've probably written a subclass with a resized()
  62529. callback but forgotten to make it call its parent class's resized() method.
  62530. It's important when you override methods like resized(), moved(),
  62531. etc., that you make sure the base class methods also get called.
  62532. Of course you shouldn't really be overriding ResizableWindow::resized() anyway,
  62533. because your content should all be inside the content component - and it's the
  62534. content component's resized() method that you should be using to do your
  62535. layout.
  62536. */
  62537. jassert (hasBeenResized || (getWidth() == 0 && getHeight() == 0));
  62538. #endif
  62539. }
  62540. void ResizableWindow::lookAndFeelChanged()
  62541. {
  62542. resized();
  62543. if (isOnDesktop())
  62544. {
  62545. Component::addToDesktop (getDesktopWindowStyleFlags());
  62546. ComponentPeer* const peer = getPeer();
  62547. if (peer != 0)
  62548. peer->setConstrainer (constrainer);
  62549. }
  62550. }
  62551. const Colour ResizableWindow::getBackgroundColour() const throw()
  62552. {
  62553. return findColour (backgroundColourId, false);
  62554. }
  62555. void ResizableWindow::setBackgroundColour (const Colour& newColour)
  62556. {
  62557. Colour backgroundColour (newColour);
  62558. if (! Desktop::canUseSemiTransparentWindows())
  62559. backgroundColour = newColour.withAlpha (1.0f);
  62560. setColour (backgroundColourId, backgroundColour);
  62561. setOpaque (backgroundColour.isOpaque());
  62562. repaint();
  62563. }
  62564. bool ResizableWindow::isFullScreen() const
  62565. {
  62566. if (isOnDesktop())
  62567. {
  62568. ComponentPeer* const peer = getPeer();
  62569. return peer != 0 && peer->isFullScreen();
  62570. }
  62571. return fullscreen;
  62572. }
  62573. void ResizableWindow::setFullScreen (const bool shouldBeFullScreen)
  62574. {
  62575. if (shouldBeFullScreen != isFullScreen())
  62576. {
  62577. updateLastPos();
  62578. fullscreen = shouldBeFullScreen;
  62579. if (isOnDesktop())
  62580. {
  62581. ComponentPeer* const peer = getPeer();
  62582. if (peer != 0)
  62583. {
  62584. // keep a copy of this intact in case the real one gets messed-up while we're un-maximising
  62585. const Rectangle<int> lastPos (lastNonFullScreenPos);
  62586. peer->setFullScreen (shouldBeFullScreen);
  62587. if (! shouldBeFullScreen)
  62588. setBounds (lastPos);
  62589. }
  62590. else
  62591. {
  62592. jassertfalse
  62593. }
  62594. }
  62595. else
  62596. {
  62597. if (shouldBeFullScreen)
  62598. setBounds (0, 0, getParentWidth(), getParentHeight());
  62599. else
  62600. setBounds (lastNonFullScreenPos);
  62601. }
  62602. resized();
  62603. }
  62604. }
  62605. bool ResizableWindow::isMinimised() const
  62606. {
  62607. ComponentPeer* const peer = getPeer();
  62608. return (peer != 0) && peer->isMinimised();
  62609. }
  62610. void ResizableWindow::setMinimised (const bool shouldMinimise)
  62611. {
  62612. if (shouldMinimise != isMinimised())
  62613. {
  62614. ComponentPeer* const peer = getPeer();
  62615. if (peer != 0)
  62616. {
  62617. updateLastPos();
  62618. peer->setMinimised (shouldMinimise);
  62619. }
  62620. else
  62621. {
  62622. jassertfalse
  62623. }
  62624. }
  62625. }
  62626. void ResizableWindow::updateLastPos()
  62627. {
  62628. if (isShowing() && ! (isFullScreen() || isMinimised()))
  62629. {
  62630. lastNonFullScreenPos = getBounds();
  62631. }
  62632. }
  62633. void ResizableWindow::parentSizeChanged()
  62634. {
  62635. if (isFullScreen() && getParentComponent() != 0)
  62636. {
  62637. setBounds (0, 0, getParentWidth(), getParentHeight());
  62638. }
  62639. }
  62640. const String ResizableWindow::getWindowStateAsString()
  62641. {
  62642. updateLastPos();
  62643. return (isFullScreen() ? "fs " : "") + lastNonFullScreenPos.toString();
  62644. }
  62645. bool ResizableWindow::restoreWindowStateFromString (const String& s)
  62646. {
  62647. StringArray tokens;
  62648. tokens.addTokens (s, false);
  62649. tokens.removeEmptyStrings();
  62650. tokens.trim();
  62651. const bool fs = tokens[0].startsWithIgnoreCase (T("fs"));
  62652. const int firstCoord = fs ? 1 : 0;
  62653. if (tokens.size() != firstCoord + 4)
  62654. return false;
  62655. Rectangle<int> newPos (tokens[firstCoord].getIntValue(),
  62656. tokens[firstCoord + 1].getIntValue(),
  62657. tokens[firstCoord + 2].getIntValue(),
  62658. tokens[firstCoord + 3].getIntValue());
  62659. if (newPos.isEmpty())
  62660. return false;
  62661. const Rectangle<int> screen (Desktop::getInstance().getMonitorAreaContaining (newPos.getCentre()));
  62662. ComponentPeer* const peer = isOnDesktop() ? getPeer() : 0;
  62663. if (peer != 0)
  62664. peer->getFrameSize().addTo (newPos);
  62665. if (! screen.contains (newPos))
  62666. {
  62667. newPos.setSize (jmin (newPos.getWidth(), screen.getWidth()),
  62668. jmin (newPos.getHeight(), screen.getHeight()));
  62669. newPos.setPosition (jlimit (screen.getX(), screen.getRight() - newPos.getWidth(), newPos.getX()),
  62670. jlimit (screen.getY(), screen.getBottom() - newPos.getHeight(), newPos.getY()));
  62671. }
  62672. if (peer != 0)
  62673. {
  62674. peer->getFrameSize().subtractFrom (newPos);
  62675. peer->setNonFullScreenBounds (newPos);
  62676. }
  62677. lastNonFullScreenPos = newPos;
  62678. setFullScreen (fs);
  62679. if (! fs)
  62680. setBoundsConstrained (newPos);
  62681. return true;
  62682. }
  62683. void ResizableWindow::mouseDown (const MouseEvent&)
  62684. {
  62685. if (! isFullScreen())
  62686. dragger.startDraggingComponent (this, constrainer);
  62687. }
  62688. void ResizableWindow::mouseDrag (const MouseEvent& e)
  62689. {
  62690. if (! isFullScreen())
  62691. dragger.dragComponent (this, e);
  62692. }
  62693. #ifdef JUCE_DEBUG
  62694. void ResizableWindow::addChildComponent (Component* const child, int zOrder)
  62695. {
  62696. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62697. manages its child components automatically, and if you add your own it'll cause
  62698. trouble. Instead, use setContentComponent() to give it a component which
  62699. will be automatically resized and kept in the right place - then you can add
  62700. subcomponents to the content comp. See the notes for the ResizableWindow class
  62701. for more info.
  62702. If you really know what you're doing and want to avoid this assertion, just call
  62703. Component::addChildComponent directly.
  62704. */
  62705. jassertfalse
  62706. Component::addChildComponent (child, zOrder);
  62707. }
  62708. void ResizableWindow::addAndMakeVisible (Component* const child, int zOrder)
  62709. {
  62710. /* Agh! You shouldn't add components directly to a ResizableWindow - this class
  62711. manages its child components automatically, and if you add your own it'll cause
  62712. trouble. Instead, use setContentComponent() to give it a component which
  62713. will be automatically resized and kept in the right place - then you can add
  62714. subcomponents to the content comp. See the notes for the ResizableWindow class
  62715. for more info.
  62716. If you really know what you're doing and want to avoid this assertion, just call
  62717. Component::addAndMakeVisible directly.
  62718. */
  62719. jassertfalse
  62720. Component::addAndMakeVisible (child, zOrder);
  62721. }
  62722. #endif
  62723. END_JUCE_NAMESPACE
  62724. /*** End of inlined file: juce_ResizableWindow.cpp ***/
  62725. /*** Start of inlined file: juce_SplashScreen.cpp ***/
  62726. BEGIN_JUCE_NAMESPACE
  62727. SplashScreen::SplashScreen()
  62728. : backgroundImage (0)
  62729. {
  62730. setOpaque (true);
  62731. }
  62732. SplashScreen::~SplashScreen()
  62733. {
  62734. ImageCache::releaseOrDelete (backgroundImage);
  62735. }
  62736. void SplashScreen::show (const String& title,
  62737. Image* const backgroundImage_,
  62738. const int minimumTimeToDisplayFor,
  62739. const bool useDropShadow,
  62740. const bool removeOnMouseClick)
  62741. {
  62742. backgroundImage = backgroundImage_;
  62743. jassert (backgroundImage_ != 0);
  62744. if (backgroundImage_ != 0)
  62745. {
  62746. setOpaque (! backgroundImage_->hasAlphaChannel());
  62747. show (title,
  62748. backgroundImage_->getWidth(),
  62749. backgroundImage_->getHeight(),
  62750. minimumTimeToDisplayFor,
  62751. useDropShadow,
  62752. removeOnMouseClick);
  62753. }
  62754. }
  62755. void SplashScreen::show (const String& title,
  62756. const int width,
  62757. const int height,
  62758. const int minimumTimeToDisplayFor,
  62759. const bool useDropShadow,
  62760. const bool removeOnMouseClick)
  62761. {
  62762. setName (title);
  62763. setAlwaysOnTop (true);
  62764. setVisible (true);
  62765. centreWithSize (width, height);
  62766. addToDesktop (useDropShadow ? ComponentPeer::windowHasDropShadow : 0);
  62767. toFront (false);
  62768. MessageManager::getInstance()->runDispatchLoopUntil (300);
  62769. repaint();
  62770. originalClickCounter = removeOnMouseClick
  62771. ? Desktop::getMouseButtonClickCounter()
  62772. : std::numeric_limits<int>::max();
  62773. earliestTimeToDelete = Time::getCurrentTime() + RelativeTime::milliseconds (minimumTimeToDisplayFor);
  62774. startTimer (50);
  62775. }
  62776. void SplashScreen::paint (Graphics& g)
  62777. {
  62778. if (backgroundImage != 0)
  62779. {
  62780. g.setOpacity (1.0f);
  62781. g.drawImage (backgroundImage,
  62782. 0, 0, getWidth(), getHeight(),
  62783. 0, 0, backgroundImage->getWidth(), backgroundImage->getHeight());
  62784. }
  62785. }
  62786. void SplashScreen::timerCallback()
  62787. {
  62788. if (Time::getCurrentTime() > earliestTimeToDelete
  62789. || Desktop::getMouseButtonClickCounter() > originalClickCounter)
  62790. {
  62791. delete this;
  62792. }
  62793. }
  62794. END_JUCE_NAMESPACE
  62795. /*** End of inlined file: juce_SplashScreen.cpp ***/
  62796. /*** Start of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62797. BEGIN_JUCE_NAMESPACE
  62798. ThreadWithProgressWindow::ThreadWithProgressWindow (const String& title,
  62799. const bool hasProgressBar,
  62800. const bool hasCancelButton,
  62801. const int timeOutMsWhenCancelling_,
  62802. const String& cancelButtonText)
  62803. : Thread ("Juce Progress Window"),
  62804. progress (0.0),
  62805. timeOutMsWhenCancelling (timeOutMsWhenCancelling_)
  62806. {
  62807. alertWindow = LookAndFeel::getDefaultLookAndFeel()
  62808. .createAlertWindow (title, String::empty, cancelButtonText,
  62809. String::empty, String::empty,
  62810. AlertWindow::NoIcon, hasCancelButton ? 1 : 0, 0);
  62811. if (hasProgressBar)
  62812. alertWindow->addProgressBarComponent (progress);
  62813. }
  62814. ThreadWithProgressWindow::~ThreadWithProgressWindow()
  62815. {
  62816. stopThread (timeOutMsWhenCancelling);
  62817. }
  62818. bool ThreadWithProgressWindow::runThread (const int priority)
  62819. {
  62820. startThread (priority);
  62821. startTimer (100);
  62822. {
  62823. const ScopedLock sl (messageLock);
  62824. alertWindow->setMessage (message);
  62825. }
  62826. const bool finishedNaturally = alertWindow->runModalLoop() != 0;
  62827. stopThread (timeOutMsWhenCancelling);
  62828. alertWindow->setVisible (false);
  62829. return finishedNaturally;
  62830. }
  62831. void ThreadWithProgressWindow::setProgress (const double newProgress)
  62832. {
  62833. progress = newProgress;
  62834. }
  62835. void ThreadWithProgressWindow::setStatusMessage (const String& newStatusMessage)
  62836. {
  62837. const ScopedLock sl (messageLock);
  62838. message = newStatusMessage;
  62839. }
  62840. void ThreadWithProgressWindow::timerCallback()
  62841. {
  62842. if (! isThreadRunning())
  62843. {
  62844. // thread has finished normally..
  62845. alertWindow->exitModalState (1);
  62846. alertWindow->setVisible (false);
  62847. }
  62848. else
  62849. {
  62850. const ScopedLock sl (messageLock);
  62851. alertWindow->setMessage (message);
  62852. }
  62853. }
  62854. END_JUCE_NAMESPACE
  62855. /*** End of inlined file: juce_ThreadWithProgressWindow.cpp ***/
  62856. /*** Start of inlined file: juce_TooltipWindow.cpp ***/
  62857. BEGIN_JUCE_NAMESPACE
  62858. TooltipWindow::TooltipWindow (Component* const parentComponent,
  62859. const int millisecondsBeforeTipAppears_)
  62860. : Component ("tooltip"),
  62861. millisecondsBeforeTipAppears (millisecondsBeforeTipAppears_),
  62862. lastHideTime (0),
  62863. lastComponentUnderMouse (0),
  62864. changedCompsSinceShown (true)
  62865. {
  62866. startTimer (123);
  62867. setAlwaysOnTop (true);
  62868. setOpaque (true);
  62869. if (parentComponent != 0)
  62870. parentComponent->addChildComponent (this);
  62871. }
  62872. TooltipWindow::~TooltipWindow()
  62873. {
  62874. hide();
  62875. }
  62876. void TooltipWindow::setMillisecondsBeforeTipAppears (const int newTimeMs) throw()
  62877. {
  62878. millisecondsBeforeTipAppears = newTimeMs;
  62879. }
  62880. void TooltipWindow::paint (Graphics& g)
  62881. {
  62882. getLookAndFeel().drawTooltip (g, tipShowing, getWidth(), getHeight());
  62883. }
  62884. void TooltipWindow::mouseEnter (const MouseEvent&)
  62885. {
  62886. hide();
  62887. }
  62888. void TooltipWindow::showFor (const String& tip)
  62889. {
  62890. jassert (tip.isNotEmpty());
  62891. tipShowing = tip;
  62892. Point<int> mousePos (Desktop::getMousePosition());
  62893. if (getParentComponent() != 0)
  62894. mousePos = getParentComponent()->globalPositionToRelative (mousePos);
  62895. int x, y, w, h;
  62896. getLookAndFeel().getTooltipSize (tip, w, h);
  62897. if (mousePos.getX() > getParentWidth() / 2)
  62898. x = mousePos.getX() - (w + 12);
  62899. else
  62900. x = mousePos.getX() + 24;
  62901. if (mousePos.getY() > getParentHeight() / 2)
  62902. y = mousePos.getY() - (h + 6);
  62903. else
  62904. y = mousePos.getY() + 6;
  62905. setBounds (x, y, w, h);
  62906. setVisible (true);
  62907. if (getParentComponent() == 0)
  62908. {
  62909. addToDesktop (ComponentPeer::windowHasDropShadow
  62910. | ComponentPeer::windowIsTemporary
  62911. | ComponentPeer::windowIgnoresKeyPresses);
  62912. }
  62913. toFront (false);
  62914. }
  62915. const String TooltipWindow::getTipFor (Component* const c)
  62916. {
  62917. if (c->isValidComponent()
  62918. && Process::isForegroundProcess()
  62919. && ! Component::isMouseButtonDownAnywhere())
  62920. {
  62921. TooltipClient* const ttc = dynamic_cast <TooltipClient*> (c);
  62922. if (ttc != 0 && ! c->isCurrentlyBlockedByAnotherModalComponent())
  62923. return ttc->getTooltip();
  62924. }
  62925. return String::empty;
  62926. }
  62927. void TooltipWindow::hide()
  62928. {
  62929. tipShowing = String::empty;
  62930. removeFromDesktop();
  62931. setVisible (false);
  62932. }
  62933. void TooltipWindow::timerCallback()
  62934. {
  62935. const unsigned int now = Time::getApproximateMillisecondCounter();
  62936. Component* const newComp = Component::getComponentUnderMouse();
  62937. const String newTip (getTipFor (newComp));
  62938. const bool tipChanged = (newTip != lastTipUnderMouse || newComp != lastComponentUnderMouse);
  62939. lastComponentUnderMouse = newComp;
  62940. lastTipUnderMouse = newTip;
  62941. const int clickCount = Desktop::getInstance().getMouseButtonClickCounter();
  62942. const bool mouseWasClicked = clickCount > mouseClicks;
  62943. mouseClicks = clickCount;
  62944. const Point<int> mousePos (Desktop::getMousePosition());
  62945. const bool mouseMovedQuickly = mousePos.getDistanceFrom (lastMousePos) > 12;
  62946. lastMousePos = mousePos;
  62947. if (tipChanged || mouseWasClicked || mouseMovedQuickly)
  62948. lastCompChangeTime = now;
  62949. if (isVisible() || now < lastHideTime + 500)
  62950. {
  62951. // if a tip is currently visible (or has just disappeared), update to a new one
  62952. // immediately if needed..
  62953. if (newComp == 0 || mouseWasClicked || newTip.isEmpty())
  62954. {
  62955. if (isVisible())
  62956. {
  62957. lastHideTime = now;
  62958. hide();
  62959. }
  62960. }
  62961. else if (tipChanged)
  62962. {
  62963. showFor (newTip);
  62964. }
  62965. }
  62966. else
  62967. {
  62968. // if there isn't currently a tip, but one is needed, only let it
  62969. // appear after a timeout..
  62970. if (newTip.isNotEmpty()
  62971. && newTip != tipShowing
  62972. && now > lastCompChangeTime + millisecondsBeforeTipAppears)
  62973. {
  62974. showFor (newTip);
  62975. }
  62976. }
  62977. }
  62978. END_JUCE_NAMESPACE
  62979. /*** End of inlined file: juce_TooltipWindow.cpp ***/
  62980. /*** Start of inlined file: juce_TopLevelWindow.cpp ***/
  62981. BEGIN_JUCE_NAMESPACE
  62982. class TopLevelWindowManager : public Timer,
  62983. public DeletedAtShutdown
  62984. {
  62985. public:
  62986. TopLevelWindowManager()
  62987. : currentActive (0)
  62988. {
  62989. }
  62990. ~TopLevelWindowManager()
  62991. {
  62992. clearSingletonInstance();
  62993. }
  62994. juce_DeclareSingleton_SingleThreaded_Minimal (TopLevelWindowManager)
  62995. void timerCallback()
  62996. {
  62997. startTimer (jmin (1731, getTimerInterval() * 2));
  62998. TopLevelWindow* active = 0;
  62999. if (Process::isForegroundProcess())
  63000. {
  63001. active = currentActive;
  63002. Component* const c = Component::getCurrentlyFocusedComponent();
  63003. TopLevelWindow* tlw = dynamic_cast <TopLevelWindow*> (c);
  63004. if (tlw == 0 && c != 0)
  63005. // (unable to use the syntax findParentComponentOfClass <TopLevelWindow> () because of a VC6 compiler bug)
  63006. tlw = c->findParentComponentOfClass ((TopLevelWindow*) 0);
  63007. if (tlw != 0)
  63008. active = tlw;
  63009. }
  63010. if (active != currentActive)
  63011. {
  63012. currentActive = active;
  63013. for (int i = windows.size(); --i >= 0;)
  63014. {
  63015. TopLevelWindow* const tlw = (TopLevelWindow*) windows.getUnchecked (i);
  63016. tlw->setWindowActive (isWindowActive (tlw));
  63017. i = jmin (i, windows.size() - 1);
  63018. }
  63019. Desktop::getInstance().triggerFocusCallback();
  63020. }
  63021. }
  63022. bool addWindow (TopLevelWindow* const w) throw()
  63023. {
  63024. windows.add (w);
  63025. startTimer (10);
  63026. return isWindowActive (w);
  63027. }
  63028. void removeWindow (TopLevelWindow* const w) throw()
  63029. {
  63030. startTimer (10);
  63031. if (currentActive == w)
  63032. currentActive = 0;
  63033. windows.removeValue (w);
  63034. if (windows.size() == 0)
  63035. deleteInstance();
  63036. }
  63037. VoidArray windows;
  63038. private:
  63039. TopLevelWindow* currentActive;
  63040. bool isWindowActive (TopLevelWindow* const tlw) const throw()
  63041. {
  63042. return (tlw == currentActive
  63043. || tlw->isParentOf (currentActive)
  63044. || tlw->hasKeyboardFocus (true))
  63045. && tlw->isShowing();
  63046. }
  63047. TopLevelWindowManager (const TopLevelWindowManager&);
  63048. TopLevelWindowManager& operator= (const TopLevelWindowManager&);
  63049. };
  63050. juce_ImplementSingleton_SingleThreaded (TopLevelWindowManager)
  63051. void juce_CheckCurrentlyFocusedTopLevelWindow()
  63052. {
  63053. if (TopLevelWindowManager::getInstanceWithoutCreating() != 0)
  63054. TopLevelWindowManager::getInstanceWithoutCreating()->startTimer (20);
  63055. }
  63056. TopLevelWindow::TopLevelWindow (const String& name,
  63057. const bool addToDesktop_)
  63058. : Component (name),
  63059. useDropShadow (true),
  63060. useNativeTitleBar (false),
  63061. windowIsActive_ (false)
  63062. {
  63063. setOpaque (true);
  63064. if (addToDesktop_)
  63065. Component::addToDesktop (getDesktopWindowStyleFlags());
  63066. else
  63067. setDropShadowEnabled (true);
  63068. setWantsKeyboardFocus (true);
  63069. setBroughtToFrontOnMouseClick (true);
  63070. windowIsActive_ = TopLevelWindowManager::getInstance()->addWindow (this);
  63071. }
  63072. TopLevelWindow::~TopLevelWindow()
  63073. {
  63074. shadower = 0;
  63075. TopLevelWindowManager::getInstance()->removeWindow (this);
  63076. }
  63077. void TopLevelWindow::focusOfChildComponentChanged (FocusChangeType)
  63078. {
  63079. if (hasKeyboardFocus (true))
  63080. TopLevelWindowManager::getInstance()->timerCallback();
  63081. else
  63082. TopLevelWindowManager::getInstance()->startTimer (10);
  63083. }
  63084. void TopLevelWindow::setWindowActive (const bool isNowActive) throw()
  63085. {
  63086. if (windowIsActive_ != isNowActive)
  63087. {
  63088. windowIsActive_ = isNowActive;
  63089. activeWindowStatusChanged();
  63090. }
  63091. }
  63092. void TopLevelWindow::activeWindowStatusChanged()
  63093. {
  63094. }
  63095. void TopLevelWindow::parentHierarchyChanged()
  63096. {
  63097. setDropShadowEnabled (useDropShadow);
  63098. }
  63099. void TopLevelWindow::visibilityChanged()
  63100. {
  63101. if (isShowing())
  63102. toFront (true);
  63103. }
  63104. int TopLevelWindow::getDesktopWindowStyleFlags() const
  63105. {
  63106. int flags = ComponentPeer::windowAppearsOnTaskbar;
  63107. if (useDropShadow)
  63108. flags |= ComponentPeer::windowHasDropShadow;
  63109. if (useNativeTitleBar)
  63110. flags |= ComponentPeer::windowHasTitleBar;
  63111. return flags;
  63112. }
  63113. void TopLevelWindow::setDropShadowEnabled (const bool useShadow)
  63114. {
  63115. useDropShadow = useShadow;
  63116. if (isOnDesktop())
  63117. {
  63118. shadower = 0;
  63119. Component::addToDesktop (getDesktopWindowStyleFlags());
  63120. }
  63121. else
  63122. {
  63123. if (useShadow && isOpaque())
  63124. {
  63125. if (shadower == 0)
  63126. {
  63127. shadower = getLookAndFeel().createDropShadowerForComponent (this);
  63128. if (shadower != 0)
  63129. shadower->setOwner (this);
  63130. }
  63131. }
  63132. else
  63133. {
  63134. shadower = 0;
  63135. }
  63136. }
  63137. }
  63138. void TopLevelWindow::setUsingNativeTitleBar (const bool useNativeTitleBar_)
  63139. {
  63140. if (useNativeTitleBar != useNativeTitleBar_)
  63141. {
  63142. useNativeTitleBar = useNativeTitleBar_;
  63143. recreateDesktopWindow();
  63144. sendLookAndFeelChange();
  63145. }
  63146. }
  63147. void TopLevelWindow::recreateDesktopWindow()
  63148. {
  63149. if (isOnDesktop())
  63150. {
  63151. Component::addToDesktop (getDesktopWindowStyleFlags());
  63152. toFront (true);
  63153. }
  63154. }
  63155. void TopLevelWindow::addToDesktop (int windowStyleFlags, void* nativeWindowToAttachTo)
  63156. {
  63157. /* It's not recommended to change the desktop window flags directly for a TopLevelWindow,
  63158. because this class needs to make sure its layout corresponds with settings like whether
  63159. it's got a native title bar or not.
  63160. If you need custom flags for your window, you can override the getDesktopWindowStyleFlags()
  63161. method. If you do this, it's best to call the base class's getDesktopWindowStyleFlags()
  63162. method, then add or remove whatever flags are necessary from this value before returning it.
  63163. */
  63164. jassert ((windowStyleFlags & ~ComponentPeer::windowIsSemiTransparent)
  63165. == (getDesktopWindowStyleFlags() & ~ComponentPeer::windowIsSemiTransparent));
  63166. Component::addToDesktop (windowStyleFlags, nativeWindowToAttachTo);
  63167. if (windowStyleFlags != getDesktopWindowStyleFlags())
  63168. sendLookAndFeelChange();
  63169. }
  63170. void TopLevelWindow::centreAroundComponent (Component* c, const int width, const int height)
  63171. {
  63172. if (c == 0)
  63173. c = TopLevelWindow::getActiveTopLevelWindow();
  63174. if (c == 0)
  63175. {
  63176. centreWithSize (width, height);
  63177. }
  63178. else
  63179. {
  63180. Point<int> p (c->relativePositionToGlobal (Point<int> ((c->getWidth() - width) / 2,
  63181. (c->getHeight() - height) / 2)));
  63182. Rectangle<int> parentArea (c->getParentMonitorArea());
  63183. if (getParentComponent() != 0)
  63184. {
  63185. p = getParentComponent()->globalPositionToRelative (p);
  63186. parentArea.setBounds (0, 0, getParentWidth(), getParentHeight());
  63187. }
  63188. parentArea.reduce (12, 12);
  63189. setBounds (jlimit (parentArea.getX(), jmax (parentArea.getX(), parentArea.getRight() - width), p.getX()),
  63190. jlimit (parentArea.getY(), jmax (parentArea.getY(), parentArea.getBottom() - height), p.getY()),
  63191. width, height);
  63192. }
  63193. }
  63194. int TopLevelWindow::getNumTopLevelWindows() throw()
  63195. {
  63196. return TopLevelWindowManager::getInstance()->windows.size();
  63197. }
  63198. TopLevelWindow* TopLevelWindow::getTopLevelWindow (const int index) throw()
  63199. {
  63200. return (TopLevelWindow*) TopLevelWindowManager::getInstance()->windows [index];
  63201. }
  63202. TopLevelWindow* TopLevelWindow::getActiveTopLevelWindow() throw()
  63203. {
  63204. TopLevelWindow* best = 0;
  63205. int bestNumTWLParents = -1;
  63206. for (int i = TopLevelWindow::getNumTopLevelWindows(); --i >= 0;)
  63207. {
  63208. TopLevelWindow* const tlw = TopLevelWindow::getTopLevelWindow (i);
  63209. if (tlw->isActiveWindow())
  63210. {
  63211. int numTWLParents = 0;
  63212. const Component* c = tlw->getParentComponent();
  63213. while (c != 0)
  63214. {
  63215. if (dynamic_cast <const TopLevelWindow*> (c) != 0)
  63216. ++numTWLParents;
  63217. c = c->getParentComponent();
  63218. }
  63219. if (bestNumTWLParents < numTWLParents)
  63220. {
  63221. best = tlw;
  63222. bestNumTWLParents = numTWLParents;
  63223. }
  63224. }
  63225. }
  63226. return best;
  63227. }
  63228. END_JUCE_NAMESPACE
  63229. /*** End of inlined file: juce_TopLevelWindow.cpp ***/
  63230. /*** Start of inlined file: juce_Colour.cpp ***/
  63231. BEGIN_JUCE_NAMESPACE
  63232. static uint8 floatAlphaToInt (const float alpha)
  63233. {
  63234. return (uint8) jlimit (0, 0xff, roundToInt (alpha * 255.0f));
  63235. }
  63236. static const float oneOver255 = 1.0f / 255.0f;
  63237. Colour::Colour() throw()
  63238. : argb (0)
  63239. {
  63240. }
  63241. Colour::Colour (const Colour& other) throw()
  63242. : argb (other.argb)
  63243. {
  63244. }
  63245. Colour& Colour::operator= (const Colour& other) throw()
  63246. {
  63247. argb = other.argb;
  63248. return *this;
  63249. }
  63250. bool Colour::operator== (const Colour& other) const throw()
  63251. {
  63252. return argb.getARGB() == other.argb.getARGB();
  63253. }
  63254. bool Colour::operator!= (const Colour& other) const throw()
  63255. {
  63256. return argb.getARGB() != other.argb.getARGB();
  63257. }
  63258. Colour::Colour (const uint32 argb_) throw()
  63259. : argb (argb_)
  63260. {
  63261. }
  63262. Colour::Colour (const uint8 red,
  63263. const uint8 green,
  63264. const uint8 blue) throw()
  63265. {
  63266. argb.setARGB (0xff, red, green, blue);
  63267. }
  63268. const Colour Colour::fromRGB (const uint8 red,
  63269. const uint8 green,
  63270. const uint8 blue) throw()
  63271. {
  63272. return Colour (red, green, blue);
  63273. }
  63274. Colour::Colour (const uint8 red,
  63275. const uint8 green,
  63276. const uint8 blue,
  63277. const uint8 alpha) throw()
  63278. {
  63279. argb.setARGB (alpha, red, green, blue);
  63280. }
  63281. const Colour Colour::fromRGBA (const uint8 red,
  63282. const uint8 green,
  63283. const uint8 blue,
  63284. const uint8 alpha) throw()
  63285. {
  63286. return Colour (red, green, blue, alpha);
  63287. }
  63288. Colour::Colour (const uint8 red,
  63289. const uint8 green,
  63290. const uint8 blue,
  63291. const float alpha) throw()
  63292. {
  63293. argb.setARGB (floatAlphaToInt (alpha), red, green, blue);
  63294. }
  63295. const Colour Colour::fromRGBAFloat (const uint8 red,
  63296. const uint8 green,
  63297. const uint8 blue,
  63298. const float alpha) throw()
  63299. {
  63300. return Colour (red, green, blue, alpha);
  63301. }
  63302. static void convertHSBtoRGB (float h, float s, float v,
  63303. uint8& r, uint8& g, uint8& b) throw()
  63304. {
  63305. v = jlimit (0.0f, 1.0f, v);
  63306. v *= 255.0f;
  63307. const uint8 intV = (uint8) roundToInt (v);
  63308. if (s <= 0)
  63309. {
  63310. r = intV;
  63311. g = intV;
  63312. b = intV;
  63313. }
  63314. else
  63315. {
  63316. s = jmin (1.0f, s);
  63317. h = jlimit (0.0f, 1.0f, h);
  63318. h = (h - floorf (h)) * 6.0f + 0.00001f; // need a small adjustment to compensate for rounding errors
  63319. const float f = h - floorf (h);
  63320. const uint8 x = (uint8) roundToInt (v * (1.0f - s));
  63321. const float y = v * (1.0f - s * f);
  63322. const float z = v * (1.0f - (s * (1.0f - f)));
  63323. if (h < 1.0f)
  63324. {
  63325. r = intV;
  63326. g = (uint8) roundToInt (z);
  63327. b = x;
  63328. }
  63329. else if (h < 2.0f)
  63330. {
  63331. r = (uint8) roundToInt (y);
  63332. g = intV;
  63333. b = x;
  63334. }
  63335. else if (h < 3.0f)
  63336. {
  63337. r = x;
  63338. g = intV;
  63339. b = (uint8) roundToInt (z);
  63340. }
  63341. else if (h < 4.0f)
  63342. {
  63343. r = x;
  63344. g = (uint8) roundToInt (y);
  63345. b = intV;
  63346. }
  63347. else if (h < 5.0f)
  63348. {
  63349. r = (uint8) roundToInt (z);
  63350. g = x;
  63351. b = intV;
  63352. }
  63353. else if (h < 6.0f)
  63354. {
  63355. r = intV;
  63356. g = x;
  63357. b = (uint8) roundToInt (y);
  63358. }
  63359. else
  63360. {
  63361. r = 0;
  63362. g = 0;
  63363. b = 0;
  63364. }
  63365. }
  63366. }
  63367. Colour::Colour (const float hue,
  63368. const float saturation,
  63369. const float brightness,
  63370. const float alpha) throw()
  63371. {
  63372. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63373. convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63374. argb.setARGB (floatAlphaToInt (alpha), r, g, b);
  63375. }
  63376. const Colour Colour::fromHSV (const float hue,
  63377. const float saturation,
  63378. const float brightness,
  63379. const float alpha) throw()
  63380. {
  63381. return Colour (hue, saturation, brightness, alpha);
  63382. }
  63383. Colour::Colour (const float hue,
  63384. const float saturation,
  63385. const float brightness,
  63386. const uint8 alpha) throw()
  63387. {
  63388. uint8 r = getRed(), g = getGreen(), b = getBlue();
  63389. convertHSBtoRGB (hue, saturation, brightness, r, g, b);
  63390. argb.setARGB (alpha, r, g, b);
  63391. }
  63392. Colour::~Colour() throw()
  63393. {
  63394. }
  63395. const PixelARGB Colour::getPixelARGB() const throw()
  63396. {
  63397. PixelARGB p (argb);
  63398. p.premultiply();
  63399. return p;
  63400. }
  63401. uint32 Colour::getARGB() const throw()
  63402. {
  63403. return argb.getARGB();
  63404. }
  63405. bool Colour::isTransparent() const throw()
  63406. {
  63407. return getAlpha() == 0;
  63408. }
  63409. bool Colour::isOpaque() const throw()
  63410. {
  63411. return getAlpha() == 0xff;
  63412. }
  63413. const Colour Colour::withAlpha (const uint8 newAlpha) const throw()
  63414. {
  63415. PixelARGB newCol (argb);
  63416. newCol.setAlpha (newAlpha);
  63417. return Colour (newCol.getARGB());
  63418. }
  63419. const Colour Colour::withAlpha (const float newAlpha) const throw()
  63420. {
  63421. jassert (newAlpha >= 0 && newAlpha <= 1.0f);
  63422. PixelARGB newCol (argb);
  63423. newCol.setAlpha (floatAlphaToInt (newAlpha));
  63424. return Colour (newCol.getARGB());
  63425. }
  63426. const Colour Colour::withMultipliedAlpha (const float alphaMultiplier) const throw()
  63427. {
  63428. jassert (alphaMultiplier >= 0);
  63429. PixelARGB newCol (argb);
  63430. newCol.setAlpha ((uint8) jmin (0xff, roundToInt (alphaMultiplier * newCol.getAlpha())));
  63431. return Colour (newCol.getARGB());
  63432. }
  63433. const Colour Colour::overlaidWith (const Colour& src) const throw()
  63434. {
  63435. const int destAlpha = getAlpha();
  63436. if (destAlpha > 0)
  63437. {
  63438. const int invA = 0xff - (int) src.getAlpha();
  63439. const int resA = 0xff - (((0xff - destAlpha) * invA) >> 8);
  63440. if (resA > 0)
  63441. {
  63442. const int da = (invA * destAlpha) / resA;
  63443. return Colour ((uint8) (src.getRed() + ((((int) getRed() - src.getRed()) * da) >> 8)),
  63444. (uint8) (src.getGreen() + ((((int) getGreen() - src.getGreen()) * da) >> 8)),
  63445. (uint8) (src.getBlue() + ((((int) getBlue() - src.getBlue()) * da) >> 8)),
  63446. (uint8) resA);
  63447. }
  63448. return *this;
  63449. }
  63450. else
  63451. {
  63452. return src;
  63453. }
  63454. }
  63455. const Colour Colour::interpolatedWith (const Colour& other, float proportionOfOther) const throw()
  63456. {
  63457. if (proportionOfOther <= 0)
  63458. return *this;
  63459. if (proportionOfOther >= 1.0f)
  63460. return other;
  63461. PixelARGB c1 (getPixelARGB());
  63462. const PixelARGB c2 (other.getPixelARGB());
  63463. c1.tween (c2, roundToInt (proportionOfOther * 255.0f));
  63464. c1.unpremultiply();
  63465. return Colour (c1.getARGB());
  63466. }
  63467. float Colour::getFloatRed() const throw()
  63468. {
  63469. return getRed() * oneOver255;
  63470. }
  63471. float Colour::getFloatGreen() const throw()
  63472. {
  63473. return getGreen() * oneOver255;
  63474. }
  63475. float Colour::getFloatBlue() const throw()
  63476. {
  63477. return getBlue() * oneOver255;
  63478. }
  63479. float Colour::getFloatAlpha() const throw()
  63480. {
  63481. return getAlpha() * oneOver255;
  63482. }
  63483. void Colour::getHSB (float& h, float& s, float& v) const throw()
  63484. {
  63485. const int r = getRed();
  63486. const int g = getGreen();
  63487. const int b = getBlue();
  63488. const int hi = jmax (r, g, b);
  63489. const int lo = jmin (r, g, b);
  63490. if (hi != 0)
  63491. {
  63492. s = (hi - lo) / (float) hi;
  63493. if (s != 0)
  63494. {
  63495. const float invDiff = 1.0f / (hi - lo);
  63496. const float red = (hi - r) * invDiff;
  63497. const float green = (hi - g) * invDiff;
  63498. const float blue = (hi - b) * invDiff;
  63499. if (r == hi)
  63500. h = blue - green;
  63501. else if (g == hi)
  63502. h = 2.0f + red - blue;
  63503. else
  63504. h = 4.0f + green - red;
  63505. h *= 1.0f / 6.0f;
  63506. if (h < 0)
  63507. ++h;
  63508. }
  63509. else
  63510. {
  63511. h = 0;
  63512. }
  63513. }
  63514. else
  63515. {
  63516. s = 0;
  63517. h = 0;
  63518. }
  63519. v = hi * oneOver255;
  63520. }
  63521. float Colour::getHue() const throw()
  63522. {
  63523. float h, s, b;
  63524. getHSB (h, s, b);
  63525. return h;
  63526. }
  63527. const Colour Colour::withHue (const float hue) const throw()
  63528. {
  63529. float h, s, b;
  63530. getHSB (h, s, b);
  63531. return Colour (hue, s, b, getAlpha());
  63532. }
  63533. const Colour Colour::withRotatedHue (const float amountToRotate) const throw()
  63534. {
  63535. float h, s, b;
  63536. getHSB (h, s, b);
  63537. h += amountToRotate;
  63538. h -= floorf (h);
  63539. return Colour (h, s, b, getAlpha());
  63540. }
  63541. float Colour::getSaturation() const throw()
  63542. {
  63543. float h, s, b;
  63544. getHSB (h, s, b);
  63545. return s;
  63546. }
  63547. const Colour Colour::withSaturation (const float saturation) const throw()
  63548. {
  63549. float h, s, b;
  63550. getHSB (h, s, b);
  63551. return Colour (h, saturation, b, getAlpha());
  63552. }
  63553. const Colour Colour::withMultipliedSaturation (const float amount) const throw()
  63554. {
  63555. float h, s, b;
  63556. getHSB (h, s, b);
  63557. return Colour (h, jmin (1.0f, s * amount), b, getAlpha());
  63558. }
  63559. float Colour::getBrightness() const throw()
  63560. {
  63561. float h, s, b;
  63562. getHSB (h, s, b);
  63563. return b;
  63564. }
  63565. const Colour Colour::withBrightness (const float brightness) const throw()
  63566. {
  63567. float h, s, b;
  63568. getHSB (h, s, b);
  63569. return Colour (h, s, brightness, getAlpha());
  63570. }
  63571. const Colour Colour::withMultipliedBrightness (const float amount) const throw()
  63572. {
  63573. float h, s, b;
  63574. getHSB (h, s, b);
  63575. b *= amount;
  63576. if (b > 1.0f)
  63577. b = 1.0f;
  63578. return Colour (h, s, b, getAlpha());
  63579. }
  63580. const Colour Colour::brighter (float amount) const throw()
  63581. {
  63582. amount = 1.0f / (1.0f + amount);
  63583. return Colour ((uint8) (255 - (amount * (255 - getRed()))),
  63584. (uint8) (255 - (amount * (255 - getGreen()))),
  63585. (uint8) (255 - (amount * (255 - getBlue()))),
  63586. getAlpha());
  63587. }
  63588. const Colour Colour::darker (float amount) const throw()
  63589. {
  63590. amount = 1.0f / (1.0f + amount);
  63591. return Colour ((uint8) (amount * getRed()),
  63592. (uint8) (amount * getGreen()),
  63593. (uint8) (amount * getBlue()),
  63594. getAlpha());
  63595. }
  63596. const Colour Colour::greyLevel (const float brightness) throw()
  63597. {
  63598. const uint8 level
  63599. = (uint8) jlimit (0x00, 0xff, roundToInt (brightness * 255.0f));
  63600. return Colour (level, level, level);
  63601. }
  63602. const Colour Colour::contrasting (const float amount) const throw()
  63603. {
  63604. return overlaidWith ((((int) getRed() + (int) getGreen() + (int) getBlue() >= 3 * 128)
  63605. ? Colours::black
  63606. : Colours::white).withAlpha (amount));
  63607. }
  63608. const Colour Colour::contrasting (const Colour& colour1,
  63609. const Colour& colour2) throw()
  63610. {
  63611. const float b1 = colour1.getBrightness();
  63612. const float b2 = colour2.getBrightness();
  63613. float best = 0.0f;
  63614. float bestDist = 0.0f;
  63615. for (float i = 0.0f; i < 1.0f; i += 0.02f)
  63616. {
  63617. const float d1 = fabsf (i - b1);
  63618. const float d2 = fabsf (i - b2);
  63619. const float dist = jmin (d1, d2, 1.0f - d1, 1.0f - d2);
  63620. if (dist > bestDist)
  63621. {
  63622. best = i;
  63623. bestDist = dist;
  63624. }
  63625. }
  63626. return colour1.overlaidWith (colour2.withMultipliedAlpha (0.5f))
  63627. .withBrightness (best);
  63628. }
  63629. const String Colour::toString() const throw()
  63630. {
  63631. return String::toHexString ((int) argb.getARGB());
  63632. }
  63633. const Colour Colour::fromString (const String& encodedColourString)
  63634. {
  63635. return Colour ((uint32) encodedColourString.getHexValue32());
  63636. }
  63637. END_JUCE_NAMESPACE
  63638. /*** End of inlined file: juce_Colour.cpp ***/
  63639. /*** Start of inlined file: juce_ColourGradient.cpp ***/
  63640. BEGIN_JUCE_NAMESPACE
  63641. ColourGradient::ColourGradient() throw()
  63642. {
  63643. #ifdef JUCE_DEBUG
  63644. x1 = 987654.0f;
  63645. #endif
  63646. }
  63647. ColourGradient::ColourGradient (const Colour& colour1,
  63648. const float x1_,
  63649. const float y1_,
  63650. const Colour& colour2,
  63651. const float x2_,
  63652. const float y2_,
  63653. const bool isRadial_) throw()
  63654. : x1 (x1_),
  63655. y1 (y1_),
  63656. x2 (x2_),
  63657. y2 (y2_),
  63658. isRadial (isRadial_)
  63659. {
  63660. colours.add (0);
  63661. colours.add (colour1.getARGB());
  63662. colours.add (1 << 16);
  63663. colours.add (colour2.getARGB());
  63664. }
  63665. ColourGradient::~ColourGradient() throw()
  63666. {
  63667. }
  63668. void ColourGradient::clearColours() throw()
  63669. {
  63670. colours.clear();
  63671. }
  63672. void ColourGradient::addColour (const double proportionAlongGradient,
  63673. const Colour& colour) throw()
  63674. {
  63675. // must be within the two end-points
  63676. jassert (proportionAlongGradient >= 0 && proportionAlongGradient <= 1.0);
  63677. const uint32 pos = jlimit (0, 65535, roundToInt (proportionAlongGradient * 65536.0));
  63678. int i;
  63679. for (i = 0; i < colours.size(); i += 2)
  63680. if (colours.getUnchecked(i) > pos)
  63681. break;
  63682. colours.insert (i, pos);
  63683. colours.insert (i + 1, colour.getARGB());
  63684. }
  63685. void ColourGradient::multiplyOpacity (const float multiplier) throw()
  63686. {
  63687. for (int i = 1; i < colours.size(); i += 2)
  63688. {
  63689. const Colour c (colours.getUnchecked(i));
  63690. colours.set (i, c.withMultipliedAlpha (multiplier).getARGB());
  63691. }
  63692. }
  63693. int ColourGradient::getNumColours() const throw()
  63694. {
  63695. return colours.size() >> 1;
  63696. }
  63697. double ColourGradient::getColourPosition (const int index) const throw()
  63698. {
  63699. return jlimit (0.0, 1.0, colours [index << 1] / 65535.0);
  63700. }
  63701. const Colour ColourGradient::getColour (const int index) const throw()
  63702. {
  63703. return Colour (colours [(index << 1) + 1]);
  63704. }
  63705. const Colour ColourGradient::getColourAtPosition (const float position) const throw()
  63706. {
  63707. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63708. const int integerPos = jlimit (0, 65535, roundToInt (position * 65536.0f));
  63709. if (integerPos <= 0 || colours.size() <= 2)
  63710. return getColour (0);
  63711. int i = colours.size() - 2;
  63712. while (integerPos < (int) colours.getUnchecked(i))
  63713. i -= 2;
  63714. if (i >= colours.size() - 2)
  63715. return Colour (colours.getUnchecked(i));
  63716. const int pos1 = colours.getUnchecked (i);
  63717. const Colour col1 (colours.getUnchecked (i + 1));
  63718. const int pos2 = colours.getUnchecked (i + 2);
  63719. const Colour col2 (colours.getUnchecked (i + 3));
  63720. return col1.interpolatedWith (col2, (integerPos - pos1) / (float) (pos2 - pos1));
  63721. }
  63722. int ColourGradient::createLookupTable (const AffineTransform& transform, HeapBlock <PixelARGB>& lookupTable) const throw()
  63723. {
  63724. #ifdef JUCE_DEBUG
  63725. // trying to use the object without setting its co-ordinates? Have a careful read of
  63726. // the comments for the constructors.
  63727. jassert (x1 != 987654.0f);
  63728. #endif
  63729. const int numColours = colours.size() >> 1;
  63730. float tx1 = x1, ty1 = y1, tx2 = x2, ty2 = y2;
  63731. transform.transformPoint (tx1, ty1);
  63732. transform.transformPoint (tx2, ty2);
  63733. const double distance = juce_hypot (tx1 - tx2, ty1 - ty2);
  63734. const int numEntries = jlimit (1, (numColours - 1) << 8, 3 * (int) distance);
  63735. lookupTable.malloc (numEntries);
  63736. if (numColours >= 2)
  63737. {
  63738. jassert (colours.getUnchecked (0) == 0); // the first colour specified has to go at position 0
  63739. PixelARGB pix1 (colours.getUnchecked (1));
  63740. pix1.premultiply();
  63741. int index = 0;
  63742. for (int j = 2; j < colours.size(); j += 2)
  63743. {
  63744. const int numToDo = ((colours.getUnchecked (j) * (numEntries - 1)) >> 16) - index;
  63745. PixelARGB pix2 (colours.getUnchecked (j + 1));
  63746. pix2.premultiply();
  63747. for (int i = 0; i < numToDo; ++i)
  63748. {
  63749. jassert (index >= 0 && index < numEntries);
  63750. lookupTable[index] = pix1;
  63751. lookupTable[index].tween (pix2, (i << 8) / numToDo);
  63752. ++index;
  63753. }
  63754. pix1 = pix2;
  63755. }
  63756. while (index < numEntries)
  63757. lookupTable [index++] = pix1;
  63758. }
  63759. else
  63760. {
  63761. jassertfalse // no colours specified!
  63762. }
  63763. return numEntries;
  63764. }
  63765. bool ColourGradient::isOpaque() const throw()
  63766. {
  63767. for (int i = 1; i < colours.size(); i += 2)
  63768. if (PixelARGB (colours.getUnchecked(i)).getAlpha() < 0xff)
  63769. return false;
  63770. return true;
  63771. }
  63772. bool ColourGradient::isInvisible() const throw()
  63773. {
  63774. for (int i = 1; i < colours.size(); i += 2)
  63775. if (PixelARGB (colours.getUnchecked(i)).getAlpha() > 0)
  63776. return false;
  63777. return true;
  63778. }
  63779. END_JUCE_NAMESPACE
  63780. /*** End of inlined file: juce_ColourGradient.cpp ***/
  63781. /*** Start of inlined file: juce_Colours.cpp ***/
  63782. BEGIN_JUCE_NAMESPACE
  63783. const Colour Colours::transparentBlack (0);
  63784. const Colour Colours::transparentWhite (0x00ffffff);
  63785. const Colour Colours::aliceblue (0xfff0f8ff);
  63786. const Colour Colours::antiquewhite (0xfffaebd7);
  63787. const Colour Colours::aqua (0xff00ffff);
  63788. const Colour Colours::aquamarine (0xff7fffd4);
  63789. const Colour Colours::azure (0xfff0ffff);
  63790. const Colour Colours::beige (0xfff5f5dc);
  63791. const Colour Colours::bisque (0xffffe4c4);
  63792. const Colour Colours::black (0xff000000);
  63793. const Colour Colours::blanchedalmond (0xffffebcd);
  63794. const Colour Colours::blue (0xff0000ff);
  63795. const Colour Colours::blueviolet (0xff8a2be2);
  63796. const Colour Colours::brown (0xffa52a2a);
  63797. const Colour Colours::burlywood (0xffdeb887);
  63798. const Colour Colours::cadetblue (0xff5f9ea0);
  63799. const Colour Colours::chartreuse (0xff7fff00);
  63800. const Colour Colours::chocolate (0xffd2691e);
  63801. const Colour Colours::coral (0xffff7f50);
  63802. const Colour Colours::cornflowerblue (0xff6495ed);
  63803. const Colour Colours::cornsilk (0xfffff8dc);
  63804. const Colour Colours::crimson (0xffdc143c);
  63805. const Colour Colours::cyan (0xff00ffff);
  63806. const Colour Colours::darkblue (0xff00008b);
  63807. const Colour Colours::darkcyan (0xff008b8b);
  63808. const Colour Colours::darkgoldenrod (0xffb8860b);
  63809. const Colour Colours::darkgrey (0xff555555);
  63810. const Colour Colours::darkgreen (0xff006400);
  63811. const Colour Colours::darkkhaki (0xffbdb76b);
  63812. const Colour Colours::darkmagenta (0xff8b008b);
  63813. const Colour Colours::darkolivegreen (0xff556b2f);
  63814. const Colour Colours::darkorange (0xffff8c00);
  63815. const Colour Colours::darkorchid (0xff9932cc);
  63816. const Colour Colours::darkred (0xff8b0000);
  63817. const Colour Colours::darksalmon (0xffe9967a);
  63818. const Colour Colours::darkseagreen (0xff8fbc8f);
  63819. const Colour Colours::darkslateblue (0xff483d8b);
  63820. const Colour Colours::darkslategrey (0xff2f4f4f);
  63821. const Colour Colours::darkturquoise (0xff00ced1);
  63822. const Colour Colours::darkviolet (0xff9400d3);
  63823. const Colour Colours::deeppink (0xffff1493);
  63824. const Colour Colours::deepskyblue (0xff00bfff);
  63825. const Colour Colours::dimgrey (0xff696969);
  63826. const Colour Colours::dodgerblue (0xff1e90ff);
  63827. const Colour Colours::firebrick (0xffb22222);
  63828. const Colour Colours::floralwhite (0xfffffaf0);
  63829. const Colour Colours::forestgreen (0xff228b22);
  63830. const Colour Colours::fuchsia (0xffff00ff);
  63831. const Colour Colours::gainsboro (0xffdcdcdc);
  63832. const Colour Colours::gold (0xffffd700);
  63833. const Colour Colours::goldenrod (0xffdaa520);
  63834. const Colour Colours::grey (0xff808080);
  63835. const Colour Colours::green (0xff008000);
  63836. const Colour Colours::greenyellow (0xffadff2f);
  63837. const Colour Colours::honeydew (0xfff0fff0);
  63838. const Colour Colours::hotpink (0xffff69b4);
  63839. const Colour Colours::indianred (0xffcd5c5c);
  63840. const Colour Colours::indigo (0xff4b0082);
  63841. const Colour Colours::ivory (0xfffffff0);
  63842. const Colour Colours::khaki (0xfff0e68c);
  63843. const Colour Colours::lavender (0xffe6e6fa);
  63844. const Colour Colours::lavenderblush (0xfffff0f5);
  63845. const Colour Colours::lemonchiffon (0xfffffacd);
  63846. const Colour Colours::lightblue (0xffadd8e6);
  63847. const Colour Colours::lightcoral (0xfff08080);
  63848. const Colour Colours::lightcyan (0xffe0ffff);
  63849. const Colour Colours::lightgoldenrodyellow (0xfffafad2);
  63850. const Colour Colours::lightgreen (0xff90ee90);
  63851. const Colour Colours::lightgrey (0xffd3d3d3);
  63852. const Colour Colours::lightpink (0xffffb6c1);
  63853. const Colour Colours::lightsalmon (0xffffa07a);
  63854. const Colour Colours::lightseagreen (0xff20b2aa);
  63855. const Colour Colours::lightskyblue (0xff87cefa);
  63856. const Colour Colours::lightslategrey (0xff778899);
  63857. const Colour Colours::lightsteelblue (0xffb0c4de);
  63858. const Colour Colours::lightyellow (0xffffffe0);
  63859. const Colour Colours::lime (0xff00ff00);
  63860. const Colour Colours::limegreen (0xff32cd32);
  63861. const Colour Colours::linen (0xfffaf0e6);
  63862. const Colour Colours::magenta (0xffff00ff);
  63863. const Colour Colours::maroon (0xff800000);
  63864. const Colour Colours::mediumaquamarine (0xff66cdaa);
  63865. const Colour Colours::mediumblue (0xff0000cd);
  63866. const Colour Colours::mediumorchid (0xffba55d3);
  63867. const Colour Colours::mediumpurple (0xff9370db);
  63868. const Colour Colours::mediumseagreen (0xff3cb371);
  63869. const Colour Colours::mediumslateblue (0xff7b68ee);
  63870. const Colour Colours::mediumspringgreen (0xff00fa9a);
  63871. const Colour Colours::mediumturquoise (0xff48d1cc);
  63872. const Colour Colours::mediumvioletred (0xffc71585);
  63873. const Colour Colours::midnightblue (0xff191970);
  63874. const Colour Colours::mintcream (0xfff5fffa);
  63875. const Colour Colours::mistyrose (0xffffe4e1);
  63876. const Colour Colours::navajowhite (0xffffdead);
  63877. const Colour Colours::navy (0xff000080);
  63878. const Colour Colours::oldlace (0xfffdf5e6);
  63879. const Colour Colours::olive (0xff808000);
  63880. const Colour Colours::olivedrab (0xff6b8e23);
  63881. const Colour Colours::orange (0xffffa500);
  63882. const Colour Colours::orangered (0xffff4500);
  63883. const Colour Colours::orchid (0xffda70d6);
  63884. const Colour Colours::palegoldenrod (0xffeee8aa);
  63885. const Colour Colours::palegreen (0xff98fb98);
  63886. const Colour Colours::paleturquoise (0xffafeeee);
  63887. const Colour Colours::palevioletred (0xffdb7093);
  63888. const Colour Colours::papayawhip (0xffffefd5);
  63889. const Colour Colours::peachpuff (0xffffdab9);
  63890. const Colour Colours::peru (0xffcd853f);
  63891. const Colour Colours::pink (0xffffc0cb);
  63892. const Colour Colours::plum (0xffdda0dd);
  63893. const Colour Colours::powderblue (0xffb0e0e6);
  63894. const Colour Colours::purple (0xff800080);
  63895. const Colour Colours::red (0xffff0000);
  63896. const Colour Colours::rosybrown (0xffbc8f8f);
  63897. const Colour Colours::royalblue (0xff4169e1);
  63898. const Colour Colours::saddlebrown (0xff8b4513);
  63899. const Colour Colours::salmon (0xfffa8072);
  63900. const Colour Colours::sandybrown (0xfff4a460);
  63901. const Colour Colours::seagreen (0xff2e8b57);
  63902. const Colour Colours::seashell (0xfffff5ee);
  63903. const Colour Colours::sienna (0xffa0522d);
  63904. const Colour Colours::silver (0xffc0c0c0);
  63905. const Colour Colours::skyblue (0xff87ceeb);
  63906. const Colour Colours::slateblue (0xff6a5acd);
  63907. const Colour Colours::slategrey (0xff708090);
  63908. const Colour Colours::snow (0xfffffafa);
  63909. const Colour Colours::springgreen (0xff00ff7f);
  63910. const Colour Colours::steelblue (0xff4682b4);
  63911. const Colour Colours::tan (0xffd2b48c);
  63912. const Colour Colours::teal (0xff008080);
  63913. const Colour Colours::thistle (0xffd8bfd8);
  63914. const Colour Colours::tomato (0xffff6347);
  63915. const Colour Colours::turquoise (0xff40e0d0);
  63916. const Colour Colours::violet (0xffee82ee);
  63917. const Colour Colours::wheat (0xfff5deb3);
  63918. const Colour Colours::white (0xffffffff);
  63919. const Colour Colours::whitesmoke (0xfff5f5f5);
  63920. const Colour Colours::yellow (0xffffff00);
  63921. const Colour Colours::yellowgreen (0xff9acd32);
  63922. const Colour Colours::findColourForName (const String& colourName,
  63923. const Colour& defaultColour)
  63924. {
  63925. static const int presets[] =
  63926. {
  63927. // (first value is the string's hashcode, second is ARGB)
  63928. 0x05978fff, 0xff000000, /* black */
  63929. 0x06bdcc29, 0xffffffff, /* white */
  63930. 0x002e305a, 0xff0000ff, /* blue */
  63931. 0x00308adf, 0xff808080, /* grey */
  63932. 0x05e0cf03, 0xff008000, /* green */
  63933. 0x0001b891, 0xffff0000, /* red */
  63934. 0xd43c6474, 0xffffff00, /* yellow */
  63935. 0x620886da, 0xfff0f8ff, /* aliceblue */
  63936. 0x20a2676a, 0xfffaebd7, /* antiquewhite */
  63937. 0x002dcebc, 0xff00ffff, /* aqua */
  63938. 0x46bb5f7e, 0xff7fffd4, /* aquamarine */
  63939. 0x0590228f, 0xfff0ffff, /* azure */
  63940. 0x05947fe4, 0xfff5f5dc, /* beige */
  63941. 0xad388e35, 0xffffe4c4, /* bisque */
  63942. 0x00674f7e, 0xffffebcd, /* blanchedalmond */
  63943. 0x39129959, 0xff8a2be2, /* blueviolet */
  63944. 0x059a8136, 0xffa52a2a, /* brown */
  63945. 0x89cea8f9, 0xffdeb887, /* burlywood */
  63946. 0x0fa260cf, 0xff5f9ea0, /* cadetblue */
  63947. 0x6b748956, 0xff7fff00, /* chartreuse */
  63948. 0x2903623c, 0xffd2691e, /* chocolate */
  63949. 0x05a74431, 0xffff7f50, /* coral */
  63950. 0x618d42dd, 0xff6495ed, /* cornflowerblue */
  63951. 0xe4b479fd, 0xfffff8dc, /* cornsilk */
  63952. 0x3d8c4edf, 0xffdc143c, /* crimson */
  63953. 0x002ed323, 0xff00ffff, /* cyan */
  63954. 0x67cc74d0, 0xff00008b, /* darkblue */
  63955. 0x67cd1799, 0xff008b8b, /* darkcyan */
  63956. 0x31bbd168, 0xffb8860b, /* darkgoldenrod */
  63957. 0x67cecf55, 0xff555555, /* darkgrey */
  63958. 0x920b194d, 0xff006400, /* darkgreen */
  63959. 0x923edd4c, 0xffbdb76b, /* darkkhaki */
  63960. 0x5c293873, 0xff8b008b, /* darkmagenta */
  63961. 0x6b6671fe, 0xff556b2f, /* darkolivegreen */
  63962. 0xbcfd2524, 0xffff8c00, /* darkorange */
  63963. 0xbcfdf799, 0xff9932cc, /* darkorchid */
  63964. 0x55ee0d5b, 0xff8b0000, /* darkred */
  63965. 0xc2e5f564, 0xffe9967a, /* darksalmon */
  63966. 0x61be858a, 0xff8fbc8f, /* darkseagreen */
  63967. 0xc2b0f2bd, 0xff483d8b, /* darkslateblue */
  63968. 0xc2b34d42, 0xff2f4f4f, /* darkslategrey */
  63969. 0x7cf2b06b, 0xff00ced1, /* darkturquoise */
  63970. 0xc8769375, 0xff9400d3, /* darkviolet */
  63971. 0x25832862, 0xffff1493, /* deeppink */
  63972. 0xfcad568f, 0xff00bfff, /* deepskyblue */
  63973. 0x634c8b67, 0xff696969, /* dimgrey */
  63974. 0x45c1ce55, 0xff1e90ff, /* dodgerblue */
  63975. 0xef19e3cb, 0xffb22222, /* firebrick */
  63976. 0xb852b195, 0xfffffaf0, /* floralwhite */
  63977. 0xd086fd06, 0xff228b22, /* forestgreen */
  63978. 0xe106b6d7, 0xffff00ff, /* fuchsia */
  63979. 0x7880d61e, 0xffdcdcdc, /* gainsboro */
  63980. 0x00308060, 0xffffd700, /* gold */
  63981. 0xb3b3bc1e, 0xffdaa520, /* goldenrod */
  63982. 0xbab8a537, 0xffadff2f, /* greenyellow */
  63983. 0xe4cacafb, 0xfff0fff0, /* honeydew */
  63984. 0x41892743, 0xffff69b4, /* hotpink */
  63985. 0xd5796f1a, 0xffcd5c5c, /* indianred */
  63986. 0xb969fed2, 0xff4b0082, /* indigo */
  63987. 0x05fef6a9, 0xfffffff0, /* ivory */
  63988. 0x06149302, 0xfff0e68c, /* khaki */
  63989. 0xad5a05c7, 0xffe6e6fa, /* lavender */
  63990. 0x7c4d5b99, 0xfffff0f5, /* lavenderblush */
  63991. 0x195756f0, 0xfffffacd, /* lemonchiffon */
  63992. 0x28e4ea70, 0xffadd8e6, /* lightblue */
  63993. 0xf3c7ccdb, 0xfff08080, /* lightcoral */
  63994. 0x28e58d39, 0xffe0ffff, /* lightcyan */
  63995. 0x21234e3c, 0xfffafad2, /* lightgoldenrodyellow */
  63996. 0xf40157ad, 0xff90ee90, /* lightgreen */
  63997. 0x28e744f5, 0xffd3d3d3, /* lightgrey */
  63998. 0x28eb3b8c, 0xffffb6c1, /* lightpink */
  63999. 0x9fb78304, 0xffffa07a, /* lightsalmon */
  64000. 0x50632b2a, 0xff20b2aa, /* lightseagreen */
  64001. 0x68fb7b25, 0xff87cefa, /* lightskyblue */
  64002. 0xa8a35ba2, 0xff778899, /* lightslategrey */
  64003. 0xa20d484f, 0xffb0c4de, /* lightsteelblue */
  64004. 0xaa2cf10a, 0xffffffe0, /* lightyellow */
  64005. 0x0032afd5, 0xff00ff00, /* lime */
  64006. 0x607bbc4e, 0xff32cd32, /* limegreen */
  64007. 0x06234efa, 0xfffaf0e6, /* linen */
  64008. 0x316858a9, 0xffff00ff, /* magenta */
  64009. 0xbf8ca470, 0xff800000, /* maroon */
  64010. 0xbd58e0b3, 0xff66cdaa, /* mediumaquamarine */
  64011. 0x967dfd4f, 0xff0000cd, /* mediumblue */
  64012. 0x056f5c58, 0xffba55d3, /* mediumorchid */
  64013. 0x07556b71, 0xff9370db, /* mediumpurple */
  64014. 0x5369b689, 0xff3cb371, /* mediumseagreen */
  64015. 0x066be19e, 0xff7b68ee, /* mediumslateblue */
  64016. 0x3256b281, 0xff00fa9a, /* mediumspringgreen */
  64017. 0xc0ad9f4c, 0xff48d1cc, /* mediumturquoise */
  64018. 0x628e63dd, 0xffc71585, /* mediumvioletred */
  64019. 0x168eb32a, 0xff191970, /* midnightblue */
  64020. 0x4306b960, 0xfff5fffa, /* mintcream */
  64021. 0x4cbc0e6b, 0xffffe4e1, /* mistyrose */
  64022. 0xe97218a6, 0xffffdead, /* navajowhite */
  64023. 0x00337bb6, 0xff000080, /* navy */
  64024. 0xadd2d33e, 0xfffdf5e6, /* oldlace */
  64025. 0x064ee1db, 0xff808000, /* olive */
  64026. 0x9e33a98a, 0xff6b8e23, /* olivedrab */
  64027. 0xc3de262e, 0xffffa500, /* orange */
  64028. 0x58bebba3, 0xffff4500, /* orangered */
  64029. 0xc3def8a3, 0xffda70d6, /* orchid */
  64030. 0x28cb4834, 0xffeee8aa, /* palegoldenrod */
  64031. 0x3d9dd619, 0xff98fb98, /* palegreen */
  64032. 0x74022737, 0xffafeeee, /* paleturquoise */
  64033. 0x15e2ebc8, 0xffdb7093, /* palevioletred */
  64034. 0x5fd898e2, 0xffffefd5, /* papayawhip */
  64035. 0x93e1b776, 0xffffdab9, /* peachpuff */
  64036. 0x003472f8, 0xffcd853f, /* peru */
  64037. 0x00348176, 0xffffc0cb, /* pink */
  64038. 0x00348d94, 0xffdda0dd, /* plum */
  64039. 0xd036be93, 0xffb0e0e6, /* powderblue */
  64040. 0xc5c507bc, 0xff800080, /* purple */
  64041. 0xa89d65b3, 0xffbc8f8f, /* rosybrown */
  64042. 0xbd9413e1, 0xff4169e1, /* royalblue */
  64043. 0xf456044f, 0xff8b4513, /* saddlebrown */
  64044. 0xc9c6f66e, 0xfffa8072, /* salmon */
  64045. 0x0bb131e1, 0xfff4a460, /* sandybrown */
  64046. 0x34636c14, 0xff2e8b57, /* seagreen */
  64047. 0x3507fb41, 0xfffff5ee, /* seashell */
  64048. 0xca348772, 0xffa0522d, /* sienna */
  64049. 0xca37d30d, 0xffc0c0c0, /* silver */
  64050. 0x80da74fb, 0xff87ceeb, /* skyblue */
  64051. 0x44a8dd73, 0xff6a5acd, /* slateblue */
  64052. 0x44ab37f8, 0xff708090, /* slategrey */
  64053. 0x0035f183, 0xfffffafa, /* snow */
  64054. 0xd5440d16, 0xff00ff7f, /* springgreen */
  64055. 0x3e1524a5, 0xff4682b4, /* steelblue */
  64056. 0x0001bfa1, 0xffd2b48c, /* tan */
  64057. 0x0036425c, 0xff008080, /* teal */
  64058. 0xafc8858f, 0xffd8bfd8, /* thistle */
  64059. 0xcc41600a, 0xffff6347, /* tomato */
  64060. 0xfeea9b21, 0xff40e0d0, /* turquoise */
  64061. 0xcf57947f, 0xffee82ee, /* violet */
  64062. 0x06bdbae7, 0xfff5deb3, /* wheat */
  64063. 0x10802ee6, 0xfff5f5f5, /* whitesmoke */
  64064. 0xe1b5130f, 0xff9acd32 /* yellowgreen */
  64065. };
  64066. const int hash = colourName.trim().toLowerCase().hashCode();
  64067. for (int i = 0; i < numElementsInArray (presets); i += 2)
  64068. if (presets [i] == hash)
  64069. return Colour (presets [i + 1]);
  64070. return defaultColour;
  64071. }
  64072. END_JUCE_NAMESPACE
  64073. /*** End of inlined file: juce_Colours.cpp ***/
  64074. /*** Start of inlined file: juce_EdgeTable.cpp ***/
  64075. BEGIN_JUCE_NAMESPACE
  64076. const int juce_edgeTableDefaultEdgesPerLine = 32;
  64077. EdgeTable::EdgeTable (const Rectangle<int>& bounds_,
  64078. const Path& path, const AffineTransform& transform) throw()
  64079. : bounds (bounds_),
  64080. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64081. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64082. needToCheckEmptinesss (true)
  64083. {
  64084. table.malloc ((bounds.getHeight() + 1) * lineStrideElements);
  64085. int* t = table;
  64086. for (int i = bounds.getHeight(); --i >= 0;)
  64087. {
  64088. *t = 0;
  64089. t += lineStrideElements;
  64090. }
  64091. const int topLimit = bounds.getY() << 8;
  64092. const int heightLimit = bounds.getHeight() << 8;
  64093. const int leftLimit = bounds.getX() << 8;
  64094. const int rightLimit = bounds.getRight() << 8;
  64095. PathFlatteningIterator iter (path, transform);
  64096. while (iter.next())
  64097. {
  64098. int y1 = roundToInt (iter.y1 * 256.0f);
  64099. int y2 = roundToInt (iter.y2 * 256.0f);
  64100. if (y1 != y2)
  64101. {
  64102. y1 -= topLimit;
  64103. y2 -= topLimit;
  64104. const int startY = y1;
  64105. int direction = -1;
  64106. if (y1 > y2)
  64107. {
  64108. swapVariables (y1, y2);
  64109. direction = 1;
  64110. }
  64111. if (y1 < 0)
  64112. y1 = 0;
  64113. if (y2 > heightLimit)
  64114. y2 = heightLimit;
  64115. if (y1 < y2)
  64116. {
  64117. const double startX = 256.0f * iter.x1;
  64118. const double multiplier = (iter.x2 - iter.x1) / (iter.y2 - iter.y1);
  64119. const int stepSize = jlimit (1, 256, 256 / (1 + (int) fabs (multiplier)));
  64120. do
  64121. {
  64122. const int step = jmin (stepSize, y2 - y1, 256 - (y1 & 255));
  64123. int x = roundToInt (startX + multiplier * ((y1 + (step >> 1)) - startY));
  64124. if (x < leftLimit)
  64125. x = leftLimit;
  64126. else if (x >= rightLimit)
  64127. x = rightLimit - 1;
  64128. addEdgePoint (x, y1 >> 8, direction * step);
  64129. y1 += step;
  64130. }
  64131. while (y1 < y2);
  64132. }
  64133. }
  64134. }
  64135. sanitiseLevels (path.isUsingNonZeroWinding());
  64136. }
  64137. EdgeTable::EdgeTable (const Rectangle<int>& rectangleToAdd) throw()
  64138. : bounds (rectangleToAdd),
  64139. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64140. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64141. needToCheckEmptinesss (true)
  64142. {
  64143. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64144. table[0] = 0;
  64145. const int x1 = rectangleToAdd.getX() << 8;
  64146. const int x2 = rectangleToAdd.getRight() << 8;
  64147. int* t = table;
  64148. for (int i = rectangleToAdd.getHeight(); --i >= 0;)
  64149. {
  64150. t[0] = 2;
  64151. t[1] = x1;
  64152. t[2] = 255;
  64153. t[3] = x2;
  64154. t[4] = 0;
  64155. t += lineStrideElements;
  64156. }
  64157. }
  64158. EdgeTable::EdgeTable (const RectangleList& rectanglesToAdd) throw()
  64159. : bounds (rectanglesToAdd.getBounds()),
  64160. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64161. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64162. needToCheckEmptinesss (true)
  64163. {
  64164. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64165. int* t = table;
  64166. for (int i = bounds.getHeight(); --i >= 0;)
  64167. {
  64168. *t = 0;
  64169. t += lineStrideElements;
  64170. }
  64171. for (RectangleList::Iterator iter (rectanglesToAdd); iter.next();)
  64172. {
  64173. const Rectangle<int>* const r = iter.getRectangle();
  64174. const int x1 = r->getX() << 8;
  64175. const int x2 = r->getRight() << 8;
  64176. int y = r->getY() - bounds.getY();
  64177. for (int j = r->getHeight(); --j >= 0;)
  64178. {
  64179. addEdgePoint (x1, y, 255);
  64180. addEdgePoint (x2, y, -255);
  64181. ++y;
  64182. }
  64183. }
  64184. sanitiseLevels (true);
  64185. }
  64186. EdgeTable::EdgeTable (const float x, const float y, const float w, const float h) throw()
  64187. : bounds (Rectangle<int> ((int) floorf (x), roundToInt (y * 256.0f) >> 8, 2 + (int) w, 2 + (int) h)),
  64188. maxEdgesPerLine (juce_edgeTableDefaultEdgesPerLine),
  64189. lineStrideElements ((juce_edgeTableDefaultEdgesPerLine << 1) + 1),
  64190. needToCheckEmptinesss (true)
  64191. {
  64192. jassert (w > 0 && h > 0);
  64193. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64194. table[0] = 0;
  64195. const int x1 = roundToInt (x * 256.0f);
  64196. const int x2 = roundToInt ((x + w) * 256.0f);
  64197. int y1 = roundToInt (y * 256.0f) - (bounds.getY() << 8);
  64198. jassert (y1 < 256);
  64199. int y2 = roundToInt ((y + h) * 256.0f) - (bounds.getY() << 8);
  64200. if (x2 <= x1 || y2 <= y1)
  64201. {
  64202. bounds.setHeight (0);
  64203. return;
  64204. }
  64205. int lineY = 0;
  64206. int* t = table;
  64207. if ((y1 >> 8) == (y2 >> 8))
  64208. {
  64209. t[0] = 2;
  64210. t[1] = x1;
  64211. t[2] = y2 - y1;
  64212. t[3] = x2;
  64213. t[4] = 0;
  64214. ++lineY;
  64215. t += lineStrideElements;
  64216. }
  64217. else
  64218. {
  64219. t[0] = 2;
  64220. t[1] = x1;
  64221. t[2] = 255 - (y1 & 255);
  64222. t[3] = x2;
  64223. t[4] = 0;
  64224. ++lineY;
  64225. t += lineStrideElements;
  64226. while (lineY < (y2 >> 8))
  64227. {
  64228. t[0] = 2;
  64229. t[1] = x1;
  64230. t[2] = 255;
  64231. t[3] = x2;
  64232. t[4] = 0;
  64233. ++lineY;
  64234. t += lineStrideElements;
  64235. }
  64236. jassert (lineY < bounds.getHeight());
  64237. t[0] = 2;
  64238. t[1] = x1;
  64239. t[2] = y2 & 255;
  64240. t[3] = x2;
  64241. t[4] = 0;
  64242. ++lineY;
  64243. t += lineStrideElements;
  64244. }
  64245. while (lineY < bounds.getHeight())
  64246. {
  64247. t[0] = 0;
  64248. t += lineStrideElements;
  64249. ++lineY;
  64250. }
  64251. }
  64252. EdgeTable::EdgeTable (const EdgeTable& other) throw()
  64253. : table (0)
  64254. {
  64255. operator= (other);
  64256. }
  64257. EdgeTable& EdgeTable::operator= (const EdgeTable& other) throw()
  64258. {
  64259. bounds = other.bounds;
  64260. maxEdgesPerLine = other.maxEdgesPerLine;
  64261. lineStrideElements = other.lineStrideElements;
  64262. needToCheckEmptinesss = other.needToCheckEmptinesss;
  64263. table.malloc (jmax (1, bounds.getHeight()) * lineStrideElements);
  64264. copyEdgeTableData (table, lineStrideElements, other.table, lineStrideElements, bounds.getHeight());
  64265. return *this;
  64266. }
  64267. EdgeTable::~EdgeTable() throw()
  64268. {
  64269. }
  64270. void EdgeTable::copyEdgeTableData (int* dest, const int destLineStride, const int* src, const int srcLineStride, int numLines) throw()
  64271. {
  64272. while (--numLines >= 0)
  64273. {
  64274. memcpy (dest, src, (src[0] * 2 + 1) * sizeof (int));
  64275. src += srcLineStride;
  64276. dest += destLineStride;
  64277. }
  64278. }
  64279. void EdgeTable::sanitiseLevels (const bool useNonZeroWinding) throw()
  64280. {
  64281. // Convert the table from relative windings to absolute levels..
  64282. int* lineStart = table;
  64283. for (int i = bounds.getHeight(); --i >= 0;)
  64284. {
  64285. int* line = lineStart;
  64286. lineStart += lineStrideElements;
  64287. int num = *line;
  64288. if (num == 0)
  64289. continue;
  64290. int level = 0;
  64291. if (useNonZeroWinding)
  64292. {
  64293. while (--num > 0)
  64294. {
  64295. line += 2;
  64296. level += *line;
  64297. int corrected = abs (level);
  64298. if (corrected >> 8)
  64299. corrected = 255;
  64300. *line = corrected;
  64301. }
  64302. }
  64303. else
  64304. {
  64305. while (--num > 0)
  64306. {
  64307. line += 2;
  64308. level += *line;
  64309. int corrected = abs (level);
  64310. if (corrected >> 8)
  64311. {
  64312. corrected &= 511;
  64313. if (corrected >> 8)
  64314. corrected = 511 - corrected;
  64315. }
  64316. *line = corrected;
  64317. }
  64318. }
  64319. line[2] = 0; // force the last level to 0, just in case something went wrong in creating the table
  64320. }
  64321. }
  64322. void EdgeTable::remapTableForNumEdges (const int newNumEdgesPerLine) throw()
  64323. {
  64324. if (newNumEdgesPerLine != maxEdgesPerLine)
  64325. {
  64326. maxEdgesPerLine = newNumEdgesPerLine;
  64327. jassert (bounds.getHeight() > 0);
  64328. const int newLineStrideElements = maxEdgesPerLine * 2 + 1;
  64329. HeapBlock <int> newTable (bounds.getHeight() * newLineStrideElements);
  64330. copyEdgeTableData (newTable, newLineStrideElements, table, lineStrideElements, bounds.getHeight());
  64331. table.swapWith (newTable);
  64332. lineStrideElements = newLineStrideElements;
  64333. }
  64334. }
  64335. void EdgeTable::optimiseTable() throw()
  64336. {
  64337. int maxLineElements = 0;
  64338. for (int i = bounds.getHeight(); --i >= 0;)
  64339. maxLineElements = jmax (maxLineElements, table [i * lineStrideElements]);
  64340. remapTableForNumEdges (maxLineElements);
  64341. }
  64342. void EdgeTable::addEdgePoint (const int x, const int y, const int winding) throw()
  64343. {
  64344. jassert (y >= 0 && y < bounds.getHeight());
  64345. int* line = table + lineStrideElements * y;
  64346. const int numPoints = line[0];
  64347. int n = numPoints << 1;
  64348. if (n > 0)
  64349. {
  64350. while (n > 0)
  64351. {
  64352. const int cx = line [n - 1];
  64353. if (cx <= x)
  64354. {
  64355. if (cx == x)
  64356. {
  64357. line [n] += winding;
  64358. return;
  64359. }
  64360. break;
  64361. }
  64362. n -= 2;
  64363. }
  64364. if (numPoints >= maxEdgesPerLine)
  64365. {
  64366. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64367. jassert (numPoints < maxEdgesPerLine);
  64368. line = table + lineStrideElements * y;
  64369. }
  64370. memmove (line + (n + 3), line + (n + 1), sizeof (int) * ((numPoints << 1) - n));
  64371. }
  64372. line [n + 1] = x;
  64373. line [n + 2] = winding;
  64374. line[0]++;
  64375. }
  64376. void EdgeTable::translate (float dx, int dy) throw()
  64377. {
  64378. bounds.setPosition (bounds.getX() + (int) floorf (dx), bounds.getY() + dy);
  64379. int* lineStart = table;
  64380. const int intDx = (int) (dx * 256.0f);
  64381. for (int i = bounds.getHeight(); --i >= 0;)
  64382. {
  64383. int* line = lineStart;
  64384. lineStart += lineStrideElements;
  64385. int num = *line++;
  64386. while (--num >= 0)
  64387. {
  64388. *line += intDx;
  64389. line += 2;
  64390. }
  64391. }
  64392. }
  64393. void EdgeTable::intersectWithEdgeTableLine (const int y, const int* otherLine) throw()
  64394. {
  64395. jassert (y >= 0 && y < bounds.getHeight());
  64396. int* dest = table + lineStrideElements * y;
  64397. if (dest[0] == 0)
  64398. return;
  64399. int otherNumPoints = *otherLine;
  64400. if (otherNumPoints == 0)
  64401. {
  64402. *dest = 0;
  64403. return;
  64404. }
  64405. const int right = bounds.getRight() << 8;
  64406. // optimise for the common case where our line lies entirely within a
  64407. // single pair of points, as happens when clipping to a simple rect.
  64408. if (otherNumPoints == 2 && otherLine[2] >= 255)
  64409. {
  64410. clipEdgeTableLineToRange (dest, otherLine[1], jmin (right, otherLine[3]));
  64411. return;
  64412. }
  64413. ++otherLine;
  64414. const size_t lineSizeBytes = (dest[0] * 2 + 1) * sizeof (int);
  64415. int* temp = (int*) alloca (lineSizeBytes);
  64416. memcpy (temp, dest, lineSizeBytes);
  64417. const int* src1 = temp;
  64418. int srcNum1 = *src1++;
  64419. int x1 = *src1++;
  64420. const int* src2 = otherLine;
  64421. int srcNum2 = otherNumPoints;
  64422. int x2 = *src2++;
  64423. int destIndex = 0, destTotal = 0;
  64424. int level1 = 0, level2 = 0;
  64425. int lastX = std::numeric_limits<int>::min(), lastLevel = 0;
  64426. while (srcNum1 > 0 && srcNum2 > 0)
  64427. {
  64428. int nextX;
  64429. if (x1 < x2)
  64430. {
  64431. nextX = x1;
  64432. level1 = *src1++;
  64433. x1 = *src1++;
  64434. --srcNum1;
  64435. }
  64436. else if (x1 == x2)
  64437. {
  64438. nextX = x1;
  64439. level1 = *src1++;
  64440. level2 = *src2++;
  64441. x1 = *src1++;
  64442. x2 = *src2++;
  64443. --srcNum1;
  64444. --srcNum2;
  64445. }
  64446. else
  64447. {
  64448. nextX = x2;
  64449. level2 = *src2++;
  64450. x2 = *src2++;
  64451. --srcNum2;
  64452. }
  64453. if (nextX > lastX)
  64454. {
  64455. if (nextX >= right)
  64456. break;
  64457. lastX = nextX;
  64458. const int nextLevel = (level1 * (level2 + 1)) >> 8;
  64459. jassert (((unsigned int) nextLevel) < (unsigned int) 256);
  64460. if (nextLevel != lastLevel)
  64461. {
  64462. if (destTotal >= maxEdgesPerLine)
  64463. {
  64464. dest[0] = destTotal;
  64465. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64466. dest = table + lineStrideElements * y;
  64467. }
  64468. ++destTotal;
  64469. lastLevel = nextLevel;
  64470. dest[++destIndex] = nextX;
  64471. dest[++destIndex] = nextLevel;
  64472. }
  64473. }
  64474. }
  64475. if (lastLevel > 0)
  64476. {
  64477. if (destTotal >= maxEdgesPerLine)
  64478. {
  64479. dest[0] = destTotal;
  64480. remapTableForNumEdges (maxEdgesPerLine + juce_edgeTableDefaultEdgesPerLine);
  64481. dest = table + lineStrideElements * y;
  64482. }
  64483. ++destTotal;
  64484. dest[++destIndex] = right;
  64485. dest[++destIndex] = 0;
  64486. }
  64487. dest[0] = destTotal;
  64488. #if JUCE_DEBUG
  64489. int last = std::numeric_limits<int>::min();
  64490. for (int i = 0; i < dest[0]; ++i)
  64491. {
  64492. jassert (dest[i * 2 + 1] > last);
  64493. last = dest[i * 2 + 1];
  64494. }
  64495. jassert (dest [dest[0] * 2] == 0);
  64496. #endif
  64497. }
  64498. void EdgeTable::clipEdgeTableLineToRange (int* dest, const int x1, const int x2) throw()
  64499. {
  64500. int* lastItem = dest + (dest[0] * 2 - 1);
  64501. if (x2 < lastItem[0])
  64502. {
  64503. if (x2 <= dest[1])
  64504. {
  64505. dest[0] = 0;
  64506. return;
  64507. }
  64508. while (x2 < lastItem[-2])
  64509. {
  64510. --(dest[0]);
  64511. lastItem -= 2;
  64512. }
  64513. lastItem[0] = x2;
  64514. lastItem[1] = 0;
  64515. }
  64516. if (x1 > dest[1])
  64517. {
  64518. while (lastItem[0] > x1)
  64519. lastItem -= 2;
  64520. const int itemsRemoved = (int) (lastItem - (dest + 1)) / 2;
  64521. if (itemsRemoved > 0)
  64522. {
  64523. dest[0] -= itemsRemoved;
  64524. memmove (dest + 1, lastItem, dest[0] * (sizeof (int) * 2));
  64525. }
  64526. dest[1] = x1;
  64527. }
  64528. }
  64529. void EdgeTable::clipToRectangle (const Rectangle<int>& r) throw()
  64530. {
  64531. const Rectangle<int> clipped (r.getIntersection (bounds));
  64532. if (clipped.isEmpty())
  64533. {
  64534. needToCheckEmptinesss = false;
  64535. bounds.setHeight (0);
  64536. }
  64537. else
  64538. {
  64539. const int top = clipped.getY() - bounds.getY();
  64540. const int bottom = clipped.getBottom() - bounds.getY();
  64541. if (bottom < bounds.getHeight())
  64542. bounds.setHeight (bottom);
  64543. if (clipped.getRight() < bounds.getRight())
  64544. bounds.setRight (clipped.getRight());
  64545. for (int i = top; --i >= 0;)
  64546. table [lineStrideElements * i] = 0;
  64547. if (clipped.getX() > bounds.getX())
  64548. {
  64549. const int x1 = clipped.getX() << 8;
  64550. const int x2 = jmin (bounds.getRight(), clipped.getRight()) << 8;
  64551. int* line = table + lineStrideElements * top;
  64552. for (int i = bottom - top; --i >= 0;)
  64553. {
  64554. if (line[0] != 0)
  64555. clipEdgeTableLineToRange (line, x1, x2);
  64556. line += lineStrideElements;
  64557. }
  64558. }
  64559. needToCheckEmptinesss = true;
  64560. }
  64561. }
  64562. void EdgeTable::excludeRectangle (const Rectangle<int>& r) throw()
  64563. {
  64564. const Rectangle<int> clipped (r.getIntersection (bounds));
  64565. if (! clipped.isEmpty())
  64566. {
  64567. const int top = clipped.getY() - bounds.getY();
  64568. const int bottom = clipped.getBottom() - bounds.getY();
  64569. //XXX optimise here by shortening the table if it fills top or bottom
  64570. const int rectLine[] = { 4, std::numeric_limits<int>::min(), 255,
  64571. clipped.getX() << 8, 0,
  64572. clipped.getRight() << 8, 255,
  64573. std::numeric_limits<int>::max(), 0 };
  64574. for (int i = top; i < bottom; ++i)
  64575. intersectWithEdgeTableLine (i, rectLine);
  64576. needToCheckEmptinesss = true;
  64577. }
  64578. }
  64579. void EdgeTable::clipToEdgeTable (const EdgeTable& other)
  64580. {
  64581. const Rectangle<int> clipped (other.bounds.getIntersection (bounds));
  64582. if (clipped.isEmpty())
  64583. {
  64584. needToCheckEmptinesss = false;
  64585. bounds.setHeight (0);
  64586. }
  64587. else
  64588. {
  64589. const int top = clipped.getY() - bounds.getY();
  64590. const int bottom = clipped.getBottom() - bounds.getY();
  64591. if (bottom < bounds.getHeight())
  64592. bounds.setHeight (bottom);
  64593. if (clipped.getRight() < bounds.getRight())
  64594. bounds.setRight (clipped.getRight());
  64595. int i = 0;
  64596. for (i = top; --i >= 0;)
  64597. table [lineStrideElements * i] = 0;
  64598. const int* otherLine = other.table + other.lineStrideElements * (clipped.getY() - other.bounds.getY());
  64599. for (i = top; i < bottom; ++i)
  64600. {
  64601. intersectWithEdgeTableLine (i, otherLine);
  64602. otherLine += other.lineStrideElements;
  64603. }
  64604. needToCheckEmptinesss = true;
  64605. }
  64606. }
  64607. void EdgeTable::clipLineToMask (int x, int y, uint8* mask, int maskStride, int numPixels) throw()
  64608. {
  64609. y -= bounds.getY();
  64610. if (y < 0 || y >= bounds.getHeight())
  64611. return;
  64612. needToCheckEmptinesss = true;
  64613. if (numPixels <= 0)
  64614. {
  64615. table [lineStrideElements * y] = 0;
  64616. return;
  64617. }
  64618. int* tempLine = (int*) alloca ((numPixels * 2 + 4) * sizeof (int));
  64619. int destIndex = 0, lastLevel = 0;
  64620. while (--numPixels >= 0)
  64621. {
  64622. const int alpha = *mask;
  64623. mask += maskStride;
  64624. if (alpha != lastLevel)
  64625. {
  64626. tempLine[++destIndex] = (x << 8);
  64627. tempLine[++destIndex] = alpha;
  64628. lastLevel = alpha;
  64629. }
  64630. ++x;
  64631. }
  64632. if (lastLevel > 0)
  64633. {
  64634. tempLine[++destIndex] = (x << 8);
  64635. tempLine[++destIndex] = 0;
  64636. }
  64637. tempLine[0] = destIndex >> 1;
  64638. intersectWithEdgeTableLine (y, tempLine);
  64639. }
  64640. bool EdgeTable::isEmpty() throw()
  64641. {
  64642. if (needToCheckEmptinesss)
  64643. {
  64644. needToCheckEmptinesss = false;
  64645. int* t = table;
  64646. for (int i = bounds.getHeight(); --i >= 0;)
  64647. {
  64648. if (t[0] > 1)
  64649. return false;
  64650. t += lineStrideElements;
  64651. }
  64652. bounds.setHeight (0);
  64653. }
  64654. return bounds.getHeight() == 0;
  64655. }
  64656. END_JUCE_NAMESPACE
  64657. /*** End of inlined file: juce_EdgeTable.cpp ***/
  64658. /*** Start of inlined file: juce_FillType.cpp ***/
  64659. BEGIN_JUCE_NAMESPACE
  64660. FillType::FillType() throw()
  64661. : colour (0xff000000), image (0)
  64662. {
  64663. }
  64664. FillType::FillType (const Colour& colour_) throw()
  64665. : colour (colour_), image (0)
  64666. {
  64667. }
  64668. FillType::FillType (const ColourGradient& gradient_) throw()
  64669. : colour (0xff000000), gradient (new ColourGradient (gradient_)), image (0)
  64670. {
  64671. }
  64672. FillType::FillType (const Image& image_, const AffineTransform& transform_) throw()
  64673. : colour (0xff000000), image (&image_), transform (transform_)
  64674. {
  64675. }
  64676. FillType::FillType (const FillType& other) throw()
  64677. : colour (other.colour),
  64678. gradient (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0),
  64679. image (other.image), transform (other.transform)
  64680. {
  64681. }
  64682. FillType& FillType::operator= (const FillType& other) throw()
  64683. {
  64684. if (this != &other)
  64685. {
  64686. colour = other.colour;
  64687. gradient = (other.gradient != 0 ? new ColourGradient (*other.gradient) : 0);
  64688. image = other.image;
  64689. transform = other.transform;
  64690. }
  64691. return *this;
  64692. }
  64693. FillType::~FillType() throw()
  64694. {
  64695. }
  64696. void FillType::setColour (const Colour& newColour) throw()
  64697. {
  64698. gradient = 0;
  64699. image = 0;
  64700. colour = newColour;
  64701. }
  64702. void FillType::setGradient (const ColourGradient& newGradient) throw()
  64703. {
  64704. if (gradient != 0)
  64705. {
  64706. *gradient = newGradient;
  64707. }
  64708. else
  64709. {
  64710. image = 0;
  64711. gradient = new ColourGradient (newGradient);
  64712. colour = Colours::black;
  64713. }
  64714. }
  64715. void FillType::setTiledImage (const Image& image_, const AffineTransform& transform_) throw()
  64716. {
  64717. gradient = 0;
  64718. image = &image_;
  64719. transform = transform_;
  64720. colour = Colours::black;
  64721. }
  64722. void FillType::setOpacity (const float newOpacity) throw()
  64723. {
  64724. colour = colour.withAlpha (newOpacity);
  64725. }
  64726. END_JUCE_NAMESPACE
  64727. /*** End of inlined file: juce_FillType.cpp ***/
  64728. /*** Start of inlined file: juce_Graphics.cpp ***/
  64729. BEGIN_JUCE_NAMESPACE
  64730. static const Graphics::ResamplingQuality defaultQuality = Graphics::mediumResamplingQuality;
  64731. template <typename Type>
  64732. static bool areCoordsSensibleNumbers (Type x, Type y, Type w, Type h)
  64733. {
  64734. const int maxVal = 0x3fffffff;
  64735. return (int) x >= -maxVal && (int) x <= maxVal
  64736. && (int) y >= -maxVal && (int) y <= maxVal
  64737. && (int) w >= -maxVal && (int) w <= maxVal
  64738. && (int) h >= -maxVal && (int) h <= maxVal;
  64739. }
  64740. LowLevelGraphicsContext::LowLevelGraphicsContext()
  64741. {
  64742. }
  64743. LowLevelGraphicsContext::~LowLevelGraphicsContext()
  64744. {
  64745. }
  64746. Graphics::Graphics (Image& imageToDrawOnto) throw()
  64747. : context (imageToDrawOnto.createLowLevelContext()),
  64748. contextToDelete (context),
  64749. saveStatePending (false)
  64750. {
  64751. resetToDefaultState();
  64752. }
  64753. Graphics::Graphics (LowLevelGraphicsContext* const internalContext) throw()
  64754. : context (internalContext),
  64755. saveStatePending (false)
  64756. {
  64757. resetToDefaultState();
  64758. }
  64759. Graphics::~Graphics() throw()
  64760. {
  64761. }
  64762. void Graphics::resetToDefaultState() throw()
  64763. {
  64764. saveStateIfPending();
  64765. context->setFill (FillType());
  64766. context->setFont (Font());
  64767. context->setInterpolationQuality (defaultQuality);
  64768. }
  64769. bool Graphics::isVectorDevice() const throw()
  64770. {
  64771. return context->isVectorDevice();
  64772. }
  64773. bool Graphics::reduceClipRegion (const int x, const int y,
  64774. const int w, const int h) throw()
  64775. {
  64776. saveStateIfPending();
  64777. return context->clipToRectangle (Rectangle<int> (x, y, w, h));
  64778. }
  64779. bool Graphics::reduceClipRegion (const RectangleList& clipRegion) throw()
  64780. {
  64781. saveStateIfPending();
  64782. return context->clipToRectangleList (clipRegion);
  64783. }
  64784. bool Graphics::reduceClipRegion (const Path& path, const AffineTransform& transform) throw()
  64785. {
  64786. saveStateIfPending();
  64787. context->clipToPath (path, transform);
  64788. return ! context->isClipEmpty();
  64789. }
  64790. bool Graphics::reduceClipRegion (const Image& image, const Rectangle<int>& sourceClipRegion, const AffineTransform& transform) throw()
  64791. {
  64792. saveStateIfPending();
  64793. context->clipToImageAlpha (image, sourceClipRegion, transform);
  64794. return ! context->isClipEmpty();
  64795. }
  64796. void Graphics::excludeClipRegion (const int x, const int y,
  64797. const int w, const int h) throw()
  64798. {
  64799. saveStateIfPending();
  64800. context->excludeClipRectangle (Rectangle<int> (x, y, w, h));
  64801. }
  64802. bool Graphics::isClipEmpty() const throw()
  64803. {
  64804. return context->isClipEmpty();
  64805. }
  64806. const Rectangle<int> Graphics::getClipBounds() const throw()
  64807. {
  64808. return context->getClipBounds();
  64809. }
  64810. void Graphics::saveState() throw()
  64811. {
  64812. saveStateIfPending();
  64813. saveStatePending = true;
  64814. }
  64815. void Graphics::restoreState() throw()
  64816. {
  64817. if (saveStatePending)
  64818. saveStatePending = false;
  64819. else
  64820. context->restoreState();
  64821. }
  64822. void Graphics::saveStateIfPending() throw()
  64823. {
  64824. if (saveStatePending)
  64825. {
  64826. saveStatePending = false;
  64827. context->saveState();
  64828. }
  64829. }
  64830. void Graphics::setOrigin (const int newOriginX,
  64831. const int newOriginY) throw()
  64832. {
  64833. saveStateIfPending();
  64834. context->setOrigin (newOriginX, newOriginY);
  64835. }
  64836. bool Graphics::clipRegionIntersects (const int x, const int y,
  64837. const int w, const int h) const throw()
  64838. {
  64839. return context->clipRegionIntersects (Rectangle<int> (x, y, w, h));
  64840. }
  64841. void Graphics::setColour (const Colour& newColour) throw()
  64842. {
  64843. saveStateIfPending();
  64844. context->setFill (FillType (newColour));
  64845. }
  64846. void Graphics::setOpacity (const float newOpacity) throw()
  64847. {
  64848. saveStateIfPending();
  64849. context->setOpacity (newOpacity);
  64850. }
  64851. void Graphics::setGradientFill (const ColourGradient& gradient) throw()
  64852. {
  64853. saveStateIfPending();
  64854. context->setFill (FillType (gradient));
  64855. }
  64856. void Graphics::setTiledImageFill (const Image& imageToUse,
  64857. const int anchorX,
  64858. const int anchorY,
  64859. const float opacity) throw()
  64860. {
  64861. saveStateIfPending();
  64862. context->setFill (FillType (imageToUse, AffineTransform::translation ((float) anchorX, (float) anchorY)));
  64863. context->setOpacity (opacity);
  64864. }
  64865. void Graphics::setFillType (const FillType& newFill) throw()
  64866. {
  64867. saveStateIfPending();
  64868. context->setFill (newFill);
  64869. }
  64870. void Graphics::setFont (const Font& newFont) throw()
  64871. {
  64872. saveStateIfPending();
  64873. context->setFont (newFont);
  64874. }
  64875. void Graphics::setFont (const float newFontHeight,
  64876. const int newFontStyleFlags) throw()
  64877. {
  64878. saveStateIfPending();
  64879. Font f (context->getFont());
  64880. f.setSizeAndStyle (newFontHeight, newFontStyleFlags, 1.0f, 0);
  64881. context->setFont (f);
  64882. }
  64883. void Graphics::drawSingleLineText (const String& text,
  64884. const int startX,
  64885. const int baselineY) const throw()
  64886. {
  64887. if (text.isNotEmpty()
  64888. && startX < context->getClipBounds().getRight())
  64889. {
  64890. GlyphArrangement arr;
  64891. arr.addLineOfText (context->getFont(), text, (float) startX, (float) baselineY);
  64892. arr.draw (*this);
  64893. }
  64894. }
  64895. void Graphics::drawTextAsPath (const String& text,
  64896. const AffineTransform& transform) const throw()
  64897. {
  64898. if (text.isNotEmpty())
  64899. {
  64900. GlyphArrangement arr;
  64901. arr.addLineOfText (context->getFont(), text, 0.0f, 0.0f);
  64902. arr.draw (*this, transform);
  64903. }
  64904. }
  64905. void Graphics::drawMultiLineText (const String& text,
  64906. const int startX,
  64907. const int baselineY,
  64908. const int maximumLineWidth) const throw()
  64909. {
  64910. if (text.isNotEmpty()
  64911. && startX < context->getClipBounds().getRight())
  64912. {
  64913. GlyphArrangement arr;
  64914. arr.addJustifiedText (context->getFont(), text,
  64915. (float) startX, (float) baselineY, (float) maximumLineWidth,
  64916. Justification::left);
  64917. arr.draw (*this);
  64918. }
  64919. }
  64920. void Graphics::drawText (const String& text,
  64921. const int x,
  64922. const int y,
  64923. const int width,
  64924. const int height,
  64925. const Justification& justificationType,
  64926. const bool useEllipsesIfTooBig) const throw()
  64927. {
  64928. if (text.isNotEmpty() && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64929. {
  64930. GlyphArrangement arr;
  64931. arr.addCurtailedLineOfText (context->getFont(), text,
  64932. 0.0f, 0.0f, (float)width,
  64933. useEllipsesIfTooBig);
  64934. arr.justifyGlyphs (0, arr.getNumGlyphs(),
  64935. (float) x, (float) y,
  64936. (float) width, (float) height,
  64937. justificationType);
  64938. arr.draw (*this);
  64939. }
  64940. }
  64941. void Graphics::drawFittedText (const String& text,
  64942. const int x,
  64943. const int y,
  64944. const int width,
  64945. const int height,
  64946. const Justification& justification,
  64947. const int maximumNumberOfLines,
  64948. const float minimumHorizontalScale) const throw()
  64949. {
  64950. if (text.isNotEmpty()
  64951. && width > 0 && height > 0
  64952. && context->clipRegionIntersects (Rectangle<int> (x, y, width, height)))
  64953. {
  64954. GlyphArrangement arr;
  64955. arr.addFittedText (context->getFont(), text,
  64956. (float) x, (float) y,
  64957. (float) width, (float) height,
  64958. justification,
  64959. maximumNumberOfLines,
  64960. minimumHorizontalScale);
  64961. arr.draw (*this);
  64962. }
  64963. }
  64964. void Graphics::fillRect (int x,
  64965. int y,
  64966. int width,
  64967. int height) const throw()
  64968. {
  64969. // passing in a silly number can cause maths problems in rendering!
  64970. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64971. context->fillRect (Rectangle<int> (x, y, width, height), false);
  64972. }
  64973. void Graphics::fillRect (const Rectangle<int>& r) const throw()
  64974. {
  64975. context->fillRect (r, false);
  64976. }
  64977. void Graphics::fillRect (const float x,
  64978. const float y,
  64979. const float width,
  64980. const float height) const throw()
  64981. {
  64982. // passing in a silly number can cause maths problems in rendering!
  64983. jassert (areCoordsSensibleNumbers (x, y, width, height));
  64984. Path p;
  64985. p.addRectangle (x, y, width, height);
  64986. fillPath (p);
  64987. }
  64988. void Graphics::setPixel (int x, int y) const throw()
  64989. {
  64990. context->fillRect (Rectangle<int> (x, y, 1, 1), false);
  64991. }
  64992. void Graphics::fillAll() const throw()
  64993. {
  64994. fillRect (context->getClipBounds());
  64995. }
  64996. void Graphics::fillAll (const Colour& colourToUse) const throw()
  64997. {
  64998. if (! colourToUse.isTransparent())
  64999. {
  65000. const Rectangle<int> clip (context->getClipBounds());
  65001. context->saveState();
  65002. context->setFill (FillType (colourToUse));
  65003. context->fillRect (clip, false);
  65004. context->restoreState();
  65005. }
  65006. }
  65007. void Graphics::fillPath (const Path& path,
  65008. const AffineTransform& transform) const throw()
  65009. {
  65010. if ((! context->isClipEmpty()) && ! path.isEmpty())
  65011. context->fillPath (path, transform);
  65012. }
  65013. void Graphics::strokePath (const Path& path,
  65014. const PathStrokeType& strokeType,
  65015. const AffineTransform& transform) const throw()
  65016. {
  65017. Path stroke;
  65018. strokeType.createStrokedPath (stroke, path, transform);
  65019. fillPath (stroke);
  65020. }
  65021. void Graphics::drawRect (const int x,
  65022. const int y,
  65023. const int width,
  65024. const int height,
  65025. const int lineThickness) const throw()
  65026. {
  65027. // passing in a silly number can cause maths problems in rendering!
  65028. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65029. context->fillRect (Rectangle<int> (x, y, width, lineThickness), false);
  65030. context->fillRect (Rectangle<int> (x, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  65031. context->fillRect (Rectangle<int> (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2), false);
  65032. context->fillRect (Rectangle<int> (x, y + height - lineThickness, width, lineThickness), false);
  65033. }
  65034. void Graphics::drawRect (const float x,
  65035. const float y,
  65036. const float width,
  65037. const float height,
  65038. const float lineThickness) const throw()
  65039. {
  65040. // passing in a silly number can cause maths problems in rendering!
  65041. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65042. Path p;
  65043. p.addRectangle (x, y, width, lineThickness);
  65044. p.addRectangle (x, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  65045. p.addRectangle (x + width - lineThickness, y + lineThickness, lineThickness, height - lineThickness * 2.0f);
  65046. p.addRectangle (x, y + height - lineThickness, width, lineThickness);
  65047. fillPath (p);
  65048. }
  65049. void Graphics::drawRect (const Rectangle<int>& r,
  65050. const int lineThickness) const throw()
  65051. {
  65052. drawRect (r.getX(), r.getY(),
  65053. r.getWidth(), r.getHeight(),
  65054. lineThickness);
  65055. }
  65056. void Graphics::drawBevel (const int x,
  65057. const int y,
  65058. const int width,
  65059. const int height,
  65060. const int bevelThickness,
  65061. const Colour& topLeftColour,
  65062. const Colour& bottomRightColour,
  65063. const bool useGradient,
  65064. const bool sharpEdgeOnOutside) const throw()
  65065. {
  65066. // passing in a silly number can cause maths problems in rendering!
  65067. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65068. if (clipRegionIntersects (x, y, width, height))
  65069. {
  65070. context->saveState();
  65071. const float oldOpacity = 1.0f;//xxx state->colour.getFloatAlpha();
  65072. const float ramp = oldOpacity / bevelThickness;
  65073. for (int i = bevelThickness; --i >= 0;)
  65074. {
  65075. const float op = useGradient ? ramp * (sharpEdgeOnOutside ? bevelThickness - i : i)
  65076. : oldOpacity;
  65077. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op)));
  65078. context->fillRect (Rectangle<int> (x + i, y + i, width - i * 2, 1), false);
  65079. context->setFill (FillType (topLeftColour.withMultipliedAlpha (op * 0.75f)));
  65080. context->fillRect (Rectangle<int> (x + i, y + i + 1, 1, height - i * 2 - 2), false);
  65081. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op)));
  65082. context->fillRect (Rectangle<int> (x + i, y + height - i - 1, width - i * 2, 1), false);
  65083. context->setFill (FillType (bottomRightColour.withMultipliedAlpha (op * 0.75f)));
  65084. context->fillRect (Rectangle<int> (x + width - i - 1, y + i + 1, 1, height - i * 2 - 2), false);
  65085. }
  65086. context->restoreState();
  65087. }
  65088. }
  65089. void Graphics::fillEllipse (const float x,
  65090. const float y,
  65091. const float width,
  65092. const float height) const throw()
  65093. {
  65094. // passing in a silly number can cause maths problems in rendering!
  65095. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65096. Path p;
  65097. p.addEllipse (x, y, width, height);
  65098. fillPath (p);
  65099. }
  65100. void Graphics::drawEllipse (const float x,
  65101. const float y,
  65102. const float width,
  65103. const float height,
  65104. const float lineThickness) const throw()
  65105. {
  65106. // passing in a silly number can cause maths problems in rendering!
  65107. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65108. Path p;
  65109. p.addEllipse (x, y, width, height);
  65110. strokePath (p, PathStrokeType (lineThickness));
  65111. }
  65112. void Graphics::fillRoundedRectangle (const float x,
  65113. const float y,
  65114. const float width,
  65115. const float height,
  65116. const float cornerSize) const throw()
  65117. {
  65118. // passing in a silly number can cause maths problems in rendering!
  65119. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65120. Path p;
  65121. p.addRoundedRectangle (x, y, width, height, cornerSize);
  65122. fillPath (p);
  65123. }
  65124. void Graphics::fillRoundedRectangle (const Rectangle<int>& r,
  65125. const float cornerSize) const throw()
  65126. {
  65127. fillRoundedRectangle ((float) r.getX(),
  65128. (float) r.getY(),
  65129. (float) r.getWidth(),
  65130. (float) r.getHeight(),
  65131. cornerSize);
  65132. }
  65133. void Graphics::drawRoundedRectangle (const float x,
  65134. const float y,
  65135. const float width,
  65136. const float height,
  65137. const float cornerSize,
  65138. const float lineThickness) const throw()
  65139. {
  65140. // passing in a silly number can cause maths problems in rendering!
  65141. jassert (areCoordsSensibleNumbers (x, y, width, height));
  65142. Path p;
  65143. p.addRoundedRectangle (x, y, width, height, cornerSize);
  65144. strokePath (p, PathStrokeType (lineThickness));
  65145. }
  65146. void Graphics::drawRoundedRectangle (const Rectangle<int>& r,
  65147. const float cornerSize,
  65148. const float lineThickness) const throw()
  65149. {
  65150. drawRoundedRectangle ((float) r.getX(),
  65151. (float) r.getY(),
  65152. (float) r.getWidth(),
  65153. (float) r.getHeight(),
  65154. cornerSize, lineThickness);
  65155. }
  65156. void Graphics::drawArrow (const float startX,
  65157. const float startY,
  65158. const float endX,
  65159. const float endY,
  65160. const float lineThickness,
  65161. const float arrowheadWidth,
  65162. const float arrowheadLength) const throw()
  65163. {
  65164. Path p;
  65165. p.addArrow (startX, startY, endX, endY,
  65166. lineThickness, arrowheadWidth, arrowheadLength);
  65167. fillPath (p);
  65168. }
  65169. void Graphics::fillCheckerBoard (int x, int y,
  65170. int width, int height,
  65171. const int checkWidth,
  65172. const int checkHeight,
  65173. const Colour& colour1,
  65174. const Colour& colour2) const throw()
  65175. {
  65176. jassert (checkWidth > 0 && checkHeight > 0); // can't be zero or less!
  65177. if (checkWidth > 0 && checkHeight > 0)
  65178. {
  65179. context->saveState();
  65180. if (colour1 == colour2)
  65181. {
  65182. context->setFill (FillType (colour1));
  65183. context->fillRect (Rectangle<int> (x, y, width, height), false);
  65184. }
  65185. else
  65186. {
  65187. const Rectangle<int> clip (context->getClipBounds());
  65188. const int right = jmin (x + width, clip.getRight());
  65189. const int bottom = jmin (y + height, clip.getBottom());
  65190. int cy = 0;
  65191. while (y < bottom)
  65192. {
  65193. int cx = cy;
  65194. for (int xx = x; xx < right; xx += checkWidth)
  65195. {
  65196. context->setFill (FillType (((cx++ & 1) == 0) ? colour1 : colour2));
  65197. context->fillRect (Rectangle<int> (xx, y, jmin (checkWidth, right - xx), jmin (checkHeight, bottom - y)),
  65198. false);
  65199. }
  65200. ++cy;
  65201. y += checkHeight;
  65202. }
  65203. }
  65204. context->restoreState();
  65205. }
  65206. }
  65207. void Graphics::drawVerticalLine (const int x, float top, float bottom) const throw()
  65208. {
  65209. context->drawVerticalLine (x, top, bottom);
  65210. }
  65211. void Graphics::drawHorizontalLine (const int y, float left, float right) const throw()
  65212. {
  65213. context->drawHorizontalLine (y, left, right);
  65214. }
  65215. void Graphics::drawLine (float x1, float y1, float x2, float y2) const throw()
  65216. {
  65217. context->drawLine (x1, y1, x2, y2);
  65218. }
  65219. void Graphics::drawLine (const float startX,
  65220. const float startY,
  65221. const float endX,
  65222. const float endY,
  65223. const float lineThickness) const throw()
  65224. {
  65225. Path p;
  65226. p.addLineSegment (startX, startY, endX, endY, lineThickness);
  65227. fillPath (p);
  65228. }
  65229. void Graphics::drawLine (const Line& line) const throw()
  65230. {
  65231. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY());
  65232. }
  65233. void Graphics::drawLine (const Line& line,
  65234. const float lineThickness) const throw()
  65235. {
  65236. drawLine (line.getStartX(), line.getStartY(), line.getEndX(), line.getEndY(), lineThickness);
  65237. }
  65238. void Graphics::drawDashedLine (const float startX,
  65239. const float startY,
  65240. const float endX,
  65241. const float endY,
  65242. const float* const dashLengths,
  65243. const int numDashLengths,
  65244. const float lineThickness) const throw()
  65245. {
  65246. const double dx = endX - startX;
  65247. const double dy = endY - startY;
  65248. const double totalLen = juce_hypot (dx, dy);
  65249. if (totalLen >= 0.5)
  65250. {
  65251. const double onePixAlpha = 1.0 / totalLen;
  65252. double alpha = 0.0;
  65253. float x = startX;
  65254. float y = startY;
  65255. int n = 0;
  65256. while (alpha < 1.0f)
  65257. {
  65258. alpha = jmin (1.0, alpha + dashLengths[n++] * onePixAlpha);
  65259. n = n % numDashLengths;
  65260. const float oldX = x;
  65261. const float oldY = y;
  65262. x = (float) (startX + dx * alpha);
  65263. y = (float) (startY + dy * alpha);
  65264. if ((n & 1) != 0)
  65265. {
  65266. if (lineThickness != 1.0f)
  65267. drawLine (oldX, oldY, x, y, lineThickness);
  65268. else
  65269. drawLine (oldX, oldY, x, y);
  65270. }
  65271. }
  65272. }
  65273. }
  65274. void Graphics::setImageResamplingQuality (const Graphics::ResamplingQuality newQuality) throw()
  65275. {
  65276. saveStateIfPending();
  65277. context->setInterpolationQuality (newQuality);
  65278. }
  65279. void Graphics::drawImageAt (const Image* const imageToDraw,
  65280. const int topLeftX,
  65281. const int topLeftY,
  65282. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65283. {
  65284. if (imageToDraw != 0)
  65285. {
  65286. const int imageW = imageToDraw->getWidth();
  65287. const int imageH = imageToDraw->getHeight();
  65288. drawImage (imageToDraw,
  65289. topLeftX, topLeftY, imageW, imageH,
  65290. 0, 0, imageW, imageH,
  65291. fillAlphaChannelWithCurrentBrush);
  65292. }
  65293. }
  65294. void Graphics::drawImageWithin (const Image* const imageToDraw,
  65295. const int destX,
  65296. const int destY,
  65297. const int destW,
  65298. const int destH,
  65299. const RectanglePlacement& placementWithinTarget,
  65300. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65301. {
  65302. // passing in a silly number can cause maths problems in rendering!
  65303. jassert (areCoordsSensibleNumbers (destX, destY, destW, destH));
  65304. if (imageToDraw != 0)
  65305. {
  65306. const int imageW = imageToDraw->getWidth();
  65307. const int imageH = imageToDraw->getHeight();
  65308. if (imageW > 0 && imageH > 0)
  65309. {
  65310. double newX = 0.0, newY = 0.0;
  65311. double newW = imageW;
  65312. double newH = imageH;
  65313. placementWithinTarget.applyTo (newX, newY, newW, newH,
  65314. destX, destY, destW, destH);
  65315. if (newW > 0 && newH > 0)
  65316. {
  65317. drawImage (imageToDraw,
  65318. roundToInt (newX), roundToInt (newY),
  65319. roundToInt (newW), roundToInt (newH),
  65320. 0, 0, imageW, imageH,
  65321. fillAlphaChannelWithCurrentBrush);
  65322. }
  65323. }
  65324. }
  65325. }
  65326. void Graphics::drawImage (const Image* const imageToDraw,
  65327. int dx, int dy, int dw, int dh,
  65328. int sx, int sy, int sw, int sh,
  65329. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65330. {
  65331. // passing in a silly number can cause maths problems in rendering!
  65332. jassert (areCoordsSensibleNumbers (dx, dy, dw, dh));
  65333. jassert (areCoordsSensibleNumbers (sx, sy, sw, sh));
  65334. if (context->clipRegionIntersects (Rectangle<int> (dx, dy, dw, dh)))
  65335. {
  65336. drawImageTransformed (imageToDraw, Rectangle<int> (sx, sy, sw, sh),
  65337. AffineTransform::scale (dw / (float) sw, dh / (float) sh)
  65338. .translated ((float) dx, (float) dy),
  65339. fillAlphaChannelWithCurrentBrush);
  65340. }
  65341. }
  65342. void Graphics::drawImageTransformed (const Image* const imageToDraw,
  65343. const Rectangle<int>& imageSubRegion,
  65344. const AffineTransform& transform,
  65345. const bool fillAlphaChannelWithCurrentBrush) const throw()
  65346. {
  65347. if (imageToDraw != 0 && ! context->isClipEmpty())
  65348. {
  65349. const Rectangle<int> srcClip (imageSubRegion.getIntersection (imageToDraw->getBounds()));
  65350. if (fillAlphaChannelWithCurrentBrush)
  65351. {
  65352. context->saveState();
  65353. context->clipToImageAlpha (*imageToDraw, srcClip, transform);
  65354. fillAll();
  65355. context->restoreState();
  65356. }
  65357. else
  65358. {
  65359. context->drawImage (*imageToDraw, srcClip, transform, false);
  65360. }
  65361. }
  65362. }
  65363. END_JUCE_NAMESPACE
  65364. /*** End of inlined file: juce_Graphics.cpp ***/
  65365. /*** Start of inlined file: juce_Justification.cpp ***/
  65366. BEGIN_JUCE_NAMESPACE
  65367. Justification::Justification (const Justification& other) throw()
  65368. : flags (other.flags)
  65369. {
  65370. }
  65371. Justification& Justification::operator= (const Justification& other) throw()
  65372. {
  65373. flags = other.flags;
  65374. return *this;
  65375. }
  65376. int Justification::getOnlyVerticalFlags() const throw()
  65377. {
  65378. return flags & (top | bottom | verticallyCentred);
  65379. }
  65380. int Justification::getOnlyHorizontalFlags() const throw()
  65381. {
  65382. return flags & (left | right | horizontallyCentred | horizontallyJustified);
  65383. }
  65384. void Justification::applyToRectangle (int& x, int& y,
  65385. const int w, const int h,
  65386. const int spaceX, const int spaceY,
  65387. const int spaceW, const int spaceH) const throw()
  65388. {
  65389. if ((flags & horizontallyCentred) != 0)
  65390. {
  65391. x = spaceX + ((spaceW - w) >> 1);
  65392. }
  65393. else if ((flags & right) != 0)
  65394. {
  65395. x = spaceX + spaceW - w;
  65396. }
  65397. else
  65398. {
  65399. x = spaceX;
  65400. }
  65401. if ((flags & verticallyCentred) != 0)
  65402. {
  65403. y = spaceY + ((spaceH - h) >> 1);
  65404. }
  65405. else if ((flags & bottom) != 0)
  65406. {
  65407. y = spaceY + spaceH - h;
  65408. }
  65409. else
  65410. {
  65411. y = spaceY;
  65412. }
  65413. }
  65414. END_JUCE_NAMESPACE
  65415. /*** End of inlined file: juce_Justification.cpp ***/
  65416. /*** Start of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65417. BEGIN_JUCE_NAMESPACE
  65418. // this will throw an assertion if you try to draw something that's not
  65419. // possible in postscript
  65420. #define WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS 0
  65421. #if defined (JUCE_DEBUG) && WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS
  65422. #define notPossibleInPostscriptAssert jassertfalse
  65423. #else
  65424. #define notPossibleInPostscriptAssert
  65425. #endif
  65426. LowLevelGraphicsPostScriptRenderer::LowLevelGraphicsPostScriptRenderer (OutputStream& resultingPostScript,
  65427. const String& documentTitle,
  65428. const int totalWidth_,
  65429. const int totalHeight_)
  65430. : out (resultingPostScript),
  65431. totalWidth (totalWidth_),
  65432. totalHeight (totalHeight_),
  65433. needToClip (true)
  65434. {
  65435. stateStack.add (new SavedState());
  65436. stateStack.getLast()->clip = Rectangle<int> (0, 0, totalWidth_, totalHeight_);
  65437. const float scale = jmin ((520.0f / totalWidth_), (750.0f / totalHeight));
  65438. out << "%!PS-Adobe-3.0 EPSF-3.0"
  65439. "\n%%BoundingBox: 0 0 600 824"
  65440. "\n%%Pages: 0"
  65441. "\n%%Creator: Raw Material Software JUCE"
  65442. "\n%%Title: " << documentTitle <<
  65443. "\n%%CreationDate: none"
  65444. "\n%%LanguageLevel: 2"
  65445. "\n%%EndComments"
  65446. "\n%%BeginProlog"
  65447. "\n%%BeginResource: JRes"
  65448. "\n/bd {bind def} bind def"
  65449. "\n/c {setrgbcolor} bd"
  65450. "\n/m {moveto} bd"
  65451. "\n/l {lineto} bd"
  65452. "\n/rl {rlineto} bd"
  65453. "\n/ct {curveto} bd"
  65454. "\n/cp {closepath} bd"
  65455. "\n/pr {3 index 3 index moveto 1 index 0 rlineto 0 1 index rlineto pop neg 0 rlineto pop pop closepath} bd"
  65456. "\n/doclip {initclip newpath} bd"
  65457. "\n/endclip {clip newpath} bd"
  65458. "\n%%EndResource"
  65459. "\n%%EndProlog"
  65460. "\n%%BeginSetup"
  65461. "\n%%EndSetup"
  65462. "\n%%Page: 1 1"
  65463. "\n%%BeginPageSetup"
  65464. "\n%%EndPageSetup\n\n"
  65465. << "40 800 translate\n"
  65466. << scale << ' ' << scale << " scale\n\n";
  65467. }
  65468. LowLevelGraphicsPostScriptRenderer::~LowLevelGraphicsPostScriptRenderer()
  65469. {
  65470. }
  65471. bool LowLevelGraphicsPostScriptRenderer::isVectorDevice() const
  65472. {
  65473. return true;
  65474. }
  65475. void LowLevelGraphicsPostScriptRenderer::setOrigin (int x, int y)
  65476. {
  65477. if (x != 0 || y != 0)
  65478. {
  65479. stateStack.getLast()->xOffset += x;
  65480. stateStack.getLast()->yOffset += y;
  65481. needToClip = true;
  65482. }
  65483. }
  65484. bool LowLevelGraphicsPostScriptRenderer::clipToRectangle (const Rectangle<int>& r)
  65485. {
  65486. needToClip = true;
  65487. return stateStack.getLast()->clip.clipTo (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65488. }
  65489. bool LowLevelGraphicsPostScriptRenderer::clipToRectangleList (const RectangleList& clipRegion)
  65490. {
  65491. needToClip = true;
  65492. return stateStack.getLast()->clip.clipTo (clipRegion);
  65493. }
  65494. void LowLevelGraphicsPostScriptRenderer::excludeClipRectangle (const Rectangle<int>& r)
  65495. {
  65496. needToClip = true;
  65497. stateStack.getLast()->clip.subtract (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65498. }
  65499. void LowLevelGraphicsPostScriptRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  65500. {
  65501. writeClip();
  65502. Path p (path);
  65503. p.applyTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65504. writePath (p);
  65505. out << "clip\n";
  65506. }
  65507. void LowLevelGraphicsPostScriptRenderer::clipToImageAlpha (const Image& /*sourceImage*/, const Rectangle<int>& /*srcClip*/, const AffineTransform& /*transform*/)
  65508. {
  65509. needToClip = true;
  65510. jassertfalse // xxx
  65511. }
  65512. bool LowLevelGraphicsPostScriptRenderer::clipRegionIntersects (const Rectangle<int>& r)
  65513. {
  65514. return stateStack.getLast()->clip.intersectsRectangle (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65515. }
  65516. const Rectangle<int> LowLevelGraphicsPostScriptRenderer::getClipBounds() const
  65517. {
  65518. return stateStack.getLast()->clip.getBounds().translated (-stateStack.getLast()->xOffset,
  65519. -stateStack.getLast()->yOffset);
  65520. }
  65521. bool LowLevelGraphicsPostScriptRenderer::isClipEmpty() const
  65522. {
  65523. return stateStack.getLast()->clip.isEmpty();
  65524. }
  65525. LowLevelGraphicsPostScriptRenderer::SavedState::SavedState()
  65526. : xOffset (0),
  65527. yOffset (0)
  65528. {
  65529. }
  65530. LowLevelGraphicsPostScriptRenderer::SavedState::~SavedState()
  65531. {
  65532. }
  65533. void LowLevelGraphicsPostScriptRenderer::saveState()
  65534. {
  65535. stateStack.add (new SavedState (*stateStack.getLast()));
  65536. }
  65537. void LowLevelGraphicsPostScriptRenderer::restoreState()
  65538. {
  65539. jassert (stateStack.size() > 0);
  65540. if (stateStack.size() > 0)
  65541. stateStack.removeLast();
  65542. }
  65543. void LowLevelGraphicsPostScriptRenderer::writeClip()
  65544. {
  65545. if (needToClip)
  65546. {
  65547. needToClip = false;
  65548. out << "doclip ";
  65549. int itemsOnLine = 0;
  65550. for (RectangleList::Iterator i (stateStack.getLast()->clip); i.next();)
  65551. {
  65552. if (++itemsOnLine == 6)
  65553. {
  65554. itemsOnLine = 0;
  65555. out << '\n';
  65556. }
  65557. const Rectangle<int>& r = *i.getRectangle();
  65558. out << r.getX() << ' ' << -r.getY() << ' '
  65559. << r.getWidth() << ' ' << -r.getHeight() << " pr ";
  65560. }
  65561. out << "endclip\n";
  65562. }
  65563. }
  65564. void LowLevelGraphicsPostScriptRenderer::writeColour (const Colour& colour)
  65565. {
  65566. Colour c (Colours::white.overlaidWith (colour));
  65567. if (lastColour != c)
  65568. {
  65569. lastColour = c;
  65570. out << String (c.getFloatRed(), 3) << ' '
  65571. << String (c.getFloatGreen(), 3) << ' '
  65572. << String (c.getFloatBlue(), 3) << " c\n";
  65573. }
  65574. }
  65575. void LowLevelGraphicsPostScriptRenderer::writeXY (const float x, const float y) const
  65576. {
  65577. out << String (x, 2) << ' '
  65578. << String (-y, 2) << ' ';
  65579. }
  65580. void LowLevelGraphicsPostScriptRenderer::writePath (const Path& path) const
  65581. {
  65582. out << "newpath ";
  65583. float lastX = 0.0f;
  65584. float lastY = 0.0f;
  65585. int itemsOnLine = 0;
  65586. Path::Iterator i (path);
  65587. while (i.next())
  65588. {
  65589. if (++itemsOnLine == 4)
  65590. {
  65591. itemsOnLine = 0;
  65592. out << '\n';
  65593. }
  65594. switch (i.elementType)
  65595. {
  65596. case Path::Iterator::startNewSubPath:
  65597. writeXY (i.x1, i.y1);
  65598. lastX = i.x1;
  65599. lastY = i.y1;
  65600. out << "m ";
  65601. break;
  65602. case Path::Iterator::lineTo:
  65603. writeXY (i.x1, i.y1);
  65604. lastX = i.x1;
  65605. lastY = i.y1;
  65606. out << "l ";
  65607. break;
  65608. case Path::Iterator::quadraticTo:
  65609. {
  65610. const float cp1x = lastX + (i.x1 - lastX) * 2.0f / 3.0f;
  65611. const float cp1y = lastY + (i.y1 - lastY) * 2.0f / 3.0f;
  65612. const float cp2x = cp1x + (i.x2 - lastX) / 3.0f;
  65613. const float cp2y = cp1y + (i.y2 - lastY) / 3.0f;
  65614. writeXY (cp1x, cp1y);
  65615. writeXY (cp2x, cp2y);
  65616. writeXY (i.x2, i.y2);
  65617. out << "ct ";
  65618. lastX = i.x2;
  65619. lastY = i.y2;
  65620. }
  65621. break;
  65622. case Path::Iterator::cubicTo:
  65623. writeXY (i.x1, i.y1);
  65624. writeXY (i.x2, i.y2);
  65625. writeXY (i.x3, i.y3);
  65626. out << "ct ";
  65627. lastX = i.x3;
  65628. lastY = i.y3;
  65629. break;
  65630. case Path::Iterator::closePath:
  65631. out << "cp ";
  65632. break;
  65633. default:
  65634. jassertfalse
  65635. break;
  65636. }
  65637. }
  65638. out << '\n';
  65639. }
  65640. void LowLevelGraphicsPostScriptRenderer::writeTransform (const AffineTransform& trans) const
  65641. {
  65642. out << "[ "
  65643. << trans.mat00 << ' '
  65644. << trans.mat10 << ' '
  65645. << trans.mat01 << ' '
  65646. << trans.mat11 << ' '
  65647. << trans.mat02 << ' '
  65648. << trans.mat12 << " ] concat ";
  65649. }
  65650. void LowLevelGraphicsPostScriptRenderer::setFill (const FillType& fillType)
  65651. {
  65652. stateStack.getLast()->fillType = fillType;
  65653. }
  65654. void LowLevelGraphicsPostScriptRenderer::setOpacity (float /*opacity*/)
  65655. {
  65656. }
  65657. void LowLevelGraphicsPostScriptRenderer::setInterpolationQuality (Graphics::ResamplingQuality /*quality*/)
  65658. {
  65659. }
  65660. void LowLevelGraphicsPostScriptRenderer::fillRect (const Rectangle<int>& r, const bool /*replaceExistingContents*/)
  65661. {
  65662. if (stateStack.getLast()->fillType.isColour())
  65663. {
  65664. writeClip();
  65665. writeColour (stateStack.getLast()->fillType.colour);
  65666. Rectangle<int> r2 (r.translated (stateStack.getLast()->xOffset, stateStack.getLast()->yOffset));
  65667. out << r2.getX() << ' ' << -r2.getBottom() << ' ' << r2.getWidth() << ' ' << r2.getHeight() << " rectfill\n";
  65668. }
  65669. else
  65670. {
  65671. Path p;
  65672. p.addRectangle (r);
  65673. fillPath (p, AffineTransform::identity);
  65674. }
  65675. }
  65676. void LowLevelGraphicsPostScriptRenderer::fillPath (const Path& path, const AffineTransform& t)
  65677. {
  65678. if (stateStack.getLast()->fillType.isColour())
  65679. {
  65680. writeClip();
  65681. Path p (path);
  65682. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset,
  65683. (float) stateStack.getLast()->yOffset));
  65684. writePath (p);
  65685. writeColour (stateStack.getLast()->fillType.colour);
  65686. out << "fill\n";
  65687. }
  65688. else if (stateStack.getLast()->fillType.isGradient())
  65689. {
  65690. // this doesn't work correctly yet - it could be improved to handle solid gradients, but
  65691. // postscript can't do semi-transparent ones.
  65692. notPossibleInPostscriptAssert // you can disable this warning by setting the WARN_ABOUT_NON_POSTSCRIPT_OPERATIONS flag at the top of this file
  65693. writeClip();
  65694. out << "gsave ";
  65695. {
  65696. Path p (path);
  65697. p.applyTransform (t.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset));
  65698. writePath (p);
  65699. out << "clip\n";
  65700. }
  65701. const Rectangle<int> bounds (stateStack.getLast()->clip.getBounds());
  65702. // ideally this would draw lots of lines or ellipses to approximate the gradient, but for the
  65703. // time-being, this just fills it with the average colour..
  65704. writeColour (stateStack.getLast()->fillType.gradient->getColourAtPosition (0.5f));
  65705. out << bounds.getX() << ' ' << -bounds.getBottom() << ' ' << bounds.getWidth() << ' ' << bounds.getHeight() << " rectfill\n";
  65706. out << "grestore\n";
  65707. }
  65708. }
  65709. void LowLevelGraphicsPostScriptRenderer::writeImage (const Image& im,
  65710. const int sx, const int sy,
  65711. const int maxW, const int maxH) const
  65712. {
  65713. out << "{<\n";
  65714. const int w = jmin (maxW, im.getWidth());
  65715. const int h = jmin (maxH, im.getHeight());
  65716. int charsOnLine = 0;
  65717. const Image::BitmapData srcData (im, 0, 0, w, h);
  65718. Colour pixel;
  65719. for (int y = h; --y >= 0;)
  65720. {
  65721. for (int x = 0; x < w; ++x)
  65722. {
  65723. const uint8* pixelData = srcData.getPixelPointer (x, y);
  65724. if (x >= sx && y >= sy)
  65725. {
  65726. if (im.isARGB())
  65727. {
  65728. PixelARGB p (*(const PixelARGB*) pixelData);
  65729. p.unpremultiply();
  65730. pixel = Colours::white.overlaidWith (Colour (p.getARGB()));
  65731. }
  65732. else if (im.isRGB())
  65733. {
  65734. pixel = Colour (((const PixelRGB*) pixelData)->getARGB());
  65735. }
  65736. else
  65737. {
  65738. pixel = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *pixelData);
  65739. }
  65740. }
  65741. else
  65742. {
  65743. pixel = Colours::transparentWhite;
  65744. }
  65745. const uint8 pixelValues[3] = { pixel.getRed(), pixel.getGreen(), pixel.getBlue() };
  65746. out << String::toHexString (pixelValues, 3, 0);
  65747. charsOnLine += 3;
  65748. if (charsOnLine > 100)
  65749. {
  65750. out << '\n';
  65751. charsOnLine = 0;
  65752. }
  65753. }
  65754. }
  65755. out << "\n>}\n";
  65756. }
  65757. void LowLevelGraphicsPostScriptRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  65758. const AffineTransform& transform, const bool /*fillEntireClipAsTiles*/)
  65759. {
  65760. const int w = jmin (sourceImage.getWidth(), srcClip.getRight());
  65761. const int h = jmin (sourceImage.getHeight(), srcClip.getBottom());
  65762. writeClip();
  65763. out << "gsave ";
  65764. writeTransform (transform.translated ((float) stateStack.getLast()->xOffset, (float) stateStack.getLast()->yOffset)
  65765. .scaled (1.0f, -1.0f));
  65766. RectangleList imageClip;
  65767. sourceImage.createSolidAreaMask (imageClip, 0.5f);
  65768. imageClip.clipTo (srcClip);
  65769. out << "newpath ";
  65770. int itemsOnLine = 0;
  65771. for (RectangleList::Iterator i (imageClip); i.next();)
  65772. {
  65773. if (++itemsOnLine == 6)
  65774. {
  65775. out << '\n';
  65776. itemsOnLine = 0;
  65777. }
  65778. const Rectangle<int>& r = *i.getRectangle();
  65779. out << r.getX() << ' ' << r.getY() << ' ' << r.getWidth() << ' ' << r.getHeight() << " pr ";
  65780. }
  65781. out << " clip newpath\n";
  65782. out << w << ' ' << h << " scale\n";
  65783. out << w << ' ' << h << " 8 [" << w << " 0 0 -" << h << ' ' << (int) 0 << ' ' << h << " ]\n";
  65784. writeImage (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  65785. out << "false 3 colorimage grestore\n";
  65786. needToClip = true;
  65787. }
  65788. void LowLevelGraphicsPostScriptRenderer::drawLine (double x1, double y1, double x2, double y2)
  65789. {
  65790. Path p;
  65791. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  65792. fillPath (p, AffineTransform::identity);
  65793. }
  65794. void LowLevelGraphicsPostScriptRenderer::drawVerticalLine (const int x, double top, double bottom)
  65795. {
  65796. drawLine (x, top, x, bottom);
  65797. }
  65798. void LowLevelGraphicsPostScriptRenderer::drawHorizontalLine (const int y, double left, double right)
  65799. {
  65800. drawLine (left, y, right, y);
  65801. }
  65802. void LowLevelGraphicsPostScriptRenderer::setFont (const Font& newFont)
  65803. {
  65804. stateStack.getLast()->font = newFont;
  65805. }
  65806. const Font LowLevelGraphicsPostScriptRenderer::getFont()
  65807. {
  65808. return stateStack.getLast()->font;
  65809. }
  65810. void LowLevelGraphicsPostScriptRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  65811. {
  65812. Path p;
  65813. Font& font = stateStack.getLast()->font;
  65814. font.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  65815. fillPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight()).followedBy (transform));
  65816. }
  65817. END_JUCE_NAMESPACE
  65818. /*** End of inlined file: juce_LowLevelGraphicsPostScriptRenderer.cpp ***/
  65819. /*** Start of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  65820. BEGIN_JUCE_NAMESPACE
  65821. #if (JUCE_WINDOWS || JUCE_LINUX) && ! JUCE_64BIT
  65822. #define JUCE_USE_SSE_INSTRUCTIONS 1
  65823. #endif
  65824. #if JUCE_MSVC && JUCE_DEBUG
  65825. #pragma warning (disable: 4714) // warning about forcedinline methods not being inlined
  65826. #endif
  65827. #if JUCE_MSVC
  65828. #pragma warning (push)
  65829. #pragma warning (disable: 4127) // "expression is constant" warning
  65830. #endif
  65831. template <class PixelType, bool replaceExisting = false>
  65832. class SolidColourEdgeTableRenderer
  65833. {
  65834. public:
  65835. SolidColourEdgeTableRenderer (const Image::BitmapData& data_, const PixelARGB& colour) throw()
  65836. : data (data_),
  65837. sourceColour (colour)
  65838. {
  65839. if (sizeof (PixelType) == 3)
  65840. {
  65841. areRGBComponentsEqual = sourceColour.getRed() == sourceColour.getGreen()
  65842. && sourceColour.getGreen() == sourceColour.getBlue();
  65843. filler[0].set (sourceColour);
  65844. filler[1].set (sourceColour);
  65845. filler[2].set (sourceColour);
  65846. filler[3].set (sourceColour);
  65847. }
  65848. }
  65849. forcedinline void setEdgeTableYPos (const int y) throw()
  65850. {
  65851. linePixels = (PixelType*) data.getLinePointer (y);
  65852. }
  65853. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  65854. {
  65855. if (replaceExisting)
  65856. linePixels[x].set (sourceColour);
  65857. else
  65858. linePixels[x].blend (sourceColour, alphaLevel);
  65859. }
  65860. forcedinline void handleEdgeTableLine (const int x, int width, const int alphaLevel) const throw()
  65861. {
  65862. PixelARGB p (sourceColour);
  65863. p.multiplyAlpha (alphaLevel);
  65864. PixelType* dest = linePixels + x;
  65865. if (replaceExisting || p.getAlpha() >= 0xff)
  65866. replaceLine (dest, p, width);
  65867. else
  65868. blendLine (dest, p, width);
  65869. }
  65870. private:
  65871. const Image::BitmapData& data;
  65872. PixelType* linePixels;
  65873. PixelARGB sourceColour;
  65874. PixelRGB filler [4];
  65875. bool areRGBComponentsEqual;
  65876. inline void blendLine (PixelType* dest, const PixelARGB& colour, int width) const
  65877. {
  65878. do
  65879. {
  65880. dest->blend (colour);
  65881. ++dest;
  65882. } while (--width > 0);
  65883. }
  65884. forcedinline void replaceLine (PixelRGB* dest, const PixelARGB& colour, int width) const throw()
  65885. {
  65886. if (areRGBComponentsEqual) // if all the component values are the same, we can cheat..
  65887. {
  65888. memset (dest, colour.getRed(), width * 3);
  65889. }
  65890. else
  65891. {
  65892. if (width >> 5)
  65893. {
  65894. const int* const intFiller = (const int*) filler;
  65895. while (width > 8 && (((pointer_sized_int) dest) & 7) != 0)
  65896. {
  65897. dest->set (colour);
  65898. ++dest;
  65899. --width;
  65900. }
  65901. while (width > 4)
  65902. {
  65903. ((int*) dest) [0] = intFiller[0];
  65904. ((int*) dest) [1] = intFiller[1];
  65905. ((int*) dest) [2] = intFiller[2];
  65906. dest = (PixelRGB*) (((uint8*) dest) + 12);
  65907. width -= 4;
  65908. }
  65909. }
  65910. while (--width >= 0)
  65911. {
  65912. dest->set (colour);
  65913. ++dest;
  65914. }
  65915. }
  65916. }
  65917. forcedinline void replaceLine (PixelAlpha* dest, const PixelARGB& colour, int width) const throw()
  65918. {
  65919. memset (dest, colour.getAlpha(), width);
  65920. }
  65921. forcedinline void replaceLine (PixelARGB* dest, const PixelARGB& colour, int width) const throw()
  65922. {
  65923. do
  65924. {
  65925. dest->set (colour);
  65926. ++dest;
  65927. } while (--width > 0);
  65928. }
  65929. SolidColourEdgeTableRenderer (const SolidColourEdgeTableRenderer&);
  65930. SolidColourEdgeTableRenderer& operator= (const SolidColourEdgeTableRenderer&);
  65931. };
  65932. class LinearGradientPixelGenerator
  65933. {
  65934. public:
  65935. LinearGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform, const PixelARGB* const lookupTable_, const int numEntries_)
  65936. : lookupTable (lookupTable_), numEntries (numEntries_)
  65937. {
  65938. jassert (numEntries_ >= 0);
  65939. float x1 = gradient.x1;
  65940. float y1 = gradient.y1;
  65941. float x2 = gradient.x2;
  65942. float y2 = gradient.y2;
  65943. if (! transform.isIdentity())
  65944. {
  65945. const Line l (x2, y2, x1, y1);
  65946. const Point<float> p3 = l.getPointAlongLine (0.0f, 100.0f);
  65947. float x3 = p3.getX();
  65948. float y3 = p3.getY();
  65949. transform.transformPoint (x1, y1);
  65950. transform.transformPoint (x2, y2);
  65951. transform.transformPoint (x3, y3);
  65952. const Line l2 (x2, y2, x3, y3);
  65953. const float prop = l2.findNearestPointTo (x1, y1);
  65954. const Point<float> newP2 (l2.getPointAlongLineProportionally (prop));
  65955. x2 = newP2.getX();
  65956. y2 = newP2.getY();
  65957. }
  65958. vertical = fabs (x1 - x2) < 0.001f;
  65959. horizontal = fabs (y1 - y2) < 0.001f;
  65960. if (vertical)
  65961. {
  65962. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (y2 - y1));
  65963. start = roundToInt (y1 * scale);
  65964. }
  65965. else if (horizontal)
  65966. {
  65967. scale = roundToInt ((numEntries << (int) numScaleBits) / (double) (x2 - x1));
  65968. start = roundToInt (x1 * scale);
  65969. }
  65970. else
  65971. {
  65972. grad = (y2 - y1) / (double) (x1 - x2);
  65973. yTerm = y1 - x1 / grad;
  65974. scale = roundToInt ((numEntries << (int) numScaleBits) / (yTerm * grad - (y2 * grad - x2)));
  65975. grad *= scale;
  65976. }
  65977. }
  65978. forcedinline void setY (const int y) throw()
  65979. {
  65980. if (vertical)
  65981. linePix = lookupTable [jlimit (0, numEntries, (y * scale - start) >> (int) numScaleBits)];
  65982. else if (! horizontal)
  65983. start = roundToInt ((y - yTerm) * grad);
  65984. }
  65985. forcedinline const PixelARGB getPixel (const int x) const throw()
  65986. {
  65987. return vertical ? linePix
  65988. : lookupTable [jlimit (0, numEntries, (x * scale - start) >> (int) numScaleBits)];
  65989. }
  65990. private:
  65991. const PixelARGB* const lookupTable;
  65992. const int numEntries;
  65993. PixelARGB linePix;
  65994. int start, scale;
  65995. double grad, yTerm;
  65996. bool vertical, horizontal;
  65997. enum { numScaleBits = 12 };
  65998. LinearGradientPixelGenerator (const LinearGradientPixelGenerator&);
  65999. LinearGradientPixelGenerator& operator= (const LinearGradientPixelGenerator&);
  66000. };
  66001. class RadialGradientPixelGenerator
  66002. {
  66003. public:
  66004. RadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform&,
  66005. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66006. : lookupTable (lookupTable_),
  66007. numEntries (numEntries_),
  66008. gx1 (gradient.x1),
  66009. gy1 (gradient.y1)
  66010. {
  66011. jassert (numEntries_ >= 0);
  66012. const float gdx = gradient.x1 - gradient.x2;
  66013. const float gdy = gradient.y1 - gradient.y2;
  66014. maxDist = gdx * gdx + gdy * gdy;
  66015. invScale = numEntries / sqrt (maxDist);
  66016. jassert (roundToInt (sqrt (maxDist) * invScale) <= numEntries);
  66017. }
  66018. forcedinline void setY (const int y) throw()
  66019. {
  66020. dy = y - gy1;
  66021. dy *= dy;
  66022. }
  66023. forcedinline const PixelARGB getPixel (const int px) const throw()
  66024. {
  66025. double x = px - gx1;
  66026. x *= x;
  66027. x += dy;
  66028. return lookupTable [x >= maxDist ? numEntries : roundToInt (sqrt (x) * invScale)];
  66029. }
  66030. protected:
  66031. const PixelARGB* const lookupTable;
  66032. const int numEntries;
  66033. const double gx1, gy1;
  66034. double maxDist, invScale, dy;
  66035. RadialGradientPixelGenerator (const RadialGradientPixelGenerator&);
  66036. RadialGradientPixelGenerator& operator= (const RadialGradientPixelGenerator&);
  66037. };
  66038. class TransformedRadialGradientPixelGenerator : public RadialGradientPixelGenerator
  66039. {
  66040. public:
  66041. TransformedRadialGradientPixelGenerator (const ColourGradient& gradient, const AffineTransform& transform,
  66042. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66043. : RadialGradientPixelGenerator (gradient, transform, lookupTable_, numEntries_),
  66044. inverseTransform (transform.inverted())
  66045. {
  66046. tM10 = inverseTransform.mat10;
  66047. tM00 = inverseTransform.mat00;
  66048. }
  66049. forcedinline void setY (const int y) throw()
  66050. {
  66051. lineYM01 = inverseTransform.mat01 * y + inverseTransform.mat02 - gx1;
  66052. lineYM11 = inverseTransform.mat11 * y + inverseTransform.mat12 - gy1;
  66053. }
  66054. forcedinline const PixelARGB getPixel (const int px) const throw()
  66055. {
  66056. double x = px;
  66057. const double y = tM10 * x + lineYM11;
  66058. x = tM00 * x + lineYM01;
  66059. x *= x;
  66060. x += y * y;
  66061. if (x >= maxDist)
  66062. return lookupTable [numEntries];
  66063. else
  66064. return lookupTable [jmin (numEntries, roundToInt (sqrt (x) * invScale))];
  66065. }
  66066. private:
  66067. double tM10, tM00, lineYM01, lineYM11;
  66068. const AffineTransform inverseTransform;
  66069. TransformedRadialGradientPixelGenerator (const TransformedRadialGradientPixelGenerator&);
  66070. TransformedRadialGradientPixelGenerator& operator= (const TransformedRadialGradientPixelGenerator&);
  66071. };
  66072. template <class PixelType, class GradientType>
  66073. class GradientEdgeTableRenderer : public GradientType
  66074. {
  66075. public:
  66076. GradientEdgeTableRenderer (const Image::BitmapData& destData_, const ColourGradient& gradient, const AffineTransform& transform,
  66077. const PixelARGB* const lookupTable_, const int numEntries_) throw()
  66078. : GradientType (gradient, transform, lookupTable_, numEntries_ - 1),
  66079. destData (destData_)
  66080. {
  66081. }
  66082. forcedinline void setEdgeTableYPos (const int y) throw()
  66083. {
  66084. linePixels = (PixelType*) destData.getLinePointer (y);
  66085. GradientType::setY (y);
  66086. }
  66087. forcedinline void handleEdgeTablePixel (const int x, const int alphaLevel) const throw()
  66088. {
  66089. linePixels[x].blend (GradientType::getPixel (x), alphaLevel);
  66090. }
  66091. forcedinline void handleEdgeTableLine (int x, int width, const int alphaLevel) const throw()
  66092. {
  66093. PixelType* dest = linePixels + x;
  66094. if (alphaLevel < 0xff)
  66095. {
  66096. do
  66097. {
  66098. (dest++)->blend (GradientType::getPixel (x++), alphaLevel);
  66099. } while (--width > 0);
  66100. }
  66101. else
  66102. {
  66103. do
  66104. {
  66105. (dest++)->blend (GradientType::getPixel (x++));
  66106. } while (--width > 0);
  66107. }
  66108. }
  66109. private:
  66110. const Image::BitmapData& destData;
  66111. PixelType* linePixels;
  66112. GradientEdgeTableRenderer (const GradientEdgeTableRenderer&);
  66113. GradientEdgeTableRenderer& operator= (const GradientEdgeTableRenderer&);
  66114. };
  66115. static forcedinline int safeModulo (int n, const int divisor) throw()
  66116. {
  66117. jassert (divisor > 0);
  66118. n %= divisor;
  66119. return (n < 0) ? (n + divisor) : n;
  66120. }
  66121. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  66122. class ImageFillEdgeTableRenderer
  66123. {
  66124. public:
  66125. ImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  66126. const Image::BitmapData& srcData_,
  66127. const int extraAlpha_,
  66128. const int x, const int y) throw()
  66129. : destData (destData_),
  66130. srcData (srcData_),
  66131. extraAlpha (extraAlpha_ + 1),
  66132. xOffset (repeatPattern ? safeModulo (x, srcData_.width) - srcData_.width : x),
  66133. yOffset (repeatPattern ? safeModulo (y, srcData_.height) - srcData_.height : y)
  66134. {
  66135. }
  66136. forcedinline void setEdgeTableYPos (int y) throw()
  66137. {
  66138. linePixels = (DestPixelType*) destData.getLinePointer (y);
  66139. y -= yOffset;
  66140. if (repeatPattern)
  66141. {
  66142. jassert (y >= 0);
  66143. y %= srcData.height;
  66144. }
  66145. sourceLineStart = (SrcPixelType*) srcData.getLinePointer (y);
  66146. }
  66147. forcedinline void handleEdgeTablePixel (int x, int alphaLevel) const throw()
  66148. {
  66149. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  66150. linePixels[x].blend (sourceLineStart [repeatPattern ? ((x - xOffset) % srcData.width) : (x - xOffset)], alphaLevel);
  66151. }
  66152. forcedinline void handleEdgeTableLine (int x, int width, int alphaLevel) const throw()
  66153. {
  66154. DestPixelType* dest = linePixels + x;
  66155. alphaLevel = (alphaLevel * extraAlpha) >> 8;
  66156. x -= xOffset;
  66157. jassert (repeatPattern || (x >= 0 && x + width <= srcData.width));
  66158. if (alphaLevel < 0xfe)
  66159. {
  66160. do
  66161. {
  66162. dest++ ->blend (sourceLineStart [repeatPattern ? (x++ % srcData.width) : x++], alphaLevel);
  66163. } while (--width > 0);
  66164. }
  66165. else
  66166. {
  66167. if (repeatPattern)
  66168. {
  66169. do
  66170. {
  66171. dest++ ->blend (sourceLineStart [x++ % srcData.width]);
  66172. } while (--width > 0);
  66173. }
  66174. else
  66175. {
  66176. copyRow (dest, sourceLineStart + x, width);
  66177. }
  66178. }
  66179. }
  66180. void clipEdgeTableLine (EdgeTable& et, int x, int y, int width) throw()
  66181. {
  66182. jassert (x - xOffset >= 0 && x + width - xOffset <= srcData.width);
  66183. SrcPixelType* s = (SrcPixelType*) srcData.getLinePointer (y - yOffset);
  66184. uint8* mask = (uint8*) (s + x - xOffset);
  66185. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  66186. mask += PixelARGB::indexA;
  66187. et.clipLineToMask (x, y, mask, sizeof (SrcPixelType), width);
  66188. }
  66189. private:
  66190. const Image::BitmapData& destData;
  66191. const Image::BitmapData& srcData;
  66192. const int extraAlpha, xOffset, yOffset;
  66193. DestPixelType* linePixels;
  66194. SrcPixelType* sourceLineStart;
  66195. template <class PixelType1, class PixelType2>
  66196. forcedinline static void copyRow (PixelType1* dest, PixelType2* src, int width) throw()
  66197. {
  66198. do
  66199. {
  66200. dest++ ->blend (*src++);
  66201. } while (--width > 0);
  66202. }
  66203. forcedinline static void copyRow (PixelRGB* dest, PixelRGB* src, int width) throw()
  66204. {
  66205. memcpy (dest, src, width * sizeof (PixelRGB));
  66206. }
  66207. ImageFillEdgeTableRenderer (const ImageFillEdgeTableRenderer&);
  66208. ImageFillEdgeTableRenderer& operator= (const ImageFillEdgeTableRenderer&);
  66209. };
  66210. template <class DestPixelType, class SrcPixelType, bool repeatPattern>
  66211. class TransformedImageFillEdgeTableRenderer
  66212. {
  66213. public:
  66214. TransformedImageFillEdgeTableRenderer (const Image::BitmapData& destData_,
  66215. const Image::BitmapData& srcData_,
  66216. const AffineTransform& transform,
  66217. const int extraAlpha_,
  66218. const bool betterQuality_) throw()
  66219. : interpolator (transform),
  66220. destData (destData_),
  66221. srcData (srcData_),
  66222. extraAlpha (extraAlpha_ + 1),
  66223. betterQuality (betterQuality_),
  66224. pixelOffset (betterQuality_ ? 0.5f : 0.0f),
  66225. pixelOffsetInt (betterQuality_ ? -128 : 0),
  66226. maxX (srcData_.width - 1),
  66227. maxY (srcData_.height - 1),
  66228. scratchSize (2048)
  66229. {
  66230. scratchBuffer.malloc (scratchSize);
  66231. }
  66232. ~TransformedImageFillEdgeTableRenderer() throw()
  66233. {
  66234. }
  66235. forcedinline void setEdgeTableYPos (const int newY) throw()
  66236. {
  66237. y = newY;
  66238. linePixels = (DestPixelType*) destData.getLinePointer (newY);
  66239. }
  66240. forcedinline void handleEdgeTablePixel (const int x, int alphaLevel) throw()
  66241. {
  66242. alphaLevel *= extraAlpha;
  66243. alphaLevel >>= 8;
  66244. SrcPixelType p;
  66245. generate (&p, x, 1);
  66246. linePixels[x].blend (p, alphaLevel);
  66247. }
  66248. forcedinline void handleEdgeTableLine (const int x, int width, int alphaLevel) throw()
  66249. {
  66250. if (width > scratchSize)
  66251. {
  66252. scratchSize = width;
  66253. scratchBuffer.malloc (scratchSize);
  66254. }
  66255. SrcPixelType* span = scratchBuffer;
  66256. generate (span, x, width);
  66257. DestPixelType* dest = linePixels + x;
  66258. alphaLevel *= extraAlpha;
  66259. alphaLevel >>= 8;
  66260. if (alphaLevel < 0xfe)
  66261. {
  66262. do
  66263. {
  66264. dest++ ->blend (*span++, alphaLevel);
  66265. } while (--width > 0);
  66266. }
  66267. else
  66268. {
  66269. do
  66270. {
  66271. dest++ ->blend (*span++);
  66272. } while (--width > 0);
  66273. }
  66274. }
  66275. void clipEdgeTableLine (EdgeTable& et, int x, int y_, int width) throw()
  66276. {
  66277. if (width > scratchSize)
  66278. {
  66279. scratchSize = width;
  66280. scratchBuffer.malloc (scratchSize);
  66281. }
  66282. uint8* mask = (uint8*) scratchBuffer;
  66283. y = y_;
  66284. generate ((SrcPixelType*) mask, x, width);
  66285. if (sizeof (SrcPixelType) == sizeof (PixelARGB))
  66286. mask += PixelARGB::indexA;
  66287. et.clipLineToMask (x, y_, mask, sizeof (SrcPixelType), width);
  66288. }
  66289. private:
  66290. void generate (PixelARGB* dest, const int x, int numPixels) throw()
  66291. {
  66292. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66293. do
  66294. {
  66295. int hiResX, hiResY;
  66296. this->interpolator.next (hiResX, hiResY);
  66297. hiResX += pixelOffsetInt;
  66298. hiResY += pixelOffsetInt;
  66299. int loResX = hiResX >> 8;
  66300. int loResY = hiResY >> 8;
  66301. if (repeatPattern)
  66302. {
  66303. loResX = safeModulo (loResX, srcData.width);
  66304. loResY = safeModulo (loResY, srcData.height);
  66305. }
  66306. if (betterQuality
  66307. && ((unsigned int) loResX) < (unsigned int) maxX
  66308. && ((unsigned int) loResY) < (unsigned int) maxY)
  66309. {
  66310. uint32 c[4] = { 256 * 128, 256 * 128, 256 * 128, 256 * 128 };
  66311. hiResX &= 255;
  66312. hiResY &= 255;
  66313. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66314. uint32 weight = (256 - hiResX) * (256 - hiResY);
  66315. c[0] += weight * src[0];
  66316. c[1] += weight * src[1];
  66317. c[2] += weight * src[2];
  66318. c[3] += weight * src[3];
  66319. weight = hiResX * (256 - hiResY);
  66320. c[0] += weight * src[4];
  66321. c[1] += weight * src[5];
  66322. c[2] += weight * src[6];
  66323. c[3] += weight * src[7];
  66324. src += this->srcData.lineStride;
  66325. weight = (256 - hiResX) * hiResY;
  66326. c[0] += weight * src[0];
  66327. c[1] += weight * src[1];
  66328. c[2] += weight * src[2];
  66329. c[3] += weight * src[3];
  66330. weight = hiResX * hiResY;
  66331. c[0] += weight * src[4];
  66332. c[1] += weight * src[5];
  66333. c[2] += weight * src[6];
  66334. c[3] += weight * src[7];
  66335. dest->setARGB ((uint8) (c[PixelARGB::indexA] >> 16),
  66336. (uint8) (c[PixelARGB::indexR] >> 16),
  66337. (uint8) (c[PixelARGB::indexG] >> 16),
  66338. (uint8) (c[PixelARGB::indexB] >> 16));
  66339. }
  66340. else
  66341. {
  66342. if (! repeatPattern)
  66343. {
  66344. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66345. if (loResX < 0) loResX = 0;
  66346. if (loResY < 0) loResY = 0;
  66347. if (loResX > maxX) loResX = maxX;
  66348. if (loResY > maxY) loResY = maxY;
  66349. }
  66350. dest->set (*(const PixelARGB*) this->srcData.getPixelPointer (loResX, loResY));
  66351. }
  66352. ++dest;
  66353. } while (--numPixels > 0);
  66354. }
  66355. void generate (PixelRGB* dest, const int x, int numPixels) throw()
  66356. {
  66357. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66358. do
  66359. {
  66360. int hiResX, hiResY;
  66361. this->interpolator.next (hiResX, hiResY);
  66362. hiResX += pixelOffsetInt;
  66363. hiResY += pixelOffsetInt;
  66364. int loResX = hiResX >> 8;
  66365. int loResY = hiResY >> 8;
  66366. if (repeatPattern)
  66367. {
  66368. loResX = safeModulo (loResX, srcData.width);
  66369. loResY = safeModulo (loResY, srcData.height);
  66370. }
  66371. if (betterQuality
  66372. && ((unsigned int) loResX) < (unsigned int) maxX
  66373. && ((unsigned int) loResY) < (unsigned int) maxY)
  66374. {
  66375. uint32 c[3] = { 256 * 128, 256 * 128, 256 * 128 };
  66376. hiResX &= 255;
  66377. hiResY &= 255;
  66378. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66379. unsigned int weight = (256 - hiResX) * (256 - hiResY);
  66380. c[0] += weight * src[0];
  66381. c[1] += weight * src[1];
  66382. c[2] += weight * src[2];
  66383. weight = hiResX * (256 - hiResY);
  66384. c[0] += weight * src[3];
  66385. c[1] += weight * src[4];
  66386. c[2] += weight * src[5];
  66387. src += this->srcData.lineStride;
  66388. weight = (256 - hiResX) * hiResY;
  66389. c[0] += weight * src[0];
  66390. c[1] += weight * src[1];
  66391. c[2] += weight * src[2];
  66392. weight = hiResX * hiResY;
  66393. c[0] += weight * src[3];
  66394. c[1] += weight * src[4];
  66395. c[2] += weight * src[5];
  66396. dest->setARGB ((uint8) 255,
  66397. (uint8) (c[PixelRGB::indexR] >> 16),
  66398. (uint8) (c[PixelRGB::indexG] >> 16),
  66399. (uint8) (c[PixelRGB::indexB] >> 16));
  66400. }
  66401. else
  66402. {
  66403. if (! repeatPattern)
  66404. {
  66405. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66406. if (loResX < 0) loResX = 0;
  66407. if (loResY < 0) loResY = 0;
  66408. if (loResX > maxX) loResX = maxX;
  66409. if (loResY > maxY) loResY = maxY;
  66410. }
  66411. dest->set (*(const PixelRGB*) this->srcData.getPixelPointer (loResX, loResY));
  66412. }
  66413. ++dest;
  66414. } while (--numPixels > 0);
  66415. }
  66416. void generate (PixelAlpha* dest, const int x, int numPixels) throw()
  66417. {
  66418. this->interpolator.setStartOfLine (x + pixelOffset, y + pixelOffset, numPixels);
  66419. do
  66420. {
  66421. int hiResX, hiResY;
  66422. this->interpolator.next (hiResX, hiResY);
  66423. hiResX += pixelOffsetInt;
  66424. hiResY += pixelOffsetInt;
  66425. int loResX = hiResX >> 8;
  66426. int loResY = hiResY >> 8;
  66427. if (repeatPattern)
  66428. {
  66429. loResX = safeModulo (loResX, srcData.width);
  66430. loResY = safeModulo (loResY, srcData.height);
  66431. }
  66432. if (betterQuality
  66433. && ((unsigned int) loResX) < (unsigned int) maxX
  66434. && ((unsigned int) loResY) < (unsigned int) maxY)
  66435. {
  66436. hiResX &= 255;
  66437. hiResY &= 255;
  66438. const uint8* src = this->srcData.getPixelPointer (loResX, loResY);
  66439. uint32 c = 256 * 128;
  66440. c += src[0] * ((256 - hiResX) * (256 - hiResY));
  66441. c += src[1] * (hiResX * (256 - hiResY));
  66442. src += this->srcData.lineStride;
  66443. c += src[0] * ((256 - hiResX) * hiResY);
  66444. c += src[1] * (hiResX * hiResY);
  66445. *((uint8*) dest) = (uint8) c;
  66446. }
  66447. else
  66448. {
  66449. if (! repeatPattern)
  66450. {
  66451. // Beyond the edges, just repeat the edge pixels and leave the anti-aliasing to be handled by the edgetable
  66452. if (loResX < 0) loResX = 0;
  66453. if (loResY < 0) loResY = 0;
  66454. if (loResX > maxX) loResX = maxX;
  66455. if (loResY > maxY) loResY = maxY;
  66456. }
  66457. *((uint8*) dest) = *(this->srcData.getPixelPointer (loResX, loResY));
  66458. }
  66459. ++dest;
  66460. } while (--numPixels > 0);
  66461. }
  66462. class TransformedImageSpanInterpolator
  66463. {
  66464. public:
  66465. TransformedImageSpanInterpolator (const AffineTransform& transform) throw()
  66466. : inverseTransform (transform.inverted())
  66467. {}
  66468. void setStartOfLine (float x, float y, const int numPixels) throw()
  66469. {
  66470. float x1 = x, y1 = y;
  66471. inverseTransform.transformPoint (x1, y1);
  66472. x += numPixels;
  66473. inverseTransform.transformPoint (x, y);
  66474. xBresenham.set ((int) (x1 * 256.0f), (int) (x * 256.0f), numPixels);
  66475. yBresenham.set ((int) (y1 * 256.0f), (int) (y * 256.0f), numPixels);
  66476. }
  66477. void next (int& x, int& y) throw()
  66478. {
  66479. x = xBresenham.n;
  66480. xBresenham.stepToNext();
  66481. y = yBresenham.n;
  66482. yBresenham.stepToNext();
  66483. }
  66484. private:
  66485. class BresenhamInterpolator
  66486. {
  66487. public:
  66488. BresenhamInterpolator() throw() {}
  66489. void set (const int n1, const int n2, const int numSteps_) throw()
  66490. {
  66491. numSteps = jmax (1, numSteps_);
  66492. step = (n2 - n1) / numSteps;
  66493. remainder = modulo = (n2 - n1) % numSteps;
  66494. n = n1;
  66495. if (modulo <= 0)
  66496. {
  66497. modulo += numSteps;
  66498. remainder += numSteps;
  66499. --step;
  66500. }
  66501. modulo -= numSteps;
  66502. }
  66503. forcedinline void stepToNext() throw()
  66504. {
  66505. modulo += remainder;
  66506. n += step;
  66507. if (modulo > 0)
  66508. {
  66509. modulo -= numSteps;
  66510. ++n;
  66511. }
  66512. }
  66513. int n;
  66514. private:
  66515. int numSteps, step, modulo, remainder;
  66516. };
  66517. const AffineTransform inverseTransform;
  66518. BresenhamInterpolator xBresenham, yBresenham;
  66519. TransformedImageSpanInterpolator (const TransformedImageSpanInterpolator&);
  66520. TransformedImageSpanInterpolator& operator= (const TransformedImageSpanInterpolator&);
  66521. };
  66522. TransformedImageSpanInterpolator interpolator;
  66523. const Image::BitmapData& destData;
  66524. const Image::BitmapData& srcData;
  66525. const int extraAlpha;
  66526. const bool betterQuality;
  66527. const float pixelOffset;
  66528. const int pixelOffsetInt, maxX, maxY;
  66529. int y;
  66530. DestPixelType* linePixels;
  66531. HeapBlock <SrcPixelType> scratchBuffer;
  66532. int scratchSize;
  66533. TransformedImageFillEdgeTableRenderer (const TransformedImageFillEdgeTableRenderer&);
  66534. TransformedImageFillEdgeTableRenderer& operator= (const TransformedImageFillEdgeTableRenderer&);
  66535. };
  66536. class LLGCSavedState
  66537. {
  66538. public:
  66539. LLGCSavedState (const Rectangle<int>& clip_, const int xOffset_, const int yOffset_,
  66540. const Font& font_, const FillType& fillType_,
  66541. const Graphics::ResamplingQuality interpolationQuality_) throw()
  66542. : edgeTable (new EdgeTableHolder (EdgeTable (clip_))),
  66543. xOffset (xOffset_), yOffset (yOffset_),
  66544. font (font_), fillType (fillType_),
  66545. interpolationQuality (interpolationQuality_)
  66546. {
  66547. }
  66548. LLGCSavedState (const LLGCSavedState& other) throw()
  66549. : edgeTable (other.edgeTable), xOffset (other.xOffset),
  66550. yOffset (other.yOffset), font (other.font),
  66551. fillType (other.fillType), interpolationQuality (other.interpolationQuality)
  66552. {
  66553. }
  66554. ~LLGCSavedState() throw()
  66555. {
  66556. }
  66557. bool clipToRectangle (const Rectangle<int>& r) throw()
  66558. {
  66559. dupeEdgeTableIfMultiplyReferenced();
  66560. edgeTable->edgeTable.clipToRectangle (r.translated (xOffset, yOffset));
  66561. return ! edgeTable->edgeTable.isEmpty();
  66562. }
  66563. bool clipToRectangleList (const RectangleList& r) throw()
  66564. {
  66565. dupeEdgeTableIfMultiplyReferenced();
  66566. RectangleList offsetList (r);
  66567. offsetList.offsetAll (xOffset, yOffset);
  66568. EdgeTable e2 (offsetList);
  66569. edgeTable->edgeTable.clipToEdgeTable (e2);
  66570. return ! edgeTable->edgeTable.isEmpty();
  66571. }
  66572. bool excludeClipRectangle (const Rectangle<int>& r) throw()
  66573. {
  66574. dupeEdgeTableIfMultiplyReferenced();
  66575. edgeTable->edgeTable.excludeRectangle (r.translated (xOffset, yOffset));
  66576. return ! edgeTable->edgeTable.isEmpty();
  66577. }
  66578. void clipToPath (const Path& p, const AffineTransform& transform) throw()
  66579. {
  66580. dupeEdgeTableIfMultiplyReferenced();
  66581. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform.translated ((float) xOffset, (float) yOffset));
  66582. edgeTable->edgeTable.clipToEdgeTable (et);
  66583. }
  66584. void fillEdgeTable (Image& image, EdgeTable& et, const bool replaceContents = false) throw()
  66585. {
  66586. et.clipToEdgeTable (edgeTable->edgeTable);
  66587. Image::BitmapData destData (image, 0, 0, image.getWidth(), image.getHeight(), true);
  66588. if (fillType.isGradient())
  66589. {
  66590. jassert (! replaceContents); // that option is just for solid colours
  66591. ColourGradient g2 (*(fillType.gradient));
  66592. g2.multiplyOpacity (fillType.getOpacity());
  66593. g2.x1 -= 0.5f; g2.y1 -= 0.5f;
  66594. g2.x2 -= 0.5f; g2.y2 -= 0.5f;
  66595. AffineTransform transform (fillType.transform.translated ((float) xOffset, (float) yOffset));
  66596. const bool isIdentity = transform.isOnlyTranslation();
  66597. if (isIdentity)
  66598. {
  66599. // If our translation doesn't involve any distortion, we can speed it up..
  66600. transform.transformPoint (g2.x1, g2.y1);
  66601. transform.transformPoint (g2.x2, g2.y2);
  66602. transform = AffineTransform::identity;
  66603. }
  66604. HeapBlock <PixelARGB> lookupTable;
  66605. const int numLookupEntries = g2.createLookupTable (transform, lookupTable);
  66606. jassert (numLookupEntries > 0);
  66607. switch (image.getFormat())
  66608. {
  66609. case Image::ARGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelARGB*) 0); break;
  66610. case Image::RGB: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelRGB*) 0); break;
  66611. default: renderGradient (et, destData, g2, transform, lookupTable, numLookupEntries, isIdentity, (PixelAlpha*) 0); break;
  66612. }
  66613. }
  66614. else if (fillType.isTiledImage())
  66615. {
  66616. renderImage (image, *(fillType.image), fillType.image->getBounds(), fillType.transform, &et);
  66617. }
  66618. else
  66619. {
  66620. const PixelARGB fillColour (fillType.colour.getPixelARGB());
  66621. switch (image.getFormat())
  66622. {
  66623. case Image::ARGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelARGB*) 0); break;
  66624. case Image::RGB: renderSolidFill (et, destData, fillColour, replaceContents, (PixelRGB*) 0); break;
  66625. default: renderSolidFill (et, destData, fillColour, replaceContents, (PixelAlpha*) 0); break;
  66626. }
  66627. }
  66628. }
  66629. void renderImage (Image& destImage, const Image& sourceImage, const Rectangle<int>& srcClip,
  66630. const AffineTransform& t, const EdgeTable* const tiledFillClipRegion) throw()
  66631. {
  66632. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66633. const Image::BitmapData destData (destImage, 0, 0, destImage.getWidth(), destImage.getHeight(), true);
  66634. const Image::BitmapData srcData (sourceImage, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66635. const int alpha = fillType.colour.getAlpha();
  66636. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66637. if (transform.isOnlyTranslation())
  66638. {
  66639. // If our translation doesn't involve any distortion, just use a simple blit..
  66640. int tx = (int) (transform.getTranslationX() * 256.0f);
  66641. int ty = (int) (transform.getTranslationY() * 256.0f);
  66642. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66643. {
  66644. tx = ((tx + 128) >> 8);
  66645. ty = ((ty + 128) >> 8);
  66646. if (tiledFillClipRegion != 0)
  66647. {
  66648. blittedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, tx, ty, true);
  66649. }
  66650. else
  66651. {
  66652. EdgeTable et (Rectangle<int> (tx, ty, srcClip.getWidth(), srcClip.getHeight()).getIntersection (destImage.getBounds()));
  66653. et.clipToEdgeTable (edgeTable->edgeTable);
  66654. if (! et.isEmpty())
  66655. blittedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, tx, ty, false);
  66656. }
  66657. return;
  66658. }
  66659. }
  66660. if (transform.isSingularity())
  66661. return;
  66662. if (tiledFillClipRegion != 0)
  66663. {
  66664. transformedRenderImage (sourceImage, destImage, *tiledFillClipRegion, destData, srcData, alpha, transform, betterQuality, true);
  66665. }
  66666. else
  66667. {
  66668. Path p;
  66669. p.addRectangle (0.0f, 0.0f, (float) srcClip.getWidth(), (float) srcClip.getHeight());
  66670. EdgeTable et (edgeTable->edgeTable.getMaximumBounds(), p, transform);
  66671. et.clipToEdgeTable (edgeTable->edgeTable);
  66672. if (! et.isEmpty())
  66673. transformedRenderImage (sourceImage, destImage, et, destData, srcData, alpha, transform, betterQuality, false);
  66674. }
  66675. }
  66676. void clipToImageAlpha (const Image& image, const Rectangle<int>& srcClip, const AffineTransform& t) throw()
  66677. {
  66678. if (! image.hasAlphaChannel())
  66679. {
  66680. Path p;
  66681. p.addRectangle (srcClip);
  66682. clipToPath (p, t);
  66683. return;
  66684. }
  66685. dupeEdgeTableIfMultiplyReferenced();
  66686. const AffineTransform transform (t.translated ((float) xOffset, (float) yOffset));
  66687. const Image::BitmapData srcData (image, srcClip.getX(), srcClip.getY(), srcClip.getWidth(), srcClip.getHeight());
  66688. const bool betterQuality = (interpolationQuality != Graphics::lowResamplingQuality);
  66689. EdgeTable& et = edgeTable->edgeTable;
  66690. if (transform.isOnlyTranslation())
  66691. {
  66692. // If our translation doesn't involve any distortion, just use a simple blit..
  66693. const int tx = (int) (transform.getTranslationX() * 256.0f);
  66694. const int ty = (int) (transform.getTranslationY() * 256.0f);
  66695. if ((! betterQuality) || ((tx | ty) & 224) == 0)
  66696. {
  66697. const int imageX = ((tx + 128) >> 8);
  66698. const int imageY = ((ty + 128) >> 8);
  66699. if (image.getFormat() == Image::ARGB)
  66700. straightClipImage (et, srcData, imageX, imageY, (PixelARGB*)0);
  66701. else
  66702. straightClipImage (et, srcData, imageX, imageY, (PixelAlpha*)0);
  66703. return;
  66704. }
  66705. }
  66706. if (transform.isSingularity())
  66707. {
  66708. et.clipToRectangle (Rectangle<int>());
  66709. return;
  66710. }
  66711. {
  66712. Path p;
  66713. p.addRectangle (0, 0, (float) srcData.width, (float) srcData.height);
  66714. EdgeTable et2 (et.getMaximumBounds(), p, transform);
  66715. et.clipToEdgeTable (et2);
  66716. }
  66717. if (! et.isEmpty())
  66718. {
  66719. if (image.getFormat() == Image::ARGB)
  66720. transformedClipImage (et, srcData, transform, betterQuality, (PixelARGB*)0);
  66721. else
  66722. transformedClipImage (et, srcData, transform, betterQuality, (PixelAlpha*)0);
  66723. }
  66724. }
  66725. template <class SrcPixelType>
  66726. void transformedClipImage (EdgeTable& et, const Image::BitmapData& srcData, const AffineTransform& transform, const bool betterQuality, const SrcPixelType *) throw()
  66727. {
  66728. TransformedImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, transform, 255, betterQuality);
  66729. for (int y = 0; y < et.getMaximumBounds().getHeight(); ++y)
  66730. renderer.clipEdgeTableLine (et, et.getMaximumBounds().getX(), y + et.getMaximumBounds().getY(),
  66731. et.getMaximumBounds().getWidth());
  66732. }
  66733. template <class SrcPixelType>
  66734. void straightClipImage (EdgeTable& et, const Image::BitmapData& srcData, int imageX, int imageY, const SrcPixelType *) throw()
  66735. {
  66736. Rectangle<int> r (imageX, imageY, srcData.width, srcData.height);
  66737. et.clipToRectangle (r);
  66738. ImageFillEdgeTableRenderer <SrcPixelType, SrcPixelType, false> renderer (srcData, srcData, 255, imageX, imageY);
  66739. for (int y = 0; y < r.getHeight(); ++y)
  66740. renderer.clipEdgeTableLine (et, r.getX(), y + r.getY(), r.getWidth());
  66741. }
  66742. class EdgeTableHolder : public ReferenceCountedObject
  66743. {
  66744. public:
  66745. EdgeTableHolder (const EdgeTable& e) throw() : edgeTable (e) {}
  66746. EdgeTable edgeTable;
  66747. };
  66748. ReferenceCountedObjectPtr<EdgeTableHolder> edgeTable;
  66749. int xOffset, yOffset;
  66750. Font font;
  66751. FillType fillType;
  66752. Graphics::ResamplingQuality interpolationQuality;
  66753. private:
  66754. LLGCSavedState& operator= (const LLGCSavedState&);
  66755. void dupeEdgeTableIfMultiplyReferenced() throw()
  66756. {
  66757. if (edgeTable->getReferenceCount() > 1)
  66758. edgeTable = new EdgeTableHolder (edgeTable->edgeTable);
  66759. }
  66760. template <class DestPixelType>
  66761. void renderGradient (EdgeTable& et, const Image::BitmapData& destData, const ColourGradient& g, const AffineTransform& transform,
  66762. const PixelARGB* const lookupTable, const int numLookupEntries, const bool isIdentity, DestPixelType*) throw()
  66763. {
  66764. jassert (destData.pixelStride == sizeof (DestPixelType));
  66765. if (g.isRadial)
  66766. {
  66767. if (isIdentity)
  66768. {
  66769. GradientEdgeTableRenderer <DestPixelType, RadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66770. et.iterate (renderer);
  66771. }
  66772. else
  66773. {
  66774. GradientEdgeTableRenderer <DestPixelType, TransformedRadialGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66775. et.iterate (renderer);
  66776. }
  66777. }
  66778. else
  66779. {
  66780. GradientEdgeTableRenderer <DestPixelType, LinearGradientPixelGenerator> renderer (destData, g, transform, lookupTable, numLookupEntries);
  66781. et.iterate (renderer);
  66782. }
  66783. }
  66784. template <class DestPixelType>
  66785. void renderSolidFill (EdgeTable& et, const Image::BitmapData& destData, const PixelARGB& fillColour, const bool replaceContents, DestPixelType*) throw()
  66786. {
  66787. jassert (destData.pixelStride == sizeof (DestPixelType));
  66788. if (replaceContents)
  66789. {
  66790. SolidColourEdgeTableRenderer <DestPixelType, true> r (destData, fillColour);
  66791. et.iterate (r);
  66792. }
  66793. else
  66794. {
  66795. SolidColourEdgeTableRenderer <DestPixelType, false> r (destData, fillColour);
  66796. et.iterate (r);
  66797. }
  66798. }
  66799. void transformedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData, const Image::BitmapData& srcData,
  66800. const int alpha, const AffineTransform& transform, const bool betterQuality, const bool repeatPattern) throw()
  66801. {
  66802. switch (destImage.getFormat())
  66803. {
  66804. case Image::ARGB:
  66805. switch (srcImage.getFormat())
  66806. {
  66807. case Image::ARGB:
  66808. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66809. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66810. break;
  66811. case Image::RGB:
  66812. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66813. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66814. break;
  66815. default:
  66816. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66817. else { TransformedImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66818. break;
  66819. }
  66820. break;
  66821. case Image::RGB:
  66822. switch (srcImage.getFormat())
  66823. {
  66824. case Image::ARGB:
  66825. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66826. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66827. break;
  66828. case Image::RGB:
  66829. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66830. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66831. break;
  66832. default:
  66833. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66834. else { TransformedImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66835. break;
  66836. }
  66837. break;
  66838. default:
  66839. switch (srcImage.getFormat())
  66840. {
  66841. case Image::ARGB:
  66842. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66843. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66844. break;
  66845. case Image::RGB:
  66846. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66847. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66848. break;
  66849. default:
  66850. if (repeatPattern) { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66851. else { TransformedImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, transform, alpha, betterQuality); et.iterate (r); }
  66852. break;
  66853. }
  66854. break;
  66855. }
  66856. }
  66857. void blittedRenderImage (const Image& srcImage, Image& destImage, const EdgeTable& et, const Image::BitmapData& destData,
  66858. const Image::BitmapData& srcData, const int alpha, int x, int y, const bool repeatPattern) throw()
  66859. {
  66860. switch (destImage.getFormat())
  66861. {
  66862. case Image::ARGB:
  66863. switch (srcImage.getFormat())
  66864. {
  66865. case Image::ARGB:
  66866. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66867. else { ImageFillEdgeTableRenderer <PixelARGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66868. break;
  66869. case Image::RGB:
  66870. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66871. else { ImageFillEdgeTableRenderer <PixelARGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66872. break;
  66873. default:
  66874. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66875. else { ImageFillEdgeTableRenderer <PixelARGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66876. break;
  66877. }
  66878. break;
  66879. case Image::RGB:
  66880. switch (srcImage.getFormat())
  66881. {
  66882. case Image::ARGB:
  66883. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66884. else { ImageFillEdgeTableRenderer <PixelRGB, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66885. break;
  66886. case Image::RGB:
  66887. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66888. else { ImageFillEdgeTableRenderer <PixelRGB, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66889. break;
  66890. default:
  66891. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66892. else { ImageFillEdgeTableRenderer <PixelRGB, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66893. break;
  66894. }
  66895. break;
  66896. default:
  66897. switch (srcImage.getFormat())
  66898. {
  66899. case Image::ARGB:
  66900. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66901. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelARGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66902. break;
  66903. case Image::RGB:
  66904. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66905. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelRGB, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66906. break;
  66907. default:
  66908. if (repeatPattern) { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, true> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66909. else { ImageFillEdgeTableRenderer <PixelAlpha, PixelAlpha, false> r (destData, srcData, alpha, x, y); et.iterate (r); }
  66910. break;
  66911. }
  66912. break;
  66913. }
  66914. }
  66915. };
  66916. LowLevelGraphicsSoftwareRenderer::LowLevelGraphicsSoftwareRenderer (Image& image_)
  66917. : image (image_)
  66918. {
  66919. currentState = new LLGCSavedState (image_.getBounds(), 0, 0, Font(),
  66920. FillType(), Graphics::mediumResamplingQuality);
  66921. }
  66922. LowLevelGraphicsSoftwareRenderer::~LowLevelGraphicsSoftwareRenderer()
  66923. {
  66924. }
  66925. bool LowLevelGraphicsSoftwareRenderer::isVectorDevice() const
  66926. {
  66927. return false;
  66928. }
  66929. void LowLevelGraphicsSoftwareRenderer::setOrigin (int x, int y)
  66930. {
  66931. currentState->xOffset += x;
  66932. currentState->yOffset += y;
  66933. }
  66934. bool LowLevelGraphicsSoftwareRenderer::clipToRectangle (const Rectangle<int>& r)
  66935. {
  66936. return currentState->clipToRectangle (r);
  66937. }
  66938. bool LowLevelGraphicsSoftwareRenderer::clipToRectangleList (const RectangleList& clipRegion)
  66939. {
  66940. return currentState->clipToRectangleList (clipRegion);
  66941. }
  66942. void LowLevelGraphicsSoftwareRenderer::excludeClipRectangle (const Rectangle<int>& r)
  66943. {
  66944. currentState->excludeClipRectangle (r);
  66945. }
  66946. void LowLevelGraphicsSoftwareRenderer::clipToPath (const Path& path, const AffineTransform& transform)
  66947. {
  66948. currentState->clipToPath (path, transform);
  66949. }
  66950. void LowLevelGraphicsSoftwareRenderer::clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  66951. {
  66952. currentState->clipToImageAlpha (sourceImage, srcClip, transform);
  66953. }
  66954. bool LowLevelGraphicsSoftwareRenderer::clipRegionIntersects (const Rectangle<int>& r)
  66955. {
  66956. return currentState->edgeTable->edgeTable.getMaximumBounds()
  66957. .intersects (r.translated (currentState->xOffset, currentState->yOffset));
  66958. }
  66959. const Rectangle<int> LowLevelGraphicsSoftwareRenderer::getClipBounds() const
  66960. {
  66961. return currentState->edgeTable->edgeTable.getMaximumBounds().translated (-currentState->xOffset, -currentState->yOffset);
  66962. }
  66963. bool LowLevelGraphicsSoftwareRenderer::isClipEmpty() const
  66964. {
  66965. return currentState->edgeTable->edgeTable.isEmpty();
  66966. }
  66967. void LowLevelGraphicsSoftwareRenderer::saveState()
  66968. {
  66969. stateStack.add (new LLGCSavedState (*currentState));
  66970. }
  66971. void LowLevelGraphicsSoftwareRenderer::restoreState()
  66972. {
  66973. LLGCSavedState* const top = stateStack.getLast();
  66974. if (top != 0)
  66975. {
  66976. currentState = top;
  66977. stateStack.removeLast (1, false);
  66978. }
  66979. else
  66980. {
  66981. jassertfalse // trying to pop with an empty stack!
  66982. }
  66983. }
  66984. void LowLevelGraphicsSoftwareRenderer::setFill (const FillType& fillType)
  66985. {
  66986. currentState->fillType = fillType;
  66987. }
  66988. void LowLevelGraphicsSoftwareRenderer::setOpacity (float newOpacity)
  66989. {
  66990. currentState->fillType.setOpacity (newOpacity);
  66991. }
  66992. void LowLevelGraphicsSoftwareRenderer::setInterpolationQuality (Graphics::ResamplingQuality quality)
  66993. {
  66994. currentState->interpolationQuality = quality;
  66995. }
  66996. void LowLevelGraphicsSoftwareRenderer::fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  66997. {
  66998. const Rectangle<int>& totalClip = currentState->edgeTable->edgeTable.getMaximumBounds();
  66999. const Rectangle<int> clipped (totalClip.getIntersection (r.translated (currentState->xOffset, currentState->yOffset)));
  67000. if (! clipped.isEmpty())
  67001. {
  67002. EdgeTable et (clipped);
  67003. currentState->fillEdgeTable (image, et, replaceExistingContents);
  67004. }
  67005. }
  67006. void LowLevelGraphicsSoftwareRenderer::fillPath (const Path& path, const AffineTransform& transform)
  67007. {
  67008. EdgeTable et (currentState->edgeTable->edgeTable.getMaximumBounds(),
  67009. path, transform.translated ((float) currentState->xOffset,
  67010. (float) currentState->yOffset));
  67011. currentState->fillEdgeTable (image, et);
  67012. }
  67013. void LowLevelGraphicsSoftwareRenderer::drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  67014. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  67015. {
  67016. jassert (sourceImage.getBounds().contains (srcClip));
  67017. currentState->renderImage (image, sourceImage, srcClip, transform,
  67018. fillEntireClipAsTiles ? &(currentState->edgeTable->edgeTable) : 0);
  67019. }
  67020. void LowLevelGraphicsSoftwareRenderer::drawLine (double x1, double y1, double x2, double y2)
  67021. {
  67022. Path p;
  67023. p.addLineSegment ((float) x1, (float) y1, (float) x2, (float) y2, 1.0f);
  67024. fillPath (p, AffineTransform::identity);
  67025. }
  67026. void LowLevelGraphicsSoftwareRenderer::drawVerticalLine (const int x, double top, double bottom)
  67027. {
  67028. if (bottom > top)
  67029. {
  67030. EdgeTable et ((float) (x + currentState->xOffset), (float) (top + currentState->yOffset), 1.0f, (float) (bottom - top));
  67031. currentState->fillEdgeTable (image, et);
  67032. }
  67033. }
  67034. void LowLevelGraphicsSoftwareRenderer::drawHorizontalLine (const int y, double left, double right)
  67035. {
  67036. if (right > left)
  67037. {
  67038. EdgeTable et ((float) (left + currentState->xOffset), (float) (y + currentState->yOffset),
  67039. (float) (right - left), 1.0f);
  67040. currentState->fillEdgeTable (image, et);
  67041. }
  67042. }
  67043. class GlyphCache : private DeletedAtShutdown
  67044. {
  67045. public:
  67046. GlyphCache() throw()
  67047. : accessCounter (0), hits (0), misses (0)
  67048. {
  67049. for (int i = 120; --i >= 0;)
  67050. glyphs.add (new CachedGlyph());
  67051. }
  67052. ~GlyphCache() throw()
  67053. {
  67054. clearSingletonInstance();
  67055. }
  67056. juce_DeclareSingleton_SingleThreaded_Minimal (GlyphCache);
  67057. void drawGlyph (LLGCSavedState& state, Image& image, const Font& font, const int glyphNumber, float x, float y) throw()
  67058. {
  67059. ++accessCounter;
  67060. int oldestCounter = std::numeric_limits<int>::max();
  67061. CachedGlyph* oldest = 0;
  67062. for (int i = glyphs.size(); --i >= 0;)
  67063. {
  67064. CachedGlyph* const glyph = glyphs.getUnchecked (i);
  67065. if (glyph->glyph == glyphNumber && glyph->font == font)
  67066. {
  67067. ++hits;
  67068. glyph->lastAccessCount = accessCounter;
  67069. glyph->draw (state, image, x, y);
  67070. return;
  67071. }
  67072. if (glyph->lastAccessCount <= oldestCounter)
  67073. {
  67074. oldestCounter = glyph->lastAccessCount;
  67075. oldest = glyph;
  67076. }
  67077. }
  67078. if (hits + ++misses > (glyphs.size() << 4))
  67079. {
  67080. if (misses * 2 > hits)
  67081. {
  67082. for (int i = 32; --i >= 0;)
  67083. glyphs.add (new CachedGlyph());
  67084. }
  67085. hits = misses = 0;
  67086. oldest = glyphs.getLast();
  67087. }
  67088. jassert (oldest != 0);
  67089. oldest->lastAccessCount = accessCounter;
  67090. oldest->generate (font, glyphNumber);
  67091. oldest->draw (state, image, x, y);
  67092. }
  67093. class CachedGlyph
  67094. {
  67095. public:
  67096. CachedGlyph() : glyph (0), lastAccessCount (0) {}
  67097. ~CachedGlyph() {}
  67098. void draw (LLGCSavedState& state, Image& image, const float x, const float y) const throw()
  67099. {
  67100. if (edgeTable != 0)
  67101. {
  67102. EdgeTable et (*edgeTable);
  67103. et.translate (x, roundToInt (y));
  67104. state.fillEdgeTable (image, et, false);
  67105. }
  67106. }
  67107. void generate (const Font& newFont, const int glyphNumber) throw()
  67108. {
  67109. font = newFont;
  67110. glyph = glyphNumber;
  67111. edgeTable = 0;
  67112. Path glyphPath;
  67113. font.getTypeface()->getOutlineForGlyph (glyphNumber, glyphPath);
  67114. if (! glyphPath.isEmpty())
  67115. {
  67116. const float fontHeight = font.getHeight();
  67117. const AffineTransform transform (AffineTransform::scale (fontHeight * font.getHorizontalScale(), fontHeight)
  67118. .translated (0.0f, -0.5f));
  67119. edgeTable = new EdgeTable (glyphPath.getBoundsTransformed (transform).getSmallestIntegerContainer().expanded (1, 0),
  67120. glyphPath, transform);
  67121. }
  67122. }
  67123. int glyph, lastAccessCount;
  67124. Font font;
  67125. juce_UseDebuggingNewOperator
  67126. private:
  67127. ScopedPointer <EdgeTable> edgeTable;
  67128. CachedGlyph (const CachedGlyph&);
  67129. CachedGlyph& operator= (const CachedGlyph&);
  67130. };
  67131. juce_UseDebuggingNewOperator
  67132. private:
  67133. OwnedArray <CachedGlyph> glyphs;
  67134. int accessCounter, hits, misses;
  67135. GlyphCache (const GlyphCache&);
  67136. GlyphCache& operator= (const GlyphCache&);
  67137. };
  67138. juce_ImplementSingleton_SingleThreaded (GlyphCache);
  67139. void LowLevelGraphicsSoftwareRenderer::setFont (const Font& newFont)
  67140. {
  67141. currentState->font = newFont;
  67142. }
  67143. const Font LowLevelGraphicsSoftwareRenderer::getFont()
  67144. {
  67145. return currentState->font;
  67146. }
  67147. void LowLevelGraphicsSoftwareRenderer::drawGlyph (int glyphNumber, const AffineTransform& transform)
  67148. {
  67149. Font& f = currentState->font;
  67150. if (transform.isOnlyTranslation())
  67151. {
  67152. GlyphCache::getInstance()->drawGlyph (*currentState, image, f, glyphNumber,
  67153. transform.getTranslationX() + (float) currentState->xOffset,
  67154. transform.getTranslationY() + (float) currentState->yOffset);
  67155. }
  67156. else
  67157. {
  67158. Path p;
  67159. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  67160. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight()).followedBy (transform));
  67161. }
  67162. }
  67163. #if JUCE_MSVC
  67164. #pragma warning (pop)
  67165. #endif
  67166. END_JUCE_NAMESPACE
  67167. /*** End of inlined file: juce_LowLevelGraphicsSoftwareRenderer.cpp ***/
  67168. /*** Start of inlined file: juce_RectanglePlacement.cpp ***/
  67169. BEGIN_JUCE_NAMESPACE
  67170. RectanglePlacement::RectanglePlacement (const RectanglePlacement& other) throw()
  67171. : flags (other.flags)
  67172. {
  67173. }
  67174. RectanglePlacement& RectanglePlacement::operator= (const RectanglePlacement& other) throw()
  67175. {
  67176. flags = other.flags;
  67177. return *this;
  67178. }
  67179. void RectanglePlacement::applyTo (double& x, double& y,
  67180. double& w, double& h,
  67181. const double dx, const double dy,
  67182. const double dw, const double dh) const throw()
  67183. {
  67184. if (w == 0 || h == 0)
  67185. return;
  67186. if ((flags & stretchToFit) != 0)
  67187. {
  67188. x = dx;
  67189. y = dy;
  67190. w = dw;
  67191. h = dh;
  67192. }
  67193. else
  67194. {
  67195. double scale = (flags & fillDestination) != 0 ? jmax (dw / w, dh / h)
  67196. : jmin (dw / w, dh / h);
  67197. if ((flags & onlyReduceInSize) != 0)
  67198. scale = jmin (scale, 1.0);
  67199. if ((flags & onlyIncreaseInSize) != 0)
  67200. scale = jmax (scale, 1.0);
  67201. w *= scale;
  67202. h *= scale;
  67203. if ((flags & xLeft) != 0)
  67204. x = dx;
  67205. else if ((flags & xRight) != 0)
  67206. x = dx + dw - w;
  67207. else
  67208. x = dx + (dw - w) * 0.5;
  67209. if ((flags & yTop) != 0)
  67210. y = dy;
  67211. else if ((flags & yBottom) != 0)
  67212. y = dy + dh - h;
  67213. else
  67214. y = dy + (dh - h) * 0.5;
  67215. }
  67216. }
  67217. const AffineTransform RectanglePlacement::getTransformToFit (float x, float y,
  67218. float w, float h,
  67219. const float dx, const float dy,
  67220. const float dw, const float dh) const throw()
  67221. {
  67222. if (w == 0 || h == 0)
  67223. return AffineTransform::identity;
  67224. const float scaleX = dw / w;
  67225. const float scaleY = dh / h;
  67226. if ((flags & stretchToFit) != 0)
  67227. return AffineTransform::translation (-x, -y)
  67228. .scaled (scaleX, scaleY)
  67229. .translated (dx, dy);
  67230. float scale = (flags & fillDestination) != 0 ? jmax (scaleX, scaleY)
  67231. : jmin (scaleX, scaleY);
  67232. if ((flags & onlyReduceInSize) != 0)
  67233. scale = jmin (scale, 1.0f);
  67234. if ((flags & onlyIncreaseInSize) != 0)
  67235. scale = jmax (scale, 1.0f);
  67236. w *= scale;
  67237. h *= scale;
  67238. float newX = dx;
  67239. if ((flags & xRight) != 0)
  67240. newX += dw - w; // right
  67241. else if ((flags & xLeft) == 0)
  67242. newX += (dw - w) / 2.0f; // centre
  67243. float newY = dy;
  67244. if ((flags & yBottom) != 0)
  67245. newY += dh - h; // bottom
  67246. else if ((flags & yTop) == 0)
  67247. newY += (dh - h) / 2.0f; // centre
  67248. return AffineTransform::translation (-x, -y)
  67249. .scaled (scale, scale)
  67250. .translated (newX, newY);
  67251. }
  67252. END_JUCE_NAMESPACE
  67253. /*** End of inlined file: juce_RectanglePlacement.cpp ***/
  67254. /*** Start of inlined file: juce_Drawable.cpp ***/
  67255. BEGIN_JUCE_NAMESPACE
  67256. Drawable::RenderingContext::RenderingContext (Graphics& g_,
  67257. const AffineTransform& transform_,
  67258. const float opacity_) throw()
  67259. : g (g_),
  67260. transform (transform_),
  67261. opacity (opacity_)
  67262. {
  67263. }
  67264. Drawable::Drawable()
  67265. {
  67266. }
  67267. Drawable::~Drawable()
  67268. {
  67269. }
  67270. void Drawable::draw (Graphics& g, const float opacity,
  67271. const AffineTransform& transform) const
  67272. {
  67273. render (RenderingContext (g, transform, opacity));
  67274. }
  67275. void Drawable::drawAt (Graphics& g, const float x, const float y, const float opacity) const
  67276. {
  67277. draw (g, opacity, AffineTransform::translation (x, y));
  67278. }
  67279. void Drawable::drawWithin (Graphics& g,
  67280. const int destX,
  67281. const int destY,
  67282. const int destW,
  67283. const int destH,
  67284. const RectanglePlacement& placement,
  67285. const float opacity) const
  67286. {
  67287. if (destW > 0 && destH > 0)
  67288. {
  67289. Rectangle<float> bounds (getBounds());
  67290. draw (g, opacity,
  67291. placement.getTransformToFit (bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight(),
  67292. (float) destX, (float) destY,
  67293. (float) destW, (float) destH));
  67294. }
  67295. }
  67296. Drawable* Drawable::createFromImageData (const void* data, const size_t numBytes)
  67297. {
  67298. Drawable* result = 0;
  67299. Image* const image = ImageFileFormat::loadFrom (data, (int) numBytes);
  67300. if (image != 0)
  67301. {
  67302. DrawableImage* const di = new DrawableImage();
  67303. di->setImage (image, true);
  67304. result = di;
  67305. }
  67306. else
  67307. {
  67308. const String asString (String::createStringFromData (data, (int) numBytes));
  67309. XmlDocument doc (asString);
  67310. ScopedPointer <XmlElement> outer (doc.getDocumentElement (true));
  67311. if (outer != 0 && outer->hasTagName (T("svg")))
  67312. {
  67313. ScopedPointer <XmlElement> svg (doc.getDocumentElement());
  67314. if (svg != 0)
  67315. result = Drawable::createFromSVG (*svg);
  67316. }
  67317. }
  67318. return result;
  67319. }
  67320. Drawable* Drawable::createFromImageDataStream (InputStream& dataSource)
  67321. {
  67322. MemoryBlock mb;
  67323. dataSource.readIntoMemoryBlock (mb);
  67324. return createFromImageData (mb.getData(), mb.getSize());
  67325. }
  67326. Drawable* Drawable::createFromImageFile (const File& file)
  67327. {
  67328. const ScopedPointer <FileInputStream> fin (file.createInputStream());
  67329. return fin != 0 ? createFromImageDataStream (*fin) : 0;
  67330. }
  67331. Drawable* Drawable::createFromValueTree (const ValueTree& tree) throw()
  67332. {
  67333. Drawable* d = DrawablePath::createFromValueTree (tree);
  67334. if (d == 0)
  67335. {
  67336. d = DrawableComposite::createFromValueTree (tree);
  67337. if (d == 0)
  67338. {
  67339. d = DrawableImage::createFromValueTree (tree);
  67340. if (d == 0)
  67341. d = DrawableText::createFromValueTree (tree);
  67342. }
  67343. }
  67344. return d;
  67345. }
  67346. END_JUCE_NAMESPACE
  67347. /*** End of inlined file: juce_Drawable.cpp ***/
  67348. /*** Start of inlined file: juce_DrawableComposite.cpp ***/
  67349. BEGIN_JUCE_NAMESPACE
  67350. DrawableComposite::DrawableComposite()
  67351. {
  67352. }
  67353. DrawableComposite::~DrawableComposite()
  67354. {
  67355. }
  67356. void DrawableComposite::insertDrawable (Drawable* drawable,
  67357. const AffineTransform& transform,
  67358. const int index)
  67359. {
  67360. if (drawable != 0)
  67361. {
  67362. if (! drawables.contains (drawable))
  67363. {
  67364. drawables.insert (index, drawable);
  67365. if (transform.isIdentity())
  67366. transforms.insert (index, 0);
  67367. else
  67368. transforms.insert (index, new AffineTransform (transform));
  67369. }
  67370. else
  67371. {
  67372. jassertfalse // trying to add a drawable that's already in here!
  67373. }
  67374. }
  67375. }
  67376. void DrawableComposite::insertDrawable (const Drawable& drawable,
  67377. const AffineTransform& transform,
  67378. const int index)
  67379. {
  67380. insertDrawable (drawable.createCopy(), transform, index);
  67381. }
  67382. void DrawableComposite::removeDrawable (const int index, const bool deleteDrawable)
  67383. {
  67384. drawables.remove (index, deleteDrawable);
  67385. transforms.remove (index);
  67386. }
  67387. void DrawableComposite::bringToFront (const int index)
  67388. {
  67389. if (index >= 0 && index < drawables.size() - 1)
  67390. {
  67391. drawables.move (index, -1);
  67392. transforms.move (index, -1);
  67393. }
  67394. }
  67395. void DrawableComposite::render (const Drawable::RenderingContext& context) const
  67396. {
  67397. if (drawables.size() > 0 && context.opacity > 0)
  67398. {
  67399. if (context.opacity >= 1.0f || drawables.size() == 1)
  67400. {
  67401. Drawable::RenderingContext contextCopy (context);
  67402. for (int i = 0; i < drawables.size(); ++i)
  67403. {
  67404. const AffineTransform* const t = transforms.getUnchecked(i);
  67405. contextCopy.transform = (t == 0) ? context.transform
  67406. : t->followedBy (context.transform);
  67407. drawables.getUnchecked(i)->render (contextCopy);
  67408. }
  67409. }
  67410. else
  67411. {
  67412. // To correctly render a whole composite layer with an overall transparency,
  67413. // we need to render everything opaquely into a temp buffer, then blend that
  67414. // with the target opacity...
  67415. const Rectangle<int> clipBounds (context.g.getClipBounds());
  67416. Image tempImage (Image::ARGB, clipBounds.getWidth(), clipBounds.getHeight(), true);
  67417. {
  67418. Graphics tempG (tempImage);
  67419. tempG.setOrigin (-clipBounds.getX(), -clipBounds.getY());
  67420. Drawable::RenderingContext tempContext (tempG, context.transform, 1.0f);
  67421. render (tempContext);
  67422. }
  67423. context.g.setOpacity (context.opacity);
  67424. context.g.drawImageAt (&tempImage, clipBounds.getX(), clipBounds.getY());
  67425. }
  67426. }
  67427. }
  67428. const Rectangle<float> DrawableComposite::getBounds() const
  67429. {
  67430. Rectangle<float> bounds;
  67431. for (int i = 0; i < drawables.size(); ++i)
  67432. {
  67433. const Drawable* const d = drawables.getUnchecked(i);
  67434. const AffineTransform* const t = transforms.getUnchecked(i);
  67435. bounds = bounds.getUnion (t == 0 ? d->getBounds()
  67436. : d->getBounds().transformed (*t));
  67437. }
  67438. return bounds;
  67439. }
  67440. bool DrawableComposite::hitTest (float x, float y) const
  67441. {
  67442. for (int i = 0; i < drawables.size(); ++i)
  67443. {
  67444. float tx = x;
  67445. float ty = y;
  67446. const AffineTransform* const t = transforms.getUnchecked(i);
  67447. if (t != 0)
  67448. t->inverted().transformPoint (tx, ty);
  67449. if (drawables.getUnchecked(i)->hitTest (tx, ty))
  67450. return true;
  67451. }
  67452. return false;
  67453. }
  67454. Drawable* DrawableComposite::createCopy() const
  67455. {
  67456. DrawableComposite* const dc = new DrawableComposite();
  67457. for (int i = 0; i < drawables.size(); ++i)
  67458. {
  67459. dc->drawables.add (drawables.getUnchecked(i)->createCopy());
  67460. const AffineTransform* const t = transforms.getUnchecked(i);
  67461. dc->transforms.add (t != 0 ? new AffineTransform (*t) : 0);
  67462. }
  67463. return dc;
  67464. }
  67465. ValueTree DrawableComposite::createValueTree() const throw()
  67466. {
  67467. ValueTree v (T("Group"));
  67468. if (getName().isNotEmpty())
  67469. v.setProperty ("id", getName(), 0);
  67470. for (int i = 0; i < drawables.size(); ++i)
  67471. {
  67472. Drawable* const d = drawables.getUnchecked(i);
  67473. ValueTree child (d->createValueTree());
  67474. AffineTransform* transform = transforms.getUnchecked(i);
  67475. if (transform != 0)
  67476. {
  67477. String t;
  67478. t << transform->mat00 << " " << transform->mat01 << " " << transform->mat02 << " "
  67479. << transform->mat10 << " " << transform->mat11 << " " << transform->mat12;
  67480. child.setProperty ("transform", t, 0);
  67481. }
  67482. v.addChild (child, -1, 0);
  67483. }
  67484. return v;
  67485. }
  67486. DrawableComposite* DrawableComposite::createFromValueTree (const ValueTree& tree) throw()
  67487. {
  67488. if (! tree.hasType ("Group"))
  67489. return 0;
  67490. DrawableComposite* dc = new DrawableComposite();
  67491. dc->setName (tree ["id"]);
  67492. for (int i = 0; i < tree.getNumChildren(); ++i)
  67493. {
  67494. ValueTree childTree (tree.getChild (i));
  67495. Drawable* d = Drawable::createFromValueTree (childTree);
  67496. if (d != 0)
  67497. {
  67498. AffineTransform transform;
  67499. const String transformAtt (childTree ["transform"].toString());
  67500. if (transformAtt.isNotEmpty())
  67501. {
  67502. StringArray tokens;
  67503. tokens.addTokens (transformAtt.trim(), false);
  67504. tokens.removeEmptyStrings (true);
  67505. if (tokens.size() == 6)
  67506. {
  67507. float f[6];
  67508. for (int j = 0; j < 6; ++j)
  67509. f[j] = (float) tokens[j].getDoubleValue();
  67510. transform = AffineTransform (f[0], f[1], f[2], f[3], f[4], f[5]);
  67511. }
  67512. }
  67513. dc->insertDrawable (d, transform);
  67514. }
  67515. }
  67516. return dc;
  67517. }
  67518. END_JUCE_NAMESPACE
  67519. /*** End of inlined file: juce_DrawableComposite.cpp ***/
  67520. /*** Start of inlined file: juce_DrawableImage.cpp ***/
  67521. BEGIN_JUCE_NAMESPACE
  67522. DrawableImage::DrawableImage()
  67523. : image (0),
  67524. canDeleteImage (false),
  67525. opacity (1.0f),
  67526. overlayColour (0x00000000)
  67527. {
  67528. }
  67529. DrawableImage::~DrawableImage()
  67530. {
  67531. clearImage();
  67532. }
  67533. void DrawableImage::clearImage()
  67534. {
  67535. if (canDeleteImage && image != 0)
  67536. ImageCache::releaseOrDelete (image);
  67537. image = 0;
  67538. }
  67539. void DrawableImage::setImage (const Image& imageToCopy)
  67540. {
  67541. clearImage();
  67542. image = new Image (imageToCopy);
  67543. canDeleteImage = true;
  67544. }
  67545. void DrawableImage::setImage (Image* imageToUse,
  67546. const bool releaseWhenNotNeeded)
  67547. {
  67548. clearImage();
  67549. image = imageToUse;
  67550. canDeleteImage = releaseWhenNotNeeded;
  67551. }
  67552. void DrawableImage::setOpacity (const float newOpacity)
  67553. {
  67554. opacity = newOpacity;
  67555. }
  67556. void DrawableImage::setOverlayColour (const Colour& newOverlayColour)
  67557. {
  67558. overlayColour = newOverlayColour;
  67559. }
  67560. void DrawableImage::render (const Drawable::RenderingContext& context) const
  67561. {
  67562. if (image != 0)
  67563. {
  67564. if (opacity > 0.0f && ! overlayColour.isOpaque())
  67565. {
  67566. context.g.setOpacity (context.opacity * opacity);
  67567. context.g.drawImageTransformed (image, image->getBounds(),
  67568. context.transform, false);
  67569. }
  67570. if (! overlayColour.isTransparent())
  67571. {
  67572. context.g.setColour (overlayColour.withMultipliedAlpha (context.opacity));
  67573. context.g.drawImageTransformed (image, image->getBounds(),
  67574. context.transform, true);
  67575. }
  67576. }
  67577. }
  67578. const Rectangle<float> DrawableImage::getBounds() const
  67579. {
  67580. if (image == 0)
  67581. return Rectangle<float>();
  67582. return Rectangle<float> (0, 0, (float) image->getWidth(), (float) image->getHeight());
  67583. }
  67584. bool DrawableImage::hitTest (float x, float y) const
  67585. {
  67586. return image != 0
  67587. && x >= 0.0f
  67588. && y >= 0.0f
  67589. && x < image->getWidth()
  67590. && y < image->getHeight()
  67591. && image->getPixelAt (roundToInt (x), roundToInt (y)).getAlpha() >= 127;
  67592. }
  67593. Drawable* DrawableImage::createCopy() const
  67594. {
  67595. DrawableImage* const di = new DrawableImage();
  67596. di->opacity = opacity;
  67597. di->overlayColour = overlayColour;
  67598. if (image != 0)
  67599. {
  67600. if ((! canDeleteImage) || ! ImageCache::isImageInCache (image))
  67601. {
  67602. di->setImage (*image);
  67603. }
  67604. else
  67605. {
  67606. ImageCache::incReferenceCount (image);
  67607. di->setImage (image, true);
  67608. }
  67609. }
  67610. return di;
  67611. }
  67612. ValueTree DrawableImage::createValueTree() const throw()
  67613. {
  67614. ValueTree v (T("Image"));
  67615. if (getName().isNotEmpty())
  67616. v.setProperty ("id", getName(), 0);
  67617. if (opacity < 1.0f)
  67618. v.setProperty ("opacity", (double) opacity, 0);
  67619. if (! overlayColour.isTransparent())
  67620. v.setProperty ("overlay", String::toHexString ((int) overlayColour.getARGB()), 0);
  67621. if (image != 0)
  67622. {
  67623. MemoryOutputStream imageData;
  67624. PNGImageFormat pngFormat;
  67625. if (pngFormat.writeImageToStream (*image, imageData))
  67626. {
  67627. String base64 (MemoryBlock (imageData.getData(), imageData.getDataSize()).toBase64Encoding());
  67628. for (int i = (base64.length() & ~127); i >= 0; i -= 128)
  67629. base64 = base64.substring (0, i) + "\n" + base64.substring (i);
  67630. v.setProperty ("data", base64, 0);
  67631. }
  67632. }
  67633. return v;
  67634. }
  67635. DrawableImage* DrawableImage::createFromValueTree (const ValueTree& tree) throw()
  67636. {
  67637. if (! tree.hasType ("Image"))
  67638. return 0;
  67639. DrawableImage* di = new DrawableImage();
  67640. di->setName (tree ["id"]);
  67641. di->opacity = tree.hasProperty ("opacity") ? (float) tree ["opacity"] : 1.0f;
  67642. di->overlayColour = Colour (tree ["overlay"].toString().getHexValue32());
  67643. MemoryBlock imageData;
  67644. if (imageData.fromBase64Encoding (tree ["data"]))
  67645. {
  67646. Image* const im = ImageFileFormat::loadFrom (imageData.getData(), (int) imageData.getSize());
  67647. if (im == 0)
  67648. return false;
  67649. di->setImage (im, true);
  67650. }
  67651. return di;
  67652. }
  67653. END_JUCE_NAMESPACE
  67654. /*** End of inlined file: juce_DrawableImage.cpp ***/
  67655. /*** Start of inlined file: juce_DrawablePath.cpp ***/
  67656. BEGIN_JUCE_NAMESPACE
  67657. DrawablePath::DrawablePath()
  67658. : mainFill (FillType (Colours::black)),
  67659. strokeFill (FillType (Colours::transparentBlack)),
  67660. strokeType (0.0f)
  67661. {
  67662. }
  67663. DrawablePath::~DrawablePath()
  67664. {
  67665. }
  67666. void DrawablePath::setPath (const Path& newPath) throw()
  67667. {
  67668. path = newPath;
  67669. updateOutline();
  67670. }
  67671. void DrawablePath::setFill (const FillType& newFill) throw()
  67672. {
  67673. mainFill = newFill;
  67674. }
  67675. void DrawablePath::setStrokeFill (const FillType& newFill) throw()
  67676. {
  67677. strokeFill = newFill;
  67678. }
  67679. void DrawablePath::setStrokeType (const PathStrokeType& newStrokeType) throw()
  67680. {
  67681. strokeType = newStrokeType;
  67682. updateOutline();
  67683. }
  67684. void DrawablePath::setStrokeThickness (const float newThickness) throw()
  67685. {
  67686. setStrokeType (PathStrokeType (newThickness, strokeType.getJointStyle(), strokeType.getEndStyle()));
  67687. }
  67688. void DrawablePath::render (const Drawable::RenderingContext& context) const
  67689. {
  67690. {
  67691. FillType f (mainFill);
  67692. if (f.isGradient())
  67693. f.gradient->multiplyOpacity (context.opacity);
  67694. f.transform = f.transform.followedBy (context.transform);
  67695. context.g.setFillType (f);
  67696. context.g.fillPath (path, context.transform);
  67697. }
  67698. if (strokeType.getStrokeThickness() > 0.0f)
  67699. {
  67700. FillType f (strokeFill);
  67701. if (f.isGradient())
  67702. f.gradient->multiplyOpacity (context.opacity);
  67703. f.transform = f.transform.followedBy (context.transform);
  67704. context.g.setFillType (f);
  67705. context.g.fillPath (stroke, context.transform);
  67706. }
  67707. }
  67708. void DrawablePath::updateOutline()
  67709. {
  67710. stroke.clear();
  67711. strokeType.createStrokedPath (stroke, path, AffineTransform::identity, 4.0f);
  67712. }
  67713. const Rectangle<float> DrawablePath::getBounds() const
  67714. {
  67715. if (strokeType.getStrokeThickness() > 0.0f)
  67716. return stroke.getBounds();
  67717. else
  67718. return path.getBounds();
  67719. }
  67720. bool DrawablePath::hitTest (float x, float y) const
  67721. {
  67722. return path.contains (x, y)
  67723. || stroke.contains (x, y);
  67724. }
  67725. Drawable* DrawablePath::createCopy() const
  67726. {
  67727. DrawablePath* const dp = new DrawablePath();
  67728. dp->path = path;
  67729. dp->stroke = stroke;
  67730. dp->mainFill = mainFill;
  67731. dp->strokeFill = strokeFill;
  67732. dp->strokeType = strokeType;
  67733. return dp;
  67734. }
  67735. static const FillType readFillTypeFromTree (const ValueTree& v)
  67736. {
  67737. const String type (v["type"].toString());
  67738. if (type.equalsIgnoreCase (T("solid")))
  67739. {
  67740. const String colour (v ["colour"].toString());
  67741. return FillType (Colour (colour.isEmpty() ? (uint32) 0xff000000
  67742. : (uint32) colour.getHexValue32()));
  67743. }
  67744. else if (type.equalsIgnoreCase ("gradient"))
  67745. {
  67746. ColourGradient g;
  67747. g.x1 = v["x1"];
  67748. g.y1 = v["y1"];
  67749. g.x2 = v["x2"];
  67750. g.y2 = v["y2"];
  67751. g.isRadial = v["radial"];
  67752. StringArray colours;
  67753. colours.addTokens (v["colours"].toString(), false);
  67754. for (int i = 0; i < colours.size() / 2; ++i)
  67755. g.addColour (colours[i * 2].getDoubleValue(),
  67756. Colour ((uint32) colours[i * 2 + 1].getHexValue32()));
  67757. return FillType (g);
  67758. }
  67759. jassertfalse
  67760. return FillType();
  67761. }
  67762. static ValueTree createTreeForFillType (const String& tagName, const FillType& fillType)
  67763. {
  67764. ValueTree v (tagName);
  67765. if (fillType.isColour())
  67766. {
  67767. v.setProperty ("type", T("solid"), 0);
  67768. v.setProperty ("colour", String::toHexString ((int) fillType.colour.getARGB()), 0);
  67769. }
  67770. else if (fillType.isGradient())
  67771. {
  67772. v.setProperty ("type", T("gradient"), 0);
  67773. v.setProperty ("x1", fillType.gradient->x1, 0);
  67774. v.setProperty ("y1", fillType.gradient->y1, 0);
  67775. v.setProperty ("x2", fillType.gradient->x2, 0);
  67776. v.setProperty ("y2", fillType.gradient->y2, 0);
  67777. v.setProperty ("radial", fillType.gradient->isRadial, 0);
  67778. String s;
  67779. for (int i = 0; i < fillType.gradient->getNumColours(); ++i)
  67780. s << " " << fillType.gradient->getColourPosition (i)
  67781. << " " << String::toHexString ((int) fillType.gradient->getColour(i).getARGB());
  67782. v.setProperty ("colours", s.trimStart(), 0);
  67783. }
  67784. else
  67785. {
  67786. jassertfalse //xxx
  67787. }
  67788. return v;
  67789. }
  67790. ValueTree DrawablePath::createValueTree() const throw()
  67791. {
  67792. ValueTree v (T("Path"));
  67793. v.addChild (createTreeForFillType (T("fill"), mainFill), -1, 0);
  67794. v.addChild (createTreeForFillType (T("stroke"), strokeFill), -1, 0);
  67795. if (getName().isNotEmpty())
  67796. v.setProperty ("id", getName(), 0);
  67797. v.setProperty ("strokeWidth", (double) strokeType.getStrokeThickness(), 0);
  67798. v.setProperty ("jointStyle", strokeType.getJointStyle() == PathStrokeType::mitered
  67799. ? T("miter") : (strokeType.getJointStyle() == PathStrokeType::curved ? T("curved") : T("bevel")), 0);
  67800. v.setProperty ("capStyle", strokeType.getEndStyle() == PathStrokeType::butt
  67801. ? T("butt") : (strokeType.getEndStyle() == PathStrokeType::square ? T("square") : T("round")), 0);
  67802. v.setProperty ("path", path.toString(), 0);
  67803. return v;
  67804. }
  67805. DrawablePath* DrawablePath::createFromValueTree (const ValueTree& tree) throw()
  67806. {
  67807. if (! tree.hasType ("Path"))
  67808. return 0;
  67809. DrawablePath* p = new DrawablePath();
  67810. p->setName (tree ["id"]);
  67811. p->mainFill = readFillTypeFromTree (tree.getChildWithName (T("fill")));
  67812. p->strokeFill = readFillTypeFromTree (tree.getChildWithName (T("stroke")));
  67813. const String jointStyle (tree ["jointStyle"].toString());
  67814. const String endStyle (tree ["capStyle"].toString());
  67815. p->strokeType
  67816. = PathStrokeType (tree ["strokeWidth"],
  67817. jointStyle.equalsIgnoreCase (T("curved")) ? PathStrokeType::curved
  67818. : (jointStyle.equalsIgnoreCase (T("bevel")) ? PathStrokeType::beveled
  67819. : PathStrokeType::mitered),
  67820. endStyle.equalsIgnoreCase (T("square")) ? PathStrokeType::square
  67821. : (endStyle.equalsIgnoreCase (T("round")) ? PathStrokeType::rounded
  67822. : PathStrokeType::butt));
  67823. p->path.clear();
  67824. p->path.restoreFromString (tree ["path"]);
  67825. p->updateOutline();
  67826. return p;
  67827. }
  67828. END_JUCE_NAMESPACE
  67829. /*** End of inlined file: juce_DrawablePath.cpp ***/
  67830. /*** Start of inlined file: juce_DrawableText.cpp ***/
  67831. BEGIN_JUCE_NAMESPACE
  67832. DrawableText::DrawableText()
  67833. : colour (Colours::white)
  67834. {
  67835. }
  67836. DrawableText::~DrawableText()
  67837. {
  67838. }
  67839. void DrawableText::setText (const GlyphArrangement& newText)
  67840. {
  67841. text = newText;
  67842. }
  67843. void DrawableText::setText (const String& newText, const Font& fontToUse)
  67844. {
  67845. text.clear();
  67846. text.addLineOfText (fontToUse, newText, 0.0f, 0.0f);
  67847. }
  67848. void DrawableText::setColour (const Colour& newColour)
  67849. {
  67850. colour = newColour;
  67851. }
  67852. void DrawableText::render (const Drawable::RenderingContext& context) const
  67853. {
  67854. context.g.setColour (colour.withMultipliedAlpha (context.opacity));
  67855. text.draw (context.g, context.transform);
  67856. }
  67857. const Rectangle<float> DrawableText::getBounds() const
  67858. {
  67859. float x, y, w, h;
  67860. text.getBoundingBox (0, -1, x, y, w, h, false); // (really returns top, left, bottom, right)
  67861. w -= x;
  67862. h -= y;
  67863. return Rectangle<float> (x, y, w, h);
  67864. }
  67865. bool DrawableText::hitTest (float x, float y) const
  67866. {
  67867. return text.findGlyphIndexAt (x, y) >= 0;
  67868. }
  67869. Drawable* DrawableText::createCopy() const
  67870. {
  67871. DrawableText* const dt = new DrawableText();
  67872. dt->text = text;
  67873. dt->colour = colour;
  67874. return dt;
  67875. }
  67876. ValueTree DrawableText::createValueTree() const throw()
  67877. {
  67878. ValueTree v (T("Text"));
  67879. if (getName().isNotEmpty())
  67880. v.setProperty ("id", getName(), 0);
  67881. jassertfalse // xxx not finished!
  67882. return v;
  67883. }
  67884. DrawableText* DrawableText::createFromValueTree (const ValueTree& tree) throw()
  67885. {
  67886. if (! tree.hasType ("Text"))
  67887. return 0;
  67888. DrawableText* dt = new DrawableText();
  67889. dt->setName (tree ["id"]);
  67890. jassertfalse // xxx not finished!
  67891. return dt;
  67892. }
  67893. END_JUCE_NAMESPACE
  67894. /*** End of inlined file: juce_DrawableText.cpp ***/
  67895. /*** Start of inlined file: juce_SVGParser.cpp ***/
  67896. BEGIN_JUCE_NAMESPACE
  67897. class SVGState
  67898. {
  67899. public:
  67900. SVGState (const XmlElement* const topLevel)
  67901. : topLevelXml (topLevel),
  67902. elementX (0), elementY (0),
  67903. width (512), height (512),
  67904. viewBoxW (0), viewBoxH (0)
  67905. {
  67906. }
  67907. ~SVGState()
  67908. {
  67909. }
  67910. Drawable* parseSVGElement (const XmlElement& xml)
  67911. {
  67912. if (! xml.hasTagName (T("svg")))
  67913. return 0;
  67914. DrawableComposite* const drawable = new DrawableComposite();
  67915. drawable->setName (xml.getStringAttribute (T("id")));
  67916. SVGState newState (*this);
  67917. if (xml.hasAttribute (T("transform")))
  67918. newState.addTransform (xml);
  67919. newState.elementX = getCoordLength (xml.getStringAttribute (T("x"), String (newState.elementX)), viewBoxW);
  67920. newState.elementY = getCoordLength (xml.getStringAttribute (T("y"), String (newState.elementY)), viewBoxH);
  67921. newState.width = getCoordLength (xml.getStringAttribute (T("width"), String (newState.width)), viewBoxW);
  67922. newState.height = getCoordLength (xml.getStringAttribute (T("height"), String (newState.height)), viewBoxH);
  67923. if (xml.hasAttribute (T("viewBox")))
  67924. {
  67925. const String viewParams (xml.getStringAttribute (T("viewBox")));
  67926. int i = 0;
  67927. float vx, vy, vw, vh;
  67928. if (parseCoords (viewParams, vx, vy, i, true)
  67929. && parseCoords (viewParams, vw, vh, i, true)
  67930. && vw > 0
  67931. && vh > 0)
  67932. {
  67933. newState.viewBoxW = vw;
  67934. newState.viewBoxH = vh;
  67935. int placementFlags = 0;
  67936. const String aspect (xml.getStringAttribute (T("preserveAspectRatio")));
  67937. if (aspect.containsIgnoreCase (T("none")))
  67938. {
  67939. placementFlags = RectanglePlacement::stretchToFit;
  67940. }
  67941. else
  67942. {
  67943. if (aspect.containsIgnoreCase (T("slice")))
  67944. placementFlags |= RectanglePlacement::fillDestination;
  67945. if (aspect.containsIgnoreCase (T("xMin")))
  67946. placementFlags |= RectanglePlacement::xLeft;
  67947. else if (aspect.containsIgnoreCase (T("xMax")))
  67948. placementFlags |= RectanglePlacement::xRight;
  67949. else
  67950. placementFlags |= RectanglePlacement::xMid;
  67951. if (aspect.containsIgnoreCase (T("yMin")))
  67952. placementFlags |= RectanglePlacement::yTop;
  67953. else if (aspect.containsIgnoreCase (T("yMax")))
  67954. placementFlags |= RectanglePlacement::yBottom;
  67955. else
  67956. placementFlags |= RectanglePlacement::yMid;
  67957. }
  67958. const RectanglePlacement placement (placementFlags);
  67959. newState.transform
  67960. = placement.getTransformToFit (vx, vy, vw, vh,
  67961. 0.0f, 0.0f, newState.width, newState.height)
  67962. .followedBy (newState.transform);
  67963. }
  67964. }
  67965. else
  67966. {
  67967. if (viewBoxW == 0)
  67968. newState.viewBoxW = newState.width;
  67969. if (viewBoxH == 0)
  67970. newState.viewBoxH = newState.height;
  67971. }
  67972. newState.parseSubElements (xml, drawable);
  67973. return drawable;
  67974. }
  67975. private:
  67976. const XmlElement* const topLevelXml;
  67977. float elementX, elementY, width, height, viewBoxW, viewBoxH;
  67978. AffineTransform transform;
  67979. String cssStyleText;
  67980. void parseSubElements (const XmlElement& xml, DrawableComposite* const parentDrawable)
  67981. {
  67982. forEachXmlChildElement (xml, e)
  67983. {
  67984. Drawable* d = 0;
  67985. if (e->hasTagName (T("g")))
  67986. d = parseGroupElement (*e);
  67987. else if (e->hasTagName (T("svg")))
  67988. d = parseSVGElement (*e);
  67989. else if (e->hasTagName (T("path")))
  67990. d = parsePath (*e);
  67991. else if (e->hasTagName (T("rect")))
  67992. d = parseRect (*e);
  67993. else if (e->hasTagName (T("circle")))
  67994. d = parseCircle (*e);
  67995. else if (e->hasTagName (T("ellipse")))
  67996. d = parseEllipse (*e);
  67997. else if (e->hasTagName (T("line")))
  67998. d = parseLine (*e);
  67999. else if (e->hasTagName (T("polyline")))
  68000. d = parsePolygon (*e, true);
  68001. else if (e->hasTagName (T("polygon")))
  68002. d = parsePolygon (*e, false);
  68003. else if (e->hasTagName (T("text")))
  68004. d = parseText (*e);
  68005. else if (e->hasTagName (T("switch")))
  68006. d = parseSwitch (*e);
  68007. else if (e->hasTagName (T("style")))
  68008. parseCSSStyle (*e);
  68009. parentDrawable->insertDrawable (d);
  68010. }
  68011. }
  68012. DrawableComposite* parseSwitch (const XmlElement& xml)
  68013. {
  68014. const XmlElement* const group = xml.getChildByName (T("g"));
  68015. if (group != 0)
  68016. return parseGroupElement (*group);
  68017. return 0;
  68018. }
  68019. DrawableComposite* parseGroupElement (const XmlElement& xml)
  68020. {
  68021. DrawableComposite* const drawable = new DrawableComposite();
  68022. drawable->setName (xml.getStringAttribute (T("id")));
  68023. if (xml.hasAttribute (T("transform")))
  68024. {
  68025. SVGState newState (*this);
  68026. newState.addTransform (xml);
  68027. newState.parseSubElements (xml, drawable);
  68028. }
  68029. else
  68030. {
  68031. parseSubElements (xml, drawable);
  68032. }
  68033. return drawable;
  68034. }
  68035. Drawable* parsePath (const XmlElement& xml) const
  68036. {
  68037. const String d (xml.getStringAttribute (T("d")).trimStart());
  68038. Path path;
  68039. if (getStyleAttribute (&xml, T("fill-rule")).trim().equalsIgnoreCase (T("evenodd")))
  68040. path.setUsingNonZeroWinding (false);
  68041. int index = 0;
  68042. float lastX = 0, lastY = 0;
  68043. float lastX2 = 0, lastY2 = 0;
  68044. tchar lastCommandChar = 0;
  68045. bool isRelative = true;
  68046. bool carryOn = true;
  68047. const String validCommandChars (T("MmLlHhVvCcSsQqTtAaZz"));
  68048. for (;;)
  68049. {
  68050. float x, y, x2, y2, x3, y3;
  68051. if (validCommandChars.containsChar (d[index]))
  68052. {
  68053. lastCommandChar = d [index++];
  68054. isRelative = (lastCommandChar >= 'a' && lastCommandChar <= 'z');
  68055. }
  68056. switch (lastCommandChar)
  68057. {
  68058. case T('M'):
  68059. case T('m'):
  68060. case T('L'):
  68061. case T('l'):
  68062. if (parseCoords (d, x, y, index, false))
  68063. {
  68064. if (isRelative)
  68065. {
  68066. x += lastX;
  68067. y += lastY;
  68068. }
  68069. if (lastCommandChar == T('M') || lastCommandChar == T('m'))
  68070. path.startNewSubPath (x, y);
  68071. else
  68072. path.lineTo (x, y);
  68073. lastX2 = lastX;
  68074. lastY2 = lastY;
  68075. lastX = x;
  68076. lastY = y;
  68077. }
  68078. else
  68079. {
  68080. ++index;
  68081. }
  68082. break;
  68083. case T('H'):
  68084. case T('h'):
  68085. if (parseCoord (d, x, index, false, true))
  68086. {
  68087. if (isRelative)
  68088. x += lastX;
  68089. path.lineTo (x, lastY);
  68090. lastX2 = lastX;
  68091. lastX = x;
  68092. }
  68093. else
  68094. {
  68095. ++index;
  68096. }
  68097. break;
  68098. case T('V'):
  68099. case T('v'):
  68100. if (parseCoord (d, y, index, false, false))
  68101. {
  68102. if (isRelative)
  68103. y += lastY;
  68104. path.lineTo (lastX, y);
  68105. lastY2 = lastY;
  68106. lastY = y;
  68107. }
  68108. else
  68109. {
  68110. ++index;
  68111. }
  68112. break;
  68113. case T('C'):
  68114. case T('c'):
  68115. if (parseCoords (d, x, y, index, false)
  68116. && parseCoords (d, x2, y2, index, false)
  68117. && parseCoords (d, x3, y3, index, false))
  68118. {
  68119. if (isRelative)
  68120. {
  68121. x += lastX;
  68122. y += lastY;
  68123. x2 += lastX;
  68124. y2 += lastY;
  68125. x3 += lastX;
  68126. y3 += lastY;
  68127. }
  68128. path.cubicTo (x, y, x2, y2, x3, y3);
  68129. lastX2 = x2;
  68130. lastY2 = y2;
  68131. lastX = x3;
  68132. lastY = y3;
  68133. }
  68134. else
  68135. {
  68136. ++index;
  68137. }
  68138. break;
  68139. case T('S'):
  68140. case T('s'):
  68141. if (parseCoords (d, x, y, index, false)
  68142. && parseCoords (d, x3, y3, index, false))
  68143. {
  68144. if (isRelative)
  68145. {
  68146. x += lastX;
  68147. y += lastY;
  68148. x3 += lastX;
  68149. y3 += lastY;
  68150. }
  68151. x2 = lastX + (lastX - lastX2);
  68152. y2 = lastY + (lastY - lastY2);
  68153. path.cubicTo (x2, y2, x, y, x3, y3);
  68154. lastX2 = x;
  68155. lastY2 = y;
  68156. lastX = x3;
  68157. lastY = y3;
  68158. }
  68159. else
  68160. {
  68161. ++index;
  68162. }
  68163. break;
  68164. case T('Q'):
  68165. case T('q'):
  68166. if (parseCoords (d, x, y, index, false)
  68167. && parseCoords (d, x2, y2, index, false))
  68168. {
  68169. if (isRelative)
  68170. {
  68171. x += lastX;
  68172. y += lastY;
  68173. x2 += lastX;
  68174. y2 += lastY;
  68175. }
  68176. path.quadraticTo (x, y, x2, y2);
  68177. lastX2 = x;
  68178. lastY2 = y;
  68179. lastX = x2;
  68180. lastY = y2;
  68181. }
  68182. else
  68183. {
  68184. ++index;
  68185. }
  68186. break;
  68187. case T('T'):
  68188. case T('t'):
  68189. if (parseCoords (d, x, y, index, false))
  68190. {
  68191. if (isRelative)
  68192. {
  68193. x += lastX;
  68194. y += lastY;
  68195. }
  68196. x2 = lastX + (lastX - lastX2);
  68197. y2 = lastY + (lastY - lastY2);
  68198. path.quadraticTo (x2, y2, x, y);
  68199. lastX2 = x2;
  68200. lastY2 = y2;
  68201. lastX = x;
  68202. lastY = y;
  68203. }
  68204. else
  68205. {
  68206. ++index;
  68207. }
  68208. break;
  68209. case T('A'):
  68210. case T('a'):
  68211. if (parseCoords (d, x, y, index, false))
  68212. {
  68213. String num;
  68214. if (parseNextNumber (d, num, index, false))
  68215. {
  68216. const float angle = num.getFloatValue() * (180.0f / float_Pi);
  68217. if (parseNextNumber (d, num, index, false))
  68218. {
  68219. const bool largeArc = num.getIntValue() != 0;
  68220. if (parseNextNumber (d, num, index, false))
  68221. {
  68222. const bool sweep = num.getIntValue() != 0;
  68223. if (parseCoords (d, x2, y2, index, false))
  68224. {
  68225. if (isRelative)
  68226. {
  68227. x2 += lastX;
  68228. y2 += lastY;
  68229. }
  68230. if (lastX != x2 || lastY != y2)
  68231. {
  68232. double centreX, centreY, startAngle, deltaAngle;
  68233. double rx = x, ry = y;
  68234. endpointToCentreParameters (lastX, lastY, x2, y2,
  68235. angle, largeArc, sweep,
  68236. rx, ry, centreX, centreY,
  68237. startAngle, deltaAngle);
  68238. path.addCentredArc ((float) centreX, (float) centreY,
  68239. (float) rx, (float) ry,
  68240. angle, (float) startAngle, (float) (startAngle + deltaAngle),
  68241. false);
  68242. path.lineTo (x2, y2);
  68243. }
  68244. lastX2 = lastX;
  68245. lastY2 = lastY;
  68246. lastX = x2;
  68247. lastY = y2;
  68248. }
  68249. }
  68250. }
  68251. }
  68252. }
  68253. else
  68254. {
  68255. ++index;
  68256. }
  68257. break;
  68258. case T('Z'):
  68259. case T('z'):
  68260. path.closeSubPath();
  68261. while (CharacterFunctions::isWhitespace (d [index]))
  68262. ++index;
  68263. break;
  68264. default:
  68265. carryOn = false;
  68266. break;
  68267. }
  68268. if (! carryOn)
  68269. break;
  68270. }
  68271. return parseShape (xml, path);
  68272. }
  68273. Drawable* parseRect (const XmlElement& xml) const
  68274. {
  68275. Path rect;
  68276. const bool hasRX = xml.hasAttribute (T("rx"));
  68277. const bool hasRY = xml.hasAttribute (T("ry"));
  68278. if (hasRX || hasRY)
  68279. {
  68280. float rx = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68281. float ry = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68282. if (! hasRX)
  68283. rx = ry;
  68284. else if (! hasRY)
  68285. ry = rx;
  68286. rect.addRoundedRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  68287. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  68288. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  68289. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH),
  68290. rx, ry);
  68291. }
  68292. else
  68293. {
  68294. rect.addRectangle (getCoordLength (xml.getStringAttribute (T("x")), viewBoxW),
  68295. getCoordLength (xml.getStringAttribute (T("y")), viewBoxH),
  68296. getCoordLength (xml.getStringAttribute (T("width")), viewBoxW),
  68297. getCoordLength (xml.getStringAttribute (T("height")), viewBoxH));
  68298. }
  68299. return parseShape (xml, rect);
  68300. }
  68301. Drawable* parseCircle (const XmlElement& xml) const
  68302. {
  68303. Path circle;
  68304. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68305. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68306. const float radius = getCoordLength (xml.getStringAttribute (T("r")), viewBoxW);
  68307. circle.addEllipse (cx - radius, cy - radius, radius * 2.0f, radius * 2.0f);
  68308. return parseShape (xml, circle);
  68309. }
  68310. Drawable* parseEllipse (const XmlElement& xml) const
  68311. {
  68312. Path ellipse;
  68313. const float cx = getCoordLength (xml.getStringAttribute (T("cx")), viewBoxW);
  68314. const float cy = getCoordLength (xml.getStringAttribute (T("cy")), viewBoxH);
  68315. const float radiusX = getCoordLength (xml.getStringAttribute (T("rx")), viewBoxW);
  68316. const float radiusY = getCoordLength (xml.getStringAttribute (T("ry")), viewBoxH);
  68317. ellipse.addEllipse (cx - radiusX, cy - radiusY, radiusX * 2.0f, radiusY * 2.0f);
  68318. return parseShape (xml, ellipse);
  68319. }
  68320. Drawable* parseLine (const XmlElement& xml) const
  68321. {
  68322. Path line;
  68323. const float x1 = getCoordLength (xml.getStringAttribute (T("x1")), viewBoxW);
  68324. const float y1 = getCoordLength (xml.getStringAttribute (T("y1")), viewBoxH);
  68325. const float x2 = getCoordLength (xml.getStringAttribute (T("x2")), viewBoxW);
  68326. const float y2 = getCoordLength (xml.getStringAttribute (T("y2")), viewBoxH);
  68327. line.startNewSubPath (x1, y1);
  68328. line.lineTo (x2, y2);
  68329. return parseShape (xml, line);
  68330. }
  68331. Drawable* parsePolygon (const XmlElement& xml, const bool isPolyline) const
  68332. {
  68333. const String points (xml.getStringAttribute (T("points")));
  68334. Path path;
  68335. int index = 0;
  68336. float x, y;
  68337. if (parseCoords (points, x, y, index, true))
  68338. {
  68339. float firstX = x;
  68340. float firstY = y;
  68341. float lastX = 0, lastY = 0;
  68342. path.startNewSubPath (x, y);
  68343. while (parseCoords (points, x, y, index, true))
  68344. {
  68345. lastX = x;
  68346. lastY = y;
  68347. path.lineTo (x, y);
  68348. }
  68349. if ((! isPolyline) || (firstX == lastX && firstY == lastY))
  68350. path.closeSubPath();
  68351. }
  68352. return parseShape (xml, path);
  68353. }
  68354. Drawable* parseShape (const XmlElement& xml, Path& path,
  68355. const bool shouldParseTransform = true) const
  68356. {
  68357. if (shouldParseTransform && xml.hasAttribute (T("transform")))
  68358. {
  68359. SVGState newState (*this);
  68360. newState.addTransform (xml);
  68361. return newState.parseShape (xml, path, false);
  68362. }
  68363. DrawablePath* dp = new DrawablePath();
  68364. dp->setName (xml.getStringAttribute (T("id")));
  68365. dp->setFill (FillType (Colours::transparentBlack));
  68366. path.applyTransform (transform);
  68367. dp->setPath (path);
  68368. Path::Iterator iter (path);
  68369. bool containsClosedSubPath = false;
  68370. while (iter.next())
  68371. {
  68372. if (iter.elementType == Path::Iterator::closePath)
  68373. {
  68374. containsClosedSubPath = true;
  68375. break;
  68376. }
  68377. }
  68378. dp->setFill (getPathFillType (path,
  68379. getStyleAttribute (&xml, T("fill")),
  68380. getStyleAttribute (&xml, T("fill-opacity")),
  68381. getStyleAttribute (&xml, T("opacity")),
  68382. containsClosedSubPath ? Colours::black
  68383. : Colours::transparentBlack));
  68384. const String strokeType (getStyleAttribute (&xml, T("stroke")));
  68385. if (strokeType.isNotEmpty() && ! strokeType.equalsIgnoreCase (T("none")))
  68386. {
  68387. dp->setStrokeFill (getPathFillType (path, strokeType,
  68388. getStyleAttribute (&xml, T("stroke-opacity")),
  68389. getStyleAttribute (&xml, T("opacity")),
  68390. Colours::transparentBlack));
  68391. dp->setStrokeType (getStrokeFor (&xml));
  68392. }
  68393. return dp;
  68394. }
  68395. const XmlElement* findLinkedElement (const XmlElement* e) const
  68396. {
  68397. const String id (e->getStringAttribute (T("xlink:href")));
  68398. if (! id.startsWithChar (T('#')))
  68399. return 0;
  68400. return findElementForId (topLevelXml, id.substring (1));
  68401. }
  68402. void addGradientStopsIn (ColourGradient& cg, const XmlElement* const fillXml) const
  68403. {
  68404. if (fillXml == 0)
  68405. return;
  68406. forEachXmlChildElementWithTagName (*fillXml, e, T("stop"))
  68407. {
  68408. int index = 0;
  68409. Colour col (parseColour (getStyleAttribute (e, T("stop-color")), index, Colours::black));
  68410. const String opacity (getStyleAttribute (e, T("stop-opacity"), T("1")));
  68411. col = col.withMultipliedAlpha (jlimit (0.0f, 1.0f, opacity.getFloatValue()));
  68412. double offset = e->getDoubleAttribute (T("offset"));
  68413. if (e->getStringAttribute (T("offset")).containsChar (T('%')))
  68414. offset *= 0.01;
  68415. cg.addColour (jlimit (0.0, 1.0, offset), col);
  68416. }
  68417. }
  68418. const FillType getPathFillType (const Path& path,
  68419. const String& fill,
  68420. const String& fillOpacity,
  68421. const String& overallOpacity,
  68422. const Colour& defaultColour) const
  68423. {
  68424. float opacity = 1.0f;
  68425. if (overallOpacity.isNotEmpty())
  68426. opacity = jlimit (0.0f, 1.0f, overallOpacity.getFloatValue());
  68427. if (fillOpacity.isNotEmpty())
  68428. opacity *= (jlimit (0.0f, 1.0f, fillOpacity.getFloatValue()));
  68429. if (fill.startsWithIgnoreCase (T("url")))
  68430. {
  68431. const String id (fill.fromFirstOccurrenceOf (T("#"), false, false)
  68432. .upToLastOccurrenceOf (T(")"), false, false).trim());
  68433. const XmlElement* const fillXml = findElementForId (topLevelXml, id);
  68434. if (fillXml != 0
  68435. && (fillXml->hasTagName (T("linearGradient"))
  68436. || fillXml->hasTagName (T("radialGradient"))))
  68437. {
  68438. const XmlElement* inheritedFrom = findLinkedElement (fillXml);
  68439. ColourGradient gradient;
  68440. addGradientStopsIn (gradient, inheritedFrom);
  68441. addGradientStopsIn (gradient, fillXml);
  68442. if (gradient.getNumColours() > 0)
  68443. {
  68444. gradient.addColour (0.0, gradient.getColour (0));
  68445. gradient.addColour (1.0, gradient.getColour (gradient.getNumColours() - 1));
  68446. }
  68447. else
  68448. {
  68449. gradient.addColour (0.0, Colours::black);
  68450. gradient.addColour (1.0, Colours::black);
  68451. }
  68452. if (overallOpacity.isNotEmpty())
  68453. gradient.multiplyOpacity (overallOpacity.getFloatValue());
  68454. jassert (gradient.getNumColours() > 0);
  68455. gradient.isRadial = fillXml->hasTagName (T("radialGradient"));
  68456. float width = viewBoxW;
  68457. float height = viewBoxH;
  68458. float dx = 0.0f;
  68459. float dy = 0.0f;
  68460. const bool userSpace = fillXml->getStringAttribute (T("gradientUnits")).equalsIgnoreCase (T("userSpaceOnUse"));
  68461. if (! userSpace)
  68462. {
  68463. const Rectangle<float> bounds (path.getBounds());
  68464. dx = bounds.getX();
  68465. dy = bounds.getY();
  68466. width = bounds.getWidth();
  68467. height = bounds.getHeight();
  68468. }
  68469. if (gradient.isRadial)
  68470. {
  68471. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("cx"), T("50%")), width);
  68472. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("cy"), T("50%")), height);
  68473. const float radius = getCoordLength (fillXml->getStringAttribute (T("r"), T("50%")), width);
  68474. gradient.x2 = gradient.x1 + radius;
  68475. gradient.y2 = gradient.y1;
  68476. //xxx (the fx, fy focal point isn't handled properly here..)
  68477. }
  68478. else
  68479. {
  68480. gradient.x1 = dx + getCoordLength (fillXml->getStringAttribute (T("x1"), T("0%")), width);
  68481. gradient.y1 = dy + getCoordLength (fillXml->getStringAttribute (T("y1"), T("0%")), height);
  68482. gradient.x2 = dx + getCoordLength (fillXml->getStringAttribute (T("x2"), T("100%")), width);
  68483. gradient.y2 = dy + getCoordLength (fillXml->getStringAttribute (T("y2"), T("0%")), height);
  68484. if (gradient.x1 == gradient.x2 && gradient.y1 == gradient.y2)
  68485. return Colour (gradient.getColour (gradient.getNumColours() - 1));
  68486. }
  68487. FillType type (gradient);
  68488. type.transform = parseTransform (fillXml->getStringAttribute (T("gradientTransform")))
  68489. .followedBy (transform);
  68490. return type;
  68491. }
  68492. }
  68493. if (fill.equalsIgnoreCase (T("none")))
  68494. return Colours::transparentBlack;
  68495. int i = 0;
  68496. const Colour colour (parseColour (fill, i, defaultColour));
  68497. return colour.withMultipliedAlpha (opacity);
  68498. }
  68499. const PathStrokeType getStrokeFor (const XmlElement* const xml) const
  68500. {
  68501. const String width (getStyleAttribute (xml, T("stroke-width")));
  68502. const String cap (getStyleAttribute (xml, T("stroke-linecap")));
  68503. const String join (getStyleAttribute (xml, T("stroke-linejoin")));
  68504. //const String mitreLimit (getStyleAttribute (xml, T("stroke-miterlimit")));
  68505. //const String dashArray (getStyleAttribute (xml, T("stroke-dasharray")));
  68506. //const String dashOffset (getStyleAttribute (xml, T("stroke-dashoffset")));
  68507. PathStrokeType::JointStyle joinStyle = PathStrokeType::mitered;
  68508. PathStrokeType::EndCapStyle capStyle = PathStrokeType::butt;
  68509. if (join.equalsIgnoreCase (T("round")))
  68510. joinStyle = PathStrokeType::curved;
  68511. else if (join.equalsIgnoreCase (T("bevel")))
  68512. joinStyle = PathStrokeType::beveled;
  68513. if (cap.equalsIgnoreCase (T("round")))
  68514. capStyle = PathStrokeType::rounded;
  68515. else if (cap.equalsIgnoreCase (T("square")))
  68516. capStyle = PathStrokeType::square;
  68517. float ox = 0.0f, oy = 0.0f;
  68518. transform.transformPoint (ox, oy);
  68519. float x = getCoordLength (width, viewBoxW), y = 0.0f;
  68520. transform.transformPoint (x, y);
  68521. return PathStrokeType (width.isNotEmpty() ? juce_hypotf (x - ox, y - oy) : 1.0f,
  68522. joinStyle, capStyle);
  68523. }
  68524. Drawable* parseText (const XmlElement& xml)
  68525. {
  68526. Array <float> xCoords, yCoords, dxCoords, dyCoords;
  68527. getCoordList (xCoords, getInheritedAttribute (&xml, T("x")), true, true);
  68528. getCoordList (yCoords, getInheritedAttribute (&xml, T("y")), true, false);
  68529. getCoordList (dxCoords, getInheritedAttribute (&xml, T("dx")), true, true);
  68530. getCoordList (dyCoords, getInheritedAttribute (&xml, T("dy")), true, false);
  68531. //xxx not done text yet!
  68532. forEachXmlChildElement (xml, e)
  68533. {
  68534. if (e->isTextElement())
  68535. {
  68536. const String text (e->getText());
  68537. Path path;
  68538. Drawable* s = parseShape (*e, path);
  68539. delete s;
  68540. }
  68541. else if (e->hasTagName (T("tspan")))
  68542. {
  68543. Drawable* s = parseText (*e);
  68544. delete s;
  68545. }
  68546. }
  68547. return 0;
  68548. }
  68549. void addTransform (const XmlElement& xml)
  68550. {
  68551. transform = parseTransform (xml.getStringAttribute (T("transform")))
  68552. .followedBy (transform);
  68553. }
  68554. bool parseCoord (const String& s, float& value, int& index,
  68555. const bool allowUnits, const bool isX) const
  68556. {
  68557. String number;
  68558. if (! parseNextNumber (s, number, index, allowUnits))
  68559. {
  68560. value = 0;
  68561. return false;
  68562. }
  68563. value = getCoordLength (number, isX ? viewBoxW : viewBoxH);
  68564. return true;
  68565. }
  68566. bool parseCoords (const String& s, float& x, float& y,
  68567. int& index, const bool allowUnits) const
  68568. {
  68569. return parseCoord (s, x, index, allowUnits, true)
  68570. && parseCoord (s, y, index, allowUnits, false);
  68571. }
  68572. float getCoordLength (const String& s, const float sizeForProportions) const
  68573. {
  68574. float n = s.getFloatValue();
  68575. const int len = s.length();
  68576. if (len > 2)
  68577. {
  68578. const float dpi = 96.0f;
  68579. const tchar n1 = s [len - 2];
  68580. const tchar n2 = s [len - 1];
  68581. if (n1 == T('i') && n2 == T('n'))
  68582. n *= dpi;
  68583. else if (n1 == T('m') && n2 == T('m'))
  68584. n *= dpi / 25.4f;
  68585. else if (n1 == T('c') && n2 == T('m'))
  68586. n *= dpi / 2.54f;
  68587. else if (n1 == T('p') && n2 == T('c'))
  68588. n *= 15.0f;
  68589. else if (n2 == T('%'))
  68590. n *= 0.01f * sizeForProportions;
  68591. }
  68592. return n;
  68593. }
  68594. void getCoordList (Array <float>& coords, const String& list,
  68595. const bool allowUnits, const bool isX) const
  68596. {
  68597. int index = 0;
  68598. float value;
  68599. while (parseCoord (list, value, index, allowUnits, isX))
  68600. coords.add (value);
  68601. }
  68602. void parseCSSStyle (const XmlElement& xml)
  68603. {
  68604. cssStyleText = xml.getAllSubText() + T("\n") + cssStyleText;
  68605. }
  68606. const String getStyleAttribute (const XmlElement* xml, const String& attributeName,
  68607. const String& defaultValue = String::empty) const
  68608. {
  68609. if (xml->hasAttribute (attributeName))
  68610. return xml->getStringAttribute (attributeName, defaultValue);
  68611. const String styleAtt (xml->getStringAttribute (T("style")));
  68612. if (styleAtt.isNotEmpty())
  68613. {
  68614. const String value (getAttributeFromStyleList (styleAtt, attributeName, String::empty));
  68615. if (value.isNotEmpty())
  68616. return value;
  68617. }
  68618. else if (xml->hasAttribute (T("class")))
  68619. {
  68620. const String className (T(".") + xml->getStringAttribute (T("class")));
  68621. int index = cssStyleText.indexOfIgnoreCase (className + T(" "));
  68622. if (index < 0)
  68623. index = cssStyleText.indexOfIgnoreCase (className + T("{"));
  68624. if (index >= 0)
  68625. {
  68626. const int openBracket = cssStyleText.indexOfChar (index, T('{'));
  68627. if (openBracket > index)
  68628. {
  68629. const int closeBracket = cssStyleText.indexOfChar (openBracket, T('}'));
  68630. if (closeBracket > openBracket)
  68631. {
  68632. const String value (getAttributeFromStyleList (cssStyleText.substring (openBracket + 1, closeBracket), attributeName, defaultValue));
  68633. if (value.isNotEmpty())
  68634. return value;
  68635. }
  68636. }
  68637. }
  68638. }
  68639. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68640. if (xml != 0)
  68641. return getStyleAttribute (xml, attributeName, defaultValue);
  68642. return defaultValue;
  68643. }
  68644. const String getInheritedAttribute (const XmlElement* xml, const String& attributeName) const
  68645. {
  68646. if (xml->hasAttribute (attributeName))
  68647. return xml->getStringAttribute (attributeName);
  68648. xml = const_cast <XmlElement*> (topLevelXml)->findParentElementOf (xml);
  68649. if (xml != 0)
  68650. return getInheritedAttribute (xml, attributeName);
  68651. return String::empty;
  68652. }
  68653. static bool isIdentifierChar (const tchar c)
  68654. {
  68655. return CharacterFunctions::isLetter (c) || c == T('-');
  68656. }
  68657. static const String getAttributeFromStyleList (const String& list, const String& attributeName, const String& defaultValue)
  68658. {
  68659. int i = 0;
  68660. for (;;)
  68661. {
  68662. i = list.indexOf (i, attributeName);
  68663. if (i < 0)
  68664. break;
  68665. if ((i == 0 || (i > 0 && ! isIdentifierChar (list [i - 1])))
  68666. && ! isIdentifierChar (list [i + attributeName.length()]))
  68667. {
  68668. i = list.indexOfChar (i, T(':'));
  68669. if (i < 0)
  68670. break;
  68671. int end = list.indexOfChar (i, T(';'));
  68672. if (end < 0)
  68673. end = 0x7ffff;
  68674. return list.substring (i + 1, end).trim();
  68675. }
  68676. ++i;
  68677. }
  68678. return defaultValue;
  68679. }
  68680. static bool parseNextNumber (const String& source, String& value, int& index, const bool allowUnits)
  68681. {
  68682. const tchar* const s = (const tchar*) source;
  68683. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68684. ++index;
  68685. int start = index;
  68686. if (CharacterFunctions::isDigit (s[index]) || s[index] == T('.') || s[index] == T('-'))
  68687. ++index;
  68688. while (CharacterFunctions::isDigit (s[index]) || s[index] == T('.'))
  68689. ++index;
  68690. if ((s[index] == T('e') || s[index] == T('E'))
  68691. && (CharacterFunctions::isDigit (s[index + 1])
  68692. || s[index + 1] == T('-')
  68693. || s[index + 1] == T('+')))
  68694. {
  68695. index += 2;
  68696. while (CharacterFunctions::isDigit (s[index]))
  68697. ++index;
  68698. }
  68699. if (allowUnits)
  68700. {
  68701. while (CharacterFunctions::isLetter (s[index]))
  68702. ++index;
  68703. }
  68704. if (index == start)
  68705. return false;
  68706. value = String (s + start, index - start);
  68707. while (CharacterFunctions::isWhitespace (s[index]) || s[index] == T(','))
  68708. ++index;
  68709. return true;
  68710. }
  68711. static const Colour parseColour (const String& s, int& index, const Colour& defaultColour)
  68712. {
  68713. if (s [index] == T('#'))
  68714. {
  68715. uint32 hex [6];
  68716. zeromem (hex, sizeof (hex));
  68717. int numChars = 0;
  68718. for (int i = 6; --i >= 0;)
  68719. {
  68720. const int hexValue = CharacterFunctions::getHexDigitValue (s [++index]);
  68721. if (hexValue >= 0)
  68722. hex [numChars++] = hexValue;
  68723. else
  68724. break;
  68725. }
  68726. if (numChars <= 3)
  68727. return Colour ((uint8) (hex [0] * 0x11),
  68728. (uint8) (hex [1] * 0x11),
  68729. (uint8) (hex [2] * 0x11));
  68730. else
  68731. return Colour ((uint8) ((hex [0] << 4) + hex [1]),
  68732. (uint8) ((hex [2] << 4) + hex [3]),
  68733. (uint8) ((hex [4] << 4) + hex [5]));
  68734. }
  68735. else if (s [index] == T('r')
  68736. && s [index + 1] == T('g')
  68737. && s [index + 2] == T('b'))
  68738. {
  68739. const int openBracket = s.indexOfChar (index, T('('));
  68740. const int closeBracket = s.indexOfChar (openBracket, T(')'));
  68741. if (openBracket >= 3 && closeBracket > openBracket)
  68742. {
  68743. index = closeBracket;
  68744. StringArray tokens;
  68745. tokens.addTokens (s.substring (openBracket + 1, closeBracket), T(","), T(""));
  68746. tokens.trim();
  68747. tokens.removeEmptyStrings();
  68748. if (tokens[0].containsChar (T('%')))
  68749. return Colour ((uint8) roundToInt (2.55 * tokens[0].getDoubleValue()),
  68750. (uint8) roundToInt (2.55 * tokens[1].getDoubleValue()),
  68751. (uint8) roundToInt (2.55 * tokens[2].getDoubleValue()));
  68752. else
  68753. return Colour ((uint8) tokens[0].getIntValue(),
  68754. (uint8) tokens[1].getIntValue(),
  68755. (uint8) tokens[2].getIntValue());
  68756. }
  68757. }
  68758. return Colours::findColourForName (s, defaultColour);
  68759. }
  68760. static const AffineTransform parseTransform (String t)
  68761. {
  68762. AffineTransform result;
  68763. while (t.isNotEmpty())
  68764. {
  68765. StringArray tokens;
  68766. tokens.addTokens (t.fromFirstOccurrenceOf (T("("), false, false)
  68767. .upToFirstOccurrenceOf (T(")"), false, false),
  68768. T(", "), 0);
  68769. tokens.removeEmptyStrings (true);
  68770. float numbers [6];
  68771. for (int i = 0; i < 6; ++i)
  68772. numbers[i] = tokens[i].getFloatValue();
  68773. AffineTransform trans;
  68774. if (t.startsWithIgnoreCase (T("matrix")))
  68775. {
  68776. trans = AffineTransform (numbers[0], numbers[2], numbers[4],
  68777. numbers[1], numbers[3], numbers[5]);
  68778. }
  68779. else if (t.startsWithIgnoreCase (T("translate")))
  68780. {
  68781. jassert (tokens.size() == 2);
  68782. trans = AffineTransform::translation (numbers[0], numbers[1]);
  68783. }
  68784. else if (t.startsWithIgnoreCase (T("scale")))
  68785. {
  68786. if (tokens.size() == 1)
  68787. trans = AffineTransform::scale (numbers[0], numbers[0]);
  68788. else
  68789. trans = AffineTransform::scale (numbers[0], numbers[1]);
  68790. }
  68791. else if (t.startsWithIgnoreCase (T("rotate")))
  68792. {
  68793. if (tokens.size() != 3)
  68794. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi));
  68795. else
  68796. trans = AffineTransform::rotation (numbers[0] / (180.0f / float_Pi),
  68797. numbers[1], numbers[2]);
  68798. }
  68799. else if (t.startsWithIgnoreCase (T("skewX")))
  68800. {
  68801. trans = AffineTransform (1.0f, tanf (numbers[0] * (float_Pi / 180.0f)), 0.0f,
  68802. 0.0f, 1.0f, 0.0f);
  68803. }
  68804. else if (t.startsWithIgnoreCase (T("skewY")))
  68805. {
  68806. trans = AffineTransform (1.0f, 0.0f, 0.0f,
  68807. tanf (numbers[0] * (float_Pi / 180.0f)), 1.0f, 0.0f);
  68808. }
  68809. result = trans.followedBy (result);
  68810. t = t.fromFirstOccurrenceOf (T(")"), false, false).trimStart();
  68811. }
  68812. return result;
  68813. }
  68814. static void endpointToCentreParameters (const double x1, const double y1,
  68815. const double x2, const double y2,
  68816. const double angle,
  68817. const bool largeArc, const bool sweep,
  68818. double& rx, double& ry,
  68819. double& centreX, double& centreY,
  68820. double& startAngle, double& deltaAngle)
  68821. {
  68822. const double midX = (x1 - x2) * 0.5;
  68823. const double midY = (y1 - y2) * 0.5;
  68824. const double cosAngle = cos (angle);
  68825. const double sinAngle = sin (angle);
  68826. const double xp = cosAngle * midX + sinAngle * midY;
  68827. const double yp = cosAngle * midY - sinAngle * midX;
  68828. const double xp2 = xp * xp;
  68829. const double yp2 = yp * yp;
  68830. double rx2 = rx * rx;
  68831. double ry2 = ry * ry;
  68832. const double s = (xp2 / rx2) + (yp2 / ry2);
  68833. double c;
  68834. if (s <= 1.0)
  68835. {
  68836. c = sqrt (jmax (0.0, ((rx2 * ry2) - (rx2 * yp2) - (ry2 * xp2))
  68837. / (( rx2 * yp2) + (ry2 * xp2))));
  68838. if (largeArc == sweep)
  68839. c = -c;
  68840. }
  68841. else
  68842. {
  68843. const double s2 = sqrt (s);
  68844. rx *= s2;
  68845. ry *= s2;
  68846. rx2 = rx * rx;
  68847. ry2 = ry * ry;
  68848. c = 0;
  68849. }
  68850. const double cpx = ((rx * yp) / ry) * c;
  68851. const double cpy = ((-ry * xp) / rx) * c;
  68852. centreX = ((x1 + x2) * 0.5) + (cosAngle * cpx) - (sinAngle * cpy);
  68853. centreY = ((y1 + y2) * 0.5) + (sinAngle * cpx) + (cosAngle * cpy);
  68854. const double ux = (xp - cpx) / rx;
  68855. const double uy = (yp - cpy) / ry;
  68856. const double vx = (-xp - cpx) / rx;
  68857. const double vy = (-yp - cpy) / ry;
  68858. const double length = juce_hypot (ux, uy);
  68859. startAngle = acos (jlimit (-1.0, 1.0, ux / length));
  68860. if (uy < 0)
  68861. startAngle = -startAngle;
  68862. startAngle += double_Pi * 0.5;
  68863. deltaAngle = acos (jlimit (-1.0, 1.0, ((ux * vx) + (uy * vy))
  68864. / (length * juce_hypot (vx, vy))));
  68865. if ((ux * vy) - (uy * vx) < 0)
  68866. deltaAngle = -deltaAngle;
  68867. if (sweep)
  68868. {
  68869. if (deltaAngle < 0)
  68870. deltaAngle += double_Pi * 2.0;
  68871. }
  68872. else
  68873. {
  68874. if (deltaAngle > 0)
  68875. deltaAngle -= double_Pi * 2.0;
  68876. }
  68877. deltaAngle = fmod (deltaAngle, double_Pi * 2.0);
  68878. }
  68879. static const XmlElement* findElementForId (const XmlElement* const parent, const String& id)
  68880. {
  68881. forEachXmlChildElement (*parent, e)
  68882. {
  68883. if (e->compareAttribute (T("id"), id))
  68884. return e;
  68885. const XmlElement* const found = findElementForId (e, id);
  68886. if (found != 0)
  68887. return found;
  68888. }
  68889. return 0;
  68890. }
  68891. SVGState& operator= (const SVGState&);
  68892. };
  68893. Drawable* Drawable::createFromSVG (const XmlElement& svgDocument)
  68894. {
  68895. SVGState state (&svgDocument);
  68896. return state.parseSVGElement (svgDocument);
  68897. }
  68898. END_JUCE_NAMESPACE
  68899. /*** End of inlined file: juce_SVGParser.cpp ***/
  68900. /*** Start of inlined file: juce_DropShadowEffect.cpp ***/
  68901. BEGIN_JUCE_NAMESPACE
  68902. #if JUCE_MSVC
  68903. #pragma optimize ("t", on) // try to avoid slowing everything down in debug builds
  68904. #endif
  68905. DropShadowEffect::DropShadowEffect()
  68906. : offsetX (0),
  68907. offsetY (0),
  68908. radius (4),
  68909. opacity (0.6f)
  68910. {
  68911. }
  68912. DropShadowEffect::~DropShadowEffect()
  68913. {
  68914. }
  68915. void DropShadowEffect::setShadowProperties (const float newRadius,
  68916. const float newOpacity,
  68917. const int newShadowOffsetX,
  68918. const int newShadowOffsetY)
  68919. {
  68920. radius = jmax (1.1f, newRadius);
  68921. offsetX = newShadowOffsetX;
  68922. offsetY = newShadowOffsetY;
  68923. opacity = newOpacity;
  68924. }
  68925. void DropShadowEffect::applyEffect (Image& image, Graphics& g)
  68926. {
  68927. const int w = image.getWidth();
  68928. const int h = image.getHeight();
  68929. Image shadowImage (Image::SingleChannel, w, h, false);
  68930. const Image::BitmapData srcData (image, 0, 0, w, h);
  68931. const Image::BitmapData destData (shadowImage, 0, 0, w, h, true);
  68932. const int filter = roundToInt (63.0f / radius);
  68933. const int radiusMinus1 = roundToInt ((radius - 1.0f) * 63.0f);
  68934. for (int x = w; --x >= 0;)
  68935. {
  68936. int shadowAlpha = 0;
  68937. const PixelARGB* src = ((const PixelARGB*) srcData.data) + x;
  68938. uint8* shadowPix = destData.data + x;
  68939. for (int y = h; --y >= 0;)
  68940. {
  68941. shadowAlpha = ((shadowAlpha * radiusMinus1 + (src->getAlpha() << 6)) * filter) >> 12;
  68942. *shadowPix = (uint8) shadowAlpha;
  68943. src = (const PixelARGB*) (((const uint8*) src) + srcData.lineStride);
  68944. shadowPix += destData.lineStride;
  68945. }
  68946. }
  68947. for (int y = h; --y >= 0;)
  68948. {
  68949. int shadowAlpha = 0;
  68950. uint8* shadowPix = destData.getLinePointer (y);
  68951. for (int x = w; --x >= 0;)
  68952. {
  68953. shadowAlpha = ((shadowAlpha * radiusMinus1 + (*shadowPix << 6)) * filter) >> 12;
  68954. *shadowPix++ = (uint8) shadowAlpha;
  68955. }
  68956. }
  68957. g.setColour (Colours::black.withAlpha (opacity));
  68958. g.drawImageAt (&shadowImage, offsetX, offsetY, true);
  68959. g.setOpacity (1.0f);
  68960. g.drawImageAt (&image, 0, 0);
  68961. }
  68962. END_JUCE_NAMESPACE
  68963. /*** End of inlined file: juce_DropShadowEffect.cpp ***/
  68964. /*** Start of inlined file: juce_GlowEffect.cpp ***/
  68965. BEGIN_JUCE_NAMESPACE
  68966. GlowEffect::GlowEffect()
  68967. : radius (2.0f),
  68968. colour (Colours::white)
  68969. {
  68970. }
  68971. GlowEffect::~GlowEffect()
  68972. {
  68973. }
  68974. void GlowEffect::setGlowProperties (const float newRadius,
  68975. const Colour& newColour)
  68976. {
  68977. radius = newRadius;
  68978. colour = newColour;
  68979. }
  68980. void GlowEffect::applyEffect (Image& image, Graphics& g)
  68981. {
  68982. const int w = image.getWidth();
  68983. const int h = image.getHeight();
  68984. Image temp (image.getFormat(), w, h, true);
  68985. ImageConvolutionKernel blurKernel (roundToInt (radius * 2.0f));
  68986. blurKernel.createGaussianBlur (radius);
  68987. blurKernel.rescaleAllValues (radius);
  68988. blurKernel.applyToImage (temp, &image, 0, 0, w, h);
  68989. g.setColour (colour);
  68990. g.drawImageAt (&temp, 0, 0, true);
  68991. g.setOpacity (1.0f);
  68992. g.drawImageAt (&image, 0, 0, false);
  68993. }
  68994. END_JUCE_NAMESPACE
  68995. /*** End of inlined file: juce_GlowEffect.cpp ***/
  68996. /*** Start of inlined file: juce_ReduceOpacityEffect.cpp ***/
  68997. BEGIN_JUCE_NAMESPACE
  68998. ReduceOpacityEffect::ReduceOpacityEffect (const float opacity_)
  68999. : opacity (opacity_)
  69000. {
  69001. }
  69002. ReduceOpacityEffect::~ReduceOpacityEffect()
  69003. {
  69004. }
  69005. void ReduceOpacityEffect::setOpacity (const float newOpacity)
  69006. {
  69007. opacity = jlimit (0.0f, 1.0f, newOpacity);
  69008. }
  69009. void ReduceOpacityEffect::applyEffect (Image& image, Graphics& g)
  69010. {
  69011. g.setOpacity (opacity);
  69012. g.drawImageAt (&image, 0, 0);
  69013. }
  69014. END_JUCE_NAMESPACE
  69015. /*** End of inlined file: juce_ReduceOpacityEffect.cpp ***/
  69016. /*** Start of inlined file: juce_Font.cpp ***/
  69017. BEGIN_JUCE_NAMESPACE
  69018. static const float minFontHeight = 0.1f;
  69019. static const float maxFontHeight = 10000.0f;
  69020. static const float defaultFontHeight = 14.0f;
  69021. static const tchar* const juce_defaultFontNameSans = T("<Sans-Serif>");
  69022. static const tchar* const juce_defaultFontNameSerif = T("<Serif>");
  69023. static const tchar* const juce_defaultFontNameMono = T("<Monospaced>");
  69024. void clearUpDefaultFontNames() throw(); // in juce_LookAndFeel.cpp
  69025. Font::SharedFontInternal::SharedFontInternal (const String& typefaceName_, const float height_, const float horizontalScale_,
  69026. const float kerning_, const float ascent_, const int styleFlags_,
  69027. Typeface* const typeface_) throw()
  69028. : typefaceName (typefaceName_),
  69029. height (height_),
  69030. horizontalScale (horizontalScale_),
  69031. kerning (kerning_),
  69032. ascent (ascent_),
  69033. styleFlags (styleFlags_),
  69034. typeface (typeface_)
  69035. {
  69036. }
  69037. Font::SharedFontInternal::SharedFontInternal (const SharedFontInternal& other) throw()
  69038. : typefaceName (other.typefaceName),
  69039. height (other.height),
  69040. horizontalScale (other.horizontalScale),
  69041. kerning (other.kerning),
  69042. ascent (other.ascent),
  69043. styleFlags (other.styleFlags),
  69044. typeface (other.typeface)
  69045. {
  69046. }
  69047. Font::Font() throw()
  69048. : font (new SharedFontInternal (juce_defaultFontNameSans, defaultFontHeight,
  69049. 1.0f, 0, 0, Font::plain, 0))
  69050. {
  69051. }
  69052. Font::Font (const float fontHeight, const int styleFlags_) throw()
  69053. : font (new SharedFontInternal (juce_defaultFontNameSans, jlimit (minFontHeight, maxFontHeight, fontHeight),
  69054. 1.0f, 0, 0, styleFlags_, 0))
  69055. {
  69056. }
  69057. Font::Font (const String& typefaceName_,
  69058. const float fontHeight,
  69059. const int styleFlags_) throw()
  69060. : font (new SharedFontInternal (typefaceName_, jlimit (minFontHeight, maxFontHeight, fontHeight),
  69061. 1.0f, 0, 0, styleFlags_, 0))
  69062. {
  69063. }
  69064. Font::Font (const Font& other) throw()
  69065. : font (other.font)
  69066. {
  69067. }
  69068. Font& Font::operator= (const Font& other) throw()
  69069. {
  69070. font = other.font;
  69071. return *this;
  69072. }
  69073. Font::~Font() throw()
  69074. {
  69075. }
  69076. Font::Font (const Typeface::Ptr& typeface) throw()
  69077. : font (new SharedFontInternal (typeface->getName(), defaultFontHeight,
  69078. 1.0f, 0, 0, Font::plain, typeface))
  69079. {
  69080. }
  69081. bool Font::operator== (const Font& other) const throw()
  69082. {
  69083. return font == other.font
  69084. || (font->height == other.font->height
  69085. && font->styleFlags == other.font->styleFlags
  69086. && font->horizontalScale == other.font->horizontalScale
  69087. && font->kerning == other.font->kerning
  69088. && font->typefaceName == other.font->typefaceName);
  69089. }
  69090. bool Font::operator!= (const Font& other) const throw()
  69091. {
  69092. return ! operator== (other);
  69093. }
  69094. void Font::dupeInternalIfShared() throw()
  69095. {
  69096. if (font->getReferenceCount() > 1)
  69097. font = new SharedFontInternal (*font);
  69098. }
  69099. const String Font::getDefaultSansSerifFontName() throw()
  69100. {
  69101. return juce_defaultFontNameSans;
  69102. }
  69103. const String Font::getDefaultSerifFontName() throw()
  69104. {
  69105. return juce_defaultFontNameSerif;
  69106. }
  69107. const String Font::getDefaultMonospacedFontName() throw()
  69108. {
  69109. return juce_defaultFontNameMono;
  69110. }
  69111. void Font::setTypefaceName (const String& faceName) throw()
  69112. {
  69113. if (faceName != font->typefaceName)
  69114. {
  69115. dupeInternalIfShared();
  69116. font->typefaceName = faceName;
  69117. font->typeface = 0;
  69118. font->ascent = 0;
  69119. }
  69120. }
  69121. static String fallbackFont;
  69122. const String Font::getFallbackFontName() throw()
  69123. {
  69124. return fallbackFont;
  69125. }
  69126. void Font::setFallbackFontName (const String& name) throw()
  69127. {
  69128. fallbackFont = name;
  69129. }
  69130. void Font::setHeight (float newHeight) throw()
  69131. {
  69132. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69133. if (font->height != newHeight)
  69134. {
  69135. dupeInternalIfShared();
  69136. font->height = newHeight;
  69137. }
  69138. }
  69139. void Font::setHeightWithoutChangingWidth (float newHeight) throw()
  69140. {
  69141. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69142. if (font->height != newHeight)
  69143. {
  69144. dupeInternalIfShared();
  69145. font->horizontalScale *= (font->height / newHeight);
  69146. font->height = newHeight;
  69147. }
  69148. }
  69149. void Font::setStyleFlags (const int newFlags) throw()
  69150. {
  69151. if (font->styleFlags != newFlags)
  69152. {
  69153. dupeInternalIfShared();
  69154. font->styleFlags = newFlags;
  69155. font->typeface = 0;
  69156. font->ascent = 0;
  69157. }
  69158. }
  69159. void Font::setSizeAndStyle (float newHeight,
  69160. const int newStyleFlags,
  69161. const float newHorizontalScale,
  69162. const float newKerningAmount) throw()
  69163. {
  69164. newHeight = jlimit (minFontHeight, maxFontHeight, newHeight);
  69165. if (font->height != newHeight
  69166. || font->horizontalScale != newHorizontalScale
  69167. || font->kerning != newKerningAmount)
  69168. {
  69169. dupeInternalIfShared();
  69170. font->height = newHeight;
  69171. font->horizontalScale = newHorizontalScale;
  69172. font->kerning = newKerningAmount;
  69173. }
  69174. setStyleFlags (newStyleFlags);
  69175. }
  69176. void Font::setHorizontalScale (const float scaleFactor) throw()
  69177. {
  69178. dupeInternalIfShared();
  69179. font->horizontalScale = scaleFactor;
  69180. }
  69181. void Font::setExtraKerningFactor (const float extraKerning) throw()
  69182. {
  69183. dupeInternalIfShared();
  69184. font->kerning = extraKerning;
  69185. }
  69186. void Font::setBold (const bool shouldBeBold) throw()
  69187. {
  69188. setStyleFlags (shouldBeBold ? (font->styleFlags | bold)
  69189. : (font->styleFlags & ~bold));
  69190. }
  69191. bool Font::isBold() const throw()
  69192. {
  69193. return (font->styleFlags & bold) != 0;
  69194. }
  69195. void Font::setItalic (const bool shouldBeItalic) throw()
  69196. {
  69197. setStyleFlags (shouldBeItalic ? (font->styleFlags | italic)
  69198. : (font->styleFlags & ~italic));
  69199. }
  69200. bool Font::isItalic() const throw()
  69201. {
  69202. return (font->styleFlags & italic) != 0;
  69203. }
  69204. void Font::setUnderline (const bool shouldBeUnderlined) throw()
  69205. {
  69206. setStyleFlags (shouldBeUnderlined ? (font->styleFlags | underlined)
  69207. : (font->styleFlags & ~underlined));
  69208. }
  69209. bool Font::isUnderlined() const throw()
  69210. {
  69211. return (font->styleFlags & underlined) != 0;
  69212. }
  69213. float Font::getAscent() const throw()
  69214. {
  69215. if (font->ascent == 0)
  69216. font->ascent = getTypeface()->getAscent();
  69217. return font->height * font->ascent;
  69218. }
  69219. float Font::getDescent() const throw()
  69220. {
  69221. return font->height - getAscent();
  69222. }
  69223. int Font::getStringWidth (const String& text) const throw()
  69224. {
  69225. return roundToInt (getStringWidthFloat (text));
  69226. }
  69227. float Font::getStringWidthFloat (const String& text) const throw()
  69228. {
  69229. float w = getTypeface()->getStringWidth (text);
  69230. if (font->kerning != 0)
  69231. w += font->kerning * text.length();
  69232. return w * font->height * font->horizontalScale;
  69233. }
  69234. void Font::getGlyphPositions (const String& text, Array <int>& glyphs, Array <float>& xOffsets) const throw()
  69235. {
  69236. getTypeface()->getGlyphPositions (text, glyphs, xOffsets);
  69237. const float scale = font->height * font->horizontalScale;
  69238. const int num = xOffsets.size();
  69239. if (num > 0)
  69240. {
  69241. float* const x = &(xOffsets.getReference(0));
  69242. if (font->kerning != 0)
  69243. {
  69244. for (int i = 0; i < num; ++i)
  69245. x[i] = (x[i] + i * font->kerning) * scale;
  69246. }
  69247. else
  69248. {
  69249. for (int i = 0; i < num; ++i)
  69250. x[i] *= scale;
  69251. }
  69252. }
  69253. }
  69254. void Font::findFonts (Array<Font>& destArray) throw()
  69255. {
  69256. const StringArray names (findAllTypefaceNames());
  69257. for (int i = 0; i < names.size(); ++i)
  69258. destArray.add (Font (names[i], defaultFontHeight, Font::plain));
  69259. }
  69260. class TypefaceCache : public DeletedAtShutdown
  69261. {
  69262. public:
  69263. TypefaceCache (int numToCache = 10) throw()
  69264. : counter (1)
  69265. {
  69266. while (--numToCache >= 0)
  69267. faces.add (new CachedFace());
  69268. }
  69269. ~TypefaceCache()
  69270. {
  69271. clearUpDefaultFontNames();
  69272. clearSingletonInstance();
  69273. }
  69274. juce_DeclareSingleton_SingleThreaded_Minimal (TypefaceCache)
  69275. const Typeface::Ptr findTypefaceFor (const Font& font) throw()
  69276. {
  69277. const int flags = font.getStyleFlags() & (Font::bold | Font::italic);
  69278. const String faceName (font.getTypefaceName());
  69279. int i;
  69280. for (i = faces.size(); --i >= 0;)
  69281. {
  69282. CachedFace* const face = faces.getUnchecked(i);
  69283. if (face->flags == flags
  69284. && face->typefaceName == faceName)
  69285. {
  69286. face->lastUsageCount = ++counter;
  69287. return face->typeFace;
  69288. }
  69289. }
  69290. int replaceIndex = 0;
  69291. int bestLastUsageCount = std::numeric_limits<int>::max();
  69292. for (i = faces.size(); --i >= 0;)
  69293. {
  69294. const int lu = faces.getUnchecked(i)->lastUsageCount;
  69295. if (bestLastUsageCount > lu)
  69296. {
  69297. bestLastUsageCount = lu;
  69298. replaceIndex = i;
  69299. }
  69300. }
  69301. CachedFace* const face = faces.getUnchecked (replaceIndex);
  69302. face->typefaceName = faceName;
  69303. face->flags = flags;
  69304. face->lastUsageCount = ++counter;
  69305. face->typeFace = LookAndFeel::getDefaultLookAndFeel().getTypefaceForFont (font);
  69306. jassert (face->typeFace != 0); // the look and feel must return a typeface!
  69307. return face->typeFace;
  69308. }
  69309. juce_UseDebuggingNewOperator
  69310. private:
  69311. struct CachedFace
  69312. {
  69313. CachedFace() throw()
  69314. : lastUsageCount (0), flags (-1)
  69315. {
  69316. }
  69317. String typefaceName;
  69318. int lastUsageCount;
  69319. int flags;
  69320. Typeface::Ptr typeFace;
  69321. };
  69322. int counter;
  69323. OwnedArray <CachedFace> faces;
  69324. TypefaceCache (const TypefaceCache&);
  69325. TypefaceCache& operator= (const TypefaceCache&);
  69326. };
  69327. juce_ImplementSingleton_SingleThreaded (TypefaceCache)
  69328. Typeface* Font::getTypeface() const throw()
  69329. {
  69330. if (font->typeface == 0)
  69331. font->typeface = TypefaceCache::getInstance()->findTypefaceFor (*this);
  69332. return font->typeface;
  69333. }
  69334. END_JUCE_NAMESPACE
  69335. /*** End of inlined file: juce_Font.cpp ***/
  69336. /*** Start of inlined file: juce_GlyphArrangement.cpp ***/
  69337. BEGIN_JUCE_NAMESPACE
  69338. PositionedGlyph::PositionedGlyph()
  69339. {
  69340. }
  69341. void PositionedGlyph::draw (const Graphics& g) const
  69342. {
  69343. if (! isWhitespace())
  69344. {
  69345. g.getInternalContext()->setFont (font);
  69346. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y));
  69347. }
  69348. }
  69349. void PositionedGlyph::draw (const Graphics& g,
  69350. const AffineTransform& transform) const
  69351. {
  69352. if (! isWhitespace())
  69353. {
  69354. g.getInternalContext()->setFont (font);
  69355. g.getInternalContext()->drawGlyph (glyph, AffineTransform::translation (x, y)
  69356. .followedBy (transform));
  69357. }
  69358. }
  69359. void PositionedGlyph::createPath (Path& path) const
  69360. {
  69361. if (! isWhitespace())
  69362. {
  69363. Typeface* const t = font.getTypeface();
  69364. if (t != 0)
  69365. {
  69366. Path p;
  69367. t->getOutlineForGlyph (glyph, p);
  69368. path.addPath (p, AffineTransform::scale (font.getHeight() * font.getHorizontalScale(), font.getHeight())
  69369. .translated (x, y));
  69370. }
  69371. }
  69372. }
  69373. bool PositionedGlyph::hitTest (float px, float py) const
  69374. {
  69375. if (px >= getLeft() && px < getRight()
  69376. && py >= getTop() && py < getBottom()
  69377. && ! isWhitespace())
  69378. {
  69379. Typeface* const t = font.getTypeface();
  69380. if (t != 0)
  69381. {
  69382. Path p;
  69383. t->getOutlineForGlyph (glyph, p);
  69384. AffineTransform::translation (-x, -y)
  69385. .scaled (1.0f / (font.getHeight() * font.getHorizontalScale()), 1.0f / font.getHeight())
  69386. .transformPoint (px, py);
  69387. return p.contains (px, py);
  69388. }
  69389. }
  69390. return false;
  69391. }
  69392. void PositionedGlyph::moveBy (const float deltaX,
  69393. const float deltaY)
  69394. {
  69395. x += deltaX;
  69396. y += deltaY;
  69397. }
  69398. GlyphArrangement::GlyphArrangement()
  69399. {
  69400. glyphs.ensureStorageAllocated (128);
  69401. }
  69402. GlyphArrangement::GlyphArrangement (const GlyphArrangement& other)
  69403. {
  69404. addGlyphArrangement (other);
  69405. }
  69406. GlyphArrangement& GlyphArrangement::operator= (const GlyphArrangement& other)
  69407. {
  69408. if (this != &other)
  69409. {
  69410. clear();
  69411. addGlyphArrangement (other);
  69412. }
  69413. return *this;
  69414. }
  69415. GlyphArrangement::~GlyphArrangement()
  69416. {
  69417. }
  69418. void GlyphArrangement::clear()
  69419. {
  69420. glyphs.clear();
  69421. }
  69422. PositionedGlyph& GlyphArrangement::getGlyph (const int index) const
  69423. {
  69424. jassert (((unsigned int) index) < (unsigned int) glyphs.size());
  69425. return *glyphs [index];
  69426. }
  69427. void GlyphArrangement::addGlyphArrangement (const GlyphArrangement& other)
  69428. {
  69429. glyphs.ensureStorageAllocated (glyphs.size() + other.glyphs.size());
  69430. for (int i = 0; i < other.glyphs.size(); ++i)
  69431. glyphs.add (new PositionedGlyph (*other.glyphs.getUnchecked (i)));
  69432. }
  69433. void GlyphArrangement::removeRangeOfGlyphs (int startIndex, const int num)
  69434. {
  69435. glyphs.removeRange (startIndex, num < 0 ? glyphs.size() : num);
  69436. }
  69437. void GlyphArrangement::addLineOfText (const Font& font,
  69438. const String& text,
  69439. const float xOffset,
  69440. const float yOffset)
  69441. {
  69442. addCurtailedLineOfText (font, text,
  69443. xOffset, yOffset,
  69444. 1.0e10f, false);
  69445. }
  69446. void GlyphArrangement::addCurtailedLineOfText (const Font& font,
  69447. const String& text,
  69448. float xOffset,
  69449. const float yOffset,
  69450. const float maxWidthPixels,
  69451. const bool useEllipsis)
  69452. {
  69453. int textLen = text.length();
  69454. if (textLen > 0)
  69455. {
  69456. Array <int> newGlyphs;
  69457. Array <float> xOffsets;
  69458. font.getGlyphPositions (text, newGlyphs, xOffsets);
  69459. const juce_wchar* const unicodeText = (const juce_wchar*) text;
  69460. textLen = jmin (textLen, newGlyphs.size());
  69461. for (int i = 0; i < textLen; ++i)
  69462. {
  69463. const float thisX = xOffsets.getUnchecked (i);
  69464. const float nextX = xOffsets.getUnchecked (i + 1);
  69465. if (nextX > maxWidthPixels + 1.0f)
  69466. {
  69467. // curtail the string if it's too wide..
  69468. if (useEllipsis && textLen > 3 && glyphs.size() >= 3)
  69469. insertEllipsis (font, xOffset + maxWidthPixels, 0, glyphs.size());
  69470. break;
  69471. }
  69472. else
  69473. {
  69474. PositionedGlyph* const pg = new PositionedGlyph();
  69475. pg->x = xOffset + thisX;
  69476. pg->y = yOffset;
  69477. pg->w = nextX - thisX;
  69478. pg->font = font;
  69479. pg->glyph = newGlyphs.getUnchecked(i);
  69480. pg->character = unicodeText[i];
  69481. glyphs.add (pg);
  69482. }
  69483. }
  69484. }
  69485. }
  69486. int GlyphArrangement::insertEllipsis (const Font& font, const float maxXPos,
  69487. const int startIndex, int endIndex)
  69488. {
  69489. int numDeleted = 0;
  69490. if (glyphs.size() > 0)
  69491. {
  69492. Array<int> dotGlyphs;
  69493. Array<float> dotXs;
  69494. font.getGlyphPositions (T(".."), dotGlyphs, dotXs);
  69495. const float dx = dotXs[1];
  69496. float xOffset = 0.0f, yOffset = 0.0f;
  69497. while (endIndex > startIndex)
  69498. {
  69499. const PositionedGlyph* pg = glyphs.getUnchecked (--endIndex);
  69500. xOffset = pg->x;
  69501. yOffset = pg->y;
  69502. glyphs.remove (endIndex);
  69503. ++numDeleted;
  69504. if (xOffset + dx * 3 <= maxXPos)
  69505. break;
  69506. }
  69507. for (int i = 3; --i >= 0;)
  69508. {
  69509. PositionedGlyph* const pg = new PositionedGlyph();
  69510. pg->x = xOffset;
  69511. pg->y = yOffset;
  69512. pg->w = dx;
  69513. pg->font = font;
  69514. pg->character = '.';
  69515. pg->glyph = dotGlyphs.getFirst();
  69516. glyphs.insert (endIndex++, pg);
  69517. --numDeleted;
  69518. xOffset += dx;
  69519. if (xOffset > maxXPos)
  69520. break;
  69521. }
  69522. }
  69523. return numDeleted;
  69524. }
  69525. void GlyphArrangement::addJustifiedText (const Font& font,
  69526. const String& text,
  69527. float x, float y,
  69528. const float maxLineWidth,
  69529. const Justification& horizontalLayout)
  69530. {
  69531. int lineStartIndex = glyphs.size();
  69532. addLineOfText (font, text, x, y);
  69533. const float originalY = y;
  69534. while (lineStartIndex < glyphs.size())
  69535. {
  69536. int i = lineStartIndex;
  69537. if (glyphs.getUnchecked(i)->getCharacter() != T('\n')
  69538. && glyphs.getUnchecked(i)->getCharacter() != T('\r'))
  69539. ++i;
  69540. const float lineMaxX = glyphs.getUnchecked (lineStartIndex)->getLeft() + maxLineWidth;
  69541. int lastWordBreakIndex = -1;
  69542. while (i < glyphs.size())
  69543. {
  69544. const PositionedGlyph* pg = glyphs.getUnchecked (i);
  69545. const juce_wchar c = pg->getCharacter();
  69546. if (c == T('\r') || c == T('\n'))
  69547. {
  69548. ++i;
  69549. if (c == T('\r') && i < glyphs.size()
  69550. && glyphs.getUnchecked(i)->getCharacter() == T('\n'))
  69551. ++i;
  69552. break;
  69553. }
  69554. else if (pg->isWhitespace())
  69555. {
  69556. lastWordBreakIndex = i + 1;
  69557. }
  69558. else if (pg->getRight() - 0.0001f >= lineMaxX)
  69559. {
  69560. if (lastWordBreakIndex >= 0)
  69561. i = lastWordBreakIndex;
  69562. break;
  69563. }
  69564. ++i;
  69565. }
  69566. const float currentLineStartX = glyphs.getUnchecked (lineStartIndex)->getLeft();
  69567. float currentLineEndX = currentLineStartX;
  69568. for (int j = i; --j >= lineStartIndex;)
  69569. {
  69570. if (! glyphs.getUnchecked (j)->isWhitespace())
  69571. {
  69572. currentLineEndX = glyphs.getUnchecked (j)->getRight();
  69573. break;
  69574. }
  69575. }
  69576. float deltaX = 0.0f;
  69577. if (horizontalLayout.testFlags (Justification::horizontallyJustified))
  69578. spreadOutLine (lineStartIndex, i - lineStartIndex, maxLineWidth);
  69579. else if (horizontalLayout.testFlags (Justification::horizontallyCentred))
  69580. deltaX = (maxLineWidth - (currentLineEndX - currentLineStartX)) * 0.5f;
  69581. else if (horizontalLayout.testFlags (Justification::right))
  69582. deltaX = maxLineWidth - (currentLineEndX - currentLineStartX);
  69583. moveRangeOfGlyphs (lineStartIndex, i - lineStartIndex,
  69584. x + deltaX - currentLineStartX, y - originalY);
  69585. lineStartIndex = i;
  69586. y += font.getHeight();
  69587. }
  69588. }
  69589. void GlyphArrangement::addFittedText (const Font& f,
  69590. const String& text,
  69591. const float x, const float y,
  69592. const float width, const float height,
  69593. const Justification& layout,
  69594. int maximumLines,
  69595. const float minimumHorizontalScale)
  69596. {
  69597. // doesn't make much sense if this is outside a sensible range of 0.5 to 1.0
  69598. jassert (minimumHorizontalScale > 0 && minimumHorizontalScale <= 1.0f);
  69599. if (text.containsAnyOf (T("\r\n")))
  69600. {
  69601. GlyphArrangement ga;
  69602. ga.addJustifiedText (f, text, x, y, width, layout);
  69603. float l, t, r, b;
  69604. ga.getBoundingBox (0, -1, l, t, r, b, false);
  69605. float dy = y - t;
  69606. if (layout.testFlags (Justification::verticallyCentred))
  69607. dy += (height - (b - t)) * 0.5f;
  69608. else if (layout.testFlags (Justification::bottom))
  69609. dy += height - (b - t);
  69610. ga.moveRangeOfGlyphs (0, -1, 0.0f, dy);
  69611. glyphs.ensureStorageAllocated (glyphs.size() + ga.glyphs.size());
  69612. for (int i = 0; i < ga.glyphs.size(); ++i)
  69613. glyphs.add (ga.glyphs.getUnchecked (i));
  69614. ga.glyphs.clear (false);
  69615. return;
  69616. }
  69617. int startIndex = glyphs.size();
  69618. addLineOfText (f, text.trim(), x, y);
  69619. if (glyphs.size() > startIndex)
  69620. {
  69621. float lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69622. - glyphs.getUnchecked (startIndex)->getLeft();
  69623. if (lineWidth <= 0)
  69624. return;
  69625. if (lineWidth * minimumHorizontalScale < width)
  69626. {
  69627. if (lineWidth > width)
  69628. stretchRangeOfGlyphs (startIndex, glyphs.size() - startIndex,
  69629. width / lineWidth);
  69630. justifyGlyphs (startIndex, glyphs.size() - startIndex,
  69631. x, y, width, height, layout);
  69632. }
  69633. else if (maximumLines <= 1)
  69634. {
  69635. fitLineIntoSpace (startIndex, glyphs.size() - startIndex,
  69636. x, y, width, height, f, layout, minimumHorizontalScale);
  69637. }
  69638. else
  69639. {
  69640. Font font (f);
  69641. String txt (text.trim());
  69642. const int length = txt.length();
  69643. const int originalStartIndex = startIndex;
  69644. int numLines = 1;
  69645. if (length <= 12 && ! txt.containsAnyOf (T(" -\t\r\n")))
  69646. maximumLines = 1;
  69647. maximumLines = jmin (maximumLines, length);
  69648. while (numLines < maximumLines)
  69649. {
  69650. ++numLines;
  69651. const float newFontHeight = height / (float) numLines;
  69652. if (newFontHeight < font.getHeight())
  69653. {
  69654. font.setHeight (jmax (8.0f, newFontHeight));
  69655. removeRangeOfGlyphs (startIndex, -1);
  69656. addLineOfText (font, txt, x, y);
  69657. lineWidth = glyphs.getUnchecked (glyphs.size() - 1)->getRight()
  69658. - glyphs.getUnchecked (startIndex)->getLeft();
  69659. }
  69660. if (numLines > lineWidth / width || newFontHeight < 8.0f)
  69661. break;
  69662. }
  69663. if (numLines < 1)
  69664. numLines = 1;
  69665. float lineY = y;
  69666. float widthPerLine = lineWidth / numLines;
  69667. int lastLineStartIndex = 0;
  69668. for (int line = 0; line < numLines; ++line)
  69669. {
  69670. int i = startIndex;
  69671. lastLineStartIndex = i;
  69672. float lineStartX = glyphs.getUnchecked (startIndex)->getLeft();
  69673. if (line == numLines - 1)
  69674. {
  69675. widthPerLine = width;
  69676. i = glyphs.size();
  69677. }
  69678. else
  69679. {
  69680. while (i < glyphs.size())
  69681. {
  69682. lineWidth = (glyphs.getUnchecked (i)->getRight() - lineStartX);
  69683. if (lineWidth > widthPerLine)
  69684. {
  69685. // got to a point where the line's too long, so skip forward to find a
  69686. // good place to break it..
  69687. const int searchStartIndex = i;
  69688. while (i < glyphs.size())
  69689. {
  69690. if ((glyphs.getUnchecked (i)->getRight() - lineStartX) * minimumHorizontalScale < width)
  69691. {
  69692. if (glyphs.getUnchecked (i)->isWhitespace()
  69693. || glyphs.getUnchecked (i)->getCharacter() == T('-'))
  69694. {
  69695. ++i;
  69696. break;
  69697. }
  69698. }
  69699. else
  69700. {
  69701. // can't find a suitable break, so try looking backwards..
  69702. i = searchStartIndex;
  69703. for (int back = 1; back < jmin (5, i - startIndex - 1); ++back)
  69704. {
  69705. if (glyphs.getUnchecked (i - back)->isWhitespace()
  69706. || glyphs.getUnchecked (i - back)->getCharacter() == T('-'))
  69707. {
  69708. i -= back - 1;
  69709. break;
  69710. }
  69711. }
  69712. break;
  69713. }
  69714. ++i;
  69715. }
  69716. break;
  69717. }
  69718. ++i;
  69719. }
  69720. int wsStart = i;
  69721. while (wsStart > 0 && glyphs.getUnchecked (wsStart - 1)->isWhitespace())
  69722. --wsStart;
  69723. int wsEnd = i;
  69724. while (wsEnd < glyphs.size() && glyphs.getUnchecked (wsEnd)->isWhitespace())
  69725. ++wsEnd;
  69726. removeRangeOfGlyphs (wsStart, wsEnd - wsStart);
  69727. i = jmax (wsStart, startIndex + 1);
  69728. }
  69729. i -= fitLineIntoSpace (startIndex, i - startIndex,
  69730. x, lineY, width, font.getHeight(), font,
  69731. layout.getOnlyHorizontalFlags() | Justification::verticallyCentred,
  69732. minimumHorizontalScale);
  69733. startIndex = i;
  69734. lineY += font.getHeight();
  69735. if (startIndex >= glyphs.size())
  69736. break;
  69737. }
  69738. justifyGlyphs (originalStartIndex, glyphs.size() - originalStartIndex,
  69739. x, y, width, height, layout.getFlags() & ~Justification::horizontallyJustified);
  69740. }
  69741. }
  69742. }
  69743. void GlyphArrangement::moveRangeOfGlyphs (int startIndex, int num,
  69744. const float dx, const float dy)
  69745. {
  69746. jassert (startIndex >= 0);
  69747. if (dx != 0.0f || dy != 0.0f)
  69748. {
  69749. if (num < 0 || startIndex + num > glyphs.size())
  69750. num = glyphs.size() - startIndex;
  69751. while (--num >= 0)
  69752. glyphs.getUnchecked (startIndex++)->moveBy (dx, dy);
  69753. }
  69754. }
  69755. int GlyphArrangement::fitLineIntoSpace (int start, int numGlyphs, float x, float y, float w, float h, const Font& font,
  69756. const Justification& justification, float minimumHorizontalScale)
  69757. {
  69758. int numDeleted = 0;
  69759. const float lineStartX = glyphs.getUnchecked (start)->getLeft();
  69760. float lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX;
  69761. if (lineWidth > w)
  69762. {
  69763. if (minimumHorizontalScale < 1.0f)
  69764. {
  69765. stretchRangeOfGlyphs (start, numGlyphs, jmax (minimumHorizontalScale, w / lineWidth));
  69766. lineWidth = glyphs.getUnchecked (start + numGlyphs - 1)->getRight() - lineStartX - 0.5f;
  69767. }
  69768. if (lineWidth > w)
  69769. {
  69770. numDeleted = insertEllipsis (font, lineStartX + w, start, start + numGlyphs);
  69771. numGlyphs -= numDeleted;
  69772. }
  69773. }
  69774. justifyGlyphs (start, numGlyphs, x, y, w, h, justification);
  69775. return numDeleted;
  69776. }
  69777. void GlyphArrangement::stretchRangeOfGlyphs (int startIndex, int num,
  69778. const float horizontalScaleFactor)
  69779. {
  69780. jassert (startIndex >= 0);
  69781. if (num < 0 || startIndex + num > glyphs.size())
  69782. num = glyphs.size() - startIndex;
  69783. if (num > 0)
  69784. {
  69785. const float xAnchor = glyphs.getUnchecked (startIndex)->getLeft();
  69786. while (--num >= 0)
  69787. {
  69788. PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69789. pg->x = xAnchor + (pg->x - xAnchor) * horizontalScaleFactor;
  69790. pg->font.setHorizontalScale (pg->font.getHorizontalScale() * horizontalScaleFactor);
  69791. pg->w *= horizontalScaleFactor;
  69792. }
  69793. }
  69794. }
  69795. void GlyphArrangement::getBoundingBox (int startIndex, int num,
  69796. float& left,
  69797. float& top,
  69798. float& right,
  69799. float& bottom,
  69800. const bool includeWhitespace) const
  69801. {
  69802. jassert (startIndex >= 0);
  69803. if (num < 0 || startIndex + num > glyphs.size())
  69804. num = glyphs.size() - startIndex;
  69805. left = 0.0f;
  69806. top = 0.0f;
  69807. right = 0.0f;
  69808. bottom = 0.0f;
  69809. bool isFirst = true;
  69810. while (--num >= 0)
  69811. {
  69812. const PositionedGlyph* const pg = glyphs.getUnchecked (startIndex++);
  69813. if (includeWhitespace || ! pg->isWhitespace())
  69814. {
  69815. if (isFirst)
  69816. {
  69817. isFirst = false;
  69818. left = pg->getLeft();
  69819. top = pg->getTop();
  69820. right = pg->getRight();
  69821. bottom = pg->getBottom();
  69822. }
  69823. else
  69824. {
  69825. left = jmin (left, pg->getLeft());
  69826. top = jmin (top, pg->getTop());
  69827. right = jmax (right, pg->getRight());
  69828. bottom = jmax (bottom, pg->getBottom());
  69829. }
  69830. }
  69831. }
  69832. }
  69833. void GlyphArrangement::justifyGlyphs (const int startIndex,
  69834. const int num,
  69835. const float x, const float y,
  69836. const float width, const float height,
  69837. const Justification& justification)
  69838. {
  69839. jassert (num >= 0 && startIndex >= 0);
  69840. if (glyphs.size() > 0 && num > 0)
  69841. {
  69842. float left, top, right, bottom;
  69843. getBoundingBox (startIndex, num, left, top, right, bottom,
  69844. ! justification.testFlags (Justification::horizontallyJustified
  69845. | Justification::horizontallyCentred));
  69846. float deltaX = 0.0f;
  69847. if (justification.testFlags (Justification::horizontallyJustified))
  69848. deltaX = x - left;
  69849. else if (justification.testFlags (Justification::horizontallyCentred))
  69850. deltaX = x + (width - (right - left)) * 0.5f - left;
  69851. else if (justification.testFlags (Justification::right))
  69852. deltaX = (x + width) - right;
  69853. else
  69854. deltaX = x - left;
  69855. float deltaY = 0.0f;
  69856. if (justification.testFlags (Justification::top))
  69857. deltaY = y - top;
  69858. else if (justification.testFlags (Justification::bottom))
  69859. deltaY = (y + height) - bottom;
  69860. else
  69861. deltaY = y + (height - (bottom - top)) * 0.5f - top;
  69862. moveRangeOfGlyphs (startIndex, num, deltaX, deltaY);
  69863. if (justification.testFlags (Justification::horizontallyJustified))
  69864. {
  69865. int lineStart = 0;
  69866. float baseY = glyphs.getUnchecked (startIndex)->getBaselineY();
  69867. int i;
  69868. for (i = 0; i < num; ++i)
  69869. {
  69870. const float glyphY = glyphs.getUnchecked (startIndex + i)->getBaselineY();
  69871. if (glyphY != baseY)
  69872. {
  69873. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69874. lineStart = i;
  69875. baseY = glyphY;
  69876. }
  69877. }
  69878. if (i > lineStart)
  69879. spreadOutLine (startIndex + lineStart, i - lineStart, width);
  69880. }
  69881. }
  69882. }
  69883. void GlyphArrangement::spreadOutLine (const int start, const int num, const float targetWidth)
  69884. {
  69885. if (start + num < glyphs.size()
  69886. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\r')
  69887. && glyphs.getUnchecked (start + num - 1)->getCharacter() != T('\n'))
  69888. {
  69889. int numSpaces = 0;
  69890. int spacesAtEnd = 0;
  69891. for (int i = 0; i < num; ++i)
  69892. {
  69893. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69894. {
  69895. ++spacesAtEnd;
  69896. ++numSpaces;
  69897. }
  69898. else
  69899. {
  69900. spacesAtEnd = 0;
  69901. }
  69902. }
  69903. numSpaces -= spacesAtEnd;
  69904. if (numSpaces > 0)
  69905. {
  69906. const float startX = glyphs.getUnchecked (start)->getLeft();
  69907. const float endX = glyphs.getUnchecked (start + num - 1 - spacesAtEnd)->getRight();
  69908. const float extraPaddingBetweenWords
  69909. = (targetWidth - (endX - startX)) / (float) numSpaces;
  69910. float deltaX = 0.0f;
  69911. for (int i = 0; i < num; ++i)
  69912. {
  69913. glyphs.getUnchecked (start + i)->moveBy (deltaX, 0.0f);
  69914. if (glyphs.getUnchecked (start + i)->isWhitespace())
  69915. deltaX += extraPaddingBetweenWords;
  69916. }
  69917. }
  69918. }
  69919. }
  69920. void GlyphArrangement::draw (const Graphics& g) const
  69921. {
  69922. for (int i = 0; i < glyphs.size(); ++i)
  69923. {
  69924. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69925. if (pg->font.isUnderlined())
  69926. {
  69927. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69928. float nextX = pg->x + pg->w;
  69929. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69930. nextX = glyphs.getUnchecked (i + 1)->x;
  69931. g.fillRect (pg->x, pg->y + lineThickness * 2.0f,
  69932. nextX - pg->x, lineThickness);
  69933. }
  69934. pg->draw (g);
  69935. }
  69936. }
  69937. void GlyphArrangement::draw (const Graphics& g, const AffineTransform& transform) const
  69938. {
  69939. for (int i = 0; i < glyphs.size(); ++i)
  69940. {
  69941. const PositionedGlyph* const pg = glyphs.getUnchecked(i);
  69942. if (pg->font.isUnderlined())
  69943. {
  69944. const float lineThickness = (pg->font.getDescent()) * 0.3f;
  69945. float nextX = pg->x + pg->w;
  69946. if (i < glyphs.size() - 1 && glyphs.getUnchecked (i + 1)->y == pg->y)
  69947. nextX = glyphs.getUnchecked (i + 1)->x;
  69948. Path p;
  69949. p.addLineSegment (pg->x, pg->y + lineThickness * 2.0f,
  69950. nextX, pg->y + lineThickness * 2.0f,
  69951. lineThickness);
  69952. g.fillPath (p, transform);
  69953. }
  69954. pg->draw (g, transform);
  69955. }
  69956. }
  69957. void GlyphArrangement::createPath (Path& path) const
  69958. {
  69959. for (int i = 0; i < glyphs.size(); ++i)
  69960. glyphs.getUnchecked (i)->createPath (path);
  69961. }
  69962. int GlyphArrangement::findGlyphIndexAt (float x, float y) const
  69963. {
  69964. for (int i = 0; i < glyphs.size(); ++i)
  69965. if (glyphs.getUnchecked (i)->hitTest (x, y))
  69966. return i;
  69967. return -1;
  69968. }
  69969. END_JUCE_NAMESPACE
  69970. /*** End of inlined file: juce_GlyphArrangement.cpp ***/
  69971. /*** Start of inlined file: juce_TextLayout.cpp ***/
  69972. BEGIN_JUCE_NAMESPACE
  69973. class TextLayout::Token
  69974. {
  69975. public:
  69976. String text;
  69977. Font font;
  69978. int x, y, w, h;
  69979. int line, lineHeight;
  69980. bool isWhitespace, isNewLine;
  69981. Token (const String& t,
  69982. const Font& f,
  69983. const bool isWhitespace_) throw()
  69984. : text (t),
  69985. font (f),
  69986. x(0),
  69987. y(0),
  69988. isWhitespace (isWhitespace_)
  69989. {
  69990. w = font.getStringWidth (t);
  69991. h = roundToInt (f.getHeight());
  69992. isNewLine = t.containsAnyOf (T("\r\n"));
  69993. }
  69994. Token (const Token& other) throw()
  69995. : text (other.text),
  69996. font (other.font),
  69997. x (other.x),
  69998. y (other.y),
  69999. w (other.w),
  70000. h (other.h),
  70001. line (other.line),
  70002. lineHeight (other.lineHeight),
  70003. isWhitespace (other.isWhitespace),
  70004. isNewLine (other.isNewLine)
  70005. {
  70006. }
  70007. ~Token() throw()
  70008. {
  70009. }
  70010. void draw (Graphics& g,
  70011. const int xOffset,
  70012. const int yOffset) throw()
  70013. {
  70014. if (! isWhitespace)
  70015. {
  70016. g.setFont (font);
  70017. g.drawSingleLineText (text.trimEnd(),
  70018. xOffset + x,
  70019. yOffset + y + (lineHeight - h)
  70020. + roundToInt (font.getAscent()));
  70021. }
  70022. }
  70023. juce_UseDebuggingNewOperator
  70024. };
  70025. TextLayout::TextLayout() throw()
  70026. : totalLines (0)
  70027. {
  70028. tokens.ensureStorageAllocated (64);
  70029. }
  70030. TextLayout::TextLayout (const String& text,
  70031. const Font& font) throw()
  70032. : totalLines (0)
  70033. {
  70034. tokens.ensureStorageAllocated (64);
  70035. appendText (text, font);
  70036. }
  70037. TextLayout::TextLayout (const TextLayout& other) throw()
  70038. : totalLines (0)
  70039. {
  70040. *this = other;
  70041. }
  70042. TextLayout& TextLayout::operator= (const TextLayout& other) throw()
  70043. {
  70044. if (this != &other)
  70045. {
  70046. clear();
  70047. totalLines = other.totalLines;
  70048. for (int i = 0; i < other.tokens.size(); ++i)
  70049. tokens.add (new Token (*other.tokens.getUnchecked(i)));
  70050. }
  70051. return *this;
  70052. }
  70053. TextLayout::~TextLayout() throw()
  70054. {
  70055. clear();
  70056. }
  70057. void TextLayout::clear() throw()
  70058. {
  70059. tokens.clear();
  70060. totalLines = 0;
  70061. }
  70062. void TextLayout::appendText (const String& text,
  70063. const Font& font) throw()
  70064. {
  70065. const tchar* t = text;
  70066. String currentString;
  70067. int lastCharType = 0;
  70068. for (;;)
  70069. {
  70070. const tchar c = *t++;
  70071. if (c == 0)
  70072. break;
  70073. int charType;
  70074. if (c == T('\r') || c == T('\n'))
  70075. {
  70076. charType = 0;
  70077. }
  70078. else if (CharacterFunctions::isWhitespace (c))
  70079. {
  70080. charType = 2;
  70081. }
  70082. else
  70083. {
  70084. charType = 1;
  70085. }
  70086. if (charType == 0 || charType != lastCharType)
  70087. {
  70088. if (currentString.isNotEmpty())
  70089. {
  70090. tokens.add (new Token (currentString, font,
  70091. lastCharType == 2 || lastCharType == 0));
  70092. }
  70093. currentString = String::charToString (c);
  70094. if (c == T('\r') && *t == T('\n'))
  70095. currentString += *t++;
  70096. }
  70097. else
  70098. {
  70099. currentString += c;
  70100. }
  70101. lastCharType = charType;
  70102. }
  70103. if (currentString.isNotEmpty())
  70104. tokens.add (new Token (currentString, font, lastCharType == 2));
  70105. }
  70106. void TextLayout::setText (const String& text, const Font& font) throw()
  70107. {
  70108. clear();
  70109. appendText (text, font);
  70110. }
  70111. void TextLayout::layout (int maxWidth,
  70112. const Justification& justification,
  70113. const bool attemptToBalanceLineLengths) throw()
  70114. {
  70115. if (attemptToBalanceLineLengths)
  70116. {
  70117. const int originalW = maxWidth;
  70118. int bestWidth = maxWidth;
  70119. float bestLineProportion = 0.0f;
  70120. while (maxWidth > originalW / 2)
  70121. {
  70122. layout (maxWidth, justification, false);
  70123. if (getNumLines() <= 1)
  70124. return;
  70125. const int lastLineW = getLineWidth (getNumLines() - 1);
  70126. const int lastButOneLineW = getLineWidth (getNumLines() - 2);
  70127. const float prop = lastLineW / (float) lastButOneLineW;
  70128. if (prop > 0.9f)
  70129. return;
  70130. if (prop > bestLineProportion)
  70131. {
  70132. bestLineProportion = prop;
  70133. bestWidth = maxWidth;
  70134. }
  70135. maxWidth -= 10;
  70136. }
  70137. layout (bestWidth, justification, false);
  70138. }
  70139. else
  70140. {
  70141. int x = 0;
  70142. int y = 0;
  70143. int h = 0;
  70144. totalLines = 0;
  70145. int i;
  70146. for (i = 0; i < tokens.size(); ++i)
  70147. {
  70148. Token* const t = tokens.getUnchecked(i);
  70149. t->x = x;
  70150. t->y = y;
  70151. t->line = totalLines;
  70152. x += t->w;
  70153. h = jmax (h, t->h);
  70154. const Token* nextTok = tokens [i + 1];
  70155. if (nextTok == 0)
  70156. break;
  70157. if (t->isNewLine || ((! nextTok->isWhitespace) && x + nextTok->w > maxWidth))
  70158. {
  70159. // finished a line, so go back and update the heights of the things on it
  70160. for (int j = i; j >= 0; --j)
  70161. {
  70162. Token* const tok = tokens.getUnchecked(j);
  70163. if (tok->line == totalLines)
  70164. tok->lineHeight = h;
  70165. else
  70166. break;
  70167. }
  70168. x = 0;
  70169. y += h;
  70170. h = 0;
  70171. ++totalLines;
  70172. }
  70173. }
  70174. // finished a line, so go back and update the heights of the things on it
  70175. for (int j = jmin (i, tokens.size() - 1); j >= 0; --j)
  70176. {
  70177. Token* const t = tokens.getUnchecked(j);
  70178. if (t->line == totalLines)
  70179. t->lineHeight = h;
  70180. else
  70181. break;
  70182. }
  70183. ++totalLines;
  70184. if (! justification.testFlags (Justification::left))
  70185. {
  70186. int totalW = getWidth();
  70187. for (i = totalLines; --i >= 0;)
  70188. {
  70189. const int lineW = getLineWidth (i);
  70190. int dx = 0;
  70191. if (justification.testFlags (Justification::horizontallyCentred))
  70192. dx = (totalW - lineW) / 2;
  70193. else if (justification.testFlags (Justification::right))
  70194. dx = totalW - lineW;
  70195. for (int j = tokens.size(); --j >= 0;)
  70196. {
  70197. Token* const t = tokens.getUnchecked(j);
  70198. if (t->line == i)
  70199. t->x += dx;
  70200. }
  70201. }
  70202. }
  70203. }
  70204. }
  70205. int TextLayout::getLineWidth (const int lineNumber) const throw()
  70206. {
  70207. int maxW = 0;
  70208. for (int i = tokens.size(); --i >= 0;)
  70209. {
  70210. const Token* const t = tokens.getUnchecked(i);
  70211. if (t->line == lineNumber && ! t->isWhitespace)
  70212. maxW = jmax (maxW, t->x + t->w);
  70213. }
  70214. return maxW;
  70215. }
  70216. int TextLayout::getWidth() const throw()
  70217. {
  70218. int maxW = 0;
  70219. for (int i = tokens.size(); --i >= 0;)
  70220. {
  70221. const Token* const t = tokens.getUnchecked(i);
  70222. if (! t->isWhitespace)
  70223. maxW = jmax (maxW, t->x + t->w);
  70224. }
  70225. return maxW;
  70226. }
  70227. int TextLayout::getHeight() const throw()
  70228. {
  70229. int maxH = 0;
  70230. for (int i = tokens.size(); --i >= 0;)
  70231. {
  70232. const Token* const t = tokens.getUnchecked(i);
  70233. if (! t->isWhitespace)
  70234. maxH = jmax (maxH, t->y + t->h);
  70235. }
  70236. return maxH;
  70237. }
  70238. void TextLayout::draw (Graphics& g,
  70239. const int xOffset,
  70240. const int yOffset) const throw()
  70241. {
  70242. for (int i = tokens.size(); --i >= 0;)
  70243. tokens.getUnchecked(i)->draw (g, xOffset, yOffset);
  70244. }
  70245. void TextLayout::drawWithin (Graphics& g,
  70246. int x, int y, int w, int h,
  70247. const Justification& justification) const throw()
  70248. {
  70249. justification.applyToRectangle (x, y, getWidth(), getHeight(),
  70250. x, y, w, h);
  70251. draw (g, x, y);
  70252. }
  70253. END_JUCE_NAMESPACE
  70254. /*** End of inlined file: juce_TextLayout.cpp ***/
  70255. /*** Start of inlined file: juce_Typeface.cpp ***/
  70256. BEGIN_JUCE_NAMESPACE
  70257. Typeface::Typeface (const String& name_) throw()
  70258. : name (name_)
  70259. {
  70260. }
  70261. Typeface::~Typeface()
  70262. {
  70263. }
  70264. class CustomTypeface::GlyphInfo
  70265. {
  70266. public:
  70267. GlyphInfo (const juce_wchar character_, const Path& path_, const float width_) throw()
  70268. : character (character_), path (path_), width (width_)
  70269. {
  70270. }
  70271. ~GlyphInfo() throw()
  70272. {
  70273. }
  70274. struct KerningPair
  70275. {
  70276. juce_wchar character2;
  70277. float kerningAmount;
  70278. };
  70279. void addKerningPair (const juce_wchar subsequentCharacter,
  70280. const float extraKerningAmount) throw()
  70281. {
  70282. KerningPair kp;
  70283. kp.character2 = subsequentCharacter;
  70284. kp.kerningAmount = extraKerningAmount;
  70285. kerningPairs.add (kp);
  70286. }
  70287. float getHorizontalSpacing (const juce_wchar subsequentCharacter) const throw()
  70288. {
  70289. if (subsequentCharacter != 0)
  70290. {
  70291. for (int i = kerningPairs.size(); --i >= 0;)
  70292. if (kerningPairs.getReference(i).character2 == subsequentCharacter)
  70293. return width + kerningPairs.getReference(i).kerningAmount;
  70294. }
  70295. return width;
  70296. }
  70297. const juce_wchar character;
  70298. const Path path;
  70299. float width;
  70300. Array <KerningPair> kerningPairs;
  70301. juce_UseDebuggingNewOperator
  70302. private:
  70303. GlyphInfo (const GlyphInfo&);
  70304. GlyphInfo& operator= (const GlyphInfo&);
  70305. };
  70306. CustomTypeface::CustomTypeface()
  70307. : Typeface (String::empty)
  70308. {
  70309. clear();
  70310. }
  70311. CustomTypeface::CustomTypeface (InputStream& serialisedTypefaceStream)
  70312. : Typeface (String::empty)
  70313. {
  70314. clear();
  70315. GZIPDecompressorInputStream gzin (&serialisedTypefaceStream, false);
  70316. BufferedInputStream in (&gzin, 32768, false);
  70317. name = in.readString();
  70318. isBold = in.readBool();
  70319. isItalic = in.readBool();
  70320. ascent = in.readFloat();
  70321. defaultCharacter = (juce_wchar) in.readShort();
  70322. int i, numChars = in.readInt();
  70323. for (i = 0; i < numChars; ++i)
  70324. {
  70325. const juce_wchar c = (juce_wchar) in.readShort();
  70326. const float width = in.readFloat();
  70327. Path p;
  70328. p.loadPathFromStream (in);
  70329. addGlyph (c, p, width);
  70330. }
  70331. const int numKerningPairs = in.readInt();
  70332. for (i = 0; i < numKerningPairs; ++i)
  70333. {
  70334. const juce_wchar char1 = (juce_wchar) in.readShort();
  70335. const juce_wchar char2 = (juce_wchar) in.readShort();
  70336. addKerningPair (char1, char2, in.readFloat());
  70337. }
  70338. }
  70339. CustomTypeface::~CustomTypeface()
  70340. {
  70341. }
  70342. void CustomTypeface::clear()
  70343. {
  70344. defaultCharacter = 0;
  70345. ascent = 1.0f;
  70346. isBold = isItalic = false;
  70347. zeromem (lookupTable, sizeof (lookupTable));
  70348. glyphs.clear();
  70349. }
  70350. void CustomTypeface::setCharacteristics (const String& name_, const float ascent_, const bool isBold_,
  70351. const bool isItalic_, const juce_wchar defaultCharacter_) throw()
  70352. {
  70353. name = name_;
  70354. defaultCharacter = defaultCharacter_;
  70355. ascent = ascent_;
  70356. isBold = isBold_;
  70357. isItalic = isItalic_;
  70358. }
  70359. void CustomTypeface::addGlyph (const juce_wchar character, const Path& path, const float width) throw()
  70360. {
  70361. // Check that you're not trying to add the same character twice..
  70362. jassert (findGlyph (character, false) == 0);
  70363. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable))
  70364. lookupTable [character] = (short) glyphs.size();
  70365. glyphs.add (new GlyphInfo (character, path, width));
  70366. }
  70367. void CustomTypeface::addKerningPair (const juce_wchar char1, const juce_wchar char2, const float extraAmount) throw()
  70368. {
  70369. if (extraAmount != 0)
  70370. {
  70371. GlyphInfo* const g = findGlyph (char1, true);
  70372. jassert (g != 0); // can only add kerning pairs for characters that exist!
  70373. if (g != 0)
  70374. g->addKerningPair (char2, extraAmount);
  70375. }
  70376. }
  70377. CustomTypeface::GlyphInfo* CustomTypeface::findGlyph (const juce_wchar character, const bool loadIfNeeded) throw()
  70378. {
  70379. if (((unsigned int) character) < (unsigned int) numElementsInArray (lookupTable) && lookupTable [character] > 0)
  70380. return glyphs [(int) lookupTable [(int) character]];
  70381. for (int i = 0; i < glyphs.size(); ++i)
  70382. {
  70383. GlyphInfo* const g = glyphs.getUnchecked(i);
  70384. if (g->character == character)
  70385. return g;
  70386. }
  70387. if (loadIfNeeded && loadGlyphIfPossible (character))
  70388. return findGlyph (character, false);
  70389. return 0;
  70390. }
  70391. CustomTypeface::GlyphInfo* CustomTypeface::findGlyphSubstituting (const juce_wchar character) throw()
  70392. {
  70393. GlyphInfo* glyph = findGlyph (character, true);
  70394. if (glyph == 0)
  70395. {
  70396. if (CharacterFunctions::isWhitespace (character) && character != L' ')
  70397. glyph = findGlyph (L' ', true);
  70398. if (glyph == 0)
  70399. {
  70400. const Font fallbackFont (Font::getFallbackFontName(), 10, 0);
  70401. Typeface* const fallbackTypeface = fallbackFont.getTypeface();
  70402. if (fallbackTypeface != 0 && fallbackTypeface != this)
  70403. {
  70404. //xxx
  70405. }
  70406. if (glyph == 0)
  70407. glyph = findGlyph (defaultCharacter, true);
  70408. }
  70409. }
  70410. return glyph;
  70411. }
  70412. bool CustomTypeface::loadGlyphIfPossible (const juce_wchar /*characterNeeded*/)
  70413. {
  70414. return false;
  70415. }
  70416. void CustomTypeface::addGlyphsFromOtherTypeface (Typeface& typefaceToCopy, juce_wchar characterStartIndex, int numCharacters) throw()
  70417. {
  70418. for (int i = 0; i < numCharacters; ++i)
  70419. {
  70420. const juce_wchar c = (juce_wchar) (characterStartIndex + i);
  70421. Array <int> glyphIndexes;
  70422. Array <float> offsets;
  70423. typefaceToCopy.getGlyphPositions (String::charToString (c), glyphIndexes, offsets);
  70424. const int glyphIndex = glyphIndexes.getFirst();
  70425. if (glyphIndex >= 0 && glyphIndexes.size() > 0)
  70426. {
  70427. const float glyphWidth = offsets[1];
  70428. Path p;
  70429. typefaceToCopy.getOutlineForGlyph (glyphIndex, p);
  70430. addGlyph (c, p, glyphWidth);
  70431. for (int j = glyphs.size() - 1; --j >= 0;)
  70432. {
  70433. const juce_wchar char2 = glyphs.getUnchecked (j)->character;
  70434. glyphIndexes.clearQuick();
  70435. offsets.clearQuick();
  70436. typefaceToCopy.getGlyphPositions (String::charToString (c) + String::charToString (char2), glyphIndexes, offsets);
  70437. if (offsets.size() > 1)
  70438. addKerningPair (c, char2, offsets[1] - glyphWidth);
  70439. }
  70440. }
  70441. }
  70442. }
  70443. bool CustomTypeface::writeToStream (OutputStream& outputStream)
  70444. {
  70445. GZIPCompressorOutputStream out (&outputStream);
  70446. out.writeString (name);
  70447. out.writeBool (isBold);
  70448. out.writeBool (isItalic);
  70449. out.writeFloat (ascent);
  70450. out.writeShort ((short) (unsigned short) defaultCharacter);
  70451. out.writeInt (glyphs.size());
  70452. int i, numKerningPairs = 0;
  70453. for (i = 0; i < glyphs.size(); ++i)
  70454. {
  70455. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70456. out.writeShort ((short) (unsigned short) g->character);
  70457. out.writeFloat (g->width);
  70458. g->path.writePathToStream (out);
  70459. numKerningPairs += g->kerningPairs.size();
  70460. }
  70461. out.writeInt (numKerningPairs);
  70462. for (i = 0; i < glyphs.size(); ++i)
  70463. {
  70464. const GlyphInfo* const g = glyphs.getUnchecked (i);
  70465. for (int j = 0; j < g->kerningPairs.size(); ++j)
  70466. {
  70467. const GlyphInfo::KerningPair& p = g->kerningPairs.getReference (j);
  70468. out.writeShort ((short) (unsigned short) g->character);
  70469. out.writeShort ((short) (unsigned short) p.character2);
  70470. out.writeFloat (p.kerningAmount);
  70471. }
  70472. }
  70473. return true;
  70474. }
  70475. float CustomTypeface::getAscent() const
  70476. {
  70477. return ascent;
  70478. }
  70479. float CustomTypeface::getDescent() const
  70480. {
  70481. return 1.0f - ascent;
  70482. }
  70483. float CustomTypeface::getStringWidth (const String& text)
  70484. {
  70485. float x = 0;
  70486. const juce_wchar* t = (const juce_wchar*) text;
  70487. while (*t != 0)
  70488. {
  70489. const GlyphInfo* const glyph = findGlyphSubstituting (*t++);
  70490. if (glyph != 0)
  70491. x += glyph->getHorizontalSpacing (*t);
  70492. }
  70493. return x;
  70494. }
  70495. void CustomTypeface::getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array<float>& xOffsets)
  70496. {
  70497. xOffsets.add (0);
  70498. float x = 0;
  70499. const juce_wchar* t = (const juce_wchar*) text;
  70500. while (*t != 0)
  70501. {
  70502. const juce_wchar c = *t++;
  70503. const GlyphInfo* const glyph = findGlyphSubstituting (c);
  70504. if (glyph != 0)
  70505. {
  70506. x += glyph->getHorizontalSpacing (*t);
  70507. resultGlyphs.add ((int) glyph->character);
  70508. xOffsets.add (x);
  70509. }
  70510. }
  70511. }
  70512. bool CustomTypeface::getOutlineForGlyph (int glyphNumber, Path& path)
  70513. {
  70514. const GlyphInfo* const glyph = findGlyphSubstituting ((juce_wchar) glyphNumber);
  70515. if (glyph != 0)
  70516. {
  70517. path = glyph->path;
  70518. return true;
  70519. }
  70520. return false;
  70521. }
  70522. END_JUCE_NAMESPACE
  70523. /*** End of inlined file: juce_Typeface.cpp ***/
  70524. /*** Start of inlined file: juce_AffineTransform.cpp ***/
  70525. BEGIN_JUCE_NAMESPACE
  70526. AffineTransform::AffineTransform() throw()
  70527. : mat00 (1.0f),
  70528. mat01 (0),
  70529. mat02 (0),
  70530. mat10 (0),
  70531. mat11 (1.0f),
  70532. mat12 (0)
  70533. {
  70534. }
  70535. AffineTransform::AffineTransform (const AffineTransform& other) throw()
  70536. : mat00 (other.mat00),
  70537. mat01 (other.mat01),
  70538. mat02 (other.mat02),
  70539. mat10 (other.mat10),
  70540. mat11 (other.mat11),
  70541. mat12 (other.mat12)
  70542. {
  70543. }
  70544. AffineTransform::AffineTransform (const float mat00_,
  70545. const float mat01_,
  70546. const float mat02_,
  70547. const float mat10_,
  70548. const float mat11_,
  70549. const float mat12_) throw()
  70550. : mat00 (mat00_),
  70551. mat01 (mat01_),
  70552. mat02 (mat02_),
  70553. mat10 (mat10_),
  70554. mat11 (mat11_),
  70555. mat12 (mat12_)
  70556. {
  70557. }
  70558. AffineTransform& AffineTransform::operator= (const AffineTransform& other) throw()
  70559. {
  70560. mat00 = other.mat00;
  70561. mat01 = other.mat01;
  70562. mat02 = other.mat02;
  70563. mat10 = other.mat10;
  70564. mat11 = other.mat11;
  70565. mat12 = other.mat12;
  70566. return *this;
  70567. }
  70568. bool AffineTransform::operator== (const AffineTransform& other) const throw()
  70569. {
  70570. return mat00 == other.mat00
  70571. && mat01 == other.mat01
  70572. && mat02 == other.mat02
  70573. && mat10 == other.mat10
  70574. && mat11 == other.mat11
  70575. && mat12 == other.mat12;
  70576. }
  70577. bool AffineTransform::operator!= (const AffineTransform& other) const throw()
  70578. {
  70579. return ! operator== (other);
  70580. }
  70581. bool AffineTransform::isIdentity() const throw()
  70582. {
  70583. return (mat01 == 0)
  70584. && (mat02 == 0)
  70585. && (mat10 == 0)
  70586. && (mat12 == 0)
  70587. && (mat00 == 1.0f)
  70588. && (mat11 == 1.0f);
  70589. }
  70590. const AffineTransform AffineTransform::identity;
  70591. const AffineTransform AffineTransform::followedBy (const AffineTransform& other) const throw()
  70592. {
  70593. return AffineTransform (other.mat00 * mat00 + other.mat01 * mat10,
  70594. other.mat00 * mat01 + other.mat01 * mat11,
  70595. other.mat00 * mat02 + other.mat01 * mat12 + other.mat02,
  70596. other.mat10 * mat00 + other.mat11 * mat10,
  70597. other.mat10 * mat01 + other.mat11 * mat11,
  70598. other.mat10 * mat02 + other.mat11 * mat12 + other.mat12);
  70599. }
  70600. const AffineTransform AffineTransform::followedBy (const float omat00,
  70601. const float omat01,
  70602. const float omat02,
  70603. const float omat10,
  70604. const float omat11,
  70605. const float omat12) const throw()
  70606. {
  70607. return AffineTransform (omat00 * mat00 + omat01 * mat10,
  70608. omat00 * mat01 + omat01 * mat11,
  70609. omat00 * mat02 + omat01 * mat12 + omat02,
  70610. omat10 * mat00 + omat11 * mat10,
  70611. omat10 * mat01 + omat11 * mat11,
  70612. omat10 * mat02 + omat11 * mat12 + omat12);
  70613. }
  70614. const AffineTransform AffineTransform::translated (const float dx,
  70615. const float dy) const throw()
  70616. {
  70617. return AffineTransform (mat00, mat01, mat02 + dx,
  70618. mat10, mat11, mat12 + dy);
  70619. }
  70620. const AffineTransform AffineTransform::translation (const float dx,
  70621. const float dy) throw()
  70622. {
  70623. return AffineTransform (1.0f, 0, dx,
  70624. 0, 1.0f, dy);
  70625. }
  70626. const AffineTransform AffineTransform::rotated (const float rad) const throw()
  70627. {
  70628. const float cosRad = cosf (rad);
  70629. const float sinRad = sinf (rad);
  70630. return followedBy (cosRad, -sinRad, 0,
  70631. sinRad, cosRad, 0);
  70632. }
  70633. const AffineTransform AffineTransform::rotation (const float rad) throw()
  70634. {
  70635. const float cosRad = cosf (rad);
  70636. const float sinRad = sinf (rad);
  70637. return AffineTransform (cosRad, -sinRad, 0,
  70638. sinRad, cosRad, 0);
  70639. }
  70640. const AffineTransform AffineTransform::rotated (const float angle,
  70641. const float pivotX,
  70642. const float pivotY) const throw()
  70643. {
  70644. return translated (-pivotX, -pivotY)
  70645. .rotated (angle)
  70646. .translated (pivotX, pivotY);
  70647. }
  70648. const AffineTransform AffineTransform::rotation (const float angle,
  70649. const float pivotX,
  70650. const float pivotY) throw()
  70651. {
  70652. return translation (-pivotX, -pivotY)
  70653. .rotated (angle)
  70654. .translated (pivotX, pivotY);
  70655. }
  70656. const AffineTransform AffineTransform::scaled (const float factorX,
  70657. const float factorY) const throw()
  70658. {
  70659. return AffineTransform (factorX * mat00, factorX * mat01, factorX * mat02,
  70660. factorY * mat10, factorY * mat11, factorY * mat12);
  70661. }
  70662. const AffineTransform AffineTransform::scale (const float factorX,
  70663. const float factorY) throw()
  70664. {
  70665. return AffineTransform (factorX, 0, 0,
  70666. 0, factorY, 0);
  70667. }
  70668. const AffineTransform AffineTransform::sheared (const float shearX,
  70669. const float shearY) const throw()
  70670. {
  70671. return followedBy (1.0f, shearX, 0,
  70672. shearY, 1.0f, 0);
  70673. }
  70674. const AffineTransform AffineTransform::inverted() const throw()
  70675. {
  70676. double determinant = (mat00 * mat11 - mat10 * mat01);
  70677. if (determinant != 0.0)
  70678. {
  70679. determinant = 1.0 / determinant;
  70680. const float dst00 = (float) (mat11 * determinant);
  70681. const float dst10 = (float) (-mat10 * determinant);
  70682. const float dst01 = (float) (-mat01 * determinant);
  70683. const float dst11 = (float) (mat00 * determinant);
  70684. return AffineTransform (dst00, dst01, -mat02 * dst00 - mat12 * dst01,
  70685. dst10, dst11, -mat02 * dst10 - mat12 * dst11);
  70686. }
  70687. else
  70688. {
  70689. // singularity..
  70690. return *this;
  70691. }
  70692. }
  70693. bool AffineTransform::isSingularity() const throw()
  70694. {
  70695. return (mat00 * mat11 - mat10 * mat01) == 0.0;
  70696. }
  70697. bool AffineTransform::isOnlyTranslation() const throw()
  70698. {
  70699. return (mat01 == 0)
  70700. && (mat10 == 0)
  70701. && (mat00 == 1.0f)
  70702. && (mat11 == 1.0f);
  70703. }
  70704. void AffineTransform::transformPoint (float& x,
  70705. float& y) const throw()
  70706. {
  70707. const float oldX = x;
  70708. x = mat00 * oldX + mat01 * y + mat02;
  70709. y = mat10 * oldX + mat11 * y + mat12;
  70710. }
  70711. void AffineTransform::transformPoint (double& x,
  70712. double& y) const throw()
  70713. {
  70714. const double oldX = x;
  70715. x = mat00 * oldX + mat01 * y + mat02;
  70716. y = mat10 * oldX + mat11 * y + mat12;
  70717. }
  70718. END_JUCE_NAMESPACE
  70719. /*** End of inlined file: juce_AffineTransform.cpp ***/
  70720. /*** Start of inlined file: juce_BorderSize.cpp ***/
  70721. BEGIN_JUCE_NAMESPACE
  70722. BorderSize::BorderSize() throw()
  70723. : top (0),
  70724. left (0),
  70725. bottom (0),
  70726. right (0)
  70727. {
  70728. }
  70729. BorderSize::BorderSize (const BorderSize& other) throw()
  70730. : top (other.top),
  70731. left (other.left),
  70732. bottom (other.bottom),
  70733. right (other.right)
  70734. {
  70735. }
  70736. BorderSize::BorderSize (const int topGap,
  70737. const int leftGap,
  70738. const int bottomGap,
  70739. const int rightGap) throw()
  70740. : top (topGap),
  70741. left (leftGap),
  70742. bottom (bottomGap),
  70743. right (rightGap)
  70744. {
  70745. }
  70746. BorderSize::BorderSize (const int allGaps) throw()
  70747. : top (allGaps),
  70748. left (allGaps),
  70749. bottom (allGaps),
  70750. right (allGaps)
  70751. {
  70752. }
  70753. BorderSize::~BorderSize() throw()
  70754. {
  70755. }
  70756. void BorderSize::setTop (const int newTopGap) throw()
  70757. {
  70758. top = newTopGap;
  70759. }
  70760. void BorderSize::setLeft (const int newLeftGap) throw()
  70761. {
  70762. left = newLeftGap;
  70763. }
  70764. void BorderSize::setBottom (const int newBottomGap) throw()
  70765. {
  70766. bottom = newBottomGap;
  70767. }
  70768. void BorderSize::setRight (const int newRightGap) throw()
  70769. {
  70770. right = newRightGap;
  70771. }
  70772. const Rectangle<int> BorderSize::subtractedFrom (const Rectangle<int>& r) const throw()
  70773. {
  70774. return Rectangle<int> (r.getX() + left,
  70775. r.getY() + top,
  70776. r.getWidth() - (left + right),
  70777. r.getHeight() - (top + bottom));
  70778. }
  70779. void BorderSize::subtractFrom (Rectangle<int>& r) const throw()
  70780. {
  70781. r.setBounds (r.getX() + left,
  70782. r.getY() + top,
  70783. r.getWidth() - (left + right),
  70784. r.getHeight() - (top + bottom));
  70785. }
  70786. const Rectangle<int> BorderSize::addedTo (const Rectangle<int>& r) const throw()
  70787. {
  70788. return Rectangle<int> (r.getX() - left,
  70789. r.getY() - top,
  70790. r.getWidth() + (left + right),
  70791. r.getHeight() + (top + bottom));
  70792. }
  70793. void BorderSize::addTo (Rectangle<int>& r) const throw()
  70794. {
  70795. r.setBounds (r.getX() - left,
  70796. r.getY() - top,
  70797. r.getWidth() + (left + right),
  70798. r.getHeight() + (top + bottom));
  70799. }
  70800. bool BorderSize::operator== (const BorderSize& other) const throw()
  70801. {
  70802. return top == other.top
  70803. && left == other.left
  70804. && bottom == other.bottom
  70805. && right == other.right;
  70806. }
  70807. bool BorderSize::operator!= (const BorderSize& other) const throw()
  70808. {
  70809. return ! operator== (other);
  70810. }
  70811. END_JUCE_NAMESPACE
  70812. /*** End of inlined file: juce_BorderSize.cpp ***/
  70813. /*** Start of inlined file: juce_Line.cpp ***/
  70814. BEGIN_JUCE_NAMESPACE
  70815. static bool juce_lineIntersection (const float x1, const float y1,
  70816. const float x2, const float y2,
  70817. const float x3, const float y3,
  70818. const float x4, const float y4,
  70819. float& intersectionX,
  70820. float& intersectionY) throw()
  70821. {
  70822. if (x2 != x3 || y2 != y3)
  70823. {
  70824. const float dx1 = x2 - x1;
  70825. const float dy1 = y2 - y1;
  70826. const float dx2 = x4 - x3;
  70827. const float dy2 = y4 - y3;
  70828. const float divisor = dx1 * dy2 - dx2 * dy1;
  70829. if (divisor == 0)
  70830. {
  70831. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  70832. {
  70833. if (dy1 == 0 && dy2 != 0)
  70834. {
  70835. const float along = (y1 - y3) / dy2;
  70836. intersectionX = x3 + along * dx2;
  70837. intersectionY = y1;
  70838. return along >= 0 && along <= 1.0f;
  70839. }
  70840. else if (dy2 == 0 && dy1 != 0)
  70841. {
  70842. const float along = (y3 - y1) / dy1;
  70843. intersectionX = x1 + along * dx1;
  70844. intersectionY = y3;
  70845. return along >= 0 && along <= 1.0f;
  70846. }
  70847. else if (dx1 == 0 && dx2 != 0)
  70848. {
  70849. const float along = (x1 - x3) / dx2;
  70850. intersectionX = x1;
  70851. intersectionY = y3 + along * dy2;
  70852. return along >= 0 && along <= 1.0f;
  70853. }
  70854. else if (dx2 == 0 && dx1 != 0)
  70855. {
  70856. const float along = (x3 - x1) / dx1;
  70857. intersectionX = x3;
  70858. intersectionY = y1 + along * dy1;
  70859. return along >= 0 && along <= 1.0f;
  70860. }
  70861. }
  70862. intersectionX = 0.5f * (x2 + x3);
  70863. intersectionY = 0.5f * (y2 + y3);
  70864. return false;
  70865. }
  70866. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  70867. intersectionX = x1 + along1 * dx1;
  70868. intersectionY = y1 + along1 * dy1;
  70869. if (along1 < 0 || along1 > 1.0f)
  70870. return false;
  70871. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1) / divisor;
  70872. return along2 >= 0 && along2 <= 1.0f;
  70873. }
  70874. intersectionX = x2;
  70875. intersectionY = y2;
  70876. return true;
  70877. }
  70878. Line::Line() throw()
  70879. : startX (0.0f),
  70880. startY (0.0f),
  70881. endX (0.0f),
  70882. endY (0.0f)
  70883. {
  70884. }
  70885. Line::Line (const Line& other) throw()
  70886. : startX (other.startX),
  70887. startY (other.startY),
  70888. endX (other.endX),
  70889. endY (other.endY)
  70890. {
  70891. }
  70892. Line::Line (const float startX_, const float startY_,
  70893. const float endX_, const float endY_) throw()
  70894. : startX (startX_),
  70895. startY (startY_),
  70896. endX (endX_),
  70897. endY (endY_)
  70898. {
  70899. }
  70900. Line::Line (const Point<float>& start,
  70901. const Point<float>& end) throw()
  70902. : startX (start.getX()),
  70903. startY (start.getY()),
  70904. endX (end.getX()),
  70905. endY (end.getY())
  70906. {
  70907. }
  70908. Line& Line::operator= (const Line& other) throw()
  70909. {
  70910. startX = other.startX;
  70911. startY = other.startY;
  70912. endX = other.endX;
  70913. endY = other.endY;
  70914. return *this;
  70915. }
  70916. Line::~Line() throw()
  70917. {
  70918. }
  70919. const Point<float> Line::getStart() const throw()
  70920. {
  70921. return Point<float> (startX, startY);
  70922. }
  70923. const Point<float> Line::getEnd() const throw()
  70924. {
  70925. return Point<float> (endX, endY);
  70926. }
  70927. void Line::setStart (const float newStartX,
  70928. const float newStartY) throw()
  70929. {
  70930. startX = newStartX;
  70931. startY = newStartY;
  70932. }
  70933. void Line::setStart (const Point<float>& newStart) throw()
  70934. {
  70935. startX = newStart.getX();
  70936. startY = newStart.getY();
  70937. }
  70938. void Line::setEnd (const float newEndX,
  70939. const float newEndY) throw()
  70940. {
  70941. endX = newEndX;
  70942. endY = newEndY;
  70943. }
  70944. void Line::setEnd (const Point<float>& newEnd) throw()
  70945. {
  70946. endX = newEnd.getX();
  70947. endY = newEnd.getY();
  70948. }
  70949. bool Line::operator== (const Line& other) const throw()
  70950. {
  70951. return startX == other.startX
  70952. && startY == other.startY
  70953. && endX == other.endX
  70954. && endY == other.endY;
  70955. }
  70956. bool Line::operator!= (const Line& other) const throw()
  70957. {
  70958. return startX != other.startX
  70959. || startY != other.startY
  70960. || endX != other.endX
  70961. || endY != other.endY;
  70962. }
  70963. void Line::applyTransform (const AffineTransform& transform) throw()
  70964. {
  70965. transform.transformPoint (startX, startY);
  70966. transform.transformPoint (endX, endY);
  70967. }
  70968. float Line::getLength() const throw()
  70969. {
  70970. return (float) juce_hypot (startX - endX,
  70971. startY - endY);
  70972. }
  70973. float Line::getAngle() const throw()
  70974. {
  70975. return atan2f (endX - startX,
  70976. endY - startY);
  70977. }
  70978. const Point<float> Line::getPointAlongLine (const float distanceFromStart) const throw()
  70979. {
  70980. const float alpha = distanceFromStart / getLength();
  70981. return Point<float> (startX + (endX - startX) * alpha,
  70982. startY + (endY - startY) * alpha);
  70983. }
  70984. const Point<float> Line::getPointAlongLine (const float offsetX,
  70985. const float offsetY) const throw()
  70986. {
  70987. const float dx = endX - startX;
  70988. const float dy = endY - startY;
  70989. const double length = juce_hypot (dx, dy);
  70990. if (length == 0)
  70991. return Point<float> (startX, startY);
  70992. else
  70993. return Point<float> (startX + (float) (((dx * offsetX) - (dy * offsetY)) / length),
  70994. startY + (float) (((dy * offsetX) + (dx * offsetY)) / length));
  70995. }
  70996. const Point<float> Line::getPointAlongLineProportionally (const float alpha) const throw()
  70997. {
  70998. return Point<float> (startX + (endX - startX) * alpha,
  70999. startY + (endY - startY) * alpha);
  71000. }
  71001. float Line::getDistanceFromLine (const float x,
  71002. const float y) const throw()
  71003. {
  71004. const double dx = endX - startX;
  71005. const double dy = endY - startY;
  71006. const double length = dx * dx + dy * dy;
  71007. if (length > 0)
  71008. {
  71009. const double prop = ((x - startX) * dx + (y - startY) * dy) / length;
  71010. if (prop >= 0.0f && prop < 1.0f)
  71011. {
  71012. return (float) juce_hypot (x - (startX + prop * dx),
  71013. y - (startY + prop * dy));
  71014. }
  71015. }
  71016. return (float) jmin (juce_hypot (x - startX, y - startY),
  71017. juce_hypot (x - endX, y - endY));
  71018. }
  71019. float Line::findNearestPointTo (const float x,
  71020. const float y) const throw()
  71021. {
  71022. const double dx = endX - startX;
  71023. const double dy = endY - startY;
  71024. const double length = dx * dx + dy * dy;
  71025. if (length <= 0.0)
  71026. return 0.0f;
  71027. return jlimit (0.0f, 1.0f,
  71028. (float) (((x - startX) * dx + (y - startY) * dy) / length));
  71029. }
  71030. const Line Line::withShortenedStart (const float distanceToShortenBy) const throw()
  71031. {
  71032. const float length = getLength();
  71033. return Line (getPointAlongLine (jmin (distanceToShortenBy, length)),
  71034. getEnd());
  71035. }
  71036. const Line Line::withShortenedEnd (const float distanceToShortenBy) const throw()
  71037. {
  71038. const float length = getLength();
  71039. return Line (getStart(),
  71040. getPointAlongLine (length - jmin (distanceToShortenBy, length)));
  71041. }
  71042. bool Line::clipToPath (const Path& path,
  71043. const bool keepSectionOutsidePath) throw()
  71044. {
  71045. const bool startInside = path.contains (startX, startY);
  71046. const bool endInside = path.contains (endX, endY);
  71047. if (startInside == endInside)
  71048. {
  71049. if (keepSectionOutsidePath != startInside)
  71050. {
  71051. // entirely outside the path
  71052. return false;
  71053. }
  71054. else
  71055. {
  71056. // entirely inside the path
  71057. startX = 0.0f;
  71058. startY = 0.0f;
  71059. endX = 0.0f;
  71060. endY = 0.0f;
  71061. return true;
  71062. }
  71063. }
  71064. else
  71065. {
  71066. bool changed = false;
  71067. PathFlatteningIterator iter (path, AffineTransform::identity);
  71068. while (iter.next())
  71069. {
  71070. float ix, iy;
  71071. if (intersects (Line (iter.x1, iter.y1,
  71072. iter.x2, iter.y2),
  71073. ix, iy))
  71074. {
  71075. if ((startInside && keepSectionOutsidePath)
  71076. || (endInside && ! keepSectionOutsidePath))
  71077. {
  71078. setStart (ix, iy);
  71079. }
  71080. else
  71081. {
  71082. setEnd (ix, iy);
  71083. }
  71084. changed = true;
  71085. }
  71086. }
  71087. return changed;
  71088. }
  71089. }
  71090. bool Line::intersects (const Line& line,
  71091. float& intersectionX,
  71092. float& intersectionY) const throw()
  71093. {
  71094. return juce_lineIntersection (startX, startY,
  71095. endX, endY,
  71096. line.startX, line.startY,
  71097. line.endX, line.endY,
  71098. intersectionX,
  71099. intersectionY);
  71100. }
  71101. bool Line::isVertical() const throw()
  71102. {
  71103. return startX == endX;
  71104. }
  71105. bool Line::isHorizontal() const throw()
  71106. {
  71107. return startY == endY;
  71108. }
  71109. bool Line::isPointAbove (const float x, const float y) const throw()
  71110. {
  71111. return startX != endX
  71112. && y < ((endY - startY) * (x - startX)) / (endX - startX) + startY;
  71113. }
  71114. END_JUCE_NAMESPACE
  71115. /*** End of inlined file: juce_Line.cpp ***/
  71116. /*** Start of inlined file: juce_Path.cpp ***/
  71117. BEGIN_JUCE_NAMESPACE
  71118. // tests that some co-ords aren't NaNs
  71119. #define CHECK_COORDS_ARE_VALID(x, y) \
  71120. jassert (x == x && y == y);
  71121. const float Path::lineMarker = 100001.0f;
  71122. const float Path::moveMarker = 100002.0f;
  71123. const float Path::quadMarker = 100003.0f;
  71124. const float Path::cubicMarker = 100004.0f;
  71125. const float Path::closeSubPathMarker = 100005.0f;
  71126. static const int defaultGranularity = 32;
  71127. Path::Path() throw()
  71128. : numElements (0),
  71129. pathXMin (0),
  71130. pathXMax (0),
  71131. pathYMin (0),
  71132. pathYMax (0),
  71133. useNonZeroWinding (true)
  71134. {
  71135. }
  71136. Path::~Path() throw()
  71137. {
  71138. }
  71139. Path::Path (const Path& other) throw()
  71140. : numElements (other.numElements),
  71141. pathXMin (other.pathXMin),
  71142. pathXMax (other.pathXMax),
  71143. pathYMin (other.pathYMin),
  71144. pathYMax (other.pathYMax),
  71145. useNonZeroWinding (other.useNonZeroWinding)
  71146. {
  71147. if (numElements > 0)
  71148. {
  71149. data.setAllocatedSize (numElements);
  71150. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  71151. }
  71152. }
  71153. Path& Path::operator= (const Path& other) throw()
  71154. {
  71155. if (this != &other)
  71156. {
  71157. data.ensureAllocatedSize (other.numElements);
  71158. numElements = other.numElements;
  71159. pathXMin = other.pathXMin;
  71160. pathXMax = other.pathXMax;
  71161. pathYMin = other.pathYMin;
  71162. pathYMax = other.pathYMax;
  71163. useNonZeroWinding = other.useNonZeroWinding;
  71164. if (numElements > 0)
  71165. memcpy (data.elements, other.data.elements, numElements * sizeof (float));
  71166. }
  71167. return *this;
  71168. }
  71169. void Path::clear() throw()
  71170. {
  71171. numElements = 0;
  71172. pathXMin = 0;
  71173. pathYMin = 0;
  71174. pathYMax = 0;
  71175. pathXMax = 0;
  71176. }
  71177. void Path::swapWithPath (Path& other)
  71178. {
  71179. data.swapWith (other.data);
  71180. swapVariables <int> (numElements, other.numElements);
  71181. swapVariables <float> (pathXMin, other.pathXMin);
  71182. swapVariables <float> (pathXMax, other.pathXMax);
  71183. swapVariables <float> (pathYMin, other.pathYMin);
  71184. swapVariables <float> (pathYMax, other.pathYMax);
  71185. swapVariables <bool> (useNonZeroWinding, other.useNonZeroWinding);
  71186. }
  71187. void Path::setUsingNonZeroWinding (const bool isNonZero) throw()
  71188. {
  71189. useNonZeroWinding = isNonZero;
  71190. }
  71191. void Path::scaleToFit (const float x, const float y, const float w, const float h,
  71192. const bool preserveProportions) throw()
  71193. {
  71194. applyTransform (getTransformToScaleToFit (x, y, w, h, preserveProportions));
  71195. }
  71196. bool Path::isEmpty() const throw()
  71197. {
  71198. int i = 0;
  71199. while (i < numElements)
  71200. {
  71201. const float type = data.elements [i++];
  71202. if (type == moveMarker)
  71203. {
  71204. i += 2;
  71205. }
  71206. else if (type == lineMarker
  71207. || type == quadMarker
  71208. || type == cubicMarker)
  71209. {
  71210. return false;
  71211. }
  71212. }
  71213. return true;
  71214. }
  71215. const Rectangle<float> Path::getBounds () const throw()
  71216. {
  71217. return Rectangle<float> (pathXMin, pathYMin,
  71218. pathXMax - pathXMin,
  71219. pathYMax - pathYMin);
  71220. }
  71221. const Rectangle<float> Path::getBoundsTransformed (const AffineTransform& transform) const throw()
  71222. {
  71223. return getBounds().transformed (transform);
  71224. }
  71225. void Path::startNewSubPath (const float x,
  71226. const float y) throw()
  71227. {
  71228. CHECK_COORDS_ARE_VALID (x, y);
  71229. if (numElements == 0)
  71230. {
  71231. pathXMin = pathXMax = x;
  71232. pathYMin = pathYMax = y;
  71233. }
  71234. else
  71235. {
  71236. pathXMin = jmin (pathXMin, x);
  71237. pathXMax = jmax (pathXMax, x);
  71238. pathYMin = jmin (pathYMin, y);
  71239. pathYMax = jmax (pathYMax, y);
  71240. }
  71241. data.ensureAllocatedSize (numElements + 3);
  71242. data.elements [numElements++] = moveMarker;
  71243. data.elements [numElements++] = x;
  71244. data.elements [numElements++] = y;
  71245. }
  71246. void Path::lineTo (const float x, const float y) throw()
  71247. {
  71248. CHECK_COORDS_ARE_VALID (x, y);
  71249. if (numElements == 0)
  71250. startNewSubPath (0, 0);
  71251. data.ensureAllocatedSize (numElements + 3);
  71252. data.elements [numElements++] = lineMarker;
  71253. data.elements [numElements++] = x;
  71254. data.elements [numElements++] = y;
  71255. pathXMin = jmin (pathXMin, x);
  71256. pathXMax = jmax (pathXMax, x);
  71257. pathYMin = jmin (pathYMin, y);
  71258. pathYMax = jmax (pathYMax, y);
  71259. }
  71260. void Path::quadraticTo (const float x1, const float y1,
  71261. const float x2, const float y2) throw()
  71262. {
  71263. CHECK_COORDS_ARE_VALID (x1, y1);
  71264. CHECK_COORDS_ARE_VALID (x2, y2);
  71265. if (numElements == 0)
  71266. startNewSubPath (0, 0);
  71267. data.ensureAllocatedSize (numElements + 5);
  71268. data.elements [numElements++] = quadMarker;
  71269. data.elements [numElements++] = x1;
  71270. data.elements [numElements++] = y1;
  71271. data.elements [numElements++] = x2;
  71272. data.elements [numElements++] = y2;
  71273. pathXMin = jmin (pathXMin, x1, x2);
  71274. pathXMax = jmax (pathXMax, x1, x2);
  71275. pathYMin = jmin (pathYMin, y1, y2);
  71276. pathYMax = jmax (pathYMax, y1, y2);
  71277. }
  71278. void Path::cubicTo (const float x1, const float y1,
  71279. const float x2, const float y2,
  71280. const float x3, const float y3) throw()
  71281. {
  71282. CHECK_COORDS_ARE_VALID (x1, y1);
  71283. CHECK_COORDS_ARE_VALID (x2, y2);
  71284. CHECK_COORDS_ARE_VALID (x3, y3);
  71285. if (numElements == 0)
  71286. startNewSubPath (0, 0);
  71287. data.ensureAllocatedSize (numElements + 7);
  71288. data.elements [numElements++] = cubicMarker;
  71289. data.elements [numElements++] = x1;
  71290. data.elements [numElements++] = y1;
  71291. data.elements [numElements++] = x2;
  71292. data.elements [numElements++] = y2;
  71293. data.elements [numElements++] = x3;
  71294. data.elements [numElements++] = y3;
  71295. pathXMin = jmin (pathXMin, x1, x2, x3);
  71296. pathXMax = jmax (pathXMax, x1, x2, x3);
  71297. pathYMin = jmin (pathYMin, y1, y2, y3);
  71298. pathYMax = jmax (pathYMax, y1, y2, y3);
  71299. }
  71300. void Path::closeSubPath() throw()
  71301. {
  71302. if (numElements > 0
  71303. && data.elements [numElements - 1] != closeSubPathMarker)
  71304. {
  71305. data.ensureAllocatedSize (numElements + 1);
  71306. data.elements [numElements++] = closeSubPathMarker;
  71307. }
  71308. }
  71309. const Point<float> Path::getCurrentPosition() const
  71310. {
  71311. int i = numElements - 1;
  71312. if (i > 0 && data.elements[i] == closeSubPathMarker)
  71313. {
  71314. while (i >= 0)
  71315. {
  71316. if (data.elements[i] == moveMarker)
  71317. {
  71318. i += 2;
  71319. break;
  71320. }
  71321. --i;
  71322. }
  71323. }
  71324. if (i > 0)
  71325. return Point<float> (data.elements [i - 1], data.elements [i]);
  71326. return Point<float>();
  71327. }
  71328. void Path::addRectangle (const float x, const float y,
  71329. const float w, const float h) throw()
  71330. {
  71331. float x1 = x, y1 = y, x2 = x + w, y2 = y + h;
  71332. if (w < 0)
  71333. swapVariables (x1, x2);
  71334. if (h < 0)
  71335. swapVariables (y1, y2);
  71336. data.ensureAllocatedSize (numElements + 13);
  71337. if (numElements == 0)
  71338. {
  71339. pathXMin = x1;
  71340. pathXMax = x2;
  71341. pathYMin = y1;
  71342. pathYMax = y2;
  71343. }
  71344. else
  71345. {
  71346. pathXMin = jmin (pathXMin, x1);
  71347. pathXMax = jmax (pathXMax, x2);
  71348. pathYMin = jmin (pathYMin, y1);
  71349. pathYMax = jmax (pathYMax, y2);
  71350. }
  71351. data.elements [numElements++] = moveMarker;
  71352. data.elements [numElements++] = x1;
  71353. data.elements [numElements++] = y2;
  71354. data.elements [numElements++] = lineMarker;
  71355. data.elements [numElements++] = x1;
  71356. data.elements [numElements++] = y1;
  71357. data.elements [numElements++] = lineMarker;
  71358. data.elements [numElements++] = x2;
  71359. data.elements [numElements++] = y1;
  71360. data.elements [numElements++] = lineMarker;
  71361. data.elements [numElements++] = x2;
  71362. data.elements [numElements++] = y2;
  71363. data.elements [numElements++] = closeSubPathMarker;
  71364. }
  71365. void Path::addRectangle (const Rectangle<int>& rectangle) throw()
  71366. {
  71367. addRectangle ((float) rectangle.getX(), (float) rectangle.getY(),
  71368. (float) rectangle.getWidth(), (float) rectangle.getHeight());
  71369. }
  71370. void Path::addRoundedRectangle (const float x, const float y,
  71371. const float w, const float h,
  71372. float csx,
  71373. float csy) throw()
  71374. {
  71375. csx = jmin (csx, w * 0.5f);
  71376. csy = jmin (csy, h * 0.5f);
  71377. const float cs45x = csx * 0.45f;
  71378. const float cs45y = csy * 0.45f;
  71379. const float x2 = x + w;
  71380. const float y2 = y + h;
  71381. startNewSubPath (x + csx, y);
  71382. lineTo (x2 - csx, y);
  71383. cubicTo (x2 - cs45x, y, x2, y + cs45y, x2, y + csy);
  71384. lineTo (x2, y2 - csy);
  71385. cubicTo (x2, y2 - cs45y, x2 - cs45x, y2, x2 - csx, y2);
  71386. lineTo (x + csx, y2);
  71387. cubicTo (x + cs45x, y2, x, y2 - cs45y, x, y2 - csy);
  71388. lineTo (x, y + csy);
  71389. cubicTo (x, y + cs45y, x + cs45x, y, x + csx, y);
  71390. closeSubPath();
  71391. }
  71392. void Path::addRoundedRectangle (const float x, const float y,
  71393. const float w, const float h,
  71394. float cs) throw()
  71395. {
  71396. addRoundedRectangle (x, y, w, h, cs, cs);
  71397. }
  71398. void Path::addTriangle (const float x1, const float y1,
  71399. const float x2, const float y2,
  71400. const float x3, const float y3) throw()
  71401. {
  71402. startNewSubPath (x1, y1);
  71403. lineTo (x2, y2);
  71404. lineTo (x3, y3);
  71405. closeSubPath();
  71406. }
  71407. void Path::addQuadrilateral (const float x1, const float y1,
  71408. const float x2, const float y2,
  71409. const float x3, const float y3,
  71410. const float x4, const float y4) throw()
  71411. {
  71412. startNewSubPath (x1, y1);
  71413. lineTo (x2, y2);
  71414. lineTo (x3, y3);
  71415. lineTo (x4, y4);
  71416. closeSubPath();
  71417. }
  71418. void Path::addEllipse (const float x, const float y,
  71419. const float w, const float h) throw()
  71420. {
  71421. const float hw = w * 0.5f;
  71422. const float hw55 = hw * 0.55f;
  71423. const float hh = h * 0.5f;
  71424. const float hh45 = hh * 0.55f;
  71425. const float cx = x + hw;
  71426. const float cy = y + hh;
  71427. startNewSubPath (cx, cy - hh);
  71428. cubicTo (cx + hw55, cy - hh, cx + hw, cy - hh45, cx + hw, cy);
  71429. cubicTo (cx + hw, cy + hh45, cx + hw55, cy + hh, cx, cy + hh);
  71430. cubicTo (cx - hw55, cy + hh, cx - hw, cy + hh45, cx - hw, cy);
  71431. cubicTo (cx - hw, cy - hh45, cx - hw55, cy - hh, cx, cy - hh);
  71432. closeSubPath();
  71433. }
  71434. void Path::addArc (const float x, const float y,
  71435. const float w, const float h,
  71436. const float fromRadians,
  71437. const float toRadians,
  71438. const bool startAsNewSubPath) throw()
  71439. {
  71440. const float radiusX = w / 2.0f;
  71441. const float radiusY = h / 2.0f;
  71442. addCentredArc (x + radiusX,
  71443. y + radiusY,
  71444. radiusX, radiusY,
  71445. 0.0f,
  71446. fromRadians, toRadians,
  71447. startAsNewSubPath);
  71448. }
  71449. static const float ellipseAngularIncrement = 0.05f;
  71450. void Path::addCentredArc (const float centreX, const float centreY,
  71451. const float radiusX, const float radiusY,
  71452. const float rotationOfEllipse,
  71453. const float fromRadians,
  71454. const float toRadians,
  71455. const bool startAsNewSubPath) throw()
  71456. {
  71457. if (radiusX > 0.0f && radiusY > 0.0f)
  71458. {
  71459. const AffineTransform rotation (AffineTransform::rotation (rotationOfEllipse, centreX, centreY));
  71460. float angle = fromRadians;
  71461. if (startAsNewSubPath)
  71462. {
  71463. float x = centreX + radiusX * sinf (angle);
  71464. float y = centreY - radiusY * cosf (angle);
  71465. if (rotationOfEllipse != 0)
  71466. rotation.transformPoint (x, y);
  71467. startNewSubPath (x, y);
  71468. }
  71469. if (fromRadians < toRadians)
  71470. {
  71471. if (startAsNewSubPath)
  71472. angle += ellipseAngularIncrement;
  71473. while (angle < toRadians)
  71474. {
  71475. float x = centreX + radiusX * sinf (angle);
  71476. float y = centreY - radiusY * cosf (angle);
  71477. if (rotationOfEllipse != 0)
  71478. rotation.transformPoint (x, y);
  71479. lineTo (x, y);
  71480. angle += ellipseAngularIncrement;
  71481. }
  71482. }
  71483. else
  71484. {
  71485. if (startAsNewSubPath)
  71486. angle -= ellipseAngularIncrement;
  71487. while (angle > toRadians)
  71488. {
  71489. float x = centreX + radiusX * sinf (angle);
  71490. float y = centreY - radiusY * cosf (angle);
  71491. if (rotationOfEllipse != 0)
  71492. rotation.transformPoint (x, y);
  71493. lineTo (x, y);
  71494. angle -= ellipseAngularIncrement;
  71495. }
  71496. }
  71497. float x = centreX + radiusX * sinf (toRadians);
  71498. float y = centreY - radiusY * cosf (toRadians);
  71499. if (rotationOfEllipse != 0)
  71500. rotation.transformPoint (x, y);
  71501. lineTo (x, y);
  71502. }
  71503. }
  71504. void Path::addPieSegment (const float x, const float y,
  71505. const float width, const float height,
  71506. const float fromRadians,
  71507. const float toRadians,
  71508. const float innerCircleProportionalSize)
  71509. {
  71510. float hw = width * 0.5f;
  71511. float hh = height * 0.5f;
  71512. const float centreX = x + hw;
  71513. const float centreY = y + hh;
  71514. startNewSubPath (centreX + hw * sinf (fromRadians),
  71515. centreY - hh * cosf (fromRadians));
  71516. addArc (x, y, width, height, fromRadians, toRadians);
  71517. if (fabs (fromRadians - toRadians) > float_Pi * 1.999f)
  71518. {
  71519. closeSubPath();
  71520. if (innerCircleProportionalSize > 0)
  71521. {
  71522. hw *= innerCircleProportionalSize;
  71523. hh *= innerCircleProportionalSize;
  71524. startNewSubPath (centreX + hw * sinf (toRadians),
  71525. centreY - hh * cosf (toRadians));
  71526. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71527. toRadians, fromRadians);
  71528. }
  71529. }
  71530. else
  71531. {
  71532. if (innerCircleProportionalSize > 0)
  71533. {
  71534. hw *= innerCircleProportionalSize;
  71535. hh *= innerCircleProportionalSize;
  71536. addArc (centreX - hw, centreY - hh, hw * 2.0f, hh * 2.0f,
  71537. toRadians, fromRadians);
  71538. }
  71539. else
  71540. {
  71541. lineTo (centreX, centreY);
  71542. }
  71543. }
  71544. closeSubPath();
  71545. }
  71546. static void perpendicularOffset (const float x1, const float y1,
  71547. const float x2, const float y2,
  71548. const float offsetX, const float offsetY,
  71549. float& resultX, float& resultY) throw()
  71550. {
  71551. const float dx = x2 - x1;
  71552. const float dy = y2 - y1;
  71553. const float len = juce_hypotf (dx, dy);
  71554. if (len == 0)
  71555. {
  71556. resultX = x1;
  71557. resultY = y1;
  71558. }
  71559. else
  71560. {
  71561. resultX = x1 + ((dx * offsetX) - (dy * offsetY)) / len;
  71562. resultY = y1 + ((dy * offsetX) + (dx * offsetY)) / len;
  71563. }
  71564. }
  71565. void Path::addLineSegment (const float startX, const float startY,
  71566. const float endX, const float endY,
  71567. float lineThickness) throw()
  71568. {
  71569. lineThickness *= 0.5f;
  71570. float x, y;
  71571. perpendicularOffset (startX, startY, endX, endY,
  71572. 0, lineThickness, x, y);
  71573. startNewSubPath (x, y);
  71574. perpendicularOffset (startX, startY, endX, endY,
  71575. 0, -lineThickness, x, y);
  71576. lineTo (x, y);
  71577. perpendicularOffset (endX, endY, startX, startY,
  71578. 0, lineThickness, x, y);
  71579. lineTo (x, y);
  71580. perpendicularOffset (endX, endY, startX, startY,
  71581. 0, -lineThickness, x, y);
  71582. lineTo (x, y);
  71583. closeSubPath();
  71584. }
  71585. void Path::addArrow (const float startX, const float startY,
  71586. const float endX, const float endY,
  71587. float lineThickness,
  71588. float arrowheadWidth,
  71589. float arrowheadLength) throw()
  71590. {
  71591. lineThickness *= 0.5f;
  71592. arrowheadWidth *= 0.5f;
  71593. arrowheadLength = jmin (arrowheadLength, 0.8f * juce_hypotf (startX - endX,
  71594. startY - endY));
  71595. float x, y;
  71596. perpendicularOffset (startX, startY, endX, endY,
  71597. 0, lineThickness, x, y);
  71598. startNewSubPath (x, y);
  71599. perpendicularOffset (startX, startY, endX, endY,
  71600. 0, -lineThickness, x, y);
  71601. lineTo (x, y);
  71602. perpendicularOffset (endX, endY, startX, startY,
  71603. arrowheadLength, lineThickness, x, y);
  71604. lineTo (x, y);
  71605. perpendicularOffset (endX, endY, startX, startY,
  71606. arrowheadLength, arrowheadWidth, x, y);
  71607. lineTo (x, y);
  71608. perpendicularOffset (endX, endY, startX, startY,
  71609. 0, 0, x, y);
  71610. lineTo (x, y);
  71611. perpendicularOffset (endX, endY, startX, startY,
  71612. arrowheadLength, -arrowheadWidth, x, y);
  71613. lineTo (x, y);
  71614. perpendicularOffset (endX, endY, startX, startY,
  71615. arrowheadLength, -lineThickness, x, y);
  71616. lineTo (x, y);
  71617. closeSubPath();
  71618. }
  71619. void Path::addStar (const float centreX,
  71620. const float centreY,
  71621. const int numberOfPoints,
  71622. const float innerRadius,
  71623. const float outerRadius,
  71624. const float startAngle)
  71625. {
  71626. jassert (numberOfPoints > 1); // this would be silly.
  71627. if (numberOfPoints > 1)
  71628. {
  71629. const float angleBetweenPoints = float_Pi * 2.0f / numberOfPoints;
  71630. for (int i = 0; i < numberOfPoints; ++i)
  71631. {
  71632. float angle = startAngle + i * angleBetweenPoints;
  71633. const float x = centreX + outerRadius * sinf (angle);
  71634. const float y = centreY - outerRadius * cosf (angle);
  71635. if (i == 0)
  71636. startNewSubPath (x, y);
  71637. else
  71638. lineTo (x, y);
  71639. angle += angleBetweenPoints * 0.5f;
  71640. lineTo (centreX + innerRadius * sinf (angle),
  71641. centreY - innerRadius * cosf (angle));
  71642. }
  71643. closeSubPath();
  71644. }
  71645. }
  71646. void Path::addBubble (float x, float y,
  71647. float w, float h,
  71648. float cs,
  71649. float tipX,
  71650. float tipY,
  71651. int whichSide,
  71652. float arrowPos,
  71653. float arrowWidth)
  71654. {
  71655. if (w > 1.0f && h > 1.0f)
  71656. {
  71657. cs = jmin (cs, w * 0.5f, h * 0.5f);
  71658. const float cs2 = 2.0f * cs;
  71659. startNewSubPath (x + cs, y);
  71660. if (whichSide == 0)
  71661. {
  71662. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71663. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71664. lineTo (arrowX1, y);
  71665. lineTo (tipX, tipY);
  71666. lineTo (arrowX1 + halfArrowW * 2.0f, y);
  71667. }
  71668. lineTo (x + w - cs, y);
  71669. if (cs > 0.0f)
  71670. addArc (x + w - cs2, y, cs2, cs2, 0, float_Pi * 0.5f);
  71671. if (whichSide == 3)
  71672. {
  71673. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71674. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71675. lineTo (x + w, arrowY1);
  71676. lineTo (tipX, tipY);
  71677. lineTo (x + w, arrowY1 + halfArrowH * 2.0f);
  71678. }
  71679. lineTo (x + w, y + h - cs);
  71680. if (cs > 0.0f)
  71681. addArc (x + w - cs2, y + h - cs2, cs2, cs2, float_Pi * 0.5f, float_Pi);
  71682. if (whichSide == 2)
  71683. {
  71684. const float halfArrowW = jmin (arrowWidth, w - cs2) * 0.5f;
  71685. const float arrowX1 = x + cs + jmax (0.0f, (w - cs2) * arrowPos - halfArrowW);
  71686. lineTo (arrowX1 + halfArrowW * 2.0f, y + h);
  71687. lineTo (tipX, tipY);
  71688. lineTo (arrowX1, y + h);
  71689. }
  71690. lineTo (x + cs, y + h);
  71691. if (cs > 0.0f)
  71692. addArc (x, y + h - cs2, cs2, cs2, float_Pi, float_Pi * 1.5f);
  71693. if (whichSide == 1)
  71694. {
  71695. const float halfArrowH = jmin (arrowWidth, h - cs2) * 0.5f;
  71696. const float arrowY1 = y + cs + jmax (0.0f, (h - cs2) * arrowPos - halfArrowH);
  71697. lineTo (x, arrowY1 + halfArrowH * 2.0f);
  71698. lineTo (tipX, tipY);
  71699. lineTo (x, arrowY1);
  71700. }
  71701. lineTo (x, y + cs);
  71702. if (cs > 0.0f)
  71703. addArc (x, y, cs2, cs2, float_Pi * 1.5f, float_Pi * 2.0f - ellipseAngularIncrement);
  71704. closeSubPath();
  71705. }
  71706. }
  71707. void Path::addPath (const Path& other) throw()
  71708. {
  71709. int i = 0;
  71710. while (i < other.numElements)
  71711. {
  71712. const float type = other.data.elements [i++];
  71713. if (type == moveMarker)
  71714. {
  71715. startNewSubPath (other.data.elements [i],
  71716. other.data.elements [i + 1]);
  71717. i += 2;
  71718. }
  71719. else if (type == lineMarker)
  71720. {
  71721. lineTo (other.data.elements [i],
  71722. other.data.elements [i + 1]);
  71723. i += 2;
  71724. }
  71725. else if (type == quadMarker)
  71726. {
  71727. quadraticTo (other.data.elements [i],
  71728. other.data.elements [i + 1],
  71729. other.data.elements [i + 2],
  71730. other.data.elements [i + 3]);
  71731. i += 4;
  71732. }
  71733. else if (type == cubicMarker)
  71734. {
  71735. cubicTo (other.data.elements [i],
  71736. other.data.elements [i + 1],
  71737. other.data.elements [i + 2],
  71738. other.data.elements [i + 3],
  71739. other.data.elements [i + 4],
  71740. other.data.elements [i + 5]);
  71741. i += 6;
  71742. }
  71743. else if (type == closeSubPathMarker)
  71744. {
  71745. closeSubPath();
  71746. }
  71747. else
  71748. {
  71749. // something's gone wrong with the element list!
  71750. jassertfalse
  71751. }
  71752. }
  71753. }
  71754. void Path::addPath (const Path& other,
  71755. const AffineTransform& transformToApply) throw()
  71756. {
  71757. int i = 0;
  71758. while (i < other.numElements)
  71759. {
  71760. const float type = other.data.elements [i++];
  71761. if (type == closeSubPathMarker)
  71762. {
  71763. closeSubPath();
  71764. }
  71765. else
  71766. {
  71767. float x = other.data.elements [i++];
  71768. float y = other.data.elements [i++];
  71769. transformToApply.transformPoint (x, y);
  71770. if (type == moveMarker)
  71771. {
  71772. startNewSubPath (x, y);
  71773. }
  71774. else if (type == lineMarker)
  71775. {
  71776. lineTo (x, y);
  71777. }
  71778. else if (type == quadMarker)
  71779. {
  71780. float x2 = other.data.elements [i++];
  71781. float y2 = other.data.elements [i++];
  71782. transformToApply.transformPoint (x2, y2);
  71783. quadraticTo (x, y, x2, y2);
  71784. }
  71785. else if (type == cubicMarker)
  71786. {
  71787. float x2 = other.data.elements [i++];
  71788. float y2 = other.data.elements [i++];
  71789. float x3 = other.data.elements [i++];
  71790. float y3 = other.data.elements [i++];
  71791. transformToApply.transformPoint (x2, y2);
  71792. transformToApply.transformPoint (x3, y3);
  71793. cubicTo (x, y, x2, y2, x3, y3);
  71794. }
  71795. else
  71796. {
  71797. // something's gone wrong with the element list!
  71798. jassertfalse
  71799. }
  71800. }
  71801. }
  71802. }
  71803. void Path::applyTransform (const AffineTransform& transform) throw()
  71804. {
  71805. int i = 0;
  71806. pathYMin = pathXMin = 0;
  71807. pathYMax = pathXMax = 0;
  71808. bool setMaxMin = false;
  71809. while (i < numElements)
  71810. {
  71811. const float type = data.elements [i++];
  71812. if (type == moveMarker)
  71813. {
  71814. transform.transformPoint (data.elements [i],
  71815. data.elements [i + 1]);
  71816. if (setMaxMin)
  71817. {
  71818. pathXMin = jmin (pathXMin, data.elements [i]);
  71819. pathXMax = jmax (pathXMax, data.elements [i]);
  71820. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71821. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71822. }
  71823. else
  71824. {
  71825. pathXMin = pathXMax = data.elements [i];
  71826. pathYMin = pathYMax = data.elements [i + 1];
  71827. setMaxMin = true;
  71828. }
  71829. i += 2;
  71830. }
  71831. else if (type == lineMarker)
  71832. {
  71833. transform.transformPoint (data.elements [i],
  71834. data.elements [i + 1]);
  71835. pathXMin = jmin (pathXMin, data.elements [i]);
  71836. pathXMax = jmax (pathXMax, data.elements [i]);
  71837. pathYMin = jmin (pathYMin, data.elements [i + 1]);
  71838. pathYMax = jmax (pathYMax, data.elements [i + 1]);
  71839. i += 2;
  71840. }
  71841. else if (type == quadMarker)
  71842. {
  71843. transform.transformPoint (data.elements [i],
  71844. data.elements [i + 1]);
  71845. transform.transformPoint (data.elements [i + 2],
  71846. data.elements [i + 3]);
  71847. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2]);
  71848. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2]);
  71849. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3]);
  71850. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3]);
  71851. i += 4;
  71852. }
  71853. else if (type == cubicMarker)
  71854. {
  71855. transform.transformPoint (data.elements [i],
  71856. data.elements [i + 1]);
  71857. transform.transformPoint (data.elements [i + 2],
  71858. data.elements [i + 3]);
  71859. transform.transformPoint (data.elements [i + 4],
  71860. data.elements [i + 5]);
  71861. pathXMin = jmin (pathXMin, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71862. pathXMax = jmax (pathXMax, data.elements [i], data.elements [i + 2], data.elements [i + 4]);
  71863. pathYMin = jmin (pathYMin, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71864. pathYMax = jmax (pathYMax, data.elements [i + 1], data.elements [i + 3], data.elements [i + 5]);
  71865. i += 6;
  71866. }
  71867. }
  71868. }
  71869. const AffineTransform Path::getTransformToScaleToFit (const float x, const float y,
  71870. const float w, const float h,
  71871. const bool preserveProportions,
  71872. const Justification& justification) const throw()
  71873. {
  71874. Rectangle<float> bounds (getBounds());
  71875. if (preserveProportions)
  71876. {
  71877. if (w <= 0 || h <= 0 || bounds.isEmpty())
  71878. return AffineTransform::identity;
  71879. float newW, newH;
  71880. const float srcRatio = bounds.getHeight() / bounds.getWidth();
  71881. if (srcRatio > h / w)
  71882. {
  71883. newW = h / srcRatio;
  71884. newH = h;
  71885. }
  71886. else
  71887. {
  71888. newW = w;
  71889. newH = w * srcRatio;
  71890. }
  71891. float newXCentre = x;
  71892. float newYCentre = y;
  71893. if (justification.testFlags (Justification::left))
  71894. newXCentre += newW * 0.5f;
  71895. else if (justification.testFlags (Justification::right))
  71896. newXCentre += w - newW * 0.5f;
  71897. else
  71898. newXCentre += w * 0.5f;
  71899. if (justification.testFlags (Justification::top))
  71900. newYCentre += newH * 0.5f;
  71901. else if (justification.testFlags (Justification::bottom))
  71902. newYCentre += h - newH * 0.5f;
  71903. else
  71904. newYCentre += h * 0.5f;
  71905. return AffineTransform::translation (bounds.getWidth() * -0.5f - bounds.getX(),
  71906. bounds.getHeight() * -0.5f - bounds.getY())
  71907. .scaled (newW / bounds.getWidth(), newH / bounds.getHeight())
  71908. .translated (newXCentre, newYCentre);
  71909. }
  71910. else
  71911. {
  71912. return AffineTransform::translation (-bounds.getX(), -bounds.getY())
  71913. .scaled (w / bounds.getWidth(), h / bounds.getHeight())
  71914. .translated (x, y);
  71915. }
  71916. }
  71917. bool Path::contains (const float x, const float y, const float tolerence) const throw()
  71918. {
  71919. if (x <= pathXMin || x >= pathXMax
  71920. || y <= pathYMin || y >= pathYMax)
  71921. return false;
  71922. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71923. int positiveCrossings = 0;
  71924. int negativeCrossings = 0;
  71925. while (i.next())
  71926. {
  71927. if ((i.y1 <= y && i.y2 > y)
  71928. || (i.y2 <= y && i.y1 > y))
  71929. {
  71930. const float intersectX = i.x1 + (i.x2 - i.x1) * (y - i.y1) / (i.y2 - i.y1);
  71931. if (intersectX <= x)
  71932. {
  71933. if (i.y1 < i.y2)
  71934. ++positiveCrossings;
  71935. else
  71936. ++negativeCrossings;
  71937. }
  71938. }
  71939. }
  71940. return (useNonZeroWinding) ? (negativeCrossings != positiveCrossings)
  71941. : ((negativeCrossings + positiveCrossings) & 1) != 0;
  71942. }
  71943. bool Path::intersectsLine (const float x1, const float y1,
  71944. const float x2, const float y2,
  71945. const float tolerence) throw()
  71946. {
  71947. PathFlatteningIterator i (*this, AffineTransform::identity, tolerence);
  71948. const Line line1 (x1, y1, x2, y2);
  71949. while (i.next())
  71950. {
  71951. const Line line2 (i.x1, i.y1, i.x2, i.y2);
  71952. float ix, iy;
  71953. if (line1.intersects (line2, ix, iy))
  71954. return true;
  71955. }
  71956. return false;
  71957. }
  71958. const Path Path::createPathWithRoundedCorners (const float cornerRadius) const throw()
  71959. {
  71960. if (cornerRadius <= 0.01f)
  71961. return *this;
  71962. int indexOfPathStart = 0, indexOfPathStartThis = 0;
  71963. int n = 0;
  71964. bool lastWasLine = false, firstWasLine = false;
  71965. Path p;
  71966. while (n < numElements)
  71967. {
  71968. const float type = data.elements [n++];
  71969. if (type == moveMarker)
  71970. {
  71971. indexOfPathStart = p.numElements;
  71972. indexOfPathStartThis = n - 1;
  71973. const float x = data.elements [n++];
  71974. const float y = data.elements [n++];
  71975. p.startNewSubPath (x, y);
  71976. lastWasLine = false;
  71977. firstWasLine = (data.elements [n] == lineMarker);
  71978. }
  71979. else if (type == lineMarker || type == closeSubPathMarker)
  71980. {
  71981. float startX = 0, startY = 0, joinX = 0, joinY = 0, endX, endY;
  71982. if (type == lineMarker)
  71983. {
  71984. endX = data.elements [n++];
  71985. endY = data.elements [n++];
  71986. if (n > 8)
  71987. {
  71988. startX = data.elements [n - 8];
  71989. startY = data.elements [n - 7];
  71990. joinX = data.elements [n - 5];
  71991. joinY = data.elements [n - 4];
  71992. }
  71993. }
  71994. else
  71995. {
  71996. endX = data.elements [indexOfPathStartThis + 1];
  71997. endY = data.elements [indexOfPathStartThis + 2];
  71998. if (n > 6)
  71999. {
  72000. startX = data.elements [n - 6];
  72001. startY = data.elements [n - 5];
  72002. joinX = data.elements [n - 3];
  72003. joinY = data.elements [n - 2];
  72004. }
  72005. }
  72006. if (lastWasLine)
  72007. {
  72008. const double len1 = juce_hypot (startX - joinX,
  72009. startY - joinY);
  72010. if (len1 > 0)
  72011. {
  72012. const double propNeeded = jmin (0.5, cornerRadius / len1);
  72013. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  72014. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  72015. }
  72016. const double len2 = juce_hypot (endX - joinX,
  72017. endY - joinY);
  72018. if (len2 > 0)
  72019. {
  72020. const double propNeeded = jmin (0.5, cornerRadius / len2);
  72021. p.quadraticTo (joinX, joinY,
  72022. (float) (joinX + (endX - joinX) * propNeeded),
  72023. (float) (joinY + (endY - joinY) * propNeeded));
  72024. }
  72025. p.lineTo (endX, endY);
  72026. }
  72027. else if (type == lineMarker)
  72028. {
  72029. p.lineTo (endX, endY);
  72030. lastWasLine = true;
  72031. }
  72032. if (type == closeSubPathMarker)
  72033. {
  72034. if (firstWasLine)
  72035. {
  72036. startX = data.elements [n - 3];
  72037. startY = data.elements [n - 2];
  72038. joinX = endX;
  72039. joinY = endY;
  72040. endX = data.elements [indexOfPathStartThis + 4];
  72041. endY = data.elements [indexOfPathStartThis + 5];
  72042. const double len1 = juce_hypot (startX - joinX,
  72043. startY - joinY);
  72044. if (len1 > 0)
  72045. {
  72046. const double propNeeded = jmin (0.5, cornerRadius / len1);
  72047. p.data.elements [p.numElements - 2] = (float) (joinX - (joinX - startX) * propNeeded);
  72048. p.data.elements [p.numElements - 1] = (float) (joinY - (joinY - startY) * propNeeded);
  72049. }
  72050. const double len2 = juce_hypot (endX - joinX,
  72051. endY - joinY);
  72052. if (len2 > 0)
  72053. {
  72054. const double propNeeded = jmin (0.5, cornerRadius / len2);
  72055. endX = (float) (joinX + (endX - joinX) * propNeeded);
  72056. endY = (float) (joinY + (endY - joinY) * propNeeded);
  72057. p.quadraticTo (joinX, joinY, endX, endY);
  72058. p.data.elements [indexOfPathStart + 1] = endX;
  72059. p.data.elements [indexOfPathStart + 2] = endY;
  72060. }
  72061. }
  72062. p.closeSubPath();
  72063. }
  72064. }
  72065. else if (type == quadMarker)
  72066. {
  72067. lastWasLine = false;
  72068. const float x1 = data.elements [n++];
  72069. const float y1 = data.elements [n++];
  72070. const float x2 = data.elements [n++];
  72071. const float y2 = data.elements [n++];
  72072. p.quadraticTo (x1, y1, x2, y2);
  72073. }
  72074. else if (type == cubicMarker)
  72075. {
  72076. lastWasLine = false;
  72077. const float x1 = data.elements [n++];
  72078. const float y1 = data.elements [n++];
  72079. const float x2 = data.elements [n++];
  72080. const float y2 = data.elements [n++];
  72081. const float x3 = data.elements [n++];
  72082. const float y3 = data.elements [n++];
  72083. p.cubicTo (x1, y1, x2, y2, x3, y3);
  72084. }
  72085. }
  72086. return p;
  72087. }
  72088. void Path::loadPathFromStream (InputStream& source)
  72089. {
  72090. while (! source.isExhausted())
  72091. {
  72092. switch (source.readByte())
  72093. {
  72094. case 'm':
  72095. {
  72096. const float x = source.readFloat();
  72097. const float y = source.readFloat();
  72098. startNewSubPath (x, y);
  72099. break;
  72100. }
  72101. case 'l':
  72102. {
  72103. const float x = source.readFloat();
  72104. const float y = source.readFloat();
  72105. lineTo (x, y);
  72106. break;
  72107. }
  72108. case 'q':
  72109. {
  72110. const float x1 = source.readFloat();
  72111. const float y1 = source.readFloat();
  72112. const float x2 = source.readFloat();
  72113. const float y2 = source.readFloat();
  72114. quadraticTo (x1, y1, x2, y2);
  72115. break;
  72116. }
  72117. case 'b':
  72118. {
  72119. const float x1 = source.readFloat();
  72120. const float y1 = source.readFloat();
  72121. const float x2 = source.readFloat();
  72122. const float y2 = source.readFloat();
  72123. const float x3 = source.readFloat();
  72124. const float y3 = source.readFloat();
  72125. cubicTo (x1, y1, x2, y2, x3, y3);
  72126. break;
  72127. }
  72128. case 'c':
  72129. closeSubPath();
  72130. break;
  72131. case 'n':
  72132. useNonZeroWinding = true;
  72133. break;
  72134. case 'z':
  72135. useNonZeroWinding = false;
  72136. break;
  72137. case 'e':
  72138. return; // end of path marker
  72139. default:
  72140. jassertfalse // illegal char in the stream
  72141. break;
  72142. }
  72143. }
  72144. }
  72145. void Path::loadPathFromData (const unsigned char* const data,
  72146. const int numberOfBytes) throw()
  72147. {
  72148. MemoryInputStream in ((const char*) data, numberOfBytes, false);
  72149. loadPathFromStream (in);
  72150. }
  72151. void Path::writePathToStream (OutputStream& dest) const
  72152. {
  72153. dest.writeByte ((useNonZeroWinding) ? 'n' : 'z');
  72154. int i = 0;
  72155. while (i < numElements)
  72156. {
  72157. const float type = data.elements [i++];
  72158. if (type == moveMarker)
  72159. {
  72160. dest.writeByte ('m');
  72161. dest.writeFloat (data.elements [i++]);
  72162. dest.writeFloat (data.elements [i++]);
  72163. }
  72164. else if (type == lineMarker)
  72165. {
  72166. dest.writeByte ('l');
  72167. dest.writeFloat (data.elements [i++]);
  72168. dest.writeFloat (data.elements [i++]);
  72169. }
  72170. else if (type == quadMarker)
  72171. {
  72172. dest.writeByte ('q');
  72173. dest.writeFloat (data.elements [i++]);
  72174. dest.writeFloat (data.elements [i++]);
  72175. dest.writeFloat (data.elements [i++]);
  72176. dest.writeFloat (data.elements [i++]);
  72177. }
  72178. else if (type == cubicMarker)
  72179. {
  72180. dest.writeByte ('b');
  72181. dest.writeFloat (data.elements [i++]);
  72182. dest.writeFloat (data.elements [i++]);
  72183. dest.writeFloat (data.elements [i++]);
  72184. dest.writeFloat (data.elements [i++]);
  72185. dest.writeFloat (data.elements [i++]);
  72186. dest.writeFloat (data.elements [i++]);
  72187. }
  72188. else if (type == closeSubPathMarker)
  72189. {
  72190. dest.writeByte ('c');
  72191. }
  72192. }
  72193. dest.writeByte ('e'); // marks the end-of-path
  72194. }
  72195. const String Path::toString() const
  72196. {
  72197. MemoryOutputStream s (2048, 2048);
  72198. if (! useNonZeroWinding)
  72199. s << "a ";
  72200. int i = 0;
  72201. float lastMarker = 0.0f;
  72202. while (i < numElements)
  72203. {
  72204. const float marker = data.elements [i++];
  72205. char markerChar = 0;
  72206. int numCoords = 0;
  72207. if (marker == moveMarker)
  72208. {
  72209. markerChar = 'm';
  72210. numCoords = 2;
  72211. }
  72212. else if (marker == lineMarker)
  72213. {
  72214. markerChar = 'l';
  72215. numCoords = 2;
  72216. }
  72217. else if (marker == quadMarker)
  72218. {
  72219. markerChar = 'q';
  72220. numCoords = 4;
  72221. }
  72222. else if (marker == cubicMarker)
  72223. {
  72224. markerChar = 'c';
  72225. numCoords = 6;
  72226. }
  72227. else
  72228. {
  72229. jassert (marker == closeSubPathMarker);
  72230. markerChar = 'z';
  72231. }
  72232. if (marker != lastMarker)
  72233. {
  72234. s << markerChar << ' ';
  72235. lastMarker = marker;
  72236. }
  72237. while (--numCoords >= 0 && i < numElements)
  72238. {
  72239. String n (data.elements [i++], 3);
  72240. if (n.endsWithChar (T('0')))
  72241. {
  72242. do
  72243. {
  72244. n = n.dropLastCharacters (1);
  72245. } while (n.endsWithChar (T('0')));
  72246. if (n.endsWithChar (T('.')))
  72247. n = n.dropLastCharacters (1);
  72248. }
  72249. s << n << ' ';
  72250. }
  72251. }
  72252. const char* const result = (const char*) s.getData();
  72253. size_t len = s.getDataSize();
  72254. while (len > 0 && CharacterFunctions::isWhitespace (result [len - 1]))
  72255. --len;
  72256. return String (result, len);
  72257. }
  72258. static const String nextToken (const tchar*& t)
  72259. {
  72260. while (CharacterFunctions::isWhitespace (*t))
  72261. ++t;
  72262. const tchar* const start = t;
  72263. while (*t != 0 && ! CharacterFunctions::isWhitespace (*t))
  72264. ++t;
  72265. const int length = (int) (t - start);
  72266. while (CharacterFunctions::isWhitespace (*t))
  72267. ++t;
  72268. return String (start, length);
  72269. }
  72270. void Path::restoreFromString (const String& stringVersion)
  72271. {
  72272. clear();
  72273. setUsingNonZeroWinding (true);
  72274. const tchar* t = stringVersion;
  72275. tchar marker = T('m');
  72276. int numValues = 2;
  72277. float values [6];
  72278. while (*t != 0)
  72279. {
  72280. const String token (nextToken (t));
  72281. const tchar firstChar = token[0];
  72282. int startNum = 0;
  72283. if (firstChar == T('m') || firstChar == T('l'))
  72284. {
  72285. marker = firstChar;
  72286. numValues = 2;
  72287. }
  72288. else if (firstChar == T('q'))
  72289. {
  72290. marker = firstChar;
  72291. numValues = 4;
  72292. }
  72293. else if (firstChar == T('c'))
  72294. {
  72295. marker = firstChar;
  72296. numValues = 6;
  72297. }
  72298. else if (firstChar == T('z'))
  72299. {
  72300. marker = firstChar;
  72301. numValues = 0;
  72302. }
  72303. else if (firstChar == T('a'))
  72304. {
  72305. setUsingNonZeroWinding (false);
  72306. continue;
  72307. }
  72308. else
  72309. {
  72310. ++startNum;
  72311. values [0] = token.getFloatValue();
  72312. }
  72313. for (int i = startNum; i < numValues; ++i)
  72314. values [i] = nextToken (t).getFloatValue();
  72315. switch (marker)
  72316. {
  72317. case T('m'):
  72318. startNewSubPath (values[0], values[1]);
  72319. break;
  72320. case T('l'):
  72321. lineTo (values[0], values[1]);
  72322. break;
  72323. case T('q'):
  72324. quadraticTo (values[0], values[1],
  72325. values[2], values[3]);
  72326. break;
  72327. case T('c'):
  72328. cubicTo (values[0], values[1],
  72329. values[2], values[3],
  72330. values[4], values[5]);
  72331. break;
  72332. case T('z'):
  72333. closeSubPath();
  72334. break;
  72335. default:
  72336. jassertfalse // illegal string format?
  72337. break;
  72338. }
  72339. }
  72340. }
  72341. Path::Iterator::Iterator (const Path& path_)
  72342. : path (path_),
  72343. index (0)
  72344. {
  72345. }
  72346. Path::Iterator::~Iterator()
  72347. {
  72348. }
  72349. bool Path::Iterator::next()
  72350. {
  72351. const float* const elements = path.data.elements;
  72352. if (index < path.numElements)
  72353. {
  72354. const float type = elements [index++];
  72355. if (type == moveMarker)
  72356. {
  72357. elementType = startNewSubPath;
  72358. x1 = elements [index++];
  72359. y1 = elements [index++];
  72360. }
  72361. else if (type == lineMarker)
  72362. {
  72363. elementType = lineTo;
  72364. x1 = elements [index++];
  72365. y1 = elements [index++];
  72366. }
  72367. else if (type == quadMarker)
  72368. {
  72369. elementType = quadraticTo;
  72370. x1 = elements [index++];
  72371. y1 = elements [index++];
  72372. x2 = elements [index++];
  72373. y2 = elements [index++];
  72374. }
  72375. else if (type == cubicMarker)
  72376. {
  72377. elementType = cubicTo;
  72378. x1 = elements [index++];
  72379. y1 = elements [index++];
  72380. x2 = elements [index++];
  72381. y2 = elements [index++];
  72382. x3 = elements [index++];
  72383. y3 = elements [index++];
  72384. }
  72385. else if (type == closeSubPathMarker)
  72386. {
  72387. elementType = closePath;
  72388. }
  72389. return true;
  72390. }
  72391. return false;
  72392. }
  72393. END_JUCE_NAMESPACE
  72394. /*** End of inlined file: juce_Path.cpp ***/
  72395. /*** Start of inlined file: juce_PathIterator.cpp ***/
  72396. BEGIN_JUCE_NAMESPACE
  72397. #if JUCE_MSVC
  72398. #pragma optimize ("t", on)
  72399. #endif
  72400. PathFlatteningIterator::PathFlatteningIterator (const Path& path_,
  72401. const AffineTransform& transform_,
  72402. float tolerence_) throw()
  72403. : x2 (0),
  72404. y2 (0),
  72405. closesSubPath (false),
  72406. subPathIndex (-1),
  72407. path (path_),
  72408. transform (transform_),
  72409. points (path_.data.elements),
  72410. tolerence (tolerence_ * tolerence_),
  72411. subPathCloseX (0),
  72412. subPathCloseY (0),
  72413. stackBase (32),
  72414. index (0),
  72415. stackSize (32)
  72416. {
  72417. isIdentityTransform = transform.isIdentity();
  72418. stackPos = stackBase;
  72419. }
  72420. PathFlatteningIterator::~PathFlatteningIterator() throw()
  72421. {
  72422. }
  72423. bool PathFlatteningIterator::next() throw()
  72424. {
  72425. x1 = x2;
  72426. y1 = y2;
  72427. float x3 = 0;
  72428. float y3 = 0;
  72429. float x4 = 0;
  72430. float y4 = 0;
  72431. float type;
  72432. for (;;)
  72433. {
  72434. if (stackPos == stackBase)
  72435. {
  72436. if (index >= path.numElements)
  72437. {
  72438. return false;
  72439. }
  72440. else
  72441. {
  72442. type = points [index++];
  72443. if (type != Path::closeSubPathMarker)
  72444. {
  72445. x2 = points [index++];
  72446. y2 = points [index++];
  72447. if (! isIdentityTransform)
  72448. transform.transformPoint (x2, y2);
  72449. if (type == Path::quadMarker)
  72450. {
  72451. x3 = points [index++];
  72452. y3 = points [index++];
  72453. if (! isIdentityTransform)
  72454. transform.transformPoint (x3, y3);
  72455. }
  72456. else if (type == Path::cubicMarker)
  72457. {
  72458. x3 = points [index++];
  72459. y3 = points [index++];
  72460. x4 = points [index++];
  72461. y4 = points [index++];
  72462. if (! isIdentityTransform)
  72463. {
  72464. transform.transformPoint (x3, y3);
  72465. transform.transformPoint (x4, y4);
  72466. }
  72467. }
  72468. }
  72469. }
  72470. }
  72471. else
  72472. {
  72473. type = *--stackPos;
  72474. if (type != Path::closeSubPathMarker)
  72475. {
  72476. x2 = *--stackPos;
  72477. y2 = *--stackPos;
  72478. if (type == Path::quadMarker)
  72479. {
  72480. x3 = *--stackPos;
  72481. y3 = *--stackPos;
  72482. }
  72483. else if (type == Path::cubicMarker)
  72484. {
  72485. x3 = *--stackPos;
  72486. y3 = *--stackPos;
  72487. x4 = *--stackPos;
  72488. y4 = *--stackPos;
  72489. }
  72490. }
  72491. }
  72492. if (type == Path::lineMarker)
  72493. {
  72494. ++subPathIndex;
  72495. closesSubPath = (stackPos == stackBase)
  72496. && (index < path.numElements)
  72497. && (points [index] == Path::closeSubPathMarker)
  72498. && x2 == subPathCloseX
  72499. && y2 == subPathCloseY;
  72500. return true;
  72501. }
  72502. else if (type == Path::quadMarker)
  72503. {
  72504. const int offset = (int) (stackPos - stackBase);
  72505. if (offset >= stackSize - 10)
  72506. {
  72507. stackSize <<= 1;
  72508. stackBase.realloc (stackSize);
  72509. stackPos = stackBase + offset;
  72510. }
  72511. const float dx1 = x1 - x2;
  72512. const float dy1 = y1 - y2;
  72513. const float dx2 = x2 - x3;
  72514. const float dy2 = y2 - y3;
  72515. const float m1x = (x1 + x2) * 0.5f;
  72516. const float m1y = (y1 + y2) * 0.5f;
  72517. const float m2x = (x2 + x3) * 0.5f;
  72518. const float m2y = (y2 + y3) * 0.5f;
  72519. const float m3x = (m1x + m2x) * 0.5f;
  72520. const float m3y = (m1y + m2y) * 0.5f;
  72521. if (dx1*dx1 + dy1*dy1 + dx2*dx2 + dy2*dy2 > tolerence)
  72522. {
  72523. *stackPos++ = y3;
  72524. *stackPos++ = x3;
  72525. *stackPos++ = m2y;
  72526. *stackPos++ = m2x;
  72527. *stackPos++ = Path::quadMarker;
  72528. *stackPos++ = m3y;
  72529. *stackPos++ = m3x;
  72530. *stackPos++ = m1y;
  72531. *stackPos++ = m1x;
  72532. *stackPos++ = Path::quadMarker;
  72533. }
  72534. else
  72535. {
  72536. *stackPos++ = y3;
  72537. *stackPos++ = x3;
  72538. *stackPos++ = Path::lineMarker;
  72539. *stackPos++ = m3y;
  72540. *stackPos++ = m3x;
  72541. *stackPos++ = Path::lineMarker;
  72542. }
  72543. jassert (stackPos < stackBase + stackSize);
  72544. }
  72545. else if (type == Path::cubicMarker)
  72546. {
  72547. const int offset = (int) (stackPos - stackBase);
  72548. if (offset >= stackSize - 16)
  72549. {
  72550. stackSize <<= 1;
  72551. stackBase.realloc (stackSize);
  72552. stackPos = stackBase + offset;
  72553. }
  72554. const float dx1 = x1 - x2;
  72555. const float dy1 = y1 - y2;
  72556. const float dx2 = x2 - x3;
  72557. const float dy2 = y2 - y3;
  72558. const float dx3 = x3 - x4;
  72559. const float dy3 = y3 - y4;
  72560. const float m1x = (x1 + x2) * 0.5f;
  72561. const float m1y = (y1 + y2) * 0.5f;
  72562. const float m2x = (x3 + x2) * 0.5f;
  72563. const float m2y = (y3 + y2) * 0.5f;
  72564. const float m3x = (x3 + x4) * 0.5f;
  72565. const float m3y = (y3 + y4) * 0.5f;
  72566. const float m4x = (m1x + m2x) * 0.5f;
  72567. const float m4y = (m1y + m2y) * 0.5f;
  72568. const float m5x = (m3x + m2x) * 0.5f;
  72569. const float m5y = (m3y + m2y) * 0.5f;
  72570. if (dx1*dx1 + dy1*dy1 + dx2*dx2
  72571. + dy2*dy2 + dx3*dx3 + dy3*dy3 > tolerence)
  72572. {
  72573. *stackPos++ = y4;
  72574. *stackPos++ = x4;
  72575. *stackPos++ = m3y;
  72576. *stackPos++ = m3x;
  72577. *stackPos++ = m5y;
  72578. *stackPos++ = m5x;
  72579. *stackPos++ = Path::cubicMarker;
  72580. *stackPos++ = (m4y + m5y) * 0.5f;
  72581. *stackPos++ = (m4x + m5x) * 0.5f;
  72582. *stackPos++ = m4y;
  72583. *stackPos++ = m4x;
  72584. *stackPos++ = m1y;
  72585. *stackPos++ = m1x;
  72586. *stackPos++ = Path::cubicMarker;
  72587. }
  72588. else
  72589. {
  72590. *stackPos++ = y4;
  72591. *stackPos++ = x4;
  72592. *stackPos++ = Path::lineMarker;
  72593. *stackPos++ = m5y;
  72594. *stackPos++ = m5x;
  72595. *stackPos++ = Path::lineMarker;
  72596. *stackPos++ = m4y;
  72597. *stackPos++ = m4x;
  72598. *stackPos++ = Path::lineMarker;
  72599. }
  72600. }
  72601. else if (type == Path::closeSubPathMarker)
  72602. {
  72603. if (x2 != subPathCloseX || y2 != subPathCloseY)
  72604. {
  72605. x1 = x2;
  72606. y1 = y2;
  72607. x2 = subPathCloseX;
  72608. y2 = subPathCloseY;
  72609. closesSubPath = true;
  72610. return true;
  72611. }
  72612. }
  72613. else
  72614. {
  72615. jassert (type == Path::moveMarker);
  72616. subPathIndex = -1;
  72617. subPathCloseX = x1 = x2;
  72618. subPathCloseY = y1 = y2;
  72619. }
  72620. }
  72621. }
  72622. END_JUCE_NAMESPACE
  72623. /*** End of inlined file: juce_PathIterator.cpp ***/
  72624. /*** Start of inlined file: juce_PathStrokeType.cpp ***/
  72625. BEGIN_JUCE_NAMESPACE
  72626. PathStrokeType::PathStrokeType (const float strokeThickness,
  72627. const JointStyle jointStyle_,
  72628. const EndCapStyle endStyle_) throw()
  72629. : thickness (strokeThickness),
  72630. jointStyle (jointStyle_),
  72631. endStyle (endStyle_)
  72632. {
  72633. }
  72634. PathStrokeType::PathStrokeType (const PathStrokeType& other) throw()
  72635. : thickness (other.thickness),
  72636. jointStyle (other.jointStyle),
  72637. endStyle (other.endStyle)
  72638. {
  72639. }
  72640. PathStrokeType& PathStrokeType::operator= (const PathStrokeType& other) throw()
  72641. {
  72642. thickness = other.thickness;
  72643. jointStyle = other.jointStyle;
  72644. endStyle = other.endStyle;
  72645. return *this;
  72646. }
  72647. PathStrokeType::~PathStrokeType() throw()
  72648. {
  72649. }
  72650. bool PathStrokeType::operator== (const PathStrokeType& other) const throw()
  72651. {
  72652. return thickness == other.thickness
  72653. && jointStyle == other.jointStyle
  72654. && endStyle == other.endStyle;
  72655. }
  72656. bool PathStrokeType::operator!= (const PathStrokeType& other) const throw()
  72657. {
  72658. return ! operator== (other);
  72659. }
  72660. static bool lineIntersection (const float x1, const float y1,
  72661. const float x2, const float y2,
  72662. const float x3, const float y3,
  72663. const float x4, const float y4,
  72664. float& intersectionX,
  72665. float& intersectionY,
  72666. float& distanceBeyondLine1EndSquared) throw()
  72667. {
  72668. if (x2 != x3 || y2 != y3)
  72669. {
  72670. const float dx1 = x2 - x1;
  72671. const float dy1 = y2 - y1;
  72672. const float dx2 = x4 - x3;
  72673. const float dy2 = y4 - y3;
  72674. const float divisor = dx1 * dy2 - dx2 * dy1;
  72675. if (divisor == 0)
  72676. {
  72677. if (! ((dx1 == 0 && dy1 == 0) || (dx2 == 0 && dy2 == 0)))
  72678. {
  72679. if (dy1 == 0 && dy2 != 0)
  72680. {
  72681. const float along = (y1 - y3) / dy2;
  72682. intersectionX = x3 + along * dx2;
  72683. intersectionY = y1;
  72684. distanceBeyondLine1EndSquared = intersectionX - x2;
  72685. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72686. if ((x2 > x1) == (intersectionX < x2))
  72687. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72688. return along >= 0 && along <= 1.0f;
  72689. }
  72690. else if (dy2 == 0 && dy1 != 0)
  72691. {
  72692. const float along = (y3 - y1) / dy1;
  72693. intersectionX = x1 + along * dx1;
  72694. intersectionY = y3;
  72695. distanceBeyondLine1EndSquared = (along - 1.0f) * dx1;
  72696. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72697. if (along < 1.0f)
  72698. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72699. return along >= 0 && along <= 1.0f;
  72700. }
  72701. else if (dx1 == 0 && dx2 != 0)
  72702. {
  72703. const float along = (x1 - x3) / dx2;
  72704. intersectionX = x1;
  72705. intersectionY = y3 + along * dy2;
  72706. distanceBeyondLine1EndSquared = intersectionY - y2;
  72707. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72708. if ((y2 > y1) == (intersectionY < y2))
  72709. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72710. return along >= 0 && along <= 1.0f;
  72711. }
  72712. else if (dx2 == 0 && dx1 != 0)
  72713. {
  72714. const float along = (x3 - x1) / dx1;
  72715. intersectionX = x3;
  72716. intersectionY = y1 + along * dy1;
  72717. distanceBeyondLine1EndSquared = (along - 1.0f) * dy1;
  72718. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72719. if (along < 1.0f)
  72720. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72721. return along >= 0 && along <= 1.0f;
  72722. }
  72723. }
  72724. intersectionX = 0.5f * (x2 + x3);
  72725. intersectionY = 0.5f * (y2 + y3);
  72726. distanceBeyondLine1EndSquared = 0.0f;
  72727. return false;
  72728. }
  72729. else
  72730. {
  72731. const float along1 = ((y1 - y3) * dx2 - (x1 - x3) * dy2) / divisor;
  72732. intersectionX = x1 + along1 * dx1;
  72733. intersectionY = y1 + along1 * dy1;
  72734. if (along1 >= 0 && along1 <= 1.0f)
  72735. {
  72736. const float along2 = ((y1 - y3) * dx1 - (x1 - x3) * dy1);
  72737. if (along2 >= 0 && along2 <= divisor)
  72738. {
  72739. distanceBeyondLine1EndSquared = 0.0f;
  72740. return true;
  72741. }
  72742. }
  72743. distanceBeyondLine1EndSquared = along1 - 1.0f;
  72744. distanceBeyondLine1EndSquared *= distanceBeyondLine1EndSquared;
  72745. distanceBeyondLine1EndSquared *= (dx1 * dx1 + dy1 * dy1);
  72746. if (along1 < 1.0f)
  72747. distanceBeyondLine1EndSquared = -distanceBeyondLine1EndSquared;
  72748. return false;
  72749. }
  72750. }
  72751. intersectionX = x2;
  72752. intersectionY = y2;
  72753. distanceBeyondLine1EndSquared = 0.0f;
  72754. return true;
  72755. }
  72756. namespace PathFunctions
  72757. {
  72758. // part of stroke drawing stuff
  72759. static void addEdgeAndJoint (Path& destPath,
  72760. const PathStrokeType::JointStyle style,
  72761. const float maxMiterExtensionSquared, const float width,
  72762. const float x1, const float y1,
  72763. const float x2, const float y2,
  72764. const float x3, const float y3,
  72765. const float x4, const float y4,
  72766. const float midX, const float midY)
  72767. {
  72768. if (style == PathStrokeType::beveled
  72769. || (x3 == x4 && y3 == y4)
  72770. || (x1 == x2 && y1 == y2))
  72771. {
  72772. destPath.lineTo (x2, y2);
  72773. destPath.lineTo (x3, y3);
  72774. }
  72775. else
  72776. {
  72777. float jx, jy, distanceBeyondLine1EndSquared;
  72778. // if they intersect, use this point..
  72779. if (lineIntersection (x1, y1, x2, y2,
  72780. x3, y3, x4, y4,
  72781. jx, jy, distanceBeyondLine1EndSquared))
  72782. {
  72783. destPath.lineTo (jx, jy);
  72784. }
  72785. else
  72786. {
  72787. if (style == PathStrokeType::mitered)
  72788. {
  72789. if (distanceBeyondLine1EndSquared < maxMiterExtensionSquared
  72790. && distanceBeyondLine1EndSquared > 0.0f)
  72791. {
  72792. destPath.lineTo (jx, jy);
  72793. }
  72794. else
  72795. {
  72796. // the end sticks out too far, so just use a blunt joint
  72797. destPath.lineTo (x2, y2);
  72798. destPath.lineTo (x3, y3);
  72799. }
  72800. }
  72801. else
  72802. {
  72803. // curved joints
  72804. float angle1 = atan2f (x2 - midX, y2 - midY);
  72805. float angle2 = atan2f (x3 - midX, y3 - midY);
  72806. const float angleIncrement = 0.1f;
  72807. destPath.lineTo (x2, y2);
  72808. if (fabs (angle1 - angle2) > angleIncrement)
  72809. {
  72810. if (angle2 > angle1 + float_Pi
  72811. || (angle2 < angle1 && angle2 >= angle1 - float_Pi))
  72812. {
  72813. if (angle2 > angle1)
  72814. angle2 -= float_Pi * 2.0f;
  72815. jassert (angle1 <= angle2 + float_Pi);
  72816. angle1 -= angleIncrement;
  72817. while (angle1 > angle2)
  72818. {
  72819. destPath.lineTo (midX + width * sinf (angle1),
  72820. midY + width * cosf (angle1));
  72821. angle1 -= angleIncrement;
  72822. }
  72823. }
  72824. else
  72825. {
  72826. if (angle1 > angle2)
  72827. angle1 -= float_Pi * 2.0f;
  72828. jassert (angle1 >= angle2 - float_Pi);
  72829. angle1 += angleIncrement;
  72830. while (angle1 < angle2)
  72831. {
  72832. destPath.lineTo (midX + width * sinf (angle1),
  72833. midY + width * cosf (angle1));
  72834. angle1 += angleIncrement;
  72835. }
  72836. }
  72837. }
  72838. destPath.lineTo (x3, y3);
  72839. }
  72840. }
  72841. }
  72842. }
  72843. static void addLineEnd (Path& destPath,
  72844. const PathStrokeType::EndCapStyle style,
  72845. const float x1, const float y1,
  72846. const float x2, const float y2,
  72847. const float width)
  72848. {
  72849. if (style == PathStrokeType::butt)
  72850. {
  72851. destPath.lineTo (x2, y2);
  72852. }
  72853. else
  72854. {
  72855. float offx1, offy1, offx2, offy2;
  72856. float dx = x2 - x1;
  72857. float dy = y2 - y1;
  72858. const float len = juce_hypotf (dx, dy);
  72859. if (len == 0)
  72860. {
  72861. offx1 = offx2 = x1;
  72862. offy1 = offy2 = y1;
  72863. }
  72864. else
  72865. {
  72866. const float offset = width / len;
  72867. dx *= offset;
  72868. dy *= offset;
  72869. offx1 = x1 + dy;
  72870. offy1 = y1 - dx;
  72871. offx2 = x2 + dy;
  72872. offy2 = y2 - dx;
  72873. }
  72874. if (style == PathStrokeType::square)
  72875. {
  72876. // sqaure ends
  72877. destPath.lineTo (offx1, offy1);
  72878. destPath.lineTo (offx2, offy2);
  72879. destPath.lineTo (x2, y2);
  72880. }
  72881. else
  72882. {
  72883. // rounded ends
  72884. const float midx = (offx1 + offx2) * 0.5f;
  72885. const float midy = (offy1 + offy2) * 0.5f;
  72886. destPath.cubicTo (x1 + (offx1 - x1) * 0.55f, y1 + (offy1 - y1) * 0.55f,
  72887. offx1 + (midx - offx1) * 0.45f, offy1 + (midy - offy1) * 0.45f,
  72888. midx, midy);
  72889. destPath.cubicTo (midx + (offx2 - midx) * 0.55f, midy + (offy2 - midy) * 0.55f,
  72890. offx2 + (x2 - offx2) * 0.45f, offy2 + (y2 - offy2) * 0.45f,
  72891. x2, y2);
  72892. }
  72893. }
  72894. }
  72895. struct LineSection
  72896. {
  72897. LineSection() {}
  72898. LineSection (int) {}
  72899. float x1, y1, x2, y2; // original line
  72900. float lx1, ly1, lx2, ly2; // the left-hand stroke
  72901. float rx1, ry1, rx2, ry2; // the right-hand stroke
  72902. };
  72903. static void addSubPath (Path& destPath, const Array <LineSection>& subPath,
  72904. const bool isClosed,
  72905. const float width, const float maxMiterExtensionSquared,
  72906. const PathStrokeType::JointStyle jointStyle, const PathStrokeType::EndCapStyle endStyle)
  72907. {
  72908. jassert (subPath.size() > 0);
  72909. const LineSection& firstLine = subPath.getReference (0);
  72910. float lastX1 = firstLine.lx1;
  72911. float lastY1 = firstLine.ly1;
  72912. float lastX2 = firstLine.lx2;
  72913. float lastY2 = firstLine.ly2;
  72914. if (isClosed)
  72915. {
  72916. destPath.startNewSubPath (lastX1, lastY1);
  72917. }
  72918. else
  72919. {
  72920. destPath.startNewSubPath (firstLine.rx2, firstLine.ry2);
  72921. addLineEnd (destPath, endStyle,
  72922. firstLine.rx2, firstLine.ry2,
  72923. lastX1, lastY1,
  72924. width);
  72925. }
  72926. int i;
  72927. for (i = 1; i < subPath.size(); ++i)
  72928. {
  72929. const LineSection& l = subPath.getReference (i);
  72930. addEdgeAndJoint (destPath, jointStyle,
  72931. maxMiterExtensionSquared, width,
  72932. lastX1, lastY1, lastX2, lastY2,
  72933. l.lx1, l.ly1, l.lx2, l.ly2,
  72934. l.x1, l.y1);
  72935. lastX1 = l.lx1;
  72936. lastY1 = l.ly1;
  72937. lastX2 = l.lx2;
  72938. lastY2 = l.ly2;
  72939. }
  72940. const LineSection& lastLine = subPath.getReference (subPath.size() - 1);
  72941. if (isClosed)
  72942. {
  72943. const LineSection& l = subPath.getReference (0);
  72944. addEdgeAndJoint (destPath, jointStyle,
  72945. maxMiterExtensionSquared, width,
  72946. lastX1, lastY1, lastX2, lastY2,
  72947. l.lx1, l.ly1, l.lx2, l.ly2,
  72948. l.x1, l.y1);
  72949. destPath.closeSubPath();
  72950. destPath.startNewSubPath (lastLine.rx1, lastLine.ry1);
  72951. }
  72952. else
  72953. {
  72954. destPath.lineTo (lastX2, lastY2);
  72955. addLineEnd (destPath, endStyle,
  72956. lastX2, lastY2,
  72957. lastLine.rx1, lastLine.ry1,
  72958. width);
  72959. }
  72960. lastX1 = lastLine.rx1;
  72961. lastY1 = lastLine.ry1;
  72962. lastX2 = lastLine.rx2;
  72963. lastY2 = lastLine.ry2;
  72964. for (i = subPath.size() - 1; --i >= 0;)
  72965. {
  72966. const LineSection& l = subPath.getReference (i);
  72967. addEdgeAndJoint (destPath, jointStyle,
  72968. maxMiterExtensionSquared, width,
  72969. lastX1, lastY1, lastX2, lastY2,
  72970. l.rx1, l.ry1, l.rx2, l.ry2,
  72971. l.x2, l.y2);
  72972. lastX1 = l.rx1;
  72973. lastY1 = l.ry1;
  72974. lastX2 = l.rx2;
  72975. lastY2 = l.ry2;
  72976. }
  72977. if (isClosed)
  72978. {
  72979. addEdgeAndJoint (destPath, jointStyle,
  72980. maxMiterExtensionSquared, width,
  72981. lastX1, lastY1, lastX2, lastY2,
  72982. lastLine.rx1, lastLine.ry1, lastLine.rx2, lastLine.ry2,
  72983. lastLine.x2, lastLine.y2);
  72984. }
  72985. else
  72986. {
  72987. // do the last line
  72988. destPath.lineTo (lastX2, lastY2);
  72989. }
  72990. destPath.closeSubPath();
  72991. }
  72992. }
  72993. void PathStrokeType::createStrokedPath (Path& destPath,
  72994. const Path& source,
  72995. const AffineTransform& transform,
  72996. const float extraAccuracy) const
  72997. {
  72998. if (thickness <= 0)
  72999. {
  73000. destPath.clear();
  73001. return;
  73002. }
  73003. const Path* sourcePath = &source;
  73004. Path temp;
  73005. if (sourcePath == &destPath)
  73006. {
  73007. destPath.swapWithPath (temp);
  73008. sourcePath = &temp;
  73009. }
  73010. else
  73011. {
  73012. destPath.clear();
  73013. }
  73014. destPath.setUsingNonZeroWinding (true);
  73015. const float maxMiterExtensionSquared = 9.0f * thickness * thickness;
  73016. const float width = 0.5f * thickness;
  73017. // Iterate the path, creating a list of the
  73018. // left/right-hand lines along either side of it...
  73019. PathFlatteningIterator it (*sourcePath, transform, 9.0f / extraAccuracy);
  73020. using namespace PathFunctions;
  73021. Array <LineSection> subPath;
  73022. LineSection l;
  73023. l.x1 = 0;
  73024. l.y1 = 0;
  73025. const float minSegmentLength = 2.0f / (extraAccuracy * extraAccuracy);
  73026. while (it.next())
  73027. {
  73028. if (it.subPathIndex == 0)
  73029. {
  73030. if (subPath.size() > 0)
  73031. {
  73032. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73033. subPath.clearQuick();
  73034. }
  73035. l.x1 = it.x1;
  73036. l.y1 = it.y1;
  73037. }
  73038. l.x2 = it.x2;
  73039. l.y2 = it.y2;
  73040. float dx = l.x2 - l.x1;
  73041. float dy = l.y2 - l.y1;
  73042. const float hypotSquared = dx*dx + dy*dy;
  73043. if (it.closesSubPath || hypotSquared > minSegmentLength || it.isLastInSubpath())
  73044. {
  73045. const float len = sqrtf (hypotSquared);
  73046. if (len == 0)
  73047. {
  73048. l.rx1 = l.rx2 = l.lx1 = l.lx2 = l.x1;
  73049. l.ry1 = l.ry2 = l.ly1 = l.ly2 = l.y1;
  73050. }
  73051. else
  73052. {
  73053. const float offset = width / len;
  73054. dx *= offset;
  73055. dy *= offset;
  73056. l.rx2 = l.x1 - dy;
  73057. l.ry2 = l.y1 + dx;
  73058. l.lx1 = l.x1 + dy;
  73059. l.ly1 = l.y1 - dx;
  73060. l.lx2 = l.x2 + dy;
  73061. l.ly2 = l.y2 - dx;
  73062. l.rx1 = l.x2 - dy;
  73063. l.ry1 = l.y2 + dx;
  73064. }
  73065. subPath.add (l);
  73066. if (it.closesSubPath)
  73067. {
  73068. addSubPath (destPath, subPath, true, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73069. subPath.clearQuick();
  73070. }
  73071. else
  73072. {
  73073. l.x1 = it.x2;
  73074. l.y1 = it.y2;
  73075. }
  73076. }
  73077. }
  73078. if (subPath.size() > 0)
  73079. addSubPath (destPath, subPath, false, width, maxMiterExtensionSquared, jointStyle, endStyle);
  73080. }
  73081. void PathStrokeType::createDashedStroke (Path& destPath,
  73082. const Path& sourcePath,
  73083. const float* dashLengths,
  73084. int numDashLengths,
  73085. const AffineTransform& transform,
  73086. const float extraAccuracy) const
  73087. {
  73088. if (thickness <= 0)
  73089. return;
  73090. // this should really be an even number..
  73091. jassert ((numDashLengths & 1) == 0);
  73092. Path newDestPath;
  73093. PathFlatteningIterator it (sourcePath, transform, 9.0f / extraAccuracy);
  73094. bool first = true;
  73095. int dashNum = 0;
  73096. float pos = 0.0f, lineLen = 0.0f, lineEndPos = 0.0f;
  73097. float dx = 0.0f, dy = 0.0f;
  73098. for (;;)
  73099. {
  73100. const bool isSolid = ((dashNum & 1) == 0);
  73101. const float dashLen = dashLengths [dashNum++ % numDashLengths];
  73102. jassert (dashLen > 0); // must be a positive increment!
  73103. if (dashLen <= 0)
  73104. break;
  73105. pos += dashLen;
  73106. while (pos > lineEndPos)
  73107. {
  73108. if (! it.next())
  73109. {
  73110. if (isSolid && ! first)
  73111. newDestPath.lineTo (it.x2, it.y2);
  73112. createStrokedPath (destPath, newDestPath, AffineTransform::identity, extraAccuracy);
  73113. return;
  73114. }
  73115. if (isSolid && ! first)
  73116. newDestPath.lineTo (it.x1, it.y1);
  73117. else
  73118. newDestPath.startNewSubPath (it.x1, it.y1);
  73119. dx = it.x2 - it.x1;
  73120. dy = it.y2 - it.y1;
  73121. lineLen = juce_hypotf (dx, dy);
  73122. lineEndPos += lineLen;
  73123. first = it.closesSubPath;
  73124. }
  73125. const float alpha = (pos - (lineEndPos - lineLen)) / lineLen;
  73126. if (isSolid)
  73127. newDestPath.lineTo (it.x1 + dx * alpha,
  73128. it.y1 + dy * alpha);
  73129. else
  73130. newDestPath.startNewSubPath (it.x1 + dx * alpha,
  73131. it.y1 + dy * alpha);
  73132. }
  73133. }
  73134. END_JUCE_NAMESPACE
  73135. /*** End of inlined file: juce_PathStrokeType.cpp ***/
  73136. /*** Start of inlined file: juce_PositionedRectangle.cpp ***/
  73137. BEGIN_JUCE_NAMESPACE
  73138. PositionedRectangle::PositionedRectangle() throw()
  73139. : x (0.0),
  73140. y (0.0),
  73141. w (0.0),
  73142. h (0.0),
  73143. xMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  73144. yMode (anchorAtLeftOrTop | absoluteFromParentTopLeft),
  73145. wMode (absoluteSize),
  73146. hMode (absoluteSize)
  73147. {
  73148. }
  73149. PositionedRectangle::PositionedRectangle (const PositionedRectangle& other) throw()
  73150. : x (other.x),
  73151. y (other.y),
  73152. w (other.w),
  73153. h (other.h),
  73154. xMode (other.xMode),
  73155. yMode (other.yMode),
  73156. wMode (other.wMode),
  73157. hMode (other.hMode)
  73158. {
  73159. }
  73160. PositionedRectangle& PositionedRectangle::operator= (const PositionedRectangle& other) throw()
  73161. {
  73162. x = other.x;
  73163. y = other.y;
  73164. w = other.w;
  73165. h = other.h;
  73166. xMode = other.xMode;
  73167. yMode = other.yMode;
  73168. wMode = other.wMode;
  73169. hMode = other.hMode;
  73170. return *this;
  73171. }
  73172. PositionedRectangle::~PositionedRectangle() throw()
  73173. {
  73174. }
  73175. bool PositionedRectangle::operator== (const PositionedRectangle& other) const throw()
  73176. {
  73177. return x == other.x
  73178. && y == other.y
  73179. && w == other.w
  73180. && h == other.h
  73181. && xMode == other.xMode
  73182. && yMode == other.yMode
  73183. && wMode == other.wMode
  73184. && hMode == other.hMode;
  73185. }
  73186. bool PositionedRectangle::operator!= (const PositionedRectangle& other) const throw()
  73187. {
  73188. return ! operator== (other);
  73189. }
  73190. PositionedRectangle::PositionedRectangle (const String& stringVersion) throw()
  73191. {
  73192. StringArray tokens;
  73193. tokens.addTokens (stringVersion, false);
  73194. decodePosString (tokens [0], xMode, x);
  73195. decodePosString (tokens [1], yMode, y);
  73196. decodeSizeString (tokens [2], wMode, w);
  73197. decodeSizeString (tokens [3], hMode, h);
  73198. }
  73199. const String PositionedRectangle::toString() const throw()
  73200. {
  73201. String s;
  73202. s.preallocateStorage (12);
  73203. addPosDescription (s, xMode, x);
  73204. s << T(' ');
  73205. addPosDescription (s, yMode, y);
  73206. s << T(' ');
  73207. addSizeDescription (s, wMode, w);
  73208. s << T(' ');
  73209. addSizeDescription (s, hMode, h);
  73210. return s;
  73211. }
  73212. const Rectangle<int> PositionedRectangle::getRectangle (const Rectangle<int>& target) const throw()
  73213. {
  73214. jassert (! target.isEmpty());
  73215. double x_, y_, w_, h_;
  73216. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  73217. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  73218. return Rectangle<int> (roundToInt (x_), roundToInt (y_),
  73219. roundToInt (w_), roundToInt (h_));
  73220. }
  73221. void PositionedRectangle::getRectangleDouble (const Rectangle<int>& target,
  73222. double& x_, double& y_,
  73223. double& w_, double& h_) const throw()
  73224. {
  73225. jassert (! target.isEmpty());
  73226. applyPosAndSize (x_, w_, x, w, xMode, wMode, target.getX(), target.getWidth());
  73227. applyPosAndSize (y_, h_, y, h, yMode, hMode, target.getY(), target.getHeight());
  73228. }
  73229. void PositionedRectangle::applyToComponent (Component& comp) const throw()
  73230. {
  73231. comp.setBounds (getRectangle (Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight())));
  73232. }
  73233. void PositionedRectangle::updateFrom (const Rectangle<int>& rectangle,
  73234. const Rectangle<int>& target) throw()
  73235. {
  73236. updatePosAndSize (x, w, rectangle.getX(), rectangle.getWidth(), xMode, wMode, target.getX(), target.getWidth());
  73237. updatePosAndSize (y, h, rectangle.getY(), rectangle.getHeight(), yMode, hMode, target.getY(), target.getHeight());
  73238. }
  73239. void PositionedRectangle::updateFromDouble (const double newX, const double newY,
  73240. const double newW, const double newH,
  73241. const Rectangle<int>& target) throw()
  73242. {
  73243. updatePosAndSize (x, w, newX, newW, xMode, wMode, target.getX(), target.getWidth());
  73244. updatePosAndSize (y, h, newY, newH, yMode, hMode, target.getY(), target.getHeight());
  73245. }
  73246. void PositionedRectangle::updateFromComponent (const Component& comp) throw()
  73247. {
  73248. if (comp.getParentComponent() == 0 && ! comp.isOnDesktop())
  73249. updateFrom (comp.getBounds(), Rectangle<int>());
  73250. else
  73251. updateFrom (comp.getBounds(), Rectangle<int> (0, 0, comp.getParentWidth(), comp.getParentHeight()));
  73252. }
  73253. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointX() const throw()
  73254. {
  73255. return (AnchorPoint) (xMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  73256. }
  73257. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeX() const throw()
  73258. {
  73259. return (PositionMode) (xMode & (absoluteFromParentTopLeft
  73260. | absoluteFromParentBottomRight
  73261. | absoluteFromParentCentre
  73262. | proportionOfParentSize));
  73263. }
  73264. PositionedRectangle::AnchorPoint PositionedRectangle::getAnchorPointY() const throw()
  73265. {
  73266. return (AnchorPoint) (yMode & (anchorAtLeftOrTop | anchorAtRightOrBottom | anchorAtCentre));
  73267. }
  73268. PositionedRectangle::PositionMode PositionedRectangle::getPositionModeY() const throw()
  73269. {
  73270. return (PositionMode) (yMode & (absoluteFromParentTopLeft
  73271. | absoluteFromParentBottomRight
  73272. | absoluteFromParentCentre
  73273. | proportionOfParentSize));
  73274. }
  73275. PositionedRectangle::SizeMode PositionedRectangle::getWidthMode() const throw()
  73276. {
  73277. return (SizeMode) wMode;
  73278. }
  73279. PositionedRectangle::SizeMode PositionedRectangle::getHeightMode() const throw()
  73280. {
  73281. return (SizeMode) hMode;
  73282. }
  73283. void PositionedRectangle::setModes (const AnchorPoint xAnchor,
  73284. const PositionMode xMode_,
  73285. const AnchorPoint yAnchor,
  73286. const PositionMode yMode_,
  73287. const SizeMode widthMode,
  73288. const SizeMode heightMode,
  73289. const Rectangle<int>& target) throw()
  73290. {
  73291. if (xMode != (xAnchor | xMode_) || wMode != widthMode)
  73292. {
  73293. double tx, tw;
  73294. applyPosAndSize (tx, tw, x, w, xMode, wMode, target.getX(), target.getWidth());
  73295. xMode = (uint8) (xAnchor | xMode_);
  73296. wMode = (uint8) widthMode;
  73297. updatePosAndSize (x, w, tx, tw, xMode, wMode, target.getX(), target.getWidth());
  73298. }
  73299. if (yMode != (yAnchor | yMode_) || hMode != heightMode)
  73300. {
  73301. double ty, th;
  73302. applyPosAndSize (ty, th, y, h, yMode, hMode, target.getY(), target.getHeight());
  73303. yMode = (uint8) (yAnchor | yMode_);
  73304. hMode = (uint8) heightMode;
  73305. updatePosAndSize (y, h, ty, th, yMode, hMode, target.getY(), target.getHeight());
  73306. }
  73307. }
  73308. bool PositionedRectangle::isPositionAbsolute() const throw()
  73309. {
  73310. return xMode == absoluteFromParentTopLeft
  73311. && yMode == absoluteFromParentTopLeft
  73312. && wMode == absoluteSize
  73313. && hMode == absoluteSize;
  73314. }
  73315. void PositionedRectangle::addPosDescription (String& s, const uint8 mode, const double value) const throw()
  73316. {
  73317. if ((mode & proportionOfParentSize) != 0)
  73318. {
  73319. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73320. }
  73321. else
  73322. {
  73323. s << (roundToInt (value * 100.0) / 100.0);
  73324. if ((mode & absoluteFromParentBottomRight) != 0)
  73325. s << T('R');
  73326. else if ((mode & absoluteFromParentCentre) != 0)
  73327. s << T('C');
  73328. }
  73329. if ((mode & anchorAtRightOrBottom) != 0)
  73330. s << T('r');
  73331. else if ((mode & anchorAtCentre) != 0)
  73332. s << T('c');
  73333. }
  73334. void PositionedRectangle::addSizeDescription (String& s, const uint8 mode, const double value) const throw()
  73335. {
  73336. if (mode == proportionalSize)
  73337. s << (roundToInt (value * 100000.0) / 1000.0) << T('%');
  73338. else if (mode == parentSizeMinusAbsolute)
  73339. s << (roundToInt (value * 100.0) / 100.0) << T('M');
  73340. else
  73341. s << (roundToInt (value * 100.0) / 100.0);
  73342. }
  73343. void PositionedRectangle::decodePosString (const String& s, uint8& mode, double& value) throw()
  73344. {
  73345. if (s.containsChar (T('r')))
  73346. mode = anchorAtRightOrBottom;
  73347. else if (s.containsChar (T('c')))
  73348. mode = anchorAtCentre;
  73349. else
  73350. mode = anchorAtLeftOrTop;
  73351. if (s.containsChar (T('%')))
  73352. {
  73353. mode |= proportionOfParentSize;
  73354. value = s.removeCharacters (T("%rcRC")).getDoubleValue() / 100.0;
  73355. }
  73356. else
  73357. {
  73358. if (s.containsChar (T('R')))
  73359. mode |= absoluteFromParentBottomRight;
  73360. else if (s.containsChar (T('C')))
  73361. mode |= absoluteFromParentCentre;
  73362. else
  73363. mode |= absoluteFromParentTopLeft;
  73364. value = s.removeCharacters (T("rcRC")).getDoubleValue();
  73365. }
  73366. }
  73367. void PositionedRectangle::decodeSizeString (const String& s, uint8& mode, double& value) throw()
  73368. {
  73369. if (s.containsChar (T('%')))
  73370. {
  73371. mode = proportionalSize;
  73372. value = s.upToFirstOccurrenceOf (T("%"), false, false).getDoubleValue() / 100.0;
  73373. }
  73374. else if (s.containsChar (T('M')))
  73375. {
  73376. mode = parentSizeMinusAbsolute;
  73377. value = s.getDoubleValue();
  73378. }
  73379. else
  73380. {
  73381. mode = absoluteSize;
  73382. value = s.getDoubleValue();
  73383. }
  73384. }
  73385. void PositionedRectangle::applyPosAndSize (double& xOut, double& wOut,
  73386. const double x_, const double w_,
  73387. const uint8 xMode_, const uint8 wMode_,
  73388. const int parentPos,
  73389. const int parentSize) const throw()
  73390. {
  73391. if (wMode_ == proportionalSize)
  73392. wOut = roundToInt (w_ * parentSize);
  73393. else if (wMode_ == parentSizeMinusAbsolute)
  73394. wOut = jmax (0, parentSize - roundToInt (w_));
  73395. else
  73396. wOut = roundToInt (w_);
  73397. if ((xMode_ & proportionOfParentSize) != 0)
  73398. xOut = parentPos + x_ * parentSize;
  73399. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73400. xOut = (parentPos + parentSize) - x_;
  73401. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73402. xOut = x_ + (parentPos + parentSize / 2);
  73403. else
  73404. xOut = x_ + parentPos;
  73405. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73406. xOut -= wOut;
  73407. else if ((xMode_ & anchorAtCentre) != 0)
  73408. xOut -= wOut / 2;
  73409. }
  73410. void PositionedRectangle::updatePosAndSize (double& xOut, double& wOut,
  73411. double x_, const double w_,
  73412. const uint8 xMode_, const uint8 wMode_,
  73413. const int parentPos,
  73414. const int parentSize) const throw()
  73415. {
  73416. if (wMode_ == proportionalSize)
  73417. {
  73418. if (parentSize > 0)
  73419. wOut = w_ / parentSize;
  73420. }
  73421. else if (wMode_ == parentSizeMinusAbsolute)
  73422. wOut = parentSize - w_;
  73423. else
  73424. wOut = w_;
  73425. if ((xMode_ & anchorAtRightOrBottom) != 0)
  73426. x_ += w_;
  73427. else if ((xMode_ & anchorAtCentre) != 0)
  73428. x_ += w_ / 2;
  73429. if ((xMode_ & proportionOfParentSize) != 0)
  73430. {
  73431. if (parentSize > 0)
  73432. xOut = (x_ - parentPos) / parentSize;
  73433. }
  73434. else if ((xMode_ & absoluteFromParentBottomRight) != 0)
  73435. xOut = (parentPos + parentSize) - x_;
  73436. else if ((xMode_ & absoluteFromParentCentre) != 0)
  73437. xOut = x_ - (parentPos + parentSize / 2);
  73438. else
  73439. xOut = x_ - parentPos;
  73440. }
  73441. END_JUCE_NAMESPACE
  73442. /*** End of inlined file: juce_PositionedRectangle.cpp ***/
  73443. /*** Start of inlined file: juce_RectangleList.cpp ***/
  73444. BEGIN_JUCE_NAMESPACE
  73445. RectangleList::RectangleList() throw()
  73446. {
  73447. }
  73448. RectangleList::RectangleList (const Rectangle<int>& rect) throw()
  73449. {
  73450. if (! rect.isEmpty())
  73451. rects.add (rect);
  73452. }
  73453. RectangleList::RectangleList (const RectangleList& other) throw()
  73454. : rects (other.rects)
  73455. {
  73456. }
  73457. RectangleList& RectangleList::operator= (const RectangleList& other) throw()
  73458. {
  73459. rects = other.rects;
  73460. return *this;
  73461. }
  73462. RectangleList::~RectangleList() throw()
  73463. {
  73464. }
  73465. void RectangleList::clear() throw()
  73466. {
  73467. rects.clearQuick();
  73468. }
  73469. const Rectangle<int> RectangleList::getRectangle (const int index) const throw()
  73470. {
  73471. if (((unsigned int) index) < (unsigned int) rects.size())
  73472. return rects.getReference (index);
  73473. return Rectangle<int>();
  73474. }
  73475. bool RectangleList::isEmpty() const throw()
  73476. {
  73477. return rects.size() == 0;
  73478. }
  73479. RectangleList::Iterator::Iterator (const RectangleList& list) throw()
  73480. : current (0),
  73481. owner (list),
  73482. index (list.rects.size())
  73483. {
  73484. }
  73485. RectangleList::Iterator::~Iterator() throw()
  73486. {
  73487. }
  73488. bool RectangleList::Iterator::next() throw()
  73489. {
  73490. if (--index >= 0)
  73491. {
  73492. current = & (owner.rects.getReference (index));
  73493. return true;
  73494. }
  73495. return false;
  73496. }
  73497. void RectangleList::add (const Rectangle<int>& rect) throw()
  73498. {
  73499. if (! rect.isEmpty())
  73500. {
  73501. if (rects.size() == 0)
  73502. {
  73503. rects.add (rect);
  73504. }
  73505. else
  73506. {
  73507. bool anyOverlaps = false;
  73508. int i;
  73509. for (i = rects.size(); --i >= 0;)
  73510. {
  73511. Rectangle<int>& ourRect = rects.getReference (i);
  73512. if (rect.intersects (ourRect))
  73513. {
  73514. if (rect.contains (ourRect))
  73515. rects.remove (i);
  73516. else if (! ourRect.reduceIfPartlyContainedIn (rect))
  73517. anyOverlaps = true;
  73518. }
  73519. }
  73520. if (anyOverlaps && rects.size() > 0)
  73521. {
  73522. RectangleList r (rect);
  73523. for (i = rects.size(); --i >= 0;)
  73524. {
  73525. const Rectangle<int>& ourRect = rects.getReference (i);
  73526. if (rect.intersects (ourRect))
  73527. {
  73528. r.subtract (ourRect);
  73529. if (r.rects.size() == 0)
  73530. return;
  73531. }
  73532. }
  73533. for (i = r.getNumRectangles(); --i >= 0;)
  73534. rects.add (r.rects.getReference (i));
  73535. }
  73536. else
  73537. {
  73538. rects.add (rect);
  73539. }
  73540. }
  73541. }
  73542. }
  73543. void RectangleList::addWithoutMerging (const Rectangle<int>& rect) throw()
  73544. {
  73545. rects.add (rect);
  73546. }
  73547. void RectangleList::add (const int x, const int y, const int w, const int h) throw()
  73548. {
  73549. if (rects.size() == 0)
  73550. {
  73551. if (w > 0 && h > 0)
  73552. rects.add (Rectangle<int> (x, y, w, h));
  73553. }
  73554. else
  73555. {
  73556. add (Rectangle<int> (x, y, w, h));
  73557. }
  73558. }
  73559. void RectangleList::add (const RectangleList& other) throw()
  73560. {
  73561. for (int i = 0; i < other.rects.size(); ++i)
  73562. add (other.rects.getReference (i));
  73563. }
  73564. void RectangleList::subtract (const Rectangle<int>& rect) throw()
  73565. {
  73566. const int originalNumRects = rects.size();
  73567. if (originalNumRects > 0)
  73568. {
  73569. const int x1 = rect.x;
  73570. const int y1 = rect.y;
  73571. const int x2 = x1 + rect.w;
  73572. const int y2 = y1 + rect.h;
  73573. for (int i = getNumRectangles(); --i >= 0;)
  73574. {
  73575. Rectangle<int>& r = rects.getReference (i);
  73576. const int rx1 = r.x;
  73577. const int ry1 = r.y;
  73578. const int rx2 = rx1 + r.w;
  73579. const int ry2 = ry1 + r.h;
  73580. if (! (x2 <= rx1 || x1 >= rx2 || y2 <= ry1 || y1 >= ry2))
  73581. {
  73582. if (x1 > rx1 && x1 < rx2)
  73583. {
  73584. if (y1 <= ry1 && y2 >= ry2 && x2 >= rx2)
  73585. {
  73586. r.w = x1 - rx1;
  73587. }
  73588. else
  73589. {
  73590. r.x = x1;
  73591. r.w = rx2 - x1;
  73592. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x1 - rx1, ry2 - ry1));
  73593. i += 2;
  73594. }
  73595. }
  73596. else if (x2 > rx1 && x2 < rx2)
  73597. {
  73598. r.x = x2;
  73599. r.w = rx2 - x2;
  73600. if (y1 > ry1 || y2 < ry2 || x1 > rx1)
  73601. {
  73602. rects.insert (i + 1, Rectangle<int> (rx1, ry1, x2 - rx1, ry2 - ry1));
  73603. i += 2;
  73604. }
  73605. }
  73606. else if (y1 > ry1 && y1 < ry2)
  73607. {
  73608. if (x1 <= rx1 && x2 >= rx2 && y2 >= ry2)
  73609. {
  73610. r.h = y1 - ry1;
  73611. }
  73612. else
  73613. {
  73614. r.y = y1;
  73615. r.h = ry2 - y1;
  73616. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y1 - ry1));
  73617. i += 2;
  73618. }
  73619. }
  73620. else if (y2 > ry1 && y2 < ry2)
  73621. {
  73622. r.y = y2;
  73623. r.h = ry2 - y2;
  73624. if (x1 > rx1 || x2 < rx2 || y1 > ry1)
  73625. {
  73626. rects.insert (i + 1, Rectangle<int> (rx1, ry1, rx2 - rx1, y2 - ry1));
  73627. i += 2;
  73628. }
  73629. }
  73630. else
  73631. {
  73632. rects.remove (i);
  73633. }
  73634. }
  73635. }
  73636. if (rects.size() > originalNumRects + 10)
  73637. consolidate();
  73638. }
  73639. }
  73640. void RectangleList::subtract (const RectangleList& otherList) throw()
  73641. {
  73642. for (int i = otherList.rects.size(); --i >= 0;)
  73643. subtract (otherList.rects.getReference (i));
  73644. }
  73645. bool RectangleList::clipTo (const Rectangle<int>& rect) throw()
  73646. {
  73647. bool notEmpty = false;
  73648. if (rect.isEmpty())
  73649. {
  73650. clear();
  73651. }
  73652. else
  73653. {
  73654. for (int i = rects.size(); --i >= 0;)
  73655. {
  73656. Rectangle<int>& r = rects.getReference (i);
  73657. if (! rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73658. rects.remove (i);
  73659. else
  73660. notEmpty = true;
  73661. }
  73662. }
  73663. return notEmpty;
  73664. }
  73665. bool RectangleList::clipTo (const RectangleList& other) throw()
  73666. {
  73667. if (rects.size() == 0)
  73668. return false;
  73669. RectangleList result;
  73670. for (int j = 0; j < rects.size(); ++j)
  73671. {
  73672. const Rectangle<int>& rect = rects.getReference (j);
  73673. for (int i = other.rects.size(); --i >= 0;)
  73674. {
  73675. Rectangle<int> r (other.rects.getReference (i));
  73676. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73677. result.rects.add (r);
  73678. }
  73679. }
  73680. swapWith (result);
  73681. return ! isEmpty();
  73682. }
  73683. bool RectangleList::getIntersectionWith (const Rectangle<int>& rect, RectangleList& destRegion) const throw()
  73684. {
  73685. destRegion.clear();
  73686. if (! rect.isEmpty())
  73687. {
  73688. for (int i = rects.size(); --i >= 0;)
  73689. {
  73690. Rectangle<int> r (rects.getReference (i));
  73691. if (rect.intersectRectangle (r.x, r.y, r.w, r.h))
  73692. destRegion.rects.add (r);
  73693. }
  73694. }
  73695. return destRegion.rects.size() > 0;
  73696. }
  73697. void RectangleList::swapWith (RectangleList& otherList) throw()
  73698. {
  73699. rects.swapWithArray (otherList.rects);
  73700. }
  73701. void RectangleList::consolidate() throw()
  73702. {
  73703. int i;
  73704. for (i = 0; i < getNumRectangles() - 1; ++i)
  73705. {
  73706. Rectangle<int>& r = rects.getReference (i);
  73707. const int rx1 = r.x;
  73708. const int ry1 = r.y;
  73709. const int rx2 = rx1 + r.w;
  73710. const int ry2 = ry1 + r.h;
  73711. for (int j = rects.size(); --j > i;)
  73712. {
  73713. Rectangle<int>& r2 = rects.getReference (j);
  73714. const int jrx1 = r2.x;
  73715. const int jry1 = r2.y;
  73716. const int jrx2 = jrx1 + r2.w;
  73717. const int jry2 = jry1 + r2.h;
  73718. // if the vertical edges of any blocks are touching and their horizontals don't
  73719. // line up, split them horizontally..
  73720. if (jrx1 == rx2 || jrx2 == rx1)
  73721. {
  73722. if (jry1 > ry1 && jry1 < ry2)
  73723. {
  73724. r.h = jry1 - ry1;
  73725. rects.add (Rectangle<int> (rx1, jry1, rx2 - rx1, ry2 - jry1));
  73726. i = -1;
  73727. break;
  73728. }
  73729. if (jry2 > ry1 && jry2 < ry2)
  73730. {
  73731. r.h = jry2 - ry1;
  73732. rects.add (Rectangle<int> (rx1, jry2, rx2 - rx1, ry2 - jry2));
  73733. i = -1;
  73734. break;
  73735. }
  73736. else if (ry1 > jry1 && ry1 < jry2)
  73737. {
  73738. r2.h = ry1 - jry1;
  73739. rects.add (Rectangle<int> (jrx1, ry1, jrx2 - jrx1, jry2 - ry1));
  73740. i = -1;
  73741. break;
  73742. }
  73743. else if (ry2 > jry1 && ry2 < jry2)
  73744. {
  73745. r2.h = ry2 - jry1;
  73746. rects.add (Rectangle<int> (jrx1, ry2, jrx2 - jrx1, jry2 - ry2));
  73747. i = -1;
  73748. break;
  73749. }
  73750. }
  73751. }
  73752. }
  73753. for (i = 0; i < rects.size() - 1; ++i)
  73754. {
  73755. Rectangle<int>& r = rects.getReference (i);
  73756. for (int j = rects.size(); --j > i;)
  73757. {
  73758. if (r.enlargeIfAdjacent (rects.getReference (j)))
  73759. {
  73760. rects.remove (j);
  73761. i = -1;
  73762. break;
  73763. }
  73764. }
  73765. }
  73766. }
  73767. bool RectangleList::containsPoint (const int x, const int y) const throw()
  73768. {
  73769. for (int i = getNumRectangles(); --i >= 0;)
  73770. if (rects.getReference (i).contains (x, y))
  73771. return true;
  73772. return false;
  73773. }
  73774. bool RectangleList::containsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73775. {
  73776. if (rects.size() > 1)
  73777. {
  73778. RectangleList r (rectangleToCheck);
  73779. for (int i = rects.size(); --i >= 0;)
  73780. {
  73781. r.subtract (rects.getReference (i));
  73782. if (r.rects.size() == 0)
  73783. return true;
  73784. }
  73785. }
  73786. else if (rects.size() > 0)
  73787. {
  73788. return rects.getReference (0).contains (rectangleToCheck);
  73789. }
  73790. return false;
  73791. }
  73792. bool RectangleList::intersectsRectangle (const Rectangle<int>& rectangleToCheck) const throw()
  73793. {
  73794. for (int i = rects.size(); --i >= 0;)
  73795. if (rects.getReference (i).intersects (rectangleToCheck))
  73796. return true;
  73797. return false;
  73798. }
  73799. bool RectangleList::intersects (const RectangleList& other) const throw()
  73800. {
  73801. for (int i = rects.size(); --i >= 0;)
  73802. if (other.intersectsRectangle (rects.getReference (i)))
  73803. return true;
  73804. return false;
  73805. }
  73806. const Rectangle<int> RectangleList::getBounds() const throw()
  73807. {
  73808. if (rects.size() <= 1)
  73809. {
  73810. if (rects.size() == 0)
  73811. return Rectangle<int>();
  73812. else
  73813. return rects.getReference (0);
  73814. }
  73815. else
  73816. {
  73817. const Rectangle<int>& r = rects.getReference (0);
  73818. int minX = r.x;
  73819. int minY = r.y;
  73820. int maxX = minX + r.w;
  73821. int maxY = minY + r.h;
  73822. for (int i = rects.size(); --i > 0;)
  73823. {
  73824. const Rectangle<int>& r2 = rects.getReference (i);
  73825. minX = jmin (minX, r2.x);
  73826. minY = jmin (minY, r2.y);
  73827. maxX = jmax (maxX, r2.getRight());
  73828. maxY = jmax (maxY, r2.getBottom());
  73829. }
  73830. return Rectangle<int> (minX, minY, maxX - minX, maxY - minY);
  73831. }
  73832. }
  73833. void RectangleList::offsetAll (const int dx, const int dy) throw()
  73834. {
  73835. for (int i = rects.size(); --i >= 0;)
  73836. {
  73837. Rectangle<int>& r = rects.getReference (i);
  73838. r.x += dx;
  73839. r.y += dy;
  73840. }
  73841. }
  73842. const Path RectangleList::toPath() const throw()
  73843. {
  73844. Path p;
  73845. for (int i = rects.size(); --i >= 0;)
  73846. {
  73847. const Rectangle<int>& r = rects.getReference (i);
  73848. p.addRectangle ((float) r.x,
  73849. (float) r.y,
  73850. (float) r.w,
  73851. (float) r.h);
  73852. }
  73853. return p;
  73854. }
  73855. END_JUCE_NAMESPACE
  73856. /*** End of inlined file: juce_RectangleList.cpp ***/
  73857. /*** Start of inlined file: juce_Image.cpp ***/
  73858. BEGIN_JUCE_NAMESPACE
  73859. static const int fullAlphaThreshold = 253;
  73860. Image::Image (const PixelFormat format_,
  73861. const int imageWidth_,
  73862. const int imageHeight_)
  73863. : format (format_),
  73864. imageWidth (imageWidth_),
  73865. imageHeight (imageHeight_),
  73866. imageData (0)
  73867. {
  73868. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73869. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73870. // actual image will be at least 1x1.
  73871. }
  73872. Image::Image (const PixelFormat format_,
  73873. const int imageWidth_,
  73874. const int imageHeight_,
  73875. const bool clearImage)
  73876. : format (format_),
  73877. imageWidth (imageWidth_),
  73878. imageHeight (imageHeight_)
  73879. {
  73880. jassert (format_ == RGB || format_ == ARGB || format_ == SingleChannel);
  73881. jassert (imageWidth_ > 0 && imageHeight_ > 0); // it's illegal to create a zero-sized image - the
  73882. // actual image will be at least 1x1.
  73883. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73884. lineStride = (pixelStride * jmax (1, imageWidth_) + 3) & ~3;
  73885. imageDataAllocated.allocate (lineStride * jmax (1, imageHeight_), clearImage);
  73886. imageData = imageDataAllocated;
  73887. }
  73888. Image::Image (const Image& other)
  73889. : format (other.format),
  73890. imageWidth (other.imageWidth),
  73891. imageHeight (other.imageHeight)
  73892. {
  73893. pixelStride = (format == RGB) ? 3 : ((format == ARGB) ? 4 : 1);
  73894. lineStride = (pixelStride * jmax (1, imageWidth) + 3) & ~3;
  73895. imageDataAllocated.malloc (lineStride * jmax (1, imageHeight));
  73896. imageData = imageDataAllocated;
  73897. BitmapData srcData (other, 0, 0, imageWidth, imageHeight);
  73898. setPixelData (0, 0, imageWidth, imageHeight, srcData.data, srcData.lineStride);
  73899. }
  73900. Image::~Image()
  73901. {
  73902. }
  73903. LowLevelGraphicsContext* Image::createLowLevelContext()
  73904. {
  73905. return new LowLevelGraphicsSoftwareRenderer (*this);
  73906. }
  73907. Image::BitmapData::BitmapData (Image& image, int x, int y, int w, int h, const bool /*makeWritable*/)
  73908. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73909. lineStride (image.lineStride),
  73910. pixelStride (image.pixelStride),
  73911. width (w),
  73912. height (h)
  73913. {
  73914. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73915. }
  73916. Image::BitmapData::BitmapData (const Image& image, int x, int y, int w, int h)
  73917. : data (image.imageData + image.lineStride * y + image.pixelStride * x),
  73918. lineStride (image.lineStride),
  73919. pixelStride (image.pixelStride),
  73920. width (w),
  73921. height (h)
  73922. {
  73923. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= image.getWidth() && y + h <= image.getHeight());
  73924. }
  73925. Image::BitmapData::~BitmapData()
  73926. {
  73927. }
  73928. void Image::setPixelData (int x, int y, int w, int h,
  73929. const uint8* sourcePixelData, int sourceLineStride)
  73930. {
  73931. jassert (x >= 0 && y >= 0 && w > 0 && h > 0 && x + w <= imageWidth && y + h <= imageHeight);
  73932. if (Rectangle<int>::intersectRectangles (x, y, w, h, 0, 0, imageWidth, imageHeight))
  73933. {
  73934. const BitmapData dest (*this, x, y, w, h, true);
  73935. for (int i = 0; i < h; ++i)
  73936. {
  73937. memcpy (dest.getLinePointer(i),
  73938. sourcePixelData + sourceLineStride * i,
  73939. w * dest.pixelStride);
  73940. }
  73941. }
  73942. }
  73943. void Image::clear (int dx, int dy, int dw, int dh,
  73944. const Colour& colourToClearTo)
  73945. {
  73946. const PixelARGB col (colourToClearTo.getPixelARGB());
  73947. const BitmapData destData (*this, dx, dy, dw, dh, true);
  73948. uint8* dest = destData.data;
  73949. while (--dh >= 0)
  73950. {
  73951. uint8* line = dest;
  73952. dest += destData.lineStride;
  73953. if (isARGB())
  73954. {
  73955. for (int x = dw; --x >= 0;)
  73956. {
  73957. ((PixelARGB*) line)->set (col);
  73958. line += destData.pixelStride;
  73959. }
  73960. }
  73961. else if (isRGB())
  73962. {
  73963. for (int x = dw; --x >= 0;)
  73964. {
  73965. ((PixelRGB*) line)->set (col);
  73966. line += destData.pixelStride;
  73967. }
  73968. }
  73969. else
  73970. {
  73971. for (int x = dw; --x >= 0;)
  73972. {
  73973. *line = col.getAlpha();
  73974. line += destData.pixelStride;
  73975. }
  73976. }
  73977. }
  73978. }
  73979. Image* Image::createCopy (int newWidth, int newHeight,
  73980. const Graphics::ResamplingQuality quality) const
  73981. {
  73982. if (newWidth < 0)
  73983. newWidth = imageWidth;
  73984. if (newHeight < 0)
  73985. newHeight = imageHeight;
  73986. Image* const newImage = Image::createNativeImage (format, newWidth, newHeight, true);
  73987. Graphics g (*newImage);
  73988. g.setImageResamplingQuality (quality);
  73989. g.drawImage (this,
  73990. 0, 0, newWidth, newHeight,
  73991. 0, 0, imageWidth, imageHeight,
  73992. false);
  73993. return newImage;
  73994. }
  73995. Image* Image::createCopyOfAlphaChannel() const
  73996. {
  73997. jassert (format != SingleChannel);
  73998. Image* const newImage = Image::createNativeImage (SingleChannel, imageWidth, imageHeight, false);
  73999. if (! hasAlphaChannel())
  74000. {
  74001. newImage->clear (0, 0, imageWidth, imageHeight, Colours::black);
  74002. }
  74003. else
  74004. {
  74005. const BitmapData destData (*newImage, 0, 0, imageWidth, imageHeight, true);
  74006. const BitmapData srcData (*this, 0, 0, imageWidth, imageHeight);
  74007. for (int y = 0; y < imageHeight; ++y)
  74008. {
  74009. const PixelARGB* src = (const PixelARGB*) srcData.getLinePointer(y);
  74010. uint8* dst = destData.getLinePointer (y);
  74011. for (int x = imageWidth; --x >= 0;)
  74012. {
  74013. *dst++ = src->getAlpha();
  74014. ++src;
  74015. }
  74016. }
  74017. }
  74018. return newImage;
  74019. }
  74020. const Colour Image::getPixelAt (const int x, const int y) const
  74021. {
  74022. Colour c;
  74023. if (((unsigned int) x) < (unsigned int) imageWidth
  74024. && ((unsigned int) y) < (unsigned int) imageHeight)
  74025. {
  74026. const BitmapData srcData (*this, x, y, 1, 1);
  74027. if (isARGB())
  74028. {
  74029. PixelARGB p (*(const PixelARGB*) srcData.data);
  74030. p.unpremultiply();
  74031. c = Colour (p.getARGB());
  74032. }
  74033. else if (isRGB())
  74034. c = Colour (((const PixelRGB*) srcData.data)->getARGB());
  74035. else
  74036. c = Colour ((uint8) 0, (uint8) 0, (uint8) 0, *(srcData.data));
  74037. }
  74038. return c;
  74039. }
  74040. void Image::setPixelAt (const int x, const int y,
  74041. const Colour& colour)
  74042. {
  74043. if (((unsigned int) x) < (unsigned int) imageWidth
  74044. && ((unsigned int) y) < (unsigned int) imageHeight)
  74045. {
  74046. const BitmapData destData (*this, x, y, 1, 1, true);
  74047. const PixelARGB col (colour.getPixelARGB());
  74048. if (isARGB())
  74049. ((PixelARGB*) destData.data)->set (col);
  74050. else if (isRGB())
  74051. ((PixelRGB*) destData.data)->set (col);
  74052. else
  74053. *(destData.data) = col.getAlpha();
  74054. }
  74055. }
  74056. void Image::multiplyAlphaAt (const int x, const int y,
  74057. const float multiplier)
  74058. {
  74059. if (((unsigned int) x) < (unsigned int) imageWidth
  74060. && ((unsigned int) y) < (unsigned int) imageHeight
  74061. && hasAlphaChannel())
  74062. {
  74063. const BitmapData destData (*this, x, y, 1, 1, true);
  74064. if (isARGB())
  74065. ((PixelARGB*) destData.data)->multiplyAlpha (multiplier);
  74066. else
  74067. *(destData.data) = (uint8) (*(destData.data) * multiplier);
  74068. }
  74069. }
  74070. void Image::multiplyAllAlphas (const float amountToMultiplyBy)
  74071. {
  74072. if (hasAlphaChannel())
  74073. {
  74074. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  74075. if (isARGB())
  74076. {
  74077. for (int y = 0; y < imageHeight; ++y)
  74078. {
  74079. uint8* p = destData.getLinePointer (y);
  74080. for (int x = 0; x < imageWidth; ++x)
  74081. {
  74082. ((PixelARGB*) p)->multiplyAlpha (amountToMultiplyBy);
  74083. p += destData.pixelStride;
  74084. }
  74085. }
  74086. }
  74087. else
  74088. {
  74089. for (int y = 0; y < imageHeight; ++y)
  74090. {
  74091. uint8* p = destData.getLinePointer (y);
  74092. for (int x = 0; x < imageWidth; ++x)
  74093. {
  74094. *p = (uint8) (*p * amountToMultiplyBy);
  74095. p += destData.pixelStride;
  74096. }
  74097. }
  74098. }
  74099. }
  74100. else
  74101. {
  74102. jassertfalse // can't do this without an alpha-channel!
  74103. }
  74104. }
  74105. void Image::desaturate()
  74106. {
  74107. if (isARGB() || isRGB())
  74108. {
  74109. const BitmapData destData (*this, 0, 0, getWidth(), getHeight(), true);
  74110. if (isARGB())
  74111. {
  74112. for (int y = 0; y < imageHeight; ++y)
  74113. {
  74114. uint8* p = destData.getLinePointer (y);
  74115. for (int x = 0; x < imageWidth; ++x)
  74116. {
  74117. ((PixelARGB*) p)->desaturate();
  74118. p += destData.pixelStride;
  74119. }
  74120. }
  74121. }
  74122. else
  74123. {
  74124. for (int y = 0; y < imageHeight; ++y)
  74125. {
  74126. uint8* p = destData.getLinePointer (y);
  74127. for (int x = 0; x < imageWidth; ++x)
  74128. {
  74129. ((PixelRGB*) p)->desaturate();
  74130. p += destData.pixelStride;
  74131. }
  74132. }
  74133. }
  74134. }
  74135. }
  74136. void Image::createSolidAreaMask (RectangleList& result, const float alphaThreshold) const
  74137. {
  74138. if (hasAlphaChannel())
  74139. {
  74140. const uint8 threshold = (uint8) jlimit (0, 255, roundToInt (alphaThreshold * 255.0f));
  74141. SparseSet <int> pixelsOnRow;
  74142. const BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  74143. for (int y = 0; y < imageHeight; ++y)
  74144. {
  74145. pixelsOnRow.clear();
  74146. const uint8* lineData = srcData.getLinePointer (y);
  74147. if (isARGB())
  74148. {
  74149. for (int x = 0; x < imageWidth; ++x)
  74150. {
  74151. if (((const PixelARGB*) lineData)->getAlpha() >= threshold)
  74152. pixelsOnRow.addRange (x, 1);
  74153. lineData += srcData.pixelStride;
  74154. }
  74155. }
  74156. else
  74157. {
  74158. for (int x = 0; x < imageWidth; ++x)
  74159. {
  74160. if (*lineData >= threshold)
  74161. pixelsOnRow.addRange (x, 1);
  74162. lineData += srcData.pixelStride;
  74163. }
  74164. }
  74165. for (int i = 0; i < pixelsOnRow.getNumRanges(); ++i)
  74166. {
  74167. int x, w;
  74168. if (pixelsOnRow.getRange (i, x, w))
  74169. result.add (Rectangle<int> (x, y, w, 1));
  74170. }
  74171. result.consolidate();
  74172. }
  74173. }
  74174. else
  74175. {
  74176. result.add (0, 0, imageWidth, imageHeight);
  74177. }
  74178. }
  74179. void Image::moveImageSection (int dx, int dy,
  74180. int sx, int sy,
  74181. int w, int h)
  74182. {
  74183. if (dx < 0)
  74184. {
  74185. w += dx;
  74186. sx -= dx;
  74187. dx = 0;
  74188. }
  74189. if (dy < 0)
  74190. {
  74191. h += dy;
  74192. sy -= dy;
  74193. dy = 0;
  74194. }
  74195. if (sx < 0)
  74196. {
  74197. w += sx;
  74198. dx -= sx;
  74199. sx = 0;
  74200. }
  74201. if (sy < 0)
  74202. {
  74203. h += sy;
  74204. dy -= sy;
  74205. sy = 0;
  74206. }
  74207. const int minX = jmin (dx, sx);
  74208. const int minY = jmin (dy, sy);
  74209. w = jmin (w, getWidth() - jmax (sx, dx));
  74210. h = jmin (h, getHeight() - jmax (sy, dy));
  74211. if (w > 0 && h > 0)
  74212. {
  74213. const int maxX = jmax (dx, sx) + w;
  74214. const int maxY = jmax (dy, sy) + h;
  74215. const BitmapData destData (*this, minX, minY, maxX - minX, maxY - minY, true);
  74216. uint8* dst = destData.getPixelPointer (dx - minX, dy - minY);
  74217. const uint8* src = destData.getPixelPointer (sx - minX, sy - minY);
  74218. const int lineSize = destData.pixelStride * w;
  74219. if (dy > sy)
  74220. {
  74221. while (--h >= 0)
  74222. {
  74223. const int offset = h * destData.lineStride;
  74224. memmove (dst + offset, src + offset, lineSize);
  74225. }
  74226. }
  74227. else if (dst != src)
  74228. {
  74229. while (--h >= 0)
  74230. {
  74231. memmove (dst, src, lineSize);
  74232. dst += destData.lineStride;
  74233. src += destData.lineStride;
  74234. }
  74235. }
  74236. }
  74237. }
  74238. END_JUCE_NAMESPACE
  74239. /*** End of inlined file: juce_Image.cpp ***/
  74240. /*** Start of inlined file: juce_ImageCache.cpp ***/
  74241. BEGIN_JUCE_NAMESPACE
  74242. struct ImageCacheItem
  74243. {
  74244. ScopedPointer <Image> image;
  74245. int64 hashCode;
  74246. int refCount;
  74247. uint32 releaseTime;
  74248. juce_UseDebuggingNewOperator
  74249. };
  74250. static ImageCache* instance = 0;
  74251. static int cacheTimeout = 5000;
  74252. ImageCache::ImageCache()
  74253. {
  74254. }
  74255. ImageCache::~ImageCache()
  74256. {
  74257. jassert (instance == this);
  74258. instance = 0;
  74259. }
  74260. Image* ImageCache::getFromHashCode (const int64 hashCode)
  74261. {
  74262. if (instance != 0)
  74263. {
  74264. const ScopedLock sl (instance->lock);
  74265. for (int i = instance->images.size(); --i >= 0;)
  74266. {
  74267. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74268. if (ci->hashCode == hashCode)
  74269. {
  74270. ci->refCount++;
  74271. return ci->image;
  74272. }
  74273. }
  74274. }
  74275. return 0;
  74276. }
  74277. void ImageCache::addImageToCache (Image* const image,
  74278. const int64 hashCode)
  74279. {
  74280. if (image != 0)
  74281. {
  74282. if (instance == 0)
  74283. instance = new ImageCache();
  74284. ImageCacheItem* const newC = new ImageCacheItem();
  74285. newC->hashCode = hashCode;
  74286. newC->image = image;
  74287. newC->refCount = 1;
  74288. newC->releaseTime = 0;
  74289. const ScopedLock sl (instance->lock);
  74290. instance->images.add (newC);
  74291. }
  74292. }
  74293. void ImageCache::release (Image* const imageToRelease)
  74294. {
  74295. if (imageToRelease != 0 && instance != 0)
  74296. {
  74297. const ScopedLock sl (instance->lock);
  74298. for (int i = instance->images.size(); --i >= 0;)
  74299. {
  74300. ImageCacheItem* const ci = instance->images.getUnchecked(i);
  74301. if ((Image*) ci->image == imageToRelease)
  74302. {
  74303. if (--(ci->refCount) == 0)
  74304. ci->releaseTime = Time::getApproximateMillisecondCounter();
  74305. if (! instance->isTimerRunning())
  74306. instance->startTimer (999);
  74307. break;
  74308. }
  74309. }
  74310. }
  74311. }
  74312. void ImageCache::releaseOrDelete (Image* const imageToRelease)
  74313. {
  74314. if (isImageInCache (imageToRelease))
  74315. release (imageToRelease);
  74316. else
  74317. delete imageToRelease;
  74318. }
  74319. bool ImageCache::isImageInCache (Image* const imageToLookFor)
  74320. {
  74321. if (instance != 0)
  74322. {
  74323. const ScopedLock sl (instance->lock);
  74324. for (int i = instance->images.size(); --i >= 0;)
  74325. if ((Image*) instance->images.getUnchecked(i)->image == imageToLookFor)
  74326. return true;
  74327. }
  74328. return false;
  74329. }
  74330. void ImageCache::incReferenceCount (Image* const image)
  74331. {
  74332. if (instance != 0)
  74333. {
  74334. const ScopedLock sl (instance->lock);
  74335. for (int i = instance->images.size(); --i >= 0;)
  74336. {
  74337. ImageCacheItem* const ci = (ImageCacheItem*) instance->images.getUnchecked(i);
  74338. if ((Image*) ci->image == image)
  74339. {
  74340. ci->refCount++;
  74341. return;
  74342. }
  74343. }
  74344. }
  74345. jassertfalse // (trying to inc the ref count of an image that's not in the cache)
  74346. }
  74347. void ImageCache::timerCallback()
  74348. {
  74349. int numberStillNeedingReleasing = 0;
  74350. const unsigned int now = Time::getApproximateMillisecondCounter();
  74351. const ScopedLock sl (lock);
  74352. for (int i = images.size(); --i >= 0;)
  74353. {
  74354. ImageCacheItem* const ci = images.getUnchecked(i);
  74355. if (ci->refCount <= 0)
  74356. {
  74357. if (now > ci->releaseTime + cacheTimeout
  74358. || now < ci->releaseTime - 1000)
  74359. {
  74360. images.remove (i);
  74361. }
  74362. else
  74363. {
  74364. ++numberStillNeedingReleasing;
  74365. }
  74366. }
  74367. }
  74368. if (numberStillNeedingReleasing == 0)
  74369. stopTimer();
  74370. }
  74371. Image* ImageCache::getFromFile (const File& file)
  74372. {
  74373. const int64 hashCode = file.hashCode64();
  74374. Image* image = getFromHashCode (hashCode);
  74375. if (image == 0)
  74376. {
  74377. image = ImageFileFormat::loadFrom (file);
  74378. addImageToCache (image, hashCode);
  74379. }
  74380. return image;
  74381. }
  74382. Image* ImageCache::getFromMemory (const void* imageData,
  74383. const int dataSize)
  74384. {
  74385. const int64 hashCode = (int64) (pointer_sized_int) imageData;
  74386. Image* image = getFromHashCode (hashCode);
  74387. if (image == 0)
  74388. {
  74389. image = ImageFileFormat::loadFrom (imageData, dataSize);
  74390. addImageToCache (image, hashCode);
  74391. }
  74392. return image;
  74393. }
  74394. void ImageCache::setCacheTimeout (const int millisecs)
  74395. {
  74396. cacheTimeout = millisecs;
  74397. }
  74398. END_JUCE_NAMESPACE
  74399. /*** End of inlined file: juce_ImageCache.cpp ***/
  74400. /*** Start of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74401. BEGIN_JUCE_NAMESPACE
  74402. ImageConvolutionKernel::ImageConvolutionKernel (const int size_)
  74403. : values (size_ * size_),
  74404. size (size_)
  74405. {
  74406. clear();
  74407. }
  74408. ImageConvolutionKernel::~ImageConvolutionKernel()
  74409. {
  74410. }
  74411. void ImageConvolutionKernel::setKernelValue (const int x,
  74412. const int y,
  74413. const float value)
  74414. {
  74415. if (((unsigned int) x) < (unsigned int) size
  74416. && ((unsigned int) y) < (unsigned int) size)
  74417. {
  74418. values [x + y * size] = value;
  74419. }
  74420. else
  74421. {
  74422. jassertfalse
  74423. }
  74424. }
  74425. void ImageConvolutionKernel::clear()
  74426. {
  74427. for (int i = size * size; --i >= 0;)
  74428. values[i] = 0;
  74429. }
  74430. void ImageConvolutionKernel::setOverallSum (const float desiredTotalSum)
  74431. {
  74432. double currentTotal = 0.0;
  74433. for (int i = size * size; --i >= 0;)
  74434. currentTotal += values[i];
  74435. rescaleAllValues ((float) (desiredTotalSum / currentTotal));
  74436. }
  74437. void ImageConvolutionKernel::rescaleAllValues (const float multiplier)
  74438. {
  74439. for (int i = size * size; --i >= 0;)
  74440. values[i] *= multiplier;
  74441. }
  74442. void ImageConvolutionKernel::createGaussianBlur (const float radius)
  74443. {
  74444. const double radiusFactor = -1.0 / (radius * radius * 2);
  74445. const int centre = size >> 1;
  74446. for (int y = size; --y >= 0;)
  74447. {
  74448. for (int x = size; --x >= 0;)
  74449. {
  74450. const int cx = x - centre;
  74451. const int cy = y - centre;
  74452. values [x + y * size] = (float) exp (radiusFactor * (cx * cx + cy * cy));
  74453. }
  74454. }
  74455. setOverallSum (1.0f);
  74456. }
  74457. void ImageConvolutionKernel::applyToImage (Image& destImage,
  74458. const Image* sourceImage,
  74459. int dx,
  74460. int dy,
  74461. int dw,
  74462. int dh) const
  74463. {
  74464. ScopedPointer <Image> imageCreated;
  74465. if (sourceImage == 0)
  74466. {
  74467. sourceImage = imageCreated = destImage.createCopy();
  74468. }
  74469. else
  74470. {
  74471. jassert (sourceImage->getWidth() == destImage.getWidth()
  74472. && sourceImage->getHeight() == destImage.getHeight()
  74473. && sourceImage->getFormat() == destImage.getFormat());
  74474. if (sourceImage->getWidth() != destImage.getWidth()
  74475. || sourceImage->getHeight() != destImage.getHeight()
  74476. || sourceImage->getFormat() != destImage.getFormat())
  74477. return;
  74478. }
  74479. const int imageWidth = destImage.getWidth();
  74480. const int imageHeight = destImage.getHeight();
  74481. if (dx >= imageWidth || dy >= imageHeight)
  74482. return;
  74483. if (dx + dw > imageWidth)
  74484. dw = imageWidth - dx;
  74485. if (dy + dh > imageHeight)
  74486. dh = imageHeight - dy;
  74487. const int dx2 = dx + dw;
  74488. const int dy2 = dy + dh;
  74489. const Image::BitmapData destData (destImage, dx, dy, dw, dh, true);
  74490. uint8* line = destData.data;
  74491. const Image::BitmapData srcData (*sourceImage, 0, 0, sourceImage->getWidth(), sourceImage->getHeight());
  74492. if (destData.pixelStride == 4)
  74493. {
  74494. for (int y = dy; y < dy2; ++y)
  74495. {
  74496. uint8* dest = line;
  74497. line += destData.lineStride;
  74498. for (int x = dx; x < dx2; ++x)
  74499. {
  74500. float c1 = 0;
  74501. float c2 = 0;
  74502. float c3 = 0;
  74503. float c4 = 0;
  74504. for (int yy = 0; yy < size; ++yy)
  74505. {
  74506. const int sy = y + yy - (size >> 1);
  74507. if (sy >= imageHeight)
  74508. break;
  74509. if (sy >= 0)
  74510. {
  74511. int sx = x - (size >> 1);
  74512. const uint8* src = srcData.getPixelPointer (sx, sy);
  74513. for (int xx = 0; xx < size; ++xx)
  74514. {
  74515. if (sx >= imageWidth)
  74516. break;
  74517. if (sx >= 0)
  74518. {
  74519. const float kernelMult = values [xx + yy * size];
  74520. c1 += kernelMult * *src++;
  74521. c2 += kernelMult * *src++;
  74522. c3 += kernelMult * *src++;
  74523. c4 += kernelMult * *src++;
  74524. }
  74525. else
  74526. {
  74527. src += 4;
  74528. }
  74529. ++sx;
  74530. }
  74531. }
  74532. }
  74533. *dest++ = (uint8) jmin (0xff, roundToInt (c1));
  74534. *dest++ = (uint8) jmin (0xff, roundToInt (c2));
  74535. *dest++ = (uint8) jmin (0xff, roundToInt (c3));
  74536. *dest++ = (uint8) jmin (0xff, roundToInt (c4));
  74537. }
  74538. }
  74539. }
  74540. else if (destData.pixelStride == 3)
  74541. {
  74542. for (int y = dy; y < dy2; ++y)
  74543. {
  74544. uint8* dest = line;
  74545. line += destData.lineStride;
  74546. for (int x = dx; x < dx2; ++x)
  74547. {
  74548. float c1 = 0;
  74549. float c2 = 0;
  74550. float c3 = 0;
  74551. for (int yy = 0; yy < size; ++yy)
  74552. {
  74553. const int sy = y + yy - (size >> 1);
  74554. if (sy >= imageHeight)
  74555. break;
  74556. if (sy >= 0)
  74557. {
  74558. int sx = x - (size >> 1);
  74559. const uint8* src = srcData.getPixelPointer (sx, sy);
  74560. for (int xx = 0; xx < size; ++xx)
  74561. {
  74562. if (sx >= imageWidth)
  74563. break;
  74564. if (sx >= 0)
  74565. {
  74566. const float kernelMult = values [xx + yy * size];
  74567. c1 += kernelMult * *src++;
  74568. c2 += kernelMult * *src++;
  74569. c3 += kernelMult * *src++;
  74570. }
  74571. else
  74572. {
  74573. src += 3;
  74574. }
  74575. ++sx;
  74576. }
  74577. }
  74578. }
  74579. *dest++ = (uint8) roundToInt (c1);
  74580. *dest++ = (uint8) roundToInt (c2);
  74581. *dest++ = (uint8) roundToInt (c3);
  74582. }
  74583. }
  74584. }
  74585. }
  74586. END_JUCE_NAMESPACE
  74587. /*** End of inlined file: juce_ImageConvolutionKernel.cpp ***/
  74588. /*** Start of inlined file: juce_ImageFileFormat.cpp ***/
  74589. BEGIN_JUCE_NAMESPACE
  74590. /*** Start of inlined file: juce_GIFLoader.h ***/
  74591. #ifndef __JUCE_GIFLOADER_JUCEHEADER__
  74592. #define __JUCE_GIFLOADER_JUCEHEADER__
  74593. #ifndef DOXYGEN
  74594. class GIFLoader
  74595. {
  74596. public:
  74597. GIFLoader (InputStream& in);
  74598. ~GIFLoader();
  74599. Image* getImage() const { return image; }
  74600. private:
  74601. Image* image;
  74602. InputStream& input;
  74603. uint8 buffer [300];
  74604. uint8 palette [256][4];
  74605. bool dataBlockIsZero, fresh, finished;
  74606. int currentBit, lastBit, lastByteIndex;
  74607. int codeSize, setCodeSize;
  74608. int maxCode, maxCodeSize;
  74609. int firstcode, oldcode;
  74610. int clearCode, end_code;
  74611. enum { maxGifCode = 1 << 12 };
  74612. int table [2] [maxGifCode];
  74613. int stack [2 * maxGifCode];
  74614. int *sp;
  74615. bool getSizeFromHeader (int& width, int& height);
  74616. bool readPalette (const int numCols);
  74617. int readDataBlock (unsigned char* dest);
  74618. int processExtension (int type, int& transparent);
  74619. int readLZWByte (bool initialise, int input_code_size);
  74620. int getCode (int code_size, bool initialise);
  74621. bool readImage (int width, int height, int interlace, int transparent);
  74622. static inline int makeWord (const uint8 a, const uint8 b) { return (b << 8) | a; }
  74623. GIFLoader (const GIFLoader&);
  74624. GIFLoader& operator= (const GIFLoader&);
  74625. };
  74626. #endif // DOXYGEN
  74627. #endif // __JUCE_GIFLOADER_JUCEHEADER__
  74628. /*** End of inlined file: juce_GIFLoader.h ***/
  74629. Image* juce_loadPNGImageFromStream (InputStream& inputStream);
  74630. bool juce_writePNGImageToStream (const Image& image, OutputStream& out);
  74631. PNGImageFormat::PNGImageFormat() {}
  74632. PNGImageFormat::~PNGImageFormat() {}
  74633. const String PNGImageFormat::getFormatName()
  74634. {
  74635. return T("PNG");
  74636. }
  74637. bool PNGImageFormat::canUnderstand (InputStream& in)
  74638. {
  74639. const int bytesNeeded = 4;
  74640. char header [bytesNeeded];
  74641. return in.read (header, bytesNeeded) == bytesNeeded
  74642. && header[1] == 'P'
  74643. && header[2] == 'N'
  74644. && header[3] == 'G';
  74645. }
  74646. Image* PNGImageFormat::decodeImage (InputStream& in)
  74647. {
  74648. return juce_loadPNGImageFromStream (in);
  74649. }
  74650. bool PNGImageFormat::writeImageToStream (const Image& sourceImage,
  74651. OutputStream& destStream)
  74652. {
  74653. return juce_writePNGImageToStream (sourceImage, destStream);
  74654. }
  74655. Image* juce_loadJPEGImageFromStream (InputStream& inputStream);
  74656. bool juce_writeJPEGImageToStream (const Image& image, OutputStream& out, float quality);
  74657. JPEGImageFormat::JPEGImageFormat()
  74658. : quality (-1.0f)
  74659. {
  74660. }
  74661. JPEGImageFormat::~JPEGImageFormat() {}
  74662. void JPEGImageFormat::setQuality (const float newQuality)
  74663. {
  74664. quality = newQuality;
  74665. }
  74666. const String JPEGImageFormat::getFormatName()
  74667. {
  74668. return T("JPEG");
  74669. }
  74670. bool JPEGImageFormat::canUnderstand (InputStream& in)
  74671. {
  74672. const int bytesNeeded = 10;
  74673. uint8 header [bytesNeeded];
  74674. if (in.read (header, bytesNeeded) == bytesNeeded)
  74675. {
  74676. return header[0] == 0xff
  74677. && header[1] == 0xd8
  74678. && header[2] == 0xff
  74679. && (header[3] == 0xe0 || header[3] == 0xe1);
  74680. }
  74681. return false;
  74682. }
  74683. Image* JPEGImageFormat::decodeImage (InputStream& in)
  74684. {
  74685. return juce_loadJPEGImageFromStream (in);
  74686. }
  74687. bool JPEGImageFormat::writeImageToStream (const Image& sourceImage,
  74688. OutputStream& destStream)
  74689. {
  74690. return juce_writeJPEGImageToStream (sourceImage, destStream, quality);
  74691. }
  74692. class GIFImageFormat : public ImageFileFormat
  74693. {
  74694. public:
  74695. GIFImageFormat() {}
  74696. ~GIFImageFormat() {}
  74697. const String getFormatName()
  74698. {
  74699. return T("GIF");
  74700. }
  74701. bool canUnderstand (InputStream& in)
  74702. {
  74703. const int bytesNeeded = 4;
  74704. char header [bytesNeeded];
  74705. return (in.read (header, bytesNeeded) == bytesNeeded)
  74706. && header[0] == 'G'
  74707. && header[1] == 'I'
  74708. && header[2] == 'F';
  74709. }
  74710. Image* decodeImage (InputStream& in)
  74711. {
  74712. const ScopedPointer <GIFLoader> loader (new GIFLoader (in));
  74713. return loader->getImage();
  74714. }
  74715. bool writeImageToStream (const Image& /*sourceImage*/, OutputStream& /*destStream*/)
  74716. {
  74717. return false;
  74718. }
  74719. };
  74720. ImageFileFormat* ImageFileFormat::findImageFormatForStream (InputStream& input)
  74721. {
  74722. static PNGImageFormat png;
  74723. static JPEGImageFormat jpg;
  74724. static GIFImageFormat gif;
  74725. ImageFileFormat* formats[4];
  74726. int numFormats = 0;
  74727. formats [numFormats++] = &png;
  74728. formats [numFormats++] = &jpg;
  74729. formats [numFormats++] = &gif;
  74730. const int64 streamPos = input.getPosition();
  74731. for (int i = 0; i < numFormats; ++i)
  74732. {
  74733. const bool found = formats[i]->canUnderstand (input);
  74734. input.setPosition (streamPos);
  74735. if (found)
  74736. return formats[i];
  74737. }
  74738. return 0;
  74739. }
  74740. Image* ImageFileFormat::loadFrom (InputStream& input)
  74741. {
  74742. ImageFileFormat* const format = findImageFormatForStream (input);
  74743. if (format != 0)
  74744. return format->decodeImage (input);
  74745. return 0;
  74746. }
  74747. Image* ImageFileFormat::loadFrom (const File& file)
  74748. {
  74749. InputStream* const in = file.createInputStream();
  74750. if (in != 0)
  74751. {
  74752. BufferedInputStream b (in, 8192, true);
  74753. return loadFrom (b);
  74754. }
  74755. return 0;
  74756. }
  74757. Image* ImageFileFormat::loadFrom (const void* rawData, const int numBytes)
  74758. {
  74759. if (rawData != 0 && numBytes > 4)
  74760. {
  74761. MemoryInputStream stream (rawData, numBytes, false);
  74762. return loadFrom (stream);
  74763. }
  74764. return 0;
  74765. }
  74766. END_JUCE_NAMESPACE
  74767. /*** End of inlined file: juce_ImageFileFormat.cpp ***/
  74768. /*** Start of inlined file: juce_GIFLoader.cpp ***/
  74769. BEGIN_JUCE_NAMESPACE
  74770. GIFLoader::GIFLoader (InputStream& in)
  74771. : image (0),
  74772. input (in),
  74773. dataBlockIsZero (false),
  74774. fresh (false),
  74775. finished (false)
  74776. {
  74777. currentBit = lastBit = lastByteIndex = 0;
  74778. maxCode = maxCodeSize = codeSize = setCodeSize = 0;
  74779. firstcode = oldcode = 0;
  74780. clearCode = end_code = 0;
  74781. int imageWidth, imageHeight;
  74782. int transparent = -1;
  74783. if (! getSizeFromHeader (imageWidth, imageHeight))
  74784. return;
  74785. if ((imageWidth <= 0) || (imageHeight <= 0))
  74786. return;
  74787. unsigned char buf [16];
  74788. if (in.read (buf, 3) != 3)
  74789. return;
  74790. int numColours = 2 << (buf[0] & 7);
  74791. if ((buf[0] & 0x80) != 0)
  74792. readPalette (numColours);
  74793. for (;;)
  74794. {
  74795. if (input.read (buf, 1) != 1)
  74796. break;
  74797. if (buf[0] == ';')
  74798. break;
  74799. if (buf[0] == '!')
  74800. {
  74801. if (input.read (buf, 1) != 1)
  74802. break;
  74803. if (processExtension (buf[0], transparent) < 0)
  74804. break;
  74805. continue;
  74806. }
  74807. if (buf[0] != ',')
  74808. continue;
  74809. if (input.read (buf, 9) != 9)
  74810. break;
  74811. imageWidth = makeWord (buf[4], buf[5]);
  74812. imageHeight = makeWord (buf[6], buf[7]);
  74813. numColours = 2 << (buf[8] & 7);
  74814. if ((buf[8] & 0x80) != 0)
  74815. if (! readPalette (numColours))
  74816. break;
  74817. image = Image::createNativeImage ((transparent >= 0) ? Image::ARGB : Image::RGB,
  74818. imageWidth, imageHeight, (transparent >= 0));
  74819. readImage (imageWidth, imageHeight,
  74820. (buf[8] & 0x40) != 0,
  74821. transparent);
  74822. break;
  74823. }
  74824. }
  74825. GIFLoader::~GIFLoader()
  74826. {
  74827. }
  74828. bool GIFLoader::getSizeFromHeader (int& w, int& h)
  74829. {
  74830. unsigned char b [8];
  74831. if (input.read (b, 6) == 6)
  74832. {
  74833. if ((strncmp ("GIF87a", (char*) b, 6) == 0)
  74834. || (strncmp ("GIF89a", (char*) b, 6) == 0))
  74835. {
  74836. if (input.read (b, 4) == 4)
  74837. {
  74838. w = makeWord (b[0], b[1]);
  74839. h = makeWord (b[2], b[3]);
  74840. return true;
  74841. }
  74842. }
  74843. }
  74844. return false;
  74845. }
  74846. bool GIFLoader::readPalette (const int numCols)
  74847. {
  74848. unsigned char rgb[4];
  74849. for (int i = 0; i < numCols; ++i)
  74850. {
  74851. input.read (rgb, 3);
  74852. palette [i][0] = rgb[0];
  74853. palette [i][1] = rgb[1];
  74854. palette [i][2] = rgb[2];
  74855. palette [i][3] = 0xff;
  74856. }
  74857. return true;
  74858. }
  74859. int GIFLoader::readDataBlock (unsigned char* const dest)
  74860. {
  74861. unsigned char n;
  74862. if (input.read (&n, 1) == 1)
  74863. {
  74864. dataBlockIsZero = (n == 0);
  74865. if (dataBlockIsZero || (input.read (dest, n) == n))
  74866. return n;
  74867. }
  74868. return -1;
  74869. }
  74870. int GIFLoader::processExtension (const int type, int& transparent)
  74871. {
  74872. unsigned char b [300];
  74873. int n = 0;
  74874. if (type == 0xf9)
  74875. {
  74876. n = readDataBlock (b);
  74877. if (n < 0)
  74878. return 1;
  74879. if ((b[0] & 0x1) != 0)
  74880. transparent = b[3];
  74881. }
  74882. do
  74883. {
  74884. n = readDataBlock (b);
  74885. }
  74886. while (n > 0);
  74887. return n;
  74888. }
  74889. int GIFLoader::getCode (const int codeSize_, const bool initialise)
  74890. {
  74891. if (initialise)
  74892. {
  74893. currentBit = 0;
  74894. lastBit = 0;
  74895. finished = false;
  74896. return 0;
  74897. }
  74898. if ((currentBit + codeSize_) >= lastBit)
  74899. {
  74900. if (finished)
  74901. return -1;
  74902. buffer[0] = buffer [lastByteIndex - 2];
  74903. buffer[1] = buffer [lastByteIndex - 1];
  74904. const int n = readDataBlock (&buffer[2]);
  74905. if (n == 0)
  74906. finished = true;
  74907. lastByteIndex = 2 + n;
  74908. currentBit = (currentBit - lastBit) + 16;
  74909. lastBit = (2 + n) * 8 ;
  74910. }
  74911. int result = 0;
  74912. int i = currentBit;
  74913. for (int j = 0; j < codeSize_; ++j)
  74914. {
  74915. result |= ((buffer[i >> 3] & (1 << (i & 7))) != 0) << j;
  74916. ++i;
  74917. }
  74918. currentBit += codeSize_;
  74919. return result;
  74920. }
  74921. int GIFLoader::readLZWByte (const bool initialise, const int inputCodeSize)
  74922. {
  74923. int code, incode, i;
  74924. if (initialise)
  74925. {
  74926. setCodeSize = inputCodeSize;
  74927. codeSize = setCodeSize + 1;
  74928. clearCode = 1 << setCodeSize;
  74929. end_code = clearCode + 1;
  74930. maxCodeSize = 2 * clearCode;
  74931. maxCode = clearCode + 2;
  74932. getCode (0, true);
  74933. fresh = true;
  74934. for (i = 0; i < clearCode; ++i)
  74935. {
  74936. table[0][i] = 0;
  74937. table[1][i] = i;
  74938. }
  74939. for (; i < maxGifCode; ++i)
  74940. {
  74941. table[0][i] = 0;
  74942. table[1][i] = 0;
  74943. }
  74944. sp = stack;
  74945. return 0;
  74946. }
  74947. else if (fresh)
  74948. {
  74949. fresh = false;
  74950. do
  74951. {
  74952. firstcode = oldcode
  74953. = getCode (codeSize, false);
  74954. }
  74955. while (firstcode == clearCode);
  74956. return firstcode;
  74957. }
  74958. if (sp > stack)
  74959. return *--sp;
  74960. while ((code = getCode (codeSize, false)) >= 0)
  74961. {
  74962. if (code == clearCode)
  74963. {
  74964. for (i = 0; i < clearCode; ++i)
  74965. {
  74966. table[0][i] = 0;
  74967. table[1][i] = i;
  74968. }
  74969. for (; i < maxGifCode; ++i)
  74970. {
  74971. table[0][i] = 0;
  74972. table[1][i] = 0;
  74973. }
  74974. codeSize = setCodeSize + 1;
  74975. maxCodeSize = 2 * clearCode;
  74976. maxCode = clearCode + 2;
  74977. sp = stack;
  74978. firstcode = oldcode = getCode (codeSize, false);
  74979. return firstcode;
  74980. }
  74981. else if (code == end_code)
  74982. {
  74983. if (dataBlockIsZero)
  74984. return -2;
  74985. unsigned char buf [260];
  74986. int n;
  74987. while ((n = readDataBlock (buf)) > 0)
  74988. {}
  74989. if (n != 0)
  74990. return -2;
  74991. }
  74992. incode = code;
  74993. if (code >= maxCode)
  74994. {
  74995. *sp++ = firstcode;
  74996. code = oldcode;
  74997. }
  74998. while (code >= clearCode)
  74999. {
  75000. *sp++ = table[1][code];
  75001. if (code == table[0][code])
  75002. return -2;
  75003. code = table[0][code];
  75004. }
  75005. *sp++ = firstcode = table[1][code];
  75006. if ((code = maxCode) < maxGifCode)
  75007. {
  75008. table[0][code] = oldcode;
  75009. table[1][code] = firstcode;
  75010. ++maxCode;
  75011. if ((maxCode >= maxCodeSize)
  75012. && (maxCodeSize < maxGifCode))
  75013. {
  75014. maxCodeSize <<= 1;
  75015. ++codeSize;
  75016. }
  75017. }
  75018. oldcode = incode;
  75019. if (sp > stack)
  75020. return *--sp;
  75021. }
  75022. return code;
  75023. }
  75024. bool GIFLoader::readImage (const int width, const int height,
  75025. const int interlace, const int transparent)
  75026. {
  75027. unsigned char c;
  75028. if (input.read (&c, 1) != 1
  75029. || readLZWByte (true, c) < 0)
  75030. return false;
  75031. if (transparent >= 0)
  75032. {
  75033. palette [transparent][0] = 0;
  75034. palette [transparent][1] = 0;
  75035. palette [transparent][2] = 0;
  75036. palette [transparent][3] = 0;
  75037. }
  75038. int index;
  75039. int xpos = 0, ypos = 0, pass = 0;
  75040. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  75041. uint8* p = destData.data;
  75042. const bool hasAlpha = image->hasAlphaChannel();
  75043. while ((index = readLZWByte (false, c)) >= 0)
  75044. {
  75045. const uint8* const paletteEntry = palette [index];
  75046. if (hasAlpha)
  75047. {
  75048. ((PixelARGB*) p)->setARGB (paletteEntry[3],
  75049. paletteEntry[0],
  75050. paletteEntry[1],
  75051. paletteEntry[2]);
  75052. ((PixelARGB*) p)->premultiply();
  75053. }
  75054. else
  75055. {
  75056. ((PixelRGB*) p)->setARGB (0,
  75057. paletteEntry[0],
  75058. paletteEntry[1],
  75059. paletteEntry[2]);
  75060. }
  75061. p += destData.pixelStride;
  75062. ++xpos;
  75063. if (xpos == width)
  75064. {
  75065. xpos = 0;
  75066. if (interlace)
  75067. {
  75068. switch (pass)
  75069. {
  75070. case 0:
  75071. case 1:
  75072. ypos += 8;
  75073. break;
  75074. case 2:
  75075. ypos += 4;
  75076. break;
  75077. case 3:
  75078. ypos += 2;
  75079. break;
  75080. }
  75081. while (ypos >= height)
  75082. {
  75083. ++pass;
  75084. switch (pass)
  75085. {
  75086. case 1:
  75087. ypos = 4;
  75088. break;
  75089. case 2:
  75090. ypos = 2;
  75091. break;
  75092. case 3:
  75093. ypos = 1;
  75094. break;
  75095. default:
  75096. return true;
  75097. }
  75098. }
  75099. }
  75100. else
  75101. {
  75102. ++ypos;
  75103. }
  75104. p = destData.getPixelPointer (xpos, ypos);
  75105. }
  75106. if (ypos >= height)
  75107. break;
  75108. }
  75109. return true;
  75110. }
  75111. END_JUCE_NAMESPACE
  75112. /*** End of inlined file: juce_GIFLoader.cpp ***/
  75113. #endif
  75114. //==============================================================================
  75115. // some files include lots of library code, so leave them to the end to avoid cluttering
  75116. // up the build for the clean files.
  75117. #if JUCE_BUILD_CORE
  75118. /*** Start of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75119. namespace zlibNamespace
  75120. {
  75121. #if JUCE_INCLUDE_ZLIB_CODE
  75122. #undef OS_CODE
  75123. #undef fdopen
  75124. /*** Start of inlined file: zlib.h ***/
  75125. #ifndef ZLIB_H
  75126. #define ZLIB_H
  75127. /*** Start of inlined file: zconf.h ***/
  75128. #ifndef ZCONF_H
  75129. #define ZCONF_H
  75130. // *** Just a few hacks here to make it compile nicely with Juce..
  75131. #define Z_PREFIX 1
  75132. #undef __MACTYPES__
  75133. #ifdef _MSC_VER
  75134. #pragma warning (disable : 4131 4127 4244 4267)
  75135. #endif
  75136. #ifdef Z_PREFIX
  75137. # define deflateInit_ z_deflateInit_
  75138. # define deflate z_deflate
  75139. # define deflateEnd z_deflateEnd
  75140. # define inflateInit_ z_inflateInit_
  75141. # define inflate z_inflate
  75142. # define inflateEnd z_inflateEnd
  75143. # define deflateInit2_ z_deflateInit2_
  75144. # define deflateSetDictionary z_deflateSetDictionary
  75145. # define deflateCopy z_deflateCopy
  75146. # define deflateReset z_deflateReset
  75147. # define deflateParams z_deflateParams
  75148. # define deflateBound z_deflateBound
  75149. # define deflatePrime z_deflatePrime
  75150. # define inflateInit2_ z_inflateInit2_
  75151. # define inflateSetDictionary z_inflateSetDictionary
  75152. # define inflateSync z_inflateSync
  75153. # define inflateSyncPoint z_inflateSyncPoint
  75154. # define inflateCopy z_inflateCopy
  75155. # define inflateReset z_inflateReset
  75156. # define inflateBack z_inflateBack
  75157. # define inflateBackEnd z_inflateBackEnd
  75158. # define compress z_compress
  75159. # define compress2 z_compress2
  75160. # define compressBound z_compressBound
  75161. # define uncompress z_uncompress
  75162. # define adler32 z_adler32
  75163. # define crc32 z_crc32
  75164. # define get_crc_table z_get_crc_table
  75165. # define zError z_zError
  75166. # define alloc_func z_alloc_func
  75167. # define free_func z_free_func
  75168. # define in_func z_in_func
  75169. # define out_func z_out_func
  75170. # define Byte z_Byte
  75171. # define uInt z_uInt
  75172. # define uLong z_uLong
  75173. # define Bytef z_Bytef
  75174. # define charf z_charf
  75175. # define intf z_intf
  75176. # define uIntf z_uIntf
  75177. # define uLongf z_uLongf
  75178. # define voidpf z_voidpf
  75179. # define voidp z_voidp
  75180. #endif
  75181. #if defined(__MSDOS__) && !defined(MSDOS)
  75182. # define MSDOS
  75183. #endif
  75184. #if (defined(OS_2) || defined(__OS2__)) && !defined(OS2)
  75185. # define OS2
  75186. #endif
  75187. #if defined(_WINDOWS) && !defined(WINDOWS)
  75188. # define WINDOWS
  75189. #endif
  75190. #if defined(_WIN32) || defined(_WIN32_WCE) || defined(__WIN32__)
  75191. # ifndef WIN32
  75192. # define WIN32
  75193. # endif
  75194. #endif
  75195. #if (defined(MSDOS) || defined(OS2) || defined(WINDOWS)) && !defined(WIN32)
  75196. # if !defined(__GNUC__) && !defined(__FLAT__) && !defined(__386__)
  75197. # ifndef SYS16BIT
  75198. # define SYS16BIT
  75199. # endif
  75200. # endif
  75201. #endif
  75202. #ifdef SYS16BIT
  75203. # define MAXSEG_64K
  75204. #endif
  75205. #ifdef MSDOS
  75206. # define UNALIGNED_OK
  75207. #endif
  75208. #ifdef __STDC_VERSION__
  75209. # ifndef STDC
  75210. # define STDC
  75211. # endif
  75212. # if __STDC_VERSION__ >= 199901L
  75213. # ifndef STDC99
  75214. # define STDC99
  75215. # endif
  75216. # endif
  75217. #endif
  75218. #if !defined(STDC) && (defined(__STDC__) || defined(__cplusplus))
  75219. # define STDC
  75220. #endif
  75221. #if !defined(STDC) && (defined(__GNUC__) || defined(__BORLANDC__))
  75222. # define STDC
  75223. #endif
  75224. #if !defined(STDC) && (defined(MSDOS) || defined(WINDOWS) || defined(WIN32))
  75225. # define STDC
  75226. #endif
  75227. #if !defined(STDC) && (defined(OS2) || defined(__HOS_AIX__))
  75228. # define STDC
  75229. #endif
  75230. #if defined(__OS400__) && !defined(STDC) /* iSeries (formerly AS/400). */
  75231. # define STDC
  75232. #endif
  75233. #ifndef STDC
  75234. # ifndef const /* cannot use !defined(STDC) && !defined(const) on Mac */
  75235. # define const /* note: need a more gentle solution here */
  75236. # endif
  75237. #endif
  75238. #if defined(__MWERKS__)||defined(applec)||defined(THINK_C)||defined(__SC__)
  75239. # define NO_DUMMY_DECL
  75240. #endif
  75241. #ifndef MAX_MEM_LEVEL
  75242. # ifdef MAXSEG_64K
  75243. # define MAX_MEM_LEVEL 8
  75244. # else
  75245. # define MAX_MEM_LEVEL 9
  75246. # endif
  75247. #endif
  75248. #ifndef MAX_WBITS
  75249. # define MAX_WBITS 15 /* 32K LZ77 window */
  75250. #endif
  75251. #ifndef OF /* function prototypes */
  75252. # ifdef STDC
  75253. # define OF(args) args
  75254. # else
  75255. # define OF(args) ()
  75256. # endif
  75257. #endif
  75258. #ifdef SYS16BIT
  75259. # if defined(M_I86SM) || defined(M_I86MM)
  75260. # define SMALL_MEDIUM
  75261. # ifdef _MSC_VER
  75262. # define FAR _far
  75263. # else
  75264. # define FAR far
  75265. # endif
  75266. # endif
  75267. # if (defined(__SMALL__) || defined(__MEDIUM__))
  75268. # define SMALL_MEDIUM
  75269. # ifdef __BORLANDC__
  75270. # define FAR _far
  75271. # else
  75272. # define FAR far
  75273. # endif
  75274. # endif
  75275. #endif
  75276. #if defined(WINDOWS) || defined(WIN32)
  75277. # ifdef ZLIB_DLL
  75278. # if defined(WIN32) && (!defined(__BORLANDC__) || (__BORLANDC__ >= 0x500))
  75279. # ifdef ZLIB_INTERNAL
  75280. # define ZEXTERN extern __declspec(dllexport)
  75281. # else
  75282. # define ZEXTERN extern __declspec(dllimport)
  75283. # endif
  75284. # endif
  75285. # endif /* ZLIB_DLL */
  75286. # ifdef ZLIB_WINAPI
  75287. # ifdef FAR
  75288. # undef FAR
  75289. # endif
  75290. # include <windows.h>
  75291. # define ZEXPORT WINAPI
  75292. # ifdef WIN32
  75293. # define ZEXPORTVA WINAPIV
  75294. # else
  75295. # define ZEXPORTVA FAR CDECL
  75296. # endif
  75297. # endif
  75298. #endif
  75299. #if defined (__BEOS__)
  75300. # ifdef ZLIB_DLL
  75301. # ifdef ZLIB_INTERNAL
  75302. # define ZEXPORT __declspec(dllexport)
  75303. # define ZEXPORTVA __declspec(dllexport)
  75304. # else
  75305. # define ZEXPORT __declspec(dllimport)
  75306. # define ZEXPORTVA __declspec(dllimport)
  75307. # endif
  75308. # endif
  75309. #endif
  75310. #ifndef ZEXTERN
  75311. # define ZEXTERN extern
  75312. #endif
  75313. #ifndef ZEXPORT
  75314. # define ZEXPORT
  75315. #endif
  75316. #ifndef ZEXPORTVA
  75317. # define ZEXPORTVA
  75318. #endif
  75319. #ifndef FAR
  75320. # define FAR
  75321. #endif
  75322. #if !defined(__MACTYPES__)
  75323. typedef unsigned char Byte; /* 8 bits */
  75324. #endif
  75325. typedef unsigned int uInt; /* 16 bits or more */
  75326. typedef unsigned long uLong; /* 32 bits or more */
  75327. #ifdef SMALL_MEDIUM
  75328. # define Bytef Byte FAR
  75329. #else
  75330. typedef Byte FAR Bytef;
  75331. #endif
  75332. typedef char FAR charf;
  75333. typedef int FAR intf;
  75334. typedef uInt FAR uIntf;
  75335. typedef uLong FAR uLongf;
  75336. #ifdef STDC
  75337. typedef void const *voidpc;
  75338. typedef void FAR *voidpf;
  75339. typedef void *voidp;
  75340. #else
  75341. typedef Byte const *voidpc;
  75342. typedef Byte FAR *voidpf;
  75343. typedef Byte *voidp;
  75344. #endif
  75345. #if 0 /* HAVE_UNISTD_H -- this line is updated by ./configure */
  75346. # include <sys/types.h> /* for off_t */
  75347. # include <unistd.h> /* for SEEK_* and off_t */
  75348. # ifdef VMS
  75349. # include <unixio.h> /* for off_t */
  75350. # endif
  75351. # define z_off_t off_t
  75352. #endif
  75353. #ifndef SEEK_SET
  75354. # define SEEK_SET 0 /* Seek from beginning of file. */
  75355. # define SEEK_CUR 1 /* Seek from current position. */
  75356. # define SEEK_END 2 /* Set file pointer to EOF plus "offset" */
  75357. #endif
  75358. #ifndef z_off_t
  75359. # define z_off_t long
  75360. #endif
  75361. #if defined(__OS400__)
  75362. # define NO_vsnprintf
  75363. #endif
  75364. #if defined(__MVS__)
  75365. # define NO_vsnprintf
  75366. # ifdef FAR
  75367. # undef FAR
  75368. # endif
  75369. #endif
  75370. #if defined(__MVS__)
  75371. # pragma map(deflateInit_,"DEIN")
  75372. # pragma map(deflateInit2_,"DEIN2")
  75373. # pragma map(deflateEnd,"DEEND")
  75374. # pragma map(deflateBound,"DEBND")
  75375. # pragma map(inflateInit_,"ININ")
  75376. # pragma map(inflateInit2_,"ININ2")
  75377. # pragma map(inflateEnd,"INEND")
  75378. # pragma map(inflateSync,"INSY")
  75379. # pragma map(inflateSetDictionary,"INSEDI")
  75380. # pragma map(compressBound,"CMBND")
  75381. # pragma map(inflate_table,"INTABL")
  75382. # pragma map(inflate_fast,"INFA")
  75383. # pragma map(inflate_copyright,"INCOPY")
  75384. #endif
  75385. #endif /* ZCONF_H */
  75386. /*** End of inlined file: zconf.h ***/
  75387. #ifdef __cplusplus
  75388. extern "C" {
  75389. #endif
  75390. #define ZLIB_VERSION "1.2.3"
  75391. #define ZLIB_VERNUM 0x1230
  75392. typedef voidpf (*alloc_func) OF((voidpf opaque, uInt items, uInt size));
  75393. typedef void (*free_func) OF((voidpf opaque, voidpf address));
  75394. struct internal_state;
  75395. typedef struct z_stream_s {
  75396. Bytef *next_in; /* next input byte */
  75397. uInt avail_in; /* number of bytes available at next_in */
  75398. uLong total_in; /* total nb of input bytes read so far */
  75399. Bytef *next_out; /* next output byte should be put there */
  75400. uInt avail_out; /* remaining free space at next_out */
  75401. uLong total_out; /* total nb of bytes output so far */
  75402. char *msg; /* last error message, NULL if no error */
  75403. struct internal_state FAR *state; /* not visible by applications */
  75404. alloc_func zalloc; /* used to allocate the internal state */
  75405. free_func zfree; /* used to free the internal state */
  75406. voidpf opaque; /* private data object passed to zalloc and zfree */
  75407. int data_type; /* best guess about the data type: binary or text */
  75408. uLong adler; /* adler32 value of the uncompressed data */
  75409. uLong reserved; /* reserved for future use */
  75410. } z_stream;
  75411. typedef z_stream FAR *z_streamp;
  75412. typedef struct gz_header_s {
  75413. int text; /* true if compressed data believed to be text */
  75414. uLong time; /* modification time */
  75415. int xflags; /* extra flags (not used when writing a gzip file) */
  75416. int os; /* operating system */
  75417. Bytef *extra; /* pointer to extra field or Z_NULL if none */
  75418. uInt extra_len; /* extra field length (valid if extra != Z_NULL) */
  75419. uInt extra_max; /* space at extra (only when reading header) */
  75420. Bytef *name; /* pointer to zero-terminated file name or Z_NULL */
  75421. uInt name_max; /* space at name (only when reading header) */
  75422. Bytef *comment; /* pointer to zero-terminated comment or Z_NULL */
  75423. uInt comm_max; /* space at comment (only when reading header) */
  75424. int hcrc; /* true if there was or will be a header crc */
  75425. int done; /* true when done reading gzip header (not used
  75426. when writing a gzip file) */
  75427. } gz_header;
  75428. typedef gz_header FAR *gz_headerp;
  75429. #define Z_NO_FLUSH 0
  75430. #define Z_PARTIAL_FLUSH 1 /* will be removed, use Z_SYNC_FLUSH instead */
  75431. #define Z_SYNC_FLUSH 2
  75432. #define Z_FULL_FLUSH 3
  75433. #define Z_FINISH 4
  75434. #define Z_BLOCK 5
  75435. #define Z_OK 0
  75436. #define Z_STREAM_END 1
  75437. #define Z_NEED_DICT 2
  75438. #define Z_ERRNO (-1)
  75439. #define Z_STREAM_ERROR (-2)
  75440. #define Z_DATA_ERROR (-3)
  75441. #define Z_MEM_ERROR (-4)
  75442. #define Z_BUF_ERROR (-5)
  75443. #define Z_VERSION_ERROR (-6)
  75444. #define Z_NO_COMPRESSION 0
  75445. #define Z_BEST_SPEED 1
  75446. #define Z_BEST_COMPRESSION 9
  75447. #define Z_DEFAULT_COMPRESSION (-1)
  75448. #define Z_FILTERED 1
  75449. #define Z_HUFFMAN_ONLY 2
  75450. #define Z_RLE 3
  75451. #define Z_FIXED 4
  75452. #define Z_DEFAULT_STRATEGY 0
  75453. #define Z_BINARY 0
  75454. #define Z_TEXT 1
  75455. #define Z_ASCII Z_TEXT /* for compatibility with 1.2.2 and earlier */
  75456. #define Z_UNKNOWN 2
  75457. #define Z_DEFLATED 8
  75458. #define Z_NULL 0 /* for initializing zalloc, zfree, opaque */
  75459. #define zlib_version zlibVersion()
  75460. //ZEXTERN const char * ZEXPORT zlibVersion OF((void));
  75461. ZEXTERN int ZEXPORT deflate OF((z_streamp strm, int flush));
  75462. ZEXTERN int ZEXPORT deflateEnd OF((z_streamp strm));
  75463. ZEXTERN int ZEXPORT inflate OF((z_streamp strm, int flush));
  75464. ZEXTERN int ZEXPORT inflateEnd OF((z_streamp strm));
  75465. ZEXTERN int ZEXPORT deflateSetDictionary OF((z_streamp strm,
  75466. const Bytef *dictionary,
  75467. uInt dictLength));
  75468. ZEXTERN int ZEXPORT deflateCopy OF((z_streamp dest,
  75469. z_streamp source));
  75470. ZEXTERN int ZEXPORT deflateReset OF((z_streamp strm));
  75471. ZEXTERN int ZEXPORT deflateParams OF((z_streamp strm,
  75472. int level,
  75473. int strategy));
  75474. ZEXTERN int ZEXPORT deflateTune OF((z_streamp strm,
  75475. int good_length,
  75476. int max_lazy,
  75477. int nice_length,
  75478. int max_chain));
  75479. ZEXTERN uLong ZEXPORT deflateBound OF((z_streamp strm,
  75480. uLong sourceLen));
  75481. ZEXTERN int ZEXPORT deflatePrime OF((z_streamp strm,
  75482. int bits,
  75483. int value));
  75484. ZEXTERN int ZEXPORT deflateSetHeader OF((z_streamp strm,
  75485. gz_headerp head));
  75486. ZEXTERN int ZEXPORT inflateSetDictionary OF((z_streamp strm,
  75487. const Bytef *dictionary,
  75488. uInt dictLength));
  75489. ZEXTERN int ZEXPORT inflateSync OF((z_streamp strm));
  75490. ZEXTERN int ZEXPORT inflateCopy OF((z_streamp dest,
  75491. z_streamp source));
  75492. ZEXTERN int ZEXPORT inflateReset OF((z_streamp strm));
  75493. ZEXTERN int ZEXPORT inflatePrime OF((z_streamp strm,
  75494. int bits,
  75495. int value));
  75496. ZEXTERN int ZEXPORT inflateGetHeader OF((z_streamp strm,
  75497. gz_headerp head));
  75498. typedef unsigned (*in_func) OF((void FAR *, unsigned char FAR * FAR *));
  75499. typedef int (*out_func) OF((void FAR *, unsigned char FAR *, unsigned));
  75500. ZEXTERN int ZEXPORT inflateBack OF((z_streamp strm,
  75501. in_func in, void FAR *in_desc,
  75502. out_func out, void FAR *out_desc));
  75503. ZEXTERN int ZEXPORT inflateBackEnd OF((z_streamp strm));
  75504. //ZEXTERN uLong ZEXPORT zlibCompileFlags OF((void));
  75505. ZEXTERN int ZEXPORT compress OF((Bytef *dest, uLongf *destLen,
  75506. const Bytef *source, uLong sourceLen));
  75507. ZEXTERN int ZEXPORT compress2 OF((Bytef *dest, uLongf *destLen,
  75508. const Bytef *source, uLong sourceLen,
  75509. int level));
  75510. ZEXTERN uLong ZEXPORT compressBound OF((uLong sourceLen));
  75511. ZEXTERN int ZEXPORT uncompress OF((Bytef *dest, uLongf *destLen,
  75512. const Bytef *source, uLong sourceLen));
  75513. typedef voidp gzFile;
  75514. ZEXTERN gzFile ZEXPORT gzopen OF((const char *path, const char *mode));
  75515. ZEXTERN gzFile ZEXPORT gzdopen OF((int fd, const char *mode));
  75516. ZEXTERN int ZEXPORT gzsetparams OF((gzFile file, int level, int strategy));
  75517. ZEXTERN int ZEXPORT gzread OF((gzFile file, voidp buf, unsigned len));
  75518. ZEXTERN int ZEXPORT gzwrite OF((gzFile file,
  75519. voidpc buf, unsigned len));
  75520. ZEXTERN int ZEXPORTVA gzprintf OF((gzFile file, const char *format, ...));
  75521. ZEXTERN int ZEXPORT gzputs OF((gzFile file, const char *s));
  75522. ZEXTERN char * ZEXPORT gzgets OF((gzFile file, char *buf, int len));
  75523. ZEXTERN int ZEXPORT gzputc OF((gzFile file, int c));
  75524. ZEXTERN int ZEXPORT gzgetc OF((gzFile file));
  75525. ZEXTERN int ZEXPORT gzungetc OF((int c, gzFile file));
  75526. ZEXTERN int ZEXPORT gzflush OF((gzFile file, int flush));
  75527. ZEXTERN z_off_t ZEXPORT gzseek OF((gzFile file,
  75528. z_off_t offset, int whence));
  75529. ZEXTERN int ZEXPORT gzrewind OF((gzFile file));
  75530. ZEXTERN z_off_t ZEXPORT gztell OF((gzFile file));
  75531. ZEXTERN int ZEXPORT gzeof OF((gzFile file));
  75532. ZEXTERN int ZEXPORT gzdirect OF((gzFile file));
  75533. ZEXTERN int ZEXPORT gzclose OF((gzFile file));
  75534. ZEXTERN const char * ZEXPORT gzerror OF((gzFile file, int *errnum));
  75535. ZEXTERN void ZEXPORT gzclearerr OF((gzFile file));
  75536. ZEXTERN uLong ZEXPORT adler32 OF((uLong adler, const Bytef *buf, uInt len));
  75537. ZEXTERN uLong ZEXPORT adler32_combine OF((uLong adler1, uLong adler2,
  75538. z_off_t len2));
  75539. ZEXTERN uLong ZEXPORT crc32 OF((uLong crc, const Bytef *buf, uInt len));
  75540. ZEXTERN uLong ZEXPORT crc32_combine OF((uLong crc1, uLong crc2, z_off_t len2));
  75541. ZEXTERN int ZEXPORT deflateInit_ OF((z_streamp strm, int level,
  75542. const char *version, int stream_size));
  75543. ZEXTERN int ZEXPORT inflateInit_ OF((z_streamp strm,
  75544. const char *version, int stream_size));
  75545. ZEXTERN int ZEXPORT deflateInit2_ OF((z_streamp strm, int level, int method,
  75546. int windowBits, int memLevel,
  75547. int strategy, const char *version,
  75548. int stream_size));
  75549. ZEXTERN int ZEXPORT inflateInit2_ OF((z_streamp strm, int windowBits,
  75550. const char *version, int stream_size));
  75551. ZEXTERN int ZEXPORT inflateBackInit_ OF((z_streamp strm, int windowBits,
  75552. unsigned char FAR *window,
  75553. const char *version,
  75554. int stream_size));
  75555. #define deflateInit(strm, level) \
  75556. deflateInit_((strm), (level), ZLIB_VERSION, sizeof(z_stream))
  75557. #define inflateInit(strm) \
  75558. inflateInit_((strm), ZLIB_VERSION, sizeof(z_stream))
  75559. #define deflateInit2(strm, level, method, windowBits, memLevel, strategy) \
  75560. deflateInit2_((strm),(level),(method),(windowBits),(memLevel),\
  75561. (strategy), ZLIB_VERSION, sizeof(z_stream))
  75562. #define inflateInit2(strm, windowBits) \
  75563. inflateInit2_((strm), (windowBits), ZLIB_VERSION, sizeof(z_stream))
  75564. #define inflateBackInit(strm, windowBits, window) \
  75565. inflateBackInit_((strm), (windowBits), (window), \
  75566. ZLIB_VERSION, sizeof(z_stream))
  75567. #if !defined(ZUTIL_H) && !defined(NO_DUMMY_DECL)
  75568. struct internal_state {int dummy;}; /* hack for buggy compilers */
  75569. #endif
  75570. ZEXTERN const char * ZEXPORT zError OF((int));
  75571. ZEXTERN int ZEXPORT inflateSyncPoint OF((z_streamp z));
  75572. ZEXTERN const uLongf * ZEXPORT get_crc_table OF((void));
  75573. #ifdef __cplusplus
  75574. }
  75575. #endif
  75576. #endif /* ZLIB_H */
  75577. /*** End of inlined file: zlib.h ***/
  75578. #undef OS_CODE
  75579. #else
  75580. #include <zlib.h>
  75581. #endif
  75582. }
  75583. BEGIN_JUCE_NAMESPACE
  75584. using namespace zlibNamespace;
  75585. // internal helper object that holds the zlib structures so they don't have to be
  75586. // included publicly.
  75587. class GZIPCompressorHelper
  75588. {
  75589. public:
  75590. GZIPCompressorHelper (const int compressionLevel, const bool nowrap)
  75591. : data (0),
  75592. dataSize (0),
  75593. compLevel (compressionLevel),
  75594. strategy (0),
  75595. setParams (true),
  75596. streamIsValid (false),
  75597. finished (false),
  75598. shouldFinish (false)
  75599. {
  75600. zerostruct (stream);
  75601. streamIsValid = (deflateInit2 (&stream, compLevel, Z_DEFLATED,
  75602. nowrap ? -MAX_WBITS : MAX_WBITS,
  75603. 8, strategy) == Z_OK);
  75604. }
  75605. ~GZIPCompressorHelper()
  75606. {
  75607. if (streamIsValid)
  75608. deflateEnd (&stream);
  75609. }
  75610. bool needsInput() const throw()
  75611. {
  75612. return dataSize <= 0;
  75613. }
  75614. void setInput (uint8* const newData, const int size) throw()
  75615. {
  75616. data = newData;
  75617. dataSize = size;
  75618. }
  75619. int doNextBlock (uint8* const dest, const int destSize) throw()
  75620. {
  75621. if (streamIsValid)
  75622. {
  75623. stream.next_in = data;
  75624. stream.next_out = dest;
  75625. stream.avail_in = dataSize;
  75626. stream.avail_out = destSize;
  75627. const int result = setParams ? deflateParams (&stream, compLevel, strategy)
  75628. : deflate (&stream, shouldFinish ? Z_FINISH : Z_NO_FLUSH);
  75629. setParams = false;
  75630. switch (result)
  75631. {
  75632. case Z_STREAM_END:
  75633. finished = true;
  75634. // Deliberate fall-through..
  75635. case Z_OK:
  75636. data += dataSize - stream.avail_in;
  75637. dataSize = stream.avail_in;
  75638. return destSize - stream.avail_out;
  75639. default:
  75640. break;
  75641. }
  75642. }
  75643. return 0;
  75644. }
  75645. private:
  75646. z_stream stream;
  75647. uint8* data;
  75648. int dataSize, compLevel, strategy;
  75649. bool setParams, streamIsValid;
  75650. public:
  75651. bool finished, shouldFinish;
  75652. };
  75653. const int gzipCompBufferSize = 32768;
  75654. GZIPCompressorOutputStream::GZIPCompressorOutputStream (OutputStream* const destStream_,
  75655. int compressionLevel,
  75656. const bool deleteDestStream,
  75657. const bool noWrap)
  75658. : destStream (destStream_),
  75659. streamToDelete (deleteDestStream ? destStream_ : 0),
  75660. buffer (gzipCompBufferSize)
  75661. {
  75662. if (compressionLevel < 1 || compressionLevel > 9)
  75663. compressionLevel = -1;
  75664. helper = new GZIPCompressorHelper (compressionLevel, noWrap);
  75665. }
  75666. GZIPCompressorOutputStream::~GZIPCompressorOutputStream()
  75667. {
  75668. flush();
  75669. }
  75670. void GZIPCompressorOutputStream::flush()
  75671. {
  75672. if (! helper->finished)
  75673. {
  75674. helper->shouldFinish = true;
  75675. while (! helper->finished)
  75676. doNextBlock();
  75677. }
  75678. destStream->flush();
  75679. }
  75680. bool GZIPCompressorOutputStream::write (const void* destBuffer, int howMany)
  75681. {
  75682. if (! helper->finished)
  75683. {
  75684. helper->setInput ((uint8*) destBuffer, howMany);
  75685. while (! helper->needsInput())
  75686. {
  75687. if (! doNextBlock())
  75688. return false;
  75689. }
  75690. }
  75691. return true;
  75692. }
  75693. bool GZIPCompressorOutputStream::doNextBlock()
  75694. {
  75695. const int len = helper->doNextBlock (buffer, gzipCompBufferSize);
  75696. if (len > 0)
  75697. return destStream->write (buffer, len);
  75698. else
  75699. return true;
  75700. }
  75701. int64 GZIPCompressorOutputStream::getPosition()
  75702. {
  75703. return destStream->getPosition();
  75704. }
  75705. bool GZIPCompressorOutputStream::setPosition (int64 /*newPosition*/)
  75706. {
  75707. jassertfalse // can't do it!
  75708. return false;
  75709. }
  75710. END_JUCE_NAMESPACE
  75711. /*** End of inlined file: juce_GZIPCompressorOutputStream.cpp ***/
  75712. /*** Start of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  75713. #if JUCE_MSVC
  75714. #pragma warning (push)
  75715. #pragma warning (disable: 4309 4305)
  75716. #endif
  75717. namespace zlibNamespace
  75718. {
  75719. #if JUCE_INCLUDE_ZLIB_CODE
  75720. extern "C"
  75721. {
  75722. #undef OS_CODE
  75723. #undef fdopen
  75724. #define ZLIB_INTERNAL
  75725. #define NO_DUMMY_DECL
  75726. /*** Start of inlined file: adler32.c ***/
  75727. #define ZLIB_INTERNAL
  75728. #define BASE 65521UL /* largest prime smaller than 65536 */
  75729. #define NMAX 5552
  75730. #define DO1(buf,i) {adler += (buf)[i]; sum2 += adler;}
  75731. #define DO2(buf,i) DO1(buf,i); DO1(buf,i+1);
  75732. #define DO4(buf,i) DO2(buf,i); DO2(buf,i+2);
  75733. #define DO8(buf,i) DO4(buf,i); DO4(buf,i+4);
  75734. #define DO16(buf) DO8(buf,0); DO8(buf,8);
  75735. #ifdef NO_DIVIDE
  75736. # define MOD(a) \
  75737. do { \
  75738. if (a >= (BASE << 16)) a -= (BASE << 16); \
  75739. if (a >= (BASE << 15)) a -= (BASE << 15); \
  75740. if (a >= (BASE << 14)) a -= (BASE << 14); \
  75741. if (a >= (BASE << 13)) a -= (BASE << 13); \
  75742. if (a >= (BASE << 12)) a -= (BASE << 12); \
  75743. if (a >= (BASE << 11)) a -= (BASE << 11); \
  75744. if (a >= (BASE << 10)) a -= (BASE << 10); \
  75745. if (a >= (BASE << 9)) a -= (BASE << 9); \
  75746. if (a >= (BASE << 8)) a -= (BASE << 8); \
  75747. if (a >= (BASE << 7)) a -= (BASE << 7); \
  75748. if (a >= (BASE << 6)) a -= (BASE << 6); \
  75749. if (a >= (BASE << 5)) a -= (BASE << 5); \
  75750. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75751. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75752. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75753. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75754. if (a >= BASE) a -= BASE; \
  75755. } while (0)
  75756. # define MOD4(a) \
  75757. do { \
  75758. if (a >= (BASE << 4)) a -= (BASE << 4); \
  75759. if (a >= (BASE << 3)) a -= (BASE << 3); \
  75760. if (a >= (BASE << 2)) a -= (BASE << 2); \
  75761. if (a >= (BASE << 1)) a -= (BASE << 1); \
  75762. if (a >= BASE) a -= BASE; \
  75763. } while (0)
  75764. #else
  75765. # define MOD(a) a %= BASE
  75766. # define MOD4(a) a %= BASE
  75767. #endif
  75768. uLong ZEXPORT adler32(uLong adler, const Bytef *buf, uInt len)
  75769. {
  75770. unsigned long sum2;
  75771. unsigned n;
  75772. sum2 = (adler >> 16) & 0xffff;
  75773. adler &= 0xffff;
  75774. if (len == 1) {
  75775. adler += buf[0];
  75776. if (adler >= BASE)
  75777. adler -= BASE;
  75778. sum2 += adler;
  75779. if (sum2 >= BASE)
  75780. sum2 -= BASE;
  75781. return adler | (sum2 << 16);
  75782. }
  75783. if (buf == Z_NULL)
  75784. return 1L;
  75785. if (len < 16) {
  75786. while (len--) {
  75787. adler += *buf++;
  75788. sum2 += adler;
  75789. }
  75790. if (adler >= BASE)
  75791. adler -= BASE;
  75792. MOD4(sum2); /* only added so many BASE's */
  75793. return adler | (sum2 << 16);
  75794. }
  75795. while (len >= NMAX) {
  75796. len -= NMAX;
  75797. n = NMAX / 16; /* NMAX is divisible by 16 */
  75798. do {
  75799. DO16(buf); /* 16 sums unrolled */
  75800. buf += 16;
  75801. } while (--n);
  75802. MOD(adler);
  75803. MOD(sum2);
  75804. }
  75805. if (len) { /* avoid modulos if none remaining */
  75806. while (len >= 16) {
  75807. len -= 16;
  75808. DO16(buf);
  75809. buf += 16;
  75810. }
  75811. while (len--) {
  75812. adler += *buf++;
  75813. sum2 += adler;
  75814. }
  75815. MOD(adler);
  75816. MOD(sum2);
  75817. }
  75818. return adler | (sum2 << 16);
  75819. }
  75820. uLong ZEXPORT adler32_combine(uLong adler1, uLong adler2, z_off_t len2)
  75821. {
  75822. unsigned long sum1;
  75823. unsigned long sum2;
  75824. unsigned rem;
  75825. rem = (unsigned)(len2 % BASE);
  75826. sum1 = adler1 & 0xffff;
  75827. sum2 = rem * sum1;
  75828. MOD(sum2);
  75829. sum1 += (adler2 & 0xffff) + BASE - 1;
  75830. sum2 += ((adler1 >> 16) & 0xffff) + ((adler2 >> 16) & 0xffff) + BASE - rem;
  75831. if (sum1 > BASE) sum1 -= BASE;
  75832. if (sum1 > BASE) sum1 -= BASE;
  75833. if (sum2 > (BASE << 1)) sum2 -= (BASE << 1);
  75834. if (sum2 > BASE) sum2 -= BASE;
  75835. return sum1 | (sum2 << 16);
  75836. }
  75837. /*** End of inlined file: adler32.c ***/
  75838. /*** Start of inlined file: compress.c ***/
  75839. #define ZLIB_INTERNAL
  75840. int ZEXPORT compress2 (Bytef *dest, uLongf *destLen, const Bytef *source,
  75841. uLong sourceLen, int level)
  75842. {
  75843. z_stream stream;
  75844. int err;
  75845. stream.next_in = (Bytef*)source;
  75846. stream.avail_in = (uInt)sourceLen;
  75847. #ifdef MAXSEG_64K
  75848. if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR;
  75849. #endif
  75850. stream.next_out = dest;
  75851. stream.avail_out = (uInt)*destLen;
  75852. if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR;
  75853. stream.zalloc = (alloc_func)0;
  75854. stream.zfree = (free_func)0;
  75855. stream.opaque = (voidpf)0;
  75856. err = deflateInit(&stream, level);
  75857. if (err != Z_OK) return err;
  75858. err = deflate(&stream, Z_FINISH);
  75859. if (err != Z_STREAM_END) {
  75860. deflateEnd(&stream);
  75861. return err == Z_OK ? Z_BUF_ERROR : err;
  75862. }
  75863. *destLen = stream.total_out;
  75864. err = deflateEnd(&stream);
  75865. return err;
  75866. }
  75867. int ZEXPORT compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen)
  75868. {
  75869. return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION);
  75870. }
  75871. uLong ZEXPORT compressBound (uLong sourceLen)
  75872. {
  75873. return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 11;
  75874. }
  75875. /*** End of inlined file: compress.c ***/
  75876. #undef DO1
  75877. #undef DO8
  75878. /*** Start of inlined file: crc32.c ***/
  75879. #ifdef MAKECRCH
  75880. # include <stdio.h>
  75881. # ifndef DYNAMIC_CRC_TABLE
  75882. # define DYNAMIC_CRC_TABLE
  75883. # endif /* !DYNAMIC_CRC_TABLE */
  75884. #endif /* MAKECRCH */
  75885. /*** Start of inlined file: zutil.h ***/
  75886. #ifndef ZUTIL_H
  75887. #define ZUTIL_H
  75888. #define ZLIB_INTERNAL
  75889. #ifdef STDC
  75890. # ifndef _WIN32_WCE
  75891. # include <stddef.h>
  75892. # endif
  75893. # include <string.h>
  75894. # include <stdlib.h>
  75895. #endif
  75896. #ifdef NO_ERRNO_H
  75897. # ifdef _WIN32_WCE
  75898. # define errno z_errno
  75899. # endif
  75900. extern int errno;
  75901. #else
  75902. # ifndef _WIN32_WCE
  75903. # include <errno.h>
  75904. # endif
  75905. #endif
  75906. #ifndef local
  75907. # define local static
  75908. #endif
  75909. typedef unsigned char uch;
  75910. typedef uch FAR uchf;
  75911. typedef unsigned short ush;
  75912. typedef ush FAR ushf;
  75913. typedef unsigned long ulg;
  75914. extern const char * const z_errmsg[10]; /* indexed by 2-zlib_error */
  75915. #define ERR_MSG(err) z_errmsg[Z_NEED_DICT-(err)]
  75916. #define ERR_RETURN(strm,err) \
  75917. return (strm->msg = (char*)ERR_MSG(err), (err))
  75918. #ifndef DEF_WBITS
  75919. # define DEF_WBITS MAX_WBITS
  75920. #endif
  75921. #if MAX_MEM_LEVEL >= 8
  75922. # define DEF_MEM_LEVEL 8
  75923. #else
  75924. # define DEF_MEM_LEVEL MAX_MEM_LEVEL
  75925. #endif
  75926. #define STORED_BLOCK 0
  75927. #define STATIC_TREES 1
  75928. #define DYN_TREES 2
  75929. #define MIN_MATCH 3
  75930. #define MAX_MATCH 258
  75931. #define PRESET_DICT 0x20 /* preset dictionary flag in zlib header */
  75932. #if defined(MSDOS) || (defined(WINDOWS) && !defined(WIN32))
  75933. # define OS_CODE 0x00
  75934. # if defined(__TURBOC__) || defined(__BORLANDC__)
  75935. # if(__STDC__ == 1) && (defined(__LARGE__) || defined(__COMPACT__))
  75936. void _Cdecl farfree( void *block );
  75937. void *_Cdecl farmalloc( unsigned long nbytes );
  75938. # else
  75939. # include <alloc.h>
  75940. # endif
  75941. # else /* MSC or DJGPP */
  75942. # include <malloc.h>
  75943. # endif
  75944. #endif
  75945. #ifdef AMIGA
  75946. # define OS_CODE 0x01
  75947. #endif
  75948. #if defined(VAXC) || defined(VMS)
  75949. # define OS_CODE 0x02
  75950. # define F_OPEN(name, mode) \
  75951. fopen((name), (mode), "mbc=60", "ctx=stm", "rfm=fix", "mrs=512")
  75952. #endif
  75953. #if defined(ATARI) || defined(atarist)
  75954. # define OS_CODE 0x05
  75955. #endif
  75956. #ifdef OS2
  75957. # define OS_CODE 0x06
  75958. # ifdef M_I86
  75959. #include <malloc.h>
  75960. # endif
  75961. #endif
  75962. #if defined(MACOS) || TARGET_OS_MAC
  75963. # define OS_CODE 0x07
  75964. # if defined(__MWERKS__) && __dest_os != __be_os && __dest_os != __win32_os
  75965. # include <unix.h> /* for fdopen */
  75966. # else
  75967. # ifndef fdopen
  75968. # define fdopen(fd,mode) NULL /* No fdopen() */
  75969. # endif
  75970. # endif
  75971. #endif
  75972. #ifdef TOPS20
  75973. # define OS_CODE 0x0a
  75974. #endif
  75975. #ifdef WIN32
  75976. # ifndef __CYGWIN__ /* Cygwin is Unix, not Win32 */
  75977. # define OS_CODE 0x0b
  75978. # endif
  75979. #endif
  75980. #ifdef __50SERIES /* Prime/PRIMOS */
  75981. # define OS_CODE 0x0f
  75982. #endif
  75983. #if defined(_BEOS_) || defined(RISCOS)
  75984. # define fdopen(fd,mode) NULL /* No fdopen() */
  75985. #endif
  75986. #if (defined(_MSC_VER) && (_MSC_VER > 600))
  75987. # if defined(_WIN32_WCE)
  75988. # define fdopen(fd,mode) NULL /* No fdopen() */
  75989. # ifndef _PTRDIFF_T_DEFINED
  75990. typedef int ptrdiff_t;
  75991. # define _PTRDIFF_T_DEFINED
  75992. # endif
  75993. # else
  75994. # define fdopen(fd,type) _fdopen(fd,type)
  75995. # endif
  75996. #endif
  75997. #ifndef OS_CODE
  75998. # define OS_CODE 0x03 /* assume Unix */
  75999. #endif
  76000. #ifndef F_OPEN
  76001. # define F_OPEN(name, mode) fopen((name), (mode))
  76002. #endif
  76003. #if defined(STDC99) || (defined(__TURBOC__) && __TURBOC__ >= 0x550)
  76004. # ifndef HAVE_VSNPRINTF
  76005. # define HAVE_VSNPRINTF
  76006. # endif
  76007. #endif
  76008. #if defined(__CYGWIN__)
  76009. # ifndef HAVE_VSNPRINTF
  76010. # define HAVE_VSNPRINTF
  76011. # endif
  76012. #endif
  76013. #ifndef HAVE_VSNPRINTF
  76014. # ifdef MSDOS
  76015. # define NO_vsnprintf
  76016. # endif
  76017. # ifdef __TURBOC__
  76018. # define NO_vsnprintf
  76019. # endif
  76020. # ifdef WIN32
  76021. # if !defined(vsnprintf) && !defined(NO_vsnprintf)
  76022. # define vsnprintf _vsnprintf
  76023. # endif
  76024. # endif
  76025. # ifdef __SASC
  76026. # define NO_vsnprintf
  76027. # endif
  76028. #endif
  76029. #ifdef VMS
  76030. # define NO_vsnprintf
  76031. #endif
  76032. #if defined(pyr)
  76033. # define NO_MEMCPY
  76034. #endif
  76035. #if defined(SMALL_MEDIUM) && !defined(_MSC_VER) && !defined(__SC__)
  76036. # define NO_MEMCPY
  76037. #endif
  76038. #if defined(STDC) && !defined(HAVE_MEMCPY) && !defined(NO_MEMCPY)
  76039. # define HAVE_MEMCPY
  76040. #endif
  76041. #ifdef HAVE_MEMCPY
  76042. # ifdef SMALL_MEDIUM /* MSDOS small or medium model */
  76043. # define zmemcpy _fmemcpy
  76044. # define zmemcmp _fmemcmp
  76045. # define zmemzero(dest, len) _fmemset(dest, 0, len)
  76046. # else
  76047. # define zmemcpy memcpy
  76048. # define zmemcmp memcmp
  76049. # define zmemzero(dest, len) memset(dest, 0, len)
  76050. # endif
  76051. #else
  76052. extern void zmemcpy OF((Bytef* dest, const Bytef* source, uInt len));
  76053. extern int zmemcmp OF((const Bytef* s1, const Bytef* s2, uInt len));
  76054. extern void zmemzero OF((Bytef* dest, uInt len));
  76055. #endif
  76056. #ifdef DEBUG
  76057. # include <stdio.h>
  76058. extern int z_verbose;
  76059. extern void z_error OF((const char *m));
  76060. # define Assert(cond,msg) {if(!(cond)) z_error(msg);}
  76061. # define Trace(x) {if (z_verbose>=0) fprintf x ;}
  76062. # define Tracev(x) {if (z_verbose>0) fprintf x ;}
  76063. # define Tracevv(x) {if (z_verbose>1) fprintf x ;}
  76064. # define Tracec(c,x) {if (z_verbose>0 && (c)) fprintf x ;}
  76065. # define Tracecv(c,x) {if (z_verbose>1 && (c)) fprintf x ;}
  76066. #else
  76067. # define Assert(cond,msg)
  76068. # define Trace(x)
  76069. # define Tracev(x)
  76070. # define Tracevv(x)
  76071. # define Tracec(c,x)
  76072. # define Tracecv(c,x)
  76073. #endif
  76074. voidpf zcalloc OF((voidpf opaque, unsigned items, unsigned size));
  76075. void zcfree OF((voidpf opaque, voidpf ptr));
  76076. #define ZALLOC(strm, items, size) \
  76077. (*((strm)->zalloc))((strm)->opaque, (items), (size))
  76078. #define ZFREE(strm, addr) (*((strm)->zfree))((strm)->opaque, (voidpf)(addr))
  76079. #define TRY_FREE(s, p) {if (p) ZFREE(s, p);}
  76080. #endif /* ZUTIL_H */
  76081. /*** End of inlined file: zutil.h ***/
  76082. /* for STDC and FAR definitions */
  76083. #define local static
  76084. #ifndef NOBYFOUR
  76085. # ifdef STDC /* need ANSI C limits.h to determine sizes */
  76086. # include <limits.h>
  76087. # define BYFOUR
  76088. # if (UINT_MAX == 0xffffffffUL)
  76089. typedef unsigned int u4;
  76090. # else
  76091. # if (ULONG_MAX == 0xffffffffUL)
  76092. typedef unsigned long u4;
  76093. # else
  76094. # if (USHRT_MAX == 0xffffffffUL)
  76095. typedef unsigned short u4;
  76096. # else
  76097. # undef BYFOUR /* can't find a four-byte integer type! */
  76098. # endif
  76099. # endif
  76100. # endif
  76101. # endif /* STDC */
  76102. #endif /* !NOBYFOUR */
  76103. #ifdef BYFOUR
  76104. # define REV(w) (((w)>>24)+(((w)>>8)&0xff00)+ \
  76105. (((w)&0xff00)<<8)+(((w)&0xff)<<24))
  76106. local unsigned long crc32_little OF((unsigned long,
  76107. const unsigned char FAR *, unsigned));
  76108. local unsigned long crc32_big OF((unsigned long,
  76109. const unsigned char FAR *, unsigned));
  76110. # define TBLS 8
  76111. #else
  76112. # define TBLS 1
  76113. #endif /* BYFOUR */
  76114. local unsigned long gf2_matrix_times OF((unsigned long *mat,
  76115. unsigned long vec));
  76116. local void gf2_matrix_square OF((unsigned long *square, unsigned long *mat));
  76117. #ifdef DYNAMIC_CRC_TABLE
  76118. local volatile int crc_table_empty = 1;
  76119. local unsigned long FAR crc_table[TBLS][256];
  76120. local void make_crc_table OF((void));
  76121. #ifdef MAKECRCH
  76122. local void write_table OF((FILE *, const unsigned long FAR *));
  76123. #endif /* MAKECRCH */
  76124. local void make_crc_table()
  76125. {
  76126. unsigned long c;
  76127. int n, k;
  76128. unsigned long poly; /* polynomial exclusive-or pattern */
  76129. static volatile int first = 1; /* flag to limit concurrent making */
  76130. static const unsigned char p[] = {0,1,2,4,5,7,8,10,11,12,16,22,23,26};
  76131. if (first) {
  76132. first = 0;
  76133. poly = 0UL;
  76134. for (n = 0; n < sizeof(p)/sizeof(unsigned char); n++)
  76135. poly |= 1UL << (31 - p[n]);
  76136. for (n = 0; n < 256; n++) {
  76137. c = (unsigned long)n;
  76138. for (k = 0; k < 8; k++)
  76139. c = c & 1 ? poly ^ (c >> 1) : c >> 1;
  76140. crc_table[0][n] = c;
  76141. }
  76142. #ifdef BYFOUR
  76143. for (n = 0; n < 256; n++) {
  76144. c = crc_table[0][n];
  76145. crc_table[4][n] = REV(c);
  76146. for (k = 1; k < 4; k++) {
  76147. c = crc_table[0][c & 0xff] ^ (c >> 8);
  76148. crc_table[k][n] = c;
  76149. crc_table[k + 4][n] = REV(c);
  76150. }
  76151. }
  76152. #endif /* BYFOUR */
  76153. crc_table_empty = 0;
  76154. }
  76155. else { /* not first */
  76156. while (crc_table_empty)
  76157. ;
  76158. }
  76159. #ifdef MAKECRCH
  76160. {
  76161. FILE *out;
  76162. out = fopen("crc32.h", "w");
  76163. if (out == NULL) return;
  76164. fprintf(out, "/* crc32.h -- tables for rapid CRC calculation\n");
  76165. fprintf(out, " * Generated automatically by crc32.c\n */\n\n");
  76166. fprintf(out, "local const unsigned long FAR ");
  76167. fprintf(out, "crc_table[TBLS][256] =\n{\n {\n");
  76168. write_table(out, crc_table[0]);
  76169. # ifdef BYFOUR
  76170. fprintf(out, "#ifdef BYFOUR\n");
  76171. for (k = 1; k < 8; k++) {
  76172. fprintf(out, " },\n {\n");
  76173. write_table(out, crc_table[k]);
  76174. }
  76175. fprintf(out, "#endif\n");
  76176. # endif /* BYFOUR */
  76177. fprintf(out, " }\n};\n");
  76178. fclose(out);
  76179. }
  76180. #endif /* MAKECRCH */
  76181. }
  76182. #ifdef MAKECRCH
  76183. local void write_table(out, table)
  76184. FILE *out;
  76185. const unsigned long FAR *table;
  76186. {
  76187. int n;
  76188. for (n = 0; n < 256; n++)
  76189. fprintf(out, "%s0x%08lxUL%s", n % 5 ? "" : " ", table[n],
  76190. n == 255 ? "\n" : (n % 5 == 4 ? ",\n" : ", "));
  76191. }
  76192. #endif /* MAKECRCH */
  76193. #else /* !DYNAMIC_CRC_TABLE */
  76194. /*** Start of inlined file: crc32.h ***/
  76195. local const unsigned long FAR crc_table[TBLS][256] =
  76196. {
  76197. {
  76198. 0x00000000UL, 0x77073096UL, 0xee0e612cUL, 0x990951baUL, 0x076dc419UL,
  76199. 0x706af48fUL, 0xe963a535UL, 0x9e6495a3UL, 0x0edb8832UL, 0x79dcb8a4UL,
  76200. 0xe0d5e91eUL, 0x97d2d988UL, 0x09b64c2bUL, 0x7eb17cbdUL, 0xe7b82d07UL,
  76201. 0x90bf1d91UL, 0x1db71064UL, 0x6ab020f2UL, 0xf3b97148UL, 0x84be41deUL,
  76202. 0x1adad47dUL, 0x6ddde4ebUL, 0xf4d4b551UL, 0x83d385c7UL, 0x136c9856UL,
  76203. 0x646ba8c0UL, 0xfd62f97aUL, 0x8a65c9ecUL, 0x14015c4fUL, 0x63066cd9UL,
  76204. 0xfa0f3d63UL, 0x8d080df5UL, 0x3b6e20c8UL, 0x4c69105eUL, 0xd56041e4UL,
  76205. 0xa2677172UL, 0x3c03e4d1UL, 0x4b04d447UL, 0xd20d85fdUL, 0xa50ab56bUL,
  76206. 0x35b5a8faUL, 0x42b2986cUL, 0xdbbbc9d6UL, 0xacbcf940UL, 0x32d86ce3UL,
  76207. 0x45df5c75UL, 0xdcd60dcfUL, 0xabd13d59UL, 0x26d930acUL, 0x51de003aUL,
  76208. 0xc8d75180UL, 0xbfd06116UL, 0x21b4f4b5UL, 0x56b3c423UL, 0xcfba9599UL,
  76209. 0xb8bda50fUL, 0x2802b89eUL, 0x5f058808UL, 0xc60cd9b2UL, 0xb10be924UL,
  76210. 0x2f6f7c87UL, 0x58684c11UL, 0xc1611dabUL, 0xb6662d3dUL, 0x76dc4190UL,
  76211. 0x01db7106UL, 0x98d220bcUL, 0xefd5102aUL, 0x71b18589UL, 0x06b6b51fUL,
  76212. 0x9fbfe4a5UL, 0xe8b8d433UL, 0x7807c9a2UL, 0x0f00f934UL, 0x9609a88eUL,
  76213. 0xe10e9818UL, 0x7f6a0dbbUL, 0x086d3d2dUL, 0x91646c97UL, 0xe6635c01UL,
  76214. 0x6b6b51f4UL, 0x1c6c6162UL, 0x856530d8UL, 0xf262004eUL, 0x6c0695edUL,
  76215. 0x1b01a57bUL, 0x8208f4c1UL, 0xf50fc457UL, 0x65b0d9c6UL, 0x12b7e950UL,
  76216. 0x8bbeb8eaUL, 0xfcb9887cUL, 0x62dd1ddfUL, 0x15da2d49UL, 0x8cd37cf3UL,
  76217. 0xfbd44c65UL, 0x4db26158UL, 0x3ab551ceUL, 0xa3bc0074UL, 0xd4bb30e2UL,
  76218. 0x4adfa541UL, 0x3dd895d7UL, 0xa4d1c46dUL, 0xd3d6f4fbUL, 0x4369e96aUL,
  76219. 0x346ed9fcUL, 0xad678846UL, 0xda60b8d0UL, 0x44042d73UL, 0x33031de5UL,
  76220. 0xaa0a4c5fUL, 0xdd0d7cc9UL, 0x5005713cUL, 0x270241aaUL, 0xbe0b1010UL,
  76221. 0xc90c2086UL, 0x5768b525UL, 0x206f85b3UL, 0xb966d409UL, 0xce61e49fUL,
  76222. 0x5edef90eUL, 0x29d9c998UL, 0xb0d09822UL, 0xc7d7a8b4UL, 0x59b33d17UL,
  76223. 0x2eb40d81UL, 0xb7bd5c3bUL, 0xc0ba6cadUL, 0xedb88320UL, 0x9abfb3b6UL,
  76224. 0x03b6e20cUL, 0x74b1d29aUL, 0xead54739UL, 0x9dd277afUL, 0x04db2615UL,
  76225. 0x73dc1683UL, 0xe3630b12UL, 0x94643b84UL, 0x0d6d6a3eUL, 0x7a6a5aa8UL,
  76226. 0xe40ecf0bUL, 0x9309ff9dUL, 0x0a00ae27UL, 0x7d079eb1UL, 0xf00f9344UL,
  76227. 0x8708a3d2UL, 0x1e01f268UL, 0x6906c2feUL, 0xf762575dUL, 0x806567cbUL,
  76228. 0x196c3671UL, 0x6e6b06e7UL, 0xfed41b76UL, 0x89d32be0UL, 0x10da7a5aUL,
  76229. 0x67dd4accUL, 0xf9b9df6fUL, 0x8ebeeff9UL, 0x17b7be43UL, 0x60b08ed5UL,
  76230. 0xd6d6a3e8UL, 0xa1d1937eUL, 0x38d8c2c4UL, 0x4fdff252UL, 0xd1bb67f1UL,
  76231. 0xa6bc5767UL, 0x3fb506ddUL, 0x48b2364bUL, 0xd80d2bdaUL, 0xaf0a1b4cUL,
  76232. 0x36034af6UL, 0x41047a60UL, 0xdf60efc3UL, 0xa867df55UL, 0x316e8eefUL,
  76233. 0x4669be79UL, 0xcb61b38cUL, 0xbc66831aUL, 0x256fd2a0UL, 0x5268e236UL,
  76234. 0xcc0c7795UL, 0xbb0b4703UL, 0x220216b9UL, 0x5505262fUL, 0xc5ba3bbeUL,
  76235. 0xb2bd0b28UL, 0x2bb45a92UL, 0x5cb36a04UL, 0xc2d7ffa7UL, 0xb5d0cf31UL,
  76236. 0x2cd99e8bUL, 0x5bdeae1dUL, 0x9b64c2b0UL, 0xec63f226UL, 0x756aa39cUL,
  76237. 0x026d930aUL, 0x9c0906a9UL, 0xeb0e363fUL, 0x72076785UL, 0x05005713UL,
  76238. 0x95bf4a82UL, 0xe2b87a14UL, 0x7bb12baeUL, 0x0cb61b38UL, 0x92d28e9bUL,
  76239. 0xe5d5be0dUL, 0x7cdcefb7UL, 0x0bdbdf21UL, 0x86d3d2d4UL, 0xf1d4e242UL,
  76240. 0x68ddb3f8UL, 0x1fda836eUL, 0x81be16cdUL, 0xf6b9265bUL, 0x6fb077e1UL,
  76241. 0x18b74777UL, 0x88085ae6UL, 0xff0f6a70UL, 0x66063bcaUL, 0x11010b5cUL,
  76242. 0x8f659effUL, 0xf862ae69UL, 0x616bffd3UL, 0x166ccf45UL, 0xa00ae278UL,
  76243. 0xd70dd2eeUL, 0x4e048354UL, 0x3903b3c2UL, 0xa7672661UL, 0xd06016f7UL,
  76244. 0x4969474dUL, 0x3e6e77dbUL, 0xaed16a4aUL, 0xd9d65adcUL, 0x40df0b66UL,
  76245. 0x37d83bf0UL, 0xa9bcae53UL, 0xdebb9ec5UL, 0x47b2cf7fUL, 0x30b5ffe9UL,
  76246. 0xbdbdf21cUL, 0xcabac28aUL, 0x53b39330UL, 0x24b4a3a6UL, 0xbad03605UL,
  76247. 0xcdd70693UL, 0x54de5729UL, 0x23d967bfUL, 0xb3667a2eUL, 0xc4614ab8UL,
  76248. 0x5d681b02UL, 0x2a6f2b94UL, 0xb40bbe37UL, 0xc30c8ea1UL, 0x5a05df1bUL,
  76249. 0x2d02ef8dUL
  76250. #ifdef BYFOUR
  76251. },
  76252. {
  76253. 0x00000000UL, 0x191b3141UL, 0x32366282UL, 0x2b2d53c3UL, 0x646cc504UL,
  76254. 0x7d77f445UL, 0x565aa786UL, 0x4f4196c7UL, 0xc8d98a08UL, 0xd1c2bb49UL,
  76255. 0xfaefe88aUL, 0xe3f4d9cbUL, 0xacb54f0cUL, 0xb5ae7e4dUL, 0x9e832d8eUL,
  76256. 0x87981ccfUL, 0x4ac21251UL, 0x53d92310UL, 0x78f470d3UL, 0x61ef4192UL,
  76257. 0x2eaed755UL, 0x37b5e614UL, 0x1c98b5d7UL, 0x05838496UL, 0x821b9859UL,
  76258. 0x9b00a918UL, 0xb02dfadbUL, 0xa936cb9aUL, 0xe6775d5dUL, 0xff6c6c1cUL,
  76259. 0xd4413fdfUL, 0xcd5a0e9eUL, 0x958424a2UL, 0x8c9f15e3UL, 0xa7b24620UL,
  76260. 0xbea97761UL, 0xf1e8e1a6UL, 0xe8f3d0e7UL, 0xc3de8324UL, 0xdac5b265UL,
  76261. 0x5d5daeaaUL, 0x44469febUL, 0x6f6bcc28UL, 0x7670fd69UL, 0x39316baeUL,
  76262. 0x202a5aefUL, 0x0b07092cUL, 0x121c386dUL, 0xdf4636f3UL, 0xc65d07b2UL,
  76263. 0xed705471UL, 0xf46b6530UL, 0xbb2af3f7UL, 0xa231c2b6UL, 0x891c9175UL,
  76264. 0x9007a034UL, 0x179fbcfbUL, 0x0e848dbaUL, 0x25a9de79UL, 0x3cb2ef38UL,
  76265. 0x73f379ffUL, 0x6ae848beUL, 0x41c51b7dUL, 0x58de2a3cUL, 0xf0794f05UL,
  76266. 0xe9627e44UL, 0xc24f2d87UL, 0xdb541cc6UL, 0x94158a01UL, 0x8d0ebb40UL,
  76267. 0xa623e883UL, 0xbf38d9c2UL, 0x38a0c50dUL, 0x21bbf44cUL, 0x0a96a78fUL,
  76268. 0x138d96ceUL, 0x5ccc0009UL, 0x45d73148UL, 0x6efa628bUL, 0x77e153caUL,
  76269. 0xbabb5d54UL, 0xa3a06c15UL, 0x888d3fd6UL, 0x91960e97UL, 0xded79850UL,
  76270. 0xc7cca911UL, 0xece1fad2UL, 0xf5facb93UL, 0x7262d75cUL, 0x6b79e61dUL,
  76271. 0x4054b5deUL, 0x594f849fUL, 0x160e1258UL, 0x0f152319UL, 0x243870daUL,
  76272. 0x3d23419bUL, 0x65fd6ba7UL, 0x7ce65ae6UL, 0x57cb0925UL, 0x4ed03864UL,
  76273. 0x0191aea3UL, 0x188a9fe2UL, 0x33a7cc21UL, 0x2abcfd60UL, 0xad24e1afUL,
  76274. 0xb43fd0eeUL, 0x9f12832dUL, 0x8609b26cUL, 0xc94824abUL, 0xd05315eaUL,
  76275. 0xfb7e4629UL, 0xe2657768UL, 0x2f3f79f6UL, 0x362448b7UL, 0x1d091b74UL,
  76276. 0x04122a35UL, 0x4b53bcf2UL, 0x52488db3UL, 0x7965de70UL, 0x607eef31UL,
  76277. 0xe7e6f3feUL, 0xfefdc2bfUL, 0xd5d0917cUL, 0xcccba03dUL, 0x838a36faUL,
  76278. 0x9a9107bbUL, 0xb1bc5478UL, 0xa8a76539UL, 0x3b83984bUL, 0x2298a90aUL,
  76279. 0x09b5fac9UL, 0x10aecb88UL, 0x5fef5d4fUL, 0x46f46c0eUL, 0x6dd93fcdUL,
  76280. 0x74c20e8cUL, 0xf35a1243UL, 0xea412302UL, 0xc16c70c1UL, 0xd8774180UL,
  76281. 0x9736d747UL, 0x8e2de606UL, 0xa500b5c5UL, 0xbc1b8484UL, 0x71418a1aUL,
  76282. 0x685abb5bUL, 0x4377e898UL, 0x5a6cd9d9UL, 0x152d4f1eUL, 0x0c367e5fUL,
  76283. 0x271b2d9cUL, 0x3e001cddUL, 0xb9980012UL, 0xa0833153UL, 0x8bae6290UL,
  76284. 0x92b553d1UL, 0xddf4c516UL, 0xc4eff457UL, 0xefc2a794UL, 0xf6d996d5UL,
  76285. 0xae07bce9UL, 0xb71c8da8UL, 0x9c31de6bUL, 0x852aef2aUL, 0xca6b79edUL,
  76286. 0xd37048acUL, 0xf85d1b6fUL, 0xe1462a2eUL, 0x66de36e1UL, 0x7fc507a0UL,
  76287. 0x54e85463UL, 0x4df36522UL, 0x02b2f3e5UL, 0x1ba9c2a4UL, 0x30849167UL,
  76288. 0x299fa026UL, 0xe4c5aeb8UL, 0xfdde9ff9UL, 0xd6f3cc3aUL, 0xcfe8fd7bUL,
  76289. 0x80a96bbcUL, 0x99b25afdUL, 0xb29f093eUL, 0xab84387fUL, 0x2c1c24b0UL,
  76290. 0x350715f1UL, 0x1e2a4632UL, 0x07317773UL, 0x4870e1b4UL, 0x516bd0f5UL,
  76291. 0x7a468336UL, 0x635db277UL, 0xcbfad74eUL, 0xd2e1e60fUL, 0xf9ccb5ccUL,
  76292. 0xe0d7848dUL, 0xaf96124aUL, 0xb68d230bUL, 0x9da070c8UL, 0x84bb4189UL,
  76293. 0x03235d46UL, 0x1a386c07UL, 0x31153fc4UL, 0x280e0e85UL, 0x674f9842UL,
  76294. 0x7e54a903UL, 0x5579fac0UL, 0x4c62cb81UL, 0x8138c51fUL, 0x9823f45eUL,
  76295. 0xb30ea79dUL, 0xaa1596dcUL, 0xe554001bUL, 0xfc4f315aUL, 0xd7626299UL,
  76296. 0xce7953d8UL, 0x49e14f17UL, 0x50fa7e56UL, 0x7bd72d95UL, 0x62cc1cd4UL,
  76297. 0x2d8d8a13UL, 0x3496bb52UL, 0x1fbbe891UL, 0x06a0d9d0UL, 0x5e7ef3ecUL,
  76298. 0x4765c2adUL, 0x6c48916eUL, 0x7553a02fUL, 0x3a1236e8UL, 0x230907a9UL,
  76299. 0x0824546aUL, 0x113f652bUL, 0x96a779e4UL, 0x8fbc48a5UL, 0xa4911b66UL,
  76300. 0xbd8a2a27UL, 0xf2cbbce0UL, 0xebd08da1UL, 0xc0fdde62UL, 0xd9e6ef23UL,
  76301. 0x14bce1bdUL, 0x0da7d0fcUL, 0x268a833fUL, 0x3f91b27eUL, 0x70d024b9UL,
  76302. 0x69cb15f8UL, 0x42e6463bUL, 0x5bfd777aUL, 0xdc656bb5UL, 0xc57e5af4UL,
  76303. 0xee530937UL, 0xf7483876UL, 0xb809aeb1UL, 0xa1129ff0UL, 0x8a3fcc33UL,
  76304. 0x9324fd72UL
  76305. },
  76306. {
  76307. 0x00000000UL, 0x01c26a37UL, 0x0384d46eUL, 0x0246be59UL, 0x0709a8dcUL,
  76308. 0x06cbc2ebUL, 0x048d7cb2UL, 0x054f1685UL, 0x0e1351b8UL, 0x0fd13b8fUL,
  76309. 0x0d9785d6UL, 0x0c55efe1UL, 0x091af964UL, 0x08d89353UL, 0x0a9e2d0aUL,
  76310. 0x0b5c473dUL, 0x1c26a370UL, 0x1de4c947UL, 0x1fa2771eUL, 0x1e601d29UL,
  76311. 0x1b2f0bacUL, 0x1aed619bUL, 0x18abdfc2UL, 0x1969b5f5UL, 0x1235f2c8UL,
  76312. 0x13f798ffUL, 0x11b126a6UL, 0x10734c91UL, 0x153c5a14UL, 0x14fe3023UL,
  76313. 0x16b88e7aUL, 0x177ae44dUL, 0x384d46e0UL, 0x398f2cd7UL, 0x3bc9928eUL,
  76314. 0x3a0bf8b9UL, 0x3f44ee3cUL, 0x3e86840bUL, 0x3cc03a52UL, 0x3d025065UL,
  76315. 0x365e1758UL, 0x379c7d6fUL, 0x35dac336UL, 0x3418a901UL, 0x3157bf84UL,
  76316. 0x3095d5b3UL, 0x32d36beaUL, 0x331101ddUL, 0x246be590UL, 0x25a98fa7UL,
  76317. 0x27ef31feUL, 0x262d5bc9UL, 0x23624d4cUL, 0x22a0277bUL, 0x20e69922UL,
  76318. 0x2124f315UL, 0x2a78b428UL, 0x2bbade1fUL, 0x29fc6046UL, 0x283e0a71UL,
  76319. 0x2d711cf4UL, 0x2cb376c3UL, 0x2ef5c89aUL, 0x2f37a2adUL, 0x709a8dc0UL,
  76320. 0x7158e7f7UL, 0x731e59aeUL, 0x72dc3399UL, 0x7793251cUL, 0x76514f2bUL,
  76321. 0x7417f172UL, 0x75d59b45UL, 0x7e89dc78UL, 0x7f4bb64fUL, 0x7d0d0816UL,
  76322. 0x7ccf6221UL, 0x798074a4UL, 0x78421e93UL, 0x7a04a0caUL, 0x7bc6cafdUL,
  76323. 0x6cbc2eb0UL, 0x6d7e4487UL, 0x6f38fadeUL, 0x6efa90e9UL, 0x6bb5866cUL,
  76324. 0x6a77ec5bUL, 0x68315202UL, 0x69f33835UL, 0x62af7f08UL, 0x636d153fUL,
  76325. 0x612bab66UL, 0x60e9c151UL, 0x65a6d7d4UL, 0x6464bde3UL, 0x662203baUL,
  76326. 0x67e0698dUL, 0x48d7cb20UL, 0x4915a117UL, 0x4b531f4eUL, 0x4a917579UL,
  76327. 0x4fde63fcUL, 0x4e1c09cbUL, 0x4c5ab792UL, 0x4d98dda5UL, 0x46c49a98UL,
  76328. 0x4706f0afUL, 0x45404ef6UL, 0x448224c1UL, 0x41cd3244UL, 0x400f5873UL,
  76329. 0x4249e62aUL, 0x438b8c1dUL, 0x54f16850UL, 0x55330267UL, 0x5775bc3eUL,
  76330. 0x56b7d609UL, 0x53f8c08cUL, 0x523aaabbUL, 0x507c14e2UL, 0x51be7ed5UL,
  76331. 0x5ae239e8UL, 0x5b2053dfUL, 0x5966ed86UL, 0x58a487b1UL, 0x5deb9134UL,
  76332. 0x5c29fb03UL, 0x5e6f455aUL, 0x5fad2f6dUL, 0xe1351b80UL, 0xe0f771b7UL,
  76333. 0xe2b1cfeeUL, 0xe373a5d9UL, 0xe63cb35cUL, 0xe7fed96bUL, 0xe5b86732UL,
  76334. 0xe47a0d05UL, 0xef264a38UL, 0xeee4200fUL, 0xeca29e56UL, 0xed60f461UL,
  76335. 0xe82fe2e4UL, 0xe9ed88d3UL, 0xebab368aUL, 0xea695cbdUL, 0xfd13b8f0UL,
  76336. 0xfcd1d2c7UL, 0xfe976c9eUL, 0xff5506a9UL, 0xfa1a102cUL, 0xfbd87a1bUL,
  76337. 0xf99ec442UL, 0xf85cae75UL, 0xf300e948UL, 0xf2c2837fUL, 0xf0843d26UL,
  76338. 0xf1465711UL, 0xf4094194UL, 0xf5cb2ba3UL, 0xf78d95faUL, 0xf64fffcdUL,
  76339. 0xd9785d60UL, 0xd8ba3757UL, 0xdafc890eUL, 0xdb3ee339UL, 0xde71f5bcUL,
  76340. 0xdfb39f8bUL, 0xddf521d2UL, 0xdc374be5UL, 0xd76b0cd8UL, 0xd6a966efUL,
  76341. 0xd4efd8b6UL, 0xd52db281UL, 0xd062a404UL, 0xd1a0ce33UL, 0xd3e6706aUL,
  76342. 0xd2241a5dUL, 0xc55efe10UL, 0xc49c9427UL, 0xc6da2a7eUL, 0xc7184049UL,
  76343. 0xc25756ccUL, 0xc3953cfbUL, 0xc1d382a2UL, 0xc011e895UL, 0xcb4dafa8UL,
  76344. 0xca8fc59fUL, 0xc8c97bc6UL, 0xc90b11f1UL, 0xcc440774UL, 0xcd866d43UL,
  76345. 0xcfc0d31aUL, 0xce02b92dUL, 0x91af9640UL, 0x906dfc77UL, 0x922b422eUL,
  76346. 0x93e92819UL, 0x96a63e9cUL, 0x976454abUL, 0x9522eaf2UL, 0x94e080c5UL,
  76347. 0x9fbcc7f8UL, 0x9e7eadcfUL, 0x9c381396UL, 0x9dfa79a1UL, 0x98b56f24UL,
  76348. 0x99770513UL, 0x9b31bb4aUL, 0x9af3d17dUL, 0x8d893530UL, 0x8c4b5f07UL,
  76349. 0x8e0de15eUL, 0x8fcf8b69UL, 0x8a809decUL, 0x8b42f7dbUL, 0x89044982UL,
  76350. 0x88c623b5UL, 0x839a6488UL, 0x82580ebfUL, 0x801eb0e6UL, 0x81dcdad1UL,
  76351. 0x8493cc54UL, 0x8551a663UL, 0x8717183aUL, 0x86d5720dUL, 0xa9e2d0a0UL,
  76352. 0xa820ba97UL, 0xaa6604ceUL, 0xaba46ef9UL, 0xaeeb787cUL, 0xaf29124bUL,
  76353. 0xad6fac12UL, 0xacadc625UL, 0xa7f18118UL, 0xa633eb2fUL, 0xa4755576UL,
  76354. 0xa5b73f41UL, 0xa0f829c4UL, 0xa13a43f3UL, 0xa37cfdaaUL, 0xa2be979dUL,
  76355. 0xb5c473d0UL, 0xb40619e7UL, 0xb640a7beUL, 0xb782cd89UL, 0xb2cddb0cUL,
  76356. 0xb30fb13bUL, 0xb1490f62UL, 0xb08b6555UL, 0xbbd72268UL, 0xba15485fUL,
  76357. 0xb853f606UL, 0xb9919c31UL, 0xbcde8ab4UL, 0xbd1ce083UL, 0xbf5a5edaUL,
  76358. 0xbe9834edUL
  76359. },
  76360. {
  76361. 0x00000000UL, 0xb8bc6765UL, 0xaa09c88bUL, 0x12b5afeeUL, 0x8f629757UL,
  76362. 0x37def032UL, 0x256b5fdcUL, 0x9dd738b9UL, 0xc5b428efUL, 0x7d084f8aUL,
  76363. 0x6fbde064UL, 0xd7018701UL, 0x4ad6bfb8UL, 0xf26ad8ddUL, 0xe0df7733UL,
  76364. 0x58631056UL, 0x5019579fUL, 0xe8a530faUL, 0xfa109f14UL, 0x42acf871UL,
  76365. 0xdf7bc0c8UL, 0x67c7a7adUL, 0x75720843UL, 0xcdce6f26UL, 0x95ad7f70UL,
  76366. 0x2d111815UL, 0x3fa4b7fbUL, 0x8718d09eUL, 0x1acfe827UL, 0xa2738f42UL,
  76367. 0xb0c620acUL, 0x087a47c9UL, 0xa032af3eUL, 0x188ec85bUL, 0x0a3b67b5UL,
  76368. 0xb28700d0UL, 0x2f503869UL, 0x97ec5f0cUL, 0x8559f0e2UL, 0x3de59787UL,
  76369. 0x658687d1UL, 0xdd3ae0b4UL, 0xcf8f4f5aUL, 0x7733283fUL, 0xeae41086UL,
  76370. 0x525877e3UL, 0x40edd80dUL, 0xf851bf68UL, 0xf02bf8a1UL, 0x48979fc4UL,
  76371. 0x5a22302aUL, 0xe29e574fUL, 0x7f496ff6UL, 0xc7f50893UL, 0xd540a77dUL,
  76372. 0x6dfcc018UL, 0x359fd04eUL, 0x8d23b72bUL, 0x9f9618c5UL, 0x272a7fa0UL,
  76373. 0xbafd4719UL, 0x0241207cUL, 0x10f48f92UL, 0xa848e8f7UL, 0x9b14583dUL,
  76374. 0x23a83f58UL, 0x311d90b6UL, 0x89a1f7d3UL, 0x1476cf6aUL, 0xaccaa80fUL,
  76375. 0xbe7f07e1UL, 0x06c36084UL, 0x5ea070d2UL, 0xe61c17b7UL, 0xf4a9b859UL,
  76376. 0x4c15df3cUL, 0xd1c2e785UL, 0x697e80e0UL, 0x7bcb2f0eUL, 0xc377486bUL,
  76377. 0xcb0d0fa2UL, 0x73b168c7UL, 0x6104c729UL, 0xd9b8a04cUL, 0x446f98f5UL,
  76378. 0xfcd3ff90UL, 0xee66507eUL, 0x56da371bUL, 0x0eb9274dUL, 0xb6054028UL,
  76379. 0xa4b0efc6UL, 0x1c0c88a3UL, 0x81dbb01aUL, 0x3967d77fUL, 0x2bd27891UL,
  76380. 0x936e1ff4UL, 0x3b26f703UL, 0x839a9066UL, 0x912f3f88UL, 0x299358edUL,
  76381. 0xb4446054UL, 0x0cf80731UL, 0x1e4da8dfUL, 0xa6f1cfbaUL, 0xfe92dfecUL,
  76382. 0x462eb889UL, 0x549b1767UL, 0xec277002UL, 0x71f048bbUL, 0xc94c2fdeUL,
  76383. 0xdbf98030UL, 0x6345e755UL, 0x6b3fa09cUL, 0xd383c7f9UL, 0xc1366817UL,
  76384. 0x798a0f72UL, 0xe45d37cbUL, 0x5ce150aeUL, 0x4e54ff40UL, 0xf6e89825UL,
  76385. 0xae8b8873UL, 0x1637ef16UL, 0x048240f8UL, 0xbc3e279dUL, 0x21e91f24UL,
  76386. 0x99557841UL, 0x8be0d7afUL, 0x335cb0caUL, 0xed59b63bUL, 0x55e5d15eUL,
  76387. 0x47507eb0UL, 0xffec19d5UL, 0x623b216cUL, 0xda874609UL, 0xc832e9e7UL,
  76388. 0x708e8e82UL, 0x28ed9ed4UL, 0x9051f9b1UL, 0x82e4565fUL, 0x3a58313aUL,
  76389. 0xa78f0983UL, 0x1f336ee6UL, 0x0d86c108UL, 0xb53aa66dUL, 0xbd40e1a4UL,
  76390. 0x05fc86c1UL, 0x1749292fUL, 0xaff54e4aUL, 0x322276f3UL, 0x8a9e1196UL,
  76391. 0x982bbe78UL, 0x2097d91dUL, 0x78f4c94bUL, 0xc048ae2eUL, 0xd2fd01c0UL,
  76392. 0x6a4166a5UL, 0xf7965e1cUL, 0x4f2a3979UL, 0x5d9f9697UL, 0xe523f1f2UL,
  76393. 0x4d6b1905UL, 0xf5d77e60UL, 0xe762d18eUL, 0x5fdeb6ebUL, 0xc2098e52UL,
  76394. 0x7ab5e937UL, 0x680046d9UL, 0xd0bc21bcUL, 0x88df31eaUL, 0x3063568fUL,
  76395. 0x22d6f961UL, 0x9a6a9e04UL, 0x07bda6bdUL, 0xbf01c1d8UL, 0xadb46e36UL,
  76396. 0x15080953UL, 0x1d724e9aUL, 0xa5ce29ffUL, 0xb77b8611UL, 0x0fc7e174UL,
  76397. 0x9210d9cdUL, 0x2aacbea8UL, 0x38191146UL, 0x80a57623UL, 0xd8c66675UL,
  76398. 0x607a0110UL, 0x72cfaefeUL, 0xca73c99bUL, 0x57a4f122UL, 0xef189647UL,
  76399. 0xfdad39a9UL, 0x45115eccUL, 0x764dee06UL, 0xcef18963UL, 0xdc44268dUL,
  76400. 0x64f841e8UL, 0xf92f7951UL, 0x41931e34UL, 0x5326b1daUL, 0xeb9ad6bfUL,
  76401. 0xb3f9c6e9UL, 0x0b45a18cUL, 0x19f00e62UL, 0xa14c6907UL, 0x3c9b51beUL,
  76402. 0x842736dbUL, 0x96929935UL, 0x2e2efe50UL, 0x2654b999UL, 0x9ee8defcUL,
  76403. 0x8c5d7112UL, 0x34e11677UL, 0xa9362eceUL, 0x118a49abUL, 0x033fe645UL,
  76404. 0xbb838120UL, 0xe3e09176UL, 0x5b5cf613UL, 0x49e959fdUL, 0xf1553e98UL,
  76405. 0x6c820621UL, 0xd43e6144UL, 0xc68bceaaUL, 0x7e37a9cfUL, 0xd67f4138UL,
  76406. 0x6ec3265dUL, 0x7c7689b3UL, 0xc4caeed6UL, 0x591dd66fUL, 0xe1a1b10aUL,
  76407. 0xf3141ee4UL, 0x4ba87981UL, 0x13cb69d7UL, 0xab770eb2UL, 0xb9c2a15cUL,
  76408. 0x017ec639UL, 0x9ca9fe80UL, 0x241599e5UL, 0x36a0360bUL, 0x8e1c516eUL,
  76409. 0x866616a7UL, 0x3eda71c2UL, 0x2c6fde2cUL, 0x94d3b949UL, 0x090481f0UL,
  76410. 0xb1b8e695UL, 0xa30d497bUL, 0x1bb12e1eUL, 0x43d23e48UL, 0xfb6e592dUL,
  76411. 0xe9dbf6c3UL, 0x516791a6UL, 0xccb0a91fUL, 0x740cce7aUL, 0x66b96194UL,
  76412. 0xde0506f1UL
  76413. },
  76414. {
  76415. 0x00000000UL, 0x96300777UL, 0x2c610eeeUL, 0xba510999UL, 0x19c46d07UL,
  76416. 0x8ff46a70UL, 0x35a563e9UL, 0xa395649eUL, 0x3288db0eUL, 0xa4b8dc79UL,
  76417. 0x1ee9d5e0UL, 0x88d9d297UL, 0x2b4cb609UL, 0xbd7cb17eUL, 0x072db8e7UL,
  76418. 0x911dbf90UL, 0x6410b71dUL, 0xf220b06aUL, 0x4871b9f3UL, 0xde41be84UL,
  76419. 0x7dd4da1aUL, 0xebe4dd6dUL, 0x51b5d4f4UL, 0xc785d383UL, 0x56986c13UL,
  76420. 0xc0a86b64UL, 0x7af962fdUL, 0xecc9658aUL, 0x4f5c0114UL, 0xd96c0663UL,
  76421. 0x633d0ffaUL, 0xf50d088dUL, 0xc8206e3bUL, 0x5e10694cUL, 0xe44160d5UL,
  76422. 0x727167a2UL, 0xd1e4033cUL, 0x47d4044bUL, 0xfd850dd2UL, 0x6bb50aa5UL,
  76423. 0xfaa8b535UL, 0x6c98b242UL, 0xd6c9bbdbUL, 0x40f9bcacUL, 0xe36cd832UL,
  76424. 0x755cdf45UL, 0xcf0dd6dcUL, 0x593dd1abUL, 0xac30d926UL, 0x3a00de51UL,
  76425. 0x8051d7c8UL, 0x1661d0bfUL, 0xb5f4b421UL, 0x23c4b356UL, 0x9995bacfUL,
  76426. 0x0fa5bdb8UL, 0x9eb80228UL, 0x0888055fUL, 0xb2d90cc6UL, 0x24e90bb1UL,
  76427. 0x877c6f2fUL, 0x114c6858UL, 0xab1d61c1UL, 0x3d2d66b6UL, 0x9041dc76UL,
  76428. 0x0671db01UL, 0xbc20d298UL, 0x2a10d5efUL, 0x8985b171UL, 0x1fb5b606UL,
  76429. 0xa5e4bf9fUL, 0x33d4b8e8UL, 0xa2c90778UL, 0x34f9000fUL, 0x8ea80996UL,
  76430. 0x18980ee1UL, 0xbb0d6a7fUL, 0x2d3d6d08UL, 0x976c6491UL, 0x015c63e6UL,
  76431. 0xf4516b6bUL, 0x62616c1cUL, 0xd8306585UL, 0x4e0062f2UL, 0xed95066cUL,
  76432. 0x7ba5011bUL, 0xc1f40882UL, 0x57c40ff5UL, 0xc6d9b065UL, 0x50e9b712UL,
  76433. 0xeab8be8bUL, 0x7c88b9fcUL, 0xdf1ddd62UL, 0x492dda15UL, 0xf37cd38cUL,
  76434. 0x654cd4fbUL, 0x5861b24dUL, 0xce51b53aUL, 0x7400bca3UL, 0xe230bbd4UL,
  76435. 0x41a5df4aUL, 0xd795d83dUL, 0x6dc4d1a4UL, 0xfbf4d6d3UL, 0x6ae96943UL,
  76436. 0xfcd96e34UL, 0x468867adUL, 0xd0b860daUL, 0x732d0444UL, 0xe51d0333UL,
  76437. 0x5f4c0aaaUL, 0xc97c0dddUL, 0x3c710550UL, 0xaa410227UL, 0x10100bbeUL,
  76438. 0x86200cc9UL, 0x25b56857UL, 0xb3856f20UL, 0x09d466b9UL, 0x9fe461ceUL,
  76439. 0x0ef9de5eUL, 0x98c9d929UL, 0x2298d0b0UL, 0xb4a8d7c7UL, 0x173db359UL,
  76440. 0x810db42eUL, 0x3b5cbdb7UL, 0xad6cbac0UL, 0x2083b8edUL, 0xb6b3bf9aUL,
  76441. 0x0ce2b603UL, 0x9ad2b174UL, 0x3947d5eaUL, 0xaf77d29dUL, 0x1526db04UL,
  76442. 0x8316dc73UL, 0x120b63e3UL, 0x843b6494UL, 0x3e6a6d0dUL, 0xa85a6a7aUL,
  76443. 0x0bcf0ee4UL, 0x9dff0993UL, 0x27ae000aUL, 0xb19e077dUL, 0x44930ff0UL,
  76444. 0xd2a30887UL, 0x68f2011eUL, 0xfec20669UL, 0x5d5762f7UL, 0xcb676580UL,
  76445. 0x71366c19UL, 0xe7066b6eUL, 0x761bd4feUL, 0xe02bd389UL, 0x5a7ada10UL,
  76446. 0xcc4add67UL, 0x6fdfb9f9UL, 0xf9efbe8eUL, 0x43beb717UL, 0xd58eb060UL,
  76447. 0xe8a3d6d6UL, 0x7e93d1a1UL, 0xc4c2d838UL, 0x52f2df4fUL, 0xf167bbd1UL,
  76448. 0x6757bca6UL, 0xdd06b53fUL, 0x4b36b248UL, 0xda2b0dd8UL, 0x4c1b0aafUL,
  76449. 0xf64a0336UL, 0x607a0441UL, 0xc3ef60dfUL, 0x55df67a8UL, 0xef8e6e31UL,
  76450. 0x79be6946UL, 0x8cb361cbUL, 0x1a8366bcUL, 0xa0d26f25UL, 0x36e26852UL,
  76451. 0x95770cccUL, 0x03470bbbUL, 0xb9160222UL, 0x2f260555UL, 0xbe3bbac5UL,
  76452. 0x280bbdb2UL, 0x925ab42bUL, 0x046ab35cUL, 0xa7ffd7c2UL, 0x31cfd0b5UL,
  76453. 0x8b9ed92cUL, 0x1daede5bUL, 0xb0c2649bUL, 0x26f263ecUL, 0x9ca36a75UL,
  76454. 0x0a936d02UL, 0xa906099cUL, 0x3f360eebUL, 0x85670772UL, 0x13570005UL,
  76455. 0x824abf95UL, 0x147ab8e2UL, 0xae2bb17bUL, 0x381bb60cUL, 0x9b8ed292UL,
  76456. 0x0dbed5e5UL, 0xb7efdc7cUL, 0x21dfdb0bUL, 0xd4d2d386UL, 0x42e2d4f1UL,
  76457. 0xf8b3dd68UL, 0x6e83da1fUL, 0xcd16be81UL, 0x5b26b9f6UL, 0xe177b06fUL,
  76458. 0x7747b718UL, 0xe65a0888UL, 0x706a0fffUL, 0xca3b0666UL, 0x5c0b0111UL,
  76459. 0xff9e658fUL, 0x69ae62f8UL, 0xd3ff6b61UL, 0x45cf6c16UL, 0x78e20aa0UL,
  76460. 0xeed20dd7UL, 0x5483044eUL, 0xc2b30339UL, 0x612667a7UL, 0xf71660d0UL,
  76461. 0x4d476949UL, 0xdb776e3eUL, 0x4a6ad1aeUL, 0xdc5ad6d9UL, 0x660bdf40UL,
  76462. 0xf03bd837UL, 0x53aebca9UL, 0xc59ebbdeUL, 0x7fcfb247UL, 0xe9ffb530UL,
  76463. 0x1cf2bdbdUL, 0x8ac2bacaUL, 0x3093b353UL, 0xa6a3b424UL, 0x0536d0baUL,
  76464. 0x9306d7cdUL, 0x2957de54UL, 0xbf67d923UL, 0x2e7a66b3UL, 0xb84a61c4UL,
  76465. 0x021b685dUL, 0x942b6f2aUL, 0x37be0bb4UL, 0xa18e0cc3UL, 0x1bdf055aUL,
  76466. 0x8def022dUL
  76467. },
  76468. {
  76469. 0x00000000UL, 0x41311b19UL, 0x82623632UL, 0xc3532d2bUL, 0x04c56c64UL,
  76470. 0x45f4777dUL, 0x86a75a56UL, 0xc796414fUL, 0x088ad9c8UL, 0x49bbc2d1UL,
  76471. 0x8ae8effaUL, 0xcbd9f4e3UL, 0x0c4fb5acUL, 0x4d7eaeb5UL, 0x8e2d839eUL,
  76472. 0xcf1c9887UL, 0x5112c24aUL, 0x1023d953UL, 0xd370f478UL, 0x9241ef61UL,
  76473. 0x55d7ae2eUL, 0x14e6b537UL, 0xd7b5981cUL, 0x96848305UL, 0x59981b82UL,
  76474. 0x18a9009bUL, 0xdbfa2db0UL, 0x9acb36a9UL, 0x5d5d77e6UL, 0x1c6c6cffUL,
  76475. 0xdf3f41d4UL, 0x9e0e5acdUL, 0xa2248495UL, 0xe3159f8cUL, 0x2046b2a7UL,
  76476. 0x6177a9beUL, 0xa6e1e8f1UL, 0xe7d0f3e8UL, 0x2483dec3UL, 0x65b2c5daUL,
  76477. 0xaaae5d5dUL, 0xeb9f4644UL, 0x28cc6b6fUL, 0x69fd7076UL, 0xae6b3139UL,
  76478. 0xef5a2a20UL, 0x2c09070bUL, 0x6d381c12UL, 0xf33646dfUL, 0xb2075dc6UL,
  76479. 0x715470edUL, 0x30656bf4UL, 0xf7f32abbUL, 0xb6c231a2UL, 0x75911c89UL,
  76480. 0x34a00790UL, 0xfbbc9f17UL, 0xba8d840eUL, 0x79dea925UL, 0x38efb23cUL,
  76481. 0xff79f373UL, 0xbe48e86aUL, 0x7d1bc541UL, 0x3c2ade58UL, 0x054f79f0UL,
  76482. 0x447e62e9UL, 0x872d4fc2UL, 0xc61c54dbUL, 0x018a1594UL, 0x40bb0e8dUL,
  76483. 0x83e823a6UL, 0xc2d938bfUL, 0x0dc5a038UL, 0x4cf4bb21UL, 0x8fa7960aUL,
  76484. 0xce968d13UL, 0x0900cc5cUL, 0x4831d745UL, 0x8b62fa6eUL, 0xca53e177UL,
  76485. 0x545dbbbaUL, 0x156ca0a3UL, 0xd63f8d88UL, 0x970e9691UL, 0x5098d7deUL,
  76486. 0x11a9ccc7UL, 0xd2fae1ecUL, 0x93cbfaf5UL, 0x5cd76272UL, 0x1de6796bUL,
  76487. 0xdeb55440UL, 0x9f844f59UL, 0x58120e16UL, 0x1923150fUL, 0xda703824UL,
  76488. 0x9b41233dUL, 0xa76bfd65UL, 0xe65ae67cUL, 0x2509cb57UL, 0x6438d04eUL,
  76489. 0xa3ae9101UL, 0xe29f8a18UL, 0x21cca733UL, 0x60fdbc2aUL, 0xafe124adUL,
  76490. 0xeed03fb4UL, 0x2d83129fUL, 0x6cb20986UL, 0xab2448c9UL, 0xea1553d0UL,
  76491. 0x29467efbUL, 0x687765e2UL, 0xf6793f2fUL, 0xb7482436UL, 0x741b091dUL,
  76492. 0x352a1204UL, 0xf2bc534bUL, 0xb38d4852UL, 0x70de6579UL, 0x31ef7e60UL,
  76493. 0xfef3e6e7UL, 0xbfc2fdfeUL, 0x7c91d0d5UL, 0x3da0cbccUL, 0xfa368a83UL,
  76494. 0xbb07919aUL, 0x7854bcb1UL, 0x3965a7a8UL, 0x4b98833bUL, 0x0aa99822UL,
  76495. 0xc9fab509UL, 0x88cbae10UL, 0x4f5def5fUL, 0x0e6cf446UL, 0xcd3fd96dUL,
  76496. 0x8c0ec274UL, 0x43125af3UL, 0x022341eaUL, 0xc1706cc1UL, 0x804177d8UL,
  76497. 0x47d73697UL, 0x06e62d8eUL, 0xc5b500a5UL, 0x84841bbcUL, 0x1a8a4171UL,
  76498. 0x5bbb5a68UL, 0x98e87743UL, 0xd9d96c5aUL, 0x1e4f2d15UL, 0x5f7e360cUL,
  76499. 0x9c2d1b27UL, 0xdd1c003eUL, 0x120098b9UL, 0x533183a0UL, 0x9062ae8bUL,
  76500. 0xd153b592UL, 0x16c5f4ddUL, 0x57f4efc4UL, 0x94a7c2efUL, 0xd596d9f6UL,
  76501. 0xe9bc07aeUL, 0xa88d1cb7UL, 0x6bde319cUL, 0x2aef2a85UL, 0xed796bcaUL,
  76502. 0xac4870d3UL, 0x6f1b5df8UL, 0x2e2a46e1UL, 0xe136de66UL, 0xa007c57fUL,
  76503. 0x6354e854UL, 0x2265f34dUL, 0xe5f3b202UL, 0xa4c2a91bUL, 0x67918430UL,
  76504. 0x26a09f29UL, 0xb8aec5e4UL, 0xf99fdefdUL, 0x3accf3d6UL, 0x7bfde8cfUL,
  76505. 0xbc6ba980UL, 0xfd5ab299UL, 0x3e099fb2UL, 0x7f3884abUL, 0xb0241c2cUL,
  76506. 0xf1150735UL, 0x32462a1eUL, 0x73773107UL, 0xb4e17048UL, 0xf5d06b51UL,
  76507. 0x3683467aUL, 0x77b25d63UL, 0x4ed7facbUL, 0x0fe6e1d2UL, 0xccb5ccf9UL,
  76508. 0x8d84d7e0UL, 0x4a1296afUL, 0x0b238db6UL, 0xc870a09dUL, 0x8941bb84UL,
  76509. 0x465d2303UL, 0x076c381aUL, 0xc43f1531UL, 0x850e0e28UL, 0x42984f67UL,
  76510. 0x03a9547eUL, 0xc0fa7955UL, 0x81cb624cUL, 0x1fc53881UL, 0x5ef42398UL,
  76511. 0x9da70eb3UL, 0xdc9615aaUL, 0x1b0054e5UL, 0x5a314ffcUL, 0x996262d7UL,
  76512. 0xd85379ceUL, 0x174fe149UL, 0x567efa50UL, 0x952dd77bUL, 0xd41ccc62UL,
  76513. 0x138a8d2dUL, 0x52bb9634UL, 0x91e8bb1fUL, 0xd0d9a006UL, 0xecf37e5eUL,
  76514. 0xadc26547UL, 0x6e91486cUL, 0x2fa05375UL, 0xe836123aUL, 0xa9070923UL,
  76515. 0x6a542408UL, 0x2b653f11UL, 0xe479a796UL, 0xa548bc8fUL, 0x661b91a4UL,
  76516. 0x272a8abdUL, 0xe0bccbf2UL, 0xa18dd0ebUL, 0x62defdc0UL, 0x23efe6d9UL,
  76517. 0xbde1bc14UL, 0xfcd0a70dUL, 0x3f838a26UL, 0x7eb2913fUL, 0xb924d070UL,
  76518. 0xf815cb69UL, 0x3b46e642UL, 0x7a77fd5bUL, 0xb56b65dcUL, 0xf45a7ec5UL,
  76519. 0x370953eeUL, 0x763848f7UL, 0xb1ae09b8UL, 0xf09f12a1UL, 0x33cc3f8aUL,
  76520. 0x72fd2493UL
  76521. },
  76522. {
  76523. 0x00000000UL, 0x376ac201UL, 0x6ed48403UL, 0x59be4602UL, 0xdca80907UL,
  76524. 0xebc2cb06UL, 0xb27c8d04UL, 0x85164f05UL, 0xb851130eUL, 0x8f3bd10fUL,
  76525. 0xd685970dUL, 0xe1ef550cUL, 0x64f91a09UL, 0x5393d808UL, 0x0a2d9e0aUL,
  76526. 0x3d475c0bUL, 0x70a3261cUL, 0x47c9e41dUL, 0x1e77a21fUL, 0x291d601eUL,
  76527. 0xac0b2f1bUL, 0x9b61ed1aUL, 0xc2dfab18UL, 0xf5b56919UL, 0xc8f23512UL,
  76528. 0xff98f713UL, 0xa626b111UL, 0x914c7310UL, 0x145a3c15UL, 0x2330fe14UL,
  76529. 0x7a8eb816UL, 0x4de47a17UL, 0xe0464d38UL, 0xd72c8f39UL, 0x8e92c93bUL,
  76530. 0xb9f80b3aUL, 0x3cee443fUL, 0x0b84863eUL, 0x523ac03cUL, 0x6550023dUL,
  76531. 0x58175e36UL, 0x6f7d9c37UL, 0x36c3da35UL, 0x01a91834UL, 0x84bf5731UL,
  76532. 0xb3d59530UL, 0xea6bd332UL, 0xdd011133UL, 0x90e56b24UL, 0xa78fa925UL,
  76533. 0xfe31ef27UL, 0xc95b2d26UL, 0x4c4d6223UL, 0x7b27a022UL, 0x2299e620UL,
  76534. 0x15f32421UL, 0x28b4782aUL, 0x1fdeba2bUL, 0x4660fc29UL, 0x710a3e28UL,
  76535. 0xf41c712dUL, 0xc376b32cUL, 0x9ac8f52eUL, 0xada2372fUL, 0xc08d9a70UL,
  76536. 0xf7e75871UL, 0xae591e73UL, 0x9933dc72UL, 0x1c259377UL, 0x2b4f5176UL,
  76537. 0x72f11774UL, 0x459bd575UL, 0x78dc897eUL, 0x4fb64b7fUL, 0x16080d7dUL,
  76538. 0x2162cf7cUL, 0xa4748079UL, 0x931e4278UL, 0xcaa0047aUL, 0xfdcac67bUL,
  76539. 0xb02ebc6cUL, 0x87447e6dUL, 0xdefa386fUL, 0xe990fa6eUL, 0x6c86b56bUL,
  76540. 0x5bec776aUL, 0x02523168UL, 0x3538f369UL, 0x087faf62UL, 0x3f156d63UL,
  76541. 0x66ab2b61UL, 0x51c1e960UL, 0xd4d7a665UL, 0xe3bd6464UL, 0xba032266UL,
  76542. 0x8d69e067UL, 0x20cbd748UL, 0x17a11549UL, 0x4e1f534bUL, 0x7975914aUL,
  76543. 0xfc63de4fUL, 0xcb091c4eUL, 0x92b75a4cUL, 0xa5dd984dUL, 0x989ac446UL,
  76544. 0xaff00647UL, 0xf64e4045UL, 0xc1248244UL, 0x4432cd41UL, 0x73580f40UL,
  76545. 0x2ae64942UL, 0x1d8c8b43UL, 0x5068f154UL, 0x67023355UL, 0x3ebc7557UL,
  76546. 0x09d6b756UL, 0x8cc0f853UL, 0xbbaa3a52UL, 0xe2147c50UL, 0xd57ebe51UL,
  76547. 0xe839e25aUL, 0xdf53205bUL, 0x86ed6659UL, 0xb187a458UL, 0x3491eb5dUL,
  76548. 0x03fb295cUL, 0x5a456f5eUL, 0x6d2fad5fUL, 0x801b35e1UL, 0xb771f7e0UL,
  76549. 0xeecfb1e2UL, 0xd9a573e3UL, 0x5cb33ce6UL, 0x6bd9fee7UL, 0x3267b8e5UL,
  76550. 0x050d7ae4UL, 0x384a26efUL, 0x0f20e4eeUL, 0x569ea2ecUL, 0x61f460edUL,
  76551. 0xe4e22fe8UL, 0xd388ede9UL, 0x8a36abebUL, 0xbd5c69eaUL, 0xf0b813fdUL,
  76552. 0xc7d2d1fcUL, 0x9e6c97feUL, 0xa90655ffUL, 0x2c101afaUL, 0x1b7ad8fbUL,
  76553. 0x42c49ef9UL, 0x75ae5cf8UL, 0x48e900f3UL, 0x7f83c2f2UL, 0x263d84f0UL,
  76554. 0x115746f1UL, 0x944109f4UL, 0xa32bcbf5UL, 0xfa958df7UL, 0xcdff4ff6UL,
  76555. 0x605d78d9UL, 0x5737bad8UL, 0x0e89fcdaUL, 0x39e33edbUL, 0xbcf571deUL,
  76556. 0x8b9fb3dfUL, 0xd221f5ddUL, 0xe54b37dcUL, 0xd80c6bd7UL, 0xef66a9d6UL,
  76557. 0xb6d8efd4UL, 0x81b22dd5UL, 0x04a462d0UL, 0x33cea0d1UL, 0x6a70e6d3UL,
  76558. 0x5d1a24d2UL, 0x10fe5ec5UL, 0x27949cc4UL, 0x7e2adac6UL, 0x494018c7UL,
  76559. 0xcc5657c2UL, 0xfb3c95c3UL, 0xa282d3c1UL, 0x95e811c0UL, 0xa8af4dcbUL,
  76560. 0x9fc58fcaUL, 0xc67bc9c8UL, 0xf1110bc9UL, 0x740744ccUL, 0x436d86cdUL,
  76561. 0x1ad3c0cfUL, 0x2db902ceUL, 0x4096af91UL, 0x77fc6d90UL, 0x2e422b92UL,
  76562. 0x1928e993UL, 0x9c3ea696UL, 0xab546497UL, 0xf2ea2295UL, 0xc580e094UL,
  76563. 0xf8c7bc9fUL, 0xcfad7e9eUL, 0x9613389cUL, 0xa179fa9dUL, 0x246fb598UL,
  76564. 0x13057799UL, 0x4abb319bUL, 0x7dd1f39aUL, 0x3035898dUL, 0x075f4b8cUL,
  76565. 0x5ee10d8eUL, 0x698bcf8fUL, 0xec9d808aUL, 0xdbf7428bUL, 0x82490489UL,
  76566. 0xb523c688UL, 0x88649a83UL, 0xbf0e5882UL, 0xe6b01e80UL, 0xd1dadc81UL,
  76567. 0x54cc9384UL, 0x63a65185UL, 0x3a181787UL, 0x0d72d586UL, 0xa0d0e2a9UL,
  76568. 0x97ba20a8UL, 0xce0466aaUL, 0xf96ea4abUL, 0x7c78ebaeUL, 0x4b1229afUL,
  76569. 0x12ac6fadUL, 0x25c6adacUL, 0x1881f1a7UL, 0x2feb33a6UL, 0x765575a4UL,
  76570. 0x413fb7a5UL, 0xc429f8a0UL, 0xf3433aa1UL, 0xaafd7ca3UL, 0x9d97bea2UL,
  76571. 0xd073c4b5UL, 0xe71906b4UL, 0xbea740b6UL, 0x89cd82b7UL, 0x0cdbcdb2UL,
  76572. 0x3bb10fb3UL, 0x620f49b1UL, 0x55658bb0UL, 0x6822d7bbUL, 0x5f4815baUL,
  76573. 0x06f653b8UL, 0x319c91b9UL, 0xb48adebcUL, 0x83e01cbdUL, 0xda5e5abfUL,
  76574. 0xed3498beUL
  76575. },
  76576. {
  76577. 0x00000000UL, 0x6567bcb8UL, 0x8bc809aaUL, 0xeeafb512UL, 0x5797628fUL,
  76578. 0x32f0de37UL, 0xdc5f6b25UL, 0xb938d79dUL, 0xef28b4c5UL, 0x8a4f087dUL,
  76579. 0x64e0bd6fUL, 0x018701d7UL, 0xb8bfd64aUL, 0xddd86af2UL, 0x3377dfe0UL,
  76580. 0x56106358UL, 0x9f571950UL, 0xfa30a5e8UL, 0x149f10faUL, 0x71f8ac42UL,
  76581. 0xc8c07bdfUL, 0xada7c767UL, 0x43087275UL, 0x266fcecdUL, 0x707fad95UL,
  76582. 0x1518112dUL, 0xfbb7a43fUL, 0x9ed01887UL, 0x27e8cf1aUL, 0x428f73a2UL,
  76583. 0xac20c6b0UL, 0xc9477a08UL, 0x3eaf32a0UL, 0x5bc88e18UL, 0xb5673b0aUL,
  76584. 0xd00087b2UL, 0x6938502fUL, 0x0c5fec97UL, 0xe2f05985UL, 0x8797e53dUL,
  76585. 0xd1878665UL, 0xb4e03addUL, 0x5a4f8fcfUL, 0x3f283377UL, 0x8610e4eaUL,
  76586. 0xe3775852UL, 0x0dd8ed40UL, 0x68bf51f8UL, 0xa1f82bf0UL, 0xc49f9748UL,
  76587. 0x2a30225aUL, 0x4f579ee2UL, 0xf66f497fUL, 0x9308f5c7UL, 0x7da740d5UL,
  76588. 0x18c0fc6dUL, 0x4ed09f35UL, 0x2bb7238dUL, 0xc518969fUL, 0xa07f2a27UL,
  76589. 0x1947fdbaUL, 0x7c204102UL, 0x928ff410UL, 0xf7e848a8UL, 0x3d58149bUL,
  76590. 0x583fa823UL, 0xb6901d31UL, 0xd3f7a189UL, 0x6acf7614UL, 0x0fa8caacUL,
  76591. 0xe1077fbeUL, 0x8460c306UL, 0xd270a05eUL, 0xb7171ce6UL, 0x59b8a9f4UL,
  76592. 0x3cdf154cUL, 0x85e7c2d1UL, 0xe0807e69UL, 0x0e2fcb7bUL, 0x6b4877c3UL,
  76593. 0xa20f0dcbUL, 0xc768b173UL, 0x29c70461UL, 0x4ca0b8d9UL, 0xf5986f44UL,
  76594. 0x90ffd3fcUL, 0x7e5066eeUL, 0x1b37da56UL, 0x4d27b90eUL, 0x284005b6UL,
  76595. 0xc6efb0a4UL, 0xa3880c1cUL, 0x1ab0db81UL, 0x7fd76739UL, 0x9178d22bUL,
  76596. 0xf41f6e93UL, 0x03f7263bUL, 0x66909a83UL, 0x883f2f91UL, 0xed589329UL,
  76597. 0x546044b4UL, 0x3107f80cUL, 0xdfa84d1eUL, 0xbacff1a6UL, 0xecdf92feUL,
  76598. 0x89b82e46UL, 0x67179b54UL, 0x027027ecUL, 0xbb48f071UL, 0xde2f4cc9UL,
  76599. 0x3080f9dbUL, 0x55e74563UL, 0x9ca03f6bUL, 0xf9c783d3UL, 0x176836c1UL,
  76600. 0x720f8a79UL, 0xcb375de4UL, 0xae50e15cUL, 0x40ff544eUL, 0x2598e8f6UL,
  76601. 0x73888baeUL, 0x16ef3716UL, 0xf8408204UL, 0x9d273ebcUL, 0x241fe921UL,
  76602. 0x41785599UL, 0xafd7e08bUL, 0xcab05c33UL, 0x3bb659edUL, 0x5ed1e555UL,
  76603. 0xb07e5047UL, 0xd519ecffUL, 0x6c213b62UL, 0x094687daUL, 0xe7e932c8UL,
  76604. 0x828e8e70UL, 0xd49eed28UL, 0xb1f95190UL, 0x5f56e482UL, 0x3a31583aUL,
  76605. 0x83098fa7UL, 0xe66e331fUL, 0x08c1860dUL, 0x6da63ab5UL, 0xa4e140bdUL,
  76606. 0xc186fc05UL, 0x2f294917UL, 0x4a4ef5afUL, 0xf3762232UL, 0x96119e8aUL,
  76607. 0x78be2b98UL, 0x1dd99720UL, 0x4bc9f478UL, 0x2eae48c0UL, 0xc001fdd2UL,
  76608. 0xa566416aUL, 0x1c5e96f7UL, 0x79392a4fUL, 0x97969f5dUL, 0xf2f123e5UL,
  76609. 0x05196b4dUL, 0x607ed7f5UL, 0x8ed162e7UL, 0xebb6de5fUL, 0x528e09c2UL,
  76610. 0x37e9b57aUL, 0xd9460068UL, 0xbc21bcd0UL, 0xea31df88UL, 0x8f566330UL,
  76611. 0x61f9d622UL, 0x049e6a9aUL, 0xbda6bd07UL, 0xd8c101bfUL, 0x366eb4adUL,
  76612. 0x53090815UL, 0x9a4e721dUL, 0xff29cea5UL, 0x11867bb7UL, 0x74e1c70fUL,
  76613. 0xcdd91092UL, 0xa8beac2aUL, 0x46111938UL, 0x2376a580UL, 0x7566c6d8UL,
  76614. 0x10017a60UL, 0xfeaecf72UL, 0x9bc973caUL, 0x22f1a457UL, 0x479618efUL,
  76615. 0xa939adfdUL, 0xcc5e1145UL, 0x06ee4d76UL, 0x6389f1ceUL, 0x8d2644dcUL,
  76616. 0xe841f864UL, 0x51792ff9UL, 0x341e9341UL, 0xdab12653UL, 0xbfd69aebUL,
  76617. 0xe9c6f9b3UL, 0x8ca1450bUL, 0x620ef019UL, 0x07694ca1UL, 0xbe519b3cUL,
  76618. 0xdb362784UL, 0x35999296UL, 0x50fe2e2eUL, 0x99b95426UL, 0xfcdee89eUL,
  76619. 0x12715d8cUL, 0x7716e134UL, 0xce2e36a9UL, 0xab498a11UL, 0x45e63f03UL,
  76620. 0x208183bbUL, 0x7691e0e3UL, 0x13f65c5bUL, 0xfd59e949UL, 0x983e55f1UL,
  76621. 0x2106826cUL, 0x44613ed4UL, 0xaace8bc6UL, 0xcfa9377eUL, 0x38417fd6UL,
  76622. 0x5d26c36eUL, 0xb389767cUL, 0xd6eecac4UL, 0x6fd61d59UL, 0x0ab1a1e1UL,
  76623. 0xe41e14f3UL, 0x8179a84bUL, 0xd769cb13UL, 0xb20e77abUL, 0x5ca1c2b9UL,
  76624. 0x39c67e01UL, 0x80fea99cUL, 0xe5991524UL, 0x0b36a036UL, 0x6e511c8eUL,
  76625. 0xa7166686UL, 0xc271da3eUL, 0x2cde6f2cUL, 0x49b9d394UL, 0xf0810409UL,
  76626. 0x95e6b8b1UL, 0x7b490da3UL, 0x1e2eb11bUL, 0x483ed243UL, 0x2d596efbUL,
  76627. 0xc3f6dbe9UL, 0xa6916751UL, 0x1fa9b0ccUL, 0x7ace0c74UL, 0x9461b966UL,
  76628. 0xf10605deUL
  76629. #endif
  76630. }
  76631. };
  76632. /*** End of inlined file: crc32.h ***/
  76633. #endif /* DYNAMIC_CRC_TABLE */
  76634. const unsigned long FAR * ZEXPORT get_crc_table()
  76635. {
  76636. #ifdef DYNAMIC_CRC_TABLE
  76637. if (crc_table_empty)
  76638. make_crc_table();
  76639. #endif /* DYNAMIC_CRC_TABLE */
  76640. return (const unsigned long FAR *)crc_table;
  76641. }
  76642. #define DO1 crc = crc_table[0][((int)crc ^ (*buf++)) & 0xff] ^ (crc >> 8)
  76643. #define DO8 DO1; DO1; DO1; DO1; DO1; DO1; DO1; DO1
  76644. unsigned long ZEXPORT crc32 (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76645. {
  76646. if (buf == Z_NULL) return 0UL;
  76647. #ifdef DYNAMIC_CRC_TABLE
  76648. if (crc_table_empty)
  76649. make_crc_table();
  76650. #endif /* DYNAMIC_CRC_TABLE */
  76651. #ifdef BYFOUR
  76652. if (sizeof(void *) == sizeof(ptrdiff_t)) {
  76653. u4 endian;
  76654. endian = 1;
  76655. if (*((unsigned char *)(&endian)))
  76656. return crc32_little(crc, buf, len);
  76657. else
  76658. return crc32_big(crc, buf, len);
  76659. }
  76660. #endif /* BYFOUR */
  76661. crc = crc ^ 0xffffffffUL;
  76662. while (len >= 8) {
  76663. DO8;
  76664. len -= 8;
  76665. }
  76666. if (len) do {
  76667. DO1;
  76668. } while (--len);
  76669. return crc ^ 0xffffffffUL;
  76670. }
  76671. #ifdef BYFOUR
  76672. #define DOLIT4 c ^= *buf4++; \
  76673. c = crc_table[3][c & 0xff] ^ crc_table[2][(c >> 8) & 0xff] ^ \
  76674. crc_table[1][(c >> 16) & 0xff] ^ crc_table[0][c >> 24]
  76675. #define DOLIT32 DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4; DOLIT4
  76676. local unsigned long crc32_little(unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76677. {
  76678. register u4 c;
  76679. register const u4 FAR *buf4;
  76680. c = (u4)crc;
  76681. c = ~c;
  76682. while (len && ((ptrdiff_t)buf & 3)) {
  76683. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76684. len--;
  76685. }
  76686. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76687. while (len >= 32) {
  76688. DOLIT32;
  76689. len -= 32;
  76690. }
  76691. while (len >= 4) {
  76692. DOLIT4;
  76693. len -= 4;
  76694. }
  76695. buf = (const unsigned char FAR *)buf4;
  76696. if (len) do {
  76697. c = crc_table[0][(c ^ *buf++) & 0xff] ^ (c >> 8);
  76698. } while (--len);
  76699. c = ~c;
  76700. return (unsigned long)c;
  76701. }
  76702. #define DOBIG4 c ^= *++buf4; \
  76703. c = crc_table[4][c & 0xff] ^ crc_table[5][(c >> 8) & 0xff] ^ \
  76704. crc_table[6][(c >> 16) & 0xff] ^ crc_table[7][c >> 24]
  76705. #define DOBIG32 DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4; DOBIG4
  76706. local unsigned long crc32_big (unsigned long crc, const unsigned char FAR *buf, unsigned len)
  76707. {
  76708. register u4 c;
  76709. register const u4 FAR *buf4;
  76710. c = REV((u4)crc);
  76711. c = ~c;
  76712. while (len && ((ptrdiff_t)buf & 3)) {
  76713. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76714. len--;
  76715. }
  76716. buf4 = (const u4 FAR *)(const void FAR *)buf;
  76717. buf4--;
  76718. while (len >= 32) {
  76719. DOBIG32;
  76720. len -= 32;
  76721. }
  76722. while (len >= 4) {
  76723. DOBIG4;
  76724. len -= 4;
  76725. }
  76726. buf4++;
  76727. buf = (const unsigned char FAR *)buf4;
  76728. if (len) do {
  76729. c = crc_table[4][(c >> 24) ^ *buf++] ^ (c << 8);
  76730. } while (--len);
  76731. c = ~c;
  76732. return (unsigned long)(REV(c));
  76733. }
  76734. #endif /* BYFOUR */
  76735. #define GF2_DIM 32 /* dimension of GF(2) vectors (length of CRC) */
  76736. local unsigned long gf2_matrix_times (unsigned long *mat, unsigned long vec)
  76737. {
  76738. unsigned long sum;
  76739. sum = 0;
  76740. while (vec) {
  76741. if (vec & 1)
  76742. sum ^= *mat;
  76743. vec >>= 1;
  76744. mat++;
  76745. }
  76746. return sum;
  76747. }
  76748. local void gf2_matrix_square (unsigned long *square, unsigned long *mat)
  76749. {
  76750. int n;
  76751. for (n = 0; n < GF2_DIM; n++)
  76752. square[n] = gf2_matrix_times(mat, mat[n]);
  76753. }
  76754. uLong ZEXPORT crc32_combine (uLong crc1, uLong crc2, z_off_t len2)
  76755. {
  76756. int n;
  76757. unsigned long row;
  76758. unsigned long even[GF2_DIM]; /* even-power-of-two zeros operator */
  76759. unsigned long odd[GF2_DIM]; /* odd-power-of-two zeros operator */
  76760. if (len2 == 0)
  76761. return crc1;
  76762. odd[0] = 0xedb88320L; /* CRC-32 polynomial */
  76763. row = 1;
  76764. for (n = 1; n < GF2_DIM; n++) {
  76765. odd[n] = row;
  76766. row <<= 1;
  76767. }
  76768. gf2_matrix_square(even, odd);
  76769. gf2_matrix_square(odd, even);
  76770. do {
  76771. gf2_matrix_square(even, odd);
  76772. if (len2 & 1)
  76773. crc1 = gf2_matrix_times(even, crc1);
  76774. len2 >>= 1;
  76775. if (len2 == 0)
  76776. break;
  76777. gf2_matrix_square(odd, even);
  76778. if (len2 & 1)
  76779. crc1 = gf2_matrix_times(odd, crc1);
  76780. len2 >>= 1;
  76781. } while (len2 != 0);
  76782. crc1 ^= crc2;
  76783. return crc1;
  76784. }
  76785. /*** End of inlined file: crc32.c ***/
  76786. /*** Start of inlined file: deflate.c ***/
  76787. /*** Start of inlined file: deflate.h ***/
  76788. #ifndef DEFLATE_H
  76789. #define DEFLATE_H
  76790. #ifndef NO_GZIP
  76791. # define GZIP
  76792. #endif
  76793. #define NO_DUMMY_DECL
  76794. #define LENGTH_CODES 29
  76795. #define LITERALS 256
  76796. #define L_CODES (LITERALS+1+LENGTH_CODES)
  76797. #define D_CODES 30
  76798. #define BL_CODES 19
  76799. #define HEAP_SIZE (2*L_CODES+1)
  76800. #define MAX_BITS 15
  76801. #define INIT_STATE 42
  76802. #define EXTRA_STATE 69
  76803. #define NAME_STATE 73
  76804. #define COMMENT_STATE 91
  76805. #define HCRC_STATE 103
  76806. #define BUSY_STATE 113
  76807. #define FINISH_STATE 666
  76808. typedef struct ct_data_s {
  76809. union {
  76810. ush freq; /* frequency count */
  76811. ush code; /* bit string */
  76812. } fc;
  76813. union {
  76814. ush dad; /* father node in Huffman tree */
  76815. ush len; /* length of bit string */
  76816. } dl;
  76817. } FAR ct_data;
  76818. #define Freq fc.freq
  76819. #define Code fc.code
  76820. #define Dad dl.dad
  76821. #define Len dl.len
  76822. typedef struct static_tree_desc_s static_tree_desc;
  76823. typedef struct tree_desc_s {
  76824. ct_data *dyn_tree; /* the dynamic tree */
  76825. int max_code; /* largest code with non zero frequency */
  76826. static_tree_desc *stat_desc; /* the corresponding static tree */
  76827. } FAR tree_desc;
  76828. typedef ush Pos;
  76829. typedef Pos FAR Posf;
  76830. typedef unsigned IPos;
  76831. typedef struct internal_state {
  76832. z_streamp strm; /* pointer back to this zlib stream */
  76833. int status; /* as the name implies */
  76834. Bytef *pending_buf; /* output still pending */
  76835. ulg pending_buf_size; /* size of pending_buf */
  76836. Bytef *pending_out; /* next pending byte to output to the stream */
  76837. uInt pending; /* nb of bytes in the pending buffer */
  76838. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  76839. gz_headerp gzhead; /* gzip header information to write */
  76840. uInt gzindex; /* where in extra, name, or comment */
  76841. Byte method; /* STORED (for zip only) or DEFLATED */
  76842. int last_flush; /* value of flush param for previous deflate call */
  76843. uInt w_size; /* LZ77 window size (32K by default) */
  76844. uInt w_bits; /* log2(w_size) (8..16) */
  76845. uInt w_mask; /* w_size - 1 */
  76846. Bytef *window;
  76847. ulg window_size;
  76848. Posf *prev;
  76849. Posf *head; /* Heads of the hash chains or NIL. */
  76850. uInt ins_h; /* hash index of string to be inserted */
  76851. uInt hash_size; /* number of elements in hash table */
  76852. uInt hash_bits; /* log2(hash_size) */
  76853. uInt hash_mask; /* hash_size-1 */
  76854. uInt hash_shift;
  76855. long block_start;
  76856. uInt match_length; /* length of best match */
  76857. IPos prev_match; /* previous match */
  76858. int match_available; /* set if previous match exists */
  76859. uInt strstart; /* start of string to insert */
  76860. uInt match_start; /* start of matching string */
  76861. uInt lookahead; /* number of valid bytes ahead in window */
  76862. uInt prev_length;
  76863. uInt max_chain_length;
  76864. uInt max_lazy_match;
  76865. # define max_insert_length max_lazy_match
  76866. int level; /* compression level (1..9) */
  76867. int strategy; /* favor or force Huffman coding*/
  76868. uInt good_match;
  76869. int nice_match; /* Stop searching when current match exceeds this */
  76870. struct ct_data_s dyn_ltree[HEAP_SIZE]; /* literal and length tree */
  76871. struct ct_data_s dyn_dtree[2*D_CODES+1]; /* distance tree */
  76872. struct ct_data_s bl_tree[2*BL_CODES+1]; /* Huffman tree for bit lengths */
  76873. struct tree_desc_s l_desc; /* desc. for literal tree */
  76874. struct tree_desc_s d_desc; /* desc. for distance tree */
  76875. struct tree_desc_s bl_desc; /* desc. for bit length tree */
  76876. ush bl_count[MAX_BITS+1];
  76877. int heap[2*L_CODES+1]; /* heap used to build the Huffman trees */
  76878. int heap_len; /* number of elements in the heap */
  76879. int heap_max; /* element of largest frequency */
  76880. uch depth[2*L_CODES+1];
  76881. uchf *l_buf; /* buffer for literals or lengths */
  76882. uInt lit_bufsize;
  76883. uInt last_lit; /* running index in l_buf */
  76884. ushf *d_buf;
  76885. ulg opt_len; /* bit length of current block with optimal trees */
  76886. ulg static_len; /* bit length of current block with static trees */
  76887. uInt matches; /* number of string matches in current block */
  76888. int last_eob_len; /* bit length of EOB code for last block */
  76889. #ifdef DEBUG
  76890. ulg compressed_len; /* total bit length of compressed file mod 2^32 */
  76891. ulg bits_sent; /* bit length of compressed data sent mod 2^32 */
  76892. #endif
  76893. ush bi_buf;
  76894. int bi_valid;
  76895. } FAR deflate_state;
  76896. #define put_byte(s, c) {s->pending_buf[s->pending++] = (c);}
  76897. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76898. #define MAX_DIST(s) ((s)->w_size-MIN_LOOKAHEAD)
  76899. void _tr_init OF((deflate_state *s));
  76900. int _tr_tally OF((deflate_state *s, unsigned dist, unsigned lc));
  76901. void _tr_flush_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76902. int eof));
  76903. void _tr_align OF((deflate_state *s));
  76904. void _tr_stored_block OF((deflate_state *s, charf *buf, ulg stored_len,
  76905. int eof));
  76906. #define d_code(dist) \
  76907. ((dist) < 256 ? _dist_code[dist] : _dist_code[256+((dist)>>7)])
  76908. #ifndef DEBUG
  76909. #if defined(GEN_TREES_H) || !defined(STDC)
  76910. extern uch _length_code[];
  76911. extern uch _dist_code[];
  76912. #else
  76913. extern const uch _length_code[];
  76914. extern const uch _dist_code[];
  76915. #endif
  76916. # define _tr_tally_lit(s, c, flush) \
  76917. { uch cc = (c); \
  76918. s->d_buf[s->last_lit] = 0; \
  76919. s->l_buf[s->last_lit++] = cc; \
  76920. s->dyn_ltree[cc].Freq++; \
  76921. flush = (s->last_lit == s->lit_bufsize-1); \
  76922. }
  76923. # define _tr_tally_dist(s, distance, length, flush) \
  76924. { uch len = (length); \
  76925. ush dist = (distance); \
  76926. s->d_buf[s->last_lit] = dist; \
  76927. s->l_buf[s->last_lit++] = len; \
  76928. dist--; \
  76929. s->dyn_ltree[_length_code[len]+LITERALS+1].Freq++; \
  76930. s->dyn_dtree[d_code(dist)].Freq++; \
  76931. flush = (s->last_lit == s->lit_bufsize-1); \
  76932. }
  76933. #else
  76934. # define _tr_tally_lit(s, c, flush) flush = _tr_tally(s, 0, c)
  76935. # define _tr_tally_dist(s, distance, length, flush) \
  76936. flush = _tr_tally(s, distance, length)
  76937. #endif
  76938. #endif /* DEFLATE_H */
  76939. /*** End of inlined file: deflate.h ***/
  76940. const char deflate_copyright[] =
  76941. " deflate 1.2.3 Copyright 1995-2005 Jean-loup Gailly ";
  76942. typedef enum {
  76943. need_more, /* block not completed, need more input or more output */
  76944. block_done, /* block flush performed */
  76945. finish_started, /* finish started, need only more output at next deflate */
  76946. finish_done /* finish done, accept no more input or output */
  76947. } block_state;
  76948. typedef block_state (*compress_func) OF((deflate_state *s, int flush));
  76949. local void fill_window OF((deflate_state *s));
  76950. local block_state deflate_stored OF((deflate_state *s, int flush));
  76951. local block_state deflate_fast OF((deflate_state *s, int flush));
  76952. #ifndef FASTEST
  76953. local block_state deflate_slow OF((deflate_state *s, int flush));
  76954. #endif
  76955. local void lm_init OF((deflate_state *s));
  76956. local void putShortMSB OF((deflate_state *s, uInt b));
  76957. local void flush_pending OF((z_streamp strm));
  76958. local int read_buf OF((z_streamp strm, Bytef *buf, unsigned size));
  76959. #ifndef FASTEST
  76960. #ifdef ASMV
  76961. void match_init OF((void)); /* asm code initialization */
  76962. uInt longest_match OF((deflate_state *s, IPos cur_match));
  76963. #else
  76964. local uInt longest_match OF((deflate_state *s, IPos cur_match));
  76965. #endif
  76966. #endif
  76967. local uInt longest_match_fast OF((deflate_state *s, IPos cur_match));
  76968. #ifdef DEBUG
  76969. local void check_match OF((deflate_state *s, IPos start, IPos match,
  76970. int length));
  76971. #endif
  76972. #define NIL 0
  76973. #ifndef TOO_FAR
  76974. # define TOO_FAR 4096
  76975. #endif
  76976. #define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1)
  76977. typedef struct config_s {
  76978. ush good_length; /* reduce lazy search above this match length */
  76979. ush max_lazy; /* do not perform lazy search above this match length */
  76980. ush nice_length; /* quit search above this match length */
  76981. ush max_chain;
  76982. compress_func func;
  76983. } config;
  76984. #ifdef FASTEST
  76985. local const config configuration_table[2] = {
  76986. {0, 0, 0, 0, deflate_stored}, /* store only */
  76987. {4, 4, 8, 4, deflate_fast}}; /* max speed, no lazy matches */
  76988. #else
  76989. local const config configuration_table[10] = {
  76990. {0, 0, 0, 0, deflate_stored}, /* store only */
  76991. {4, 4, 8, 4, deflate_fast}, /* max speed, no lazy matches */
  76992. {4, 5, 16, 8, deflate_fast},
  76993. {4, 6, 32, 32, deflate_fast},
  76994. {4, 4, 16, 16, deflate_slow}, /* lazy matches */
  76995. {8, 16, 32, 32, deflate_slow},
  76996. {8, 16, 128, 128, deflate_slow},
  76997. {8, 32, 128, 256, deflate_slow},
  76998. {32, 128, 258, 1024, deflate_slow},
  76999. {32, 258, 258, 4096, deflate_slow}}; /* max compression */
  77000. #endif
  77001. #define EQUAL 0
  77002. #ifndef NO_DUMMY_DECL
  77003. struct static_tree_desc_s {int dummy;}; /* for buggy compilers */
  77004. #endif
  77005. #define UPDATE_HASH(s,h,c) (h = (((h)<<s->hash_shift) ^ (c)) & s->hash_mask)
  77006. #ifdef FASTEST
  77007. #define INSERT_STRING(s, str, match_head) \
  77008. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  77009. match_head = s->head[s->ins_h], \
  77010. s->head[s->ins_h] = (Pos)(str))
  77011. #else
  77012. #define INSERT_STRING(s, str, match_head) \
  77013. (UPDATE_HASH(s, s->ins_h, s->window[(str) + (MIN_MATCH-1)]), \
  77014. match_head = s->prev[(str) & s->w_mask] = s->head[s->ins_h], \
  77015. s->head[s->ins_h] = (Pos)(str))
  77016. #endif
  77017. #define CLEAR_HASH(s) \
  77018. s->head[s->hash_size-1] = NIL; \
  77019. zmemzero((Bytef *)s->head, (unsigned)(s->hash_size-1)*sizeof(*s->head));
  77020. int ZEXPORT deflateInit_(z_streamp strm, int level, const char *version, int stream_size)
  77021. {
  77022. return deflateInit2_(strm, level, Z_DEFLATED, MAX_WBITS, DEF_MEM_LEVEL,
  77023. Z_DEFAULT_STRATEGY, version, stream_size);
  77024. }
  77025. int ZEXPORT deflateInit2_ (z_streamp strm, int level, int method, int windowBits, int memLevel, int strategy, const char *version, int stream_size)
  77026. {
  77027. deflate_state *s;
  77028. int wrap = 1;
  77029. static const char my_version[] = ZLIB_VERSION;
  77030. ushf *overlay;
  77031. if (version == Z_NULL || version[0] != my_version[0] ||
  77032. stream_size != sizeof(z_stream)) {
  77033. return Z_VERSION_ERROR;
  77034. }
  77035. if (strm == Z_NULL) return Z_STREAM_ERROR;
  77036. strm->msg = Z_NULL;
  77037. if (strm->zalloc == (alloc_func)0) {
  77038. strm->zalloc = zcalloc;
  77039. strm->opaque = (voidpf)0;
  77040. }
  77041. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  77042. #ifdef FASTEST
  77043. if (level != 0) level = 1;
  77044. #else
  77045. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  77046. #endif
  77047. if (windowBits < 0) { /* suppress zlib wrapper */
  77048. wrap = 0;
  77049. windowBits = -windowBits;
  77050. }
  77051. #ifdef GZIP
  77052. else if (windowBits > 15) {
  77053. wrap = 2; /* write gzip wrapper instead */
  77054. windowBits -= 16;
  77055. }
  77056. #endif
  77057. if (memLevel < 1 || memLevel > MAX_MEM_LEVEL || method != Z_DEFLATED ||
  77058. windowBits < 8 || windowBits > 15 || level < 0 || level > 9 ||
  77059. strategy < 0 || strategy > Z_FIXED) {
  77060. return Z_STREAM_ERROR;
  77061. }
  77062. if (windowBits == 8) windowBits = 9; /* until 256-byte window bug fixed */
  77063. s = (deflate_state *) ZALLOC(strm, 1, sizeof(deflate_state));
  77064. if (s == Z_NULL) return Z_MEM_ERROR;
  77065. strm->state = (struct internal_state FAR *)s;
  77066. s->strm = strm;
  77067. s->wrap = wrap;
  77068. s->gzhead = Z_NULL;
  77069. s->w_bits = windowBits;
  77070. s->w_size = 1 << s->w_bits;
  77071. s->w_mask = s->w_size - 1;
  77072. s->hash_bits = memLevel + 7;
  77073. s->hash_size = 1 << s->hash_bits;
  77074. s->hash_mask = s->hash_size - 1;
  77075. s->hash_shift = ((s->hash_bits+MIN_MATCH-1)/MIN_MATCH);
  77076. s->window = (Bytef *) ZALLOC(strm, s->w_size, 2*sizeof(Byte));
  77077. s->prev = (Posf *) ZALLOC(strm, s->w_size, sizeof(Pos));
  77078. s->head = (Posf *) ZALLOC(strm, s->hash_size, sizeof(Pos));
  77079. s->lit_bufsize = 1 << (memLevel + 6); /* 16K elements by default */
  77080. overlay = (ushf *) ZALLOC(strm, s->lit_bufsize, sizeof(ush)+2);
  77081. s->pending_buf = (uchf *) overlay;
  77082. s->pending_buf_size = (ulg)s->lit_bufsize * (sizeof(ush)+2L);
  77083. if (s->window == Z_NULL || s->prev == Z_NULL || s->head == Z_NULL ||
  77084. s->pending_buf == Z_NULL) {
  77085. s->status = FINISH_STATE;
  77086. strm->msg = (char*)ERR_MSG(Z_MEM_ERROR);
  77087. deflateEnd (strm);
  77088. return Z_MEM_ERROR;
  77089. }
  77090. s->d_buf = overlay + s->lit_bufsize/sizeof(ush);
  77091. s->l_buf = s->pending_buf + (1+sizeof(ush))*s->lit_bufsize;
  77092. s->level = level;
  77093. s->strategy = strategy;
  77094. s->method = (Byte)method;
  77095. return deflateReset(strm);
  77096. }
  77097. int ZEXPORT deflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  77098. {
  77099. deflate_state *s;
  77100. uInt length = dictLength;
  77101. uInt n;
  77102. IPos hash_head = 0;
  77103. if (strm == Z_NULL || strm->state == Z_NULL || dictionary == Z_NULL ||
  77104. strm->state->wrap == 2 ||
  77105. (strm->state->wrap == 1 && strm->state->status != INIT_STATE))
  77106. return Z_STREAM_ERROR;
  77107. s = strm->state;
  77108. if (s->wrap)
  77109. strm->adler = adler32(strm->adler, dictionary, dictLength);
  77110. if (length < MIN_MATCH) return Z_OK;
  77111. if (length > MAX_DIST(s)) {
  77112. length = MAX_DIST(s);
  77113. dictionary += dictLength - length; /* use the tail of the dictionary */
  77114. }
  77115. zmemcpy(s->window, dictionary, length);
  77116. s->strstart = length;
  77117. s->block_start = (long)length;
  77118. s->ins_h = s->window[0];
  77119. UPDATE_HASH(s, s->ins_h, s->window[1]);
  77120. for (n = 0; n <= length - MIN_MATCH; n++) {
  77121. INSERT_STRING(s, n, hash_head);
  77122. }
  77123. if (hash_head) hash_head = 0; /* to make compiler happy */
  77124. return Z_OK;
  77125. }
  77126. int ZEXPORT deflateReset (z_streamp strm)
  77127. {
  77128. deflate_state *s;
  77129. if (strm == Z_NULL || strm->state == Z_NULL ||
  77130. strm->zalloc == (alloc_func)0 || strm->zfree == (free_func)0) {
  77131. return Z_STREAM_ERROR;
  77132. }
  77133. strm->total_in = strm->total_out = 0;
  77134. strm->msg = Z_NULL; /* use zfree if we ever allocate msg dynamically */
  77135. strm->data_type = Z_UNKNOWN;
  77136. s = (deflate_state *)strm->state;
  77137. s->pending = 0;
  77138. s->pending_out = s->pending_buf;
  77139. if (s->wrap < 0) {
  77140. s->wrap = -s->wrap; /* was made negative by deflate(..., Z_FINISH); */
  77141. }
  77142. s->status = s->wrap ? INIT_STATE : BUSY_STATE;
  77143. strm->adler =
  77144. #ifdef GZIP
  77145. s->wrap == 2 ? crc32(0L, Z_NULL, 0) :
  77146. #endif
  77147. adler32(0L, Z_NULL, 0);
  77148. s->last_flush = Z_NO_FLUSH;
  77149. _tr_init(s);
  77150. lm_init(s);
  77151. return Z_OK;
  77152. }
  77153. int ZEXPORT deflateSetHeader (z_streamp strm, gz_headerp head)
  77154. {
  77155. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77156. if (strm->state->wrap != 2) return Z_STREAM_ERROR;
  77157. strm->state->gzhead = head;
  77158. return Z_OK;
  77159. }
  77160. int ZEXPORT deflatePrime (z_streamp strm, int bits, int value)
  77161. {
  77162. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77163. strm->state->bi_valid = bits;
  77164. strm->state->bi_buf = (ush)(value & ((1 << bits) - 1));
  77165. return Z_OK;
  77166. }
  77167. int ZEXPORT deflateParams (z_streamp strm, int level, int strategy)
  77168. {
  77169. deflate_state *s;
  77170. compress_func func;
  77171. int err = Z_OK;
  77172. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77173. s = strm->state;
  77174. #ifdef FASTEST
  77175. if (level != 0) level = 1;
  77176. #else
  77177. if (level == Z_DEFAULT_COMPRESSION) level = 6;
  77178. #endif
  77179. if (level < 0 || level > 9 || strategy < 0 || strategy > Z_FIXED) {
  77180. return Z_STREAM_ERROR;
  77181. }
  77182. func = configuration_table[s->level].func;
  77183. if (func != configuration_table[level].func && strm->total_in != 0) {
  77184. err = deflate(strm, Z_PARTIAL_FLUSH);
  77185. }
  77186. if (s->level != level) {
  77187. s->level = level;
  77188. s->max_lazy_match = configuration_table[level].max_lazy;
  77189. s->good_match = configuration_table[level].good_length;
  77190. s->nice_match = configuration_table[level].nice_length;
  77191. s->max_chain_length = configuration_table[level].max_chain;
  77192. }
  77193. s->strategy = strategy;
  77194. return err;
  77195. }
  77196. int ZEXPORT deflateTune (z_streamp strm, int good_length, int max_lazy, int nice_length, int max_chain)
  77197. {
  77198. deflate_state *s;
  77199. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77200. s = strm->state;
  77201. s->good_match = good_length;
  77202. s->max_lazy_match = max_lazy;
  77203. s->nice_match = nice_length;
  77204. s->max_chain_length = max_chain;
  77205. return Z_OK;
  77206. }
  77207. uLong ZEXPORT deflateBound (z_streamp strm, uLong sourceLen)
  77208. {
  77209. deflate_state *s;
  77210. uLong destLen;
  77211. destLen = sourceLen +
  77212. ((sourceLen + 7) >> 3) + ((sourceLen + 63) >> 6) + 11;
  77213. if (strm == Z_NULL || strm->state == Z_NULL)
  77214. return destLen;
  77215. s = strm->state;
  77216. if (s->w_bits != 15 || s->hash_bits != 8 + 7)
  77217. return destLen;
  77218. return compressBound(sourceLen);
  77219. }
  77220. local void putShortMSB (deflate_state *s, uInt b)
  77221. {
  77222. put_byte(s, (Byte)(b >> 8));
  77223. put_byte(s, (Byte)(b & 0xff));
  77224. }
  77225. local void flush_pending (z_streamp strm)
  77226. {
  77227. unsigned len = strm->state->pending;
  77228. if (len > strm->avail_out) len = strm->avail_out;
  77229. if (len == 0) return;
  77230. zmemcpy(strm->next_out, strm->state->pending_out, len);
  77231. strm->next_out += len;
  77232. strm->state->pending_out += len;
  77233. strm->total_out += len;
  77234. strm->avail_out -= len;
  77235. strm->state->pending -= len;
  77236. if (strm->state->pending == 0) {
  77237. strm->state->pending_out = strm->state->pending_buf;
  77238. }
  77239. }
  77240. int ZEXPORT deflate (z_streamp strm, int flush)
  77241. {
  77242. int old_flush; /* value of flush param for previous deflate call */
  77243. deflate_state *s;
  77244. if (strm == Z_NULL || strm->state == Z_NULL ||
  77245. flush > Z_FINISH || flush < 0) {
  77246. return Z_STREAM_ERROR;
  77247. }
  77248. s = strm->state;
  77249. if (strm->next_out == Z_NULL ||
  77250. (strm->next_in == Z_NULL && strm->avail_in != 0) ||
  77251. (s->status == FINISH_STATE && flush != Z_FINISH)) {
  77252. ERR_RETURN(strm, Z_STREAM_ERROR);
  77253. }
  77254. if (strm->avail_out == 0) ERR_RETURN(strm, Z_BUF_ERROR);
  77255. s->strm = strm; /* just in case */
  77256. old_flush = s->last_flush;
  77257. s->last_flush = flush;
  77258. if (s->status == INIT_STATE) {
  77259. #ifdef GZIP
  77260. if (s->wrap == 2) {
  77261. strm->adler = crc32(0L, Z_NULL, 0);
  77262. put_byte(s, 31);
  77263. put_byte(s, 139);
  77264. put_byte(s, 8);
  77265. if (s->gzhead == NULL) {
  77266. put_byte(s, 0);
  77267. put_byte(s, 0);
  77268. put_byte(s, 0);
  77269. put_byte(s, 0);
  77270. put_byte(s, 0);
  77271. put_byte(s, s->level == 9 ? 2 :
  77272. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77273. 4 : 0));
  77274. put_byte(s, OS_CODE);
  77275. s->status = BUSY_STATE;
  77276. }
  77277. else {
  77278. put_byte(s, (s->gzhead->text ? 1 : 0) +
  77279. (s->gzhead->hcrc ? 2 : 0) +
  77280. (s->gzhead->extra == Z_NULL ? 0 : 4) +
  77281. (s->gzhead->name == Z_NULL ? 0 : 8) +
  77282. (s->gzhead->comment == Z_NULL ? 0 : 16)
  77283. );
  77284. put_byte(s, (Byte)(s->gzhead->time & 0xff));
  77285. put_byte(s, (Byte)((s->gzhead->time >> 8) & 0xff));
  77286. put_byte(s, (Byte)((s->gzhead->time >> 16) & 0xff));
  77287. put_byte(s, (Byte)((s->gzhead->time >> 24) & 0xff));
  77288. put_byte(s, s->level == 9 ? 2 :
  77289. (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2 ?
  77290. 4 : 0));
  77291. put_byte(s, s->gzhead->os & 0xff);
  77292. if (s->gzhead->extra != NULL) {
  77293. put_byte(s, s->gzhead->extra_len & 0xff);
  77294. put_byte(s, (s->gzhead->extra_len >> 8) & 0xff);
  77295. }
  77296. if (s->gzhead->hcrc)
  77297. strm->adler = crc32(strm->adler, s->pending_buf,
  77298. s->pending);
  77299. s->gzindex = 0;
  77300. s->status = EXTRA_STATE;
  77301. }
  77302. }
  77303. else
  77304. #endif
  77305. {
  77306. uInt header = (Z_DEFLATED + ((s->w_bits-8)<<4)) << 8;
  77307. uInt level_flags;
  77308. if (s->strategy >= Z_HUFFMAN_ONLY || s->level < 2)
  77309. level_flags = 0;
  77310. else if (s->level < 6)
  77311. level_flags = 1;
  77312. else if (s->level == 6)
  77313. level_flags = 2;
  77314. else
  77315. level_flags = 3;
  77316. header |= (level_flags << 6);
  77317. if (s->strstart != 0) header |= PRESET_DICT;
  77318. header += 31 - (header % 31);
  77319. s->status = BUSY_STATE;
  77320. putShortMSB(s, header);
  77321. if (s->strstart != 0) {
  77322. putShortMSB(s, (uInt)(strm->adler >> 16));
  77323. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77324. }
  77325. strm->adler = adler32(0L, Z_NULL, 0);
  77326. }
  77327. }
  77328. #ifdef GZIP
  77329. if (s->status == EXTRA_STATE) {
  77330. if (s->gzhead->extra != NULL) {
  77331. uInt beg = s->pending; /* start of bytes to update crc */
  77332. while (s->gzindex < (s->gzhead->extra_len & 0xffff)) {
  77333. if (s->pending == s->pending_buf_size) {
  77334. if (s->gzhead->hcrc && s->pending > beg)
  77335. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77336. s->pending - beg);
  77337. flush_pending(strm);
  77338. beg = s->pending;
  77339. if (s->pending == s->pending_buf_size)
  77340. break;
  77341. }
  77342. put_byte(s, s->gzhead->extra[s->gzindex]);
  77343. s->gzindex++;
  77344. }
  77345. if (s->gzhead->hcrc && s->pending > beg)
  77346. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77347. s->pending - beg);
  77348. if (s->gzindex == s->gzhead->extra_len) {
  77349. s->gzindex = 0;
  77350. s->status = NAME_STATE;
  77351. }
  77352. }
  77353. else
  77354. s->status = NAME_STATE;
  77355. }
  77356. if (s->status == NAME_STATE) {
  77357. if (s->gzhead->name != NULL) {
  77358. uInt beg = s->pending; /* start of bytes to update crc */
  77359. int val;
  77360. do {
  77361. if (s->pending == s->pending_buf_size) {
  77362. if (s->gzhead->hcrc && s->pending > beg)
  77363. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77364. s->pending - beg);
  77365. flush_pending(strm);
  77366. beg = s->pending;
  77367. if (s->pending == s->pending_buf_size) {
  77368. val = 1;
  77369. break;
  77370. }
  77371. }
  77372. val = s->gzhead->name[s->gzindex++];
  77373. put_byte(s, val);
  77374. } while (val != 0);
  77375. if (s->gzhead->hcrc && s->pending > beg)
  77376. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77377. s->pending - beg);
  77378. if (val == 0) {
  77379. s->gzindex = 0;
  77380. s->status = COMMENT_STATE;
  77381. }
  77382. }
  77383. else
  77384. s->status = COMMENT_STATE;
  77385. }
  77386. if (s->status == COMMENT_STATE) {
  77387. if (s->gzhead->comment != NULL) {
  77388. uInt beg = s->pending; /* start of bytes to update crc */
  77389. int val;
  77390. do {
  77391. if (s->pending == s->pending_buf_size) {
  77392. if (s->gzhead->hcrc && s->pending > beg)
  77393. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77394. s->pending - beg);
  77395. flush_pending(strm);
  77396. beg = s->pending;
  77397. if (s->pending == s->pending_buf_size) {
  77398. val = 1;
  77399. break;
  77400. }
  77401. }
  77402. val = s->gzhead->comment[s->gzindex++];
  77403. put_byte(s, val);
  77404. } while (val != 0);
  77405. if (s->gzhead->hcrc && s->pending > beg)
  77406. strm->adler = crc32(strm->adler, s->pending_buf + beg,
  77407. s->pending - beg);
  77408. if (val == 0)
  77409. s->status = HCRC_STATE;
  77410. }
  77411. else
  77412. s->status = HCRC_STATE;
  77413. }
  77414. if (s->status == HCRC_STATE) {
  77415. if (s->gzhead->hcrc) {
  77416. if (s->pending + 2 > s->pending_buf_size)
  77417. flush_pending(strm);
  77418. if (s->pending + 2 <= s->pending_buf_size) {
  77419. put_byte(s, (Byte)(strm->adler & 0xff));
  77420. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77421. strm->adler = crc32(0L, Z_NULL, 0);
  77422. s->status = BUSY_STATE;
  77423. }
  77424. }
  77425. else
  77426. s->status = BUSY_STATE;
  77427. }
  77428. #endif
  77429. if (s->pending != 0) {
  77430. flush_pending(strm);
  77431. if (strm->avail_out == 0) {
  77432. s->last_flush = -1;
  77433. return Z_OK;
  77434. }
  77435. } else if (strm->avail_in == 0 && flush <= old_flush &&
  77436. flush != Z_FINISH) {
  77437. ERR_RETURN(strm, Z_BUF_ERROR);
  77438. }
  77439. if (s->status == FINISH_STATE && strm->avail_in != 0) {
  77440. ERR_RETURN(strm, Z_BUF_ERROR);
  77441. }
  77442. if (strm->avail_in != 0 || s->lookahead != 0 ||
  77443. (flush != Z_NO_FLUSH && s->status != FINISH_STATE)) {
  77444. block_state bstate;
  77445. bstate = (*(configuration_table[s->level].func))(s, flush);
  77446. if (bstate == finish_started || bstate == finish_done) {
  77447. s->status = FINISH_STATE;
  77448. }
  77449. if (bstate == need_more || bstate == finish_started) {
  77450. if (strm->avail_out == 0) {
  77451. s->last_flush = -1; /* avoid BUF_ERROR next call, see above */
  77452. }
  77453. return Z_OK;
  77454. }
  77455. if (bstate == block_done) {
  77456. if (flush == Z_PARTIAL_FLUSH) {
  77457. _tr_align(s);
  77458. } else { /* FULL_FLUSH or SYNC_FLUSH */
  77459. _tr_stored_block(s, (char*)0, 0L, 0);
  77460. if (flush == Z_FULL_FLUSH) {
  77461. CLEAR_HASH(s); /* forget history */
  77462. }
  77463. }
  77464. flush_pending(strm);
  77465. if (strm->avail_out == 0) {
  77466. s->last_flush = -1; /* avoid BUF_ERROR at next call, see above */
  77467. return Z_OK;
  77468. }
  77469. }
  77470. }
  77471. Assert(strm->avail_out > 0, "bug2");
  77472. if (flush != Z_FINISH) return Z_OK;
  77473. if (s->wrap <= 0) return Z_STREAM_END;
  77474. #ifdef GZIP
  77475. if (s->wrap == 2) {
  77476. put_byte(s, (Byte)(strm->adler & 0xff));
  77477. put_byte(s, (Byte)((strm->adler >> 8) & 0xff));
  77478. put_byte(s, (Byte)((strm->adler >> 16) & 0xff));
  77479. put_byte(s, (Byte)((strm->adler >> 24) & 0xff));
  77480. put_byte(s, (Byte)(strm->total_in & 0xff));
  77481. put_byte(s, (Byte)((strm->total_in >> 8) & 0xff));
  77482. put_byte(s, (Byte)((strm->total_in >> 16) & 0xff));
  77483. put_byte(s, (Byte)((strm->total_in >> 24) & 0xff));
  77484. }
  77485. else
  77486. #endif
  77487. {
  77488. putShortMSB(s, (uInt)(strm->adler >> 16));
  77489. putShortMSB(s, (uInt)(strm->adler & 0xffff));
  77490. }
  77491. flush_pending(strm);
  77492. if (s->wrap > 0) s->wrap = -s->wrap; /* write the trailer only once! */
  77493. return s->pending != 0 ? Z_OK : Z_STREAM_END;
  77494. }
  77495. int ZEXPORT deflateEnd (z_streamp strm)
  77496. {
  77497. int status;
  77498. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  77499. status = strm->state->status;
  77500. if (status != INIT_STATE &&
  77501. status != EXTRA_STATE &&
  77502. status != NAME_STATE &&
  77503. status != COMMENT_STATE &&
  77504. status != HCRC_STATE &&
  77505. status != BUSY_STATE &&
  77506. status != FINISH_STATE) {
  77507. return Z_STREAM_ERROR;
  77508. }
  77509. TRY_FREE(strm, strm->state->pending_buf);
  77510. TRY_FREE(strm, strm->state->head);
  77511. TRY_FREE(strm, strm->state->prev);
  77512. TRY_FREE(strm, strm->state->window);
  77513. ZFREE(strm, strm->state);
  77514. strm->state = Z_NULL;
  77515. return status == BUSY_STATE ? Z_DATA_ERROR : Z_OK;
  77516. }
  77517. int ZEXPORT deflateCopy (z_streamp dest, z_streamp source)
  77518. {
  77519. #ifdef MAXSEG_64K
  77520. return Z_STREAM_ERROR;
  77521. #else
  77522. deflate_state *ds;
  77523. deflate_state *ss;
  77524. ushf *overlay;
  77525. if (source == Z_NULL || dest == Z_NULL || source->state == Z_NULL) {
  77526. return Z_STREAM_ERROR;
  77527. }
  77528. ss = source->state;
  77529. zmemcpy(dest, source, sizeof(z_stream));
  77530. ds = (deflate_state *) ZALLOC(dest, 1, sizeof(deflate_state));
  77531. if (ds == Z_NULL) return Z_MEM_ERROR;
  77532. dest->state = (struct internal_state FAR *) ds;
  77533. zmemcpy(ds, ss, sizeof(deflate_state));
  77534. ds->strm = dest;
  77535. ds->window = (Bytef *) ZALLOC(dest, ds->w_size, 2*sizeof(Byte));
  77536. ds->prev = (Posf *) ZALLOC(dest, ds->w_size, sizeof(Pos));
  77537. ds->head = (Posf *) ZALLOC(dest, ds->hash_size, sizeof(Pos));
  77538. overlay = (ushf *) ZALLOC(dest, ds->lit_bufsize, sizeof(ush)+2);
  77539. ds->pending_buf = (uchf *) overlay;
  77540. if (ds->window == Z_NULL || ds->prev == Z_NULL || ds->head == Z_NULL ||
  77541. ds->pending_buf == Z_NULL) {
  77542. deflateEnd (dest);
  77543. return Z_MEM_ERROR;
  77544. }
  77545. zmemcpy(ds->window, ss->window, ds->w_size * 2 * sizeof(Byte));
  77546. zmemcpy(ds->prev, ss->prev, ds->w_size * sizeof(Pos));
  77547. zmemcpy(ds->head, ss->head, ds->hash_size * sizeof(Pos));
  77548. zmemcpy(ds->pending_buf, ss->pending_buf, (uInt)ds->pending_buf_size);
  77549. ds->pending_out = ds->pending_buf + (ss->pending_out - ss->pending_buf);
  77550. ds->d_buf = overlay + ds->lit_bufsize/sizeof(ush);
  77551. ds->l_buf = ds->pending_buf + (1+sizeof(ush))*ds->lit_bufsize;
  77552. ds->l_desc.dyn_tree = ds->dyn_ltree;
  77553. ds->d_desc.dyn_tree = ds->dyn_dtree;
  77554. ds->bl_desc.dyn_tree = ds->bl_tree;
  77555. return Z_OK;
  77556. #endif /* MAXSEG_64K */
  77557. }
  77558. local int read_buf (z_streamp strm, Bytef *buf, unsigned size)
  77559. {
  77560. unsigned len = strm->avail_in;
  77561. if (len > size) len = size;
  77562. if (len == 0) return 0;
  77563. strm->avail_in -= len;
  77564. if (strm->state->wrap == 1) {
  77565. strm->adler = adler32(strm->adler, strm->next_in, len);
  77566. }
  77567. #ifdef GZIP
  77568. else if (strm->state->wrap == 2) {
  77569. strm->adler = crc32(strm->adler, strm->next_in, len);
  77570. }
  77571. #endif
  77572. zmemcpy(buf, strm->next_in, len);
  77573. strm->next_in += len;
  77574. strm->total_in += len;
  77575. return (int)len;
  77576. }
  77577. local void lm_init (deflate_state *s)
  77578. {
  77579. s->window_size = (ulg)2L*s->w_size;
  77580. CLEAR_HASH(s);
  77581. s->max_lazy_match = configuration_table[s->level].max_lazy;
  77582. s->good_match = configuration_table[s->level].good_length;
  77583. s->nice_match = configuration_table[s->level].nice_length;
  77584. s->max_chain_length = configuration_table[s->level].max_chain;
  77585. s->strstart = 0;
  77586. s->block_start = 0L;
  77587. s->lookahead = 0;
  77588. s->match_length = s->prev_length = MIN_MATCH-1;
  77589. s->match_available = 0;
  77590. s->ins_h = 0;
  77591. #ifndef FASTEST
  77592. #ifdef ASMV
  77593. match_init(); /* initialize the asm code */
  77594. #endif
  77595. #endif
  77596. }
  77597. #ifndef FASTEST
  77598. #ifndef ASMV
  77599. local uInt longest_match(deflate_state *s, IPos cur_match)
  77600. {
  77601. unsigned chain_length = s->max_chain_length;/* max hash chain length */
  77602. register Bytef *scan = s->window + s->strstart; /* current string */
  77603. register Bytef *match; /* matched string */
  77604. register int len; /* length of current match */
  77605. int best_len = s->prev_length; /* best match length so far */
  77606. int nice_match = s->nice_match; /* stop if match long enough */
  77607. IPos limit = s->strstart > (IPos)MAX_DIST(s) ?
  77608. s->strstart - (IPos)MAX_DIST(s) : NIL;
  77609. Posf *prev = s->prev;
  77610. uInt wmask = s->w_mask;
  77611. #ifdef UNALIGNED_OK
  77612. register Bytef *strend = s->window + s->strstart + MAX_MATCH - 1;
  77613. register ush scan_start = *(ushf*)scan;
  77614. register ush scan_end = *(ushf*)(scan+best_len-1);
  77615. #else
  77616. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77617. register Byte scan_end1 = scan[best_len-1];
  77618. register Byte scan_end = scan[best_len];
  77619. #endif
  77620. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77621. if (s->prev_length >= s->good_match) {
  77622. chain_length >>= 2;
  77623. }
  77624. if ((uInt)nice_match > s->lookahead) nice_match = s->lookahead;
  77625. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77626. do {
  77627. Assert(cur_match < s->strstart, "no future");
  77628. match = s->window + cur_match;
  77629. #if (defined(UNALIGNED_OK) && MAX_MATCH == 258)
  77630. if (*(ushf*)(match+best_len-1) != scan_end ||
  77631. *(ushf*)match != scan_start) continue;
  77632. Assert(scan[2] == match[2], "scan[2]?");
  77633. scan++, match++;
  77634. do {
  77635. } while (*(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77636. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77637. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77638. *(ushf*)(scan+=2) == *(ushf*)(match+=2) &&
  77639. scan < strend);
  77640. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77641. if (*scan == *match) scan++;
  77642. len = (MAX_MATCH - 1) - (int)(strend-scan);
  77643. scan = strend - (MAX_MATCH-1);
  77644. #else /* UNALIGNED_OK */
  77645. if (match[best_len] != scan_end ||
  77646. match[best_len-1] != scan_end1 ||
  77647. *match != *scan ||
  77648. *++match != scan[1]) continue;
  77649. scan += 2, match++;
  77650. Assert(*scan == *match, "match[2]?");
  77651. do {
  77652. } while (*++scan == *++match && *++scan == *++match &&
  77653. *++scan == *++match && *++scan == *++match &&
  77654. *++scan == *++match && *++scan == *++match &&
  77655. *++scan == *++match && *++scan == *++match &&
  77656. scan < strend);
  77657. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77658. len = MAX_MATCH - (int)(strend - scan);
  77659. scan = strend - MAX_MATCH;
  77660. #endif /* UNALIGNED_OK */
  77661. if (len > best_len) {
  77662. s->match_start = cur_match;
  77663. best_len = len;
  77664. if (len >= nice_match) break;
  77665. #ifdef UNALIGNED_OK
  77666. scan_end = *(ushf*)(scan+best_len-1);
  77667. #else
  77668. scan_end1 = scan[best_len-1];
  77669. scan_end = scan[best_len];
  77670. #endif
  77671. }
  77672. } while ((cur_match = prev[cur_match & wmask]) > limit
  77673. && --chain_length != 0);
  77674. if ((uInt)best_len <= s->lookahead) return (uInt)best_len;
  77675. return s->lookahead;
  77676. }
  77677. #endif /* ASMV */
  77678. #endif /* FASTEST */
  77679. local uInt longest_match_fast (deflate_state *s, IPos cur_match)
  77680. {
  77681. register Bytef *scan = s->window + s->strstart; /* current string */
  77682. register Bytef *match; /* matched string */
  77683. register int len; /* length of current match */
  77684. register Bytef *strend = s->window + s->strstart + MAX_MATCH;
  77685. Assert(s->hash_bits >= 8 && MAX_MATCH == 258, "Code too clever");
  77686. Assert((ulg)s->strstart <= s->window_size-MIN_LOOKAHEAD, "need lookahead");
  77687. Assert(cur_match < s->strstart, "no future");
  77688. match = s->window + cur_match;
  77689. if (match[0] != scan[0] || match[1] != scan[1]) return MIN_MATCH-1;
  77690. scan += 2, match += 2;
  77691. Assert(*scan == *match, "match[2]?");
  77692. do {
  77693. } while (*++scan == *++match && *++scan == *++match &&
  77694. *++scan == *++match && *++scan == *++match &&
  77695. *++scan == *++match && *++scan == *++match &&
  77696. *++scan == *++match && *++scan == *++match &&
  77697. scan < strend);
  77698. Assert(scan <= s->window+(unsigned)(s->window_size-1), "wild scan");
  77699. len = MAX_MATCH - (int)(strend - scan);
  77700. if (len < MIN_MATCH) return MIN_MATCH - 1;
  77701. s->match_start = cur_match;
  77702. return (uInt)len <= s->lookahead ? (uInt)len : s->lookahead;
  77703. }
  77704. #ifdef DEBUG
  77705. local void check_match(deflate_state *s, IPos start, IPos match, int length)
  77706. {
  77707. if (zmemcmp(s->window + match,
  77708. s->window + start, length) != EQUAL) {
  77709. fprintf(stderr, " start %u, match %u, length %d\n",
  77710. start, match, length);
  77711. do {
  77712. fprintf(stderr, "%c%c", s->window[match++], s->window[start++]);
  77713. } while (--length != 0);
  77714. z_error("invalid match");
  77715. }
  77716. if (z_verbose > 1) {
  77717. fprintf(stderr,"\\[%d,%d]", start-match, length);
  77718. do { putc(s->window[start++], stderr); } while (--length != 0);
  77719. }
  77720. }
  77721. #else
  77722. # define check_match(s, start, match, length)
  77723. #endif /* DEBUG */
  77724. local void fill_window (deflate_state *s)
  77725. {
  77726. register unsigned n, m;
  77727. register Posf *p;
  77728. unsigned more; /* Amount of free space at the end of the window. */
  77729. uInt wsize = s->w_size;
  77730. do {
  77731. more = (unsigned)(s->window_size -(ulg)s->lookahead -(ulg)s->strstart);
  77732. if (sizeof(int) <= 2) {
  77733. if (more == 0 && s->strstart == 0 && s->lookahead == 0) {
  77734. more = wsize;
  77735. } else if (more == (unsigned)(-1)) {
  77736. more--;
  77737. }
  77738. }
  77739. if (s->strstart >= wsize+MAX_DIST(s)) {
  77740. zmemcpy(s->window, s->window+wsize, (unsigned)wsize);
  77741. s->match_start -= wsize;
  77742. s->strstart -= wsize; /* we now have strstart >= MAX_DIST */
  77743. s->block_start -= (long) wsize;
  77744. n = s->hash_size;
  77745. p = &s->head[n];
  77746. do {
  77747. m = *--p;
  77748. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77749. } while (--n);
  77750. n = wsize;
  77751. #ifndef FASTEST
  77752. p = &s->prev[n];
  77753. do {
  77754. m = *--p;
  77755. *p = (Pos)(m >= wsize ? m-wsize : NIL);
  77756. } while (--n);
  77757. #endif
  77758. more += wsize;
  77759. }
  77760. if (s->strm->avail_in == 0) return;
  77761. Assert(more >= 2, "more < 2");
  77762. n = read_buf(s->strm, s->window + s->strstart + s->lookahead, more);
  77763. s->lookahead += n;
  77764. if (s->lookahead >= MIN_MATCH) {
  77765. s->ins_h = s->window[s->strstart];
  77766. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77767. #if MIN_MATCH != 3
  77768. Call UPDATE_HASH() MIN_MATCH-3 more times
  77769. #endif
  77770. }
  77771. } while (s->lookahead < MIN_LOOKAHEAD && s->strm->avail_in != 0);
  77772. }
  77773. #define FLUSH_BLOCK_ONLY(s, eof) { \
  77774. _tr_flush_block(s, (s->block_start >= 0L ? \
  77775. (charf *)&s->window[(unsigned)s->block_start] : \
  77776. (charf *)Z_NULL), \
  77777. (ulg)((long)s->strstart - s->block_start), \
  77778. (eof)); \
  77779. s->block_start = s->strstart; \
  77780. flush_pending(s->strm); \
  77781. Tracev((stderr,"[FLUSH]")); \
  77782. }
  77783. #define FLUSH_BLOCK(s, eof) { \
  77784. FLUSH_BLOCK_ONLY(s, eof); \
  77785. if (s->strm->avail_out == 0) return (eof) ? finish_started : need_more; \
  77786. }
  77787. local block_state deflate_stored(deflate_state *s, int flush)
  77788. {
  77789. ulg max_block_size = 0xffff;
  77790. ulg max_start;
  77791. if (max_block_size > s->pending_buf_size - 5) {
  77792. max_block_size = s->pending_buf_size - 5;
  77793. }
  77794. for (;;) {
  77795. if (s->lookahead <= 1) {
  77796. Assert(s->strstart < s->w_size+MAX_DIST(s) ||
  77797. s->block_start >= (long)s->w_size, "slide too late");
  77798. fill_window(s);
  77799. if (s->lookahead == 0 && flush == Z_NO_FLUSH) return need_more;
  77800. if (s->lookahead == 0) break; /* flush the current block */
  77801. }
  77802. Assert(s->block_start >= 0L, "block gone");
  77803. s->strstart += s->lookahead;
  77804. s->lookahead = 0;
  77805. max_start = s->block_start + max_block_size;
  77806. if (s->strstart == 0 || (ulg)s->strstart >= max_start) {
  77807. s->lookahead = (uInt)(s->strstart - max_start);
  77808. s->strstart = (uInt)max_start;
  77809. FLUSH_BLOCK(s, 0);
  77810. }
  77811. if (s->strstart - (uInt)s->block_start >= MAX_DIST(s)) {
  77812. FLUSH_BLOCK(s, 0);
  77813. }
  77814. }
  77815. FLUSH_BLOCK(s, flush == Z_FINISH);
  77816. return flush == Z_FINISH ? finish_done : block_done;
  77817. }
  77818. local block_state deflate_fast(deflate_state *s, int flush)
  77819. {
  77820. IPos hash_head = NIL; /* head of the hash chain */
  77821. int bflush; /* set if current block must be flushed */
  77822. for (;;) {
  77823. if (s->lookahead < MIN_LOOKAHEAD) {
  77824. fill_window(s);
  77825. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77826. return need_more;
  77827. }
  77828. if (s->lookahead == 0) break; /* flush the current block */
  77829. }
  77830. if (s->lookahead >= MIN_MATCH) {
  77831. INSERT_STRING(s, s->strstart, hash_head);
  77832. }
  77833. if (hash_head != NIL && s->strstart - hash_head <= MAX_DIST(s)) {
  77834. #ifdef FASTEST
  77835. if ((s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) ||
  77836. (s->strategy == Z_RLE && s->strstart - hash_head == 1)) {
  77837. s->match_length = longest_match_fast (s, hash_head);
  77838. }
  77839. #else
  77840. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77841. s->match_length = longest_match (s, hash_head);
  77842. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77843. s->match_length = longest_match_fast (s, hash_head);
  77844. }
  77845. #endif
  77846. }
  77847. if (s->match_length >= MIN_MATCH) {
  77848. check_match(s, s->strstart, s->match_start, s->match_length);
  77849. _tr_tally_dist(s, s->strstart - s->match_start,
  77850. s->match_length - MIN_MATCH, bflush);
  77851. s->lookahead -= s->match_length;
  77852. #ifndef FASTEST
  77853. if (s->match_length <= s->max_insert_length &&
  77854. s->lookahead >= MIN_MATCH) {
  77855. s->match_length--; /* string at strstart already in table */
  77856. do {
  77857. s->strstart++;
  77858. INSERT_STRING(s, s->strstart, hash_head);
  77859. } while (--s->match_length != 0);
  77860. s->strstart++;
  77861. } else
  77862. #endif
  77863. {
  77864. s->strstart += s->match_length;
  77865. s->match_length = 0;
  77866. s->ins_h = s->window[s->strstart];
  77867. UPDATE_HASH(s, s->ins_h, s->window[s->strstart+1]);
  77868. #if MIN_MATCH != 3
  77869. Call UPDATE_HASH() MIN_MATCH-3 more times
  77870. #endif
  77871. }
  77872. } else {
  77873. Tracevv((stderr,"%c", s->window[s->strstart]));
  77874. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77875. s->lookahead--;
  77876. s->strstart++;
  77877. }
  77878. if (bflush) FLUSH_BLOCK(s, 0);
  77879. }
  77880. FLUSH_BLOCK(s, flush == Z_FINISH);
  77881. return flush == Z_FINISH ? finish_done : block_done;
  77882. }
  77883. #ifndef FASTEST
  77884. local block_state deflate_slow(deflate_state *s, int flush)
  77885. {
  77886. IPos hash_head = NIL; /* head of hash chain */
  77887. int bflush; /* set if current block must be flushed */
  77888. for (;;) {
  77889. if (s->lookahead < MIN_LOOKAHEAD) {
  77890. fill_window(s);
  77891. if (s->lookahead < MIN_LOOKAHEAD && flush == Z_NO_FLUSH) {
  77892. return need_more;
  77893. }
  77894. if (s->lookahead == 0) break; /* flush the current block */
  77895. }
  77896. if (s->lookahead >= MIN_MATCH) {
  77897. INSERT_STRING(s, s->strstart, hash_head);
  77898. }
  77899. s->prev_length = s->match_length, s->prev_match = s->match_start;
  77900. s->match_length = MIN_MATCH-1;
  77901. if (hash_head != NIL && s->prev_length < s->max_lazy_match &&
  77902. s->strstart - hash_head <= MAX_DIST(s)) {
  77903. if (s->strategy != Z_HUFFMAN_ONLY && s->strategy != Z_RLE) {
  77904. s->match_length = longest_match (s, hash_head);
  77905. } else if (s->strategy == Z_RLE && s->strstart - hash_head == 1) {
  77906. s->match_length = longest_match_fast (s, hash_head);
  77907. }
  77908. if (s->match_length <= 5 && (s->strategy == Z_FILTERED
  77909. #if TOO_FAR <= 32767
  77910. || (s->match_length == MIN_MATCH &&
  77911. s->strstart - s->match_start > TOO_FAR)
  77912. #endif
  77913. )) {
  77914. s->match_length = MIN_MATCH-1;
  77915. }
  77916. }
  77917. if (s->prev_length >= MIN_MATCH && s->match_length <= s->prev_length) {
  77918. uInt max_insert = s->strstart + s->lookahead - MIN_MATCH;
  77919. check_match(s, s->strstart-1, s->prev_match, s->prev_length);
  77920. _tr_tally_dist(s, s->strstart -1 - s->prev_match,
  77921. s->prev_length - MIN_MATCH, bflush);
  77922. s->lookahead -= s->prev_length-1;
  77923. s->prev_length -= 2;
  77924. do {
  77925. if (++s->strstart <= max_insert) {
  77926. INSERT_STRING(s, s->strstart, hash_head);
  77927. }
  77928. } while (--s->prev_length != 0);
  77929. s->match_available = 0;
  77930. s->match_length = MIN_MATCH-1;
  77931. s->strstart++;
  77932. if (bflush) FLUSH_BLOCK(s, 0);
  77933. } else if (s->match_available) {
  77934. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77935. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77936. if (bflush) {
  77937. FLUSH_BLOCK_ONLY(s, 0);
  77938. }
  77939. s->strstart++;
  77940. s->lookahead--;
  77941. if (s->strm->avail_out == 0) return need_more;
  77942. } else {
  77943. s->match_available = 1;
  77944. s->strstart++;
  77945. s->lookahead--;
  77946. }
  77947. }
  77948. Assert (flush != Z_NO_FLUSH, "no flush?");
  77949. if (s->match_available) {
  77950. Tracevv((stderr,"%c", s->window[s->strstart-1]));
  77951. _tr_tally_lit(s, s->window[s->strstart-1], bflush);
  77952. s->match_available = 0;
  77953. }
  77954. FLUSH_BLOCK(s, flush == Z_FINISH);
  77955. return flush == Z_FINISH ? finish_done : block_done;
  77956. }
  77957. #endif /* FASTEST */
  77958. #if 0
  77959. local block_state deflate_rle(s, flush)
  77960. deflate_state *s;
  77961. int flush;
  77962. {
  77963. int bflush; /* set if current block must be flushed */
  77964. uInt run; /* length of run */
  77965. uInt max; /* maximum length of run */
  77966. uInt prev; /* byte at distance one to match */
  77967. Bytef *scan; /* scan for end of run */
  77968. for (;;) {
  77969. if (s->lookahead < MAX_MATCH) {
  77970. fill_window(s);
  77971. if (s->lookahead < MAX_MATCH && flush == Z_NO_FLUSH) {
  77972. return need_more;
  77973. }
  77974. if (s->lookahead == 0) break; /* flush the current block */
  77975. }
  77976. run = 0;
  77977. if (s->strstart > 0) { /* if there is a previous byte, that is */
  77978. max = s->lookahead < MAX_MATCH ? s->lookahead : MAX_MATCH;
  77979. scan = s->window + s->strstart - 1;
  77980. prev = *scan++;
  77981. do {
  77982. if (*scan++ != prev)
  77983. break;
  77984. } while (++run < max);
  77985. }
  77986. if (run >= MIN_MATCH) {
  77987. check_match(s, s->strstart, s->strstart - 1, run);
  77988. _tr_tally_dist(s, 1, run - MIN_MATCH, bflush);
  77989. s->lookahead -= run;
  77990. s->strstart += run;
  77991. } else {
  77992. Tracevv((stderr,"%c", s->window[s->strstart]));
  77993. _tr_tally_lit (s, s->window[s->strstart], bflush);
  77994. s->lookahead--;
  77995. s->strstart++;
  77996. }
  77997. if (bflush) FLUSH_BLOCK(s, 0);
  77998. }
  77999. FLUSH_BLOCK(s, flush == Z_FINISH);
  78000. return flush == Z_FINISH ? finish_done : block_done;
  78001. }
  78002. #endif
  78003. /*** End of inlined file: deflate.c ***/
  78004. /*** Start of inlined file: inffast.c ***/
  78005. /*** Start of inlined file: inftrees.h ***/
  78006. #ifndef _INFTREES_H_
  78007. #define _INFTREES_H_
  78008. typedef struct {
  78009. unsigned char op; /* operation, extra bits, table bits */
  78010. unsigned char bits; /* bits in this part of the code */
  78011. unsigned short val; /* offset in table or code value */
  78012. } code;
  78013. #define ENOUGH 2048
  78014. #define MAXD 592
  78015. typedef enum {
  78016. CODES,
  78017. LENS,
  78018. DISTS
  78019. } codetype;
  78020. extern int inflate_table OF((codetype type, unsigned short FAR *lens,
  78021. unsigned codes, code FAR * FAR *table,
  78022. unsigned FAR *bits, unsigned short FAR *work));
  78023. #endif
  78024. /*** End of inlined file: inftrees.h ***/
  78025. /*** Start of inlined file: inflate.h ***/
  78026. #ifndef _INFLATE_H_
  78027. #define _INFLATE_H_
  78028. #ifndef NO_GZIP
  78029. # define GUNZIP
  78030. #endif
  78031. typedef enum {
  78032. HEAD, /* i: waiting for magic header */
  78033. FLAGS, /* i: waiting for method and flags (gzip) */
  78034. TIME, /* i: waiting for modification time (gzip) */
  78035. OS, /* i: waiting for extra flags and operating system (gzip) */
  78036. EXLEN, /* i: waiting for extra length (gzip) */
  78037. EXTRA, /* i: waiting for extra bytes (gzip) */
  78038. NAME, /* i: waiting for end of file name (gzip) */
  78039. COMMENT, /* i: waiting for end of comment (gzip) */
  78040. HCRC, /* i: waiting for header crc (gzip) */
  78041. DICTID, /* i: waiting for dictionary check value */
  78042. DICT, /* waiting for inflateSetDictionary() call */
  78043. TYPE, /* i: waiting for type bits, including last-flag bit */
  78044. TYPEDO, /* i: same, but skip check to exit inflate on new block */
  78045. STORED, /* i: waiting for stored size (length and complement) */
  78046. COPY, /* i/o: waiting for input or output to copy stored block */
  78047. TABLE, /* i: waiting for dynamic block table lengths */
  78048. LENLENS, /* i: waiting for code length code lengths */
  78049. CODELENS, /* i: waiting for length/lit and distance code lengths */
  78050. LEN, /* i: waiting for length/lit code */
  78051. LENEXT, /* i: waiting for length extra bits */
  78052. DIST, /* i: waiting for distance code */
  78053. DISTEXT, /* i: waiting for distance extra bits */
  78054. MATCH, /* o: waiting for output space to copy string */
  78055. LIT, /* o: waiting for output space to write literal */
  78056. CHECK, /* i: waiting for 32-bit check value */
  78057. LENGTH, /* i: waiting for 32-bit length (gzip) */
  78058. DONE, /* finished check, done -- remain here until reset */
  78059. BAD, /* got a data error -- remain here until reset */
  78060. MEM, /* got an inflate() memory error -- remain here until reset */
  78061. SYNC /* looking for synchronization bytes to restart inflate() */
  78062. } inflate_mode;
  78063. struct inflate_state {
  78064. inflate_mode mode; /* current inflate mode */
  78065. int last; /* true if processing last block */
  78066. int wrap; /* bit 0 true for zlib, bit 1 true for gzip */
  78067. int havedict; /* true if dictionary provided */
  78068. int flags; /* gzip header method and flags (0 if zlib) */
  78069. unsigned dmax; /* zlib header max distance (INFLATE_STRICT) */
  78070. unsigned long check; /* protected copy of check value */
  78071. unsigned long total; /* protected copy of output count */
  78072. gz_headerp head; /* where to save gzip header information */
  78073. unsigned wbits; /* log base 2 of requested window size */
  78074. unsigned wsize; /* window size or zero if not using window */
  78075. unsigned whave; /* valid bytes in the window */
  78076. unsigned write; /* window write index */
  78077. unsigned char FAR *window; /* allocated sliding window, if needed */
  78078. unsigned long hold; /* input bit accumulator */
  78079. unsigned bits; /* number of bits in "in" */
  78080. unsigned length; /* literal or length of data to copy */
  78081. unsigned offset; /* distance back to copy string from */
  78082. unsigned extra; /* extra bits needed */
  78083. code const FAR *lencode; /* starting table for length/literal codes */
  78084. code const FAR *distcode; /* starting table for distance codes */
  78085. unsigned lenbits; /* index bits for lencode */
  78086. unsigned distbits; /* index bits for distcode */
  78087. unsigned ncode; /* number of code length code lengths */
  78088. unsigned nlen; /* number of length code lengths */
  78089. unsigned ndist; /* number of distance code lengths */
  78090. unsigned have; /* number of code lengths in lens[] */
  78091. code FAR *next; /* next available space in codes[] */
  78092. unsigned short lens[320]; /* temporary storage for code lengths */
  78093. unsigned short work[288]; /* work area for code table building */
  78094. code codes[ENOUGH]; /* space for code tables */
  78095. };
  78096. #endif
  78097. /*** End of inlined file: inflate.h ***/
  78098. /*** Start of inlined file: inffast.h ***/
  78099. void inflate_fast OF((z_streamp strm, unsigned start));
  78100. /*** End of inlined file: inffast.h ***/
  78101. #ifndef ASMINF
  78102. #ifdef POSTINC
  78103. # define OFF 0
  78104. # define PUP(a) *(a)++
  78105. #else
  78106. # define OFF 1
  78107. # define PUP(a) *++(a)
  78108. #endif
  78109. void inflate_fast (z_streamp strm, unsigned start)
  78110. {
  78111. struct inflate_state FAR *state;
  78112. unsigned char FAR *in; /* local strm->next_in */
  78113. unsigned char FAR *last; /* while in < last, enough input available */
  78114. unsigned char FAR *out; /* local strm->next_out */
  78115. unsigned char FAR *beg; /* inflate()'s initial strm->next_out */
  78116. unsigned char FAR *end; /* while out < end, enough space available */
  78117. #ifdef INFLATE_STRICT
  78118. unsigned dmax; /* maximum distance from zlib header */
  78119. #endif
  78120. unsigned wsize; /* window size or zero if not using window */
  78121. unsigned whave; /* valid bytes in the window */
  78122. unsigned write; /* window write index */
  78123. unsigned char FAR *window; /* allocated sliding window, if wsize != 0 */
  78124. unsigned long hold; /* local strm->hold */
  78125. unsigned bits; /* local strm->bits */
  78126. code const FAR *lcode; /* local strm->lencode */
  78127. code const FAR *dcode; /* local strm->distcode */
  78128. unsigned lmask; /* mask for first level of length codes */
  78129. unsigned dmask; /* mask for first level of distance codes */
  78130. code thisx; /* retrieved table entry */
  78131. unsigned op; /* code bits, operation, extra bits, or */
  78132. unsigned len; /* match length, unused bytes */
  78133. unsigned dist; /* match distance */
  78134. unsigned char FAR *from; /* where to copy match from */
  78135. state = (struct inflate_state FAR *)strm->state;
  78136. in = strm->next_in - OFF;
  78137. last = in + (strm->avail_in - 5);
  78138. out = strm->next_out - OFF;
  78139. beg = out - (start - strm->avail_out);
  78140. end = out + (strm->avail_out - 257);
  78141. #ifdef INFLATE_STRICT
  78142. dmax = state->dmax;
  78143. #endif
  78144. wsize = state->wsize;
  78145. whave = state->whave;
  78146. write = state->write;
  78147. window = state->window;
  78148. hold = state->hold;
  78149. bits = state->bits;
  78150. lcode = state->lencode;
  78151. dcode = state->distcode;
  78152. lmask = (1U << state->lenbits) - 1;
  78153. dmask = (1U << state->distbits) - 1;
  78154. do {
  78155. if (bits < 15) {
  78156. hold += (unsigned long)(PUP(in)) << bits;
  78157. bits += 8;
  78158. hold += (unsigned long)(PUP(in)) << bits;
  78159. bits += 8;
  78160. }
  78161. thisx = lcode[hold & lmask];
  78162. dolen:
  78163. op = (unsigned)(thisx.bits);
  78164. hold >>= op;
  78165. bits -= op;
  78166. op = (unsigned)(thisx.op);
  78167. if (op == 0) { /* literal */
  78168. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  78169. "inflate: literal '%c'\n" :
  78170. "inflate: literal 0x%02x\n", thisx.val));
  78171. PUP(out) = (unsigned char)(thisx.val);
  78172. }
  78173. else if (op & 16) { /* length base */
  78174. len = (unsigned)(thisx.val);
  78175. op &= 15; /* number of extra bits */
  78176. if (op) {
  78177. if (bits < op) {
  78178. hold += (unsigned long)(PUP(in)) << bits;
  78179. bits += 8;
  78180. }
  78181. len += (unsigned)hold & ((1U << op) - 1);
  78182. hold >>= op;
  78183. bits -= op;
  78184. }
  78185. Tracevv((stderr, "inflate: length %u\n", len));
  78186. if (bits < 15) {
  78187. hold += (unsigned long)(PUP(in)) << bits;
  78188. bits += 8;
  78189. hold += (unsigned long)(PUP(in)) << bits;
  78190. bits += 8;
  78191. }
  78192. thisx = dcode[hold & dmask];
  78193. dodist:
  78194. op = (unsigned)(thisx.bits);
  78195. hold >>= op;
  78196. bits -= op;
  78197. op = (unsigned)(thisx.op);
  78198. if (op & 16) { /* distance base */
  78199. dist = (unsigned)(thisx.val);
  78200. op &= 15; /* number of extra bits */
  78201. if (bits < op) {
  78202. hold += (unsigned long)(PUP(in)) << bits;
  78203. bits += 8;
  78204. if (bits < op) {
  78205. hold += (unsigned long)(PUP(in)) << bits;
  78206. bits += 8;
  78207. }
  78208. }
  78209. dist += (unsigned)hold & ((1U << op) - 1);
  78210. #ifdef INFLATE_STRICT
  78211. if (dist > dmax) {
  78212. strm->msg = (char *)"invalid distance too far back";
  78213. state->mode = BAD;
  78214. break;
  78215. }
  78216. #endif
  78217. hold >>= op;
  78218. bits -= op;
  78219. Tracevv((stderr, "inflate: distance %u\n", dist));
  78220. op = (unsigned)(out - beg); /* max distance in output */
  78221. if (dist > op) { /* see if copy from window */
  78222. op = dist - op; /* distance back in window */
  78223. if (op > whave) {
  78224. strm->msg = (char *)"invalid distance too far back";
  78225. state->mode = BAD;
  78226. break;
  78227. }
  78228. from = window - OFF;
  78229. if (write == 0) { /* very common case */
  78230. from += wsize - op;
  78231. if (op < len) { /* some from window */
  78232. len -= op;
  78233. do {
  78234. PUP(out) = PUP(from);
  78235. } while (--op);
  78236. from = out - dist; /* rest from output */
  78237. }
  78238. }
  78239. else if (write < op) { /* wrap around window */
  78240. from += wsize + write - op;
  78241. op -= write;
  78242. if (op < len) { /* some from end of window */
  78243. len -= op;
  78244. do {
  78245. PUP(out) = PUP(from);
  78246. } while (--op);
  78247. from = window - OFF;
  78248. if (write < len) { /* some from start of window */
  78249. op = write;
  78250. len -= op;
  78251. do {
  78252. PUP(out) = PUP(from);
  78253. } while (--op);
  78254. from = out - dist; /* rest from output */
  78255. }
  78256. }
  78257. }
  78258. else { /* contiguous in window */
  78259. from += write - op;
  78260. if (op < len) { /* some from window */
  78261. len -= op;
  78262. do {
  78263. PUP(out) = PUP(from);
  78264. } while (--op);
  78265. from = out - dist; /* rest from output */
  78266. }
  78267. }
  78268. while (len > 2) {
  78269. PUP(out) = PUP(from);
  78270. PUP(out) = PUP(from);
  78271. PUP(out) = PUP(from);
  78272. len -= 3;
  78273. }
  78274. if (len) {
  78275. PUP(out) = PUP(from);
  78276. if (len > 1)
  78277. PUP(out) = PUP(from);
  78278. }
  78279. }
  78280. else {
  78281. from = out - dist; /* copy direct from output */
  78282. do { /* minimum length is three */
  78283. PUP(out) = PUP(from);
  78284. PUP(out) = PUP(from);
  78285. PUP(out) = PUP(from);
  78286. len -= 3;
  78287. } while (len > 2);
  78288. if (len) {
  78289. PUP(out) = PUP(from);
  78290. if (len > 1)
  78291. PUP(out) = PUP(from);
  78292. }
  78293. }
  78294. }
  78295. else if ((op & 64) == 0) { /* 2nd level distance code */
  78296. thisx = dcode[thisx.val + (hold & ((1U << op) - 1))];
  78297. goto dodist;
  78298. }
  78299. else {
  78300. strm->msg = (char *)"invalid distance code";
  78301. state->mode = BAD;
  78302. break;
  78303. }
  78304. }
  78305. else if ((op & 64) == 0) { /* 2nd level length code */
  78306. thisx = lcode[thisx.val + (hold & ((1U << op) - 1))];
  78307. goto dolen;
  78308. }
  78309. else if (op & 32) { /* end-of-block */
  78310. Tracevv((stderr, "inflate: end of block\n"));
  78311. state->mode = TYPE;
  78312. break;
  78313. }
  78314. else {
  78315. strm->msg = (char *)"invalid literal/length code";
  78316. state->mode = BAD;
  78317. break;
  78318. }
  78319. } while (in < last && out < end);
  78320. len = bits >> 3;
  78321. in -= len;
  78322. bits -= len << 3;
  78323. hold &= (1U << bits) - 1;
  78324. strm->next_in = in + OFF;
  78325. strm->next_out = out + OFF;
  78326. strm->avail_in = (unsigned)(in < last ? 5 + (last - in) : 5 - (in - last));
  78327. strm->avail_out = (unsigned)(out < end ?
  78328. 257 + (end - out) : 257 - (out - end));
  78329. state->hold = hold;
  78330. state->bits = bits;
  78331. return;
  78332. }
  78333. #endif /* !ASMINF */
  78334. /*** End of inlined file: inffast.c ***/
  78335. #undef PULLBYTE
  78336. #undef LOAD
  78337. #undef RESTORE
  78338. #undef INITBITS
  78339. #undef NEEDBITS
  78340. #undef DROPBITS
  78341. #undef BYTEBITS
  78342. /*** Start of inlined file: inflate.c ***/
  78343. /*** Start of inlined file: inffast.h ***/
  78344. void inflate_fast OF((z_streamp strm, unsigned start));
  78345. /*** End of inlined file: inffast.h ***/
  78346. #ifdef MAKEFIXED
  78347. # ifndef BUILDFIXED
  78348. # define BUILDFIXED
  78349. # endif
  78350. #endif
  78351. local void fixedtables OF((struct inflate_state FAR *state));
  78352. local int updatewindow OF((z_streamp strm, unsigned out));
  78353. #ifdef BUILDFIXED
  78354. void makefixed OF((void));
  78355. #endif
  78356. local unsigned syncsearch OF((unsigned FAR *have, unsigned char FAR *buf,
  78357. unsigned len));
  78358. int ZEXPORT inflateReset (z_streamp strm)
  78359. {
  78360. struct inflate_state FAR *state;
  78361. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78362. state = (struct inflate_state FAR *)strm->state;
  78363. strm->total_in = strm->total_out = state->total = 0;
  78364. strm->msg = Z_NULL;
  78365. strm->adler = 1; /* to support ill-conceived Java test suite */
  78366. state->mode = HEAD;
  78367. state->last = 0;
  78368. state->havedict = 0;
  78369. state->dmax = 32768U;
  78370. state->head = Z_NULL;
  78371. state->wsize = 0;
  78372. state->whave = 0;
  78373. state->write = 0;
  78374. state->hold = 0;
  78375. state->bits = 0;
  78376. state->lencode = state->distcode = state->next = state->codes;
  78377. Tracev((stderr, "inflate: reset\n"));
  78378. return Z_OK;
  78379. }
  78380. int ZEXPORT inflatePrime (z_streamp strm, int bits, int value)
  78381. {
  78382. struct inflate_state FAR *state;
  78383. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  78384. state = (struct inflate_state FAR *)strm->state;
  78385. if (bits > 16 || state->bits + bits > 32) return Z_STREAM_ERROR;
  78386. value &= (1L << bits) - 1;
  78387. state->hold += value << state->bits;
  78388. state->bits += bits;
  78389. return Z_OK;
  78390. }
  78391. int ZEXPORT inflateInit2_(z_streamp strm, int windowBits, const char *version, int stream_size)
  78392. {
  78393. struct inflate_state FAR *state;
  78394. if (version == Z_NULL || version[0] != ZLIB_VERSION[0] ||
  78395. stream_size != (int)(sizeof(z_stream)))
  78396. return Z_VERSION_ERROR;
  78397. if (strm == Z_NULL) return Z_STREAM_ERROR;
  78398. strm->msg = Z_NULL; /* in case we return an error */
  78399. if (strm->zalloc == (alloc_func)0) {
  78400. strm->zalloc = zcalloc;
  78401. strm->opaque = (voidpf)0;
  78402. }
  78403. if (strm->zfree == (free_func)0) strm->zfree = zcfree;
  78404. state = (struct inflate_state FAR *)
  78405. ZALLOC(strm, 1, sizeof(struct inflate_state));
  78406. if (state == Z_NULL) return Z_MEM_ERROR;
  78407. Tracev((stderr, "inflate: allocated\n"));
  78408. strm->state = (struct internal_state FAR *)state;
  78409. if (windowBits < 0) {
  78410. state->wrap = 0;
  78411. windowBits = -windowBits;
  78412. }
  78413. else {
  78414. state->wrap = (windowBits >> 4) + 1;
  78415. #ifdef GUNZIP
  78416. if (windowBits < 48) windowBits &= 15;
  78417. #endif
  78418. }
  78419. if (windowBits < 8 || windowBits > 15) {
  78420. ZFREE(strm, state);
  78421. strm->state = Z_NULL;
  78422. return Z_STREAM_ERROR;
  78423. }
  78424. state->wbits = (unsigned)windowBits;
  78425. state->window = Z_NULL;
  78426. return inflateReset(strm);
  78427. }
  78428. int ZEXPORT inflateInit_ (z_streamp strm, const char *version, int stream_size)
  78429. {
  78430. return inflateInit2_(strm, DEF_WBITS, version, stream_size);
  78431. }
  78432. local void fixedtables (struct inflate_state FAR *state)
  78433. {
  78434. #ifdef BUILDFIXED
  78435. static int virgin = 1;
  78436. static code *lenfix, *distfix;
  78437. static code fixed[544];
  78438. if (virgin) {
  78439. unsigned sym, bits;
  78440. static code *next;
  78441. sym = 0;
  78442. while (sym < 144) state->lens[sym++] = 8;
  78443. while (sym < 256) state->lens[sym++] = 9;
  78444. while (sym < 280) state->lens[sym++] = 7;
  78445. while (sym < 288) state->lens[sym++] = 8;
  78446. next = fixed;
  78447. lenfix = next;
  78448. bits = 9;
  78449. inflate_table(LENS, state->lens, 288, &(next), &(bits), state->work);
  78450. sym = 0;
  78451. while (sym < 32) state->lens[sym++] = 5;
  78452. distfix = next;
  78453. bits = 5;
  78454. inflate_table(DISTS, state->lens, 32, &(next), &(bits), state->work);
  78455. virgin = 0;
  78456. }
  78457. #else /* !BUILDFIXED */
  78458. /*** Start of inlined file: inffixed.h ***/
  78459. static const code lenfix[512] = {
  78460. {96,7,0},{0,8,80},{0,8,16},{20,8,115},{18,7,31},{0,8,112},{0,8,48},
  78461. {0,9,192},{16,7,10},{0,8,96},{0,8,32},{0,9,160},{0,8,0},{0,8,128},
  78462. {0,8,64},{0,9,224},{16,7,6},{0,8,88},{0,8,24},{0,9,144},{19,7,59},
  78463. {0,8,120},{0,8,56},{0,9,208},{17,7,17},{0,8,104},{0,8,40},{0,9,176},
  78464. {0,8,8},{0,8,136},{0,8,72},{0,9,240},{16,7,4},{0,8,84},{0,8,20},
  78465. {21,8,227},{19,7,43},{0,8,116},{0,8,52},{0,9,200},{17,7,13},{0,8,100},
  78466. {0,8,36},{0,9,168},{0,8,4},{0,8,132},{0,8,68},{0,9,232},{16,7,8},
  78467. {0,8,92},{0,8,28},{0,9,152},{20,7,83},{0,8,124},{0,8,60},{0,9,216},
  78468. {18,7,23},{0,8,108},{0,8,44},{0,9,184},{0,8,12},{0,8,140},{0,8,76},
  78469. {0,9,248},{16,7,3},{0,8,82},{0,8,18},{21,8,163},{19,7,35},{0,8,114},
  78470. {0,8,50},{0,9,196},{17,7,11},{0,8,98},{0,8,34},{0,9,164},{0,8,2},
  78471. {0,8,130},{0,8,66},{0,9,228},{16,7,7},{0,8,90},{0,8,26},{0,9,148},
  78472. {20,7,67},{0,8,122},{0,8,58},{0,9,212},{18,7,19},{0,8,106},{0,8,42},
  78473. {0,9,180},{0,8,10},{0,8,138},{0,8,74},{0,9,244},{16,7,5},{0,8,86},
  78474. {0,8,22},{64,8,0},{19,7,51},{0,8,118},{0,8,54},{0,9,204},{17,7,15},
  78475. {0,8,102},{0,8,38},{0,9,172},{0,8,6},{0,8,134},{0,8,70},{0,9,236},
  78476. {16,7,9},{0,8,94},{0,8,30},{0,9,156},{20,7,99},{0,8,126},{0,8,62},
  78477. {0,9,220},{18,7,27},{0,8,110},{0,8,46},{0,9,188},{0,8,14},{0,8,142},
  78478. {0,8,78},{0,9,252},{96,7,0},{0,8,81},{0,8,17},{21,8,131},{18,7,31},
  78479. {0,8,113},{0,8,49},{0,9,194},{16,7,10},{0,8,97},{0,8,33},{0,9,162},
  78480. {0,8,1},{0,8,129},{0,8,65},{0,9,226},{16,7,6},{0,8,89},{0,8,25},
  78481. {0,9,146},{19,7,59},{0,8,121},{0,8,57},{0,9,210},{17,7,17},{0,8,105},
  78482. {0,8,41},{0,9,178},{0,8,9},{0,8,137},{0,8,73},{0,9,242},{16,7,4},
  78483. {0,8,85},{0,8,21},{16,8,258},{19,7,43},{0,8,117},{0,8,53},{0,9,202},
  78484. {17,7,13},{0,8,101},{0,8,37},{0,9,170},{0,8,5},{0,8,133},{0,8,69},
  78485. {0,9,234},{16,7,8},{0,8,93},{0,8,29},{0,9,154},{20,7,83},{0,8,125},
  78486. {0,8,61},{0,9,218},{18,7,23},{0,8,109},{0,8,45},{0,9,186},{0,8,13},
  78487. {0,8,141},{0,8,77},{0,9,250},{16,7,3},{0,8,83},{0,8,19},{21,8,195},
  78488. {19,7,35},{0,8,115},{0,8,51},{0,9,198},{17,7,11},{0,8,99},{0,8,35},
  78489. {0,9,166},{0,8,3},{0,8,131},{0,8,67},{0,9,230},{16,7,7},{0,8,91},
  78490. {0,8,27},{0,9,150},{20,7,67},{0,8,123},{0,8,59},{0,9,214},{18,7,19},
  78491. {0,8,107},{0,8,43},{0,9,182},{0,8,11},{0,8,139},{0,8,75},{0,9,246},
  78492. {16,7,5},{0,8,87},{0,8,23},{64,8,0},{19,7,51},{0,8,119},{0,8,55},
  78493. {0,9,206},{17,7,15},{0,8,103},{0,8,39},{0,9,174},{0,8,7},{0,8,135},
  78494. {0,8,71},{0,9,238},{16,7,9},{0,8,95},{0,8,31},{0,9,158},{20,7,99},
  78495. {0,8,127},{0,8,63},{0,9,222},{18,7,27},{0,8,111},{0,8,47},{0,9,190},
  78496. {0,8,15},{0,8,143},{0,8,79},{0,9,254},{96,7,0},{0,8,80},{0,8,16},
  78497. {20,8,115},{18,7,31},{0,8,112},{0,8,48},{0,9,193},{16,7,10},{0,8,96},
  78498. {0,8,32},{0,9,161},{0,8,0},{0,8,128},{0,8,64},{0,9,225},{16,7,6},
  78499. {0,8,88},{0,8,24},{0,9,145},{19,7,59},{0,8,120},{0,8,56},{0,9,209},
  78500. {17,7,17},{0,8,104},{0,8,40},{0,9,177},{0,8,8},{0,8,136},{0,8,72},
  78501. {0,9,241},{16,7,4},{0,8,84},{0,8,20},{21,8,227},{19,7,43},{0,8,116},
  78502. {0,8,52},{0,9,201},{17,7,13},{0,8,100},{0,8,36},{0,9,169},{0,8,4},
  78503. {0,8,132},{0,8,68},{0,9,233},{16,7,8},{0,8,92},{0,8,28},{0,9,153},
  78504. {20,7,83},{0,8,124},{0,8,60},{0,9,217},{18,7,23},{0,8,108},{0,8,44},
  78505. {0,9,185},{0,8,12},{0,8,140},{0,8,76},{0,9,249},{16,7,3},{0,8,82},
  78506. {0,8,18},{21,8,163},{19,7,35},{0,8,114},{0,8,50},{0,9,197},{17,7,11},
  78507. {0,8,98},{0,8,34},{0,9,165},{0,8,2},{0,8,130},{0,8,66},{0,9,229},
  78508. {16,7,7},{0,8,90},{0,8,26},{0,9,149},{20,7,67},{0,8,122},{0,8,58},
  78509. {0,9,213},{18,7,19},{0,8,106},{0,8,42},{0,9,181},{0,8,10},{0,8,138},
  78510. {0,8,74},{0,9,245},{16,7,5},{0,8,86},{0,8,22},{64,8,0},{19,7,51},
  78511. {0,8,118},{0,8,54},{0,9,205},{17,7,15},{0,8,102},{0,8,38},{0,9,173},
  78512. {0,8,6},{0,8,134},{0,8,70},{0,9,237},{16,7,9},{0,8,94},{0,8,30},
  78513. {0,9,157},{20,7,99},{0,8,126},{0,8,62},{0,9,221},{18,7,27},{0,8,110},
  78514. {0,8,46},{0,9,189},{0,8,14},{0,8,142},{0,8,78},{0,9,253},{96,7,0},
  78515. {0,8,81},{0,8,17},{21,8,131},{18,7,31},{0,8,113},{0,8,49},{0,9,195},
  78516. {16,7,10},{0,8,97},{0,8,33},{0,9,163},{0,8,1},{0,8,129},{0,8,65},
  78517. {0,9,227},{16,7,6},{0,8,89},{0,8,25},{0,9,147},{19,7,59},{0,8,121},
  78518. {0,8,57},{0,9,211},{17,7,17},{0,8,105},{0,8,41},{0,9,179},{0,8,9},
  78519. {0,8,137},{0,8,73},{0,9,243},{16,7,4},{0,8,85},{0,8,21},{16,8,258},
  78520. {19,7,43},{0,8,117},{0,8,53},{0,9,203},{17,7,13},{0,8,101},{0,8,37},
  78521. {0,9,171},{0,8,5},{0,8,133},{0,8,69},{0,9,235},{16,7,8},{0,8,93},
  78522. {0,8,29},{0,9,155},{20,7,83},{0,8,125},{0,8,61},{0,9,219},{18,7,23},
  78523. {0,8,109},{0,8,45},{0,9,187},{0,8,13},{0,8,141},{0,8,77},{0,9,251},
  78524. {16,7,3},{0,8,83},{0,8,19},{21,8,195},{19,7,35},{0,8,115},{0,8,51},
  78525. {0,9,199},{17,7,11},{0,8,99},{0,8,35},{0,9,167},{0,8,3},{0,8,131},
  78526. {0,8,67},{0,9,231},{16,7,7},{0,8,91},{0,8,27},{0,9,151},{20,7,67},
  78527. {0,8,123},{0,8,59},{0,9,215},{18,7,19},{0,8,107},{0,8,43},{0,9,183},
  78528. {0,8,11},{0,8,139},{0,8,75},{0,9,247},{16,7,5},{0,8,87},{0,8,23},
  78529. {64,8,0},{19,7,51},{0,8,119},{0,8,55},{0,9,207},{17,7,15},{0,8,103},
  78530. {0,8,39},{0,9,175},{0,8,7},{0,8,135},{0,8,71},{0,9,239},{16,7,9},
  78531. {0,8,95},{0,8,31},{0,9,159},{20,7,99},{0,8,127},{0,8,63},{0,9,223},
  78532. {18,7,27},{0,8,111},{0,8,47},{0,9,191},{0,8,15},{0,8,143},{0,8,79},
  78533. {0,9,255}
  78534. };
  78535. static const code distfix[32] = {
  78536. {16,5,1},{23,5,257},{19,5,17},{27,5,4097},{17,5,5},{25,5,1025},
  78537. {21,5,65},{29,5,16385},{16,5,3},{24,5,513},{20,5,33},{28,5,8193},
  78538. {18,5,9},{26,5,2049},{22,5,129},{64,5,0},{16,5,2},{23,5,385},
  78539. {19,5,25},{27,5,6145},{17,5,7},{25,5,1537},{21,5,97},{29,5,24577},
  78540. {16,5,4},{24,5,769},{20,5,49},{28,5,12289},{18,5,13},{26,5,3073},
  78541. {22,5,193},{64,5,0}
  78542. };
  78543. /*** End of inlined file: inffixed.h ***/
  78544. #endif /* BUILDFIXED */
  78545. state->lencode = lenfix;
  78546. state->lenbits = 9;
  78547. state->distcode = distfix;
  78548. state->distbits = 5;
  78549. }
  78550. #ifdef MAKEFIXED
  78551. #include <stdio.h>
  78552. void makefixed()
  78553. {
  78554. unsigned low, size;
  78555. struct inflate_state state;
  78556. fixedtables(&state);
  78557. puts(" /* inffixed.h -- table for decoding fixed codes");
  78558. puts(" * Generated automatically by makefixed().");
  78559. puts(" */");
  78560. puts("");
  78561. puts(" /* WARNING: this file should *not* be used by applications.");
  78562. puts(" It is part of the implementation of this library and is");
  78563. puts(" subject to change. Applications should only use zlib.h.");
  78564. puts(" */");
  78565. puts("");
  78566. size = 1U << 9;
  78567. printf(" static const code lenfix[%u] = {", size);
  78568. low = 0;
  78569. for (;;) {
  78570. if ((low % 7) == 0) printf("\n ");
  78571. printf("{%u,%u,%d}", state.lencode[low].op, state.lencode[low].bits,
  78572. state.lencode[low].val);
  78573. if (++low == size) break;
  78574. putchar(',');
  78575. }
  78576. puts("\n };");
  78577. size = 1U << 5;
  78578. printf("\n static const code distfix[%u] = {", size);
  78579. low = 0;
  78580. for (;;) {
  78581. if ((low % 6) == 0) printf("\n ");
  78582. printf("{%u,%u,%d}", state.distcode[low].op, state.distcode[low].bits,
  78583. state.distcode[low].val);
  78584. if (++low == size) break;
  78585. putchar(',');
  78586. }
  78587. puts("\n };");
  78588. }
  78589. #endif /* MAKEFIXED */
  78590. local int updatewindow (z_streamp strm, unsigned out)
  78591. {
  78592. struct inflate_state FAR *state;
  78593. unsigned copy, dist;
  78594. state = (struct inflate_state FAR *)strm->state;
  78595. if (state->window == Z_NULL) {
  78596. state->window = (unsigned char FAR *)
  78597. ZALLOC(strm, 1U << state->wbits,
  78598. sizeof(unsigned char));
  78599. if (state->window == Z_NULL) return 1;
  78600. }
  78601. if (state->wsize == 0) {
  78602. state->wsize = 1U << state->wbits;
  78603. state->write = 0;
  78604. state->whave = 0;
  78605. }
  78606. copy = out - strm->avail_out;
  78607. if (copy >= state->wsize) {
  78608. zmemcpy(state->window, strm->next_out - state->wsize, state->wsize);
  78609. state->write = 0;
  78610. state->whave = state->wsize;
  78611. }
  78612. else {
  78613. dist = state->wsize - state->write;
  78614. if (dist > copy) dist = copy;
  78615. zmemcpy(state->window + state->write, strm->next_out - copy, dist);
  78616. copy -= dist;
  78617. if (copy) {
  78618. zmemcpy(state->window, strm->next_out - copy, copy);
  78619. state->write = copy;
  78620. state->whave = state->wsize;
  78621. }
  78622. else {
  78623. state->write += dist;
  78624. if (state->write == state->wsize) state->write = 0;
  78625. if (state->whave < state->wsize) state->whave += dist;
  78626. }
  78627. }
  78628. return 0;
  78629. }
  78630. #ifdef GUNZIP
  78631. # define UPDATE(check, buf, len) \
  78632. (state->flags ? crc32(check, buf, len) : adler32(check, buf, len))
  78633. #else
  78634. # define UPDATE(check, buf, len) adler32(check, buf, len)
  78635. #endif
  78636. #ifdef GUNZIP
  78637. # define CRC2(check, word) \
  78638. do { \
  78639. hbuf[0] = (unsigned char)(word); \
  78640. hbuf[1] = (unsigned char)((word) >> 8); \
  78641. check = crc32(check, hbuf, 2); \
  78642. } while (0)
  78643. # define CRC4(check, word) \
  78644. do { \
  78645. hbuf[0] = (unsigned char)(word); \
  78646. hbuf[1] = (unsigned char)((word) >> 8); \
  78647. hbuf[2] = (unsigned char)((word) >> 16); \
  78648. hbuf[3] = (unsigned char)((word) >> 24); \
  78649. check = crc32(check, hbuf, 4); \
  78650. } while (0)
  78651. #endif
  78652. #define LOAD() \
  78653. do { \
  78654. put = strm->next_out; \
  78655. left = strm->avail_out; \
  78656. next = strm->next_in; \
  78657. have = strm->avail_in; \
  78658. hold = state->hold; \
  78659. bits = state->bits; \
  78660. } while (0)
  78661. #define RESTORE() \
  78662. do { \
  78663. strm->next_out = put; \
  78664. strm->avail_out = left; \
  78665. strm->next_in = next; \
  78666. strm->avail_in = have; \
  78667. state->hold = hold; \
  78668. state->bits = bits; \
  78669. } while (0)
  78670. #define INITBITS() \
  78671. do { \
  78672. hold = 0; \
  78673. bits = 0; \
  78674. } while (0)
  78675. #define PULLBYTE() \
  78676. do { \
  78677. if (have == 0) goto inf_leave; \
  78678. have--; \
  78679. hold += (unsigned long)(*next++) << bits; \
  78680. bits += 8; \
  78681. } while (0)
  78682. #define NEEDBITS(n) \
  78683. do { \
  78684. while (bits < (unsigned)(n)) \
  78685. PULLBYTE(); \
  78686. } while (0)
  78687. #define BITS(n) \
  78688. ((unsigned)hold & ((1U << (n)) - 1))
  78689. #define DROPBITS(n) \
  78690. do { \
  78691. hold >>= (n); \
  78692. bits -= (unsigned)(n); \
  78693. } while (0)
  78694. #define BYTEBITS() \
  78695. do { \
  78696. hold >>= bits & 7; \
  78697. bits -= bits & 7; \
  78698. } while (0)
  78699. #define REVERSE(q) \
  78700. ((((q) >> 24) & 0xff) + (((q) >> 8) & 0xff00) + \
  78701. (((q) & 0xff00) << 8) + (((q) & 0xff) << 24))
  78702. int ZEXPORT inflate (z_streamp strm, int flush)
  78703. {
  78704. struct inflate_state FAR *state;
  78705. unsigned char FAR *next; /* next input */
  78706. unsigned char FAR *put; /* next output */
  78707. unsigned have, left; /* available input and output */
  78708. unsigned long hold; /* bit buffer */
  78709. unsigned bits; /* bits in bit buffer */
  78710. unsigned in, out; /* save starting available input and output */
  78711. unsigned copy; /* number of stored or match bytes to copy */
  78712. unsigned char FAR *from; /* where to copy match bytes from */
  78713. code thisx; /* current decoding table entry */
  78714. code last; /* parent table entry */
  78715. unsigned len; /* length to copy for repeats, bits to drop */
  78716. int ret; /* return code */
  78717. #ifdef GUNZIP
  78718. unsigned char hbuf[4]; /* buffer for gzip header crc calculation */
  78719. #endif
  78720. static const unsigned short order[19] = /* permutation of code lengths */
  78721. {16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15};
  78722. if (strm == Z_NULL || strm->state == Z_NULL || strm->next_out == Z_NULL ||
  78723. (strm->next_in == Z_NULL && strm->avail_in != 0))
  78724. return Z_STREAM_ERROR;
  78725. state = (struct inflate_state FAR *)strm->state;
  78726. if (state->mode == TYPE) state->mode = TYPEDO; /* skip check */
  78727. LOAD();
  78728. in = have;
  78729. out = left;
  78730. ret = Z_OK;
  78731. for (;;)
  78732. switch (state->mode) {
  78733. case HEAD:
  78734. if (state->wrap == 0) {
  78735. state->mode = TYPEDO;
  78736. break;
  78737. }
  78738. NEEDBITS(16);
  78739. #ifdef GUNZIP
  78740. if ((state->wrap & 2) && hold == 0x8b1f) { /* gzip header */
  78741. state->check = crc32(0L, Z_NULL, 0);
  78742. CRC2(state->check, hold);
  78743. INITBITS();
  78744. state->mode = FLAGS;
  78745. break;
  78746. }
  78747. state->flags = 0; /* expect zlib header */
  78748. if (state->head != Z_NULL)
  78749. state->head->done = -1;
  78750. if (!(state->wrap & 1) || /* check if zlib header allowed */
  78751. #else
  78752. if (
  78753. #endif
  78754. ((BITS(8) << 8) + (hold >> 8)) % 31) {
  78755. strm->msg = (char *)"incorrect header check";
  78756. state->mode = BAD;
  78757. break;
  78758. }
  78759. if (BITS(4) != Z_DEFLATED) {
  78760. strm->msg = (char *)"unknown compression method";
  78761. state->mode = BAD;
  78762. break;
  78763. }
  78764. DROPBITS(4);
  78765. len = BITS(4) + 8;
  78766. if (len > state->wbits) {
  78767. strm->msg = (char *)"invalid window size";
  78768. state->mode = BAD;
  78769. break;
  78770. }
  78771. state->dmax = 1U << len;
  78772. Tracev((stderr, "inflate: zlib header ok\n"));
  78773. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78774. state->mode = hold & 0x200 ? DICTID : TYPE;
  78775. INITBITS();
  78776. break;
  78777. #ifdef GUNZIP
  78778. case FLAGS:
  78779. NEEDBITS(16);
  78780. state->flags = (int)(hold);
  78781. if ((state->flags & 0xff) != Z_DEFLATED) {
  78782. strm->msg = (char *)"unknown compression method";
  78783. state->mode = BAD;
  78784. break;
  78785. }
  78786. if (state->flags & 0xe000) {
  78787. strm->msg = (char *)"unknown header flags set";
  78788. state->mode = BAD;
  78789. break;
  78790. }
  78791. if (state->head != Z_NULL)
  78792. state->head->text = (int)((hold >> 8) & 1);
  78793. if (state->flags & 0x0200) CRC2(state->check, hold);
  78794. INITBITS();
  78795. state->mode = TIME;
  78796. case TIME:
  78797. NEEDBITS(32);
  78798. if (state->head != Z_NULL)
  78799. state->head->time = hold;
  78800. if (state->flags & 0x0200) CRC4(state->check, hold);
  78801. INITBITS();
  78802. state->mode = OS;
  78803. case OS:
  78804. NEEDBITS(16);
  78805. if (state->head != Z_NULL) {
  78806. state->head->xflags = (int)(hold & 0xff);
  78807. state->head->os = (int)(hold >> 8);
  78808. }
  78809. if (state->flags & 0x0200) CRC2(state->check, hold);
  78810. INITBITS();
  78811. state->mode = EXLEN;
  78812. case EXLEN:
  78813. if (state->flags & 0x0400) {
  78814. NEEDBITS(16);
  78815. state->length = (unsigned)(hold);
  78816. if (state->head != Z_NULL)
  78817. state->head->extra_len = (unsigned)hold;
  78818. if (state->flags & 0x0200) CRC2(state->check, hold);
  78819. INITBITS();
  78820. }
  78821. else if (state->head != Z_NULL)
  78822. state->head->extra = Z_NULL;
  78823. state->mode = EXTRA;
  78824. case EXTRA:
  78825. if (state->flags & 0x0400) {
  78826. copy = state->length;
  78827. if (copy > have) copy = have;
  78828. if (copy) {
  78829. if (state->head != Z_NULL &&
  78830. state->head->extra != Z_NULL) {
  78831. len = state->head->extra_len - state->length;
  78832. zmemcpy(state->head->extra + len, next,
  78833. len + copy > state->head->extra_max ?
  78834. state->head->extra_max - len : copy);
  78835. }
  78836. if (state->flags & 0x0200)
  78837. state->check = crc32(state->check, next, copy);
  78838. have -= copy;
  78839. next += copy;
  78840. state->length -= copy;
  78841. }
  78842. if (state->length) goto inf_leave;
  78843. }
  78844. state->length = 0;
  78845. state->mode = NAME;
  78846. case NAME:
  78847. if (state->flags & 0x0800) {
  78848. if (have == 0) goto inf_leave;
  78849. copy = 0;
  78850. do {
  78851. len = (unsigned)(next[copy++]);
  78852. if (state->head != Z_NULL &&
  78853. state->head->name != Z_NULL &&
  78854. state->length < state->head->name_max)
  78855. state->head->name[state->length++] = len;
  78856. } while (len && copy < have);
  78857. if (state->flags & 0x0200)
  78858. state->check = crc32(state->check, next, copy);
  78859. have -= copy;
  78860. next += copy;
  78861. if (len) goto inf_leave;
  78862. }
  78863. else if (state->head != Z_NULL)
  78864. state->head->name = Z_NULL;
  78865. state->length = 0;
  78866. state->mode = COMMENT;
  78867. case COMMENT:
  78868. if (state->flags & 0x1000) {
  78869. if (have == 0) goto inf_leave;
  78870. copy = 0;
  78871. do {
  78872. len = (unsigned)(next[copy++]);
  78873. if (state->head != Z_NULL &&
  78874. state->head->comment != Z_NULL &&
  78875. state->length < state->head->comm_max)
  78876. state->head->comment[state->length++] = len;
  78877. } while (len && copy < have);
  78878. if (state->flags & 0x0200)
  78879. state->check = crc32(state->check, next, copy);
  78880. have -= copy;
  78881. next += copy;
  78882. if (len) goto inf_leave;
  78883. }
  78884. else if (state->head != Z_NULL)
  78885. state->head->comment = Z_NULL;
  78886. state->mode = HCRC;
  78887. case HCRC:
  78888. if (state->flags & 0x0200) {
  78889. NEEDBITS(16);
  78890. if (hold != (state->check & 0xffff)) {
  78891. strm->msg = (char *)"header crc mismatch";
  78892. state->mode = BAD;
  78893. break;
  78894. }
  78895. INITBITS();
  78896. }
  78897. if (state->head != Z_NULL) {
  78898. state->head->hcrc = (int)((state->flags >> 9) & 1);
  78899. state->head->done = 1;
  78900. }
  78901. strm->adler = state->check = crc32(0L, Z_NULL, 0);
  78902. state->mode = TYPE;
  78903. break;
  78904. #endif
  78905. case DICTID:
  78906. NEEDBITS(32);
  78907. strm->adler = state->check = REVERSE(hold);
  78908. INITBITS();
  78909. state->mode = DICT;
  78910. case DICT:
  78911. if (state->havedict == 0) {
  78912. RESTORE();
  78913. return Z_NEED_DICT;
  78914. }
  78915. strm->adler = state->check = adler32(0L, Z_NULL, 0);
  78916. state->mode = TYPE;
  78917. case TYPE:
  78918. if (flush == Z_BLOCK) goto inf_leave;
  78919. case TYPEDO:
  78920. if (state->last) {
  78921. BYTEBITS();
  78922. state->mode = CHECK;
  78923. break;
  78924. }
  78925. NEEDBITS(3);
  78926. state->last = BITS(1);
  78927. DROPBITS(1);
  78928. switch (BITS(2)) {
  78929. case 0: /* stored block */
  78930. Tracev((stderr, "inflate: stored block%s\n",
  78931. state->last ? " (last)" : ""));
  78932. state->mode = STORED;
  78933. break;
  78934. case 1: /* fixed block */
  78935. fixedtables(state);
  78936. Tracev((stderr, "inflate: fixed codes block%s\n",
  78937. state->last ? " (last)" : ""));
  78938. state->mode = LEN; /* decode codes */
  78939. break;
  78940. case 2: /* dynamic block */
  78941. Tracev((stderr, "inflate: dynamic codes block%s\n",
  78942. state->last ? " (last)" : ""));
  78943. state->mode = TABLE;
  78944. break;
  78945. case 3:
  78946. strm->msg = (char *)"invalid block type";
  78947. state->mode = BAD;
  78948. }
  78949. DROPBITS(2);
  78950. break;
  78951. case STORED:
  78952. BYTEBITS(); /* go to byte boundary */
  78953. NEEDBITS(32);
  78954. if ((hold & 0xffff) != ((hold >> 16) ^ 0xffff)) {
  78955. strm->msg = (char *)"invalid stored block lengths";
  78956. state->mode = BAD;
  78957. break;
  78958. }
  78959. state->length = (unsigned)hold & 0xffff;
  78960. Tracev((stderr, "inflate: stored length %u\n",
  78961. state->length));
  78962. INITBITS();
  78963. state->mode = COPY;
  78964. case COPY:
  78965. copy = state->length;
  78966. if (copy) {
  78967. if (copy > have) copy = have;
  78968. if (copy > left) copy = left;
  78969. if (copy == 0) goto inf_leave;
  78970. zmemcpy(put, next, copy);
  78971. have -= copy;
  78972. next += copy;
  78973. left -= copy;
  78974. put += copy;
  78975. state->length -= copy;
  78976. break;
  78977. }
  78978. Tracev((stderr, "inflate: stored end\n"));
  78979. state->mode = TYPE;
  78980. break;
  78981. case TABLE:
  78982. NEEDBITS(14);
  78983. state->nlen = BITS(5) + 257;
  78984. DROPBITS(5);
  78985. state->ndist = BITS(5) + 1;
  78986. DROPBITS(5);
  78987. state->ncode = BITS(4) + 4;
  78988. DROPBITS(4);
  78989. #ifndef PKZIP_BUG_WORKAROUND
  78990. if (state->nlen > 286 || state->ndist > 30) {
  78991. strm->msg = (char *)"too many length or distance symbols";
  78992. state->mode = BAD;
  78993. break;
  78994. }
  78995. #endif
  78996. Tracev((stderr, "inflate: table sizes ok\n"));
  78997. state->have = 0;
  78998. state->mode = LENLENS;
  78999. case LENLENS:
  79000. while (state->have < state->ncode) {
  79001. NEEDBITS(3);
  79002. state->lens[order[state->have++]] = (unsigned short)BITS(3);
  79003. DROPBITS(3);
  79004. }
  79005. while (state->have < 19)
  79006. state->lens[order[state->have++]] = 0;
  79007. state->next = state->codes;
  79008. state->lencode = (code const FAR *)(state->next);
  79009. state->lenbits = 7;
  79010. ret = inflate_table(CODES, state->lens, 19, &(state->next),
  79011. &(state->lenbits), state->work);
  79012. if (ret) {
  79013. strm->msg = (char *)"invalid code lengths set";
  79014. state->mode = BAD;
  79015. break;
  79016. }
  79017. Tracev((stderr, "inflate: code lengths ok\n"));
  79018. state->have = 0;
  79019. state->mode = CODELENS;
  79020. case CODELENS:
  79021. while (state->have < state->nlen + state->ndist) {
  79022. for (;;) {
  79023. thisx = state->lencode[BITS(state->lenbits)];
  79024. if ((unsigned)(thisx.bits) <= bits) break;
  79025. PULLBYTE();
  79026. }
  79027. if (thisx.val < 16) {
  79028. NEEDBITS(thisx.bits);
  79029. DROPBITS(thisx.bits);
  79030. state->lens[state->have++] = thisx.val;
  79031. }
  79032. else {
  79033. if (thisx.val == 16) {
  79034. NEEDBITS(thisx.bits + 2);
  79035. DROPBITS(thisx.bits);
  79036. if (state->have == 0) {
  79037. strm->msg = (char *)"invalid bit length repeat";
  79038. state->mode = BAD;
  79039. break;
  79040. }
  79041. len = state->lens[state->have - 1];
  79042. copy = 3 + BITS(2);
  79043. DROPBITS(2);
  79044. }
  79045. else if (thisx.val == 17) {
  79046. NEEDBITS(thisx.bits + 3);
  79047. DROPBITS(thisx.bits);
  79048. len = 0;
  79049. copy = 3 + BITS(3);
  79050. DROPBITS(3);
  79051. }
  79052. else {
  79053. NEEDBITS(thisx.bits + 7);
  79054. DROPBITS(thisx.bits);
  79055. len = 0;
  79056. copy = 11 + BITS(7);
  79057. DROPBITS(7);
  79058. }
  79059. if (state->have + copy > state->nlen + state->ndist) {
  79060. strm->msg = (char *)"invalid bit length repeat";
  79061. state->mode = BAD;
  79062. break;
  79063. }
  79064. while (copy--)
  79065. state->lens[state->have++] = (unsigned short)len;
  79066. }
  79067. }
  79068. if (state->mode == BAD) break;
  79069. state->next = state->codes;
  79070. state->lencode = (code const FAR *)(state->next);
  79071. state->lenbits = 9;
  79072. ret = inflate_table(LENS, state->lens, state->nlen, &(state->next),
  79073. &(state->lenbits), state->work);
  79074. if (ret) {
  79075. strm->msg = (char *)"invalid literal/lengths set";
  79076. state->mode = BAD;
  79077. break;
  79078. }
  79079. state->distcode = (code const FAR *)(state->next);
  79080. state->distbits = 6;
  79081. ret = inflate_table(DISTS, state->lens + state->nlen, state->ndist,
  79082. &(state->next), &(state->distbits), state->work);
  79083. if (ret) {
  79084. strm->msg = (char *)"invalid distances set";
  79085. state->mode = BAD;
  79086. break;
  79087. }
  79088. Tracev((stderr, "inflate: codes ok\n"));
  79089. state->mode = LEN;
  79090. case LEN:
  79091. if (have >= 6 && left >= 258) {
  79092. RESTORE();
  79093. inflate_fast(strm, out);
  79094. LOAD();
  79095. break;
  79096. }
  79097. for (;;) {
  79098. thisx = state->lencode[BITS(state->lenbits)];
  79099. if ((unsigned)(thisx.bits) <= bits) break;
  79100. PULLBYTE();
  79101. }
  79102. if (thisx.op && (thisx.op & 0xf0) == 0) {
  79103. last = thisx;
  79104. for (;;) {
  79105. thisx = state->lencode[last.val +
  79106. (BITS(last.bits + last.op) >> last.bits)];
  79107. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  79108. PULLBYTE();
  79109. }
  79110. DROPBITS(last.bits);
  79111. }
  79112. DROPBITS(thisx.bits);
  79113. state->length = (unsigned)thisx.val;
  79114. if ((int)(thisx.op) == 0) {
  79115. Tracevv((stderr, thisx.val >= 0x20 && thisx.val < 0x7f ?
  79116. "inflate: literal '%c'\n" :
  79117. "inflate: literal 0x%02x\n", thisx.val));
  79118. state->mode = LIT;
  79119. break;
  79120. }
  79121. if (thisx.op & 32) {
  79122. Tracevv((stderr, "inflate: end of block\n"));
  79123. state->mode = TYPE;
  79124. break;
  79125. }
  79126. if (thisx.op & 64) {
  79127. strm->msg = (char *)"invalid literal/length code";
  79128. state->mode = BAD;
  79129. break;
  79130. }
  79131. state->extra = (unsigned)(thisx.op) & 15;
  79132. state->mode = LENEXT;
  79133. case LENEXT:
  79134. if (state->extra) {
  79135. NEEDBITS(state->extra);
  79136. state->length += BITS(state->extra);
  79137. DROPBITS(state->extra);
  79138. }
  79139. Tracevv((stderr, "inflate: length %u\n", state->length));
  79140. state->mode = DIST;
  79141. case DIST:
  79142. for (;;) {
  79143. thisx = state->distcode[BITS(state->distbits)];
  79144. if ((unsigned)(thisx.bits) <= bits) break;
  79145. PULLBYTE();
  79146. }
  79147. if ((thisx.op & 0xf0) == 0) {
  79148. last = thisx;
  79149. for (;;) {
  79150. thisx = state->distcode[last.val +
  79151. (BITS(last.bits + last.op) >> last.bits)];
  79152. if ((unsigned)(last.bits + thisx.bits) <= bits) break;
  79153. PULLBYTE();
  79154. }
  79155. DROPBITS(last.bits);
  79156. }
  79157. DROPBITS(thisx.bits);
  79158. if (thisx.op & 64) {
  79159. strm->msg = (char *)"invalid distance code";
  79160. state->mode = BAD;
  79161. break;
  79162. }
  79163. state->offset = (unsigned)thisx.val;
  79164. state->extra = (unsigned)(thisx.op) & 15;
  79165. state->mode = DISTEXT;
  79166. case DISTEXT:
  79167. if (state->extra) {
  79168. NEEDBITS(state->extra);
  79169. state->offset += BITS(state->extra);
  79170. DROPBITS(state->extra);
  79171. }
  79172. #ifdef INFLATE_STRICT
  79173. if (state->offset > state->dmax) {
  79174. strm->msg = (char *)"invalid distance too far back";
  79175. state->mode = BAD;
  79176. break;
  79177. }
  79178. #endif
  79179. if (state->offset > state->whave + out - left) {
  79180. strm->msg = (char *)"invalid distance too far back";
  79181. state->mode = BAD;
  79182. break;
  79183. }
  79184. Tracevv((stderr, "inflate: distance %u\n", state->offset));
  79185. state->mode = MATCH;
  79186. case MATCH:
  79187. if (left == 0) goto inf_leave;
  79188. copy = out - left;
  79189. if (state->offset > copy) { /* copy from window */
  79190. copy = state->offset - copy;
  79191. if (copy > state->write) {
  79192. copy -= state->write;
  79193. from = state->window + (state->wsize - copy);
  79194. }
  79195. else
  79196. from = state->window + (state->write - copy);
  79197. if (copy > state->length) copy = state->length;
  79198. }
  79199. else { /* copy from output */
  79200. from = put - state->offset;
  79201. copy = state->length;
  79202. }
  79203. if (copy > left) copy = left;
  79204. left -= copy;
  79205. state->length -= copy;
  79206. do {
  79207. *put++ = *from++;
  79208. } while (--copy);
  79209. if (state->length == 0) state->mode = LEN;
  79210. break;
  79211. case LIT:
  79212. if (left == 0) goto inf_leave;
  79213. *put++ = (unsigned char)(state->length);
  79214. left--;
  79215. state->mode = LEN;
  79216. break;
  79217. case CHECK:
  79218. if (state->wrap) {
  79219. NEEDBITS(32);
  79220. out -= left;
  79221. strm->total_out += out;
  79222. state->total += out;
  79223. if (out)
  79224. strm->adler = state->check =
  79225. UPDATE(state->check, put - out, out);
  79226. out = left;
  79227. if ((
  79228. #ifdef GUNZIP
  79229. state->flags ? hold :
  79230. #endif
  79231. REVERSE(hold)) != state->check) {
  79232. strm->msg = (char *)"incorrect data check";
  79233. state->mode = BAD;
  79234. break;
  79235. }
  79236. INITBITS();
  79237. Tracev((stderr, "inflate: check matches trailer\n"));
  79238. }
  79239. #ifdef GUNZIP
  79240. state->mode = LENGTH;
  79241. case LENGTH:
  79242. if (state->wrap && state->flags) {
  79243. NEEDBITS(32);
  79244. if (hold != (state->total & 0xffffffffUL)) {
  79245. strm->msg = (char *)"incorrect length check";
  79246. state->mode = BAD;
  79247. break;
  79248. }
  79249. INITBITS();
  79250. Tracev((stderr, "inflate: length matches trailer\n"));
  79251. }
  79252. #endif
  79253. state->mode = DONE;
  79254. case DONE:
  79255. ret = Z_STREAM_END;
  79256. goto inf_leave;
  79257. case BAD:
  79258. ret = Z_DATA_ERROR;
  79259. goto inf_leave;
  79260. case MEM:
  79261. return Z_MEM_ERROR;
  79262. case SYNC:
  79263. default:
  79264. return Z_STREAM_ERROR;
  79265. }
  79266. inf_leave:
  79267. RESTORE();
  79268. if (state->wsize || (state->mode < CHECK && out != strm->avail_out))
  79269. if (updatewindow(strm, out)) {
  79270. state->mode = MEM;
  79271. return Z_MEM_ERROR;
  79272. }
  79273. in -= strm->avail_in;
  79274. out -= strm->avail_out;
  79275. strm->total_in += in;
  79276. strm->total_out += out;
  79277. state->total += out;
  79278. if (state->wrap && out)
  79279. strm->adler = state->check =
  79280. UPDATE(state->check, strm->next_out - out, out);
  79281. strm->data_type = state->bits + (state->last ? 64 : 0) +
  79282. (state->mode == TYPE ? 128 : 0);
  79283. if (((in == 0 && out == 0) || flush == Z_FINISH) && ret == Z_OK)
  79284. ret = Z_BUF_ERROR;
  79285. return ret;
  79286. }
  79287. int ZEXPORT inflateEnd (z_streamp strm)
  79288. {
  79289. struct inflate_state FAR *state;
  79290. if (strm == Z_NULL || strm->state == Z_NULL || strm->zfree == (free_func)0)
  79291. return Z_STREAM_ERROR;
  79292. state = (struct inflate_state FAR *)strm->state;
  79293. if (state->window != Z_NULL) ZFREE(strm, state->window);
  79294. ZFREE(strm, strm->state);
  79295. strm->state = Z_NULL;
  79296. Tracev((stderr, "inflate: end\n"));
  79297. return Z_OK;
  79298. }
  79299. int ZEXPORT inflateSetDictionary (z_streamp strm, const Bytef *dictionary, uInt dictLength)
  79300. {
  79301. struct inflate_state FAR *state;
  79302. unsigned long id_;
  79303. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79304. state = (struct inflate_state FAR *)strm->state;
  79305. if (state->wrap != 0 && state->mode != DICT)
  79306. return Z_STREAM_ERROR;
  79307. if (state->mode == DICT) {
  79308. id_ = adler32(0L, Z_NULL, 0);
  79309. id_ = adler32(id_, dictionary, dictLength);
  79310. if (id_ != state->check)
  79311. return Z_DATA_ERROR;
  79312. }
  79313. if (updatewindow(strm, strm->avail_out)) {
  79314. state->mode = MEM;
  79315. return Z_MEM_ERROR;
  79316. }
  79317. if (dictLength > state->wsize) {
  79318. zmemcpy(state->window, dictionary + dictLength - state->wsize,
  79319. state->wsize);
  79320. state->whave = state->wsize;
  79321. }
  79322. else {
  79323. zmemcpy(state->window + state->wsize - dictLength, dictionary,
  79324. dictLength);
  79325. state->whave = dictLength;
  79326. }
  79327. state->havedict = 1;
  79328. Tracev((stderr, "inflate: dictionary set\n"));
  79329. return Z_OK;
  79330. }
  79331. int ZEXPORT inflateGetHeader (z_streamp strm, gz_headerp head)
  79332. {
  79333. struct inflate_state FAR *state;
  79334. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79335. state = (struct inflate_state FAR *)strm->state;
  79336. if ((state->wrap & 2) == 0) return Z_STREAM_ERROR;
  79337. state->head = head;
  79338. head->done = 0;
  79339. return Z_OK;
  79340. }
  79341. local unsigned syncsearch (unsigned FAR *have, unsigned char FAR *buf, unsigned len)
  79342. {
  79343. unsigned got;
  79344. unsigned next;
  79345. got = *have;
  79346. next = 0;
  79347. while (next < len && got < 4) {
  79348. if ((int)(buf[next]) == (got < 2 ? 0 : 0xff))
  79349. got++;
  79350. else if (buf[next])
  79351. got = 0;
  79352. else
  79353. got = 4 - got;
  79354. next++;
  79355. }
  79356. *have = got;
  79357. return next;
  79358. }
  79359. int ZEXPORT inflateSync (z_streamp strm)
  79360. {
  79361. unsigned len; /* number of bytes to look at or looked at */
  79362. unsigned long in, out; /* temporary to save total_in and total_out */
  79363. unsigned char buf[4]; /* to restore bit buffer to byte string */
  79364. struct inflate_state FAR *state;
  79365. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79366. state = (struct inflate_state FAR *)strm->state;
  79367. if (strm->avail_in == 0 && state->bits < 8) return Z_BUF_ERROR;
  79368. if (state->mode != SYNC) {
  79369. state->mode = SYNC;
  79370. state->hold <<= state->bits & 7;
  79371. state->bits -= state->bits & 7;
  79372. len = 0;
  79373. while (state->bits >= 8) {
  79374. buf[len++] = (unsigned char)(state->hold);
  79375. state->hold >>= 8;
  79376. state->bits -= 8;
  79377. }
  79378. state->have = 0;
  79379. syncsearch(&(state->have), buf, len);
  79380. }
  79381. len = syncsearch(&(state->have), strm->next_in, strm->avail_in);
  79382. strm->avail_in -= len;
  79383. strm->next_in += len;
  79384. strm->total_in += len;
  79385. if (state->have != 4) return Z_DATA_ERROR;
  79386. in = strm->total_in; out = strm->total_out;
  79387. inflateReset(strm);
  79388. strm->total_in = in; strm->total_out = out;
  79389. state->mode = TYPE;
  79390. return Z_OK;
  79391. }
  79392. int ZEXPORT inflateSyncPoint (z_streamp strm)
  79393. {
  79394. struct inflate_state FAR *state;
  79395. if (strm == Z_NULL || strm->state == Z_NULL) return Z_STREAM_ERROR;
  79396. state = (struct inflate_state FAR *)strm->state;
  79397. return state->mode == STORED && state->bits == 0;
  79398. }
  79399. int ZEXPORT inflateCopy(z_streamp dest, z_streamp source)
  79400. {
  79401. struct inflate_state FAR *state;
  79402. struct inflate_state FAR *copy;
  79403. unsigned char FAR *window;
  79404. unsigned wsize;
  79405. if (dest == Z_NULL || source == Z_NULL || source->state == Z_NULL ||
  79406. source->zalloc == (alloc_func)0 || source->zfree == (free_func)0)
  79407. return Z_STREAM_ERROR;
  79408. state = (struct inflate_state FAR *)source->state;
  79409. copy = (struct inflate_state FAR *)
  79410. ZALLOC(source, 1, sizeof(struct inflate_state));
  79411. if (copy == Z_NULL) return Z_MEM_ERROR;
  79412. window = Z_NULL;
  79413. if (state->window != Z_NULL) {
  79414. window = (unsigned char FAR *)
  79415. ZALLOC(source, 1U << state->wbits, sizeof(unsigned char));
  79416. if (window == Z_NULL) {
  79417. ZFREE(source, copy);
  79418. return Z_MEM_ERROR;
  79419. }
  79420. }
  79421. zmemcpy(dest, source, sizeof(z_stream));
  79422. zmemcpy(copy, state, sizeof(struct inflate_state));
  79423. if (state->lencode >= state->codes &&
  79424. state->lencode <= state->codes + ENOUGH - 1) {
  79425. copy->lencode = copy->codes + (state->lencode - state->codes);
  79426. copy->distcode = copy->codes + (state->distcode - state->codes);
  79427. }
  79428. copy->next = copy->codes + (state->next - state->codes);
  79429. if (window != Z_NULL) {
  79430. wsize = 1U << state->wbits;
  79431. zmemcpy(window, state->window, wsize);
  79432. }
  79433. copy->window = window;
  79434. dest->state = (struct internal_state FAR *)copy;
  79435. return Z_OK;
  79436. }
  79437. /*** End of inlined file: inflate.c ***/
  79438. /*** Start of inlined file: inftrees.c ***/
  79439. #define MAXBITS 15
  79440. const char inflate_copyright[] =
  79441. " inflate 1.2.3 Copyright 1995-2005 Mark Adler ";
  79442. int inflate_table (codetype type,
  79443. unsigned short FAR *lens,
  79444. unsigned codes,
  79445. code FAR * FAR *table,
  79446. unsigned FAR *bits,
  79447. unsigned short FAR *work)
  79448. {
  79449. unsigned len; /* a code's length in bits */
  79450. unsigned sym; /* index of code symbols */
  79451. unsigned min, max; /* minimum and maximum code lengths */
  79452. unsigned root; /* number of index bits for root table */
  79453. unsigned curr; /* number of index bits for current table */
  79454. unsigned drop; /* code bits to drop for sub-table */
  79455. int left; /* number of prefix codes available */
  79456. unsigned used; /* code entries in table used */
  79457. unsigned huff; /* Huffman code */
  79458. unsigned incr; /* for incrementing code, index */
  79459. unsigned fill; /* index for replicating entries */
  79460. unsigned low; /* low bits for current root entry */
  79461. unsigned mask; /* mask for low root bits */
  79462. code thisx; /* table entry for duplication */
  79463. code FAR *next; /* next available space in table */
  79464. const unsigned short FAR *base; /* base value table to use */
  79465. const unsigned short FAR *extra; /* extra bits table to use */
  79466. int end; /* use base and extra for symbol > end */
  79467. unsigned short count[MAXBITS+1]; /* number of codes of each length */
  79468. unsigned short offs[MAXBITS+1]; /* offsets in table for each length */
  79469. static const unsigned short lbase[31] = { /* Length codes 257..285 base */
  79470. 3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31,
  79471. 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258, 0, 0};
  79472. static const unsigned short lext[31] = { /* Length codes 257..285 extra */
  79473. 16, 16, 16, 16, 16, 16, 16, 16, 17, 17, 17, 17, 18, 18, 18, 18,
  79474. 19, 19, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 16, 201, 196};
  79475. static const unsigned short dbase[32] = { /* Distance codes 0..29 base */
  79476. 1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193,
  79477. 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145,
  79478. 8193, 12289, 16385, 24577, 0, 0};
  79479. static const unsigned short dext[32] = { /* Distance codes 0..29 extra */
  79480. 16, 16, 16, 16, 17, 17, 18, 18, 19, 19, 20, 20, 21, 21, 22, 22,
  79481. 23, 23, 24, 24, 25, 25, 26, 26, 27, 27,
  79482. 28, 28, 29, 29, 64, 64};
  79483. for (len = 0; len <= MAXBITS; len++)
  79484. count[len] = 0;
  79485. for (sym = 0; sym < codes; sym++)
  79486. count[lens[sym]]++;
  79487. root = *bits;
  79488. for (max = MAXBITS; max >= 1; max--)
  79489. if (count[max] != 0) break;
  79490. if (root > max) root = max;
  79491. if (max == 0) { /* no symbols to code at all */
  79492. thisx.op = (unsigned char)64; /* invalid code marker */
  79493. thisx.bits = (unsigned char)1;
  79494. thisx.val = (unsigned short)0;
  79495. *(*table)++ = thisx; /* make a table to force an error */
  79496. *(*table)++ = thisx;
  79497. *bits = 1;
  79498. return 0; /* no symbols, but wait for decoding to report error */
  79499. }
  79500. for (min = 1; min <= MAXBITS; min++)
  79501. if (count[min] != 0) break;
  79502. if (root < min) root = min;
  79503. left = 1;
  79504. for (len = 1; len <= MAXBITS; len++) {
  79505. left <<= 1;
  79506. left -= count[len];
  79507. if (left < 0) return -1; /* over-subscribed */
  79508. }
  79509. if (left > 0 && (type == CODES || max != 1))
  79510. return -1; /* incomplete set */
  79511. offs[1] = 0;
  79512. for (len = 1; len < MAXBITS; len++)
  79513. offs[len + 1] = offs[len] + count[len];
  79514. for (sym = 0; sym < codes; sym++)
  79515. if (lens[sym] != 0) work[offs[lens[sym]]++] = (unsigned short)sym;
  79516. switch (type) {
  79517. case CODES:
  79518. base = extra = work; /* dummy value--not used */
  79519. end = 19;
  79520. break;
  79521. case LENS:
  79522. base = lbase;
  79523. base -= 257;
  79524. extra = lext;
  79525. extra -= 257;
  79526. end = 256;
  79527. break;
  79528. default: /* DISTS */
  79529. base = dbase;
  79530. extra = dext;
  79531. end = -1;
  79532. }
  79533. huff = 0; /* starting code */
  79534. sym = 0; /* starting code symbol */
  79535. len = min; /* starting code length */
  79536. next = *table; /* current table to fill in */
  79537. curr = root; /* current table index bits */
  79538. drop = 0; /* current bits to drop from code for index */
  79539. low = (unsigned)(-1); /* trigger new sub-table when len > root */
  79540. used = 1U << root; /* use root table entries */
  79541. mask = used - 1; /* mask for comparing low */
  79542. if (type == LENS && used >= ENOUGH - MAXD)
  79543. return 1;
  79544. for (;;) {
  79545. thisx.bits = (unsigned char)(len - drop);
  79546. if ((int)(work[sym]) < end) {
  79547. thisx.op = (unsigned char)0;
  79548. thisx.val = work[sym];
  79549. }
  79550. else if ((int)(work[sym]) > end) {
  79551. thisx.op = (unsigned char)(extra[work[sym]]);
  79552. thisx.val = base[work[sym]];
  79553. }
  79554. else {
  79555. thisx.op = (unsigned char)(32 + 64); /* end of block */
  79556. thisx.val = 0;
  79557. }
  79558. incr = 1U << (len - drop);
  79559. fill = 1U << curr;
  79560. min = fill; /* save offset to next table */
  79561. do {
  79562. fill -= incr;
  79563. next[(huff >> drop) + fill] = thisx;
  79564. } while (fill != 0);
  79565. incr = 1U << (len - 1);
  79566. while (huff & incr)
  79567. incr >>= 1;
  79568. if (incr != 0) {
  79569. huff &= incr - 1;
  79570. huff += incr;
  79571. }
  79572. else
  79573. huff = 0;
  79574. sym++;
  79575. if (--(count[len]) == 0) {
  79576. if (len == max) break;
  79577. len = lens[work[sym]];
  79578. }
  79579. if (len > root && (huff & mask) != low) {
  79580. if (drop == 0)
  79581. drop = root;
  79582. next += min; /* here min is 1 << curr */
  79583. curr = len - drop;
  79584. left = (int)(1 << curr);
  79585. while (curr + drop < max) {
  79586. left -= count[curr + drop];
  79587. if (left <= 0) break;
  79588. curr++;
  79589. left <<= 1;
  79590. }
  79591. used += 1U << curr;
  79592. if (type == LENS && used >= ENOUGH - MAXD)
  79593. return 1;
  79594. low = huff & mask;
  79595. (*table)[low].op = (unsigned char)curr;
  79596. (*table)[low].bits = (unsigned char)root;
  79597. (*table)[low].val = (unsigned short)(next - *table);
  79598. }
  79599. }
  79600. thisx.op = (unsigned char)64; /* invalid code marker */
  79601. thisx.bits = (unsigned char)(len - drop);
  79602. thisx.val = (unsigned short)0;
  79603. while (huff != 0) {
  79604. if (drop != 0 && (huff & mask) != low) {
  79605. drop = 0;
  79606. len = root;
  79607. next = *table;
  79608. thisx.bits = (unsigned char)len;
  79609. }
  79610. next[huff >> drop] = thisx;
  79611. incr = 1U << (len - 1);
  79612. while (huff & incr)
  79613. incr >>= 1;
  79614. if (incr != 0) {
  79615. huff &= incr - 1;
  79616. huff += incr;
  79617. }
  79618. else
  79619. huff = 0;
  79620. }
  79621. *table += used;
  79622. *bits = root;
  79623. return 0;
  79624. }
  79625. /*** End of inlined file: inftrees.c ***/
  79626. /*** Start of inlined file: trees.c ***/
  79627. #ifdef DEBUG
  79628. # include <ctype.h>
  79629. #endif
  79630. #define MAX_BL_BITS 7
  79631. #define END_BLOCK 256
  79632. #define REP_3_6 16
  79633. #define REPZ_3_10 17
  79634. #define REPZ_11_138 18
  79635. local const int extra_lbits[LENGTH_CODES] /* extra bits for each length code */
  79636. = {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};
  79637. local const int extra_dbits[D_CODES] /* extra bits for each distance code */
  79638. = {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};
  79639. local const int extra_blbits[BL_CODES]/* extra bits for each bit length code */
  79640. = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,2,3,7};
  79641. local const uch bl_order[BL_CODES]
  79642. = {16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15};
  79643. #define Buf_size (8 * 2*sizeof(char))
  79644. #define DIST_CODE_LEN 512 /* see definition of array dist_code below */
  79645. #if defined(GEN_TREES_H) || !defined(STDC)
  79646. local ct_data static_ltree[L_CODES+2];
  79647. local ct_data static_dtree[D_CODES];
  79648. uch _dist_code[DIST_CODE_LEN];
  79649. uch _length_code[MAX_MATCH-MIN_MATCH+1];
  79650. local int base_length[LENGTH_CODES];
  79651. local int base_dist[D_CODES];
  79652. #else
  79653. /*** Start of inlined file: trees.h ***/
  79654. local const ct_data static_ltree[L_CODES+2] = {
  79655. {{ 12},{ 8}}, {{140},{ 8}}, {{ 76},{ 8}}, {{204},{ 8}}, {{ 44},{ 8}},
  79656. {{172},{ 8}}, {{108},{ 8}}, {{236},{ 8}}, {{ 28},{ 8}}, {{156},{ 8}},
  79657. {{ 92},{ 8}}, {{220},{ 8}}, {{ 60},{ 8}}, {{188},{ 8}}, {{124},{ 8}},
  79658. {{252},{ 8}}, {{ 2},{ 8}}, {{130},{ 8}}, {{ 66},{ 8}}, {{194},{ 8}},
  79659. {{ 34},{ 8}}, {{162},{ 8}}, {{ 98},{ 8}}, {{226},{ 8}}, {{ 18},{ 8}},
  79660. {{146},{ 8}}, {{ 82},{ 8}}, {{210},{ 8}}, {{ 50},{ 8}}, {{178},{ 8}},
  79661. {{114},{ 8}}, {{242},{ 8}}, {{ 10},{ 8}}, {{138},{ 8}}, {{ 74},{ 8}},
  79662. {{202},{ 8}}, {{ 42},{ 8}}, {{170},{ 8}}, {{106},{ 8}}, {{234},{ 8}},
  79663. {{ 26},{ 8}}, {{154},{ 8}}, {{ 90},{ 8}}, {{218},{ 8}}, {{ 58},{ 8}},
  79664. {{186},{ 8}}, {{122},{ 8}}, {{250},{ 8}}, {{ 6},{ 8}}, {{134},{ 8}},
  79665. {{ 70},{ 8}}, {{198},{ 8}}, {{ 38},{ 8}}, {{166},{ 8}}, {{102},{ 8}},
  79666. {{230},{ 8}}, {{ 22},{ 8}}, {{150},{ 8}}, {{ 86},{ 8}}, {{214},{ 8}},
  79667. {{ 54},{ 8}}, {{182},{ 8}}, {{118},{ 8}}, {{246},{ 8}}, {{ 14},{ 8}},
  79668. {{142},{ 8}}, {{ 78},{ 8}}, {{206},{ 8}}, {{ 46},{ 8}}, {{174},{ 8}},
  79669. {{110},{ 8}}, {{238},{ 8}}, {{ 30},{ 8}}, {{158},{ 8}}, {{ 94},{ 8}},
  79670. {{222},{ 8}}, {{ 62},{ 8}}, {{190},{ 8}}, {{126},{ 8}}, {{254},{ 8}},
  79671. {{ 1},{ 8}}, {{129},{ 8}}, {{ 65},{ 8}}, {{193},{ 8}}, {{ 33},{ 8}},
  79672. {{161},{ 8}}, {{ 97},{ 8}}, {{225},{ 8}}, {{ 17},{ 8}}, {{145},{ 8}},
  79673. {{ 81},{ 8}}, {{209},{ 8}}, {{ 49},{ 8}}, {{177},{ 8}}, {{113},{ 8}},
  79674. {{241},{ 8}}, {{ 9},{ 8}}, {{137},{ 8}}, {{ 73},{ 8}}, {{201},{ 8}},
  79675. {{ 41},{ 8}}, {{169},{ 8}}, {{105},{ 8}}, {{233},{ 8}}, {{ 25},{ 8}},
  79676. {{153},{ 8}}, {{ 89},{ 8}}, {{217},{ 8}}, {{ 57},{ 8}}, {{185},{ 8}},
  79677. {{121},{ 8}}, {{249},{ 8}}, {{ 5},{ 8}}, {{133},{ 8}}, {{ 69},{ 8}},
  79678. {{197},{ 8}}, {{ 37},{ 8}}, {{165},{ 8}}, {{101},{ 8}}, {{229},{ 8}},
  79679. {{ 21},{ 8}}, {{149},{ 8}}, {{ 85},{ 8}}, {{213},{ 8}}, {{ 53},{ 8}},
  79680. {{181},{ 8}}, {{117},{ 8}}, {{245},{ 8}}, {{ 13},{ 8}}, {{141},{ 8}},
  79681. {{ 77},{ 8}}, {{205},{ 8}}, {{ 45},{ 8}}, {{173},{ 8}}, {{109},{ 8}},
  79682. {{237},{ 8}}, {{ 29},{ 8}}, {{157},{ 8}}, {{ 93},{ 8}}, {{221},{ 8}},
  79683. {{ 61},{ 8}}, {{189},{ 8}}, {{125},{ 8}}, {{253},{ 8}}, {{ 19},{ 9}},
  79684. {{275},{ 9}}, {{147},{ 9}}, {{403},{ 9}}, {{ 83},{ 9}}, {{339},{ 9}},
  79685. {{211},{ 9}}, {{467},{ 9}}, {{ 51},{ 9}}, {{307},{ 9}}, {{179},{ 9}},
  79686. {{435},{ 9}}, {{115},{ 9}}, {{371},{ 9}}, {{243},{ 9}}, {{499},{ 9}},
  79687. {{ 11},{ 9}}, {{267},{ 9}}, {{139},{ 9}}, {{395},{ 9}}, {{ 75},{ 9}},
  79688. {{331},{ 9}}, {{203},{ 9}}, {{459},{ 9}}, {{ 43},{ 9}}, {{299},{ 9}},
  79689. {{171},{ 9}}, {{427},{ 9}}, {{107},{ 9}}, {{363},{ 9}}, {{235},{ 9}},
  79690. {{491},{ 9}}, {{ 27},{ 9}}, {{283},{ 9}}, {{155},{ 9}}, {{411},{ 9}},
  79691. {{ 91},{ 9}}, {{347},{ 9}}, {{219},{ 9}}, {{475},{ 9}}, {{ 59},{ 9}},
  79692. {{315},{ 9}}, {{187},{ 9}}, {{443},{ 9}}, {{123},{ 9}}, {{379},{ 9}},
  79693. {{251},{ 9}}, {{507},{ 9}}, {{ 7},{ 9}}, {{263},{ 9}}, {{135},{ 9}},
  79694. {{391},{ 9}}, {{ 71},{ 9}}, {{327},{ 9}}, {{199},{ 9}}, {{455},{ 9}},
  79695. {{ 39},{ 9}}, {{295},{ 9}}, {{167},{ 9}}, {{423},{ 9}}, {{103},{ 9}},
  79696. {{359},{ 9}}, {{231},{ 9}}, {{487},{ 9}}, {{ 23},{ 9}}, {{279},{ 9}},
  79697. {{151},{ 9}}, {{407},{ 9}}, {{ 87},{ 9}}, {{343},{ 9}}, {{215},{ 9}},
  79698. {{471},{ 9}}, {{ 55},{ 9}}, {{311},{ 9}}, {{183},{ 9}}, {{439},{ 9}},
  79699. {{119},{ 9}}, {{375},{ 9}}, {{247},{ 9}}, {{503},{ 9}}, {{ 15},{ 9}},
  79700. {{271},{ 9}}, {{143},{ 9}}, {{399},{ 9}}, {{ 79},{ 9}}, {{335},{ 9}},
  79701. {{207},{ 9}}, {{463},{ 9}}, {{ 47},{ 9}}, {{303},{ 9}}, {{175},{ 9}},
  79702. {{431},{ 9}}, {{111},{ 9}}, {{367},{ 9}}, {{239},{ 9}}, {{495},{ 9}},
  79703. {{ 31},{ 9}}, {{287},{ 9}}, {{159},{ 9}}, {{415},{ 9}}, {{ 95},{ 9}},
  79704. {{351},{ 9}}, {{223},{ 9}}, {{479},{ 9}}, {{ 63},{ 9}}, {{319},{ 9}},
  79705. {{191},{ 9}}, {{447},{ 9}}, {{127},{ 9}}, {{383},{ 9}}, {{255},{ 9}},
  79706. {{511},{ 9}}, {{ 0},{ 7}}, {{ 64},{ 7}}, {{ 32},{ 7}}, {{ 96},{ 7}},
  79707. {{ 16},{ 7}}, {{ 80},{ 7}}, {{ 48},{ 7}}, {{112},{ 7}}, {{ 8},{ 7}},
  79708. {{ 72},{ 7}}, {{ 40},{ 7}}, {{104},{ 7}}, {{ 24},{ 7}}, {{ 88},{ 7}},
  79709. {{ 56},{ 7}}, {{120},{ 7}}, {{ 4},{ 7}}, {{ 68},{ 7}}, {{ 36},{ 7}},
  79710. {{100},{ 7}}, {{ 20},{ 7}}, {{ 84},{ 7}}, {{ 52},{ 7}}, {{116},{ 7}},
  79711. {{ 3},{ 8}}, {{131},{ 8}}, {{ 67},{ 8}}, {{195},{ 8}}, {{ 35},{ 8}},
  79712. {{163},{ 8}}, {{ 99},{ 8}}, {{227},{ 8}}
  79713. };
  79714. local const ct_data static_dtree[D_CODES] = {
  79715. {{ 0},{ 5}}, {{16},{ 5}}, {{ 8},{ 5}}, {{24},{ 5}}, {{ 4},{ 5}},
  79716. {{20},{ 5}}, {{12},{ 5}}, {{28},{ 5}}, {{ 2},{ 5}}, {{18},{ 5}},
  79717. {{10},{ 5}}, {{26},{ 5}}, {{ 6},{ 5}}, {{22},{ 5}}, {{14},{ 5}},
  79718. {{30},{ 5}}, {{ 1},{ 5}}, {{17},{ 5}}, {{ 9},{ 5}}, {{25},{ 5}},
  79719. {{ 5},{ 5}}, {{21},{ 5}}, {{13},{ 5}}, {{29},{ 5}}, {{ 3},{ 5}},
  79720. {{19},{ 5}}, {{11},{ 5}}, {{27},{ 5}}, {{ 7},{ 5}}, {{23},{ 5}}
  79721. };
  79722. const uch _dist_code[DIST_CODE_LEN] = {
  79723. 0, 1, 2, 3, 4, 4, 5, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8,
  79724. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 10, 10, 10, 10, 10, 10, 10, 10,
  79725. 10, 10, 10, 10, 10, 10, 10, 10, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
  79726. 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
  79727. 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 13, 13, 13, 13,
  79728. 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13, 13,
  79729. 13, 13, 13, 13, 13, 13, 13, 13, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79730. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79731. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14,
  79732. 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 14, 15, 15, 15, 15, 15, 15, 15, 15,
  79733. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79734. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15,
  79735. 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 0, 0, 16, 17,
  79736. 18, 18, 19, 19, 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 22, 22, 22, 22,
  79737. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79738. 24, 24, 24, 24, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79739. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79740. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27,
  79741. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79742. 27, 27, 27, 27, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79743. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79744. 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28,
  79745. 28, 28, 28, 28, 28, 28, 28, 28, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79746. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79747. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29,
  79748. 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29, 29
  79749. };
  79750. const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {
  79751. 0, 1, 2, 3, 4, 5, 6, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 12, 12,
  79752. 13, 13, 13, 13, 14, 14, 14, 14, 15, 15, 15, 15, 16, 16, 16, 16, 16, 16, 16, 16,
  79753. 17, 17, 17, 17, 17, 17, 17, 17, 18, 18, 18, 18, 18, 18, 18, 18, 19, 19, 19, 19,
  79754. 19, 19, 19, 19, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20, 20,
  79755. 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 21, 22, 22, 22, 22,
  79756. 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 23, 23, 23, 23, 23, 23, 23, 23,
  79757. 23, 23, 23, 23, 23, 23, 23, 23, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79758. 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24, 24,
  79759. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25,
  79760. 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 25, 26, 26, 26, 26, 26, 26, 26, 26,
  79761. 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26, 26,
  79762. 26, 26, 26, 26, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27,
  79763. 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 27, 28
  79764. };
  79765. local const int base_length[LENGTH_CODES] = {
  79766. 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 12, 14, 16, 20, 24, 28, 32, 40, 48, 56,
  79767. 64, 80, 96, 112, 128, 160, 192, 224, 0
  79768. };
  79769. local const int base_dist[D_CODES] = {
  79770. 0, 1, 2, 3, 4, 6, 8, 12, 16, 24,
  79771. 32, 48, 64, 96, 128, 192, 256, 384, 512, 768,
  79772. 1024, 1536, 2048, 3072, 4096, 6144, 8192, 12288, 16384, 24576
  79773. };
  79774. /*** End of inlined file: trees.h ***/
  79775. #endif /* GEN_TREES_H */
  79776. struct static_tree_desc_s {
  79777. const ct_data *static_tree; /* static tree or NULL */
  79778. const intf *extra_bits; /* extra bits for each code or NULL */
  79779. int extra_base; /* base index for extra_bits */
  79780. int elems; /* max number of elements in the tree */
  79781. int max_length; /* max bit length for the codes */
  79782. };
  79783. local static_tree_desc static_l_desc =
  79784. {static_ltree, extra_lbits, LITERALS+1, L_CODES, MAX_BITS};
  79785. local static_tree_desc static_d_desc =
  79786. {static_dtree, extra_dbits, 0, D_CODES, MAX_BITS};
  79787. local static_tree_desc static_bl_desc =
  79788. {(const ct_data *)0, extra_blbits, 0, BL_CODES, MAX_BL_BITS};
  79789. local void tr_static_init OF((void));
  79790. local void init_block OF((deflate_state *s));
  79791. local void pqdownheap OF((deflate_state *s, ct_data *tree, int k));
  79792. local void gen_bitlen OF((deflate_state *s, tree_desc *desc));
  79793. local void gen_codes OF((ct_data *tree, int max_code, ushf *bl_count));
  79794. local void build_tree OF((deflate_state *s, tree_desc *desc));
  79795. local void scan_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79796. local void send_tree OF((deflate_state *s, ct_data *tree, int max_code));
  79797. local int build_bl_tree OF((deflate_state *s));
  79798. local void send_all_trees OF((deflate_state *s, int lcodes, int dcodes,
  79799. int blcodes));
  79800. local void compress_block OF((deflate_state *s, ct_data *ltree,
  79801. ct_data *dtree));
  79802. local void set_data_type OF((deflate_state *s));
  79803. local unsigned bi_reverse OF((unsigned value, int length));
  79804. local void bi_windup OF((deflate_state *s));
  79805. local void bi_flush OF((deflate_state *s));
  79806. local void copy_block OF((deflate_state *s, charf *buf, unsigned len,
  79807. int header));
  79808. #ifdef GEN_TREES_H
  79809. local void gen_trees_header OF((void));
  79810. #endif
  79811. #ifndef DEBUG
  79812. # define send_code(s, c, tree) send_bits(s, tree[c].Code, tree[c].Len)
  79813. #else /* DEBUG */
  79814. # define send_code(s, c, tree) \
  79815. { if (z_verbose>2) fprintf(stderr,"\ncd %3d ",(c)); \
  79816. send_bits(s, tree[c].Code, tree[c].Len); }
  79817. #endif
  79818. #define put_short(s, w) { \
  79819. put_byte(s, (uch)((w) & 0xff)); \
  79820. put_byte(s, (uch)((ush)(w) >> 8)); \
  79821. }
  79822. #ifdef DEBUG
  79823. local void send_bits OF((deflate_state *s, int value, int length));
  79824. local void send_bits (deflate_state *s, int value, int length)
  79825. {
  79826. Tracevv((stderr," l %2d v %4x ", length, value));
  79827. Assert(length > 0 && length <= 15, "invalid length");
  79828. s->bits_sent += (ulg)length;
  79829. if (s->bi_valid > (int)Buf_size - length) {
  79830. s->bi_buf |= (value << s->bi_valid);
  79831. put_short(s, s->bi_buf);
  79832. s->bi_buf = (ush)value >> (Buf_size - s->bi_valid);
  79833. s->bi_valid += length - Buf_size;
  79834. } else {
  79835. s->bi_buf |= value << s->bi_valid;
  79836. s->bi_valid += length;
  79837. }
  79838. }
  79839. #else /* !DEBUG */
  79840. #define send_bits(s, value, length) \
  79841. { int len = length;\
  79842. if (s->bi_valid > (int)Buf_size - len) {\
  79843. int val = value;\
  79844. s->bi_buf |= (val << s->bi_valid);\
  79845. put_short(s, s->bi_buf);\
  79846. s->bi_buf = (ush)val >> (Buf_size - s->bi_valid);\
  79847. s->bi_valid += len - Buf_size;\
  79848. } else {\
  79849. s->bi_buf |= (value) << s->bi_valid;\
  79850. s->bi_valid += len;\
  79851. }\
  79852. }
  79853. #endif /* DEBUG */
  79854. local void tr_static_init()
  79855. {
  79856. #if defined(GEN_TREES_H) || !defined(STDC)
  79857. static int static_init_done = 0;
  79858. int n; /* iterates over tree elements */
  79859. int bits; /* bit counter */
  79860. int length; /* length value */
  79861. int code; /* code value */
  79862. int dist; /* distance index */
  79863. ush bl_count[MAX_BITS+1];
  79864. if (static_init_done) return;
  79865. static_l_desc.static_tree = static_ltree;
  79866. static_l_desc.extra_bits = extra_lbits;
  79867. static_d_desc.static_tree = static_dtree;
  79868. static_d_desc.extra_bits = extra_dbits;
  79869. static_bl_desc.extra_bits = extra_blbits;
  79870. length = 0;
  79871. for (code = 0; code < LENGTH_CODES-1; code++) {
  79872. base_length[code] = length;
  79873. for (n = 0; n < (1<<extra_lbits[code]); n++) {
  79874. _length_code[length++] = (uch)code;
  79875. }
  79876. }
  79877. Assert (length == 256, "tr_static_init: length != 256");
  79878. _length_code[length-1] = (uch)code;
  79879. dist = 0;
  79880. for (code = 0 ; code < 16; code++) {
  79881. base_dist[code] = dist;
  79882. for (n = 0; n < (1<<extra_dbits[code]); n++) {
  79883. _dist_code[dist++] = (uch)code;
  79884. }
  79885. }
  79886. Assert (dist == 256, "tr_static_init: dist != 256");
  79887. dist >>= 7; /* from now on, all distances are divided by 128 */
  79888. for ( ; code < D_CODES; code++) {
  79889. base_dist[code] = dist << 7;
  79890. for (n = 0; n < (1<<(extra_dbits[code]-7)); n++) {
  79891. _dist_code[256 + dist++] = (uch)code;
  79892. }
  79893. }
  79894. Assert (dist == 256, "tr_static_init: 256+dist != 512");
  79895. for (bits = 0; bits <= MAX_BITS; bits++) bl_count[bits] = 0;
  79896. n = 0;
  79897. while (n <= 143) static_ltree[n++].Len = 8, bl_count[8]++;
  79898. while (n <= 255) static_ltree[n++].Len = 9, bl_count[9]++;
  79899. while (n <= 279) static_ltree[n++].Len = 7, bl_count[7]++;
  79900. while (n <= 287) static_ltree[n++].Len = 8, bl_count[8]++;
  79901. gen_codes((ct_data *)static_ltree, L_CODES+1, bl_count);
  79902. for (n = 0; n < D_CODES; n++) {
  79903. static_dtree[n].Len = 5;
  79904. static_dtree[n].Code = bi_reverse((unsigned)n, 5);
  79905. }
  79906. static_init_done = 1;
  79907. # ifdef GEN_TREES_H
  79908. gen_trees_header();
  79909. # endif
  79910. #endif /* defined(GEN_TREES_H) || !defined(STDC) */
  79911. }
  79912. #ifdef GEN_TREES_H
  79913. # ifndef DEBUG
  79914. # include <stdio.h>
  79915. # endif
  79916. # define SEPARATOR(i, last, width) \
  79917. ((i) == (last)? "\n};\n\n" : \
  79918. ((i) % (width) == (width)-1 ? ",\n" : ", "))
  79919. void gen_trees_header()
  79920. {
  79921. FILE *header = fopen("trees.h", "w");
  79922. int i;
  79923. Assert (header != NULL, "Can't open trees.h");
  79924. fprintf(header,
  79925. "/* header created automatically with -DGEN_TREES_H */\n\n");
  79926. fprintf(header, "local const ct_data static_ltree[L_CODES+2] = {\n");
  79927. for (i = 0; i < L_CODES+2; i++) {
  79928. fprintf(header, "{{%3u},{%3u}}%s", static_ltree[i].Code,
  79929. static_ltree[i].Len, SEPARATOR(i, L_CODES+1, 5));
  79930. }
  79931. fprintf(header, "local const ct_data static_dtree[D_CODES] = {\n");
  79932. for (i = 0; i < D_CODES; i++) {
  79933. fprintf(header, "{{%2u},{%2u}}%s", static_dtree[i].Code,
  79934. static_dtree[i].Len, SEPARATOR(i, D_CODES-1, 5));
  79935. }
  79936. fprintf(header, "const uch _dist_code[DIST_CODE_LEN] = {\n");
  79937. for (i = 0; i < DIST_CODE_LEN; i++) {
  79938. fprintf(header, "%2u%s", _dist_code[i],
  79939. SEPARATOR(i, DIST_CODE_LEN-1, 20));
  79940. }
  79941. fprintf(header, "const uch _length_code[MAX_MATCH-MIN_MATCH+1]= {\n");
  79942. for (i = 0; i < MAX_MATCH-MIN_MATCH+1; i++) {
  79943. fprintf(header, "%2u%s", _length_code[i],
  79944. SEPARATOR(i, MAX_MATCH-MIN_MATCH, 20));
  79945. }
  79946. fprintf(header, "local const int base_length[LENGTH_CODES] = {\n");
  79947. for (i = 0; i < LENGTH_CODES; i++) {
  79948. fprintf(header, "%1u%s", base_length[i],
  79949. SEPARATOR(i, LENGTH_CODES-1, 20));
  79950. }
  79951. fprintf(header, "local const int base_dist[D_CODES] = {\n");
  79952. for (i = 0; i < D_CODES; i++) {
  79953. fprintf(header, "%5u%s", base_dist[i],
  79954. SEPARATOR(i, D_CODES-1, 10));
  79955. }
  79956. fclose(header);
  79957. }
  79958. #endif /* GEN_TREES_H */
  79959. void _tr_init(deflate_state *s)
  79960. {
  79961. tr_static_init();
  79962. s->l_desc.dyn_tree = s->dyn_ltree;
  79963. s->l_desc.stat_desc = &static_l_desc;
  79964. s->d_desc.dyn_tree = s->dyn_dtree;
  79965. s->d_desc.stat_desc = &static_d_desc;
  79966. s->bl_desc.dyn_tree = s->bl_tree;
  79967. s->bl_desc.stat_desc = &static_bl_desc;
  79968. s->bi_buf = 0;
  79969. s->bi_valid = 0;
  79970. s->last_eob_len = 8; /* enough lookahead for inflate */
  79971. #ifdef DEBUG
  79972. s->compressed_len = 0L;
  79973. s->bits_sent = 0L;
  79974. #endif
  79975. init_block(s);
  79976. }
  79977. local void init_block (deflate_state *s)
  79978. {
  79979. int n; /* iterates over tree elements */
  79980. for (n = 0; n < L_CODES; n++) s->dyn_ltree[n].Freq = 0;
  79981. for (n = 0; n < D_CODES; n++) s->dyn_dtree[n].Freq = 0;
  79982. for (n = 0; n < BL_CODES; n++) s->bl_tree[n].Freq = 0;
  79983. s->dyn_ltree[END_BLOCK].Freq = 1;
  79984. s->opt_len = s->static_len = 0L;
  79985. s->last_lit = s->matches = 0;
  79986. }
  79987. #define SMALLEST 1
  79988. #define pqremove(s, tree, top) \
  79989. {\
  79990. top = s->heap[SMALLEST]; \
  79991. s->heap[SMALLEST] = s->heap[s->heap_len--]; \
  79992. pqdownheap(s, tree, SMALLEST); \
  79993. }
  79994. #define smaller(tree, n, m, depth) \
  79995. (tree[n].Freq < tree[m].Freq || \
  79996. (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m]))
  79997. local void pqdownheap (deflate_state *s,
  79998. ct_data *tree, /* the tree to restore */
  79999. int k) /* node to move down */
  80000. {
  80001. int v = s->heap[k];
  80002. int j = k << 1; /* left son of k */
  80003. while (j <= s->heap_len) {
  80004. if (j < s->heap_len &&
  80005. smaller(tree, s->heap[j+1], s->heap[j], s->depth)) {
  80006. j++;
  80007. }
  80008. if (smaller(tree, v, s->heap[j], s->depth)) break;
  80009. s->heap[k] = s->heap[j]; k = j;
  80010. j <<= 1;
  80011. }
  80012. s->heap[k] = v;
  80013. }
  80014. local void gen_bitlen (deflate_state *s, tree_desc *desc)
  80015. {
  80016. ct_data *tree = desc->dyn_tree;
  80017. int max_code = desc->max_code;
  80018. const ct_data *stree = desc->stat_desc->static_tree;
  80019. const intf *extra = desc->stat_desc->extra_bits;
  80020. int base = desc->stat_desc->extra_base;
  80021. int max_length = desc->stat_desc->max_length;
  80022. int h; /* heap index */
  80023. int n, m; /* iterate over the tree elements */
  80024. int bits; /* bit length */
  80025. int xbits; /* extra bits */
  80026. ush f; /* frequency */
  80027. int overflow = 0; /* number of elements with bit length too large */
  80028. for (bits = 0; bits <= MAX_BITS; bits++) s->bl_count[bits] = 0;
  80029. tree[s->heap[s->heap_max]].Len = 0; /* root of the heap */
  80030. for (h = s->heap_max+1; h < HEAP_SIZE; h++) {
  80031. n = s->heap[h];
  80032. bits = tree[tree[n].Dad].Len + 1;
  80033. if (bits > max_length) bits = max_length, overflow++;
  80034. tree[n].Len = (ush)bits;
  80035. if (n > max_code) continue; /* not a leaf node */
  80036. s->bl_count[bits]++;
  80037. xbits = 0;
  80038. if (n >= base) xbits = extra[n-base];
  80039. f = tree[n].Freq;
  80040. s->opt_len += (ulg)f * (bits + xbits);
  80041. if (stree) s->static_len += (ulg)f * (stree[n].Len + xbits);
  80042. }
  80043. if (overflow == 0) return;
  80044. Trace((stderr,"\nbit length overflow\n"));
  80045. do {
  80046. bits = max_length-1;
  80047. while (s->bl_count[bits] == 0) bits--;
  80048. s->bl_count[bits]--; /* move one leaf down the tree */
  80049. s->bl_count[bits+1] += 2; /* move one overflow item as its brother */
  80050. s->bl_count[max_length]--;
  80051. overflow -= 2;
  80052. } while (overflow > 0);
  80053. for (bits = max_length; bits != 0; bits--) {
  80054. n = s->bl_count[bits];
  80055. while (n != 0) {
  80056. m = s->heap[--h];
  80057. if (m > max_code) continue;
  80058. if ((unsigned) tree[m].Len != (unsigned) bits) {
  80059. Trace((stderr,"code %d bits %d->%d\n", m, tree[m].Len, bits));
  80060. s->opt_len += ((long)bits - (long)tree[m].Len)
  80061. *(long)tree[m].Freq;
  80062. tree[m].Len = (ush)bits;
  80063. }
  80064. n--;
  80065. }
  80066. }
  80067. }
  80068. local void gen_codes (ct_data *tree, /* the tree to decorate */
  80069. int max_code, /* largest code with non zero frequency */
  80070. ushf *bl_count) /* number of codes at each bit length */
  80071. {
  80072. ush next_code[MAX_BITS+1]; /* next code value for each bit length */
  80073. ush code = 0; /* running code value */
  80074. int bits; /* bit index */
  80075. int n; /* code index */
  80076. for (bits = 1; bits <= MAX_BITS; bits++) {
  80077. next_code[bits] = code = (code + bl_count[bits-1]) << 1;
  80078. }
  80079. Assert (code + bl_count[MAX_BITS]-1 == (1<<MAX_BITS)-1,
  80080. "inconsistent bit counts");
  80081. Tracev((stderr,"\ngen_codes: max_code %d ", max_code));
  80082. for (n = 0; n <= max_code; n++) {
  80083. int len = tree[n].Len;
  80084. if (len == 0) continue;
  80085. tree[n].Code = bi_reverse(next_code[len]++, len);
  80086. Tracecv(tree != static_ltree, (stderr,"\nn %3d %c l %2d c %4x (%x) ",
  80087. n, (isgraph(n) ? n : ' '), len, tree[n].Code, next_code[len]-1));
  80088. }
  80089. }
  80090. local void build_tree (deflate_state *s,
  80091. tree_desc *desc) /* the tree descriptor */
  80092. {
  80093. ct_data *tree = desc->dyn_tree;
  80094. const ct_data *stree = desc->stat_desc->static_tree;
  80095. int elems = desc->stat_desc->elems;
  80096. int n, m; /* iterate over heap elements */
  80097. int max_code = -1; /* largest code with non zero frequency */
  80098. int node; /* new node being created */
  80099. s->heap_len = 0, s->heap_max = HEAP_SIZE;
  80100. for (n = 0; n < elems; n++) {
  80101. if (tree[n].Freq != 0) {
  80102. s->heap[++(s->heap_len)] = max_code = n;
  80103. s->depth[n] = 0;
  80104. } else {
  80105. tree[n].Len = 0;
  80106. }
  80107. }
  80108. while (s->heap_len < 2) {
  80109. node = s->heap[++(s->heap_len)] = (max_code < 2 ? ++max_code : 0);
  80110. tree[node].Freq = 1;
  80111. s->depth[node] = 0;
  80112. s->opt_len--; if (stree) s->static_len -= stree[node].Len;
  80113. }
  80114. desc->max_code = max_code;
  80115. for (n = s->heap_len/2; n >= 1; n--) pqdownheap(s, tree, n);
  80116. node = elems; /* next internal node of the tree */
  80117. do {
  80118. pqremove(s, tree, n); /* n = node of least frequency */
  80119. m = s->heap[SMALLEST]; /* m = node of next least frequency */
  80120. s->heap[--(s->heap_max)] = n; /* keep the nodes sorted by frequency */
  80121. s->heap[--(s->heap_max)] = m;
  80122. tree[node].Freq = tree[n].Freq + tree[m].Freq;
  80123. s->depth[node] = (uch)((s->depth[n] >= s->depth[m] ?
  80124. s->depth[n] : s->depth[m]) + 1);
  80125. tree[n].Dad = tree[m].Dad = (ush)node;
  80126. #ifdef DUMP_BL_TREE
  80127. if (tree == s->bl_tree) {
  80128. fprintf(stderr,"\nnode %d(%d), sons %d(%d) %d(%d)",
  80129. node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq);
  80130. }
  80131. #endif
  80132. s->heap[SMALLEST] = node++;
  80133. pqdownheap(s, tree, SMALLEST);
  80134. } while (s->heap_len >= 2);
  80135. s->heap[--(s->heap_max)] = s->heap[SMALLEST];
  80136. gen_bitlen(s, (tree_desc *)desc);
  80137. gen_codes ((ct_data *)tree, max_code, s->bl_count);
  80138. }
  80139. local void scan_tree (deflate_state *s,
  80140. ct_data *tree, /* the tree to be scanned */
  80141. int max_code) /* and its largest code of non zero frequency */
  80142. {
  80143. int n; /* iterates over all tree elements */
  80144. int prevlen = -1; /* last emitted length */
  80145. int curlen; /* length of current code */
  80146. int nextlen = tree[0].Len; /* length of next code */
  80147. int count = 0; /* repeat count of the current code */
  80148. int max_count = 7; /* max repeat count */
  80149. int min_count = 4; /* min repeat count */
  80150. if (nextlen == 0) max_count = 138, min_count = 3;
  80151. tree[max_code+1].Len = (ush)0xffff; /* guard */
  80152. for (n = 0; n <= max_code; n++) {
  80153. curlen = nextlen; nextlen = tree[n+1].Len;
  80154. if (++count < max_count && curlen == nextlen) {
  80155. continue;
  80156. } else if (count < min_count) {
  80157. s->bl_tree[curlen].Freq += count;
  80158. } else if (curlen != 0) {
  80159. if (curlen != prevlen) s->bl_tree[curlen].Freq++;
  80160. s->bl_tree[REP_3_6].Freq++;
  80161. } else if (count <= 10) {
  80162. s->bl_tree[REPZ_3_10].Freq++;
  80163. } else {
  80164. s->bl_tree[REPZ_11_138].Freq++;
  80165. }
  80166. count = 0; prevlen = curlen;
  80167. if (nextlen == 0) {
  80168. max_count = 138, min_count = 3;
  80169. } else if (curlen == nextlen) {
  80170. max_count = 6, min_count = 3;
  80171. } else {
  80172. max_count = 7, min_count = 4;
  80173. }
  80174. }
  80175. }
  80176. local void send_tree (deflate_state *s,
  80177. ct_data *tree, /* the tree to be scanned */
  80178. int max_code) /* and its largest code of non zero frequency */
  80179. {
  80180. int n; /* iterates over all tree elements */
  80181. int prevlen = -1; /* last emitted length */
  80182. int curlen; /* length of current code */
  80183. int nextlen = tree[0].Len; /* length of next code */
  80184. int count = 0; /* repeat count of the current code */
  80185. int max_count = 7; /* max repeat count */
  80186. int min_count = 4; /* min repeat count */
  80187. /* guard already set */
  80188. if (nextlen == 0) max_count = 138, min_count = 3;
  80189. for (n = 0; n <= max_code; n++) {
  80190. curlen = nextlen; nextlen = tree[n+1].Len;
  80191. if (++count < max_count && curlen == nextlen) {
  80192. continue;
  80193. } else if (count < min_count) {
  80194. do { send_code(s, curlen, s->bl_tree); } while (--count != 0);
  80195. } else if (curlen != 0) {
  80196. if (curlen != prevlen) {
  80197. send_code(s, curlen, s->bl_tree); count--;
  80198. }
  80199. Assert(count >= 3 && count <= 6, " 3_6?");
  80200. send_code(s, REP_3_6, s->bl_tree); send_bits(s, count-3, 2);
  80201. } else if (count <= 10) {
  80202. send_code(s, REPZ_3_10, s->bl_tree); send_bits(s, count-3, 3);
  80203. } else {
  80204. send_code(s, REPZ_11_138, s->bl_tree); send_bits(s, count-11, 7);
  80205. }
  80206. count = 0; prevlen = curlen;
  80207. if (nextlen == 0) {
  80208. max_count = 138, min_count = 3;
  80209. } else if (curlen == nextlen) {
  80210. max_count = 6, min_count = 3;
  80211. } else {
  80212. max_count = 7, min_count = 4;
  80213. }
  80214. }
  80215. }
  80216. local int build_bl_tree (deflate_state *s)
  80217. {
  80218. int max_blindex; /* index of last bit length code of non zero freq */
  80219. scan_tree(s, (ct_data *)s->dyn_ltree, s->l_desc.max_code);
  80220. scan_tree(s, (ct_data *)s->dyn_dtree, s->d_desc.max_code);
  80221. build_tree(s, (tree_desc *)(&(s->bl_desc)));
  80222. for (max_blindex = BL_CODES-1; max_blindex >= 3; max_blindex--) {
  80223. if (s->bl_tree[bl_order[max_blindex]].Len != 0) break;
  80224. }
  80225. s->opt_len += 3*(max_blindex+1) + 5+5+4;
  80226. Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld",
  80227. s->opt_len, s->static_len));
  80228. return max_blindex;
  80229. }
  80230. local void send_all_trees (deflate_state *s,
  80231. int lcodes, int dcodes, int blcodes) /* number of codes for each tree */
  80232. {
  80233. int rank; /* index in bl_order */
  80234. Assert (lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes");
  80235. Assert (lcodes <= L_CODES && dcodes <= D_CODES && blcodes <= BL_CODES,
  80236. "too many codes");
  80237. Tracev((stderr, "\nbl counts: "));
  80238. send_bits(s, lcodes-257, 5); /* not +255 as stated in appnote.txt */
  80239. send_bits(s, dcodes-1, 5);
  80240. send_bits(s, blcodes-4, 4); /* not -3 as stated in appnote.txt */
  80241. for (rank = 0; rank < blcodes; rank++) {
  80242. Tracev((stderr, "\nbl code %2d ", bl_order[rank]));
  80243. send_bits(s, s->bl_tree[bl_order[rank]].Len, 3);
  80244. }
  80245. Tracev((stderr, "\nbl tree: sent %ld", s->bits_sent));
  80246. send_tree(s, (ct_data *)s->dyn_ltree, lcodes-1); /* literal tree */
  80247. Tracev((stderr, "\nlit tree: sent %ld", s->bits_sent));
  80248. send_tree(s, (ct_data *)s->dyn_dtree, dcodes-1); /* distance tree */
  80249. Tracev((stderr, "\ndist tree: sent %ld", s->bits_sent));
  80250. }
  80251. void _tr_stored_block (deflate_state *s, charf *buf, ulg stored_len, int eof)
  80252. {
  80253. send_bits(s, (STORED_BLOCK<<1)+eof, 3); /* send block type */
  80254. #ifdef DEBUG
  80255. s->compressed_len = (s->compressed_len + 3 + 7) & (ulg)~7L;
  80256. s->compressed_len += (stored_len + 4) << 3;
  80257. #endif
  80258. copy_block(s, buf, (unsigned)stored_len, 1); /* with header */
  80259. }
  80260. void _tr_align (deflate_state *s)
  80261. {
  80262. send_bits(s, STATIC_TREES<<1, 3);
  80263. send_code(s, END_BLOCK, static_ltree);
  80264. #ifdef DEBUG
  80265. s->compressed_len += 10L; /* 3 for block type, 7 for EOB */
  80266. #endif
  80267. bi_flush(s);
  80268. if (1 + s->last_eob_len + 10 - s->bi_valid < 9) {
  80269. send_bits(s, STATIC_TREES<<1, 3);
  80270. send_code(s, END_BLOCK, static_ltree);
  80271. #ifdef DEBUG
  80272. s->compressed_len += 10L;
  80273. #endif
  80274. bi_flush(s);
  80275. }
  80276. s->last_eob_len = 7;
  80277. }
  80278. void _tr_flush_block (deflate_state *s,
  80279. charf *buf, /* input block, or NULL if too old */
  80280. ulg stored_len, /* length of input block */
  80281. int eof) /* true if this is the last block for a file */
  80282. {
  80283. ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */
  80284. int max_blindex = 0; /* index of last bit length code of non zero freq */
  80285. if (s->level > 0) {
  80286. if (stored_len > 0 && s->strm->data_type == Z_UNKNOWN)
  80287. set_data_type(s);
  80288. build_tree(s, (tree_desc *)(&(s->l_desc)));
  80289. Tracev((stderr, "\nlit data: dyn %ld, stat %ld", s->opt_len,
  80290. s->static_len));
  80291. build_tree(s, (tree_desc *)(&(s->d_desc)));
  80292. Tracev((stderr, "\ndist data: dyn %ld, stat %ld", s->opt_len,
  80293. s->static_len));
  80294. max_blindex = build_bl_tree(s);
  80295. opt_lenb = (s->opt_len+3+7)>>3;
  80296. static_lenb = (s->static_len+3+7)>>3;
  80297. Tracev((stderr, "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u ",
  80298. opt_lenb, s->opt_len, static_lenb, s->static_len, stored_len,
  80299. s->last_lit));
  80300. if (static_lenb <= opt_lenb) opt_lenb = static_lenb;
  80301. } else {
  80302. Assert(buf != (char*)0, "lost buf");
  80303. opt_lenb = static_lenb = stored_len + 5; /* force a stored block */
  80304. }
  80305. #ifdef FORCE_STORED
  80306. if (buf != (char*)0) { /* force stored block */
  80307. #else
  80308. if (stored_len+4 <= opt_lenb && buf != (char*)0) {
  80309. #endif
  80310. _tr_stored_block(s, buf, stored_len, eof);
  80311. #ifdef FORCE_STATIC
  80312. } else if (static_lenb >= 0) { /* force static trees */
  80313. #else
  80314. } else if (s->strategy == Z_FIXED || static_lenb == opt_lenb) {
  80315. #endif
  80316. send_bits(s, (STATIC_TREES<<1)+eof, 3);
  80317. compress_block(s, (ct_data *)static_ltree, (ct_data *)static_dtree);
  80318. #ifdef DEBUG
  80319. s->compressed_len += 3 + s->static_len;
  80320. #endif
  80321. } else {
  80322. send_bits(s, (DYN_TREES<<1)+eof, 3);
  80323. send_all_trees(s, s->l_desc.max_code+1, s->d_desc.max_code+1,
  80324. max_blindex+1);
  80325. compress_block(s, (ct_data *)s->dyn_ltree, (ct_data *)s->dyn_dtree);
  80326. #ifdef DEBUG
  80327. s->compressed_len += 3 + s->opt_len;
  80328. #endif
  80329. }
  80330. Assert (s->compressed_len == s->bits_sent, "bad compressed size");
  80331. init_block(s);
  80332. if (eof) {
  80333. bi_windup(s);
  80334. #ifdef DEBUG
  80335. s->compressed_len += 7; /* align on byte boundary */
  80336. #endif
  80337. }
  80338. Tracev((stderr,"\ncomprlen %lu(%lu) ", s->compressed_len>>3,
  80339. s->compressed_len-7*eof));
  80340. }
  80341. int _tr_tally (deflate_state *s,
  80342. unsigned dist, /* distance of matched string */
  80343. unsigned lc) /* match length-MIN_MATCH or unmatched char (if dist==0) */
  80344. {
  80345. s->d_buf[s->last_lit] = (ush)dist;
  80346. s->l_buf[s->last_lit++] = (uch)lc;
  80347. if (dist == 0) {
  80348. s->dyn_ltree[lc].Freq++;
  80349. } else {
  80350. s->matches++;
  80351. dist--; /* dist = match distance - 1 */
  80352. Assert((ush)dist < (ush)MAX_DIST(s) &&
  80353. (ush)lc <= (ush)(MAX_MATCH-MIN_MATCH) &&
  80354. (ush)d_code(dist) < (ush)D_CODES, "_tr_tally: bad match");
  80355. s->dyn_ltree[_length_code[lc]+LITERALS+1].Freq++;
  80356. s->dyn_dtree[d_code(dist)].Freq++;
  80357. }
  80358. #ifdef TRUNCATE_BLOCK
  80359. if ((s->last_lit & 0x1fff) == 0 && s->level > 2) {
  80360. ulg out_length = (ulg)s->last_lit*8L;
  80361. ulg in_length = (ulg)((long)s->strstart - s->block_start);
  80362. int dcode;
  80363. for (dcode = 0; dcode < D_CODES; dcode++) {
  80364. out_length += (ulg)s->dyn_dtree[dcode].Freq *
  80365. (5L+extra_dbits[dcode]);
  80366. }
  80367. out_length >>= 3;
  80368. Tracev((stderr,"\nlast_lit %u, in %ld, out ~%ld(%ld%%) ",
  80369. s->last_lit, in_length, out_length,
  80370. 100L - out_length*100L/in_length));
  80371. if (s->matches < s->last_lit/2 && out_length < in_length/2) return 1;
  80372. }
  80373. #endif
  80374. return (s->last_lit == s->lit_bufsize-1);
  80375. }
  80376. local void compress_block (deflate_state *s,
  80377. ct_data *ltree, /* literal tree */
  80378. ct_data *dtree) /* distance tree */
  80379. {
  80380. unsigned dist; /* distance of matched string */
  80381. int lc; /* match length or unmatched char (if dist == 0) */
  80382. unsigned lx = 0; /* running index in l_buf */
  80383. unsigned code; /* the code to send */
  80384. int extra; /* number of extra bits to send */
  80385. if (s->last_lit != 0) do {
  80386. dist = s->d_buf[lx];
  80387. lc = s->l_buf[lx++];
  80388. if (dist == 0) {
  80389. send_code(s, lc, ltree); /* send a literal byte */
  80390. Tracecv(isgraph(lc), (stderr," '%c' ", lc));
  80391. } else {
  80392. code = _length_code[lc];
  80393. send_code(s, code+LITERALS+1, ltree); /* send the length code */
  80394. extra = extra_lbits[code];
  80395. if (extra != 0) {
  80396. lc -= base_length[code];
  80397. send_bits(s, lc, extra); /* send the extra length bits */
  80398. }
  80399. dist--; /* dist is now the match distance - 1 */
  80400. code = d_code(dist);
  80401. Assert (code < D_CODES, "bad d_code");
  80402. send_code(s, code, dtree); /* send the distance code */
  80403. extra = extra_dbits[code];
  80404. if (extra != 0) {
  80405. dist -= base_dist[code];
  80406. send_bits(s, dist, extra); /* send the extra distance bits */
  80407. }
  80408. } /* literal or match pair ? */
  80409. Assert((uInt)(s->pending) < s->lit_bufsize + 2*lx,
  80410. "pendingBuf overflow");
  80411. } while (lx < s->last_lit);
  80412. send_code(s, END_BLOCK, ltree);
  80413. s->last_eob_len = ltree[END_BLOCK].Len;
  80414. }
  80415. local void set_data_type (deflate_state *s)
  80416. {
  80417. int n;
  80418. for (n = 0; n < 9; n++)
  80419. if (s->dyn_ltree[n].Freq != 0)
  80420. break;
  80421. if (n == 9)
  80422. for (n = 14; n < 32; n++)
  80423. if (s->dyn_ltree[n].Freq != 0)
  80424. break;
  80425. s->strm->data_type = (n == 32) ? Z_TEXT : Z_BINARY;
  80426. }
  80427. local unsigned bi_reverse (unsigned code, int len)
  80428. {
  80429. register unsigned res = 0;
  80430. do {
  80431. res |= code & 1;
  80432. code >>= 1, res <<= 1;
  80433. } while (--len > 0);
  80434. return res >> 1;
  80435. }
  80436. local void bi_flush (deflate_state *s)
  80437. {
  80438. if (s->bi_valid == 16) {
  80439. put_short(s, s->bi_buf);
  80440. s->bi_buf = 0;
  80441. s->bi_valid = 0;
  80442. } else if (s->bi_valid >= 8) {
  80443. put_byte(s, (Byte)s->bi_buf);
  80444. s->bi_buf >>= 8;
  80445. s->bi_valid -= 8;
  80446. }
  80447. }
  80448. local void bi_windup (deflate_state *s)
  80449. {
  80450. if (s->bi_valid > 8) {
  80451. put_short(s, s->bi_buf);
  80452. } else if (s->bi_valid > 0) {
  80453. put_byte(s, (Byte)s->bi_buf);
  80454. }
  80455. s->bi_buf = 0;
  80456. s->bi_valid = 0;
  80457. #ifdef DEBUG
  80458. s->bits_sent = (s->bits_sent+7) & ~7;
  80459. #endif
  80460. }
  80461. local void copy_block(deflate_state *s,
  80462. charf *buf, /* the input data */
  80463. unsigned len, /* its length */
  80464. int header) /* true if block header must be written */
  80465. {
  80466. bi_windup(s); /* align on byte boundary */
  80467. s->last_eob_len = 8; /* enough lookahead for inflate */
  80468. if (header) {
  80469. put_short(s, (ush)len);
  80470. put_short(s, (ush)~len);
  80471. #ifdef DEBUG
  80472. s->bits_sent += 2*16;
  80473. #endif
  80474. }
  80475. #ifdef DEBUG
  80476. s->bits_sent += (ulg)len<<3;
  80477. #endif
  80478. while (len--) {
  80479. put_byte(s, *buf++);
  80480. }
  80481. }
  80482. /*** End of inlined file: trees.c ***/
  80483. /*** Start of inlined file: zutil.c ***/
  80484. #ifndef NO_DUMMY_DECL
  80485. struct internal_state {int dummy;}; /* for buggy compilers */
  80486. #endif
  80487. const char * const z_errmsg[10] = {
  80488. "need dictionary", /* Z_NEED_DICT 2 */
  80489. "stream end", /* Z_STREAM_END 1 */
  80490. "", /* Z_OK 0 */
  80491. "file error", /* Z_ERRNO (-1) */
  80492. "stream error", /* Z_STREAM_ERROR (-2) */
  80493. "data error", /* Z_DATA_ERROR (-3) */
  80494. "insufficient memory", /* Z_MEM_ERROR (-4) */
  80495. "buffer error", /* Z_BUF_ERROR (-5) */
  80496. "incompatible version",/* Z_VERSION_ERROR (-6) */
  80497. ""};
  80498. #ifdef DEBUG
  80499. # ifndef verbose
  80500. # define verbose 0
  80501. # endif
  80502. int z_verbose = verbose;
  80503. void z_error (const char *m)
  80504. {
  80505. fprintf(stderr, "%s\n", m);
  80506. exit(1);
  80507. }
  80508. #endif
  80509. const char * ZEXPORT zError(int err)
  80510. {
  80511. return ERR_MSG(err);
  80512. }
  80513. #if defined(_WIN32_WCE)
  80514. int errno = 0;
  80515. #endif
  80516. #ifndef HAVE_MEMCPY
  80517. void zmemcpy(dest, source, len)
  80518. Bytef* dest;
  80519. const Bytef* source;
  80520. uInt len;
  80521. {
  80522. if (len == 0) return;
  80523. do {
  80524. *dest++ = *source++; /* ??? to be unrolled */
  80525. } while (--len != 0);
  80526. }
  80527. int zmemcmp(s1, s2, len)
  80528. const Bytef* s1;
  80529. const Bytef* s2;
  80530. uInt len;
  80531. {
  80532. uInt j;
  80533. for (j = 0; j < len; j++) {
  80534. if (s1[j] != s2[j]) return 2*(s1[j] > s2[j])-1;
  80535. }
  80536. return 0;
  80537. }
  80538. void zmemzero(dest, len)
  80539. Bytef* dest;
  80540. uInt len;
  80541. {
  80542. if (len == 0) return;
  80543. do {
  80544. *dest++ = 0; /* ??? to be unrolled */
  80545. } while (--len != 0);
  80546. }
  80547. #endif
  80548. #ifdef SYS16BIT
  80549. #ifdef __TURBOC__
  80550. # define MY_ZCALLOC
  80551. #define MAX_PTR 10
  80552. local int next_ptr = 0;
  80553. typedef struct ptr_table_s {
  80554. voidpf org_ptr;
  80555. voidpf new_ptr;
  80556. } ptr_table;
  80557. local ptr_table table[MAX_PTR];
  80558. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80559. {
  80560. voidpf buf = opaque; /* just to make some compilers happy */
  80561. ulg bsize = (ulg)items*size;
  80562. if (bsize < 65520L) {
  80563. buf = farmalloc(bsize);
  80564. if (*(ush*)&buf != 0) return buf;
  80565. } else {
  80566. buf = farmalloc(bsize + 16L);
  80567. }
  80568. if (buf == NULL || next_ptr >= MAX_PTR) return NULL;
  80569. table[next_ptr].org_ptr = buf;
  80570. *((ush*)&buf+1) += ((ush)((uch*)buf-0) + 15) >> 4;
  80571. *(ush*)&buf = 0;
  80572. table[next_ptr++].new_ptr = buf;
  80573. return buf;
  80574. }
  80575. void zcfree (voidpf opaque, voidpf ptr)
  80576. {
  80577. int n;
  80578. if (*(ush*)&ptr != 0) { /* object < 64K */
  80579. farfree(ptr);
  80580. return;
  80581. }
  80582. for (n = 0; n < next_ptr; n++) {
  80583. if (ptr != table[n].new_ptr) continue;
  80584. farfree(table[n].org_ptr);
  80585. while (++n < next_ptr) {
  80586. table[n-1] = table[n];
  80587. }
  80588. next_ptr--;
  80589. return;
  80590. }
  80591. ptr = opaque; /* just to make some compilers happy */
  80592. Assert(0, "zcfree: ptr not found");
  80593. }
  80594. #endif /* __TURBOC__ */
  80595. #ifdef M_I86
  80596. # define MY_ZCALLOC
  80597. #if (!defined(_MSC_VER) || (_MSC_VER <= 600))
  80598. # define _halloc halloc
  80599. # define _hfree hfree
  80600. #endif
  80601. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80602. {
  80603. if (opaque) opaque = 0; /* to make compiler happy */
  80604. return _halloc((long)items, size);
  80605. }
  80606. void zcfree (voidpf opaque, voidpf ptr)
  80607. {
  80608. if (opaque) opaque = 0; /* to make compiler happy */
  80609. _hfree(ptr);
  80610. }
  80611. #endif /* M_I86 */
  80612. #endif /* SYS16BIT */
  80613. #ifndef MY_ZCALLOC /* Any system without a special alloc function */
  80614. #ifndef STDC
  80615. extern voidp malloc OF((uInt size));
  80616. extern voidp calloc OF((uInt items, uInt size));
  80617. extern void free OF((voidpf ptr));
  80618. #endif
  80619. voidpf zcalloc (voidpf opaque, unsigned items, unsigned size)
  80620. {
  80621. if (opaque) items += size - size; /* make compiler happy */
  80622. return sizeof(uInt) > 2 ? (voidpf)malloc(items * size) :
  80623. (voidpf)calloc(items, size);
  80624. }
  80625. void zcfree (voidpf opaque, voidpf ptr)
  80626. {
  80627. free(ptr);
  80628. if (opaque) return; /* make compiler happy */
  80629. }
  80630. #endif /* MY_ZCALLOC */
  80631. /*** End of inlined file: zutil.c ***/
  80632. #undef Byte
  80633. }
  80634. #else
  80635. #include <zlib.h>
  80636. #endif
  80637. }
  80638. #if JUCE_MSVC
  80639. #pragma warning (pop)
  80640. #endif
  80641. BEGIN_JUCE_NAMESPACE
  80642. using namespace zlibNamespace;
  80643. // internal helper object that holds the zlib structures so they don't have to be
  80644. // included publicly.
  80645. class GZIPDecompressHelper
  80646. {
  80647. public:
  80648. GZIPDecompressHelper (const bool noWrap) throw()
  80649. : data (0),
  80650. dataSize (0),
  80651. finished (true),
  80652. needsDictionary (false),
  80653. error (true),
  80654. streamIsValid (false)
  80655. {
  80656. zerostruct (stream);
  80657. streamIsValid = (inflateInit2 (&stream, noWrap ? -MAX_WBITS : MAX_WBITS) == Z_OK);
  80658. finished = error = ! streamIsValid;
  80659. }
  80660. ~GZIPDecompressHelper() throw()
  80661. {
  80662. if (streamIsValid)
  80663. inflateEnd (&stream);
  80664. }
  80665. bool needsInput() const throw() { return dataSize <= 0; }
  80666. void setInput (uint8* const data_, const int size) throw()
  80667. {
  80668. data = data_;
  80669. dataSize = size;
  80670. }
  80671. int doNextBlock (uint8* const dest, const int destSize) throw()
  80672. {
  80673. if (streamIsValid && data != 0 && ! finished)
  80674. {
  80675. stream.next_in = data;
  80676. stream.next_out = dest;
  80677. stream.avail_in = dataSize;
  80678. stream.avail_out = destSize;
  80679. switch (inflate (&stream, Z_PARTIAL_FLUSH))
  80680. {
  80681. case Z_STREAM_END:
  80682. finished = true;
  80683. // deliberate fall-through
  80684. case Z_OK:
  80685. data += dataSize - stream.avail_in;
  80686. dataSize = stream.avail_in;
  80687. return destSize - stream.avail_out;
  80688. case Z_NEED_DICT:
  80689. needsDictionary = true;
  80690. data += dataSize - stream.avail_in;
  80691. dataSize = stream.avail_in;
  80692. break;
  80693. case Z_DATA_ERROR:
  80694. case Z_MEM_ERROR:
  80695. error = true;
  80696. default:
  80697. break;
  80698. }
  80699. }
  80700. return 0;
  80701. }
  80702. private:
  80703. z_stream stream;
  80704. uint8* data;
  80705. int dataSize;
  80706. public:
  80707. bool finished, needsDictionary, error, streamIsValid;
  80708. };
  80709. const int gzipDecompBufferSize = 32768;
  80710. GZIPDecompressorInputStream::GZIPDecompressorInputStream (InputStream* const sourceStream_,
  80711. const bool deleteSourceWhenDestroyed,
  80712. const bool noWrap_,
  80713. const int64 uncompressedStreamLength_)
  80714. : sourceStream (sourceStream_),
  80715. streamToDelete (deleteSourceWhenDestroyed ? sourceStream_ : 0),
  80716. uncompressedStreamLength (uncompressedStreamLength_),
  80717. noWrap (noWrap_),
  80718. isEof (false),
  80719. activeBufferSize (0),
  80720. originalSourcePos (sourceStream_->getPosition()),
  80721. currentPos (0),
  80722. buffer (gzipDecompBufferSize),
  80723. helper (new GZIPDecompressHelper (noWrap_))
  80724. {
  80725. }
  80726. GZIPDecompressorInputStream::~GZIPDecompressorInputStream()
  80727. {
  80728. }
  80729. int64 GZIPDecompressorInputStream::getTotalLength()
  80730. {
  80731. return uncompressedStreamLength;
  80732. }
  80733. int GZIPDecompressorInputStream::read (void* destBuffer, int howMany)
  80734. {
  80735. if ((howMany > 0) && ! isEof)
  80736. {
  80737. jassert (destBuffer != 0);
  80738. if (destBuffer != 0)
  80739. {
  80740. int numRead = 0;
  80741. uint8* d = (uint8*) destBuffer;
  80742. while (! helper->error)
  80743. {
  80744. const int n = helper->doNextBlock (d, howMany);
  80745. currentPos += n;
  80746. if (n == 0)
  80747. {
  80748. if (helper->finished || helper->needsDictionary)
  80749. {
  80750. isEof = true;
  80751. return numRead;
  80752. }
  80753. if (helper->needsInput())
  80754. {
  80755. activeBufferSize = sourceStream->read (buffer, gzipDecompBufferSize);
  80756. if (activeBufferSize > 0)
  80757. {
  80758. helper->setInput ((uint8*) buffer, activeBufferSize);
  80759. }
  80760. else
  80761. {
  80762. isEof = true;
  80763. return numRead;
  80764. }
  80765. }
  80766. }
  80767. else
  80768. {
  80769. numRead += n;
  80770. howMany -= n;
  80771. d += n;
  80772. if (howMany <= 0)
  80773. return numRead;
  80774. }
  80775. }
  80776. }
  80777. }
  80778. return 0;
  80779. }
  80780. bool GZIPDecompressorInputStream::isExhausted()
  80781. {
  80782. return helper->error || isEof;
  80783. }
  80784. int64 GZIPDecompressorInputStream::getPosition()
  80785. {
  80786. return currentPos;
  80787. }
  80788. bool GZIPDecompressorInputStream::setPosition (int64 newPos)
  80789. {
  80790. if (newPos < currentPos)
  80791. {
  80792. // to go backwards, reset the stream and start again..
  80793. isEof = false;
  80794. activeBufferSize = 0;
  80795. currentPos = 0;
  80796. helper = new GZIPDecompressHelper (noWrap);
  80797. sourceStream->setPosition (originalSourcePos);
  80798. }
  80799. skipNextBytes (newPos - currentPos);
  80800. return true;
  80801. }
  80802. END_JUCE_NAMESPACE
  80803. /*** End of inlined file: juce_GZIPDecompressorInputStream.cpp ***/
  80804. #endif
  80805. #if JUCE_BUILD_NATIVE && ! JUCE_ONLY_BUILD_CORE_LIBRARY
  80806. /*** Start of inlined file: juce_FlacAudioFormat.cpp ***/
  80807. #if JUCE_USE_FLAC
  80808. #if JUCE_WINDOWS
  80809. #include <windows.h>
  80810. #endif
  80811. #ifdef _MSC_VER
  80812. #pragma warning (disable : 4505)
  80813. #pragma warning (push)
  80814. #endif
  80815. namespace FlacNamespace
  80816. {
  80817. #if JUCE_INCLUDE_FLAC_CODE
  80818. #define FLAC__NO_DLL 1
  80819. #if ! defined (SIZE_MAX)
  80820. #define SIZE_MAX 0xffffffff
  80821. #endif
  80822. #define __STDC_LIMIT_MACROS 1
  80823. /*** Start of inlined file: all.h ***/
  80824. #ifndef FLAC__ALL_H
  80825. #define FLAC__ALL_H
  80826. /*** Start of inlined file: export.h ***/
  80827. #ifndef FLAC__EXPORT_H
  80828. #define FLAC__EXPORT_H
  80829. #if defined(FLAC__NO_DLL) || !defined(_MSC_VER)
  80830. #define FLAC_API
  80831. #else
  80832. #ifdef FLAC_API_EXPORTS
  80833. #define FLAC_API _declspec(dllexport)
  80834. #else
  80835. #define FLAC_API _declspec(dllimport)
  80836. #endif
  80837. #endif
  80838. #define FLAC_API_VERSION_CURRENT 10
  80839. #define FLAC_API_VERSION_REVISION 0 /**< see above */
  80840. #define FLAC_API_VERSION_AGE 2 /**< see above */
  80841. #ifdef __cplusplus
  80842. extern "C" {
  80843. #endif
  80844. extern FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC;
  80845. #ifdef __cplusplus
  80846. }
  80847. #endif
  80848. #endif
  80849. /*** End of inlined file: export.h ***/
  80850. /*** Start of inlined file: assert.h ***/
  80851. #ifndef FLAC__ASSERT_H
  80852. #define FLAC__ASSERT_H
  80853. /* we need this since some compilers (like MSVC) leave assert()s on release code (and we don't want to use their ASSERT) */
  80854. #ifdef DEBUG
  80855. #include <assert.h>
  80856. #define FLAC__ASSERT(x) assert(x)
  80857. #define FLAC__ASSERT_DECLARATION(x) x
  80858. #else
  80859. #define FLAC__ASSERT(x)
  80860. #define FLAC__ASSERT_DECLARATION(x)
  80861. #endif
  80862. #endif
  80863. /*** End of inlined file: assert.h ***/
  80864. /*** Start of inlined file: callback.h ***/
  80865. #ifndef FLAC__CALLBACK_H
  80866. #define FLAC__CALLBACK_H
  80867. /*** Start of inlined file: ordinals.h ***/
  80868. #ifndef FLAC__ORDINALS_H
  80869. #define FLAC__ORDINALS_H
  80870. #if !(defined(_MSC_VER) || defined(__BORLANDC__) || defined(__EMX__))
  80871. #include <inttypes.h>
  80872. #endif
  80873. typedef signed char FLAC__int8;
  80874. typedef unsigned char FLAC__uint8;
  80875. #if defined(_MSC_VER) || defined(__BORLANDC__)
  80876. typedef __int16 FLAC__int16;
  80877. typedef __int32 FLAC__int32;
  80878. typedef __int64 FLAC__int64;
  80879. typedef unsigned __int16 FLAC__uint16;
  80880. typedef unsigned __int32 FLAC__uint32;
  80881. typedef unsigned __int64 FLAC__uint64;
  80882. #elif defined(__EMX__)
  80883. typedef short FLAC__int16;
  80884. typedef long FLAC__int32;
  80885. typedef long long FLAC__int64;
  80886. typedef unsigned short FLAC__uint16;
  80887. typedef unsigned long FLAC__uint32;
  80888. typedef unsigned long long FLAC__uint64;
  80889. #else
  80890. typedef int16_t FLAC__int16;
  80891. typedef int32_t FLAC__int32;
  80892. typedef int64_t FLAC__int64;
  80893. typedef uint16_t FLAC__uint16;
  80894. typedef uint32_t FLAC__uint32;
  80895. typedef uint64_t FLAC__uint64;
  80896. #endif
  80897. typedef int FLAC__bool;
  80898. typedef FLAC__uint8 FLAC__byte;
  80899. #ifdef true
  80900. #undef true
  80901. #endif
  80902. #ifdef false
  80903. #undef false
  80904. #endif
  80905. #ifndef __cplusplus
  80906. #define true 1
  80907. #define false 0
  80908. #endif
  80909. #endif
  80910. /*** End of inlined file: ordinals.h ***/
  80911. #include <stdlib.h> /* for size_t */
  80912. #ifdef __cplusplus
  80913. extern "C" {
  80914. #endif
  80915. typedef void* FLAC__IOHandle;
  80916. typedef size_t (*FLAC__IOCallback_Read) (void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80917. typedef size_t (*FLAC__IOCallback_Write) (const void *ptr, size_t size, size_t nmemb, FLAC__IOHandle handle);
  80918. typedef int (*FLAC__IOCallback_Seek) (FLAC__IOHandle handle, FLAC__int64 offset, int whence);
  80919. typedef FLAC__int64 (*FLAC__IOCallback_Tell) (FLAC__IOHandle handle);
  80920. typedef int (*FLAC__IOCallback_Eof) (FLAC__IOHandle handle);
  80921. typedef int (*FLAC__IOCallback_Close) (FLAC__IOHandle handle);
  80922. typedef struct {
  80923. FLAC__IOCallback_Read read;
  80924. FLAC__IOCallback_Write write;
  80925. FLAC__IOCallback_Seek seek;
  80926. FLAC__IOCallback_Tell tell;
  80927. FLAC__IOCallback_Eof eof;
  80928. FLAC__IOCallback_Close close;
  80929. } FLAC__IOCallbacks;
  80930. #ifdef __cplusplus
  80931. }
  80932. #endif
  80933. #endif
  80934. /*** End of inlined file: callback.h ***/
  80935. /*** Start of inlined file: format.h ***/
  80936. #ifndef FLAC__FORMAT_H
  80937. #define FLAC__FORMAT_H
  80938. #ifdef __cplusplus
  80939. extern "C" {
  80940. #endif
  80941. #define FLAC__MAX_METADATA_TYPE_CODE (126u)
  80942. #define FLAC__MIN_BLOCK_SIZE (16u)
  80943. #define FLAC__MAX_BLOCK_SIZE (65535u)
  80944. #define FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ (4608u)
  80945. #define FLAC__MAX_CHANNELS (8u)
  80946. #define FLAC__MIN_BITS_PER_SAMPLE (4u)
  80947. #define FLAC__MAX_BITS_PER_SAMPLE (32u)
  80948. #define FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE (24u)
  80949. #define FLAC__MAX_SAMPLE_RATE (655350u)
  80950. #define FLAC__MAX_LPC_ORDER (32u)
  80951. #define FLAC__SUBSET_MAX_LPC_ORDER_48000HZ (12u)
  80952. #define FLAC__MIN_QLP_COEFF_PRECISION (5u)
  80953. #define FLAC__MAX_QLP_COEFF_PRECISION (15u)
  80954. #define FLAC__MAX_FIXED_ORDER (4u)
  80955. #define FLAC__MAX_RICE_PARTITION_ORDER (15u)
  80956. #define FLAC__SUBSET_MAX_RICE_PARTITION_ORDER (8u)
  80957. extern FLAC_API const char *FLAC__VERSION_STRING;
  80958. extern FLAC_API const char *FLAC__VENDOR_STRING;
  80959. extern FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4]; /* = "fLaC" */
  80960. extern FLAC_API const unsigned FLAC__STREAM_SYNC; /* = 0x664C6143 */
  80961. extern FLAC_API const unsigned FLAC__STREAM_SYNC_LEN; /* = 32 bits */
  80962. #define FLAC__STREAM_SYNC_LENGTH (4u)
  80963. typedef enum {
  80964. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE = 0,
  80965. FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2 = 1
  80966. } FLAC__EntropyCodingMethodType;
  80967. extern FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[];
  80968. typedef struct {
  80969. unsigned *parameters;
  80970. unsigned *raw_bits;
  80971. unsigned capacity_by_order;
  80972. } FLAC__EntropyCodingMethod_PartitionedRiceContents;
  80973. typedef struct {
  80974. unsigned order;
  80975. const FLAC__EntropyCodingMethod_PartitionedRiceContents *contents;
  80976. } FLAC__EntropyCodingMethod_PartitionedRice;
  80977. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN; /**< == 4 (bits) */
  80978. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN; /**< == 4 (bits) */
  80979. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN; /**< == 5 (bits) */
  80980. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN; /**< == 5 (bits) */
  80981. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  80982. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER;
  80983. typedef struct {
  80984. FLAC__EntropyCodingMethodType type;
  80985. union {
  80986. FLAC__EntropyCodingMethod_PartitionedRice partitioned_rice;
  80987. } data;
  80988. } FLAC__EntropyCodingMethod;
  80989. extern FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN; /**< == 2 (bits) */
  80990. typedef enum {
  80991. FLAC__SUBFRAME_TYPE_CONSTANT = 0, /**< constant signal */
  80992. FLAC__SUBFRAME_TYPE_VERBATIM = 1, /**< uncompressed signal */
  80993. FLAC__SUBFRAME_TYPE_FIXED = 2, /**< fixed polynomial prediction */
  80994. FLAC__SUBFRAME_TYPE_LPC = 3 /**< linear prediction */
  80995. } FLAC__SubframeType;
  80996. extern FLAC_API const char * const FLAC__SubframeTypeString[];
  80997. typedef struct {
  80998. FLAC__int32 value; /**< The constant signal value. */
  80999. } FLAC__Subframe_Constant;
  81000. typedef struct {
  81001. const FLAC__int32 *data; /**< A pointer to verbatim signal. */
  81002. } FLAC__Subframe_Verbatim;
  81003. typedef struct {
  81004. FLAC__EntropyCodingMethod entropy_coding_method;
  81005. unsigned order;
  81006. FLAC__int32 warmup[FLAC__MAX_FIXED_ORDER];
  81007. const FLAC__int32 *residual;
  81008. } FLAC__Subframe_Fixed;
  81009. typedef struct {
  81010. FLAC__EntropyCodingMethod entropy_coding_method;
  81011. unsigned order;
  81012. unsigned qlp_coeff_precision;
  81013. int quantization_level;
  81014. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  81015. FLAC__int32 warmup[FLAC__MAX_LPC_ORDER];
  81016. const FLAC__int32 *residual;
  81017. } FLAC__Subframe_LPC;
  81018. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN; /**< == 4 (bits) */
  81019. extern FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN; /**< == 5 (bits) */
  81020. typedef struct {
  81021. FLAC__SubframeType type;
  81022. union {
  81023. FLAC__Subframe_Constant constant;
  81024. FLAC__Subframe_Fixed fixed;
  81025. FLAC__Subframe_LPC lpc;
  81026. FLAC__Subframe_Verbatim verbatim;
  81027. } data;
  81028. unsigned wasted_bits;
  81029. } FLAC__Subframe;
  81030. extern FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN;
  81031. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN; /**< == 6 (bits) */
  81032. extern FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN; /**< == 1 (bit) */
  81033. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK; /**< = 0x00 */
  81034. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK; /**< = 0x02 */
  81035. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK; /**< = 0x10 */
  81036. extern FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK; /**< = 0x40 */
  81037. typedef enum {
  81038. FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT = 0, /**< independent channels */
  81039. FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE = 1, /**< left+side stereo */
  81040. FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE = 2, /**< right+side stereo */
  81041. FLAC__CHANNEL_ASSIGNMENT_MID_SIDE = 3 /**< mid+side stereo */
  81042. } FLAC__ChannelAssignment;
  81043. extern FLAC_API const char * const FLAC__ChannelAssignmentString[];
  81044. typedef enum {
  81045. FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER, /**< number contains the frame number */
  81046. FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER /**< number contains the sample number of first sample in frame */
  81047. } FLAC__FrameNumberType;
  81048. extern FLAC_API const char * const FLAC__FrameNumberTypeString[];
  81049. typedef struct {
  81050. unsigned blocksize;
  81051. unsigned sample_rate;
  81052. unsigned channels;
  81053. FLAC__ChannelAssignment channel_assignment;
  81054. unsigned bits_per_sample;
  81055. FLAC__FrameNumberType number_type;
  81056. union {
  81057. FLAC__uint32 frame_number;
  81058. FLAC__uint64 sample_number;
  81059. } number;
  81060. FLAC__uint8 crc;
  81061. } FLAC__FrameHeader;
  81062. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC; /**< == 0x3ffe; the frame header sync code */
  81063. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN; /**< == 14 (bits) */
  81064. extern FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN; /**< == 1 (bits) */
  81065. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN; /**< == 1 (bits) */
  81066. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN; /**< == 4 (bits) */
  81067. extern FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN; /**< == 4 (bits) */
  81068. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN; /**< == 4 (bits) */
  81069. extern FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN; /**< == 3 (bits) */
  81070. extern FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN; /**< == 1 (bit) */
  81071. extern FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN; /**< == 8 (bits) */
  81072. typedef struct {
  81073. FLAC__uint16 crc;
  81074. } FLAC__FrameFooter;
  81075. extern FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN; /**< == 16 (bits) */
  81076. typedef struct {
  81077. FLAC__FrameHeader header;
  81078. FLAC__Subframe subframes[FLAC__MAX_CHANNELS];
  81079. FLAC__FrameFooter footer;
  81080. } FLAC__Frame;
  81081. typedef enum {
  81082. FLAC__METADATA_TYPE_STREAMINFO = 0,
  81083. FLAC__METADATA_TYPE_PADDING = 1,
  81084. FLAC__METADATA_TYPE_APPLICATION = 2,
  81085. FLAC__METADATA_TYPE_SEEKTABLE = 3,
  81086. FLAC__METADATA_TYPE_VORBIS_COMMENT = 4,
  81087. FLAC__METADATA_TYPE_CUESHEET = 5,
  81088. FLAC__METADATA_TYPE_PICTURE = 6,
  81089. FLAC__METADATA_TYPE_UNDEFINED = 7
  81090. } FLAC__MetadataType;
  81091. extern FLAC_API const char * const FLAC__MetadataTypeString[];
  81092. typedef struct {
  81093. unsigned min_blocksize, max_blocksize;
  81094. unsigned min_framesize, max_framesize;
  81095. unsigned sample_rate;
  81096. unsigned channels;
  81097. unsigned bits_per_sample;
  81098. FLAC__uint64 total_samples;
  81099. FLAC__byte md5sum[16];
  81100. } FLAC__StreamMetadata_StreamInfo;
  81101. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  81102. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN; /**< == 16 (bits) */
  81103. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN; /**< == 24 (bits) */
  81104. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN; /**< == 24 (bits) */
  81105. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN; /**< == 20 (bits) */
  81106. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN; /**< == 3 (bits) */
  81107. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN; /**< == 5 (bits) */
  81108. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN; /**< == 36 (bits) */
  81109. extern FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN; /**< == 128 (bits) */
  81110. #define FLAC__STREAM_METADATA_STREAMINFO_LENGTH (34u)
  81111. typedef struct {
  81112. int dummy;
  81113. } FLAC__StreamMetadata_Padding;
  81114. typedef struct {
  81115. FLAC__byte id[4];
  81116. FLAC__byte *data;
  81117. } FLAC__StreamMetadata_Application;
  81118. extern FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN; /**< == 32 (bits) */
  81119. typedef struct {
  81120. FLAC__uint64 sample_number;
  81121. FLAC__uint64 stream_offset;
  81122. unsigned frame_samples;
  81123. } FLAC__StreamMetadata_SeekPoint;
  81124. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN; /**< == 64 (bits) */
  81125. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN; /**< == 64 (bits) */
  81126. extern FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN; /**< == 16 (bits) */
  81127. #define FLAC__STREAM_METADATA_SEEKPOINT_LENGTH (18u)
  81128. extern FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  81129. typedef struct {
  81130. unsigned num_points;
  81131. FLAC__StreamMetadata_SeekPoint *points;
  81132. } FLAC__StreamMetadata_SeekTable;
  81133. typedef struct {
  81134. FLAC__uint32 length;
  81135. FLAC__byte *entry;
  81136. } FLAC__StreamMetadata_VorbisComment_Entry;
  81137. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN; /**< == 32 (bits) */
  81138. typedef struct {
  81139. FLAC__StreamMetadata_VorbisComment_Entry vendor_string;
  81140. FLAC__uint32 num_comments;
  81141. FLAC__StreamMetadata_VorbisComment_Entry *comments;
  81142. } FLAC__StreamMetadata_VorbisComment;
  81143. extern FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN; /**< == 32 (bits) */
  81144. typedef struct {
  81145. FLAC__uint64 offset;
  81146. FLAC__byte number;
  81147. } FLAC__StreamMetadata_CueSheet_Index;
  81148. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN; /**< == 64 (bits) */
  81149. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN; /**< == 8 (bits) */
  81150. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN; /**< == 3*8 (bits) */
  81151. typedef struct {
  81152. FLAC__uint64 offset;
  81153. FLAC__byte number;
  81154. char isrc[13];
  81155. unsigned type:1;
  81156. unsigned pre_emphasis:1;
  81157. FLAC__byte num_indices;
  81158. FLAC__StreamMetadata_CueSheet_Index *indices;
  81159. } FLAC__StreamMetadata_CueSheet_Track;
  81160. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN; /**< == 64 (bits) */
  81161. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN; /**< == 8 (bits) */
  81162. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN; /**< == 12*8 (bits) */
  81163. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN; /**< == 1 (bit) */
  81164. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN; /**< == 1 (bit) */
  81165. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN; /**< == 6+13*8 (bits) */
  81166. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN; /**< == 8 (bits) */
  81167. typedef struct {
  81168. char media_catalog_number[129];
  81169. FLAC__uint64 lead_in;
  81170. FLAC__bool is_cd;
  81171. unsigned num_tracks;
  81172. FLAC__StreamMetadata_CueSheet_Track *tracks;
  81173. } FLAC__StreamMetadata_CueSheet;
  81174. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN; /**< == 128*8 (bits) */
  81175. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN; /**< == 64 (bits) */
  81176. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN; /**< == 1 (bit) */
  81177. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN; /**< == 7+258*8 (bits) */
  81178. extern FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN; /**< == 8 (bits) */
  81179. typedef enum {
  81180. FLAC__STREAM_METADATA_PICTURE_TYPE_OTHER = 0, /**< Other */
  81181. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD = 1, /**< 32x32 pixels 'file icon' (PNG only) */
  81182. FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON = 2, /**< Other file icon */
  81183. FLAC__STREAM_METADATA_PICTURE_TYPE_FRONT_COVER = 3, /**< Cover (front) */
  81184. FLAC__STREAM_METADATA_PICTURE_TYPE_BACK_COVER = 4, /**< Cover (back) */
  81185. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAFLET_PAGE = 5, /**< Leaflet page */
  81186. FLAC__STREAM_METADATA_PICTURE_TYPE_MEDIA = 6, /**< Media (e.g. label side of CD) */
  81187. FLAC__STREAM_METADATA_PICTURE_TYPE_LEAD_ARTIST = 7, /**< Lead artist/lead performer/soloist */
  81188. FLAC__STREAM_METADATA_PICTURE_TYPE_ARTIST = 8, /**< Artist/performer */
  81189. FLAC__STREAM_METADATA_PICTURE_TYPE_CONDUCTOR = 9, /**< Conductor */
  81190. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND = 10, /**< Band/Orchestra */
  81191. FLAC__STREAM_METADATA_PICTURE_TYPE_COMPOSER = 11, /**< Composer */
  81192. FLAC__STREAM_METADATA_PICTURE_TYPE_LYRICIST = 12, /**< Lyricist/text writer */
  81193. FLAC__STREAM_METADATA_PICTURE_TYPE_RECORDING_LOCATION = 13, /**< Recording Location */
  81194. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_RECORDING = 14, /**< During recording */
  81195. FLAC__STREAM_METADATA_PICTURE_TYPE_DURING_PERFORMANCE = 15, /**< During performance */
  81196. FLAC__STREAM_METADATA_PICTURE_TYPE_VIDEO_SCREEN_CAPTURE = 16, /**< Movie/video screen capture */
  81197. FLAC__STREAM_METADATA_PICTURE_TYPE_FISH = 17, /**< A bright coloured fish */
  81198. FLAC__STREAM_METADATA_PICTURE_TYPE_ILLUSTRATION = 18, /**< Illustration */
  81199. FLAC__STREAM_METADATA_PICTURE_TYPE_BAND_LOGOTYPE = 19, /**< Band/artist logotype */
  81200. FLAC__STREAM_METADATA_PICTURE_TYPE_PUBLISHER_LOGOTYPE = 20, /**< Publisher/Studio logotype */
  81201. FLAC__STREAM_METADATA_PICTURE_TYPE_UNDEFINED
  81202. } FLAC__StreamMetadata_Picture_Type;
  81203. extern FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[];
  81204. typedef struct {
  81205. FLAC__StreamMetadata_Picture_Type type;
  81206. char *mime_type;
  81207. FLAC__byte *description;
  81208. FLAC__uint32 width;
  81209. FLAC__uint32 height;
  81210. FLAC__uint32 depth;
  81211. FLAC__uint32 colors;
  81212. FLAC__uint32 data_length;
  81213. FLAC__byte *data;
  81214. } FLAC__StreamMetadata_Picture;
  81215. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN; /**< == 32 (bits) */
  81216. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN; /**< == 32 (bits) */
  81217. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN; /**< == 32 (bits) */
  81218. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN; /**< == 32 (bits) */
  81219. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN; /**< == 32 (bits) */
  81220. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN; /**< == 32 (bits) */
  81221. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN; /**< == 32 (bits) */
  81222. extern FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN; /**< == 32 (bits) */
  81223. typedef struct {
  81224. FLAC__byte *data;
  81225. } FLAC__StreamMetadata_Unknown;
  81226. typedef struct {
  81227. FLAC__MetadataType type;
  81228. FLAC__bool is_last;
  81229. unsigned length;
  81230. union {
  81231. FLAC__StreamMetadata_StreamInfo stream_info;
  81232. FLAC__StreamMetadata_Padding padding;
  81233. FLAC__StreamMetadata_Application application;
  81234. FLAC__StreamMetadata_SeekTable seek_table;
  81235. FLAC__StreamMetadata_VorbisComment vorbis_comment;
  81236. FLAC__StreamMetadata_CueSheet cue_sheet;
  81237. FLAC__StreamMetadata_Picture picture;
  81238. FLAC__StreamMetadata_Unknown unknown;
  81239. } data;
  81240. } FLAC__StreamMetadata;
  81241. extern FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN; /**< == 1 (bit) */
  81242. extern FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN; /**< == 7 (bits) */
  81243. extern FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN; /**< == 24 (bits) */
  81244. #define FLAC__STREAM_METADATA_HEADER_LENGTH (4u)
  81245. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate);
  81246. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate);
  81247. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name);
  81248. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length);
  81249. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length);
  81250. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table);
  81251. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table);
  81252. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation);
  81253. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation);
  81254. #ifdef __cplusplus
  81255. }
  81256. #endif
  81257. #endif
  81258. /*** End of inlined file: format.h ***/
  81259. /*** Start of inlined file: metadata.h ***/
  81260. #ifndef FLAC__METADATA_H
  81261. #define FLAC__METADATA_H
  81262. #include <sys/types.h> /* for off_t */
  81263. #ifdef __cplusplus
  81264. extern "C" {
  81265. #endif
  81266. FLAC_API FLAC__bool FLAC__metadata_get_streaminfo(const char *filename, FLAC__StreamMetadata *streaminfo);
  81267. FLAC_API FLAC__bool FLAC__metadata_get_tags(const char *filename, FLAC__StreamMetadata **tags);
  81268. FLAC_API FLAC__bool FLAC__metadata_get_cuesheet(const char *filename, FLAC__StreamMetadata **cuesheet);
  81269. 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);
  81270. struct FLAC__Metadata_SimpleIterator;
  81271. typedef struct FLAC__Metadata_SimpleIterator FLAC__Metadata_SimpleIterator;
  81272. typedef enum {
  81273. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_OK = 0,
  81274. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ILLEGAL_INPUT,
  81275. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_ERROR_OPENING_FILE,
  81276. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_A_FLAC_FILE,
  81277. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_NOT_WRITABLE,
  81278. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_BAD_METADATA,
  81279. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_READ_ERROR,
  81280. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_SEEK_ERROR,
  81281. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_WRITE_ERROR,
  81282. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_RENAME_ERROR,
  81283. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_UNLINK_ERROR,
  81284. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_MEMORY_ALLOCATION_ERROR,
  81285. FLAC__METADATA_SIMPLE_ITERATOR_STATUS_INTERNAL_ERROR
  81286. } FLAC__Metadata_SimpleIteratorStatus;
  81287. extern FLAC_API const char * const FLAC__Metadata_SimpleIteratorStatusString[];
  81288. FLAC_API FLAC__Metadata_SimpleIterator *FLAC__metadata_simple_iterator_new(void);
  81289. FLAC_API void FLAC__metadata_simple_iterator_delete(FLAC__Metadata_SimpleIterator *iterator);
  81290. FLAC_API FLAC__Metadata_SimpleIteratorStatus FLAC__metadata_simple_iterator_status(FLAC__Metadata_SimpleIterator *iterator);
  81291. 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);
  81292. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_writable(const FLAC__Metadata_SimpleIterator *iterator);
  81293. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_next(FLAC__Metadata_SimpleIterator *iterator);
  81294. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_prev(FLAC__Metadata_SimpleIterator *iterator);
  81295. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_is_last(const FLAC__Metadata_SimpleIterator *iterator);
  81296. FLAC_API off_t FLAC__metadata_simple_iterator_get_block_offset(const FLAC__Metadata_SimpleIterator *iterator);
  81297. FLAC_API FLAC__MetadataType FLAC__metadata_simple_iterator_get_block_type(const FLAC__Metadata_SimpleIterator *iterator);
  81298. FLAC_API unsigned FLAC__metadata_simple_iterator_get_block_length(const FLAC__Metadata_SimpleIterator *iterator);
  81299. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_get_application_id(FLAC__Metadata_SimpleIterator *iterator, FLAC__byte *id);
  81300. FLAC_API FLAC__StreamMetadata *FLAC__metadata_simple_iterator_get_block(FLAC__Metadata_SimpleIterator *iterator);
  81301. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_set_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81302. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_insert_block_after(FLAC__Metadata_SimpleIterator *iterator, FLAC__StreamMetadata *block, FLAC__bool use_padding);
  81303. FLAC_API FLAC__bool FLAC__metadata_simple_iterator_delete_block(FLAC__Metadata_SimpleIterator *iterator, FLAC__bool use_padding);
  81304. struct FLAC__Metadata_Chain;
  81305. typedef struct FLAC__Metadata_Chain FLAC__Metadata_Chain;
  81306. struct FLAC__Metadata_Iterator;
  81307. typedef struct FLAC__Metadata_Iterator FLAC__Metadata_Iterator;
  81308. typedef enum {
  81309. FLAC__METADATA_CHAIN_STATUS_OK = 0,
  81310. FLAC__METADATA_CHAIN_STATUS_ILLEGAL_INPUT,
  81311. FLAC__METADATA_CHAIN_STATUS_ERROR_OPENING_FILE,
  81312. FLAC__METADATA_CHAIN_STATUS_NOT_A_FLAC_FILE,
  81313. FLAC__METADATA_CHAIN_STATUS_NOT_WRITABLE,
  81314. FLAC__METADATA_CHAIN_STATUS_BAD_METADATA,
  81315. FLAC__METADATA_CHAIN_STATUS_READ_ERROR,
  81316. FLAC__METADATA_CHAIN_STATUS_SEEK_ERROR,
  81317. FLAC__METADATA_CHAIN_STATUS_WRITE_ERROR,
  81318. FLAC__METADATA_CHAIN_STATUS_RENAME_ERROR,
  81319. FLAC__METADATA_CHAIN_STATUS_UNLINK_ERROR,
  81320. FLAC__METADATA_CHAIN_STATUS_MEMORY_ALLOCATION_ERROR,
  81321. FLAC__METADATA_CHAIN_STATUS_INTERNAL_ERROR,
  81322. FLAC__METADATA_CHAIN_STATUS_INVALID_CALLBACKS,
  81323. FLAC__METADATA_CHAIN_STATUS_READ_WRITE_MISMATCH,
  81324. FLAC__METADATA_CHAIN_STATUS_WRONG_WRITE_CALL
  81325. } FLAC__Metadata_ChainStatus;
  81326. extern FLAC_API const char * const FLAC__Metadata_ChainStatusString[];
  81327. FLAC_API FLAC__Metadata_Chain *FLAC__metadata_chain_new(void);
  81328. FLAC_API void FLAC__metadata_chain_delete(FLAC__Metadata_Chain *chain);
  81329. FLAC_API FLAC__Metadata_ChainStatus FLAC__metadata_chain_status(FLAC__Metadata_Chain *chain);
  81330. FLAC_API FLAC__bool FLAC__metadata_chain_read(FLAC__Metadata_Chain *chain, const char *filename);
  81331. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg(FLAC__Metadata_Chain *chain, const char *filename);
  81332. FLAC_API FLAC__bool FLAC__metadata_chain_read_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81333. FLAC_API FLAC__bool FLAC__metadata_chain_read_ogg_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81334. FLAC_API FLAC__bool FLAC__metadata_chain_check_if_tempfile_needed(FLAC__Metadata_Chain *chain, FLAC__bool use_padding);
  81335. FLAC_API FLAC__bool FLAC__metadata_chain_write(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__bool preserve_file_stats);
  81336. FLAC_API FLAC__bool FLAC__metadata_chain_write_with_callbacks(FLAC__Metadata_Chain *chain, FLAC__bool use_padding, FLAC__IOHandle handle, FLAC__IOCallbacks callbacks);
  81337. 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);
  81338. FLAC_API void FLAC__metadata_chain_merge_padding(FLAC__Metadata_Chain *chain);
  81339. FLAC_API void FLAC__metadata_chain_sort_padding(FLAC__Metadata_Chain *chain);
  81340. FLAC_API FLAC__Metadata_Iterator *FLAC__metadata_iterator_new(void);
  81341. FLAC_API void FLAC__metadata_iterator_delete(FLAC__Metadata_Iterator *iterator);
  81342. FLAC_API void FLAC__metadata_iterator_init(FLAC__Metadata_Iterator *iterator, FLAC__Metadata_Chain *chain);
  81343. FLAC_API FLAC__bool FLAC__metadata_iterator_next(FLAC__Metadata_Iterator *iterator);
  81344. FLAC_API FLAC__bool FLAC__metadata_iterator_prev(FLAC__Metadata_Iterator *iterator);
  81345. FLAC_API FLAC__MetadataType FLAC__metadata_iterator_get_block_type(const FLAC__Metadata_Iterator *iterator);
  81346. FLAC_API FLAC__StreamMetadata *FLAC__metadata_iterator_get_block(FLAC__Metadata_Iterator *iterator);
  81347. FLAC_API FLAC__bool FLAC__metadata_iterator_set_block(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81348. FLAC_API FLAC__bool FLAC__metadata_iterator_delete_block(FLAC__Metadata_Iterator *iterator, FLAC__bool replace_with_padding);
  81349. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_before(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81350. FLAC_API FLAC__bool FLAC__metadata_iterator_insert_block_after(FLAC__Metadata_Iterator *iterator, FLAC__StreamMetadata *block);
  81351. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_new(FLAC__MetadataType type);
  81352. FLAC_API FLAC__StreamMetadata *FLAC__metadata_object_clone(const FLAC__StreamMetadata *object);
  81353. FLAC_API void FLAC__metadata_object_delete(FLAC__StreamMetadata *object);
  81354. FLAC_API FLAC__bool FLAC__metadata_object_is_equal(const FLAC__StreamMetadata *block1, const FLAC__StreamMetadata *block2);
  81355. FLAC_API FLAC__bool FLAC__metadata_object_application_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, unsigned length, FLAC__bool copy);
  81356. FLAC_API FLAC__bool FLAC__metadata_object_seektable_resize_points(FLAC__StreamMetadata *object, unsigned new_num_points);
  81357. FLAC_API void FLAC__metadata_object_seektable_set_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81358. FLAC_API FLAC__bool FLAC__metadata_object_seektable_insert_point(FLAC__StreamMetadata *object, unsigned point_num, FLAC__StreamMetadata_SeekPoint point);
  81359. FLAC_API FLAC__bool FLAC__metadata_object_seektable_delete_point(FLAC__StreamMetadata *object, unsigned point_num);
  81360. FLAC_API FLAC__bool FLAC__metadata_object_seektable_is_legal(const FLAC__StreamMetadata *object);
  81361. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_placeholders(FLAC__StreamMetadata *object, unsigned num);
  81362. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_point(FLAC__StreamMetadata *object, FLAC__uint64 sample_number);
  81363. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_points(FLAC__StreamMetadata *object, FLAC__uint64 sample_numbers[], unsigned num);
  81364. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points(FLAC__StreamMetadata *object, unsigned num, FLAC__uint64 total_samples);
  81365. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_append_spaced_points_by_samples(FLAC__StreamMetadata *object, unsigned samples, FLAC__uint64 total_samples);
  81366. FLAC_API FLAC__bool FLAC__metadata_object_seektable_template_sort(FLAC__StreamMetadata *object, FLAC__bool compact);
  81367. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_vendor_string(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81368. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_resize_comments(FLAC__StreamMetadata *object, unsigned new_num_comments);
  81369. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_set_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81370. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_insert_comment(FLAC__StreamMetadata *object, unsigned comment_num, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81371. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_append_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool copy);
  81372. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_replace_comment(FLAC__StreamMetadata *object, FLAC__StreamMetadata_VorbisComment_Entry entry, FLAC__bool all, FLAC__bool copy);
  81373. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_delete_comment(FLAC__StreamMetadata *object, unsigned comment_num);
  81374. 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);
  81375. 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);
  81376. FLAC_API FLAC__bool FLAC__metadata_object_vorbiscomment_entry_matches(const FLAC__StreamMetadata_VorbisComment_Entry entry, const char *field_name, unsigned field_name_length);
  81377. FLAC_API int FLAC__metadata_object_vorbiscomment_find_entry_from(const FLAC__StreamMetadata *object, unsigned offset, const char *field_name);
  81378. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entry_matching(FLAC__StreamMetadata *object, const char *field_name);
  81379. FLAC_API int FLAC__metadata_object_vorbiscomment_remove_entries_matching(FLAC__StreamMetadata *object, const char *field_name);
  81380. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_new(void);
  81381. FLAC_API FLAC__StreamMetadata_CueSheet_Track *FLAC__metadata_object_cuesheet_track_clone(const FLAC__StreamMetadata_CueSheet_Track *object);
  81382. FLAC_API void FLAC__metadata_object_cuesheet_track_delete(FLAC__StreamMetadata_CueSheet_Track *object);
  81383. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_resize_indices(FLAC__StreamMetadata *object, unsigned track_num, unsigned new_num_indices);
  81384. 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);
  81385. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_insert_blank_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81386. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_track_delete_index(FLAC__StreamMetadata *object, unsigned track_num, unsigned index_num);
  81387. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_resize_tracks(FLAC__StreamMetadata *object, unsigned new_num_tracks);
  81388. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_set_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81389. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_track(FLAC__StreamMetadata *object, unsigned track_num, FLAC__StreamMetadata_CueSheet_Track *track, FLAC__bool copy);
  81390. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_insert_blank_track(FLAC__StreamMetadata *object, unsigned track_num);
  81391. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_delete_track(FLAC__StreamMetadata *object, unsigned track_num);
  81392. FLAC_API FLAC__bool FLAC__metadata_object_cuesheet_is_legal(const FLAC__StreamMetadata *object, FLAC__bool check_cd_da_subset, const char **violation);
  81393. FLAC_API FLAC__uint32 FLAC__metadata_object_cuesheet_calculate_cddb_id(const FLAC__StreamMetadata *object);
  81394. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_mime_type(FLAC__StreamMetadata *object, char *mime_type, FLAC__bool copy);
  81395. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_description(FLAC__StreamMetadata *object, FLAC__byte *description, FLAC__bool copy);
  81396. FLAC_API FLAC__bool FLAC__metadata_object_picture_set_data(FLAC__StreamMetadata *object, FLAC__byte *data, FLAC__uint32 length, FLAC__bool copy);
  81397. FLAC_API FLAC__bool FLAC__metadata_object_picture_is_legal(const FLAC__StreamMetadata *object, const char **violation);
  81398. #ifdef __cplusplus
  81399. }
  81400. #endif
  81401. #endif
  81402. /*** End of inlined file: metadata.h ***/
  81403. /*** Start of inlined file: stream_decoder.h ***/
  81404. #ifndef FLAC__STREAM_DECODER_H
  81405. #define FLAC__STREAM_DECODER_H
  81406. #include <stdio.h> /* for FILE */
  81407. #ifdef __cplusplus
  81408. extern "C" {
  81409. #endif
  81410. typedef enum {
  81411. FLAC__STREAM_DECODER_SEARCH_FOR_METADATA = 0,
  81412. FLAC__STREAM_DECODER_READ_METADATA,
  81413. FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC,
  81414. FLAC__STREAM_DECODER_READ_FRAME,
  81415. FLAC__STREAM_DECODER_END_OF_STREAM,
  81416. FLAC__STREAM_DECODER_OGG_ERROR,
  81417. FLAC__STREAM_DECODER_SEEK_ERROR,
  81418. FLAC__STREAM_DECODER_ABORTED,
  81419. FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR,
  81420. FLAC__STREAM_DECODER_UNINITIALIZED
  81421. } FLAC__StreamDecoderState;
  81422. extern FLAC_API const char * const FLAC__StreamDecoderStateString[];
  81423. typedef enum {
  81424. FLAC__STREAM_DECODER_INIT_STATUS_OK = 0,
  81425. FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81426. FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS,
  81427. FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR,
  81428. FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE,
  81429. FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED
  81430. } FLAC__StreamDecoderInitStatus;
  81431. extern FLAC_API const char * const FLAC__StreamDecoderInitStatusString[];
  81432. typedef enum {
  81433. FLAC__STREAM_DECODER_READ_STATUS_CONTINUE,
  81434. FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM,
  81435. FLAC__STREAM_DECODER_READ_STATUS_ABORT
  81436. } FLAC__StreamDecoderReadStatus;
  81437. extern FLAC_API const char * const FLAC__StreamDecoderReadStatusString[];
  81438. typedef enum {
  81439. FLAC__STREAM_DECODER_SEEK_STATUS_OK,
  81440. FLAC__STREAM_DECODER_SEEK_STATUS_ERROR,
  81441. FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED
  81442. } FLAC__StreamDecoderSeekStatus;
  81443. extern FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[];
  81444. typedef enum {
  81445. FLAC__STREAM_DECODER_TELL_STATUS_OK,
  81446. FLAC__STREAM_DECODER_TELL_STATUS_ERROR,
  81447. FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED
  81448. } FLAC__StreamDecoderTellStatus;
  81449. extern FLAC_API const char * const FLAC__StreamDecoderTellStatusString[];
  81450. typedef enum {
  81451. FLAC__STREAM_DECODER_LENGTH_STATUS_OK,
  81452. FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR,
  81453. FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED
  81454. } FLAC__StreamDecoderLengthStatus;
  81455. extern FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[];
  81456. typedef enum {
  81457. FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE,
  81458. FLAC__STREAM_DECODER_WRITE_STATUS_ABORT
  81459. } FLAC__StreamDecoderWriteStatus;
  81460. extern FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[];
  81461. typedef enum {
  81462. FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC,
  81463. FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER,
  81464. FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH,
  81465. FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM
  81466. } FLAC__StreamDecoderErrorStatus;
  81467. extern FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[];
  81468. struct FLAC__StreamDecoderProtected;
  81469. struct FLAC__StreamDecoderPrivate;
  81470. typedef struct {
  81471. struct FLAC__StreamDecoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81472. struct FLAC__StreamDecoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81473. } FLAC__StreamDecoder;
  81474. typedef FLAC__StreamDecoderReadStatus (*FLAC__StreamDecoderReadCallback)(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81475. typedef FLAC__StreamDecoderSeekStatus (*FLAC__StreamDecoderSeekCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81476. typedef FLAC__StreamDecoderTellStatus (*FLAC__StreamDecoderTellCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81477. typedef FLAC__StreamDecoderLengthStatus (*FLAC__StreamDecoderLengthCallback)(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  81478. typedef FLAC__bool (*FLAC__StreamDecoderEofCallback)(const FLAC__StreamDecoder *decoder, void *client_data);
  81479. typedef FLAC__StreamDecoderWriteStatus (*FLAC__StreamDecoderWriteCallback)(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  81480. typedef void (*FLAC__StreamDecoderMetadataCallback)(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81481. typedef void (*FLAC__StreamDecoderErrorCallback)(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  81482. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void);
  81483. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder);
  81484. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long serial_number);
  81485. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value);
  81486. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81487. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81488. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder);
  81489. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type);
  81490. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4]);
  81491. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder);
  81492. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder);
  81493. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder);
  81494. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder);
  81495. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder);
  81496. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder);
  81497. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder);
  81498. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder);
  81499. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder);
  81500. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder);
  81501. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position);
  81502. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  81503. FLAC__StreamDecoder *decoder,
  81504. FLAC__StreamDecoderReadCallback read_callback,
  81505. FLAC__StreamDecoderSeekCallback seek_callback,
  81506. FLAC__StreamDecoderTellCallback tell_callback,
  81507. FLAC__StreamDecoderLengthCallback length_callback,
  81508. FLAC__StreamDecoderEofCallback eof_callback,
  81509. FLAC__StreamDecoderWriteCallback write_callback,
  81510. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81511. FLAC__StreamDecoderErrorCallback error_callback,
  81512. void *client_data
  81513. );
  81514. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  81515. FLAC__StreamDecoder *decoder,
  81516. FLAC__StreamDecoderReadCallback read_callback,
  81517. FLAC__StreamDecoderSeekCallback seek_callback,
  81518. FLAC__StreamDecoderTellCallback tell_callback,
  81519. FLAC__StreamDecoderLengthCallback length_callback,
  81520. FLAC__StreamDecoderEofCallback eof_callback,
  81521. FLAC__StreamDecoderWriteCallback write_callback,
  81522. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81523. FLAC__StreamDecoderErrorCallback error_callback,
  81524. void *client_data
  81525. );
  81526. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  81527. FLAC__StreamDecoder *decoder,
  81528. FILE *file,
  81529. FLAC__StreamDecoderWriteCallback write_callback,
  81530. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81531. FLAC__StreamDecoderErrorCallback error_callback,
  81532. void *client_data
  81533. );
  81534. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  81535. FLAC__StreamDecoder *decoder,
  81536. FILE *file,
  81537. FLAC__StreamDecoderWriteCallback write_callback,
  81538. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81539. FLAC__StreamDecoderErrorCallback error_callback,
  81540. void *client_data
  81541. );
  81542. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  81543. FLAC__StreamDecoder *decoder,
  81544. const char *filename,
  81545. FLAC__StreamDecoderWriteCallback write_callback,
  81546. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81547. FLAC__StreamDecoderErrorCallback error_callback,
  81548. void *client_data
  81549. );
  81550. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  81551. FLAC__StreamDecoder *decoder,
  81552. const char *filename,
  81553. FLAC__StreamDecoderWriteCallback write_callback,
  81554. FLAC__StreamDecoderMetadataCallback metadata_callback,
  81555. FLAC__StreamDecoderErrorCallback error_callback,
  81556. void *client_data
  81557. );
  81558. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder);
  81559. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder);
  81560. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder);
  81561. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder);
  81562. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder);
  81563. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder);
  81564. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder);
  81565. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample);
  81566. #ifdef __cplusplus
  81567. }
  81568. #endif
  81569. #endif
  81570. /*** End of inlined file: stream_decoder.h ***/
  81571. /*** Start of inlined file: stream_encoder.h ***/
  81572. #ifndef FLAC__STREAM_ENCODER_H
  81573. #define FLAC__STREAM_ENCODER_H
  81574. #include <stdio.h> /* for FILE */
  81575. #ifdef __cplusplus
  81576. extern "C" {
  81577. #endif
  81578. typedef enum {
  81579. FLAC__STREAM_ENCODER_OK = 0,
  81580. FLAC__STREAM_ENCODER_UNINITIALIZED,
  81581. FLAC__STREAM_ENCODER_OGG_ERROR,
  81582. FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR,
  81583. FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA,
  81584. FLAC__STREAM_ENCODER_CLIENT_ERROR,
  81585. FLAC__STREAM_ENCODER_IO_ERROR,
  81586. FLAC__STREAM_ENCODER_FRAMING_ERROR,
  81587. FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR
  81588. } FLAC__StreamEncoderState;
  81589. extern FLAC_API const char * const FLAC__StreamEncoderStateString[];
  81590. typedef enum {
  81591. FLAC__STREAM_ENCODER_INIT_STATUS_OK = 0,
  81592. FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR,
  81593. FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER,
  81594. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS,
  81595. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS,
  81596. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE,
  81597. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE,
  81598. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE,
  81599. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER,
  81600. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION,
  81601. FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER,
  81602. FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE,
  81603. FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA,
  81604. FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED
  81605. } FLAC__StreamEncoderInitStatus;
  81606. extern FLAC_API const char * const FLAC__StreamEncoderInitStatusString[];
  81607. typedef enum {
  81608. FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE,
  81609. FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM,
  81610. FLAC__STREAM_ENCODER_READ_STATUS_ABORT,
  81611. FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED
  81612. } FLAC__StreamEncoderReadStatus;
  81613. extern FLAC_API const char * const FLAC__StreamEncoderReadStatusString[];
  81614. typedef enum {
  81615. FLAC__STREAM_ENCODER_WRITE_STATUS_OK = 0,
  81616. FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR
  81617. } FLAC__StreamEncoderWriteStatus;
  81618. extern FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[];
  81619. typedef enum {
  81620. FLAC__STREAM_ENCODER_SEEK_STATUS_OK,
  81621. FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR,
  81622. FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED
  81623. } FLAC__StreamEncoderSeekStatus;
  81624. extern FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[];
  81625. typedef enum {
  81626. FLAC__STREAM_ENCODER_TELL_STATUS_OK,
  81627. FLAC__STREAM_ENCODER_TELL_STATUS_ERROR,
  81628. FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED
  81629. } FLAC__StreamEncoderTellStatus;
  81630. extern FLAC_API const char * const FLAC__StreamEncoderTellStatusString[];
  81631. struct FLAC__StreamEncoderProtected;
  81632. struct FLAC__StreamEncoderPrivate;
  81633. typedef struct {
  81634. struct FLAC__StreamEncoderProtected *protected_; /* avoid the C++ keyword 'protected' */
  81635. struct FLAC__StreamEncoderPrivate *private_; /* avoid the C++ keyword 'private' */
  81636. } FLAC__StreamEncoder;
  81637. typedef FLAC__StreamEncoderReadStatus (*FLAC__StreamEncoderReadCallback)(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  81638. typedef FLAC__StreamEncoderWriteStatus (*FLAC__StreamEncoderWriteCallback)(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data);
  81639. typedef FLAC__StreamEncoderSeekStatus (*FLAC__StreamEncoderSeekCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  81640. typedef FLAC__StreamEncoderTellStatus (*FLAC__StreamEncoderTellCallback)(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  81641. typedef void (*FLAC__StreamEncoderMetadataCallback)(const FLAC__StreamEncoder *encoder, const FLAC__StreamMetadata *metadata, void *client_data);
  81642. 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);
  81643. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void);
  81644. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder);
  81645. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long serial_number);
  81646. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81647. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81648. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value);
  81649. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value);
  81650. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value);
  81651. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value);
  81652. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value);
  81653. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81654. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81655. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification);
  81656. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value);
  81657. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value);
  81658. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81659. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81660. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value);
  81661. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81662. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value);
  81663. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value);
  81664. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value);
  81665. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks);
  81666. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder);
  81667. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder);
  81668. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder);
  81669. 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);
  81670. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder);
  81671. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder);
  81672. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder);
  81673. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder);
  81674. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder);
  81675. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder);
  81676. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81677. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder);
  81678. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder);
  81679. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder);
  81680. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder);
  81681. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder);
  81682. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder);
  81683. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81684. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder);
  81685. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder);
  81686. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder);
  81687. 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);
  81688. 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);
  81689. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81690. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(FLAC__StreamEncoder *encoder, FILE *file, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81691. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81692. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(FLAC__StreamEncoder *encoder, const char *filename, FLAC__StreamEncoderProgressCallback progress_callback, void *client_data);
  81693. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder);
  81694. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples);
  81695. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples);
  81696. #ifdef __cplusplus
  81697. }
  81698. #endif
  81699. #endif
  81700. /*** End of inlined file: stream_encoder.h ***/
  81701. #ifdef _MSC_VER
  81702. static _inline FLAC__uint32 local_swap32_(FLAC__uint32 x)
  81703. {
  81704. x = ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
  81705. return (x>>16) | (x<<16);
  81706. }
  81707. #endif
  81708. #if defined(_MSC_VER) && defined(_X86_)
  81709. static void local_swap32_block_(FLAC__uint32 *start, FLAC__uint32 len)
  81710. {
  81711. __asm {
  81712. mov edx, start
  81713. mov ecx, len
  81714. test ecx, ecx
  81715. loop1:
  81716. jz done1
  81717. mov eax, [edx]
  81718. bswap eax
  81719. mov [edx], eax
  81720. add edx, 4
  81721. dec ecx
  81722. jmp short loop1
  81723. done1:
  81724. }
  81725. }
  81726. #endif
  81727. #endif
  81728. /*** End of inlined file: all.h ***/
  81729. /*** Start of inlined file: bitmath.c ***/
  81730. /*** Start of inlined file: juce_FlacHeader.h ***/
  81731. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81732. // tasks..
  81733. #define VERSION "1.2.1"
  81734. #define FLAC__NO_DLL 1
  81735. #if JUCE_MSVC
  81736. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81737. #endif
  81738. #if JUCE_MAC
  81739. #define FLAC__SYS_DARWIN 1
  81740. #endif
  81741. /*** End of inlined file: juce_FlacHeader.h ***/
  81742. #if JUCE_USE_FLAC
  81743. #if HAVE_CONFIG_H
  81744. # include <config.h>
  81745. #endif
  81746. /*** Start of inlined file: bitmath.h ***/
  81747. #ifndef FLAC__PRIVATE__BITMATH_H
  81748. #define FLAC__PRIVATE__BITMATH_H
  81749. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v);
  81750. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v);
  81751. unsigned FLAC__bitmath_silog2(int v);
  81752. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v);
  81753. #endif
  81754. /*** End of inlined file: bitmath.h ***/
  81755. unsigned FLAC__bitmath_ilog2(FLAC__uint32 v)
  81756. {
  81757. unsigned l = 0;
  81758. FLAC__ASSERT(v > 0);
  81759. while(v >>= 1)
  81760. l++;
  81761. return l;
  81762. }
  81763. unsigned FLAC__bitmath_ilog2_wide(FLAC__uint64 v)
  81764. {
  81765. unsigned l = 0;
  81766. FLAC__ASSERT(v > 0);
  81767. while(v >>= 1)
  81768. l++;
  81769. return l;
  81770. }
  81771. unsigned FLAC__bitmath_silog2(int v)
  81772. {
  81773. while(1) {
  81774. if(v == 0) {
  81775. return 0;
  81776. }
  81777. else if(v > 0) {
  81778. unsigned l = 0;
  81779. while(v) {
  81780. l++;
  81781. v >>= 1;
  81782. }
  81783. return l+1;
  81784. }
  81785. else if(v == -1) {
  81786. return 2;
  81787. }
  81788. else {
  81789. v++;
  81790. v = -v;
  81791. }
  81792. }
  81793. }
  81794. unsigned FLAC__bitmath_silog2_wide(FLAC__int64 v)
  81795. {
  81796. while(1) {
  81797. if(v == 0) {
  81798. return 0;
  81799. }
  81800. else if(v > 0) {
  81801. unsigned l = 0;
  81802. while(v) {
  81803. l++;
  81804. v >>= 1;
  81805. }
  81806. return l+1;
  81807. }
  81808. else if(v == -1) {
  81809. return 2;
  81810. }
  81811. else {
  81812. v++;
  81813. v = -v;
  81814. }
  81815. }
  81816. }
  81817. #endif
  81818. /*** End of inlined file: bitmath.c ***/
  81819. /*** Start of inlined file: bitreader.c ***/
  81820. /*** Start of inlined file: juce_FlacHeader.h ***/
  81821. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  81822. // tasks..
  81823. #define VERSION "1.2.1"
  81824. #define FLAC__NO_DLL 1
  81825. #if JUCE_MSVC
  81826. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  81827. #endif
  81828. #if JUCE_MAC
  81829. #define FLAC__SYS_DARWIN 1
  81830. #endif
  81831. /*** End of inlined file: juce_FlacHeader.h ***/
  81832. #if JUCE_USE_FLAC
  81833. #if HAVE_CONFIG_H
  81834. # include <config.h>
  81835. #endif
  81836. #include <stdlib.h> /* for malloc() */
  81837. #include <string.h> /* for memcpy(), memset() */
  81838. #ifdef _MSC_VER
  81839. #include <winsock.h> /* for ntohl() */
  81840. #elif defined FLAC__SYS_DARWIN
  81841. #include <machine/endian.h> /* for ntohl() */
  81842. #elif defined __MINGW32__
  81843. #include <winsock.h> /* for ntohl() */
  81844. #else
  81845. #include <netinet/in.h> /* for ntohl() */
  81846. #endif
  81847. /*** Start of inlined file: bitreader.h ***/
  81848. #ifndef FLAC__PRIVATE__BITREADER_H
  81849. #define FLAC__PRIVATE__BITREADER_H
  81850. #include <stdio.h> /* for FILE */
  81851. /*** Start of inlined file: cpu.h ***/
  81852. #ifndef FLAC__PRIVATE__CPU_H
  81853. #define FLAC__PRIVATE__CPU_H
  81854. #ifdef HAVE_CONFIG_H
  81855. #include <config.h>
  81856. #endif
  81857. typedef enum {
  81858. FLAC__CPUINFO_TYPE_IA32,
  81859. FLAC__CPUINFO_TYPE_PPC,
  81860. FLAC__CPUINFO_TYPE_UNKNOWN
  81861. } FLAC__CPUInfo_Type;
  81862. typedef struct {
  81863. FLAC__bool cpuid;
  81864. FLAC__bool bswap;
  81865. FLAC__bool cmov;
  81866. FLAC__bool mmx;
  81867. FLAC__bool fxsr;
  81868. FLAC__bool sse;
  81869. FLAC__bool sse2;
  81870. FLAC__bool sse3;
  81871. FLAC__bool ssse3;
  81872. FLAC__bool _3dnow;
  81873. FLAC__bool ext3dnow;
  81874. FLAC__bool extmmx;
  81875. } FLAC__CPUInfo_IA32;
  81876. typedef struct {
  81877. FLAC__bool altivec;
  81878. FLAC__bool ppc64;
  81879. } FLAC__CPUInfo_PPC;
  81880. typedef struct {
  81881. FLAC__bool use_asm;
  81882. FLAC__CPUInfo_Type type;
  81883. union {
  81884. FLAC__CPUInfo_IA32 ia32;
  81885. FLAC__CPUInfo_PPC ppc;
  81886. } data;
  81887. } FLAC__CPUInfo;
  81888. void FLAC__cpu_info(FLAC__CPUInfo *info);
  81889. #ifndef FLAC__NO_ASM
  81890. #ifdef FLAC__CPU_IA32
  81891. #ifdef FLAC__HAS_NASM
  81892. FLAC__uint32 FLAC__cpu_have_cpuid_asm_ia32(void);
  81893. void FLAC__cpu_info_asm_ia32(FLAC__uint32 *flags_edx, FLAC__uint32 *flags_ecx);
  81894. FLAC__uint32 FLAC__cpu_info_extended_amd_asm_ia32(void);
  81895. #endif
  81896. #endif
  81897. #endif
  81898. #endif
  81899. /*** End of inlined file: cpu.h ***/
  81900. struct FLAC__BitReader;
  81901. typedef struct FLAC__BitReader FLAC__BitReader;
  81902. typedef FLAC__bool (*FLAC__BitReaderReadCallback)(FLAC__byte buffer[], size_t *bytes, void *client_data);
  81903. FLAC__BitReader *FLAC__bitreader_new(void);
  81904. void FLAC__bitreader_delete(FLAC__BitReader *br);
  81905. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd);
  81906. void FLAC__bitreader_free(FLAC__BitReader *br); /* does not 'free(br)' */
  81907. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br);
  81908. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out);
  81909. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed);
  81910. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br);
  81911. FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br);
  81912. unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br);
  81913. unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br);
  81914. FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits);
  81915. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits);
  81916. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits);
  81917. FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val); /*only for bits=32*/
  81918. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits); /* WATCHOUT: does not CRC the skipped data! */ /*@@@@ add to unit tests */
  81919. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals); /* WATCHOUT: does not CRC the read data! */
  81920. 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! */
  81921. FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val);
  81922. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81923. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81924. #ifndef FLAC__NO_ASM
  81925. # ifdef FLAC__CPU_IA32
  81926. # ifdef FLAC__HAS_NASM
  81927. FLAC__bool FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter);
  81928. # endif
  81929. # endif
  81930. #endif
  81931. #if 0 /* UNUSED */
  81932. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter);
  81933. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter);
  81934. #endif
  81935. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen);
  81936. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen);
  81937. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br);
  81938. #endif
  81939. /*** End of inlined file: bitreader.h ***/
  81940. /*** Start of inlined file: crc.h ***/
  81941. #ifndef FLAC__PRIVATE__CRC_H
  81942. #define FLAC__PRIVATE__CRC_H
  81943. extern FLAC__byte const FLAC__crc8_table[256];
  81944. #define FLAC__CRC8_UPDATE(data, crc) (crc) = FLAC__crc8_table[(crc) ^ (data)];
  81945. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc);
  81946. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc);
  81947. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len);
  81948. extern unsigned FLAC__crc16_table[256];
  81949. #define FLAC__CRC16_UPDATE(data, crc) (((((crc)<<8) & 0xffff) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]))
  81950. #if 0
  81951. #define FLAC__CRC16_UPDATE(data, crc) ((((crc)<<8) ^ FLAC__crc16_table[((crc)>>8) ^ (data)]) & 0xffff)
  81952. #endif
  81953. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len);
  81954. #endif
  81955. /*** End of inlined file: crc.h ***/
  81956. typedef FLAC__uint32 brword;
  81957. #define FLAC__BYTES_PER_WORD 4
  81958. #define FLAC__BITS_PER_WORD 32
  81959. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  81960. #if WORDS_BIGENDIAN
  81961. #define SWAP_BE_WORD_TO_HOST(x) (x)
  81962. #else
  81963. #if defined (_MSC_VER) && defined (_X86_)
  81964. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  81965. #else
  81966. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  81967. #endif
  81968. #endif
  81969. #define COUNT_ZERO_MSBS(word) ( \
  81970. (word) <= 0xffff ? \
  81971. ( (word) <= 0xff? byte_to_unary_table[word] + 24 : byte_to_unary_table[(word) >> 8] + 16 ) : \
  81972. ( (word) <= 0xffffff? byte_to_unary_table[word >> 16] + 8 : byte_to_unary_table[(word) >> 24] ) \
  81973. )
  81974. #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])) )
  81975. static const unsigned FLAC__BITREADER_DEFAULT_CAPACITY = 65536u / FLAC__BITS_PER_WORD; /* in words */
  81976. static const unsigned char byte_to_unary_table[] = {
  81977. 8, 7, 6, 6, 5, 5, 5, 5, 4, 4, 4, 4, 4, 4, 4, 4,
  81978. 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
  81979. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81980. 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
  81981. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81982. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81983. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81984. 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
  81985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  81992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
  81993. };
  81994. #ifdef min
  81995. #undef min
  81996. #endif
  81997. #define min(x,y) ((x)<(y)?(x):(y))
  81998. #ifdef max
  81999. #undef max
  82000. #endif
  82001. #define max(x,y) ((x)>(y)?(x):(y))
  82002. #ifdef _MSC_VER
  82003. #define FLAC__U64L(x) x
  82004. #else
  82005. #define FLAC__U64L(x) x##LLU
  82006. #endif
  82007. #ifndef FLaC__INLINE
  82008. #define FLaC__INLINE
  82009. #endif
  82010. struct FLAC__BitReader {
  82011. brword *buffer;
  82012. unsigned capacity; /* in words */
  82013. unsigned words; /* # of completed words in buffer */
  82014. unsigned bytes; /* # of bytes in incomplete word at buffer[words] */
  82015. unsigned consumed_words; /* #words ... */
  82016. unsigned consumed_bits; /* ... + (#bits of head word) already consumed from the front of buffer */
  82017. unsigned read_crc16; /* the running frame CRC */
  82018. unsigned crc16_align; /* the number of bits in the current consumed word that should not be CRC'd */
  82019. FLAC__BitReaderReadCallback read_callback;
  82020. void *client_data;
  82021. FLAC__CPUInfo cpu_info;
  82022. };
  82023. static FLaC__INLINE void crc16_update_word_(FLAC__BitReader *br, brword word)
  82024. {
  82025. register unsigned crc = br->read_crc16;
  82026. #if FLAC__BYTES_PER_WORD == 4
  82027. switch(br->crc16_align) {
  82028. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 24), crc);
  82029. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  82030. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  82031. case 24: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  82032. }
  82033. #elif FLAC__BYTES_PER_WORD == 8
  82034. switch(br->crc16_align) {
  82035. case 0: crc = FLAC__CRC16_UPDATE((unsigned)(word >> 56), crc);
  82036. case 8: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 48) & 0xff), crc);
  82037. case 16: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 40) & 0xff), crc);
  82038. case 24: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 32) & 0xff), crc);
  82039. case 32: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 24) & 0xff), crc);
  82040. case 40: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 16) & 0xff), crc);
  82041. case 48: crc = FLAC__CRC16_UPDATE((unsigned)((word >> 8) & 0xff), crc);
  82042. case 56: br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)(word & 0xff), crc);
  82043. }
  82044. #else
  82045. for( ; br->crc16_align < FLAC__BITS_PER_WORD; br->crc16_align += 8)
  82046. crc = FLAC__CRC16_UPDATE((unsigned)((word >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), crc);
  82047. br->read_crc16 = crc;
  82048. #endif
  82049. br->crc16_align = 0;
  82050. }
  82051. FLAC__bool bitreader_read_from_client_(FLAC__BitReader *br)
  82052. {
  82053. unsigned start, end;
  82054. size_t bytes;
  82055. FLAC__byte *target;
  82056. if(br->consumed_words > 0) {
  82057. start = br->consumed_words;
  82058. end = br->words + (br->bytes? 1:0);
  82059. memmove(br->buffer, br->buffer+start, FLAC__BYTES_PER_WORD * (end - start));
  82060. br->words -= start;
  82061. br->consumed_words = 0;
  82062. }
  82063. bytes = (br->capacity - br->words) * FLAC__BYTES_PER_WORD - br->bytes;
  82064. if(bytes == 0)
  82065. return false; /* no space left, buffer is too small; see note for FLAC__BITREADER_DEFAULT_CAPACITY */
  82066. target = ((FLAC__byte*)(br->buffer+br->words)) + br->bytes;
  82067. #if WORDS_BIGENDIAN
  82068. #else
  82069. if(br->bytes)
  82070. br->buffer[br->words] = SWAP_BE_WORD_TO_HOST(br->buffer[br->words]);
  82071. #endif
  82072. if(!br->read_callback(target, &bytes, br->client_data))
  82073. return false;
  82074. #if WORDS_BIGENDIAN
  82075. #else
  82076. end = (br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes + (FLAC__BYTES_PER_WORD-1)) / FLAC__BYTES_PER_WORD;
  82077. # if defined(_MSC_VER) && defined (_X86_) && (FLAC__BYTES_PER_WORD == 4)
  82078. if(br->cpu_info.type == FLAC__CPUINFO_TYPE_IA32 && br->cpu_info.data.ia32.bswap) {
  82079. start = br->words;
  82080. local_swap32_block_(br->buffer + start, end - start);
  82081. }
  82082. else
  82083. # endif
  82084. for(start = br->words; start < end; start++)
  82085. br->buffer[start] = SWAP_BE_WORD_TO_HOST(br->buffer[start]);
  82086. #endif
  82087. end = br->words*FLAC__BYTES_PER_WORD + br->bytes + bytes;
  82088. br->words = end / FLAC__BYTES_PER_WORD;
  82089. br->bytes = end % FLAC__BYTES_PER_WORD;
  82090. return true;
  82091. }
  82092. FLAC__BitReader *FLAC__bitreader_new(void)
  82093. {
  82094. FLAC__BitReader *br = (FLAC__BitReader*)calloc(1, sizeof(FLAC__BitReader));
  82095. return br;
  82096. }
  82097. void FLAC__bitreader_delete(FLAC__BitReader *br)
  82098. {
  82099. FLAC__ASSERT(0 != br);
  82100. FLAC__bitreader_free(br);
  82101. free(br);
  82102. }
  82103. FLAC__bool FLAC__bitreader_init(FLAC__BitReader *br, FLAC__CPUInfo cpu, FLAC__BitReaderReadCallback rcb, void *cd)
  82104. {
  82105. FLAC__ASSERT(0 != br);
  82106. br->words = br->bytes = 0;
  82107. br->consumed_words = br->consumed_bits = 0;
  82108. br->capacity = FLAC__BITREADER_DEFAULT_CAPACITY;
  82109. br->buffer = (brword*)malloc(sizeof(brword) * br->capacity);
  82110. if(br->buffer == 0)
  82111. return false;
  82112. br->read_callback = rcb;
  82113. br->client_data = cd;
  82114. br->cpu_info = cpu;
  82115. return true;
  82116. }
  82117. void FLAC__bitreader_free(FLAC__BitReader *br)
  82118. {
  82119. FLAC__ASSERT(0 != br);
  82120. if(0 != br->buffer)
  82121. free(br->buffer);
  82122. br->buffer = 0;
  82123. br->capacity = 0;
  82124. br->words = br->bytes = 0;
  82125. br->consumed_words = br->consumed_bits = 0;
  82126. br->read_callback = 0;
  82127. br->client_data = 0;
  82128. }
  82129. FLAC__bool FLAC__bitreader_clear(FLAC__BitReader *br)
  82130. {
  82131. br->words = br->bytes = 0;
  82132. br->consumed_words = br->consumed_bits = 0;
  82133. return true;
  82134. }
  82135. void FLAC__bitreader_dump(const FLAC__BitReader *br, FILE *out)
  82136. {
  82137. unsigned i, j;
  82138. if(br == 0) {
  82139. fprintf(out, "bitreader is NULL\n");
  82140. }
  82141. else {
  82142. 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);
  82143. for(i = 0; i < br->words; i++) {
  82144. fprintf(out, "%08X: ", i);
  82145. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  82146. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  82147. fprintf(out, ".");
  82148. else
  82149. fprintf(out, "%01u", br->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  82150. fprintf(out, "\n");
  82151. }
  82152. if(br->bytes > 0) {
  82153. fprintf(out, "%08X: ", i);
  82154. for(j = 0; j < br->bytes*8; j++)
  82155. if(i < br->consumed_words || (i == br->consumed_words && j < br->consumed_bits))
  82156. fprintf(out, ".");
  82157. else
  82158. fprintf(out, "%01u", br->buffer[i] & (1 << (br->bytes*8-j-1)) ? 1:0);
  82159. fprintf(out, "\n");
  82160. }
  82161. }
  82162. }
  82163. void FLAC__bitreader_reset_read_crc16(FLAC__BitReader *br, FLAC__uint16 seed)
  82164. {
  82165. FLAC__ASSERT(0 != br);
  82166. FLAC__ASSERT(0 != br->buffer);
  82167. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  82168. br->read_crc16 = (unsigned)seed;
  82169. br->crc16_align = br->consumed_bits;
  82170. }
  82171. FLAC__uint16 FLAC__bitreader_get_read_crc16(FLAC__BitReader *br)
  82172. {
  82173. FLAC__ASSERT(0 != br);
  82174. FLAC__ASSERT(0 != br->buffer);
  82175. FLAC__ASSERT((br->consumed_bits & 7) == 0);
  82176. FLAC__ASSERT(br->crc16_align <= br->consumed_bits);
  82177. if(br->consumed_bits) {
  82178. const brword tail = br->buffer[br->consumed_words];
  82179. for( ; br->crc16_align < br->consumed_bits; br->crc16_align += 8)
  82180. br->read_crc16 = FLAC__CRC16_UPDATE((unsigned)((tail >> (FLAC__BITS_PER_WORD-8-br->crc16_align)) & 0xff), br->read_crc16);
  82181. }
  82182. return br->read_crc16;
  82183. }
  82184. FLaC__INLINE FLAC__bool FLAC__bitreader_is_consumed_byte_aligned(const FLAC__BitReader *br)
  82185. {
  82186. return ((br->consumed_bits & 7) == 0);
  82187. }
  82188. FLaC__INLINE unsigned FLAC__bitreader_bits_left_for_byte_alignment(const FLAC__BitReader *br)
  82189. {
  82190. return 8 - (br->consumed_bits & 7);
  82191. }
  82192. FLaC__INLINE unsigned FLAC__bitreader_get_input_bits_unconsumed(const FLAC__BitReader *br)
  82193. {
  82194. return (br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits;
  82195. }
  82196. FLaC__INLINE FLAC__bool FLAC__bitreader_read_raw_uint32(FLAC__BitReader *br, FLAC__uint32 *val, unsigned bits)
  82197. {
  82198. FLAC__ASSERT(0 != br);
  82199. FLAC__ASSERT(0 != br->buffer);
  82200. FLAC__ASSERT(bits <= 32);
  82201. FLAC__ASSERT((br->capacity*FLAC__BITS_PER_WORD) * 2 >= bits);
  82202. FLAC__ASSERT(br->consumed_words <= br->words);
  82203. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82204. if(bits == 0) { /* OPT: investigate if this can ever happen, maybe change to assertion */
  82205. *val = 0;
  82206. return true;
  82207. }
  82208. while((br->words-br->consumed_words)*FLAC__BITS_PER_WORD + br->bytes*8 - br->consumed_bits < bits) {
  82209. if(!bitreader_read_from_client_(br))
  82210. return false;
  82211. }
  82212. if(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82213. if(br->consumed_bits) {
  82214. const unsigned n = FLAC__BITS_PER_WORD - br->consumed_bits;
  82215. const brword word = br->buffer[br->consumed_words];
  82216. if(bits < n) {
  82217. *val = (word & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (n-bits);
  82218. br->consumed_bits += bits;
  82219. return true;
  82220. }
  82221. *val = word & (FLAC__WORD_ALL_ONES >> br->consumed_bits);
  82222. bits -= n;
  82223. crc16_update_word_(br, word);
  82224. br->consumed_words++;
  82225. br->consumed_bits = 0;
  82226. 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 */
  82227. *val <<= bits;
  82228. *val |= (br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits));
  82229. br->consumed_bits = bits;
  82230. }
  82231. return true;
  82232. }
  82233. else {
  82234. const brword word = br->buffer[br->consumed_words];
  82235. if(bits < FLAC__BITS_PER_WORD) {
  82236. *val = word >> (FLAC__BITS_PER_WORD-bits);
  82237. br->consumed_bits = bits;
  82238. return true;
  82239. }
  82240. *val = word;
  82241. crc16_update_word_(br, word);
  82242. br->consumed_words++;
  82243. return true;
  82244. }
  82245. }
  82246. else {
  82247. if(br->consumed_bits) {
  82248. FLAC__ASSERT(br->consumed_bits + bits <= br->bytes*8);
  82249. *val = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES >> br->consumed_bits)) >> (FLAC__BITS_PER_WORD-br->consumed_bits-bits);
  82250. br->consumed_bits += bits;
  82251. return true;
  82252. }
  82253. else {
  82254. *val = br->buffer[br->consumed_words] >> (FLAC__BITS_PER_WORD-bits);
  82255. br->consumed_bits += bits;
  82256. return true;
  82257. }
  82258. }
  82259. }
  82260. FLAC__bool FLAC__bitreader_read_raw_int32(FLAC__BitReader *br, FLAC__int32 *val, unsigned bits)
  82261. {
  82262. if(!FLAC__bitreader_read_raw_uint32(br, (FLAC__uint32*)val, bits))
  82263. return false;
  82264. *val <<= (32-bits);
  82265. *val >>= (32-bits);
  82266. return true;
  82267. }
  82268. FLAC__bool FLAC__bitreader_read_raw_uint64(FLAC__BitReader *br, FLAC__uint64 *val, unsigned bits)
  82269. {
  82270. FLAC__uint32 hi, lo;
  82271. if(bits > 32) {
  82272. if(!FLAC__bitreader_read_raw_uint32(br, &hi, bits-32))
  82273. return false;
  82274. if(!FLAC__bitreader_read_raw_uint32(br, &lo, 32))
  82275. return false;
  82276. *val = hi;
  82277. *val <<= 32;
  82278. *val |= lo;
  82279. }
  82280. else {
  82281. if(!FLAC__bitreader_read_raw_uint32(br, &lo, bits))
  82282. return false;
  82283. *val = lo;
  82284. }
  82285. return true;
  82286. }
  82287. FLaC__INLINE FLAC__bool FLAC__bitreader_read_uint32_little_endian(FLAC__BitReader *br, FLAC__uint32 *val)
  82288. {
  82289. FLAC__uint32 x8, x32 = 0;
  82290. if(!FLAC__bitreader_read_raw_uint32(br, &x32, 8))
  82291. return false;
  82292. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82293. return false;
  82294. x32 |= (x8 << 8);
  82295. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82296. return false;
  82297. x32 |= (x8 << 16);
  82298. if(!FLAC__bitreader_read_raw_uint32(br, &x8, 8))
  82299. return false;
  82300. x32 |= (x8 << 24);
  82301. *val = x32;
  82302. return true;
  82303. }
  82304. FLAC__bool FLAC__bitreader_skip_bits_no_crc(FLAC__BitReader *br, unsigned bits)
  82305. {
  82306. FLAC__ASSERT(0 != br);
  82307. FLAC__ASSERT(0 != br->buffer);
  82308. if(bits > 0) {
  82309. const unsigned n = br->consumed_bits & 7;
  82310. unsigned m;
  82311. FLAC__uint32 x;
  82312. if(n != 0) {
  82313. m = min(8-n, bits);
  82314. if(!FLAC__bitreader_read_raw_uint32(br, &x, m))
  82315. return false;
  82316. bits -= m;
  82317. }
  82318. m = bits / 8;
  82319. if(m > 0) {
  82320. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(br, m))
  82321. return false;
  82322. bits %= 8;
  82323. }
  82324. if(bits > 0) {
  82325. if(!FLAC__bitreader_read_raw_uint32(br, &x, bits))
  82326. return false;
  82327. }
  82328. }
  82329. return true;
  82330. }
  82331. FLAC__bool FLAC__bitreader_skip_byte_block_aligned_no_crc(FLAC__BitReader *br, unsigned nvals)
  82332. {
  82333. FLAC__uint32 x;
  82334. FLAC__ASSERT(0 != br);
  82335. FLAC__ASSERT(0 != br->buffer);
  82336. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82337. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82338. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82339. return false;
  82340. nvals--;
  82341. }
  82342. if(0 == nvals)
  82343. return true;
  82344. while(nvals >= FLAC__BYTES_PER_WORD) {
  82345. if(br->consumed_words < br->words) {
  82346. br->consumed_words++;
  82347. nvals -= FLAC__BYTES_PER_WORD;
  82348. }
  82349. else if(!bitreader_read_from_client_(br))
  82350. return false;
  82351. }
  82352. while(nvals) {
  82353. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82354. return false;
  82355. nvals--;
  82356. }
  82357. return true;
  82358. }
  82359. FLAC__bool FLAC__bitreader_read_byte_block_aligned_no_crc(FLAC__BitReader *br, FLAC__byte *val, unsigned nvals)
  82360. {
  82361. FLAC__uint32 x;
  82362. FLAC__ASSERT(0 != br);
  82363. FLAC__ASSERT(0 != br->buffer);
  82364. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(br));
  82365. while(nvals && br->consumed_bits) { /* i.e. run until we read 'nvals' bytes or we hit the end of the head word */
  82366. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82367. return false;
  82368. *val++ = (FLAC__byte)x;
  82369. nvals--;
  82370. }
  82371. if(0 == nvals)
  82372. return true;
  82373. while(nvals >= FLAC__BYTES_PER_WORD) {
  82374. if(br->consumed_words < br->words) {
  82375. const brword word = br->buffer[br->consumed_words++];
  82376. #if FLAC__BYTES_PER_WORD == 4
  82377. val[0] = (FLAC__byte)(word >> 24);
  82378. val[1] = (FLAC__byte)(word >> 16);
  82379. val[2] = (FLAC__byte)(word >> 8);
  82380. val[3] = (FLAC__byte)word;
  82381. #elif FLAC__BYTES_PER_WORD == 8
  82382. val[0] = (FLAC__byte)(word >> 56);
  82383. val[1] = (FLAC__byte)(word >> 48);
  82384. val[2] = (FLAC__byte)(word >> 40);
  82385. val[3] = (FLAC__byte)(word >> 32);
  82386. val[4] = (FLAC__byte)(word >> 24);
  82387. val[5] = (FLAC__byte)(word >> 16);
  82388. val[6] = (FLAC__byte)(word >> 8);
  82389. val[7] = (FLAC__byte)word;
  82390. #else
  82391. for(x = 0; x < FLAC__BYTES_PER_WORD; x++)
  82392. val[x] = (FLAC__byte)(word >> (8*(FLAC__BYTES_PER_WORD-x-1)));
  82393. #endif
  82394. val += FLAC__BYTES_PER_WORD;
  82395. nvals -= FLAC__BYTES_PER_WORD;
  82396. }
  82397. else if(!bitreader_read_from_client_(br))
  82398. return false;
  82399. }
  82400. while(nvals) {
  82401. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82402. return false;
  82403. *val++ = (FLAC__byte)x;
  82404. nvals--;
  82405. }
  82406. return true;
  82407. }
  82408. FLaC__INLINE FLAC__bool FLAC__bitreader_read_unary_unsigned(FLAC__BitReader *br, unsigned *val)
  82409. #if 0 /* slow but readable version */
  82410. {
  82411. unsigned bit;
  82412. FLAC__ASSERT(0 != br);
  82413. FLAC__ASSERT(0 != br->buffer);
  82414. *val = 0;
  82415. while(1) {
  82416. if(!FLAC__bitreader_read_bit(br, &bit))
  82417. return false;
  82418. if(bit)
  82419. break;
  82420. else
  82421. *val++;
  82422. }
  82423. return true;
  82424. }
  82425. #else
  82426. {
  82427. unsigned i;
  82428. FLAC__ASSERT(0 != br);
  82429. FLAC__ASSERT(0 != br->buffer);
  82430. *val = 0;
  82431. while(1) {
  82432. while(br->consumed_words < br->words) { /* if we've not consumed up to a partial tail word... */
  82433. brword b = br->buffer[br->consumed_words] << br->consumed_bits;
  82434. if(b) {
  82435. i = COUNT_ZERO_MSBS(b);
  82436. *val += i;
  82437. i++;
  82438. br->consumed_bits += i;
  82439. if(br->consumed_bits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(br->consumed_bits == FLAC__BITS_PER_WORD) */
  82440. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82441. br->consumed_words++;
  82442. br->consumed_bits = 0;
  82443. }
  82444. return true;
  82445. }
  82446. else {
  82447. *val += FLAC__BITS_PER_WORD - br->consumed_bits;
  82448. crc16_update_word_(br, br->buffer[br->consumed_words]);
  82449. br->consumed_words++;
  82450. br->consumed_bits = 0;
  82451. }
  82452. }
  82453. if(br->bytes) {
  82454. const unsigned end = br->bytes * 8;
  82455. brword b = (br->buffer[br->consumed_words] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << br->consumed_bits;
  82456. if(b) {
  82457. i = COUNT_ZERO_MSBS(b);
  82458. *val += i;
  82459. i++;
  82460. br->consumed_bits += i;
  82461. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82462. return true;
  82463. }
  82464. else {
  82465. *val += end - br->consumed_bits;
  82466. br->consumed_bits += end;
  82467. FLAC__ASSERT(br->consumed_bits < FLAC__BITS_PER_WORD);
  82468. }
  82469. }
  82470. if(!bitreader_read_from_client_(br))
  82471. return false;
  82472. }
  82473. }
  82474. #endif
  82475. FLAC__bool FLAC__bitreader_read_rice_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82476. {
  82477. FLAC__uint32 lsbs = 0, msbs = 0;
  82478. unsigned uval;
  82479. FLAC__ASSERT(0 != br);
  82480. FLAC__ASSERT(0 != br->buffer);
  82481. FLAC__ASSERT(parameter <= 31);
  82482. if(!FLAC__bitreader_read_unary_unsigned(br, (unsigned int*) &msbs))
  82483. return false;
  82484. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, parameter))
  82485. return false;
  82486. uval = (msbs << parameter) | lsbs;
  82487. if(uval & 1)
  82488. *val = -((int)(uval >> 1)) - 1;
  82489. else
  82490. *val = (int)(uval >> 1);
  82491. return true;
  82492. }
  82493. FLAC__bool FLAC__bitreader_read_rice_signed_block(FLAC__BitReader *br, int vals[], unsigned nvals, unsigned parameter)
  82494. #ifdef _MSC_VER
  82495. {
  82496. unsigned i;
  82497. unsigned uval = 0;
  82498. unsigned bits; /* the # of binary LSBs left to read to finish a rice codeword */
  82499. register unsigned cwords;
  82500. register unsigned cbits;
  82501. FLAC__ASSERT(0 != br);
  82502. FLAC__ASSERT(0 != br->buffer);
  82503. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82504. FLAC__ASSERT(parameter < 32);
  82505. if(nvals == 0)
  82506. return true;
  82507. cbits = br->consumed_bits;
  82508. cwords = br->consumed_words;
  82509. while(1) {
  82510. while(1) {
  82511. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82512. brword b = br->buffer[cwords] << cbits;
  82513. if(b) {
  82514. #if 0 /* slower, probably due to bad register allocation... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32
  82515. __asm {
  82516. bsr eax, b
  82517. not eax
  82518. and eax, 31
  82519. mov i, eax
  82520. }
  82521. #else
  82522. i = COUNT_ZERO_MSBS(b);
  82523. #endif
  82524. uval += i;
  82525. bits = parameter;
  82526. i++;
  82527. cbits += i;
  82528. if(cbits == FLAC__BITS_PER_WORD) {
  82529. crc16_update_word_(br, br->buffer[cwords]);
  82530. cwords++;
  82531. cbits = 0;
  82532. }
  82533. goto break1;
  82534. }
  82535. else {
  82536. uval += FLAC__BITS_PER_WORD - cbits;
  82537. crc16_update_word_(br, br->buffer[cwords]);
  82538. cwords++;
  82539. cbits = 0;
  82540. }
  82541. }
  82542. if(br->bytes) {
  82543. const unsigned end = br->bytes * 8;
  82544. brword b = (br->buffer[cwords] & (FLAC__WORD_ALL_ONES << (FLAC__BITS_PER_WORD-end))) << cbits;
  82545. if(b) {
  82546. i = COUNT_ZERO_MSBS(b);
  82547. uval += i;
  82548. bits = parameter;
  82549. i++;
  82550. cbits += i;
  82551. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82552. goto break1;
  82553. }
  82554. else {
  82555. uval += end - cbits;
  82556. cbits += end;
  82557. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82558. }
  82559. }
  82560. br->consumed_bits = cbits;
  82561. br->consumed_words = cwords;
  82562. if(!bitreader_read_from_client_(br))
  82563. return false;
  82564. cwords = br->consumed_words;
  82565. }
  82566. break1:
  82567. FLAC__ASSERT(cwords <= br->words);
  82568. if(bits) {
  82569. while((br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits < bits) {
  82570. br->consumed_bits = cbits;
  82571. br->consumed_words = cwords;
  82572. if(!bitreader_read_from_client_(br))
  82573. return false;
  82574. cwords = br->consumed_words;
  82575. }
  82576. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82577. if(cbits) {
  82578. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82579. const brword word = br->buffer[cwords];
  82580. if(bits < n) {
  82581. uval <<= bits;
  82582. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-bits);
  82583. cbits += bits;
  82584. goto break2;
  82585. }
  82586. uval <<= n;
  82587. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82588. bits -= n;
  82589. crc16_update_word_(br, word);
  82590. cwords++;
  82591. cbits = 0;
  82592. 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 */
  82593. uval <<= bits;
  82594. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits));
  82595. cbits = bits;
  82596. }
  82597. goto break2;
  82598. }
  82599. else {
  82600. FLAC__ASSERT(bits < FLAC__BITS_PER_WORD);
  82601. uval <<= bits;
  82602. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82603. cbits = bits;
  82604. goto break2;
  82605. }
  82606. }
  82607. else {
  82608. uval <<= bits;
  82609. if(cbits) {
  82610. FLAC__ASSERT(cbits + bits <= br->bytes*8);
  82611. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-bits);
  82612. cbits += bits;
  82613. goto break2;
  82614. }
  82615. else {
  82616. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-bits);
  82617. cbits += bits;
  82618. goto break2;
  82619. }
  82620. }
  82621. }
  82622. break2:
  82623. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82624. --nvals;
  82625. if(nvals == 0) {
  82626. br->consumed_bits = cbits;
  82627. br->consumed_words = cwords;
  82628. return true;
  82629. }
  82630. uval = 0;
  82631. ++vals;
  82632. }
  82633. }
  82634. #else
  82635. {
  82636. unsigned i;
  82637. unsigned uval = 0;
  82638. register unsigned cwords;
  82639. register unsigned cbits;
  82640. unsigned ucbits; /* keep track of the number of unconsumed bits in the buffer */
  82641. FLAC__ASSERT(0 != br);
  82642. FLAC__ASSERT(0 != br->buffer);
  82643. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  82644. FLAC__ASSERT(parameter < 32);
  82645. if(nvals == 0)
  82646. return true;
  82647. cbits = br->consumed_bits;
  82648. cwords = br->consumed_words;
  82649. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82650. while(1) {
  82651. while(1) {
  82652. while(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82653. brword b = br->buffer[cwords] << cbits;
  82654. if(b) {
  82655. #if 0 /* is not discernably faster... */ && defined FLAC__CPU_IA32 && !defined FLAC__NO_ASM && FLAC__BITS_PER_WORD == 32 && defined __GNUC__
  82656. asm volatile (
  82657. "bsrl %1, %0;"
  82658. "notl %0;"
  82659. "andl $31, %0;"
  82660. : "=r"(i)
  82661. : "r"(b)
  82662. );
  82663. #else
  82664. i = COUNT_ZERO_MSBS(b);
  82665. #endif
  82666. uval += i;
  82667. cbits += i;
  82668. cbits++; /* skip over stop bit */
  82669. if(cbits >= FLAC__BITS_PER_WORD) { /* faster way of testing if(cbits == FLAC__BITS_PER_WORD) */
  82670. crc16_update_word_(br, br->buffer[cwords]);
  82671. cwords++;
  82672. cbits = 0;
  82673. }
  82674. goto break1;
  82675. }
  82676. else {
  82677. uval += FLAC__BITS_PER_WORD - cbits;
  82678. crc16_update_word_(br, br->buffer[cwords]);
  82679. cwords++;
  82680. cbits = 0;
  82681. }
  82682. }
  82683. if(br->bytes) {
  82684. const unsigned end = br->bytes * 8;
  82685. brword b = (br->buffer[cwords] & ~(FLAC__WORD_ALL_ONES >> end)) << cbits;
  82686. if(b) {
  82687. i = COUNT_ZERO_MSBS(b);
  82688. uval += i;
  82689. cbits += i;
  82690. cbits++; /* skip over stop bit */
  82691. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82692. goto break1;
  82693. }
  82694. else {
  82695. uval += end - cbits;
  82696. cbits += end;
  82697. FLAC__ASSERT(cbits < FLAC__BITS_PER_WORD);
  82698. }
  82699. }
  82700. br->consumed_bits = cbits;
  82701. br->consumed_words = cwords;
  82702. if(!bitreader_read_from_client_(br))
  82703. return false;
  82704. cwords = br->consumed_words;
  82705. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits + uval;
  82706. }
  82707. break1:
  82708. ucbits -= uval;
  82709. ucbits--; /* account for stop bit */
  82710. FLAC__ASSERT(cwords <= br->words);
  82711. if(parameter) {
  82712. while(ucbits < parameter) {
  82713. br->consumed_bits = cbits;
  82714. br->consumed_words = cwords;
  82715. if(!bitreader_read_from_client_(br))
  82716. return false;
  82717. cwords = br->consumed_words;
  82718. ucbits = (br->words-cwords)*FLAC__BITS_PER_WORD + br->bytes*8 - cbits;
  82719. }
  82720. if(cwords < br->words) { /* if we've not consumed up to a partial tail word... */
  82721. if(cbits) {
  82722. const unsigned n = FLAC__BITS_PER_WORD - cbits;
  82723. const brword word = br->buffer[cwords];
  82724. if(parameter < n) {
  82725. uval <<= parameter;
  82726. uval |= (word & (FLAC__WORD_ALL_ONES >> cbits)) >> (n-parameter);
  82727. cbits += parameter;
  82728. }
  82729. else {
  82730. uval <<= n;
  82731. uval |= word & (FLAC__WORD_ALL_ONES >> cbits);
  82732. crc16_update_word_(br, word);
  82733. cwords++;
  82734. cbits = parameter - n;
  82735. 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 */
  82736. uval <<= cbits;
  82737. uval |= (br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits));
  82738. }
  82739. }
  82740. }
  82741. else {
  82742. cbits = parameter;
  82743. uval <<= parameter;
  82744. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82745. }
  82746. }
  82747. else {
  82748. uval <<= parameter;
  82749. if(cbits) {
  82750. FLAC__ASSERT(cbits + parameter <= br->bytes*8);
  82751. uval |= (br->buffer[cwords] & (FLAC__WORD_ALL_ONES >> cbits)) >> (FLAC__BITS_PER_WORD-cbits-parameter);
  82752. cbits += parameter;
  82753. }
  82754. else {
  82755. cbits = parameter;
  82756. uval |= br->buffer[cwords] >> (FLAC__BITS_PER_WORD-cbits);
  82757. }
  82758. }
  82759. }
  82760. ucbits -= parameter;
  82761. *vals = (int)(uval >> 1 ^ -(int)(uval & 1));
  82762. --nvals;
  82763. if(nvals == 0) {
  82764. br->consumed_bits = cbits;
  82765. br->consumed_words = cwords;
  82766. return true;
  82767. }
  82768. uval = 0;
  82769. ++vals;
  82770. }
  82771. }
  82772. #endif
  82773. #if 0 /* UNUSED */
  82774. FLAC__bool FLAC__bitreader_read_golomb_signed(FLAC__BitReader *br, int *val, unsigned parameter)
  82775. {
  82776. FLAC__uint32 lsbs = 0, msbs = 0;
  82777. unsigned bit, uval, k;
  82778. FLAC__ASSERT(0 != br);
  82779. FLAC__ASSERT(0 != br->buffer);
  82780. k = FLAC__bitmath_ilog2(parameter);
  82781. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82782. return false;
  82783. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82784. return false;
  82785. if(parameter == 1u<<k) {
  82786. uval = (msbs << k) | lsbs;
  82787. }
  82788. else {
  82789. unsigned d = (1 << (k+1)) - parameter;
  82790. if(lsbs >= d) {
  82791. if(!FLAC__bitreader_read_bit(br, &bit))
  82792. return false;
  82793. lsbs <<= 1;
  82794. lsbs |= bit;
  82795. lsbs -= d;
  82796. }
  82797. uval = msbs * parameter + lsbs;
  82798. }
  82799. if(uval & 1)
  82800. *val = -((int)(uval >> 1)) - 1;
  82801. else
  82802. *val = (int)(uval >> 1);
  82803. return true;
  82804. }
  82805. FLAC__bool FLAC__bitreader_read_golomb_unsigned(FLAC__BitReader *br, unsigned *val, unsigned parameter)
  82806. {
  82807. FLAC__uint32 lsbs, msbs = 0;
  82808. unsigned bit, k;
  82809. FLAC__ASSERT(0 != br);
  82810. FLAC__ASSERT(0 != br->buffer);
  82811. k = FLAC__bitmath_ilog2(parameter);
  82812. if(!FLAC__bitreader_read_unary_unsigned(br, &msbs))
  82813. return false;
  82814. if(!FLAC__bitreader_read_raw_uint32(br, &lsbs, k))
  82815. return false;
  82816. if(parameter == 1u<<k) {
  82817. *val = (msbs << k) | lsbs;
  82818. }
  82819. else {
  82820. unsigned d = (1 << (k+1)) - parameter;
  82821. if(lsbs >= d) {
  82822. if(!FLAC__bitreader_read_bit(br, &bit))
  82823. return false;
  82824. lsbs <<= 1;
  82825. lsbs |= bit;
  82826. lsbs -= d;
  82827. }
  82828. *val = msbs * parameter + lsbs;
  82829. }
  82830. return true;
  82831. }
  82832. #endif /* UNUSED */
  82833. FLAC__bool FLAC__bitreader_read_utf8_uint32(FLAC__BitReader *br, FLAC__uint32 *val, FLAC__byte *raw, unsigned *rawlen)
  82834. {
  82835. FLAC__uint32 v = 0;
  82836. FLAC__uint32 x;
  82837. unsigned i;
  82838. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82839. return false;
  82840. if(raw)
  82841. raw[(*rawlen)++] = (FLAC__byte)x;
  82842. if(!(x & 0x80)) { /* 0xxxxxxx */
  82843. v = x;
  82844. i = 0;
  82845. }
  82846. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82847. v = x & 0x1F;
  82848. i = 1;
  82849. }
  82850. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82851. v = x & 0x0F;
  82852. i = 2;
  82853. }
  82854. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82855. v = x & 0x07;
  82856. i = 3;
  82857. }
  82858. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82859. v = x & 0x03;
  82860. i = 4;
  82861. }
  82862. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82863. v = x & 0x01;
  82864. i = 5;
  82865. }
  82866. else {
  82867. *val = 0xffffffff;
  82868. return true;
  82869. }
  82870. for( ; i; i--) {
  82871. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82872. return false;
  82873. if(raw)
  82874. raw[(*rawlen)++] = (FLAC__byte)x;
  82875. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82876. *val = 0xffffffff;
  82877. return true;
  82878. }
  82879. v <<= 6;
  82880. v |= (x & 0x3F);
  82881. }
  82882. *val = v;
  82883. return true;
  82884. }
  82885. FLAC__bool FLAC__bitreader_read_utf8_uint64(FLAC__BitReader *br, FLAC__uint64 *val, FLAC__byte *raw, unsigned *rawlen)
  82886. {
  82887. FLAC__uint64 v = 0;
  82888. FLAC__uint32 x;
  82889. unsigned i;
  82890. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82891. return false;
  82892. if(raw)
  82893. raw[(*rawlen)++] = (FLAC__byte)x;
  82894. if(!(x & 0x80)) { /* 0xxxxxxx */
  82895. v = x;
  82896. i = 0;
  82897. }
  82898. else if(x & 0xC0 && !(x & 0x20)) { /* 110xxxxx */
  82899. v = x & 0x1F;
  82900. i = 1;
  82901. }
  82902. else if(x & 0xE0 && !(x & 0x10)) { /* 1110xxxx */
  82903. v = x & 0x0F;
  82904. i = 2;
  82905. }
  82906. else if(x & 0xF0 && !(x & 0x08)) { /* 11110xxx */
  82907. v = x & 0x07;
  82908. i = 3;
  82909. }
  82910. else if(x & 0xF8 && !(x & 0x04)) { /* 111110xx */
  82911. v = x & 0x03;
  82912. i = 4;
  82913. }
  82914. else if(x & 0xFC && !(x & 0x02)) { /* 1111110x */
  82915. v = x & 0x01;
  82916. i = 5;
  82917. }
  82918. else if(x & 0xFE && !(x & 0x01)) { /* 11111110 */
  82919. v = 0;
  82920. i = 6;
  82921. }
  82922. else {
  82923. *val = FLAC__U64L(0xffffffffffffffff);
  82924. return true;
  82925. }
  82926. for( ; i; i--) {
  82927. if(!FLAC__bitreader_read_raw_uint32(br, &x, 8))
  82928. return false;
  82929. if(raw)
  82930. raw[(*rawlen)++] = (FLAC__byte)x;
  82931. if(!(x & 0x80) || (x & 0x40)) { /* 10xxxxxx */
  82932. *val = FLAC__U64L(0xffffffffffffffff);
  82933. return true;
  82934. }
  82935. v <<= 6;
  82936. v |= (x & 0x3F);
  82937. }
  82938. *val = v;
  82939. return true;
  82940. }
  82941. #endif
  82942. /*** End of inlined file: bitreader.c ***/
  82943. /*** Start of inlined file: bitwriter.c ***/
  82944. /*** Start of inlined file: juce_FlacHeader.h ***/
  82945. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  82946. // tasks..
  82947. #define VERSION "1.2.1"
  82948. #define FLAC__NO_DLL 1
  82949. #if JUCE_MSVC
  82950. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  82951. #endif
  82952. #if JUCE_MAC
  82953. #define FLAC__SYS_DARWIN 1
  82954. #endif
  82955. /*** End of inlined file: juce_FlacHeader.h ***/
  82956. #if JUCE_USE_FLAC
  82957. #if HAVE_CONFIG_H
  82958. # include <config.h>
  82959. #endif
  82960. #include <stdlib.h> /* for malloc() */
  82961. #include <string.h> /* for memcpy(), memset() */
  82962. #ifdef _MSC_VER
  82963. #include <winsock.h> /* for ntohl() */
  82964. #elif defined FLAC__SYS_DARWIN
  82965. #include <machine/endian.h> /* for ntohl() */
  82966. #elif defined __MINGW32__
  82967. #include <winsock.h> /* for ntohl() */
  82968. #else
  82969. #include <netinet/in.h> /* for ntohl() */
  82970. #endif
  82971. #if 0 /* UNUSED */
  82972. #endif
  82973. /*** Start of inlined file: bitwriter.h ***/
  82974. #ifndef FLAC__PRIVATE__BITWRITER_H
  82975. #define FLAC__PRIVATE__BITWRITER_H
  82976. #include <stdio.h> /* for FILE */
  82977. struct FLAC__BitWriter;
  82978. typedef struct FLAC__BitWriter FLAC__BitWriter;
  82979. FLAC__BitWriter *FLAC__bitwriter_new(void);
  82980. void FLAC__bitwriter_delete(FLAC__BitWriter *bw);
  82981. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw);
  82982. void FLAC__bitwriter_free(FLAC__BitWriter *bw); /* does not 'free(buffer)' */
  82983. void FLAC__bitwriter_clear(FLAC__BitWriter *bw);
  82984. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out);
  82985. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc);
  82986. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc);
  82987. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw);
  82988. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw); /* can be called anytime, returns total # of bits unconsumed */
  82989. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes);
  82990. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw);
  82991. FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits);
  82992. FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits);
  82993. FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits);
  82994. FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits);
  82995. FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val); /*only for bits=32*/
  82996. FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals);
  82997. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val);
  82998. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter);
  82999. #if 0 /* UNUSED */
  83000. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter);
  83001. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned val, unsigned parameter);
  83002. #endif
  83003. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter);
  83004. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter);
  83005. #if 0 /* UNUSED */
  83006. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter);
  83007. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned val, unsigned parameter);
  83008. #endif
  83009. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val);
  83010. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val);
  83011. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw);
  83012. #endif
  83013. /*** End of inlined file: bitwriter.h ***/
  83014. /*** Start of inlined file: alloc.h ***/
  83015. #ifndef FLAC__SHARE__ALLOC_H
  83016. #define FLAC__SHARE__ALLOC_H
  83017. #if HAVE_CONFIG_H
  83018. # include <config.h>
  83019. #endif
  83020. #include <limits.h> /* for SIZE_MAX */
  83021. #if !defined _MSC_VER && !defined __MINGW32__ && !defined __EMX__
  83022. #include <stdint.h> /* for SIZE_MAX in case limits.h didn't get it */
  83023. #endif
  83024. #include <stdlib.h> /* for size_t, malloc(), etc */
  83025. #ifndef SIZE_MAX
  83026. # ifndef SIZE_T_MAX
  83027. # ifdef _MSC_VER
  83028. # define SIZE_T_MAX UINT_MAX
  83029. # else
  83030. # error
  83031. # endif
  83032. # endif
  83033. # define SIZE_MAX SIZE_T_MAX
  83034. #endif
  83035. #ifndef FLaC__INLINE
  83036. #define FLaC__INLINE
  83037. #endif
  83038. static FLaC__INLINE void *safe_malloc_(size_t size)
  83039. {
  83040. if(!size)
  83041. size++;
  83042. return malloc(size);
  83043. }
  83044. static FLaC__INLINE void *safe_calloc_(size_t nmemb, size_t size)
  83045. {
  83046. if(!nmemb || !size)
  83047. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83048. return calloc(nmemb, size);
  83049. }
  83050. static FLaC__INLINE void *safe_malloc_add_2op_(size_t size1, size_t size2)
  83051. {
  83052. size2 += size1;
  83053. if(size2 < size1)
  83054. return 0;
  83055. return safe_malloc_(size2);
  83056. }
  83057. static FLaC__INLINE void *safe_malloc_add_3op_(size_t size1, size_t size2, size_t size3)
  83058. {
  83059. size2 += size1;
  83060. if(size2 < size1)
  83061. return 0;
  83062. size3 += size2;
  83063. if(size3 < size2)
  83064. return 0;
  83065. return safe_malloc_(size3);
  83066. }
  83067. static FLaC__INLINE void *safe_malloc_add_4op_(size_t size1, size_t size2, size_t size3, size_t size4)
  83068. {
  83069. size2 += size1;
  83070. if(size2 < size1)
  83071. return 0;
  83072. size3 += size2;
  83073. if(size3 < size2)
  83074. return 0;
  83075. size4 += size3;
  83076. if(size4 < size3)
  83077. return 0;
  83078. return safe_malloc_(size4);
  83079. }
  83080. static FLaC__INLINE void *safe_malloc_mul_2op_(size_t size1, size_t size2)
  83081. #if 0
  83082. needs support for cases where sizeof(size_t) != 4
  83083. {
  83084. if(sizeof(size_t) == 4) {
  83085. if ((double)size1 * (double)size2 < 4294967296.0)
  83086. return malloc(size1*size2);
  83087. }
  83088. return 0;
  83089. }
  83090. #else
  83091. {
  83092. if(!size1 || !size2)
  83093. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83094. if(size1 > SIZE_MAX / size2)
  83095. return 0;
  83096. return malloc(size1*size2);
  83097. }
  83098. #endif
  83099. static FLaC__INLINE void *safe_malloc_mul_3op_(size_t size1, size_t size2, size_t size3)
  83100. {
  83101. if(!size1 || !size2 || !size3)
  83102. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83103. if(size1 > SIZE_MAX / size2)
  83104. return 0;
  83105. size1 *= size2;
  83106. if(size1 > SIZE_MAX / size3)
  83107. return 0;
  83108. return malloc(size1*size3);
  83109. }
  83110. static FLaC__INLINE void *safe_malloc_mul2add_(size_t size1, size_t size2, size_t size3)
  83111. {
  83112. if(!size1 || !size2)
  83113. return safe_malloc_(size3);
  83114. if(size1 > SIZE_MAX / size2)
  83115. return 0;
  83116. return safe_malloc_add_2op_(size1*size2, size3);
  83117. }
  83118. static FLaC__INLINE void *safe_malloc_muladd2_(size_t size1, size_t size2, size_t size3)
  83119. {
  83120. if(!size1 || (!size2 && !size3))
  83121. return malloc(1); /* malloc(0) is undefined; FLAC src convention is to always allocate */
  83122. size2 += size3;
  83123. if(size2 < size3)
  83124. return 0;
  83125. return safe_malloc_mul_2op_(size1, size2);
  83126. }
  83127. static FLaC__INLINE void *safe_realloc_add_2op_(void *ptr, size_t size1, size_t size2)
  83128. {
  83129. size2 += size1;
  83130. if(size2 < size1)
  83131. return 0;
  83132. return realloc(ptr, size2);
  83133. }
  83134. static FLaC__INLINE void *safe_realloc_add_3op_(void *ptr, size_t size1, size_t size2, size_t size3)
  83135. {
  83136. size2 += size1;
  83137. if(size2 < size1)
  83138. return 0;
  83139. size3 += size2;
  83140. if(size3 < size2)
  83141. return 0;
  83142. return realloc(ptr, size3);
  83143. }
  83144. static FLaC__INLINE void *safe_realloc_add_4op_(void *ptr, size_t size1, size_t size2, size_t size3, size_t size4)
  83145. {
  83146. size2 += size1;
  83147. if(size2 < size1)
  83148. return 0;
  83149. size3 += size2;
  83150. if(size3 < size2)
  83151. return 0;
  83152. size4 += size3;
  83153. if(size4 < size3)
  83154. return 0;
  83155. return realloc(ptr, size4);
  83156. }
  83157. static FLaC__INLINE void *safe_realloc_mul_2op_(void *ptr, size_t size1, size_t size2)
  83158. {
  83159. if(!size1 || !size2)
  83160. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  83161. if(size1 > SIZE_MAX / size2)
  83162. return 0;
  83163. return realloc(ptr, size1*size2);
  83164. }
  83165. static FLaC__INLINE void *safe_realloc_muladd2_(void *ptr, size_t size1, size_t size2, size_t size3)
  83166. {
  83167. if(!size1 || (!size2 && !size3))
  83168. return realloc(ptr, 0); /* preserve POSIX realloc(ptr, 0) semantics */
  83169. size2 += size3;
  83170. if(size2 < size3)
  83171. return 0;
  83172. return safe_realloc_mul_2op_(ptr, size1, size2);
  83173. }
  83174. #endif
  83175. /*** End of inlined file: alloc.h ***/
  83176. typedef FLAC__uint32 bwword;
  83177. #define FLAC__BYTES_PER_WORD 4
  83178. #define FLAC__BITS_PER_WORD 32
  83179. #define FLAC__WORD_ALL_ONES ((FLAC__uint32)0xffffffff)
  83180. #if WORDS_BIGENDIAN
  83181. #define SWAP_BE_WORD_TO_HOST(x) (x)
  83182. #else
  83183. #ifdef _MSC_VER
  83184. #define SWAP_BE_WORD_TO_HOST(x) local_swap32_(x)
  83185. #else
  83186. #define SWAP_BE_WORD_TO_HOST(x) ntohl(x)
  83187. #endif
  83188. #endif
  83189. static const unsigned FLAC__BITWRITER_DEFAULT_CAPACITY = 32768u / sizeof(bwword); /* size in words */
  83190. static const unsigned FLAC__BITWRITER_DEFAULT_INCREMENT = 4096u / sizeof(bwword); /* size in words */
  83191. #define FLAC__WORDS_TO_BITS(words) ((words) * FLAC__BITS_PER_WORD)
  83192. #define FLAC__TOTAL_BITS(bw) (FLAC__WORDS_TO_BITS((bw)->words) + (bw)->bits)
  83193. #ifdef min
  83194. #undef min
  83195. #endif
  83196. #define min(x,y) ((x)<(y)?(x):(y))
  83197. #ifdef _MSC_VER
  83198. #define FLAC__U64L(x) x
  83199. #else
  83200. #define FLAC__U64L(x) x##LLU
  83201. #endif
  83202. #ifndef FLaC__INLINE
  83203. #define FLaC__INLINE
  83204. #endif
  83205. struct FLAC__BitWriter {
  83206. bwword *buffer;
  83207. bwword accum; /* accumulator; bits are right-justified; when full, accum is appended to buffer */
  83208. unsigned capacity; /* capacity of buffer in words */
  83209. unsigned words; /* # of complete words in buffer */
  83210. unsigned bits; /* # of used bits in accum */
  83211. };
  83212. static FLAC__bool bitwriter_grow_(FLAC__BitWriter *bw, unsigned bits_to_add)
  83213. {
  83214. unsigned new_capacity;
  83215. bwword *new_buffer;
  83216. FLAC__ASSERT(0 != bw);
  83217. FLAC__ASSERT(0 != bw->buffer);
  83218. new_capacity = bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD);
  83219. if(bw->capacity >= new_capacity)
  83220. return true;
  83221. if((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT)
  83222. new_capacity += FLAC__BITWRITER_DEFAULT_INCREMENT - ((new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  83223. FLAC__ASSERT(0 == (new_capacity - bw->capacity) % FLAC__BITWRITER_DEFAULT_INCREMENT);
  83224. FLAC__ASSERT(new_capacity > bw->capacity);
  83225. FLAC__ASSERT(new_capacity >= bw->words + ((bw->bits + bits_to_add + FLAC__BITS_PER_WORD - 1) / FLAC__BITS_PER_WORD));
  83226. new_buffer = (bwword*)safe_realloc_mul_2op_(bw->buffer, sizeof(bwword), /*times*/new_capacity);
  83227. if(new_buffer == 0)
  83228. return false;
  83229. bw->buffer = new_buffer;
  83230. bw->capacity = new_capacity;
  83231. return true;
  83232. }
  83233. FLAC__BitWriter *FLAC__bitwriter_new(void)
  83234. {
  83235. FLAC__BitWriter *bw = (FLAC__BitWriter*)calloc(1, sizeof(FLAC__BitWriter));
  83236. return bw;
  83237. }
  83238. void FLAC__bitwriter_delete(FLAC__BitWriter *bw)
  83239. {
  83240. FLAC__ASSERT(0 != bw);
  83241. FLAC__bitwriter_free(bw);
  83242. free(bw);
  83243. }
  83244. FLAC__bool FLAC__bitwriter_init(FLAC__BitWriter *bw)
  83245. {
  83246. FLAC__ASSERT(0 != bw);
  83247. bw->words = bw->bits = 0;
  83248. bw->capacity = FLAC__BITWRITER_DEFAULT_CAPACITY;
  83249. bw->buffer = (bwword*)malloc(sizeof(bwword) * bw->capacity);
  83250. if(bw->buffer == 0)
  83251. return false;
  83252. return true;
  83253. }
  83254. void FLAC__bitwriter_free(FLAC__BitWriter *bw)
  83255. {
  83256. FLAC__ASSERT(0 != bw);
  83257. if(0 != bw->buffer)
  83258. free(bw->buffer);
  83259. bw->buffer = 0;
  83260. bw->capacity = 0;
  83261. bw->words = bw->bits = 0;
  83262. }
  83263. void FLAC__bitwriter_clear(FLAC__BitWriter *bw)
  83264. {
  83265. bw->words = bw->bits = 0;
  83266. }
  83267. void FLAC__bitwriter_dump(const FLAC__BitWriter *bw, FILE *out)
  83268. {
  83269. unsigned i, j;
  83270. if(bw == 0) {
  83271. fprintf(out, "bitwriter is NULL\n");
  83272. }
  83273. else {
  83274. fprintf(out, "bitwriter: capacity=%u words=%u bits=%u total_bits=%u\n", bw->capacity, bw->words, bw->bits, FLAC__TOTAL_BITS(bw));
  83275. for(i = 0; i < bw->words; i++) {
  83276. fprintf(out, "%08X: ", i);
  83277. for(j = 0; j < FLAC__BITS_PER_WORD; j++)
  83278. fprintf(out, "%01u", bw->buffer[i] & (1 << (FLAC__BITS_PER_WORD-j-1)) ? 1:0);
  83279. fprintf(out, "\n");
  83280. }
  83281. if(bw->bits > 0) {
  83282. fprintf(out, "%08X: ", i);
  83283. for(j = 0; j < bw->bits; j++)
  83284. fprintf(out, "%01u", bw->accum & (1 << (bw->bits-j-1)) ? 1:0);
  83285. fprintf(out, "\n");
  83286. }
  83287. }
  83288. }
  83289. FLAC__bool FLAC__bitwriter_get_write_crc16(FLAC__BitWriter *bw, FLAC__uint16 *crc)
  83290. {
  83291. const FLAC__byte *buffer;
  83292. size_t bytes;
  83293. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83294. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83295. return false;
  83296. *crc = (FLAC__uint16)FLAC__crc16(buffer, bytes);
  83297. FLAC__bitwriter_release_buffer(bw);
  83298. return true;
  83299. }
  83300. FLAC__bool FLAC__bitwriter_get_write_crc8(FLAC__BitWriter *bw, FLAC__byte *crc)
  83301. {
  83302. const FLAC__byte *buffer;
  83303. size_t bytes;
  83304. FLAC__ASSERT((bw->bits & 7) == 0); /* assert that we're byte-aligned */
  83305. if(!FLAC__bitwriter_get_buffer(bw, &buffer, &bytes))
  83306. return false;
  83307. *crc = FLAC__crc8(buffer, bytes);
  83308. FLAC__bitwriter_release_buffer(bw);
  83309. return true;
  83310. }
  83311. FLAC__bool FLAC__bitwriter_is_byte_aligned(const FLAC__BitWriter *bw)
  83312. {
  83313. return ((bw->bits & 7) == 0);
  83314. }
  83315. unsigned FLAC__bitwriter_get_input_bits_unconsumed(const FLAC__BitWriter *bw)
  83316. {
  83317. return FLAC__TOTAL_BITS(bw);
  83318. }
  83319. FLAC__bool FLAC__bitwriter_get_buffer(FLAC__BitWriter *bw, const FLAC__byte **buffer, size_t *bytes)
  83320. {
  83321. FLAC__ASSERT((bw->bits & 7) == 0);
  83322. if(bw->bits & 7)
  83323. return false;
  83324. if(bw->bits) {
  83325. FLAC__ASSERT(bw->words <= bw->capacity);
  83326. if(bw->words == bw->capacity && !bitwriter_grow_(bw, FLAC__BITS_PER_WORD))
  83327. return false;
  83328. bw->buffer[bw->words] = SWAP_BE_WORD_TO_HOST(bw->accum << (FLAC__BITS_PER_WORD-bw->bits));
  83329. }
  83330. *buffer = (FLAC__byte*)bw->buffer;
  83331. *bytes = (FLAC__BYTES_PER_WORD * bw->words) + (bw->bits >> 3);
  83332. return true;
  83333. }
  83334. void FLAC__bitwriter_release_buffer(FLAC__BitWriter *bw)
  83335. {
  83336. (void)bw;
  83337. }
  83338. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_zeroes(FLAC__BitWriter *bw, unsigned bits)
  83339. {
  83340. unsigned n;
  83341. FLAC__ASSERT(0 != bw);
  83342. FLAC__ASSERT(0 != bw->buffer);
  83343. if(bits == 0)
  83344. return true;
  83345. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83346. return false;
  83347. if(bw->bits) {
  83348. n = min(FLAC__BITS_PER_WORD - bw->bits, bits);
  83349. bw->accum <<= n;
  83350. bits -= n;
  83351. bw->bits += n;
  83352. if(bw->bits == FLAC__BITS_PER_WORD) {
  83353. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83354. bw->bits = 0;
  83355. }
  83356. else
  83357. return true;
  83358. }
  83359. while(bits >= FLAC__BITS_PER_WORD) {
  83360. bw->buffer[bw->words++] = 0;
  83361. bits -= FLAC__BITS_PER_WORD;
  83362. }
  83363. if(bits > 0) {
  83364. bw->accum = 0;
  83365. bw->bits = bits;
  83366. }
  83367. return true;
  83368. }
  83369. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32(FLAC__BitWriter *bw, FLAC__uint32 val, unsigned bits)
  83370. {
  83371. register unsigned left;
  83372. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83373. FLAC__ASSERT(0 != bw);
  83374. FLAC__ASSERT(0 != bw->buffer);
  83375. FLAC__ASSERT(bits <= 32);
  83376. if(bits == 0)
  83377. return true;
  83378. if(bw->capacity <= bw->words + bits && !bitwriter_grow_(bw, bits))
  83379. return false;
  83380. left = FLAC__BITS_PER_WORD - bw->bits;
  83381. if(bits < left) {
  83382. bw->accum <<= bits;
  83383. bw->accum |= val;
  83384. bw->bits += bits;
  83385. }
  83386. 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 */
  83387. bw->accum <<= left;
  83388. bw->accum |= val >> (bw->bits = bits - left);
  83389. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83390. bw->accum = val;
  83391. }
  83392. else {
  83393. bw->accum = val;
  83394. bw->bits = 0;
  83395. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(val);
  83396. }
  83397. return true;
  83398. }
  83399. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_int32(FLAC__BitWriter *bw, FLAC__int32 val, unsigned bits)
  83400. {
  83401. if(bits < 32)
  83402. val &= (~(0xffffffff << bits));
  83403. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83404. }
  83405. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint64(FLAC__BitWriter *bw, FLAC__uint64 val, unsigned bits)
  83406. {
  83407. if(bits > 32) {
  83408. return
  83409. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(val>>32), bits-32) &&
  83410. FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 32);
  83411. }
  83412. else
  83413. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, bits);
  83414. }
  83415. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_raw_uint32_little_endian(FLAC__BitWriter *bw, FLAC__uint32 val)
  83416. {
  83417. if(!FLAC__bitwriter_write_raw_uint32(bw, val & 0xff, 8))
  83418. return false;
  83419. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>8) & 0xff, 8))
  83420. return false;
  83421. if(!FLAC__bitwriter_write_raw_uint32(bw, (val>>16) & 0xff, 8))
  83422. return false;
  83423. if(!FLAC__bitwriter_write_raw_uint32(bw, val>>24, 8))
  83424. return false;
  83425. return true;
  83426. }
  83427. FLaC__INLINE FLAC__bool FLAC__bitwriter_write_byte_block(FLAC__BitWriter *bw, const FLAC__byte vals[], unsigned nvals)
  83428. {
  83429. unsigned i;
  83430. for(i = 0; i < nvals; i++) {
  83431. if(!FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)(vals[i]), 8))
  83432. return false;
  83433. }
  83434. return true;
  83435. }
  83436. FLAC__bool FLAC__bitwriter_write_unary_unsigned(FLAC__BitWriter *bw, unsigned val)
  83437. {
  83438. if(val < 32)
  83439. return FLAC__bitwriter_write_raw_uint32(bw, 1, ++val);
  83440. else
  83441. return
  83442. FLAC__bitwriter_write_zeroes(bw, val) &&
  83443. FLAC__bitwriter_write_raw_uint32(bw, 1, 1);
  83444. }
  83445. unsigned FLAC__bitwriter_rice_bits(FLAC__int32 val, unsigned parameter)
  83446. {
  83447. FLAC__uint32 uval;
  83448. FLAC__ASSERT(parameter < sizeof(unsigned)*8);
  83449. uval = (val<<1) ^ (val>>31);
  83450. return 1 + parameter + (uval >> parameter);
  83451. }
  83452. #if 0 /* UNUSED */
  83453. unsigned FLAC__bitwriter_golomb_bits_signed(int val, unsigned parameter)
  83454. {
  83455. unsigned bits, msbs, uval;
  83456. unsigned k;
  83457. FLAC__ASSERT(parameter > 0);
  83458. if(val < 0)
  83459. uval = (unsigned)(((-(++val)) << 1) + 1);
  83460. else
  83461. uval = (unsigned)(val << 1);
  83462. k = FLAC__bitmath_ilog2(parameter);
  83463. if(parameter == 1u<<k) {
  83464. FLAC__ASSERT(k <= 30);
  83465. msbs = uval >> k;
  83466. bits = 1 + k + msbs;
  83467. }
  83468. else {
  83469. unsigned q, r, d;
  83470. d = (1 << (k+1)) - parameter;
  83471. q = uval / parameter;
  83472. r = uval - (q * parameter);
  83473. bits = 1 + q + k;
  83474. if(r >= d)
  83475. bits++;
  83476. }
  83477. return bits;
  83478. }
  83479. unsigned FLAC__bitwriter_golomb_bits_unsigned(unsigned uval, unsigned parameter)
  83480. {
  83481. unsigned bits, msbs;
  83482. unsigned k;
  83483. FLAC__ASSERT(parameter > 0);
  83484. k = FLAC__bitmath_ilog2(parameter);
  83485. if(parameter == 1u<<k) {
  83486. FLAC__ASSERT(k <= 30);
  83487. msbs = uval >> k;
  83488. bits = 1 + k + msbs;
  83489. }
  83490. else {
  83491. unsigned q, r, d;
  83492. d = (1 << (k+1)) - parameter;
  83493. q = uval / parameter;
  83494. r = uval - (q * parameter);
  83495. bits = 1 + q + k;
  83496. if(r >= d)
  83497. bits++;
  83498. }
  83499. return bits;
  83500. }
  83501. #endif /* UNUSED */
  83502. FLAC__bool FLAC__bitwriter_write_rice_signed(FLAC__BitWriter *bw, FLAC__int32 val, unsigned parameter)
  83503. {
  83504. unsigned total_bits, interesting_bits, msbs;
  83505. FLAC__uint32 uval, pattern;
  83506. FLAC__ASSERT(0 != bw);
  83507. FLAC__ASSERT(0 != bw->buffer);
  83508. FLAC__ASSERT(parameter < 8*sizeof(uval));
  83509. uval = (val<<1) ^ (val>>31);
  83510. msbs = uval >> parameter;
  83511. interesting_bits = 1 + parameter;
  83512. total_bits = interesting_bits + msbs;
  83513. pattern = 1 << parameter; /* the unary end bit */
  83514. pattern |= (uval & ((1<<parameter)-1)); /* the binary LSBs */
  83515. if(total_bits <= 32)
  83516. return FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits);
  83517. else
  83518. return
  83519. FLAC__bitwriter_write_zeroes(bw, msbs) && /* write the unary MSBs */
  83520. FLAC__bitwriter_write_raw_uint32(bw, pattern, interesting_bits); /* write the unary end bit and binary LSBs */
  83521. }
  83522. FLAC__bool FLAC__bitwriter_write_rice_signed_block(FLAC__BitWriter *bw, const FLAC__int32 *vals, unsigned nvals, unsigned parameter)
  83523. {
  83524. const FLAC__uint32 mask1 = FLAC__WORD_ALL_ONES << parameter; /* we val|=mask1 to set the stop bit above it... */
  83525. const FLAC__uint32 mask2 = FLAC__WORD_ALL_ONES >> (31-parameter); /* ...then mask off the bits above the stop bit with val&=mask2*/
  83526. FLAC__uint32 uval;
  83527. unsigned left;
  83528. const unsigned lsbits = 1 + parameter;
  83529. unsigned msbits;
  83530. FLAC__ASSERT(0 != bw);
  83531. FLAC__ASSERT(0 != bw->buffer);
  83532. FLAC__ASSERT(parameter < 8*sizeof(bwword)-1);
  83533. FLAC__ASSERT(FLAC__BITS_PER_WORD >= 32);
  83534. while(nvals) {
  83535. uval = (*vals<<1) ^ (*vals>>31);
  83536. msbits = uval >> parameter;
  83537. #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) */
  83538. if(bw->bits && bw->bits + msbits + lsbits <= FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83539. bw->bits = bw->bits + msbits + lsbits;
  83540. uval |= mask1; /* set stop bit */
  83541. uval &= mask2; /* mask off unused top bits */
  83542. bw->accum <<= msbits;
  83543. bw->accum <<= lsbits;
  83544. bw->accum |= uval;
  83545. if(bw->bits == FLAC__BITS_PER_WORD) {
  83546. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83547. bw->bits = 0;
  83548. if(bw->capacity <= bw->words && nvals > 1 && !bitwriter_grow_(bw, 1)) {
  83549. FLAC__ASSERT(bw->capacity == bw->words);
  83550. return false;
  83551. }
  83552. }
  83553. }
  83554. else {
  83555. #elif 1 /*@@@@@@ OPT: try this version with MSVC6 to see if better, not much difference for gcc-4 */
  83556. if(bw->bits && bw->bits + msbits + lsbits < FLAC__BITS_PER_WORD) { /* i.e. if the whole thing fits in the current bwword */
  83557. bw->bits = bw->bits + msbits + lsbits;
  83558. uval |= mask1; /* set stop bit */
  83559. uval &= mask2; /* mask off unused top bits */
  83560. bw->accum <<= msbits + lsbits;
  83561. bw->accum |= uval;
  83562. }
  83563. else {
  83564. #endif
  83565. if(bw->capacity <= bw->words + bw->bits + msbits + 1/*lsbits always fit in 1 bwword*/ && !bitwriter_grow_(bw, msbits+lsbits))
  83566. return false;
  83567. if(msbits) {
  83568. if(bw->bits) {
  83569. left = FLAC__BITS_PER_WORD - bw->bits;
  83570. if(msbits < left) {
  83571. bw->accum <<= msbits;
  83572. bw->bits += msbits;
  83573. goto break1;
  83574. }
  83575. else {
  83576. bw->accum <<= left;
  83577. msbits -= left;
  83578. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83579. bw->bits = 0;
  83580. }
  83581. }
  83582. while(msbits >= FLAC__BITS_PER_WORD) {
  83583. bw->buffer[bw->words++] = 0;
  83584. msbits -= FLAC__BITS_PER_WORD;
  83585. }
  83586. if(msbits > 0) {
  83587. bw->accum = 0;
  83588. bw->bits = msbits;
  83589. }
  83590. }
  83591. break1:
  83592. uval |= mask1; /* set stop bit */
  83593. uval &= mask2; /* mask off unused top bits */
  83594. left = FLAC__BITS_PER_WORD - bw->bits;
  83595. if(lsbits < left) {
  83596. bw->accum <<= lsbits;
  83597. bw->accum |= uval;
  83598. bw->bits += lsbits;
  83599. }
  83600. else {
  83601. FLAC__ASSERT(bw->bits);
  83602. FLAC__ASSERT(left < FLAC__BITS_PER_WORD);
  83603. bw->accum <<= left;
  83604. bw->accum |= uval >> (bw->bits = lsbits - left);
  83605. bw->buffer[bw->words++] = SWAP_BE_WORD_TO_HOST(bw->accum);
  83606. bw->accum = uval;
  83607. }
  83608. #if 1
  83609. }
  83610. #endif
  83611. vals++;
  83612. nvals--;
  83613. }
  83614. return true;
  83615. }
  83616. #if 0 /* UNUSED */
  83617. FLAC__bool FLAC__bitwriter_write_golomb_signed(FLAC__BitWriter *bw, int val, unsigned parameter)
  83618. {
  83619. unsigned total_bits, msbs, uval;
  83620. unsigned k;
  83621. FLAC__ASSERT(0 != bw);
  83622. FLAC__ASSERT(0 != bw->buffer);
  83623. FLAC__ASSERT(parameter > 0);
  83624. if(val < 0)
  83625. uval = (unsigned)(((-(++val)) << 1) + 1);
  83626. else
  83627. uval = (unsigned)(val << 1);
  83628. k = FLAC__bitmath_ilog2(parameter);
  83629. if(parameter == 1u<<k) {
  83630. unsigned pattern;
  83631. FLAC__ASSERT(k <= 30);
  83632. msbs = uval >> k;
  83633. total_bits = 1 + k + msbs;
  83634. pattern = 1 << k; /* the unary end bit */
  83635. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83636. if(total_bits <= 32) {
  83637. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83638. return false;
  83639. }
  83640. else {
  83641. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83642. return false;
  83643. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83644. return false;
  83645. }
  83646. }
  83647. else {
  83648. unsigned q, r, d;
  83649. d = (1 << (k+1)) - parameter;
  83650. q = uval / parameter;
  83651. r = uval - (q * parameter);
  83652. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83653. return false;
  83654. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83655. return false;
  83656. if(r >= d) {
  83657. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83658. return false;
  83659. }
  83660. else {
  83661. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83662. return false;
  83663. }
  83664. }
  83665. return true;
  83666. }
  83667. FLAC__bool FLAC__bitwriter_write_golomb_unsigned(FLAC__BitWriter *bw, unsigned uval, unsigned parameter)
  83668. {
  83669. unsigned total_bits, msbs;
  83670. unsigned k;
  83671. FLAC__ASSERT(0 != bw);
  83672. FLAC__ASSERT(0 != bw->buffer);
  83673. FLAC__ASSERT(parameter > 0);
  83674. k = FLAC__bitmath_ilog2(parameter);
  83675. if(parameter == 1u<<k) {
  83676. unsigned pattern;
  83677. FLAC__ASSERT(k <= 30);
  83678. msbs = uval >> k;
  83679. total_bits = 1 + k + msbs;
  83680. pattern = 1 << k; /* the unary end bit */
  83681. pattern |= (uval & ((1u<<k)-1)); /* the binary LSBs */
  83682. if(total_bits <= 32) {
  83683. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, total_bits))
  83684. return false;
  83685. }
  83686. else {
  83687. if(!FLAC__bitwriter_write_zeroes(bw, msbs))
  83688. return false;
  83689. if(!FLAC__bitwriter_write_raw_uint32(bw, pattern, k+1))
  83690. return false;
  83691. }
  83692. }
  83693. else {
  83694. unsigned q, r, d;
  83695. d = (1 << (k+1)) - parameter;
  83696. q = uval / parameter;
  83697. r = uval - (q * parameter);
  83698. if(!FLAC__bitwriter_write_zeroes(bw, q))
  83699. return false;
  83700. if(!FLAC__bitwriter_write_raw_uint32(bw, 1, 1))
  83701. return false;
  83702. if(r >= d) {
  83703. if(!FLAC__bitwriter_write_raw_uint32(bw, r+d, k+1))
  83704. return false;
  83705. }
  83706. else {
  83707. if(!FLAC__bitwriter_write_raw_uint32(bw, r, k))
  83708. return false;
  83709. }
  83710. }
  83711. return true;
  83712. }
  83713. #endif /* UNUSED */
  83714. FLAC__bool FLAC__bitwriter_write_utf8_uint32(FLAC__BitWriter *bw, FLAC__uint32 val)
  83715. {
  83716. FLAC__bool ok = 1;
  83717. FLAC__ASSERT(0 != bw);
  83718. FLAC__ASSERT(0 != bw->buffer);
  83719. FLAC__ASSERT(!(val & 0x80000000)); /* this version only handles 31 bits */
  83720. if(val < 0x80) {
  83721. return FLAC__bitwriter_write_raw_uint32(bw, val, 8);
  83722. }
  83723. else if(val < 0x800) {
  83724. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (val>>6), 8);
  83725. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83726. }
  83727. else if(val < 0x10000) {
  83728. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (val>>12), 8);
  83729. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83730. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83731. }
  83732. else if(val < 0x200000) {
  83733. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (val>>18), 8);
  83734. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83735. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83736. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83737. }
  83738. else if(val < 0x4000000) {
  83739. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (val>>24), 8);
  83740. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83741. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83742. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83743. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83744. }
  83745. else {
  83746. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (val>>30), 8);
  83747. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>24)&0x3F), 8);
  83748. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>18)&0x3F), 8);
  83749. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>12)&0x3F), 8);
  83750. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | ((val>>6)&0x3F), 8);
  83751. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (val&0x3F), 8);
  83752. }
  83753. return ok;
  83754. }
  83755. FLAC__bool FLAC__bitwriter_write_utf8_uint64(FLAC__BitWriter *bw, FLAC__uint64 val)
  83756. {
  83757. FLAC__bool ok = 1;
  83758. FLAC__ASSERT(0 != bw);
  83759. FLAC__ASSERT(0 != bw->buffer);
  83760. FLAC__ASSERT(!(val & FLAC__U64L(0xFFFFFFF000000000))); /* this version only handles 36 bits */
  83761. if(val < 0x80) {
  83762. return FLAC__bitwriter_write_raw_uint32(bw, (FLAC__uint32)val, 8);
  83763. }
  83764. else if(val < 0x800) {
  83765. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xC0 | (FLAC__uint32)(val>>6), 8);
  83766. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83767. }
  83768. else if(val < 0x10000) {
  83769. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xE0 | (FLAC__uint32)(val>>12), 8);
  83770. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83771. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83772. }
  83773. else if(val < 0x200000) {
  83774. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF0 | (FLAC__uint32)(val>>18), 8);
  83775. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83776. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83777. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83778. }
  83779. else if(val < 0x4000000) {
  83780. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xF8 | (FLAC__uint32)(val>>24), 8);
  83781. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83782. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83783. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83784. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83785. }
  83786. else if(val < 0x80000000) {
  83787. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFC | (FLAC__uint32)(val>>30), 8);
  83788. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83789. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83790. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83791. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83792. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83793. }
  83794. else {
  83795. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0xFE, 8);
  83796. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>30)&0x3F), 8);
  83797. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>24)&0x3F), 8);
  83798. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>18)&0x3F), 8);
  83799. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>12)&0x3F), 8);
  83800. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)((val>>6)&0x3F), 8);
  83801. ok &= FLAC__bitwriter_write_raw_uint32(bw, 0x80 | (FLAC__uint32)(val&0x3F), 8);
  83802. }
  83803. return ok;
  83804. }
  83805. FLAC__bool FLAC__bitwriter_zero_pad_to_byte_boundary(FLAC__BitWriter *bw)
  83806. {
  83807. if(bw->bits & 7u)
  83808. return FLAC__bitwriter_write_zeroes(bw, 8 - (bw->bits & 7u));
  83809. else
  83810. return true;
  83811. }
  83812. #endif
  83813. /*** End of inlined file: bitwriter.c ***/
  83814. /*** Start of inlined file: cpu.c ***/
  83815. /*** Start of inlined file: juce_FlacHeader.h ***/
  83816. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  83817. // tasks..
  83818. #define VERSION "1.2.1"
  83819. #define FLAC__NO_DLL 1
  83820. #if JUCE_MSVC
  83821. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  83822. #endif
  83823. #if JUCE_MAC
  83824. #define FLAC__SYS_DARWIN 1
  83825. #endif
  83826. /*** End of inlined file: juce_FlacHeader.h ***/
  83827. #if JUCE_USE_FLAC
  83828. #if HAVE_CONFIG_H
  83829. # include <config.h>
  83830. #endif
  83831. #include <stdlib.h>
  83832. #include <stdio.h>
  83833. #if defined FLAC__CPU_IA32
  83834. # include <signal.h>
  83835. #elif defined FLAC__CPU_PPC
  83836. # if !defined FLAC__NO_ASM
  83837. # if defined FLAC__SYS_DARWIN
  83838. # include <sys/sysctl.h>
  83839. # include <mach/mach.h>
  83840. # include <mach/mach_host.h>
  83841. # include <mach/host_info.h>
  83842. # include <mach/machine.h>
  83843. # ifndef CPU_SUBTYPE_POWERPC_970
  83844. # define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
  83845. # endif
  83846. # else /* FLAC__SYS_DARWIN */
  83847. # include <signal.h>
  83848. # include <setjmp.h>
  83849. static sigjmp_buf jmpbuf;
  83850. static volatile sig_atomic_t canjump = 0;
  83851. static void sigill_handler (int sig)
  83852. {
  83853. if (!canjump) {
  83854. signal (sig, SIG_DFL);
  83855. raise (sig);
  83856. }
  83857. canjump = 0;
  83858. siglongjmp (jmpbuf, 1);
  83859. }
  83860. # endif /* FLAC__SYS_DARWIN */
  83861. # endif /* FLAC__NO_ASM */
  83862. #endif /* FLAC__CPU_PPC */
  83863. #if defined (__NetBSD__) || defined(__OpenBSD__)
  83864. #include <sys/param.h>
  83865. #include <sys/sysctl.h>
  83866. #include <machine/cpu.h>
  83867. #endif
  83868. #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__)
  83869. #include <sys/types.h>
  83870. #include <sys/sysctl.h>
  83871. #endif
  83872. #if defined(__APPLE__)
  83873. #endif
  83874. static const unsigned FLAC__CPUINFO_IA32_CPUID_CMOV = 0x00008000;
  83875. static const unsigned FLAC__CPUINFO_IA32_CPUID_MMX = 0x00800000;
  83876. static const unsigned FLAC__CPUINFO_IA32_CPUID_FXSR = 0x01000000;
  83877. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE = 0x02000000;
  83878. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE2 = 0x04000000;
  83879. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSE3 = 0x00000001;
  83880. static const unsigned FLAC__CPUINFO_IA32_CPUID_SSSE3 = 0x00000200;
  83881. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW = 0x80000000;
  83882. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW = 0x40000000;
  83883. static const unsigned FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX = 0x00400000;
  83884. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM && !defined FLAC__NO_SSE_OS && !defined FLAC__SSE_OS
  83885. # if defined(__linux__)
  83886. # undef USE_OBSOLETE_SIGCONTEXT_FLAVOR /* #define this to use the older signal handler method */
  83887. # ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83888. static void sigill_handler_sse_os(int signal, struct sigcontext sc)
  83889. {
  83890. (void)signal;
  83891. sc.eip += 3 + 3 + 6;
  83892. }
  83893. # else
  83894. # include <sys/ucontext.h>
  83895. static void sigill_handler_sse_os(int signal, siginfo_t *si, void *uc)
  83896. {
  83897. (void)signal, (void)si;
  83898. ((ucontext_t*)uc)->uc_mcontext.gregs[14/*REG_EIP*/] += 3 + 3 + 6;
  83899. }
  83900. # endif
  83901. # elif defined(_MSC_VER)
  83902. # include <windows.h>
  83903. # undef USE_TRY_CATCH_FLAVOR /* #define this to use the try/catch method for catching illegal opcode exception */
  83904. # ifdef USE_TRY_CATCH_FLAVOR
  83905. # else
  83906. LONG CALLBACK sigill_handler_sse_os(EXCEPTION_POINTERS *ep)
  83907. {
  83908. if(ep->ExceptionRecord->ExceptionCode == EXCEPTION_ILLEGAL_INSTRUCTION) {
  83909. ep->ContextRecord->Eip += 3 + 3 + 6;
  83910. return EXCEPTION_CONTINUE_EXECUTION;
  83911. }
  83912. return EXCEPTION_CONTINUE_SEARCH;
  83913. }
  83914. # endif
  83915. # endif
  83916. #endif
  83917. void FLAC__cpu_info(FLAC__CPUInfo *info)
  83918. {
  83919. #ifdef FLAC__CPU_IA32
  83920. info->type = FLAC__CPUINFO_TYPE_IA32;
  83921. #if !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  83922. info->use_asm = true; /* we assume a minimum of 80386 with FLAC__CPU_IA32 */
  83923. info->data.ia32.cpuid = FLAC__cpu_have_cpuid_asm_ia32()? true : false;
  83924. info->data.ia32.bswap = info->data.ia32.cpuid; /* CPUID => BSWAP since it came after */
  83925. info->data.ia32.cmov = false;
  83926. info->data.ia32.mmx = false;
  83927. info->data.ia32.fxsr = false;
  83928. info->data.ia32.sse = false;
  83929. info->data.ia32.sse2 = false;
  83930. info->data.ia32.sse3 = false;
  83931. info->data.ia32.ssse3 = false;
  83932. info->data.ia32._3dnow = false;
  83933. info->data.ia32.ext3dnow = false;
  83934. info->data.ia32.extmmx = false;
  83935. if(info->data.ia32.cpuid) {
  83936. FLAC__uint32 flags_edx, flags_ecx;
  83937. FLAC__cpu_info_asm_ia32(&flags_edx, &flags_ecx);
  83938. info->data.ia32.cmov = (flags_edx & FLAC__CPUINFO_IA32_CPUID_CMOV )? true : false;
  83939. info->data.ia32.mmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_MMX )? true : false;
  83940. info->data.ia32.fxsr = (flags_edx & FLAC__CPUINFO_IA32_CPUID_FXSR )? true : false;
  83941. info->data.ia32.sse = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE )? true : false;
  83942. info->data.ia32.sse2 = (flags_edx & FLAC__CPUINFO_IA32_CPUID_SSE2 )? true : false;
  83943. info->data.ia32.sse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSE3 )? true : false;
  83944. info->data.ia32.ssse3 = (flags_ecx & FLAC__CPUINFO_IA32_CPUID_SSSE3)? true : false;
  83945. #ifdef FLAC__USE_3DNOW
  83946. flags_edx = FLAC__cpu_info_extended_amd_asm_ia32();
  83947. info->data.ia32._3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_3DNOW )? true : false;
  83948. info->data.ia32.ext3dnow = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXT3DNOW)? true : false;
  83949. info->data.ia32.extmmx = (flags_edx & FLAC__CPUINFO_IA32_CPUID_EXTENDED_AMD_EXTMMX )? true : false;
  83950. #else
  83951. info->data.ia32._3dnow = info->data.ia32.ext3dnow = info->data.ia32.extmmx = false;
  83952. #endif
  83953. #ifdef DEBUG
  83954. fprintf(stderr, "CPU info (IA-32):\n");
  83955. fprintf(stderr, " CPUID ...... %c\n", info->data.ia32.cpuid ? 'Y' : 'n');
  83956. fprintf(stderr, " BSWAP ...... %c\n", info->data.ia32.bswap ? 'Y' : 'n');
  83957. fprintf(stderr, " CMOV ....... %c\n", info->data.ia32.cmov ? 'Y' : 'n');
  83958. fprintf(stderr, " MMX ........ %c\n", info->data.ia32.mmx ? 'Y' : 'n');
  83959. fprintf(stderr, " FXSR ....... %c\n", info->data.ia32.fxsr ? 'Y' : 'n');
  83960. fprintf(stderr, " SSE ........ %c\n", info->data.ia32.sse ? 'Y' : 'n');
  83961. fprintf(stderr, " SSE2 ....... %c\n", info->data.ia32.sse2 ? 'Y' : 'n');
  83962. fprintf(stderr, " SSE3 ....... %c\n", info->data.ia32.sse3 ? 'Y' : 'n');
  83963. fprintf(stderr, " SSSE3 ...... %c\n", info->data.ia32.ssse3 ? 'Y' : 'n');
  83964. fprintf(stderr, " 3DNow! ..... %c\n", info->data.ia32._3dnow ? 'Y' : 'n');
  83965. fprintf(stderr, " 3DNow!-ext . %c\n", info->data.ia32.ext3dnow? 'Y' : 'n');
  83966. fprintf(stderr, " 3DNow!-MMX . %c\n", info->data.ia32.extmmx ? 'Y' : 'n');
  83967. #endif
  83968. if(info->data.ia32.fxsr || info->data.ia32.sse || info->data.ia32.sse2) {
  83969. #if defined FLAC__NO_SSE_OS
  83970. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83971. #elif defined FLAC__SSE_OS
  83972. #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) || defined(__APPLE__)
  83973. int sse = 0;
  83974. size_t len;
  83975. len = sizeof(sse); sse = sse || (sysctlbyname("hw.instruction_sse", &sse, &len, NULL, 0) == 0 && sse);
  83976. len = sizeof(sse); sse = sse || (sysctlbyname("hw.optional.sse" , &sse, &len, NULL, 0) == 0 && sse); /* __APPLE__ ? */
  83977. if(!sse)
  83978. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83979. #elif defined(__NetBSD__) || defined (__OpenBSD__)
  83980. # if __NetBSD_Version__ >= 105250000 || (defined __OpenBSD__)
  83981. int val = 0, mib[2] = { CTL_MACHDEP, CPU_SSE };
  83982. size_t len = sizeof(val);
  83983. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83984. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83985. else { /* double-check SSE2 */
  83986. mib[1] = CPU_SSE2;
  83987. len = sizeof(val);
  83988. if(sysctl(mib, 2, &val, &len, NULL, 0) < 0 || !val)
  83989. info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83990. }
  83991. # else
  83992. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  83993. # endif
  83994. #elif defined(__linux__)
  83995. int sse = 0;
  83996. struct sigaction sigill_save;
  83997. #ifdef USE_OBSOLETE_SIGCONTEXT_FLAVOR
  83998. if(0 == sigaction(SIGILL, NULL, &sigill_save) && signal(SIGILL, (void (*)(int))sigill_handler_sse_os) != SIG_ERR)
  83999. #else
  84000. struct sigaction sigill_sse;
  84001. sigill_sse.sa_sigaction = sigill_handler_sse_os;
  84002. __sigemptyset(&sigill_sse.sa_mask);
  84003. 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 */
  84004. if(0 == sigaction(SIGILL, &sigill_sse, &sigill_save))
  84005. #endif
  84006. {
  84007. asm volatile (
  84008. "xorl %0,%0\n\t" /* for some reason, still need to do this to clear 'sse' var */
  84009. "xorps %%xmm0,%%xmm0\n\t" /* will cause SIGILL if unsupported by OS */
  84010. "incl %0\n\t" /* SIGILL handler will jump over this */
  84011. "nop\n\t" /* SIGILL jump lands here if "inc" is 9 bytes */
  84012. "nop\n\t"
  84013. "nop\n\t"
  84014. "nop\n\t"
  84015. "nop\n\t"
  84016. "nop\n\t"
  84017. "nop\n\t" /* SIGILL jump lands here if "inc" is 3 bytes (expected) */
  84018. "nop\n\t"
  84019. "nop" /* SIGILL jump lands here if "inc" is 1 byte */
  84020. : "=r"(sse)
  84021. : "r"(sse)
  84022. );
  84023. sigaction(SIGILL, &sigill_save, NULL);
  84024. }
  84025. if(!sse)
  84026. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84027. #elif defined(_MSC_VER)
  84028. # ifdef USE_TRY_CATCH_FLAVOR
  84029. _try {
  84030. __asm {
  84031. # if _MSC_VER <= 1200
  84032. _emit 0x0F
  84033. _emit 0x57
  84034. _emit 0xC0
  84035. # else
  84036. xorps xmm0,xmm0
  84037. # endif
  84038. }
  84039. }
  84040. _except(EXCEPTION_EXECUTE_HANDLER) {
  84041. if (_exception_code() == STATUS_ILLEGAL_INSTRUCTION)
  84042. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84043. }
  84044. # else
  84045. int sse = 0;
  84046. LPTOP_LEVEL_EXCEPTION_FILTER save = SetUnhandledExceptionFilter(sigill_handler_sse_os);
  84047. __asm {
  84048. # if _MSC_VER <= 1200
  84049. _emit 0x0F
  84050. _emit 0x57
  84051. _emit 0xC0
  84052. # else
  84053. xorps xmm0,xmm0
  84054. # endif
  84055. inc sse
  84056. nop
  84057. nop
  84058. nop
  84059. nop
  84060. nop
  84061. nop
  84062. nop
  84063. nop
  84064. nop
  84065. }
  84066. SetUnhandledExceptionFilter(save);
  84067. if(!sse)
  84068. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84069. # endif
  84070. #else
  84071. info->data.ia32.fxsr = info->data.ia32.sse = info->data.ia32.sse2 = info->data.ia32.sse3 = info->data.ia32.ssse3 = false;
  84072. #endif
  84073. #ifdef DEBUG
  84074. fprintf(stderr, " SSE OS sup . %c\n", info->data.ia32.sse ? 'Y' : 'n');
  84075. #endif
  84076. }
  84077. }
  84078. #else
  84079. info->use_asm = false;
  84080. #endif
  84081. #elif defined FLAC__CPU_PPC
  84082. info->type = FLAC__CPUINFO_TYPE_PPC;
  84083. # if !defined FLAC__NO_ASM
  84084. info->use_asm = true;
  84085. # ifdef FLAC__USE_ALTIVEC
  84086. # if defined FLAC__SYS_DARWIN
  84087. {
  84088. int val = 0, mib[2] = { CTL_HW, HW_VECTORUNIT };
  84089. size_t len = sizeof(val);
  84090. info->data.ppc.altivec = !(sysctl(mib, 2, &val, &len, NULL, 0) || !val);
  84091. }
  84092. {
  84093. host_basic_info_data_t hostInfo;
  84094. mach_msg_type_number_t infoCount;
  84095. infoCount = HOST_BASIC_INFO_COUNT;
  84096. host_info(mach_host_self(), HOST_BASIC_INFO, (host_info_t)&hostInfo, &infoCount);
  84097. info->data.ppc.ppc64 = (hostInfo.cpu_type == CPU_TYPE_POWERPC) && (hostInfo.cpu_subtype == CPU_SUBTYPE_POWERPC_970);
  84098. }
  84099. # else /* FLAC__USE_ALTIVEC && !FLAC__SYS_DARWIN */
  84100. {
  84101. info->data.ppc.altivec = 0;
  84102. info->data.ppc.ppc64 = 0;
  84103. signal (SIGILL, sigill_handler);
  84104. canjump = 0;
  84105. if (!sigsetjmp (jmpbuf, 1)) {
  84106. canjump = 1;
  84107. asm volatile (
  84108. "mtspr 256, %0\n\t"
  84109. "vand %%v0, %%v0, %%v0"
  84110. :
  84111. : "r" (-1)
  84112. );
  84113. info->data.ppc.altivec = 1;
  84114. }
  84115. canjump = 0;
  84116. if (!sigsetjmp (jmpbuf, 1)) {
  84117. int x = 0;
  84118. canjump = 1;
  84119. asm volatile ("cntlzd %0, %1" : "=r" (x) : "r" (x) );
  84120. info->data.ppc.ppc64 = 1;
  84121. }
  84122. signal (SIGILL, SIG_DFL); /*@@@@@@ should save and restore old signal */
  84123. }
  84124. # endif
  84125. # else /* !FLAC__USE_ALTIVEC */
  84126. info->data.ppc.altivec = 0;
  84127. info->data.ppc.ppc64 = 0;
  84128. # endif
  84129. # else
  84130. info->use_asm = false;
  84131. # endif
  84132. #else
  84133. info->type = FLAC__CPUINFO_TYPE_UNKNOWN;
  84134. info->use_asm = false;
  84135. #endif
  84136. }
  84137. #endif
  84138. /*** End of inlined file: cpu.c ***/
  84139. /*** Start of inlined file: crc.c ***/
  84140. /*** Start of inlined file: juce_FlacHeader.h ***/
  84141. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84142. // tasks..
  84143. #define VERSION "1.2.1"
  84144. #define FLAC__NO_DLL 1
  84145. #if JUCE_MSVC
  84146. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84147. #endif
  84148. #if JUCE_MAC
  84149. #define FLAC__SYS_DARWIN 1
  84150. #endif
  84151. /*** End of inlined file: juce_FlacHeader.h ***/
  84152. #if JUCE_USE_FLAC
  84153. #if HAVE_CONFIG_H
  84154. # include <config.h>
  84155. #endif
  84156. FLAC__byte const FLAC__crc8_table[256] = {
  84157. 0x00, 0x07, 0x0E, 0x09, 0x1C, 0x1B, 0x12, 0x15,
  84158. 0x38, 0x3F, 0x36, 0x31, 0x24, 0x23, 0x2A, 0x2D,
  84159. 0x70, 0x77, 0x7E, 0x79, 0x6C, 0x6B, 0x62, 0x65,
  84160. 0x48, 0x4F, 0x46, 0x41, 0x54, 0x53, 0x5A, 0x5D,
  84161. 0xE0, 0xE7, 0xEE, 0xE9, 0xFC, 0xFB, 0xF2, 0xF5,
  84162. 0xD8, 0xDF, 0xD6, 0xD1, 0xC4, 0xC3, 0xCA, 0xCD,
  84163. 0x90, 0x97, 0x9E, 0x99, 0x8C, 0x8B, 0x82, 0x85,
  84164. 0xA8, 0xAF, 0xA6, 0xA1, 0xB4, 0xB3, 0xBA, 0xBD,
  84165. 0xC7, 0xC0, 0xC9, 0xCE, 0xDB, 0xDC, 0xD5, 0xD2,
  84166. 0xFF, 0xF8, 0xF1, 0xF6, 0xE3, 0xE4, 0xED, 0xEA,
  84167. 0xB7, 0xB0, 0xB9, 0xBE, 0xAB, 0xAC, 0xA5, 0xA2,
  84168. 0x8F, 0x88, 0x81, 0x86, 0x93, 0x94, 0x9D, 0x9A,
  84169. 0x27, 0x20, 0x29, 0x2E, 0x3B, 0x3C, 0x35, 0x32,
  84170. 0x1F, 0x18, 0x11, 0x16, 0x03, 0x04, 0x0D, 0x0A,
  84171. 0x57, 0x50, 0x59, 0x5E, 0x4B, 0x4C, 0x45, 0x42,
  84172. 0x6F, 0x68, 0x61, 0x66, 0x73, 0x74, 0x7D, 0x7A,
  84173. 0x89, 0x8E, 0x87, 0x80, 0x95, 0x92, 0x9B, 0x9C,
  84174. 0xB1, 0xB6, 0xBF, 0xB8, 0xAD, 0xAA, 0xA3, 0xA4,
  84175. 0xF9, 0xFE, 0xF7, 0xF0, 0xE5, 0xE2, 0xEB, 0xEC,
  84176. 0xC1, 0xC6, 0xCF, 0xC8, 0xDD, 0xDA, 0xD3, 0xD4,
  84177. 0x69, 0x6E, 0x67, 0x60, 0x75, 0x72, 0x7B, 0x7C,
  84178. 0x51, 0x56, 0x5F, 0x58, 0x4D, 0x4A, 0x43, 0x44,
  84179. 0x19, 0x1E, 0x17, 0x10, 0x05, 0x02, 0x0B, 0x0C,
  84180. 0x21, 0x26, 0x2F, 0x28, 0x3D, 0x3A, 0x33, 0x34,
  84181. 0x4E, 0x49, 0x40, 0x47, 0x52, 0x55, 0x5C, 0x5B,
  84182. 0x76, 0x71, 0x78, 0x7F, 0x6A, 0x6D, 0x64, 0x63,
  84183. 0x3E, 0x39, 0x30, 0x37, 0x22, 0x25, 0x2C, 0x2B,
  84184. 0x06, 0x01, 0x08, 0x0F, 0x1A, 0x1D, 0x14, 0x13,
  84185. 0xAE, 0xA9, 0xA0, 0xA7, 0xB2, 0xB5, 0xBC, 0xBB,
  84186. 0x96, 0x91, 0x98, 0x9F, 0x8A, 0x8D, 0x84, 0x83,
  84187. 0xDE, 0xD9, 0xD0, 0xD7, 0xC2, 0xC5, 0xCC, 0xCB,
  84188. 0xE6, 0xE1, 0xE8, 0xEF, 0xFA, 0xFD, 0xF4, 0xF3
  84189. };
  84190. unsigned FLAC__crc16_table[256] = {
  84191. 0x0000, 0x8005, 0x800f, 0x000a, 0x801b, 0x001e, 0x0014, 0x8011,
  84192. 0x8033, 0x0036, 0x003c, 0x8039, 0x0028, 0x802d, 0x8027, 0x0022,
  84193. 0x8063, 0x0066, 0x006c, 0x8069, 0x0078, 0x807d, 0x8077, 0x0072,
  84194. 0x0050, 0x8055, 0x805f, 0x005a, 0x804b, 0x004e, 0x0044, 0x8041,
  84195. 0x80c3, 0x00c6, 0x00cc, 0x80c9, 0x00d8, 0x80dd, 0x80d7, 0x00d2,
  84196. 0x00f0, 0x80f5, 0x80ff, 0x00fa, 0x80eb, 0x00ee, 0x00e4, 0x80e1,
  84197. 0x00a0, 0x80a5, 0x80af, 0x00aa, 0x80bb, 0x00be, 0x00b4, 0x80b1,
  84198. 0x8093, 0x0096, 0x009c, 0x8099, 0x0088, 0x808d, 0x8087, 0x0082,
  84199. 0x8183, 0x0186, 0x018c, 0x8189, 0x0198, 0x819d, 0x8197, 0x0192,
  84200. 0x01b0, 0x81b5, 0x81bf, 0x01ba, 0x81ab, 0x01ae, 0x01a4, 0x81a1,
  84201. 0x01e0, 0x81e5, 0x81ef, 0x01ea, 0x81fb, 0x01fe, 0x01f4, 0x81f1,
  84202. 0x81d3, 0x01d6, 0x01dc, 0x81d9, 0x01c8, 0x81cd, 0x81c7, 0x01c2,
  84203. 0x0140, 0x8145, 0x814f, 0x014a, 0x815b, 0x015e, 0x0154, 0x8151,
  84204. 0x8173, 0x0176, 0x017c, 0x8179, 0x0168, 0x816d, 0x8167, 0x0162,
  84205. 0x8123, 0x0126, 0x012c, 0x8129, 0x0138, 0x813d, 0x8137, 0x0132,
  84206. 0x0110, 0x8115, 0x811f, 0x011a, 0x810b, 0x010e, 0x0104, 0x8101,
  84207. 0x8303, 0x0306, 0x030c, 0x8309, 0x0318, 0x831d, 0x8317, 0x0312,
  84208. 0x0330, 0x8335, 0x833f, 0x033a, 0x832b, 0x032e, 0x0324, 0x8321,
  84209. 0x0360, 0x8365, 0x836f, 0x036a, 0x837b, 0x037e, 0x0374, 0x8371,
  84210. 0x8353, 0x0356, 0x035c, 0x8359, 0x0348, 0x834d, 0x8347, 0x0342,
  84211. 0x03c0, 0x83c5, 0x83cf, 0x03ca, 0x83db, 0x03de, 0x03d4, 0x83d1,
  84212. 0x83f3, 0x03f6, 0x03fc, 0x83f9, 0x03e8, 0x83ed, 0x83e7, 0x03e2,
  84213. 0x83a3, 0x03a6, 0x03ac, 0x83a9, 0x03b8, 0x83bd, 0x83b7, 0x03b2,
  84214. 0x0390, 0x8395, 0x839f, 0x039a, 0x838b, 0x038e, 0x0384, 0x8381,
  84215. 0x0280, 0x8285, 0x828f, 0x028a, 0x829b, 0x029e, 0x0294, 0x8291,
  84216. 0x82b3, 0x02b6, 0x02bc, 0x82b9, 0x02a8, 0x82ad, 0x82a7, 0x02a2,
  84217. 0x82e3, 0x02e6, 0x02ec, 0x82e9, 0x02f8, 0x82fd, 0x82f7, 0x02f2,
  84218. 0x02d0, 0x82d5, 0x82df, 0x02da, 0x82cb, 0x02ce, 0x02c4, 0x82c1,
  84219. 0x8243, 0x0246, 0x024c, 0x8249, 0x0258, 0x825d, 0x8257, 0x0252,
  84220. 0x0270, 0x8275, 0x827f, 0x027a, 0x826b, 0x026e, 0x0264, 0x8261,
  84221. 0x0220, 0x8225, 0x822f, 0x022a, 0x823b, 0x023e, 0x0234, 0x8231,
  84222. 0x8213, 0x0216, 0x021c, 0x8219, 0x0208, 0x820d, 0x8207, 0x0202
  84223. };
  84224. void FLAC__crc8_update(const FLAC__byte data, FLAC__uint8 *crc)
  84225. {
  84226. *crc = FLAC__crc8_table[*crc ^ data];
  84227. }
  84228. void FLAC__crc8_update_block(const FLAC__byte *data, unsigned len, FLAC__uint8 *crc)
  84229. {
  84230. while(len--)
  84231. *crc = FLAC__crc8_table[*crc ^ *data++];
  84232. }
  84233. FLAC__uint8 FLAC__crc8(const FLAC__byte *data, unsigned len)
  84234. {
  84235. FLAC__uint8 crc = 0;
  84236. while(len--)
  84237. crc = FLAC__crc8_table[crc ^ *data++];
  84238. return crc;
  84239. }
  84240. unsigned FLAC__crc16(const FLAC__byte *data, unsigned len)
  84241. {
  84242. unsigned crc = 0;
  84243. while(len--)
  84244. crc = ((crc<<8) ^ FLAC__crc16_table[(crc>>8) ^ *data++]) & 0xffff;
  84245. return crc;
  84246. }
  84247. #endif
  84248. /*** End of inlined file: crc.c ***/
  84249. /*** Start of inlined file: fixed.c ***/
  84250. /*** Start of inlined file: juce_FlacHeader.h ***/
  84251. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84252. // tasks..
  84253. #define VERSION "1.2.1"
  84254. #define FLAC__NO_DLL 1
  84255. #if JUCE_MSVC
  84256. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84257. #endif
  84258. #if JUCE_MAC
  84259. #define FLAC__SYS_DARWIN 1
  84260. #endif
  84261. /*** End of inlined file: juce_FlacHeader.h ***/
  84262. #if JUCE_USE_FLAC
  84263. #if HAVE_CONFIG_H
  84264. # include <config.h>
  84265. #endif
  84266. #include <math.h>
  84267. #include <string.h>
  84268. /*** Start of inlined file: fixed.h ***/
  84269. #ifndef FLAC__PRIVATE__FIXED_H
  84270. #define FLAC__PRIVATE__FIXED_H
  84271. #ifdef HAVE_CONFIG_H
  84272. #include <config.h>
  84273. #endif
  84274. /*** Start of inlined file: float.h ***/
  84275. #ifndef FLAC__PRIVATE__FLOAT_H
  84276. #define FLAC__PRIVATE__FLOAT_H
  84277. #ifdef HAVE_CONFIG_H
  84278. #include <config.h>
  84279. #endif
  84280. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84281. typedef double FLAC__double;
  84282. typedef float FLAC__float;
  84283. typedef float FLAC__real;
  84284. #else
  84285. typedef FLAC__int32 FLAC__fixedpoint;
  84286. extern const FLAC__fixedpoint FLAC__FP_ZERO;
  84287. extern const FLAC__fixedpoint FLAC__FP_ONE_HALF;
  84288. extern const FLAC__fixedpoint FLAC__FP_ONE;
  84289. extern const FLAC__fixedpoint FLAC__FP_LN2;
  84290. extern const FLAC__fixedpoint FLAC__FP_E;
  84291. #define FLAC__fixedpoint_trunc(x) ((x)>>16)
  84292. #define FLAC__fixedpoint_mul(x, y) ( (FLAC__fixedpoint) ( ((FLAC__int64)(x)*(FLAC__int64)(y)) >> 16 ) )
  84293. #define FLAC__fixedpoint_div(x, y) ( (FLAC__fixedpoint) ( ( ((FLAC__int64)(x)<<32) / (FLAC__int64)(y) ) >> 16 ) )
  84294. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision);
  84295. #endif
  84296. #endif
  84297. /*** End of inlined file: float.h ***/
  84298. /*** Start of inlined file: format.h ***/
  84299. #ifndef FLAC__PRIVATE__FORMAT_H
  84300. #define FLAC__PRIVATE__FORMAT_H
  84301. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order);
  84302. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize);
  84303. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order);
  84304. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84305. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object);
  84306. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order);
  84307. #endif
  84308. /*** End of inlined file: format.h ***/
  84309. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84310. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84311. # ifndef FLAC__NO_ASM
  84312. # ifdef FLAC__CPU_IA32
  84313. # ifdef FLAC__HAS_NASM
  84314. 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]);
  84315. # endif
  84316. # endif
  84317. # endif
  84318. 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]);
  84319. #else
  84320. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  84321. 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]);
  84322. #endif
  84323. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[]);
  84324. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[]);
  84325. #endif
  84326. /*** End of inlined file: fixed.h ***/
  84327. #ifndef M_LN2
  84328. #define M_LN2 0.69314718055994530942
  84329. #endif
  84330. #ifdef min
  84331. #undef min
  84332. #endif
  84333. #define min(x,y) ((x) < (y)? (x) : (y))
  84334. #ifdef local_abs
  84335. #undef local_abs
  84336. #endif
  84337. #define local_abs(x) ((unsigned)((x)<0? -(x) : (x)))
  84338. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84339. static FLAC__fixedpoint local__compute_rbps_integerized(FLAC__uint32 err, FLAC__uint32 n)
  84340. {
  84341. FLAC__uint32 rbps;
  84342. unsigned bits; /* the number of bits required to represent a number */
  84343. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84344. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84345. FLAC__ASSERT(err > 0);
  84346. FLAC__ASSERT(n > 0);
  84347. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84348. if(err <= n)
  84349. return 0;
  84350. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2(err)+1);
  84351. err <<= fracbits;
  84352. err /= n;
  84353. FLAC__ASSERT(err > 0);
  84354. bits = FLAC__bitmath_ilog2(err)+1;
  84355. if(bits > 16) {
  84356. err >>= (bits-16);
  84357. fracbits -= (bits-16);
  84358. }
  84359. rbps = (FLAC__uint32)err;
  84360. rbps *= FLAC__FP_LN2;
  84361. fracbits += 16;
  84362. FLAC__ASSERT(fracbits >= 0);
  84363. {
  84364. const int f = fracbits & 3;
  84365. if(f) {
  84366. rbps >>= f;
  84367. fracbits -= f;
  84368. }
  84369. }
  84370. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84371. if(rbps == 0)
  84372. return 0;
  84373. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84374. FLAC__ASSERT(fracbits >= -3);
  84375. if(fracbits < 16)
  84376. return rbps << (16-fracbits);
  84377. else if(fracbits > 16)
  84378. return rbps >> (fracbits-16);
  84379. else
  84380. return rbps;
  84381. }
  84382. static FLAC__fixedpoint local__compute_rbps_wide_integerized(FLAC__uint64 err, FLAC__uint32 n)
  84383. {
  84384. FLAC__uint32 rbps;
  84385. unsigned bits; /* the number of bits required to represent a number */
  84386. int fracbits; /* the number of bits of rbps that comprise the fractional part */
  84387. FLAC__ASSERT(sizeof(rbps) == sizeof(FLAC__fixedpoint));
  84388. FLAC__ASSERT(err > 0);
  84389. FLAC__ASSERT(n > 0);
  84390. FLAC__ASSERT(n <= FLAC__MAX_BLOCK_SIZE);
  84391. if(err <= n)
  84392. return 0;
  84393. fracbits = (8*sizeof(err)) - (FLAC__bitmath_ilog2_wide(err)+1);
  84394. err <<= fracbits;
  84395. err /= n;
  84396. FLAC__ASSERT(err > 0);
  84397. bits = FLAC__bitmath_ilog2_wide(err)+1;
  84398. if(bits > 16) {
  84399. err >>= (bits-16);
  84400. fracbits -= (bits-16);
  84401. }
  84402. rbps = (FLAC__uint32)err;
  84403. rbps *= FLAC__FP_LN2;
  84404. fracbits += 16;
  84405. FLAC__ASSERT(fracbits >= 0);
  84406. {
  84407. const int f = fracbits & 3;
  84408. if(f) {
  84409. rbps >>= f;
  84410. fracbits -= f;
  84411. }
  84412. }
  84413. rbps = FLAC__fixedpoint_log2(rbps, fracbits, (unsigned)(-1));
  84414. if(rbps == 0)
  84415. return 0;
  84416. FLAC__ASSERT((int)FLAC__bitmath_ilog2(rbps)+1 <= fracbits + 6);
  84417. FLAC__ASSERT(fracbits >= -3);
  84418. if(fracbits < 16)
  84419. return rbps << (16-fracbits);
  84420. else if(fracbits > 16)
  84421. return rbps >> (fracbits-16);
  84422. else
  84423. return rbps;
  84424. }
  84425. #endif
  84426. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84427. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84428. #else
  84429. unsigned FLAC__fixed_compute_best_predictor(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1])
  84430. #endif
  84431. {
  84432. FLAC__int32 last_error_0 = data[-1];
  84433. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84434. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84435. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84436. FLAC__int32 error, save;
  84437. FLAC__uint32 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84438. unsigned i, order;
  84439. for(i = 0; i < data_len; i++) {
  84440. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84441. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84442. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84443. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84444. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84445. }
  84446. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84447. order = 0;
  84448. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84449. order = 1;
  84450. else if(total_error_2 < min(total_error_3, total_error_4))
  84451. order = 2;
  84452. else if(total_error_3 < total_error_4)
  84453. order = 3;
  84454. else
  84455. order = 4;
  84456. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84457. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84458. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84459. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84460. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84461. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84462. 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);
  84463. 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);
  84464. 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);
  84465. 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);
  84466. 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);
  84467. #else
  84468. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_integerized(total_error_0, data_len) : 0;
  84469. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_integerized(total_error_1, data_len) : 0;
  84470. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_integerized(total_error_2, data_len) : 0;
  84471. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_integerized(total_error_3, data_len) : 0;
  84472. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_integerized(total_error_4, data_len) : 0;
  84473. #endif
  84474. return order;
  84475. }
  84476. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84477. 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])
  84478. #else
  84479. 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])
  84480. #endif
  84481. {
  84482. FLAC__int32 last_error_0 = data[-1];
  84483. FLAC__int32 last_error_1 = data[-1] - data[-2];
  84484. FLAC__int32 last_error_2 = last_error_1 - (data[-2] - data[-3]);
  84485. FLAC__int32 last_error_3 = last_error_2 - (data[-2] - 2*data[-3] + data[-4]);
  84486. FLAC__int32 error, save;
  84487. FLAC__uint64 total_error_0 = 0, total_error_1 = 0, total_error_2 = 0, total_error_3 = 0, total_error_4 = 0;
  84488. unsigned i, order;
  84489. for(i = 0; i < data_len; i++) {
  84490. error = data[i] ; total_error_0 += local_abs(error); save = error;
  84491. error -= last_error_0; total_error_1 += local_abs(error); last_error_0 = save; save = error;
  84492. error -= last_error_1; total_error_2 += local_abs(error); last_error_1 = save; save = error;
  84493. error -= last_error_2; total_error_3 += local_abs(error); last_error_2 = save; save = error;
  84494. error -= last_error_3; total_error_4 += local_abs(error); last_error_3 = save;
  84495. }
  84496. if(total_error_0 < min(min(min(total_error_1, total_error_2), total_error_3), total_error_4))
  84497. order = 0;
  84498. else if(total_error_1 < min(min(total_error_2, total_error_3), total_error_4))
  84499. order = 1;
  84500. else if(total_error_2 < min(total_error_3, total_error_4))
  84501. order = 2;
  84502. else if(total_error_3 < total_error_4)
  84503. order = 3;
  84504. else
  84505. order = 4;
  84506. FLAC__ASSERT(data_len > 0 || total_error_0 == 0);
  84507. FLAC__ASSERT(data_len > 0 || total_error_1 == 0);
  84508. FLAC__ASSERT(data_len > 0 || total_error_2 == 0);
  84509. FLAC__ASSERT(data_len > 0 || total_error_3 == 0);
  84510. FLAC__ASSERT(data_len > 0 || total_error_4 == 0);
  84511. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  84512. #if defined _MSC_VER || defined __MINGW32__
  84513. 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);
  84514. 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);
  84515. 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);
  84516. 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);
  84517. 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);
  84518. #else
  84519. 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);
  84520. 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);
  84521. 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);
  84522. 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);
  84523. 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);
  84524. #endif
  84525. #else
  84526. residual_bits_per_sample[0] = (total_error_0 > 0) ? local__compute_rbps_wide_integerized(total_error_0, data_len) : 0;
  84527. residual_bits_per_sample[1] = (total_error_1 > 0) ? local__compute_rbps_wide_integerized(total_error_1, data_len) : 0;
  84528. residual_bits_per_sample[2] = (total_error_2 > 0) ? local__compute_rbps_wide_integerized(total_error_2, data_len) : 0;
  84529. residual_bits_per_sample[3] = (total_error_3 > 0) ? local__compute_rbps_wide_integerized(total_error_3, data_len) : 0;
  84530. residual_bits_per_sample[4] = (total_error_4 > 0) ? local__compute_rbps_wide_integerized(total_error_4, data_len) : 0;
  84531. #endif
  84532. return order;
  84533. }
  84534. void FLAC__fixed_compute_residual(const FLAC__int32 data[], unsigned data_len, unsigned order, FLAC__int32 residual[])
  84535. {
  84536. const int idata_len = (int)data_len;
  84537. int i;
  84538. switch(order) {
  84539. case 0:
  84540. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84541. memcpy(residual, data, sizeof(residual[0])*data_len);
  84542. break;
  84543. case 1:
  84544. for(i = 0; i < idata_len; i++)
  84545. residual[i] = data[i] - data[i-1];
  84546. break;
  84547. case 2:
  84548. for(i = 0; i < idata_len; i++)
  84549. #if 1 /* OPT: may be faster with some compilers on some systems */
  84550. residual[i] = data[i] - (data[i-1] << 1) + data[i-2];
  84551. #else
  84552. residual[i] = data[i] - 2*data[i-1] + data[i-2];
  84553. #endif
  84554. break;
  84555. case 3:
  84556. for(i = 0; i < idata_len; i++)
  84557. #if 1 /* OPT: may be faster with some compilers on some systems */
  84558. residual[i] = data[i] - (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) - data[i-3];
  84559. #else
  84560. residual[i] = data[i] - 3*data[i-1] + 3*data[i-2] - data[i-3];
  84561. #endif
  84562. break;
  84563. case 4:
  84564. for(i = 0; i < idata_len; i++)
  84565. #if 1 /* OPT: may be faster with some compilers on some systems */
  84566. residual[i] = data[i] - ((data[i-1]+data[i-3])<<2) + ((data[i-2]<<2) + (data[i-2]<<1)) + data[i-4];
  84567. #else
  84568. residual[i] = data[i] - 4*data[i-1] + 6*data[i-2] - 4*data[i-3] + data[i-4];
  84569. #endif
  84570. break;
  84571. default:
  84572. FLAC__ASSERT(0);
  84573. }
  84574. }
  84575. void FLAC__fixed_restore_signal(const FLAC__int32 residual[], unsigned data_len, unsigned order, FLAC__int32 data[])
  84576. {
  84577. int i, idata_len = (int)data_len;
  84578. switch(order) {
  84579. case 0:
  84580. FLAC__ASSERT(sizeof(residual[0]) == sizeof(data[0]));
  84581. memcpy(data, residual, sizeof(residual[0])*data_len);
  84582. break;
  84583. case 1:
  84584. for(i = 0; i < idata_len; i++)
  84585. data[i] = residual[i] + data[i-1];
  84586. break;
  84587. case 2:
  84588. for(i = 0; i < idata_len; i++)
  84589. #if 1 /* OPT: may be faster with some compilers on some systems */
  84590. data[i] = residual[i] + (data[i-1]<<1) - data[i-2];
  84591. #else
  84592. data[i] = residual[i] + 2*data[i-1] - data[i-2];
  84593. #endif
  84594. break;
  84595. case 3:
  84596. for(i = 0; i < idata_len; i++)
  84597. #if 1 /* OPT: may be faster with some compilers on some systems */
  84598. data[i] = residual[i] + (((data[i-1]-data[i-2])<<1) + (data[i-1]-data[i-2])) + data[i-3];
  84599. #else
  84600. data[i] = residual[i] + 3*data[i-1] - 3*data[i-2] + data[i-3];
  84601. #endif
  84602. break;
  84603. case 4:
  84604. for(i = 0; i < idata_len; i++)
  84605. #if 1 /* OPT: may be faster with some compilers on some systems */
  84606. data[i] = residual[i] + ((data[i-1]+data[i-3])<<2) - ((data[i-2]<<2) + (data[i-2]<<1)) - data[i-4];
  84607. #else
  84608. data[i] = residual[i] + 4*data[i-1] - 6*data[i-2] + 4*data[i-3] - data[i-4];
  84609. #endif
  84610. break;
  84611. default:
  84612. FLAC__ASSERT(0);
  84613. }
  84614. }
  84615. #endif
  84616. /*** End of inlined file: fixed.c ***/
  84617. /*** Start of inlined file: float.c ***/
  84618. /*** Start of inlined file: juce_FlacHeader.h ***/
  84619. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84620. // tasks..
  84621. #define VERSION "1.2.1"
  84622. #define FLAC__NO_DLL 1
  84623. #if JUCE_MSVC
  84624. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84625. #endif
  84626. #if JUCE_MAC
  84627. #define FLAC__SYS_DARWIN 1
  84628. #endif
  84629. /*** End of inlined file: juce_FlacHeader.h ***/
  84630. #if JUCE_USE_FLAC
  84631. #if HAVE_CONFIG_H
  84632. # include <config.h>
  84633. #endif
  84634. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  84635. #ifdef _MSC_VER
  84636. #define FLAC__U64L(x) x
  84637. #else
  84638. #define FLAC__U64L(x) x##LLU
  84639. #endif
  84640. const FLAC__fixedpoint FLAC__FP_ZERO = 0;
  84641. const FLAC__fixedpoint FLAC__FP_ONE_HALF = 0x00008000;
  84642. const FLAC__fixedpoint FLAC__FP_ONE = 0x00010000;
  84643. const FLAC__fixedpoint FLAC__FP_LN2 = 45426;
  84644. const FLAC__fixedpoint FLAC__FP_E = 178145;
  84645. #define LOG2_LOOKUP_PRECISION 16
  84646. static const FLAC__uint32 log2_lookup[][LOG2_LOOKUP_PRECISION] = {
  84647. {
  84648. 0x00000000,
  84649. 0x00000001,
  84650. 0x00000000,
  84651. 0x00000000,
  84652. 0x00000000,
  84653. 0x00000000,
  84654. 0x00000000,
  84655. 0x00000000,
  84656. 0x00000000,
  84657. 0x00000000,
  84658. 0x00000000,
  84659. 0x00000000,
  84660. 0x00000000,
  84661. 0x00000000,
  84662. 0x00000000,
  84663. 0x00000000
  84664. },
  84665. {
  84666. 0x00000000,
  84667. 0x00000010,
  84668. 0x00000007,
  84669. 0x00000003,
  84670. 0x00000001,
  84671. 0x00000001,
  84672. 0x00000000,
  84673. 0x00000000,
  84674. 0x00000000,
  84675. 0x00000000,
  84676. 0x00000000,
  84677. 0x00000000,
  84678. 0x00000000,
  84679. 0x00000000,
  84680. 0x00000000,
  84681. 0x00000000
  84682. },
  84683. {
  84684. 0x00000000,
  84685. 0x00000100,
  84686. 0x0000006a,
  84687. 0x00000031,
  84688. 0x00000018,
  84689. 0x0000000c,
  84690. 0x00000006,
  84691. 0x00000003,
  84692. 0x00000001,
  84693. 0x00000001,
  84694. 0x00000000,
  84695. 0x00000000,
  84696. 0x00000000,
  84697. 0x00000000,
  84698. 0x00000000,
  84699. 0x00000000
  84700. },
  84701. {
  84702. 0x00000000,
  84703. 0x00001000,
  84704. 0x000006a4,
  84705. 0x00000315,
  84706. 0x0000017d,
  84707. 0x000000bc,
  84708. 0x0000005d,
  84709. 0x0000002e,
  84710. 0x00000017,
  84711. 0x0000000c,
  84712. 0x00000006,
  84713. 0x00000003,
  84714. 0x00000001,
  84715. 0x00000001,
  84716. 0x00000000,
  84717. 0x00000000
  84718. },
  84719. {
  84720. 0x00000000,
  84721. 0x00010000,
  84722. 0x00006a40,
  84723. 0x00003151,
  84724. 0x000017d6,
  84725. 0x00000bba,
  84726. 0x000005d1,
  84727. 0x000002e6,
  84728. 0x00000172,
  84729. 0x000000b9,
  84730. 0x0000005c,
  84731. 0x0000002e,
  84732. 0x00000017,
  84733. 0x0000000c,
  84734. 0x00000006,
  84735. 0x00000003
  84736. },
  84737. {
  84738. 0x00000000,
  84739. 0x00100000,
  84740. 0x0006a3fe,
  84741. 0x00031513,
  84742. 0x00017d60,
  84743. 0x0000bb9d,
  84744. 0x00005d10,
  84745. 0x00002e59,
  84746. 0x00001721,
  84747. 0x00000b8e,
  84748. 0x000005c6,
  84749. 0x000002e3,
  84750. 0x00000171,
  84751. 0x000000b9,
  84752. 0x0000005c,
  84753. 0x0000002e
  84754. },
  84755. {
  84756. 0x00000000,
  84757. 0x01000000,
  84758. 0x006a3fe6,
  84759. 0x00315130,
  84760. 0x0017d605,
  84761. 0x000bb9ca,
  84762. 0x0005d0fc,
  84763. 0x0002e58f,
  84764. 0x0001720e,
  84765. 0x0000b8d8,
  84766. 0x00005c61,
  84767. 0x00002e2d,
  84768. 0x00001716,
  84769. 0x00000b8b,
  84770. 0x000005c5,
  84771. 0x000002e3
  84772. },
  84773. {
  84774. 0x00000000,
  84775. 0x10000000,
  84776. 0x06a3fe5c,
  84777. 0x03151301,
  84778. 0x017d6049,
  84779. 0x00bb9ca6,
  84780. 0x005d0fba,
  84781. 0x002e58f7,
  84782. 0x001720da,
  84783. 0x000b8d87,
  84784. 0x0005c60b,
  84785. 0x0002e2d7,
  84786. 0x00017160,
  84787. 0x0000b8ad,
  84788. 0x00005c56,
  84789. 0x00002e2b
  84790. }
  84791. };
  84792. #if 0
  84793. static const FLAC__uint64 log2_lookup_wide[] = {
  84794. {
  84795. 0x00000000,
  84796. FLAC__U64L(0x100000000),
  84797. FLAC__U64L(0x6a3fe5c6),
  84798. FLAC__U64L(0x31513015),
  84799. FLAC__U64L(0x17d60497),
  84800. FLAC__U64L(0x0bb9ca65),
  84801. FLAC__U64L(0x05d0fba2),
  84802. FLAC__U64L(0x02e58f74),
  84803. FLAC__U64L(0x01720d9c),
  84804. FLAC__U64L(0x00b8d875),
  84805. FLAC__U64L(0x005c60aa),
  84806. FLAC__U64L(0x002e2d72),
  84807. FLAC__U64L(0x00171600),
  84808. FLAC__U64L(0x000b8ad2),
  84809. FLAC__U64L(0x0005c55d),
  84810. FLAC__U64L(0x0002e2ac)
  84811. },
  84812. {
  84813. 0x00000000,
  84814. FLAC__U64L(0x1000000000000),
  84815. FLAC__U64L(0x6a3fe5c60429),
  84816. FLAC__U64L(0x315130157f7a),
  84817. FLAC__U64L(0x17d60496cfbb),
  84818. FLAC__U64L(0xbb9ca64ecac),
  84819. FLAC__U64L(0x5d0fba187cd),
  84820. FLAC__U64L(0x2e58f7441ee),
  84821. FLAC__U64L(0x1720d9c06a8),
  84822. FLAC__U64L(0xb8d8752173),
  84823. FLAC__U64L(0x5c60aa252e),
  84824. FLAC__U64L(0x2e2d71b0d8),
  84825. FLAC__U64L(0x1716001719),
  84826. FLAC__U64L(0xb8ad1de1b),
  84827. FLAC__U64L(0x5c55d640d),
  84828. FLAC__U64L(0x2e2abcf52)
  84829. }
  84830. };
  84831. #endif
  84832. FLAC__uint32 FLAC__fixedpoint_log2(FLAC__uint32 x, unsigned fracbits, unsigned precision)
  84833. {
  84834. const FLAC__uint32 ONE = (1u << fracbits);
  84835. const FLAC__uint32 *table = log2_lookup[fracbits >> 2];
  84836. FLAC__ASSERT(fracbits < 32);
  84837. FLAC__ASSERT((fracbits & 0x3) == 0);
  84838. if(x < ONE)
  84839. return 0;
  84840. if(precision > LOG2_LOOKUP_PRECISION)
  84841. precision = LOG2_LOOKUP_PRECISION;
  84842. {
  84843. FLAC__uint32 y = 0;
  84844. FLAC__uint32 z = x >> 1, k = 1;
  84845. while (x > ONE && k < precision) {
  84846. if (x - z >= ONE) {
  84847. x -= z;
  84848. z = x >> k;
  84849. y += table[k];
  84850. }
  84851. else {
  84852. z >>= 1;
  84853. k++;
  84854. }
  84855. }
  84856. return y;
  84857. }
  84858. }
  84859. #endif /* defined FLAC__INTEGER_ONLY_LIBRARY */
  84860. #endif
  84861. /*** End of inlined file: float.c ***/
  84862. /*** Start of inlined file: format.c ***/
  84863. /*** Start of inlined file: juce_FlacHeader.h ***/
  84864. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  84865. // tasks..
  84866. #define VERSION "1.2.1"
  84867. #define FLAC__NO_DLL 1
  84868. #if JUCE_MSVC
  84869. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  84870. #endif
  84871. #if JUCE_MAC
  84872. #define FLAC__SYS_DARWIN 1
  84873. #endif
  84874. /*** End of inlined file: juce_FlacHeader.h ***/
  84875. #if JUCE_USE_FLAC
  84876. #if HAVE_CONFIG_H
  84877. # include <config.h>
  84878. #endif
  84879. #include <stdio.h>
  84880. #include <stdlib.h> /* for qsort() */
  84881. #include <string.h> /* for memset() */
  84882. #ifndef FLaC__INLINE
  84883. #define FLaC__INLINE
  84884. #endif
  84885. #ifdef min
  84886. #undef min
  84887. #endif
  84888. #define min(a,b) ((a)<(b)?(a):(b))
  84889. #ifdef _MSC_VER
  84890. #define FLAC__U64L(x) x
  84891. #else
  84892. #define FLAC__U64L(x) x##LLU
  84893. #endif
  84894. FLAC_API const char *FLAC__VERSION_STRING = VERSION
  84895. ;
  84896. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINW32__
  84897. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC 1.2.1 20070917";
  84898. #else
  84899. FLAC_API const char *FLAC__VENDOR_STRING = "reference libFLAC " VERSION " 20070917";
  84900. #endif
  84901. FLAC_API const FLAC__byte FLAC__STREAM_SYNC_STRING[4] = { 'f','L','a','C' };
  84902. FLAC_API const unsigned FLAC__STREAM_SYNC = 0x664C6143;
  84903. FLAC_API const unsigned FLAC__STREAM_SYNC_LEN = 32; /* bits */
  84904. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN = 16; /* bits */
  84905. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN = 16; /* bits */
  84906. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN = 24; /* bits */
  84907. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN = 24; /* bits */
  84908. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN = 20; /* bits */
  84909. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN = 3; /* bits */
  84910. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN = 5; /* bits */
  84911. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN = 36; /* bits */
  84912. FLAC_API const unsigned FLAC__STREAM_METADATA_STREAMINFO_MD5SUM_LEN = 128; /* bits */
  84913. FLAC_API const unsigned FLAC__STREAM_METADATA_APPLICATION_ID_LEN = 32; /* bits */
  84914. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN = 64; /* bits */
  84915. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN = 64; /* bits */
  84916. FLAC_API const unsigned FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN = 16; /* bits */
  84917. FLAC_API const FLAC__uint64 FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER = FLAC__U64L(0xffffffffffffffff);
  84918. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN = 32; /* bits */
  84919. FLAC_API const unsigned FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN = 32; /* bits */
  84920. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN = 64; /* bits */
  84921. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN = 8; /* bits */
  84922. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN = 3*8; /* bits */
  84923. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN = 64; /* bits */
  84924. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN = 8; /* bits */
  84925. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN = 12*8; /* bits */
  84926. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN = 1; /* bit */
  84927. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN = 1; /* bit */
  84928. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN = 6+13*8; /* bits */
  84929. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN = 8; /* bits */
  84930. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN = 128*8; /* bits */
  84931. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN = 64; /* bits */
  84932. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN = 1; /* bit */
  84933. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN = 7+258*8; /* bits */
  84934. FLAC_API const unsigned FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN = 8; /* bits */
  84935. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_TYPE_LEN = 32; /* bits */
  84936. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN = 32; /* bits */
  84937. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN = 32; /* bits */
  84938. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN = 32; /* bits */
  84939. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN = 32; /* bits */
  84940. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN = 32; /* bits */
  84941. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_COLORS_LEN = 32; /* bits */
  84942. FLAC_API const unsigned FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN = 32; /* bits */
  84943. FLAC_API const unsigned FLAC__STREAM_METADATA_IS_LAST_LEN = 1; /* bits */
  84944. FLAC_API const unsigned FLAC__STREAM_METADATA_TYPE_LEN = 7; /* bits */
  84945. FLAC_API const unsigned FLAC__STREAM_METADATA_LENGTH_LEN = 24; /* bits */
  84946. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC = 0x3ffe;
  84947. FLAC_API const unsigned FLAC__FRAME_HEADER_SYNC_LEN = 14; /* bits */
  84948. FLAC_API const unsigned FLAC__FRAME_HEADER_RESERVED_LEN = 1; /* bits */
  84949. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN = 1; /* bits */
  84950. FLAC_API const unsigned FLAC__FRAME_HEADER_BLOCK_SIZE_LEN = 4; /* bits */
  84951. FLAC_API const unsigned FLAC__FRAME_HEADER_SAMPLE_RATE_LEN = 4; /* bits */
  84952. FLAC_API const unsigned FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN = 4; /* bits */
  84953. FLAC_API const unsigned FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN = 3; /* bits */
  84954. FLAC_API const unsigned FLAC__FRAME_HEADER_ZERO_PAD_LEN = 1; /* bits */
  84955. FLAC_API const unsigned FLAC__FRAME_HEADER_CRC_LEN = 8; /* bits */
  84956. FLAC_API const unsigned FLAC__FRAME_FOOTER_CRC_LEN = 16; /* bits */
  84957. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_TYPE_LEN = 2; /* bits */
  84958. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN = 4; /* bits */
  84959. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN = 4; /* bits */
  84960. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN = 5; /* bits */
  84961. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN = 5; /* bits */
  84962. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER = 15; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN)-1 */
  84963. FLAC_API const unsigned FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER = 31; /* == (1<<FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN)-1 */
  84964. FLAC_API const char * const FLAC__EntropyCodingMethodTypeString[] = {
  84965. "PARTITIONED_RICE",
  84966. "PARTITIONED_RICE2"
  84967. };
  84968. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN = 4; /* bits */
  84969. FLAC_API const unsigned FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN = 5; /* bits */
  84970. FLAC_API const unsigned FLAC__SUBFRAME_ZERO_PAD_LEN = 1; /* bits */
  84971. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LEN = 6; /* bits */
  84972. FLAC_API const unsigned FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN = 1; /* bits */
  84973. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_CONSTANT_BYTE_ALIGNED_MASK = 0x00;
  84974. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_VERBATIM_BYTE_ALIGNED_MASK = 0x02;
  84975. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_FIXED_BYTE_ALIGNED_MASK = 0x10;
  84976. FLAC_API const unsigned FLAC__SUBFRAME_TYPE_LPC_BYTE_ALIGNED_MASK = 0x40;
  84977. FLAC_API const char * const FLAC__SubframeTypeString[] = {
  84978. "CONSTANT",
  84979. "VERBATIM",
  84980. "FIXED",
  84981. "LPC"
  84982. };
  84983. FLAC_API const char * const FLAC__ChannelAssignmentString[] = {
  84984. "INDEPENDENT",
  84985. "LEFT_SIDE",
  84986. "RIGHT_SIDE",
  84987. "MID_SIDE"
  84988. };
  84989. FLAC_API const char * const FLAC__FrameNumberTypeString[] = {
  84990. "FRAME_NUMBER_TYPE_FRAME_NUMBER",
  84991. "FRAME_NUMBER_TYPE_SAMPLE_NUMBER"
  84992. };
  84993. FLAC_API const char * const FLAC__MetadataTypeString[] = {
  84994. "STREAMINFO",
  84995. "PADDING",
  84996. "APPLICATION",
  84997. "SEEKTABLE",
  84998. "VORBIS_COMMENT",
  84999. "CUESHEET",
  85000. "PICTURE"
  85001. };
  85002. FLAC_API const char * const FLAC__StreamMetadata_Picture_TypeString[] = {
  85003. "Other",
  85004. "32x32 pixels 'file icon' (PNG only)",
  85005. "Other file icon",
  85006. "Cover (front)",
  85007. "Cover (back)",
  85008. "Leaflet page",
  85009. "Media (e.g. label side of CD)",
  85010. "Lead artist/lead performer/soloist",
  85011. "Artist/performer",
  85012. "Conductor",
  85013. "Band/Orchestra",
  85014. "Composer",
  85015. "Lyricist/text writer",
  85016. "Recording Location",
  85017. "During recording",
  85018. "During performance",
  85019. "Movie/video screen capture",
  85020. "A bright coloured fish",
  85021. "Illustration",
  85022. "Band/artist logotype",
  85023. "Publisher/Studio logotype"
  85024. };
  85025. FLAC_API FLAC__bool FLAC__format_sample_rate_is_valid(unsigned sample_rate)
  85026. {
  85027. if(sample_rate == 0 || sample_rate > FLAC__MAX_SAMPLE_RATE) {
  85028. return false;
  85029. }
  85030. else
  85031. return true;
  85032. }
  85033. FLAC_API FLAC__bool FLAC__format_sample_rate_is_subset(unsigned sample_rate)
  85034. {
  85035. if(
  85036. !FLAC__format_sample_rate_is_valid(sample_rate) ||
  85037. (
  85038. sample_rate >= (1u << 16) &&
  85039. !(sample_rate % 1000 == 0 || sample_rate % 10 == 0)
  85040. )
  85041. ) {
  85042. return false;
  85043. }
  85044. else
  85045. return true;
  85046. }
  85047. FLAC_API FLAC__bool FLAC__format_seektable_is_legal(const FLAC__StreamMetadata_SeekTable *seek_table)
  85048. {
  85049. unsigned i;
  85050. FLAC__uint64 prev_sample_number = 0;
  85051. FLAC__bool got_prev = false;
  85052. FLAC__ASSERT(0 != seek_table);
  85053. for(i = 0; i < seek_table->num_points; i++) {
  85054. if(got_prev) {
  85055. if(
  85056. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  85057. seek_table->points[i].sample_number <= prev_sample_number
  85058. )
  85059. return false;
  85060. }
  85061. prev_sample_number = seek_table->points[i].sample_number;
  85062. got_prev = true;
  85063. }
  85064. return true;
  85065. }
  85066. static int seekpoint_compare_(const FLAC__StreamMetadata_SeekPoint *l, const FLAC__StreamMetadata_SeekPoint *r)
  85067. {
  85068. if(l->sample_number == r->sample_number)
  85069. return 0;
  85070. else if(l->sample_number < r->sample_number)
  85071. return -1;
  85072. else
  85073. return 1;
  85074. }
  85075. FLAC_API unsigned FLAC__format_seektable_sort(FLAC__StreamMetadata_SeekTable *seek_table)
  85076. {
  85077. unsigned i, j;
  85078. FLAC__bool first;
  85079. FLAC__ASSERT(0 != seek_table);
  85080. qsort(seek_table->points, seek_table->num_points, sizeof(FLAC__StreamMetadata_SeekPoint), (int (*)(const void *, const void *))seekpoint_compare_);
  85081. first = true;
  85082. for(i = j = 0; i < seek_table->num_points; i++) {
  85083. if(seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER) {
  85084. if(!first) {
  85085. if(seek_table->points[i].sample_number == seek_table->points[j-1].sample_number)
  85086. continue;
  85087. }
  85088. }
  85089. first = false;
  85090. seek_table->points[j++] = seek_table->points[i];
  85091. }
  85092. for(i = j; i < seek_table->num_points; i++) {
  85093. seek_table->points[i].sample_number = FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER;
  85094. seek_table->points[i].stream_offset = 0;
  85095. seek_table->points[i].frame_samples = 0;
  85096. }
  85097. return j;
  85098. }
  85099. static FLaC__INLINE unsigned utf8len_(const FLAC__byte *utf8)
  85100. {
  85101. FLAC__ASSERT(0 != utf8);
  85102. if ((utf8[0] & 0x80) == 0) {
  85103. return 1;
  85104. }
  85105. else if ((utf8[0] & 0xE0) == 0xC0 && (utf8[1] & 0xC0) == 0x80) {
  85106. if ((utf8[0] & 0xFE) == 0xC0) /* overlong sequence check */
  85107. return 0;
  85108. return 2;
  85109. }
  85110. else if ((utf8[0] & 0xF0) == 0xE0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80) {
  85111. if (utf8[0] == 0xE0 && (utf8[1] & 0xE0) == 0x80) /* overlong sequence check */
  85112. return 0;
  85113. if (utf8[0] == 0xED && (utf8[1] & 0xE0) == 0xA0) /* D800-DFFF */
  85114. return 0;
  85115. if (utf8[0] == 0xEF && utf8[1] == 0xBF && (utf8[2] & 0xFE) == 0xBE) /* FFFE-FFFF */
  85116. return 0;
  85117. return 3;
  85118. }
  85119. else if ((utf8[0] & 0xF8) == 0xF0 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80) {
  85120. if (utf8[0] == 0xF0 && (utf8[1] & 0xF0) == 0x80) /* overlong sequence check */
  85121. return 0;
  85122. return 4;
  85123. }
  85124. else if ((utf8[0] & 0xFC) == 0xF8 && (utf8[1] & 0xC0) == 0x80 && (utf8[2] & 0xC0) == 0x80 && (utf8[3] & 0xC0) == 0x80 && (utf8[4] & 0xC0) == 0x80) {
  85125. if (utf8[0] == 0xF8 && (utf8[1] & 0xF8) == 0x80) /* overlong sequence check */
  85126. return 0;
  85127. return 5;
  85128. }
  85129. 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) {
  85130. if (utf8[0] == 0xFC && (utf8[1] & 0xFC) == 0x80) /* overlong sequence check */
  85131. return 0;
  85132. return 6;
  85133. }
  85134. else {
  85135. return 0;
  85136. }
  85137. }
  85138. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_name_is_legal(const char *name)
  85139. {
  85140. char c;
  85141. for(c = *name; c; c = *(++name))
  85142. if(c < 0x20 || c == 0x3d || c > 0x7d)
  85143. return false;
  85144. return true;
  85145. }
  85146. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_value_is_legal(const FLAC__byte *value, unsigned length)
  85147. {
  85148. if(length == (unsigned)(-1)) {
  85149. while(*value) {
  85150. unsigned n = utf8len_(value);
  85151. if(n == 0)
  85152. return false;
  85153. value += n;
  85154. }
  85155. }
  85156. else {
  85157. const FLAC__byte *end = value + length;
  85158. while(value < end) {
  85159. unsigned n = utf8len_(value);
  85160. if(n == 0)
  85161. return false;
  85162. value += n;
  85163. }
  85164. if(value != end)
  85165. return false;
  85166. }
  85167. return true;
  85168. }
  85169. FLAC_API FLAC__bool FLAC__format_vorbiscomment_entry_is_legal(const FLAC__byte *entry, unsigned length)
  85170. {
  85171. const FLAC__byte *s, *end;
  85172. for(s = entry, end = s + length; s < end && *s != '='; s++) {
  85173. if(*s < 0x20 || *s > 0x7D)
  85174. return false;
  85175. }
  85176. if(s == end)
  85177. return false;
  85178. s++; /* skip '=' */
  85179. while(s < end) {
  85180. unsigned n = utf8len_(s);
  85181. if(n == 0)
  85182. return false;
  85183. s += n;
  85184. }
  85185. if(s != end)
  85186. return false;
  85187. return true;
  85188. }
  85189. FLAC_API FLAC__bool FLAC__format_cuesheet_is_legal(const FLAC__StreamMetadata_CueSheet *cue_sheet, FLAC__bool check_cd_da_subset, const char **violation)
  85190. {
  85191. unsigned i, j;
  85192. if(check_cd_da_subset) {
  85193. if(cue_sheet->lead_in < 2 * 44100) {
  85194. if(violation) *violation = "CD-DA cue sheet must have a lead-in length of at least 2 seconds";
  85195. return false;
  85196. }
  85197. if(cue_sheet->lead_in % 588 != 0) {
  85198. if(violation) *violation = "CD-DA cue sheet lead-in length must be evenly divisible by 588 samples";
  85199. return false;
  85200. }
  85201. }
  85202. if(cue_sheet->num_tracks == 0) {
  85203. if(violation) *violation = "cue sheet must have at least one track (the lead-out)";
  85204. return false;
  85205. }
  85206. if(check_cd_da_subset && cue_sheet->tracks[cue_sheet->num_tracks-1].number != 170) {
  85207. if(violation) *violation = "CD-DA cue sheet must have a lead-out track number 170 (0xAA)";
  85208. return false;
  85209. }
  85210. for(i = 0; i < cue_sheet->num_tracks; i++) {
  85211. if(cue_sheet->tracks[i].number == 0) {
  85212. if(violation) *violation = "cue sheet may not have a track number 0";
  85213. return false;
  85214. }
  85215. if(check_cd_da_subset) {
  85216. if(!((cue_sheet->tracks[i].number >= 1 && cue_sheet->tracks[i].number <= 99) || cue_sheet->tracks[i].number == 170)) {
  85217. if(violation) *violation = "CD-DA cue sheet track number must be 1-99 or 170";
  85218. return false;
  85219. }
  85220. }
  85221. if(check_cd_da_subset && cue_sheet->tracks[i].offset % 588 != 0) {
  85222. if(violation) {
  85223. if(i == cue_sheet->num_tracks-1) /* the lead-out track... */
  85224. *violation = "CD-DA cue sheet lead-out offset must be evenly divisible by 588 samples";
  85225. else
  85226. *violation = "CD-DA cue sheet track offset must be evenly divisible by 588 samples";
  85227. }
  85228. return false;
  85229. }
  85230. if(i < cue_sheet->num_tracks - 1) {
  85231. if(cue_sheet->tracks[i].num_indices == 0) {
  85232. if(violation) *violation = "cue sheet track must have at least one index point";
  85233. return false;
  85234. }
  85235. if(cue_sheet->tracks[i].indices[0].number > 1) {
  85236. if(violation) *violation = "cue sheet track's first index number must be 0 or 1";
  85237. return false;
  85238. }
  85239. }
  85240. for(j = 0; j < cue_sheet->tracks[i].num_indices; j++) {
  85241. if(check_cd_da_subset && cue_sheet->tracks[i].indices[j].offset % 588 != 0) {
  85242. if(violation) *violation = "CD-DA cue sheet track index offset must be evenly divisible by 588 samples";
  85243. return false;
  85244. }
  85245. if(j > 0) {
  85246. if(cue_sheet->tracks[i].indices[j].number != cue_sheet->tracks[i].indices[j-1].number + 1) {
  85247. if(violation) *violation = "cue sheet track index numbers must increase by 1";
  85248. return false;
  85249. }
  85250. }
  85251. }
  85252. }
  85253. return true;
  85254. }
  85255. FLAC_API FLAC__bool FLAC__format_picture_is_legal(const FLAC__StreamMetadata_Picture *picture, const char **violation)
  85256. {
  85257. char *p;
  85258. FLAC__byte *b;
  85259. for(p = picture->mime_type; *p; p++) {
  85260. if(*p < 0x20 || *p > 0x7e) {
  85261. if(violation) *violation = "MIME type string must contain only printable ASCII characters (0x20-0x7e)";
  85262. return false;
  85263. }
  85264. }
  85265. for(b = picture->description; *b; ) {
  85266. unsigned n = utf8len_(b);
  85267. if(n == 0) {
  85268. if(violation) *violation = "description string must be valid UTF-8";
  85269. return false;
  85270. }
  85271. b += n;
  85272. }
  85273. return true;
  85274. }
  85275. unsigned FLAC__format_get_max_rice_partition_order(unsigned blocksize, unsigned predictor_order)
  85276. {
  85277. return
  85278. FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(
  85279. FLAC__format_get_max_rice_partition_order_from_blocksize(blocksize),
  85280. blocksize,
  85281. predictor_order
  85282. );
  85283. }
  85284. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize(unsigned blocksize)
  85285. {
  85286. unsigned max_rice_partition_order = 0;
  85287. while(!(blocksize & 1)) {
  85288. max_rice_partition_order++;
  85289. blocksize >>= 1;
  85290. }
  85291. return min(FLAC__MAX_RICE_PARTITION_ORDER, max_rice_partition_order);
  85292. }
  85293. unsigned FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(unsigned limit, unsigned blocksize, unsigned predictor_order)
  85294. {
  85295. unsigned max_rice_partition_order = limit;
  85296. while(max_rice_partition_order > 0 && (blocksize >> max_rice_partition_order) <= predictor_order)
  85297. max_rice_partition_order--;
  85298. FLAC__ASSERT(
  85299. (max_rice_partition_order == 0 && blocksize >= predictor_order) ||
  85300. (max_rice_partition_order > 0 && blocksize >> max_rice_partition_order > predictor_order)
  85301. );
  85302. return max_rice_partition_order;
  85303. }
  85304. void FLAC__format_entropy_coding_method_partitioned_rice_contents_init(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85305. {
  85306. FLAC__ASSERT(0 != object);
  85307. object->parameters = 0;
  85308. object->raw_bits = 0;
  85309. object->capacity_by_order = 0;
  85310. }
  85311. void FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(FLAC__EntropyCodingMethod_PartitionedRiceContents *object)
  85312. {
  85313. FLAC__ASSERT(0 != object);
  85314. if(0 != object->parameters)
  85315. free(object->parameters);
  85316. if(0 != object->raw_bits)
  85317. free(object->raw_bits);
  85318. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(object);
  85319. }
  85320. FLAC__bool FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(FLAC__EntropyCodingMethod_PartitionedRiceContents *object, unsigned max_partition_order)
  85321. {
  85322. FLAC__ASSERT(0 != object);
  85323. FLAC__ASSERT(object->capacity_by_order > 0 || (0 == object->parameters && 0 == object->raw_bits));
  85324. if(object->capacity_by_order < max_partition_order) {
  85325. if(0 == (object->parameters = (unsigned*)realloc(object->parameters, sizeof(unsigned)*(1 << max_partition_order))))
  85326. return false;
  85327. if(0 == (object->raw_bits = (unsigned*)realloc(object->raw_bits, sizeof(unsigned)*(1 << max_partition_order))))
  85328. return false;
  85329. memset(object->raw_bits, 0, sizeof(unsigned)*(1 << max_partition_order));
  85330. object->capacity_by_order = max_partition_order;
  85331. }
  85332. return true;
  85333. }
  85334. #endif
  85335. /*** End of inlined file: format.c ***/
  85336. /*** Start of inlined file: lpc_flac.c ***/
  85337. /*** Start of inlined file: juce_FlacHeader.h ***/
  85338. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  85339. // tasks..
  85340. #define VERSION "1.2.1"
  85341. #define FLAC__NO_DLL 1
  85342. #if JUCE_MSVC
  85343. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  85344. #endif
  85345. #if JUCE_MAC
  85346. #define FLAC__SYS_DARWIN 1
  85347. #endif
  85348. /*** End of inlined file: juce_FlacHeader.h ***/
  85349. #if JUCE_USE_FLAC
  85350. #if HAVE_CONFIG_H
  85351. # include <config.h>
  85352. #endif
  85353. #include <math.h>
  85354. /*** Start of inlined file: lpc.h ***/
  85355. #ifndef FLAC__PRIVATE__LPC_H
  85356. #define FLAC__PRIVATE__LPC_H
  85357. #ifdef HAVE_CONFIG_H
  85358. #include <config.h>
  85359. #endif
  85360. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85361. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len);
  85362. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85363. #ifndef FLAC__NO_ASM
  85364. # ifdef FLAC__CPU_IA32
  85365. # ifdef FLAC__HAS_NASM
  85366. void FLAC__lpc_compute_autocorrelation_asm_ia32(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85367. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85368. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85369. void FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85370. void FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  85371. # endif
  85372. # endif
  85373. #endif
  85374. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[]);
  85375. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift);
  85376. 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[]);
  85377. 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[]);
  85378. #ifndef FLAC__NO_ASM
  85379. # ifdef FLAC__CPU_IA32
  85380. # ifdef FLAC__HAS_NASM
  85381. 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[]);
  85382. 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[]);
  85383. # endif
  85384. # endif
  85385. #endif
  85386. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85387. 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[]);
  85388. 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[]);
  85389. #ifndef FLAC__NO_ASM
  85390. # ifdef FLAC__CPU_IA32
  85391. # ifdef FLAC__HAS_NASM
  85392. 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[]);
  85393. 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[]);
  85394. # endif /* FLAC__HAS_NASM */
  85395. # elif defined FLAC__CPU_PPC
  85396. 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[]);
  85397. 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[]);
  85398. # endif/* FLAC__CPU_IA32 || FLAC__CPU_PPC */
  85399. #endif /* FLAC__NO_ASM */
  85400. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85401. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples);
  85402. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale);
  85403. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order);
  85404. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  85405. #endif
  85406. /*** End of inlined file: lpc.h ***/
  85407. #if defined DEBUG || defined FLAC__OVERFLOW_DETECT || defined FLAC__OVERFLOW_DETECT_VERBOSE
  85408. #include <stdio.h>
  85409. #endif
  85410. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  85411. #ifndef M_LN2
  85412. #define M_LN2 0.69314718055994530942
  85413. #endif
  85414. #define FLAC__LPC_UNROLLED_FILTER_LOOPS
  85415. void FLAC__lpc_window_data(const FLAC__int32 in[], const FLAC__real window[], FLAC__real out[], unsigned data_len)
  85416. {
  85417. unsigned i;
  85418. for(i = 0; i < data_len; i++)
  85419. out[i] = in[i] * window[i];
  85420. }
  85421. void FLAC__lpc_compute_autocorrelation(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[])
  85422. {
  85423. #if 0
  85424. FLAC__real d;
  85425. unsigned i;
  85426. FLAC__ASSERT(lag > 0);
  85427. FLAC__ASSERT(lag <= data_len);
  85428. while(lag--) {
  85429. for(i = lag, d = 0.0; i < data_len; i++)
  85430. d += data[i] * data[i - lag];
  85431. autoc[lag] = d;
  85432. }
  85433. #endif
  85434. FLAC__real d;
  85435. unsigned sample, coeff;
  85436. const unsigned limit = data_len - lag;
  85437. FLAC__ASSERT(lag > 0);
  85438. FLAC__ASSERT(lag <= data_len);
  85439. for(coeff = 0; coeff < lag; coeff++)
  85440. autoc[coeff] = 0.0;
  85441. for(sample = 0; sample <= limit; sample++) {
  85442. d = data[sample];
  85443. for(coeff = 0; coeff < lag; coeff++)
  85444. autoc[coeff] += d * data[sample+coeff];
  85445. }
  85446. for(; sample < data_len; sample++) {
  85447. d = data[sample];
  85448. for(coeff = 0; coeff < data_len - sample; coeff++)
  85449. autoc[coeff] += d * data[sample+coeff];
  85450. }
  85451. }
  85452. void FLAC__lpc_compute_lp_coefficients(const FLAC__real autoc[], unsigned *max_order, FLAC__real lp_coeff[][FLAC__MAX_LPC_ORDER], FLAC__double error[])
  85453. {
  85454. unsigned i, j;
  85455. FLAC__double r, err, ref[FLAC__MAX_LPC_ORDER], lpc[FLAC__MAX_LPC_ORDER];
  85456. FLAC__ASSERT(0 != max_order);
  85457. FLAC__ASSERT(0 < *max_order);
  85458. FLAC__ASSERT(*max_order <= FLAC__MAX_LPC_ORDER);
  85459. FLAC__ASSERT(autoc[0] != 0.0);
  85460. err = autoc[0];
  85461. for(i = 0; i < *max_order; i++) {
  85462. r = -autoc[i+1];
  85463. for(j = 0; j < i; j++)
  85464. r -= lpc[j] * autoc[i-j];
  85465. ref[i] = (r/=err);
  85466. lpc[i]=r;
  85467. for(j = 0; j < (i>>1); j++) {
  85468. FLAC__double tmp = lpc[j];
  85469. lpc[j] += r * lpc[i-1-j];
  85470. lpc[i-1-j] += r * tmp;
  85471. }
  85472. if(i & 1)
  85473. lpc[j] += lpc[j] * r;
  85474. err *= (1.0 - r * r);
  85475. for(j = 0; j <= i; j++)
  85476. lp_coeff[i][j] = (FLAC__real)(-lpc[j]); /* negate FIR filter coeff to get predictor coeff */
  85477. error[i] = err;
  85478. if(err == 0.0) {
  85479. *max_order = i+1;
  85480. return;
  85481. }
  85482. }
  85483. }
  85484. int FLAC__lpc_quantize_coefficients(const FLAC__real lp_coeff[], unsigned order, unsigned precision, FLAC__int32 qlp_coeff[], int *shift)
  85485. {
  85486. unsigned i;
  85487. FLAC__double cmax;
  85488. FLAC__int32 qmax, qmin;
  85489. FLAC__ASSERT(precision > 0);
  85490. FLAC__ASSERT(precision >= FLAC__MIN_QLP_COEFF_PRECISION);
  85491. precision--;
  85492. qmax = 1 << precision;
  85493. qmin = -qmax;
  85494. qmax--;
  85495. cmax = 0.0;
  85496. for(i = 0; i < order; i++) {
  85497. const FLAC__double d = fabs(lp_coeff[i]);
  85498. if(d > cmax)
  85499. cmax = d;
  85500. }
  85501. if(cmax <= 0.0) {
  85502. return 2;
  85503. }
  85504. else {
  85505. const int max_shiftlimit = (1 << (FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN-1)) - 1;
  85506. const int min_shiftlimit = -max_shiftlimit - 1;
  85507. int log2cmax;
  85508. (void)frexp(cmax, &log2cmax);
  85509. log2cmax--;
  85510. *shift = (int)precision - log2cmax - 1;
  85511. if(*shift > max_shiftlimit)
  85512. *shift = max_shiftlimit;
  85513. else if(*shift < min_shiftlimit)
  85514. return 1;
  85515. }
  85516. if(*shift >= 0) {
  85517. FLAC__double error = 0.0;
  85518. FLAC__int32 q;
  85519. for(i = 0; i < order; i++) {
  85520. error += lp_coeff[i] * (1 << *shift);
  85521. #if 1 /* unfortunately lround() is C99 */
  85522. if(error >= 0.0)
  85523. q = (FLAC__int32)(error + 0.5);
  85524. else
  85525. q = (FLAC__int32)(error - 0.5);
  85526. #else
  85527. q = lround(error);
  85528. #endif
  85529. #ifdef FLAC__OVERFLOW_DETECT
  85530. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85531. 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]);
  85532. else if(q < qmin)
  85533. 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]);
  85534. #endif
  85535. if(q > qmax)
  85536. q = qmax;
  85537. else if(q < qmin)
  85538. q = qmin;
  85539. error -= q;
  85540. qlp_coeff[i] = q;
  85541. }
  85542. }
  85543. else {
  85544. const int nshift = -(*shift);
  85545. FLAC__double error = 0.0;
  85546. FLAC__int32 q;
  85547. #ifdef DEBUG
  85548. fprintf(stderr,"FLAC__lpc_quantize_coefficients: negative shift=%d order=%u cmax=%f\n", *shift, order, cmax);
  85549. #endif
  85550. for(i = 0; i < order; i++) {
  85551. error += lp_coeff[i] / (1 << nshift);
  85552. #if 1 /* unfortunately lround() is C99 */
  85553. if(error >= 0.0)
  85554. q = (FLAC__int32)(error + 0.5);
  85555. else
  85556. q = (FLAC__int32)(error - 0.5);
  85557. #else
  85558. q = lround(error);
  85559. #endif
  85560. #ifdef FLAC__OVERFLOW_DETECT
  85561. if(q > qmax+1) /* we expect q==qmax+1 occasionally due to rounding */
  85562. 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]);
  85563. else if(q < qmin)
  85564. 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]);
  85565. #endif
  85566. if(q > qmax)
  85567. q = qmax;
  85568. else if(q < qmin)
  85569. q = qmin;
  85570. error -= q;
  85571. qlp_coeff[i] = q;
  85572. }
  85573. *shift = 0;
  85574. }
  85575. return 0;
  85576. }
  85577. 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[])
  85578. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85579. {
  85580. FLAC__int64 sumo;
  85581. unsigned i, j;
  85582. FLAC__int32 sum;
  85583. const FLAC__int32 *history;
  85584. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85585. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85586. for(i=0;i<order;i++)
  85587. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85588. fprintf(stderr,"\n");
  85589. #endif
  85590. FLAC__ASSERT(order > 0);
  85591. for(i = 0; i < data_len; i++) {
  85592. sumo = 0;
  85593. sum = 0;
  85594. history = data;
  85595. for(j = 0; j < order; j++) {
  85596. sum += qlp_coeff[j] * (*(--history));
  85597. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  85598. #if defined _MSC_VER
  85599. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  85600. 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);
  85601. #else
  85602. if(sumo > 2147483647ll || sumo < -2147483648ll)
  85603. 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);
  85604. #endif
  85605. }
  85606. *(residual++) = *(data++) - (sum >> lp_quantization);
  85607. }
  85608. }
  85609. #else /* fully unrolled version for normal use */
  85610. {
  85611. int i;
  85612. FLAC__int32 sum;
  85613. FLAC__ASSERT(order > 0);
  85614. FLAC__ASSERT(order <= 32);
  85615. if(order <= 12) {
  85616. if(order > 8) {
  85617. if(order > 10) {
  85618. if(order == 12) {
  85619. for(i = 0; i < (int)data_len; i++) {
  85620. sum = 0;
  85621. sum += qlp_coeff[11] * data[i-12];
  85622. sum += qlp_coeff[10] * data[i-11];
  85623. sum += qlp_coeff[9] * data[i-10];
  85624. sum += qlp_coeff[8] * data[i-9];
  85625. sum += qlp_coeff[7] * data[i-8];
  85626. sum += qlp_coeff[6] * data[i-7];
  85627. sum += qlp_coeff[5] * data[i-6];
  85628. sum += qlp_coeff[4] * data[i-5];
  85629. sum += qlp_coeff[3] * data[i-4];
  85630. sum += qlp_coeff[2] * data[i-3];
  85631. sum += qlp_coeff[1] * data[i-2];
  85632. sum += qlp_coeff[0] * data[i-1];
  85633. residual[i] = data[i] - (sum >> lp_quantization);
  85634. }
  85635. }
  85636. else { /* order == 11 */
  85637. for(i = 0; i < (int)data_len; i++) {
  85638. sum = 0;
  85639. sum += qlp_coeff[10] * data[i-11];
  85640. sum += qlp_coeff[9] * data[i-10];
  85641. sum += qlp_coeff[8] * data[i-9];
  85642. sum += qlp_coeff[7] * data[i-8];
  85643. sum += qlp_coeff[6] * data[i-7];
  85644. sum += qlp_coeff[5] * data[i-6];
  85645. sum += qlp_coeff[4] * data[i-5];
  85646. sum += qlp_coeff[3] * data[i-4];
  85647. sum += qlp_coeff[2] * data[i-3];
  85648. sum += qlp_coeff[1] * data[i-2];
  85649. sum += qlp_coeff[0] * data[i-1];
  85650. residual[i] = data[i] - (sum >> lp_quantization);
  85651. }
  85652. }
  85653. }
  85654. else {
  85655. if(order == 10) {
  85656. for(i = 0; i < (int)data_len; i++) {
  85657. sum = 0;
  85658. sum += qlp_coeff[9] * data[i-10];
  85659. sum += qlp_coeff[8] * data[i-9];
  85660. sum += qlp_coeff[7] * data[i-8];
  85661. sum += qlp_coeff[6] * data[i-7];
  85662. sum += qlp_coeff[5] * data[i-6];
  85663. sum += qlp_coeff[4] * data[i-5];
  85664. sum += qlp_coeff[3] * data[i-4];
  85665. sum += qlp_coeff[2] * data[i-3];
  85666. sum += qlp_coeff[1] * data[i-2];
  85667. sum += qlp_coeff[0] * data[i-1];
  85668. residual[i] = data[i] - (sum >> lp_quantization);
  85669. }
  85670. }
  85671. else { /* order == 9 */
  85672. for(i = 0; i < (int)data_len; i++) {
  85673. sum = 0;
  85674. sum += qlp_coeff[8] * data[i-9];
  85675. sum += qlp_coeff[7] * data[i-8];
  85676. sum += qlp_coeff[6] * data[i-7];
  85677. sum += qlp_coeff[5] * data[i-6];
  85678. sum += qlp_coeff[4] * data[i-5];
  85679. sum += qlp_coeff[3] * data[i-4];
  85680. sum += qlp_coeff[2] * data[i-3];
  85681. sum += qlp_coeff[1] * data[i-2];
  85682. sum += qlp_coeff[0] * data[i-1];
  85683. residual[i] = data[i] - (sum >> lp_quantization);
  85684. }
  85685. }
  85686. }
  85687. }
  85688. else if(order > 4) {
  85689. if(order > 6) {
  85690. if(order == 8) {
  85691. for(i = 0; i < (int)data_len; i++) {
  85692. sum = 0;
  85693. sum += qlp_coeff[7] * data[i-8];
  85694. sum += qlp_coeff[6] * data[i-7];
  85695. sum += qlp_coeff[5] * data[i-6];
  85696. sum += qlp_coeff[4] * data[i-5];
  85697. sum += qlp_coeff[3] * data[i-4];
  85698. sum += qlp_coeff[2] * data[i-3];
  85699. sum += qlp_coeff[1] * data[i-2];
  85700. sum += qlp_coeff[0] * data[i-1];
  85701. residual[i] = data[i] - (sum >> lp_quantization);
  85702. }
  85703. }
  85704. else { /* order == 7 */
  85705. for(i = 0; i < (int)data_len; i++) {
  85706. sum = 0;
  85707. sum += qlp_coeff[6] * data[i-7];
  85708. sum += qlp_coeff[5] * data[i-6];
  85709. sum += qlp_coeff[4] * data[i-5];
  85710. sum += qlp_coeff[3] * data[i-4];
  85711. sum += qlp_coeff[2] * data[i-3];
  85712. sum += qlp_coeff[1] * data[i-2];
  85713. sum += qlp_coeff[0] * data[i-1];
  85714. residual[i] = data[i] - (sum >> lp_quantization);
  85715. }
  85716. }
  85717. }
  85718. else {
  85719. if(order == 6) {
  85720. for(i = 0; i < (int)data_len; i++) {
  85721. sum = 0;
  85722. sum += qlp_coeff[5] * data[i-6];
  85723. sum += qlp_coeff[4] * data[i-5];
  85724. sum += qlp_coeff[3] * data[i-4];
  85725. sum += qlp_coeff[2] * data[i-3];
  85726. sum += qlp_coeff[1] * data[i-2];
  85727. sum += qlp_coeff[0] * data[i-1];
  85728. residual[i] = data[i] - (sum >> lp_quantization);
  85729. }
  85730. }
  85731. else { /* order == 5 */
  85732. for(i = 0; i < (int)data_len; i++) {
  85733. sum = 0;
  85734. sum += qlp_coeff[4] * data[i-5];
  85735. sum += qlp_coeff[3] * data[i-4];
  85736. sum += qlp_coeff[2] * data[i-3];
  85737. sum += qlp_coeff[1] * data[i-2];
  85738. sum += qlp_coeff[0] * data[i-1];
  85739. residual[i] = data[i] - (sum >> lp_quantization);
  85740. }
  85741. }
  85742. }
  85743. }
  85744. else {
  85745. if(order > 2) {
  85746. if(order == 4) {
  85747. for(i = 0; i < (int)data_len; i++) {
  85748. sum = 0;
  85749. sum += qlp_coeff[3] * data[i-4];
  85750. sum += qlp_coeff[2] * data[i-3];
  85751. sum += qlp_coeff[1] * data[i-2];
  85752. sum += qlp_coeff[0] * data[i-1];
  85753. residual[i] = data[i] - (sum >> lp_quantization);
  85754. }
  85755. }
  85756. else { /* order == 3 */
  85757. for(i = 0; i < (int)data_len; i++) {
  85758. sum = 0;
  85759. sum += qlp_coeff[2] * data[i-3];
  85760. sum += qlp_coeff[1] * data[i-2];
  85761. sum += qlp_coeff[0] * data[i-1];
  85762. residual[i] = data[i] - (sum >> lp_quantization);
  85763. }
  85764. }
  85765. }
  85766. else {
  85767. if(order == 2) {
  85768. for(i = 0; i < (int)data_len; i++) {
  85769. sum = 0;
  85770. sum += qlp_coeff[1] * data[i-2];
  85771. sum += qlp_coeff[0] * data[i-1];
  85772. residual[i] = data[i] - (sum >> lp_quantization);
  85773. }
  85774. }
  85775. else { /* order == 1 */
  85776. for(i = 0; i < (int)data_len; i++)
  85777. residual[i] = data[i] - ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  85778. }
  85779. }
  85780. }
  85781. }
  85782. else { /* order > 12 */
  85783. for(i = 0; i < (int)data_len; i++) {
  85784. sum = 0;
  85785. switch(order) {
  85786. case 32: sum += qlp_coeff[31] * data[i-32];
  85787. case 31: sum += qlp_coeff[30] * data[i-31];
  85788. case 30: sum += qlp_coeff[29] * data[i-30];
  85789. case 29: sum += qlp_coeff[28] * data[i-29];
  85790. case 28: sum += qlp_coeff[27] * data[i-28];
  85791. case 27: sum += qlp_coeff[26] * data[i-27];
  85792. case 26: sum += qlp_coeff[25] * data[i-26];
  85793. case 25: sum += qlp_coeff[24] * data[i-25];
  85794. case 24: sum += qlp_coeff[23] * data[i-24];
  85795. case 23: sum += qlp_coeff[22] * data[i-23];
  85796. case 22: sum += qlp_coeff[21] * data[i-22];
  85797. case 21: sum += qlp_coeff[20] * data[i-21];
  85798. case 20: sum += qlp_coeff[19] * data[i-20];
  85799. case 19: sum += qlp_coeff[18] * data[i-19];
  85800. case 18: sum += qlp_coeff[17] * data[i-18];
  85801. case 17: sum += qlp_coeff[16] * data[i-17];
  85802. case 16: sum += qlp_coeff[15] * data[i-16];
  85803. case 15: sum += qlp_coeff[14] * data[i-15];
  85804. case 14: sum += qlp_coeff[13] * data[i-14];
  85805. case 13: sum += qlp_coeff[12] * data[i-13];
  85806. sum += qlp_coeff[11] * data[i-12];
  85807. sum += qlp_coeff[10] * data[i-11];
  85808. sum += qlp_coeff[ 9] * data[i-10];
  85809. sum += qlp_coeff[ 8] * data[i- 9];
  85810. sum += qlp_coeff[ 7] * data[i- 8];
  85811. sum += qlp_coeff[ 6] * data[i- 7];
  85812. sum += qlp_coeff[ 5] * data[i- 6];
  85813. sum += qlp_coeff[ 4] * data[i- 5];
  85814. sum += qlp_coeff[ 3] * data[i- 4];
  85815. sum += qlp_coeff[ 2] * data[i- 3];
  85816. sum += qlp_coeff[ 1] * data[i- 2];
  85817. sum += qlp_coeff[ 0] * data[i- 1];
  85818. }
  85819. residual[i] = data[i] - (sum >> lp_quantization);
  85820. }
  85821. }
  85822. }
  85823. #endif
  85824. 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[])
  85825. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  85826. {
  85827. unsigned i, j;
  85828. FLAC__int64 sum;
  85829. const FLAC__int32 *history;
  85830. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  85831. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  85832. for(i=0;i<order;i++)
  85833. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  85834. fprintf(stderr,"\n");
  85835. #endif
  85836. FLAC__ASSERT(order > 0);
  85837. for(i = 0; i < data_len; i++) {
  85838. sum = 0;
  85839. history = data;
  85840. for(j = 0; j < order; j++)
  85841. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  85842. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  85843. #if defined _MSC_VER
  85844. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  85845. #else
  85846. fprintf(stderr,"FLAC__lpc_compute_residual_from_qlp_coefficients_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  85847. #endif
  85848. break;
  85849. }
  85850. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*data) - (sum >> lp_quantization)) > 32) {
  85851. #if defined _MSC_VER
  85852. 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));
  85853. #else
  85854. 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)));
  85855. #endif
  85856. break;
  85857. }
  85858. *(residual++) = *(data++) - (FLAC__int32)(sum >> lp_quantization);
  85859. }
  85860. }
  85861. #else /* fully unrolled version for normal use */
  85862. {
  85863. int i;
  85864. FLAC__int64 sum;
  85865. FLAC__ASSERT(order > 0);
  85866. FLAC__ASSERT(order <= 32);
  85867. if(order <= 12) {
  85868. if(order > 8) {
  85869. if(order > 10) {
  85870. if(order == 12) {
  85871. for(i = 0; i < (int)data_len; i++) {
  85872. sum = 0;
  85873. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  85874. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85875. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85876. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85877. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85878. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85879. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85880. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85881. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85882. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85883. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85884. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85885. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85886. }
  85887. }
  85888. else { /* order == 11 */
  85889. for(i = 0; i < (int)data_len; i++) {
  85890. sum = 0;
  85891. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  85892. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85893. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85894. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85895. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85896. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85897. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85898. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85899. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85900. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85901. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85902. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85903. }
  85904. }
  85905. }
  85906. else {
  85907. if(order == 10) {
  85908. for(i = 0; i < (int)data_len; i++) {
  85909. sum = 0;
  85910. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  85911. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85912. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85913. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85914. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85915. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85916. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85917. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85918. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85919. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85920. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85921. }
  85922. }
  85923. else { /* order == 9 */
  85924. for(i = 0; i < (int)data_len; i++) {
  85925. sum = 0;
  85926. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  85927. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85928. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85929. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85930. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85931. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85932. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85933. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85934. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85935. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85936. }
  85937. }
  85938. }
  85939. }
  85940. else if(order > 4) {
  85941. if(order > 6) {
  85942. if(order == 8) {
  85943. for(i = 0; i < (int)data_len; i++) {
  85944. sum = 0;
  85945. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  85946. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85947. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85948. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85949. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85950. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85951. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85952. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85953. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85954. }
  85955. }
  85956. else { /* order == 7 */
  85957. for(i = 0; i < (int)data_len; i++) {
  85958. sum = 0;
  85959. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  85960. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85961. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85962. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85963. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85964. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85965. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85966. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85967. }
  85968. }
  85969. }
  85970. else {
  85971. if(order == 6) {
  85972. for(i = 0; i < (int)data_len; i++) {
  85973. sum = 0;
  85974. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  85975. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85976. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85977. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85978. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85979. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85980. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85981. }
  85982. }
  85983. else { /* order == 5 */
  85984. for(i = 0; i < (int)data_len; i++) {
  85985. sum = 0;
  85986. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  85987. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  85988. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  85989. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  85990. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  85991. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  85992. }
  85993. }
  85994. }
  85995. }
  85996. else {
  85997. if(order > 2) {
  85998. if(order == 4) {
  85999. for(i = 0; i < (int)data_len; i++) {
  86000. sum = 0;
  86001. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86002. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86003. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86004. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86005. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86006. }
  86007. }
  86008. else { /* order == 3 */
  86009. for(i = 0; i < (int)data_len; i++) {
  86010. sum = 0;
  86011. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86012. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86013. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86014. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86015. }
  86016. }
  86017. }
  86018. else {
  86019. if(order == 2) {
  86020. for(i = 0; i < (int)data_len; i++) {
  86021. sum = 0;
  86022. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86023. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86024. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86025. }
  86026. }
  86027. else { /* order == 1 */
  86028. for(i = 0; i < (int)data_len; i++)
  86029. residual[i] = data[i] - (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86030. }
  86031. }
  86032. }
  86033. }
  86034. else { /* order > 12 */
  86035. for(i = 0; i < (int)data_len; i++) {
  86036. sum = 0;
  86037. switch(order) {
  86038. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86039. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86040. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86041. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86042. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86043. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86044. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86045. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86046. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86047. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86048. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86049. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86050. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86051. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86052. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86053. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86054. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86055. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86056. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86057. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86058. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86059. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86060. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86061. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86062. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86063. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86064. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86065. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86066. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86067. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86068. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86069. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86070. }
  86071. residual[i] = data[i] - (FLAC__int32)(sum >> lp_quantization);
  86072. }
  86073. }
  86074. }
  86075. #endif
  86076. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86077. 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[])
  86078. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86079. {
  86080. FLAC__int64 sumo;
  86081. unsigned i, j;
  86082. FLAC__int32 sum;
  86083. const FLAC__int32 *r = residual, *history;
  86084. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86085. fprintf(stderr,"FLAC__lpc_restore_signal: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86086. for(i=0;i<order;i++)
  86087. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86088. fprintf(stderr,"\n");
  86089. #endif
  86090. FLAC__ASSERT(order > 0);
  86091. for(i = 0; i < data_len; i++) {
  86092. sumo = 0;
  86093. sum = 0;
  86094. history = data;
  86095. for(j = 0; j < order; j++) {
  86096. sum += qlp_coeff[j] * (*(--history));
  86097. sumo += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*history);
  86098. #if defined _MSC_VER
  86099. if(sumo > 2147483647I64 || sumo < -2147483648I64)
  86100. 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);
  86101. #else
  86102. if(sumo > 2147483647ll || sumo < -2147483648ll)
  86103. 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);
  86104. #endif
  86105. }
  86106. *(data++) = *(r++) + (sum >> lp_quantization);
  86107. }
  86108. }
  86109. #else /* fully unrolled version for normal use */
  86110. {
  86111. int i;
  86112. FLAC__int32 sum;
  86113. FLAC__ASSERT(order > 0);
  86114. FLAC__ASSERT(order <= 32);
  86115. if(order <= 12) {
  86116. if(order > 8) {
  86117. if(order > 10) {
  86118. if(order == 12) {
  86119. for(i = 0; i < (int)data_len; i++) {
  86120. sum = 0;
  86121. sum += qlp_coeff[11] * data[i-12];
  86122. sum += qlp_coeff[10] * data[i-11];
  86123. sum += qlp_coeff[9] * data[i-10];
  86124. sum += qlp_coeff[8] * data[i-9];
  86125. sum += qlp_coeff[7] * data[i-8];
  86126. sum += qlp_coeff[6] * data[i-7];
  86127. sum += qlp_coeff[5] * data[i-6];
  86128. sum += qlp_coeff[4] * data[i-5];
  86129. sum += qlp_coeff[3] * data[i-4];
  86130. sum += qlp_coeff[2] * data[i-3];
  86131. sum += qlp_coeff[1] * data[i-2];
  86132. sum += qlp_coeff[0] * data[i-1];
  86133. data[i] = residual[i] + (sum >> lp_quantization);
  86134. }
  86135. }
  86136. else { /* order == 11 */
  86137. for(i = 0; i < (int)data_len; i++) {
  86138. sum = 0;
  86139. sum += qlp_coeff[10] * data[i-11];
  86140. sum += qlp_coeff[9] * data[i-10];
  86141. sum += qlp_coeff[8] * data[i-9];
  86142. sum += qlp_coeff[7] * data[i-8];
  86143. sum += qlp_coeff[6] * data[i-7];
  86144. sum += qlp_coeff[5] * data[i-6];
  86145. sum += qlp_coeff[4] * data[i-5];
  86146. sum += qlp_coeff[3] * data[i-4];
  86147. sum += qlp_coeff[2] * data[i-3];
  86148. sum += qlp_coeff[1] * data[i-2];
  86149. sum += qlp_coeff[0] * data[i-1];
  86150. data[i] = residual[i] + (sum >> lp_quantization);
  86151. }
  86152. }
  86153. }
  86154. else {
  86155. if(order == 10) {
  86156. for(i = 0; i < (int)data_len; i++) {
  86157. sum = 0;
  86158. sum += qlp_coeff[9] * data[i-10];
  86159. sum += qlp_coeff[8] * data[i-9];
  86160. sum += qlp_coeff[7] * data[i-8];
  86161. sum += qlp_coeff[6] * data[i-7];
  86162. sum += qlp_coeff[5] * data[i-6];
  86163. sum += qlp_coeff[4] * data[i-5];
  86164. sum += qlp_coeff[3] * data[i-4];
  86165. sum += qlp_coeff[2] * data[i-3];
  86166. sum += qlp_coeff[1] * data[i-2];
  86167. sum += qlp_coeff[0] * data[i-1];
  86168. data[i] = residual[i] + (sum >> lp_quantization);
  86169. }
  86170. }
  86171. else { /* order == 9 */
  86172. for(i = 0; i < (int)data_len; i++) {
  86173. sum = 0;
  86174. sum += qlp_coeff[8] * data[i-9];
  86175. sum += qlp_coeff[7] * data[i-8];
  86176. sum += qlp_coeff[6] * data[i-7];
  86177. sum += qlp_coeff[5] * data[i-6];
  86178. sum += qlp_coeff[4] * data[i-5];
  86179. sum += qlp_coeff[3] * data[i-4];
  86180. sum += qlp_coeff[2] * data[i-3];
  86181. sum += qlp_coeff[1] * data[i-2];
  86182. sum += qlp_coeff[0] * data[i-1];
  86183. data[i] = residual[i] + (sum >> lp_quantization);
  86184. }
  86185. }
  86186. }
  86187. }
  86188. else if(order > 4) {
  86189. if(order > 6) {
  86190. if(order == 8) {
  86191. for(i = 0; i < (int)data_len; i++) {
  86192. sum = 0;
  86193. sum += qlp_coeff[7] * data[i-8];
  86194. sum += qlp_coeff[6] * data[i-7];
  86195. sum += qlp_coeff[5] * data[i-6];
  86196. sum += qlp_coeff[4] * data[i-5];
  86197. sum += qlp_coeff[3] * data[i-4];
  86198. sum += qlp_coeff[2] * data[i-3];
  86199. sum += qlp_coeff[1] * data[i-2];
  86200. sum += qlp_coeff[0] * data[i-1];
  86201. data[i] = residual[i] + (sum >> lp_quantization);
  86202. }
  86203. }
  86204. else { /* order == 7 */
  86205. for(i = 0; i < (int)data_len; i++) {
  86206. sum = 0;
  86207. sum += qlp_coeff[6] * data[i-7];
  86208. sum += qlp_coeff[5] * data[i-6];
  86209. sum += qlp_coeff[4] * data[i-5];
  86210. sum += qlp_coeff[3] * data[i-4];
  86211. sum += qlp_coeff[2] * data[i-3];
  86212. sum += qlp_coeff[1] * data[i-2];
  86213. sum += qlp_coeff[0] * data[i-1];
  86214. data[i] = residual[i] + (sum >> lp_quantization);
  86215. }
  86216. }
  86217. }
  86218. else {
  86219. if(order == 6) {
  86220. for(i = 0; i < (int)data_len; i++) {
  86221. sum = 0;
  86222. sum += qlp_coeff[5] * data[i-6];
  86223. sum += qlp_coeff[4] * data[i-5];
  86224. sum += qlp_coeff[3] * data[i-4];
  86225. sum += qlp_coeff[2] * data[i-3];
  86226. sum += qlp_coeff[1] * data[i-2];
  86227. sum += qlp_coeff[0] * data[i-1];
  86228. data[i] = residual[i] + (sum >> lp_quantization);
  86229. }
  86230. }
  86231. else { /* order == 5 */
  86232. for(i = 0; i < (int)data_len; i++) {
  86233. sum = 0;
  86234. sum += qlp_coeff[4] * data[i-5];
  86235. sum += qlp_coeff[3] * data[i-4];
  86236. sum += qlp_coeff[2] * data[i-3];
  86237. sum += qlp_coeff[1] * data[i-2];
  86238. sum += qlp_coeff[0] * data[i-1];
  86239. data[i] = residual[i] + (sum >> lp_quantization);
  86240. }
  86241. }
  86242. }
  86243. }
  86244. else {
  86245. if(order > 2) {
  86246. if(order == 4) {
  86247. for(i = 0; i < (int)data_len; i++) {
  86248. sum = 0;
  86249. sum += qlp_coeff[3] * data[i-4];
  86250. sum += qlp_coeff[2] * data[i-3];
  86251. sum += qlp_coeff[1] * data[i-2];
  86252. sum += qlp_coeff[0] * data[i-1];
  86253. data[i] = residual[i] + (sum >> lp_quantization);
  86254. }
  86255. }
  86256. else { /* order == 3 */
  86257. for(i = 0; i < (int)data_len; i++) {
  86258. sum = 0;
  86259. sum += qlp_coeff[2] * data[i-3];
  86260. sum += qlp_coeff[1] * data[i-2];
  86261. sum += qlp_coeff[0] * data[i-1];
  86262. data[i] = residual[i] + (sum >> lp_quantization);
  86263. }
  86264. }
  86265. }
  86266. else {
  86267. if(order == 2) {
  86268. for(i = 0; i < (int)data_len; i++) {
  86269. sum = 0;
  86270. sum += qlp_coeff[1] * data[i-2];
  86271. sum += qlp_coeff[0] * data[i-1];
  86272. data[i] = residual[i] + (sum >> lp_quantization);
  86273. }
  86274. }
  86275. else { /* order == 1 */
  86276. for(i = 0; i < (int)data_len; i++)
  86277. data[i] = residual[i] + ((qlp_coeff[0] * data[i-1]) >> lp_quantization);
  86278. }
  86279. }
  86280. }
  86281. }
  86282. else { /* order > 12 */
  86283. for(i = 0; i < (int)data_len; i++) {
  86284. sum = 0;
  86285. switch(order) {
  86286. case 32: sum += qlp_coeff[31] * data[i-32];
  86287. case 31: sum += qlp_coeff[30] * data[i-31];
  86288. case 30: sum += qlp_coeff[29] * data[i-30];
  86289. case 29: sum += qlp_coeff[28] * data[i-29];
  86290. case 28: sum += qlp_coeff[27] * data[i-28];
  86291. case 27: sum += qlp_coeff[26] * data[i-27];
  86292. case 26: sum += qlp_coeff[25] * data[i-26];
  86293. case 25: sum += qlp_coeff[24] * data[i-25];
  86294. case 24: sum += qlp_coeff[23] * data[i-24];
  86295. case 23: sum += qlp_coeff[22] * data[i-23];
  86296. case 22: sum += qlp_coeff[21] * data[i-22];
  86297. case 21: sum += qlp_coeff[20] * data[i-21];
  86298. case 20: sum += qlp_coeff[19] * data[i-20];
  86299. case 19: sum += qlp_coeff[18] * data[i-19];
  86300. case 18: sum += qlp_coeff[17] * data[i-18];
  86301. case 17: sum += qlp_coeff[16] * data[i-17];
  86302. case 16: sum += qlp_coeff[15] * data[i-16];
  86303. case 15: sum += qlp_coeff[14] * data[i-15];
  86304. case 14: sum += qlp_coeff[13] * data[i-14];
  86305. case 13: sum += qlp_coeff[12] * data[i-13];
  86306. sum += qlp_coeff[11] * data[i-12];
  86307. sum += qlp_coeff[10] * data[i-11];
  86308. sum += qlp_coeff[ 9] * data[i-10];
  86309. sum += qlp_coeff[ 8] * data[i- 9];
  86310. sum += qlp_coeff[ 7] * data[i- 8];
  86311. sum += qlp_coeff[ 6] * data[i- 7];
  86312. sum += qlp_coeff[ 5] * data[i- 6];
  86313. sum += qlp_coeff[ 4] * data[i- 5];
  86314. sum += qlp_coeff[ 3] * data[i- 4];
  86315. sum += qlp_coeff[ 2] * data[i- 3];
  86316. sum += qlp_coeff[ 1] * data[i- 2];
  86317. sum += qlp_coeff[ 0] * data[i- 1];
  86318. }
  86319. data[i] = residual[i] + (sum >> lp_quantization);
  86320. }
  86321. }
  86322. }
  86323. #endif
  86324. 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[])
  86325. #if defined(FLAC__OVERFLOW_DETECT) || !defined(FLAC__LPC_UNROLLED_FILTER_LOOPS)
  86326. {
  86327. unsigned i, j;
  86328. FLAC__int64 sum;
  86329. const FLAC__int32 *r = residual, *history;
  86330. #ifdef FLAC__OVERFLOW_DETECT_VERBOSE
  86331. fprintf(stderr,"FLAC__lpc_restore_signal_wide: data_len=%d, order=%u, lpq=%d",data_len,order,lp_quantization);
  86332. for(i=0;i<order;i++)
  86333. fprintf(stderr,", q[%u]=%d",i,qlp_coeff[i]);
  86334. fprintf(stderr,"\n");
  86335. #endif
  86336. FLAC__ASSERT(order > 0);
  86337. for(i = 0; i < data_len; i++) {
  86338. sum = 0;
  86339. history = data;
  86340. for(j = 0; j < order; j++)
  86341. sum += (FLAC__int64)qlp_coeff[j] * (FLAC__int64)(*(--history));
  86342. if(FLAC__bitmath_silog2_wide(sum >> lp_quantization) > 32) {
  86343. #ifdef _MSC_VER
  86344. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%I64d\n", i, sum >> lp_quantization);
  86345. #else
  86346. fprintf(stderr,"FLAC__lpc_restore_signal_wide: OVERFLOW, i=%u, sum=%lld\n", i, (long long)(sum >> lp_quantization));
  86347. #endif
  86348. break;
  86349. }
  86350. if(FLAC__bitmath_silog2_wide((FLAC__int64)(*r) + (sum >> lp_quantization)) > 32) {
  86351. #ifdef _MSC_VER
  86352. 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));
  86353. #else
  86354. 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)));
  86355. #endif
  86356. break;
  86357. }
  86358. *(data++) = *(r++) + (FLAC__int32)(sum >> lp_quantization);
  86359. }
  86360. }
  86361. #else /* fully unrolled version for normal use */
  86362. {
  86363. int i;
  86364. FLAC__int64 sum;
  86365. FLAC__ASSERT(order > 0);
  86366. FLAC__ASSERT(order <= 32);
  86367. if(order <= 12) {
  86368. if(order > 8) {
  86369. if(order > 10) {
  86370. if(order == 12) {
  86371. for(i = 0; i < (int)data_len; i++) {
  86372. sum = 0;
  86373. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86374. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86375. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86376. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86377. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86378. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86379. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86380. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86381. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86382. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86383. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86384. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86385. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86386. }
  86387. }
  86388. else { /* order == 11 */
  86389. for(i = 0; i < (int)data_len; i++) {
  86390. sum = 0;
  86391. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86392. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86393. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86394. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86395. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86396. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86397. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86398. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86399. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86400. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86401. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86402. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86403. }
  86404. }
  86405. }
  86406. else {
  86407. if(order == 10) {
  86408. for(i = 0; i < (int)data_len; i++) {
  86409. sum = 0;
  86410. sum += qlp_coeff[9] * (FLAC__int64)data[i-10];
  86411. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86412. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86413. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86414. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86415. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86416. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86417. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86418. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86419. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86420. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86421. }
  86422. }
  86423. else { /* order == 9 */
  86424. for(i = 0; i < (int)data_len; i++) {
  86425. sum = 0;
  86426. sum += qlp_coeff[8] * (FLAC__int64)data[i-9];
  86427. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86428. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86429. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86430. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86431. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86432. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86433. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86434. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86435. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86436. }
  86437. }
  86438. }
  86439. }
  86440. else if(order > 4) {
  86441. if(order > 6) {
  86442. if(order == 8) {
  86443. for(i = 0; i < (int)data_len; i++) {
  86444. sum = 0;
  86445. sum += qlp_coeff[7] * (FLAC__int64)data[i-8];
  86446. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86447. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86448. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86449. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86450. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86451. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86452. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86453. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86454. }
  86455. }
  86456. else { /* order == 7 */
  86457. for(i = 0; i < (int)data_len; i++) {
  86458. sum = 0;
  86459. sum += qlp_coeff[6] * (FLAC__int64)data[i-7];
  86460. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86461. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86462. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86463. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86464. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86465. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86466. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86467. }
  86468. }
  86469. }
  86470. else {
  86471. if(order == 6) {
  86472. for(i = 0; i < (int)data_len; i++) {
  86473. sum = 0;
  86474. sum += qlp_coeff[5] * (FLAC__int64)data[i-6];
  86475. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86476. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86477. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86478. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86479. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86480. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86481. }
  86482. }
  86483. else { /* order == 5 */
  86484. for(i = 0; i < (int)data_len; i++) {
  86485. sum = 0;
  86486. sum += qlp_coeff[4] * (FLAC__int64)data[i-5];
  86487. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86488. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86489. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86490. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86491. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86492. }
  86493. }
  86494. }
  86495. }
  86496. else {
  86497. if(order > 2) {
  86498. if(order == 4) {
  86499. for(i = 0; i < (int)data_len; i++) {
  86500. sum = 0;
  86501. sum += qlp_coeff[3] * (FLAC__int64)data[i-4];
  86502. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86503. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86504. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86505. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86506. }
  86507. }
  86508. else { /* order == 3 */
  86509. for(i = 0; i < (int)data_len; i++) {
  86510. sum = 0;
  86511. sum += qlp_coeff[2] * (FLAC__int64)data[i-3];
  86512. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86513. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86514. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86515. }
  86516. }
  86517. }
  86518. else {
  86519. if(order == 2) {
  86520. for(i = 0; i < (int)data_len; i++) {
  86521. sum = 0;
  86522. sum += qlp_coeff[1] * (FLAC__int64)data[i-2];
  86523. sum += qlp_coeff[0] * (FLAC__int64)data[i-1];
  86524. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86525. }
  86526. }
  86527. else { /* order == 1 */
  86528. for(i = 0; i < (int)data_len; i++)
  86529. data[i] = residual[i] + (FLAC__int32)((qlp_coeff[0] * (FLAC__int64)data[i-1]) >> lp_quantization);
  86530. }
  86531. }
  86532. }
  86533. }
  86534. else { /* order > 12 */
  86535. for(i = 0; i < (int)data_len; i++) {
  86536. sum = 0;
  86537. switch(order) {
  86538. case 32: sum += qlp_coeff[31] * (FLAC__int64)data[i-32];
  86539. case 31: sum += qlp_coeff[30] * (FLAC__int64)data[i-31];
  86540. case 30: sum += qlp_coeff[29] * (FLAC__int64)data[i-30];
  86541. case 29: sum += qlp_coeff[28] * (FLAC__int64)data[i-29];
  86542. case 28: sum += qlp_coeff[27] * (FLAC__int64)data[i-28];
  86543. case 27: sum += qlp_coeff[26] * (FLAC__int64)data[i-27];
  86544. case 26: sum += qlp_coeff[25] * (FLAC__int64)data[i-26];
  86545. case 25: sum += qlp_coeff[24] * (FLAC__int64)data[i-25];
  86546. case 24: sum += qlp_coeff[23] * (FLAC__int64)data[i-24];
  86547. case 23: sum += qlp_coeff[22] * (FLAC__int64)data[i-23];
  86548. case 22: sum += qlp_coeff[21] * (FLAC__int64)data[i-22];
  86549. case 21: sum += qlp_coeff[20] * (FLAC__int64)data[i-21];
  86550. case 20: sum += qlp_coeff[19] * (FLAC__int64)data[i-20];
  86551. case 19: sum += qlp_coeff[18] * (FLAC__int64)data[i-19];
  86552. case 18: sum += qlp_coeff[17] * (FLAC__int64)data[i-18];
  86553. case 17: sum += qlp_coeff[16] * (FLAC__int64)data[i-17];
  86554. case 16: sum += qlp_coeff[15] * (FLAC__int64)data[i-16];
  86555. case 15: sum += qlp_coeff[14] * (FLAC__int64)data[i-15];
  86556. case 14: sum += qlp_coeff[13] * (FLAC__int64)data[i-14];
  86557. case 13: sum += qlp_coeff[12] * (FLAC__int64)data[i-13];
  86558. sum += qlp_coeff[11] * (FLAC__int64)data[i-12];
  86559. sum += qlp_coeff[10] * (FLAC__int64)data[i-11];
  86560. sum += qlp_coeff[ 9] * (FLAC__int64)data[i-10];
  86561. sum += qlp_coeff[ 8] * (FLAC__int64)data[i- 9];
  86562. sum += qlp_coeff[ 7] * (FLAC__int64)data[i- 8];
  86563. sum += qlp_coeff[ 6] * (FLAC__int64)data[i- 7];
  86564. sum += qlp_coeff[ 5] * (FLAC__int64)data[i- 6];
  86565. sum += qlp_coeff[ 4] * (FLAC__int64)data[i- 5];
  86566. sum += qlp_coeff[ 3] * (FLAC__int64)data[i- 4];
  86567. sum += qlp_coeff[ 2] * (FLAC__int64)data[i- 3];
  86568. sum += qlp_coeff[ 1] * (FLAC__int64)data[i- 2];
  86569. sum += qlp_coeff[ 0] * (FLAC__int64)data[i- 1];
  86570. }
  86571. data[i] = residual[i] + (FLAC__int32)(sum >> lp_quantization);
  86572. }
  86573. }
  86574. }
  86575. #endif
  86576. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  86577. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample(FLAC__double lpc_error, unsigned total_samples)
  86578. {
  86579. FLAC__double error_scale;
  86580. FLAC__ASSERT(total_samples > 0);
  86581. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86582. return FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(lpc_error, error_scale);
  86583. }
  86584. FLAC__double FLAC__lpc_compute_expected_bits_per_residual_sample_with_error_scale(FLAC__double lpc_error, FLAC__double error_scale)
  86585. {
  86586. if(lpc_error > 0.0) {
  86587. FLAC__double bps = (FLAC__double)0.5 * log(error_scale * lpc_error) / M_LN2;
  86588. if(bps >= 0.0)
  86589. return bps;
  86590. else
  86591. return 0.0;
  86592. }
  86593. else if(lpc_error < 0.0) { /* error should not be negative but can happen due to inadequate floating-point resolution */
  86594. return 1e32;
  86595. }
  86596. else {
  86597. return 0.0;
  86598. }
  86599. }
  86600. unsigned FLAC__lpc_compute_best_order(const FLAC__double lpc_error[], unsigned max_order, unsigned total_samples, unsigned overhead_bits_per_order)
  86601. {
  86602. 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 */
  86603. FLAC__double bits, best_bits, error_scale;
  86604. FLAC__ASSERT(max_order > 0);
  86605. FLAC__ASSERT(total_samples > 0);
  86606. error_scale = 0.5 * M_LN2 * M_LN2 / (FLAC__double)total_samples;
  86607. best_index = 0;
  86608. best_bits = (unsigned)(-1);
  86609. for(index = 0, order = 1; index < max_order; index++, order++) {
  86610. 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);
  86611. if(bits < best_bits) {
  86612. best_index = index;
  86613. best_bits = bits;
  86614. }
  86615. }
  86616. return best_index+1; /* +1 since index of lpc_error[] is order-1 */
  86617. }
  86618. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  86619. #endif
  86620. /*** End of inlined file: lpc_flac.c ***/
  86621. /*** Start of inlined file: md5.c ***/
  86622. /*** Start of inlined file: juce_FlacHeader.h ***/
  86623. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86624. // tasks..
  86625. #define VERSION "1.2.1"
  86626. #define FLAC__NO_DLL 1
  86627. #if JUCE_MSVC
  86628. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86629. #endif
  86630. #if JUCE_MAC
  86631. #define FLAC__SYS_DARWIN 1
  86632. #endif
  86633. /*** End of inlined file: juce_FlacHeader.h ***/
  86634. #if JUCE_USE_FLAC
  86635. #if HAVE_CONFIG_H
  86636. # include <config.h>
  86637. #endif
  86638. #include <stdlib.h> /* for malloc() */
  86639. #include <string.h> /* for memcpy() */
  86640. /*** Start of inlined file: md5.h ***/
  86641. #ifndef FLAC__PRIVATE__MD5_H
  86642. #define FLAC__PRIVATE__MD5_H
  86643. typedef struct {
  86644. FLAC__uint32 in[16];
  86645. FLAC__uint32 buf[4];
  86646. FLAC__uint32 bytes[2];
  86647. FLAC__byte *internal_buf;
  86648. size_t capacity;
  86649. } FLAC__MD5Context;
  86650. void FLAC__MD5Init(FLAC__MD5Context *context);
  86651. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *context);
  86652. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample);
  86653. #endif
  86654. /*** End of inlined file: md5.h ***/
  86655. #ifndef FLaC__INLINE
  86656. #define FLaC__INLINE
  86657. #endif
  86658. #define F1(x, y, z) (z ^ (x & (y ^ z)))
  86659. #define F2(x, y, z) F1(z, x, y)
  86660. #define F3(x, y, z) (x ^ y ^ z)
  86661. #define F4(x, y, z) (y ^ (x | ~z))
  86662. #define MD5STEP(f,w,x,y,z,in,s) \
  86663. (w += f(x,y,z) + in, w = (w<<s | w>>(32-s)) + x)
  86664. static void FLAC__MD5Transform(FLAC__uint32 buf[4], FLAC__uint32 const in[16])
  86665. {
  86666. register FLAC__uint32 a, b, c, d;
  86667. a = buf[0];
  86668. b = buf[1];
  86669. c = buf[2];
  86670. d = buf[3];
  86671. MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7);
  86672. MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12);
  86673. MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17);
  86674. MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22);
  86675. MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7);
  86676. MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12);
  86677. MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17);
  86678. MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22);
  86679. MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7);
  86680. MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12);
  86681. MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17);
  86682. MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22);
  86683. MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7);
  86684. MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12);
  86685. MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17);
  86686. MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22);
  86687. MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5);
  86688. MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9);
  86689. MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14);
  86690. MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20);
  86691. MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5);
  86692. MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9);
  86693. MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14);
  86694. MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20);
  86695. MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5);
  86696. MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9);
  86697. MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14);
  86698. MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20);
  86699. MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5);
  86700. MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9);
  86701. MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14);
  86702. MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20);
  86703. MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4);
  86704. MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11);
  86705. MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16);
  86706. MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23);
  86707. MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4);
  86708. MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11);
  86709. MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16);
  86710. MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23);
  86711. MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4);
  86712. MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11);
  86713. MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16);
  86714. MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23);
  86715. MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4);
  86716. MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11);
  86717. MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16);
  86718. MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23);
  86719. MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6);
  86720. MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10);
  86721. MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15);
  86722. MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21);
  86723. MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6);
  86724. MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10);
  86725. MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15);
  86726. MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21);
  86727. MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6);
  86728. MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10);
  86729. MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15);
  86730. MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21);
  86731. MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6);
  86732. MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10);
  86733. MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15);
  86734. MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21);
  86735. buf[0] += a;
  86736. buf[1] += b;
  86737. buf[2] += c;
  86738. buf[3] += d;
  86739. }
  86740. #if WORDS_BIGENDIAN
  86741. //@@@@@@ OPT: use bswap/intrinsics
  86742. static void byteSwap(FLAC__uint32 *buf, unsigned words)
  86743. {
  86744. register FLAC__uint32 x;
  86745. do {
  86746. x = *buf;
  86747. x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff);
  86748. *buf++ = (x >> 16) | (x << 16);
  86749. } while (--words);
  86750. }
  86751. static void byteSwapX16(FLAC__uint32 *buf)
  86752. {
  86753. register FLAC__uint32 x;
  86754. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86755. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86756. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86757. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86758. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86759. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86760. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86761. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86762. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86763. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86764. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86765. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86766. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86767. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86768. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf++ = (x >> 16) | (x << 16);
  86769. x = *buf; x = ((x << 8) & 0xff00ff00) | ((x >> 8) & 0x00ff00ff); *buf = (x >> 16) | (x << 16);
  86770. }
  86771. #else
  86772. #define byteSwap(buf, words)
  86773. #define byteSwapX16(buf)
  86774. #endif
  86775. static void FLAC__MD5Update(FLAC__MD5Context *ctx, FLAC__byte const *buf, unsigned len)
  86776. {
  86777. FLAC__uint32 t;
  86778. t = ctx->bytes[0];
  86779. if ((ctx->bytes[0] = t + len) < t)
  86780. ctx->bytes[1]++; /* Carry from low to high */
  86781. t = 64 - (t & 0x3f); /* Space available in ctx->in (at least 1) */
  86782. if (t > len) {
  86783. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, len);
  86784. return;
  86785. }
  86786. memcpy((FLAC__byte *)ctx->in + 64 - t, buf, t);
  86787. byteSwapX16(ctx->in);
  86788. FLAC__MD5Transform(ctx->buf, ctx->in);
  86789. buf += t;
  86790. len -= t;
  86791. while (len >= 64) {
  86792. memcpy(ctx->in, buf, 64);
  86793. byteSwapX16(ctx->in);
  86794. FLAC__MD5Transform(ctx->buf, ctx->in);
  86795. buf += 64;
  86796. len -= 64;
  86797. }
  86798. memcpy(ctx->in, buf, len);
  86799. }
  86800. void FLAC__MD5Init(FLAC__MD5Context *ctx)
  86801. {
  86802. ctx->buf[0] = 0x67452301;
  86803. ctx->buf[1] = 0xefcdab89;
  86804. ctx->buf[2] = 0x98badcfe;
  86805. ctx->buf[3] = 0x10325476;
  86806. ctx->bytes[0] = 0;
  86807. ctx->bytes[1] = 0;
  86808. ctx->internal_buf = 0;
  86809. ctx->capacity = 0;
  86810. }
  86811. void FLAC__MD5Final(FLAC__byte digest[16], FLAC__MD5Context *ctx)
  86812. {
  86813. int count = ctx->bytes[0] & 0x3f; /* Number of bytes in ctx->in */
  86814. FLAC__byte *p = (FLAC__byte *)ctx->in + count;
  86815. *p++ = 0x80;
  86816. count = 56 - 1 - count;
  86817. if (count < 0) { /* Padding forces an extra block */
  86818. memset(p, 0, count + 8);
  86819. byteSwapX16(ctx->in);
  86820. FLAC__MD5Transform(ctx->buf, ctx->in);
  86821. p = (FLAC__byte *)ctx->in;
  86822. count = 56;
  86823. }
  86824. memset(p, 0, count);
  86825. byteSwap(ctx->in, 14);
  86826. ctx->in[14] = ctx->bytes[0] << 3;
  86827. ctx->in[15] = ctx->bytes[1] << 3 | ctx->bytes[0] >> 29;
  86828. FLAC__MD5Transform(ctx->buf, ctx->in);
  86829. byteSwap(ctx->buf, 4);
  86830. memcpy(digest, ctx->buf, 16);
  86831. memset(ctx, 0, sizeof(ctx)); /* In case it's sensitive */
  86832. if(0 != ctx->internal_buf) {
  86833. free(ctx->internal_buf);
  86834. ctx->internal_buf = 0;
  86835. ctx->capacity = 0;
  86836. }
  86837. }
  86838. static void format_input_(FLAC__byte *buf, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86839. {
  86840. unsigned channel, sample;
  86841. register FLAC__int32 a_word;
  86842. register FLAC__byte *buf_ = buf;
  86843. #if WORDS_BIGENDIAN
  86844. #else
  86845. if(channels == 2 && bytes_per_sample == 2) {
  86846. FLAC__int16 *buf1_ = ((FLAC__int16*)buf_) + 1;
  86847. memcpy(buf_, signal[0], sizeof(FLAC__int32) * samples);
  86848. for(sample = 0; sample < samples; sample++, buf1_+=2)
  86849. *buf1_ = (FLAC__int16)signal[1][sample];
  86850. }
  86851. else if(channels == 1 && bytes_per_sample == 2) {
  86852. FLAC__int16 *buf1_ = (FLAC__int16*)buf_;
  86853. for(sample = 0; sample < samples; sample++)
  86854. *buf1_++ = (FLAC__int16)signal[0][sample];
  86855. }
  86856. else
  86857. #endif
  86858. if(bytes_per_sample == 2) {
  86859. if(channels == 2) {
  86860. for(sample = 0; sample < samples; sample++) {
  86861. a_word = signal[0][sample];
  86862. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86863. *buf_++ = (FLAC__byte)a_word;
  86864. a_word = signal[1][sample];
  86865. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86866. *buf_++ = (FLAC__byte)a_word;
  86867. }
  86868. }
  86869. else if(channels == 1) {
  86870. for(sample = 0; sample < samples; sample++) {
  86871. a_word = signal[0][sample];
  86872. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86873. *buf_++ = (FLAC__byte)a_word;
  86874. }
  86875. }
  86876. else {
  86877. for(sample = 0; sample < samples; sample++) {
  86878. for(channel = 0; channel < channels; channel++) {
  86879. a_word = signal[channel][sample];
  86880. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86881. *buf_++ = (FLAC__byte)a_word;
  86882. }
  86883. }
  86884. }
  86885. }
  86886. else if(bytes_per_sample == 3) {
  86887. if(channels == 2) {
  86888. for(sample = 0; sample < samples; sample++) {
  86889. a_word = signal[0][sample];
  86890. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86891. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86892. *buf_++ = (FLAC__byte)a_word;
  86893. a_word = signal[1][sample];
  86894. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86895. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86896. *buf_++ = (FLAC__byte)a_word;
  86897. }
  86898. }
  86899. else if(channels == 1) {
  86900. for(sample = 0; sample < samples; sample++) {
  86901. a_word = signal[0][sample];
  86902. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86903. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86904. *buf_++ = (FLAC__byte)a_word;
  86905. }
  86906. }
  86907. else {
  86908. for(sample = 0; sample < samples; sample++) {
  86909. for(channel = 0; channel < channels; channel++) {
  86910. a_word = signal[channel][sample];
  86911. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86912. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86913. *buf_++ = (FLAC__byte)a_word;
  86914. }
  86915. }
  86916. }
  86917. }
  86918. else if(bytes_per_sample == 1) {
  86919. if(channels == 2) {
  86920. for(sample = 0; sample < samples; sample++) {
  86921. a_word = signal[0][sample];
  86922. *buf_++ = (FLAC__byte)a_word;
  86923. a_word = signal[1][sample];
  86924. *buf_++ = (FLAC__byte)a_word;
  86925. }
  86926. }
  86927. else if(channels == 1) {
  86928. for(sample = 0; sample < samples; sample++) {
  86929. a_word = signal[0][sample];
  86930. *buf_++ = (FLAC__byte)a_word;
  86931. }
  86932. }
  86933. else {
  86934. for(sample = 0; sample < samples; sample++) {
  86935. for(channel = 0; channel < channels; channel++) {
  86936. a_word = signal[channel][sample];
  86937. *buf_++ = (FLAC__byte)a_word;
  86938. }
  86939. }
  86940. }
  86941. }
  86942. else { /* bytes_per_sample == 4, maybe optimize more later */
  86943. for(sample = 0; sample < samples; sample++) {
  86944. for(channel = 0; channel < channels; channel++) {
  86945. a_word = signal[channel][sample];
  86946. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86947. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86948. *buf_++ = (FLAC__byte)a_word; a_word >>= 8;
  86949. *buf_++ = (FLAC__byte)a_word;
  86950. }
  86951. }
  86952. }
  86953. }
  86954. FLAC__bool FLAC__MD5Accumulate(FLAC__MD5Context *ctx, const FLAC__int32 * const signal[], unsigned channels, unsigned samples, unsigned bytes_per_sample)
  86955. {
  86956. const size_t bytes_needed = (size_t)channels * (size_t)samples * (size_t)bytes_per_sample;
  86957. if((size_t)channels > SIZE_MAX / (size_t)bytes_per_sample)
  86958. return false;
  86959. if((size_t)channels * (size_t)bytes_per_sample > SIZE_MAX / (size_t)samples)
  86960. return false;
  86961. if(ctx->capacity < bytes_needed) {
  86962. FLAC__byte *tmp = (FLAC__byte*)realloc(ctx->internal_buf, bytes_needed);
  86963. if(0 == tmp) {
  86964. free(ctx->internal_buf);
  86965. if(0 == (ctx->internal_buf = (FLAC__byte*)safe_malloc_(bytes_needed)))
  86966. return false;
  86967. }
  86968. ctx->internal_buf = tmp;
  86969. ctx->capacity = bytes_needed;
  86970. }
  86971. format_input_(ctx->internal_buf, signal, channels, samples, bytes_per_sample);
  86972. FLAC__MD5Update(ctx, ctx->internal_buf, bytes_needed);
  86973. return true;
  86974. }
  86975. #endif
  86976. /*** End of inlined file: md5.c ***/
  86977. /*** Start of inlined file: memory.c ***/
  86978. /*** Start of inlined file: juce_FlacHeader.h ***/
  86979. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  86980. // tasks..
  86981. #define VERSION "1.2.1"
  86982. #define FLAC__NO_DLL 1
  86983. #if JUCE_MSVC
  86984. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  86985. #endif
  86986. #if JUCE_MAC
  86987. #define FLAC__SYS_DARWIN 1
  86988. #endif
  86989. /*** End of inlined file: juce_FlacHeader.h ***/
  86990. #if JUCE_USE_FLAC
  86991. #if HAVE_CONFIG_H
  86992. # include <config.h>
  86993. #endif
  86994. /*** Start of inlined file: memory.h ***/
  86995. #ifndef FLAC__PRIVATE__MEMORY_H
  86996. #define FLAC__PRIVATE__MEMORY_H
  86997. #ifdef HAVE_CONFIG_H
  86998. #include <config.h>
  86999. #endif
  87000. #include <stdlib.h> /* for size_t */
  87001. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address);
  87002. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer);
  87003. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer);
  87004. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer);
  87005. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer);
  87006. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  87007. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer);
  87008. #endif
  87009. #endif
  87010. /*** End of inlined file: memory.h ***/
  87011. void *FLAC__memory_alloc_aligned(size_t bytes, void **aligned_address)
  87012. {
  87013. void *x;
  87014. FLAC__ASSERT(0 != aligned_address);
  87015. #ifdef FLAC__ALIGN_MALLOC_DATA
  87016. x = safe_malloc_add_2op_(bytes, /*+*/31);
  87017. #ifdef SIZEOF_VOIDP
  87018. #if SIZEOF_VOIDP == 4
  87019. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  87020. #elif SIZEOF_VOIDP == 8
  87021. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  87022. #else
  87023. # error Unsupported sizeof(void*)
  87024. #endif
  87025. #else
  87026. if(sizeof(void*) == sizeof(unsigned))
  87027. *aligned_address = (void*)(((unsigned)x + 31) & -32);
  87028. else if(sizeof(void*) == sizeof(FLAC__uint64))
  87029. *aligned_address = (void*)(((FLAC__uint64)x + 31) & (FLAC__uint64)(-((FLAC__int64)32)));
  87030. else
  87031. return 0;
  87032. #endif
  87033. #else
  87034. x = safe_malloc_(bytes);
  87035. *aligned_address = x;
  87036. #endif
  87037. return x;
  87038. }
  87039. FLAC__bool FLAC__memory_alloc_aligned_int32_array(unsigned elements, FLAC__int32 **unaligned_pointer, FLAC__int32 **aligned_pointer)
  87040. {
  87041. FLAC__int32 *pu; /* unaligned pointer */
  87042. union { /* union needed to comply with C99 pointer aliasing rules */
  87043. FLAC__int32 *pa; /* aligned pointer */
  87044. void *pv; /* aligned pointer alias */
  87045. } u;
  87046. FLAC__ASSERT(elements > 0);
  87047. FLAC__ASSERT(0 != unaligned_pointer);
  87048. FLAC__ASSERT(0 != aligned_pointer);
  87049. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87050. pu = (FLAC__int32*)FLAC__memory_alloc_aligned(sizeof(*pu) * (size_t)elements, &u.pv);
  87051. if(0 == pu) {
  87052. return false;
  87053. }
  87054. else {
  87055. if(*unaligned_pointer != 0)
  87056. free(*unaligned_pointer);
  87057. *unaligned_pointer = pu;
  87058. *aligned_pointer = u.pa;
  87059. return true;
  87060. }
  87061. }
  87062. FLAC__bool FLAC__memory_alloc_aligned_uint32_array(unsigned elements, FLAC__uint32 **unaligned_pointer, FLAC__uint32 **aligned_pointer)
  87063. {
  87064. FLAC__uint32 *pu; /* unaligned pointer */
  87065. union { /* union needed to comply with C99 pointer aliasing rules */
  87066. FLAC__uint32 *pa; /* aligned pointer */
  87067. void *pv; /* aligned pointer alias */
  87068. } u;
  87069. FLAC__ASSERT(elements > 0);
  87070. FLAC__ASSERT(0 != unaligned_pointer);
  87071. FLAC__ASSERT(0 != aligned_pointer);
  87072. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87073. pu = (FLAC__uint32*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87074. if(0 == pu) {
  87075. return false;
  87076. }
  87077. else {
  87078. if(*unaligned_pointer != 0)
  87079. free(*unaligned_pointer);
  87080. *unaligned_pointer = pu;
  87081. *aligned_pointer = u.pa;
  87082. return true;
  87083. }
  87084. }
  87085. FLAC__bool FLAC__memory_alloc_aligned_uint64_array(unsigned elements, FLAC__uint64 **unaligned_pointer, FLAC__uint64 **aligned_pointer)
  87086. {
  87087. FLAC__uint64 *pu; /* unaligned pointer */
  87088. union { /* union needed to comply with C99 pointer aliasing rules */
  87089. FLAC__uint64 *pa; /* aligned pointer */
  87090. void *pv; /* aligned pointer alias */
  87091. } u;
  87092. FLAC__ASSERT(elements > 0);
  87093. FLAC__ASSERT(0 != unaligned_pointer);
  87094. FLAC__ASSERT(0 != aligned_pointer);
  87095. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87096. pu = (FLAC__uint64*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87097. if(0 == pu) {
  87098. return false;
  87099. }
  87100. else {
  87101. if(*unaligned_pointer != 0)
  87102. free(*unaligned_pointer);
  87103. *unaligned_pointer = pu;
  87104. *aligned_pointer = u.pa;
  87105. return true;
  87106. }
  87107. }
  87108. FLAC__bool FLAC__memory_alloc_aligned_unsigned_array(unsigned elements, unsigned **unaligned_pointer, unsigned **aligned_pointer)
  87109. {
  87110. unsigned *pu; /* unaligned pointer */
  87111. union { /* union needed to comply with C99 pointer aliasing rules */
  87112. unsigned *pa; /* aligned pointer */
  87113. void *pv; /* aligned pointer alias */
  87114. } u;
  87115. FLAC__ASSERT(elements > 0);
  87116. FLAC__ASSERT(0 != unaligned_pointer);
  87117. FLAC__ASSERT(0 != aligned_pointer);
  87118. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87119. pu = (unsigned*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87120. if(0 == pu) {
  87121. return false;
  87122. }
  87123. else {
  87124. if(*unaligned_pointer != 0)
  87125. free(*unaligned_pointer);
  87126. *unaligned_pointer = pu;
  87127. *aligned_pointer = u.pa;
  87128. return true;
  87129. }
  87130. }
  87131. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  87132. FLAC__bool FLAC__memory_alloc_aligned_real_array(unsigned elements, FLAC__real **unaligned_pointer, FLAC__real **aligned_pointer)
  87133. {
  87134. FLAC__real *pu; /* unaligned pointer */
  87135. union { /* union needed to comply with C99 pointer aliasing rules */
  87136. FLAC__real *pa; /* aligned pointer */
  87137. void *pv; /* aligned pointer alias */
  87138. } u;
  87139. FLAC__ASSERT(elements > 0);
  87140. FLAC__ASSERT(0 != unaligned_pointer);
  87141. FLAC__ASSERT(0 != aligned_pointer);
  87142. FLAC__ASSERT(unaligned_pointer != aligned_pointer);
  87143. pu = (FLAC__real*)FLAC__memory_alloc_aligned(sizeof(*pu) * elements, &u.pv);
  87144. if(0 == pu) {
  87145. return false;
  87146. }
  87147. else {
  87148. if(*unaligned_pointer != 0)
  87149. free(*unaligned_pointer);
  87150. *unaligned_pointer = pu;
  87151. *aligned_pointer = u.pa;
  87152. return true;
  87153. }
  87154. }
  87155. #endif
  87156. #endif
  87157. /*** End of inlined file: memory.c ***/
  87158. /*** Start of inlined file: stream_decoder.c ***/
  87159. /*** Start of inlined file: juce_FlacHeader.h ***/
  87160. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  87161. // tasks..
  87162. #define VERSION "1.2.1"
  87163. #define FLAC__NO_DLL 1
  87164. #if JUCE_MSVC
  87165. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  87166. #endif
  87167. #if JUCE_MAC
  87168. #define FLAC__SYS_DARWIN 1
  87169. #endif
  87170. /*** End of inlined file: juce_FlacHeader.h ***/
  87171. #if JUCE_USE_FLAC
  87172. #if HAVE_CONFIG_H
  87173. # include <config.h>
  87174. #endif
  87175. #if defined _MSC_VER || defined __MINGW32__
  87176. #include <io.h> /* for _setmode() */
  87177. #include <fcntl.h> /* for _O_BINARY */
  87178. #endif
  87179. #if defined __CYGWIN__ || defined __EMX__
  87180. #include <io.h> /* for setmode(), O_BINARY */
  87181. #include <fcntl.h> /* for _O_BINARY */
  87182. #endif
  87183. #include <stdio.h>
  87184. #include <stdlib.h> /* for malloc() */
  87185. #include <string.h> /* for memset/memcpy() */
  87186. #include <sys/stat.h> /* for stat() */
  87187. #include <sys/types.h> /* for off_t */
  87188. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  87189. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  87190. #define fseeko fseek
  87191. #define ftello ftell
  87192. #endif
  87193. #endif
  87194. /*** Start of inlined file: stream_decoder.h ***/
  87195. #ifndef FLAC__PROTECTED__STREAM_DECODER_H
  87196. #define FLAC__PROTECTED__STREAM_DECODER_H
  87197. #if FLAC__HAS_OGG
  87198. #include "include/private/ogg_decoder_aspect.h"
  87199. #endif
  87200. typedef struct FLAC__StreamDecoderProtected {
  87201. FLAC__StreamDecoderState state;
  87202. unsigned channels;
  87203. FLAC__ChannelAssignment channel_assignment;
  87204. unsigned bits_per_sample;
  87205. unsigned sample_rate; /* in Hz */
  87206. unsigned blocksize; /* in samples (per channel) */
  87207. FLAC__bool md5_checking; /* if true, generate MD5 signature of decoded data and compare against signature in the STREAMINFO metadata block */
  87208. #if FLAC__HAS_OGG
  87209. FLAC__OggDecoderAspect ogg_decoder_aspect;
  87210. #endif
  87211. } FLAC__StreamDecoderProtected;
  87212. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder);
  87213. #endif
  87214. /*** End of inlined file: stream_decoder.h ***/
  87215. #ifdef max
  87216. #undef max
  87217. #endif
  87218. #define max(a,b) ((a)>(b)?(a):(b))
  87219. #ifdef _MSC_VER
  87220. #define FLAC__U64L(x) x
  87221. #else
  87222. #define FLAC__U64L(x) x##LLU
  87223. #endif
  87224. FLAC_API int FLAC_API_SUPPORTS_OGG_FLAC =
  87225. #if FLAC__HAS_OGG
  87226. 1
  87227. #else
  87228. 0
  87229. #endif
  87230. ;
  87231. static FLAC__byte ID3V2_TAG_[3] = { 'I', 'D', '3' };
  87232. static void set_defaults_dec(FLAC__StreamDecoder *decoder);
  87233. static FILE *get_binary_stdin_(void);
  87234. static FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels);
  87235. static FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id);
  87236. static FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder);
  87237. static FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder);
  87238. static FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  87239. static FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length);
  87240. static FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj);
  87241. static FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj);
  87242. static FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj);
  87243. static FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder);
  87244. static FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder);
  87245. static FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode);
  87246. static FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder);
  87247. static FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87248. static FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87249. static FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  87250. static FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode);
  87251. static FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode);
  87252. 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);
  87253. static FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder);
  87254. static FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data);
  87255. #if FLAC__HAS_OGG
  87256. static FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes);
  87257. static FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  87258. #endif
  87259. static FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[]);
  87260. static void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status);
  87261. static FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  87262. #if FLAC__HAS_OGG
  87263. static FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample);
  87264. #endif
  87265. static FLAC__StreamDecoderReadStatus file_read_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  87266. static FLAC__StreamDecoderSeekStatus file_seek_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  87267. static FLAC__StreamDecoderTellStatus file_tell_callback_dec (const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  87268. static FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data);
  87269. static FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data);
  87270. typedef struct FLAC__StreamDecoderPrivate {
  87271. #if FLAC__HAS_OGG
  87272. FLAC__bool is_ogg;
  87273. #endif
  87274. FLAC__StreamDecoderReadCallback read_callback;
  87275. FLAC__StreamDecoderSeekCallback seek_callback;
  87276. FLAC__StreamDecoderTellCallback tell_callback;
  87277. FLAC__StreamDecoderLengthCallback length_callback;
  87278. FLAC__StreamDecoderEofCallback eof_callback;
  87279. FLAC__StreamDecoderWriteCallback write_callback;
  87280. FLAC__StreamDecoderMetadataCallback metadata_callback;
  87281. FLAC__StreamDecoderErrorCallback error_callback;
  87282. 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[]);
  87283. 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[]);
  87284. 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[]);
  87285. 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[]);
  87286. FLAC__bool (*local_bitreader_read_rice_signed_block)(FLAC__BitReader *br, int* vals, unsigned nvals, unsigned parameter);
  87287. void *client_data;
  87288. FILE *file; /* only used if FLAC__stream_decoder_init_file()/FLAC__stream_decoder_init_file() called, else NULL */
  87289. FLAC__BitReader *input;
  87290. FLAC__int32 *output[FLAC__MAX_CHANNELS];
  87291. FLAC__int32 *residual[FLAC__MAX_CHANNELS]; /* WATCHOUT: these are the aligned pointers; the real pointers that should be free()'d are residual_unaligned[] below */
  87292. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents[FLAC__MAX_CHANNELS];
  87293. unsigned output_capacity, output_channels;
  87294. FLAC__uint32 fixed_block_size, next_fixed_block_size;
  87295. FLAC__uint64 samples_decoded;
  87296. FLAC__bool has_stream_info, has_seek_table;
  87297. FLAC__StreamMetadata stream_info;
  87298. FLAC__StreamMetadata seek_table;
  87299. FLAC__bool metadata_filter[128]; /* MAGIC number 128 == total number of metadata block types == 1 << 7 */
  87300. FLAC__byte *metadata_filter_ids;
  87301. size_t metadata_filter_ids_count, metadata_filter_ids_capacity; /* units for both are IDs, not bytes */
  87302. FLAC__Frame frame;
  87303. FLAC__bool cached; /* true if there is a byte in lookahead */
  87304. FLAC__CPUInfo cpuinfo;
  87305. FLAC__byte header_warmup[2]; /* contains the sync code and reserved bits */
  87306. FLAC__byte lookahead; /* temp storage when we need to look ahead one byte in the stream */
  87307. FLAC__int32 *residual_unaligned[FLAC__MAX_CHANNELS];
  87308. 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 */
  87309. FLAC__bool internal_reset_hack; /* used only during init() so we can call reset to set up the decoder without rewinding the input */
  87310. FLAC__bool is_seeking;
  87311. FLAC__MD5Context md5context;
  87312. FLAC__byte computed_md5sum[16]; /* this is the sum we computed from the decoded data */
  87313. FLAC__Frame last_frame; /* holds the info of the last frame we seeked to */
  87314. FLAC__uint64 first_frame_offset; /* hint to the seek routine of where in the stream the first audio frame starts */
  87315. FLAC__uint64 target_sample;
  87316. unsigned unparseable_frame_count; /* used to tell whether we're decoding a future version of FLAC or just got a bad sync */
  87317. #if FLAC__HAS_OGG
  87318. FLAC__bool got_a_frame; /* hack needed in Ogg FLAC seek routine to check when process_single() actually writes a frame */
  87319. #endif
  87320. } FLAC__StreamDecoderPrivate;
  87321. FLAC_API const char * const FLAC__StreamDecoderStateString[] = {
  87322. "FLAC__STREAM_DECODER_SEARCH_FOR_METADATA",
  87323. "FLAC__STREAM_DECODER_READ_METADATA",
  87324. "FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC",
  87325. "FLAC__STREAM_DECODER_READ_FRAME",
  87326. "FLAC__STREAM_DECODER_END_OF_STREAM",
  87327. "FLAC__STREAM_DECODER_OGG_ERROR",
  87328. "FLAC__STREAM_DECODER_SEEK_ERROR",
  87329. "FLAC__STREAM_DECODER_ABORTED",
  87330. "FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR",
  87331. "FLAC__STREAM_DECODER_UNINITIALIZED"
  87332. };
  87333. FLAC_API const char * const FLAC__StreamDecoderInitStatusString[] = {
  87334. "FLAC__STREAM_DECODER_INIT_STATUS_OK",
  87335. "FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  87336. "FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS",
  87337. "FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR",
  87338. "FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE",
  87339. "FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED"
  87340. };
  87341. FLAC_API const char * const FLAC__StreamDecoderReadStatusString[] = {
  87342. "FLAC__STREAM_DECODER_READ_STATUS_CONTINUE",
  87343. "FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM",
  87344. "FLAC__STREAM_DECODER_READ_STATUS_ABORT"
  87345. };
  87346. FLAC_API const char * const FLAC__StreamDecoderSeekStatusString[] = {
  87347. "FLAC__STREAM_DECODER_SEEK_STATUS_OK",
  87348. "FLAC__STREAM_DECODER_SEEK_STATUS_ERROR",
  87349. "FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED"
  87350. };
  87351. FLAC_API const char * const FLAC__StreamDecoderTellStatusString[] = {
  87352. "FLAC__STREAM_DECODER_TELL_STATUS_OK",
  87353. "FLAC__STREAM_DECODER_TELL_STATUS_ERROR",
  87354. "FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED"
  87355. };
  87356. FLAC_API const char * const FLAC__StreamDecoderLengthStatusString[] = {
  87357. "FLAC__STREAM_DECODER_LENGTH_STATUS_OK",
  87358. "FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR",
  87359. "FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED"
  87360. };
  87361. FLAC_API const char * const FLAC__StreamDecoderWriteStatusString[] = {
  87362. "FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE",
  87363. "FLAC__STREAM_DECODER_WRITE_STATUS_ABORT"
  87364. };
  87365. FLAC_API const char * const FLAC__StreamDecoderErrorStatusString[] = {
  87366. "FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC",
  87367. "FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER",
  87368. "FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH",
  87369. "FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM"
  87370. };
  87371. FLAC_API FLAC__StreamDecoder *FLAC__stream_decoder_new(void)
  87372. {
  87373. FLAC__StreamDecoder *decoder;
  87374. unsigned i;
  87375. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  87376. decoder = (FLAC__StreamDecoder*)calloc(1, sizeof(FLAC__StreamDecoder));
  87377. if(decoder == 0) {
  87378. return 0;
  87379. }
  87380. decoder->protected_ = (FLAC__StreamDecoderProtected*)calloc(1, sizeof(FLAC__StreamDecoderProtected));
  87381. if(decoder->protected_ == 0) {
  87382. free(decoder);
  87383. return 0;
  87384. }
  87385. decoder->private_ = (FLAC__StreamDecoderPrivate*)calloc(1, sizeof(FLAC__StreamDecoderPrivate));
  87386. if(decoder->private_ == 0) {
  87387. free(decoder->protected_);
  87388. free(decoder);
  87389. return 0;
  87390. }
  87391. decoder->private_->input = FLAC__bitreader_new();
  87392. if(decoder->private_->input == 0) {
  87393. free(decoder->private_);
  87394. free(decoder->protected_);
  87395. free(decoder);
  87396. return 0;
  87397. }
  87398. decoder->private_->metadata_filter_ids_capacity = 16;
  87399. if(0 == (decoder->private_->metadata_filter_ids = (FLAC__byte*)malloc((FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) * decoder->private_->metadata_filter_ids_capacity))) {
  87400. FLAC__bitreader_delete(decoder->private_->input);
  87401. free(decoder->private_);
  87402. free(decoder->protected_);
  87403. free(decoder);
  87404. return 0;
  87405. }
  87406. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87407. decoder->private_->output[i] = 0;
  87408. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87409. }
  87410. decoder->private_->output_capacity = 0;
  87411. decoder->private_->output_channels = 0;
  87412. decoder->private_->has_seek_table = false;
  87413. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87414. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&decoder->private_->partitioned_rice_contents[i]);
  87415. decoder->private_->file = 0;
  87416. set_defaults_dec(decoder);
  87417. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87418. return decoder;
  87419. }
  87420. FLAC_API void FLAC__stream_decoder_delete(FLAC__StreamDecoder *decoder)
  87421. {
  87422. unsigned i;
  87423. FLAC__ASSERT(0 != decoder);
  87424. FLAC__ASSERT(0 != decoder->protected_);
  87425. FLAC__ASSERT(0 != decoder->private_);
  87426. FLAC__ASSERT(0 != decoder->private_->input);
  87427. (void)FLAC__stream_decoder_finish(decoder);
  87428. if(0 != decoder->private_->metadata_filter_ids)
  87429. free(decoder->private_->metadata_filter_ids);
  87430. FLAC__bitreader_delete(decoder->private_->input);
  87431. for(i = 0; i < FLAC__MAX_CHANNELS; i++)
  87432. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&decoder->private_->partitioned_rice_contents[i]);
  87433. free(decoder->private_);
  87434. free(decoder->protected_);
  87435. free(decoder);
  87436. }
  87437. static FLAC__StreamDecoderInitStatus init_stream_internal_dec(
  87438. FLAC__StreamDecoder *decoder,
  87439. FLAC__StreamDecoderReadCallback read_callback,
  87440. FLAC__StreamDecoderSeekCallback seek_callback,
  87441. FLAC__StreamDecoderTellCallback tell_callback,
  87442. FLAC__StreamDecoderLengthCallback length_callback,
  87443. FLAC__StreamDecoderEofCallback eof_callback,
  87444. FLAC__StreamDecoderWriteCallback write_callback,
  87445. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87446. FLAC__StreamDecoderErrorCallback error_callback,
  87447. void *client_data,
  87448. FLAC__bool is_ogg
  87449. )
  87450. {
  87451. FLAC__ASSERT(0 != decoder);
  87452. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87453. return FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED;
  87454. #if !FLAC__HAS_OGG
  87455. if(is_ogg)
  87456. return FLAC__STREAM_DECODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  87457. #endif
  87458. if(
  87459. 0 == read_callback ||
  87460. 0 == write_callback ||
  87461. 0 == error_callback ||
  87462. (seek_callback && (0 == tell_callback || 0 == length_callback || 0 == eof_callback))
  87463. )
  87464. return FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS;
  87465. #if FLAC__HAS_OGG
  87466. decoder->private_->is_ogg = is_ogg;
  87467. if(is_ogg && !FLAC__ogg_decoder_aspect_init(&decoder->protected_->ogg_decoder_aspect))
  87468. return decoder->protected_->state = FLAC__STREAM_DECODER_OGG_ERROR;
  87469. #endif
  87470. FLAC__cpu_info(&decoder->private_->cpuinfo);
  87471. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal;
  87472. decoder->private_->local_lpc_restore_signal_64bit = FLAC__lpc_restore_signal_wide;
  87473. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal;
  87474. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal;
  87475. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block;
  87476. #ifndef FLAC__NO_ASM
  87477. if(decoder->private_->cpuinfo.use_asm) {
  87478. #ifdef FLAC__CPU_IA32
  87479. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  87480. #ifdef FLAC__HAS_NASM
  87481. #if 1 /*@@@@@@ OPT: not clearly faster, needs more testing */
  87482. if(decoder->private_->cpuinfo.data.ia32.bswap)
  87483. decoder->private_->local_bitreader_read_rice_signed_block = FLAC__bitreader_read_rice_signed_block_asm_ia32_bswap;
  87484. #endif
  87485. if(decoder->private_->cpuinfo.data.ia32.mmx) {
  87486. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87487. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87488. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32_mmx;
  87489. }
  87490. else {
  87491. decoder->private_->local_lpc_restore_signal = FLAC__lpc_restore_signal_asm_ia32;
  87492. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ia32;
  87493. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ia32;
  87494. }
  87495. #endif
  87496. #elif defined FLAC__CPU_PPC
  87497. FLAC__ASSERT(decoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_PPC);
  87498. if(decoder->private_->cpuinfo.data.ppc.altivec) {
  87499. decoder->private_->local_lpc_restore_signal_16bit = FLAC__lpc_restore_signal_asm_ppc_altivec_16;
  87500. decoder->private_->local_lpc_restore_signal_16bit_order8 = FLAC__lpc_restore_signal_asm_ppc_altivec_16_order8;
  87501. }
  87502. #endif
  87503. }
  87504. #endif
  87505. if(!FLAC__bitreader_init(decoder->private_->input, decoder->private_->cpuinfo, read_callback_, decoder)) {
  87506. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87507. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87508. }
  87509. decoder->private_->read_callback = read_callback;
  87510. decoder->private_->seek_callback = seek_callback;
  87511. decoder->private_->tell_callback = tell_callback;
  87512. decoder->private_->length_callback = length_callback;
  87513. decoder->private_->eof_callback = eof_callback;
  87514. decoder->private_->write_callback = write_callback;
  87515. decoder->private_->metadata_callback = metadata_callback;
  87516. decoder->private_->error_callback = error_callback;
  87517. decoder->private_->client_data = client_data;
  87518. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87519. decoder->private_->samples_decoded = 0;
  87520. decoder->private_->has_stream_info = false;
  87521. decoder->private_->cached = false;
  87522. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87523. decoder->private_->is_seeking = false;
  87524. decoder->private_->internal_reset_hack = true; /* so the following reset does not try to rewind the input */
  87525. if(!FLAC__stream_decoder_reset(decoder)) {
  87526. return FLAC__STREAM_DECODER_INIT_STATUS_MEMORY_ALLOCATION_ERROR;
  87527. }
  87528. return FLAC__STREAM_DECODER_INIT_STATUS_OK;
  87529. }
  87530. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_stream(
  87531. FLAC__StreamDecoder *decoder,
  87532. FLAC__StreamDecoderReadCallback read_callback,
  87533. FLAC__StreamDecoderSeekCallback seek_callback,
  87534. FLAC__StreamDecoderTellCallback tell_callback,
  87535. FLAC__StreamDecoderLengthCallback length_callback,
  87536. FLAC__StreamDecoderEofCallback eof_callback,
  87537. FLAC__StreamDecoderWriteCallback write_callback,
  87538. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87539. FLAC__StreamDecoderErrorCallback error_callback,
  87540. void *client_data
  87541. )
  87542. {
  87543. return init_stream_internal_dec(
  87544. decoder,
  87545. read_callback,
  87546. seek_callback,
  87547. tell_callback,
  87548. length_callback,
  87549. eof_callback,
  87550. write_callback,
  87551. metadata_callback,
  87552. error_callback,
  87553. client_data,
  87554. false
  87555. );
  87556. }
  87557. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_stream(
  87558. FLAC__StreamDecoder *decoder,
  87559. FLAC__StreamDecoderReadCallback read_callback,
  87560. FLAC__StreamDecoderSeekCallback seek_callback,
  87561. FLAC__StreamDecoderTellCallback tell_callback,
  87562. FLAC__StreamDecoderLengthCallback length_callback,
  87563. FLAC__StreamDecoderEofCallback eof_callback,
  87564. FLAC__StreamDecoderWriteCallback write_callback,
  87565. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87566. FLAC__StreamDecoderErrorCallback error_callback,
  87567. void *client_data
  87568. )
  87569. {
  87570. return init_stream_internal_dec(
  87571. decoder,
  87572. read_callback,
  87573. seek_callback,
  87574. tell_callback,
  87575. length_callback,
  87576. eof_callback,
  87577. write_callback,
  87578. metadata_callback,
  87579. error_callback,
  87580. client_data,
  87581. true
  87582. );
  87583. }
  87584. static FLAC__StreamDecoderInitStatus init_FILE_internal_(
  87585. FLAC__StreamDecoder *decoder,
  87586. FILE *file,
  87587. FLAC__StreamDecoderWriteCallback write_callback,
  87588. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87589. FLAC__StreamDecoderErrorCallback error_callback,
  87590. void *client_data,
  87591. FLAC__bool is_ogg
  87592. )
  87593. {
  87594. FLAC__ASSERT(0 != decoder);
  87595. FLAC__ASSERT(0 != file);
  87596. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87597. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87598. if(0 == write_callback || 0 == error_callback)
  87599. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87600. if(file == stdin)
  87601. file = get_binary_stdin_(); /* just to be safe */
  87602. decoder->private_->file = file;
  87603. return init_stream_internal_dec(
  87604. decoder,
  87605. file_read_callback_dec,
  87606. decoder->private_->file == stdin? 0: file_seek_callback_dec,
  87607. decoder->private_->file == stdin? 0: file_tell_callback_dec,
  87608. decoder->private_->file == stdin? 0: file_length_callback_,
  87609. file_eof_callback_,
  87610. write_callback,
  87611. metadata_callback,
  87612. error_callback,
  87613. client_data,
  87614. is_ogg
  87615. );
  87616. }
  87617. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_FILE(
  87618. FLAC__StreamDecoder *decoder,
  87619. FILE *file,
  87620. FLAC__StreamDecoderWriteCallback write_callback,
  87621. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87622. FLAC__StreamDecoderErrorCallback error_callback,
  87623. void *client_data
  87624. )
  87625. {
  87626. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87627. }
  87628. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_FILE(
  87629. FLAC__StreamDecoder *decoder,
  87630. FILE *file,
  87631. FLAC__StreamDecoderWriteCallback write_callback,
  87632. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87633. FLAC__StreamDecoderErrorCallback error_callback,
  87634. void *client_data
  87635. )
  87636. {
  87637. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87638. }
  87639. static FLAC__StreamDecoderInitStatus init_file_internal_(
  87640. FLAC__StreamDecoder *decoder,
  87641. const char *filename,
  87642. FLAC__StreamDecoderWriteCallback write_callback,
  87643. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87644. FLAC__StreamDecoderErrorCallback error_callback,
  87645. void *client_data,
  87646. FLAC__bool is_ogg
  87647. )
  87648. {
  87649. FILE *file;
  87650. FLAC__ASSERT(0 != decoder);
  87651. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87652. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_ALREADY_INITIALIZED);
  87653. if(0 == write_callback || 0 == error_callback)
  87654. return (FLAC__StreamDecoderInitStatus) (decoder->protected_->state = (FLAC__StreamDecoderState) FLAC__STREAM_DECODER_INIT_STATUS_INVALID_CALLBACKS);
  87655. file = filename? fopen(filename, "rb") : stdin;
  87656. if(0 == file)
  87657. return FLAC__STREAM_DECODER_INIT_STATUS_ERROR_OPENING_FILE;
  87658. return init_FILE_internal_(decoder, file, write_callback, metadata_callback, error_callback, client_data, is_ogg);
  87659. }
  87660. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_file(
  87661. FLAC__StreamDecoder *decoder,
  87662. const char *filename,
  87663. FLAC__StreamDecoderWriteCallback write_callback,
  87664. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87665. FLAC__StreamDecoderErrorCallback error_callback,
  87666. void *client_data
  87667. )
  87668. {
  87669. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/false);
  87670. }
  87671. FLAC_API FLAC__StreamDecoderInitStatus FLAC__stream_decoder_init_ogg_file(
  87672. FLAC__StreamDecoder *decoder,
  87673. const char *filename,
  87674. FLAC__StreamDecoderWriteCallback write_callback,
  87675. FLAC__StreamDecoderMetadataCallback metadata_callback,
  87676. FLAC__StreamDecoderErrorCallback error_callback,
  87677. void *client_data
  87678. )
  87679. {
  87680. return init_file_internal_(decoder, filename, write_callback, metadata_callback, error_callback, client_data, /*is_ogg=*/true);
  87681. }
  87682. FLAC_API FLAC__bool FLAC__stream_decoder_finish(FLAC__StreamDecoder *decoder)
  87683. {
  87684. FLAC__bool md5_failed = false;
  87685. unsigned i;
  87686. FLAC__ASSERT(0 != decoder);
  87687. FLAC__ASSERT(0 != decoder->private_);
  87688. FLAC__ASSERT(0 != decoder->protected_);
  87689. if(decoder->protected_->state == FLAC__STREAM_DECODER_UNINITIALIZED)
  87690. return true;
  87691. FLAC__MD5Final(decoder->private_->computed_md5sum, &decoder->private_->md5context);
  87692. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87693. free(decoder->private_->seek_table.data.seek_table.points);
  87694. decoder->private_->seek_table.data.seek_table.points = 0;
  87695. decoder->private_->has_seek_table = false;
  87696. }
  87697. FLAC__bitreader_free(decoder->private_->input);
  87698. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  87699. if(0 != decoder->private_->output[i]) {
  87700. free(decoder->private_->output[i]-4);
  87701. decoder->private_->output[i] = 0;
  87702. }
  87703. if(0 != decoder->private_->residual_unaligned[i]) {
  87704. free(decoder->private_->residual_unaligned[i]);
  87705. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  87706. }
  87707. }
  87708. decoder->private_->output_capacity = 0;
  87709. decoder->private_->output_channels = 0;
  87710. #if FLAC__HAS_OGG
  87711. if(decoder->private_->is_ogg)
  87712. FLAC__ogg_decoder_aspect_finish(&decoder->protected_->ogg_decoder_aspect);
  87713. #endif
  87714. if(0 != decoder->private_->file) {
  87715. if(decoder->private_->file != stdin)
  87716. fclose(decoder->private_->file);
  87717. decoder->private_->file = 0;
  87718. }
  87719. if(decoder->private_->do_md5_checking) {
  87720. if(memcmp(decoder->private_->stream_info.data.stream_info.md5sum, decoder->private_->computed_md5sum, 16))
  87721. md5_failed = true;
  87722. }
  87723. decoder->private_->is_seeking = false;
  87724. set_defaults_dec(decoder);
  87725. decoder->protected_->state = FLAC__STREAM_DECODER_UNINITIALIZED;
  87726. return !md5_failed;
  87727. }
  87728. FLAC_API FLAC__bool FLAC__stream_decoder_set_ogg_serial_number(FLAC__StreamDecoder *decoder, long value)
  87729. {
  87730. FLAC__ASSERT(0 != decoder);
  87731. FLAC__ASSERT(0 != decoder->private_);
  87732. FLAC__ASSERT(0 != decoder->protected_);
  87733. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87734. return false;
  87735. #if FLAC__HAS_OGG
  87736. FLAC__ogg_decoder_aspect_set_serial_number(&decoder->protected_->ogg_decoder_aspect, value);
  87737. return true;
  87738. #else
  87739. (void)value;
  87740. return false;
  87741. #endif
  87742. }
  87743. FLAC_API FLAC__bool FLAC__stream_decoder_set_md5_checking(FLAC__StreamDecoder *decoder, FLAC__bool value)
  87744. {
  87745. FLAC__ASSERT(0 != decoder);
  87746. FLAC__ASSERT(0 != decoder->protected_);
  87747. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87748. return false;
  87749. decoder->protected_->md5_checking = value;
  87750. return true;
  87751. }
  87752. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87753. {
  87754. FLAC__ASSERT(0 != decoder);
  87755. FLAC__ASSERT(0 != decoder->private_);
  87756. FLAC__ASSERT(0 != decoder->protected_);
  87757. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87758. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87759. return false;
  87760. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87761. return false;
  87762. decoder->private_->metadata_filter[type] = true;
  87763. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87764. decoder->private_->metadata_filter_ids_count = 0;
  87765. return true;
  87766. }
  87767. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87768. {
  87769. FLAC__ASSERT(0 != decoder);
  87770. FLAC__ASSERT(0 != decoder->private_);
  87771. FLAC__ASSERT(0 != decoder->protected_);
  87772. FLAC__ASSERT(0 != id);
  87773. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87774. return false;
  87775. if(decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87776. return true;
  87777. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87778. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87779. 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))) {
  87780. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87781. return false;
  87782. }
  87783. decoder->private_->metadata_filter_ids_capacity *= 2;
  87784. }
  87785. 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));
  87786. decoder->private_->metadata_filter_ids_count++;
  87787. return true;
  87788. }
  87789. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_respond_all(FLAC__StreamDecoder *decoder)
  87790. {
  87791. unsigned i;
  87792. FLAC__ASSERT(0 != decoder);
  87793. FLAC__ASSERT(0 != decoder->private_);
  87794. FLAC__ASSERT(0 != decoder->protected_);
  87795. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87796. return false;
  87797. for(i = 0; i < sizeof(decoder->private_->metadata_filter) / sizeof(decoder->private_->metadata_filter[0]); i++)
  87798. decoder->private_->metadata_filter[i] = true;
  87799. decoder->private_->metadata_filter_ids_count = 0;
  87800. return true;
  87801. }
  87802. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore(FLAC__StreamDecoder *decoder, FLAC__MetadataType type)
  87803. {
  87804. FLAC__ASSERT(0 != decoder);
  87805. FLAC__ASSERT(0 != decoder->private_);
  87806. FLAC__ASSERT(0 != decoder->protected_);
  87807. FLAC__ASSERT((unsigned)type <= FLAC__MAX_METADATA_TYPE_CODE);
  87808. if((unsigned)type > FLAC__MAX_METADATA_TYPE_CODE)
  87809. return false;
  87810. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87811. return false;
  87812. decoder->private_->metadata_filter[type] = false;
  87813. if(type == FLAC__METADATA_TYPE_APPLICATION)
  87814. decoder->private_->metadata_filter_ids_count = 0;
  87815. return true;
  87816. }
  87817. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_application(FLAC__StreamDecoder *decoder, const FLAC__byte id[4])
  87818. {
  87819. FLAC__ASSERT(0 != decoder);
  87820. FLAC__ASSERT(0 != decoder->private_);
  87821. FLAC__ASSERT(0 != decoder->protected_);
  87822. FLAC__ASSERT(0 != id);
  87823. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87824. return false;
  87825. if(!decoder->private_->metadata_filter[FLAC__METADATA_TYPE_APPLICATION])
  87826. return true;
  87827. FLAC__ASSERT(0 != decoder->private_->metadata_filter_ids);
  87828. if(decoder->private_->metadata_filter_ids_count == decoder->private_->metadata_filter_ids_capacity) {
  87829. 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))) {
  87830. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87831. return false;
  87832. }
  87833. decoder->private_->metadata_filter_ids_capacity *= 2;
  87834. }
  87835. 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));
  87836. decoder->private_->metadata_filter_ids_count++;
  87837. return true;
  87838. }
  87839. FLAC_API FLAC__bool FLAC__stream_decoder_set_metadata_ignore_all(FLAC__StreamDecoder *decoder)
  87840. {
  87841. FLAC__ASSERT(0 != decoder);
  87842. FLAC__ASSERT(0 != decoder->private_);
  87843. FLAC__ASSERT(0 != decoder->protected_);
  87844. if(decoder->protected_->state != FLAC__STREAM_DECODER_UNINITIALIZED)
  87845. return false;
  87846. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  87847. decoder->private_->metadata_filter_ids_count = 0;
  87848. return true;
  87849. }
  87850. FLAC_API FLAC__StreamDecoderState FLAC__stream_decoder_get_state(const FLAC__StreamDecoder *decoder)
  87851. {
  87852. FLAC__ASSERT(0 != decoder);
  87853. FLAC__ASSERT(0 != decoder->protected_);
  87854. return decoder->protected_->state;
  87855. }
  87856. FLAC_API const char *FLAC__stream_decoder_get_resolved_state_string(const FLAC__StreamDecoder *decoder)
  87857. {
  87858. return FLAC__StreamDecoderStateString[decoder->protected_->state];
  87859. }
  87860. FLAC_API FLAC__bool FLAC__stream_decoder_get_md5_checking(const FLAC__StreamDecoder *decoder)
  87861. {
  87862. FLAC__ASSERT(0 != decoder);
  87863. FLAC__ASSERT(0 != decoder->protected_);
  87864. return decoder->protected_->md5_checking;
  87865. }
  87866. FLAC_API FLAC__uint64 FLAC__stream_decoder_get_total_samples(const FLAC__StreamDecoder *decoder)
  87867. {
  87868. FLAC__ASSERT(0 != decoder);
  87869. FLAC__ASSERT(0 != decoder->protected_);
  87870. return decoder->private_->has_stream_info? decoder->private_->stream_info.data.stream_info.total_samples : 0;
  87871. }
  87872. FLAC_API unsigned FLAC__stream_decoder_get_channels(const FLAC__StreamDecoder *decoder)
  87873. {
  87874. FLAC__ASSERT(0 != decoder);
  87875. FLAC__ASSERT(0 != decoder->protected_);
  87876. return decoder->protected_->channels;
  87877. }
  87878. FLAC_API FLAC__ChannelAssignment FLAC__stream_decoder_get_channel_assignment(const FLAC__StreamDecoder *decoder)
  87879. {
  87880. FLAC__ASSERT(0 != decoder);
  87881. FLAC__ASSERT(0 != decoder->protected_);
  87882. return decoder->protected_->channel_assignment;
  87883. }
  87884. FLAC_API unsigned FLAC__stream_decoder_get_bits_per_sample(const FLAC__StreamDecoder *decoder)
  87885. {
  87886. FLAC__ASSERT(0 != decoder);
  87887. FLAC__ASSERT(0 != decoder->protected_);
  87888. return decoder->protected_->bits_per_sample;
  87889. }
  87890. FLAC_API unsigned FLAC__stream_decoder_get_sample_rate(const FLAC__StreamDecoder *decoder)
  87891. {
  87892. FLAC__ASSERT(0 != decoder);
  87893. FLAC__ASSERT(0 != decoder->protected_);
  87894. return decoder->protected_->sample_rate;
  87895. }
  87896. FLAC_API unsigned FLAC__stream_decoder_get_blocksize(const FLAC__StreamDecoder *decoder)
  87897. {
  87898. FLAC__ASSERT(0 != decoder);
  87899. FLAC__ASSERT(0 != decoder->protected_);
  87900. return decoder->protected_->blocksize;
  87901. }
  87902. FLAC_API FLAC__bool FLAC__stream_decoder_get_decode_position(const FLAC__StreamDecoder *decoder, FLAC__uint64 *position)
  87903. {
  87904. FLAC__ASSERT(0 != decoder);
  87905. FLAC__ASSERT(0 != decoder->private_);
  87906. FLAC__ASSERT(0 != position);
  87907. #if FLAC__HAS_OGG
  87908. if(decoder->private_->is_ogg)
  87909. return false;
  87910. #endif
  87911. if(0 == decoder->private_->tell_callback)
  87912. return false;
  87913. if(decoder->private_->tell_callback(decoder, position, decoder->private_->client_data) != FLAC__STREAM_DECODER_TELL_STATUS_OK)
  87914. return false;
  87915. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input))
  87916. return false;
  87917. FLAC__ASSERT(*position >= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder));
  87918. *position -= FLAC__stream_decoder_get_input_bytes_unconsumed(decoder);
  87919. return true;
  87920. }
  87921. FLAC_API FLAC__bool FLAC__stream_decoder_flush(FLAC__StreamDecoder *decoder)
  87922. {
  87923. FLAC__ASSERT(0 != decoder);
  87924. FLAC__ASSERT(0 != decoder->private_);
  87925. FLAC__ASSERT(0 != decoder->protected_);
  87926. decoder->private_->samples_decoded = 0;
  87927. decoder->private_->do_md5_checking = false;
  87928. #if FLAC__HAS_OGG
  87929. if(decoder->private_->is_ogg)
  87930. FLAC__ogg_decoder_aspect_flush(&decoder->protected_->ogg_decoder_aspect);
  87931. #endif
  87932. if(!FLAC__bitreader_clear(decoder->private_->input)) {
  87933. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  87934. return false;
  87935. }
  87936. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  87937. return true;
  87938. }
  87939. FLAC_API FLAC__bool FLAC__stream_decoder_reset(FLAC__StreamDecoder *decoder)
  87940. {
  87941. FLAC__ASSERT(0 != decoder);
  87942. FLAC__ASSERT(0 != decoder->private_);
  87943. FLAC__ASSERT(0 != decoder->protected_);
  87944. if(!FLAC__stream_decoder_flush(decoder)) {
  87945. return false;
  87946. }
  87947. #if FLAC__HAS_OGG
  87948. if(decoder->private_->is_ogg)
  87949. FLAC__ogg_decoder_aspect_reset(&decoder->protected_->ogg_decoder_aspect);
  87950. #endif
  87951. if(!decoder->private_->internal_reset_hack) {
  87952. if(decoder->private_->file == stdin)
  87953. return false; /* can't rewind stdin, reset fails */
  87954. if(decoder->private_->seek_callback && decoder->private_->seek_callback(decoder, 0, decoder->private_->client_data) == FLAC__STREAM_DECODER_SEEK_STATUS_ERROR)
  87955. return false; /* seekable and seek fails, reset fails */
  87956. }
  87957. else
  87958. decoder->private_->internal_reset_hack = false;
  87959. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_METADATA;
  87960. decoder->private_->has_stream_info = false;
  87961. if(decoder->private_->has_seek_table && 0 != decoder->private_->seek_table.data.seek_table.points) {
  87962. free(decoder->private_->seek_table.data.seek_table.points);
  87963. decoder->private_->seek_table.data.seek_table.points = 0;
  87964. decoder->private_->has_seek_table = false;
  87965. }
  87966. decoder->private_->do_md5_checking = decoder->protected_->md5_checking;
  87967. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size = 0;
  87968. FLAC__MD5Init(&decoder->private_->md5context);
  87969. decoder->private_->first_frame_offset = 0;
  87970. decoder->private_->unparseable_frame_count = 0;
  87971. return true;
  87972. }
  87973. FLAC_API FLAC__bool FLAC__stream_decoder_process_single(FLAC__StreamDecoder *decoder)
  87974. {
  87975. FLAC__bool got_a_frame;
  87976. FLAC__ASSERT(0 != decoder);
  87977. FLAC__ASSERT(0 != decoder->protected_);
  87978. while(1) {
  87979. switch(decoder->protected_->state) {
  87980. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  87981. if(!find_metadata_(decoder))
  87982. return false; /* above function sets the status for us */
  87983. break;
  87984. case FLAC__STREAM_DECODER_READ_METADATA:
  87985. if(!read_metadata_(decoder))
  87986. return false; /* above function sets the status for us */
  87987. else
  87988. return true;
  87989. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  87990. if(!frame_sync_(decoder))
  87991. return true; /* above function sets the status for us */
  87992. break;
  87993. case FLAC__STREAM_DECODER_READ_FRAME:
  87994. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/true))
  87995. return false; /* above function sets the status for us */
  87996. if(got_a_frame)
  87997. return true; /* above function sets the status for us */
  87998. break;
  87999. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88000. case FLAC__STREAM_DECODER_ABORTED:
  88001. return true;
  88002. default:
  88003. FLAC__ASSERT(0);
  88004. return false;
  88005. }
  88006. }
  88007. }
  88008. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_metadata(FLAC__StreamDecoder *decoder)
  88009. {
  88010. FLAC__ASSERT(0 != decoder);
  88011. FLAC__ASSERT(0 != decoder->protected_);
  88012. while(1) {
  88013. switch(decoder->protected_->state) {
  88014. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88015. if(!find_metadata_(decoder))
  88016. return false; /* above function sets the status for us */
  88017. break;
  88018. case FLAC__STREAM_DECODER_READ_METADATA:
  88019. if(!read_metadata_(decoder))
  88020. return false; /* above function sets the status for us */
  88021. break;
  88022. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88023. case FLAC__STREAM_DECODER_READ_FRAME:
  88024. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88025. case FLAC__STREAM_DECODER_ABORTED:
  88026. return true;
  88027. default:
  88028. FLAC__ASSERT(0);
  88029. return false;
  88030. }
  88031. }
  88032. }
  88033. FLAC_API FLAC__bool FLAC__stream_decoder_process_until_end_of_stream(FLAC__StreamDecoder *decoder)
  88034. {
  88035. FLAC__bool dummy;
  88036. FLAC__ASSERT(0 != decoder);
  88037. FLAC__ASSERT(0 != decoder->protected_);
  88038. while(1) {
  88039. switch(decoder->protected_->state) {
  88040. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88041. if(!find_metadata_(decoder))
  88042. return false; /* above function sets the status for us */
  88043. break;
  88044. case FLAC__STREAM_DECODER_READ_METADATA:
  88045. if(!read_metadata_(decoder))
  88046. return false; /* above function sets the status for us */
  88047. break;
  88048. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88049. if(!frame_sync_(decoder))
  88050. return true; /* above function sets the status for us */
  88051. break;
  88052. case FLAC__STREAM_DECODER_READ_FRAME:
  88053. if(!read_frame_(decoder, &dummy, /*do_full_decode=*/true))
  88054. return false; /* above function sets the status for us */
  88055. break;
  88056. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88057. case FLAC__STREAM_DECODER_ABORTED:
  88058. return true;
  88059. default:
  88060. FLAC__ASSERT(0);
  88061. return false;
  88062. }
  88063. }
  88064. }
  88065. FLAC_API FLAC__bool FLAC__stream_decoder_skip_single_frame(FLAC__StreamDecoder *decoder)
  88066. {
  88067. FLAC__bool got_a_frame;
  88068. FLAC__ASSERT(0 != decoder);
  88069. FLAC__ASSERT(0 != decoder->protected_);
  88070. while(1) {
  88071. switch(decoder->protected_->state) {
  88072. case FLAC__STREAM_DECODER_SEARCH_FOR_METADATA:
  88073. case FLAC__STREAM_DECODER_READ_METADATA:
  88074. return false; /* above function sets the status for us */
  88075. case FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC:
  88076. if(!frame_sync_(decoder))
  88077. return true; /* above function sets the status for us */
  88078. break;
  88079. case FLAC__STREAM_DECODER_READ_FRAME:
  88080. if(!read_frame_(decoder, &got_a_frame, /*do_full_decode=*/false))
  88081. return false; /* above function sets the status for us */
  88082. if(got_a_frame)
  88083. return true; /* above function sets the status for us */
  88084. break;
  88085. case FLAC__STREAM_DECODER_END_OF_STREAM:
  88086. case FLAC__STREAM_DECODER_ABORTED:
  88087. return true;
  88088. default:
  88089. FLAC__ASSERT(0);
  88090. return false;
  88091. }
  88092. }
  88093. }
  88094. FLAC_API FLAC__bool FLAC__stream_decoder_seek_absolute(FLAC__StreamDecoder *decoder, FLAC__uint64 sample)
  88095. {
  88096. FLAC__uint64 length;
  88097. FLAC__ASSERT(0 != decoder);
  88098. if(
  88099. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_METADATA &&
  88100. decoder->protected_->state != FLAC__STREAM_DECODER_READ_METADATA &&
  88101. decoder->protected_->state != FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC &&
  88102. decoder->protected_->state != FLAC__STREAM_DECODER_READ_FRAME &&
  88103. decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM
  88104. )
  88105. return false;
  88106. if(0 == decoder->private_->seek_callback)
  88107. return false;
  88108. FLAC__ASSERT(decoder->private_->seek_callback);
  88109. FLAC__ASSERT(decoder->private_->tell_callback);
  88110. FLAC__ASSERT(decoder->private_->length_callback);
  88111. FLAC__ASSERT(decoder->private_->eof_callback);
  88112. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder))
  88113. return false;
  88114. decoder->private_->is_seeking = true;
  88115. decoder->private_->do_md5_checking = false;
  88116. if(decoder->private_->length_callback(decoder, &length, decoder->private_->client_data) != FLAC__STREAM_DECODER_LENGTH_STATUS_OK) {
  88117. decoder->private_->is_seeking = false;
  88118. return false;
  88119. }
  88120. if(
  88121. decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_METADATA ||
  88122. decoder->protected_->state == FLAC__STREAM_DECODER_READ_METADATA
  88123. ) {
  88124. if(!FLAC__stream_decoder_process_until_end_of_metadata(decoder)) {
  88125. decoder->private_->is_seeking = false;
  88126. return false;
  88127. }
  88128. if(FLAC__stream_decoder_get_total_samples(decoder) > 0 && sample >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88129. decoder->private_->is_seeking = false;
  88130. return false;
  88131. }
  88132. }
  88133. {
  88134. const FLAC__bool ok =
  88135. #if FLAC__HAS_OGG
  88136. decoder->private_->is_ogg?
  88137. seek_to_absolute_sample_ogg_(decoder, length, sample) :
  88138. #endif
  88139. seek_to_absolute_sample_(decoder, length, sample)
  88140. ;
  88141. decoder->private_->is_seeking = false;
  88142. return ok;
  88143. }
  88144. }
  88145. unsigned FLAC__stream_decoder_get_input_bytes_unconsumed(const FLAC__StreamDecoder *decoder)
  88146. {
  88147. FLAC__ASSERT(0 != decoder);
  88148. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88149. FLAC__ASSERT(!(FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) & 7));
  88150. return FLAC__bitreader_get_input_bits_unconsumed(decoder->private_->input) / 8;
  88151. }
  88152. void set_defaults_dec(FLAC__StreamDecoder *decoder)
  88153. {
  88154. #if FLAC__HAS_OGG
  88155. decoder->private_->is_ogg = false;
  88156. #endif
  88157. decoder->private_->read_callback = 0;
  88158. decoder->private_->seek_callback = 0;
  88159. decoder->private_->tell_callback = 0;
  88160. decoder->private_->length_callback = 0;
  88161. decoder->private_->eof_callback = 0;
  88162. decoder->private_->write_callback = 0;
  88163. decoder->private_->metadata_callback = 0;
  88164. decoder->private_->error_callback = 0;
  88165. decoder->private_->client_data = 0;
  88166. memset(decoder->private_->metadata_filter, 0, sizeof(decoder->private_->metadata_filter));
  88167. decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] = true;
  88168. decoder->private_->metadata_filter_ids_count = 0;
  88169. decoder->protected_->md5_checking = false;
  88170. #if FLAC__HAS_OGG
  88171. FLAC__ogg_decoder_aspect_set_defaults(&decoder->protected_->ogg_decoder_aspect);
  88172. #endif
  88173. }
  88174. FILE *get_binary_stdin_(void)
  88175. {
  88176. #if defined _MSC_VER || defined __MINGW32__
  88177. _setmode(_fileno(stdin), _O_BINARY);
  88178. #elif defined __CYGWIN__
  88179. setmode(_fileno(stdin), _O_BINARY);
  88180. #elif defined __EMX__
  88181. setmode(fileno(stdin), O_BINARY);
  88182. #endif
  88183. return stdin;
  88184. }
  88185. FLAC__bool allocate_output_(FLAC__StreamDecoder *decoder, unsigned size, unsigned channels)
  88186. {
  88187. unsigned i;
  88188. FLAC__int32 *tmp;
  88189. if(size <= decoder->private_->output_capacity && channels <= decoder->private_->output_channels)
  88190. return true;
  88191. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  88192. if(0 != decoder->private_->output[i]) {
  88193. free(decoder->private_->output[i]-4);
  88194. decoder->private_->output[i] = 0;
  88195. }
  88196. if(0 != decoder->private_->residual_unaligned[i]) {
  88197. free(decoder->private_->residual_unaligned[i]);
  88198. decoder->private_->residual_unaligned[i] = decoder->private_->residual[i] = 0;
  88199. }
  88200. }
  88201. for(i = 0; i < channels; i++) {
  88202. tmp = (FLAC__int32*)safe_malloc_muladd2_(sizeof(FLAC__int32), /*times (*/size, /*+*/4/*)*/);
  88203. if(tmp == 0) {
  88204. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88205. return false;
  88206. }
  88207. memset(tmp, 0, sizeof(FLAC__int32)*4);
  88208. decoder->private_->output[i] = tmp + 4;
  88209. if(!FLAC__memory_alloc_aligned_int32_array(size, &decoder->private_->residual_unaligned[i], &decoder->private_->residual[i])) {
  88210. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88211. return false;
  88212. }
  88213. }
  88214. decoder->private_->output_capacity = size;
  88215. decoder->private_->output_channels = channels;
  88216. return true;
  88217. }
  88218. FLAC__bool has_id_filtered_(FLAC__StreamDecoder *decoder, FLAC__byte *id)
  88219. {
  88220. size_t i;
  88221. FLAC__ASSERT(0 != decoder);
  88222. FLAC__ASSERT(0 != decoder->private_);
  88223. for(i = 0; i < decoder->private_->metadata_filter_ids_count; i++)
  88224. if(0 == memcmp(decoder->private_->metadata_filter_ids + i * (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8), id, (FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8)))
  88225. return true;
  88226. return false;
  88227. }
  88228. FLAC__bool find_metadata_(FLAC__StreamDecoder *decoder)
  88229. {
  88230. FLAC__uint32 x;
  88231. unsigned i, id_;
  88232. FLAC__bool first = true;
  88233. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88234. for(i = id_ = 0; i < 4; ) {
  88235. if(decoder->private_->cached) {
  88236. x = (FLAC__uint32)decoder->private_->lookahead;
  88237. decoder->private_->cached = false;
  88238. }
  88239. else {
  88240. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88241. return false; /* read_callback_ sets the state for us */
  88242. }
  88243. if(x == FLAC__STREAM_SYNC_STRING[i]) {
  88244. first = true;
  88245. i++;
  88246. id_ = 0;
  88247. continue;
  88248. }
  88249. if(x == ID3V2_TAG_[id_]) {
  88250. id_++;
  88251. i = 0;
  88252. if(id_ == 3) {
  88253. if(!skip_id3v2_tag_(decoder))
  88254. return false; /* skip_id3v2_tag_ sets the state for us */
  88255. }
  88256. continue;
  88257. }
  88258. id_ = 0;
  88259. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88260. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88261. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88262. return false; /* read_callback_ sets the state for us */
  88263. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88264. decoder->private_->lookahead = (FLAC__byte)x;
  88265. decoder->private_->cached = true;
  88266. }
  88267. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88268. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88269. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88270. return true;
  88271. }
  88272. }
  88273. i = 0;
  88274. if(first) {
  88275. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88276. first = false;
  88277. }
  88278. }
  88279. decoder->protected_->state = FLAC__STREAM_DECODER_READ_METADATA;
  88280. return true;
  88281. }
  88282. FLAC__bool read_metadata_(FLAC__StreamDecoder *decoder)
  88283. {
  88284. FLAC__bool is_last;
  88285. FLAC__uint32 i, x, type, length;
  88286. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88287. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_IS_LAST_LEN))
  88288. return false; /* read_callback_ sets the state for us */
  88289. is_last = x? true : false;
  88290. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &type, FLAC__STREAM_METADATA_TYPE_LEN))
  88291. return false; /* read_callback_ sets the state for us */
  88292. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &length, FLAC__STREAM_METADATA_LENGTH_LEN))
  88293. return false; /* read_callback_ sets the state for us */
  88294. if(type == FLAC__METADATA_TYPE_STREAMINFO) {
  88295. if(!read_metadata_streaminfo_(decoder, is_last, length))
  88296. return false;
  88297. decoder->private_->has_stream_info = true;
  88298. 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))
  88299. decoder->private_->do_md5_checking = false;
  88300. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_STREAMINFO] && decoder->private_->metadata_callback)
  88301. decoder->private_->metadata_callback(decoder, &decoder->private_->stream_info, decoder->private_->client_data);
  88302. }
  88303. else if(type == FLAC__METADATA_TYPE_SEEKTABLE) {
  88304. if(!read_metadata_seektable_(decoder, is_last, length))
  88305. return false;
  88306. decoder->private_->has_seek_table = true;
  88307. if(!decoder->private_->is_seeking && decoder->private_->metadata_filter[FLAC__METADATA_TYPE_SEEKTABLE] && decoder->private_->metadata_callback)
  88308. decoder->private_->metadata_callback(decoder, &decoder->private_->seek_table, decoder->private_->client_data);
  88309. }
  88310. else {
  88311. FLAC__bool skip_it = !decoder->private_->metadata_filter[type];
  88312. unsigned real_length = length;
  88313. FLAC__StreamMetadata block;
  88314. block.is_last = is_last;
  88315. block.type = (FLAC__MetadataType)type;
  88316. block.length = length;
  88317. if(type == FLAC__METADATA_TYPE_APPLICATION) {
  88318. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8))
  88319. return false; /* read_callback_ sets the state for us */
  88320. if(real_length < FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8) { /* underflow check */
  88321. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;/*@@@@@@ maybe wrong error? need to resync?*/
  88322. return false;
  88323. }
  88324. real_length -= FLAC__STREAM_METADATA_APPLICATION_ID_LEN/8;
  88325. if(decoder->private_->metadata_filter_ids_count > 0 && has_id_filtered_(decoder, block.data.application.id))
  88326. skip_it = !skip_it;
  88327. }
  88328. if(skip_it) {
  88329. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88330. return false; /* read_callback_ sets the state for us */
  88331. }
  88332. else {
  88333. switch(type) {
  88334. case FLAC__METADATA_TYPE_PADDING:
  88335. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, real_length))
  88336. return false; /* read_callback_ sets the state for us */
  88337. break;
  88338. case FLAC__METADATA_TYPE_APPLICATION:
  88339. if(real_length > 0) {
  88340. if(0 == (block.data.application.data = (FLAC__byte*)malloc(real_length))) {
  88341. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88342. return false;
  88343. }
  88344. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.application.data, real_length))
  88345. return false; /* read_callback_ sets the state for us */
  88346. }
  88347. else
  88348. block.data.application.data = 0;
  88349. break;
  88350. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88351. if(!read_metadata_vorbiscomment_(decoder, &block.data.vorbis_comment))
  88352. return false;
  88353. break;
  88354. case FLAC__METADATA_TYPE_CUESHEET:
  88355. if(!read_metadata_cuesheet_(decoder, &block.data.cue_sheet))
  88356. return false;
  88357. break;
  88358. case FLAC__METADATA_TYPE_PICTURE:
  88359. if(!read_metadata_picture_(decoder, &block.data.picture))
  88360. return false;
  88361. break;
  88362. case FLAC__METADATA_TYPE_STREAMINFO:
  88363. case FLAC__METADATA_TYPE_SEEKTABLE:
  88364. FLAC__ASSERT(0);
  88365. break;
  88366. default:
  88367. if(real_length > 0) {
  88368. if(0 == (block.data.unknown.data = (FLAC__byte*)malloc(real_length))) {
  88369. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88370. return false;
  88371. }
  88372. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, block.data.unknown.data, real_length))
  88373. return false; /* read_callback_ sets the state for us */
  88374. }
  88375. else
  88376. block.data.unknown.data = 0;
  88377. break;
  88378. }
  88379. if(!decoder->private_->is_seeking && decoder->private_->metadata_callback)
  88380. decoder->private_->metadata_callback(decoder, &block, decoder->private_->client_data);
  88381. switch(type) {
  88382. case FLAC__METADATA_TYPE_PADDING:
  88383. break;
  88384. case FLAC__METADATA_TYPE_APPLICATION:
  88385. if(0 != block.data.application.data)
  88386. free(block.data.application.data);
  88387. break;
  88388. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  88389. if(0 != block.data.vorbis_comment.vendor_string.entry)
  88390. free(block.data.vorbis_comment.vendor_string.entry);
  88391. if(block.data.vorbis_comment.num_comments > 0)
  88392. for(i = 0; i < block.data.vorbis_comment.num_comments; i++)
  88393. if(0 != block.data.vorbis_comment.comments[i].entry)
  88394. free(block.data.vorbis_comment.comments[i].entry);
  88395. if(0 != block.data.vorbis_comment.comments)
  88396. free(block.data.vorbis_comment.comments);
  88397. break;
  88398. case FLAC__METADATA_TYPE_CUESHEET:
  88399. if(block.data.cue_sheet.num_tracks > 0)
  88400. for(i = 0; i < block.data.cue_sheet.num_tracks; i++)
  88401. if(0 != block.data.cue_sheet.tracks[i].indices)
  88402. free(block.data.cue_sheet.tracks[i].indices);
  88403. if(0 != block.data.cue_sheet.tracks)
  88404. free(block.data.cue_sheet.tracks);
  88405. break;
  88406. case FLAC__METADATA_TYPE_PICTURE:
  88407. if(0 != block.data.picture.mime_type)
  88408. free(block.data.picture.mime_type);
  88409. if(0 != block.data.picture.description)
  88410. free(block.data.picture.description);
  88411. if(0 != block.data.picture.data)
  88412. free(block.data.picture.data);
  88413. break;
  88414. case FLAC__METADATA_TYPE_STREAMINFO:
  88415. case FLAC__METADATA_TYPE_SEEKTABLE:
  88416. FLAC__ASSERT(0);
  88417. default:
  88418. if(0 != block.data.unknown.data)
  88419. free(block.data.unknown.data);
  88420. break;
  88421. }
  88422. }
  88423. }
  88424. if(is_last) {
  88425. if(!FLAC__stream_decoder_get_decode_position(decoder, &decoder->private_->first_frame_offset))
  88426. decoder->private_->first_frame_offset = 0;
  88427. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88428. }
  88429. return true;
  88430. }
  88431. FLAC__bool read_metadata_streaminfo_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88432. {
  88433. FLAC__uint32 x;
  88434. unsigned bits, used_bits = 0;
  88435. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88436. decoder->private_->stream_info.type = FLAC__METADATA_TYPE_STREAMINFO;
  88437. decoder->private_->stream_info.is_last = is_last;
  88438. decoder->private_->stream_info.length = length;
  88439. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN;
  88440. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, bits))
  88441. return false; /* read_callback_ sets the state for us */
  88442. decoder->private_->stream_info.data.stream_info.min_blocksize = x;
  88443. used_bits += bits;
  88444. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN;
  88445. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  88446. return false; /* read_callback_ sets the state for us */
  88447. decoder->private_->stream_info.data.stream_info.max_blocksize = x;
  88448. used_bits += bits;
  88449. bits = FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN;
  88450. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  88451. return false; /* read_callback_ sets the state for us */
  88452. decoder->private_->stream_info.data.stream_info.min_framesize = x;
  88453. used_bits += bits;
  88454. bits = FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN;
  88455. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  88456. return false; /* read_callback_ sets the state for us */
  88457. decoder->private_->stream_info.data.stream_info.max_framesize = x;
  88458. used_bits += bits;
  88459. bits = FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN;
  88460. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  88461. return false; /* read_callback_ sets the state for us */
  88462. decoder->private_->stream_info.data.stream_info.sample_rate = x;
  88463. used_bits += bits;
  88464. bits = FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN;
  88465. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  88466. return false; /* read_callback_ sets the state for us */
  88467. decoder->private_->stream_info.data.stream_info.channels = x+1;
  88468. used_bits += bits;
  88469. bits = FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN;
  88470. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  88471. return false; /* read_callback_ sets the state for us */
  88472. decoder->private_->stream_info.data.stream_info.bits_per_sample = x+1;
  88473. used_bits += bits;
  88474. bits = FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN;
  88475. 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))
  88476. return false; /* read_callback_ sets the state for us */
  88477. used_bits += bits;
  88478. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, decoder->private_->stream_info.data.stream_info.md5sum, 16))
  88479. return false; /* read_callback_ sets the state for us */
  88480. used_bits += 16*8;
  88481. FLAC__ASSERT(used_bits % 8 == 0);
  88482. length -= (used_bits / 8);
  88483. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88484. return false; /* read_callback_ sets the state for us */
  88485. return true;
  88486. }
  88487. FLAC__bool read_metadata_seektable_(FLAC__StreamDecoder *decoder, FLAC__bool is_last, unsigned length)
  88488. {
  88489. FLAC__uint32 i, x;
  88490. FLAC__uint64 xx;
  88491. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88492. decoder->private_->seek_table.type = FLAC__METADATA_TYPE_SEEKTABLE;
  88493. decoder->private_->seek_table.is_last = is_last;
  88494. decoder->private_->seek_table.length = length;
  88495. decoder->private_->seek_table.data.seek_table.num_points = length / FLAC__STREAM_METADATA_SEEKPOINT_LENGTH;
  88496. 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)))) {
  88497. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88498. return false;
  88499. }
  88500. for(i = 0; i < decoder->private_->seek_table.data.seek_table.num_points; i++) {
  88501. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  88502. return false; /* read_callback_ sets the state for us */
  88503. decoder->private_->seek_table.data.seek_table.points[i].sample_number = xx;
  88504. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &xx, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  88505. return false; /* read_callback_ sets the state for us */
  88506. decoder->private_->seek_table.data.seek_table.points[i].stream_offset = xx;
  88507. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  88508. return false; /* read_callback_ sets the state for us */
  88509. decoder->private_->seek_table.data.seek_table.points[i].frame_samples = x;
  88510. }
  88511. length -= (decoder->private_->seek_table.data.seek_table.num_points * FLAC__STREAM_METADATA_SEEKPOINT_LENGTH);
  88512. if(length > 0) {
  88513. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, length))
  88514. return false; /* read_callback_ sets the state for us */
  88515. }
  88516. return true;
  88517. }
  88518. FLAC__bool read_metadata_vorbiscomment_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_VorbisComment *obj)
  88519. {
  88520. FLAC__uint32 i;
  88521. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88522. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88523. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->vendor_string.length))
  88524. return false; /* read_callback_ sets the state for us */
  88525. if(obj->vendor_string.length > 0) {
  88526. if(0 == (obj->vendor_string.entry = (FLAC__byte*)safe_malloc_add_2op_(obj->vendor_string.length, /*+*/1))) {
  88527. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88528. return false;
  88529. }
  88530. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->vendor_string.entry, obj->vendor_string.length))
  88531. return false; /* read_callback_ sets the state for us */
  88532. obj->vendor_string.entry[obj->vendor_string.length] = '\0';
  88533. }
  88534. else
  88535. obj->vendor_string.entry = 0;
  88536. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_NUM_COMMENTS_LEN == 32);
  88537. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->num_comments))
  88538. return false; /* read_callback_ sets the state for us */
  88539. if(obj->num_comments > 0) {
  88540. if(0 == (obj->comments = (FLAC__StreamMetadata_VorbisComment_Entry*)safe_malloc_mul_2op_(obj->num_comments, /*times*/sizeof(FLAC__StreamMetadata_VorbisComment_Entry)))) {
  88541. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88542. return false;
  88543. }
  88544. for(i = 0; i < obj->num_comments; i++) {
  88545. FLAC__ASSERT(FLAC__STREAM_METADATA_VORBIS_COMMENT_ENTRY_LENGTH_LEN == 32);
  88546. if(!FLAC__bitreader_read_uint32_little_endian(decoder->private_->input, &obj->comments[i].length))
  88547. return false; /* read_callback_ sets the state for us */
  88548. if(obj->comments[i].length > 0) {
  88549. if(0 == (obj->comments[i].entry = (FLAC__byte*)safe_malloc_add_2op_(obj->comments[i].length, /*+*/1))) {
  88550. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88551. return false;
  88552. }
  88553. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->comments[i].entry, obj->comments[i].length))
  88554. return false; /* read_callback_ sets the state for us */
  88555. obj->comments[i].entry[obj->comments[i].length] = '\0';
  88556. }
  88557. else
  88558. obj->comments[i].entry = 0;
  88559. }
  88560. }
  88561. else {
  88562. obj->comments = 0;
  88563. }
  88564. return true;
  88565. }
  88566. FLAC__bool read_metadata_cuesheet_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_CueSheet *obj)
  88567. {
  88568. FLAC__uint32 i, j, x;
  88569. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88570. memset(obj, 0, sizeof(FLAC__StreamMetadata_CueSheet));
  88571. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  88572. 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))
  88573. return false; /* read_callback_ sets the state for us */
  88574. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &obj->lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  88575. return false; /* read_callback_ sets the state for us */
  88576. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  88577. return false; /* read_callback_ sets the state for us */
  88578. obj->is_cd = x? true : false;
  88579. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  88580. return false; /* read_callback_ sets the state for us */
  88581. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  88582. return false; /* read_callback_ sets the state for us */
  88583. obj->num_tracks = x;
  88584. if(obj->num_tracks > 0) {
  88585. if(0 == (obj->tracks = (FLAC__StreamMetadata_CueSheet_Track*)safe_calloc_(obj->num_tracks, sizeof(FLAC__StreamMetadata_CueSheet_Track)))) {
  88586. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88587. return false;
  88588. }
  88589. for(i = 0; i < obj->num_tracks; i++) {
  88590. FLAC__StreamMetadata_CueSheet_Track *track = &obj->tracks[i];
  88591. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  88592. return false; /* read_callback_ sets the state for us */
  88593. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  88594. return false; /* read_callback_ sets the state for us */
  88595. track->number = (FLAC__byte)x;
  88596. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  88597. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  88598. return false; /* read_callback_ sets the state for us */
  88599. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  88600. return false; /* read_callback_ sets the state for us */
  88601. track->type = x;
  88602. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  88603. return false; /* read_callback_ sets the state for us */
  88604. track->pre_emphasis = x;
  88605. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  88606. return false; /* read_callback_ sets the state for us */
  88607. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  88608. return false; /* read_callback_ sets the state for us */
  88609. track->num_indices = (FLAC__byte)x;
  88610. if(track->num_indices > 0) {
  88611. if(0 == (track->indices = (FLAC__StreamMetadata_CueSheet_Index*)safe_calloc_(track->num_indices, sizeof(FLAC__StreamMetadata_CueSheet_Index)))) {
  88612. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88613. return false;
  88614. }
  88615. for(j = 0; j < track->num_indices; j++) {
  88616. FLAC__StreamMetadata_CueSheet_Index *index = &track->indices[j];
  88617. if(!FLAC__bitreader_read_raw_uint64(decoder->private_->input, &index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  88618. return false; /* read_callback_ sets the state for us */
  88619. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  88620. return false; /* read_callback_ sets the state for us */
  88621. index->number = (FLAC__byte)x;
  88622. if(!FLAC__bitreader_skip_bits_no_crc(decoder->private_->input, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  88623. return false; /* read_callback_ sets the state for us */
  88624. }
  88625. }
  88626. }
  88627. }
  88628. return true;
  88629. }
  88630. FLAC__bool read_metadata_picture_(FLAC__StreamDecoder *decoder, FLAC__StreamMetadata_Picture *obj)
  88631. {
  88632. FLAC__uint32 x;
  88633. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88634. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  88635. return false; /* read_callback_ sets the state for us */
  88636. obj->type = (FLAC__StreamMetadata_Picture_Type) x;
  88637. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  88638. return false; /* read_callback_ sets the state for us */
  88639. if(0 == (obj->mime_type = (char*)safe_malloc_add_2op_(x, /*+*/1))) {
  88640. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88641. return false;
  88642. }
  88643. if(x > 0) {
  88644. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, (FLAC__byte*)obj->mime_type, x))
  88645. return false; /* read_callback_ sets the state for us */
  88646. }
  88647. obj->mime_type[x] = '\0';
  88648. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  88649. return false; /* read_callback_ sets the state for us */
  88650. if(0 == (obj->description = (FLAC__byte*)safe_malloc_add_2op_(x, /*+*/1))) {
  88651. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88652. return false;
  88653. }
  88654. if(x > 0) {
  88655. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->description, x))
  88656. return false; /* read_callback_ sets the state for us */
  88657. }
  88658. obj->description[x] = '\0';
  88659. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  88660. return false; /* read_callback_ sets the state for us */
  88661. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  88662. return false; /* read_callback_ sets the state for us */
  88663. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  88664. return false; /* read_callback_ sets the state for us */
  88665. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &obj->colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  88666. return false; /* read_callback_ sets the state for us */
  88667. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &(obj->data_length), FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  88668. return false; /* read_callback_ sets the state for us */
  88669. if(0 == (obj->data = (FLAC__byte*)safe_malloc_(obj->data_length))) {
  88670. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  88671. return false;
  88672. }
  88673. if(obj->data_length > 0) {
  88674. if(!FLAC__bitreader_read_byte_block_aligned_no_crc(decoder->private_->input, obj->data, obj->data_length))
  88675. return false; /* read_callback_ sets the state for us */
  88676. }
  88677. return true;
  88678. }
  88679. FLAC__bool skip_id3v2_tag_(FLAC__StreamDecoder *decoder)
  88680. {
  88681. FLAC__uint32 x;
  88682. unsigned i, skip;
  88683. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 24))
  88684. return false; /* read_callback_ sets the state for us */
  88685. skip = 0;
  88686. for(i = 0; i < 4; i++) {
  88687. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88688. return false; /* read_callback_ sets the state for us */
  88689. skip <<= 7;
  88690. skip |= (x & 0x7f);
  88691. }
  88692. if(!FLAC__bitreader_skip_byte_block_aligned_no_crc(decoder->private_->input, skip))
  88693. return false; /* read_callback_ sets the state for us */
  88694. return true;
  88695. }
  88696. FLAC__bool frame_sync_(FLAC__StreamDecoder *decoder)
  88697. {
  88698. FLAC__uint32 x;
  88699. FLAC__bool first = true;
  88700. if(FLAC__stream_decoder_get_total_samples(decoder) > 0) {
  88701. if(decoder->private_->samples_decoded >= FLAC__stream_decoder_get_total_samples(decoder)) {
  88702. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  88703. return true;
  88704. }
  88705. }
  88706. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  88707. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  88708. return false; /* read_callback_ sets the state for us */
  88709. }
  88710. while(1) {
  88711. if(decoder->private_->cached) {
  88712. x = (FLAC__uint32)decoder->private_->lookahead;
  88713. decoder->private_->cached = false;
  88714. }
  88715. else {
  88716. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88717. return false; /* read_callback_ sets the state for us */
  88718. }
  88719. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88720. decoder->private_->header_warmup[0] = (FLAC__byte)x;
  88721. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88722. return false; /* read_callback_ sets the state for us */
  88723. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88724. decoder->private_->lookahead = (FLAC__byte)x;
  88725. decoder->private_->cached = true;
  88726. }
  88727. else if(x >> 2 == 0x3e) { /* MAGIC NUMBER for the last 6 sync bits */
  88728. decoder->private_->header_warmup[1] = (FLAC__byte)x;
  88729. decoder->protected_->state = FLAC__STREAM_DECODER_READ_FRAME;
  88730. return true;
  88731. }
  88732. }
  88733. if(first) {
  88734. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  88735. first = false;
  88736. }
  88737. }
  88738. return true;
  88739. }
  88740. FLAC__bool read_frame_(FLAC__StreamDecoder *decoder, FLAC__bool *got_a_frame, FLAC__bool do_full_decode)
  88741. {
  88742. unsigned channel;
  88743. unsigned i;
  88744. FLAC__int32 mid, side;
  88745. unsigned frame_crc; /* the one we calculate from the input stream */
  88746. FLAC__uint32 x;
  88747. *got_a_frame = false;
  88748. frame_crc = 0;
  88749. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[0], frame_crc);
  88750. frame_crc = FLAC__CRC16_UPDATE(decoder->private_->header_warmup[1], frame_crc);
  88751. FLAC__bitreader_reset_read_crc16(decoder->private_->input, (FLAC__uint16)frame_crc);
  88752. if(!read_frame_header_(decoder))
  88753. return false;
  88754. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means we didn't sync on a valid header */
  88755. return true;
  88756. if(!allocate_output_(decoder, decoder->private_->frame.header.blocksize, decoder->private_->frame.header.channels))
  88757. return false;
  88758. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88759. unsigned bps = decoder->private_->frame.header.bits_per_sample;
  88760. switch(decoder->private_->frame.header.channel_assignment) {
  88761. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88762. break;
  88763. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88764. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88765. if(channel == 1)
  88766. bps++;
  88767. break;
  88768. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88769. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88770. if(channel == 0)
  88771. bps++;
  88772. break;
  88773. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88774. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88775. if(channel == 1)
  88776. bps++;
  88777. break;
  88778. default:
  88779. FLAC__ASSERT(0);
  88780. }
  88781. if(!read_subframe_(decoder, channel, bps, do_full_decode))
  88782. return false;
  88783. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  88784. return true;
  88785. }
  88786. if(!read_zero_padding_(decoder))
  88787. return false;
  88788. 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) */
  88789. return true;
  88790. frame_crc = FLAC__bitreader_get_read_crc16(decoder->private_->input);
  88791. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, FLAC__FRAME_FOOTER_CRC_LEN))
  88792. return false; /* read_callback_ sets the state for us */
  88793. if(frame_crc == x) {
  88794. if(do_full_decode) {
  88795. switch(decoder->private_->frame.header.channel_assignment) {
  88796. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  88797. break;
  88798. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  88799. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88800. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88801. decoder->private_->output[1][i] = decoder->private_->output[0][i] - decoder->private_->output[1][i];
  88802. break;
  88803. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  88804. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88805. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  88806. decoder->private_->output[0][i] += decoder->private_->output[1][i];
  88807. break;
  88808. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  88809. FLAC__ASSERT(decoder->private_->frame.header.channels == 2);
  88810. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  88811. #if 1
  88812. mid = decoder->private_->output[0][i];
  88813. side = decoder->private_->output[1][i];
  88814. mid <<= 1;
  88815. mid |= (side & 1); /* i.e. if 'side' is odd... */
  88816. decoder->private_->output[0][i] = (mid + side) >> 1;
  88817. decoder->private_->output[1][i] = (mid - side) >> 1;
  88818. #else
  88819. mid = (decoder->private_->output[0][i] << 1) | (decoder->private_->output[1][i] & 1); /* i.e. if 'side' is odd... */
  88820. decoder->private_->output[0][i] = (mid + decoder->private_->output[1][i]) >> 1;
  88821. decoder->private_->output[1][i] = (mid - decoder->private_->output[1][i]) >> 1;
  88822. #endif
  88823. }
  88824. break;
  88825. default:
  88826. FLAC__ASSERT(0);
  88827. break;
  88828. }
  88829. }
  88830. }
  88831. else {
  88832. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_FRAME_CRC_MISMATCH);
  88833. if(do_full_decode) {
  88834. for(channel = 0; channel < decoder->private_->frame.header.channels; channel++) {
  88835. memset(decoder->private_->output[channel], 0, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  88836. }
  88837. }
  88838. }
  88839. *got_a_frame = true;
  88840. if(decoder->private_->next_fixed_block_size)
  88841. decoder->private_->fixed_block_size = decoder->private_->next_fixed_block_size;
  88842. decoder->protected_->channels = decoder->private_->frame.header.channels;
  88843. decoder->protected_->channel_assignment = decoder->private_->frame.header.channel_assignment;
  88844. decoder->protected_->bits_per_sample = decoder->private_->frame.header.bits_per_sample;
  88845. decoder->protected_->sample_rate = decoder->private_->frame.header.sample_rate;
  88846. decoder->protected_->blocksize = decoder->private_->frame.header.blocksize;
  88847. FLAC__ASSERT(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  88848. decoder->private_->samples_decoded = decoder->private_->frame.header.number.sample_number + decoder->private_->frame.header.blocksize;
  88849. if(do_full_decode) {
  88850. if(write_audio_frame_to_client_(decoder, &decoder->private_->frame, (const FLAC__int32 * const *)decoder->private_->output) != FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE)
  88851. return false;
  88852. }
  88853. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88854. return true;
  88855. }
  88856. FLAC__bool read_frame_header_(FLAC__StreamDecoder *decoder)
  88857. {
  88858. FLAC__uint32 x;
  88859. FLAC__uint64 xx;
  88860. unsigned i, blocksize_hint = 0, sample_rate_hint = 0;
  88861. FLAC__byte crc8, raw_header[16]; /* MAGIC NUMBER based on the maximum frame header size, including CRC */
  88862. unsigned raw_header_len;
  88863. FLAC__bool is_unparseable = false;
  88864. FLAC__ASSERT(FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input));
  88865. raw_header[0] = decoder->private_->header_warmup[0];
  88866. raw_header[1] = decoder->private_->header_warmup[1];
  88867. raw_header_len = 2;
  88868. if(raw_header[1] & 0x02) /* MAGIC NUMBER */
  88869. is_unparseable = true;
  88870. for(i = 0; i < 2; i++) {
  88871. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  88872. return false; /* read_callback_ sets the state for us */
  88873. if(x == 0xff) { /* MAGIC NUMBER for the first 8 frame sync bits */
  88874. decoder->private_->lookahead = (FLAC__byte)x;
  88875. decoder->private_->cached = true;
  88876. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88877. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88878. return true;
  88879. }
  88880. raw_header[raw_header_len++] = (FLAC__byte)x;
  88881. }
  88882. switch(x = raw_header[2] >> 4) {
  88883. case 0:
  88884. is_unparseable = true;
  88885. break;
  88886. case 1:
  88887. decoder->private_->frame.header.blocksize = 192;
  88888. break;
  88889. case 2:
  88890. case 3:
  88891. case 4:
  88892. case 5:
  88893. decoder->private_->frame.header.blocksize = 576 << (x-2);
  88894. break;
  88895. case 6:
  88896. case 7:
  88897. blocksize_hint = x;
  88898. break;
  88899. case 8:
  88900. case 9:
  88901. case 10:
  88902. case 11:
  88903. case 12:
  88904. case 13:
  88905. case 14:
  88906. case 15:
  88907. decoder->private_->frame.header.blocksize = 256 << (x-8);
  88908. break;
  88909. default:
  88910. FLAC__ASSERT(0);
  88911. break;
  88912. }
  88913. switch(x = raw_header[2] & 0x0f) {
  88914. case 0:
  88915. if(decoder->private_->has_stream_info)
  88916. decoder->private_->frame.header.sample_rate = decoder->private_->stream_info.data.stream_info.sample_rate;
  88917. else
  88918. is_unparseable = true;
  88919. break;
  88920. case 1:
  88921. decoder->private_->frame.header.sample_rate = 88200;
  88922. break;
  88923. case 2:
  88924. decoder->private_->frame.header.sample_rate = 176400;
  88925. break;
  88926. case 3:
  88927. decoder->private_->frame.header.sample_rate = 192000;
  88928. break;
  88929. case 4:
  88930. decoder->private_->frame.header.sample_rate = 8000;
  88931. break;
  88932. case 5:
  88933. decoder->private_->frame.header.sample_rate = 16000;
  88934. break;
  88935. case 6:
  88936. decoder->private_->frame.header.sample_rate = 22050;
  88937. break;
  88938. case 7:
  88939. decoder->private_->frame.header.sample_rate = 24000;
  88940. break;
  88941. case 8:
  88942. decoder->private_->frame.header.sample_rate = 32000;
  88943. break;
  88944. case 9:
  88945. decoder->private_->frame.header.sample_rate = 44100;
  88946. break;
  88947. case 10:
  88948. decoder->private_->frame.header.sample_rate = 48000;
  88949. break;
  88950. case 11:
  88951. decoder->private_->frame.header.sample_rate = 96000;
  88952. break;
  88953. case 12:
  88954. case 13:
  88955. case 14:
  88956. sample_rate_hint = x;
  88957. break;
  88958. case 15:
  88959. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  88960. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  88961. return true;
  88962. default:
  88963. FLAC__ASSERT(0);
  88964. }
  88965. x = (unsigned)(raw_header[3] >> 4);
  88966. if(x & 8) {
  88967. decoder->private_->frame.header.channels = 2;
  88968. switch(x & 7) {
  88969. case 0:
  88970. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE;
  88971. break;
  88972. case 1:
  88973. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE;
  88974. break;
  88975. case 2:
  88976. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_MID_SIDE;
  88977. break;
  88978. default:
  88979. is_unparseable = true;
  88980. break;
  88981. }
  88982. }
  88983. else {
  88984. decoder->private_->frame.header.channels = (unsigned)x + 1;
  88985. decoder->private_->frame.header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  88986. }
  88987. switch(x = (unsigned)(raw_header[3] & 0x0e) >> 1) {
  88988. case 0:
  88989. if(decoder->private_->has_stream_info)
  88990. decoder->private_->frame.header.bits_per_sample = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  88991. else
  88992. is_unparseable = true;
  88993. break;
  88994. case 1:
  88995. decoder->private_->frame.header.bits_per_sample = 8;
  88996. break;
  88997. case 2:
  88998. decoder->private_->frame.header.bits_per_sample = 12;
  88999. break;
  89000. case 4:
  89001. decoder->private_->frame.header.bits_per_sample = 16;
  89002. break;
  89003. case 5:
  89004. decoder->private_->frame.header.bits_per_sample = 20;
  89005. break;
  89006. case 6:
  89007. decoder->private_->frame.header.bits_per_sample = 24;
  89008. break;
  89009. case 3:
  89010. case 7:
  89011. is_unparseable = true;
  89012. break;
  89013. default:
  89014. FLAC__ASSERT(0);
  89015. break;
  89016. }
  89017. if(raw_header[3] & 0x01) /* MAGIC NUMBER */
  89018. is_unparseable = true;
  89019. if(
  89020. raw_header[1] & 0x01 ||
  89021. (decoder->private_->has_stream_info && decoder->private_->stream_info.data.stream_info.min_blocksize != decoder->private_->stream_info.data.stream_info.max_blocksize)
  89022. ) { /* variable blocksize */
  89023. if(!FLAC__bitreader_read_utf8_uint64(decoder->private_->input, &xx, raw_header, &raw_header_len))
  89024. return false; /* read_callback_ sets the state for us */
  89025. if(xx == FLAC__U64L(0xffffffffffffffff)) { /* i.e. non-UTF8 code... */
  89026. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  89027. decoder->private_->cached = true;
  89028. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89029. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89030. return true;
  89031. }
  89032. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  89033. decoder->private_->frame.header.number.sample_number = xx;
  89034. }
  89035. else { /* fixed blocksize */
  89036. if(!FLAC__bitreader_read_utf8_uint32(decoder->private_->input, &x, raw_header, &raw_header_len))
  89037. return false; /* read_callback_ sets the state for us */
  89038. if(x == 0xffffffff) { /* i.e. non-UTF8 code... */
  89039. decoder->private_->lookahead = raw_header[raw_header_len-1]; /* back up as much as we can */
  89040. decoder->private_->cached = true;
  89041. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89042. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89043. return true;
  89044. }
  89045. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  89046. decoder->private_->frame.header.number.frame_number = x;
  89047. }
  89048. if(blocksize_hint) {
  89049. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89050. return false; /* read_callback_ sets the state for us */
  89051. raw_header[raw_header_len++] = (FLAC__byte)x;
  89052. if(blocksize_hint == 7) {
  89053. FLAC__uint32 _x;
  89054. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  89055. return false; /* read_callback_ sets the state for us */
  89056. raw_header[raw_header_len++] = (FLAC__byte)_x;
  89057. x = (x << 8) | _x;
  89058. }
  89059. decoder->private_->frame.header.blocksize = x+1;
  89060. }
  89061. if(sample_rate_hint) {
  89062. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89063. return false; /* read_callback_ sets the state for us */
  89064. raw_header[raw_header_len++] = (FLAC__byte)x;
  89065. if(sample_rate_hint != 12) {
  89066. FLAC__uint32 _x;
  89067. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &_x, 8))
  89068. return false; /* read_callback_ sets the state for us */
  89069. raw_header[raw_header_len++] = (FLAC__byte)_x;
  89070. x = (x << 8) | _x;
  89071. }
  89072. if(sample_rate_hint == 12)
  89073. decoder->private_->frame.header.sample_rate = x*1000;
  89074. else if(sample_rate_hint == 13)
  89075. decoder->private_->frame.header.sample_rate = x;
  89076. else
  89077. decoder->private_->frame.header.sample_rate = x*10;
  89078. }
  89079. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8))
  89080. return false; /* read_callback_ sets the state for us */
  89081. crc8 = (FLAC__byte)x;
  89082. if(FLAC__crc8(raw_header, raw_header_len) != crc8) {
  89083. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_BAD_HEADER);
  89084. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89085. return true;
  89086. }
  89087. decoder->private_->next_fixed_block_size = 0;
  89088. if(decoder->private_->frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  89089. x = decoder->private_->frame.header.number.frame_number;
  89090. decoder->private_->frame.header.number_type = FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER;
  89091. if(decoder->private_->fixed_block_size)
  89092. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->fixed_block_size * (FLAC__uint64)x;
  89093. else if(decoder->private_->has_stream_info) {
  89094. if(decoder->private_->stream_info.data.stream_info.min_blocksize == decoder->private_->stream_info.data.stream_info.max_blocksize) {
  89095. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->stream_info.data.stream_info.min_blocksize * (FLAC__uint64)x;
  89096. decoder->private_->next_fixed_block_size = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89097. }
  89098. else
  89099. is_unparseable = true;
  89100. }
  89101. else if(x == 0) {
  89102. decoder->private_->frame.header.number.sample_number = 0;
  89103. decoder->private_->next_fixed_block_size = decoder->private_->frame.header.blocksize;
  89104. }
  89105. else {
  89106. decoder->private_->frame.header.number.sample_number = (FLAC__uint64)decoder->private_->frame.header.blocksize * (FLAC__uint64)x;
  89107. }
  89108. }
  89109. if(is_unparseable) {
  89110. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89111. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89112. return true;
  89113. }
  89114. return true;
  89115. }
  89116. FLAC__bool read_subframe_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89117. {
  89118. FLAC__uint32 x;
  89119. FLAC__bool wasted_bits;
  89120. unsigned i;
  89121. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &x, 8)) /* MAGIC NUMBER */
  89122. return false; /* read_callback_ sets the state for us */
  89123. wasted_bits = (x & 1);
  89124. x &= 0xfe;
  89125. if(wasted_bits) {
  89126. unsigned u;
  89127. if(!FLAC__bitreader_read_unary_unsigned(decoder->private_->input, &u))
  89128. return false; /* read_callback_ sets the state for us */
  89129. decoder->private_->frame.subframes[channel].wasted_bits = u+1;
  89130. bps -= decoder->private_->frame.subframes[channel].wasted_bits;
  89131. }
  89132. else
  89133. decoder->private_->frame.subframes[channel].wasted_bits = 0;
  89134. if(x & 0x80) {
  89135. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89136. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89137. return true;
  89138. }
  89139. else if(x == 0) {
  89140. if(!read_subframe_constant_(decoder, channel, bps, do_full_decode))
  89141. return false;
  89142. }
  89143. else if(x == 2) {
  89144. if(!read_subframe_verbatim_(decoder, channel, bps, do_full_decode))
  89145. return false;
  89146. }
  89147. else if(x < 16) {
  89148. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89149. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89150. return true;
  89151. }
  89152. else if(x <= 24) {
  89153. if(!read_subframe_fixed_(decoder, channel, bps, (x>>1)&7, do_full_decode))
  89154. return false;
  89155. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  89156. return true;
  89157. }
  89158. else if(x < 64) {
  89159. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89160. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89161. return true;
  89162. }
  89163. else {
  89164. if(!read_subframe_lpc_(decoder, channel, bps, ((x>>1)&31)+1, do_full_decode))
  89165. return false;
  89166. if(decoder->protected_->state == FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC) /* means bad sync or got corruption */
  89167. return true;
  89168. }
  89169. if(wasted_bits && do_full_decode) {
  89170. x = decoder->private_->frame.subframes[channel].wasted_bits;
  89171. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89172. decoder->private_->output[channel][i] <<= x;
  89173. }
  89174. return true;
  89175. }
  89176. FLAC__bool read_subframe_constant_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89177. {
  89178. FLAC__Subframe_Constant *subframe = &decoder->private_->frame.subframes[channel].data.constant;
  89179. FLAC__int32 x;
  89180. unsigned i;
  89181. FLAC__int32 *output = decoder->private_->output[channel];
  89182. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_CONSTANT;
  89183. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89184. return false; /* read_callback_ sets the state for us */
  89185. subframe->value = x;
  89186. if(do_full_decode) {
  89187. for(i = 0; i < decoder->private_->frame.header.blocksize; i++)
  89188. output[i] = x;
  89189. }
  89190. return true;
  89191. }
  89192. FLAC__bool read_subframe_fixed_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  89193. {
  89194. FLAC__Subframe_Fixed *subframe = &decoder->private_->frame.subframes[channel].data.fixed;
  89195. FLAC__int32 i32;
  89196. FLAC__uint32 u32;
  89197. unsigned u;
  89198. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_FIXED;
  89199. subframe->residual = decoder->private_->residual[channel];
  89200. subframe->order = order;
  89201. for(u = 0; u < order; u++) {
  89202. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  89203. return false; /* read_callback_ sets the state for us */
  89204. subframe->warmup[u] = i32;
  89205. }
  89206. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  89207. return false; /* read_callback_ sets the state for us */
  89208. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  89209. switch(subframe->entropy_coding_method.type) {
  89210. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89211. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89212. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89213. return false; /* read_callback_ sets the state for us */
  89214. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  89215. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  89216. break;
  89217. default:
  89218. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89219. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89220. return true;
  89221. }
  89222. switch(subframe->entropy_coding_method.type) {
  89223. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89224. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89225. 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))
  89226. return false;
  89227. break;
  89228. default:
  89229. FLAC__ASSERT(0);
  89230. }
  89231. if(do_full_decode) {
  89232. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89233. FLAC__fixed_restore_signal(decoder->private_->residual[channel], decoder->private_->frame.header.blocksize-order, order, decoder->private_->output[channel]+order);
  89234. }
  89235. return true;
  89236. }
  89237. FLAC__bool read_subframe_lpc_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, const unsigned order, FLAC__bool do_full_decode)
  89238. {
  89239. FLAC__Subframe_LPC *subframe = &decoder->private_->frame.subframes[channel].data.lpc;
  89240. FLAC__int32 i32;
  89241. FLAC__uint32 u32;
  89242. unsigned u;
  89243. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_LPC;
  89244. subframe->residual = decoder->private_->residual[channel];
  89245. subframe->order = order;
  89246. for(u = 0; u < order; u++) {
  89247. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, bps))
  89248. return false; /* read_callback_ sets the state for us */
  89249. subframe->warmup[u] = i32;
  89250. }
  89251. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  89252. return false; /* read_callback_ sets the state for us */
  89253. if(u32 == (1u << FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN) - 1) {
  89254. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89255. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89256. return true;
  89257. }
  89258. subframe->qlp_coeff_precision = u32+1;
  89259. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  89260. return false; /* read_callback_ sets the state for us */
  89261. subframe->quantization_level = i32;
  89262. for(u = 0; u < order; u++) {
  89263. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &i32, subframe->qlp_coeff_precision))
  89264. return false; /* read_callback_ sets the state for us */
  89265. subframe->qlp_coeff[u] = i32;
  89266. }
  89267. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  89268. return false; /* read_callback_ sets the state for us */
  89269. subframe->entropy_coding_method.type = (FLAC__EntropyCodingMethodType)u32;
  89270. switch(subframe->entropy_coding_method.type) {
  89271. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89272. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89273. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &u32, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  89274. return false; /* read_callback_ sets the state for us */
  89275. subframe->entropy_coding_method.data.partitioned_rice.order = u32;
  89276. subframe->entropy_coding_method.data.partitioned_rice.contents = &decoder->private_->partitioned_rice_contents[channel];
  89277. break;
  89278. default:
  89279. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM);
  89280. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89281. return true;
  89282. }
  89283. switch(subframe->entropy_coding_method.type) {
  89284. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  89285. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  89286. 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))
  89287. return false;
  89288. break;
  89289. default:
  89290. FLAC__ASSERT(0);
  89291. }
  89292. if(do_full_decode) {
  89293. memcpy(decoder->private_->output[channel], subframe->warmup, sizeof(FLAC__int32) * order);
  89294. if(bps + subframe->qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  89295. if(bps <= 16 && subframe->qlp_coeff_precision <= 16) {
  89296. if(order <= 8)
  89297. 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);
  89298. else
  89299. 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);
  89300. }
  89301. else
  89302. 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);
  89303. else
  89304. 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);
  89305. }
  89306. return true;
  89307. }
  89308. FLAC__bool read_subframe_verbatim_(FLAC__StreamDecoder *decoder, unsigned channel, unsigned bps, FLAC__bool do_full_decode)
  89309. {
  89310. FLAC__Subframe_Verbatim *subframe = &decoder->private_->frame.subframes[channel].data.verbatim;
  89311. FLAC__int32 x, *residual = decoder->private_->residual[channel];
  89312. unsigned i;
  89313. decoder->private_->frame.subframes[channel].type = FLAC__SUBFRAME_TYPE_VERBATIM;
  89314. subframe->data = residual;
  89315. for(i = 0; i < decoder->private_->frame.header.blocksize; i++) {
  89316. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, &x, bps))
  89317. return false; /* read_callback_ sets the state for us */
  89318. residual[i] = x;
  89319. }
  89320. if(do_full_decode)
  89321. memcpy(decoder->private_->output[channel], subframe->data, sizeof(FLAC__int32) * decoder->private_->frame.header.blocksize);
  89322. return true;
  89323. }
  89324. 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)
  89325. {
  89326. FLAC__uint32 rice_parameter;
  89327. int i;
  89328. unsigned partition, sample, u;
  89329. const unsigned partitions = 1u << partition_order;
  89330. const unsigned partition_samples = partition_order > 0? decoder->private_->frame.header.blocksize >> partition_order : decoder->private_->frame.header.blocksize - predictor_order;
  89331. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  89332. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  89333. if(partition_order == 0) {
  89334. if(decoder->private_->frame.header.blocksize < predictor_order) {
  89335. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89336. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89337. return true;
  89338. }
  89339. }
  89340. else {
  89341. if(partition_samples < predictor_order) {
  89342. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89343. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89344. return true;
  89345. }
  89346. }
  89347. if(!FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order))) {
  89348. decoder->protected_->state = FLAC__STREAM_DECODER_MEMORY_ALLOCATION_ERROR;
  89349. return false;
  89350. }
  89351. sample = 0;
  89352. for(partition = 0; partition < partitions; partition++) {
  89353. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, plen))
  89354. return false; /* read_callback_ sets the state for us */
  89355. partitioned_rice_contents->parameters[partition] = rice_parameter;
  89356. if(rice_parameter < pesc) {
  89357. partitioned_rice_contents->raw_bits[partition] = 0;
  89358. u = (partition_order == 0 || partition > 0)? partition_samples : partition_samples - predictor_order;
  89359. if(!decoder->private_->local_bitreader_read_rice_signed_block(decoder->private_->input, (int*) residual + sample, u, rice_parameter))
  89360. return false; /* read_callback_ sets the state for us */
  89361. sample += u;
  89362. }
  89363. else {
  89364. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &rice_parameter, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  89365. return false; /* read_callback_ sets the state for us */
  89366. partitioned_rice_contents->raw_bits[partition] = rice_parameter;
  89367. for(u = (partition_order == 0 || partition > 0)? 0 : predictor_order; u < partition_samples; u++, sample++) {
  89368. if(!FLAC__bitreader_read_raw_int32(decoder->private_->input, (FLAC__int32*) &i, rice_parameter))
  89369. return false; /* read_callback_ sets the state for us */
  89370. residual[sample] = i;
  89371. }
  89372. }
  89373. }
  89374. return true;
  89375. }
  89376. FLAC__bool read_zero_padding_(FLAC__StreamDecoder *decoder)
  89377. {
  89378. if(!FLAC__bitreader_is_consumed_byte_aligned(decoder->private_->input)) {
  89379. FLAC__uint32 zero = 0;
  89380. if(!FLAC__bitreader_read_raw_uint32(decoder->private_->input, &zero, FLAC__bitreader_bits_left_for_byte_alignment(decoder->private_->input)))
  89381. return false; /* read_callback_ sets the state for us */
  89382. if(zero != 0) {
  89383. send_error_to_client_(decoder, FLAC__STREAM_DECODER_ERROR_STATUS_LOST_SYNC);
  89384. decoder->protected_->state = FLAC__STREAM_DECODER_SEARCH_FOR_FRAME_SYNC;
  89385. }
  89386. }
  89387. return true;
  89388. }
  89389. FLAC__bool read_callback_(FLAC__byte buffer[], size_t *bytes, void *client_data)
  89390. {
  89391. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder *)client_data;
  89392. if(
  89393. #if FLAC__HAS_OGG
  89394. !decoder->private_->is_ogg &&
  89395. #endif
  89396. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89397. ) {
  89398. *bytes = 0;
  89399. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89400. return false;
  89401. }
  89402. else if(*bytes > 0) {
  89403. if(decoder->private_->is_seeking && decoder->private_->unparseable_frame_count > 20) {
  89404. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89405. return false;
  89406. }
  89407. else {
  89408. const FLAC__StreamDecoderReadStatus status =
  89409. #if FLAC__HAS_OGG
  89410. decoder->private_->is_ogg?
  89411. read_callback_ogg_aspect_(decoder, buffer, bytes) :
  89412. #endif
  89413. decoder->private_->read_callback(decoder, buffer, bytes, decoder->private_->client_data)
  89414. ;
  89415. if(status == FLAC__STREAM_DECODER_READ_STATUS_ABORT) {
  89416. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89417. return false;
  89418. }
  89419. else if(*bytes == 0) {
  89420. if(
  89421. status == FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM ||
  89422. (
  89423. #if FLAC__HAS_OGG
  89424. !decoder->private_->is_ogg &&
  89425. #endif
  89426. decoder->private_->eof_callback && decoder->private_->eof_callback(decoder, decoder->private_->client_data)
  89427. )
  89428. ) {
  89429. decoder->protected_->state = FLAC__STREAM_DECODER_END_OF_STREAM;
  89430. return false;
  89431. }
  89432. else
  89433. return true;
  89434. }
  89435. else
  89436. return true;
  89437. }
  89438. }
  89439. else {
  89440. decoder->protected_->state = FLAC__STREAM_DECODER_ABORTED;
  89441. return false;
  89442. }
  89443. }
  89444. #if FLAC__HAS_OGG
  89445. FLAC__StreamDecoderReadStatus read_callback_ogg_aspect_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes)
  89446. {
  89447. switch(FLAC__ogg_decoder_aspect_read_callback_wrapper(&decoder->protected_->ogg_decoder_aspect, buffer, bytes, read_callback_proxy_, decoder, decoder->private_->client_data)) {
  89448. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK:
  89449. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89450. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_LOST_SYNC:
  89451. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89452. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM:
  89453. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89454. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_NOT_FLAC:
  89455. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_UNSUPPORTED_MAPPING_VERSION:
  89456. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT:
  89457. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_ERROR:
  89458. case FLAC__OGG_DECODER_ASPECT_READ_STATUS_MEMORY_ALLOCATION_ERROR:
  89459. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89460. default:
  89461. FLAC__ASSERT(0);
  89462. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89463. }
  89464. }
  89465. FLAC__OggDecoderAspectReadStatus read_callback_proxy_(const void *void_decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89466. {
  89467. FLAC__StreamDecoder *decoder = (FLAC__StreamDecoder*)void_decoder;
  89468. switch(decoder->private_->read_callback(decoder, buffer, bytes, client_data)) {
  89469. case FLAC__STREAM_DECODER_READ_STATUS_CONTINUE:
  89470. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_OK;
  89471. case FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM:
  89472. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_END_OF_STREAM;
  89473. case FLAC__STREAM_DECODER_READ_STATUS_ABORT:
  89474. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89475. default:
  89476. FLAC__ASSERT(0);
  89477. return FLAC__OGG_DECODER_ASPECT_READ_STATUS_ABORT;
  89478. }
  89479. }
  89480. #endif
  89481. FLAC__StreamDecoderWriteStatus write_audio_frame_to_client_(FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[])
  89482. {
  89483. if(decoder->private_->is_seeking) {
  89484. FLAC__uint64 this_frame_sample = frame->header.number.sample_number;
  89485. FLAC__uint64 next_frame_sample = this_frame_sample + (FLAC__uint64)frame->header.blocksize;
  89486. FLAC__uint64 target_sample = decoder->private_->target_sample;
  89487. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89488. #if FLAC__HAS_OGG
  89489. decoder->private_->got_a_frame = true;
  89490. #endif
  89491. decoder->private_->last_frame = *frame; /* save the frame */
  89492. if(this_frame_sample <= target_sample && target_sample < next_frame_sample) { /* we hit our target frame */
  89493. unsigned delta = (unsigned)(target_sample - this_frame_sample);
  89494. decoder->private_->is_seeking = false;
  89495. if(delta > 0) {
  89496. unsigned channel;
  89497. const FLAC__int32 *newbuffer[FLAC__MAX_CHANNELS];
  89498. for(channel = 0; channel < frame->header.channels; channel++)
  89499. newbuffer[channel] = buffer[channel] + delta;
  89500. decoder->private_->last_frame.header.blocksize -= delta;
  89501. decoder->private_->last_frame.header.number.sample_number += (FLAC__uint64)delta;
  89502. return decoder->private_->write_callback(decoder, &decoder->private_->last_frame, newbuffer, decoder->private_->client_data);
  89503. }
  89504. else {
  89505. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89506. }
  89507. }
  89508. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  89509. }
  89510. if(!decoder->private_->has_stream_info)
  89511. decoder->private_->do_md5_checking = false;
  89512. if(decoder->private_->do_md5_checking) {
  89513. if(!FLAC__MD5Accumulate(&decoder->private_->md5context, buffer, frame->header.channels, frame->header.blocksize, (frame->header.bits_per_sample+7) / 8))
  89514. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  89515. }
  89516. return decoder->private_->write_callback(decoder, frame, buffer, decoder->private_->client_data);
  89517. }
  89518. void send_error_to_client_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status)
  89519. {
  89520. if(!decoder->private_->is_seeking)
  89521. decoder->private_->error_callback(decoder, status, decoder->private_->client_data);
  89522. else if(status == FLAC__STREAM_DECODER_ERROR_STATUS_UNPARSEABLE_STREAM)
  89523. decoder->private_->unparseable_frame_count++;
  89524. }
  89525. FLAC__bool seek_to_absolute_sample_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89526. {
  89527. FLAC__uint64 first_frame_offset = decoder->private_->first_frame_offset, lower_bound, upper_bound, lower_bound_sample, upper_bound_sample, this_frame_sample;
  89528. FLAC__int64 pos = -1;
  89529. int i;
  89530. unsigned approx_bytes_per_frame;
  89531. FLAC__bool first_seek = true;
  89532. const FLAC__uint64 total_samples = FLAC__stream_decoder_get_total_samples(decoder);
  89533. const unsigned min_blocksize = decoder->private_->stream_info.data.stream_info.min_blocksize;
  89534. const unsigned max_blocksize = decoder->private_->stream_info.data.stream_info.max_blocksize;
  89535. const unsigned max_framesize = decoder->private_->stream_info.data.stream_info.max_framesize;
  89536. const unsigned min_framesize = decoder->private_->stream_info.data.stream_info.min_framesize;
  89537. unsigned channels = FLAC__stream_decoder_get_channels(decoder);
  89538. unsigned bps = FLAC__stream_decoder_get_bits_per_sample(decoder);
  89539. const FLAC__StreamMetadata_SeekTable *seek_table = decoder->private_->has_seek_table? &decoder->private_->seek_table.data.seek_table : 0;
  89540. if(channels == 0)
  89541. channels = decoder->private_->stream_info.data.stream_info.channels;
  89542. if(bps == 0)
  89543. bps = decoder->private_->stream_info.data.stream_info.bits_per_sample;
  89544. if(max_framesize > 0)
  89545. approx_bytes_per_frame = (max_framesize + min_framesize) / 2 + 1;
  89546. else if(min_blocksize == max_blocksize && min_blocksize > 0) {
  89547. approx_bytes_per_frame = min_blocksize * channels * bps/8 + 64;
  89548. }
  89549. else
  89550. approx_bytes_per_frame = 4096 * channels * bps/8 + 64;
  89551. lower_bound = first_frame_offset;
  89552. lower_bound_sample = 0;
  89553. upper_bound = stream_length;
  89554. upper_bound_sample = total_samples > 0 ? total_samples : target_sample /*estimate it*/;
  89555. if(seek_table) {
  89556. FLAC__uint64 new_lower_bound = lower_bound;
  89557. FLAC__uint64 new_upper_bound = upper_bound;
  89558. FLAC__uint64 new_lower_bound_sample = lower_bound_sample;
  89559. FLAC__uint64 new_upper_bound_sample = upper_bound_sample;
  89560. for(i = (int)seek_table->num_points - 1; i >= 0; i--) {
  89561. if(
  89562. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89563. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89564. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89565. seek_table->points[i].sample_number <= target_sample
  89566. )
  89567. break;
  89568. }
  89569. if(i >= 0) { /* i.e. we found a suitable seek point... */
  89570. new_lower_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89571. new_lower_bound_sample = seek_table->points[i].sample_number;
  89572. }
  89573. for(i = 0; i < (int)seek_table->num_points; i++) {
  89574. if(
  89575. seek_table->points[i].sample_number != FLAC__STREAM_METADATA_SEEKPOINT_PLACEHOLDER &&
  89576. seek_table->points[i].frame_samples > 0 && /* defense against bad seekpoints */
  89577. (total_samples <= 0 || seek_table->points[i].sample_number < total_samples) && /* defense against bad seekpoints */
  89578. seek_table->points[i].sample_number > target_sample
  89579. )
  89580. break;
  89581. }
  89582. if(i < (int)seek_table->num_points) { /* i.e. we found a suitable seek point... */
  89583. new_upper_bound = first_frame_offset + seek_table->points[i].stream_offset;
  89584. new_upper_bound_sample = seek_table->points[i].sample_number;
  89585. }
  89586. if(new_upper_bound >= new_lower_bound) {
  89587. lower_bound = new_lower_bound;
  89588. upper_bound = new_upper_bound;
  89589. lower_bound_sample = new_lower_bound_sample;
  89590. upper_bound_sample = new_upper_bound_sample;
  89591. }
  89592. }
  89593. FLAC__ASSERT(upper_bound_sample >= lower_bound_sample);
  89594. if(upper_bound_sample == lower_bound_sample)
  89595. upper_bound_sample++;
  89596. decoder->private_->target_sample = target_sample;
  89597. while(1) {
  89598. if (lower_bound_sample >= upper_bound_sample || lower_bound > upper_bound) {
  89599. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89600. return false;
  89601. }
  89602. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89603. #if defined _MSC_VER || defined __MINGW32__
  89604. 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;
  89605. #else
  89606. 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;
  89607. #endif
  89608. #else
  89609. if(upper_bound - lower_bound < 0xffffffff)
  89610. 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;
  89611. else /* @@@ WATCHOUT, ~2TB limit */
  89612. 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;
  89613. #endif
  89614. if(pos >= (FLAC__int64)upper_bound)
  89615. pos = (FLAC__int64)upper_bound - 1;
  89616. if(pos < (FLAC__int64)lower_bound)
  89617. pos = (FLAC__int64)lower_bound;
  89618. if(decoder->private_->seek_callback(decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89619. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89620. return false;
  89621. }
  89622. if(!FLAC__stream_decoder_flush(decoder)) {
  89623. return false;
  89624. }
  89625. decoder->private_->unparseable_frame_count = 0;
  89626. if(!FLAC__stream_decoder_process_single(decoder)) {
  89627. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89628. return false;
  89629. }
  89630. #if 0
  89631. if(decoder->protected_->state != FLAC__SEEKABLE_STREAM_DECODER_SEEKING && decoder->protected_->state != FLAC__STREAM_DECODER_END_OF_STREAM)
  89632. break;
  89633. #endif
  89634. if(!decoder->private_->is_seeking)
  89635. break;
  89636. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89637. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89638. if (0 == decoder->private_->samples_decoded || (this_frame_sample + decoder->private_->last_frame.header.blocksize >= upper_bound_sample && !first_seek)) {
  89639. if (pos == (FLAC__int64)lower_bound) {
  89640. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89641. return false;
  89642. }
  89643. approx_bytes_per_frame = approx_bytes_per_frame? approx_bytes_per_frame * 2 : 16;
  89644. continue;
  89645. }
  89646. first_seek = false;
  89647. if (this_frame_sample < lower_bound_sample) {
  89648. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89649. return false;
  89650. }
  89651. if(target_sample < this_frame_sample) {
  89652. upper_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89653. if(!FLAC__stream_decoder_get_decode_position(decoder, &upper_bound)) {
  89654. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89655. return false;
  89656. }
  89657. approx_bytes_per_frame = (unsigned)(2 * (upper_bound - pos) / 3 + 16);
  89658. }
  89659. else { /* target_sample >= this_frame_sample + this frame's blocksize */
  89660. lower_bound_sample = this_frame_sample + decoder->private_->last_frame.header.blocksize;
  89661. if(!FLAC__stream_decoder_get_decode_position(decoder, &lower_bound)) {
  89662. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89663. return false;
  89664. }
  89665. approx_bytes_per_frame = (unsigned)(2 * (lower_bound - pos) / 3 + 16);
  89666. }
  89667. }
  89668. return true;
  89669. }
  89670. #if FLAC__HAS_OGG
  89671. FLAC__bool seek_to_absolute_sample_ogg_(FLAC__StreamDecoder *decoder, FLAC__uint64 stream_length, FLAC__uint64 target_sample)
  89672. {
  89673. FLAC__uint64 left_pos = 0, right_pos = stream_length;
  89674. FLAC__uint64 left_sample = 0, right_sample = FLAC__stream_decoder_get_total_samples(decoder);
  89675. FLAC__uint64 this_frame_sample = (FLAC__uint64)0 - 1;
  89676. FLAC__uint64 pos = 0; /* only initialized to avoid compiler warning */
  89677. FLAC__bool did_a_seek;
  89678. unsigned iteration = 0;
  89679. unsigned BINARY_SEARCH_AFTER_ITERATION = 2;
  89680. static const FLAC__uint64 LINEAR_SEARCH_WITHIN_SAMPLES = FLAC__MAX_BLOCK_SIZE * 2;
  89681. if(right_sample == 0) {
  89682. right_sample = (FLAC__uint64)(-1);
  89683. BINARY_SEARCH_AFTER_ITERATION = 0;
  89684. }
  89685. decoder->private_->target_sample = target_sample;
  89686. for( ; ; iteration++) {
  89687. if (iteration == 0 || this_frame_sample > target_sample || target_sample - this_frame_sample > LINEAR_SEARCH_WITHIN_SAMPLES) {
  89688. if (iteration >= BINARY_SEARCH_AFTER_ITERATION) {
  89689. pos = (right_pos + left_pos) / 2;
  89690. }
  89691. else {
  89692. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89693. #if defined _MSC_VER || defined __MINGW32__
  89694. 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));
  89695. #else
  89696. pos = (FLAC__uint64)((FLAC__double)(target_sample - left_sample) / (FLAC__double)(right_sample - left_sample) * (FLAC__double)(right_pos - left_pos));
  89697. #endif
  89698. #else
  89699. if ((target_sample-left_sample <= 0xffffffff) && (right_pos-left_pos <= 0xffffffff))
  89700. pos = (FLAC__int64)(((target_sample-left_sample) * (right_pos-left_pos)) / (right_sample-left_sample));
  89701. else /* @@@ WATCHOUT, ~2TB limit */
  89702. pos = (FLAC__int64)((((target_sample-left_sample)>>8) * ((right_pos-left_pos)>>8)) / ((right_sample-left_sample)>>16));
  89703. #endif
  89704. }
  89705. if(decoder->private_->seek_callback((FLAC__StreamDecoder*)decoder, (FLAC__uint64)pos, decoder->private_->client_data) != FLAC__STREAM_DECODER_SEEK_STATUS_OK) {
  89706. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89707. return false;
  89708. }
  89709. if(!FLAC__stream_decoder_flush(decoder)) {
  89710. return false;
  89711. }
  89712. did_a_seek = true;
  89713. }
  89714. else
  89715. did_a_seek = false;
  89716. decoder->private_->got_a_frame = false;
  89717. if(!FLAC__stream_decoder_process_single(decoder)) {
  89718. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89719. return false;
  89720. }
  89721. if(!decoder->private_->got_a_frame) {
  89722. if(did_a_seek) {
  89723. right_pos = pos;
  89724. BINARY_SEARCH_AFTER_ITERATION = 0;
  89725. }
  89726. else {
  89727. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89728. return false;
  89729. }
  89730. }
  89731. else if(!decoder->private_->is_seeking) {
  89732. break;
  89733. }
  89734. else {
  89735. this_frame_sample = decoder->private_->last_frame.header.number.sample_number;
  89736. FLAC__ASSERT(decoder->private_->last_frame.header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  89737. if (did_a_seek) {
  89738. if (this_frame_sample <= target_sample) {
  89739. FLAC__ASSERT(this_frame_sample != target_sample);
  89740. left_sample = this_frame_sample;
  89741. if (left_pos == pos) {
  89742. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89743. return false;
  89744. }
  89745. left_pos = pos;
  89746. }
  89747. else if(this_frame_sample > target_sample) {
  89748. right_sample = this_frame_sample;
  89749. if (right_pos == pos) {
  89750. decoder->protected_->state = FLAC__STREAM_DECODER_SEEK_ERROR;
  89751. return false;
  89752. }
  89753. right_pos = pos;
  89754. }
  89755. }
  89756. }
  89757. }
  89758. return true;
  89759. }
  89760. #endif
  89761. FLAC__StreamDecoderReadStatus file_read_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  89762. {
  89763. (void)client_data;
  89764. if(*bytes > 0) {
  89765. *bytes = fread(buffer, sizeof(FLAC__byte), *bytes, decoder->private_->file);
  89766. if(ferror(decoder->private_->file))
  89767. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  89768. else if(*bytes == 0)
  89769. return FLAC__STREAM_DECODER_READ_STATUS_END_OF_STREAM;
  89770. else
  89771. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  89772. }
  89773. else
  89774. return FLAC__STREAM_DECODER_READ_STATUS_ABORT; /* abort to avoid a deadlock */
  89775. }
  89776. FLAC__StreamDecoderSeekStatus file_seek_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  89777. {
  89778. (void)client_data;
  89779. if(decoder->private_->file == stdin)
  89780. return FLAC__STREAM_DECODER_SEEK_STATUS_UNSUPPORTED;
  89781. else if(fseeko(decoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  89782. return FLAC__STREAM_DECODER_SEEK_STATUS_ERROR;
  89783. else
  89784. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  89785. }
  89786. FLAC__StreamDecoderTellStatus file_tell_callback_dec(const FLAC__StreamDecoder *decoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  89787. {
  89788. off_t pos;
  89789. (void)client_data;
  89790. if(decoder->private_->file == stdin)
  89791. return FLAC__STREAM_DECODER_TELL_STATUS_UNSUPPORTED;
  89792. else if((pos = ftello(decoder->private_->file)) < 0)
  89793. return FLAC__STREAM_DECODER_TELL_STATUS_ERROR;
  89794. else {
  89795. *absolute_byte_offset = (FLAC__uint64)pos;
  89796. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  89797. }
  89798. }
  89799. FLAC__StreamDecoderLengthStatus file_length_callback_(const FLAC__StreamDecoder *decoder, FLAC__uint64 *stream_length, void *client_data)
  89800. {
  89801. struct stat filestats;
  89802. (void)client_data;
  89803. if(decoder->private_->file == stdin)
  89804. return FLAC__STREAM_DECODER_LENGTH_STATUS_UNSUPPORTED;
  89805. else if(fstat(fileno(decoder->private_->file), &filestats) != 0)
  89806. return FLAC__STREAM_DECODER_LENGTH_STATUS_ERROR;
  89807. else {
  89808. *stream_length = (FLAC__uint64)filestats.st_size;
  89809. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  89810. }
  89811. }
  89812. FLAC__bool file_eof_callback_(const FLAC__StreamDecoder *decoder, void *client_data)
  89813. {
  89814. (void)client_data;
  89815. return feof(decoder->private_->file)? true : false;
  89816. }
  89817. #endif
  89818. /*** End of inlined file: stream_decoder.c ***/
  89819. /*** Start of inlined file: stream_encoder.c ***/
  89820. /*** Start of inlined file: juce_FlacHeader.h ***/
  89821. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  89822. // tasks..
  89823. #define VERSION "1.2.1"
  89824. #define FLAC__NO_DLL 1
  89825. #if JUCE_MSVC
  89826. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  89827. #endif
  89828. #if JUCE_MAC
  89829. #define FLAC__SYS_DARWIN 1
  89830. #endif
  89831. /*** End of inlined file: juce_FlacHeader.h ***/
  89832. #if JUCE_USE_FLAC
  89833. #if HAVE_CONFIG_H
  89834. # include <config.h>
  89835. #endif
  89836. #if defined _MSC_VER || defined __MINGW32__
  89837. #include <io.h> /* for _setmode() */
  89838. #include <fcntl.h> /* for _O_BINARY */
  89839. #endif
  89840. #if defined __CYGWIN__ || defined __EMX__
  89841. #include <io.h> /* for setmode(), O_BINARY */
  89842. #include <fcntl.h> /* for _O_BINARY */
  89843. #endif
  89844. #include <limits.h>
  89845. #include <stdio.h>
  89846. #include <stdlib.h> /* for malloc() */
  89847. #include <string.h> /* for memcpy() */
  89848. #include <sys/types.h> /* for off_t */
  89849. #if defined _MSC_VER || defined __BORLANDC__ || defined __MINGW32__
  89850. #if _MSC_VER <= 1600 || defined __BORLANDC__ /* @@@ [2G limit] */
  89851. #define fseeko fseek
  89852. #define ftello ftell
  89853. #endif
  89854. #endif
  89855. /*** Start of inlined file: stream_encoder.h ***/
  89856. #ifndef FLAC__PROTECTED__STREAM_ENCODER_H
  89857. #define FLAC__PROTECTED__STREAM_ENCODER_H
  89858. #if FLAC__HAS_OGG
  89859. #include "private/ogg_encoder_aspect.h"
  89860. #endif
  89861. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89862. #define FLAC__MAX_APODIZATION_FUNCTIONS 32
  89863. typedef enum {
  89864. FLAC__APODIZATION_BARTLETT,
  89865. FLAC__APODIZATION_BARTLETT_HANN,
  89866. FLAC__APODIZATION_BLACKMAN,
  89867. FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE,
  89868. FLAC__APODIZATION_CONNES,
  89869. FLAC__APODIZATION_FLATTOP,
  89870. FLAC__APODIZATION_GAUSS,
  89871. FLAC__APODIZATION_HAMMING,
  89872. FLAC__APODIZATION_HANN,
  89873. FLAC__APODIZATION_KAISER_BESSEL,
  89874. FLAC__APODIZATION_NUTTALL,
  89875. FLAC__APODIZATION_RECTANGLE,
  89876. FLAC__APODIZATION_TRIANGLE,
  89877. FLAC__APODIZATION_TUKEY,
  89878. FLAC__APODIZATION_WELCH
  89879. } FLAC__ApodizationFunction;
  89880. typedef struct {
  89881. FLAC__ApodizationFunction type;
  89882. union {
  89883. struct {
  89884. FLAC__real stddev;
  89885. } gauss;
  89886. struct {
  89887. FLAC__real p;
  89888. } tukey;
  89889. } parameters;
  89890. } FLAC__ApodizationSpecification;
  89891. #endif // #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89892. typedef struct FLAC__StreamEncoderProtected {
  89893. FLAC__StreamEncoderState state;
  89894. FLAC__bool verify;
  89895. FLAC__bool streamable_subset;
  89896. FLAC__bool do_md5;
  89897. FLAC__bool do_mid_side_stereo;
  89898. FLAC__bool loose_mid_side_stereo;
  89899. unsigned channels;
  89900. unsigned bits_per_sample;
  89901. unsigned sample_rate;
  89902. unsigned blocksize;
  89903. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89904. unsigned num_apodizations;
  89905. FLAC__ApodizationSpecification apodizations[FLAC__MAX_APODIZATION_FUNCTIONS];
  89906. #endif
  89907. unsigned max_lpc_order;
  89908. unsigned qlp_coeff_precision;
  89909. FLAC__bool do_qlp_coeff_prec_search;
  89910. FLAC__bool do_exhaustive_model_search;
  89911. FLAC__bool do_escape_coding;
  89912. unsigned min_residual_partition_order;
  89913. unsigned max_residual_partition_order;
  89914. unsigned rice_parameter_search_dist;
  89915. FLAC__uint64 total_samples_estimate;
  89916. FLAC__StreamMetadata **metadata;
  89917. unsigned num_metadata_blocks;
  89918. FLAC__uint64 streaminfo_offset, seektable_offset, audio_offset;
  89919. #if FLAC__HAS_OGG
  89920. FLAC__OggEncoderAspect ogg_encoder_aspect;
  89921. #endif
  89922. } FLAC__StreamEncoderProtected;
  89923. #endif
  89924. /*** End of inlined file: stream_encoder.h ***/
  89925. #if FLAC__HAS_OGG
  89926. #include "include/private/ogg_helper.h"
  89927. #include "include/private/ogg_mapping.h"
  89928. #endif
  89929. /*** Start of inlined file: stream_encoder_framing.h ***/
  89930. #ifndef FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89931. #define FLAC__PRIVATE__STREAM_ENCODER_FRAMING_H
  89932. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw);
  89933. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw);
  89934. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89935. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89936. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89937. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw);
  89938. #endif
  89939. /*** End of inlined file: stream_encoder_framing.h ***/
  89940. /*** Start of inlined file: window.h ***/
  89941. #ifndef FLAC__PRIVATE__WINDOW_H
  89942. #define FLAC__PRIVATE__WINDOW_H
  89943. #ifdef HAVE_CONFIG_H
  89944. #include <config.h>
  89945. #endif
  89946. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  89947. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L);
  89948. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L);
  89949. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L);
  89950. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L);
  89951. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L);
  89952. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L);
  89953. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev); /* 0.0 < stddev <= 0.5 */
  89954. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L);
  89955. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L);
  89956. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L);
  89957. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L);
  89958. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L);
  89959. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L);
  89960. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p);
  89961. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L);
  89962. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  89963. #endif
  89964. /*** End of inlined file: window.h ***/
  89965. #ifndef FLaC__INLINE
  89966. #define FLaC__INLINE
  89967. #endif
  89968. #ifdef min
  89969. #undef min
  89970. #endif
  89971. #define min(x,y) ((x)<(y)?(x):(y))
  89972. #ifdef max
  89973. #undef max
  89974. #endif
  89975. #define max(x,y) ((x)>(y)?(x):(y))
  89976. #undef EXACT_RICE_BITS_CALCULATION
  89977. #undef ENABLE_RICE_PARAMETER_SEARCH
  89978. typedef struct {
  89979. FLAC__int32 *data[FLAC__MAX_CHANNELS];
  89980. unsigned size; /* of each data[] in samples */
  89981. unsigned tail;
  89982. } verify_input_fifo;
  89983. typedef struct {
  89984. const FLAC__byte *data;
  89985. unsigned capacity;
  89986. unsigned bytes;
  89987. } verify_output;
  89988. typedef enum {
  89989. ENCODER_IN_MAGIC = 0,
  89990. ENCODER_IN_METADATA = 1,
  89991. ENCODER_IN_AUDIO = 2
  89992. } EncoderStateHint;
  89993. static struct CompressionLevels {
  89994. FLAC__bool do_mid_side_stereo;
  89995. FLAC__bool loose_mid_side_stereo;
  89996. unsigned max_lpc_order;
  89997. unsigned qlp_coeff_precision;
  89998. FLAC__bool do_qlp_coeff_prec_search;
  89999. FLAC__bool do_escape_coding;
  90000. FLAC__bool do_exhaustive_model_search;
  90001. unsigned min_residual_partition_order;
  90002. unsigned max_residual_partition_order;
  90003. unsigned rice_parameter_search_dist;
  90004. } compression_levels_[] = {
  90005. { false, false, 0, 0, false, false, false, 0, 3, 0 },
  90006. { true , true , 0, 0, false, false, false, 0, 3, 0 },
  90007. { true , false, 0, 0, false, false, false, 0, 3, 0 },
  90008. { false, false, 6, 0, false, false, false, 0, 4, 0 },
  90009. { true , true , 8, 0, false, false, false, 0, 4, 0 },
  90010. { true , false, 8, 0, false, false, false, 0, 5, 0 },
  90011. { true , false, 8, 0, false, false, false, 0, 6, 0 },
  90012. { true , false, 8, 0, false, false, true , 0, 6, 0 },
  90013. { true , false, 12, 0, false, false, true , 0, 6, 0 }
  90014. };
  90015. static void set_defaults_enc(FLAC__StreamEncoder *encoder);
  90016. static void free_(FLAC__StreamEncoder *encoder);
  90017. static FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize);
  90018. static FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block);
  90019. static FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block);
  90020. static void update_metadata_(const FLAC__StreamEncoder *encoder);
  90021. #if FLAC__HAS_OGG
  90022. static void update_ogg_metadata_(FLAC__StreamEncoder *encoder);
  90023. #endif
  90024. static FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block);
  90025. static FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block);
  90026. static FLAC__bool process_subframe_(
  90027. FLAC__StreamEncoder *encoder,
  90028. unsigned min_partition_order,
  90029. unsigned max_partition_order,
  90030. const FLAC__FrameHeader *frame_header,
  90031. unsigned subframe_bps,
  90032. const FLAC__int32 integer_signal[],
  90033. FLAC__Subframe *subframe[2],
  90034. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  90035. FLAC__int32 *residual[2],
  90036. unsigned *best_subframe,
  90037. unsigned *best_bits
  90038. );
  90039. static FLAC__bool add_subframe_(
  90040. FLAC__StreamEncoder *encoder,
  90041. unsigned blocksize,
  90042. unsigned subframe_bps,
  90043. const FLAC__Subframe *subframe,
  90044. FLAC__BitWriter *frame
  90045. );
  90046. static unsigned evaluate_constant_subframe_(
  90047. FLAC__StreamEncoder *encoder,
  90048. const FLAC__int32 signal,
  90049. unsigned blocksize,
  90050. unsigned subframe_bps,
  90051. FLAC__Subframe *subframe
  90052. );
  90053. static unsigned evaluate_fixed_subframe_(
  90054. FLAC__StreamEncoder *encoder,
  90055. const FLAC__int32 signal[],
  90056. FLAC__int32 residual[],
  90057. FLAC__uint64 abs_residual_partition_sums[],
  90058. unsigned raw_bits_per_partition[],
  90059. unsigned blocksize,
  90060. unsigned subframe_bps,
  90061. unsigned order,
  90062. unsigned rice_parameter,
  90063. unsigned rice_parameter_limit,
  90064. unsigned min_partition_order,
  90065. unsigned max_partition_order,
  90066. FLAC__bool do_escape_coding,
  90067. unsigned rice_parameter_search_dist,
  90068. FLAC__Subframe *subframe,
  90069. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  90070. );
  90071. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90072. static unsigned evaluate_lpc_subframe_(
  90073. FLAC__StreamEncoder *encoder,
  90074. const FLAC__int32 signal[],
  90075. FLAC__int32 residual[],
  90076. FLAC__uint64 abs_residual_partition_sums[],
  90077. unsigned raw_bits_per_partition[],
  90078. const FLAC__real lp_coeff[],
  90079. unsigned blocksize,
  90080. unsigned subframe_bps,
  90081. unsigned order,
  90082. unsigned qlp_coeff_precision,
  90083. unsigned rice_parameter,
  90084. unsigned rice_parameter_limit,
  90085. unsigned min_partition_order,
  90086. unsigned max_partition_order,
  90087. FLAC__bool do_escape_coding,
  90088. unsigned rice_parameter_search_dist,
  90089. FLAC__Subframe *subframe,
  90090. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  90091. );
  90092. #endif
  90093. static unsigned evaluate_verbatim_subframe_(
  90094. FLAC__StreamEncoder *encoder,
  90095. const FLAC__int32 signal[],
  90096. unsigned blocksize,
  90097. unsigned subframe_bps,
  90098. FLAC__Subframe *subframe
  90099. );
  90100. static unsigned find_best_partition_order_(
  90101. struct FLAC__StreamEncoderPrivate *private_,
  90102. const FLAC__int32 residual[],
  90103. FLAC__uint64 abs_residual_partition_sums[],
  90104. unsigned raw_bits_per_partition[],
  90105. unsigned residual_samples,
  90106. unsigned predictor_order,
  90107. unsigned rice_parameter,
  90108. unsigned rice_parameter_limit,
  90109. unsigned min_partition_order,
  90110. unsigned max_partition_order,
  90111. unsigned bps,
  90112. FLAC__bool do_escape_coding,
  90113. unsigned rice_parameter_search_dist,
  90114. FLAC__EntropyCodingMethod *best_ecm
  90115. );
  90116. static void precompute_partition_info_sums_(
  90117. const FLAC__int32 residual[],
  90118. FLAC__uint64 abs_residual_partition_sums[],
  90119. unsigned residual_samples,
  90120. unsigned predictor_order,
  90121. unsigned min_partition_order,
  90122. unsigned max_partition_order,
  90123. unsigned bps
  90124. );
  90125. static void precompute_partition_info_escapes_(
  90126. const FLAC__int32 residual[],
  90127. unsigned raw_bits_per_partition[],
  90128. unsigned residual_samples,
  90129. unsigned predictor_order,
  90130. unsigned min_partition_order,
  90131. unsigned max_partition_order
  90132. );
  90133. static FLAC__bool set_partitioned_rice_(
  90134. #ifdef EXACT_RICE_BITS_CALCULATION
  90135. const FLAC__int32 residual[],
  90136. #endif
  90137. const FLAC__uint64 abs_residual_partition_sums[],
  90138. const unsigned raw_bits_per_partition[],
  90139. const unsigned residual_samples,
  90140. const unsigned predictor_order,
  90141. const unsigned suggested_rice_parameter,
  90142. const unsigned rice_parameter_limit,
  90143. const unsigned rice_parameter_search_dist,
  90144. const unsigned partition_order,
  90145. const FLAC__bool search_for_escapes,
  90146. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  90147. unsigned *bits
  90148. );
  90149. static unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples);
  90150. static void append_to_verify_fifo_(
  90151. verify_input_fifo *fifo,
  90152. const FLAC__int32 * const input[],
  90153. unsigned input_offset,
  90154. unsigned channels,
  90155. unsigned wide_samples
  90156. );
  90157. static void append_to_verify_fifo_interleaved_(
  90158. verify_input_fifo *fifo,
  90159. const FLAC__int32 input[],
  90160. unsigned input_offset,
  90161. unsigned channels,
  90162. unsigned wide_samples
  90163. );
  90164. static FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  90165. static FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data);
  90166. static void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data);
  90167. static void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data);
  90168. static FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data);
  90169. static FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data);
  90170. static FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data);
  90171. 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);
  90172. static FILE *get_binary_stdout_(void);
  90173. typedef struct FLAC__StreamEncoderPrivate {
  90174. unsigned input_capacity; /* current size (in samples) of the signal and residual buffers */
  90175. FLAC__int32 *integer_signal[FLAC__MAX_CHANNELS]; /* the integer version of the input signal */
  90176. FLAC__int32 *integer_signal_mid_side[2]; /* the integer version of the mid-side input signal (stereo only) */
  90177. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90178. FLAC__real *real_signal[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) the floating-point version of the input signal */
  90179. FLAC__real *real_signal_mid_side[2]; /* (@@@ currently unused) the floating-point version of the mid-side input signal (stereo only) */
  90180. FLAC__real *window[FLAC__MAX_APODIZATION_FUNCTIONS]; /* the pre-computed floating-point window for each apodization function */
  90181. FLAC__real *windowed_signal; /* the integer_signal[] * current window[] */
  90182. #endif
  90183. unsigned subframe_bps[FLAC__MAX_CHANNELS]; /* the effective bits per sample of the input signal (stream bps - wasted bits) */
  90184. unsigned subframe_bps_mid_side[2]; /* the effective bits per sample of the mid-side input signal (stream bps - wasted bits + 0/1) */
  90185. FLAC__int32 *residual_workspace[FLAC__MAX_CHANNELS][2]; /* each channel has a candidate and best workspace where the subframe residual signals will be stored */
  90186. FLAC__int32 *residual_workspace_mid_side[2][2];
  90187. FLAC__Subframe subframe_workspace[FLAC__MAX_CHANNELS][2];
  90188. FLAC__Subframe subframe_workspace_mid_side[2][2];
  90189. FLAC__Subframe *subframe_workspace_ptr[FLAC__MAX_CHANNELS][2];
  90190. FLAC__Subframe *subframe_workspace_ptr_mid_side[2][2];
  90191. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace[FLAC__MAX_CHANNELS][2];
  90192. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_workspace_mid_side[FLAC__MAX_CHANNELS][2];
  90193. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr[FLAC__MAX_CHANNELS][2];
  90194. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents_workspace_ptr_mid_side[FLAC__MAX_CHANNELS][2];
  90195. unsigned best_subframe[FLAC__MAX_CHANNELS]; /* index (0 or 1) into 2nd dimension of the above workspaces */
  90196. unsigned best_subframe_mid_side[2];
  90197. unsigned best_subframe_bits[FLAC__MAX_CHANNELS]; /* size in bits of the best subframe for each channel */
  90198. unsigned best_subframe_bits_mid_side[2];
  90199. FLAC__uint64 *abs_residual_partition_sums; /* workspace where the sum of abs(candidate residual) for each partition is stored */
  90200. unsigned *raw_bits_per_partition; /* workspace where the sum of silog2(candidate residual) for each partition is stored */
  90201. FLAC__BitWriter *frame; /* the current frame being worked on */
  90202. unsigned loose_mid_side_stereo_frames; /* rounded number of frames the encoder will use before trying both independent and mid/side frames again */
  90203. unsigned loose_mid_side_stereo_frame_count; /* number of frames using the current channel assignment */
  90204. FLAC__ChannelAssignment last_channel_assignment;
  90205. FLAC__StreamMetadata streaminfo; /* scratchpad for STREAMINFO as it is built */
  90206. FLAC__StreamMetadata_SeekTable *seek_table; /* pointer into encoder->protected_->metadata_ where the seek table is */
  90207. unsigned current_sample_number;
  90208. unsigned current_frame_number;
  90209. FLAC__MD5Context md5context;
  90210. FLAC__CPUInfo cpuinfo;
  90211. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90212. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__float residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  90213. #else
  90214. unsigned (*local_fixed_compute_best_predictor)(const FLAC__int32 data[], unsigned data_len, FLAC__fixedpoint residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1]);
  90215. #endif
  90216. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90217. void (*local_lpc_compute_autocorrelation)(const FLAC__real data[], unsigned data_len, unsigned lag, FLAC__real autoc[]);
  90218. 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[]);
  90219. 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[]);
  90220. 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[]);
  90221. #endif
  90222. FLAC__bool use_wide_by_block; /* use slow 64-bit versions of some functions because of the block size */
  90223. FLAC__bool use_wide_by_partition; /* use slow 64-bit versions of some functions because of the min partition order and blocksize */
  90224. FLAC__bool use_wide_by_order; /* use slow 64-bit versions of some functions because of the lpc order */
  90225. FLAC__bool disable_constant_subframes;
  90226. FLAC__bool disable_fixed_subframes;
  90227. FLAC__bool disable_verbatim_subframes;
  90228. #if FLAC__HAS_OGG
  90229. FLAC__bool is_ogg;
  90230. #endif
  90231. FLAC__StreamEncoderReadCallback read_callback; /* currently only needed for Ogg FLAC */
  90232. FLAC__StreamEncoderSeekCallback seek_callback;
  90233. FLAC__StreamEncoderTellCallback tell_callback;
  90234. FLAC__StreamEncoderWriteCallback write_callback;
  90235. FLAC__StreamEncoderMetadataCallback metadata_callback;
  90236. FLAC__StreamEncoderProgressCallback progress_callback;
  90237. void *client_data;
  90238. unsigned first_seekpoint_to_check;
  90239. FILE *file; /* only used when encoding to a file */
  90240. FLAC__uint64 bytes_written;
  90241. FLAC__uint64 samples_written;
  90242. unsigned frames_written;
  90243. unsigned total_frames_estimate;
  90244. FLAC__int32 *integer_signal_unaligned[FLAC__MAX_CHANNELS];
  90245. FLAC__int32 *integer_signal_mid_side_unaligned[2];
  90246. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90247. FLAC__real *real_signal_unaligned[FLAC__MAX_CHANNELS]; /* (@@@ currently unused) */
  90248. FLAC__real *real_signal_mid_side_unaligned[2]; /* (@@@ currently unused) */
  90249. FLAC__real *window_unaligned[FLAC__MAX_APODIZATION_FUNCTIONS];
  90250. FLAC__real *windowed_signal_unaligned;
  90251. #endif
  90252. FLAC__int32 *residual_workspace_unaligned[FLAC__MAX_CHANNELS][2];
  90253. FLAC__int32 *residual_workspace_mid_side_unaligned[2][2];
  90254. FLAC__uint64 *abs_residual_partition_sums_unaligned;
  90255. unsigned *raw_bits_per_partition_unaligned;
  90256. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90257. FLAC__real lp_coeff[FLAC__MAX_LPC_ORDER][FLAC__MAX_LPC_ORDER]; /* from process_subframe_() */
  90258. #endif
  90259. FLAC__EntropyCodingMethod_PartitionedRiceContents partitioned_rice_contents_extra[2]; /* from find_best_partition_order_() */
  90260. struct {
  90261. FLAC__StreamDecoder *decoder;
  90262. EncoderStateHint state_hint;
  90263. FLAC__bool needs_magic_hack;
  90264. verify_input_fifo input_fifo;
  90265. verify_output output;
  90266. struct {
  90267. FLAC__uint64 absolute_sample;
  90268. unsigned frame_number;
  90269. unsigned channel;
  90270. unsigned sample;
  90271. FLAC__int32 expected;
  90272. FLAC__int32 got;
  90273. } error_stats;
  90274. } verify;
  90275. FLAC__bool is_being_deleted; /* if true, call to ..._finish() from ..._delete() will not call the callbacks */
  90276. } FLAC__StreamEncoderPrivate;
  90277. FLAC_API const char * const FLAC__StreamEncoderStateString[] = {
  90278. "FLAC__STREAM_ENCODER_OK",
  90279. "FLAC__STREAM_ENCODER_UNINITIALIZED",
  90280. "FLAC__STREAM_ENCODER_OGG_ERROR",
  90281. "FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR",
  90282. "FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA",
  90283. "FLAC__STREAM_ENCODER_CLIENT_ERROR",
  90284. "FLAC__STREAM_ENCODER_IO_ERROR",
  90285. "FLAC__STREAM_ENCODER_FRAMING_ERROR",
  90286. "FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR"
  90287. };
  90288. FLAC_API const char * const FLAC__StreamEncoderInitStatusString[] = {
  90289. "FLAC__STREAM_ENCODER_INIT_STATUS_OK",
  90290. "FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR",
  90291. "FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER",
  90292. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS",
  90293. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS",
  90294. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE",
  90295. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE",
  90296. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE",
  90297. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER",
  90298. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION",
  90299. "FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER",
  90300. "FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE",
  90301. "FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA",
  90302. "FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED"
  90303. };
  90304. FLAC_API const char * const FLAC__treamEncoderReadStatusString[] = {
  90305. "FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE",
  90306. "FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM",
  90307. "FLAC__STREAM_ENCODER_READ_STATUS_ABORT",
  90308. "FLAC__STREAM_ENCODER_READ_STATUS_UNSUPPORTED"
  90309. };
  90310. FLAC_API const char * const FLAC__StreamEncoderWriteStatusString[] = {
  90311. "FLAC__STREAM_ENCODER_WRITE_STATUS_OK",
  90312. "FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR"
  90313. };
  90314. FLAC_API const char * const FLAC__StreamEncoderSeekStatusString[] = {
  90315. "FLAC__STREAM_ENCODER_SEEK_STATUS_OK",
  90316. "FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR",
  90317. "FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED"
  90318. };
  90319. FLAC_API const char * const FLAC__StreamEncoderTellStatusString[] = {
  90320. "FLAC__STREAM_ENCODER_TELL_STATUS_OK",
  90321. "FLAC__STREAM_ENCODER_TELL_STATUS_ERROR",
  90322. "FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED"
  90323. };
  90324. static const unsigned OVERREAD_ = 1;
  90325. FLAC_API FLAC__StreamEncoder *FLAC__stream_encoder_new(void)
  90326. {
  90327. FLAC__StreamEncoder *encoder;
  90328. unsigned i;
  90329. FLAC__ASSERT(sizeof(int) >= 4); /* we want to die right away if this is not true */
  90330. encoder = (FLAC__StreamEncoder*)calloc(1, sizeof(FLAC__StreamEncoder));
  90331. if(encoder == 0) {
  90332. return 0;
  90333. }
  90334. encoder->protected_ = (FLAC__StreamEncoderProtected*)calloc(1, sizeof(FLAC__StreamEncoderProtected));
  90335. if(encoder->protected_ == 0) {
  90336. free(encoder);
  90337. return 0;
  90338. }
  90339. encoder->private_ = (FLAC__StreamEncoderPrivate*)calloc(1, sizeof(FLAC__StreamEncoderPrivate));
  90340. if(encoder->private_ == 0) {
  90341. free(encoder->protected_);
  90342. free(encoder);
  90343. return 0;
  90344. }
  90345. encoder->private_->frame = FLAC__bitwriter_new();
  90346. if(encoder->private_->frame == 0) {
  90347. free(encoder->private_);
  90348. free(encoder->protected_);
  90349. free(encoder);
  90350. return 0;
  90351. }
  90352. encoder->private_->file = 0;
  90353. set_defaults_enc(encoder);
  90354. encoder->private_->is_being_deleted = false;
  90355. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90356. encoder->private_->subframe_workspace_ptr[i][0] = &encoder->private_->subframe_workspace[i][0];
  90357. encoder->private_->subframe_workspace_ptr[i][1] = &encoder->private_->subframe_workspace[i][1];
  90358. }
  90359. for(i = 0; i < 2; i++) {
  90360. encoder->private_->subframe_workspace_ptr_mid_side[i][0] = &encoder->private_->subframe_workspace_mid_side[i][0];
  90361. encoder->private_->subframe_workspace_ptr_mid_side[i][1] = &encoder->private_->subframe_workspace_mid_side[i][1];
  90362. }
  90363. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90364. encoder->private_->partitioned_rice_contents_workspace_ptr[i][0] = &encoder->private_->partitioned_rice_contents_workspace[i][0];
  90365. encoder->private_->partitioned_rice_contents_workspace_ptr[i][1] = &encoder->private_->partitioned_rice_contents_workspace[i][1];
  90366. }
  90367. for(i = 0; i < 2; i++) {
  90368. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][0] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0];
  90369. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[i][1] = &encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1];
  90370. }
  90371. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90372. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90373. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90374. }
  90375. for(i = 0; i < 2; i++) {
  90376. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90377. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90378. }
  90379. for(i = 0; i < 2; i++)
  90380. FLAC__format_entropy_coding_method_partitioned_rice_contents_init(&encoder->private_->partitioned_rice_contents_extra[i]);
  90381. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  90382. return encoder;
  90383. }
  90384. FLAC_API void FLAC__stream_encoder_delete(FLAC__StreamEncoder *encoder)
  90385. {
  90386. unsigned i;
  90387. FLAC__ASSERT(0 != encoder);
  90388. FLAC__ASSERT(0 != encoder->protected_);
  90389. FLAC__ASSERT(0 != encoder->private_);
  90390. FLAC__ASSERT(0 != encoder->private_->frame);
  90391. encoder->private_->is_being_deleted = true;
  90392. (void)FLAC__stream_encoder_finish(encoder);
  90393. if(0 != encoder->private_->verify.decoder)
  90394. FLAC__stream_decoder_delete(encoder->private_->verify.decoder);
  90395. for(i = 0; i < FLAC__MAX_CHANNELS; i++) {
  90396. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][0]);
  90397. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace[i][1]);
  90398. }
  90399. for(i = 0; i < 2; i++) {
  90400. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][0]);
  90401. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_workspace_mid_side[i][1]);
  90402. }
  90403. for(i = 0; i < 2; i++)
  90404. FLAC__format_entropy_coding_method_partitioned_rice_contents_clear(&encoder->private_->partitioned_rice_contents_extra[i]);
  90405. FLAC__bitwriter_delete(encoder->private_->frame);
  90406. free(encoder->private_);
  90407. free(encoder->protected_);
  90408. free(encoder);
  90409. }
  90410. static FLAC__StreamEncoderInitStatus init_stream_internal_enc(
  90411. FLAC__StreamEncoder *encoder,
  90412. FLAC__StreamEncoderReadCallback read_callback,
  90413. FLAC__StreamEncoderWriteCallback write_callback,
  90414. FLAC__StreamEncoderSeekCallback seek_callback,
  90415. FLAC__StreamEncoderTellCallback tell_callback,
  90416. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90417. void *client_data,
  90418. FLAC__bool is_ogg
  90419. )
  90420. {
  90421. unsigned i;
  90422. FLAC__bool metadata_has_seektable, metadata_has_vorbis_comment, metadata_picture_has_type1, metadata_picture_has_type2;
  90423. FLAC__ASSERT(0 != encoder);
  90424. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90425. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90426. #if !FLAC__HAS_OGG
  90427. if(is_ogg)
  90428. return FLAC__STREAM_ENCODER_INIT_STATUS_UNSUPPORTED_CONTAINER;
  90429. #endif
  90430. if(0 == write_callback || (seek_callback && 0 == tell_callback))
  90431. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_CALLBACKS;
  90432. if(encoder->protected_->channels == 0 || encoder->protected_->channels > FLAC__MAX_CHANNELS)
  90433. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_NUMBER_OF_CHANNELS;
  90434. if(encoder->protected_->channels != 2) {
  90435. encoder->protected_->do_mid_side_stereo = false;
  90436. encoder->protected_->loose_mid_side_stereo = false;
  90437. }
  90438. else if(!encoder->protected_->do_mid_side_stereo)
  90439. encoder->protected_->loose_mid_side_stereo = false;
  90440. if(encoder->protected_->bits_per_sample >= 32)
  90441. encoder->protected_->do_mid_side_stereo = false; /* since we currenty do 32-bit math, the side channel would have 33 bps and overflow */
  90442. if(encoder->protected_->bits_per_sample < FLAC__MIN_BITS_PER_SAMPLE || encoder->protected_->bits_per_sample > FLAC__REFERENCE_CODEC_MAX_BITS_PER_SAMPLE)
  90443. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BITS_PER_SAMPLE;
  90444. if(!FLAC__format_sample_rate_is_valid(encoder->protected_->sample_rate))
  90445. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_SAMPLE_RATE;
  90446. if(encoder->protected_->blocksize == 0) {
  90447. if(encoder->protected_->max_lpc_order == 0)
  90448. encoder->protected_->blocksize = 1152;
  90449. else
  90450. encoder->protected_->blocksize = 4096;
  90451. }
  90452. if(encoder->protected_->blocksize < FLAC__MIN_BLOCK_SIZE || encoder->protected_->blocksize > FLAC__MAX_BLOCK_SIZE)
  90453. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_BLOCK_SIZE;
  90454. if(encoder->protected_->max_lpc_order > FLAC__MAX_LPC_ORDER)
  90455. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_MAX_LPC_ORDER;
  90456. if(encoder->protected_->blocksize < encoder->protected_->max_lpc_order)
  90457. return FLAC__STREAM_ENCODER_INIT_STATUS_BLOCK_SIZE_TOO_SMALL_FOR_LPC_ORDER;
  90458. if(encoder->protected_->qlp_coeff_precision == 0) {
  90459. if(encoder->protected_->bits_per_sample < 16) {
  90460. encoder->protected_->qlp_coeff_precision = max(FLAC__MIN_QLP_COEFF_PRECISION, 2 + encoder->protected_->bits_per_sample / 2);
  90461. }
  90462. else if(encoder->protected_->bits_per_sample == 16) {
  90463. if(encoder->protected_->blocksize <= 192)
  90464. encoder->protected_->qlp_coeff_precision = 7;
  90465. else if(encoder->protected_->blocksize <= 384)
  90466. encoder->protected_->qlp_coeff_precision = 8;
  90467. else if(encoder->protected_->blocksize <= 576)
  90468. encoder->protected_->qlp_coeff_precision = 9;
  90469. else if(encoder->protected_->blocksize <= 1152)
  90470. encoder->protected_->qlp_coeff_precision = 10;
  90471. else if(encoder->protected_->blocksize <= 2304)
  90472. encoder->protected_->qlp_coeff_precision = 11;
  90473. else if(encoder->protected_->blocksize <= 4608)
  90474. encoder->protected_->qlp_coeff_precision = 12;
  90475. else
  90476. encoder->protected_->qlp_coeff_precision = 13;
  90477. }
  90478. else {
  90479. if(encoder->protected_->blocksize <= 384)
  90480. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-2;
  90481. else if(encoder->protected_->blocksize <= 1152)
  90482. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION-1;
  90483. else
  90484. encoder->protected_->qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  90485. }
  90486. FLAC__ASSERT(encoder->protected_->qlp_coeff_precision <= FLAC__MAX_QLP_COEFF_PRECISION);
  90487. }
  90488. else if(encoder->protected_->qlp_coeff_precision < FLAC__MIN_QLP_COEFF_PRECISION || encoder->protected_->qlp_coeff_precision > FLAC__MAX_QLP_COEFF_PRECISION)
  90489. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_QLP_COEFF_PRECISION;
  90490. if(encoder->protected_->streamable_subset) {
  90491. if(
  90492. encoder->protected_->blocksize != 192 &&
  90493. encoder->protected_->blocksize != 576 &&
  90494. encoder->protected_->blocksize != 1152 &&
  90495. encoder->protected_->blocksize != 2304 &&
  90496. encoder->protected_->blocksize != 4608 &&
  90497. encoder->protected_->blocksize != 256 &&
  90498. encoder->protected_->blocksize != 512 &&
  90499. encoder->protected_->blocksize != 1024 &&
  90500. encoder->protected_->blocksize != 2048 &&
  90501. encoder->protected_->blocksize != 4096 &&
  90502. encoder->protected_->blocksize != 8192 &&
  90503. encoder->protected_->blocksize != 16384
  90504. )
  90505. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90506. if(!FLAC__format_sample_rate_is_subset(encoder->protected_->sample_rate))
  90507. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90508. if(
  90509. encoder->protected_->bits_per_sample != 8 &&
  90510. encoder->protected_->bits_per_sample != 12 &&
  90511. encoder->protected_->bits_per_sample != 16 &&
  90512. encoder->protected_->bits_per_sample != 20 &&
  90513. encoder->protected_->bits_per_sample != 24
  90514. )
  90515. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90516. if(encoder->protected_->max_residual_partition_order > FLAC__SUBSET_MAX_RICE_PARTITION_ORDER)
  90517. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90518. if(
  90519. encoder->protected_->sample_rate <= 48000 &&
  90520. (
  90521. encoder->protected_->blocksize > FLAC__SUBSET_MAX_BLOCK_SIZE_48000HZ ||
  90522. encoder->protected_->max_lpc_order > FLAC__SUBSET_MAX_LPC_ORDER_48000HZ
  90523. )
  90524. ) {
  90525. return FLAC__STREAM_ENCODER_INIT_STATUS_NOT_STREAMABLE;
  90526. }
  90527. }
  90528. if(encoder->protected_->max_residual_partition_order >= (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  90529. encoder->protected_->max_residual_partition_order = (1u << FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN) - 1;
  90530. if(encoder->protected_->min_residual_partition_order >= encoder->protected_->max_residual_partition_order)
  90531. encoder->protected_->min_residual_partition_order = encoder->protected_->max_residual_partition_order;
  90532. #if FLAC__HAS_OGG
  90533. if(is_ogg && 0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 1) {
  90534. unsigned i;
  90535. for(i = 1; i < encoder->protected_->num_metadata_blocks; i++) {
  90536. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90537. FLAC__StreamMetadata *vc = encoder->protected_->metadata[i];
  90538. for( ; i > 0; i--)
  90539. encoder->protected_->metadata[i] = encoder->protected_->metadata[i-1];
  90540. encoder->protected_->metadata[0] = vc;
  90541. break;
  90542. }
  90543. }
  90544. }
  90545. #endif
  90546. if(0 != encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0) {
  90547. unsigned i;
  90548. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90549. if(0 != encoder->protected_->metadata[i] && encoder->protected_->metadata[i]->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90550. encoder->private_->seek_table = &encoder->protected_->metadata[i]->data.seek_table;
  90551. break; /* take only the first one */
  90552. }
  90553. }
  90554. }
  90555. if(0 == encoder->protected_->metadata && encoder->protected_->num_metadata_blocks > 0)
  90556. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90557. metadata_has_seektable = false;
  90558. metadata_has_vorbis_comment = false;
  90559. metadata_picture_has_type1 = false;
  90560. metadata_picture_has_type2 = false;
  90561. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90562. const FLAC__StreamMetadata *m = encoder->protected_->metadata[i];
  90563. if(m->type == FLAC__METADATA_TYPE_STREAMINFO)
  90564. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90565. else if(m->type == FLAC__METADATA_TYPE_SEEKTABLE) {
  90566. if(metadata_has_seektable) /* only one is allowed */
  90567. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90568. metadata_has_seektable = true;
  90569. if(!FLAC__format_seektable_is_legal(&m->data.seek_table))
  90570. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90571. }
  90572. else if(m->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  90573. if(metadata_has_vorbis_comment) /* only one is allowed */
  90574. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90575. metadata_has_vorbis_comment = true;
  90576. }
  90577. else if(m->type == FLAC__METADATA_TYPE_CUESHEET) {
  90578. if(!FLAC__format_cuesheet_is_legal(&m->data.cue_sheet, m->data.cue_sheet.is_cd, /*violation=*/0))
  90579. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90580. }
  90581. else if(m->type == FLAC__METADATA_TYPE_PICTURE) {
  90582. if(!FLAC__format_picture_is_legal(&m->data.picture, /*violation=*/0))
  90583. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90584. if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD) {
  90585. if(metadata_picture_has_type1) /* there should only be 1 per stream */
  90586. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90587. metadata_picture_has_type1 = true;
  90588. if(
  90589. m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON_STANDARD &&
  90590. (
  90591. (strcmp(m->data.picture.mime_type, "image/png") && strcmp(m->data.picture.mime_type, "-->")) ||
  90592. m->data.picture.width != 32 ||
  90593. m->data.picture.height != 32
  90594. )
  90595. )
  90596. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90597. }
  90598. else if(m->data.picture.type == FLAC__STREAM_METADATA_PICTURE_TYPE_FILE_ICON) {
  90599. if(metadata_picture_has_type2) /* there should only be 1 per stream */
  90600. return FLAC__STREAM_ENCODER_INIT_STATUS_INVALID_METADATA;
  90601. metadata_picture_has_type2 = true;
  90602. }
  90603. }
  90604. }
  90605. encoder->private_->input_capacity = 0;
  90606. for(i = 0; i < encoder->protected_->channels; i++) {
  90607. encoder->private_->integer_signal_unaligned[i] = encoder->private_->integer_signal[i] = 0;
  90608. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90609. encoder->private_->real_signal_unaligned[i] = encoder->private_->real_signal[i] = 0;
  90610. #endif
  90611. }
  90612. for(i = 0; i < 2; i++) {
  90613. encoder->private_->integer_signal_mid_side_unaligned[i] = encoder->private_->integer_signal_mid_side[i] = 0;
  90614. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90615. encoder->private_->real_signal_mid_side_unaligned[i] = encoder->private_->real_signal_mid_side[i] = 0;
  90616. #endif
  90617. }
  90618. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90619. for(i = 0; i < encoder->protected_->num_apodizations; i++)
  90620. encoder->private_->window_unaligned[i] = encoder->private_->window[i] = 0;
  90621. encoder->private_->windowed_signal_unaligned = encoder->private_->windowed_signal = 0;
  90622. #endif
  90623. for(i = 0; i < encoder->protected_->channels; i++) {
  90624. encoder->private_->residual_workspace_unaligned[i][0] = encoder->private_->residual_workspace[i][0] = 0;
  90625. encoder->private_->residual_workspace_unaligned[i][1] = encoder->private_->residual_workspace[i][1] = 0;
  90626. encoder->private_->best_subframe[i] = 0;
  90627. }
  90628. for(i = 0; i < 2; i++) {
  90629. encoder->private_->residual_workspace_mid_side_unaligned[i][0] = encoder->private_->residual_workspace_mid_side[i][0] = 0;
  90630. encoder->private_->residual_workspace_mid_side_unaligned[i][1] = encoder->private_->residual_workspace_mid_side[i][1] = 0;
  90631. encoder->private_->best_subframe_mid_side[i] = 0;
  90632. }
  90633. encoder->private_->abs_residual_partition_sums_unaligned = encoder->private_->abs_residual_partition_sums = 0;
  90634. encoder->private_->raw_bits_per_partition_unaligned = encoder->private_->raw_bits_per_partition = 0;
  90635. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90636. encoder->private_->loose_mid_side_stereo_frames = (unsigned)((FLAC__double)encoder->protected_->sample_rate * 0.4 / (FLAC__double)encoder->protected_->blocksize + 0.5);
  90637. #else
  90638. FLAC__ASSERT(FLAC__MAX_SAMPLE_RATE <= 655350);
  90639. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535);
  90640. FLAC__ASSERT(encoder->protected_->sample_rate <= 655350);
  90641. FLAC__ASSERT(encoder->protected_->blocksize <= 65535);
  90642. 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);
  90643. #endif
  90644. if(encoder->private_->loose_mid_side_stereo_frames == 0)
  90645. encoder->private_->loose_mid_side_stereo_frames = 1;
  90646. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  90647. encoder->private_->current_sample_number = 0;
  90648. encoder->private_->current_frame_number = 0;
  90649. encoder->private_->use_wide_by_block = (encoder->protected_->bits_per_sample + FLAC__bitmath_ilog2(encoder->protected_->blocksize)+1 > 30);
  90650. 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? */
  90651. encoder->private_->use_wide_by_partition = (false); /*@@@ need to set this */
  90652. FLAC__cpu_info(&encoder->private_->cpuinfo);
  90653. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90654. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation;
  90655. #endif
  90656. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor;
  90657. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90658. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90659. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit = FLAC__lpc_compute_residual_from_qlp_coefficients_wide;
  90660. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients;
  90661. #endif
  90662. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  90663. # ifndef FLAC__NO_ASM
  90664. if(encoder->private_->cpuinfo.use_asm) {
  90665. # ifdef FLAC__CPU_IA32
  90666. FLAC__ASSERT(encoder->private_->cpuinfo.type == FLAC__CPUINFO_TYPE_IA32);
  90667. # ifdef FLAC__HAS_NASM
  90668. if(encoder->private_->cpuinfo.data.ia32.sse) {
  90669. if(encoder->protected_->max_lpc_order < 4)
  90670. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_4;
  90671. else if(encoder->protected_->max_lpc_order < 8)
  90672. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_8;
  90673. else if(encoder->protected_->max_lpc_order < 12)
  90674. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_sse_lag_12;
  90675. else
  90676. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90677. }
  90678. else if(encoder->private_->cpuinfo.data.ia32._3dnow)
  90679. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32_3dnow;
  90680. else
  90681. encoder->private_->local_lpc_compute_autocorrelation = FLAC__lpc_compute_autocorrelation_asm_ia32;
  90682. if(encoder->private_->cpuinfo.data.ia32.mmx) {
  90683. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90684. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32_mmx;
  90685. }
  90686. else {
  90687. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90688. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit = FLAC__lpc_compute_residual_from_qlp_coefficients_asm_ia32;
  90689. }
  90690. if(encoder->private_->cpuinfo.data.ia32.mmx && encoder->private_->cpuinfo.data.ia32.cmov)
  90691. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_asm_ia32_mmx_cmov;
  90692. # endif /* FLAC__HAS_NASM */
  90693. # endif /* FLAC__CPU_IA32 */
  90694. }
  90695. # endif /* !FLAC__NO_ASM */
  90696. #endif /* !FLAC__INTEGER_ONLY_LIBRARY */
  90697. if(encoder->private_->use_wide_by_block) {
  90698. encoder->private_->local_fixed_compute_best_predictor = FLAC__fixed_compute_best_predictor_wide;
  90699. }
  90700. encoder->protected_->state = FLAC__STREAM_ENCODER_OK;
  90701. #if FLAC__HAS_OGG
  90702. encoder->private_->is_ogg = is_ogg;
  90703. if(is_ogg && !FLAC__ogg_encoder_aspect_init(&encoder->protected_->ogg_encoder_aspect)) {
  90704. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  90705. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90706. }
  90707. #endif
  90708. encoder->private_->read_callback = read_callback;
  90709. encoder->private_->write_callback = write_callback;
  90710. encoder->private_->seek_callback = seek_callback;
  90711. encoder->private_->tell_callback = tell_callback;
  90712. encoder->private_->metadata_callback = metadata_callback;
  90713. encoder->private_->client_data = client_data;
  90714. if(!resize_buffers_(encoder, encoder->protected_->blocksize)) {
  90715. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90716. }
  90717. if(!FLAC__bitwriter_init(encoder->private_->frame)) {
  90718. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90719. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90720. }
  90721. if(encoder->protected_->verify) {
  90722. encoder->private_->verify.input_fifo.size = encoder->protected_->blocksize+OVERREAD_;
  90723. for(i = 0; i < encoder->protected_->channels; i++) {
  90724. 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))) {
  90725. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  90726. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90727. }
  90728. }
  90729. encoder->private_->verify.input_fifo.tail = 0;
  90730. encoder->private_->verify.decoder = FLAC__stream_decoder_new();
  90731. if(0 == encoder->private_->verify.decoder) {
  90732. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90733. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90734. }
  90735. 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) {
  90736. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  90737. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90738. }
  90739. }
  90740. encoder->private_->verify.error_stats.absolute_sample = 0;
  90741. encoder->private_->verify.error_stats.frame_number = 0;
  90742. encoder->private_->verify.error_stats.channel = 0;
  90743. encoder->private_->verify.error_stats.sample = 0;
  90744. encoder->private_->verify.error_stats.expected = 0;
  90745. encoder->private_->verify.error_stats.got = 0;
  90746. encoder->private_->first_seekpoint_to_check = 0;
  90747. encoder->private_->samples_written = 0;
  90748. encoder->protected_->streaminfo_offset = 0;
  90749. encoder->protected_->seektable_offset = 0;
  90750. encoder->protected_->audio_offset = 0;
  90751. if(encoder->protected_->verify)
  90752. encoder->private_->verify.state_hint = ENCODER_IN_MAGIC;
  90753. if(!FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, FLAC__STREAM_SYNC, FLAC__STREAM_SYNC_LEN)) {
  90754. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90755. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90756. }
  90757. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90758. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90759. }
  90760. if(encoder->protected_->verify)
  90761. encoder->private_->verify.state_hint = ENCODER_IN_METADATA;
  90762. encoder->private_->streaminfo.type = FLAC__METADATA_TYPE_STREAMINFO;
  90763. encoder->private_->streaminfo.is_last = false; /* we will have at a minimum a VORBIS_COMMENT afterwards */
  90764. encoder->private_->streaminfo.length = FLAC__STREAM_METADATA_STREAMINFO_LENGTH;
  90765. encoder->private_->streaminfo.data.stream_info.min_blocksize = encoder->protected_->blocksize; /* this encoder uses the same blocksize for the whole stream */
  90766. encoder->private_->streaminfo.data.stream_info.max_blocksize = encoder->protected_->blocksize;
  90767. encoder->private_->streaminfo.data.stream_info.min_framesize = 0; /* we don't know this yet; have to fill it in later */
  90768. encoder->private_->streaminfo.data.stream_info.max_framesize = 0; /* we don't know this yet; have to fill it in later */
  90769. encoder->private_->streaminfo.data.stream_info.sample_rate = encoder->protected_->sample_rate;
  90770. encoder->private_->streaminfo.data.stream_info.channels = encoder->protected_->channels;
  90771. encoder->private_->streaminfo.data.stream_info.bits_per_sample = encoder->protected_->bits_per_sample;
  90772. encoder->private_->streaminfo.data.stream_info.total_samples = encoder->protected_->total_samples_estimate; /* we will replace this later with the real total */
  90773. memset(encoder->private_->streaminfo.data.stream_info.md5sum, 0, 16); /* we don't know this yet; have to fill it in later */
  90774. if(encoder->protected_->do_md5)
  90775. FLAC__MD5Init(&encoder->private_->md5context);
  90776. if(!FLAC__add_metadata_block(&encoder->private_->streaminfo, encoder->private_->frame)) {
  90777. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90778. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90779. }
  90780. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90781. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90782. }
  90783. encoder->private_->streaminfo.data.stream_info.min_framesize = (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN) - 1;
  90784. encoder->private_->streaminfo.data.stream_info.total_samples = 0;
  90785. if(!metadata_has_vorbis_comment) {
  90786. FLAC__StreamMetadata vorbis_comment;
  90787. vorbis_comment.type = FLAC__METADATA_TYPE_VORBIS_COMMENT;
  90788. vorbis_comment.is_last = (encoder->protected_->num_metadata_blocks == 0);
  90789. vorbis_comment.length = 4 + 4; /* MAGIC NUMBER */
  90790. vorbis_comment.data.vorbis_comment.vendor_string.length = 0;
  90791. vorbis_comment.data.vorbis_comment.vendor_string.entry = 0;
  90792. vorbis_comment.data.vorbis_comment.num_comments = 0;
  90793. vorbis_comment.data.vorbis_comment.comments = 0;
  90794. if(!FLAC__add_metadata_block(&vorbis_comment, encoder->private_->frame)) {
  90795. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90796. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90797. }
  90798. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90799. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90800. }
  90801. }
  90802. for(i = 0; i < encoder->protected_->num_metadata_blocks; i++) {
  90803. encoder->protected_->metadata[i]->is_last = (i == encoder->protected_->num_metadata_blocks - 1);
  90804. if(!FLAC__add_metadata_block(encoder->protected_->metadata[i], encoder->private_->frame)) {
  90805. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  90806. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90807. }
  90808. if(!write_bitbuffer_(encoder, 0, /*is_last_block=*/false)) {
  90809. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90810. }
  90811. }
  90812. 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 */
  90813. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  90814. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90815. }
  90816. if(encoder->protected_->verify)
  90817. encoder->private_->verify.state_hint = ENCODER_IN_AUDIO;
  90818. return FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  90819. }
  90820. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_stream(
  90821. FLAC__StreamEncoder *encoder,
  90822. FLAC__StreamEncoderWriteCallback write_callback,
  90823. FLAC__StreamEncoderSeekCallback seek_callback,
  90824. FLAC__StreamEncoderTellCallback tell_callback,
  90825. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90826. void *client_data
  90827. )
  90828. {
  90829. return init_stream_internal_enc(
  90830. encoder,
  90831. 0,
  90832. write_callback,
  90833. seek_callback,
  90834. tell_callback,
  90835. metadata_callback,
  90836. client_data,
  90837. false
  90838. );
  90839. }
  90840. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_stream(
  90841. FLAC__StreamEncoder *encoder,
  90842. FLAC__StreamEncoderReadCallback read_callback,
  90843. FLAC__StreamEncoderWriteCallback write_callback,
  90844. FLAC__StreamEncoderSeekCallback seek_callback,
  90845. FLAC__StreamEncoderTellCallback tell_callback,
  90846. FLAC__StreamEncoderMetadataCallback metadata_callback,
  90847. void *client_data
  90848. )
  90849. {
  90850. return init_stream_internal_enc(
  90851. encoder,
  90852. read_callback,
  90853. write_callback,
  90854. seek_callback,
  90855. tell_callback,
  90856. metadata_callback,
  90857. client_data,
  90858. true
  90859. );
  90860. }
  90861. static FLAC__StreamEncoderInitStatus init_FILE_internal_enc(
  90862. FLAC__StreamEncoder *encoder,
  90863. FILE *file,
  90864. FLAC__StreamEncoderProgressCallback progress_callback,
  90865. void *client_data,
  90866. FLAC__bool is_ogg
  90867. )
  90868. {
  90869. FLAC__StreamEncoderInitStatus init_status;
  90870. FLAC__ASSERT(0 != encoder);
  90871. FLAC__ASSERT(0 != file);
  90872. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90873. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90874. if(file == 0) {
  90875. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90876. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90877. }
  90878. if(file == stdout)
  90879. file = get_binary_stdout_(); /* just to be safe */
  90880. encoder->private_->file = file;
  90881. encoder->private_->progress_callback = progress_callback;
  90882. encoder->private_->bytes_written = 0;
  90883. encoder->private_->samples_written = 0;
  90884. encoder->private_->frames_written = 0;
  90885. init_status = init_stream_internal_enc(
  90886. encoder,
  90887. encoder->private_->file == stdout? 0 : is_ogg? file_read_callback_enc : 0,
  90888. file_write_callback_,
  90889. encoder->private_->file == stdout? 0 : file_seek_callback_enc,
  90890. encoder->private_->file == stdout? 0 : file_tell_callback_enc,
  90891. 0,
  90892. client_data,
  90893. is_ogg
  90894. );
  90895. if(init_status != FLAC__STREAM_ENCODER_INIT_STATUS_OK) {
  90896. return init_status;
  90897. }
  90898. {
  90899. unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  90900. FLAC__ASSERT(blocksize != 0);
  90901. encoder->private_->total_frames_estimate = (unsigned)((FLAC__stream_encoder_get_total_samples_estimate(encoder) + blocksize - 1) / blocksize);
  90902. }
  90903. return init_status;
  90904. }
  90905. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_FILE(
  90906. FLAC__StreamEncoder *encoder,
  90907. FILE *file,
  90908. FLAC__StreamEncoderProgressCallback progress_callback,
  90909. void *client_data
  90910. )
  90911. {
  90912. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/false);
  90913. }
  90914. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_FILE(
  90915. FLAC__StreamEncoder *encoder,
  90916. FILE *file,
  90917. FLAC__StreamEncoderProgressCallback progress_callback,
  90918. void *client_data
  90919. )
  90920. {
  90921. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, /*is_ogg=*/true);
  90922. }
  90923. static FLAC__StreamEncoderInitStatus init_file_internal_enc(
  90924. FLAC__StreamEncoder *encoder,
  90925. const char *filename,
  90926. FLAC__StreamEncoderProgressCallback progress_callback,
  90927. void *client_data,
  90928. FLAC__bool is_ogg
  90929. )
  90930. {
  90931. FILE *file;
  90932. FLAC__ASSERT(0 != encoder);
  90933. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  90934. return FLAC__STREAM_ENCODER_INIT_STATUS_ALREADY_INITIALIZED;
  90935. file = filename? fopen(filename, "w+b") : stdout;
  90936. if(file == 0) {
  90937. encoder->protected_->state = FLAC__STREAM_ENCODER_IO_ERROR;
  90938. return FLAC__STREAM_ENCODER_INIT_STATUS_ENCODER_ERROR;
  90939. }
  90940. return init_FILE_internal_enc(encoder, file, progress_callback, client_data, is_ogg);
  90941. }
  90942. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_file(
  90943. FLAC__StreamEncoder *encoder,
  90944. const char *filename,
  90945. FLAC__StreamEncoderProgressCallback progress_callback,
  90946. void *client_data
  90947. )
  90948. {
  90949. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/false);
  90950. }
  90951. FLAC_API FLAC__StreamEncoderInitStatus FLAC__stream_encoder_init_ogg_file(
  90952. FLAC__StreamEncoder *encoder,
  90953. const char *filename,
  90954. FLAC__StreamEncoderProgressCallback progress_callback,
  90955. void *client_data
  90956. )
  90957. {
  90958. return init_file_internal_enc(encoder, filename, progress_callback, client_data, /*is_ogg=*/true);
  90959. }
  90960. FLAC_API FLAC__bool FLAC__stream_encoder_finish(FLAC__StreamEncoder *encoder)
  90961. {
  90962. FLAC__bool error = false;
  90963. FLAC__ASSERT(0 != encoder);
  90964. FLAC__ASSERT(0 != encoder->private_);
  90965. FLAC__ASSERT(0 != encoder->protected_);
  90966. if(encoder->protected_->state == FLAC__STREAM_ENCODER_UNINITIALIZED)
  90967. return true;
  90968. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK && !encoder->private_->is_being_deleted) {
  90969. if(encoder->private_->current_sample_number != 0) {
  90970. const FLAC__bool is_fractional_block = encoder->protected_->blocksize != encoder->private_->current_sample_number;
  90971. encoder->protected_->blocksize = encoder->private_->current_sample_number;
  90972. if(!process_frame_(encoder, is_fractional_block, /*is_last_block=*/true))
  90973. error = true;
  90974. }
  90975. }
  90976. if(encoder->protected_->do_md5)
  90977. FLAC__MD5Final(encoder->private_->streaminfo.data.stream_info.md5sum, &encoder->private_->md5context);
  90978. if(!encoder->private_->is_being_deleted) {
  90979. if(encoder->protected_->state == FLAC__STREAM_ENCODER_OK) {
  90980. if(encoder->private_->seek_callback) {
  90981. #if FLAC__HAS_OGG
  90982. if(encoder->private_->is_ogg)
  90983. update_ogg_metadata_(encoder);
  90984. else
  90985. #endif
  90986. update_metadata_(encoder);
  90987. if(encoder->protected_->state != FLAC__STREAM_ENCODER_OK)
  90988. error = true;
  90989. }
  90990. if(encoder->private_->metadata_callback)
  90991. encoder->private_->metadata_callback(encoder, &encoder->private_->streaminfo, encoder->private_->client_data);
  90992. }
  90993. if(encoder->protected_->verify && 0 != encoder->private_->verify.decoder && !FLAC__stream_decoder_finish(encoder->private_->verify.decoder)) {
  90994. if(!error)
  90995. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  90996. error = true;
  90997. }
  90998. }
  90999. if(0 != encoder->private_->file) {
  91000. if(encoder->private_->file != stdout)
  91001. fclose(encoder->private_->file);
  91002. encoder->private_->file = 0;
  91003. }
  91004. #if FLAC__HAS_OGG
  91005. if(encoder->private_->is_ogg)
  91006. FLAC__ogg_encoder_aspect_finish(&encoder->protected_->ogg_encoder_aspect);
  91007. #endif
  91008. free_(encoder);
  91009. set_defaults_enc(encoder);
  91010. if(!error)
  91011. encoder->protected_->state = FLAC__STREAM_ENCODER_UNINITIALIZED;
  91012. return !error;
  91013. }
  91014. FLAC_API FLAC__bool FLAC__stream_encoder_set_ogg_serial_number(FLAC__StreamEncoder *encoder, long value)
  91015. {
  91016. FLAC__ASSERT(0 != encoder);
  91017. FLAC__ASSERT(0 != encoder->private_);
  91018. FLAC__ASSERT(0 != encoder->protected_);
  91019. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91020. return false;
  91021. #if FLAC__HAS_OGG
  91022. FLAC__ogg_encoder_aspect_set_serial_number(&encoder->protected_->ogg_encoder_aspect, value);
  91023. return true;
  91024. #else
  91025. (void)value;
  91026. return false;
  91027. #endif
  91028. }
  91029. FLAC_API FLAC__bool FLAC__stream_encoder_set_verify(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91030. {
  91031. FLAC__ASSERT(0 != encoder);
  91032. FLAC__ASSERT(0 != encoder->private_);
  91033. FLAC__ASSERT(0 != encoder->protected_);
  91034. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91035. return false;
  91036. #ifndef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91037. encoder->protected_->verify = value;
  91038. #endif
  91039. return true;
  91040. }
  91041. FLAC_API FLAC__bool FLAC__stream_encoder_set_streamable_subset(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91042. {
  91043. FLAC__ASSERT(0 != encoder);
  91044. FLAC__ASSERT(0 != encoder->private_);
  91045. FLAC__ASSERT(0 != encoder->protected_);
  91046. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91047. return false;
  91048. encoder->protected_->streamable_subset = value;
  91049. return true;
  91050. }
  91051. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_md5(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91052. {
  91053. FLAC__ASSERT(0 != encoder);
  91054. FLAC__ASSERT(0 != encoder->private_);
  91055. FLAC__ASSERT(0 != encoder->protected_);
  91056. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91057. return false;
  91058. encoder->protected_->do_md5 = value;
  91059. return true;
  91060. }
  91061. FLAC_API FLAC__bool FLAC__stream_encoder_set_channels(FLAC__StreamEncoder *encoder, unsigned value)
  91062. {
  91063. FLAC__ASSERT(0 != encoder);
  91064. FLAC__ASSERT(0 != encoder->private_);
  91065. FLAC__ASSERT(0 != encoder->protected_);
  91066. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91067. return false;
  91068. encoder->protected_->channels = value;
  91069. return true;
  91070. }
  91071. FLAC_API FLAC__bool FLAC__stream_encoder_set_bits_per_sample(FLAC__StreamEncoder *encoder, unsigned value)
  91072. {
  91073. FLAC__ASSERT(0 != encoder);
  91074. FLAC__ASSERT(0 != encoder->private_);
  91075. FLAC__ASSERT(0 != encoder->protected_);
  91076. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91077. return false;
  91078. encoder->protected_->bits_per_sample = value;
  91079. return true;
  91080. }
  91081. FLAC_API FLAC__bool FLAC__stream_encoder_set_sample_rate(FLAC__StreamEncoder *encoder, unsigned value)
  91082. {
  91083. FLAC__ASSERT(0 != encoder);
  91084. FLAC__ASSERT(0 != encoder->private_);
  91085. FLAC__ASSERT(0 != encoder->protected_);
  91086. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91087. return false;
  91088. encoder->protected_->sample_rate = value;
  91089. return true;
  91090. }
  91091. FLAC_API FLAC__bool FLAC__stream_encoder_set_compression_level(FLAC__StreamEncoder *encoder, unsigned value)
  91092. {
  91093. FLAC__bool ok = true;
  91094. FLAC__ASSERT(0 != encoder);
  91095. FLAC__ASSERT(0 != encoder->private_);
  91096. FLAC__ASSERT(0 != encoder->protected_);
  91097. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91098. return false;
  91099. if(value >= sizeof(compression_levels_)/sizeof(compression_levels_[0]))
  91100. value = sizeof(compression_levels_)/sizeof(compression_levels_[0]) - 1;
  91101. ok &= FLAC__stream_encoder_set_do_mid_side_stereo (encoder, compression_levels_[value].do_mid_side_stereo);
  91102. ok &= FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, compression_levels_[value].loose_mid_side_stereo);
  91103. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91104. #if 0
  91105. ok &= FLAC__stream_encoder_set_apodization (encoder, compression_levels_[value].apodization);
  91106. #else
  91107. encoder->protected_->num_apodizations = 1;
  91108. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91109. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91110. #endif
  91111. #endif
  91112. ok &= FLAC__stream_encoder_set_max_lpc_order (encoder, compression_levels_[value].max_lpc_order);
  91113. ok &= FLAC__stream_encoder_set_qlp_coeff_precision (encoder, compression_levels_[value].qlp_coeff_precision);
  91114. ok &= FLAC__stream_encoder_set_do_qlp_coeff_prec_search (encoder, compression_levels_[value].do_qlp_coeff_prec_search);
  91115. ok &= FLAC__stream_encoder_set_do_escape_coding (encoder, compression_levels_[value].do_escape_coding);
  91116. ok &= FLAC__stream_encoder_set_do_exhaustive_model_search (encoder, compression_levels_[value].do_exhaustive_model_search);
  91117. ok &= FLAC__stream_encoder_set_min_residual_partition_order(encoder, compression_levels_[value].min_residual_partition_order);
  91118. ok &= FLAC__stream_encoder_set_max_residual_partition_order(encoder, compression_levels_[value].max_residual_partition_order);
  91119. ok &= FLAC__stream_encoder_set_rice_parameter_search_dist (encoder, compression_levels_[value].rice_parameter_search_dist);
  91120. return ok;
  91121. }
  91122. FLAC_API FLAC__bool FLAC__stream_encoder_set_blocksize(FLAC__StreamEncoder *encoder, unsigned value)
  91123. {
  91124. FLAC__ASSERT(0 != encoder);
  91125. FLAC__ASSERT(0 != encoder->private_);
  91126. FLAC__ASSERT(0 != encoder->protected_);
  91127. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91128. return false;
  91129. encoder->protected_->blocksize = value;
  91130. return true;
  91131. }
  91132. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91133. {
  91134. FLAC__ASSERT(0 != encoder);
  91135. FLAC__ASSERT(0 != encoder->private_);
  91136. FLAC__ASSERT(0 != encoder->protected_);
  91137. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91138. return false;
  91139. encoder->protected_->do_mid_side_stereo = value;
  91140. return true;
  91141. }
  91142. FLAC_API FLAC__bool FLAC__stream_encoder_set_loose_mid_side_stereo(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91143. {
  91144. FLAC__ASSERT(0 != encoder);
  91145. FLAC__ASSERT(0 != encoder->private_);
  91146. FLAC__ASSERT(0 != encoder->protected_);
  91147. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91148. return false;
  91149. encoder->protected_->loose_mid_side_stereo = value;
  91150. return true;
  91151. }
  91152. FLAC_API FLAC__bool FLAC__stream_encoder_set_apodization(FLAC__StreamEncoder *encoder, const char *specification)
  91153. {
  91154. FLAC__ASSERT(0 != encoder);
  91155. FLAC__ASSERT(0 != encoder->private_);
  91156. FLAC__ASSERT(0 != encoder->protected_);
  91157. FLAC__ASSERT(0 != specification);
  91158. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91159. return false;
  91160. #ifdef FLAC__INTEGER_ONLY_LIBRARY
  91161. (void)specification; /* silently ignore since we haven't integerized; will always use a rectangular window */
  91162. #else
  91163. encoder->protected_->num_apodizations = 0;
  91164. while(1) {
  91165. const char *s = strchr(specification, ';');
  91166. const size_t n = s? (size_t)(s - specification) : strlen(specification);
  91167. if (n==8 && 0 == strncmp("bartlett" , specification, n))
  91168. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT;
  91169. else if(n==13 && 0 == strncmp("bartlett_hann", specification, n))
  91170. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BARTLETT_HANN;
  91171. else if(n==8 && 0 == strncmp("blackman" , specification, n))
  91172. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN;
  91173. else if(n==26 && 0 == strncmp("blackman_harris_4term_92db", specification, n))
  91174. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE;
  91175. else if(n==6 && 0 == strncmp("connes" , specification, n))
  91176. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_CONNES;
  91177. else if(n==7 && 0 == strncmp("flattop" , specification, n))
  91178. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_FLATTOP;
  91179. else if(n>7 && 0 == strncmp("gauss(" , specification, 6)) {
  91180. FLAC__real stddev = (FLAC__real)strtod(specification+6, 0);
  91181. if (stddev > 0.0 && stddev <= 0.5) {
  91182. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.gauss.stddev = stddev;
  91183. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_GAUSS;
  91184. }
  91185. }
  91186. else if(n==7 && 0 == strncmp("hamming" , specification, n))
  91187. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HAMMING;
  91188. else if(n==4 && 0 == strncmp("hann" , specification, n))
  91189. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_HANN;
  91190. else if(n==13 && 0 == strncmp("kaiser_bessel", specification, n))
  91191. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_KAISER_BESSEL;
  91192. else if(n==7 && 0 == strncmp("nuttall" , specification, n))
  91193. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_NUTTALL;
  91194. else if(n==9 && 0 == strncmp("rectangle" , specification, n))
  91195. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_RECTANGLE;
  91196. else if(n==8 && 0 == strncmp("triangle" , specification, n))
  91197. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TRIANGLE;
  91198. else if(n>7 && 0 == strncmp("tukey(" , specification, 6)) {
  91199. FLAC__real p = (FLAC__real)strtod(specification+6, 0);
  91200. if (p >= 0.0 && p <= 1.0) {
  91201. encoder->protected_->apodizations[encoder->protected_->num_apodizations].parameters.tukey.p = p;
  91202. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_TUKEY;
  91203. }
  91204. }
  91205. else if(n==5 && 0 == strncmp("welch" , specification, n))
  91206. encoder->protected_->apodizations[encoder->protected_->num_apodizations++].type = FLAC__APODIZATION_WELCH;
  91207. if (encoder->protected_->num_apodizations == 32)
  91208. break;
  91209. if (s)
  91210. specification = s+1;
  91211. else
  91212. break;
  91213. }
  91214. if(encoder->protected_->num_apodizations == 0) {
  91215. encoder->protected_->num_apodizations = 1;
  91216. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91217. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91218. }
  91219. #endif
  91220. return true;
  91221. }
  91222. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_lpc_order(FLAC__StreamEncoder *encoder, unsigned value)
  91223. {
  91224. FLAC__ASSERT(0 != encoder);
  91225. FLAC__ASSERT(0 != encoder->private_);
  91226. FLAC__ASSERT(0 != encoder->protected_);
  91227. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91228. return false;
  91229. encoder->protected_->max_lpc_order = value;
  91230. return true;
  91231. }
  91232. FLAC_API FLAC__bool FLAC__stream_encoder_set_qlp_coeff_precision(FLAC__StreamEncoder *encoder, unsigned value)
  91233. {
  91234. FLAC__ASSERT(0 != encoder);
  91235. FLAC__ASSERT(0 != encoder->private_);
  91236. FLAC__ASSERT(0 != encoder->protected_);
  91237. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91238. return false;
  91239. encoder->protected_->qlp_coeff_precision = value;
  91240. return true;
  91241. }
  91242. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_qlp_coeff_prec_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91243. {
  91244. FLAC__ASSERT(0 != encoder);
  91245. FLAC__ASSERT(0 != encoder->private_);
  91246. FLAC__ASSERT(0 != encoder->protected_);
  91247. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91248. return false;
  91249. encoder->protected_->do_qlp_coeff_prec_search = value;
  91250. return true;
  91251. }
  91252. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_escape_coding(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91253. {
  91254. FLAC__ASSERT(0 != encoder);
  91255. FLAC__ASSERT(0 != encoder->private_);
  91256. FLAC__ASSERT(0 != encoder->protected_);
  91257. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91258. return false;
  91259. #if 0
  91260. encoder->protected_->do_escape_coding = value;
  91261. #else
  91262. (void)value;
  91263. #endif
  91264. return true;
  91265. }
  91266. FLAC_API FLAC__bool FLAC__stream_encoder_set_do_exhaustive_model_search(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91267. {
  91268. FLAC__ASSERT(0 != encoder);
  91269. FLAC__ASSERT(0 != encoder->private_);
  91270. FLAC__ASSERT(0 != encoder->protected_);
  91271. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91272. return false;
  91273. encoder->protected_->do_exhaustive_model_search = value;
  91274. return true;
  91275. }
  91276. FLAC_API FLAC__bool FLAC__stream_encoder_set_min_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  91277. {
  91278. FLAC__ASSERT(0 != encoder);
  91279. FLAC__ASSERT(0 != encoder->private_);
  91280. FLAC__ASSERT(0 != encoder->protected_);
  91281. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91282. return false;
  91283. encoder->protected_->min_residual_partition_order = value;
  91284. return true;
  91285. }
  91286. FLAC_API FLAC__bool FLAC__stream_encoder_set_max_residual_partition_order(FLAC__StreamEncoder *encoder, unsigned value)
  91287. {
  91288. FLAC__ASSERT(0 != encoder);
  91289. FLAC__ASSERT(0 != encoder->private_);
  91290. FLAC__ASSERT(0 != encoder->protected_);
  91291. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91292. return false;
  91293. encoder->protected_->max_residual_partition_order = value;
  91294. return true;
  91295. }
  91296. FLAC_API FLAC__bool FLAC__stream_encoder_set_rice_parameter_search_dist(FLAC__StreamEncoder *encoder, unsigned value)
  91297. {
  91298. FLAC__ASSERT(0 != encoder);
  91299. FLAC__ASSERT(0 != encoder->private_);
  91300. FLAC__ASSERT(0 != encoder->protected_);
  91301. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91302. return false;
  91303. #if 0
  91304. encoder->protected_->rice_parameter_search_dist = value;
  91305. #else
  91306. (void)value;
  91307. #endif
  91308. return true;
  91309. }
  91310. FLAC_API FLAC__bool FLAC__stream_encoder_set_total_samples_estimate(FLAC__StreamEncoder *encoder, FLAC__uint64 value)
  91311. {
  91312. FLAC__ASSERT(0 != encoder);
  91313. FLAC__ASSERT(0 != encoder->private_);
  91314. FLAC__ASSERT(0 != encoder->protected_);
  91315. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91316. return false;
  91317. encoder->protected_->total_samples_estimate = value;
  91318. return true;
  91319. }
  91320. FLAC_API FLAC__bool FLAC__stream_encoder_set_metadata(FLAC__StreamEncoder *encoder, FLAC__StreamMetadata **metadata, unsigned num_blocks)
  91321. {
  91322. FLAC__ASSERT(0 != encoder);
  91323. FLAC__ASSERT(0 != encoder->private_);
  91324. FLAC__ASSERT(0 != encoder->protected_);
  91325. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91326. return false;
  91327. if(0 == metadata)
  91328. num_blocks = 0;
  91329. if(0 == num_blocks)
  91330. metadata = 0;
  91331. if(encoder->protected_->metadata) {
  91332. free(encoder->protected_->metadata);
  91333. encoder->protected_->metadata = 0;
  91334. encoder->protected_->num_metadata_blocks = 0;
  91335. }
  91336. if(num_blocks) {
  91337. FLAC__StreamMetadata **m;
  91338. if(0 == (m = (FLAC__StreamMetadata**)safe_malloc_mul_2op_(sizeof(m[0]), /*times*/num_blocks)))
  91339. return false;
  91340. memcpy(m, metadata, sizeof(m[0]) * num_blocks);
  91341. encoder->protected_->metadata = m;
  91342. encoder->protected_->num_metadata_blocks = num_blocks;
  91343. }
  91344. #if FLAC__HAS_OGG
  91345. if(!FLAC__ogg_encoder_aspect_set_num_metadata(&encoder->protected_->ogg_encoder_aspect, num_blocks))
  91346. return false;
  91347. #endif
  91348. return true;
  91349. }
  91350. FLAC_API FLAC__bool FLAC__stream_encoder_disable_constant_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91351. {
  91352. FLAC__ASSERT(0 != encoder);
  91353. FLAC__ASSERT(0 != encoder->private_);
  91354. FLAC__ASSERT(0 != encoder->protected_);
  91355. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91356. return false;
  91357. encoder->private_->disable_constant_subframes = value;
  91358. return true;
  91359. }
  91360. FLAC_API FLAC__bool FLAC__stream_encoder_disable_fixed_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91361. {
  91362. FLAC__ASSERT(0 != encoder);
  91363. FLAC__ASSERT(0 != encoder->private_);
  91364. FLAC__ASSERT(0 != encoder->protected_);
  91365. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91366. return false;
  91367. encoder->private_->disable_fixed_subframes = value;
  91368. return true;
  91369. }
  91370. FLAC_API FLAC__bool FLAC__stream_encoder_disable_verbatim_subframes(FLAC__StreamEncoder *encoder, FLAC__bool value)
  91371. {
  91372. FLAC__ASSERT(0 != encoder);
  91373. FLAC__ASSERT(0 != encoder->private_);
  91374. FLAC__ASSERT(0 != encoder->protected_);
  91375. if(encoder->protected_->state != FLAC__STREAM_ENCODER_UNINITIALIZED)
  91376. return false;
  91377. encoder->private_->disable_verbatim_subframes = value;
  91378. return true;
  91379. }
  91380. FLAC_API FLAC__StreamEncoderState FLAC__stream_encoder_get_state(const FLAC__StreamEncoder *encoder)
  91381. {
  91382. FLAC__ASSERT(0 != encoder);
  91383. FLAC__ASSERT(0 != encoder->private_);
  91384. FLAC__ASSERT(0 != encoder->protected_);
  91385. return encoder->protected_->state;
  91386. }
  91387. FLAC_API FLAC__StreamDecoderState FLAC__stream_encoder_get_verify_decoder_state(const FLAC__StreamEncoder *encoder)
  91388. {
  91389. FLAC__ASSERT(0 != encoder);
  91390. FLAC__ASSERT(0 != encoder->private_);
  91391. FLAC__ASSERT(0 != encoder->protected_);
  91392. if(encoder->protected_->verify)
  91393. return FLAC__stream_decoder_get_state(encoder->private_->verify.decoder);
  91394. else
  91395. return FLAC__STREAM_DECODER_UNINITIALIZED;
  91396. }
  91397. FLAC_API const char *FLAC__stream_encoder_get_resolved_state_string(const FLAC__StreamEncoder *encoder)
  91398. {
  91399. FLAC__ASSERT(0 != encoder);
  91400. FLAC__ASSERT(0 != encoder->private_);
  91401. FLAC__ASSERT(0 != encoder->protected_);
  91402. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR)
  91403. return FLAC__StreamEncoderStateString[encoder->protected_->state];
  91404. else
  91405. return FLAC__stream_decoder_get_resolved_state_string(encoder->private_->verify.decoder);
  91406. }
  91407. 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)
  91408. {
  91409. FLAC__ASSERT(0 != encoder);
  91410. FLAC__ASSERT(0 != encoder->private_);
  91411. FLAC__ASSERT(0 != encoder->protected_);
  91412. if(0 != absolute_sample)
  91413. *absolute_sample = encoder->private_->verify.error_stats.absolute_sample;
  91414. if(0 != frame_number)
  91415. *frame_number = encoder->private_->verify.error_stats.frame_number;
  91416. if(0 != channel)
  91417. *channel = encoder->private_->verify.error_stats.channel;
  91418. if(0 != sample)
  91419. *sample = encoder->private_->verify.error_stats.sample;
  91420. if(0 != expected)
  91421. *expected = encoder->private_->verify.error_stats.expected;
  91422. if(0 != got)
  91423. *got = encoder->private_->verify.error_stats.got;
  91424. }
  91425. FLAC_API FLAC__bool FLAC__stream_encoder_get_verify(const FLAC__StreamEncoder *encoder)
  91426. {
  91427. FLAC__ASSERT(0 != encoder);
  91428. FLAC__ASSERT(0 != encoder->private_);
  91429. FLAC__ASSERT(0 != encoder->protected_);
  91430. return encoder->protected_->verify;
  91431. }
  91432. FLAC_API FLAC__bool FLAC__stream_encoder_get_streamable_subset(const FLAC__StreamEncoder *encoder)
  91433. {
  91434. FLAC__ASSERT(0 != encoder);
  91435. FLAC__ASSERT(0 != encoder->private_);
  91436. FLAC__ASSERT(0 != encoder->protected_);
  91437. return encoder->protected_->streamable_subset;
  91438. }
  91439. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_md5(const FLAC__StreamEncoder *encoder)
  91440. {
  91441. FLAC__ASSERT(0 != encoder);
  91442. FLAC__ASSERT(0 != encoder->private_);
  91443. FLAC__ASSERT(0 != encoder->protected_);
  91444. return encoder->protected_->do_md5;
  91445. }
  91446. FLAC_API unsigned FLAC__stream_encoder_get_channels(const FLAC__StreamEncoder *encoder)
  91447. {
  91448. FLAC__ASSERT(0 != encoder);
  91449. FLAC__ASSERT(0 != encoder->private_);
  91450. FLAC__ASSERT(0 != encoder->protected_);
  91451. return encoder->protected_->channels;
  91452. }
  91453. FLAC_API unsigned FLAC__stream_encoder_get_bits_per_sample(const FLAC__StreamEncoder *encoder)
  91454. {
  91455. FLAC__ASSERT(0 != encoder);
  91456. FLAC__ASSERT(0 != encoder->private_);
  91457. FLAC__ASSERT(0 != encoder->protected_);
  91458. return encoder->protected_->bits_per_sample;
  91459. }
  91460. FLAC_API unsigned FLAC__stream_encoder_get_sample_rate(const FLAC__StreamEncoder *encoder)
  91461. {
  91462. FLAC__ASSERT(0 != encoder);
  91463. FLAC__ASSERT(0 != encoder->private_);
  91464. FLAC__ASSERT(0 != encoder->protected_);
  91465. return encoder->protected_->sample_rate;
  91466. }
  91467. FLAC_API unsigned FLAC__stream_encoder_get_blocksize(const FLAC__StreamEncoder *encoder)
  91468. {
  91469. FLAC__ASSERT(0 != encoder);
  91470. FLAC__ASSERT(0 != encoder->private_);
  91471. FLAC__ASSERT(0 != encoder->protected_);
  91472. return encoder->protected_->blocksize;
  91473. }
  91474. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91475. {
  91476. FLAC__ASSERT(0 != encoder);
  91477. FLAC__ASSERT(0 != encoder->private_);
  91478. FLAC__ASSERT(0 != encoder->protected_);
  91479. return encoder->protected_->do_mid_side_stereo;
  91480. }
  91481. FLAC_API FLAC__bool FLAC__stream_encoder_get_loose_mid_side_stereo(const FLAC__StreamEncoder *encoder)
  91482. {
  91483. FLAC__ASSERT(0 != encoder);
  91484. FLAC__ASSERT(0 != encoder->private_);
  91485. FLAC__ASSERT(0 != encoder->protected_);
  91486. return encoder->protected_->loose_mid_side_stereo;
  91487. }
  91488. FLAC_API unsigned FLAC__stream_encoder_get_max_lpc_order(const FLAC__StreamEncoder *encoder)
  91489. {
  91490. FLAC__ASSERT(0 != encoder);
  91491. FLAC__ASSERT(0 != encoder->private_);
  91492. FLAC__ASSERT(0 != encoder->protected_);
  91493. return encoder->protected_->max_lpc_order;
  91494. }
  91495. FLAC_API unsigned FLAC__stream_encoder_get_qlp_coeff_precision(const FLAC__StreamEncoder *encoder)
  91496. {
  91497. FLAC__ASSERT(0 != encoder);
  91498. FLAC__ASSERT(0 != encoder->private_);
  91499. FLAC__ASSERT(0 != encoder->protected_);
  91500. return encoder->protected_->qlp_coeff_precision;
  91501. }
  91502. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_qlp_coeff_prec_search(const FLAC__StreamEncoder *encoder)
  91503. {
  91504. FLAC__ASSERT(0 != encoder);
  91505. FLAC__ASSERT(0 != encoder->private_);
  91506. FLAC__ASSERT(0 != encoder->protected_);
  91507. return encoder->protected_->do_qlp_coeff_prec_search;
  91508. }
  91509. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_escape_coding(const FLAC__StreamEncoder *encoder)
  91510. {
  91511. FLAC__ASSERT(0 != encoder);
  91512. FLAC__ASSERT(0 != encoder->private_);
  91513. FLAC__ASSERT(0 != encoder->protected_);
  91514. return encoder->protected_->do_escape_coding;
  91515. }
  91516. FLAC_API FLAC__bool FLAC__stream_encoder_get_do_exhaustive_model_search(const FLAC__StreamEncoder *encoder)
  91517. {
  91518. FLAC__ASSERT(0 != encoder);
  91519. FLAC__ASSERT(0 != encoder->private_);
  91520. FLAC__ASSERT(0 != encoder->protected_);
  91521. return encoder->protected_->do_exhaustive_model_search;
  91522. }
  91523. FLAC_API unsigned FLAC__stream_encoder_get_min_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91524. {
  91525. FLAC__ASSERT(0 != encoder);
  91526. FLAC__ASSERT(0 != encoder->private_);
  91527. FLAC__ASSERT(0 != encoder->protected_);
  91528. return encoder->protected_->min_residual_partition_order;
  91529. }
  91530. FLAC_API unsigned FLAC__stream_encoder_get_max_residual_partition_order(const FLAC__StreamEncoder *encoder)
  91531. {
  91532. FLAC__ASSERT(0 != encoder);
  91533. FLAC__ASSERT(0 != encoder->private_);
  91534. FLAC__ASSERT(0 != encoder->protected_);
  91535. return encoder->protected_->max_residual_partition_order;
  91536. }
  91537. FLAC_API unsigned FLAC__stream_encoder_get_rice_parameter_search_dist(const FLAC__StreamEncoder *encoder)
  91538. {
  91539. FLAC__ASSERT(0 != encoder);
  91540. FLAC__ASSERT(0 != encoder->private_);
  91541. FLAC__ASSERT(0 != encoder->protected_);
  91542. return encoder->protected_->rice_parameter_search_dist;
  91543. }
  91544. FLAC_API FLAC__uint64 FLAC__stream_encoder_get_total_samples_estimate(const FLAC__StreamEncoder *encoder)
  91545. {
  91546. FLAC__ASSERT(0 != encoder);
  91547. FLAC__ASSERT(0 != encoder->private_);
  91548. FLAC__ASSERT(0 != encoder->protected_);
  91549. return encoder->protected_->total_samples_estimate;
  91550. }
  91551. FLAC_API FLAC__bool FLAC__stream_encoder_process(FLAC__StreamEncoder *encoder, const FLAC__int32 * const buffer[], unsigned samples)
  91552. {
  91553. unsigned i, j = 0, channel;
  91554. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91555. FLAC__ASSERT(0 != encoder);
  91556. FLAC__ASSERT(0 != encoder->private_);
  91557. FLAC__ASSERT(0 != encoder->protected_);
  91558. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91559. do {
  91560. const unsigned n = min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j);
  91561. if(encoder->protected_->verify)
  91562. append_to_verify_fifo_(&encoder->private_->verify.input_fifo, buffer, j, channels, n);
  91563. for(channel = 0; channel < channels; channel++)
  91564. memcpy(&encoder->private_->integer_signal[channel][encoder->private_->current_sample_number], &buffer[channel][j], sizeof(buffer[channel][0]) * n);
  91565. if(encoder->protected_->do_mid_side_stereo) {
  91566. FLAC__ASSERT(channels == 2);
  91567. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91568. encoder->private_->integer_signal_mid_side[1][i] = buffer[0][j] - buffer[1][j];
  91569. 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' ! */
  91570. }
  91571. }
  91572. else
  91573. j += n;
  91574. encoder->private_->current_sample_number += n;
  91575. if(encoder->private_->current_sample_number > blocksize) {
  91576. FLAC__ASSERT(encoder->private_->current_sample_number == blocksize+OVERREAD_);
  91577. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91578. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91579. return false;
  91580. for(channel = 0; channel < channels; channel++)
  91581. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91582. if(encoder->protected_->do_mid_side_stereo) {
  91583. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91584. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91585. }
  91586. encoder->private_->current_sample_number = 1;
  91587. }
  91588. } while(j < samples);
  91589. return true;
  91590. }
  91591. FLAC_API FLAC__bool FLAC__stream_encoder_process_interleaved(FLAC__StreamEncoder *encoder, const FLAC__int32 buffer[], unsigned samples)
  91592. {
  91593. unsigned i, j, k, channel;
  91594. FLAC__int32 x, mid, side;
  91595. const unsigned channels = encoder->protected_->channels, blocksize = encoder->protected_->blocksize;
  91596. FLAC__ASSERT(0 != encoder);
  91597. FLAC__ASSERT(0 != encoder->private_);
  91598. FLAC__ASSERT(0 != encoder->protected_);
  91599. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91600. j = k = 0;
  91601. if(encoder->protected_->do_mid_side_stereo && channels == 2) {
  91602. do {
  91603. if(encoder->protected_->verify)
  91604. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91605. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91606. encoder->private_->integer_signal[0][i] = mid = side = buffer[k++];
  91607. x = buffer[k++];
  91608. encoder->private_->integer_signal[1][i] = x;
  91609. mid += x;
  91610. side -= x;
  91611. mid >>= 1; /* NOTE: not the same as 'mid = (left + right) / 2' ! */
  91612. encoder->private_->integer_signal_mid_side[1][i] = side;
  91613. encoder->private_->integer_signal_mid_side[0][i] = mid;
  91614. }
  91615. encoder->private_->current_sample_number = i;
  91616. if(i > blocksize) {
  91617. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91618. return false;
  91619. /* move unprocessed overread samples to beginnings of arrays */
  91620. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91621. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91622. encoder->private_->integer_signal[0][0] = encoder->private_->integer_signal[0][blocksize];
  91623. encoder->private_->integer_signal[1][0] = encoder->private_->integer_signal[1][blocksize];
  91624. encoder->private_->integer_signal_mid_side[0][0] = encoder->private_->integer_signal_mid_side[0][blocksize];
  91625. encoder->private_->integer_signal_mid_side[1][0] = encoder->private_->integer_signal_mid_side[1][blocksize];
  91626. encoder->private_->current_sample_number = 1;
  91627. }
  91628. } while(j < samples);
  91629. }
  91630. else {
  91631. do {
  91632. if(encoder->protected_->verify)
  91633. append_to_verify_fifo_interleaved_(&encoder->private_->verify.input_fifo, buffer, j, channels, min(blocksize+OVERREAD_-encoder->private_->current_sample_number, samples-j));
  91634. for(i = encoder->private_->current_sample_number; i <= blocksize && j < samples; i++, j++) {
  91635. for(channel = 0; channel < channels; channel++)
  91636. encoder->private_->integer_signal[channel][i] = buffer[k++];
  91637. }
  91638. encoder->private_->current_sample_number = i;
  91639. if(i > blocksize) {
  91640. if(!process_frame_(encoder, /*is_fractional_block=*/false, /*is_last_block=*/false))
  91641. return false;
  91642. /* move unprocessed overread samples to beginnings of arrays */
  91643. FLAC__ASSERT(i == blocksize+OVERREAD_);
  91644. FLAC__ASSERT(OVERREAD_ == 1); /* assert we only overread 1 sample which simplifies the rest of the code below */
  91645. for(channel = 0; channel < channels; channel++)
  91646. encoder->private_->integer_signal[channel][0] = encoder->private_->integer_signal[channel][blocksize];
  91647. encoder->private_->current_sample_number = 1;
  91648. }
  91649. } while(j < samples);
  91650. }
  91651. return true;
  91652. }
  91653. void set_defaults_enc(FLAC__StreamEncoder *encoder)
  91654. {
  91655. FLAC__ASSERT(0 != encoder);
  91656. #ifdef FLAC__MANDATORY_VERIFY_WHILE_ENCODING
  91657. encoder->protected_->verify = true;
  91658. #else
  91659. encoder->protected_->verify = false;
  91660. #endif
  91661. encoder->protected_->streamable_subset = true;
  91662. encoder->protected_->do_md5 = true;
  91663. encoder->protected_->do_mid_side_stereo = false;
  91664. encoder->protected_->loose_mid_side_stereo = false;
  91665. encoder->protected_->channels = 2;
  91666. encoder->protected_->bits_per_sample = 16;
  91667. encoder->protected_->sample_rate = 44100;
  91668. encoder->protected_->blocksize = 0;
  91669. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91670. encoder->protected_->num_apodizations = 1;
  91671. encoder->protected_->apodizations[0].type = FLAC__APODIZATION_TUKEY;
  91672. encoder->protected_->apodizations[0].parameters.tukey.p = 0.5;
  91673. #endif
  91674. encoder->protected_->max_lpc_order = 0;
  91675. encoder->protected_->qlp_coeff_precision = 0;
  91676. encoder->protected_->do_qlp_coeff_prec_search = false;
  91677. encoder->protected_->do_exhaustive_model_search = false;
  91678. encoder->protected_->do_escape_coding = false;
  91679. encoder->protected_->min_residual_partition_order = 0;
  91680. encoder->protected_->max_residual_partition_order = 0;
  91681. encoder->protected_->rice_parameter_search_dist = 0;
  91682. encoder->protected_->total_samples_estimate = 0;
  91683. encoder->protected_->metadata = 0;
  91684. encoder->protected_->num_metadata_blocks = 0;
  91685. encoder->private_->seek_table = 0;
  91686. encoder->private_->disable_constant_subframes = false;
  91687. encoder->private_->disable_fixed_subframes = false;
  91688. encoder->private_->disable_verbatim_subframes = false;
  91689. #if FLAC__HAS_OGG
  91690. encoder->private_->is_ogg = false;
  91691. #endif
  91692. encoder->private_->read_callback = 0;
  91693. encoder->private_->write_callback = 0;
  91694. encoder->private_->seek_callback = 0;
  91695. encoder->private_->tell_callback = 0;
  91696. encoder->private_->metadata_callback = 0;
  91697. encoder->private_->progress_callback = 0;
  91698. encoder->private_->client_data = 0;
  91699. #if FLAC__HAS_OGG
  91700. FLAC__ogg_encoder_aspect_set_defaults(&encoder->protected_->ogg_encoder_aspect);
  91701. #endif
  91702. }
  91703. void free_(FLAC__StreamEncoder *encoder)
  91704. {
  91705. unsigned i, channel;
  91706. FLAC__ASSERT(0 != encoder);
  91707. if(encoder->protected_->metadata) {
  91708. free(encoder->protected_->metadata);
  91709. encoder->protected_->metadata = 0;
  91710. encoder->protected_->num_metadata_blocks = 0;
  91711. }
  91712. for(i = 0; i < encoder->protected_->channels; i++) {
  91713. if(0 != encoder->private_->integer_signal_unaligned[i]) {
  91714. free(encoder->private_->integer_signal_unaligned[i]);
  91715. encoder->private_->integer_signal_unaligned[i] = 0;
  91716. }
  91717. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91718. if(0 != encoder->private_->real_signal_unaligned[i]) {
  91719. free(encoder->private_->real_signal_unaligned[i]);
  91720. encoder->private_->real_signal_unaligned[i] = 0;
  91721. }
  91722. #endif
  91723. }
  91724. for(i = 0; i < 2; i++) {
  91725. if(0 != encoder->private_->integer_signal_mid_side_unaligned[i]) {
  91726. free(encoder->private_->integer_signal_mid_side_unaligned[i]);
  91727. encoder->private_->integer_signal_mid_side_unaligned[i] = 0;
  91728. }
  91729. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91730. if(0 != encoder->private_->real_signal_mid_side_unaligned[i]) {
  91731. free(encoder->private_->real_signal_mid_side_unaligned[i]);
  91732. encoder->private_->real_signal_mid_side_unaligned[i] = 0;
  91733. }
  91734. #endif
  91735. }
  91736. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91737. for(i = 0; i < encoder->protected_->num_apodizations; i++) {
  91738. if(0 != encoder->private_->window_unaligned[i]) {
  91739. free(encoder->private_->window_unaligned[i]);
  91740. encoder->private_->window_unaligned[i] = 0;
  91741. }
  91742. }
  91743. if(0 != encoder->private_->windowed_signal_unaligned) {
  91744. free(encoder->private_->windowed_signal_unaligned);
  91745. encoder->private_->windowed_signal_unaligned = 0;
  91746. }
  91747. #endif
  91748. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  91749. for(i = 0; i < 2; i++) {
  91750. if(0 != encoder->private_->residual_workspace_unaligned[channel][i]) {
  91751. free(encoder->private_->residual_workspace_unaligned[channel][i]);
  91752. encoder->private_->residual_workspace_unaligned[channel][i] = 0;
  91753. }
  91754. }
  91755. }
  91756. for(channel = 0; channel < 2; channel++) {
  91757. for(i = 0; i < 2; i++) {
  91758. if(0 != encoder->private_->residual_workspace_mid_side_unaligned[channel][i]) {
  91759. free(encoder->private_->residual_workspace_mid_side_unaligned[channel][i]);
  91760. encoder->private_->residual_workspace_mid_side_unaligned[channel][i] = 0;
  91761. }
  91762. }
  91763. }
  91764. if(0 != encoder->private_->abs_residual_partition_sums_unaligned) {
  91765. free(encoder->private_->abs_residual_partition_sums_unaligned);
  91766. encoder->private_->abs_residual_partition_sums_unaligned = 0;
  91767. }
  91768. if(0 != encoder->private_->raw_bits_per_partition_unaligned) {
  91769. free(encoder->private_->raw_bits_per_partition_unaligned);
  91770. encoder->private_->raw_bits_per_partition_unaligned = 0;
  91771. }
  91772. if(encoder->protected_->verify) {
  91773. for(i = 0; i < encoder->protected_->channels; i++) {
  91774. if(0 != encoder->private_->verify.input_fifo.data[i]) {
  91775. free(encoder->private_->verify.input_fifo.data[i]);
  91776. encoder->private_->verify.input_fifo.data[i] = 0;
  91777. }
  91778. }
  91779. }
  91780. FLAC__bitwriter_free(encoder->private_->frame);
  91781. }
  91782. FLAC__bool resize_buffers_(FLAC__StreamEncoder *encoder, unsigned new_blocksize)
  91783. {
  91784. FLAC__bool ok;
  91785. unsigned i, channel;
  91786. FLAC__ASSERT(new_blocksize > 0);
  91787. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  91788. FLAC__ASSERT(encoder->private_->current_sample_number == 0);
  91789. if(new_blocksize <= encoder->private_->input_capacity)
  91790. return true;
  91791. ok = true;
  91792. for(i = 0; ok && i < encoder->protected_->channels; i++) {
  91793. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize+4+OVERREAD_, &encoder->private_->integer_signal_unaligned[i], &encoder->private_->integer_signal[i]);
  91794. memset(encoder->private_->integer_signal[i], 0, sizeof(FLAC__int32)*4);
  91795. encoder->private_->integer_signal[i] += 4;
  91796. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91797. #if 0 /* @@@ currently unused */
  91798. if(encoder->protected_->max_lpc_order > 0)
  91799. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize+OVERREAD_, &encoder->private_->real_signal_unaligned[i], &encoder->private_->real_signal[i]);
  91800. #endif
  91801. #endif
  91802. }
  91803. for(i = 0; ok && i < 2; i++) {
  91804. 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]);
  91805. memset(encoder->private_->integer_signal_mid_side[i], 0, sizeof(FLAC__int32)*4);
  91806. encoder->private_->integer_signal_mid_side[i] += 4;
  91807. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91808. #if 0 /* @@@ currently unused */
  91809. if(encoder->protected_->max_lpc_order > 0)
  91810. 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]);
  91811. #endif
  91812. #endif
  91813. }
  91814. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91815. if(ok && encoder->protected_->max_lpc_order > 0) {
  91816. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++)
  91817. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->window_unaligned[i], &encoder->private_->window[i]);
  91818. ok = ok && FLAC__memory_alloc_aligned_real_array(new_blocksize, &encoder->private_->windowed_signal_unaligned, &encoder->private_->windowed_signal);
  91819. }
  91820. #endif
  91821. for(channel = 0; ok && channel < encoder->protected_->channels; channel++) {
  91822. for(i = 0; ok && i < 2; i++) {
  91823. ok = ok && FLAC__memory_alloc_aligned_int32_array(new_blocksize, &encoder->private_->residual_workspace_unaligned[channel][i], &encoder->private_->residual_workspace[channel][i]);
  91824. }
  91825. }
  91826. for(channel = 0; ok && channel < 2; channel++) {
  91827. for(i = 0; ok && i < 2; i++) {
  91828. 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]);
  91829. }
  91830. }
  91831. ok = ok && FLAC__memory_alloc_aligned_uint64_array(new_blocksize * 2, &encoder->private_->abs_residual_partition_sums_unaligned, &encoder->private_->abs_residual_partition_sums);
  91832. if(encoder->protected_->do_escape_coding)
  91833. ok = ok && FLAC__memory_alloc_aligned_unsigned_array(new_blocksize * 2, &encoder->private_->raw_bits_per_partition_unaligned, &encoder->private_->raw_bits_per_partition);
  91834. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  91835. if(ok && new_blocksize != encoder->private_->input_capacity && encoder->protected_->max_lpc_order > 0) {
  91836. for(i = 0; ok && i < encoder->protected_->num_apodizations; i++) {
  91837. switch(encoder->protected_->apodizations[i].type) {
  91838. case FLAC__APODIZATION_BARTLETT:
  91839. FLAC__window_bartlett(encoder->private_->window[i], new_blocksize);
  91840. break;
  91841. case FLAC__APODIZATION_BARTLETT_HANN:
  91842. FLAC__window_bartlett_hann(encoder->private_->window[i], new_blocksize);
  91843. break;
  91844. case FLAC__APODIZATION_BLACKMAN:
  91845. FLAC__window_blackman(encoder->private_->window[i], new_blocksize);
  91846. break;
  91847. case FLAC__APODIZATION_BLACKMAN_HARRIS_4TERM_92DB_SIDELOBE:
  91848. FLAC__window_blackman_harris_4term_92db_sidelobe(encoder->private_->window[i], new_blocksize);
  91849. break;
  91850. case FLAC__APODIZATION_CONNES:
  91851. FLAC__window_connes(encoder->private_->window[i], new_blocksize);
  91852. break;
  91853. case FLAC__APODIZATION_FLATTOP:
  91854. FLAC__window_flattop(encoder->private_->window[i], new_blocksize);
  91855. break;
  91856. case FLAC__APODIZATION_GAUSS:
  91857. FLAC__window_gauss(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.gauss.stddev);
  91858. break;
  91859. case FLAC__APODIZATION_HAMMING:
  91860. FLAC__window_hamming(encoder->private_->window[i], new_blocksize);
  91861. break;
  91862. case FLAC__APODIZATION_HANN:
  91863. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91864. break;
  91865. case FLAC__APODIZATION_KAISER_BESSEL:
  91866. FLAC__window_kaiser_bessel(encoder->private_->window[i], new_blocksize);
  91867. break;
  91868. case FLAC__APODIZATION_NUTTALL:
  91869. FLAC__window_nuttall(encoder->private_->window[i], new_blocksize);
  91870. break;
  91871. case FLAC__APODIZATION_RECTANGLE:
  91872. FLAC__window_rectangle(encoder->private_->window[i], new_blocksize);
  91873. break;
  91874. case FLAC__APODIZATION_TRIANGLE:
  91875. FLAC__window_triangle(encoder->private_->window[i], new_blocksize);
  91876. break;
  91877. case FLAC__APODIZATION_TUKEY:
  91878. FLAC__window_tukey(encoder->private_->window[i], new_blocksize, encoder->protected_->apodizations[i].parameters.tukey.p);
  91879. break;
  91880. case FLAC__APODIZATION_WELCH:
  91881. FLAC__window_welch(encoder->private_->window[i], new_blocksize);
  91882. break;
  91883. default:
  91884. FLAC__ASSERT(0);
  91885. FLAC__window_hann(encoder->private_->window[i], new_blocksize);
  91886. break;
  91887. }
  91888. }
  91889. }
  91890. #endif
  91891. if(ok)
  91892. encoder->private_->input_capacity = new_blocksize;
  91893. else
  91894. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91895. return ok;
  91896. }
  91897. FLAC__bool write_bitbuffer_(FLAC__StreamEncoder *encoder, unsigned samples, FLAC__bool is_last_block)
  91898. {
  91899. const FLAC__byte *buffer;
  91900. size_t bytes;
  91901. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  91902. if(!FLAC__bitwriter_get_buffer(encoder->private_->frame, &buffer, &bytes)) {
  91903. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  91904. return false;
  91905. }
  91906. if(encoder->protected_->verify) {
  91907. encoder->private_->verify.output.data = buffer;
  91908. encoder->private_->verify.output.bytes = bytes;
  91909. if(encoder->private_->verify.state_hint == ENCODER_IN_MAGIC) {
  91910. encoder->private_->verify.needs_magic_hack = true;
  91911. }
  91912. else {
  91913. if(!FLAC__stream_decoder_process_single(encoder->private_->verify.decoder)) {
  91914. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91915. FLAC__bitwriter_clear(encoder->private_->frame);
  91916. if(encoder->protected_->state != FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA)
  91917. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  91918. return false;
  91919. }
  91920. }
  91921. }
  91922. if(write_frame_(encoder, buffer, bytes, samples, is_last_block) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91923. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91924. FLAC__bitwriter_clear(encoder->private_->frame);
  91925. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91926. return false;
  91927. }
  91928. FLAC__bitwriter_release_buffer(encoder->private_->frame);
  91929. FLAC__bitwriter_clear(encoder->private_->frame);
  91930. if(samples > 0) {
  91931. encoder->private_->streaminfo.data.stream_info.min_framesize = min(bytes, encoder->private_->streaminfo.data.stream_info.min_framesize);
  91932. encoder->private_->streaminfo.data.stream_info.max_framesize = max(bytes, encoder->private_->streaminfo.data.stream_info.max_framesize);
  91933. }
  91934. return true;
  91935. }
  91936. FLAC__StreamEncoderWriteStatus write_frame_(FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, FLAC__bool is_last_block)
  91937. {
  91938. FLAC__StreamEncoderWriteStatus status;
  91939. FLAC__uint64 output_position = 0;
  91940. if(encoder->private_->tell_callback && encoder->private_->tell_callback(encoder, &output_position, encoder->private_->client_data) == FLAC__STREAM_ENCODER_TELL_STATUS_ERROR) {
  91941. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91942. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  91943. }
  91944. if(samples == 0) {
  91945. FLAC__MetadataType type = (FLAC__MetadataType) (buffer[0] & 0x7f);
  91946. if(type == FLAC__METADATA_TYPE_STREAMINFO)
  91947. encoder->protected_->streaminfo_offset = output_position;
  91948. else if(type == FLAC__METADATA_TYPE_SEEKTABLE && encoder->protected_->seektable_offset == 0)
  91949. encoder->protected_->seektable_offset = output_position;
  91950. }
  91951. if(0 != encoder->private_->seek_table && encoder->protected_->audio_offset > 0 && encoder->private_->seek_table->num_points > 0) {
  91952. const unsigned blocksize = FLAC__stream_encoder_get_blocksize(encoder);
  91953. const FLAC__uint64 frame_first_sample = encoder->private_->samples_written;
  91954. const FLAC__uint64 frame_last_sample = frame_first_sample + (FLAC__uint64)blocksize - 1;
  91955. FLAC__uint64 test_sample;
  91956. unsigned i;
  91957. for(i = encoder->private_->first_seekpoint_to_check; i < encoder->private_->seek_table->num_points; i++) {
  91958. test_sample = encoder->private_->seek_table->points[i].sample_number;
  91959. if(test_sample > frame_last_sample) {
  91960. break;
  91961. }
  91962. else if(test_sample >= frame_first_sample) {
  91963. encoder->private_->seek_table->points[i].sample_number = frame_first_sample;
  91964. encoder->private_->seek_table->points[i].stream_offset = output_position - encoder->protected_->audio_offset;
  91965. encoder->private_->seek_table->points[i].frame_samples = blocksize;
  91966. encoder->private_->first_seekpoint_to_check++;
  91967. }
  91968. else {
  91969. encoder->private_->first_seekpoint_to_check++;
  91970. }
  91971. }
  91972. }
  91973. #if FLAC__HAS_OGG
  91974. if(encoder->private_->is_ogg) {
  91975. status = FLAC__ogg_encoder_aspect_write_callback_wrapper(
  91976. &encoder->protected_->ogg_encoder_aspect,
  91977. buffer,
  91978. bytes,
  91979. samples,
  91980. encoder->private_->current_frame_number,
  91981. is_last_block,
  91982. (FLAC__OggEncoderAspectWriteCallbackProxy)encoder->private_->write_callback,
  91983. encoder,
  91984. encoder->private_->client_data
  91985. );
  91986. }
  91987. else
  91988. #endif
  91989. status = encoder->private_->write_callback(encoder, buffer, bytes, samples, encoder->private_->current_frame_number, encoder->private_->client_data);
  91990. if(status == FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  91991. encoder->private_->bytes_written += bytes;
  91992. encoder->private_->samples_written += samples;
  91993. encoder->private_->frames_written = max(encoder->private_->frames_written, encoder->private_->current_frame_number+1);
  91994. }
  91995. else
  91996. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  91997. return status;
  91998. }
  91999. void update_metadata_(const FLAC__StreamEncoder *encoder)
  92000. {
  92001. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  92002. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  92003. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  92004. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  92005. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  92006. const unsigned bps = metadata->data.stream_info.bits_per_sample;
  92007. FLAC__StreamEncoderSeekStatus seek_status;
  92008. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  92009. {
  92010. const unsigned md5_offset =
  92011. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92012. (
  92013. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92014. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92015. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92016. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92017. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92018. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92019. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  92020. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  92021. ) / 8;
  92022. if((seek_status = encoder->private_->seek_callback(encoder, encoder->protected_->streaminfo_offset + md5_offset, encoder->private_->client_data)) != FLAC__STREAM_ENCODER_SEEK_STATUS_OK) {
  92023. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92024. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92025. return;
  92026. }
  92027. if(encoder->private_->write_callback(encoder, metadata->data.stream_info.md5sum, 16, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92028. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92029. return;
  92030. }
  92031. }
  92032. {
  92033. const unsigned total_samples_byte_offset =
  92034. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92035. (
  92036. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92037. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92038. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92039. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92040. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92041. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92042. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  92043. - 4
  92044. ) / 8;
  92045. b[0] = ((FLAC__byte)(bps-1) << 4) | (FLAC__byte)((samples >> 32) & 0x0F);
  92046. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  92047. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  92048. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  92049. b[4] = (FLAC__byte)(samples & 0xFF);
  92050. 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) {
  92051. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92052. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92053. return;
  92054. }
  92055. if(encoder->private_->write_callback(encoder, b, 5, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92056. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92057. return;
  92058. }
  92059. }
  92060. {
  92061. const unsigned min_framesize_offset =
  92062. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92063. (
  92064. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92065. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  92066. ) / 8;
  92067. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  92068. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  92069. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  92070. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  92071. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  92072. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  92073. 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) {
  92074. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92075. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92076. return;
  92077. }
  92078. if(encoder->private_->write_callback(encoder, b, 6, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92079. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92080. return;
  92081. }
  92082. }
  92083. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  92084. unsigned i;
  92085. FLAC__format_seektable_sort(encoder->private_->seek_table);
  92086. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  92087. 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) {
  92088. if(seek_status == FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR)
  92089. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92090. return;
  92091. }
  92092. for(i = 0; i < encoder->private_->seek_table->num_points; i++) {
  92093. FLAC__uint64 xx;
  92094. unsigned x;
  92095. xx = encoder->private_->seek_table->points[i].sample_number;
  92096. b[7] = (FLAC__byte)xx; xx >>= 8;
  92097. b[6] = (FLAC__byte)xx; xx >>= 8;
  92098. b[5] = (FLAC__byte)xx; xx >>= 8;
  92099. b[4] = (FLAC__byte)xx; xx >>= 8;
  92100. b[3] = (FLAC__byte)xx; xx >>= 8;
  92101. b[2] = (FLAC__byte)xx; xx >>= 8;
  92102. b[1] = (FLAC__byte)xx; xx >>= 8;
  92103. b[0] = (FLAC__byte)xx; xx >>= 8;
  92104. xx = encoder->private_->seek_table->points[i].stream_offset;
  92105. b[15] = (FLAC__byte)xx; xx >>= 8;
  92106. b[14] = (FLAC__byte)xx; xx >>= 8;
  92107. b[13] = (FLAC__byte)xx; xx >>= 8;
  92108. b[12] = (FLAC__byte)xx; xx >>= 8;
  92109. b[11] = (FLAC__byte)xx; xx >>= 8;
  92110. b[10] = (FLAC__byte)xx; xx >>= 8;
  92111. b[9] = (FLAC__byte)xx; xx >>= 8;
  92112. b[8] = (FLAC__byte)xx; xx >>= 8;
  92113. x = encoder->private_->seek_table->points[i].frame_samples;
  92114. b[17] = (FLAC__byte)x; x >>= 8;
  92115. b[16] = (FLAC__byte)x; x >>= 8;
  92116. if(encoder->private_->write_callback(encoder, b, 18, 0, 0, encoder->private_->client_data) != FLAC__STREAM_ENCODER_WRITE_STATUS_OK) {
  92117. encoder->protected_->state = FLAC__STREAM_ENCODER_CLIENT_ERROR;
  92118. return;
  92119. }
  92120. }
  92121. }
  92122. }
  92123. #if FLAC__HAS_OGG
  92124. void update_ogg_metadata_(FLAC__StreamEncoder *encoder)
  92125. {
  92126. static const unsigned FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH =
  92127. FLAC__OGG_MAPPING_PACKET_TYPE_LENGTH +
  92128. FLAC__OGG_MAPPING_MAGIC_LENGTH +
  92129. FLAC__OGG_MAPPING_VERSION_MAJOR_LENGTH +
  92130. FLAC__OGG_MAPPING_VERSION_MINOR_LENGTH +
  92131. FLAC__OGG_MAPPING_NUM_HEADERS_LENGTH +
  92132. FLAC__STREAM_SYNC_LENGTH
  92133. ;
  92134. FLAC__byte b[max(6, FLAC__STREAM_METADATA_SEEKPOINT_LENGTH)];
  92135. const FLAC__StreamMetadata *metadata = &encoder->private_->streaminfo;
  92136. const FLAC__uint64 samples = metadata->data.stream_info.total_samples;
  92137. const unsigned min_framesize = metadata->data.stream_info.min_framesize;
  92138. const unsigned max_framesize = metadata->data.stream_info.max_framesize;
  92139. ogg_page page;
  92140. FLAC__ASSERT(metadata->type == FLAC__METADATA_TYPE_STREAMINFO);
  92141. FLAC__ASSERT(0 != encoder->private_->seek_callback);
  92142. if(encoder->private_->seek_callback(encoder, 0, encoder->private_->client_data) == FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED)
  92143. return;
  92144. simple_ogg_page__init(&page);
  92145. if(!simple_ogg_page__get_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  92146. simple_ogg_page__clear(&page);
  92147. return; /* state already set */
  92148. }
  92149. {
  92150. const unsigned md5_offset =
  92151. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92152. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92153. (
  92154. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92155. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92156. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92157. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92158. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92159. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92160. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN +
  92161. FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN
  92162. ) / 8;
  92163. if(md5_offset + 16 > (unsigned)page.body_len) {
  92164. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92165. simple_ogg_page__clear(&page);
  92166. return;
  92167. }
  92168. memcpy(page.body + md5_offset, metadata->data.stream_info.md5sum, 16);
  92169. }
  92170. {
  92171. const unsigned total_samples_byte_offset =
  92172. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92173. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92174. (
  92175. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92176. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN +
  92177. FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN +
  92178. FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN +
  92179. FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN +
  92180. FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN +
  92181. FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN
  92182. - 4
  92183. ) / 8;
  92184. if(total_samples_byte_offset + 5 > (unsigned)page.body_len) {
  92185. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92186. simple_ogg_page__clear(&page);
  92187. return;
  92188. }
  92189. b[0] = (FLAC__byte)page.body[total_samples_byte_offset] & 0xF0;
  92190. b[0] |= (FLAC__byte)((samples >> 32) & 0x0F);
  92191. b[1] = (FLAC__byte)((samples >> 24) & 0xFF);
  92192. b[2] = (FLAC__byte)((samples >> 16) & 0xFF);
  92193. b[3] = (FLAC__byte)((samples >> 8) & 0xFF);
  92194. b[4] = (FLAC__byte)(samples & 0xFF);
  92195. memcpy(page.body + total_samples_byte_offset, b, 5);
  92196. }
  92197. {
  92198. const unsigned min_framesize_offset =
  92199. FIRST_OGG_PACKET_STREAMINFO_PREFIX_LENGTH +
  92200. FLAC__STREAM_METADATA_HEADER_LENGTH +
  92201. (
  92202. FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN +
  92203. FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN
  92204. ) / 8;
  92205. if(min_framesize_offset + 6 > (unsigned)page.body_len) {
  92206. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92207. simple_ogg_page__clear(&page);
  92208. return;
  92209. }
  92210. b[0] = (FLAC__byte)((min_framesize >> 16) & 0xFF);
  92211. b[1] = (FLAC__byte)((min_framesize >> 8) & 0xFF);
  92212. b[2] = (FLAC__byte)(min_framesize & 0xFF);
  92213. b[3] = (FLAC__byte)((max_framesize >> 16) & 0xFF);
  92214. b[4] = (FLAC__byte)((max_framesize >> 8) & 0xFF);
  92215. b[5] = (FLAC__byte)(max_framesize & 0xFF);
  92216. memcpy(page.body + min_framesize_offset, b, 6);
  92217. }
  92218. if(!simple_ogg_page__set_at(encoder, encoder->protected_->streaminfo_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  92219. simple_ogg_page__clear(&page);
  92220. return; /* state already set */
  92221. }
  92222. simple_ogg_page__clear(&page);
  92223. if(0 != encoder->private_->seek_table && encoder->private_->seek_table->num_points > 0 && encoder->protected_->seektable_offset > 0) {
  92224. unsigned i;
  92225. FLAC__byte *p;
  92226. FLAC__format_seektable_sort(encoder->private_->seek_table);
  92227. FLAC__ASSERT(FLAC__format_seektable_is_legal(encoder->private_->seek_table));
  92228. simple_ogg_page__init(&page);
  92229. if(!simple_ogg_page__get_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->read_callback, encoder->private_->client_data)) {
  92230. simple_ogg_page__clear(&page);
  92231. return; /* state already set */
  92232. }
  92233. if((FLAC__STREAM_METADATA_HEADER_LENGTH + 18*encoder->private_->seek_table->num_points) != (unsigned)page.body_len) {
  92234. encoder->protected_->state = FLAC__STREAM_ENCODER_OGG_ERROR;
  92235. simple_ogg_page__clear(&page);
  92236. return;
  92237. }
  92238. for(i = 0, p = page.body + FLAC__STREAM_METADATA_HEADER_LENGTH; i < encoder->private_->seek_table->num_points; i++, p += 18) {
  92239. FLAC__uint64 xx;
  92240. unsigned x;
  92241. xx = encoder->private_->seek_table->points[i].sample_number;
  92242. b[7] = (FLAC__byte)xx; xx >>= 8;
  92243. b[6] = (FLAC__byte)xx; xx >>= 8;
  92244. b[5] = (FLAC__byte)xx; xx >>= 8;
  92245. b[4] = (FLAC__byte)xx; xx >>= 8;
  92246. b[3] = (FLAC__byte)xx; xx >>= 8;
  92247. b[2] = (FLAC__byte)xx; xx >>= 8;
  92248. b[1] = (FLAC__byte)xx; xx >>= 8;
  92249. b[0] = (FLAC__byte)xx; xx >>= 8;
  92250. xx = encoder->private_->seek_table->points[i].stream_offset;
  92251. b[15] = (FLAC__byte)xx; xx >>= 8;
  92252. b[14] = (FLAC__byte)xx; xx >>= 8;
  92253. b[13] = (FLAC__byte)xx; xx >>= 8;
  92254. b[12] = (FLAC__byte)xx; xx >>= 8;
  92255. b[11] = (FLAC__byte)xx; xx >>= 8;
  92256. b[10] = (FLAC__byte)xx; xx >>= 8;
  92257. b[9] = (FLAC__byte)xx; xx >>= 8;
  92258. b[8] = (FLAC__byte)xx; xx >>= 8;
  92259. x = encoder->private_->seek_table->points[i].frame_samples;
  92260. b[17] = (FLAC__byte)x; x >>= 8;
  92261. b[16] = (FLAC__byte)x; x >>= 8;
  92262. memcpy(p, b, 18);
  92263. }
  92264. if(!simple_ogg_page__set_at(encoder, encoder->protected_->seektable_offset, &page, encoder->private_->seek_callback, encoder->private_->write_callback, encoder->private_->client_data)) {
  92265. simple_ogg_page__clear(&page);
  92266. return; /* state already set */
  92267. }
  92268. simple_ogg_page__clear(&page);
  92269. }
  92270. }
  92271. #endif
  92272. FLAC__bool process_frame_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block, FLAC__bool is_last_block)
  92273. {
  92274. FLAC__uint16 crc;
  92275. FLAC__ASSERT(encoder->protected_->state == FLAC__STREAM_ENCODER_OK);
  92276. 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)) {
  92277. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92278. return false;
  92279. }
  92280. if(!process_subframes_(encoder, is_fractional_block)) {
  92281. return false;
  92282. }
  92283. if(!FLAC__bitwriter_zero_pad_to_byte_boundary(encoder->private_->frame)) {
  92284. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92285. return false;
  92286. }
  92287. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(encoder->private_->frame));
  92288. if(
  92289. !FLAC__bitwriter_get_write_crc16(encoder->private_->frame, &crc) ||
  92290. !FLAC__bitwriter_write_raw_uint32(encoder->private_->frame, crc, FLAC__FRAME_FOOTER_CRC_LEN)
  92291. ) {
  92292. encoder->protected_->state = FLAC__STREAM_ENCODER_MEMORY_ALLOCATION_ERROR;
  92293. return false;
  92294. }
  92295. if(!write_bitbuffer_(encoder, encoder->protected_->blocksize, is_last_block)) {
  92296. return false;
  92297. }
  92298. encoder->private_->current_sample_number = 0;
  92299. encoder->private_->current_frame_number++;
  92300. encoder->private_->streaminfo.data.stream_info.total_samples += (FLAC__uint64)encoder->protected_->blocksize;
  92301. return true;
  92302. }
  92303. FLAC__bool process_subframes_(FLAC__StreamEncoder *encoder, FLAC__bool is_fractional_block)
  92304. {
  92305. FLAC__FrameHeader frame_header;
  92306. unsigned channel, min_partition_order = encoder->protected_->min_residual_partition_order, max_partition_order;
  92307. FLAC__bool do_independent, do_mid_side;
  92308. if(is_fractional_block) {
  92309. max_partition_order = 0;
  92310. }
  92311. else {
  92312. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize(encoder->protected_->blocksize);
  92313. max_partition_order = min(max_partition_order, encoder->protected_->max_residual_partition_order);
  92314. }
  92315. min_partition_order = min(min_partition_order, max_partition_order);
  92316. frame_header.blocksize = encoder->protected_->blocksize;
  92317. frame_header.sample_rate = encoder->protected_->sample_rate;
  92318. frame_header.channels = encoder->protected_->channels;
  92319. frame_header.channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT; /* the default unless the encoder determines otherwise */
  92320. frame_header.bits_per_sample = encoder->protected_->bits_per_sample;
  92321. frame_header.number_type = FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER;
  92322. frame_header.number.frame_number = encoder->private_->current_frame_number;
  92323. if(encoder->protected_->do_mid_side_stereo) {
  92324. if(encoder->protected_->loose_mid_side_stereo) {
  92325. if(encoder->private_->loose_mid_side_stereo_frame_count == 0) {
  92326. do_independent = true;
  92327. do_mid_side = true;
  92328. }
  92329. else {
  92330. do_independent = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT);
  92331. do_mid_side = !do_independent;
  92332. }
  92333. }
  92334. else {
  92335. do_independent = true;
  92336. do_mid_side = true;
  92337. }
  92338. }
  92339. else {
  92340. do_independent = true;
  92341. do_mid_side = false;
  92342. }
  92343. FLAC__ASSERT(do_independent || do_mid_side);
  92344. if(do_independent) {
  92345. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92346. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal[channel], encoder->protected_->blocksize);
  92347. encoder->private_->subframe_workspace[channel][0].wasted_bits = encoder->private_->subframe_workspace[channel][1].wasted_bits = w;
  92348. encoder->private_->subframe_bps[channel] = encoder->protected_->bits_per_sample - w;
  92349. }
  92350. }
  92351. if(do_mid_side) {
  92352. FLAC__ASSERT(encoder->protected_->channels == 2);
  92353. for(channel = 0; channel < 2; channel++) {
  92354. const unsigned w = get_wasted_bits_(encoder->private_->integer_signal_mid_side[channel], encoder->protected_->blocksize);
  92355. encoder->private_->subframe_workspace_mid_side[channel][0].wasted_bits = encoder->private_->subframe_workspace_mid_side[channel][1].wasted_bits = w;
  92356. encoder->private_->subframe_bps_mid_side[channel] = encoder->protected_->bits_per_sample - w + (channel==0? 0:1);
  92357. }
  92358. }
  92359. if(do_independent) {
  92360. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92361. if(!
  92362. process_subframe_(
  92363. encoder,
  92364. min_partition_order,
  92365. max_partition_order,
  92366. &frame_header,
  92367. encoder->private_->subframe_bps[channel],
  92368. encoder->private_->integer_signal[channel],
  92369. encoder->private_->subframe_workspace_ptr[channel],
  92370. encoder->private_->partitioned_rice_contents_workspace_ptr[channel],
  92371. encoder->private_->residual_workspace[channel],
  92372. encoder->private_->best_subframe+channel,
  92373. encoder->private_->best_subframe_bits+channel
  92374. )
  92375. )
  92376. return false;
  92377. }
  92378. }
  92379. if(do_mid_side) {
  92380. FLAC__ASSERT(encoder->protected_->channels == 2);
  92381. for(channel = 0; channel < 2; channel++) {
  92382. if(!
  92383. process_subframe_(
  92384. encoder,
  92385. min_partition_order,
  92386. max_partition_order,
  92387. &frame_header,
  92388. encoder->private_->subframe_bps_mid_side[channel],
  92389. encoder->private_->integer_signal_mid_side[channel],
  92390. encoder->private_->subframe_workspace_ptr_mid_side[channel],
  92391. encoder->private_->partitioned_rice_contents_workspace_ptr_mid_side[channel],
  92392. encoder->private_->residual_workspace_mid_side[channel],
  92393. encoder->private_->best_subframe_mid_side+channel,
  92394. encoder->private_->best_subframe_bits_mid_side+channel
  92395. )
  92396. )
  92397. return false;
  92398. }
  92399. }
  92400. if(do_mid_side) {
  92401. unsigned left_bps = 0, right_bps = 0; /* initialized only to prevent superfluous compiler warning */
  92402. FLAC__Subframe *left_subframe = 0, *right_subframe = 0; /* initialized only to prevent superfluous compiler warning */
  92403. FLAC__ChannelAssignment channel_assignment;
  92404. FLAC__ASSERT(encoder->protected_->channels == 2);
  92405. if(encoder->protected_->loose_mid_side_stereo && encoder->private_->loose_mid_side_stereo_frame_count > 0) {
  92406. channel_assignment = (encoder->private_->last_channel_assignment == FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT? FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT : FLAC__CHANNEL_ASSIGNMENT_MID_SIDE);
  92407. }
  92408. else {
  92409. unsigned bits[4]; /* WATCHOUT - indexed by FLAC__ChannelAssignment */
  92410. unsigned min_bits;
  92411. int ca;
  92412. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT == 0);
  92413. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE == 1);
  92414. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE == 2);
  92415. FLAC__ASSERT(FLAC__CHANNEL_ASSIGNMENT_MID_SIDE == 3);
  92416. FLAC__ASSERT(do_independent && do_mid_side);
  92417. bits[FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits [1];
  92418. bits[FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE ] = encoder->private_->best_subframe_bits [0] + encoder->private_->best_subframe_bits_mid_side[1];
  92419. bits[FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE ] = encoder->private_->best_subframe_bits [1] + encoder->private_->best_subframe_bits_mid_side[1];
  92420. bits[FLAC__CHANNEL_ASSIGNMENT_MID_SIDE ] = encoder->private_->best_subframe_bits_mid_side[0] + encoder->private_->best_subframe_bits_mid_side[1];
  92421. channel_assignment = FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT;
  92422. min_bits = bits[channel_assignment];
  92423. for(ca = 1; ca <= 3; ca++) {
  92424. if(bits[ca] < min_bits) {
  92425. min_bits = bits[ca];
  92426. channel_assignment = (FLAC__ChannelAssignment)ca;
  92427. }
  92428. }
  92429. }
  92430. frame_header.channel_assignment = channel_assignment;
  92431. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92432. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92433. return false;
  92434. }
  92435. switch(channel_assignment) {
  92436. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92437. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92438. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92439. break;
  92440. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92441. left_subframe = &encoder->private_->subframe_workspace [0][encoder->private_->best_subframe [0]];
  92442. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92443. break;
  92444. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92445. left_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92446. right_subframe = &encoder->private_->subframe_workspace [1][encoder->private_->best_subframe [1]];
  92447. break;
  92448. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92449. left_subframe = &encoder->private_->subframe_workspace_mid_side[0][encoder->private_->best_subframe_mid_side[0]];
  92450. right_subframe = &encoder->private_->subframe_workspace_mid_side[1][encoder->private_->best_subframe_mid_side[1]];
  92451. break;
  92452. default:
  92453. FLAC__ASSERT(0);
  92454. }
  92455. switch(channel_assignment) {
  92456. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  92457. left_bps = encoder->private_->subframe_bps [0];
  92458. right_bps = encoder->private_->subframe_bps [1];
  92459. break;
  92460. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  92461. left_bps = encoder->private_->subframe_bps [0];
  92462. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92463. break;
  92464. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  92465. left_bps = encoder->private_->subframe_bps_mid_side[1];
  92466. right_bps = encoder->private_->subframe_bps [1];
  92467. break;
  92468. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  92469. left_bps = encoder->private_->subframe_bps_mid_side[0];
  92470. right_bps = encoder->private_->subframe_bps_mid_side[1];
  92471. break;
  92472. default:
  92473. FLAC__ASSERT(0);
  92474. }
  92475. if(!add_subframe_(encoder, frame_header.blocksize, left_bps , left_subframe , encoder->private_->frame))
  92476. return false;
  92477. if(!add_subframe_(encoder, frame_header.blocksize, right_bps, right_subframe, encoder->private_->frame))
  92478. return false;
  92479. }
  92480. else {
  92481. if(!FLAC__frame_add_header(&frame_header, encoder->private_->frame)) {
  92482. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92483. return false;
  92484. }
  92485. for(channel = 0; channel < encoder->protected_->channels; channel++) {
  92486. 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)) {
  92487. return false;
  92488. }
  92489. }
  92490. }
  92491. if(encoder->protected_->loose_mid_side_stereo) {
  92492. encoder->private_->loose_mid_side_stereo_frame_count++;
  92493. if(encoder->private_->loose_mid_side_stereo_frame_count >= encoder->private_->loose_mid_side_stereo_frames)
  92494. encoder->private_->loose_mid_side_stereo_frame_count = 0;
  92495. }
  92496. encoder->private_->last_channel_assignment = frame_header.channel_assignment;
  92497. return true;
  92498. }
  92499. FLAC__bool process_subframe_(
  92500. FLAC__StreamEncoder *encoder,
  92501. unsigned min_partition_order,
  92502. unsigned max_partition_order,
  92503. const FLAC__FrameHeader *frame_header,
  92504. unsigned subframe_bps,
  92505. const FLAC__int32 integer_signal[],
  92506. FLAC__Subframe *subframe[2],
  92507. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents[2],
  92508. FLAC__int32 *residual[2],
  92509. unsigned *best_subframe,
  92510. unsigned *best_bits
  92511. )
  92512. {
  92513. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92514. FLAC__float fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92515. #else
  92516. FLAC__fixedpoint fixed_residual_bits_per_sample[FLAC__MAX_FIXED_ORDER+1];
  92517. #endif
  92518. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92519. FLAC__double lpc_residual_bits_per_sample;
  92520. 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 */
  92521. FLAC__double lpc_error[FLAC__MAX_LPC_ORDER];
  92522. unsigned min_lpc_order, max_lpc_order, lpc_order;
  92523. unsigned min_qlp_coeff_precision, max_qlp_coeff_precision, qlp_coeff_precision;
  92524. #endif
  92525. unsigned min_fixed_order, max_fixed_order, guess_fixed_order, fixed_order;
  92526. unsigned rice_parameter;
  92527. unsigned _candidate_bits, _best_bits;
  92528. unsigned _best_subframe;
  92529. 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;
  92530. FLAC__ASSERT(frame_header->blocksize > 0);
  92531. _best_subframe = 0;
  92532. if(encoder->private_->disable_verbatim_subframes && frame_header->blocksize >= FLAC__MAX_FIXED_ORDER)
  92533. _best_bits = UINT_MAX;
  92534. else
  92535. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92536. if(frame_header->blocksize >= FLAC__MAX_FIXED_ORDER) {
  92537. unsigned signal_is_constant = false;
  92538. 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);
  92539. if(
  92540. !encoder->private_->disable_constant_subframes &&
  92541. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92542. fixed_residual_bits_per_sample[1] == 0.0
  92543. #else
  92544. fixed_residual_bits_per_sample[1] == FLAC__FP_ZERO
  92545. #endif
  92546. ) {
  92547. unsigned i;
  92548. signal_is_constant = true;
  92549. for(i = 1; i < frame_header->blocksize; i++) {
  92550. if(integer_signal[0] != integer_signal[i]) {
  92551. signal_is_constant = false;
  92552. break;
  92553. }
  92554. }
  92555. }
  92556. if(signal_is_constant) {
  92557. _candidate_bits = evaluate_constant_subframe_(encoder, integer_signal[0], frame_header->blocksize, subframe_bps, subframe[!_best_subframe]);
  92558. if(_candidate_bits < _best_bits) {
  92559. _best_subframe = !_best_subframe;
  92560. _best_bits = _candidate_bits;
  92561. }
  92562. }
  92563. else {
  92564. if(!encoder->private_->disable_fixed_subframes || (encoder->protected_->max_lpc_order == 0 && _best_bits == UINT_MAX)) {
  92565. if(encoder->protected_->do_exhaustive_model_search) {
  92566. min_fixed_order = 0;
  92567. max_fixed_order = FLAC__MAX_FIXED_ORDER;
  92568. }
  92569. else {
  92570. min_fixed_order = max_fixed_order = guess_fixed_order;
  92571. }
  92572. if(max_fixed_order >= frame_header->blocksize)
  92573. max_fixed_order = frame_header->blocksize - 1;
  92574. for(fixed_order = min_fixed_order; fixed_order <= max_fixed_order; fixed_order++) {
  92575. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92576. if(fixed_residual_bits_per_sample[fixed_order] >= (FLAC__float)subframe_bps)
  92577. continue; /* don't even try */
  92578. 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 */
  92579. #else
  92580. if(FLAC__fixedpoint_trunc(fixed_residual_bits_per_sample[fixed_order]) >= (int)subframe_bps)
  92581. continue; /* don't even try */
  92582. 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 */
  92583. #endif
  92584. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92585. if(rice_parameter >= rice_parameter_limit) {
  92586. #ifdef DEBUG_VERBOSE
  92587. fprintf(stderr, "clipping rice_parameter (%u -> %u) @0\n", rice_parameter, rice_parameter_limit - 1);
  92588. #endif
  92589. rice_parameter = rice_parameter_limit - 1;
  92590. }
  92591. _candidate_bits =
  92592. evaluate_fixed_subframe_(
  92593. encoder,
  92594. integer_signal,
  92595. residual[!_best_subframe],
  92596. encoder->private_->abs_residual_partition_sums,
  92597. encoder->private_->raw_bits_per_partition,
  92598. frame_header->blocksize,
  92599. subframe_bps,
  92600. fixed_order,
  92601. rice_parameter,
  92602. rice_parameter_limit,
  92603. min_partition_order,
  92604. max_partition_order,
  92605. encoder->protected_->do_escape_coding,
  92606. encoder->protected_->rice_parameter_search_dist,
  92607. subframe[!_best_subframe],
  92608. partitioned_rice_contents[!_best_subframe]
  92609. );
  92610. if(_candidate_bits < _best_bits) {
  92611. _best_subframe = !_best_subframe;
  92612. _best_bits = _candidate_bits;
  92613. }
  92614. }
  92615. }
  92616. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92617. if(encoder->protected_->max_lpc_order > 0) {
  92618. if(encoder->protected_->max_lpc_order >= frame_header->blocksize)
  92619. max_lpc_order = frame_header->blocksize-1;
  92620. else
  92621. max_lpc_order = encoder->protected_->max_lpc_order;
  92622. if(max_lpc_order > 0) {
  92623. unsigned a;
  92624. for (a = 0; a < encoder->protected_->num_apodizations; a++) {
  92625. FLAC__lpc_window_data(integer_signal, encoder->private_->window[a], encoder->private_->windowed_signal, frame_header->blocksize);
  92626. encoder->private_->local_lpc_compute_autocorrelation(encoder->private_->windowed_signal, frame_header->blocksize, max_lpc_order+1, autoc);
  92627. if(autoc[0] != 0.0) {
  92628. FLAC__lpc_compute_lp_coefficients(autoc, &max_lpc_order, encoder->private_->lp_coeff, lpc_error);
  92629. if(encoder->protected_->do_exhaustive_model_search) {
  92630. min_lpc_order = 1;
  92631. }
  92632. else {
  92633. const unsigned guess_lpc_order =
  92634. FLAC__lpc_compute_best_order(
  92635. lpc_error,
  92636. max_lpc_order,
  92637. frame_header->blocksize,
  92638. subframe_bps + (
  92639. encoder->protected_->do_qlp_coeff_prec_search?
  92640. FLAC__MIN_QLP_COEFF_PRECISION : /* have to guess; use the min possible size to avoid accidentally favoring lower orders */
  92641. encoder->protected_->qlp_coeff_precision
  92642. )
  92643. );
  92644. min_lpc_order = max_lpc_order = guess_lpc_order;
  92645. }
  92646. if(max_lpc_order >= frame_header->blocksize)
  92647. max_lpc_order = frame_header->blocksize - 1;
  92648. for(lpc_order = min_lpc_order; lpc_order <= max_lpc_order; lpc_order++) {
  92649. lpc_residual_bits_per_sample = FLAC__lpc_compute_expected_bits_per_residual_sample(lpc_error[lpc_order-1], frame_header->blocksize-lpc_order);
  92650. if(lpc_residual_bits_per_sample >= (FLAC__double)subframe_bps)
  92651. continue; /* don't even try */
  92652. rice_parameter = (lpc_residual_bits_per_sample > 0.0)? (unsigned)(lpc_residual_bits_per_sample+0.5) : 0; /* 0.5 is for rounding */
  92653. rice_parameter++; /* to account for the signed->unsigned conversion during rice coding */
  92654. if(rice_parameter >= rice_parameter_limit) {
  92655. #ifdef DEBUG_VERBOSE
  92656. fprintf(stderr, "clipping rice_parameter (%u -> %u) @1\n", rice_parameter, rice_parameter_limit - 1);
  92657. #endif
  92658. rice_parameter = rice_parameter_limit - 1;
  92659. }
  92660. if(encoder->protected_->do_qlp_coeff_prec_search) {
  92661. min_qlp_coeff_precision = FLAC__MIN_QLP_COEFF_PRECISION;
  92662. if(subframe_bps <= 17) {
  92663. max_qlp_coeff_precision = min(32 - subframe_bps - lpc_order, FLAC__MAX_QLP_COEFF_PRECISION);
  92664. max_qlp_coeff_precision = max(max_qlp_coeff_precision, min_qlp_coeff_precision);
  92665. }
  92666. else
  92667. max_qlp_coeff_precision = FLAC__MAX_QLP_COEFF_PRECISION;
  92668. }
  92669. else {
  92670. min_qlp_coeff_precision = max_qlp_coeff_precision = encoder->protected_->qlp_coeff_precision;
  92671. }
  92672. for(qlp_coeff_precision = min_qlp_coeff_precision; qlp_coeff_precision <= max_qlp_coeff_precision; qlp_coeff_precision++) {
  92673. _candidate_bits =
  92674. evaluate_lpc_subframe_(
  92675. encoder,
  92676. integer_signal,
  92677. residual[!_best_subframe],
  92678. encoder->private_->abs_residual_partition_sums,
  92679. encoder->private_->raw_bits_per_partition,
  92680. encoder->private_->lp_coeff[lpc_order-1],
  92681. frame_header->blocksize,
  92682. subframe_bps,
  92683. lpc_order,
  92684. qlp_coeff_precision,
  92685. rice_parameter,
  92686. rice_parameter_limit,
  92687. min_partition_order,
  92688. max_partition_order,
  92689. encoder->protected_->do_escape_coding,
  92690. encoder->protected_->rice_parameter_search_dist,
  92691. subframe[!_best_subframe],
  92692. partitioned_rice_contents[!_best_subframe]
  92693. );
  92694. if(_candidate_bits > 0) { /* if == 0, there was a problem quantizing the lpcoeffs */
  92695. if(_candidate_bits < _best_bits) {
  92696. _best_subframe = !_best_subframe;
  92697. _best_bits = _candidate_bits;
  92698. }
  92699. }
  92700. }
  92701. }
  92702. }
  92703. }
  92704. }
  92705. }
  92706. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  92707. }
  92708. }
  92709. if(_best_bits == UINT_MAX) {
  92710. FLAC__ASSERT(_best_subframe == 0);
  92711. _best_bits = evaluate_verbatim_subframe_(encoder, integer_signal, frame_header->blocksize, subframe_bps, subframe[_best_subframe]);
  92712. }
  92713. *best_subframe = _best_subframe;
  92714. *best_bits = _best_bits;
  92715. return true;
  92716. }
  92717. FLAC__bool add_subframe_(
  92718. FLAC__StreamEncoder *encoder,
  92719. unsigned blocksize,
  92720. unsigned subframe_bps,
  92721. const FLAC__Subframe *subframe,
  92722. FLAC__BitWriter *frame
  92723. )
  92724. {
  92725. switch(subframe->type) {
  92726. case FLAC__SUBFRAME_TYPE_CONSTANT:
  92727. if(!FLAC__subframe_add_constant(&(subframe->data.constant), subframe_bps, subframe->wasted_bits, frame)) {
  92728. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92729. return false;
  92730. }
  92731. break;
  92732. case FLAC__SUBFRAME_TYPE_FIXED:
  92733. if(!FLAC__subframe_add_fixed(&(subframe->data.fixed), blocksize - subframe->data.fixed.order, subframe_bps, subframe->wasted_bits, frame)) {
  92734. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92735. return false;
  92736. }
  92737. break;
  92738. case FLAC__SUBFRAME_TYPE_LPC:
  92739. if(!FLAC__subframe_add_lpc(&(subframe->data.lpc), blocksize - subframe->data.lpc.order, subframe_bps, subframe->wasted_bits, frame)) {
  92740. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92741. return false;
  92742. }
  92743. break;
  92744. case FLAC__SUBFRAME_TYPE_VERBATIM:
  92745. if(!FLAC__subframe_add_verbatim(&(subframe->data.verbatim), blocksize, subframe_bps, subframe->wasted_bits, frame)) {
  92746. encoder->protected_->state = FLAC__STREAM_ENCODER_FRAMING_ERROR;
  92747. return false;
  92748. }
  92749. break;
  92750. default:
  92751. FLAC__ASSERT(0);
  92752. }
  92753. return true;
  92754. }
  92755. #define SPOTCHECK_ESTIMATE 0
  92756. #if SPOTCHECK_ESTIMATE
  92757. static void spotcheck_subframe_estimate_(
  92758. FLAC__StreamEncoder *encoder,
  92759. unsigned blocksize,
  92760. unsigned subframe_bps,
  92761. const FLAC__Subframe *subframe,
  92762. unsigned estimate
  92763. )
  92764. {
  92765. FLAC__bool ret;
  92766. FLAC__BitWriter *frame = FLAC__bitwriter_new();
  92767. if(frame == 0) {
  92768. fprintf(stderr, "EST: can't allocate frame\n");
  92769. return;
  92770. }
  92771. if(!FLAC__bitwriter_init(frame)) {
  92772. fprintf(stderr, "EST: can't init frame\n");
  92773. return;
  92774. }
  92775. ret = add_subframe_(encoder, blocksize, subframe_bps, subframe, frame);
  92776. FLAC__ASSERT(ret);
  92777. {
  92778. const unsigned actual = FLAC__bitwriter_get_input_bits_unconsumed(frame);
  92779. if(estimate != actual)
  92780. 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);
  92781. }
  92782. FLAC__bitwriter_delete(frame);
  92783. }
  92784. #endif
  92785. unsigned evaluate_constant_subframe_(
  92786. FLAC__StreamEncoder *encoder,
  92787. const FLAC__int32 signal,
  92788. unsigned blocksize,
  92789. unsigned subframe_bps,
  92790. FLAC__Subframe *subframe
  92791. )
  92792. {
  92793. unsigned estimate;
  92794. subframe->type = FLAC__SUBFRAME_TYPE_CONSTANT;
  92795. subframe->data.constant.value = signal;
  92796. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + subframe_bps;
  92797. #if SPOTCHECK_ESTIMATE
  92798. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92799. #else
  92800. (void)encoder, (void)blocksize;
  92801. #endif
  92802. return estimate;
  92803. }
  92804. unsigned evaluate_fixed_subframe_(
  92805. FLAC__StreamEncoder *encoder,
  92806. const FLAC__int32 signal[],
  92807. FLAC__int32 residual[],
  92808. FLAC__uint64 abs_residual_partition_sums[],
  92809. unsigned raw_bits_per_partition[],
  92810. unsigned blocksize,
  92811. unsigned subframe_bps,
  92812. unsigned order,
  92813. unsigned rice_parameter,
  92814. unsigned rice_parameter_limit,
  92815. unsigned min_partition_order,
  92816. unsigned max_partition_order,
  92817. FLAC__bool do_escape_coding,
  92818. unsigned rice_parameter_search_dist,
  92819. FLAC__Subframe *subframe,
  92820. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92821. )
  92822. {
  92823. unsigned i, residual_bits, estimate;
  92824. const unsigned residual_samples = blocksize - order;
  92825. FLAC__fixed_compute_residual(signal+order, residual_samples, order, residual);
  92826. subframe->type = FLAC__SUBFRAME_TYPE_FIXED;
  92827. subframe->data.fixed.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92828. subframe->data.fixed.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92829. subframe->data.fixed.residual = residual;
  92830. residual_bits =
  92831. find_best_partition_order_(
  92832. encoder->private_,
  92833. residual,
  92834. abs_residual_partition_sums,
  92835. raw_bits_per_partition,
  92836. residual_samples,
  92837. order,
  92838. rice_parameter,
  92839. rice_parameter_limit,
  92840. min_partition_order,
  92841. max_partition_order,
  92842. subframe_bps,
  92843. do_escape_coding,
  92844. rice_parameter_search_dist,
  92845. &subframe->data.fixed.entropy_coding_method
  92846. );
  92847. subframe->data.fixed.order = order;
  92848. for(i = 0; i < order; i++)
  92849. subframe->data.fixed.warmup[i] = signal[i];
  92850. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (order * subframe_bps) + residual_bits;
  92851. #if SPOTCHECK_ESTIMATE
  92852. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92853. #endif
  92854. return estimate;
  92855. }
  92856. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  92857. unsigned evaluate_lpc_subframe_(
  92858. FLAC__StreamEncoder *encoder,
  92859. const FLAC__int32 signal[],
  92860. FLAC__int32 residual[],
  92861. FLAC__uint64 abs_residual_partition_sums[],
  92862. unsigned raw_bits_per_partition[],
  92863. const FLAC__real lp_coeff[],
  92864. unsigned blocksize,
  92865. unsigned subframe_bps,
  92866. unsigned order,
  92867. unsigned qlp_coeff_precision,
  92868. unsigned rice_parameter,
  92869. unsigned rice_parameter_limit,
  92870. unsigned min_partition_order,
  92871. unsigned max_partition_order,
  92872. FLAC__bool do_escape_coding,
  92873. unsigned rice_parameter_search_dist,
  92874. FLAC__Subframe *subframe,
  92875. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents
  92876. )
  92877. {
  92878. FLAC__int32 qlp_coeff[FLAC__MAX_LPC_ORDER];
  92879. unsigned i, residual_bits, estimate;
  92880. int quantization, ret;
  92881. const unsigned residual_samples = blocksize - order;
  92882. if(subframe_bps <= 16) {
  92883. FLAC__ASSERT(order > 0);
  92884. FLAC__ASSERT(order <= FLAC__MAX_LPC_ORDER);
  92885. qlp_coeff_precision = min(qlp_coeff_precision, 32 - subframe_bps - FLAC__bitmath_ilog2(order));
  92886. }
  92887. ret = FLAC__lpc_quantize_coefficients(lp_coeff, order, qlp_coeff_precision, qlp_coeff, &quantization);
  92888. if(ret != 0)
  92889. return 0; /* this is a hack to indicate to the caller that we can't do lp at this order on this subframe */
  92890. if(subframe_bps + qlp_coeff_precision + FLAC__bitmath_ilog2(order) <= 32)
  92891. if(subframe_bps <= 16 && qlp_coeff_precision <= 16)
  92892. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_16bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92893. else
  92894. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92895. else
  92896. encoder->private_->local_lpc_compute_residual_from_qlp_coefficients_64bit(signal+order, residual_samples, qlp_coeff, order, quantization, residual);
  92897. subframe->type = FLAC__SUBFRAME_TYPE_LPC;
  92898. subframe->data.lpc.entropy_coding_method.type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE;
  92899. subframe->data.lpc.entropy_coding_method.data.partitioned_rice.contents = partitioned_rice_contents;
  92900. subframe->data.lpc.residual = residual;
  92901. residual_bits =
  92902. find_best_partition_order_(
  92903. encoder->private_,
  92904. residual,
  92905. abs_residual_partition_sums,
  92906. raw_bits_per_partition,
  92907. residual_samples,
  92908. order,
  92909. rice_parameter,
  92910. rice_parameter_limit,
  92911. min_partition_order,
  92912. max_partition_order,
  92913. subframe_bps,
  92914. do_escape_coding,
  92915. rice_parameter_search_dist,
  92916. &subframe->data.lpc.entropy_coding_method
  92917. );
  92918. subframe->data.lpc.order = order;
  92919. subframe->data.lpc.qlp_coeff_precision = qlp_coeff_precision;
  92920. subframe->data.lpc.quantization_level = quantization;
  92921. memcpy(subframe->data.lpc.qlp_coeff, qlp_coeff, sizeof(FLAC__int32)*FLAC__MAX_LPC_ORDER);
  92922. for(i = 0; i < order; i++)
  92923. subframe->data.lpc.warmup[i] = signal[i];
  92924. 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;
  92925. #if SPOTCHECK_ESTIMATE
  92926. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92927. #endif
  92928. return estimate;
  92929. }
  92930. #endif
  92931. unsigned evaluate_verbatim_subframe_(
  92932. FLAC__StreamEncoder *encoder,
  92933. const FLAC__int32 signal[],
  92934. unsigned blocksize,
  92935. unsigned subframe_bps,
  92936. FLAC__Subframe *subframe
  92937. )
  92938. {
  92939. unsigned estimate;
  92940. subframe->type = FLAC__SUBFRAME_TYPE_VERBATIM;
  92941. subframe->data.verbatim.data = signal;
  92942. estimate = FLAC__SUBFRAME_ZERO_PAD_LEN + FLAC__SUBFRAME_TYPE_LEN + FLAC__SUBFRAME_WASTED_BITS_FLAG_LEN + subframe->wasted_bits + (blocksize * subframe_bps);
  92943. #if SPOTCHECK_ESTIMATE
  92944. spotcheck_subframe_estimate_(encoder, blocksize, subframe_bps, subframe, estimate);
  92945. #else
  92946. (void)encoder;
  92947. #endif
  92948. return estimate;
  92949. }
  92950. unsigned find_best_partition_order_(
  92951. FLAC__StreamEncoderPrivate *private_,
  92952. const FLAC__int32 residual[],
  92953. FLAC__uint64 abs_residual_partition_sums[],
  92954. unsigned raw_bits_per_partition[],
  92955. unsigned residual_samples,
  92956. unsigned predictor_order,
  92957. unsigned rice_parameter,
  92958. unsigned rice_parameter_limit,
  92959. unsigned min_partition_order,
  92960. unsigned max_partition_order,
  92961. unsigned bps,
  92962. FLAC__bool do_escape_coding,
  92963. unsigned rice_parameter_search_dist,
  92964. FLAC__EntropyCodingMethod *best_ecm
  92965. )
  92966. {
  92967. unsigned residual_bits, best_residual_bits = 0;
  92968. unsigned best_parameters_index = 0;
  92969. unsigned best_partition_order = 0;
  92970. const unsigned blocksize = residual_samples + predictor_order;
  92971. max_partition_order = FLAC__format_get_max_rice_partition_order_from_blocksize_limited_max_and_predictor_order(max_partition_order, blocksize, predictor_order);
  92972. min_partition_order = min(min_partition_order, max_partition_order);
  92973. precompute_partition_info_sums_(residual, abs_residual_partition_sums, residual_samples, predictor_order, min_partition_order, max_partition_order, bps);
  92974. if(do_escape_coding)
  92975. precompute_partition_info_escapes_(residual, raw_bits_per_partition, residual_samples, predictor_order, min_partition_order, max_partition_order);
  92976. {
  92977. int partition_order;
  92978. unsigned sum;
  92979. for(partition_order = (int)max_partition_order, sum = 0; partition_order >= (int)min_partition_order; partition_order--) {
  92980. if(!
  92981. set_partitioned_rice_(
  92982. #ifdef EXACT_RICE_BITS_CALCULATION
  92983. residual,
  92984. #endif
  92985. abs_residual_partition_sums+sum,
  92986. raw_bits_per_partition+sum,
  92987. residual_samples,
  92988. predictor_order,
  92989. rice_parameter,
  92990. rice_parameter_limit,
  92991. rice_parameter_search_dist,
  92992. (unsigned)partition_order,
  92993. do_escape_coding,
  92994. &private_->partitioned_rice_contents_extra[!best_parameters_index],
  92995. &residual_bits
  92996. )
  92997. )
  92998. {
  92999. FLAC__ASSERT(best_residual_bits != 0);
  93000. break;
  93001. }
  93002. sum += 1u << partition_order;
  93003. if(best_residual_bits == 0 || residual_bits < best_residual_bits) {
  93004. best_residual_bits = residual_bits;
  93005. best_parameters_index = !best_parameters_index;
  93006. best_partition_order = partition_order;
  93007. }
  93008. }
  93009. }
  93010. best_ecm->data.partitioned_rice.order = best_partition_order;
  93011. {
  93012. FLAC__EntropyCodingMethod_PartitionedRiceContents* prc = (FLAC__EntropyCodingMethod_PartitionedRiceContents*)best_ecm->data.partitioned_rice.contents;
  93013. unsigned partition;
  93014. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(prc, max(6, best_partition_order));
  93015. memcpy(prc->parameters, private_->partitioned_rice_contents_extra[best_parameters_index].parameters, sizeof(unsigned)*(1<<(best_partition_order)));
  93016. if(do_escape_coding)
  93017. memcpy(prc->raw_bits, private_->partitioned_rice_contents_extra[best_parameters_index].raw_bits, sizeof(unsigned)*(1<<(best_partition_order)));
  93018. for(partition = 0; partition < (1u<<best_partition_order); partition++) {
  93019. if(prc->parameters[partition] >= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER) {
  93020. best_ecm->type = FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2;
  93021. break;
  93022. }
  93023. }
  93024. }
  93025. return best_residual_bits;
  93026. }
  93027. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  93028. extern void precompute_partition_info_sums_32bit_asm_ia32_(
  93029. const FLAC__int32 residual[],
  93030. FLAC__uint64 abs_residual_partition_sums[],
  93031. unsigned blocksize,
  93032. unsigned predictor_order,
  93033. unsigned min_partition_order,
  93034. unsigned max_partition_order
  93035. );
  93036. #endif
  93037. void precompute_partition_info_sums_(
  93038. const FLAC__int32 residual[],
  93039. FLAC__uint64 abs_residual_partition_sums[],
  93040. unsigned residual_samples,
  93041. unsigned predictor_order,
  93042. unsigned min_partition_order,
  93043. unsigned max_partition_order,
  93044. unsigned bps
  93045. )
  93046. {
  93047. const unsigned default_partition_samples = (residual_samples + predictor_order) >> max_partition_order;
  93048. unsigned partitions = 1u << max_partition_order;
  93049. FLAC__ASSERT(default_partition_samples > predictor_order);
  93050. #if defined(FLAC__CPU_IA32) && !defined FLAC__NO_ASM && defined FLAC__HAS_NASM
  93051. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  93052. precompute_partition_info_sums_32bit_asm_ia32_(residual, abs_residual_partition_sums, residual_samples + predictor_order, predictor_order, min_partition_order, max_partition_order);
  93053. return;
  93054. }
  93055. #endif
  93056. {
  93057. unsigned partition, residual_sample, end = (unsigned)(-(int)predictor_order);
  93058. if(FLAC__bitmath_ilog2(default_partition_samples) + bps < 32) {
  93059. FLAC__uint32 abs_residual_partition_sum;
  93060. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93061. end += default_partition_samples;
  93062. abs_residual_partition_sum = 0;
  93063. for( ; residual_sample < end; residual_sample++)
  93064. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  93065. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  93066. }
  93067. }
  93068. else { /* have to pessimistically use 64 bits for accumulator */
  93069. FLAC__uint64 abs_residual_partition_sum;
  93070. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93071. end += default_partition_samples;
  93072. abs_residual_partition_sum = 0;
  93073. for( ; residual_sample < end; residual_sample++)
  93074. abs_residual_partition_sum += abs(residual[residual_sample]); /* abs(INT_MIN) is undefined, but if the residual is INT_MIN we have bigger problems */
  93075. abs_residual_partition_sums[partition] = abs_residual_partition_sum;
  93076. }
  93077. }
  93078. }
  93079. {
  93080. unsigned from_partition = 0, to_partition = partitions;
  93081. int partition_order;
  93082. for(partition_order = (int)max_partition_order - 1; partition_order >= (int)min_partition_order; partition_order--) {
  93083. unsigned i;
  93084. partitions >>= 1;
  93085. for(i = 0; i < partitions; i++) {
  93086. abs_residual_partition_sums[to_partition++] =
  93087. abs_residual_partition_sums[from_partition ] +
  93088. abs_residual_partition_sums[from_partition+1];
  93089. from_partition += 2;
  93090. }
  93091. }
  93092. }
  93093. }
  93094. void precompute_partition_info_escapes_(
  93095. const FLAC__int32 residual[],
  93096. unsigned raw_bits_per_partition[],
  93097. unsigned residual_samples,
  93098. unsigned predictor_order,
  93099. unsigned min_partition_order,
  93100. unsigned max_partition_order
  93101. )
  93102. {
  93103. int partition_order;
  93104. unsigned from_partition, to_partition = 0;
  93105. const unsigned blocksize = residual_samples + predictor_order;
  93106. for(partition_order = (int)max_partition_order; partition_order >= 0; partition_order--) {
  93107. FLAC__int32 r;
  93108. FLAC__uint32 rmax;
  93109. unsigned partition, partition_sample, partition_samples, residual_sample;
  93110. const unsigned partitions = 1u << partition_order;
  93111. const unsigned default_partition_samples = blocksize >> partition_order;
  93112. FLAC__ASSERT(default_partition_samples > predictor_order);
  93113. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93114. partition_samples = default_partition_samples;
  93115. if(partition == 0)
  93116. partition_samples -= predictor_order;
  93117. rmax = 0;
  93118. for(partition_sample = 0; partition_sample < partition_samples; partition_sample++) {
  93119. r = residual[residual_sample++];
  93120. if(r < 0)
  93121. rmax |= ~r;
  93122. else
  93123. rmax |= r;
  93124. }
  93125. raw_bits_per_partition[partition] = rmax? FLAC__bitmath_ilog2(rmax) + 2 : 1;
  93126. }
  93127. to_partition = partitions;
  93128. break; /*@@@ yuck, should remove the 'for' loop instead */
  93129. }
  93130. for(from_partition = 0, --partition_order; partition_order >= (int)min_partition_order; partition_order--) {
  93131. unsigned m;
  93132. unsigned i;
  93133. const unsigned partitions = 1u << partition_order;
  93134. for(i = 0; i < partitions; i++) {
  93135. m = raw_bits_per_partition[from_partition];
  93136. from_partition++;
  93137. raw_bits_per_partition[to_partition] = max(m, raw_bits_per_partition[from_partition]);
  93138. from_partition++;
  93139. to_partition++;
  93140. }
  93141. }
  93142. }
  93143. #ifdef EXACT_RICE_BITS_CALCULATION
  93144. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  93145. const unsigned rice_parameter,
  93146. const unsigned partition_samples,
  93147. const FLAC__int32 *residual
  93148. )
  93149. {
  93150. unsigned i, partition_bits =
  93151. 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 */
  93152. (1+rice_parameter) * partition_samples /* 1 for unary stop bit + rice_parameter for the binary portion */
  93153. ;
  93154. for(i = 0; i < partition_samples; i++)
  93155. partition_bits += ( (FLAC__uint32)((residual[i]<<1)^(residual[i]>>31)) >> rice_parameter );
  93156. return partition_bits;
  93157. }
  93158. #else
  93159. static FLaC__INLINE unsigned count_rice_bits_in_partition_(
  93160. const unsigned rice_parameter,
  93161. const unsigned partition_samples,
  93162. const FLAC__uint64 abs_residual_partition_sum
  93163. )
  93164. {
  93165. return
  93166. 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 */
  93167. (1+rice_parameter) * partition_samples + /* 1 for unary stop bit + rice_parameter for the binary portion */
  93168. (
  93169. rice_parameter?
  93170. (unsigned)(abs_residual_partition_sum >> (rice_parameter-1)) /* rice_parameter-1 because the real coder sign-folds instead of using a sign bit */
  93171. : (unsigned)(abs_residual_partition_sum << 1) /* can't shift by negative number, so reverse */
  93172. )
  93173. - (partition_samples >> 1)
  93174. ;
  93175. }
  93176. #endif
  93177. FLAC__bool set_partitioned_rice_(
  93178. #ifdef EXACT_RICE_BITS_CALCULATION
  93179. const FLAC__int32 residual[],
  93180. #endif
  93181. const FLAC__uint64 abs_residual_partition_sums[],
  93182. const unsigned raw_bits_per_partition[],
  93183. const unsigned residual_samples,
  93184. const unsigned predictor_order,
  93185. const unsigned suggested_rice_parameter,
  93186. const unsigned rice_parameter_limit,
  93187. const unsigned rice_parameter_search_dist,
  93188. const unsigned partition_order,
  93189. const FLAC__bool search_for_escapes,
  93190. FLAC__EntropyCodingMethod_PartitionedRiceContents *partitioned_rice_contents,
  93191. unsigned *bits
  93192. )
  93193. {
  93194. unsigned rice_parameter, partition_bits;
  93195. unsigned best_partition_bits, best_rice_parameter = 0;
  93196. unsigned bits_ = FLAC__ENTROPY_CODING_METHOD_TYPE_LEN + FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN;
  93197. unsigned *parameters, *raw_bits;
  93198. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93199. unsigned min_rice_parameter, max_rice_parameter;
  93200. #else
  93201. (void)rice_parameter_search_dist;
  93202. #endif
  93203. FLAC__ASSERT(suggested_rice_parameter < FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  93204. FLAC__ASSERT(rice_parameter_limit <= FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER);
  93205. FLAC__format_entropy_coding_method_partitioned_rice_contents_ensure_size(partitioned_rice_contents, max(6, partition_order));
  93206. parameters = partitioned_rice_contents->parameters;
  93207. raw_bits = partitioned_rice_contents->raw_bits;
  93208. if(partition_order == 0) {
  93209. best_partition_bits = (unsigned)(-1);
  93210. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93211. if(rice_parameter_search_dist) {
  93212. if(suggested_rice_parameter < rice_parameter_search_dist)
  93213. min_rice_parameter = 0;
  93214. else
  93215. min_rice_parameter = suggested_rice_parameter - rice_parameter_search_dist;
  93216. max_rice_parameter = suggested_rice_parameter + rice_parameter_search_dist;
  93217. if(max_rice_parameter >= rice_parameter_limit) {
  93218. #ifdef DEBUG_VERBOSE
  93219. fprintf(stderr, "clipping rice_parameter (%u -> %u) @5\n", max_rice_parameter, rice_parameter_limit - 1);
  93220. #endif
  93221. max_rice_parameter = rice_parameter_limit - 1;
  93222. }
  93223. }
  93224. else
  93225. min_rice_parameter = max_rice_parameter = suggested_rice_parameter;
  93226. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93227. #else
  93228. rice_parameter = suggested_rice_parameter;
  93229. #endif
  93230. #ifdef EXACT_RICE_BITS_CALCULATION
  93231. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, residual);
  93232. #else
  93233. partition_bits = count_rice_bits_in_partition_(rice_parameter, residual_samples, abs_residual_partition_sums[0]);
  93234. #endif
  93235. if(partition_bits < best_partition_bits) {
  93236. best_rice_parameter = rice_parameter;
  93237. best_partition_bits = partition_bits;
  93238. }
  93239. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93240. }
  93241. #endif
  93242. if(search_for_escapes) {
  93243. 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;
  93244. if(partition_bits <= best_partition_bits) {
  93245. raw_bits[0] = raw_bits_per_partition[0];
  93246. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93247. best_partition_bits = partition_bits;
  93248. }
  93249. else
  93250. raw_bits[0] = 0;
  93251. }
  93252. parameters[0] = best_rice_parameter;
  93253. bits_ += best_partition_bits;
  93254. }
  93255. else {
  93256. unsigned partition, residual_sample;
  93257. unsigned partition_samples;
  93258. FLAC__uint64 mean, k;
  93259. const unsigned partitions = 1u << partition_order;
  93260. for(partition = residual_sample = 0; partition < partitions; partition++) {
  93261. partition_samples = (residual_samples+predictor_order) >> partition_order;
  93262. if(partition == 0) {
  93263. if(partition_samples <= predictor_order)
  93264. return false;
  93265. else
  93266. partition_samples -= predictor_order;
  93267. }
  93268. mean = abs_residual_partition_sums[partition];
  93269. for(rice_parameter = 0, k = partition_samples; k < mean; rice_parameter++, k <<= 1)
  93270. ;
  93271. if(rice_parameter >= rice_parameter_limit) {
  93272. #ifdef DEBUG_VERBOSE
  93273. fprintf(stderr, "clipping rice_parameter (%u -> %u) @6\n", rice_parameter, rice_parameter_limit - 1);
  93274. #endif
  93275. rice_parameter = rice_parameter_limit - 1;
  93276. }
  93277. best_partition_bits = (unsigned)(-1);
  93278. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93279. if(rice_parameter_search_dist) {
  93280. if(rice_parameter < rice_parameter_search_dist)
  93281. min_rice_parameter = 0;
  93282. else
  93283. min_rice_parameter = rice_parameter - rice_parameter_search_dist;
  93284. max_rice_parameter = rice_parameter + rice_parameter_search_dist;
  93285. if(max_rice_parameter >= rice_parameter_limit) {
  93286. #ifdef DEBUG_VERBOSE
  93287. fprintf(stderr, "clipping rice_parameter (%u -> %u) @7\n", max_rice_parameter, rice_parameter_limit - 1);
  93288. #endif
  93289. max_rice_parameter = rice_parameter_limit - 1;
  93290. }
  93291. }
  93292. else
  93293. min_rice_parameter = max_rice_parameter = rice_parameter;
  93294. for(rice_parameter = min_rice_parameter; rice_parameter <= max_rice_parameter; rice_parameter++) {
  93295. #endif
  93296. #ifdef EXACT_RICE_BITS_CALCULATION
  93297. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, residual+residual_sample);
  93298. #else
  93299. partition_bits = count_rice_bits_in_partition_(rice_parameter, partition_samples, abs_residual_partition_sums[partition]);
  93300. #endif
  93301. if(partition_bits < best_partition_bits) {
  93302. best_rice_parameter = rice_parameter;
  93303. best_partition_bits = partition_bits;
  93304. }
  93305. #ifdef ENABLE_RICE_PARAMETER_SEARCH
  93306. }
  93307. #endif
  93308. if(search_for_escapes) {
  93309. 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;
  93310. if(partition_bits <= best_partition_bits) {
  93311. raw_bits[partition] = raw_bits_per_partition[partition];
  93312. best_rice_parameter = 0; /* will be converted to appropriate escape parameter later */
  93313. best_partition_bits = partition_bits;
  93314. }
  93315. else
  93316. raw_bits[partition] = 0;
  93317. }
  93318. parameters[partition] = best_rice_parameter;
  93319. bits_ += best_partition_bits;
  93320. residual_sample += partition_samples;
  93321. }
  93322. }
  93323. *bits = bits_;
  93324. return true;
  93325. }
  93326. unsigned get_wasted_bits_(FLAC__int32 signal[], unsigned samples)
  93327. {
  93328. unsigned i, shift;
  93329. FLAC__int32 x = 0;
  93330. for(i = 0; i < samples && !(x&1); i++)
  93331. x |= signal[i];
  93332. if(x == 0) {
  93333. shift = 0;
  93334. }
  93335. else {
  93336. for(shift = 0; !(x&1); shift++)
  93337. x >>= 1;
  93338. }
  93339. if(shift > 0) {
  93340. for(i = 0; i < samples; i++)
  93341. signal[i] >>= shift;
  93342. }
  93343. return shift;
  93344. }
  93345. void append_to_verify_fifo_(verify_input_fifo *fifo, const FLAC__int32 * const input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93346. {
  93347. unsigned channel;
  93348. for(channel = 0; channel < channels; channel++)
  93349. memcpy(&fifo->data[channel][fifo->tail], &input[channel][input_offset], sizeof(FLAC__int32) * wide_samples);
  93350. fifo->tail += wide_samples;
  93351. FLAC__ASSERT(fifo->tail <= fifo->size);
  93352. }
  93353. void append_to_verify_fifo_interleaved_(verify_input_fifo *fifo, const FLAC__int32 input[], unsigned input_offset, unsigned channels, unsigned wide_samples)
  93354. {
  93355. unsigned channel;
  93356. unsigned sample, wide_sample;
  93357. unsigned tail = fifo->tail;
  93358. sample = input_offset * channels;
  93359. for(wide_sample = 0; wide_sample < wide_samples; wide_sample++) {
  93360. for(channel = 0; channel < channels; channel++)
  93361. fifo->data[channel][tail] = input[sample++];
  93362. tail++;
  93363. }
  93364. fifo->tail = tail;
  93365. FLAC__ASSERT(fifo->tail <= fifo->size);
  93366. }
  93367. FLAC__StreamDecoderReadStatus verify_read_callback_(const FLAC__StreamDecoder *decoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93368. {
  93369. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93370. const size_t encoded_bytes = encoder->private_->verify.output.bytes;
  93371. (void)decoder;
  93372. if(encoder->private_->verify.needs_magic_hack) {
  93373. FLAC__ASSERT(*bytes >= FLAC__STREAM_SYNC_LENGTH);
  93374. *bytes = FLAC__STREAM_SYNC_LENGTH;
  93375. memcpy(buffer, FLAC__STREAM_SYNC_STRING, *bytes);
  93376. encoder->private_->verify.needs_magic_hack = false;
  93377. }
  93378. else {
  93379. if(encoded_bytes == 0) {
  93380. FLAC__ASSERT(0);
  93381. return FLAC__STREAM_DECODER_READ_STATUS_ABORT;
  93382. }
  93383. else if(encoded_bytes < *bytes)
  93384. *bytes = encoded_bytes;
  93385. memcpy(buffer, encoder->private_->verify.output.data, *bytes);
  93386. encoder->private_->verify.output.data += *bytes;
  93387. encoder->private_->verify.output.bytes -= *bytes;
  93388. }
  93389. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  93390. }
  93391. FLAC__StreamDecoderWriteStatus verify_write_callback_(const FLAC__StreamDecoder *decoder, const FLAC__Frame *frame, const FLAC__int32 * const buffer[], void *client_data)
  93392. {
  93393. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder *)client_data;
  93394. unsigned channel;
  93395. const unsigned channels = frame->header.channels;
  93396. const unsigned blocksize = frame->header.blocksize;
  93397. const unsigned bytes_per_block = sizeof(FLAC__int32) * blocksize;
  93398. (void)decoder;
  93399. for(channel = 0; channel < channels; channel++) {
  93400. if(0 != memcmp(buffer[channel], encoder->private_->verify.input_fifo.data[channel], bytes_per_block)) {
  93401. unsigned i, sample = 0;
  93402. FLAC__int32 expect = 0, got = 0;
  93403. for(i = 0; i < blocksize; i++) {
  93404. if(buffer[channel][i] != encoder->private_->verify.input_fifo.data[channel][i]) {
  93405. sample = i;
  93406. expect = (FLAC__int32)encoder->private_->verify.input_fifo.data[channel][i];
  93407. got = (FLAC__int32)buffer[channel][i];
  93408. break;
  93409. }
  93410. }
  93411. FLAC__ASSERT(i < blocksize);
  93412. FLAC__ASSERT(frame->header.number_type == FLAC__FRAME_NUMBER_TYPE_SAMPLE_NUMBER);
  93413. encoder->private_->verify.error_stats.absolute_sample = frame->header.number.sample_number + sample;
  93414. encoder->private_->verify.error_stats.frame_number = (unsigned)(frame->header.number.sample_number / blocksize);
  93415. encoder->private_->verify.error_stats.channel = channel;
  93416. encoder->private_->verify.error_stats.sample = sample;
  93417. encoder->private_->verify.error_stats.expected = expect;
  93418. encoder->private_->verify.error_stats.got = got;
  93419. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_MISMATCH_IN_AUDIO_DATA;
  93420. return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
  93421. }
  93422. }
  93423. encoder->private_->verify.input_fifo.tail -= blocksize;
  93424. FLAC__ASSERT(encoder->private_->verify.input_fifo.tail <= OVERREAD_);
  93425. for(channel = 0; channel < channels; channel++)
  93426. 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]));
  93427. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  93428. }
  93429. void verify_metadata_callback_(const FLAC__StreamDecoder *decoder, const FLAC__StreamMetadata *metadata, void *client_data)
  93430. {
  93431. (void)decoder, (void)metadata, (void)client_data;
  93432. }
  93433. void verify_error_callback_(const FLAC__StreamDecoder *decoder, FLAC__StreamDecoderErrorStatus status, void *client_data)
  93434. {
  93435. FLAC__StreamEncoder *encoder = (FLAC__StreamEncoder*)client_data;
  93436. (void)decoder, (void)status;
  93437. encoder->protected_->state = FLAC__STREAM_ENCODER_VERIFY_DECODER_ERROR;
  93438. }
  93439. FLAC__StreamEncoderReadStatus file_read_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__byte buffer[], size_t *bytes, void *client_data)
  93440. {
  93441. (void)client_data;
  93442. *bytes = fread(buffer, 1, *bytes, encoder->private_->file);
  93443. if (*bytes == 0) {
  93444. if (feof(encoder->private_->file))
  93445. return FLAC__STREAM_ENCODER_READ_STATUS_END_OF_STREAM;
  93446. else if (ferror(encoder->private_->file))
  93447. return FLAC__STREAM_ENCODER_READ_STATUS_ABORT;
  93448. }
  93449. return FLAC__STREAM_ENCODER_READ_STATUS_CONTINUE;
  93450. }
  93451. FLAC__StreamEncoderSeekStatus file_seek_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 absolute_byte_offset, void *client_data)
  93452. {
  93453. (void)client_data;
  93454. if(fseeko(encoder->private_->file, (off_t)absolute_byte_offset, SEEK_SET) < 0)
  93455. return FLAC__STREAM_ENCODER_SEEK_STATUS_ERROR;
  93456. else
  93457. return FLAC__STREAM_ENCODER_SEEK_STATUS_OK;
  93458. }
  93459. FLAC__StreamEncoderTellStatus file_tell_callback_enc(const FLAC__StreamEncoder *encoder, FLAC__uint64 *absolute_byte_offset, void *client_data)
  93460. {
  93461. off_t offset;
  93462. (void)client_data;
  93463. offset = ftello(encoder->private_->file);
  93464. if(offset < 0) {
  93465. return FLAC__STREAM_ENCODER_TELL_STATUS_ERROR;
  93466. }
  93467. else {
  93468. *absolute_byte_offset = (FLAC__uint64)offset;
  93469. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  93470. }
  93471. }
  93472. #ifdef FLAC__VALGRIND_TESTING
  93473. static size_t local__fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream)
  93474. {
  93475. size_t ret = fwrite(ptr, size, nmemb, stream);
  93476. if(!ferror(stream))
  93477. fflush(stream);
  93478. return ret;
  93479. }
  93480. #else
  93481. #define local__fwrite fwrite
  93482. #endif
  93483. FLAC__StreamEncoderWriteStatus file_write_callback_(const FLAC__StreamEncoder *encoder, const FLAC__byte buffer[], size_t bytes, unsigned samples, unsigned current_frame, void *client_data)
  93484. {
  93485. (void)client_data, (void)current_frame;
  93486. if(local__fwrite(buffer, sizeof(FLAC__byte), bytes, encoder->private_->file) == bytes) {
  93487. FLAC__bool call_it = 0 != encoder->private_->progress_callback && (
  93488. #if FLAC__HAS_OGG
  93489. encoder->private_->is_ogg? true :
  93490. #endif
  93491. samples > 0
  93492. );
  93493. if(call_it) {
  93494. 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);
  93495. }
  93496. return FLAC__STREAM_ENCODER_WRITE_STATUS_OK;
  93497. }
  93498. else
  93499. return FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  93500. }
  93501. FILE *get_binary_stdout_(void)
  93502. {
  93503. #if defined _MSC_VER || defined __MINGW32__
  93504. _setmode(_fileno(stdout), _O_BINARY);
  93505. #elif defined __CYGWIN__
  93506. setmode(_fileno(stdout), _O_BINARY);
  93507. #elif defined __EMX__
  93508. setmode(fileno(stdout), O_BINARY);
  93509. #endif
  93510. return stdout;
  93511. }
  93512. #endif
  93513. /*** End of inlined file: stream_encoder.c ***/
  93514. /*** Start of inlined file: stream_encoder_framing.c ***/
  93515. /*** Start of inlined file: juce_FlacHeader.h ***/
  93516. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93517. // tasks..
  93518. #define VERSION "1.2.1"
  93519. #define FLAC__NO_DLL 1
  93520. #if JUCE_MSVC
  93521. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  93522. #endif
  93523. #if JUCE_MAC
  93524. #define FLAC__SYS_DARWIN 1
  93525. #endif
  93526. /*** End of inlined file: juce_FlacHeader.h ***/
  93527. #if JUCE_USE_FLAC
  93528. #if HAVE_CONFIG_H
  93529. # include <config.h>
  93530. #endif
  93531. #include <stdio.h>
  93532. #include <string.h> /* for strlen() */
  93533. #ifdef max
  93534. #undef max
  93535. #endif
  93536. #define max(x,y) ((x)>(y)?(x):(y))
  93537. static FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method);
  93538. 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);
  93539. FLAC__bool FLAC__add_metadata_block(const FLAC__StreamMetadata *metadata, FLAC__BitWriter *bw)
  93540. {
  93541. unsigned i, j;
  93542. const unsigned vendor_string_length = (unsigned)strlen(FLAC__VENDOR_STRING);
  93543. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->is_last, FLAC__STREAM_METADATA_IS_LAST_LEN))
  93544. return false;
  93545. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->type, FLAC__STREAM_METADATA_TYPE_LEN))
  93546. return false;
  93547. i = metadata->length;
  93548. if(metadata->type == FLAC__METADATA_TYPE_VORBIS_COMMENT) {
  93549. FLAC__ASSERT(metadata->data.vorbis_comment.vendor_string.length == 0 || 0 != metadata->data.vorbis_comment.vendor_string.entry);
  93550. i -= metadata->data.vorbis_comment.vendor_string.length;
  93551. i += vendor_string_length;
  93552. }
  93553. FLAC__ASSERT(i < (1u << FLAC__STREAM_METADATA_LENGTH_LEN));
  93554. if(!FLAC__bitwriter_write_raw_uint32(bw, i, FLAC__STREAM_METADATA_LENGTH_LEN))
  93555. return false;
  93556. switch(metadata->type) {
  93557. case FLAC__METADATA_TYPE_STREAMINFO:
  93558. FLAC__ASSERT(metadata->data.stream_info.min_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN));
  93559. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MIN_BLOCK_SIZE_LEN))
  93560. return false;
  93561. FLAC__ASSERT(metadata->data.stream_info.max_blocksize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN));
  93562. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_blocksize, FLAC__STREAM_METADATA_STREAMINFO_MAX_BLOCK_SIZE_LEN))
  93563. return false;
  93564. FLAC__ASSERT(metadata->data.stream_info.min_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN));
  93565. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.min_framesize, FLAC__STREAM_METADATA_STREAMINFO_MIN_FRAME_SIZE_LEN))
  93566. return false;
  93567. FLAC__ASSERT(metadata->data.stream_info.max_framesize < (1u << FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN));
  93568. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.max_framesize, FLAC__STREAM_METADATA_STREAMINFO_MAX_FRAME_SIZE_LEN))
  93569. return false;
  93570. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(metadata->data.stream_info.sample_rate));
  93571. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.sample_rate, FLAC__STREAM_METADATA_STREAMINFO_SAMPLE_RATE_LEN))
  93572. return false;
  93573. FLAC__ASSERT(metadata->data.stream_info.channels > 0);
  93574. FLAC__ASSERT(metadata->data.stream_info.channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN));
  93575. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.channels-1, FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN))
  93576. return false;
  93577. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample > 0);
  93578. FLAC__ASSERT(metadata->data.stream_info.bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93579. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.stream_info.bits_per_sample-1, FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN))
  93580. return false;
  93581. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.stream_info.total_samples, FLAC__STREAM_METADATA_STREAMINFO_TOTAL_SAMPLES_LEN))
  93582. return false;
  93583. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.stream_info.md5sum, 16))
  93584. return false;
  93585. break;
  93586. case FLAC__METADATA_TYPE_PADDING:
  93587. if(!FLAC__bitwriter_write_zeroes(bw, metadata->length * 8))
  93588. return false;
  93589. break;
  93590. case FLAC__METADATA_TYPE_APPLICATION:
  93591. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.id, FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8))
  93592. return false;
  93593. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.application.data, metadata->length - (FLAC__STREAM_METADATA_APPLICATION_ID_LEN / 8)))
  93594. return false;
  93595. break;
  93596. case FLAC__METADATA_TYPE_SEEKTABLE:
  93597. for(i = 0; i < metadata->data.seek_table.num_points; i++) {
  93598. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].sample_number, FLAC__STREAM_METADATA_SEEKPOINT_SAMPLE_NUMBER_LEN))
  93599. return false;
  93600. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.seek_table.points[i].stream_offset, FLAC__STREAM_METADATA_SEEKPOINT_STREAM_OFFSET_LEN))
  93601. return false;
  93602. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.seek_table.points[i].frame_samples, FLAC__STREAM_METADATA_SEEKPOINT_FRAME_SAMPLES_LEN))
  93603. return false;
  93604. }
  93605. break;
  93606. case FLAC__METADATA_TYPE_VORBIS_COMMENT:
  93607. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, vendor_string_length))
  93608. return false;
  93609. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)FLAC__VENDOR_STRING, vendor_string_length))
  93610. return false;
  93611. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.num_comments))
  93612. return false;
  93613. for(i = 0; i < metadata->data.vorbis_comment.num_comments; i++) {
  93614. if(!FLAC__bitwriter_write_raw_uint32_little_endian(bw, metadata->data.vorbis_comment.comments[i].length))
  93615. return false;
  93616. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.vorbis_comment.comments[i].entry, metadata->data.vorbis_comment.comments[i].length))
  93617. return false;
  93618. }
  93619. break;
  93620. case FLAC__METADATA_TYPE_CUESHEET:
  93621. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_MEDIA_CATALOG_NUMBER_LEN % 8 == 0);
  93622. 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))
  93623. return false;
  93624. if(!FLAC__bitwriter_write_raw_uint64(bw, metadata->data.cue_sheet.lead_in, FLAC__STREAM_METADATA_CUESHEET_LEAD_IN_LEN))
  93625. return false;
  93626. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.is_cd? 1 : 0, FLAC__STREAM_METADATA_CUESHEET_IS_CD_LEN))
  93627. return false;
  93628. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_RESERVED_LEN))
  93629. return false;
  93630. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.cue_sheet.num_tracks, FLAC__STREAM_METADATA_CUESHEET_NUM_TRACKS_LEN))
  93631. return false;
  93632. for(i = 0; i < metadata->data.cue_sheet.num_tracks; i++) {
  93633. const FLAC__StreamMetadata_CueSheet_Track *track = metadata->data.cue_sheet.tracks + i;
  93634. if(!FLAC__bitwriter_write_raw_uint64(bw, track->offset, FLAC__STREAM_METADATA_CUESHEET_TRACK_OFFSET_LEN))
  93635. return false;
  93636. if(!FLAC__bitwriter_write_raw_uint32(bw, track->number, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUMBER_LEN))
  93637. return false;
  93638. FLAC__ASSERT(FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN % 8 == 0);
  93639. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)track->isrc, FLAC__STREAM_METADATA_CUESHEET_TRACK_ISRC_LEN/8))
  93640. return false;
  93641. if(!FLAC__bitwriter_write_raw_uint32(bw, track->type, FLAC__STREAM_METADATA_CUESHEET_TRACK_TYPE_LEN))
  93642. return false;
  93643. if(!FLAC__bitwriter_write_raw_uint32(bw, track->pre_emphasis, FLAC__STREAM_METADATA_CUESHEET_TRACK_PRE_EMPHASIS_LEN))
  93644. return false;
  93645. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_TRACK_RESERVED_LEN))
  93646. return false;
  93647. if(!FLAC__bitwriter_write_raw_uint32(bw, track->num_indices, FLAC__STREAM_METADATA_CUESHEET_TRACK_NUM_INDICES_LEN))
  93648. return false;
  93649. for(j = 0; j < track->num_indices; j++) {
  93650. const FLAC__StreamMetadata_CueSheet_Index *index = track->indices + j;
  93651. if(!FLAC__bitwriter_write_raw_uint64(bw, index->offset, FLAC__STREAM_METADATA_CUESHEET_INDEX_OFFSET_LEN))
  93652. return false;
  93653. if(!FLAC__bitwriter_write_raw_uint32(bw, index->number, FLAC__STREAM_METADATA_CUESHEET_INDEX_NUMBER_LEN))
  93654. return false;
  93655. if(!FLAC__bitwriter_write_zeroes(bw, FLAC__STREAM_METADATA_CUESHEET_INDEX_RESERVED_LEN))
  93656. return false;
  93657. }
  93658. }
  93659. break;
  93660. case FLAC__METADATA_TYPE_PICTURE:
  93661. {
  93662. size_t len;
  93663. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.type, FLAC__STREAM_METADATA_PICTURE_TYPE_LEN))
  93664. return false;
  93665. len = strlen(metadata->data.picture.mime_type);
  93666. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_MIME_TYPE_LENGTH_LEN))
  93667. return false;
  93668. if(!FLAC__bitwriter_write_byte_block(bw, (const FLAC__byte*)metadata->data.picture.mime_type, len))
  93669. return false;
  93670. len = strlen((const char *)metadata->data.picture.description);
  93671. if(!FLAC__bitwriter_write_raw_uint32(bw, len, FLAC__STREAM_METADATA_PICTURE_DESCRIPTION_LENGTH_LEN))
  93672. return false;
  93673. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.description, len))
  93674. return false;
  93675. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.width, FLAC__STREAM_METADATA_PICTURE_WIDTH_LEN))
  93676. return false;
  93677. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.height, FLAC__STREAM_METADATA_PICTURE_HEIGHT_LEN))
  93678. return false;
  93679. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.depth, FLAC__STREAM_METADATA_PICTURE_DEPTH_LEN))
  93680. return false;
  93681. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.colors, FLAC__STREAM_METADATA_PICTURE_COLORS_LEN))
  93682. return false;
  93683. if(!FLAC__bitwriter_write_raw_uint32(bw, metadata->data.picture.data_length, FLAC__STREAM_METADATA_PICTURE_DATA_LENGTH_LEN))
  93684. return false;
  93685. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.picture.data, metadata->data.picture.data_length))
  93686. return false;
  93687. }
  93688. break;
  93689. default:
  93690. if(!FLAC__bitwriter_write_byte_block(bw, metadata->data.unknown.data, metadata->length))
  93691. return false;
  93692. break;
  93693. }
  93694. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93695. return true;
  93696. }
  93697. FLAC__bool FLAC__frame_add_header(const FLAC__FrameHeader *header, FLAC__BitWriter *bw)
  93698. {
  93699. unsigned u, blocksize_hint, sample_rate_hint;
  93700. FLAC__byte crc;
  93701. FLAC__ASSERT(FLAC__bitwriter_is_byte_aligned(bw));
  93702. if(!FLAC__bitwriter_write_raw_uint32(bw, FLAC__FRAME_HEADER_SYNC, FLAC__FRAME_HEADER_SYNC_LEN))
  93703. return false;
  93704. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_RESERVED_LEN))
  93705. return false;
  93706. if(!FLAC__bitwriter_write_raw_uint32(bw, (header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER)? 0 : 1, FLAC__FRAME_HEADER_BLOCKING_STRATEGY_LEN))
  93707. return false;
  93708. FLAC__ASSERT(header->blocksize > 0 && header->blocksize <= FLAC__MAX_BLOCK_SIZE);
  93709. FLAC__ASSERT(FLAC__MAX_BLOCK_SIZE <= 65535u);
  93710. blocksize_hint = 0;
  93711. switch(header->blocksize) {
  93712. case 192: u = 1; break;
  93713. case 576: u = 2; break;
  93714. case 1152: u = 3; break;
  93715. case 2304: u = 4; break;
  93716. case 4608: u = 5; break;
  93717. case 256: u = 8; break;
  93718. case 512: u = 9; break;
  93719. case 1024: u = 10; break;
  93720. case 2048: u = 11; break;
  93721. case 4096: u = 12; break;
  93722. case 8192: u = 13; break;
  93723. case 16384: u = 14; break;
  93724. case 32768: u = 15; break;
  93725. default:
  93726. if(header->blocksize <= 0x100)
  93727. blocksize_hint = u = 6;
  93728. else
  93729. blocksize_hint = u = 7;
  93730. break;
  93731. }
  93732. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BLOCK_SIZE_LEN))
  93733. return false;
  93734. FLAC__ASSERT(FLAC__format_sample_rate_is_valid(header->sample_rate));
  93735. sample_rate_hint = 0;
  93736. switch(header->sample_rate) {
  93737. case 88200: u = 1; break;
  93738. case 176400: u = 2; break;
  93739. case 192000: u = 3; break;
  93740. case 8000: u = 4; break;
  93741. case 16000: u = 5; break;
  93742. case 22050: u = 6; break;
  93743. case 24000: u = 7; break;
  93744. case 32000: u = 8; break;
  93745. case 44100: u = 9; break;
  93746. case 48000: u = 10; break;
  93747. case 96000: u = 11; break;
  93748. default:
  93749. if(header->sample_rate <= 255000 && header->sample_rate % 1000 == 0)
  93750. sample_rate_hint = u = 12;
  93751. else if(header->sample_rate % 10 == 0)
  93752. sample_rate_hint = u = 14;
  93753. else if(header->sample_rate <= 0xffff)
  93754. sample_rate_hint = u = 13;
  93755. else
  93756. u = 0;
  93757. break;
  93758. }
  93759. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_SAMPLE_RATE_LEN))
  93760. return false;
  93761. FLAC__ASSERT(header->channels > 0 && header->channels <= (1u << FLAC__STREAM_METADATA_STREAMINFO_CHANNELS_LEN) && header->channels <= FLAC__MAX_CHANNELS);
  93762. switch(header->channel_assignment) {
  93763. case FLAC__CHANNEL_ASSIGNMENT_INDEPENDENT:
  93764. u = header->channels - 1;
  93765. break;
  93766. case FLAC__CHANNEL_ASSIGNMENT_LEFT_SIDE:
  93767. FLAC__ASSERT(header->channels == 2);
  93768. u = 8;
  93769. break;
  93770. case FLAC__CHANNEL_ASSIGNMENT_RIGHT_SIDE:
  93771. FLAC__ASSERT(header->channels == 2);
  93772. u = 9;
  93773. break;
  93774. case FLAC__CHANNEL_ASSIGNMENT_MID_SIDE:
  93775. FLAC__ASSERT(header->channels == 2);
  93776. u = 10;
  93777. break;
  93778. default:
  93779. FLAC__ASSERT(0);
  93780. }
  93781. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_CHANNEL_ASSIGNMENT_LEN))
  93782. return false;
  93783. FLAC__ASSERT(header->bits_per_sample > 0 && header->bits_per_sample <= (1u << FLAC__STREAM_METADATA_STREAMINFO_BITS_PER_SAMPLE_LEN));
  93784. switch(header->bits_per_sample) {
  93785. case 8 : u = 1; break;
  93786. case 12: u = 2; break;
  93787. case 16: u = 4; break;
  93788. case 20: u = 5; break;
  93789. case 24: u = 6; break;
  93790. default: u = 0; break;
  93791. }
  93792. if(!FLAC__bitwriter_write_raw_uint32(bw, u, FLAC__FRAME_HEADER_BITS_PER_SAMPLE_LEN))
  93793. return false;
  93794. if(!FLAC__bitwriter_write_raw_uint32(bw, 0, FLAC__FRAME_HEADER_ZERO_PAD_LEN))
  93795. return false;
  93796. if(header->number_type == FLAC__FRAME_NUMBER_TYPE_FRAME_NUMBER) {
  93797. if(!FLAC__bitwriter_write_utf8_uint32(bw, header->number.frame_number))
  93798. return false;
  93799. }
  93800. else {
  93801. if(!FLAC__bitwriter_write_utf8_uint64(bw, header->number.sample_number))
  93802. return false;
  93803. }
  93804. if(blocksize_hint)
  93805. if(!FLAC__bitwriter_write_raw_uint32(bw, header->blocksize-1, (blocksize_hint==6)? 8:16))
  93806. return false;
  93807. switch(sample_rate_hint) {
  93808. case 12:
  93809. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 1000, 8))
  93810. return false;
  93811. break;
  93812. case 13:
  93813. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate, 16))
  93814. return false;
  93815. break;
  93816. case 14:
  93817. if(!FLAC__bitwriter_write_raw_uint32(bw, header->sample_rate / 10, 16))
  93818. return false;
  93819. break;
  93820. }
  93821. if(!FLAC__bitwriter_get_write_crc8(bw, &crc))
  93822. return false;
  93823. if(!FLAC__bitwriter_write_raw_uint32(bw, crc, FLAC__FRAME_HEADER_CRC_LEN))
  93824. return false;
  93825. return true;
  93826. }
  93827. FLAC__bool FLAC__subframe_add_constant(const FLAC__Subframe_Constant *subframe, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93828. {
  93829. FLAC__bool ok;
  93830. ok =
  93831. 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) &&
  93832. (wasted_bits? FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1) : true) &&
  93833. FLAC__bitwriter_write_raw_int32(bw, subframe->value, subframe_bps)
  93834. ;
  93835. return ok;
  93836. }
  93837. FLAC__bool FLAC__subframe_add_fixed(const FLAC__Subframe_Fixed *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93838. {
  93839. unsigned i;
  93840. 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))
  93841. return false;
  93842. if(wasted_bits)
  93843. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93844. return false;
  93845. for(i = 0; i < subframe->order; i++)
  93846. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93847. return false;
  93848. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93849. return false;
  93850. switch(subframe->entropy_coding_method.type) {
  93851. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93852. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93853. if(!add_residual_partitioned_rice_(
  93854. bw,
  93855. subframe->residual,
  93856. residual_samples,
  93857. subframe->order,
  93858. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93859. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93860. subframe->entropy_coding_method.data.partitioned_rice.order,
  93861. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93862. ))
  93863. return false;
  93864. break;
  93865. default:
  93866. FLAC__ASSERT(0);
  93867. }
  93868. return true;
  93869. }
  93870. FLAC__bool FLAC__subframe_add_lpc(const FLAC__Subframe_LPC *subframe, unsigned residual_samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93871. {
  93872. unsigned i;
  93873. 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))
  93874. return false;
  93875. if(wasted_bits)
  93876. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93877. return false;
  93878. for(i = 0; i < subframe->order; i++)
  93879. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->warmup[i], subframe_bps))
  93880. return false;
  93881. if(!FLAC__bitwriter_write_raw_uint32(bw, subframe->qlp_coeff_precision-1, FLAC__SUBFRAME_LPC_QLP_COEFF_PRECISION_LEN))
  93882. return false;
  93883. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->quantization_level, FLAC__SUBFRAME_LPC_QLP_SHIFT_LEN))
  93884. return false;
  93885. for(i = 0; i < subframe->order; i++)
  93886. if(!FLAC__bitwriter_write_raw_int32(bw, subframe->qlp_coeff[i], subframe->qlp_coeff_precision))
  93887. return false;
  93888. if(!add_entropy_coding_method_(bw, &subframe->entropy_coding_method))
  93889. return false;
  93890. switch(subframe->entropy_coding_method.type) {
  93891. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93892. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93893. if(!add_residual_partitioned_rice_(
  93894. bw,
  93895. subframe->residual,
  93896. residual_samples,
  93897. subframe->order,
  93898. subframe->entropy_coding_method.data.partitioned_rice.contents->parameters,
  93899. subframe->entropy_coding_method.data.partitioned_rice.contents->raw_bits,
  93900. subframe->entropy_coding_method.data.partitioned_rice.order,
  93901. subframe->entropy_coding_method.type == FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2
  93902. ))
  93903. return false;
  93904. break;
  93905. default:
  93906. FLAC__ASSERT(0);
  93907. }
  93908. return true;
  93909. }
  93910. FLAC__bool FLAC__subframe_add_verbatim(const FLAC__Subframe_Verbatim *subframe, unsigned samples, unsigned subframe_bps, unsigned wasted_bits, FLAC__BitWriter *bw)
  93911. {
  93912. unsigned i;
  93913. const FLAC__int32 *signal = subframe->data;
  93914. 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))
  93915. return false;
  93916. if(wasted_bits)
  93917. if(!FLAC__bitwriter_write_unary_unsigned(bw, wasted_bits-1))
  93918. return false;
  93919. for(i = 0; i < samples; i++)
  93920. if(!FLAC__bitwriter_write_raw_int32(bw, signal[i], subframe_bps))
  93921. return false;
  93922. return true;
  93923. }
  93924. FLAC__bool add_entropy_coding_method_(FLAC__BitWriter *bw, const FLAC__EntropyCodingMethod *method)
  93925. {
  93926. if(!FLAC__bitwriter_write_raw_uint32(bw, method->type, FLAC__ENTROPY_CODING_METHOD_TYPE_LEN))
  93927. return false;
  93928. switch(method->type) {
  93929. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE:
  93930. case FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2:
  93931. if(!FLAC__bitwriter_write_raw_uint32(bw, method->data.partitioned_rice.order, FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ORDER_LEN))
  93932. return false;
  93933. break;
  93934. default:
  93935. FLAC__ASSERT(0);
  93936. }
  93937. return true;
  93938. }
  93939. 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)
  93940. {
  93941. const unsigned plen = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_PARAMETER_LEN : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_PARAMETER_LEN;
  93942. const unsigned pesc = is_extended? FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE2_ESCAPE_PARAMETER : FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_ESCAPE_PARAMETER;
  93943. if(partition_order == 0) {
  93944. unsigned i;
  93945. if(raw_bits[0] == 0) {
  93946. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[0], plen))
  93947. return false;
  93948. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual, residual_samples, rice_parameters[0]))
  93949. return false;
  93950. }
  93951. else {
  93952. FLAC__ASSERT(rice_parameters[0] == 0);
  93953. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93954. return false;
  93955. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[0], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93956. return false;
  93957. for(i = 0; i < residual_samples; i++) {
  93958. if(!FLAC__bitwriter_write_raw_int32(bw, residual[i], raw_bits[0]))
  93959. return false;
  93960. }
  93961. }
  93962. return true;
  93963. }
  93964. else {
  93965. unsigned i, j, k = 0, k_last = 0;
  93966. unsigned partition_samples;
  93967. const unsigned default_partition_samples = (residual_samples+predictor_order) >> partition_order;
  93968. for(i = 0; i < (1u<<partition_order); i++) {
  93969. partition_samples = default_partition_samples;
  93970. if(i == 0)
  93971. partition_samples -= predictor_order;
  93972. k += partition_samples;
  93973. if(raw_bits[i] == 0) {
  93974. if(!FLAC__bitwriter_write_raw_uint32(bw, rice_parameters[i], plen))
  93975. return false;
  93976. if(!FLAC__bitwriter_write_rice_signed_block(bw, residual+k_last, k-k_last, rice_parameters[i]))
  93977. return false;
  93978. }
  93979. else {
  93980. if(!FLAC__bitwriter_write_raw_uint32(bw, pesc, plen))
  93981. return false;
  93982. if(!FLAC__bitwriter_write_raw_uint32(bw, raw_bits[i], FLAC__ENTROPY_CODING_METHOD_PARTITIONED_RICE_RAW_LEN))
  93983. return false;
  93984. for(j = k_last; j < k; j++) {
  93985. if(!FLAC__bitwriter_write_raw_int32(bw, residual[j], raw_bits[i]))
  93986. return false;
  93987. }
  93988. }
  93989. k_last = k;
  93990. }
  93991. return true;
  93992. }
  93993. }
  93994. #endif
  93995. /*** End of inlined file: stream_encoder_framing.c ***/
  93996. /*** Start of inlined file: window_flac.c ***/
  93997. /*** Start of inlined file: juce_FlacHeader.h ***/
  93998. // This file is included at the start of each FLAC .c file, just to do a few housekeeping
  93999. // tasks..
  94000. #define VERSION "1.2.1"
  94001. #define FLAC__NO_DLL 1
  94002. #if JUCE_MSVC
  94003. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4312)
  94004. #endif
  94005. #if JUCE_MAC
  94006. #define FLAC__SYS_DARWIN 1
  94007. #endif
  94008. /*** End of inlined file: juce_FlacHeader.h ***/
  94009. #if JUCE_USE_FLAC
  94010. #if HAVE_CONFIG_H
  94011. # include <config.h>
  94012. #endif
  94013. #include <math.h>
  94014. #ifndef FLAC__INTEGER_ONLY_LIBRARY
  94015. #ifndef M_PI
  94016. #define M_PI 3.14159265358979323846
  94017. #endif
  94018. void FLAC__window_bartlett(FLAC__real *window, const FLAC__int32 L)
  94019. {
  94020. const FLAC__int32 N = L - 1;
  94021. FLAC__int32 n;
  94022. if (L & 1) {
  94023. for (n = 0; n <= N/2; n++)
  94024. window[n] = 2.0f * n / (float)N;
  94025. for (; n <= N; n++)
  94026. window[n] = 2.0f - 2.0f * n / (float)N;
  94027. }
  94028. else {
  94029. for (n = 0; n <= L/2-1; n++)
  94030. window[n] = 2.0f * n / (float)N;
  94031. for (; n <= N; n++)
  94032. window[n] = 2.0f - 2.0f * (N-n) / (float)N;
  94033. }
  94034. }
  94035. void FLAC__window_bartlett_hann(FLAC__real *window, const FLAC__int32 L)
  94036. {
  94037. const FLAC__int32 N = L - 1;
  94038. FLAC__int32 n;
  94039. for (n = 0; n < L; n++)
  94040. 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)));
  94041. }
  94042. void FLAC__window_blackman(FLAC__real *window, const FLAC__int32 L)
  94043. {
  94044. const FLAC__int32 N = L - 1;
  94045. FLAC__int32 n;
  94046. for (n = 0; n < L; n++)
  94047. window[n] = (FLAC__real)(0.42f - 0.5f * cos(2.0f * M_PI * n / N) + 0.08f * cos(4.0f * M_PI * n / N));
  94048. }
  94049. void FLAC__window_blackman_harris_4term_92db_sidelobe(FLAC__real *window, const FLAC__int32 L)
  94050. {
  94051. const FLAC__int32 N = L - 1;
  94052. FLAC__int32 n;
  94053. for (n = 0; n <= N; n++)
  94054. 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));
  94055. }
  94056. void FLAC__window_connes(FLAC__real *window, const FLAC__int32 L)
  94057. {
  94058. const FLAC__int32 N = L - 1;
  94059. const double N2 = (double)N / 2.;
  94060. FLAC__int32 n;
  94061. for (n = 0; n <= N; n++) {
  94062. double k = ((double)n - N2) / N2;
  94063. k = 1.0f - k * k;
  94064. window[n] = (FLAC__real)(k * k);
  94065. }
  94066. }
  94067. void FLAC__window_flattop(FLAC__real *window, const FLAC__int32 L)
  94068. {
  94069. const FLAC__int32 N = L - 1;
  94070. FLAC__int32 n;
  94071. for (n = 0; n < L; n++)
  94072. 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));
  94073. }
  94074. void FLAC__window_gauss(FLAC__real *window, const FLAC__int32 L, const FLAC__real stddev)
  94075. {
  94076. const FLAC__int32 N = L - 1;
  94077. const double N2 = (double)N / 2.;
  94078. FLAC__int32 n;
  94079. for (n = 0; n <= N; n++) {
  94080. const double k = ((double)n - N2) / (stddev * N2);
  94081. window[n] = (FLAC__real)exp(-0.5f * k * k);
  94082. }
  94083. }
  94084. void FLAC__window_hamming(FLAC__real *window, const FLAC__int32 L)
  94085. {
  94086. const FLAC__int32 N = L - 1;
  94087. FLAC__int32 n;
  94088. for (n = 0; n < L; n++)
  94089. window[n] = (FLAC__real)(0.54f - 0.46f * cos(2.0f * M_PI * n / N));
  94090. }
  94091. void FLAC__window_hann(FLAC__real *window, const FLAC__int32 L)
  94092. {
  94093. const FLAC__int32 N = L - 1;
  94094. FLAC__int32 n;
  94095. for (n = 0; n < L; n++)
  94096. window[n] = (FLAC__real)(0.5f - 0.5f * cos(2.0f * M_PI * n / N));
  94097. }
  94098. void FLAC__window_kaiser_bessel(FLAC__real *window, const FLAC__int32 L)
  94099. {
  94100. const FLAC__int32 N = L - 1;
  94101. FLAC__int32 n;
  94102. for (n = 0; n < L; n++)
  94103. 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));
  94104. }
  94105. void FLAC__window_nuttall(FLAC__real *window, const FLAC__int32 L)
  94106. {
  94107. const FLAC__int32 N = L - 1;
  94108. FLAC__int32 n;
  94109. for (n = 0; n < L; n++)
  94110. 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));
  94111. }
  94112. void FLAC__window_rectangle(FLAC__real *window, const FLAC__int32 L)
  94113. {
  94114. FLAC__int32 n;
  94115. for (n = 0; n < L; n++)
  94116. window[n] = 1.0f;
  94117. }
  94118. void FLAC__window_triangle(FLAC__real *window, const FLAC__int32 L)
  94119. {
  94120. FLAC__int32 n;
  94121. if (L & 1) {
  94122. for (n = 1; n <= L+1/2; n++)
  94123. window[n-1] = 2.0f * n / ((float)L + 1.0f);
  94124. for (; n <= L; n++)
  94125. window[n-1] = - (float)(2 * (L - n + 1)) / ((float)L + 1.0f);
  94126. }
  94127. else {
  94128. for (n = 1; n <= L/2; n++)
  94129. window[n-1] = 2.0f * n / (float)L;
  94130. for (; n <= L; n++)
  94131. window[n-1] = ((float)(2 * (L - n)) + 1.0f) / (float)L;
  94132. }
  94133. }
  94134. void FLAC__window_tukey(FLAC__real *window, const FLAC__int32 L, const FLAC__real p)
  94135. {
  94136. if (p <= 0.0)
  94137. FLAC__window_rectangle(window, L);
  94138. else if (p >= 1.0)
  94139. FLAC__window_hann(window, L);
  94140. else {
  94141. const FLAC__int32 Np = (FLAC__int32)(p / 2.0f * L) - 1;
  94142. FLAC__int32 n;
  94143. FLAC__window_rectangle(window, L);
  94144. if (Np > 0) {
  94145. for (n = 0; n <= Np; n++) {
  94146. window[n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * n / Np));
  94147. window[L-Np-1+n] = (FLAC__real)(0.5f - 0.5f * cos(M_PI * (n+Np) / Np));
  94148. }
  94149. }
  94150. }
  94151. }
  94152. void FLAC__window_welch(FLAC__real *window, const FLAC__int32 L)
  94153. {
  94154. const FLAC__int32 N = L - 1;
  94155. const double N2 = (double)N / 2.;
  94156. FLAC__int32 n;
  94157. for (n = 0; n <= N; n++) {
  94158. const double k = ((double)n - N2) / N2;
  94159. window[n] = (FLAC__real)(1.0f - k * k);
  94160. }
  94161. }
  94162. #endif /* !defined FLAC__INTEGER_ONLY_LIBRARY */
  94163. #endif
  94164. /*** End of inlined file: window_flac.c ***/
  94165. #else
  94166. #include <FLAC/all.h>
  94167. #endif
  94168. }
  94169. #ifdef _MSC_VER
  94170. #pragma warning (pop)
  94171. #endif
  94172. BEGIN_JUCE_NAMESPACE
  94173. using namespace FlacNamespace;
  94174. static const char* const flacFormatName = "FLAC file";
  94175. static const tchar* const flacExtensions[] = { T(".flac"), 0 };
  94176. class FlacReader : public AudioFormatReader
  94177. {
  94178. FLAC__StreamDecoder* decoder;
  94179. AudioSampleBuffer reservoir;
  94180. int reservoirStart, samplesInReservoir;
  94181. bool ok, scanningForLength;
  94182. public:
  94183. FlacReader (InputStream* const in)
  94184. : AudioFormatReader (in, TRANS (flacFormatName)),
  94185. reservoir (2, 0),
  94186. reservoirStart (0),
  94187. samplesInReservoir (0),
  94188. scanningForLength (false)
  94189. {
  94190. using namespace FlacNamespace;
  94191. lengthInSamples = 0;
  94192. decoder = FLAC__stream_decoder_new();
  94193. ok = FLAC__stream_decoder_init_stream (decoder,
  94194. readCallback_, seekCallback_, tellCallback_, lengthCallback_,
  94195. eofCallback_, writeCallback_, metadataCallback_, errorCallback_,
  94196. (void*) this) == FLAC__STREAM_DECODER_INIT_STATUS_OK;
  94197. if (ok)
  94198. {
  94199. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  94200. if (lengthInSamples == 0 && sampleRate > 0)
  94201. {
  94202. // the length hasn't been stored in the metadata, so we'll need to
  94203. // work it out the length the hard way, by scanning the whole file..
  94204. scanningForLength = true;
  94205. FLAC__stream_decoder_process_until_end_of_stream (decoder);
  94206. scanningForLength = false;
  94207. const int64 tempLength = lengthInSamples;
  94208. FLAC__stream_decoder_reset (decoder);
  94209. FLAC__stream_decoder_process_until_end_of_metadata (decoder);
  94210. lengthInSamples = tempLength;
  94211. }
  94212. }
  94213. }
  94214. ~FlacReader()
  94215. {
  94216. FLAC__stream_decoder_delete (decoder);
  94217. }
  94218. void useMetadata (const FLAC__StreamMetadata_StreamInfo& info)
  94219. {
  94220. sampleRate = info.sample_rate;
  94221. bitsPerSample = info.bits_per_sample;
  94222. lengthInSamples = (unsigned int) info.total_samples;
  94223. numChannels = info.channels;
  94224. reservoir.setSize (numChannels, 2 * info.max_blocksize, false, false, true);
  94225. }
  94226. // returns the number of samples read
  94227. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  94228. int64 startSampleInFile, int numSamples)
  94229. {
  94230. using namespace FlacNamespace;
  94231. if (! ok)
  94232. return false;
  94233. while (numSamples > 0)
  94234. {
  94235. if (startSampleInFile >= reservoirStart
  94236. && startSampleInFile < reservoirStart + samplesInReservoir)
  94237. {
  94238. const int num = (int) jmin ((int64) numSamples,
  94239. reservoirStart + samplesInReservoir - startSampleInFile);
  94240. jassert (num > 0);
  94241. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  94242. if (destSamples[i] != 0)
  94243. memcpy (destSamples[i] + startOffsetInDestBuffer,
  94244. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  94245. sizeof (int) * num);
  94246. startOffsetInDestBuffer += num;
  94247. startSampleInFile += num;
  94248. numSamples -= num;
  94249. }
  94250. else
  94251. {
  94252. if (startSampleInFile >= (int) lengthInSamples)
  94253. {
  94254. samplesInReservoir = 0;
  94255. }
  94256. else if (startSampleInFile < reservoirStart
  94257. || startSampleInFile > reservoirStart + jmax (samplesInReservoir, 511))
  94258. {
  94259. // had some problems with flac crashing if the read pos is aligned more
  94260. // accurately than this. Probably fixed in newer versions of the library, though.
  94261. reservoirStart = (int) (startSampleInFile & ~511);
  94262. samplesInReservoir = 0;
  94263. FLAC__stream_decoder_seek_absolute (decoder, (FLAC__uint64) reservoirStart);
  94264. }
  94265. else
  94266. {
  94267. reservoirStart += samplesInReservoir;
  94268. samplesInReservoir = 0;
  94269. FLAC__stream_decoder_process_single (decoder);
  94270. }
  94271. if (samplesInReservoir == 0)
  94272. break;
  94273. }
  94274. }
  94275. if (numSamples > 0)
  94276. {
  94277. for (int i = numDestChannels; --i >= 0;)
  94278. if (destSamples[i] != 0)
  94279. zeromem (destSamples[i] + startOffsetInDestBuffer,
  94280. sizeof (int) * numSamples);
  94281. }
  94282. return true;
  94283. }
  94284. void useSamples (const FLAC__int32* const buffer[], int numSamples)
  94285. {
  94286. if (scanningForLength)
  94287. {
  94288. lengthInSamples += numSamples;
  94289. }
  94290. else
  94291. {
  94292. if (numSamples > reservoir.getNumSamples())
  94293. reservoir.setSize (numChannels, numSamples, false, false, true);
  94294. const int bitsToShift = 32 - bitsPerSample;
  94295. for (int i = 0; i < (int) numChannels; ++i)
  94296. {
  94297. const FLAC__int32* src = buffer[i];
  94298. int n = i;
  94299. while (src == 0 && n > 0)
  94300. src = buffer [--n];
  94301. if (src != 0)
  94302. {
  94303. int* dest = (int*) reservoir.getSampleData(i);
  94304. for (int j = 0; j < numSamples; ++j)
  94305. dest[j] = src[j] << bitsToShift;
  94306. }
  94307. }
  94308. samplesInReservoir = numSamples;
  94309. }
  94310. }
  94311. static FLAC__StreamDecoderReadStatus readCallback_ (const FLAC__StreamDecoder*, FLAC__byte buffer[], size_t* bytes, void* client_data)
  94312. {
  94313. *bytes = (unsigned int) ((const FlacReader*) client_data)->input->read (buffer, (int) *bytes);
  94314. return FLAC__STREAM_DECODER_READ_STATUS_CONTINUE;
  94315. }
  94316. static FLAC__StreamDecoderSeekStatus seekCallback_ (const FLAC__StreamDecoder*, FLAC__uint64 absolute_byte_offset, void* client_data)
  94317. {
  94318. ((const FlacReader*) client_data)->input->setPosition ((int) absolute_byte_offset);
  94319. return FLAC__STREAM_DECODER_SEEK_STATUS_OK;
  94320. }
  94321. static FLAC__StreamDecoderTellStatus tellCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94322. {
  94323. *absolute_byte_offset = ((const FlacReader*) client_data)->input->getPosition();
  94324. return FLAC__STREAM_DECODER_TELL_STATUS_OK;
  94325. }
  94326. static FLAC__StreamDecoderLengthStatus lengthCallback_ (const FLAC__StreamDecoder*, FLAC__uint64* stream_length, void* client_data)
  94327. {
  94328. *stream_length = ((const FlacReader*) client_data)->input->getTotalLength();
  94329. return FLAC__STREAM_DECODER_LENGTH_STATUS_OK;
  94330. }
  94331. static FLAC__bool eofCallback_ (const FLAC__StreamDecoder*, void* client_data)
  94332. {
  94333. return ((const FlacReader*) client_data)->input->isExhausted();
  94334. }
  94335. static FLAC__StreamDecoderWriteStatus writeCallback_ (const FLAC__StreamDecoder*,
  94336. const FLAC__Frame* frame,
  94337. const FLAC__int32* const buffer[],
  94338. void* client_data)
  94339. {
  94340. ((FlacReader*) client_data)->useSamples (buffer, frame->header.blocksize);
  94341. return FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
  94342. }
  94343. static void metadataCallback_ (const FLAC__StreamDecoder*,
  94344. const FLAC__StreamMetadata* metadata,
  94345. void* client_data)
  94346. {
  94347. ((FlacReader*) client_data)->useMetadata (metadata->data.stream_info);
  94348. }
  94349. static void errorCallback_ (const FLAC__StreamDecoder*, FLAC__StreamDecoderErrorStatus, void*)
  94350. {
  94351. }
  94352. juce_UseDebuggingNewOperator
  94353. };
  94354. class FlacWriter : public AudioFormatWriter
  94355. {
  94356. FLAC__StreamEncoder* encoder;
  94357. MemoryBlock temp;
  94358. public:
  94359. bool ok;
  94360. FlacWriter (OutputStream* const out,
  94361. const double sampleRate_,
  94362. const int numChannels_,
  94363. const int bitsPerSample_)
  94364. : AudioFormatWriter (out, TRANS (flacFormatName),
  94365. sampleRate_,
  94366. numChannels_,
  94367. bitsPerSample_)
  94368. {
  94369. using namespace FlacNamespace;
  94370. encoder = FLAC__stream_encoder_new();
  94371. FLAC__stream_encoder_set_do_mid_side_stereo (encoder, numChannels == 2);
  94372. FLAC__stream_encoder_set_loose_mid_side_stereo (encoder, numChannels == 2);
  94373. FLAC__stream_encoder_set_channels (encoder, numChannels);
  94374. FLAC__stream_encoder_set_bits_per_sample (encoder, jmin ((unsigned int) 24, bitsPerSample));
  94375. FLAC__stream_encoder_set_sample_rate (encoder, (unsigned int) sampleRate);
  94376. FLAC__stream_encoder_set_blocksize (encoder, 2048);
  94377. FLAC__stream_encoder_set_do_escape_coding (encoder, true);
  94378. ok = FLAC__stream_encoder_init_stream (encoder,
  94379. encodeWriteCallback, encodeSeekCallback,
  94380. encodeTellCallback, encodeMetadataCallback,
  94381. (void*) this) == FLAC__STREAM_ENCODER_INIT_STATUS_OK;
  94382. }
  94383. ~FlacWriter()
  94384. {
  94385. if (ok)
  94386. {
  94387. FLAC__stream_encoder_finish (encoder);
  94388. output->flush();
  94389. }
  94390. else
  94391. {
  94392. output = 0; // to stop the base class deleting this, as it needs to be returned
  94393. // to the caller of createWriter()
  94394. }
  94395. FLAC__stream_encoder_delete (encoder);
  94396. }
  94397. bool write (const int** samplesToWrite, int numSamples)
  94398. {
  94399. if (! ok)
  94400. return false;
  94401. int* buf[3];
  94402. const int bitsToShift = 32 - bitsPerSample;
  94403. if (bitsToShift > 0)
  94404. {
  94405. const int numChannelsToWrite = (samplesToWrite[1] == 0) ? 1 : 2;
  94406. temp.setSize (sizeof (int) * numSamples * numChannelsToWrite);
  94407. buf[0] = (int*) temp.getData();
  94408. buf[1] = buf[0] + numSamples;
  94409. buf[2] = 0;
  94410. for (int i = numChannelsToWrite; --i >= 0;)
  94411. {
  94412. if (samplesToWrite[i] != 0)
  94413. {
  94414. for (int j = 0; j < numSamples; ++j)
  94415. buf [i][j] = (samplesToWrite [i][j] >> bitsToShift);
  94416. }
  94417. }
  94418. samplesToWrite = (const int**) buf;
  94419. }
  94420. return FLAC__stream_encoder_process (encoder,
  94421. (const FLAC__int32**) samplesToWrite,
  94422. numSamples) != 0;
  94423. }
  94424. bool writeData (const void* const data, const int size) const
  94425. {
  94426. return output->write (data, size);
  94427. }
  94428. static void packUint32 (FLAC__uint32 val, FLAC__byte* b, const int bytes)
  94429. {
  94430. b += bytes;
  94431. for (int i = 0; i < bytes; ++i)
  94432. {
  94433. *(--b) = (FLAC__byte) (val & 0xff);
  94434. val >>= 8;
  94435. }
  94436. }
  94437. void writeMetaData (const FLAC__StreamMetadata* metadata)
  94438. {
  94439. using namespace FlacNamespace;
  94440. const FLAC__StreamMetadata_StreamInfo& info = metadata->data.stream_info;
  94441. unsigned char buffer [FLAC__STREAM_METADATA_STREAMINFO_LENGTH];
  94442. const unsigned int channelsMinus1 = info.channels - 1;
  94443. const unsigned int bitsMinus1 = info.bits_per_sample - 1;
  94444. packUint32 (info.min_blocksize, buffer, 2);
  94445. packUint32 (info.max_blocksize, buffer + 2, 2);
  94446. packUint32 (info.min_framesize, buffer + 4, 3);
  94447. packUint32 (info.max_framesize, buffer + 7, 3);
  94448. buffer[10] = (uint8) ((info.sample_rate >> 12) & 0xff);
  94449. buffer[11] = (uint8) ((info.sample_rate >> 4) & 0xff);
  94450. buffer[12] = (uint8) (((info.sample_rate & 0x0f) << 4) | (channelsMinus1 << 1) | (bitsMinus1 >> 4));
  94451. buffer[13] = (FLAC__byte) (((bitsMinus1 & 0x0f) << 4) | (unsigned int) ((info.total_samples >> 32) & 0x0f));
  94452. packUint32 ((FLAC__uint32) info.total_samples, buffer + 14, 4);
  94453. memcpy (buffer + 18, info.md5sum, 16);
  94454. const bool seekOk = output->setPosition (4);
  94455. (void) seekOk;
  94456. // if this fails, you've given it an output stream that can't seek! It needs
  94457. // to be able to seek back to write the header
  94458. jassert (seekOk);
  94459. output->writeIntBigEndian (FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94460. output->write (buffer, FLAC__STREAM_METADATA_STREAMINFO_LENGTH);
  94461. }
  94462. static FLAC__StreamEncoderWriteStatus encodeWriteCallback (const FLAC__StreamEncoder*,
  94463. const FLAC__byte buffer[],
  94464. size_t bytes,
  94465. unsigned int /*samples*/,
  94466. unsigned int /*current_frame*/,
  94467. void* client_data)
  94468. {
  94469. using namespace FlacNamespace;
  94470. return ((FlacWriter*) client_data)->writeData (buffer, (int) bytes)
  94471. ? FLAC__STREAM_ENCODER_WRITE_STATUS_OK
  94472. : FLAC__STREAM_ENCODER_WRITE_STATUS_FATAL_ERROR;
  94473. }
  94474. static FLAC__StreamEncoderSeekStatus encodeSeekCallback (const FLAC__StreamEncoder*, FLAC__uint64, void*)
  94475. {
  94476. return FLAC__STREAM_ENCODER_SEEK_STATUS_UNSUPPORTED;
  94477. }
  94478. static FLAC__StreamEncoderTellStatus encodeTellCallback (const FLAC__StreamEncoder*, FLAC__uint64* absolute_byte_offset, void* client_data)
  94479. {
  94480. if (client_data == 0)
  94481. return FLAC__STREAM_ENCODER_TELL_STATUS_UNSUPPORTED;
  94482. *absolute_byte_offset = (FLAC__uint64) ((FlacWriter*) client_data)->output->getPosition();
  94483. return FLAC__STREAM_ENCODER_TELL_STATUS_OK;
  94484. }
  94485. static void encodeMetadataCallback (const FLAC__StreamEncoder*,
  94486. const FLAC__StreamMetadata* metadata,
  94487. void* client_data)
  94488. {
  94489. ((FlacWriter*) client_data)->writeMetaData (metadata);
  94490. }
  94491. juce_UseDebuggingNewOperator
  94492. };
  94493. FlacAudioFormat::FlacAudioFormat()
  94494. : AudioFormat (TRANS (flacFormatName), (const tchar**) flacExtensions)
  94495. {
  94496. }
  94497. FlacAudioFormat::~FlacAudioFormat()
  94498. {
  94499. }
  94500. const Array <int> FlacAudioFormat::getPossibleSampleRates()
  94501. {
  94502. const int rates[] = { 22050, 32000, 44100, 48000, 88200, 96000, 0 };
  94503. return Array <int> (rates);
  94504. }
  94505. const Array <int> FlacAudioFormat::getPossibleBitDepths()
  94506. {
  94507. const int depths[] = { 16, 24, 0 };
  94508. return Array <int> (depths);
  94509. }
  94510. bool FlacAudioFormat::canDoStereo()
  94511. {
  94512. return true;
  94513. }
  94514. bool FlacAudioFormat::canDoMono()
  94515. {
  94516. return true;
  94517. }
  94518. bool FlacAudioFormat::isCompressed()
  94519. {
  94520. return true;
  94521. }
  94522. AudioFormatReader* FlacAudioFormat::createReaderFor (InputStream* in,
  94523. const bool deleteStreamIfOpeningFails)
  94524. {
  94525. ScopedPointer <FlacReader> r (new FlacReader (in));
  94526. if (r->sampleRate != 0)
  94527. return r.release();
  94528. if (! deleteStreamIfOpeningFails)
  94529. r->input = 0;
  94530. return 0;
  94531. }
  94532. AudioFormatWriter* FlacAudioFormat::createWriterFor (OutputStream* out,
  94533. double sampleRate,
  94534. unsigned int numberOfChannels,
  94535. int bitsPerSample,
  94536. const StringPairArray& /*metadataValues*/,
  94537. int /*qualityOptionIndex*/)
  94538. {
  94539. if (getPossibleBitDepths().contains (bitsPerSample))
  94540. {
  94541. ScopedPointer <FlacWriter> w (new FlacWriter (out,
  94542. sampleRate,
  94543. numberOfChannels,
  94544. bitsPerSample));
  94545. if (w->ok)
  94546. return w.release();
  94547. }
  94548. return 0;
  94549. }
  94550. END_JUCE_NAMESPACE
  94551. #endif
  94552. /*** End of inlined file: juce_FlacAudioFormat.cpp ***/
  94553. /*** Start of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  94554. #if JUCE_USE_OGGVORBIS
  94555. #if JUCE_MAC
  94556. #define __MACOSX__ 1
  94557. #endif
  94558. namespace OggVorbisNamespace
  94559. {
  94560. #if JUCE_INCLUDE_OGGVORBIS_CODE
  94561. /*** Start of inlined file: vorbisenc.h ***/
  94562. #ifndef _OV_ENC_H_
  94563. #define _OV_ENC_H_
  94564. #ifdef __cplusplus
  94565. extern "C"
  94566. {
  94567. #endif /* __cplusplus */
  94568. /*** Start of inlined file: codec.h ***/
  94569. #ifndef _vorbis_codec_h_
  94570. #define _vorbis_codec_h_
  94571. #ifdef __cplusplus
  94572. extern "C"
  94573. {
  94574. #endif /* __cplusplus */
  94575. /*** Start of inlined file: ogg.h ***/
  94576. #ifndef _OGG_H
  94577. #define _OGG_H
  94578. #ifdef __cplusplus
  94579. extern "C" {
  94580. #endif
  94581. /*** Start of inlined file: os_types.h ***/
  94582. #ifndef _OS_TYPES_H
  94583. #define _OS_TYPES_H
  94584. #define _ogg_malloc malloc
  94585. #define _ogg_calloc calloc
  94586. #define _ogg_realloc realloc
  94587. #define _ogg_free free
  94588. #if defined(_WIN32)
  94589. # if defined(__CYGWIN__)
  94590. # include <_G_config.h>
  94591. typedef _G_int64_t ogg_int64_t;
  94592. typedef _G_int32_t ogg_int32_t;
  94593. typedef _G_uint32_t ogg_uint32_t;
  94594. typedef _G_int16_t ogg_int16_t;
  94595. typedef _G_uint16_t ogg_uint16_t;
  94596. # elif defined(__MINGW32__)
  94597. typedef short ogg_int16_t;
  94598. typedef unsigned short ogg_uint16_t;
  94599. typedef int ogg_int32_t;
  94600. typedef unsigned int ogg_uint32_t;
  94601. typedef long long ogg_int64_t;
  94602. typedef unsigned long long ogg_uint64_t;
  94603. # elif defined(__MWERKS__)
  94604. typedef long long ogg_int64_t;
  94605. typedef int ogg_int32_t;
  94606. typedef unsigned int ogg_uint32_t;
  94607. typedef short ogg_int16_t;
  94608. typedef unsigned short ogg_uint16_t;
  94609. # else
  94610. typedef __int64 ogg_int64_t;
  94611. typedef __int32 ogg_int32_t;
  94612. typedef unsigned __int32 ogg_uint32_t;
  94613. typedef __int16 ogg_int16_t;
  94614. typedef unsigned __int16 ogg_uint16_t;
  94615. # endif
  94616. #elif defined(__MACOS__)
  94617. # include <sys/types.h>
  94618. typedef SInt16 ogg_int16_t;
  94619. typedef UInt16 ogg_uint16_t;
  94620. typedef SInt32 ogg_int32_t;
  94621. typedef UInt32 ogg_uint32_t;
  94622. typedef SInt64 ogg_int64_t;
  94623. #elif defined(__MACOSX__) /* MacOS X Framework build */
  94624. # include <sys/types.h>
  94625. typedef int16_t ogg_int16_t;
  94626. typedef u_int16_t ogg_uint16_t;
  94627. typedef int32_t ogg_int32_t;
  94628. typedef u_int32_t ogg_uint32_t;
  94629. typedef int64_t ogg_int64_t;
  94630. #elif defined(__BEOS__)
  94631. # include <inttypes.h>
  94632. typedef int16_t ogg_int16_t;
  94633. typedef u_int16_t ogg_uint16_t;
  94634. typedef int32_t ogg_int32_t;
  94635. typedef u_int32_t ogg_uint32_t;
  94636. typedef int64_t ogg_int64_t;
  94637. #elif defined (__EMX__)
  94638. typedef short ogg_int16_t;
  94639. typedef unsigned short ogg_uint16_t;
  94640. typedef int ogg_int32_t;
  94641. typedef unsigned int ogg_uint32_t;
  94642. typedef long long ogg_int64_t;
  94643. #elif defined (DJGPP)
  94644. typedef short ogg_int16_t;
  94645. typedef int ogg_int32_t;
  94646. typedef unsigned int ogg_uint32_t;
  94647. typedef long long ogg_int64_t;
  94648. #elif defined(R5900)
  94649. typedef long ogg_int64_t;
  94650. typedef int ogg_int32_t;
  94651. typedef unsigned ogg_uint32_t;
  94652. typedef short ogg_int16_t;
  94653. #elif defined(__SYMBIAN32__)
  94654. typedef signed short ogg_int16_t;
  94655. typedef unsigned short ogg_uint16_t;
  94656. typedef signed int ogg_int32_t;
  94657. typedef unsigned int ogg_uint32_t;
  94658. typedef long long int ogg_int64_t;
  94659. #else
  94660. # include <sys/types.h>
  94661. /*** Start of inlined file: config_types.h ***/
  94662. #ifndef __CONFIG_TYPES_H__
  94663. #define __CONFIG_TYPES_H__
  94664. typedef int16_t ogg_int16_t;
  94665. typedef unsigned short ogg_uint16_t;
  94666. typedef int32_t ogg_int32_t;
  94667. typedef unsigned int ogg_uint32_t;
  94668. typedef int64_t ogg_int64_t;
  94669. #endif
  94670. /*** End of inlined file: config_types.h ***/
  94671. #endif
  94672. #endif /* _OS_TYPES_H */
  94673. /*** End of inlined file: os_types.h ***/
  94674. typedef struct {
  94675. long endbyte;
  94676. int endbit;
  94677. unsigned char *buffer;
  94678. unsigned char *ptr;
  94679. long storage;
  94680. } oggpack_buffer;
  94681. typedef struct {
  94682. unsigned char *header;
  94683. long header_len;
  94684. unsigned char *body;
  94685. long body_len;
  94686. } ogg_page;
  94687. ogg_uint32_t ogg_bitreverse(ogg_uint32_t x){
  94688. x= ((x>>16)&0x0000ffffUL) | ((x<<16)&0xffff0000UL);
  94689. x= ((x>> 8)&0x00ff00ffUL) | ((x<< 8)&0xff00ff00UL);
  94690. x= ((x>> 4)&0x0f0f0f0fUL) | ((x<< 4)&0xf0f0f0f0UL);
  94691. x= ((x>> 2)&0x33333333UL) | ((x<< 2)&0xccccccccUL);
  94692. return((x>> 1)&0x55555555UL) | ((x<< 1)&0xaaaaaaaaUL);
  94693. }
  94694. typedef struct {
  94695. unsigned char *body_data; /* bytes from packet bodies */
  94696. long body_storage; /* storage elements allocated */
  94697. long body_fill; /* elements stored; fill mark */
  94698. long body_returned; /* elements of fill returned */
  94699. int *lacing_vals; /* The values that will go to the segment table */
  94700. ogg_int64_t *granule_vals; /* granulepos values for headers. Not compact
  94701. this way, but it is simple coupled to the
  94702. lacing fifo */
  94703. long lacing_storage;
  94704. long lacing_fill;
  94705. long lacing_packet;
  94706. long lacing_returned;
  94707. unsigned char header[282]; /* working space for header encode */
  94708. int header_fill;
  94709. int e_o_s; /* set when we have buffered the last packet in the
  94710. logical bitstream */
  94711. int b_o_s; /* set after we've written the initial page
  94712. of a logical bitstream */
  94713. long serialno;
  94714. long pageno;
  94715. ogg_int64_t packetno; /* sequence number for decode; the framing
  94716. knows where there's a hole in the data,
  94717. but we need coupling so that the codec
  94718. (which is in a seperate abstraction
  94719. layer) also knows about the gap */
  94720. ogg_int64_t granulepos;
  94721. } ogg_stream_state;
  94722. typedef struct {
  94723. unsigned char *packet;
  94724. long bytes;
  94725. long b_o_s;
  94726. long e_o_s;
  94727. ogg_int64_t granulepos;
  94728. ogg_int64_t packetno; /* sequence number for decode; the framing
  94729. knows where there's a hole in the data,
  94730. but we need coupling so that the codec
  94731. (which is in a seperate abstraction
  94732. layer) also knows about the gap */
  94733. } ogg_packet;
  94734. typedef struct {
  94735. unsigned char *data;
  94736. int storage;
  94737. int fill;
  94738. int returned;
  94739. int unsynced;
  94740. int headerbytes;
  94741. int bodybytes;
  94742. } ogg_sync_state;
  94743. extern void oggpack_writeinit(oggpack_buffer *b);
  94744. extern void oggpack_writetrunc(oggpack_buffer *b,long bits);
  94745. extern void oggpack_writealign(oggpack_buffer *b);
  94746. extern void oggpack_writecopy(oggpack_buffer *b,void *source,long bits);
  94747. extern void oggpack_reset(oggpack_buffer *b);
  94748. extern void oggpack_writeclear(oggpack_buffer *b);
  94749. extern void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94750. extern void oggpack_write(oggpack_buffer *b,unsigned long value,int bits);
  94751. extern long oggpack_look(oggpack_buffer *b,int bits);
  94752. extern long oggpack_look1(oggpack_buffer *b);
  94753. extern void oggpack_adv(oggpack_buffer *b,int bits);
  94754. extern void oggpack_adv1(oggpack_buffer *b);
  94755. extern long oggpack_read(oggpack_buffer *b,int bits);
  94756. extern long oggpack_read1(oggpack_buffer *b);
  94757. extern long oggpack_bytes(oggpack_buffer *b);
  94758. extern long oggpack_bits(oggpack_buffer *b);
  94759. extern unsigned char *oggpack_get_buffer(oggpack_buffer *b);
  94760. extern void oggpackB_writeinit(oggpack_buffer *b);
  94761. extern void oggpackB_writetrunc(oggpack_buffer *b,long bits);
  94762. extern void oggpackB_writealign(oggpack_buffer *b);
  94763. extern void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits);
  94764. extern void oggpackB_reset(oggpack_buffer *b);
  94765. extern void oggpackB_writeclear(oggpack_buffer *b);
  94766. extern void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes);
  94767. extern void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits);
  94768. extern long oggpackB_look(oggpack_buffer *b,int bits);
  94769. extern long oggpackB_look1(oggpack_buffer *b);
  94770. extern void oggpackB_adv(oggpack_buffer *b,int bits);
  94771. extern void oggpackB_adv1(oggpack_buffer *b);
  94772. extern long oggpackB_read(oggpack_buffer *b,int bits);
  94773. extern long oggpackB_read1(oggpack_buffer *b);
  94774. extern long oggpackB_bytes(oggpack_buffer *b);
  94775. extern long oggpackB_bits(oggpack_buffer *b);
  94776. extern unsigned char *oggpackB_get_buffer(oggpack_buffer *b);
  94777. extern int ogg_stream_packetin(ogg_stream_state *os, ogg_packet *op);
  94778. extern int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og);
  94779. extern int ogg_stream_flush(ogg_stream_state *os, ogg_page *og);
  94780. extern int ogg_sync_init(ogg_sync_state *oy);
  94781. extern int ogg_sync_clear(ogg_sync_state *oy);
  94782. extern int ogg_sync_reset(ogg_sync_state *oy);
  94783. extern int ogg_sync_destroy(ogg_sync_state *oy);
  94784. extern char *ogg_sync_buffer(ogg_sync_state *oy, long size);
  94785. extern int ogg_sync_wrote(ogg_sync_state *oy, long bytes);
  94786. extern long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og);
  94787. extern int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og);
  94788. extern int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og);
  94789. extern int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op);
  94790. extern int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op);
  94791. extern int ogg_stream_init(ogg_stream_state *os,int serialno);
  94792. extern int ogg_stream_clear(ogg_stream_state *os);
  94793. extern int ogg_stream_reset(ogg_stream_state *os);
  94794. extern int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno);
  94795. extern int ogg_stream_destroy(ogg_stream_state *os);
  94796. extern int ogg_stream_eos(ogg_stream_state *os);
  94797. extern void ogg_page_checksum_set(ogg_page *og);
  94798. extern int ogg_page_version(ogg_page *og);
  94799. extern int ogg_page_continued(ogg_page *og);
  94800. extern int ogg_page_bos(ogg_page *og);
  94801. extern int ogg_page_eos(ogg_page *og);
  94802. extern ogg_int64_t ogg_page_granulepos(ogg_page *og);
  94803. extern int ogg_page_serialno(ogg_page *og);
  94804. extern long ogg_page_pageno(ogg_page *og);
  94805. extern int ogg_page_packets(ogg_page *og);
  94806. extern void ogg_packet_clear(ogg_packet *op);
  94807. #ifdef __cplusplus
  94808. }
  94809. #endif
  94810. #endif /* _OGG_H */
  94811. /*** End of inlined file: ogg.h ***/
  94812. typedef struct vorbis_info{
  94813. int version;
  94814. int channels;
  94815. long rate;
  94816. long bitrate_upper;
  94817. long bitrate_nominal;
  94818. long bitrate_lower;
  94819. long bitrate_window;
  94820. void *codec_setup;
  94821. } vorbis_info;
  94822. typedef struct vorbis_dsp_state{
  94823. int analysisp;
  94824. vorbis_info *vi;
  94825. float **pcm;
  94826. float **pcmret;
  94827. int pcm_storage;
  94828. int pcm_current;
  94829. int pcm_returned;
  94830. int preextrapolate;
  94831. int eofflag;
  94832. long lW;
  94833. long W;
  94834. long nW;
  94835. long centerW;
  94836. ogg_int64_t granulepos;
  94837. ogg_int64_t sequence;
  94838. ogg_int64_t glue_bits;
  94839. ogg_int64_t time_bits;
  94840. ogg_int64_t floor_bits;
  94841. ogg_int64_t res_bits;
  94842. void *backend_state;
  94843. } vorbis_dsp_state;
  94844. typedef struct vorbis_block{
  94845. float **pcm; /* this is a pointer into local storage */
  94846. oggpack_buffer opb;
  94847. long lW;
  94848. long W;
  94849. long nW;
  94850. int pcmend;
  94851. int mode;
  94852. int eofflag;
  94853. ogg_int64_t granulepos;
  94854. ogg_int64_t sequence;
  94855. vorbis_dsp_state *vd; /* For read-only access of configuration */
  94856. void *localstore;
  94857. long localtop;
  94858. long localalloc;
  94859. long totaluse;
  94860. struct alloc_chain *reap;
  94861. long glue_bits;
  94862. long time_bits;
  94863. long floor_bits;
  94864. long res_bits;
  94865. void *internal;
  94866. } vorbis_block;
  94867. struct alloc_chain{
  94868. void *ptr;
  94869. struct alloc_chain *next;
  94870. };
  94871. typedef struct vorbis_comment{
  94872. char **user_comments;
  94873. int *comment_lengths;
  94874. int comments;
  94875. char *vendor;
  94876. } vorbis_comment;
  94877. extern void vorbis_info_init(vorbis_info *vi);
  94878. extern void vorbis_info_clear(vorbis_info *vi);
  94879. extern int vorbis_info_blocksize(vorbis_info *vi,int zo);
  94880. extern void vorbis_comment_init(vorbis_comment *vc);
  94881. extern void vorbis_comment_add(vorbis_comment *vc, char *comment);
  94882. extern void vorbis_comment_add_tag(vorbis_comment *vc,
  94883. const char *tag, char *contents);
  94884. extern char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count);
  94885. extern int vorbis_comment_query_count(vorbis_comment *vc, char *tag);
  94886. extern void vorbis_comment_clear(vorbis_comment *vc);
  94887. extern int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb);
  94888. extern int vorbis_block_clear(vorbis_block *vb);
  94889. extern void vorbis_dsp_clear(vorbis_dsp_state *v);
  94890. extern double vorbis_granule_time(vorbis_dsp_state *v,
  94891. ogg_int64_t granulepos);
  94892. extern int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94893. extern int vorbis_commentheader_out(vorbis_comment *vc, ogg_packet *op);
  94894. extern int vorbis_analysis_headerout(vorbis_dsp_state *v,
  94895. vorbis_comment *vc,
  94896. ogg_packet *op,
  94897. ogg_packet *op_comm,
  94898. ogg_packet *op_code);
  94899. extern float **vorbis_analysis_buffer(vorbis_dsp_state *v,int vals);
  94900. extern int vorbis_analysis_wrote(vorbis_dsp_state *v,int vals);
  94901. extern int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb);
  94902. extern int vorbis_analysis(vorbis_block *vb,ogg_packet *op);
  94903. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  94904. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,
  94905. ogg_packet *op);
  94906. extern int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,
  94907. ogg_packet *op);
  94908. extern int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi);
  94909. extern int vorbis_synthesis_restart(vorbis_dsp_state *v);
  94910. extern int vorbis_synthesis(vorbis_block *vb,ogg_packet *op);
  94911. extern int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op);
  94912. extern int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb);
  94913. extern int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm);
  94914. extern int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm);
  94915. extern int vorbis_synthesis_read(vorbis_dsp_state *v,int samples);
  94916. extern long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op);
  94917. extern int vorbis_synthesis_halfrate(vorbis_info *v,int flag);
  94918. extern int vorbis_synthesis_halfrate_p(vorbis_info *v);
  94919. #define OV_FALSE -1
  94920. #define OV_EOF -2
  94921. #define OV_HOLE -3
  94922. #define OV_EREAD -128
  94923. #define OV_EFAULT -129
  94924. #define OV_EIMPL -130
  94925. #define OV_EINVAL -131
  94926. #define OV_ENOTVORBIS -132
  94927. #define OV_EBADHEADER -133
  94928. #define OV_EVERSION -134
  94929. #define OV_ENOTAUDIO -135
  94930. #define OV_EBADPACKET -136
  94931. #define OV_EBADLINK -137
  94932. #define OV_ENOSEEK -138
  94933. #ifdef __cplusplus
  94934. }
  94935. #endif /* __cplusplus */
  94936. #endif
  94937. /*** End of inlined file: codec.h ***/
  94938. extern int vorbis_encode_init(vorbis_info *vi,
  94939. long channels,
  94940. long rate,
  94941. long max_bitrate,
  94942. long nominal_bitrate,
  94943. long min_bitrate);
  94944. extern int vorbis_encode_setup_managed(vorbis_info *vi,
  94945. long channels,
  94946. long rate,
  94947. long max_bitrate,
  94948. long nominal_bitrate,
  94949. long min_bitrate);
  94950. extern int vorbis_encode_setup_vbr(vorbis_info *vi,
  94951. long channels,
  94952. long rate,
  94953. float quality /* quality level from 0. (lo) to 1. (hi) */
  94954. );
  94955. extern int vorbis_encode_init_vbr(vorbis_info *vi,
  94956. long channels,
  94957. long rate,
  94958. float base_quality /* quality level from 0. (lo) to 1. (hi) */
  94959. );
  94960. extern int vorbis_encode_setup_init(vorbis_info *vi);
  94961. extern int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg);
  94962. #define OV_ECTL_RATEMANAGE_GET 0x10
  94963. #define OV_ECTL_RATEMANAGE_SET 0x11
  94964. #define OV_ECTL_RATEMANAGE_AVG 0x12
  94965. #define OV_ECTL_RATEMANAGE_HARD 0x13
  94966. struct ovectl_ratemanage_arg {
  94967. int management_active;
  94968. long bitrate_hard_min;
  94969. long bitrate_hard_max;
  94970. double bitrate_hard_window;
  94971. long bitrate_av_lo;
  94972. long bitrate_av_hi;
  94973. double bitrate_av_window;
  94974. double bitrate_av_window_center;
  94975. };
  94976. #define OV_ECTL_RATEMANAGE2_GET 0x14
  94977. #define OV_ECTL_RATEMANAGE2_SET 0x15
  94978. struct ovectl_ratemanage2_arg {
  94979. int management_active;
  94980. long bitrate_limit_min_kbps;
  94981. long bitrate_limit_max_kbps;
  94982. long bitrate_limit_reservoir_bits;
  94983. double bitrate_limit_reservoir_bias;
  94984. long bitrate_average_kbps;
  94985. double bitrate_average_damping;
  94986. };
  94987. #define OV_ECTL_LOWPASS_GET 0x20
  94988. #define OV_ECTL_LOWPASS_SET 0x21
  94989. #define OV_ECTL_IBLOCK_GET 0x30
  94990. #define OV_ECTL_IBLOCK_SET 0x31
  94991. #ifdef __cplusplus
  94992. }
  94993. #endif /* __cplusplus */
  94994. #endif
  94995. /*** End of inlined file: vorbisenc.h ***/
  94996. /*** Start of inlined file: vorbisfile.h ***/
  94997. #ifndef _OV_FILE_H_
  94998. #define _OV_FILE_H_
  94999. #ifdef __cplusplus
  95000. extern "C"
  95001. {
  95002. #endif /* __cplusplus */
  95003. #include <stdio.h>
  95004. typedef struct {
  95005. size_t (*read_func) (void *ptr, size_t size, size_t nmemb, void *datasource);
  95006. int (*seek_func) (void *datasource, ogg_int64_t offset, int whence);
  95007. int (*close_func) (void *datasource);
  95008. long (*tell_func) (void *datasource);
  95009. } ov_callbacks;
  95010. #define NOTOPEN 0
  95011. #define PARTOPEN 1
  95012. #define OPENED 2
  95013. #define STREAMSET 3
  95014. #define INITSET 4
  95015. typedef struct OggVorbis_File {
  95016. void *datasource; /* Pointer to a FILE *, etc. */
  95017. int seekable;
  95018. ogg_int64_t offset;
  95019. ogg_int64_t end;
  95020. ogg_sync_state oy;
  95021. int links;
  95022. ogg_int64_t *offsets;
  95023. ogg_int64_t *dataoffsets;
  95024. long *serialnos;
  95025. ogg_int64_t *pcmlengths; /* overloaded to maintain binary
  95026. compatability; x2 size, stores both
  95027. beginning and end values */
  95028. vorbis_info *vi;
  95029. vorbis_comment *vc;
  95030. ogg_int64_t pcm_offset;
  95031. int ready_state;
  95032. long current_serialno;
  95033. int current_link;
  95034. double bittrack;
  95035. double samptrack;
  95036. ogg_stream_state os; /* take physical pages, weld into a logical
  95037. stream of packets */
  95038. vorbis_dsp_state vd; /* central working state for the packet->PCM decoder */
  95039. vorbis_block vb; /* local working space for packet->PCM decode */
  95040. ov_callbacks callbacks;
  95041. } OggVorbis_File;
  95042. extern int ov_clear(OggVorbis_File *vf);
  95043. extern int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  95044. extern int ov_open_callbacks(void *datasource, OggVorbis_File *vf,
  95045. char *initial, long ibytes, ov_callbacks callbacks);
  95046. extern int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes);
  95047. extern int ov_test_callbacks(void *datasource, OggVorbis_File *vf,
  95048. char *initial, long ibytes, ov_callbacks callbacks);
  95049. extern int ov_test_open(OggVorbis_File *vf);
  95050. extern long ov_bitrate(OggVorbis_File *vf,int i);
  95051. extern long ov_bitrate_instant(OggVorbis_File *vf);
  95052. extern long ov_streams(OggVorbis_File *vf);
  95053. extern long ov_seekable(OggVorbis_File *vf);
  95054. extern long ov_serialnumber(OggVorbis_File *vf,int i);
  95055. extern ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i);
  95056. extern ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i);
  95057. extern double ov_time_total(OggVorbis_File *vf,int i);
  95058. extern int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos);
  95059. extern int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos);
  95060. extern int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos);
  95061. extern int ov_time_seek(OggVorbis_File *vf,double pos);
  95062. extern int ov_time_seek_page(OggVorbis_File *vf,double pos);
  95063. extern int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95064. extern int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95065. extern int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos);
  95066. extern int ov_time_seek_lap(OggVorbis_File *vf,double pos);
  95067. extern int ov_time_seek_page_lap(OggVorbis_File *vf,double pos);
  95068. extern ogg_int64_t ov_raw_tell(OggVorbis_File *vf);
  95069. extern ogg_int64_t ov_pcm_tell(OggVorbis_File *vf);
  95070. extern double ov_time_tell(OggVorbis_File *vf);
  95071. extern vorbis_info *ov_info(OggVorbis_File *vf,int link);
  95072. extern vorbis_comment *ov_comment(OggVorbis_File *vf,int link);
  95073. extern long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int samples,
  95074. int *bitstream);
  95075. extern long ov_read(OggVorbis_File *vf,char *buffer,int length,
  95076. int bigendianp,int word,int sgned,int *bitstream);
  95077. extern int ov_crosslap(OggVorbis_File *vf1,OggVorbis_File *vf2);
  95078. extern int ov_halfrate(OggVorbis_File *vf,int flag);
  95079. extern int ov_halfrate_p(OggVorbis_File *vf);
  95080. #ifdef __cplusplus
  95081. }
  95082. #endif /* __cplusplus */
  95083. #endif
  95084. /*** End of inlined file: vorbisfile.h ***/
  95085. /*** Start of inlined file: bitwise.c ***/
  95086. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95087. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95088. // tasks..
  95089. #if JUCE_MSVC
  95090. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95091. #endif
  95092. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95093. #if JUCE_USE_OGGVORBIS
  95094. #include <string.h>
  95095. #include <stdlib.h>
  95096. #define BUFFER_INCREMENT 256
  95097. static const unsigned long mask[]=
  95098. {0x00000000,0x00000001,0x00000003,0x00000007,0x0000000f,
  95099. 0x0000001f,0x0000003f,0x0000007f,0x000000ff,0x000001ff,
  95100. 0x000003ff,0x000007ff,0x00000fff,0x00001fff,0x00003fff,
  95101. 0x00007fff,0x0000ffff,0x0001ffff,0x0003ffff,0x0007ffff,
  95102. 0x000fffff,0x001fffff,0x003fffff,0x007fffff,0x00ffffff,
  95103. 0x01ffffff,0x03ffffff,0x07ffffff,0x0fffffff,0x1fffffff,
  95104. 0x3fffffff,0x7fffffff,0xffffffff };
  95105. static const unsigned int mask8B[]=
  95106. {0x00,0x80,0xc0,0xe0,0xf0,0xf8,0xfc,0xfe,0xff};
  95107. void oggpack_writeinit(oggpack_buffer *b){
  95108. memset(b,0,sizeof(*b));
  95109. b->ptr=b->buffer=(unsigned char*) _ogg_malloc(BUFFER_INCREMENT);
  95110. b->buffer[0]='\0';
  95111. b->storage=BUFFER_INCREMENT;
  95112. }
  95113. void oggpackB_writeinit(oggpack_buffer *b){
  95114. oggpack_writeinit(b);
  95115. }
  95116. void oggpack_writetrunc(oggpack_buffer *b,long bits){
  95117. long bytes=bits>>3;
  95118. bits-=bytes*8;
  95119. b->ptr=b->buffer+bytes;
  95120. b->endbit=bits;
  95121. b->endbyte=bytes;
  95122. *b->ptr&=mask[bits];
  95123. }
  95124. void oggpackB_writetrunc(oggpack_buffer *b,long bits){
  95125. long bytes=bits>>3;
  95126. bits-=bytes*8;
  95127. b->ptr=b->buffer+bytes;
  95128. b->endbit=bits;
  95129. b->endbyte=bytes;
  95130. *b->ptr&=mask8B[bits];
  95131. }
  95132. void oggpack_write(oggpack_buffer *b,unsigned long value,int bits){
  95133. if(b->endbyte+4>=b->storage){
  95134. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  95135. b->storage+=BUFFER_INCREMENT;
  95136. b->ptr=b->buffer+b->endbyte;
  95137. }
  95138. value&=mask[bits];
  95139. bits+=b->endbit;
  95140. b->ptr[0]|=value<<b->endbit;
  95141. if(bits>=8){
  95142. b->ptr[1]=(unsigned char)(value>>(8-b->endbit));
  95143. if(bits>=16){
  95144. b->ptr[2]=(unsigned char)(value>>(16-b->endbit));
  95145. if(bits>=24){
  95146. b->ptr[3]=(unsigned char)(value>>(24-b->endbit));
  95147. if(bits>=32){
  95148. if(b->endbit)
  95149. b->ptr[4]=(unsigned char)(value>>(32-b->endbit));
  95150. else
  95151. b->ptr[4]=0;
  95152. }
  95153. }
  95154. }
  95155. }
  95156. b->endbyte+=bits/8;
  95157. b->ptr+=bits/8;
  95158. b->endbit=bits&7;
  95159. }
  95160. void oggpackB_write(oggpack_buffer *b,unsigned long value,int bits){
  95161. if(b->endbyte+4>=b->storage){
  95162. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage+BUFFER_INCREMENT);
  95163. b->storage+=BUFFER_INCREMENT;
  95164. b->ptr=b->buffer+b->endbyte;
  95165. }
  95166. value=(value&mask[bits])<<(32-bits);
  95167. bits+=b->endbit;
  95168. b->ptr[0]|=value>>(24+b->endbit);
  95169. if(bits>=8){
  95170. b->ptr[1]=(unsigned char)(value>>(16+b->endbit));
  95171. if(bits>=16){
  95172. b->ptr[2]=(unsigned char)(value>>(8+b->endbit));
  95173. if(bits>=24){
  95174. b->ptr[3]=(unsigned char)(value>>(b->endbit));
  95175. if(bits>=32){
  95176. if(b->endbit)
  95177. b->ptr[4]=(unsigned char)(value<<(8-b->endbit));
  95178. else
  95179. b->ptr[4]=0;
  95180. }
  95181. }
  95182. }
  95183. }
  95184. b->endbyte+=bits/8;
  95185. b->ptr+=bits/8;
  95186. b->endbit=bits&7;
  95187. }
  95188. void oggpack_writealign(oggpack_buffer *b){
  95189. int bits=8-b->endbit;
  95190. if(bits<8)
  95191. oggpack_write(b,0,bits);
  95192. }
  95193. void oggpackB_writealign(oggpack_buffer *b){
  95194. int bits=8-b->endbit;
  95195. if(bits<8)
  95196. oggpackB_write(b,0,bits);
  95197. }
  95198. static void oggpack_writecopy_helper(oggpack_buffer *b,
  95199. void *source,
  95200. long bits,
  95201. void (*w)(oggpack_buffer *,
  95202. unsigned long,
  95203. int),
  95204. int msb){
  95205. unsigned char *ptr=(unsigned char *)source;
  95206. long bytes=bits/8;
  95207. bits-=bytes*8;
  95208. if(b->endbit){
  95209. int i;
  95210. for(i=0;i<bytes;i++)
  95211. w(b,(unsigned long)(ptr[i]),8);
  95212. }else{
  95213. if(b->endbyte+bytes+1>=b->storage){
  95214. b->storage=b->endbyte+bytes+BUFFER_INCREMENT;
  95215. b->buffer=(unsigned char*) _ogg_realloc(b->buffer,b->storage);
  95216. b->ptr=b->buffer+b->endbyte;
  95217. }
  95218. memmove(b->ptr,source,bytes);
  95219. b->ptr+=bytes;
  95220. b->endbyte+=bytes;
  95221. *b->ptr=0;
  95222. }
  95223. if(bits){
  95224. if(msb)
  95225. w(b,(unsigned long)(ptr[bytes]>>(8-bits)),bits);
  95226. else
  95227. w(b,(unsigned long)(ptr[bytes]),bits);
  95228. }
  95229. }
  95230. void oggpack_writecopy(oggpack_buffer *b,void *source,long bits){
  95231. oggpack_writecopy_helper(b,source,bits,oggpack_write,0);
  95232. }
  95233. void oggpackB_writecopy(oggpack_buffer *b,void *source,long bits){
  95234. oggpack_writecopy_helper(b,source,bits,oggpackB_write,1);
  95235. }
  95236. void oggpack_reset(oggpack_buffer *b){
  95237. b->ptr=b->buffer;
  95238. b->buffer[0]=0;
  95239. b->endbit=b->endbyte=0;
  95240. }
  95241. void oggpackB_reset(oggpack_buffer *b){
  95242. oggpack_reset(b);
  95243. }
  95244. void oggpack_writeclear(oggpack_buffer *b){
  95245. _ogg_free(b->buffer);
  95246. memset(b,0,sizeof(*b));
  95247. }
  95248. void oggpackB_writeclear(oggpack_buffer *b){
  95249. oggpack_writeclear(b);
  95250. }
  95251. void oggpack_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  95252. memset(b,0,sizeof(*b));
  95253. b->buffer=b->ptr=buf;
  95254. b->storage=bytes;
  95255. }
  95256. void oggpackB_readinit(oggpack_buffer *b,unsigned char *buf,int bytes){
  95257. oggpack_readinit(b,buf,bytes);
  95258. }
  95259. long oggpack_look(oggpack_buffer *b,int bits){
  95260. unsigned long ret;
  95261. unsigned long m=mask[bits];
  95262. bits+=b->endbit;
  95263. if(b->endbyte+4>=b->storage){
  95264. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95265. }
  95266. ret=b->ptr[0]>>b->endbit;
  95267. if(bits>8){
  95268. ret|=b->ptr[1]<<(8-b->endbit);
  95269. if(bits>16){
  95270. ret|=b->ptr[2]<<(16-b->endbit);
  95271. if(bits>24){
  95272. ret|=b->ptr[3]<<(24-b->endbit);
  95273. if(bits>32 && b->endbit)
  95274. ret|=b->ptr[4]<<(32-b->endbit);
  95275. }
  95276. }
  95277. }
  95278. return(m&ret);
  95279. }
  95280. long oggpackB_look(oggpack_buffer *b,int bits){
  95281. unsigned long ret;
  95282. int m=32-bits;
  95283. bits+=b->endbit;
  95284. if(b->endbyte+4>=b->storage){
  95285. if(b->endbyte*8+bits>b->storage*8)return(-1);
  95286. }
  95287. ret=b->ptr[0]<<(24+b->endbit);
  95288. if(bits>8){
  95289. ret|=b->ptr[1]<<(16+b->endbit);
  95290. if(bits>16){
  95291. ret|=b->ptr[2]<<(8+b->endbit);
  95292. if(bits>24){
  95293. ret|=b->ptr[3]<<(b->endbit);
  95294. if(bits>32 && b->endbit)
  95295. ret|=b->ptr[4]>>(8-b->endbit);
  95296. }
  95297. }
  95298. }
  95299. return ((ret&0xffffffff)>>(m>>1))>>((m+1)>>1);
  95300. }
  95301. long oggpack_look1(oggpack_buffer *b){
  95302. if(b->endbyte>=b->storage)return(-1);
  95303. return((b->ptr[0]>>b->endbit)&1);
  95304. }
  95305. long oggpackB_look1(oggpack_buffer *b){
  95306. if(b->endbyte>=b->storage)return(-1);
  95307. return((b->ptr[0]>>(7-b->endbit))&1);
  95308. }
  95309. void oggpack_adv(oggpack_buffer *b,int bits){
  95310. bits+=b->endbit;
  95311. b->ptr+=bits/8;
  95312. b->endbyte+=bits/8;
  95313. b->endbit=bits&7;
  95314. }
  95315. void oggpackB_adv(oggpack_buffer *b,int bits){
  95316. oggpack_adv(b,bits);
  95317. }
  95318. void oggpack_adv1(oggpack_buffer *b){
  95319. if(++(b->endbit)>7){
  95320. b->endbit=0;
  95321. b->ptr++;
  95322. b->endbyte++;
  95323. }
  95324. }
  95325. void oggpackB_adv1(oggpack_buffer *b){
  95326. oggpack_adv1(b);
  95327. }
  95328. long oggpack_read(oggpack_buffer *b,int bits){
  95329. long ret;
  95330. unsigned long m=mask[bits];
  95331. bits+=b->endbit;
  95332. if(b->endbyte+4>=b->storage){
  95333. ret=-1L;
  95334. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95335. }
  95336. ret=b->ptr[0]>>b->endbit;
  95337. if(bits>8){
  95338. ret|=b->ptr[1]<<(8-b->endbit);
  95339. if(bits>16){
  95340. ret|=b->ptr[2]<<(16-b->endbit);
  95341. if(bits>24){
  95342. ret|=b->ptr[3]<<(24-b->endbit);
  95343. if(bits>32 && b->endbit){
  95344. ret|=b->ptr[4]<<(32-b->endbit);
  95345. }
  95346. }
  95347. }
  95348. }
  95349. ret&=m;
  95350. overflow:
  95351. b->ptr+=bits/8;
  95352. b->endbyte+=bits/8;
  95353. b->endbit=bits&7;
  95354. return(ret);
  95355. }
  95356. long oggpackB_read(oggpack_buffer *b,int bits){
  95357. long ret;
  95358. long m=32-bits;
  95359. bits+=b->endbit;
  95360. if(b->endbyte+4>=b->storage){
  95361. ret=-1L;
  95362. if(b->endbyte*8+bits>b->storage*8)goto overflow;
  95363. }
  95364. ret=b->ptr[0]<<(24+b->endbit);
  95365. if(bits>8){
  95366. ret|=b->ptr[1]<<(16+b->endbit);
  95367. if(bits>16){
  95368. ret|=b->ptr[2]<<(8+b->endbit);
  95369. if(bits>24){
  95370. ret|=b->ptr[3]<<(b->endbit);
  95371. if(bits>32 && b->endbit)
  95372. ret|=b->ptr[4]>>(8-b->endbit);
  95373. }
  95374. }
  95375. }
  95376. ret=((ret&0xffffffffUL)>>(m>>1))>>((m+1)>>1);
  95377. overflow:
  95378. b->ptr+=bits/8;
  95379. b->endbyte+=bits/8;
  95380. b->endbit=bits&7;
  95381. return(ret);
  95382. }
  95383. long oggpack_read1(oggpack_buffer *b){
  95384. long ret;
  95385. if(b->endbyte>=b->storage){
  95386. ret=-1L;
  95387. goto overflow;
  95388. }
  95389. ret=(b->ptr[0]>>b->endbit)&1;
  95390. overflow:
  95391. b->endbit++;
  95392. if(b->endbit>7){
  95393. b->endbit=0;
  95394. b->ptr++;
  95395. b->endbyte++;
  95396. }
  95397. return(ret);
  95398. }
  95399. long oggpackB_read1(oggpack_buffer *b){
  95400. long ret;
  95401. if(b->endbyte>=b->storage){
  95402. ret=-1L;
  95403. goto overflow;
  95404. }
  95405. ret=(b->ptr[0]>>(7-b->endbit))&1;
  95406. overflow:
  95407. b->endbit++;
  95408. if(b->endbit>7){
  95409. b->endbit=0;
  95410. b->ptr++;
  95411. b->endbyte++;
  95412. }
  95413. return(ret);
  95414. }
  95415. long oggpack_bytes(oggpack_buffer *b){
  95416. return(b->endbyte+(b->endbit+7)/8);
  95417. }
  95418. long oggpack_bits(oggpack_buffer *b){
  95419. return(b->endbyte*8+b->endbit);
  95420. }
  95421. long oggpackB_bytes(oggpack_buffer *b){
  95422. return oggpack_bytes(b);
  95423. }
  95424. long oggpackB_bits(oggpack_buffer *b){
  95425. return oggpack_bits(b);
  95426. }
  95427. unsigned char *oggpack_get_buffer(oggpack_buffer *b){
  95428. return(b->buffer);
  95429. }
  95430. unsigned char *oggpackB_get_buffer(oggpack_buffer *b){
  95431. return oggpack_get_buffer(b);
  95432. }
  95433. #ifdef _V_SELFTEST
  95434. #include <stdio.h>
  95435. static int ilog(unsigned int v){
  95436. int ret=0;
  95437. while(v){
  95438. ret++;
  95439. v>>=1;
  95440. }
  95441. return(ret);
  95442. }
  95443. oggpack_buffer o;
  95444. oggpack_buffer r;
  95445. void report(char *in){
  95446. fprintf(stderr,"%s",in);
  95447. exit(1);
  95448. }
  95449. void cliptest(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95450. long bytes,i;
  95451. unsigned char *buffer;
  95452. oggpack_reset(&o);
  95453. for(i=0;i<vals;i++)
  95454. oggpack_write(&o,b[i],bits?bits:ilog(b[i]));
  95455. buffer=oggpack_get_buffer(&o);
  95456. bytes=oggpack_bytes(&o);
  95457. if(bytes!=compsize)report("wrong number of bytes!\n");
  95458. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95459. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95460. report("wrote incorrect value!\n");
  95461. }
  95462. oggpack_readinit(&r,buffer,bytes);
  95463. for(i=0;i<vals;i++){
  95464. int tbit=bits?bits:ilog(b[i]);
  95465. if(oggpack_look(&r,tbit)==-1)
  95466. report("out of data!\n");
  95467. if(oggpack_look(&r,tbit)!=(b[i]&mask[tbit]))
  95468. report("looked at incorrect value!\n");
  95469. if(tbit==1)
  95470. if(oggpack_look1(&r)!=(b[i]&mask[tbit]))
  95471. report("looked at single bit incorrect value!\n");
  95472. if(tbit==1){
  95473. if(oggpack_read1(&r)!=(b[i]&mask[tbit]))
  95474. report("read incorrect single bit value!\n");
  95475. }else{
  95476. if(oggpack_read(&r,tbit)!=(b[i]&mask[tbit]))
  95477. report("read incorrect value!\n");
  95478. }
  95479. }
  95480. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95481. }
  95482. void cliptestB(unsigned long *b,int vals,int bits,int *comp,int compsize){
  95483. long bytes,i;
  95484. unsigned char *buffer;
  95485. oggpackB_reset(&o);
  95486. for(i=0;i<vals;i++)
  95487. oggpackB_write(&o,b[i],bits?bits:ilog(b[i]));
  95488. buffer=oggpackB_get_buffer(&o);
  95489. bytes=oggpackB_bytes(&o);
  95490. if(bytes!=compsize)report("wrong number of bytes!\n");
  95491. for(i=0;i<bytes;i++)if(buffer[i]!=comp[i]){
  95492. for(i=0;i<bytes;i++)fprintf(stderr,"%x %x\n",(int)buffer[i],(int)comp[i]);
  95493. report("wrote incorrect value!\n");
  95494. }
  95495. oggpackB_readinit(&r,buffer,bytes);
  95496. for(i=0;i<vals;i++){
  95497. int tbit=bits?bits:ilog(b[i]);
  95498. if(oggpackB_look(&r,tbit)==-1)
  95499. report("out of data!\n");
  95500. if(oggpackB_look(&r,tbit)!=(b[i]&mask[tbit]))
  95501. report("looked at incorrect value!\n");
  95502. if(tbit==1)
  95503. if(oggpackB_look1(&r)!=(b[i]&mask[tbit]))
  95504. report("looked at single bit incorrect value!\n");
  95505. if(tbit==1){
  95506. if(oggpackB_read1(&r)!=(b[i]&mask[tbit]))
  95507. report("read incorrect single bit value!\n");
  95508. }else{
  95509. if(oggpackB_read(&r,tbit)!=(b[i]&mask[tbit]))
  95510. report("read incorrect value!\n");
  95511. }
  95512. }
  95513. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95514. }
  95515. int main(void){
  95516. unsigned char *buffer;
  95517. long bytes,i;
  95518. static unsigned long testbuffer1[]=
  95519. {18,12,103948,4325,543,76,432,52,3,65,4,56,32,42,34,21,1,23,32,546,456,7,
  95520. 567,56,8,8,55,3,52,342,341,4,265,7,67,86,2199,21,7,1,5,1,4};
  95521. int test1size=43;
  95522. static unsigned long testbuffer2[]=
  95523. {216531625L,1237861823,56732452,131,3212421,12325343,34547562,12313212,
  95524. 1233432,534,5,346435231,14436467,7869299,76326614,167548585,
  95525. 85525151,0,12321,1,349528352};
  95526. int test2size=21;
  95527. static unsigned long testbuffer3[]=
  95528. {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,
  95529. 0,1,30,1,1,1,0,0,1,0,0,0,12,0,11,0,1,0,0,1};
  95530. int test3size=56;
  95531. static unsigned long large[]=
  95532. {2136531625L,2137861823,56732452,131,3212421,12325343,34547562,12313212,
  95533. 1233432,534,5,2146435231,14436467,7869299,76326614,167548585,
  95534. 85525151,0,12321,1,2146528352};
  95535. int onesize=33;
  95536. static int one[33]={146,25,44,151,195,15,153,176,233,131,196,65,85,172,47,40,
  95537. 34,242,223,136,35,222,211,86,171,50,225,135,214,75,172,
  95538. 223,4};
  95539. static int oneB[33]={150,101,131,33,203,15,204,216,105,193,156,65,84,85,222,
  95540. 8,139,145,227,126,34,55,244,171,85,100,39,195,173,18,
  95541. 245,251,128};
  95542. int twosize=6;
  95543. static int two[6]={61,255,255,251,231,29};
  95544. static int twoB[6]={247,63,255,253,249,120};
  95545. int threesize=54;
  95546. static int three[54]={169,2,232,252,91,132,156,36,89,13,123,176,144,32,254,
  95547. 142,224,85,59,121,144,79,124,23,67,90,90,216,79,23,83,
  95548. 58,135,196,61,55,129,183,54,101,100,170,37,127,126,10,
  95549. 100,52,4,14,18,86,77,1};
  95550. static int threeB[54]={206,128,42,153,57,8,183,251,13,89,36,30,32,144,183,
  95551. 130,59,240,121,59,85,223,19,228,180,134,33,107,74,98,
  95552. 233,253,196,135,63,2,110,114,50,155,90,127,37,170,104,
  95553. 200,20,254,4,58,106,176,144,0};
  95554. int foursize=38;
  95555. static int four[38]={18,6,163,252,97,194,104,131,32,1,7,82,137,42,129,11,72,
  95556. 132,60,220,112,8,196,109,64,179,86,9,137,195,208,122,169,
  95557. 28,2,133,0,1};
  95558. static int fourB[38]={36,48,102,83,243,24,52,7,4,35,132,10,145,21,2,93,2,41,
  95559. 1,219,184,16,33,184,54,149,170,132,18,30,29,98,229,67,
  95560. 129,10,4,32};
  95561. int fivesize=45;
  95562. static int five[45]={169,2,126,139,144,172,30,4,80,72,240,59,130,218,73,62,
  95563. 241,24,210,44,4,20,0,248,116,49,135,100,110,130,181,169,
  95564. 84,75,159,2,1,0,132,192,8,0,0,18,22};
  95565. static int fiveB[45]={1,84,145,111,245,100,128,8,56,36,40,71,126,78,213,226,
  95566. 124,105,12,0,133,128,0,162,233,242,67,152,77,205,77,
  95567. 172,150,169,129,79,128,0,6,4,32,0,27,9,0};
  95568. int sixsize=7;
  95569. static int six[7]={17,177,170,242,169,19,148};
  95570. static int sixB[7]={136,141,85,79,149,200,41};
  95571. oggpack_writeinit(&o);
  95572. fprintf(stderr,"\nSmall preclipped packing (LSb): ");
  95573. cliptest(testbuffer1,test1size,0,one,onesize);
  95574. fprintf(stderr,"ok.");
  95575. fprintf(stderr,"\nNull bit call (LSb): ");
  95576. cliptest(testbuffer3,test3size,0,two,twosize);
  95577. fprintf(stderr,"ok.");
  95578. fprintf(stderr,"\nLarge preclipped packing (LSb): ");
  95579. cliptest(testbuffer2,test2size,0,three,threesize);
  95580. fprintf(stderr,"ok.");
  95581. fprintf(stderr,"\n32 bit preclipped packing (LSb): ");
  95582. oggpack_reset(&o);
  95583. for(i=0;i<test2size;i++)
  95584. oggpack_write(&o,large[i],32);
  95585. buffer=oggpack_get_buffer(&o);
  95586. bytes=oggpack_bytes(&o);
  95587. oggpack_readinit(&r,buffer,bytes);
  95588. for(i=0;i<test2size;i++){
  95589. if(oggpack_look(&r,32)==-1)report("out of data. failed!");
  95590. if(oggpack_look(&r,32)!=large[i]){
  95591. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpack_look(&r,32),large[i],
  95592. oggpack_look(&r,32),large[i]);
  95593. report("read incorrect value!\n");
  95594. }
  95595. oggpack_adv(&r,32);
  95596. }
  95597. if(oggpack_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95598. fprintf(stderr,"ok.");
  95599. fprintf(stderr,"\nSmall unclipped packing (LSb): ");
  95600. cliptest(testbuffer1,test1size,7,four,foursize);
  95601. fprintf(stderr,"ok.");
  95602. fprintf(stderr,"\nLarge unclipped packing (LSb): ");
  95603. cliptest(testbuffer2,test2size,17,five,fivesize);
  95604. fprintf(stderr,"ok.");
  95605. fprintf(stderr,"\nSingle bit unclipped packing (LSb): ");
  95606. cliptest(testbuffer3,test3size,1,six,sixsize);
  95607. fprintf(stderr,"ok.");
  95608. fprintf(stderr,"\nTesting read past end (LSb): ");
  95609. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95610. for(i=0;i<64;i++){
  95611. if(oggpack_read(&r,1)!=0){
  95612. fprintf(stderr,"failed; got -1 prematurely.\n");
  95613. exit(1);
  95614. }
  95615. }
  95616. if(oggpack_look(&r,1)!=-1 ||
  95617. oggpack_read(&r,1)!=-1){
  95618. fprintf(stderr,"failed; read past end without -1.\n");
  95619. exit(1);
  95620. }
  95621. oggpack_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95622. if(oggpack_read(&r,30)!=0 || oggpack_read(&r,16)!=0){
  95623. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95624. exit(1);
  95625. }
  95626. if(oggpack_look(&r,18)!=0 ||
  95627. oggpack_look(&r,18)!=0){
  95628. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95629. exit(1);
  95630. }
  95631. if(oggpack_look(&r,19)!=-1 ||
  95632. oggpack_look(&r,19)!=-1){
  95633. fprintf(stderr,"failed; read past end without -1.\n");
  95634. exit(1);
  95635. }
  95636. if(oggpack_look(&r,32)!=-1 ||
  95637. oggpack_look(&r,32)!=-1){
  95638. fprintf(stderr,"failed; read past end without -1.\n");
  95639. exit(1);
  95640. }
  95641. oggpack_writeclear(&o);
  95642. fprintf(stderr,"ok.\n");
  95643. oggpackB_writeinit(&o);
  95644. fprintf(stderr,"\nSmall preclipped packing (MSb): ");
  95645. cliptestB(testbuffer1,test1size,0,oneB,onesize);
  95646. fprintf(stderr,"ok.");
  95647. fprintf(stderr,"\nNull bit call (MSb): ");
  95648. cliptestB(testbuffer3,test3size,0,twoB,twosize);
  95649. fprintf(stderr,"ok.");
  95650. fprintf(stderr,"\nLarge preclipped packing (MSb): ");
  95651. cliptestB(testbuffer2,test2size,0,threeB,threesize);
  95652. fprintf(stderr,"ok.");
  95653. fprintf(stderr,"\n32 bit preclipped packing (MSb): ");
  95654. oggpackB_reset(&o);
  95655. for(i=0;i<test2size;i++)
  95656. oggpackB_write(&o,large[i],32);
  95657. buffer=oggpackB_get_buffer(&o);
  95658. bytes=oggpackB_bytes(&o);
  95659. oggpackB_readinit(&r,buffer,bytes);
  95660. for(i=0;i<test2size;i++){
  95661. if(oggpackB_look(&r,32)==-1)report("out of data. failed!");
  95662. if(oggpackB_look(&r,32)!=large[i]){
  95663. fprintf(stderr,"%ld != %ld (%lx!=%lx):",oggpackB_look(&r,32),large[i],
  95664. oggpackB_look(&r,32),large[i]);
  95665. report("read incorrect value!\n");
  95666. }
  95667. oggpackB_adv(&r,32);
  95668. }
  95669. if(oggpackB_bytes(&r)!=bytes)report("leftover bytes after read!\n");
  95670. fprintf(stderr,"ok.");
  95671. fprintf(stderr,"\nSmall unclipped packing (MSb): ");
  95672. cliptestB(testbuffer1,test1size,7,fourB,foursize);
  95673. fprintf(stderr,"ok.");
  95674. fprintf(stderr,"\nLarge unclipped packing (MSb): ");
  95675. cliptestB(testbuffer2,test2size,17,fiveB,fivesize);
  95676. fprintf(stderr,"ok.");
  95677. fprintf(stderr,"\nSingle bit unclipped packing (MSb): ");
  95678. cliptestB(testbuffer3,test3size,1,sixB,sixsize);
  95679. fprintf(stderr,"ok.");
  95680. fprintf(stderr,"\nTesting read past end (MSb): ");
  95681. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95682. for(i=0;i<64;i++){
  95683. if(oggpackB_read(&r,1)!=0){
  95684. fprintf(stderr,"failed; got -1 prematurely.\n");
  95685. exit(1);
  95686. }
  95687. }
  95688. if(oggpackB_look(&r,1)!=-1 ||
  95689. oggpackB_read(&r,1)!=-1){
  95690. fprintf(stderr,"failed; read past end without -1.\n");
  95691. exit(1);
  95692. }
  95693. oggpackB_readinit(&r,"\0\0\0\0\0\0\0\0",8);
  95694. if(oggpackB_read(&r,30)!=0 || oggpackB_read(&r,16)!=0){
  95695. fprintf(stderr,"failed 2; got -1 prematurely.\n");
  95696. exit(1);
  95697. }
  95698. if(oggpackB_look(&r,18)!=0 ||
  95699. oggpackB_look(&r,18)!=0){
  95700. fprintf(stderr,"failed 3; got -1 prematurely.\n");
  95701. exit(1);
  95702. }
  95703. if(oggpackB_look(&r,19)!=-1 ||
  95704. oggpackB_look(&r,19)!=-1){
  95705. fprintf(stderr,"failed; read past end without -1.\n");
  95706. exit(1);
  95707. }
  95708. if(oggpackB_look(&r,32)!=-1 ||
  95709. oggpackB_look(&r,32)!=-1){
  95710. fprintf(stderr,"failed; read past end without -1.\n");
  95711. exit(1);
  95712. }
  95713. oggpackB_writeclear(&o);
  95714. fprintf(stderr,"ok.\n\n");
  95715. return(0);
  95716. }
  95717. #endif /* _V_SELFTEST */
  95718. #undef BUFFER_INCREMENT
  95719. #endif
  95720. /*** End of inlined file: bitwise.c ***/
  95721. /*** Start of inlined file: framing.c ***/
  95722. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  95723. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  95724. // tasks..
  95725. #if JUCE_MSVC
  95726. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  95727. #endif
  95728. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  95729. #if JUCE_USE_OGGVORBIS
  95730. #include <stdlib.h>
  95731. #include <string.h>
  95732. int ogg_page_version(ogg_page *og){
  95733. return((int)(og->header[4]));
  95734. }
  95735. int ogg_page_continued(ogg_page *og){
  95736. return((int)(og->header[5]&0x01));
  95737. }
  95738. int ogg_page_bos(ogg_page *og){
  95739. return((int)(og->header[5]&0x02));
  95740. }
  95741. int ogg_page_eos(ogg_page *og){
  95742. return((int)(og->header[5]&0x04));
  95743. }
  95744. ogg_int64_t ogg_page_granulepos(ogg_page *og){
  95745. unsigned char *page=og->header;
  95746. ogg_int64_t granulepos=page[13]&(0xff);
  95747. granulepos= (granulepos<<8)|(page[12]&0xff);
  95748. granulepos= (granulepos<<8)|(page[11]&0xff);
  95749. granulepos= (granulepos<<8)|(page[10]&0xff);
  95750. granulepos= (granulepos<<8)|(page[9]&0xff);
  95751. granulepos= (granulepos<<8)|(page[8]&0xff);
  95752. granulepos= (granulepos<<8)|(page[7]&0xff);
  95753. granulepos= (granulepos<<8)|(page[6]&0xff);
  95754. return(granulepos);
  95755. }
  95756. int ogg_page_serialno(ogg_page *og){
  95757. return(og->header[14] |
  95758. (og->header[15]<<8) |
  95759. (og->header[16]<<16) |
  95760. (og->header[17]<<24));
  95761. }
  95762. long ogg_page_pageno(ogg_page *og){
  95763. return(og->header[18] |
  95764. (og->header[19]<<8) |
  95765. (og->header[20]<<16) |
  95766. (og->header[21]<<24));
  95767. }
  95768. int ogg_page_packets(ogg_page *og){
  95769. int i,n=og->header[26],count=0;
  95770. for(i=0;i<n;i++)
  95771. if(og->header[27+i]<255)count++;
  95772. return(count);
  95773. }
  95774. #if 0
  95775. static ogg_uint32_t _ogg_crc_entry(unsigned long index){
  95776. int i;
  95777. unsigned long r;
  95778. r = index << 24;
  95779. for (i=0; i<8; i++)
  95780. if (r & 0x80000000UL)
  95781. r = (r << 1) ^ 0x04c11db7; /* The same as the ethernet generator
  95782. polynomial, although we use an
  95783. unreflected alg and an init/final
  95784. of 0, not 0xffffffff */
  95785. else
  95786. r<<=1;
  95787. return (r & 0xffffffffUL);
  95788. }
  95789. #endif
  95790. static const ogg_uint32_t crc_lookup[256]={
  95791. 0x00000000,0x04c11db7,0x09823b6e,0x0d4326d9,
  95792. 0x130476dc,0x17c56b6b,0x1a864db2,0x1e475005,
  95793. 0x2608edb8,0x22c9f00f,0x2f8ad6d6,0x2b4bcb61,
  95794. 0x350c9b64,0x31cd86d3,0x3c8ea00a,0x384fbdbd,
  95795. 0x4c11db70,0x48d0c6c7,0x4593e01e,0x4152fda9,
  95796. 0x5f15adac,0x5bd4b01b,0x569796c2,0x52568b75,
  95797. 0x6a1936c8,0x6ed82b7f,0x639b0da6,0x675a1011,
  95798. 0x791d4014,0x7ddc5da3,0x709f7b7a,0x745e66cd,
  95799. 0x9823b6e0,0x9ce2ab57,0x91a18d8e,0x95609039,
  95800. 0x8b27c03c,0x8fe6dd8b,0x82a5fb52,0x8664e6e5,
  95801. 0xbe2b5b58,0xbaea46ef,0xb7a96036,0xb3687d81,
  95802. 0xad2f2d84,0xa9ee3033,0xa4ad16ea,0xa06c0b5d,
  95803. 0xd4326d90,0xd0f37027,0xddb056fe,0xd9714b49,
  95804. 0xc7361b4c,0xc3f706fb,0xceb42022,0xca753d95,
  95805. 0xf23a8028,0xf6fb9d9f,0xfbb8bb46,0xff79a6f1,
  95806. 0xe13ef6f4,0xe5ffeb43,0xe8bccd9a,0xec7dd02d,
  95807. 0x34867077,0x30476dc0,0x3d044b19,0x39c556ae,
  95808. 0x278206ab,0x23431b1c,0x2e003dc5,0x2ac12072,
  95809. 0x128e9dcf,0x164f8078,0x1b0ca6a1,0x1fcdbb16,
  95810. 0x018aeb13,0x054bf6a4,0x0808d07d,0x0cc9cdca,
  95811. 0x7897ab07,0x7c56b6b0,0x71159069,0x75d48dde,
  95812. 0x6b93dddb,0x6f52c06c,0x6211e6b5,0x66d0fb02,
  95813. 0x5e9f46bf,0x5a5e5b08,0x571d7dd1,0x53dc6066,
  95814. 0x4d9b3063,0x495a2dd4,0x44190b0d,0x40d816ba,
  95815. 0xaca5c697,0xa864db20,0xa527fdf9,0xa1e6e04e,
  95816. 0xbfa1b04b,0xbb60adfc,0xb6238b25,0xb2e29692,
  95817. 0x8aad2b2f,0x8e6c3698,0x832f1041,0x87ee0df6,
  95818. 0x99a95df3,0x9d684044,0x902b669d,0x94ea7b2a,
  95819. 0xe0b41de7,0xe4750050,0xe9362689,0xedf73b3e,
  95820. 0xf3b06b3b,0xf771768c,0xfa325055,0xfef34de2,
  95821. 0xc6bcf05f,0xc27dede8,0xcf3ecb31,0xcbffd686,
  95822. 0xd5b88683,0xd1799b34,0xdc3abded,0xd8fba05a,
  95823. 0x690ce0ee,0x6dcdfd59,0x608edb80,0x644fc637,
  95824. 0x7a089632,0x7ec98b85,0x738aad5c,0x774bb0eb,
  95825. 0x4f040d56,0x4bc510e1,0x46863638,0x42472b8f,
  95826. 0x5c007b8a,0x58c1663d,0x558240e4,0x51435d53,
  95827. 0x251d3b9e,0x21dc2629,0x2c9f00f0,0x285e1d47,
  95828. 0x36194d42,0x32d850f5,0x3f9b762c,0x3b5a6b9b,
  95829. 0x0315d626,0x07d4cb91,0x0a97ed48,0x0e56f0ff,
  95830. 0x1011a0fa,0x14d0bd4d,0x19939b94,0x1d528623,
  95831. 0xf12f560e,0xf5ee4bb9,0xf8ad6d60,0xfc6c70d7,
  95832. 0xe22b20d2,0xe6ea3d65,0xeba91bbc,0xef68060b,
  95833. 0xd727bbb6,0xd3e6a601,0xdea580d8,0xda649d6f,
  95834. 0xc423cd6a,0xc0e2d0dd,0xcda1f604,0xc960ebb3,
  95835. 0xbd3e8d7e,0xb9ff90c9,0xb4bcb610,0xb07daba7,
  95836. 0xae3afba2,0xaafbe615,0xa7b8c0cc,0xa379dd7b,
  95837. 0x9b3660c6,0x9ff77d71,0x92b45ba8,0x9675461f,
  95838. 0x8832161a,0x8cf30bad,0x81b02d74,0x857130c3,
  95839. 0x5d8a9099,0x594b8d2e,0x5408abf7,0x50c9b640,
  95840. 0x4e8ee645,0x4a4ffbf2,0x470cdd2b,0x43cdc09c,
  95841. 0x7b827d21,0x7f436096,0x7200464f,0x76c15bf8,
  95842. 0x68860bfd,0x6c47164a,0x61043093,0x65c52d24,
  95843. 0x119b4be9,0x155a565e,0x18197087,0x1cd86d30,
  95844. 0x029f3d35,0x065e2082,0x0b1d065b,0x0fdc1bec,
  95845. 0x3793a651,0x3352bbe6,0x3e119d3f,0x3ad08088,
  95846. 0x2497d08d,0x2056cd3a,0x2d15ebe3,0x29d4f654,
  95847. 0xc5a92679,0xc1683bce,0xcc2b1d17,0xc8ea00a0,
  95848. 0xd6ad50a5,0xd26c4d12,0xdf2f6bcb,0xdbee767c,
  95849. 0xe3a1cbc1,0xe760d676,0xea23f0af,0xeee2ed18,
  95850. 0xf0a5bd1d,0xf464a0aa,0xf9278673,0xfde69bc4,
  95851. 0x89b8fd09,0x8d79e0be,0x803ac667,0x84fbdbd0,
  95852. 0x9abc8bd5,0x9e7d9662,0x933eb0bb,0x97ffad0c,
  95853. 0xafb010b1,0xab710d06,0xa6322bdf,0xa2f33668,
  95854. 0xbcb4666d,0xb8757bda,0xb5365d03,0xb1f740b4};
  95855. int ogg_stream_init(ogg_stream_state *os,int serialno){
  95856. if(os){
  95857. memset(os,0,sizeof(*os));
  95858. os->body_storage=16*1024;
  95859. os->body_data=(unsigned char*) _ogg_malloc(os->body_storage*sizeof(*os->body_data));
  95860. os->lacing_storage=1024;
  95861. os->lacing_vals=(int*) _ogg_malloc(os->lacing_storage*sizeof(*os->lacing_vals));
  95862. os->granule_vals=(ogg_int64_t*) _ogg_malloc(os->lacing_storage*sizeof(*os->granule_vals));
  95863. os->serialno=serialno;
  95864. return(0);
  95865. }
  95866. return(-1);
  95867. }
  95868. int ogg_stream_clear(ogg_stream_state *os){
  95869. if(os){
  95870. if(os->body_data)_ogg_free(os->body_data);
  95871. if(os->lacing_vals)_ogg_free(os->lacing_vals);
  95872. if(os->granule_vals)_ogg_free(os->granule_vals);
  95873. memset(os,0,sizeof(*os));
  95874. }
  95875. return(0);
  95876. }
  95877. int ogg_stream_destroy(ogg_stream_state *os){
  95878. if(os){
  95879. ogg_stream_clear(os);
  95880. _ogg_free(os);
  95881. }
  95882. return(0);
  95883. }
  95884. static void _os_body_expand(ogg_stream_state *os,int needed){
  95885. if(os->body_storage<=os->body_fill+needed){
  95886. os->body_storage+=(needed+1024);
  95887. os->body_data=(unsigned char*) _ogg_realloc(os->body_data,os->body_storage*sizeof(*os->body_data));
  95888. }
  95889. }
  95890. static void _os_lacing_expand(ogg_stream_state *os,int needed){
  95891. if(os->lacing_storage<=os->lacing_fill+needed){
  95892. os->lacing_storage+=(needed+32);
  95893. os->lacing_vals=(int*)_ogg_realloc(os->lacing_vals,os->lacing_storage*sizeof(*os->lacing_vals));
  95894. os->granule_vals=(ogg_int64_t*)_ogg_realloc(os->granule_vals,os->lacing_storage*sizeof(*os->granule_vals));
  95895. }
  95896. }
  95897. void ogg_page_checksum_set(ogg_page *og){
  95898. if(og){
  95899. ogg_uint32_t crc_reg=0;
  95900. int i;
  95901. og->header[22]=0;
  95902. og->header[23]=0;
  95903. og->header[24]=0;
  95904. og->header[25]=0;
  95905. for(i=0;i<og->header_len;i++)
  95906. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->header[i]];
  95907. for(i=0;i<og->body_len;i++)
  95908. crc_reg=(crc_reg<<8)^crc_lookup[((crc_reg >> 24)&0xff)^og->body[i]];
  95909. og->header[22]=(unsigned char)(crc_reg&0xff);
  95910. og->header[23]=(unsigned char)((crc_reg>>8)&0xff);
  95911. og->header[24]=(unsigned char)((crc_reg>>16)&0xff);
  95912. og->header[25]=(unsigned char)((crc_reg>>24)&0xff);
  95913. }
  95914. }
  95915. int ogg_stream_packetin(ogg_stream_state *os,ogg_packet *op){
  95916. int lacing_vals=op->bytes/255+1,i;
  95917. if(os->body_returned){
  95918. os->body_fill-=os->body_returned;
  95919. if(os->body_fill)
  95920. memmove(os->body_data,os->body_data+os->body_returned,
  95921. os->body_fill);
  95922. os->body_returned=0;
  95923. }
  95924. _os_body_expand(os,op->bytes);
  95925. _os_lacing_expand(os,lacing_vals);
  95926. memcpy(os->body_data+os->body_fill,op->packet,op->bytes);
  95927. os->body_fill+=op->bytes;
  95928. for(i=0;i<lacing_vals-1;i++){
  95929. os->lacing_vals[os->lacing_fill+i]=255;
  95930. os->granule_vals[os->lacing_fill+i]=os->granulepos;
  95931. }
  95932. os->lacing_vals[os->lacing_fill+i]=(op->bytes)%255;
  95933. os->granulepos=os->granule_vals[os->lacing_fill+i]=op->granulepos;
  95934. os->lacing_vals[os->lacing_fill]|= 0x100;
  95935. os->lacing_fill+=lacing_vals;
  95936. os->packetno++;
  95937. if(op->e_o_s)os->e_o_s=1;
  95938. return(0);
  95939. }
  95940. int ogg_stream_flush(ogg_stream_state *os,ogg_page *og){
  95941. int i;
  95942. int vals=0;
  95943. int maxvals=(os->lacing_fill>255?255:os->lacing_fill);
  95944. int bytes=0;
  95945. long acc=0;
  95946. ogg_int64_t granule_pos=-1;
  95947. if(maxvals==0)return(0);
  95948. if(os->b_o_s==0){ /* 'initial header page' case */
  95949. granule_pos=0;
  95950. for(vals=0;vals<maxvals;vals++){
  95951. if((os->lacing_vals[vals]&0x0ff)<255){
  95952. vals++;
  95953. break;
  95954. }
  95955. }
  95956. }else{
  95957. for(vals=0;vals<maxvals;vals++){
  95958. if(acc>4096)break;
  95959. acc+=os->lacing_vals[vals]&0x0ff;
  95960. if((os->lacing_vals[vals]&0xff)<255)
  95961. granule_pos=os->granule_vals[vals];
  95962. }
  95963. }
  95964. memcpy(os->header,"OggS",4);
  95965. os->header[4]=0x00;
  95966. os->header[5]=0x00;
  95967. if((os->lacing_vals[0]&0x100)==0)os->header[5]|=0x01;
  95968. if(os->b_o_s==0)os->header[5]|=0x02;
  95969. if(os->e_o_s && os->lacing_fill==vals)os->header[5]|=0x04;
  95970. os->b_o_s=1;
  95971. for(i=6;i<14;i++){
  95972. os->header[i]=(unsigned char)(granule_pos&0xff);
  95973. granule_pos>>=8;
  95974. }
  95975. {
  95976. long serialno=os->serialno;
  95977. for(i=14;i<18;i++){
  95978. os->header[i]=(unsigned char)(serialno&0xff);
  95979. serialno>>=8;
  95980. }
  95981. }
  95982. if(os->pageno==-1)os->pageno=0; /* because someone called
  95983. stream_reset; this would be a
  95984. strange thing to do in an
  95985. encode stream, but it has
  95986. plausible uses */
  95987. {
  95988. long pageno=os->pageno++;
  95989. for(i=18;i<22;i++){
  95990. os->header[i]=(unsigned char)(pageno&0xff);
  95991. pageno>>=8;
  95992. }
  95993. }
  95994. os->header[22]=0;
  95995. os->header[23]=0;
  95996. os->header[24]=0;
  95997. os->header[25]=0;
  95998. os->header[26]=(unsigned char)(vals&0xff);
  95999. for(i=0;i<vals;i++)
  96000. bytes+=os->header[i+27]=(unsigned char)(os->lacing_vals[i]&0xff);
  96001. og->header=os->header;
  96002. og->header_len=os->header_fill=vals+27;
  96003. og->body=os->body_data+os->body_returned;
  96004. og->body_len=bytes;
  96005. os->lacing_fill-=vals;
  96006. memmove(os->lacing_vals,os->lacing_vals+vals,os->lacing_fill*sizeof(*os->lacing_vals));
  96007. memmove(os->granule_vals,os->granule_vals+vals,os->lacing_fill*sizeof(*os->granule_vals));
  96008. os->body_returned+=bytes;
  96009. ogg_page_checksum_set(og);
  96010. return(1);
  96011. }
  96012. int ogg_stream_pageout(ogg_stream_state *os, ogg_page *og){
  96013. if((os->e_o_s&&os->lacing_fill) || /* 'were done, now flush' case */
  96014. os->body_fill-os->body_returned > 4096 ||/* 'page nominal size' case */
  96015. os->lacing_fill>=255 || /* 'segment table full' case */
  96016. (os->lacing_fill&&!os->b_o_s)){ /* 'initial header page' case */
  96017. return(ogg_stream_flush(os,og));
  96018. }
  96019. return(0);
  96020. }
  96021. int ogg_stream_eos(ogg_stream_state *os){
  96022. return os->e_o_s;
  96023. }
  96024. int ogg_sync_init(ogg_sync_state *oy){
  96025. if(oy){
  96026. memset(oy,0,sizeof(*oy));
  96027. }
  96028. return(0);
  96029. }
  96030. int ogg_sync_clear(ogg_sync_state *oy){
  96031. if(oy){
  96032. if(oy->data)_ogg_free(oy->data);
  96033. ogg_sync_init(oy);
  96034. }
  96035. return(0);
  96036. }
  96037. int ogg_sync_destroy(ogg_sync_state *oy){
  96038. if(oy){
  96039. ogg_sync_clear(oy);
  96040. _ogg_free(oy);
  96041. }
  96042. return(0);
  96043. }
  96044. char *ogg_sync_buffer(ogg_sync_state *oy, long size){
  96045. if(oy->returned){
  96046. oy->fill-=oy->returned;
  96047. if(oy->fill>0)
  96048. memmove(oy->data,oy->data+oy->returned,oy->fill);
  96049. oy->returned=0;
  96050. }
  96051. if(size>oy->storage-oy->fill){
  96052. long newsize=size+oy->fill+4096; /* an extra page to be nice */
  96053. if(oy->data)
  96054. oy->data=(unsigned char*) _ogg_realloc(oy->data,newsize);
  96055. else
  96056. oy->data=(unsigned char*) _ogg_malloc(newsize);
  96057. oy->storage=newsize;
  96058. }
  96059. return((char *)oy->data+oy->fill);
  96060. }
  96061. int ogg_sync_wrote(ogg_sync_state *oy, long bytes){
  96062. if(oy->fill+bytes>oy->storage)return(-1);
  96063. oy->fill+=bytes;
  96064. return(0);
  96065. }
  96066. long ogg_sync_pageseek(ogg_sync_state *oy,ogg_page *og){
  96067. unsigned char *page=oy->data+oy->returned;
  96068. unsigned char *next;
  96069. long bytes=oy->fill-oy->returned;
  96070. if(oy->headerbytes==0){
  96071. int headerbytes,i;
  96072. if(bytes<27)return(0); /* not enough for a header */
  96073. if(memcmp(page,"OggS",4))goto sync_fail;
  96074. headerbytes=page[26]+27;
  96075. if(bytes<headerbytes)return(0); /* not enough for header + seg table */
  96076. for(i=0;i<page[26];i++)
  96077. oy->bodybytes+=page[27+i];
  96078. oy->headerbytes=headerbytes;
  96079. }
  96080. if(oy->bodybytes+oy->headerbytes>bytes)return(0);
  96081. {
  96082. char chksum[4];
  96083. ogg_page log;
  96084. memcpy(chksum,page+22,4);
  96085. memset(page+22,0,4);
  96086. log.header=page;
  96087. log.header_len=oy->headerbytes;
  96088. log.body=page+oy->headerbytes;
  96089. log.body_len=oy->bodybytes;
  96090. ogg_page_checksum_set(&log);
  96091. if(memcmp(chksum,page+22,4)){
  96092. memcpy(page+22,chksum,4);
  96093. goto sync_fail;
  96094. }
  96095. }
  96096. {
  96097. unsigned char *page=oy->data+oy->returned;
  96098. long bytes;
  96099. if(og){
  96100. og->header=page;
  96101. og->header_len=oy->headerbytes;
  96102. og->body=page+oy->headerbytes;
  96103. og->body_len=oy->bodybytes;
  96104. }
  96105. oy->unsynced=0;
  96106. oy->returned+=(bytes=oy->headerbytes+oy->bodybytes);
  96107. oy->headerbytes=0;
  96108. oy->bodybytes=0;
  96109. return(bytes);
  96110. }
  96111. sync_fail:
  96112. oy->headerbytes=0;
  96113. oy->bodybytes=0;
  96114. next=(unsigned char*)memchr(page+1,'O',bytes-1);
  96115. if(!next)
  96116. next=oy->data+oy->fill;
  96117. oy->returned=next-oy->data;
  96118. return(-(next-page));
  96119. }
  96120. int ogg_sync_pageout(ogg_sync_state *oy, ogg_page *og){
  96121. for(;;){
  96122. long ret=ogg_sync_pageseek(oy,og);
  96123. if(ret>0){
  96124. return(1);
  96125. }
  96126. if(ret==0){
  96127. return(0);
  96128. }
  96129. if(!oy->unsynced){
  96130. oy->unsynced=1;
  96131. return(-1);
  96132. }
  96133. }
  96134. }
  96135. int ogg_stream_pagein(ogg_stream_state *os, ogg_page *og){
  96136. unsigned char *header=og->header;
  96137. unsigned char *body=og->body;
  96138. long bodysize=og->body_len;
  96139. int segptr=0;
  96140. int version=ogg_page_version(og);
  96141. int continued=ogg_page_continued(og);
  96142. int bos=ogg_page_bos(og);
  96143. int eos=ogg_page_eos(og);
  96144. ogg_int64_t granulepos=ogg_page_granulepos(og);
  96145. int serialno=ogg_page_serialno(og);
  96146. long pageno=ogg_page_pageno(og);
  96147. int segments=header[26];
  96148. {
  96149. long lr=os->lacing_returned;
  96150. long br=os->body_returned;
  96151. if(br){
  96152. os->body_fill-=br;
  96153. if(os->body_fill)
  96154. memmove(os->body_data,os->body_data+br,os->body_fill);
  96155. os->body_returned=0;
  96156. }
  96157. if(lr){
  96158. if(os->lacing_fill-lr){
  96159. memmove(os->lacing_vals,os->lacing_vals+lr,
  96160. (os->lacing_fill-lr)*sizeof(*os->lacing_vals));
  96161. memmove(os->granule_vals,os->granule_vals+lr,
  96162. (os->lacing_fill-lr)*sizeof(*os->granule_vals));
  96163. }
  96164. os->lacing_fill-=lr;
  96165. os->lacing_packet-=lr;
  96166. os->lacing_returned=0;
  96167. }
  96168. }
  96169. if(serialno!=os->serialno)return(-1);
  96170. if(version>0)return(-1);
  96171. _os_lacing_expand(os,segments+1);
  96172. if(pageno!=os->pageno){
  96173. int i;
  96174. for(i=os->lacing_packet;i<os->lacing_fill;i++)
  96175. os->body_fill-=os->lacing_vals[i]&0xff;
  96176. os->lacing_fill=os->lacing_packet;
  96177. if(os->pageno!=-1){
  96178. os->lacing_vals[os->lacing_fill++]=0x400;
  96179. os->lacing_packet++;
  96180. }
  96181. }
  96182. if(continued){
  96183. if(os->lacing_fill<1 ||
  96184. os->lacing_vals[os->lacing_fill-1]==0x400){
  96185. bos=0;
  96186. for(;segptr<segments;segptr++){
  96187. int val=header[27+segptr];
  96188. body+=val;
  96189. bodysize-=val;
  96190. if(val<255){
  96191. segptr++;
  96192. break;
  96193. }
  96194. }
  96195. }
  96196. }
  96197. if(bodysize){
  96198. _os_body_expand(os,bodysize);
  96199. memcpy(os->body_data+os->body_fill,body,bodysize);
  96200. os->body_fill+=bodysize;
  96201. }
  96202. {
  96203. int saved=-1;
  96204. while(segptr<segments){
  96205. int val=header[27+segptr];
  96206. os->lacing_vals[os->lacing_fill]=val;
  96207. os->granule_vals[os->lacing_fill]=-1;
  96208. if(bos){
  96209. os->lacing_vals[os->lacing_fill]|=0x100;
  96210. bos=0;
  96211. }
  96212. if(val<255)saved=os->lacing_fill;
  96213. os->lacing_fill++;
  96214. segptr++;
  96215. if(val<255)os->lacing_packet=os->lacing_fill;
  96216. }
  96217. if(saved!=-1){
  96218. os->granule_vals[saved]=granulepos;
  96219. }
  96220. }
  96221. if(eos){
  96222. os->e_o_s=1;
  96223. if(os->lacing_fill>0)
  96224. os->lacing_vals[os->lacing_fill-1]|=0x200;
  96225. }
  96226. os->pageno=pageno+1;
  96227. return(0);
  96228. }
  96229. int ogg_sync_reset(ogg_sync_state *oy){
  96230. oy->fill=0;
  96231. oy->returned=0;
  96232. oy->unsynced=0;
  96233. oy->headerbytes=0;
  96234. oy->bodybytes=0;
  96235. return(0);
  96236. }
  96237. int ogg_stream_reset(ogg_stream_state *os){
  96238. os->body_fill=0;
  96239. os->body_returned=0;
  96240. os->lacing_fill=0;
  96241. os->lacing_packet=0;
  96242. os->lacing_returned=0;
  96243. os->header_fill=0;
  96244. os->e_o_s=0;
  96245. os->b_o_s=0;
  96246. os->pageno=-1;
  96247. os->packetno=0;
  96248. os->granulepos=0;
  96249. return(0);
  96250. }
  96251. int ogg_stream_reset_serialno(ogg_stream_state *os,int serialno){
  96252. ogg_stream_reset(os);
  96253. os->serialno=serialno;
  96254. return(0);
  96255. }
  96256. static int _packetout(ogg_stream_state *os,ogg_packet *op,int adv){
  96257. int ptr=os->lacing_returned;
  96258. if(os->lacing_packet<=ptr)return(0);
  96259. if(os->lacing_vals[ptr]&0x400){
  96260. os->lacing_returned++;
  96261. os->packetno++;
  96262. return(-1);
  96263. }
  96264. if(!op && !adv)return(1); /* just using peek as an inexpensive way
  96265. to ask if there's a whole packet
  96266. waiting */
  96267. {
  96268. int size=os->lacing_vals[ptr]&0xff;
  96269. int bytes=size;
  96270. int eos=os->lacing_vals[ptr]&0x200; /* last packet of the stream? */
  96271. int bos=os->lacing_vals[ptr]&0x100; /* first packet of the stream? */
  96272. while(size==255){
  96273. int val=os->lacing_vals[++ptr];
  96274. size=val&0xff;
  96275. if(val&0x200)eos=0x200;
  96276. bytes+=size;
  96277. }
  96278. if(op){
  96279. op->e_o_s=eos;
  96280. op->b_o_s=bos;
  96281. op->packet=os->body_data+os->body_returned;
  96282. op->packetno=os->packetno;
  96283. op->granulepos=os->granule_vals[ptr];
  96284. op->bytes=bytes;
  96285. }
  96286. if(adv){
  96287. os->body_returned+=bytes;
  96288. os->lacing_returned=ptr+1;
  96289. os->packetno++;
  96290. }
  96291. }
  96292. return(1);
  96293. }
  96294. int ogg_stream_packetout(ogg_stream_state *os,ogg_packet *op){
  96295. return _packetout(os,op,1);
  96296. }
  96297. int ogg_stream_packetpeek(ogg_stream_state *os,ogg_packet *op){
  96298. return _packetout(os,op,0);
  96299. }
  96300. void ogg_packet_clear(ogg_packet *op) {
  96301. _ogg_free(op->packet);
  96302. memset(op, 0, sizeof(*op));
  96303. }
  96304. #ifdef _V_SELFTEST
  96305. #include <stdio.h>
  96306. ogg_stream_state os_en, os_de;
  96307. ogg_sync_state oy;
  96308. void checkpacket(ogg_packet *op,int len, int no, int pos){
  96309. long j;
  96310. static int sequence=0;
  96311. static int lastno=0;
  96312. if(op->bytes!=len){
  96313. fprintf(stderr,"incorrect packet length!\n");
  96314. exit(1);
  96315. }
  96316. if(op->granulepos!=pos){
  96317. fprintf(stderr,"incorrect packet position!\n");
  96318. exit(1);
  96319. }
  96320. if(no==0){
  96321. sequence=0;
  96322. }else{
  96323. sequence++;
  96324. if(no>lastno+1)
  96325. sequence++;
  96326. }
  96327. lastno=no;
  96328. if(op->packetno!=sequence){
  96329. fprintf(stderr,"incorrect packet sequence %ld != %d\n",
  96330. (long)(op->packetno),sequence);
  96331. exit(1);
  96332. }
  96333. for(j=0;j<op->bytes;j++)
  96334. if(op->packet[j]!=((j+no)&0xff)){
  96335. fprintf(stderr,"body data mismatch (1) at pos %ld: %x!=%lx!\n\n",
  96336. j,op->packet[j],(j+no)&0xff);
  96337. exit(1);
  96338. }
  96339. }
  96340. void check_page(unsigned char *data,const int *header,ogg_page *og){
  96341. long j;
  96342. for(j=0;j<og->body_len;j++)
  96343. if(og->body[j]!=data[j]){
  96344. fprintf(stderr,"body data mismatch (2) at pos %ld: %x!=%x!\n\n",
  96345. j,data[j],og->body[j]);
  96346. exit(1);
  96347. }
  96348. for(j=0;j<og->header_len;j++){
  96349. if(og->header[j]!=header[j]){
  96350. fprintf(stderr,"header content mismatch at pos %ld:\n",j);
  96351. for(j=0;j<header[26]+27;j++)
  96352. fprintf(stderr," (%ld)%02x:%02x",j,header[j],og->header[j]);
  96353. fprintf(stderr,"\n");
  96354. exit(1);
  96355. }
  96356. }
  96357. if(og->header_len!=header[26]+27){
  96358. fprintf(stderr,"header length incorrect! (%ld!=%d)\n",
  96359. og->header_len,header[26]+27);
  96360. exit(1);
  96361. }
  96362. }
  96363. void print_header(ogg_page *og){
  96364. int j;
  96365. fprintf(stderr,"\nHEADER:\n");
  96366. fprintf(stderr," capture: %c %c %c %c version: %d flags: %x\n",
  96367. og->header[0],og->header[1],og->header[2],og->header[3],
  96368. (int)og->header[4],(int)og->header[5]);
  96369. fprintf(stderr," granulepos: %d serialno: %d pageno: %ld\n",
  96370. (og->header[9]<<24)|(og->header[8]<<16)|
  96371. (og->header[7]<<8)|og->header[6],
  96372. (og->header[17]<<24)|(og->header[16]<<16)|
  96373. (og->header[15]<<8)|og->header[14],
  96374. ((long)(og->header[21])<<24)|(og->header[20]<<16)|
  96375. (og->header[19]<<8)|og->header[18]);
  96376. fprintf(stderr," checksum: %02x:%02x:%02x:%02x\n segments: %d (",
  96377. (int)og->header[22],(int)og->header[23],
  96378. (int)og->header[24],(int)og->header[25],
  96379. (int)og->header[26]);
  96380. for(j=27;j<og->header_len;j++)
  96381. fprintf(stderr,"%d ",(int)og->header[j]);
  96382. fprintf(stderr,")\n\n");
  96383. }
  96384. void copy_page(ogg_page *og){
  96385. unsigned char *temp=_ogg_malloc(og->header_len);
  96386. memcpy(temp,og->header,og->header_len);
  96387. og->header=temp;
  96388. temp=_ogg_malloc(og->body_len);
  96389. memcpy(temp,og->body,og->body_len);
  96390. og->body=temp;
  96391. }
  96392. void free_page(ogg_page *og){
  96393. _ogg_free (og->header);
  96394. _ogg_free (og->body);
  96395. }
  96396. void error(void){
  96397. fprintf(stderr,"error!\n");
  96398. exit(1);
  96399. }
  96400. const int head1_0[] = {0x4f,0x67,0x67,0x53,0,0x06,
  96401. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96402. 0x01,0x02,0x03,0x04,0,0,0,0,
  96403. 0x15,0xed,0xec,0x91,
  96404. 1,
  96405. 17};
  96406. const int head1_1[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96407. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96408. 0x01,0x02,0x03,0x04,0,0,0,0,
  96409. 0x59,0x10,0x6c,0x2c,
  96410. 1,
  96411. 17};
  96412. const int head2_1[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96413. 0x07,0x18,0x00,0x00,0x00,0x00,0x00,0x00,
  96414. 0x01,0x02,0x03,0x04,1,0,0,0,
  96415. 0x89,0x33,0x85,0xce,
  96416. 13,
  96417. 254,255,0,255,1,255,245,255,255,0,
  96418. 255,255,90};
  96419. const int head1_2[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96420. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96421. 0x01,0x02,0x03,0x04,0,0,0,0,
  96422. 0xff,0x7b,0x23,0x17,
  96423. 1,
  96424. 0};
  96425. const int head2_2[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96426. 0x07,0x28,0x00,0x00,0x00,0x00,0x00,0x00,
  96427. 0x01,0x02,0x03,0x04,1,0,0,0,
  96428. 0x5c,0x3f,0x66,0xcb,
  96429. 17,
  96430. 17,254,255,0,0,255,1,0,255,245,255,255,0,
  96431. 255,255,90,0};
  96432. const int head1_3[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96433. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96434. 0x01,0x02,0x03,0x04,0,0,0,0,
  96435. 0x01,0x27,0x31,0xaa,
  96436. 18,
  96437. 255,255,255,255,255,255,255,255,
  96438. 255,255,255,255,255,255,255,255,255,10};
  96439. const int head2_3[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96440. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96441. 0x01,0x02,0x03,0x04,1,0,0,0,
  96442. 0x7f,0x4e,0x8a,0xd2,
  96443. 4,
  96444. 255,4,255,0};
  96445. const int head1_4[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96446. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96447. 0x01,0x02,0x03,0x04,0,0,0,0,
  96448. 0xff,0x7b,0x23,0x17,
  96449. 1,
  96450. 0};
  96451. const int head2_4[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96452. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96453. 0x01,0x02,0x03,0x04,1,0,0,0,
  96454. 0x54,0x05,0x51,0xc8,
  96455. 17,
  96456. 255,255,255,255,255,255,255,255,
  96457. 255,255,255,255,255,255,255,255,255};
  96458. const int head3_4[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96459. 0x07,0x0c,0x00,0x00,0x00,0x00,0x00,0x00,
  96460. 0x01,0x02,0x03,0x04,2,0,0,0,
  96461. 0xc8,0xc3,0xcb,0xed,
  96462. 5,
  96463. 10,255,4,255,0};
  96464. const int head1_5[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96465. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96466. 0x01,0x02,0x03,0x04,0,0,0,0,
  96467. 0xff,0x7b,0x23,0x17,
  96468. 1,
  96469. 0};
  96470. const int head2_5[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96471. 0x07,0xfc,0x03,0x00,0x00,0x00,0x00,0x00,
  96472. 0x01,0x02,0x03,0x04,1,0,0,0,
  96473. 0xed,0x2a,0x2e,0xa7,
  96474. 255,
  96475. 10,10,10,10,10,10,10,10,
  96476. 10,10,10,10,10,10,10,10,
  96477. 10,10,10,10,10,10,10,10,
  96478. 10,10,10,10,10,10,10,10,
  96479. 10,10,10,10,10,10,10,10,
  96480. 10,10,10,10,10,10,10,10,
  96481. 10,10,10,10,10,10,10,10,
  96482. 10,10,10,10,10,10,10,10,
  96483. 10,10,10,10,10,10,10,10,
  96484. 10,10,10,10,10,10,10,10,
  96485. 10,10,10,10,10,10,10,10,
  96486. 10,10,10,10,10,10,10,10,
  96487. 10,10,10,10,10,10,10,10,
  96488. 10,10,10,10,10,10,10,10,
  96489. 10,10,10,10,10,10,10,10,
  96490. 10,10,10,10,10,10,10,10,
  96491. 10,10,10,10,10,10,10,10,
  96492. 10,10,10,10,10,10,10,10,
  96493. 10,10,10,10,10,10,10,10,
  96494. 10,10,10,10,10,10,10,10,
  96495. 10,10,10,10,10,10,10,10,
  96496. 10,10,10,10,10,10,10,10,
  96497. 10,10,10,10,10,10,10,10,
  96498. 10,10,10,10,10,10,10,10,
  96499. 10,10,10,10,10,10,10,10,
  96500. 10,10,10,10,10,10,10,10,
  96501. 10,10,10,10,10,10,10,10,
  96502. 10,10,10,10,10,10,10,10,
  96503. 10,10,10,10,10,10,10,10,
  96504. 10,10,10,10,10,10,10,10,
  96505. 10,10,10,10,10,10,10,10,
  96506. 10,10,10,10,10,10,10};
  96507. const int head3_5[] = {0x4f,0x67,0x67,0x53,0,0x04,
  96508. 0x07,0x00,0x04,0x00,0x00,0x00,0x00,0x00,
  96509. 0x01,0x02,0x03,0x04,2,0,0,0,
  96510. 0x6c,0x3b,0x82,0x3d,
  96511. 1,
  96512. 50};
  96513. const int head1_6[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96514. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96515. 0x01,0x02,0x03,0x04,0,0,0,0,
  96516. 0xff,0x7b,0x23,0x17,
  96517. 1,
  96518. 0};
  96519. const int head2_6[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96520. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96521. 0x01,0x02,0x03,0x04,1,0,0,0,
  96522. 0x3c,0xd9,0x4d,0x3f,
  96523. 17,
  96524. 100,255,255,255,255,255,255,255,255,
  96525. 255,255,255,255,255,255,255,255};
  96526. const int head3_6[] = {0x4f,0x67,0x67,0x53,0,0x01,
  96527. 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,0xFF,
  96528. 0x01,0x02,0x03,0x04,2,0,0,0,
  96529. 0x01,0xd2,0xe5,0xe5,
  96530. 17,
  96531. 255,255,255,255,255,255,255,255,
  96532. 255,255,255,255,255,255,255,255,255};
  96533. const int head4_6[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96534. 0x07,0x10,0x00,0x00,0x00,0x00,0x00,0x00,
  96535. 0x01,0x02,0x03,0x04,3,0,0,0,
  96536. 0xef,0xdd,0x88,0xde,
  96537. 7,
  96538. 255,255,75,255,4,255,0};
  96539. const int head1_7[] = {0x4f,0x67,0x67,0x53,0,0x02,
  96540. 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
  96541. 0x01,0x02,0x03,0x04,0,0,0,0,
  96542. 0xff,0x7b,0x23,0x17,
  96543. 1,
  96544. 0};
  96545. const int head2_7[] = {0x4f,0x67,0x67,0x53,0,0x00,
  96546. 0x07,0x04,0x00,0x00,0x00,0x00,0x00,0x00,
  96547. 0x01,0x02,0x03,0x04,1,0,0,0,
  96548. 0x3c,0xd9,0x4d,0x3f,
  96549. 17,
  96550. 100,255,255,255,255,255,255,255,255,
  96551. 255,255,255,255,255,255,255,255};
  96552. const int head3_7[] = {0x4f,0x67,0x67,0x53,0,0x05,
  96553. 0x07,0x08,0x00,0x00,0x00,0x00,0x00,0x00,
  96554. 0x01,0x02,0x03,0x04,2,0,0,0,
  96555. 0xd4,0xe0,0x60,0xe5,
  96556. 1,0};
  96557. void test_pack(const int *pl, const int **headers, int byteskip,
  96558. int pageskip, int packetskip){
  96559. unsigned char *data=_ogg_malloc(1024*1024); /* for scripted test cases only */
  96560. long inptr=0;
  96561. long outptr=0;
  96562. long deptr=0;
  96563. long depacket=0;
  96564. long granule_pos=7,pageno=0;
  96565. int i,j,packets,pageout=pageskip;
  96566. int eosflag=0;
  96567. int bosflag=0;
  96568. int byteskipcount=0;
  96569. ogg_stream_reset(&os_en);
  96570. ogg_stream_reset(&os_de);
  96571. ogg_sync_reset(&oy);
  96572. for(packets=0;packets<packetskip;packets++)
  96573. depacket+=pl[packets];
  96574. for(packets=0;;packets++)if(pl[packets]==-1)break;
  96575. for(i=0;i<packets;i++){
  96576. ogg_packet op;
  96577. int len=pl[i];
  96578. op.packet=data+inptr;
  96579. op.bytes=len;
  96580. op.e_o_s=(pl[i+1]<0?1:0);
  96581. op.granulepos=granule_pos;
  96582. granule_pos+=1024;
  96583. for(j=0;j<len;j++)data[inptr++]=i+j;
  96584. ogg_stream_packetin(&os_en,&op);
  96585. {
  96586. ogg_page og;
  96587. while(ogg_stream_pageout(&os_en,&og)){
  96588. fprintf(stderr,"%ld, ",pageno);
  96589. if(headers[pageno]==NULL){
  96590. fprintf(stderr,"coded too many pages!\n");
  96591. exit(1);
  96592. }
  96593. check_page(data+outptr,headers[pageno],&og);
  96594. outptr+=og.body_len;
  96595. pageno++;
  96596. if(pageskip){
  96597. bosflag=1;
  96598. pageskip--;
  96599. deptr+=og.body_len;
  96600. }
  96601. {
  96602. ogg_page og_de;
  96603. ogg_packet op_de,op_de2;
  96604. char *buf=ogg_sync_buffer(&oy,og.header_len+og.body_len);
  96605. char *next=buf;
  96606. byteskipcount+=og.header_len;
  96607. if(byteskipcount>byteskip){
  96608. memcpy(next,og.header,byteskipcount-byteskip);
  96609. next+=byteskipcount-byteskip;
  96610. byteskipcount=byteskip;
  96611. }
  96612. byteskipcount+=og.body_len;
  96613. if(byteskipcount>byteskip){
  96614. memcpy(next,og.body,byteskipcount-byteskip);
  96615. next+=byteskipcount-byteskip;
  96616. byteskipcount=byteskip;
  96617. }
  96618. ogg_sync_wrote(&oy,next-buf);
  96619. while(1){
  96620. int ret=ogg_sync_pageout(&oy,&og_de);
  96621. if(ret==0)break;
  96622. if(ret<0)continue;
  96623. fprintf(stderr,"(%ld), ",pageout);
  96624. check_page(data+deptr,headers[pageout],&og_de);
  96625. deptr+=og_de.body_len;
  96626. pageout++;
  96627. ogg_stream_pagein(&os_de,&og_de);
  96628. while(ogg_stream_packetpeek(&os_de,&op_de2)>0){
  96629. ogg_stream_packetpeek(&os_de,NULL);
  96630. ogg_stream_packetout(&os_de,&op_de); /* just catching them all */
  96631. if(memcmp(&op_de,&op_de2,sizeof(op_de))){
  96632. fprintf(stderr,"packetout != packetpeek! pos=%ld\n",
  96633. depacket);
  96634. exit(1);
  96635. }
  96636. if(memcmp(data+depacket,op_de.packet,op_de.bytes)){
  96637. fprintf(stderr,"packet data mismatch in decode! pos=%ld\n",
  96638. depacket);
  96639. exit(1);
  96640. }
  96641. if(bosflag==0 && op_de.b_o_s==0){
  96642. fprintf(stderr,"b_o_s flag not set on packet!\n");
  96643. exit(1);
  96644. }
  96645. if(bosflag && op_de.b_o_s){
  96646. fprintf(stderr,"b_o_s flag incorrectly set on packet!\n");
  96647. exit(1);
  96648. }
  96649. bosflag=1;
  96650. depacket+=op_de.bytes;
  96651. if(eosflag){
  96652. fprintf(stderr,"Multiple decoded packets with eos flag!\n");
  96653. exit(1);
  96654. }
  96655. if(op_de.e_o_s)eosflag=1;
  96656. if(op_de.granulepos!=-1){
  96657. fprintf(stderr," granule:%ld ",(long)op_de.granulepos);
  96658. }
  96659. }
  96660. }
  96661. }
  96662. }
  96663. }
  96664. }
  96665. _ogg_free(data);
  96666. if(headers[pageno]!=NULL){
  96667. fprintf(stderr,"did not write last page!\n");
  96668. exit(1);
  96669. }
  96670. if(headers[pageout]!=NULL){
  96671. fprintf(stderr,"did not decode last page!\n");
  96672. exit(1);
  96673. }
  96674. if(inptr!=outptr){
  96675. fprintf(stderr,"encoded page data incomplete!\n");
  96676. exit(1);
  96677. }
  96678. if(inptr!=deptr){
  96679. fprintf(stderr,"decoded page data incomplete!\n");
  96680. exit(1);
  96681. }
  96682. if(inptr!=depacket){
  96683. fprintf(stderr,"decoded packet data incomplete!\n");
  96684. exit(1);
  96685. }
  96686. if(!eosflag){
  96687. fprintf(stderr,"Never got a packet with EOS set!\n");
  96688. exit(1);
  96689. }
  96690. fprintf(stderr,"ok.\n");
  96691. }
  96692. int main(void){
  96693. ogg_stream_init(&os_en,0x04030201);
  96694. ogg_stream_init(&os_de,0x04030201);
  96695. ogg_sync_init(&oy);
  96696. {
  96697. const int packets[]={17, -1};
  96698. const int *headret[]={head1_0,NULL};
  96699. fprintf(stderr,"testing single page encoding... ");
  96700. test_pack(packets,headret,0,0,0);
  96701. }
  96702. {
  96703. const int packets[]={17, 254, 255, 256, 500, 510, 600, -1};
  96704. const int *headret[]={head1_1,head2_1,NULL};
  96705. fprintf(stderr,"testing basic page encoding... ");
  96706. test_pack(packets,headret,0,0,0);
  96707. }
  96708. {
  96709. const int packets[]={0,17, 254, 255, 0, 256, 0, 500, 510, 600, 0, -1};
  96710. const int *headret[]={head1_2,head2_2,NULL};
  96711. fprintf(stderr,"testing basic nil packets... ");
  96712. test_pack(packets,headret,0,0,0);
  96713. }
  96714. {
  96715. const int packets[]={4345,259,255,-1};
  96716. const int *headret[]={head1_3,head2_3,NULL};
  96717. fprintf(stderr,"testing initial-packet lacing > 4k... ");
  96718. test_pack(packets,headret,0,0,0);
  96719. }
  96720. {
  96721. const int packets[]={0,4345,259,255,-1};
  96722. const int *headret[]={head1_4,head2_4,head3_4,NULL};
  96723. fprintf(stderr,"testing single packet page span... ");
  96724. test_pack(packets,headret,0,0,0);
  96725. }
  96726. {
  96727. const int packets[]={0,10,10,10,10,10,10,10,10,
  96728. 10,10,10,10,10,10,10,10,
  96729. 10,10,10,10,10,10,10,10,
  96730. 10,10,10,10,10,10,10,10,
  96731. 10,10,10,10,10,10,10,10,
  96732. 10,10,10,10,10,10,10,10,
  96733. 10,10,10,10,10,10,10,10,
  96734. 10,10,10,10,10,10,10,10,
  96735. 10,10,10,10,10,10,10,10,
  96736. 10,10,10,10,10,10,10,10,
  96737. 10,10,10,10,10,10,10,10,
  96738. 10,10,10,10,10,10,10,10,
  96739. 10,10,10,10,10,10,10,10,
  96740. 10,10,10,10,10,10,10,10,
  96741. 10,10,10,10,10,10,10,10,
  96742. 10,10,10,10,10,10,10,10,
  96743. 10,10,10,10,10,10,10,10,
  96744. 10,10,10,10,10,10,10,10,
  96745. 10,10,10,10,10,10,10,10,
  96746. 10,10,10,10,10,10,10,10,
  96747. 10,10,10,10,10,10,10,10,
  96748. 10,10,10,10,10,10,10,10,
  96749. 10,10,10,10,10,10,10,10,
  96750. 10,10,10,10,10,10,10,10,
  96751. 10,10,10,10,10,10,10,10,
  96752. 10,10,10,10,10,10,10,10,
  96753. 10,10,10,10,10,10,10,10,
  96754. 10,10,10,10,10,10,10,10,
  96755. 10,10,10,10,10,10,10,10,
  96756. 10,10,10,10,10,10,10,10,
  96757. 10,10,10,10,10,10,10,10,
  96758. 10,10,10,10,10,10,10,50,-1};
  96759. const int *headret[]={head1_5,head2_5,head3_5,NULL};
  96760. fprintf(stderr,"testing max packet segments... ");
  96761. test_pack(packets,headret,0,0,0);
  96762. }
  96763. {
  96764. const int packets[]={0,100,9000,259,255,-1};
  96765. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96766. fprintf(stderr,"testing very large packets... ");
  96767. test_pack(packets,headret,0,0,0);
  96768. }
  96769. {
  96770. const int packets[]={0,100,9000,259,255,-1};
  96771. const int *headret[]={head1_6,head2_6,head3_6,head4_6,NULL};
  96772. fprintf(stderr,"testing continuation resync in very large packets... ");
  96773. test_pack(packets,headret,100,2,3);
  96774. }
  96775. {
  96776. const int packets[]={0,100,4080,-1};
  96777. const int *headret[]={head1_7,head2_7,head3_7,NULL};
  96778. fprintf(stderr,"testing zero data page (1 nil packet)... ");
  96779. test_pack(packets,headret,0,0,0);
  96780. }
  96781. {
  96782. unsigned char *data=_ogg_malloc(1024*1024);
  96783. int pl[]={0,100,4079,2956,2057,76,34,912,0,234,1000,1000,1000,300,-1};
  96784. int inptr=0,i,j;
  96785. ogg_page og[5];
  96786. ogg_stream_reset(&os_en);
  96787. for(i=0;pl[i]!=-1;i++){
  96788. ogg_packet op;
  96789. int len=pl[i];
  96790. op.packet=data+inptr;
  96791. op.bytes=len;
  96792. op.e_o_s=(pl[i+1]<0?1:0);
  96793. op.granulepos=(i+1)*1000;
  96794. for(j=0;j<len;j++)data[inptr++]=i+j;
  96795. ogg_stream_packetin(&os_en,&op);
  96796. }
  96797. _ogg_free(data);
  96798. for(i=0;i<5;i++){
  96799. if(ogg_stream_pageout(&os_en,&og[i])==0){
  96800. fprintf(stderr,"Too few pages output building sync tests!\n");
  96801. exit(1);
  96802. }
  96803. copy_page(&og[i]);
  96804. }
  96805. {
  96806. ogg_page temp;
  96807. ogg_packet test;
  96808. fprintf(stderr,"Testing loss of pages... ");
  96809. ogg_sync_reset(&oy);
  96810. ogg_stream_reset(&os_de);
  96811. for(i=0;i<5;i++){
  96812. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96813. og[i].header_len);
  96814. ogg_sync_wrote(&oy,og[i].header_len);
  96815. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96816. ogg_sync_wrote(&oy,og[i].body_len);
  96817. }
  96818. ogg_sync_pageout(&oy,&temp);
  96819. ogg_stream_pagein(&os_de,&temp);
  96820. ogg_sync_pageout(&oy,&temp);
  96821. ogg_stream_pagein(&os_de,&temp);
  96822. ogg_sync_pageout(&oy,&temp);
  96823. ogg_sync_pageout(&oy,&temp);
  96824. ogg_stream_pagein(&os_de,&temp);
  96825. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96826. checkpacket(&test,0,0,0);
  96827. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96828. checkpacket(&test,100,1,-1);
  96829. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96830. checkpacket(&test,4079,2,3000);
  96831. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96832. fprintf(stderr,"Error: loss of page did not return error\n");
  96833. exit(1);
  96834. }
  96835. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96836. checkpacket(&test,76,5,-1);
  96837. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96838. checkpacket(&test,34,6,-1);
  96839. fprintf(stderr,"ok.\n");
  96840. }
  96841. {
  96842. ogg_page temp;
  96843. ogg_packet test;
  96844. fprintf(stderr,"Testing loss of pages (rollback required)... ");
  96845. ogg_sync_reset(&oy);
  96846. ogg_stream_reset(&os_de);
  96847. for(i=0;i<5;i++){
  96848. memcpy(ogg_sync_buffer(&oy,og[i].header_len),og[i].header,
  96849. og[i].header_len);
  96850. ogg_sync_wrote(&oy,og[i].header_len);
  96851. memcpy(ogg_sync_buffer(&oy,og[i].body_len),og[i].body,og[i].body_len);
  96852. ogg_sync_wrote(&oy,og[i].body_len);
  96853. }
  96854. ogg_sync_pageout(&oy,&temp);
  96855. ogg_stream_pagein(&os_de,&temp);
  96856. ogg_sync_pageout(&oy,&temp);
  96857. ogg_stream_pagein(&os_de,&temp);
  96858. ogg_sync_pageout(&oy,&temp);
  96859. ogg_stream_pagein(&os_de,&temp);
  96860. ogg_sync_pageout(&oy,&temp);
  96861. ogg_sync_pageout(&oy,&temp);
  96862. ogg_stream_pagein(&os_de,&temp);
  96863. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96864. checkpacket(&test,0,0,0);
  96865. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96866. checkpacket(&test,100,1,-1);
  96867. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96868. checkpacket(&test,4079,2,3000);
  96869. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96870. checkpacket(&test,2956,3,4000);
  96871. if(ogg_stream_packetout(&os_de,&test)!=-1){
  96872. fprintf(stderr,"Error: loss of page did not return error\n");
  96873. exit(1);
  96874. }
  96875. if(ogg_stream_packetout(&os_de,&test)!=1)error();
  96876. checkpacket(&test,300,13,14000);
  96877. fprintf(stderr,"ok.\n");
  96878. }
  96879. {
  96880. ogg_page og_de;
  96881. fprintf(stderr,"Testing sync on partial inputs... ");
  96882. ogg_sync_reset(&oy);
  96883. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96884. 3);
  96885. ogg_sync_wrote(&oy,3);
  96886. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96887. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+3,
  96888. 20);
  96889. ogg_sync_wrote(&oy,20);
  96890. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96891. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+23,
  96892. 5);
  96893. ogg_sync_wrote(&oy,5);
  96894. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96895. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+28,
  96896. og[1].header_len-28);
  96897. ogg_sync_wrote(&oy,og[1].header_len-28);
  96898. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96899. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,1000);
  96900. ogg_sync_wrote(&oy,1000);
  96901. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96902. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body+1000,
  96903. og[1].body_len-1000);
  96904. ogg_sync_wrote(&oy,og[1].body_len-1000);
  96905. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96906. fprintf(stderr,"ok.\n");
  96907. }
  96908. {
  96909. ogg_page og_de;
  96910. fprintf(stderr,"Testing sync on 1+partial inputs... ");
  96911. ogg_sync_reset(&oy);
  96912. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96913. og[1].header_len);
  96914. ogg_sync_wrote(&oy,og[1].header_len);
  96915. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96916. og[1].body_len);
  96917. ogg_sync_wrote(&oy,og[1].body_len);
  96918. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96919. 20);
  96920. ogg_sync_wrote(&oy,20);
  96921. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96922. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96923. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header+20,
  96924. og[1].header_len-20);
  96925. ogg_sync_wrote(&oy,og[1].header_len-20);
  96926. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96927. og[1].body_len);
  96928. ogg_sync_wrote(&oy,og[1].body_len);
  96929. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96930. fprintf(stderr,"ok.\n");
  96931. }
  96932. {
  96933. ogg_page og_de;
  96934. fprintf(stderr,"Testing search for capture... ");
  96935. ogg_sync_reset(&oy);
  96936. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96937. og[1].body_len);
  96938. ogg_sync_wrote(&oy,og[1].body_len);
  96939. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96940. og[1].header_len);
  96941. ogg_sync_wrote(&oy,og[1].header_len);
  96942. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96943. og[1].body_len);
  96944. ogg_sync_wrote(&oy,og[1].body_len);
  96945. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96946. 20);
  96947. ogg_sync_wrote(&oy,20);
  96948. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96949. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96950. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96951. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header+20,
  96952. og[2].header_len-20);
  96953. ogg_sync_wrote(&oy,og[2].header_len-20);
  96954. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96955. og[2].body_len);
  96956. ogg_sync_wrote(&oy,og[2].body_len);
  96957. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96958. fprintf(stderr,"ok.\n");
  96959. }
  96960. {
  96961. ogg_page og_de;
  96962. fprintf(stderr,"Testing recapture... ");
  96963. ogg_sync_reset(&oy);
  96964. memcpy(ogg_sync_buffer(&oy,og[1].header_len),og[1].header,
  96965. og[1].header_len);
  96966. ogg_sync_wrote(&oy,og[1].header_len);
  96967. memcpy(ogg_sync_buffer(&oy,og[1].body_len),og[1].body,
  96968. og[1].body_len);
  96969. ogg_sync_wrote(&oy,og[1].body_len);
  96970. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96971. og[2].header_len);
  96972. ogg_sync_wrote(&oy,og[2].header_len);
  96973. memcpy(ogg_sync_buffer(&oy,og[2].header_len),og[2].header,
  96974. og[2].header_len);
  96975. ogg_sync_wrote(&oy,og[2].header_len);
  96976. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96977. memcpy(ogg_sync_buffer(&oy,og[2].body_len),og[2].body,
  96978. og[2].body_len-5);
  96979. ogg_sync_wrote(&oy,og[2].body_len-5);
  96980. memcpy(ogg_sync_buffer(&oy,og[3].header_len),og[3].header,
  96981. og[3].header_len);
  96982. ogg_sync_wrote(&oy,og[3].header_len);
  96983. memcpy(ogg_sync_buffer(&oy,og[3].body_len),og[3].body,
  96984. og[3].body_len);
  96985. ogg_sync_wrote(&oy,og[3].body_len);
  96986. if(ogg_sync_pageout(&oy,&og_de)>0)error();
  96987. if(ogg_sync_pageout(&oy,&og_de)<=0)error();
  96988. fprintf(stderr,"ok.\n");
  96989. }
  96990. {
  96991. for(i=0;i<5;i++){
  96992. free_page(&og[i]);
  96993. }
  96994. }
  96995. }
  96996. return(0);
  96997. }
  96998. #endif
  96999. #endif
  97000. /*** End of inlined file: framing.c ***/
  97001. /*** Start of inlined file: analysis.c ***/
  97002. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97003. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97004. // tasks..
  97005. #if JUCE_MSVC
  97006. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97007. #endif
  97008. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97009. #if JUCE_USE_OGGVORBIS
  97010. #include <stdio.h>
  97011. #include <string.h>
  97012. #include <math.h>
  97013. /*** Start of inlined file: codec_internal.h ***/
  97014. #ifndef _V_CODECI_H_
  97015. #define _V_CODECI_H_
  97016. /*** Start of inlined file: envelope.h ***/
  97017. #ifndef _V_ENVELOPE_
  97018. #define _V_ENVELOPE_
  97019. /*** Start of inlined file: mdct.h ***/
  97020. #ifndef _OGG_mdct_H_
  97021. #define _OGG_mdct_H_
  97022. #ifdef MDCT_INTEGERIZED
  97023. #define DATA_TYPE int
  97024. #define REG_TYPE register int
  97025. #define TRIGBITS 14
  97026. #define cPI3_8 6270
  97027. #define cPI2_8 11585
  97028. #define cPI1_8 15137
  97029. #define FLOAT_CONV(x) ((int)((x)*(1<<TRIGBITS)+.5))
  97030. #define MULT_NORM(x) ((x)>>TRIGBITS)
  97031. #define HALVE(x) ((x)>>1)
  97032. #else
  97033. #define DATA_TYPE float
  97034. #define REG_TYPE float
  97035. #define cPI3_8 .38268343236508977175F
  97036. #define cPI2_8 .70710678118654752441F
  97037. #define cPI1_8 .92387953251128675613F
  97038. #define FLOAT_CONV(x) (x)
  97039. #define MULT_NORM(x) (x)
  97040. #define HALVE(x) ((x)*.5f)
  97041. #endif
  97042. typedef struct {
  97043. int n;
  97044. int log2n;
  97045. DATA_TYPE *trig;
  97046. int *bitrev;
  97047. DATA_TYPE scale;
  97048. } mdct_lookup;
  97049. extern void mdct_init(mdct_lookup *lookup,int n);
  97050. extern void mdct_clear(mdct_lookup *l);
  97051. extern void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  97052. extern void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out);
  97053. #endif
  97054. /*** End of inlined file: mdct.h ***/
  97055. #define VE_PRE 16
  97056. #define VE_WIN 4
  97057. #define VE_POST 2
  97058. #define VE_AMP (VE_PRE+VE_POST-1)
  97059. #define VE_BANDS 7
  97060. #define VE_NEARDC 15
  97061. #define VE_MINSTRETCH 2 /* a bit less than short block */
  97062. #define VE_MAXSTRETCH 12 /* one-third full block */
  97063. typedef struct {
  97064. float ampbuf[VE_AMP];
  97065. int ampptr;
  97066. float nearDC[VE_NEARDC];
  97067. float nearDC_acc;
  97068. float nearDC_partialacc;
  97069. int nearptr;
  97070. } envelope_filter_state;
  97071. typedef struct {
  97072. int begin;
  97073. int end;
  97074. float *window;
  97075. float total;
  97076. } envelope_band;
  97077. typedef struct {
  97078. int ch;
  97079. int winlength;
  97080. int searchstep;
  97081. float minenergy;
  97082. mdct_lookup mdct;
  97083. float *mdct_win;
  97084. envelope_band band[VE_BANDS];
  97085. envelope_filter_state *filter;
  97086. int stretch;
  97087. int *mark;
  97088. long storage;
  97089. long current;
  97090. long curmark;
  97091. long cursor;
  97092. } envelope_lookup;
  97093. extern void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi);
  97094. extern void _ve_envelope_clear(envelope_lookup *e);
  97095. extern long _ve_envelope_search(vorbis_dsp_state *v);
  97096. extern void _ve_envelope_shift(envelope_lookup *e,long shift);
  97097. extern int _ve_envelope_mark(vorbis_dsp_state *v);
  97098. #endif
  97099. /*** End of inlined file: envelope.h ***/
  97100. /*** Start of inlined file: codebook.h ***/
  97101. #ifndef _V_CODEBOOK_H_
  97102. #define _V_CODEBOOK_H_
  97103. typedef struct static_codebook{
  97104. long dim; /* codebook dimensions (elements per vector) */
  97105. long entries; /* codebook entries */
  97106. long *lengthlist; /* codeword lengths in bits */
  97107. int maptype; /* 0=none
  97108. 1=implicitly populated values from map column
  97109. 2=listed arbitrary values */
  97110. long q_min; /* packed 32 bit float; quant value 0 maps to minval */
  97111. long q_delta; /* packed 32 bit float; val 1 - val 0 == delta */
  97112. int q_quant; /* bits: 0 < quant <= 16 */
  97113. int q_sequencep; /* bitflag */
  97114. long *quantlist; /* map == 1: (int)(entries^(1/dim)) element column map
  97115. map == 2: list of dim*entries quantized entry vals
  97116. */
  97117. struct encode_aux_nearestmatch *nearest_tree;
  97118. struct encode_aux_threshmatch *thresh_tree;
  97119. struct encode_aux_pigeonhole *pigeon_tree;
  97120. int allocedp;
  97121. } static_codebook;
  97122. typedef struct encode_aux_nearestmatch{
  97123. long *ptr0;
  97124. long *ptr1;
  97125. long *p; /* decision points (each is an entry) */
  97126. long *q; /* decision points (each is an entry) */
  97127. long aux; /* number of tree entries */
  97128. long alloc;
  97129. } encode_aux_nearestmatch;
  97130. typedef struct encode_aux_threshmatch{
  97131. float *quantthresh;
  97132. long *quantmap;
  97133. int quantvals;
  97134. int threshvals;
  97135. } encode_aux_threshmatch;
  97136. typedef struct encode_aux_pigeonhole{
  97137. float min;
  97138. float del;
  97139. int mapentries;
  97140. int quantvals;
  97141. long *pigeonmap;
  97142. long fittotal;
  97143. long *fitlist;
  97144. long *fitmap;
  97145. long *fitlength;
  97146. } encode_aux_pigeonhole;
  97147. typedef struct codebook{
  97148. long dim; /* codebook dimensions (elements per vector) */
  97149. long entries; /* codebook entries */
  97150. long used_entries; /* populated codebook entries */
  97151. const static_codebook *c;
  97152. float *valuelist; /* list of dim*entries actual entry values */
  97153. ogg_uint32_t *codelist; /* list of bitstream codewords for each entry */
  97154. int *dec_index; /* only used if sparseness collapsed */
  97155. char *dec_codelengths;
  97156. ogg_uint32_t *dec_firsttable;
  97157. int dec_firsttablen;
  97158. int dec_maxlength;
  97159. } codebook;
  97160. extern void vorbis_staticbook_clear(static_codebook *b);
  97161. extern void vorbis_staticbook_destroy(static_codebook *b);
  97162. extern int vorbis_book_init_encode(codebook *dest,const static_codebook *source);
  97163. extern int vorbis_book_init_decode(codebook *dest,const static_codebook *source);
  97164. extern void vorbis_book_clear(codebook *b);
  97165. extern float *_book_unquantize(const static_codebook *b,int n,int *map);
  97166. extern float *_book_logdist(const static_codebook *b,float *vals);
  97167. extern float _float32_unpack(long val);
  97168. extern long _float32_pack(float val);
  97169. extern int _best(codebook *book, float *a, int step);
  97170. extern int _ilog(unsigned int v);
  97171. extern long _book_maptype1_quantvals(const static_codebook *b);
  97172. extern int vorbis_book_besterror(codebook *book,float *a,int step,int addmul);
  97173. extern long vorbis_book_codeword(codebook *book,int entry);
  97174. extern long vorbis_book_codelen(codebook *book,int entry);
  97175. extern int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *b);
  97176. extern int vorbis_staticbook_unpack(oggpack_buffer *b,static_codebook *c);
  97177. extern int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b);
  97178. extern int vorbis_book_errorv(codebook *book, float *a);
  97179. extern int vorbis_book_encodev(codebook *book, int best,float *a,
  97180. oggpack_buffer *b);
  97181. extern long vorbis_book_decode(codebook *book, oggpack_buffer *b);
  97182. extern long vorbis_book_decodevs_add(codebook *book, float *a,
  97183. oggpack_buffer *b,int n);
  97184. extern long vorbis_book_decodev_set(codebook *book, float *a,
  97185. oggpack_buffer *b,int n);
  97186. extern long vorbis_book_decodev_add(codebook *book, float *a,
  97187. oggpack_buffer *b,int n);
  97188. extern long vorbis_book_decodevv_add(codebook *book, float **a,
  97189. long off,int ch,
  97190. oggpack_buffer *b,int n);
  97191. #endif
  97192. /*** End of inlined file: codebook.h ***/
  97193. #define BLOCKTYPE_IMPULSE 0
  97194. #define BLOCKTYPE_PADDING 1
  97195. #define BLOCKTYPE_TRANSITION 0
  97196. #define BLOCKTYPE_LONG 1
  97197. #define PACKETBLOBS 15
  97198. typedef struct vorbis_block_internal{
  97199. float **pcmdelay; /* this is a pointer into local storage */
  97200. float ampmax;
  97201. int blocktype;
  97202. oggpack_buffer *packetblob[PACKETBLOBS]; /* initialized, must be freed;
  97203. blob [PACKETBLOBS/2] points to
  97204. the oggpack_buffer in the
  97205. main vorbis_block */
  97206. } vorbis_block_internal;
  97207. typedef void vorbis_look_floor;
  97208. typedef void vorbis_look_residue;
  97209. typedef void vorbis_look_transform;
  97210. typedef struct {
  97211. int blockflag;
  97212. int windowtype;
  97213. int transformtype;
  97214. int mapping;
  97215. } vorbis_info_mode;
  97216. typedef void vorbis_info_floor;
  97217. typedef void vorbis_info_residue;
  97218. typedef void vorbis_info_mapping;
  97219. /*** Start of inlined file: psy.h ***/
  97220. #ifndef _V_PSY_H_
  97221. #define _V_PSY_H_
  97222. /*** Start of inlined file: smallft.h ***/
  97223. #ifndef _V_SMFT_H_
  97224. #define _V_SMFT_H_
  97225. typedef struct {
  97226. int n;
  97227. float *trigcache;
  97228. int *splitcache;
  97229. } drft_lookup;
  97230. extern void drft_forward(drft_lookup *l,float *data);
  97231. extern void drft_backward(drft_lookup *l,float *data);
  97232. extern void drft_init(drft_lookup *l,int n);
  97233. extern void drft_clear(drft_lookup *l);
  97234. #endif
  97235. /*** End of inlined file: smallft.h ***/
  97236. /*** Start of inlined file: backends.h ***/
  97237. #ifndef _vorbis_backend_h_
  97238. #define _vorbis_backend_h_
  97239. typedef struct{
  97240. void (*pack) (vorbis_info_floor *,oggpack_buffer *);
  97241. vorbis_info_floor *(*unpack)(vorbis_info *,oggpack_buffer *);
  97242. vorbis_look_floor *(*look) (vorbis_dsp_state *,vorbis_info_floor *);
  97243. void (*free_info) (vorbis_info_floor *);
  97244. void (*free_look) (vorbis_look_floor *);
  97245. void *(*inverse1) (struct vorbis_block *,vorbis_look_floor *);
  97246. int (*inverse2) (struct vorbis_block *,vorbis_look_floor *,
  97247. void *buffer,float *);
  97248. } vorbis_func_floor;
  97249. typedef struct{
  97250. int order;
  97251. long rate;
  97252. long barkmap;
  97253. int ampbits;
  97254. int ampdB;
  97255. int numbooks; /* <= 16 */
  97256. int books[16];
  97257. float lessthan; /* encode-only config setting hacks for libvorbis */
  97258. float greaterthan; /* encode-only config setting hacks for libvorbis */
  97259. } vorbis_info_floor0;
  97260. #define VIF_POSIT 63
  97261. #define VIF_CLASS 16
  97262. #define VIF_PARTS 31
  97263. typedef struct{
  97264. int partitions; /* 0 to 31 */
  97265. int partitionclass[VIF_PARTS]; /* 0 to 15 */
  97266. int class_dim[VIF_CLASS]; /* 1 to 8 */
  97267. int class_subs[VIF_CLASS]; /* 0,1,2,3 (bits: 1<<n poss) */
  97268. int class_book[VIF_CLASS]; /* subs ^ dim entries */
  97269. int class_subbook[VIF_CLASS][8]; /* [VIF_CLASS][subs] */
  97270. int mult; /* 1 2 3 or 4 */
  97271. int postlist[VIF_POSIT+2]; /* first two implicit */
  97272. float maxover;
  97273. float maxunder;
  97274. float maxerr;
  97275. float twofitweight;
  97276. float twofitatten;
  97277. int n;
  97278. } vorbis_info_floor1;
  97279. typedef struct{
  97280. void (*pack) (vorbis_info_residue *,oggpack_buffer *);
  97281. vorbis_info_residue *(*unpack)(vorbis_info *,oggpack_buffer *);
  97282. vorbis_look_residue *(*look) (vorbis_dsp_state *,
  97283. vorbis_info_residue *);
  97284. void (*free_info) (vorbis_info_residue *);
  97285. void (*free_look) (vorbis_look_residue *);
  97286. long **(*classx) (struct vorbis_block *,vorbis_look_residue *,
  97287. float **,int *,int);
  97288. int (*forward) (oggpack_buffer *,struct vorbis_block *,
  97289. vorbis_look_residue *,
  97290. float **,float **,int *,int,long **);
  97291. int (*inverse) (struct vorbis_block *,vorbis_look_residue *,
  97292. float **,int *,int);
  97293. } vorbis_func_residue;
  97294. typedef struct vorbis_info_residue0{
  97295. long begin;
  97296. long end;
  97297. int grouping; /* group n vectors per partition */
  97298. int partitions; /* possible codebooks for a partition */
  97299. int groupbook; /* huffbook for partitioning */
  97300. int secondstages[64]; /* expanded out to pointers in lookup */
  97301. int booklist[256]; /* list of second stage books */
  97302. float classmetric1[64];
  97303. float classmetric2[64];
  97304. } vorbis_info_residue0;
  97305. typedef struct{
  97306. void (*pack) (vorbis_info *,vorbis_info_mapping *,
  97307. oggpack_buffer *);
  97308. vorbis_info_mapping *(*unpack)(vorbis_info *,oggpack_buffer *);
  97309. void (*free_info) (vorbis_info_mapping *);
  97310. int (*forward) (struct vorbis_block *vb);
  97311. int (*inverse) (struct vorbis_block *vb,vorbis_info_mapping *);
  97312. } vorbis_func_mapping;
  97313. typedef struct vorbis_info_mapping0{
  97314. int submaps; /* <= 16 */
  97315. int chmuxlist[256]; /* up to 256 channels in a Vorbis stream */
  97316. int floorsubmap[16]; /* [mux] submap to floors */
  97317. int residuesubmap[16]; /* [mux] submap to residue */
  97318. int coupling_steps;
  97319. int coupling_mag[256];
  97320. int coupling_ang[256];
  97321. } vorbis_info_mapping0;
  97322. #endif
  97323. /*** End of inlined file: backends.h ***/
  97324. #ifndef EHMER_MAX
  97325. #define EHMER_MAX 56
  97326. #endif
  97327. #define P_BANDS 17 /* 62Hz to 16kHz */
  97328. #define P_LEVELS 8 /* 30dB to 100dB */
  97329. #define P_LEVEL_0 30. /* 30 dB */
  97330. #define P_NOISECURVES 3
  97331. #define NOISE_COMPAND_LEVELS 40
  97332. typedef struct vorbis_info_psy{
  97333. int blockflag;
  97334. float ath_adjatt;
  97335. float ath_maxatt;
  97336. float tone_masteratt[P_NOISECURVES];
  97337. float tone_centerboost;
  97338. float tone_decay;
  97339. float tone_abs_limit;
  97340. float toneatt[P_BANDS];
  97341. int noisemaskp;
  97342. float noisemaxsupp;
  97343. float noisewindowlo;
  97344. float noisewindowhi;
  97345. int noisewindowlomin;
  97346. int noisewindowhimin;
  97347. int noisewindowfixed;
  97348. float noiseoff[P_NOISECURVES][P_BANDS];
  97349. float noisecompand[NOISE_COMPAND_LEVELS];
  97350. float max_curve_dB;
  97351. int normal_channel_p;
  97352. int normal_point_p;
  97353. int normal_start;
  97354. int normal_partition;
  97355. double normal_thresh;
  97356. } vorbis_info_psy;
  97357. typedef struct{
  97358. int eighth_octave_lines;
  97359. float preecho_thresh[VE_BANDS];
  97360. float postecho_thresh[VE_BANDS];
  97361. float stretch_penalty;
  97362. float preecho_minenergy;
  97363. float ampmax_att_per_sec;
  97364. int coupling_pkHz[PACKETBLOBS];
  97365. int coupling_pointlimit[2][PACKETBLOBS];
  97366. int coupling_prepointamp[PACKETBLOBS];
  97367. int coupling_postpointamp[PACKETBLOBS];
  97368. int sliding_lowpass[2][PACKETBLOBS];
  97369. } vorbis_info_psy_global;
  97370. typedef struct {
  97371. float ampmax;
  97372. int channels;
  97373. vorbis_info_psy_global *gi;
  97374. int coupling_pointlimit[2][P_NOISECURVES];
  97375. } vorbis_look_psy_global;
  97376. typedef struct {
  97377. int n;
  97378. struct vorbis_info_psy *vi;
  97379. float ***tonecurves;
  97380. float **noiseoffset;
  97381. float *ath;
  97382. long *octave; /* in n.ocshift format */
  97383. long *bark;
  97384. long firstoc;
  97385. long shiftoc;
  97386. int eighth_octave_lines; /* power of two, please */
  97387. int total_octave_lines;
  97388. long rate; /* cache it */
  97389. float m_val; /* Masking compensation value */
  97390. } vorbis_look_psy;
  97391. extern void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  97392. vorbis_info_psy_global *gi,int n,long rate);
  97393. extern void _vp_psy_clear(vorbis_look_psy *p);
  97394. extern void *_vi_psy_dup(void *source);
  97395. extern void _vi_psy_free(vorbis_info_psy *i);
  97396. extern vorbis_info_psy *_vi_psy_copy(vorbis_info_psy *i);
  97397. extern void _vp_remove_floor(vorbis_look_psy *p,
  97398. float *mdct,
  97399. int *icodedflr,
  97400. float *residue,
  97401. int sliding_lowpass);
  97402. extern void _vp_noisemask(vorbis_look_psy *p,
  97403. float *logmdct,
  97404. float *logmask);
  97405. extern void _vp_tonemask(vorbis_look_psy *p,
  97406. float *logfft,
  97407. float *logmask,
  97408. float global_specmax,
  97409. float local_specmax);
  97410. extern void _vp_offset_and_mix(vorbis_look_psy *p,
  97411. float *noise,
  97412. float *tone,
  97413. int offset_select,
  97414. float *logmask,
  97415. float *mdct,
  97416. float *logmdct);
  97417. extern float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd);
  97418. extern float **_vp_quantize_couple_memo(vorbis_block *vb,
  97419. vorbis_info_psy_global *g,
  97420. vorbis_look_psy *p,
  97421. vorbis_info_mapping0 *vi,
  97422. float **mdct);
  97423. extern void _vp_couple(int blobno,
  97424. vorbis_info_psy_global *g,
  97425. vorbis_look_psy *p,
  97426. vorbis_info_mapping0 *vi,
  97427. float **res,
  97428. float **mag_memo,
  97429. int **mag_sort,
  97430. int **ifloor,
  97431. int *nonzero,
  97432. int sliding_lowpass);
  97433. extern void _vp_noise_normalize(vorbis_look_psy *p,
  97434. float *in,float *out,int *sortedindex);
  97435. extern void _vp_noise_normalize_sort(vorbis_look_psy *p,
  97436. float *magnitudes,int *sortedindex);
  97437. extern int **_vp_quantize_couple_sort(vorbis_block *vb,
  97438. vorbis_look_psy *p,
  97439. vorbis_info_mapping0 *vi,
  97440. float **mags);
  97441. extern void hf_reduction(vorbis_info_psy_global *g,
  97442. vorbis_look_psy *p,
  97443. vorbis_info_mapping0 *vi,
  97444. float **mdct);
  97445. #endif
  97446. /*** End of inlined file: psy.h ***/
  97447. /*** Start of inlined file: bitrate.h ***/
  97448. #ifndef _V_BITRATE_H_
  97449. #define _V_BITRATE_H_
  97450. /*** Start of inlined file: os.h ***/
  97451. #ifndef _OS_H
  97452. #define _OS_H
  97453. #ifdef HAVE_CONFIG_H
  97454. #include "config.h"
  97455. #endif
  97456. #include <math.h>
  97457. /*** Start of inlined file: misc.h ***/
  97458. #ifndef _V_RANDOM_H_
  97459. #define _V_RANDOM_H_
  97460. extern int analysis_noisy;
  97461. extern void *_vorbis_block_alloc(vorbis_block *vb,long bytes);
  97462. extern void _vorbis_block_ripcord(vorbis_block *vb);
  97463. extern void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97464. ogg_int64_t off);
  97465. #ifdef DEBUG_MALLOC
  97466. #define _VDBG_GRAPHFILE "malloc.m"
  97467. extern void *_VDBG_malloc(void *ptr,long bytes,char *file,long line);
  97468. extern void _VDBG_free(void *ptr,char *file,long line);
  97469. #ifndef MISC_C
  97470. #undef _ogg_malloc
  97471. #undef _ogg_calloc
  97472. #undef _ogg_realloc
  97473. #undef _ogg_free
  97474. #define _ogg_malloc(x) _VDBG_malloc(NULL,(x),__FILE__,__LINE__)
  97475. #define _ogg_calloc(x,y) _VDBG_malloc(NULL,(x)*(y),__FILE__,__LINE__)
  97476. #define _ogg_realloc(x,y) _VDBG_malloc((x),(y),__FILE__,__LINE__)
  97477. #define _ogg_free(x) _VDBG_free((x),__FILE__,__LINE__)
  97478. #endif
  97479. #endif
  97480. #endif
  97481. /*** End of inlined file: misc.h ***/
  97482. #ifndef _V_IFDEFJAIL_H_
  97483. # define _V_IFDEFJAIL_H_
  97484. # ifdef __GNUC__
  97485. # define STIN static __inline__
  97486. # elif _WIN32
  97487. # define STIN static __inline
  97488. # else
  97489. # define STIN static
  97490. # endif
  97491. #ifdef DJGPP
  97492. # define rint(x) (floor((x)+0.5f))
  97493. #endif
  97494. #ifndef M_PI
  97495. # define M_PI (3.1415926536f)
  97496. #endif
  97497. #if defined(_WIN32) && !defined(__SYMBIAN32__)
  97498. # include <malloc.h>
  97499. # define rint(x) (floor((x)+0.5f))
  97500. # define NO_FLOAT_MATH_LIB
  97501. # define FAST_HYPOT(a, b) sqrt((a)*(a) + (b)*(b))
  97502. #endif
  97503. #if defined(__SYMBIAN32__) && defined(__WINS__)
  97504. void *_alloca(size_t size);
  97505. # define alloca _alloca
  97506. #endif
  97507. #ifndef FAST_HYPOT
  97508. # define FAST_HYPOT hypot
  97509. #endif
  97510. #endif
  97511. #ifdef HAVE_ALLOCA_H
  97512. # include <alloca.h>
  97513. #endif
  97514. #ifdef USE_MEMORY_H
  97515. # include <memory.h>
  97516. #endif
  97517. #ifndef min
  97518. # define min(x,y) ((x)>(y)?(y):(x))
  97519. #endif
  97520. #ifndef max
  97521. # define max(x,y) ((x)<(y)?(y):(x))
  97522. #endif
  97523. #if defined(__i386__) && defined(__GNUC__) && !defined(__BEOS__)
  97524. # define VORBIS_FPU_CONTROL
  97525. typedef ogg_int16_t vorbis_fpu_control;
  97526. static inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97527. ogg_int16_t ret;
  97528. ogg_int16_t temp;
  97529. __asm__ __volatile__("fnstcw %0\n\t"
  97530. "movw %0,%%dx\n\t"
  97531. "orw $62463,%%dx\n\t"
  97532. "movw %%dx,%1\n\t"
  97533. "fldcw %1\n\t":"=m"(ret):"m"(temp): "dx");
  97534. *fpu=ret;
  97535. }
  97536. static inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97537. __asm__ __volatile__("fldcw %0":: "m"(fpu));
  97538. }
  97539. static inline int vorbis_ftoi(double f){ /* yes, double! Otherwise,
  97540. we get extra fst/fld to
  97541. truncate precision */
  97542. int i;
  97543. __asm__("fistl %0": "=m"(i) : "t"(f));
  97544. return(i);
  97545. }
  97546. #endif
  97547. #if defined(_WIN32) && defined(_X86_) && !defined(__GNUC__) && !defined(__BORLANDC__)
  97548. # define VORBIS_FPU_CONTROL
  97549. typedef ogg_int16_t vorbis_fpu_control;
  97550. static __inline int vorbis_ftoi(double f){
  97551. int i;
  97552. __asm{
  97553. fld f
  97554. fistp i
  97555. }
  97556. return i;
  97557. }
  97558. static __inline void vorbis_fpu_setround(vorbis_fpu_control *fpu){
  97559. }
  97560. static __inline void vorbis_fpu_restore(vorbis_fpu_control fpu){
  97561. }
  97562. #endif
  97563. #ifndef VORBIS_FPU_CONTROL
  97564. typedef int vorbis_fpu_control;
  97565. static int vorbis_ftoi(double f){
  97566. return (int)(f+.5);
  97567. }
  97568. # define vorbis_fpu_setround(vorbis_fpu_control) {}
  97569. # define vorbis_fpu_restore(vorbis_fpu_control) {}
  97570. #endif
  97571. #endif /* _OS_H */
  97572. /*** End of inlined file: os.h ***/
  97573. typedef struct bitrate_manager_state {
  97574. int managed;
  97575. long avg_reservoir;
  97576. long minmax_reservoir;
  97577. long avg_bitsper;
  97578. long min_bitsper;
  97579. long max_bitsper;
  97580. long short_per_long;
  97581. double avgfloat;
  97582. vorbis_block *vb;
  97583. int choice;
  97584. } bitrate_manager_state;
  97585. typedef struct bitrate_manager_info{
  97586. long avg_rate;
  97587. long min_rate;
  97588. long max_rate;
  97589. long reservoir_bits;
  97590. double reservoir_bias;
  97591. double slew_damp;
  97592. } bitrate_manager_info;
  97593. extern void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bs);
  97594. extern void vorbis_bitrate_clear(bitrate_manager_state *bs);
  97595. extern int vorbis_bitrate_managed(vorbis_block *vb);
  97596. extern int vorbis_bitrate_addblock(vorbis_block *vb);
  97597. extern int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd, ogg_packet *op);
  97598. #endif
  97599. /*** End of inlined file: bitrate.h ***/
  97600. static int ilog(unsigned int v){
  97601. int ret=0;
  97602. while(v){
  97603. ret++;
  97604. v>>=1;
  97605. }
  97606. return(ret);
  97607. }
  97608. static int ilog2(unsigned int v){
  97609. int ret=0;
  97610. if(v)--v;
  97611. while(v){
  97612. ret++;
  97613. v>>=1;
  97614. }
  97615. return(ret);
  97616. }
  97617. typedef struct private_state {
  97618. envelope_lookup *ve; /* envelope lookup */
  97619. int window[2];
  97620. vorbis_look_transform **transform[2]; /* block, type */
  97621. drft_lookup fft_look[2];
  97622. int modebits;
  97623. vorbis_look_floor **flr;
  97624. vorbis_look_residue **residue;
  97625. vorbis_look_psy *psy;
  97626. vorbis_look_psy_global *psy_g_look;
  97627. unsigned char *header;
  97628. unsigned char *header1;
  97629. unsigned char *header2;
  97630. bitrate_manager_state bms;
  97631. ogg_int64_t sample_count;
  97632. } private_state;
  97633. /*** Start of inlined file: highlevel.h ***/
  97634. typedef struct highlevel_byblocktype {
  97635. double tone_mask_setting;
  97636. double tone_peaklimit_setting;
  97637. double noise_bias_setting;
  97638. double noise_compand_setting;
  97639. } highlevel_byblocktype;
  97640. typedef struct highlevel_encode_setup {
  97641. void *setup;
  97642. int set_in_stone;
  97643. double base_setting;
  97644. double long_setting;
  97645. double short_setting;
  97646. double impulse_noisetune;
  97647. int managed;
  97648. long bitrate_min;
  97649. long bitrate_av;
  97650. double bitrate_av_damp;
  97651. long bitrate_max;
  97652. long bitrate_reservoir;
  97653. double bitrate_reservoir_bias;
  97654. int impulse_block_p;
  97655. int noise_normalize_p;
  97656. double stereo_point_setting;
  97657. double lowpass_kHz;
  97658. double ath_floating_dB;
  97659. double ath_absolute_dB;
  97660. double amplitude_track_dBpersec;
  97661. double trigger_setting;
  97662. highlevel_byblocktype block[4]; /* padding, impulse, transition, long */
  97663. } highlevel_encode_setup;
  97664. /*** End of inlined file: highlevel.h ***/
  97665. typedef struct codec_setup_info {
  97666. long blocksizes[2];
  97667. int modes;
  97668. int maps;
  97669. int floors;
  97670. int residues;
  97671. int books;
  97672. int psys; /* encode only */
  97673. vorbis_info_mode *mode_param[64];
  97674. int map_type[64];
  97675. vorbis_info_mapping *map_param[64];
  97676. int floor_type[64];
  97677. vorbis_info_floor *floor_param[64];
  97678. int residue_type[64];
  97679. vorbis_info_residue *residue_param[64];
  97680. static_codebook *book_param[256];
  97681. codebook *fullbooks;
  97682. vorbis_info_psy *psy_param[4]; /* encode only */
  97683. vorbis_info_psy_global psy_g_param;
  97684. bitrate_manager_info bi;
  97685. highlevel_encode_setup hi; /* used only by vorbisenc.c. It's a
  97686. highly redundant structure, but
  97687. improves clarity of program flow. */
  97688. int halfrate_flag; /* painless downsample for decode */
  97689. } codec_setup_info;
  97690. extern vorbis_look_psy_global *_vp_global_look(vorbis_info *vi);
  97691. extern void _vp_global_free(vorbis_look_psy_global *look);
  97692. #endif
  97693. /*** End of inlined file: codec_internal.h ***/
  97694. /*** Start of inlined file: registry.h ***/
  97695. #ifndef _V_REG_H_
  97696. #define _V_REG_H_
  97697. #define VI_TRANSFORMB 1
  97698. #define VI_WINDOWB 1
  97699. #define VI_TIMEB 1
  97700. #define VI_FLOORB 2
  97701. #define VI_RESB 3
  97702. #define VI_MAPB 1
  97703. extern vorbis_func_floor *_floor_P[];
  97704. extern vorbis_func_residue *_residue_P[];
  97705. extern vorbis_func_mapping *_mapping_P[];
  97706. #endif
  97707. /*** End of inlined file: registry.h ***/
  97708. /*** Start of inlined file: scales.h ***/
  97709. #ifndef _V_SCALES_H_
  97710. #define _V_SCALES_H_
  97711. #include <math.h>
  97712. #define VORBIS_IEEE_FLOAT32 1
  97713. #ifdef VORBIS_IEEE_FLOAT32
  97714. static float unitnorm(float x){
  97715. union {
  97716. ogg_uint32_t i;
  97717. float f;
  97718. } ix;
  97719. ix.f = x;
  97720. ix.i = (ix.i & 0x80000000U) | (0x3f800000U);
  97721. return ix.f;
  97722. }
  97723. static float todB(const float *x){
  97724. union {
  97725. ogg_uint32_t i;
  97726. float f;
  97727. } ix;
  97728. ix.f = *x;
  97729. ix.i = ix.i&0x7fffffff;
  97730. return (float)(ix.i * 7.17711438e-7f -764.6161886f);
  97731. }
  97732. #define todB_nn(x) todB(x)
  97733. #else
  97734. static float unitnorm(float x){
  97735. if(x<0)return(-1.f);
  97736. return(1.f);
  97737. }
  97738. #define todB(x) (*(x)==0?-400.f:log(*(x)**(x))*4.34294480f)
  97739. #define todB_nn(x) (*(x)==0.f?-400.f:log(*(x))*8.6858896f)
  97740. #endif
  97741. #define fromdB(x) (exp((x)*.11512925f))
  97742. #define toBARK(n) (13.1f*atan(.00074f*(n))+2.24f*atan((n)*(n)*1.85e-8f)+1e-4f*(n))
  97743. #define fromBARK(z) (102.f*(z)-2.f*pow(z,2.f)+.4f*pow(z,3.f)+pow(1.46f,z)-1.f)
  97744. #define toMEL(n) (log(1.f+(n)*.001f)*1442.695f)
  97745. #define fromMEL(m) (1000.f*exp((m)/1442.695f)-1000.f)
  97746. #define toOC(n) (log(n)*1.442695f-5.965784f)
  97747. #define fromOC(o) (exp(((o)+5.965784f)*.693147f))
  97748. #endif
  97749. /*** End of inlined file: scales.h ***/
  97750. int analysis_noisy=1;
  97751. int vorbis_analysis(vorbis_block *vb, ogg_packet *op){
  97752. int ret,i;
  97753. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  97754. vb->glue_bits=0;
  97755. vb->time_bits=0;
  97756. vb->floor_bits=0;
  97757. vb->res_bits=0;
  97758. for(i=0;i<PACKETBLOBS;i++)
  97759. oggpack_reset(vbi->packetblob[i]);
  97760. if((ret=_mapping_P[0]->forward(vb)))
  97761. return(ret);
  97762. if(op){
  97763. if(vorbis_bitrate_managed(vb))
  97764. return(OV_EINVAL);
  97765. op->packet=oggpack_get_buffer(&vb->opb);
  97766. op->bytes=oggpack_bytes(&vb->opb);
  97767. op->b_o_s=0;
  97768. op->e_o_s=vb->eofflag;
  97769. op->granulepos=vb->granulepos;
  97770. op->packetno=vb->sequence; /* for sake of completeness */
  97771. }
  97772. return(0);
  97773. }
  97774. void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,ogg_int64_t off){
  97775. int j;
  97776. FILE *of;
  97777. char buffer[80];
  97778. sprintf(buffer,"%s_%d.m",base,i);
  97779. of=fopen(buffer,"w");
  97780. if(!of)perror("failed to open data dump file");
  97781. for(j=0;j<n;j++){
  97782. if(bark){
  97783. float b=toBARK((4000.f*j/n)+.25);
  97784. fprintf(of,"%f ",b);
  97785. }else
  97786. if(off!=0)
  97787. fprintf(of,"%f ",(double)(j+off)/8000.);
  97788. else
  97789. fprintf(of,"%f ",(double)j);
  97790. if(dB){
  97791. float val;
  97792. if(v[j]==0.)
  97793. val=-140.;
  97794. else
  97795. val=todB(v+j);
  97796. fprintf(of,"%f\n",val);
  97797. }else{
  97798. fprintf(of,"%f\n",v[j]);
  97799. }
  97800. }
  97801. fclose(of);
  97802. }
  97803. void _analysis_output(char *base,int i,float *v,int n,int bark,int dB,
  97804. ogg_int64_t off){
  97805. if(analysis_noisy)_analysis_output_always(base,i,v,n,bark,dB,off);
  97806. }
  97807. #endif
  97808. /*** End of inlined file: analysis.c ***/
  97809. /*** Start of inlined file: bitrate.c ***/
  97810. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97811. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97812. // tasks..
  97813. #if JUCE_MSVC
  97814. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97815. #endif
  97816. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97817. #if JUCE_USE_OGGVORBIS
  97818. #include <stdlib.h>
  97819. #include <string.h>
  97820. #include <math.h>
  97821. void vorbis_bitrate_init(vorbis_info *vi,bitrate_manager_state *bm){
  97822. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  97823. bitrate_manager_info *bi=&ci->bi;
  97824. memset(bm,0,sizeof(*bm));
  97825. if(bi && (bi->reservoir_bits>0)){
  97826. long ratesamples=vi->rate;
  97827. int halfsamples=ci->blocksizes[0]>>1;
  97828. bm->short_per_long=ci->blocksizes[1]/ci->blocksizes[0];
  97829. bm->managed=1;
  97830. bm->avg_bitsper= rint(1.*bi->avg_rate*halfsamples/ratesamples);
  97831. bm->min_bitsper= rint(1.*bi->min_rate*halfsamples/ratesamples);
  97832. bm->max_bitsper= rint(1.*bi->max_rate*halfsamples/ratesamples);
  97833. bm->avgfloat=PACKETBLOBS/2;
  97834. {
  97835. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97836. bm->minmax_reservoir=desired_fill;
  97837. bm->avg_reservoir=desired_fill;
  97838. }
  97839. }
  97840. }
  97841. void vorbis_bitrate_clear(bitrate_manager_state *bm){
  97842. memset(bm,0,sizeof(*bm));
  97843. return;
  97844. }
  97845. int vorbis_bitrate_managed(vorbis_block *vb){
  97846. vorbis_dsp_state *vd=vb->vd;
  97847. private_state *b=(private_state*)vd->backend_state;
  97848. bitrate_manager_state *bm=&b->bms;
  97849. if(bm && bm->managed)return(1);
  97850. return(0);
  97851. }
  97852. int vorbis_bitrate_addblock(vorbis_block *vb){
  97853. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97854. vorbis_dsp_state *vd=vb->vd;
  97855. private_state *b=(private_state*)vd->backend_state;
  97856. bitrate_manager_state *bm=&b->bms;
  97857. vorbis_info *vi=vd->vi;
  97858. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  97859. bitrate_manager_info *bi=&ci->bi;
  97860. int choice=rint(bm->avgfloat);
  97861. long this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97862. long min_target_bits=(vb->W?bm->min_bitsper*bm->short_per_long:bm->min_bitsper);
  97863. long max_target_bits=(vb->W?bm->max_bitsper*bm->short_per_long:bm->max_bitsper);
  97864. int samples=ci->blocksizes[vb->W]>>1;
  97865. long desired_fill=bi->reservoir_bits*bi->reservoir_bias;
  97866. if(!bm->managed){
  97867. if(bm->vb)return(-1); /* one has been submitted without
  97868. being claimed */
  97869. bm->vb=vb;
  97870. return(0);
  97871. }
  97872. bm->vb=vb;
  97873. if(bm->avg_bitsper>0){
  97874. double slew=0.;
  97875. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97876. double slewlimit= 15./bi->slew_damp;
  97877. if(bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97878. while(choice>0 && this_bits>avg_target_bits &&
  97879. bm->avg_reservoir+(this_bits-avg_target_bits)>desired_fill){
  97880. choice--;
  97881. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97882. }
  97883. }else if(bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97884. while(choice+1<PACKETBLOBS && this_bits<avg_target_bits &&
  97885. bm->avg_reservoir+(this_bits-avg_target_bits)<desired_fill){
  97886. choice++;
  97887. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97888. }
  97889. }
  97890. slew=rint(choice-bm->avgfloat)/samples*vi->rate;
  97891. if(slew<-slewlimit)slew=-slewlimit;
  97892. if(slew>slewlimit)slew=slewlimit;
  97893. choice=rint(bm->avgfloat+= slew/vi->rate*samples);
  97894. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97895. }
  97896. if(bm->min_bitsper>0){
  97897. if(this_bits<min_target_bits){
  97898. while(bm->minmax_reservoir-(min_target_bits-this_bits)<0){
  97899. choice++;
  97900. if(choice>=PACKETBLOBS)break;
  97901. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97902. }
  97903. }
  97904. }
  97905. if(bm->max_bitsper>0){
  97906. if(this_bits>max_target_bits){
  97907. while(bm->minmax_reservoir+(this_bits-max_target_bits)>bi->reservoir_bits){
  97908. choice--;
  97909. if(choice<0)break;
  97910. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97911. }
  97912. }
  97913. }
  97914. if(choice<0){
  97915. long maxsize=(max_target_bits+(bi->reservoir_bits-bm->minmax_reservoir))/8;
  97916. bm->choice=choice=0;
  97917. if(oggpack_bytes(vbi->packetblob[choice])>maxsize){
  97918. oggpack_writetrunc(vbi->packetblob[choice],maxsize*8);
  97919. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97920. }
  97921. }else{
  97922. long minsize=(min_target_bits-bm->minmax_reservoir+7)/8;
  97923. if(choice>=PACKETBLOBS)
  97924. choice=PACKETBLOBS-1;
  97925. bm->choice=choice;
  97926. minsize-=oggpack_bytes(vbi->packetblob[choice]);
  97927. while(minsize-->0)oggpack_write(vbi->packetblob[choice],0,8);
  97928. this_bits=oggpack_bytes(vbi->packetblob[choice])*8;
  97929. }
  97930. if(bm->min_bitsper>0 || bm->max_bitsper>0){
  97931. if(max_target_bits>0 && this_bits>max_target_bits){
  97932. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97933. }else if(min_target_bits>0 && this_bits<min_target_bits){
  97934. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97935. }else{
  97936. if(bm->minmax_reservoir>desired_fill){
  97937. if(max_target_bits>0){ /* logical bulletproofing against initialization state */
  97938. bm->minmax_reservoir+=(this_bits-max_target_bits);
  97939. if(bm->minmax_reservoir<desired_fill)bm->minmax_reservoir=desired_fill;
  97940. }else{
  97941. bm->minmax_reservoir=desired_fill;
  97942. }
  97943. }else{
  97944. if(min_target_bits>0){ /* logical bulletproofing against initialization state */
  97945. bm->minmax_reservoir+=(this_bits-min_target_bits);
  97946. if(bm->minmax_reservoir>desired_fill)bm->minmax_reservoir=desired_fill;
  97947. }else{
  97948. bm->minmax_reservoir=desired_fill;
  97949. }
  97950. }
  97951. }
  97952. }
  97953. if(bm->avg_bitsper>0){
  97954. long avg_target_bits=(vb->W?bm->avg_bitsper*bm->short_per_long:bm->avg_bitsper);
  97955. bm->avg_reservoir+=this_bits-avg_target_bits;
  97956. }
  97957. return(0);
  97958. }
  97959. int vorbis_bitrate_flushpacket(vorbis_dsp_state *vd,ogg_packet *op){
  97960. private_state *b=(private_state*)vd->backend_state;
  97961. bitrate_manager_state *bm=&b->bms;
  97962. vorbis_block *vb=bm->vb;
  97963. int choice=PACKETBLOBS/2;
  97964. if(!vb)return 0;
  97965. if(op){
  97966. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  97967. if(vorbis_bitrate_managed(vb))
  97968. choice=bm->choice;
  97969. op->packet=oggpack_get_buffer(vbi->packetblob[choice]);
  97970. op->bytes=oggpack_bytes(vbi->packetblob[choice]);
  97971. op->b_o_s=0;
  97972. op->e_o_s=vb->eofflag;
  97973. op->granulepos=vb->granulepos;
  97974. op->packetno=vb->sequence; /* for sake of completeness */
  97975. }
  97976. bm->vb=0;
  97977. return(1);
  97978. }
  97979. #endif
  97980. /*** End of inlined file: bitrate.c ***/
  97981. /*** Start of inlined file: block.c ***/
  97982. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  97983. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  97984. // tasks..
  97985. #if JUCE_MSVC
  97986. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  97987. #endif
  97988. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  97989. #if JUCE_USE_OGGVORBIS
  97990. #include <stdio.h>
  97991. #include <stdlib.h>
  97992. #include <string.h>
  97993. /*** Start of inlined file: window.h ***/
  97994. #ifndef _V_WINDOW_
  97995. #define _V_WINDOW_
  97996. extern float *_vorbis_window_get(int n);
  97997. extern void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  97998. int lW,int W,int nW);
  97999. #endif
  98000. /*** End of inlined file: window.h ***/
  98001. /*** Start of inlined file: lpc.h ***/
  98002. #ifndef _V_LPC_H_
  98003. #define _V_LPC_H_
  98004. extern float vorbis_lpc_from_data(float *data,float *lpc,int n,int m);
  98005. extern void vorbis_lpc_predict(float *coeff,float *prime,int m,
  98006. float *data,long n);
  98007. #endif
  98008. /*** End of inlined file: lpc.h ***/
  98009. #ifndef WORD_ALIGN
  98010. #define WORD_ALIGN 8
  98011. #endif
  98012. int vorbis_block_init(vorbis_dsp_state *v, vorbis_block *vb){
  98013. int i;
  98014. memset(vb,0,sizeof(*vb));
  98015. vb->vd=v;
  98016. vb->localalloc=0;
  98017. vb->localstore=NULL;
  98018. if(v->analysisp){
  98019. vorbis_block_internal *vbi=(vorbis_block_internal*)
  98020. (vb->internal=(vorbis_block_internal*)_ogg_calloc(1,sizeof(vorbis_block_internal)));
  98021. vbi->ampmax=-9999;
  98022. for(i=0;i<PACKETBLOBS;i++){
  98023. if(i==PACKETBLOBS/2){
  98024. vbi->packetblob[i]=&vb->opb;
  98025. }else{
  98026. vbi->packetblob[i]=
  98027. (oggpack_buffer*) _ogg_calloc(1,sizeof(oggpack_buffer));
  98028. }
  98029. oggpack_writeinit(vbi->packetblob[i]);
  98030. }
  98031. }
  98032. return(0);
  98033. }
  98034. void *_vorbis_block_alloc(vorbis_block *vb,long bytes){
  98035. bytes=(bytes+(WORD_ALIGN-1)) & ~(WORD_ALIGN-1);
  98036. if(bytes+vb->localtop>vb->localalloc){
  98037. if(vb->localstore){
  98038. struct alloc_chain *link=(struct alloc_chain*)_ogg_malloc(sizeof(*link));
  98039. vb->totaluse+=vb->localtop;
  98040. link->next=vb->reap;
  98041. link->ptr=vb->localstore;
  98042. vb->reap=link;
  98043. }
  98044. vb->localalloc=bytes;
  98045. vb->localstore=_ogg_malloc(vb->localalloc);
  98046. vb->localtop=0;
  98047. }
  98048. {
  98049. void *ret=(void *)(((char *)vb->localstore)+vb->localtop);
  98050. vb->localtop+=bytes;
  98051. return ret;
  98052. }
  98053. }
  98054. void _vorbis_block_ripcord(vorbis_block *vb){
  98055. struct alloc_chain *reap=vb->reap;
  98056. while(reap){
  98057. struct alloc_chain *next=reap->next;
  98058. _ogg_free(reap->ptr);
  98059. memset(reap,0,sizeof(*reap));
  98060. _ogg_free(reap);
  98061. reap=next;
  98062. }
  98063. if(vb->totaluse){
  98064. vb->localstore=_ogg_realloc(vb->localstore,vb->totaluse+vb->localalloc);
  98065. vb->localalloc+=vb->totaluse;
  98066. vb->totaluse=0;
  98067. }
  98068. vb->localtop=0;
  98069. vb->reap=NULL;
  98070. }
  98071. int vorbis_block_clear(vorbis_block *vb){
  98072. int i;
  98073. vorbis_block_internal *vbi=(vorbis_block_internal*)vb->internal;
  98074. _vorbis_block_ripcord(vb);
  98075. if(vb->localstore)_ogg_free(vb->localstore);
  98076. if(vbi){
  98077. for(i=0;i<PACKETBLOBS;i++){
  98078. oggpack_writeclear(vbi->packetblob[i]);
  98079. if(i!=PACKETBLOBS/2)_ogg_free(vbi->packetblob[i]);
  98080. }
  98081. _ogg_free(vbi);
  98082. }
  98083. memset(vb,0,sizeof(*vb));
  98084. return(0);
  98085. }
  98086. static int _vds_shared_init(vorbis_dsp_state *v,vorbis_info *vi,int encp){
  98087. int i;
  98088. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98089. private_state *b=NULL;
  98090. int hs;
  98091. if(ci==NULL) return 1;
  98092. hs=ci->halfrate_flag;
  98093. memset(v,0,sizeof(*v));
  98094. b=(private_state*) (v->backend_state=(private_state*)_ogg_calloc(1,sizeof(*b)));
  98095. v->vi=vi;
  98096. b->modebits=ilog2(ci->modes);
  98097. b->transform[0]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[0]));
  98098. b->transform[1]=(vorbis_look_transform**)_ogg_calloc(VI_TRANSFORMB,sizeof(*b->transform[1]));
  98099. b->transform[0][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  98100. b->transform[1][0]=_ogg_calloc(1,sizeof(mdct_lookup));
  98101. mdct_init((mdct_lookup*)b->transform[0][0],ci->blocksizes[0]>>hs);
  98102. mdct_init((mdct_lookup*)b->transform[1][0],ci->blocksizes[1]>>hs);
  98103. b->window[0]=ilog2(ci->blocksizes[0])-6;
  98104. b->window[1]=ilog2(ci->blocksizes[1])-6;
  98105. if(encp){ /* encode/decode differ here */
  98106. drft_init(&b->fft_look[0],ci->blocksizes[0]);
  98107. drft_init(&b->fft_look[1],ci->blocksizes[1]);
  98108. if(!ci->fullbooks){
  98109. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  98110. for(i=0;i<ci->books;i++)
  98111. vorbis_book_init_encode(ci->fullbooks+i,ci->book_param[i]);
  98112. }
  98113. b->psy=(vorbis_look_psy*)_ogg_calloc(ci->psys,sizeof(*b->psy));
  98114. for(i=0;i<ci->psys;i++){
  98115. _vp_psy_init(b->psy+i,
  98116. ci->psy_param[i],
  98117. &ci->psy_g_param,
  98118. ci->blocksizes[ci->psy_param[i]->blockflag]/2,
  98119. vi->rate);
  98120. }
  98121. v->analysisp=1;
  98122. }else{
  98123. if(!ci->fullbooks){
  98124. ci->fullbooks=(codebook*) _ogg_calloc(ci->books,sizeof(*ci->fullbooks));
  98125. for(i=0;i<ci->books;i++){
  98126. vorbis_book_init_decode(ci->fullbooks+i,ci->book_param[i]);
  98127. vorbis_staticbook_destroy(ci->book_param[i]);
  98128. ci->book_param[i]=NULL;
  98129. }
  98130. }
  98131. }
  98132. v->pcm_storage=ci->blocksizes[1];
  98133. v->pcm=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcm));
  98134. v->pcmret=(float**)_ogg_malloc(vi->channels*sizeof(*v->pcmret));
  98135. {
  98136. int i;
  98137. for(i=0;i<vi->channels;i++)
  98138. v->pcm[i]=(float*)_ogg_calloc(v->pcm_storage,sizeof(*v->pcm[i]));
  98139. }
  98140. v->lW=0; /* previous window size */
  98141. v->W=0; /* current window size */
  98142. v->centerW=ci->blocksizes[1]/2;
  98143. v->pcm_current=v->centerW;
  98144. b->flr=(vorbis_look_floor**)_ogg_calloc(ci->floors,sizeof(*b->flr));
  98145. b->residue=(vorbis_look_residue**)_ogg_calloc(ci->residues,sizeof(*b->residue));
  98146. for(i=0;i<ci->floors;i++)
  98147. b->flr[i]=_floor_P[ci->floor_type[i]]->
  98148. look(v,ci->floor_param[i]);
  98149. for(i=0;i<ci->residues;i++)
  98150. b->residue[i]=_residue_P[ci->residue_type[i]]->
  98151. look(v,ci->residue_param[i]);
  98152. return 0;
  98153. }
  98154. int vorbis_analysis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98155. private_state *b=NULL;
  98156. if(_vds_shared_init(v,vi,1))return 1;
  98157. b=(private_state*)v->backend_state;
  98158. b->psy_g_look=_vp_global_look(vi);
  98159. b->ve=(envelope_lookup*)_ogg_calloc(1,sizeof(*b->ve));
  98160. _ve_envelope_init(b->ve,vi);
  98161. vorbis_bitrate_init(vi,&b->bms);
  98162. v->sequence=3;
  98163. return(0);
  98164. }
  98165. void vorbis_dsp_clear(vorbis_dsp_state *v){
  98166. int i;
  98167. if(v){
  98168. vorbis_info *vi=v->vi;
  98169. codec_setup_info *ci=(codec_setup_info*)(vi?vi->codec_setup:NULL);
  98170. private_state *b=(private_state*)v->backend_state;
  98171. if(b){
  98172. if(b->ve){
  98173. _ve_envelope_clear(b->ve);
  98174. _ogg_free(b->ve);
  98175. }
  98176. if(b->transform[0]){
  98177. mdct_clear((mdct_lookup*) b->transform[0][0]);
  98178. _ogg_free(b->transform[0][0]);
  98179. _ogg_free(b->transform[0]);
  98180. }
  98181. if(b->transform[1]){
  98182. mdct_clear((mdct_lookup*) b->transform[1][0]);
  98183. _ogg_free(b->transform[1][0]);
  98184. _ogg_free(b->transform[1]);
  98185. }
  98186. if(b->flr){
  98187. for(i=0;i<ci->floors;i++)
  98188. _floor_P[ci->floor_type[i]]->
  98189. free_look(b->flr[i]);
  98190. _ogg_free(b->flr);
  98191. }
  98192. if(b->residue){
  98193. for(i=0;i<ci->residues;i++)
  98194. _residue_P[ci->residue_type[i]]->
  98195. free_look(b->residue[i]);
  98196. _ogg_free(b->residue);
  98197. }
  98198. if(b->psy){
  98199. for(i=0;i<ci->psys;i++)
  98200. _vp_psy_clear(b->psy+i);
  98201. _ogg_free(b->psy);
  98202. }
  98203. if(b->psy_g_look)_vp_global_free(b->psy_g_look);
  98204. vorbis_bitrate_clear(&b->bms);
  98205. drft_clear(&b->fft_look[0]);
  98206. drft_clear(&b->fft_look[1]);
  98207. }
  98208. if(v->pcm){
  98209. for(i=0;i<vi->channels;i++)
  98210. if(v->pcm[i])_ogg_free(v->pcm[i]);
  98211. _ogg_free(v->pcm);
  98212. if(v->pcmret)_ogg_free(v->pcmret);
  98213. }
  98214. if(b){
  98215. if(b->header)_ogg_free(b->header);
  98216. if(b->header1)_ogg_free(b->header1);
  98217. if(b->header2)_ogg_free(b->header2);
  98218. _ogg_free(b);
  98219. }
  98220. memset(v,0,sizeof(*v));
  98221. }
  98222. }
  98223. float **vorbis_analysis_buffer(vorbis_dsp_state *v, int vals){
  98224. int i;
  98225. vorbis_info *vi=v->vi;
  98226. private_state *b=(private_state*)v->backend_state;
  98227. if(b->header)_ogg_free(b->header);b->header=NULL;
  98228. if(b->header1)_ogg_free(b->header1);b->header1=NULL;
  98229. if(b->header2)_ogg_free(b->header2);b->header2=NULL;
  98230. if(v->pcm_current+vals>=v->pcm_storage){
  98231. v->pcm_storage=v->pcm_current+vals*2;
  98232. for(i=0;i<vi->channels;i++){
  98233. v->pcm[i]=(float*)_ogg_realloc(v->pcm[i],v->pcm_storage*sizeof(*v->pcm[i]));
  98234. }
  98235. }
  98236. for(i=0;i<vi->channels;i++)
  98237. v->pcmret[i]=v->pcm[i]+v->pcm_current;
  98238. return(v->pcmret);
  98239. }
  98240. static void _preextrapolate_helper(vorbis_dsp_state *v){
  98241. int i;
  98242. int order=32;
  98243. float *lpc=(float*)alloca(order*sizeof(*lpc));
  98244. float *work=(float*)alloca(v->pcm_current*sizeof(*work));
  98245. long j;
  98246. v->preextrapolate=1;
  98247. if(v->pcm_current-v->centerW>order*2){ /* safety */
  98248. for(i=0;i<v->vi->channels;i++){
  98249. for(j=0;j<v->pcm_current;j++)
  98250. work[j]=v->pcm[i][v->pcm_current-j-1];
  98251. vorbis_lpc_from_data(work,lpc,v->pcm_current-v->centerW,order);
  98252. vorbis_lpc_predict(lpc,work+v->pcm_current-v->centerW-order,
  98253. order,
  98254. work+v->pcm_current-v->centerW,
  98255. v->centerW);
  98256. for(j=0;j<v->pcm_current;j++)
  98257. v->pcm[i][v->pcm_current-j-1]=work[j];
  98258. }
  98259. }
  98260. }
  98261. int vorbis_analysis_wrote(vorbis_dsp_state *v, int vals){
  98262. vorbis_info *vi=v->vi;
  98263. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98264. if(vals<=0){
  98265. int order=32;
  98266. int i;
  98267. float *lpc=(float*) alloca(order*sizeof(*lpc));
  98268. if(!v->preextrapolate)
  98269. _preextrapolate_helper(v);
  98270. vorbis_analysis_buffer(v,ci->blocksizes[1]*3);
  98271. v->eofflag=v->pcm_current;
  98272. v->pcm_current+=ci->blocksizes[1]*3;
  98273. for(i=0;i<vi->channels;i++){
  98274. if(v->eofflag>order*2){
  98275. long n;
  98276. n=v->eofflag;
  98277. if(n>ci->blocksizes[1])n=ci->blocksizes[1];
  98278. vorbis_lpc_from_data(v->pcm[i]+v->eofflag-n,lpc,n,order);
  98279. vorbis_lpc_predict(lpc,v->pcm[i]+v->eofflag-order,order,
  98280. v->pcm[i]+v->eofflag,v->pcm_current-v->eofflag);
  98281. }else{
  98282. memset(v->pcm[i]+v->eofflag,0,
  98283. (v->pcm_current-v->eofflag)*sizeof(*v->pcm[i]));
  98284. }
  98285. }
  98286. }else{
  98287. if(v->pcm_current+vals>v->pcm_storage)
  98288. return(OV_EINVAL);
  98289. v->pcm_current+=vals;
  98290. if(!v->preextrapolate && v->pcm_current-v->centerW>ci->blocksizes[1])
  98291. _preextrapolate_helper(v);
  98292. }
  98293. return(0);
  98294. }
  98295. int vorbis_analysis_blockout(vorbis_dsp_state *v,vorbis_block *vb){
  98296. int i;
  98297. vorbis_info *vi=v->vi;
  98298. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98299. private_state *b=(private_state*)v->backend_state;
  98300. vorbis_look_psy_global *g=b->psy_g_look;
  98301. long beginW=v->centerW-ci->blocksizes[v->W]/2,centerNext;
  98302. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  98303. if(!v->preextrapolate)return(0);
  98304. if(v->eofflag==-1)return(0);
  98305. {
  98306. long bp=_ve_envelope_search(v);
  98307. if(bp==-1){
  98308. if(v->eofflag==0)return(0); /* not enough data currently to search for a
  98309. full long block */
  98310. v->nW=0;
  98311. }else{
  98312. if(ci->blocksizes[0]==ci->blocksizes[1])
  98313. v->nW=0;
  98314. else
  98315. v->nW=bp;
  98316. }
  98317. }
  98318. centerNext=v->centerW+ci->blocksizes[v->W]/4+ci->blocksizes[v->nW]/4;
  98319. {
  98320. long blockbound=centerNext+ci->blocksizes[v->nW]/2;
  98321. if(v->pcm_current<blockbound)return(0); /* not enough data yet;
  98322. although this check is
  98323. less strict that the
  98324. _ve_envelope_search,
  98325. the search is not run
  98326. if we only use one
  98327. block size */
  98328. }
  98329. _vorbis_block_ripcord(vb);
  98330. vb->lW=v->lW;
  98331. vb->W=v->W;
  98332. vb->nW=v->nW;
  98333. if(v->W){
  98334. if(!v->lW || !v->nW){
  98335. vbi->blocktype=BLOCKTYPE_TRANSITION;
  98336. }else{
  98337. vbi->blocktype=BLOCKTYPE_LONG;
  98338. }
  98339. }else{
  98340. if(_ve_envelope_mark(v)){
  98341. vbi->blocktype=BLOCKTYPE_IMPULSE;
  98342. }else{
  98343. vbi->blocktype=BLOCKTYPE_PADDING;
  98344. }
  98345. }
  98346. vb->vd=v;
  98347. vb->sequence=v->sequence++;
  98348. vb->granulepos=v->granulepos;
  98349. vb->pcmend=ci->blocksizes[v->W];
  98350. if(vbi->ampmax>g->ampmax)g->ampmax=vbi->ampmax;
  98351. g->ampmax=_vp_ampmax_decay(g->ampmax,v);
  98352. vbi->ampmax=g->ampmax;
  98353. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  98354. vbi->pcmdelay=(float**)_vorbis_block_alloc(vb,sizeof(*vbi->pcmdelay)*vi->channels);
  98355. for(i=0;i<vi->channels;i++){
  98356. vbi->pcmdelay[i]=
  98357. (float*) _vorbis_block_alloc(vb,(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98358. memcpy(vbi->pcmdelay[i],v->pcm[i],(vb->pcmend+beginW)*sizeof(*vbi->pcmdelay[i]));
  98359. vb->pcm[i]=vbi->pcmdelay[i]+beginW;
  98360. }
  98361. if(v->eofflag){
  98362. if(v->centerW>=v->eofflag){
  98363. v->eofflag=-1;
  98364. vb->eofflag=1;
  98365. return(1);
  98366. }
  98367. }
  98368. {
  98369. int new_centerNext=ci->blocksizes[1]/2;
  98370. int movementW=centerNext-new_centerNext;
  98371. if(movementW>0){
  98372. _ve_envelope_shift(b->ve,movementW);
  98373. v->pcm_current-=movementW;
  98374. for(i=0;i<vi->channels;i++)
  98375. memmove(v->pcm[i],v->pcm[i]+movementW,
  98376. v->pcm_current*sizeof(*v->pcm[i]));
  98377. v->lW=v->W;
  98378. v->W=v->nW;
  98379. v->centerW=new_centerNext;
  98380. if(v->eofflag){
  98381. v->eofflag-=movementW;
  98382. if(v->eofflag<=0)v->eofflag=-1;
  98383. if(v->centerW>=v->eofflag){
  98384. v->granulepos+=movementW-(v->centerW-v->eofflag);
  98385. }else{
  98386. v->granulepos+=movementW;
  98387. }
  98388. }else{
  98389. v->granulepos+=movementW;
  98390. }
  98391. }
  98392. }
  98393. return(1);
  98394. }
  98395. int vorbis_synthesis_restart(vorbis_dsp_state *v){
  98396. vorbis_info *vi=v->vi;
  98397. codec_setup_info *ci;
  98398. int hs;
  98399. if(!v->backend_state)return -1;
  98400. if(!vi)return -1;
  98401. ci=(codec_setup_info*) vi->codec_setup;
  98402. if(!ci)return -1;
  98403. hs=ci->halfrate_flag;
  98404. v->centerW=ci->blocksizes[1]>>(hs+1);
  98405. v->pcm_current=v->centerW>>hs;
  98406. v->pcm_returned=-1;
  98407. v->granulepos=-1;
  98408. v->sequence=-1;
  98409. v->eofflag=0;
  98410. ((private_state *)(v->backend_state))->sample_count=-1;
  98411. return(0);
  98412. }
  98413. int vorbis_synthesis_init(vorbis_dsp_state *v,vorbis_info *vi){
  98414. if(_vds_shared_init(v,vi,0)) return 1;
  98415. vorbis_synthesis_restart(v);
  98416. return 0;
  98417. }
  98418. int vorbis_synthesis_blockin(vorbis_dsp_state *v,vorbis_block *vb){
  98419. vorbis_info *vi=v->vi;
  98420. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  98421. private_state *b=(private_state*)v->backend_state;
  98422. int hs=ci->halfrate_flag;
  98423. int i,j;
  98424. if(!vb)return(OV_EINVAL);
  98425. if(v->pcm_current>v->pcm_returned && v->pcm_returned!=-1)return(OV_EINVAL);
  98426. v->lW=v->W;
  98427. v->W=vb->W;
  98428. v->nW=-1;
  98429. if((v->sequence==-1)||
  98430. (v->sequence+1 != vb->sequence)){
  98431. v->granulepos=-1; /* out of sequence; lose count */
  98432. b->sample_count=-1;
  98433. }
  98434. v->sequence=vb->sequence;
  98435. if(vb->pcm){ /* no pcm to process if vorbis_synthesis_trackonly
  98436. was called on block */
  98437. int n=ci->blocksizes[v->W]>>(hs+1);
  98438. int n0=ci->blocksizes[0]>>(hs+1);
  98439. int n1=ci->blocksizes[1]>>(hs+1);
  98440. int thisCenter;
  98441. int prevCenter;
  98442. v->glue_bits+=vb->glue_bits;
  98443. v->time_bits+=vb->time_bits;
  98444. v->floor_bits+=vb->floor_bits;
  98445. v->res_bits+=vb->res_bits;
  98446. if(v->centerW){
  98447. thisCenter=n1;
  98448. prevCenter=0;
  98449. }else{
  98450. thisCenter=0;
  98451. prevCenter=n1;
  98452. }
  98453. for(j=0;j<vi->channels;j++){
  98454. if(v->lW){
  98455. if(v->W){
  98456. float *w=_vorbis_window_get(b->window[1]-hs);
  98457. float *pcm=v->pcm[j]+prevCenter;
  98458. float *p=vb->pcm[j];
  98459. for(i=0;i<n1;i++)
  98460. pcm[i]=pcm[i]*w[n1-i-1] + p[i]*w[i];
  98461. }else{
  98462. float *w=_vorbis_window_get(b->window[0]-hs);
  98463. float *pcm=v->pcm[j]+prevCenter+n1/2-n0/2;
  98464. float *p=vb->pcm[j];
  98465. for(i=0;i<n0;i++)
  98466. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98467. }
  98468. }else{
  98469. if(v->W){
  98470. float *w=_vorbis_window_get(b->window[0]-hs);
  98471. float *pcm=v->pcm[j]+prevCenter;
  98472. float *p=vb->pcm[j]+n1/2-n0/2;
  98473. for(i=0;i<n0;i++)
  98474. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98475. for(;i<n1/2+n0/2;i++)
  98476. pcm[i]=p[i];
  98477. }else{
  98478. float *w=_vorbis_window_get(b->window[0]-hs);
  98479. float *pcm=v->pcm[j]+prevCenter;
  98480. float *p=vb->pcm[j];
  98481. for(i=0;i<n0;i++)
  98482. pcm[i]=pcm[i]*w[n0-i-1] +p[i]*w[i];
  98483. }
  98484. }
  98485. {
  98486. float *pcm=v->pcm[j]+thisCenter;
  98487. float *p=vb->pcm[j]+n;
  98488. for(i=0;i<n;i++)
  98489. pcm[i]=p[i];
  98490. }
  98491. }
  98492. if(v->centerW)
  98493. v->centerW=0;
  98494. else
  98495. v->centerW=n1;
  98496. if(v->pcm_returned==-1){
  98497. v->pcm_returned=thisCenter;
  98498. v->pcm_current=thisCenter;
  98499. }else{
  98500. v->pcm_returned=prevCenter;
  98501. v->pcm_current=prevCenter+
  98502. ((ci->blocksizes[v->lW]/4+
  98503. ci->blocksizes[v->W]/4)>>hs);
  98504. }
  98505. }
  98506. if(b->sample_count==-1){
  98507. b->sample_count=0;
  98508. }else{
  98509. b->sample_count+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98510. }
  98511. if(v->granulepos==-1){
  98512. if(vb->granulepos!=-1){ /* only set if we have a position to set to */
  98513. v->granulepos=vb->granulepos;
  98514. if(b->sample_count>v->granulepos){
  98515. if(vb->eofflag){
  98516. v->pcm_current-=(b->sample_count-v->granulepos)>>hs;
  98517. }else{
  98518. v->pcm_returned+=(b->sample_count-v->granulepos)>>hs;
  98519. if(v->pcm_returned>v->pcm_current)
  98520. v->pcm_returned=v->pcm_current;
  98521. }
  98522. }
  98523. }
  98524. }else{
  98525. v->granulepos+=ci->blocksizes[v->lW]/4+ci->blocksizes[v->W]/4;
  98526. if(vb->granulepos!=-1 && v->granulepos!=vb->granulepos){
  98527. if(v->granulepos>vb->granulepos){
  98528. long extra=v->granulepos-vb->granulepos;
  98529. if(extra)
  98530. if(vb->eofflag){
  98531. v->pcm_current-=extra>>hs;
  98532. } /* else {Shouldn't happen *unless* the bitstream is out of
  98533. spec. Either way, believe the bitstream } */
  98534. } /* else {Shouldn't happen *unless* the bitstream is out of
  98535. spec. Either way, believe the bitstream } */
  98536. v->granulepos=vb->granulepos;
  98537. }
  98538. }
  98539. if(vb->eofflag)v->eofflag=1;
  98540. return(0);
  98541. }
  98542. int vorbis_synthesis_pcmout(vorbis_dsp_state *v,float ***pcm){
  98543. vorbis_info *vi=v->vi;
  98544. if(v->pcm_returned>-1 && v->pcm_returned<v->pcm_current){
  98545. if(pcm){
  98546. int i;
  98547. for(i=0;i<vi->channels;i++)
  98548. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98549. *pcm=v->pcmret;
  98550. }
  98551. return(v->pcm_current-v->pcm_returned);
  98552. }
  98553. return(0);
  98554. }
  98555. int vorbis_synthesis_read(vorbis_dsp_state *v,int n){
  98556. if(n && v->pcm_returned+n>v->pcm_current)return(OV_EINVAL);
  98557. v->pcm_returned+=n;
  98558. return(0);
  98559. }
  98560. int vorbis_synthesis_lapout(vorbis_dsp_state *v,float ***pcm){
  98561. vorbis_info *vi=v->vi;
  98562. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  98563. int hs=ci->halfrate_flag;
  98564. int n=ci->blocksizes[v->W]>>(hs+1);
  98565. int n0=ci->blocksizes[0]>>(hs+1);
  98566. int n1=ci->blocksizes[1]>>(hs+1);
  98567. int i,j;
  98568. if(v->pcm_returned<0)return 0;
  98569. if(v->centerW==n1){
  98570. for(j=0;j<vi->channels;j++){
  98571. float *p=v->pcm[j];
  98572. for(i=0;i<n1;i++){
  98573. float temp=p[i];
  98574. p[i]=p[i+n1];
  98575. p[i+n1]=temp;
  98576. }
  98577. }
  98578. v->pcm_current-=n1;
  98579. v->pcm_returned-=n1;
  98580. v->centerW=0;
  98581. }
  98582. if((v->lW^v->W)==1){
  98583. for(j=0;j<vi->channels;j++){
  98584. float *s=v->pcm[j];
  98585. float *d=v->pcm[j]+(n1-n0)/2;
  98586. for(i=(n1+n0)/2-1;i>=0;--i)
  98587. d[i]=s[i];
  98588. }
  98589. v->pcm_returned+=(n1-n0)/2;
  98590. v->pcm_current+=(n1-n0)/2;
  98591. }else{
  98592. if(v->lW==0){
  98593. for(j=0;j<vi->channels;j++){
  98594. float *s=v->pcm[j];
  98595. float *d=v->pcm[j]+n1-n0;
  98596. for(i=n0-1;i>=0;--i)
  98597. d[i]=s[i];
  98598. }
  98599. v->pcm_returned+=n1-n0;
  98600. v->pcm_current+=n1-n0;
  98601. }
  98602. }
  98603. if(pcm){
  98604. int i;
  98605. for(i=0;i<vi->channels;i++)
  98606. v->pcmret[i]=v->pcm[i]+v->pcm_returned;
  98607. *pcm=v->pcmret;
  98608. }
  98609. return(n1+n-v->pcm_returned);
  98610. }
  98611. float *vorbis_window(vorbis_dsp_state *v,int W){
  98612. vorbis_info *vi=v->vi;
  98613. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  98614. int hs=ci->halfrate_flag;
  98615. private_state *b=(private_state*)v->backend_state;
  98616. if(b->window[W]-1<0)return NULL;
  98617. return _vorbis_window_get(b->window[W]-hs);
  98618. }
  98619. #endif
  98620. /*** End of inlined file: block.c ***/
  98621. /*** Start of inlined file: codebook.c ***/
  98622. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  98623. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  98624. // tasks..
  98625. #if JUCE_MSVC
  98626. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  98627. #endif
  98628. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  98629. #if JUCE_USE_OGGVORBIS
  98630. #include <stdlib.h>
  98631. #include <string.h>
  98632. #include <math.h>
  98633. int vorbis_staticbook_pack(const static_codebook *c,oggpack_buffer *opb){
  98634. long i,j;
  98635. int ordered=0;
  98636. oggpack_write(opb,0x564342,24);
  98637. oggpack_write(opb,c->dim,16);
  98638. oggpack_write(opb,c->entries,24);
  98639. for(i=1;i<c->entries;i++)
  98640. if(c->lengthlist[i-1]==0 || c->lengthlist[i]<c->lengthlist[i-1])break;
  98641. if(i==c->entries)ordered=1;
  98642. if(ordered){
  98643. long count=0;
  98644. oggpack_write(opb,1,1); /* ordered */
  98645. oggpack_write(opb,c->lengthlist[0]-1,5); /* 1 to 32 */
  98646. for(i=1;i<c->entries;i++){
  98647. long thisx=c->lengthlist[i];
  98648. long last=c->lengthlist[i-1];
  98649. if(thisx>last){
  98650. for(j=last;j<thisx;j++){
  98651. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98652. count=i;
  98653. }
  98654. }
  98655. }
  98656. oggpack_write(opb,i-count,_ilog(c->entries-count));
  98657. }else{
  98658. oggpack_write(opb,0,1); /* unordered */
  98659. for(i=0;i<c->entries;i++)
  98660. if(c->lengthlist[i]==0)break;
  98661. if(i==c->entries){
  98662. oggpack_write(opb,0,1); /* no unused entries */
  98663. for(i=0;i<c->entries;i++)
  98664. oggpack_write(opb,c->lengthlist[i]-1,5);
  98665. }else{
  98666. oggpack_write(opb,1,1); /* we have unused entries; thus we tag */
  98667. for(i=0;i<c->entries;i++){
  98668. if(c->lengthlist[i]==0){
  98669. oggpack_write(opb,0,1);
  98670. }else{
  98671. oggpack_write(opb,1,1);
  98672. oggpack_write(opb,c->lengthlist[i]-1,5);
  98673. }
  98674. }
  98675. }
  98676. }
  98677. oggpack_write(opb,c->maptype,4);
  98678. switch(c->maptype){
  98679. case 0:
  98680. break;
  98681. case 1:case 2:
  98682. if(!c->quantlist){
  98683. return(-1);
  98684. }
  98685. oggpack_write(opb,c->q_min,32);
  98686. oggpack_write(opb,c->q_delta,32);
  98687. oggpack_write(opb,c->q_quant-1,4);
  98688. oggpack_write(opb,c->q_sequencep,1);
  98689. {
  98690. int quantvals;
  98691. switch(c->maptype){
  98692. case 1:
  98693. quantvals=_book_maptype1_quantvals(c);
  98694. break;
  98695. case 2:
  98696. quantvals=c->entries*c->dim;
  98697. break;
  98698. default: /* NOT_REACHABLE */
  98699. quantvals=-1;
  98700. }
  98701. for(i=0;i<quantvals;i++)
  98702. oggpack_write(opb,labs(c->quantlist[i]),c->q_quant);
  98703. }
  98704. break;
  98705. default:
  98706. return(-1);
  98707. }
  98708. return(0);
  98709. }
  98710. int vorbis_staticbook_unpack(oggpack_buffer *opb,static_codebook *s){
  98711. long i,j;
  98712. memset(s,0,sizeof(*s));
  98713. s->allocedp=1;
  98714. if(oggpack_read(opb,24)!=0x564342)goto _eofout;
  98715. s->dim=oggpack_read(opb,16);
  98716. s->entries=oggpack_read(opb,24);
  98717. if(s->entries==-1)goto _eofout;
  98718. switch((int)oggpack_read(opb,1)){
  98719. case 0:
  98720. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98721. if(oggpack_read(opb,1)){
  98722. for(i=0;i<s->entries;i++){
  98723. if(oggpack_read(opb,1)){
  98724. long num=oggpack_read(opb,5);
  98725. if(num==-1)goto _eofout;
  98726. s->lengthlist[i]=num+1;
  98727. }else
  98728. s->lengthlist[i]=0;
  98729. }
  98730. }else{
  98731. for(i=0;i<s->entries;i++){
  98732. long num=oggpack_read(opb,5);
  98733. if(num==-1)goto _eofout;
  98734. s->lengthlist[i]=num+1;
  98735. }
  98736. }
  98737. break;
  98738. case 1:
  98739. {
  98740. long length=oggpack_read(opb,5)+1;
  98741. s->lengthlist=(long*)_ogg_malloc(sizeof(*s->lengthlist)*s->entries);
  98742. for(i=0;i<s->entries;){
  98743. long num=oggpack_read(opb,_ilog(s->entries-i));
  98744. if(num==-1)goto _eofout;
  98745. for(j=0;j<num && i<s->entries;j++,i++)
  98746. s->lengthlist[i]=length;
  98747. length++;
  98748. }
  98749. }
  98750. break;
  98751. default:
  98752. return(-1);
  98753. }
  98754. switch((s->maptype=oggpack_read(opb,4))){
  98755. case 0:
  98756. break;
  98757. case 1: case 2:
  98758. s->q_min=oggpack_read(opb,32);
  98759. s->q_delta=oggpack_read(opb,32);
  98760. s->q_quant=oggpack_read(opb,4)+1;
  98761. s->q_sequencep=oggpack_read(opb,1);
  98762. {
  98763. int quantvals=0;
  98764. switch(s->maptype){
  98765. case 1:
  98766. quantvals=_book_maptype1_quantvals(s);
  98767. break;
  98768. case 2:
  98769. quantvals=s->entries*s->dim;
  98770. break;
  98771. }
  98772. s->quantlist=(long*)_ogg_malloc(sizeof(*s->quantlist)*quantvals);
  98773. for(i=0;i<quantvals;i++)
  98774. s->quantlist[i]=oggpack_read(opb,s->q_quant);
  98775. if(quantvals&&s->quantlist[quantvals-1]==-1)goto _eofout;
  98776. }
  98777. break;
  98778. default:
  98779. goto _errout;
  98780. }
  98781. return(0);
  98782. _errout:
  98783. _eofout:
  98784. vorbis_staticbook_clear(s);
  98785. return(-1);
  98786. }
  98787. int vorbis_book_encode(codebook *book, int a, oggpack_buffer *b){
  98788. oggpack_write(b,book->codelist[a],book->c->lengthlist[a]);
  98789. return(book->c->lengthlist[a]);
  98790. }
  98791. int vorbis_book_errorv(codebook *book,float *a){
  98792. int dim=book->dim,k;
  98793. int best=_best(book,a,1);
  98794. for(k=0;k<dim;k++)
  98795. a[k]=(book->valuelist+best*dim)[k];
  98796. return(best);
  98797. }
  98798. int vorbis_book_encodev(codebook *book,int best,float *a,oggpack_buffer *b){
  98799. int k,dim=book->dim;
  98800. for(k=0;k<dim;k++)
  98801. a[k]=(book->valuelist+best*dim)[k];
  98802. return(vorbis_book_encode(book,best,b));
  98803. }
  98804. STIN long decode_packed_entry_number(codebook *book, oggpack_buffer *b){
  98805. int read=book->dec_maxlength;
  98806. long lo,hi;
  98807. long lok = oggpack_look(b,book->dec_firsttablen);
  98808. if (lok >= 0) {
  98809. long entry = book->dec_firsttable[lok];
  98810. if(entry&0x80000000UL){
  98811. lo=(entry>>15)&0x7fff;
  98812. hi=book->used_entries-(entry&0x7fff);
  98813. }else{
  98814. oggpack_adv(b, book->dec_codelengths[entry-1]);
  98815. return(entry-1);
  98816. }
  98817. }else{
  98818. lo=0;
  98819. hi=book->used_entries;
  98820. }
  98821. lok = oggpack_look(b, read);
  98822. while(lok<0 && read>1)
  98823. lok = oggpack_look(b, --read);
  98824. if(lok<0)return -1;
  98825. {
  98826. ogg_uint32_t testword=ogg_bitreverse((ogg_uint32_t)lok);
  98827. while(hi-lo>1){
  98828. long p=(hi-lo)>>1;
  98829. long test=book->codelist[lo+p]>testword;
  98830. lo+=p&(test-1);
  98831. hi-=p&(-test);
  98832. }
  98833. if(book->dec_codelengths[lo]<=read){
  98834. oggpack_adv(b, book->dec_codelengths[lo]);
  98835. return(lo);
  98836. }
  98837. }
  98838. oggpack_adv(b, read);
  98839. return(-1);
  98840. }
  98841. long vorbis_book_decode(codebook *book, oggpack_buffer *b){
  98842. long packed_entry=decode_packed_entry_number(book,b);
  98843. if(packed_entry>=0)
  98844. return(book->dec_index[packed_entry]);
  98845. return(packed_entry);
  98846. }
  98847. long vorbis_book_decodevs_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98848. int step=n/book->dim;
  98849. long *entry = (long*)alloca(sizeof(*entry)*step);
  98850. float **t = (float**)alloca(sizeof(*t)*step);
  98851. int i,j,o;
  98852. for (i = 0; i < step; i++) {
  98853. entry[i]=decode_packed_entry_number(book,b);
  98854. if(entry[i]==-1)return(-1);
  98855. t[i] = book->valuelist+entry[i]*book->dim;
  98856. }
  98857. for(i=0,o=0;i<book->dim;i++,o+=step)
  98858. for (j=0;j<step;j++)
  98859. a[o+j]+=t[j][i];
  98860. return(0);
  98861. }
  98862. long vorbis_book_decodev_add(codebook *book,float *a,oggpack_buffer *b,int n){
  98863. int i,j,entry;
  98864. float *t;
  98865. if(book->dim>8){
  98866. for(i=0;i<n;){
  98867. entry = decode_packed_entry_number(book,b);
  98868. if(entry==-1)return(-1);
  98869. t = book->valuelist+entry*book->dim;
  98870. for (j=0;j<book->dim;)
  98871. a[i++]+=t[j++];
  98872. }
  98873. }else{
  98874. for(i=0;i<n;){
  98875. entry = decode_packed_entry_number(book,b);
  98876. if(entry==-1)return(-1);
  98877. t = book->valuelist+entry*book->dim;
  98878. j=0;
  98879. switch((int)book->dim){
  98880. case 8:
  98881. a[i++]+=t[j++];
  98882. case 7:
  98883. a[i++]+=t[j++];
  98884. case 6:
  98885. a[i++]+=t[j++];
  98886. case 5:
  98887. a[i++]+=t[j++];
  98888. case 4:
  98889. a[i++]+=t[j++];
  98890. case 3:
  98891. a[i++]+=t[j++];
  98892. case 2:
  98893. a[i++]+=t[j++];
  98894. case 1:
  98895. a[i++]+=t[j++];
  98896. case 0:
  98897. break;
  98898. }
  98899. }
  98900. }
  98901. return(0);
  98902. }
  98903. long vorbis_book_decodev_set(codebook *book,float *a,oggpack_buffer *b,int n){
  98904. int i,j,entry;
  98905. float *t;
  98906. for(i=0;i<n;){
  98907. entry = decode_packed_entry_number(book,b);
  98908. if(entry==-1)return(-1);
  98909. t = book->valuelist+entry*book->dim;
  98910. for (j=0;j<book->dim;)
  98911. a[i++]=t[j++];
  98912. }
  98913. return(0);
  98914. }
  98915. long vorbis_book_decodevv_add(codebook *book,float **a,long offset,int ch,
  98916. oggpack_buffer *b,int n){
  98917. long i,j,entry;
  98918. int chptr=0;
  98919. for(i=offset/ch;i<(offset+n)/ch;){
  98920. entry = decode_packed_entry_number(book,b);
  98921. if(entry==-1)return(-1);
  98922. {
  98923. const float *t = book->valuelist+entry*book->dim;
  98924. for (j=0;j<book->dim;j++){
  98925. a[chptr++][i]+=t[j];
  98926. if(chptr==ch){
  98927. chptr=0;
  98928. i++;
  98929. }
  98930. }
  98931. }
  98932. }
  98933. return(0);
  98934. }
  98935. #ifdef _V_SELFTEST
  98936. #include <stdio.h>
  98937. #include "vorbis/book/lsp20_0.vqh"
  98938. #include "vorbis/book/res0a_13.vqh"
  98939. #define TESTSIZE 40
  98940. float test1[TESTSIZE]={
  98941. 0.105939f,
  98942. 0.215373f,
  98943. 0.429117f,
  98944. 0.587974f,
  98945. 0.181173f,
  98946. 0.296583f,
  98947. 0.515707f,
  98948. 0.715261f,
  98949. 0.162327f,
  98950. 0.263834f,
  98951. 0.342876f,
  98952. 0.406025f,
  98953. 0.103571f,
  98954. 0.223561f,
  98955. 0.368513f,
  98956. 0.540313f,
  98957. 0.136672f,
  98958. 0.395882f,
  98959. 0.587183f,
  98960. 0.652476f,
  98961. 0.114338f,
  98962. 0.417300f,
  98963. 0.525486f,
  98964. 0.698679f,
  98965. 0.147492f,
  98966. 0.324481f,
  98967. 0.643089f,
  98968. 0.757582f,
  98969. 0.139556f,
  98970. 0.215795f,
  98971. 0.324559f,
  98972. 0.399387f,
  98973. 0.120236f,
  98974. 0.267420f,
  98975. 0.446940f,
  98976. 0.608760f,
  98977. 0.115587f,
  98978. 0.287234f,
  98979. 0.571081f,
  98980. 0.708603f,
  98981. };
  98982. float test3[TESTSIZE]={
  98983. 0,1,-2,3,4,-5,6,7,8,9,
  98984. 8,-2,7,-1,4,6,8,3,1,-9,
  98985. 10,11,12,13,14,15,26,17,18,19,
  98986. 30,-25,-30,-1,-5,-32,4,3,-2,0};
  98987. static_codebook *testlist[]={&_vq_book_lsp20_0,
  98988. &_vq_book_res0a_13,NULL};
  98989. float *testvec[]={test1,test3};
  98990. int main(){
  98991. oggpack_buffer write;
  98992. oggpack_buffer read;
  98993. long ptr=0,i;
  98994. oggpack_writeinit(&write);
  98995. fprintf(stderr,"Testing codebook abstraction...:\n");
  98996. while(testlist[ptr]){
  98997. codebook c;
  98998. static_codebook s;
  98999. float *qv=alloca(sizeof(*qv)*TESTSIZE);
  99000. float *iv=alloca(sizeof(*iv)*TESTSIZE);
  99001. memcpy(qv,testvec[ptr],sizeof(*qv)*TESTSIZE);
  99002. memset(iv,0,sizeof(*iv)*TESTSIZE);
  99003. fprintf(stderr,"\tpacking/coding %ld... ",ptr);
  99004. oggpack_reset(&write);
  99005. vorbis_book_init_encode(&c,testlist[ptr]); /* get it into memory
  99006. we can write */
  99007. vorbis_staticbook_pack(testlist[ptr],&write);
  99008. fprintf(stderr,"Codebook size %ld bytes... ",oggpack_bytes(&write));
  99009. for(i=0;i<TESTSIZE;i+=c.dim){
  99010. int best=_best(&c,qv+i,1);
  99011. vorbis_book_encodev(&c,best,qv+i,&write);
  99012. }
  99013. vorbis_book_clear(&c);
  99014. fprintf(stderr,"OK.\n");
  99015. fprintf(stderr,"\tunpacking/decoding %ld... ",ptr);
  99016. oggpack_readinit(&read,oggpack_get_buffer(&write),oggpack_bytes(&write));
  99017. if(vorbis_staticbook_unpack(&read,&s)){
  99018. fprintf(stderr,"Error unpacking codebook.\n");
  99019. exit(1);
  99020. }
  99021. if(vorbis_book_init_decode(&c,&s)){
  99022. fprintf(stderr,"Error initializing codebook.\n");
  99023. exit(1);
  99024. }
  99025. for(i=0;i<TESTSIZE;i+=c.dim)
  99026. if(vorbis_book_decodev_set(&c,iv+i,&read,c.dim)==-1){
  99027. fprintf(stderr,"Error reading codebook test data (EOP).\n");
  99028. exit(1);
  99029. }
  99030. for(i=0;i<TESTSIZE;i++)
  99031. if(fabs(qv[i]-iv[i])>.000001){
  99032. fprintf(stderr,"read (%g) != written (%g) at position (%ld)\n",
  99033. iv[i],qv[i],i);
  99034. exit(1);
  99035. }
  99036. fprintf(stderr,"OK\n");
  99037. ptr++;
  99038. }
  99039. exit(0);
  99040. }
  99041. #endif
  99042. #endif
  99043. /*** End of inlined file: codebook.c ***/
  99044. /*** Start of inlined file: envelope.c ***/
  99045. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99046. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99047. // tasks..
  99048. #if JUCE_MSVC
  99049. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99050. #endif
  99051. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99052. #if JUCE_USE_OGGVORBIS
  99053. #include <stdlib.h>
  99054. #include <string.h>
  99055. #include <stdio.h>
  99056. #include <math.h>
  99057. void _ve_envelope_init(envelope_lookup *e,vorbis_info *vi){
  99058. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99059. vorbis_info_psy_global *gi=&ci->psy_g_param;
  99060. int ch=vi->channels;
  99061. int i,j;
  99062. int n=e->winlength=128;
  99063. e->searchstep=64; /* not random */
  99064. e->minenergy=gi->preecho_minenergy;
  99065. e->ch=ch;
  99066. e->storage=128;
  99067. e->cursor=ci->blocksizes[1]/2;
  99068. e->mdct_win=(float*)_ogg_calloc(n,sizeof(*e->mdct_win));
  99069. mdct_init(&e->mdct,n);
  99070. for(i=0;i<n;i++){
  99071. e->mdct_win[i]=sin(i/(n-1.)*M_PI);
  99072. e->mdct_win[i]*=e->mdct_win[i];
  99073. }
  99074. e->band[0].begin=2; e->band[0].end=4;
  99075. e->band[1].begin=4; e->band[1].end=5;
  99076. e->band[2].begin=6; e->band[2].end=6;
  99077. e->band[3].begin=9; e->band[3].end=8;
  99078. e->band[4].begin=13; e->band[4].end=8;
  99079. e->band[5].begin=17; e->band[5].end=8;
  99080. e->band[6].begin=22; e->band[6].end=8;
  99081. for(j=0;j<VE_BANDS;j++){
  99082. n=e->band[j].end;
  99083. e->band[j].window=(float*)_ogg_malloc(n*sizeof(*e->band[0].window));
  99084. for(i=0;i<n;i++){
  99085. e->band[j].window[i]=sin((i+.5)/n*M_PI);
  99086. e->band[j].total+=e->band[j].window[i];
  99087. }
  99088. e->band[j].total=1./e->band[j].total;
  99089. }
  99090. e->filter=(envelope_filter_state*)_ogg_calloc(VE_BANDS*ch,sizeof(*e->filter));
  99091. e->mark=(int*)_ogg_calloc(e->storage,sizeof(*e->mark));
  99092. }
  99093. void _ve_envelope_clear(envelope_lookup *e){
  99094. int i;
  99095. mdct_clear(&e->mdct);
  99096. for(i=0;i<VE_BANDS;i++)
  99097. _ogg_free(e->band[i].window);
  99098. _ogg_free(e->mdct_win);
  99099. _ogg_free(e->filter);
  99100. _ogg_free(e->mark);
  99101. memset(e,0,sizeof(*e));
  99102. }
  99103. static int _ve_amp(envelope_lookup *ve,
  99104. vorbis_info_psy_global *gi,
  99105. float *data,
  99106. envelope_band *bands,
  99107. envelope_filter_state *filters,
  99108. long pos){
  99109. long n=ve->winlength;
  99110. int ret=0;
  99111. long i,j;
  99112. float decay;
  99113. float minV=ve->minenergy;
  99114. float *vec=(float*) alloca(n*sizeof(*vec));
  99115. int stretch=max(VE_MINSTRETCH,ve->stretch/2);
  99116. float penalty=gi->stretch_penalty-(ve->stretch/2-VE_MINSTRETCH);
  99117. if(penalty<0.f)penalty=0.f;
  99118. if(penalty>gi->stretch_penalty)penalty=gi->stretch_penalty;
  99119. for(i=0;i<n;i++)
  99120. vec[i]=data[i]*ve->mdct_win[i];
  99121. mdct_forward(&ve->mdct,vec,vec);
  99122. {
  99123. float temp=vec[0]*vec[0]+.7*vec[1]*vec[1]+.2*vec[2]*vec[2];
  99124. int ptr=filters->nearptr;
  99125. if(ptr==0){
  99126. decay=filters->nearDC_acc=filters->nearDC_partialacc+temp;
  99127. filters->nearDC_partialacc=temp;
  99128. }else{
  99129. decay=filters->nearDC_acc+=temp;
  99130. filters->nearDC_partialacc+=temp;
  99131. }
  99132. filters->nearDC_acc-=filters->nearDC[ptr];
  99133. filters->nearDC[ptr]=temp;
  99134. decay*=(1./(VE_NEARDC+1));
  99135. filters->nearptr++;
  99136. if(filters->nearptr>=VE_NEARDC)filters->nearptr=0;
  99137. decay=todB(&decay)*.5-15.f;
  99138. }
  99139. for(i=0;i<n/2;i+=2){
  99140. float val=vec[i]*vec[i]+vec[i+1]*vec[i+1];
  99141. val=todB(&val)*.5f;
  99142. if(val<decay)val=decay;
  99143. if(val<minV)val=minV;
  99144. vec[i>>1]=val;
  99145. decay-=8.;
  99146. }
  99147. for(j=0;j<VE_BANDS;j++){
  99148. float acc=0.;
  99149. float valmax,valmin;
  99150. for(i=0;i<bands[j].end;i++)
  99151. acc+=vec[i+bands[j].begin]*bands[j].window[i];
  99152. acc*=bands[j].total;
  99153. {
  99154. int p,thisx=filters[j].ampptr;
  99155. float postmax,postmin,premax=-99999.f,premin=99999.f;
  99156. p=thisx;
  99157. p--;
  99158. if(p<0)p+=VE_AMP;
  99159. postmax=max(acc,filters[j].ampbuf[p]);
  99160. postmin=min(acc,filters[j].ampbuf[p]);
  99161. for(i=0;i<stretch;i++){
  99162. p--;
  99163. if(p<0)p+=VE_AMP;
  99164. premax=max(premax,filters[j].ampbuf[p]);
  99165. premin=min(premin,filters[j].ampbuf[p]);
  99166. }
  99167. valmin=postmin-premin;
  99168. valmax=postmax-premax;
  99169. filters[j].ampbuf[thisx]=acc;
  99170. filters[j].ampptr++;
  99171. if(filters[j].ampptr>=VE_AMP)filters[j].ampptr=0;
  99172. }
  99173. if(valmax>gi->preecho_thresh[j]+penalty){
  99174. ret|=1;
  99175. ret|=4;
  99176. }
  99177. if(valmin<gi->postecho_thresh[j]-penalty)ret|=2;
  99178. }
  99179. return(ret);
  99180. }
  99181. #if 0
  99182. static int seq=0;
  99183. static ogg_int64_t totalshift=-1024;
  99184. #endif
  99185. long _ve_envelope_search(vorbis_dsp_state *v){
  99186. vorbis_info *vi=v->vi;
  99187. codec_setup_info *ci=(codec_setup_info *)vi->codec_setup;
  99188. vorbis_info_psy_global *gi=&ci->psy_g_param;
  99189. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  99190. long i,j;
  99191. int first=ve->current/ve->searchstep;
  99192. int last=v->pcm_current/ve->searchstep-VE_WIN;
  99193. if(first<0)first=0;
  99194. if(last+VE_WIN+VE_POST>ve->storage){
  99195. ve->storage=last+VE_WIN+VE_POST; /* be sure */
  99196. ve->mark=(int*)_ogg_realloc(ve->mark,ve->storage*sizeof(*ve->mark));
  99197. }
  99198. for(j=first;j<last;j++){
  99199. int ret=0;
  99200. ve->stretch++;
  99201. if(ve->stretch>VE_MAXSTRETCH*2)
  99202. ve->stretch=VE_MAXSTRETCH*2;
  99203. for(i=0;i<ve->ch;i++){
  99204. float *pcm=v->pcm[i]+ve->searchstep*(j);
  99205. ret|=_ve_amp(ve,gi,pcm,ve->band,ve->filter+i*VE_BANDS,j);
  99206. }
  99207. ve->mark[j+VE_POST]=0;
  99208. if(ret&1){
  99209. ve->mark[j]=1;
  99210. ve->mark[j+1]=1;
  99211. }
  99212. if(ret&2){
  99213. ve->mark[j]=1;
  99214. if(j>0)ve->mark[j-1]=1;
  99215. }
  99216. if(ret&4)ve->stretch=-1;
  99217. }
  99218. ve->current=last*ve->searchstep;
  99219. {
  99220. long centerW=v->centerW;
  99221. long testW=
  99222. centerW+
  99223. ci->blocksizes[v->W]/4+
  99224. ci->blocksizes[1]/2+
  99225. ci->blocksizes[0]/4;
  99226. j=ve->cursor;
  99227. while(j<ve->current-(ve->searchstep)){/* account for postecho
  99228. working back one window */
  99229. if(j>=testW)return(1);
  99230. ve->cursor=j;
  99231. if(ve->mark[j/ve->searchstep]){
  99232. if(j>centerW){
  99233. #if 0
  99234. if(j>ve->curmark){
  99235. float *marker=alloca(v->pcm_current*sizeof(*marker));
  99236. int l,m;
  99237. memset(marker,0,sizeof(*marker)*v->pcm_current);
  99238. fprintf(stderr,"mark! seq=%d, cursor:%fs time:%fs\n",
  99239. seq,
  99240. (totalshift+ve->cursor)/44100.,
  99241. (totalshift+j)/44100.);
  99242. _analysis_output_always("pcmL",seq,v->pcm[0],v->pcm_current,0,0,totalshift);
  99243. _analysis_output_always("pcmR",seq,v->pcm[1],v->pcm_current,0,0,totalshift);
  99244. _analysis_output_always("markL",seq,v->pcm[0],j,0,0,totalshift);
  99245. _analysis_output_always("markR",seq,v->pcm[1],j,0,0,totalshift);
  99246. for(m=0;m<VE_BANDS;m++){
  99247. char buf[80];
  99248. sprintf(buf,"delL%d",m);
  99249. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m].markers[l]*.1;
  99250. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  99251. }
  99252. for(m=0;m<VE_BANDS;m++){
  99253. char buf[80];
  99254. sprintf(buf,"delR%d",m);
  99255. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->filter[m+VE_BANDS].markers[l]*.1;
  99256. _analysis_output_always(buf,seq,marker,v->pcm_current,0,0,totalshift);
  99257. }
  99258. for(l=0;l<last;l++)marker[l*ve->searchstep]=ve->mark[l]*.4;
  99259. _analysis_output_always("mark",seq,marker,v->pcm_current,0,0,totalshift);
  99260. seq++;
  99261. }
  99262. #endif
  99263. ve->curmark=j;
  99264. if(j>=testW)return(1);
  99265. return(0);
  99266. }
  99267. }
  99268. j+=ve->searchstep;
  99269. }
  99270. }
  99271. return(-1);
  99272. }
  99273. int _ve_envelope_mark(vorbis_dsp_state *v){
  99274. envelope_lookup *ve=((private_state *)(v->backend_state))->ve;
  99275. vorbis_info *vi=v->vi;
  99276. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99277. long centerW=v->centerW;
  99278. long beginW=centerW-ci->blocksizes[v->W]/4;
  99279. long endW=centerW+ci->blocksizes[v->W]/4;
  99280. if(v->W){
  99281. beginW-=ci->blocksizes[v->lW]/4;
  99282. endW+=ci->blocksizes[v->nW]/4;
  99283. }else{
  99284. beginW-=ci->blocksizes[0]/4;
  99285. endW+=ci->blocksizes[0]/4;
  99286. }
  99287. if(ve->curmark>=beginW && ve->curmark<endW)return(1);
  99288. {
  99289. long first=beginW/ve->searchstep;
  99290. long last=endW/ve->searchstep;
  99291. long i;
  99292. for(i=first;i<last;i++)
  99293. if(ve->mark[i])return(1);
  99294. }
  99295. return(0);
  99296. }
  99297. void _ve_envelope_shift(envelope_lookup *e,long shift){
  99298. int smallsize=e->current/e->searchstep+VE_POST; /* adjust for placing marks
  99299. ahead of ve->current */
  99300. int smallshift=shift/e->searchstep;
  99301. memmove(e->mark,e->mark+smallshift,(smallsize-smallshift)*sizeof(*e->mark));
  99302. #if 0
  99303. for(i=0;i<VE_BANDS*e->ch;i++)
  99304. memmove(e->filter[i].markers,
  99305. e->filter[i].markers+smallshift,
  99306. (1024-smallshift)*sizeof(*(*e->filter).markers));
  99307. totalshift+=shift;
  99308. #endif
  99309. e->current-=shift;
  99310. if(e->curmark>=0)
  99311. e->curmark-=shift;
  99312. e->cursor-=shift;
  99313. }
  99314. #endif
  99315. /*** End of inlined file: envelope.c ***/
  99316. /*** Start of inlined file: floor0.c ***/
  99317. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99318. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99319. // tasks..
  99320. #if JUCE_MSVC
  99321. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99322. #endif
  99323. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99324. #if JUCE_USE_OGGVORBIS
  99325. #include <stdlib.h>
  99326. #include <string.h>
  99327. #include <math.h>
  99328. /*** Start of inlined file: lsp.h ***/
  99329. #ifndef _V_LSP_H_
  99330. #define _V_LSP_H_
  99331. extern int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m);
  99332. extern void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,
  99333. float *lsp,int m,
  99334. float amp,float ampoffset);
  99335. #endif
  99336. /*** End of inlined file: lsp.h ***/
  99337. #include <stdio.h>
  99338. typedef struct {
  99339. int ln;
  99340. int m;
  99341. int **linearmap;
  99342. int n[2];
  99343. vorbis_info_floor0 *vi;
  99344. long bits;
  99345. long frames;
  99346. } vorbis_look_floor0;
  99347. static void floor0_free_info(vorbis_info_floor *i){
  99348. vorbis_info_floor0 *info=(vorbis_info_floor0 *)i;
  99349. if(info){
  99350. memset(info,0,sizeof(*info));
  99351. _ogg_free(info);
  99352. }
  99353. }
  99354. static void floor0_free_look(vorbis_look_floor *i){
  99355. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99356. if(look){
  99357. if(look->linearmap){
  99358. if(look->linearmap[0])_ogg_free(look->linearmap[0]);
  99359. if(look->linearmap[1])_ogg_free(look->linearmap[1]);
  99360. _ogg_free(look->linearmap);
  99361. }
  99362. memset(look,0,sizeof(*look));
  99363. _ogg_free(look);
  99364. }
  99365. }
  99366. static vorbis_info_floor *floor0_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99367. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99368. int j;
  99369. vorbis_info_floor0 *info=(vorbis_info_floor0*)_ogg_malloc(sizeof(*info));
  99370. info->order=oggpack_read(opb,8);
  99371. info->rate=oggpack_read(opb,16);
  99372. info->barkmap=oggpack_read(opb,16);
  99373. info->ampbits=oggpack_read(opb,6);
  99374. info->ampdB=oggpack_read(opb,8);
  99375. info->numbooks=oggpack_read(opb,4)+1;
  99376. if(info->order<1)goto err_out;
  99377. if(info->rate<1)goto err_out;
  99378. if(info->barkmap<1)goto err_out;
  99379. if(info->numbooks<1)goto err_out;
  99380. for(j=0;j<info->numbooks;j++){
  99381. info->books[j]=oggpack_read(opb,8);
  99382. if(info->books[j]<0 || info->books[j]>=ci->books)goto err_out;
  99383. }
  99384. return(info);
  99385. err_out:
  99386. floor0_free_info(info);
  99387. return(NULL);
  99388. }
  99389. static void floor0_map_lazy_init(vorbis_block *vb,
  99390. vorbis_info_floor *infoX,
  99391. vorbis_look_floor0 *look){
  99392. if(!look->linearmap[vb->W]){
  99393. vorbis_dsp_state *vd=vb->vd;
  99394. vorbis_info *vi=vd->vi;
  99395. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99396. vorbis_info_floor0 *info=(vorbis_info_floor0 *)infoX;
  99397. int W=vb->W;
  99398. int n=ci->blocksizes[W]/2,j;
  99399. float scale=look->ln/toBARK(info->rate/2.f);
  99400. look->linearmap[W]=(int*)_ogg_malloc((n+1)*sizeof(**look->linearmap));
  99401. for(j=0;j<n;j++){
  99402. int val=floor( toBARK((info->rate/2.f)/n*j)
  99403. *scale); /* bark numbers represent band edges */
  99404. if(val>=look->ln)val=look->ln-1; /* guard against the approximation */
  99405. look->linearmap[W][j]=val;
  99406. }
  99407. look->linearmap[W][j]=-1;
  99408. look->n[W]=n;
  99409. }
  99410. }
  99411. static vorbis_look_floor *floor0_look(vorbis_dsp_state *vd,
  99412. vorbis_info_floor *i){
  99413. vorbis_info_floor0 *info=(vorbis_info_floor0*)i;
  99414. vorbis_look_floor0 *look=(vorbis_look_floor0*)_ogg_calloc(1,sizeof(*look));
  99415. look->m=info->order;
  99416. look->ln=info->barkmap;
  99417. look->vi=info;
  99418. look->linearmap=(int**)_ogg_calloc(2,sizeof(*look->linearmap));
  99419. return look;
  99420. }
  99421. static void *floor0_inverse1(vorbis_block *vb,vorbis_look_floor *i){
  99422. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99423. vorbis_info_floor0 *info=look->vi;
  99424. int j,k;
  99425. int ampraw=oggpack_read(&vb->opb,info->ampbits);
  99426. if(ampraw>0){ /* also handles the -1 out of data case */
  99427. long maxval=(1<<info->ampbits)-1;
  99428. float amp=(float)ampraw/maxval*info->ampdB;
  99429. int booknum=oggpack_read(&vb->opb,_ilog(info->numbooks));
  99430. if(booknum!=-1 && booknum<info->numbooks){ /* be paranoid */
  99431. codec_setup_info *ci=(codec_setup_info *)vb->vd->vi->codec_setup;
  99432. codebook *b=ci->fullbooks+info->books[booknum];
  99433. float last=0.f;
  99434. float *lsp=(float*)_vorbis_block_alloc(vb,sizeof(*lsp)*(look->m+b->dim+1));
  99435. for(j=0;j<look->m;j+=b->dim)
  99436. if(vorbis_book_decodev_set(b,lsp+j,&vb->opb,b->dim)==-1)goto eop;
  99437. for(j=0;j<look->m;){
  99438. for(k=0;k<b->dim;k++,j++)lsp[j]+=last;
  99439. last=lsp[j-1];
  99440. }
  99441. lsp[look->m]=amp;
  99442. return(lsp);
  99443. }
  99444. }
  99445. eop:
  99446. return(NULL);
  99447. }
  99448. static int floor0_inverse2(vorbis_block *vb,vorbis_look_floor *i,
  99449. void *memo,float *out){
  99450. vorbis_look_floor0 *look=(vorbis_look_floor0 *)i;
  99451. vorbis_info_floor0 *info=look->vi;
  99452. floor0_map_lazy_init(vb,info,look);
  99453. if(memo){
  99454. float *lsp=(float *)memo;
  99455. float amp=lsp[look->m];
  99456. vorbis_lsp_to_curve(out,
  99457. look->linearmap[vb->W],
  99458. look->n[vb->W],
  99459. look->ln,
  99460. lsp,look->m,amp,(float)info->ampdB);
  99461. return(1);
  99462. }
  99463. memset(out,0,sizeof(*out)*look->n[vb->W]);
  99464. return(0);
  99465. }
  99466. vorbis_func_floor floor0_exportbundle={
  99467. NULL,&floor0_unpack,&floor0_look,&floor0_free_info,
  99468. &floor0_free_look,&floor0_inverse1,&floor0_inverse2
  99469. };
  99470. #endif
  99471. /*** End of inlined file: floor0.c ***/
  99472. /*** Start of inlined file: floor1.c ***/
  99473. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  99474. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  99475. // tasks..
  99476. #if JUCE_MSVC
  99477. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  99478. #endif
  99479. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  99480. #if JUCE_USE_OGGVORBIS
  99481. #include <stdlib.h>
  99482. #include <string.h>
  99483. #include <math.h>
  99484. #include <stdio.h>
  99485. #define floor1_rangedB 140 /* floor 1 fixed at -140dB to 0dB range */
  99486. typedef struct {
  99487. int sorted_index[VIF_POSIT+2];
  99488. int forward_index[VIF_POSIT+2];
  99489. int reverse_index[VIF_POSIT+2];
  99490. int hineighbor[VIF_POSIT];
  99491. int loneighbor[VIF_POSIT];
  99492. int posts;
  99493. int n;
  99494. int quant_q;
  99495. vorbis_info_floor1 *vi;
  99496. long phrasebits;
  99497. long postbits;
  99498. long frames;
  99499. } vorbis_look_floor1;
  99500. typedef struct lsfit_acc{
  99501. long x0;
  99502. long x1;
  99503. long xa;
  99504. long ya;
  99505. long x2a;
  99506. long y2a;
  99507. long xya;
  99508. long an;
  99509. } lsfit_acc;
  99510. static void floor1_free_info(vorbis_info_floor *i){
  99511. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99512. if(info){
  99513. memset(info,0,sizeof(*info));
  99514. _ogg_free(info);
  99515. }
  99516. }
  99517. static void floor1_free_look(vorbis_look_floor *i){
  99518. vorbis_look_floor1 *look=(vorbis_look_floor1 *)i;
  99519. if(look){
  99520. memset(look,0,sizeof(*look));
  99521. _ogg_free(look);
  99522. }
  99523. }
  99524. static void floor1_pack (vorbis_info_floor *i,oggpack_buffer *opb){
  99525. vorbis_info_floor1 *info=(vorbis_info_floor1 *)i;
  99526. int j,k;
  99527. int count=0;
  99528. int rangebits;
  99529. int maxposit=info->postlist[1];
  99530. int maxclass=-1;
  99531. oggpack_write(opb,info->partitions,5); /* only 0 to 31 legal */
  99532. for(j=0;j<info->partitions;j++){
  99533. oggpack_write(opb,info->partitionclass[j],4); /* only 0 to 15 legal */
  99534. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99535. }
  99536. for(j=0;j<maxclass+1;j++){
  99537. oggpack_write(opb,info->class_dim[j]-1,3); /* 1 to 8 */
  99538. oggpack_write(opb,info->class_subs[j],2); /* 0 to 3 */
  99539. if(info->class_subs[j])oggpack_write(opb,info->class_book[j],8);
  99540. for(k=0;k<(1<<info->class_subs[j]);k++)
  99541. oggpack_write(opb,info->class_subbook[j][k]+1,8);
  99542. }
  99543. oggpack_write(opb,info->mult-1,2); /* only 1,2,3,4 legal now */
  99544. oggpack_write(opb,ilog2(maxposit),4);
  99545. rangebits=ilog2(maxposit);
  99546. for(j=0,k=0;j<info->partitions;j++){
  99547. count+=info->class_dim[info->partitionclass[j]];
  99548. for(;k<count;k++)
  99549. oggpack_write(opb,info->postlist[k+2],rangebits);
  99550. }
  99551. }
  99552. static vorbis_info_floor *floor1_unpack (vorbis_info *vi,oggpack_buffer *opb){
  99553. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  99554. int j,k,count=0,maxclass=-1,rangebits;
  99555. vorbis_info_floor1 *info=(vorbis_info_floor1*)_ogg_calloc(1,sizeof(*info));
  99556. info->partitions=oggpack_read(opb,5); /* only 0 to 31 legal */
  99557. for(j=0;j<info->partitions;j++){
  99558. info->partitionclass[j]=oggpack_read(opb,4); /* only 0 to 15 legal */
  99559. if(maxclass<info->partitionclass[j])maxclass=info->partitionclass[j];
  99560. }
  99561. for(j=0;j<maxclass+1;j++){
  99562. info->class_dim[j]=oggpack_read(opb,3)+1; /* 1 to 8 */
  99563. info->class_subs[j]=oggpack_read(opb,2); /* 0,1,2,3 bits */
  99564. if(info->class_subs[j]<0)
  99565. goto err_out;
  99566. if(info->class_subs[j])info->class_book[j]=oggpack_read(opb,8);
  99567. if(info->class_book[j]<0 || info->class_book[j]>=ci->books)
  99568. goto err_out;
  99569. for(k=0;k<(1<<info->class_subs[j]);k++){
  99570. info->class_subbook[j][k]=oggpack_read(opb,8)-1;
  99571. if(info->class_subbook[j][k]<-1 || info->class_subbook[j][k]>=ci->books)
  99572. goto err_out;
  99573. }
  99574. }
  99575. info->mult=oggpack_read(opb,2)+1; /* only 1,2,3,4 legal now */
  99576. rangebits=oggpack_read(opb,4);
  99577. for(j=0,k=0;j<info->partitions;j++){
  99578. count+=info->class_dim[info->partitionclass[j]];
  99579. for(;k<count;k++){
  99580. int t=info->postlist[k+2]=oggpack_read(opb,rangebits);
  99581. if(t<0 || t>=(1<<rangebits))
  99582. goto err_out;
  99583. }
  99584. }
  99585. info->postlist[0]=0;
  99586. info->postlist[1]=1<<rangebits;
  99587. return(info);
  99588. err_out:
  99589. floor1_free_info(info);
  99590. return(NULL);
  99591. }
  99592. static int icomp(const void *a,const void *b){
  99593. return(**(int **)a-**(int **)b);
  99594. }
  99595. static vorbis_look_floor *floor1_look(vorbis_dsp_state *vd,
  99596. vorbis_info_floor *in){
  99597. int *sortpointer[VIF_POSIT+2];
  99598. vorbis_info_floor1 *info=(vorbis_info_floor1*)in;
  99599. vorbis_look_floor1 *look=(vorbis_look_floor1*)_ogg_calloc(1,sizeof(*look));
  99600. int i,j,n=0;
  99601. look->vi=info;
  99602. look->n=info->postlist[1];
  99603. for(i=0;i<info->partitions;i++)n+=info->class_dim[info->partitionclass[i]];
  99604. n+=2;
  99605. look->posts=n;
  99606. for(i=0;i<n;i++)sortpointer[i]=info->postlist+i;
  99607. qsort(sortpointer,n,sizeof(*sortpointer),icomp);
  99608. for(i=0;i<n;i++)look->forward_index[i]=sortpointer[i]-info->postlist;
  99609. for(i=0;i<n;i++)look->reverse_index[look->forward_index[i]]=i;
  99610. for(i=0;i<n;i++)look->sorted_index[i]=info->postlist[look->forward_index[i]];
  99611. switch(info->mult){
  99612. case 1: /* 1024 -> 256 */
  99613. look->quant_q=256;
  99614. break;
  99615. case 2: /* 1024 -> 128 */
  99616. look->quant_q=128;
  99617. break;
  99618. case 3: /* 1024 -> 86 */
  99619. look->quant_q=86;
  99620. break;
  99621. case 4: /* 1024 -> 64 */
  99622. look->quant_q=64;
  99623. break;
  99624. }
  99625. for(i=0;i<n-2;i++){
  99626. int lo=0;
  99627. int hi=1;
  99628. int lx=0;
  99629. int hx=look->n;
  99630. int currentx=info->postlist[i+2];
  99631. for(j=0;j<i+2;j++){
  99632. int x=info->postlist[j];
  99633. if(x>lx && x<currentx){
  99634. lo=j;
  99635. lx=x;
  99636. }
  99637. if(x<hx && x>currentx){
  99638. hi=j;
  99639. hx=x;
  99640. }
  99641. }
  99642. look->loneighbor[i]=lo;
  99643. look->hineighbor[i]=hi;
  99644. }
  99645. return(look);
  99646. }
  99647. static int render_point(int x0,int x1,int y0,int y1,int x){
  99648. y0&=0x7fff; /* mask off flag */
  99649. y1&=0x7fff;
  99650. {
  99651. int dy=y1-y0;
  99652. int adx=x1-x0;
  99653. int ady=abs(dy);
  99654. int err=ady*(x-x0);
  99655. int off=err/adx;
  99656. if(dy<0)return(y0-off);
  99657. return(y0+off);
  99658. }
  99659. }
  99660. static int vorbis_dBquant(const float *x){
  99661. int i= *x*7.3142857f+1023.5f;
  99662. if(i>1023)return(1023);
  99663. if(i<0)return(0);
  99664. return i;
  99665. }
  99666. static float FLOOR1_fromdB_LOOKUP[256]={
  99667. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  99668. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  99669. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  99670. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  99671. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  99672. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  99673. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  99674. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  99675. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  99676. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  99677. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  99678. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  99679. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  99680. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  99681. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  99682. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  99683. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  99684. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  99685. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  99686. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  99687. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  99688. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  99689. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  99690. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  99691. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  99692. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  99693. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  99694. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  99695. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  99696. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  99697. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  99698. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  99699. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  99700. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  99701. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  99702. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  99703. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  99704. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  99705. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  99706. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  99707. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  99708. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  99709. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  99710. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  99711. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  99712. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  99713. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  99714. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  99715. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  99716. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  99717. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  99718. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  99719. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  99720. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  99721. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  99722. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  99723. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  99724. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  99725. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  99726. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  99727. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  99728. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  99729. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  99730. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  99731. };
  99732. static void render_line(int x0,int x1,int y0,int y1,float *d){
  99733. int dy=y1-y0;
  99734. int adx=x1-x0;
  99735. int ady=abs(dy);
  99736. int base=dy/adx;
  99737. int sy=(dy<0?base-1:base+1);
  99738. int x=x0;
  99739. int y=y0;
  99740. int err=0;
  99741. ady-=abs(base*adx);
  99742. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99743. while(++x<x1){
  99744. err=err+ady;
  99745. if(err>=adx){
  99746. err-=adx;
  99747. y+=sy;
  99748. }else{
  99749. y+=base;
  99750. }
  99751. d[x]*=FLOOR1_fromdB_LOOKUP[y];
  99752. }
  99753. }
  99754. static void render_line0(int x0,int x1,int y0,int y1,int *d){
  99755. int dy=y1-y0;
  99756. int adx=x1-x0;
  99757. int ady=abs(dy);
  99758. int base=dy/adx;
  99759. int sy=(dy<0?base-1:base+1);
  99760. int x=x0;
  99761. int y=y0;
  99762. int err=0;
  99763. ady-=abs(base*adx);
  99764. d[x]=y;
  99765. while(++x<x1){
  99766. err=err+ady;
  99767. if(err>=adx){
  99768. err-=adx;
  99769. y+=sy;
  99770. }else{
  99771. y+=base;
  99772. }
  99773. d[x]=y;
  99774. }
  99775. }
  99776. static int accumulate_fit(const float *flr,const float *mdct,
  99777. int x0, int x1,lsfit_acc *a,
  99778. int n,vorbis_info_floor1 *info){
  99779. long i;
  99780. 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;
  99781. memset(a,0,sizeof(*a));
  99782. a->x0=x0;
  99783. a->x1=x1;
  99784. if(x1>=n)x1=n-1;
  99785. for(i=x0;i<=x1;i++){
  99786. int quantized=vorbis_dBquant(flr+i);
  99787. if(quantized){
  99788. if(mdct[i]+info->twofitatten>=flr[i]){
  99789. xa += i;
  99790. ya += quantized;
  99791. x2a += i*i;
  99792. y2a += quantized*quantized;
  99793. xya += i*quantized;
  99794. na++;
  99795. }else{
  99796. xb += i;
  99797. yb += quantized;
  99798. x2b += i*i;
  99799. y2b += quantized*quantized;
  99800. xyb += i*quantized;
  99801. nb++;
  99802. }
  99803. }
  99804. }
  99805. xb+=xa;
  99806. yb+=ya;
  99807. x2b+=x2a;
  99808. y2b+=y2a;
  99809. xyb+=xya;
  99810. nb+=na;
  99811. {
  99812. int weight=nb*info->twofitweight/(na+1);
  99813. a->xa=xa*weight+xb;
  99814. a->ya=ya*weight+yb;
  99815. a->x2a=x2a*weight+x2b;
  99816. a->y2a=y2a*weight+y2b;
  99817. a->xya=xya*weight+xyb;
  99818. a->an=na*weight+nb;
  99819. }
  99820. return(na);
  99821. }
  99822. static void fit_line(lsfit_acc *a,int fits,int *y0,int *y1){
  99823. long x=0,y=0,x2=0,y2=0,xy=0,an=0,i;
  99824. long x0=a[0].x0;
  99825. long x1=a[fits-1].x1;
  99826. for(i=0;i<fits;i++){
  99827. x+=a[i].xa;
  99828. y+=a[i].ya;
  99829. x2+=a[i].x2a;
  99830. y2+=a[i].y2a;
  99831. xy+=a[i].xya;
  99832. an+=a[i].an;
  99833. }
  99834. if(*y0>=0){
  99835. x+= x0;
  99836. y+= *y0;
  99837. x2+= x0 * x0;
  99838. y2+= *y0 * *y0;
  99839. xy+= *y0 * x0;
  99840. an++;
  99841. }
  99842. if(*y1>=0){
  99843. x+= x1;
  99844. y+= *y1;
  99845. x2+= x1 * x1;
  99846. y2+= *y1 * *y1;
  99847. xy+= *y1 * x1;
  99848. an++;
  99849. }
  99850. if(an){
  99851. double fx=x;
  99852. double fy=y;
  99853. double fx2=x2;
  99854. double fxy=xy;
  99855. double denom=1./(an*fx2-fx*fx);
  99856. double a=(fy*fx2-fxy*fx)*denom;
  99857. double b=(an*fxy-fx*fy)*denom;
  99858. *y0=rint(a+b*x0);
  99859. *y1=rint(a+b*x1);
  99860. if(*y0>1023)*y0=1023;
  99861. if(*y1>1023)*y1=1023;
  99862. if(*y0<0)*y0=0;
  99863. if(*y1<0)*y1=0;
  99864. }else{
  99865. *y0=0;
  99866. *y1=0;
  99867. }
  99868. }
  99869. static int inspect_error(int x0,int x1,int y0,int y1,const float *mask,
  99870. const float *mdct,
  99871. vorbis_info_floor1 *info){
  99872. int dy=y1-y0;
  99873. int adx=x1-x0;
  99874. int ady=abs(dy);
  99875. int base=dy/adx;
  99876. int sy=(dy<0?base-1:base+1);
  99877. int x=x0;
  99878. int y=y0;
  99879. int err=0;
  99880. int val=vorbis_dBquant(mask+x);
  99881. int mse=0;
  99882. int n=0;
  99883. ady-=abs(base*adx);
  99884. mse=(y-val);
  99885. mse*=mse;
  99886. n++;
  99887. if(mdct[x]+info->twofitatten>=mask[x]){
  99888. if(y+info->maxover<val)return(1);
  99889. if(y-info->maxunder>val)return(1);
  99890. }
  99891. while(++x<x1){
  99892. err=err+ady;
  99893. if(err>=adx){
  99894. err-=adx;
  99895. y+=sy;
  99896. }else{
  99897. y+=base;
  99898. }
  99899. val=vorbis_dBquant(mask+x);
  99900. mse+=((y-val)*(y-val));
  99901. n++;
  99902. if(mdct[x]+info->twofitatten>=mask[x]){
  99903. if(val){
  99904. if(y+info->maxover<val)return(1);
  99905. if(y-info->maxunder>val)return(1);
  99906. }
  99907. }
  99908. }
  99909. if(info->maxover*info->maxover/n>info->maxerr)return(0);
  99910. if(info->maxunder*info->maxunder/n>info->maxerr)return(0);
  99911. if(mse/n>info->maxerr)return(1);
  99912. return(0);
  99913. }
  99914. static int post_Y(int *A,int *B,int pos){
  99915. if(A[pos]<0)
  99916. return B[pos];
  99917. if(B[pos]<0)
  99918. return A[pos];
  99919. return (A[pos]+B[pos])>>1;
  99920. }
  99921. int *floor1_fit(vorbis_block *vb,void *look_,
  99922. const float *logmdct, /* in */
  99923. const float *logmask){
  99924. long i,j;
  99925. vorbis_look_floor1 *look = (vorbis_look_floor1*) look_;
  99926. vorbis_info_floor1 *info=look->vi;
  99927. long n=look->n;
  99928. long posts=look->posts;
  99929. long nonzero=0;
  99930. lsfit_acc fits[VIF_POSIT+1];
  99931. int fit_valueA[VIF_POSIT+2]; /* index by range list position */
  99932. int fit_valueB[VIF_POSIT+2]; /* index by range list position */
  99933. int loneighbor[VIF_POSIT+2]; /* sorted index of range list position (+2) */
  99934. int hineighbor[VIF_POSIT+2];
  99935. int *output=NULL;
  99936. int memo[VIF_POSIT+2];
  99937. for(i=0;i<posts;i++)fit_valueA[i]=-200; /* mark all unused */
  99938. for(i=0;i<posts;i++)fit_valueB[i]=-200; /* mark all unused */
  99939. for(i=0;i<posts;i++)loneighbor[i]=0; /* 0 for the implicit 0 post */
  99940. for(i=0;i<posts;i++)hineighbor[i]=1; /* 1 for the implicit post at n */
  99941. for(i=0;i<posts;i++)memo[i]=-1; /* no neighbor yet */
  99942. if(posts==0){
  99943. nonzero+=accumulate_fit(logmask,logmdct,0,n,fits,n,info);
  99944. }else{
  99945. for(i=0;i<posts-1;i++)
  99946. nonzero+=accumulate_fit(logmask,logmdct,look->sorted_index[i],
  99947. look->sorted_index[i+1],fits+i,
  99948. n,info);
  99949. }
  99950. if(nonzero){
  99951. int y0=-200;
  99952. int y1=-200;
  99953. fit_line(fits,posts-1,&y0,&y1);
  99954. fit_valueA[0]=y0;
  99955. fit_valueB[0]=y0;
  99956. fit_valueB[1]=y1;
  99957. fit_valueA[1]=y1;
  99958. for(i=2;i<posts;i++){
  99959. int sortpos=look->reverse_index[i];
  99960. int ln=loneighbor[sortpos];
  99961. int hn=hineighbor[sortpos];
  99962. if(memo[ln]!=hn){
  99963. int lsortpos=look->reverse_index[ln];
  99964. int hsortpos=look->reverse_index[hn];
  99965. memo[ln]=hn;
  99966. {
  99967. int lx=info->postlist[ln];
  99968. int hx=info->postlist[hn];
  99969. int ly=post_Y(fit_valueA,fit_valueB,ln);
  99970. int hy=post_Y(fit_valueA,fit_valueB,hn);
  99971. if(ly==-1 || hy==-1){
  99972. exit(1);
  99973. }
  99974. if(inspect_error(lx,hx,ly,hy,logmask,logmdct,info)){
  99975. int ly0=-200;
  99976. int ly1=-200;
  99977. int hy0=-200;
  99978. int hy1=-200;
  99979. fit_line(fits+lsortpos,sortpos-lsortpos,&ly0,&ly1);
  99980. fit_line(fits+sortpos,hsortpos-sortpos,&hy0,&hy1);
  99981. fit_valueB[ln]=ly0;
  99982. if(ln==0)fit_valueA[ln]=ly0;
  99983. fit_valueA[i]=ly1;
  99984. fit_valueB[i]=hy0;
  99985. fit_valueA[hn]=hy1;
  99986. if(hn==1)fit_valueB[hn]=hy1;
  99987. if(ly1>=0 || hy0>=0){
  99988. for(j=sortpos-1;j>=0;j--)
  99989. if(hineighbor[j]==hn)
  99990. hineighbor[j]=i;
  99991. else
  99992. break;
  99993. for(j=sortpos+1;j<posts;j++)
  99994. if(loneighbor[j]==ln)
  99995. loneighbor[j]=i;
  99996. else
  99997. break;
  99998. }
  99999. }else{
  100000. fit_valueA[i]=-200;
  100001. fit_valueB[i]=-200;
  100002. }
  100003. }
  100004. }
  100005. }
  100006. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  100007. output[0]=post_Y(fit_valueA,fit_valueB,0);
  100008. output[1]=post_Y(fit_valueA,fit_valueB,1);
  100009. for(i=2;i<posts;i++){
  100010. int ln=look->loneighbor[i-2];
  100011. int hn=look->hineighbor[i-2];
  100012. int x0=info->postlist[ln];
  100013. int x1=info->postlist[hn];
  100014. int y0=output[ln];
  100015. int y1=output[hn];
  100016. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  100017. int vx=post_Y(fit_valueA,fit_valueB,i);
  100018. if(vx>=0 && predicted!=vx){
  100019. output[i]=vx;
  100020. }else{
  100021. output[i]= predicted|0x8000;
  100022. }
  100023. }
  100024. }
  100025. return(output);
  100026. }
  100027. int *floor1_interpolate_fit(vorbis_block *vb,void *look_,
  100028. int *A,int *B,
  100029. int del){
  100030. long i;
  100031. vorbis_look_floor1* look = (vorbis_look_floor1*) look_;
  100032. long posts=look->posts;
  100033. int *output=NULL;
  100034. if(A && B){
  100035. output=(int*)_vorbis_block_alloc(vb,sizeof(*output)*posts);
  100036. for(i=0;i<posts;i++){
  100037. output[i]=((65536-del)*(A[i]&0x7fff)+del*(B[i]&0x7fff)+32768)>>16;
  100038. if(A[i]&0x8000 && B[i]&0x8000)output[i]|=0x8000;
  100039. }
  100040. }
  100041. return(output);
  100042. }
  100043. int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  100044. void*look_,
  100045. int *post,int *ilogmask){
  100046. long i,j;
  100047. vorbis_look_floor1 *look = (vorbis_look_floor1 *) look_;
  100048. vorbis_info_floor1 *info=look->vi;
  100049. long posts=look->posts;
  100050. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100051. int out[VIF_POSIT+2];
  100052. static_codebook **sbooks=ci->book_param;
  100053. codebook *books=ci->fullbooks;
  100054. static long seq=0;
  100055. if(post){
  100056. for(i=0;i<posts;i++){
  100057. int val=post[i]&0x7fff;
  100058. switch(info->mult){
  100059. case 1: /* 1024 -> 256 */
  100060. val>>=2;
  100061. break;
  100062. case 2: /* 1024 -> 128 */
  100063. val>>=3;
  100064. break;
  100065. case 3: /* 1024 -> 86 */
  100066. val/=12;
  100067. break;
  100068. case 4: /* 1024 -> 64 */
  100069. val>>=4;
  100070. break;
  100071. }
  100072. post[i]=val | (post[i]&0x8000);
  100073. }
  100074. out[0]=post[0];
  100075. out[1]=post[1];
  100076. for(i=2;i<posts;i++){
  100077. int ln=look->loneighbor[i-2];
  100078. int hn=look->hineighbor[i-2];
  100079. int x0=info->postlist[ln];
  100080. int x1=info->postlist[hn];
  100081. int y0=post[ln];
  100082. int y1=post[hn];
  100083. int predicted=render_point(x0,x1,y0,y1,info->postlist[i]);
  100084. if((post[i]&0x8000) || (predicted==post[i])){
  100085. post[i]=predicted|0x8000; /* in case there was roundoff jitter
  100086. in interpolation */
  100087. out[i]=0;
  100088. }else{
  100089. int headroom=(look->quant_q-predicted<predicted?
  100090. look->quant_q-predicted:predicted);
  100091. int val=post[i]-predicted;
  100092. if(val<0)
  100093. if(val<-headroom)
  100094. val=headroom-val-1;
  100095. else
  100096. val=-1-(val<<1);
  100097. else
  100098. if(val>=headroom)
  100099. val= val+headroom;
  100100. else
  100101. val<<=1;
  100102. out[i]=val;
  100103. post[ln]&=0x7fff;
  100104. post[hn]&=0x7fff;
  100105. }
  100106. }
  100107. oggpack_write(opb,1,1);
  100108. look->frames++;
  100109. look->postbits+=ilog(look->quant_q-1)*2;
  100110. oggpack_write(opb,out[0],ilog(look->quant_q-1));
  100111. oggpack_write(opb,out[1],ilog(look->quant_q-1));
  100112. for(i=0,j=2;i<info->partitions;i++){
  100113. int classx=info->partitionclass[i];
  100114. int cdim=info->class_dim[classx];
  100115. int csubbits=info->class_subs[classx];
  100116. int csub=1<<csubbits;
  100117. int bookas[8]={0,0,0,0,0,0,0,0};
  100118. int cval=0;
  100119. int cshift=0;
  100120. int k,l;
  100121. if(csubbits){
  100122. int maxval[8];
  100123. for(k=0;k<csub;k++){
  100124. int booknum=info->class_subbook[classx][k];
  100125. if(booknum<0){
  100126. maxval[k]=1;
  100127. }else{
  100128. maxval[k]=sbooks[info->class_subbook[classx][k]]->entries;
  100129. }
  100130. }
  100131. for(k=0;k<cdim;k++){
  100132. for(l=0;l<csub;l++){
  100133. int val=out[j+k];
  100134. if(val<maxval[l]){
  100135. bookas[k]=l;
  100136. break;
  100137. }
  100138. }
  100139. cval|= bookas[k]<<cshift;
  100140. cshift+=csubbits;
  100141. }
  100142. look->phrasebits+=
  100143. vorbis_book_encode(books+info->class_book[classx],cval,opb);
  100144. #ifdef TRAIN_FLOOR1
  100145. {
  100146. FILE *of;
  100147. char buffer[80];
  100148. sprintf(buffer,"line_%dx%ld_class%d.vqd",
  100149. vb->pcmend/2,posts-2,class);
  100150. of=fopen(buffer,"a");
  100151. fprintf(of,"%d\n",cval);
  100152. fclose(of);
  100153. }
  100154. #endif
  100155. }
  100156. for(k=0;k<cdim;k++){
  100157. int book=info->class_subbook[classx][bookas[k]];
  100158. if(book>=0){
  100159. if(out[j+k]<(books+book)->entries)
  100160. look->postbits+=vorbis_book_encode(books+book,
  100161. out[j+k],opb);
  100162. #ifdef TRAIN_FLOOR1
  100163. {
  100164. FILE *of;
  100165. char buffer[80];
  100166. sprintf(buffer,"line_%dx%ld_%dsub%d.vqd",
  100167. vb->pcmend/2,posts-2,class,bookas[k]);
  100168. of=fopen(buffer,"a");
  100169. fprintf(of,"%d\n",out[j+k]);
  100170. fclose(of);
  100171. }
  100172. #endif
  100173. }
  100174. }
  100175. j+=cdim;
  100176. }
  100177. {
  100178. int hx=0;
  100179. int lx=0;
  100180. int ly=post[0]*info->mult;
  100181. for(j=1;j<look->posts;j++){
  100182. int current=look->forward_index[j];
  100183. int hy=post[current]&0x7fff;
  100184. if(hy==post[current]){
  100185. hy*=info->mult;
  100186. hx=info->postlist[current];
  100187. render_line0(lx,hx,ly,hy,ilogmask);
  100188. lx=hx;
  100189. ly=hy;
  100190. }
  100191. }
  100192. for(j=hx;j<vb->pcmend/2;j++)ilogmask[j]=ly; /* be certain */
  100193. seq++;
  100194. return(1);
  100195. }
  100196. }else{
  100197. oggpack_write(opb,0,1);
  100198. memset(ilogmask,0,vb->pcmend/2*sizeof(*ilogmask));
  100199. seq++;
  100200. return(0);
  100201. }
  100202. }
  100203. static void *floor1_inverse1(vorbis_block *vb,vorbis_look_floor *in){
  100204. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  100205. vorbis_info_floor1 *info=look->vi;
  100206. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100207. int i,j,k;
  100208. codebook *books=ci->fullbooks;
  100209. if(oggpack_read(&vb->opb,1)==1){
  100210. int *fit_value=(int*)_vorbis_block_alloc(vb,(look->posts)*sizeof(*fit_value));
  100211. fit_value[0]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  100212. fit_value[1]=oggpack_read(&vb->opb,ilog(look->quant_q-1));
  100213. for(i=0,j=2;i<info->partitions;i++){
  100214. int classx=info->partitionclass[i];
  100215. int cdim=info->class_dim[classx];
  100216. int csubbits=info->class_subs[classx];
  100217. int csub=1<<csubbits;
  100218. int cval=0;
  100219. if(csubbits){
  100220. cval=vorbis_book_decode(books+info->class_book[classx],&vb->opb);
  100221. if(cval==-1)goto eop;
  100222. }
  100223. for(k=0;k<cdim;k++){
  100224. int book=info->class_subbook[classx][cval&(csub-1)];
  100225. cval>>=csubbits;
  100226. if(book>=0){
  100227. if((fit_value[j+k]=vorbis_book_decode(books+book,&vb->opb))==-1)
  100228. goto eop;
  100229. }else{
  100230. fit_value[j+k]=0;
  100231. }
  100232. }
  100233. j+=cdim;
  100234. }
  100235. for(i=2;i<look->posts;i++){
  100236. int predicted=render_point(info->postlist[look->loneighbor[i-2]],
  100237. info->postlist[look->hineighbor[i-2]],
  100238. fit_value[look->loneighbor[i-2]],
  100239. fit_value[look->hineighbor[i-2]],
  100240. info->postlist[i]);
  100241. int hiroom=look->quant_q-predicted;
  100242. int loroom=predicted;
  100243. int room=(hiroom<loroom?hiroom:loroom)<<1;
  100244. int val=fit_value[i];
  100245. if(val){
  100246. if(val>=room){
  100247. if(hiroom>loroom){
  100248. val = val-loroom;
  100249. }else{
  100250. val = -1-(val-hiroom);
  100251. }
  100252. }else{
  100253. if(val&1){
  100254. val= -((val+1)>>1);
  100255. }else{
  100256. val>>=1;
  100257. }
  100258. }
  100259. fit_value[i]=val+predicted;
  100260. fit_value[look->loneighbor[i-2]]&=0x7fff;
  100261. fit_value[look->hineighbor[i-2]]&=0x7fff;
  100262. }else{
  100263. fit_value[i]=predicted|0x8000;
  100264. }
  100265. }
  100266. return(fit_value);
  100267. }
  100268. eop:
  100269. return(NULL);
  100270. }
  100271. static int floor1_inverse2(vorbis_block *vb,vorbis_look_floor *in,void *memo,
  100272. float *out){
  100273. vorbis_look_floor1 *look=(vorbis_look_floor1 *)in;
  100274. vorbis_info_floor1 *info=look->vi;
  100275. codec_setup_info *ci=(codec_setup_info*)vb->vd->vi->codec_setup;
  100276. int n=ci->blocksizes[vb->W]/2;
  100277. int j;
  100278. if(memo){
  100279. int *fit_value=(int *)memo;
  100280. int hx=0;
  100281. int lx=0;
  100282. int ly=fit_value[0]*info->mult;
  100283. for(j=1;j<look->posts;j++){
  100284. int current=look->forward_index[j];
  100285. int hy=fit_value[current]&0x7fff;
  100286. if(hy==fit_value[current]){
  100287. hy*=info->mult;
  100288. hx=info->postlist[current];
  100289. render_line(lx,hx,ly,hy,out);
  100290. lx=hx;
  100291. ly=hy;
  100292. }
  100293. }
  100294. for(j=hx;j<n;j++)out[j]*=FLOOR1_fromdB_LOOKUP[ly]; /* be certain */
  100295. return(1);
  100296. }
  100297. memset(out,0,sizeof(*out)*n);
  100298. return(0);
  100299. }
  100300. vorbis_func_floor floor1_exportbundle={
  100301. &floor1_pack,&floor1_unpack,&floor1_look,&floor1_free_info,
  100302. &floor1_free_look,&floor1_inverse1,&floor1_inverse2
  100303. };
  100304. #endif
  100305. /*** End of inlined file: floor1.c ***/
  100306. /*** Start of inlined file: info.c ***/
  100307. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100308. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100309. // tasks..
  100310. #if JUCE_MSVC
  100311. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100312. #endif
  100313. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100314. #if JUCE_USE_OGGVORBIS
  100315. #include <stdlib.h>
  100316. #include <string.h>
  100317. #include <ctype.h>
  100318. static void _v_writestring(oggpack_buffer *o, const char *s, int bytes){
  100319. while(bytes--){
  100320. oggpack_write(o,*s++,8);
  100321. }
  100322. }
  100323. static void _v_readstring(oggpack_buffer *o,char *buf,int bytes){
  100324. while(bytes--){
  100325. *buf++=oggpack_read(o,8);
  100326. }
  100327. }
  100328. void vorbis_comment_init(vorbis_comment *vc){
  100329. memset(vc,0,sizeof(*vc));
  100330. }
  100331. void vorbis_comment_add(vorbis_comment *vc,char *comment){
  100332. vc->user_comments=(char**)_ogg_realloc(vc->user_comments,
  100333. (vc->comments+2)*sizeof(*vc->user_comments));
  100334. vc->comment_lengths=(int*)_ogg_realloc(vc->comment_lengths,
  100335. (vc->comments+2)*sizeof(*vc->comment_lengths));
  100336. vc->comment_lengths[vc->comments]=strlen(comment);
  100337. vc->user_comments[vc->comments]=(char*)_ogg_malloc(vc->comment_lengths[vc->comments]+1);
  100338. strcpy(vc->user_comments[vc->comments], comment);
  100339. vc->comments++;
  100340. vc->user_comments[vc->comments]=NULL;
  100341. }
  100342. void vorbis_comment_add_tag(vorbis_comment *vc, const char *tag, char *contents){
  100343. char *comment=(char*)alloca(strlen(tag)+strlen(contents)+2); /* +2 for = and \0 */
  100344. strcpy(comment, tag);
  100345. strcat(comment, "=");
  100346. strcat(comment, contents);
  100347. vorbis_comment_add(vc, comment);
  100348. }
  100349. static int tagcompare(const char *s1, const char *s2, int n){
  100350. int c=0;
  100351. while(c < n){
  100352. if(toupper(s1[c]) != toupper(s2[c]))
  100353. return !0;
  100354. c++;
  100355. }
  100356. return 0;
  100357. }
  100358. char *vorbis_comment_query(vorbis_comment *vc, char *tag, int count){
  100359. long i;
  100360. int found = 0;
  100361. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100362. char *fulltag = (char*)alloca(taglen+ 1);
  100363. strcpy(fulltag, tag);
  100364. strcat(fulltag, "=");
  100365. for(i=0;i<vc->comments;i++){
  100366. if(!tagcompare(vc->user_comments[i], fulltag, taglen)){
  100367. if(count == found)
  100368. return vc->user_comments[i] + taglen;
  100369. else
  100370. found++;
  100371. }
  100372. }
  100373. return NULL; /* didn't find anything */
  100374. }
  100375. int vorbis_comment_query_count(vorbis_comment *vc, char *tag){
  100376. int i,count=0;
  100377. int taglen = strlen(tag)+1; /* +1 for the = we append */
  100378. char *fulltag = (char*)alloca(taglen+1);
  100379. strcpy(fulltag,tag);
  100380. strcat(fulltag, "=");
  100381. for(i=0;i<vc->comments;i++){
  100382. if(!tagcompare(vc->user_comments[i], fulltag, taglen))
  100383. count++;
  100384. }
  100385. return count;
  100386. }
  100387. void vorbis_comment_clear(vorbis_comment *vc){
  100388. if(vc){
  100389. long i;
  100390. for(i=0;i<vc->comments;i++)
  100391. if(vc->user_comments[i])_ogg_free(vc->user_comments[i]);
  100392. if(vc->user_comments)_ogg_free(vc->user_comments);
  100393. if(vc->comment_lengths)_ogg_free(vc->comment_lengths);
  100394. if(vc->vendor)_ogg_free(vc->vendor);
  100395. }
  100396. memset(vc,0,sizeof(*vc));
  100397. }
  100398. int vorbis_info_blocksize(vorbis_info *vi,int zo){
  100399. codec_setup_info *ci = (codec_setup_info*)vi->codec_setup;
  100400. return ci ? ci->blocksizes[zo] : -1;
  100401. }
  100402. void vorbis_info_init(vorbis_info *vi){
  100403. memset(vi,0,sizeof(*vi));
  100404. vi->codec_setup=_ogg_calloc(1,sizeof(codec_setup_info));
  100405. }
  100406. void vorbis_info_clear(vorbis_info *vi){
  100407. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100408. int i;
  100409. if(ci){
  100410. for(i=0;i<ci->modes;i++)
  100411. if(ci->mode_param[i])_ogg_free(ci->mode_param[i]);
  100412. for(i=0;i<ci->maps;i++) /* unpack does the range checking */
  100413. _mapping_P[ci->map_type[i]]->free_info(ci->map_param[i]);
  100414. for(i=0;i<ci->floors;i++) /* unpack does the range checking */
  100415. _floor_P[ci->floor_type[i]]->free_info(ci->floor_param[i]);
  100416. for(i=0;i<ci->residues;i++) /* unpack does the range checking */
  100417. _residue_P[ci->residue_type[i]]->free_info(ci->residue_param[i]);
  100418. for(i=0;i<ci->books;i++){
  100419. if(ci->book_param[i]){
  100420. vorbis_staticbook_destroy(ci->book_param[i]);
  100421. }
  100422. if(ci->fullbooks)
  100423. vorbis_book_clear(ci->fullbooks+i);
  100424. }
  100425. if(ci->fullbooks)
  100426. _ogg_free(ci->fullbooks);
  100427. for(i=0;i<ci->psys;i++)
  100428. _vi_psy_free(ci->psy_param[i]);
  100429. _ogg_free(ci);
  100430. }
  100431. memset(vi,0,sizeof(*vi));
  100432. }
  100433. static int _vorbis_unpack_info(vorbis_info *vi,oggpack_buffer *opb){
  100434. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100435. if(!ci)return(OV_EFAULT);
  100436. vi->version=oggpack_read(opb,32);
  100437. if(vi->version!=0)return(OV_EVERSION);
  100438. vi->channels=oggpack_read(opb,8);
  100439. vi->rate=oggpack_read(opb,32);
  100440. vi->bitrate_upper=oggpack_read(opb,32);
  100441. vi->bitrate_nominal=oggpack_read(opb,32);
  100442. vi->bitrate_lower=oggpack_read(opb,32);
  100443. ci->blocksizes[0]=1<<oggpack_read(opb,4);
  100444. ci->blocksizes[1]=1<<oggpack_read(opb,4);
  100445. if(vi->rate<1)goto err_out;
  100446. if(vi->channels<1)goto err_out;
  100447. if(ci->blocksizes[0]<8)goto err_out;
  100448. if(ci->blocksizes[1]<ci->blocksizes[0])goto err_out;
  100449. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100450. return(0);
  100451. err_out:
  100452. vorbis_info_clear(vi);
  100453. return(OV_EBADHEADER);
  100454. }
  100455. static int _vorbis_unpack_comment(vorbis_comment *vc,oggpack_buffer *opb){
  100456. int i;
  100457. int vendorlen=oggpack_read(opb,32);
  100458. if(vendorlen<0)goto err_out;
  100459. vc->vendor=(char*)_ogg_calloc(vendorlen+1,1);
  100460. _v_readstring(opb,vc->vendor,vendorlen);
  100461. vc->comments=oggpack_read(opb,32);
  100462. if(vc->comments<0)goto err_out;
  100463. vc->user_comments=(char**)_ogg_calloc(vc->comments+1,sizeof(*vc->user_comments));
  100464. vc->comment_lengths=(int*)_ogg_calloc(vc->comments+1, sizeof(*vc->comment_lengths));
  100465. for(i=0;i<vc->comments;i++){
  100466. int len=oggpack_read(opb,32);
  100467. if(len<0)goto err_out;
  100468. vc->comment_lengths[i]=len;
  100469. vc->user_comments[i]=(char*)_ogg_calloc(len+1,1);
  100470. _v_readstring(opb,vc->user_comments[i],len);
  100471. }
  100472. if(oggpack_read(opb,1)!=1)goto err_out; /* EOP check */
  100473. return(0);
  100474. err_out:
  100475. vorbis_comment_clear(vc);
  100476. return(OV_EBADHEADER);
  100477. }
  100478. static int _vorbis_unpack_books(vorbis_info *vi,oggpack_buffer *opb){
  100479. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100480. int i;
  100481. if(!ci)return(OV_EFAULT);
  100482. ci->books=oggpack_read(opb,8)+1;
  100483. for(i=0;i<ci->books;i++){
  100484. ci->book_param[i]=(static_codebook*)_ogg_calloc(1,sizeof(*ci->book_param[i]));
  100485. if(vorbis_staticbook_unpack(opb,ci->book_param[i]))goto err_out;
  100486. }
  100487. {
  100488. int times=oggpack_read(opb,6)+1;
  100489. for(i=0;i<times;i++){
  100490. int test=oggpack_read(opb,16);
  100491. if(test<0 || test>=VI_TIMEB)goto err_out;
  100492. }
  100493. }
  100494. ci->floors=oggpack_read(opb,6)+1;
  100495. for(i=0;i<ci->floors;i++){
  100496. ci->floor_type[i]=oggpack_read(opb,16);
  100497. if(ci->floor_type[i]<0 || ci->floor_type[i]>=VI_FLOORB)goto err_out;
  100498. ci->floor_param[i]=_floor_P[ci->floor_type[i]]->unpack(vi,opb);
  100499. if(!ci->floor_param[i])goto err_out;
  100500. }
  100501. ci->residues=oggpack_read(opb,6)+1;
  100502. for(i=0;i<ci->residues;i++){
  100503. ci->residue_type[i]=oggpack_read(opb,16);
  100504. if(ci->residue_type[i]<0 || ci->residue_type[i]>=VI_RESB)goto err_out;
  100505. ci->residue_param[i]=_residue_P[ci->residue_type[i]]->unpack(vi,opb);
  100506. if(!ci->residue_param[i])goto err_out;
  100507. }
  100508. ci->maps=oggpack_read(opb,6)+1;
  100509. for(i=0;i<ci->maps;i++){
  100510. ci->map_type[i]=oggpack_read(opb,16);
  100511. if(ci->map_type[i]<0 || ci->map_type[i]>=VI_MAPB)goto err_out;
  100512. ci->map_param[i]=_mapping_P[ci->map_type[i]]->unpack(vi,opb);
  100513. if(!ci->map_param[i])goto err_out;
  100514. }
  100515. ci->modes=oggpack_read(opb,6)+1;
  100516. for(i=0;i<ci->modes;i++){
  100517. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*ci->mode_param[i]));
  100518. ci->mode_param[i]->blockflag=oggpack_read(opb,1);
  100519. ci->mode_param[i]->windowtype=oggpack_read(opb,16);
  100520. ci->mode_param[i]->transformtype=oggpack_read(opb,16);
  100521. ci->mode_param[i]->mapping=oggpack_read(opb,8);
  100522. if(ci->mode_param[i]->windowtype>=VI_WINDOWB)goto err_out;
  100523. if(ci->mode_param[i]->transformtype>=VI_WINDOWB)goto err_out;
  100524. if(ci->mode_param[i]->mapping>=ci->maps)goto err_out;
  100525. }
  100526. if(oggpack_read(opb,1)!=1)goto err_out; /* top level EOP check */
  100527. return(0);
  100528. err_out:
  100529. vorbis_info_clear(vi);
  100530. return(OV_EBADHEADER);
  100531. }
  100532. int vorbis_synthesis_headerin(vorbis_info *vi,vorbis_comment *vc,ogg_packet *op){
  100533. oggpack_buffer opb;
  100534. if(op){
  100535. oggpack_readinit(&opb,op->packet,op->bytes);
  100536. {
  100537. char buffer[6];
  100538. int packtype=oggpack_read(&opb,8);
  100539. memset(buffer,0,6);
  100540. _v_readstring(&opb,buffer,6);
  100541. if(memcmp(buffer,"vorbis",6)){
  100542. return(OV_ENOTVORBIS);
  100543. }
  100544. switch(packtype){
  100545. case 0x01: /* least significant *bit* is read first */
  100546. if(!op->b_o_s){
  100547. return(OV_EBADHEADER);
  100548. }
  100549. if(vi->rate!=0){
  100550. return(OV_EBADHEADER);
  100551. }
  100552. return(_vorbis_unpack_info(vi,&opb));
  100553. case 0x03: /* least significant *bit* is read first */
  100554. if(vi->rate==0){
  100555. return(OV_EBADHEADER);
  100556. }
  100557. return(_vorbis_unpack_comment(vc,&opb));
  100558. case 0x05: /* least significant *bit* is read first */
  100559. if(vi->rate==0 || vc->vendor==NULL){
  100560. return(OV_EBADHEADER);
  100561. }
  100562. return(_vorbis_unpack_books(vi,&opb));
  100563. default:
  100564. return(OV_EBADHEADER);
  100565. break;
  100566. }
  100567. }
  100568. }
  100569. return(OV_EBADHEADER);
  100570. }
  100571. static int _vorbis_pack_info(oggpack_buffer *opb,vorbis_info *vi){
  100572. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100573. if(!ci)return(OV_EFAULT);
  100574. oggpack_write(opb,0x01,8);
  100575. _v_writestring(opb,"vorbis", 6);
  100576. oggpack_write(opb,0x00,32);
  100577. oggpack_write(opb,vi->channels,8);
  100578. oggpack_write(opb,vi->rate,32);
  100579. oggpack_write(opb,vi->bitrate_upper,32);
  100580. oggpack_write(opb,vi->bitrate_nominal,32);
  100581. oggpack_write(opb,vi->bitrate_lower,32);
  100582. oggpack_write(opb,ilog2(ci->blocksizes[0]),4);
  100583. oggpack_write(opb,ilog2(ci->blocksizes[1]),4);
  100584. oggpack_write(opb,1,1);
  100585. return(0);
  100586. }
  100587. static int _vorbis_pack_comment(oggpack_buffer *opb,vorbis_comment *vc){
  100588. char temp[]="Xiph.Org libVorbis I 20050304";
  100589. int bytes = strlen(temp);
  100590. oggpack_write(opb,0x03,8);
  100591. _v_writestring(opb,"vorbis", 6);
  100592. oggpack_write(opb,bytes,32);
  100593. _v_writestring(opb,temp, bytes);
  100594. oggpack_write(opb,vc->comments,32);
  100595. if(vc->comments){
  100596. int i;
  100597. for(i=0;i<vc->comments;i++){
  100598. if(vc->user_comments[i]){
  100599. oggpack_write(opb,vc->comment_lengths[i],32);
  100600. _v_writestring(opb,vc->user_comments[i], vc->comment_lengths[i]);
  100601. }else{
  100602. oggpack_write(opb,0,32);
  100603. }
  100604. }
  100605. }
  100606. oggpack_write(opb,1,1);
  100607. return(0);
  100608. }
  100609. static int _vorbis_pack_books(oggpack_buffer *opb,vorbis_info *vi){
  100610. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  100611. int i;
  100612. if(!ci)return(OV_EFAULT);
  100613. oggpack_write(opb,0x05,8);
  100614. _v_writestring(opb,"vorbis", 6);
  100615. oggpack_write(opb,ci->books-1,8);
  100616. for(i=0;i<ci->books;i++)
  100617. if(vorbis_staticbook_pack(ci->book_param[i],opb))goto err_out;
  100618. oggpack_write(opb,0,6);
  100619. oggpack_write(opb,0,16);
  100620. oggpack_write(opb,ci->floors-1,6);
  100621. for(i=0;i<ci->floors;i++){
  100622. oggpack_write(opb,ci->floor_type[i],16);
  100623. if(_floor_P[ci->floor_type[i]]->pack)
  100624. _floor_P[ci->floor_type[i]]->pack(ci->floor_param[i],opb);
  100625. else
  100626. goto err_out;
  100627. }
  100628. oggpack_write(opb,ci->residues-1,6);
  100629. for(i=0;i<ci->residues;i++){
  100630. oggpack_write(opb,ci->residue_type[i],16);
  100631. _residue_P[ci->residue_type[i]]->pack(ci->residue_param[i],opb);
  100632. }
  100633. oggpack_write(opb,ci->maps-1,6);
  100634. for(i=0;i<ci->maps;i++){
  100635. oggpack_write(opb,ci->map_type[i],16);
  100636. _mapping_P[ci->map_type[i]]->pack(vi,ci->map_param[i],opb);
  100637. }
  100638. oggpack_write(opb,ci->modes-1,6);
  100639. for(i=0;i<ci->modes;i++){
  100640. oggpack_write(opb,ci->mode_param[i]->blockflag,1);
  100641. oggpack_write(opb,ci->mode_param[i]->windowtype,16);
  100642. oggpack_write(opb,ci->mode_param[i]->transformtype,16);
  100643. oggpack_write(opb,ci->mode_param[i]->mapping,8);
  100644. }
  100645. oggpack_write(opb,1,1);
  100646. return(0);
  100647. err_out:
  100648. return(-1);
  100649. }
  100650. int vorbis_commentheader_out(vorbis_comment *vc,
  100651. ogg_packet *op){
  100652. oggpack_buffer opb;
  100653. oggpack_writeinit(&opb);
  100654. if(_vorbis_pack_comment(&opb,vc)) return OV_EIMPL;
  100655. op->packet = (unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100656. memcpy(op->packet, opb.buffer, oggpack_bytes(&opb));
  100657. op->bytes=oggpack_bytes(&opb);
  100658. op->b_o_s=0;
  100659. op->e_o_s=0;
  100660. op->granulepos=0;
  100661. op->packetno=1;
  100662. return 0;
  100663. }
  100664. int vorbis_analysis_headerout(vorbis_dsp_state *v,
  100665. vorbis_comment *vc,
  100666. ogg_packet *op,
  100667. ogg_packet *op_comm,
  100668. ogg_packet *op_code){
  100669. int ret=OV_EIMPL;
  100670. vorbis_info *vi=v->vi;
  100671. oggpack_buffer opb;
  100672. private_state *b=(private_state*)v->backend_state;
  100673. if(!b){
  100674. ret=OV_EFAULT;
  100675. goto err_out;
  100676. }
  100677. oggpack_writeinit(&opb);
  100678. if(_vorbis_pack_info(&opb,vi))goto err_out;
  100679. if(b->header)_ogg_free(b->header);
  100680. b->header=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100681. memcpy(b->header,opb.buffer,oggpack_bytes(&opb));
  100682. op->packet=b->header;
  100683. op->bytes=oggpack_bytes(&opb);
  100684. op->b_o_s=1;
  100685. op->e_o_s=0;
  100686. op->granulepos=0;
  100687. op->packetno=0;
  100688. oggpack_reset(&opb);
  100689. if(_vorbis_pack_comment(&opb,vc))goto err_out;
  100690. if(b->header1)_ogg_free(b->header1);
  100691. b->header1=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100692. memcpy(b->header1,opb.buffer,oggpack_bytes(&opb));
  100693. op_comm->packet=b->header1;
  100694. op_comm->bytes=oggpack_bytes(&opb);
  100695. op_comm->b_o_s=0;
  100696. op_comm->e_o_s=0;
  100697. op_comm->granulepos=0;
  100698. op_comm->packetno=1;
  100699. oggpack_reset(&opb);
  100700. if(_vorbis_pack_books(&opb,vi))goto err_out;
  100701. if(b->header2)_ogg_free(b->header2);
  100702. b->header2=(unsigned char*) _ogg_malloc(oggpack_bytes(&opb));
  100703. memcpy(b->header2,opb.buffer,oggpack_bytes(&opb));
  100704. op_code->packet=b->header2;
  100705. op_code->bytes=oggpack_bytes(&opb);
  100706. op_code->b_o_s=0;
  100707. op_code->e_o_s=0;
  100708. op_code->granulepos=0;
  100709. op_code->packetno=2;
  100710. oggpack_writeclear(&opb);
  100711. return(0);
  100712. err_out:
  100713. oggpack_writeclear(&opb);
  100714. memset(op,0,sizeof(*op));
  100715. memset(op_comm,0,sizeof(*op_comm));
  100716. memset(op_code,0,sizeof(*op_code));
  100717. if(b->header)_ogg_free(b->header);
  100718. if(b->header1)_ogg_free(b->header1);
  100719. if(b->header2)_ogg_free(b->header2);
  100720. b->header=NULL;
  100721. b->header1=NULL;
  100722. b->header2=NULL;
  100723. return(ret);
  100724. }
  100725. double vorbis_granule_time(vorbis_dsp_state *v,ogg_int64_t granulepos){
  100726. if(granulepos>=0)
  100727. return((double)granulepos/v->vi->rate);
  100728. return(-1);
  100729. }
  100730. #endif
  100731. /*** End of inlined file: info.c ***/
  100732. /*** Start of inlined file: lpc.c ***/
  100733. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100734. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100735. // tasks..
  100736. #if JUCE_MSVC
  100737. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100738. #endif
  100739. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100740. #if JUCE_USE_OGGVORBIS
  100741. #include <stdlib.h>
  100742. #include <string.h>
  100743. #include <math.h>
  100744. float vorbis_lpc_from_data(float *data,float *lpci,int n,int m){
  100745. double *aut=(double*)alloca(sizeof(*aut)*(m+1));
  100746. double *lpc=(double*)alloca(sizeof(*lpc)*(m));
  100747. double error;
  100748. int i,j;
  100749. j=m+1;
  100750. while(j--){
  100751. double d=0; /* double needed for accumulator depth */
  100752. for(i=j;i<n;i++)d+=(double)data[i]*data[i-j];
  100753. aut[j]=d;
  100754. }
  100755. error=aut[0];
  100756. for(i=0;i<m;i++){
  100757. double r= -aut[i+1];
  100758. if(error==0){
  100759. memset(lpci,0,m*sizeof(*lpci));
  100760. return 0;
  100761. }
  100762. for(j=0;j<i;j++)r-=lpc[j]*aut[i-j];
  100763. r/=error;
  100764. lpc[i]=r;
  100765. for(j=0;j<i/2;j++){
  100766. double tmp=lpc[j];
  100767. lpc[j]+=r*lpc[i-1-j];
  100768. lpc[i-1-j]+=r*tmp;
  100769. }
  100770. if(i%2)lpc[j]+=lpc[j]*r;
  100771. error*=1.f-r*r;
  100772. }
  100773. for(j=0;j<m;j++)lpci[j]=(float)lpc[j];
  100774. return error;
  100775. }
  100776. void vorbis_lpc_predict(float *coeff,float *prime,int m,
  100777. float *data,long n){
  100778. long i,j,o,p;
  100779. float y;
  100780. float *work=(float*)alloca(sizeof(*work)*(m+n));
  100781. if(!prime)
  100782. for(i=0;i<m;i++)
  100783. work[i]=0.f;
  100784. else
  100785. for(i=0;i<m;i++)
  100786. work[i]=prime[i];
  100787. for(i=0;i<n;i++){
  100788. y=0;
  100789. o=i;
  100790. p=m;
  100791. for(j=0;j<m;j++)
  100792. y-=work[o++]*coeff[--p];
  100793. data[i]=work[o]=y;
  100794. }
  100795. }
  100796. #endif
  100797. /*** End of inlined file: lpc.c ***/
  100798. /*** Start of inlined file: lsp.c ***/
  100799. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100800. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100801. // tasks..
  100802. #if JUCE_MSVC
  100803. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100804. #endif
  100805. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100806. #if JUCE_USE_OGGVORBIS
  100807. #include <math.h>
  100808. #include <string.h>
  100809. #include <stdlib.h>
  100810. /*** Start of inlined file: lookup.h ***/
  100811. #ifndef _V_LOOKUP_H_
  100812. #ifdef FLOAT_LOOKUP
  100813. extern float vorbis_coslook(float a);
  100814. extern float vorbis_invsqlook(float a);
  100815. extern float vorbis_invsq2explook(int a);
  100816. extern float vorbis_fromdBlook(float a);
  100817. #endif
  100818. #ifdef INT_LOOKUP
  100819. extern long vorbis_invsqlook_i(long a,long e);
  100820. extern long vorbis_coslook_i(long a);
  100821. extern float vorbis_fromdBlook_i(long a);
  100822. #endif
  100823. #endif
  100824. /*** End of inlined file: lookup.h ***/
  100825. #define FLOAT_LOOKUP
  100826. #undef INT_LOOKUP
  100827. #ifdef FLOAT_LOOKUP
  100828. /*** Start of inlined file: lookup.c ***/
  100829. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  100830. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  100831. // tasks..
  100832. #if JUCE_MSVC
  100833. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  100834. #endif
  100835. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  100836. #if JUCE_USE_OGGVORBIS
  100837. #include <math.h>
  100838. /*** Start of inlined file: lookup.h ***/
  100839. #ifndef _V_LOOKUP_H_
  100840. #ifdef FLOAT_LOOKUP
  100841. extern float vorbis_coslook(float a);
  100842. extern float vorbis_invsqlook(float a);
  100843. extern float vorbis_invsq2explook(int a);
  100844. extern float vorbis_fromdBlook(float a);
  100845. #endif
  100846. #ifdef INT_LOOKUP
  100847. extern long vorbis_invsqlook_i(long a,long e);
  100848. extern long vorbis_coslook_i(long a);
  100849. extern float vorbis_fromdBlook_i(long a);
  100850. #endif
  100851. #endif
  100852. /*** End of inlined file: lookup.h ***/
  100853. /*** Start of inlined file: lookup_data.h ***/
  100854. #ifndef _V_LOOKUP_DATA_H_
  100855. #ifdef FLOAT_LOOKUP
  100856. #define COS_LOOKUP_SZ 128
  100857. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  100858. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  100859. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  100860. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  100861. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  100862. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  100863. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  100864. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  100865. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  100866. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  100867. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  100868. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  100869. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  100870. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  100871. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  100872. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  100873. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  100874. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  100875. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  100876. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  100877. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  100878. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  100879. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  100880. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  100881. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  100882. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  100883. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  100884. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  100885. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  100886. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  100887. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  100888. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  100889. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  100890. -1.0000000000000f,
  100891. };
  100892. #define INVSQ_LOOKUP_SZ 32
  100893. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  100894. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  100895. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  100896. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  100897. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  100898. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  100899. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  100900. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  100901. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  100902. 1.000000000000f,
  100903. };
  100904. #define INVSQ2EXP_LOOKUP_MIN (-32)
  100905. #define INVSQ2EXP_LOOKUP_MAX 32
  100906. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  100907. INVSQ2EXP_LOOKUP_MIN+1]={
  100908. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  100909. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  100910. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  100911. 1024.f, 724.0773439f, 512.f, 362.038672f,
  100912. 256.f, 181.019336f, 128.f, 90.50966799f,
  100913. 64.f, 45.254834f, 32.f, 22.627417f,
  100914. 16.f, 11.3137085f, 8.f, 5.656854249f,
  100915. 4.f, 2.828427125f, 2.f, 1.414213562f,
  100916. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  100917. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  100918. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  100919. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  100920. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  100921. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  100922. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  100923. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  100924. 1.525878906e-05f,
  100925. };
  100926. #endif
  100927. #define FROMdB_LOOKUP_SZ 35
  100928. #define FROMdB2_LOOKUP_SZ 32
  100929. #define FROMdB_SHIFT 5
  100930. #define FROMdB2_SHIFT 3
  100931. #define FROMdB2_MASK 31
  100932. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  100933. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  100934. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  100935. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  100936. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  100937. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  100938. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  100939. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  100940. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  100941. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  100942. };
  100943. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  100944. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  100945. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  100946. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  100947. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  100948. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  100949. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  100950. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  100951. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  100952. };
  100953. #ifdef INT_LOOKUP
  100954. #define INVSQ_LOOKUP_I_SHIFT 10
  100955. #define INVSQ_LOOKUP_I_MASK 1023
  100956. static long INVSQ_LOOKUP_I[64+1]={
  100957. 92682l, 91966l, 91267l, 90583l,
  100958. 89915l, 89261l, 88621l, 87995l,
  100959. 87381l, 86781l, 86192l, 85616l,
  100960. 85051l, 84497l, 83953l, 83420l,
  100961. 82897l, 82384l, 81880l, 81385l,
  100962. 80899l, 80422l, 79953l, 79492l,
  100963. 79039l, 78594l, 78156l, 77726l,
  100964. 77302l, 76885l, 76475l, 76072l,
  100965. 75674l, 75283l, 74898l, 74519l,
  100966. 74146l, 73778l, 73415l, 73058l,
  100967. 72706l, 72359l, 72016l, 71679l,
  100968. 71347l, 71019l, 70695l, 70376l,
  100969. 70061l, 69750l, 69444l, 69141l,
  100970. 68842l, 68548l, 68256l, 67969l,
  100971. 67685l, 67405l, 67128l, 66855l,
  100972. 66585l, 66318l, 66054l, 65794l,
  100973. 65536l,
  100974. };
  100975. #define COS_LOOKUP_I_SHIFT 9
  100976. #define COS_LOOKUP_I_MASK 511
  100977. #define COS_LOOKUP_I_SZ 128
  100978. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  100979. 16384l, 16379l, 16364l, 16340l,
  100980. 16305l, 16261l, 16207l, 16143l,
  100981. 16069l, 15986l, 15893l, 15791l,
  100982. 15679l, 15557l, 15426l, 15286l,
  100983. 15137l, 14978l, 14811l, 14635l,
  100984. 14449l, 14256l, 14053l, 13842l,
  100985. 13623l, 13395l, 13160l, 12916l,
  100986. 12665l, 12406l, 12140l, 11866l,
  100987. 11585l, 11297l, 11003l, 10702l,
  100988. 10394l, 10080l, 9760l, 9434l,
  100989. 9102l, 8765l, 8423l, 8076l,
  100990. 7723l, 7366l, 7005l, 6639l,
  100991. 6270l, 5897l, 5520l, 5139l,
  100992. 4756l, 4370l, 3981l, 3590l,
  100993. 3196l, 2801l, 2404l, 2006l,
  100994. 1606l, 1205l, 804l, 402l,
  100995. 0l, -401l, -803l, -1204l,
  100996. -1605l, -2005l, -2403l, -2800l,
  100997. -3195l, -3589l, -3980l, -4369l,
  100998. -4755l, -5138l, -5519l, -5896l,
  100999. -6269l, -6638l, -7004l, -7365l,
  101000. -7722l, -8075l, -8422l, -8764l,
  101001. -9101l, -9433l, -9759l, -10079l,
  101002. -10393l, -10701l, -11002l, -11296l,
  101003. -11584l, -11865l, -12139l, -12405l,
  101004. -12664l, -12915l, -13159l, -13394l,
  101005. -13622l, -13841l, -14052l, -14255l,
  101006. -14448l, -14634l, -14810l, -14977l,
  101007. -15136l, -15285l, -15425l, -15556l,
  101008. -15678l, -15790l, -15892l, -15985l,
  101009. -16068l, -16142l, -16206l, -16260l,
  101010. -16304l, -16339l, -16363l, -16378l,
  101011. -16383l,
  101012. };
  101013. #endif
  101014. #endif
  101015. /*** End of inlined file: lookup_data.h ***/
  101016. #ifdef FLOAT_LOOKUP
  101017. float vorbis_coslook(float a){
  101018. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101019. int i=vorbis_ftoi(d-.5);
  101020. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101021. }
  101022. float vorbis_invsqlook(float a){
  101023. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101024. int i=vorbis_ftoi(d-.5f);
  101025. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101026. }
  101027. float vorbis_invsq2explook(int a){
  101028. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101029. }
  101030. #include <stdio.h>
  101031. float vorbis_fromdBlook(float a){
  101032. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101033. return (i<0)?1.f:
  101034. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101035. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101036. }
  101037. #endif
  101038. #ifdef INT_LOOKUP
  101039. long vorbis_invsqlook_i(long a,long e){
  101040. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101041. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101042. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101043. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101044. d)>>16); /* result 1.16 */
  101045. e+=32;
  101046. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101047. e=(e>>1)-8;
  101048. return(val>>e);
  101049. }
  101050. float vorbis_fromdBlook_i(long a){
  101051. int i=(-a)>>(12-FROMdB2_SHIFT);
  101052. return (i<0)?1.f:
  101053. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101054. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101055. }
  101056. long vorbis_coslook_i(long a){
  101057. int i=a>>COS_LOOKUP_I_SHIFT;
  101058. int d=a&COS_LOOKUP_I_MASK;
  101059. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101060. COS_LOOKUP_I_SHIFT);
  101061. }
  101062. #endif
  101063. #endif
  101064. /*** End of inlined file: lookup.c ***/
  101065. /* catch this in the build system; we #include for
  101066. compilers (like gcc) that can't inline across
  101067. modules */
  101068. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101069. float amp,float ampoffset){
  101070. int i;
  101071. float wdel=M_PI/ln;
  101072. vorbis_fpu_control fpu;
  101073. (void) fpu; // to avoid an unused variable warning
  101074. vorbis_fpu_setround(&fpu);
  101075. for(i=0;i<m;i++)lsp[i]=vorbis_coslook(lsp[i]);
  101076. i=0;
  101077. while(i<n){
  101078. int k=map[i];
  101079. int qexp;
  101080. float p=.7071067812f;
  101081. float q=.7071067812f;
  101082. float w=vorbis_coslook(wdel*k);
  101083. float *ftmp=lsp;
  101084. int c=m>>1;
  101085. do{
  101086. q*=ftmp[0]-w;
  101087. p*=ftmp[1]-w;
  101088. ftmp+=2;
  101089. }while(--c);
  101090. if(m&1){
  101091. q*=ftmp[0]-w;
  101092. q*=q;
  101093. p*=p*(1.f-w*w);
  101094. }else{
  101095. q*=q*(1.f+w);
  101096. p*=p*(1.f-w);
  101097. }
  101098. q=frexp(p+q,&qexp);
  101099. q=vorbis_fromdBlook(amp*
  101100. vorbis_invsqlook(q)*
  101101. vorbis_invsq2explook(qexp+m)-
  101102. ampoffset);
  101103. do{
  101104. curve[i++]*=q;
  101105. }while(map[i]==k);
  101106. }
  101107. vorbis_fpu_restore(fpu);
  101108. }
  101109. #else
  101110. #ifdef INT_LOOKUP
  101111. /*** Start of inlined file: lookup.c ***/
  101112. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101113. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101114. // tasks..
  101115. #if JUCE_MSVC
  101116. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101117. #endif
  101118. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101119. #if JUCE_USE_OGGVORBIS
  101120. #include <math.h>
  101121. /*** Start of inlined file: lookup.h ***/
  101122. #ifndef _V_LOOKUP_H_
  101123. #ifdef FLOAT_LOOKUP
  101124. extern float vorbis_coslook(float a);
  101125. extern float vorbis_invsqlook(float a);
  101126. extern float vorbis_invsq2explook(int a);
  101127. extern float vorbis_fromdBlook(float a);
  101128. #endif
  101129. #ifdef INT_LOOKUP
  101130. extern long vorbis_invsqlook_i(long a,long e);
  101131. extern long vorbis_coslook_i(long a);
  101132. extern float vorbis_fromdBlook_i(long a);
  101133. #endif
  101134. #endif
  101135. /*** End of inlined file: lookup.h ***/
  101136. /*** Start of inlined file: lookup_data.h ***/
  101137. #ifndef _V_LOOKUP_DATA_H_
  101138. #ifdef FLOAT_LOOKUP
  101139. #define COS_LOOKUP_SZ 128
  101140. static float COS_LOOKUP[COS_LOOKUP_SZ+1]={
  101141. +1.0000000000000f,+0.9996988186962f,+0.9987954562052f,+0.9972904566787f,
  101142. +0.9951847266722f,+0.9924795345987f,+0.9891765099648f,+0.9852776423889f,
  101143. +0.9807852804032f,+0.9757021300385f,+0.9700312531945f,+0.9637760657954f,
  101144. +0.9569403357322f,+0.9495281805930f,+0.9415440651830f,+0.9329927988347f,
  101145. +0.9238795325113f,+0.9142097557035f,+0.9039892931234f,+0.8932243011955f,
  101146. +0.8819212643484f,+0.8700869911087f,+0.8577286100003f,+0.8448535652497f,
  101147. +0.8314696123025f,+0.8175848131516f,+0.8032075314806f,+0.7883464276266f,
  101148. +0.7730104533627f,+0.7572088465065f,+0.7409511253550f,+0.7242470829515f,
  101149. +0.7071067811865f,+0.6895405447371f,+0.6715589548470f,+0.6531728429538f,
  101150. +0.6343932841636f,+0.6152315905806f,+0.5956993044924f,+0.5758081914178f,
  101151. +0.5555702330196f,+0.5349976198871f,+0.5141027441932f,+0.4928981922298f,
  101152. +0.4713967368260f,+0.4496113296546f,+0.4275550934303f,+0.4052413140050f,
  101153. +0.3826834323651f,+0.3598950365350f,+0.3368898533922f,+0.3136817403989f,
  101154. +0.2902846772545f,+0.2667127574749f,+0.2429801799033f,+0.2191012401569f,
  101155. +0.1950903220161f,+0.1709618887603f,+0.1467304744554f,+0.1224106751992f,
  101156. +0.0980171403296f,+0.0735645635997f,+0.0490676743274f,+0.0245412285229f,
  101157. +0.0000000000000f,-0.0245412285229f,-0.0490676743274f,-0.0735645635997f,
  101158. -0.0980171403296f,-0.1224106751992f,-0.1467304744554f,-0.1709618887603f,
  101159. -0.1950903220161f,-0.2191012401569f,-0.2429801799033f,-0.2667127574749f,
  101160. -0.2902846772545f,-0.3136817403989f,-0.3368898533922f,-0.3598950365350f,
  101161. -0.3826834323651f,-0.4052413140050f,-0.4275550934303f,-0.4496113296546f,
  101162. -0.4713967368260f,-0.4928981922298f,-0.5141027441932f,-0.5349976198871f,
  101163. -0.5555702330196f,-0.5758081914178f,-0.5956993044924f,-0.6152315905806f,
  101164. -0.6343932841636f,-0.6531728429538f,-0.6715589548470f,-0.6895405447371f,
  101165. -0.7071067811865f,-0.7242470829515f,-0.7409511253550f,-0.7572088465065f,
  101166. -0.7730104533627f,-0.7883464276266f,-0.8032075314806f,-0.8175848131516f,
  101167. -0.8314696123025f,-0.8448535652497f,-0.8577286100003f,-0.8700869911087f,
  101168. -0.8819212643484f,-0.8932243011955f,-0.9039892931234f,-0.9142097557035f,
  101169. -0.9238795325113f,-0.9329927988347f,-0.9415440651830f,-0.9495281805930f,
  101170. -0.9569403357322f,-0.9637760657954f,-0.9700312531945f,-0.9757021300385f,
  101171. -0.9807852804032f,-0.9852776423889f,-0.9891765099648f,-0.9924795345987f,
  101172. -0.9951847266722f,-0.9972904566787f,-0.9987954562052f,-0.9996988186962f,
  101173. -1.0000000000000f,
  101174. };
  101175. #define INVSQ_LOOKUP_SZ 32
  101176. static float INVSQ_LOOKUP[INVSQ_LOOKUP_SZ+1]={
  101177. 1.414213562373f,1.392621247646f,1.371988681140f,1.352246807566f,
  101178. 1.333333333333f,1.315191898443f,1.297771369046f,1.281025230441f,
  101179. 1.264911064067f,1.249390095109f,1.234426799697f,1.219988562661f,
  101180. 1.206045378311f,1.192569588000f,1.179535649239f,1.166919931983f,
  101181. 1.154700538379f,1.142857142857f,1.131370849898f,1.120224067222f,
  101182. 1.109400392450f,1.098884511590f,1.088662107904f,1.078719779941f,
  101183. 1.069044967650f,1.059625885652f,1.050451462878f,1.041511287847f,
  101184. 1.032795558989f,1.024295039463f,1.016001016002f,1.007905261358f,
  101185. 1.000000000000f,
  101186. };
  101187. #define INVSQ2EXP_LOOKUP_MIN (-32)
  101188. #define INVSQ2EXP_LOOKUP_MAX 32
  101189. static float INVSQ2EXP_LOOKUP[INVSQ2EXP_LOOKUP_MAX-\
  101190. INVSQ2EXP_LOOKUP_MIN+1]={
  101191. 65536.f, 46340.95001f, 32768.f, 23170.47501f,
  101192. 16384.f, 11585.2375f, 8192.f, 5792.618751f,
  101193. 4096.f, 2896.309376f, 2048.f, 1448.154688f,
  101194. 1024.f, 724.0773439f, 512.f, 362.038672f,
  101195. 256.f, 181.019336f, 128.f, 90.50966799f,
  101196. 64.f, 45.254834f, 32.f, 22.627417f,
  101197. 16.f, 11.3137085f, 8.f, 5.656854249f,
  101198. 4.f, 2.828427125f, 2.f, 1.414213562f,
  101199. 1.f, 0.7071067812f, 0.5f, 0.3535533906f,
  101200. 0.25f, 0.1767766953f, 0.125f, 0.08838834765f,
  101201. 0.0625f, 0.04419417382f, 0.03125f, 0.02209708691f,
  101202. 0.015625f, 0.01104854346f, 0.0078125f, 0.005524271728f,
  101203. 0.00390625f, 0.002762135864f, 0.001953125f, 0.001381067932f,
  101204. 0.0009765625f, 0.000690533966f, 0.00048828125f, 0.000345266983f,
  101205. 0.000244140625f,0.0001726334915f,0.0001220703125f,8.631674575e-05f,
  101206. 6.103515625e-05f,4.315837288e-05f,3.051757812e-05f,2.157918644e-05f,
  101207. 1.525878906e-05f,
  101208. };
  101209. #endif
  101210. #define FROMdB_LOOKUP_SZ 35
  101211. #define FROMdB2_LOOKUP_SZ 32
  101212. #define FROMdB_SHIFT 5
  101213. #define FROMdB2_SHIFT 3
  101214. #define FROMdB2_MASK 31
  101215. static float FROMdB_LOOKUP[FROMdB_LOOKUP_SZ]={
  101216. 1.f, 0.6309573445f, 0.3981071706f, 0.2511886432f,
  101217. 0.1584893192f, 0.1f, 0.06309573445f, 0.03981071706f,
  101218. 0.02511886432f, 0.01584893192f, 0.01f, 0.006309573445f,
  101219. 0.003981071706f, 0.002511886432f, 0.001584893192f, 0.001f,
  101220. 0.0006309573445f,0.0003981071706f,0.0002511886432f,0.0001584893192f,
  101221. 0.0001f,6.309573445e-05f,3.981071706e-05f,2.511886432e-05f,
  101222. 1.584893192e-05f, 1e-05f,6.309573445e-06f,3.981071706e-06f,
  101223. 2.511886432e-06f,1.584893192e-06f, 1e-06f,6.309573445e-07f,
  101224. 3.981071706e-07f,2.511886432e-07f,1.584893192e-07f,
  101225. };
  101226. static float FROMdB2_LOOKUP[FROMdB2_LOOKUP_SZ]={
  101227. 0.9928302478f, 0.9786445908f, 0.9646616199f, 0.9508784391f,
  101228. 0.9372921937f, 0.92390007f, 0.9106992942f, 0.8976871324f,
  101229. 0.8848608897f, 0.8722179097f, 0.8597555737f, 0.8474713009f,
  101230. 0.835362547f, 0.8234268041f, 0.8116616003f, 0.8000644989f,
  101231. 0.7886330981f, 0.7773650302f, 0.7662579617f, 0.755309592f,
  101232. 0.7445176537f, 0.7338799116f, 0.7233941627f, 0.7130582353f,
  101233. 0.7028699885f, 0.6928273125f, 0.6829281272f, 0.6731703824f,
  101234. 0.6635520573f, 0.6540711597f, 0.6447257262f, 0.6355138211f,
  101235. };
  101236. #ifdef INT_LOOKUP
  101237. #define INVSQ_LOOKUP_I_SHIFT 10
  101238. #define INVSQ_LOOKUP_I_MASK 1023
  101239. static long INVSQ_LOOKUP_I[64+1]={
  101240. 92682l, 91966l, 91267l, 90583l,
  101241. 89915l, 89261l, 88621l, 87995l,
  101242. 87381l, 86781l, 86192l, 85616l,
  101243. 85051l, 84497l, 83953l, 83420l,
  101244. 82897l, 82384l, 81880l, 81385l,
  101245. 80899l, 80422l, 79953l, 79492l,
  101246. 79039l, 78594l, 78156l, 77726l,
  101247. 77302l, 76885l, 76475l, 76072l,
  101248. 75674l, 75283l, 74898l, 74519l,
  101249. 74146l, 73778l, 73415l, 73058l,
  101250. 72706l, 72359l, 72016l, 71679l,
  101251. 71347l, 71019l, 70695l, 70376l,
  101252. 70061l, 69750l, 69444l, 69141l,
  101253. 68842l, 68548l, 68256l, 67969l,
  101254. 67685l, 67405l, 67128l, 66855l,
  101255. 66585l, 66318l, 66054l, 65794l,
  101256. 65536l,
  101257. };
  101258. #define COS_LOOKUP_I_SHIFT 9
  101259. #define COS_LOOKUP_I_MASK 511
  101260. #define COS_LOOKUP_I_SZ 128
  101261. static long COS_LOOKUP_I[COS_LOOKUP_I_SZ+1]={
  101262. 16384l, 16379l, 16364l, 16340l,
  101263. 16305l, 16261l, 16207l, 16143l,
  101264. 16069l, 15986l, 15893l, 15791l,
  101265. 15679l, 15557l, 15426l, 15286l,
  101266. 15137l, 14978l, 14811l, 14635l,
  101267. 14449l, 14256l, 14053l, 13842l,
  101268. 13623l, 13395l, 13160l, 12916l,
  101269. 12665l, 12406l, 12140l, 11866l,
  101270. 11585l, 11297l, 11003l, 10702l,
  101271. 10394l, 10080l, 9760l, 9434l,
  101272. 9102l, 8765l, 8423l, 8076l,
  101273. 7723l, 7366l, 7005l, 6639l,
  101274. 6270l, 5897l, 5520l, 5139l,
  101275. 4756l, 4370l, 3981l, 3590l,
  101276. 3196l, 2801l, 2404l, 2006l,
  101277. 1606l, 1205l, 804l, 402l,
  101278. 0l, -401l, -803l, -1204l,
  101279. -1605l, -2005l, -2403l, -2800l,
  101280. -3195l, -3589l, -3980l, -4369l,
  101281. -4755l, -5138l, -5519l, -5896l,
  101282. -6269l, -6638l, -7004l, -7365l,
  101283. -7722l, -8075l, -8422l, -8764l,
  101284. -9101l, -9433l, -9759l, -10079l,
  101285. -10393l, -10701l, -11002l, -11296l,
  101286. -11584l, -11865l, -12139l, -12405l,
  101287. -12664l, -12915l, -13159l, -13394l,
  101288. -13622l, -13841l, -14052l, -14255l,
  101289. -14448l, -14634l, -14810l, -14977l,
  101290. -15136l, -15285l, -15425l, -15556l,
  101291. -15678l, -15790l, -15892l, -15985l,
  101292. -16068l, -16142l, -16206l, -16260l,
  101293. -16304l, -16339l, -16363l, -16378l,
  101294. -16383l,
  101295. };
  101296. #endif
  101297. #endif
  101298. /*** End of inlined file: lookup_data.h ***/
  101299. #ifdef FLOAT_LOOKUP
  101300. float vorbis_coslook(float a){
  101301. double d=a*(.31830989*(float)COS_LOOKUP_SZ);
  101302. int i=vorbis_ftoi(d-.5);
  101303. return COS_LOOKUP[i]+ (d-i)*(COS_LOOKUP[i+1]-COS_LOOKUP[i]);
  101304. }
  101305. float vorbis_invsqlook(float a){
  101306. double d=a*(2.f*(float)INVSQ_LOOKUP_SZ)-(float)INVSQ_LOOKUP_SZ;
  101307. int i=vorbis_ftoi(d-.5f);
  101308. return INVSQ_LOOKUP[i]+ (d-i)*(INVSQ_LOOKUP[i+1]-INVSQ_LOOKUP[i]);
  101309. }
  101310. float vorbis_invsq2explook(int a){
  101311. return INVSQ2EXP_LOOKUP[a-INVSQ2EXP_LOOKUP_MIN];
  101312. }
  101313. #include <stdio.h>
  101314. float vorbis_fromdBlook(float a){
  101315. int i=vorbis_ftoi(a*((float)(-(1<<FROMdB2_SHIFT)))-.5f);
  101316. return (i<0)?1.f:
  101317. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101318. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101319. }
  101320. #endif
  101321. #ifdef INT_LOOKUP
  101322. long vorbis_invsqlook_i(long a,long e){
  101323. long i=(a&0x7fff)>>(INVSQ_LOOKUP_I_SHIFT-1);
  101324. long d=(a&INVSQ_LOOKUP_I_MASK)<<(16-INVSQ_LOOKUP_I_SHIFT); /* 0.16 */
  101325. long val=INVSQ_LOOKUP_I[i]- /* 1.16 */
  101326. (((INVSQ_LOOKUP_I[i]-INVSQ_LOOKUP_I[i+1])* /* 0.16 */
  101327. d)>>16); /* result 1.16 */
  101328. e+=32;
  101329. if(e&1)val=(val*5792)>>13; /* multiply val by 1/sqrt(2) */
  101330. e=(e>>1)-8;
  101331. return(val>>e);
  101332. }
  101333. float vorbis_fromdBlook_i(long a){
  101334. int i=(-a)>>(12-FROMdB2_SHIFT);
  101335. return (i<0)?1.f:
  101336. ((i>=(FROMdB_LOOKUP_SZ<<FROMdB_SHIFT))?0.f:
  101337. FROMdB_LOOKUP[i>>FROMdB_SHIFT]*FROMdB2_LOOKUP[i&FROMdB2_MASK]);
  101338. }
  101339. long vorbis_coslook_i(long a){
  101340. int i=a>>COS_LOOKUP_I_SHIFT;
  101341. int d=a&COS_LOOKUP_I_MASK;
  101342. return COS_LOOKUP_I[i]- ((d*(COS_LOOKUP_I[i]-COS_LOOKUP_I[i+1]))>>
  101343. COS_LOOKUP_I_SHIFT);
  101344. }
  101345. #endif
  101346. #endif
  101347. /*** End of inlined file: lookup.c ***/
  101348. /* catch this in the build system; we #include for
  101349. compilers (like gcc) that can't inline across
  101350. modules */
  101351. static int MLOOP_1[64]={
  101352. 0,10,11,11, 12,12,12,12, 13,13,13,13, 13,13,13,13,
  101353. 14,14,14,14, 14,14,14,14, 14,14,14,14, 14,14,14,14,
  101354. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101355. 15,15,15,15, 15,15,15,15, 15,15,15,15, 15,15,15,15,
  101356. };
  101357. static int MLOOP_2[64]={
  101358. 0,4,5,5, 6,6,6,6, 7,7,7,7, 7,7,7,7,
  101359. 8,8,8,8, 8,8,8,8, 8,8,8,8, 8,8,8,8,
  101360. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101361. 9,9,9,9, 9,9,9,9, 9,9,9,9, 9,9,9,9,
  101362. };
  101363. static int MLOOP_3[8]={0,1,2,2,3,3,3,3};
  101364. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101365. float amp,float ampoffset){
  101366. int i;
  101367. int ampoffseti=rint(ampoffset*4096.f);
  101368. int ampi=rint(amp*16.f);
  101369. long *ilsp=alloca(m*sizeof(*ilsp));
  101370. for(i=0;i<m;i++)ilsp[i]=vorbis_coslook_i(lsp[i]/M_PI*65536.f+.5f);
  101371. i=0;
  101372. while(i<n){
  101373. int j,k=map[i];
  101374. unsigned long pi=46341; /* 2**-.5 in 0.16 */
  101375. unsigned long qi=46341;
  101376. int qexp=0,shift;
  101377. long wi=vorbis_coslook_i(k*65536/ln);
  101378. qi*=labs(ilsp[0]-wi);
  101379. pi*=labs(ilsp[1]-wi);
  101380. for(j=3;j<m;j+=2){
  101381. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101382. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101383. shift=MLOOP_3[(pi|qi)>>16];
  101384. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101385. pi=(pi>>shift)*labs(ilsp[j]-wi);
  101386. qexp+=shift;
  101387. }
  101388. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101389. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101390. shift=MLOOP_3[(pi|qi)>>16];
  101391. if(m&1){
  101392. qi=(qi>>shift)*labs(ilsp[j-1]-wi);
  101393. pi=(pi>>shift)<<14;
  101394. qexp+=shift;
  101395. if(!(shift=MLOOP_1[(pi|qi)>>25]))
  101396. if(!(shift=MLOOP_2[(pi|qi)>>19]))
  101397. shift=MLOOP_3[(pi|qi)>>16];
  101398. pi>>=shift;
  101399. qi>>=shift;
  101400. qexp+=shift-14*((m+1)>>1);
  101401. pi=((pi*pi)>>16);
  101402. qi=((qi*qi)>>16);
  101403. qexp=qexp*2+m;
  101404. pi*=(1<<14)-((wi*wi)>>14);
  101405. qi+=pi>>14;
  101406. }else{
  101407. pi>>=shift;
  101408. qi>>=shift;
  101409. qexp+=shift-7*m;
  101410. pi=((pi*pi)>>16);
  101411. qi=((qi*qi)>>16);
  101412. qexp=qexp*2+m;
  101413. pi*=(1<<14)-wi;
  101414. qi*=(1<<14)+wi;
  101415. qi=(qi+pi)>>14;
  101416. }
  101417. if(qi&0xffff0000){ /* checks for 1.xxxxxxxxxxxxxxxx */
  101418. qi>>=1; qexp++;
  101419. }else
  101420. while(qi && !(qi&0x8000)){ /* checks for 0.0xxxxxxxxxxxxxxx or less*/
  101421. qi<<=1; qexp--;
  101422. }
  101423. amp=vorbis_fromdBlook_i(ampi* /* n.4 */
  101424. vorbis_invsqlook_i(qi,qexp)-
  101425. ampoffseti); /* 8.12[0] */
  101426. curve[i]*=amp;
  101427. while(map[++i]==k)curve[i]*=amp;
  101428. }
  101429. }
  101430. #else
  101431. void vorbis_lsp_to_curve(float *curve,int *map,int n,int ln,float *lsp,int m,
  101432. float amp,float ampoffset){
  101433. int i;
  101434. float wdel=M_PI/ln;
  101435. for(i=0;i<m;i++)lsp[i]=2.f*cos(lsp[i]);
  101436. i=0;
  101437. while(i<n){
  101438. int j,k=map[i];
  101439. float p=.5f;
  101440. float q=.5f;
  101441. float w=2.f*cos(wdel*k);
  101442. for(j=1;j<m;j+=2){
  101443. q *= w-lsp[j-1];
  101444. p *= w-lsp[j];
  101445. }
  101446. if(j==m){
  101447. q*=w-lsp[j-1];
  101448. p*=p*(4.f-w*w);
  101449. q*=q;
  101450. }else{
  101451. p*=p*(2.f-w);
  101452. q*=q*(2.f+w);
  101453. }
  101454. q=fromdB(amp/sqrt(p+q)-ampoffset);
  101455. curve[i]*=q;
  101456. while(map[++i]==k)curve[i]*=q;
  101457. }
  101458. }
  101459. #endif
  101460. #endif
  101461. static void cheby(float *g, int ord) {
  101462. int i, j;
  101463. g[0] *= .5f;
  101464. for(i=2; i<= ord; i++) {
  101465. for(j=ord; j >= i; j--) {
  101466. g[j-2] -= g[j];
  101467. g[j] += g[j];
  101468. }
  101469. }
  101470. }
  101471. static int comp(const void *a,const void *b){
  101472. return (*(float *)a<*(float *)b)-(*(float *)a>*(float *)b);
  101473. }
  101474. #define EPSILON 10e-7
  101475. static int Laguerre_With_Deflation(float *a,int ord,float *r){
  101476. int i,m;
  101477. double lastdelta=0.f;
  101478. double *defl=(double*)alloca(sizeof(*defl)*(ord+1));
  101479. for(i=0;i<=ord;i++)defl[i]=a[i];
  101480. for(m=ord;m>0;m--){
  101481. double newx=0.f,delta;
  101482. while(1){
  101483. double p=defl[m],pp=0.f,ppp=0.f,denom;
  101484. for(i=m;i>0;i--){
  101485. ppp = newx*ppp + pp;
  101486. pp = newx*pp + p;
  101487. p = newx*p + defl[i-1];
  101488. }
  101489. denom=(m-1) * ((m-1)*pp*pp - m*p*ppp);
  101490. if(denom<0)
  101491. return(-1); /* complex root! The LPC generator handed us a bad filter */
  101492. if(pp>0){
  101493. denom = pp + sqrt(denom);
  101494. if(denom<EPSILON)denom=EPSILON;
  101495. }else{
  101496. denom = pp - sqrt(denom);
  101497. if(denom>-(EPSILON))denom=-(EPSILON);
  101498. }
  101499. delta = m*p/denom;
  101500. newx -= delta;
  101501. if(delta<0.f)delta*=-1;
  101502. if(fabs(delta/newx)<10e-12)break;
  101503. lastdelta=delta;
  101504. }
  101505. r[m-1]=newx;
  101506. for(i=m;i>0;i--)
  101507. defl[i-1]+=newx*defl[i];
  101508. defl++;
  101509. }
  101510. return(0);
  101511. }
  101512. static int Newton_Raphson(float *a,int ord,float *r){
  101513. int i, k, count=0;
  101514. double error=1.f;
  101515. double *root=(double*)alloca(ord*sizeof(*root));
  101516. for(i=0; i<ord;i++) root[i] = r[i];
  101517. while(error>1e-20){
  101518. error=0;
  101519. for(i=0; i<ord; i++) { /* Update each point. */
  101520. double pp=0.,delta;
  101521. double rooti=root[i];
  101522. double p=a[ord];
  101523. for(k=ord-1; k>= 0; k--) {
  101524. pp= pp* rooti + p;
  101525. p = p * rooti + a[k];
  101526. }
  101527. delta = p/pp;
  101528. root[i] -= delta;
  101529. error+= delta*delta;
  101530. }
  101531. if(count>40)return(-1);
  101532. count++;
  101533. }
  101534. for(i=0; i<ord;i++) r[i] = root[i];
  101535. return(0);
  101536. }
  101537. int vorbis_lpc_to_lsp(float *lpc,float *lsp,int m){
  101538. int order2=(m+1)>>1;
  101539. int g1_order,g2_order;
  101540. float *g1=(float*)alloca(sizeof(*g1)*(order2+1));
  101541. float *g2=(float*)alloca(sizeof(*g2)*(order2+1));
  101542. float *g1r=(float*)alloca(sizeof(*g1r)*(order2+1));
  101543. float *g2r=(float*)alloca(sizeof(*g2r)*(order2+1));
  101544. int i;
  101545. g1_order=(m+1)>>1;
  101546. g2_order=(m) >>1;
  101547. g1[g1_order] = 1.f;
  101548. for(i=1;i<=g1_order;i++) g1[g1_order-i] = lpc[i-1]+lpc[m-i];
  101549. g2[g2_order] = 1.f;
  101550. for(i=1;i<=g2_order;i++) g2[g2_order-i] = lpc[i-1]-lpc[m-i];
  101551. if(g1_order>g2_order){
  101552. for(i=2; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+2];
  101553. }else{
  101554. for(i=1; i<=g1_order;i++) g1[g1_order-i] -= g1[g1_order-i+1];
  101555. for(i=1; i<=g2_order;i++) g2[g2_order-i] += g2[g2_order-i+1];
  101556. }
  101557. cheby(g1,g1_order);
  101558. cheby(g2,g2_order);
  101559. if(Laguerre_With_Deflation(g1,g1_order,g1r) ||
  101560. Laguerre_With_Deflation(g2,g2_order,g2r))
  101561. return(-1);
  101562. Newton_Raphson(g1,g1_order,g1r); /* if it fails, it leaves g1r alone */
  101563. Newton_Raphson(g2,g2_order,g2r); /* if it fails, it leaves g2r alone */
  101564. qsort(g1r,g1_order,sizeof(*g1r),comp);
  101565. qsort(g2r,g2_order,sizeof(*g2r),comp);
  101566. for(i=0;i<g1_order;i++)
  101567. lsp[i*2] = acos(g1r[i]);
  101568. for(i=0;i<g2_order;i++)
  101569. lsp[i*2+1] = acos(g2r[i]);
  101570. return(0);
  101571. }
  101572. #endif
  101573. /*** End of inlined file: lsp.c ***/
  101574. /*** Start of inlined file: mapping0.c ***/
  101575. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  101576. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  101577. // tasks..
  101578. #if JUCE_MSVC
  101579. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  101580. #endif
  101581. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  101582. #if JUCE_USE_OGGVORBIS
  101583. #include <stdlib.h>
  101584. #include <stdio.h>
  101585. #include <string.h>
  101586. #include <math.h>
  101587. static void mapping0_free_info(vorbis_info_mapping *i){
  101588. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)i;
  101589. if(info){
  101590. memset(info,0,sizeof(*info));
  101591. _ogg_free(info);
  101592. }
  101593. }
  101594. static int ilog3(unsigned int v){
  101595. int ret=0;
  101596. if(v)--v;
  101597. while(v){
  101598. ret++;
  101599. v>>=1;
  101600. }
  101601. return(ret);
  101602. }
  101603. static void mapping0_pack(vorbis_info *vi,vorbis_info_mapping *vm,
  101604. oggpack_buffer *opb){
  101605. int i;
  101606. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)vm;
  101607. if(info->submaps>1){
  101608. oggpack_write(opb,1,1);
  101609. oggpack_write(opb,info->submaps-1,4);
  101610. }else
  101611. oggpack_write(opb,0,1);
  101612. if(info->coupling_steps>0){
  101613. oggpack_write(opb,1,1);
  101614. oggpack_write(opb,info->coupling_steps-1,8);
  101615. for(i=0;i<info->coupling_steps;i++){
  101616. oggpack_write(opb,info->coupling_mag[i],ilog3(vi->channels));
  101617. oggpack_write(opb,info->coupling_ang[i],ilog3(vi->channels));
  101618. }
  101619. }else
  101620. oggpack_write(opb,0,1);
  101621. oggpack_write(opb,0,2); /* 2,3:reserved */
  101622. if(info->submaps>1){
  101623. for(i=0;i<vi->channels;i++)
  101624. oggpack_write(opb,info->chmuxlist[i],4);
  101625. }
  101626. for(i=0;i<info->submaps;i++){
  101627. oggpack_write(opb,0,8); /* time submap unused */
  101628. oggpack_write(opb,info->floorsubmap[i],8);
  101629. oggpack_write(opb,info->residuesubmap[i],8);
  101630. }
  101631. }
  101632. static vorbis_info_mapping *mapping0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  101633. int i;
  101634. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)_ogg_calloc(1,sizeof(*info));
  101635. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101636. memset(info,0,sizeof(*info));
  101637. if(oggpack_read(opb,1))
  101638. info->submaps=oggpack_read(opb,4)+1;
  101639. else
  101640. info->submaps=1;
  101641. if(oggpack_read(opb,1)){
  101642. info->coupling_steps=oggpack_read(opb,8)+1;
  101643. for(i=0;i<info->coupling_steps;i++){
  101644. int testM=info->coupling_mag[i]=oggpack_read(opb,ilog3(vi->channels));
  101645. int testA=info->coupling_ang[i]=oggpack_read(opb,ilog3(vi->channels));
  101646. if(testM<0 ||
  101647. testA<0 ||
  101648. testM==testA ||
  101649. testM>=vi->channels ||
  101650. testA>=vi->channels) goto err_out;
  101651. }
  101652. }
  101653. if(oggpack_read(opb,2)>0)goto err_out; /* 2,3:reserved */
  101654. if(info->submaps>1){
  101655. for(i=0;i<vi->channels;i++){
  101656. info->chmuxlist[i]=oggpack_read(opb,4);
  101657. if(info->chmuxlist[i]>=info->submaps)goto err_out;
  101658. }
  101659. }
  101660. for(i=0;i<info->submaps;i++){
  101661. oggpack_read(opb,8); /* time submap unused */
  101662. info->floorsubmap[i]=oggpack_read(opb,8);
  101663. if(info->floorsubmap[i]>=ci->floors)goto err_out;
  101664. info->residuesubmap[i]=oggpack_read(opb,8);
  101665. if(info->residuesubmap[i]>=ci->residues)goto err_out;
  101666. }
  101667. return info;
  101668. err_out:
  101669. mapping0_free_info(info);
  101670. return(NULL);
  101671. }
  101672. #if 0
  101673. static long seq=0;
  101674. static ogg_int64_t total=0;
  101675. static float FLOOR1_fromdB_LOOKUP[256]={
  101676. 1.0649863e-07F, 1.1341951e-07F, 1.2079015e-07F, 1.2863978e-07F,
  101677. 1.3699951e-07F, 1.4590251e-07F, 1.5538408e-07F, 1.6548181e-07F,
  101678. 1.7623575e-07F, 1.8768855e-07F, 1.9988561e-07F, 2.128753e-07F,
  101679. 2.2670913e-07F, 2.4144197e-07F, 2.5713223e-07F, 2.7384213e-07F,
  101680. 2.9163793e-07F, 3.1059021e-07F, 3.3077411e-07F, 3.5226968e-07F,
  101681. 3.7516214e-07F, 3.9954229e-07F, 4.2550680e-07F, 4.5315863e-07F,
  101682. 4.8260743e-07F, 5.1396998e-07F, 5.4737065e-07F, 5.8294187e-07F,
  101683. 6.2082472e-07F, 6.6116941e-07F, 7.0413592e-07F, 7.4989464e-07F,
  101684. 7.9862701e-07F, 8.5052630e-07F, 9.0579828e-07F, 9.6466216e-07F,
  101685. 1.0273513e-06F, 1.0941144e-06F, 1.1652161e-06F, 1.2409384e-06F,
  101686. 1.3215816e-06F, 1.4074654e-06F, 1.4989305e-06F, 1.5963394e-06F,
  101687. 1.7000785e-06F, 1.8105592e-06F, 1.9282195e-06F, 2.0535261e-06F,
  101688. 2.1869758e-06F, 2.3290978e-06F, 2.4804557e-06F, 2.6416497e-06F,
  101689. 2.8133190e-06F, 2.9961443e-06F, 3.1908506e-06F, 3.3982101e-06F,
  101690. 3.6190449e-06F, 3.8542308e-06F, 4.1047004e-06F, 4.3714470e-06F,
  101691. 4.6555282e-06F, 4.9580707e-06F, 5.2802740e-06F, 5.6234160e-06F,
  101692. 5.9888572e-06F, 6.3780469e-06F, 6.7925283e-06F, 7.2339451e-06F,
  101693. 7.7040476e-06F, 8.2047000e-06F, 8.7378876e-06F, 9.3057248e-06F,
  101694. 9.9104632e-06F, 1.0554501e-05F, 1.1240392e-05F, 1.1970856e-05F,
  101695. 1.2748789e-05F, 1.3577278e-05F, 1.4459606e-05F, 1.5399272e-05F,
  101696. 1.6400004e-05F, 1.7465768e-05F, 1.8600792e-05F, 1.9809576e-05F,
  101697. 2.1096914e-05F, 2.2467911e-05F, 2.3928002e-05F, 2.5482978e-05F,
  101698. 2.7139006e-05F, 2.8902651e-05F, 3.0780908e-05F, 3.2781225e-05F,
  101699. 3.4911534e-05F, 3.7180282e-05F, 3.9596466e-05F, 4.2169667e-05F,
  101700. 4.4910090e-05F, 4.7828601e-05F, 5.0936773e-05F, 5.4246931e-05F,
  101701. 5.7772202e-05F, 6.1526565e-05F, 6.5524908e-05F, 6.9783085e-05F,
  101702. 7.4317983e-05F, 7.9147585e-05F, 8.4291040e-05F, 8.9768747e-05F,
  101703. 9.5602426e-05F, 0.00010181521F, 0.00010843174F, 0.00011547824F,
  101704. 0.00012298267F, 0.00013097477F, 0.00013948625F, 0.00014855085F,
  101705. 0.00015820453F, 0.00016848555F, 0.00017943469F, 0.00019109536F,
  101706. 0.00020351382F, 0.00021673929F, 0.00023082423F, 0.00024582449F,
  101707. 0.00026179955F, 0.00027881276F, 0.00029693158F, 0.00031622787F,
  101708. 0.00033677814F, 0.00035866388F, 0.00038197188F, 0.00040679456F,
  101709. 0.00043323036F, 0.00046138411F, 0.00049136745F, 0.00052329927F,
  101710. 0.00055730621F, 0.00059352311F, 0.00063209358F, 0.00067317058F,
  101711. 0.00071691700F, 0.00076350630F, 0.00081312324F, 0.00086596457F,
  101712. 0.00092223983F, 0.00098217216F, 0.0010459992F, 0.0011139742F,
  101713. 0.0011863665F, 0.0012634633F, 0.0013455702F, 0.0014330129F,
  101714. 0.0015261382F, 0.0016253153F, 0.0017309374F, 0.0018434235F,
  101715. 0.0019632195F, 0.0020908006F, 0.0022266726F, 0.0023713743F,
  101716. 0.0025254795F, 0.0026895994F, 0.0028643847F, 0.0030505286F,
  101717. 0.0032487691F, 0.0034598925F, 0.0036847358F, 0.0039241906F,
  101718. 0.0041792066F, 0.0044507950F, 0.0047400328F, 0.0050480668F,
  101719. 0.0053761186F, 0.0057254891F, 0.0060975636F, 0.0064938176F,
  101720. 0.0069158225F, 0.0073652516F, 0.0078438871F, 0.0083536271F,
  101721. 0.0088964928F, 0.009474637F, 0.010090352F, 0.010746080F,
  101722. 0.011444421F, 0.012188144F, 0.012980198F, 0.013823725F,
  101723. 0.014722068F, 0.015678791F, 0.016697687F, 0.017782797F,
  101724. 0.018938423F, 0.020169149F, 0.021479854F, 0.022875735F,
  101725. 0.024362330F, 0.025945531F, 0.027631618F, 0.029427276F,
  101726. 0.031339626F, 0.033376252F, 0.035545228F, 0.037855157F,
  101727. 0.040315199F, 0.042935108F, 0.045725273F, 0.048696758F,
  101728. 0.051861348F, 0.055231591F, 0.058820850F, 0.062643361F,
  101729. 0.066714279F, 0.071049749F, 0.075666962F, 0.080584227F,
  101730. 0.085821044F, 0.091398179F, 0.097337747F, 0.10366330F,
  101731. 0.11039993F, 0.11757434F, 0.12521498F, 0.13335215F,
  101732. 0.14201813F, 0.15124727F, 0.16107617F, 0.17154380F,
  101733. 0.18269168F, 0.19456402F, 0.20720788F, 0.22067342F,
  101734. 0.23501402F, 0.25028656F, 0.26655159F, 0.28387361F,
  101735. 0.30232132F, 0.32196786F, 0.34289114F, 0.36517414F,
  101736. 0.38890521F, 0.41417847F, 0.44109412F, 0.46975890F,
  101737. 0.50028648F, 0.53279791F, 0.56742212F, 0.60429640F,
  101738. 0.64356699F, 0.68538959F, 0.72993007F, 0.77736504F,
  101739. 0.82788260F, 0.88168307F, 0.9389798F, 1.F,
  101740. };
  101741. #endif
  101742. extern int *floor1_fit(vorbis_block *vb,void *look,
  101743. const float *logmdct, /* in */
  101744. const float *logmask);
  101745. extern int *floor1_interpolate_fit(vorbis_block *vb,void *look,
  101746. int *A,int *B,
  101747. int del);
  101748. extern int floor1_encode(oggpack_buffer *opb,vorbis_block *vb,
  101749. void*look,
  101750. int *post,int *ilogmask);
  101751. static int mapping0_forward(vorbis_block *vb){
  101752. vorbis_dsp_state *vd=vb->vd;
  101753. vorbis_info *vi=vd->vi;
  101754. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  101755. private_state *b=(private_state*)vb->vd->backend_state;
  101756. vorbis_block_internal *vbi=(vorbis_block_internal *)vb->internal;
  101757. int n=vb->pcmend;
  101758. int i,j,k;
  101759. int *nonzero = (int*) alloca(sizeof(*nonzero)*vi->channels);
  101760. float **gmdct = (float**) _vorbis_block_alloc(vb,vi->channels*sizeof(*gmdct));
  101761. int **ilogmaskch= (int**) _vorbis_block_alloc(vb,vi->channels*sizeof(*ilogmaskch));
  101762. int ***floor_posts = (int***) _vorbis_block_alloc(vb,vi->channels*sizeof(*floor_posts));
  101763. float global_ampmax=vbi->ampmax;
  101764. float *local_ampmax=(float*)alloca(sizeof(*local_ampmax)*vi->channels);
  101765. int blocktype=vbi->blocktype;
  101766. int modenumber=vb->W;
  101767. vorbis_info_mapping0 *info=(vorbis_info_mapping0*)ci->map_param[modenumber];
  101768. vorbis_look_psy *psy_look=
  101769. b->psy+blocktype+(vb->W?2:0);
  101770. vb->mode=modenumber;
  101771. for(i=0;i<vi->channels;i++){
  101772. float scale=4.f/n;
  101773. float scale_dB;
  101774. float *pcm =vb->pcm[i];
  101775. float *logfft =pcm;
  101776. gmdct[i]=(float*)_vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  101777. scale_dB=todB(&scale) + .345; /* + .345 is a hack; the original
  101778. todB estimation used on IEEE 754
  101779. compliant machines had a bug that
  101780. returned dB values about a third
  101781. of a decibel too high. The bug
  101782. was harmless because tunings
  101783. implicitly took that into
  101784. account. However, fixing the bug
  101785. in the estimator requires
  101786. changing all the tunings as well.
  101787. For now, it's easier to sync
  101788. things back up here, and
  101789. recalibrate the tunings in the
  101790. next major model upgrade. */
  101791. #if 0
  101792. if(vi->channels==2)
  101793. if(i==0)
  101794. _analysis_output("pcmL",seq,pcm,n,0,0,total-n/2);
  101795. else
  101796. _analysis_output("pcmR",seq,pcm,n,0,0,total-n/2);
  101797. #endif
  101798. _vorbis_apply_window(pcm,b->window,ci->blocksizes,vb->lW,vb->W,vb->nW);
  101799. #if 0
  101800. if(vi->channels==2)
  101801. if(i==0)
  101802. _analysis_output("windowedL",seq,pcm,n,0,0,total-n/2);
  101803. else
  101804. _analysis_output("windowedR",seq,pcm,n,0,0,total-n/2);
  101805. #endif
  101806. mdct_forward((mdct_lookup*) b->transform[vb->W][0],pcm,gmdct[i]);
  101807. drft_forward(&b->fft_look[vb->W],pcm);
  101808. logfft[0]=scale_dB+todB(pcm) + .345; /* + .345 is a hack; the
  101809. original todB estimation used on
  101810. IEEE 754 compliant machines had a
  101811. bug that returned dB values about
  101812. a third of a decibel too high.
  101813. The bug was harmless because
  101814. tunings implicitly took that into
  101815. account. However, fixing the bug
  101816. in the estimator requires
  101817. changing all the tunings as well.
  101818. For now, it's easier to sync
  101819. things back up here, and
  101820. recalibrate the tunings in the
  101821. next major model upgrade. */
  101822. local_ampmax[i]=logfft[0];
  101823. for(j=1;j<n-1;j+=2){
  101824. float temp=pcm[j]*pcm[j]+pcm[j+1]*pcm[j+1];
  101825. temp=logfft[(j+1)>>1]=scale_dB+.5f*todB(&temp) + .345; /* +
  101826. .345 is a hack; the original todB
  101827. estimation used on IEEE 754
  101828. compliant machines had a bug that
  101829. returned dB values about a third
  101830. of a decibel too high. The bug
  101831. was harmless because tunings
  101832. implicitly took that into
  101833. account. However, fixing the bug
  101834. in the estimator requires
  101835. changing all the tunings as well.
  101836. For now, it's easier to sync
  101837. things back up here, and
  101838. recalibrate the tunings in the
  101839. next major model upgrade. */
  101840. if(temp>local_ampmax[i])local_ampmax[i]=temp;
  101841. }
  101842. if(local_ampmax[i]>0.f)local_ampmax[i]=0.f;
  101843. if(local_ampmax[i]>global_ampmax)global_ampmax=local_ampmax[i];
  101844. #if 0
  101845. if(vi->channels==2){
  101846. if(i==0){
  101847. _analysis_output("fftL",seq,logfft,n/2,1,0,0);
  101848. }else{
  101849. _analysis_output("fftR",seq,logfft,n/2,1,0,0);
  101850. }
  101851. }
  101852. #endif
  101853. }
  101854. {
  101855. float *noise = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*noise));
  101856. float *tone = (float*) _vorbis_block_alloc(vb,n/2*sizeof(*tone));
  101857. for(i=0;i<vi->channels;i++){
  101858. int submap=info->chmuxlist[i];
  101859. float *mdct =gmdct[i];
  101860. float *logfft =vb->pcm[i];
  101861. float *logmdct =logfft+n/2;
  101862. float *logmask =logfft;
  101863. vb->mode=modenumber;
  101864. floor_posts[i]=(int**) _vorbis_block_alloc(vb,PACKETBLOBS*sizeof(**floor_posts));
  101865. memset(floor_posts[i],0,sizeof(**floor_posts)*PACKETBLOBS);
  101866. for(j=0;j<n/2;j++)
  101867. logmdct[j]=todB(mdct+j) + .345; /* + .345 is a hack; the original
  101868. todB estimation used on IEEE 754
  101869. compliant machines had a bug that
  101870. returned dB values about a third
  101871. of a decibel too high. The bug
  101872. was harmless because tunings
  101873. implicitly took that into
  101874. account. However, fixing the bug
  101875. in the estimator requires
  101876. changing all the tunings as well.
  101877. For now, it's easier to sync
  101878. things back up here, and
  101879. recalibrate the tunings in the
  101880. next major model upgrade. */
  101881. #if 0
  101882. if(vi->channels==2){
  101883. if(i==0)
  101884. _analysis_output("mdctL",seq,logmdct,n/2,1,0,0);
  101885. else
  101886. _analysis_output("mdctR",seq,logmdct,n/2,1,0,0);
  101887. }else{
  101888. _analysis_output("mdct",seq,logmdct,n/2,1,0,0);
  101889. }
  101890. #endif
  101891. _vp_noisemask(psy_look,
  101892. logmdct,
  101893. noise); /* noise does not have by-frequency offset
  101894. bias applied yet */
  101895. #if 0
  101896. if(vi->channels==2){
  101897. if(i==0)
  101898. _analysis_output("noiseL",seq,noise,n/2,1,0,0);
  101899. else
  101900. _analysis_output("noiseR",seq,noise,n/2,1,0,0);
  101901. }
  101902. #endif
  101903. _vp_tonemask(psy_look,
  101904. logfft,
  101905. tone,
  101906. global_ampmax,
  101907. local_ampmax[i]);
  101908. #if 0
  101909. if(vi->channels==2){
  101910. if(i==0)
  101911. _analysis_output("toneL",seq,tone,n/2,1,0,0);
  101912. else
  101913. _analysis_output("toneR",seq,tone,n/2,1,0,0);
  101914. }
  101915. #endif
  101916. #if 0
  101917. {
  101918. float aotuv[psy_look->n];
  101919. #endif
  101920. _vp_offset_and_mix(psy_look,
  101921. noise,
  101922. tone,
  101923. 1,
  101924. logmask,
  101925. mdct,
  101926. logmdct);
  101927. #if 0
  101928. if(vi->channels==2){
  101929. if(i==0)
  101930. _analysis_output("aotuvM1_L",seq,aotuv,psy_look->n,1,1,0);
  101931. else
  101932. _analysis_output("aotuvM1_R",seq,aotuv,psy_look->n,1,1,0);
  101933. }
  101934. }
  101935. #endif
  101936. #if 0
  101937. if(vi->channels==2){
  101938. if(i==0)
  101939. _analysis_output("mask1L",seq,logmask,n/2,1,0,0);
  101940. else
  101941. _analysis_output("mask1R",seq,logmask,n/2,1,0,0);
  101942. }
  101943. #endif
  101944. if(ci->floor_type[info->floorsubmap[submap]]!=1)return(-1);
  101945. floor_posts[i][PACKETBLOBS/2]=
  101946. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101947. logmdct,
  101948. logmask);
  101949. if(vorbis_bitrate_managed(vb) && floor_posts[i][PACKETBLOBS/2]){
  101950. _vp_offset_and_mix(psy_look,
  101951. noise,
  101952. tone,
  101953. 2,
  101954. logmask,
  101955. mdct,
  101956. logmdct);
  101957. #if 0
  101958. if(vi->channels==2){
  101959. if(i==0)
  101960. _analysis_output("mask2L",seq,logmask,n/2,1,0,0);
  101961. else
  101962. _analysis_output("mask2R",seq,logmask,n/2,1,0,0);
  101963. }
  101964. #endif
  101965. floor_posts[i][PACKETBLOBS-1]=
  101966. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101967. logmdct,
  101968. logmask);
  101969. _vp_offset_and_mix(psy_look,
  101970. noise,
  101971. tone,
  101972. 0,
  101973. logmask,
  101974. mdct,
  101975. logmdct);
  101976. #if 0
  101977. if(vi->channels==2)
  101978. if(i==0)
  101979. _analysis_output("mask0L",seq,logmask,n/2,1,0,0);
  101980. else
  101981. _analysis_output("mask0R",seq,logmask,n/2,1,0,0);
  101982. #endif
  101983. floor_posts[i][0]=
  101984. floor1_fit(vb,b->flr[info->floorsubmap[submap]],
  101985. logmdct,
  101986. logmask);
  101987. for(k=1;k<PACKETBLOBS/2;k++)
  101988. floor_posts[i][k]=
  101989. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101990. floor_posts[i][0],
  101991. floor_posts[i][PACKETBLOBS/2],
  101992. k*65536/(PACKETBLOBS/2));
  101993. for(k=PACKETBLOBS/2+1;k<PACKETBLOBS-1;k++)
  101994. floor_posts[i][k]=
  101995. floor1_interpolate_fit(vb,b->flr[info->floorsubmap[submap]],
  101996. floor_posts[i][PACKETBLOBS/2],
  101997. floor_posts[i][PACKETBLOBS-1],
  101998. (k-PACKETBLOBS/2)*65536/(PACKETBLOBS/2));
  101999. }
  102000. }
  102001. }
  102002. vbi->ampmax=global_ampmax;
  102003. {
  102004. float **res_bundle=(float**) alloca(sizeof(*res_bundle)*vi->channels);
  102005. float **couple_bundle=(float**) alloca(sizeof(*couple_bundle)*vi->channels);
  102006. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  102007. int **sortindex=(int**) alloca(sizeof(*sortindex)*vi->channels);
  102008. float **mag_memo;
  102009. int **mag_sort;
  102010. if(info->coupling_steps){
  102011. mag_memo=_vp_quantize_couple_memo(vb,
  102012. &ci->psy_g_param,
  102013. psy_look,
  102014. info,
  102015. gmdct);
  102016. mag_sort=_vp_quantize_couple_sort(vb,
  102017. psy_look,
  102018. info,
  102019. mag_memo);
  102020. hf_reduction(&ci->psy_g_param,
  102021. psy_look,
  102022. info,
  102023. mag_memo);
  102024. }
  102025. memset(sortindex,0,sizeof(*sortindex)*vi->channels);
  102026. if(psy_look->vi->normal_channel_p){
  102027. for(i=0;i<vi->channels;i++){
  102028. float *mdct =gmdct[i];
  102029. sortindex[i]=(int*) alloca(sizeof(**sortindex)*n/2);
  102030. _vp_noise_normalize_sort(psy_look,mdct,sortindex[i]);
  102031. }
  102032. }
  102033. for(k=(vorbis_bitrate_managed(vb)?0:PACKETBLOBS/2);
  102034. k<=(vorbis_bitrate_managed(vb)?PACKETBLOBS-1:PACKETBLOBS/2);
  102035. k++){
  102036. oggpack_buffer *opb=vbi->packetblob[k];
  102037. oggpack_write(opb,0,1);
  102038. oggpack_write(opb,modenumber,b->modebits);
  102039. if(vb->W){
  102040. oggpack_write(opb,vb->lW,1);
  102041. oggpack_write(opb,vb->nW,1);
  102042. }
  102043. for(i=0;i<vi->channels;i++){
  102044. int submap=info->chmuxlist[i];
  102045. float *mdct =gmdct[i];
  102046. float *res =vb->pcm[i];
  102047. int *ilogmask=ilogmaskch[i]=
  102048. (int*) _vorbis_block_alloc(vb,n/2*sizeof(**gmdct));
  102049. nonzero[i]=floor1_encode(opb,vb,b->flr[info->floorsubmap[submap]],
  102050. floor_posts[i][k],
  102051. ilogmask);
  102052. #if 0
  102053. {
  102054. char buf[80];
  102055. sprintf(buf,"maskI%c%d",i?'R':'L',k);
  102056. float work[n/2];
  102057. for(j=0;j<n/2;j++)
  102058. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]];
  102059. _analysis_output(buf,seq,work,n/2,1,1,0);
  102060. }
  102061. #endif
  102062. _vp_remove_floor(psy_look,
  102063. mdct,
  102064. ilogmask,
  102065. res,
  102066. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  102067. _vp_noise_normalize(psy_look,res,res+n/2,sortindex[i]);
  102068. #if 0
  102069. {
  102070. char buf[80];
  102071. float work[n/2];
  102072. for(j=0;j<n/2;j++)
  102073. work[j]=FLOOR1_fromdB_LOOKUP[ilogmask[j]]*(res+n/2)[j];
  102074. sprintf(buf,"resI%c%d",i?'R':'L',k);
  102075. _analysis_output(buf,seq,work,n/2,1,1,0);
  102076. }
  102077. #endif
  102078. }
  102079. if(info->coupling_steps){
  102080. _vp_couple(k,
  102081. &ci->psy_g_param,
  102082. psy_look,
  102083. info,
  102084. vb->pcm,
  102085. mag_memo,
  102086. mag_sort,
  102087. ilogmaskch,
  102088. nonzero,
  102089. ci->psy_g_param.sliding_lowpass[vb->W][k]);
  102090. }
  102091. for(i=0;i<info->submaps;i++){
  102092. int ch_in_bundle=0;
  102093. long **classifications;
  102094. int resnum=info->residuesubmap[i];
  102095. for(j=0;j<vi->channels;j++){
  102096. if(info->chmuxlist[j]==i){
  102097. zerobundle[ch_in_bundle]=0;
  102098. if(nonzero[j])zerobundle[ch_in_bundle]=1;
  102099. res_bundle[ch_in_bundle]=vb->pcm[j];
  102100. couple_bundle[ch_in_bundle++]=vb->pcm[j]+n/2;
  102101. }
  102102. }
  102103. classifications=_residue_P[ci->residue_type[resnum]]->
  102104. classx(vb,b->residue[resnum],couple_bundle,zerobundle,ch_in_bundle);
  102105. _residue_P[ci->residue_type[resnum]]->
  102106. forward(opb,vb,b->residue[resnum],
  102107. couple_bundle,NULL,zerobundle,ch_in_bundle,classifications);
  102108. }
  102109. }
  102110. }
  102111. #if 0
  102112. seq++;
  102113. total+=ci->blocksizes[vb->W]/4+ci->blocksizes[vb->nW]/4;
  102114. #endif
  102115. return(0);
  102116. }
  102117. static int mapping0_inverse(vorbis_block *vb,vorbis_info_mapping *l){
  102118. vorbis_dsp_state *vd=vb->vd;
  102119. vorbis_info *vi=vd->vi;
  102120. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  102121. private_state *b=(private_state*)vd->backend_state;
  102122. vorbis_info_mapping0 *info=(vorbis_info_mapping0 *)l;
  102123. int i,j;
  102124. long n=vb->pcmend=ci->blocksizes[vb->W];
  102125. float **pcmbundle=(float**) alloca(sizeof(*pcmbundle)*vi->channels);
  102126. int *zerobundle=(int*) alloca(sizeof(*zerobundle)*vi->channels);
  102127. int *nonzero =(int*) alloca(sizeof(*nonzero)*vi->channels);
  102128. void **floormemo=(void**) alloca(sizeof(*floormemo)*vi->channels);
  102129. for(i=0;i<vi->channels;i++){
  102130. int submap=info->chmuxlist[i];
  102131. floormemo[i]=_floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  102132. inverse1(vb,b->flr[info->floorsubmap[submap]]);
  102133. if(floormemo[i])
  102134. nonzero[i]=1;
  102135. else
  102136. nonzero[i]=0;
  102137. memset(vb->pcm[i],0,sizeof(*vb->pcm[i])*n/2);
  102138. }
  102139. for(i=0;i<info->coupling_steps;i++){
  102140. if(nonzero[info->coupling_mag[i]] ||
  102141. nonzero[info->coupling_ang[i]]){
  102142. nonzero[info->coupling_mag[i]]=1;
  102143. nonzero[info->coupling_ang[i]]=1;
  102144. }
  102145. }
  102146. for(i=0;i<info->submaps;i++){
  102147. int ch_in_bundle=0;
  102148. for(j=0;j<vi->channels;j++){
  102149. if(info->chmuxlist[j]==i){
  102150. if(nonzero[j])
  102151. zerobundle[ch_in_bundle]=1;
  102152. else
  102153. zerobundle[ch_in_bundle]=0;
  102154. pcmbundle[ch_in_bundle++]=vb->pcm[j];
  102155. }
  102156. }
  102157. _residue_P[ci->residue_type[info->residuesubmap[i]]]->
  102158. inverse(vb,b->residue[info->residuesubmap[i]],
  102159. pcmbundle,zerobundle,ch_in_bundle);
  102160. }
  102161. for(i=info->coupling_steps-1;i>=0;i--){
  102162. float *pcmM=vb->pcm[info->coupling_mag[i]];
  102163. float *pcmA=vb->pcm[info->coupling_ang[i]];
  102164. for(j=0;j<n/2;j++){
  102165. float mag=pcmM[j];
  102166. float ang=pcmA[j];
  102167. if(mag>0)
  102168. if(ang>0){
  102169. pcmM[j]=mag;
  102170. pcmA[j]=mag-ang;
  102171. }else{
  102172. pcmA[j]=mag;
  102173. pcmM[j]=mag+ang;
  102174. }
  102175. else
  102176. if(ang>0){
  102177. pcmM[j]=mag;
  102178. pcmA[j]=mag+ang;
  102179. }else{
  102180. pcmA[j]=mag;
  102181. pcmM[j]=mag-ang;
  102182. }
  102183. }
  102184. }
  102185. for(i=0;i<vi->channels;i++){
  102186. float *pcm=vb->pcm[i];
  102187. int submap=info->chmuxlist[i];
  102188. _floor_P[ci->floor_type[info->floorsubmap[submap]]]->
  102189. inverse2(vb,b->flr[info->floorsubmap[submap]],
  102190. floormemo[i],pcm);
  102191. }
  102192. for(i=0;i<vi->channels;i++){
  102193. float *pcm=vb->pcm[i];
  102194. mdct_backward((mdct_lookup*) b->transform[vb->W][0],pcm,pcm);
  102195. }
  102196. return(0);
  102197. }
  102198. vorbis_func_mapping mapping0_exportbundle={
  102199. &mapping0_pack,
  102200. &mapping0_unpack,
  102201. &mapping0_free_info,
  102202. &mapping0_forward,
  102203. &mapping0_inverse
  102204. };
  102205. #endif
  102206. /*** End of inlined file: mapping0.c ***/
  102207. /*** Start of inlined file: mdct.c ***/
  102208. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102209. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102210. // tasks..
  102211. #if JUCE_MSVC
  102212. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102213. #endif
  102214. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102215. #if JUCE_USE_OGGVORBIS
  102216. #include <stdio.h>
  102217. #include <stdlib.h>
  102218. #include <string.h>
  102219. #include <math.h>
  102220. void mdct_init(mdct_lookup *lookup,int n){
  102221. int *bitrev=(int*) _ogg_malloc(sizeof(*bitrev)*(n/4));
  102222. DATA_TYPE *T=(DATA_TYPE*) _ogg_malloc(sizeof(*T)*(n+n/4));
  102223. int i;
  102224. int n2=n>>1;
  102225. int log2n=lookup->log2n=rint(log((float)n)/log(2.f));
  102226. lookup->n=n;
  102227. lookup->trig=T;
  102228. lookup->bitrev=bitrev;
  102229. for(i=0;i<n/4;i++){
  102230. T[i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i)));
  102231. T[i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i)));
  102232. T[n2+i*2]=FLOAT_CONV(cos((M_PI/(2*n))*(2*i+1)));
  102233. T[n2+i*2+1]=FLOAT_CONV(sin((M_PI/(2*n))*(2*i+1)));
  102234. }
  102235. for(i=0;i<n/8;i++){
  102236. T[n+i*2]=FLOAT_CONV(cos((M_PI/n)*(4*i+2))*.5);
  102237. T[n+i*2+1]=FLOAT_CONV(-sin((M_PI/n)*(4*i+2))*.5);
  102238. }
  102239. {
  102240. int mask=(1<<(log2n-1))-1,i,j;
  102241. int msb=1<<(log2n-2);
  102242. for(i=0;i<n/8;i++){
  102243. int acc=0;
  102244. for(j=0;msb>>j;j++)
  102245. if((msb>>j)&i)acc|=1<<j;
  102246. bitrev[i*2]=((~acc)&mask)-1;
  102247. bitrev[i*2+1]=acc;
  102248. }
  102249. }
  102250. lookup->scale=FLOAT_CONV(4.f/n);
  102251. }
  102252. STIN void mdct_butterfly_8(DATA_TYPE *x){
  102253. REG_TYPE r0 = x[6] + x[2];
  102254. REG_TYPE r1 = x[6] - x[2];
  102255. REG_TYPE r2 = x[4] + x[0];
  102256. REG_TYPE r3 = x[4] - x[0];
  102257. x[6] = r0 + r2;
  102258. x[4] = r0 - r2;
  102259. r0 = x[5] - x[1];
  102260. r2 = x[7] - x[3];
  102261. x[0] = r1 + r0;
  102262. x[2] = r1 - r0;
  102263. r0 = x[5] + x[1];
  102264. r1 = x[7] + x[3];
  102265. x[3] = r2 + r3;
  102266. x[1] = r2 - r3;
  102267. x[7] = r1 + r0;
  102268. x[5] = r1 - r0;
  102269. }
  102270. STIN void mdct_butterfly_16(DATA_TYPE *x){
  102271. REG_TYPE r0 = x[1] - x[9];
  102272. REG_TYPE r1 = x[0] - x[8];
  102273. x[8] += x[0];
  102274. x[9] += x[1];
  102275. x[0] = MULT_NORM((r0 + r1) * cPI2_8);
  102276. x[1] = MULT_NORM((r0 - r1) * cPI2_8);
  102277. r0 = x[3] - x[11];
  102278. r1 = x[10] - x[2];
  102279. x[10] += x[2];
  102280. x[11] += x[3];
  102281. x[2] = r0;
  102282. x[3] = r1;
  102283. r0 = x[12] - x[4];
  102284. r1 = x[13] - x[5];
  102285. x[12] += x[4];
  102286. x[13] += x[5];
  102287. x[4] = MULT_NORM((r0 - r1) * cPI2_8);
  102288. x[5] = MULT_NORM((r0 + r1) * cPI2_8);
  102289. r0 = x[14] - x[6];
  102290. r1 = x[15] - x[7];
  102291. x[14] += x[6];
  102292. x[15] += x[7];
  102293. x[6] = r0;
  102294. x[7] = r1;
  102295. mdct_butterfly_8(x);
  102296. mdct_butterfly_8(x+8);
  102297. }
  102298. STIN void mdct_butterfly_32(DATA_TYPE *x){
  102299. REG_TYPE r0 = x[30] - x[14];
  102300. REG_TYPE r1 = x[31] - x[15];
  102301. x[30] += x[14];
  102302. x[31] += x[15];
  102303. x[14] = r0;
  102304. x[15] = r1;
  102305. r0 = x[28] - x[12];
  102306. r1 = x[29] - x[13];
  102307. x[28] += x[12];
  102308. x[29] += x[13];
  102309. x[12] = MULT_NORM( r0 * cPI1_8 - r1 * cPI3_8 );
  102310. x[13] = MULT_NORM( r0 * cPI3_8 + r1 * cPI1_8 );
  102311. r0 = x[26] - x[10];
  102312. r1 = x[27] - x[11];
  102313. x[26] += x[10];
  102314. x[27] += x[11];
  102315. x[10] = MULT_NORM(( r0 - r1 ) * cPI2_8);
  102316. x[11] = MULT_NORM(( r0 + r1 ) * cPI2_8);
  102317. r0 = x[24] - x[8];
  102318. r1 = x[25] - x[9];
  102319. x[24] += x[8];
  102320. x[25] += x[9];
  102321. x[8] = MULT_NORM( r0 * cPI3_8 - r1 * cPI1_8 );
  102322. x[9] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102323. r0 = x[22] - x[6];
  102324. r1 = x[7] - x[23];
  102325. x[22] += x[6];
  102326. x[23] += x[7];
  102327. x[6] = r1;
  102328. x[7] = r0;
  102329. r0 = x[4] - x[20];
  102330. r1 = x[5] - x[21];
  102331. x[20] += x[4];
  102332. x[21] += x[5];
  102333. x[4] = MULT_NORM( r1 * cPI1_8 + r0 * cPI3_8 );
  102334. x[5] = MULT_NORM( r1 * cPI3_8 - r0 * cPI1_8 );
  102335. r0 = x[2] - x[18];
  102336. r1 = x[3] - x[19];
  102337. x[18] += x[2];
  102338. x[19] += x[3];
  102339. x[2] = MULT_NORM(( r1 + r0 ) * cPI2_8);
  102340. x[3] = MULT_NORM(( r1 - r0 ) * cPI2_8);
  102341. r0 = x[0] - x[16];
  102342. r1 = x[1] - x[17];
  102343. x[16] += x[0];
  102344. x[17] += x[1];
  102345. x[0] = MULT_NORM( r1 * cPI3_8 + r0 * cPI1_8 );
  102346. x[1] = MULT_NORM( r1 * cPI1_8 - r0 * cPI3_8 );
  102347. mdct_butterfly_16(x);
  102348. mdct_butterfly_16(x+16);
  102349. }
  102350. STIN void mdct_butterfly_first(DATA_TYPE *T,
  102351. DATA_TYPE *x,
  102352. int points){
  102353. DATA_TYPE *x1 = x + points - 8;
  102354. DATA_TYPE *x2 = x + (points>>1) - 8;
  102355. REG_TYPE r0;
  102356. REG_TYPE r1;
  102357. do{
  102358. r0 = x1[6] - x2[6];
  102359. r1 = x1[7] - x2[7];
  102360. x1[6] += x2[6];
  102361. x1[7] += x2[7];
  102362. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102363. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102364. r0 = x1[4] - x2[4];
  102365. r1 = x1[5] - x2[5];
  102366. x1[4] += x2[4];
  102367. x1[5] += x2[5];
  102368. x2[4] = MULT_NORM(r1 * T[5] + r0 * T[4]);
  102369. x2[5] = MULT_NORM(r1 * T[4] - r0 * T[5]);
  102370. r0 = x1[2] - x2[2];
  102371. r1 = x1[3] - x2[3];
  102372. x1[2] += x2[2];
  102373. x1[3] += x2[3];
  102374. x2[2] = MULT_NORM(r1 * T[9] + r0 * T[8]);
  102375. x2[3] = MULT_NORM(r1 * T[8] - r0 * T[9]);
  102376. r0 = x1[0] - x2[0];
  102377. r1 = x1[1] - x2[1];
  102378. x1[0] += x2[0];
  102379. x1[1] += x2[1];
  102380. x2[0] = MULT_NORM(r1 * T[13] + r0 * T[12]);
  102381. x2[1] = MULT_NORM(r1 * T[12] - r0 * T[13]);
  102382. x1-=8;
  102383. x2-=8;
  102384. T+=16;
  102385. }while(x2>=x);
  102386. }
  102387. STIN void mdct_butterfly_generic(DATA_TYPE *T,
  102388. DATA_TYPE *x,
  102389. int points,
  102390. int trigint){
  102391. DATA_TYPE *x1 = x + points - 8;
  102392. DATA_TYPE *x2 = x + (points>>1) - 8;
  102393. REG_TYPE r0;
  102394. REG_TYPE r1;
  102395. do{
  102396. r0 = x1[6] - x2[6];
  102397. r1 = x1[7] - x2[7];
  102398. x1[6] += x2[6];
  102399. x1[7] += x2[7];
  102400. x2[6] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102401. x2[7] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102402. T+=trigint;
  102403. r0 = x1[4] - x2[4];
  102404. r1 = x1[5] - x2[5];
  102405. x1[4] += x2[4];
  102406. x1[5] += x2[5];
  102407. x2[4] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102408. x2[5] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102409. T+=trigint;
  102410. r0 = x1[2] - x2[2];
  102411. r1 = x1[3] - x2[3];
  102412. x1[2] += x2[2];
  102413. x1[3] += x2[3];
  102414. x2[2] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102415. x2[3] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102416. T+=trigint;
  102417. r0 = x1[0] - x2[0];
  102418. r1 = x1[1] - x2[1];
  102419. x1[0] += x2[0];
  102420. x1[1] += x2[1];
  102421. x2[0] = MULT_NORM(r1 * T[1] + r0 * T[0]);
  102422. x2[1] = MULT_NORM(r1 * T[0] - r0 * T[1]);
  102423. T+=trigint;
  102424. x1-=8;
  102425. x2-=8;
  102426. }while(x2>=x);
  102427. }
  102428. STIN void mdct_butterflies(mdct_lookup *init,
  102429. DATA_TYPE *x,
  102430. int points){
  102431. DATA_TYPE *T=init->trig;
  102432. int stages=init->log2n-5;
  102433. int i,j;
  102434. if(--stages>0){
  102435. mdct_butterfly_first(T,x,points);
  102436. }
  102437. for(i=1;--stages>0;i++){
  102438. for(j=0;j<(1<<i);j++)
  102439. mdct_butterfly_generic(T,x+(points>>i)*j,points>>i,4<<i);
  102440. }
  102441. for(j=0;j<points;j+=32)
  102442. mdct_butterfly_32(x+j);
  102443. }
  102444. void mdct_clear(mdct_lookup *l){
  102445. if(l){
  102446. if(l->trig)_ogg_free(l->trig);
  102447. if(l->bitrev)_ogg_free(l->bitrev);
  102448. memset(l,0,sizeof(*l));
  102449. }
  102450. }
  102451. STIN void mdct_bitreverse(mdct_lookup *init,
  102452. DATA_TYPE *x){
  102453. int n = init->n;
  102454. int *bit = init->bitrev;
  102455. DATA_TYPE *w0 = x;
  102456. DATA_TYPE *w1 = x = w0+(n>>1);
  102457. DATA_TYPE *T = init->trig+n;
  102458. do{
  102459. DATA_TYPE *x0 = x+bit[0];
  102460. DATA_TYPE *x1 = x+bit[1];
  102461. REG_TYPE r0 = x0[1] - x1[1];
  102462. REG_TYPE r1 = x0[0] + x1[0];
  102463. REG_TYPE r2 = MULT_NORM(r1 * T[0] + r0 * T[1]);
  102464. REG_TYPE r3 = MULT_NORM(r1 * T[1] - r0 * T[0]);
  102465. w1 -= 4;
  102466. r0 = HALVE(x0[1] + x1[1]);
  102467. r1 = HALVE(x0[0] - x1[0]);
  102468. w0[0] = r0 + r2;
  102469. w1[2] = r0 - r2;
  102470. w0[1] = r1 + r3;
  102471. w1[3] = r3 - r1;
  102472. x0 = x+bit[2];
  102473. x1 = x+bit[3];
  102474. r0 = x0[1] - x1[1];
  102475. r1 = x0[0] + x1[0];
  102476. r2 = MULT_NORM(r1 * T[2] + r0 * T[3]);
  102477. r3 = MULT_NORM(r1 * T[3] - r0 * T[2]);
  102478. r0 = HALVE(x0[1] + x1[1]);
  102479. r1 = HALVE(x0[0] - x1[0]);
  102480. w0[2] = r0 + r2;
  102481. w1[0] = r0 - r2;
  102482. w0[3] = r1 + r3;
  102483. w1[1] = r3 - r1;
  102484. T += 4;
  102485. bit += 4;
  102486. w0 += 4;
  102487. }while(w0<w1);
  102488. }
  102489. void mdct_backward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102490. int n=init->n;
  102491. int n2=n>>1;
  102492. int n4=n>>2;
  102493. DATA_TYPE *iX = in+n2-7;
  102494. DATA_TYPE *oX = out+n2+n4;
  102495. DATA_TYPE *T = init->trig+n4;
  102496. do{
  102497. oX -= 4;
  102498. oX[0] = MULT_NORM(-iX[2] * T[3] - iX[0] * T[2]);
  102499. oX[1] = MULT_NORM (iX[0] * T[3] - iX[2] * T[2]);
  102500. oX[2] = MULT_NORM(-iX[6] * T[1] - iX[4] * T[0]);
  102501. oX[3] = MULT_NORM (iX[4] * T[1] - iX[6] * T[0]);
  102502. iX -= 8;
  102503. T += 4;
  102504. }while(iX>=in);
  102505. iX = in+n2-8;
  102506. oX = out+n2+n4;
  102507. T = init->trig+n4;
  102508. do{
  102509. T -= 4;
  102510. oX[0] = MULT_NORM (iX[4] * T[3] + iX[6] * T[2]);
  102511. oX[1] = MULT_NORM (iX[4] * T[2] - iX[6] * T[3]);
  102512. oX[2] = MULT_NORM (iX[0] * T[1] + iX[2] * T[0]);
  102513. oX[3] = MULT_NORM (iX[0] * T[0] - iX[2] * T[1]);
  102514. iX -= 8;
  102515. oX += 4;
  102516. }while(iX>=in);
  102517. mdct_butterflies(init,out+n2,n2);
  102518. mdct_bitreverse(init,out);
  102519. {
  102520. DATA_TYPE *oX1=out+n2+n4;
  102521. DATA_TYPE *oX2=out+n2+n4;
  102522. DATA_TYPE *iX =out;
  102523. T =init->trig+n2;
  102524. do{
  102525. oX1-=4;
  102526. oX1[3] = MULT_NORM (iX[0] * T[1] - iX[1] * T[0]);
  102527. oX2[0] = -MULT_NORM (iX[0] * T[0] + iX[1] * T[1]);
  102528. oX1[2] = MULT_NORM (iX[2] * T[3] - iX[3] * T[2]);
  102529. oX2[1] = -MULT_NORM (iX[2] * T[2] + iX[3] * T[3]);
  102530. oX1[1] = MULT_NORM (iX[4] * T[5] - iX[5] * T[4]);
  102531. oX2[2] = -MULT_NORM (iX[4] * T[4] + iX[5] * T[5]);
  102532. oX1[0] = MULT_NORM (iX[6] * T[7] - iX[7] * T[6]);
  102533. oX2[3] = -MULT_NORM (iX[6] * T[6] + iX[7] * T[7]);
  102534. oX2+=4;
  102535. iX += 8;
  102536. T += 8;
  102537. }while(iX<oX1);
  102538. iX=out+n2+n4;
  102539. oX1=out+n4;
  102540. oX2=oX1;
  102541. do{
  102542. oX1-=4;
  102543. iX-=4;
  102544. oX2[0] = -(oX1[3] = iX[3]);
  102545. oX2[1] = -(oX1[2] = iX[2]);
  102546. oX2[2] = -(oX1[1] = iX[1]);
  102547. oX2[3] = -(oX1[0] = iX[0]);
  102548. oX2+=4;
  102549. }while(oX2<iX);
  102550. iX=out+n2+n4;
  102551. oX1=out+n2+n4;
  102552. oX2=out+n2;
  102553. do{
  102554. oX1-=4;
  102555. oX1[0]= iX[3];
  102556. oX1[1]= iX[2];
  102557. oX1[2]= iX[1];
  102558. oX1[3]= iX[0];
  102559. iX+=4;
  102560. }while(oX1>oX2);
  102561. }
  102562. }
  102563. void mdct_forward(mdct_lookup *init, DATA_TYPE *in, DATA_TYPE *out){
  102564. int n=init->n;
  102565. int n2=n>>1;
  102566. int n4=n>>2;
  102567. int n8=n>>3;
  102568. DATA_TYPE *w=(DATA_TYPE*) alloca(n*sizeof(*w)); /* forward needs working space */
  102569. DATA_TYPE *w2=w+n2;
  102570. REG_TYPE r0;
  102571. REG_TYPE r1;
  102572. DATA_TYPE *x0=in+n2+n4;
  102573. DATA_TYPE *x1=x0+1;
  102574. DATA_TYPE *T=init->trig+n2;
  102575. int i=0;
  102576. for(i=0;i<n8;i+=2){
  102577. x0 -=4;
  102578. T-=2;
  102579. r0= x0[2] + x1[0];
  102580. r1= x0[0] + x1[2];
  102581. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102582. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102583. x1 +=4;
  102584. }
  102585. x1=in+1;
  102586. for(;i<n2-n8;i+=2){
  102587. T-=2;
  102588. x0 -=4;
  102589. r0= x0[2] - x1[0];
  102590. r1= x0[0] - x1[2];
  102591. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102592. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102593. x1 +=4;
  102594. }
  102595. x0=in+n;
  102596. for(;i<n2;i+=2){
  102597. T-=2;
  102598. x0 -=4;
  102599. r0= -x0[2] - x1[0];
  102600. r1= -x0[0] - x1[2];
  102601. w2[i]= MULT_NORM(r1*T[1] + r0*T[0]);
  102602. w2[i+1]= MULT_NORM(r1*T[0] - r0*T[1]);
  102603. x1 +=4;
  102604. }
  102605. mdct_butterflies(init,w+n2,n2);
  102606. mdct_bitreverse(init,w);
  102607. T=init->trig+n2;
  102608. x0=out+n2;
  102609. for(i=0;i<n4;i++){
  102610. x0--;
  102611. out[i] =MULT_NORM((w[0]*T[0]+w[1]*T[1])*init->scale);
  102612. x0[0] =MULT_NORM((w[0]*T[1]-w[1]*T[0])*init->scale);
  102613. w+=2;
  102614. T+=2;
  102615. }
  102616. }
  102617. #endif
  102618. /*** End of inlined file: mdct.c ***/
  102619. /*** Start of inlined file: psy.c ***/
  102620. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  102621. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  102622. // tasks..
  102623. #if JUCE_MSVC
  102624. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  102625. #endif
  102626. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  102627. #if JUCE_USE_OGGVORBIS
  102628. #include <stdlib.h>
  102629. #include <math.h>
  102630. #include <string.h>
  102631. /*** Start of inlined file: masking.h ***/
  102632. #ifndef _V_MASKING_H_
  102633. #define _V_MASKING_H_
  102634. #define MAX_ATH 88
  102635. static float ATH[]={
  102636. -51, -52, -53, -54, -55, -56, -57, -58,
  102637. -59, -60, -61, -62, -63, -64, -65, -66,
  102638. -67, -68, -69, -70, -71, -72, -73, -74,
  102639. -75, -76, -77, -78, -80, -81, -82, -83,
  102640. -84, -85, -86, -87, -88, -88, -89, -89,
  102641. -90, -91, -91, -92, -93, -94, -95, -96,
  102642. -96, -97, -98, -98, -99, -99,-100,-100,
  102643. -101,-102,-103,-104,-106,-107,-107,-107,
  102644. -107,-105,-103,-102,-101, -99, -98, -96,
  102645. -95, -95, -96, -97, -96, -95, -93, -90,
  102646. -80, -70, -50, -40, -30, -30, -30, -30
  102647. };
  102648. #define EHMER_OFFSET 16
  102649. #define EHMER_MAX 56
  102650. static float tonemasks[P_BANDS][6][EHMER_MAX]={
  102651. {{ -60, -60, -60, -60, -60, -60, -60, -60,
  102652. -60, -60, -60, -60, -62, -62, -65, -73,
  102653. -69, -68, -68, -67, -70, -70, -72, -74,
  102654. -75, -79, -79, -80, -83, -88, -93, -100,
  102655. -110, -999, -999, -999, -999, -999, -999, -999,
  102656. -999, -999, -999, -999, -999, -999, -999, -999,
  102657. -999, -999, -999, -999, -999, -999, -999, -999},
  102658. { -48, -48, -48, -48, -48, -48, -48, -48,
  102659. -48, -48, -48, -48, -48, -53, -61, -66,
  102660. -66, -68, -67, -70, -76, -76, -72, -73,
  102661. -75, -76, -78, -79, -83, -88, -93, -100,
  102662. -110, -999, -999, -999, -999, -999, -999, -999,
  102663. -999, -999, -999, -999, -999, -999, -999, -999,
  102664. -999, -999, -999, -999, -999, -999, -999, -999},
  102665. { -37, -37, -37, -37, -37, -37, -37, -37,
  102666. -38, -40, -42, -46, -48, -53, -55, -62,
  102667. -65, -58, -56, -56, -61, -60, -65, -67,
  102668. -69, -71, -77, -77, -78, -80, -82, -84,
  102669. -88, -93, -98, -106, -112, -999, -999, -999,
  102670. -999, -999, -999, -999, -999, -999, -999, -999,
  102671. -999, -999, -999, -999, -999, -999, -999, -999},
  102672. { -25, -25, -25, -25, -25, -25, -25, -25,
  102673. -25, -26, -27, -29, -32, -38, -48, -52,
  102674. -52, -50, -48, -48, -51, -52, -54, -60,
  102675. -67, -67, -66, -68, -69, -73, -73, -76,
  102676. -80, -81, -81, -85, -85, -86, -88, -93,
  102677. -100, -110, -999, -999, -999, -999, -999, -999,
  102678. -999, -999, -999, -999, -999, -999, -999, -999},
  102679. { -16, -16, -16, -16, -16, -16, -16, -16,
  102680. -17, -19, -20, -22, -26, -28, -31, -40,
  102681. -47, -39, -39, -40, -42, -43, -47, -51,
  102682. -57, -52, -55, -55, -60, -58, -62, -63,
  102683. -70, -67, -69, -72, -73, -77, -80, -82,
  102684. -83, -87, -90, -94, -98, -104, -115, -999,
  102685. -999, -999, -999, -999, -999, -999, -999, -999},
  102686. { -8, -8, -8, -8, -8, -8, -8, -8,
  102687. -8, -8, -10, -11, -15, -19, -25, -30,
  102688. -34, -31, -30, -31, -29, -32, -35, -42,
  102689. -48, -42, -44, -46, -50, -50, -51, -52,
  102690. -59, -54, -55, -55, -58, -62, -63, -66,
  102691. -72, -73, -76, -75, -78, -80, -80, -81,
  102692. -84, -88, -90, -94, -98, -101, -106, -110}},
  102693. {{ -66, -66, -66, -66, -66, -66, -66, -66,
  102694. -66, -66, -66, -66, -66, -67, -67, -67,
  102695. -76, -72, -71, -74, -76, -76, -75, -78,
  102696. -79, -79, -81, -83, -86, -89, -93, -97,
  102697. -100, -105, -110, -999, -999, -999, -999, -999,
  102698. -999, -999, -999, -999, -999, -999, -999, -999,
  102699. -999, -999, -999, -999, -999, -999, -999, -999},
  102700. { -47, -47, -47, -47, -47, -47, -47, -47,
  102701. -47, -47, -47, -48, -51, -55, -59, -66,
  102702. -66, -66, -67, -66, -68, -69, -70, -74,
  102703. -79, -77, -77, -78, -80, -81, -82, -84,
  102704. -86, -88, -91, -95, -100, -108, -116, -999,
  102705. -999, -999, -999, -999, -999, -999, -999, -999,
  102706. -999, -999, -999, -999, -999, -999, -999, -999},
  102707. { -36, -36, -36, -36, -36, -36, -36, -36,
  102708. -36, -37, -37, -41, -44, -48, -51, -58,
  102709. -62, -60, -57, -59, -59, -60, -63, -65,
  102710. -72, -71, -70, -72, -74, -77, -76, -78,
  102711. -81, -81, -80, -83, -86, -91, -96, -100,
  102712. -105, -110, -999, -999, -999, -999, -999, -999,
  102713. -999, -999, -999, -999, -999, -999, -999, -999},
  102714. { -28, -28, -28, -28, -28, -28, -28, -28,
  102715. -28, -30, -32, -32, -33, -35, -41, -49,
  102716. -50, -49, -47, -48, -48, -52, -51, -57,
  102717. -65, -61, -59, -61, -64, -69, -70, -74,
  102718. -77, -77, -78, -81, -84, -85, -87, -90,
  102719. -92, -96, -100, -107, -112, -999, -999, -999,
  102720. -999, -999, -999, -999, -999, -999, -999, -999},
  102721. { -19, -19, -19, -19, -19, -19, -19, -19,
  102722. -20, -21, -23, -27, -30, -35, -36, -41,
  102723. -46, -44, -42, -40, -41, -41, -43, -48,
  102724. -55, -53, -52, -53, -56, -59, -58, -60,
  102725. -67, -66, -69, -71, -72, -75, -79, -81,
  102726. -84, -87, -90, -93, -97, -101, -107, -114,
  102727. -999, -999, -999, -999, -999, -999, -999, -999},
  102728. { -9, -9, -9, -9, -9, -9, -9, -9,
  102729. -11, -12, -12, -15, -16, -20, -23, -30,
  102730. -37, -34, -33, -34, -31, -32, -32, -38,
  102731. -47, -44, -41, -40, -47, -49, -46, -46,
  102732. -58, -50, -50, -54, -58, -62, -64, -67,
  102733. -67, -70, -72, -76, -79, -83, -87, -91,
  102734. -96, -100, -104, -110, -999, -999, -999, -999}},
  102735. {{ -62, -62, -62, -62, -62, -62, -62, -62,
  102736. -62, -62, -63, -64, -66, -67, -66, -68,
  102737. -75, -72, -76, -75, -76, -78, -79, -82,
  102738. -84, -85, -90, -94, -101, -110, -999, -999,
  102739. -999, -999, -999, -999, -999, -999, -999, -999,
  102740. -999, -999, -999, -999, -999, -999, -999, -999,
  102741. -999, -999, -999, -999, -999, -999, -999, -999},
  102742. { -59, -59, -59, -59, -59, -59, -59, -59,
  102743. -59, -59, -59, -60, -60, -61, -63, -66,
  102744. -71, -68, -70, -70, -71, -72, -72, -75,
  102745. -81, -78, -79, -82, -83, -86, -90, -97,
  102746. -103, -113, -999, -999, -999, -999, -999, -999,
  102747. -999, -999, -999, -999, -999, -999, -999, -999,
  102748. -999, -999, -999, -999, -999, -999, -999, -999},
  102749. { -53, -53, -53, -53, -53, -53, -53, -53,
  102750. -53, -54, -55, -57, -56, -57, -55, -61,
  102751. -65, -60, -60, -62, -63, -63, -66, -68,
  102752. -74, -73, -75, -75, -78, -80, -80, -82,
  102753. -85, -90, -96, -101, -108, -999, -999, -999,
  102754. -999, -999, -999, -999, -999, -999, -999, -999,
  102755. -999, -999, -999, -999, -999, -999, -999, -999},
  102756. { -46, -46, -46, -46, -46, -46, -46, -46,
  102757. -46, -46, -47, -47, -47, -47, -48, -51,
  102758. -57, -51, -49, -50, -51, -53, -54, -59,
  102759. -66, -60, -62, -67, -67, -70, -72, -75,
  102760. -76, -78, -81, -85, -88, -94, -97, -104,
  102761. -112, -999, -999, -999, -999, -999, -999, -999,
  102762. -999, -999, -999, -999, -999, -999, -999, -999},
  102763. { -36, -36, -36, -36, -36, -36, -36, -36,
  102764. -39, -41, -42, -42, -39, -38, -41, -43,
  102765. -52, -44, -40, -39, -37, -37, -40, -47,
  102766. -54, -50, -48, -50, -55, -61, -59, -62,
  102767. -66, -66, -66, -69, -69, -73, -74, -74,
  102768. -75, -77, -79, -82, -87, -91, -95, -100,
  102769. -108, -115, -999, -999, -999, -999, -999, -999},
  102770. { -28, -26, -24, -22, -20, -20, -23, -29,
  102771. -30, -31, -28, -27, -28, -28, -28, -35,
  102772. -40, -33, -32, -29, -30, -30, -30, -37,
  102773. -45, -41, -37, -38, -45, -47, -47, -48,
  102774. -53, -49, -48, -50, -49, -49, -51, -52,
  102775. -58, -56, -57, -56, -60, -61, -62, -70,
  102776. -72, -74, -78, -83, -88, -93, -100, -106}},
  102777. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102778. -999, -110, -105, -100, -95, -91, -87, -83,
  102779. -80, -78, -76, -78, -78, -81, -83, -85,
  102780. -86, -85, -86, -87, -90, -97, -107, -999,
  102781. -999, -999, -999, -999, -999, -999, -999, -999,
  102782. -999, -999, -999, -999, -999, -999, -999, -999,
  102783. -999, -999, -999, -999, -999, -999, -999, -999},
  102784. {-999, -999, -999, -110, -105, -100, -95, -90,
  102785. -85, -81, -77, -73, -70, -67, -67, -68,
  102786. -75, -73, -70, -69, -70, -72, -75, -79,
  102787. -84, -83, -84, -86, -88, -89, -89, -93,
  102788. -98, -105, -112, -999, -999, -999, -999, -999,
  102789. -999, -999, -999, -999, -999, -999, -999, -999,
  102790. -999, -999, -999, -999, -999, -999, -999, -999},
  102791. {-105, -100, -95, -90, -85, -80, -76, -71,
  102792. -68, -68, -65, -63, -63, -62, -62, -64,
  102793. -65, -64, -61, -62, -63, -64, -66, -68,
  102794. -73, -73, -74, -75, -76, -81, -83, -85,
  102795. -88, -89, -92, -95, -100, -108, -999, -999,
  102796. -999, -999, -999, -999, -999, -999, -999, -999,
  102797. -999, -999, -999, -999, -999, -999, -999, -999},
  102798. { -80, -75, -71, -68, -65, -63, -62, -61,
  102799. -61, -61, -61, -59, -56, -57, -53, -50,
  102800. -58, -52, -50, -50, -52, -53, -54, -58,
  102801. -67, -63, -67, -68, -72, -75, -78, -80,
  102802. -81, -81, -82, -85, -89, -90, -93, -97,
  102803. -101, -107, -114, -999, -999, -999, -999, -999,
  102804. -999, -999, -999, -999, -999, -999, -999, -999},
  102805. { -65, -61, -59, -57, -56, -55, -55, -56,
  102806. -56, -57, -55, -53, -52, -47, -44, -44,
  102807. -50, -44, -41, -39, -39, -42, -40, -46,
  102808. -51, -49, -50, -53, -54, -63, -60, -61,
  102809. -62, -66, -66, -66, -70, -73, -74, -75,
  102810. -76, -75, -79, -85, -89, -91, -96, -102,
  102811. -110, -999, -999, -999, -999, -999, -999, -999},
  102812. { -52, -50, -49, -49, -48, -48, -48, -49,
  102813. -50, -50, -49, -46, -43, -39, -35, -33,
  102814. -38, -36, -32, -29, -32, -32, -32, -35,
  102815. -44, -39, -38, -38, -46, -50, -45, -46,
  102816. -53, -50, -50, -50, -54, -54, -53, -53,
  102817. -56, -57, -59, -66, -70, -72, -74, -79,
  102818. -83, -85, -90, -97, -114, -999, -999, -999}},
  102819. {{-999, -999, -999, -999, -999, -999, -110, -105,
  102820. -100, -95, -90, -86, -80, -75, -75, -79,
  102821. -80, -79, -80, -81, -82, -88, -95, -103,
  102822. -110, -999, -999, -999, -999, -999, -999, -999,
  102823. -999, -999, -999, -999, -999, -999, -999, -999,
  102824. -999, -999, -999, -999, -999, -999, -999, -999,
  102825. -999, -999, -999, -999, -999, -999, -999, -999},
  102826. {-999, -999, -999, -999, -108, -103, -98, -93,
  102827. -88, -83, -79, -78, -75, -71, -67, -68,
  102828. -73, -73, -72, -73, -75, -77, -80, -82,
  102829. -88, -93, -100, -107, -114, -999, -999, -999,
  102830. -999, -999, -999, -999, -999, -999, -999, -999,
  102831. -999, -999, -999, -999, -999, -999, -999, -999,
  102832. -999, -999, -999, -999, -999, -999, -999, -999},
  102833. {-999, -999, -999, -110, -105, -101, -96, -90,
  102834. -86, -81, -77, -73, -69, -66, -61, -62,
  102835. -66, -64, -62, -65, -66, -70, -72, -76,
  102836. -81, -80, -84, -90, -95, -102, -110, -999,
  102837. -999, -999, -999, -999, -999, -999, -999, -999,
  102838. -999, -999, -999, -999, -999, -999, -999, -999,
  102839. -999, -999, -999, -999, -999, -999, -999, -999},
  102840. {-999, -999, -999, -107, -103, -97, -92, -88,
  102841. -83, -79, -74, -70, -66, -59, -53, -58,
  102842. -62, -55, -54, -54, -54, -58, -61, -62,
  102843. -72, -70, -72, -75, -78, -80, -81, -80,
  102844. -83, -83, -88, -93, -100, -107, -115, -999,
  102845. -999, -999, -999, -999, -999, -999, -999, -999,
  102846. -999, -999, -999, -999, -999, -999, -999, -999},
  102847. {-999, -999, -999, -105, -100, -95, -90, -85,
  102848. -80, -75, -70, -66, -62, -56, -48, -44,
  102849. -48, -46, -46, -43, -46, -48, -48, -51,
  102850. -58, -58, -59, -60, -62, -62, -61, -61,
  102851. -65, -64, -65, -68, -70, -74, -75, -78,
  102852. -81, -86, -95, -110, -999, -999, -999, -999,
  102853. -999, -999, -999, -999, -999, -999, -999, -999},
  102854. {-999, -999, -105, -100, -95, -90, -85, -80,
  102855. -75, -70, -65, -61, -55, -49, -39, -33,
  102856. -40, -35, -32, -38, -40, -33, -35, -37,
  102857. -46, -41, -45, -44, -46, -42, -45, -46,
  102858. -52, -50, -50, -50, -54, -54, -55, -57,
  102859. -62, -64, -66, -68, -70, -76, -81, -90,
  102860. -100, -110, -999, -999, -999, -999, -999, -999}},
  102861. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102862. -105, -98, -90, -85, -82, -83, -80, -78,
  102863. -84, -79, -80, -83, -87, -89, -91, -93,
  102864. -99, -106, -117, -999, -999, -999, -999, -999,
  102865. -999, -999, -999, -999, -999, -999, -999, -999,
  102866. -999, -999, -999, -999, -999, -999, -999, -999,
  102867. -999, -999, -999, -999, -999, -999, -999, -999},
  102868. {-999, -999, -999, -999, -999, -999, -999, -999,
  102869. -105, -98, -90, -85, -80, -75, -70, -68,
  102870. -74, -72, -74, -77, -80, -82, -85, -87,
  102871. -92, -89, -91, -95, -100, -106, -112, -999,
  102872. -999, -999, -999, -999, -999, -999, -999, -999,
  102873. -999, -999, -999, -999, -999, -999, -999, -999,
  102874. -999, -999, -999, -999, -999, -999, -999, -999},
  102875. {-999, -999, -999, -999, -999, -999, -999, -999,
  102876. -105, -98, -90, -83, -75, -71, -63, -64,
  102877. -67, -62, -64, -67, -70, -73, -77, -81,
  102878. -84, -83, -85, -89, -90, -93, -98, -104,
  102879. -109, -114, -999, -999, -999, -999, -999, -999,
  102880. -999, -999, -999, -999, -999, -999, -999, -999,
  102881. -999, -999, -999, -999, -999, -999, -999, -999},
  102882. {-999, -999, -999, -999, -999, -999, -999, -999,
  102883. -103, -96, -88, -81, -75, -68, -58, -54,
  102884. -56, -54, -56, -56, -58, -60, -63, -66,
  102885. -74, -69, -72, -72, -75, -74, -77, -81,
  102886. -81, -82, -84, -87, -93, -96, -99, -104,
  102887. -110, -999, -999, -999, -999, -999, -999, -999,
  102888. -999, -999, -999, -999, -999, -999, -999, -999},
  102889. {-999, -999, -999, -999, -999, -108, -102, -96,
  102890. -91, -85, -80, -74, -68, -60, -51, -46,
  102891. -48, -46, -43, -45, -47, -47, -49, -48,
  102892. -56, -53, -55, -58, -57, -63, -58, -60,
  102893. -66, -64, -67, -70, -70, -74, -77, -84,
  102894. -86, -89, -91, -93, -94, -101, -109, -118,
  102895. -999, -999, -999, -999, -999, -999, -999, -999},
  102896. {-999, -999, -999, -108, -103, -98, -93, -88,
  102897. -83, -78, -73, -68, -60, -53, -44, -35,
  102898. -38, -38, -34, -34, -36, -40, -41, -44,
  102899. -51, -45, -46, -47, -46, -54, -50, -49,
  102900. -50, -50, -50, -51, -54, -57, -58, -60,
  102901. -66, -66, -66, -64, -65, -68, -77, -82,
  102902. -87, -95, -110, -999, -999, -999, -999, -999}},
  102903. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102904. -107, -102, -97, -92, -87, -83, -78, -75,
  102905. -82, -79, -83, -85, -89, -92, -95, -98,
  102906. -101, -105, -109, -113, -999, -999, -999, -999,
  102907. -999, -999, -999, -999, -999, -999, -999, -999,
  102908. -999, -999, -999, -999, -999, -999, -999, -999,
  102909. -999, -999, -999, -999, -999, -999, -999, -999},
  102910. {-999, -999, -999, -999, -999, -999, -999, -106,
  102911. -100, -95, -90, -86, -81, -78, -74, -69,
  102912. -74, -74, -76, -79, -83, -84, -86, -89,
  102913. -92, -97, -93, -100, -103, -107, -110, -999,
  102914. -999, -999, -999, -999, -999, -999, -999, -999,
  102915. -999, -999, -999, -999, -999, -999, -999, -999,
  102916. -999, -999, -999, -999, -999, -999, -999, -999},
  102917. {-999, -999, -999, -999, -999, -999, -106, -100,
  102918. -95, -90, -87, -83, -80, -75, -69, -60,
  102919. -66, -66, -68, -70, -74, -78, -79, -81,
  102920. -81, -83, -84, -87, -93, -96, -99, -103,
  102921. -107, -110, -999, -999, -999, -999, -999, -999,
  102922. -999, -999, -999, -999, -999, -999, -999, -999,
  102923. -999, -999, -999, -999, -999, -999, -999, -999},
  102924. {-999, -999, -999, -999, -999, -108, -103, -98,
  102925. -93, -89, -85, -82, -78, -71, -62, -55,
  102926. -58, -58, -54, -54, -55, -59, -61, -62,
  102927. -70, -66, -66, -67, -70, -72, -75, -78,
  102928. -84, -84, -84, -88, -91, -90, -95, -98,
  102929. -102, -103, -106, -110, -999, -999, -999, -999,
  102930. -999, -999, -999, -999, -999, -999, -999, -999},
  102931. {-999, -999, -999, -999, -108, -103, -98, -94,
  102932. -90, -87, -82, -79, -73, -67, -58, -47,
  102933. -50, -45, -41, -45, -48, -44, -44, -49,
  102934. -54, -51, -48, -47, -49, -50, -51, -57,
  102935. -58, -60, -63, -69, -70, -69, -71, -74,
  102936. -78, -82, -90, -95, -101, -105, -110, -999,
  102937. -999, -999, -999, -999, -999, -999, -999, -999},
  102938. {-999, -999, -999, -105, -101, -97, -93, -90,
  102939. -85, -80, -77, -72, -65, -56, -48, -37,
  102940. -40, -36, -34, -40, -50, -47, -38, -41,
  102941. -47, -38, -35, -39, -38, -43, -40, -45,
  102942. -50, -45, -44, -47, -50, -55, -48, -48,
  102943. -52, -66, -70, -76, -82, -90, -97, -105,
  102944. -110, -999, -999, -999, -999, -999, -999, -999}},
  102945. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102946. -999, -108, -103, -98, -93, -86, -79, -76,
  102947. -83, -81, -85, -87, -89, -93, -98, -102,
  102948. -107, -112, -999, -999, -999, -999, -999, -999,
  102949. -999, -999, -999, -999, -999, -999, -999, -999,
  102950. -999, -999, -999, -999, -999, -999, -999, -999,
  102951. -999, -999, -999, -999, -999, -999, -999, -999},
  102952. {-999, -999, -999, -999, -999, -999, -999, -999,
  102953. -999, -108, -103, -98, -93, -86, -79, -71,
  102954. -77, -74, -77, -79, -81, -84, -85, -90,
  102955. -92, -93, -92, -98, -101, -108, -112, -999,
  102956. -999, -999, -999, -999, -999, -999, -999, -999,
  102957. -999, -999, -999, -999, -999, -999, -999, -999,
  102958. -999, -999, -999, -999, -999, -999, -999, -999},
  102959. {-999, -999, -999, -999, -999, -999, -999, -999,
  102960. -108, -103, -98, -93, -87, -78, -68, -65,
  102961. -66, -62, -65, -67, -70, -73, -75, -78,
  102962. -82, -82, -83, -84, -91, -93, -98, -102,
  102963. -106, -110, -999, -999, -999, -999, -999, -999,
  102964. -999, -999, -999, -999, -999, -999, -999, -999,
  102965. -999, -999, -999, -999, -999, -999, -999, -999},
  102966. {-999, -999, -999, -999, -999, -999, -999, -999,
  102967. -105, -100, -95, -90, -82, -74, -62, -57,
  102968. -58, -56, -51, -52, -52, -54, -54, -58,
  102969. -66, -59, -60, -63, -66, -69, -73, -79,
  102970. -83, -84, -80, -81, -81, -82, -88, -92,
  102971. -98, -105, -113, -999, -999, -999, -999, -999,
  102972. -999, -999, -999, -999, -999, -999, -999, -999},
  102973. {-999, -999, -999, -999, -999, -999, -999, -107,
  102974. -102, -97, -92, -84, -79, -69, -57, -47,
  102975. -52, -47, -44, -45, -50, -52, -42, -42,
  102976. -53, -43, -43, -48, -51, -56, -55, -52,
  102977. -57, -59, -61, -62, -67, -71, -78, -83,
  102978. -86, -94, -98, -103, -110, -999, -999, -999,
  102979. -999, -999, -999, -999, -999, -999, -999, -999},
  102980. {-999, -999, -999, -999, -999, -999, -105, -100,
  102981. -95, -90, -84, -78, -70, -61, -51, -41,
  102982. -40, -38, -40, -46, -52, -51, -41, -40,
  102983. -46, -40, -38, -38, -41, -46, -41, -46,
  102984. -47, -43, -43, -45, -41, -45, -56, -67,
  102985. -68, -83, -87, -90, -95, -102, -107, -113,
  102986. -999, -999, -999, -999, -999, -999, -999, -999}},
  102987. {{-999, -999, -999, -999, -999, -999, -999, -999,
  102988. -999, -109, -105, -101, -96, -91, -84, -77,
  102989. -82, -82, -85, -89, -94, -100, -106, -110,
  102990. -999, -999, -999, -999, -999, -999, -999, -999,
  102991. -999, -999, -999, -999, -999, -999, -999, -999,
  102992. -999, -999, -999, -999, -999, -999, -999, -999,
  102993. -999, -999, -999, -999, -999, -999, -999, -999},
  102994. {-999, -999, -999, -999, -999, -999, -999, -999,
  102995. -999, -106, -103, -98, -92, -85, -80, -71,
  102996. -75, -72, -76, -80, -84, -86, -89, -93,
  102997. -100, -107, -113, -999, -999, -999, -999, -999,
  102998. -999, -999, -999, -999, -999, -999, -999, -999,
  102999. -999, -999, -999, -999, -999, -999, -999, -999,
  103000. -999, -999, -999, -999, -999, -999, -999, -999},
  103001. {-999, -999, -999, -999, -999, -999, -999, -107,
  103002. -104, -101, -97, -92, -88, -84, -80, -64,
  103003. -66, -63, -64, -66, -69, -73, -77, -83,
  103004. -83, -86, -91, -98, -104, -111, -999, -999,
  103005. -999, -999, -999, -999, -999, -999, -999, -999,
  103006. -999, -999, -999, -999, -999, -999, -999, -999,
  103007. -999, -999, -999, -999, -999, -999, -999, -999},
  103008. {-999, -999, -999, -999, -999, -999, -999, -107,
  103009. -104, -101, -97, -92, -90, -84, -74, -57,
  103010. -58, -52, -55, -54, -50, -52, -50, -52,
  103011. -63, -62, -69, -76, -77, -78, -78, -79,
  103012. -82, -88, -94, -100, -106, -111, -999, -999,
  103013. -999, -999, -999, -999, -999, -999, -999, -999,
  103014. -999, -999, -999, -999, -999, -999, -999, -999},
  103015. {-999, -999, -999, -999, -999, -999, -106, -102,
  103016. -98, -95, -90, -85, -83, -78, -70, -50,
  103017. -50, -41, -44, -49, -47, -50, -50, -44,
  103018. -55, -46, -47, -48, -48, -54, -49, -49,
  103019. -58, -62, -71, -81, -87, -92, -97, -102,
  103020. -108, -114, -999, -999, -999, -999, -999, -999,
  103021. -999, -999, -999, -999, -999, -999, -999, -999},
  103022. {-999, -999, -999, -999, -999, -999, -106, -102,
  103023. -98, -95, -90, -85, -83, -78, -70, -45,
  103024. -43, -41, -47, -50, -51, -50, -49, -45,
  103025. -47, -41, -44, -41, -39, -43, -38, -37,
  103026. -40, -41, -44, -50, -58, -65, -73, -79,
  103027. -85, -92, -97, -101, -105, -109, -113, -999,
  103028. -999, -999, -999, -999, -999, -999, -999, -999}},
  103029. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103030. -999, -999, -999, -107, -100, -95, -87, -81,
  103031. -85, -83, -88, -93, -100, -107, -114, -999,
  103032. -999, -999, -999, -999, -999, -999, -999, -999,
  103033. -999, -999, -999, -999, -999, -999, -999, -999,
  103034. -999, -999, -999, -999, -999, -999, -999, -999,
  103035. -999, -999, -999, -999, -999, -999, -999, -999},
  103036. {-999, -999, -999, -999, -999, -999, -999, -999,
  103037. -999, -999, -107, -101, -95, -88, -83, -76,
  103038. -73, -72, -79, -84, -90, -95, -100, -105,
  103039. -110, -115, -999, -999, -999, -999, -999, -999,
  103040. -999, -999, -999, -999, -999, -999, -999, -999,
  103041. -999, -999, -999, -999, -999, -999, -999, -999,
  103042. -999, -999, -999, -999, -999, -999, -999, -999},
  103043. {-999, -999, -999, -999, -999, -999, -999, -999,
  103044. -999, -999, -104, -98, -92, -87, -81, -70,
  103045. -65, -62, -67, -71, -74, -80, -85, -91,
  103046. -95, -99, -103, -108, -111, -114, -999, -999,
  103047. -999, -999, -999, -999, -999, -999, -999, -999,
  103048. -999, -999, -999, -999, -999, -999, -999, -999,
  103049. -999, -999, -999, -999, -999, -999, -999, -999},
  103050. {-999, -999, -999, -999, -999, -999, -999, -999,
  103051. -999, -999, -103, -97, -90, -85, -76, -60,
  103052. -56, -54, -60, -62, -61, -56, -63, -65,
  103053. -73, -74, -77, -75, -78, -81, -86, -87,
  103054. -88, -91, -94, -98, -103, -110, -999, -999,
  103055. -999, -999, -999, -999, -999, -999, -999, -999,
  103056. -999, -999, -999, -999, -999, -999, -999, -999},
  103057. {-999, -999, -999, -999, -999, -999, -999, -105,
  103058. -100, -97, -92, -86, -81, -79, -70, -57,
  103059. -51, -47, -51, -58, -60, -56, -53, -50,
  103060. -58, -52, -50, -50, -53, -55, -64, -69,
  103061. -71, -85, -82, -78, -81, -85, -95, -102,
  103062. -112, -999, -999, -999, -999, -999, -999, -999,
  103063. -999, -999, -999, -999, -999, -999, -999, -999},
  103064. {-999, -999, -999, -999, -999, -999, -999, -105,
  103065. -100, -97, -92, -85, -83, -79, -72, -49,
  103066. -40, -43, -43, -54, -56, -51, -50, -40,
  103067. -43, -38, -36, -35, -37, -38, -37, -44,
  103068. -54, -60, -57, -60, -70, -75, -84, -92,
  103069. -103, -112, -999, -999, -999, -999, -999, -999,
  103070. -999, -999, -999, -999, -999, -999, -999, -999}},
  103071. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103072. -999, -999, -999, -110, -102, -95, -89, -82,
  103073. -83, -84, -90, -92, -99, -107, -113, -999,
  103074. -999, -999, -999, -999, -999, -999, -999, -999,
  103075. -999, -999, -999, -999, -999, -999, -999, -999,
  103076. -999, -999, -999, -999, -999, -999, -999, -999,
  103077. -999, -999, -999, -999, -999, -999, -999, -999},
  103078. {-999, -999, -999, -999, -999, -999, -999, -999,
  103079. -999, -999, -107, -101, -95, -89, -83, -72,
  103080. -74, -78, -85, -88, -88, -90, -92, -98,
  103081. -105, -111, -999, -999, -999, -999, -999, -999,
  103082. -999, -999, -999, -999, -999, -999, -999, -999,
  103083. -999, -999, -999, -999, -999, -999, -999, -999,
  103084. -999, -999, -999, -999, -999, -999, -999, -999},
  103085. {-999, -999, -999, -999, -999, -999, -999, -999,
  103086. -999, -109, -103, -97, -93, -87, -81, -70,
  103087. -70, -67, -75, -73, -76, -79, -81, -83,
  103088. -88, -89, -97, -103, -110, -999, -999, -999,
  103089. -999, -999, -999, -999, -999, -999, -999, -999,
  103090. -999, -999, -999, -999, -999, -999, -999, -999,
  103091. -999, -999, -999, -999, -999, -999, -999, -999},
  103092. {-999, -999, -999, -999, -999, -999, -999, -999,
  103093. -999, -107, -100, -94, -88, -83, -75, -63,
  103094. -59, -59, -63, -66, -60, -62, -67, -67,
  103095. -77, -76, -81, -88, -86, -92, -96, -102,
  103096. -109, -116, -999, -999, -999, -999, -999, -999,
  103097. -999, -999, -999, -999, -999, -999, -999, -999,
  103098. -999, -999, -999, -999, -999, -999, -999, -999},
  103099. {-999, -999, -999, -999, -999, -999, -999, -999,
  103100. -999, -105, -98, -92, -86, -81, -73, -56,
  103101. -52, -47, -55, -60, -58, -52, -51, -45,
  103102. -49, -50, -53, -54, -61, -71, -70, -69,
  103103. -78, -79, -87, -90, -96, -104, -112, -999,
  103104. -999, -999, -999, -999, -999, -999, -999, -999,
  103105. -999, -999, -999, -999, -999, -999, -999, -999},
  103106. {-999, -999, -999, -999, -999, -999, -999, -999,
  103107. -999, -103, -96, -90, -86, -78, -70, -51,
  103108. -42, -47, -48, -55, -54, -54, -53, -42,
  103109. -35, -28, -33, -38, -37, -44, -47, -49,
  103110. -54, -63, -68, -78, -82, -89, -94, -99,
  103111. -104, -109, -114, -999, -999, -999, -999, -999,
  103112. -999, -999, -999, -999, -999, -999, -999, -999}},
  103113. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103114. -999, -999, -999, -999, -110, -100, -90, -79,
  103115. -85, -81, -82, -82, -89, -94, -99, -103,
  103116. -109, -115, -999, -999, -999, -999, -999, -999,
  103117. -999, -999, -999, -999, -999, -999, -999, -999,
  103118. -999, -999, -999, -999, -999, -999, -999, -999,
  103119. -999, -999, -999, -999, -999, -999, -999, -999},
  103120. {-999, -999, -999, -999, -999, -999, -999, -999,
  103121. -999, -999, -999, -999, -105, -97, -85, -72,
  103122. -74, -70, -70, -70, -76, -85, -91, -93,
  103123. -97, -103, -109, -115, -999, -999, -999, -999,
  103124. -999, -999, -999, -999, -999, -999, -999, -999,
  103125. -999, -999, -999, -999, -999, -999, -999, -999,
  103126. -999, -999, -999, -999, -999, -999, -999, -999},
  103127. {-999, -999, -999, -999, -999, -999, -999, -999,
  103128. -999, -999, -999, -999, -112, -93, -81, -68,
  103129. -62, -60, -60, -57, -63, -70, -77, -82,
  103130. -90, -93, -98, -104, -109, -113, -999, -999,
  103131. -999, -999, -999, -999, -999, -999, -999, -999,
  103132. -999, -999, -999, -999, -999, -999, -999, -999,
  103133. -999, -999, -999, -999, -999, -999, -999, -999},
  103134. {-999, -999, -999, -999, -999, -999, -999, -999,
  103135. -999, -999, -999, -113, -100, -93, -84, -63,
  103136. -58, -48, -53, -54, -52, -52, -57, -64,
  103137. -66, -76, -83, -81, -85, -85, -90, -95,
  103138. -98, -101, -103, -106, -108, -111, -999, -999,
  103139. -999, -999, -999, -999, -999, -999, -999, -999,
  103140. -999, -999, -999, -999, -999, -999, -999, -999},
  103141. {-999, -999, -999, -999, -999, -999, -999, -999,
  103142. -999, -999, -999, -105, -95, -86, -74, -53,
  103143. -50, -38, -43, -49, -43, -42, -39, -39,
  103144. -46, -52, -57, -56, -72, -69, -74, -81,
  103145. -87, -92, -94, -97, -99, -102, -105, -108,
  103146. -999, -999, -999, -999, -999, -999, -999, -999,
  103147. -999, -999, -999, -999, -999, -999, -999, -999},
  103148. {-999, -999, -999, -999, -999, -999, -999, -999,
  103149. -999, -999, -108, -99, -90, -76, -66, -45,
  103150. -43, -41, -44, -47, -43, -47, -40, -30,
  103151. -31, -31, -39, -33, -40, -41, -43, -53,
  103152. -59, -70, -73, -77, -79, -82, -84, -87,
  103153. -999, -999, -999, -999, -999, -999, -999, -999,
  103154. -999, -999, -999, -999, -999, -999, -999, -999}},
  103155. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103156. -999, -999, -999, -999, -999, -110, -91, -76,
  103157. -75, -85, -93, -98, -104, -110, -999, -999,
  103158. -999, -999, -999, -999, -999, -999, -999, -999,
  103159. -999, -999, -999, -999, -999, -999, -999, -999,
  103160. -999, -999, -999, -999, -999, -999, -999, -999,
  103161. -999, -999, -999, -999, -999, -999, -999, -999},
  103162. {-999, -999, -999, -999, -999, -999, -999, -999,
  103163. -999, -999, -999, -999, -999, -110, -91, -70,
  103164. -70, -75, -86, -89, -94, -98, -101, -106,
  103165. -110, -999, -999, -999, -999, -999, -999, -999,
  103166. -999, -999, -999, -999, -999, -999, -999, -999,
  103167. -999, -999, -999, -999, -999, -999, -999, -999,
  103168. -999, -999, -999, -999, -999, -999, -999, -999},
  103169. {-999, -999, -999, -999, -999, -999, -999, -999,
  103170. -999, -999, -999, -999, -110, -95, -80, -60,
  103171. -65, -64, -74, -83, -88, -91, -95, -99,
  103172. -103, -107, -110, -999, -999, -999, -999, -999,
  103173. -999, -999, -999, -999, -999, -999, -999, -999,
  103174. -999, -999, -999, -999, -999, -999, -999, -999,
  103175. -999, -999, -999, -999, -999, -999, -999, -999},
  103176. {-999, -999, -999, -999, -999, -999, -999, -999,
  103177. -999, -999, -999, -999, -110, -95, -80, -58,
  103178. -55, -49, -66, -68, -71, -78, -78, -80,
  103179. -88, -85, -89, -97, -100, -105, -110, -999,
  103180. -999, -999, -999, -999, -999, -999, -999, -999,
  103181. -999, -999, -999, -999, -999, -999, -999, -999,
  103182. -999, -999, -999, -999, -999, -999, -999, -999},
  103183. {-999, -999, -999, -999, -999, -999, -999, -999,
  103184. -999, -999, -999, -999, -110, -95, -80, -53,
  103185. -52, -41, -59, -59, -49, -58, -56, -63,
  103186. -86, -79, -90, -93, -98, -103, -107, -112,
  103187. -999, -999, -999, -999, -999, -999, -999, -999,
  103188. -999, -999, -999, -999, -999, -999, -999, -999,
  103189. -999, -999, -999, -999, -999, -999, -999, -999},
  103190. {-999, -999, -999, -999, -999, -999, -999, -999,
  103191. -999, -999, -999, -110, -97, -91, -73, -45,
  103192. -40, -33, -53, -61, -49, -54, -50, -50,
  103193. -60, -52, -67, -74, -81, -92, -96, -100,
  103194. -105, -110, -999, -999, -999, -999, -999, -999,
  103195. -999, -999, -999, -999, -999, -999, -999, -999,
  103196. -999, -999, -999, -999, -999, -999, -999, -999}},
  103197. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103198. -999, -999, -999, -113, -106, -99, -92, -77,
  103199. -80, -88, -97, -106, -115, -999, -999, -999,
  103200. -999, -999, -999, -999, -999, -999, -999, -999,
  103201. -999, -999, -999, -999, -999, -999, -999, -999,
  103202. -999, -999, -999, -999, -999, -999, -999, -999,
  103203. -999, -999, -999, -999, -999, -999, -999, -999},
  103204. {-999, -999, -999, -999, -999, -999, -999, -999,
  103205. -999, -999, -116, -109, -102, -95, -89, -74,
  103206. -72, -88, -87, -95, -102, -109, -116, -999,
  103207. -999, -999, -999, -999, -999, -999, -999, -999,
  103208. -999, -999, -999, -999, -999, -999, -999, -999,
  103209. -999, -999, -999, -999, -999, -999, -999, -999,
  103210. -999, -999, -999, -999, -999, -999, -999, -999},
  103211. {-999, -999, -999, -999, -999, -999, -999, -999,
  103212. -999, -999, -116, -109, -102, -95, -89, -75,
  103213. -66, -74, -77, -78, -86, -87, -90, -96,
  103214. -105, -115, -999, -999, -999, -999, -999, -999,
  103215. -999, -999, -999, -999, -999, -999, -999, -999,
  103216. -999, -999, -999, -999, -999, -999, -999, -999,
  103217. -999, -999, -999, -999, -999, -999, -999, -999},
  103218. {-999, -999, -999, -999, -999, -999, -999, -999,
  103219. -999, -999, -115, -108, -101, -94, -88, -66,
  103220. -56, -61, -70, -65, -78, -72, -83, -84,
  103221. -93, -98, -105, -110, -999, -999, -999, -999,
  103222. -999, -999, -999, -999, -999, -999, -999, -999,
  103223. -999, -999, -999, -999, -999, -999, -999, -999,
  103224. -999, -999, -999, -999, -999, -999, -999, -999},
  103225. {-999, -999, -999, -999, -999, -999, -999, -999,
  103226. -999, -999, -110, -105, -95, -89, -82, -57,
  103227. -52, -52, -59, -56, -59, -58, -69, -67,
  103228. -88, -82, -82, -89, -94, -100, -108, -999,
  103229. -999, -999, -999, -999, -999, -999, -999, -999,
  103230. -999, -999, -999, -999, -999, -999, -999, -999,
  103231. -999, -999, -999, -999, -999, -999, -999, -999},
  103232. {-999, -999, -999, -999, -999, -999, -999, -999,
  103233. -999, -110, -101, -96, -90, -83, -77, -54,
  103234. -43, -38, -50, -48, -52, -48, -42, -42,
  103235. -51, -52, -53, -59, -65, -71, -78, -85,
  103236. -95, -999, -999, -999, -999, -999, -999, -999,
  103237. -999, -999, -999, -999, -999, -999, -999, -999,
  103238. -999, -999, -999, -999, -999, -999, -999, -999}},
  103239. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103240. -999, -999, -999, -999, -120, -105, -86, -68,
  103241. -78, -79, -90, -100, -110, -999, -999, -999,
  103242. -999, -999, -999, -999, -999, -999, -999, -999,
  103243. -999, -999, -999, -999, -999, -999, -999, -999,
  103244. -999, -999, -999, -999, -999, -999, -999, -999,
  103245. -999, -999, -999, -999, -999, -999, -999, -999},
  103246. {-999, -999, -999, -999, -999, -999, -999, -999,
  103247. -999, -999, -999, -999, -120, -105, -86, -66,
  103248. -73, -77, -88, -96, -105, -115, -999, -999,
  103249. -999, -999, -999, -999, -999, -999, -999, -999,
  103250. -999, -999, -999, -999, -999, -999, -999, -999,
  103251. -999, -999, -999, -999, -999, -999, -999, -999,
  103252. -999, -999, -999, -999, -999, -999, -999, -999},
  103253. {-999, -999, -999, -999, -999, -999, -999, -999,
  103254. -999, -999, -999, -120, -105, -92, -80, -61,
  103255. -64, -68, -80, -87, -92, -100, -110, -999,
  103256. -999, -999, -999, -999, -999, -999, -999, -999,
  103257. -999, -999, -999, -999, -999, -999, -999, -999,
  103258. -999, -999, -999, -999, -999, -999, -999, -999,
  103259. -999, -999, -999, -999, -999, -999, -999, -999},
  103260. {-999, -999, -999, -999, -999, -999, -999, -999,
  103261. -999, -999, -999, -120, -104, -91, -79, -52,
  103262. -60, -54, -64, -69, -77, -80, -82, -84,
  103263. -85, -87, -88, -90, -999, -999, -999, -999,
  103264. -999, -999, -999, -999, -999, -999, -999, -999,
  103265. -999, -999, -999, -999, -999, -999, -999, -999,
  103266. -999, -999, -999, -999, -999, -999, -999, -999},
  103267. {-999, -999, -999, -999, -999, -999, -999, -999,
  103268. -999, -999, -999, -118, -100, -87, -77, -49,
  103269. -50, -44, -58, -61, -61, -67, -65, -62,
  103270. -62, -62, -65, -68, -999, -999, -999, -999,
  103271. -999, -999, -999, -999, -999, -999, -999, -999,
  103272. -999, -999, -999, -999, -999, -999, -999, -999,
  103273. -999, -999, -999, -999, -999, -999, -999, -999},
  103274. {-999, -999, -999, -999, -999, -999, -999, -999,
  103275. -999, -999, -999, -115, -98, -84, -62, -49,
  103276. -44, -38, -46, -49, -49, -46, -39, -37,
  103277. -39, -40, -42, -43, -999, -999, -999, -999,
  103278. -999, -999, -999, -999, -999, -999, -999, -999,
  103279. -999, -999, -999, -999, -999, -999, -999, -999,
  103280. -999, -999, -999, -999, -999, -999, -999, -999}},
  103281. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103282. -999, -999, -999, -999, -999, -110, -88, -74,
  103283. -77, -82, -82, -85, -90, -94, -99, -104,
  103284. -999, -999, -999, -999, -999, -999, -999, -999,
  103285. -999, -999, -999, -999, -999, -999, -999, -999,
  103286. -999, -999, -999, -999, -999, -999, -999, -999,
  103287. -999, -999, -999, -999, -999, -999, -999, -999},
  103288. {-999, -999, -999, -999, -999, -999, -999, -999,
  103289. -999, -999, -999, -999, -999, -110, -88, -66,
  103290. -70, -81, -80, -81, -84, -88, -91, -93,
  103291. -999, -999, -999, -999, -999, -999, -999, -999,
  103292. -999, -999, -999, -999, -999, -999, -999, -999,
  103293. -999, -999, -999, -999, -999, -999, -999, -999,
  103294. -999, -999, -999, -999, -999, -999, -999, -999},
  103295. {-999, -999, -999, -999, -999, -999, -999, -999,
  103296. -999, -999, -999, -999, -999, -110, -88, -61,
  103297. -63, -70, -71, -74, -77, -80, -83, -85,
  103298. -999, -999, -999, -999, -999, -999, -999, -999,
  103299. -999, -999, -999, -999, -999, -999, -999, -999,
  103300. -999, -999, -999, -999, -999, -999, -999, -999,
  103301. -999, -999, -999, -999, -999, -999, -999, -999},
  103302. {-999, -999, -999, -999, -999, -999, -999, -999,
  103303. -999, -999, -999, -999, -999, -110, -86, -62,
  103304. -63, -62, -62, -58, -52, -50, -50, -52,
  103305. -54, -999, -999, -999, -999, -999, -999, -999,
  103306. -999, -999, -999, -999, -999, -999, -999, -999,
  103307. -999, -999, -999, -999, -999, -999, -999, -999,
  103308. -999, -999, -999, -999, -999, -999, -999, -999},
  103309. {-999, -999, -999, -999, -999, -999, -999, -999,
  103310. -999, -999, -999, -999, -118, -108, -84, -53,
  103311. -50, -50, -50, -55, -47, -45, -40, -40,
  103312. -40, -999, -999, -999, -999, -999, -999, -999,
  103313. -999, -999, -999, -999, -999, -999, -999, -999,
  103314. -999, -999, -999, -999, -999, -999, -999, -999,
  103315. -999, -999, -999, -999, -999, -999, -999, -999},
  103316. {-999, -999, -999, -999, -999, -999, -999, -999,
  103317. -999, -999, -999, -999, -118, -100, -73, -43,
  103318. -37, -42, -43, -53, -38, -37, -35, -35,
  103319. -38, -999, -999, -999, -999, -999, -999, -999,
  103320. -999, -999, -999, -999, -999, -999, -999, -999,
  103321. -999, -999, -999, -999, -999, -999, -999, -999,
  103322. -999, -999, -999, -999, -999, -999, -999, -999}},
  103323. {{-999, -999, -999, -999, -999, -999, -999, -999,
  103324. -999, -999, -999, -110, -100, -91, -84, -74,
  103325. -80, -80, -80, -80, -80, -999, -999, -999,
  103326. -999, -999, -999, -999, -999, -999, -999, -999,
  103327. -999, -999, -999, -999, -999, -999, -999, -999,
  103328. -999, -999, -999, -999, -999, -999, -999, -999,
  103329. -999, -999, -999, -999, -999, -999, -999, -999},
  103330. {-999, -999, -999, -999, -999, -999, -999, -999,
  103331. -999, -999, -999, -110, -100, -91, -84, -74,
  103332. -68, -68, -68, -68, -68, -999, -999, -999,
  103333. -999, -999, -999, -999, -999, -999, -999, -999,
  103334. -999, -999, -999, -999, -999, -999, -999, -999,
  103335. -999, -999, -999, -999, -999, -999, -999, -999,
  103336. -999, -999, -999, -999, -999, -999, -999, -999},
  103337. {-999, -999, -999, -999, -999, -999, -999, -999,
  103338. -999, -999, -999, -110, -100, -86, -78, -70,
  103339. -60, -45, -30, -21, -999, -999, -999, -999,
  103340. -999, -999, -999, -999, -999, -999, -999, -999,
  103341. -999, -999, -999, -999, -999, -999, -999, -999,
  103342. -999, -999, -999, -999, -999, -999, -999, -999,
  103343. -999, -999, -999, -999, -999, -999, -999, -999},
  103344. {-999, -999, -999, -999, -999, -999, -999, -999,
  103345. -999, -999, -999, -110, -100, -87, -78, -67,
  103346. -48, -38, -29, -21, -999, -999, -999, -999,
  103347. -999, -999, -999, -999, -999, -999, -999, -999,
  103348. -999, -999, -999, -999, -999, -999, -999, -999,
  103349. -999, -999, -999, -999, -999, -999, -999, -999,
  103350. -999, -999, -999, -999, -999, -999, -999, -999},
  103351. {-999, -999, -999, -999, -999, -999, -999, -999,
  103352. -999, -999, -999, -110, -100, -86, -69, -56,
  103353. -45, -35, -33, -29, -999, -999, -999, -999,
  103354. -999, -999, -999, -999, -999, -999, -999, -999,
  103355. -999, -999, -999, -999, -999, -999, -999, -999,
  103356. -999, -999, -999, -999, -999, -999, -999, -999,
  103357. -999, -999, -999, -999, -999, -999, -999, -999},
  103358. {-999, -999, -999, -999, -999, -999, -999, -999,
  103359. -999, -999, -999, -110, -100, -83, -71, -48,
  103360. -27, -38, -37, -34, -999, -999, -999, -999,
  103361. -999, -999, -999, -999, -999, -999, -999, -999,
  103362. -999, -999, -999, -999, -999, -999, -999, -999,
  103363. -999, -999, -999, -999, -999, -999, -999, -999,
  103364. -999, -999, -999, -999, -999, -999, -999, -999}}
  103365. };
  103366. #endif
  103367. /*** End of inlined file: masking.h ***/
  103368. #define NEGINF -9999.f
  103369. static double stereo_threshholds[]={0.0, .5, 1.0, 1.5, 2.5, 4.5, 8.5, 16.5, 9e10};
  103370. static double stereo_threshholds_limited[]={0.0, .5, 1.0, 1.5, 2.0, 2.5, 4.5, 8.5, 9e10};
  103371. vorbis_look_psy_global *_vp_global_look(vorbis_info *vi){
  103372. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  103373. vorbis_info_psy_global *gi=&ci->psy_g_param;
  103374. vorbis_look_psy_global *look=(vorbis_look_psy_global*)_ogg_calloc(1,sizeof(*look));
  103375. look->channels=vi->channels;
  103376. look->ampmax=-9999.;
  103377. look->gi=gi;
  103378. return(look);
  103379. }
  103380. void _vp_global_free(vorbis_look_psy_global *look){
  103381. if(look){
  103382. memset(look,0,sizeof(*look));
  103383. _ogg_free(look);
  103384. }
  103385. }
  103386. void _vi_gpsy_free(vorbis_info_psy_global *i){
  103387. if(i){
  103388. memset(i,0,sizeof(*i));
  103389. _ogg_free(i);
  103390. }
  103391. }
  103392. void _vi_psy_free(vorbis_info_psy *i){
  103393. if(i){
  103394. memset(i,0,sizeof(*i));
  103395. _ogg_free(i);
  103396. }
  103397. }
  103398. static void min_curve(float *c,
  103399. float *c2){
  103400. int i;
  103401. for(i=0;i<EHMER_MAX;i++)if(c2[i]<c[i])c[i]=c2[i];
  103402. }
  103403. static void max_curve(float *c,
  103404. float *c2){
  103405. int i;
  103406. for(i=0;i<EHMER_MAX;i++)if(c2[i]>c[i])c[i]=c2[i];
  103407. }
  103408. static void attenuate_curve(float *c,float att){
  103409. int i;
  103410. for(i=0;i<EHMER_MAX;i++)
  103411. c[i]+=att;
  103412. }
  103413. static float ***setup_tone_curves(float curveatt_dB[P_BANDS],float binHz,int n,
  103414. float center_boost, float center_decay_rate){
  103415. int i,j,k,m;
  103416. float ath[EHMER_MAX];
  103417. float workc[P_BANDS][P_LEVELS][EHMER_MAX];
  103418. float athc[P_LEVELS][EHMER_MAX];
  103419. float *brute_buffer=(float*) alloca(n*sizeof(*brute_buffer));
  103420. float ***ret=(float***) _ogg_malloc(sizeof(*ret)*P_BANDS);
  103421. memset(workc,0,sizeof(workc));
  103422. for(i=0;i<P_BANDS;i++){
  103423. int ath_offset=i*4;
  103424. for(j=0;j<EHMER_MAX;j++){
  103425. float min=999.;
  103426. for(k=0;k<4;k++)
  103427. if(j+k+ath_offset<MAX_ATH){
  103428. if(min>ATH[j+k+ath_offset])min=ATH[j+k+ath_offset];
  103429. }else{
  103430. if(min>ATH[MAX_ATH-1])min=ATH[MAX_ATH-1];
  103431. }
  103432. ath[j]=min;
  103433. }
  103434. for(j=0;j<6;j++)
  103435. memcpy(workc[i][j+2],tonemasks[i][j],EHMER_MAX*sizeof(*tonemasks[i][j]));
  103436. memcpy(workc[i][0],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103437. memcpy(workc[i][1],tonemasks[i][0],EHMER_MAX*sizeof(*tonemasks[i][0]));
  103438. for(j=0;j<P_LEVELS;j++){
  103439. for(k=0;k<EHMER_MAX;k++){
  103440. float adj=center_boost+abs(EHMER_OFFSET-k)*center_decay_rate;
  103441. if(adj<0. && center_boost>0)adj=0.;
  103442. if(adj>0. && center_boost<0)adj=0.;
  103443. workc[i][j][k]+=adj;
  103444. }
  103445. }
  103446. for(j=0;j<P_LEVELS;j++){
  103447. attenuate_curve(workc[i][j],curveatt_dB[i]+100.-(j<2?2:j)*10.-P_LEVEL_0);
  103448. memcpy(athc[j],ath,EHMER_MAX*sizeof(**athc));
  103449. attenuate_curve(athc[j],+100.-j*10.f-P_LEVEL_0);
  103450. max_curve(athc[j],workc[i][j]);
  103451. }
  103452. for(j=1;j<P_LEVELS;j++){
  103453. min_curve(athc[j],athc[j-1]);
  103454. min_curve(workc[i][j],athc[j]);
  103455. }
  103456. }
  103457. for(i=0;i<P_BANDS;i++){
  103458. int hi_curve,lo_curve,bin;
  103459. ret[i]=(float**)_ogg_malloc(sizeof(**ret)*P_LEVELS);
  103460. bin=floor(fromOC(i*.5)/binHz);
  103461. lo_curve= ceil(toOC(bin*binHz+1)*2);
  103462. hi_curve= floor(toOC((bin+1)*binHz)*2);
  103463. if(lo_curve>i)lo_curve=i;
  103464. if(lo_curve<0)lo_curve=0;
  103465. if(hi_curve>=P_BANDS)hi_curve=P_BANDS-1;
  103466. for(m=0;m<P_LEVELS;m++){
  103467. ret[i][m]=(float*)_ogg_malloc(sizeof(***ret)*(EHMER_MAX+2));
  103468. for(j=0;j<n;j++)brute_buffer[j]=999.;
  103469. for(k=lo_curve;k<=hi_curve;k++){
  103470. int l=0;
  103471. for(j=0;j<EHMER_MAX;j++){
  103472. int lo_bin= fromOC(j*.125+k*.5-2.0625)/binHz;
  103473. int hi_bin= fromOC(j*.125+k*.5-1.9375)/binHz+1;
  103474. if(lo_bin<0)lo_bin=0;
  103475. if(lo_bin>n)lo_bin=n;
  103476. if(lo_bin<l)l=lo_bin;
  103477. if(hi_bin<0)hi_bin=0;
  103478. if(hi_bin>n)hi_bin=n;
  103479. for(;l<hi_bin && l<n;l++)
  103480. if(brute_buffer[l]>workc[k][m][j])
  103481. brute_buffer[l]=workc[k][m][j];
  103482. }
  103483. for(;l<n;l++)
  103484. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103485. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103486. }
  103487. if(i+1<P_BANDS){
  103488. int l=0;
  103489. k=i+1;
  103490. for(j=0;j<EHMER_MAX;j++){
  103491. int lo_bin= fromOC(j*.125+i*.5-2.0625)/binHz;
  103492. int hi_bin= fromOC(j*.125+i*.5-1.9375)/binHz+1;
  103493. if(lo_bin<0)lo_bin=0;
  103494. if(lo_bin>n)lo_bin=n;
  103495. if(lo_bin<l)l=lo_bin;
  103496. if(hi_bin<0)hi_bin=0;
  103497. if(hi_bin>n)hi_bin=n;
  103498. for(;l<hi_bin && l<n;l++)
  103499. if(brute_buffer[l]>workc[k][m][j])
  103500. brute_buffer[l]=workc[k][m][j];
  103501. }
  103502. for(;l<n;l++)
  103503. if(brute_buffer[l]>workc[k][m][EHMER_MAX-1])
  103504. brute_buffer[l]=workc[k][m][EHMER_MAX-1];
  103505. }
  103506. for(j=0;j<EHMER_MAX;j++){
  103507. int bin=fromOC(j*.125+i*.5-2.)/binHz;
  103508. if(bin<0){
  103509. ret[i][m][j+2]=-999.;
  103510. }else{
  103511. if(bin>=n){
  103512. ret[i][m][j+2]=-999.;
  103513. }else{
  103514. ret[i][m][j+2]=brute_buffer[bin];
  103515. }
  103516. }
  103517. }
  103518. for(j=0;j<EHMER_OFFSET;j++)
  103519. if(ret[i][m][j+2]>-200.f)break;
  103520. ret[i][m][0]=j;
  103521. for(j=EHMER_MAX-1;j>EHMER_OFFSET+1;j--)
  103522. if(ret[i][m][j+2]>-200.f)
  103523. break;
  103524. ret[i][m][1]=j;
  103525. }
  103526. }
  103527. return(ret);
  103528. }
  103529. void _vp_psy_init(vorbis_look_psy *p,vorbis_info_psy *vi,
  103530. vorbis_info_psy_global *gi,int n,long rate){
  103531. long i,j,lo=-99,hi=1;
  103532. long maxoc;
  103533. memset(p,0,sizeof(*p));
  103534. p->eighth_octave_lines=gi->eighth_octave_lines;
  103535. p->shiftoc=rint(log(gi->eighth_octave_lines*8.f)/log(2.f))-1;
  103536. p->firstoc=toOC(.25f*rate*.5/n)*(1<<(p->shiftoc+1))-gi->eighth_octave_lines;
  103537. maxoc=toOC((n+.25f)*rate*.5/n)*(1<<(p->shiftoc+1))+.5f;
  103538. p->total_octave_lines=maxoc-p->firstoc+1;
  103539. p->ath=(float*)_ogg_malloc(n*sizeof(*p->ath));
  103540. p->octave=(long*)_ogg_malloc(n*sizeof(*p->octave));
  103541. p->bark=(long*)_ogg_malloc(n*sizeof(*p->bark));
  103542. p->vi=vi;
  103543. p->n=n;
  103544. p->rate=rate;
  103545. p->m_val = 1.;
  103546. if(rate < 26000) p->m_val = 0;
  103547. else if(rate < 38000) p->m_val = .94; /* 32kHz */
  103548. else if(rate > 46000) p->m_val = 1.275; /* 48kHz */
  103549. for(i=0,j=0;i<MAX_ATH-1;i++){
  103550. int endpos=rint(fromOC((i+1)*.125-2.)*2*n/rate);
  103551. float base=ATH[i];
  103552. if(j<endpos){
  103553. float delta=(ATH[i+1]-base)/(endpos-j);
  103554. for(;j<endpos && j<n;j++){
  103555. p->ath[j]=base+100.;
  103556. base+=delta;
  103557. }
  103558. }
  103559. }
  103560. for(i=0;i<n;i++){
  103561. float bark=toBARK(rate/(2*n)*i);
  103562. for(;lo+vi->noisewindowlomin<i &&
  103563. toBARK(rate/(2*n)*lo)<(bark-vi->noisewindowlo);lo++);
  103564. for(;hi<=n && (hi<i+vi->noisewindowhimin ||
  103565. toBARK(rate/(2*n)*hi)<(bark+vi->noisewindowhi));hi++);
  103566. p->bark[i]=((lo-1)<<16)+(hi-1);
  103567. }
  103568. for(i=0;i<n;i++)
  103569. p->octave[i]=toOC((i+.25f)*.5*rate/n)*(1<<(p->shiftoc+1))+.5f;
  103570. p->tonecurves=setup_tone_curves(vi->toneatt,rate*.5/n,n,
  103571. vi->tone_centerboost,vi->tone_decay);
  103572. p->noiseoffset=(float**)_ogg_malloc(P_NOISECURVES*sizeof(*p->noiseoffset));
  103573. for(i=0;i<P_NOISECURVES;i++)
  103574. p->noiseoffset[i]=(float*)_ogg_malloc(n*sizeof(**p->noiseoffset));
  103575. for(i=0;i<n;i++){
  103576. float halfoc=toOC((i+.5)*rate/(2.*n))*2.;
  103577. int inthalfoc;
  103578. float del;
  103579. if(halfoc<0)halfoc=0;
  103580. if(halfoc>=P_BANDS-1)halfoc=P_BANDS-1;
  103581. inthalfoc=(int)halfoc;
  103582. del=halfoc-inthalfoc;
  103583. for(j=0;j<P_NOISECURVES;j++)
  103584. p->noiseoffset[j][i]=
  103585. p->vi->noiseoff[j][inthalfoc]*(1.-del) +
  103586. p->vi->noiseoff[j][inthalfoc+1]*del;
  103587. }
  103588. #if 0
  103589. {
  103590. static int ls=0;
  103591. _analysis_output_always("noiseoff0",ls,p->noiseoffset[0],n,1,0,0);
  103592. _analysis_output_always("noiseoff1",ls,p->noiseoffset[1],n,1,0,0);
  103593. _analysis_output_always("noiseoff2",ls++,p->noiseoffset[2],n,1,0,0);
  103594. }
  103595. #endif
  103596. }
  103597. void _vp_psy_clear(vorbis_look_psy *p){
  103598. int i,j;
  103599. if(p){
  103600. if(p->ath)_ogg_free(p->ath);
  103601. if(p->octave)_ogg_free(p->octave);
  103602. if(p->bark)_ogg_free(p->bark);
  103603. if(p->tonecurves){
  103604. for(i=0;i<P_BANDS;i++){
  103605. for(j=0;j<P_LEVELS;j++){
  103606. _ogg_free(p->tonecurves[i][j]);
  103607. }
  103608. _ogg_free(p->tonecurves[i]);
  103609. }
  103610. _ogg_free(p->tonecurves);
  103611. }
  103612. if(p->noiseoffset){
  103613. for(i=0;i<P_NOISECURVES;i++){
  103614. _ogg_free(p->noiseoffset[i]);
  103615. }
  103616. _ogg_free(p->noiseoffset);
  103617. }
  103618. memset(p,0,sizeof(*p));
  103619. }
  103620. }
  103621. static void seed_curve(float *seed,
  103622. const float **curves,
  103623. float amp,
  103624. int oc, int n,
  103625. int linesper,float dBoffset){
  103626. int i,post1;
  103627. int seedptr;
  103628. const float *posts,*curve;
  103629. int choice=(int)((amp+dBoffset-P_LEVEL_0)*.1f);
  103630. choice=max(choice,0);
  103631. choice=min(choice,P_LEVELS-1);
  103632. posts=curves[choice];
  103633. curve=posts+2;
  103634. post1=(int)posts[1];
  103635. seedptr=oc+(posts[0]-EHMER_OFFSET)*linesper-(linesper>>1);
  103636. for(i=posts[0];i<post1;i++){
  103637. if(seedptr>0){
  103638. float lin=amp+curve[i];
  103639. if(seed[seedptr]<lin)seed[seedptr]=lin;
  103640. }
  103641. seedptr+=linesper;
  103642. if(seedptr>=n)break;
  103643. }
  103644. }
  103645. static void seed_loop(vorbis_look_psy *p,
  103646. const float ***curves,
  103647. const float *f,
  103648. const float *flr,
  103649. float *seed,
  103650. float specmax){
  103651. vorbis_info_psy *vi=p->vi;
  103652. long n=p->n,i;
  103653. float dBoffset=vi->max_curve_dB-specmax;
  103654. for(i=0;i<n;i++){
  103655. float max=f[i];
  103656. long oc=p->octave[i];
  103657. while(i+1<n && p->octave[i+1]==oc){
  103658. i++;
  103659. if(f[i]>max)max=f[i];
  103660. }
  103661. if(max+6.f>flr[i]){
  103662. oc=oc>>p->shiftoc;
  103663. if(oc>=P_BANDS)oc=P_BANDS-1;
  103664. if(oc<0)oc=0;
  103665. seed_curve(seed,
  103666. curves[oc],
  103667. max,
  103668. p->octave[i]-p->firstoc,
  103669. p->total_octave_lines,
  103670. p->eighth_octave_lines,
  103671. dBoffset);
  103672. }
  103673. }
  103674. }
  103675. static void seed_chase(float *seeds, int linesper, long n){
  103676. long *posstack=(long*)alloca(n*sizeof(*posstack));
  103677. float *ampstack=(float*)alloca(n*sizeof(*ampstack));
  103678. long stack=0;
  103679. long pos=0;
  103680. long i;
  103681. for(i=0;i<n;i++){
  103682. if(stack<2){
  103683. posstack[stack]=i;
  103684. ampstack[stack++]=seeds[i];
  103685. }else{
  103686. while(1){
  103687. if(seeds[i]<ampstack[stack-1]){
  103688. posstack[stack]=i;
  103689. ampstack[stack++]=seeds[i];
  103690. break;
  103691. }else{
  103692. if(i<posstack[stack-1]+linesper){
  103693. if(stack>1 && ampstack[stack-1]<=ampstack[stack-2] &&
  103694. i<posstack[stack-2]+linesper){
  103695. stack--;
  103696. continue;
  103697. }
  103698. }
  103699. posstack[stack]=i;
  103700. ampstack[stack++]=seeds[i];
  103701. break;
  103702. }
  103703. }
  103704. }
  103705. }
  103706. for(i=0;i<stack;i++){
  103707. long endpos;
  103708. if(i<stack-1 && ampstack[i+1]>ampstack[i]){
  103709. endpos=posstack[i+1];
  103710. }else{
  103711. endpos=posstack[i]+linesper+1; /* +1 is important, else bin 0 is
  103712. discarded in short frames */
  103713. }
  103714. if(endpos>n)endpos=n;
  103715. for(;pos<endpos;pos++)
  103716. seeds[pos]=ampstack[i];
  103717. }
  103718. }
  103719. #include<stdio.h>
  103720. static void max_seeds(vorbis_look_psy *p,
  103721. float *seed,
  103722. float *flr){
  103723. long n=p->total_octave_lines;
  103724. int linesper=p->eighth_octave_lines;
  103725. long linpos=0;
  103726. long pos;
  103727. seed_chase(seed,linesper,n); /* for masking */
  103728. pos=p->octave[0]-p->firstoc-(linesper>>1);
  103729. while(linpos+1<p->n){
  103730. float minV=seed[pos];
  103731. long end=((p->octave[linpos]+p->octave[linpos+1])>>1)-p->firstoc;
  103732. if(minV>p->vi->tone_abs_limit)minV=p->vi->tone_abs_limit;
  103733. while(pos+1<=end){
  103734. pos++;
  103735. if((seed[pos]>NEGINF && seed[pos]<minV) || minV==NEGINF)
  103736. minV=seed[pos];
  103737. }
  103738. end=pos+p->firstoc;
  103739. for(;linpos<p->n && p->octave[linpos]<=end;linpos++)
  103740. if(flr[linpos]<minV)flr[linpos]=minV;
  103741. }
  103742. {
  103743. float minV=seed[p->total_octave_lines-1];
  103744. for(;linpos<p->n;linpos++)
  103745. if(flr[linpos]<minV)flr[linpos]=minV;
  103746. }
  103747. }
  103748. static void bark_noise_hybridmp(int n,const long *b,
  103749. const float *f,
  103750. float *noise,
  103751. const float offset,
  103752. const int fixed){
  103753. float *N=(float*) alloca(n*sizeof(*N));
  103754. float *X=(float*) alloca(n*sizeof(*N));
  103755. float *XX=(float*) alloca(n*sizeof(*N));
  103756. float *Y=(float*) alloca(n*sizeof(*N));
  103757. float *XY=(float*) alloca(n*sizeof(*N));
  103758. float tN, tX, tXX, tY, tXY;
  103759. int i;
  103760. int lo, hi;
  103761. float R, A, B, D;
  103762. float w, x, y;
  103763. tN = tX = tXX = tY = tXY = 0.f;
  103764. y = f[0] + offset;
  103765. if (y < 1.f) y = 1.f;
  103766. w = y * y * .5;
  103767. tN += w;
  103768. tX += w;
  103769. tY += w * y;
  103770. N[0] = tN;
  103771. X[0] = tX;
  103772. XX[0] = tXX;
  103773. Y[0] = tY;
  103774. XY[0] = tXY;
  103775. for (i = 1, x = 1.f; i < n; i++, x += 1.f) {
  103776. y = f[i] + offset;
  103777. if (y < 1.f) y = 1.f;
  103778. w = y * y;
  103779. tN += w;
  103780. tX += w * x;
  103781. tXX += w * x * x;
  103782. tY += w * y;
  103783. tXY += w * x * y;
  103784. N[i] = tN;
  103785. X[i] = tX;
  103786. XX[i] = tXX;
  103787. Y[i] = tY;
  103788. XY[i] = tXY;
  103789. }
  103790. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103791. lo = b[i] >> 16;
  103792. if( lo>=0 ) break;
  103793. hi = b[i] & 0xffff;
  103794. tN = N[hi] + N[-lo];
  103795. tX = X[hi] - X[-lo];
  103796. tXX = XX[hi] + XX[-lo];
  103797. tY = Y[hi] + Y[-lo];
  103798. tXY = XY[hi] - XY[-lo];
  103799. A = tY * tXX - tX * tXY;
  103800. B = tN * tXY - tX * tY;
  103801. D = tN * tXX - tX * tX;
  103802. R = (A + x * B) / D;
  103803. if (R < 0.f)
  103804. R = 0.f;
  103805. noise[i] = R - offset;
  103806. }
  103807. for ( ;; i++, x += 1.f) {
  103808. lo = b[i] >> 16;
  103809. hi = b[i] & 0xffff;
  103810. if(hi>=n)break;
  103811. tN = N[hi] - N[lo];
  103812. tX = X[hi] - X[lo];
  103813. tXX = XX[hi] - XX[lo];
  103814. tY = Y[hi] - Y[lo];
  103815. tXY = XY[hi] - XY[lo];
  103816. A = tY * tXX - tX * tXY;
  103817. B = tN * tXY - tX * tY;
  103818. D = tN * tXX - tX * tX;
  103819. R = (A + x * B) / D;
  103820. if (R < 0.f) R = 0.f;
  103821. noise[i] = R - offset;
  103822. }
  103823. for ( ; i < n; i++, x += 1.f) {
  103824. R = (A + x * B) / D;
  103825. if (R < 0.f) R = 0.f;
  103826. noise[i] = R - offset;
  103827. }
  103828. if (fixed <= 0) return;
  103829. for (i = 0, x = 0.f;; i++, x += 1.f) {
  103830. hi = i + fixed / 2;
  103831. lo = hi - fixed;
  103832. if(lo>=0)break;
  103833. tN = N[hi] + N[-lo];
  103834. tX = X[hi] - X[-lo];
  103835. tXX = XX[hi] + XX[-lo];
  103836. tY = Y[hi] + Y[-lo];
  103837. tXY = XY[hi] - XY[-lo];
  103838. A = tY * tXX - tX * tXY;
  103839. B = tN * tXY - tX * tY;
  103840. D = tN * tXX - tX * tX;
  103841. R = (A + x * B) / D;
  103842. if (R - offset < noise[i]) noise[i] = R - offset;
  103843. }
  103844. for ( ;; i++, x += 1.f) {
  103845. hi = i + fixed / 2;
  103846. lo = hi - fixed;
  103847. if(hi>=n)break;
  103848. tN = N[hi] - N[lo];
  103849. tX = X[hi] - X[lo];
  103850. tXX = XX[hi] - XX[lo];
  103851. tY = Y[hi] - Y[lo];
  103852. tXY = XY[hi] - XY[lo];
  103853. A = tY * tXX - tX * tXY;
  103854. B = tN * tXY - tX * tY;
  103855. D = tN * tXX - tX * tX;
  103856. R = (A + x * B) / D;
  103857. if (R - offset < noise[i]) noise[i] = R - offset;
  103858. }
  103859. for ( ; i < n; i++, x += 1.f) {
  103860. R = (A + x * B) / D;
  103861. if (R - offset < noise[i]) noise[i] = R - offset;
  103862. }
  103863. }
  103864. static float FLOOR1_fromdB_INV_LOOKUP[256]={
  103865. 0.F, 8.81683e+06F, 8.27882e+06F, 7.77365e+06F,
  103866. 7.29930e+06F, 6.85389e+06F, 6.43567e+06F, 6.04296e+06F,
  103867. 5.67422e+06F, 5.32798e+06F, 5.00286e+06F, 4.69759e+06F,
  103868. 4.41094e+06F, 4.14178e+06F, 3.88905e+06F, 3.65174e+06F,
  103869. 3.42891e+06F, 3.21968e+06F, 3.02321e+06F, 2.83873e+06F,
  103870. 2.66551e+06F, 2.50286e+06F, 2.35014e+06F, 2.20673e+06F,
  103871. 2.07208e+06F, 1.94564e+06F, 1.82692e+06F, 1.71544e+06F,
  103872. 1.61076e+06F, 1.51247e+06F, 1.42018e+06F, 1.33352e+06F,
  103873. 1.25215e+06F, 1.17574e+06F, 1.10400e+06F, 1.03663e+06F,
  103874. 973377.F, 913981.F, 858210.F, 805842.F,
  103875. 756669.F, 710497.F, 667142.F, 626433.F,
  103876. 588208.F, 552316.F, 518613.F, 486967.F,
  103877. 457252.F, 429351.F, 403152.F, 378551.F,
  103878. 355452.F, 333762.F, 313396.F, 294273.F,
  103879. 276316.F, 259455.F, 243623.F, 228757.F,
  103880. 214798.F, 201691.F, 189384.F, 177828.F,
  103881. 166977.F, 156788.F, 147221.F, 138237.F,
  103882. 129802.F, 121881.F, 114444.F, 107461.F,
  103883. 100903.F, 94746.3F, 88964.9F, 83536.2F,
  103884. 78438.8F, 73652.5F, 69158.2F, 64938.1F,
  103885. 60975.6F, 57254.9F, 53761.2F, 50480.6F,
  103886. 47400.3F, 44507.9F, 41792.0F, 39241.9F,
  103887. 36847.3F, 34598.9F, 32487.7F, 30505.3F,
  103888. 28643.8F, 26896.0F, 25254.8F, 23713.7F,
  103889. 22266.7F, 20908.0F, 19632.2F, 18434.2F,
  103890. 17309.4F, 16253.1F, 15261.4F, 14330.1F,
  103891. 13455.7F, 12634.6F, 11863.7F, 11139.7F,
  103892. 10460.0F, 9821.72F, 9222.39F, 8659.64F,
  103893. 8131.23F, 7635.06F, 7169.17F, 6731.70F,
  103894. 6320.93F, 5935.23F, 5573.06F, 5232.99F,
  103895. 4913.67F, 4613.84F, 4332.30F, 4067.94F,
  103896. 3819.72F, 3586.64F, 3367.78F, 3162.28F,
  103897. 2969.31F, 2788.13F, 2617.99F, 2458.24F,
  103898. 2308.24F, 2167.39F, 2035.14F, 1910.95F,
  103899. 1794.35F, 1684.85F, 1582.04F, 1485.51F,
  103900. 1394.86F, 1309.75F, 1229.83F, 1154.78F,
  103901. 1084.32F, 1018.15F, 956.024F, 897.687F,
  103902. 842.910F, 791.475F, 743.179F, 697.830F,
  103903. 655.249F, 615.265F, 577.722F, 542.469F,
  103904. 509.367F, 478.286F, 449.101F, 421.696F,
  103905. 395.964F, 371.803F, 349.115F, 327.812F,
  103906. 307.809F, 289.026F, 271.390F, 254.830F,
  103907. 239.280F, 224.679F, 210.969F, 198.096F,
  103908. 186.008F, 174.658F, 164.000F, 153.993F,
  103909. 144.596F, 135.773F, 127.488F, 119.708F,
  103910. 112.404F, 105.545F, 99.1046F, 93.0572F,
  103911. 87.3788F, 82.0469F, 77.0404F, 72.3394F,
  103912. 67.9252F, 63.7804F, 59.8885F, 56.2341F,
  103913. 52.8027F, 49.5807F, 46.5553F, 43.7144F,
  103914. 41.0470F, 38.5423F, 36.1904F, 33.9821F,
  103915. 31.9085F, 29.9614F, 28.1332F, 26.4165F,
  103916. 24.8045F, 23.2910F, 21.8697F, 20.5352F,
  103917. 19.2822F, 18.1056F, 17.0008F, 15.9634F,
  103918. 14.9893F, 14.0746F, 13.2158F, 12.4094F,
  103919. 11.6522F, 10.9411F, 10.2735F, 9.64662F,
  103920. 9.05798F, 8.50526F, 7.98626F, 7.49894F,
  103921. 7.04135F, 6.61169F, 6.20824F, 5.82941F,
  103922. 5.47370F, 5.13970F, 4.82607F, 4.53158F,
  103923. 4.25507F, 3.99542F, 3.75162F, 3.52269F,
  103924. 3.30774F, 3.10590F, 2.91638F, 2.73842F,
  103925. 2.57132F, 2.41442F, 2.26709F, 2.12875F,
  103926. 1.99885F, 1.87688F, 1.76236F, 1.65482F,
  103927. 1.55384F, 1.45902F, 1.36999F, 1.28640F,
  103928. 1.20790F, 1.13419F, 1.06499F, 1.F
  103929. };
  103930. void _vp_remove_floor(vorbis_look_psy *p,
  103931. float *mdct,
  103932. int *codedflr,
  103933. float *residue,
  103934. int sliding_lowpass){
  103935. int i,n=p->n;
  103936. if(sliding_lowpass>n)sliding_lowpass=n;
  103937. for(i=0;i<sliding_lowpass;i++){
  103938. residue[i]=
  103939. mdct[i]*FLOOR1_fromdB_INV_LOOKUP[codedflr[i]];
  103940. }
  103941. for(;i<n;i++)
  103942. residue[i]=0.;
  103943. }
  103944. void _vp_noisemask(vorbis_look_psy *p,
  103945. float *logmdct,
  103946. float *logmask){
  103947. int i,n=p->n;
  103948. float *work=(float*) alloca(n*sizeof(*work));
  103949. bark_noise_hybridmp(n,p->bark,logmdct,logmask,
  103950. 140.,-1);
  103951. for(i=0;i<n;i++)work[i]=logmdct[i]-logmask[i];
  103952. bark_noise_hybridmp(n,p->bark,work,logmask,0.,
  103953. p->vi->noisewindowfixed);
  103954. for(i=0;i<n;i++)work[i]=logmdct[i]-work[i];
  103955. #if 0
  103956. {
  103957. static int seq=0;
  103958. float work2[n];
  103959. for(i=0;i<n;i++){
  103960. work2[i]=logmask[i]+work[i];
  103961. }
  103962. if(seq&1)
  103963. _analysis_output("median2R",seq/2,work,n,1,0,0);
  103964. else
  103965. _analysis_output("median2L",seq/2,work,n,1,0,0);
  103966. if(seq&1)
  103967. _analysis_output("envelope2R",seq/2,work2,n,1,0,0);
  103968. else
  103969. _analysis_output("envelope2L",seq/2,work2,n,1,0,0);
  103970. seq++;
  103971. }
  103972. #endif
  103973. for(i=0;i<n;i++){
  103974. int dB=logmask[i]+.5;
  103975. if(dB>=NOISE_COMPAND_LEVELS)dB=NOISE_COMPAND_LEVELS-1;
  103976. if(dB<0)dB=0;
  103977. logmask[i]= work[i]+p->vi->noisecompand[dB];
  103978. }
  103979. }
  103980. void _vp_tonemask(vorbis_look_psy *p,
  103981. float *logfft,
  103982. float *logmask,
  103983. float global_specmax,
  103984. float local_specmax){
  103985. int i,n=p->n;
  103986. float *seed=(float*) alloca(sizeof(*seed)*p->total_octave_lines);
  103987. float att=local_specmax+p->vi->ath_adjatt;
  103988. for(i=0;i<p->total_octave_lines;i++)seed[i]=NEGINF;
  103989. if(att<p->vi->ath_maxatt)att=p->vi->ath_maxatt;
  103990. for(i=0;i<n;i++)
  103991. logmask[i]=p->ath[i]+att;
  103992. seed_loop(p,(const float ***)p->tonecurves,logfft,logmask,seed,global_specmax);
  103993. max_seeds(p,seed,logmask);
  103994. }
  103995. void _vp_offset_and_mix(vorbis_look_psy *p,
  103996. float *noise,
  103997. float *tone,
  103998. int offset_select,
  103999. float *logmask,
  104000. float *mdct,
  104001. float *logmdct){
  104002. int i,n=p->n;
  104003. float de, coeffi, cx;/* AoTuV */
  104004. float toneatt=p->vi->tone_masteratt[offset_select];
  104005. cx = p->m_val;
  104006. for(i=0;i<n;i++){
  104007. float val= noise[i]+p->noiseoffset[offset_select][i];
  104008. if(val>p->vi->noisemaxsupp)val=p->vi->noisemaxsupp;
  104009. logmask[i]=max(val,tone[i]+toneatt);
  104010. if(offset_select == 1) {
  104011. coeffi = -17.2; /* coeffi is a -17.2dB threshold */
  104012. val = val - logmdct[i]; /* val == mdct line value relative to floor in dB */
  104013. if(val > coeffi){
  104014. de = 1.0-((val-coeffi)*0.005*cx);
  104015. if(de < 0) de = 0.0001;
  104016. }else
  104017. de = 1.0-((val-coeffi)*0.0003*cx);
  104018. mdct[i] *= de;
  104019. }
  104020. }
  104021. }
  104022. float _vp_ampmax_decay(float amp,vorbis_dsp_state *vd){
  104023. vorbis_info *vi=vd->vi;
  104024. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  104025. vorbis_info_psy_global *gi=&ci->psy_g_param;
  104026. int n=ci->blocksizes[vd->W]/2;
  104027. float secs=(float)n/vi->rate;
  104028. amp+=secs*gi->ampmax_att_per_sec;
  104029. if(amp<-9999)amp=-9999;
  104030. return(amp);
  104031. }
  104032. static void couple_lossless(float A, float B,
  104033. float *qA, float *qB){
  104034. int test1=fabs(*qA)>fabs(*qB);
  104035. test1-= fabs(*qA)<fabs(*qB);
  104036. if(!test1)test1=((fabs(A)>fabs(B))<<1)-1;
  104037. if(test1==1){
  104038. *qB=(*qA>0.f?*qA-*qB:*qB-*qA);
  104039. }else{
  104040. float temp=*qB;
  104041. *qB=(*qB>0.f?*qA-*qB:*qB-*qA);
  104042. *qA=temp;
  104043. }
  104044. if(*qB>fabs(*qA)*1.9999f){
  104045. *qB= -fabs(*qA)*2.f;
  104046. *qA= -*qA;
  104047. }
  104048. }
  104049. static float hypot_lookup[32]={
  104050. -0.009935, -0.011245, -0.012726, -0.014397,
  104051. -0.016282, -0.018407, -0.020800, -0.023494,
  104052. -0.026522, -0.029923, -0.033737, -0.038010,
  104053. -0.042787, -0.048121, -0.054064, -0.060671,
  104054. -0.068000, -0.076109, -0.085054, -0.094892,
  104055. -0.105675, -0.117451, -0.130260, -0.144134,
  104056. -0.159093, -0.175146, -0.192286, -0.210490,
  104057. -0.229718, -0.249913, -0.271001, -0.292893};
  104058. static void precomputed_couple_point(float premag,
  104059. int floorA,int floorB,
  104060. float *mag, float *ang){
  104061. int test=(floorA>floorB)-1;
  104062. int offset=31-abs(floorA-floorB);
  104063. float floormag=hypot_lookup[((offset<0)-1)&offset]+1.f;
  104064. floormag*=FLOOR1_fromdB_INV_LOOKUP[(floorB&test)|(floorA&(~test))];
  104065. *mag=premag*floormag;
  104066. *ang=0.f;
  104067. }
  104068. static float dipole_hypot(float a, float b){
  104069. if(a>0.){
  104070. if(b>0.)return sqrt(a*a+b*b);
  104071. if(a>-b)return sqrt(a*a-b*b);
  104072. return -sqrt(b*b-a*a);
  104073. }
  104074. if(b<0.)return -sqrt(a*a+b*b);
  104075. if(-a>b)return -sqrt(a*a-b*b);
  104076. return sqrt(b*b-a*a);
  104077. }
  104078. static float round_hypot(float a, float b){
  104079. if(a>0.){
  104080. if(b>0.)return sqrt(a*a+b*b);
  104081. if(a>-b)return sqrt(a*a+b*b);
  104082. return -sqrt(b*b+a*a);
  104083. }
  104084. if(b<0.)return -sqrt(a*a+b*b);
  104085. if(-a>b)return -sqrt(a*a+b*b);
  104086. return sqrt(b*b+a*a);
  104087. }
  104088. float **_vp_quantize_couple_memo(vorbis_block *vb,
  104089. vorbis_info_psy_global *g,
  104090. vorbis_look_psy *p,
  104091. vorbis_info_mapping0 *vi,
  104092. float **mdct){
  104093. int i,j,n=p->n;
  104094. float **ret=(float**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  104095. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  104096. for(i=0;i<vi->coupling_steps;i++){
  104097. float *mdctM=mdct[vi->coupling_mag[i]];
  104098. float *mdctA=mdct[vi->coupling_ang[i]];
  104099. ret[i]=(float*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  104100. for(j=0;j<limit;j++)
  104101. ret[i][j]=dipole_hypot(mdctM[j],mdctA[j]);
  104102. for(;j<n;j++)
  104103. ret[i][j]=round_hypot(mdctM[j],mdctA[j]);
  104104. }
  104105. return(ret);
  104106. }
  104107. static int apsort(const void *a, const void *b){
  104108. float f1=fabs(**(float**)a);
  104109. float f2=fabs(**(float**)b);
  104110. return (f1<f2)-(f1>f2);
  104111. }
  104112. int **_vp_quantize_couple_sort(vorbis_block *vb,
  104113. vorbis_look_psy *p,
  104114. vorbis_info_mapping0 *vi,
  104115. float **mags){
  104116. if(p->vi->normal_point_p){
  104117. int i,j,k,n=p->n;
  104118. int **ret=(int**) _vorbis_block_alloc(vb,vi->coupling_steps*sizeof(*ret));
  104119. int partition=p->vi->normal_partition;
  104120. float **work=(float**) alloca(sizeof(*work)*partition);
  104121. for(i=0;i<vi->coupling_steps;i++){
  104122. ret[i]=(int*) _vorbis_block_alloc(vb,n*sizeof(**ret));
  104123. for(j=0;j<n;j+=partition){
  104124. for(k=0;k<partition;k++)work[k]=mags[i]+k+j;
  104125. qsort(work,partition,sizeof(*work),apsort);
  104126. for(k=0;k<partition;k++)ret[i][k+j]=work[k]-mags[i];
  104127. }
  104128. }
  104129. return(ret);
  104130. }
  104131. return(NULL);
  104132. }
  104133. void _vp_noise_normalize_sort(vorbis_look_psy *p,
  104134. float *magnitudes,int *sortedindex){
  104135. int i,j,n=p->n;
  104136. vorbis_info_psy *vi=p->vi;
  104137. int partition=vi->normal_partition;
  104138. float **work=(float**) alloca(sizeof(*work)*partition);
  104139. int start=vi->normal_start;
  104140. for(j=start;j<n;j+=partition){
  104141. if(j+partition>n)partition=n-j;
  104142. for(i=0;i<partition;i++)work[i]=magnitudes+i+j;
  104143. qsort(work,partition,sizeof(*work),apsort);
  104144. for(i=0;i<partition;i++){
  104145. sortedindex[i+j-start]=work[i]-magnitudes;
  104146. }
  104147. }
  104148. }
  104149. void _vp_noise_normalize(vorbis_look_psy *p,
  104150. float *in,float *out,int *sortedindex){
  104151. int flag=0,i,j=0,n=p->n;
  104152. vorbis_info_psy *vi=p->vi;
  104153. int partition=vi->normal_partition;
  104154. int start=vi->normal_start;
  104155. if(start>n)start=n;
  104156. if(vi->normal_channel_p){
  104157. for(;j<start;j++)
  104158. out[j]=rint(in[j]);
  104159. for(;j+partition<=n;j+=partition){
  104160. float acc=0.;
  104161. int k;
  104162. for(i=j;i<j+partition;i++)
  104163. acc+=in[i]*in[i];
  104164. for(i=0;i<partition;i++){
  104165. k=sortedindex[i+j-start];
  104166. if(in[k]*in[k]>=.25f){
  104167. out[k]=rint(in[k]);
  104168. acc-=in[k]*in[k];
  104169. flag=1;
  104170. }else{
  104171. if(acc<vi->normal_thresh)break;
  104172. out[k]=unitnorm(in[k]);
  104173. acc-=1.;
  104174. }
  104175. }
  104176. for(;i<partition;i++){
  104177. k=sortedindex[i+j-start];
  104178. out[k]=0.;
  104179. }
  104180. }
  104181. }
  104182. for(;j<n;j++)
  104183. out[j]=rint(in[j]);
  104184. }
  104185. void _vp_couple(int blobno,
  104186. vorbis_info_psy_global *g,
  104187. vorbis_look_psy *p,
  104188. vorbis_info_mapping0 *vi,
  104189. float **res,
  104190. float **mag_memo,
  104191. int **mag_sort,
  104192. int **ifloor,
  104193. int *nonzero,
  104194. int sliding_lowpass){
  104195. int i,j,k,n=p->n;
  104196. for(i=0;i<vi->coupling_steps;i++){
  104197. if(nonzero[vi->coupling_mag[i]] ||
  104198. nonzero[vi->coupling_ang[i]]){
  104199. float *rM=res[vi->coupling_mag[i]];
  104200. float *rA=res[vi->coupling_ang[i]];
  104201. float *qM=rM+n;
  104202. float *qA=rA+n;
  104203. int *floorM=ifloor[vi->coupling_mag[i]];
  104204. int *floorA=ifloor[vi->coupling_ang[i]];
  104205. float prepoint=stereo_threshholds[g->coupling_prepointamp[blobno]];
  104206. float postpoint=stereo_threshholds[g->coupling_postpointamp[blobno]];
  104207. int partition=(p->vi->normal_point_p?p->vi->normal_partition:p->n);
  104208. int limit=g->coupling_pointlimit[p->vi->blockflag][blobno];
  104209. int pointlimit=limit;
  104210. nonzero[vi->coupling_mag[i]]=1;
  104211. nonzero[vi->coupling_ang[i]]=1;
  104212. if(n > 1000)
  104213. postpoint=stereo_threshholds_limited[g->coupling_postpointamp[blobno]];
  104214. for(j=0;j<p->n;j+=partition){
  104215. float acc=0.f;
  104216. for(k=0;k<partition;k++){
  104217. int l=k+j;
  104218. if(l<sliding_lowpass){
  104219. if((l>=limit && fabs(rM[l])<postpoint && fabs(rA[l])<postpoint) ||
  104220. (fabs(rM[l])<prepoint && fabs(rA[l])<prepoint)){
  104221. precomputed_couple_point(mag_memo[i][l],
  104222. floorM[l],floorA[l],
  104223. qM+l,qA+l);
  104224. if(rint(qM[l])==0.f)acc+=qM[l]*qM[l];
  104225. }else{
  104226. couple_lossless(rM[l],rA[l],qM+l,qA+l);
  104227. }
  104228. }else{
  104229. qM[l]=0.;
  104230. qA[l]=0.;
  104231. }
  104232. }
  104233. if(p->vi->normal_point_p){
  104234. for(k=0;k<partition && acc>=p->vi->normal_thresh;k++){
  104235. int l=mag_sort[i][j+k];
  104236. if(l<sliding_lowpass && l>=pointlimit && rint(qM[l])==0.f){
  104237. qM[l]=unitnorm(qM[l]);
  104238. acc-=1.f;
  104239. }
  104240. }
  104241. }
  104242. }
  104243. }
  104244. }
  104245. }
  104246. void hf_reduction(vorbis_info_psy_global *g,
  104247. vorbis_look_psy *p,
  104248. vorbis_info_mapping0 *vi,
  104249. float **mdct){
  104250. int i,j,n=p->n, de=0.3*p->m_val;
  104251. int limit=g->coupling_pointlimit[p->vi->blockflag][PACKETBLOBS/2];
  104252. for(i=0; i<vi->coupling_steps; i++){
  104253. for(j=limit; j<n; j++)
  104254. mdct[i][j] *= (1.0 - de*((float)(j-limit) / (float)(n-limit)));
  104255. }
  104256. }
  104257. #endif
  104258. /*** End of inlined file: psy.c ***/
  104259. /*** Start of inlined file: registry.c ***/
  104260. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104261. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104262. // tasks..
  104263. #if JUCE_MSVC
  104264. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104265. #endif
  104266. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104267. #if JUCE_USE_OGGVORBIS
  104268. extern vorbis_func_floor floor0_exportbundle;
  104269. extern vorbis_func_floor floor1_exportbundle;
  104270. extern vorbis_func_residue residue0_exportbundle;
  104271. extern vorbis_func_residue residue1_exportbundle;
  104272. extern vorbis_func_residue residue2_exportbundle;
  104273. extern vorbis_func_mapping mapping0_exportbundle;
  104274. vorbis_func_floor *_floor_P[]={
  104275. &floor0_exportbundle,
  104276. &floor1_exportbundle,
  104277. };
  104278. vorbis_func_residue *_residue_P[]={
  104279. &residue0_exportbundle,
  104280. &residue1_exportbundle,
  104281. &residue2_exportbundle,
  104282. };
  104283. vorbis_func_mapping *_mapping_P[]={
  104284. &mapping0_exportbundle,
  104285. };
  104286. #endif
  104287. /*** End of inlined file: registry.c ***/
  104288. /*** Start of inlined file: res0.c ***/
  104289. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104290. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104291. // tasks..
  104292. #if JUCE_MSVC
  104293. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104294. #endif
  104295. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104296. #if JUCE_USE_OGGVORBIS
  104297. #include <stdlib.h>
  104298. #include <string.h>
  104299. #include <math.h>
  104300. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104301. #include <stdio.h>
  104302. #endif
  104303. typedef struct {
  104304. vorbis_info_residue0 *info;
  104305. int parts;
  104306. int stages;
  104307. codebook *fullbooks;
  104308. codebook *phrasebook;
  104309. codebook ***partbooks;
  104310. int partvals;
  104311. int **decodemap;
  104312. long postbits;
  104313. long phrasebits;
  104314. long frames;
  104315. #if defined(TRAIN_RES) || defined(TRAIN_RESAUX)
  104316. int train_seq;
  104317. long *training_data[8][64];
  104318. float training_max[8][64];
  104319. float training_min[8][64];
  104320. float tmin;
  104321. float tmax;
  104322. #endif
  104323. } vorbis_look_residue0;
  104324. void res0_free_info(vorbis_info_residue *i){
  104325. vorbis_info_residue0 *info=(vorbis_info_residue0 *)i;
  104326. if(info){
  104327. memset(info,0,sizeof(*info));
  104328. _ogg_free(info);
  104329. }
  104330. }
  104331. void res0_free_look(vorbis_look_residue *i){
  104332. int j;
  104333. if(i){
  104334. vorbis_look_residue0 *look=(vorbis_look_residue0 *)i;
  104335. #ifdef TRAIN_RES
  104336. {
  104337. int j,k,l;
  104338. for(j=0;j<look->parts;j++){
  104339. for(k=0;k<8;k++)
  104340. if(look->training_data[k][j]){
  104341. char buffer[80];
  104342. FILE *of;
  104343. codebook *statebook=look->partbooks[j][k];
  104344. sprintf(buffer,"res_part%d_pass%d.vqd",j,k);
  104345. of=fopen(buffer,"a");
  104346. for(l=0;l<statebook->entries;l++)
  104347. fprintf(of,"%d:%ld\n",l,look->training_data[k][j][l]);
  104348. fclose(of);
  104349. _ogg_free(look->training_data[k][j]);
  104350. look->training_data[k][j]=NULL;
  104351. }
  104352. }
  104353. }
  104354. fprintf(stderr,"min/max residue: %g::%g\n",look->tmin,look->tmax);
  104355. #endif
  104356. for(j=0;j<look->parts;j++)
  104357. if(look->partbooks[j])_ogg_free(look->partbooks[j]);
  104358. _ogg_free(look->partbooks);
  104359. for(j=0;j<look->partvals;j++)
  104360. _ogg_free(look->decodemap[j]);
  104361. _ogg_free(look->decodemap);
  104362. memset(look,0,sizeof(*look));
  104363. _ogg_free(look);
  104364. }
  104365. }
  104366. static int icount(unsigned int v){
  104367. int ret=0;
  104368. while(v){
  104369. ret+=v&1;
  104370. v>>=1;
  104371. }
  104372. return(ret);
  104373. }
  104374. void res0_pack(vorbis_info_residue *vr,oggpack_buffer *opb){
  104375. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104376. int j,acc=0;
  104377. oggpack_write(opb,info->begin,24);
  104378. oggpack_write(opb,info->end,24);
  104379. oggpack_write(opb,info->grouping-1,24); /* residue vectors to group and
  104380. code with a partitioned book */
  104381. oggpack_write(opb,info->partitions-1,6); /* possible partition choices */
  104382. oggpack_write(opb,info->groupbook,8); /* group huffman book */
  104383. for(j=0;j<info->partitions;j++){
  104384. if(ilog(info->secondstages[j])>3){
  104385. oggpack_write(opb,info->secondstages[j],3);
  104386. oggpack_write(opb,1,1);
  104387. oggpack_write(opb,info->secondstages[j]>>3,5);
  104388. }else
  104389. oggpack_write(opb,info->secondstages[j],4); /* trailing zero */
  104390. acc+=icount(info->secondstages[j]);
  104391. }
  104392. for(j=0;j<acc;j++)
  104393. oggpack_write(opb,info->booklist[j],8);
  104394. }
  104395. vorbis_info_residue *res0_unpack(vorbis_info *vi,oggpack_buffer *opb){
  104396. int j,acc=0;
  104397. vorbis_info_residue0 *info=(vorbis_info_residue0*) _ogg_calloc(1,sizeof(*info));
  104398. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  104399. info->begin=oggpack_read(opb,24);
  104400. info->end=oggpack_read(opb,24);
  104401. info->grouping=oggpack_read(opb,24)+1;
  104402. info->partitions=oggpack_read(opb,6)+1;
  104403. info->groupbook=oggpack_read(opb,8);
  104404. for(j=0;j<info->partitions;j++){
  104405. int cascade=oggpack_read(opb,3);
  104406. if(oggpack_read(opb,1))
  104407. cascade|=(oggpack_read(opb,5)<<3);
  104408. info->secondstages[j]=cascade;
  104409. acc+=icount(cascade);
  104410. }
  104411. for(j=0;j<acc;j++)
  104412. info->booklist[j]=oggpack_read(opb,8);
  104413. if(info->groupbook>=ci->books)goto errout;
  104414. for(j=0;j<acc;j++)
  104415. if(info->booklist[j]>=ci->books)goto errout;
  104416. return(info);
  104417. errout:
  104418. res0_free_info(info);
  104419. return(NULL);
  104420. }
  104421. vorbis_look_residue *res0_look(vorbis_dsp_state *vd,
  104422. vorbis_info_residue *vr){
  104423. vorbis_info_residue0 *info=(vorbis_info_residue0 *)vr;
  104424. vorbis_look_residue0 *look=(vorbis_look_residue0 *)_ogg_calloc(1,sizeof(*look));
  104425. codec_setup_info *ci=(codec_setup_info*)vd->vi->codec_setup;
  104426. int j,k,acc=0;
  104427. int dim;
  104428. int maxstage=0;
  104429. look->info=info;
  104430. look->parts=info->partitions;
  104431. look->fullbooks=ci->fullbooks;
  104432. look->phrasebook=ci->fullbooks+info->groupbook;
  104433. dim=look->phrasebook->dim;
  104434. look->partbooks=(codebook***)_ogg_calloc(look->parts,sizeof(*look->partbooks));
  104435. for(j=0;j<look->parts;j++){
  104436. int stages=ilog(info->secondstages[j]);
  104437. if(stages){
  104438. if(stages>maxstage)maxstage=stages;
  104439. look->partbooks[j]=(codebook**) _ogg_calloc(stages,sizeof(*look->partbooks[j]));
  104440. for(k=0;k<stages;k++)
  104441. if(info->secondstages[j]&(1<<k)){
  104442. look->partbooks[j][k]=ci->fullbooks+info->booklist[acc++];
  104443. #ifdef TRAIN_RES
  104444. look->training_data[k][j]=_ogg_calloc(look->partbooks[j][k]->entries,
  104445. sizeof(***look->training_data));
  104446. #endif
  104447. }
  104448. }
  104449. }
  104450. look->partvals=rint(pow((float)look->parts,(float)dim));
  104451. look->stages=maxstage;
  104452. look->decodemap=(int**)_ogg_malloc(look->partvals*sizeof(*look->decodemap));
  104453. for(j=0;j<look->partvals;j++){
  104454. long val=j;
  104455. long mult=look->partvals/look->parts;
  104456. look->decodemap[j]=(int*)_ogg_malloc(dim*sizeof(*look->decodemap[j]));
  104457. for(k=0;k<dim;k++){
  104458. long deco=val/mult;
  104459. val-=deco*mult;
  104460. mult/=look->parts;
  104461. look->decodemap[j][k]=deco;
  104462. }
  104463. }
  104464. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104465. {
  104466. static int train_seq=0;
  104467. look->train_seq=train_seq++;
  104468. }
  104469. #endif
  104470. return(look);
  104471. }
  104472. static int local_book_besterror(codebook *book,float *a){
  104473. int dim=book->dim,i,k,o;
  104474. int best=0;
  104475. encode_aux_threshmatch *tt=book->c->thresh_tree;
  104476. for(k=0,o=dim;k<dim;++k){
  104477. float val=a[--o];
  104478. i=tt->threshvals>>1;
  104479. if(val<tt->quantthresh[i]){
  104480. if(val<tt->quantthresh[i-1]){
  104481. for(--i;i>0;--i)
  104482. if(val>=tt->quantthresh[i-1])
  104483. break;
  104484. }
  104485. }else{
  104486. for(++i;i<tt->threshvals-1;++i)
  104487. if(val<tt->quantthresh[i])break;
  104488. }
  104489. best=(best*tt->quantvals)+tt->quantmap[i];
  104490. }
  104491. if(book->c->lengthlist[best]<=0){
  104492. const static_codebook *c=book->c;
  104493. int i,j;
  104494. float bestf=0.f;
  104495. float *e=book->valuelist;
  104496. best=-1;
  104497. for(i=0;i<book->entries;i++){
  104498. if(c->lengthlist[i]>0){
  104499. float thisx=0.f;
  104500. for(j=0;j<dim;j++){
  104501. float val=(e[j]-a[j]);
  104502. thisx+=val*val;
  104503. }
  104504. if(best==-1 || thisx<bestf){
  104505. bestf=thisx;
  104506. best=i;
  104507. }
  104508. }
  104509. e+=dim;
  104510. }
  104511. }
  104512. {
  104513. float *ptr=book->valuelist+best*dim;
  104514. for(i=0;i<dim;i++)
  104515. *a++ -= *ptr++;
  104516. }
  104517. return(best);
  104518. }
  104519. static int _encodepart(oggpack_buffer *opb,float *vec, int n,
  104520. codebook *book,long *acc){
  104521. int i,bits=0;
  104522. int dim=book->dim;
  104523. int step=n/dim;
  104524. for(i=0;i<step;i++){
  104525. int entry=local_book_besterror(book,vec+i*dim);
  104526. #ifdef TRAIN_RES
  104527. acc[entry]++;
  104528. #endif
  104529. bits+=vorbis_book_encode(book,entry,opb);
  104530. }
  104531. return(bits);
  104532. }
  104533. static long **_01class(vorbis_block *vb,vorbis_look_residue *vl,
  104534. float **in,int ch){
  104535. long i,j,k;
  104536. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104537. vorbis_info_residue0 *info=look->info;
  104538. int samples_per_partition=info->grouping;
  104539. int possible_partitions=info->partitions;
  104540. int n=info->end-info->begin;
  104541. int partvals=n/samples_per_partition;
  104542. long **partword=(long**)_vorbis_block_alloc(vb,ch*sizeof(*partword));
  104543. float scale=100./samples_per_partition;
  104544. for(i=0;i<ch;i++){
  104545. partword[i]=(long*)_vorbis_block_alloc(vb,n/samples_per_partition*sizeof(*partword[i]));
  104546. memset(partword[i],0,n/samples_per_partition*sizeof(*partword[i]));
  104547. }
  104548. for(i=0;i<partvals;i++){
  104549. int offset=i*samples_per_partition+info->begin;
  104550. for(j=0;j<ch;j++){
  104551. float max=0.;
  104552. float ent=0.;
  104553. for(k=0;k<samples_per_partition;k++){
  104554. if(fabs(in[j][offset+k])>max)max=fabs(in[j][offset+k]);
  104555. ent+=fabs(rint(in[j][offset+k]));
  104556. }
  104557. ent*=scale;
  104558. for(k=0;k<possible_partitions-1;k++)
  104559. if(max<=info->classmetric1[k] &&
  104560. (info->classmetric2[k]<0 || (int)ent<info->classmetric2[k]))
  104561. break;
  104562. partword[j][i]=k;
  104563. }
  104564. }
  104565. #ifdef TRAIN_RESAUX
  104566. {
  104567. FILE *of;
  104568. char buffer[80];
  104569. for(i=0;i<ch;i++){
  104570. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104571. of=fopen(buffer,"a");
  104572. for(j=0;j<partvals;j++)
  104573. fprintf(of,"%ld, ",partword[i][j]);
  104574. fprintf(of,"\n");
  104575. fclose(of);
  104576. }
  104577. }
  104578. #endif
  104579. look->frames++;
  104580. return(partword);
  104581. }
  104582. static long **_2class(vorbis_block *vb,vorbis_look_residue *vl,float **in,
  104583. int ch){
  104584. long i,j,k,l;
  104585. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104586. vorbis_info_residue0 *info=look->info;
  104587. int samples_per_partition=info->grouping;
  104588. int possible_partitions=info->partitions;
  104589. int n=info->end-info->begin;
  104590. int partvals=n/samples_per_partition;
  104591. long **partword=(long**)_vorbis_block_alloc(vb,sizeof(*partword));
  104592. #if defined(TRAIN_RES) || defined (TRAIN_RESAUX)
  104593. FILE *of;
  104594. char buffer[80];
  104595. #endif
  104596. partword[0]=(long*)_vorbis_block_alloc(vb,n*ch/samples_per_partition*sizeof(*partword[0]));
  104597. memset(partword[0],0,n*ch/samples_per_partition*sizeof(*partword[0]));
  104598. for(i=0,l=info->begin/ch;i<partvals;i++){
  104599. float magmax=0.f;
  104600. float angmax=0.f;
  104601. for(j=0;j<samples_per_partition;j+=ch){
  104602. if(fabs(in[0][l])>magmax)magmax=fabs(in[0][l]);
  104603. for(k=1;k<ch;k++)
  104604. if(fabs(in[k][l])>angmax)angmax=fabs(in[k][l]);
  104605. l++;
  104606. }
  104607. for(j=0;j<possible_partitions-1;j++)
  104608. if(magmax<=info->classmetric1[j] &&
  104609. angmax<=info->classmetric2[j])
  104610. break;
  104611. partword[0][i]=j;
  104612. }
  104613. #ifdef TRAIN_RESAUX
  104614. sprintf(buffer,"resaux_%d.vqd",look->train_seq);
  104615. of=fopen(buffer,"a");
  104616. for(i=0;i<partvals;i++)
  104617. fprintf(of,"%ld, ",partword[0][i]);
  104618. fprintf(of,"\n");
  104619. fclose(of);
  104620. #endif
  104621. look->frames++;
  104622. return(partword);
  104623. }
  104624. static int _01forward(oggpack_buffer *opb,
  104625. vorbis_block *vb,vorbis_look_residue *vl,
  104626. float **in,int ch,
  104627. long **partword,
  104628. int (*encode)(oggpack_buffer *,float *,int,
  104629. codebook *,long *)){
  104630. long i,j,k,s;
  104631. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104632. vorbis_info_residue0 *info=look->info;
  104633. int samples_per_partition=info->grouping;
  104634. int possible_partitions=info->partitions;
  104635. int partitions_per_word=look->phrasebook->dim;
  104636. int n=info->end-info->begin;
  104637. int partvals=n/samples_per_partition;
  104638. long resbits[128];
  104639. long resvals[128];
  104640. #ifdef TRAIN_RES
  104641. for(i=0;i<ch;i++)
  104642. for(j=info->begin;j<info->end;j++){
  104643. if(in[i][j]>look->tmax)look->tmax=in[i][j];
  104644. if(in[i][j]<look->tmin)look->tmin=in[i][j];
  104645. }
  104646. #endif
  104647. memset(resbits,0,sizeof(resbits));
  104648. memset(resvals,0,sizeof(resvals));
  104649. for(s=0;s<look->stages;s++){
  104650. for(i=0;i<partvals;){
  104651. if(s==0){
  104652. for(j=0;j<ch;j++){
  104653. long val=partword[j][i];
  104654. for(k=1;k<partitions_per_word;k++){
  104655. val*=possible_partitions;
  104656. if(i+k<partvals)
  104657. val+=partword[j][i+k];
  104658. }
  104659. if(val<look->phrasebook->entries)
  104660. look->phrasebits+=vorbis_book_encode(look->phrasebook,val,opb);
  104661. #if 0 /*def TRAIN_RES*/
  104662. else
  104663. fprintf(stderr,"!");
  104664. #endif
  104665. }
  104666. }
  104667. for(k=0;k<partitions_per_word && i<partvals;k++,i++){
  104668. long offset=i*samples_per_partition+info->begin;
  104669. for(j=0;j<ch;j++){
  104670. if(s==0)resvals[partword[j][i]]+=samples_per_partition;
  104671. if(info->secondstages[partword[j][i]]&(1<<s)){
  104672. codebook *statebook=look->partbooks[partword[j][i]][s];
  104673. if(statebook){
  104674. int ret;
  104675. long *accumulator=NULL;
  104676. #ifdef TRAIN_RES
  104677. accumulator=look->training_data[s][partword[j][i]];
  104678. {
  104679. int l;
  104680. float *samples=in[j]+offset;
  104681. for(l=0;l<samples_per_partition;l++){
  104682. if(samples[l]<look->training_min[s][partword[j][i]])
  104683. look->training_min[s][partword[j][i]]=samples[l];
  104684. if(samples[l]>look->training_max[s][partword[j][i]])
  104685. look->training_max[s][partword[j][i]]=samples[l];
  104686. }
  104687. }
  104688. #endif
  104689. ret=encode(opb,in[j]+offset,samples_per_partition,
  104690. statebook,accumulator);
  104691. look->postbits+=ret;
  104692. resbits[partword[j][i]]+=ret;
  104693. }
  104694. }
  104695. }
  104696. }
  104697. }
  104698. }
  104699. return(0);
  104700. }
  104701. static int _01inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104702. float **in,int ch,
  104703. long (*decodepart)(codebook *, float *,
  104704. oggpack_buffer *,int)){
  104705. long i,j,k,l,s;
  104706. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104707. vorbis_info_residue0 *info=look->info;
  104708. int samples_per_partition=info->grouping;
  104709. int partitions_per_word=look->phrasebook->dim;
  104710. int n=info->end-info->begin;
  104711. int partvals=n/samples_per_partition;
  104712. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104713. int ***partword=(int***)alloca(ch*sizeof(*partword));
  104714. for(j=0;j<ch;j++)
  104715. partword[j]=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword[j]));
  104716. for(s=0;s<look->stages;s++){
  104717. for(i=0,l=0;i<partvals;l++){
  104718. if(s==0){
  104719. for(j=0;j<ch;j++){
  104720. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104721. if(temp==-1)goto eopbreak;
  104722. partword[j][l]=look->decodemap[temp];
  104723. if(partword[j][l]==NULL)goto errout;
  104724. }
  104725. }
  104726. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104727. for(j=0;j<ch;j++){
  104728. long offset=info->begin+i*samples_per_partition;
  104729. if(info->secondstages[partword[j][l][k]]&(1<<s)){
  104730. codebook *stagebook=look->partbooks[partword[j][l][k]][s];
  104731. if(stagebook){
  104732. if(decodepart(stagebook,in[j]+offset,&vb->opb,
  104733. samples_per_partition)==-1)goto eopbreak;
  104734. }
  104735. }
  104736. }
  104737. }
  104738. }
  104739. errout:
  104740. eopbreak:
  104741. return(0);
  104742. }
  104743. #if 0
  104744. long **res0_class(vorbis_block *vb,vorbis_look_residue *vl,
  104745. float **in,int *nonzero,int ch){
  104746. int i,used=0;
  104747. for(i=0;i<ch;i++)
  104748. if(nonzero[i])
  104749. in[used++]=in[i];
  104750. if(used)
  104751. return(_01class(vb,vl,in,used));
  104752. else
  104753. return(0);
  104754. }
  104755. int res0_forward(vorbis_block *vb,vorbis_look_residue *vl,
  104756. float **in,float **out,int *nonzero,int ch,
  104757. long **partword){
  104758. int i,j,used=0,n=vb->pcmend/2;
  104759. for(i=0;i<ch;i++)
  104760. if(nonzero[i]){
  104761. if(out)
  104762. for(j=0;j<n;j++)
  104763. out[i][j]+=in[i][j];
  104764. in[used++]=in[i];
  104765. }
  104766. if(used){
  104767. int ret=_01forward(vb,vl,in,used,partword,
  104768. _interleaved_encodepart);
  104769. if(out){
  104770. used=0;
  104771. for(i=0;i<ch;i++)
  104772. if(nonzero[i]){
  104773. for(j=0;j<n;j++)
  104774. out[i][j]-=in[used][j];
  104775. used++;
  104776. }
  104777. }
  104778. return(ret);
  104779. }else{
  104780. return(0);
  104781. }
  104782. }
  104783. #endif
  104784. int res0_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104785. float **in,int *nonzero,int ch){
  104786. int i,used=0;
  104787. for(i=0;i<ch;i++)
  104788. if(nonzero[i])
  104789. in[used++]=in[i];
  104790. if(used)
  104791. return(_01inverse(vb,vl,in,used,vorbis_book_decodevs_add));
  104792. else
  104793. return(0);
  104794. }
  104795. int res1_forward(oggpack_buffer *opb,vorbis_block *vb,vorbis_look_residue *vl,
  104796. float **in,float **out,int *nonzero,int ch,
  104797. long **partword){
  104798. int i,j,used=0,n=vb->pcmend/2;
  104799. for(i=0;i<ch;i++)
  104800. if(nonzero[i]){
  104801. if(out)
  104802. for(j=0;j<n;j++)
  104803. out[i][j]+=in[i][j];
  104804. in[used++]=in[i];
  104805. }
  104806. if(used){
  104807. int ret=_01forward(opb,vb,vl,in,used,partword,_encodepart);
  104808. if(out){
  104809. used=0;
  104810. for(i=0;i<ch;i++)
  104811. if(nonzero[i]){
  104812. for(j=0;j<n;j++)
  104813. out[i][j]-=in[used][j];
  104814. used++;
  104815. }
  104816. }
  104817. return(ret);
  104818. }else{
  104819. return(0);
  104820. }
  104821. }
  104822. long **res1_class(vorbis_block *vb,vorbis_look_residue *vl,
  104823. float **in,int *nonzero,int ch){
  104824. int i,used=0;
  104825. for(i=0;i<ch;i++)
  104826. if(nonzero[i])
  104827. in[used++]=in[i];
  104828. if(used)
  104829. return(_01class(vb,vl,in,used));
  104830. else
  104831. return(0);
  104832. }
  104833. int res1_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104834. float **in,int *nonzero,int ch){
  104835. int i,used=0;
  104836. for(i=0;i<ch;i++)
  104837. if(nonzero[i])
  104838. in[used++]=in[i];
  104839. if(used)
  104840. return(_01inverse(vb,vl,in,used,vorbis_book_decodev_add));
  104841. else
  104842. return(0);
  104843. }
  104844. long **res2_class(vorbis_block *vb,vorbis_look_residue *vl,
  104845. float **in,int *nonzero,int ch){
  104846. int i,used=0;
  104847. for(i=0;i<ch;i++)
  104848. if(nonzero[i])used++;
  104849. if(used)
  104850. return(_2class(vb,vl,in,ch));
  104851. else
  104852. return(0);
  104853. }
  104854. int res2_forward(oggpack_buffer *opb,
  104855. vorbis_block *vb,vorbis_look_residue *vl,
  104856. float **in,float **out,int *nonzero,int ch,
  104857. long **partword){
  104858. long i,j,k,n=vb->pcmend/2,used=0;
  104859. float *work=(float*)_vorbis_block_alloc(vb,ch*n*sizeof(*work));
  104860. for(i=0;i<ch;i++){
  104861. float *pcm=in[i];
  104862. if(nonzero[i])used++;
  104863. for(j=0,k=i;j<n;j++,k+=ch)
  104864. work[k]=pcm[j];
  104865. }
  104866. if(used){
  104867. int ret=_01forward(opb,vb,vl,&work,1,partword,_encodepart);
  104868. if(out){
  104869. for(i=0;i<ch;i++){
  104870. float *pcm=in[i];
  104871. float *sofar=out[i];
  104872. for(j=0,k=i;j<n;j++,k+=ch)
  104873. sofar[j]+=pcm[j]-work[k];
  104874. }
  104875. }
  104876. return(ret);
  104877. }else{
  104878. return(0);
  104879. }
  104880. }
  104881. int res2_inverse(vorbis_block *vb,vorbis_look_residue *vl,
  104882. float **in,int *nonzero,int ch){
  104883. long i,k,l,s;
  104884. vorbis_look_residue0 *look=(vorbis_look_residue0 *)vl;
  104885. vorbis_info_residue0 *info=look->info;
  104886. int samples_per_partition=info->grouping;
  104887. int partitions_per_word=look->phrasebook->dim;
  104888. int n=info->end-info->begin;
  104889. int partvals=n/samples_per_partition;
  104890. int partwords=(partvals+partitions_per_word-1)/partitions_per_word;
  104891. int **partword=(int**)_vorbis_block_alloc(vb,partwords*sizeof(*partword));
  104892. for(i=0;i<ch;i++)if(nonzero[i])break;
  104893. if(i==ch)return(0); /* no nonzero vectors */
  104894. for(s=0;s<look->stages;s++){
  104895. for(i=0,l=0;i<partvals;l++){
  104896. if(s==0){
  104897. int temp=vorbis_book_decode(look->phrasebook,&vb->opb);
  104898. if(temp==-1)goto eopbreak;
  104899. partword[l]=look->decodemap[temp];
  104900. if(partword[l]==NULL)goto errout;
  104901. }
  104902. for(k=0;k<partitions_per_word && i<partvals;k++,i++)
  104903. if(info->secondstages[partword[l][k]]&(1<<s)){
  104904. codebook *stagebook=look->partbooks[partword[l][k]][s];
  104905. if(stagebook){
  104906. if(vorbis_book_decodevv_add(stagebook,in,
  104907. i*samples_per_partition+info->begin,ch,
  104908. &vb->opb,samples_per_partition)==-1)
  104909. goto eopbreak;
  104910. }
  104911. }
  104912. }
  104913. }
  104914. errout:
  104915. eopbreak:
  104916. return(0);
  104917. }
  104918. vorbis_func_residue residue0_exportbundle={
  104919. NULL,
  104920. &res0_unpack,
  104921. &res0_look,
  104922. &res0_free_info,
  104923. &res0_free_look,
  104924. NULL,
  104925. NULL,
  104926. &res0_inverse
  104927. };
  104928. vorbis_func_residue residue1_exportbundle={
  104929. &res0_pack,
  104930. &res0_unpack,
  104931. &res0_look,
  104932. &res0_free_info,
  104933. &res0_free_look,
  104934. &res1_class,
  104935. &res1_forward,
  104936. &res1_inverse
  104937. };
  104938. vorbis_func_residue residue2_exportbundle={
  104939. &res0_pack,
  104940. &res0_unpack,
  104941. &res0_look,
  104942. &res0_free_info,
  104943. &res0_free_look,
  104944. &res2_class,
  104945. &res2_forward,
  104946. &res2_inverse
  104947. };
  104948. #endif
  104949. /*** End of inlined file: res0.c ***/
  104950. /*** Start of inlined file: sharedbook.c ***/
  104951. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  104952. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  104953. // tasks..
  104954. #if JUCE_MSVC
  104955. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  104956. #endif
  104957. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  104958. #if JUCE_USE_OGGVORBIS
  104959. #include <stdlib.h>
  104960. #include <math.h>
  104961. #include <string.h>
  104962. int _ilog(unsigned int v){
  104963. int ret=0;
  104964. while(v){
  104965. ret++;
  104966. v>>=1;
  104967. }
  104968. return(ret);
  104969. }
  104970. #define VQ_FEXP 10
  104971. #define VQ_FMAN 21
  104972. #define VQ_FEXP_BIAS 768 /* bias toward values smaller than 1. */
  104973. long _float32_pack(float val){
  104974. int sign=0;
  104975. long exp;
  104976. long mant;
  104977. if(val<0){
  104978. sign=0x80000000;
  104979. val= -val;
  104980. }
  104981. exp= floor(log(val)/log(2.f));
  104982. mant=rint(ldexp(val,(VQ_FMAN-1)-exp));
  104983. exp=(exp+VQ_FEXP_BIAS)<<VQ_FMAN;
  104984. return(sign|exp|mant);
  104985. }
  104986. float _float32_unpack(long val){
  104987. double mant=val&0x1fffff;
  104988. int sign=val&0x80000000;
  104989. long exp =(val&0x7fe00000L)>>VQ_FMAN;
  104990. if(sign)mant= -mant;
  104991. return(ldexp(mant,exp-(VQ_FMAN-1)-VQ_FEXP_BIAS));
  104992. }
  104993. ogg_uint32_t *_make_words(long *l,long n,long sparsecount){
  104994. long i,j,count=0;
  104995. ogg_uint32_t marker[33];
  104996. ogg_uint32_t *r=(ogg_uint32_t*)_ogg_malloc((sparsecount?sparsecount:n)*sizeof(*r));
  104997. memset(marker,0,sizeof(marker));
  104998. for(i=0;i<n;i++){
  104999. long length=l[i];
  105000. if(length>0){
  105001. ogg_uint32_t entry=marker[length];
  105002. if(length<32 && (entry>>length)){
  105003. _ogg_free(r);
  105004. return(NULL);
  105005. }
  105006. r[count++]=entry;
  105007. {
  105008. for(j=length;j>0;j--){
  105009. if(marker[j]&1){
  105010. if(j==1)
  105011. marker[1]++;
  105012. else
  105013. marker[j]=marker[j-1]<<1;
  105014. break; /* invariant says next upper marker would already
  105015. have been moved if it was on the same path */
  105016. }
  105017. marker[j]++;
  105018. }
  105019. }
  105020. for(j=length+1;j<33;j++)
  105021. if((marker[j]>>1) == entry){
  105022. entry=marker[j];
  105023. marker[j]=marker[j-1]<<1;
  105024. }else
  105025. break;
  105026. }else
  105027. if(sparsecount==0)count++;
  105028. }
  105029. for(i=0,count=0;i<n;i++){
  105030. ogg_uint32_t temp=0;
  105031. for(j=0;j<l[i];j++){
  105032. temp<<=1;
  105033. temp|=(r[count]>>j)&1;
  105034. }
  105035. if(sparsecount){
  105036. if(l[i])
  105037. r[count++]=temp;
  105038. }else
  105039. r[count++]=temp;
  105040. }
  105041. return(r);
  105042. }
  105043. long _book_maptype1_quantvals(const static_codebook *b){
  105044. long vals=floor(pow((float)b->entries,1.f/b->dim));
  105045. while(1){
  105046. long acc=1;
  105047. long acc1=1;
  105048. int i;
  105049. for(i=0;i<b->dim;i++){
  105050. acc*=vals;
  105051. acc1*=vals+1;
  105052. }
  105053. if(acc<=b->entries && acc1>b->entries){
  105054. return(vals);
  105055. }else{
  105056. if(acc>b->entries){
  105057. vals--;
  105058. }else{
  105059. vals++;
  105060. }
  105061. }
  105062. }
  105063. }
  105064. float *_book_unquantize(const static_codebook *b,int n,int *sparsemap){
  105065. long j,k,count=0;
  105066. if(b->maptype==1 || b->maptype==2){
  105067. int quantvals;
  105068. float mindel=_float32_unpack(b->q_min);
  105069. float delta=_float32_unpack(b->q_delta);
  105070. float *r=(float*)_ogg_calloc(n*b->dim,sizeof(*r));
  105071. switch(b->maptype){
  105072. case 1:
  105073. quantvals=_book_maptype1_quantvals(b);
  105074. for(j=0;j<b->entries;j++){
  105075. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  105076. float last=0.f;
  105077. int indexdiv=1;
  105078. for(k=0;k<b->dim;k++){
  105079. int index= (j/indexdiv)%quantvals;
  105080. float val=b->quantlist[index];
  105081. val=fabs(val)*delta+mindel+last;
  105082. if(b->q_sequencep)last=val;
  105083. if(sparsemap)
  105084. r[sparsemap[count]*b->dim+k]=val;
  105085. else
  105086. r[count*b->dim+k]=val;
  105087. indexdiv*=quantvals;
  105088. }
  105089. count++;
  105090. }
  105091. }
  105092. break;
  105093. case 2:
  105094. for(j=0;j<b->entries;j++){
  105095. if((sparsemap && b->lengthlist[j]) || !sparsemap){
  105096. float last=0.f;
  105097. for(k=0;k<b->dim;k++){
  105098. float val=b->quantlist[j*b->dim+k];
  105099. val=fabs(val)*delta+mindel+last;
  105100. if(b->q_sequencep)last=val;
  105101. if(sparsemap)
  105102. r[sparsemap[count]*b->dim+k]=val;
  105103. else
  105104. r[count*b->dim+k]=val;
  105105. }
  105106. count++;
  105107. }
  105108. }
  105109. break;
  105110. }
  105111. return(r);
  105112. }
  105113. return(NULL);
  105114. }
  105115. void vorbis_staticbook_clear(static_codebook *b){
  105116. if(b->allocedp){
  105117. if(b->quantlist)_ogg_free(b->quantlist);
  105118. if(b->lengthlist)_ogg_free(b->lengthlist);
  105119. if(b->nearest_tree){
  105120. _ogg_free(b->nearest_tree->ptr0);
  105121. _ogg_free(b->nearest_tree->ptr1);
  105122. _ogg_free(b->nearest_tree->p);
  105123. _ogg_free(b->nearest_tree->q);
  105124. memset(b->nearest_tree,0,sizeof(*b->nearest_tree));
  105125. _ogg_free(b->nearest_tree);
  105126. }
  105127. if(b->thresh_tree){
  105128. _ogg_free(b->thresh_tree->quantthresh);
  105129. _ogg_free(b->thresh_tree->quantmap);
  105130. memset(b->thresh_tree,0,sizeof(*b->thresh_tree));
  105131. _ogg_free(b->thresh_tree);
  105132. }
  105133. memset(b,0,sizeof(*b));
  105134. }
  105135. }
  105136. void vorbis_staticbook_destroy(static_codebook *b){
  105137. if(b->allocedp){
  105138. vorbis_staticbook_clear(b);
  105139. _ogg_free(b);
  105140. }
  105141. }
  105142. void vorbis_book_clear(codebook *b){
  105143. if(b->valuelist)_ogg_free(b->valuelist);
  105144. if(b->codelist)_ogg_free(b->codelist);
  105145. if(b->dec_index)_ogg_free(b->dec_index);
  105146. if(b->dec_codelengths)_ogg_free(b->dec_codelengths);
  105147. if(b->dec_firsttable)_ogg_free(b->dec_firsttable);
  105148. memset(b,0,sizeof(*b));
  105149. }
  105150. int vorbis_book_init_encode(codebook *c,const static_codebook *s){
  105151. memset(c,0,sizeof(*c));
  105152. c->c=s;
  105153. c->entries=s->entries;
  105154. c->used_entries=s->entries;
  105155. c->dim=s->dim;
  105156. c->codelist=_make_words(s->lengthlist,s->entries,0);
  105157. c->valuelist=_book_unquantize(s,s->entries,NULL);
  105158. return(0);
  105159. }
  105160. static int sort32a(const void *a,const void *b){
  105161. return ( **(ogg_uint32_t **)a>**(ogg_uint32_t **)b)-
  105162. ( **(ogg_uint32_t **)a<**(ogg_uint32_t **)b);
  105163. }
  105164. int vorbis_book_init_decode(codebook *c,const static_codebook *s){
  105165. int i,j,n=0,tabn;
  105166. int *sortindex;
  105167. memset(c,0,sizeof(*c));
  105168. for(i=0;i<s->entries;i++)
  105169. if(s->lengthlist[i]>0)
  105170. n++;
  105171. c->entries=s->entries;
  105172. c->used_entries=n;
  105173. c->dim=s->dim;
  105174. {
  105175. ogg_uint32_t *codes=_make_words(s->lengthlist,s->entries,c->used_entries);
  105176. ogg_uint32_t **codep=(ogg_uint32_t**)alloca(sizeof(*codep)*n);
  105177. if(codes==NULL)goto err_out;
  105178. for(i=0;i<n;i++){
  105179. codes[i]=ogg_bitreverse(codes[i]);
  105180. codep[i]=codes+i;
  105181. }
  105182. qsort(codep,n,sizeof(*codep),sort32a);
  105183. sortindex=(int*)alloca(n*sizeof(*sortindex));
  105184. c->codelist=(ogg_uint32_t*)_ogg_malloc(n*sizeof(*c->codelist));
  105185. for(i=0;i<n;i++){
  105186. int position=codep[i]-codes;
  105187. sortindex[position]=i;
  105188. }
  105189. for(i=0;i<n;i++)
  105190. c->codelist[sortindex[i]]=codes[i];
  105191. _ogg_free(codes);
  105192. }
  105193. c->valuelist=_book_unquantize(s,n,sortindex);
  105194. c->dec_index=(int*)_ogg_malloc(n*sizeof(*c->dec_index));
  105195. for(n=0,i=0;i<s->entries;i++)
  105196. if(s->lengthlist[i]>0)
  105197. c->dec_index[sortindex[n++]]=i;
  105198. c->dec_codelengths=(char*)_ogg_malloc(n*sizeof(*c->dec_codelengths));
  105199. for(n=0,i=0;i<s->entries;i++)
  105200. if(s->lengthlist[i]>0)
  105201. c->dec_codelengths[sortindex[n++]]=s->lengthlist[i];
  105202. c->dec_firsttablen=_ilog(c->used_entries)-4; /* this is magic */
  105203. if(c->dec_firsttablen<5)c->dec_firsttablen=5;
  105204. if(c->dec_firsttablen>8)c->dec_firsttablen=8;
  105205. tabn=1<<c->dec_firsttablen;
  105206. c->dec_firsttable=(ogg_uint32_t*)_ogg_calloc(tabn,sizeof(*c->dec_firsttable));
  105207. c->dec_maxlength=0;
  105208. for(i=0;i<n;i++){
  105209. if(c->dec_maxlength<c->dec_codelengths[i])
  105210. c->dec_maxlength=c->dec_codelengths[i];
  105211. if(c->dec_codelengths[i]<=c->dec_firsttablen){
  105212. ogg_uint32_t orig=ogg_bitreverse(c->codelist[i]);
  105213. for(j=0;j<(1<<(c->dec_firsttablen-c->dec_codelengths[i]));j++)
  105214. c->dec_firsttable[orig|(j<<c->dec_codelengths[i])]=i+1;
  105215. }
  105216. }
  105217. {
  105218. ogg_uint32_t mask=0xfffffffeUL<<(31-c->dec_firsttablen);
  105219. long lo=0,hi=0;
  105220. for(i=0;i<tabn;i++){
  105221. ogg_uint32_t word=i<<(32-c->dec_firsttablen);
  105222. if(c->dec_firsttable[ogg_bitreverse(word)]==0){
  105223. while((lo+1)<n && c->codelist[lo+1]<=word)lo++;
  105224. while( hi<n && word>=(c->codelist[hi]&mask))hi++;
  105225. {
  105226. unsigned long loval=lo;
  105227. unsigned long hival=n-hi;
  105228. if(loval>0x7fff)loval=0x7fff;
  105229. if(hival>0x7fff)hival=0x7fff;
  105230. c->dec_firsttable[ogg_bitreverse(word)]=
  105231. 0x80000000UL | (loval<<15) | hival;
  105232. }
  105233. }
  105234. }
  105235. }
  105236. return(0);
  105237. err_out:
  105238. vorbis_book_clear(c);
  105239. return(-1);
  105240. }
  105241. static float _dist(int el,float *ref, float *b,int step){
  105242. int i;
  105243. float acc=0.f;
  105244. for(i=0;i<el;i++){
  105245. float val=(ref[i]-b[i*step]);
  105246. acc+=val*val;
  105247. }
  105248. return(acc);
  105249. }
  105250. int _best(codebook *book, float *a, int step){
  105251. encode_aux_threshmatch *tt=book->c->thresh_tree;
  105252. #if 0
  105253. encode_aux_nearestmatch *nt=book->c->nearest_tree;
  105254. encode_aux_pigeonhole *pt=book->c->pigeon_tree;
  105255. #endif
  105256. int dim=book->dim;
  105257. int k,o;
  105258. if(tt){
  105259. int index=0,i;
  105260. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105261. i=tt->threshvals>>1;
  105262. if(a[o]<tt->quantthresh[i]){
  105263. for(;i>0;i--)
  105264. if(a[o]>=tt->quantthresh[i-1])
  105265. break;
  105266. }else{
  105267. for(i++;i<tt->threshvals-1;i++)
  105268. if(a[o]<tt->quantthresh[i])break;
  105269. }
  105270. index=(index*tt->quantvals)+tt->quantmap[i];
  105271. }
  105272. if(book->c->lengthlist[index]>0) /* is this unused? If so, we'll
  105273. use a decision tree after all
  105274. and fall through*/
  105275. return(index);
  105276. }
  105277. #if 0
  105278. if(pt){
  105279. const static_codebook *c=book->c;
  105280. int i,besti=-1;
  105281. float best=0.f;
  105282. int entry=0;
  105283. if(c->q_sequencep){
  105284. int pv;
  105285. long mul=1;
  105286. float qlast=0;
  105287. for(k=0,o=0;k<dim;k++,o+=step){
  105288. pv=(int)((a[o]-qlast-pt->min)/pt->del);
  105289. if(pv<0 || pv>=pt->mapentries)break;
  105290. entry+=pt->pigeonmap[pv]*mul;
  105291. mul*=pt->quantvals;
  105292. qlast+=pv*pt->del+pt->min;
  105293. }
  105294. }else{
  105295. for(k=0,o=step*(dim-1);k<dim;k++,o-=step){
  105296. int pv=(int)((a[o]-pt->min)/pt->del);
  105297. if(pv<0 || pv>=pt->mapentries)break;
  105298. entry=entry*pt->quantvals+pt->pigeonmap[pv];
  105299. }
  105300. }
  105301. if(k==dim && pt->fitlength[entry]){
  105302. long *list=pt->fitlist+pt->fitmap[entry];
  105303. for(i=0;i<pt->fitlength[entry];i++){
  105304. float this=_dist(dim,book->valuelist+list[i]*dim,a,step);
  105305. if(besti==-1 || this<best){
  105306. best=this;
  105307. besti=list[i];
  105308. }
  105309. }
  105310. return(besti);
  105311. }
  105312. }
  105313. if(nt){
  105314. while(1){
  105315. float c=0.f;
  105316. float *p=book->valuelist+nt->p[ptr];
  105317. float *q=book->valuelist+nt->q[ptr];
  105318. for(k=0,o=0;k<dim;k++,o+=step)
  105319. c+=(p[k]-q[k])*(a[o]-(p[k]+q[k])*.5);
  105320. if(c>0.f) /* in A */
  105321. ptr= -nt->ptr0[ptr];
  105322. else /* in B */
  105323. ptr= -nt->ptr1[ptr];
  105324. if(ptr<=0)break;
  105325. }
  105326. return(-ptr);
  105327. }
  105328. #endif
  105329. {
  105330. const static_codebook *c=book->c;
  105331. int i,besti=-1;
  105332. float best=0.f;
  105333. float *e=book->valuelist;
  105334. for(i=0;i<book->entries;i++){
  105335. if(c->lengthlist[i]>0){
  105336. float thisx=_dist(dim,e,a,step);
  105337. if(besti==-1 || thisx<best){
  105338. best=thisx;
  105339. besti=i;
  105340. }
  105341. }
  105342. e+=dim;
  105343. }
  105344. return(besti);
  105345. }
  105346. }
  105347. long vorbis_book_codeword(codebook *book,int entry){
  105348. if(book->c) /* only use with encode; decode optimizations are
  105349. allowed to break this */
  105350. return book->codelist[entry];
  105351. return -1;
  105352. }
  105353. long vorbis_book_codelen(codebook *book,int entry){
  105354. if(book->c) /* only use with encode; decode optimizations are
  105355. allowed to break this */
  105356. return book->c->lengthlist[entry];
  105357. return -1;
  105358. }
  105359. #ifdef _V_SELFTEST
  105360. #include <stdio.h>
  105361. static long full_quantlist1[]={0,1,2,3, 4,5,6,7, 8,3,6,1};
  105362. static long partial_quantlist1[]={0,7,2};
  105363. static_codebook test1={
  105364. 4,16,
  105365. NULL,
  105366. 0,
  105367. 0,0,0,0,
  105368. NULL,
  105369. NULL,NULL
  105370. };
  105371. static float *test1_result=NULL;
  105372. static_codebook test2={
  105373. 4,3,
  105374. NULL,
  105375. 2,
  105376. -533200896,1611661312,4,0,
  105377. full_quantlist1,
  105378. NULL,NULL
  105379. };
  105380. static float test2_result[]={-3,-2,-1,0, 1,2,3,4, 5,0,3,-2};
  105381. static_codebook test3={
  105382. 4,3,
  105383. NULL,
  105384. 2,
  105385. -533200896,1611661312,4,1,
  105386. full_quantlist1,
  105387. NULL,NULL
  105388. };
  105389. static float test3_result[]={-3,-5,-6,-6, 1,3,6,10, 5,5,8,6};
  105390. static_codebook test4={
  105391. 3,27,
  105392. NULL,
  105393. 1,
  105394. -533200896,1611661312,4,0,
  105395. partial_quantlist1,
  105396. NULL,NULL
  105397. };
  105398. static float test4_result[]={-3,-3,-3, 4,-3,-3, -1,-3,-3,
  105399. -3, 4,-3, 4, 4,-3, -1, 4,-3,
  105400. -3,-1,-3, 4,-1,-3, -1,-1,-3,
  105401. -3,-3, 4, 4,-3, 4, -1,-3, 4,
  105402. -3, 4, 4, 4, 4, 4, -1, 4, 4,
  105403. -3,-1, 4, 4,-1, 4, -1,-1, 4,
  105404. -3,-3,-1, 4,-3,-1, -1,-3,-1,
  105405. -3, 4,-1, 4, 4,-1, -1, 4,-1,
  105406. -3,-1,-1, 4,-1,-1, -1,-1,-1};
  105407. static_codebook test5={
  105408. 3,27,
  105409. NULL,
  105410. 1,
  105411. -533200896,1611661312,4,1,
  105412. partial_quantlist1,
  105413. NULL,NULL
  105414. };
  105415. static float test5_result[]={-3,-6,-9, 4, 1,-2, -1,-4,-7,
  105416. -3, 1,-2, 4, 8, 5, -1, 3, 0,
  105417. -3,-4,-7, 4, 3, 0, -1,-2,-5,
  105418. -3,-6,-2, 4, 1, 5, -1,-4, 0,
  105419. -3, 1, 5, 4, 8,12, -1, 3, 7,
  105420. -3,-4, 0, 4, 3, 7, -1,-2, 2,
  105421. -3,-6,-7, 4, 1, 0, -1,-4,-5,
  105422. -3, 1, 0, 4, 8, 7, -1, 3, 2,
  105423. -3,-4,-5, 4, 3, 2, -1,-2,-3};
  105424. void run_test(static_codebook *b,float *comp){
  105425. float *out=_book_unquantize(b,b->entries,NULL);
  105426. int i;
  105427. if(comp){
  105428. if(!out){
  105429. fprintf(stderr,"_book_unquantize incorrectly returned NULL\n");
  105430. exit(1);
  105431. }
  105432. for(i=0;i<b->entries*b->dim;i++)
  105433. if(fabs(out[i]-comp[i])>.0001){
  105434. fprintf(stderr,"disagreement in unquantized and reference data:\n"
  105435. "position %d, %g != %g\n",i,out[i],comp[i]);
  105436. exit(1);
  105437. }
  105438. }else{
  105439. if(out){
  105440. fprintf(stderr,"_book_unquantize returned a value array: \n"
  105441. " correct result should have been NULL\n");
  105442. exit(1);
  105443. }
  105444. }
  105445. }
  105446. int main(){
  105447. fprintf(stderr,"Dequant test 1... ");
  105448. run_test(&test1,test1_result);
  105449. fprintf(stderr,"OK\nDequant test 2... ");
  105450. run_test(&test2,test2_result);
  105451. fprintf(stderr,"OK\nDequant test 3... ");
  105452. run_test(&test3,test3_result);
  105453. fprintf(stderr,"OK\nDequant test 4... ");
  105454. run_test(&test4,test4_result);
  105455. fprintf(stderr,"OK\nDequant test 5... ");
  105456. run_test(&test5,test5_result);
  105457. fprintf(stderr,"OK\n\n");
  105458. return(0);
  105459. }
  105460. #endif
  105461. #endif
  105462. /*** End of inlined file: sharedbook.c ***/
  105463. /*** Start of inlined file: smallft.c ***/
  105464. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  105465. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  105466. // tasks..
  105467. #if JUCE_MSVC
  105468. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  105469. #endif
  105470. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  105471. #if JUCE_USE_OGGVORBIS
  105472. #include <stdlib.h>
  105473. #include <string.h>
  105474. #include <math.h>
  105475. static void drfti1(int n, float *wa, int *ifac){
  105476. static int ntryh[4] = { 4,2,3,5 };
  105477. static float tpi = 6.28318530717958648f;
  105478. float arg,argh,argld,fi;
  105479. int ntry=0,i,j=-1;
  105480. int k1, l1, l2, ib;
  105481. int ld, ii, ip, is, nq, nr;
  105482. int ido, ipm, nfm1;
  105483. int nl=n;
  105484. int nf=0;
  105485. L101:
  105486. j++;
  105487. if (j < 4)
  105488. ntry=ntryh[j];
  105489. else
  105490. ntry+=2;
  105491. L104:
  105492. nq=nl/ntry;
  105493. nr=nl-ntry*nq;
  105494. if (nr!=0) goto L101;
  105495. nf++;
  105496. ifac[nf+1]=ntry;
  105497. nl=nq;
  105498. if(ntry!=2)goto L107;
  105499. if(nf==1)goto L107;
  105500. for (i=1;i<nf;i++){
  105501. ib=nf-i+1;
  105502. ifac[ib+1]=ifac[ib];
  105503. }
  105504. ifac[2] = 2;
  105505. L107:
  105506. if(nl!=1)goto L104;
  105507. ifac[0]=n;
  105508. ifac[1]=nf;
  105509. argh=tpi/n;
  105510. is=0;
  105511. nfm1=nf-1;
  105512. l1=1;
  105513. if(nfm1==0)return;
  105514. for (k1=0;k1<nfm1;k1++){
  105515. ip=ifac[k1+2];
  105516. ld=0;
  105517. l2=l1*ip;
  105518. ido=n/l2;
  105519. ipm=ip-1;
  105520. for (j=0;j<ipm;j++){
  105521. ld+=l1;
  105522. i=is;
  105523. argld=(float)ld*argh;
  105524. fi=0.f;
  105525. for (ii=2;ii<ido;ii+=2){
  105526. fi+=1.f;
  105527. arg=fi*argld;
  105528. wa[i++]=cos(arg);
  105529. wa[i++]=sin(arg);
  105530. }
  105531. is+=ido;
  105532. }
  105533. l1=l2;
  105534. }
  105535. }
  105536. static void fdrffti(int n, float *wsave, int *ifac){
  105537. if (n == 1) return;
  105538. drfti1(n, wsave+n, ifac);
  105539. }
  105540. static void dradf2(int ido,int l1,float *cc,float *ch,float *wa1){
  105541. int i,k;
  105542. float ti2,tr2;
  105543. int t0,t1,t2,t3,t4,t5,t6;
  105544. t1=0;
  105545. t0=(t2=l1*ido);
  105546. t3=ido<<1;
  105547. for(k=0;k<l1;k++){
  105548. ch[t1<<1]=cc[t1]+cc[t2];
  105549. ch[(t1<<1)+t3-1]=cc[t1]-cc[t2];
  105550. t1+=ido;
  105551. t2+=ido;
  105552. }
  105553. if(ido<2)return;
  105554. if(ido==2)goto L105;
  105555. t1=0;
  105556. t2=t0;
  105557. for(k=0;k<l1;k++){
  105558. t3=t2;
  105559. t4=(t1<<1)+(ido<<1);
  105560. t5=t1;
  105561. t6=t1+t1;
  105562. for(i=2;i<ido;i+=2){
  105563. t3+=2;
  105564. t4-=2;
  105565. t5+=2;
  105566. t6+=2;
  105567. tr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105568. ti2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105569. ch[t6]=cc[t5]+ti2;
  105570. ch[t4]=ti2-cc[t5];
  105571. ch[t6-1]=cc[t5-1]+tr2;
  105572. ch[t4-1]=cc[t5-1]-tr2;
  105573. }
  105574. t1+=ido;
  105575. t2+=ido;
  105576. }
  105577. if(ido%2==1)return;
  105578. L105:
  105579. t3=(t2=(t1=ido)-1);
  105580. t2+=t0;
  105581. for(k=0;k<l1;k++){
  105582. ch[t1]=-cc[t2];
  105583. ch[t1-1]=cc[t3];
  105584. t1+=ido<<1;
  105585. t2+=ido;
  105586. t3+=ido;
  105587. }
  105588. }
  105589. static void dradf4(int ido,int l1,float *cc,float *ch,float *wa1,
  105590. float *wa2,float *wa3){
  105591. static float hsqt2 = .70710678118654752f;
  105592. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105593. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  105594. t0=l1*ido;
  105595. t1=t0;
  105596. t4=t1<<1;
  105597. t2=t1+(t1<<1);
  105598. t3=0;
  105599. for(k=0;k<l1;k++){
  105600. tr1=cc[t1]+cc[t2];
  105601. tr2=cc[t3]+cc[t4];
  105602. ch[t5=t3<<2]=tr1+tr2;
  105603. ch[(ido<<2)+t5-1]=tr2-tr1;
  105604. ch[(t5+=(ido<<1))-1]=cc[t3]-cc[t4];
  105605. ch[t5]=cc[t2]-cc[t1];
  105606. t1+=ido;
  105607. t2+=ido;
  105608. t3+=ido;
  105609. t4+=ido;
  105610. }
  105611. if(ido<2)return;
  105612. if(ido==2)goto L105;
  105613. t1=0;
  105614. for(k=0;k<l1;k++){
  105615. t2=t1;
  105616. t4=t1<<2;
  105617. t5=(t6=ido<<1)+t4;
  105618. for(i=2;i<ido;i+=2){
  105619. t3=(t2+=2);
  105620. t4+=2;
  105621. t5-=2;
  105622. t3+=t0;
  105623. cr2=wa1[i-2]*cc[t3-1]+wa1[i-1]*cc[t3];
  105624. ci2=wa1[i-2]*cc[t3]-wa1[i-1]*cc[t3-1];
  105625. t3+=t0;
  105626. cr3=wa2[i-2]*cc[t3-1]+wa2[i-1]*cc[t3];
  105627. ci3=wa2[i-2]*cc[t3]-wa2[i-1]*cc[t3-1];
  105628. t3+=t0;
  105629. cr4=wa3[i-2]*cc[t3-1]+wa3[i-1]*cc[t3];
  105630. ci4=wa3[i-2]*cc[t3]-wa3[i-1]*cc[t3-1];
  105631. tr1=cr2+cr4;
  105632. tr4=cr4-cr2;
  105633. ti1=ci2+ci4;
  105634. ti4=ci2-ci4;
  105635. ti2=cc[t2]+ci3;
  105636. ti3=cc[t2]-ci3;
  105637. tr2=cc[t2-1]+cr3;
  105638. tr3=cc[t2-1]-cr3;
  105639. ch[t4-1]=tr1+tr2;
  105640. ch[t4]=ti1+ti2;
  105641. ch[t5-1]=tr3-ti4;
  105642. ch[t5]=tr4-ti3;
  105643. ch[t4+t6-1]=ti4+tr3;
  105644. ch[t4+t6]=tr4+ti3;
  105645. ch[t5+t6-1]=tr2-tr1;
  105646. ch[t5+t6]=ti1-ti2;
  105647. }
  105648. t1+=ido;
  105649. }
  105650. if(ido&1)return;
  105651. L105:
  105652. t2=(t1=t0+ido-1)+(t0<<1);
  105653. t3=ido<<2;
  105654. t4=ido;
  105655. t5=ido<<1;
  105656. t6=ido;
  105657. for(k=0;k<l1;k++){
  105658. ti1=-hsqt2*(cc[t1]+cc[t2]);
  105659. tr1=hsqt2*(cc[t1]-cc[t2]);
  105660. ch[t4-1]=tr1+cc[t6-1];
  105661. ch[t4+t5-1]=cc[t6-1]-tr1;
  105662. ch[t4]=ti1-cc[t1+t0];
  105663. ch[t4+t5]=ti1+cc[t1+t0];
  105664. t1+=ido;
  105665. t2+=ido;
  105666. t4+=t3;
  105667. t6+=ido;
  105668. }
  105669. }
  105670. static void dradfg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  105671. float *c2,float *ch,float *ch2,float *wa){
  105672. static float tpi=6.283185307179586f;
  105673. int idij,ipph,i,j,k,l,ic,ik,is;
  105674. int t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  105675. float dc2,ai1,ai2,ar1,ar2,ds2;
  105676. int nbd;
  105677. float dcp,arg,dsp,ar1h,ar2h;
  105678. int idp2,ipp2;
  105679. arg=tpi/(float)ip;
  105680. dcp=cos(arg);
  105681. dsp=sin(arg);
  105682. ipph=(ip+1)>>1;
  105683. ipp2=ip;
  105684. idp2=ido;
  105685. nbd=(ido-1)>>1;
  105686. t0=l1*ido;
  105687. t10=ip*ido;
  105688. if(ido==1)goto L119;
  105689. for(ik=0;ik<idl1;ik++)ch2[ik]=c2[ik];
  105690. t1=0;
  105691. for(j=1;j<ip;j++){
  105692. t1+=t0;
  105693. t2=t1;
  105694. for(k=0;k<l1;k++){
  105695. ch[t2]=c1[t2];
  105696. t2+=ido;
  105697. }
  105698. }
  105699. is=-ido;
  105700. t1=0;
  105701. if(nbd>l1){
  105702. for(j=1;j<ip;j++){
  105703. t1+=t0;
  105704. is+=ido;
  105705. t2= -ido+t1;
  105706. for(k=0;k<l1;k++){
  105707. idij=is-1;
  105708. t2+=ido;
  105709. t3=t2;
  105710. for(i=2;i<ido;i+=2){
  105711. idij+=2;
  105712. t3+=2;
  105713. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105714. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105715. }
  105716. }
  105717. }
  105718. }else{
  105719. for(j=1;j<ip;j++){
  105720. is+=ido;
  105721. idij=is-1;
  105722. t1+=t0;
  105723. t2=t1;
  105724. for(i=2;i<ido;i+=2){
  105725. idij+=2;
  105726. t2+=2;
  105727. t3=t2;
  105728. for(k=0;k<l1;k++){
  105729. ch[t3-1]=wa[idij-1]*c1[t3-1]+wa[idij]*c1[t3];
  105730. ch[t3]=wa[idij-1]*c1[t3]-wa[idij]*c1[t3-1];
  105731. t3+=ido;
  105732. }
  105733. }
  105734. }
  105735. }
  105736. t1=0;
  105737. t2=ipp2*t0;
  105738. if(nbd<l1){
  105739. for(j=1;j<ipph;j++){
  105740. t1+=t0;
  105741. t2-=t0;
  105742. t3=t1;
  105743. t4=t2;
  105744. for(i=2;i<ido;i+=2){
  105745. t3+=2;
  105746. t4+=2;
  105747. t5=t3-ido;
  105748. t6=t4-ido;
  105749. for(k=0;k<l1;k++){
  105750. t5+=ido;
  105751. t6+=ido;
  105752. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105753. c1[t6-1]=ch[t5]-ch[t6];
  105754. c1[t5]=ch[t5]+ch[t6];
  105755. c1[t6]=ch[t6-1]-ch[t5-1];
  105756. }
  105757. }
  105758. }
  105759. }else{
  105760. for(j=1;j<ipph;j++){
  105761. t1+=t0;
  105762. t2-=t0;
  105763. t3=t1;
  105764. t4=t2;
  105765. for(k=0;k<l1;k++){
  105766. t5=t3;
  105767. t6=t4;
  105768. for(i=2;i<ido;i+=2){
  105769. t5+=2;
  105770. t6+=2;
  105771. c1[t5-1]=ch[t5-1]+ch[t6-1];
  105772. c1[t6-1]=ch[t5]-ch[t6];
  105773. c1[t5]=ch[t5]+ch[t6];
  105774. c1[t6]=ch[t6-1]-ch[t5-1];
  105775. }
  105776. t3+=ido;
  105777. t4+=ido;
  105778. }
  105779. }
  105780. }
  105781. L119:
  105782. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  105783. t1=0;
  105784. t2=ipp2*idl1;
  105785. for(j=1;j<ipph;j++){
  105786. t1+=t0;
  105787. t2-=t0;
  105788. t3=t1-ido;
  105789. t4=t2-ido;
  105790. for(k=0;k<l1;k++){
  105791. t3+=ido;
  105792. t4+=ido;
  105793. c1[t3]=ch[t3]+ch[t4];
  105794. c1[t4]=ch[t4]-ch[t3];
  105795. }
  105796. }
  105797. ar1=1.f;
  105798. ai1=0.f;
  105799. t1=0;
  105800. t2=ipp2*idl1;
  105801. t3=(ip-1)*idl1;
  105802. for(l=1;l<ipph;l++){
  105803. t1+=idl1;
  105804. t2-=idl1;
  105805. ar1h=dcp*ar1-dsp*ai1;
  105806. ai1=dcp*ai1+dsp*ar1;
  105807. ar1=ar1h;
  105808. t4=t1;
  105809. t5=t2;
  105810. t6=t3;
  105811. t7=idl1;
  105812. for(ik=0;ik<idl1;ik++){
  105813. ch2[t4++]=c2[ik]+ar1*c2[t7++];
  105814. ch2[t5++]=ai1*c2[t6++];
  105815. }
  105816. dc2=ar1;
  105817. ds2=ai1;
  105818. ar2=ar1;
  105819. ai2=ai1;
  105820. t4=idl1;
  105821. t5=(ipp2-1)*idl1;
  105822. for(j=2;j<ipph;j++){
  105823. t4+=idl1;
  105824. t5-=idl1;
  105825. ar2h=dc2*ar2-ds2*ai2;
  105826. ai2=dc2*ai2+ds2*ar2;
  105827. ar2=ar2h;
  105828. t6=t1;
  105829. t7=t2;
  105830. t8=t4;
  105831. t9=t5;
  105832. for(ik=0;ik<idl1;ik++){
  105833. ch2[t6++]+=ar2*c2[t8++];
  105834. ch2[t7++]+=ai2*c2[t9++];
  105835. }
  105836. }
  105837. }
  105838. t1=0;
  105839. for(j=1;j<ipph;j++){
  105840. t1+=idl1;
  105841. t2=t1;
  105842. for(ik=0;ik<idl1;ik++)ch2[ik]+=c2[t2++];
  105843. }
  105844. if(ido<l1)goto L132;
  105845. t1=0;
  105846. t2=0;
  105847. for(k=0;k<l1;k++){
  105848. t3=t1;
  105849. t4=t2;
  105850. for(i=0;i<ido;i++)cc[t4++]=ch[t3++];
  105851. t1+=ido;
  105852. t2+=t10;
  105853. }
  105854. goto L135;
  105855. L132:
  105856. for(i=0;i<ido;i++){
  105857. t1=i;
  105858. t2=i;
  105859. for(k=0;k<l1;k++){
  105860. cc[t2]=ch[t1];
  105861. t1+=ido;
  105862. t2+=t10;
  105863. }
  105864. }
  105865. L135:
  105866. t1=0;
  105867. t2=ido<<1;
  105868. t3=0;
  105869. t4=ipp2*t0;
  105870. for(j=1;j<ipph;j++){
  105871. t1+=t2;
  105872. t3+=t0;
  105873. t4-=t0;
  105874. t5=t1;
  105875. t6=t3;
  105876. t7=t4;
  105877. for(k=0;k<l1;k++){
  105878. cc[t5-1]=ch[t6];
  105879. cc[t5]=ch[t7];
  105880. t5+=t10;
  105881. t6+=ido;
  105882. t7+=ido;
  105883. }
  105884. }
  105885. if(ido==1)return;
  105886. if(nbd<l1)goto L141;
  105887. t1=-ido;
  105888. t3=0;
  105889. t4=0;
  105890. t5=ipp2*t0;
  105891. for(j=1;j<ipph;j++){
  105892. t1+=t2;
  105893. t3+=t2;
  105894. t4+=t0;
  105895. t5-=t0;
  105896. t6=t1;
  105897. t7=t3;
  105898. t8=t4;
  105899. t9=t5;
  105900. for(k=0;k<l1;k++){
  105901. for(i=2;i<ido;i+=2){
  105902. ic=idp2-i;
  105903. cc[i+t7-1]=ch[i+t8-1]+ch[i+t9-1];
  105904. cc[ic+t6-1]=ch[i+t8-1]-ch[i+t9-1];
  105905. cc[i+t7]=ch[i+t8]+ch[i+t9];
  105906. cc[ic+t6]=ch[i+t9]-ch[i+t8];
  105907. }
  105908. t6+=t10;
  105909. t7+=t10;
  105910. t8+=ido;
  105911. t9+=ido;
  105912. }
  105913. }
  105914. return;
  105915. L141:
  105916. t1=-ido;
  105917. t3=0;
  105918. t4=0;
  105919. t5=ipp2*t0;
  105920. for(j=1;j<ipph;j++){
  105921. t1+=t2;
  105922. t3+=t2;
  105923. t4+=t0;
  105924. t5-=t0;
  105925. for(i=2;i<ido;i+=2){
  105926. t6=idp2+t1-i;
  105927. t7=i+t3;
  105928. t8=i+t4;
  105929. t9=i+t5;
  105930. for(k=0;k<l1;k++){
  105931. cc[t7-1]=ch[t8-1]+ch[t9-1];
  105932. cc[t6-1]=ch[t8-1]-ch[t9-1];
  105933. cc[t7]=ch[t8]+ch[t9];
  105934. cc[t6]=ch[t9]-ch[t8];
  105935. t6+=t10;
  105936. t7+=t10;
  105937. t8+=ido;
  105938. t9+=ido;
  105939. }
  105940. }
  105941. }
  105942. }
  105943. static void drftf1(int n,float *c,float *ch,float *wa,int *ifac){
  105944. int i,k1,l1,l2;
  105945. int na,kh,nf;
  105946. int ip,iw,ido,idl1,ix2,ix3;
  105947. nf=ifac[1];
  105948. na=1;
  105949. l2=n;
  105950. iw=n;
  105951. for(k1=0;k1<nf;k1++){
  105952. kh=nf-k1;
  105953. ip=ifac[kh+1];
  105954. l1=l2/ip;
  105955. ido=n/l2;
  105956. idl1=ido*l1;
  105957. iw-=(ip-1)*ido;
  105958. na=1-na;
  105959. if(ip!=4)goto L102;
  105960. ix2=iw+ido;
  105961. ix3=ix2+ido;
  105962. if(na!=0)
  105963. dradf4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105964. else
  105965. dradf4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  105966. goto L110;
  105967. L102:
  105968. if(ip!=2)goto L104;
  105969. if(na!=0)goto L103;
  105970. dradf2(ido,l1,c,ch,wa+iw-1);
  105971. goto L110;
  105972. L103:
  105973. dradf2(ido,l1,ch,c,wa+iw-1);
  105974. goto L110;
  105975. L104:
  105976. if(ido==1)na=1-na;
  105977. if(na!=0)goto L109;
  105978. dradfg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  105979. na=1;
  105980. goto L110;
  105981. L109:
  105982. dradfg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  105983. na=0;
  105984. L110:
  105985. l2=l1;
  105986. }
  105987. if(na==1)return;
  105988. for(i=0;i<n;i++)c[i]=ch[i];
  105989. }
  105990. static void dradb2(int ido,int l1,float *cc,float *ch,float *wa1){
  105991. int i,k,t0,t1,t2,t3,t4,t5,t6;
  105992. float ti2,tr2;
  105993. t0=l1*ido;
  105994. t1=0;
  105995. t2=0;
  105996. t3=(ido<<1)-1;
  105997. for(k=0;k<l1;k++){
  105998. ch[t1]=cc[t2]+cc[t3+t2];
  105999. ch[t1+t0]=cc[t2]-cc[t3+t2];
  106000. t2=(t1+=ido)<<1;
  106001. }
  106002. if(ido<2)return;
  106003. if(ido==2)goto L105;
  106004. t1=0;
  106005. t2=0;
  106006. for(k=0;k<l1;k++){
  106007. t3=t1;
  106008. t5=(t4=t2)+(ido<<1);
  106009. t6=t0+t1;
  106010. for(i=2;i<ido;i+=2){
  106011. t3+=2;
  106012. t4+=2;
  106013. t5-=2;
  106014. t6+=2;
  106015. ch[t3-1]=cc[t4-1]+cc[t5-1];
  106016. tr2=cc[t4-1]-cc[t5-1];
  106017. ch[t3]=cc[t4]-cc[t5];
  106018. ti2=cc[t4]+cc[t5];
  106019. ch[t6-1]=wa1[i-2]*tr2-wa1[i-1]*ti2;
  106020. ch[t6]=wa1[i-2]*ti2+wa1[i-1]*tr2;
  106021. }
  106022. t2=(t1+=ido)<<1;
  106023. }
  106024. if(ido%2==1)return;
  106025. L105:
  106026. t1=ido-1;
  106027. t2=ido-1;
  106028. for(k=0;k<l1;k++){
  106029. ch[t1]=cc[t2]+cc[t2];
  106030. ch[t1+t0]=-(cc[t2+1]+cc[t2+1]);
  106031. t1+=ido;
  106032. t2+=ido<<1;
  106033. }
  106034. }
  106035. static void dradb3(int ido,int l1,float *cc,float *ch,float *wa1,
  106036. float *wa2){
  106037. static float taur = -.5f;
  106038. static float taui = .8660254037844386f;
  106039. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10;
  106040. float ci2,ci3,di2,di3,cr2,cr3,dr2,dr3,ti2,tr2;
  106041. t0=l1*ido;
  106042. t1=0;
  106043. t2=t0<<1;
  106044. t3=ido<<1;
  106045. t4=ido+(ido<<1);
  106046. t5=0;
  106047. for(k=0;k<l1;k++){
  106048. tr2=cc[t3-1]+cc[t3-1];
  106049. cr2=cc[t5]+(taur*tr2);
  106050. ch[t1]=cc[t5]+tr2;
  106051. ci3=taui*(cc[t3]+cc[t3]);
  106052. ch[t1+t0]=cr2-ci3;
  106053. ch[t1+t2]=cr2+ci3;
  106054. t1+=ido;
  106055. t3+=t4;
  106056. t5+=t4;
  106057. }
  106058. if(ido==1)return;
  106059. t1=0;
  106060. t3=ido<<1;
  106061. for(k=0;k<l1;k++){
  106062. t7=t1+(t1<<1);
  106063. t6=(t5=t7+t3);
  106064. t8=t1;
  106065. t10=(t9=t1+t0)+t0;
  106066. for(i=2;i<ido;i+=2){
  106067. t5+=2;
  106068. t6-=2;
  106069. t7+=2;
  106070. t8+=2;
  106071. t9+=2;
  106072. t10+=2;
  106073. tr2=cc[t5-1]+cc[t6-1];
  106074. cr2=cc[t7-1]+(taur*tr2);
  106075. ch[t8-1]=cc[t7-1]+tr2;
  106076. ti2=cc[t5]-cc[t6];
  106077. ci2=cc[t7]+(taur*ti2);
  106078. ch[t8]=cc[t7]+ti2;
  106079. cr3=taui*(cc[t5-1]-cc[t6-1]);
  106080. ci3=taui*(cc[t5]+cc[t6]);
  106081. dr2=cr2-ci3;
  106082. dr3=cr2+ci3;
  106083. di2=ci2+cr3;
  106084. di3=ci2-cr3;
  106085. ch[t9-1]=wa1[i-2]*dr2-wa1[i-1]*di2;
  106086. ch[t9]=wa1[i-2]*di2+wa1[i-1]*dr2;
  106087. ch[t10-1]=wa2[i-2]*dr3-wa2[i-1]*di3;
  106088. ch[t10]=wa2[i-2]*di3+wa2[i-1]*dr3;
  106089. }
  106090. t1+=ido;
  106091. }
  106092. }
  106093. static void dradb4(int ido,int l1,float *cc,float *ch,float *wa1,
  106094. float *wa2,float *wa3){
  106095. static float sqrt2=1.414213562373095f;
  106096. int i,k,t0,t1,t2,t3,t4,t5,t6,t7,t8;
  106097. float ci2,ci3,ci4,cr2,cr3,cr4,ti1,ti2,ti3,ti4,tr1,tr2,tr3,tr4;
  106098. t0=l1*ido;
  106099. t1=0;
  106100. t2=ido<<2;
  106101. t3=0;
  106102. t6=ido<<1;
  106103. for(k=0;k<l1;k++){
  106104. t4=t3+t6;
  106105. t5=t1;
  106106. tr3=cc[t4-1]+cc[t4-1];
  106107. tr4=cc[t4]+cc[t4];
  106108. tr1=cc[t3]-cc[(t4+=t6)-1];
  106109. tr2=cc[t3]+cc[t4-1];
  106110. ch[t5]=tr2+tr3;
  106111. ch[t5+=t0]=tr1-tr4;
  106112. ch[t5+=t0]=tr2-tr3;
  106113. ch[t5+=t0]=tr1+tr4;
  106114. t1+=ido;
  106115. t3+=t2;
  106116. }
  106117. if(ido<2)return;
  106118. if(ido==2)goto L105;
  106119. t1=0;
  106120. for(k=0;k<l1;k++){
  106121. t5=(t4=(t3=(t2=t1<<2)+t6))+t6;
  106122. t7=t1;
  106123. for(i=2;i<ido;i+=2){
  106124. t2+=2;
  106125. t3+=2;
  106126. t4-=2;
  106127. t5-=2;
  106128. t7+=2;
  106129. ti1=cc[t2]+cc[t5];
  106130. ti2=cc[t2]-cc[t5];
  106131. ti3=cc[t3]-cc[t4];
  106132. tr4=cc[t3]+cc[t4];
  106133. tr1=cc[t2-1]-cc[t5-1];
  106134. tr2=cc[t2-1]+cc[t5-1];
  106135. ti4=cc[t3-1]-cc[t4-1];
  106136. tr3=cc[t3-1]+cc[t4-1];
  106137. ch[t7-1]=tr2+tr3;
  106138. cr3=tr2-tr3;
  106139. ch[t7]=ti2+ti3;
  106140. ci3=ti2-ti3;
  106141. cr2=tr1-tr4;
  106142. cr4=tr1+tr4;
  106143. ci2=ti1+ti4;
  106144. ci4=ti1-ti4;
  106145. ch[(t8=t7+t0)-1]=wa1[i-2]*cr2-wa1[i-1]*ci2;
  106146. ch[t8]=wa1[i-2]*ci2+wa1[i-1]*cr2;
  106147. ch[(t8+=t0)-1]=wa2[i-2]*cr3-wa2[i-1]*ci3;
  106148. ch[t8]=wa2[i-2]*ci3+wa2[i-1]*cr3;
  106149. ch[(t8+=t0)-1]=wa3[i-2]*cr4-wa3[i-1]*ci4;
  106150. ch[t8]=wa3[i-2]*ci4+wa3[i-1]*cr4;
  106151. }
  106152. t1+=ido;
  106153. }
  106154. if(ido%2 == 1)return;
  106155. L105:
  106156. t1=ido;
  106157. t2=ido<<2;
  106158. t3=ido-1;
  106159. t4=ido+(ido<<1);
  106160. for(k=0;k<l1;k++){
  106161. t5=t3;
  106162. ti1=cc[t1]+cc[t4];
  106163. ti2=cc[t4]-cc[t1];
  106164. tr1=cc[t1-1]-cc[t4-1];
  106165. tr2=cc[t1-1]+cc[t4-1];
  106166. ch[t5]=tr2+tr2;
  106167. ch[t5+=t0]=sqrt2*(tr1-ti1);
  106168. ch[t5+=t0]=ti2+ti2;
  106169. ch[t5+=t0]=-sqrt2*(tr1+ti1);
  106170. t3+=ido;
  106171. t1+=t2;
  106172. t4+=t2;
  106173. }
  106174. }
  106175. static void dradbg(int ido,int ip,int l1,int idl1,float *cc,float *c1,
  106176. float *c2,float *ch,float *ch2,float *wa){
  106177. static float tpi=6.283185307179586f;
  106178. int idij,ipph,i,j,k,l,ik,is,t0,t1,t2,t3,t4,t5,t6,t7,t8,t9,t10,
  106179. t11,t12;
  106180. float dc2,ai1,ai2,ar1,ar2,ds2;
  106181. int nbd;
  106182. float dcp,arg,dsp,ar1h,ar2h;
  106183. int ipp2;
  106184. t10=ip*ido;
  106185. t0=l1*ido;
  106186. arg=tpi/(float)ip;
  106187. dcp=cos(arg);
  106188. dsp=sin(arg);
  106189. nbd=(ido-1)>>1;
  106190. ipp2=ip;
  106191. ipph=(ip+1)>>1;
  106192. if(ido<l1)goto L103;
  106193. t1=0;
  106194. t2=0;
  106195. for(k=0;k<l1;k++){
  106196. t3=t1;
  106197. t4=t2;
  106198. for(i=0;i<ido;i++){
  106199. ch[t3]=cc[t4];
  106200. t3++;
  106201. t4++;
  106202. }
  106203. t1+=ido;
  106204. t2+=t10;
  106205. }
  106206. goto L106;
  106207. L103:
  106208. t1=0;
  106209. for(i=0;i<ido;i++){
  106210. t2=t1;
  106211. t3=t1;
  106212. for(k=0;k<l1;k++){
  106213. ch[t2]=cc[t3];
  106214. t2+=ido;
  106215. t3+=t10;
  106216. }
  106217. t1++;
  106218. }
  106219. L106:
  106220. t1=0;
  106221. t2=ipp2*t0;
  106222. t7=(t5=ido<<1);
  106223. for(j=1;j<ipph;j++){
  106224. t1+=t0;
  106225. t2-=t0;
  106226. t3=t1;
  106227. t4=t2;
  106228. t6=t5;
  106229. for(k=0;k<l1;k++){
  106230. ch[t3]=cc[t6-1]+cc[t6-1];
  106231. ch[t4]=cc[t6]+cc[t6];
  106232. t3+=ido;
  106233. t4+=ido;
  106234. t6+=t10;
  106235. }
  106236. t5+=t7;
  106237. }
  106238. if (ido == 1)goto L116;
  106239. if(nbd<l1)goto L112;
  106240. t1=0;
  106241. t2=ipp2*t0;
  106242. t7=0;
  106243. for(j=1;j<ipph;j++){
  106244. t1+=t0;
  106245. t2-=t0;
  106246. t3=t1;
  106247. t4=t2;
  106248. t7+=(ido<<1);
  106249. t8=t7;
  106250. for(k=0;k<l1;k++){
  106251. t5=t3;
  106252. t6=t4;
  106253. t9=t8;
  106254. t11=t8;
  106255. for(i=2;i<ido;i+=2){
  106256. t5+=2;
  106257. t6+=2;
  106258. t9+=2;
  106259. t11-=2;
  106260. ch[t5-1]=cc[t9-1]+cc[t11-1];
  106261. ch[t6-1]=cc[t9-1]-cc[t11-1];
  106262. ch[t5]=cc[t9]-cc[t11];
  106263. ch[t6]=cc[t9]+cc[t11];
  106264. }
  106265. t3+=ido;
  106266. t4+=ido;
  106267. t8+=t10;
  106268. }
  106269. }
  106270. goto L116;
  106271. L112:
  106272. t1=0;
  106273. t2=ipp2*t0;
  106274. t7=0;
  106275. for(j=1;j<ipph;j++){
  106276. t1+=t0;
  106277. t2-=t0;
  106278. t3=t1;
  106279. t4=t2;
  106280. t7+=(ido<<1);
  106281. t8=t7;
  106282. t9=t7;
  106283. for(i=2;i<ido;i+=2){
  106284. t3+=2;
  106285. t4+=2;
  106286. t8+=2;
  106287. t9-=2;
  106288. t5=t3;
  106289. t6=t4;
  106290. t11=t8;
  106291. t12=t9;
  106292. for(k=0;k<l1;k++){
  106293. ch[t5-1]=cc[t11-1]+cc[t12-1];
  106294. ch[t6-1]=cc[t11-1]-cc[t12-1];
  106295. ch[t5]=cc[t11]-cc[t12];
  106296. ch[t6]=cc[t11]+cc[t12];
  106297. t5+=ido;
  106298. t6+=ido;
  106299. t11+=t10;
  106300. t12+=t10;
  106301. }
  106302. }
  106303. }
  106304. L116:
  106305. ar1=1.f;
  106306. ai1=0.f;
  106307. t1=0;
  106308. t9=(t2=ipp2*idl1);
  106309. t3=(ip-1)*idl1;
  106310. for(l=1;l<ipph;l++){
  106311. t1+=idl1;
  106312. t2-=idl1;
  106313. ar1h=dcp*ar1-dsp*ai1;
  106314. ai1=dcp*ai1+dsp*ar1;
  106315. ar1=ar1h;
  106316. t4=t1;
  106317. t5=t2;
  106318. t6=0;
  106319. t7=idl1;
  106320. t8=t3;
  106321. for(ik=0;ik<idl1;ik++){
  106322. c2[t4++]=ch2[t6++]+ar1*ch2[t7++];
  106323. c2[t5++]=ai1*ch2[t8++];
  106324. }
  106325. dc2=ar1;
  106326. ds2=ai1;
  106327. ar2=ar1;
  106328. ai2=ai1;
  106329. t6=idl1;
  106330. t7=t9-idl1;
  106331. for(j=2;j<ipph;j++){
  106332. t6+=idl1;
  106333. t7-=idl1;
  106334. ar2h=dc2*ar2-ds2*ai2;
  106335. ai2=dc2*ai2+ds2*ar2;
  106336. ar2=ar2h;
  106337. t4=t1;
  106338. t5=t2;
  106339. t11=t6;
  106340. t12=t7;
  106341. for(ik=0;ik<idl1;ik++){
  106342. c2[t4++]+=ar2*ch2[t11++];
  106343. c2[t5++]+=ai2*ch2[t12++];
  106344. }
  106345. }
  106346. }
  106347. t1=0;
  106348. for(j=1;j<ipph;j++){
  106349. t1+=idl1;
  106350. t2=t1;
  106351. for(ik=0;ik<idl1;ik++)ch2[ik]+=ch2[t2++];
  106352. }
  106353. t1=0;
  106354. t2=ipp2*t0;
  106355. for(j=1;j<ipph;j++){
  106356. t1+=t0;
  106357. t2-=t0;
  106358. t3=t1;
  106359. t4=t2;
  106360. for(k=0;k<l1;k++){
  106361. ch[t3]=c1[t3]-c1[t4];
  106362. ch[t4]=c1[t3]+c1[t4];
  106363. t3+=ido;
  106364. t4+=ido;
  106365. }
  106366. }
  106367. if(ido==1)goto L132;
  106368. if(nbd<l1)goto L128;
  106369. t1=0;
  106370. t2=ipp2*t0;
  106371. for(j=1;j<ipph;j++){
  106372. t1+=t0;
  106373. t2-=t0;
  106374. t3=t1;
  106375. t4=t2;
  106376. for(k=0;k<l1;k++){
  106377. t5=t3;
  106378. t6=t4;
  106379. for(i=2;i<ido;i+=2){
  106380. t5+=2;
  106381. t6+=2;
  106382. ch[t5-1]=c1[t5-1]-c1[t6];
  106383. ch[t6-1]=c1[t5-1]+c1[t6];
  106384. ch[t5]=c1[t5]+c1[t6-1];
  106385. ch[t6]=c1[t5]-c1[t6-1];
  106386. }
  106387. t3+=ido;
  106388. t4+=ido;
  106389. }
  106390. }
  106391. goto L132;
  106392. L128:
  106393. t1=0;
  106394. t2=ipp2*t0;
  106395. for(j=1;j<ipph;j++){
  106396. t1+=t0;
  106397. t2-=t0;
  106398. t3=t1;
  106399. t4=t2;
  106400. for(i=2;i<ido;i+=2){
  106401. t3+=2;
  106402. t4+=2;
  106403. t5=t3;
  106404. t6=t4;
  106405. for(k=0;k<l1;k++){
  106406. ch[t5-1]=c1[t5-1]-c1[t6];
  106407. ch[t6-1]=c1[t5-1]+c1[t6];
  106408. ch[t5]=c1[t5]+c1[t6-1];
  106409. ch[t6]=c1[t5]-c1[t6-1];
  106410. t5+=ido;
  106411. t6+=ido;
  106412. }
  106413. }
  106414. }
  106415. L132:
  106416. if(ido==1)return;
  106417. for(ik=0;ik<idl1;ik++)c2[ik]=ch2[ik];
  106418. t1=0;
  106419. for(j=1;j<ip;j++){
  106420. t2=(t1+=t0);
  106421. for(k=0;k<l1;k++){
  106422. c1[t2]=ch[t2];
  106423. t2+=ido;
  106424. }
  106425. }
  106426. if(nbd>l1)goto L139;
  106427. is= -ido-1;
  106428. t1=0;
  106429. for(j=1;j<ip;j++){
  106430. is+=ido;
  106431. t1+=t0;
  106432. idij=is;
  106433. t2=t1;
  106434. for(i=2;i<ido;i+=2){
  106435. t2+=2;
  106436. idij+=2;
  106437. t3=t2;
  106438. for(k=0;k<l1;k++){
  106439. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106440. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106441. t3+=ido;
  106442. }
  106443. }
  106444. }
  106445. return;
  106446. L139:
  106447. is= -ido-1;
  106448. t1=0;
  106449. for(j=1;j<ip;j++){
  106450. is+=ido;
  106451. t1+=t0;
  106452. t2=t1;
  106453. for(k=0;k<l1;k++){
  106454. idij=is;
  106455. t3=t2;
  106456. for(i=2;i<ido;i+=2){
  106457. idij+=2;
  106458. t3+=2;
  106459. c1[t3-1]=wa[idij-1]*ch[t3-1]-wa[idij]*ch[t3];
  106460. c1[t3]=wa[idij-1]*ch[t3]+wa[idij]*ch[t3-1];
  106461. }
  106462. t2+=ido;
  106463. }
  106464. }
  106465. }
  106466. static void drftb1(int n, float *c, float *ch, float *wa, int *ifac){
  106467. int i,k1,l1,l2;
  106468. int na;
  106469. int nf,ip,iw,ix2,ix3,ido,idl1;
  106470. nf=ifac[1];
  106471. na=0;
  106472. l1=1;
  106473. iw=1;
  106474. for(k1=0;k1<nf;k1++){
  106475. ip=ifac[k1 + 2];
  106476. l2=ip*l1;
  106477. ido=n/l2;
  106478. idl1=ido*l1;
  106479. if(ip!=4)goto L103;
  106480. ix2=iw+ido;
  106481. ix3=ix2+ido;
  106482. if(na!=0)
  106483. dradb4(ido,l1,ch,c,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106484. else
  106485. dradb4(ido,l1,c,ch,wa+iw-1,wa+ix2-1,wa+ix3-1);
  106486. na=1-na;
  106487. goto L115;
  106488. L103:
  106489. if(ip!=2)goto L106;
  106490. if(na!=0)
  106491. dradb2(ido,l1,ch,c,wa+iw-1);
  106492. else
  106493. dradb2(ido,l1,c,ch,wa+iw-1);
  106494. na=1-na;
  106495. goto L115;
  106496. L106:
  106497. if(ip!=3)goto L109;
  106498. ix2=iw+ido;
  106499. if(na!=0)
  106500. dradb3(ido,l1,ch,c,wa+iw-1,wa+ix2-1);
  106501. else
  106502. dradb3(ido,l1,c,ch,wa+iw-1,wa+ix2-1);
  106503. na=1-na;
  106504. goto L115;
  106505. L109:
  106506. if(na!=0)
  106507. dradbg(ido,ip,l1,idl1,ch,ch,ch,c,c,wa+iw-1);
  106508. else
  106509. dradbg(ido,ip,l1,idl1,c,c,c,ch,ch,wa+iw-1);
  106510. if(ido==1)na=1-na;
  106511. L115:
  106512. l1=l2;
  106513. iw+=(ip-1)*ido;
  106514. }
  106515. if(na==0)return;
  106516. for(i=0;i<n;i++)c[i]=ch[i];
  106517. }
  106518. void drft_forward(drft_lookup *l,float *data){
  106519. if(l->n==1)return;
  106520. drftf1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106521. }
  106522. void drft_backward(drft_lookup *l,float *data){
  106523. if (l->n==1)return;
  106524. drftb1(l->n,data,l->trigcache,l->trigcache+l->n,l->splitcache);
  106525. }
  106526. void drft_init(drft_lookup *l,int n){
  106527. l->n=n;
  106528. l->trigcache=(float*)_ogg_calloc(3*n,sizeof(*l->trigcache));
  106529. l->splitcache=(int*)_ogg_calloc(32,sizeof(*l->splitcache));
  106530. fdrffti(n, l->trigcache, l->splitcache);
  106531. }
  106532. void drft_clear(drft_lookup *l){
  106533. if(l){
  106534. if(l->trigcache)_ogg_free(l->trigcache);
  106535. if(l->splitcache)_ogg_free(l->splitcache);
  106536. memset(l,0,sizeof(*l));
  106537. }
  106538. }
  106539. #endif
  106540. /*** End of inlined file: smallft.c ***/
  106541. /*** Start of inlined file: synthesis.c ***/
  106542. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106543. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106544. // tasks..
  106545. #if JUCE_MSVC
  106546. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106547. #endif
  106548. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106549. #if JUCE_USE_OGGVORBIS
  106550. #include <stdio.h>
  106551. int vorbis_synthesis(vorbis_block *vb,ogg_packet *op){
  106552. vorbis_dsp_state *vd=vb->vd;
  106553. private_state *b=(private_state*)vd->backend_state;
  106554. vorbis_info *vi=vd->vi;
  106555. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  106556. oggpack_buffer *opb=&vb->opb;
  106557. int type,mode,i;
  106558. _vorbis_block_ripcord(vb);
  106559. oggpack_readinit(opb,op->packet,op->bytes);
  106560. if(oggpack_read(opb,1)!=0){
  106561. return(OV_ENOTAUDIO);
  106562. }
  106563. mode=oggpack_read(opb,b->modebits);
  106564. if(mode==-1)return(OV_EBADPACKET);
  106565. vb->mode=mode;
  106566. vb->W=ci->mode_param[mode]->blockflag;
  106567. if(vb->W){
  106568. vb->lW=oggpack_read(opb,1);
  106569. vb->nW=oggpack_read(opb,1);
  106570. if(vb->nW==-1) return(OV_EBADPACKET);
  106571. }else{
  106572. vb->lW=0;
  106573. vb->nW=0;
  106574. }
  106575. vb->granulepos=op->granulepos;
  106576. vb->sequence=op->packetno;
  106577. vb->eofflag=op->e_o_s;
  106578. vb->pcmend=ci->blocksizes[vb->W];
  106579. vb->pcm=(float**)_vorbis_block_alloc(vb,sizeof(*vb->pcm)*vi->channels);
  106580. for(i=0;i<vi->channels;i++)
  106581. vb->pcm[i]=(float*)_vorbis_block_alloc(vb,vb->pcmend*sizeof(*vb->pcm[i]));
  106582. type=ci->map_type[ci->mode_param[mode]->mapping];
  106583. return(_mapping_P[type]->inverse(vb,ci->map_param[ci->mode_param[mode]->
  106584. mapping]));
  106585. }
  106586. int vorbis_synthesis_trackonly(vorbis_block *vb,ogg_packet *op){
  106587. vorbis_dsp_state *vd=vb->vd;
  106588. private_state *b=(private_state*)vd->backend_state;
  106589. vorbis_info *vi=vd->vi;
  106590. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106591. oggpack_buffer *opb=&vb->opb;
  106592. int mode;
  106593. _vorbis_block_ripcord(vb);
  106594. oggpack_readinit(opb,op->packet,op->bytes);
  106595. if(oggpack_read(opb,1)!=0){
  106596. return(OV_ENOTAUDIO);
  106597. }
  106598. mode=oggpack_read(opb,b->modebits);
  106599. if(mode==-1)return(OV_EBADPACKET);
  106600. vb->mode=mode;
  106601. vb->W=ci->mode_param[mode]->blockflag;
  106602. if(vb->W){
  106603. vb->lW=oggpack_read(opb,1);
  106604. vb->nW=oggpack_read(opb,1);
  106605. if(vb->nW==-1) return(OV_EBADPACKET);
  106606. }else{
  106607. vb->lW=0;
  106608. vb->nW=0;
  106609. }
  106610. vb->granulepos=op->granulepos;
  106611. vb->sequence=op->packetno;
  106612. vb->eofflag=op->e_o_s;
  106613. vb->pcmend=0;
  106614. vb->pcm=NULL;
  106615. return(0);
  106616. }
  106617. long vorbis_packet_blocksize(vorbis_info *vi,ogg_packet *op){
  106618. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106619. oggpack_buffer opb;
  106620. int mode;
  106621. oggpack_readinit(&opb,op->packet,op->bytes);
  106622. if(oggpack_read(&opb,1)!=0){
  106623. return(OV_ENOTAUDIO);
  106624. }
  106625. {
  106626. int modebits=0;
  106627. int v=ci->modes;
  106628. while(v>1){
  106629. modebits++;
  106630. v>>=1;
  106631. }
  106632. mode=oggpack_read(&opb,modebits);
  106633. }
  106634. if(mode==-1)return(OV_EBADPACKET);
  106635. return(ci->blocksizes[ci->mode_param[mode]->blockflag]);
  106636. }
  106637. int vorbis_synthesis_halfrate(vorbis_info *vi,int flag){
  106638. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106639. if(ci->blocksizes[0]<=64 && flag)return -1;
  106640. ci->halfrate_flag=(flag?1:0);
  106641. return 0;
  106642. }
  106643. int vorbis_synthesis_halfrate_p(vorbis_info *vi){
  106644. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  106645. return ci->halfrate_flag;
  106646. }
  106647. #endif
  106648. /*** End of inlined file: synthesis.c ***/
  106649. /*** Start of inlined file: vorbisenc.c ***/
  106650. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  106651. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  106652. // tasks..
  106653. #if JUCE_MSVC
  106654. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  106655. #endif
  106656. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  106657. #if JUCE_USE_OGGVORBIS
  106658. #include <stdlib.h>
  106659. #include <string.h>
  106660. #include <math.h>
  106661. typedef struct {
  106662. static_codebook *books[12][3];
  106663. } static_bookblock;
  106664. typedef struct {
  106665. int res_type;
  106666. int limit_type; /* 0 lowpass limited, 1 point stereo limited */
  106667. vorbis_info_residue0 *res;
  106668. static_codebook *book_aux;
  106669. static_codebook *book_aux_managed;
  106670. static_bookblock *books_base;
  106671. static_bookblock *books_base_managed;
  106672. } vorbis_residue_template;
  106673. typedef struct {
  106674. vorbis_info_mapping0 *map;
  106675. vorbis_residue_template *res;
  106676. } vorbis_mapping_template;
  106677. typedef struct vp_adjblock{
  106678. int block[P_BANDS];
  106679. } vp_adjblock;
  106680. typedef struct {
  106681. int data[NOISE_COMPAND_LEVELS];
  106682. } compandblock;
  106683. typedef struct {
  106684. int att[P_NOISECURVES];
  106685. float boost;
  106686. float decay;
  106687. } att3;
  106688. typedef struct { int data[P_NOISECURVES]; } adj3;
  106689. typedef struct {
  106690. int pre[PACKETBLOBS];
  106691. int post[PACKETBLOBS];
  106692. float kHz[PACKETBLOBS];
  106693. float lowpasskHz[PACKETBLOBS];
  106694. } adj_stereo;
  106695. typedef struct {
  106696. int lo;
  106697. int hi;
  106698. int fixed;
  106699. } noiseguard;
  106700. typedef struct {
  106701. int data[P_NOISECURVES][17];
  106702. } noise3;
  106703. typedef struct {
  106704. int mappings;
  106705. double *rate_mapping;
  106706. double *quality_mapping;
  106707. int coupling_restriction;
  106708. long samplerate_min_restriction;
  106709. long samplerate_max_restriction;
  106710. int *blocksize_short;
  106711. int *blocksize_long;
  106712. att3 *psy_tone_masteratt;
  106713. int *psy_tone_0dB;
  106714. int *psy_tone_dBsuppress;
  106715. vp_adjblock *psy_tone_adj_impulse;
  106716. vp_adjblock *psy_tone_adj_long;
  106717. vp_adjblock *psy_tone_adj_other;
  106718. noiseguard *psy_noiseguards;
  106719. noise3 *psy_noise_bias_impulse;
  106720. noise3 *psy_noise_bias_padding;
  106721. noise3 *psy_noise_bias_trans;
  106722. noise3 *psy_noise_bias_long;
  106723. int *psy_noise_dBsuppress;
  106724. compandblock *psy_noise_compand;
  106725. double *psy_noise_compand_short_mapping;
  106726. double *psy_noise_compand_long_mapping;
  106727. int *psy_noise_normal_start[2];
  106728. int *psy_noise_normal_partition[2];
  106729. double *psy_noise_normal_thresh;
  106730. int *psy_ath_float;
  106731. int *psy_ath_abs;
  106732. double *psy_lowpass;
  106733. vorbis_info_psy_global *global_params;
  106734. double *global_mapping;
  106735. adj_stereo *stereo_modes;
  106736. static_codebook ***floor_books;
  106737. vorbis_info_floor1 *floor_params;
  106738. int *floor_short_mapping;
  106739. int *floor_long_mapping;
  106740. vorbis_mapping_template *maps;
  106741. } ve_setup_data_template;
  106742. static vorbis_info_mode _mode_template[2]={
  106743. {0,0,0,0},
  106744. {1,0,0,1}
  106745. };
  106746. static vorbis_info_mapping0 _map_nominal[2]={
  106747. {1, {0,0}, {0}, {0}, 1,{0},{1}},
  106748. {1, {0,0}, {1}, {1}, 1,{0},{1}}
  106749. };
  106750. /*** Start of inlined file: setup_44.h ***/
  106751. /*** Start of inlined file: floor_all.h ***/
  106752. /*** Start of inlined file: floor_books.h ***/
  106753. static long _huff_lengthlist_line_256x7_0sub1[] = {
  106754. 0, 2, 3, 3, 3, 3, 4, 3, 4,
  106755. };
  106756. static static_codebook _huff_book_line_256x7_0sub1 = {
  106757. 1, 9,
  106758. _huff_lengthlist_line_256x7_0sub1,
  106759. 0, 0, 0, 0, 0,
  106760. NULL,
  106761. NULL,
  106762. NULL,
  106763. NULL,
  106764. 0
  106765. };
  106766. static long _huff_lengthlist_line_256x7_0sub2[] = {
  106767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 4, 3, 5, 3,
  106768. 6, 3, 6, 4, 6, 4, 7, 5, 7,
  106769. };
  106770. static static_codebook _huff_book_line_256x7_0sub2 = {
  106771. 1, 25,
  106772. _huff_lengthlist_line_256x7_0sub2,
  106773. 0, 0, 0, 0, 0,
  106774. NULL,
  106775. NULL,
  106776. NULL,
  106777. NULL,
  106778. 0
  106779. };
  106780. static long _huff_lengthlist_line_256x7_0sub3[] = {
  106781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 2, 5, 3, 5, 3,
  106783. 6, 3, 6, 4, 7, 6, 7, 8, 7, 9, 8, 9, 9, 9,10, 9,
  106784. 11,13,11,13,10,10,13,13,13,13,13,13,12,12,12,12,
  106785. };
  106786. static static_codebook _huff_book_line_256x7_0sub3 = {
  106787. 1, 64,
  106788. _huff_lengthlist_line_256x7_0sub3,
  106789. 0, 0, 0, 0, 0,
  106790. NULL,
  106791. NULL,
  106792. NULL,
  106793. NULL,
  106794. 0
  106795. };
  106796. static long _huff_lengthlist_line_256x7_1sub1[] = {
  106797. 0, 3, 3, 3, 3, 2, 4, 3, 4,
  106798. };
  106799. static static_codebook _huff_book_line_256x7_1sub1 = {
  106800. 1, 9,
  106801. _huff_lengthlist_line_256x7_1sub1,
  106802. 0, 0, 0, 0, 0,
  106803. NULL,
  106804. NULL,
  106805. NULL,
  106806. NULL,
  106807. 0
  106808. };
  106809. static long _huff_lengthlist_line_256x7_1sub2[] = {
  106810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 3, 4, 3, 4, 4,
  106811. 5, 4, 6, 5, 6, 7, 6, 8, 8,
  106812. };
  106813. static static_codebook _huff_book_line_256x7_1sub2 = {
  106814. 1, 25,
  106815. _huff_lengthlist_line_256x7_1sub2,
  106816. 0, 0, 0, 0, 0,
  106817. NULL,
  106818. NULL,
  106819. NULL,
  106820. NULL,
  106821. 0
  106822. };
  106823. static long _huff_lengthlist_line_256x7_1sub3[] = {
  106824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 2, 4, 3, 6, 3, 7,
  106826. 3, 8, 5, 8, 6, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  106827. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7,
  106828. };
  106829. static static_codebook _huff_book_line_256x7_1sub3 = {
  106830. 1, 64,
  106831. _huff_lengthlist_line_256x7_1sub3,
  106832. 0, 0, 0, 0, 0,
  106833. NULL,
  106834. NULL,
  106835. NULL,
  106836. NULL,
  106837. 0
  106838. };
  106839. static long _huff_lengthlist_line_256x7_class0[] = {
  106840. 7, 5, 5, 9, 9, 6, 6, 9,12, 8, 7, 8,11, 8, 9,15,
  106841. 6, 3, 3, 7, 7, 4, 3, 6, 9, 6, 5, 6, 8, 6, 8,15,
  106842. 8, 5, 5, 9, 8, 5, 4, 6,10, 7, 5, 5,11, 8, 7,15,
  106843. 14,15,13,13,13,13, 8,11,15,10, 7, 6,11, 9,10,15,
  106844. };
  106845. static static_codebook _huff_book_line_256x7_class0 = {
  106846. 1, 64,
  106847. _huff_lengthlist_line_256x7_class0,
  106848. 0, 0, 0, 0, 0,
  106849. NULL,
  106850. NULL,
  106851. NULL,
  106852. NULL,
  106853. 0
  106854. };
  106855. static long _huff_lengthlist_line_256x7_class1[] = {
  106856. 5, 6, 8,15, 6, 9,10,15,10,11,12,15,15,15,15,15,
  106857. 4, 6, 7,15, 6, 7, 8,15, 9, 8, 9,15,15,15,15,15,
  106858. 6, 8, 9,15, 7, 7, 8,15,10, 9,10,15,15,15,15,15,
  106859. 15,13,15,15,15,10,11,15,15,13,13,15,15,15,15,15,
  106860. 4, 6, 7,15, 6, 8, 9,15,10,10,12,15,15,15,15,15,
  106861. 2, 5, 6,15, 5, 6, 7,15, 8, 6, 7,15,15,15,15,15,
  106862. 5, 6, 8,15, 5, 6, 7,15, 9, 6, 7,15,15,15,15,15,
  106863. 14,12,13,15,12,10,11,15,15,15,15,15,15,15,15,15,
  106864. 7, 8, 9,15, 9,10,10,15,15,14,14,15,15,15,15,15,
  106865. 5, 6, 7,15, 7, 8, 9,15,12, 9,10,15,15,15,15,15,
  106866. 7, 7, 9,15, 7, 7, 8,15,12, 8, 9,15,15,15,15,15,
  106867. 13,13,14,15,12,11,12,15,15,15,15,15,15,15,15,15,
  106868. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106869. 13,13,13,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106870. 15,12,13,15,15,12,13,15,15,14,15,15,15,15,15,15,
  106871. 15,15,15,15,15,15,13,15,15,15,15,15,15,15,15,15,
  106872. };
  106873. static static_codebook _huff_book_line_256x7_class1 = {
  106874. 1, 256,
  106875. _huff_lengthlist_line_256x7_class1,
  106876. 0, 0, 0, 0, 0,
  106877. NULL,
  106878. NULL,
  106879. NULL,
  106880. NULL,
  106881. 0
  106882. };
  106883. static long _huff_lengthlist_line_512x17_0sub0[] = {
  106884. 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  106885. 5, 6, 5, 6, 6, 6, 6, 5, 6, 6, 7, 6, 7, 6, 7, 6,
  106886. 7, 6, 8, 7, 8, 7, 8, 7, 8, 7, 8, 7, 9, 7, 9, 7,
  106887. 9, 7, 9, 8, 9, 8,10, 8,10, 8,10, 7,10, 6,10, 8,
  106888. 10, 8,11, 7,10, 7,11, 8,11,11,12,12,11,11,12,11,
  106889. 13,11,13,11,13,12,15,12,13,13,14,14,14,14,14,15,
  106890. 15,15,16,14,17,19,19,18,18,18,18,18,18,18,18,18,
  106891. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  106892. };
  106893. static static_codebook _huff_book_line_512x17_0sub0 = {
  106894. 1, 128,
  106895. _huff_lengthlist_line_512x17_0sub0,
  106896. 0, 0, 0, 0, 0,
  106897. NULL,
  106898. NULL,
  106899. NULL,
  106900. NULL,
  106901. 0
  106902. };
  106903. static long _huff_lengthlist_line_512x17_1sub0[] = {
  106904. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  106905. 6, 5, 6, 6, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 8, 7,
  106906. };
  106907. static static_codebook _huff_book_line_512x17_1sub0 = {
  106908. 1, 32,
  106909. _huff_lengthlist_line_512x17_1sub0,
  106910. 0, 0, 0, 0, 0,
  106911. NULL,
  106912. NULL,
  106913. NULL,
  106914. NULL,
  106915. 0
  106916. };
  106917. static long _huff_lengthlist_line_512x17_1sub1[] = {
  106918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106920. 4, 3, 5, 3, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 6, 5,
  106921. 6, 5, 7, 5, 8, 6, 8, 6, 8, 6, 8, 6, 8, 7, 9, 7,
  106922. 9, 7,11, 9,11,11,12,11,14,12,14,16,14,16,13,16,
  106923. 14,16,12,15,13,16,14,16,13,14,12,15,13,15,13,13,
  106924. 13,15,12,14,14,15,13,15,12,15,15,15,15,15,15,15,
  106925. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,
  106926. };
  106927. static static_codebook _huff_book_line_512x17_1sub1 = {
  106928. 1, 128,
  106929. _huff_lengthlist_line_512x17_1sub1,
  106930. 0, 0, 0, 0, 0,
  106931. NULL,
  106932. NULL,
  106933. NULL,
  106934. NULL,
  106935. 0
  106936. };
  106937. static long _huff_lengthlist_line_512x17_2sub1[] = {
  106938. 0, 4, 5, 4, 4, 4, 5, 4, 4, 4, 5, 4, 5, 4, 5, 3,
  106939. 5, 3,
  106940. };
  106941. static static_codebook _huff_book_line_512x17_2sub1 = {
  106942. 1, 18,
  106943. _huff_lengthlist_line_512x17_2sub1,
  106944. 0, 0, 0, 0, 0,
  106945. NULL,
  106946. NULL,
  106947. NULL,
  106948. NULL,
  106949. 0
  106950. };
  106951. static long _huff_lengthlist_line_512x17_2sub2[] = {
  106952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106953. 0, 0, 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 6, 4, 6, 5,
  106954. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 7, 8, 7, 9, 7,
  106955. 9, 8,
  106956. };
  106957. static static_codebook _huff_book_line_512x17_2sub2 = {
  106958. 1, 50,
  106959. _huff_lengthlist_line_512x17_2sub2,
  106960. 0, 0, 0, 0, 0,
  106961. NULL,
  106962. NULL,
  106963. NULL,
  106964. NULL,
  106965. 0
  106966. };
  106967. static long _huff_lengthlist_line_512x17_2sub3[] = {
  106968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  106971. 0, 0, 3, 3, 3, 3, 4, 3, 4, 4, 5, 5, 6, 6, 7, 7,
  106972. 7, 8, 8,11, 8, 9, 9, 9,10,11,11,11, 9,10,10,11,
  106973. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106974. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106975. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  106976. };
  106977. static static_codebook _huff_book_line_512x17_2sub3 = {
  106978. 1, 128,
  106979. _huff_lengthlist_line_512x17_2sub3,
  106980. 0, 0, 0, 0, 0,
  106981. NULL,
  106982. NULL,
  106983. NULL,
  106984. NULL,
  106985. 0
  106986. };
  106987. static long _huff_lengthlist_line_512x17_3sub1[] = {
  106988. 0, 4, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4, 5, 4, 5,
  106989. 5, 5,
  106990. };
  106991. static static_codebook _huff_book_line_512x17_3sub1 = {
  106992. 1, 18,
  106993. _huff_lengthlist_line_512x17_3sub1,
  106994. 0, 0, 0, 0, 0,
  106995. NULL,
  106996. NULL,
  106997. NULL,
  106998. NULL,
  106999. 0
  107000. };
  107001. static long _huff_lengthlist_line_512x17_3sub2[] = {
  107002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107003. 0, 0, 2, 3, 3, 4, 3, 5, 4, 6, 4, 6, 5, 7, 6, 7,
  107004. 6, 8, 6, 8, 7, 9, 8,10, 8,12, 9,13,10,15,10,15,
  107005. 11,14,
  107006. };
  107007. static static_codebook _huff_book_line_512x17_3sub2 = {
  107008. 1, 50,
  107009. _huff_lengthlist_line_512x17_3sub2,
  107010. 0, 0, 0, 0, 0,
  107011. NULL,
  107012. NULL,
  107013. NULL,
  107014. NULL,
  107015. 0
  107016. };
  107017. static long _huff_lengthlist_line_512x17_3sub3[] = {
  107018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107021. 0, 0, 4, 8, 4, 8, 4, 8, 4, 8, 5, 8, 5, 8, 6, 8,
  107022. 4, 8, 4, 8, 5, 8, 5, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107023. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107024. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107025. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107026. };
  107027. static static_codebook _huff_book_line_512x17_3sub3 = {
  107028. 1, 128,
  107029. _huff_lengthlist_line_512x17_3sub3,
  107030. 0, 0, 0, 0, 0,
  107031. NULL,
  107032. NULL,
  107033. NULL,
  107034. NULL,
  107035. 0
  107036. };
  107037. static long _huff_lengthlist_line_512x17_class1[] = {
  107038. 1, 2, 3, 6, 5, 4, 7, 7,
  107039. };
  107040. static static_codebook _huff_book_line_512x17_class1 = {
  107041. 1, 8,
  107042. _huff_lengthlist_line_512x17_class1,
  107043. 0, 0, 0, 0, 0,
  107044. NULL,
  107045. NULL,
  107046. NULL,
  107047. NULL,
  107048. 0
  107049. };
  107050. static long _huff_lengthlist_line_512x17_class2[] = {
  107051. 3, 3, 3,14, 5, 4, 4,11, 8, 6, 6,10,17,12,11,17,
  107052. 6, 5, 5,15, 5, 3, 4,11, 8, 5, 5, 8,16, 9,10,14,
  107053. 10, 8, 9,17, 8, 6, 6,13,10, 7, 7,10,16,11,13,14,
  107054. 17,17,17,17,17,16,16,16,16,15,16,16,16,16,16,16,
  107055. };
  107056. static static_codebook _huff_book_line_512x17_class2 = {
  107057. 1, 64,
  107058. _huff_lengthlist_line_512x17_class2,
  107059. 0, 0, 0, 0, 0,
  107060. NULL,
  107061. NULL,
  107062. NULL,
  107063. NULL,
  107064. 0
  107065. };
  107066. static long _huff_lengthlist_line_512x17_class3[] = {
  107067. 2, 4, 6,17, 4, 5, 7,17, 8, 7,10,17,17,17,17,17,
  107068. 3, 4, 6,15, 3, 3, 6,15, 7, 6, 9,17,17,17,17,17,
  107069. 6, 8,10,17, 6, 6, 8,16, 9, 8,10,17,17,15,16,17,
  107070. 17,17,17,17,12,15,15,16,12,15,15,16,16,16,16,16,
  107071. };
  107072. static static_codebook _huff_book_line_512x17_class3 = {
  107073. 1, 64,
  107074. _huff_lengthlist_line_512x17_class3,
  107075. 0, 0, 0, 0, 0,
  107076. NULL,
  107077. NULL,
  107078. NULL,
  107079. NULL,
  107080. 0
  107081. };
  107082. static long _huff_lengthlist_line_128x4_class0[] = {
  107083. 7, 7, 7,11, 6, 6, 7,11, 7, 6, 6,10,12,10,10,13,
  107084. 7, 7, 8,11, 7, 7, 7,11, 7, 6, 7,10,11,10,10,13,
  107085. 10,10, 9,12, 9, 9, 9,11, 8, 8, 8,11,13,11,10,14,
  107086. 15,15,14,15,15,14,13,14,15,12,12,17,17,17,17,17,
  107087. 7, 7, 6, 9, 6, 6, 6, 9, 7, 6, 6, 8,11,11,10,12,
  107088. 7, 7, 7, 9, 7, 6, 6, 9, 7, 6, 6, 9,13,10,10,11,
  107089. 10, 9, 8,10, 9, 8, 8,10, 8, 8, 7, 9,13,12,10,11,
  107090. 17,14,14,13,15,14,12,13,17,13,12,15,17,17,14,17,
  107091. 7, 6, 6, 7, 6, 6, 5, 7, 6, 6, 6, 6,11, 9, 9, 9,
  107092. 7, 7, 6, 7, 7, 6, 6, 7, 6, 6, 6, 6,10, 9, 8, 9,
  107093. 10, 9, 8, 8, 9, 8, 7, 8, 8, 7, 6, 8,11,10, 9,10,
  107094. 17,17,12,15,15,15,12,14,14,14,10,12,15,13,12,13,
  107095. 11,10, 8,10,11,10, 8, 8,10, 9, 7, 7,10, 9, 9,11,
  107096. 11,11, 9,10,11,10, 8, 9,10, 8, 6, 8,10, 9, 9,11,
  107097. 14,13,10,12,12,11,10,10, 8, 7, 8,10,10,11,11,12,
  107098. 17,17,15,17,17,17,17,17,17,13,12,17,17,17,14,17,
  107099. };
  107100. static static_codebook _huff_book_line_128x4_class0 = {
  107101. 1, 256,
  107102. _huff_lengthlist_line_128x4_class0,
  107103. 0, 0, 0, 0, 0,
  107104. NULL,
  107105. NULL,
  107106. NULL,
  107107. NULL,
  107108. 0
  107109. };
  107110. static long _huff_lengthlist_line_128x4_0sub0[] = {
  107111. 2, 2, 2, 2,
  107112. };
  107113. static static_codebook _huff_book_line_128x4_0sub0 = {
  107114. 1, 4,
  107115. _huff_lengthlist_line_128x4_0sub0,
  107116. 0, 0, 0, 0, 0,
  107117. NULL,
  107118. NULL,
  107119. NULL,
  107120. NULL,
  107121. 0
  107122. };
  107123. static long _huff_lengthlist_line_128x4_0sub1[] = {
  107124. 0, 0, 0, 0, 3, 2, 3, 2, 3, 3,
  107125. };
  107126. static static_codebook _huff_book_line_128x4_0sub1 = {
  107127. 1, 10,
  107128. _huff_lengthlist_line_128x4_0sub1,
  107129. 0, 0, 0, 0, 0,
  107130. NULL,
  107131. NULL,
  107132. NULL,
  107133. NULL,
  107134. 0
  107135. };
  107136. static long _huff_lengthlist_line_128x4_0sub2[] = {
  107137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 4, 3, 4, 3,
  107138. 4, 4, 5, 4, 5, 4, 6, 5, 6,
  107139. };
  107140. static static_codebook _huff_book_line_128x4_0sub2 = {
  107141. 1, 25,
  107142. _huff_lengthlist_line_128x4_0sub2,
  107143. 0, 0, 0, 0, 0,
  107144. NULL,
  107145. NULL,
  107146. NULL,
  107147. NULL,
  107148. 0
  107149. };
  107150. static long _huff_lengthlist_line_128x4_0sub3[] = {
  107151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  107153. 5, 4, 6, 5, 6, 5, 7, 6, 6, 7, 7, 9, 9,11,11,16,
  107154. 11,14,10,11,11,13,16,15,15,15,15,15,15,15,15,15,
  107155. };
  107156. static static_codebook _huff_book_line_128x4_0sub3 = {
  107157. 1, 64,
  107158. _huff_lengthlist_line_128x4_0sub3,
  107159. 0, 0, 0, 0, 0,
  107160. NULL,
  107161. NULL,
  107162. NULL,
  107163. NULL,
  107164. 0
  107165. };
  107166. static long _huff_lengthlist_line_256x4_class0[] = {
  107167. 6, 7, 7,12, 6, 6, 7,12, 7, 6, 6,10,15,12,11,13,
  107168. 7, 7, 8,13, 7, 7, 8,12, 7, 7, 7,11,12,12,11,13,
  107169. 10, 9, 9,11, 9, 9, 9,10,10, 8, 8,12,14,12,12,14,
  107170. 11,11,12,14,11,12,11,15,15,12,13,15,15,15,15,15,
  107171. 6, 6, 7,10, 6, 6, 6,11, 7, 6, 6, 9,14,12,11,13,
  107172. 7, 7, 7,10, 6, 6, 7, 9, 7, 7, 6,10,13,12,10,12,
  107173. 9, 9, 9,11, 9, 9, 8, 9, 9, 8, 8,10,13,12,10,12,
  107174. 12,12,11,13,12,12,11,12,15,13,12,15,15,15,14,14,
  107175. 6, 6, 6, 8, 6, 6, 5, 6, 7, 7, 6, 5,11,10, 9, 8,
  107176. 7, 6, 6, 7, 6, 6, 5, 6, 7, 7, 6, 6,11,10, 9, 8,
  107177. 8, 8, 8, 9, 8, 8, 7, 8, 8, 8, 6, 7,11,10, 9, 9,
  107178. 14,11,10,14,14,11,10,15,13,11, 9,11,15,12,12,11,
  107179. 11, 9, 8, 8,10, 9, 8, 9,11,10, 9, 8,12,11,12,11,
  107180. 13,10, 8, 9,11,10, 8, 9,10, 9, 8, 9,10, 8,12,12,
  107181. 15,11,10,10,13,11,10,10, 8, 8, 7,12,10, 9,11,12,
  107182. 15,12,11,15,13,11,11,15,12,14,11,13,15,15,13,13,
  107183. };
  107184. static static_codebook _huff_book_line_256x4_class0 = {
  107185. 1, 256,
  107186. _huff_lengthlist_line_256x4_class0,
  107187. 0, 0, 0, 0, 0,
  107188. NULL,
  107189. NULL,
  107190. NULL,
  107191. NULL,
  107192. 0
  107193. };
  107194. static long _huff_lengthlist_line_256x4_0sub0[] = {
  107195. 2, 2, 2, 2,
  107196. };
  107197. static static_codebook _huff_book_line_256x4_0sub0 = {
  107198. 1, 4,
  107199. _huff_lengthlist_line_256x4_0sub0,
  107200. 0, 0, 0, 0, 0,
  107201. NULL,
  107202. NULL,
  107203. NULL,
  107204. NULL,
  107205. 0
  107206. };
  107207. static long _huff_lengthlist_line_256x4_0sub1[] = {
  107208. 0, 0, 0, 0, 2, 2, 3, 3, 3, 3,
  107209. };
  107210. static static_codebook _huff_book_line_256x4_0sub1 = {
  107211. 1, 10,
  107212. _huff_lengthlist_line_256x4_0sub1,
  107213. 0, 0, 0, 0, 0,
  107214. NULL,
  107215. NULL,
  107216. NULL,
  107217. NULL,
  107218. 0
  107219. };
  107220. static long _huff_lengthlist_line_256x4_0sub2[] = {
  107221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 3, 4, 3, 4, 3,
  107222. 5, 3, 5, 4, 5, 4, 6, 4, 6,
  107223. };
  107224. static static_codebook _huff_book_line_256x4_0sub2 = {
  107225. 1, 25,
  107226. _huff_lengthlist_line_256x4_0sub2,
  107227. 0, 0, 0, 0, 0,
  107228. NULL,
  107229. NULL,
  107230. NULL,
  107231. NULL,
  107232. 0
  107233. };
  107234. static long _huff_lengthlist_line_256x4_0sub3[] = {
  107235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 4, 3, 5, 3, 5, 3,
  107237. 6, 4, 7, 4, 7, 5, 7, 6, 7, 6, 7, 8,10,13,13,13,
  107238. 13,13,13,13,13,13,13,13,13,13,13,12,12,12,12,12,
  107239. };
  107240. static static_codebook _huff_book_line_256x4_0sub3 = {
  107241. 1, 64,
  107242. _huff_lengthlist_line_256x4_0sub3,
  107243. 0, 0, 0, 0, 0,
  107244. NULL,
  107245. NULL,
  107246. NULL,
  107247. NULL,
  107248. 0
  107249. };
  107250. static long _huff_lengthlist_line_128x7_class0[] = {
  107251. 10, 7, 8,13, 9, 6, 7,11,10, 8, 8,12,17,17,17,17,
  107252. 7, 5, 5, 9, 6, 4, 4, 8, 8, 5, 5, 8,16,14,13,16,
  107253. 7, 5, 5, 7, 6, 3, 3, 5, 8, 5, 4, 7,14,12,12,15,
  107254. 10, 7, 8, 9, 7, 5, 5, 6, 9, 6, 5, 5,15,12, 9,10,
  107255. };
  107256. static static_codebook _huff_book_line_128x7_class0 = {
  107257. 1, 64,
  107258. _huff_lengthlist_line_128x7_class0,
  107259. 0, 0, 0, 0, 0,
  107260. NULL,
  107261. NULL,
  107262. NULL,
  107263. NULL,
  107264. 0
  107265. };
  107266. static long _huff_lengthlist_line_128x7_class1[] = {
  107267. 8,13,17,17, 8,11,17,17,11,13,17,17,17,17,17,17,
  107268. 6,10,16,17, 6,10,15,17, 8,10,16,17,17,17,17,17,
  107269. 9,13,15,17, 8,11,17,17,10,12,17,17,17,17,17,17,
  107270. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107271. 6,11,15,17, 7,10,15,17, 8,10,17,17,17,15,17,17,
  107272. 4, 8,13,17, 4, 7,13,17, 6, 8,15,17,16,15,17,17,
  107273. 6,11,15,17, 6, 9,13,17, 8,10,17,17,15,17,17,17,
  107274. 16,17,17,17,12,14,15,17,13,14,15,17,17,17,17,17,
  107275. 5,10,14,17, 5, 9,14,17, 7, 9,15,17,15,15,17,17,
  107276. 3, 7,12,17, 3, 6,11,17, 5, 7,13,17,12,12,17,17,
  107277. 5, 9,14,17, 3, 7,11,17, 5, 8,13,17,13,11,16,17,
  107278. 12,17,17,17, 9,14,15,17,10,11,14,17,16,14,17,17,
  107279. 8,12,17,17, 8,12,17,17,10,12,17,17,17,17,17,17,
  107280. 5,10,17,17, 5, 9,15,17, 7, 9,17,17,13,13,17,17,
  107281. 7,11,17,17, 6,10,15,17, 7, 9,15,17,12,11,17,17,
  107282. 12,15,17,17,11,14,17,17,11,10,15,17,17,16,17,17,
  107283. };
  107284. static static_codebook _huff_book_line_128x7_class1 = {
  107285. 1, 256,
  107286. _huff_lengthlist_line_128x7_class1,
  107287. 0, 0, 0, 0, 0,
  107288. NULL,
  107289. NULL,
  107290. NULL,
  107291. NULL,
  107292. 0
  107293. };
  107294. static long _huff_lengthlist_line_128x7_0sub1[] = {
  107295. 0, 3, 3, 3, 3, 3, 3, 3, 3,
  107296. };
  107297. static static_codebook _huff_book_line_128x7_0sub1 = {
  107298. 1, 9,
  107299. _huff_lengthlist_line_128x7_0sub1,
  107300. 0, 0, 0, 0, 0,
  107301. NULL,
  107302. NULL,
  107303. NULL,
  107304. NULL,
  107305. 0
  107306. };
  107307. static long _huff_lengthlist_line_128x7_0sub2[] = {
  107308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 4, 4, 4,
  107309. 5, 4, 5, 4, 5, 4, 6, 4, 6,
  107310. };
  107311. static static_codebook _huff_book_line_128x7_0sub2 = {
  107312. 1, 25,
  107313. _huff_lengthlist_line_128x7_0sub2,
  107314. 0, 0, 0, 0, 0,
  107315. NULL,
  107316. NULL,
  107317. NULL,
  107318. NULL,
  107319. 0
  107320. };
  107321. static long _huff_lengthlist_line_128x7_0sub3[] = {
  107322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 5, 3, 5, 3, 5, 4,
  107324. 5, 4, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107325. 7, 8, 9,11,13,13,13,13,13,13,13,13,13,13,13,13,
  107326. };
  107327. static static_codebook _huff_book_line_128x7_0sub3 = {
  107328. 1, 64,
  107329. _huff_lengthlist_line_128x7_0sub3,
  107330. 0, 0, 0, 0, 0,
  107331. NULL,
  107332. NULL,
  107333. NULL,
  107334. NULL,
  107335. 0
  107336. };
  107337. static long _huff_lengthlist_line_128x7_1sub1[] = {
  107338. 0, 3, 3, 2, 3, 3, 4, 3, 4,
  107339. };
  107340. static static_codebook _huff_book_line_128x7_1sub1 = {
  107341. 1, 9,
  107342. _huff_lengthlist_line_128x7_1sub1,
  107343. 0, 0, 0, 0, 0,
  107344. NULL,
  107345. NULL,
  107346. NULL,
  107347. NULL,
  107348. 0
  107349. };
  107350. static long _huff_lengthlist_line_128x7_1sub2[] = {
  107351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 4, 3, 6, 3, 6, 3,
  107352. 6, 3, 7, 3, 8, 4, 9, 4, 9,
  107353. };
  107354. static static_codebook _huff_book_line_128x7_1sub2 = {
  107355. 1, 25,
  107356. _huff_lengthlist_line_128x7_1sub2,
  107357. 0, 0, 0, 0, 0,
  107358. NULL,
  107359. NULL,
  107360. NULL,
  107361. NULL,
  107362. 0
  107363. };
  107364. static long _huff_lengthlist_line_128x7_1sub3[] = {
  107365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 7, 2, 7, 3, 8, 4,
  107367. 9, 5, 9, 8,10,11,11,12,14,14,14,14,14,14,14,14,
  107368. 14,14,14,14,14,14,14,14,14,14,14,14,13,13,13,13,
  107369. };
  107370. static static_codebook _huff_book_line_128x7_1sub3 = {
  107371. 1, 64,
  107372. _huff_lengthlist_line_128x7_1sub3,
  107373. 0, 0, 0, 0, 0,
  107374. NULL,
  107375. NULL,
  107376. NULL,
  107377. NULL,
  107378. 0
  107379. };
  107380. static long _huff_lengthlist_line_128x11_class1[] = {
  107381. 1, 6, 3, 7, 2, 4, 5, 7,
  107382. };
  107383. static static_codebook _huff_book_line_128x11_class1 = {
  107384. 1, 8,
  107385. _huff_lengthlist_line_128x11_class1,
  107386. 0, 0, 0, 0, 0,
  107387. NULL,
  107388. NULL,
  107389. NULL,
  107390. NULL,
  107391. 0
  107392. };
  107393. static long _huff_lengthlist_line_128x11_class2[] = {
  107394. 1, 6,12,16, 4,12,15,16, 9,15,16,16,16,16,16,16,
  107395. 2, 5,11,16, 5,11,13,16, 9,13,16,16,16,16,16,16,
  107396. 4, 8,12,16, 5, 9,12,16, 9,13,15,16,16,16,16,16,
  107397. 15,16,16,16,11,14,13,16,12,15,16,16,16,16,16,15,
  107398. };
  107399. static static_codebook _huff_book_line_128x11_class2 = {
  107400. 1, 64,
  107401. _huff_lengthlist_line_128x11_class2,
  107402. 0, 0, 0, 0, 0,
  107403. NULL,
  107404. NULL,
  107405. NULL,
  107406. NULL,
  107407. 0
  107408. };
  107409. static long _huff_lengthlist_line_128x11_class3[] = {
  107410. 7, 6, 9,17, 7, 6, 8,17,12, 9,11,16,16,16,16,16,
  107411. 5, 4, 7,16, 5, 3, 6,14, 9, 6, 8,15,16,16,16,16,
  107412. 5, 4, 6,13, 3, 2, 4,11, 7, 4, 6,13,16,11,10,14,
  107413. 12,12,12,16, 9, 7,10,15,12, 9,11,16,16,15,15,16,
  107414. };
  107415. static static_codebook _huff_book_line_128x11_class3 = {
  107416. 1, 64,
  107417. _huff_lengthlist_line_128x11_class3,
  107418. 0, 0, 0, 0, 0,
  107419. NULL,
  107420. NULL,
  107421. NULL,
  107422. NULL,
  107423. 0
  107424. };
  107425. static long _huff_lengthlist_line_128x11_0sub0[] = {
  107426. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107427. 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 6, 6, 6, 7, 6,
  107428. 7, 6, 7, 6, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6, 8, 7,
  107429. 8, 7, 8, 7, 8, 7, 9, 7, 9, 8, 9, 8, 9, 8,10, 8,
  107430. 10, 9,10, 9,10, 9,11, 9,11, 9,10,10,11,10,11,10,
  107431. 11,11,11,11,11,11,12,13,14,14,14,15,15,16,16,16,
  107432. 17,15,16,15,16,16,17,17,16,17,17,17,17,17,17,17,
  107433. 17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,17,
  107434. };
  107435. static static_codebook _huff_book_line_128x11_0sub0 = {
  107436. 1, 128,
  107437. _huff_lengthlist_line_128x11_0sub0,
  107438. 0, 0, 0, 0, 0,
  107439. NULL,
  107440. NULL,
  107441. NULL,
  107442. NULL,
  107443. 0
  107444. };
  107445. static long _huff_lengthlist_line_128x11_1sub0[] = {
  107446. 2, 5, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  107447. 6, 5, 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 8, 6,
  107448. };
  107449. static static_codebook _huff_book_line_128x11_1sub0 = {
  107450. 1, 32,
  107451. _huff_lengthlist_line_128x11_1sub0,
  107452. 0, 0, 0, 0, 0,
  107453. NULL,
  107454. NULL,
  107455. NULL,
  107456. NULL,
  107457. 0
  107458. };
  107459. static long _huff_lengthlist_line_128x11_1sub1[] = {
  107460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107462. 5, 3, 5, 3, 6, 4, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107463. 8, 4, 9, 5, 9, 5, 9, 5, 9, 6,10, 6,10, 6,11, 7,
  107464. 10, 7,10, 8,11, 9,11, 9,11,10,11,11,12,11,11,12,
  107465. 15,15,12,14,11,14,12,14,11,14,13,14,12,14,11,14,
  107466. 11,14,12,14,11,14,11,14,13,13,14,14,14,14,14,14,
  107467. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  107468. };
  107469. static static_codebook _huff_book_line_128x11_1sub1 = {
  107470. 1, 128,
  107471. _huff_lengthlist_line_128x11_1sub1,
  107472. 0, 0, 0, 0, 0,
  107473. NULL,
  107474. NULL,
  107475. NULL,
  107476. NULL,
  107477. 0
  107478. };
  107479. static long _huff_lengthlist_line_128x11_2sub1[] = {
  107480. 0, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4,
  107481. 5, 5,
  107482. };
  107483. static static_codebook _huff_book_line_128x11_2sub1 = {
  107484. 1, 18,
  107485. _huff_lengthlist_line_128x11_2sub1,
  107486. 0, 0, 0, 0, 0,
  107487. NULL,
  107488. NULL,
  107489. NULL,
  107490. NULL,
  107491. 0
  107492. };
  107493. static long _huff_lengthlist_line_128x11_2sub2[] = {
  107494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107495. 0, 0, 3, 3, 3, 4, 4, 4, 4, 5, 4, 5, 4, 6, 5, 7,
  107496. 5, 7, 6, 8, 6, 8, 6, 9, 7, 9, 7,10, 7, 9, 8,11,
  107497. 8,11,
  107498. };
  107499. static static_codebook _huff_book_line_128x11_2sub2 = {
  107500. 1, 50,
  107501. _huff_lengthlist_line_128x11_2sub2,
  107502. 0, 0, 0, 0, 0,
  107503. NULL,
  107504. NULL,
  107505. NULL,
  107506. NULL,
  107507. 0
  107508. };
  107509. static long _huff_lengthlist_line_128x11_2sub3[] = {
  107510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107513. 0, 0, 4, 8, 3, 8, 4, 8, 4, 8, 6, 8, 5, 8, 4, 8,
  107514. 4, 8, 6, 8, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107515. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107516. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107517. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107518. };
  107519. static static_codebook _huff_book_line_128x11_2sub3 = {
  107520. 1, 128,
  107521. _huff_lengthlist_line_128x11_2sub3,
  107522. 0, 0, 0, 0, 0,
  107523. NULL,
  107524. NULL,
  107525. NULL,
  107526. NULL,
  107527. 0
  107528. };
  107529. static long _huff_lengthlist_line_128x11_3sub1[] = {
  107530. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4,
  107531. 5, 4,
  107532. };
  107533. static static_codebook _huff_book_line_128x11_3sub1 = {
  107534. 1, 18,
  107535. _huff_lengthlist_line_128x11_3sub1,
  107536. 0, 0, 0, 0, 0,
  107537. NULL,
  107538. NULL,
  107539. NULL,
  107540. NULL,
  107541. 0
  107542. };
  107543. static long _huff_lengthlist_line_128x11_3sub2[] = {
  107544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107545. 0, 0, 5, 3, 5, 4, 6, 4, 6, 4, 7, 4, 7, 4, 8, 4,
  107546. 8, 4, 9, 4, 9, 4,10, 4,10, 5,10, 5,11, 5,12, 6,
  107547. 12, 6,
  107548. };
  107549. static static_codebook _huff_book_line_128x11_3sub2 = {
  107550. 1, 50,
  107551. _huff_lengthlist_line_128x11_3sub2,
  107552. 0, 0, 0, 0, 0,
  107553. NULL,
  107554. NULL,
  107555. NULL,
  107556. NULL,
  107557. 0
  107558. };
  107559. static long _huff_lengthlist_line_128x11_3sub3[] = {
  107560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107563. 0, 0, 7, 1, 6, 3, 7, 3, 8, 4, 8, 5, 8, 8, 8, 9,
  107564. 7, 8, 8, 7, 7, 7, 8, 9,10, 9, 9,10,10,10,10,10,
  107565. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107566. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  107567. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  107568. };
  107569. static static_codebook _huff_book_line_128x11_3sub3 = {
  107570. 1, 128,
  107571. _huff_lengthlist_line_128x11_3sub3,
  107572. 0, 0, 0, 0, 0,
  107573. NULL,
  107574. NULL,
  107575. NULL,
  107576. NULL,
  107577. 0
  107578. };
  107579. static long _huff_lengthlist_line_128x17_class1[] = {
  107580. 1, 3, 4, 7, 2, 5, 6, 7,
  107581. };
  107582. static static_codebook _huff_book_line_128x17_class1 = {
  107583. 1, 8,
  107584. _huff_lengthlist_line_128x17_class1,
  107585. 0, 0, 0, 0, 0,
  107586. NULL,
  107587. NULL,
  107588. NULL,
  107589. NULL,
  107590. 0
  107591. };
  107592. static long _huff_lengthlist_line_128x17_class2[] = {
  107593. 1, 4,10,19, 3, 8,13,19, 7,12,19,19,19,19,19,19,
  107594. 2, 6,11,19, 8,13,19,19, 9,11,19,19,19,19,19,19,
  107595. 6, 7,13,19, 9,13,19,19,10,13,18,18,18,18,18,18,
  107596. 18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,18,
  107597. };
  107598. static static_codebook _huff_book_line_128x17_class2 = {
  107599. 1, 64,
  107600. _huff_lengthlist_line_128x17_class2,
  107601. 0, 0, 0, 0, 0,
  107602. NULL,
  107603. NULL,
  107604. NULL,
  107605. NULL,
  107606. 0
  107607. };
  107608. static long _huff_lengthlist_line_128x17_class3[] = {
  107609. 3, 6,10,17, 4, 8,11,20, 8,10,11,20,20,20,20,20,
  107610. 2, 4, 8,18, 4, 6, 8,17, 7, 8,10,20,20,17,20,20,
  107611. 3, 5, 8,17, 3, 4, 6,17, 8, 8,10,17,17,12,16,20,
  107612. 13,13,15,20,10,10,12,20,15,14,15,20,20,20,19,19,
  107613. };
  107614. static static_codebook _huff_book_line_128x17_class3 = {
  107615. 1, 64,
  107616. _huff_lengthlist_line_128x17_class3,
  107617. 0, 0, 0, 0, 0,
  107618. NULL,
  107619. NULL,
  107620. NULL,
  107621. NULL,
  107622. 0
  107623. };
  107624. static long _huff_lengthlist_line_128x17_0sub0[] = {
  107625. 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107626. 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5,
  107627. 8, 5, 8, 5, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6, 9, 6,
  107628. 9, 6, 9, 7, 9, 7, 9, 7, 9, 7,10, 7,10, 8,10, 8,
  107629. 10, 8,10, 8,10, 8,11, 8,11, 8,11, 8,11, 8,11, 9,
  107630. 12, 9,12, 9,12, 9,12, 9,12,10,12,10,13,11,13,11,
  107631. 14,12,14,13,15,14,16,14,17,15,18,16,20,20,20,20,
  107632. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107633. };
  107634. static static_codebook _huff_book_line_128x17_0sub0 = {
  107635. 1, 128,
  107636. _huff_lengthlist_line_128x17_0sub0,
  107637. 0, 0, 0, 0, 0,
  107638. NULL,
  107639. NULL,
  107640. NULL,
  107641. NULL,
  107642. 0
  107643. };
  107644. static long _huff_lengthlist_line_128x17_1sub0[] = {
  107645. 2, 5, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  107646. 6, 5, 6, 5, 7, 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7,
  107647. };
  107648. static static_codebook _huff_book_line_128x17_1sub0 = {
  107649. 1, 32,
  107650. _huff_lengthlist_line_128x17_1sub0,
  107651. 0, 0, 0, 0, 0,
  107652. NULL,
  107653. NULL,
  107654. NULL,
  107655. NULL,
  107656. 0
  107657. };
  107658. static long _huff_lengthlist_line_128x17_1sub1[] = {
  107659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107661. 4, 3, 5, 3, 5, 3, 6, 3, 6, 4, 6, 4, 7, 4, 7, 5,
  107662. 8, 5, 8, 6, 9, 7, 9, 7, 9, 8,10, 9,10, 9,11,10,
  107663. 11,11,11,11,11,11,12,12,12,13,12,13,12,14,12,15,
  107664. 12,14,12,16,13,17,13,17,14,17,14,16,13,17,14,17,
  107665. 14,17,15,17,15,15,16,17,17,17,17,17,17,17,17,17,
  107666. 17,17,17,17,17,17,16,16,16,16,16,16,16,16,16,16,
  107667. };
  107668. static static_codebook _huff_book_line_128x17_1sub1 = {
  107669. 1, 128,
  107670. _huff_lengthlist_line_128x17_1sub1,
  107671. 0, 0, 0, 0, 0,
  107672. NULL,
  107673. NULL,
  107674. NULL,
  107675. NULL,
  107676. 0
  107677. };
  107678. static long _huff_lengthlist_line_128x17_2sub1[] = {
  107679. 0, 4, 5, 4, 6, 4, 8, 3, 9, 3, 9, 2, 9, 3, 8, 4,
  107680. 9, 4,
  107681. };
  107682. static static_codebook _huff_book_line_128x17_2sub1 = {
  107683. 1, 18,
  107684. _huff_lengthlist_line_128x17_2sub1,
  107685. 0, 0, 0, 0, 0,
  107686. NULL,
  107687. NULL,
  107688. NULL,
  107689. NULL,
  107690. 0
  107691. };
  107692. static long _huff_lengthlist_line_128x17_2sub2[] = {
  107693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107694. 0, 0, 5, 1, 5, 3, 5, 3, 5, 4, 7, 5,10, 7,10, 7,
  107695. 12,10,14,10,14, 9,14,11,14,14,14,13,13,13,13,13,
  107696. 13,13,
  107697. };
  107698. static static_codebook _huff_book_line_128x17_2sub2 = {
  107699. 1, 50,
  107700. _huff_lengthlist_line_128x17_2sub2,
  107701. 0, 0, 0, 0, 0,
  107702. NULL,
  107703. NULL,
  107704. NULL,
  107705. NULL,
  107706. 0
  107707. };
  107708. static long _huff_lengthlist_line_128x17_2sub3[] = {
  107709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107712. 0, 0, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  107713. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
  107714. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107715. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107716. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  107717. };
  107718. static static_codebook _huff_book_line_128x17_2sub3 = {
  107719. 1, 128,
  107720. _huff_lengthlist_line_128x17_2sub3,
  107721. 0, 0, 0, 0, 0,
  107722. NULL,
  107723. NULL,
  107724. NULL,
  107725. NULL,
  107726. 0
  107727. };
  107728. static long _huff_lengthlist_line_128x17_3sub1[] = {
  107729. 0, 4, 4, 4, 4, 4, 4, 4, 5, 3, 5, 3, 5, 4, 6, 4,
  107730. 6, 4,
  107731. };
  107732. static static_codebook _huff_book_line_128x17_3sub1 = {
  107733. 1, 18,
  107734. _huff_lengthlist_line_128x17_3sub1,
  107735. 0, 0, 0, 0, 0,
  107736. NULL,
  107737. NULL,
  107738. NULL,
  107739. NULL,
  107740. 0
  107741. };
  107742. static long _huff_lengthlist_line_128x17_3sub2[] = {
  107743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107744. 0, 0, 5, 3, 6, 3, 6, 4, 7, 4, 7, 4, 7, 4, 8, 4,
  107745. 8, 4, 8, 4, 8, 4, 9, 4, 9, 5,10, 5,10, 7,10, 8,
  107746. 10, 8,
  107747. };
  107748. static static_codebook _huff_book_line_128x17_3sub2 = {
  107749. 1, 50,
  107750. _huff_lengthlist_line_128x17_3sub2,
  107751. 0, 0, 0, 0, 0,
  107752. NULL,
  107753. NULL,
  107754. NULL,
  107755. NULL,
  107756. 0
  107757. };
  107758. static long _huff_lengthlist_line_128x17_3sub3[] = {
  107759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107762. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 4, 7, 5, 8, 5,11,
  107763. 6,10, 6,12, 7,12, 7,12, 8,12, 8,12,10,12,12,12,
  107764. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107765. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107766. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  107767. };
  107768. static static_codebook _huff_book_line_128x17_3sub3 = {
  107769. 1, 128,
  107770. _huff_lengthlist_line_128x17_3sub3,
  107771. 0, 0, 0, 0, 0,
  107772. NULL,
  107773. NULL,
  107774. NULL,
  107775. NULL,
  107776. 0
  107777. };
  107778. static long _huff_lengthlist_line_1024x27_class1[] = {
  107779. 2,10, 8,14, 7,12,11,14, 1, 5, 3, 7, 4, 9, 7,13,
  107780. };
  107781. static static_codebook _huff_book_line_1024x27_class1 = {
  107782. 1, 16,
  107783. _huff_lengthlist_line_1024x27_class1,
  107784. 0, 0, 0, 0, 0,
  107785. NULL,
  107786. NULL,
  107787. NULL,
  107788. NULL,
  107789. 0
  107790. };
  107791. static long _huff_lengthlist_line_1024x27_class2[] = {
  107792. 1, 4, 2, 6, 3, 7, 5, 7,
  107793. };
  107794. static static_codebook _huff_book_line_1024x27_class2 = {
  107795. 1, 8,
  107796. _huff_lengthlist_line_1024x27_class2,
  107797. 0, 0, 0, 0, 0,
  107798. NULL,
  107799. NULL,
  107800. NULL,
  107801. NULL,
  107802. 0
  107803. };
  107804. static long _huff_lengthlist_line_1024x27_class3[] = {
  107805. 1, 5, 7,21, 5, 8, 9,21,10, 9,12,20,20,16,20,20,
  107806. 4, 8, 9,20, 6, 8, 9,20,11,11,13,20,20,15,17,20,
  107807. 9,11,14,20, 8,10,15,20,11,13,15,20,20,20,20,20,
  107808. 20,20,20,20,13,20,20,20,18,18,20,20,20,20,20,20,
  107809. 3, 6, 8,20, 6, 7, 9,20,10, 9,12,20,20,20,20,20,
  107810. 5, 7, 9,20, 6, 6, 9,20,10, 9,12,20,20,20,20,20,
  107811. 8,10,13,20, 8, 9,12,20,11,10,12,20,20,20,20,20,
  107812. 18,20,20,20,15,17,18,20,18,17,18,20,20,20,20,20,
  107813. 7,10,12,20, 8, 9,11,20,14,13,14,20,20,20,20,20,
  107814. 6, 9,12,20, 7, 8,11,20,12,11,13,20,20,20,20,20,
  107815. 9,11,15,20, 8,10,14,20,12,11,14,20,20,20,20,20,
  107816. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107817. 11,16,18,20,15,15,17,20,20,17,20,20,20,20,20,20,
  107818. 9,14,16,20,12,12,15,20,17,15,18,20,20,20,20,20,
  107819. 16,19,18,20,15,16,20,20,17,17,20,20,20,20,20,20,
  107820. 20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,20,
  107821. };
  107822. static static_codebook _huff_book_line_1024x27_class3 = {
  107823. 1, 256,
  107824. _huff_lengthlist_line_1024x27_class3,
  107825. 0, 0, 0, 0, 0,
  107826. NULL,
  107827. NULL,
  107828. NULL,
  107829. NULL,
  107830. 0
  107831. };
  107832. static long _huff_lengthlist_line_1024x27_class4[] = {
  107833. 2, 3, 7,13, 4, 4, 7,15, 8, 6, 9,17,21,16,15,21,
  107834. 2, 5, 7,11, 5, 5, 7,14, 9, 7,10,16,17,15,16,21,
  107835. 4, 7,10,17, 7, 7, 9,15,11, 9,11,16,21,18,15,21,
  107836. 18,21,21,21,15,17,17,19,21,19,18,20,21,21,21,20,
  107837. };
  107838. static static_codebook _huff_book_line_1024x27_class4 = {
  107839. 1, 64,
  107840. _huff_lengthlist_line_1024x27_class4,
  107841. 0, 0, 0, 0, 0,
  107842. NULL,
  107843. NULL,
  107844. NULL,
  107845. NULL,
  107846. 0
  107847. };
  107848. static long _huff_lengthlist_line_1024x27_0sub0[] = {
  107849. 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107850. 6, 5, 6, 5, 6, 5, 6, 5, 7, 5, 7, 5, 7, 5, 7, 5,
  107851. 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,10, 6,10, 6,11, 6,
  107852. 11, 7,11, 7,12, 7,12, 7,12, 7,12, 7,12, 7,12, 7,
  107853. 12, 7,12, 8,13, 8,12, 8,12, 8,13, 8,13, 9,13, 9,
  107854. 13, 9,13, 9,12,10,12,10,13,10,14,11,14,12,14,13,
  107855. 14,13,14,14,15,16,15,15,15,14,15,17,21,22,22,21,
  107856. 22,22,22,22,22,22,21,21,21,21,21,21,21,21,21,21,
  107857. };
  107858. static static_codebook _huff_book_line_1024x27_0sub0 = {
  107859. 1, 128,
  107860. _huff_lengthlist_line_1024x27_0sub0,
  107861. 0, 0, 0, 0, 0,
  107862. NULL,
  107863. NULL,
  107864. NULL,
  107865. NULL,
  107866. 0
  107867. };
  107868. static long _huff_lengthlist_line_1024x27_1sub0[] = {
  107869. 2, 5, 5, 4, 5, 4, 5, 4, 5, 4, 6, 5, 6, 5, 6, 5,
  107870. 6, 5, 7, 5, 7, 6, 8, 6, 8, 6, 8, 6, 9, 6, 9, 6,
  107871. };
  107872. static static_codebook _huff_book_line_1024x27_1sub0 = {
  107873. 1, 32,
  107874. _huff_lengthlist_line_1024x27_1sub0,
  107875. 0, 0, 0, 0, 0,
  107876. NULL,
  107877. NULL,
  107878. NULL,
  107879. NULL,
  107880. 0
  107881. };
  107882. static long _huff_lengthlist_line_1024x27_1sub1[] = {
  107883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107885. 8, 5, 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 4,
  107886. 9, 4, 9, 4, 9, 4, 8, 4, 8, 4, 9, 5, 9, 5, 9, 5,
  107887. 9, 5, 9, 6,10, 6,10, 7,10, 8,11, 9,11,11,12,13,
  107888. 12,14,13,15,13,15,14,16,14,17,15,17,15,15,16,16,
  107889. 15,16,16,16,15,18,16,15,17,17,19,19,19,19,19,19,
  107890. 19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,
  107891. };
  107892. static static_codebook _huff_book_line_1024x27_1sub1 = {
  107893. 1, 128,
  107894. _huff_lengthlist_line_1024x27_1sub1,
  107895. 0, 0, 0, 0, 0,
  107896. NULL,
  107897. NULL,
  107898. NULL,
  107899. NULL,
  107900. 0
  107901. };
  107902. static long _huff_lengthlist_line_1024x27_2sub0[] = {
  107903. 1, 5, 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  107904. 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 9, 8,10, 9,10, 9,
  107905. };
  107906. static static_codebook _huff_book_line_1024x27_2sub0 = {
  107907. 1, 32,
  107908. _huff_lengthlist_line_1024x27_2sub0,
  107909. 0, 0, 0, 0, 0,
  107910. NULL,
  107911. NULL,
  107912. NULL,
  107913. NULL,
  107914. 0
  107915. };
  107916. static long _huff_lengthlist_line_1024x27_2sub1[] = {
  107917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107919. 4, 3, 4, 3, 4, 4, 5, 4, 5, 4, 5, 5, 6, 5, 6, 5,
  107920. 7, 5, 7, 6, 7, 6, 8, 7, 8, 7, 8, 7, 9, 8, 9, 9,
  107921. 9, 9,10,10,10,11, 9,12, 9,12, 9,15,10,14, 9,13,
  107922. 10,13,10,12,10,12,10,13,10,12,11,13,11,14,12,13,
  107923. 13,14,14,13,14,15,14,16,13,13,14,16,16,16,16,16,
  107924. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,15,15,
  107925. };
  107926. static static_codebook _huff_book_line_1024x27_2sub1 = {
  107927. 1, 128,
  107928. _huff_lengthlist_line_1024x27_2sub1,
  107929. 0, 0, 0, 0, 0,
  107930. NULL,
  107931. NULL,
  107932. NULL,
  107933. NULL,
  107934. 0
  107935. };
  107936. static long _huff_lengthlist_line_1024x27_3sub1[] = {
  107937. 0, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4, 4, 4, 4, 5,
  107938. 5, 5,
  107939. };
  107940. static static_codebook _huff_book_line_1024x27_3sub1 = {
  107941. 1, 18,
  107942. _huff_lengthlist_line_1024x27_3sub1,
  107943. 0, 0, 0, 0, 0,
  107944. NULL,
  107945. NULL,
  107946. NULL,
  107947. NULL,
  107948. 0
  107949. };
  107950. static long _huff_lengthlist_line_1024x27_3sub2[] = {
  107951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107952. 0, 0, 3, 3, 4, 3, 4, 4, 4, 4, 5, 5, 5, 5, 5, 6,
  107953. 5, 7, 5, 8, 6, 8, 6, 9, 7,10, 7,10, 8,10, 8,11,
  107954. 9,11,
  107955. };
  107956. static static_codebook _huff_book_line_1024x27_3sub2 = {
  107957. 1, 50,
  107958. _huff_lengthlist_line_1024x27_3sub2,
  107959. 0, 0, 0, 0, 0,
  107960. NULL,
  107961. NULL,
  107962. NULL,
  107963. NULL,
  107964. 0
  107965. };
  107966. static long _huff_lengthlist_line_1024x27_3sub3[] = {
  107967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  107970. 0, 0, 3, 7, 3, 8, 3,10, 3, 8, 3, 9, 3, 8, 4, 9,
  107971. 4, 9, 5, 9, 6,10, 6, 9, 7,11, 7,12, 9,13,10,13,
  107972. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107973. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107974. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  107975. };
  107976. static static_codebook _huff_book_line_1024x27_3sub3 = {
  107977. 1, 128,
  107978. _huff_lengthlist_line_1024x27_3sub3,
  107979. 0, 0, 0, 0, 0,
  107980. NULL,
  107981. NULL,
  107982. NULL,
  107983. NULL,
  107984. 0
  107985. };
  107986. static long _huff_lengthlist_line_1024x27_4sub1[] = {
  107987. 0, 4, 5, 4, 5, 4, 5, 4, 5, 3, 5, 3, 5, 3, 5, 4,
  107988. 5, 4,
  107989. };
  107990. static static_codebook _huff_book_line_1024x27_4sub1 = {
  107991. 1, 18,
  107992. _huff_lengthlist_line_1024x27_4sub1,
  107993. 0, 0, 0, 0, 0,
  107994. NULL,
  107995. NULL,
  107996. NULL,
  107997. NULL,
  107998. 0
  107999. };
  108000. static long _huff_lengthlist_line_1024x27_4sub2[] = {
  108001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108002. 0, 0, 4, 2, 4, 2, 5, 3, 5, 4, 6, 6, 6, 7, 7, 8,
  108003. 7, 8, 7, 8, 7, 9, 8, 9, 8, 9, 8,10, 8,11, 9,12,
  108004. 9,12,
  108005. };
  108006. static static_codebook _huff_book_line_1024x27_4sub2 = {
  108007. 1, 50,
  108008. _huff_lengthlist_line_1024x27_4sub2,
  108009. 0, 0, 0, 0, 0,
  108010. NULL,
  108011. NULL,
  108012. NULL,
  108013. NULL,
  108014. 0
  108015. };
  108016. static long _huff_lengthlist_line_1024x27_4sub3[] = {
  108017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108020. 0, 0, 2, 5, 2, 6, 3, 6, 4, 7, 4, 7, 5, 9, 5,11,
  108021. 6,11, 6,11, 7,11, 6,11, 6,11, 9,11, 8,11,11,11,
  108022. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108023. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  108024. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  108025. };
  108026. static static_codebook _huff_book_line_1024x27_4sub3 = {
  108027. 1, 128,
  108028. _huff_lengthlist_line_1024x27_4sub3,
  108029. 0, 0, 0, 0, 0,
  108030. NULL,
  108031. NULL,
  108032. NULL,
  108033. NULL,
  108034. 0
  108035. };
  108036. static long _huff_lengthlist_line_2048x27_class1[] = {
  108037. 2, 6, 8, 9, 7,11,13,13, 1, 3, 5, 5, 6, 6,12,10,
  108038. };
  108039. static static_codebook _huff_book_line_2048x27_class1 = {
  108040. 1, 16,
  108041. _huff_lengthlist_line_2048x27_class1,
  108042. 0, 0, 0, 0, 0,
  108043. NULL,
  108044. NULL,
  108045. NULL,
  108046. NULL,
  108047. 0
  108048. };
  108049. static long _huff_lengthlist_line_2048x27_class2[] = {
  108050. 1, 2, 3, 6, 4, 7, 5, 7,
  108051. };
  108052. static static_codebook _huff_book_line_2048x27_class2 = {
  108053. 1, 8,
  108054. _huff_lengthlist_line_2048x27_class2,
  108055. 0, 0, 0, 0, 0,
  108056. NULL,
  108057. NULL,
  108058. NULL,
  108059. NULL,
  108060. 0
  108061. };
  108062. static long _huff_lengthlist_line_2048x27_class3[] = {
  108063. 3, 3, 6,16, 5, 5, 7,16, 9, 8,11,16,16,16,16,16,
  108064. 5, 5, 8,16, 5, 5, 7,16, 8, 7, 9,16,16,16,16,16,
  108065. 9, 9,12,16, 6, 8,11,16, 9,10,11,16,16,16,16,16,
  108066. 16,16,16,16,13,16,16,16,15,16,16,16,16,16,16,16,
  108067. 5, 4, 7,16, 6, 5, 8,16, 9, 8,10,16,16,16,16,16,
  108068. 5, 5, 7,15, 5, 4, 6,15, 7, 6, 8,16,16,16,16,16,
  108069. 9, 9,11,15, 7, 7, 9,16, 8, 8, 9,16,16,16,16,16,
  108070. 16,16,16,16,15,15,15,16,15,15,14,16,16,16,16,16,
  108071. 8, 8,11,16, 8, 9,10,16,11,10,14,16,16,16,16,16,
  108072. 6, 8,10,16, 6, 7,10,16, 8, 8,11,16,14,16,16,16,
  108073. 10,11,14,16, 9, 9,11,16,10,10,11,16,16,16,16,16,
  108074. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108075. 16,16,16,16,15,16,16,16,16,16,16,16,16,16,16,16,
  108076. 12,16,15,16,12,14,16,16,16,16,16,16,16,16,16,16,
  108077. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108078. 16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,16,
  108079. };
  108080. static static_codebook _huff_book_line_2048x27_class3 = {
  108081. 1, 256,
  108082. _huff_lengthlist_line_2048x27_class3,
  108083. 0, 0, 0, 0, 0,
  108084. NULL,
  108085. NULL,
  108086. NULL,
  108087. NULL,
  108088. 0
  108089. };
  108090. static long _huff_lengthlist_line_2048x27_class4[] = {
  108091. 2, 4, 7,13, 4, 5, 7,15, 8, 7,10,16,16,14,16,16,
  108092. 2, 4, 7,16, 3, 4, 7,14, 8, 8,10,16,16,16,15,16,
  108093. 6, 8,11,16, 7, 7, 9,16,11, 9,13,16,16,16,15,16,
  108094. 16,16,16,16,14,16,16,16,16,16,16,16,16,16,16,16,
  108095. };
  108096. static static_codebook _huff_book_line_2048x27_class4 = {
  108097. 1, 64,
  108098. _huff_lengthlist_line_2048x27_class4,
  108099. 0, 0, 0, 0, 0,
  108100. NULL,
  108101. NULL,
  108102. NULL,
  108103. NULL,
  108104. 0
  108105. };
  108106. static long _huff_lengthlist_line_2048x27_0sub0[] = {
  108107. 5, 5, 5, 5, 5, 5, 6, 5, 6, 5, 6, 5, 6, 5, 6, 5,
  108108. 6, 5, 7, 5, 7, 5, 7, 5, 8, 5, 8, 5, 8, 5, 9, 5,
  108109. 9, 6,10, 6,10, 6,11, 6,11, 6,11, 6,11, 6,11, 6,
  108110. 11, 6,11, 6,12, 7,11, 7,11, 7,11, 7,11, 7,10, 7,
  108111. 11, 7,11, 7,12, 7,11, 8,11, 8,11, 8,11, 8,13, 8,
  108112. 12, 9,11, 9,11, 9,11,10,12,10,12, 9,12,10,12,11,
  108113. 14,12,16,12,12,11,14,16,17,17,17,17,17,17,17,17,
  108114. 17,17,17,17,17,17,17,17,17,17,17,17,16,16,16,16,
  108115. };
  108116. static static_codebook _huff_book_line_2048x27_0sub0 = {
  108117. 1, 128,
  108118. _huff_lengthlist_line_2048x27_0sub0,
  108119. 0, 0, 0, 0, 0,
  108120. NULL,
  108121. NULL,
  108122. NULL,
  108123. NULL,
  108124. 0
  108125. };
  108126. static long _huff_lengthlist_line_2048x27_1sub0[] = {
  108127. 4, 4, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5,
  108128. 5, 5, 6, 6, 6, 6, 6, 6, 7, 6, 7, 6, 7, 6, 7, 6,
  108129. };
  108130. static static_codebook _huff_book_line_2048x27_1sub0 = {
  108131. 1, 32,
  108132. _huff_lengthlist_line_2048x27_1sub0,
  108133. 0, 0, 0, 0, 0,
  108134. NULL,
  108135. NULL,
  108136. NULL,
  108137. NULL,
  108138. 0
  108139. };
  108140. static long _huff_lengthlist_line_2048x27_1sub1[] = {
  108141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108143. 6, 5, 7, 5, 7, 4, 7, 4, 8, 4, 8, 4, 8, 4, 8, 3,
  108144. 8, 4, 9, 4, 9, 4, 9, 4, 9, 4, 9, 5, 9, 5, 9, 6,
  108145. 9, 7, 9, 8, 9, 9, 9,10, 9,11, 9,14, 9,15,10,15,
  108146. 10,15,10,15,10,15,11,15,10,14,12,14,11,14,13,14,
  108147. 13,15,15,15,12,15,15,15,13,15,13,15,13,15,15,15,
  108148. 15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,
  108149. };
  108150. static static_codebook _huff_book_line_2048x27_1sub1 = {
  108151. 1, 128,
  108152. _huff_lengthlist_line_2048x27_1sub1,
  108153. 0, 0, 0, 0, 0,
  108154. NULL,
  108155. NULL,
  108156. NULL,
  108157. NULL,
  108158. 0
  108159. };
  108160. static long _huff_lengthlist_line_2048x27_2sub0[] = {
  108161. 2, 4, 5, 4, 5, 4, 5, 4, 5, 5, 5, 5, 5, 5, 6, 5,
  108162. 6, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  108163. };
  108164. static static_codebook _huff_book_line_2048x27_2sub0 = {
  108165. 1, 32,
  108166. _huff_lengthlist_line_2048x27_2sub0,
  108167. 0, 0, 0, 0, 0,
  108168. NULL,
  108169. NULL,
  108170. NULL,
  108171. NULL,
  108172. 0
  108173. };
  108174. static long _huff_lengthlist_line_2048x27_2sub1[] = {
  108175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108177. 3, 4, 3, 4, 3, 4, 4, 5, 4, 5, 5, 5, 6, 6, 6, 7,
  108178. 6, 8, 6, 8, 6, 9, 7,10, 7,10, 7,10, 7,12, 7,12,
  108179. 7,12, 9,12,11,12,10,12,10,12,11,12,12,12,10,12,
  108180. 10,12,10,12, 9,12,11,12,12,12,12,12,11,12,11,12,
  108181. 12,12,12,12,12,12,12,12,10,10,12,12,12,12,12,10,
  108182. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  108183. };
  108184. static static_codebook _huff_book_line_2048x27_2sub1 = {
  108185. 1, 128,
  108186. _huff_lengthlist_line_2048x27_2sub1,
  108187. 0, 0, 0, 0, 0,
  108188. NULL,
  108189. NULL,
  108190. NULL,
  108191. NULL,
  108192. 0
  108193. };
  108194. static long _huff_lengthlist_line_2048x27_3sub1[] = {
  108195. 0, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
  108196. 5, 5,
  108197. };
  108198. static static_codebook _huff_book_line_2048x27_3sub1 = {
  108199. 1, 18,
  108200. _huff_lengthlist_line_2048x27_3sub1,
  108201. 0, 0, 0, 0, 0,
  108202. NULL,
  108203. NULL,
  108204. NULL,
  108205. NULL,
  108206. 0
  108207. };
  108208. static long _huff_lengthlist_line_2048x27_3sub2[] = {
  108209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108210. 0, 0, 3, 3, 3, 4, 4, 4, 4, 4, 4, 5, 5, 5, 5, 6,
  108211. 6, 7, 6, 7, 6, 8, 6, 9, 7, 9, 7, 9, 9,11, 9,12,
  108212. 10,12,
  108213. };
  108214. static static_codebook _huff_book_line_2048x27_3sub2 = {
  108215. 1, 50,
  108216. _huff_lengthlist_line_2048x27_3sub2,
  108217. 0, 0, 0, 0, 0,
  108218. NULL,
  108219. NULL,
  108220. NULL,
  108221. NULL,
  108222. 0
  108223. };
  108224. static long _huff_lengthlist_line_2048x27_3sub3[] = {
  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, 3, 6, 3, 7, 3, 7, 5, 7, 7, 7, 7, 7, 6, 7,
  108229. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108230. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108231. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108232. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108233. };
  108234. static static_codebook _huff_book_line_2048x27_3sub3 = {
  108235. 1, 128,
  108236. _huff_lengthlist_line_2048x27_3sub3,
  108237. 0, 0, 0, 0, 0,
  108238. NULL,
  108239. NULL,
  108240. NULL,
  108241. NULL,
  108242. 0
  108243. };
  108244. static long _huff_lengthlist_line_2048x27_4sub1[] = {
  108245. 0, 3, 4, 4, 4, 4, 4, 4, 4, 4, 5, 4, 5, 4, 5, 4,
  108246. 4, 5,
  108247. };
  108248. static static_codebook _huff_book_line_2048x27_4sub1 = {
  108249. 1, 18,
  108250. _huff_lengthlist_line_2048x27_4sub1,
  108251. 0, 0, 0, 0, 0,
  108252. NULL,
  108253. NULL,
  108254. NULL,
  108255. NULL,
  108256. 0
  108257. };
  108258. static long _huff_lengthlist_line_2048x27_4sub2[] = {
  108259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108260. 0, 0, 3, 2, 4, 3, 4, 4, 4, 5, 5, 6, 5, 6, 5, 7,
  108261. 6, 6, 6, 7, 7, 7, 8, 9, 9, 9,12,10,11,10,10,12,
  108262. 10,10,
  108263. };
  108264. static static_codebook _huff_book_line_2048x27_4sub2 = {
  108265. 1, 50,
  108266. _huff_lengthlist_line_2048x27_4sub2,
  108267. 0, 0, 0, 0, 0,
  108268. NULL,
  108269. NULL,
  108270. NULL,
  108271. NULL,
  108272. 0
  108273. };
  108274. static long _huff_lengthlist_line_2048x27_4sub3[] = {
  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, 3, 6, 5, 7, 5, 7, 7, 7, 7, 7, 5, 7, 5, 7,
  108279. 5, 7, 5, 7, 7, 7, 7, 7, 4, 7, 7, 7, 7, 7, 7, 7,
  108280. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108281. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  108282. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  108283. };
  108284. static static_codebook _huff_book_line_2048x27_4sub3 = {
  108285. 1, 128,
  108286. _huff_lengthlist_line_2048x27_4sub3,
  108287. 0, 0, 0, 0, 0,
  108288. NULL,
  108289. NULL,
  108290. NULL,
  108291. NULL,
  108292. 0
  108293. };
  108294. static long _huff_lengthlist_line_256x4low_class0[] = {
  108295. 4, 5, 6,11, 5, 5, 6,10, 7, 7, 6, 6,14,13, 9, 9,
  108296. 6, 6, 6,10, 6, 6, 6, 9, 8, 7, 7, 9,14,12, 8,11,
  108297. 8, 7, 7,11, 8, 8, 7,11, 9, 9, 7, 9,13,11, 9,13,
  108298. 19,19,18,19,15,16,16,19,11,11,10,13,10,10, 9,15,
  108299. 5, 5, 6,13, 6, 6, 6,11, 8, 7, 6, 7,14,11,10,11,
  108300. 6, 6, 6,12, 7, 6, 6,11, 8, 7, 7,11,13,11, 9,11,
  108301. 9, 7, 6,12, 8, 7, 6,12, 9, 8, 8,11,13,10, 7,13,
  108302. 19,19,17,19,17,14,14,19,12,10, 8,12,13,10, 9,16,
  108303. 7, 8, 7,12, 7, 7, 7,11, 8, 7, 7, 8,12,12,11,11,
  108304. 8, 8, 7,12, 8, 7, 6,11, 8, 7, 7,10,10,11,10,11,
  108305. 9, 8, 8,13, 9, 8, 7,12,10, 9, 7,11, 9, 8, 7,11,
  108306. 18,18,15,18,18,16,17,18,15,11,10,18,11, 9, 9,18,
  108307. 16,16,13,16,12,11,10,16,12,11, 9, 6,15,12,11,13,
  108308. 16,16,14,14,13,11,12,16,12, 9, 9,13,13,10,10,12,
  108309. 17,18,17,17,14,15,14,16,14,12,14,15,12,10,11,12,
  108310. 18,18,18,18,18,18,18,18,18,12,13,18,16,11, 9,18,
  108311. };
  108312. static static_codebook _huff_book_line_256x4low_class0 = {
  108313. 1, 256,
  108314. _huff_lengthlist_line_256x4low_class0,
  108315. 0, 0, 0, 0, 0,
  108316. NULL,
  108317. NULL,
  108318. NULL,
  108319. NULL,
  108320. 0
  108321. };
  108322. static long _huff_lengthlist_line_256x4low_0sub0[] = {
  108323. 1, 3, 2, 3,
  108324. };
  108325. static static_codebook _huff_book_line_256x4low_0sub0 = {
  108326. 1, 4,
  108327. _huff_lengthlist_line_256x4low_0sub0,
  108328. 0, 0, 0, 0, 0,
  108329. NULL,
  108330. NULL,
  108331. NULL,
  108332. NULL,
  108333. 0
  108334. };
  108335. static long _huff_lengthlist_line_256x4low_0sub1[] = {
  108336. 0, 0, 0, 0, 2, 3, 2, 3, 3, 3,
  108337. };
  108338. static static_codebook _huff_book_line_256x4low_0sub1 = {
  108339. 1, 10,
  108340. _huff_lengthlist_line_256x4low_0sub1,
  108341. 0, 0, 0, 0, 0,
  108342. NULL,
  108343. NULL,
  108344. NULL,
  108345. NULL,
  108346. 0
  108347. };
  108348. static long _huff_lengthlist_line_256x4low_0sub2[] = {
  108349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 4, 3, 4,
  108350. 4, 4, 4, 4, 5, 5, 5, 6, 6,
  108351. };
  108352. static static_codebook _huff_book_line_256x4low_0sub2 = {
  108353. 1, 25,
  108354. _huff_lengthlist_line_256x4low_0sub2,
  108355. 0, 0, 0, 0, 0,
  108356. NULL,
  108357. NULL,
  108358. NULL,
  108359. NULL,
  108360. 0
  108361. };
  108362. static long _huff_lengthlist_line_256x4low_0sub3[] = {
  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, 3, 4, 2, 4, 3, 5, 4,
  108365. 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 7, 7, 8, 6, 9,
  108366. 7,12,11,16,13,16,12,15,13,15,12,14,12,15,15,15,
  108367. };
  108368. static static_codebook _huff_book_line_256x4low_0sub3 = {
  108369. 1, 64,
  108370. _huff_lengthlist_line_256x4low_0sub3,
  108371. 0, 0, 0, 0, 0,
  108372. NULL,
  108373. NULL,
  108374. NULL,
  108375. NULL,
  108376. 0
  108377. };
  108378. /*** End of inlined file: floor_books.h ***/
  108379. static static_codebook *_floor_128x4_books[]={
  108380. &_huff_book_line_128x4_class0,
  108381. &_huff_book_line_128x4_0sub0,
  108382. &_huff_book_line_128x4_0sub1,
  108383. &_huff_book_line_128x4_0sub2,
  108384. &_huff_book_line_128x4_0sub3,
  108385. };
  108386. static static_codebook *_floor_256x4_books[]={
  108387. &_huff_book_line_256x4_class0,
  108388. &_huff_book_line_256x4_0sub0,
  108389. &_huff_book_line_256x4_0sub1,
  108390. &_huff_book_line_256x4_0sub2,
  108391. &_huff_book_line_256x4_0sub3,
  108392. };
  108393. static static_codebook *_floor_128x7_books[]={
  108394. &_huff_book_line_128x7_class0,
  108395. &_huff_book_line_128x7_class1,
  108396. &_huff_book_line_128x7_0sub1,
  108397. &_huff_book_line_128x7_0sub2,
  108398. &_huff_book_line_128x7_0sub3,
  108399. &_huff_book_line_128x7_1sub1,
  108400. &_huff_book_line_128x7_1sub2,
  108401. &_huff_book_line_128x7_1sub3,
  108402. };
  108403. static static_codebook *_floor_256x7_books[]={
  108404. &_huff_book_line_256x7_class0,
  108405. &_huff_book_line_256x7_class1,
  108406. &_huff_book_line_256x7_0sub1,
  108407. &_huff_book_line_256x7_0sub2,
  108408. &_huff_book_line_256x7_0sub3,
  108409. &_huff_book_line_256x7_1sub1,
  108410. &_huff_book_line_256x7_1sub2,
  108411. &_huff_book_line_256x7_1sub3,
  108412. };
  108413. static static_codebook *_floor_128x11_books[]={
  108414. &_huff_book_line_128x11_class1,
  108415. &_huff_book_line_128x11_class2,
  108416. &_huff_book_line_128x11_class3,
  108417. &_huff_book_line_128x11_0sub0,
  108418. &_huff_book_line_128x11_1sub0,
  108419. &_huff_book_line_128x11_1sub1,
  108420. &_huff_book_line_128x11_2sub1,
  108421. &_huff_book_line_128x11_2sub2,
  108422. &_huff_book_line_128x11_2sub3,
  108423. &_huff_book_line_128x11_3sub1,
  108424. &_huff_book_line_128x11_3sub2,
  108425. &_huff_book_line_128x11_3sub3,
  108426. };
  108427. static static_codebook *_floor_128x17_books[]={
  108428. &_huff_book_line_128x17_class1,
  108429. &_huff_book_line_128x17_class2,
  108430. &_huff_book_line_128x17_class3,
  108431. &_huff_book_line_128x17_0sub0,
  108432. &_huff_book_line_128x17_1sub0,
  108433. &_huff_book_line_128x17_1sub1,
  108434. &_huff_book_line_128x17_2sub1,
  108435. &_huff_book_line_128x17_2sub2,
  108436. &_huff_book_line_128x17_2sub3,
  108437. &_huff_book_line_128x17_3sub1,
  108438. &_huff_book_line_128x17_3sub2,
  108439. &_huff_book_line_128x17_3sub3,
  108440. };
  108441. static static_codebook *_floor_256x4low_books[]={
  108442. &_huff_book_line_256x4low_class0,
  108443. &_huff_book_line_256x4low_0sub0,
  108444. &_huff_book_line_256x4low_0sub1,
  108445. &_huff_book_line_256x4low_0sub2,
  108446. &_huff_book_line_256x4low_0sub3,
  108447. };
  108448. static static_codebook *_floor_1024x27_books[]={
  108449. &_huff_book_line_1024x27_class1,
  108450. &_huff_book_line_1024x27_class2,
  108451. &_huff_book_line_1024x27_class3,
  108452. &_huff_book_line_1024x27_class4,
  108453. &_huff_book_line_1024x27_0sub0,
  108454. &_huff_book_line_1024x27_1sub0,
  108455. &_huff_book_line_1024x27_1sub1,
  108456. &_huff_book_line_1024x27_2sub0,
  108457. &_huff_book_line_1024x27_2sub1,
  108458. &_huff_book_line_1024x27_3sub1,
  108459. &_huff_book_line_1024x27_3sub2,
  108460. &_huff_book_line_1024x27_3sub3,
  108461. &_huff_book_line_1024x27_4sub1,
  108462. &_huff_book_line_1024x27_4sub2,
  108463. &_huff_book_line_1024x27_4sub3,
  108464. };
  108465. static static_codebook *_floor_2048x27_books[]={
  108466. &_huff_book_line_2048x27_class1,
  108467. &_huff_book_line_2048x27_class2,
  108468. &_huff_book_line_2048x27_class3,
  108469. &_huff_book_line_2048x27_class4,
  108470. &_huff_book_line_2048x27_0sub0,
  108471. &_huff_book_line_2048x27_1sub0,
  108472. &_huff_book_line_2048x27_1sub1,
  108473. &_huff_book_line_2048x27_2sub0,
  108474. &_huff_book_line_2048x27_2sub1,
  108475. &_huff_book_line_2048x27_3sub1,
  108476. &_huff_book_line_2048x27_3sub2,
  108477. &_huff_book_line_2048x27_3sub3,
  108478. &_huff_book_line_2048x27_4sub1,
  108479. &_huff_book_line_2048x27_4sub2,
  108480. &_huff_book_line_2048x27_4sub3,
  108481. };
  108482. static static_codebook *_floor_512x17_books[]={
  108483. &_huff_book_line_512x17_class1,
  108484. &_huff_book_line_512x17_class2,
  108485. &_huff_book_line_512x17_class3,
  108486. &_huff_book_line_512x17_0sub0,
  108487. &_huff_book_line_512x17_1sub0,
  108488. &_huff_book_line_512x17_1sub1,
  108489. &_huff_book_line_512x17_2sub1,
  108490. &_huff_book_line_512x17_2sub2,
  108491. &_huff_book_line_512x17_2sub3,
  108492. &_huff_book_line_512x17_3sub1,
  108493. &_huff_book_line_512x17_3sub2,
  108494. &_huff_book_line_512x17_3sub3,
  108495. };
  108496. static static_codebook **_floor_books[10]={
  108497. _floor_128x4_books,
  108498. _floor_256x4_books,
  108499. _floor_128x7_books,
  108500. _floor_256x7_books,
  108501. _floor_128x11_books,
  108502. _floor_128x17_books,
  108503. _floor_256x4low_books,
  108504. _floor_1024x27_books,
  108505. _floor_2048x27_books,
  108506. _floor_512x17_books,
  108507. };
  108508. static vorbis_info_floor1 _floor[10]={
  108509. {
  108510. 1,{0},{4},{2},{0},
  108511. {{1,2,3,4}},
  108512. 4,{0,128, 33,8,16,70},
  108513. 60,30,500, 1.,18., -1
  108514. },
  108515. {
  108516. 1,{0},{4},{2},{0},
  108517. {{1,2,3,4}},
  108518. 4,{0,256, 66,16,32,140},
  108519. 60,30,500, 1.,18., -1
  108520. },
  108521. {
  108522. 2,{0,1},{3,4},{2,2},{0,1},
  108523. {{-1,2,3,4},{-1,5,6,7}},
  108524. 4,{0,128, 14,4,58, 2,8,28,90},
  108525. 60,30,500, 1.,18., -1
  108526. },
  108527. {
  108528. 2,{0,1},{3,4},{2,2},{0,1},
  108529. {{-1,2,3,4},{-1,5,6,7}},
  108530. 4,{0,256, 28,8,116, 4,16,56,180},
  108531. 60,30,500, 1.,18., -1
  108532. },
  108533. {
  108534. 4,{0,1,2,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108535. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108536. 2,{0,128, 8,33, 4,16,70, 2,6,12, 23,46,90},
  108537. 60,30,500, 1,18., -1
  108538. },
  108539. {
  108540. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108541. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108542. 2,{0,128, 12,46, 4,8,16, 23,33,70, 2,6,10, 14,19,28, 39,58,90},
  108543. 60,30,500, 1,18., -1
  108544. },
  108545. {
  108546. 1,{0},{4},{2},{0},
  108547. {{1,2,3,4}},
  108548. 4,{0,256, 66,16,32,140},
  108549. 60,30,500, 1.,18., -1
  108550. },
  108551. {
  108552. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108553. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108554. 2,{0,1024, 93,23,372, 6,46,186,750, 14,33,65, 130,260,556,
  108555. 3,10,18,28, 39,55,79,111, 158,220,312, 464,650,850},
  108556. 60,30,500, 3,18., -1 /* lowpass */
  108557. },
  108558. {
  108559. 8,{0,1,2,2,3,3,4,4},{3,4,3,4,3},{0,1,1,2,2},{-1,0,1,2,3},
  108560. {{4},{5,6},{7,8},{-1,9,10,11},{-1,12,13,14}},
  108561. 2,{0,2048, 186,46,744, 12,92,372,1500, 28,66,130, 260,520,1112,
  108562. 6,20,36,56, 78,110,158,222, 316,440,624, 928,1300,1700},
  108563. 60,30,500, 3,18., -1 /* lowpass */
  108564. },
  108565. {
  108566. 6,{0,1,1,2,3,3},{2,3,3,3},{0,1,2,2},{-1,0,1,2},
  108567. {{3},{4,5},{-1,6,7,8},{-1,9,10,11}},
  108568. 2,{0,512, 46,186, 16,33,65, 93,130,278,
  108569. 7,23,39, 55,79,110, 156,232,360},
  108570. 60,30,500, 1,18., -1 /* lowpass! */
  108571. },
  108572. };
  108573. /*** End of inlined file: floor_all.h ***/
  108574. /*** Start of inlined file: residue_44.h ***/
  108575. /*** Start of inlined file: res_books_stereo.h ***/
  108576. static long _vq_quantlist__16c0_s_p1_0[] = {
  108577. 1,
  108578. 0,
  108579. 2,
  108580. };
  108581. static long _vq_lengthlist__16c0_s_p1_0[] = {
  108582. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  108583. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0,
  108588. 0, 0, 0, 7, 9,10, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  108593. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108610. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108611. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108612. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108613. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108614. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108615. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108616. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108617. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108618. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108619. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108620. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108621. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108622. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108623. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108624. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108625. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108626. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108627. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  108628. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108629. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0, 0,
  108633. 0, 0, 0, 9, 9,12, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108636. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108637. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  108638. 0, 0, 0, 0, 9,12,10, 0, 0, 0, 0, 0, 0,10,11,12,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  108674. 0, 0, 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108678. 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,12,11, 0,
  108679. 0, 0, 0, 0, 0, 9,10,12, 0, 0, 0, 0, 0, 0, 0, 0,
  108680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108683. 0, 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,12,
  108684. 0, 0, 0, 0, 0, 0, 9,12, 9, 0, 0, 0, 0, 0, 0, 0,
  108685. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108686. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108687. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108688. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108689. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108690. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108691. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108692. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108693. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108694. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108695. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108696. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108699. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108763. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108768. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108773. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108774. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108775. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108776. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108777. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108778. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108779. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108780. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108781. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108782. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108786. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108787. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108791. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  108992. 0,
  108993. };
  108994. static float _vq_quantthresh__16c0_s_p1_0[] = {
  108995. -0.5, 0.5,
  108996. };
  108997. static long _vq_quantmap__16c0_s_p1_0[] = {
  108998. 1, 0, 2,
  108999. };
  109000. static encode_aux_threshmatch _vq_auxt__16c0_s_p1_0 = {
  109001. _vq_quantthresh__16c0_s_p1_0,
  109002. _vq_quantmap__16c0_s_p1_0,
  109003. 3,
  109004. 3
  109005. };
  109006. static static_codebook _16c0_s_p1_0 = {
  109007. 8, 6561,
  109008. _vq_lengthlist__16c0_s_p1_0,
  109009. 1, -535822336, 1611661312, 2, 0,
  109010. _vq_quantlist__16c0_s_p1_0,
  109011. NULL,
  109012. &_vq_auxt__16c0_s_p1_0,
  109013. NULL,
  109014. 0
  109015. };
  109016. static long _vq_quantlist__16c0_s_p2_0[] = {
  109017. 2,
  109018. 1,
  109019. 3,
  109020. 0,
  109021. 4,
  109022. };
  109023. static long _vq_lengthlist__16c0_s_p2_0[] = {
  109024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109063. 0,
  109064. };
  109065. static float _vq_quantthresh__16c0_s_p2_0[] = {
  109066. -1.5, -0.5, 0.5, 1.5,
  109067. };
  109068. static long _vq_quantmap__16c0_s_p2_0[] = {
  109069. 3, 1, 0, 2, 4,
  109070. };
  109071. static encode_aux_threshmatch _vq_auxt__16c0_s_p2_0 = {
  109072. _vq_quantthresh__16c0_s_p2_0,
  109073. _vq_quantmap__16c0_s_p2_0,
  109074. 5,
  109075. 5
  109076. };
  109077. static static_codebook _16c0_s_p2_0 = {
  109078. 4, 625,
  109079. _vq_lengthlist__16c0_s_p2_0,
  109080. 1, -533725184, 1611661312, 3, 0,
  109081. _vq_quantlist__16c0_s_p2_0,
  109082. NULL,
  109083. &_vq_auxt__16c0_s_p2_0,
  109084. NULL,
  109085. 0
  109086. };
  109087. static long _vq_quantlist__16c0_s_p3_0[] = {
  109088. 2,
  109089. 1,
  109090. 3,
  109091. 0,
  109092. 4,
  109093. };
  109094. static long _vq_lengthlist__16c0_s_p3_0[] = {
  109095. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 7, 6, 0, 0,
  109097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109098. 0, 0, 4, 6, 6, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  109100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109101. 0, 0, 0, 0, 6, 6, 6, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  109102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109134. 0,
  109135. };
  109136. static float _vq_quantthresh__16c0_s_p3_0[] = {
  109137. -1.5, -0.5, 0.5, 1.5,
  109138. };
  109139. static long _vq_quantmap__16c0_s_p3_0[] = {
  109140. 3, 1, 0, 2, 4,
  109141. };
  109142. static encode_aux_threshmatch _vq_auxt__16c0_s_p3_0 = {
  109143. _vq_quantthresh__16c0_s_p3_0,
  109144. _vq_quantmap__16c0_s_p3_0,
  109145. 5,
  109146. 5
  109147. };
  109148. static static_codebook _16c0_s_p3_0 = {
  109149. 4, 625,
  109150. _vq_lengthlist__16c0_s_p3_0,
  109151. 1, -533725184, 1611661312, 3, 0,
  109152. _vq_quantlist__16c0_s_p3_0,
  109153. NULL,
  109154. &_vq_auxt__16c0_s_p3_0,
  109155. NULL,
  109156. 0
  109157. };
  109158. static long _vq_quantlist__16c0_s_p4_0[] = {
  109159. 4,
  109160. 3,
  109161. 5,
  109162. 2,
  109163. 6,
  109164. 1,
  109165. 7,
  109166. 0,
  109167. 8,
  109168. };
  109169. static long _vq_lengthlist__16c0_s_p4_0[] = {
  109170. 1, 3, 2, 7, 8, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  109171. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  109172. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  109173. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  109174. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109175. 0,
  109176. };
  109177. static float _vq_quantthresh__16c0_s_p4_0[] = {
  109178. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109179. };
  109180. static long _vq_quantmap__16c0_s_p4_0[] = {
  109181. 7, 5, 3, 1, 0, 2, 4, 6,
  109182. 8,
  109183. };
  109184. static encode_aux_threshmatch _vq_auxt__16c0_s_p4_0 = {
  109185. _vq_quantthresh__16c0_s_p4_0,
  109186. _vq_quantmap__16c0_s_p4_0,
  109187. 9,
  109188. 9
  109189. };
  109190. static static_codebook _16c0_s_p4_0 = {
  109191. 2, 81,
  109192. _vq_lengthlist__16c0_s_p4_0,
  109193. 1, -531628032, 1611661312, 4, 0,
  109194. _vq_quantlist__16c0_s_p4_0,
  109195. NULL,
  109196. &_vq_auxt__16c0_s_p4_0,
  109197. NULL,
  109198. 0
  109199. };
  109200. static long _vq_quantlist__16c0_s_p5_0[] = {
  109201. 4,
  109202. 3,
  109203. 5,
  109204. 2,
  109205. 6,
  109206. 1,
  109207. 7,
  109208. 0,
  109209. 8,
  109210. };
  109211. static long _vq_lengthlist__16c0_s_p5_0[] = {
  109212. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  109213. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 8, 0, 0, 0, 7, 7,
  109214. 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0, 0, 0,
  109215. 8, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  109216. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  109217. 10,
  109218. };
  109219. static float _vq_quantthresh__16c0_s_p5_0[] = {
  109220. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  109221. };
  109222. static long _vq_quantmap__16c0_s_p5_0[] = {
  109223. 7, 5, 3, 1, 0, 2, 4, 6,
  109224. 8,
  109225. };
  109226. static encode_aux_threshmatch _vq_auxt__16c0_s_p5_0 = {
  109227. _vq_quantthresh__16c0_s_p5_0,
  109228. _vq_quantmap__16c0_s_p5_0,
  109229. 9,
  109230. 9
  109231. };
  109232. static static_codebook _16c0_s_p5_0 = {
  109233. 2, 81,
  109234. _vq_lengthlist__16c0_s_p5_0,
  109235. 1, -531628032, 1611661312, 4, 0,
  109236. _vq_quantlist__16c0_s_p5_0,
  109237. NULL,
  109238. &_vq_auxt__16c0_s_p5_0,
  109239. NULL,
  109240. 0
  109241. };
  109242. static long _vq_quantlist__16c0_s_p6_0[] = {
  109243. 8,
  109244. 7,
  109245. 9,
  109246. 6,
  109247. 10,
  109248. 5,
  109249. 11,
  109250. 4,
  109251. 12,
  109252. 3,
  109253. 13,
  109254. 2,
  109255. 14,
  109256. 1,
  109257. 15,
  109258. 0,
  109259. 16,
  109260. };
  109261. static long _vq_lengthlist__16c0_s_p6_0[] = {
  109262. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  109263. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  109264. 11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  109265. 11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  109266. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  109267. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  109268. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  109269. 10,11,11,12,12,12,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  109270. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10,10,10,
  109271. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  109272. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  109273. 9,10,10,11,11,12,12,13,13,13,14, 0, 0, 0, 0, 0,
  109274. 10,10,10,11,11,11,12,12,13,13,13,14, 0, 0, 0, 0,
  109275. 0, 0, 0,10,10,11,11,12,12,13,13,14,14, 0, 0, 0,
  109276. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  109277. 0, 0, 0, 0, 0,11,11,12,12,12,13,13,14,15,14, 0,
  109278. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,14,14,15,
  109279. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,13,14,
  109280. 14,
  109281. };
  109282. static float _vq_quantthresh__16c0_s_p6_0[] = {
  109283. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  109284. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  109285. };
  109286. static long _vq_quantmap__16c0_s_p6_0[] = {
  109287. 15, 13, 11, 9, 7, 5, 3, 1,
  109288. 0, 2, 4, 6, 8, 10, 12, 14,
  109289. 16,
  109290. };
  109291. static encode_aux_threshmatch _vq_auxt__16c0_s_p6_0 = {
  109292. _vq_quantthresh__16c0_s_p6_0,
  109293. _vq_quantmap__16c0_s_p6_0,
  109294. 17,
  109295. 17
  109296. };
  109297. static static_codebook _16c0_s_p6_0 = {
  109298. 2, 289,
  109299. _vq_lengthlist__16c0_s_p6_0,
  109300. 1, -529530880, 1611661312, 5, 0,
  109301. _vq_quantlist__16c0_s_p6_0,
  109302. NULL,
  109303. &_vq_auxt__16c0_s_p6_0,
  109304. NULL,
  109305. 0
  109306. };
  109307. static long _vq_quantlist__16c0_s_p7_0[] = {
  109308. 1,
  109309. 0,
  109310. 2,
  109311. };
  109312. static long _vq_lengthlist__16c0_s_p7_0[] = {
  109313. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,11,10,10,11,
  109314. 11,10, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  109315. 11,11,11,10, 6, 9, 9,11,12,12,11, 9, 9, 6, 9,10,
  109316. 11,12,12,11, 9,10, 7,11,11,11,11,11,12,13,12, 6,
  109317. 9,10,11,10,10,12,13,13, 6,10, 9,11,10,10,11,12,
  109318. 13,
  109319. };
  109320. static float _vq_quantthresh__16c0_s_p7_0[] = {
  109321. -5.5, 5.5,
  109322. };
  109323. static long _vq_quantmap__16c0_s_p7_0[] = {
  109324. 1, 0, 2,
  109325. };
  109326. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_0 = {
  109327. _vq_quantthresh__16c0_s_p7_0,
  109328. _vq_quantmap__16c0_s_p7_0,
  109329. 3,
  109330. 3
  109331. };
  109332. static static_codebook _16c0_s_p7_0 = {
  109333. 4, 81,
  109334. _vq_lengthlist__16c0_s_p7_0,
  109335. 1, -529137664, 1618345984, 2, 0,
  109336. _vq_quantlist__16c0_s_p7_0,
  109337. NULL,
  109338. &_vq_auxt__16c0_s_p7_0,
  109339. NULL,
  109340. 0
  109341. };
  109342. static long _vq_quantlist__16c0_s_p7_1[] = {
  109343. 5,
  109344. 4,
  109345. 6,
  109346. 3,
  109347. 7,
  109348. 2,
  109349. 8,
  109350. 1,
  109351. 9,
  109352. 0,
  109353. 10,
  109354. };
  109355. static long _vq_lengthlist__16c0_s_p7_1[] = {
  109356. 1, 3, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7,
  109357. 8, 8, 8, 9, 9, 9,10,10,10, 6, 7, 8, 8, 8, 8, 9,
  109358. 8,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10, 7,
  109359. 7, 8, 8, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9, 9,
  109360. 9, 9,11,11,11, 8, 8, 9, 9, 9, 9, 9,10,10,11,11,
  109361. 9, 9, 9, 9, 9, 9, 9,10,11,11,11,10,11, 9, 9, 9,
  109362. 9,10, 9,11,11,11,10,11,10,10, 9, 9,10,10,11,11,
  109363. 11,11,11, 9, 9, 9, 9,10,10,
  109364. };
  109365. static float _vq_quantthresh__16c0_s_p7_1[] = {
  109366. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  109367. 3.5, 4.5,
  109368. };
  109369. static long _vq_quantmap__16c0_s_p7_1[] = {
  109370. 9, 7, 5, 3, 1, 0, 2, 4,
  109371. 6, 8, 10,
  109372. };
  109373. static encode_aux_threshmatch _vq_auxt__16c0_s_p7_1 = {
  109374. _vq_quantthresh__16c0_s_p7_1,
  109375. _vq_quantmap__16c0_s_p7_1,
  109376. 11,
  109377. 11
  109378. };
  109379. static static_codebook _16c0_s_p7_1 = {
  109380. 2, 121,
  109381. _vq_lengthlist__16c0_s_p7_1,
  109382. 1, -531365888, 1611661312, 4, 0,
  109383. _vq_quantlist__16c0_s_p7_1,
  109384. NULL,
  109385. &_vq_auxt__16c0_s_p7_1,
  109386. NULL,
  109387. 0
  109388. };
  109389. static long _vq_quantlist__16c0_s_p8_0[] = {
  109390. 6,
  109391. 5,
  109392. 7,
  109393. 4,
  109394. 8,
  109395. 3,
  109396. 9,
  109397. 2,
  109398. 10,
  109399. 1,
  109400. 11,
  109401. 0,
  109402. 12,
  109403. };
  109404. static long _vq_lengthlist__16c0_s_p8_0[] = {
  109405. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8,10,10, 6, 5, 6,
  109406. 8, 8, 8, 8, 8, 8, 8, 9,10,10, 7, 6, 6, 8, 8, 8,
  109407. 8, 8, 8, 8, 8,10,10, 0, 8, 8, 8, 8, 9, 8, 9, 9,
  109408. 9,10,10,10, 0, 9, 8, 8, 8, 9, 9, 8, 8, 9, 9,10,
  109409. 10, 0,12,11, 8, 8, 9, 9, 9, 9,10,10,11,10, 0,12,
  109410. 13, 8, 8, 9,10, 9, 9,11,11,11,12, 0, 0, 0, 8, 8,
  109411. 8, 8,10, 9,12,13,12,14, 0, 0, 0, 8, 8, 8, 9,10,
  109412. 10,12,12,13,14, 0, 0, 0,13,13, 9, 9,11,11, 0, 0,
  109413. 14, 0, 0, 0, 0,14,14,10,10,12,11,12,14,14,14, 0,
  109414. 0, 0, 0, 0,11,11,13,13,14,13,14,14, 0, 0, 0, 0,
  109415. 0,12,13,13,12,13,14,14,14,
  109416. };
  109417. static float _vq_quantthresh__16c0_s_p8_0[] = {
  109418. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  109419. 12.5, 17.5, 22.5, 27.5,
  109420. };
  109421. static long _vq_quantmap__16c0_s_p8_0[] = {
  109422. 11, 9, 7, 5, 3, 1, 0, 2,
  109423. 4, 6, 8, 10, 12,
  109424. };
  109425. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_0 = {
  109426. _vq_quantthresh__16c0_s_p8_0,
  109427. _vq_quantmap__16c0_s_p8_0,
  109428. 13,
  109429. 13
  109430. };
  109431. static static_codebook _16c0_s_p8_0 = {
  109432. 2, 169,
  109433. _vq_lengthlist__16c0_s_p8_0,
  109434. 1, -526516224, 1616117760, 4, 0,
  109435. _vq_quantlist__16c0_s_p8_0,
  109436. NULL,
  109437. &_vq_auxt__16c0_s_p8_0,
  109438. NULL,
  109439. 0
  109440. };
  109441. static long _vq_quantlist__16c0_s_p8_1[] = {
  109442. 2,
  109443. 1,
  109444. 3,
  109445. 0,
  109446. 4,
  109447. };
  109448. static long _vq_lengthlist__16c0_s_p8_1[] = {
  109449. 1, 4, 3, 5, 5, 7, 7, 7, 6, 6, 7, 7, 7, 5, 5, 7,
  109450. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  109451. };
  109452. static float _vq_quantthresh__16c0_s_p8_1[] = {
  109453. -1.5, -0.5, 0.5, 1.5,
  109454. };
  109455. static long _vq_quantmap__16c0_s_p8_1[] = {
  109456. 3, 1, 0, 2, 4,
  109457. };
  109458. static encode_aux_threshmatch _vq_auxt__16c0_s_p8_1 = {
  109459. _vq_quantthresh__16c0_s_p8_1,
  109460. _vq_quantmap__16c0_s_p8_1,
  109461. 5,
  109462. 5
  109463. };
  109464. static static_codebook _16c0_s_p8_1 = {
  109465. 2, 25,
  109466. _vq_lengthlist__16c0_s_p8_1,
  109467. 1, -533725184, 1611661312, 3, 0,
  109468. _vq_quantlist__16c0_s_p8_1,
  109469. NULL,
  109470. &_vq_auxt__16c0_s_p8_1,
  109471. NULL,
  109472. 0
  109473. };
  109474. static long _vq_quantlist__16c0_s_p9_0[] = {
  109475. 1,
  109476. 0,
  109477. 2,
  109478. };
  109479. static long _vq_lengthlist__16c0_s_p9_0[] = {
  109480. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109481. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  109482. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109483. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109484. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  109485. 7,
  109486. };
  109487. static float _vq_quantthresh__16c0_s_p9_0[] = {
  109488. -157.5, 157.5,
  109489. };
  109490. static long _vq_quantmap__16c0_s_p9_0[] = {
  109491. 1, 0, 2,
  109492. };
  109493. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_0 = {
  109494. _vq_quantthresh__16c0_s_p9_0,
  109495. _vq_quantmap__16c0_s_p9_0,
  109496. 3,
  109497. 3
  109498. };
  109499. static static_codebook _16c0_s_p9_0 = {
  109500. 4, 81,
  109501. _vq_lengthlist__16c0_s_p9_0,
  109502. 1, -518803456, 1628680192, 2, 0,
  109503. _vq_quantlist__16c0_s_p9_0,
  109504. NULL,
  109505. &_vq_auxt__16c0_s_p9_0,
  109506. NULL,
  109507. 0
  109508. };
  109509. static long _vq_quantlist__16c0_s_p9_1[] = {
  109510. 7,
  109511. 6,
  109512. 8,
  109513. 5,
  109514. 9,
  109515. 4,
  109516. 10,
  109517. 3,
  109518. 11,
  109519. 2,
  109520. 12,
  109521. 1,
  109522. 13,
  109523. 0,
  109524. 14,
  109525. };
  109526. static long _vq_lengthlist__16c0_s_p9_1[] = {
  109527. 1, 5, 5, 5, 5, 9,11,11,10,10,10,10,10,10,10, 7,
  109528. 6, 6, 6, 6,10,10,10,10,10,10,10,10,10,10, 7, 6,
  109529. 6, 6, 6,10, 9,10,10,10,10,10,10,10,10,10, 7, 7,
  109530. 8, 9,10,10,10,10,10,10,10,10,10,10,10, 8, 7,10,
  109531. 10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109532. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109533. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109534. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109535. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109536. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109537. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109538. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109539. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109540. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  109541. 10,
  109542. };
  109543. static float _vq_quantthresh__16c0_s_p9_1[] = {
  109544. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  109545. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  109546. };
  109547. static long _vq_quantmap__16c0_s_p9_1[] = {
  109548. 13, 11, 9, 7, 5, 3, 1, 0,
  109549. 2, 4, 6, 8, 10, 12, 14,
  109550. };
  109551. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_1 = {
  109552. _vq_quantthresh__16c0_s_p9_1,
  109553. _vq_quantmap__16c0_s_p9_1,
  109554. 15,
  109555. 15
  109556. };
  109557. static static_codebook _16c0_s_p9_1 = {
  109558. 2, 225,
  109559. _vq_lengthlist__16c0_s_p9_1,
  109560. 1, -520986624, 1620377600, 4, 0,
  109561. _vq_quantlist__16c0_s_p9_1,
  109562. NULL,
  109563. &_vq_auxt__16c0_s_p9_1,
  109564. NULL,
  109565. 0
  109566. };
  109567. static long _vq_quantlist__16c0_s_p9_2[] = {
  109568. 10,
  109569. 9,
  109570. 11,
  109571. 8,
  109572. 12,
  109573. 7,
  109574. 13,
  109575. 6,
  109576. 14,
  109577. 5,
  109578. 15,
  109579. 4,
  109580. 16,
  109581. 3,
  109582. 17,
  109583. 2,
  109584. 18,
  109585. 1,
  109586. 19,
  109587. 0,
  109588. 20,
  109589. };
  109590. static long _vq_lengthlist__16c0_s_p9_2[] = {
  109591. 1, 5, 5, 7, 8, 8, 7, 9, 9, 9,12,12,11,12,12,10,
  109592. 10,11,12,12,12,11,12,12, 8, 9, 8, 7, 9,10,10,11,
  109593. 11,10,11,12,10,12,10,12,12,12,11,12,11, 9, 8, 8,
  109594. 9,10, 9, 8, 9,10,12,12,11,11,12,11,10,11,12,11,
  109595. 12,12, 8, 9, 9, 9,10,11,12,11,12,11,11,11,11,12,
  109596. 12,11,11,12,12,11,11, 9, 9, 8, 9, 9,11, 9, 9,10,
  109597. 9,11,11,11,11,12,11,11,10,12,12,12, 9,12,11,10,
  109598. 11,11,11,11,12,12,12,11,11,11,12,10,12,12,12,10,
  109599. 10, 9,10, 9,10,10, 9, 9, 9,10,10,12,10,11,11, 9,
  109600. 11,11,10,11,11,11,10,10,10, 9, 9,10,10, 9, 9,10,
  109601. 11,11,10,11,10,11,10,11,11,10,11,11,11,10, 9,10,
  109602. 10, 9,10, 9, 9,11, 9, 9,11,10,10,11,11,10,10,11,
  109603. 10,11, 8, 9,11,11,10, 9,10,11,11,10,11,11,10,10,
  109604. 10,11,10, 9,10,10,11, 9,10,10, 9,11,10,10,10,10,
  109605. 11,10,11,11, 9,11,10,11,10,10,11,11,10,10,10, 9,
  109606. 10,10,11,11,11, 9,10,10,10,10,10,11,10,10,10, 9,
  109607. 10,10,11,10,10,10,10,10, 9,10,11,10,10,10,10,11,
  109608. 11,11,10,10,10,10,10,11,10,11,10,11,10,10,10, 9,
  109609. 11,11,10,10,10,11,11,10,10,10,10,10,10,10,10,11,
  109610. 11, 9,10,10,10,11,10,11,10,10,10,11, 9,10,11,10,
  109611. 11,10,10, 9,10,10,10,11,10,11,10,10,10,10,10,11,
  109612. 11,10,11,11,10,10,11,11,10, 9, 9,10,10,10,10,10,
  109613. 9,11, 9,10,10,10,11,11,10,10,10,10,11,11,11,10,
  109614. 9, 9,10,10,11,10,10,10,10,10,11,11,11,10,10,10,
  109615. 11,11,11, 9,10,10,10,10, 9,10, 9,10,11,10,11,10,
  109616. 10,11,11,10,11,11,11,11,11,10,11,10,10,10, 9,11,
  109617. 11,10,11,11,11,11,11,11,11,11,11,10,11,10,10,10,
  109618. 10,11,10,10,11, 9,10,10,10,
  109619. };
  109620. static float _vq_quantthresh__16c0_s_p9_2[] = {
  109621. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  109622. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  109623. 6.5, 7.5, 8.5, 9.5,
  109624. };
  109625. static long _vq_quantmap__16c0_s_p9_2[] = {
  109626. 19, 17, 15, 13, 11, 9, 7, 5,
  109627. 3, 1, 0, 2, 4, 6, 8, 10,
  109628. 12, 14, 16, 18, 20,
  109629. };
  109630. static encode_aux_threshmatch _vq_auxt__16c0_s_p9_2 = {
  109631. _vq_quantthresh__16c0_s_p9_2,
  109632. _vq_quantmap__16c0_s_p9_2,
  109633. 21,
  109634. 21
  109635. };
  109636. static static_codebook _16c0_s_p9_2 = {
  109637. 2, 441,
  109638. _vq_lengthlist__16c0_s_p9_2,
  109639. 1, -529268736, 1611661312, 5, 0,
  109640. _vq_quantlist__16c0_s_p9_2,
  109641. NULL,
  109642. &_vq_auxt__16c0_s_p9_2,
  109643. NULL,
  109644. 0
  109645. };
  109646. static long _huff_lengthlist__16c0_s_single[] = {
  109647. 3, 4,19, 7, 9, 7, 8,11, 9,12, 4, 1,19, 6, 7, 7,
  109648. 8,10,11,13,18,18,18,18,18,18,18,18,18,18, 8, 6,
  109649. 18, 8, 9, 9,11,12,14,18, 9, 6,18, 9, 7, 8, 9,11,
  109650. 12,18, 7, 6,18, 8, 7, 7, 7, 9,11,17, 8, 8,18, 9,
  109651. 7, 6, 6, 8,11,17,10,10,18,12, 9, 8, 7, 9,12,18,
  109652. 13,15,18,15,13,11,10,11,15,18,14,18,18,18,18,18,
  109653. 16,16,18,18,
  109654. };
  109655. static static_codebook _huff_book__16c0_s_single = {
  109656. 2, 100,
  109657. _huff_lengthlist__16c0_s_single,
  109658. 0, 0, 0, 0, 0,
  109659. NULL,
  109660. NULL,
  109661. NULL,
  109662. NULL,
  109663. 0
  109664. };
  109665. static long _huff_lengthlist__16c1_s_long[] = {
  109666. 2, 5,20, 7,10, 7, 8,10,11,11, 4, 2,20, 5, 8, 6,
  109667. 7, 9,10,10,20,20,20,20,19,19,19,19,19,19, 7, 5,
  109668. 19, 6,10, 7, 9,11,13,17,11, 8,19,10, 7, 7, 8,10,
  109669. 11,15, 7, 5,19, 7, 7, 5, 6, 9,11,16, 7, 6,19, 8,
  109670. 7, 6, 6, 7, 9,13, 9, 9,19,11, 9, 8, 6, 7, 8,13,
  109671. 12,14,19,16,13,10, 9, 8, 9,13,14,17,19,18,18,17,
  109672. 12,11,11,13,
  109673. };
  109674. static static_codebook _huff_book__16c1_s_long = {
  109675. 2, 100,
  109676. _huff_lengthlist__16c1_s_long,
  109677. 0, 0, 0, 0, 0,
  109678. NULL,
  109679. NULL,
  109680. NULL,
  109681. NULL,
  109682. 0
  109683. };
  109684. static long _vq_quantlist__16c1_s_p1_0[] = {
  109685. 1,
  109686. 0,
  109687. 2,
  109688. };
  109689. static long _vq_lengthlist__16c1_s_p1_0[] = {
  109690. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  109691. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109696. 0, 0, 0, 7, 8, 9, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  109701. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109702. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  109736. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  109741. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109746. 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  109782. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109783. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109784. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109785. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109786. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  109787. 0, 0, 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  109788. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109789. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109790. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109791. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  109792. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  109793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  109999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110100. 0,
  110101. };
  110102. static float _vq_quantthresh__16c1_s_p1_0[] = {
  110103. -0.5, 0.5,
  110104. };
  110105. static long _vq_quantmap__16c1_s_p1_0[] = {
  110106. 1, 0, 2,
  110107. };
  110108. static encode_aux_threshmatch _vq_auxt__16c1_s_p1_0 = {
  110109. _vq_quantthresh__16c1_s_p1_0,
  110110. _vq_quantmap__16c1_s_p1_0,
  110111. 3,
  110112. 3
  110113. };
  110114. static static_codebook _16c1_s_p1_0 = {
  110115. 8, 6561,
  110116. _vq_lengthlist__16c1_s_p1_0,
  110117. 1, -535822336, 1611661312, 2, 0,
  110118. _vq_quantlist__16c1_s_p1_0,
  110119. NULL,
  110120. &_vq_auxt__16c1_s_p1_0,
  110121. NULL,
  110122. 0
  110123. };
  110124. static long _vq_quantlist__16c1_s_p2_0[] = {
  110125. 2,
  110126. 1,
  110127. 3,
  110128. 0,
  110129. 4,
  110130. };
  110131. static long _vq_lengthlist__16c1_s_p2_0[] = {
  110132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110171. 0,
  110172. };
  110173. static float _vq_quantthresh__16c1_s_p2_0[] = {
  110174. -1.5, -0.5, 0.5, 1.5,
  110175. };
  110176. static long _vq_quantmap__16c1_s_p2_0[] = {
  110177. 3, 1, 0, 2, 4,
  110178. };
  110179. static encode_aux_threshmatch _vq_auxt__16c1_s_p2_0 = {
  110180. _vq_quantthresh__16c1_s_p2_0,
  110181. _vq_quantmap__16c1_s_p2_0,
  110182. 5,
  110183. 5
  110184. };
  110185. static static_codebook _16c1_s_p2_0 = {
  110186. 4, 625,
  110187. _vq_lengthlist__16c1_s_p2_0,
  110188. 1, -533725184, 1611661312, 3, 0,
  110189. _vq_quantlist__16c1_s_p2_0,
  110190. NULL,
  110191. &_vq_auxt__16c1_s_p2_0,
  110192. NULL,
  110193. 0
  110194. };
  110195. static long _vq_quantlist__16c1_s_p3_0[] = {
  110196. 2,
  110197. 1,
  110198. 3,
  110199. 0,
  110200. 4,
  110201. };
  110202. static long _vq_lengthlist__16c1_s_p3_0[] = {
  110203. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  110205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110206. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 7, 7, 9, 9,
  110208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110209. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  110210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110242. 0,
  110243. };
  110244. static float _vq_quantthresh__16c1_s_p3_0[] = {
  110245. -1.5, -0.5, 0.5, 1.5,
  110246. };
  110247. static long _vq_quantmap__16c1_s_p3_0[] = {
  110248. 3, 1, 0, 2, 4,
  110249. };
  110250. static encode_aux_threshmatch _vq_auxt__16c1_s_p3_0 = {
  110251. _vq_quantthresh__16c1_s_p3_0,
  110252. _vq_quantmap__16c1_s_p3_0,
  110253. 5,
  110254. 5
  110255. };
  110256. static static_codebook _16c1_s_p3_0 = {
  110257. 4, 625,
  110258. _vq_lengthlist__16c1_s_p3_0,
  110259. 1, -533725184, 1611661312, 3, 0,
  110260. _vq_quantlist__16c1_s_p3_0,
  110261. NULL,
  110262. &_vq_auxt__16c1_s_p3_0,
  110263. NULL,
  110264. 0
  110265. };
  110266. static long _vq_quantlist__16c1_s_p4_0[] = {
  110267. 4,
  110268. 3,
  110269. 5,
  110270. 2,
  110271. 6,
  110272. 1,
  110273. 7,
  110274. 0,
  110275. 8,
  110276. };
  110277. static long _vq_lengthlist__16c1_s_p4_0[] = {
  110278. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  110279. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  110280. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  110281. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 9, 0, 0, 0, 0, 0,
  110282. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110283. 0,
  110284. };
  110285. static float _vq_quantthresh__16c1_s_p4_0[] = {
  110286. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110287. };
  110288. static long _vq_quantmap__16c1_s_p4_0[] = {
  110289. 7, 5, 3, 1, 0, 2, 4, 6,
  110290. 8,
  110291. };
  110292. static encode_aux_threshmatch _vq_auxt__16c1_s_p4_0 = {
  110293. _vq_quantthresh__16c1_s_p4_0,
  110294. _vq_quantmap__16c1_s_p4_0,
  110295. 9,
  110296. 9
  110297. };
  110298. static static_codebook _16c1_s_p4_0 = {
  110299. 2, 81,
  110300. _vq_lengthlist__16c1_s_p4_0,
  110301. 1, -531628032, 1611661312, 4, 0,
  110302. _vq_quantlist__16c1_s_p4_0,
  110303. NULL,
  110304. &_vq_auxt__16c1_s_p4_0,
  110305. NULL,
  110306. 0
  110307. };
  110308. static long _vq_quantlist__16c1_s_p5_0[] = {
  110309. 4,
  110310. 3,
  110311. 5,
  110312. 2,
  110313. 6,
  110314. 1,
  110315. 7,
  110316. 0,
  110317. 8,
  110318. };
  110319. static long _vq_lengthlist__16c1_s_p5_0[] = {
  110320. 1, 3, 3, 5, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  110321. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 8, 8,
  110322. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  110323. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  110324. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  110325. 10,
  110326. };
  110327. static float _vq_quantthresh__16c1_s_p5_0[] = {
  110328. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110329. };
  110330. static long _vq_quantmap__16c1_s_p5_0[] = {
  110331. 7, 5, 3, 1, 0, 2, 4, 6,
  110332. 8,
  110333. };
  110334. static encode_aux_threshmatch _vq_auxt__16c1_s_p5_0 = {
  110335. _vq_quantthresh__16c1_s_p5_0,
  110336. _vq_quantmap__16c1_s_p5_0,
  110337. 9,
  110338. 9
  110339. };
  110340. static static_codebook _16c1_s_p5_0 = {
  110341. 2, 81,
  110342. _vq_lengthlist__16c1_s_p5_0,
  110343. 1, -531628032, 1611661312, 4, 0,
  110344. _vq_quantlist__16c1_s_p5_0,
  110345. NULL,
  110346. &_vq_auxt__16c1_s_p5_0,
  110347. NULL,
  110348. 0
  110349. };
  110350. static long _vq_quantlist__16c1_s_p6_0[] = {
  110351. 8,
  110352. 7,
  110353. 9,
  110354. 6,
  110355. 10,
  110356. 5,
  110357. 11,
  110358. 4,
  110359. 12,
  110360. 3,
  110361. 13,
  110362. 2,
  110363. 14,
  110364. 1,
  110365. 15,
  110366. 0,
  110367. 16,
  110368. };
  110369. static long _vq_lengthlist__16c1_s_p6_0[] = {
  110370. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,12,
  110371. 12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  110372. 12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  110373. 11,12,12, 0, 0, 0, 8, 8, 8, 9,10, 9,10,10,10,10,
  110374. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,11,
  110375. 11,11,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  110376. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  110377. 10,11,11,12,12,13,13, 0, 0, 0, 9, 9, 9, 9,10,10,
  110378. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  110379. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  110380. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  110381. 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0,
  110382. 10,10,11,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0,
  110383. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  110384. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  110385. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0,
  110386. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  110387. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  110388. 14,
  110389. };
  110390. static float _vq_quantthresh__16c1_s_p6_0[] = {
  110391. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110392. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  110393. };
  110394. static long _vq_quantmap__16c1_s_p6_0[] = {
  110395. 15, 13, 11, 9, 7, 5, 3, 1,
  110396. 0, 2, 4, 6, 8, 10, 12, 14,
  110397. 16,
  110398. };
  110399. static encode_aux_threshmatch _vq_auxt__16c1_s_p6_0 = {
  110400. _vq_quantthresh__16c1_s_p6_0,
  110401. _vq_quantmap__16c1_s_p6_0,
  110402. 17,
  110403. 17
  110404. };
  110405. static static_codebook _16c1_s_p6_0 = {
  110406. 2, 289,
  110407. _vq_lengthlist__16c1_s_p6_0,
  110408. 1, -529530880, 1611661312, 5, 0,
  110409. _vq_quantlist__16c1_s_p6_0,
  110410. NULL,
  110411. &_vq_auxt__16c1_s_p6_0,
  110412. NULL,
  110413. 0
  110414. };
  110415. static long _vq_quantlist__16c1_s_p7_0[] = {
  110416. 1,
  110417. 0,
  110418. 2,
  110419. };
  110420. static long _vq_lengthlist__16c1_s_p7_0[] = {
  110421. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9,10,10,
  110422. 10, 9, 4, 7, 7,10,10,10,11,10,10, 6,10,10,11,11,
  110423. 11,11,10,10, 6,10, 9,11,11,11,11,10,10, 6,10,10,
  110424. 11,11,11,11,10,10, 7,11,11,11,11,11,12,12,11, 6,
  110425. 10,10,11,10,10,11,11,11, 6,10,10,10,11,10,11,11,
  110426. 11,
  110427. };
  110428. static float _vq_quantthresh__16c1_s_p7_0[] = {
  110429. -5.5, 5.5,
  110430. };
  110431. static long _vq_quantmap__16c1_s_p7_0[] = {
  110432. 1, 0, 2,
  110433. };
  110434. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_0 = {
  110435. _vq_quantthresh__16c1_s_p7_0,
  110436. _vq_quantmap__16c1_s_p7_0,
  110437. 3,
  110438. 3
  110439. };
  110440. static static_codebook _16c1_s_p7_0 = {
  110441. 4, 81,
  110442. _vq_lengthlist__16c1_s_p7_0,
  110443. 1, -529137664, 1618345984, 2, 0,
  110444. _vq_quantlist__16c1_s_p7_0,
  110445. NULL,
  110446. &_vq_auxt__16c1_s_p7_0,
  110447. NULL,
  110448. 0
  110449. };
  110450. static long _vq_quantlist__16c1_s_p7_1[] = {
  110451. 5,
  110452. 4,
  110453. 6,
  110454. 3,
  110455. 7,
  110456. 2,
  110457. 8,
  110458. 1,
  110459. 9,
  110460. 0,
  110461. 10,
  110462. };
  110463. static long _vq_lengthlist__16c1_s_p7_1[] = {
  110464. 2, 3, 3, 5, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  110465. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  110466. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  110467. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  110468. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  110469. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  110470. 8, 9, 9,10,10,10,10,10, 9, 9, 8, 8, 9, 9,10,10,
  110471. 10,10,10, 8, 8, 8, 8, 9, 9,
  110472. };
  110473. static float _vq_quantthresh__16c1_s_p7_1[] = {
  110474. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  110475. 3.5, 4.5,
  110476. };
  110477. static long _vq_quantmap__16c1_s_p7_1[] = {
  110478. 9, 7, 5, 3, 1, 0, 2, 4,
  110479. 6, 8, 10,
  110480. };
  110481. static encode_aux_threshmatch _vq_auxt__16c1_s_p7_1 = {
  110482. _vq_quantthresh__16c1_s_p7_1,
  110483. _vq_quantmap__16c1_s_p7_1,
  110484. 11,
  110485. 11
  110486. };
  110487. static static_codebook _16c1_s_p7_1 = {
  110488. 2, 121,
  110489. _vq_lengthlist__16c1_s_p7_1,
  110490. 1, -531365888, 1611661312, 4, 0,
  110491. _vq_quantlist__16c1_s_p7_1,
  110492. NULL,
  110493. &_vq_auxt__16c1_s_p7_1,
  110494. NULL,
  110495. 0
  110496. };
  110497. static long _vq_quantlist__16c1_s_p8_0[] = {
  110498. 6,
  110499. 5,
  110500. 7,
  110501. 4,
  110502. 8,
  110503. 3,
  110504. 9,
  110505. 2,
  110506. 10,
  110507. 1,
  110508. 11,
  110509. 0,
  110510. 12,
  110511. };
  110512. static long _vq_lengthlist__16c1_s_p8_0[] = {
  110513. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  110514. 7, 8, 8, 9, 8, 8, 9, 9,10,11, 6, 5, 5, 8, 8, 9,
  110515. 9, 8, 8, 9,10,10,11, 0, 8, 8, 8, 9, 9, 9, 9, 9,
  110516. 10,10,11,11, 0, 9, 9, 9, 8, 9, 9, 9, 9,10,10,11,
  110517. 11, 0,13,13, 9, 9,10,10,10,10,11,11,12,12, 0,14,
  110518. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  110519. 9, 9,11,11,12,12,13,12, 0, 0, 0,10,10, 9, 9,10,
  110520. 10,12,12,13,13, 0, 0, 0,13,14,11,10,11,11,12,12,
  110521. 13,14, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  110522. 0, 0, 0, 0,12,12,12,12,13,13,14,15, 0, 0, 0, 0,
  110523. 0,12,12,12,12,13,13,14,15,
  110524. };
  110525. static float _vq_quantthresh__16c1_s_p8_0[] = {
  110526. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  110527. 12.5, 17.5, 22.5, 27.5,
  110528. };
  110529. static long _vq_quantmap__16c1_s_p8_0[] = {
  110530. 11, 9, 7, 5, 3, 1, 0, 2,
  110531. 4, 6, 8, 10, 12,
  110532. };
  110533. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_0 = {
  110534. _vq_quantthresh__16c1_s_p8_0,
  110535. _vq_quantmap__16c1_s_p8_0,
  110536. 13,
  110537. 13
  110538. };
  110539. static static_codebook _16c1_s_p8_0 = {
  110540. 2, 169,
  110541. _vq_lengthlist__16c1_s_p8_0,
  110542. 1, -526516224, 1616117760, 4, 0,
  110543. _vq_quantlist__16c1_s_p8_0,
  110544. NULL,
  110545. &_vq_auxt__16c1_s_p8_0,
  110546. NULL,
  110547. 0
  110548. };
  110549. static long _vq_quantlist__16c1_s_p8_1[] = {
  110550. 2,
  110551. 1,
  110552. 3,
  110553. 0,
  110554. 4,
  110555. };
  110556. static long _vq_lengthlist__16c1_s_p8_1[] = {
  110557. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  110558. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  110559. };
  110560. static float _vq_quantthresh__16c1_s_p8_1[] = {
  110561. -1.5, -0.5, 0.5, 1.5,
  110562. };
  110563. static long _vq_quantmap__16c1_s_p8_1[] = {
  110564. 3, 1, 0, 2, 4,
  110565. };
  110566. static encode_aux_threshmatch _vq_auxt__16c1_s_p8_1 = {
  110567. _vq_quantthresh__16c1_s_p8_1,
  110568. _vq_quantmap__16c1_s_p8_1,
  110569. 5,
  110570. 5
  110571. };
  110572. static static_codebook _16c1_s_p8_1 = {
  110573. 2, 25,
  110574. _vq_lengthlist__16c1_s_p8_1,
  110575. 1, -533725184, 1611661312, 3, 0,
  110576. _vq_quantlist__16c1_s_p8_1,
  110577. NULL,
  110578. &_vq_auxt__16c1_s_p8_1,
  110579. NULL,
  110580. 0
  110581. };
  110582. static long _vq_quantlist__16c1_s_p9_0[] = {
  110583. 6,
  110584. 5,
  110585. 7,
  110586. 4,
  110587. 8,
  110588. 3,
  110589. 9,
  110590. 2,
  110591. 10,
  110592. 1,
  110593. 11,
  110594. 0,
  110595. 12,
  110596. };
  110597. static long _vq_lengthlist__16c1_s_p9_0[] = {
  110598. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110599. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110600. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110601. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110602. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  110603. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110604. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110605. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110606. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110607. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110608. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  110609. };
  110610. static float _vq_quantthresh__16c1_s_p9_0[] = {
  110611. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  110612. 787.5, 1102.5, 1417.5, 1732.5,
  110613. };
  110614. static long _vq_quantmap__16c1_s_p9_0[] = {
  110615. 11, 9, 7, 5, 3, 1, 0, 2,
  110616. 4, 6, 8, 10, 12,
  110617. };
  110618. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_0 = {
  110619. _vq_quantthresh__16c1_s_p9_0,
  110620. _vq_quantmap__16c1_s_p9_0,
  110621. 13,
  110622. 13
  110623. };
  110624. static static_codebook _16c1_s_p9_0 = {
  110625. 2, 169,
  110626. _vq_lengthlist__16c1_s_p9_0,
  110627. 1, -513964032, 1628680192, 4, 0,
  110628. _vq_quantlist__16c1_s_p9_0,
  110629. NULL,
  110630. &_vq_auxt__16c1_s_p9_0,
  110631. NULL,
  110632. 0
  110633. };
  110634. static long _vq_quantlist__16c1_s_p9_1[] = {
  110635. 7,
  110636. 6,
  110637. 8,
  110638. 5,
  110639. 9,
  110640. 4,
  110641. 10,
  110642. 3,
  110643. 11,
  110644. 2,
  110645. 12,
  110646. 1,
  110647. 13,
  110648. 0,
  110649. 14,
  110650. };
  110651. static long _vq_lengthlist__16c1_s_p9_1[] = {
  110652. 1, 4, 4, 4, 4, 8, 8,12,13,14,14,14,14,14,14, 6,
  110653. 6, 6, 6, 6,10, 9,14,14,14,14,14,14,14,14, 7, 6,
  110654. 5, 6, 6,10, 9,12,13,13,13,13,13,13,13,13, 7, 7,
  110655. 9, 9,11,11,12,13,13,13,13,13,13,13,13, 7, 7, 8,
  110656. 8,11,12,13,13,13,13,13,13,13,13,13,12,12,10,10,
  110657. 13,12,13,13,13,13,13,13,13,13,13,12,12,10,10,13,
  110658. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,13,12,
  110659. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110660. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110661. 13,13,13,13,13,13,13,13,13,13,13,13,12,13,13,13,
  110662. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110663. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110664. 13,13,13,13,13,13,13,13,13,12,13,13,13,13,13,13,
  110665. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  110666. 13,
  110667. };
  110668. static float _vq_quantthresh__16c1_s_p9_1[] = {
  110669. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  110670. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  110671. };
  110672. static long _vq_quantmap__16c1_s_p9_1[] = {
  110673. 13, 11, 9, 7, 5, 3, 1, 0,
  110674. 2, 4, 6, 8, 10, 12, 14,
  110675. };
  110676. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_1 = {
  110677. _vq_quantthresh__16c1_s_p9_1,
  110678. _vq_quantmap__16c1_s_p9_1,
  110679. 15,
  110680. 15
  110681. };
  110682. static static_codebook _16c1_s_p9_1 = {
  110683. 2, 225,
  110684. _vq_lengthlist__16c1_s_p9_1,
  110685. 1, -520986624, 1620377600, 4, 0,
  110686. _vq_quantlist__16c1_s_p9_1,
  110687. NULL,
  110688. &_vq_auxt__16c1_s_p9_1,
  110689. NULL,
  110690. 0
  110691. };
  110692. static long _vq_quantlist__16c1_s_p9_2[] = {
  110693. 10,
  110694. 9,
  110695. 11,
  110696. 8,
  110697. 12,
  110698. 7,
  110699. 13,
  110700. 6,
  110701. 14,
  110702. 5,
  110703. 15,
  110704. 4,
  110705. 16,
  110706. 3,
  110707. 17,
  110708. 2,
  110709. 18,
  110710. 1,
  110711. 19,
  110712. 0,
  110713. 20,
  110714. };
  110715. static long _vq_lengthlist__16c1_s_p9_2[] = {
  110716. 1, 4, 4, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9,10,
  110717. 10,10, 9,10,10,11,12,12, 8, 8, 8, 8, 9, 9, 9, 9,
  110718. 10,10,10,10,10,11,11,10,12,11,11,13,11, 7, 7, 8,
  110719. 8, 8, 8, 9, 9, 9,10,10,10,10, 9,10,10,11,11,12,
  110720. 11,11, 8, 8, 8, 8, 9, 9,10,10,10,10,11,11,11,11,
  110721. 11,11,11,12,11,12,12, 8, 8, 9, 9, 9, 9, 9,10,10,
  110722. 10,10,10,10,11,11,11,11,11,11,12,11, 9, 9, 9, 9,
  110723. 10,10,10,10,11,10,11,11,11,11,11,11,12,12,12,12,
  110724. 11, 9, 9, 9, 9,10,10,10,10,11,11,11,11,11,11,11,
  110725. 11,11,12,12,12,13, 9,10,10, 9,11,10,10,10,10,11,
  110726. 11,11,11,11,10,11,12,11,12,12,11,12,11,10, 9,10,
  110727. 10,11,10,11,11,11,11,11,11,11,11,11,12,12,11,12,
  110728. 12,12,10,10,10,11,10,11,11,11,11,11,11,11,11,11,
  110729. 11,11,12,13,12,12,11, 9,10,10,11,11,10,11,11,11,
  110730. 12,11,11,11,11,11,12,12,13,13,12,13,10,10,12,10,
  110731. 11,11,11,11,11,11,11,11,11,12,12,11,13,12,12,12,
  110732. 12,13,12,11,11,11,11,11,11,12,11,12,11,11,11,11,
  110733. 12,12,13,12,11,12,12,11,11,11,11,11,12,11,11,11,
  110734. 11,12,11,11,12,11,12,13,13,12,12,12,12,11,11,11,
  110735. 11,11,12,11,11,12,11,12,11,11,11,11,13,12,12,12,
  110736. 12,13,11,11,11,12,12,11,11,11,12,11,12,12,12,11,
  110737. 12,13,12,11,11,12,12,11,12,11,11,11,12,12,11,12,
  110738. 11,11,11,12,12,12,12,13,12,13,12,12,12,12,11,11,
  110739. 12,11,11,11,11,11,11,12,12,12,13,12,11,13,13,12,
  110740. 12,11,12,10,11,11,11,11,12,11,12,12,11,12,12,13,
  110741. 12,12,13,12,12,12,12,12,11,12,12,12,11,12,11,11,
  110742. 11,12,13,12,13,13,13,13,13,12,13,13,12,12,13,11,
  110743. 11,11,11,11,12,11,11,12,11,
  110744. };
  110745. static float _vq_quantthresh__16c1_s_p9_2[] = {
  110746. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  110747. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  110748. 6.5, 7.5, 8.5, 9.5,
  110749. };
  110750. static long _vq_quantmap__16c1_s_p9_2[] = {
  110751. 19, 17, 15, 13, 11, 9, 7, 5,
  110752. 3, 1, 0, 2, 4, 6, 8, 10,
  110753. 12, 14, 16, 18, 20,
  110754. };
  110755. static encode_aux_threshmatch _vq_auxt__16c1_s_p9_2 = {
  110756. _vq_quantthresh__16c1_s_p9_2,
  110757. _vq_quantmap__16c1_s_p9_2,
  110758. 21,
  110759. 21
  110760. };
  110761. static static_codebook _16c1_s_p9_2 = {
  110762. 2, 441,
  110763. _vq_lengthlist__16c1_s_p9_2,
  110764. 1, -529268736, 1611661312, 5, 0,
  110765. _vq_quantlist__16c1_s_p9_2,
  110766. NULL,
  110767. &_vq_auxt__16c1_s_p9_2,
  110768. NULL,
  110769. 0
  110770. };
  110771. static long _huff_lengthlist__16c1_s_short[] = {
  110772. 5, 6,17, 8,12, 9,10,10,12,13, 5, 2,17, 4, 9, 5,
  110773. 7, 8,11,13,16,16,16,16,16,16,16,16,16,16, 6, 4,
  110774. 16, 5,10, 5, 7,10,14,16,13, 9,16,11, 8, 7, 8, 9,
  110775. 13,16, 7, 4,16, 5, 7, 4, 6, 8,11,13, 8, 6,16, 7,
  110776. 8, 5, 5, 7, 9,13, 9, 8,16, 9, 8, 6, 6, 7, 9,13,
  110777. 11,11,16,10,10, 7, 7, 7, 9,13,13,13,16,13,13, 9,
  110778. 9, 9,10,13,
  110779. };
  110780. static static_codebook _huff_book__16c1_s_short = {
  110781. 2, 100,
  110782. _huff_lengthlist__16c1_s_short,
  110783. 0, 0, 0, 0, 0,
  110784. NULL,
  110785. NULL,
  110786. NULL,
  110787. NULL,
  110788. 0
  110789. };
  110790. static long _huff_lengthlist__16c2_s_long[] = {
  110791. 4, 7, 9, 9, 9, 8, 9,10,15,19, 5, 4, 5, 6, 7, 7,
  110792. 8, 9,14,16, 6, 5, 4, 5, 6, 7, 8,10,12,19, 7, 6,
  110793. 5, 4, 5, 6, 7, 9,11,18, 8, 7, 6, 5, 5, 5, 7, 9,
  110794. 10,17, 8, 7, 7, 5, 5, 5, 6, 7,12,18, 8, 8, 8, 7,
  110795. 7, 5, 5, 7,12,18, 8, 9,10, 9, 9, 7, 6, 7,12,17,
  110796. 14,18,16,16,15,12,11,10,12,18,15,17,18,18,18,15,
  110797. 14,14,16,18,
  110798. };
  110799. static static_codebook _huff_book__16c2_s_long = {
  110800. 2, 100,
  110801. _huff_lengthlist__16c2_s_long,
  110802. 0, 0, 0, 0, 0,
  110803. NULL,
  110804. NULL,
  110805. NULL,
  110806. NULL,
  110807. 0
  110808. };
  110809. static long _vq_quantlist__16c2_s_p1_0[] = {
  110810. 1,
  110811. 0,
  110812. 2,
  110813. };
  110814. static long _vq_lengthlist__16c2_s_p1_0[] = {
  110815. 1, 3, 3, 0, 0, 0, 0, 0, 0, 4, 5, 5, 0, 0, 0, 0,
  110816. 0, 0, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110820. 0,
  110821. };
  110822. static float _vq_quantthresh__16c2_s_p1_0[] = {
  110823. -0.5, 0.5,
  110824. };
  110825. static long _vq_quantmap__16c2_s_p1_0[] = {
  110826. 1, 0, 2,
  110827. };
  110828. static encode_aux_threshmatch _vq_auxt__16c2_s_p1_0 = {
  110829. _vq_quantthresh__16c2_s_p1_0,
  110830. _vq_quantmap__16c2_s_p1_0,
  110831. 3,
  110832. 3
  110833. };
  110834. static static_codebook _16c2_s_p1_0 = {
  110835. 4, 81,
  110836. _vq_lengthlist__16c2_s_p1_0,
  110837. 1, -535822336, 1611661312, 2, 0,
  110838. _vq_quantlist__16c2_s_p1_0,
  110839. NULL,
  110840. &_vq_auxt__16c2_s_p1_0,
  110841. NULL,
  110842. 0
  110843. };
  110844. static long _vq_quantlist__16c2_s_p2_0[] = {
  110845. 2,
  110846. 1,
  110847. 3,
  110848. 0,
  110849. 4,
  110850. };
  110851. static long _vq_lengthlist__16c2_s_p2_0[] = {
  110852. 2, 4, 3, 7, 7, 0, 0, 0, 7, 8, 0, 0, 0, 8, 8, 0,
  110853. 0, 0, 8, 8, 0, 0, 0, 8, 8, 4, 5, 4, 8, 8, 0, 0,
  110854. 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0,
  110855. 9, 9, 4, 4, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8,
  110856. 8, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 7, 8, 8,10,10,
  110857. 0, 0, 0,12,11, 0, 0, 0,11,11, 0, 0, 0,14,13, 0,
  110858. 0, 0,14,13, 7, 8, 8, 9,10, 0, 0, 0,11,12, 0, 0,
  110859. 0,11,11, 0, 0, 0,14,14, 0, 0, 0,13,14, 0, 0, 0,
  110860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110864. 0, 0, 0, 0, 0, 0, 0, 0, 8, 8, 8,11,11, 0, 0, 0,
  110865. 11,11, 0, 0, 0,12,11, 0, 0, 0,12,12, 0, 0, 0,13,
  110866. 13, 8, 8, 8,11,11, 0, 0, 0,11,11, 0, 0, 0,11,12,
  110867. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  110868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110872. 0, 0, 0, 0, 0, 8, 8, 8,12,11, 0, 0, 0,12,11, 0,
  110873. 0, 0,11,11, 0, 0, 0,13,13, 0, 0, 0,13,12, 8, 8,
  110874. 8,11,12, 0, 0, 0,11,12, 0, 0, 0,11,11, 0, 0, 0,
  110875. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110880. 0, 0, 8, 9, 9,14,13, 0, 0, 0,13,12, 0, 0, 0,13,
  110881. 13, 0, 0, 0,13,12, 0, 0, 0,13,13, 8, 9, 9,13,14,
  110882. 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,13, 0,
  110883. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 8,
  110888. 9, 9,14,13, 0, 0, 0,13,13, 0, 0, 0,13,12, 0, 0,
  110889. 0,13,13, 0, 0, 0,13,12, 8, 9, 9,14,14, 0, 0, 0,
  110890. 13,13, 0, 0, 0,12,13, 0, 0, 0,13,13, 0, 0, 0,12,
  110891. 13,
  110892. };
  110893. static float _vq_quantthresh__16c2_s_p2_0[] = {
  110894. -1.5, -0.5, 0.5, 1.5,
  110895. };
  110896. static long _vq_quantmap__16c2_s_p2_0[] = {
  110897. 3, 1, 0, 2, 4,
  110898. };
  110899. static encode_aux_threshmatch _vq_auxt__16c2_s_p2_0 = {
  110900. _vq_quantthresh__16c2_s_p2_0,
  110901. _vq_quantmap__16c2_s_p2_0,
  110902. 5,
  110903. 5
  110904. };
  110905. static static_codebook _16c2_s_p2_0 = {
  110906. 4, 625,
  110907. _vq_lengthlist__16c2_s_p2_0,
  110908. 1, -533725184, 1611661312, 3, 0,
  110909. _vq_quantlist__16c2_s_p2_0,
  110910. NULL,
  110911. &_vq_auxt__16c2_s_p2_0,
  110912. NULL,
  110913. 0
  110914. };
  110915. static long _vq_quantlist__16c2_s_p3_0[] = {
  110916. 4,
  110917. 3,
  110918. 5,
  110919. 2,
  110920. 6,
  110921. 1,
  110922. 7,
  110923. 0,
  110924. 8,
  110925. };
  110926. static long _vq_lengthlist__16c2_s_p3_0[] = {
  110927. 1, 3, 3, 6, 6, 7, 7, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  110928. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  110929. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  110930. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 9, 9,10,10, 0,
  110931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110932. 0,
  110933. };
  110934. static float _vq_quantthresh__16c2_s_p3_0[] = {
  110935. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  110936. };
  110937. static long _vq_quantmap__16c2_s_p3_0[] = {
  110938. 7, 5, 3, 1, 0, 2, 4, 6,
  110939. 8,
  110940. };
  110941. static encode_aux_threshmatch _vq_auxt__16c2_s_p3_0 = {
  110942. _vq_quantthresh__16c2_s_p3_0,
  110943. _vq_quantmap__16c2_s_p3_0,
  110944. 9,
  110945. 9
  110946. };
  110947. static static_codebook _16c2_s_p3_0 = {
  110948. 2, 81,
  110949. _vq_lengthlist__16c2_s_p3_0,
  110950. 1, -531628032, 1611661312, 4, 0,
  110951. _vq_quantlist__16c2_s_p3_0,
  110952. NULL,
  110953. &_vq_auxt__16c2_s_p3_0,
  110954. NULL,
  110955. 0
  110956. };
  110957. static long _vq_quantlist__16c2_s_p4_0[] = {
  110958. 8,
  110959. 7,
  110960. 9,
  110961. 6,
  110962. 10,
  110963. 5,
  110964. 11,
  110965. 4,
  110966. 12,
  110967. 3,
  110968. 13,
  110969. 2,
  110970. 14,
  110971. 1,
  110972. 15,
  110973. 0,
  110974. 16,
  110975. };
  110976. static long _vq_lengthlist__16c2_s_p4_0[] = {
  110977. 2, 3, 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,
  110978. 10, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  110979. 11,11, 0, 0, 0, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  110980. 10,10,11, 0, 0, 0, 6, 6, 8, 8, 8, 8, 9, 9,10,10,
  110981. 10,11,11,11, 0, 0, 0, 6, 6, 8, 8, 9, 9, 9, 9,10,
  110982. 10,11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,
  110983. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9,
  110984. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  110985. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  110986. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  110987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  110995. 0,
  110996. };
  110997. static float _vq_quantthresh__16c2_s_p4_0[] = {
  110998. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  110999. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  111000. };
  111001. static long _vq_quantmap__16c2_s_p4_0[] = {
  111002. 15, 13, 11, 9, 7, 5, 3, 1,
  111003. 0, 2, 4, 6, 8, 10, 12, 14,
  111004. 16,
  111005. };
  111006. static encode_aux_threshmatch _vq_auxt__16c2_s_p4_0 = {
  111007. _vq_quantthresh__16c2_s_p4_0,
  111008. _vq_quantmap__16c2_s_p4_0,
  111009. 17,
  111010. 17
  111011. };
  111012. static static_codebook _16c2_s_p4_0 = {
  111013. 2, 289,
  111014. _vq_lengthlist__16c2_s_p4_0,
  111015. 1, -529530880, 1611661312, 5, 0,
  111016. _vq_quantlist__16c2_s_p4_0,
  111017. NULL,
  111018. &_vq_auxt__16c2_s_p4_0,
  111019. NULL,
  111020. 0
  111021. };
  111022. static long _vq_quantlist__16c2_s_p5_0[] = {
  111023. 1,
  111024. 0,
  111025. 2,
  111026. };
  111027. static long _vq_lengthlist__16c2_s_p5_0[] = {
  111028. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6,10,10,10,10,
  111029. 10,10, 4, 7, 6,10,10,10,10,10,10, 5, 9, 9, 9,12,
  111030. 11,10,11,12, 7,10,10,12,12,12,12,12,12, 7,10,10,
  111031. 11,12,12,12,12,13, 6,10,10,10,12,12,10,12,12, 7,
  111032. 10,10,11,13,12,12,12,12, 7,10,10,11,12,12,12,12,
  111033. 12,
  111034. };
  111035. static float _vq_quantthresh__16c2_s_p5_0[] = {
  111036. -5.5, 5.5,
  111037. };
  111038. static long _vq_quantmap__16c2_s_p5_0[] = {
  111039. 1, 0, 2,
  111040. };
  111041. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_0 = {
  111042. _vq_quantthresh__16c2_s_p5_0,
  111043. _vq_quantmap__16c2_s_p5_0,
  111044. 3,
  111045. 3
  111046. };
  111047. static static_codebook _16c2_s_p5_0 = {
  111048. 4, 81,
  111049. _vq_lengthlist__16c2_s_p5_0,
  111050. 1, -529137664, 1618345984, 2, 0,
  111051. _vq_quantlist__16c2_s_p5_0,
  111052. NULL,
  111053. &_vq_auxt__16c2_s_p5_0,
  111054. NULL,
  111055. 0
  111056. };
  111057. static long _vq_quantlist__16c2_s_p5_1[] = {
  111058. 5,
  111059. 4,
  111060. 6,
  111061. 3,
  111062. 7,
  111063. 2,
  111064. 8,
  111065. 1,
  111066. 9,
  111067. 0,
  111068. 10,
  111069. };
  111070. static long _vq_lengthlist__16c2_s_p5_1[] = {
  111071. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11, 6, 6,
  111072. 7, 7, 8, 8, 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8,
  111073. 8,11,11,11, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  111074. 6, 8, 8, 8, 8, 9, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  111075. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 9,11,11,11,
  111076. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,11,11, 8, 8, 8,
  111077. 8, 8, 8,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  111078. 11,11,11, 7, 7, 8, 8, 8, 8,
  111079. };
  111080. static float _vq_quantthresh__16c2_s_p5_1[] = {
  111081. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111082. 3.5, 4.5,
  111083. };
  111084. static long _vq_quantmap__16c2_s_p5_1[] = {
  111085. 9, 7, 5, 3, 1, 0, 2, 4,
  111086. 6, 8, 10,
  111087. };
  111088. static encode_aux_threshmatch _vq_auxt__16c2_s_p5_1 = {
  111089. _vq_quantthresh__16c2_s_p5_1,
  111090. _vq_quantmap__16c2_s_p5_1,
  111091. 11,
  111092. 11
  111093. };
  111094. static static_codebook _16c2_s_p5_1 = {
  111095. 2, 121,
  111096. _vq_lengthlist__16c2_s_p5_1,
  111097. 1, -531365888, 1611661312, 4, 0,
  111098. _vq_quantlist__16c2_s_p5_1,
  111099. NULL,
  111100. &_vq_auxt__16c2_s_p5_1,
  111101. NULL,
  111102. 0
  111103. };
  111104. static long _vq_quantlist__16c2_s_p6_0[] = {
  111105. 6,
  111106. 5,
  111107. 7,
  111108. 4,
  111109. 8,
  111110. 3,
  111111. 9,
  111112. 2,
  111113. 10,
  111114. 1,
  111115. 11,
  111116. 0,
  111117. 12,
  111118. };
  111119. static long _vq_lengthlist__16c2_s_p6_0[] = {
  111120. 1, 4, 4, 7, 6, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  111121. 7, 7, 9, 9, 9, 9,11,11,12,12, 6, 5, 5, 7, 7, 9,
  111122. 9,10,10,11,11,12,12, 0, 6, 6, 7, 7, 9, 9,10,10,
  111123. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,12,12,
  111124. 12, 0,11,11, 8, 8,10,10,11,11,12,12,13,13, 0,11,
  111125. 12, 8, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  111126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111130. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111131. };
  111132. static float _vq_quantthresh__16c2_s_p6_0[] = {
  111133. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  111134. 12.5, 17.5, 22.5, 27.5,
  111135. };
  111136. static long _vq_quantmap__16c2_s_p6_0[] = {
  111137. 11, 9, 7, 5, 3, 1, 0, 2,
  111138. 4, 6, 8, 10, 12,
  111139. };
  111140. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_0 = {
  111141. _vq_quantthresh__16c2_s_p6_0,
  111142. _vq_quantmap__16c2_s_p6_0,
  111143. 13,
  111144. 13
  111145. };
  111146. static static_codebook _16c2_s_p6_0 = {
  111147. 2, 169,
  111148. _vq_lengthlist__16c2_s_p6_0,
  111149. 1, -526516224, 1616117760, 4, 0,
  111150. _vq_quantlist__16c2_s_p6_0,
  111151. NULL,
  111152. &_vq_auxt__16c2_s_p6_0,
  111153. NULL,
  111154. 0
  111155. };
  111156. static long _vq_quantlist__16c2_s_p6_1[] = {
  111157. 2,
  111158. 1,
  111159. 3,
  111160. 0,
  111161. 4,
  111162. };
  111163. static long _vq_lengthlist__16c2_s_p6_1[] = {
  111164. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  111165. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  111166. };
  111167. static float _vq_quantthresh__16c2_s_p6_1[] = {
  111168. -1.5, -0.5, 0.5, 1.5,
  111169. };
  111170. static long _vq_quantmap__16c2_s_p6_1[] = {
  111171. 3, 1, 0, 2, 4,
  111172. };
  111173. static encode_aux_threshmatch _vq_auxt__16c2_s_p6_1 = {
  111174. _vq_quantthresh__16c2_s_p6_1,
  111175. _vq_quantmap__16c2_s_p6_1,
  111176. 5,
  111177. 5
  111178. };
  111179. static static_codebook _16c2_s_p6_1 = {
  111180. 2, 25,
  111181. _vq_lengthlist__16c2_s_p6_1,
  111182. 1, -533725184, 1611661312, 3, 0,
  111183. _vq_quantlist__16c2_s_p6_1,
  111184. NULL,
  111185. &_vq_auxt__16c2_s_p6_1,
  111186. NULL,
  111187. 0
  111188. };
  111189. static long _vq_quantlist__16c2_s_p7_0[] = {
  111190. 6,
  111191. 5,
  111192. 7,
  111193. 4,
  111194. 8,
  111195. 3,
  111196. 9,
  111197. 2,
  111198. 10,
  111199. 1,
  111200. 11,
  111201. 0,
  111202. 12,
  111203. };
  111204. static long _vq_lengthlist__16c2_s_p7_0[] = {
  111205. 1, 4, 4, 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 5, 5,
  111206. 8, 8, 9, 9,10,10,11,11,12,12, 6, 5, 5, 8, 8, 9,
  111207. 9,10,10,11,11,12,13,18, 6, 6, 7, 7, 9, 9,10,10,
  111208. 12,12,13,13,18, 6, 6, 7, 7, 9, 9,10,10,12,12,13,
  111209. 13,18,11,10, 8, 8,10,10,11,11,12,12,13,13,18,11,
  111210. 11, 8, 8,10,10,11,11,12,13,13,13,18,18,18,10,11,
  111211. 11,11,12,12,13,13,14,14,18,18,18,11,11,11,11,12,
  111212. 12,13,13,14,14,18,18,18,14,14,12,12,12,12,14,14,
  111213. 15,14,18,18,18,15,15,11,12,12,12,13,13,15,15,18,
  111214. 18,18,18,18,13,13,13,13,13,14,17,16,18,18,18,18,
  111215. 18,13,14,13,13,14,13,15,14,
  111216. };
  111217. static float _vq_quantthresh__16c2_s_p7_0[] = {
  111218. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  111219. 27.5, 38.5, 49.5, 60.5,
  111220. };
  111221. static long _vq_quantmap__16c2_s_p7_0[] = {
  111222. 11, 9, 7, 5, 3, 1, 0, 2,
  111223. 4, 6, 8, 10, 12,
  111224. };
  111225. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_0 = {
  111226. _vq_quantthresh__16c2_s_p7_0,
  111227. _vq_quantmap__16c2_s_p7_0,
  111228. 13,
  111229. 13
  111230. };
  111231. static static_codebook _16c2_s_p7_0 = {
  111232. 2, 169,
  111233. _vq_lengthlist__16c2_s_p7_0,
  111234. 1, -523206656, 1618345984, 4, 0,
  111235. _vq_quantlist__16c2_s_p7_0,
  111236. NULL,
  111237. &_vq_auxt__16c2_s_p7_0,
  111238. NULL,
  111239. 0
  111240. };
  111241. static long _vq_quantlist__16c2_s_p7_1[] = {
  111242. 5,
  111243. 4,
  111244. 6,
  111245. 3,
  111246. 7,
  111247. 2,
  111248. 8,
  111249. 1,
  111250. 9,
  111251. 0,
  111252. 10,
  111253. };
  111254. static long _vq_lengthlist__16c2_s_p7_1[] = {
  111255. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 9, 9, 6, 6,
  111256. 7, 7, 8, 8, 8, 8, 9, 9, 9, 6, 6, 7, 7, 8, 8, 8,
  111257. 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7,
  111258. 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  111259. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  111260. 7, 7, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 9, 7, 7, 7,
  111261. 7, 8, 8, 9, 9, 9, 9, 9, 8, 8, 7, 7, 8, 8, 9, 9,
  111262. 9, 9, 9, 7, 7, 7, 7, 8, 8,
  111263. };
  111264. static float _vq_quantthresh__16c2_s_p7_1[] = {
  111265. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111266. 3.5, 4.5,
  111267. };
  111268. static long _vq_quantmap__16c2_s_p7_1[] = {
  111269. 9, 7, 5, 3, 1, 0, 2, 4,
  111270. 6, 8, 10,
  111271. };
  111272. static encode_aux_threshmatch _vq_auxt__16c2_s_p7_1 = {
  111273. _vq_quantthresh__16c2_s_p7_1,
  111274. _vq_quantmap__16c2_s_p7_1,
  111275. 11,
  111276. 11
  111277. };
  111278. static static_codebook _16c2_s_p7_1 = {
  111279. 2, 121,
  111280. _vq_lengthlist__16c2_s_p7_1,
  111281. 1, -531365888, 1611661312, 4, 0,
  111282. _vq_quantlist__16c2_s_p7_1,
  111283. NULL,
  111284. &_vq_auxt__16c2_s_p7_1,
  111285. NULL,
  111286. 0
  111287. };
  111288. static long _vq_quantlist__16c2_s_p8_0[] = {
  111289. 7,
  111290. 6,
  111291. 8,
  111292. 5,
  111293. 9,
  111294. 4,
  111295. 10,
  111296. 3,
  111297. 11,
  111298. 2,
  111299. 12,
  111300. 1,
  111301. 13,
  111302. 0,
  111303. 14,
  111304. };
  111305. static long _vq_lengthlist__16c2_s_p8_0[] = {
  111306. 1, 4, 4, 7, 6, 7, 7, 6, 6, 8, 8, 9, 9,10,10, 6,
  111307. 6, 6, 8, 8, 9, 8, 8, 8, 9, 9,11,10,11,11, 7, 6,
  111308. 6, 8, 8, 9, 8, 7, 7, 9, 9,10,10,12,11,14, 8, 8,
  111309. 8, 9, 9, 9, 9, 9,10, 9,10,10,11,13,14, 8, 8, 8,
  111310. 8, 9, 9, 8, 8, 9, 9,10,10,11,12,14,13,11, 9, 9,
  111311. 9, 9, 9, 9, 9,10,11,10,13,12,14,11,13, 8, 9, 9,
  111312. 9, 9, 9,10,10,11,10,13,12,14,14,14, 8, 9, 9, 9,
  111313. 11,11,11,11,11,12,13,13,14,14,14, 9, 8, 9, 9,10,
  111314. 10,12,10,11,12,12,14,14,14,14,11,12,10,10,12,12,
  111315. 12,12,13,14,12,12,14,14,14,12,12, 9,10,11,11,12,
  111316. 14,12,14,14,14,14,14,14,14,14,11,11,12,11,12,14,
  111317. 14,14,14,14,14,14,14,14,14,12,11,11,11,11,14,14,
  111318. 14,14,14,14,14,14,14,14,14,14,13,12,14,14,14,14,
  111319. 14,14,14,14,14,14,14,14,14,12,12,12,13,14,14,13,
  111320. 13,
  111321. };
  111322. static float _vq_quantthresh__16c2_s_p8_0[] = {
  111323. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  111324. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  111325. };
  111326. static long _vq_quantmap__16c2_s_p8_0[] = {
  111327. 13, 11, 9, 7, 5, 3, 1, 0,
  111328. 2, 4, 6, 8, 10, 12, 14,
  111329. };
  111330. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_0 = {
  111331. _vq_quantthresh__16c2_s_p8_0,
  111332. _vq_quantmap__16c2_s_p8_0,
  111333. 15,
  111334. 15
  111335. };
  111336. static static_codebook _16c2_s_p8_0 = {
  111337. 2, 225,
  111338. _vq_lengthlist__16c2_s_p8_0,
  111339. 1, -520986624, 1620377600, 4, 0,
  111340. _vq_quantlist__16c2_s_p8_0,
  111341. NULL,
  111342. &_vq_auxt__16c2_s_p8_0,
  111343. NULL,
  111344. 0
  111345. };
  111346. static long _vq_quantlist__16c2_s_p8_1[] = {
  111347. 10,
  111348. 9,
  111349. 11,
  111350. 8,
  111351. 12,
  111352. 7,
  111353. 13,
  111354. 6,
  111355. 14,
  111356. 5,
  111357. 15,
  111358. 4,
  111359. 16,
  111360. 3,
  111361. 17,
  111362. 2,
  111363. 18,
  111364. 1,
  111365. 19,
  111366. 0,
  111367. 20,
  111368. };
  111369. static long _vq_lengthlist__16c2_s_p8_1[] = {
  111370. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  111371. 8, 8, 8, 8, 8,11,12,11, 7, 7, 8, 8, 8, 8, 9, 9,
  111372. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,11,11,10, 7, 7, 8,
  111373. 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  111374. 11,11, 8, 7, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 9,10,
  111375. 10, 9,10,10,11,11,12, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  111376. 9, 9, 9,10, 9,10,10,10,10,11,11,11, 8, 8, 9, 9,
  111377. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  111378. 11, 8, 8, 9, 8, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,
  111379. 10, 9,10,11,11,11, 9, 9, 9, 9,10, 9, 9, 9,10,10,
  111380. 9,10, 9,10,10,10,10,10,11,12,11,11,11, 9, 9, 9,
  111381. 9, 9,10,10, 9,10,10,10,10,10,10,10,10,12,11,13,
  111382. 13,11, 9, 9, 9, 9,10,10, 9,10,10,10,10,11,10,10,
  111383. 10,10,11,12,11,12,11, 9, 9, 9,10,10, 9,10,10,10,
  111384. 10,10,10,10,10,10,10,11,11,11,12,11, 9,10,10,10,
  111385. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,12,12,
  111386. 11,11,11,10, 9,10,10,10,10,10,10,10,10,11,10,10,
  111387. 10,11,11,11,11,11,11,11,10,10,10,11,10,10,10,10,
  111388. 10,10,10,10,10,10,11,11,11,11,12,12,11,10,10,10,
  111389. 10,10,10,10,10,11,10,10,10,11,10,12,11,11,12,11,
  111390. 11,11,10,10,10,10,10,11,10,10,10,10,10,11,10,10,
  111391. 11,11,11,12,11,12,11,11,12,10,10,10,10,10,10,10,
  111392. 11,10,10,11,10,12,11,11,11,12,11,11,11,11,10,10,
  111393. 10,10,10,10,10,11,11,11,10,11,12,11,11,11,12,11,
  111394. 12,11,12,10,11,10,10,10,10,11,10,10,10,10,10,10,
  111395. 12,11,11,11,11,11,12,12,10,10,10,10,10,11,10,10,
  111396. 11,10,11,11,11,11,11,11,11,11,11,11,11,11,12,11,
  111397. 10,11,10,10,10,10,10,10,10,
  111398. };
  111399. static float _vq_quantthresh__16c2_s_p8_1[] = {
  111400. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  111401. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  111402. 6.5, 7.5, 8.5, 9.5,
  111403. };
  111404. static long _vq_quantmap__16c2_s_p8_1[] = {
  111405. 19, 17, 15, 13, 11, 9, 7, 5,
  111406. 3, 1, 0, 2, 4, 6, 8, 10,
  111407. 12, 14, 16, 18, 20,
  111408. };
  111409. static encode_aux_threshmatch _vq_auxt__16c2_s_p8_1 = {
  111410. _vq_quantthresh__16c2_s_p8_1,
  111411. _vq_quantmap__16c2_s_p8_1,
  111412. 21,
  111413. 21
  111414. };
  111415. static static_codebook _16c2_s_p8_1 = {
  111416. 2, 441,
  111417. _vq_lengthlist__16c2_s_p8_1,
  111418. 1, -529268736, 1611661312, 5, 0,
  111419. _vq_quantlist__16c2_s_p8_1,
  111420. NULL,
  111421. &_vq_auxt__16c2_s_p8_1,
  111422. NULL,
  111423. 0
  111424. };
  111425. static long _vq_quantlist__16c2_s_p9_0[] = {
  111426. 6,
  111427. 5,
  111428. 7,
  111429. 4,
  111430. 8,
  111431. 3,
  111432. 9,
  111433. 2,
  111434. 10,
  111435. 1,
  111436. 11,
  111437. 0,
  111438. 12,
  111439. };
  111440. static long _vq_lengthlist__16c2_s_p9_0[] = {
  111441. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111442. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111443. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111444. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111445. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  111446. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111447. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111448. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111449. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111450. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111451. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  111452. };
  111453. static float _vq_quantthresh__16c2_s_p9_0[] = {
  111454. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5,
  111455. 2327.5, 3258.5, 4189.5, 5120.5,
  111456. };
  111457. static long _vq_quantmap__16c2_s_p9_0[] = {
  111458. 11, 9, 7, 5, 3, 1, 0, 2,
  111459. 4, 6, 8, 10, 12,
  111460. };
  111461. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_0 = {
  111462. _vq_quantthresh__16c2_s_p9_0,
  111463. _vq_quantmap__16c2_s_p9_0,
  111464. 13,
  111465. 13
  111466. };
  111467. static static_codebook _16c2_s_p9_0 = {
  111468. 2, 169,
  111469. _vq_lengthlist__16c2_s_p9_0,
  111470. 1, -510275072, 1631393792, 4, 0,
  111471. _vq_quantlist__16c2_s_p9_0,
  111472. NULL,
  111473. &_vq_auxt__16c2_s_p9_0,
  111474. NULL,
  111475. 0
  111476. };
  111477. static long _vq_quantlist__16c2_s_p9_1[] = {
  111478. 8,
  111479. 7,
  111480. 9,
  111481. 6,
  111482. 10,
  111483. 5,
  111484. 11,
  111485. 4,
  111486. 12,
  111487. 3,
  111488. 13,
  111489. 2,
  111490. 14,
  111491. 1,
  111492. 15,
  111493. 0,
  111494. 16,
  111495. };
  111496. static long _vq_lengthlist__16c2_s_p9_1[] = {
  111497. 1, 5, 5, 9, 8, 7, 7, 7, 6,10,11,11,11,11,11,11,
  111498. 11, 8, 7, 6, 8, 8,10, 9,10,10,10, 9,11,10,10,10,
  111499. 10,10, 8, 6, 6, 8, 8, 9, 8, 9, 8, 9,10,10,10,10,
  111500. 10,10,10,10, 8,10, 9, 9, 9, 9,10,10,10,10,10,10,
  111501. 10,10,10,10,10, 8, 9, 9, 9,10,10, 9,10,10,10,10,
  111502. 10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,10,10,10,
  111503. 10,10,10,10,10,10,10,10, 9, 8, 8, 9, 9,10,10,10,
  111504. 10,10,10,10,10,10,10,10,10,10, 9,10, 9, 9,10,10,
  111505. 10,10,10,10,10,10,10,10,10,10,10, 9, 8, 9, 9,10,
  111506. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  111507. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111508. 8,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111509. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111510. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111511. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111512. 10,10,10,10, 9,10, 9,10,10,10,10,10,10,10,10,10,
  111513. 10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,
  111514. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  111515. 10,
  111516. };
  111517. static float _vq_quantthresh__16c2_s_p9_1[] = {
  111518. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -24.5,
  111519. 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5, 367.5,
  111520. };
  111521. static long _vq_quantmap__16c2_s_p9_1[] = {
  111522. 15, 13, 11, 9, 7, 5, 3, 1,
  111523. 0, 2, 4, 6, 8, 10, 12, 14,
  111524. 16,
  111525. };
  111526. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_1 = {
  111527. _vq_quantthresh__16c2_s_p9_1,
  111528. _vq_quantmap__16c2_s_p9_1,
  111529. 17,
  111530. 17
  111531. };
  111532. static static_codebook _16c2_s_p9_1 = {
  111533. 2, 289,
  111534. _vq_lengthlist__16c2_s_p9_1,
  111535. 1, -518488064, 1622704128, 5, 0,
  111536. _vq_quantlist__16c2_s_p9_1,
  111537. NULL,
  111538. &_vq_auxt__16c2_s_p9_1,
  111539. NULL,
  111540. 0
  111541. };
  111542. static long _vq_quantlist__16c2_s_p9_2[] = {
  111543. 13,
  111544. 12,
  111545. 14,
  111546. 11,
  111547. 15,
  111548. 10,
  111549. 16,
  111550. 9,
  111551. 17,
  111552. 8,
  111553. 18,
  111554. 7,
  111555. 19,
  111556. 6,
  111557. 20,
  111558. 5,
  111559. 21,
  111560. 4,
  111561. 22,
  111562. 3,
  111563. 23,
  111564. 2,
  111565. 24,
  111566. 1,
  111567. 25,
  111568. 0,
  111569. 26,
  111570. };
  111571. static long _vq_lengthlist__16c2_s_p9_2[] = {
  111572. 1, 4, 4, 5, 5, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  111573. 7, 7, 7, 7, 8, 7, 8, 7, 7, 4, 4,
  111574. };
  111575. static float _vq_quantthresh__16c2_s_p9_2[] = {
  111576. -12.5, -11.5, -10.5, -9.5, -8.5, -7.5, -6.5, -5.5,
  111577. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  111578. 3.5, 4.5, 5.5, 6.5, 7.5, 8.5, 9.5, 10.5,
  111579. 11.5, 12.5,
  111580. };
  111581. static long _vq_quantmap__16c2_s_p9_2[] = {
  111582. 25, 23, 21, 19, 17, 15, 13, 11,
  111583. 9, 7, 5, 3, 1, 0, 2, 4,
  111584. 6, 8, 10, 12, 14, 16, 18, 20,
  111585. 22, 24, 26,
  111586. };
  111587. static encode_aux_threshmatch _vq_auxt__16c2_s_p9_2 = {
  111588. _vq_quantthresh__16c2_s_p9_2,
  111589. _vq_quantmap__16c2_s_p9_2,
  111590. 27,
  111591. 27
  111592. };
  111593. static static_codebook _16c2_s_p9_2 = {
  111594. 1, 27,
  111595. _vq_lengthlist__16c2_s_p9_2,
  111596. 1, -528875520, 1611661312, 5, 0,
  111597. _vq_quantlist__16c2_s_p9_2,
  111598. NULL,
  111599. &_vq_auxt__16c2_s_p9_2,
  111600. NULL,
  111601. 0
  111602. };
  111603. static long _huff_lengthlist__16c2_s_short[] = {
  111604. 7,10,11,11,11,14,15,15,17,14, 8, 6, 7, 7, 8, 9,
  111605. 11,11,14,17, 9, 6, 6, 6, 7, 7,10,11,15,16, 9, 6,
  111606. 6, 4, 4, 5, 8, 9,12,16,10, 6, 6, 4, 4, 4, 6, 9,
  111607. 13,16,10, 7, 6, 5, 4, 3, 5, 7,13,16,11, 9, 8, 7,
  111608. 6, 5, 5, 6,12,15,10,10,10, 9, 7, 6, 6, 7,11,15,
  111609. 13,13,13,13,11,10,10, 9,12,16,16,16,16,14,16,15,
  111610. 15,12,14,14,
  111611. };
  111612. static static_codebook _huff_book__16c2_s_short = {
  111613. 2, 100,
  111614. _huff_lengthlist__16c2_s_short,
  111615. 0, 0, 0, 0, 0,
  111616. NULL,
  111617. NULL,
  111618. NULL,
  111619. NULL,
  111620. 0
  111621. };
  111622. static long _vq_quantlist__8c0_s_p1_0[] = {
  111623. 1,
  111624. 0,
  111625. 2,
  111626. };
  111627. static long _vq_lengthlist__8c0_s_p1_0[] = {
  111628. 1, 5, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  111629. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  111634. 0, 0, 0, 7, 8, 9, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  111639. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111642. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111643. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111644. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111650. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111651. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111652. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111664. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111665. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111666. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111667. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111668. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111669. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111670. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111671. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111672. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111673. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  111674. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111675. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111676. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111677. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111678. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0, 0,
  111679. 0, 0, 0, 8, 9,11, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111680. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111681. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111682. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111683. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9,10, 0, 0,
  111684. 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  111720. 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111724. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,11, 0,
  111725. 0, 0, 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 0, 0,
  111726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111729. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,11,11,
  111730. 0, 0, 0, 0, 0, 0, 8,11, 9, 0, 0, 0, 0, 0, 0, 0,
  111731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111792. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111793. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111794. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111795. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111796. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  111999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112038. 0,
  112039. };
  112040. static float _vq_quantthresh__8c0_s_p1_0[] = {
  112041. -0.5, 0.5,
  112042. };
  112043. static long _vq_quantmap__8c0_s_p1_0[] = {
  112044. 1, 0, 2,
  112045. };
  112046. static encode_aux_threshmatch _vq_auxt__8c0_s_p1_0 = {
  112047. _vq_quantthresh__8c0_s_p1_0,
  112048. _vq_quantmap__8c0_s_p1_0,
  112049. 3,
  112050. 3
  112051. };
  112052. static static_codebook _8c0_s_p1_0 = {
  112053. 8, 6561,
  112054. _vq_lengthlist__8c0_s_p1_0,
  112055. 1, -535822336, 1611661312, 2, 0,
  112056. _vq_quantlist__8c0_s_p1_0,
  112057. NULL,
  112058. &_vq_auxt__8c0_s_p1_0,
  112059. NULL,
  112060. 0
  112061. };
  112062. static long _vq_quantlist__8c0_s_p2_0[] = {
  112063. 2,
  112064. 1,
  112065. 3,
  112066. 0,
  112067. 4,
  112068. };
  112069. static long _vq_lengthlist__8c0_s_p2_0[] = {
  112070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112109. 0,
  112110. };
  112111. static float _vq_quantthresh__8c0_s_p2_0[] = {
  112112. -1.5, -0.5, 0.5, 1.5,
  112113. };
  112114. static long _vq_quantmap__8c0_s_p2_0[] = {
  112115. 3, 1, 0, 2, 4,
  112116. };
  112117. static encode_aux_threshmatch _vq_auxt__8c0_s_p2_0 = {
  112118. _vq_quantthresh__8c0_s_p2_0,
  112119. _vq_quantmap__8c0_s_p2_0,
  112120. 5,
  112121. 5
  112122. };
  112123. static static_codebook _8c0_s_p2_0 = {
  112124. 4, 625,
  112125. _vq_lengthlist__8c0_s_p2_0,
  112126. 1, -533725184, 1611661312, 3, 0,
  112127. _vq_quantlist__8c0_s_p2_0,
  112128. NULL,
  112129. &_vq_auxt__8c0_s_p2_0,
  112130. NULL,
  112131. 0
  112132. };
  112133. static long _vq_quantlist__8c0_s_p3_0[] = {
  112134. 2,
  112135. 1,
  112136. 3,
  112137. 0,
  112138. 4,
  112139. };
  112140. static long _vq_lengthlist__8c0_s_p3_0[] = {
  112141. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 6, 7, 7, 0, 0,
  112143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112144. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 8, 8,
  112146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112147. 0, 0, 0, 0, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  112148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112180. 0,
  112181. };
  112182. static float _vq_quantthresh__8c0_s_p3_0[] = {
  112183. -1.5, -0.5, 0.5, 1.5,
  112184. };
  112185. static long _vq_quantmap__8c0_s_p3_0[] = {
  112186. 3, 1, 0, 2, 4,
  112187. };
  112188. static encode_aux_threshmatch _vq_auxt__8c0_s_p3_0 = {
  112189. _vq_quantthresh__8c0_s_p3_0,
  112190. _vq_quantmap__8c0_s_p3_0,
  112191. 5,
  112192. 5
  112193. };
  112194. static static_codebook _8c0_s_p3_0 = {
  112195. 4, 625,
  112196. _vq_lengthlist__8c0_s_p3_0,
  112197. 1, -533725184, 1611661312, 3, 0,
  112198. _vq_quantlist__8c0_s_p3_0,
  112199. NULL,
  112200. &_vq_auxt__8c0_s_p3_0,
  112201. NULL,
  112202. 0
  112203. };
  112204. static long _vq_quantlist__8c0_s_p4_0[] = {
  112205. 4,
  112206. 3,
  112207. 5,
  112208. 2,
  112209. 6,
  112210. 1,
  112211. 7,
  112212. 0,
  112213. 8,
  112214. };
  112215. static long _vq_lengthlist__8c0_s_p4_0[] = {
  112216. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  112217. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  112218. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  112219. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  112220. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112221. 0,
  112222. };
  112223. static float _vq_quantthresh__8c0_s_p4_0[] = {
  112224. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112225. };
  112226. static long _vq_quantmap__8c0_s_p4_0[] = {
  112227. 7, 5, 3, 1, 0, 2, 4, 6,
  112228. 8,
  112229. };
  112230. static encode_aux_threshmatch _vq_auxt__8c0_s_p4_0 = {
  112231. _vq_quantthresh__8c0_s_p4_0,
  112232. _vq_quantmap__8c0_s_p4_0,
  112233. 9,
  112234. 9
  112235. };
  112236. static static_codebook _8c0_s_p4_0 = {
  112237. 2, 81,
  112238. _vq_lengthlist__8c0_s_p4_0,
  112239. 1, -531628032, 1611661312, 4, 0,
  112240. _vq_quantlist__8c0_s_p4_0,
  112241. NULL,
  112242. &_vq_auxt__8c0_s_p4_0,
  112243. NULL,
  112244. 0
  112245. };
  112246. static long _vq_quantlist__8c0_s_p5_0[] = {
  112247. 4,
  112248. 3,
  112249. 5,
  112250. 2,
  112251. 6,
  112252. 1,
  112253. 7,
  112254. 0,
  112255. 8,
  112256. };
  112257. static long _vq_lengthlist__8c0_s_p5_0[] = {
  112258. 1, 3, 3, 5, 5, 7, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  112259. 8, 8, 0, 0, 0, 7, 7, 7, 7, 8, 9, 0, 0, 0, 8, 8,
  112260. 8, 8, 9, 9, 0, 0, 0, 8, 8, 8, 8, 9, 9, 0, 0, 0,
  112261. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  112262. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  112263. 10,
  112264. };
  112265. static float _vq_quantthresh__8c0_s_p5_0[] = {
  112266. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  112267. };
  112268. static long _vq_quantmap__8c0_s_p5_0[] = {
  112269. 7, 5, 3, 1, 0, 2, 4, 6,
  112270. 8,
  112271. };
  112272. static encode_aux_threshmatch _vq_auxt__8c0_s_p5_0 = {
  112273. _vq_quantthresh__8c0_s_p5_0,
  112274. _vq_quantmap__8c0_s_p5_0,
  112275. 9,
  112276. 9
  112277. };
  112278. static static_codebook _8c0_s_p5_0 = {
  112279. 2, 81,
  112280. _vq_lengthlist__8c0_s_p5_0,
  112281. 1, -531628032, 1611661312, 4, 0,
  112282. _vq_quantlist__8c0_s_p5_0,
  112283. NULL,
  112284. &_vq_auxt__8c0_s_p5_0,
  112285. NULL,
  112286. 0
  112287. };
  112288. static long _vq_quantlist__8c0_s_p6_0[] = {
  112289. 8,
  112290. 7,
  112291. 9,
  112292. 6,
  112293. 10,
  112294. 5,
  112295. 11,
  112296. 4,
  112297. 12,
  112298. 3,
  112299. 13,
  112300. 2,
  112301. 14,
  112302. 1,
  112303. 15,
  112304. 0,
  112305. 16,
  112306. };
  112307. static long _vq_lengthlist__8c0_s_p6_0[] = {
  112308. 1, 3, 3, 6, 6, 8, 8, 9, 9, 8, 8,10, 9,10,10,11,
  112309. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  112310. 11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  112311. 11,12,11, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,10,10,
  112312. 11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10, 9, 9,11,
  112313. 10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,10,
  112314. 11,11,11,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,10,
  112315. 10,11,11,12,12,13,13, 0, 0, 0,10,10,10,10,11,11,
  112316. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,10, 9,10,
  112317. 11,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  112318. 10, 9,10,11,12,12,13,13,14,13, 0, 0, 0, 0, 0, 9,
  112319. 9, 9,10,10,10,11,11,13,12,13,13, 0, 0, 0, 0, 0,
  112320. 10,10,10,10,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  112321. 0, 0, 0,10,10,11,11,12,12,13,13,13,14, 0, 0, 0,
  112322. 0, 0, 0, 0,11,11,11,11,12,12,13,14,14,14, 0, 0,
  112323. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,14,13, 0,
  112324. 0, 0, 0, 0, 0, 0,11,11,12,12,13,13,14,14,14,14,
  112325. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  112326. 14,
  112327. };
  112328. static float _vq_quantthresh__8c0_s_p6_0[] = {
  112329. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  112330. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  112331. };
  112332. static long _vq_quantmap__8c0_s_p6_0[] = {
  112333. 15, 13, 11, 9, 7, 5, 3, 1,
  112334. 0, 2, 4, 6, 8, 10, 12, 14,
  112335. 16,
  112336. };
  112337. static encode_aux_threshmatch _vq_auxt__8c0_s_p6_0 = {
  112338. _vq_quantthresh__8c0_s_p6_0,
  112339. _vq_quantmap__8c0_s_p6_0,
  112340. 17,
  112341. 17
  112342. };
  112343. static static_codebook _8c0_s_p6_0 = {
  112344. 2, 289,
  112345. _vq_lengthlist__8c0_s_p6_0,
  112346. 1, -529530880, 1611661312, 5, 0,
  112347. _vq_quantlist__8c0_s_p6_0,
  112348. NULL,
  112349. &_vq_auxt__8c0_s_p6_0,
  112350. NULL,
  112351. 0
  112352. };
  112353. static long _vq_quantlist__8c0_s_p7_0[] = {
  112354. 1,
  112355. 0,
  112356. 2,
  112357. };
  112358. static long _vq_lengthlist__8c0_s_p7_0[] = {
  112359. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,11, 9,10,12,
  112360. 9,10, 4, 7, 7,10,10,10,11, 9, 9, 6,11,10,11,11,
  112361. 12,11,11,11, 6,10,10,11,11,12,11,10,10, 6, 9,10,
  112362. 11,11,11,11,10,10, 7,10,11,12,11,11,12,11,12, 6,
  112363. 9, 9,10, 9, 9,11,10,10, 6, 9, 9,10,10,10,11,10,
  112364. 10,
  112365. };
  112366. static float _vq_quantthresh__8c0_s_p7_0[] = {
  112367. -5.5, 5.5,
  112368. };
  112369. static long _vq_quantmap__8c0_s_p7_0[] = {
  112370. 1, 0, 2,
  112371. };
  112372. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_0 = {
  112373. _vq_quantthresh__8c0_s_p7_0,
  112374. _vq_quantmap__8c0_s_p7_0,
  112375. 3,
  112376. 3
  112377. };
  112378. static static_codebook _8c0_s_p7_0 = {
  112379. 4, 81,
  112380. _vq_lengthlist__8c0_s_p7_0,
  112381. 1, -529137664, 1618345984, 2, 0,
  112382. _vq_quantlist__8c0_s_p7_0,
  112383. NULL,
  112384. &_vq_auxt__8c0_s_p7_0,
  112385. NULL,
  112386. 0
  112387. };
  112388. static long _vq_quantlist__8c0_s_p7_1[] = {
  112389. 5,
  112390. 4,
  112391. 6,
  112392. 3,
  112393. 7,
  112394. 2,
  112395. 8,
  112396. 1,
  112397. 9,
  112398. 0,
  112399. 10,
  112400. };
  112401. static long _vq_lengthlist__8c0_s_p7_1[] = {
  112402. 1, 3, 3, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10, 7, 7,
  112403. 8, 8, 9, 9, 9, 9,10,10, 9, 7, 7, 8, 8, 9, 9, 9,
  112404. 9,10,10,10, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10, 8,
  112405. 8, 9, 9, 9, 9, 8, 9,10,10,10, 8, 8, 9, 9, 9,10,
  112406. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,11,10,11,
  112407. 9, 9, 9, 9,10,10,10,10,11,11,11,10,10, 9, 9,10,
  112408. 10,10, 9,11,10,10,10,10,10,10, 9, 9,10,10,11,11,
  112409. 10,10,10, 9, 9, 9,10,10,10,
  112410. };
  112411. static float _vq_quantthresh__8c0_s_p7_1[] = {
  112412. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  112413. 3.5, 4.5,
  112414. };
  112415. static long _vq_quantmap__8c0_s_p7_1[] = {
  112416. 9, 7, 5, 3, 1, 0, 2, 4,
  112417. 6, 8, 10,
  112418. };
  112419. static encode_aux_threshmatch _vq_auxt__8c0_s_p7_1 = {
  112420. _vq_quantthresh__8c0_s_p7_1,
  112421. _vq_quantmap__8c0_s_p7_1,
  112422. 11,
  112423. 11
  112424. };
  112425. static static_codebook _8c0_s_p7_1 = {
  112426. 2, 121,
  112427. _vq_lengthlist__8c0_s_p7_1,
  112428. 1, -531365888, 1611661312, 4, 0,
  112429. _vq_quantlist__8c0_s_p7_1,
  112430. NULL,
  112431. &_vq_auxt__8c0_s_p7_1,
  112432. NULL,
  112433. 0
  112434. };
  112435. static long _vq_quantlist__8c0_s_p8_0[] = {
  112436. 6,
  112437. 5,
  112438. 7,
  112439. 4,
  112440. 8,
  112441. 3,
  112442. 9,
  112443. 2,
  112444. 10,
  112445. 1,
  112446. 11,
  112447. 0,
  112448. 12,
  112449. };
  112450. static long _vq_lengthlist__8c0_s_p8_0[] = {
  112451. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 6, 6,
  112452. 7, 7, 8, 8, 7, 7, 8, 9,10,10, 7, 6, 6, 7, 7, 8,
  112453. 7, 7, 7, 9, 9,10,12, 0, 8, 8, 8, 8, 8, 9, 8, 8,
  112454. 9, 9,10,10, 0, 8, 8, 8, 8, 8, 9, 8, 9, 9, 9,11,
  112455. 10, 0, 0,13, 9, 8, 9, 9, 9, 9,10,10,11,11, 0,13,
  112456. 0, 9, 9, 9, 9, 9, 9,11,10,11,11, 0, 0, 0, 8, 9,
  112457. 10, 9,10,10,13,11,12,12, 0, 0, 0, 8, 9, 9, 9,10,
  112458. 10,13,12,12,13, 0, 0, 0,12, 0,10,10,12,11,10,11,
  112459. 12,12, 0, 0, 0,13,13,10,10,10,11,12, 0,13, 0, 0,
  112460. 0, 0, 0, 0,13,11, 0,12,12,12,13,12, 0, 0, 0, 0,
  112461. 0, 0,13,13,11,13,13,11,12,
  112462. };
  112463. static float _vq_quantthresh__8c0_s_p8_0[] = {
  112464. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  112465. 12.5, 17.5, 22.5, 27.5,
  112466. };
  112467. static long _vq_quantmap__8c0_s_p8_0[] = {
  112468. 11, 9, 7, 5, 3, 1, 0, 2,
  112469. 4, 6, 8, 10, 12,
  112470. };
  112471. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_0 = {
  112472. _vq_quantthresh__8c0_s_p8_0,
  112473. _vq_quantmap__8c0_s_p8_0,
  112474. 13,
  112475. 13
  112476. };
  112477. static static_codebook _8c0_s_p8_0 = {
  112478. 2, 169,
  112479. _vq_lengthlist__8c0_s_p8_0,
  112480. 1, -526516224, 1616117760, 4, 0,
  112481. _vq_quantlist__8c0_s_p8_0,
  112482. NULL,
  112483. &_vq_auxt__8c0_s_p8_0,
  112484. NULL,
  112485. 0
  112486. };
  112487. static long _vq_quantlist__8c0_s_p8_1[] = {
  112488. 2,
  112489. 1,
  112490. 3,
  112491. 0,
  112492. 4,
  112493. };
  112494. static long _vq_lengthlist__8c0_s_p8_1[] = {
  112495. 1, 3, 4, 5, 5, 7, 6, 6, 6, 5, 7, 7, 7, 6, 6, 7,
  112496. 7, 7, 6, 6, 7, 7, 7, 6, 6,
  112497. };
  112498. static float _vq_quantthresh__8c0_s_p8_1[] = {
  112499. -1.5, -0.5, 0.5, 1.5,
  112500. };
  112501. static long _vq_quantmap__8c0_s_p8_1[] = {
  112502. 3, 1, 0, 2, 4,
  112503. };
  112504. static encode_aux_threshmatch _vq_auxt__8c0_s_p8_1 = {
  112505. _vq_quantthresh__8c0_s_p8_1,
  112506. _vq_quantmap__8c0_s_p8_1,
  112507. 5,
  112508. 5
  112509. };
  112510. static static_codebook _8c0_s_p8_1 = {
  112511. 2, 25,
  112512. _vq_lengthlist__8c0_s_p8_1,
  112513. 1, -533725184, 1611661312, 3, 0,
  112514. _vq_quantlist__8c0_s_p8_1,
  112515. NULL,
  112516. &_vq_auxt__8c0_s_p8_1,
  112517. NULL,
  112518. 0
  112519. };
  112520. static long _vq_quantlist__8c0_s_p9_0[] = {
  112521. 1,
  112522. 0,
  112523. 2,
  112524. };
  112525. static long _vq_lengthlist__8c0_s_p9_0[] = {
  112526. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112527. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  112528. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112529. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112530. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  112531. 7,
  112532. };
  112533. static float _vq_quantthresh__8c0_s_p9_0[] = {
  112534. -157.5, 157.5,
  112535. };
  112536. static long _vq_quantmap__8c0_s_p9_0[] = {
  112537. 1, 0, 2,
  112538. };
  112539. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_0 = {
  112540. _vq_quantthresh__8c0_s_p9_0,
  112541. _vq_quantmap__8c0_s_p9_0,
  112542. 3,
  112543. 3
  112544. };
  112545. static static_codebook _8c0_s_p9_0 = {
  112546. 4, 81,
  112547. _vq_lengthlist__8c0_s_p9_0,
  112548. 1, -518803456, 1628680192, 2, 0,
  112549. _vq_quantlist__8c0_s_p9_0,
  112550. NULL,
  112551. &_vq_auxt__8c0_s_p9_0,
  112552. NULL,
  112553. 0
  112554. };
  112555. static long _vq_quantlist__8c0_s_p9_1[] = {
  112556. 7,
  112557. 6,
  112558. 8,
  112559. 5,
  112560. 9,
  112561. 4,
  112562. 10,
  112563. 3,
  112564. 11,
  112565. 2,
  112566. 12,
  112567. 1,
  112568. 13,
  112569. 0,
  112570. 14,
  112571. };
  112572. static long _vq_lengthlist__8c0_s_p9_1[] = {
  112573. 1, 4, 4, 5, 5,10, 8,11,11,11,11,11,11,11,11, 6,
  112574. 6, 6, 7, 6,11,10,11,11,11,11,11,11,11,11, 7, 5,
  112575. 6, 6, 6, 8, 7,11,11,11,11,11,11,11,11,11, 7, 8,
  112576. 8, 8, 9, 9,11,11,11,11,11,11,11,11,11, 9, 8, 7,
  112577. 8, 9,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112578. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  112579. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112580. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112581. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112582. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112583. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112584. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112585. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112586. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  112587. 11,
  112588. };
  112589. static float _vq_quantthresh__8c0_s_p9_1[] = {
  112590. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  112591. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  112592. };
  112593. static long _vq_quantmap__8c0_s_p9_1[] = {
  112594. 13, 11, 9, 7, 5, 3, 1, 0,
  112595. 2, 4, 6, 8, 10, 12, 14,
  112596. };
  112597. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_1 = {
  112598. _vq_quantthresh__8c0_s_p9_1,
  112599. _vq_quantmap__8c0_s_p9_1,
  112600. 15,
  112601. 15
  112602. };
  112603. static static_codebook _8c0_s_p9_1 = {
  112604. 2, 225,
  112605. _vq_lengthlist__8c0_s_p9_1,
  112606. 1, -520986624, 1620377600, 4, 0,
  112607. _vq_quantlist__8c0_s_p9_1,
  112608. NULL,
  112609. &_vq_auxt__8c0_s_p9_1,
  112610. NULL,
  112611. 0
  112612. };
  112613. static long _vq_quantlist__8c0_s_p9_2[] = {
  112614. 10,
  112615. 9,
  112616. 11,
  112617. 8,
  112618. 12,
  112619. 7,
  112620. 13,
  112621. 6,
  112622. 14,
  112623. 5,
  112624. 15,
  112625. 4,
  112626. 16,
  112627. 3,
  112628. 17,
  112629. 2,
  112630. 18,
  112631. 1,
  112632. 19,
  112633. 0,
  112634. 20,
  112635. };
  112636. static long _vq_lengthlist__8c0_s_p9_2[] = {
  112637. 1, 5, 5, 7, 7, 8, 7, 8, 8,10,10, 9, 9,10,10,10,
  112638. 11,11,10,12,11,12,12,12, 9, 8, 8, 8, 8, 8, 9,10,
  112639. 10,10,10,11,11,11,10,11,11,12,12,11,12, 8, 8, 7,
  112640. 7, 8, 9,10,10,10, 9,10,10, 9,10,10,11,11,11,11,
  112641. 11,11, 9, 9, 9, 9, 8, 9,10,10,11,10,10,11,11,12,
  112642. 10,10,12,12,11,11,10, 9, 9,10, 8, 9,10,10,10, 9,
  112643. 10,10,11,11,10,11,10,10,10,12,12,12, 9,10, 9,10,
  112644. 9, 9,10,10,11,11,11,11,10,10,10,11,12,11,12,11,
  112645. 12,10,11,10,11, 9,10, 9,10, 9,10,10, 9,10,10,11,
  112646. 10,11,11,11,11,12,11, 9,10,10,10,10,11,11,11,11,
  112647. 11,10,11,11,11,11,10,12,10,12,12,11,12,10,10,11,
  112648. 10, 9,11,10,11, 9,10,11,10,10,10,11,11,11,11,12,
  112649. 12,10, 9, 9,11,10, 9,12,11,10,12,12,11,11,11,11,
  112650. 10,11,11,12,11,10,12, 9,11,10,11,10,10,11,10,11,
  112651. 9,10,10,10,11,12,11,11,12,11,10,10,11,11, 9,10,
  112652. 10,12,10,11,10,10,10, 9,10,10,10,10, 9,10,10,11,
  112653. 11,11,11,12,11,10,10,10,10,11,11,10,11,11, 9,11,
  112654. 10,12,10,12,11,10,11,10,10,10,11,10,10,11,11,10,
  112655. 11,10,10,10,10,11,11,12,10,10,10,11,10,11,12,11,
  112656. 10,11,10,10,11,11,10,12,10, 9,10,10,11,11,11,10,
  112657. 12,10,10,11,11,11,10,10,11,10,10,10,11,10,11,10,
  112658. 12,11,11,10,10,10,12,10,10,11, 9,10,11,11,11,10,
  112659. 10,11,10,10, 9,11,11,12,12,11,12,11,11,11,11,11,
  112660. 11, 9,10,11,10,12,10,10,10,10,11,10,10,11,10,10,
  112661. 12,10,10,10,10,10, 9,12,10,10,10,10,12, 9,11,10,
  112662. 10,11,10,12,12,10,12,12,12,10,10,10,10, 9,10,11,
  112663. 10,10,12,10,10,12,11,10,11,10,10,12,11,10,12,10,
  112664. 10,11, 9,11,10, 9,10, 9,10,
  112665. };
  112666. static float _vq_quantthresh__8c0_s_p9_2[] = {
  112667. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  112668. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  112669. 6.5, 7.5, 8.5, 9.5,
  112670. };
  112671. static long _vq_quantmap__8c0_s_p9_2[] = {
  112672. 19, 17, 15, 13, 11, 9, 7, 5,
  112673. 3, 1, 0, 2, 4, 6, 8, 10,
  112674. 12, 14, 16, 18, 20,
  112675. };
  112676. static encode_aux_threshmatch _vq_auxt__8c0_s_p9_2 = {
  112677. _vq_quantthresh__8c0_s_p9_2,
  112678. _vq_quantmap__8c0_s_p9_2,
  112679. 21,
  112680. 21
  112681. };
  112682. static static_codebook _8c0_s_p9_2 = {
  112683. 2, 441,
  112684. _vq_lengthlist__8c0_s_p9_2,
  112685. 1, -529268736, 1611661312, 5, 0,
  112686. _vq_quantlist__8c0_s_p9_2,
  112687. NULL,
  112688. &_vq_auxt__8c0_s_p9_2,
  112689. NULL,
  112690. 0
  112691. };
  112692. static long _huff_lengthlist__8c0_s_single[] = {
  112693. 4, 5,18, 7,10, 6, 7, 8, 9,10, 5, 2,18, 5, 7, 5,
  112694. 6, 7, 8,11,17,17,17,17,17,17,17,17,17,17, 7, 4,
  112695. 17, 6, 9, 6, 8,10,12,15,11, 7,17, 9, 6, 6, 7, 9,
  112696. 11,15, 6, 4,17, 6, 6, 4, 5, 8,11,16, 6, 6,17, 8,
  112697. 6, 5, 6, 9,13,16, 8, 9,17,11, 9, 8, 8,11,13,17,
  112698. 9,12,17,15,14,13,12,13,14,17,12,15,17,17,17,17,
  112699. 17,16,17,17,
  112700. };
  112701. static static_codebook _huff_book__8c0_s_single = {
  112702. 2, 100,
  112703. _huff_lengthlist__8c0_s_single,
  112704. 0, 0, 0, 0, 0,
  112705. NULL,
  112706. NULL,
  112707. NULL,
  112708. NULL,
  112709. 0
  112710. };
  112711. static long _vq_quantlist__8c1_s_p1_0[] = {
  112712. 1,
  112713. 0,
  112714. 2,
  112715. };
  112716. static long _vq_lengthlist__8c1_s_p1_0[] = {
  112717. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  112718. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0,
  112723. 0, 0, 0, 7, 8, 9, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  112728. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112735. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112736. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112737. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112738. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112739. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112740. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112741. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112742. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112743. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112744. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112745. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112746. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112747. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112748. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112749. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112750. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112751. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112752. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112753. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112754. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112755. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112756. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112757. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112758. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112759. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112760. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112761. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112762. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  112763. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112764. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112765. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112766. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112767. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  112768. 0, 0, 0, 8, 8,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112769. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112770. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112771. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112772. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  112773. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  112809. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112813. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  112814. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  112815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112818. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  112819. 0, 0, 0, 0, 0, 0, 8,10, 8, 0, 0, 0, 0, 0, 0, 0,
  112820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112831. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112836. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112841. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112845. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112846. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112847. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  112999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113127. 0,
  113128. };
  113129. static float _vq_quantthresh__8c1_s_p1_0[] = {
  113130. -0.5, 0.5,
  113131. };
  113132. static long _vq_quantmap__8c1_s_p1_0[] = {
  113133. 1, 0, 2,
  113134. };
  113135. static encode_aux_threshmatch _vq_auxt__8c1_s_p1_0 = {
  113136. _vq_quantthresh__8c1_s_p1_0,
  113137. _vq_quantmap__8c1_s_p1_0,
  113138. 3,
  113139. 3
  113140. };
  113141. static static_codebook _8c1_s_p1_0 = {
  113142. 8, 6561,
  113143. _vq_lengthlist__8c1_s_p1_0,
  113144. 1, -535822336, 1611661312, 2, 0,
  113145. _vq_quantlist__8c1_s_p1_0,
  113146. NULL,
  113147. &_vq_auxt__8c1_s_p1_0,
  113148. NULL,
  113149. 0
  113150. };
  113151. static long _vq_quantlist__8c1_s_p2_0[] = {
  113152. 2,
  113153. 1,
  113154. 3,
  113155. 0,
  113156. 4,
  113157. };
  113158. static long _vq_lengthlist__8c1_s_p2_0[] = {
  113159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113198. 0,
  113199. };
  113200. static float _vq_quantthresh__8c1_s_p2_0[] = {
  113201. -1.5, -0.5, 0.5, 1.5,
  113202. };
  113203. static long _vq_quantmap__8c1_s_p2_0[] = {
  113204. 3, 1, 0, 2, 4,
  113205. };
  113206. static encode_aux_threshmatch _vq_auxt__8c1_s_p2_0 = {
  113207. _vq_quantthresh__8c1_s_p2_0,
  113208. _vq_quantmap__8c1_s_p2_0,
  113209. 5,
  113210. 5
  113211. };
  113212. static static_codebook _8c1_s_p2_0 = {
  113213. 4, 625,
  113214. _vq_lengthlist__8c1_s_p2_0,
  113215. 1, -533725184, 1611661312, 3, 0,
  113216. _vq_quantlist__8c1_s_p2_0,
  113217. NULL,
  113218. &_vq_auxt__8c1_s_p2_0,
  113219. NULL,
  113220. 0
  113221. };
  113222. static long _vq_quantlist__8c1_s_p3_0[] = {
  113223. 2,
  113224. 1,
  113225. 3,
  113226. 0,
  113227. 4,
  113228. };
  113229. static long _vq_lengthlist__8c1_s_p3_0[] = {
  113230. 2, 4, 4, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  113232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113233. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 7, 7,
  113235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113236. 0, 0, 0, 0, 6, 6, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113269. 0,
  113270. };
  113271. static float _vq_quantthresh__8c1_s_p3_0[] = {
  113272. -1.5, -0.5, 0.5, 1.5,
  113273. };
  113274. static long _vq_quantmap__8c1_s_p3_0[] = {
  113275. 3, 1, 0, 2, 4,
  113276. };
  113277. static encode_aux_threshmatch _vq_auxt__8c1_s_p3_0 = {
  113278. _vq_quantthresh__8c1_s_p3_0,
  113279. _vq_quantmap__8c1_s_p3_0,
  113280. 5,
  113281. 5
  113282. };
  113283. static static_codebook _8c1_s_p3_0 = {
  113284. 4, 625,
  113285. _vq_lengthlist__8c1_s_p3_0,
  113286. 1, -533725184, 1611661312, 3, 0,
  113287. _vq_quantlist__8c1_s_p3_0,
  113288. NULL,
  113289. &_vq_auxt__8c1_s_p3_0,
  113290. NULL,
  113291. 0
  113292. };
  113293. static long _vq_quantlist__8c1_s_p4_0[] = {
  113294. 4,
  113295. 3,
  113296. 5,
  113297. 2,
  113298. 6,
  113299. 1,
  113300. 7,
  113301. 0,
  113302. 8,
  113303. };
  113304. static long _vq_lengthlist__8c1_s_p4_0[] = {
  113305. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  113306. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  113307. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  113308. 8, 8, 0, 0, 0, 0, 0, 0, 0, 9, 8, 0, 0, 0, 0, 0,
  113309. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113310. 0,
  113311. };
  113312. static float _vq_quantthresh__8c1_s_p4_0[] = {
  113313. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113314. };
  113315. static long _vq_quantmap__8c1_s_p4_0[] = {
  113316. 7, 5, 3, 1, 0, 2, 4, 6,
  113317. 8,
  113318. };
  113319. static encode_aux_threshmatch _vq_auxt__8c1_s_p4_0 = {
  113320. _vq_quantthresh__8c1_s_p4_0,
  113321. _vq_quantmap__8c1_s_p4_0,
  113322. 9,
  113323. 9
  113324. };
  113325. static static_codebook _8c1_s_p4_0 = {
  113326. 2, 81,
  113327. _vq_lengthlist__8c1_s_p4_0,
  113328. 1, -531628032, 1611661312, 4, 0,
  113329. _vq_quantlist__8c1_s_p4_0,
  113330. NULL,
  113331. &_vq_auxt__8c1_s_p4_0,
  113332. NULL,
  113333. 0
  113334. };
  113335. static long _vq_quantlist__8c1_s_p5_0[] = {
  113336. 4,
  113337. 3,
  113338. 5,
  113339. 2,
  113340. 6,
  113341. 1,
  113342. 7,
  113343. 0,
  113344. 8,
  113345. };
  113346. static long _vq_lengthlist__8c1_s_p5_0[] = {
  113347. 1, 3, 3, 4, 5, 6, 6, 8, 8, 0, 0, 0, 8, 8, 7, 7,
  113348. 9, 9, 0, 0, 0, 8, 8, 7, 7, 9, 9, 0, 0, 0, 9,10,
  113349. 8, 8, 9, 9, 0, 0, 0,10,10, 8, 8, 9, 9, 0, 0, 0,
  113350. 11,10, 8, 8,10,10, 0, 0, 0,11,11, 8, 8,10,10, 0,
  113351. 0, 0,12,12, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  113352. 10,
  113353. };
  113354. static float _vq_quantthresh__8c1_s_p5_0[] = {
  113355. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  113356. };
  113357. static long _vq_quantmap__8c1_s_p5_0[] = {
  113358. 7, 5, 3, 1, 0, 2, 4, 6,
  113359. 8,
  113360. };
  113361. static encode_aux_threshmatch _vq_auxt__8c1_s_p5_0 = {
  113362. _vq_quantthresh__8c1_s_p5_0,
  113363. _vq_quantmap__8c1_s_p5_0,
  113364. 9,
  113365. 9
  113366. };
  113367. static static_codebook _8c1_s_p5_0 = {
  113368. 2, 81,
  113369. _vq_lengthlist__8c1_s_p5_0,
  113370. 1, -531628032, 1611661312, 4, 0,
  113371. _vq_quantlist__8c1_s_p5_0,
  113372. NULL,
  113373. &_vq_auxt__8c1_s_p5_0,
  113374. NULL,
  113375. 0
  113376. };
  113377. static long _vq_quantlist__8c1_s_p6_0[] = {
  113378. 8,
  113379. 7,
  113380. 9,
  113381. 6,
  113382. 10,
  113383. 5,
  113384. 11,
  113385. 4,
  113386. 12,
  113387. 3,
  113388. 13,
  113389. 2,
  113390. 14,
  113391. 1,
  113392. 15,
  113393. 0,
  113394. 16,
  113395. };
  113396. static long _vq_lengthlist__8c1_s_p6_0[] = {
  113397. 1, 3, 3, 5, 5, 8, 8, 8, 8, 9, 9,10,10,11,11,11,
  113398. 11, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11,
  113399. 12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113400. 11,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,11,
  113401. 12,12,12,12, 0, 0, 0, 9, 9, 8, 8,10,10,10,10,11,
  113402. 11,12,12,12,12, 0, 0, 0,10,10, 9, 9,10,10,10,10,
  113403. 11,11,12,12,13,13, 0, 0, 0,10,10, 9, 9,10,10,10,
  113404. 10,11,11,12,12,13,13, 0, 0, 0,11,11, 9, 9,10,10,
  113405. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  113406. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  113407. 10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0, 0, 9,
  113408. 9,10,10,11,11,12,11,12,12,13,13, 0, 0, 0, 0, 0,
  113409. 10,10,11,11,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  113410. 0, 0, 0,11,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  113411. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  113412. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,13, 0,
  113413. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  113414. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  113415. 14,
  113416. };
  113417. static float _vq_quantthresh__8c1_s_p6_0[] = {
  113418. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  113419. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  113420. };
  113421. static long _vq_quantmap__8c1_s_p6_0[] = {
  113422. 15, 13, 11, 9, 7, 5, 3, 1,
  113423. 0, 2, 4, 6, 8, 10, 12, 14,
  113424. 16,
  113425. };
  113426. static encode_aux_threshmatch _vq_auxt__8c1_s_p6_0 = {
  113427. _vq_quantthresh__8c1_s_p6_0,
  113428. _vq_quantmap__8c1_s_p6_0,
  113429. 17,
  113430. 17
  113431. };
  113432. static static_codebook _8c1_s_p6_0 = {
  113433. 2, 289,
  113434. _vq_lengthlist__8c1_s_p6_0,
  113435. 1, -529530880, 1611661312, 5, 0,
  113436. _vq_quantlist__8c1_s_p6_0,
  113437. NULL,
  113438. &_vq_auxt__8c1_s_p6_0,
  113439. NULL,
  113440. 0
  113441. };
  113442. static long _vq_quantlist__8c1_s_p7_0[] = {
  113443. 1,
  113444. 0,
  113445. 2,
  113446. };
  113447. static long _vq_lengthlist__8c1_s_p7_0[] = {
  113448. 1, 4, 4, 6, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  113449. 9, 9, 5, 7, 7,10, 9, 9,10, 9, 9, 6,10,10,10,10,
  113450. 10,11,10,10, 6, 9, 9,10, 9,10,11,10,10, 6, 9, 9,
  113451. 10, 9, 9,11, 9,10, 7,10,10,11,11,11,11,10,10, 6,
  113452. 9, 9,10,10,10,11, 9, 9, 6, 9, 9,10,10,10,10, 9,
  113453. 9,
  113454. };
  113455. static float _vq_quantthresh__8c1_s_p7_0[] = {
  113456. -5.5, 5.5,
  113457. };
  113458. static long _vq_quantmap__8c1_s_p7_0[] = {
  113459. 1, 0, 2,
  113460. };
  113461. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_0 = {
  113462. _vq_quantthresh__8c1_s_p7_0,
  113463. _vq_quantmap__8c1_s_p7_0,
  113464. 3,
  113465. 3
  113466. };
  113467. static static_codebook _8c1_s_p7_0 = {
  113468. 4, 81,
  113469. _vq_lengthlist__8c1_s_p7_0,
  113470. 1, -529137664, 1618345984, 2, 0,
  113471. _vq_quantlist__8c1_s_p7_0,
  113472. NULL,
  113473. &_vq_auxt__8c1_s_p7_0,
  113474. NULL,
  113475. 0
  113476. };
  113477. static long _vq_quantlist__8c1_s_p7_1[] = {
  113478. 5,
  113479. 4,
  113480. 6,
  113481. 3,
  113482. 7,
  113483. 2,
  113484. 8,
  113485. 1,
  113486. 9,
  113487. 0,
  113488. 10,
  113489. };
  113490. static long _vq_lengthlist__8c1_s_p7_1[] = {
  113491. 2, 3, 3, 5, 5, 7, 7, 7, 7, 7, 7,10,10, 9, 7, 7,
  113492. 7, 7, 8, 8, 8, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8, 8,
  113493. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  113494. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  113495. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  113496. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  113497. 8, 8, 8,10,10,10,10,10, 8, 8, 8, 8, 8, 8,10,10,
  113498. 10,10,10, 8, 8, 8, 8, 8, 8,
  113499. };
  113500. static float _vq_quantthresh__8c1_s_p7_1[] = {
  113501. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  113502. 3.5, 4.5,
  113503. };
  113504. static long _vq_quantmap__8c1_s_p7_1[] = {
  113505. 9, 7, 5, 3, 1, 0, 2, 4,
  113506. 6, 8, 10,
  113507. };
  113508. static encode_aux_threshmatch _vq_auxt__8c1_s_p7_1 = {
  113509. _vq_quantthresh__8c1_s_p7_1,
  113510. _vq_quantmap__8c1_s_p7_1,
  113511. 11,
  113512. 11
  113513. };
  113514. static static_codebook _8c1_s_p7_1 = {
  113515. 2, 121,
  113516. _vq_lengthlist__8c1_s_p7_1,
  113517. 1, -531365888, 1611661312, 4, 0,
  113518. _vq_quantlist__8c1_s_p7_1,
  113519. NULL,
  113520. &_vq_auxt__8c1_s_p7_1,
  113521. NULL,
  113522. 0
  113523. };
  113524. static long _vq_quantlist__8c1_s_p8_0[] = {
  113525. 6,
  113526. 5,
  113527. 7,
  113528. 4,
  113529. 8,
  113530. 3,
  113531. 9,
  113532. 2,
  113533. 10,
  113534. 1,
  113535. 11,
  113536. 0,
  113537. 12,
  113538. };
  113539. static long _vq_lengthlist__8c1_s_p8_0[] = {
  113540. 1, 4, 4, 6, 6, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5,
  113541. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  113542. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  113543. 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  113544. 11, 0,12,12, 9, 9, 9, 9,10, 9,10,11,11,11, 0,13,
  113545. 12, 9, 8, 9, 9,10,10,11,11,12,11, 0, 0, 0, 9, 9,
  113546. 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10, 9, 9,10,
  113547. 10,11,11,12,12, 0, 0, 0,13,13,10,10,11,11,12,11,
  113548. 13,12, 0, 0, 0,14,14,10,10,11,10,11,11,12,12, 0,
  113549. 0, 0, 0, 0,12,12,11,11,12,12,13,13, 0, 0, 0, 0,
  113550. 0,12,12,11,10,12,11,13,12,
  113551. };
  113552. static float _vq_quantthresh__8c1_s_p8_0[] = {
  113553. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  113554. 12.5, 17.5, 22.5, 27.5,
  113555. };
  113556. static long _vq_quantmap__8c1_s_p8_0[] = {
  113557. 11, 9, 7, 5, 3, 1, 0, 2,
  113558. 4, 6, 8, 10, 12,
  113559. };
  113560. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_0 = {
  113561. _vq_quantthresh__8c1_s_p8_0,
  113562. _vq_quantmap__8c1_s_p8_0,
  113563. 13,
  113564. 13
  113565. };
  113566. static static_codebook _8c1_s_p8_0 = {
  113567. 2, 169,
  113568. _vq_lengthlist__8c1_s_p8_0,
  113569. 1, -526516224, 1616117760, 4, 0,
  113570. _vq_quantlist__8c1_s_p8_0,
  113571. NULL,
  113572. &_vq_auxt__8c1_s_p8_0,
  113573. NULL,
  113574. 0
  113575. };
  113576. static long _vq_quantlist__8c1_s_p8_1[] = {
  113577. 2,
  113578. 1,
  113579. 3,
  113580. 0,
  113581. 4,
  113582. };
  113583. static long _vq_lengthlist__8c1_s_p8_1[] = {
  113584. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  113585. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  113586. };
  113587. static float _vq_quantthresh__8c1_s_p8_1[] = {
  113588. -1.5, -0.5, 0.5, 1.5,
  113589. };
  113590. static long _vq_quantmap__8c1_s_p8_1[] = {
  113591. 3, 1, 0, 2, 4,
  113592. };
  113593. static encode_aux_threshmatch _vq_auxt__8c1_s_p8_1 = {
  113594. _vq_quantthresh__8c1_s_p8_1,
  113595. _vq_quantmap__8c1_s_p8_1,
  113596. 5,
  113597. 5
  113598. };
  113599. static static_codebook _8c1_s_p8_1 = {
  113600. 2, 25,
  113601. _vq_lengthlist__8c1_s_p8_1,
  113602. 1, -533725184, 1611661312, 3, 0,
  113603. _vq_quantlist__8c1_s_p8_1,
  113604. NULL,
  113605. &_vq_auxt__8c1_s_p8_1,
  113606. NULL,
  113607. 0
  113608. };
  113609. static long _vq_quantlist__8c1_s_p9_0[] = {
  113610. 6,
  113611. 5,
  113612. 7,
  113613. 4,
  113614. 8,
  113615. 3,
  113616. 9,
  113617. 2,
  113618. 10,
  113619. 1,
  113620. 11,
  113621. 0,
  113622. 12,
  113623. };
  113624. static long _vq_lengthlist__8c1_s_p9_0[] = {
  113625. 1, 3, 3,10,10,10,10,10,10,10,10,10,10, 5, 6, 6,
  113626. 10,10,10,10,10,10,10,10,10,10, 6, 7, 8,10,10,10,
  113627. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113628. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113629. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113630. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113631. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113632. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113633. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113634. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113635. 10,10,10,10,10, 9, 9, 9, 9,
  113636. };
  113637. static float _vq_quantthresh__8c1_s_p9_0[] = {
  113638. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  113639. 787.5, 1102.5, 1417.5, 1732.5,
  113640. };
  113641. static long _vq_quantmap__8c1_s_p9_0[] = {
  113642. 11, 9, 7, 5, 3, 1, 0, 2,
  113643. 4, 6, 8, 10, 12,
  113644. };
  113645. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_0 = {
  113646. _vq_quantthresh__8c1_s_p9_0,
  113647. _vq_quantmap__8c1_s_p9_0,
  113648. 13,
  113649. 13
  113650. };
  113651. static static_codebook _8c1_s_p9_0 = {
  113652. 2, 169,
  113653. _vq_lengthlist__8c1_s_p9_0,
  113654. 1, -513964032, 1628680192, 4, 0,
  113655. _vq_quantlist__8c1_s_p9_0,
  113656. NULL,
  113657. &_vq_auxt__8c1_s_p9_0,
  113658. NULL,
  113659. 0
  113660. };
  113661. static long _vq_quantlist__8c1_s_p9_1[] = {
  113662. 7,
  113663. 6,
  113664. 8,
  113665. 5,
  113666. 9,
  113667. 4,
  113668. 10,
  113669. 3,
  113670. 11,
  113671. 2,
  113672. 12,
  113673. 1,
  113674. 13,
  113675. 0,
  113676. 14,
  113677. };
  113678. static long _vq_lengthlist__8c1_s_p9_1[] = {
  113679. 1, 4, 4, 5, 5, 7, 7, 9, 9,11,11,12,12,13,13, 6,
  113680. 5, 5, 6, 6, 9, 9,10,10,12,12,12,13,15,14, 6, 5,
  113681. 5, 7, 7, 9, 9,10,10,12,12,12,13,14,13,17, 7, 7,
  113682. 8, 8,10,10,11,11,12,13,13,13,13,13,17, 7, 7, 8,
  113683. 8,10,10,11,11,13,13,13,13,14,14,17,11,11, 9, 9,
  113684. 11,11,12,12,12,13,13,14,15,13,17,12,12, 9, 9,11,
  113685. 11,12,12,13,13,13,13,14,16,17,17,17,11,12,12,12,
  113686. 13,13,13,14,15,14,15,15,17,17,17,12,12,11,11,13,
  113687. 13,14,14,15,14,15,15,17,17,17,15,15,13,13,14,14,
  113688. 15,14,15,15,16,15,17,17,17,15,15,13,13,13,14,14,
  113689. 15,15,15,15,16,17,17,17,17,16,14,15,14,14,15,14,
  113690. 14,15,15,15,17,17,17,17,17,14,14,16,14,15,15,15,
  113691. 15,15,15,17,17,17,17,17,17,16,16,15,17,15,15,14,
  113692. 17,15,17,16,17,17,17,17,16,15,14,15,15,15,15,15,
  113693. 15,
  113694. };
  113695. static float _vq_quantthresh__8c1_s_p9_1[] = {
  113696. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  113697. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  113698. };
  113699. static long _vq_quantmap__8c1_s_p9_1[] = {
  113700. 13, 11, 9, 7, 5, 3, 1, 0,
  113701. 2, 4, 6, 8, 10, 12, 14,
  113702. };
  113703. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_1 = {
  113704. _vq_quantthresh__8c1_s_p9_1,
  113705. _vq_quantmap__8c1_s_p9_1,
  113706. 15,
  113707. 15
  113708. };
  113709. static static_codebook _8c1_s_p9_1 = {
  113710. 2, 225,
  113711. _vq_lengthlist__8c1_s_p9_1,
  113712. 1, -520986624, 1620377600, 4, 0,
  113713. _vq_quantlist__8c1_s_p9_1,
  113714. NULL,
  113715. &_vq_auxt__8c1_s_p9_1,
  113716. NULL,
  113717. 0
  113718. };
  113719. static long _vq_quantlist__8c1_s_p9_2[] = {
  113720. 10,
  113721. 9,
  113722. 11,
  113723. 8,
  113724. 12,
  113725. 7,
  113726. 13,
  113727. 6,
  113728. 14,
  113729. 5,
  113730. 15,
  113731. 4,
  113732. 16,
  113733. 3,
  113734. 17,
  113735. 2,
  113736. 18,
  113737. 1,
  113738. 19,
  113739. 0,
  113740. 20,
  113741. };
  113742. static long _vq_lengthlist__8c1_s_p9_2[] = {
  113743. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  113744. 9, 9, 9, 9, 9,11,11,12, 7, 7, 7, 7, 8, 8, 9, 9,
  113745. 9, 9,10,10,10,10,10,10,10,10,11,11,11, 7, 7, 7,
  113746. 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,11,
  113747. 11,12, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,
  113748. 10,10,10,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  113749. 9,10,10,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  113750. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,11,11,
  113751. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  113752. 10,10,10,11,12,11, 9, 9, 8, 9, 9, 9, 9, 9,10,10,
  113753. 10,10,10,10,10,10,10,10,11,11,11,11,11, 8, 8, 9,
  113754. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,11,12,11,
  113755. 12,11, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  113756. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  113757. 10,10,10,10,10,10,10,12,11,12,11,11, 9, 9, 9,10,
  113758. 10,10,10,10,10,10,10,10,10,10,10,10,12,11,11,11,
  113759. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113760. 11,11,11,12,11,11,12,11,10,10,10,10,10,10,10,10,
  113761. 10,10,10,10,11,10,11,11,11,11,11,11,11,10,10,10,
  113762. 10,10,10,10,10,10,10,10,10,10,10,11,11,12,11,12,
  113763. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  113764. 11,11,12,11,12,11,11,11,11,10,10,10,10,10,10,10,
  113765. 10,10,10,10,10,11,11,12,11,11,12,11,11,12,10,10,
  113766. 11,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  113767. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,12,
  113768. 12,11,12,11,11,12,12,12,11,11,10,10,10,10,10,10,
  113769. 10,10,10,11,12,12,11,12,12,11,12,11,11,11,11,10,
  113770. 10,10,10,10,10,10,10,10,10,
  113771. };
  113772. static float _vq_quantthresh__8c1_s_p9_2[] = {
  113773. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  113774. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  113775. 6.5, 7.5, 8.5, 9.5,
  113776. };
  113777. static long _vq_quantmap__8c1_s_p9_2[] = {
  113778. 19, 17, 15, 13, 11, 9, 7, 5,
  113779. 3, 1, 0, 2, 4, 6, 8, 10,
  113780. 12, 14, 16, 18, 20,
  113781. };
  113782. static encode_aux_threshmatch _vq_auxt__8c1_s_p9_2 = {
  113783. _vq_quantthresh__8c1_s_p9_2,
  113784. _vq_quantmap__8c1_s_p9_2,
  113785. 21,
  113786. 21
  113787. };
  113788. static static_codebook _8c1_s_p9_2 = {
  113789. 2, 441,
  113790. _vq_lengthlist__8c1_s_p9_2,
  113791. 1, -529268736, 1611661312, 5, 0,
  113792. _vq_quantlist__8c1_s_p9_2,
  113793. NULL,
  113794. &_vq_auxt__8c1_s_p9_2,
  113795. NULL,
  113796. 0
  113797. };
  113798. static long _huff_lengthlist__8c1_s_single[] = {
  113799. 4, 6,18, 8,11, 8, 8, 9, 9,10, 4, 4,18, 5, 9, 5,
  113800. 6, 7, 8,10,18,18,18,18,17,17,17,17,17,17, 7, 5,
  113801. 17, 6,11, 6, 7, 8, 9,12,12, 9,17,12, 8, 8, 9,10,
  113802. 10,13, 7, 5,17, 6, 8, 4, 5, 6, 8,10, 6, 5,17, 6,
  113803. 8, 5, 4, 5, 7, 9, 7, 7,17, 8, 9, 6, 5, 5, 6, 8,
  113804. 8, 8,17, 9,11, 8, 6, 6, 6, 7, 9,10,17,12,12,10,
  113805. 9, 7, 7, 8,
  113806. };
  113807. static static_codebook _huff_book__8c1_s_single = {
  113808. 2, 100,
  113809. _huff_lengthlist__8c1_s_single,
  113810. 0, 0, 0, 0, 0,
  113811. NULL,
  113812. NULL,
  113813. NULL,
  113814. NULL,
  113815. 0
  113816. };
  113817. static long _huff_lengthlist__44c2_s_long[] = {
  113818. 6, 6,12,10,10,10, 9,10,12,12, 6, 1,10, 5, 6, 6,
  113819. 7, 9,11,14,12, 9, 8,11, 7, 8, 9,11,13,15,10, 5,
  113820. 12, 7, 8, 7, 9,12,14,15,10, 6, 7, 8, 5, 6, 7, 9,
  113821. 12,14, 9, 6, 8, 7, 6, 6, 7, 9,12,12, 9, 7, 9, 9,
  113822. 7, 6, 6, 7,10,10,10, 9,10,11, 8, 7, 6, 6, 8,10,
  113823. 12,11,13,13,11,10, 8, 8, 8,10,11,13,15,15,14,13,
  113824. 10, 8, 8, 9,
  113825. };
  113826. static static_codebook _huff_book__44c2_s_long = {
  113827. 2, 100,
  113828. _huff_lengthlist__44c2_s_long,
  113829. 0, 0, 0, 0, 0,
  113830. NULL,
  113831. NULL,
  113832. NULL,
  113833. NULL,
  113834. 0
  113835. };
  113836. static long _vq_quantlist__44c2_s_p1_0[] = {
  113837. 1,
  113838. 0,
  113839. 2,
  113840. };
  113841. static long _vq_lengthlist__44c2_s_p1_0[] = {
  113842. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  113843. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113848. 0, 0, 0, 6, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  113853. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  113888. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  113893. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  113898. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113907. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113915. 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113923. 0, 0, 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  113934. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113938. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  113939. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  113940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113943. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  113944. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  113945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  113972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114252. 0,
  114253. };
  114254. static float _vq_quantthresh__44c2_s_p1_0[] = {
  114255. -0.5, 0.5,
  114256. };
  114257. static long _vq_quantmap__44c2_s_p1_0[] = {
  114258. 1, 0, 2,
  114259. };
  114260. static encode_aux_threshmatch _vq_auxt__44c2_s_p1_0 = {
  114261. _vq_quantthresh__44c2_s_p1_0,
  114262. _vq_quantmap__44c2_s_p1_0,
  114263. 3,
  114264. 3
  114265. };
  114266. static static_codebook _44c2_s_p1_0 = {
  114267. 8, 6561,
  114268. _vq_lengthlist__44c2_s_p1_0,
  114269. 1, -535822336, 1611661312, 2, 0,
  114270. _vq_quantlist__44c2_s_p1_0,
  114271. NULL,
  114272. &_vq_auxt__44c2_s_p1_0,
  114273. NULL,
  114274. 0
  114275. };
  114276. static long _vq_quantlist__44c2_s_p2_0[] = {
  114277. 2,
  114278. 1,
  114279. 3,
  114280. 0,
  114281. 4,
  114282. };
  114283. static long _vq_lengthlist__44c2_s_p2_0[] = {
  114284. 1, 4, 4, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0,
  114285. 8, 8, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  114286. 8, 0, 0, 0, 8, 8, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  114287. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0,
  114288. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114293. 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,11,11, 0, 0,
  114294. 0,11,11, 0, 0, 0,12,11, 0, 0, 0, 0, 0, 0, 0, 7,
  114295. 8, 8, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0, 0,11,
  114296. 12, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114301. 0, 0, 0, 6, 8, 8, 0, 0, 0,11,11, 0, 0, 0,11,11,
  114302. 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0,
  114303. 0, 0,10,11, 0, 0, 0,10,11, 0, 0, 0,11,11, 0, 0,
  114304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114309. 8, 9, 9, 0, 0, 0,11,12, 0, 0, 0,11,12, 0, 0, 0,
  114310. 12,11, 0, 0, 0, 0, 0, 0, 0, 8,10, 9, 0, 0, 0,12,
  114311. 11, 0, 0, 0,12,11, 0, 0, 0,11,12, 0, 0, 0, 0, 0,
  114312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114323. 0,
  114324. };
  114325. static float _vq_quantthresh__44c2_s_p2_0[] = {
  114326. -1.5, -0.5, 0.5, 1.5,
  114327. };
  114328. static long _vq_quantmap__44c2_s_p2_0[] = {
  114329. 3, 1, 0, 2, 4,
  114330. };
  114331. static encode_aux_threshmatch _vq_auxt__44c2_s_p2_0 = {
  114332. _vq_quantthresh__44c2_s_p2_0,
  114333. _vq_quantmap__44c2_s_p2_0,
  114334. 5,
  114335. 5
  114336. };
  114337. static static_codebook _44c2_s_p2_0 = {
  114338. 4, 625,
  114339. _vq_lengthlist__44c2_s_p2_0,
  114340. 1, -533725184, 1611661312, 3, 0,
  114341. _vq_quantlist__44c2_s_p2_0,
  114342. NULL,
  114343. &_vq_auxt__44c2_s_p2_0,
  114344. NULL,
  114345. 0
  114346. };
  114347. static long _vq_quantlist__44c2_s_p3_0[] = {
  114348. 2,
  114349. 1,
  114350. 3,
  114351. 0,
  114352. 4,
  114353. };
  114354. static long _vq_lengthlist__44c2_s_p3_0[] = {
  114355. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  114357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114358. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  114360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114361. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  114362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114394. 0,
  114395. };
  114396. static float _vq_quantthresh__44c2_s_p3_0[] = {
  114397. -1.5, -0.5, 0.5, 1.5,
  114398. };
  114399. static long _vq_quantmap__44c2_s_p3_0[] = {
  114400. 3, 1, 0, 2, 4,
  114401. };
  114402. static encode_aux_threshmatch _vq_auxt__44c2_s_p3_0 = {
  114403. _vq_quantthresh__44c2_s_p3_0,
  114404. _vq_quantmap__44c2_s_p3_0,
  114405. 5,
  114406. 5
  114407. };
  114408. static static_codebook _44c2_s_p3_0 = {
  114409. 4, 625,
  114410. _vq_lengthlist__44c2_s_p3_0,
  114411. 1, -533725184, 1611661312, 3, 0,
  114412. _vq_quantlist__44c2_s_p3_0,
  114413. NULL,
  114414. &_vq_auxt__44c2_s_p3_0,
  114415. NULL,
  114416. 0
  114417. };
  114418. static long _vq_quantlist__44c2_s_p4_0[] = {
  114419. 4,
  114420. 3,
  114421. 5,
  114422. 2,
  114423. 6,
  114424. 1,
  114425. 7,
  114426. 0,
  114427. 8,
  114428. };
  114429. static long _vq_lengthlist__44c2_s_p4_0[] = {
  114430. 1, 3, 3, 6, 6, 0, 0, 0, 0, 0, 6, 6, 6, 6, 0, 0,
  114431. 0, 0, 0, 6, 6, 6, 6, 0, 0, 0, 0, 0, 7, 7, 6, 6,
  114432. 0, 0, 0, 0, 0, 0, 0, 6, 7, 0, 0, 0, 0, 0, 0, 0,
  114433. 7, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  114434. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114435. 0,
  114436. };
  114437. static float _vq_quantthresh__44c2_s_p4_0[] = {
  114438. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114439. };
  114440. static long _vq_quantmap__44c2_s_p4_0[] = {
  114441. 7, 5, 3, 1, 0, 2, 4, 6,
  114442. 8,
  114443. };
  114444. static encode_aux_threshmatch _vq_auxt__44c2_s_p4_0 = {
  114445. _vq_quantthresh__44c2_s_p4_0,
  114446. _vq_quantmap__44c2_s_p4_0,
  114447. 9,
  114448. 9
  114449. };
  114450. static static_codebook _44c2_s_p4_0 = {
  114451. 2, 81,
  114452. _vq_lengthlist__44c2_s_p4_0,
  114453. 1, -531628032, 1611661312, 4, 0,
  114454. _vq_quantlist__44c2_s_p4_0,
  114455. NULL,
  114456. &_vq_auxt__44c2_s_p4_0,
  114457. NULL,
  114458. 0
  114459. };
  114460. static long _vq_quantlist__44c2_s_p5_0[] = {
  114461. 4,
  114462. 3,
  114463. 5,
  114464. 2,
  114465. 6,
  114466. 1,
  114467. 7,
  114468. 0,
  114469. 8,
  114470. };
  114471. static long _vq_lengthlist__44c2_s_p5_0[] = {
  114472. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 7, 7, 7, 7, 7, 7,
  114473. 9, 9, 0, 7, 7, 7, 7, 7, 7, 9, 9, 0, 8, 8, 7, 7,
  114474. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  114475. 9, 9, 8, 8,10,10, 0, 0, 0, 9, 9, 8, 8,10,10, 0,
  114476. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  114477. 11,
  114478. };
  114479. static float _vq_quantthresh__44c2_s_p5_0[] = {
  114480. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  114481. };
  114482. static long _vq_quantmap__44c2_s_p5_0[] = {
  114483. 7, 5, 3, 1, 0, 2, 4, 6,
  114484. 8,
  114485. };
  114486. static encode_aux_threshmatch _vq_auxt__44c2_s_p5_0 = {
  114487. _vq_quantthresh__44c2_s_p5_0,
  114488. _vq_quantmap__44c2_s_p5_0,
  114489. 9,
  114490. 9
  114491. };
  114492. static static_codebook _44c2_s_p5_0 = {
  114493. 2, 81,
  114494. _vq_lengthlist__44c2_s_p5_0,
  114495. 1, -531628032, 1611661312, 4, 0,
  114496. _vq_quantlist__44c2_s_p5_0,
  114497. NULL,
  114498. &_vq_auxt__44c2_s_p5_0,
  114499. NULL,
  114500. 0
  114501. };
  114502. static long _vq_quantlist__44c2_s_p6_0[] = {
  114503. 8,
  114504. 7,
  114505. 9,
  114506. 6,
  114507. 10,
  114508. 5,
  114509. 11,
  114510. 4,
  114511. 12,
  114512. 3,
  114513. 13,
  114514. 2,
  114515. 14,
  114516. 1,
  114517. 15,
  114518. 0,
  114519. 16,
  114520. };
  114521. static long _vq_lengthlist__44c2_s_p6_0[] = {
  114522. 1, 4, 3, 6, 6, 8, 8, 9, 9, 9, 9, 9, 9,10,10,11,
  114523. 11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  114524. 12,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  114525. 11,11,12, 0, 8, 8, 7, 7, 9, 9,10,10, 9, 9,10,10,
  114526. 11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10, 9,10,
  114527. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  114528. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  114529. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  114530. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  114531. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  114532. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  114533. 9,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  114534. 10,10,10,10,11,11,12,12,13,12,13,13, 0, 0, 0, 0,
  114535. 0, 0, 0,10,10,11,11,12,12,13,13,13,13, 0, 0, 0,
  114536. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  114537. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  114538. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  114539. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,13,13,14,
  114540. 14,
  114541. };
  114542. static float _vq_quantthresh__44c2_s_p6_0[] = {
  114543. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114544. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114545. };
  114546. static long _vq_quantmap__44c2_s_p6_0[] = {
  114547. 15, 13, 11, 9, 7, 5, 3, 1,
  114548. 0, 2, 4, 6, 8, 10, 12, 14,
  114549. 16,
  114550. };
  114551. static encode_aux_threshmatch _vq_auxt__44c2_s_p6_0 = {
  114552. _vq_quantthresh__44c2_s_p6_0,
  114553. _vq_quantmap__44c2_s_p6_0,
  114554. 17,
  114555. 17
  114556. };
  114557. static static_codebook _44c2_s_p6_0 = {
  114558. 2, 289,
  114559. _vq_lengthlist__44c2_s_p6_0,
  114560. 1, -529530880, 1611661312, 5, 0,
  114561. _vq_quantlist__44c2_s_p6_0,
  114562. NULL,
  114563. &_vq_auxt__44c2_s_p6_0,
  114564. NULL,
  114565. 0
  114566. };
  114567. static long _vq_quantlist__44c2_s_p7_0[] = {
  114568. 1,
  114569. 0,
  114570. 2,
  114571. };
  114572. static long _vq_lengthlist__44c2_s_p7_0[] = {
  114573. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  114574. 9, 9, 4, 7, 7,10, 9, 9,10, 9, 9, 7,10,10,11,10,
  114575. 11,11,10,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  114576. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 6,
  114577. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,12,10,
  114578. 11,
  114579. };
  114580. static float _vq_quantthresh__44c2_s_p7_0[] = {
  114581. -5.5, 5.5,
  114582. };
  114583. static long _vq_quantmap__44c2_s_p7_0[] = {
  114584. 1, 0, 2,
  114585. };
  114586. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_0 = {
  114587. _vq_quantthresh__44c2_s_p7_0,
  114588. _vq_quantmap__44c2_s_p7_0,
  114589. 3,
  114590. 3
  114591. };
  114592. static static_codebook _44c2_s_p7_0 = {
  114593. 4, 81,
  114594. _vq_lengthlist__44c2_s_p7_0,
  114595. 1, -529137664, 1618345984, 2, 0,
  114596. _vq_quantlist__44c2_s_p7_0,
  114597. NULL,
  114598. &_vq_auxt__44c2_s_p7_0,
  114599. NULL,
  114600. 0
  114601. };
  114602. static long _vq_quantlist__44c2_s_p7_1[] = {
  114603. 5,
  114604. 4,
  114605. 6,
  114606. 3,
  114607. 7,
  114608. 2,
  114609. 8,
  114610. 1,
  114611. 9,
  114612. 0,
  114613. 10,
  114614. };
  114615. static long _vq_lengthlist__44c2_s_p7_1[] = {
  114616. 2, 3, 4, 6, 6, 7, 7, 7, 7, 7, 7, 9, 7, 7, 6, 6,
  114617. 7, 7, 8, 8, 8, 8, 9, 6, 6, 6, 6, 7, 7, 8, 8, 8,
  114618. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  114619. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  114620. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  114621. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  114622. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  114623. 10,10,10, 8, 8, 8, 8, 8, 8,
  114624. };
  114625. static float _vq_quantthresh__44c2_s_p7_1[] = {
  114626. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  114627. 3.5, 4.5,
  114628. };
  114629. static long _vq_quantmap__44c2_s_p7_1[] = {
  114630. 9, 7, 5, 3, 1, 0, 2, 4,
  114631. 6, 8, 10,
  114632. };
  114633. static encode_aux_threshmatch _vq_auxt__44c2_s_p7_1 = {
  114634. _vq_quantthresh__44c2_s_p7_1,
  114635. _vq_quantmap__44c2_s_p7_1,
  114636. 11,
  114637. 11
  114638. };
  114639. static static_codebook _44c2_s_p7_1 = {
  114640. 2, 121,
  114641. _vq_lengthlist__44c2_s_p7_1,
  114642. 1, -531365888, 1611661312, 4, 0,
  114643. _vq_quantlist__44c2_s_p7_1,
  114644. NULL,
  114645. &_vq_auxt__44c2_s_p7_1,
  114646. NULL,
  114647. 0
  114648. };
  114649. static long _vq_quantlist__44c2_s_p8_0[] = {
  114650. 6,
  114651. 5,
  114652. 7,
  114653. 4,
  114654. 8,
  114655. 3,
  114656. 9,
  114657. 2,
  114658. 10,
  114659. 1,
  114660. 11,
  114661. 0,
  114662. 12,
  114663. };
  114664. static long _vq_lengthlist__44c2_s_p8_0[] = {
  114665. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 6, 5, 5,
  114666. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  114667. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  114668. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  114669. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  114670. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  114671. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  114672. 11,12,12,12,12, 0, 0, 0,14,14,10,11,11,11,12,12,
  114673. 13,13, 0, 0, 0,14,14,11,10,11,11,13,12,13,13, 0,
  114674. 0, 0, 0, 0,12,12,11,12,13,12,14,14, 0, 0, 0, 0,
  114675. 0,12,12,12,12,13,12,14,14,
  114676. };
  114677. static float _vq_quantthresh__44c2_s_p8_0[] = {
  114678. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  114679. 12.5, 17.5, 22.5, 27.5,
  114680. };
  114681. static long _vq_quantmap__44c2_s_p8_0[] = {
  114682. 11, 9, 7, 5, 3, 1, 0, 2,
  114683. 4, 6, 8, 10, 12,
  114684. };
  114685. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_0 = {
  114686. _vq_quantthresh__44c2_s_p8_0,
  114687. _vq_quantmap__44c2_s_p8_0,
  114688. 13,
  114689. 13
  114690. };
  114691. static static_codebook _44c2_s_p8_0 = {
  114692. 2, 169,
  114693. _vq_lengthlist__44c2_s_p8_0,
  114694. 1, -526516224, 1616117760, 4, 0,
  114695. _vq_quantlist__44c2_s_p8_0,
  114696. NULL,
  114697. &_vq_auxt__44c2_s_p8_0,
  114698. NULL,
  114699. 0
  114700. };
  114701. static long _vq_quantlist__44c2_s_p8_1[] = {
  114702. 2,
  114703. 1,
  114704. 3,
  114705. 0,
  114706. 4,
  114707. };
  114708. static long _vq_lengthlist__44c2_s_p8_1[] = {
  114709. 2, 4, 4, 5, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  114710. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  114711. };
  114712. static float _vq_quantthresh__44c2_s_p8_1[] = {
  114713. -1.5, -0.5, 0.5, 1.5,
  114714. };
  114715. static long _vq_quantmap__44c2_s_p8_1[] = {
  114716. 3, 1, 0, 2, 4,
  114717. };
  114718. static encode_aux_threshmatch _vq_auxt__44c2_s_p8_1 = {
  114719. _vq_quantthresh__44c2_s_p8_1,
  114720. _vq_quantmap__44c2_s_p8_1,
  114721. 5,
  114722. 5
  114723. };
  114724. static static_codebook _44c2_s_p8_1 = {
  114725. 2, 25,
  114726. _vq_lengthlist__44c2_s_p8_1,
  114727. 1, -533725184, 1611661312, 3, 0,
  114728. _vq_quantlist__44c2_s_p8_1,
  114729. NULL,
  114730. &_vq_auxt__44c2_s_p8_1,
  114731. NULL,
  114732. 0
  114733. };
  114734. static long _vq_quantlist__44c2_s_p9_0[] = {
  114735. 6,
  114736. 5,
  114737. 7,
  114738. 4,
  114739. 8,
  114740. 3,
  114741. 9,
  114742. 2,
  114743. 10,
  114744. 1,
  114745. 11,
  114746. 0,
  114747. 12,
  114748. };
  114749. static long _vq_lengthlist__44c2_s_p9_0[] = {
  114750. 1, 5, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  114751. 11,11,11,11,11,11,11,11,11,11, 2, 8, 7,11,11,11,
  114752. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114753. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  114754. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114755. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114756. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114757. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114758. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114759. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  114760. 11,11,11,11,11,11,11,11,11,
  114761. };
  114762. static float _vq_quantthresh__44c2_s_p9_0[] = {
  114763. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  114764. 552.5, 773.5, 994.5, 1215.5,
  114765. };
  114766. static long _vq_quantmap__44c2_s_p9_0[] = {
  114767. 11, 9, 7, 5, 3, 1, 0, 2,
  114768. 4, 6, 8, 10, 12,
  114769. };
  114770. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_0 = {
  114771. _vq_quantthresh__44c2_s_p9_0,
  114772. _vq_quantmap__44c2_s_p9_0,
  114773. 13,
  114774. 13
  114775. };
  114776. static static_codebook _44c2_s_p9_0 = {
  114777. 2, 169,
  114778. _vq_lengthlist__44c2_s_p9_0,
  114779. 1, -514541568, 1627103232, 4, 0,
  114780. _vq_quantlist__44c2_s_p9_0,
  114781. NULL,
  114782. &_vq_auxt__44c2_s_p9_0,
  114783. NULL,
  114784. 0
  114785. };
  114786. static long _vq_quantlist__44c2_s_p9_1[] = {
  114787. 6,
  114788. 5,
  114789. 7,
  114790. 4,
  114791. 8,
  114792. 3,
  114793. 9,
  114794. 2,
  114795. 10,
  114796. 1,
  114797. 11,
  114798. 0,
  114799. 12,
  114800. };
  114801. static long _vq_lengthlist__44c2_s_p9_1[] = {
  114802. 1, 4, 4, 6, 6, 7, 6, 8, 8,10, 9,10,10, 6, 5, 5,
  114803. 7, 7, 8, 7,10, 9,11,11,12,13, 6, 5, 5, 7, 7, 8,
  114804. 8,10,10,11,11,13,13,18, 8, 8, 8, 8, 9, 9,10,10,
  114805. 12,12,12,13,18, 8, 8, 8, 8, 9, 9,10,10,12,12,13,
  114806. 13,18,11,11, 8, 8,10,10,11,11,12,11,13,12,18,11,
  114807. 11, 9, 7,10,10,11,11,11,12,12,13,17,17,17,10,10,
  114808. 11,11,12,12,12,10,12,12,17,17,17,11,10,11,10,13,
  114809. 12,11,12,12,12,17,17,17,15,14,11,11,12,11,13,10,
  114810. 13,12,17,17,17,14,14,12,10,11,11,13,13,13,13,17,
  114811. 17,16,17,16,13,13,12,10,13,10,14,13,17,16,17,16,
  114812. 17,13,12,12,10,13,11,14,14,
  114813. };
  114814. static float _vq_quantthresh__44c2_s_p9_1[] = {
  114815. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  114816. 42.5, 59.5, 76.5, 93.5,
  114817. };
  114818. static long _vq_quantmap__44c2_s_p9_1[] = {
  114819. 11, 9, 7, 5, 3, 1, 0, 2,
  114820. 4, 6, 8, 10, 12,
  114821. };
  114822. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_1 = {
  114823. _vq_quantthresh__44c2_s_p9_1,
  114824. _vq_quantmap__44c2_s_p9_1,
  114825. 13,
  114826. 13
  114827. };
  114828. static static_codebook _44c2_s_p9_1 = {
  114829. 2, 169,
  114830. _vq_lengthlist__44c2_s_p9_1,
  114831. 1, -522616832, 1620115456, 4, 0,
  114832. _vq_quantlist__44c2_s_p9_1,
  114833. NULL,
  114834. &_vq_auxt__44c2_s_p9_1,
  114835. NULL,
  114836. 0
  114837. };
  114838. static long _vq_quantlist__44c2_s_p9_2[] = {
  114839. 8,
  114840. 7,
  114841. 9,
  114842. 6,
  114843. 10,
  114844. 5,
  114845. 11,
  114846. 4,
  114847. 12,
  114848. 3,
  114849. 13,
  114850. 2,
  114851. 14,
  114852. 1,
  114853. 15,
  114854. 0,
  114855. 16,
  114856. };
  114857. static long _vq_lengthlist__44c2_s_p9_2[] = {
  114858. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  114859. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  114860. 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  114861. 9, 9, 9,10, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  114862. 9, 9, 9, 9,10,10,10, 8, 7, 8, 8, 8, 8, 9, 9, 9,
  114863. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  114864. 9, 9,10, 9, 9, 9,10,11,10, 8, 8, 8, 8, 9, 9, 9,
  114865. 9, 9, 9, 9,10,10,10,10,11,10, 8, 8, 9, 9, 9, 9,
  114866. 9, 9,10, 9, 9,10, 9,10,11,10,11,11,11, 8, 8, 9,
  114867. 9, 9, 9, 9, 9, 9, 9,10,10,11,11,11,11,11, 9, 9,
  114868. 9, 9, 9, 9,10, 9, 9, 9,10,10,11,11,11,11,11, 9,
  114869. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,11,11,11,11,11,
  114870. 9, 9, 9, 9,10,10, 9, 9, 9,10,10,10,11,11,11,11,
  114871. 11,11,11, 9, 9, 9,10, 9, 9,10,10,10,10,11,11,10,
  114872. 11,11,11,11,10, 9,10,10, 9, 9, 9, 9,10,10,11,10,
  114873. 11,11,11,11,11, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  114874. 10,11,11,11,11,11,10,10, 9, 9,10, 9,10,10,10,10,
  114875. 10,10,10,11,11,11,11,11,11, 9, 9,10, 9,10, 9,10,
  114876. 10,
  114877. };
  114878. static float _vq_quantthresh__44c2_s_p9_2[] = {
  114879. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  114880. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  114881. };
  114882. static long _vq_quantmap__44c2_s_p9_2[] = {
  114883. 15, 13, 11, 9, 7, 5, 3, 1,
  114884. 0, 2, 4, 6, 8, 10, 12, 14,
  114885. 16,
  114886. };
  114887. static encode_aux_threshmatch _vq_auxt__44c2_s_p9_2 = {
  114888. _vq_quantthresh__44c2_s_p9_2,
  114889. _vq_quantmap__44c2_s_p9_2,
  114890. 17,
  114891. 17
  114892. };
  114893. static static_codebook _44c2_s_p9_2 = {
  114894. 2, 289,
  114895. _vq_lengthlist__44c2_s_p9_2,
  114896. 1, -529530880, 1611661312, 5, 0,
  114897. _vq_quantlist__44c2_s_p9_2,
  114898. NULL,
  114899. &_vq_auxt__44c2_s_p9_2,
  114900. NULL,
  114901. 0
  114902. };
  114903. static long _huff_lengthlist__44c2_s_short[] = {
  114904. 11, 9,13,12,12,11,12,12,13,15, 8, 2,11, 4, 8, 5,
  114905. 7,10,12,15,13, 7,10, 9, 8, 8,10,13,17,17,11, 4,
  114906. 12, 5, 9, 5, 8,11,14,16,12, 6, 8, 7, 6, 6, 8,11,
  114907. 13,16,11, 4, 9, 5, 6, 4, 6,10,13,16,11, 6,11, 7,
  114908. 7, 6, 7,10,13,15,13, 9,12, 9, 8, 6, 8,10,12,14,
  114909. 14,10,10, 8, 6, 5, 6, 9,11,13,15,11,11, 9, 6, 5,
  114910. 6, 8, 9,12,
  114911. };
  114912. static static_codebook _huff_book__44c2_s_short = {
  114913. 2, 100,
  114914. _huff_lengthlist__44c2_s_short,
  114915. 0, 0, 0, 0, 0,
  114916. NULL,
  114917. NULL,
  114918. NULL,
  114919. NULL,
  114920. 0
  114921. };
  114922. static long _huff_lengthlist__44c3_s_long[] = {
  114923. 5, 6,11,11,11,11,10,10,12,11, 5, 2,11, 5, 6, 6,
  114924. 7, 9,11,13,13,10, 7,11, 6, 7, 8, 9,10,12,11, 5,
  114925. 11, 6, 8, 7, 9,11,14,15,11, 6, 6, 8, 4, 5, 7, 8,
  114926. 10,13,10, 5, 7, 7, 5, 5, 6, 8,10,11,10, 7, 7, 8,
  114927. 6, 5, 5, 7, 9, 9,11, 8, 8,11, 8, 7, 6, 6, 7, 9,
  114928. 12,11,10,13, 9, 9, 7, 7, 7, 9,11,13,12,15,12,11,
  114929. 9, 8, 8, 8,
  114930. };
  114931. static static_codebook _huff_book__44c3_s_long = {
  114932. 2, 100,
  114933. _huff_lengthlist__44c3_s_long,
  114934. 0, 0, 0, 0, 0,
  114935. NULL,
  114936. NULL,
  114937. NULL,
  114938. NULL,
  114939. 0
  114940. };
  114941. static long _vq_quantlist__44c3_s_p1_0[] = {
  114942. 1,
  114943. 0,
  114944. 2,
  114945. };
  114946. static long _vq_lengthlist__44c3_s_p1_0[] = {
  114947. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  114948. 0, 0, 5, 6, 6, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114953. 0, 0, 0, 6, 7, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  114958. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  114993. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  114994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  114997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  114998. 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  114999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  115003. 0, 0, 0, 0, 7, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115012. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115020. 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115028. 0, 0, 0, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  115039. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115043. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  115044. 0, 0, 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  115045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115048. 0, 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  115049. 0, 0, 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 0,
  115050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115357. 0,
  115358. };
  115359. static float _vq_quantthresh__44c3_s_p1_0[] = {
  115360. -0.5, 0.5,
  115361. };
  115362. static long _vq_quantmap__44c3_s_p1_0[] = {
  115363. 1, 0, 2,
  115364. };
  115365. static encode_aux_threshmatch _vq_auxt__44c3_s_p1_0 = {
  115366. _vq_quantthresh__44c3_s_p1_0,
  115367. _vq_quantmap__44c3_s_p1_0,
  115368. 3,
  115369. 3
  115370. };
  115371. static static_codebook _44c3_s_p1_0 = {
  115372. 8, 6561,
  115373. _vq_lengthlist__44c3_s_p1_0,
  115374. 1, -535822336, 1611661312, 2, 0,
  115375. _vq_quantlist__44c3_s_p1_0,
  115376. NULL,
  115377. &_vq_auxt__44c3_s_p1_0,
  115378. NULL,
  115379. 0
  115380. };
  115381. static long _vq_quantlist__44c3_s_p2_0[] = {
  115382. 2,
  115383. 1,
  115384. 3,
  115385. 0,
  115386. 4,
  115387. };
  115388. static long _vq_lengthlist__44c3_s_p2_0[] = {
  115389. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  115390. 7, 8, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  115391. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115392. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  115393. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115398. 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0,
  115399. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  115400. 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  115401. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115406. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  115407. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  115408. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  115409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115414. 8,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  115415. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  115416. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  115417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115428. 0,
  115429. };
  115430. static float _vq_quantthresh__44c3_s_p2_0[] = {
  115431. -1.5, -0.5, 0.5, 1.5,
  115432. };
  115433. static long _vq_quantmap__44c3_s_p2_0[] = {
  115434. 3, 1, 0, 2, 4,
  115435. };
  115436. static encode_aux_threshmatch _vq_auxt__44c3_s_p2_0 = {
  115437. _vq_quantthresh__44c3_s_p2_0,
  115438. _vq_quantmap__44c3_s_p2_0,
  115439. 5,
  115440. 5
  115441. };
  115442. static static_codebook _44c3_s_p2_0 = {
  115443. 4, 625,
  115444. _vq_lengthlist__44c3_s_p2_0,
  115445. 1, -533725184, 1611661312, 3, 0,
  115446. _vq_quantlist__44c3_s_p2_0,
  115447. NULL,
  115448. &_vq_auxt__44c3_s_p2_0,
  115449. NULL,
  115450. 0
  115451. };
  115452. static long _vq_quantlist__44c3_s_p3_0[] = {
  115453. 2,
  115454. 1,
  115455. 3,
  115456. 0,
  115457. 4,
  115458. };
  115459. static long _vq_lengthlist__44c3_s_p3_0[] = {
  115460. 2, 4, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  115462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115463. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  115465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115466. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  115467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115499. 0,
  115500. };
  115501. static float _vq_quantthresh__44c3_s_p3_0[] = {
  115502. -1.5, -0.5, 0.5, 1.5,
  115503. };
  115504. static long _vq_quantmap__44c3_s_p3_0[] = {
  115505. 3, 1, 0, 2, 4,
  115506. };
  115507. static encode_aux_threshmatch _vq_auxt__44c3_s_p3_0 = {
  115508. _vq_quantthresh__44c3_s_p3_0,
  115509. _vq_quantmap__44c3_s_p3_0,
  115510. 5,
  115511. 5
  115512. };
  115513. static static_codebook _44c3_s_p3_0 = {
  115514. 4, 625,
  115515. _vq_lengthlist__44c3_s_p3_0,
  115516. 1, -533725184, 1611661312, 3, 0,
  115517. _vq_quantlist__44c3_s_p3_0,
  115518. NULL,
  115519. &_vq_auxt__44c3_s_p3_0,
  115520. NULL,
  115521. 0
  115522. };
  115523. static long _vq_quantlist__44c3_s_p4_0[] = {
  115524. 4,
  115525. 3,
  115526. 5,
  115527. 2,
  115528. 6,
  115529. 1,
  115530. 7,
  115531. 0,
  115532. 8,
  115533. };
  115534. static long _vq_lengthlist__44c3_s_p4_0[] = {
  115535. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  115536. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  115537. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  115538. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  115539. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  115540. 0,
  115541. };
  115542. static float _vq_quantthresh__44c3_s_p4_0[] = {
  115543. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115544. };
  115545. static long _vq_quantmap__44c3_s_p4_0[] = {
  115546. 7, 5, 3, 1, 0, 2, 4, 6,
  115547. 8,
  115548. };
  115549. static encode_aux_threshmatch _vq_auxt__44c3_s_p4_0 = {
  115550. _vq_quantthresh__44c3_s_p4_0,
  115551. _vq_quantmap__44c3_s_p4_0,
  115552. 9,
  115553. 9
  115554. };
  115555. static static_codebook _44c3_s_p4_0 = {
  115556. 2, 81,
  115557. _vq_lengthlist__44c3_s_p4_0,
  115558. 1, -531628032, 1611661312, 4, 0,
  115559. _vq_quantlist__44c3_s_p4_0,
  115560. NULL,
  115561. &_vq_auxt__44c3_s_p4_0,
  115562. NULL,
  115563. 0
  115564. };
  115565. static long _vq_quantlist__44c3_s_p5_0[] = {
  115566. 4,
  115567. 3,
  115568. 5,
  115569. 2,
  115570. 6,
  115571. 1,
  115572. 7,
  115573. 0,
  115574. 8,
  115575. };
  115576. static long _vq_lengthlist__44c3_s_p5_0[] = {
  115577. 1, 3, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 7, 8,
  115578. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  115579. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  115580. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  115581. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  115582. 11,
  115583. };
  115584. static float _vq_quantthresh__44c3_s_p5_0[] = {
  115585. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  115586. };
  115587. static long _vq_quantmap__44c3_s_p5_0[] = {
  115588. 7, 5, 3, 1, 0, 2, 4, 6,
  115589. 8,
  115590. };
  115591. static encode_aux_threshmatch _vq_auxt__44c3_s_p5_0 = {
  115592. _vq_quantthresh__44c3_s_p5_0,
  115593. _vq_quantmap__44c3_s_p5_0,
  115594. 9,
  115595. 9
  115596. };
  115597. static static_codebook _44c3_s_p5_0 = {
  115598. 2, 81,
  115599. _vq_lengthlist__44c3_s_p5_0,
  115600. 1, -531628032, 1611661312, 4, 0,
  115601. _vq_quantlist__44c3_s_p5_0,
  115602. NULL,
  115603. &_vq_auxt__44c3_s_p5_0,
  115604. NULL,
  115605. 0
  115606. };
  115607. static long _vq_quantlist__44c3_s_p6_0[] = {
  115608. 8,
  115609. 7,
  115610. 9,
  115611. 6,
  115612. 10,
  115613. 5,
  115614. 11,
  115615. 4,
  115616. 12,
  115617. 3,
  115618. 13,
  115619. 2,
  115620. 14,
  115621. 1,
  115622. 15,
  115623. 0,
  115624. 16,
  115625. };
  115626. static long _vq_lengthlist__44c3_s_p6_0[] = {
  115627. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  115628. 10, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  115629. 11,11, 0, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  115630. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  115631. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  115632. 10,11,11,11,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115633. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  115634. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  115635. 10,10,11,10,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  115636. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 8,
  115637. 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8,
  115638. 8, 9, 9,10,10,11,11,12,11,12,12, 0, 0, 0, 0, 0,
  115639. 9,10,10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0,
  115640. 0, 0, 0,10,10,10,10,11,11,12,12,13,13, 0, 0, 0,
  115641. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  115642. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  115643. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13,
  115644. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  115645. 13,
  115646. };
  115647. static float _vq_quantthresh__44c3_s_p6_0[] = {
  115648. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115649. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115650. };
  115651. static long _vq_quantmap__44c3_s_p6_0[] = {
  115652. 15, 13, 11, 9, 7, 5, 3, 1,
  115653. 0, 2, 4, 6, 8, 10, 12, 14,
  115654. 16,
  115655. };
  115656. static encode_aux_threshmatch _vq_auxt__44c3_s_p6_0 = {
  115657. _vq_quantthresh__44c3_s_p6_0,
  115658. _vq_quantmap__44c3_s_p6_0,
  115659. 17,
  115660. 17
  115661. };
  115662. static static_codebook _44c3_s_p6_0 = {
  115663. 2, 289,
  115664. _vq_lengthlist__44c3_s_p6_0,
  115665. 1, -529530880, 1611661312, 5, 0,
  115666. _vq_quantlist__44c3_s_p6_0,
  115667. NULL,
  115668. &_vq_auxt__44c3_s_p6_0,
  115669. NULL,
  115670. 0
  115671. };
  115672. static long _vq_quantlist__44c3_s_p7_0[] = {
  115673. 1,
  115674. 0,
  115675. 2,
  115676. };
  115677. static long _vq_lengthlist__44c3_s_p7_0[] = {
  115678. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  115679. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  115680. 10,12,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  115681. 11,10,10,11,10,10, 7,11,11,11,11,11,12,11,11, 6,
  115682. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  115683. 10,
  115684. };
  115685. static float _vq_quantthresh__44c3_s_p7_0[] = {
  115686. -5.5, 5.5,
  115687. };
  115688. static long _vq_quantmap__44c3_s_p7_0[] = {
  115689. 1, 0, 2,
  115690. };
  115691. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_0 = {
  115692. _vq_quantthresh__44c3_s_p7_0,
  115693. _vq_quantmap__44c3_s_p7_0,
  115694. 3,
  115695. 3
  115696. };
  115697. static static_codebook _44c3_s_p7_0 = {
  115698. 4, 81,
  115699. _vq_lengthlist__44c3_s_p7_0,
  115700. 1, -529137664, 1618345984, 2, 0,
  115701. _vq_quantlist__44c3_s_p7_0,
  115702. NULL,
  115703. &_vq_auxt__44c3_s_p7_0,
  115704. NULL,
  115705. 0
  115706. };
  115707. static long _vq_quantlist__44c3_s_p7_1[] = {
  115708. 5,
  115709. 4,
  115710. 6,
  115711. 3,
  115712. 7,
  115713. 2,
  115714. 8,
  115715. 1,
  115716. 9,
  115717. 0,
  115718. 10,
  115719. };
  115720. static long _vq_lengthlist__44c3_s_p7_1[] = {
  115721. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  115722. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  115723. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  115724. 7, 8, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  115725. 8, 8,10,10,10, 7, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  115726. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  115727. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  115728. 10,10,10, 8, 8, 8, 8, 8, 8,
  115729. };
  115730. static float _vq_quantthresh__44c3_s_p7_1[] = {
  115731. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  115732. 3.5, 4.5,
  115733. };
  115734. static long _vq_quantmap__44c3_s_p7_1[] = {
  115735. 9, 7, 5, 3, 1, 0, 2, 4,
  115736. 6, 8, 10,
  115737. };
  115738. static encode_aux_threshmatch _vq_auxt__44c3_s_p7_1 = {
  115739. _vq_quantthresh__44c3_s_p7_1,
  115740. _vq_quantmap__44c3_s_p7_1,
  115741. 11,
  115742. 11
  115743. };
  115744. static static_codebook _44c3_s_p7_1 = {
  115745. 2, 121,
  115746. _vq_lengthlist__44c3_s_p7_1,
  115747. 1, -531365888, 1611661312, 4, 0,
  115748. _vq_quantlist__44c3_s_p7_1,
  115749. NULL,
  115750. &_vq_auxt__44c3_s_p7_1,
  115751. NULL,
  115752. 0
  115753. };
  115754. static long _vq_quantlist__44c3_s_p8_0[] = {
  115755. 6,
  115756. 5,
  115757. 7,
  115758. 4,
  115759. 8,
  115760. 3,
  115761. 9,
  115762. 2,
  115763. 10,
  115764. 1,
  115765. 11,
  115766. 0,
  115767. 12,
  115768. };
  115769. static long _vq_lengthlist__44c3_s_p8_0[] = {
  115770. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  115771. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  115772. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  115773. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  115774. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,12, 0,13,
  115775. 13, 9, 9,10,10,10,10,11,11,12,12, 0, 0, 0,10,10,
  115776. 10,10,11,11,12,12,12,12, 0, 0, 0,10,10,10,10,11,
  115777. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  115778. 13,13, 0, 0, 0,14,14,11,11,11,11,12,12,13,13, 0,
  115779. 0, 0, 0, 0,12,12,12,12,13,13,14,13, 0, 0, 0, 0,
  115780. 0,13,13,12,12,13,12,14,13,
  115781. };
  115782. static float _vq_quantthresh__44c3_s_p8_0[] = {
  115783. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  115784. 12.5, 17.5, 22.5, 27.5,
  115785. };
  115786. static long _vq_quantmap__44c3_s_p8_0[] = {
  115787. 11, 9, 7, 5, 3, 1, 0, 2,
  115788. 4, 6, 8, 10, 12,
  115789. };
  115790. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_0 = {
  115791. _vq_quantthresh__44c3_s_p8_0,
  115792. _vq_quantmap__44c3_s_p8_0,
  115793. 13,
  115794. 13
  115795. };
  115796. static static_codebook _44c3_s_p8_0 = {
  115797. 2, 169,
  115798. _vq_lengthlist__44c3_s_p8_0,
  115799. 1, -526516224, 1616117760, 4, 0,
  115800. _vq_quantlist__44c3_s_p8_0,
  115801. NULL,
  115802. &_vq_auxt__44c3_s_p8_0,
  115803. NULL,
  115804. 0
  115805. };
  115806. static long _vq_quantlist__44c3_s_p8_1[] = {
  115807. 2,
  115808. 1,
  115809. 3,
  115810. 0,
  115811. 4,
  115812. };
  115813. static long _vq_lengthlist__44c3_s_p8_1[] = {
  115814. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  115815. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  115816. };
  115817. static float _vq_quantthresh__44c3_s_p8_1[] = {
  115818. -1.5, -0.5, 0.5, 1.5,
  115819. };
  115820. static long _vq_quantmap__44c3_s_p8_1[] = {
  115821. 3, 1, 0, 2, 4,
  115822. };
  115823. static encode_aux_threshmatch _vq_auxt__44c3_s_p8_1 = {
  115824. _vq_quantthresh__44c3_s_p8_1,
  115825. _vq_quantmap__44c3_s_p8_1,
  115826. 5,
  115827. 5
  115828. };
  115829. static static_codebook _44c3_s_p8_1 = {
  115830. 2, 25,
  115831. _vq_lengthlist__44c3_s_p8_1,
  115832. 1, -533725184, 1611661312, 3, 0,
  115833. _vq_quantlist__44c3_s_p8_1,
  115834. NULL,
  115835. &_vq_auxt__44c3_s_p8_1,
  115836. NULL,
  115837. 0
  115838. };
  115839. static long _vq_quantlist__44c3_s_p9_0[] = {
  115840. 6,
  115841. 5,
  115842. 7,
  115843. 4,
  115844. 8,
  115845. 3,
  115846. 9,
  115847. 2,
  115848. 10,
  115849. 1,
  115850. 11,
  115851. 0,
  115852. 12,
  115853. };
  115854. static long _vq_lengthlist__44c3_s_p9_0[] = {
  115855. 1, 4, 4,12,12,12,12,12,12,12,12,12,12, 4, 9, 8,
  115856. 12,12,12,12,12,12,12,12,12,12, 2, 9, 7,12,12,12,
  115857. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115858. 12,12,12,12,12,12,11,12,12,12,12,12,12,12,12,12,
  115859. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115860. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115861. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115862. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  115863. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  115864. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  115865. 11,11,11,11,11,11,11,11,11,
  115866. };
  115867. static float _vq_quantthresh__44c3_s_p9_0[] = {
  115868. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  115869. 637.5, 892.5, 1147.5, 1402.5,
  115870. };
  115871. static long _vq_quantmap__44c3_s_p9_0[] = {
  115872. 11, 9, 7, 5, 3, 1, 0, 2,
  115873. 4, 6, 8, 10, 12,
  115874. };
  115875. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_0 = {
  115876. _vq_quantthresh__44c3_s_p9_0,
  115877. _vq_quantmap__44c3_s_p9_0,
  115878. 13,
  115879. 13
  115880. };
  115881. static static_codebook _44c3_s_p9_0 = {
  115882. 2, 169,
  115883. _vq_lengthlist__44c3_s_p9_0,
  115884. 1, -514332672, 1627381760, 4, 0,
  115885. _vq_quantlist__44c3_s_p9_0,
  115886. NULL,
  115887. &_vq_auxt__44c3_s_p9_0,
  115888. NULL,
  115889. 0
  115890. };
  115891. static long _vq_quantlist__44c3_s_p9_1[] = {
  115892. 7,
  115893. 6,
  115894. 8,
  115895. 5,
  115896. 9,
  115897. 4,
  115898. 10,
  115899. 3,
  115900. 11,
  115901. 2,
  115902. 12,
  115903. 1,
  115904. 13,
  115905. 0,
  115906. 14,
  115907. };
  115908. static long _vq_lengthlist__44c3_s_p9_1[] = {
  115909. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 9,10,10,10,10, 6,
  115910. 5, 5, 7, 7, 8, 8,10, 8,11,10,12,12,13,13, 6, 5,
  115911. 5, 7, 7, 8, 8,10, 9,11,11,12,12,13,12,18, 8, 8,
  115912. 8, 8, 9, 9,10, 9,11,10,12,12,13,13,18, 8, 8, 8,
  115913. 8, 9, 9,10,10,11,11,13,12,14,13,18,11,11, 9, 9,
  115914. 10,10,11,11,11,12,13,12,13,14,18,11,11, 9, 8,11,
  115915. 10,11,11,11,11,12,12,14,13,18,18,18,10,11,10,11,
  115916. 12,12,12,12,13,12,14,13,18,18,18,10,11,11, 9,12,
  115917. 11,12,12,12,13,13,13,18,18,17,14,14,11,11,12,12,
  115918. 13,12,14,12,14,13,18,18,18,14,14,11,10,12, 9,12,
  115919. 13,13,13,13,13,18,18,17,16,18,13,13,12,12,13,11,
  115920. 14,12,14,14,17,18,18,17,18,13,12,13,10,12,11,14,
  115921. 14,14,14,17,18,18,18,18,15,16,12,12,13,10,14,12,
  115922. 14,15,18,18,18,16,17,16,14,12,11,13,10,13,13,14,
  115923. 15,
  115924. };
  115925. static float _vq_quantthresh__44c3_s_p9_1[] = {
  115926. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  115927. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  115928. };
  115929. static long _vq_quantmap__44c3_s_p9_1[] = {
  115930. 13, 11, 9, 7, 5, 3, 1, 0,
  115931. 2, 4, 6, 8, 10, 12, 14,
  115932. };
  115933. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_1 = {
  115934. _vq_quantthresh__44c3_s_p9_1,
  115935. _vq_quantmap__44c3_s_p9_1,
  115936. 15,
  115937. 15
  115938. };
  115939. static static_codebook _44c3_s_p9_1 = {
  115940. 2, 225,
  115941. _vq_lengthlist__44c3_s_p9_1,
  115942. 1, -522338304, 1620115456, 4, 0,
  115943. _vq_quantlist__44c3_s_p9_1,
  115944. NULL,
  115945. &_vq_auxt__44c3_s_p9_1,
  115946. NULL,
  115947. 0
  115948. };
  115949. static long _vq_quantlist__44c3_s_p9_2[] = {
  115950. 8,
  115951. 7,
  115952. 9,
  115953. 6,
  115954. 10,
  115955. 5,
  115956. 11,
  115957. 4,
  115958. 12,
  115959. 3,
  115960. 13,
  115961. 2,
  115962. 14,
  115963. 1,
  115964. 15,
  115965. 0,
  115966. 16,
  115967. };
  115968. static long _vq_lengthlist__44c3_s_p9_2[] = {
  115969. 2, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8,
  115970. 8,10, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 8, 9, 9, 9,
  115971. 9, 9,10, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  115972. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  115973. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  115974. 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  115975. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  115976. 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 9, 9, 9, 9, 9,
  115977. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 9, 9, 9,
  115978. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  115979. 9, 9, 9, 9,10,10, 9, 9,10, 9,11,10,11,11,11, 9,
  115980. 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,11,11,11,11,11,
  115981. 9, 9, 9, 9,10,10, 9, 9, 9, 9,10, 9,11,11,11,11,
  115982. 11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11,
  115983. 11,11,11,11,10, 9,10,10, 9,10, 9, 9,10, 9,11,10,
  115984. 10,11,11,11,11, 9,10, 9, 9, 9, 9,10,10,10,10,11,
  115985. 11,11,11,11,11,10,10,10, 9, 9,10, 9,10, 9,10,10,
  115986. 10,10,11,11,11,11,11,11,11, 9, 9, 9, 9, 9,10,10,
  115987. 10,
  115988. };
  115989. static float _vq_quantthresh__44c3_s_p9_2[] = {
  115990. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  115991. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  115992. };
  115993. static long _vq_quantmap__44c3_s_p9_2[] = {
  115994. 15, 13, 11, 9, 7, 5, 3, 1,
  115995. 0, 2, 4, 6, 8, 10, 12, 14,
  115996. 16,
  115997. };
  115998. static encode_aux_threshmatch _vq_auxt__44c3_s_p9_2 = {
  115999. _vq_quantthresh__44c3_s_p9_2,
  116000. _vq_quantmap__44c3_s_p9_2,
  116001. 17,
  116002. 17
  116003. };
  116004. static static_codebook _44c3_s_p9_2 = {
  116005. 2, 289,
  116006. _vq_lengthlist__44c3_s_p9_2,
  116007. 1, -529530880, 1611661312, 5, 0,
  116008. _vq_quantlist__44c3_s_p9_2,
  116009. NULL,
  116010. &_vq_auxt__44c3_s_p9_2,
  116011. NULL,
  116012. 0
  116013. };
  116014. static long _huff_lengthlist__44c3_s_short[] = {
  116015. 10, 9,13,11,14,10,12,13,13,14, 7, 2,12, 5,10, 5,
  116016. 7,10,12,14,12, 6, 9, 8, 7, 7, 9,11,13,16,10, 4,
  116017. 12, 5,10, 6, 8,12,14,16,12, 6, 8, 7, 6, 5, 7,11,
  116018. 12,16,10, 4, 8, 5, 6, 4, 6, 9,13,16,10, 6,10, 7,
  116019. 7, 6, 7, 9,13,15,12, 9,11, 9, 8, 6, 7,10,12,14,
  116020. 14,11,10, 9, 6, 5, 6, 9,11,13,15,13,11,10, 6, 5,
  116021. 6, 8, 9,11,
  116022. };
  116023. static static_codebook _huff_book__44c3_s_short = {
  116024. 2, 100,
  116025. _huff_lengthlist__44c3_s_short,
  116026. 0, 0, 0, 0, 0,
  116027. NULL,
  116028. NULL,
  116029. NULL,
  116030. NULL,
  116031. 0
  116032. };
  116033. static long _huff_lengthlist__44c4_s_long[] = {
  116034. 4, 7,11,11,11,11,10,11,12,11, 5, 2,11, 5, 6, 6,
  116035. 7, 9,11,12,11, 9, 6,10, 6, 7, 8, 9,10,11,11, 5,
  116036. 11, 7, 8, 8, 9,11,13,14,11, 6, 5, 8, 4, 5, 7, 8,
  116037. 10,11,10, 6, 7, 7, 5, 5, 6, 8, 9,11,10, 7, 8, 9,
  116038. 6, 6, 6, 7, 8, 9,11, 9, 9,11, 7, 7, 6, 6, 7, 9,
  116039. 12,12,10,13, 9, 8, 7, 7, 7, 8,11,13,11,14,11,10,
  116040. 9, 8, 7, 7,
  116041. };
  116042. static static_codebook _huff_book__44c4_s_long = {
  116043. 2, 100,
  116044. _huff_lengthlist__44c4_s_long,
  116045. 0, 0, 0, 0, 0,
  116046. NULL,
  116047. NULL,
  116048. NULL,
  116049. NULL,
  116050. 0
  116051. };
  116052. static long _vq_quantlist__44c4_s_p1_0[] = {
  116053. 1,
  116054. 0,
  116055. 2,
  116056. };
  116057. static long _vq_lengthlist__44c4_s_p1_0[] = {
  116058. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 0,
  116059. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  116064. 0, 0, 0, 6, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 6, 8, 7, 0, 0,
  116069. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  116104. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  116105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  116109. 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  116110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  116114. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  116115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116123. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116131. 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116139. 0, 0, 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  116150. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116154. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  116155. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  116156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116159. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  116160. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116468. 0,
  116469. };
  116470. static float _vq_quantthresh__44c4_s_p1_0[] = {
  116471. -0.5, 0.5,
  116472. };
  116473. static long _vq_quantmap__44c4_s_p1_0[] = {
  116474. 1, 0, 2,
  116475. };
  116476. static encode_aux_threshmatch _vq_auxt__44c4_s_p1_0 = {
  116477. _vq_quantthresh__44c4_s_p1_0,
  116478. _vq_quantmap__44c4_s_p1_0,
  116479. 3,
  116480. 3
  116481. };
  116482. static static_codebook _44c4_s_p1_0 = {
  116483. 8, 6561,
  116484. _vq_lengthlist__44c4_s_p1_0,
  116485. 1, -535822336, 1611661312, 2, 0,
  116486. _vq_quantlist__44c4_s_p1_0,
  116487. NULL,
  116488. &_vq_auxt__44c4_s_p1_0,
  116489. NULL,
  116490. 0
  116491. };
  116492. static long _vq_quantlist__44c4_s_p2_0[] = {
  116493. 2,
  116494. 1,
  116495. 3,
  116496. 0,
  116497. 4,
  116498. };
  116499. static long _vq_lengthlist__44c4_s_p2_0[] = {
  116500. 2, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  116501. 7, 7, 0, 0, 0, 0, 0, 0, 0, 5, 6, 6, 0, 0, 0, 7,
  116502. 7, 0, 0, 0, 7, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116503. 0, 0, 5, 6, 6, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0,
  116504. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116509. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 7, 7, 0, 0,
  116510. 0, 7, 7, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5,
  116511. 7, 8, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9,
  116512. 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116517. 0, 0, 0, 5, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 7, 7,
  116518. 0, 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0,
  116519. 0, 0, 7, 7, 0, 0, 0, 7, 7, 0, 0, 0, 9, 9, 0, 0,
  116520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116525. 7,10,10, 0, 0, 0, 9, 9, 0, 0, 0, 9, 9, 0, 0, 0,
  116526. 10,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0, 9,
  116527. 9, 0, 0, 0, 9, 9, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  116528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116539. 0,
  116540. };
  116541. static float _vq_quantthresh__44c4_s_p2_0[] = {
  116542. -1.5, -0.5, 0.5, 1.5,
  116543. };
  116544. static long _vq_quantmap__44c4_s_p2_0[] = {
  116545. 3, 1, 0, 2, 4,
  116546. };
  116547. static encode_aux_threshmatch _vq_auxt__44c4_s_p2_0 = {
  116548. _vq_quantthresh__44c4_s_p2_0,
  116549. _vq_quantmap__44c4_s_p2_0,
  116550. 5,
  116551. 5
  116552. };
  116553. static static_codebook _44c4_s_p2_0 = {
  116554. 4, 625,
  116555. _vq_lengthlist__44c4_s_p2_0,
  116556. 1, -533725184, 1611661312, 3, 0,
  116557. _vq_quantlist__44c4_s_p2_0,
  116558. NULL,
  116559. &_vq_auxt__44c4_s_p2_0,
  116560. NULL,
  116561. 0
  116562. };
  116563. static long _vq_quantlist__44c4_s_p3_0[] = {
  116564. 2,
  116565. 1,
  116566. 3,
  116567. 0,
  116568. 4,
  116569. };
  116570. static long _vq_lengthlist__44c4_s_p3_0[] = {
  116571. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 4, 6, 6, 0, 0,
  116573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116574. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  116576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116577. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  116578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116593. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116594. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116595. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116596. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116597. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116598. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116599. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116600. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116601. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116602. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116603. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116604. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116605. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116606. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116607. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116608. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116609. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116610. 0,
  116611. };
  116612. static float _vq_quantthresh__44c4_s_p3_0[] = {
  116613. -1.5, -0.5, 0.5, 1.5,
  116614. };
  116615. static long _vq_quantmap__44c4_s_p3_0[] = {
  116616. 3, 1, 0, 2, 4,
  116617. };
  116618. static encode_aux_threshmatch _vq_auxt__44c4_s_p3_0 = {
  116619. _vq_quantthresh__44c4_s_p3_0,
  116620. _vq_quantmap__44c4_s_p3_0,
  116621. 5,
  116622. 5
  116623. };
  116624. static static_codebook _44c4_s_p3_0 = {
  116625. 4, 625,
  116626. _vq_lengthlist__44c4_s_p3_0,
  116627. 1, -533725184, 1611661312, 3, 0,
  116628. _vq_quantlist__44c4_s_p3_0,
  116629. NULL,
  116630. &_vq_auxt__44c4_s_p3_0,
  116631. NULL,
  116632. 0
  116633. };
  116634. static long _vq_quantlist__44c4_s_p4_0[] = {
  116635. 4,
  116636. 3,
  116637. 5,
  116638. 2,
  116639. 6,
  116640. 1,
  116641. 7,
  116642. 0,
  116643. 8,
  116644. };
  116645. static long _vq_lengthlist__44c4_s_p4_0[] = {
  116646. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  116647. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  116648. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  116649. 7, 8, 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0,
  116650. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  116651. 0,
  116652. };
  116653. static float _vq_quantthresh__44c4_s_p4_0[] = {
  116654. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116655. };
  116656. static long _vq_quantmap__44c4_s_p4_0[] = {
  116657. 7, 5, 3, 1, 0, 2, 4, 6,
  116658. 8,
  116659. };
  116660. static encode_aux_threshmatch _vq_auxt__44c4_s_p4_0 = {
  116661. _vq_quantthresh__44c4_s_p4_0,
  116662. _vq_quantmap__44c4_s_p4_0,
  116663. 9,
  116664. 9
  116665. };
  116666. static static_codebook _44c4_s_p4_0 = {
  116667. 2, 81,
  116668. _vq_lengthlist__44c4_s_p4_0,
  116669. 1, -531628032, 1611661312, 4, 0,
  116670. _vq_quantlist__44c4_s_p4_0,
  116671. NULL,
  116672. &_vq_auxt__44c4_s_p4_0,
  116673. NULL,
  116674. 0
  116675. };
  116676. static long _vq_quantlist__44c4_s_p5_0[] = {
  116677. 4,
  116678. 3,
  116679. 5,
  116680. 2,
  116681. 6,
  116682. 1,
  116683. 7,
  116684. 0,
  116685. 8,
  116686. };
  116687. static long _vq_lengthlist__44c4_s_p5_0[] = {
  116688. 2, 3, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  116689. 9, 9, 0, 4, 5, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  116690. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10, 9, 0, 0, 0,
  116691. 9, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  116692. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,10,
  116693. 10,
  116694. };
  116695. static float _vq_quantthresh__44c4_s_p5_0[] = {
  116696. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  116697. };
  116698. static long _vq_quantmap__44c4_s_p5_0[] = {
  116699. 7, 5, 3, 1, 0, 2, 4, 6,
  116700. 8,
  116701. };
  116702. static encode_aux_threshmatch _vq_auxt__44c4_s_p5_0 = {
  116703. _vq_quantthresh__44c4_s_p5_0,
  116704. _vq_quantmap__44c4_s_p5_0,
  116705. 9,
  116706. 9
  116707. };
  116708. static static_codebook _44c4_s_p5_0 = {
  116709. 2, 81,
  116710. _vq_lengthlist__44c4_s_p5_0,
  116711. 1, -531628032, 1611661312, 4, 0,
  116712. _vq_quantlist__44c4_s_p5_0,
  116713. NULL,
  116714. &_vq_auxt__44c4_s_p5_0,
  116715. NULL,
  116716. 0
  116717. };
  116718. static long _vq_quantlist__44c4_s_p6_0[] = {
  116719. 8,
  116720. 7,
  116721. 9,
  116722. 6,
  116723. 10,
  116724. 5,
  116725. 11,
  116726. 4,
  116727. 12,
  116728. 3,
  116729. 13,
  116730. 2,
  116731. 14,
  116732. 1,
  116733. 15,
  116734. 0,
  116735. 16,
  116736. };
  116737. static long _vq_lengthlist__44c4_s_p6_0[] = {
  116738. 2, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  116739. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  116740. 11,11, 0, 4, 4, 7, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  116741. 11,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  116742. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  116743. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116744. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9,
  116745. 9,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  116746. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  116747. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  116748. 9,10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9,
  116749. 9, 9, 9,10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0,
  116750. 10,10,10,10,11,11,11,11,12,12,13,12, 0, 0, 0, 0,
  116751. 0, 0, 0,10,10,11,11,11,11,12,12,12,12, 0, 0, 0,
  116752. 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0, 0,
  116753. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  116754. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,13,13,
  116755. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,
  116756. 13,
  116757. };
  116758. static float _vq_quantthresh__44c4_s_p6_0[] = {
  116759. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  116760. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  116761. };
  116762. static long _vq_quantmap__44c4_s_p6_0[] = {
  116763. 15, 13, 11, 9, 7, 5, 3, 1,
  116764. 0, 2, 4, 6, 8, 10, 12, 14,
  116765. 16,
  116766. };
  116767. static encode_aux_threshmatch _vq_auxt__44c4_s_p6_0 = {
  116768. _vq_quantthresh__44c4_s_p6_0,
  116769. _vq_quantmap__44c4_s_p6_0,
  116770. 17,
  116771. 17
  116772. };
  116773. static static_codebook _44c4_s_p6_0 = {
  116774. 2, 289,
  116775. _vq_lengthlist__44c4_s_p6_0,
  116776. 1, -529530880, 1611661312, 5, 0,
  116777. _vq_quantlist__44c4_s_p6_0,
  116778. NULL,
  116779. &_vq_auxt__44c4_s_p6_0,
  116780. NULL,
  116781. 0
  116782. };
  116783. static long _vq_quantlist__44c4_s_p7_0[] = {
  116784. 1,
  116785. 0,
  116786. 2,
  116787. };
  116788. static long _vq_lengthlist__44c4_s_p7_0[] = {
  116789. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  116790. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  116791. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  116792. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  116793. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  116794. 10,
  116795. };
  116796. static float _vq_quantthresh__44c4_s_p7_0[] = {
  116797. -5.5, 5.5,
  116798. };
  116799. static long _vq_quantmap__44c4_s_p7_0[] = {
  116800. 1, 0, 2,
  116801. };
  116802. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_0 = {
  116803. _vq_quantthresh__44c4_s_p7_0,
  116804. _vq_quantmap__44c4_s_p7_0,
  116805. 3,
  116806. 3
  116807. };
  116808. static static_codebook _44c4_s_p7_0 = {
  116809. 4, 81,
  116810. _vq_lengthlist__44c4_s_p7_0,
  116811. 1, -529137664, 1618345984, 2, 0,
  116812. _vq_quantlist__44c4_s_p7_0,
  116813. NULL,
  116814. &_vq_auxt__44c4_s_p7_0,
  116815. NULL,
  116816. 0
  116817. };
  116818. static long _vq_quantlist__44c4_s_p7_1[] = {
  116819. 5,
  116820. 4,
  116821. 6,
  116822. 3,
  116823. 7,
  116824. 2,
  116825. 8,
  116826. 1,
  116827. 9,
  116828. 0,
  116829. 10,
  116830. };
  116831. static long _vq_lengthlist__44c4_s_p7_1[] = {
  116832. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  116833. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  116834. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  116835. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  116836. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  116837. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  116838. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 9, 8,10,10,
  116839. 10,10,10, 8, 8, 8, 8, 9, 9,
  116840. };
  116841. static float _vq_quantthresh__44c4_s_p7_1[] = {
  116842. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  116843. 3.5, 4.5,
  116844. };
  116845. static long _vq_quantmap__44c4_s_p7_1[] = {
  116846. 9, 7, 5, 3, 1, 0, 2, 4,
  116847. 6, 8, 10,
  116848. };
  116849. static encode_aux_threshmatch _vq_auxt__44c4_s_p7_1 = {
  116850. _vq_quantthresh__44c4_s_p7_1,
  116851. _vq_quantmap__44c4_s_p7_1,
  116852. 11,
  116853. 11
  116854. };
  116855. static static_codebook _44c4_s_p7_1 = {
  116856. 2, 121,
  116857. _vq_lengthlist__44c4_s_p7_1,
  116858. 1, -531365888, 1611661312, 4, 0,
  116859. _vq_quantlist__44c4_s_p7_1,
  116860. NULL,
  116861. &_vq_auxt__44c4_s_p7_1,
  116862. NULL,
  116863. 0
  116864. };
  116865. static long _vq_quantlist__44c4_s_p8_0[] = {
  116866. 6,
  116867. 5,
  116868. 7,
  116869. 4,
  116870. 8,
  116871. 3,
  116872. 9,
  116873. 2,
  116874. 10,
  116875. 1,
  116876. 11,
  116877. 0,
  116878. 12,
  116879. };
  116880. static long _vq_lengthlist__44c4_s_p8_0[] = {
  116881. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  116882. 7, 7, 8, 8, 8, 8, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  116883. 8, 9, 9,10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  116884. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  116885. 11, 0,12,12, 9, 9, 9, 9,10,10,10,10,11,11, 0,13,
  116886. 13, 9, 9,10, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  116887. 10,10,10,10,11,11,12,12, 0, 0, 0,10,10,10,10,10,
  116888. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  116889. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,13, 0,
  116890. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  116891. 0,13,12,12,12,12,12,13,13,
  116892. };
  116893. static float _vq_quantthresh__44c4_s_p8_0[] = {
  116894. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  116895. 12.5, 17.5, 22.5, 27.5,
  116896. };
  116897. static long _vq_quantmap__44c4_s_p8_0[] = {
  116898. 11, 9, 7, 5, 3, 1, 0, 2,
  116899. 4, 6, 8, 10, 12,
  116900. };
  116901. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_0 = {
  116902. _vq_quantthresh__44c4_s_p8_0,
  116903. _vq_quantmap__44c4_s_p8_0,
  116904. 13,
  116905. 13
  116906. };
  116907. static static_codebook _44c4_s_p8_0 = {
  116908. 2, 169,
  116909. _vq_lengthlist__44c4_s_p8_0,
  116910. 1, -526516224, 1616117760, 4, 0,
  116911. _vq_quantlist__44c4_s_p8_0,
  116912. NULL,
  116913. &_vq_auxt__44c4_s_p8_0,
  116914. NULL,
  116915. 0
  116916. };
  116917. static long _vq_quantlist__44c4_s_p8_1[] = {
  116918. 2,
  116919. 1,
  116920. 3,
  116921. 0,
  116922. 4,
  116923. };
  116924. static long _vq_lengthlist__44c4_s_p8_1[] = {
  116925. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 5, 4, 5, 5, 6,
  116926. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  116927. };
  116928. static float _vq_quantthresh__44c4_s_p8_1[] = {
  116929. -1.5, -0.5, 0.5, 1.5,
  116930. };
  116931. static long _vq_quantmap__44c4_s_p8_1[] = {
  116932. 3, 1, 0, 2, 4,
  116933. };
  116934. static encode_aux_threshmatch _vq_auxt__44c4_s_p8_1 = {
  116935. _vq_quantthresh__44c4_s_p8_1,
  116936. _vq_quantmap__44c4_s_p8_1,
  116937. 5,
  116938. 5
  116939. };
  116940. static static_codebook _44c4_s_p8_1 = {
  116941. 2, 25,
  116942. _vq_lengthlist__44c4_s_p8_1,
  116943. 1, -533725184, 1611661312, 3, 0,
  116944. _vq_quantlist__44c4_s_p8_1,
  116945. NULL,
  116946. &_vq_auxt__44c4_s_p8_1,
  116947. NULL,
  116948. 0
  116949. };
  116950. static long _vq_quantlist__44c4_s_p9_0[] = {
  116951. 6,
  116952. 5,
  116953. 7,
  116954. 4,
  116955. 8,
  116956. 3,
  116957. 9,
  116958. 2,
  116959. 10,
  116960. 1,
  116961. 11,
  116962. 0,
  116963. 12,
  116964. };
  116965. static long _vq_lengthlist__44c4_s_p9_0[] = {
  116966. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 4, 7, 7,
  116967. 12,12,12,12,12,12,12,12,12,12, 3, 8, 8,12,12,12,
  116968. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116969. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116970. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116971. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116972. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116973. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116974. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116975. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  116976. 12,12,12,12,12,12,12,12,12,
  116977. };
  116978. static float _vq_quantthresh__44c4_s_p9_0[] = {
  116979. -1732.5, -1417.5, -1102.5, -787.5, -472.5, -157.5, 157.5, 472.5,
  116980. 787.5, 1102.5, 1417.5, 1732.5,
  116981. };
  116982. static long _vq_quantmap__44c4_s_p9_0[] = {
  116983. 11, 9, 7, 5, 3, 1, 0, 2,
  116984. 4, 6, 8, 10, 12,
  116985. };
  116986. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_0 = {
  116987. _vq_quantthresh__44c4_s_p9_0,
  116988. _vq_quantmap__44c4_s_p9_0,
  116989. 13,
  116990. 13
  116991. };
  116992. static static_codebook _44c4_s_p9_0 = {
  116993. 2, 169,
  116994. _vq_lengthlist__44c4_s_p9_0,
  116995. 1, -513964032, 1628680192, 4, 0,
  116996. _vq_quantlist__44c4_s_p9_0,
  116997. NULL,
  116998. &_vq_auxt__44c4_s_p9_0,
  116999. NULL,
  117000. 0
  117001. };
  117002. static long _vq_quantlist__44c4_s_p9_1[] = {
  117003. 7,
  117004. 6,
  117005. 8,
  117006. 5,
  117007. 9,
  117008. 4,
  117009. 10,
  117010. 3,
  117011. 11,
  117012. 2,
  117013. 12,
  117014. 1,
  117015. 13,
  117016. 0,
  117017. 14,
  117018. };
  117019. static long _vq_lengthlist__44c4_s_p9_1[] = {
  117020. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,10,10, 6,
  117021. 5, 5, 7, 7, 9, 8,10, 9,11,10,12,12,13,13, 6, 5,
  117022. 5, 7, 7, 9, 9,10,10,11,11,12,12,12,13,19, 8, 8,
  117023. 8, 8, 9, 9,10,10,12,11,12,12,13,13,19, 8, 8, 8,
  117024. 8, 9, 9,11,11,12,12,13,13,13,13,19,12,12, 9, 9,
  117025. 11,11,11,11,12,11,13,12,13,13,18,12,12, 9, 9,11,
  117026. 10,11,11,12,12,12,13,13,14,19,18,18,11,11,11,11,
  117027. 12,12,13,12,13,13,14,14,16,18,18,11,11,11,10,12,
  117028. 11,13,13,13,13,13,14,17,18,18,14,15,11,12,12,13,
  117029. 13,13,13,14,14,14,18,18,18,15,15,12,10,13,10,13,
  117030. 13,13,13,13,14,18,17,18,17,18,12,13,12,13,13,13,
  117031. 14,14,16,14,18,17,18,18,17,13,12,13,10,12,12,14,
  117032. 14,14,14,17,18,18,18,18,14,15,12,12,13,12,14,14,
  117033. 15,15,18,18,18,17,18,15,14,12,11,12,12,14,14,14,
  117034. 15,
  117035. };
  117036. static float _vq_quantthresh__44c4_s_p9_1[] = {
  117037. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  117038. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  117039. };
  117040. static long _vq_quantmap__44c4_s_p9_1[] = {
  117041. 13, 11, 9, 7, 5, 3, 1, 0,
  117042. 2, 4, 6, 8, 10, 12, 14,
  117043. };
  117044. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_1 = {
  117045. _vq_quantthresh__44c4_s_p9_1,
  117046. _vq_quantmap__44c4_s_p9_1,
  117047. 15,
  117048. 15
  117049. };
  117050. static static_codebook _44c4_s_p9_1 = {
  117051. 2, 225,
  117052. _vq_lengthlist__44c4_s_p9_1,
  117053. 1, -520986624, 1620377600, 4, 0,
  117054. _vq_quantlist__44c4_s_p9_1,
  117055. NULL,
  117056. &_vq_auxt__44c4_s_p9_1,
  117057. NULL,
  117058. 0
  117059. };
  117060. static long _vq_quantlist__44c4_s_p9_2[] = {
  117061. 10,
  117062. 9,
  117063. 11,
  117064. 8,
  117065. 12,
  117066. 7,
  117067. 13,
  117068. 6,
  117069. 14,
  117070. 5,
  117071. 15,
  117072. 4,
  117073. 16,
  117074. 3,
  117075. 17,
  117076. 2,
  117077. 18,
  117078. 1,
  117079. 19,
  117080. 0,
  117081. 20,
  117082. };
  117083. static long _vq_lengthlist__44c4_s_p9_2[] = {
  117084. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  117085. 8, 9, 9, 9, 9,11, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  117086. 9, 9, 9, 9, 9, 9,10,10,10,10,11, 6, 6, 7, 7, 8,
  117087. 8, 8, 8, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,
  117088. 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  117089. 10,10,10,10,12,11,11, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  117090. 9,10,10,10,10,10,10,10,10,12,11,12, 8, 8, 8, 8,
  117091. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,11,
  117092. 11, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,
  117093. 10,10,10,11,11,12, 9, 9, 9, 9, 9, 9,10, 9,10,10,
  117094. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  117095. 9,10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,
  117096. 11,11, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  117097. 10,10,11,11,11,11,11, 9, 9, 9, 9,10,10,10,10,10,
  117098. 10,10,10,10,10,10,10,11,11,11,12,12,10,10,10,10,
  117099. 10,10,10,10,10,10,10,10,10,10,10,10,11,12,11,12,
  117100. 11,11,11, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  117101. 10,11,12,11,11,11,11,11,10,10,10,10,10,10,10,10,
  117102. 10,10,10,10,10,10,11,11,11,12,11,11,11,10,10,10,
  117103. 10,10,10,10,10,10,10,10,10,10,10,12,11,11,12,11,
  117104. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  117105. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  117106. 10,10,10,10,10,11,11,11,11,12,12,11,11,11,11,11,
  117107. 11,11,10,10,10,10,10,10,10,10,12,12,12,11,11,11,
  117108. 12,11,11,11,10,10,10,10,10,10,10,10,10,10,10,12,
  117109. 11,12,12,12,12,12,11,12,11,11,10,10,10,10,10,10,
  117110. 10,10,10,10,12,12,12,12,11,11,11,11,11,11,11,10,
  117111. 10,10,10,10,10,10,10,10,10,
  117112. };
  117113. static float _vq_quantthresh__44c4_s_p9_2[] = {
  117114. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  117115. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  117116. 6.5, 7.5, 8.5, 9.5,
  117117. };
  117118. static long _vq_quantmap__44c4_s_p9_2[] = {
  117119. 19, 17, 15, 13, 11, 9, 7, 5,
  117120. 3, 1, 0, 2, 4, 6, 8, 10,
  117121. 12, 14, 16, 18, 20,
  117122. };
  117123. static encode_aux_threshmatch _vq_auxt__44c4_s_p9_2 = {
  117124. _vq_quantthresh__44c4_s_p9_2,
  117125. _vq_quantmap__44c4_s_p9_2,
  117126. 21,
  117127. 21
  117128. };
  117129. static static_codebook _44c4_s_p9_2 = {
  117130. 2, 441,
  117131. _vq_lengthlist__44c4_s_p9_2,
  117132. 1, -529268736, 1611661312, 5, 0,
  117133. _vq_quantlist__44c4_s_p9_2,
  117134. NULL,
  117135. &_vq_auxt__44c4_s_p9_2,
  117136. NULL,
  117137. 0
  117138. };
  117139. static long _huff_lengthlist__44c4_s_short[] = {
  117140. 4, 7,14,10,15,10,12,15,16,15, 4, 2,11, 5,10, 6,
  117141. 8,11,14,14,14,10, 7,11, 6, 8,10,11,13,15, 9, 4,
  117142. 11, 5, 9, 6, 9,12,14,15,14, 9, 6, 9, 4, 5, 7,10,
  117143. 12,13, 9, 5, 7, 6, 5, 5, 7,10,13,13,10, 8, 9, 8,
  117144. 7, 6, 8,10,14,14,13,11,10,10, 7, 7, 8,11,14,15,
  117145. 13,12, 9, 9, 6, 5, 7,10,14,17,15,13,11,10, 6, 6,
  117146. 7, 9,12,17,
  117147. };
  117148. static static_codebook _huff_book__44c4_s_short = {
  117149. 2, 100,
  117150. _huff_lengthlist__44c4_s_short,
  117151. 0, 0, 0, 0, 0,
  117152. NULL,
  117153. NULL,
  117154. NULL,
  117155. NULL,
  117156. 0
  117157. };
  117158. static long _huff_lengthlist__44c5_s_long[] = {
  117159. 3, 8, 9,13,10,12,12,12,12,12, 6, 4, 6, 8, 6, 8,
  117160. 10,10,11,12, 8, 5, 4,10, 4, 7, 8, 9,10,11,13, 8,
  117161. 10, 8, 9, 9,11,12,13,14,10, 6, 4, 9, 3, 5, 6, 8,
  117162. 10,11,11, 8, 6, 9, 5, 5, 6, 7, 9,11,12, 9, 7,11,
  117163. 6, 6, 6, 7, 8,10,12,11, 9,12, 7, 7, 6, 6, 7, 9,
  117164. 13,12,10,13, 9, 8, 7, 7, 7, 8,11,15,11,15,11,10,
  117165. 9, 8, 7, 7,
  117166. };
  117167. static static_codebook _huff_book__44c5_s_long = {
  117168. 2, 100,
  117169. _huff_lengthlist__44c5_s_long,
  117170. 0, 0, 0, 0, 0,
  117171. NULL,
  117172. NULL,
  117173. NULL,
  117174. NULL,
  117175. 0
  117176. };
  117177. static long _vq_quantlist__44c5_s_p1_0[] = {
  117178. 1,
  117179. 0,
  117180. 2,
  117181. };
  117182. static long _vq_lengthlist__44c5_s_p1_0[] = {
  117183. 2, 4, 4, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  117184. 0, 0, 4, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  117189. 0, 0, 0, 7, 8, 9, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  117194. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  117229. 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  117230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  117234. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  117235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  117239. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  117240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117248. 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117256. 0, 0, 0, 0, 0, 0, 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. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117264. 0, 0, 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  117275. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117279. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  117280. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  117281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117284. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  117285. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  117286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117403. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117404. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117405. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117406. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117407. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117408. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117409. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117410. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117411. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117412. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117413. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117414. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117415. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117418. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117421. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117454. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117455. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117456. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117457. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117458. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117459. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117460. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117461. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117462. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117463. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117464. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117465. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117466. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117467. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117468. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117469. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117470. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117471. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117472. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117473. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117474. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117475. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117476. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117477. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117478. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117479. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117484. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117485. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117486. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117487. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117488. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117489. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117490. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117491. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117492. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117501. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117502. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117503. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117504. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117505. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117506. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117507. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117508. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117509. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117510. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117511. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117512. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117513. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117514. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117515. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117516. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117517. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117518. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117519. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117520. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117521. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117522. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117523. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117524. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117525. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117526. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117527. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117528. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117529. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117530. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117531. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117532. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117533. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117534. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117535. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117536. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117537. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117538. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117539. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117540. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117541. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117542. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117543. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117544. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117545. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117546. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117547. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117548. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117549. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117550. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117551. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117552. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117553. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117554. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117555. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117556. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117557. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117558. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117559. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117560. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117561. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117562. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117563. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117564. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117565. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117566. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117567. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117568. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117569. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117570. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117571. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117572. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117573. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117574. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117575. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117576. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117577. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117578. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117579. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117580. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117581. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117582. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117583. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117584. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117585. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117586. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117587. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117588. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117589. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117590. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117591. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117592. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117593. 0,
  117594. };
  117595. static float _vq_quantthresh__44c5_s_p1_0[] = {
  117596. -0.5, 0.5,
  117597. };
  117598. static long _vq_quantmap__44c5_s_p1_0[] = {
  117599. 1, 0, 2,
  117600. };
  117601. static encode_aux_threshmatch _vq_auxt__44c5_s_p1_0 = {
  117602. _vq_quantthresh__44c5_s_p1_0,
  117603. _vq_quantmap__44c5_s_p1_0,
  117604. 3,
  117605. 3
  117606. };
  117607. static static_codebook _44c5_s_p1_0 = {
  117608. 8, 6561,
  117609. _vq_lengthlist__44c5_s_p1_0,
  117610. 1, -535822336, 1611661312, 2, 0,
  117611. _vq_quantlist__44c5_s_p1_0,
  117612. NULL,
  117613. &_vq_auxt__44c5_s_p1_0,
  117614. NULL,
  117615. 0
  117616. };
  117617. static long _vq_quantlist__44c5_s_p2_0[] = {
  117618. 2,
  117619. 1,
  117620. 3,
  117621. 0,
  117622. 4,
  117623. };
  117624. static long _vq_lengthlist__44c5_s_p2_0[] = {
  117625. 2, 4, 4, 0, 0, 0, 5, 5, 0, 0, 0, 5, 5, 0, 0, 0,
  117626. 8, 7, 0, 0, 0, 0, 0, 0, 0, 4, 6, 6, 0, 0, 0, 8,
  117627. 8, 0, 0, 0, 8, 7, 0, 0, 0,10,10, 0, 0, 0, 0, 0,
  117628. 0, 0, 4, 6, 6, 0, 0, 0, 8, 8, 0, 0, 0, 7, 8, 0,
  117629. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117630. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117631. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117634. 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 8, 8, 0, 0,
  117635. 0, 8, 8, 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5,
  117636. 7, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,
  117637. 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117638. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117639. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117640. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117641. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117642. 0, 0, 0, 5, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0, 8, 8,
  117643. 0, 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0,
  117644. 0, 0, 8, 8, 0, 0, 0, 8, 8, 0, 0, 0,10,10, 0, 0,
  117645. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117646. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117647. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117648. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117649. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117650. 8,10,10, 0, 0, 0,10,10, 0, 0, 0, 9,10, 0, 0, 0,
  117651. 11,10, 0, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0, 0,10,
  117652. 10, 0, 0, 0,10,10, 0, 0, 0,10,11, 0, 0, 0, 0, 0,
  117653. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117654. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117655. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117656. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117657. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117658. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117659. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117660. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117661. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117662. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117663. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117664. 0,
  117665. };
  117666. static float _vq_quantthresh__44c5_s_p2_0[] = {
  117667. -1.5, -0.5, 0.5, 1.5,
  117668. };
  117669. static long _vq_quantmap__44c5_s_p2_0[] = {
  117670. 3, 1, 0, 2, 4,
  117671. };
  117672. static encode_aux_threshmatch _vq_auxt__44c5_s_p2_0 = {
  117673. _vq_quantthresh__44c5_s_p2_0,
  117674. _vq_quantmap__44c5_s_p2_0,
  117675. 5,
  117676. 5
  117677. };
  117678. static static_codebook _44c5_s_p2_0 = {
  117679. 4, 625,
  117680. _vq_lengthlist__44c5_s_p2_0,
  117681. 1, -533725184, 1611661312, 3, 0,
  117682. _vq_quantlist__44c5_s_p2_0,
  117683. NULL,
  117684. &_vq_auxt__44c5_s_p2_0,
  117685. NULL,
  117686. 0
  117687. };
  117688. static long _vq_quantlist__44c5_s_p3_0[] = {
  117689. 2,
  117690. 1,
  117691. 3,
  117692. 0,
  117693. 4,
  117694. };
  117695. static long _vq_lengthlist__44c5_s_p3_0[] = {
  117696. 2, 4, 3, 5, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117697. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 6, 6, 0, 0,
  117698. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117699. 0, 0, 3, 5, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117700. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  117701. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117702. 0, 0, 0, 0, 5, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  117703. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117704. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117705. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117706. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117707. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117708. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117709. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117710. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117711. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117712. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117713. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117714. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117715. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117716. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117717. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117718. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117719. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117720. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117721. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117722. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117723. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117724. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117725. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117726. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117727. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117728. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117729. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117730. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117731. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117732. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117733. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117734. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117735. 0,
  117736. };
  117737. static float _vq_quantthresh__44c5_s_p3_0[] = {
  117738. -1.5, -0.5, 0.5, 1.5,
  117739. };
  117740. static long _vq_quantmap__44c5_s_p3_0[] = {
  117741. 3, 1, 0, 2, 4,
  117742. };
  117743. static encode_aux_threshmatch _vq_auxt__44c5_s_p3_0 = {
  117744. _vq_quantthresh__44c5_s_p3_0,
  117745. _vq_quantmap__44c5_s_p3_0,
  117746. 5,
  117747. 5
  117748. };
  117749. static static_codebook _44c5_s_p3_0 = {
  117750. 4, 625,
  117751. _vq_lengthlist__44c5_s_p3_0,
  117752. 1, -533725184, 1611661312, 3, 0,
  117753. _vq_quantlist__44c5_s_p3_0,
  117754. NULL,
  117755. &_vq_auxt__44c5_s_p3_0,
  117756. NULL,
  117757. 0
  117758. };
  117759. static long _vq_quantlist__44c5_s_p4_0[] = {
  117760. 4,
  117761. 3,
  117762. 5,
  117763. 2,
  117764. 6,
  117765. 1,
  117766. 7,
  117767. 0,
  117768. 8,
  117769. };
  117770. static long _vq_lengthlist__44c5_s_p4_0[] = {
  117771. 2, 3, 3, 6, 6, 0, 0, 0, 0, 0, 4, 4, 6, 6, 0, 0,
  117772. 0, 0, 0, 4, 4, 6, 6, 0, 0, 0, 0, 0, 5, 5, 6, 6,
  117773. 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0,
  117774. 7, 7, 0, 0, 0, 0, 0, 0, 0, 8, 7, 0, 0, 0, 0, 0,
  117775. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  117776. 0,
  117777. };
  117778. static float _vq_quantthresh__44c5_s_p4_0[] = {
  117779. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117780. };
  117781. static long _vq_quantmap__44c5_s_p4_0[] = {
  117782. 7, 5, 3, 1, 0, 2, 4, 6,
  117783. 8,
  117784. };
  117785. static encode_aux_threshmatch _vq_auxt__44c5_s_p4_0 = {
  117786. _vq_quantthresh__44c5_s_p4_0,
  117787. _vq_quantmap__44c5_s_p4_0,
  117788. 9,
  117789. 9
  117790. };
  117791. static static_codebook _44c5_s_p4_0 = {
  117792. 2, 81,
  117793. _vq_lengthlist__44c5_s_p4_0,
  117794. 1, -531628032, 1611661312, 4, 0,
  117795. _vq_quantlist__44c5_s_p4_0,
  117796. NULL,
  117797. &_vq_auxt__44c5_s_p4_0,
  117798. NULL,
  117799. 0
  117800. };
  117801. static long _vq_quantlist__44c5_s_p5_0[] = {
  117802. 4,
  117803. 3,
  117804. 5,
  117805. 2,
  117806. 6,
  117807. 1,
  117808. 7,
  117809. 0,
  117810. 8,
  117811. };
  117812. static long _vq_lengthlist__44c5_s_p5_0[] = {
  117813. 2, 4, 3, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  117814. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7,
  117815. 7, 7, 9, 9, 0, 0, 0, 7, 6, 7, 7, 9, 9, 0, 0, 0,
  117816. 8, 8, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  117817. 0, 0, 9, 9, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  117818. 10,
  117819. };
  117820. static float _vq_quantthresh__44c5_s_p5_0[] = {
  117821. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  117822. };
  117823. static long _vq_quantmap__44c5_s_p5_0[] = {
  117824. 7, 5, 3, 1, 0, 2, 4, 6,
  117825. 8,
  117826. };
  117827. static encode_aux_threshmatch _vq_auxt__44c5_s_p5_0 = {
  117828. _vq_quantthresh__44c5_s_p5_0,
  117829. _vq_quantmap__44c5_s_p5_0,
  117830. 9,
  117831. 9
  117832. };
  117833. static static_codebook _44c5_s_p5_0 = {
  117834. 2, 81,
  117835. _vq_lengthlist__44c5_s_p5_0,
  117836. 1, -531628032, 1611661312, 4, 0,
  117837. _vq_quantlist__44c5_s_p5_0,
  117838. NULL,
  117839. &_vq_auxt__44c5_s_p5_0,
  117840. NULL,
  117841. 0
  117842. };
  117843. static long _vq_quantlist__44c5_s_p6_0[] = {
  117844. 8,
  117845. 7,
  117846. 9,
  117847. 6,
  117848. 10,
  117849. 5,
  117850. 11,
  117851. 4,
  117852. 12,
  117853. 3,
  117854. 13,
  117855. 2,
  117856. 14,
  117857. 1,
  117858. 15,
  117859. 0,
  117860. 16,
  117861. };
  117862. static long _vq_lengthlist__44c5_s_p6_0[] = {
  117863. 2, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,11,
  117864. 11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,11,
  117865. 12,12, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,
  117866. 11,12,12, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  117867. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  117868. 10,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  117869. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 9,10,10,10,
  117870. 10,11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,
  117871. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  117872. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  117873. 10,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9,
  117874. 9, 9,10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  117875. 10,10,10,10,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  117876. 0, 0, 0,10,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  117877. 0, 0, 0, 0,11,11,11,11,12,12,12,13,13,13, 0, 0,
  117878. 0, 0, 0, 0, 0,11,11,11,11,12,12,12,12,13,13, 0,
  117879. 0, 0, 0, 0, 0, 0,12,12,12,12,13,12,13,13,13,13,
  117880. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,
  117881. 13,
  117882. };
  117883. static float _vq_quantthresh__44c5_s_p6_0[] = {
  117884. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  117885. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  117886. };
  117887. static long _vq_quantmap__44c5_s_p6_0[] = {
  117888. 15, 13, 11, 9, 7, 5, 3, 1,
  117889. 0, 2, 4, 6, 8, 10, 12, 14,
  117890. 16,
  117891. };
  117892. static encode_aux_threshmatch _vq_auxt__44c5_s_p6_0 = {
  117893. _vq_quantthresh__44c5_s_p6_0,
  117894. _vq_quantmap__44c5_s_p6_0,
  117895. 17,
  117896. 17
  117897. };
  117898. static static_codebook _44c5_s_p6_0 = {
  117899. 2, 289,
  117900. _vq_lengthlist__44c5_s_p6_0,
  117901. 1, -529530880, 1611661312, 5, 0,
  117902. _vq_quantlist__44c5_s_p6_0,
  117903. NULL,
  117904. &_vq_auxt__44c5_s_p6_0,
  117905. NULL,
  117906. 0
  117907. };
  117908. static long _vq_quantlist__44c5_s_p7_0[] = {
  117909. 1,
  117910. 0,
  117911. 2,
  117912. };
  117913. static long _vq_lengthlist__44c5_s_p7_0[] = {
  117914. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  117915. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  117916. 10,11,11,11, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  117917. 11,10,10,11,10,10, 7,11,11,12,11,11,12,11,11, 6,
  117918. 9, 9,11,10,10,11,10,10, 6, 9, 9,11,10,10,11,10,
  117919. 10,
  117920. };
  117921. static float _vq_quantthresh__44c5_s_p7_0[] = {
  117922. -5.5, 5.5,
  117923. };
  117924. static long _vq_quantmap__44c5_s_p7_0[] = {
  117925. 1, 0, 2,
  117926. };
  117927. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_0 = {
  117928. _vq_quantthresh__44c5_s_p7_0,
  117929. _vq_quantmap__44c5_s_p7_0,
  117930. 3,
  117931. 3
  117932. };
  117933. static static_codebook _44c5_s_p7_0 = {
  117934. 4, 81,
  117935. _vq_lengthlist__44c5_s_p7_0,
  117936. 1, -529137664, 1618345984, 2, 0,
  117937. _vq_quantlist__44c5_s_p7_0,
  117938. NULL,
  117939. &_vq_auxt__44c5_s_p7_0,
  117940. NULL,
  117941. 0
  117942. };
  117943. static long _vq_quantlist__44c5_s_p7_1[] = {
  117944. 5,
  117945. 4,
  117946. 6,
  117947. 3,
  117948. 7,
  117949. 2,
  117950. 8,
  117951. 1,
  117952. 9,
  117953. 0,
  117954. 10,
  117955. };
  117956. static long _vq_lengthlist__44c5_s_p7_1[] = {
  117957. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6,
  117958. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  117959. 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  117960. 7, 8, 8, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  117961. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  117962. 8, 8, 8, 8, 8, 8, 8, 9,10,10,10,10,10, 8, 8, 8,
  117963. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  117964. 10,10,10, 8, 8, 8, 8, 8, 8,
  117965. };
  117966. static float _vq_quantthresh__44c5_s_p7_1[] = {
  117967. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  117968. 3.5, 4.5,
  117969. };
  117970. static long _vq_quantmap__44c5_s_p7_1[] = {
  117971. 9, 7, 5, 3, 1, 0, 2, 4,
  117972. 6, 8, 10,
  117973. };
  117974. static encode_aux_threshmatch _vq_auxt__44c5_s_p7_1 = {
  117975. _vq_quantthresh__44c5_s_p7_1,
  117976. _vq_quantmap__44c5_s_p7_1,
  117977. 11,
  117978. 11
  117979. };
  117980. static static_codebook _44c5_s_p7_1 = {
  117981. 2, 121,
  117982. _vq_lengthlist__44c5_s_p7_1,
  117983. 1, -531365888, 1611661312, 4, 0,
  117984. _vq_quantlist__44c5_s_p7_1,
  117985. NULL,
  117986. &_vq_auxt__44c5_s_p7_1,
  117987. NULL,
  117988. 0
  117989. };
  117990. static long _vq_quantlist__44c5_s_p8_0[] = {
  117991. 6,
  117992. 5,
  117993. 7,
  117994. 4,
  117995. 8,
  117996. 3,
  117997. 9,
  117998. 2,
  117999. 10,
  118000. 1,
  118001. 11,
  118002. 0,
  118003. 12,
  118004. };
  118005. static long _vq_lengthlist__44c5_s_p8_0[] = {
  118006. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  118007. 7, 7, 8, 8, 8, 9,10,10,10,10, 7, 5, 5, 7, 7, 8,
  118008. 8, 9, 9,10,10,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  118009. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  118010. 11, 0,12,12, 9, 9, 9,10,10,10,10,10,11,11, 0,13,
  118011. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  118012. 10,10,10,10,11,11,11,11, 0, 0, 0,10,10,10,10,10,
  118013. 10,11,11,12,12, 0, 0, 0,14,14,11,11,11,11,12,12,
  118014. 12,12, 0, 0, 0,14,14,11,11,11,11,12,12,12,12, 0,
  118015. 0, 0, 0, 0,12,12,12,12,12,12,13,13, 0, 0, 0, 0,
  118016. 0,12,12,12,12,12,12,13,13,
  118017. };
  118018. static float _vq_quantthresh__44c5_s_p8_0[] = {
  118019. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118020. 12.5, 17.5, 22.5, 27.5,
  118021. };
  118022. static long _vq_quantmap__44c5_s_p8_0[] = {
  118023. 11, 9, 7, 5, 3, 1, 0, 2,
  118024. 4, 6, 8, 10, 12,
  118025. };
  118026. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_0 = {
  118027. _vq_quantthresh__44c5_s_p8_0,
  118028. _vq_quantmap__44c5_s_p8_0,
  118029. 13,
  118030. 13
  118031. };
  118032. static static_codebook _44c5_s_p8_0 = {
  118033. 2, 169,
  118034. _vq_lengthlist__44c5_s_p8_0,
  118035. 1, -526516224, 1616117760, 4, 0,
  118036. _vq_quantlist__44c5_s_p8_0,
  118037. NULL,
  118038. &_vq_auxt__44c5_s_p8_0,
  118039. NULL,
  118040. 0
  118041. };
  118042. static long _vq_quantlist__44c5_s_p8_1[] = {
  118043. 2,
  118044. 1,
  118045. 3,
  118046. 0,
  118047. 4,
  118048. };
  118049. static long _vq_lengthlist__44c5_s_p8_1[] = {
  118050. 2, 4, 4, 5, 5, 6, 5, 5, 5, 5, 6, 4, 5, 5, 5, 6,
  118051. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118052. };
  118053. static float _vq_quantthresh__44c5_s_p8_1[] = {
  118054. -1.5, -0.5, 0.5, 1.5,
  118055. };
  118056. static long _vq_quantmap__44c5_s_p8_1[] = {
  118057. 3, 1, 0, 2, 4,
  118058. };
  118059. static encode_aux_threshmatch _vq_auxt__44c5_s_p8_1 = {
  118060. _vq_quantthresh__44c5_s_p8_1,
  118061. _vq_quantmap__44c5_s_p8_1,
  118062. 5,
  118063. 5
  118064. };
  118065. static static_codebook _44c5_s_p8_1 = {
  118066. 2, 25,
  118067. _vq_lengthlist__44c5_s_p8_1,
  118068. 1, -533725184, 1611661312, 3, 0,
  118069. _vq_quantlist__44c5_s_p8_1,
  118070. NULL,
  118071. &_vq_auxt__44c5_s_p8_1,
  118072. NULL,
  118073. 0
  118074. };
  118075. static long _vq_quantlist__44c5_s_p9_0[] = {
  118076. 7,
  118077. 6,
  118078. 8,
  118079. 5,
  118080. 9,
  118081. 4,
  118082. 10,
  118083. 3,
  118084. 11,
  118085. 2,
  118086. 12,
  118087. 1,
  118088. 13,
  118089. 0,
  118090. 14,
  118091. };
  118092. static long _vq_lengthlist__44c5_s_p9_0[] = {
  118093. 1, 3, 3,13,13,13,13,13,13,13,13,13,13,13,13, 4,
  118094. 7, 7,13,13,13,13,13,13,13,13,13,13,13,13, 3, 8,
  118095. 6,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118096. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118097. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118098. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118099. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118100. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118101. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118102. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118103. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118104. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118105. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  118106. 13,13,13,13,13,13,13,13,13,12,12,12,12,12,12,12,
  118107. 12,
  118108. };
  118109. static float _vq_quantthresh__44c5_s_p9_0[] = {
  118110. -2320.5, -1963.5, -1606.5, -1249.5, -892.5, -535.5, -178.5, 178.5,
  118111. 535.5, 892.5, 1249.5, 1606.5, 1963.5, 2320.5,
  118112. };
  118113. static long _vq_quantmap__44c5_s_p9_0[] = {
  118114. 13, 11, 9, 7, 5, 3, 1, 0,
  118115. 2, 4, 6, 8, 10, 12, 14,
  118116. };
  118117. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_0 = {
  118118. _vq_quantthresh__44c5_s_p9_0,
  118119. _vq_quantmap__44c5_s_p9_0,
  118120. 15,
  118121. 15
  118122. };
  118123. static static_codebook _44c5_s_p9_0 = {
  118124. 2, 225,
  118125. _vq_lengthlist__44c5_s_p9_0,
  118126. 1, -512522752, 1628852224, 4, 0,
  118127. _vq_quantlist__44c5_s_p9_0,
  118128. NULL,
  118129. &_vq_auxt__44c5_s_p9_0,
  118130. NULL,
  118131. 0
  118132. };
  118133. static long _vq_quantlist__44c5_s_p9_1[] = {
  118134. 8,
  118135. 7,
  118136. 9,
  118137. 6,
  118138. 10,
  118139. 5,
  118140. 11,
  118141. 4,
  118142. 12,
  118143. 3,
  118144. 13,
  118145. 2,
  118146. 14,
  118147. 1,
  118148. 15,
  118149. 0,
  118150. 16,
  118151. };
  118152. static long _vq_lengthlist__44c5_s_p9_1[] = {
  118153. 1, 4, 4, 5, 5, 7, 7, 9, 8,10, 9,10,10,11,10,11,
  118154. 11, 6, 5, 5, 7, 7, 8, 9,10,10,11,10,12,11,12,11,
  118155. 13,12, 6, 5, 5, 7, 7, 9, 9,10,10,11,11,12,12,13,
  118156. 12,13,13,18, 8, 8, 8, 8, 9, 9,10,11,11,11,12,11,
  118157. 13,11,13,12,18, 8, 8, 8, 8,10,10,11,11,12,12,13,
  118158. 13,13,13,13,14,18,12,12, 9, 9,11,11,11,11,12,12,
  118159. 13,12,13,12,13,13,20,13,12, 9, 9,11,11,11,11,12,
  118160. 12,13,13,13,14,14,13,20,18,19,11,12,11,11,12,12,
  118161. 13,13,13,13,13,13,14,13,18,19,19,12,11,11,11,12,
  118162. 12,13,12,13,13,13,14,14,13,18,17,19,14,15,12,12,
  118163. 12,13,13,13,14,14,14,14,14,14,19,19,19,16,15,12,
  118164. 11,13,12,14,14,14,13,13,14,14,14,19,18,19,18,19,
  118165. 13,13,13,13,14,14,14,13,14,14,14,14,18,17,19,19,
  118166. 19,13,13,13,11,13,11,13,14,14,14,14,14,19,17,17,
  118167. 18,18,16,16,13,13,13,13,14,13,15,15,14,14,19,19,
  118168. 17,17,18,16,16,13,11,14,10,13,12,14,14,14,14,19,
  118169. 19,19,19,19,18,17,13,14,13,11,14,13,14,14,15,15,
  118170. 19,19,19,17,19,18,18,14,13,12,11,14,11,15,15,15,
  118171. 15,
  118172. };
  118173. static float _vq_quantthresh__44c5_s_p9_1[] = {
  118174. -157.5, -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5,
  118175. 10.5, 31.5, 52.5, 73.5, 94.5, 115.5, 136.5, 157.5,
  118176. };
  118177. static long _vq_quantmap__44c5_s_p9_1[] = {
  118178. 15, 13, 11, 9, 7, 5, 3, 1,
  118179. 0, 2, 4, 6, 8, 10, 12, 14,
  118180. 16,
  118181. };
  118182. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_1 = {
  118183. _vq_quantthresh__44c5_s_p9_1,
  118184. _vq_quantmap__44c5_s_p9_1,
  118185. 17,
  118186. 17
  118187. };
  118188. static static_codebook _44c5_s_p9_1 = {
  118189. 2, 289,
  118190. _vq_lengthlist__44c5_s_p9_1,
  118191. 1, -520814592, 1620377600, 5, 0,
  118192. _vq_quantlist__44c5_s_p9_1,
  118193. NULL,
  118194. &_vq_auxt__44c5_s_p9_1,
  118195. NULL,
  118196. 0
  118197. };
  118198. static long _vq_quantlist__44c5_s_p9_2[] = {
  118199. 10,
  118200. 9,
  118201. 11,
  118202. 8,
  118203. 12,
  118204. 7,
  118205. 13,
  118206. 6,
  118207. 14,
  118208. 5,
  118209. 15,
  118210. 4,
  118211. 16,
  118212. 3,
  118213. 17,
  118214. 2,
  118215. 18,
  118216. 1,
  118217. 19,
  118218. 0,
  118219. 20,
  118220. };
  118221. static long _vq_lengthlist__44c5_s_p9_2[] = {
  118222. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  118223. 8, 8, 8, 8, 9,11, 5, 6, 7, 7, 8, 7, 8, 8, 8, 8,
  118224. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11, 5, 5, 7, 7, 7,
  118225. 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  118226. 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  118227. 9,10, 9,10,11,11,11, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  118228. 9, 9, 9,10,10,10,10,10,10,11,11,11, 8, 8, 8, 8,
  118229. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,11,11,
  118230. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,
  118231. 10,10,10,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118232. 10,10,10,10,10,10,10,10,11,11,11,11,11, 9, 9, 9,
  118233. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,11,11,11,
  118234. 11,11, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,
  118235. 10,10,11,11,11,11,11, 9, 9, 9, 9, 9, 9,10,10,10,
  118236. 10,10,10,10,10,10,10,11,11,11,11,11, 9, 9,10, 9,
  118237. 10,10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,
  118238. 11,11,11, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  118239. 10,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  118240. 10,10,10,10,10,10,11,11,11,11,11,11,11,10,10,10,
  118241. 10,10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,
  118242. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118243. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118244. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118245. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118246. 11,11,11,10,10,10,10,10,10,10,10,10,10,10,10,11,
  118247. 11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,10,
  118248. 10,10,10,10,11,11,11,11,11,11,11,11,11,11,11,10,
  118249. 10,10,10,10,10,10,10,10,10,
  118250. };
  118251. static float _vq_quantthresh__44c5_s_p9_2[] = {
  118252. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118253. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118254. 6.5, 7.5, 8.5, 9.5,
  118255. };
  118256. static long _vq_quantmap__44c5_s_p9_2[] = {
  118257. 19, 17, 15, 13, 11, 9, 7, 5,
  118258. 3, 1, 0, 2, 4, 6, 8, 10,
  118259. 12, 14, 16, 18, 20,
  118260. };
  118261. static encode_aux_threshmatch _vq_auxt__44c5_s_p9_2 = {
  118262. _vq_quantthresh__44c5_s_p9_2,
  118263. _vq_quantmap__44c5_s_p9_2,
  118264. 21,
  118265. 21
  118266. };
  118267. static static_codebook _44c5_s_p9_2 = {
  118268. 2, 441,
  118269. _vq_lengthlist__44c5_s_p9_2,
  118270. 1, -529268736, 1611661312, 5, 0,
  118271. _vq_quantlist__44c5_s_p9_2,
  118272. NULL,
  118273. &_vq_auxt__44c5_s_p9_2,
  118274. NULL,
  118275. 0
  118276. };
  118277. static long _huff_lengthlist__44c5_s_short[] = {
  118278. 5, 8,10,14,11,11,12,16,15,17, 5, 5, 7, 9, 7, 8,
  118279. 10,13,17,17, 7, 5, 5,10, 5, 7, 8,11,13,15,10, 8,
  118280. 10, 8, 8, 8,11,15,18,18, 8, 5, 5, 8, 3, 4, 6,10,
  118281. 14,16, 9, 7, 6, 7, 4, 3, 5, 9,14,18,10, 9, 8,10,
  118282. 6, 5, 6, 9,14,18,12,12,11,12, 8, 7, 8,11,14,18,
  118283. 14,13,12,10, 7, 5, 6, 9,14,18,14,14,13,10, 6, 5,
  118284. 6, 8,11,16,
  118285. };
  118286. static static_codebook _huff_book__44c5_s_short = {
  118287. 2, 100,
  118288. _huff_lengthlist__44c5_s_short,
  118289. 0, 0, 0, 0, 0,
  118290. NULL,
  118291. NULL,
  118292. NULL,
  118293. NULL,
  118294. 0
  118295. };
  118296. static long _huff_lengthlist__44c6_s_long[] = {
  118297. 3, 8,11,13,14,14,13,13,16,14, 6, 3, 4, 7, 9, 9,
  118298. 10,11,14,13,10, 4, 3, 5, 7, 7, 9,10,13,15,12, 7,
  118299. 4, 4, 6, 6, 8,10,13,15,12, 8, 6, 6, 6, 6, 8,10,
  118300. 13,14,11, 9, 7, 6, 6, 6, 7, 8,12,11,13,10, 9, 8,
  118301. 7, 6, 6, 7,11,11,13,11,10, 9, 9, 7, 7, 6,10,11,
  118302. 13,13,13,13,13,11, 9, 8,10,12,12,15,15,16,15,12,
  118303. 11,10,10,12,
  118304. };
  118305. static static_codebook _huff_book__44c6_s_long = {
  118306. 2, 100,
  118307. _huff_lengthlist__44c6_s_long,
  118308. 0, 0, 0, 0, 0,
  118309. NULL,
  118310. NULL,
  118311. NULL,
  118312. NULL,
  118313. 0
  118314. };
  118315. static long _vq_quantlist__44c6_s_p1_0[] = {
  118316. 1,
  118317. 0,
  118318. 2,
  118319. };
  118320. static long _vq_lengthlist__44c6_s_p1_0[] = {
  118321. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  118322. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  118323. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  118324. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  118325. 9, 9, 0, 8, 8, 0, 8, 8, 5, 9, 9, 0, 8, 8, 0, 8,
  118326. 8,
  118327. };
  118328. static float _vq_quantthresh__44c6_s_p1_0[] = {
  118329. -0.5, 0.5,
  118330. };
  118331. static long _vq_quantmap__44c6_s_p1_0[] = {
  118332. 1, 0, 2,
  118333. };
  118334. static encode_aux_threshmatch _vq_auxt__44c6_s_p1_0 = {
  118335. _vq_quantthresh__44c6_s_p1_0,
  118336. _vq_quantmap__44c6_s_p1_0,
  118337. 3,
  118338. 3
  118339. };
  118340. static static_codebook _44c6_s_p1_0 = {
  118341. 4, 81,
  118342. _vq_lengthlist__44c6_s_p1_0,
  118343. 1, -535822336, 1611661312, 2, 0,
  118344. _vq_quantlist__44c6_s_p1_0,
  118345. NULL,
  118346. &_vq_auxt__44c6_s_p1_0,
  118347. NULL,
  118348. 0
  118349. };
  118350. static long _vq_quantlist__44c6_s_p2_0[] = {
  118351. 2,
  118352. 1,
  118353. 3,
  118354. 0,
  118355. 4,
  118356. };
  118357. static long _vq_lengthlist__44c6_s_p2_0[] = {
  118358. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  118359. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  118360. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  118361. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  118362. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,11,
  118363. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  118364. 0, 0,14,13, 8, 9, 9,11,11, 0,11,11,12,12, 0,10,
  118365. 11,12,12, 0,14,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  118366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118367. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  118368. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  118369. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  118370. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  118371. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  118372. 13, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,12,12,
  118373. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  118374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118375. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  118376. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,11,
  118377. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,11,
  118378. 0, 0, 0,10,11, 8,10,10,12,12, 0,10,10,12,12, 0,
  118379. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,14,13, 8,10,
  118380. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  118381. 13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118383. 7,10,10,14,13, 0, 9, 9,13,12, 0, 9, 9,12,12, 0,
  118384. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  118385. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  118386. 12,12, 9,11,11,14,13, 0,11,10,14,13, 0,11,11,13,
  118387. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  118388. 0,10,11,13,14, 0,11,11,13,13, 0,12,12,13,13, 0,
  118389. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  118394. 11,11,14,14, 0,11,11,13,13, 0,11,10,13,13, 0,12,
  118395. 12,13,13, 0, 0, 0,13,13, 9,11,11,14,14, 0,11,11,
  118396. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  118397. 13,
  118398. };
  118399. static float _vq_quantthresh__44c6_s_p2_0[] = {
  118400. -1.5, -0.5, 0.5, 1.5,
  118401. };
  118402. static long _vq_quantmap__44c6_s_p2_0[] = {
  118403. 3, 1, 0, 2, 4,
  118404. };
  118405. static encode_aux_threshmatch _vq_auxt__44c6_s_p2_0 = {
  118406. _vq_quantthresh__44c6_s_p2_0,
  118407. _vq_quantmap__44c6_s_p2_0,
  118408. 5,
  118409. 5
  118410. };
  118411. static static_codebook _44c6_s_p2_0 = {
  118412. 4, 625,
  118413. _vq_lengthlist__44c6_s_p2_0,
  118414. 1, -533725184, 1611661312, 3, 0,
  118415. _vq_quantlist__44c6_s_p2_0,
  118416. NULL,
  118417. &_vq_auxt__44c6_s_p2_0,
  118418. NULL,
  118419. 0
  118420. };
  118421. static long _vq_quantlist__44c6_s_p3_0[] = {
  118422. 4,
  118423. 3,
  118424. 5,
  118425. 2,
  118426. 6,
  118427. 1,
  118428. 7,
  118429. 0,
  118430. 8,
  118431. };
  118432. static long _vq_lengthlist__44c6_s_p3_0[] = {
  118433. 2, 3, 4, 6, 6, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  118434. 9,10, 0, 4, 4, 6, 6, 7, 7,10, 9, 0, 5, 5, 7, 7,
  118435. 8, 8,10,10, 0, 0, 0, 7, 6, 8, 8,10,10, 0, 0, 0,
  118436. 7, 7, 9, 9,11,11, 0, 0, 0, 7, 7, 9, 9,11,11, 0,
  118437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118438. 0,
  118439. };
  118440. static float _vq_quantthresh__44c6_s_p3_0[] = {
  118441. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  118442. };
  118443. static long _vq_quantmap__44c6_s_p3_0[] = {
  118444. 7, 5, 3, 1, 0, 2, 4, 6,
  118445. 8,
  118446. };
  118447. static encode_aux_threshmatch _vq_auxt__44c6_s_p3_0 = {
  118448. _vq_quantthresh__44c6_s_p3_0,
  118449. _vq_quantmap__44c6_s_p3_0,
  118450. 9,
  118451. 9
  118452. };
  118453. static static_codebook _44c6_s_p3_0 = {
  118454. 2, 81,
  118455. _vq_lengthlist__44c6_s_p3_0,
  118456. 1, -531628032, 1611661312, 4, 0,
  118457. _vq_quantlist__44c6_s_p3_0,
  118458. NULL,
  118459. &_vq_auxt__44c6_s_p3_0,
  118460. NULL,
  118461. 0
  118462. };
  118463. static long _vq_quantlist__44c6_s_p4_0[] = {
  118464. 8,
  118465. 7,
  118466. 9,
  118467. 6,
  118468. 10,
  118469. 5,
  118470. 11,
  118471. 4,
  118472. 12,
  118473. 3,
  118474. 13,
  118475. 2,
  118476. 14,
  118477. 1,
  118478. 15,
  118479. 0,
  118480. 16,
  118481. };
  118482. static long _vq_lengthlist__44c6_s_p4_0[] = {
  118483. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,10,10,
  118484. 10, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  118485. 11,11, 0, 4, 4, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  118486. 10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  118487. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  118488. 10,11,11,11,11, 0, 0, 0, 7, 7, 9, 9,10,10,10,10,
  118489. 11,11,11,11,12,12, 0, 0, 0, 7, 7, 9, 9,10,10,10,
  118490. 10,11,11,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  118491. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 8, 8, 9,
  118492. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  118493. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118494. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118495. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118496. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118497. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118498. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118499. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118500. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118501. 0,
  118502. };
  118503. static float _vq_quantthresh__44c6_s_p4_0[] = {
  118504. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  118505. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  118506. };
  118507. static long _vq_quantmap__44c6_s_p4_0[] = {
  118508. 15, 13, 11, 9, 7, 5, 3, 1,
  118509. 0, 2, 4, 6, 8, 10, 12, 14,
  118510. 16,
  118511. };
  118512. static encode_aux_threshmatch _vq_auxt__44c6_s_p4_0 = {
  118513. _vq_quantthresh__44c6_s_p4_0,
  118514. _vq_quantmap__44c6_s_p4_0,
  118515. 17,
  118516. 17
  118517. };
  118518. static static_codebook _44c6_s_p4_0 = {
  118519. 2, 289,
  118520. _vq_lengthlist__44c6_s_p4_0,
  118521. 1, -529530880, 1611661312, 5, 0,
  118522. _vq_quantlist__44c6_s_p4_0,
  118523. NULL,
  118524. &_vq_auxt__44c6_s_p4_0,
  118525. NULL,
  118526. 0
  118527. };
  118528. static long _vq_quantlist__44c6_s_p5_0[] = {
  118529. 1,
  118530. 0,
  118531. 2,
  118532. };
  118533. static long _vq_lengthlist__44c6_s_p5_0[] = {
  118534. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 6, 9, 9,10,10,
  118535. 10, 9, 4, 6, 6, 9,10, 9,10, 9,10, 6, 9, 9,10,12,
  118536. 11,10,11,11, 7,10, 9,11,12,12,12,12,12, 7,10,10,
  118537. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  118538. 9,10,11,12,12,12,12,12, 7,10, 9,12,12,12,12,12,
  118539. 12,
  118540. };
  118541. static float _vq_quantthresh__44c6_s_p5_0[] = {
  118542. -5.5, 5.5,
  118543. };
  118544. static long _vq_quantmap__44c6_s_p5_0[] = {
  118545. 1, 0, 2,
  118546. };
  118547. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_0 = {
  118548. _vq_quantthresh__44c6_s_p5_0,
  118549. _vq_quantmap__44c6_s_p5_0,
  118550. 3,
  118551. 3
  118552. };
  118553. static static_codebook _44c6_s_p5_0 = {
  118554. 4, 81,
  118555. _vq_lengthlist__44c6_s_p5_0,
  118556. 1, -529137664, 1618345984, 2, 0,
  118557. _vq_quantlist__44c6_s_p5_0,
  118558. NULL,
  118559. &_vq_auxt__44c6_s_p5_0,
  118560. NULL,
  118561. 0
  118562. };
  118563. static long _vq_quantlist__44c6_s_p5_1[] = {
  118564. 5,
  118565. 4,
  118566. 6,
  118567. 3,
  118568. 7,
  118569. 2,
  118570. 8,
  118571. 1,
  118572. 9,
  118573. 0,
  118574. 10,
  118575. };
  118576. static long _vq_lengthlist__44c6_s_p5_1[] = {
  118577. 3, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  118578. 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6, 7, 7, 8, 8, 8,
  118579. 8,11, 6, 6, 6, 6, 8, 8, 8, 8, 9, 9,11,11,11, 6,
  118580. 6, 7, 8, 8, 8, 8, 9,11,11,11, 7, 7, 8, 8, 8, 8,
  118581. 8, 8,11,11,11, 7, 7, 8, 8, 8, 8, 8, 8,11,11,11,
  118582. 8, 8, 8, 8, 8, 8, 8, 8,11,11,11,10,10, 8, 8, 8,
  118583. 8, 8, 8,11,11,11,10,10, 8, 8, 8, 8, 8, 8,11,11,
  118584. 11,10,10, 7, 7, 8, 8, 8, 8,
  118585. };
  118586. static float _vq_quantthresh__44c6_s_p5_1[] = {
  118587. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118588. 3.5, 4.5,
  118589. };
  118590. static long _vq_quantmap__44c6_s_p5_1[] = {
  118591. 9, 7, 5, 3, 1, 0, 2, 4,
  118592. 6, 8, 10,
  118593. };
  118594. static encode_aux_threshmatch _vq_auxt__44c6_s_p5_1 = {
  118595. _vq_quantthresh__44c6_s_p5_1,
  118596. _vq_quantmap__44c6_s_p5_1,
  118597. 11,
  118598. 11
  118599. };
  118600. static static_codebook _44c6_s_p5_1 = {
  118601. 2, 121,
  118602. _vq_lengthlist__44c6_s_p5_1,
  118603. 1, -531365888, 1611661312, 4, 0,
  118604. _vq_quantlist__44c6_s_p5_1,
  118605. NULL,
  118606. &_vq_auxt__44c6_s_p5_1,
  118607. NULL,
  118608. 0
  118609. };
  118610. static long _vq_quantlist__44c6_s_p6_0[] = {
  118611. 6,
  118612. 5,
  118613. 7,
  118614. 4,
  118615. 8,
  118616. 3,
  118617. 9,
  118618. 2,
  118619. 10,
  118620. 1,
  118621. 11,
  118622. 0,
  118623. 12,
  118624. };
  118625. static long _vq_lengthlist__44c6_s_p6_0[] = {
  118626. 1, 4, 4, 6, 6, 8, 8, 8, 8,10, 9,10,10, 6, 5, 5,
  118627. 7, 7, 9, 9, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 9,
  118628. 9,10, 9,11,10,11,11, 0, 6, 6, 7, 7, 9, 9,10,10,
  118629. 11,11,12,12, 0, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118630. 12, 0,11,11, 8, 8,10,10,11,11,12,12,12,12, 0,11,
  118631. 12, 9, 8,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  118632. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118633. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118634. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118635. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118636. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  118637. };
  118638. static float _vq_quantthresh__44c6_s_p6_0[] = {
  118639. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  118640. 12.5, 17.5, 22.5, 27.5,
  118641. };
  118642. static long _vq_quantmap__44c6_s_p6_0[] = {
  118643. 11, 9, 7, 5, 3, 1, 0, 2,
  118644. 4, 6, 8, 10, 12,
  118645. };
  118646. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_0 = {
  118647. _vq_quantthresh__44c6_s_p6_0,
  118648. _vq_quantmap__44c6_s_p6_0,
  118649. 13,
  118650. 13
  118651. };
  118652. static static_codebook _44c6_s_p6_0 = {
  118653. 2, 169,
  118654. _vq_lengthlist__44c6_s_p6_0,
  118655. 1, -526516224, 1616117760, 4, 0,
  118656. _vq_quantlist__44c6_s_p6_0,
  118657. NULL,
  118658. &_vq_auxt__44c6_s_p6_0,
  118659. NULL,
  118660. 0
  118661. };
  118662. static long _vq_quantlist__44c6_s_p6_1[] = {
  118663. 2,
  118664. 1,
  118665. 3,
  118666. 0,
  118667. 4,
  118668. };
  118669. static long _vq_lengthlist__44c6_s_p6_1[] = {
  118670. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  118671. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  118672. };
  118673. static float _vq_quantthresh__44c6_s_p6_1[] = {
  118674. -1.5, -0.5, 0.5, 1.5,
  118675. };
  118676. static long _vq_quantmap__44c6_s_p6_1[] = {
  118677. 3, 1, 0, 2, 4,
  118678. };
  118679. static encode_aux_threshmatch _vq_auxt__44c6_s_p6_1 = {
  118680. _vq_quantthresh__44c6_s_p6_1,
  118681. _vq_quantmap__44c6_s_p6_1,
  118682. 5,
  118683. 5
  118684. };
  118685. static static_codebook _44c6_s_p6_1 = {
  118686. 2, 25,
  118687. _vq_lengthlist__44c6_s_p6_1,
  118688. 1, -533725184, 1611661312, 3, 0,
  118689. _vq_quantlist__44c6_s_p6_1,
  118690. NULL,
  118691. &_vq_auxt__44c6_s_p6_1,
  118692. NULL,
  118693. 0
  118694. };
  118695. static long _vq_quantlist__44c6_s_p7_0[] = {
  118696. 6,
  118697. 5,
  118698. 7,
  118699. 4,
  118700. 8,
  118701. 3,
  118702. 9,
  118703. 2,
  118704. 10,
  118705. 1,
  118706. 11,
  118707. 0,
  118708. 12,
  118709. };
  118710. static long _vq_lengthlist__44c6_s_p7_0[] = {
  118711. 1, 4, 4, 6, 6, 8, 8, 8, 8,10,10,11,10, 6, 5, 5,
  118712. 7, 7, 8, 8, 9, 9,10,10,12,11, 6, 5, 5, 7, 7, 8,
  118713. 8, 9, 9,10,10,12,11,21, 7, 7, 7, 7, 9, 9,10,10,
  118714. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,11,11,12,
  118715. 12,21,12,12, 9, 9,10,10,11,11,11,11,12,12,21,12,
  118716. 12, 9, 9,10,10,11,11,12,12,12,12,21,21,21,11,11,
  118717. 10,10,11,12,12,12,13,13,21,21,21,11,11,10,10,12,
  118718. 12,12,12,13,13,21,21,21,15,15,11,11,12,12,13,13,
  118719. 13,13,21,21,21,15,16,11,11,12,12,13,13,14,14,21,
  118720. 21,21,21,20,13,13,13,13,13,13,14,14,20,20,20,20,
  118721. 20,13,13,13,13,13,13,14,14,
  118722. };
  118723. static float _vq_quantthresh__44c6_s_p7_0[] = {
  118724. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  118725. 27.5, 38.5, 49.5, 60.5,
  118726. };
  118727. static long _vq_quantmap__44c6_s_p7_0[] = {
  118728. 11, 9, 7, 5, 3, 1, 0, 2,
  118729. 4, 6, 8, 10, 12,
  118730. };
  118731. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_0 = {
  118732. _vq_quantthresh__44c6_s_p7_0,
  118733. _vq_quantmap__44c6_s_p7_0,
  118734. 13,
  118735. 13
  118736. };
  118737. static static_codebook _44c6_s_p7_0 = {
  118738. 2, 169,
  118739. _vq_lengthlist__44c6_s_p7_0,
  118740. 1, -523206656, 1618345984, 4, 0,
  118741. _vq_quantlist__44c6_s_p7_0,
  118742. NULL,
  118743. &_vq_auxt__44c6_s_p7_0,
  118744. NULL,
  118745. 0
  118746. };
  118747. static long _vq_quantlist__44c6_s_p7_1[] = {
  118748. 5,
  118749. 4,
  118750. 6,
  118751. 3,
  118752. 7,
  118753. 2,
  118754. 8,
  118755. 1,
  118756. 9,
  118757. 0,
  118758. 10,
  118759. };
  118760. static long _vq_lengthlist__44c6_s_p7_1[] = {
  118761. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 9, 5, 5, 6, 6,
  118762. 7, 7, 7, 7, 8, 7, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7,
  118763. 7, 9, 6, 6, 7, 7, 7, 7, 8, 7, 7, 8, 9, 9, 9, 7,
  118764. 7, 7, 7, 7, 7, 7, 8, 9, 9, 9, 7, 7, 7, 7, 8, 8,
  118765. 8, 8, 9, 9, 9, 7, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  118766. 8, 8, 8, 8, 7, 7, 8, 8, 9, 9, 9, 9, 8, 8, 8, 7,
  118767. 7, 8, 8, 9, 9, 9, 8, 8, 8, 8, 7, 7, 8, 8, 9, 9,
  118768. 9, 8, 8, 7, 7, 7, 7, 8, 8,
  118769. };
  118770. static float _vq_quantthresh__44c6_s_p7_1[] = {
  118771. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  118772. 3.5, 4.5,
  118773. };
  118774. static long _vq_quantmap__44c6_s_p7_1[] = {
  118775. 9, 7, 5, 3, 1, 0, 2, 4,
  118776. 6, 8, 10,
  118777. };
  118778. static encode_aux_threshmatch _vq_auxt__44c6_s_p7_1 = {
  118779. _vq_quantthresh__44c6_s_p7_1,
  118780. _vq_quantmap__44c6_s_p7_1,
  118781. 11,
  118782. 11
  118783. };
  118784. static static_codebook _44c6_s_p7_1 = {
  118785. 2, 121,
  118786. _vq_lengthlist__44c6_s_p7_1,
  118787. 1, -531365888, 1611661312, 4, 0,
  118788. _vq_quantlist__44c6_s_p7_1,
  118789. NULL,
  118790. &_vq_auxt__44c6_s_p7_1,
  118791. NULL,
  118792. 0
  118793. };
  118794. static long _vq_quantlist__44c6_s_p8_0[] = {
  118795. 7,
  118796. 6,
  118797. 8,
  118798. 5,
  118799. 9,
  118800. 4,
  118801. 10,
  118802. 3,
  118803. 11,
  118804. 2,
  118805. 12,
  118806. 1,
  118807. 13,
  118808. 0,
  118809. 14,
  118810. };
  118811. static long _vq_lengthlist__44c6_s_p8_0[] = {
  118812. 1, 4, 4, 7, 7, 8, 8, 7, 7, 8, 7, 9, 8,10, 9, 6,
  118813. 5, 5, 8, 8, 9, 9, 8, 8, 9, 9,11,10,11,10, 6, 5,
  118814. 5, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,11,18, 8, 8,
  118815. 9, 8,10,10, 9, 9,10,10,10,10,11,10,18, 8, 8, 9,
  118816. 9,10,10, 9, 9,10,10,11,11,12,12,18,12,13, 9,10,
  118817. 10,10, 9,10,10,10,11,11,12,11,18,13,13, 9, 9,10,
  118818. 10,10,10,10,10,11,11,12,12,18,18,18,10,10, 9, 9,
  118819. 11,11,11,11,11,12,12,12,18,18,18,10, 9,10, 9,11,
  118820. 10,11,11,11,11,13,12,18,18,18,14,13,10,10,11,11,
  118821. 12,12,12,12,12,12,18,18,18,14,13,10,10,11,10,12,
  118822. 12,12,12,12,12,18,18,18,18,18,12,12,11,11,12,12,
  118823. 13,13,13,14,18,18,18,18,18,12,12,11,11,12,11,13,
  118824. 13,14,13,18,18,18,18,18,16,16,11,12,12,13,13,13,
  118825. 14,13,18,18,18,18,18,16,15,12,11,12,11,13,11,15,
  118826. 14,
  118827. };
  118828. static float _vq_quantthresh__44c6_s_p8_0[] = {
  118829. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  118830. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  118831. };
  118832. static long _vq_quantmap__44c6_s_p8_0[] = {
  118833. 13, 11, 9, 7, 5, 3, 1, 0,
  118834. 2, 4, 6, 8, 10, 12, 14,
  118835. };
  118836. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_0 = {
  118837. _vq_quantthresh__44c6_s_p8_0,
  118838. _vq_quantmap__44c6_s_p8_0,
  118839. 15,
  118840. 15
  118841. };
  118842. static static_codebook _44c6_s_p8_0 = {
  118843. 2, 225,
  118844. _vq_lengthlist__44c6_s_p8_0,
  118845. 1, -520986624, 1620377600, 4, 0,
  118846. _vq_quantlist__44c6_s_p8_0,
  118847. NULL,
  118848. &_vq_auxt__44c6_s_p8_0,
  118849. NULL,
  118850. 0
  118851. };
  118852. static long _vq_quantlist__44c6_s_p8_1[] = {
  118853. 10,
  118854. 9,
  118855. 11,
  118856. 8,
  118857. 12,
  118858. 7,
  118859. 13,
  118860. 6,
  118861. 14,
  118862. 5,
  118863. 15,
  118864. 4,
  118865. 16,
  118866. 3,
  118867. 17,
  118868. 2,
  118869. 18,
  118870. 1,
  118871. 19,
  118872. 0,
  118873. 20,
  118874. };
  118875. static long _vq_lengthlist__44c6_s_p8_1[] = {
  118876. 3, 5, 5, 6, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 8,
  118877. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8,
  118878. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  118879. 8, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10,
  118880. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118881. 9, 9, 9, 9,10,11,11, 8, 7, 8, 8, 8, 9, 9, 9, 9,
  118882. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11, 8, 8, 8, 8,
  118883. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,
  118884. 11, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118885. 9, 9, 9,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  118886. 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9, 9,
  118887. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,
  118888. 11,11, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9,10, 9, 9,
  118889. 10, 9,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,10,10,
  118890. 10,10, 9,10,10, 9,10,11,11,11,11,11, 9, 9, 9, 9,
  118891. 10,10,10, 9,10,10,10,10, 9,10,10, 9,11,11,11,11,
  118892. 11,11,11, 9, 9, 9, 9,10,10,10,10, 9,10,10,10,10,
  118893. 10,11,11,11,11,11,11,11,10, 9,10,10,10,10,10,10,
  118894. 10, 9,10, 9,10,10,11,11,11,11,11,11,11,10, 9,10,
  118895. 9,10,10, 9,10,10,10,10,10,10,10,11,11,11,11,11,
  118896. 11,11,10,10,10,10,10,10,10, 9,10,10,10,10,10, 9,
  118897. 11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,10,
  118898. 10,10,10,10,10,11,11,11,11,11,11,11,11,11,10,10,
  118899. 10,10,10,10,10,10,10,10,10,10,11,11,11,11,11,11,
  118900. 11,11,11,10,10,10,10,10,10,10,10,10, 9,10,10,11,
  118901. 11,11,11,11,11,11,11,11,10,10,10, 9,10,10,10,10,
  118902. 10,10,10,10,10,11,11,11,11,11,11,11,11,10,11, 9,
  118903. 10,10,10,10,10,10,10,10,10,
  118904. };
  118905. static float _vq_quantthresh__44c6_s_p8_1[] = {
  118906. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  118907. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  118908. 6.5, 7.5, 8.5, 9.5,
  118909. };
  118910. static long _vq_quantmap__44c6_s_p8_1[] = {
  118911. 19, 17, 15, 13, 11, 9, 7, 5,
  118912. 3, 1, 0, 2, 4, 6, 8, 10,
  118913. 12, 14, 16, 18, 20,
  118914. };
  118915. static encode_aux_threshmatch _vq_auxt__44c6_s_p8_1 = {
  118916. _vq_quantthresh__44c6_s_p8_1,
  118917. _vq_quantmap__44c6_s_p8_1,
  118918. 21,
  118919. 21
  118920. };
  118921. static static_codebook _44c6_s_p8_1 = {
  118922. 2, 441,
  118923. _vq_lengthlist__44c6_s_p8_1,
  118924. 1, -529268736, 1611661312, 5, 0,
  118925. _vq_quantlist__44c6_s_p8_1,
  118926. NULL,
  118927. &_vq_auxt__44c6_s_p8_1,
  118928. NULL,
  118929. 0
  118930. };
  118931. static long _vq_quantlist__44c6_s_p9_0[] = {
  118932. 6,
  118933. 5,
  118934. 7,
  118935. 4,
  118936. 8,
  118937. 3,
  118938. 9,
  118939. 2,
  118940. 10,
  118941. 1,
  118942. 11,
  118943. 0,
  118944. 12,
  118945. };
  118946. static long _vq_lengthlist__44c6_s_p9_0[] = {
  118947. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 7, 7,
  118948. 11,11,11,11,11,11,11,11,11,11, 5, 8, 9,11,11,11,
  118949. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  118950. 11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,10,
  118951. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118952. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118953. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118954. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118955. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118956. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  118957. 10,10,10,10,10,10,10,10,10,
  118958. };
  118959. static float _vq_quantthresh__44c6_s_p9_0[] = {
  118960. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  118961. 1592.5, 2229.5, 2866.5, 3503.5,
  118962. };
  118963. static long _vq_quantmap__44c6_s_p9_0[] = {
  118964. 11, 9, 7, 5, 3, 1, 0, 2,
  118965. 4, 6, 8, 10, 12,
  118966. };
  118967. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_0 = {
  118968. _vq_quantthresh__44c6_s_p9_0,
  118969. _vq_quantmap__44c6_s_p9_0,
  118970. 13,
  118971. 13
  118972. };
  118973. static static_codebook _44c6_s_p9_0 = {
  118974. 2, 169,
  118975. _vq_lengthlist__44c6_s_p9_0,
  118976. 1, -511845376, 1630791680, 4, 0,
  118977. _vq_quantlist__44c6_s_p9_0,
  118978. NULL,
  118979. &_vq_auxt__44c6_s_p9_0,
  118980. NULL,
  118981. 0
  118982. };
  118983. static long _vq_quantlist__44c6_s_p9_1[] = {
  118984. 6,
  118985. 5,
  118986. 7,
  118987. 4,
  118988. 8,
  118989. 3,
  118990. 9,
  118991. 2,
  118992. 10,
  118993. 1,
  118994. 11,
  118995. 0,
  118996. 12,
  118997. };
  118998. static long _vq_lengthlist__44c6_s_p9_1[] = {
  118999. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119000. 8, 8, 8, 8, 8, 7, 9, 8,10,10, 5, 6, 6, 8, 8, 9,
  119001. 9, 8, 8,10,10,10,10,16, 9, 9, 9, 9, 9, 9, 9, 8,
  119002. 10, 9,11,11,16, 8, 9, 9, 9, 9, 9, 9, 9,10,10,11,
  119003. 11,16,13,13, 9, 9,10, 9, 9,10,11,11,11,12,16,13,
  119004. 14, 9, 8,10, 8, 9, 9,10,10,12,11,16,14,16, 9, 9,
  119005. 9, 9,11,11,12,11,12,11,16,16,16, 9, 7, 9, 6,11,
  119006. 11,11,10,11,11,16,16,16,11,12, 9,10,11,11,12,11,
  119007. 13,13,16,16,16,12,11,10, 7,12,10,12,12,12,12,16,
  119008. 16,15,16,16,10,11,10,11,13,13,14,12,16,16,16,15,
  119009. 15,12,10,11,11,13,11,12,13,
  119010. };
  119011. static float _vq_quantthresh__44c6_s_p9_1[] = {
  119012. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119013. 122.5, 171.5, 220.5, 269.5,
  119014. };
  119015. static long _vq_quantmap__44c6_s_p9_1[] = {
  119016. 11, 9, 7, 5, 3, 1, 0, 2,
  119017. 4, 6, 8, 10, 12,
  119018. };
  119019. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_1 = {
  119020. _vq_quantthresh__44c6_s_p9_1,
  119021. _vq_quantmap__44c6_s_p9_1,
  119022. 13,
  119023. 13
  119024. };
  119025. static static_codebook _44c6_s_p9_1 = {
  119026. 2, 169,
  119027. _vq_lengthlist__44c6_s_p9_1,
  119028. 1, -518889472, 1622704128, 4, 0,
  119029. _vq_quantlist__44c6_s_p9_1,
  119030. NULL,
  119031. &_vq_auxt__44c6_s_p9_1,
  119032. NULL,
  119033. 0
  119034. };
  119035. static long _vq_quantlist__44c6_s_p9_2[] = {
  119036. 24,
  119037. 23,
  119038. 25,
  119039. 22,
  119040. 26,
  119041. 21,
  119042. 27,
  119043. 20,
  119044. 28,
  119045. 19,
  119046. 29,
  119047. 18,
  119048. 30,
  119049. 17,
  119050. 31,
  119051. 16,
  119052. 32,
  119053. 15,
  119054. 33,
  119055. 14,
  119056. 34,
  119057. 13,
  119058. 35,
  119059. 12,
  119060. 36,
  119061. 11,
  119062. 37,
  119063. 10,
  119064. 38,
  119065. 9,
  119066. 39,
  119067. 8,
  119068. 40,
  119069. 7,
  119070. 41,
  119071. 6,
  119072. 42,
  119073. 5,
  119074. 43,
  119075. 4,
  119076. 44,
  119077. 3,
  119078. 45,
  119079. 2,
  119080. 46,
  119081. 1,
  119082. 47,
  119083. 0,
  119084. 48,
  119085. };
  119086. static long _vq_lengthlist__44c6_s_p9_2[] = {
  119087. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119088. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119089. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119090. 7,
  119091. };
  119092. static float _vq_quantthresh__44c6_s_p9_2[] = {
  119093. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119094. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119095. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119096. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119097. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119098. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119099. };
  119100. static long _vq_quantmap__44c6_s_p9_2[] = {
  119101. 47, 45, 43, 41, 39, 37, 35, 33,
  119102. 31, 29, 27, 25, 23, 21, 19, 17,
  119103. 15, 13, 11, 9, 7, 5, 3, 1,
  119104. 0, 2, 4, 6, 8, 10, 12, 14,
  119105. 16, 18, 20, 22, 24, 26, 28, 30,
  119106. 32, 34, 36, 38, 40, 42, 44, 46,
  119107. 48,
  119108. };
  119109. static encode_aux_threshmatch _vq_auxt__44c6_s_p9_2 = {
  119110. _vq_quantthresh__44c6_s_p9_2,
  119111. _vq_quantmap__44c6_s_p9_2,
  119112. 49,
  119113. 49
  119114. };
  119115. static static_codebook _44c6_s_p9_2 = {
  119116. 1, 49,
  119117. _vq_lengthlist__44c6_s_p9_2,
  119118. 1, -526909440, 1611661312, 6, 0,
  119119. _vq_quantlist__44c6_s_p9_2,
  119120. NULL,
  119121. &_vq_auxt__44c6_s_p9_2,
  119122. NULL,
  119123. 0
  119124. };
  119125. static long _huff_lengthlist__44c6_s_short[] = {
  119126. 3, 9,11,11,13,14,19,17,17,19, 5, 4, 5, 8,10,10,
  119127. 13,16,18,19, 7, 4, 4, 5, 8, 9,12,14,17,19, 8, 6,
  119128. 5, 5, 7, 7,10,13,16,18,10, 8, 7, 6, 5, 5, 8,11,
  119129. 17,19,11, 9, 7, 7, 5, 4, 5, 8,17,19,13,11, 8, 7,
  119130. 7, 5, 5, 7,16,18,14,13, 8, 6, 6, 5, 5, 7,16,18,
  119131. 18,16,10, 8, 8, 7, 7, 9,16,18,18,18,12,10,10, 9,
  119132. 9,10,17,18,
  119133. };
  119134. static static_codebook _huff_book__44c6_s_short = {
  119135. 2, 100,
  119136. _huff_lengthlist__44c6_s_short,
  119137. 0, 0, 0, 0, 0,
  119138. NULL,
  119139. NULL,
  119140. NULL,
  119141. NULL,
  119142. 0
  119143. };
  119144. static long _huff_lengthlist__44c7_s_long[] = {
  119145. 3, 8,11,13,15,14,14,13,15,14, 6, 4, 5, 7, 9,10,
  119146. 11,11,14,13,10, 4, 3, 5, 7, 8, 9,10,13,13,12, 7,
  119147. 4, 4, 5, 6, 8, 9,12,14,13, 9, 6, 5, 5, 6, 8, 9,
  119148. 12,14,12, 9, 7, 6, 5, 5, 6, 8,11,11,12,11, 9, 8,
  119149. 7, 6, 6, 7,10,11,13,11,10, 9, 8, 7, 6, 6, 9,11,
  119150. 13,13,12,12,12,10, 9, 8, 9,11,12,14,15,15,14,12,
  119151. 11,10,10,12,
  119152. };
  119153. static static_codebook _huff_book__44c7_s_long = {
  119154. 2, 100,
  119155. _huff_lengthlist__44c7_s_long,
  119156. 0, 0, 0, 0, 0,
  119157. NULL,
  119158. NULL,
  119159. NULL,
  119160. NULL,
  119161. 0
  119162. };
  119163. static long _vq_quantlist__44c7_s_p1_0[] = {
  119164. 1,
  119165. 0,
  119166. 2,
  119167. };
  119168. static long _vq_lengthlist__44c7_s_p1_0[] = {
  119169. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 8, 7, 0, 9, 9, 0,
  119170. 9, 8, 5, 7, 8, 0, 9, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  119171. 0, 0, 0, 0, 5, 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  119172. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  119173. 9, 9, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  119174. 8,
  119175. };
  119176. static float _vq_quantthresh__44c7_s_p1_0[] = {
  119177. -0.5, 0.5,
  119178. };
  119179. static long _vq_quantmap__44c7_s_p1_0[] = {
  119180. 1, 0, 2,
  119181. };
  119182. static encode_aux_threshmatch _vq_auxt__44c7_s_p1_0 = {
  119183. _vq_quantthresh__44c7_s_p1_0,
  119184. _vq_quantmap__44c7_s_p1_0,
  119185. 3,
  119186. 3
  119187. };
  119188. static static_codebook _44c7_s_p1_0 = {
  119189. 4, 81,
  119190. _vq_lengthlist__44c7_s_p1_0,
  119191. 1, -535822336, 1611661312, 2, 0,
  119192. _vq_quantlist__44c7_s_p1_0,
  119193. NULL,
  119194. &_vq_auxt__44c7_s_p1_0,
  119195. NULL,
  119196. 0
  119197. };
  119198. static long _vq_quantlist__44c7_s_p2_0[] = {
  119199. 2,
  119200. 1,
  119201. 3,
  119202. 0,
  119203. 4,
  119204. };
  119205. static long _vq_lengthlist__44c7_s_p2_0[] = {
  119206. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  119207. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  119208. 8,10,10, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  119209. 11,11, 5, 7, 7, 9, 9, 0, 8, 8,10,10, 0, 7, 8, 9,
  119210. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  119211. 0,11,11,12,12, 0,11,10,12,12, 0,13,14,14,14, 0,
  119212. 0, 0,14,13, 8, 9, 9,10,11, 0,11,11,12,12, 0,10,
  119213. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  119214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119215. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  119216. 0, 7, 7,10,10, 0, 9, 9,11,10, 0, 0, 0,11,11, 5,
  119217. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  119218. 9,10,11, 0, 0, 0,11,11, 8,10, 9,12,12, 0,10,10,
  119219. 12,12, 0,10,10,12,12, 0,12,12,13,13, 0, 0, 0,13,
  119220. 13, 8, 9,10,12,12, 0,10,10,12,12, 0,10,10,11,12,
  119221. 0,12,12,13,13, 0, 0, 0,13,13, 0, 0, 0, 0, 0, 0,
  119222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119223. 0, 0, 0, 5, 8, 8,11,11, 0, 7, 7,10,10, 0, 7, 7,
  119224. 10,10, 0, 9, 9,10,11, 0, 0, 0,11,10, 5, 8, 8,10,
  119225. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,11,10,
  119226. 0, 0, 0,10,11, 9,10,10,12,12, 0,10,10,12,12, 0,
  119227. 10,10,12,12, 0,12,13,13,13, 0, 0, 0,13,12, 9,10,
  119228. 10,12,12, 0,10,10,12,12, 0,10,10,12,12, 0,13,12,
  119229. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119231. 7,10,10,14,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  119232. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,14, 0, 9,
  119233. 9,12,13, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  119234. 12,12, 9,11,11,14,13, 0,11,10,13,12, 0,11,11,13,
  119235. 13, 0,12,12,13,13, 0, 0, 0,13,13, 9,11,11,13,14,
  119236. 0,10,11,12,13, 0,11,11,13,13, 0,12,12,13,13, 0,
  119237. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  119242. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,12,
  119243. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  119244. 13,13, 0,10,11,13,13, 0,12,12,14,13, 0, 0, 0,13,
  119245. 13,
  119246. };
  119247. static float _vq_quantthresh__44c7_s_p2_0[] = {
  119248. -1.5, -0.5, 0.5, 1.5,
  119249. };
  119250. static long _vq_quantmap__44c7_s_p2_0[] = {
  119251. 3, 1, 0, 2, 4,
  119252. };
  119253. static encode_aux_threshmatch _vq_auxt__44c7_s_p2_0 = {
  119254. _vq_quantthresh__44c7_s_p2_0,
  119255. _vq_quantmap__44c7_s_p2_0,
  119256. 5,
  119257. 5
  119258. };
  119259. static static_codebook _44c7_s_p2_0 = {
  119260. 4, 625,
  119261. _vq_lengthlist__44c7_s_p2_0,
  119262. 1, -533725184, 1611661312, 3, 0,
  119263. _vq_quantlist__44c7_s_p2_0,
  119264. NULL,
  119265. &_vq_auxt__44c7_s_p2_0,
  119266. NULL,
  119267. 0
  119268. };
  119269. static long _vq_quantlist__44c7_s_p3_0[] = {
  119270. 4,
  119271. 3,
  119272. 5,
  119273. 2,
  119274. 6,
  119275. 1,
  119276. 7,
  119277. 0,
  119278. 8,
  119279. };
  119280. static long _vq_lengthlist__44c7_s_p3_0[] = {
  119281. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  119282. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  119283. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  119284. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  119285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119286. 0,
  119287. };
  119288. static float _vq_quantthresh__44c7_s_p3_0[] = {
  119289. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  119290. };
  119291. static long _vq_quantmap__44c7_s_p3_0[] = {
  119292. 7, 5, 3, 1, 0, 2, 4, 6,
  119293. 8,
  119294. };
  119295. static encode_aux_threshmatch _vq_auxt__44c7_s_p3_0 = {
  119296. _vq_quantthresh__44c7_s_p3_0,
  119297. _vq_quantmap__44c7_s_p3_0,
  119298. 9,
  119299. 9
  119300. };
  119301. static static_codebook _44c7_s_p3_0 = {
  119302. 2, 81,
  119303. _vq_lengthlist__44c7_s_p3_0,
  119304. 1, -531628032, 1611661312, 4, 0,
  119305. _vq_quantlist__44c7_s_p3_0,
  119306. NULL,
  119307. &_vq_auxt__44c7_s_p3_0,
  119308. NULL,
  119309. 0
  119310. };
  119311. static long _vq_quantlist__44c7_s_p4_0[] = {
  119312. 8,
  119313. 7,
  119314. 9,
  119315. 6,
  119316. 10,
  119317. 5,
  119318. 11,
  119319. 4,
  119320. 12,
  119321. 3,
  119322. 13,
  119323. 2,
  119324. 14,
  119325. 1,
  119326. 15,
  119327. 0,
  119328. 16,
  119329. };
  119330. static long _vq_lengthlist__44c7_s_p4_0[] = {
  119331. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  119332. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  119333. 12,12, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  119334. 11,12,12, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,
  119335. 11,12,12,12, 0, 0, 0, 6, 6, 8, 7, 9, 9, 9, 9,10,
  119336. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  119337. 11,11,12,12,13,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  119338. 10,11,11,12,12,12,13, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  119339. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  119340. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  119341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119349. 0,
  119350. };
  119351. static float _vq_quantthresh__44c7_s_p4_0[] = {
  119352. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119353. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119354. };
  119355. static long _vq_quantmap__44c7_s_p4_0[] = {
  119356. 15, 13, 11, 9, 7, 5, 3, 1,
  119357. 0, 2, 4, 6, 8, 10, 12, 14,
  119358. 16,
  119359. };
  119360. static encode_aux_threshmatch _vq_auxt__44c7_s_p4_0 = {
  119361. _vq_quantthresh__44c7_s_p4_0,
  119362. _vq_quantmap__44c7_s_p4_0,
  119363. 17,
  119364. 17
  119365. };
  119366. static static_codebook _44c7_s_p4_0 = {
  119367. 2, 289,
  119368. _vq_lengthlist__44c7_s_p4_0,
  119369. 1, -529530880, 1611661312, 5, 0,
  119370. _vq_quantlist__44c7_s_p4_0,
  119371. NULL,
  119372. &_vq_auxt__44c7_s_p4_0,
  119373. NULL,
  119374. 0
  119375. };
  119376. static long _vq_quantlist__44c7_s_p5_0[] = {
  119377. 1,
  119378. 0,
  119379. 2,
  119380. };
  119381. static long _vq_lengthlist__44c7_s_p5_0[] = {
  119382. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 6, 7,10,10,10,10,
  119383. 10, 9, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  119384. 12,10,11,12, 7,10,10,11,12,12,12,12,12, 7,10,10,
  119385. 11,12,12,12,12,12, 6,10,10,10,12,12,11,12,12, 7,
  119386. 10,10,12,12,12,12,11,12, 7,10,10,11,12,12,12,12,
  119387. 12,
  119388. };
  119389. static float _vq_quantthresh__44c7_s_p5_0[] = {
  119390. -5.5, 5.5,
  119391. };
  119392. static long _vq_quantmap__44c7_s_p5_0[] = {
  119393. 1, 0, 2,
  119394. };
  119395. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_0 = {
  119396. _vq_quantthresh__44c7_s_p5_0,
  119397. _vq_quantmap__44c7_s_p5_0,
  119398. 3,
  119399. 3
  119400. };
  119401. static static_codebook _44c7_s_p5_0 = {
  119402. 4, 81,
  119403. _vq_lengthlist__44c7_s_p5_0,
  119404. 1, -529137664, 1618345984, 2, 0,
  119405. _vq_quantlist__44c7_s_p5_0,
  119406. NULL,
  119407. &_vq_auxt__44c7_s_p5_0,
  119408. NULL,
  119409. 0
  119410. };
  119411. static long _vq_quantlist__44c7_s_p5_1[] = {
  119412. 5,
  119413. 4,
  119414. 6,
  119415. 3,
  119416. 7,
  119417. 2,
  119418. 8,
  119419. 1,
  119420. 9,
  119421. 0,
  119422. 10,
  119423. };
  119424. static long _vq_lengthlist__44c7_s_p5_1[] = {
  119425. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 4, 6, 6,
  119426. 7, 7, 8, 8, 9, 9,11, 4, 4, 6, 6, 7, 7, 8, 8, 9,
  119427. 9,12, 5, 5, 6, 6, 7, 7, 9, 9, 9, 9,12,12,12, 6,
  119428. 6, 7, 7, 9, 9, 9, 9,11,11,11, 7, 7, 7, 7, 8, 8,
  119429. 9, 9,11,11,11, 7, 7, 7, 7, 8, 8, 9, 9,11,11,11,
  119430. 7, 7, 8, 8, 8, 8, 9, 9,11,11,11,11,11, 8, 8, 8,
  119431. 8, 8, 9,11,11,11,11,11, 8, 8, 8, 8, 8, 8,11,11,
  119432. 11,11,11, 7, 7, 8, 8, 8, 8,
  119433. };
  119434. static float _vq_quantthresh__44c7_s_p5_1[] = {
  119435. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119436. 3.5, 4.5,
  119437. };
  119438. static long _vq_quantmap__44c7_s_p5_1[] = {
  119439. 9, 7, 5, 3, 1, 0, 2, 4,
  119440. 6, 8, 10,
  119441. };
  119442. static encode_aux_threshmatch _vq_auxt__44c7_s_p5_1 = {
  119443. _vq_quantthresh__44c7_s_p5_1,
  119444. _vq_quantmap__44c7_s_p5_1,
  119445. 11,
  119446. 11
  119447. };
  119448. static static_codebook _44c7_s_p5_1 = {
  119449. 2, 121,
  119450. _vq_lengthlist__44c7_s_p5_1,
  119451. 1, -531365888, 1611661312, 4, 0,
  119452. _vq_quantlist__44c7_s_p5_1,
  119453. NULL,
  119454. &_vq_auxt__44c7_s_p5_1,
  119455. NULL,
  119456. 0
  119457. };
  119458. static long _vq_quantlist__44c7_s_p6_0[] = {
  119459. 6,
  119460. 5,
  119461. 7,
  119462. 4,
  119463. 8,
  119464. 3,
  119465. 9,
  119466. 2,
  119467. 10,
  119468. 1,
  119469. 11,
  119470. 0,
  119471. 12,
  119472. };
  119473. static long _vq_lengthlist__44c7_s_p6_0[] = {
  119474. 1, 4, 4, 6, 6, 7, 7, 8, 7, 9, 8,10,10, 6, 5, 5,
  119475. 7, 7, 8, 8, 9, 9, 9,10,11,11, 7, 5, 5, 7, 7, 8,
  119476. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 8, 9, 9,
  119477. 10,10,11,11, 0, 8, 8, 7, 7, 8, 9, 9, 9,10,10,11,
  119478. 11, 0,11,11, 9, 9,10,10,11,10,11,11,12,12, 0,12,
  119479. 12, 9, 9,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0,
  119480. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119481. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119482. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119483. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119484. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  119485. };
  119486. static float _vq_quantthresh__44c7_s_p6_0[] = {
  119487. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  119488. 12.5, 17.5, 22.5, 27.5,
  119489. };
  119490. static long _vq_quantmap__44c7_s_p6_0[] = {
  119491. 11, 9, 7, 5, 3, 1, 0, 2,
  119492. 4, 6, 8, 10, 12,
  119493. };
  119494. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_0 = {
  119495. _vq_quantthresh__44c7_s_p6_0,
  119496. _vq_quantmap__44c7_s_p6_0,
  119497. 13,
  119498. 13
  119499. };
  119500. static static_codebook _44c7_s_p6_0 = {
  119501. 2, 169,
  119502. _vq_lengthlist__44c7_s_p6_0,
  119503. 1, -526516224, 1616117760, 4, 0,
  119504. _vq_quantlist__44c7_s_p6_0,
  119505. NULL,
  119506. &_vq_auxt__44c7_s_p6_0,
  119507. NULL,
  119508. 0
  119509. };
  119510. static long _vq_quantlist__44c7_s_p6_1[] = {
  119511. 2,
  119512. 1,
  119513. 3,
  119514. 0,
  119515. 4,
  119516. };
  119517. static long _vq_lengthlist__44c7_s_p6_1[] = {
  119518. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  119519. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  119520. };
  119521. static float _vq_quantthresh__44c7_s_p6_1[] = {
  119522. -1.5, -0.5, 0.5, 1.5,
  119523. };
  119524. static long _vq_quantmap__44c7_s_p6_1[] = {
  119525. 3, 1, 0, 2, 4,
  119526. };
  119527. static encode_aux_threshmatch _vq_auxt__44c7_s_p6_1 = {
  119528. _vq_quantthresh__44c7_s_p6_1,
  119529. _vq_quantmap__44c7_s_p6_1,
  119530. 5,
  119531. 5
  119532. };
  119533. static static_codebook _44c7_s_p6_1 = {
  119534. 2, 25,
  119535. _vq_lengthlist__44c7_s_p6_1,
  119536. 1, -533725184, 1611661312, 3, 0,
  119537. _vq_quantlist__44c7_s_p6_1,
  119538. NULL,
  119539. &_vq_auxt__44c7_s_p6_1,
  119540. NULL,
  119541. 0
  119542. };
  119543. static long _vq_quantlist__44c7_s_p7_0[] = {
  119544. 6,
  119545. 5,
  119546. 7,
  119547. 4,
  119548. 8,
  119549. 3,
  119550. 9,
  119551. 2,
  119552. 10,
  119553. 1,
  119554. 11,
  119555. 0,
  119556. 12,
  119557. };
  119558. static long _vq_lengthlist__44c7_s_p7_0[] = {
  119559. 1, 4, 4, 6, 6, 7, 8, 9, 9,10,10,12,11, 6, 5, 5,
  119560. 7, 7, 8, 8, 9,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  119561. 8,10,10,11,11,12,12,20, 7, 7, 7, 7, 8, 9,10,10,
  119562. 11,11,12,13,20, 7, 7, 7, 7, 9, 9,10,10,11,12,13,
  119563. 13,20,11,11, 8, 8, 9, 9,11,11,12,12,13,13,20,11,
  119564. 11, 8, 8, 9, 9,11,11,12,12,13,13,20,20,20,10,10,
  119565. 10,10,12,12,13,13,13,13,20,20,20,10,10,10,10,12,
  119566. 12,13,13,13,14,20,20,20,14,14,11,11,12,12,13,13,
  119567. 14,14,20,20,20,14,14,11,11,12,12,13,13,14,14,20,
  119568. 20,20,20,19,13,13,13,13,14,14,15,14,19,19,19,19,
  119569. 19,13,13,13,13,14,14,15,15,
  119570. };
  119571. static float _vq_quantthresh__44c7_s_p7_0[] = {
  119572. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  119573. 27.5, 38.5, 49.5, 60.5,
  119574. };
  119575. static long _vq_quantmap__44c7_s_p7_0[] = {
  119576. 11, 9, 7, 5, 3, 1, 0, 2,
  119577. 4, 6, 8, 10, 12,
  119578. };
  119579. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_0 = {
  119580. _vq_quantthresh__44c7_s_p7_0,
  119581. _vq_quantmap__44c7_s_p7_0,
  119582. 13,
  119583. 13
  119584. };
  119585. static static_codebook _44c7_s_p7_0 = {
  119586. 2, 169,
  119587. _vq_lengthlist__44c7_s_p7_0,
  119588. 1, -523206656, 1618345984, 4, 0,
  119589. _vq_quantlist__44c7_s_p7_0,
  119590. NULL,
  119591. &_vq_auxt__44c7_s_p7_0,
  119592. NULL,
  119593. 0
  119594. };
  119595. static long _vq_quantlist__44c7_s_p7_1[] = {
  119596. 5,
  119597. 4,
  119598. 6,
  119599. 3,
  119600. 7,
  119601. 2,
  119602. 8,
  119603. 1,
  119604. 9,
  119605. 0,
  119606. 10,
  119607. };
  119608. static long _vq_lengthlist__44c7_s_p7_1[] = {
  119609. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 7, 7,
  119610. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  119611. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  119612. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119613. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  119614. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  119615. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  119616. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  119617. };
  119618. static float _vq_quantthresh__44c7_s_p7_1[] = {
  119619. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  119620. 3.5, 4.5,
  119621. };
  119622. static long _vq_quantmap__44c7_s_p7_1[] = {
  119623. 9, 7, 5, 3, 1, 0, 2, 4,
  119624. 6, 8, 10,
  119625. };
  119626. static encode_aux_threshmatch _vq_auxt__44c7_s_p7_1 = {
  119627. _vq_quantthresh__44c7_s_p7_1,
  119628. _vq_quantmap__44c7_s_p7_1,
  119629. 11,
  119630. 11
  119631. };
  119632. static static_codebook _44c7_s_p7_1 = {
  119633. 2, 121,
  119634. _vq_lengthlist__44c7_s_p7_1,
  119635. 1, -531365888, 1611661312, 4, 0,
  119636. _vq_quantlist__44c7_s_p7_1,
  119637. NULL,
  119638. &_vq_auxt__44c7_s_p7_1,
  119639. NULL,
  119640. 0
  119641. };
  119642. static long _vq_quantlist__44c7_s_p8_0[] = {
  119643. 7,
  119644. 6,
  119645. 8,
  119646. 5,
  119647. 9,
  119648. 4,
  119649. 10,
  119650. 3,
  119651. 11,
  119652. 2,
  119653. 12,
  119654. 1,
  119655. 13,
  119656. 0,
  119657. 14,
  119658. };
  119659. static long _vq_lengthlist__44c7_s_p8_0[] = {
  119660. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8, 9, 9,10,10, 6,
  119661. 5, 5, 7, 7, 9, 9, 8, 8,10, 9,11,10,12,11, 6, 5,
  119662. 5, 8, 7, 9, 9, 8, 8,10,10,11,11,12,11,19, 8, 8,
  119663. 8, 8,10,10, 9, 9,10,10,11,11,12,11,19, 8, 8, 8,
  119664. 8,10,10, 9, 9,10,10,11,11,12,12,19,12,12, 9, 9,
  119665. 10,10, 9,10,10,10,11,11,12,12,19,12,12, 9, 9,10,
  119666. 10,10,10,10,10,12,12,12,12,19,19,19, 9, 9, 9, 9,
  119667. 11,10,11,11,12,11,13,13,19,19,19, 9, 9, 9, 9,11,
  119668. 10,11,11,11,12,13,13,19,19,19,13,13,10,10,11,11,
  119669. 12,12,12,12,13,12,19,19,19,14,13,10,10,11,11,12,
  119670. 12,12,13,13,13,19,19,19,19,19,12,12,12,11,12,13,
  119671. 14,13,13,13,19,19,19,19,19,12,12,12,11,12,12,13,
  119672. 14,13,14,19,19,19,19,19,16,16,12,13,12,13,13,14,
  119673. 15,14,19,18,18,18,18,16,15,12,11,12,11,14,12,14,
  119674. 14,
  119675. };
  119676. static float _vq_quantthresh__44c7_s_p8_0[] = {
  119677. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  119678. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  119679. };
  119680. static long _vq_quantmap__44c7_s_p8_0[] = {
  119681. 13, 11, 9, 7, 5, 3, 1, 0,
  119682. 2, 4, 6, 8, 10, 12, 14,
  119683. };
  119684. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_0 = {
  119685. _vq_quantthresh__44c7_s_p8_0,
  119686. _vq_quantmap__44c7_s_p8_0,
  119687. 15,
  119688. 15
  119689. };
  119690. static static_codebook _44c7_s_p8_0 = {
  119691. 2, 225,
  119692. _vq_lengthlist__44c7_s_p8_0,
  119693. 1, -520986624, 1620377600, 4, 0,
  119694. _vq_quantlist__44c7_s_p8_0,
  119695. NULL,
  119696. &_vq_auxt__44c7_s_p8_0,
  119697. NULL,
  119698. 0
  119699. };
  119700. static long _vq_quantlist__44c7_s_p8_1[] = {
  119701. 10,
  119702. 9,
  119703. 11,
  119704. 8,
  119705. 12,
  119706. 7,
  119707. 13,
  119708. 6,
  119709. 14,
  119710. 5,
  119711. 15,
  119712. 4,
  119713. 16,
  119714. 3,
  119715. 17,
  119716. 2,
  119717. 18,
  119718. 1,
  119719. 19,
  119720. 0,
  119721. 20,
  119722. };
  119723. static long _vq_lengthlist__44c7_s_p8_1[] = {
  119724. 3, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  119725. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  119726. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  119727. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  119728. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119729. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  119730. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  119731. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  119732. 10, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119733. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  119734. 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,10,10, 9, 9, 9,
  119735. 9, 9, 9, 9, 9, 9, 9,10, 9, 9,10, 9, 9,10,11,10,
  119736. 11,10, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9, 9,
  119737. 9, 9,11,10,11,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,
  119738. 10, 9, 9,10, 9, 9,10,11,10,10,11,10, 9, 9, 9, 9,
  119739. 9,10,10, 9,10,10,10,10, 9,10,10,10,10,10,10,11,
  119740. 11,11,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  119741. 10,10,10,11,11,10,10,10,10,10,10,10,10,10,10,10,
  119742. 10, 9,10,10, 9,10,11,11,10,11,10,11,10, 9,10,10,
  119743. 9,10,10,10,10,10,10,10,10,10,10,11,11,11,11,10,
  119744. 11,11,10,10,10,10,10,10, 9,10, 9,10,10, 9,10, 9,
  119745. 10,10,10,11,10,11,10,11,11,10,10,10,10,10,10, 9,
  119746. 10,10,10,10,10,10,10,11,10,10,10,10,10,10,10,10,
  119747. 10,10,10,10,10,10,10,10,10,10,10,10,10,11,10,11,
  119748. 11,10,10,10,10, 9, 9,10,10, 9, 9,10, 9,10,10,10,
  119749. 10,11,11,10,10,10,10,10,10,10, 9, 9,10,10,10, 9,
  119750. 9,10,10,10,10,10,11,10,11,10,10,10,10,10,10, 9,
  119751. 10,10,10,10,10,10,10,10,10,
  119752. };
  119753. static float _vq_quantthresh__44c7_s_p8_1[] = {
  119754. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  119755. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  119756. 6.5, 7.5, 8.5, 9.5,
  119757. };
  119758. static long _vq_quantmap__44c7_s_p8_1[] = {
  119759. 19, 17, 15, 13, 11, 9, 7, 5,
  119760. 3, 1, 0, 2, 4, 6, 8, 10,
  119761. 12, 14, 16, 18, 20,
  119762. };
  119763. static encode_aux_threshmatch _vq_auxt__44c7_s_p8_1 = {
  119764. _vq_quantthresh__44c7_s_p8_1,
  119765. _vq_quantmap__44c7_s_p8_1,
  119766. 21,
  119767. 21
  119768. };
  119769. static static_codebook _44c7_s_p8_1 = {
  119770. 2, 441,
  119771. _vq_lengthlist__44c7_s_p8_1,
  119772. 1, -529268736, 1611661312, 5, 0,
  119773. _vq_quantlist__44c7_s_p8_1,
  119774. NULL,
  119775. &_vq_auxt__44c7_s_p8_1,
  119776. NULL,
  119777. 0
  119778. };
  119779. static long _vq_quantlist__44c7_s_p9_0[] = {
  119780. 6,
  119781. 5,
  119782. 7,
  119783. 4,
  119784. 8,
  119785. 3,
  119786. 9,
  119787. 2,
  119788. 10,
  119789. 1,
  119790. 11,
  119791. 0,
  119792. 12,
  119793. };
  119794. static long _vq_lengthlist__44c7_s_p9_0[] = {
  119795. 1, 3, 3,11,11,11,11,11,11,11,11,11,11, 4, 6, 6,
  119796. 11,11,11,11,11,11,11,11,11,11, 4, 7, 7,11,11,11,
  119797. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119798. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119799. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119800. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119801. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119802. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119803. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119804. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  119805. 11,11,11,11,11,11,11,11,11,
  119806. };
  119807. static float _vq_quantthresh__44c7_s_p9_0[] = {
  119808. -3503.5, -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5,
  119809. 1592.5, 2229.5, 2866.5, 3503.5,
  119810. };
  119811. static long _vq_quantmap__44c7_s_p9_0[] = {
  119812. 11, 9, 7, 5, 3, 1, 0, 2,
  119813. 4, 6, 8, 10, 12,
  119814. };
  119815. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_0 = {
  119816. _vq_quantthresh__44c7_s_p9_0,
  119817. _vq_quantmap__44c7_s_p9_0,
  119818. 13,
  119819. 13
  119820. };
  119821. static static_codebook _44c7_s_p9_0 = {
  119822. 2, 169,
  119823. _vq_lengthlist__44c7_s_p9_0,
  119824. 1, -511845376, 1630791680, 4, 0,
  119825. _vq_quantlist__44c7_s_p9_0,
  119826. NULL,
  119827. &_vq_auxt__44c7_s_p9_0,
  119828. NULL,
  119829. 0
  119830. };
  119831. static long _vq_quantlist__44c7_s_p9_1[] = {
  119832. 6,
  119833. 5,
  119834. 7,
  119835. 4,
  119836. 8,
  119837. 3,
  119838. 9,
  119839. 2,
  119840. 10,
  119841. 1,
  119842. 11,
  119843. 0,
  119844. 12,
  119845. };
  119846. static long _vq_lengthlist__44c7_s_p9_1[] = {
  119847. 1, 4, 4, 7, 7, 7, 7, 7, 6, 8, 8, 8, 8, 6, 6, 6,
  119848. 8, 8, 9, 8, 8, 7, 9, 8,11,10, 5, 6, 6, 8, 8, 9,
  119849. 8, 8, 8,10, 9,11,11,16, 8, 8, 9, 8, 9, 9, 9, 8,
  119850. 10, 9,11,10,16, 8, 8, 9, 9,10,10, 9, 9,10,10,11,
  119851. 11,16,13,13, 9, 9,10,10, 9,10,11,11,12,11,16,13,
  119852. 13, 9, 8,10, 9,10,10,10,10,11,11,16,14,16, 8, 9,
  119853. 9, 9,11,10,11,11,12,11,16,16,16, 9, 7,10, 7,11,
  119854. 10,11,11,12,11,16,16,16,12,12, 9,10,11,11,12,11,
  119855. 12,12,16,16,16,12,10,10, 7,11, 8,12,11,12,12,16,
  119856. 16,15,16,16,11,12,10,10,12,11,12,12,16,16,16,15,
  119857. 15,11,11,10,10,12,12,12,12,
  119858. };
  119859. static float _vq_quantthresh__44c7_s_p9_1[] = {
  119860. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  119861. 122.5, 171.5, 220.5, 269.5,
  119862. };
  119863. static long _vq_quantmap__44c7_s_p9_1[] = {
  119864. 11, 9, 7, 5, 3, 1, 0, 2,
  119865. 4, 6, 8, 10, 12,
  119866. };
  119867. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_1 = {
  119868. _vq_quantthresh__44c7_s_p9_1,
  119869. _vq_quantmap__44c7_s_p9_1,
  119870. 13,
  119871. 13
  119872. };
  119873. static static_codebook _44c7_s_p9_1 = {
  119874. 2, 169,
  119875. _vq_lengthlist__44c7_s_p9_1,
  119876. 1, -518889472, 1622704128, 4, 0,
  119877. _vq_quantlist__44c7_s_p9_1,
  119878. NULL,
  119879. &_vq_auxt__44c7_s_p9_1,
  119880. NULL,
  119881. 0
  119882. };
  119883. static long _vq_quantlist__44c7_s_p9_2[] = {
  119884. 24,
  119885. 23,
  119886. 25,
  119887. 22,
  119888. 26,
  119889. 21,
  119890. 27,
  119891. 20,
  119892. 28,
  119893. 19,
  119894. 29,
  119895. 18,
  119896. 30,
  119897. 17,
  119898. 31,
  119899. 16,
  119900. 32,
  119901. 15,
  119902. 33,
  119903. 14,
  119904. 34,
  119905. 13,
  119906. 35,
  119907. 12,
  119908. 36,
  119909. 11,
  119910. 37,
  119911. 10,
  119912. 38,
  119913. 9,
  119914. 39,
  119915. 8,
  119916. 40,
  119917. 7,
  119918. 41,
  119919. 6,
  119920. 42,
  119921. 5,
  119922. 43,
  119923. 4,
  119924. 44,
  119925. 3,
  119926. 45,
  119927. 2,
  119928. 46,
  119929. 1,
  119930. 47,
  119931. 0,
  119932. 48,
  119933. };
  119934. static long _vq_lengthlist__44c7_s_p9_2[] = {
  119935. 2, 4, 3, 4, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6, 6,
  119936. 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119937. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  119938. 7,
  119939. };
  119940. static float _vq_quantthresh__44c7_s_p9_2[] = {
  119941. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  119942. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  119943. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  119944. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  119945. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  119946. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  119947. };
  119948. static long _vq_quantmap__44c7_s_p9_2[] = {
  119949. 47, 45, 43, 41, 39, 37, 35, 33,
  119950. 31, 29, 27, 25, 23, 21, 19, 17,
  119951. 15, 13, 11, 9, 7, 5, 3, 1,
  119952. 0, 2, 4, 6, 8, 10, 12, 14,
  119953. 16, 18, 20, 22, 24, 26, 28, 30,
  119954. 32, 34, 36, 38, 40, 42, 44, 46,
  119955. 48,
  119956. };
  119957. static encode_aux_threshmatch _vq_auxt__44c7_s_p9_2 = {
  119958. _vq_quantthresh__44c7_s_p9_2,
  119959. _vq_quantmap__44c7_s_p9_2,
  119960. 49,
  119961. 49
  119962. };
  119963. static static_codebook _44c7_s_p9_2 = {
  119964. 1, 49,
  119965. _vq_lengthlist__44c7_s_p9_2,
  119966. 1, -526909440, 1611661312, 6, 0,
  119967. _vq_quantlist__44c7_s_p9_2,
  119968. NULL,
  119969. &_vq_auxt__44c7_s_p9_2,
  119970. NULL,
  119971. 0
  119972. };
  119973. static long _huff_lengthlist__44c7_s_short[] = {
  119974. 4,11,12,14,15,15,17,17,18,18, 5, 6, 6, 8, 9,10,
  119975. 13,17,18,19, 7, 5, 4, 6, 8, 9,11,15,19,19, 8, 6,
  119976. 5, 5, 6, 7,11,14,16,17, 9, 7, 7, 6, 7, 7,10,13,
  119977. 15,19,10, 8, 7, 6, 7, 6, 7, 9,14,16,12,10, 9, 7,
  119978. 7, 6, 4, 5,10,15,14,13,11, 7, 6, 6, 4, 2, 7,13,
  119979. 16,16,15, 9, 8, 8, 8, 6, 9,13,19,19,17,12,11,10,
  119980. 10, 9,11,14,
  119981. };
  119982. static static_codebook _huff_book__44c7_s_short = {
  119983. 2, 100,
  119984. _huff_lengthlist__44c7_s_short,
  119985. 0, 0, 0, 0, 0,
  119986. NULL,
  119987. NULL,
  119988. NULL,
  119989. NULL,
  119990. 0
  119991. };
  119992. static long _huff_lengthlist__44c8_s_long[] = {
  119993. 3, 8,12,13,14,14,14,13,14,14, 6, 4, 5, 8,10,10,
  119994. 11,11,14,13, 9, 5, 4, 5, 7, 8, 9,10,13,13,12, 7,
  119995. 5, 4, 5, 6, 8, 9,12,13,13, 9, 6, 5, 5, 5, 7, 9,
  119996. 11,14,12,10, 7, 6, 5, 4, 6, 7,10,11,12,11, 9, 8,
  119997. 7, 5, 5, 6,10,10,13,12,10, 9, 8, 6, 6, 5, 8,10,
  119998. 14,13,12,12,11,10, 9, 7, 8,10,12,13,14,14,13,12,
  119999. 11, 9, 9,10,
  120000. };
  120001. static static_codebook _huff_book__44c8_s_long = {
  120002. 2, 100,
  120003. _huff_lengthlist__44c8_s_long,
  120004. 0, 0, 0, 0, 0,
  120005. NULL,
  120006. NULL,
  120007. NULL,
  120008. NULL,
  120009. 0
  120010. };
  120011. static long _vq_quantlist__44c8_s_p1_0[] = {
  120012. 1,
  120013. 0,
  120014. 2,
  120015. };
  120016. static long _vq_lengthlist__44c8_s_p1_0[] = {
  120017. 1, 5, 5, 0, 5, 5, 0, 5, 5, 5, 7, 7, 0, 9, 8, 0,
  120018. 9, 8, 6, 7, 7, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120019. 0, 0, 0, 0, 5, 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9,
  120020. 0, 8, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120021. 9, 8, 0, 8, 8, 0, 8, 8, 5, 8, 9, 0, 8, 8, 0, 8,
  120022. 8,
  120023. };
  120024. static float _vq_quantthresh__44c8_s_p1_0[] = {
  120025. -0.5, 0.5,
  120026. };
  120027. static long _vq_quantmap__44c8_s_p1_0[] = {
  120028. 1, 0, 2,
  120029. };
  120030. static encode_aux_threshmatch _vq_auxt__44c8_s_p1_0 = {
  120031. _vq_quantthresh__44c8_s_p1_0,
  120032. _vq_quantmap__44c8_s_p1_0,
  120033. 3,
  120034. 3
  120035. };
  120036. static static_codebook _44c8_s_p1_0 = {
  120037. 4, 81,
  120038. _vq_lengthlist__44c8_s_p1_0,
  120039. 1, -535822336, 1611661312, 2, 0,
  120040. _vq_quantlist__44c8_s_p1_0,
  120041. NULL,
  120042. &_vq_auxt__44c8_s_p1_0,
  120043. NULL,
  120044. 0
  120045. };
  120046. static long _vq_quantlist__44c8_s_p2_0[] = {
  120047. 2,
  120048. 1,
  120049. 3,
  120050. 0,
  120051. 4,
  120052. };
  120053. static long _vq_lengthlist__44c8_s_p2_0[] = {
  120054. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120055. 7, 7, 9, 9, 0, 0, 0, 9, 9, 5, 7, 7, 9, 9, 0, 8,
  120056. 7,10, 9, 0, 8, 7,10, 9, 0,10,10,11,11, 0, 0, 0,
  120057. 11,11, 5, 7, 7, 9, 9, 0, 7, 8, 9,10, 0, 7, 8, 9,
  120058. 10, 0,10,10,11,11, 0, 0, 0,11,11, 8, 9, 9,11,10,
  120059. 0,11,10,12,11, 0,11,10,12,12, 0,13,13,14,14, 0,
  120060. 0, 0,14,13, 8, 9, 9,10,11, 0,10,11,12,12, 0,10,
  120061. 11,12,12, 0,13,13,14,14, 0, 0, 0,13,14, 0, 0, 0,
  120062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120063. 0, 0, 0, 0, 0, 0, 5, 8, 7,11,10, 0, 7, 7,10,10,
  120064. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,11,10, 5,
  120065. 7, 8,10,11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9,
  120066. 9,10,10, 0, 0, 0,10,10, 8,10, 9,12,12, 0,10,10,
  120067. 12,11, 0,10,10,12,12, 0,12,12,13,12, 0, 0, 0,13,
  120068. 12, 8, 9,10,12,12, 0,10,10,11,12, 0,10,10,11,12,
  120069. 0,12,12,13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0,
  120070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120071. 0, 0, 0, 6, 8, 7,11,10, 0, 7, 7,10,10, 0, 7, 7,
  120072. 10,10, 0, 9, 9,10,11, 0, 0, 0,10,10, 6, 7, 8,10,
  120073. 11, 0, 7, 7,10,10, 0, 7, 7,10,10, 0, 9, 9,10,10,
  120074. 0, 0, 0,10,10, 9,10, 9,12,12, 0,10,10,12,12, 0,
  120075. 10,10,12,11, 0,12,12,13,13, 0, 0, 0,13,12, 8, 9,
  120076. 10,12,12, 0,10,10,12,12, 0,10,10,11,12, 0,12,12,
  120077. 13,13, 0, 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120079. 7,10,10,13,13, 0, 9, 9,12,12, 0, 9, 9,12,12, 0,
  120080. 10,10,12,12, 0, 0, 0,12,12, 7,10,10,13,13, 0, 9,
  120081. 9,12,12, 0, 9, 9,12,12, 0,10,10,12,12, 0, 0, 0,
  120082. 12,12, 9,11,11,14,13, 0,10,10,13,12, 0,11,10,13,
  120083. 12, 0,12,12,13,12, 0, 0, 0,13,13, 9,11,11,13,14,
  120084. 0,10,11,12,13, 0,10,11,13,13, 0,12,12,12,13, 0,
  120085. 0, 0,13,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120090. 11,11,14,14, 0,10,11,13,13, 0,11,10,13,13, 0,11,
  120091. 12,13,13, 0, 0, 0,13,12, 9,11,11,14,14, 0,11,10,
  120092. 13,13, 0,10,11,13,13, 0,12,12,13,13, 0, 0, 0,12,
  120093. 13,
  120094. };
  120095. static float _vq_quantthresh__44c8_s_p2_0[] = {
  120096. -1.5, -0.5, 0.5, 1.5,
  120097. };
  120098. static long _vq_quantmap__44c8_s_p2_0[] = {
  120099. 3, 1, 0, 2, 4,
  120100. };
  120101. static encode_aux_threshmatch _vq_auxt__44c8_s_p2_0 = {
  120102. _vq_quantthresh__44c8_s_p2_0,
  120103. _vq_quantmap__44c8_s_p2_0,
  120104. 5,
  120105. 5
  120106. };
  120107. static static_codebook _44c8_s_p2_0 = {
  120108. 4, 625,
  120109. _vq_lengthlist__44c8_s_p2_0,
  120110. 1, -533725184, 1611661312, 3, 0,
  120111. _vq_quantlist__44c8_s_p2_0,
  120112. NULL,
  120113. &_vq_auxt__44c8_s_p2_0,
  120114. NULL,
  120115. 0
  120116. };
  120117. static long _vq_quantlist__44c8_s_p3_0[] = {
  120118. 4,
  120119. 3,
  120120. 5,
  120121. 2,
  120122. 6,
  120123. 1,
  120124. 7,
  120125. 0,
  120126. 8,
  120127. };
  120128. static long _vq_lengthlist__44c8_s_p3_0[] = {
  120129. 2, 4, 4, 5, 5, 7, 7, 9, 9, 0, 4, 4, 6, 6, 7, 7,
  120130. 9, 9, 0, 4, 4, 6, 6, 7, 7, 9, 9, 0, 5, 5, 6, 6,
  120131. 8, 8,10,10, 0, 0, 0, 6, 6, 8, 8,10,10, 0, 0, 0,
  120132. 7, 7, 9, 9,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0,
  120133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120134. 0,
  120135. };
  120136. static float _vq_quantthresh__44c8_s_p3_0[] = {
  120137. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  120138. };
  120139. static long _vq_quantmap__44c8_s_p3_0[] = {
  120140. 7, 5, 3, 1, 0, 2, 4, 6,
  120141. 8,
  120142. };
  120143. static encode_aux_threshmatch _vq_auxt__44c8_s_p3_0 = {
  120144. _vq_quantthresh__44c8_s_p3_0,
  120145. _vq_quantmap__44c8_s_p3_0,
  120146. 9,
  120147. 9
  120148. };
  120149. static static_codebook _44c8_s_p3_0 = {
  120150. 2, 81,
  120151. _vq_lengthlist__44c8_s_p3_0,
  120152. 1, -531628032, 1611661312, 4, 0,
  120153. _vq_quantlist__44c8_s_p3_0,
  120154. NULL,
  120155. &_vq_auxt__44c8_s_p3_0,
  120156. NULL,
  120157. 0
  120158. };
  120159. static long _vq_quantlist__44c8_s_p4_0[] = {
  120160. 8,
  120161. 7,
  120162. 9,
  120163. 6,
  120164. 10,
  120165. 5,
  120166. 11,
  120167. 4,
  120168. 12,
  120169. 3,
  120170. 13,
  120171. 2,
  120172. 14,
  120173. 1,
  120174. 15,
  120175. 0,
  120176. 16,
  120177. };
  120178. static long _vq_lengthlist__44c8_s_p4_0[] = {
  120179. 3, 4, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  120180. 11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 8,10,10,11,11,
  120181. 11,11, 0, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  120182. 11,11,11, 0, 6, 5, 6, 6, 7, 7, 9, 9, 9, 9,10,10,
  120183. 11,11,12,12, 0, 0, 0, 6, 6, 7, 7, 9, 9, 9, 9,10,
  120184. 10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,
  120185. 11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,
  120186. 10,11,11,11,12,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  120187. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  120188. 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 0, 0,
  120189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120197. 0,
  120198. };
  120199. static float _vq_quantthresh__44c8_s_p4_0[] = {
  120200. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120201. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120202. };
  120203. static long _vq_quantmap__44c8_s_p4_0[] = {
  120204. 15, 13, 11, 9, 7, 5, 3, 1,
  120205. 0, 2, 4, 6, 8, 10, 12, 14,
  120206. 16,
  120207. };
  120208. static encode_aux_threshmatch _vq_auxt__44c8_s_p4_0 = {
  120209. _vq_quantthresh__44c8_s_p4_0,
  120210. _vq_quantmap__44c8_s_p4_0,
  120211. 17,
  120212. 17
  120213. };
  120214. static static_codebook _44c8_s_p4_0 = {
  120215. 2, 289,
  120216. _vq_lengthlist__44c8_s_p4_0,
  120217. 1, -529530880, 1611661312, 5, 0,
  120218. _vq_quantlist__44c8_s_p4_0,
  120219. NULL,
  120220. &_vq_auxt__44c8_s_p4_0,
  120221. NULL,
  120222. 0
  120223. };
  120224. static long _vq_quantlist__44c8_s_p5_0[] = {
  120225. 1,
  120226. 0,
  120227. 2,
  120228. };
  120229. static long _vq_lengthlist__44c8_s_p5_0[] = {
  120230. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6,10,10,10,10,
  120231. 10,10, 4, 6, 6,10,10,10,10, 9,10, 5,10,10, 9,11,
  120232. 11,10,11,11, 7,10,10,11,12,12,12,12,12, 7,10,10,
  120233. 11,12,12,12,12,12, 6,10,10,10,12,12,10,12,12, 7,
  120234. 10,10,11,12,12,12,12,12, 7,10,10,11,12,12,12,12,
  120235. 12,
  120236. };
  120237. static float _vq_quantthresh__44c8_s_p5_0[] = {
  120238. -5.5, 5.5,
  120239. };
  120240. static long _vq_quantmap__44c8_s_p5_0[] = {
  120241. 1, 0, 2,
  120242. };
  120243. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_0 = {
  120244. _vq_quantthresh__44c8_s_p5_0,
  120245. _vq_quantmap__44c8_s_p5_0,
  120246. 3,
  120247. 3
  120248. };
  120249. static static_codebook _44c8_s_p5_0 = {
  120250. 4, 81,
  120251. _vq_lengthlist__44c8_s_p5_0,
  120252. 1, -529137664, 1618345984, 2, 0,
  120253. _vq_quantlist__44c8_s_p5_0,
  120254. NULL,
  120255. &_vq_auxt__44c8_s_p5_0,
  120256. NULL,
  120257. 0
  120258. };
  120259. static long _vq_quantlist__44c8_s_p5_1[] = {
  120260. 5,
  120261. 4,
  120262. 6,
  120263. 3,
  120264. 7,
  120265. 2,
  120266. 8,
  120267. 1,
  120268. 9,
  120269. 0,
  120270. 10,
  120271. };
  120272. static long _vq_lengthlist__44c8_s_p5_1[] = {
  120273. 3, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11, 4, 5, 6, 6,
  120274. 7, 7, 8, 8, 8, 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  120275. 9,12, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,12,12,12, 6,
  120276. 6, 7, 7, 8, 8, 9, 9,11,11,11, 6, 6, 7, 7, 8, 8,
  120277. 8, 8,11,11,11, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11,
  120278. 7, 7, 7, 8, 8, 8, 8, 8,11,11,11,11,11, 7, 7, 8,
  120279. 8, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 8, 8,11,11,
  120280. 11,11,11, 7, 7, 7, 7, 8, 8,
  120281. };
  120282. static float _vq_quantthresh__44c8_s_p5_1[] = {
  120283. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120284. 3.5, 4.5,
  120285. };
  120286. static long _vq_quantmap__44c8_s_p5_1[] = {
  120287. 9, 7, 5, 3, 1, 0, 2, 4,
  120288. 6, 8, 10,
  120289. };
  120290. static encode_aux_threshmatch _vq_auxt__44c8_s_p5_1 = {
  120291. _vq_quantthresh__44c8_s_p5_1,
  120292. _vq_quantmap__44c8_s_p5_1,
  120293. 11,
  120294. 11
  120295. };
  120296. static static_codebook _44c8_s_p5_1 = {
  120297. 2, 121,
  120298. _vq_lengthlist__44c8_s_p5_1,
  120299. 1, -531365888, 1611661312, 4, 0,
  120300. _vq_quantlist__44c8_s_p5_1,
  120301. NULL,
  120302. &_vq_auxt__44c8_s_p5_1,
  120303. NULL,
  120304. 0
  120305. };
  120306. static long _vq_quantlist__44c8_s_p6_0[] = {
  120307. 6,
  120308. 5,
  120309. 7,
  120310. 4,
  120311. 8,
  120312. 3,
  120313. 9,
  120314. 2,
  120315. 10,
  120316. 1,
  120317. 11,
  120318. 0,
  120319. 12,
  120320. };
  120321. static long _vq_lengthlist__44c8_s_p6_0[] = {
  120322. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  120323. 7, 7, 8, 8, 9, 9,10,10,11,11, 6, 5, 5, 7, 7, 8,
  120324. 8, 9, 9,10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,
  120325. 10,10,11,11, 0, 7, 7, 7, 7, 9, 9,10,10,10,10,11,
  120326. 11, 0,11,11, 9, 9,10,10,11,11,11,11,12,12, 0,12,
  120327. 12, 9, 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0,
  120328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120332. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120333. };
  120334. static float _vq_quantthresh__44c8_s_p6_0[] = {
  120335. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  120336. 12.5, 17.5, 22.5, 27.5,
  120337. };
  120338. static long _vq_quantmap__44c8_s_p6_0[] = {
  120339. 11, 9, 7, 5, 3, 1, 0, 2,
  120340. 4, 6, 8, 10, 12,
  120341. };
  120342. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_0 = {
  120343. _vq_quantthresh__44c8_s_p6_0,
  120344. _vq_quantmap__44c8_s_p6_0,
  120345. 13,
  120346. 13
  120347. };
  120348. static static_codebook _44c8_s_p6_0 = {
  120349. 2, 169,
  120350. _vq_lengthlist__44c8_s_p6_0,
  120351. 1, -526516224, 1616117760, 4, 0,
  120352. _vq_quantlist__44c8_s_p6_0,
  120353. NULL,
  120354. &_vq_auxt__44c8_s_p6_0,
  120355. NULL,
  120356. 0
  120357. };
  120358. static long _vq_quantlist__44c8_s_p6_1[] = {
  120359. 2,
  120360. 1,
  120361. 3,
  120362. 0,
  120363. 4,
  120364. };
  120365. static long _vq_lengthlist__44c8_s_p6_1[] = {
  120366. 3, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 6,
  120367. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  120368. };
  120369. static float _vq_quantthresh__44c8_s_p6_1[] = {
  120370. -1.5, -0.5, 0.5, 1.5,
  120371. };
  120372. static long _vq_quantmap__44c8_s_p6_1[] = {
  120373. 3, 1, 0, 2, 4,
  120374. };
  120375. static encode_aux_threshmatch _vq_auxt__44c8_s_p6_1 = {
  120376. _vq_quantthresh__44c8_s_p6_1,
  120377. _vq_quantmap__44c8_s_p6_1,
  120378. 5,
  120379. 5
  120380. };
  120381. static static_codebook _44c8_s_p6_1 = {
  120382. 2, 25,
  120383. _vq_lengthlist__44c8_s_p6_1,
  120384. 1, -533725184, 1611661312, 3, 0,
  120385. _vq_quantlist__44c8_s_p6_1,
  120386. NULL,
  120387. &_vq_auxt__44c8_s_p6_1,
  120388. NULL,
  120389. 0
  120390. };
  120391. static long _vq_quantlist__44c8_s_p7_0[] = {
  120392. 6,
  120393. 5,
  120394. 7,
  120395. 4,
  120396. 8,
  120397. 3,
  120398. 9,
  120399. 2,
  120400. 10,
  120401. 1,
  120402. 11,
  120403. 0,
  120404. 12,
  120405. };
  120406. static long _vq_lengthlist__44c8_s_p7_0[] = {
  120407. 1, 4, 4, 6, 6, 8, 7, 9, 9,10,10,12,12, 6, 5, 5,
  120408. 7, 7, 8, 8,10,10,11,11,12,12, 7, 5, 5, 7, 7, 8,
  120409. 8,10,10,11,11,12,12,21, 7, 7, 7, 7, 8, 9,10,10,
  120410. 11,11,12,12,21, 7, 7, 7, 7, 9, 9,10,10,12,12,13,
  120411. 13,21,11,11, 8, 8, 9, 9,11,11,12,12,13,13,21,11,
  120412. 11, 8, 8, 9, 9,11,11,12,12,13,13,21,21,21,10,10,
  120413. 10,10,11,11,12,13,13,13,21,21,21,10,10,10,10,11,
  120414. 11,13,13,14,13,21,21,21,13,13,11,11,12,12,13,13,
  120415. 14,14,21,21,21,14,14,11,11,12,12,13,13,14,14,21,
  120416. 21,21,21,20,13,13,13,12,14,14,16,15,20,20,20,20,
  120417. 20,13,13,13,13,14,13,15,15,
  120418. };
  120419. static float _vq_quantthresh__44c8_s_p7_0[] = {
  120420. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  120421. 27.5, 38.5, 49.5, 60.5,
  120422. };
  120423. static long _vq_quantmap__44c8_s_p7_0[] = {
  120424. 11, 9, 7, 5, 3, 1, 0, 2,
  120425. 4, 6, 8, 10, 12,
  120426. };
  120427. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_0 = {
  120428. _vq_quantthresh__44c8_s_p7_0,
  120429. _vq_quantmap__44c8_s_p7_0,
  120430. 13,
  120431. 13
  120432. };
  120433. static static_codebook _44c8_s_p7_0 = {
  120434. 2, 169,
  120435. _vq_lengthlist__44c8_s_p7_0,
  120436. 1, -523206656, 1618345984, 4, 0,
  120437. _vq_quantlist__44c8_s_p7_0,
  120438. NULL,
  120439. &_vq_auxt__44c8_s_p7_0,
  120440. NULL,
  120441. 0
  120442. };
  120443. static long _vq_quantlist__44c8_s_p7_1[] = {
  120444. 5,
  120445. 4,
  120446. 6,
  120447. 3,
  120448. 7,
  120449. 2,
  120450. 8,
  120451. 1,
  120452. 9,
  120453. 0,
  120454. 10,
  120455. };
  120456. static long _vq_lengthlist__44c8_s_p7_1[] = {
  120457. 4, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 7,
  120458. 7, 7, 7, 7, 7, 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  120459. 7, 8, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7,
  120460. 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120461. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  120462. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  120463. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  120464. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  120465. };
  120466. static float _vq_quantthresh__44c8_s_p7_1[] = {
  120467. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  120468. 3.5, 4.5,
  120469. };
  120470. static long _vq_quantmap__44c8_s_p7_1[] = {
  120471. 9, 7, 5, 3, 1, 0, 2, 4,
  120472. 6, 8, 10,
  120473. };
  120474. static encode_aux_threshmatch _vq_auxt__44c8_s_p7_1 = {
  120475. _vq_quantthresh__44c8_s_p7_1,
  120476. _vq_quantmap__44c8_s_p7_1,
  120477. 11,
  120478. 11
  120479. };
  120480. static static_codebook _44c8_s_p7_1 = {
  120481. 2, 121,
  120482. _vq_lengthlist__44c8_s_p7_1,
  120483. 1, -531365888, 1611661312, 4, 0,
  120484. _vq_quantlist__44c8_s_p7_1,
  120485. NULL,
  120486. &_vq_auxt__44c8_s_p7_1,
  120487. NULL,
  120488. 0
  120489. };
  120490. static long _vq_quantlist__44c8_s_p8_0[] = {
  120491. 7,
  120492. 6,
  120493. 8,
  120494. 5,
  120495. 9,
  120496. 4,
  120497. 10,
  120498. 3,
  120499. 11,
  120500. 2,
  120501. 12,
  120502. 1,
  120503. 13,
  120504. 0,
  120505. 14,
  120506. };
  120507. static long _vq_lengthlist__44c8_s_p8_0[] = {
  120508. 1, 4, 4, 7, 6, 8, 8, 8, 7, 9, 8,10,10,11,10, 6,
  120509. 5, 5, 7, 7, 9, 9, 8, 8,10,10,11,11,12,11, 6, 5,
  120510. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8,
  120511. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,20, 8, 8, 8,
  120512. 8,10, 9, 9, 9,10,10,11,11,12,12,20,12,12, 9, 9,
  120513. 10,10,10,10,10,11,12,12,12,12,20,12,12, 9, 9,10,
  120514. 10,10,10,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,
  120515. 11,10,11,11,12,12,12,13,20,19,19, 9, 9, 9, 9,11,
  120516. 11,11,12,12,12,13,13,19,19,19,13,13,10,10,11,11,
  120517. 12,12,13,13,13,13,19,19,19,14,13,11,10,11,11,12,
  120518. 12,12,13,13,13,19,19,19,19,19,12,12,12,12,13,13,
  120519. 13,13,14,13,19,19,19,19,19,12,12,12,11,12,12,13,
  120520. 14,14,14,19,19,19,19,19,16,15,13,12,13,13,13,14,
  120521. 14,14,19,19,19,19,19,17,17,13,12,13,11,14,13,15,
  120522. 15,
  120523. };
  120524. static float _vq_quantthresh__44c8_s_p8_0[] = {
  120525. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  120526. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  120527. };
  120528. static long _vq_quantmap__44c8_s_p8_0[] = {
  120529. 13, 11, 9, 7, 5, 3, 1, 0,
  120530. 2, 4, 6, 8, 10, 12, 14,
  120531. };
  120532. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_0 = {
  120533. _vq_quantthresh__44c8_s_p8_0,
  120534. _vq_quantmap__44c8_s_p8_0,
  120535. 15,
  120536. 15
  120537. };
  120538. static static_codebook _44c8_s_p8_0 = {
  120539. 2, 225,
  120540. _vq_lengthlist__44c8_s_p8_0,
  120541. 1, -520986624, 1620377600, 4, 0,
  120542. _vq_quantlist__44c8_s_p8_0,
  120543. NULL,
  120544. &_vq_auxt__44c8_s_p8_0,
  120545. NULL,
  120546. 0
  120547. };
  120548. static long _vq_quantlist__44c8_s_p8_1[] = {
  120549. 10,
  120550. 9,
  120551. 11,
  120552. 8,
  120553. 12,
  120554. 7,
  120555. 13,
  120556. 6,
  120557. 14,
  120558. 5,
  120559. 15,
  120560. 4,
  120561. 16,
  120562. 3,
  120563. 17,
  120564. 2,
  120565. 18,
  120566. 1,
  120567. 19,
  120568. 0,
  120569. 20,
  120570. };
  120571. static long _vq_lengthlist__44c8_s_p8_1[] = {
  120572. 4, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  120573. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  120574. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  120575. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  120576. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120577. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  120578. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 9,
  120579. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  120580. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120581. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120582. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  120583. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  120584. 10,10, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9,
  120585. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  120586. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  120587. 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,10,10,10,10,
  120588. 10,10,10, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  120589. 9,10,10,10,10,10,10,10, 9,10,10, 9,10,10,10,10,
  120590. 9,10, 9,10,10, 9,10,10,10,10,10,10,10, 9,10,10,
  120591. 10,10,10,10, 9, 9,10,10, 9,10,10,10,10,10,10,10,
  120592. 10,10,10,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9, 9,
  120593. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  120594. 10, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120595. 10,10,10,10, 9, 9,10, 9, 9, 9,10,10,10,10,10,10,
  120596. 10,10,10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9,10,10,
  120597. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10, 9,
  120598. 9,10, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  120599. 10, 9, 9,10,10, 9,10, 9, 9,
  120600. };
  120601. static float _vq_quantthresh__44c8_s_p8_1[] = {
  120602. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  120603. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  120604. 6.5, 7.5, 8.5, 9.5,
  120605. };
  120606. static long _vq_quantmap__44c8_s_p8_1[] = {
  120607. 19, 17, 15, 13, 11, 9, 7, 5,
  120608. 3, 1, 0, 2, 4, 6, 8, 10,
  120609. 12, 14, 16, 18, 20,
  120610. };
  120611. static encode_aux_threshmatch _vq_auxt__44c8_s_p8_1 = {
  120612. _vq_quantthresh__44c8_s_p8_1,
  120613. _vq_quantmap__44c8_s_p8_1,
  120614. 21,
  120615. 21
  120616. };
  120617. static static_codebook _44c8_s_p8_1 = {
  120618. 2, 441,
  120619. _vq_lengthlist__44c8_s_p8_1,
  120620. 1, -529268736, 1611661312, 5, 0,
  120621. _vq_quantlist__44c8_s_p8_1,
  120622. NULL,
  120623. &_vq_auxt__44c8_s_p8_1,
  120624. NULL,
  120625. 0
  120626. };
  120627. static long _vq_quantlist__44c8_s_p9_0[] = {
  120628. 8,
  120629. 7,
  120630. 9,
  120631. 6,
  120632. 10,
  120633. 5,
  120634. 11,
  120635. 4,
  120636. 12,
  120637. 3,
  120638. 13,
  120639. 2,
  120640. 14,
  120641. 1,
  120642. 15,
  120643. 0,
  120644. 16,
  120645. };
  120646. static long _vq_lengthlist__44c8_s_p9_0[] = {
  120647. 1, 4, 3,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120648. 11, 4, 7, 7,11,11,11,11,11,11,11,11,11,11,11,11,
  120649. 11,11, 4, 8,11,11,11,11,11,11,11,11,11,11,11,11,
  120650. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120651. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120652. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120653. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120654. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120655. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120656. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120657. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120658. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120659. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120660. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  120661. 11,11,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120662. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120663. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120664. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  120665. 10,
  120666. };
  120667. static float _vq_quantthresh__44c8_s_p9_0[] = {
  120668. -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5,
  120669. 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5, 6982.5,
  120670. };
  120671. static long _vq_quantmap__44c8_s_p9_0[] = {
  120672. 15, 13, 11, 9, 7, 5, 3, 1,
  120673. 0, 2, 4, 6, 8, 10, 12, 14,
  120674. 16,
  120675. };
  120676. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_0 = {
  120677. _vq_quantthresh__44c8_s_p9_0,
  120678. _vq_quantmap__44c8_s_p9_0,
  120679. 17,
  120680. 17
  120681. };
  120682. static static_codebook _44c8_s_p9_0 = {
  120683. 2, 289,
  120684. _vq_lengthlist__44c8_s_p9_0,
  120685. 1, -509798400, 1631393792, 5, 0,
  120686. _vq_quantlist__44c8_s_p9_0,
  120687. NULL,
  120688. &_vq_auxt__44c8_s_p9_0,
  120689. NULL,
  120690. 0
  120691. };
  120692. static long _vq_quantlist__44c8_s_p9_1[] = {
  120693. 9,
  120694. 8,
  120695. 10,
  120696. 7,
  120697. 11,
  120698. 6,
  120699. 12,
  120700. 5,
  120701. 13,
  120702. 4,
  120703. 14,
  120704. 3,
  120705. 15,
  120706. 2,
  120707. 16,
  120708. 1,
  120709. 17,
  120710. 0,
  120711. 18,
  120712. };
  120713. static long _vq_lengthlist__44c8_s_p9_1[] = {
  120714. 1, 4, 4, 7, 6, 7, 7, 7, 7, 8, 8, 9, 9,10,10,10,
  120715. 10,11,11, 6, 6, 6, 8, 8, 9, 8, 8, 7,10, 8,11,10,
  120716. 12,11,12,12,13,13, 5, 5, 6, 8, 8, 9, 9, 8, 8,10,
  120717. 9,11,11,12,12,13,13,13,13,17, 8, 8, 9, 9, 9, 9,
  120718. 9, 9,10, 9,12,10,12,12,13,12,13,13,17, 9, 8, 9,
  120719. 9, 9, 9, 9, 9,10,10,12,12,12,12,13,13,13,13,17,
  120720. 13,13, 9, 9,10,10,10,10,11,11,12,11,13,12,13,13,
  120721. 14,15,17,13,13, 9, 8,10, 9,10,10,11,11,12,12,14,
  120722. 13,15,13,14,15,17,17,17, 9,10, 9,10,11,11,12,12,
  120723. 12,12,13,13,14,14,15,15,17,17,17, 9, 8, 9, 8,11,
  120724. 11,12,12,12,12,14,13,14,14,14,15,17,17,17,12,14,
  120725. 9,10,11,11,12,12,14,13,13,14,15,13,15,15,17,17,
  120726. 17,13,11,10, 8,11, 9,13,12,13,13,13,13,13,14,14,
  120727. 14,17,17,17,17,17,11,12,11,11,13,13,14,13,15,14,
  120728. 13,15,16,15,17,17,17,17,17,11,11,12, 8,13,12,14,
  120729. 13,17,14,15,14,15,14,17,17,17,17,17,15,15,12,12,
  120730. 12,12,13,14,14,14,15,14,17,14,17,17,17,17,17,16,
  120731. 17,12,12,13,12,13,13,14,14,14,14,14,14,17,17,17,
  120732. 17,17,17,17,14,14,13,12,13,13,15,15,14,13,15,17,
  120733. 17,17,17,17,17,17,17,13,14,13,13,13,13,14,15,15,
  120734. 15,14,15,17,17,17,17,17,17,17,16,15,13,14,13,13,
  120735. 14,14,15,14,14,16,17,17,17,17,17,17,17,16,16,13,
  120736. 14,13,13,14,14,15,14,15,14,
  120737. };
  120738. static float _vq_quantthresh__44c8_s_p9_1[] = {
  120739. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  120740. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  120741. 367.5, 416.5,
  120742. };
  120743. static long _vq_quantmap__44c8_s_p9_1[] = {
  120744. 17, 15, 13, 11, 9, 7, 5, 3,
  120745. 1, 0, 2, 4, 6, 8, 10, 12,
  120746. 14, 16, 18,
  120747. };
  120748. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_1 = {
  120749. _vq_quantthresh__44c8_s_p9_1,
  120750. _vq_quantmap__44c8_s_p9_1,
  120751. 19,
  120752. 19
  120753. };
  120754. static static_codebook _44c8_s_p9_1 = {
  120755. 2, 361,
  120756. _vq_lengthlist__44c8_s_p9_1,
  120757. 1, -518287360, 1622704128, 5, 0,
  120758. _vq_quantlist__44c8_s_p9_1,
  120759. NULL,
  120760. &_vq_auxt__44c8_s_p9_1,
  120761. NULL,
  120762. 0
  120763. };
  120764. static long _vq_quantlist__44c8_s_p9_2[] = {
  120765. 24,
  120766. 23,
  120767. 25,
  120768. 22,
  120769. 26,
  120770. 21,
  120771. 27,
  120772. 20,
  120773. 28,
  120774. 19,
  120775. 29,
  120776. 18,
  120777. 30,
  120778. 17,
  120779. 31,
  120780. 16,
  120781. 32,
  120782. 15,
  120783. 33,
  120784. 14,
  120785. 34,
  120786. 13,
  120787. 35,
  120788. 12,
  120789. 36,
  120790. 11,
  120791. 37,
  120792. 10,
  120793. 38,
  120794. 9,
  120795. 39,
  120796. 8,
  120797. 40,
  120798. 7,
  120799. 41,
  120800. 6,
  120801. 42,
  120802. 5,
  120803. 43,
  120804. 4,
  120805. 44,
  120806. 3,
  120807. 45,
  120808. 2,
  120809. 46,
  120810. 1,
  120811. 47,
  120812. 0,
  120813. 48,
  120814. };
  120815. static long _vq_lengthlist__44c8_s_p9_2[] = {
  120816. 2, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  120817. 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120818. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  120819. 7,
  120820. };
  120821. static float _vq_quantthresh__44c8_s_p9_2[] = {
  120822. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  120823. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  120824. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  120825. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  120826. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  120827. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  120828. };
  120829. static long _vq_quantmap__44c8_s_p9_2[] = {
  120830. 47, 45, 43, 41, 39, 37, 35, 33,
  120831. 31, 29, 27, 25, 23, 21, 19, 17,
  120832. 15, 13, 11, 9, 7, 5, 3, 1,
  120833. 0, 2, 4, 6, 8, 10, 12, 14,
  120834. 16, 18, 20, 22, 24, 26, 28, 30,
  120835. 32, 34, 36, 38, 40, 42, 44, 46,
  120836. 48,
  120837. };
  120838. static encode_aux_threshmatch _vq_auxt__44c8_s_p9_2 = {
  120839. _vq_quantthresh__44c8_s_p9_2,
  120840. _vq_quantmap__44c8_s_p9_2,
  120841. 49,
  120842. 49
  120843. };
  120844. static static_codebook _44c8_s_p9_2 = {
  120845. 1, 49,
  120846. _vq_lengthlist__44c8_s_p9_2,
  120847. 1, -526909440, 1611661312, 6, 0,
  120848. _vq_quantlist__44c8_s_p9_2,
  120849. NULL,
  120850. &_vq_auxt__44c8_s_p9_2,
  120851. NULL,
  120852. 0
  120853. };
  120854. static long _huff_lengthlist__44c8_s_short[] = {
  120855. 4,11,13,14,15,15,18,17,19,17, 5, 6, 8, 9,10,10,
  120856. 12,15,19,19, 6, 6, 6, 6, 8, 8,11,14,18,19, 8, 6,
  120857. 5, 4, 6, 7,10,13,16,17, 9, 7, 6, 5, 6, 7, 9,12,
  120858. 15,19,10, 8, 7, 6, 6, 6, 7, 9,13,15,12,10, 9, 8,
  120859. 7, 6, 4, 5,10,15,13,13,11, 8, 6, 6, 4, 2, 7,12,
  120860. 17,15,16,10, 8, 8, 7, 6, 9,12,19,18,17,13,11,10,
  120861. 10, 9,11,14,
  120862. };
  120863. static static_codebook _huff_book__44c8_s_short = {
  120864. 2, 100,
  120865. _huff_lengthlist__44c8_s_short,
  120866. 0, 0, 0, 0, 0,
  120867. NULL,
  120868. NULL,
  120869. NULL,
  120870. NULL,
  120871. 0
  120872. };
  120873. static long _huff_lengthlist__44c9_s_long[] = {
  120874. 3, 8,12,14,15,15,15,13,15,15, 6, 5, 8,10,12,12,
  120875. 13,12,14,13,10, 6, 5, 6, 8, 9,11,11,13,13,13, 8,
  120876. 5, 4, 5, 6, 8,10,11,13,14,10, 7, 5, 4, 5, 7, 9,
  120877. 11,12,13,11, 8, 6, 5, 4, 5, 7, 9,11,12,11,10, 8,
  120878. 7, 5, 4, 5, 9,10,13,13,11,10, 8, 6, 5, 4, 7, 9,
  120879. 15,14,13,12,10, 9, 8, 7, 8, 9,12,12,14,13,12,11,
  120880. 10, 9, 8, 9,
  120881. };
  120882. static static_codebook _huff_book__44c9_s_long = {
  120883. 2, 100,
  120884. _huff_lengthlist__44c9_s_long,
  120885. 0, 0, 0, 0, 0,
  120886. NULL,
  120887. NULL,
  120888. NULL,
  120889. NULL,
  120890. 0
  120891. };
  120892. static long _vq_quantlist__44c9_s_p1_0[] = {
  120893. 1,
  120894. 0,
  120895. 2,
  120896. };
  120897. static long _vq_lengthlist__44c9_s_p1_0[] = {
  120898. 1, 5, 5, 0, 5, 5, 0, 5, 5, 6, 8, 8, 0, 9, 8, 0,
  120899. 9, 8, 6, 8, 8, 0, 8, 9, 0, 8, 9, 0, 0, 0, 0, 0,
  120900. 0, 0, 0, 0, 5, 8, 8, 0, 7, 7, 0, 8, 8, 5, 8, 8,
  120901. 0, 7, 8, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5,
  120902. 9, 8, 0, 8, 8, 0, 7, 7, 5, 8, 9, 0, 8, 8, 0, 7,
  120903. 7,
  120904. };
  120905. static float _vq_quantthresh__44c9_s_p1_0[] = {
  120906. -0.5, 0.5,
  120907. };
  120908. static long _vq_quantmap__44c9_s_p1_0[] = {
  120909. 1, 0, 2,
  120910. };
  120911. static encode_aux_threshmatch _vq_auxt__44c9_s_p1_0 = {
  120912. _vq_quantthresh__44c9_s_p1_0,
  120913. _vq_quantmap__44c9_s_p1_0,
  120914. 3,
  120915. 3
  120916. };
  120917. static static_codebook _44c9_s_p1_0 = {
  120918. 4, 81,
  120919. _vq_lengthlist__44c9_s_p1_0,
  120920. 1, -535822336, 1611661312, 2, 0,
  120921. _vq_quantlist__44c9_s_p1_0,
  120922. NULL,
  120923. &_vq_auxt__44c9_s_p1_0,
  120924. NULL,
  120925. 0
  120926. };
  120927. static long _vq_quantlist__44c9_s_p2_0[] = {
  120928. 2,
  120929. 1,
  120930. 3,
  120931. 0,
  120932. 4,
  120933. };
  120934. static long _vq_lengthlist__44c9_s_p2_0[] = {
  120935. 3, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0, 5, 5, 8, 8, 0,
  120936. 7, 7, 9, 9, 0, 0, 0, 9, 9, 6, 7, 7, 9, 8, 0, 8,
  120937. 8, 9, 9, 0, 8, 7, 9, 9, 0, 9,10,10,10, 0, 0, 0,
  120938. 11,10, 6, 7, 7, 8, 9, 0, 8, 8, 9, 9, 0, 7, 8, 9,
  120939. 9, 0,10, 9,11,10, 0, 0, 0,10,10, 8, 9, 8,10,10,
  120940. 0,10,10,12,11, 0,10,10,11,11, 0,12,13,13,13, 0,
  120941. 0, 0,13,12, 8, 8, 9,10,10, 0,10,10,11,12, 0,10,
  120942. 10,11,11, 0,13,12,13,13, 0, 0, 0,13,13, 0, 0, 0,
  120943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120944. 0, 0, 0, 0, 0, 0, 6, 8, 7,10,10, 0, 7, 7,10, 9,
  120945. 0, 7, 7,10,10, 0, 9, 9,10,10, 0, 0, 0,10,10, 6,
  120946. 7, 8,10,10, 0, 7, 7, 9,10, 0, 7, 7,10,10, 0, 9,
  120947. 9,10,10, 0, 0, 0,10,10, 8, 9, 9,11,11, 0,10,10,
  120948. 11,11, 0,10,10,11,11, 0,12,12,12,12, 0, 0, 0,12,
  120949. 12, 8, 9,10,11,11, 0, 9,10,11,11, 0,10,10,11,11,
  120950. 0,12,12,12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0,
  120951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120952. 0, 0, 0, 5, 8, 7,10,10, 0, 7, 7,10,10, 0, 7, 7,
  120953. 10, 9, 0, 9, 9,10,10, 0, 0, 0,10,10, 6, 7, 8,10,
  120954. 10, 0, 7, 7,10,10, 0, 7, 7, 9,10, 0, 9, 9,10,10,
  120955. 0, 0, 0,10,10, 8,10, 9,12,11, 0,10,10,12,11, 0,
  120956. 10, 9,11,11, 0,11,12,12,12, 0, 0, 0,12,12, 8, 9,
  120957. 10,11,12, 0,10,10,11,11, 0, 9,10,11,11, 0,12,11,
  120958. 12,12, 0, 0, 0,12,12, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120960. 7,10, 9,12,12, 0, 9, 9,12,11, 0, 9, 9,11,11, 0,
  120961. 10,10,12,11, 0, 0, 0,11,12, 7, 9,10,12,12, 0, 9,
  120962. 9,11,12, 0, 9, 9,11,11, 0,10,10,11,12, 0, 0, 0,
  120963. 11,11, 9,11,10,13,12, 0,10,10,12,12, 0,10,10,12,
  120964. 12, 0,11,11,12,12, 0, 0, 0,13,12, 9,10,11,12,13,
  120965. 0,10,10,12,12, 0,10,10,12,12, 0,11,12,12,12, 0,
  120966. 0, 0,12,13, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  120970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9,
  120971. 11,10,13,13, 0,10,10,12,12, 0,10,10,12,12, 0,11,
  120972. 12,12,12, 0, 0, 0,12,12, 9,10,11,13,13, 0,10,10,
  120973. 12,12, 0,10,10,12,12, 0,12,11,13,12, 0, 0, 0,12,
  120974. 12,
  120975. };
  120976. static float _vq_quantthresh__44c9_s_p2_0[] = {
  120977. -1.5, -0.5, 0.5, 1.5,
  120978. };
  120979. static long _vq_quantmap__44c9_s_p2_0[] = {
  120980. 3, 1, 0, 2, 4,
  120981. };
  120982. static encode_aux_threshmatch _vq_auxt__44c9_s_p2_0 = {
  120983. _vq_quantthresh__44c9_s_p2_0,
  120984. _vq_quantmap__44c9_s_p2_0,
  120985. 5,
  120986. 5
  120987. };
  120988. static static_codebook _44c9_s_p2_0 = {
  120989. 4, 625,
  120990. _vq_lengthlist__44c9_s_p2_0,
  120991. 1, -533725184, 1611661312, 3, 0,
  120992. _vq_quantlist__44c9_s_p2_0,
  120993. NULL,
  120994. &_vq_auxt__44c9_s_p2_0,
  120995. NULL,
  120996. 0
  120997. };
  120998. static long _vq_quantlist__44c9_s_p3_0[] = {
  120999. 4,
  121000. 3,
  121001. 5,
  121002. 2,
  121003. 6,
  121004. 1,
  121005. 7,
  121006. 0,
  121007. 8,
  121008. };
  121009. static long _vq_lengthlist__44c9_s_p3_0[] = {
  121010. 3, 4, 4, 5, 5, 6, 6, 8, 8, 0, 4, 4, 5, 5, 6, 7,
  121011. 8, 8, 0, 4, 4, 5, 5, 7, 7, 8, 8, 0, 5, 5, 6, 6,
  121012. 7, 7, 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0,
  121013. 7, 7, 8, 8, 9, 9, 0, 0, 0, 7, 7, 8, 8, 9, 9, 0,
  121014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121015. 0,
  121016. };
  121017. static float _vq_quantthresh__44c9_s_p3_0[] = {
  121018. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  121019. };
  121020. static long _vq_quantmap__44c9_s_p3_0[] = {
  121021. 7, 5, 3, 1, 0, 2, 4, 6,
  121022. 8,
  121023. };
  121024. static encode_aux_threshmatch _vq_auxt__44c9_s_p3_0 = {
  121025. _vq_quantthresh__44c9_s_p3_0,
  121026. _vq_quantmap__44c9_s_p3_0,
  121027. 9,
  121028. 9
  121029. };
  121030. static static_codebook _44c9_s_p3_0 = {
  121031. 2, 81,
  121032. _vq_lengthlist__44c9_s_p3_0,
  121033. 1, -531628032, 1611661312, 4, 0,
  121034. _vq_quantlist__44c9_s_p3_0,
  121035. NULL,
  121036. &_vq_auxt__44c9_s_p3_0,
  121037. NULL,
  121038. 0
  121039. };
  121040. static long _vq_quantlist__44c9_s_p4_0[] = {
  121041. 8,
  121042. 7,
  121043. 9,
  121044. 6,
  121045. 10,
  121046. 5,
  121047. 11,
  121048. 4,
  121049. 12,
  121050. 3,
  121051. 13,
  121052. 2,
  121053. 14,
  121054. 1,
  121055. 15,
  121056. 0,
  121057. 16,
  121058. };
  121059. static long _vq_lengthlist__44c9_s_p4_0[] = {
  121060. 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,10,
  121061. 10, 0, 5, 4, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  121062. 11,11, 0, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  121063. 10,11,11, 0, 6, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,
  121064. 11,11,11,12, 0, 0, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,
  121065. 10,11,11,12,12, 0, 0, 0, 7, 7, 7, 7, 9, 9, 9, 9,
  121066. 10,10,11,11,12,12, 0, 0, 0, 7, 7, 7, 8, 9, 9, 9,
  121067. 9,10,10,11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,
  121068. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 8, 8, 9,
  121069. 9,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 0, 0,
  121070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121078. 0,
  121079. };
  121080. static float _vq_quantthresh__44c9_s_p4_0[] = {
  121081. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121082. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121083. };
  121084. static long _vq_quantmap__44c9_s_p4_0[] = {
  121085. 15, 13, 11, 9, 7, 5, 3, 1,
  121086. 0, 2, 4, 6, 8, 10, 12, 14,
  121087. 16,
  121088. };
  121089. static encode_aux_threshmatch _vq_auxt__44c9_s_p4_0 = {
  121090. _vq_quantthresh__44c9_s_p4_0,
  121091. _vq_quantmap__44c9_s_p4_0,
  121092. 17,
  121093. 17
  121094. };
  121095. static static_codebook _44c9_s_p4_0 = {
  121096. 2, 289,
  121097. _vq_lengthlist__44c9_s_p4_0,
  121098. 1, -529530880, 1611661312, 5, 0,
  121099. _vq_quantlist__44c9_s_p4_0,
  121100. NULL,
  121101. &_vq_auxt__44c9_s_p4_0,
  121102. NULL,
  121103. 0
  121104. };
  121105. static long _vq_quantlist__44c9_s_p5_0[] = {
  121106. 1,
  121107. 0,
  121108. 2,
  121109. };
  121110. static long _vq_lengthlist__44c9_s_p5_0[] = {
  121111. 1, 4, 4, 5, 7, 7, 6, 7, 7, 4, 7, 6, 9,10,10,10,
  121112. 10, 9, 4, 6, 7, 9,10,10,10, 9,10, 5, 9, 9, 9,11,
  121113. 11,10,11,11, 7,10, 9,11,12,11,12,12,12, 7, 9,10,
  121114. 11,11,12,12,12,12, 6,10,10,10,12,12,10,12,11, 7,
  121115. 10,10,11,12,12,11,12,12, 7,10,10,11,12,12,12,12,
  121116. 12,
  121117. };
  121118. static float _vq_quantthresh__44c9_s_p5_0[] = {
  121119. -5.5, 5.5,
  121120. };
  121121. static long _vq_quantmap__44c9_s_p5_0[] = {
  121122. 1, 0, 2,
  121123. };
  121124. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_0 = {
  121125. _vq_quantthresh__44c9_s_p5_0,
  121126. _vq_quantmap__44c9_s_p5_0,
  121127. 3,
  121128. 3
  121129. };
  121130. static static_codebook _44c9_s_p5_0 = {
  121131. 4, 81,
  121132. _vq_lengthlist__44c9_s_p5_0,
  121133. 1, -529137664, 1618345984, 2, 0,
  121134. _vq_quantlist__44c9_s_p5_0,
  121135. NULL,
  121136. &_vq_auxt__44c9_s_p5_0,
  121137. NULL,
  121138. 0
  121139. };
  121140. static long _vq_quantlist__44c9_s_p5_1[] = {
  121141. 5,
  121142. 4,
  121143. 6,
  121144. 3,
  121145. 7,
  121146. 2,
  121147. 8,
  121148. 1,
  121149. 9,
  121150. 0,
  121151. 10,
  121152. };
  121153. static long _vq_lengthlist__44c9_s_p5_1[] = {
  121154. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7,11, 5, 5, 6, 6,
  121155. 7, 7, 7, 7, 8, 8,11, 5, 5, 6, 6, 7, 7, 7, 7, 8,
  121156. 8,11, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8,11,11,11, 6,
  121157. 6, 7, 7, 7, 8, 8, 8,11,11,11, 6, 6, 7, 7, 7, 8,
  121158. 8, 8,11,11,11, 6, 6, 7, 7, 7, 7, 8, 8,11,11,11,
  121159. 7, 7, 7, 7, 7, 7, 8, 8,11,11,11,10,10, 7, 7, 7,
  121160. 7, 8, 8,11,11,11,11,11, 7, 7, 7, 7, 7, 7,11,11,
  121161. 11,11,11, 7, 7, 7, 7, 7, 7,
  121162. };
  121163. static float _vq_quantthresh__44c9_s_p5_1[] = {
  121164. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121165. 3.5, 4.5,
  121166. };
  121167. static long _vq_quantmap__44c9_s_p5_1[] = {
  121168. 9, 7, 5, 3, 1, 0, 2, 4,
  121169. 6, 8, 10,
  121170. };
  121171. static encode_aux_threshmatch _vq_auxt__44c9_s_p5_1 = {
  121172. _vq_quantthresh__44c9_s_p5_1,
  121173. _vq_quantmap__44c9_s_p5_1,
  121174. 11,
  121175. 11
  121176. };
  121177. static static_codebook _44c9_s_p5_1 = {
  121178. 2, 121,
  121179. _vq_lengthlist__44c9_s_p5_1,
  121180. 1, -531365888, 1611661312, 4, 0,
  121181. _vq_quantlist__44c9_s_p5_1,
  121182. NULL,
  121183. &_vq_auxt__44c9_s_p5_1,
  121184. NULL,
  121185. 0
  121186. };
  121187. static long _vq_quantlist__44c9_s_p6_0[] = {
  121188. 6,
  121189. 5,
  121190. 7,
  121191. 4,
  121192. 8,
  121193. 3,
  121194. 9,
  121195. 2,
  121196. 10,
  121197. 1,
  121198. 11,
  121199. 0,
  121200. 12,
  121201. };
  121202. static long _vq_lengthlist__44c9_s_p6_0[] = {
  121203. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 5, 4, 4,
  121204. 6, 6, 8, 8, 9, 9, 9, 9,10,10, 6, 4, 4, 6, 6, 8,
  121205. 8, 9, 9, 9, 9,10,10, 0, 6, 6, 7, 7, 8, 8, 9, 9,
  121206. 10,10,11,11, 0, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  121207. 11, 0,10,10, 8, 8, 9, 9,10,10,11,11,12,12, 0,11,
  121208. 11, 8, 8, 9, 9,10,10,11,11,12,12, 0, 0, 0, 0, 0,
  121209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121213. 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121214. };
  121215. static float _vq_quantthresh__44c9_s_p6_0[] = {
  121216. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  121217. 12.5, 17.5, 22.5, 27.5,
  121218. };
  121219. static long _vq_quantmap__44c9_s_p6_0[] = {
  121220. 11, 9, 7, 5, 3, 1, 0, 2,
  121221. 4, 6, 8, 10, 12,
  121222. };
  121223. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_0 = {
  121224. _vq_quantthresh__44c9_s_p6_0,
  121225. _vq_quantmap__44c9_s_p6_0,
  121226. 13,
  121227. 13
  121228. };
  121229. static static_codebook _44c9_s_p6_0 = {
  121230. 2, 169,
  121231. _vq_lengthlist__44c9_s_p6_0,
  121232. 1, -526516224, 1616117760, 4, 0,
  121233. _vq_quantlist__44c9_s_p6_0,
  121234. NULL,
  121235. &_vq_auxt__44c9_s_p6_0,
  121236. NULL,
  121237. 0
  121238. };
  121239. static long _vq_quantlist__44c9_s_p6_1[] = {
  121240. 2,
  121241. 1,
  121242. 3,
  121243. 0,
  121244. 4,
  121245. };
  121246. static long _vq_lengthlist__44c9_s_p6_1[] = {
  121247. 4, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5, 4, 4, 5, 5, 5,
  121248. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  121249. };
  121250. static float _vq_quantthresh__44c9_s_p6_1[] = {
  121251. -1.5, -0.5, 0.5, 1.5,
  121252. };
  121253. static long _vq_quantmap__44c9_s_p6_1[] = {
  121254. 3, 1, 0, 2, 4,
  121255. };
  121256. static encode_aux_threshmatch _vq_auxt__44c9_s_p6_1 = {
  121257. _vq_quantthresh__44c9_s_p6_1,
  121258. _vq_quantmap__44c9_s_p6_1,
  121259. 5,
  121260. 5
  121261. };
  121262. static static_codebook _44c9_s_p6_1 = {
  121263. 2, 25,
  121264. _vq_lengthlist__44c9_s_p6_1,
  121265. 1, -533725184, 1611661312, 3, 0,
  121266. _vq_quantlist__44c9_s_p6_1,
  121267. NULL,
  121268. &_vq_auxt__44c9_s_p6_1,
  121269. NULL,
  121270. 0
  121271. };
  121272. static long _vq_quantlist__44c9_s_p7_0[] = {
  121273. 6,
  121274. 5,
  121275. 7,
  121276. 4,
  121277. 8,
  121278. 3,
  121279. 9,
  121280. 2,
  121281. 10,
  121282. 1,
  121283. 11,
  121284. 0,
  121285. 12,
  121286. };
  121287. static long _vq_lengthlist__44c9_s_p7_0[] = {
  121288. 2, 4, 4, 6, 6, 7, 7, 8, 8,10,10,11,11, 6, 4, 4,
  121289. 6, 6, 8, 8, 9, 9,10,10,12,12, 6, 4, 5, 6, 6, 8,
  121290. 8, 9, 9,10,10,12,12,20, 6, 6, 6, 6, 8, 8, 9,10,
  121291. 11,11,12,12,20, 6, 6, 6, 6, 8, 8,10,10,11,11,12,
  121292. 12,20,10,10, 7, 7, 9, 9,10,10,11,11,12,12,20,11,
  121293. 11, 7, 7, 9, 9,10,10,11,11,12,12,20,20,20, 9, 9,
  121294. 9, 9,11,11,12,12,13,13,20,20,20, 9, 9, 9, 9,11,
  121295. 11,12,12,13,13,20,20,20,13,13,10,10,11,11,12,13,
  121296. 13,13,20,20,20,13,13,10,10,11,11,12,13,13,13,20,
  121297. 20,20,20,19,12,12,12,12,13,13,14,15,19,19,19,19,
  121298. 19,12,12,12,12,13,13,14,14,
  121299. };
  121300. static float _vq_quantthresh__44c9_s_p7_0[] = {
  121301. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  121302. 27.5, 38.5, 49.5, 60.5,
  121303. };
  121304. static long _vq_quantmap__44c9_s_p7_0[] = {
  121305. 11, 9, 7, 5, 3, 1, 0, 2,
  121306. 4, 6, 8, 10, 12,
  121307. };
  121308. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_0 = {
  121309. _vq_quantthresh__44c9_s_p7_0,
  121310. _vq_quantmap__44c9_s_p7_0,
  121311. 13,
  121312. 13
  121313. };
  121314. static static_codebook _44c9_s_p7_0 = {
  121315. 2, 169,
  121316. _vq_lengthlist__44c9_s_p7_0,
  121317. 1, -523206656, 1618345984, 4, 0,
  121318. _vq_quantlist__44c9_s_p7_0,
  121319. NULL,
  121320. &_vq_auxt__44c9_s_p7_0,
  121321. NULL,
  121322. 0
  121323. };
  121324. static long _vq_quantlist__44c9_s_p7_1[] = {
  121325. 5,
  121326. 4,
  121327. 6,
  121328. 3,
  121329. 7,
  121330. 2,
  121331. 8,
  121332. 1,
  121333. 9,
  121334. 0,
  121335. 10,
  121336. };
  121337. static long _vq_lengthlist__44c9_s_p7_1[] = {
  121338. 5, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6,
  121339. 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121340. 7, 8, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 6,
  121341. 6, 7, 7, 7, 7, 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121342. 7, 7, 8, 8, 8, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  121343. 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  121344. 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 7, 8, 8,
  121345. 8, 8, 8, 7, 7, 7, 7, 7, 7,
  121346. };
  121347. static float _vq_quantthresh__44c9_s_p7_1[] = {
  121348. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  121349. 3.5, 4.5,
  121350. };
  121351. static long _vq_quantmap__44c9_s_p7_1[] = {
  121352. 9, 7, 5, 3, 1, 0, 2, 4,
  121353. 6, 8, 10,
  121354. };
  121355. static encode_aux_threshmatch _vq_auxt__44c9_s_p7_1 = {
  121356. _vq_quantthresh__44c9_s_p7_1,
  121357. _vq_quantmap__44c9_s_p7_1,
  121358. 11,
  121359. 11
  121360. };
  121361. static static_codebook _44c9_s_p7_1 = {
  121362. 2, 121,
  121363. _vq_lengthlist__44c9_s_p7_1,
  121364. 1, -531365888, 1611661312, 4, 0,
  121365. _vq_quantlist__44c9_s_p7_1,
  121366. NULL,
  121367. &_vq_auxt__44c9_s_p7_1,
  121368. NULL,
  121369. 0
  121370. };
  121371. static long _vq_quantlist__44c9_s_p8_0[] = {
  121372. 7,
  121373. 6,
  121374. 8,
  121375. 5,
  121376. 9,
  121377. 4,
  121378. 10,
  121379. 3,
  121380. 11,
  121381. 2,
  121382. 12,
  121383. 1,
  121384. 13,
  121385. 0,
  121386. 14,
  121387. };
  121388. static long _vq_lengthlist__44c9_s_p8_0[] = {
  121389. 1, 4, 4, 7, 6, 8, 8, 8, 8, 9, 9,10,10,11,10, 6,
  121390. 5, 5, 7, 7, 9, 9, 8, 9,10,10,11,11,12,12, 6, 5,
  121391. 5, 7, 7, 9, 9, 9, 9,10,10,11,11,12,12,21, 7, 8,
  121392. 8, 8, 9, 9, 9, 9,10,10,11,11,12,12,21, 8, 8, 8,
  121393. 8, 9, 9, 9, 9,10,10,11,11,12,12,21,11,12, 9, 9,
  121394. 10,10,10,10,10,11,11,12,12,12,21,12,12, 9, 8,10,
  121395. 10,10,10,11,11,12,12,13,13,21,21,21, 9, 9, 9, 9,
  121396. 11,11,11,11,12,12,12,13,21,20,20, 9, 9, 9, 9,10,
  121397. 11,11,11,12,12,13,13,20,20,20,13,13,10,10,11,11,
  121398. 12,12,13,13,13,13,20,20,20,13,13,10,10,11,11,12,
  121399. 12,13,13,13,13,20,20,20,20,20,12,12,12,12,12,12,
  121400. 13,13,14,14,20,20,20,20,20,12,12,12,11,13,12,13,
  121401. 13,14,14,20,20,20,20,20,15,16,13,12,13,13,14,13,
  121402. 14,14,20,20,20,20,20,16,15,12,12,13,12,14,13,14,
  121403. 14,
  121404. };
  121405. static float _vq_quantthresh__44c9_s_p8_0[] = {
  121406. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  121407. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  121408. };
  121409. static long _vq_quantmap__44c9_s_p8_0[] = {
  121410. 13, 11, 9, 7, 5, 3, 1, 0,
  121411. 2, 4, 6, 8, 10, 12, 14,
  121412. };
  121413. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_0 = {
  121414. _vq_quantthresh__44c9_s_p8_0,
  121415. _vq_quantmap__44c9_s_p8_0,
  121416. 15,
  121417. 15
  121418. };
  121419. static static_codebook _44c9_s_p8_0 = {
  121420. 2, 225,
  121421. _vq_lengthlist__44c9_s_p8_0,
  121422. 1, -520986624, 1620377600, 4, 0,
  121423. _vq_quantlist__44c9_s_p8_0,
  121424. NULL,
  121425. &_vq_auxt__44c9_s_p8_0,
  121426. NULL,
  121427. 0
  121428. };
  121429. static long _vq_quantlist__44c9_s_p8_1[] = {
  121430. 10,
  121431. 9,
  121432. 11,
  121433. 8,
  121434. 12,
  121435. 7,
  121436. 13,
  121437. 6,
  121438. 14,
  121439. 5,
  121440. 15,
  121441. 4,
  121442. 16,
  121443. 3,
  121444. 17,
  121445. 2,
  121446. 18,
  121447. 1,
  121448. 19,
  121449. 0,
  121450. 20,
  121451. };
  121452. static long _vq_lengthlist__44c9_s_p8_1[] = {
  121453. 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  121454. 8, 8, 8, 8, 8,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  121455. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 6, 6, 7, 7, 8,
  121456. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,
  121457. 7, 7, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121458. 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  121459. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8,
  121460. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  121461. 10, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121462. 9, 9, 9,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121463. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  121464. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  121465. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121466. 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  121467. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9,
  121468. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,
  121469. 10,10,10, 9, 9, 9, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,
  121470. 9,10,10,10,10,10,10,10, 9, 9, 9,10,10,10,10,10,
  121471. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10, 9, 9,10,
  121472. 9,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121473. 10,10,10,10, 9, 9,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  121474. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  121475. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  121476. 10,10, 9, 9,10, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  121477. 10,10,10,10,10, 9, 9,10,10, 9, 9,10, 9, 9, 9,10,
  121478. 10,10,10,10,10,10,10,10,10,10, 9, 9,10, 9, 9, 9,
  121479. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9,
  121480. 9, 9, 9,10, 9, 9, 9, 9, 9,
  121481. };
  121482. static float _vq_quantthresh__44c9_s_p8_1[] = {
  121483. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  121484. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  121485. 6.5, 7.5, 8.5, 9.5,
  121486. };
  121487. static long _vq_quantmap__44c9_s_p8_1[] = {
  121488. 19, 17, 15, 13, 11, 9, 7, 5,
  121489. 3, 1, 0, 2, 4, 6, 8, 10,
  121490. 12, 14, 16, 18, 20,
  121491. };
  121492. static encode_aux_threshmatch _vq_auxt__44c9_s_p8_1 = {
  121493. _vq_quantthresh__44c9_s_p8_1,
  121494. _vq_quantmap__44c9_s_p8_1,
  121495. 21,
  121496. 21
  121497. };
  121498. static static_codebook _44c9_s_p8_1 = {
  121499. 2, 441,
  121500. _vq_lengthlist__44c9_s_p8_1,
  121501. 1, -529268736, 1611661312, 5, 0,
  121502. _vq_quantlist__44c9_s_p8_1,
  121503. NULL,
  121504. &_vq_auxt__44c9_s_p8_1,
  121505. NULL,
  121506. 0
  121507. };
  121508. static long _vq_quantlist__44c9_s_p9_0[] = {
  121509. 9,
  121510. 8,
  121511. 10,
  121512. 7,
  121513. 11,
  121514. 6,
  121515. 12,
  121516. 5,
  121517. 13,
  121518. 4,
  121519. 14,
  121520. 3,
  121521. 15,
  121522. 2,
  121523. 16,
  121524. 1,
  121525. 17,
  121526. 0,
  121527. 18,
  121528. };
  121529. static long _vq_lengthlist__44c9_s_p9_0[] = {
  121530. 1, 4, 3,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121531. 12,12,12, 4, 5, 6,12,12,12,12,12,12,12,12,12,12,
  121532. 12,12,12,12,12,12, 4, 6, 6,12,12,12,12,12,12,12,
  121533. 12,12,12,12,12,12,12,12,12,12,12,11,12,12,12,12,
  121534. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121535. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121536. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121537. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121538. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121539. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121540. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121541. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121542. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121543. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121544. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121545. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  121546. 12,12,12,12,12,12,12,12,12,12,11,11,11,11,11,11,
  121547. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121548. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121549. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121550. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121551. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  121552. 11,11,11,11,11,11,11,11,11,
  121553. };
  121554. static float _vq_quantthresh__44c9_s_p9_0[] = {
  121555. -7913.5, -6982.5, -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5,
  121556. -465.5, 465.5, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  121557. 6982.5, 7913.5,
  121558. };
  121559. static long _vq_quantmap__44c9_s_p9_0[] = {
  121560. 17, 15, 13, 11, 9, 7, 5, 3,
  121561. 1, 0, 2, 4, 6, 8, 10, 12,
  121562. 14, 16, 18,
  121563. };
  121564. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_0 = {
  121565. _vq_quantthresh__44c9_s_p9_0,
  121566. _vq_quantmap__44c9_s_p9_0,
  121567. 19,
  121568. 19
  121569. };
  121570. static static_codebook _44c9_s_p9_0 = {
  121571. 2, 361,
  121572. _vq_lengthlist__44c9_s_p9_0,
  121573. 1, -508535424, 1631393792, 5, 0,
  121574. _vq_quantlist__44c9_s_p9_0,
  121575. NULL,
  121576. &_vq_auxt__44c9_s_p9_0,
  121577. NULL,
  121578. 0
  121579. };
  121580. static long _vq_quantlist__44c9_s_p9_1[] = {
  121581. 9,
  121582. 8,
  121583. 10,
  121584. 7,
  121585. 11,
  121586. 6,
  121587. 12,
  121588. 5,
  121589. 13,
  121590. 4,
  121591. 14,
  121592. 3,
  121593. 15,
  121594. 2,
  121595. 16,
  121596. 1,
  121597. 17,
  121598. 0,
  121599. 18,
  121600. };
  121601. static long _vq_lengthlist__44c9_s_p9_1[] = {
  121602. 1, 4, 4, 7, 7, 7, 7, 8, 7, 9, 8, 9, 9,10,10,11,
  121603. 11,11,11, 6, 5, 5, 8, 8, 9, 9, 9, 8,10, 9,11,10,
  121604. 12,12,13,12,13,13, 5, 5, 5, 8, 8, 9, 9, 9, 9,10,
  121605. 10,11,11,12,12,13,12,13,13,17, 8, 8, 9, 9, 9, 9,
  121606. 9, 9,10,10,12,11,13,12,13,13,13,13,18, 8, 8, 9,
  121607. 9, 9, 9, 9, 9,11,11,12,12,13,13,13,13,13,13,17,
  121608. 13,12, 9, 9,10,10,10,10,11,11,12,12,12,13,13,13,
  121609. 14,14,18,13,12, 9, 9,10,10,10,10,11,11,12,12,13,
  121610. 13,13,14,14,14,17,18,18,10,10,10,10,11,11,11,12,
  121611. 12,12,14,13,14,13,13,14,18,18,18,10, 9,10, 9,11,
  121612. 11,12,12,12,12,13,13,15,14,14,14,18,18,16,13,14,
  121613. 10,11,11,11,12,13,13,13,13,14,13,13,14,14,18,18,
  121614. 18,14,12,11, 9,11,10,13,12,13,13,13,14,14,14,13,
  121615. 14,18,18,17,18,18,11,12,12,12,13,13,14,13,14,14,
  121616. 13,14,14,14,18,18,18,18,17,12,10,12, 9,13,11,13,
  121617. 14,14,14,14,14,15,14,18,18,17,17,18,14,15,12,13,
  121618. 13,13,14,13,14,14,15,14,15,14,18,17,18,18,18,15,
  121619. 15,12,10,14,10,14,14,13,13,14,14,14,14,18,16,18,
  121620. 18,18,18,17,14,14,13,14,14,13,13,14,14,14,15,15,
  121621. 18,18,18,18,17,17,17,14,14,14,12,14,13,14,14,15,
  121622. 14,15,14,18,18,18,18,18,18,18,17,16,13,13,13,14,
  121623. 14,14,14,15,16,15,18,18,18,18,18,18,18,17,17,13,
  121624. 13,13,13,14,13,14,15,15,15,
  121625. };
  121626. static float _vq_quantthresh__44c9_s_p9_1[] = {
  121627. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  121628. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  121629. 367.5, 416.5,
  121630. };
  121631. static long _vq_quantmap__44c9_s_p9_1[] = {
  121632. 17, 15, 13, 11, 9, 7, 5, 3,
  121633. 1, 0, 2, 4, 6, 8, 10, 12,
  121634. 14, 16, 18,
  121635. };
  121636. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_1 = {
  121637. _vq_quantthresh__44c9_s_p9_1,
  121638. _vq_quantmap__44c9_s_p9_1,
  121639. 19,
  121640. 19
  121641. };
  121642. static static_codebook _44c9_s_p9_1 = {
  121643. 2, 361,
  121644. _vq_lengthlist__44c9_s_p9_1,
  121645. 1, -518287360, 1622704128, 5, 0,
  121646. _vq_quantlist__44c9_s_p9_1,
  121647. NULL,
  121648. &_vq_auxt__44c9_s_p9_1,
  121649. NULL,
  121650. 0
  121651. };
  121652. static long _vq_quantlist__44c9_s_p9_2[] = {
  121653. 24,
  121654. 23,
  121655. 25,
  121656. 22,
  121657. 26,
  121658. 21,
  121659. 27,
  121660. 20,
  121661. 28,
  121662. 19,
  121663. 29,
  121664. 18,
  121665. 30,
  121666. 17,
  121667. 31,
  121668. 16,
  121669. 32,
  121670. 15,
  121671. 33,
  121672. 14,
  121673. 34,
  121674. 13,
  121675. 35,
  121676. 12,
  121677. 36,
  121678. 11,
  121679. 37,
  121680. 10,
  121681. 38,
  121682. 9,
  121683. 39,
  121684. 8,
  121685. 40,
  121686. 7,
  121687. 41,
  121688. 6,
  121689. 42,
  121690. 5,
  121691. 43,
  121692. 4,
  121693. 44,
  121694. 3,
  121695. 45,
  121696. 2,
  121697. 46,
  121698. 1,
  121699. 47,
  121700. 0,
  121701. 48,
  121702. };
  121703. static long _vq_lengthlist__44c9_s_p9_2[] = {
  121704. 2, 4, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  121705. 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  121706. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  121707. 7,
  121708. };
  121709. static float _vq_quantthresh__44c9_s_p9_2[] = {
  121710. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  121711. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  121712. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  121713. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  121714. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  121715. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  121716. };
  121717. static long _vq_quantmap__44c9_s_p9_2[] = {
  121718. 47, 45, 43, 41, 39, 37, 35, 33,
  121719. 31, 29, 27, 25, 23, 21, 19, 17,
  121720. 15, 13, 11, 9, 7, 5, 3, 1,
  121721. 0, 2, 4, 6, 8, 10, 12, 14,
  121722. 16, 18, 20, 22, 24, 26, 28, 30,
  121723. 32, 34, 36, 38, 40, 42, 44, 46,
  121724. 48,
  121725. };
  121726. static encode_aux_threshmatch _vq_auxt__44c9_s_p9_2 = {
  121727. _vq_quantthresh__44c9_s_p9_2,
  121728. _vq_quantmap__44c9_s_p9_2,
  121729. 49,
  121730. 49
  121731. };
  121732. static static_codebook _44c9_s_p9_2 = {
  121733. 1, 49,
  121734. _vq_lengthlist__44c9_s_p9_2,
  121735. 1, -526909440, 1611661312, 6, 0,
  121736. _vq_quantlist__44c9_s_p9_2,
  121737. NULL,
  121738. &_vq_auxt__44c9_s_p9_2,
  121739. NULL,
  121740. 0
  121741. };
  121742. static long _huff_lengthlist__44c9_s_short[] = {
  121743. 5,13,18,16,17,17,19,18,19,19, 5, 7,10,11,12,12,
  121744. 13,16,17,18, 6, 6, 7, 7, 9, 9,10,14,17,19, 8, 7,
  121745. 6, 5, 6, 7, 9,12,19,17, 8, 7, 7, 6, 5, 6, 8,11,
  121746. 15,19, 9, 8, 7, 6, 5, 5, 6, 8,13,15,11,10, 8, 8,
  121747. 7, 5, 4, 4,10,14,12,13,11, 9, 7, 6, 4, 2, 6,12,
  121748. 18,16,16,13, 8, 7, 7, 5, 8,13,16,17,18,15,11, 9,
  121749. 9, 8,10,13,
  121750. };
  121751. static static_codebook _huff_book__44c9_s_short = {
  121752. 2, 100,
  121753. _huff_lengthlist__44c9_s_short,
  121754. 0, 0, 0, 0, 0,
  121755. NULL,
  121756. NULL,
  121757. NULL,
  121758. NULL,
  121759. 0
  121760. };
  121761. static long _huff_lengthlist__44c0_s_long[] = {
  121762. 5, 4, 8, 9, 8, 9,10,12,15, 4, 1, 5, 5, 6, 8,11,
  121763. 12,12, 8, 5, 8, 9, 9,11,13,12,12, 9, 5, 8, 5, 7,
  121764. 9,12,13,13, 8, 6, 8, 7, 7, 9,11,11,11, 9, 7, 9,
  121765. 7, 7, 7, 7,10,12,10,10,11, 9, 8, 7, 7, 9,11,11,
  121766. 12,13,12,11, 9, 8, 9,11,13,16,16,15,15,12,10,11,
  121767. 12,
  121768. };
  121769. static static_codebook _huff_book__44c0_s_long = {
  121770. 2, 81,
  121771. _huff_lengthlist__44c0_s_long,
  121772. 0, 0, 0, 0, 0,
  121773. NULL,
  121774. NULL,
  121775. NULL,
  121776. NULL,
  121777. 0
  121778. };
  121779. static long _vq_quantlist__44c0_s_p1_0[] = {
  121780. 1,
  121781. 0,
  121782. 2,
  121783. };
  121784. static long _vq_lengthlist__44c0_s_p1_0[] = {
  121785. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121786. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121791. 0, 0, 0, 7, 9, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121796. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121797. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121798. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121799. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121800. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121801. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121802. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121803. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121804. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121805. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121806. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121807. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121808. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121809. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121810. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121811. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121812. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121813. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121814. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121815. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121816. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121817. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121818. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121819. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121820. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121821. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121822. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121823. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121824. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121825. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121826. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121827. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121828. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121829. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121830. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  121831. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121832. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121833. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121834. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121835. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  121836. 0, 0, 0, 9,10,11, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121837. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121838. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121839. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121840. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121841. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 9,10,11,
  121842. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121843. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121844. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  121877. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121881. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,11,10, 0,
  121882. 0, 0, 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  121883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121886. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,11,
  121887. 0, 0, 0, 0, 0, 0, 9,11,10, 0, 0, 0, 0, 0, 0, 0,
  121888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  121999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122195. 0,
  122196. };
  122197. static float _vq_quantthresh__44c0_s_p1_0[] = {
  122198. -0.5, 0.5,
  122199. };
  122200. static long _vq_quantmap__44c0_s_p1_0[] = {
  122201. 1, 0, 2,
  122202. };
  122203. static encode_aux_threshmatch _vq_auxt__44c0_s_p1_0 = {
  122204. _vq_quantthresh__44c0_s_p1_0,
  122205. _vq_quantmap__44c0_s_p1_0,
  122206. 3,
  122207. 3
  122208. };
  122209. static static_codebook _44c0_s_p1_0 = {
  122210. 8, 6561,
  122211. _vq_lengthlist__44c0_s_p1_0,
  122212. 1, -535822336, 1611661312, 2, 0,
  122213. _vq_quantlist__44c0_s_p1_0,
  122214. NULL,
  122215. &_vq_auxt__44c0_s_p1_0,
  122216. NULL,
  122217. 0
  122218. };
  122219. static long _vq_quantlist__44c0_s_p2_0[] = {
  122220. 2,
  122221. 1,
  122222. 3,
  122223. 0,
  122224. 4,
  122225. };
  122226. static long _vq_lengthlist__44c0_s_p2_0[] = {
  122227. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 6, 0, 0,
  122229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122230. 0, 0, 4, 5, 6, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  122232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122233. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  122234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122266. 0,
  122267. };
  122268. static float _vq_quantthresh__44c0_s_p2_0[] = {
  122269. -1.5, -0.5, 0.5, 1.5,
  122270. };
  122271. static long _vq_quantmap__44c0_s_p2_0[] = {
  122272. 3, 1, 0, 2, 4,
  122273. };
  122274. static encode_aux_threshmatch _vq_auxt__44c0_s_p2_0 = {
  122275. _vq_quantthresh__44c0_s_p2_0,
  122276. _vq_quantmap__44c0_s_p2_0,
  122277. 5,
  122278. 5
  122279. };
  122280. static static_codebook _44c0_s_p2_0 = {
  122281. 4, 625,
  122282. _vq_lengthlist__44c0_s_p2_0,
  122283. 1, -533725184, 1611661312, 3, 0,
  122284. _vq_quantlist__44c0_s_p2_0,
  122285. NULL,
  122286. &_vq_auxt__44c0_s_p2_0,
  122287. NULL,
  122288. 0
  122289. };
  122290. static long _vq_quantlist__44c0_s_p3_0[] = {
  122291. 4,
  122292. 3,
  122293. 5,
  122294. 2,
  122295. 6,
  122296. 1,
  122297. 7,
  122298. 0,
  122299. 8,
  122300. };
  122301. static long _vq_lengthlist__44c0_s_p3_0[] = {
  122302. 1, 3, 2, 8, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  122303. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  122304. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  122305. 8, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  122306. 0, 0, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122307. 0,
  122308. };
  122309. static float _vq_quantthresh__44c0_s_p3_0[] = {
  122310. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122311. };
  122312. static long _vq_quantmap__44c0_s_p3_0[] = {
  122313. 7, 5, 3, 1, 0, 2, 4, 6,
  122314. 8,
  122315. };
  122316. static encode_aux_threshmatch _vq_auxt__44c0_s_p3_0 = {
  122317. _vq_quantthresh__44c0_s_p3_0,
  122318. _vq_quantmap__44c0_s_p3_0,
  122319. 9,
  122320. 9
  122321. };
  122322. static static_codebook _44c0_s_p3_0 = {
  122323. 2, 81,
  122324. _vq_lengthlist__44c0_s_p3_0,
  122325. 1, -531628032, 1611661312, 4, 0,
  122326. _vq_quantlist__44c0_s_p3_0,
  122327. NULL,
  122328. &_vq_auxt__44c0_s_p3_0,
  122329. NULL,
  122330. 0
  122331. };
  122332. static long _vq_quantlist__44c0_s_p4_0[] = {
  122333. 4,
  122334. 3,
  122335. 5,
  122336. 2,
  122337. 6,
  122338. 1,
  122339. 7,
  122340. 0,
  122341. 8,
  122342. };
  122343. static long _vq_lengthlist__44c0_s_p4_0[] = {
  122344. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  122345. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  122346. 7, 8, 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0,
  122347. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 9, 8, 8,10,10, 0,
  122348. 0, 0,10,10, 9, 9,10,10, 0, 0, 0, 0, 0, 9, 9,10,
  122349. 10,
  122350. };
  122351. static float _vq_quantthresh__44c0_s_p4_0[] = {
  122352. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  122353. };
  122354. static long _vq_quantmap__44c0_s_p4_0[] = {
  122355. 7, 5, 3, 1, 0, 2, 4, 6,
  122356. 8,
  122357. };
  122358. static encode_aux_threshmatch _vq_auxt__44c0_s_p4_0 = {
  122359. _vq_quantthresh__44c0_s_p4_0,
  122360. _vq_quantmap__44c0_s_p4_0,
  122361. 9,
  122362. 9
  122363. };
  122364. static static_codebook _44c0_s_p4_0 = {
  122365. 2, 81,
  122366. _vq_lengthlist__44c0_s_p4_0,
  122367. 1, -531628032, 1611661312, 4, 0,
  122368. _vq_quantlist__44c0_s_p4_0,
  122369. NULL,
  122370. &_vq_auxt__44c0_s_p4_0,
  122371. NULL,
  122372. 0
  122373. };
  122374. static long _vq_quantlist__44c0_s_p5_0[] = {
  122375. 8,
  122376. 7,
  122377. 9,
  122378. 6,
  122379. 10,
  122380. 5,
  122381. 11,
  122382. 4,
  122383. 12,
  122384. 3,
  122385. 13,
  122386. 2,
  122387. 14,
  122388. 1,
  122389. 15,
  122390. 0,
  122391. 16,
  122392. };
  122393. static long _vq_lengthlist__44c0_s_p5_0[] = {
  122394. 1, 4, 3, 6, 6, 8, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  122395. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9, 9,10,10,10,
  122396. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  122397. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  122398. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  122399. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  122400. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  122401. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  122402. 10,10,11,11,11,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  122403. 10,10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,
  122404. 10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  122405. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  122406. 10,10,11,11,11,11,11,12,12,12,13,13, 0, 0, 0, 0,
  122407. 0, 0, 0,11,10,11,11,11,11,12,12,13,13, 0, 0, 0,
  122408. 0, 0, 0, 0,11,11,12,11,12,12,12,12,13,13, 0, 0,
  122409. 0, 0, 0, 0, 0,11,11,11,12,12,12,12,13,13,13, 0,
  122410. 0, 0, 0, 0, 0, 0,12,12,12,12,12,13,13,13,14,14,
  122411. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  122412. 14,
  122413. };
  122414. static float _vq_quantthresh__44c0_s_p5_0[] = {
  122415. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122416. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122417. };
  122418. static long _vq_quantmap__44c0_s_p5_0[] = {
  122419. 15, 13, 11, 9, 7, 5, 3, 1,
  122420. 0, 2, 4, 6, 8, 10, 12, 14,
  122421. 16,
  122422. };
  122423. static encode_aux_threshmatch _vq_auxt__44c0_s_p5_0 = {
  122424. _vq_quantthresh__44c0_s_p5_0,
  122425. _vq_quantmap__44c0_s_p5_0,
  122426. 17,
  122427. 17
  122428. };
  122429. static static_codebook _44c0_s_p5_0 = {
  122430. 2, 289,
  122431. _vq_lengthlist__44c0_s_p5_0,
  122432. 1, -529530880, 1611661312, 5, 0,
  122433. _vq_quantlist__44c0_s_p5_0,
  122434. NULL,
  122435. &_vq_auxt__44c0_s_p5_0,
  122436. NULL,
  122437. 0
  122438. };
  122439. static long _vq_quantlist__44c0_s_p6_0[] = {
  122440. 1,
  122441. 0,
  122442. 2,
  122443. };
  122444. static long _vq_lengthlist__44c0_s_p6_0[] = {
  122445. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,10,
  122446. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,11,11,
  122447. 11,12,10,11, 6, 9, 9,11,10,11,11,10,10, 6, 9, 9,
  122448. 11,10,11,11,10,10, 7,11,10,12,11,11,11,11,11, 7,
  122449. 9, 9,10,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  122450. 10,
  122451. };
  122452. static float _vq_quantthresh__44c0_s_p6_0[] = {
  122453. -5.5, 5.5,
  122454. };
  122455. static long _vq_quantmap__44c0_s_p6_0[] = {
  122456. 1, 0, 2,
  122457. };
  122458. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_0 = {
  122459. _vq_quantthresh__44c0_s_p6_0,
  122460. _vq_quantmap__44c0_s_p6_0,
  122461. 3,
  122462. 3
  122463. };
  122464. static static_codebook _44c0_s_p6_0 = {
  122465. 4, 81,
  122466. _vq_lengthlist__44c0_s_p6_0,
  122467. 1, -529137664, 1618345984, 2, 0,
  122468. _vq_quantlist__44c0_s_p6_0,
  122469. NULL,
  122470. &_vq_auxt__44c0_s_p6_0,
  122471. NULL,
  122472. 0
  122473. };
  122474. static long _vq_quantlist__44c0_s_p6_1[] = {
  122475. 5,
  122476. 4,
  122477. 6,
  122478. 3,
  122479. 7,
  122480. 2,
  122481. 8,
  122482. 1,
  122483. 9,
  122484. 0,
  122485. 10,
  122486. };
  122487. static long _vq_lengthlist__44c0_s_p6_1[] = {
  122488. 2, 3, 3, 6, 6, 7, 7, 7, 7, 7, 8,10,10,10, 6, 6,
  122489. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  122490. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  122491. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 7, 8, 8, 8, 8,
  122492. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  122493. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  122494. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  122495. 10,10,10, 8, 8, 8, 8, 8, 8,
  122496. };
  122497. static float _vq_quantthresh__44c0_s_p6_1[] = {
  122498. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  122499. 3.5, 4.5,
  122500. };
  122501. static long _vq_quantmap__44c0_s_p6_1[] = {
  122502. 9, 7, 5, 3, 1, 0, 2, 4,
  122503. 6, 8, 10,
  122504. };
  122505. static encode_aux_threshmatch _vq_auxt__44c0_s_p6_1 = {
  122506. _vq_quantthresh__44c0_s_p6_1,
  122507. _vq_quantmap__44c0_s_p6_1,
  122508. 11,
  122509. 11
  122510. };
  122511. static static_codebook _44c0_s_p6_1 = {
  122512. 2, 121,
  122513. _vq_lengthlist__44c0_s_p6_1,
  122514. 1, -531365888, 1611661312, 4, 0,
  122515. _vq_quantlist__44c0_s_p6_1,
  122516. NULL,
  122517. &_vq_auxt__44c0_s_p6_1,
  122518. NULL,
  122519. 0
  122520. };
  122521. static long _vq_quantlist__44c0_s_p7_0[] = {
  122522. 6,
  122523. 5,
  122524. 7,
  122525. 4,
  122526. 8,
  122527. 3,
  122528. 9,
  122529. 2,
  122530. 10,
  122531. 1,
  122532. 11,
  122533. 0,
  122534. 12,
  122535. };
  122536. static long _vq_lengthlist__44c0_s_p7_0[] = {
  122537. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  122538. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  122539. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  122540. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  122541. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  122542. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  122543. 10,10,11,11,11,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  122544. 11,11,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  122545. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  122546. 0, 0, 0, 0,11,11,11,11,13,12,13,13, 0, 0, 0, 0,
  122547. 0,12,12,11,11,12,12,13,13,
  122548. };
  122549. static float _vq_quantthresh__44c0_s_p7_0[] = {
  122550. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  122551. 12.5, 17.5, 22.5, 27.5,
  122552. };
  122553. static long _vq_quantmap__44c0_s_p7_0[] = {
  122554. 11, 9, 7, 5, 3, 1, 0, 2,
  122555. 4, 6, 8, 10, 12,
  122556. };
  122557. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_0 = {
  122558. _vq_quantthresh__44c0_s_p7_0,
  122559. _vq_quantmap__44c0_s_p7_0,
  122560. 13,
  122561. 13
  122562. };
  122563. static static_codebook _44c0_s_p7_0 = {
  122564. 2, 169,
  122565. _vq_lengthlist__44c0_s_p7_0,
  122566. 1, -526516224, 1616117760, 4, 0,
  122567. _vq_quantlist__44c0_s_p7_0,
  122568. NULL,
  122569. &_vq_auxt__44c0_s_p7_0,
  122570. NULL,
  122571. 0
  122572. };
  122573. static long _vq_quantlist__44c0_s_p7_1[] = {
  122574. 2,
  122575. 1,
  122576. 3,
  122577. 0,
  122578. 4,
  122579. };
  122580. static long _vq_lengthlist__44c0_s_p7_1[] = {
  122581. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  122582. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  122583. };
  122584. static float _vq_quantthresh__44c0_s_p7_1[] = {
  122585. -1.5, -0.5, 0.5, 1.5,
  122586. };
  122587. static long _vq_quantmap__44c0_s_p7_1[] = {
  122588. 3, 1, 0, 2, 4,
  122589. };
  122590. static encode_aux_threshmatch _vq_auxt__44c0_s_p7_1 = {
  122591. _vq_quantthresh__44c0_s_p7_1,
  122592. _vq_quantmap__44c0_s_p7_1,
  122593. 5,
  122594. 5
  122595. };
  122596. static static_codebook _44c0_s_p7_1 = {
  122597. 2, 25,
  122598. _vq_lengthlist__44c0_s_p7_1,
  122599. 1, -533725184, 1611661312, 3, 0,
  122600. _vq_quantlist__44c0_s_p7_1,
  122601. NULL,
  122602. &_vq_auxt__44c0_s_p7_1,
  122603. NULL,
  122604. 0
  122605. };
  122606. static long _vq_quantlist__44c0_s_p8_0[] = {
  122607. 2,
  122608. 1,
  122609. 3,
  122610. 0,
  122611. 4,
  122612. };
  122613. static long _vq_lengthlist__44c0_s_p8_0[] = {
  122614. 1, 5, 5,10,10, 6, 9, 8,10,10, 6,10, 9,10,10,10,
  122615. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122616. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122617. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122618. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122619. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122620. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122621. 10,10,10,10,10,10,10,10,10,10,10,10,10, 8,10,10,
  122622. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122623. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122624. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122625. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  122626. 10,10,10,10,10,10,10,10,11,11,11,11,11,11,11,11,
  122627. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122628. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122629. 11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,
  122630. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122631. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122632. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122633. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122634. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122635. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122636. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122637. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122638. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122639. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122640. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122641. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122642. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122643. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122644. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122645. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122646. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122647. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122648. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122649. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122650. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122651. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122652. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  122653. 11,
  122654. };
  122655. static float _vq_quantthresh__44c0_s_p8_0[] = {
  122656. -331.5, -110.5, 110.5, 331.5,
  122657. };
  122658. static long _vq_quantmap__44c0_s_p8_0[] = {
  122659. 3, 1, 0, 2, 4,
  122660. };
  122661. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_0 = {
  122662. _vq_quantthresh__44c0_s_p8_0,
  122663. _vq_quantmap__44c0_s_p8_0,
  122664. 5,
  122665. 5
  122666. };
  122667. static static_codebook _44c0_s_p8_0 = {
  122668. 4, 625,
  122669. _vq_lengthlist__44c0_s_p8_0,
  122670. 1, -518283264, 1627103232, 3, 0,
  122671. _vq_quantlist__44c0_s_p8_0,
  122672. NULL,
  122673. &_vq_auxt__44c0_s_p8_0,
  122674. NULL,
  122675. 0
  122676. };
  122677. static long _vq_quantlist__44c0_s_p8_1[] = {
  122678. 6,
  122679. 5,
  122680. 7,
  122681. 4,
  122682. 8,
  122683. 3,
  122684. 9,
  122685. 2,
  122686. 10,
  122687. 1,
  122688. 11,
  122689. 0,
  122690. 12,
  122691. };
  122692. static long _vq_lengthlist__44c0_s_p8_1[] = {
  122693. 1, 4, 4, 6, 6, 7, 7, 9, 9,11,12,13,12, 6, 5, 5,
  122694. 7, 7, 8, 8,10, 9,12,12,12,12, 6, 5, 5, 7, 7, 8,
  122695. 8,10, 9,12,11,11,13,16, 7, 7, 8, 8, 9, 9,10,10,
  122696. 12,12,13,12,16, 7, 7, 8, 7, 9, 9,10,10,11,12,12,
  122697. 13,16,10,10, 8, 8,10,10,11,12,12,12,13,13,16,11,
  122698. 10, 8, 7,11,10,11,11,12,11,13,13,16,16,16,10,10,
  122699. 10,10,11,11,13,12,13,13,16,16,16,11, 9,11, 9,15,
  122700. 13,12,13,13,13,16,16,16,15,13,11,11,12,13,12,12,
  122701. 14,13,16,16,16,14,13,11,11,13,12,14,13,13,13,16,
  122702. 16,16,16,16,13,13,13,12,14,13,14,14,16,16,16,16,
  122703. 16,13,13,12,12,14,14,15,13,
  122704. };
  122705. static float _vq_quantthresh__44c0_s_p8_1[] = {
  122706. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  122707. 42.5, 59.5, 76.5, 93.5,
  122708. };
  122709. static long _vq_quantmap__44c0_s_p8_1[] = {
  122710. 11, 9, 7, 5, 3, 1, 0, 2,
  122711. 4, 6, 8, 10, 12,
  122712. };
  122713. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_1 = {
  122714. _vq_quantthresh__44c0_s_p8_1,
  122715. _vq_quantmap__44c0_s_p8_1,
  122716. 13,
  122717. 13
  122718. };
  122719. static static_codebook _44c0_s_p8_1 = {
  122720. 2, 169,
  122721. _vq_lengthlist__44c0_s_p8_1,
  122722. 1, -522616832, 1620115456, 4, 0,
  122723. _vq_quantlist__44c0_s_p8_1,
  122724. NULL,
  122725. &_vq_auxt__44c0_s_p8_1,
  122726. NULL,
  122727. 0
  122728. };
  122729. static long _vq_quantlist__44c0_s_p8_2[] = {
  122730. 8,
  122731. 7,
  122732. 9,
  122733. 6,
  122734. 10,
  122735. 5,
  122736. 11,
  122737. 4,
  122738. 12,
  122739. 3,
  122740. 13,
  122741. 2,
  122742. 14,
  122743. 1,
  122744. 15,
  122745. 0,
  122746. 16,
  122747. };
  122748. static long _vq_lengthlist__44c0_s_p8_2[] = {
  122749. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  122750. 8,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  122751. 9, 9,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  122752. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  122753. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  122754. 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 8, 9, 9,
  122755. 9, 9, 9,10, 9,10,10,10,10, 7, 7, 8, 8, 9, 9, 9,
  122756. 9, 9, 9,10, 9,10,10,10,10,10, 8, 8, 8, 9, 9, 9,
  122757. 9, 9, 9, 9,10,10,10, 9,11,10,10,10,10, 8, 8, 9,
  122758. 9, 9, 9, 9,10, 9, 9, 9,10,10,10,10,11,11, 9, 9,
  122759. 9, 9, 9, 9, 9, 9,10, 9, 9,10,11,10,10,11,11, 9,
  122760. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  122761. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,10,11,
  122762. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  122763. 11,11,11,11, 9,10, 9,10, 9, 9, 9, 9,10, 9,10,11,
  122764. 10,11,10,10,10,10,10, 9, 9, 9,10, 9, 9, 9,10,11,
  122765. 11,10,11,11,10,11,10,10,10, 9, 9, 9, 9,10, 9, 9,
  122766. 10,11,10,11,11,11,11,10,11,10,10, 9,10, 9, 9, 9,
  122767. 10,
  122768. };
  122769. static float _vq_quantthresh__44c0_s_p8_2[] = {
  122770. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  122771. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  122772. };
  122773. static long _vq_quantmap__44c0_s_p8_2[] = {
  122774. 15, 13, 11, 9, 7, 5, 3, 1,
  122775. 0, 2, 4, 6, 8, 10, 12, 14,
  122776. 16,
  122777. };
  122778. static encode_aux_threshmatch _vq_auxt__44c0_s_p8_2 = {
  122779. _vq_quantthresh__44c0_s_p8_2,
  122780. _vq_quantmap__44c0_s_p8_2,
  122781. 17,
  122782. 17
  122783. };
  122784. static static_codebook _44c0_s_p8_2 = {
  122785. 2, 289,
  122786. _vq_lengthlist__44c0_s_p8_2,
  122787. 1, -529530880, 1611661312, 5, 0,
  122788. _vq_quantlist__44c0_s_p8_2,
  122789. NULL,
  122790. &_vq_auxt__44c0_s_p8_2,
  122791. NULL,
  122792. 0
  122793. };
  122794. static long _huff_lengthlist__44c0_s_short[] = {
  122795. 9, 8,12,11,12,13,14,14,16, 6, 1, 5, 6, 6, 9,12,
  122796. 14,17, 9, 4, 5, 9, 7, 9,13,15,16, 8, 5, 8, 6, 8,
  122797. 10,13,17,17, 9, 6, 7, 7, 8, 9,13,15,17,11, 8, 9,
  122798. 9, 9,10,12,16,16,13, 7, 8, 7, 7, 9,12,14,15,13,
  122799. 6, 7, 5, 5, 7,10,13,13,14, 7, 8, 5, 6, 7, 9,10,
  122800. 12,
  122801. };
  122802. static static_codebook _huff_book__44c0_s_short = {
  122803. 2, 81,
  122804. _huff_lengthlist__44c0_s_short,
  122805. 0, 0, 0, 0, 0,
  122806. NULL,
  122807. NULL,
  122808. NULL,
  122809. NULL,
  122810. 0
  122811. };
  122812. static long _huff_lengthlist__44c0_sm_long[] = {
  122813. 5, 4, 9,10, 9,10,11,12,13, 4, 1, 5, 7, 7, 9,11,
  122814. 12,14, 8, 5, 7, 9, 8,10,13,13,13,10, 7, 9, 4, 6,
  122815. 7,10,12,14, 9, 6, 7, 6, 6, 7,10,12,12, 9, 8, 9,
  122816. 7, 6, 7, 8,11,12,11,11,11, 9, 8, 7, 8,10,12,12,
  122817. 13,14,12,11, 9, 9, 9,12,12,17,17,15,16,12,10,11,
  122818. 13,
  122819. };
  122820. static static_codebook _huff_book__44c0_sm_long = {
  122821. 2, 81,
  122822. _huff_lengthlist__44c0_sm_long,
  122823. 0, 0, 0, 0, 0,
  122824. NULL,
  122825. NULL,
  122826. NULL,
  122827. NULL,
  122828. 0
  122829. };
  122830. static long _vq_quantlist__44c0_sm_p1_0[] = {
  122831. 1,
  122832. 0,
  122833. 2,
  122834. };
  122835. static long _vq_lengthlist__44c0_sm_p1_0[] = {
  122836. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  122837. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122842. 0, 0, 0, 7, 8, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  122847. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122848. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122849. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122850. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122851. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122852. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122853. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122854. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122855. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122856. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122857. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122858. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122859. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122860. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122861. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122862. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122863. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122864. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122865. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122866. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122867. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122868. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122869. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  122882. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  122883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  122887. 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122892. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  122928. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122932. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  122933. 0, 0, 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  122934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122937. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  122938. 0, 0, 0, 0, 0, 0, 9,10,10, 0, 0, 0, 0, 0, 0, 0,
  122939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  122999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123246. 0,
  123247. };
  123248. static float _vq_quantthresh__44c0_sm_p1_0[] = {
  123249. -0.5, 0.5,
  123250. };
  123251. static long _vq_quantmap__44c0_sm_p1_0[] = {
  123252. 1, 0, 2,
  123253. };
  123254. static encode_aux_threshmatch _vq_auxt__44c0_sm_p1_0 = {
  123255. _vq_quantthresh__44c0_sm_p1_0,
  123256. _vq_quantmap__44c0_sm_p1_0,
  123257. 3,
  123258. 3
  123259. };
  123260. static static_codebook _44c0_sm_p1_0 = {
  123261. 8, 6561,
  123262. _vq_lengthlist__44c0_sm_p1_0,
  123263. 1, -535822336, 1611661312, 2, 0,
  123264. _vq_quantlist__44c0_sm_p1_0,
  123265. NULL,
  123266. &_vq_auxt__44c0_sm_p1_0,
  123267. NULL,
  123268. 0
  123269. };
  123270. static long _vq_quantlist__44c0_sm_p2_0[] = {
  123271. 2,
  123272. 1,
  123273. 3,
  123274. 0,
  123275. 4,
  123276. };
  123277. static long _vq_lengthlist__44c0_sm_p2_0[] = {
  123278. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  123280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123281. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  123283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123284. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  123285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123317. 0,
  123318. };
  123319. static float _vq_quantthresh__44c0_sm_p2_0[] = {
  123320. -1.5, -0.5, 0.5, 1.5,
  123321. };
  123322. static long _vq_quantmap__44c0_sm_p2_0[] = {
  123323. 3, 1, 0, 2, 4,
  123324. };
  123325. static encode_aux_threshmatch _vq_auxt__44c0_sm_p2_0 = {
  123326. _vq_quantthresh__44c0_sm_p2_0,
  123327. _vq_quantmap__44c0_sm_p2_0,
  123328. 5,
  123329. 5
  123330. };
  123331. static static_codebook _44c0_sm_p2_0 = {
  123332. 4, 625,
  123333. _vq_lengthlist__44c0_sm_p2_0,
  123334. 1, -533725184, 1611661312, 3, 0,
  123335. _vq_quantlist__44c0_sm_p2_0,
  123336. NULL,
  123337. &_vq_auxt__44c0_sm_p2_0,
  123338. NULL,
  123339. 0
  123340. };
  123341. static long _vq_quantlist__44c0_sm_p3_0[] = {
  123342. 4,
  123343. 3,
  123344. 5,
  123345. 2,
  123346. 6,
  123347. 1,
  123348. 7,
  123349. 0,
  123350. 8,
  123351. };
  123352. static long _vq_lengthlist__44c0_sm_p3_0[] = {
  123353. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 4, 7, 7, 0, 0,
  123354. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  123355. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  123356. 9,10, 0, 0, 0, 0, 0, 0, 0, 9, 9, 0, 0, 0, 0, 0,
  123357. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123358. 0,
  123359. };
  123360. static float _vq_quantthresh__44c0_sm_p3_0[] = {
  123361. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123362. };
  123363. static long _vq_quantmap__44c0_sm_p3_0[] = {
  123364. 7, 5, 3, 1, 0, 2, 4, 6,
  123365. 8,
  123366. };
  123367. static encode_aux_threshmatch _vq_auxt__44c0_sm_p3_0 = {
  123368. _vq_quantthresh__44c0_sm_p3_0,
  123369. _vq_quantmap__44c0_sm_p3_0,
  123370. 9,
  123371. 9
  123372. };
  123373. static static_codebook _44c0_sm_p3_0 = {
  123374. 2, 81,
  123375. _vq_lengthlist__44c0_sm_p3_0,
  123376. 1, -531628032, 1611661312, 4, 0,
  123377. _vq_quantlist__44c0_sm_p3_0,
  123378. NULL,
  123379. &_vq_auxt__44c0_sm_p3_0,
  123380. NULL,
  123381. 0
  123382. };
  123383. static long _vq_quantlist__44c0_sm_p4_0[] = {
  123384. 4,
  123385. 3,
  123386. 5,
  123387. 2,
  123388. 6,
  123389. 1,
  123390. 7,
  123391. 0,
  123392. 8,
  123393. };
  123394. static long _vq_lengthlist__44c0_sm_p4_0[] = {
  123395. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  123396. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  123397. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  123398. 9, 9, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  123399. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  123400. 11,
  123401. };
  123402. static float _vq_quantthresh__44c0_sm_p4_0[] = {
  123403. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  123404. };
  123405. static long _vq_quantmap__44c0_sm_p4_0[] = {
  123406. 7, 5, 3, 1, 0, 2, 4, 6,
  123407. 8,
  123408. };
  123409. static encode_aux_threshmatch _vq_auxt__44c0_sm_p4_0 = {
  123410. _vq_quantthresh__44c0_sm_p4_0,
  123411. _vq_quantmap__44c0_sm_p4_0,
  123412. 9,
  123413. 9
  123414. };
  123415. static static_codebook _44c0_sm_p4_0 = {
  123416. 2, 81,
  123417. _vq_lengthlist__44c0_sm_p4_0,
  123418. 1, -531628032, 1611661312, 4, 0,
  123419. _vq_quantlist__44c0_sm_p4_0,
  123420. NULL,
  123421. &_vq_auxt__44c0_sm_p4_0,
  123422. NULL,
  123423. 0
  123424. };
  123425. static long _vq_quantlist__44c0_sm_p5_0[] = {
  123426. 8,
  123427. 7,
  123428. 9,
  123429. 6,
  123430. 10,
  123431. 5,
  123432. 11,
  123433. 4,
  123434. 12,
  123435. 3,
  123436. 13,
  123437. 2,
  123438. 14,
  123439. 1,
  123440. 15,
  123441. 0,
  123442. 16,
  123443. };
  123444. static long _vq_lengthlist__44c0_sm_p5_0[] = {
  123445. 1, 4, 4, 6, 6, 8, 8, 8, 8, 8, 8, 9, 9,10,10,11,
  123446. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,11,
  123447. 11,11, 0, 5, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  123448. 11,11,11, 0, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  123449. 11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,
  123450. 10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  123451. 11,11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  123452. 10,11,11,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  123453. 10,10,11,11,12,12,12,13, 0, 0, 0, 0, 0, 9, 9,10,
  123454. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  123455. 10,10,11,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  123456. 9,10,10,11,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  123457. 10,10,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0,
  123458. 0, 0, 0,10,10,11,11,12,12,12,13,13,13, 0, 0, 0,
  123459. 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14, 0, 0,
  123460. 0, 0, 0, 0, 0,11,11,12,11,12,12,13,13,13,13, 0,
  123461. 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,13,13,14,14,
  123462. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  123463. 14,
  123464. };
  123465. static float _vq_quantthresh__44c0_sm_p5_0[] = {
  123466. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123467. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123468. };
  123469. static long _vq_quantmap__44c0_sm_p5_0[] = {
  123470. 15, 13, 11, 9, 7, 5, 3, 1,
  123471. 0, 2, 4, 6, 8, 10, 12, 14,
  123472. 16,
  123473. };
  123474. static encode_aux_threshmatch _vq_auxt__44c0_sm_p5_0 = {
  123475. _vq_quantthresh__44c0_sm_p5_0,
  123476. _vq_quantmap__44c0_sm_p5_0,
  123477. 17,
  123478. 17
  123479. };
  123480. static static_codebook _44c0_sm_p5_0 = {
  123481. 2, 289,
  123482. _vq_lengthlist__44c0_sm_p5_0,
  123483. 1, -529530880, 1611661312, 5, 0,
  123484. _vq_quantlist__44c0_sm_p5_0,
  123485. NULL,
  123486. &_vq_auxt__44c0_sm_p5_0,
  123487. NULL,
  123488. 0
  123489. };
  123490. static long _vq_quantlist__44c0_sm_p6_0[] = {
  123491. 1,
  123492. 0,
  123493. 2,
  123494. };
  123495. static long _vq_lengthlist__44c0_sm_p6_0[] = {
  123496. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  123497. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  123498. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  123499. 11,10,11,11,10,10, 7,11,10,11,11,11,11,11,11, 6,
  123500. 9, 9,11,10,10,11,11,10, 6, 9, 9,11,10,10,11,10,
  123501. 11,
  123502. };
  123503. static float _vq_quantthresh__44c0_sm_p6_0[] = {
  123504. -5.5, 5.5,
  123505. };
  123506. static long _vq_quantmap__44c0_sm_p6_0[] = {
  123507. 1, 0, 2,
  123508. };
  123509. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_0 = {
  123510. _vq_quantthresh__44c0_sm_p6_0,
  123511. _vq_quantmap__44c0_sm_p6_0,
  123512. 3,
  123513. 3
  123514. };
  123515. static static_codebook _44c0_sm_p6_0 = {
  123516. 4, 81,
  123517. _vq_lengthlist__44c0_sm_p6_0,
  123518. 1, -529137664, 1618345984, 2, 0,
  123519. _vq_quantlist__44c0_sm_p6_0,
  123520. NULL,
  123521. &_vq_auxt__44c0_sm_p6_0,
  123522. NULL,
  123523. 0
  123524. };
  123525. static long _vq_quantlist__44c0_sm_p6_1[] = {
  123526. 5,
  123527. 4,
  123528. 6,
  123529. 3,
  123530. 7,
  123531. 2,
  123532. 8,
  123533. 1,
  123534. 9,
  123535. 0,
  123536. 10,
  123537. };
  123538. static long _vq_lengthlist__44c0_sm_p6_1[] = {
  123539. 2, 4, 4, 6, 6, 7, 7, 7, 7, 7, 8, 9, 5, 5, 6, 6,
  123540. 7, 7, 8, 8, 8, 8, 9, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  123541. 8,10, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  123542. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  123543. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  123544. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  123545. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  123546. 10,10,10, 8, 8, 8, 8, 8, 8,
  123547. };
  123548. static float _vq_quantthresh__44c0_sm_p6_1[] = {
  123549. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  123550. 3.5, 4.5,
  123551. };
  123552. static long _vq_quantmap__44c0_sm_p6_1[] = {
  123553. 9, 7, 5, 3, 1, 0, 2, 4,
  123554. 6, 8, 10,
  123555. };
  123556. static encode_aux_threshmatch _vq_auxt__44c0_sm_p6_1 = {
  123557. _vq_quantthresh__44c0_sm_p6_1,
  123558. _vq_quantmap__44c0_sm_p6_1,
  123559. 11,
  123560. 11
  123561. };
  123562. static static_codebook _44c0_sm_p6_1 = {
  123563. 2, 121,
  123564. _vq_lengthlist__44c0_sm_p6_1,
  123565. 1, -531365888, 1611661312, 4, 0,
  123566. _vq_quantlist__44c0_sm_p6_1,
  123567. NULL,
  123568. &_vq_auxt__44c0_sm_p6_1,
  123569. NULL,
  123570. 0
  123571. };
  123572. static long _vq_quantlist__44c0_sm_p7_0[] = {
  123573. 6,
  123574. 5,
  123575. 7,
  123576. 4,
  123577. 8,
  123578. 3,
  123579. 9,
  123580. 2,
  123581. 10,
  123582. 1,
  123583. 11,
  123584. 0,
  123585. 12,
  123586. };
  123587. static long _vq_lengthlist__44c0_sm_p7_0[] = {
  123588. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  123589. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 6, 5, 7, 7, 8,
  123590. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  123591. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  123592. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  123593. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0, 9,10,
  123594. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10, 9, 9,11,
  123595. 11,12,12,12,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  123596. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  123597. 0, 0, 0, 0,11,12,11,11,13,12,13,13, 0, 0, 0, 0,
  123598. 0,12,12,11,11,13,12,14,14,
  123599. };
  123600. static float _vq_quantthresh__44c0_sm_p7_0[] = {
  123601. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  123602. 12.5, 17.5, 22.5, 27.5,
  123603. };
  123604. static long _vq_quantmap__44c0_sm_p7_0[] = {
  123605. 11, 9, 7, 5, 3, 1, 0, 2,
  123606. 4, 6, 8, 10, 12,
  123607. };
  123608. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_0 = {
  123609. _vq_quantthresh__44c0_sm_p7_0,
  123610. _vq_quantmap__44c0_sm_p7_0,
  123611. 13,
  123612. 13
  123613. };
  123614. static static_codebook _44c0_sm_p7_0 = {
  123615. 2, 169,
  123616. _vq_lengthlist__44c0_sm_p7_0,
  123617. 1, -526516224, 1616117760, 4, 0,
  123618. _vq_quantlist__44c0_sm_p7_0,
  123619. NULL,
  123620. &_vq_auxt__44c0_sm_p7_0,
  123621. NULL,
  123622. 0
  123623. };
  123624. static long _vq_quantlist__44c0_sm_p7_1[] = {
  123625. 2,
  123626. 1,
  123627. 3,
  123628. 0,
  123629. 4,
  123630. };
  123631. static long _vq_lengthlist__44c0_sm_p7_1[] = {
  123632. 2, 4, 4, 4, 4, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  123633. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  123634. };
  123635. static float _vq_quantthresh__44c0_sm_p7_1[] = {
  123636. -1.5, -0.5, 0.5, 1.5,
  123637. };
  123638. static long _vq_quantmap__44c0_sm_p7_1[] = {
  123639. 3, 1, 0, 2, 4,
  123640. };
  123641. static encode_aux_threshmatch _vq_auxt__44c0_sm_p7_1 = {
  123642. _vq_quantthresh__44c0_sm_p7_1,
  123643. _vq_quantmap__44c0_sm_p7_1,
  123644. 5,
  123645. 5
  123646. };
  123647. static static_codebook _44c0_sm_p7_1 = {
  123648. 2, 25,
  123649. _vq_lengthlist__44c0_sm_p7_1,
  123650. 1, -533725184, 1611661312, 3, 0,
  123651. _vq_quantlist__44c0_sm_p7_1,
  123652. NULL,
  123653. &_vq_auxt__44c0_sm_p7_1,
  123654. NULL,
  123655. 0
  123656. };
  123657. static long _vq_quantlist__44c0_sm_p8_0[] = {
  123658. 4,
  123659. 3,
  123660. 5,
  123661. 2,
  123662. 6,
  123663. 1,
  123664. 7,
  123665. 0,
  123666. 8,
  123667. };
  123668. static long _vq_lengthlist__44c0_sm_p8_0[] = {
  123669. 1, 3, 3,11,11,11,11,11,11, 3, 7, 6,11,11,11,11,
  123670. 11,11, 4, 8, 7,11,11,11,11,11,11,11,11,11,11,11,
  123671. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  123672. 11,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123673. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  123674. 12,
  123675. };
  123676. static float _vq_quantthresh__44c0_sm_p8_0[] = {
  123677. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  123678. };
  123679. static long _vq_quantmap__44c0_sm_p8_0[] = {
  123680. 7, 5, 3, 1, 0, 2, 4, 6,
  123681. 8,
  123682. };
  123683. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_0 = {
  123684. _vq_quantthresh__44c0_sm_p8_0,
  123685. _vq_quantmap__44c0_sm_p8_0,
  123686. 9,
  123687. 9
  123688. };
  123689. static static_codebook _44c0_sm_p8_0 = {
  123690. 2, 81,
  123691. _vq_lengthlist__44c0_sm_p8_0,
  123692. 1, -516186112, 1627103232, 4, 0,
  123693. _vq_quantlist__44c0_sm_p8_0,
  123694. NULL,
  123695. &_vq_auxt__44c0_sm_p8_0,
  123696. NULL,
  123697. 0
  123698. };
  123699. static long _vq_quantlist__44c0_sm_p8_1[] = {
  123700. 6,
  123701. 5,
  123702. 7,
  123703. 4,
  123704. 8,
  123705. 3,
  123706. 9,
  123707. 2,
  123708. 10,
  123709. 1,
  123710. 11,
  123711. 0,
  123712. 12,
  123713. };
  123714. static long _vq_lengthlist__44c0_sm_p8_1[] = {
  123715. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  123716. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  123717. 8,10,10,12,11,12,12,17, 7, 7, 8, 8, 9, 9,10,10,
  123718. 12,12,13,13,18, 7, 7, 8, 7, 9, 9,10,10,12,12,12,
  123719. 13,19,10,10, 8, 8,10,10,11,11,12,12,13,14,19,11,
  123720. 10, 8, 7,10,10,11,11,12,12,13,12,19,19,19,10,10,
  123721. 10,10,11,11,12,12,13,13,19,19,19,11, 9,11, 9,14,
  123722. 12,13,12,13,13,19,20,18,13,14,11,11,12,12,13,13,
  123723. 14,13,20,20,20,15,13,11,10,13,11,13,13,14,13,20,
  123724. 20,20,20,20,13,14,12,12,13,13,13,13,20,20,20,20,
  123725. 20,13,13,12,12,16,13,15,13,
  123726. };
  123727. static float _vq_quantthresh__44c0_sm_p8_1[] = {
  123728. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  123729. 42.5, 59.5, 76.5, 93.5,
  123730. };
  123731. static long _vq_quantmap__44c0_sm_p8_1[] = {
  123732. 11, 9, 7, 5, 3, 1, 0, 2,
  123733. 4, 6, 8, 10, 12,
  123734. };
  123735. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_1 = {
  123736. _vq_quantthresh__44c0_sm_p8_1,
  123737. _vq_quantmap__44c0_sm_p8_1,
  123738. 13,
  123739. 13
  123740. };
  123741. static static_codebook _44c0_sm_p8_1 = {
  123742. 2, 169,
  123743. _vq_lengthlist__44c0_sm_p8_1,
  123744. 1, -522616832, 1620115456, 4, 0,
  123745. _vq_quantlist__44c0_sm_p8_1,
  123746. NULL,
  123747. &_vq_auxt__44c0_sm_p8_1,
  123748. NULL,
  123749. 0
  123750. };
  123751. static long _vq_quantlist__44c0_sm_p8_2[] = {
  123752. 8,
  123753. 7,
  123754. 9,
  123755. 6,
  123756. 10,
  123757. 5,
  123758. 11,
  123759. 4,
  123760. 12,
  123761. 3,
  123762. 13,
  123763. 2,
  123764. 14,
  123765. 1,
  123766. 15,
  123767. 0,
  123768. 16,
  123769. };
  123770. static long _vq_lengthlist__44c0_sm_p8_2[] = {
  123771. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  123772. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  123773. 9, 9,10, 6, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  123774. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  123775. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  123776. 9,10, 9, 9,10,10,10,11, 8, 8, 8, 8, 9, 9, 9, 9,
  123777. 9, 9, 9,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  123778. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  123779. 9, 9, 9, 9, 9, 9,10,10,10,10,10,11,11, 8, 8, 9,
  123780. 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,11,11,11, 9, 9,
  123781. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,10,11,11, 9,
  123782. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,11,10,11,11,
  123783. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,10,11,11,
  123784. 11,11,11, 9, 9,10, 9, 9, 9, 9, 9, 9, 9,10,11,10,
  123785. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  123786. 11,11,11,11,11, 9,10, 9, 9, 9, 9, 9, 9, 9, 9,11,
  123787. 11,10,11,11,11,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  123788. 10,11,10,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  123789. 9,
  123790. };
  123791. static float _vq_quantthresh__44c0_sm_p8_2[] = {
  123792. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  123793. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  123794. };
  123795. static long _vq_quantmap__44c0_sm_p8_2[] = {
  123796. 15, 13, 11, 9, 7, 5, 3, 1,
  123797. 0, 2, 4, 6, 8, 10, 12, 14,
  123798. 16,
  123799. };
  123800. static encode_aux_threshmatch _vq_auxt__44c0_sm_p8_2 = {
  123801. _vq_quantthresh__44c0_sm_p8_2,
  123802. _vq_quantmap__44c0_sm_p8_2,
  123803. 17,
  123804. 17
  123805. };
  123806. static static_codebook _44c0_sm_p8_2 = {
  123807. 2, 289,
  123808. _vq_lengthlist__44c0_sm_p8_2,
  123809. 1, -529530880, 1611661312, 5, 0,
  123810. _vq_quantlist__44c0_sm_p8_2,
  123811. NULL,
  123812. &_vq_auxt__44c0_sm_p8_2,
  123813. NULL,
  123814. 0
  123815. };
  123816. static long _huff_lengthlist__44c0_sm_short[] = {
  123817. 6, 6,12,13,13,14,16,17,17, 4, 2, 5, 8, 7, 9,12,
  123818. 15,15, 9, 4, 5, 9, 7, 9,12,16,18,11, 6, 7, 4, 6,
  123819. 8,11,14,18,10, 5, 6, 5, 5, 7,10,14,17,10, 5, 7,
  123820. 7, 6, 7,10,13,16,11, 5, 7, 7, 7, 8,10,12,15,13,
  123821. 6, 7, 5, 5, 7, 9,12,13,16, 8, 9, 6, 6, 7, 9,10,
  123822. 12,
  123823. };
  123824. static static_codebook _huff_book__44c0_sm_short = {
  123825. 2, 81,
  123826. _huff_lengthlist__44c0_sm_short,
  123827. 0, 0, 0, 0, 0,
  123828. NULL,
  123829. NULL,
  123830. NULL,
  123831. NULL,
  123832. 0
  123833. };
  123834. static long _huff_lengthlist__44c1_s_long[] = {
  123835. 5, 5, 9,10, 9, 9,10,11,12, 5, 1, 5, 6, 6, 7,10,
  123836. 12,14, 9, 5, 6, 8, 8,10,12,14,14,10, 5, 8, 5, 6,
  123837. 8,11,13,14, 9, 5, 7, 6, 6, 8,10,12,11, 9, 7, 9,
  123838. 7, 6, 6, 7,10,10,10, 9,12, 9, 8, 7, 7,10,12,11,
  123839. 11,13,12,10, 9, 8, 9,11,11,14,15,15,13,11, 9, 9,
  123840. 11,
  123841. };
  123842. static static_codebook _huff_book__44c1_s_long = {
  123843. 2, 81,
  123844. _huff_lengthlist__44c1_s_long,
  123845. 0, 0, 0, 0, 0,
  123846. NULL,
  123847. NULL,
  123848. NULL,
  123849. NULL,
  123850. 0
  123851. };
  123852. static long _vq_quantlist__44c1_s_p1_0[] = {
  123853. 1,
  123854. 0,
  123855. 2,
  123856. };
  123857. static long _vq_lengthlist__44c1_s_p1_0[] = {
  123858. 2, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 6, 0, 0, 0, 0,
  123859. 0, 0, 5, 6, 7, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123864. 0, 0, 0, 7, 8, 8, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123869. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123870. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123871. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123872. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123873. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123874. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123875. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123876. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123877. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123878. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123879. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123880. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123881. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123882. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123883. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123884. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123885. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123886. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123887. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123888. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123889. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123890. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123891. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123892. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123893. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123894. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123895. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123896. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123897. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123898. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123899. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123900. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123901. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 7, 7, 0, 0, 0, 0,
  123904. 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0, 0,
  123909. 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0,
  123910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 8, 8, 0, 0,
  123914. 0, 0, 0, 0, 8, 9, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 4, 7, 7, 0, 0, 0, 0, 0, 0, 7, 8, 8, 0, 0,
  123950. 0, 0, 0, 0, 7, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123954. 0, 0, 0, 6, 8, 8, 0, 0, 0, 0, 0, 0, 8,10, 9, 0,
  123955. 0, 0, 0, 0, 0, 8, 8, 9, 0, 0, 0, 0, 0, 0, 0, 0,
  123956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123959. 0, 0, 0, 0, 7, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9,
  123960. 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  123961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123968. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123973. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123978. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123982. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  123999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124268. 0,
  124269. };
  124270. static float _vq_quantthresh__44c1_s_p1_0[] = {
  124271. -0.5, 0.5,
  124272. };
  124273. static long _vq_quantmap__44c1_s_p1_0[] = {
  124274. 1, 0, 2,
  124275. };
  124276. static encode_aux_threshmatch _vq_auxt__44c1_s_p1_0 = {
  124277. _vq_quantthresh__44c1_s_p1_0,
  124278. _vq_quantmap__44c1_s_p1_0,
  124279. 3,
  124280. 3
  124281. };
  124282. static static_codebook _44c1_s_p1_0 = {
  124283. 8, 6561,
  124284. _vq_lengthlist__44c1_s_p1_0,
  124285. 1, -535822336, 1611661312, 2, 0,
  124286. _vq_quantlist__44c1_s_p1_0,
  124287. NULL,
  124288. &_vq_auxt__44c1_s_p1_0,
  124289. NULL,
  124290. 0
  124291. };
  124292. static long _vq_quantlist__44c1_s_p2_0[] = {
  124293. 2,
  124294. 1,
  124295. 3,
  124296. 0,
  124297. 4,
  124298. };
  124299. static long _vq_lengthlist__44c1_s_p2_0[] = {
  124300. 2, 3, 4, 6, 5, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  124302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124303. 0, 0, 4, 4, 5, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 8, 8,
  124305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124306. 0, 0, 0, 0, 6, 6, 6, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  124307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124339. 0,
  124340. };
  124341. static float _vq_quantthresh__44c1_s_p2_0[] = {
  124342. -1.5, -0.5, 0.5, 1.5,
  124343. };
  124344. static long _vq_quantmap__44c1_s_p2_0[] = {
  124345. 3, 1, 0, 2, 4,
  124346. };
  124347. static encode_aux_threshmatch _vq_auxt__44c1_s_p2_0 = {
  124348. _vq_quantthresh__44c1_s_p2_0,
  124349. _vq_quantmap__44c1_s_p2_0,
  124350. 5,
  124351. 5
  124352. };
  124353. static static_codebook _44c1_s_p2_0 = {
  124354. 4, 625,
  124355. _vq_lengthlist__44c1_s_p2_0,
  124356. 1, -533725184, 1611661312, 3, 0,
  124357. _vq_quantlist__44c1_s_p2_0,
  124358. NULL,
  124359. &_vq_auxt__44c1_s_p2_0,
  124360. NULL,
  124361. 0
  124362. };
  124363. static long _vq_quantlist__44c1_s_p3_0[] = {
  124364. 4,
  124365. 3,
  124366. 5,
  124367. 2,
  124368. 6,
  124369. 1,
  124370. 7,
  124371. 0,
  124372. 8,
  124373. };
  124374. static long _vq_lengthlist__44c1_s_p3_0[] = {
  124375. 1, 3, 2, 7, 7, 0, 0, 0, 0, 0,13,13, 6, 6, 0, 0,
  124376. 0, 0, 0,12, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  124377. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  124378. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  124379. 0, 0,11,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124380. 0,
  124381. };
  124382. static float _vq_quantthresh__44c1_s_p3_0[] = {
  124383. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124384. };
  124385. static long _vq_quantmap__44c1_s_p3_0[] = {
  124386. 7, 5, 3, 1, 0, 2, 4, 6,
  124387. 8,
  124388. };
  124389. static encode_aux_threshmatch _vq_auxt__44c1_s_p3_0 = {
  124390. _vq_quantthresh__44c1_s_p3_0,
  124391. _vq_quantmap__44c1_s_p3_0,
  124392. 9,
  124393. 9
  124394. };
  124395. static static_codebook _44c1_s_p3_0 = {
  124396. 2, 81,
  124397. _vq_lengthlist__44c1_s_p3_0,
  124398. 1, -531628032, 1611661312, 4, 0,
  124399. _vq_quantlist__44c1_s_p3_0,
  124400. NULL,
  124401. &_vq_auxt__44c1_s_p3_0,
  124402. NULL,
  124403. 0
  124404. };
  124405. static long _vq_quantlist__44c1_s_p4_0[] = {
  124406. 4,
  124407. 3,
  124408. 5,
  124409. 2,
  124410. 6,
  124411. 1,
  124412. 7,
  124413. 0,
  124414. 8,
  124415. };
  124416. static long _vq_lengthlist__44c1_s_p4_0[] = {
  124417. 1, 3, 3, 6, 5, 6, 6, 8, 8, 0, 0, 0, 7, 7, 7, 7,
  124418. 9, 9, 0, 0, 0, 7, 7, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  124419. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  124420. 9, 9, 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0,
  124421. 0, 0,10,10, 9, 9,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  124422. 11,
  124423. };
  124424. static float _vq_quantthresh__44c1_s_p4_0[] = {
  124425. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  124426. };
  124427. static long _vq_quantmap__44c1_s_p4_0[] = {
  124428. 7, 5, 3, 1, 0, 2, 4, 6,
  124429. 8,
  124430. };
  124431. static encode_aux_threshmatch _vq_auxt__44c1_s_p4_0 = {
  124432. _vq_quantthresh__44c1_s_p4_0,
  124433. _vq_quantmap__44c1_s_p4_0,
  124434. 9,
  124435. 9
  124436. };
  124437. static static_codebook _44c1_s_p4_0 = {
  124438. 2, 81,
  124439. _vq_lengthlist__44c1_s_p4_0,
  124440. 1, -531628032, 1611661312, 4, 0,
  124441. _vq_quantlist__44c1_s_p4_0,
  124442. NULL,
  124443. &_vq_auxt__44c1_s_p4_0,
  124444. NULL,
  124445. 0
  124446. };
  124447. static long _vq_quantlist__44c1_s_p5_0[] = {
  124448. 8,
  124449. 7,
  124450. 9,
  124451. 6,
  124452. 10,
  124453. 5,
  124454. 11,
  124455. 4,
  124456. 12,
  124457. 3,
  124458. 13,
  124459. 2,
  124460. 14,
  124461. 1,
  124462. 15,
  124463. 0,
  124464. 16,
  124465. };
  124466. static long _vq_lengthlist__44c1_s_p5_0[] = {
  124467. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  124468. 11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  124469. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  124470. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  124471. 11,11,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  124472. 10,11,11,12,11, 0, 0, 0, 8, 8, 9, 9, 9,10,10,10,
  124473. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10, 9,10,
  124474. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  124475. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  124476. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  124477. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  124478. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  124479. 10,10,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  124480. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  124481. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,13, 0, 0,
  124482. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  124483. 0, 0, 0, 0, 0, 0,12,12,12,12,12,12,13,13,14,14,
  124484. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  124485. 14,
  124486. };
  124487. static float _vq_quantthresh__44c1_s_p5_0[] = {
  124488. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124489. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124490. };
  124491. static long _vq_quantmap__44c1_s_p5_0[] = {
  124492. 15, 13, 11, 9, 7, 5, 3, 1,
  124493. 0, 2, 4, 6, 8, 10, 12, 14,
  124494. 16,
  124495. };
  124496. static encode_aux_threshmatch _vq_auxt__44c1_s_p5_0 = {
  124497. _vq_quantthresh__44c1_s_p5_0,
  124498. _vq_quantmap__44c1_s_p5_0,
  124499. 17,
  124500. 17
  124501. };
  124502. static static_codebook _44c1_s_p5_0 = {
  124503. 2, 289,
  124504. _vq_lengthlist__44c1_s_p5_0,
  124505. 1, -529530880, 1611661312, 5, 0,
  124506. _vq_quantlist__44c1_s_p5_0,
  124507. NULL,
  124508. &_vq_auxt__44c1_s_p5_0,
  124509. NULL,
  124510. 0
  124511. };
  124512. static long _vq_quantlist__44c1_s_p6_0[] = {
  124513. 1,
  124514. 0,
  124515. 2,
  124516. };
  124517. static long _vq_lengthlist__44c1_s_p6_0[] = {
  124518. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  124519. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 6,10,10,11,11,
  124520. 11,11,10,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  124521. 11,10,11,11,10,10, 7,11,10,11,11,11,12,11,11, 7,
  124522. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,12,10,
  124523. 11,
  124524. };
  124525. static float _vq_quantthresh__44c1_s_p6_0[] = {
  124526. -5.5, 5.5,
  124527. };
  124528. static long _vq_quantmap__44c1_s_p6_0[] = {
  124529. 1, 0, 2,
  124530. };
  124531. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_0 = {
  124532. _vq_quantthresh__44c1_s_p6_0,
  124533. _vq_quantmap__44c1_s_p6_0,
  124534. 3,
  124535. 3
  124536. };
  124537. static static_codebook _44c1_s_p6_0 = {
  124538. 4, 81,
  124539. _vq_lengthlist__44c1_s_p6_0,
  124540. 1, -529137664, 1618345984, 2, 0,
  124541. _vq_quantlist__44c1_s_p6_0,
  124542. NULL,
  124543. &_vq_auxt__44c1_s_p6_0,
  124544. NULL,
  124545. 0
  124546. };
  124547. static long _vq_quantlist__44c1_s_p6_1[] = {
  124548. 5,
  124549. 4,
  124550. 6,
  124551. 3,
  124552. 7,
  124553. 2,
  124554. 8,
  124555. 1,
  124556. 9,
  124557. 0,
  124558. 10,
  124559. };
  124560. static long _vq_lengthlist__44c1_s_p6_1[] = {
  124561. 2, 3, 3, 6, 6, 7, 7, 7, 7, 8, 8,10,10,10, 6, 6,
  124562. 7, 7, 8, 8, 8, 8,10,10,10, 6, 6, 7, 7, 8, 8, 8,
  124563. 8,10,10,10, 7, 7, 7, 7, 8, 8, 8, 8,10,10,10, 7,
  124564. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  124565. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  124566. 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,10,10, 8, 8, 8,
  124567. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  124568. 10,10,10, 8, 8, 8, 8, 8, 8,
  124569. };
  124570. static float _vq_quantthresh__44c1_s_p6_1[] = {
  124571. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  124572. 3.5, 4.5,
  124573. };
  124574. static long _vq_quantmap__44c1_s_p6_1[] = {
  124575. 9, 7, 5, 3, 1, 0, 2, 4,
  124576. 6, 8, 10,
  124577. };
  124578. static encode_aux_threshmatch _vq_auxt__44c1_s_p6_1 = {
  124579. _vq_quantthresh__44c1_s_p6_1,
  124580. _vq_quantmap__44c1_s_p6_1,
  124581. 11,
  124582. 11
  124583. };
  124584. static static_codebook _44c1_s_p6_1 = {
  124585. 2, 121,
  124586. _vq_lengthlist__44c1_s_p6_1,
  124587. 1, -531365888, 1611661312, 4, 0,
  124588. _vq_quantlist__44c1_s_p6_1,
  124589. NULL,
  124590. &_vq_auxt__44c1_s_p6_1,
  124591. NULL,
  124592. 0
  124593. };
  124594. static long _vq_quantlist__44c1_s_p7_0[] = {
  124595. 6,
  124596. 5,
  124597. 7,
  124598. 4,
  124599. 8,
  124600. 3,
  124601. 9,
  124602. 2,
  124603. 10,
  124604. 1,
  124605. 11,
  124606. 0,
  124607. 12,
  124608. };
  124609. static long _vq_lengthlist__44c1_s_p7_0[] = {
  124610. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 9, 7, 5, 6,
  124611. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 5, 7, 7, 8,
  124612. 8, 8, 8, 9, 9,10,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  124613. 10,10,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  124614. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,11, 0,13,
  124615. 13, 9, 9, 9, 9,10,10,11,11,11,11, 0, 0, 0,10,10,
  124616. 10,10,11,11,12,11,12,12, 0, 0, 0,10,10,10, 9,11,
  124617. 11,12,11,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  124618. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  124619. 0, 0, 0, 0,11,12,11,11,12,12,14,13, 0, 0, 0, 0,
  124620. 0,12,11,11,11,13,10,14,13,
  124621. };
  124622. static float _vq_quantthresh__44c1_s_p7_0[] = {
  124623. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  124624. 12.5, 17.5, 22.5, 27.5,
  124625. };
  124626. static long _vq_quantmap__44c1_s_p7_0[] = {
  124627. 11, 9, 7, 5, 3, 1, 0, 2,
  124628. 4, 6, 8, 10, 12,
  124629. };
  124630. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_0 = {
  124631. _vq_quantthresh__44c1_s_p7_0,
  124632. _vq_quantmap__44c1_s_p7_0,
  124633. 13,
  124634. 13
  124635. };
  124636. static static_codebook _44c1_s_p7_0 = {
  124637. 2, 169,
  124638. _vq_lengthlist__44c1_s_p7_0,
  124639. 1, -526516224, 1616117760, 4, 0,
  124640. _vq_quantlist__44c1_s_p7_0,
  124641. NULL,
  124642. &_vq_auxt__44c1_s_p7_0,
  124643. NULL,
  124644. 0
  124645. };
  124646. static long _vq_quantlist__44c1_s_p7_1[] = {
  124647. 2,
  124648. 1,
  124649. 3,
  124650. 0,
  124651. 4,
  124652. };
  124653. static long _vq_lengthlist__44c1_s_p7_1[] = {
  124654. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  124655. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  124656. };
  124657. static float _vq_quantthresh__44c1_s_p7_1[] = {
  124658. -1.5, -0.5, 0.5, 1.5,
  124659. };
  124660. static long _vq_quantmap__44c1_s_p7_1[] = {
  124661. 3, 1, 0, 2, 4,
  124662. };
  124663. static encode_aux_threshmatch _vq_auxt__44c1_s_p7_1 = {
  124664. _vq_quantthresh__44c1_s_p7_1,
  124665. _vq_quantmap__44c1_s_p7_1,
  124666. 5,
  124667. 5
  124668. };
  124669. static static_codebook _44c1_s_p7_1 = {
  124670. 2, 25,
  124671. _vq_lengthlist__44c1_s_p7_1,
  124672. 1, -533725184, 1611661312, 3, 0,
  124673. _vq_quantlist__44c1_s_p7_1,
  124674. NULL,
  124675. &_vq_auxt__44c1_s_p7_1,
  124676. NULL,
  124677. 0
  124678. };
  124679. static long _vq_quantlist__44c1_s_p8_0[] = {
  124680. 6,
  124681. 5,
  124682. 7,
  124683. 4,
  124684. 8,
  124685. 3,
  124686. 9,
  124687. 2,
  124688. 10,
  124689. 1,
  124690. 11,
  124691. 0,
  124692. 12,
  124693. };
  124694. static long _vq_lengthlist__44c1_s_p8_0[] = {
  124695. 1, 4, 3,10,10,10,10,10,10,10,10,10,10, 4, 8, 6,
  124696. 10,10,10,10,10,10,10,10,10,10, 4, 8, 7,10,10,10,
  124697. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124698. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124699. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124700. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124701. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124702. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124703. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124704. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  124705. 10,10,10,10,10,10,10,10,10,
  124706. };
  124707. static float _vq_quantthresh__44c1_s_p8_0[] = {
  124708. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  124709. 552.5, 773.5, 994.5, 1215.5,
  124710. };
  124711. static long _vq_quantmap__44c1_s_p8_0[] = {
  124712. 11, 9, 7, 5, 3, 1, 0, 2,
  124713. 4, 6, 8, 10, 12,
  124714. };
  124715. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_0 = {
  124716. _vq_quantthresh__44c1_s_p8_0,
  124717. _vq_quantmap__44c1_s_p8_0,
  124718. 13,
  124719. 13
  124720. };
  124721. static static_codebook _44c1_s_p8_0 = {
  124722. 2, 169,
  124723. _vq_lengthlist__44c1_s_p8_0,
  124724. 1, -514541568, 1627103232, 4, 0,
  124725. _vq_quantlist__44c1_s_p8_0,
  124726. NULL,
  124727. &_vq_auxt__44c1_s_p8_0,
  124728. NULL,
  124729. 0
  124730. };
  124731. static long _vq_quantlist__44c1_s_p8_1[] = {
  124732. 6,
  124733. 5,
  124734. 7,
  124735. 4,
  124736. 8,
  124737. 3,
  124738. 9,
  124739. 2,
  124740. 10,
  124741. 1,
  124742. 11,
  124743. 0,
  124744. 12,
  124745. };
  124746. static long _vq_lengthlist__44c1_s_p8_1[] = {
  124747. 1, 4, 4, 6, 5, 7, 7, 9, 9,10,10,12,12, 6, 5, 5,
  124748. 7, 7, 8, 8,10,10,12,11,12,12, 6, 5, 5, 7, 7, 8,
  124749. 8,10,10,11,11,12,12,15, 7, 7, 8, 8, 9, 9,11,11,
  124750. 12,12,13,12,15, 8, 8, 8, 7, 9, 9,10,10,12,12,13,
  124751. 13,16,11,10, 8, 8,10,10,11,11,12,12,13,13,16,11,
  124752. 11, 9, 8,11,10,11,11,12,12,13,12,16,16,16,10,11,
  124753. 10,11,12,12,12,12,13,13,16,16,16,11, 9,11, 9,14,
  124754. 12,12,12,13,13,16,16,16,12,14,11,12,12,12,13,13,
  124755. 14,13,16,16,16,15,13,12,10,13,10,13,14,13,13,16,
  124756. 16,16,16,16,13,14,12,13,13,12,13,13,16,16,16,16,
  124757. 16,13,12,12,11,14,12,15,13,
  124758. };
  124759. static float _vq_quantthresh__44c1_s_p8_1[] = {
  124760. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  124761. 42.5, 59.5, 76.5, 93.5,
  124762. };
  124763. static long _vq_quantmap__44c1_s_p8_1[] = {
  124764. 11, 9, 7, 5, 3, 1, 0, 2,
  124765. 4, 6, 8, 10, 12,
  124766. };
  124767. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_1 = {
  124768. _vq_quantthresh__44c1_s_p8_1,
  124769. _vq_quantmap__44c1_s_p8_1,
  124770. 13,
  124771. 13
  124772. };
  124773. static static_codebook _44c1_s_p8_1 = {
  124774. 2, 169,
  124775. _vq_lengthlist__44c1_s_p8_1,
  124776. 1, -522616832, 1620115456, 4, 0,
  124777. _vq_quantlist__44c1_s_p8_1,
  124778. NULL,
  124779. &_vq_auxt__44c1_s_p8_1,
  124780. NULL,
  124781. 0
  124782. };
  124783. static long _vq_quantlist__44c1_s_p8_2[] = {
  124784. 8,
  124785. 7,
  124786. 9,
  124787. 6,
  124788. 10,
  124789. 5,
  124790. 11,
  124791. 4,
  124792. 12,
  124793. 3,
  124794. 13,
  124795. 2,
  124796. 14,
  124797. 1,
  124798. 15,
  124799. 0,
  124800. 16,
  124801. };
  124802. static long _vq_lengthlist__44c1_s_p8_2[] = {
  124803. 2, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  124804. 8,10,10,10, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  124805. 9, 9,10,10,10, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  124806. 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  124807. 9,10, 9, 9,10,10,10, 7, 7, 8, 8, 9, 8, 9, 9, 9,
  124808. 9,10, 9, 9,10,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  124809. 9, 9,10, 9, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  124810. 9, 9, 9, 9, 9,10,10,11,11,11, 8, 8, 9, 9, 9, 9,
  124811. 9, 9, 9, 9, 9, 9,10,10,10,10,11,11,11, 8, 8, 9,
  124812. 9, 9, 9,10, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  124813. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 9,
  124814. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  124815. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10,11,11,
  124816. 11,11,11, 9, 9, 9,10, 9, 9, 9, 9, 9, 9,10,11,11,
  124817. 11,11,11,11,10,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  124818. 11,11,11,11,11, 9,10, 9, 9, 9, 9,10, 9, 9, 9,11,
  124819. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  124820. 11,11,10,11,11,11,11,10,11, 9, 9, 9, 9, 9, 9, 9,
  124821. 9,
  124822. };
  124823. static float _vq_quantthresh__44c1_s_p8_2[] = {
  124824. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  124825. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  124826. };
  124827. static long _vq_quantmap__44c1_s_p8_2[] = {
  124828. 15, 13, 11, 9, 7, 5, 3, 1,
  124829. 0, 2, 4, 6, 8, 10, 12, 14,
  124830. 16,
  124831. };
  124832. static encode_aux_threshmatch _vq_auxt__44c1_s_p8_2 = {
  124833. _vq_quantthresh__44c1_s_p8_2,
  124834. _vq_quantmap__44c1_s_p8_2,
  124835. 17,
  124836. 17
  124837. };
  124838. static static_codebook _44c1_s_p8_2 = {
  124839. 2, 289,
  124840. _vq_lengthlist__44c1_s_p8_2,
  124841. 1, -529530880, 1611661312, 5, 0,
  124842. _vq_quantlist__44c1_s_p8_2,
  124843. NULL,
  124844. &_vq_auxt__44c1_s_p8_2,
  124845. NULL,
  124846. 0
  124847. };
  124848. static long _huff_lengthlist__44c1_s_short[] = {
  124849. 6, 8,13,12,13,14,15,16,16, 4, 2, 4, 7, 6, 8,11,
  124850. 13,15,10, 4, 4, 8, 6, 8,11,14,17,11, 5, 6, 5, 6,
  124851. 8,12,14,17,11, 5, 5, 6, 5, 7,10,13,16,12, 6, 7,
  124852. 8, 7, 8,10,13,15,13, 8, 8, 7, 7, 8,10,12,15,15,
  124853. 7, 7, 5, 5, 7, 9,12,14,15, 8, 8, 6, 6, 7, 8,10,
  124854. 11,
  124855. };
  124856. static static_codebook _huff_book__44c1_s_short = {
  124857. 2, 81,
  124858. _huff_lengthlist__44c1_s_short,
  124859. 0, 0, 0, 0, 0,
  124860. NULL,
  124861. NULL,
  124862. NULL,
  124863. NULL,
  124864. 0
  124865. };
  124866. static long _huff_lengthlist__44c1_sm_long[] = {
  124867. 5, 4, 8,10, 9, 9,10,11,12, 4, 2, 5, 6, 6, 8,10,
  124868. 11,13, 8, 4, 6, 8, 7, 9,12,12,14,10, 6, 8, 4, 5,
  124869. 6, 9,11,12, 9, 5, 6, 5, 5, 6, 9,11,11, 9, 7, 9,
  124870. 6, 5, 5, 7,10,10,10, 9,11, 8, 7, 6, 7, 9,11,11,
  124871. 12,13,10,10, 9, 8, 9,11,11,15,15,12,13,11, 9,10,
  124872. 11,
  124873. };
  124874. static static_codebook _huff_book__44c1_sm_long = {
  124875. 2, 81,
  124876. _huff_lengthlist__44c1_sm_long,
  124877. 0, 0, 0, 0, 0,
  124878. NULL,
  124879. NULL,
  124880. NULL,
  124881. NULL,
  124882. 0
  124883. };
  124884. static long _vq_quantlist__44c1_sm_p1_0[] = {
  124885. 1,
  124886. 0,
  124887. 2,
  124888. };
  124889. static long _vq_lengthlist__44c1_sm_p1_0[] = {
  124890. 1, 5, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  124891. 0, 0, 5, 7, 7, 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, 5, 8, 7, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124896. 0, 0, 0, 7, 8, 9, 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, 5, 7, 7, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  124901. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124902. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124903. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124904. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124905. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124906. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124907. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124908. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124909. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124910. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124911. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124912. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124913. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124914. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124915. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124916. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124917. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124918. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124919. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124920. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124921. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124922. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124923. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124924. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124925. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124926. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124927. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124928. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124929. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124930. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124931. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124932. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124933. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 7, 0, 0, 0, 0,
  124936. 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0, 0,
  124941. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  124946. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 7, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  124982. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124983. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124984. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124986. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  124987. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  124988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124991. 0, 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  124992. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  124993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  124999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125019. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125024. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125300. 0,
  125301. };
  125302. static float _vq_quantthresh__44c1_sm_p1_0[] = {
  125303. -0.5, 0.5,
  125304. };
  125305. static long _vq_quantmap__44c1_sm_p1_0[] = {
  125306. 1, 0, 2,
  125307. };
  125308. static encode_aux_threshmatch _vq_auxt__44c1_sm_p1_0 = {
  125309. _vq_quantthresh__44c1_sm_p1_0,
  125310. _vq_quantmap__44c1_sm_p1_0,
  125311. 3,
  125312. 3
  125313. };
  125314. static static_codebook _44c1_sm_p1_0 = {
  125315. 8, 6561,
  125316. _vq_lengthlist__44c1_sm_p1_0,
  125317. 1, -535822336, 1611661312, 2, 0,
  125318. _vq_quantlist__44c1_sm_p1_0,
  125319. NULL,
  125320. &_vq_auxt__44c1_sm_p1_0,
  125321. NULL,
  125322. 0
  125323. };
  125324. static long _vq_quantlist__44c1_sm_p2_0[] = {
  125325. 2,
  125326. 1,
  125327. 3,
  125328. 0,
  125329. 4,
  125330. };
  125331. static long _vq_lengthlist__44c1_sm_p2_0[] = {
  125332. 2, 3, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, 4, 6, 6, 0, 0,
  125334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125335. 0, 0, 4, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 6, 6, 9, 9,
  125337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125338. 0, 0, 0, 0, 6, 6, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  125339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125371. 0,
  125372. };
  125373. static float _vq_quantthresh__44c1_sm_p2_0[] = {
  125374. -1.5, -0.5, 0.5, 1.5,
  125375. };
  125376. static long _vq_quantmap__44c1_sm_p2_0[] = {
  125377. 3, 1, 0, 2, 4,
  125378. };
  125379. static encode_aux_threshmatch _vq_auxt__44c1_sm_p2_0 = {
  125380. _vq_quantthresh__44c1_sm_p2_0,
  125381. _vq_quantmap__44c1_sm_p2_0,
  125382. 5,
  125383. 5
  125384. };
  125385. static static_codebook _44c1_sm_p2_0 = {
  125386. 4, 625,
  125387. _vq_lengthlist__44c1_sm_p2_0,
  125388. 1, -533725184, 1611661312, 3, 0,
  125389. _vq_quantlist__44c1_sm_p2_0,
  125390. NULL,
  125391. &_vq_auxt__44c1_sm_p2_0,
  125392. NULL,
  125393. 0
  125394. };
  125395. static long _vq_quantlist__44c1_sm_p3_0[] = {
  125396. 4,
  125397. 3,
  125398. 5,
  125399. 2,
  125400. 6,
  125401. 1,
  125402. 7,
  125403. 0,
  125404. 8,
  125405. };
  125406. static long _vq_lengthlist__44c1_sm_p3_0[] = {
  125407. 1, 3, 3, 7, 7, 0, 0, 0, 0, 0, 5, 5, 6, 6, 0, 0,
  125408. 0, 0, 0, 5, 5, 7, 7, 0, 0, 0, 0, 0, 7, 7, 7, 7,
  125409. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  125410. 8, 9, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  125411. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125412. 0,
  125413. };
  125414. static float _vq_quantthresh__44c1_sm_p3_0[] = {
  125415. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125416. };
  125417. static long _vq_quantmap__44c1_sm_p3_0[] = {
  125418. 7, 5, 3, 1, 0, 2, 4, 6,
  125419. 8,
  125420. };
  125421. static encode_aux_threshmatch _vq_auxt__44c1_sm_p3_0 = {
  125422. _vq_quantthresh__44c1_sm_p3_0,
  125423. _vq_quantmap__44c1_sm_p3_0,
  125424. 9,
  125425. 9
  125426. };
  125427. static static_codebook _44c1_sm_p3_0 = {
  125428. 2, 81,
  125429. _vq_lengthlist__44c1_sm_p3_0,
  125430. 1, -531628032, 1611661312, 4, 0,
  125431. _vq_quantlist__44c1_sm_p3_0,
  125432. NULL,
  125433. &_vq_auxt__44c1_sm_p3_0,
  125434. NULL,
  125435. 0
  125436. };
  125437. static long _vq_quantlist__44c1_sm_p4_0[] = {
  125438. 4,
  125439. 3,
  125440. 5,
  125441. 2,
  125442. 6,
  125443. 1,
  125444. 7,
  125445. 0,
  125446. 8,
  125447. };
  125448. static long _vq_lengthlist__44c1_sm_p4_0[] = {
  125449. 1, 3, 3, 6, 6, 7, 7, 9, 9, 0, 6, 6, 7, 7, 8, 8,
  125450. 9, 9, 0, 6, 6, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  125451. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  125452. 8, 8, 9, 9,11,11, 0, 0, 0, 9, 9, 9, 9,11,11, 0,
  125453. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0, 9, 9,11,
  125454. 11,
  125455. };
  125456. static float _vq_quantthresh__44c1_sm_p4_0[] = {
  125457. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  125458. };
  125459. static long _vq_quantmap__44c1_sm_p4_0[] = {
  125460. 7, 5, 3, 1, 0, 2, 4, 6,
  125461. 8,
  125462. };
  125463. static encode_aux_threshmatch _vq_auxt__44c1_sm_p4_0 = {
  125464. _vq_quantthresh__44c1_sm_p4_0,
  125465. _vq_quantmap__44c1_sm_p4_0,
  125466. 9,
  125467. 9
  125468. };
  125469. static static_codebook _44c1_sm_p4_0 = {
  125470. 2, 81,
  125471. _vq_lengthlist__44c1_sm_p4_0,
  125472. 1, -531628032, 1611661312, 4, 0,
  125473. _vq_quantlist__44c1_sm_p4_0,
  125474. NULL,
  125475. &_vq_auxt__44c1_sm_p4_0,
  125476. NULL,
  125477. 0
  125478. };
  125479. static long _vq_quantlist__44c1_sm_p5_0[] = {
  125480. 8,
  125481. 7,
  125482. 9,
  125483. 6,
  125484. 10,
  125485. 5,
  125486. 11,
  125487. 4,
  125488. 12,
  125489. 3,
  125490. 13,
  125491. 2,
  125492. 14,
  125493. 1,
  125494. 15,
  125495. 0,
  125496. 16,
  125497. };
  125498. static long _vq_lengthlist__44c1_sm_p5_0[] = {
  125499. 2, 3, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  125500. 11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,10,
  125501. 11,11, 0, 5, 5, 6, 6, 8, 8, 9, 9, 9, 9,10,10,10,
  125502. 10,11,11, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  125503. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  125504. 10,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,10,
  125505. 10,11,11,11,12,12, 0, 0, 0, 8, 8, 8, 8, 9, 9,10,
  125506. 10,10,10,11,11,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  125507. 10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  125508. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  125509. 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  125510. 9, 9, 9,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  125511. 9, 9,10,10,11,11,12,12,12,12,13,13, 0, 0, 0, 0,
  125512. 0, 0, 0,10,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  125513. 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0, 0,
  125514. 0, 0, 0, 0, 0,11,11,11,11,12,12,13,13,13,13, 0,
  125515. 0, 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,14,14,
  125516. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,12,12,13,13,14,
  125517. 14,
  125518. };
  125519. static float _vq_quantthresh__44c1_sm_p5_0[] = {
  125520. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125521. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125522. };
  125523. static long _vq_quantmap__44c1_sm_p5_0[] = {
  125524. 15, 13, 11, 9, 7, 5, 3, 1,
  125525. 0, 2, 4, 6, 8, 10, 12, 14,
  125526. 16,
  125527. };
  125528. static encode_aux_threshmatch _vq_auxt__44c1_sm_p5_0 = {
  125529. _vq_quantthresh__44c1_sm_p5_0,
  125530. _vq_quantmap__44c1_sm_p5_0,
  125531. 17,
  125532. 17
  125533. };
  125534. static static_codebook _44c1_sm_p5_0 = {
  125535. 2, 289,
  125536. _vq_lengthlist__44c1_sm_p5_0,
  125537. 1, -529530880, 1611661312, 5, 0,
  125538. _vq_quantlist__44c1_sm_p5_0,
  125539. NULL,
  125540. &_vq_auxt__44c1_sm_p5_0,
  125541. NULL,
  125542. 0
  125543. };
  125544. static long _vq_quantlist__44c1_sm_p6_0[] = {
  125545. 1,
  125546. 0,
  125547. 2,
  125548. };
  125549. static long _vq_lengthlist__44c1_sm_p6_0[] = {
  125550. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 7,10, 9, 9,11,
  125551. 9, 9, 4, 7, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  125552. 11,11,10,10, 6, 9, 9,11,11,10,11,10,10, 6, 9, 9,
  125553. 11,10,11,11,10,10, 7,11,11,11,11,11,11,11,11, 6,
  125554. 9, 9,11,10,10,11,11,10, 6, 9, 9,10,10,10,11,10,
  125555. 11,
  125556. };
  125557. static float _vq_quantthresh__44c1_sm_p6_0[] = {
  125558. -5.5, 5.5,
  125559. };
  125560. static long _vq_quantmap__44c1_sm_p6_0[] = {
  125561. 1, 0, 2,
  125562. };
  125563. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_0 = {
  125564. _vq_quantthresh__44c1_sm_p6_0,
  125565. _vq_quantmap__44c1_sm_p6_0,
  125566. 3,
  125567. 3
  125568. };
  125569. static static_codebook _44c1_sm_p6_0 = {
  125570. 4, 81,
  125571. _vq_lengthlist__44c1_sm_p6_0,
  125572. 1, -529137664, 1618345984, 2, 0,
  125573. _vq_quantlist__44c1_sm_p6_0,
  125574. NULL,
  125575. &_vq_auxt__44c1_sm_p6_0,
  125576. NULL,
  125577. 0
  125578. };
  125579. static long _vq_quantlist__44c1_sm_p6_1[] = {
  125580. 5,
  125581. 4,
  125582. 6,
  125583. 3,
  125584. 7,
  125585. 2,
  125586. 8,
  125587. 1,
  125588. 9,
  125589. 0,
  125590. 10,
  125591. };
  125592. static long _vq_lengthlist__44c1_sm_p6_1[] = {
  125593. 2, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  125594. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  125595. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  125596. 7, 7, 7, 8, 8, 8, 8,10,10,10, 7, 7, 8, 8, 8, 8,
  125597. 8, 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10,
  125598. 8, 8, 8, 8, 8, 8, 9, 8,10,10,10,10,10, 8, 8, 8,
  125599. 8, 8, 8,10,10,10,10,10, 9, 9, 8, 8, 8, 8,10,10,
  125600. 10,10,10, 8, 8, 8, 8, 8, 8,
  125601. };
  125602. static float _vq_quantthresh__44c1_sm_p6_1[] = {
  125603. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  125604. 3.5, 4.5,
  125605. };
  125606. static long _vq_quantmap__44c1_sm_p6_1[] = {
  125607. 9, 7, 5, 3, 1, 0, 2, 4,
  125608. 6, 8, 10,
  125609. };
  125610. static encode_aux_threshmatch _vq_auxt__44c1_sm_p6_1 = {
  125611. _vq_quantthresh__44c1_sm_p6_1,
  125612. _vq_quantmap__44c1_sm_p6_1,
  125613. 11,
  125614. 11
  125615. };
  125616. static static_codebook _44c1_sm_p6_1 = {
  125617. 2, 121,
  125618. _vq_lengthlist__44c1_sm_p6_1,
  125619. 1, -531365888, 1611661312, 4, 0,
  125620. _vq_quantlist__44c1_sm_p6_1,
  125621. NULL,
  125622. &_vq_auxt__44c1_sm_p6_1,
  125623. NULL,
  125624. 0
  125625. };
  125626. static long _vq_quantlist__44c1_sm_p7_0[] = {
  125627. 6,
  125628. 5,
  125629. 7,
  125630. 4,
  125631. 8,
  125632. 3,
  125633. 9,
  125634. 2,
  125635. 10,
  125636. 1,
  125637. 11,
  125638. 0,
  125639. 12,
  125640. };
  125641. static long _vq_lengthlist__44c1_sm_p7_0[] = {
  125642. 1, 4, 4, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 7, 5, 5,
  125643. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 7, 5, 6, 7, 7, 8,
  125644. 8, 8, 8, 9, 9,11,10, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  125645. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  125646. 11, 0,12,12, 9, 9,10,10,10,10,11,11,11,11, 0,13,
  125647. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0, 9,10,
  125648. 9,10,11,11,12,11,13,12, 0, 0, 0,10,10, 9, 9,11,
  125649. 11,12,12,13,12, 0, 0, 0,13,13,10,10,11,11,12,12,
  125650. 13,13, 0, 0, 0,14,14,10,10,11,11,12,12,13,13, 0,
  125651. 0, 0, 0, 0,11,12,11,11,12,13,14,13, 0, 0, 0, 0,
  125652. 0,12,12,11,11,13,12,14,13,
  125653. };
  125654. static float _vq_quantthresh__44c1_sm_p7_0[] = {
  125655. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  125656. 12.5, 17.5, 22.5, 27.5,
  125657. };
  125658. static long _vq_quantmap__44c1_sm_p7_0[] = {
  125659. 11, 9, 7, 5, 3, 1, 0, 2,
  125660. 4, 6, 8, 10, 12,
  125661. };
  125662. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_0 = {
  125663. _vq_quantthresh__44c1_sm_p7_0,
  125664. _vq_quantmap__44c1_sm_p7_0,
  125665. 13,
  125666. 13
  125667. };
  125668. static static_codebook _44c1_sm_p7_0 = {
  125669. 2, 169,
  125670. _vq_lengthlist__44c1_sm_p7_0,
  125671. 1, -526516224, 1616117760, 4, 0,
  125672. _vq_quantlist__44c1_sm_p7_0,
  125673. NULL,
  125674. &_vq_auxt__44c1_sm_p7_0,
  125675. NULL,
  125676. 0
  125677. };
  125678. static long _vq_quantlist__44c1_sm_p7_1[] = {
  125679. 2,
  125680. 1,
  125681. 3,
  125682. 0,
  125683. 4,
  125684. };
  125685. static long _vq_lengthlist__44c1_sm_p7_1[] = {
  125686. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  125687. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  125688. };
  125689. static float _vq_quantthresh__44c1_sm_p7_1[] = {
  125690. -1.5, -0.5, 0.5, 1.5,
  125691. };
  125692. static long _vq_quantmap__44c1_sm_p7_1[] = {
  125693. 3, 1, 0, 2, 4,
  125694. };
  125695. static encode_aux_threshmatch _vq_auxt__44c1_sm_p7_1 = {
  125696. _vq_quantthresh__44c1_sm_p7_1,
  125697. _vq_quantmap__44c1_sm_p7_1,
  125698. 5,
  125699. 5
  125700. };
  125701. static static_codebook _44c1_sm_p7_1 = {
  125702. 2, 25,
  125703. _vq_lengthlist__44c1_sm_p7_1,
  125704. 1, -533725184, 1611661312, 3, 0,
  125705. _vq_quantlist__44c1_sm_p7_1,
  125706. NULL,
  125707. &_vq_auxt__44c1_sm_p7_1,
  125708. NULL,
  125709. 0
  125710. };
  125711. static long _vq_quantlist__44c1_sm_p8_0[] = {
  125712. 6,
  125713. 5,
  125714. 7,
  125715. 4,
  125716. 8,
  125717. 3,
  125718. 9,
  125719. 2,
  125720. 10,
  125721. 1,
  125722. 11,
  125723. 0,
  125724. 12,
  125725. };
  125726. static long _vq_lengthlist__44c1_sm_p8_0[] = {
  125727. 1, 3, 3,13,13,13,13,13,13,13,13,13,13, 3, 6, 6,
  125728. 13,13,13,13,13,13,13,13,13,13, 4, 8, 7,13,13,13,
  125729. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125730. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125731. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125732. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125733. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125734. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125735. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125736. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  125737. 13,13,13,13,13,13,13,13,13,
  125738. };
  125739. static float _vq_quantthresh__44c1_sm_p8_0[] = {
  125740. -1215.5, -994.5, -773.5, -552.5, -331.5, -110.5, 110.5, 331.5,
  125741. 552.5, 773.5, 994.5, 1215.5,
  125742. };
  125743. static long _vq_quantmap__44c1_sm_p8_0[] = {
  125744. 11, 9, 7, 5, 3, 1, 0, 2,
  125745. 4, 6, 8, 10, 12,
  125746. };
  125747. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_0 = {
  125748. _vq_quantthresh__44c1_sm_p8_0,
  125749. _vq_quantmap__44c1_sm_p8_0,
  125750. 13,
  125751. 13
  125752. };
  125753. static static_codebook _44c1_sm_p8_0 = {
  125754. 2, 169,
  125755. _vq_lengthlist__44c1_sm_p8_0,
  125756. 1, -514541568, 1627103232, 4, 0,
  125757. _vq_quantlist__44c1_sm_p8_0,
  125758. NULL,
  125759. &_vq_auxt__44c1_sm_p8_0,
  125760. NULL,
  125761. 0
  125762. };
  125763. static long _vq_quantlist__44c1_sm_p8_1[] = {
  125764. 6,
  125765. 5,
  125766. 7,
  125767. 4,
  125768. 8,
  125769. 3,
  125770. 9,
  125771. 2,
  125772. 10,
  125773. 1,
  125774. 11,
  125775. 0,
  125776. 12,
  125777. };
  125778. static long _vq_lengthlist__44c1_sm_p8_1[] = {
  125779. 1, 4, 4, 6, 6, 7, 7, 9, 9,10,11,12,12, 6, 5, 5,
  125780. 7, 7, 8, 7,10,10,11,11,12,12, 6, 5, 5, 7, 7, 8,
  125781. 8,10,10,11,11,12,12,16, 7, 7, 8, 8, 9, 9,11,11,
  125782. 12,12,13,13,17, 7, 7, 8, 7, 9, 9,11,10,12,12,13,
  125783. 13,19,11,10, 8, 8,10,10,11,11,12,12,13,13,19,11,
  125784. 11, 9, 7,11,10,11,11,12,12,13,12,19,19,19,10,10,
  125785. 10,10,11,12,12,12,13,14,18,19,19,11, 9,11, 9,13,
  125786. 12,12,12,13,13,19,20,19,13,15,11,11,12,12,13,13,
  125787. 14,13,18,19,20,15,13,12,10,13,10,13,13,13,14,20,
  125788. 20,20,20,20,13,14,12,12,13,12,13,13,20,20,20,20,
  125789. 20,13,12,12,12,14,12,14,13,
  125790. };
  125791. static float _vq_quantthresh__44c1_sm_p8_1[] = {
  125792. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  125793. 42.5, 59.5, 76.5, 93.5,
  125794. };
  125795. static long _vq_quantmap__44c1_sm_p8_1[] = {
  125796. 11, 9, 7, 5, 3, 1, 0, 2,
  125797. 4, 6, 8, 10, 12,
  125798. };
  125799. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_1 = {
  125800. _vq_quantthresh__44c1_sm_p8_1,
  125801. _vq_quantmap__44c1_sm_p8_1,
  125802. 13,
  125803. 13
  125804. };
  125805. static static_codebook _44c1_sm_p8_1 = {
  125806. 2, 169,
  125807. _vq_lengthlist__44c1_sm_p8_1,
  125808. 1, -522616832, 1620115456, 4, 0,
  125809. _vq_quantlist__44c1_sm_p8_1,
  125810. NULL,
  125811. &_vq_auxt__44c1_sm_p8_1,
  125812. NULL,
  125813. 0
  125814. };
  125815. static long _vq_quantlist__44c1_sm_p8_2[] = {
  125816. 8,
  125817. 7,
  125818. 9,
  125819. 6,
  125820. 10,
  125821. 5,
  125822. 11,
  125823. 4,
  125824. 12,
  125825. 3,
  125826. 13,
  125827. 2,
  125828. 14,
  125829. 1,
  125830. 15,
  125831. 0,
  125832. 16,
  125833. };
  125834. static long _vq_lengthlist__44c1_sm_p8_2[] = {
  125835. 2, 5, 5, 6, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 8,
  125836. 8,10, 6, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  125837. 9, 9,10, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  125838. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  125839. 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  125840. 9, 9, 9, 9, 9,10,11,11, 8, 8, 8, 8, 9, 9, 9, 9,
  125841. 9, 9,10,10, 9,10,10,10,10, 8, 8, 8, 8, 9, 9, 9,
  125842. 9, 9, 9, 9, 9,10,10,11,10,10, 8, 8, 9, 9, 9, 9,
  125843. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,11,11, 8, 8, 9,
  125844. 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,11,11,11, 9, 9,
  125845. 9, 9, 9, 9, 9, 9,10, 9,10, 9,11,11,11,11,11, 9,
  125846. 8, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,10,11,11,
  125847. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,11,11,11,11,
  125848. 11,11,11, 9, 9,10, 9, 9, 9, 9,10, 9,10,10,11,10,
  125849. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,10,11,
  125850. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,11,
  125851. 11,10,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9,10, 9,
  125852. 10,11,10,11,11,11,11,11,11, 9, 9,10, 9, 9, 9, 9,
  125853. 9,
  125854. };
  125855. static float _vq_quantthresh__44c1_sm_p8_2[] = {
  125856. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  125857. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  125858. };
  125859. static long _vq_quantmap__44c1_sm_p8_2[] = {
  125860. 15, 13, 11, 9, 7, 5, 3, 1,
  125861. 0, 2, 4, 6, 8, 10, 12, 14,
  125862. 16,
  125863. };
  125864. static encode_aux_threshmatch _vq_auxt__44c1_sm_p8_2 = {
  125865. _vq_quantthresh__44c1_sm_p8_2,
  125866. _vq_quantmap__44c1_sm_p8_2,
  125867. 17,
  125868. 17
  125869. };
  125870. static static_codebook _44c1_sm_p8_2 = {
  125871. 2, 289,
  125872. _vq_lengthlist__44c1_sm_p8_2,
  125873. 1, -529530880, 1611661312, 5, 0,
  125874. _vq_quantlist__44c1_sm_p8_2,
  125875. NULL,
  125876. &_vq_auxt__44c1_sm_p8_2,
  125877. NULL,
  125878. 0
  125879. };
  125880. static long _huff_lengthlist__44c1_sm_short[] = {
  125881. 4, 7,13,14,14,15,16,18,18, 4, 2, 5, 8, 7, 9,12,
  125882. 15,15,10, 4, 5,10, 6, 8,11,15,17,12, 5, 7, 5, 6,
  125883. 8,11,14,17,11, 5, 6, 6, 5, 6, 9,13,17,12, 6, 7,
  125884. 6, 5, 6, 8,12,14,14, 7, 8, 6, 6, 7, 9,11,14,14,
  125885. 8, 9, 6, 5, 6, 9,11,13,16,10,10, 7, 6, 7, 8,10,
  125886. 11,
  125887. };
  125888. static static_codebook _huff_book__44c1_sm_short = {
  125889. 2, 81,
  125890. _huff_lengthlist__44c1_sm_short,
  125891. 0, 0, 0, 0, 0,
  125892. NULL,
  125893. NULL,
  125894. NULL,
  125895. NULL,
  125896. 0
  125897. };
  125898. static long _huff_lengthlist__44cn1_s_long[] = {
  125899. 4, 4, 7, 8, 7, 8,10,12,17, 3, 1, 6, 6, 7, 8,10,
  125900. 12,15, 7, 6, 9, 9, 9,11,12,14,17, 8, 6, 9, 6, 7,
  125901. 9,11,13,17, 7, 6, 9, 7, 7, 8, 9,12,15, 8, 8,10,
  125902. 8, 7, 7, 7,10,14, 9,10,12,10, 8, 8, 8,10,14,11,
  125903. 13,15,13,12,11,11,12,16,17,18,18,19,20,18,16,16,
  125904. 20,
  125905. };
  125906. static static_codebook _huff_book__44cn1_s_long = {
  125907. 2, 81,
  125908. _huff_lengthlist__44cn1_s_long,
  125909. 0, 0, 0, 0, 0,
  125910. NULL,
  125911. NULL,
  125912. NULL,
  125913. NULL,
  125914. 0
  125915. };
  125916. static long _vq_quantlist__44cn1_s_p1_0[] = {
  125917. 1,
  125918. 0,
  125919. 2,
  125920. };
  125921. static long _vq_lengthlist__44cn1_s_p1_0[] = {
  125922. 1, 4, 4, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  125923. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  125928. 0, 0, 0, 7, 9,10, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0,
  125933. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125934. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125935. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125936. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125937. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125938. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125939. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125940. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125941. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125942. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125943. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125944. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125945. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125946. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125947. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125948. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125949. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125950. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125951. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125952. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125953. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125954. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125955. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125956. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125957. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125958. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125959. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125960. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125961. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125962. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125963. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125964. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125965. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125966. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125967. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  125968. 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 8, 9,10, 0, 0,
  125969. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125970. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125971. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125972. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0, 0,
  125973. 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  125974. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125975. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125976. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125977. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10,10, 0, 0,
  125978. 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0,10,11,11,
  125979. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125980. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  125981. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8,10,10, 0, 0,
  126014. 0, 0, 0, 0, 8,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126018. 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11, 0,
  126019. 0, 0, 0, 0, 0, 9, 9,11, 0, 0, 0, 0, 0, 0, 0, 0,
  126020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126023. 0, 0, 0, 0, 7,10,10, 0, 0, 0, 0, 0, 0,10,11,11,
  126024. 0, 0, 0, 0, 0, 0, 9,11, 9, 0, 0, 0, 0, 0, 0, 0,
  126025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126029. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126033. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126034. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126035. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126036. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126037. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126038. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126039. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126040. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126041. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126042. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126043. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126044. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126045. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126046. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126047. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126048. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126049. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126050. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126051. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126052. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126053. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126054. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126055. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126056. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126057. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126058. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126059. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126060. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126061. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126062. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126063. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126064. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126065. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126069. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126070. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126074. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126075. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126332. 0,
  126333. };
  126334. static float _vq_quantthresh__44cn1_s_p1_0[] = {
  126335. -0.5, 0.5,
  126336. };
  126337. static long _vq_quantmap__44cn1_s_p1_0[] = {
  126338. 1, 0, 2,
  126339. };
  126340. static encode_aux_threshmatch _vq_auxt__44cn1_s_p1_0 = {
  126341. _vq_quantthresh__44cn1_s_p1_0,
  126342. _vq_quantmap__44cn1_s_p1_0,
  126343. 3,
  126344. 3
  126345. };
  126346. static static_codebook _44cn1_s_p1_0 = {
  126347. 8, 6561,
  126348. _vq_lengthlist__44cn1_s_p1_0,
  126349. 1, -535822336, 1611661312, 2, 0,
  126350. _vq_quantlist__44cn1_s_p1_0,
  126351. NULL,
  126352. &_vq_auxt__44cn1_s_p1_0,
  126353. NULL,
  126354. 0
  126355. };
  126356. static long _vq_quantlist__44cn1_s_p2_0[] = {
  126357. 2,
  126358. 1,
  126359. 3,
  126360. 0,
  126361. 4,
  126362. };
  126363. static long _vq_lengthlist__44cn1_s_p2_0[] = {
  126364. 1, 4, 4, 7, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  126366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126367. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  126369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126370. 0, 0, 0, 0, 6, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  126371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126383. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126384. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126385. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126386. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126387. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126388. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126389. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126390. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126391. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126392. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126393. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126394. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126395. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126396. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126397. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126398. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126399. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126400. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126401. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126402. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126403. 0,
  126404. };
  126405. static float _vq_quantthresh__44cn1_s_p2_0[] = {
  126406. -1.5, -0.5, 0.5, 1.5,
  126407. };
  126408. static long _vq_quantmap__44cn1_s_p2_0[] = {
  126409. 3, 1, 0, 2, 4,
  126410. };
  126411. static encode_aux_threshmatch _vq_auxt__44cn1_s_p2_0 = {
  126412. _vq_quantthresh__44cn1_s_p2_0,
  126413. _vq_quantmap__44cn1_s_p2_0,
  126414. 5,
  126415. 5
  126416. };
  126417. static static_codebook _44cn1_s_p2_0 = {
  126418. 4, 625,
  126419. _vq_lengthlist__44cn1_s_p2_0,
  126420. 1, -533725184, 1611661312, 3, 0,
  126421. _vq_quantlist__44cn1_s_p2_0,
  126422. NULL,
  126423. &_vq_auxt__44cn1_s_p2_0,
  126424. NULL,
  126425. 0
  126426. };
  126427. static long _vq_quantlist__44cn1_s_p3_0[] = {
  126428. 4,
  126429. 3,
  126430. 5,
  126431. 2,
  126432. 6,
  126433. 1,
  126434. 7,
  126435. 0,
  126436. 8,
  126437. };
  126438. static long _vq_lengthlist__44cn1_s_p3_0[] = {
  126439. 1, 2, 3, 7, 7, 0, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0,
  126440. 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 0, 7, 7,
  126441. 0, 0, 0, 0, 0, 0, 0, 7, 7, 0, 0, 0, 0, 0, 0, 0,
  126442. 9, 8, 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0,
  126443. 0, 0,10,10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126444. 0,
  126445. };
  126446. static float _vq_quantthresh__44cn1_s_p3_0[] = {
  126447. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126448. };
  126449. static long _vq_quantmap__44cn1_s_p3_0[] = {
  126450. 7, 5, 3, 1, 0, 2, 4, 6,
  126451. 8,
  126452. };
  126453. static encode_aux_threshmatch _vq_auxt__44cn1_s_p3_0 = {
  126454. _vq_quantthresh__44cn1_s_p3_0,
  126455. _vq_quantmap__44cn1_s_p3_0,
  126456. 9,
  126457. 9
  126458. };
  126459. static static_codebook _44cn1_s_p3_0 = {
  126460. 2, 81,
  126461. _vq_lengthlist__44cn1_s_p3_0,
  126462. 1, -531628032, 1611661312, 4, 0,
  126463. _vq_quantlist__44cn1_s_p3_0,
  126464. NULL,
  126465. &_vq_auxt__44cn1_s_p3_0,
  126466. NULL,
  126467. 0
  126468. };
  126469. static long _vq_quantlist__44cn1_s_p4_0[] = {
  126470. 4,
  126471. 3,
  126472. 5,
  126473. 2,
  126474. 6,
  126475. 1,
  126476. 7,
  126477. 0,
  126478. 8,
  126479. };
  126480. static long _vq_lengthlist__44cn1_s_p4_0[] = {
  126481. 1, 3, 3, 6, 6, 6, 6, 8, 8, 0, 0, 0, 6, 6, 7, 7,
  126482. 9, 9, 0, 0, 0, 6, 6, 7, 7, 9, 9, 0, 0, 0, 7, 7,
  126483. 8, 8,10,10, 0, 0, 0, 7, 7, 8, 8,10,10, 0, 0, 0,
  126484. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  126485. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  126486. 11,
  126487. };
  126488. static float _vq_quantthresh__44cn1_s_p4_0[] = {
  126489. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  126490. };
  126491. static long _vq_quantmap__44cn1_s_p4_0[] = {
  126492. 7, 5, 3, 1, 0, 2, 4, 6,
  126493. 8,
  126494. };
  126495. static encode_aux_threshmatch _vq_auxt__44cn1_s_p4_0 = {
  126496. _vq_quantthresh__44cn1_s_p4_0,
  126497. _vq_quantmap__44cn1_s_p4_0,
  126498. 9,
  126499. 9
  126500. };
  126501. static static_codebook _44cn1_s_p4_0 = {
  126502. 2, 81,
  126503. _vq_lengthlist__44cn1_s_p4_0,
  126504. 1, -531628032, 1611661312, 4, 0,
  126505. _vq_quantlist__44cn1_s_p4_0,
  126506. NULL,
  126507. &_vq_auxt__44cn1_s_p4_0,
  126508. NULL,
  126509. 0
  126510. };
  126511. static long _vq_quantlist__44cn1_s_p5_0[] = {
  126512. 8,
  126513. 7,
  126514. 9,
  126515. 6,
  126516. 10,
  126517. 5,
  126518. 11,
  126519. 4,
  126520. 12,
  126521. 3,
  126522. 13,
  126523. 2,
  126524. 14,
  126525. 1,
  126526. 15,
  126527. 0,
  126528. 16,
  126529. };
  126530. static long _vq_lengthlist__44cn1_s_p5_0[] = {
  126531. 1, 4, 3, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  126532. 10, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,10,
  126533. 11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,10,
  126534. 10,11,11, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  126535. 11,11,11,12, 0, 0, 0, 7, 7, 8, 8, 9, 9, 9, 9,10,
  126536. 10,11,11,11,11, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,10,
  126537. 10,10,11,11,12,12, 0, 0, 0, 8, 8, 9, 9, 9, 9,10,
  126538. 10,10,11,11,11,12,12, 0, 0, 0, 9, 9,10, 9,10,10,
  126539. 10,10,11,11,11,11,12,12, 0, 0, 0, 0, 0, 9, 9,10,
  126540. 10,10,10,11,11,12,12,12,12, 0, 0, 0, 0, 0, 9, 9,
  126541. 10,10,10,11,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9,
  126542. 9,10,10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0,
  126543. 10,10,11,10,11,11,11,12,13,12,13,13, 0, 0, 0, 0,
  126544. 0, 0, 0,11,10,11,11,12,12,12,12,13,13, 0, 0, 0,
  126545. 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0, 0,
  126546. 0, 0, 0, 0, 0,11,11,12,12,12,12,13,13,13,14, 0,
  126547. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,13,13,14,14,
  126548. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,12,13,13,14,
  126549. 14,
  126550. };
  126551. static float _vq_quantthresh__44cn1_s_p5_0[] = {
  126552. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126553. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126554. };
  126555. static long _vq_quantmap__44cn1_s_p5_0[] = {
  126556. 15, 13, 11, 9, 7, 5, 3, 1,
  126557. 0, 2, 4, 6, 8, 10, 12, 14,
  126558. 16,
  126559. };
  126560. static encode_aux_threshmatch _vq_auxt__44cn1_s_p5_0 = {
  126561. _vq_quantthresh__44cn1_s_p5_0,
  126562. _vq_quantmap__44cn1_s_p5_0,
  126563. 17,
  126564. 17
  126565. };
  126566. static static_codebook _44cn1_s_p5_0 = {
  126567. 2, 289,
  126568. _vq_lengthlist__44cn1_s_p5_0,
  126569. 1, -529530880, 1611661312, 5, 0,
  126570. _vq_quantlist__44cn1_s_p5_0,
  126571. NULL,
  126572. &_vq_auxt__44cn1_s_p5_0,
  126573. NULL,
  126574. 0
  126575. };
  126576. static long _vq_quantlist__44cn1_s_p6_0[] = {
  126577. 1,
  126578. 0,
  126579. 2,
  126580. };
  126581. static long _vq_lengthlist__44cn1_s_p6_0[] = {
  126582. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 6, 6,10, 9, 9,11,
  126583. 9, 9, 4, 6, 6,10, 9, 9,10, 9, 9, 7,10,10,11,11,
  126584. 11,12,11,11, 7, 9, 9,11,11,10,11,10,10, 7, 9, 9,
  126585. 11,10,11,11,10,10, 7,10,10,11,11,11,12,11,11, 7,
  126586. 9, 9,11,10,10,11,10,10, 7, 9, 9,11,10,10,11,10,
  126587. 10,
  126588. };
  126589. static float _vq_quantthresh__44cn1_s_p6_0[] = {
  126590. -5.5, 5.5,
  126591. };
  126592. static long _vq_quantmap__44cn1_s_p6_0[] = {
  126593. 1, 0, 2,
  126594. };
  126595. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_0 = {
  126596. _vq_quantthresh__44cn1_s_p6_0,
  126597. _vq_quantmap__44cn1_s_p6_0,
  126598. 3,
  126599. 3
  126600. };
  126601. static static_codebook _44cn1_s_p6_0 = {
  126602. 4, 81,
  126603. _vq_lengthlist__44cn1_s_p6_0,
  126604. 1, -529137664, 1618345984, 2, 0,
  126605. _vq_quantlist__44cn1_s_p6_0,
  126606. NULL,
  126607. &_vq_auxt__44cn1_s_p6_0,
  126608. NULL,
  126609. 0
  126610. };
  126611. static long _vq_quantlist__44cn1_s_p6_1[] = {
  126612. 5,
  126613. 4,
  126614. 6,
  126615. 3,
  126616. 7,
  126617. 2,
  126618. 8,
  126619. 1,
  126620. 9,
  126621. 0,
  126622. 10,
  126623. };
  126624. static long _vq_lengthlist__44cn1_s_p6_1[] = {
  126625. 1, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,10, 7, 6,
  126626. 8, 8, 8, 8, 8, 8,10,10,10, 7, 6, 7, 7, 8, 8, 8,
  126627. 8,10,10,10, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  126628. 7, 8, 8, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 9, 9,
  126629. 9, 9,10,10,10, 8, 8, 8, 8, 9, 9, 9, 9,10,10,10,
  126630. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10, 9, 9, 9,
  126631. 9, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,10,
  126632. 10,10,10, 9, 9, 9, 9, 9, 9,
  126633. };
  126634. static float _vq_quantthresh__44cn1_s_p6_1[] = {
  126635. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  126636. 3.5, 4.5,
  126637. };
  126638. static long _vq_quantmap__44cn1_s_p6_1[] = {
  126639. 9, 7, 5, 3, 1, 0, 2, 4,
  126640. 6, 8, 10,
  126641. };
  126642. static encode_aux_threshmatch _vq_auxt__44cn1_s_p6_1 = {
  126643. _vq_quantthresh__44cn1_s_p6_1,
  126644. _vq_quantmap__44cn1_s_p6_1,
  126645. 11,
  126646. 11
  126647. };
  126648. static static_codebook _44cn1_s_p6_1 = {
  126649. 2, 121,
  126650. _vq_lengthlist__44cn1_s_p6_1,
  126651. 1, -531365888, 1611661312, 4, 0,
  126652. _vq_quantlist__44cn1_s_p6_1,
  126653. NULL,
  126654. &_vq_auxt__44cn1_s_p6_1,
  126655. NULL,
  126656. 0
  126657. };
  126658. static long _vq_quantlist__44cn1_s_p7_0[] = {
  126659. 6,
  126660. 5,
  126661. 7,
  126662. 4,
  126663. 8,
  126664. 3,
  126665. 9,
  126666. 2,
  126667. 10,
  126668. 1,
  126669. 11,
  126670. 0,
  126671. 12,
  126672. };
  126673. static long _vq_lengthlist__44cn1_s_p7_0[] = {
  126674. 1, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 6, 5, 5,
  126675. 7, 7, 8, 8, 8, 8, 9, 9,11,11, 7, 5, 5, 7, 7, 8,
  126676. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  126677. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  126678. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,11,12, 0,13,
  126679. 13, 9, 9, 9, 9,10,10,11,11,11,12, 0, 0, 0,10,10,
  126680. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  126681. 11,12,12,13,12, 0, 0, 0,14,14,11,10,11,12,12,13,
  126682. 13,14, 0, 0, 0,15,15,11,11,12,11,12,12,14,13, 0,
  126683. 0, 0, 0, 0,12,12,12,12,13,13,14,14, 0, 0, 0, 0,
  126684. 0,13,13,12,12,13,13,13,14,
  126685. };
  126686. static float _vq_quantthresh__44cn1_s_p7_0[] = {
  126687. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  126688. 12.5, 17.5, 22.5, 27.5,
  126689. };
  126690. static long _vq_quantmap__44cn1_s_p7_0[] = {
  126691. 11, 9, 7, 5, 3, 1, 0, 2,
  126692. 4, 6, 8, 10, 12,
  126693. };
  126694. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_0 = {
  126695. _vq_quantthresh__44cn1_s_p7_0,
  126696. _vq_quantmap__44cn1_s_p7_0,
  126697. 13,
  126698. 13
  126699. };
  126700. static static_codebook _44cn1_s_p7_0 = {
  126701. 2, 169,
  126702. _vq_lengthlist__44cn1_s_p7_0,
  126703. 1, -526516224, 1616117760, 4, 0,
  126704. _vq_quantlist__44cn1_s_p7_0,
  126705. NULL,
  126706. &_vq_auxt__44cn1_s_p7_0,
  126707. NULL,
  126708. 0
  126709. };
  126710. static long _vq_quantlist__44cn1_s_p7_1[] = {
  126711. 2,
  126712. 1,
  126713. 3,
  126714. 0,
  126715. 4,
  126716. };
  126717. static long _vq_lengthlist__44cn1_s_p7_1[] = {
  126718. 2, 3, 3, 5, 5, 6, 6, 6, 5, 5, 6, 6, 6, 5, 5, 6,
  126719. 6, 6, 5, 5, 6, 6, 6, 5, 5,
  126720. };
  126721. static float _vq_quantthresh__44cn1_s_p7_1[] = {
  126722. -1.5, -0.5, 0.5, 1.5,
  126723. };
  126724. static long _vq_quantmap__44cn1_s_p7_1[] = {
  126725. 3, 1, 0, 2, 4,
  126726. };
  126727. static encode_aux_threshmatch _vq_auxt__44cn1_s_p7_1 = {
  126728. _vq_quantthresh__44cn1_s_p7_1,
  126729. _vq_quantmap__44cn1_s_p7_1,
  126730. 5,
  126731. 5
  126732. };
  126733. static static_codebook _44cn1_s_p7_1 = {
  126734. 2, 25,
  126735. _vq_lengthlist__44cn1_s_p7_1,
  126736. 1, -533725184, 1611661312, 3, 0,
  126737. _vq_quantlist__44cn1_s_p7_1,
  126738. NULL,
  126739. &_vq_auxt__44cn1_s_p7_1,
  126740. NULL,
  126741. 0
  126742. };
  126743. static long _vq_quantlist__44cn1_s_p8_0[] = {
  126744. 2,
  126745. 1,
  126746. 3,
  126747. 0,
  126748. 4,
  126749. };
  126750. static long _vq_lengthlist__44cn1_s_p8_0[] = {
  126751. 1, 7, 7,11,11, 8,11,11,11,11, 4,11, 3,11,11,11,
  126752. 11,11,11,11,11,11,11,11,11,11,11,10,11,11,11,11,
  126753. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126754. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  126755. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126756. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126757. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126758. 11,11,11,11,11,11,11,11,11,11,11,11,11, 7,11,11,
  126759. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126760. 11,11,11,11,11,11,10,11,11,11,11,11,11,11,11,11,
  126761. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  126762. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126763. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126764. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126765. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126766. 11,11,11,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  126767. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126768. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126769. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126770. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126771. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126772. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126773. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126774. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126775. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126776. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126777. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126778. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126779. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126780. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126781. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126782. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126783. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  126784. 11,11,11,11,11,11,11,12,12,12,12,12,12,12,12,12,
  126785. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126786. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126787. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126788. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126789. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  126790. 12,
  126791. };
  126792. static float _vq_quantthresh__44cn1_s_p8_0[] = {
  126793. -331.5, -110.5, 110.5, 331.5,
  126794. };
  126795. static long _vq_quantmap__44cn1_s_p8_0[] = {
  126796. 3, 1, 0, 2, 4,
  126797. };
  126798. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_0 = {
  126799. _vq_quantthresh__44cn1_s_p8_0,
  126800. _vq_quantmap__44cn1_s_p8_0,
  126801. 5,
  126802. 5
  126803. };
  126804. static static_codebook _44cn1_s_p8_0 = {
  126805. 4, 625,
  126806. _vq_lengthlist__44cn1_s_p8_0,
  126807. 1, -518283264, 1627103232, 3, 0,
  126808. _vq_quantlist__44cn1_s_p8_0,
  126809. NULL,
  126810. &_vq_auxt__44cn1_s_p8_0,
  126811. NULL,
  126812. 0
  126813. };
  126814. static long _vq_quantlist__44cn1_s_p8_1[] = {
  126815. 6,
  126816. 5,
  126817. 7,
  126818. 4,
  126819. 8,
  126820. 3,
  126821. 9,
  126822. 2,
  126823. 10,
  126824. 1,
  126825. 11,
  126826. 0,
  126827. 12,
  126828. };
  126829. static long _vq_lengthlist__44cn1_s_p8_1[] = {
  126830. 1, 4, 4, 6, 6, 8, 8, 9,10,10,11,11,11, 6, 5, 5,
  126831. 7, 7, 8, 8, 9,10, 9,11,11,12, 5, 5, 5, 7, 7, 8,
  126832. 9,10,10,12,12,14,13,15, 7, 7, 8, 8, 9,10,11,11,
  126833. 10,12,10,11,15, 7, 8, 8, 8, 9, 9,11,11,13,12,12,
  126834. 13,15,10,10, 8, 8,10,10,12,12,11,14,10,10,15,11,
  126835. 11, 8, 8,10,10,12,13,13,14,15,13,15,15,15,10,10,
  126836. 10,10,12,12,13,12,13,10,15,15,15,10,10,11,10,13,
  126837. 11,13,13,15,13,15,15,15,13,13,10,11,11,11,12,10,
  126838. 14,11,15,15,14,14,13,10,10,12,11,13,13,14,14,15,
  126839. 15,15,15,15,11,11,11,11,12,11,15,12,15,15,15,15,
  126840. 15,12,12,11,11,14,12,13,14,
  126841. };
  126842. static float _vq_quantthresh__44cn1_s_p8_1[] = {
  126843. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  126844. 42.5, 59.5, 76.5, 93.5,
  126845. };
  126846. static long _vq_quantmap__44cn1_s_p8_1[] = {
  126847. 11, 9, 7, 5, 3, 1, 0, 2,
  126848. 4, 6, 8, 10, 12,
  126849. };
  126850. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_1 = {
  126851. _vq_quantthresh__44cn1_s_p8_1,
  126852. _vq_quantmap__44cn1_s_p8_1,
  126853. 13,
  126854. 13
  126855. };
  126856. static static_codebook _44cn1_s_p8_1 = {
  126857. 2, 169,
  126858. _vq_lengthlist__44cn1_s_p8_1,
  126859. 1, -522616832, 1620115456, 4, 0,
  126860. _vq_quantlist__44cn1_s_p8_1,
  126861. NULL,
  126862. &_vq_auxt__44cn1_s_p8_1,
  126863. NULL,
  126864. 0
  126865. };
  126866. static long _vq_quantlist__44cn1_s_p8_2[] = {
  126867. 8,
  126868. 7,
  126869. 9,
  126870. 6,
  126871. 10,
  126872. 5,
  126873. 11,
  126874. 4,
  126875. 12,
  126876. 3,
  126877. 13,
  126878. 2,
  126879. 14,
  126880. 1,
  126881. 15,
  126882. 0,
  126883. 16,
  126884. };
  126885. static long _vq_lengthlist__44cn1_s_p8_2[] = {
  126886. 3, 4, 3, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  126887. 9,10,11,11, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  126888. 9, 9,10,10,10, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  126889. 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9, 9,
  126890. 9, 9,10, 9,10,11,10, 7, 6, 7, 7, 8, 8, 9, 9, 9,
  126891. 9, 9, 9, 9,10,10,10,11, 7, 7, 8, 8, 8, 8, 9, 9,
  126892. 9, 9, 9, 9, 9, 9,10,10,10, 7, 7, 8, 8, 8, 8, 9,
  126893. 9, 9, 9, 9, 9, 9,10,11,11,11, 8, 8, 8, 8, 8, 8,
  126894. 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,11, 8, 8, 8,
  126895. 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,11,11, 9, 9,
  126896. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,11,10,11,11, 9,
  126897. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,10,11,10,11,11,
  126898. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,10,11,
  126899. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11,
  126900. 10,11,11,11, 9,10,10, 9, 9, 9, 9, 9, 9, 9,10,11,
  126901. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  126902. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  126903. 11,11,11,10,11,11,11,11,11, 9, 9, 9,10, 9, 9, 9,
  126904. 9,
  126905. };
  126906. static float _vq_quantthresh__44cn1_s_p8_2[] = {
  126907. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  126908. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  126909. };
  126910. static long _vq_quantmap__44cn1_s_p8_2[] = {
  126911. 15, 13, 11, 9, 7, 5, 3, 1,
  126912. 0, 2, 4, 6, 8, 10, 12, 14,
  126913. 16,
  126914. };
  126915. static encode_aux_threshmatch _vq_auxt__44cn1_s_p8_2 = {
  126916. _vq_quantthresh__44cn1_s_p8_2,
  126917. _vq_quantmap__44cn1_s_p8_2,
  126918. 17,
  126919. 17
  126920. };
  126921. static static_codebook _44cn1_s_p8_2 = {
  126922. 2, 289,
  126923. _vq_lengthlist__44cn1_s_p8_2,
  126924. 1, -529530880, 1611661312, 5, 0,
  126925. _vq_quantlist__44cn1_s_p8_2,
  126926. NULL,
  126927. &_vq_auxt__44cn1_s_p8_2,
  126928. NULL,
  126929. 0
  126930. };
  126931. static long _huff_lengthlist__44cn1_s_short[] = {
  126932. 10, 9,12,15,12,13,16,14,16, 7, 1, 5,14, 7,10,13,
  126933. 16,16, 9, 4, 6,16, 8,11,16,16,16,14, 4, 7,16, 9,
  126934. 12,14,16,16,10, 5, 7,14, 9,12,14,15,15,13, 8, 9,
  126935. 14,10,12,13,14,15,13, 9, 9, 7, 6, 8,11,12,12,14,
  126936. 8, 8, 5, 4, 5, 8,11,12,16,10,10, 6, 5, 6, 8, 9,
  126937. 10,
  126938. };
  126939. static static_codebook _huff_book__44cn1_s_short = {
  126940. 2, 81,
  126941. _huff_lengthlist__44cn1_s_short,
  126942. 0, 0, 0, 0, 0,
  126943. NULL,
  126944. NULL,
  126945. NULL,
  126946. NULL,
  126947. 0
  126948. };
  126949. static long _huff_lengthlist__44cn1_sm_long[] = {
  126950. 3, 3, 8, 8, 8, 8,10,12,14, 3, 2, 6, 7, 7, 8,10,
  126951. 12,16, 7, 6, 7, 9, 8,10,12,14,16, 8, 6, 8, 4, 5,
  126952. 7, 9,11,13, 7, 6, 8, 5, 6, 7, 9,11,14, 8, 8,10,
  126953. 7, 7, 6, 8,10,13, 9,11,12, 9, 9, 7, 8,10,12,10,
  126954. 13,15,11,11,10, 9,10,13,13,16,17,14,15,14,13,14,
  126955. 17,
  126956. };
  126957. static static_codebook _huff_book__44cn1_sm_long = {
  126958. 2, 81,
  126959. _huff_lengthlist__44cn1_sm_long,
  126960. 0, 0, 0, 0, 0,
  126961. NULL,
  126962. NULL,
  126963. NULL,
  126964. NULL,
  126965. 0
  126966. };
  126967. static long _vq_quantlist__44cn1_sm_p1_0[] = {
  126968. 1,
  126969. 0,
  126970. 2,
  126971. };
  126972. static long _vq_lengthlist__44cn1_sm_p1_0[] = {
  126973. 1, 4, 5, 0, 0, 0, 0, 0, 0, 5, 7, 7, 0, 0, 0, 0,
  126974. 0, 0, 5, 7, 7, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0, 0,
  126979. 0, 0, 0, 7, 8, 9, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 7, 9, 8, 0, 0,
  126984. 0, 0, 0, 0, 8, 9, 9, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126985. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126986. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126987. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126988. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126989. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126990. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126991. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126992. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126993. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126994. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126995. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126996. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126997. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126998. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  126999. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127000. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127001. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127002. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127003. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127004. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127005. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127006. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127007. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127008. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127009. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127010. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127011. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127012. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127013. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127014. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127015. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127016. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127017. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127018. 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 8, 8, 0, 0, 0, 0,
  127019. 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  127020. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127021. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127022. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127023. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7,10, 9, 0, 0, 0,
  127024. 0, 0, 0, 9, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  127025. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127026. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127027. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127028. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7, 9, 9, 0, 0,
  127029. 0, 0, 0, 0, 8,10, 9, 0, 0, 0, 0, 0, 0, 9,10,10,
  127030. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127031. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127032. 0, 0, 0, 0, 0, 0, 0, 0, 0, 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, 5, 8, 8, 0, 0, 0, 0, 0, 0, 8, 9, 9, 0, 0,
  127065. 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127066. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127067. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127068. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127069. 0, 0, 0, 7, 9, 9, 0, 0, 0, 0, 0, 0, 9,10,10, 0,
  127070. 0, 0, 0, 0, 0, 8, 9,10, 0, 0, 0, 0, 0, 0, 0, 0,
  127071. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127072. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127073. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127074. 0, 0, 0, 0, 7, 9,10, 0, 0, 0, 0, 0, 0, 9,10,10,
  127075. 0, 0, 0, 0, 0, 0, 9,10, 9, 0, 0, 0, 0, 0, 0, 0,
  127076. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127077. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127078. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127079. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127080. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127081. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127082. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127083. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127084. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127085. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127086. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127087. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127088. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127089. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127090. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127091. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127092. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127093. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127094. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127095. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127096. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127097. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127098. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127099. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127100. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127101. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127102. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127103. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127104. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127105. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127106. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127107. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127108. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127109. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127110. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127111. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127112. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127113. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127114. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127115. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127116. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127117. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127118. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127119. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127120. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127121. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127122. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127123. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127124. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127125. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127126. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127127. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127128. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127129. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127130. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127131. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127132. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127133. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127134. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127135. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127136. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127137. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127138. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127139. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127140. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127141. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127142. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127143. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127144. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127145. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127146. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127147. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127148. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127149. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127150. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127151. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127152. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127153. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127154. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127155. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127156. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127157. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127158. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127159. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127160. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127161. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127162. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127163. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127164. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127165. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127166. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127167. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127168. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127169. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127170. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127171. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127172. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127173. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127174. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127175. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127176. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127177. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127178. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127179. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127180. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127181. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127182. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127183. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127184. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127185. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127186. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127187. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127188. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127189. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127190. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127191. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127192. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127193. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127194. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127195. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127196. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127197. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127198. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127199. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127200. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127201. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127202. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127203. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127204. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127205. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127206. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127207. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127208. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127209. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127210. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127211. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127212. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127213. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127214. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127215. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127216. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127217. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127218. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127219. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127220. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127221. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127222. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127223. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127224. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127225. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127226. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127227. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127228. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127229. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127230. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127231. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127232. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127233. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127234. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127235. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127236. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127237. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127238. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127239. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127240. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127241. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127242. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127243. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127244. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127245. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127246. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127247. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127248. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127249. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127250. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127251. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127252. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127253. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127254. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127255. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127256. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127257. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127258. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127259. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127260. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127261. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127262. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127263. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127264. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127265. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127266. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127267. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127268. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127269. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127270. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127271. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127272. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127273. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127274. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127275. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127276. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127277. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127278. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127279. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127280. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127281. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127282. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127283. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127284. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127285. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127286. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127287. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127288. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127289. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127290. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127291. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127292. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127293. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127294. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127295. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127296. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127297. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127298. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127299. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127300. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127301. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127302. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127303. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127304. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127305. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127306. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127307. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127308. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127309. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127310. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127311. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127312. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127313. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127314. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127315. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127316. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127317. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127318. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127319. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127320. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127321. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127322. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127323. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127324. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127325. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127326. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127327. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127328. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127329. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127330. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127331. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127332. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127333. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127334. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127335. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127336. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127337. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127338. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127339. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127340. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127341. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127342. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127343. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127344. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127345. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127346. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127347. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127348. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127349. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127350. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127351. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127352. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127353. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127354. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127355. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127356. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127357. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127358. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127359. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127360. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127361. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127362. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127363. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127364. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127365. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127366. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127367. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127368. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127369. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127370. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127371. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127372. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127373. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127374. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127375. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127376. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127377. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127378. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127379. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127380. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127381. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127382. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127383. 0,
  127384. };
  127385. static float _vq_quantthresh__44cn1_sm_p1_0[] = {
  127386. -0.5, 0.5,
  127387. };
  127388. static long _vq_quantmap__44cn1_sm_p1_0[] = {
  127389. 1, 0, 2,
  127390. };
  127391. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p1_0 = {
  127392. _vq_quantthresh__44cn1_sm_p1_0,
  127393. _vq_quantmap__44cn1_sm_p1_0,
  127394. 3,
  127395. 3
  127396. };
  127397. static static_codebook _44cn1_sm_p1_0 = {
  127398. 8, 6561,
  127399. _vq_lengthlist__44cn1_sm_p1_0,
  127400. 1, -535822336, 1611661312, 2, 0,
  127401. _vq_quantlist__44cn1_sm_p1_0,
  127402. NULL,
  127403. &_vq_auxt__44cn1_sm_p1_0,
  127404. NULL,
  127405. 0
  127406. };
  127407. static long _vq_quantlist__44cn1_sm_p2_0[] = {
  127408. 2,
  127409. 1,
  127410. 3,
  127411. 0,
  127412. 4,
  127413. };
  127414. static long _vq_lengthlist__44cn1_sm_p2_0[] = {
  127415. 1, 4, 4, 6, 6, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127416. 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 5, 5, 7, 7, 0, 0,
  127417. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127418. 0, 0, 4, 5, 5, 7, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127419. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 6, 7, 7, 9, 9,
  127420. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127421. 0, 0, 0, 0, 7, 7, 7, 9, 9, 0, 0, 0, 0, 0, 0, 0,
  127422. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127423. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127424. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127425. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127426. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127427. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127428. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127429. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127430. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127431. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127432. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127433. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127434. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127435. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127436. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127437. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127438. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127439. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127440. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127441. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127442. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127443. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127444. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127445. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127446. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127447. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127448. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127449. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127450. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127451. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127452. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127453. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127454. 0,
  127455. };
  127456. static float _vq_quantthresh__44cn1_sm_p2_0[] = {
  127457. -1.5, -0.5, 0.5, 1.5,
  127458. };
  127459. static long _vq_quantmap__44cn1_sm_p2_0[] = {
  127460. 3, 1, 0, 2, 4,
  127461. };
  127462. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p2_0 = {
  127463. _vq_quantthresh__44cn1_sm_p2_0,
  127464. _vq_quantmap__44cn1_sm_p2_0,
  127465. 5,
  127466. 5
  127467. };
  127468. static static_codebook _44cn1_sm_p2_0 = {
  127469. 4, 625,
  127470. _vq_lengthlist__44cn1_sm_p2_0,
  127471. 1, -533725184, 1611661312, 3, 0,
  127472. _vq_quantlist__44cn1_sm_p2_0,
  127473. NULL,
  127474. &_vq_auxt__44cn1_sm_p2_0,
  127475. NULL,
  127476. 0
  127477. };
  127478. static long _vq_quantlist__44cn1_sm_p3_0[] = {
  127479. 4,
  127480. 3,
  127481. 5,
  127482. 2,
  127483. 6,
  127484. 1,
  127485. 7,
  127486. 0,
  127487. 8,
  127488. };
  127489. static long _vq_lengthlist__44cn1_sm_p3_0[] = {
  127490. 1, 3, 4, 7, 7, 0, 0, 0, 0, 0, 4, 4, 7, 7, 0, 0,
  127491. 0, 0, 0, 4, 5, 7, 7, 0, 0, 0, 0, 0, 6, 7, 8, 8,
  127492. 0, 0, 0, 0, 0, 0, 0, 8, 8, 0, 0, 0, 0, 0, 0, 0,
  127493. 9, 9, 0, 0, 0, 0, 0, 0, 0,10, 9, 0, 0, 0, 0, 0,
  127494. 0, 0,11,11, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  127495. 0,
  127496. };
  127497. static float _vq_quantthresh__44cn1_sm_p3_0[] = {
  127498. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127499. };
  127500. static long _vq_quantmap__44cn1_sm_p3_0[] = {
  127501. 7, 5, 3, 1, 0, 2, 4, 6,
  127502. 8,
  127503. };
  127504. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p3_0 = {
  127505. _vq_quantthresh__44cn1_sm_p3_0,
  127506. _vq_quantmap__44cn1_sm_p3_0,
  127507. 9,
  127508. 9
  127509. };
  127510. static static_codebook _44cn1_sm_p3_0 = {
  127511. 2, 81,
  127512. _vq_lengthlist__44cn1_sm_p3_0,
  127513. 1, -531628032, 1611661312, 4, 0,
  127514. _vq_quantlist__44cn1_sm_p3_0,
  127515. NULL,
  127516. &_vq_auxt__44cn1_sm_p3_0,
  127517. NULL,
  127518. 0
  127519. };
  127520. static long _vq_quantlist__44cn1_sm_p4_0[] = {
  127521. 4,
  127522. 3,
  127523. 5,
  127524. 2,
  127525. 6,
  127526. 1,
  127527. 7,
  127528. 0,
  127529. 8,
  127530. };
  127531. static long _vq_lengthlist__44cn1_sm_p4_0[] = {
  127532. 1, 4, 3, 6, 6, 7, 7, 9, 9, 0, 5, 5, 7, 7, 8, 7,
  127533. 9, 9, 0, 5, 5, 7, 7, 8, 8, 9, 9, 0, 7, 7, 8, 8,
  127534. 8, 8,10,10, 0, 0, 0, 8, 8, 8, 8,10,10, 0, 0, 0,
  127535. 9, 9, 9, 9,10,10, 0, 0, 0, 9, 9, 9, 9,10,10, 0,
  127536. 0, 0,10,10,10,10,11,11, 0, 0, 0, 0, 0,10,10,11,
  127537. 11,
  127538. };
  127539. static float _vq_quantthresh__44cn1_sm_p4_0[] = {
  127540. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  127541. };
  127542. static long _vq_quantmap__44cn1_sm_p4_0[] = {
  127543. 7, 5, 3, 1, 0, 2, 4, 6,
  127544. 8,
  127545. };
  127546. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p4_0 = {
  127547. _vq_quantthresh__44cn1_sm_p4_0,
  127548. _vq_quantmap__44cn1_sm_p4_0,
  127549. 9,
  127550. 9
  127551. };
  127552. static static_codebook _44cn1_sm_p4_0 = {
  127553. 2, 81,
  127554. _vq_lengthlist__44cn1_sm_p4_0,
  127555. 1, -531628032, 1611661312, 4, 0,
  127556. _vq_quantlist__44cn1_sm_p4_0,
  127557. NULL,
  127558. &_vq_auxt__44cn1_sm_p4_0,
  127559. NULL,
  127560. 0
  127561. };
  127562. static long _vq_quantlist__44cn1_sm_p5_0[] = {
  127563. 8,
  127564. 7,
  127565. 9,
  127566. 6,
  127567. 10,
  127568. 5,
  127569. 11,
  127570. 4,
  127571. 12,
  127572. 3,
  127573. 13,
  127574. 2,
  127575. 14,
  127576. 1,
  127577. 15,
  127578. 0,
  127579. 16,
  127580. };
  127581. static long _vq_lengthlist__44cn1_sm_p5_0[] = {
  127582. 1, 4, 4, 6, 6, 8, 8, 9, 9, 8, 8, 9, 9,10,10,11,
  127583. 11, 0, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  127584. 12,12, 0, 6, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  127585. 11,12,12, 0, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  127586. 11,11,12,12, 0, 0, 0, 7, 7, 8, 8, 9, 9,10,10,11,
  127587. 11,11,11,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,10,
  127588. 11,11,12,12,12,12, 0, 0, 0, 8, 8, 9, 9,10,10,10,
  127589. 10,11,11,12,12,12,12, 0, 0, 0, 9, 9, 9, 9,10,10,
  127590. 10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,10,
  127591. 10,10,10,11,11,12,12,13,13, 0, 0, 0, 0, 0, 9, 9,
  127592. 10,10,11,11,12,12,13,13,13,13, 0, 0, 0, 0, 0, 9,
  127593. 9,10,10,11,11,12,12,12,13,13,13, 0, 0, 0, 0, 0,
  127594. 10,10,11,11,11,11,12,12,13,13,14,14, 0, 0, 0, 0,
  127595. 0, 0, 0,11,11,11,11,12,12,13,13,14,14, 0, 0, 0,
  127596. 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0, 0,
  127597. 0, 0, 0, 0, 0,11,11,12,12,13,13,13,13,14,14, 0,
  127598. 0, 0, 0, 0, 0, 0,12,12,12,13,13,13,14,14,14,14,
  127599. 0, 0, 0, 0, 0, 0, 0, 0, 0,12,12,13,13,14,14,14,
  127600. 14,
  127601. };
  127602. static float _vq_quantthresh__44cn1_sm_p5_0[] = {
  127603. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127604. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127605. };
  127606. static long _vq_quantmap__44cn1_sm_p5_0[] = {
  127607. 15, 13, 11, 9, 7, 5, 3, 1,
  127608. 0, 2, 4, 6, 8, 10, 12, 14,
  127609. 16,
  127610. };
  127611. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p5_0 = {
  127612. _vq_quantthresh__44cn1_sm_p5_0,
  127613. _vq_quantmap__44cn1_sm_p5_0,
  127614. 17,
  127615. 17
  127616. };
  127617. static static_codebook _44cn1_sm_p5_0 = {
  127618. 2, 289,
  127619. _vq_lengthlist__44cn1_sm_p5_0,
  127620. 1, -529530880, 1611661312, 5, 0,
  127621. _vq_quantlist__44cn1_sm_p5_0,
  127622. NULL,
  127623. &_vq_auxt__44cn1_sm_p5_0,
  127624. NULL,
  127625. 0
  127626. };
  127627. static long _vq_quantlist__44cn1_sm_p6_0[] = {
  127628. 1,
  127629. 0,
  127630. 2,
  127631. };
  127632. static long _vq_lengthlist__44cn1_sm_p6_0[] = {
  127633. 1, 4, 4, 7, 6, 6, 7, 6, 6, 4, 7, 6,10, 9, 9,11,
  127634. 9, 9, 4, 6, 7,10, 9, 9,11, 9, 9, 7,10,10,10,11,
  127635. 11,11,11,10, 6, 9, 9,11,10,10,11,10,10, 6, 9, 9,
  127636. 11,10,11,11,10,10, 7,11,11,11,11,11,12,11,11, 7,
  127637. 9, 9,11,10,10,12,10,10, 7, 9, 9,11,10,10,11,10,
  127638. 10,
  127639. };
  127640. static float _vq_quantthresh__44cn1_sm_p6_0[] = {
  127641. -5.5, 5.5,
  127642. };
  127643. static long _vq_quantmap__44cn1_sm_p6_0[] = {
  127644. 1, 0, 2,
  127645. };
  127646. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_0 = {
  127647. _vq_quantthresh__44cn1_sm_p6_0,
  127648. _vq_quantmap__44cn1_sm_p6_0,
  127649. 3,
  127650. 3
  127651. };
  127652. static static_codebook _44cn1_sm_p6_0 = {
  127653. 4, 81,
  127654. _vq_lengthlist__44cn1_sm_p6_0,
  127655. 1, -529137664, 1618345984, 2, 0,
  127656. _vq_quantlist__44cn1_sm_p6_0,
  127657. NULL,
  127658. &_vq_auxt__44cn1_sm_p6_0,
  127659. NULL,
  127660. 0
  127661. };
  127662. static long _vq_quantlist__44cn1_sm_p6_1[] = {
  127663. 5,
  127664. 4,
  127665. 6,
  127666. 3,
  127667. 7,
  127668. 2,
  127669. 8,
  127670. 1,
  127671. 9,
  127672. 0,
  127673. 10,
  127674. };
  127675. static long _vq_lengthlist__44cn1_sm_p6_1[] = {
  127676. 2, 4, 4, 5, 5, 7, 7, 7, 7, 8, 8,10, 5, 5, 6, 6,
  127677. 7, 7, 8, 8, 8, 8,10, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  127678. 8,10, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8,10,10,10, 7,
  127679. 7, 7, 7, 8, 8, 8, 8,10,10,10, 8, 8, 8, 8, 8, 8,
  127680. 8, 8,10,10,10, 8, 8, 8, 8, 8, 8, 8, 8,10,10,10,
  127681. 8, 8, 8, 8, 8, 8, 9, 9,10,10,10,10,10, 8, 8, 8,
  127682. 8, 9, 9,10,10,10,10,10, 9, 9, 9, 9, 8, 9,10,10,
  127683. 10,10,10, 8, 9, 8, 8, 9, 8,
  127684. };
  127685. static float _vq_quantthresh__44cn1_sm_p6_1[] = {
  127686. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  127687. 3.5, 4.5,
  127688. };
  127689. static long _vq_quantmap__44cn1_sm_p6_1[] = {
  127690. 9, 7, 5, 3, 1, 0, 2, 4,
  127691. 6, 8, 10,
  127692. };
  127693. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p6_1 = {
  127694. _vq_quantthresh__44cn1_sm_p6_1,
  127695. _vq_quantmap__44cn1_sm_p6_1,
  127696. 11,
  127697. 11
  127698. };
  127699. static static_codebook _44cn1_sm_p6_1 = {
  127700. 2, 121,
  127701. _vq_lengthlist__44cn1_sm_p6_1,
  127702. 1, -531365888, 1611661312, 4, 0,
  127703. _vq_quantlist__44cn1_sm_p6_1,
  127704. NULL,
  127705. &_vq_auxt__44cn1_sm_p6_1,
  127706. NULL,
  127707. 0
  127708. };
  127709. static long _vq_quantlist__44cn1_sm_p7_0[] = {
  127710. 6,
  127711. 5,
  127712. 7,
  127713. 4,
  127714. 8,
  127715. 3,
  127716. 9,
  127717. 2,
  127718. 10,
  127719. 1,
  127720. 11,
  127721. 0,
  127722. 12,
  127723. };
  127724. static long _vq_lengthlist__44cn1_sm_p7_0[] = {
  127725. 1, 4, 4, 6, 6, 7, 7, 7, 7, 9, 9,10,10, 7, 5, 5,
  127726. 7, 7, 8, 8, 8, 8,10, 9,11,10, 7, 5, 5, 7, 7, 8,
  127727. 8, 8, 8, 9,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,
  127728. 10,10,11,11, 0, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,
  127729. 11, 0,12,12, 9, 9, 9,10,10,10,11,11,12,12, 0,13,
  127730. 13, 9, 9, 9, 9,10,10,11,11,12,12, 0, 0, 0,10,10,
  127731. 10,10,11,11,12,12,12,13, 0, 0, 0,10,10,10,10,11,
  127732. 11,12,12,12,12, 0, 0, 0,14,14,11,11,11,11,12,13,
  127733. 13,13, 0, 0, 0,14,14,11,10,11,11,12,12,13,13, 0,
  127734. 0, 0, 0, 0,12,12,12,12,13,13,13,14, 0, 0, 0, 0,
  127735. 0,13,12,12,12,13,13,13,14,
  127736. };
  127737. static float _vq_quantthresh__44cn1_sm_p7_0[] = {
  127738. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  127739. 12.5, 17.5, 22.5, 27.5,
  127740. };
  127741. static long _vq_quantmap__44cn1_sm_p7_0[] = {
  127742. 11, 9, 7, 5, 3, 1, 0, 2,
  127743. 4, 6, 8, 10, 12,
  127744. };
  127745. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_0 = {
  127746. _vq_quantthresh__44cn1_sm_p7_0,
  127747. _vq_quantmap__44cn1_sm_p7_0,
  127748. 13,
  127749. 13
  127750. };
  127751. static static_codebook _44cn1_sm_p7_0 = {
  127752. 2, 169,
  127753. _vq_lengthlist__44cn1_sm_p7_0,
  127754. 1, -526516224, 1616117760, 4, 0,
  127755. _vq_quantlist__44cn1_sm_p7_0,
  127756. NULL,
  127757. &_vq_auxt__44cn1_sm_p7_0,
  127758. NULL,
  127759. 0
  127760. };
  127761. static long _vq_quantlist__44cn1_sm_p7_1[] = {
  127762. 2,
  127763. 1,
  127764. 3,
  127765. 0,
  127766. 4,
  127767. };
  127768. static long _vq_lengthlist__44cn1_sm_p7_1[] = {
  127769. 2, 4, 4, 4, 5, 6, 5, 5, 5, 5, 6, 5, 5, 5, 5, 6,
  127770. 5, 5, 5, 5, 6, 6, 6, 5, 5,
  127771. };
  127772. static float _vq_quantthresh__44cn1_sm_p7_1[] = {
  127773. -1.5, -0.5, 0.5, 1.5,
  127774. };
  127775. static long _vq_quantmap__44cn1_sm_p7_1[] = {
  127776. 3, 1, 0, 2, 4,
  127777. };
  127778. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p7_1 = {
  127779. _vq_quantthresh__44cn1_sm_p7_1,
  127780. _vq_quantmap__44cn1_sm_p7_1,
  127781. 5,
  127782. 5
  127783. };
  127784. static static_codebook _44cn1_sm_p7_1 = {
  127785. 2, 25,
  127786. _vq_lengthlist__44cn1_sm_p7_1,
  127787. 1, -533725184, 1611661312, 3, 0,
  127788. _vq_quantlist__44cn1_sm_p7_1,
  127789. NULL,
  127790. &_vq_auxt__44cn1_sm_p7_1,
  127791. NULL,
  127792. 0
  127793. };
  127794. static long _vq_quantlist__44cn1_sm_p8_0[] = {
  127795. 4,
  127796. 3,
  127797. 5,
  127798. 2,
  127799. 6,
  127800. 1,
  127801. 7,
  127802. 0,
  127803. 8,
  127804. };
  127805. static long _vq_lengthlist__44cn1_sm_p8_0[] = {
  127806. 1, 4, 4,12,11,13,13,14,14, 4, 7, 7,11,13,14,14,
  127807. 14,14, 3, 8, 3,14,14,14,14,14,14,14,10,12,14,14,
  127808. 14,14,14,14,14,14, 5,14, 8,14,14,14,14,14,12,14,
  127809. 13,14,14,14,14,14,14,14,13,14,10,14,14,14,14,14,
  127810. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  127811. 14,
  127812. };
  127813. static float _vq_quantthresh__44cn1_sm_p8_0[] = {
  127814. -773.5, -552.5, -331.5, -110.5, 110.5, 331.5, 552.5, 773.5,
  127815. };
  127816. static long _vq_quantmap__44cn1_sm_p8_0[] = {
  127817. 7, 5, 3, 1, 0, 2, 4, 6,
  127818. 8,
  127819. };
  127820. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_0 = {
  127821. _vq_quantthresh__44cn1_sm_p8_0,
  127822. _vq_quantmap__44cn1_sm_p8_0,
  127823. 9,
  127824. 9
  127825. };
  127826. static static_codebook _44cn1_sm_p8_0 = {
  127827. 2, 81,
  127828. _vq_lengthlist__44cn1_sm_p8_0,
  127829. 1, -516186112, 1627103232, 4, 0,
  127830. _vq_quantlist__44cn1_sm_p8_0,
  127831. NULL,
  127832. &_vq_auxt__44cn1_sm_p8_0,
  127833. NULL,
  127834. 0
  127835. };
  127836. static long _vq_quantlist__44cn1_sm_p8_1[] = {
  127837. 6,
  127838. 5,
  127839. 7,
  127840. 4,
  127841. 8,
  127842. 3,
  127843. 9,
  127844. 2,
  127845. 10,
  127846. 1,
  127847. 11,
  127848. 0,
  127849. 12,
  127850. };
  127851. static long _vq_lengthlist__44cn1_sm_p8_1[] = {
  127852. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,11,11, 6, 5, 5,
  127853. 7, 7, 8, 8,10,10,10,11,11,11, 6, 5, 5, 7, 7, 8,
  127854. 8,10,10,11,12,12,12,14, 7, 7, 7, 8, 9, 9,11,11,
  127855. 11,12,11,12,17, 7, 7, 8, 7, 9, 9,11,11,12,12,12,
  127856. 12,14,11,11, 8, 8,10,10,11,12,12,13,11,12,14,11,
  127857. 11, 8, 8,10,10,11,12,12,13,13,12,14,15,14,10,10,
  127858. 10,10,11,12,12,12,12,11,14,13,16,10,10,10, 9,12,
  127859. 11,12,12,13,14,14,15,14,14,13,10,10,11,11,12,11,
  127860. 13,11,14,12,15,13,14,11,10,12,10,12,12,13,13,13,
  127861. 13,14,15,15,12,12,11,11,12,11,13,12,14,14,14,14,
  127862. 17,12,12,11,10,13,11,13,13,
  127863. };
  127864. static float _vq_quantthresh__44cn1_sm_p8_1[] = {
  127865. -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5, 25.5,
  127866. 42.5, 59.5, 76.5, 93.5,
  127867. };
  127868. static long _vq_quantmap__44cn1_sm_p8_1[] = {
  127869. 11, 9, 7, 5, 3, 1, 0, 2,
  127870. 4, 6, 8, 10, 12,
  127871. };
  127872. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_1 = {
  127873. _vq_quantthresh__44cn1_sm_p8_1,
  127874. _vq_quantmap__44cn1_sm_p8_1,
  127875. 13,
  127876. 13
  127877. };
  127878. static static_codebook _44cn1_sm_p8_1 = {
  127879. 2, 169,
  127880. _vq_lengthlist__44cn1_sm_p8_1,
  127881. 1, -522616832, 1620115456, 4, 0,
  127882. _vq_quantlist__44cn1_sm_p8_1,
  127883. NULL,
  127884. &_vq_auxt__44cn1_sm_p8_1,
  127885. NULL,
  127886. 0
  127887. };
  127888. static long _vq_quantlist__44cn1_sm_p8_2[] = {
  127889. 8,
  127890. 7,
  127891. 9,
  127892. 6,
  127893. 10,
  127894. 5,
  127895. 11,
  127896. 4,
  127897. 12,
  127898. 3,
  127899. 13,
  127900. 2,
  127901. 14,
  127902. 1,
  127903. 15,
  127904. 0,
  127905. 16,
  127906. };
  127907. static long _vq_lengthlist__44cn1_sm_p8_2[] = {
  127908. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  127909. 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9,
  127910. 9, 9,10, 6, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9,
  127911. 9, 9, 9,10, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,
  127912. 9, 9, 9, 9,10,10,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,
  127913. 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9, 9,
  127914. 9, 9, 9, 9, 9, 9,10,10,10, 8, 8, 8, 8, 8, 8, 9,
  127915. 9, 9, 9, 9, 9, 9, 9,11,10,11, 8, 8, 8, 8, 8, 8,
  127916. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,11,11, 8, 8, 8,
  127917. 8, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,11, 9, 9,
  127918. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,10,11,11, 9,
  127919. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,10,11,11,
  127920. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,10,11,11,
  127921. 11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,11,11,
  127922. 11,11,11,11, 9,10,10,10, 9, 9, 9, 9, 9, 9,11,10,
  127923. 11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,11,
  127924. 11,11,11,11,11,11,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  127925. 10,11,11,11,11,11,11,11,11, 9, 9, 9, 9, 9, 9, 9,
  127926. 9,
  127927. };
  127928. static float _vq_quantthresh__44cn1_sm_p8_2[] = {
  127929. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  127930. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  127931. };
  127932. static long _vq_quantmap__44cn1_sm_p8_2[] = {
  127933. 15, 13, 11, 9, 7, 5, 3, 1,
  127934. 0, 2, 4, 6, 8, 10, 12, 14,
  127935. 16,
  127936. };
  127937. static encode_aux_threshmatch _vq_auxt__44cn1_sm_p8_2 = {
  127938. _vq_quantthresh__44cn1_sm_p8_2,
  127939. _vq_quantmap__44cn1_sm_p8_2,
  127940. 17,
  127941. 17
  127942. };
  127943. static static_codebook _44cn1_sm_p8_2 = {
  127944. 2, 289,
  127945. _vq_lengthlist__44cn1_sm_p8_2,
  127946. 1, -529530880, 1611661312, 5, 0,
  127947. _vq_quantlist__44cn1_sm_p8_2,
  127948. NULL,
  127949. &_vq_auxt__44cn1_sm_p8_2,
  127950. NULL,
  127951. 0
  127952. };
  127953. static long _huff_lengthlist__44cn1_sm_short[] = {
  127954. 5, 6,12,14,12,14,16,17,18, 4, 2, 5,11, 7,10,12,
  127955. 14,15, 9, 4, 5,11, 7,10,13,15,18,15, 6, 7, 5, 6,
  127956. 8,11,13,16,11, 5, 6, 5, 5, 6, 9,13,15,12, 5, 7,
  127957. 6, 5, 6, 9,12,14,12, 6, 7, 8, 6, 7, 9,12,13,14,
  127958. 8, 8, 7, 5, 5, 8,10,12,16, 9, 9, 8, 6, 6, 7, 9,
  127959. 9,
  127960. };
  127961. static static_codebook _huff_book__44cn1_sm_short = {
  127962. 2, 81,
  127963. _huff_lengthlist__44cn1_sm_short,
  127964. 0, 0, 0, 0, 0,
  127965. NULL,
  127966. NULL,
  127967. NULL,
  127968. NULL,
  127969. 0
  127970. };
  127971. /*** End of inlined file: res_books_stereo.h ***/
  127972. static vorbis_info_residue0 _residue_44_low={
  127973. 0,-1, -1, 9,-1,
  127974. {0},
  127975. {-1},
  127976. { .5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127977. { .5, .5, .5, 999., 4.5, 8.5, 16.5, 32.5},
  127978. };
  127979. static vorbis_info_residue0 _residue_44_mid={
  127980. 0,-1, -1, 10,-1,
  127981. {0},
  127982. {-1},
  127983. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 8.5, 16.5, 32.5},
  127984. { .5, .5, 999., .5, 999., 4.5, 8.5, 16.5, 32.5},
  127985. };
  127986. static vorbis_info_residue0 _residue_44_high={
  127987. 0,-1, -1, 10,-1,
  127988. {0},
  127989. {-1},
  127990. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  127991. { .5, 1.5, 2.5, 3.5, 4.5, 8.5, 16.5, 71.5,157.5},
  127992. };
  127993. static static_bookblock _resbook_44s_n1={
  127994. {
  127995. {0},{0,0,&_44cn1_s_p1_0},{0,0,&_44cn1_s_p2_0},
  127996. {0,0,&_44cn1_s_p3_0},{0,0,&_44cn1_s_p4_0},{0,0,&_44cn1_s_p5_0},
  127997. {&_44cn1_s_p6_0,&_44cn1_s_p6_1},{&_44cn1_s_p7_0,&_44cn1_s_p7_1},
  127998. {&_44cn1_s_p8_0,&_44cn1_s_p8_1,&_44cn1_s_p8_2}
  127999. }
  128000. };
  128001. static static_bookblock _resbook_44sm_n1={
  128002. {
  128003. {0},{0,0,&_44cn1_sm_p1_0},{0,0,&_44cn1_sm_p2_0},
  128004. {0,0,&_44cn1_sm_p3_0},{0,0,&_44cn1_sm_p4_0},{0,0,&_44cn1_sm_p5_0},
  128005. {&_44cn1_sm_p6_0,&_44cn1_sm_p6_1},{&_44cn1_sm_p7_0,&_44cn1_sm_p7_1},
  128006. {&_44cn1_sm_p8_0,&_44cn1_sm_p8_1,&_44cn1_sm_p8_2}
  128007. }
  128008. };
  128009. static static_bookblock _resbook_44s_0={
  128010. {
  128011. {0},{0,0,&_44c0_s_p1_0},{0,0,&_44c0_s_p2_0},
  128012. {0,0,&_44c0_s_p3_0},{0,0,&_44c0_s_p4_0},{0,0,&_44c0_s_p5_0},
  128013. {&_44c0_s_p6_0,&_44c0_s_p6_1},{&_44c0_s_p7_0,&_44c0_s_p7_1},
  128014. {&_44c0_s_p8_0,&_44c0_s_p8_1,&_44c0_s_p8_2}
  128015. }
  128016. };
  128017. static static_bookblock _resbook_44sm_0={
  128018. {
  128019. {0},{0,0,&_44c0_sm_p1_0},{0,0,&_44c0_sm_p2_0},
  128020. {0,0,&_44c0_sm_p3_0},{0,0,&_44c0_sm_p4_0},{0,0,&_44c0_sm_p5_0},
  128021. {&_44c0_sm_p6_0,&_44c0_sm_p6_1},{&_44c0_sm_p7_0,&_44c0_sm_p7_1},
  128022. {&_44c0_sm_p8_0,&_44c0_sm_p8_1,&_44c0_sm_p8_2}
  128023. }
  128024. };
  128025. static static_bookblock _resbook_44s_1={
  128026. {
  128027. {0},{0,0,&_44c1_s_p1_0},{0,0,&_44c1_s_p2_0},
  128028. {0,0,&_44c1_s_p3_0},{0,0,&_44c1_s_p4_0},{0,0,&_44c1_s_p5_0},
  128029. {&_44c1_s_p6_0,&_44c1_s_p6_1},{&_44c1_s_p7_0,&_44c1_s_p7_1},
  128030. {&_44c1_s_p8_0,&_44c1_s_p8_1,&_44c1_s_p8_2}
  128031. }
  128032. };
  128033. static static_bookblock _resbook_44sm_1={
  128034. {
  128035. {0},{0,0,&_44c1_sm_p1_0},{0,0,&_44c1_sm_p2_0},
  128036. {0,0,&_44c1_sm_p3_0},{0,0,&_44c1_sm_p4_0},{0,0,&_44c1_sm_p5_0},
  128037. {&_44c1_sm_p6_0,&_44c1_sm_p6_1},{&_44c1_sm_p7_0,&_44c1_sm_p7_1},
  128038. {&_44c1_sm_p8_0,&_44c1_sm_p8_1,&_44c1_sm_p8_2}
  128039. }
  128040. };
  128041. static static_bookblock _resbook_44s_2={
  128042. {
  128043. {0},{0,0,&_44c2_s_p1_0},{0,0,&_44c2_s_p2_0},{0,0,&_44c2_s_p3_0},
  128044. {0,0,&_44c2_s_p4_0},{0,0,&_44c2_s_p5_0},{0,0,&_44c2_s_p6_0},
  128045. {&_44c2_s_p7_0,&_44c2_s_p7_1},{&_44c2_s_p8_0,&_44c2_s_p8_1},
  128046. {&_44c2_s_p9_0,&_44c2_s_p9_1,&_44c2_s_p9_2}
  128047. }
  128048. };
  128049. static static_bookblock _resbook_44s_3={
  128050. {
  128051. {0},{0,0,&_44c3_s_p1_0},{0,0,&_44c3_s_p2_0},{0,0,&_44c3_s_p3_0},
  128052. {0,0,&_44c3_s_p4_0},{0,0,&_44c3_s_p5_0},{0,0,&_44c3_s_p6_0},
  128053. {&_44c3_s_p7_0,&_44c3_s_p7_1},{&_44c3_s_p8_0,&_44c3_s_p8_1},
  128054. {&_44c3_s_p9_0,&_44c3_s_p9_1,&_44c3_s_p9_2}
  128055. }
  128056. };
  128057. static static_bookblock _resbook_44s_4={
  128058. {
  128059. {0},{0,0,&_44c4_s_p1_0},{0,0,&_44c4_s_p2_0},{0,0,&_44c4_s_p3_0},
  128060. {0,0,&_44c4_s_p4_0},{0,0,&_44c4_s_p5_0},{0,0,&_44c4_s_p6_0},
  128061. {&_44c4_s_p7_0,&_44c4_s_p7_1},{&_44c4_s_p8_0,&_44c4_s_p8_1},
  128062. {&_44c4_s_p9_0,&_44c4_s_p9_1,&_44c4_s_p9_2}
  128063. }
  128064. };
  128065. static static_bookblock _resbook_44s_5={
  128066. {
  128067. {0},{0,0,&_44c5_s_p1_0},{0,0,&_44c5_s_p2_0},{0,0,&_44c5_s_p3_0},
  128068. {0,0,&_44c5_s_p4_0},{0,0,&_44c5_s_p5_0},{0,0,&_44c5_s_p6_0},
  128069. {&_44c5_s_p7_0,&_44c5_s_p7_1},{&_44c5_s_p8_0,&_44c5_s_p8_1},
  128070. {&_44c5_s_p9_0,&_44c5_s_p9_1,&_44c5_s_p9_2}
  128071. }
  128072. };
  128073. static static_bookblock _resbook_44s_6={
  128074. {
  128075. {0},{0,0,&_44c6_s_p1_0},{0,0,&_44c6_s_p2_0},{0,0,&_44c6_s_p3_0},
  128076. {0,0,&_44c6_s_p4_0},
  128077. {&_44c6_s_p5_0,&_44c6_s_p5_1},
  128078. {&_44c6_s_p6_0,&_44c6_s_p6_1},
  128079. {&_44c6_s_p7_0,&_44c6_s_p7_1},
  128080. {&_44c6_s_p8_0,&_44c6_s_p8_1},
  128081. {&_44c6_s_p9_0,&_44c6_s_p9_1,&_44c6_s_p9_2}
  128082. }
  128083. };
  128084. static static_bookblock _resbook_44s_7={
  128085. {
  128086. {0},{0,0,&_44c7_s_p1_0},{0,0,&_44c7_s_p2_0},{0,0,&_44c7_s_p3_0},
  128087. {0,0,&_44c7_s_p4_0},
  128088. {&_44c7_s_p5_0,&_44c7_s_p5_1},
  128089. {&_44c7_s_p6_0,&_44c7_s_p6_1},
  128090. {&_44c7_s_p7_0,&_44c7_s_p7_1},
  128091. {&_44c7_s_p8_0,&_44c7_s_p8_1},
  128092. {&_44c7_s_p9_0,&_44c7_s_p9_1,&_44c7_s_p9_2}
  128093. }
  128094. };
  128095. static static_bookblock _resbook_44s_8={
  128096. {
  128097. {0},{0,0,&_44c8_s_p1_0},{0,0,&_44c8_s_p2_0},{0,0,&_44c8_s_p3_0},
  128098. {0,0,&_44c8_s_p4_0},
  128099. {&_44c8_s_p5_0,&_44c8_s_p5_1},
  128100. {&_44c8_s_p6_0,&_44c8_s_p6_1},
  128101. {&_44c8_s_p7_0,&_44c8_s_p7_1},
  128102. {&_44c8_s_p8_0,&_44c8_s_p8_1},
  128103. {&_44c8_s_p9_0,&_44c8_s_p9_1,&_44c8_s_p9_2}
  128104. }
  128105. };
  128106. static static_bookblock _resbook_44s_9={
  128107. {
  128108. {0},{0,0,&_44c9_s_p1_0},{0,0,&_44c9_s_p2_0},{0,0,&_44c9_s_p3_0},
  128109. {0,0,&_44c9_s_p4_0},
  128110. {&_44c9_s_p5_0,&_44c9_s_p5_1},
  128111. {&_44c9_s_p6_0,&_44c9_s_p6_1},
  128112. {&_44c9_s_p7_0,&_44c9_s_p7_1},
  128113. {&_44c9_s_p8_0,&_44c9_s_p8_1},
  128114. {&_44c9_s_p9_0,&_44c9_s_p9_1,&_44c9_s_p9_2}
  128115. }
  128116. };
  128117. static vorbis_residue_template _res_44s_n1[]={
  128118. {2,0, &_residue_44_low,
  128119. &_huff_book__44cn1_s_short,&_huff_book__44cn1_sm_short,
  128120. &_resbook_44s_n1,&_resbook_44sm_n1},
  128121. {2,0, &_residue_44_low,
  128122. &_huff_book__44cn1_s_long,&_huff_book__44cn1_sm_long,
  128123. &_resbook_44s_n1,&_resbook_44sm_n1}
  128124. };
  128125. static vorbis_residue_template _res_44s_0[]={
  128126. {2,0, &_residue_44_low,
  128127. &_huff_book__44c0_s_short,&_huff_book__44c0_sm_short,
  128128. &_resbook_44s_0,&_resbook_44sm_0},
  128129. {2,0, &_residue_44_low,
  128130. &_huff_book__44c0_s_long,&_huff_book__44c0_sm_long,
  128131. &_resbook_44s_0,&_resbook_44sm_0}
  128132. };
  128133. static vorbis_residue_template _res_44s_1[]={
  128134. {2,0, &_residue_44_low,
  128135. &_huff_book__44c1_s_short,&_huff_book__44c1_sm_short,
  128136. &_resbook_44s_1,&_resbook_44sm_1},
  128137. {2,0, &_residue_44_low,
  128138. &_huff_book__44c1_s_long,&_huff_book__44c1_sm_long,
  128139. &_resbook_44s_1,&_resbook_44sm_1}
  128140. };
  128141. static vorbis_residue_template _res_44s_2[]={
  128142. {2,0, &_residue_44_mid,
  128143. &_huff_book__44c2_s_short,&_huff_book__44c2_s_short,
  128144. &_resbook_44s_2,&_resbook_44s_2},
  128145. {2,0, &_residue_44_mid,
  128146. &_huff_book__44c2_s_long,&_huff_book__44c2_s_long,
  128147. &_resbook_44s_2,&_resbook_44s_2}
  128148. };
  128149. static vorbis_residue_template _res_44s_3[]={
  128150. {2,0, &_residue_44_mid,
  128151. &_huff_book__44c3_s_short,&_huff_book__44c3_s_short,
  128152. &_resbook_44s_3,&_resbook_44s_3},
  128153. {2,0, &_residue_44_mid,
  128154. &_huff_book__44c3_s_long,&_huff_book__44c3_s_long,
  128155. &_resbook_44s_3,&_resbook_44s_3}
  128156. };
  128157. static vorbis_residue_template _res_44s_4[]={
  128158. {2,0, &_residue_44_mid,
  128159. &_huff_book__44c4_s_short,&_huff_book__44c4_s_short,
  128160. &_resbook_44s_4,&_resbook_44s_4},
  128161. {2,0, &_residue_44_mid,
  128162. &_huff_book__44c4_s_long,&_huff_book__44c4_s_long,
  128163. &_resbook_44s_4,&_resbook_44s_4}
  128164. };
  128165. static vorbis_residue_template _res_44s_5[]={
  128166. {2,0, &_residue_44_mid,
  128167. &_huff_book__44c5_s_short,&_huff_book__44c5_s_short,
  128168. &_resbook_44s_5,&_resbook_44s_5},
  128169. {2,0, &_residue_44_mid,
  128170. &_huff_book__44c5_s_long,&_huff_book__44c5_s_long,
  128171. &_resbook_44s_5,&_resbook_44s_5}
  128172. };
  128173. static vorbis_residue_template _res_44s_6[]={
  128174. {2,0, &_residue_44_high,
  128175. &_huff_book__44c6_s_short,&_huff_book__44c6_s_short,
  128176. &_resbook_44s_6,&_resbook_44s_6},
  128177. {2,0, &_residue_44_high,
  128178. &_huff_book__44c6_s_long,&_huff_book__44c6_s_long,
  128179. &_resbook_44s_6,&_resbook_44s_6}
  128180. };
  128181. static vorbis_residue_template _res_44s_7[]={
  128182. {2,0, &_residue_44_high,
  128183. &_huff_book__44c7_s_short,&_huff_book__44c7_s_short,
  128184. &_resbook_44s_7,&_resbook_44s_7},
  128185. {2,0, &_residue_44_high,
  128186. &_huff_book__44c7_s_long,&_huff_book__44c7_s_long,
  128187. &_resbook_44s_7,&_resbook_44s_7}
  128188. };
  128189. static vorbis_residue_template _res_44s_8[]={
  128190. {2,0, &_residue_44_high,
  128191. &_huff_book__44c8_s_short,&_huff_book__44c8_s_short,
  128192. &_resbook_44s_8,&_resbook_44s_8},
  128193. {2,0, &_residue_44_high,
  128194. &_huff_book__44c8_s_long,&_huff_book__44c8_s_long,
  128195. &_resbook_44s_8,&_resbook_44s_8}
  128196. };
  128197. static vorbis_residue_template _res_44s_9[]={
  128198. {2,0, &_residue_44_high,
  128199. &_huff_book__44c9_s_short,&_huff_book__44c9_s_short,
  128200. &_resbook_44s_9,&_resbook_44s_9},
  128201. {2,0, &_residue_44_high,
  128202. &_huff_book__44c9_s_long,&_huff_book__44c9_s_long,
  128203. &_resbook_44s_9,&_resbook_44s_9}
  128204. };
  128205. static vorbis_mapping_template _mapres_template_44_stereo[]={
  128206. { _map_nominal, _res_44s_n1 }, /* -1 */
  128207. { _map_nominal, _res_44s_0 }, /* 0 */
  128208. { _map_nominal, _res_44s_1 }, /* 1 */
  128209. { _map_nominal, _res_44s_2 }, /* 2 */
  128210. { _map_nominal, _res_44s_3 }, /* 3 */
  128211. { _map_nominal, _res_44s_4 }, /* 4 */
  128212. { _map_nominal, _res_44s_5 }, /* 5 */
  128213. { _map_nominal, _res_44s_6 }, /* 6 */
  128214. { _map_nominal, _res_44s_7 }, /* 7 */
  128215. { _map_nominal, _res_44s_8 }, /* 8 */
  128216. { _map_nominal, _res_44s_9 }, /* 9 */
  128217. };
  128218. /*** End of inlined file: residue_44.h ***/
  128219. /*** Start of inlined file: psych_44.h ***/
  128220. static vorbis_info_psy_global _psy_global_44[5]={
  128221. {8, /* lines per eighth octave */
  128222. {20.f,14.f,12.f,12.f,12.f,12.f,12.f},
  128223. {-60.f,-30.f,-40.f,-40.f,-40.f,-40.f,-40.f}, 2,-75.f,
  128224. -6.f,
  128225. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128226. },
  128227. {8, /* lines per eighth octave */
  128228. {14.f,10.f,10.f,10.f,10.f,10.f,10.f},
  128229. {-40.f,-30.f,-25.f,-25.f,-25.f,-25.f,-25.f}, 2,-80.f,
  128230. -6.f,
  128231. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128232. },
  128233. {8, /* lines per eighth octave */
  128234. {12.f,10.f,10.f,10.f,10.f,10.f,10.f},
  128235. {-20.f,-20.f,-15.f,-15.f,-15.f,-15.f,-15.f}, 0,-80.f,
  128236. -6.f,
  128237. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128238. },
  128239. {8, /* lines per eighth octave */
  128240. {10.f,8.f,8.f,8.f,8.f,8.f,8.f},
  128241. {-20.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-80.f,
  128242. -6.f,
  128243. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128244. },
  128245. {8, /* lines per eighth octave */
  128246. {10.f,6.f,6.f,6.f,6.f,6.f,6.f},
  128247. {-15.f,-15.f,-12.f,-12.f,-12.f,-12.f,-12.f}, 0,-85.f,
  128248. -6.f,
  128249. {99.},{{99.},{99.}},{0},{0},{{0.},{0.}}
  128250. },
  128251. };
  128252. static compandblock _psy_compand_44[6]={
  128253. {{
  128254. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128255. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128256. 16,17,18,19,20,21,22, 23, /* 23dB */
  128257. 24,25,26,27,28,29,30, 31, /* 31dB */
  128258. 32,33,34,35,36,37,38, 39, /* 39dB */
  128259. }},
  128260. {{
  128261. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  128262. 7, 7, 7, 7, 6, 6, 6, 7, /* 15dB */
  128263. 7, 8, 9,10,11,12,13, 14, /* 23dB */
  128264. 15,16,17,17,17,18,18, 19, /* 31dB */
  128265. 19,19,20,21,22,23,24, 25, /* 39dB */
  128266. }},
  128267. {{
  128268. 0, 1, 2, 3, 4, 5, 5, 5, /* 7dB */
  128269. 6, 6, 6, 5, 4, 4, 4, 4, /* 15dB */
  128270. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128271. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128272. 11,12,13,14,15,16,17, 18, /* 39dB */
  128273. }},
  128274. {{
  128275. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128276. 8, 9,10,11,12,13,14, 15, /* 15dB */
  128277. 16,17,18,19,20,21,22, 23, /* 23dB */
  128278. 24,25,26,27,28,29,30, 31, /* 31dB */
  128279. 32,33,34,35,36,37,38, 39, /* 39dB */
  128280. }},
  128281. {{
  128282. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128283. 8, 9,10,11,12,12,13, 13, /* 15dB */
  128284. 13,14,14,14,15,15,15, 15, /* 23dB */
  128285. 16,16,17,17,17,18,18, 19, /* 31dB */
  128286. 19,19,20,21,22,23,24, 25, /* 39dB */
  128287. }},
  128288. {{
  128289. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  128290. 8, 8, 7, 6, 5, 4, 4, 4, /* 15dB */
  128291. 4, 4, 5, 5, 5, 6, 6, 6, /* 23dB */
  128292. 7, 7, 7, 8, 8, 8, 9, 10, /* 31dB */
  128293. 11,12,13,14,15,16,17, 18, /* 39dB */
  128294. }}
  128295. };
  128296. static vp_adjblock _vp_tonemask_adj_longblock[12]={
  128297. {{ -3, -8,-13,-15,-10,-10,-10,-10,-10,-10,-10, 0, 0, 0, 0, 0, 0}}, /* -1 */
  128298. {{ -4,-10,-14,-16,-15,-14,-13,-12,-12,-12,-11, -1, -1, -1, -1, -1, 0}}, /* 0 */
  128299. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, -1, -1, 0}}, /* 1 */
  128300. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -6, -3, -1, -1, -1, 0}}, /* 2 */
  128301. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, -1, -1, 0}}, /* 3 */
  128302. /* 4 */
  128303. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128304. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128305. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128306. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128307. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128308. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128309. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128310. };
  128311. static vp_adjblock _vp_tonemask_adj_otherblock[12]={
  128312. {{ -3, -8,-13,-15,-10,-10, -9, -9, -9, -9, -9, 1, 1, 1, 1, 1, 1}}, /* -1 */
  128313. {{ -4,-10,-14,-16,-14,-13,-12,-12,-11,-11,-10, 0, 0, 0, 0, 0, 0}}, /* 0 */
  128314. {{ -6,-12,-14,-16,-15,-15,-14,-13,-13,-12,-12, -2, -2, -1, 0, 0, 0}}, /* 1 */
  128315. {{-12,-13,-14,-16,-16,-16,-15,-14,-13,-12,-12, -5, -2, -1, 0, 0, 0}}, /* 2 */
  128316. {{-15,-15,-15,-16,-16,-16,-16,-14,-13,-13,-13,-10, -4, -2, 0, 0, 0}}, /* 3 */
  128317. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 4 */
  128318. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-13,-11, -7 -3, -1, -1 , 0}}, /* 5 */
  128319. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -8, -4, -2, -2, 0}}, /* 6 */
  128320. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 7 */
  128321. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 8 */
  128322. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 9 */
  128323. {{-16,-16,-16,-16,-16,-16,-16,-15,-14,-14,-14,-12, -9, -4, -2, -2, 0}}, /* 10 */
  128324. };
  128325. static noise3 _psy_noisebias_trans[12]={
  128326. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128327. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128328. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128329. {{{-15,-15,-15,-15,-15,-12, -6, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128330. {-30,-30,-30,-30,-26,-22,-20,-14, -8, -4, 0, 0, 0, 0, 2, 3, 6},
  128331. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128332. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128333. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128334. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128335. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128336. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128337. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -7, -4}}},
  128338. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128339. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128340. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128341. {{{-20,-20,-20,-20,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128342. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128343. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128344. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128345. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128346. {-34,-34,-34,-34,-30,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -5}}},
  128347. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128348. {-32,-32,-32,-32,-28,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128349. {-34,-34,-34,-34,-30,-26,-26,-24,-22,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128350. {{{-24,-24,-24,-24,-20,-18,-14, -8, -1, 1, 1, 1, 2, 3, 3, 4, 7},
  128351. {-32,-32,-32,-32,-28,-24,-24,-24,-18,-14,-12,-10,-10,-10, -8, -6, -2},
  128352. {-34,-34,-34,-34,-30,-26,-26,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128353. {{{-24,-24,-24,-24,-22,-20,-15,-10, -8, -2, 0, 0, 0, 1, 2, 3, 7},
  128354. {-36,-36,-36,-36,-30,-30,-30,-24,-20,-16,-16,-16,-16,-14,-12,-10, -7},
  128355. {-36,-36,-36,-36,-34,-30,-28,-26,-24,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128356. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128357. {-38,-38,-38,-38,-36,-34,-34,-30,-24,-20,-20,-20,-20,-18,-16,-12,-10},
  128358. {-40,-40,-40,-40,-40,-40,-40,-38,-35,-35,-35,-35,-35,-35,-35,-35,-30}}},
  128359. {{{-30,-30,-30,-30,-30,-30,-30,-28,-20,-14,-14,-14,-14,-14,-14,-12,-10},
  128360. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-20},
  128361. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128362. };
  128363. static noise3 _psy_noisebias_long[12]={
  128364. {{{-10,-10,-10,-10,-10, -4, 0, 0, 0, 6, 6, 6, 6, 10, 10, 12, 20},
  128365. {-20,-20,-20,-20,-20,-20,-10, -2, 0, 0, 0, 0, 0, 2, 4, 6, 15},
  128366. {-20,-20,-20,-20,-20,-20,-20,-10, -6, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128367. {{{-10,-10,-10,-10,-10,-10, -8, 2, 2, 2, 4, 4, 5, 5, 5, 8, 10},
  128368. {-20,-20,-20,-20,-20,-20,-20,-14, -6, 0, 0, 0, 0, 0, 2, 3, 6},
  128369. {-20,-20,-20,-20,-20,-20,-20,-14, -8, -6, -6, -6, -6, -4, -4, -4, -2}}},
  128370. {{{-10,-10,-10,-10,-10,-10, -8, -4, 0, 2, 4, 4, 5, 5, 5, 8, 10},
  128371. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -2, -2, -2, -2, 0, 1, 4},
  128372. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -8, -8, -8, -8, -6, -6, -6, -4}}},
  128373. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 5, 6, 10},
  128374. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -2, -1, 0, 3},
  128375. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -4}}},
  128376. {{{-10,-10,-10,-10,-10,-10,-10, -8, 0, 2, 2, 2, 4, 4, 4, 5, 8},
  128377. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, 0, 2},
  128378. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -5}}},
  128379. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128380. {-20,-20,-20,-20,-20,-20,-20,-14,-10, -4, -3, -3, -3, -3, -2, -1, 1},
  128381. {-20,-20,-20,-20,-20,-20,-20,-14,-10,-10,-10,-10,-10, -8, -8, -8, -7}}},
  128382. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128383. {-22,-22,-22,-22,-22,-22,-22,-16,-12, -6, -4, -4, -4, -4, -3, -1, 0},
  128384. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-12,-12,-12,-12,-10,-10, -9, -8}}},
  128385. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128386. {-24,-24,-24,-24,-24,-24,-24,-18,-14, -8, -6, -6, -6, -6, -5, -2, 0},
  128387. {-26,-26,-26,-26,-26,-26,-26,-18,-16,-15,-15,-15,-15,-13,-13,-12,-10}}},
  128388. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 1, 1, 1, 2, 3, 3, 4, 7},
  128389. {-24,-24,-24,-24,-24,-24,-24,-18,-14,-10, -8, -8, -8, -8, -6, -4, 0},
  128390. {-26,-26,-26,-26,-26,-26,-26,-22,-20,-19,-19,-19,-19,-18,-17,-16,-12}}},
  128391. {{{-15,-15,-15,-15,-15,-15,-15,-10, -4, 0, 0, 0, 0, 1, 2, 3, 7},
  128392. {-26,-26,-26,-26,-26,-26,-26,-20,-16,-12,-10,-10,-10,-10, -8, -6, -2},
  128393. {-28,-28,-28,-28,-28,-28,-28,-26,-24,-24,-24,-24,-24,-24,-24,-20,-16}}},
  128394. {{{-22,-22,-22,-22,-22,-22,-22,-18,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128395. {-26,-26,-26,-26,-26,-26,-26,-22,-18,-16,-16,-16,-16,-14,-12,-10, -7},
  128396. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128397. {{{-24,-24,-24,-24,-24,-24,-24,-24,-24,-18,-14,-14,-14,-14,-14,-12,-10},
  128398. {-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-30,-20},
  128399. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128400. };
  128401. static noise3 _psy_noisebias_impulse[12]={
  128402. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128403. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128404. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128405. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 4, 8, 8, 8, 10, 12, 14, 20},
  128406. {-30,-30,-30,-30,-26,-22,-20,-14, -6, -2, 0, 0, 0, 0, 2, 3, 6},
  128407. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128408. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128409. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -4, -4, -2, -2, -2, -2, 2},
  128410. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8,-10,-10, -8, -8, -8, -6, -4}}},
  128411. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128412. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128413. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128414. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128415. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128416. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128417. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128418. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -4, -4, -4, -2, 0},
  128419. {-30,-30,-30,-30,-26,-22,-20,-14,-10,-10,-10,-10,-10,-10,-10, -8, -4}}},
  128420. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128421. {-32,-32,-32,-32,-28,-24,-22,-16,-10, -6, -8, -8, -6, -6, -6, -4, -2},
  128422. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-12,-12,-12,-12,-12,-10, -9, -5}}},
  128423. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 4, 6, 11},
  128424. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-16,-16,-16,-16,-16,-14,-14,-12},
  128425. {-36,-36,-36,-36,-36,-34,-28,-24,-20,-20,-20,-20,-20,-20,-20,-18,-16}}},
  128426. {{{-22,-22,-22,-22,-22,-20,-14,-10, -6, 0, 0, 0, 0, 4, 4, 6, 11},
  128427. {-34,-34,-34,-34,-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-24,-22},
  128428. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128429. {{{-24,-24,-24,-24,-24,-22,-14,-10, -6, -1, -1, -1, -1, 3, 3, 5, 10},
  128430. {-34,-34,-34,-34,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-24},
  128431. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-30,-24}}},
  128432. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -4, -4, -4, -4, -4, -2, 2},
  128433. {-36,-36,-36,-36,-34,-32,-32,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26},
  128434. {-40,-40,-40,-40,-40,-40,-40,-32,-30,-30,-30,-30,-30,-30,-30,-24,-20}}},
  128435. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-16,-16,-16,-16,-16,-14,-12},
  128436. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-30,-30,-30,-30,-30,-30,-26},
  128437. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128438. };
  128439. static noise3 _psy_noisebias_padding[12]={
  128440. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128441. {-30,-30,-30,-30,-26,-20,-16, -8, -6, -6, -2, 2, 2, 3, 6, 6, 15},
  128442. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -4, -2}}},
  128443. {{{-10,-10,-10,-10,-10, -4, 0, 0, 4, 8, 8, 8, 8, 10, 12, 14, 20},
  128444. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -2, 2, 3, 6, 6, 8, 10},
  128445. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, -4, -4, -4, -4, -2, 0, 2}}},
  128446. {{{-12,-12,-12,-12,-12, -8, -6, -4, 0, 4, 4, 4, 4, 10, 12, 14, 20},
  128447. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -4, 0, 0, 0, 2, 2, 4, 8},
  128448. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -6, -6, -6, -6, -4, -2, 0}}},
  128449. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 8, 10, 10, 16},
  128450. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128451. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128452. {{{-14,-14,-14,-14,-14,-10, -8, -6, -2, 2, 2, 2, 2, 6, 8, 8, 14},
  128453. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, 0, 0, 2, 6},
  128454. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128455. {{{-16,-16,-16,-16,-16,-12,-10, -6, -2, 0, 0, 0, 0, 4, 6, 6, 12},
  128456. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -6, -1, -1, -1, -1, 0, 2, 6},
  128457. {-30,-30,-30,-30,-26,-22,-20,-14,-10, -8, -8, -8, -8, -8, -6, -4, -2}}},
  128458. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128459. {-32,-32,-32,-32,-28,-24,-22,-16,-12, -6, -3, -3, -3, -3, -2, 0, 4},
  128460. {-34,-34,-34,-34,-30,-26,-24,-18,-14,-10,-10,-10,-10,-10, -8, -5, -3}}},
  128461. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128462. {-34,-34,-34,-34,-30,-30,-24,-20,-14, -8, -4, -4, -4, -4, -3, -1, 4},
  128463. {-34,-34,-34,-34,-34,-30,-26,-20,-16,-13,-13,-13,-13,-13,-11, -8, -6}}},
  128464. {{{-20,-20,-20,-20,-20,-18,-14,-10, -4, 0, 0, 0, 0, 4, 6, 6, 12},
  128465. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-10, -8, -6, -6, -6, -5, -3, 1},
  128466. {-34,-34,-34,-34,-32,-32,-28,-22,-18,-16,-16,-16,-16,-16,-14,-12,-10}}},
  128467. {{{-22,-22,-22,-22,-22,-20,-14,-10, -4, 0, 0, 0, 0, 3, 5, 5, 11},
  128468. {-34,-34,-34,-34,-30,-30,-30,-24,-16,-12,-10, -8, -8, -8, -7, -5, -2},
  128469. {-36,-36,-36,-36,-36,-34,-28,-22,-20,-20,-20,-20,-20,-20,-20,-16,-14}}},
  128470. {{{-28,-28,-28,-28,-28,-28,-28,-20,-14, -8, -2, -2, -2, -2, 0, 2, 6},
  128471. {-36,-36,-36,-36,-34,-32,-32,-24,-16,-12,-12,-12,-12,-12,-10, -8, -5},
  128472. {-40,-40,-40,-40,-40,-40,-40,-32,-26,-24,-24,-24,-24,-24,-24,-20,-18}}},
  128473. {{{-30,-30,-30,-30,-30,-26,-24,-24,-24,-20,-12,-12,-12,-12,-12,-10, -8},
  128474. {-40,-40,-40,-40,-40,-40,-40,-40,-35,-30,-25,-25,-25,-25,-25,-25,-15},
  128475. {-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40,-40}}},
  128476. };
  128477. static noiseguard _psy_noiseguards_44[4]={
  128478. {3,3,15},
  128479. {3,3,15},
  128480. {10,10,100},
  128481. {10,10,100},
  128482. };
  128483. static int _psy_tone_suppress[12]={
  128484. -20,-20,-20,-20,-20,-24,-30,-40,-40,-45,-45,-45,
  128485. };
  128486. static int _psy_tone_0dB[12]={
  128487. 90,90,95,95,95,95,105,105,105,105,105,105,
  128488. };
  128489. static int _psy_noise_suppress[12]={
  128490. -20,-20,-24,-24,-24,-24,-30,-40,-40,-45,-45,-45,
  128491. };
  128492. static vorbis_info_psy _psy_info_template={
  128493. -1,
  128494. -140.,-140.,
  128495. {0.f,0.f,0.f}, 0.,0., -40.f, {0.},
  128496. 1, -0.f, .5f, .5f, 0,0,0,
  128497. {{-1},{-1},{-1}},{-1},105.f,
  128498. 0,0,-1,-1,0.,
  128499. };
  128500. static int _psy_ath_floater[12]={
  128501. -100,-100,-100,-100,-100,-100,-105,-105,-105,-105,-110,-120,
  128502. };
  128503. static int _psy_ath_abs[12]={
  128504. -130,-130,-130,-130,-140,-140,-140,-140,-140,-140,-140,-150,
  128505. };
  128506. static adj_stereo _psy_stereo_modes_44[12]={
  128507. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 2, 1, 0, 0, 0, 0},
  128508. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 5, 4, 3},
  128509. { 1, 2, 3, 4, 4, 4, 4, 4, 4, 5, 6, 7, 8, 8, 8},
  128510. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128511. {{ 4, 4, 4, 4, 4, 4, 4, 3, 2, 1, 0, 0, 0, 0, 0},
  128512. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128513. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128514. { 12,12.5, 13,13.5, 14,14.5, 15, 99, 99, 99, 99, 99, 99, 99, 99}},
  128515. {{ 3, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, 0, 0, 0, 0},
  128516. { 8, 8, 8, 8, 6, 6, 5, 5, 5, 5, 5, 5, 5, 4, 3},
  128517. { 1, 2, 3, 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128518. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128519. {{ 3, 3, 3, 3, 3, 3, 3, 2, 1, 1, 0, 0, 0, 0, 0},
  128520. { 8, 8, 6, 6, 5, 5, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128521. { 3, 4, 4, 5, 5, 6, 6, 6, 6, 6, 6, 8, 8, 8, 8},
  128522. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128523. {{ 2, 2, 2, 2, 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0},
  128524. { 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 2, 1},
  128525. { 4, 4, 5, 6, 6, 6, 6, 6, 8, 8, 10, 10, 10, 10, 10},
  128526. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128527. {{ 2, 2, 2, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128528. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 3, 3, 2, 1, 0},
  128529. { 6, 6, 6, 8, 8, 8, 8, 8, 8, 8, 10, 10, 10, 10, 10},
  128530. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128531. {{ 2, 2, 2, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128532. { 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 0, 0, 0, 0},
  128533. { 6, 7, 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12},
  128534. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128535. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128536. { 3, 3, 3, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128537. { 8, 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128538. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128539. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128540. { 3, 3, 3, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128541. { 8, 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128542. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128543. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128544. { 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128545. { 8, 10, 10, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12},
  128546. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128547. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128548. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128549. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128550. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128551. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128552. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  128553. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  128554. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  128555. };
  128556. static att3 _psy_tone_masteratt_44[12]={
  128557. {{ 35, 21, 9}, 0, 0}, /* -1 */
  128558. {{ 30, 20, 8}, -2, 1.25}, /* 0 */
  128559. /* 1 */
  128560. {{ 25, 12, 2}, 0, 0}, /* 1 */
  128561. /* 2 */
  128562. {{ 20, 9, -3}, 0, 0}, /* 2 */
  128563. {{ 20, 9, -4}, 0, 0}, /* 3 */
  128564. {{ 20, 9, -4}, 0, 0}, /* 4 */
  128565. {{ 20, 6, -6}, 0, 0}, /* 5 */
  128566. {{ 20, 3, -10}, 0, 0}, /* 6 */
  128567. {{ 18, 1, -14}, 0, 0}, /* 7 */
  128568. {{ 18, 0, -16}, 0, 0}, /* 8 */
  128569. {{ 18, -2, -16}, 0, 0}, /* 9 */
  128570. {{ 12, -2, -20}, 0, 0}, /* 10 */
  128571. };
  128572. static double _psy_lowpass_44[12]={
  128573. 13.9,15.1,15.8,16.5,17.2,18.9,20.1,48.,999.,999.,999.,999.
  128574. };
  128575. static int _noise_start_short_44[11]={
  128576. 32,16,16,16,32,9999,9999,9999,9999,9999,9999
  128577. };
  128578. static int _noise_start_long_44[11]={
  128579. 256,128,128,256,512,9999,9999,9999,9999,9999,9999
  128580. };
  128581. static int _noise_part_short_44[11]={
  128582. 8,8,8,8,8,8,8,8,8,8,8
  128583. };
  128584. static int _noise_part_long_44[11]={
  128585. 32,32,32,32,32,32,32,32,32,32,32
  128586. };
  128587. static double _noise_thresh_44[11]={
  128588. .2,.2,.2,.4,.6,9999.,9999.,9999.,9999.,9999.,9999.,
  128589. };
  128590. static double _noise_thresh_5only[2]={
  128591. .5,.5,
  128592. };
  128593. /*** End of inlined file: psych_44.h ***/
  128594. static double rate_mapping_44_stereo[12]={
  128595. 22500.,32000.,40000.,48000.,56000.,64000.,
  128596. 80000.,96000.,112000.,128000.,160000.,250001.
  128597. };
  128598. static double quality_mapping_44[12]={
  128599. -.1,.0,.1,.2,.3,.4,.5,.6,.7,.8,.9,1.0
  128600. };
  128601. static int blocksize_short_44[11]={
  128602. 512,256,256,256,256,256,256,256,256,256,256
  128603. };
  128604. static int blocksize_long_44[11]={
  128605. 4096,2048,2048,2048,2048,2048,2048,2048,2048,2048,2048
  128606. };
  128607. static double _psy_compand_short_mapping[12]={
  128608. 0.5, 1., 1., 1.3, 1.6, 2., 2., 2., 2., 2., 2., 2.
  128609. };
  128610. static double _psy_compand_long_mapping[12]={
  128611. 3.5, 4., 4., 4.3, 4.6, 5., 5., 5., 5., 5., 5., 5.
  128612. };
  128613. static double _global_mapping_44[12]={
  128614. 0., 1., 1., 1.5, 2., 2., 2.5, 2.7, 3.0, 3.7, 4., 4.
  128615. };
  128616. static int _floor_short_mapping_44[11]={
  128617. 1,0,0,2,2,4,5,5,5,5,5
  128618. };
  128619. static int _floor_long_mapping_44[11]={
  128620. 8,7,7,7,7,7,7,7,7,7,7
  128621. };
  128622. ve_setup_data_template ve_setup_44_stereo={
  128623. 11,
  128624. rate_mapping_44_stereo,
  128625. quality_mapping_44,
  128626. 2,
  128627. 40000,
  128628. 50000,
  128629. blocksize_short_44,
  128630. blocksize_long_44,
  128631. _psy_tone_masteratt_44,
  128632. _psy_tone_0dB,
  128633. _psy_tone_suppress,
  128634. _vp_tonemask_adj_otherblock,
  128635. _vp_tonemask_adj_longblock,
  128636. _vp_tonemask_adj_otherblock,
  128637. _psy_noiseguards_44,
  128638. _psy_noisebias_impulse,
  128639. _psy_noisebias_padding,
  128640. _psy_noisebias_trans,
  128641. _psy_noisebias_long,
  128642. _psy_noise_suppress,
  128643. _psy_compand_44,
  128644. _psy_compand_short_mapping,
  128645. _psy_compand_long_mapping,
  128646. {_noise_start_short_44,_noise_start_long_44},
  128647. {_noise_part_short_44,_noise_part_long_44},
  128648. _noise_thresh_44,
  128649. _psy_ath_floater,
  128650. _psy_ath_abs,
  128651. _psy_lowpass_44,
  128652. _psy_global_44,
  128653. _global_mapping_44,
  128654. _psy_stereo_modes_44,
  128655. _floor_books,
  128656. _floor,
  128657. _floor_short_mapping_44,
  128658. _floor_long_mapping_44,
  128659. _mapres_template_44_stereo
  128660. };
  128661. /*** End of inlined file: setup_44.h ***/
  128662. /*** Start of inlined file: setup_44u.h ***/
  128663. /*** Start of inlined file: residue_44u.h ***/
  128664. /*** Start of inlined file: res_books_uncoupled.h ***/
  128665. static long _vq_quantlist__16u0__p1_0[] = {
  128666. 1,
  128667. 0,
  128668. 2,
  128669. };
  128670. static long _vq_lengthlist__16u0__p1_0[] = {
  128671. 1, 4, 4, 5, 7, 7, 5, 7, 8, 5, 8, 8, 8,10,10, 8,
  128672. 10,11, 5, 8, 8, 8,10,10, 8,10,10, 4, 9, 9, 9,12,
  128673. 11, 8,11,11, 8,12,11,10,12,14,10,13,13, 7,11,11,
  128674. 10,14,12,11,14,14, 4, 9, 9, 8,11,11, 9,11,12, 7,
  128675. 11,11,10,13,14,10,12,14, 8,11,12,10,14,14,10,13,
  128676. 12,
  128677. };
  128678. static float _vq_quantthresh__16u0__p1_0[] = {
  128679. -0.5, 0.5,
  128680. };
  128681. static long _vq_quantmap__16u0__p1_0[] = {
  128682. 1, 0, 2,
  128683. };
  128684. static encode_aux_threshmatch _vq_auxt__16u0__p1_0 = {
  128685. _vq_quantthresh__16u0__p1_0,
  128686. _vq_quantmap__16u0__p1_0,
  128687. 3,
  128688. 3
  128689. };
  128690. static static_codebook _16u0__p1_0 = {
  128691. 4, 81,
  128692. _vq_lengthlist__16u0__p1_0,
  128693. 1, -535822336, 1611661312, 2, 0,
  128694. _vq_quantlist__16u0__p1_0,
  128695. NULL,
  128696. &_vq_auxt__16u0__p1_0,
  128697. NULL,
  128698. 0
  128699. };
  128700. static long _vq_quantlist__16u0__p2_0[] = {
  128701. 1,
  128702. 0,
  128703. 2,
  128704. };
  128705. static long _vq_lengthlist__16u0__p2_0[] = {
  128706. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 9, 7,
  128707. 8, 9, 5, 7, 7, 7, 9, 8, 7, 9, 7, 4, 7, 7, 7, 9,
  128708. 9, 7, 8, 8, 6, 9, 8, 7, 8,11, 9,11,10, 6, 8, 9,
  128709. 8,11, 8, 9,10,11, 4, 7, 7, 7, 8, 8, 7, 9, 9, 6,
  128710. 9, 8, 9,11,10, 8, 8,11, 6, 8, 9, 9,10,11, 8,11,
  128711. 8,
  128712. };
  128713. static float _vq_quantthresh__16u0__p2_0[] = {
  128714. -0.5, 0.5,
  128715. };
  128716. static long _vq_quantmap__16u0__p2_0[] = {
  128717. 1, 0, 2,
  128718. };
  128719. static encode_aux_threshmatch _vq_auxt__16u0__p2_0 = {
  128720. _vq_quantthresh__16u0__p2_0,
  128721. _vq_quantmap__16u0__p2_0,
  128722. 3,
  128723. 3
  128724. };
  128725. static static_codebook _16u0__p2_0 = {
  128726. 4, 81,
  128727. _vq_lengthlist__16u0__p2_0,
  128728. 1, -535822336, 1611661312, 2, 0,
  128729. _vq_quantlist__16u0__p2_0,
  128730. NULL,
  128731. &_vq_auxt__16u0__p2_0,
  128732. NULL,
  128733. 0
  128734. };
  128735. static long _vq_quantlist__16u0__p3_0[] = {
  128736. 2,
  128737. 1,
  128738. 3,
  128739. 0,
  128740. 4,
  128741. };
  128742. static long _vq_lengthlist__16u0__p3_0[] = {
  128743. 1, 5, 5, 7, 7, 6, 7, 7, 8, 8, 6, 7, 8, 8, 8, 8,
  128744. 9, 9,11,11, 8, 9, 9,11,11, 6, 9, 8,10,10, 8,10,
  128745. 10,11,11, 8,10,10,11,11,10,11,10,13,12, 9,11,10,
  128746. 13,13, 6, 8, 9,10,10, 8,10,10,11,11, 8,10,10,11,
  128747. 11, 9,10,11,13,12,10,10,11,12,12, 8,11,11,14,13,
  128748. 10,12,11,15,13, 9,12,11,15,14,12,14,13,16,14,12,
  128749. 13,13,17,14, 8,11,11,13,14, 9,11,12,14,15,10,11,
  128750. 12,13,15,11,13,13,14,16,12,13,14,14,16, 5, 9, 9,
  128751. 11,11, 9,11,11,12,12, 8,11,11,12,12,11,12,12,15,
  128752. 14,10,12,12,15,15, 8,11,11,13,12,10,12,12,13,13,
  128753. 10,12,12,14,13,12,12,13,14,15,11,13,13,17,16, 7,
  128754. 11,11,13,13,10,12,12,14,13,10,12,12,13,14,12,13,
  128755. 12,15,14,11,13,13,15,14, 9,12,12,16,15,11,13,13,
  128756. 17,16,10,13,13,16,16,13,14,15,15,16,13,15,14,19,
  128757. 17, 9,12,12,14,16,11,13,13,15,16,10,13,13,17,16,
  128758. 13,14,13,17,15,12,15,15,16,17, 5, 9, 9,11,11, 8,
  128759. 11,11,13,12, 9,11,11,12,12,10,12,12,14,15,11,12,
  128760. 12,14,14, 7,11,10,13,12,10,12,12,14,13,10,11,12,
  128761. 13,13,11,13,13,15,16,12,12,13,15,15, 7,11,11,13,
  128762. 13,10,13,13,14,14,10,12,12,13,13,11,13,13,16,15,
  128763. 12,13,13,15,14, 9,12,12,15,15,10,13,13,17,16,11,
  128764. 12,13,15,15,12,15,14,18,18,13,14,14,16,17, 9,12,
  128765. 12,15,16,10,13,13,15,16,11,13,13,15,16,13,15,15,
  128766. 17,17,13,15,14,16,15, 7,11,11,15,16,10,13,12,16,
  128767. 17,10,12,13,15,17,15,16,16,18,17,13,15,15,17,18,
  128768. 8,12,12,16,16,11,13,14,17,18,11,13,13,18,16,15,
  128769. 17,16,17,19,14,15,15,17,16, 8,12,12,16,15,11,14,
  128770. 13,18,17,11,13,14,18,17,15,16,16,18,17,13,16,16,
  128771. 18,18,11,15,14,18,17,13,14,15,18, 0,12,15,15, 0,
  128772. 17,17,16,17,17,18,14,16,18,18, 0,11,14,14,17, 0,
  128773. 12,15,14,17,19,12,15,14,18, 0,15,18,16, 0,17,14,
  128774. 18,16,18, 0, 7,11,11,16,15,10,12,12,18,16,10,13,
  128775. 13,16,15,13,15,14,17,17,14,16,16,19,18, 8,12,12,
  128776. 16,16,11,13,13,18,16,11,13,14,17,16,14,15,15,19,
  128777. 18,15,16,16, 0,19, 8,12,12,16,17,11,13,13,17,17,
  128778. 11,14,13,17,17,13,15,15,17,19,15,17,17,19, 0,11,
  128779. 14,15,19,17,12,15,16,18,18,12,14,15,19,17,14,16,
  128780. 17, 0,18,16,16,19,17, 0,11,14,14,18,19,12,15,14,
  128781. 17,17,13,16,14,17,16,14,17,16,18,18,15,18,15, 0,
  128782. 18,
  128783. };
  128784. static float _vq_quantthresh__16u0__p3_0[] = {
  128785. -1.5, -0.5, 0.5, 1.5,
  128786. };
  128787. static long _vq_quantmap__16u0__p3_0[] = {
  128788. 3, 1, 0, 2, 4,
  128789. };
  128790. static encode_aux_threshmatch _vq_auxt__16u0__p3_0 = {
  128791. _vq_quantthresh__16u0__p3_0,
  128792. _vq_quantmap__16u0__p3_0,
  128793. 5,
  128794. 5
  128795. };
  128796. static static_codebook _16u0__p3_0 = {
  128797. 4, 625,
  128798. _vq_lengthlist__16u0__p3_0,
  128799. 1, -533725184, 1611661312, 3, 0,
  128800. _vq_quantlist__16u0__p3_0,
  128801. NULL,
  128802. &_vq_auxt__16u0__p3_0,
  128803. NULL,
  128804. 0
  128805. };
  128806. static long _vq_quantlist__16u0__p4_0[] = {
  128807. 2,
  128808. 1,
  128809. 3,
  128810. 0,
  128811. 4,
  128812. };
  128813. static long _vq_lengthlist__16u0__p4_0[] = {
  128814. 3, 5, 5, 8, 8, 6, 6, 6, 9, 9, 6, 6, 6, 9, 9, 9,
  128815. 10, 9,11,11, 9, 9, 9,11,11, 6, 7, 7,10,10, 7, 7,
  128816. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  128817. 11,12, 6, 7, 7,10,10, 7, 8, 7,10,10, 7, 8, 7,10,
  128818. 10,10,11,10,12,11,10,10,10,13,10, 9,10,10,12,12,
  128819. 10,11,10,14,12, 9,11,11,13,13,11,12,13,13,13,11,
  128820. 12,12,15,13, 9,10,10,12,13, 9,11,10,12,13,10,10,
  128821. 11,12,13,11,12,12,12,13,11,12,12,13,13, 5, 7, 7,
  128822. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  128823. 13,10,10,11,12,12, 6, 8, 8,11,10, 7, 8, 9,10,12,
  128824. 8, 9, 9,11,11,11,10,11,11,12,10,11,11,13,12, 7,
  128825. 8, 8,10,11, 8, 9, 8,11,10, 8, 9, 9,11,11,10,12,
  128826. 10,13,11,10,11,11,13,13,10,11,10,14,13,10,10,11,
  128827. 13,13,10,12,11,14,13,12,11,13,12,13,13,12,13,14,
  128828. 14,10,11,11,13,13,10,11,10,12,13,10,12,12,12,14,
  128829. 12,12,12,14,12,12,13,12,17,15, 5, 7, 7,10,10, 7,
  128830. 8, 8,10,10, 7, 8, 8,11,10,10,10,11,12,12,10,11,
  128831. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  128832. 10,11,11,11,11,12,12,10,10,11,12,13, 6, 8, 8,10,
  128833. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,12,12,13,13,
  128834. 11,11,10,13,11, 9,11,10,14,13,11,11,11,15,13,10,
  128835. 10,11,13,13,12,13,13,14,14,12,11,12,12,13,10,11,
  128836. 11,12,13,10,11,12,13,13,10,11,10,13,12,12,12,13,
  128837. 14, 0,12,13,11,13,11, 8,10,10,13,13,10,11,11,14,
  128838. 13,10,11,11,13,12,13,14,14,14,15,12,12,12,15,14,
  128839. 9,11,10,13,12,10,10,11,13,14,11,11,11,15,12,13,
  128840. 12,14,15,16,13,13,13,14,13, 9,11,11,12,12,10,12,
  128841. 11,13,13,10,11,11,13,14,13,13,13,15,15,13,13,14,
  128842. 17,15,11,12,12,14,14,10,11,12,13,15,12,13,13, 0,
  128843. 15,13,11,14,12,16,14,16,14, 0,15,11,12,12,14,16,
  128844. 11,13,12,16,15,12,13,13,14,15,12,14,12,15,13,15,
  128845. 14,14,16,16, 8,10,10,13,13,10,11,10,13,14,10,11,
  128846. 11,13,13,13,13,12,14,14,14,13,13,16,17, 9,10,10,
  128847. 12,14,10,12,11,14,13,10,11,12,13,14,12,12,12,15,
  128848. 15,13,13,13,14,14, 9,10,10,13,13,10,11,12,12,14,
  128849. 10,11,10,13,13,13,13,13,14,16,13,13,13,14,14,11,
  128850. 12,13,15,13,12,14,13,14,16,12,12,13,13,14,13,14,
  128851. 14,17,15,13,12,17,13,16,11,12,13,14,15,12,13,14,
  128852. 14,17,11,12,11,14,14,13,16,14,16, 0,14,15,11,15,
  128853. 11,
  128854. };
  128855. static float _vq_quantthresh__16u0__p4_0[] = {
  128856. -1.5, -0.5, 0.5, 1.5,
  128857. };
  128858. static long _vq_quantmap__16u0__p4_0[] = {
  128859. 3, 1, 0, 2, 4,
  128860. };
  128861. static encode_aux_threshmatch _vq_auxt__16u0__p4_0 = {
  128862. _vq_quantthresh__16u0__p4_0,
  128863. _vq_quantmap__16u0__p4_0,
  128864. 5,
  128865. 5
  128866. };
  128867. static static_codebook _16u0__p4_0 = {
  128868. 4, 625,
  128869. _vq_lengthlist__16u0__p4_0,
  128870. 1, -533725184, 1611661312, 3, 0,
  128871. _vq_quantlist__16u0__p4_0,
  128872. NULL,
  128873. &_vq_auxt__16u0__p4_0,
  128874. NULL,
  128875. 0
  128876. };
  128877. static long _vq_quantlist__16u0__p5_0[] = {
  128878. 4,
  128879. 3,
  128880. 5,
  128881. 2,
  128882. 6,
  128883. 1,
  128884. 7,
  128885. 0,
  128886. 8,
  128887. };
  128888. static long _vq_lengthlist__16u0__p5_0[] = {
  128889. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  128890. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  128891. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 7, 8, 8,
  128892. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  128893. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,10,11,11,12,
  128894. 12,
  128895. };
  128896. static float _vq_quantthresh__16u0__p5_0[] = {
  128897. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  128898. };
  128899. static long _vq_quantmap__16u0__p5_0[] = {
  128900. 7, 5, 3, 1, 0, 2, 4, 6,
  128901. 8,
  128902. };
  128903. static encode_aux_threshmatch _vq_auxt__16u0__p5_0 = {
  128904. _vq_quantthresh__16u0__p5_0,
  128905. _vq_quantmap__16u0__p5_0,
  128906. 9,
  128907. 9
  128908. };
  128909. static static_codebook _16u0__p5_0 = {
  128910. 2, 81,
  128911. _vq_lengthlist__16u0__p5_0,
  128912. 1, -531628032, 1611661312, 4, 0,
  128913. _vq_quantlist__16u0__p5_0,
  128914. NULL,
  128915. &_vq_auxt__16u0__p5_0,
  128916. NULL,
  128917. 0
  128918. };
  128919. static long _vq_quantlist__16u0__p6_0[] = {
  128920. 6,
  128921. 5,
  128922. 7,
  128923. 4,
  128924. 8,
  128925. 3,
  128926. 9,
  128927. 2,
  128928. 10,
  128929. 1,
  128930. 11,
  128931. 0,
  128932. 12,
  128933. };
  128934. static long _vq_lengthlist__16u0__p6_0[] = {
  128935. 1, 4, 4, 7, 7,10,10,12,12,13,13,18,17, 3, 6, 6,
  128936. 9, 9,11,11,13,13,14,14,18,17, 3, 6, 6, 9, 9,11,
  128937. 11,13,13,14,14,17,18, 7, 9, 9,11,11,13,13,14,14,
  128938. 15,15, 0, 0, 7, 9, 9,11,11,13,13,14,14,15,16,19,
  128939. 18,10,11,11,13,13,14,14,16,15,17,18, 0, 0,10,11,
  128940. 11,13,13,14,14,15,15,16,18, 0, 0,11,13,13,14,14,
  128941. 15,15,17,17, 0,19, 0, 0,11,13,13,14,14,14,15,16,
  128942. 18, 0,19, 0, 0,13,14,14,15,15,18,17,18,18, 0,19,
  128943. 0, 0,13,14,14,15,16,16,16,18,18,19, 0, 0, 0,16,
  128944. 17,17, 0,17,19,19, 0,19, 0, 0, 0, 0,16,19,16,17,
  128945. 18, 0,19, 0, 0, 0, 0, 0, 0,
  128946. };
  128947. static float _vq_quantthresh__16u0__p6_0[] = {
  128948. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  128949. 12.5, 17.5, 22.5, 27.5,
  128950. };
  128951. static long _vq_quantmap__16u0__p6_0[] = {
  128952. 11, 9, 7, 5, 3, 1, 0, 2,
  128953. 4, 6, 8, 10, 12,
  128954. };
  128955. static encode_aux_threshmatch _vq_auxt__16u0__p6_0 = {
  128956. _vq_quantthresh__16u0__p6_0,
  128957. _vq_quantmap__16u0__p6_0,
  128958. 13,
  128959. 13
  128960. };
  128961. static static_codebook _16u0__p6_0 = {
  128962. 2, 169,
  128963. _vq_lengthlist__16u0__p6_0,
  128964. 1, -526516224, 1616117760, 4, 0,
  128965. _vq_quantlist__16u0__p6_0,
  128966. NULL,
  128967. &_vq_auxt__16u0__p6_0,
  128968. NULL,
  128969. 0
  128970. };
  128971. static long _vq_quantlist__16u0__p6_1[] = {
  128972. 2,
  128973. 1,
  128974. 3,
  128975. 0,
  128976. 4,
  128977. };
  128978. static long _vq_lengthlist__16u0__p6_1[] = {
  128979. 1, 4, 5, 6, 6, 4, 6, 6, 6, 6, 4, 6, 6, 6, 6, 6,
  128980. 6, 6, 7, 7, 6, 6, 6, 7, 7,
  128981. };
  128982. static float _vq_quantthresh__16u0__p6_1[] = {
  128983. -1.5, -0.5, 0.5, 1.5,
  128984. };
  128985. static long _vq_quantmap__16u0__p6_1[] = {
  128986. 3, 1, 0, 2, 4,
  128987. };
  128988. static encode_aux_threshmatch _vq_auxt__16u0__p6_1 = {
  128989. _vq_quantthresh__16u0__p6_1,
  128990. _vq_quantmap__16u0__p6_1,
  128991. 5,
  128992. 5
  128993. };
  128994. static static_codebook _16u0__p6_1 = {
  128995. 2, 25,
  128996. _vq_lengthlist__16u0__p6_1,
  128997. 1, -533725184, 1611661312, 3, 0,
  128998. _vq_quantlist__16u0__p6_1,
  128999. NULL,
  129000. &_vq_auxt__16u0__p6_1,
  129001. NULL,
  129002. 0
  129003. };
  129004. static long _vq_quantlist__16u0__p7_0[] = {
  129005. 1,
  129006. 0,
  129007. 2,
  129008. };
  129009. static long _vq_lengthlist__16u0__p7_0[] = {
  129010. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129011. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129012. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129013. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129014. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  129015. 7,
  129016. };
  129017. static float _vq_quantthresh__16u0__p7_0[] = {
  129018. -157.5, 157.5,
  129019. };
  129020. static long _vq_quantmap__16u0__p7_0[] = {
  129021. 1, 0, 2,
  129022. };
  129023. static encode_aux_threshmatch _vq_auxt__16u0__p7_0 = {
  129024. _vq_quantthresh__16u0__p7_0,
  129025. _vq_quantmap__16u0__p7_0,
  129026. 3,
  129027. 3
  129028. };
  129029. static static_codebook _16u0__p7_0 = {
  129030. 4, 81,
  129031. _vq_lengthlist__16u0__p7_0,
  129032. 1, -518803456, 1628680192, 2, 0,
  129033. _vq_quantlist__16u0__p7_0,
  129034. NULL,
  129035. &_vq_auxt__16u0__p7_0,
  129036. NULL,
  129037. 0
  129038. };
  129039. static long _vq_quantlist__16u0__p7_1[] = {
  129040. 7,
  129041. 6,
  129042. 8,
  129043. 5,
  129044. 9,
  129045. 4,
  129046. 10,
  129047. 3,
  129048. 11,
  129049. 2,
  129050. 12,
  129051. 1,
  129052. 13,
  129053. 0,
  129054. 14,
  129055. };
  129056. static long _vq_lengthlist__16u0__p7_1[] = {
  129057. 1, 5, 5, 6, 5, 9,10,11,11,10,10,10,10,10,10, 5,
  129058. 8, 8, 8,10,10,10,10,10,10,10,10,10,10,10, 5, 8,
  129059. 9, 9, 9,10,10,10,10,10,10,10,10,10,10, 5,10, 8,
  129060. 10,10,10,10,10,10,10,10,10,10,10,10, 4, 8, 9,10,
  129061. 10,10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,
  129062. 10,10,10,10,10,10,10,10,10,10, 9,10,10,10,10,10,
  129063. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129064. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129065. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129066. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129067. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129068. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129069. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129070. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129071. 10,
  129072. };
  129073. static float _vq_quantthresh__16u0__p7_1[] = {
  129074. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  129075. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  129076. };
  129077. static long _vq_quantmap__16u0__p7_1[] = {
  129078. 13, 11, 9, 7, 5, 3, 1, 0,
  129079. 2, 4, 6, 8, 10, 12, 14,
  129080. };
  129081. static encode_aux_threshmatch _vq_auxt__16u0__p7_1 = {
  129082. _vq_quantthresh__16u0__p7_1,
  129083. _vq_quantmap__16u0__p7_1,
  129084. 15,
  129085. 15
  129086. };
  129087. static static_codebook _16u0__p7_1 = {
  129088. 2, 225,
  129089. _vq_lengthlist__16u0__p7_1,
  129090. 1, -520986624, 1620377600, 4, 0,
  129091. _vq_quantlist__16u0__p7_1,
  129092. NULL,
  129093. &_vq_auxt__16u0__p7_1,
  129094. NULL,
  129095. 0
  129096. };
  129097. static long _vq_quantlist__16u0__p7_2[] = {
  129098. 10,
  129099. 9,
  129100. 11,
  129101. 8,
  129102. 12,
  129103. 7,
  129104. 13,
  129105. 6,
  129106. 14,
  129107. 5,
  129108. 15,
  129109. 4,
  129110. 16,
  129111. 3,
  129112. 17,
  129113. 2,
  129114. 18,
  129115. 1,
  129116. 19,
  129117. 0,
  129118. 20,
  129119. };
  129120. static long _vq_lengthlist__16u0__p7_2[] = {
  129121. 1, 6, 6, 7, 8, 7, 7,10, 9,10, 9,11,10, 9,11,10,
  129122. 9, 9, 9, 9,10, 6, 8, 7, 9, 9, 8, 8,10,10, 9,11,
  129123. 11,12,12,10, 9,11, 9,12,10, 9, 6, 9, 8, 9,12, 8,
  129124. 8,11, 9,11,11,12,11,12,12,10,11,11,10,10,11, 7,
  129125. 10, 9, 9, 9, 9, 9,10, 9,10, 9,10,10,12,10,10,10,
  129126. 11,12,10,10, 7, 9, 9, 9,10, 9, 9,10,10, 9, 9, 9,
  129127. 11,11,10,10,10,10, 9, 9,12, 7, 9,10, 9,11, 9,10,
  129128. 9,10,11,11,11,10,11,12, 9,12,11,10,10,10, 7, 9,
  129129. 9, 9, 9,10,12,10, 9,11,12,10,11,12,12,11, 9,10,
  129130. 11,10,11, 7, 9,10,10,11,10, 9,10,11,11,11,10,12,
  129131. 12,12,11,11,10,11,11,12, 8, 9,10,12,11,10,10,12,
  129132. 12,12,12,12,10,11,11, 9,11,10,12,11,11, 8, 9,10,
  129133. 10,11,12,11,11,10,10,10,12,12,12, 9,10,12,12,12,
  129134. 12,12, 8,10,11,10,10,12, 9,11,12,12,11,12,12,12,
  129135. 12,10,12,10,10,10,10, 8,12,11,11,11,10,10,11,12,
  129136. 12,12,12,11,12,12,12,11,11,11,12,10, 9,10,10,12,
  129137. 10,12,10,12,12,10,10,10,11,12,12,12,11,12,12,12,
  129138. 11,10,11,12,12,12,11,12,12,11,12,12,11,12,12,12,
  129139. 12,11,12,12,10,10,10,10,11,11,12,11,12,12,12,12,
  129140. 12,12,12,11,12,11,10,11,11,12,11,11, 9,10,10,10,
  129141. 12,10,10,11, 9,11,12,11,12,11,12,12,10,11,10,12,
  129142. 9, 9, 9,12,11,10,11,10,12,10,12,10,12,12,12,11,
  129143. 11,11,11,11,10, 9,10,10,11,10,11,11,12,11,10,11,
  129144. 12,12,12,11,11, 9,12,10,12, 9,10,12,10,10,11,10,
  129145. 11,11,12,11,10,11,10,11,11,11,11,12,11,11,10, 9,
  129146. 10,10,10, 9,11,11,10, 9,12,10,11,12,11,12,12,11,
  129147. 12,11,12,11,10,11,10,12,11,12,11,12,11,12,10,11,
  129148. 10,10,12,11,10,11,11,11,10,
  129149. };
  129150. static float _vq_quantthresh__16u0__p7_2[] = {
  129151. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  129152. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  129153. 6.5, 7.5, 8.5, 9.5,
  129154. };
  129155. static long _vq_quantmap__16u0__p7_2[] = {
  129156. 19, 17, 15, 13, 11, 9, 7, 5,
  129157. 3, 1, 0, 2, 4, 6, 8, 10,
  129158. 12, 14, 16, 18, 20,
  129159. };
  129160. static encode_aux_threshmatch _vq_auxt__16u0__p7_2 = {
  129161. _vq_quantthresh__16u0__p7_2,
  129162. _vq_quantmap__16u0__p7_2,
  129163. 21,
  129164. 21
  129165. };
  129166. static static_codebook _16u0__p7_2 = {
  129167. 2, 441,
  129168. _vq_lengthlist__16u0__p7_2,
  129169. 1, -529268736, 1611661312, 5, 0,
  129170. _vq_quantlist__16u0__p7_2,
  129171. NULL,
  129172. &_vq_auxt__16u0__p7_2,
  129173. NULL,
  129174. 0
  129175. };
  129176. static long _huff_lengthlist__16u0__single[] = {
  129177. 3, 5, 8, 7,14, 8, 9,19, 5, 2, 5, 5, 9, 6, 9,19,
  129178. 8, 4, 5, 7, 8, 9,13,19, 7, 4, 6, 5, 9, 6, 9,19,
  129179. 12, 8, 7, 9,10,11,13,19, 8, 5, 8, 6, 9, 6, 7,19,
  129180. 8, 8,10, 7, 7, 4, 5,19,12,17,19,15,18,13,11,18,
  129181. };
  129182. static static_codebook _huff_book__16u0__single = {
  129183. 2, 64,
  129184. _huff_lengthlist__16u0__single,
  129185. 0, 0, 0, 0, 0,
  129186. NULL,
  129187. NULL,
  129188. NULL,
  129189. NULL,
  129190. 0
  129191. };
  129192. static long _huff_lengthlist__16u1__long[] = {
  129193. 3, 6,10, 8,12, 8,14, 8,14,19, 5, 3, 5, 5, 7, 6,
  129194. 11, 7,16,19, 7, 5, 6, 7, 7, 9,11,12,19,19, 6, 4,
  129195. 7, 5, 7, 6,10, 7,18,18, 8, 6, 7, 7, 7, 7, 8, 9,
  129196. 18,18, 7, 5, 8, 5, 7, 5, 8, 6,18,18,12, 9,10, 9,
  129197. 9, 9, 8, 9,18,18, 8, 7,10, 6, 8, 5, 6, 4,11,18,
  129198. 11,15,16,12,11, 8, 8, 6, 9,18,14,18,18,18,16,16,
  129199. 16,13,16,18,
  129200. };
  129201. static static_codebook _huff_book__16u1__long = {
  129202. 2, 100,
  129203. _huff_lengthlist__16u1__long,
  129204. 0, 0, 0, 0, 0,
  129205. NULL,
  129206. NULL,
  129207. NULL,
  129208. NULL,
  129209. 0
  129210. };
  129211. static long _vq_quantlist__16u1__p1_0[] = {
  129212. 1,
  129213. 0,
  129214. 2,
  129215. };
  129216. static long _vq_lengthlist__16u1__p1_0[] = {
  129217. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 7, 7,10,10, 7,
  129218. 9,10, 5, 7, 8, 7,10, 9, 7,10,10, 5, 8, 8, 8,10,
  129219. 10, 8,10,10, 7,10,10,10,11,12,10,12,13, 7,10,10,
  129220. 9,13,11,10,12,13, 5, 8, 8, 8,10,10, 8,10,10, 7,
  129221. 10,10,10,12,12, 9,11,12, 7,10,11,10,12,12,10,13,
  129222. 11,
  129223. };
  129224. static float _vq_quantthresh__16u1__p1_0[] = {
  129225. -0.5, 0.5,
  129226. };
  129227. static long _vq_quantmap__16u1__p1_0[] = {
  129228. 1, 0, 2,
  129229. };
  129230. static encode_aux_threshmatch _vq_auxt__16u1__p1_0 = {
  129231. _vq_quantthresh__16u1__p1_0,
  129232. _vq_quantmap__16u1__p1_0,
  129233. 3,
  129234. 3
  129235. };
  129236. static static_codebook _16u1__p1_0 = {
  129237. 4, 81,
  129238. _vq_lengthlist__16u1__p1_0,
  129239. 1, -535822336, 1611661312, 2, 0,
  129240. _vq_quantlist__16u1__p1_0,
  129241. NULL,
  129242. &_vq_auxt__16u1__p1_0,
  129243. NULL,
  129244. 0
  129245. };
  129246. static long _vq_quantlist__16u1__p2_0[] = {
  129247. 1,
  129248. 0,
  129249. 2,
  129250. };
  129251. static long _vq_lengthlist__16u1__p2_0[] = {
  129252. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 7, 8, 6,
  129253. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 6, 8,
  129254. 8, 6, 8, 8, 6, 8, 8, 7, 7,10, 8, 9, 9, 6, 8, 8,
  129255. 7, 9, 8, 8, 9,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  129256. 8, 8, 8,10, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 7,10,
  129257. 8,
  129258. };
  129259. static float _vq_quantthresh__16u1__p2_0[] = {
  129260. -0.5, 0.5,
  129261. };
  129262. static long _vq_quantmap__16u1__p2_0[] = {
  129263. 1, 0, 2,
  129264. };
  129265. static encode_aux_threshmatch _vq_auxt__16u1__p2_0 = {
  129266. _vq_quantthresh__16u1__p2_0,
  129267. _vq_quantmap__16u1__p2_0,
  129268. 3,
  129269. 3
  129270. };
  129271. static static_codebook _16u1__p2_0 = {
  129272. 4, 81,
  129273. _vq_lengthlist__16u1__p2_0,
  129274. 1, -535822336, 1611661312, 2, 0,
  129275. _vq_quantlist__16u1__p2_0,
  129276. NULL,
  129277. &_vq_auxt__16u1__p2_0,
  129278. NULL,
  129279. 0
  129280. };
  129281. static long _vq_quantlist__16u1__p3_0[] = {
  129282. 2,
  129283. 1,
  129284. 3,
  129285. 0,
  129286. 4,
  129287. };
  129288. static long _vq_lengthlist__16u1__p3_0[] = {
  129289. 1, 5, 5, 8, 8, 6, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129290. 10, 9,11,11, 9, 9,10,11,11, 6, 8, 8,10,10, 8, 9,
  129291. 10,11,11, 8, 9,10,11,11,10,11,11,12,13,10,11,11,
  129292. 13,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  129293. 11,10,11,11,13,13,10,11,11,13,12, 9,11,11,14,13,
  129294. 10,12,12,15,14,10,12,11,14,13,12,13,13,15,15,12,
  129295. 13,13,16,14, 9,11,11,13,14,10,11,12,14,14,10,12,
  129296. 12,14,15,12,13,13,14,15,12,13,14,15,16, 5, 8, 8,
  129297. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  129298. 14,11,12,12,14,14, 8,10,10,12,12, 9,11,12,12,13,
  129299. 10,12,12,13,13,12,12,13,14,15,11,13,13,15,15, 7,
  129300. 10,10,12,12, 9,12,11,13,12,10,11,12,13,13,12,13,
  129301. 12,15,14,11,12,13,15,15,10,12,12,15,14,11,13,13,
  129302. 16,15,11,13,13,16,15,14,13,14,15,16,13,15,15,17,
  129303. 17,10,12,12,14,15,11,12,12,15,15,11,13,13,15,16,
  129304. 13,15,13,16,15,13,15,15,16,17, 5, 8, 8,11,11, 8,
  129305. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  129306. 12,14,14, 7,10,10,12,12,10,12,12,14,13, 9,11,12,
  129307. 12,13,12,13,13,15,15,12,12,13,13,15, 7,10,10,12,
  129308. 13,10,11,12,13,13,10,12,11,13,13,11,13,13,15,15,
  129309. 12,13,12,15,14, 9,12,12,15,14,11,13,13,15,15,11,
  129310. 12,13,15,15,13,14,14,17,19,13,13,14,16,16,10,12,
  129311. 12,14,15,11,13,13,15,16,11,13,12,16,15,13,15,15,
  129312. 17,18,14,15,13,16,15, 8,11,11,15,14,10,12,12,16,
  129313. 15,10,12,12,16,16,14,15,15,18,17,13,14,15,16,18,
  129314. 9,12,12,15,15,11,12,14,16,17,11,13,13,16,15,15,
  129315. 15,15,17,18,14,15,16,17,17, 9,12,12,15,15,11,14,
  129316. 13,16,16,11,13,13,16,16,15,16,15,17,18,14,16,15,
  129317. 17,16,12,14,14,17,16,12,14,15,18,17,13,15,15,17,
  129318. 17,15,15,18,16,20,15,16,17,18,18,11,14,14,16,17,
  129319. 13,15,14,18,17,13,15,15,17,17,15,17,15,18,17,15,
  129320. 17,16,19,18, 8,11,11,14,15,10,12,12,15,15,10,12,
  129321. 12,16,16,13,14,14,17,16,14,15,15,17,17, 9,12,12,
  129322. 15,16,11,13,13,16,16,11,12,13,16,16,14,16,15,20,
  129323. 17,14,16,16,17,17, 9,12,12,15,16,11,13,13,16,17,
  129324. 11,13,13,17,16,14,15,15,17,18,15,15,15,18,18,11,
  129325. 14,14,17,16,13,15,15,17,17,13,14,14,18,17,15,16,
  129326. 16,18,19,15,15,17,17,19,11,14,14,16,17,13,15,14,
  129327. 17,19,13,15,14,18,17,15,17,16,18,18,15,17,15,18,
  129328. 16,
  129329. };
  129330. static float _vq_quantthresh__16u1__p3_0[] = {
  129331. -1.5, -0.5, 0.5, 1.5,
  129332. };
  129333. static long _vq_quantmap__16u1__p3_0[] = {
  129334. 3, 1, 0, 2, 4,
  129335. };
  129336. static encode_aux_threshmatch _vq_auxt__16u1__p3_0 = {
  129337. _vq_quantthresh__16u1__p3_0,
  129338. _vq_quantmap__16u1__p3_0,
  129339. 5,
  129340. 5
  129341. };
  129342. static static_codebook _16u1__p3_0 = {
  129343. 4, 625,
  129344. _vq_lengthlist__16u1__p3_0,
  129345. 1, -533725184, 1611661312, 3, 0,
  129346. _vq_quantlist__16u1__p3_0,
  129347. NULL,
  129348. &_vq_auxt__16u1__p3_0,
  129349. NULL,
  129350. 0
  129351. };
  129352. static long _vq_quantlist__16u1__p4_0[] = {
  129353. 2,
  129354. 1,
  129355. 3,
  129356. 0,
  129357. 4,
  129358. };
  129359. static long _vq_lengthlist__16u1__p4_0[] = {
  129360. 4, 5, 5, 8, 8, 6, 6, 7, 9, 9, 6, 6, 6, 9, 9, 9,
  129361. 10, 9,11,11, 9, 9,10,11,11, 6, 7, 7,10, 9, 7, 7,
  129362. 8, 9,10, 7, 7, 8,10,10,10,10,10,10,12, 9, 9,10,
  129363. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 7,10,
  129364. 10, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  129365. 10,10,10,12,12, 9,10,10,12,12,12,11,12,13,13,11,
  129366. 11,12,12,13, 9,10,10,11,12, 9,10,10,12,12,10,10,
  129367. 10,12,12,11,12,11,14,13,11,12,12,14,13, 5, 7, 7,
  129368. 10,10, 7, 8, 8,10,10, 7, 8, 7,10,10,10,10,10,12,
  129369. 12,10,10,10,12,12, 6, 8, 7,10,10, 7, 7, 9,10,11,
  129370. 8, 9, 9,11,10,10,10,11,11,13,10,10,11,12,13, 6,
  129371. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,10,11,10,11,
  129372. 10,13,11,10,11,10,12,12,10,11,10,12,11,10,10,10,
  129373. 12,13,10,11,11,13,12,11,11,13,11,14,12,12,13,14,
  129374. 14, 9,10,10,12,13,10,11,10,13,12,10,11,11,12,13,
  129375. 11,12,11,14,12,12,13,13,15,14, 5, 7, 7,10,10, 7,
  129376. 7, 8,10,10, 7, 8, 8,10,10,10,10,10,11,12,10,10,
  129377. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  129378. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 7, 8,10,
  129379. 10, 8, 8, 9,10,11, 7, 9, 7,11,10,10,11,11,13,12,
  129380. 11,11,10,13,11, 9,10,10,12,12,10,11,11,13,12,10,
  129381. 10,11,12,12,12,13,13,14,14,11,11,12,12,14,10,10,
  129382. 11,12,12,10,11,11,12,13,10,10,10,13,12,12,13,13,
  129383. 15,14,12,13,10,14,11, 8,10,10,12,12,10,11,10,13,
  129384. 13, 9,10,10,12,12,12,13,13,15,14,11,12,12,13,13,
  129385. 9,10,10,13,12,10,10,11,13,13,10,11,10,13,12,12,
  129386. 12,13,14,15,12,13,12,15,13, 9,10,10,12,13,10,11,
  129387. 10,13,12,10,10,11,12,13,12,14,12,15,13,12,12,13,
  129388. 14,15,11,12,11,14,13,11,11,12,14,15,12,13,12,15,
  129389. 14,13,11,15,11,16,13,14,14,16,15,11,12,12,14,14,
  129390. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,12,14,
  129391. 14,14,15,15, 8,10,10,12,12, 9,10,10,12,12,10,10,
  129392. 11,13,13,11,12,12,13,13,12,13,13,14,15, 9,10,10,
  129393. 13,12,10,11,11,13,12,10,10,11,13,13,12,13,12,15,
  129394. 14,12,12,13,13,16, 9, 9,10,12,13,10,10,11,12,13,
  129395. 10,11,10,13,13,12,12,13,13,15,13,13,12,15,13,11,
  129396. 12,12,14,14,12,13,12,15,14,11,11,12,13,14,14,14,
  129397. 14,16,15,13,12,15,12,16,11,11,12,13,14,12,13,13,
  129398. 14,15,10,12,11,14,13,14,15,14,16,16,13,14,11,15,
  129399. 11,
  129400. };
  129401. static float _vq_quantthresh__16u1__p4_0[] = {
  129402. -1.5, -0.5, 0.5, 1.5,
  129403. };
  129404. static long _vq_quantmap__16u1__p4_0[] = {
  129405. 3, 1, 0, 2, 4,
  129406. };
  129407. static encode_aux_threshmatch _vq_auxt__16u1__p4_0 = {
  129408. _vq_quantthresh__16u1__p4_0,
  129409. _vq_quantmap__16u1__p4_0,
  129410. 5,
  129411. 5
  129412. };
  129413. static static_codebook _16u1__p4_0 = {
  129414. 4, 625,
  129415. _vq_lengthlist__16u1__p4_0,
  129416. 1, -533725184, 1611661312, 3, 0,
  129417. _vq_quantlist__16u1__p4_0,
  129418. NULL,
  129419. &_vq_auxt__16u1__p4_0,
  129420. NULL,
  129421. 0
  129422. };
  129423. static long _vq_quantlist__16u1__p5_0[] = {
  129424. 4,
  129425. 3,
  129426. 5,
  129427. 2,
  129428. 6,
  129429. 1,
  129430. 7,
  129431. 0,
  129432. 8,
  129433. };
  129434. static long _vq_lengthlist__16u1__p5_0[] = {
  129435. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  129436. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  129437. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  129438. 10, 9,11,11,12,11, 7, 8, 8, 9, 9,11,11,12,12, 9,
  129439. 10,10,11,11,12,12,13,12, 9,10,10,11,11,12,12,12,
  129440. 13,
  129441. };
  129442. static float _vq_quantthresh__16u1__p5_0[] = {
  129443. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129444. };
  129445. static long _vq_quantmap__16u1__p5_0[] = {
  129446. 7, 5, 3, 1, 0, 2, 4, 6,
  129447. 8,
  129448. };
  129449. static encode_aux_threshmatch _vq_auxt__16u1__p5_0 = {
  129450. _vq_quantthresh__16u1__p5_0,
  129451. _vq_quantmap__16u1__p5_0,
  129452. 9,
  129453. 9
  129454. };
  129455. static static_codebook _16u1__p5_0 = {
  129456. 2, 81,
  129457. _vq_lengthlist__16u1__p5_0,
  129458. 1, -531628032, 1611661312, 4, 0,
  129459. _vq_quantlist__16u1__p5_0,
  129460. NULL,
  129461. &_vq_auxt__16u1__p5_0,
  129462. NULL,
  129463. 0
  129464. };
  129465. static long _vq_quantlist__16u1__p6_0[] = {
  129466. 4,
  129467. 3,
  129468. 5,
  129469. 2,
  129470. 6,
  129471. 1,
  129472. 7,
  129473. 0,
  129474. 8,
  129475. };
  129476. static long _vq_lengthlist__16u1__p6_0[] = {
  129477. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 4, 6, 6, 8, 8,
  129478. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  129479. 8, 8,10, 9, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  129480. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  129481. 9, 9,10,10,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  129482. 11,
  129483. };
  129484. static float _vq_quantthresh__16u1__p6_0[] = {
  129485. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  129486. };
  129487. static long _vq_quantmap__16u1__p6_0[] = {
  129488. 7, 5, 3, 1, 0, 2, 4, 6,
  129489. 8,
  129490. };
  129491. static encode_aux_threshmatch _vq_auxt__16u1__p6_0 = {
  129492. _vq_quantthresh__16u1__p6_0,
  129493. _vq_quantmap__16u1__p6_0,
  129494. 9,
  129495. 9
  129496. };
  129497. static static_codebook _16u1__p6_0 = {
  129498. 2, 81,
  129499. _vq_lengthlist__16u1__p6_0,
  129500. 1, -531628032, 1611661312, 4, 0,
  129501. _vq_quantlist__16u1__p6_0,
  129502. NULL,
  129503. &_vq_auxt__16u1__p6_0,
  129504. NULL,
  129505. 0
  129506. };
  129507. static long _vq_quantlist__16u1__p7_0[] = {
  129508. 1,
  129509. 0,
  129510. 2,
  129511. };
  129512. static long _vq_lengthlist__16u1__p7_0[] = {
  129513. 1, 4, 4, 4, 8, 8, 4, 8, 8, 5,11, 9, 8,12,11, 8,
  129514. 12,11, 5,10,11, 8,11,12, 8,11,12, 4,11,11,11,14,
  129515. 13,10,13,13, 8,14,13,12,14,16,12,16,15, 8,14,14,
  129516. 13,16,14,12,15,16, 4,11,11,10,14,13,11,14,14, 8,
  129517. 15,14,12,15,15,12,14,16, 8,14,14,11,16,15,12,15,
  129518. 13,
  129519. };
  129520. static float _vq_quantthresh__16u1__p7_0[] = {
  129521. -5.5, 5.5,
  129522. };
  129523. static long _vq_quantmap__16u1__p7_0[] = {
  129524. 1, 0, 2,
  129525. };
  129526. static encode_aux_threshmatch _vq_auxt__16u1__p7_0 = {
  129527. _vq_quantthresh__16u1__p7_0,
  129528. _vq_quantmap__16u1__p7_0,
  129529. 3,
  129530. 3
  129531. };
  129532. static static_codebook _16u1__p7_0 = {
  129533. 4, 81,
  129534. _vq_lengthlist__16u1__p7_0,
  129535. 1, -529137664, 1618345984, 2, 0,
  129536. _vq_quantlist__16u1__p7_0,
  129537. NULL,
  129538. &_vq_auxt__16u1__p7_0,
  129539. NULL,
  129540. 0
  129541. };
  129542. static long _vq_quantlist__16u1__p7_1[] = {
  129543. 5,
  129544. 4,
  129545. 6,
  129546. 3,
  129547. 7,
  129548. 2,
  129549. 8,
  129550. 1,
  129551. 9,
  129552. 0,
  129553. 10,
  129554. };
  129555. static long _vq_lengthlist__16u1__p7_1[] = {
  129556. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 5, 7, 7,
  129557. 8, 8, 8, 8, 8, 8, 4, 5, 6, 7, 7, 8, 8, 8, 8, 8,
  129558. 8, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  129559. 8, 8, 8, 9, 9, 9, 9, 7, 8, 8, 8, 8, 9, 9, 9,10,
  129560. 9,10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10, 9, 8, 8, 8,
  129561. 9, 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,10,
  129562. 10,10,10, 8, 8, 8, 9, 9, 9,10,10,10,10,10, 8, 8,
  129563. 8, 9, 9,10,10,10,10,10,10,
  129564. };
  129565. static float _vq_quantthresh__16u1__p7_1[] = {
  129566. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129567. 3.5, 4.5,
  129568. };
  129569. static long _vq_quantmap__16u1__p7_1[] = {
  129570. 9, 7, 5, 3, 1, 0, 2, 4,
  129571. 6, 8, 10,
  129572. };
  129573. static encode_aux_threshmatch _vq_auxt__16u1__p7_1 = {
  129574. _vq_quantthresh__16u1__p7_1,
  129575. _vq_quantmap__16u1__p7_1,
  129576. 11,
  129577. 11
  129578. };
  129579. static static_codebook _16u1__p7_1 = {
  129580. 2, 121,
  129581. _vq_lengthlist__16u1__p7_1,
  129582. 1, -531365888, 1611661312, 4, 0,
  129583. _vq_quantlist__16u1__p7_1,
  129584. NULL,
  129585. &_vq_auxt__16u1__p7_1,
  129586. NULL,
  129587. 0
  129588. };
  129589. static long _vq_quantlist__16u1__p8_0[] = {
  129590. 5,
  129591. 4,
  129592. 6,
  129593. 3,
  129594. 7,
  129595. 2,
  129596. 8,
  129597. 1,
  129598. 9,
  129599. 0,
  129600. 10,
  129601. };
  129602. static long _vq_lengthlist__16u1__p8_0[] = {
  129603. 1, 4, 4, 5, 5, 8, 8,10,10,12,12, 4, 7, 7, 8, 8,
  129604. 9, 9,12,11,14,13, 4, 7, 7, 7, 8, 9,10,11,11,13,
  129605. 12, 5, 8, 8, 9, 9,11,11,12,13,15,14, 5, 7, 8, 9,
  129606. 9,11,11,13,13,17,15, 8, 9,10,11,11,12,13,17,14,
  129607. 17,16, 8,10, 9,11,11,12,12,13,15,15,17,10,11,11,
  129608. 12,13,14,15,15,16,16,17, 9,11,11,12,12,14,15,17,
  129609. 15,15,16,11,14,12,14,15,16,15,16,16,16,15,11,13,
  129610. 13,14,14,15,15,16,16,15,16,
  129611. };
  129612. static float _vq_quantthresh__16u1__p8_0[] = {
  129613. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  129614. 38.5, 49.5,
  129615. };
  129616. static long _vq_quantmap__16u1__p8_0[] = {
  129617. 9, 7, 5, 3, 1, 0, 2, 4,
  129618. 6, 8, 10,
  129619. };
  129620. static encode_aux_threshmatch _vq_auxt__16u1__p8_0 = {
  129621. _vq_quantthresh__16u1__p8_0,
  129622. _vq_quantmap__16u1__p8_0,
  129623. 11,
  129624. 11
  129625. };
  129626. static static_codebook _16u1__p8_0 = {
  129627. 2, 121,
  129628. _vq_lengthlist__16u1__p8_0,
  129629. 1, -524582912, 1618345984, 4, 0,
  129630. _vq_quantlist__16u1__p8_0,
  129631. NULL,
  129632. &_vq_auxt__16u1__p8_0,
  129633. NULL,
  129634. 0
  129635. };
  129636. static long _vq_quantlist__16u1__p8_1[] = {
  129637. 5,
  129638. 4,
  129639. 6,
  129640. 3,
  129641. 7,
  129642. 2,
  129643. 8,
  129644. 1,
  129645. 9,
  129646. 0,
  129647. 10,
  129648. };
  129649. static long _vq_lengthlist__16u1__p8_1[] = {
  129650. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7,
  129651. 8, 7, 8, 8, 8, 8, 4, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  129652. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 9, 6, 7, 7, 7,
  129653. 7, 8, 8, 8, 8, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  129654. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  129655. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  129656. 9, 9, 9, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  129657. 8, 9, 9, 9, 9, 9, 9, 9, 9,
  129658. };
  129659. static float _vq_quantthresh__16u1__p8_1[] = {
  129660. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  129661. 3.5, 4.5,
  129662. };
  129663. static long _vq_quantmap__16u1__p8_1[] = {
  129664. 9, 7, 5, 3, 1, 0, 2, 4,
  129665. 6, 8, 10,
  129666. };
  129667. static encode_aux_threshmatch _vq_auxt__16u1__p8_1 = {
  129668. _vq_quantthresh__16u1__p8_1,
  129669. _vq_quantmap__16u1__p8_1,
  129670. 11,
  129671. 11
  129672. };
  129673. static static_codebook _16u1__p8_1 = {
  129674. 2, 121,
  129675. _vq_lengthlist__16u1__p8_1,
  129676. 1, -531365888, 1611661312, 4, 0,
  129677. _vq_quantlist__16u1__p8_1,
  129678. NULL,
  129679. &_vq_auxt__16u1__p8_1,
  129680. NULL,
  129681. 0
  129682. };
  129683. static long _vq_quantlist__16u1__p9_0[] = {
  129684. 7,
  129685. 6,
  129686. 8,
  129687. 5,
  129688. 9,
  129689. 4,
  129690. 10,
  129691. 3,
  129692. 11,
  129693. 2,
  129694. 12,
  129695. 1,
  129696. 13,
  129697. 0,
  129698. 14,
  129699. };
  129700. static long _vq_lengthlist__16u1__p9_0[] = {
  129701. 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129702. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129703. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129704. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129705. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129706. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129707. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129708. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129709. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129710. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129711. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129712. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129713. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129714. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  129715. 8,
  129716. };
  129717. static float _vq_quantthresh__16u1__p9_0[] = {
  129718. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  129719. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  129720. };
  129721. static long _vq_quantmap__16u1__p9_0[] = {
  129722. 13, 11, 9, 7, 5, 3, 1, 0,
  129723. 2, 4, 6, 8, 10, 12, 14,
  129724. };
  129725. static encode_aux_threshmatch _vq_auxt__16u1__p9_0 = {
  129726. _vq_quantthresh__16u1__p9_0,
  129727. _vq_quantmap__16u1__p9_0,
  129728. 15,
  129729. 15
  129730. };
  129731. static static_codebook _16u1__p9_0 = {
  129732. 2, 225,
  129733. _vq_lengthlist__16u1__p9_0,
  129734. 1, -514071552, 1627381760, 4, 0,
  129735. _vq_quantlist__16u1__p9_0,
  129736. NULL,
  129737. &_vq_auxt__16u1__p9_0,
  129738. NULL,
  129739. 0
  129740. };
  129741. static long _vq_quantlist__16u1__p9_1[] = {
  129742. 7,
  129743. 6,
  129744. 8,
  129745. 5,
  129746. 9,
  129747. 4,
  129748. 10,
  129749. 3,
  129750. 11,
  129751. 2,
  129752. 12,
  129753. 1,
  129754. 13,
  129755. 0,
  129756. 14,
  129757. };
  129758. static long _vq_lengthlist__16u1__p9_1[] = {
  129759. 1, 6, 5, 9, 9,10,10, 6, 7, 9, 9,10,10,10,10, 5,
  129760. 10, 8,10, 8,10,10, 8, 8,10, 9,10,10,10,10, 5, 8,
  129761. 9,10,10,10,10, 8,10,10,10,10,10,10,10, 9,10,10,
  129762. 10,10,10,10, 9, 9,10,10,10,10,10,10, 9, 9, 8, 9,
  129763. 10,10,10, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  129764. 10,10,10,10,10,10,10,10,10,10,10, 8,10,10,10,10,
  129765. 10,10,10,10,10,10,10,10,10, 6, 8, 8,10,10,10, 8,
  129766. 10,10,10,10,10,10,10,10, 5, 8, 8,10,10,10, 9, 9,
  129767. 10,10,10,10,10,10,10,10, 9,10,10,10,10,10,10,10,
  129768. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  129769. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,
  129770. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129771. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129772. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  129773. 9,
  129774. };
  129775. static float _vq_quantthresh__16u1__p9_1[] = {
  129776. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  129777. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  129778. };
  129779. static long _vq_quantmap__16u1__p9_1[] = {
  129780. 13, 11, 9, 7, 5, 3, 1, 0,
  129781. 2, 4, 6, 8, 10, 12, 14,
  129782. };
  129783. static encode_aux_threshmatch _vq_auxt__16u1__p9_1 = {
  129784. _vq_quantthresh__16u1__p9_1,
  129785. _vq_quantmap__16u1__p9_1,
  129786. 15,
  129787. 15
  129788. };
  129789. static static_codebook _16u1__p9_1 = {
  129790. 2, 225,
  129791. _vq_lengthlist__16u1__p9_1,
  129792. 1, -522338304, 1620115456, 4, 0,
  129793. _vq_quantlist__16u1__p9_1,
  129794. NULL,
  129795. &_vq_auxt__16u1__p9_1,
  129796. NULL,
  129797. 0
  129798. };
  129799. static long _vq_quantlist__16u1__p9_2[] = {
  129800. 8,
  129801. 7,
  129802. 9,
  129803. 6,
  129804. 10,
  129805. 5,
  129806. 11,
  129807. 4,
  129808. 12,
  129809. 3,
  129810. 13,
  129811. 2,
  129812. 14,
  129813. 1,
  129814. 15,
  129815. 0,
  129816. 16,
  129817. };
  129818. static long _vq_lengthlist__16u1__p9_2[] = {
  129819. 1, 6, 6, 7, 8, 8,11,10, 9, 9,11, 9,10, 9,11,11,
  129820. 9, 6, 7, 6,11, 8,11, 9,10,10,11, 9,11,10,10,10,
  129821. 11, 9, 5, 7, 7, 8, 8,10,11, 8, 8,11, 9, 9,10,11,
  129822. 9,10,11, 8, 9, 6, 8, 8, 9, 9,10,10,11,11,11, 9,
  129823. 11,10, 9,11, 8, 8, 8, 9, 8, 9,10,11, 9, 9,11,11,
  129824. 10, 9, 9,11,10, 8,11, 8, 9, 8,11, 9,10, 9,10,11,
  129825. 11,10,10, 9,10,10, 8, 8, 9,10,10,10, 9,11, 9,10,
  129826. 11,11,11,11,10, 9,11, 9, 9,11,11,10, 8,11,11,11,
  129827. 9,10,10,11,10,11,11, 9,11,10, 9,11,10,10,10,10,
  129828. 9,11,10,11,10, 9, 9,10,11, 9, 8,10,11,11,10,10,
  129829. 11, 9,11,10,11,11,10,11, 9, 9, 8,10, 8, 9,11, 9,
  129830. 8,10,10, 9,11,10,11,10,11, 9,11, 8,10,11,11,11,
  129831. 11,10,10,11,11,11,11,10,11,11,10, 9, 8,10,10, 9,
  129832. 11,10,11,11,11, 9, 9, 9,11,11,11,10,10, 9, 9,10,
  129833. 9,11,11,11,11, 8,10,11,10,11,11,10,11,11, 9, 9,
  129834. 9,10, 9,11, 9,11,11,11,11,11,10,11,11,10,11,10,
  129835. 11,11, 9,11,10,11,10, 9,10, 9,10,10,11,11,11,11,
  129836. 9,10, 9,10,11,11,10,11,11,11,11,11,11,10,11,11,
  129837. 10,
  129838. };
  129839. static float _vq_quantthresh__16u1__p9_2[] = {
  129840. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  129841. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  129842. };
  129843. static long _vq_quantmap__16u1__p9_2[] = {
  129844. 15, 13, 11, 9, 7, 5, 3, 1,
  129845. 0, 2, 4, 6, 8, 10, 12, 14,
  129846. 16,
  129847. };
  129848. static encode_aux_threshmatch _vq_auxt__16u1__p9_2 = {
  129849. _vq_quantthresh__16u1__p9_2,
  129850. _vq_quantmap__16u1__p9_2,
  129851. 17,
  129852. 17
  129853. };
  129854. static static_codebook _16u1__p9_2 = {
  129855. 2, 289,
  129856. _vq_lengthlist__16u1__p9_2,
  129857. 1, -529530880, 1611661312, 5, 0,
  129858. _vq_quantlist__16u1__p9_2,
  129859. NULL,
  129860. &_vq_auxt__16u1__p9_2,
  129861. NULL,
  129862. 0
  129863. };
  129864. static long _huff_lengthlist__16u1__short[] = {
  129865. 5, 7,10, 9,11,10,15,11,13,16, 6, 4, 6, 6, 7, 7,
  129866. 10, 9,12,16,10, 6, 5, 6, 6, 7,10,11,16,16, 9, 6,
  129867. 7, 6, 7, 7,10, 8,14,16,11, 6, 5, 4, 5, 6, 8, 9,
  129868. 15,16, 9, 6, 6, 5, 6, 6, 9, 8,14,16,12, 7, 6, 6,
  129869. 5, 6, 6, 7,13,16, 8, 6, 7, 6, 5, 5, 4, 4,11,16,
  129870. 9, 8, 9, 9, 7, 7, 6, 5,13,16,14,14,16,15,16,15,
  129871. 16,16,16,16,
  129872. };
  129873. static static_codebook _huff_book__16u1__short = {
  129874. 2, 100,
  129875. _huff_lengthlist__16u1__short,
  129876. 0, 0, 0, 0, 0,
  129877. NULL,
  129878. NULL,
  129879. NULL,
  129880. NULL,
  129881. 0
  129882. };
  129883. static long _huff_lengthlist__16u2__long[] = {
  129884. 5, 7,10,10,10,11,11,13,18,19, 6, 5, 5, 6, 7, 8,
  129885. 9,12,19,19, 8, 5, 4, 4, 6, 7, 9,13,19,19, 8, 5,
  129886. 4, 4, 5, 6, 8,12,17,19, 7, 5, 5, 4, 4, 5, 7,12,
  129887. 18,18, 8, 7, 7, 6, 5, 5, 6,10,18,18, 9, 9, 9, 8,
  129888. 6, 5, 6, 9,18,18,11,13,13,13, 8, 7, 7, 9,16,18,
  129889. 13,17,18,16,11, 9, 9, 9,17,18,15,18,18,18,15,13,
  129890. 13,14,18,18,
  129891. };
  129892. static static_codebook _huff_book__16u2__long = {
  129893. 2, 100,
  129894. _huff_lengthlist__16u2__long,
  129895. 0, 0, 0, 0, 0,
  129896. NULL,
  129897. NULL,
  129898. NULL,
  129899. NULL,
  129900. 0
  129901. };
  129902. static long _huff_lengthlist__16u2__short[] = {
  129903. 8,11,12,12,14,15,16,16,16,16, 9, 7, 7, 8, 9,11,
  129904. 13,14,16,16,13, 7, 6, 6, 7, 9,12,13,15,16,15, 7,
  129905. 6, 5, 4, 6,10,11,14,16,12, 8, 7, 4, 2, 4, 7,10,
  129906. 14,16,11, 9, 7, 5, 3, 4, 6, 9,14,16,11,10, 9, 7,
  129907. 5, 5, 6, 9,16,16,10,10, 9, 8, 6, 6, 7,10,16,16,
  129908. 11,11,11,10,10,10,11,14,16,16,16,14,14,13,14,16,
  129909. 16,16,16,16,
  129910. };
  129911. static static_codebook _huff_book__16u2__short = {
  129912. 2, 100,
  129913. _huff_lengthlist__16u2__short,
  129914. 0, 0, 0, 0, 0,
  129915. NULL,
  129916. NULL,
  129917. NULL,
  129918. NULL,
  129919. 0
  129920. };
  129921. static long _vq_quantlist__16u2_p1_0[] = {
  129922. 1,
  129923. 0,
  129924. 2,
  129925. };
  129926. static long _vq_lengthlist__16u2_p1_0[] = {
  129927. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  129928. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 8, 9,
  129929. 9, 7, 9, 9, 7, 9, 9, 9,10,10, 9,10,10, 7, 9, 9,
  129930. 9,10,10, 9,10,11, 5, 7, 8, 8, 9, 9, 8, 9, 9, 7,
  129931. 9, 9, 9,10,10, 9, 9,10, 7, 9, 9, 9,10,10, 9,11,
  129932. 10,
  129933. };
  129934. static float _vq_quantthresh__16u2_p1_0[] = {
  129935. -0.5, 0.5,
  129936. };
  129937. static long _vq_quantmap__16u2_p1_0[] = {
  129938. 1, 0, 2,
  129939. };
  129940. static encode_aux_threshmatch _vq_auxt__16u2_p1_0 = {
  129941. _vq_quantthresh__16u2_p1_0,
  129942. _vq_quantmap__16u2_p1_0,
  129943. 3,
  129944. 3
  129945. };
  129946. static static_codebook _16u2_p1_0 = {
  129947. 4, 81,
  129948. _vq_lengthlist__16u2_p1_0,
  129949. 1, -535822336, 1611661312, 2, 0,
  129950. _vq_quantlist__16u2_p1_0,
  129951. NULL,
  129952. &_vq_auxt__16u2_p1_0,
  129953. NULL,
  129954. 0
  129955. };
  129956. static long _vq_quantlist__16u2_p2_0[] = {
  129957. 2,
  129958. 1,
  129959. 3,
  129960. 0,
  129961. 4,
  129962. };
  129963. static long _vq_lengthlist__16u2_p2_0[] = {
  129964. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 9,
  129965. 10, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  129966. 8,10,10, 7, 8, 8,10,10,10,10,10,12,12, 9,10,10,
  129967. 11,12, 5, 7, 7, 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,
  129968. 10, 9,10,10,12,11,10,10,10,12,12, 9,10,10,12,12,
  129969. 10,11,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  129970. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,12,10,10,
  129971. 10,12,12,11,12,12,14,13,12,13,12,14,14, 5, 7, 7,
  129972. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,12,
  129973. 12,10,10,11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  129974. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,12,13, 7,
  129975. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  129976. 10,13,12,10,11,11,13,13, 9,11,10,13,13,10,11,11,
  129977. 13,13,10,11,11,13,13,12,12,13,13,15,12,12,13,14,
  129978. 15, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  129979. 11,13,11,14,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  129980. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  129981. 11,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  129982. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  129983. 11, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,12,
  129984. 11,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  129985. 10,11,12,13,12,13,13,15,14,11,11,13,12,14,10,10,
  129986. 11,13,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  129987. 14,14,12,13,12,14,13, 8,10, 9,12,12, 9,11,10,13,
  129988. 13, 9,10,10,12,13,12,13,13,14,14,12,12,13,14,14,
  129989. 9,11,10,13,13,10,11,11,13,13,10,11,11,13,13,12,
  129990. 13,13,15,15,13,13,13,14,15, 9,10,10,12,13,10,11,
  129991. 10,13,12,10,11,11,13,13,12,13,12,15,14,13,13,13,
  129992. 14,15,11,12,12,15,14,12,12,13,15,15,12,13,13,15,
  129993. 14,14,13,15,14,16,13,14,15,16,16,11,12,12,14,14,
  129994. 11,12,12,15,14,12,13,13,15,15,13,14,13,16,14,14,
  129995. 14,14,16,16, 8, 9, 9,12,12, 9,10,10,13,12, 9,10,
  129996. 10,13,13,12,12,12,14,14,12,12,13,15,15, 9,10,10,
  129997. 13,12,10,11,11,13,13,10,10,11,13,14,12,13,13,15,
  129998. 15,12,12,13,14,15, 9,10,10,13,13,10,11,11,13,13,
  129999. 10,11,11,13,13,12,13,13,14,14,13,14,13,15,14,11,
  130000. 12,12,14,14,12,13,13,15,14,11,12,12,14,15,14,14,
  130001. 14,16,15,13,12,14,14,16,11,12,13,14,15,12,13,13,
  130002. 14,16,12,13,12,15,14,13,15,14,16,16,14,15,13,16,
  130003. 13,
  130004. };
  130005. static float _vq_quantthresh__16u2_p2_0[] = {
  130006. -1.5, -0.5, 0.5, 1.5,
  130007. };
  130008. static long _vq_quantmap__16u2_p2_0[] = {
  130009. 3, 1, 0, 2, 4,
  130010. };
  130011. static encode_aux_threshmatch _vq_auxt__16u2_p2_0 = {
  130012. _vq_quantthresh__16u2_p2_0,
  130013. _vq_quantmap__16u2_p2_0,
  130014. 5,
  130015. 5
  130016. };
  130017. static static_codebook _16u2_p2_0 = {
  130018. 4, 625,
  130019. _vq_lengthlist__16u2_p2_0,
  130020. 1, -533725184, 1611661312, 3, 0,
  130021. _vq_quantlist__16u2_p2_0,
  130022. NULL,
  130023. &_vq_auxt__16u2_p2_0,
  130024. NULL,
  130025. 0
  130026. };
  130027. static long _vq_quantlist__16u2_p3_0[] = {
  130028. 4,
  130029. 3,
  130030. 5,
  130031. 2,
  130032. 6,
  130033. 1,
  130034. 7,
  130035. 0,
  130036. 8,
  130037. };
  130038. static long _vq_lengthlist__16u2_p3_0[] = {
  130039. 2, 4, 4, 6, 6, 7, 7, 9, 9, 4, 5, 5, 6, 6, 8, 7,
  130040. 9, 9, 4, 5, 5, 6, 6, 7, 8, 9, 9, 6, 6, 6, 7, 7,
  130041. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8, 9,10, 7, 8, 7,
  130042. 8, 8, 9, 9,10,10, 7, 8, 8, 8, 8, 9, 9,10,10, 9,
  130043. 9, 9,10, 9,10,10,11,11, 9, 9, 9,10,10,10,10,11,
  130044. 11,
  130045. };
  130046. static float _vq_quantthresh__16u2_p3_0[] = {
  130047. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130048. };
  130049. static long _vq_quantmap__16u2_p3_0[] = {
  130050. 7, 5, 3, 1, 0, 2, 4, 6,
  130051. 8,
  130052. };
  130053. static encode_aux_threshmatch _vq_auxt__16u2_p3_0 = {
  130054. _vq_quantthresh__16u2_p3_0,
  130055. _vq_quantmap__16u2_p3_0,
  130056. 9,
  130057. 9
  130058. };
  130059. static static_codebook _16u2_p3_0 = {
  130060. 2, 81,
  130061. _vq_lengthlist__16u2_p3_0,
  130062. 1, -531628032, 1611661312, 4, 0,
  130063. _vq_quantlist__16u2_p3_0,
  130064. NULL,
  130065. &_vq_auxt__16u2_p3_0,
  130066. NULL,
  130067. 0
  130068. };
  130069. static long _vq_quantlist__16u2_p4_0[] = {
  130070. 8,
  130071. 7,
  130072. 9,
  130073. 6,
  130074. 10,
  130075. 5,
  130076. 11,
  130077. 4,
  130078. 12,
  130079. 3,
  130080. 13,
  130081. 2,
  130082. 14,
  130083. 1,
  130084. 15,
  130085. 0,
  130086. 16,
  130087. };
  130088. static long _vq_lengthlist__16u2_p4_0[] = {
  130089. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,11,
  130090. 11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,11,
  130091. 12,11, 5, 5, 5, 7, 7, 8, 8, 9, 9, 9, 9,10,10,11,
  130092. 11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  130093. 11,11,12,12, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,10,
  130094. 10,11,11,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,
  130095. 11,11,12,12,12,12, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  130096. 10,11,11,11,12,12,12, 9, 9, 9, 9, 9, 9,10,10,10,
  130097. 10,10,11,11,12,12,13,13, 8, 9, 9, 9, 9,10, 9,10,
  130098. 10,10,10,11,11,12,12,13,13, 9, 9, 9, 9, 9,10,10,
  130099. 10,10,11,11,11,12,12,12,13,13, 9, 9, 9, 9, 9,10,
  130100. 10,10,10,11,11,12,11,12,12,13,13,10,10,10,10,10,
  130101. 11,11,11,11,11,12,12,12,12,13,13,14,10,10,10,10,
  130102. 10,11,11,11,11,12,11,12,12,13,12,13,13,11,11,11,
  130103. 11,11,12,12,12,12,12,12,13,13,13,13,14,14,11,11,
  130104. 11,11,11,12,12,12,12,12,12,13,12,13,13,14,14,11,
  130105. 12,12,12,12,12,12,13,13,13,13,13,13,14,14,14,14,
  130106. 11,12,12,12,12,12,12,13,13,13,13,14,13,14,14,14,
  130107. 14,
  130108. };
  130109. static float _vq_quantthresh__16u2_p4_0[] = {
  130110. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130111. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130112. };
  130113. static long _vq_quantmap__16u2_p4_0[] = {
  130114. 15, 13, 11, 9, 7, 5, 3, 1,
  130115. 0, 2, 4, 6, 8, 10, 12, 14,
  130116. 16,
  130117. };
  130118. static encode_aux_threshmatch _vq_auxt__16u2_p4_0 = {
  130119. _vq_quantthresh__16u2_p4_0,
  130120. _vq_quantmap__16u2_p4_0,
  130121. 17,
  130122. 17
  130123. };
  130124. static static_codebook _16u2_p4_0 = {
  130125. 2, 289,
  130126. _vq_lengthlist__16u2_p4_0,
  130127. 1, -529530880, 1611661312, 5, 0,
  130128. _vq_quantlist__16u2_p4_0,
  130129. NULL,
  130130. &_vq_auxt__16u2_p4_0,
  130131. NULL,
  130132. 0
  130133. };
  130134. static long _vq_quantlist__16u2_p5_0[] = {
  130135. 1,
  130136. 0,
  130137. 2,
  130138. };
  130139. static long _vq_lengthlist__16u2_p5_0[] = {
  130140. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10, 9, 7,
  130141. 10, 9, 5, 8, 9, 7, 9,10, 7, 9,10, 4, 9, 9, 9,11,
  130142. 11, 8,11,11, 7,11,11,10,10,13,10,14,13, 7,11,11,
  130143. 10,13,11,10,13,14, 5, 9, 9, 8,11,11, 9,11,11, 7,
  130144. 11,11,10,14,13,10,12,14, 7,11,11,10,13,13,10,13,
  130145. 10,
  130146. };
  130147. static float _vq_quantthresh__16u2_p5_0[] = {
  130148. -5.5, 5.5,
  130149. };
  130150. static long _vq_quantmap__16u2_p5_0[] = {
  130151. 1, 0, 2,
  130152. };
  130153. static encode_aux_threshmatch _vq_auxt__16u2_p5_0 = {
  130154. _vq_quantthresh__16u2_p5_0,
  130155. _vq_quantmap__16u2_p5_0,
  130156. 3,
  130157. 3
  130158. };
  130159. static static_codebook _16u2_p5_0 = {
  130160. 4, 81,
  130161. _vq_lengthlist__16u2_p5_0,
  130162. 1, -529137664, 1618345984, 2, 0,
  130163. _vq_quantlist__16u2_p5_0,
  130164. NULL,
  130165. &_vq_auxt__16u2_p5_0,
  130166. NULL,
  130167. 0
  130168. };
  130169. static long _vq_quantlist__16u2_p5_1[] = {
  130170. 5,
  130171. 4,
  130172. 6,
  130173. 3,
  130174. 7,
  130175. 2,
  130176. 8,
  130177. 1,
  130178. 9,
  130179. 0,
  130180. 10,
  130181. };
  130182. static long _vq_lengthlist__16u2_p5_1[] = {
  130183. 2, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 5, 5, 5, 7, 7,
  130184. 7, 7, 8, 8, 8, 8, 5, 5, 6, 7, 7, 7, 7, 8, 8, 8,
  130185. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  130186. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 9, 9,
  130187. 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  130188. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  130189. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  130190. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  130191. };
  130192. static float _vq_quantthresh__16u2_p5_1[] = {
  130193. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130194. 3.5, 4.5,
  130195. };
  130196. static long _vq_quantmap__16u2_p5_1[] = {
  130197. 9, 7, 5, 3, 1, 0, 2, 4,
  130198. 6, 8, 10,
  130199. };
  130200. static encode_aux_threshmatch _vq_auxt__16u2_p5_1 = {
  130201. _vq_quantthresh__16u2_p5_1,
  130202. _vq_quantmap__16u2_p5_1,
  130203. 11,
  130204. 11
  130205. };
  130206. static static_codebook _16u2_p5_1 = {
  130207. 2, 121,
  130208. _vq_lengthlist__16u2_p5_1,
  130209. 1, -531365888, 1611661312, 4, 0,
  130210. _vq_quantlist__16u2_p5_1,
  130211. NULL,
  130212. &_vq_auxt__16u2_p5_1,
  130213. NULL,
  130214. 0
  130215. };
  130216. static long _vq_quantlist__16u2_p6_0[] = {
  130217. 6,
  130218. 5,
  130219. 7,
  130220. 4,
  130221. 8,
  130222. 3,
  130223. 9,
  130224. 2,
  130225. 10,
  130226. 1,
  130227. 11,
  130228. 0,
  130229. 12,
  130230. };
  130231. static long _vq_lengthlist__16u2_p6_0[] = {
  130232. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6,
  130233. 8, 8, 9, 9, 9, 9,10,10,12,11, 4, 6, 6, 8, 8, 9,
  130234. 9, 9, 9,10,10,11,12, 7, 8, 8, 9, 9,10,10,10,10,
  130235. 12,12,13,12, 7, 8, 8, 9, 9,10,10,10,10,11,12,12,
  130236. 12, 8, 9, 9,10,10,11,11,11,11,12,12,13,13, 8, 9,
  130237. 9,10,10,11,11,11,11,12,13,13,13, 8, 9, 9,10,10,
  130238. 11,11,12,12,13,13,14,14, 8, 9, 9,10,10,11,11,12,
  130239. 12,13,13,14,14, 9,10,10,11,12,13,12,13,14,14,14,
  130240. 14,14, 9,10,10,11,12,12,13,13,13,14,14,14,14,10,
  130241. 11,11,12,12,13,13,14,14,15,15,15,15,10,11,11,12,
  130242. 12,13,13,14,14,14,14,15,15,
  130243. };
  130244. static float _vq_quantthresh__16u2_p6_0[] = {
  130245. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  130246. 12.5, 17.5, 22.5, 27.5,
  130247. };
  130248. static long _vq_quantmap__16u2_p6_0[] = {
  130249. 11, 9, 7, 5, 3, 1, 0, 2,
  130250. 4, 6, 8, 10, 12,
  130251. };
  130252. static encode_aux_threshmatch _vq_auxt__16u2_p6_0 = {
  130253. _vq_quantthresh__16u2_p6_0,
  130254. _vq_quantmap__16u2_p6_0,
  130255. 13,
  130256. 13
  130257. };
  130258. static static_codebook _16u2_p6_0 = {
  130259. 2, 169,
  130260. _vq_lengthlist__16u2_p6_0,
  130261. 1, -526516224, 1616117760, 4, 0,
  130262. _vq_quantlist__16u2_p6_0,
  130263. NULL,
  130264. &_vq_auxt__16u2_p6_0,
  130265. NULL,
  130266. 0
  130267. };
  130268. static long _vq_quantlist__16u2_p6_1[] = {
  130269. 2,
  130270. 1,
  130271. 3,
  130272. 0,
  130273. 4,
  130274. };
  130275. static long _vq_lengthlist__16u2_p6_1[] = {
  130276. 2, 4, 4, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,
  130277. 5, 5, 6, 6, 5, 5, 5, 6, 6,
  130278. };
  130279. static float _vq_quantthresh__16u2_p6_1[] = {
  130280. -1.5, -0.5, 0.5, 1.5,
  130281. };
  130282. static long _vq_quantmap__16u2_p6_1[] = {
  130283. 3, 1, 0, 2, 4,
  130284. };
  130285. static encode_aux_threshmatch _vq_auxt__16u2_p6_1 = {
  130286. _vq_quantthresh__16u2_p6_1,
  130287. _vq_quantmap__16u2_p6_1,
  130288. 5,
  130289. 5
  130290. };
  130291. static static_codebook _16u2_p6_1 = {
  130292. 2, 25,
  130293. _vq_lengthlist__16u2_p6_1,
  130294. 1, -533725184, 1611661312, 3, 0,
  130295. _vq_quantlist__16u2_p6_1,
  130296. NULL,
  130297. &_vq_auxt__16u2_p6_1,
  130298. NULL,
  130299. 0
  130300. };
  130301. static long _vq_quantlist__16u2_p7_0[] = {
  130302. 6,
  130303. 5,
  130304. 7,
  130305. 4,
  130306. 8,
  130307. 3,
  130308. 9,
  130309. 2,
  130310. 10,
  130311. 1,
  130312. 11,
  130313. 0,
  130314. 12,
  130315. };
  130316. static long _vq_lengthlist__16u2_p7_0[] = {
  130317. 1, 4, 4, 7, 7, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 6,
  130318. 9, 9, 9, 9, 9, 9,10,10,11,11, 4, 6, 6, 8, 9, 9,
  130319. 9, 9, 9,10,11,12,11, 7, 8, 9,10,10,10,10,11,10,
  130320. 11,12,12,13, 7, 9, 9,10,10,10,10,10,10,11,12,13,
  130321. 13, 7, 9, 8,10,10,11,11,11,12,12,13,13,14, 7, 9,
  130322. 9,10,10,11,11,11,12,13,13,13,13, 8, 9, 9,10,11,
  130323. 11,12,12,12,13,13,13,13, 8, 9, 9,10,11,11,11,12,
  130324. 12,13,13,14,14, 9,10,10,12,11,12,13,13,13,14,13,
  130325. 13,13, 9,10,10,11,11,12,12,13,14,13,13,14,13,10,
  130326. 11,11,12,13,14,14,14,15,14,14,14,14,10,11,11,12,
  130327. 12,13,13,13,14,14,14,15,14,
  130328. };
  130329. static float _vq_quantthresh__16u2_p7_0[] = {
  130330. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  130331. 27.5, 38.5, 49.5, 60.5,
  130332. };
  130333. static long _vq_quantmap__16u2_p7_0[] = {
  130334. 11, 9, 7, 5, 3, 1, 0, 2,
  130335. 4, 6, 8, 10, 12,
  130336. };
  130337. static encode_aux_threshmatch _vq_auxt__16u2_p7_0 = {
  130338. _vq_quantthresh__16u2_p7_0,
  130339. _vq_quantmap__16u2_p7_0,
  130340. 13,
  130341. 13
  130342. };
  130343. static static_codebook _16u2_p7_0 = {
  130344. 2, 169,
  130345. _vq_lengthlist__16u2_p7_0,
  130346. 1, -523206656, 1618345984, 4, 0,
  130347. _vq_quantlist__16u2_p7_0,
  130348. NULL,
  130349. &_vq_auxt__16u2_p7_0,
  130350. NULL,
  130351. 0
  130352. };
  130353. static long _vq_quantlist__16u2_p7_1[] = {
  130354. 5,
  130355. 4,
  130356. 6,
  130357. 3,
  130358. 7,
  130359. 2,
  130360. 8,
  130361. 1,
  130362. 9,
  130363. 0,
  130364. 10,
  130365. };
  130366. static long _vq_lengthlist__16u2_p7_1[] = {
  130367. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  130368. 7, 7, 7, 7, 8, 8, 5, 6, 6, 6, 6, 7, 7, 7, 7, 8,
  130369. 8, 6, 6, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 7, 7, 7,
  130370. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  130371. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  130372. 8, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8,
  130373. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  130374. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  130375. };
  130376. static float _vq_quantthresh__16u2_p7_1[] = {
  130377. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  130378. 3.5, 4.5,
  130379. };
  130380. static long _vq_quantmap__16u2_p7_1[] = {
  130381. 9, 7, 5, 3, 1, 0, 2, 4,
  130382. 6, 8, 10,
  130383. };
  130384. static encode_aux_threshmatch _vq_auxt__16u2_p7_1 = {
  130385. _vq_quantthresh__16u2_p7_1,
  130386. _vq_quantmap__16u2_p7_1,
  130387. 11,
  130388. 11
  130389. };
  130390. static static_codebook _16u2_p7_1 = {
  130391. 2, 121,
  130392. _vq_lengthlist__16u2_p7_1,
  130393. 1, -531365888, 1611661312, 4, 0,
  130394. _vq_quantlist__16u2_p7_1,
  130395. NULL,
  130396. &_vq_auxt__16u2_p7_1,
  130397. NULL,
  130398. 0
  130399. };
  130400. static long _vq_quantlist__16u2_p8_0[] = {
  130401. 7,
  130402. 6,
  130403. 8,
  130404. 5,
  130405. 9,
  130406. 4,
  130407. 10,
  130408. 3,
  130409. 11,
  130410. 2,
  130411. 12,
  130412. 1,
  130413. 13,
  130414. 0,
  130415. 14,
  130416. };
  130417. static long _vq_lengthlist__16u2_p8_0[] = {
  130418. 1, 5, 5, 7, 7, 8, 8, 7, 7, 8, 8,10, 9,11,11, 4,
  130419. 6, 6, 8, 8,10, 9, 9, 8, 9, 9,10,10,12,14, 4, 6,
  130420. 7, 8, 9, 9,10, 9, 8, 9, 9,10,12,12,11, 7, 8, 8,
  130421. 10,10,10,10, 9, 9,10,10,11,13,13,12, 7, 8, 8, 9,
  130422. 11,11,10, 9, 9,11,10,12,11,11,14, 8, 9, 9,11,10,
  130423. 11,11,10,10,11,11,13,12,14,12, 8, 9, 9,11,12,11,
  130424. 11,10,10,12,11,12,12,12,14, 7, 8, 8, 9, 9,10,10,
  130425. 10,11,12,11,13,13,14,12, 7, 8, 9, 9, 9,10,10,11,
  130426. 11,11,12,12,14,14,14, 8,10, 9,10,11,11,11,11,14,
  130427. 12,12,13,14,14,13, 9, 9, 9,10,11,11,11,12,12,12,
  130428. 14,12,14,13,14,10,10,10,12,11,12,11,14,13,14,13,
  130429. 14,14,13,14, 9,10,10,11,12,11,13,12,13,13,14,14,
  130430. 14,13,14,10,13,13,12,12,11,12,14,13,14,13,14,12,
  130431. 14,13,10,11,11,12,11,12,12,14,14,14,13,14,14,14,
  130432. 14,
  130433. };
  130434. static float _vq_quantthresh__16u2_p8_0[] = {
  130435. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  130436. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  130437. };
  130438. static long _vq_quantmap__16u2_p8_0[] = {
  130439. 13, 11, 9, 7, 5, 3, 1, 0,
  130440. 2, 4, 6, 8, 10, 12, 14,
  130441. };
  130442. static encode_aux_threshmatch _vq_auxt__16u2_p8_0 = {
  130443. _vq_quantthresh__16u2_p8_0,
  130444. _vq_quantmap__16u2_p8_0,
  130445. 15,
  130446. 15
  130447. };
  130448. static static_codebook _16u2_p8_0 = {
  130449. 2, 225,
  130450. _vq_lengthlist__16u2_p8_0,
  130451. 1, -520986624, 1620377600, 4, 0,
  130452. _vq_quantlist__16u2_p8_0,
  130453. NULL,
  130454. &_vq_auxt__16u2_p8_0,
  130455. NULL,
  130456. 0
  130457. };
  130458. static long _vq_quantlist__16u2_p8_1[] = {
  130459. 10,
  130460. 9,
  130461. 11,
  130462. 8,
  130463. 12,
  130464. 7,
  130465. 13,
  130466. 6,
  130467. 14,
  130468. 5,
  130469. 15,
  130470. 4,
  130471. 16,
  130472. 3,
  130473. 17,
  130474. 2,
  130475. 18,
  130476. 1,
  130477. 19,
  130478. 0,
  130479. 20,
  130480. };
  130481. static long _vq_lengthlist__16u2_p8_1[] = {
  130482. 2, 5, 5, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,10, 9, 9,
  130483. 9,10,10,10,10, 5, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,
  130484. 10, 9,10,10,10,10,10,10,11,10, 5, 6, 6, 7, 7, 8,
  130485. 8, 8, 9, 9,10,10,10,10,10,10,10,10,10,10,10, 7,
  130486. 7, 7, 8, 8, 9, 8, 9, 9,10, 9,10,10,10,10,10,10,
  130487. 11,10,11,10, 7, 7, 7, 8, 8, 8, 9, 9, 9,10, 9,10,
  130488. 10,10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9,
  130489. 10, 9,10,10,10,10,10,10,10,11,10,10,11,10, 8, 8,
  130490. 8, 8, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,11,
  130491. 11,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,
  130492. 11,10,11,10,11,10,11,10, 8, 9, 9, 9, 9, 9,10,10,
  130493. 10,10,10,10,10,10,10,10,11,11,10,10,10, 9,10, 9,
  130494. 9,10,10,10,11,10,10,10,10,10,10,10,10,11,11,11,
  130495. 11,11, 9, 9, 9,10, 9,10,10,10,10,10,10,11,10,11,
  130496. 10,11,11,11,11,10,10, 9,10, 9,10,10,10,10,11,10,
  130497. 10,10,10,10,11,10,11,10,11,10,10,11, 9,10,10,10,
  130498. 10,10,10,10,10,10,11,10,10,11,11,10,11,11,11,11,
  130499. 11, 9, 9,10,10,10,10,10,11,10,10,11,10,10,11,10,
  130500. 10,11,11,11,11,11, 9,10,10,10,10,10,10,10,11,10,
  130501. 11,10,11,10,11,11,11,11,11,10,11,10,10,10,10,10,
  130502. 10,10,10,10,11,11,11,11,11,11,11,11,11,10,11,11,
  130503. 10,10,10,10,10,11,10,10,10,11,10,11,11,11,11,10,
  130504. 12,11,11,11,10,10,10,10,10,10,11,10,10,10,11,11,
  130505. 12,11,11,11,11,11,11,11,11,11,10,10,10,11,10,11,
  130506. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  130507. 10,10,11,10,11,10,10,11,11,11,11,11,11,11,11,11,
  130508. 11,11,11,10,10,10,10,10,10,10,11,11,10,11,11,10,
  130509. 11,11,10,11,11,11,10,11,11,
  130510. };
  130511. static float _vq_quantthresh__16u2_p8_1[] = {
  130512. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  130513. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  130514. 6.5, 7.5, 8.5, 9.5,
  130515. };
  130516. static long _vq_quantmap__16u2_p8_1[] = {
  130517. 19, 17, 15, 13, 11, 9, 7, 5,
  130518. 3, 1, 0, 2, 4, 6, 8, 10,
  130519. 12, 14, 16, 18, 20,
  130520. };
  130521. static encode_aux_threshmatch _vq_auxt__16u2_p8_1 = {
  130522. _vq_quantthresh__16u2_p8_1,
  130523. _vq_quantmap__16u2_p8_1,
  130524. 21,
  130525. 21
  130526. };
  130527. static static_codebook _16u2_p8_1 = {
  130528. 2, 441,
  130529. _vq_lengthlist__16u2_p8_1,
  130530. 1, -529268736, 1611661312, 5, 0,
  130531. _vq_quantlist__16u2_p8_1,
  130532. NULL,
  130533. &_vq_auxt__16u2_p8_1,
  130534. NULL,
  130535. 0
  130536. };
  130537. static long _vq_quantlist__16u2_p9_0[] = {
  130538. 5586,
  130539. 4655,
  130540. 6517,
  130541. 3724,
  130542. 7448,
  130543. 2793,
  130544. 8379,
  130545. 1862,
  130546. 9310,
  130547. 931,
  130548. 10241,
  130549. 0,
  130550. 11172,
  130551. 5521,
  130552. 5651,
  130553. };
  130554. static long _vq_lengthlist__16u2_p9_0[] = {
  130555. 1,10,10,10,10,10,10,10,10,10,10,10,10, 5, 4,10,
  130556. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130557. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130558. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130559. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130560. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130561. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130562. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130563. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130564. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130565. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130566. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  130567. 10,10,10, 4,10,10,10,10,10,10,10,10,10,10,10,10,
  130568. 6, 6, 5,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 5,
  130569. 5,
  130570. };
  130571. static float _vq_quantthresh__16u2_p9_0[] = {
  130572. -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -498, -32.5, 32.5,
  130573. 498, 1396.5, 2327.5, 3258.5, 4189.5, 5120.5,
  130574. };
  130575. static long _vq_quantmap__16u2_p9_0[] = {
  130576. 11, 9, 7, 5, 3, 1, 13, 0,
  130577. 14, 2, 4, 6, 8, 10, 12,
  130578. };
  130579. static encode_aux_threshmatch _vq_auxt__16u2_p9_0 = {
  130580. _vq_quantthresh__16u2_p9_0,
  130581. _vq_quantmap__16u2_p9_0,
  130582. 15,
  130583. 15
  130584. };
  130585. static static_codebook _16u2_p9_0 = {
  130586. 2, 225,
  130587. _vq_lengthlist__16u2_p9_0,
  130588. 1, -510275072, 1611661312, 14, 0,
  130589. _vq_quantlist__16u2_p9_0,
  130590. NULL,
  130591. &_vq_auxt__16u2_p9_0,
  130592. NULL,
  130593. 0
  130594. };
  130595. static long _vq_quantlist__16u2_p9_1[] = {
  130596. 392,
  130597. 343,
  130598. 441,
  130599. 294,
  130600. 490,
  130601. 245,
  130602. 539,
  130603. 196,
  130604. 588,
  130605. 147,
  130606. 637,
  130607. 98,
  130608. 686,
  130609. 49,
  130610. 735,
  130611. 0,
  130612. 784,
  130613. 388,
  130614. 396,
  130615. };
  130616. static long _vq_lengthlist__16u2_p9_1[] = {
  130617. 1,12,10,12,10,12,10,12,11,12,12,12,12,12,12,12,
  130618. 12, 5, 5, 9,10,12,11,11,12,12,12,12,12,12,12,12,
  130619. 12,12,12,12,10, 9, 9,11, 9,11,11,12,11,12,12,12,
  130620. 12,12,12,12,12,12,12, 8, 8,10,11, 9,12,11,12,12,
  130621. 12,12,12,12,12,12,12,12,12,12, 9, 8,10,11,12,11,
  130622. 12,11,12,12,12,12,12,12,12,12,12,12,12, 8, 9,11,
  130623. 11,10,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130624. 9,10,11,12,11,12,11,12,12,12,12,12,12,12,12,12,
  130625. 12,12,12, 9, 9,11,12,12,12,12,12,12,12,12,12,12,
  130626. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130627. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130628. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130629. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130630. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  130631. 12,12,12,12,11,11,11,11,11,11,11,11,11,11,11,11,
  130632. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130633. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130634. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130635. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130636. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  130637. 11,11,11, 5, 8, 9, 9, 8,11, 9,11,11,11,11,11,11,
  130638. 11,11,11,11, 5, 5, 4, 8, 8, 8, 8,10, 9,10,10,11,
  130639. 11,11,11,11,11,11,11, 5, 4,
  130640. };
  130641. static float _vq_quantthresh__16u2_p9_1[] = {
  130642. -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5, -26.5,
  130643. -2, 2, 26.5, 73.5, 122.5, 171.5, 220.5, 269.5,
  130644. 318.5, 367.5,
  130645. };
  130646. static long _vq_quantmap__16u2_p9_1[] = {
  130647. 15, 13, 11, 9, 7, 5, 3, 1,
  130648. 17, 0, 18, 2, 4, 6, 8, 10,
  130649. 12, 14, 16,
  130650. };
  130651. static encode_aux_threshmatch _vq_auxt__16u2_p9_1 = {
  130652. _vq_quantthresh__16u2_p9_1,
  130653. _vq_quantmap__16u2_p9_1,
  130654. 19,
  130655. 19
  130656. };
  130657. static static_codebook _16u2_p9_1 = {
  130658. 2, 361,
  130659. _vq_lengthlist__16u2_p9_1,
  130660. 1, -518488064, 1611661312, 10, 0,
  130661. _vq_quantlist__16u2_p9_1,
  130662. NULL,
  130663. &_vq_auxt__16u2_p9_1,
  130664. NULL,
  130665. 0
  130666. };
  130667. static long _vq_quantlist__16u2_p9_2[] = {
  130668. 24,
  130669. 23,
  130670. 25,
  130671. 22,
  130672. 26,
  130673. 21,
  130674. 27,
  130675. 20,
  130676. 28,
  130677. 19,
  130678. 29,
  130679. 18,
  130680. 30,
  130681. 17,
  130682. 31,
  130683. 16,
  130684. 32,
  130685. 15,
  130686. 33,
  130687. 14,
  130688. 34,
  130689. 13,
  130690. 35,
  130691. 12,
  130692. 36,
  130693. 11,
  130694. 37,
  130695. 10,
  130696. 38,
  130697. 9,
  130698. 39,
  130699. 8,
  130700. 40,
  130701. 7,
  130702. 41,
  130703. 6,
  130704. 42,
  130705. 5,
  130706. 43,
  130707. 4,
  130708. 44,
  130709. 3,
  130710. 45,
  130711. 2,
  130712. 46,
  130713. 1,
  130714. 47,
  130715. 0,
  130716. 48,
  130717. };
  130718. static long _vq_lengthlist__16u2_p9_2[] = {
  130719. 1, 3, 3, 4, 7, 7, 7, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  130720. 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 9, 9, 8, 9, 9,
  130721. 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,12,12,10,
  130722. 11,
  130723. };
  130724. static float _vq_quantthresh__16u2_p9_2[] = {
  130725. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  130726. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  130727. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  130728. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  130729. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  130730. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  130731. };
  130732. static long _vq_quantmap__16u2_p9_2[] = {
  130733. 47, 45, 43, 41, 39, 37, 35, 33,
  130734. 31, 29, 27, 25, 23, 21, 19, 17,
  130735. 15, 13, 11, 9, 7, 5, 3, 1,
  130736. 0, 2, 4, 6, 8, 10, 12, 14,
  130737. 16, 18, 20, 22, 24, 26, 28, 30,
  130738. 32, 34, 36, 38, 40, 42, 44, 46,
  130739. 48,
  130740. };
  130741. static encode_aux_threshmatch _vq_auxt__16u2_p9_2 = {
  130742. _vq_quantthresh__16u2_p9_2,
  130743. _vq_quantmap__16u2_p9_2,
  130744. 49,
  130745. 49
  130746. };
  130747. static static_codebook _16u2_p9_2 = {
  130748. 1, 49,
  130749. _vq_lengthlist__16u2_p9_2,
  130750. 1, -526909440, 1611661312, 6, 0,
  130751. _vq_quantlist__16u2_p9_2,
  130752. NULL,
  130753. &_vq_auxt__16u2_p9_2,
  130754. NULL,
  130755. 0
  130756. };
  130757. static long _vq_quantlist__8u0__p1_0[] = {
  130758. 1,
  130759. 0,
  130760. 2,
  130761. };
  130762. static long _vq_lengthlist__8u0__p1_0[] = {
  130763. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  130764. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 4, 9, 8, 8,11,
  130765. 11, 8,11,11, 7,11,11,10,11,13,10,13,13, 7,11,11,
  130766. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 8,11,11, 7,
  130767. 11,11, 9,13,13,10,12,13, 7,11,11,10,13,13,10,13,
  130768. 11,
  130769. };
  130770. static float _vq_quantthresh__8u0__p1_0[] = {
  130771. -0.5, 0.5,
  130772. };
  130773. static long _vq_quantmap__8u0__p1_0[] = {
  130774. 1, 0, 2,
  130775. };
  130776. static encode_aux_threshmatch _vq_auxt__8u0__p1_0 = {
  130777. _vq_quantthresh__8u0__p1_0,
  130778. _vq_quantmap__8u0__p1_0,
  130779. 3,
  130780. 3
  130781. };
  130782. static static_codebook _8u0__p1_0 = {
  130783. 4, 81,
  130784. _vq_lengthlist__8u0__p1_0,
  130785. 1, -535822336, 1611661312, 2, 0,
  130786. _vq_quantlist__8u0__p1_0,
  130787. NULL,
  130788. &_vq_auxt__8u0__p1_0,
  130789. NULL,
  130790. 0
  130791. };
  130792. static long _vq_quantlist__8u0__p2_0[] = {
  130793. 1,
  130794. 0,
  130795. 2,
  130796. };
  130797. static long _vq_lengthlist__8u0__p2_0[] = {
  130798. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 6, 7, 8, 6,
  130799. 7, 8, 5, 7, 7, 6, 8, 8, 7, 9, 7, 5, 7, 7, 7, 9,
  130800. 9, 7, 8, 8, 6, 9, 8, 7, 7,10, 8,10,10, 6, 8, 8,
  130801. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  130802. 8, 8, 8,10,10, 8, 8,10, 6, 8, 9, 8,10,10, 7,10,
  130803. 8,
  130804. };
  130805. static float _vq_quantthresh__8u0__p2_0[] = {
  130806. -0.5, 0.5,
  130807. };
  130808. static long _vq_quantmap__8u0__p2_0[] = {
  130809. 1, 0, 2,
  130810. };
  130811. static encode_aux_threshmatch _vq_auxt__8u0__p2_0 = {
  130812. _vq_quantthresh__8u0__p2_0,
  130813. _vq_quantmap__8u0__p2_0,
  130814. 3,
  130815. 3
  130816. };
  130817. static static_codebook _8u0__p2_0 = {
  130818. 4, 81,
  130819. _vq_lengthlist__8u0__p2_0,
  130820. 1, -535822336, 1611661312, 2, 0,
  130821. _vq_quantlist__8u0__p2_0,
  130822. NULL,
  130823. &_vq_auxt__8u0__p2_0,
  130824. NULL,
  130825. 0
  130826. };
  130827. static long _vq_quantlist__8u0__p3_0[] = {
  130828. 2,
  130829. 1,
  130830. 3,
  130831. 0,
  130832. 4,
  130833. };
  130834. static long _vq_lengthlist__8u0__p3_0[] = {
  130835. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  130836. 10, 9,11,11, 8, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  130837. 10,11,11, 8,10,10,11,11,10,11,11,12,12,10,11,11,
  130838. 12,13, 6, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  130839. 11, 9,10,11,12,12,10,11,11,12,12, 8,11,11,14,13,
  130840. 10,12,11,15,13,10,12,11,14,14,12,13,12,16,14,12,
  130841. 14,12,16,15, 8,11,11,13,14,10,11,12,13,15,10,11,
  130842. 12,13,15,11,12,13,14,15,12,12,14,14,16, 5, 8, 8,
  130843. 11,11, 9,11,11,12,12, 8,10,11,12,12,11,12,12,15,
  130844. 14,11,12,12,14,14, 7,11,10,13,12,10,11,12,13,14,
  130845. 10,12,12,14,13,12,13,13,14,15,12,13,13,15,15, 7,
  130846. 10,11,12,13,10,12,11,14,13,10,12,13,13,15,12,13,
  130847. 12,14,14,11,13,13,15,16, 9,12,12,15,14,11,13,13,
  130848. 15,16,11,13,13,16,16,13,14,15,15,15,12,14,15,17,
  130849. 16, 9,12,12,14,15,11,13,13,15,16,11,13,13,16,18,
  130850. 13,14,14,17,16,13,15,15,17,18, 5, 8, 9,11,11, 8,
  130851. 11,11,12,12, 8,10,11,12,12,11,12,12,14,14,11,12,
  130852. 12,14,15, 7,11,10,12,13,10,12,12,14,13,10,11,12,
  130853. 13,14,11,13,13,15,14,12,13,13,14,15, 7,10,11,13,
  130854. 13,10,12,12,13,14,10,12,12,13,13,11,13,13,16,16,
  130855. 12,13,13,15,14, 9,12,12,16,15,10,13,13,15,15,11,
  130856. 13,13,17,15,12,15,15,18,17,13,14,14,15,16, 9,12,
  130857. 12,15,15,11,13,13,15,16,11,13,13,15,15,12,15,15,
  130858. 16,16,13,15,14,17,15, 7,11,11,15,15,10,13,13,16,
  130859. 15,10,13,13,15,16,14,15,15,17,19,13,15,14,15,18,
  130860. 9,12,12,16,16,11,13,14,17,16,11,13,13,17,16,15,
  130861. 15,16,17,19,13,15,16, 0,18, 9,12,12,16,15,11,14,
  130862. 13,17,17,11,13,14,16,16,15,16,16,19,18,13,15,15,
  130863. 17,19,11,14,14,19,16,12,14,15, 0,18,12,16,15,18,
  130864. 17,15,15,18,16,19,14,15,17,19,19,11,14,14,18,19,
  130865. 13,15,14,19,19,12,16,15,18,17,15,17,15, 0,16,14,
  130866. 17,16,19, 0, 7,11,11,14,14,10,12,12,15,15,10,13,
  130867. 13,16,15,13,15,15,17, 0,14,15,15,16,19, 9,12,12,
  130868. 16,16,11,14,14,16,16,11,13,13,16,16,14,17,16,19,
  130869. 0,14,18,17,17,19, 9,12,12,15,16,11,13,13,15,17,
  130870. 12,14,13,19,16,13,15,15,17,19,15,17,16,17,19,11,
  130871. 14,14,19,16,12,15,15,19,17,13,14,15,17,19,14,16,
  130872. 17,19,19,16,15,16,17,19,11,15,14,16,16,12,15,15,
  130873. 19, 0,12,14,15,19,19,14,16,16, 0,18,15,19,14,18,
  130874. 16,
  130875. };
  130876. static float _vq_quantthresh__8u0__p3_0[] = {
  130877. -1.5, -0.5, 0.5, 1.5,
  130878. };
  130879. static long _vq_quantmap__8u0__p3_0[] = {
  130880. 3, 1, 0, 2, 4,
  130881. };
  130882. static encode_aux_threshmatch _vq_auxt__8u0__p3_0 = {
  130883. _vq_quantthresh__8u0__p3_0,
  130884. _vq_quantmap__8u0__p3_0,
  130885. 5,
  130886. 5
  130887. };
  130888. static static_codebook _8u0__p3_0 = {
  130889. 4, 625,
  130890. _vq_lengthlist__8u0__p3_0,
  130891. 1, -533725184, 1611661312, 3, 0,
  130892. _vq_quantlist__8u0__p3_0,
  130893. NULL,
  130894. &_vq_auxt__8u0__p3_0,
  130895. NULL,
  130896. 0
  130897. };
  130898. static long _vq_quantlist__8u0__p4_0[] = {
  130899. 2,
  130900. 1,
  130901. 3,
  130902. 0,
  130903. 4,
  130904. };
  130905. static long _vq_lengthlist__8u0__p4_0[] = {
  130906. 3, 5, 5, 8, 8, 5, 6, 7, 9, 9, 6, 7, 6, 9, 9, 9,
  130907. 9, 9,10,11, 9, 9, 9,11,10, 6, 7, 7,10,10, 7, 7,
  130908. 8,10,10, 7, 8, 8,10,10,10,10,10,10,11, 9,10,10,
  130909. 11,12, 6, 7, 7,10,10, 7, 8, 8,10,10, 7, 8, 7,10,
  130910. 10, 9,10,10,12,11,10,10,10,11,10, 9,10,10,12,11,
  130911. 10,10,10,13,11, 9,10,10,12,12,11,11,12,12,13,11,
  130912. 11,11,12,13, 9,10,10,12,12,10,10,11,12,12,10,10,
  130913. 11,12,12,11,11,11,13,13,11,12,12,13,13, 5, 7, 7,
  130914. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,11,12,
  130915. 12,10,11,10,12,12, 7, 8, 8,11,11, 7, 8, 9,10,11,
  130916. 8, 9, 9,11,11,11,10,11,10,12,10,11,11,12,13, 7,
  130917. 8, 8,10,11, 8, 9, 8,12,10, 8, 9, 9,11,12,10,11,
  130918. 10,13,11,10,11,11,13,12, 9,11,10,13,12,10,10,11,
  130919. 12,12,10,11,11,13,13,12,10,13,11,14,11,12,12,15,
  130920. 13, 9,11,11,13,13,10,11,11,13,12,10,11,11,12,14,
  130921. 12,13,11,14,12,12,12,12,14,14, 5, 7, 7,10,10, 7,
  130922. 8, 8,10,10, 7, 8, 8,11,10,10,11,11,12,12,10,11,
  130923. 10,12,12, 7, 8, 8,10,11, 8, 9, 9,12,11, 8, 8, 9,
  130924. 10,11,10,11,11,12,13,11,10,11,11,13, 6, 8, 8,10,
  130925. 11, 8, 9, 9,11,11, 7, 9, 7,11,10,10,11,11,12,12,
  130926. 10,11,10,13,10, 9,11,10,13,12,10,12,11,13,13,10,
  130927. 10,11,12,13,11,12,13,15,14,11,11,13,12,13, 9,10,
  130928. 11,12,13,10,11,11,12,13,10,11,10,13,12,12,13,13,
  130929. 13,14,12,12,11,14,11, 8,10,10,12,13,10,11,11,13,
  130930. 13,10,11,10,13,13,12,13,14,15,14,12,12,12,14,13,
  130931. 9,10,10,13,12,10,10,12,13,13,10,11,11,15,12,12,
  130932. 12,13,15,14,12,13,13,15,13, 9,10,11,12,13,10,12,
  130933. 10,13,12,10,11,11,12,13,12,14,12,15,13,12,12,12,
  130934. 15,14,11,12,11,14,13,11,11,12,14,14,12,13,13,14,
  130935. 13,13,11,15,11,15,14,14,14,16,15,11,12,12,13,14,
  130936. 11,13,11,14,14,12,12,13,14,15,12,14,12,15,12,13,
  130937. 15,14,16,15, 8,10,10,12,12,10,10,10,12,13,10,11,
  130938. 11,13,13,12,12,12,13,14,13,13,13,15,15, 9,10,10,
  130939. 12,12,10,11,11,13,12,10,10,11,13,13,12,12,12,14,
  130940. 14,12,12,13,15,14, 9,10,10,13,12,10,10,12,12,13,
  130941. 10,11,10,13,13,12,13,13,14,14,12,13,12,14,13,11,
  130942. 12,12,14,13,12,13,12,14,14,10,12,12,14,14,14,14,
  130943. 14,16,14,13,12,14,12,15,10,12,12,14,15,12,13,13,
  130944. 14,16,11,12,11,15,14,13,14,14,14,15,13,14,11,14,
  130945. 12,
  130946. };
  130947. static float _vq_quantthresh__8u0__p4_0[] = {
  130948. -1.5, -0.5, 0.5, 1.5,
  130949. };
  130950. static long _vq_quantmap__8u0__p4_0[] = {
  130951. 3, 1, 0, 2, 4,
  130952. };
  130953. static encode_aux_threshmatch _vq_auxt__8u0__p4_0 = {
  130954. _vq_quantthresh__8u0__p4_0,
  130955. _vq_quantmap__8u0__p4_0,
  130956. 5,
  130957. 5
  130958. };
  130959. static static_codebook _8u0__p4_0 = {
  130960. 4, 625,
  130961. _vq_lengthlist__8u0__p4_0,
  130962. 1, -533725184, 1611661312, 3, 0,
  130963. _vq_quantlist__8u0__p4_0,
  130964. NULL,
  130965. &_vq_auxt__8u0__p4_0,
  130966. NULL,
  130967. 0
  130968. };
  130969. static long _vq_quantlist__8u0__p5_0[] = {
  130970. 4,
  130971. 3,
  130972. 5,
  130973. 2,
  130974. 6,
  130975. 1,
  130976. 7,
  130977. 0,
  130978. 8,
  130979. };
  130980. static long _vq_lengthlist__8u0__p5_0[] = {
  130981. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 7, 8, 8,
  130982. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 6, 8, 8, 9, 9,
  130983. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 7, 8, 8,
  130984. 9, 9,10,10,12,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  130985. 10,10,11,11,11,12,12,12, 9,10,10,11,11,12,12,12,
  130986. 12,
  130987. };
  130988. static float _vq_quantthresh__8u0__p5_0[] = {
  130989. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  130990. };
  130991. static long _vq_quantmap__8u0__p5_0[] = {
  130992. 7, 5, 3, 1, 0, 2, 4, 6,
  130993. 8,
  130994. };
  130995. static encode_aux_threshmatch _vq_auxt__8u0__p5_0 = {
  130996. _vq_quantthresh__8u0__p5_0,
  130997. _vq_quantmap__8u0__p5_0,
  130998. 9,
  130999. 9
  131000. };
  131001. static static_codebook _8u0__p5_0 = {
  131002. 2, 81,
  131003. _vq_lengthlist__8u0__p5_0,
  131004. 1, -531628032, 1611661312, 4, 0,
  131005. _vq_quantlist__8u0__p5_0,
  131006. NULL,
  131007. &_vq_auxt__8u0__p5_0,
  131008. NULL,
  131009. 0
  131010. };
  131011. static long _vq_quantlist__8u0__p6_0[] = {
  131012. 6,
  131013. 5,
  131014. 7,
  131015. 4,
  131016. 8,
  131017. 3,
  131018. 9,
  131019. 2,
  131020. 10,
  131021. 1,
  131022. 11,
  131023. 0,
  131024. 12,
  131025. };
  131026. static long _vq_lengthlist__8u0__p6_0[] = {
  131027. 1, 4, 4, 7, 7, 9, 9,11,11,12,12,16,16, 3, 6, 6,
  131028. 9, 9,11,11,12,12,13,14,18,16, 3, 6, 7, 9, 9,11,
  131029. 11,13,12,14,14,17,16, 7, 9, 9,11,11,12,12,14,14,
  131030. 14,14,17,16, 7, 9, 9,11,11,13,12,13,13,14,14,17,
  131031. 0, 9,11,11,12,13,14,14,14,13,15,14,17,17, 9,11,
  131032. 11,12,12,14,14,13,14,14,15, 0, 0,11,12,12,15,14,
  131033. 15,14,15,14,15,16,17, 0,11,12,13,13,13,14,14,15,
  131034. 14,15,15, 0, 0,12,14,14,15,15,14,16,15,15,17,16,
  131035. 0,18,13,14,14,15,14,15,14,15,16,17,16, 0, 0,17,
  131036. 17,18, 0,16,18,16, 0, 0, 0,17, 0, 0,16, 0, 0,16,
  131037. 16, 0,15, 0,17, 0, 0, 0, 0,
  131038. };
  131039. static float _vq_quantthresh__8u0__p6_0[] = {
  131040. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  131041. 12.5, 17.5, 22.5, 27.5,
  131042. };
  131043. static long _vq_quantmap__8u0__p6_0[] = {
  131044. 11, 9, 7, 5, 3, 1, 0, 2,
  131045. 4, 6, 8, 10, 12,
  131046. };
  131047. static encode_aux_threshmatch _vq_auxt__8u0__p6_0 = {
  131048. _vq_quantthresh__8u0__p6_0,
  131049. _vq_quantmap__8u0__p6_0,
  131050. 13,
  131051. 13
  131052. };
  131053. static static_codebook _8u0__p6_0 = {
  131054. 2, 169,
  131055. _vq_lengthlist__8u0__p6_0,
  131056. 1, -526516224, 1616117760, 4, 0,
  131057. _vq_quantlist__8u0__p6_0,
  131058. NULL,
  131059. &_vq_auxt__8u0__p6_0,
  131060. NULL,
  131061. 0
  131062. };
  131063. static long _vq_quantlist__8u0__p6_1[] = {
  131064. 2,
  131065. 1,
  131066. 3,
  131067. 0,
  131068. 4,
  131069. };
  131070. static long _vq_lengthlist__8u0__p6_1[] = {
  131071. 1, 4, 4, 6, 6, 4, 6, 5, 7, 7, 4, 5, 6, 7, 7, 6,
  131072. 7, 7, 7, 7, 6, 7, 7, 7, 7,
  131073. };
  131074. static float _vq_quantthresh__8u0__p6_1[] = {
  131075. -1.5, -0.5, 0.5, 1.5,
  131076. };
  131077. static long _vq_quantmap__8u0__p6_1[] = {
  131078. 3, 1, 0, 2, 4,
  131079. };
  131080. static encode_aux_threshmatch _vq_auxt__8u0__p6_1 = {
  131081. _vq_quantthresh__8u0__p6_1,
  131082. _vq_quantmap__8u0__p6_1,
  131083. 5,
  131084. 5
  131085. };
  131086. static static_codebook _8u0__p6_1 = {
  131087. 2, 25,
  131088. _vq_lengthlist__8u0__p6_1,
  131089. 1, -533725184, 1611661312, 3, 0,
  131090. _vq_quantlist__8u0__p6_1,
  131091. NULL,
  131092. &_vq_auxt__8u0__p6_1,
  131093. NULL,
  131094. 0
  131095. };
  131096. static long _vq_quantlist__8u0__p7_0[] = {
  131097. 1,
  131098. 0,
  131099. 2,
  131100. };
  131101. static long _vq_lengthlist__8u0__p7_0[] = {
  131102. 1, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131103. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131104. 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131105. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131106. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  131107. 7,
  131108. };
  131109. static float _vq_quantthresh__8u0__p7_0[] = {
  131110. -157.5, 157.5,
  131111. };
  131112. static long _vq_quantmap__8u0__p7_0[] = {
  131113. 1, 0, 2,
  131114. };
  131115. static encode_aux_threshmatch _vq_auxt__8u0__p7_0 = {
  131116. _vq_quantthresh__8u0__p7_0,
  131117. _vq_quantmap__8u0__p7_0,
  131118. 3,
  131119. 3
  131120. };
  131121. static static_codebook _8u0__p7_0 = {
  131122. 4, 81,
  131123. _vq_lengthlist__8u0__p7_0,
  131124. 1, -518803456, 1628680192, 2, 0,
  131125. _vq_quantlist__8u0__p7_0,
  131126. NULL,
  131127. &_vq_auxt__8u0__p7_0,
  131128. NULL,
  131129. 0
  131130. };
  131131. static long _vq_quantlist__8u0__p7_1[] = {
  131132. 7,
  131133. 6,
  131134. 8,
  131135. 5,
  131136. 9,
  131137. 4,
  131138. 10,
  131139. 3,
  131140. 11,
  131141. 2,
  131142. 12,
  131143. 1,
  131144. 13,
  131145. 0,
  131146. 14,
  131147. };
  131148. static long _vq_lengthlist__8u0__p7_1[] = {
  131149. 1, 5, 5, 5, 5,10,10,11,11,11,11,11,11,11,11, 5,
  131150. 7, 6, 8, 8, 9,10,11,11,11,11,11,11,11,11, 6, 6,
  131151. 7, 9, 7,11,10,11,11,11,11,11,11,11,11, 5, 6, 6,
  131152. 11, 8,11,11,11,11,11,11,11,11,11,11, 5, 6, 6, 9,
  131153. 10,11,10,11,11,11,11,11,11,11,11, 7,10,10,11,11,
  131154. 11,11,11,11,11,11,11,11,11,11, 7,11, 8,11,11,11,
  131155. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131156. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131157. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131158. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131159. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131160. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131161. 11,11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,
  131162. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131163. 10,
  131164. };
  131165. static float _vq_quantthresh__8u0__p7_1[] = {
  131166. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  131167. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  131168. };
  131169. static long _vq_quantmap__8u0__p7_1[] = {
  131170. 13, 11, 9, 7, 5, 3, 1, 0,
  131171. 2, 4, 6, 8, 10, 12, 14,
  131172. };
  131173. static encode_aux_threshmatch _vq_auxt__8u0__p7_1 = {
  131174. _vq_quantthresh__8u0__p7_1,
  131175. _vq_quantmap__8u0__p7_1,
  131176. 15,
  131177. 15
  131178. };
  131179. static static_codebook _8u0__p7_1 = {
  131180. 2, 225,
  131181. _vq_lengthlist__8u0__p7_1,
  131182. 1, -520986624, 1620377600, 4, 0,
  131183. _vq_quantlist__8u0__p7_1,
  131184. NULL,
  131185. &_vq_auxt__8u0__p7_1,
  131186. NULL,
  131187. 0
  131188. };
  131189. static long _vq_quantlist__8u0__p7_2[] = {
  131190. 10,
  131191. 9,
  131192. 11,
  131193. 8,
  131194. 12,
  131195. 7,
  131196. 13,
  131197. 6,
  131198. 14,
  131199. 5,
  131200. 15,
  131201. 4,
  131202. 16,
  131203. 3,
  131204. 17,
  131205. 2,
  131206. 18,
  131207. 1,
  131208. 19,
  131209. 0,
  131210. 20,
  131211. };
  131212. static long _vq_lengthlist__8u0__p7_2[] = {
  131213. 1, 6, 5, 7, 7, 9, 9, 9, 9,10,12,12,10,11,11,10,
  131214. 11,11,11,10,11, 6, 8, 8, 9, 9,10,10, 9,10,11,11,
  131215. 10,11,11,11,11,10,11,11,11,11, 6, 7, 8, 9, 9, 9,
  131216. 10,11,10,11,12,11,10,11,11,11,11,11,11,12,10, 8,
  131217. 9, 9,10, 9,10,10, 9,10,10,10,10,10, 9,10,10,10,
  131218. 10, 9,10,10, 9, 9, 9, 9,10,10, 9, 9,10,10,11,10,
  131219. 9,12,10,11,10, 9,10,10,10, 8, 9, 9,10, 9,10, 9,
  131220. 9,10,10, 9,10, 9,11,10,10,10,10,10, 9,10, 8, 8,
  131221. 9, 9,10, 9,11, 9, 8, 9, 9,10,11,10,10,10,11,12,
  131222. 9, 9,11, 8, 9, 8,11,10,11,10,10, 9,11,10,10,10,
  131223. 10,10,10,10,11,11,11,11, 8, 9, 9, 9,10,10,10,11,
  131224. 11,12,11,12,11,10,10,10,12,11,11,11,10, 8,10, 9,
  131225. 11,10,10,11,12,10,11,12,11,11,12,11,12,12,10,11,
  131226. 11,10, 9, 9,10,11,12,10,10,10,11,10,11,11,10,12,
  131227. 12,10,11,10,11,12,10, 9,10,10,11,10,11,11,11,11,
  131228. 11,12,11,11,11, 9,11,10,11,10,11,10, 9, 9,10,11,
  131229. 11,11,10,10,11,12,12,11,12,11,11,11,12,12,12,12,
  131230. 11, 9,11,11,12,10,11,11,11,11,11,11,12,11,11,12,
  131231. 11,11,11,10,11,11, 9,11,10,11,11,11,10,10,10,11,
  131232. 11,11,12,10,11,10,11,11,11,11,12, 9,11,10,11,11,
  131233. 10,10,11,11, 9,11,11,12,10,10,10,10,10,11,11,10,
  131234. 9,10,11,11,12,11,10,10,12,11,11,12,11,12,11,11,
  131235. 10,10,11,11,10,12,11,10,11,10,11,10,10,10,11,11,
  131236. 10,10,11,11,11,11,10,10,10,12,11,11,11,11,10, 9,
  131237. 10,11,11,11,12,11,11,11,12,10,11,11,11, 9,10,11,
  131238. 11,11,11,11,11,10,10,11,11,12,11,10,11,12,11,10,
  131239. 10,11, 9,10,11,11,11,11,11,10,11,11,10,12,11,11,
  131240. 11,12,11,11,11,10,10,11,11,
  131241. };
  131242. static float _vq_quantthresh__8u0__p7_2[] = {
  131243. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  131244. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  131245. 6.5, 7.5, 8.5, 9.5,
  131246. };
  131247. static long _vq_quantmap__8u0__p7_2[] = {
  131248. 19, 17, 15, 13, 11, 9, 7, 5,
  131249. 3, 1, 0, 2, 4, 6, 8, 10,
  131250. 12, 14, 16, 18, 20,
  131251. };
  131252. static encode_aux_threshmatch _vq_auxt__8u0__p7_2 = {
  131253. _vq_quantthresh__8u0__p7_2,
  131254. _vq_quantmap__8u0__p7_2,
  131255. 21,
  131256. 21
  131257. };
  131258. static static_codebook _8u0__p7_2 = {
  131259. 2, 441,
  131260. _vq_lengthlist__8u0__p7_2,
  131261. 1, -529268736, 1611661312, 5, 0,
  131262. _vq_quantlist__8u0__p7_2,
  131263. NULL,
  131264. &_vq_auxt__8u0__p7_2,
  131265. NULL,
  131266. 0
  131267. };
  131268. static long _huff_lengthlist__8u0__single[] = {
  131269. 4, 7,11, 9,12, 8, 7,10, 6, 4, 5, 5, 7, 5, 6,16,
  131270. 9, 5, 5, 6, 7, 7, 9,16, 7, 4, 6, 5, 7, 5, 7,17,
  131271. 10, 7, 7, 8, 7, 7, 8,18, 7, 5, 6, 4, 5, 4, 5,15,
  131272. 7, 6, 7, 5, 6, 4, 5,15,12,13,18,12,17,11, 9,17,
  131273. };
  131274. static static_codebook _huff_book__8u0__single = {
  131275. 2, 64,
  131276. _huff_lengthlist__8u0__single,
  131277. 0, 0, 0, 0, 0,
  131278. NULL,
  131279. NULL,
  131280. NULL,
  131281. NULL,
  131282. 0
  131283. };
  131284. static long _vq_quantlist__8u1__p1_0[] = {
  131285. 1,
  131286. 0,
  131287. 2,
  131288. };
  131289. static long _vq_lengthlist__8u1__p1_0[] = {
  131290. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 7, 9,10, 7,
  131291. 9, 9, 5, 8, 8, 7,10, 9, 7, 9, 9, 5, 8, 8, 8,10,
  131292. 10, 8,10,10, 7,10,10, 9,10,12,10,12,12, 7,10,10,
  131293. 9,12,11,10,12,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  131294. 10,10,10,12,12, 9,11,12, 7,10,10,10,12,12, 9,12,
  131295. 10,
  131296. };
  131297. static float _vq_quantthresh__8u1__p1_0[] = {
  131298. -0.5, 0.5,
  131299. };
  131300. static long _vq_quantmap__8u1__p1_0[] = {
  131301. 1, 0, 2,
  131302. };
  131303. static encode_aux_threshmatch _vq_auxt__8u1__p1_0 = {
  131304. _vq_quantthresh__8u1__p1_0,
  131305. _vq_quantmap__8u1__p1_0,
  131306. 3,
  131307. 3
  131308. };
  131309. static static_codebook _8u1__p1_0 = {
  131310. 4, 81,
  131311. _vq_lengthlist__8u1__p1_0,
  131312. 1, -535822336, 1611661312, 2, 0,
  131313. _vq_quantlist__8u1__p1_0,
  131314. NULL,
  131315. &_vq_auxt__8u1__p1_0,
  131316. NULL,
  131317. 0
  131318. };
  131319. static long _vq_quantlist__8u1__p2_0[] = {
  131320. 1,
  131321. 0,
  131322. 2,
  131323. };
  131324. static long _vq_lengthlist__8u1__p2_0[] = {
  131325. 3, 4, 5, 5, 6, 6, 5, 6, 6, 5, 7, 6, 6, 7, 8, 6,
  131326. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 7, 5, 6, 6, 7, 8,
  131327. 8, 6, 7, 7, 6, 8, 7, 7, 7, 9, 8, 9, 9, 6, 7, 8,
  131328. 7, 9, 7, 8, 9, 9, 5, 6, 6, 6, 7, 7, 7, 8, 8, 6,
  131329. 8, 7, 8, 9, 9, 7, 7, 9, 6, 7, 8, 8, 9, 9, 7, 9,
  131330. 7,
  131331. };
  131332. static float _vq_quantthresh__8u1__p2_0[] = {
  131333. -0.5, 0.5,
  131334. };
  131335. static long _vq_quantmap__8u1__p2_0[] = {
  131336. 1, 0, 2,
  131337. };
  131338. static encode_aux_threshmatch _vq_auxt__8u1__p2_0 = {
  131339. _vq_quantthresh__8u1__p2_0,
  131340. _vq_quantmap__8u1__p2_0,
  131341. 3,
  131342. 3
  131343. };
  131344. static static_codebook _8u1__p2_0 = {
  131345. 4, 81,
  131346. _vq_lengthlist__8u1__p2_0,
  131347. 1, -535822336, 1611661312, 2, 0,
  131348. _vq_quantlist__8u1__p2_0,
  131349. NULL,
  131350. &_vq_auxt__8u1__p2_0,
  131351. NULL,
  131352. 0
  131353. };
  131354. static long _vq_quantlist__8u1__p3_0[] = {
  131355. 2,
  131356. 1,
  131357. 3,
  131358. 0,
  131359. 4,
  131360. };
  131361. static long _vq_lengthlist__8u1__p3_0[] = {
  131362. 1, 5, 5, 7, 7, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  131363. 10, 9,11,11, 9, 9, 9,11,11, 6, 8, 8,10,10, 8,10,
  131364. 10,11,11, 8, 9,10,11,11,10,11,11,12,12,10,11,11,
  131365. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10, 9,11,
  131366. 11,10,11,11,12,12,10,11,11,12,12, 9,11,11,14,13,
  131367. 10,12,11,14,14,10,12,11,14,13,12,13,13,15,14,12,
  131368. 13,13,15,14, 8,11,11,13,14,10,11,12,13,15,10,11,
  131369. 12,14,14,12,13,13,14,15,12,13,13,14,15, 5, 8, 8,
  131370. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  131371. 13,11,12,12,13,14, 8,10,10,12,12, 9,11,12,13,14,
  131372. 10,12,12,13,13,12,12,13,14,14,11,13,13,15,15, 7,
  131373. 10,10,12,12, 9,12,11,14,12,10,11,12,13,14,12,13,
  131374. 12,14,14,12,13,13,15,16,10,12,12,15,14,11,12,13,
  131375. 15,15,11,13,13,15,16,14,14,15,15,16,13,14,15,17,
  131376. 15, 9,12,12,14,15,11,13,12,15,15,11,13,13,15,15,
  131377. 13,14,13,15,14,13,14,14,17, 0, 5, 8, 8,11,11, 8,
  131378. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  131379. 12,14,14, 7,10,10,12,12,10,12,12,13,13, 9,11,12,
  131380. 12,13,11,12,13,15,15,11,12,13,14,15, 8,10,10,12,
  131381. 12,10,12,11,13,13,10,12,11,13,13,11,13,13,15,14,
  131382. 12,13,12,15,13, 9,12,12,14,14,11,13,13,16,15,11,
  131383. 12,13,16,15,13,14,15,16,16,13,13,15,15,16,10,12,
  131384. 12,15,14,11,13,13,14,16,11,13,13,15,16,13,15,15,
  131385. 16,17,13,15,14,16,15, 8,11,11,14,15,10,12,12,15,
  131386. 15,10,12,12,15,16,14,15,15,16,17,13,14,14,16,16,
  131387. 9,12,12,15,15,11,13,14,15,17,11,13,13,15,16,14,
  131388. 15,16,19,17,13,15,15, 0,17, 9,12,12,15,15,11,14,
  131389. 13,16,15,11,13,13,15,16,15,15,15,18,17,13,15,15,
  131390. 17,17,11,15,14,18,16,12,14,15,17,17,12,15,15,18,
  131391. 18,15,15,16,15,19,14,16,16, 0, 0,11,14,14,16,17,
  131392. 12,15,14,18,17,12,15,15,18,18,15,17,15,18,16,14,
  131393. 16,16,18,18, 7,11,11,14,14,10,12,12,15,15,10,12,
  131394. 13,15,15,13,14,15,16,16,14,15,15,18,18, 9,12,12,
  131395. 15,15,11,13,13,16,15,11,12,13,16,16,14,15,15,17,
  131396. 16,15,16,16,17,17, 9,12,12,15,15,11,13,13,15,17,
  131397. 11,14,13,16,15,13,15,15,17,17,15,15,15,18,17,11,
  131398. 14,14,17,15,12,14,15,17,18,13,13,15,17,17,14,16,
  131399. 16,19,18,16,15,17,17, 0,11,14,14,17,17,12,15,15,
  131400. 18, 0,12,15,14,18,16,14,17,17,19, 0,16,18,15, 0,
  131401. 16,
  131402. };
  131403. static float _vq_quantthresh__8u1__p3_0[] = {
  131404. -1.5, -0.5, 0.5, 1.5,
  131405. };
  131406. static long _vq_quantmap__8u1__p3_0[] = {
  131407. 3, 1, 0, 2, 4,
  131408. };
  131409. static encode_aux_threshmatch _vq_auxt__8u1__p3_0 = {
  131410. _vq_quantthresh__8u1__p3_0,
  131411. _vq_quantmap__8u1__p3_0,
  131412. 5,
  131413. 5
  131414. };
  131415. static static_codebook _8u1__p3_0 = {
  131416. 4, 625,
  131417. _vq_lengthlist__8u1__p3_0,
  131418. 1, -533725184, 1611661312, 3, 0,
  131419. _vq_quantlist__8u1__p3_0,
  131420. NULL,
  131421. &_vq_auxt__8u1__p3_0,
  131422. NULL,
  131423. 0
  131424. };
  131425. static long _vq_quantlist__8u1__p4_0[] = {
  131426. 2,
  131427. 1,
  131428. 3,
  131429. 0,
  131430. 4,
  131431. };
  131432. static long _vq_lengthlist__8u1__p4_0[] = {
  131433. 4, 5, 5, 9, 9, 6, 7, 7, 9, 9, 6, 7, 7, 9, 9, 9,
  131434. 9, 9,11,11, 9, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 7,
  131435. 8, 9,10, 7, 7, 8, 9,10, 9, 9,10,10,11, 9, 9,10,
  131436. 10,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 7,10,
  131437. 9, 9,10, 9,12,11,10,10, 9,12,10, 9,10,10,12,11,
  131438. 9,10,10,12,11, 9,10,10,12,12,11,11,12,12,13,11,
  131439. 11,12,12,13, 9, 9,10,12,11, 9,10,10,12,12,10,10,
  131440. 10,12,12,11,12,11,13,12,11,12,11,13,12, 6, 7, 7,
  131441. 9, 9, 7, 8, 8,10,10, 7, 8, 7,10, 9,10,10,10,12,
  131442. 12,10,10,10,12,11, 7, 8, 7,10,10, 7, 7, 9,10,11,
  131443. 8, 9, 9,11,10,10,10,11,10,12,10,10,11,12,12, 7,
  131444. 8, 8,10,10, 7, 9, 8,11,10, 8, 8, 9,11,11,10,11,
  131445. 10,12,11,10,11,11,12,12, 9,10,10,12,12, 9,10,10,
  131446. 12,12,10,11,11,13,12,11,10,12,10,14,12,12,12,13,
  131447. 14, 9,10,10,12,12, 9,11,10,12,12,10,11,11,12,12,
  131448. 11,12,11,14,12,12,12,12,14,14, 5, 7, 7, 9, 9, 7,
  131449. 7, 7, 9,10, 7, 8, 8,10,10,10,10,10,11,11,10,10,
  131450. 10,12,12, 7, 8, 8,10,10, 8, 9, 8,11,10, 7, 8, 9,
  131451. 10,11,10,10,10,11,12,10,10,11,11,13, 6, 7, 8,10,
  131452. 10, 8, 9, 9,10,10, 7, 9, 7,11,10,10,11,10,12,12,
  131453. 10,11,10,12,10, 9,10,10,12,12,10,11,11,13,12, 9,
  131454. 10,10,12,12,12,12,12,14,13,11,11,12,11,14, 9,10,
  131455. 10,11,12,10,11,11,12,13, 9,10,10,12,12,12,12,12,
  131456. 14,13,11,12,10,14,11, 9, 9,10,11,12, 9,10,10,12,
  131457. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,13,12,
  131458. 9,10, 9,12,12, 9,10,11,12,13,10,11,10,13,11,12,
  131459. 12,13,13,14,12,12,12,13,13, 9,10,10,12,12,10,11,
  131460. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,12,
  131461. 13,14,11,12,11,14,13,10,10,11,13,13,12,12,12,14,
  131462. 13,12,10,14,10,15,13,14,14,14,14,11,11,12,13,14,
  131463. 10,12,11,13,13,12,12,12,13,15,12,13,11,15,12,13,
  131464. 13,14,14,14, 9,10, 9,12,12, 9,10,10,12,12,10,10,
  131465. 10,12,12,11,11,12,12,13,12,12,12,14,14, 9,10,10,
  131466. 12,12,10,11,10,13,12,10,10,11,12,13,12,12,12,14,
  131467. 13,12,12,13,13,14, 9,10,10,12,13,10,10,11,11,12,
  131468. 9,11,10,13,12,12,12,12,13,14,12,13,12,14,13,11,
  131469. 12,11,13,13,12,13,12,14,13,10,11,12,13,13,13,13,
  131470. 13,14,15,12,11,14,12,14,11,11,12,12,13,12,12,12,
  131471. 13,14,10,12,10,14,13,13,13,13,14,15,12,14,11,15,
  131472. 10,
  131473. };
  131474. static float _vq_quantthresh__8u1__p4_0[] = {
  131475. -1.5, -0.5, 0.5, 1.5,
  131476. };
  131477. static long _vq_quantmap__8u1__p4_0[] = {
  131478. 3, 1, 0, 2, 4,
  131479. };
  131480. static encode_aux_threshmatch _vq_auxt__8u1__p4_0 = {
  131481. _vq_quantthresh__8u1__p4_0,
  131482. _vq_quantmap__8u1__p4_0,
  131483. 5,
  131484. 5
  131485. };
  131486. static static_codebook _8u1__p4_0 = {
  131487. 4, 625,
  131488. _vq_lengthlist__8u1__p4_0,
  131489. 1, -533725184, 1611661312, 3, 0,
  131490. _vq_quantlist__8u1__p4_0,
  131491. NULL,
  131492. &_vq_auxt__8u1__p4_0,
  131493. NULL,
  131494. 0
  131495. };
  131496. static long _vq_quantlist__8u1__p5_0[] = {
  131497. 4,
  131498. 3,
  131499. 5,
  131500. 2,
  131501. 6,
  131502. 1,
  131503. 7,
  131504. 0,
  131505. 8,
  131506. };
  131507. static long _vq_lengthlist__8u1__p5_0[] = {
  131508. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  131509. 10,10, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  131510. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  131511. 9, 9,10,10,12,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  131512. 10,10,11,11,11,11,13,12, 9,10,10,11,11,12,12,12,
  131513. 13,
  131514. };
  131515. static float _vq_quantthresh__8u1__p5_0[] = {
  131516. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131517. };
  131518. static long _vq_quantmap__8u1__p5_0[] = {
  131519. 7, 5, 3, 1, 0, 2, 4, 6,
  131520. 8,
  131521. };
  131522. static encode_aux_threshmatch _vq_auxt__8u1__p5_0 = {
  131523. _vq_quantthresh__8u1__p5_0,
  131524. _vq_quantmap__8u1__p5_0,
  131525. 9,
  131526. 9
  131527. };
  131528. static static_codebook _8u1__p5_0 = {
  131529. 2, 81,
  131530. _vq_lengthlist__8u1__p5_0,
  131531. 1, -531628032, 1611661312, 4, 0,
  131532. _vq_quantlist__8u1__p5_0,
  131533. NULL,
  131534. &_vq_auxt__8u1__p5_0,
  131535. NULL,
  131536. 0
  131537. };
  131538. static long _vq_quantlist__8u1__p6_0[] = {
  131539. 4,
  131540. 3,
  131541. 5,
  131542. 2,
  131543. 6,
  131544. 1,
  131545. 7,
  131546. 0,
  131547. 8,
  131548. };
  131549. static long _vq_lengthlist__8u1__p6_0[] = {
  131550. 3, 4, 4, 6, 6, 7, 7, 9, 9, 4, 4, 5, 6, 6, 7, 7,
  131551. 9, 9, 4, 4, 4, 6, 6, 7, 7, 9, 9, 6, 6, 6, 7, 7,
  131552. 8, 8, 9, 9, 6, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  131553. 8, 8, 8, 9,10,10, 7, 7, 7, 8, 8, 9, 8,10,10, 9,
  131554. 9, 9, 9, 9,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131555. 10,
  131556. };
  131557. static float _vq_quantthresh__8u1__p6_0[] = {
  131558. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  131559. };
  131560. static long _vq_quantmap__8u1__p6_0[] = {
  131561. 7, 5, 3, 1, 0, 2, 4, 6,
  131562. 8,
  131563. };
  131564. static encode_aux_threshmatch _vq_auxt__8u1__p6_0 = {
  131565. _vq_quantthresh__8u1__p6_0,
  131566. _vq_quantmap__8u1__p6_0,
  131567. 9,
  131568. 9
  131569. };
  131570. static static_codebook _8u1__p6_0 = {
  131571. 2, 81,
  131572. _vq_lengthlist__8u1__p6_0,
  131573. 1, -531628032, 1611661312, 4, 0,
  131574. _vq_quantlist__8u1__p6_0,
  131575. NULL,
  131576. &_vq_auxt__8u1__p6_0,
  131577. NULL,
  131578. 0
  131579. };
  131580. static long _vq_quantlist__8u1__p7_0[] = {
  131581. 1,
  131582. 0,
  131583. 2,
  131584. };
  131585. static long _vq_lengthlist__8u1__p7_0[] = {
  131586. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,10,10, 8,
  131587. 10,10, 5, 9, 9, 7,10,10, 8,10,10, 4,10,10, 9,12,
  131588. 12, 9,11,11, 7,12,11,10,11,13,10,13,13, 7,12,12,
  131589. 10,13,12,10,13,13, 4,10,10, 9,12,12, 9,12,12, 7,
  131590. 12,12,10,13,13,10,12,13, 7,11,12,10,13,13,10,13,
  131591. 11,
  131592. };
  131593. static float _vq_quantthresh__8u1__p7_0[] = {
  131594. -5.5, 5.5,
  131595. };
  131596. static long _vq_quantmap__8u1__p7_0[] = {
  131597. 1, 0, 2,
  131598. };
  131599. static encode_aux_threshmatch _vq_auxt__8u1__p7_0 = {
  131600. _vq_quantthresh__8u1__p7_0,
  131601. _vq_quantmap__8u1__p7_0,
  131602. 3,
  131603. 3
  131604. };
  131605. static static_codebook _8u1__p7_0 = {
  131606. 4, 81,
  131607. _vq_lengthlist__8u1__p7_0,
  131608. 1, -529137664, 1618345984, 2, 0,
  131609. _vq_quantlist__8u1__p7_0,
  131610. NULL,
  131611. &_vq_auxt__8u1__p7_0,
  131612. NULL,
  131613. 0
  131614. };
  131615. static long _vq_quantlist__8u1__p7_1[] = {
  131616. 5,
  131617. 4,
  131618. 6,
  131619. 3,
  131620. 7,
  131621. 2,
  131622. 8,
  131623. 1,
  131624. 9,
  131625. 0,
  131626. 10,
  131627. };
  131628. static long _vq_lengthlist__8u1__p7_1[] = {
  131629. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  131630. 8, 8, 9, 9, 9, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 9,
  131631. 9, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  131632. 8, 8, 8, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131633. 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  131634. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  131635. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  131636. 9, 9, 9, 9, 9,10,10,10,10,
  131637. };
  131638. static float _vq_quantthresh__8u1__p7_1[] = {
  131639. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131640. 3.5, 4.5,
  131641. };
  131642. static long _vq_quantmap__8u1__p7_1[] = {
  131643. 9, 7, 5, 3, 1, 0, 2, 4,
  131644. 6, 8, 10,
  131645. };
  131646. static encode_aux_threshmatch _vq_auxt__8u1__p7_1 = {
  131647. _vq_quantthresh__8u1__p7_1,
  131648. _vq_quantmap__8u1__p7_1,
  131649. 11,
  131650. 11
  131651. };
  131652. static static_codebook _8u1__p7_1 = {
  131653. 2, 121,
  131654. _vq_lengthlist__8u1__p7_1,
  131655. 1, -531365888, 1611661312, 4, 0,
  131656. _vq_quantlist__8u1__p7_1,
  131657. NULL,
  131658. &_vq_auxt__8u1__p7_1,
  131659. NULL,
  131660. 0
  131661. };
  131662. static long _vq_quantlist__8u1__p8_0[] = {
  131663. 5,
  131664. 4,
  131665. 6,
  131666. 3,
  131667. 7,
  131668. 2,
  131669. 8,
  131670. 1,
  131671. 9,
  131672. 0,
  131673. 10,
  131674. };
  131675. static long _vq_lengthlist__8u1__p8_0[] = {
  131676. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  131677. 9, 9,11,11,13,12, 4, 6, 6, 7, 7, 9, 9,11,11,12,
  131678. 12, 6, 7, 7, 9, 9,11,11,12,12,13,13, 6, 7, 7, 9,
  131679. 9,11,11,12,12,13,13, 8, 9, 9,11,11,12,12,13,13,
  131680. 14,14, 8, 9, 9,11,11,12,12,13,13,14,14, 9,11,11,
  131681. 12,12,13,13,14,14,15,15, 9,11,11,12,12,13,13,14,
  131682. 14,15,14,11,12,12,13,13,14,14,15,15,16,16,11,12,
  131683. 12,13,13,14,14,15,15,15,15,
  131684. };
  131685. static float _vq_quantthresh__8u1__p8_0[] = {
  131686. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  131687. 38.5, 49.5,
  131688. };
  131689. static long _vq_quantmap__8u1__p8_0[] = {
  131690. 9, 7, 5, 3, 1, 0, 2, 4,
  131691. 6, 8, 10,
  131692. };
  131693. static encode_aux_threshmatch _vq_auxt__8u1__p8_0 = {
  131694. _vq_quantthresh__8u1__p8_0,
  131695. _vq_quantmap__8u1__p8_0,
  131696. 11,
  131697. 11
  131698. };
  131699. static static_codebook _8u1__p8_0 = {
  131700. 2, 121,
  131701. _vq_lengthlist__8u1__p8_0,
  131702. 1, -524582912, 1618345984, 4, 0,
  131703. _vq_quantlist__8u1__p8_0,
  131704. NULL,
  131705. &_vq_auxt__8u1__p8_0,
  131706. NULL,
  131707. 0
  131708. };
  131709. static long _vq_quantlist__8u1__p8_1[] = {
  131710. 5,
  131711. 4,
  131712. 6,
  131713. 3,
  131714. 7,
  131715. 2,
  131716. 8,
  131717. 1,
  131718. 9,
  131719. 0,
  131720. 10,
  131721. };
  131722. static long _vq_lengthlist__8u1__p8_1[] = {
  131723. 2, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 6, 6, 7, 7,
  131724. 7, 7, 8, 8, 8, 8, 5, 6, 6, 7, 7, 7, 7, 8, 8, 8,
  131725. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  131726. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  131727. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  131728. 8, 8, 8, 8, 9, 8, 9, 9, 7, 8, 8, 8, 8, 8, 8, 9,
  131729. 8, 9, 9, 8, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8,
  131730. 8, 8, 8, 8, 8, 9, 9, 9, 9,
  131731. };
  131732. static float _vq_quantthresh__8u1__p8_1[] = {
  131733. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  131734. 3.5, 4.5,
  131735. };
  131736. static long _vq_quantmap__8u1__p8_1[] = {
  131737. 9, 7, 5, 3, 1, 0, 2, 4,
  131738. 6, 8, 10,
  131739. };
  131740. static encode_aux_threshmatch _vq_auxt__8u1__p8_1 = {
  131741. _vq_quantthresh__8u1__p8_1,
  131742. _vq_quantmap__8u1__p8_1,
  131743. 11,
  131744. 11
  131745. };
  131746. static static_codebook _8u1__p8_1 = {
  131747. 2, 121,
  131748. _vq_lengthlist__8u1__p8_1,
  131749. 1, -531365888, 1611661312, 4, 0,
  131750. _vq_quantlist__8u1__p8_1,
  131751. NULL,
  131752. &_vq_auxt__8u1__p8_1,
  131753. NULL,
  131754. 0
  131755. };
  131756. static long _vq_quantlist__8u1__p9_0[] = {
  131757. 7,
  131758. 6,
  131759. 8,
  131760. 5,
  131761. 9,
  131762. 4,
  131763. 10,
  131764. 3,
  131765. 11,
  131766. 2,
  131767. 12,
  131768. 1,
  131769. 13,
  131770. 0,
  131771. 14,
  131772. };
  131773. static long _vq_lengthlist__8u1__p9_0[] = {
  131774. 1, 4, 4,11,11,11,11,11,11,11,11,11,11,11,11, 3,
  131775. 11, 8,11,11,11,11,11,11,11,11,11,11,11,11, 3, 9,
  131776. 9,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131777. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131778. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131779. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131780. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131781. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131782. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131783. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131784. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131785. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  131786. 11,11,11,11,11,11,11,11,11,11,10,10,10,10,10,10,
  131787. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131788. 10,
  131789. };
  131790. static float _vq_quantthresh__8u1__p9_0[] = {
  131791. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  131792. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  131793. };
  131794. static long _vq_quantmap__8u1__p9_0[] = {
  131795. 13, 11, 9, 7, 5, 3, 1, 0,
  131796. 2, 4, 6, 8, 10, 12, 14,
  131797. };
  131798. static encode_aux_threshmatch _vq_auxt__8u1__p9_0 = {
  131799. _vq_quantthresh__8u1__p9_0,
  131800. _vq_quantmap__8u1__p9_0,
  131801. 15,
  131802. 15
  131803. };
  131804. static static_codebook _8u1__p9_0 = {
  131805. 2, 225,
  131806. _vq_lengthlist__8u1__p9_0,
  131807. 1, -514071552, 1627381760, 4, 0,
  131808. _vq_quantlist__8u1__p9_0,
  131809. NULL,
  131810. &_vq_auxt__8u1__p9_0,
  131811. NULL,
  131812. 0
  131813. };
  131814. static long _vq_quantlist__8u1__p9_1[] = {
  131815. 7,
  131816. 6,
  131817. 8,
  131818. 5,
  131819. 9,
  131820. 4,
  131821. 10,
  131822. 3,
  131823. 11,
  131824. 2,
  131825. 12,
  131826. 1,
  131827. 13,
  131828. 0,
  131829. 14,
  131830. };
  131831. static long _vq_lengthlist__8u1__p9_1[] = {
  131832. 1, 4, 4, 7, 7, 9, 9, 7, 7, 8, 8,10,10,11,11, 4,
  131833. 7, 7, 9, 9,10,10, 8, 8,10,10,10,11,10,11, 4, 7,
  131834. 7, 9, 9,10,10, 8, 8,10, 9,11,11,11,11, 7, 9, 9,
  131835. 12,12,11,12,10,10,11,10,12,11,11,11, 7, 9, 9,11,
  131836. 11,13,12, 9, 9,11,10,11,11,12,11, 9,10,10,12,12,
  131837. 14,14,10,10,11,12,12,11,11,11, 9,10,11,11,13,14,
  131838. 13,10,11,11,11,12,11,12,12, 7, 8, 8,10, 9,11,10,
  131839. 11,12,12,11,12,14,12,13, 7, 8, 8, 9,10,10,11,12,
  131840. 12,12,11,12,12,12,13, 9, 9, 9,11,11,13,12,12,12,
  131841. 12,11,12,12,13,12, 8,10,10,11,10,11,12,12,12,12,
  131842. 12,12,14,12,12, 9,11,11,11,12,12,12,12,13,13,12,
  131843. 12,13,13,12,10,11,11,12,11,12,12,12,11,12,13,12,
  131844. 12,12,13,11,11,12,12,12,13,12,12,11,12,13,13,12,
  131845. 12,13,12,11,12,12,13,13,12,13,12,13,13,13,13,14,
  131846. 13,
  131847. };
  131848. static float _vq_quantthresh__8u1__p9_1[] = {
  131849. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  131850. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  131851. };
  131852. static long _vq_quantmap__8u1__p9_1[] = {
  131853. 13, 11, 9, 7, 5, 3, 1, 0,
  131854. 2, 4, 6, 8, 10, 12, 14,
  131855. };
  131856. static encode_aux_threshmatch _vq_auxt__8u1__p9_1 = {
  131857. _vq_quantthresh__8u1__p9_1,
  131858. _vq_quantmap__8u1__p9_1,
  131859. 15,
  131860. 15
  131861. };
  131862. static static_codebook _8u1__p9_1 = {
  131863. 2, 225,
  131864. _vq_lengthlist__8u1__p9_1,
  131865. 1, -522338304, 1620115456, 4, 0,
  131866. _vq_quantlist__8u1__p9_1,
  131867. NULL,
  131868. &_vq_auxt__8u1__p9_1,
  131869. NULL,
  131870. 0
  131871. };
  131872. static long _vq_quantlist__8u1__p9_2[] = {
  131873. 8,
  131874. 7,
  131875. 9,
  131876. 6,
  131877. 10,
  131878. 5,
  131879. 11,
  131880. 4,
  131881. 12,
  131882. 3,
  131883. 13,
  131884. 2,
  131885. 14,
  131886. 1,
  131887. 15,
  131888. 0,
  131889. 16,
  131890. };
  131891. static long _vq_lengthlist__8u1__p9_2[] = {
  131892. 2, 5, 4, 6, 6, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131893. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  131894. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  131895. 9, 9, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  131896. 9,10,10, 9, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131897. 9, 9, 9,10,10, 8, 8, 8, 9, 9, 9, 9,10,10,10, 9,
  131898. 10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  131899. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,
  131900. 10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,10,
  131901. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  131902. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  131903. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  131904. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  131905. 9,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  131906. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,10,
  131907. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  131908. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131909. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  131910. 10,
  131911. };
  131912. static float _vq_quantthresh__8u1__p9_2[] = {
  131913. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  131914. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  131915. };
  131916. static long _vq_quantmap__8u1__p9_2[] = {
  131917. 15, 13, 11, 9, 7, 5, 3, 1,
  131918. 0, 2, 4, 6, 8, 10, 12, 14,
  131919. 16,
  131920. };
  131921. static encode_aux_threshmatch _vq_auxt__8u1__p9_2 = {
  131922. _vq_quantthresh__8u1__p9_2,
  131923. _vq_quantmap__8u1__p9_2,
  131924. 17,
  131925. 17
  131926. };
  131927. static static_codebook _8u1__p9_2 = {
  131928. 2, 289,
  131929. _vq_lengthlist__8u1__p9_2,
  131930. 1, -529530880, 1611661312, 5, 0,
  131931. _vq_quantlist__8u1__p9_2,
  131932. NULL,
  131933. &_vq_auxt__8u1__p9_2,
  131934. NULL,
  131935. 0
  131936. };
  131937. static long _huff_lengthlist__8u1__single[] = {
  131938. 4, 7,13, 9,15, 9,16, 8,10,13, 7, 5, 8, 6, 9, 7,
  131939. 10, 7,10,11,11, 6, 7, 8, 8, 9, 9, 9,12,16, 8, 5,
  131940. 8, 6, 8, 6, 9, 7,10,12,11, 7, 7, 7, 6, 7, 7, 7,
  131941. 11,15, 7, 5, 8, 6, 7, 5, 7, 6, 9,13,13, 9, 9, 8,
  131942. 6, 6, 5, 5, 9,14, 8, 6, 8, 6, 6, 4, 5, 3, 5,13,
  131943. 9, 9,11, 8,10, 7, 8, 4, 5,12,11,16,17,15,17,12,
  131944. 13, 8, 8,15,
  131945. };
  131946. static static_codebook _huff_book__8u1__single = {
  131947. 2, 100,
  131948. _huff_lengthlist__8u1__single,
  131949. 0, 0, 0, 0, 0,
  131950. NULL,
  131951. NULL,
  131952. NULL,
  131953. NULL,
  131954. 0
  131955. };
  131956. static long _huff_lengthlist__44u0__long[] = {
  131957. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  131958. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  131959. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  131960. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  131961. };
  131962. static static_codebook _huff_book__44u0__long = {
  131963. 2, 64,
  131964. _huff_lengthlist__44u0__long,
  131965. 0, 0, 0, 0, 0,
  131966. NULL,
  131967. NULL,
  131968. NULL,
  131969. NULL,
  131970. 0
  131971. };
  131972. static long _vq_quantlist__44u0__p1_0[] = {
  131973. 1,
  131974. 0,
  131975. 2,
  131976. };
  131977. static long _vq_lengthlist__44u0__p1_0[] = {
  131978. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  131979. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  131980. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  131981. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  131982. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  131983. 13,
  131984. };
  131985. static float _vq_quantthresh__44u0__p1_0[] = {
  131986. -0.5, 0.5,
  131987. };
  131988. static long _vq_quantmap__44u0__p1_0[] = {
  131989. 1, 0, 2,
  131990. };
  131991. static encode_aux_threshmatch _vq_auxt__44u0__p1_0 = {
  131992. _vq_quantthresh__44u0__p1_0,
  131993. _vq_quantmap__44u0__p1_0,
  131994. 3,
  131995. 3
  131996. };
  131997. static static_codebook _44u0__p1_0 = {
  131998. 4, 81,
  131999. _vq_lengthlist__44u0__p1_0,
  132000. 1, -535822336, 1611661312, 2, 0,
  132001. _vq_quantlist__44u0__p1_0,
  132002. NULL,
  132003. &_vq_auxt__44u0__p1_0,
  132004. NULL,
  132005. 0
  132006. };
  132007. static long _vq_quantlist__44u0__p2_0[] = {
  132008. 1,
  132009. 0,
  132010. 2,
  132011. };
  132012. static long _vq_lengthlist__44u0__p2_0[] = {
  132013. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132014. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132015. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132016. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132017. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132018. 9,
  132019. };
  132020. static float _vq_quantthresh__44u0__p2_0[] = {
  132021. -0.5, 0.5,
  132022. };
  132023. static long _vq_quantmap__44u0__p2_0[] = {
  132024. 1, 0, 2,
  132025. };
  132026. static encode_aux_threshmatch _vq_auxt__44u0__p2_0 = {
  132027. _vq_quantthresh__44u0__p2_0,
  132028. _vq_quantmap__44u0__p2_0,
  132029. 3,
  132030. 3
  132031. };
  132032. static static_codebook _44u0__p2_0 = {
  132033. 4, 81,
  132034. _vq_lengthlist__44u0__p2_0,
  132035. 1, -535822336, 1611661312, 2, 0,
  132036. _vq_quantlist__44u0__p2_0,
  132037. NULL,
  132038. &_vq_auxt__44u0__p2_0,
  132039. NULL,
  132040. 0
  132041. };
  132042. static long _vq_quantlist__44u0__p3_0[] = {
  132043. 2,
  132044. 1,
  132045. 3,
  132046. 0,
  132047. 4,
  132048. };
  132049. static long _vq_lengthlist__44u0__p3_0[] = {
  132050. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132051. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132052. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132053. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132054. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132055. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132056. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132057. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132058. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132059. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132060. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132061. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132062. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132063. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132064. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132065. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132066. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132067. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132068. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132069. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132070. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132071. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132072. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132073. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132074. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132075. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132076. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132077. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132078. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132079. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132080. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132081. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132082. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132083. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132084. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132085. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132086. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132087. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132088. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132089. 19,
  132090. };
  132091. static float _vq_quantthresh__44u0__p3_0[] = {
  132092. -1.5, -0.5, 0.5, 1.5,
  132093. };
  132094. static long _vq_quantmap__44u0__p3_0[] = {
  132095. 3, 1, 0, 2, 4,
  132096. };
  132097. static encode_aux_threshmatch _vq_auxt__44u0__p3_0 = {
  132098. _vq_quantthresh__44u0__p3_0,
  132099. _vq_quantmap__44u0__p3_0,
  132100. 5,
  132101. 5
  132102. };
  132103. static static_codebook _44u0__p3_0 = {
  132104. 4, 625,
  132105. _vq_lengthlist__44u0__p3_0,
  132106. 1, -533725184, 1611661312, 3, 0,
  132107. _vq_quantlist__44u0__p3_0,
  132108. NULL,
  132109. &_vq_auxt__44u0__p3_0,
  132110. NULL,
  132111. 0
  132112. };
  132113. static long _vq_quantlist__44u0__p4_0[] = {
  132114. 2,
  132115. 1,
  132116. 3,
  132117. 0,
  132118. 4,
  132119. };
  132120. static long _vq_lengthlist__44u0__p4_0[] = {
  132121. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132122. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132123. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132124. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132125. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132126. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132127. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132128. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132129. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132130. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132131. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132132. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132133. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132134. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132135. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132136. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132137. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132138. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132139. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132140. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132141. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132142. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132143. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132144. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132145. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132146. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132147. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132148. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132149. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132150. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132151. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132152. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132153. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132154. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132155. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132156. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132157. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132158. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132159. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132160. 12,
  132161. };
  132162. static float _vq_quantthresh__44u0__p4_0[] = {
  132163. -1.5, -0.5, 0.5, 1.5,
  132164. };
  132165. static long _vq_quantmap__44u0__p4_0[] = {
  132166. 3, 1, 0, 2, 4,
  132167. };
  132168. static encode_aux_threshmatch _vq_auxt__44u0__p4_0 = {
  132169. _vq_quantthresh__44u0__p4_0,
  132170. _vq_quantmap__44u0__p4_0,
  132171. 5,
  132172. 5
  132173. };
  132174. static static_codebook _44u0__p4_0 = {
  132175. 4, 625,
  132176. _vq_lengthlist__44u0__p4_0,
  132177. 1, -533725184, 1611661312, 3, 0,
  132178. _vq_quantlist__44u0__p4_0,
  132179. NULL,
  132180. &_vq_auxt__44u0__p4_0,
  132181. NULL,
  132182. 0
  132183. };
  132184. static long _vq_quantlist__44u0__p5_0[] = {
  132185. 4,
  132186. 3,
  132187. 5,
  132188. 2,
  132189. 6,
  132190. 1,
  132191. 7,
  132192. 0,
  132193. 8,
  132194. };
  132195. static long _vq_lengthlist__44u0__p5_0[] = {
  132196. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132197. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132198. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132199. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132200. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132201. 12,
  132202. };
  132203. static float _vq_quantthresh__44u0__p5_0[] = {
  132204. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132205. };
  132206. static long _vq_quantmap__44u0__p5_0[] = {
  132207. 7, 5, 3, 1, 0, 2, 4, 6,
  132208. 8,
  132209. };
  132210. static encode_aux_threshmatch _vq_auxt__44u0__p5_0 = {
  132211. _vq_quantthresh__44u0__p5_0,
  132212. _vq_quantmap__44u0__p5_0,
  132213. 9,
  132214. 9
  132215. };
  132216. static static_codebook _44u0__p5_0 = {
  132217. 2, 81,
  132218. _vq_lengthlist__44u0__p5_0,
  132219. 1, -531628032, 1611661312, 4, 0,
  132220. _vq_quantlist__44u0__p5_0,
  132221. NULL,
  132222. &_vq_auxt__44u0__p5_0,
  132223. NULL,
  132224. 0
  132225. };
  132226. static long _vq_quantlist__44u0__p6_0[] = {
  132227. 6,
  132228. 5,
  132229. 7,
  132230. 4,
  132231. 8,
  132232. 3,
  132233. 9,
  132234. 2,
  132235. 10,
  132236. 1,
  132237. 11,
  132238. 0,
  132239. 12,
  132240. };
  132241. static long _vq_lengthlist__44u0__p6_0[] = {
  132242. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132243. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132244. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132245. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132246. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132247. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132248. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132249. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132250. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132251. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132252. 15,17,16,17,18,17,17,18, 0,
  132253. };
  132254. static float _vq_quantthresh__44u0__p6_0[] = {
  132255. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132256. 12.5, 17.5, 22.5, 27.5,
  132257. };
  132258. static long _vq_quantmap__44u0__p6_0[] = {
  132259. 11, 9, 7, 5, 3, 1, 0, 2,
  132260. 4, 6, 8, 10, 12,
  132261. };
  132262. static encode_aux_threshmatch _vq_auxt__44u0__p6_0 = {
  132263. _vq_quantthresh__44u0__p6_0,
  132264. _vq_quantmap__44u0__p6_0,
  132265. 13,
  132266. 13
  132267. };
  132268. static static_codebook _44u0__p6_0 = {
  132269. 2, 169,
  132270. _vq_lengthlist__44u0__p6_0,
  132271. 1, -526516224, 1616117760, 4, 0,
  132272. _vq_quantlist__44u0__p6_0,
  132273. NULL,
  132274. &_vq_auxt__44u0__p6_0,
  132275. NULL,
  132276. 0
  132277. };
  132278. static long _vq_quantlist__44u0__p6_1[] = {
  132279. 2,
  132280. 1,
  132281. 3,
  132282. 0,
  132283. 4,
  132284. };
  132285. static long _vq_lengthlist__44u0__p6_1[] = {
  132286. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132287. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132288. };
  132289. static float _vq_quantthresh__44u0__p6_1[] = {
  132290. -1.5, -0.5, 0.5, 1.5,
  132291. };
  132292. static long _vq_quantmap__44u0__p6_1[] = {
  132293. 3, 1, 0, 2, 4,
  132294. };
  132295. static encode_aux_threshmatch _vq_auxt__44u0__p6_1 = {
  132296. _vq_quantthresh__44u0__p6_1,
  132297. _vq_quantmap__44u0__p6_1,
  132298. 5,
  132299. 5
  132300. };
  132301. static static_codebook _44u0__p6_1 = {
  132302. 2, 25,
  132303. _vq_lengthlist__44u0__p6_1,
  132304. 1, -533725184, 1611661312, 3, 0,
  132305. _vq_quantlist__44u0__p6_1,
  132306. NULL,
  132307. &_vq_auxt__44u0__p6_1,
  132308. NULL,
  132309. 0
  132310. };
  132311. static long _vq_quantlist__44u0__p7_0[] = {
  132312. 2,
  132313. 1,
  132314. 3,
  132315. 0,
  132316. 4,
  132317. };
  132318. static long _vq_lengthlist__44u0__p7_0[] = {
  132319. 1, 4, 4,11,11, 9,11,11,11,11,11,11,11,11,11,11,
  132320. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132321. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132322. 11,11, 9,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132323. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132324. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132325. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132326. 11,11,11,11,11,11,11,11,11,11,11,11,11,10,11,11,
  132327. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132328. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132329. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132330. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132331. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132332. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132333. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132334. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132335. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132336. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132337. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132338. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132339. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132340. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132341. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132342. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132343. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132344. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132345. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132346. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132347. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132348. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  132349. 11,11,11,11,11,11,10,10,10,10,10,10,10,10,10,10,
  132350. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132351. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132352. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132353. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132354. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132355. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132356. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132357. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  132358. 10,
  132359. };
  132360. static float _vq_quantthresh__44u0__p7_0[] = {
  132361. -253.5, -84.5, 84.5, 253.5,
  132362. };
  132363. static long _vq_quantmap__44u0__p7_0[] = {
  132364. 3, 1, 0, 2, 4,
  132365. };
  132366. static encode_aux_threshmatch _vq_auxt__44u0__p7_0 = {
  132367. _vq_quantthresh__44u0__p7_0,
  132368. _vq_quantmap__44u0__p7_0,
  132369. 5,
  132370. 5
  132371. };
  132372. static static_codebook _44u0__p7_0 = {
  132373. 4, 625,
  132374. _vq_lengthlist__44u0__p7_0,
  132375. 1, -518709248, 1626677248, 3, 0,
  132376. _vq_quantlist__44u0__p7_0,
  132377. NULL,
  132378. &_vq_auxt__44u0__p7_0,
  132379. NULL,
  132380. 0
  132381. };
  132382. static long _vq_quantlist__44u0__p7_1[] = {
  132383. 6,
  132384. 5,
  132385. 7,
  132386. 4,
  132387. 8,
  132388. 3,
  132389. 9,
  132390. 2,
  132391. 10,
  132392. 1,
  132393. 11,
  132394. 0,
  132395. 12,
  132396. };
  132397. static long _vq_lengthlist__44u0__p7_1[] = {
  132398. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132399. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132400. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132401. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132402. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132403. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132404. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132405. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132406. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132407. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132408. 15,15,15,15,15,15,15,15,15,
  132409. };
  132410. static float _vq_quantthresh__44u0__p7_1[] = {
  132411. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132412. 32.5, 45.5, 58.5, 71.5,
  132413. };
  132414. static long _vq_quantmap__44u0__p7_1[] = {
  132415. 11, 9, 7, 5, 3, 1, 0, 2,
  132416. 4, 6, 8, 10, 12,
  132417. };
  132418. static encode_aux_threshmatch _vq_auxt__44u0__p7_1 = {
  132419. _vq_quantthresh__44u0__p7_1,
  132420. _vq_quantmap__44u0__p7_1,
  132421. 13,
  132422. 13
  132423. };
  132424. static static_codebook _44u0__p7_1 = {
  132425. 2, 169,
  132426. _vq_lengthlist__44u0__p7_1,
  132427. 1, -523010048, 1618608128, 4, 0,
  132428. _vq_quantlist__44u0__p7_1,
  132429. NULL,
  132430. &_vq_auxt__44u0__p7_1,
  132431. NULL,
  132432. 0
  132433. };
  132434. static long _vq_quantlist__44u0__p7_2[] = {
  132435. 6,
  132436. 5,
  132437. 7,
  132438. 4,
  132439. 8,
  132440. 3,
  132441. 9,
  132442. 2,
  132443. 10,
  132444. 1,
  132445. 11,
  132446. 0,
  132447. 12,
  132448. };
  132449. static long _vq_lengthlist__44u0__p7_2[] = {
  132450. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132451. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132452. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132453. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132454. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132455. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132456. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132457. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132458. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132459. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132460. 9, 9, 9,10, 9, 9,10,10, 9,
  132461. };
  132462. static float _vq_quantthresh__44u0__p7_2[] = {
  132463. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132464. 2.5, 3.5, 4.5, 5.5,
  132465. };
  132466. static long _vq_quantmap__44u0__p7_2[] = {
  132467. 11, 9, 7, 5, 3, 1, 0, 2,
  132468. 4, 6, 8, 10, 12,
  132469. };
  132470. static encode_aux_threshmatch _vq_auxt__44u0__p7_2 = {
  132471. _vq_quantthresh__44u0__p7_2,
  132472. _vq_quantmap__44u0__p7_2,
  132473. 13,
  132474. 13
  132475. };
  132476. static static_codebook _44u0__p7_2 = {
  132477. 2, 169,
  132478. _vq_lengthlist__44u0__p7_2,
  132479. 1, -531103744, 1611661312, 4, 0,
  132480. _vq_quantlist__44u0__p7_2,
  132481. NULL,
  132482. &_vq_auxt__44u0__p7_2,
  132483. NULL,
  132484. 0
  132485. };
  132486. static long _huff_lengthlist__44u0__short[] = {
  132487. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  132488. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  132489. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  132490. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  132491. };
  132492. static static_codebook _huff_book__44u0__short = {
  132493. 2, 64,
  132494. _huff_lengthlist__44u0__short,
  132495. 0, 0, 0, 0, 0,
  132496. NULL,
  132497. NULL,
  132498. NULL,
  132499. NULL,
  132500. 0
  132501. };
  132502. static long _huff_lengthlist__44u1__long[] = {
  132503. 5, 8,13,10,17,11,11,15, 7, 2, 4, 5, 8, 7, 9,16,
  132504. 13, 4, 3, 5, 6, 8,11,20,10, 4, 5, 5, 7, 6, 8,18,
  132505. 15, 7, 6, 7, 8,10,14,20,10, 6, 7, 6, 9, 7, 8,17,
  132506. 9, 8,10, 8,10, 5, 4,11,12,17,19,14,16,10, 7,12,
  132507. };
  132508. static static_codebook _huff_book__44u1__long = {
  132509. 2, 64,
  132510. _huff_lengthlist__44u1__long,
  132511. 0, 0, 0, 0, 0,
  132512. NULL,
  132513. NULL,
  132514. NULL,
  132515. NULL,
  132516. 0
  132517. };
  132518. static long _vq_quantlist__44u1__p1_0[] = {
  132519. 1,
  132520. 0,
  132521. 2,
  132522. };
  132523. static long _vq_lengthlist__44u1__p1_0[] = {
  132524. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  132525. 10,10, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  132526. 11, 8,11,11, 8,12,11,11,13,13,11,13,14, 7,11,11,
  132527. 10,13,12,11,13,14, 4, 8, 8, 8,11,11, 8,11,12, 8,
  132528. 11,11,11,13,13,10,12,13, 8,11,11,11,14,13,11,14,
  132529. 13,
  132530. };
  132531. static float _vq_quantthresh__44u1__p1_0[] = {
  132532. -0.5, 0.5,
  132533. };
  132534. static long _vq_quantmap__44u1__p1_0[] = {
  132535. 1, 0, 2,
  132536. };
  132537. static encode_aux_threshmatch _vq_auxt__44u1__p1_0 = {
  132538. _vq_quantthresh__44u1__p1_0,
  132539. _vq_quantmap__44u1__p1_0,
  132540. 3,
  132541. 3
  132542. };
  132543. static static_codebook _44u1__p1_0 = {
  132544. 4, 81,
  132545. _vq_lengthlist__44u1__p1_0,
  132546. 1, -535822336, 1611661312, 2, 0,
  132547. _vq_quantlist__44u1__p1_0,
  132548. NULL,
  132549. &_vq_auxt__44u1__p1_0,
  132550. NULL,
  132551. 0
  132552. };
  132553. static long _vq_quantlist__44u1__p2_0[] = {
  132554. 1,
  132555. 0,
  132556. 2,
  132557. };
  132558. static long _vq_lengthlist__44u1__p2_0[] = {
  132559. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  132560. 8, 8, 5, 7, 7, 6, 8, 8, 7, 8, 8, 4, 7, 7, 7, 8,
  132561. 8, 7, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  132562. 8,10, 8, 8,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 8, 6,
  132563. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  132564. 9,
  132565. };
  132566. static float _vq_quantthresh__44u1__p2_0[] = {
  132567. -0.5, 0.5,
  132568. };
  132569. static long _vq_quantmap__44u1__p2_0[] = {
  132570. 1, 0, 2,
  132571. };
  132572. static encode_aux_threshmatch _vq_auxt__44u1__p2_0 = {
  132573. _vq_quantthresh__44u1__p2_0,
  132574. _vq_quantmap__44u1__p2_0,
  132575. 3,
  132576. 3
  132577. };
  132578. static static_codebook _44u1__p2_0 = {
  132579. 4, 81,
  132580. _vq_lengthlist__44u1__p2_0,
  132581. 1, -535822336, 1611661312, 2, 0,
  132582. _vq_quantlist__44u1__p2_0,
  132583. NULL,
  132584. &_vq_auxt__44u1__p2_0,
  132585. NULL,
  132586. 0
  132587. };
  132588. static long _vq_quantlist__44u1__p3_0[] = {
  132589. 2,
  132590. 1,
  132591. 3,
  132592. 0,
  132593. 4,
  132594. };
  132595. static long _vq_lengthlist__44u1__p3_0[] = {
  132596. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  132597. 10, 9,12,12, 9, 9,10,12,12, 6, 8, 8,11,10, 8,10,
  132598. 10,11,11, 8, 9,10,11,11,10,11,11,14,13,10,11,11,
  132599. 13,13, 5, 8, 8,10,10, 8,10,10,11,11, 8,10,10,11,
  132600. 11,10,11,11,13,13,10,11,11,13,13, 9,11,11,15,14,
  132601. 10,12,12,15,14,10,12,11,15,14,13,14,14,16,16,12,
  132602. 14,13,17,15, 9,11,11,14,15,10,11,12,14,16,10,11,
  132603. 12,14,16,12,13,14,16,16,13,13,15,15,18, 5, 8, 8,
  132604. 11,11, 8,10,10,12,12, 8,10,10,12,13,11,12,12,14,
  132605. 14,11,12,12,15,15, 8,10,10,13,13,10,12,12,13,13,
  132606. 10,12,12,14,14,12,13,13,15,15,12,13,13,16,16, 7,
  132607. 10,10,12,12,10,12,11,13,13,10,12,12,13,14,12,13,
  132608. 12,15,14,12,13,13,16,16,10,12,12,17,16,12,13,13,
  132609. 16,15,11,13,13,17,17,15,15,15,16,17,14,15,15,19,
  132610. 19,10,12,12,15,16,11,13,12,15,18,11,13,13,16,16,
  132611. 14,15,15,17,17,14,15,15,17,19, 5, 8, 8,11,11, 8,
  132612. 10,10,12,12, 8,10,10,12,12,11,12,12,16,15,11,12,
  132613. 12,14,15, 7,10,10,13,13,10,12,12,14,13,10,11,12,
  132614. 13,13,12,13,13,16,16,12,12,13,15,15, 8,10,10,13,
  132615. 13,10,12,12,14,14,10,12,12,13,13,12,13,13,16,16,
  132616. 12,13,13,15,15,10,12,12,16,15,11,13,13,17,16,11,
  132617. 12,13,16,15,13,15,15,19,17,14,15,14,17,16,10,12,
  132618. 12,16,16,11,13,13,16,17,12,13,13,15,17,14,15,15,
  132619. 17,19,14,15,15,17,17, 8,11,11,16,16,10,13,12,17,
  132620. 17,10,12,13,16,16,15,17,16,20,19,14,15,17,18,19,
  132621. 9,12,12,16,17,11,13,14,17,18,11,13,13,19,18,16,
  132622. 17,18,19,19,15,16,16,19,19, 9,12,12,16,17,11,14,
  132623. 13,18,17,11,13,13,17,17,16,17,16,20,19,14,16,16,
  132624. 18,18,12,15,15,19,17,14,15,16, 0,20,13,15,16,20,
  132625. 17,18,16,20, 0, 0,15,16,19,20, 0,12,15,14,18,19,
  132626. 13,16,15,20,19,13,16,15,20,18,17,18,17, 0,20,16,
  132627. 17,16, 0, 0, 8,11,11,16,15,10,12,12,17,17,10,13,
  132628. 13,17,16,14,16,15,18,20,15,16,16,19,19, 9,12,12,
  132629. 16,16,11,13,13,17,16,11,13,14,17,18,15,15,16,20,
  132630. 20,16,16,17,19,19, 9,13,12,16,17,11,14,13,17,17,
  132631. 11,14,14,18,17,14,16,15,18,19,16,17,18,18,19,12,
  132632. 14,15,19,18,13,15,16,18, 0,13,14,15, 0, 0,16,16,
  132633. 17,20, 0,17,17,20,20, 0,12,15,15,19,20,13,15,15,
  132634. 0, 0,14,16,15, 0, 0,15,18,16, 0, 0,17,18,16, 0,
  132635. 19,
  132636. };
  132637. static float _vq_quantthresh__44u1__p3_0[] = {
  132638. -1.5, -0.5, 0.5, 1.5,
  132639. };
  132640. static long _vq_quantmap__44u1__p3_0[] = {
  132641. 3, 1, 0, 2, 4,
  132642. };
  132643. static encode_aux_threshmatch _vq_auxt__44u1__p3_0 = {
  132644. _vq_quantthresh__44u1__p3_0,
  132645. _vq_quantmap__44u1__p3_0,
  132646. 5,
  132647. 5
  132648. };
  132649. static static_codebook _44u1__p3_0 = {
  132650. 4, 625,
  132651. _vq_lengthlist__44u1__p3_0,
  132652. 1, -533725184, 1611661312, 3, 0,
  132653. _vq_quantlist__44u1__p3_0,
  132654. NULL,
  132655. &_vq_auxt__44u1__p3_0,
  132656. NULL,
  132657. 0
  132658. };
  132659. static long _vq_quantlist__44u1__p4_0[] = {
  132660. 2,
  132661. 1,
  132662. 3,
  132663. 0,
  132664. 4,
  132665. };
  132666. static long _vq_lengthlist__44u1__p4_0[] = {
  132667. 4, 5, 5, 9, 9, 5, 6, 6, 9, 9, 5, 6, 6, 9, 9, 9,
  132668. 10, 9,12,12, 9, 9,10,12,12, 5, 7, 7,10,10, 7, 7,
  132669. 8,10,10, 6, 7, 8,10,10,10,10,10,11,13,10, 9,10,
  132670. 12,13, 5, 7, 7,10,10, 6, 8, 7,10,10, 7, 8, 7,10,
  132671. 10, 9,10,10,12,12,10,10,10,13,11, 9,10,10,13,13,
  132672. 10,11,10,13,13,10,10,10,13,13,12,12,13,14,14,12,
  132673. 12,13,14,14, 9,10,10,13,13,10,10,10,13,13,10,10,
  132674. 10,13,13,12,13,12,15,14,12,13,12,15,15, 5, 7, 6,
  132675. 10,10, 7, 8, 8,10,10, 7, 8, 8,10,10,10,11,10,13,
  132676. 13,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,10,11,
  132677. 8, 9, 9,11,11,11,10,11,11,14,11,11,11,13,13, 6,
  132678. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  132679. 10,14,11,10,11,11,13,13,10,11,11,14,13,10,10,11,
  132680. 14,13,10,11,11,14,14,12,11,13,12,16,13,14,14,15,
  132681. 15,10,10,11,13,14,10,11,10,14,13,10,11,11,14,14,
  132682. 12,13,12,15,13,13,13,14,15,16, 5, 7, 7,10,10, 7,
  132683. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,13,13,10,10,
  132684. 11,12,13, 6, 8, 8,11,10, 8, 9, 9,11,11, 7, 8, 9,
  132685. 10,11,10,11,11,13,13,10,10,11,11,13, 6, 8, 8,10,
  132686. 11, 8, 9, 9,11,11, 8, 9, 8,12,10,10,11,11,13,13,
  132687. 10,11,10,14,11,10,10,10,14,13,10,11,11,14,13,10,
  132688. 10,11,13,13,12,14,14,16,16,12,12,13,13,15,10,11,
  132689. 11,13,14,10,11,11,14,15,10,11,10,13,13,13,14,13,
  132690. 16,16,12,13,11,15,12, 9,10,10,13,13,10,11,11,14,
  132691. 13,10,10,11,13,14,13,14,13,16,16,13,13,13,15,16,
  132692. 9,10,10,13,13,10,10,11,13,14,10,11,11,15,13,13,
  132693. 13,14,14,18,13,13,14,16,15, 9,10,10,13,14,10,11,
  132694. 10,14,13,10,11,11,13,14,13,14,13,16,15,13,13,14,
  132695. 15,16,12,13,12,16,14,11,11,13,15,15,13,14,13,16,
  132696. 15,15,12,16,12,17,14,15,15,17,17,12,13,13,14,16,
  132697. 11,13,11,16,15,12,13,14,15,16,14,15,13, 0,14,14,
  132698. 16,16, 0, 0, 9,10,10,13,13,10,11,10,14,14,10,11,
  132699. 11,13,13,12,13,13,14,16,13,14,14,16,16, 9,10,10,
  132700. 14,14,11,11,11,14,13,10,10,11,14,14,13,13,13,16,
  132701. 16,13,13,14,14,17, 9,10,10,13,14,10,11,11,13,15,
  132702. 10,11,10,14,14,13,13,13,14,17,13,14,13,17,14,12,
  132703. 13,13,16,14,13,14,13,16,15,12,12,13,15,16,15,15,
  132704. 16,18,16,15,13,15,14, 0,12,12,13,14,16,13,13,14,
  132705. 15,16,11,12,11,16,14,15,16,16,17,17,14,15,12,17,
  132706. 12,
  132707. };
  132708. static float _vq_quantthresh__44u1__p4_0[] = {
  132709. -1.5, -0.5, 0.5, 1.5,
  132710. };
  132711. static long _vq_quantmap__44u1__p4_0[] = {
  132712. 3, 1, 0, 2, 4,
  132713. };
  132714. static encode_aux_threshmatch _vq_auxt__44u1__p4_0 = {
  132715. _vq_quantthresh__44u1__p4_0,
  132716. _vq_quantmap__44u1__p4_0,
  132717. 5,
  132718. 5
  132719. };
  132720. static static_codebook _44u1__p4_0 = {
  132721. 4, 625,
  132722. _vq_lengthlist__44u1__p4_0,
  132723. 1, -533725184, 1611661312, 3, 0,
  132724. _vq_quantlist__44u1__p4_0,
  132725. NULL,
  132726. &_vq_auxt__44u1__p4_0,
  132727. NULL,
  132728. 0
  132729. };
  132730. static long _vq_quantlist__44u1__p5_0[] = {
  132731. 4,
  132732. 3,
  132733. 5,
  132734. 2,
  132735. 6,
  132736. 1,
  132737. 7,
  132738. 0,
  132739. 8,
  132740. };
  132741. static long _vq_lengthlist__44u1__p5_0[] = {
  132742. 1, 4, 4, 7, 7, 7, 7, 9, 9, 4, 6, 6, 8, 8, 8, 8,
  132743. 9, 9, 4, 6, 6, 8, 8, 8, 8, 9, 9, 7, 8, 8, 9, 9,
  132744. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,10, 7, 8, 8,
  132745. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  132746. 9, 9,10,10,11,11,12,12, 9, 9, 9,10,11,11,11,12,
  132747. 12,
  132748. };
  132749. static float _vq_quantthresh__44u1__p5_0[] = {
  132750. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  132751. };
  132752. static long _vq_quantmap__44u1__p5_0[] = {
  132753. 7, 5, 3, 1, 0, 2, 4, 6,
  132754. 8,
  132755. };
  132756. static encode_aux_threshmatch _vq_auxt__44u1__p5_0 = {
  132757. _vq_quantthresh__44u1__p5_0,
  132758. _vq_quantmap__44u1__p5_0,
  132759. 9,
  132760. 9
  132761. };
  132762. static static_codebook _44u1__p5_0 = {
  132763. 2, 81,
  132764. _vq_lengthlist__44u1__p5_0,
  132765. 1, -531628032, 1611661312, 4, 0,
  132766. _vq_quantlist__44u1__p5_0,
  132767. NULL,
  132768. &_vq_auxt__44u1__p5_0,
  132769. NULL,
  132770. 0
  132771. };
  132772. static long _vq_quantlist__44u1__p6_0[] = {
  132773. 6,
  132774. 5,
  132775. 7,
  132776. 4,
  132777. 8,
  132778. 3,
  132779. 9,
  132780. 2,
  132781. 10,
  132782. 1,
  132783. 11,
  132784. 0,
  132785. 12,
  132786. };
  132787. static long _vq_lengthlist__44u1__p6_0[] = {
  132788. 1, 4, 4, 6, 6, 8, 8,10, 9,11,10,14,13, 4, 6, 5,
  132789. 8, 8, 9, 9,11,10,11,11,14,14, 4, 5, 6, 8, 8, 9,
  132790. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  132791. 12,12,16,15, 7, 8, 8, 9, 9,10,10,11,11,12,12,15,
  132792. 15, 9,10,10,10,10,11,11,12,12,12,12,15,15, 9,10,
  132793. 9,10,11,11,11,12,12,12,13,15,15,10,10,11,11,11,
  132794. 12,12,13,12,13,13,16,15,10,11,11,11,11,12,12,13,
  132795. 12,13,13,16,17,11,11,12,12,12,13,13,13,14,14,15,
  132796. 17,17,11,11,12,12,12,13,13,13,14,14,14,16,18,14,
  132797. 15,15,15,15,16,16,16,16,17,18, 0, 0,14,15,15,15,
  132798. 15,17,16,17,18,17,17,18, 0,
  132799. };
  132800. static float _vq_quantthresh__44u1__p6_0[] = {
  132801. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  132802. 12.5, 17.5, 22.5, 27.5,
  132803. };
  132804. static long _vq_quantmap__44u1__p6_0[] = {
  132805. 11, 9, 7, 5, 3, 1, 0, 2,
  132806. 4, 6, 8, 10, 12,
  132807. };
  132808. static encode_aux_threshmatch _vq_auxt__44u1__p6_0 = {
  132809. _vq_quantthresh__44u1__p6_0,
  132810. _vq_quantmap__44u1__p6_0,
  132811. 13,
  132812. 13
  132813. };
  132814. static static_codebook _44u1__p6_0 = {
  132815. 2, 169,
  132816. _vq_lengthlist__44u1__p6_0,
  132817. 1, -526516224, 1616117760, 4, 0,
  132818. _vq_quantlist__44u1__p6_0,
  132819. NULL,
  132820. &_vq_auxt__44u1__p6_0,
  132821. NULL,
  132822. 0
  132823. };
  132824. static long _vq_quantlist__44u1__p6_1[] = {
  132825. 2,
  132826. 1,
  132827. 3,
  132828. 0,
  132829. 4,
  132830. };
  132831. static long _vq_lengthlist__44u1__p6_1[] = {
  132832. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  132833. 6, 6, 6, 6, 5, 6, 6, 6, 6,
  132834. };
  132835. static float _vq_quantthresh__44u1__p6_1[] = {
  132836. -1.5, -0.5, 0.5, 1.5,
  132837. };
  132838. static long _vq_quantmap__44u1__p6_1[] = {
  132839. 3, 1, 0, 2, 4,
  132840. };
  132841. static encode_aux_threshmatch _vq_auxt__44u1__p6_1 = {
  132842. _vq_quantthresh__44u1__p6_1,
  132843. _vq_quantmap__44u1__p6_1,
  132844. 5,
  132845. 5
  132846. };
  132847. static static_codebook _44u1__p6_1 = {
  132848. 2, 25,
  132849. _vq_lengthlist__44u1__p6_1,
  132850. 1, -533725184, 1611661312, 3, 0,
  132851. _vq_quantlist__44u1__p6_1,
  132852. NULL,
  132853. &_vq_auxt__44u1__p6_1,
  132854. NULL,
  132855. 0
  132856. };
  132857. static long _vq_quantlist__44u1__p7_0[] = {
  132858. 3,
  132859. 2,
  132860. 4,
  132861. 1,
  132862. 5,
  132863. 0,
  132864. 6,
  132865. };
  132866. static long _vq_lengthlist__44u1__p7_0[] = {
  132867. 1, 3, 2, 9, 9, 7, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132868. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132869. 9, 9, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  132870. 8,
  132871. };
  132872. static float _vq_quantthresh__44u1__p7_0[] = {
  132873. -422.5, -253.5, -84.5, 84.5, 253.5, 422.5,
  132874. };
  132875. static long _vq_quantmap__44u1__p7_0[] = {
  132876. 5, 3, 1, 0, 2, 4, 6,
  132877. };
  132878. static encode_aux_threshmatch _vq_auxt__44u1__p7_0 = {
  132879. _vq_quantthresh__44u1__p7_0,
  132880. _vq_quantmap__44u1__p7_0,
  132881. 7,
  132882. 7
  132883. };
  132884. static static_codebook _44u1__p7_0 = {
  132885. 2, 49,
  132886. _vq_lengthlist__44u1__p7_0,
  132887. 1, -518017024, 1626677248, 3, 0,
  132888. _vq_quantlist__44u1__p7_0,
  132889. NULL,
  132890. &_vq_auxt__44u1__p7_0,
  132891. NULL,
  132892. 0
  132893. };
  132894. static long _vq_quantlist__44u1__p7_1[] = {
  132895. 6,
  132896. 5,
  132897. 7,
  132898. 4,
  132899. 8,
  132900. 3,
  132901. 9,
  132902. 2,
  132903. 10,
  132904. 1,
  132905. 11,
  132906. 0,
  132907. 12,
  132908. };
  132909. static long _vq_lengthlist__44u1__p7_1[] = {
  132910. 1, 4, 4, 6, 6, 6, 6, 7, 7, 8, 8, 9, 9, 5, 7, 7,
  132911. 8, 7, 7, 7, 9, 8,10, 9,10,11, 5, 7, 7, 8, 8, 7,
  132912. 7, 8, 9,10,10,11,11, 6, 8, 8, 9, 9, 9, 9,11,10,
  132913. 12,12,15,12, 6, 8, 8, 9, 9, 9, 9,11,11,12,11,14,
  132914. 12, 7, 8, 8,10,10,12,12,13,13,13,15,13,13, 7, 8,
  132915. 8,10,10,11,11,13,12,14,15,15,15, 9,10,10,11,12,
  132916. 13,13,14,15,14,15,14,15, 8,10,10,12,12,14,14,15,
  132917. 14,14,15,15,14,10,12,12,14,14,15,14,15,15,15,14,
  132918. 15,15,10,12,12,13,14,15,14,15,15,14,15,15,15,12,
  132919. 15,13,15,14,15,15,15,15,15,15,15,15,13,13,15,15,
  132920. 15,15,15,15,15,15,15,15,15,
  132921. };
  132922. static float _vq_quantthresh__44u1__p7_1[] = {
  132923. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  132924. 32.5, 45.5, 58.5, 71.5,
  132925. };
  132926. static long _vq_quantmap__44u1__p7_1[] = {
  132927. 11, 9, 7, 5, 3, 1, 0, 2,
  132928. 4, 6, 8, 10, 12,
  132929. };
  132930. static encode_aux_threshmatch _vq_auxt__44u1__p7_1 = {
  132931. _vq_quantthresh__44u1__p7_1,
  132932. _vq_quantmap__44u1__p7_1,
  132933. 13,
  132934. 13
  132935. };
  132936. static static_codebook _44u1__p7_1 = {
  132937. 2, 169,
  132938. _vq_lengthlist__44u1__p7_1,
  132939. 1, -523010048, 1618608128, 4, 0,
  132940. _vq_quantlist__44u1__p7_1,
  132941. NULL,
  132942. &_vq_auxt__44u1__p7_1,
  132943. NULL,
  132944. 0
  132945. };
  132946. static long _vq_quantlist__44u1__p7_2[] = {
  132947. 6,
  132948. 5,
  132949. 7,
  132950. 4,
  132951. 8,
  132952. 3,
  132953. 9,
  132954. 2,
  132955. 10,
  132956. 1,
  132957. 11,
  132958. 0,
  132959. 12,
  132960. };
  132961. static long _vq_lengthlist__44u1__p7_2[] = {
  132962. 2, 5, 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 5, 5, 6,
  132963. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 5, 6, 5, 7, 7, 8,
  132964. 8, 8, 8, 9, 9, 9, 9, 6, 7, 7, 8, 8, 8, 8, 9, 8,
  132965. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  132966. 9, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 7, 8,
  132967. 8, 9, 8, 9, 8, 9, 9, 9, 9, 9, 9, 8, 9, 8, 9, 9,
  132968. 9, 9, 9, 9, 9, 9,10,10, 8, 8, 9, 9, 9, 9, 9, 9,
  132969. 9, 9,10, 9,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132970. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  132971. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9, 9, 9, 9, 9,
  132972. 9, 9, 9,10, 9, 9,10,10, 9,
  132973. };
  132974. static float _vq_quantthresh__44u1__p7_2[] = {
  132975. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  132976. 2.5, 3.5, 4.5, 5.5,
  132977. };
  132978. static long _vq_quantmap__44u1__p7_2[] = {
  132979. 11, 9, 7, 5, 3, 1, 0, 2,
  132980. 4, 6, 8, 10, 12,
  132981. };
  132982. static encode_aux_threshmatch _vq_auxt__44u1__p7_2 = {
  132983. _vq_quantthresh__44u1__p7_2,
  132984. _vq_quantmap__44u1__p7_2,
  132985. 13,
  132986. 13
  132987. };
  132988. static static_codebook _44u1__p7_2 = {
  132989. 2, 169,
  132990. _vq_lengthlist__44u1__p7_2,
  132991. 1, -531103744, 1611661312, 4, 0,
  132992. _vq_quantlist__44u1__p7_2,
  132993. NULL,
  132994. &_vq_auxt__44u1__p7_2,
  132995. NULL,
  132996. 0
  132997. };
  132998. static long _huff_lengthlist__44u1__short[] = {
  132999. 12,13,14,13,17,12,15,17, 5, 5, 6,10,10,11,15,16,
  133000. 4, 3, 3, 7, 5, 7,10,16, 7, 7, 7,10, 9,11,12,16,
  133001. 6, 5, 5, 9, 5, 6,10,16, 8, 7, 7, 9, 6, 7, 9,16,
  133002. 11, 7, 3, 6, 4, 5, 8,16,12, 9, 4, 8, 5, 7, 9,16,
  133003. };
  133004. static static_codebook _huff_book__44u1__short = {
  133005. 2, 64,
  133006. _huff_lengthlist__44u1__short,
  133007. 0, 0, 0, 0, 0,
  133008. NULL,
  133009. NULL,
  133010. NULL,
  133011. NULL,
  133012. 0
  133013. };
  133014. static long _huff_lengthlist__44u2__long[] = {
  133015. 5, 9,14,12,15,13,10,13, 7, 4, 5, 6, 8, 7, 8,12,
  133016. 13, 4, 3, 5, 5, 6, 9,15,12, 6, 5, 6, 6, 6, 7,14,
  133017. 14, 7, 4, 6, 4, 6, 8,15,12, 6, 6, 5, 5, 5, 6,14,
  133018. 9, 7, 8, 6, 7, 5, 4,10,10,13,14,14,15,10, 6, 8,
  133019. };
  133020. static static_codebook _huff_book__44u2__long = {
  133021. 2, 64,
  133022. _huff_lengthlist__44u2__long,
  133023. 0, 0, 0, 0, 0,
  133024. NULL,
  133025. NULL,
  133026. NULL,
  133027. NULL,
  133028. 0
  133029. };
  133030. static long _vq_quantlist__44u2__p1_0[] = {
  133031. 1,
  133032. 0,
  133033. 2,
  133034. };
  133035. static long _vq_lengthlist__44u2__p1_0[] = {
  133036. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,11,11, 8,
  133037. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133038. 11, 8,11,11, 8,11,11,11,13,14,11,13,13, 7,11,11,
  133039. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 8,
  133040. 11,11,11,14,13,10,12,13, 8,11,11,11,13,13,11,13,
  133041. 13,
  133042. };
  133043. static float _vq_quantthresh__44u2__p1_0[] = {
  133044. -0.5, 0.5,
  133045. };
  133046. static long _vq_quantmap__44u2__p1_0[] = {
  133047. 1, 0, 2,
  133048. };
  133049. static encode_aux_threshmatch _vq_auxt__44u2__p1_0 = {
  133050. _vq_quantthresh__44u2__p1_0,
  133051. _vq_quantmap__44u2__p1_0,
  133052. 3,
  133053. 3
  133054. };
  133055. static static_codebook _44u2__p1_0 = {
  133056. 4, 81,
  133057. _vq_lengthlist__44u2__p1_0,
  133058. 1, -535822336, 1611661312, 2, 0,
  133059. _vq_quantlist__44u2__p1_0,
  133060. NULL,
  133061. &_vq_auxt__44u2__p1_0,
  133062. NULL,
  133063. 0
  133064. };
  133065. static long _vq_quantlist__44u2__p2_0[] = {
  133066. 1,
  133067. 0,
  133068. 2,
  133069. };
  133070. static long _vq_lengthlist__44u2__p2_0[] = {
  133071. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133072. 8, 8, 5, 6, 6, 6, 8, 7, 7, 8, 8, 5, 6, 6, 7, 8,
  133073. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133074. 7,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133075. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  133076. 9,
  133077. };
  133078. static float _vq_quantthresh__44u2__p2_0[] = {
  133079. -0.5, 0.5,
  133080. };
  133081. static long _vq_quantmap__44u2__p2_0[] = {
  133082. 1, 0, 2,
  133083. };
  133084. static encode_aux_threshmatch _vq_auxt__44u2__p2_0 = {
  133085. _vq_quantthresh__44u2__p2_0,
  133086. _vq_quantmap__44u2__p2_0,
  133087. 3,
  133088. 3
  133089. };
  133090. static static_codebook _44u2__p2_0 = {
  133091. 4, 81,
  133092. _vq_lengthlist__44u2__p2_0,
  133093. 1, -535822336, 1611661312, 2, 0,
  133094. _vq_quantlist__44u2__p2_0,
  133095. NULL,
  133096. &_vq_auxt__44u2__p2_0,
  133097. NULL,
  133098. 0
  133099. };
  133100. static long _vq_quantlist__44u2__p3_0[] = {
  133101. 2,
  133102. 1,
  133103. 3,
  133104. 0,
  133105. 4,
  133106. };
  133107. static long _vq_lengthlist__44u2__p3_0[] = {
  133108. 2, 4, 4, 7, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133109. 9, 9,12,11, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133110. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133111. 12,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133112. 11, 9,11,10,13,13,10,11,11,13,13, 8,10,10,14,13,
  133113. 10,11,11,15,14, 9,11,11,15,14,13,14,13,16,14,12,
  133114. 13,13,15,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  133115. 11,14,15,12,13,13,15,15,12,13,14,15,16, 5, 7, 7,
  133116. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133117. 13,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133118. 9,11,11,13,13,12,13,12,14,14,11,12,13,15,15, 7,
  133119. 9, 9,12,12, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133120. 12,15,13,11,13,13,15,16, 9,12,11,15,15,11,12,12,
  133121. 16,15,11,12,13,16,16,13,14,15,16,15,13,15,15,17,
  133122. 17, 9,11,11,14,15,10,12,12,15,15,11,13,12,15,16,
  133123. 13,15,14,16,16,13,15,15,17,19, 5, 7, 7,10,10, 7,
  133124. 9, 9,12,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  133125. 11,13,14, 7, 9, 9,12,12, 9,11,11,13,13, 9,10,11,
  133126. 12,13,11,13,12,16,15,11,12,12,14,15, 7, 9, 9,12,
  133127. 12, 9,11,11,13,13, 9,11,11,13,12,11,13,12,15,16,
  133128. 12,13,13,15,14, 9,11,11,15,14,11,13,12,16,15,10,
  133129. 11,12,15,15,13,14,14,18,17,13,14,14,15,17,10,11,
  133130. 11,14,15,11,13,12,15,17,11,13,12,15,16,13,15,14,
  133131. 18,17,14,15,15,16,18, 7,10,10,14,14,10,12,12,15,
  133132. 15,10,12,12,15,15,14,15,15,18,17,13,15,15,16,16,
  133133. 9,11,11,16,15,11,13,13,16,18,11,13,13,16,16,15,
  133134. 16,16, 0, 0,14,15,16,18,17, 9,11,11,15,15,10,13,
  133135. 12,17,16,11,12,13,16,17,14,15,16,19,19,14,15,15,
  133136. 0,20,12,14,14, 0, 0,13,14,16,19,18,13,15,16,20,
  133137. 17,16,18, 0, 0, 0,15,16,17,18,19,11,14,14, 0,19,
  133138. 12,15,14,17,17,13,15,15, 0, 0,16,17,15,20,19,15,
  133139. 17,16,19, 0, 8,10,10,14,15,10,12,11,15,15,10,11,
  133140. 12,16,15,13,14,14,19,17,14,15,15, 0, 0, 9,11,11,
  133141. 16,15,11,13,13,17,16,10,12,13,16,17,14,15,15,18,
  133142. 18,14,15,16,20,19, 9,12,12, 0,15,11,13,13,16,17,
  133143. 11,13,13,19,17,14,16,16,18,17,15,16,16,17,19,11,
  133144. 14,14,18,18,13,14,15, 0, 0,12,14,15,19,18,15,16,
  133145. 19, 0,19,15,16,19,19,17,12,14,14,16,19,13,15,15,
  133146. 0,17,13,15,14,18,18,15,16,15, 0,18,16,17,17, 0,
  133147. 0,
  133148. };
  133149. static float _vq_quantthresh__44u2__p3_0[] = {
  133150. -1.5, -0.5, 0.5, 1.5,
  133151. };
  133152. static long _vq_quantmap__44u2__p3_0[] = {
  133153. 3, 1, 0, 2, 4,
  133154. };
  133155. static encode_aux_threshmatch _vq_auxt__44u2__p3_0 = {
  133156. _vq_quantthresh__44u2__p3_0,
  133157. _vq_quantmap__44u2__p3_0,
  133158. 5,
  133159. 5
  133160. };
  133161. static static_codebook _44u2__p3_0 = {
  133162. 4, 625,
  133163. _vq_lengthlist__44u2__p3_0,
  133164. 1, -533725184, 1611661312, 3, 0,
  133165. _vq_quantlist__44u2__p3_0,
  133166. NULL,
  133167. &_vq_auxt__44u2__p3_0,
  133168. NULL,
  133169. 0
  133170. };
  133171. static long _vq_quantlist__44u2__p4_0[] = {
  133172. 2,
  133173. 1,
  133174. 3,
  133175. 0,
  133176. 4,
  133177. };
  133178. static long _vq_lengthlist__44u2__p4_0[] = {
  133179. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133180. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133181. 8,10,10, 7, 7, 8,10,10,10,10,10,11,12, 9,10,10,
  133182. 11,12, 5, 7, 7, 9, 9, 6, 8, 7,10,10, 7, 8, 8,10,
  133183. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10,10,12,12,
  133184. 10,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133185. 12,12,13,14, 9,10,10,12,12, 9,10,10,12,13,10,10,
  133186. 10,12,13,11,12,12,14,13,12,12,12,14,13, 5, 7, 7,
  133187. 10, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133188. 12,10,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133189. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,13,13, 6,
  133190. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133191. 10,13,11,10,11,11,13,13, 9,10,10,13,13,10,11,11,
  133192. 13,13,10,11,11,14,13,12,11,13,12,15,12,13,13,15,
  133193. 15, 9,10,10,12,13,10,11,10,13,13,10,11,11,13,13,
  133194. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9,10, 7,
  133195. 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,12,10,10,
  133196. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133197. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133198. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  133199. 10,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133200. 10,11,13,13,12,13,13,15,15,12,11,13,12,14, 9,10,
  133201. 10,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  133202. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133203. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  133204. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,12,13,
  133205. 13,14,14,16,12,13,13,15,14, 9,10,10,13,13,10,11,
  133206. 10,14,13,10,11,11,13,14,12,14,13,16,14,13,13,13,
  133207. 14,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133208. 15,14,12,15,12,16,14,15,15,17,16,11,12,12,14,15,
  133209. 11,13,11,15,14,12,13,13,15,16,13,15,12,17,13,14,
  133210. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,13,13, 9,10,
  133211. 10,13,13,12,13,12,14,14,12,13,13,15,15, 9,10,10,
  133212. 13,13,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133213. 14,12,12,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  133214. 10,11,11,14,13,13,13,13,15,15,13,14,13,16,14,11,
  133215. 12,12,14,14,12,13,13,16,15,11,12,13,14,15,14,15,
  133216. 15,16,16,14,13,15,13,17,11,12,12,14,15,12,13,13,
  133217. 15,16,11,13,12,15,15,14,15,14,16,16,14,15,12,17,
  133218. 13,
  133219. };
  133220. static float _vq_quantthresh__44u2__p4_0[] = {
  133221. -1.5, -0.5, 0.5, 1.5,
  133222. };
  133223. static long _vq_quantmap__44u2__p4_0[] = {
  133224. 3, 1, 0, 2, 4,
  133225. };
  133226. static encode_aux_threshmatch _vq_auxt__44u2__p4_0 = {
  133227. _vq_quantthresh__44u2__p4_0,
  133228. _vq_quantmap__44u2__p4_0,
  133229. 5,
  133230. 5
  133231. };
  133232. static static_codebook _44u2__p4_0 = {
  133233. 4, 625,
  133234. _vq_lengthlist__44u2__p4_0,
  133235. 1, -533725184, 1611661312, 3, 0,
  133236. _vq_quantlist__44u2__p4_0,
  133237. NULL,
  133238. &_vq_auxt__44u2__p4_0,
  133239. NULL,
  133240. 0
  133241. };
  133242. static long _vq_quantlist__44u2__p5_0[] = {
  133243. 4,
  133244. 3,
  133245. 5,
  133246. 2,
  133247. 6,
  133248. 1,
  133249. 7,
  133250. 0,
  133251. 8,
  133252. };
  133253. static long _vq_lengthlist__44u2__p5_0[] = {
  133254. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 8, 8, 8,
  133255. 10,10, 4, 5, 6, 8, 8, 8, 8,10,10, 7, 8, 8, 9, 9,
  133256. 9, 9,11,11, 7, 8, 8, 9, 9, 9, 9,11,11, 8, 8, 8,
  133257. 9, 9,10,11,12,12, 8, 8, 8, 9, 9,10,10,12,12,10,
  133258. 10,10,11,11,12,12,13,13,10,10,10,11,11,12,12,13,
  133259. 13,
  133260. };
  133261. static float _vq_quantthresh__44u2__p5_0[] = {
  133262. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133263. };
  133264. static long _vq_quantmap__44u2__p5_0[] = {
  133265. 7, 5, 3, 1, 0, 2, 4, 6,
  133266. 8,
  133267. };
  133268. static encode_aux_threshmatch _vq_auxt__44u2__p5_0 = {
  133269. _vq_quantthresh__44u2__p5_0,
  133270. _vq_quantmap__44u2__p5_0,
  133271. 9,
  133272. 9
  133273. };
  133274. static static_codebook _44u2__p5_0 = {
  133275. 2, 81,
  133276. _vq_lengthlist__44u2__p5_0,
  133277. 1, -531628032, 1611661312, 4, 0,
  133278. _vq_quantlist__44u2__p5_0,
  133279. NULL,
  133280. &_vq_auxt__44u2__p5_0,
  133281. NULL,
  133282. 0
  133283. };
  133284. static long _vq_quantlist__44u2__p6_0[] = {
  133285. 6,
  133286. 5,
  133287. 7,
  133288. 4,
  133289. 8,
  133290. 3,
  133291. 9,
  133292. 2,
  133293. 10,
  133294. 1,
  133295. 11,
  133296. 0,
  133297. 12,
  133298. };
  133299. static long _vq_lengthlist__44u2__p6_0[] = {
  133300. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,14,13, 4, 6, 5,
  133301. 8, 8, 9, 9,11,10,12,11,15,14, 4, 5, 6, 8, 8, 9,
  133302. 9,11,11,11,11,14,14, 6, 8, 8,10, 9,11,11,11,11,
  133303. 12,12,15,15, 6, 8, 8, 9, 9,11,11,11,12,12,12,15,
  133304. 15, 8,10,10,11,11,11,11,12,12,13,13,15,16, 8,10,
  133305. 10,11,11,11,11,12,12,13,13,16,16,10,11,11,12,12,
  133306. 12,12,13,13,13,13,17,16,10,11,11,12,12,12,12,13,
  133307. 13,13,14,16,17,11,12,12,13,13,13,13,14,14,15,14,
  133308. 18,17,11,12,12,13,13,13,13,14,14,14,15,19,18,14,
  133309. 15,15,15,15,16,16,18,19,18,18, 0, 0,14,15,15,16,
  133310. 15,17,17,16,18,17,18, 0, 0,
  133311. };
  133312. static float _vq_quantthresh__44u2__p6_0[] = {
  133313. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133314. 12.5, 17.5, 22.5, 27.5,
  133315. };
  133316. static long _vq_quantmap__44u2__p6_0[] = {
  133317. 11, 9, 7, 5, 3, 1, 0, 2,
  133318. 4, 6, 8, 10, 12,
  133319. };
  133320. static encode_aux_threshmatch _vq_auxt__44u2__p6_0 = {
  133321. _vq_quantthresh__44u2__p6_0,
  133322. _vq_quantmap__44u2__p6_0,
  133323. 13,
  133324. 13
  133325. };
  133326. static static_codebook _44u2__p6_0 = {
  133327. 2, 169,
  133328. _vq_lengthlist__44u2__p6_0,
  133329. 1, -526516224, 1616117760, 4, 0,
  133330. _vq_quantlist__44u2__p6_0,
  133331. NULL,
  133332. &_vq_auxt__44u2__p6_0,
  133333. NULL,
  133334. 0
  133335. };
  133336. static long _vq_quantlist__44u2__p6_1[] = {
  133337. 2,
  133338. 1,
  133339. 3,
  133340. 0,
  133341. 4,
  133342. };
  133343. static long _vq_lengthlist__44u2__p6_1[] = {
  133344. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133345. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133346. };
  133347. static float _vq_quantthresh__44u2__p6_1[] = {
  133348. -1.5, -0.5, 0.5, 1.5,
  133349. };
  133350. static long _vq_quantmap__44u2__p6_1[] = {
  133351. 3, 1, 0, 2, 4,
  133352. };
  133353. static encode_aux_threshmatch _vq_auxt__44u2__p6_1 = {
  133354. _vq_quantthresh__44u2__p6_1,
  133355. _vq_quantmap__44u2__p6_1,
  133356. 5,
  133357. 5
  133358. };
  133359. static static_codebook _44u2__p6_1 = {
  133360. 2, 25,
  133361. _vq_lengthlist__44u2__p6_1,
  133362. 1, -533725184, 1611661312, 3, 0,
  133363. _vq_quantlist__44u2__p6_1,
  133364. NULL,
  133365. &_vq_auxt__44u2__p6_1,
  133366. NULL,
  133367. 0
  133368. };
  133369. static long _vq_quantlist__44u2__p7_0[] = {
  133370. 4,
  133371. 3,
  133372. 5,
  133373. 2,
  133374. 6,
  133375. 1,
  133376. 7,
  133377. 0,
  133378. 8,
  133379. };
  133380. static long _vq_lengthlist__44u2__p7_0[] = {
  133381. 1, 3, 2,12,12,12,12,12,12, 4,12,12,12,12,12,12,
  133382. 12,12, 5,12,12,12,12,12,12,12,12,12,12,11,11,11,
  133383. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133384. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133385. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  133386. 11,
  133387. };
  133388. static float _vq_quantthresh__44u2__p7_0[] = {
  133389. -591.5, -422.5, -253.5, -84.5, 84.5, 253.5, 422.5, 591.5,
  133390. };
  133391. static long _vq_quantmap__44u2__p7_0[] = {
  133392. 7, 5, 3, 1, 0, 2, 4, 6,
  133393. 8,
  133394. };
  133395. static encode_aux_threshmatch _vq_auxt__44u2__p7_0 = {
  133396. _vq_quantthresh__44u2__p7_0,
  133397. _vq_quantmap__44u2__p7_0,
  133398. 9,
  133399. 9
  133400. };
  133401. static static_codebook _44u2__p7_0 = {
  133402. 2, 81,
  133403. _vq_lengthlist__44u2__p7_0,
  133404. 1, -516612096, 1626677248, 4, 0,
  133405. _vq_quantlist__44u2__p7_0,
  133406. NULL,
  133407. &_vq_auxt__44u2__p7_0,
  133408. NULL,
  133409. 0
  133410. };
  133411. static long _vq_quantlist__44u2__p7_1[] = {
  133412. 6,
  133413. 5,
  133414. 7,
  133415. 4,
  133416. 8,
  133417. 3,
  133418. 9,
  133419. 2,
  133420. 10,
  133421. 1,
  133422. 11,
  133423. 0,
  133424. 12,
  133425. };
  133426. static long _vq_lengthlist__44u2__p7_1[] = {
  133427. 1, 4, 4, 7, 6, 7, 6, 8, 7, 9, 7, 9, 8, 4, 7, 6,
  133428. 8, 8, 9, 8,10, 9,10,10,11,11, 4, 7, 7, 8, 8, 8,
  133429. 8, 9,10,11,11,11,11, 6, 8, 8,10,10,10,10,11,11,
  133430. 12,12,12,12, 7, 8, 8,10,10,10,10,11,11,12,12,13,
  133431. 13, 7, 9, 9,11,10,12,12,13,13,14,13,14,14, 7, 9,
  133432. 9,10,11,11,12,13,13,13,13,16,14, 9,10,10,12,12,
  133433. 13,13,14,14,15,16,15,16, 9,10,10,12,12,12,13,14,
  133434. 14,14,15,16,15,10,12,12,13,13,15,13,16,16,15,17,
  133435. 17,17,10,11,11,12,14,14,14,15,15,17,17,15,17,11,
  133436. 12,12,14,14,14,15,15,15,17,16,17,17,10,12,12,13,
  133437. 14,14,14,17,15,17,17,17,17,
  133438. };
  133439. static float _vq_quantthresh__44u2__p7_1[] = {
  133440. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  133441. 32.5, 45.5, 58.5, 71.5,
  133442. };
  133443. static long _vq_quantmap__44u2__p7_1[] = {
  133444. 11, 9, 7, 5, 3, 1, 0, 2,
  133445. 4, 6, 8, 10, 12,
  133446. };
  133447. static encode_aux_threshmatch _vq_auxt__44u2__p7_1 = {
  133448. _vq_quantthresh__44u2__p7_1,
  133449. _vq_quantmap__44u2__p7_1,
  133450. 13,
  133451. 13
  133452. };
  133453. static static_codebook _44u2__p7_1 = {
  133454. 2, 169,
  133455. _vq_lengthlist__44u2__p7_1,
  133456. 1, -523010048, 1618608128, 4, 0,
  133457. _vq_quantlist__44u2__p7_1,
  133458. NULL,
  133459. &_vq_auxt__44u2__p7_1,
  133460. NULL,
  133461. 0
  133462. };
  133463. static long _vq_quantlist__44u2__p7_2[] = {
  133464. 6,
  133465. 5,
  133466. 7,
  133467. 4,
  133468. 8,
  133469. 3,
  133470. 9,
  133471. 2,
  133472. 10,
  133473. 1,
  133474. 11,
  133475. 0,
  133476. 12,
  133477. };
  133478. static long _vq_lengthlist__44u2__p7_2[] = {
  133479. 2, 5, 5, 6, 6, 7, 7, 8, 7, 8, 8, 8, 8, 5, 6, 6,
  133480. 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 5, 6, 6, 7, 7, 8,
  133481. 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7, 8, 8, 8, 8, 8,
  133482. 9, 9, 9, 9, 6, 7, 7, 8, 7, 8, 8, 9, 9, 9, 9, 9,
  133483. 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 7, 8,
  133484. 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 9,
  133485. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  133486. 9, 9, 9, 9, 9, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133487. 9, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8,
  133488. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9,
  133489. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133490. };
  133491. static float _vq_quantthresh__44u2__p7_2[] = {
  133492. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  133493. 2.5, 3.5, 4.5, 5.5,
  133494. };
  133495. static long _vq_quantmap__44u2__p7_2[] = {
  133496. 11, 9, 7, 5, 3, 1, 0, 2,
  133497. 4, 6, 8, 10, 12,
  133498. };
  133499. static encode_aux_threshmatch _vq_auxt__44u2__p7_2 = {
  133500. _vq_quantthresh__44u2__p7_2,
  133501. _vq_quantmap__44u2__p7_2,
  133502. 13,
  133503. 13
  133504. };
  133505. static static_codebook _44u2__p7_2 = {
  133506. 2, 169,
  133507. _vq_lengthlist__44u2__p7_2,
  133508. 1, -531103744, 1611661312, 4, 0,
  133509. _vq_quantlist__44u2__p7_2,
  133510. NULL,
  133511. &_vq_auxt__44u2__p7_2,
  133512. NULL,
  133513. 0
  133514. };
  133515. static long _huff_lengthlist__44u2__short[] = {
  133516. 13,15,17,17,15,15,12,17,11, 9, 7,10,10, 9,12,17,
  133517. 10, 6, 3, 6, 5, 7,10,17,15,10, 6, 9, 8, 9,11,17,
  133518. 15, 8, 4, 7, 3, 5, 9,16,16,10, 5, 8, 4, 5, 8,16,
  133519. 13,11, 5, 8, 3, 3, 5,14,13,12, 7,10, 5, 5, 7,14,
  133520. };
  133521. static static_codebook _huff_book__44u2__short = {
  133522. 2, 64,
  133523. _huff_lengthlist__44u2__short,
  133524. 0, 0, 0, 0, 0,
  133525. NULL,
  133526. NULL,
  133527. NULL,
  133528. NULL,
  133529. 0
  133530. };
  133531. static long _huff_lengthlist__44u3__long[] = {
  133532. 6, 9,13,12,14,11,10,13, 8, 4, 5, 7, 8, 7, 8,12,
  133533. 11, 4, 3, 5, 5, 7, 9,14,11, 6, 5, 6, 6, 6, 7,13,
  133534. 13, 7, 5, 6, 4, 5, 7,14,11, 7, 6, 6, 5, 5, 6,13,
  133535. 9, 7, 8, 6, 7, 5, 3, 9, 9,12,13,12,14,10, 6, 7,
  133536. };
  133537. static static_codebook _huff_book__44u3__long = {
  133538. 2, 64,
  133539. _huff_lengthlist__44u3__long,
  133540. 0, 0, 0, 0, 0,
  133541. NULL,
  133542. NULL,
  133543. NULL,
  133544. NULL,
  133545. 0
  133546. };
  133547. static long _vq_quantlist__44u3__p1_0[] = {
  133548. 1,
  133549. 0,
  133550. 2,
  133551. };
  133552. static long _vq_lengthlist__44u3__p1_0[] = {
  133553. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  133554. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  133555. 11, 8,11,11, 8,11,11,11,13,14,11,14,14, 8,11,11,
  133556. 10,14,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  133557. 11,11,11,14,14,10,12,14, 8,11,11,11,14,14,11,14,
  133558. 13,
  133559. };
  133560. static float _vq_quantthresh__44u3__p1_0[] = {
  133561. -0.5, 0.5,
  133562. };
  133563. static long _vq_quantmap__44u3__p1_0[] = {
  133564. 1, 0, 2,
  133565. };
  133566. static encode_aux_threshmatch _vq_auxt__44u3__p1_0 = {
  133567. _vq_quantthresh__44u3__p1_0,
  133568. _vq_quantmap__44u3__p1_0,
  133569. 3,
  133570. 3
  133571. };
  133572. static static_codebook _44u3__p1_0 = {
  133573. 4, 81,
  133574. _vq_lengthlist__44u3__p1_0,
  133575. 1, -535822336, 1611661312, 2, 0,
  133576. _vq_quantlist__44u3__p1_0,
  133577. NULL,
  133578. &_vq_auxt__44u3__p1_0,
  133579. NULL,
  133580. 0
  133581. };
  133582. static long _vq_quantlist__44u3__p2_0[] = {
  133583. 1,
  133584. 0,
  133585. 2,
  133586. };
  133587. static long _vq_lengthlist__44u3__p2_0[] = {
  133588. 2, 5, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  133589. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 7, 8,
  133590. 8, 6, 8, 8, 7, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  133591. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 7, 8, 8, 6,
  133592. 8, 8, 8,10,10, 8, 8,10, 7, 8, 8, 8,10,10, 8,10,
  133593. 9,
  133594. };
  133595. static float _vq_quantthresh__44u3__p2_0[] = {
  133596. -0.5, 0.5,
  133597. };
  133598. static long _vq_quantmap__44u3__p2_0[] = {
  133599. 1, 0, 2,
  133600. };
  133601. static encode_aux_threshmatch _vq_auxt__44u3__p2_0 = {
  133602. _vq_quantthresh__44u3__p2_0,
  133603. _vq_quantmap__44u3__p2_0,
  133604. 3,
  133605. 3
  133606. };
  133607. static static_codebook _44u3__p2_0 = {
  133608. 4, 81,
  133609. _vq_lengthlist__44u3__p2_0,
  133610. 1, -535822336, 1611661312, 2, 0,
  133611. _vq_quantlist__44u3__p2_0,
  133612. NULL,
  133613. &_vq_auxt__44u3__p2_0,
  133614. NULL,
  133615. 0
  133616. };
  133617. static long _vq_quantlist__44u3__p3_0[] = {
  133618. 2,
  133619. 1,
  133620. 3,
  133621. 0,
  133622. 4,
  133623. };
  133624. static long _vq_lengthlist__44u3__p3_0[] = {
  133625. 2, 4, 4, 7, 7, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  133626. 9, 9,12,12, 8, 9, 9,11,12, 5, 7, 7,10,10, 7, 9,
  133627. 9,11,11, 7, 9, 9,10,11,10,11,11,13,13, 9,10,11,
  133628. 13,13, 5, 7, 7,10,10, 7, 9, 9,11,10, 7, 9, 9,11,
  133629. 11, 9,11,10,13,13,10,11,11,14,13, 8,10,10,14,13,
  133630. 10,11,11,15,14, 9,11,11,14,14,13,14,13,16,16,12,
  133631. 13,13,15,15, 8,10,10,13,14, 9,11,11,14,14,10,11,
  133632. 11,14,15,12,13,13,15,15,13,14,14,15,16, 5, 7, 7,
  133633. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,12,10,11,11,14,
  133634. 14,10,11,11,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  133635. 9,11,11,13,13,12,12,13,15,15,11,12,13,15,16, 7,
  133636. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  133637. 12,15,13,11,13,13,15,16, 9,12,11,15,14,11,12,13,
  133638. 16,15,11,13,13,15,16,14,14,15,17,16,13,15,16, 0,
  133639. 17, 9,11,11,15,15,10,13,12,15,15,11,13,13,15,16,
  133640. 13,15,13,16,15,14,16,15, 0,19, 5, 7, 7,10,10, 7,
  133641. 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,14,10,11,
  133642. 12,14,14, 7, 9, 9,12,12, 9,11,11,14,13, 9,10,11,
  133643. 12,13,11,13,13,16,16,11,12,13,13,16, 7, 9, 9,12,
  133644. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,15,
  133645. 12,13,12,15,14, 9,11,11,15,14,11,13,12,16,16,10,
  133646. 12,12,15,15,13,15,15,17,19,13,14,15,16,17,10,12,
  133647. 12,15,15,11,13,13,16,16,11,13,13,15,16,13,15,15,
  133648. 0, 0,14,15,15,16,16, 8,10,10,14,14,10,12,12,15,
  133649. 15,10,12,11,15,16,14,15,15,19,20,13,14,14,18,16,
  133650. 9,11,11,15,15,11,13,13,17,16,11,13,13,16,16,15,
  133651. 17,17,20,20,14,15,16,17,20, 9,11,11,15,15,10,13,
  133652. 12,16,15,11,13,13,15,17,14,16,15,18, 0,14,16,15,
  133653. 18,20,12,14,14, 0, 0,14,14,16, 0, 0,13,16,15, 0,
  133654. 0,17,17,18, 0, 0,16,17,19,19, 0,12,14,14,18, 0,
  133655. 12,16,14, 0,17,13,15,15,18, 0,16,18,17, 0,17,16,
  133656. 18,17, 0, 0, 7,10,10,14,14,10,12,11,15,15,10,12,
  133657. 12,16,15,13,15,15,18, 0,14,15,15,17, 0, 9,11,11,
  133658. 15,15,11,13,13,16,16,11,12,13,16,16,14,15,16,17,
  133659. 17,14,16,16,16,18, 9,11,12,16,16,11,13,13,17,17,
  133660. 11,14,13,20,17,15,16,16,19, 0,15,16,17, 0,19,11,
  133661. 13,14,17,16,14,15,15,20,18,13,14,15,17,19,16,18,
  133662. 18, 0,20,16,16,19,17, 0,12,15,14,17, 0,14,15,15,
  133663. 18,19,13,16,15,19,20,15,18,18, 0,20,17, 0,16, 0,
  133664. 0,
  133665. };
  133666. static float _vq_quantthresh__44u3__p3_0[] = {
  133667. -1.5, -0.5, 0.5, 1.5,
  133668. };
  133669. static long _vq_quantmap__44u3__p3_0[] = {
  133670. 3, 1, 0, 2, 4,
  133671. };
  133672. static encode_aux_threshmatch _vq_auxt__44u3__p3_0 = {
  133673. _vq_quantthresh__44u3__p3_0,
  133674. _vq_quantmap__44u3__p3_0,
  133675. 5,
  133676. 5
  133677. };
  133678. static static_codebook _44u3__p3_0 = {
  133679. 4, 625,
  133680. _vq_lengthlist__44u3__p3_0,
  133681. 1, -533725184, 1611661312, 3, 0,
  133682. _vq_quantlist__44u3__p3_0,
  133683. NULL,
  133684. &_vq_auxt__44u3__p3_0,
  133685. NULL,
  133686. 0
  133687. };
  133688. static long _vq_quantlist__44u3__p4_0[] = {
  133689. 2,
  133690. 1,
  133691. 3,
  133692. 0,
  133693. 4,
  133694. };
  133695. static long _vq_lengthlist__44u3__p4_0[] = {
  133696. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  133697. 9, 9,11,11, 9, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  133698. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  133699. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  133700. 10, 9,10, 9,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  133701. 9,10,10,13,12, 9,10,10,12,13,12,12,12,14,14,11,
  133702. 12,12,13,14, 9, 9,10,12,12, 9,10,10,12,12, 9,10,
  133703. 10,12,13,11,12,11,14,13,12,12,12,14,13, 5, 7, 7,
  133704. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  133705. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  133706. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  133707. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  133708. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  133709. 13,13,10,11,11,13,13,12,12,13,12,15,12,13,13,15,
  133710. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  133711. 12,13,11,15,13,12,13,13,15,15, 5, 7, 7, 9, 9, 7,
  133712. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  133713. 11,12,12, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  133714. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  133715. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  133716. 11,11,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  133717. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  133718. 11,12,13,10,11,11,13,13,10,11,11,13,13,12,13,13,
  133719. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  133720. 13, 9,10,10,13,13,12,13,13,15,14,12,12,12,14,13,
  133721. 9,10,10,13,12,10,11,11,13,13,10,11,11,14,12,13,
  133722. 13,14,14,16,12,13,13,15,15, 9,10,10,13,13,10,11,
  133723. 10,14,13,10,11,11,13,14,12,14,13,15,14,13,13,13,
  133724. 15,15,11,13,12,15,14,11,12,13,14,15,12,13,13,16,
  133725. 14,14,12,15,12,16,14,15,15,17,15,11,12,12,14,14,
  133726. 11,13,11,15,14,12,13,13,15,15,13,15,12,17,13,14,
  133727. 15,15,16,16, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  133728. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  133729. 13,12,10,11,11,14,13,10,10,11,13,14,12,13,13,15,
  133730. 15,12,12,13,14,16, 9,10,10,13,13,10,11,11,13,14,
  133731. 10,11,11,14,13,12,13,13,14,15,13,14,13,16,14,11,
  133732. 12,12,14,14,12,13,13,15,14,11,12,13,14,15,14,15,
  133733. 15,16,16,13,13,15,13,16,11,12,12,14,15,12,13,13,
  133734. 14,15,11,13,12,15,14,14,15,15,16,16,14,15,12,16,
  133735. 13,
  133736. };
  133737. static float _vq_quantthresh__44u3__p4_0[] = {
  133738. -1.5, -0.5, 0.5, 1.5,
  133739. };
  133740. static long _vq_quantmap__44u3__p4_0[] = {
  133741. 3, 1, 0, 2, 4,
  133742. };
  133743. static encode_aux_threshmatch _vq_auxt__44u3__p4_0 = {
  133744. _vq_quantthresh__44u3__p4_0,
  133745. _vq_quantmap__44u3__p4_0,
  133746. 5,
  133747. 5
  133748. };
  133749. static static_codebook _44u3__p4_0 = {
  133750. 4, 625,
  133751. _vq_lengthlist__44u3__p4_0,
  133752. 1, -533725184, 1611661312, 3, 0,
  133753. _vq_quantlist__44u3__p4_0,
  133754. NULL,
  133755. &_vq_auxt__44u3__p4_0,
  133756. NULL,
  133757. 0
  133758. };
  133759. static long _vq_quantlist__44u3__p5_0[] = {
  133760. 4,
  133761. 3,
  133762. 5,
  133763. 2,
  133764. 6,
  133765. 1,
  133766. 7,
  133767. 0,
  133768. 8,
  133769. };
  133770. static long _vq_lengthlist__44u3__p5_0[] = {
  133771. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  133772. 10,10, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  133773. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,10, 7, 8, 8,
  133774. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  133775. 10,10,11,10,11,11,12,12, 9,10,10,10,10,11,11,12,
  133776. 12,
  133777. };
  133778. static float _vq_quantthresh__44u3__p5_0[] = {
  133779. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  133780. };
  133781. static long _vq_quantmap__44u3__p5_0[] = {
  133782. 7, 5, 3, 1, 0, 2, 4, 6,
  133783. 8,
  133784. };
  133785. static encode_aux_threshmatch _vq_auxt__44u3__p5_0 = {
  133786. _vq_quantthresh__44u3__p5_0,
  133787. _vq_quantmap__44u3__p5_0,
  133788. 9,
  133789. 9
  133790. };
  133791. static static_codebook _44u3__p5_0 = {
  133792. 2, 81,
  133793. _vq_lengthlist__44u3__p5_0,
  133794. 1, -531628032, 1611661312, 4, 0,
  133795. _vq_quantlist__44u3__p5_0,
  133796. NULL,
  133797. &_vq_auxt__44u3__p5_0,
  133798. NULL,
  133799. 0
  133800. };
  133801. static long _vq_quantlist__44u3__p6_0[] = {
  133802. 6,
  133803. 5,
  133804. 7,
  133805. 4,
  133806. 8,
  133807. 3,
  133808. 9,
  133809. 2,
  133810. 10,
  133811. 1,
  133812. 11,
  133813. 0,
  133814. 12,
  133815. };
  133816. static long _vq_lengthlist__44u3__p6_0[] = {
  133817. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,11,13,14, 4, 6, 5,
  133818. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  133819. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  133820. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  133821. 15, 8, 9, 9,11,10,11,11,12,12,13,13,15,16, 8, 9,
  133822. 9,10,11,11,11,12,12,13,13,16,16,10,10,11,11,11,
  133823. 12,12,13,13,13,14,17,16, 9,10,11,12,11,12,12,13,
  133824. 13,13,13,16,18,11,12,11,12,12,13,13,13,14,15,14,
  133825. 17,17,11,11,12,12,12,13,13,13,14,14,15,18,17,14,
  133826. 15,15,15,15,16,16,17,17,19,18, 0,20,14,15,14,15,
  133827. 15,16,16,16,17,18,16,20,18,
  133828. };
  133829. static float _vq_quantthresh__44u3__p6_0[] = {
  133830. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  133831. 12.5, 17.5, 22.5, 27.5,
  133832. };
  133833. static long _vq_quantmap__44u3__p6_0[] = {
  133834. 11, 9, 7, 5, 3, 1, 0, 2,
  133835. 4, 6, 8, 10, 12,
  133836. };
  133837. static encode_aux_threshmatch _vq_auxt__44u3__p6_0 = {
  133838. _vq_quantthresh__44u3__p6_0,
  133839. _vq_quantmap__44u3__p6_0,
  133840. 13,
  133841. 13
  133842. };
  133843. static static_codebook _44u3__p6_0 = {
  133844. 2, 169,
  133845. _vq_lengthlist__44u3__p6_0,
  133846. 1, -526516224, 1616117760, 4, 0,
  133847. _vq_quantlist__44u3__p6_0,
  133848. NULL,
  133849. &_vq_auxt__44u3__p6_0,
  133850. NULL,
  133851. 0
  133852. };
  133853. static long _vq_quantlist__44u3__p6_1[] = {
  133854. 2,
  133855. 1,
  133856. 3,
  133857. 0,
  133858. 4,
  133859. };
  133860. static long _vq_lengthlist__44u3__p6_1[] = {
  133861. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  133862. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  133863. };
  133864. static float _vq_quantthresh__44u3__p6_1[] = {
  133865. -1.5, -0.5, 0.5, 1.5,
  133866. };
  133867. static long _vq_quantmap__44u3__p6_1[] = {
  133868. 3, 1, 0, 2, 4,
  133869. };
  133870. static encode_aux_threshmatch _vq_auxt__44u3__p6_1 = {
  133871. _vq_quantthresh__44u3__p6_1,
  133872. _vq_quantmap__44u3__p6_1,
  133873. 5,
  133874. 5
  133875. };
  133876. static static_codebook _44u3__p6_1 = {
  133877. 2, 25,
  133878. _vq_lengthlist__44u3__p6_1,
  133879. 1, -533725184, 1611661312, 3, 0,
  133880. _vq_quantlist__44u3__p6_1,
  133881. NULL,
  133882. &_vq_auxt__44u3__p6_1,
  133883. NULL,
  133884. 0
  133885. };
  133886. static long _vq_quantlist__44u3__p7_0[] = {
  133887. 4,
  133888. 3,
  133889. 5,
  133890. 2,
  133891. 6,
  133892. 1,
  133893. 7,
  133894. 0,
  133895. 8,
  133896. };
  133897. static long _vq_lengthlist__44u3__p7_0[] = {
  133898. 1, 3, 3,10,10,10,10,10,10, 4,10,10,10,10,10,10,
  133899. 10,10, 4,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  133900. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133901. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133902. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  133903. 9,
  133904. };
  133905. static float _vq_quantthresh__44u3__p7_0[] = {
  133906. -892.5, -637.5, -382.5, -127.5, 127.5, 382.5, 637.5, 892.5,
  133907. };
  133908. static long _vq_quantmap__44u3__p7_0[] = {
  133909. 7, 5, 3, 1, 0, 2, 4, 6,
  133910. 8,
  133911. };
  133912. static encode_aux_threshmatch _vq_auxt__44u3__p7_0 = {
  133913. _vq_quantthresh__44u3__p7_0,
  133914. _vq_quantmap__44u3__p7_0,
  133915. 9,
  133916. 9
  133917. };
  133918. static static_codebook _44u3__p7_0 = {
  133919. 2, 81,
  133920. _vq_lengthlist__44u3__p7_0,
  133921. 1, -515907584, 1627381760, 4, 0,
  133922. _vq_quantlist__44u3__p7_0,
  133923. NULL,
  133924. &_vq_auxt__44u3__p7_0,
  133925. NULL,
  133926. 0
  133927. };
  133928. static long _vq_quantlist__44u3__p7_1[] = {
  133929. 7,
  133930. 6,
  133931. 8,
  133932. 5,
  133933. 9,
  133934. 4,
  133935. 10,
  133936. 3,
  133937. 11,
  133938. 2,
  133939. 12,
  133940. 1,
  133941. 13,
  133942. 0,
  133943. 14,
  133944. };
  133945. static long _vq_lengthlist__44u3__p7_1[] = {
  133946. 1, 4, 4, 6, 6, 7, 6, 8, 7, 9, 8,10, 9,11,11, 4,
  133947. 7, 7, 8, 7, 9, 9,10,10,11,11,11,11,12,12, 4, 7,
  133948. 7, 7, 7, 9, 9,10,10,11,11,12,12,12,11, 6, 8, 8,
  133949. 9, 9,10,10,11,11,12,12,13,12,13,13, 6, 8, 8, 9,
  133950. 9,10,11,11,11,12,12,13,14,13,13, 8, 9, 9,11,11,
  133951. 12,12,12,13,14,13,14,14,14,15, 8, 9, 9,11,11,11,
  133952. 12,13,14,13,14,15,17,14,15, 9,10,10,12,12,13,13,
  133953. 13,14,15,15,15,16,16,16, 9,11,11,12,12,13,13,14,
  133954. 14,14,15,16,16,16,16,10,12,12,13,13,14,14,15,15,
  133955. 15,16,17,17,17,17,10,12,11,13,13,15,14,15,14,16,
  133956. 17,16,16,16,16,11,13,12,14,14,14,14,15,16,17,16,
  133957. 17,17,17,17,11,13,12,14,14,14,15,17,16,17,17,17,
  133958. 17,17,17,12,13,13,15,16,15,16,17,17,16,16,17,17,
  133959. 17,17,12,13,13,15,15,15,16,17,17,17,16,17,16,17,
  133960. 17,
  133961. };
  133962. static float _vq_quantthresh__44u3__p7_1[] = {
  133963. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  133964. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  133965. };
  133966. static long _vq_quantmap__44u3__p7_1[] = {
  133967. 13, 11, 9, 7, 5, 3, 1, 0,
  133968. 2, 4, 6, 8, 10, 12, 14,
  133969. };
  133970. static encode_aux_threshmatch _vq_auxt__44u3__p7_1 = {
  133971. _vq_quantthresh__44u3__p7_1,
  133972. _vq_quantmap__44u3__p7_1,
  133973. 15,
  133974. 15
  133975. };
  133976. static static_codebook _44u3__p7_1 = {
  133977. 2, 225,
  133978. _vq_lengthlist__44u3__p7_1,
  133979. 1, -522338304, 1620115456, 4, 0,
  133980. _vq_quantlist__44u3__p7_1,
  133981. NULL,
  133982. &_vq_auxt__44u3__p7_1,
  133983. NULL,
  133984. 0
  133985. };
  133986. static long _vq_quantlist__44u3__p7_2[] = {
  133987. 8,
  133988. 7,
  133989. 9,
  133990. 6,
  133991. 10,
  133992. 5,
  133993. 11,
  133994. 4,
  133995. 12,
  133996. 3,
  133997. 13,
  133998. 2,
  133999. 14,
  134000. 1,
  134001. 15,
  134002. 0,
  134003. 16,
  134004. };
  134005. static long _vq_lengthlist__44u3__p7_2[] = {
  134006. 2, 5, 5, 7, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134007. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134008. 10,10, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9,
  134009. 9,10, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134010. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134011. 9,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134012. 10,10,10,10,10,10, 7, 8, 8, 9, 8, 9, 9, 9, 9,10,
  134013. 9,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134014. 9,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9,10,
  134015. 9,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,10,
  134016. 9,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134017. 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,
  134018. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10,
  134019. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  134020. 10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,10,
  134021. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,11, 9,
  134022. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134023. 9,10,10,10,10,10,10,10,10,10,10,10,11,11,11,10,
  134024. 11,
  134025. };
  134026. static float _vq_quantthresh__44u3__p7_2[] = {
  134027. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134028. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134029. };
  134030. static long _vq_quantmap__44u3__p7_2[] = {
  134031. 15, 13, 11, 9, 7, 5, 3, 1,
  134032. 0, 2, 4, 6, 8, 10, 12, 14,
  134033. 16,
  134034. };
  134035. static encode_aux_threshmatch _vq_auxt__44u3__p7_2 = {
  134036. _vq_quantthresh__44u3__p7_2,
  134037. _vq_quantmap__44u3__p7_2,
  134038. 17,
  134039. 17
  134040. };
  134041. static static_codebook _44u3__p7_2 = {
  134042. 2, 289,
  134043. _vq_lengthlist__44u3__p7_2,
  134044. 1, -529530880, 1611661312, 5, 0,
  134045. _vq_quantlist__44u3__p7_2,
  134046. NULL,
  134047. &_vq_auxt__44u3__p7_2,
  134048. NULL,
  134049. 0
  134050. };
  134051. static long _huff_lengthlist__44u3__short[] = {
  134052. 14,14,14,15,13,15,12,16,10, 8, 7, 9, 9, 8,12,16,
  134053. 10, 5, 4, 6, 5, 6, 9,16,14, 8, 6, 8, 7, 8,10,16,
  134054. 14, 7, 4, 6, 3, 5, 8,16,15, 9, 5, 7, 4, 4, 7,16,
  134055. 13,10, 6, 7, 4, 3, 4,13,13,12, 7, 9, 5, 5, 6,12,
  134056. };
  134057. static static_codebook _huff_book__44u3__short = {
  134058. 2, 64,
  134059. _huff_lengthlist__44u3__short,
  134060. 0, 0, 0, 0, 0,
  134061. NULL,
  134062. NULL,
  134063. NULL,
  134064. NULL,
  134065. 0
  134066. };
  134067. static long _huff_lengthlist__44u4__long[] = {
  134068. 3, 8,12,12,13,12,11,13, 5, 4, 6, 7, 8, 8, 9,13,
  134069. 9, 5, 4, 5, 5, 7, 9,13, 9, 6, 5, 6, 6, 7, 8,12,
  134070. 12, 7, 5, 6, 4, 5, 8,13,11, 7, 6, 6, 5, 5, 6,12,
  134071. 10, 8, 8, 7, 7, 5, 3, 8,10,12,13,12,12, 9, 6, 7,
  134072. };
  134073. static static_codebook _huff_book__44u4__long = {
  134074. 2, 64,
  134075. _huff_lengthlist__44u4__long,
  134076. 0, 0, 0, 0, 0,
  134077. NULL,
  134078. NULL,
  134079. NULL,
  134080. NULL,
  134081. 0
  134082. };
  134083. static long _vq_quantlist__44u4__p1_0[] = {
  134084. 1,
  134085. 0,
  134086. 2,
  134087. };
  134088. static long _vq_lengthlist__44u4__p1_0[] = {
  134089. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  134090. 10,11, 5, 8, 8, 8,11,10, 8,11,11, 4, 8, 8, 8,11,
  134091. 11, 8,11,11, 8,11,11,11,13,14,11,15,14, 8,11,11,
  134092. 10,13,12,11,14,14, 4, 8, 8, 8,11,11, 8,11,11, 7,
  134093. 11,11,11,15,14,10,12,14, 8,11,11,11,14,14,11,14,
  134094. 13,
  134095. };
  134096. static float _vq_quantthresh__44u4__p1_0[] = {
  134097. -0.5, 0.5,
  134098. };
  134099. static long _vq_quantmap__44u4__p1_0[] = {
  134100. 1, 0, 2,
  134101. };
  134102. static encode_aux_threshmatch _vq_auxt__44u4__p1_0 = {
  134103. _vq_quantthresh__44u4__p1_0,
  134104. _vq_quantmap__44u4__p1_0,
  134105. 3,
  134106. 3
  134107. };
  134108. static static_codebook _44u4__p1_0 = {
  134109. 4, 81,
  134110. _vq_lengthlist__44u4__p1_0,
  134111. 1, -535822336, 1611661312, 2, 0,
  134112. _vq_quantlist__44u4__p1_0,
  134113. NULL,
  134114. &_vq_auxt__44u4__p1_0,
  134115. NULL,
  134116. 0
  134117. };
  134118. static long _vq_quantlist__44u4__p2_0[] = {
  134119. 1,
  134120. 0,
  134121. 2,
  134122. };
  134123. static long _vq_lengthlist__44u4__p2_0[] = {
  134124. 2, 5, 5, 5, 6, 6, 5, 6, 6, 5, 6, 6, 7, 8, 8, 6,
  134125. 8, 8, 5, 6, 6, 6, 8, 8, 7, 8, 8, 5, 7, 6, 6, 8,
  134126. 8, 6, 8, 8, 6, 8, 8, 8, 9,10, 8,10,10, 6, 8, 8,
  134127. 8,10, 8, 8,10,10, 5, 6, 6, 6, 8, 8, 6, 8, 8, 6,
  134128. 8, 8, 8,10,10, 8, 8,10, 6, 8, 8, 8,10,10, 8,10,
  134129. 9,
  134130. };
  134131. static float _vq_quantthresh__44u4__p2_0[] = {
  134132. -0.5, 0.5,
  134133. };
  134134. static long _vq_quantmap__44u4__p2_0[] = {
  134135. 1, 0, 2,
  134136. };
  134137. static encode_aux_threshmatch _vq_auxt__44u4__p2_0 = {
  134138. _vq_quantthresh__44u4__p2_0,
  134139. _vq_quantmap__44u4__p2_0,
  134140. 3,
  134141. 3
  134142. };
  134143. static static_codebook _44u4__p2_0 = {
  134144. 4, 81,
  134145. _vq_lengthlist__44u4__p2_0,
  134146. 1, -535822336, 1611661312, 2, 0,
  134147. _vq_quantlist__44u4__p2_0,
  134148. NULL,
  134149. &_vq_auxt__44u4__p2_0,
  134150. NULL,
  134151. 0
  134152. };
  134153. static long _vq_quantlist__44u4__p3_0[] = {
  134154. 2,
  134155. 1,
  134156. 3,
  134157. 0,
  134158. 4,
  134159. };
  134160. static long _vq_lengthlist__44u4__p3_0[] = {
  134161. 2, 4, 4, 8, 8, 5, 7, 7, 9, 9, 5, 7, 7, 9, 9, 8,
  134162. 10, 9,12,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134163. 9,11,11, 7, 9, 9,11,11,10,12,11,14,14, 9,10,11,
  134164. 13,14, 5, 7, 7,10,10, 7, 9, 9,11,11, 7, 9, 9,11,
  134165. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  134166. 10,12,12,15,14, 9,11,11,15,14,13,14,14,17,17,12,
  134167. 14,14,16,16, 8,10,10,14,14, 9,11,11,14,15,10,12,
  134168. 12,14,15,12,14,13,16,16,13,14,15,15,18, 4, 7, 7,
  134169. 10,10, 7, 9, 9,12,11, 7, 9, 9,11,12,10,12,11,15,
  134170. 14,10,11,12,14,15, 7, 9, 9,12,12, 9,11,12,13,13,
  134171. 9,11,12,13,13,12,13,13,15,16,11,13,13,15,16, 7,
  134172. 9, 9,12,12, 9,11,10,13,12, 9,11,12,13,14,11,13,
  134173. 12,16,14,12,13,13,15,16,10,12,12,16,15,11,13,13,
  134174. 17,16,11,13,13,17,16,14,15,15,17,17,14,16,16,18,
  134175. 20, 9,11,11,15,16,11,13,12,16,16,11,13,13,16,17,
  134176. 14,15,14,18,16,14,16,16,17,20, 5, 7, 7,10,10, 7,
  134177. 9, 9,12,11, 7, 9,10,11,12,10,12,11,15,15,10,12,
  134178. 12,14,14, 7, 9, 9,12,12, 9,12,11,14,13, 9,10,11,
  134179. 12,13,12,13,14,16,16,11,12,13,14,16, 7, 9, 9,12,
  134180. 12, 9,12,11,13,13, 9,12,11,13,13,11,13,13,16,16,
  134181. 12,13,13,16,15, 9,11,11,16,14,11,13,13,16,16,11,
  134182. 12,13,16,16,14,16,16,17,17,13,14,15,16,17,10,12,
  134183. 12,15,15,11,13,13,16,17,11,13,13,16,16,14,16,15,
  134184. 19,19,14,15,15,17,18, 8,10,10,14,14,10,12,12,15,
  134185. 15,10,12,12,16,16,14,16,15,20,19,13,15,15,17,16,
  134186. 9,12,12,16,16,11,13,13,16,18,11,14,13,16,17,16,
  134187. 17,16,20, 0,15,16,18,18,20, 9,11,11,15,15,11,14,
  134188. 12,17,16,11,13,13,17,17,15,17,15,20,20,14,16,16,
  134189. 17, 0,13,15,14,18,16,14,15,16, 0,18,14,16,16, 0,
  134190. 0,18,16, 0, 0,20,16,18,18, 0, 0,12,14,14,17,18,
  134191. 13,15,14,20,18,14,16,15,19,19,16,20,16, 0,18,16,
  134192. 19,17,19, 0, 8,10,10,14,14,10,12,12,16,15,10,12,
  134193. 12,16,16,13,15,15,18,17,14,16,16,19, 0, 9,11,11,
  134194. 16,15,11,14,13,18,17,11,12,13,17,18,14,17,16,18,
  134195. 18,15,16,17,18,18, 9,12,12,16,16,11,13,13,16,18,
  134196. 11,14,13,17,17,15,16,16,18,20,16,17,17,20,20,12,
  134197. 14,14,18,17,14,16,16, 0,19,13,14,15,18, 0,16, 0,
  134198. 0, 0, 0,16,16, 0,19,20,13,15,14, 0, 0,14,16,16,
  134199. 18,19,14,16,15, 0,20,16,20,18, 0,20,17,20,17, 0,
  134200. 0,
  134201. };
  134202. static float _vq_quantthresh__44u4__p3_0[] = {
  134203. -1.5, -0.5, 0.5, 1.5,
  134204. };
  134205. static long _vq_quantmap__44u4__p3_0[] = {
  134206. 3, 1, 0, 2, 4,
  134207. };
  134208. static encode_aux_threshmatch _vq_auxt__44u4__p3_0 = {
  134209. _vq_quantthresh__44u4__p3_0,
  134210. _vq_quantmap__44u4__p3_0,
  134211. 5,
  134212. 5
  134213. };
  134214. static static_codebook _44u4__p3_0 = {
  134215. 4, 625,
  134216. _vq_lengthlist__44u4__p3_0,
  134217. 1, -533725184, 1611661312, 3, 0,
  134218. _vq_quantlist__44u4__p3_0,
  134219. NULL,
  134220. &_vq_auxt__44u4__p3_0,
  134221. NULL,
  134222. 0
  134223. };
  134224. static long _vq_quantlist__44u4__p4_0[] = {
  134225. 2,
  134226. 1,
  134227. 3,
  134228. 0,
  134229. 4,
  134230. };
  134231. static long _vq_lengthlist__44u4__p4_0[] = {
  134232. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 9,
  134233. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  134234. 8,10,10, 7, 7, 8,10,10, 9,10,10,11,12, 9,10,10,
  134235. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  134236. 10, 9,10,10,12,11, 9,10,10,12,11, 9,10, 9,12,12,
  134237. 9,10,10,13,12, 9,10,10,12,12,12,12,12,14,14,11,
  134238. 12,12,13,14, 9, 9,10,12,12, 9,10,10,13,13, 9,10,
  134239. 10,12,13,11,12,12,14,13,11,12,12,14,14, 5, 7, 7,
  134240. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10,10,10,10,12,
  134241. 12, 9,10,10,12,12, 7, 8, 8,11,10, 8, 8, 9,11,11,
  134242. 8, 9, 9,11,11,11,11,11,12,13,10,11,11,13,13, 6,
  134243. 8, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134244. 10,13,11,10,11,11,13,13, 9,11,10,13,12,10,11,11,
  134245. 13,14,10,11,11,14,13,12,12,13,12,15,12,13,13,15,
  134246. 15, 9,10,10,12,13,10,11,10,13,12,10,11,11,13,14,
  134247. 12,13,11,15,13,13,13,13,15,15, 5, 7, 7, 9, 9, 7,
  134248. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12,10,10,
  134249. 11,12,13, 6, 8, 8,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134250. 10,11,10,11,11,13,13,10,10,11,11,13, 7, 8, 8,10,
  134251. 11, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,11,13,13,
  134252. 11,12,11,13,12, 9,10,10,13,12,10,11,11,14,13,10,
  134253. 10,11,12,13,12,13,13,15,15,12,11,13,13,14, 9,10,
  134254. 11,12,13,10,11,11,13,14,10,11,11,13,13,12,13,13,
  134255. 15,15,12,13,12,15,12, 8, 9, 9,12,12, 9,11,10,13,
  134256. 13, 9,10,10,13,13,12,13,13,15,15,12,12,12,14,14,
  134257. 9,10,10,13,13,10,11,11,13,14,10,11,11,14,13,13,
  134258. 13,14,14,16,13,13,13,15,15, 9,10,10,13,13,10,11,
  134259. 10,14,13,10,11,11,13,14,12,14,13,16,14,12,13,13,
  134260. 14,15,11,12,12,15,14,11,12,13,14,15,12,13,13,16,
  134261. 15,14,12,15,12,16,14,15,15,16,16,11,12,12,14,14,
  134262. 11,13,12,15,14,12,13,13,15,16,13,15,13,17,13,14,
  134263. 15,15,16,17, 8, 9, 9,12,12, 9,10,10,12,13, 9,10,
  134264. 10,13,13,12,12,12,14,14,12,13,13,15,15, 9,10,10,
  134265. 13,12,10,11,11,14,13,10,10,11,13,14,13,13,13,15,
  134266. 15,12,13,14,14,16, 9,10,10,13,13,10,11,11,13,14,
  134267. 10,11,11,14,14,13,13,13,15,15,13,14,13,16,14,11,
  134268. 12,12,15,14,12,13,13,16,15,11,12,13,14,15,14,15,
  134269. 15,17,16,13,13,15,13,16,11,12,13,14,15,13,13,13,
  134270. 15,16,11,13,12,15,14,14,15,15,16,16,14,15,12,17,
  134271. 13,
  134272. };
  134273. static float _vq_quantthresh__44u4__p4_0[] = {
  134274. -1.5, -0.5, 0.5, 1.5,
  134275. };
  134276. static long _vq_quantmap__44u4__p4_0[] = {
  134277. 3, 1, 0, 2, 4,
  134278. };
  134279. static encode_aux_threshmatch _vq_auxt__44u4__p4_0 = {
  134280. _vq_quantthresh__44u4__p4_0,
  134281. _vq_quantmap__44u4__p4_0,
  134282. 5,
  134283. 5
  134284. };
  134285. static static_codebook _44u4__p4_0 = {
  134286. 4, 625,
  134287. _vq_lengthlist__44u4__p4_0,
  134288. 1, -533725184, 1611661312, 3, 0,
  134289. _vq_quantlist__44u4__p4_0,
  134290. NULL,
  134291. &_vq_auxt__44u4__p4_0,
  134292. NULL,
  134293. 0
  134294. };
  134295. static long _vq_quantlist__44u4__p5_0[] = {
  134296. 4,
  134297. 3,
  134298. 5,
  134299. 2,
  134300. 6,
  134301. 1,
  134302. 7,
  134303. 0,
  134304. 8,
  134305. };
  134306. static long _vq_lengthlist__44u4__p5_0[] = {
  134307. 2, 3, 3, 6, 6, 7, 7, 9, 9, 4, 5, 5, 7, 7, 8, 8,
  134308. 10, 9, 4, 5, 5, 7, 7, 8, 8,10,10, 6, 7, 7, 8, 8,
  134309. 9, 9,11,10, 6, 7, 7, 8, 8, 9, 9,10,11, 7, 8, 8,
  134310. 9, 9,10,10,11,11, 7, 8, 8, 9, 9,10,10,11,11, 9,
  134311. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  134312. 12,
  134313. };
  134314. static float _vq_quantthresh__44u4__p5_0[] = {
  134315. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134316. };
  134317. static long _vq_quantmap__44u4__p5_0[] = {
  134318. 7, 5, 3, 1, 0, 2, 4, 6,
  134319. 8,
  134320. };
  134321. static encode_aux_threshmatch _vq_auxt__44u4__p5_0 = {
  134322. _vq_quantthresh__44u4__p5_0,
  134323. _vq_quantmap__44u4__p5_0,
  134324. 9,
  134325. 9
  134326. };
  134327. static static_codebook _44u4__p5_0 = {
  134328. 2, 81,
  134329. _vq_lengthlist__44u4__p5_0,
  134330. 1, -531628032, 1611661312, 4, 0,
  134331. _vq_quantlist__44u4__p5_0,
  134332. NULL,
  134333. &_vq_auxt__44u4__p5_0,
  134334. NULL,
  134335. 0
  134336. };
  134337. static long _vq_quantlist__44u4__p6_0[] = {
  134338. 6,
  134339. 5,
  134340. 7,
  134341. 4,
  134342. 8,
  134343. 3,
  134344. 9,
  134345. 2,
  134346. 10,
  134347. 1,
  134348. 11,
  134349. 0,
  134350. 12,
  134351. };
  134352. static long _vq_lengthlist__44u4__p6_0[] = {
  134353. 1, 4, 4, 6, 6, 8, 8, 9, 9,11,10,13,13, 4, 6, 5,
  134354. 8, 8, 9, 9,10,10,11,11,14,14, 4, 6, 6, 8, 8, 9,
  134355. 9,10,10,11,11,14,14, 6, 8, 8, 9, 9,10,10,11,11,
  134356. 12,12,15,15, 6, 8, 8, 9, 9,10,11,11,11,12,12,15,
  134357. 15, 8, 9, 9,11,10,11,11,12,12,13,13,16,16, 8, 9,
  134358. 9,10,10,11,11,12,12,13,13,16,16,10,10,10,12,11,
  134359. 12,12,13,13,14,14,16,16,10,10,10,11,12,12,12,13,
  134360. 13,13,14,16,17,11,12,11,12,12,13,13,14,14,15,14,
  134361. 18,17,11,11,12,12,12,13,13,14,14,14,15,19,18,14,
  134362. 15,14,15,15,17,16,17,17,17,17,21, 0,14,15,15,16,
  134363. 16,16,16,17,17,18,17,20,21,
  134364. };
  134365. static float _vq_quantthresh__44u4__p6_0[] = {
  134366. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  134367. 12.5, 17.5, 22.5, 27.5,
  134368. };
  134369. static long _vq_quantmap__44u4__p6_0[] = {
  134370. 11, 9, 7, 5, 3, 1, 0, 2,
  134371. 4, 6, 8, 10, 12,
  134372. };
  134373. static encode_aux_threshmatch _vq_auxt__44u4__p6_0 = {
  134374. _vq_quantthresh__44u4__p6_0,
  134375. _vq_quantmap__44u4__p6_0,
  134376. 13,
  134377. 13
  134378. };
  134379. static static_codebook _44u4__p6_0 = {
  134380. 2, 169,
  134381. _vq_lengthlist__44u4__p6_0,
  134382. 1, -526516224, 1616117760, 4, 0,
  134383. _vq_quantlist__44u4__p6_0,
  134384. NULL,
  134385. &_vq_auxt__44u4__p6_0,
  134386. NULL,
  134387. 0
  134388. };
  134389. static long _vq_quantlist__44u4__p6_1[] = {
  134390. 2,
  134391. 1,
  134392. 3,
  134393. 0,
  134394. 4,
  134395. };
  134396. static long _vq_lengthlist__44u4__p6_1[] = {
  134397. 2, 4, 4, 5, 5, 4, 5, 5, 6, 5, 4, 5, 5, 5, 6, 5,
  134398. 6, 5, 6, 6, 5, 5, 6, 6, 6,
  134399. };
  134400. static float _vq_quantthresh__44u4__p6_1[] = {
  134401. -1.5, -0.5, 0.5, 1.5,
  134402. };
  134403. static long _vq_quantmap__44u4__p6_1[] = {
  134404. 3, 1, 0, 2, 4,
  134405. };
  134406. static encode_aux_threshmatch _vq_auxt__44u4__p6_1 = {
  134407. _vq_quantthresh__44u4__p6_1,
  134408. _vq_quantmap__44u4__p6_1,
  134409. 5,
  134410. 5
  134411. };
  134412. static static_codebook _44u4__p6_1 = {
  134413. 2, 25,
  134414. _vq_lengthlist__44u4__p6_1,
  134415. 1, -533725184, 1611661312, 3, 0,
  134416. _vq_quantlist__44u4__p6_1,
  134417. NULL,
  134418. &_vq_auxt__44u4__p6_1,
  134419. NULL,
  134420. 0
  134421. };
  134422. static long _vq_quantlist__44u4__p7_0[] = {
  134423. 6,
  134424. 5,
  134425. 7,
  134426. 4,
  134427. 8,
  134428. 3,
  134429. 9,
  134430. 2,
  134431. 10,
  134432. 1,
  134433. 11,
  134434. 0,
  134435. 12,
  134436. };
  134437. static long _vq_lengthlist__44u4__p7_0[] = {
  134438. 1, 3, 3,12,12,12,12,12,12,12,12,12,12, 3,12,11,
  134439. 12,12,12,12,12,12,12,12,12,12, 4,11,10,12,12,12,
  134440. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134441. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134442. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  134443. 12,12,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134444. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134445. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134446. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134447. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  134448. 11,11,11,11,11,11,11,11,11,
  134449. };
  134450. static float _vq_quantthresh__44u4__p7_0[] = {
  134451. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  134452. 637.5, 892.5, 1147.5, 1402.5,
  134453. };
  134454. static long _vq_quantmap__44u4__p7_0[] = {
  134455. 11, 9, 7, 5, 3, 1, 0, 2,
  134456. 4, 6, 8, 10, 12,
  134457. };
  134458. static encode_aux_threshmatch _vq_auxt__44u4__p7_0 = {
  134459. _vq_quantthresh__44u4__p7_0,
  134460. _vq_quantmap__44u4__p7_0,
  134461. 13,
  134462. 13
  134463. };
  134464. static static_codebook _44u4__p7_0 = {
  134465. 2, 169,
  134466. _vq_lengthlist__44u4__p7_0,
  134467. 1, -514332672, 1627381760, 4, 0,
  134468. _vq_quantlist__44u4__p7_0,
  134469. NULL,
  134470. &_vq_auxt__44u4__p7_0,
  134471. NULL,
  134472. 0
  134473. };
  134474. static long _vq_quantlist__44u4__p7_1[] = {
  134475. 7,
  134476. 6,
  134477. 8,
  134478. 5,
  134479. 9,
  134480. 4,
  134481. 10,
  134482. 3,
  134483. 11,
  134484. 2,
  134485. 12,
  134486. 1,
  134487. 13,
  134488. 0,
  134489. 14,
  134490. };
  134491. static long _vq_lengthlist__44u4__p7_1[] = {
  134492. 1, 4, 4, 6, 6, 7, 7, 9, 8,10, 8,10, 9,11,11, 4,
  134493. 7, 6, 8, 7, 9, 9,10,10,11,10,11,10,12,10, 4, 6,
  134494. 7, 8, 8, 9, 9,10,10,11,11,11,11,12,12, 6, 8, 8,
  134495. 10, 9,11,10,12,11,12,12,12,12,13,13, 6, 8, 8,10,
  134496. 10,10,11,11,11,12,12,13,12,13,13, 8, 9, 9,11,11,
  134497. 12,11,12,12,13,13,13,13,13,13, 8, 9, 9,11,11,11,
  134498. 12,12,12,13,13,13,13,13,13, 9,10,10,12,11,13,13,
  134499. 13,13,14,13,13,14,14,14, 9,10,11,11,12,12,13,13,
  134500. 13,13,13,14,15,14,14,10,11,11,12,12,13,13,14,14,
  134501. 14,14,14,15,16,16,10,11,11,12,13,13,13,13,15,14,
  134502. 14,15,16,15,16,10,12,12,13,13,14,14,14,15,15,15,
  134503. 15,15,15,16,11,12,12,13,13,14,14,14,15,15,15,16,
  134504. 15,17,16,11,12,12,13,13,13,15,15,14,16,16,16,16,
  134505. 16,17,11,12,12,13,13,14,14,15,14,15,15,17,17,16,
  134506. 16,
  134507. };
  134508. static float _vq_quantthresh__44u4__p7_1[] = {
  134509. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  134510. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  134511. };
  134512. static long _vq_quantmap__44u4__p7_1[] = {
  134513. 13, 11, 9, 7, 5, 3, 1, 0,
  134514. 2, 4, 6, 8, 10, 12, 14,
  134515. };
  134516. static encode_aux_threshmatch _vq_auxt__44u4__p7_1 = {
  134517. _vq_quantthresh__44u4__p7_1,
  134518. _vq_quantmap__44u4__p7_1,
  134519. 15,
  134520. 15
  134521. };
  134522. static static_codebook _44u4__p7_1 = {
  134523. 2, 225,
  134524. _vq_lengthlist__44u4__p7_1,
  134525. 1, -522338304, 1620115456, 4, 0,
  134526. _vq_quantlist__44u4__p7_1,
  134527. NULL,
  134528. &_vq_auxt__44u4__p7_1,
  134529. NULL,
  134530. 0
  134531. };
  134532. static long _vq_quantlist__44u4__p7_2[] = {
  134533. 8,
  134534. 7,
  134535. 9,
  134536. 6,
  134537. 10,
  134538. 5,
  134539. 11,
  134540. 4,
  134541. 12,
  134542. 3,
  134543. 13,
  134544. 2,
  134545. 14,
  134546. 1,
  134547. 15,
  134548. 0,
  134549. 16,
  134550. };
  134551. static long _vq_lengthlist__44u4__p7_2[] = {
  134552. 2, 5, 5, 7, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134553. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134554. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134555. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134556. 10,10,10,10, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,
  134557. 9,10, 9,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  134558. 10,10,10,10,10,10, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  134559. 9,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  134560. 10,10,10,10,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  134561. 10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,10,
  134562. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  134563. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,10,
  134564. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  134565. 10,10,10,10,10,10,10,10,10,11,10,10,10, 9, 9, 9,
  134566. 10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9,
  134567. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  134568. 10, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  134569. 9,10, 9,10,10,10,10,10,10,10,10,10,10,11,10,10,
  134570. 10,
  134571. };
  134572. static float _vq_quantthresh__44u4__p7_2[] = {
  134573. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  134574. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  134575. };
  134576. static long _vq_quantmap__44u4__p7_2[] = {
  134577. 15, 13, 11, 9, 7, 5, 3, 1,
  134578. 0, 2, 4, 6, 8, 10, 12, 14,
  134579. 16,
  134580. };
  134581. static encode_aux_threshmatch _vq_auxt__44u4__p7_2 = {
  134582. _vq_quantthresh__44u4__p7_2,
  134583. _vq_quantmap__44u4__p7_2,
  134584. 17,
  134585. 17
  134586. };
  134587. static static_codebook _44u4__p7_2 = {
  134588. 2, 289,
  134589. _vq_lengthlist__44u4__p7_2,
  134590. 1, -529530880, 1611661312, 5, 0,
  134591. _vq_quantlist__44u4__p7_2,
  134592. NULL,
  134593. &_vq_auxt__44u4__p7_2,
  134594. NULL,
  134595. 0
  134596. };
  134597. static long _huff_lengthlist__44u4__short[] = {
  134598. 14,17,15,17,16,14,13,16,10, 7, 7,10,13,10,15,16,
  134599. 9, 4, 4, 6, 5, 7, 9,16,12, 8, 7, 8, 8, 8,11,16,
  134600. 14, 7, 4, 6, 3, 5, 8,15,13, 8, 5, 7, 4, 5, 7,16,
  134601. 12, 9, 6, 8, 3, 3, 5,16,14,13, 7,10, 5, 5, 7,15,
  134602. };
  134603. static static_codebook _huff_book__44u4__short = {
  134604. 2, 64,
  134605. _huff_lengthlist__44u4__short,
  134606. 0, 0, 0, 0, 0,
  134607. NULL,
  134608. NULL,
  134609. NULL,
  134610. NULL,
  134611. 0
  134612. };
  134613. static long _huff_lengthlist__44u5__long[] = {
  134614. 3, 8,13,12,14,12,16,11,13,14, 5, 4, 5, 6, 7, 8,
  134615. 10, 9,12,15,10, 5, 5, 5, 6, 8, 9, 9,13,15,10, 5,
  134616. 5, 6, 6, 7, 8, 8,11,13,12, 7, 5, 6, 4, 6, 7, 7,
  134617. 11,14,11, 7, 7, 6, 6, 6, 7, 6,10,14,14, 9, 8, 8,
  134618. 6, 7, 7, 7,11,16,11, 8, 8, 7, 6, 6, 7, 4, 7,12,
  134619. 10,10,12,10,10, 9,10, 5, 6, 9,10,12,15,13,14,14,
  134620. 14, 8, 7, 8,
  134621. };
  134622. static static_codebook _huff_book__44u5__long = {
  134623. 2, 100,
  134624. _huff_lengthlist__44u5__long,
  134625. 0, 0, 0, 0, 0,
  134626. NULL,
  134627. NULL,
  134628. NULL,
  134629. NULL,
  134630. 0
  134631. };
  134632. static long _vq_quantlist__44u5__p1_0[] = {
  134633. 1,
  134634. 0,
  134635. 2,
  134636. };
  134637. static long _vq_lengthlist__44u5__p1_0[] = {
  134638. 1, 4, 4, 5, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  134639. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  134640. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  134641. 10,13,11,10,13,13, 4, 8, 8, 8,11,10, 8,10,10, 7,
  134642. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  134643. 12,
  134644. };
  134645. static float _vq_quantthresh__44u5__p1_0[] = {
  134646. -0.5, 0.5,
  134647. };
  134648. static long _vq_quantmap__44u5__p1_0[] = {
  134649. 1, 0, 2,
  134650. };
  134651. static encode_aux_threshmatch _vq_auxt__44u5__p1_0 = {
  134652. _vq_quantthresh__44u5__p1_0,
  134653. _vq_quantmap__44u5__p1_0,
  134654. 3,
  134655. 3
  134656. };
  134657. static static_codebook _44u5__p1_0 = {
  134658. 4, 81,
  134659. _vq_lengthlist__44u5__p1_0,
  134660. 1, -535822336, 1611661312, 2, 0,
  134661. _vq_quantlist__44u5__p1_0,
  134662. NULL,
  134663. &_vq_auxt__44u5__p1_0,
  134664. NULL,
  134665. 0
  134666. };
  134667. static long _vq_quantlist__44u5__p2_0[] = {
  134668. 1,
  134669. 0,
  134670. 2,
  134671. };
  134672. static long _vq_lengthlist__44u5__p2_0[] = {
  134673. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  134674. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  134675. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  134676. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  134677. 8, 7, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  134678. 9,
  134679. };
  134680. static float _vq_quantthresh__44u5__p2_0[] = {
  134681. -0.5, 0.5,
  134682. };
  134683. static long _vq_quantmap__44u5__p2_0[] = {
  134684. 1, 0, 2,
  134685. };
  134686. static encode_aux_threshmatch _vq_auxt__44u5__p2_0 = {
  134687. _vq_quantthresh__44u5__p2_0,
  134688. _vq_quantmap__44u5__p2_0,
  134689. 3,
  134690. 3
  134691. };
  134692. static static_codebook _44u5__p2_0 = {
  134693. 4, 81,
  134694. _vq_lengthlist__44u5__p2_0,
  134695. 1, -535822336, 1611661312, 2, 0,
  134696. _vq_quantlist__44u5__p2_0,
  134697. NULL,
  134698. &_vq_auxt__44u5__p2_0,
  134699. NULL,
  134700. 0
  134701. };
  134702. static long _vq_quantlist__44u5__p3_0[] = {
  134703. 2,
  134704. 1,
  134705. 3,
  134706. 0,
  134707. 4,
  134708. };
  134709. static long _vq_lengthlist__44u5__p3_0[] = {
  134710. 2, 4, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  134711. 10, 9,13,12, 8, 9,10,12,12, 5, 7, 7,10,10, 7, 9,
  134712. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  134713. 13,14, 5, 7, 7, 9,10, 7, 9, 8,11,11, 7, 9, 9,11,
  134714. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,13,13,
  134715. 10,11,11,15,14, 9,11,11,14,14,13,14,14,17,16,12,
  134716. 13,13,15,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  134717. 11,14,15,12,14,13,16,16,13,15,14,15,17, 5, 7, 7,
  134718. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,
  134719. 14,10,11,12,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  134720. 9,11,11,13,13,12,13,13,15,16,11,12,13,15,16, 6,
  134721. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,14,11,13,
  134722. 12,16,14,11,13,13,16,17,10,12,11,15,15,11,13,13,
  134723. 16,16,11,13,13,17,16,14,15,15,17,17,14,16,16,17,
  134724. 18, 9,11,11,14,15,10,12,12,15,15,11,13,13,16,17,
  134725. 13,15,13,17,15,14,15,16,18, 0, 5, 7, 7,10,10, 7,
  134726. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  134727. 12,14,15, 6, 9, 9,12,11, 9,11,11,13,13, 8,10,11,
  134728. 12,13,11,13,13,16,15,11,12,13,14,15, 7, 9, 9,11,
  134729. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,15,16,
  134730. 11,13,13,15,14, 9,11,11,15,14,11,13,13,17,15,10,
  134731. 12,12,15,15,14,16,16,17,17,13,13,15,15,17,10,11,
  134732. 12,15,15,11,13,13,16,16,11,13,13,15,15,14,15,15,
  134733. 18,18,14,15,15,17,17, 8,10,10,13,13,10,12,11,15,
  134734. 15,10,11,12,15,15,14,15,15,18,18,13,14,14,18,18,
  134735. 9,11,11,15,16,11,13,13,17,17,11,13,13,16,16,15,
  134736. 15,16,17, 0,14,15,17, 0, 0, 9,11,11,15,15,10,13,
  134737. 12,18,16,11,13,13,15,16,14,16,15,20,20,14,15,16,
  134738. 17, 0,13,14,14,20,16,14,15,16,19,18,14,15,15,19,
  134739. 0,18,16, 0,20,20,16,18,18, 0, 0,12,14,14,18,18,
  134740. 13,15,14,18,16,14,15,16,18,20,16,19,16, 0,17,17,
  134741. 18,18,19, 0, 8,10,10,14,14,10,11,11,14,15,10,11,
  134742. 12,15,15,13,15,14,19,17,13,15,15,17, 0, 9,11,11,
  134743. 16,15,11,13,13,16,16,10,12,13,15,17,14,16,16,18,
  134744. 18,14,15,15,18, 0, 9,11,11,15,15,11,13,13,16,17,
  134745. 11,13,13,18,17,14,18,16,18,18,15,17,17,18, 0,12,
  134746. 14,14,18,18,14,15,15,20, 0,13,14,15,17, 0,16,18,
  134747. 17, 0, 0,16,16, 0,17,20,12,14,14,18,18,14,16,15,
  134748. 0,18,14,16,15,18, 0,16,19,17, 0, 0,17,18,16, 0,
  134749. 0,
  134750. };
  134751. static float _vq_quantthresh__44u5__p3_0[] = {
  134752. -1.5, -0.5, 0.5, 1.5,
  134753. };
  134754. static long _vq_quantmap__44u5__p3_0[] = {
  134755. 3, 1, 0, 2, 4,
  134756. };
  134757. static encode_aux_threshmatch _vq_auxt__44u5__p3_0 = {
  134758. _vq_quantthresh__44u5__p3_0,
  134759. _vq_quantmap__44u5__p3_0,
  134760. 5,
  134761. 5
  134762. };
  134763. static static_codebook _44u5__p3_0 = {
  134764. 4, 625,
  134765. _vq_lengthlist__44u5__p3_0,
  134766. 1, -533725184, 1611661312, 3, 0,
  134767. _vq_quantlist__44u5__p3_0,
  134768. NULL,
  134769. &_vq_auxt__44u5__p3_0,
  134770. NULL,
  134771. 0
  134772. };
  134773. static long _vq_quantlist__44u5__p4_0[] = {
  134774. 2,
  134775. 1,
  134776. 3,
  134777. 0,
  134778. 4,
  134779. };
  134780. static long _vq_lengthlist__44u5__p4_0[] = {
  134781. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  134782. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  134783. 8,10,10, 6, 7, 8, 9,10, 9,10,10,11,12, 9, 9,10,
  134784. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  134785. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,12,11,
  134786. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  134787. 11,12,13,14, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134788. 10,12,12,11,12,11,14,13,11,12,12,13,13, 5, 7, 7,
  134789. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  134790. 12, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,10,11,
  134791. 8, 9, 9,11,11,10,10,11,11,13,10,11,11,12,13, 6,
  134792. 7, 8,10,10, 7, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  134793. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  134794. 12,13,10,11,11,13,13,12,11,13,12,15,12,13,13,14,
  134795. 15, 9,10,10,12,12, 9,11,10,13,12,10,11,11,13,13,
  134796. 11,13,11,14,12,12,13,13,14,15, 5, 7, 7, 9, 9, 7,
  134797. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  134798. 10,12,12, 6, 8, 7,10,10, 8, 9, 9,11,11, 7, 8, 9,
  134799. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  134800. 10, 8, 9, 9,11,11, 8, 9, 8,11,10,10,11,11,13,12,
  134801. 10,11,10,13,11, 9,10,10,12,12,10,11,11,13,12, 9,
  134802. 10,10,12,13,12,13,13,14,15,11,11,13,12,14, 9,10,
  134803. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,13,13,
  134804. 14,14,12,13,11,14,12, 8, 9, 9,12,12, 9,10,10,12,
  134805. 12, 9,10,10,12,12,12,12,12,14,14,11,12,12,14,13,
  134806. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  134807. 12,13,14,15,12,13,13,15,14, 9,10,10,12,12,10,11,
  134808. 10,13,12,10,11,11,12,13,12,13,12,15,13,12,13,13,
  134809. 14,15,11,12,12,14,13,11,12,12,14,15,12,13,13,15,
  134810. 14,13,12,14,12,16,13,14,14,15,15,11,11,12,14,14,
  134811. 11,12,11,14,13,12,13,13,14,15,13,14,12,16,12,14,
  134812. 14,15,16,16, 8, 9, 9,11,12, 9,10,10,12,12, 9,10,
  134813. 10,12,13,11,12,12,13,13,12,12,13,14,14, 9,10,10,
  134814. 12,12,10,11,10,13,12,10,10,11,12,13,12,13,13,15,
  134815. 14,12,12,13,13,15, 9,10,10,12,13,10,11,11,12,13,
  134816. 10,11,11,13,13,12,13,13,14,15,12,13,12,15,14,11,
  134817. 12,11,14,13,12,13,13,15,14,11,11,12,13,14,14,15,
  134818. 14,16,15,13,12,14,13,16,11,12,12,13,14,12,13,13,
  134819. 14,15,11,12,11,14,14,14,14,14,15,16,13,15,12,16,
  134820. 12,
  134821. };
  134822. static float _vq_quantthresh__44u5__p4_0[] = {
  134823. -1.5, -0.5, 0.5, 1.5,
  134824. };
  134825. static long _vq_quantmap__44u5__p4_0[] = {
  134826. 3, 1, 0, 2, 4,
  134827. };
  134828. static encode_aux_threshmatch _vq_auxt__44u5__p4_0 = {
  134829. _vq_quantthresh__44u5__p4_0,
  134830. _vq_quantmap__44u5__p4_0,
  134831. 5,
  134832. 5
  134833. };
  134834. static static_codebook _44u5__p4_0 = {
  134835. 4, 625,
  134836. _vq_lengthlist__44u5__p4_0,
  134837. 1, -533725184, 1611661312, 3, 0,
  134838. _vq_quantlist__44u5__p4_0,
  134839. NULL,
  134840. &_vq_auxt__44u5__p4_0,
  134841. NULL,
  134842. 0
  134843. };
  134844. static long _vq_quantlist__44u5__p5_0[] = {
  134845. 4,
  134846. 3,
  134847. 5,
  134848. 2,
  134849. 6,
  134850. 1,
  134851. 7,
  134852. 0,
  134853. 8,
  134854. };
  134855. static long _vq_lengthlist__44u5__p5_0[] = {
  134856. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  134857. 11,10, 3, 5, 5, 7, 8, 8, 8,10,11, 6, 8, 7,10, 9,
  134858. 10,10,11,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  134859. 10,10,11,11,13,12, 8, 8, 9, 9,10,11,11,12,13,10,
  134860. 11,10,12,11,13,12,14,14,10,10,11,11,12,12,13,14,
  134861. 14,
  134862. };
  134863. static float _vq_quantthresh__44u5__p5_0[] = {
  134864. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134865. };
  134866. static long _vq_quantmap__44u5__p5_0[] = {
  134867. 7, 5, 3, 1, 0, 2, 4, 6,
  134868. 8,
  134869. };
  134870. static encode_aux_threshmatch _vq_auxt__44u5__p5_0 = {
  134871. _vq_quantthresh__44u5__p5_0,
  134872. _vq_quantmap__44u5__p5_0,
  134873. 9,
  134874. 9
  134875. };
  134876. static static_codebook _44u5__p5_0 = {
  134877. 2, 81,
  134878. _vq_lengthlist__44u5__p5_0,
  134879. 1, -531628032, 1611661312, 4, 0,
  134880. _vq_quantlist__44u5__p5_0,
  134881. NULL,
  134882. &_vq_auxt__44u5__p5_0,
  134883. NULL,
  134884. 0
  134885. };
  134886. static long _vq_quantlist__44u5__p6_0[] = {
  134887. 4,
  134888. 3,
  134889. 5,
  134890. 2,
  134891. 6,
  134892. 1,
  134893. 7,
  134894. 0,
  134895. 8,
  134896. };
  134897. static long _vq_lengthlist__44u5__p6_0[] = {
  134898. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  134899. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  134900. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  134901. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  134902. 9, 9,10,10,11,10,11,11, 9, 9, 9,10,10,11,10,11,
  134903. 11,
  134904. };
  134905. static float _vq_quantthresh__44u5__p6_0[] = {
  134906. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  134907. };
  134908. static long _vq_quantmap__44u5__p6_0[] = {
  134909. 7, 5, 3, 1, 0, 2, 4, 6,
  134910. 8,
  134911. };
  134912. static encode_aux_threshmatch _vq_auxt__44u5__p6_0 = {
  134913. _vq_quantthresh__44u5__p6_0,
  134914. _vq_quantmap__44u5__p6_0,
  134915. 9,
  134916. 9
  134917. };
  134918. static static_codebook _44u5__p6_0 = {
  134919. 2, 81,
  134920. _vq_lengthlist__44u5__p6_0,
  134921. 1, -531628032, 1611661312, 4, 0,
  134922. _vq_quantlist__44u5__p6_0,
  134923. NULL,
  134924. &_vq_auxt__44u5__p6_0,
  134925. NULL,
  134926. 0
  134927. };
  134928. static long _vq_quantlist__44u5__p7_0[] = {
  134929. 1,
  134930. 0,
  134931. 2,
  134932. };
  134933. static long _vq_lengthlist__44u5__p7_0[] = {
  134934. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 9, 8,11,10, 7,
  134935. 11,10, 5, 9, 9, 7,10,10, 8,10,11, 4, 9, 9, 9,12,
  134936. 12, 9,12,12, 8,12,12,11,12,12,10,12,13, 7,12,12,
  134937. 11,12,12,10,12,13, 4, 9, 9, 9,12,12, 9,12,12, 7,
  134938. 12,11,10,13,13,11,12,12, 7,12,12,10,13,13,11,12,
  134939. 12,
  134940. };
  134941. static float _vq_quantthresh__44u5__p7_0[] = {
  134942. -5.5, 5.5,
  134943. };
  134944. static long _vq_quantmap__44u5__p7_0[] = {
  134945. 1, 0, 2,
  134946. };
  134947. static encode_aux_threshmatch _vq_auxt__44u5__p7_0 = {
  134948. _vq_quantthresh__44u5__p7_0,
  134949. _vq_quantmap__44u5__p7_0,
  134950. 3,
  134951. 3
  134952. };
  134953. static static_codebook _44u5__p7_0 = {
  134954. 4, 81,
  134955. _vq_lengthlist__44u5__p7_0,
  134956. 1, -529137664, 1618345984, 2, 0,
  134957. _vq_quantlist__44u5__p7_0,
  134958. NULL,
  134959. &_vq_auxt__44u5__p7_0,
  134960. NULL,
  134961. 0
  134962. };
  134963. static long _vq_quantlist__44u5__p7_1[] = {
  134964. 5,
  134965. 4,
  134966. 6,
  134967. 3,
  134968. 7,
  134969. 2,
  134970. 8,
  134971. 1,
  134972. 9,
  134973. 0,
  134974. 10,
  134975. };
  134976. static long _vq_lengthlist__44u5__p7_1[] = {
  134977. 2, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 7,
  134978. 8, 8, 9, 8, 8, 9, 4, 5, 5, 7, 7, 8, 8, 9, 9, 8,
  134979. 9, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 6, 7, 7, 8,
  134980. 8, 9, 9, 9, 9, 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9,
  134981. 9, 9, 7, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9,
  134982. 9, 9, 9, 9,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  134983. 10,10,10, 8, 9, 9, 9, 9, 9, 9,10,10,10,10, 8, 9,
  134984. 9, 9, 9, 9, 9,10,10,10,10,
  134985. };
  134986. static float _vq_quantthresh__44u5__p7_1[] = {
  134987. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  134988. 3.5, 4.5,
  134989. };
  134990. static long _vq_quantmap__44u5__p7_1[] = {
  134991. 9, 7, 5, 3, 1, 0, 2, 4,
  134992. 6, 8, 10,
  134993. };
  134994. static encode_aux_threshmatch _vq_auxt__44u5__p7_1 = {
  134995. _vq_quantthresh__44u5__p7_1,
  134996. _vq_quantmap__44u5__p7_1,
  134997. 11,
  134998. 11
  134999. };
  135000. static static_codebook _44u5__p7_1 = {
  135001. 2, 121,
  135002. _vq_lengthlist__44u5__p7_1,
  135003. 1, -531365888, 1611661312, 4, 0,
  135004. _vq_quantlist__44u5__p7_1,
  135005. NULL,
  135006. &_vq_auxt__44u5__p7_1,
  135007. NULL,
  135008. 0
  135009. };
  135010. static long _vq_quantlist__44u5__p8_0[] = {
  135011. 5,
  135012. 4,
  135013. 6,
  135014. 3,
  135015. 7,
  135016. 2,
  135017. 8,
  135018. 1,
  135019. 9,
  135020. 0,
  135021. 10,
  135022. };
  135023. static long _vq_lengthlist__44u5__p8_0[] = {
  135024. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135025. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135026. 11, 6, 8, 7, 9, 9,10,10,11,11,13,12, 6, 8, 8, 9,
  135027. 9,10,10,11,11,12,13, 8, 9, 9,10,10,12,12,13,12,
  135028. 14,13, 8, 9, 9,10,10,12,12,13,13,14,14, 9,11,11,
  135029. 12,12,13,13,14,14,15,14, 9,11,11,12,12,13,13,14,
  135030. 14,15,14,11,12,12,13,13,14,14,15,14,15,14,11,11,
  135031. 12,13,13,14,14,14,14,15,15,
  135032. };
  135033. static float _vq_quantthresh__44u5__p8_0[] = {
  135034. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135035. 38.5, 49.5,
  135036. };
  135037. static long _vq_quantmap__44u5__p8_0[] = {
  135038. 9, 7, 5, 3, 1, 0, 2, 4,
  135039. 6, 8, 10,
  135040. };
  135041. static encode_aux_threshmatch _vq_auxt__44u5__p8_0 = {
  135042. _vq_quantthresh__44u5__p8_0,
  135043. _vq_quantmap__44u5__p8_0,
  135044. 11,
  135045. 11
  135046. };
  135047. static static_codebook _44u5__p8_0 = {
  135048. 2, 121,
  135049. _vq_lengthlist__44u5__p8_0,
  135050. 1, -524582912, 1618345984, 4, 0,
  135051. _vq_quantlist__44u5__p8_0,
  135052. NULL,
  135053. &_vq_auxt__44u5__p8_0,
  135054. NULL,
  135055. 0
  135056. };
  135057. static long _vq_quantlist__44u5__p8_1[] = {
  135058. 5,
  135059. 4,
  135060. 6,
  135061. 3,
  135062. 7,
  135063. 2,
  135064. 8,
  135065. 1,
  135066. 9,
  135067. 0,
  135068. 10,
  135069. };
  135070. static long _vq_lengthlist__44u5__p8_1[] = {
  135071. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 6,
  135072. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8,
  135073. 8, 6, 7, 6, 7, 7, 8, 8, 8, 8, 8, 8, 6, 6, 7, 7,
  135074. 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135075. 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8,
  135076. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135077. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135078. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135079. };
  135080. static float _vq_quantthresh__44u5__p8_1[] = {
  135081. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135082. 3.5, 4.5,
  135083. };
  135084. static long _vq_quantmap__44u5__p8_1[] = {
  135085. 9, 7, 5, 3, 1, 0, 2, 4,
  135086. 6, 8, 10,
  135087. };
  135088. static encode_aux_threshmatch _vq_auxt__44u5__p8_1 = {
  135089. _vq_quantthresh__44u5__p8_1,
  135090. _vq_quantmap__44u5__p8_1,
  135091. 11,
  135092. 11
  135093. };
  135094. static static_codebook _44u5__p8_1 = {
  135095. 2, 121,
  135096. _vq_lengthlist__44u5__p8_1,
  135097. 1, -531365888, 1611661312, 4, 0,
  135098. _vq_quantlist__44u5__p8_1,
  135099. NULL,
  135100. &_vq_auxt__44u5__p8_1,
  135101. NULL,
  135102. 0
  135103. };
  135104. static long _vq_quantlist__44u5__p9_0[] = {
  135105. 6,
  135106. 5,
  135107. 7,
  135108. 4,
  135109. 8,
  135110. 3,
  135111. 9,
  135112. 2,
  135113. 10,
  135114. 1,
  135115. 11,
  135116. 0,
  135117. 12,
  135118. };
  135119. static long _vq_lengthlist__44u5__p9_0[] = {
  135120. 1, 3, 2,12,10,13,13,13,13,13,13,13,13, 4, 9, 9,
  135121. 13,13,13,13,13,13,13,13,13,13, 5,10, 9,13,13,13,
  135122. 13,13,13,13,13,13,13,12,13,13,13,13,13,13,13,13,
  135123. 13,13,13,13,11,13,13,13,13,13,13,13,13,13,13,13,
  135124. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135125. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135126. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135127. 13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,13,
  135128. 13,13,13,13,13,13,13,13,13,13,13,13,13,12,12,12,
  135129. 12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,12,
  135130. 12,12,12,12,12,12,12,12,12,
  135131. };
  135132. static float _vq_quantthresh__44u5__p9_0[] = {
  135133. -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5, 382.5,
  135134. 637.5, 892.5, 1147.5, 1402.5,
  135135. };
  135136. static long _vq_quantmap__44u5__p9_0[] = {
  135137. 11, 9, 7, 5, 3, 1, 0, 2,
  135138. 4, 6, 8, 10, 12,
  135139. };
  135140. static encode_aux_threshmatch _vq_auxt__44u5__p9_0 = {
  135141. _vq_quantthresh__44u5__p9_0,
  135142. _vq_quantmap__44u5__p9_0,
  135143. 13,
  135144. 13
  135145. };
  135146. static static_codebook _44u5__p9_0 = {
  135147. 2, 169,
  135148. _vq_lengthlist__44u5__p9_0,
  135149. 1, -514332672, 1627381760, 4, 0,
  135150. _vq_quantlist__44u5__p9_0,
  135151. NULL,
  135152. &_vq_auxt__44u5__p9_0,
  135153. NULL,
  135154. 0
  135155. };
  135156. static long _vq_quantlist__44u5__p9_1[] = {
  135157. 7,
  135158. 6,
  135159. 8,
  135160. 5,
  135161. 9,
  135162. 4,
  135163. 10,
  135164. 3,
  135165. 11,
  135166. 2,
  135167. 12,
  135168. 1,
  135169. 13,
  135170. 0,
  135171. 14,
  135172. };
  135173. static long _vq_lengthlist__44u5__p9_1[] = {
  135174. 1, 4, 4, 7, 7, 8, 8, 8, 7, 8, 7, 9, 8, 9, 9, 4,
  135175. 7, 6, 9, 8,10,10, 9, 8, 9, 9, 9, 9, 9, 8, 5, 6,
  135176. 6, 8, 9,10,10, 9, 9, 9,10,10,10,10,11, 7, 8, 8,
  135177. 10,10,11,11,10,10,11,11,11,12,11,11, 7, 8, 8,10,
  135178. 10,11,11,10,10,11,11,12,11,11,11, 8, 9, 9,11,11,
  135179. 12,12,11,11,12,11,12,12,12,12, 8, 9,10,11,11,12,
  135180. 12,11,11,12,12,12,12,12,12, 8, 9, 9,10,10,12,11,
  135181. 12,12,12,12,12,12,12,13, 8, 9, 9,11,11,11,11,12,
  135182. 12,12,12,13,12,13,13, 9,10,10,11,11,12,12,12,13,
  135183. 12,13,13,13,14,13, 9,10,10,11,11,12,12,12,13,13,
  135184. 12,13,13,14,13, 9,11,10,12,11,13,12,12,13,13,13,
  135185. 13,13,13,14, 9,10,10,12,12,12,12,12,13,13,13,13,
  135186. 13,14,14,10,11,11,12,12,12,13,13,13,14,14,13,14,
  135187. 14,14,10,11,11,12,12,12,12,13,12,13,14,13,14,14,
  135188. 14,
  135189. };
  135190. static float _vq_quantthresh__44u5__p9_1[] = {
  135191. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135192. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135193. };
  135194. static long _vq_quantmap__44u5__p9_1[] = {
  135195. 13, 11, 9, 7, 5, 3, 1, 0,
  135196. 2, 4, 6, 8, 10, 12, 14,
  135197. };
  135198. static encode_aux_threshmatch _vq_auxt__44u5__p9_1 = {
  135199. _vq_quantthresh__44u5__p9_1,
  135200. _vq_quantmap__44u5__p9_1,
  135201. 15,
  135202. 15
  135203. };
  135204. static static_codebook _44u5__p9_1 = {
  135205. 2, 225,
  135206. _vq_lengthlist__44u5__p9_1,
  135207. 1, -522338304, 1620115456, 4, 0,
  135208. _vq_quantlist__44u5__p9_1,
  135209. NULL,
  135210. &_vq_auxt__44u5__p9_1,
  135211. NULL,
  135212. 0
  135213. };
  135214. static long _vq_quantlist__44u5__p9_2[] = {
  135215. 8,
  135216. 7,
  135217. 9,
  135218. 6,
  135219. 10,
  135220. 5,
  135221. 11,
  135222. 4,
  135223. 12,
  135224. 3,
  135225. 13,
  135226. 2,
  135227. 14,
  135228. 1,
  135229. 15,
  135230. 0,
  135231. 16,
  135232. };
  135233. static long _vq_lengthlist__44u5__p9_2[] = {
  135234. 2, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135235. 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135236. 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135237. 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9,
  135238. 9, 9, 9, 9, 7, 7, 7, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135239. 9, 9, 9, 9, 9, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  135240. 9,10, 9,10,10,10, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9,
  135241. 9, 9,10, 9,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  135242. 9,10, 9,10,10,10,10,10, 8, 9, 9, 9, 9, 9, 9,10,
  135243. 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,10, 9,
  135244. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9,
  135245. 9,10, 9,10, 9,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  135246. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  135247. 9, 9,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  135248. 9,10,10, 9,10,10,10,10,10,10,10,10,10,10, 9, 9,
  135249. 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  135250. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  135251. 9, 9, 9,10, 9,10,10,10,10,10,10,10,10,10,10,10,
  135252. 10,
  135253. };
  135254. static float _vq_quantthresh__44u5__p9_2[] = {
  135255. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135256. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135257. };
  135258. static long _vq_quantmap__44u5__p9_2[] = {
  135259. 15, 13, 11, 9, 7, 5, 3, 1,
  135260. 0, 2, 4, 6, 8, 10, 12, 14,
  135261. 16,
  135262. };
  135263. static encode_aux_threshmatch _vq_auxt__44u5__p9_2 = {
  135264. _vq_quantthresh__44u5__p9_2,
  135265. _vq_quantmap__44u5__p9_2,
  135266. 17,
  135267. 17
  135268. };
  135269. static static_codebook _44u5__p9_2 = {
  135270. 2, 289,
  135271. _vq_lengthlist__44u5__p9_2,
  135272. 1, -529530880, 1611661312, 5, 0,
  135273. _vq_quantlist__44u5__p9_2,
  135274. NULL,
  135275. &_vq_auxt__44u5__p9_2,
  135276. NULL,
  135277. 0
  135278. };
  135279. static long _huff_lengthlist__44u5__short[] = {
  135280. 4,10,17,13,17,13,17,17,17,17, 3, 6, 8, 9,11, 9,
  135281. 15,12,16,17, 6, 5, 5, 7, 7, 8,10,11,17,17, 7, 8,
  135282. 7, 9, 9,10,13,13,17,17, 8, 6, 5, 7, 4, 7, 5, 8,
  135283. 14,17, 9, 9, 8, 9, 7, 9, 8,10,16,17,12,10, 7, 8,
  135284. 4, 7, 4, 7,16,17,12,11, 9,10, 6, 9, 5, 7,14,17,
  135285. 14,13,10,15, 4, 8, 3, 5,14,17,17,14,11,15, 6,10,
  135286. 6, 8,15,17,
  135287. };
  135288. static static_codebook _huff_book__44u5__short = {
  135289. 2, 100,
  135290. _huff_lengthlist__44u5__short,
  135291. 0, 0, 0, 0, 0,
  135292. NULL,
  135293. NULL,
  135294. NULL,
  135295. NULL,
  135296. 0
  135297. };
  135298. static long _huff_lengthlist__44u6__long[] = {
  135299. 3, 9,14,13,14,13,16,12,13,14, 5, 4, 6, 6, 8, 9,
  135300. 11,10,12,15,10, 5, 5, 6, 6, 8,10,10,13,16,10, 6,
  135301. 6, 6, 6, 8, 9, 9,12,14,13, 7, 6, 6, 4, 6, 6, 7,
  135302. 11,14,10, 7, 7, 7, 6, 6, 6, 7,10,13,15,10, 9, 8,
  135303. 5, 6, 5, 6,10,14,10, 9, 8, 8, 6, 6, 5, 4, 6,11,
  135304. 11,11,12,11,10, 9, 9, 5, 5, 9,10,12,15,13,13,13,
  135305. 13, 8, 7, 7,
  135306. };
  135307. static static_codebook _huff_book__44u6__long = {
  135308. 2, 100,
  135309. _huff_lengthlist__44u6__long,
  135310. 0, 0, 0, 0, 0,
  135311. NULL,
  135312. NULL,
  135313. NULL,
  135314. NULL,
  135315. 0
  135316. };
  135317. static long _vq_quantlist__44u6__p1_0[] = {
  135318. 1,
  135319. 0,
  135320. 2,
  135321. };
  135322. static long _vq_lengthlist__44u6__p1_0[] = {
  135323. 1, 4, 4, 4, 8, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  135324. 9,10, 5, 8, 8, 7,10, 9, 8,10,10, 5, 8, 8, 8,10,
  135325. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  135326. 10,13,11,10,13,13, 5, 8, 8, 8,11,10, 8,10,10, 7,
  135327. 10,10,10,13,13,10,11,13, 8,10,11,10,13,13,10,13,
  135328. 12,
  135329. };
  135330. static float _vq_quantthresh__44u6__p1_0[] = {
  135331. -0.5, 0.5,
  135332. };
  135333. static long _vq_quantmap__44u6__p1_0[] = {
  135334. 1, 0, 2,
  135335. };
  135336. static encode_aux_threshmatch _vq_auxt__44u6__p1_0 = {
  135337. _vq_quantthresh__44u6__p1_0,
  135338. _vq_quantmap__44u6__p1_0,
  135339. 3,
  135340. 3
  135341. };
  135342. static static_codebook _44u6__p1_0 = {
  135343. 4, 81,
  135344. _vq_lengthlist__44u6__p1_0,
  135345. 1, -535822336, 1611661312, 2, 0,
  135346. _vq_quantlist__44u6__p1_0,
  135347. NULL,
  135348. &_vq_auxt__44u6__p1_0,
  135349. NULL,
  135350. 0
  135351. };
  135352. static long _vq_quantlist__44u6__p2_0[] = {
  135353. 1,
  135354. 0,
  135355. 2,
  135356. };
  135357. static long _vq_lengthlist__44u6__p2_0[] = {
  135358. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  135359. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  135360. 8, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 7, 7,
  135361. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  135362. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  135363. 9,
  135364. };
  135365. static float _vq_quantthresh__44u6__p2_0[] = {
  135366. -0.5, 0.5,
  135367. };
  135368. static long _vq_quantmap__44u6__p2_0[] = {
  135369. 1, 0, 2,
  135370. };
  135371. static encode_aux_threshmatch _vq_auxt__44u6__p2_0 = {
  135372. _vq_quantthresh__44u6__p2_0,
  135373. _vq_quantmap__44u6__p2_0,
  135374. 3,
  135375. 3
  135376. };
  135377. static static_codebook _44u6__p2_0 = {
  135378. 4, 81,
  135379. _vq_lengthlist__44u6__p2_0,
  135380. 1, -535822336, 1611661312, 2, 0,
  135381. _vq_quantlist__44u6__p2_0,
  135382. NULL,
  135383. &_vq_auxt__44u6__p2_0,
  135384. NULL,
  135385. 0
  135386. };
  135387. static long _vq_quantlist__44u6__p3_0[] = {
  135388. 2,
  135389. 1,
  135390. 3,
  135391. 0,
  135392. 4,
  135393. };
  135394. static long _vq_lengthlist__44u6__p3_0[] = {
  135395. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  135396. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  135397. 9,11,11, 7, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  135398. 13,14, 5, 7, 7, 9,10, 6, 9, 8,11,11, 7, 9, 9,11,
  135399. 11, 9,11,10,14,13,10,11,11,14,13, 8,10,10,13,13,
  135400. 10,11,11,15,15, 9,11,11,14,14,13,14,14,17,16,12,
  135401. 13,14,16,16, 8,10,10,13,14, 9,11,11,14,15,10,11,
  135402. 12,14,15,12,14,13,16,15,13,14,14,15,17, 5, 7, 7,
  135403. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,14,
  135404. 14,10,11,11,14,14, 7, 9, 9,12,11, 9,11,11,13,13,
  135405. 9,11,11,13,13,11,13,13,14,15,11,12,13,15,16, 6,
  135406. 9, 9,11,12, 8,11,10,13,12, 9,11,11,13,14,11,13,
  135407. 12,16,14,11,13,13,15,16,10,12,11,14,15,11,13,13,
  135408. 15,17,11,13,13,17,16,15,15,16,17,16,14,15,16,18,
  135409. 0, 9,11,11,14,15,10,12,12,16,15,11,13,13,16,16,
  135410. 13,15,14,18,15,14,16,16, 0, 0, 5, 7, 7,10,10, 7,
  135411. 9, 9,11,11, 7, 9, 9,11,11,10,11,11,14,14,10,11,
  135412. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  135413. 12,13,11,13,13,16,15,11,12,13,14,16, 7, 9, 9,11,
  135414. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,13,16,15,
  135415. 11,13,12,15,15, 9,11,11,15,14,11,13,13,17,16,10,
  135416. 12,13,15,16,14,16,16, 0,18,14,14,15,15,17,10,11,
  135417. 12,15,15,11,13,13,16,16,11,13,13,16,16,14,16,16,
  135418. 19,17,14,15,15,17,17, 8,10,10,14,14,10,12,11,15,
  135419. 15,10,11,12,16,15,14,15,15,18,20,13,14,16,17,18,
  135420. 9,11,11,15,16,11,13,13,17,17,11,13,13,17,16,15,
  135421. 16,16, 0, 0,15,16,16, 0, 0, 9,11,11,15,15,10,13,
  135422. 12,17,15,11,13,13,17,16,15,17,15,20,19,15,16,16,
  135423. 19, 0,13,15,14, 0,17,14,15,16, 0,20,15,16,16, 0,
  135424. 19,17,18, 0, 0, 0,16,17,18, 0, 0,12,14,14,19,18,
  135425. 13,15,14, 0,17,14,15,16,19,19,16,18,16, 0,19,19,
  135426. 20,17,20, 0, 8,10,10,13,14,10,11,11,15,15,10,12,
  135427. 12,15,16,14,15,14,19,16,14,15,15, 0,18, 9,11,11,
  135428. 16,15,11,13,13, 0,16,11,12,13,16,17,14,16,17, 0,
  135429. 19,15,16,16,18, 0, 9,11,11,15,16,11,13,13,16,16,
  135430. 11,14,13,18,17,15,16,16,18,20,15,17,19, 0, 0,12,
  135431. 14,14,17,17,14,16,15, 0, 0,13,14,15,19, 0,16,18,
  135432. 20, 0, 0,16,16,18,18, 0,12,14,14,17,20,14,16,16,
  135433. 19, 0,14,16,14, 0,20,16,20,17, 0, 0,17, 0,15, 0,
  135434. 19,
  135435. };
  135436. static float _vq_quantthresh__44u6__p3_0[] = {
  135437. -1.5, -0.5, 0.5, 1.5,
  135438. };
  135439. static long _vq_quantmap__44u6__p3_0[] = {
  135440. 3, 1, 0, 2, 4,
  135441. };
  135442. static encode_aux_threshmatch _vq_auxt__44u6__p3_0 = {
  135443. _vq_quantthresh__44u6__p3_0,
  135444. _vq_quantmap__44u6__p3_0,
  135445. 5,
  135446. 5
  135447. };
  135448. static static_codebook _44u6__p3_0 = {
  135449. 4, 625,
  135450. _vq_lengthlist__44u6__p3_0,
  135451. 1, -533725184, 1611661312, 3, 0,
  135452. _vq_quantlist__44u6__p3_0,
  135453. NULL,
  135454. &_vq_auxt__44u6__p3_0,
  135455. NULL,
  135456. 0
  135457. };
  135458. static long _vq_quantlist__44u6__p4_0[] = {
  135459. 2,
  135460. 1,
  135461. 3,
  135462. 0,
  135463. 4,
  135464. };
  135465. static long _vq_lengthlist__44u6__p4_0[] = {
  135466. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  135467. 9, 9,11,11, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  135468. 8,10,10, 7, 7, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  135469. 11,12, 6, 7, 7, 9, 9, 7, 8, 7,10, 9, 7, 8, 8,10,
  135470. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  135471. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,13,11,
  135472. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135473. 10,12,12,11,12,11,13,12,11,12,12,13,13, 5, 7, 7,
  135474. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  135475. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  135476. 8, 9, 9,11,11,10,10,11,12,13,10,10,11,12,12, 6,
  135477. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  135478. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  135479. 13,13,10,11,11,12,13,12,12,12,13,14,12,12,13,14,
  135480. 14, 9,10,10,12,12, 9,10,10,13,12,10,11,11,13,13,
  135481. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  135482. 8, 7,10,10, 7, 8, 8,10,10, 9,10,10,12,11, 9,10,
  135483. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  135484. 10,11,10,11,11,12,12,10,10,11,11,13, 7, 8, 8,10,
  135485. 10, 8, 9, 9,11,11, 8, 9, 8,11,11,10,11,10,13,12,
  135486. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,12, 9,
  135487. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  135488. 10,12,12,10,11,11,13,13,10,11,10,13,12,12,12,12,
  135489. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  135490. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,14,
  135491. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  135492. 12,13,14,15,12,12,13,14,14, 9,10,10,12,12, 9,11,
  135493. 10,13,12,10,10,11,12,13,12,13,12,14,13,12,12,13,
  135494. 14,15,11,12,12,14,13,11,12,12,14,14,12,13,13,14,
  135495. 14,13,13,14,14,16,13,14,14,15,15,11,12,11,13,13,
  135496. 11,12,11,14,13,12,12,13,14,15,12,14,12,15,12,13,
  135497. 14,15,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  135498. 10,12,12,11,12,12,14,13,11,12,12,13,13, 9,10,10,
  135499. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  135500. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  135501. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  135502. 11,11,13,13,12,13,12,14,14,11,11,12,13,14,14,14,
  135503. 14,16,15,12,12,14,12,15,11,12,12,13,14,12,13,13,
  135504. 14,15,11,12,12,14,14,13,14,14,16,16,13,14,13,16,
  135505. 13,
  135506. };
  135507. static float _vq_quantthresh__44u6__p4_0[] = {
  135508. -1.5, -0.5, 0.5, 1.5,
  135509. };
  135510. static long _vq_quantmap__44u6__p4_0[] = {
  135511. 3, 1, 0, 2, 4,
  135512. };
  135513. static encode_aux_threshmatch _vq_auxt__44u6__p4_0 = {
  135514. _vq_quantthresh__44u6__p4_0,
  135515. _vq_quantmap__44u6__p4_0,
  135516. 5,
  135517. 5
  135518. };
  135519. static static_codebook _44u6__p4_0 = {
  135520. 4, 625,
  135521. _vq_lengthlist__44u6__p4_0,
  135522. 1, -533725184, 1611661312, 3, 0,
  135523. _vq_quantlist__44u6__p4_0,
  135524. NULL,
  135525. &_vq_auxt__44u6__p4_0,
  135526. NULL,
  135527. 0
  135528. };
  135529. static long _vq_quantlist__44u6__p5_0[] = {
  135530. 4,
  135531. 3,
  135532. 5,
  135533. 2,
  135534. 6,
  135535. 1,
  135536. 7,
  135537. 0,
  135538. 8,
  135539. };
  135540. static long _vq_lengthlist__44u6__p5_0[] = {
  135541. 2, 3, 3, 6, 6, 8, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  135542. 11,11, 3, 5, 5, 7, 8, 8, 8,11,11, 6, 8, 7, 9, 9,
  135543. 10, 9,12,11, 6, 7, 8, 9, 9, 9,10,11,12, 8, 8, 8,
  135544. 10, 9,12,11,13,13, 8, 8, 9, 9,10,11,12,13,13,10,
  135545. 11,11,12,12,13,13,14,14,10,10,11,11,12,13,13,14,
  135546. 14,
  135547. };
  135548. static float _vq_quantthresh__44u6__p5_0[] = {
  135549. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135550. };
  135551. static long _vq_quantmap__44u6__p5_0[] = {
  135552. 7, 5, 3, 1, 0, 2, 4, 6,
  135553. 8,
  135554. };
  135555. static encode_aux_threshmatch _vq_auxt__44u6__p5_0 = {
  135556. _vq_quantthresh__44u6__p5_0,
  135557. _vq_quantmap__44u6__p5_0,
  135558. 9,
  135559. 9
  135560. };
  135561. static static_codebook _44u6__p5_0 = {
  135562. 2, 81,
  135563. _vq_lengthlist__44u6__p5_0,
  135564. 1, -531628032, 1611661312, 4, 0,
  135565. _vq_quantlist__44u6__p5_0,
  135566. NULL,
  135567. &_vq_auxt__44u6__p5_0,
  135568. NULL,
  135569. 0
  135570. };
  135571. static long _vq_quantlist__44u6__p6_0[] = {
  135572. 4,
  135573. 3,
  135574. 5,
  135575. 2,
  135576. 6,
  135577. 1,
  135578. 7,
  135579. 0,
  135580. 8,
  135581. };
  135582. static long _vq_lengthlist__44u6__p6_0[] = {
  135583. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  135584. 9, 9, 4, 4, 5, 6, 6, 7, 8, 9, 9, 5, 6, 6, 7, 7,
  135585. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  135586. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,10,11, 9,
  135587. 9, 9,10,10,11,11,12,11, 9, 9, 9,10,10,11,11,11,
  135588. 12,
  135589. };
  135590. static float _vq_quantthresh__44u6__p6_0[] = {
  135591. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  135592. };
  135593. static long _vq_quantmap__44u6__p6_0[] = {
  135594. 7, 5, 3, 1, 0, 2, 4, 6,
  135595. 8,
  135596. };
  135597. static encode_aux_threshmatch _vq_auxt__44u6__p6_0 = {
  135598. _vq_quantthresh__44u6__p6_0,
  135599. _vq_quantmap__44u6__p6_0,
  135600. 9,
  135601. 9
  135602. };
  135603. static static_codebook _44u6__p6_0 = {
  135604. 2, 81,
  135605. _vq_lengthlist__44u6__p6_0,
  135606. 1, -531628032, 1611661312, 4, 0,
  135607. _vq_quantlist__44u6__p6_0,
  135608. NULL,
  135609. &_vq_auxt__44u6__p6_0,
  135610. NULL,
  135611. 0
  135612. };
  135613. static long _vq_quantlist__44u6__p7_0[] = {
  135614. 1,
  135615. 0,
  135616. 2,
  135617. };
  135618. static long _vq_lengthlist__44u6__p7_0[] = {
  135619. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 7,10,10, 8,
  135620. 10,10, 5, 8, 9, 7,10,10, 7,10, 9, 4, 8, 8, 9,11,
  135621. 11, 8,11,11, 7,11,11,10,10,13,10,13,13, 7,11,11,
  135622. 10,13,12,10,13,13, 5, 9, 8, 8,11,11, 9,11,11, 7,
  135623. 11,11,10,13,13,10,12,13, 7,11,11,10,13,13, 9,13,
  135624. 10,
  135625. };
  135626. static float _vq_quantthresh__44u6__p7_0[] = {
  135627. -5.5, 5.5,
  135628. };
  135629. static long _vq_quantmap__44u6__p7_0[] = {
  135630. 1, 0, 2,
  135631. };
  135632. static encode_aux_threshmatch _vq_auxt__44u6__p7_0 = {
  135633. _vq_quantthresh__44u6__p7_0,
  135634. _vq_quantmap__44u6__p7_0,
  135635. 3,
  135636. 3
  135637. };
  135638. static static_codebook _44u6__p7_0 = {
  135639. 4, 81,
  135640. _vq_lengthlist__44u6__p7_0,
  135641. 1, -529137664, 1618345984, 2, 0,
  135642. _vq_quantlist__44u6__p7_0,
  135643. NULL,
  135644. &_vq_auxt__44u6__p7_0,
  135645. NULL,
  135646. 0
  135647. };
  135648. static long _vq_quantlist__44u6__p7_1[] = {
  135649. 5,
  135650. 4,
  135651. 6,
  135652. 3,
  135653. 7,
  135654. 2,
  135655. 8,
  135656. 1,
  135657. 9,
  135658. 0,
  135659. 10,
  135660. };
  135661. static long _vq_lengthlist__44u6__p7_1[] = {
  135662. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 7, 6,
  135663. 8, 8, 8, 8, 8, 8, 4, 5, 5, 6, 7, 8, 8, 8, 8, 8,
  135664. 8, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 6, 7, 7, 7,
  135665. 7, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 9, 9,
  135666. 9, 9, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9, 8, 8, 8,
  135667. 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9,
  135668. 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8,
  135669. 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135670. };
  135671. static float _vq_quantthresh__44u6__p7_1[] = {
  135672. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135673. 3.5, 4.5,
  135674. };
  135675. static long _vq_quantmap__44u6__p7_1[] = {
  135676. 9, 7, 5, 3, 1, 0, 2, 4,
  135677. 6, 8, 10,
  135678. };
  135679. static encode_aux_threshmatch _vq_auxt__44u6__p7_1 = {
  135680. _vq_quantthresh__44u6__p7_1,
  135681. _vq_quantmap__44u6__p7_1,
  135682. 11,
  135683. 11
  135684. };
  135685. static static_codebook _44u6__p7_1 = {
  135686. 2, 121,
  135687. _vq_lengthlist__44u6__p7_1,
  135688. 1, -531365888, 1611661312, 4, 0,
  135689. _vq_quantlist__44u6__p7_1,
  135690. NULL,
  135691. &_vq_auxt__44u6__p7_1,
  135692. NULL,
  135693. 0
  135694. };
  135695. static long _vq_quantlist__44u6__p8_0[] = {
  135696. 5,
  135697. 4,
  135698. 6,
  135699. 3,
  135700. 7,
  135701. 2,
  135702. 8,
  135703. 1,
  135704. 9,
  135705. 0,
  135706. 10,
  135707. };
  135708. static long _vq_lengthlist__44u6__p8_0[] = {
  135709. 1, 4, 4, 6, 6, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7,
  135710. 9, 9,10,10,11,11, 4, 6, 6, 7, 7, 9, 9,10,10,11,
  135711. 11, 6, 8, 8, 9, 9,10,10,11,11,12,12, 6, 8, 8, 9,
  135712. 9,10,10,11,11,12,12, 8, 9, 9,10,10,11,11,12,12,
  135713. 13,13, 8, 9, 9,10,10,11,11,12,12,13,13,10,10,10,
  135714. 11,11,13,13,13,13,15,14, 9,10,10,12,11,12,13,13,
  135715. 13,14,15,11,12,12,13,13,13,13,15,14,15,15,11,11,
  135716. 12,13,13,14,14,14,15,15,15,
  135717. };
  135718. static float _vq_quantthresh__44u6__p8_0[] = {
  135719. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  135720. 38.5, 49.5,
  135721. };
  135722. static long _vq_quantmap__44u6__p8_0[] = {
  135723. 9, 7, 5, 3, 1, 0, 2, 4,
  135724. 6, 8, 10,
  135725. };
  135726. static encode_aux_threshmatch _vq_auxt__44u6__p8_0 = {
  135727. _vq_quantthresh__44u6__p8_0,
  135728. _vq_quantmap__44u6__p8_0,
  135729. 11,
  135730. 11
  135731. };
  135732. static static_codebook _44u6__p8_0 = {
  135733. 2, 121,
  135734. _vq_lengthlist__44u6__p8_0,
  135735. 1, -524582912, 1618345984, 4, 0,
  135736. _vq_quantlist__44u6__p8_0,
  135737. NULL,
  135738. &_vq_auxt__44u6__p8_0,
  135739. NULL,
  135740. 0
  135741. };
  135742. static long _vq_quantlist__44u6__p8_1[] = {
  135743. 5,
  135744. 4,
  135745. 6,
  135746. 3,
  135747. 7,
  135748. 2,
  135749. 8,
  135750. 1,
  135751. 9,
  135752. 0,
  135753. 10,
  135754. };
  135755. static long _vq_lengthlist__44u6__p8_1[] = {
  135756. 3, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 5, 7, 7,
  135757. 7, 7, 8, 7, 8, 8, 5, 5, 6, 6, 7, 7, 7, 7, 7, 8,
  135758. 8, 6, 7, 7, 7, 7, 8, 7, 8, 8, 8, 8, 6, 6, 7, 7,
  135759. 7, 7, 8, 8, 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8,
  135760. 8, 8, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
  135761. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  135762. 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  135763. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  135764. };
  135765. static float _vq_quantthresh__44u6__p8_1[] = {
  135766. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  135767. 3.5, 4.5,
  135768. };
  135769. static long _vq_quantmap__44u6__p8_1[] = {
  135770. 9, 7, 5, 3, 1, 0, 2, 4,
  135771. 6, 8, 10,
  135772. };
  135773. static encode_aux_threshmatch _vq_auxt__44u6__p8_1 = {
  135774. _vq_quantthresh__44u6__p8_1,
  135775. _vq_quantmap__44u6__p8_1,
  135776. 11,
  135777. 11
  135778. };
  135779. static static_codebook _44u6__p8_1 = {
  135780. 2, 121,
  135781. _vq_lengthlist__44u6__p8_1,
  135782. 1, -531365888, 1611661312, 4, 0,
  135783. _vq_quantlist__44u6__p8_1,
  135784. NULL,
  135785. &_vq_auxt__44u6__p8_1,
  135786. NULL,
  135787. 0
  135788. };
  135789. static long _vq_quantlist__44u6__p9_0[] = {
  135790. 7,
  135791. 6,
  135792. 8,
  135793. 5,
  135794. 9,
  135795. 4,
  135796. 10,
  135797. 3,
  135798. 11,
  135799. 2,
  135800. 12,
  135801. 1,
  135802. 13,
  135803. 0,
  135804. 14,
  135805. };
  135806. static long _vq_lengthlist__44u6__p9_0[] = {
  135807. 1, 3, 2, 9, 8,15,15,15,15,15,15,15,15,15,15, 4,
  135808. 8, 9,13,14,14,14,14,14,14,14,14,14,14,14, 5, 8,
  135809. 9,14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,
  135810. 14,14,14,14,14,14,14,14,14,14,14,14,11,14,14,14,
  135811. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135812. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135813. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135814. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135815. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135816. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135817. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135818. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135819. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135820. 14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,14,
  135821. 14,
  135822. };
  135823. static float _vq_quantthresh__44u6__p9_0[] = {
  135824. -1657.5, -1402.5, -1147.5, -892.5, -637.5, -382.5, -127.5, 127.5,
  135825. 382.5, 637.5, 892.5, 1147.5, 1402.5, 1657.5,
  135826. };
  135827. static long _vq_quantmap__44u6__p9_0[] = {
  135828. 13, 11, 9, 7, 5, 3, 1, 0,
  135829. 2, 4, 6, 8, 10, 12, 14,
  135830. };
  135831. static encode_aux_threshmatch _vq_auxt__44u6__p9_0 = {
  135832. _vq_quantthresh__44u6__p9_0,
  135833. _vq_quantmap__44u6__p9_0,
  135834. 15,
  135835. 15
  135836. };
  135837. static static_codebook _44u6__p9_0 = {
  135838. 2, 225,
  135839. _vq_lengthlist__44u6__p9_0,
  135840. 1, -514071552, 1627381760, 4, 0,
  135841. _vq_quantlist__44u6__p9_0,
  135842. NULL,
  135843. &_vq_auxt__44u6__p9_0,
  135844. NULL,
  135845. 0
  135846. };
  135847. static long _vq_quantlist__44u6__p9_1[] = {
  135848. 7,
  135849. 6,
  135850. 8,
  135851. 5,
  135852. 9,
  135853. 4,
  135854. 10,
  135855. 3,
  135856. 11,
  135857. 2,
  135858. 12,
  135859. 1,
  135860. 13,
  135861. 0,
  135862. 14,
  135863. };
  135864. static long _vq_lengthlist__44u6__p9_1[] = {
  135865. 1, 4, 4, 7, 7, 8, 9, 8, 8, 9, 8, 9, 8, 9, 9, 4,
  135866. 7, 6, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 4, 7,
  135867. 6, 9, 9,10,10, 9, 9,10,10,10,10,11,11, 7, 9, 8,
  135868. 10,10,11,11,10,10,11,11,11,11,11,11, 7, 8, 9,10,
  135869. 10,11,11,10,10,11,11,11,11,11,12, 8,10,10,11,11,
  135870. 12,12,11,11,12,12,12,12,13,12, 8,10,10,11,11,12,
  135871. 11,11,11,11,12,12,12,12,13, 8, 9, 9,11,10,11,11,
  135872. 12,12,12,12,13,12,13,12, 8, 9, 9,11,11,11,11,12,
  135873. 12,12,12,12,13,13,13, 9,10,10,11,12,12,12,12,12,
  135874. 13,13,13,13,13,13, 9,10,10,11,11,12,12,12,12,13,
  135875. 13,13,13,14,13,10,10,10,12,11,12,12,13,13,13,13,
  135876. 13,13,13,13,10,10,11,11,11,12,12,13,13,13,13,13,
  135877. 13,13,13,10,11,11,12,12,13,12,12,13,13,13,13,13,
  135878. 13,14,10,11,11,12,12,13,12,13,13,13,14,13,13,14,
  135879. 13,
  135880. };
  135881. static float _vq_quantthresh__44u6__p9_1[] = {
  135882. -110.5, -93.5, -76.5, -59.5, -42.5, -25.5, -8.5, 8.5,
  135883. 25.5, 42.5, 59.5, 76.5, 93.5, 110.5,
  135884. };
  135885. static long _vq_quantmap__44u6__p9_1[] = {
  135886. 13, 11, 9, 7, 5, 3, 1, 0,
  135887. 2, 4, 6, 8, 10, 12, 14,
  135888. };
  135889. static encode_aux_threshmatch _vq_auxt__44u6__p9_1 = {
  135890. _vq_quantthresh__44u6__p9_1,
  135891. _vq_quantmap__44u6__p9_1,
  135892. 15,
  135893. 15
  135894. };
  135895. static static_codebook _44u6__p9_1 = {
  135896. 2, 225,
  135897. _vq_lengthlist__44u6__p9_1,
  135898. 1, -522338304, 1620115456, 4, 0,
  135899. _vq_quantlist__44u6__p9_1,
  135900. NULL,
  135901. &_vq_auxt__44u6__p9_1,
  135902. NULL,
  135903. 0
  135904. };
  135905. static long _vq_quantlist__44u6__p9_2[] = {
  135906. 8,
  135907. 7,
  135908. 9,
  135909. 6,
  135910. 10,
  135911. 5,
  135912. 11,
  135913. 4,
  135914. 12,
  135915. 3,
  135916. 13,
  135917. 2,
  135918. 14,
  135919. 1,
  135920. 15,
  135921. 0,
  135922. 16,
  135923. };
  135924. static long _vq_lengthlist__44u6__p9_2[] = {
  135925. 3, 5, 5, 7, 7, 8, 8, 8, 8, 8, 8, 9, 8, 8, 9, 9,
  135926. 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9, 9,
  135927. 9, 9, 5, 6, 6, 7, 7, 8, 8, 8, 8, 8, 8, 9, 9, 9,
  135928. 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135929. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135930. 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135931. 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  135932. 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9, 9,
  135933. 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  135934. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 9, 9, 9, 9, 9, 9,
  135935. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 8, 9, 9, 9, 9, 9,
  135936. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  135937. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9, 9, 9, 9, 9,
  135938. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,
  135939. 9, 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9, 9,
  135940. 9, 9, 9, 9, 9, 9, 9,10, 9, 9, 9,10, 9, 9,10, 9,
  135941. 9, 9, 9, 9, 9, 9, 9, 9,10,10,10, 9,10, 9,10,10,
  135942. 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10,10, 9, 9,
  135943. 10,
  135944. };
  135945. static float _vq_quantthresh__44u6__p9_2[] = {
  135946. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  135947. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  135948. };
  135949. static long _vq_quantmap__44u6__p9_2[] = {
  135950. 15, 13, 11, 9, 7, 5, 3, 1,
  135951. 0, 2, 4, 6, 8, 10, 12, 14,
  135952. 16,
  135953. };
  135954. static encode_aux_threshmatch _vq_auxt__44u6__p9_2 = {
  135955. _vq_quantthresh__44u6__p9_2,
  135956. _vq_quantmap__44u6__p9_2,
  135957. 17,
  135958. 17
  135959. };
  135960. static static_codebook _44u6__p9_2 = {
  135961. 2, 289,
  135962. _vq_lengthlist__44u6__p9_2,
  135963. 1, -529530880, 1611661312, 5, 0,
  135964. _vq_quantlist__44u6__p9_2,
  135965. NULL,
  135966. &_vq_auxt__44u6__p9_2,
  135967. NULL,
  135968. 0
  135969. };
  135970. static long _huff_lengthlist__44u6__short[] = {
  135971. 4,11,16,13,17,13,17,16,17,17, 4, 7, 9, 9,13,10,
  135972. 16,12,16,17, 7, 6, 5, 7, 8, 9,12,12,16,17, 6, 9,
  135973. 7, 9,10,10,15,15,17,17, 6, 7, 5, 7, 5, 7, 7,10,
  135974. 16,17, 7, 9, 8, 9, 8,10,11,11,15,17, 7, 7, 7, 8,
  135975. 5, 8, 8, 9,15,17, 8, 7, 9, 9, 7, 8, 7, 2, 7,15,
  135976. 14,13,13,15, 5,10, 4, 3, 6,17,17,15,13,17, 7,11,
  135977. 7, 6, 9,16,
  135978. };
  135979. static static_codebook _huff_book__44u6__short = {
  135980. 2, 100,
  135981. _huff_lengthlist__44u6__short,
  135982. 0, 0, 0, 0, 0,
  135983. NULL,
  135984. NULL,
  135985. NULL,
  135986. NULL,
  135987. 0
  135988. };
  135989. static long _huff_lengthlist__44u7__long[] = {
  135990. 3, 9,14,13,15,14,16,13,13,14, 5, 5, 7, 7, 8, 9,
  135991. 11,10,12,15,10, 6, 5, 6, 6, 9,10,10,13,16,10, 6,
  135992. 6, 6, 6, 8, 9, 9,12,15,14, 7, 6, 6, 5, 6, 6, 8,
  135993. 12,15,10, 8, 7, 7, 6, 7, 7, 7,11,13,14,10, 9, 8,
  135994. 5, 6, 4, 5, 9,12,10, 9, 9, 8, 6, 6, 5, 3, 6,11,
  135995. 12,11,12,12,10, 9, 8, 5, 5, 8,10,11,15,13,13,13,
  135996. 12, 8, 6, 7,
  135997. };
  135998. static static_codebook _huff_book__44u7__long = {
  135999. 2, 100,
  136000. _huff_lengthlist__44u7__long,
  136001. 0, 0, 0, 0, 0,
  136002. NULL,
  136003. NULL,
  136004. NULL,
  136005. NULL,
  136006. 0
  136007. };
  136008. static long _vq_quantlist__44u7__p1_0[] = {
  136009. 1,
  136010. 0,
  136011. 2,
  136012. };
  136013. static long _vq_lengthlist__44u7__p1_0[] = {
  136014. 1, 4, 4, 4, 7, 7, 5, 7, 7, 5, 8, 8, 8,10,10, 7,
  136015. 10,10, 5, 8, 8, 7,10,10, 8,10,10, 5, 8, 8, 8,11,
  136016. 10, 8,10,10, 8,10,10,10,12,13,10,13,13, 7,10,10,
  136017. 10,13,12,10,13,13, 5, 8, 8, 8,11,10, 8,10,11, 7,
  136018. 10,10,10,13,13,10,12,13, 8,11,11,10,13,13,10,13,
  136019. 12,
  136020. };
  136021. static float _vq_quantthresh__44u7__p1_0[] = {
  136022. -0.5, 0.5,
  136023. };
  136024. static long _vq_quantmap__44u7__p1_0[] = {
  136025. 1, 0, 2,
  136026. };
  136027. static encode_aux_threshmatch _vq_auxt__44u7__p1_0 = {
  136028. _vq_quantthresh__44u7__p1_0,
  136029. _vq_quantmap__44u7__p1_0,
  136030. 3,
  136031. 3
  136032. };
  136033. static static_codebook _44u7__p1_0 = {
  136034. 4, 81,
  136035. _vq_lengthlist__44u7__p1_0,
  136036. 1, -535822336, 1611661312, 2, 0,
  136037. _vq_quantlist__44u7__p1_0,
  136038. NULL,
  136039. &_vq_auxt__44u7__p1_0,
  136040. NULL,
  136041. 0
  136042. };
  136043. static long _vq_quantlist__44u7__p2_0[] = {
  136044. 1,
  136045. 0,
  136046. 2,
  136047. };
  136048. static long _vq_lengthlist__44u7__p2_0[] = {
  136049. 3, 4, 4, 5, 6, 6, 5, 6, 6, 5, 6, 6, 6, 8, 8, 6,
  136050. 7, 8, 5, 6, 6, 6, 8, 7, 6, 8, 8, 5, 6, 6, 6, 8,
  136051. 7, 6, 8, 8, 6, 8, 8, 8, 9, 9, 8, 9, 9, 6, 8, 7,
  136052. 7, 9, 8, 8, 9, 9, 5, 6, 6, 6, 8, 7, 6, 8, 8, 6,
  136053. 8, 8, 8, 9, 9, 7, 8, 9, 6, 8, 8, 8, 9, 9, 8, 9,
  136054. 9,
  136055. };
  136056. static float _vq_quantthresh__44u7__p2_0[] = {
  136057. -0.5, 0.5,
  136058. };
  136059. static long _vq_quantmap__44u7__p2_0[] = {
  136060. 1, 0, 2,
  136061. };
  136062. static encode_aux_threshmatch _vq_auxt__44u7__p2_0 = {
  136063. _vq_quantthresh__44u7__p2_0,
  136064. _vq_quantmap__44u7__p2_0,
  136065. 3,
  136066. 3
  136067. };
  136068. static static_codebook _44u7__p2_0 = {
  136069. 4, 81,
  136070. _vq_lengthlist__44u7__p2_0,
  136071. 1, -535822336, 1611661312, 2, 0,
  136072. _vq_quantlist__44u7__p2_0,
  136073. NULL,
  136074. &_vq_auxt__44u7__p2_0,
  136075. NULL,
  136076. 0
  136077. };
  136078. static long _vq_quantlist__44u7__p3_0[] = {
  136079. 2,
  136080. 1,
  136081. 3,
  136082. 0,
  136083. 4,
  136084. };
  136085. static long _vq_lengthlist__44u7__p3_0[] = {
  136086. 2, 5, 4, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136087. 9, 9,13,12, 8, 9,10,12,13, 5, 7, 7,10, 9, 7, 9,
  136088. 9,11,11, 6, 8, 9,11,11,10,11,11,14,14, 9,10,11,
  136089. 13,14, 5, 7, 7, 9, 9, 7, 9, 8,11,11, 7, 9, 9,11,
  136090. 11, 9,11,10,14,13,10,11,11,14,14, 8,10,10,14,13,
  136091. 10,11,12,15,14, 9,11,11,15,14,13,14,14,16,16,12,
  136092. 13,14,17,16, 8,10,10,13,13, 9,11,11,14,15,10,11,
  136093. 12,14,15,12,14,13,16,16,13,14,15,15,17, 5, 7, 7,
  136094. 10,10, 7, 9, 9,11,11, 7, 9, 9,11,11,10,12,11,15,
  136095. 14,10,11,12,14,14, 7, 9, 9,12,12, 9,11,11,13,13,
  136096. 9,11,11,13,13,11,13,13,14,17,11,13,13,15,16, 6,
  136097. 9, 9,11,11, 8,11,10,13,12, 9,11,11,13,13,11,13,
  136098. 12,16,14,11,13,13,16,16,10,12,12,15,15,11,13,13,
  136099. 16,16,11,13,13,16,15,14,16,17,17,19,14,16,16,18,
  136100. 0, 9,11,11,14,15,10,13,12,16,15,11,13,13,16,16,
  136101. 14,15,14, 0,16,14,16,16,18, 0, 5, 7, 7,10,10, 7,
  136102. 9, 9,12,11, 7, 9, 9,11,12,10,11,11,15,14,10,11,
  136103. 12,14,14, 6, 9, 9,11,11, 9,11,11,13,13, 8,10,11,
  136104. 12,13,11,13,13,17,15,11,12,13,14,15, 7, 9, 9,11,
  136105. 12, 9,11,11,13,13, 9,11,11,13,13,11,13,12,16,16,
  136106. 11,13,13,15,14, 9,11,11,14,15,11,13,13,16,15,10,
  136107. 12,13,16,16,15,16,16, 0, 0,14,13,15,16,18,10,11,
  136108. 11,15,15,11,13,14,16,18,11,13,13,16,15,15,16,16,
  136109. 19, 0,14,15,15,16,16, 8,10,10,13,13,10,12,11,16,
  136110. 15,10,11,11,16,15,13,15,16,18, 0,13,14,15,17,17,
  136111. 9,11,11,15,15,11,13,13,16,18,11,13,13,16,17,15,
  136112. 16,16, 0, 0,15,18,16, 0,17, 9,11,11,15,15,11,13,
  136113. 12,17,15,11,13,14,16,17,15,18,15, 0,17,15,16,16,
  136114. 18,19,13,15,14, 0,18,14,16,16,19,18,14,16,15,19,
  136115. 19,16,18,19, 0, 0,16,17, 0, 0, 0,12,14,14,17,17,
  136116. 13,16,14, 0,18,14,16,15,18, 0,16,18,16,19,17,18,
  136117. 19,17, 0, 0, 8,10,10,14,14, 9,12,11,15,15,10,11,
  136118. 12,15,17,13,15,15,18,16,14,16,15,18,17, 9,11,11,
  136119. 16,15,11,13,13, 0,16,11,12,13,16,15,15,16,16, 0,
  136120. 17,15,15,16,18,17, 9,12,11,15,17,11,13,13,16,16,
  136121. 11,14,13,16,16,15,15,16,18,19,16,18,16, 0, 0,12,
  136122. 14,14, 0,16,14,16,16, 0,18,13,14,15,16, 0,17,16,
  136123. 18, 0, 0,16,16,17,19, 0,13,14,14,17, 0,14,17,16,
  136124. 0,19,14,15,15,18,19,17,16,18, 0, 0,15,19,16, 0,
  136125. 0,
  136126. };
  136127. static float _vq_quantthresh__44u7__p3_0[] = {
  136128. -1.5, -0.5, 0.5, 1.5,
  136129. };
  136130. static long _vq_quantmap__44u7__p3_0[] = {
  136131. 3, 1, 0, 2, 4,
  136132. };
  136133. static encode_aux_threshmatch _vq_auxt__44u7__p3_0 = {
  136134. _vq_quantthresh__44u7__p3_0,
  136135. _vq_quantmap__44u7__p3_0,
  136136. 5,
  136137. 5
  136138. };
  136139. static static_codebook _44u7__p3_0 = {
  136140. 4, 625,
  136141. _vq_lengthlist__44u7__p3_0,
  136142. 1, -533725184, 1611661312, 3, 0,
  136143. _vq_quantlist__44u7__p3_0,
  136144. NULL,
  136145. &_vq_auxt__44u7__p3_0,
  136146. NULL,
  136147. 0
  136148. };
  136149. static long _vq_quantlist__44u7__p4_0[] = {
  136150. 2,
  136151. 1,
  136152. 3,
  136153. 0,
  136154. 4,
  136155. };
  136156. static long _vq_lengthlist__44u7__p4_0[] = {
  136157. 4, 5, 5, 8, 8, 6, 7, 6, 9, 9, 6, 6, 7, 9, 9, 8,
  136158. 9, 9,11,11, 8, 9, 9,10,11, 6, 7, 7, 9, 9, 7, 8,
  136159. 8,10,10, 6, 7, 8, 9,10, 9,10,10,12,12, 9, 9,10,
  136160. 11,12, 6, 7, 7, 9, 9, 6, 8, 7,10, 9, 7, 8, 8,10,
  136161. 10, 9,10, 9,12,11, 9,10,10,12,11, 8, 9, 9,11,11,
  136162. 9,10,10,12,12, 9,10,10,12,12,11,12,12,13,14,11,
  136163. 11,12,13,13, 8, 9, 9,11,11, 9,10,10,12,11, 9,10,
  136164. 10,12,12,11,12,11,13,13,11,12,12,13,13, 6, 7, 7,
  136165. 9, 9, 7, 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,
  136166. 11, 9,10,10,12,12, 7, 8, 8,10,10, 8, 8, 9,11,11,
  136167. 8, 9, 9,11,11,10,11,11,12,12,10,10,11,12,13, 6,
  136168. 7, 7,10,10, 7, 9, 8,11,10, 8, 8, 9,10,11,10,11,
  136169. 10,13,11,10,11,11,12,12, 9,10,10,12,12,10,10,11,
  136170. 13,13,10,11,11,13,12,12,12,13,13,14,12,12,13,14,
  136171. 14, 9,10,10,12,12, 9,10,10,12,12,10,11,11,13,13,
  136172. 11,12,11,14,12,12,13,13,14,14, 6, 7, 7, 9, 9, 7,
  136173. 8, 7,10,10, 7, 7, 8,10,10, 9,10,10,12,11, 9,10,
  136174. 10,11,12, 6, 7, 7,10,10, 8, 9, 8,11,10, 7, 8, 9,
  136175. 10,11,10,11,11,13,12,10,10,11,11,13, 7, 8, 8,10,
  136176. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,10,13,12,
  136177. 10,11,11,12,12, 9,10,10,12,12,10,11,11,13,12, 9,
  136178. 10,10,12,13,12,13,12,14,14,11,11,12,12,14, 9,10,
  136179. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,12,
  136180. 14,14,12,13,12,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136181. 12, 9,10,10,12,12,11,12,12,14,13,11,12,12,13,13,
  136182. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,12,12,
  136183. 13,13,14,14,12,12,13,14,14, 9,10,10,12,12, 9,11,
  136184. 10,13,12,10,10,11,12,13,11,13,12,14,13,12,12,13,
  136185. 14,14,11,12,12,13,13,11,12,13,14,14,12,13,13,14,
  136186. 14,13,13,14,14,16,13,14,14,16,16,11,11,11,13,13,
  136187. 11,12,11,14,13,12,12,13,14,15,13,14,12,16,13,14,
  136188. 14,14,15,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136189. 10,12,12,11,12,12,14,13,11,12,12,13,14, 9,10,10,
  136190. 12,12,10,11,10,13,12, 9,10,11,12,13,12,13,12,14,
  136191. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,12,13,
  136192. 10,11,11,13,13,12,13,12,14,14,12,13,13,14,14,11,
  136193. 12,12,13,13,12,13,12,14,14,11,11,12,13,14,13,15,
  136194. 14,16,15,13,12,14,13,16,11,12,12,13,13,12,13,13,
  136195. 14,14,12,12,12,14,14,13,14,14,15,15,13,14,13,16,
  136196. 14,
  136197. };
  136198. static float _vq_quantthresh__44u7__p4_0[] = {
  136199. -1.5, -0.5, 0.5, 1.5,
  136200. };
  136201. static long _vq_quantmap__44u7__p4_0[] = {
  136202. 3, 1, 0, 2, 4,
  136203. };
  136204. static encode_aux_threshmatch _vq_auxt__44u7__p4_0 = {
  136205. _vq_quantthresh__44u7__p4_0,
  136206. _vq_quantmap__44u7__p4_0,
  136207. 5,
  136208. 5
  136209. };
  136210. static static_codebook _44u7__p4_0 = {
  136211. 4, 625,
  136212. _vq_lengthlist__44u7__p4_0,
  136213. 1, -533725184, 1611661312, 3, 0,
  136214. _vq_quantlist__44u7__p4_0,
  136215. NULL,
  136216. &_vq_auxt__44u7__p4_0,
  136217. NULL,
  136218. 0
  136219. };
  136220. static long _vq_quantlist__44u7__p5_0[] = {
  136221. 4,
  136222. 3,
  136223. 5,
  136224. 2,
  136225. 6,
  136226. 1,
  136227. 7,
  136228. 0,
  136229. 8,
  136230. };
  136231. static long _vq_lengthlist__44u7__p5_0[] = {
  136232. 2, 3, 3, 6, 6, 7, 8,10,10, 4, 5, 5, 8, 7, 8, 8,
  136233. 11,11, 3, 5, 5, 7, 7, 8, 9,11,11, 6, 8, 7, 9, 9,
  136234. 10,10,12,12, 6, 7, 8, 9,10,10,10,12,12, 8, 8, 8,
  136235. 10,10,12,11,13,13, 8, 8, 9,10,10,11,11,13,13,10,
  136236. 11,11,12,12,13,13,14,14,10,11,11,12,12,13,13,14,
  136237. 14,
  136238. };
  136239. static float _vq_quantthresh__44u7__p5_0[] = {
  136240. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136241. };
  136242. static long _vq_quantmap__44u7__p5_0[] = {
  136243. 7, 5, 3, 1, 0, 2, 4, 6,
  136244. 8,
  136245. };
  136246. static encode_aux_threshmatch _vq_auxt__44u7__p5_0 = {
  136247. _vq_quantthresh__44u7__p5_0,
  136248. _vq_quantmap__44u7__p5_0,
  136249. 9,
  136250. 9
  136251. };
  136252. static static_codebook _44u7__p5_0 = {
  136253. 2, 81,
  136254. _vq_lengthlist__44u7__p5_0,
  136255. 1, -531628032, 1611661312, 4, 0,
  136256. _vq_quantlist__44u7__p5_0,
  136257. NULL,
  136258. &_vq_auxt__44u7__p5_0,
  136259. NULL,
  136260. 0
  136261. };
  136262. static long _vq_quantlist__44u7__p6_0[] = {
  136263. 4,
  136264. 3,
  136265. 5,
  136266. 2,
  136267. 6,
  136268. 1,
  136269. 7,
  136270. 0,
  136271. 8,
  136272. };
  136273. static long _vq_lengthlist__44u7__p6_0[] = {
  136274. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 8, 7,
  136275. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136276. 8, 8,10,10, 5, 6, 6, 7, 7, 8, 8,10,10, 7, 8, 7,
  136277. 8, 8,10, 9,11,11, 7, 7, 8, 8, 8, 9,10,11,11, 9,
  136278. 9, 9,10,10,11,10,12,11, 9, 9, 9,10,10,11,11,11,
  136279. 12,
  136280. };
  136281. static float _vq_quantthresh__44u7__p6_0[] = {
  136282. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136283. };
  136284. static long _vq_quantmap__44u7__p6_0[] = {
  136285. 7, 5, 3, 1, 0, 2, 4, 6,
  136286. 8,
  136287. };
  136288. static encode_aux_threshmatch _vq_auxt__44u7__p6_0 = {
  136289. _vq_quantthresh__44u7__p6_0,
  136290. _vq_quantmap__44u7__p6_0,
  136291. 9,
  136292. 9
  136293. };
  136294. static static_codebook _44u7__p6_0 = {
  136295. 2, 81,
  136296. _vq_lengthlist__44u7__p6_0,
  136297. 1, -531628032, 1611661312, 4, 0,
  136298. _vq_quantlist__44u7__p6_0,
  136299. NULL,
  136300. &_vq_auxt__44u7__p6_0,
  136301. NULL,
  136302. 0
  136303. };
  136304. static long _vq_quantlist__44u7__p7_0[] = {
  136305. 1,
  136306. 0,
  136307. 2,
  136308. };
  136309. static long _vq_lengthlist__44u7__p7_0[] = {
  136310. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 9, 8, 8, 9, 9, 7,
  136311. 10,10, 5, 8, 9, 7, 9,10, 8, 9, 9, 4, 9, 9, 9,11,
  136312. 10, 8,10,10, 7,11,10,10,10,12,10,12,12, 7,10,10,
  136313. 10,12,11,10,12,12, 5, 9, 9, 8,10,10, 9,11,11, 7,
  136314. 11,10,10,12,12,10,11,12, 7,10,11,10,12,12,10,12,
  136315. 10,
  136316. };
  136317. static float _vq_quantthresh__44u7__p7_0[] = {
  136318. -5.5, 5.5,
  136319. };
  136320. static long _vq_quantmap__44u7__p7_0[] = {
  136321. 1, 0, 2,
  136322. };
  136323. static encode_aux_threshmatch _vq_auxt__44u7__p7_0 = {
  136324. _vq_quantthresh__44u7__p7_0,
  136325. _vq_quantmap__44u7__p7_0,
  136326. 3,
  136327. 3
  136328. };
  136329. static static_codebook _44u7__p7_0 = {
  136330. 4, 81,
  136331. _vq_lengthlist__44u7__p7_0,
  136332. 1, -529137664, 1618345984, 2, 0,
  136333. _vq_quantlist__44u7__p7_0,
  136334. NULL,
  136335. &_vq_auxt__44u7__p7_0,
  136336. NULL,
  136337. 0
  136338. };
  136339. static long _vq_quantlist__44u7__p7_1[] = {
  136340. 5,
  136341. 4,
  136342. 6,
  136343. 3,
  136344. 7,
  136345. 2,
  136346. 8,
  136347. 1,
  136348. 9,
  136349. 0,
  136350. 10,
  136351. };
  136352. static long _vq_lengthlist__44u7__p7_1[] = {
  136353. 3, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6,
  136354. 8, 7, 8, 8, 8, 8, 4, 5, 5, 6, 6, 7, 8, 8, 8, 8,
  136355. 8, 6, 7, 6, 7, 7, 8, 8, 9, 9, 9, 9, 6, 6, 7, 7,
  136356. 7, 8, 8, 9, 9, 9, 9, 7, 8, 7, 8, 8, 9, 9, 9, 9,
  136357. 9, 9, 7, 7, 8, 8, 8, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  136358. 9, 9, 9, 9,10, 9, 9, 9, 8, 8, 8, 9, 9, 9, 9, 9,
  136359. 9, 9,10, 8, 8, 8, 9, 9, 9, 9,10, 9,10,10, 8, 8,
  136360. 8, 9, 9, 9, 9, 9,10,10,10,
  136361. };
  136362. static float _vq_quantthresh__44u7__p7_1[] = {
  136363. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136364. 3.5, 4.5,
  136365. };
  136366. static long _vq_quantmap__44u7__p7_1[] = {
  136367. 9, 7, 5, 3, 1, 0, 2, 4,
  136368. 6, 8, 10,
  136369. };
  136370. static encode_aux_threshmatch _vq_auxt__44u7__p7_1 = {
  136371. _vq_quantthresh__44u7__p7_1,
  136372. _vq_quantmap__44u7__p7_1,
  136373. 11,
  136374. 11
  136375. };
  136376. static static_codebook _44u7__p7_1 = {
  136377. 2, 121,
  136378. _vq_lengthlist__44u7__p7_1,
  136379. 1, -531365888, 1611661312, 4, 0,
  136380. _vq_quantlist__44u7__p7_1,
  136381. NULL,
  136382. &_vq_auxt__44u7__p7_1,
  136383. NULL,
  136384. 0
  136385. };
  136386. static long _vq_quantlist__44u7__p8_0[] = {
  136387. 5,
  136388. 4,
  136389. 6,
  136390. 3,
  136391. 7,
  136392. 2,
  136393. 8,
  136394. 1,
  136395. 9,
  136396. 0,
  136397. 10,
  136398. };
  136399. static long _vq_lengthlist__44u7__p8_0[] = {
  136400. 1, 4, 4, 6, 6, 8, 8,10,10,11,11, 4, 6, 6, 7, 7,
  136401. 9, 9,11,10,12,12, 5, 6, 5, 7, 7, 9, 9,10,11,12,
  136402. 12, 6, 7, 7, 8, 8,10,10,11,11,13,13, 6, 7, 7, 8,
  136403. 8,10,10,11,12,13,13, 8, 9, 9,10,10,11,11,12,12,
  136404. 14,14, 8, 9, 9,10,10,11,11,12,12,14,14,10,10,10,
  136405. 11,11,13,12,14,14,15,15,10,10,10,12,12,13,13,14,
  136406. 14,15,15,11,12,12,13,13,14,14,15,14,16,15,11,12,
  136407. 12,13,13,14,14,15,15,15,16,
  136408. };
  136409. static float _vq_quantthresh__44u7__p8_0[] = {
  136410. -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5, 27.5,
  136411. 38.5, 49.5,
  136412. };
  136413. static long _vq_quantmap__44u7__p8_0[] = {
  136414. 9, 7, 5, 3, 1, 0, 2, 4,
  136415. 6, 8, 10,
  136416. };
  136417. static encode_aux_threshmatch _vq_auxt__44u7__p8_0 = {
  136418. _vq_quantthresh__44u7__p8_0,
  136419. _vq_quantmap__44u7__p8_0,
  136420. 11,
  136421. 11
  136422. };
  136423. static static_codebook _44u7__p8_0 = {
  136424. 2, 121,
  136425. _vq_lengthlist__44u7__p8_0,
  136426. 1, -524582912, 1618345984, 4, 0,
  136427. _vq_quantlist__44u7__p8_0,
  136428. NULL,
  136429. &_vq_auxt__44u7__p8_0,
  136430. NULL,
  136431. 0
  136432. };
  136433. static long _vq_quantlist__44u7__p8_1[] = {
  136434. 5,
  136435. 4,
  136436. 6,
  136437. 3,
  136438. 7,
  136439. 2,
  136440. 8,
  136441. 1,
  136442. 9,
  136443. 0,
  136444. 10,
  136445. };
  136446. static long _vq_lengthlist__44u7__p8_1[] = {
  136447. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  136448. 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 7, 7, 7, 7, 7, 7,
  136449. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  136450. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  136451. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  136452. 7, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  136453. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  136454. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  136455. };
  136456. static float _vq_quantthresh__44u7__p8_1[] = {
  136457. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136458. 3.5, 4.5,
  136459. };
  136460. static long _vq_quantmap__44u7__p8_1[] = {
  136461. 9, 7, 5, 3, 1, 0, 2, 4,
  136462. 6, 8, 10,
  136463. };
  136464. static encode_aux_threshmatch _vq_auxt__44u7__p8_1 = {
  136465. _vq_quantthresh__44u7__p8_1,
  136466. _vq_quantmap__44u7__p8_1,
  136467. 11,
  136468. 11
  136469. };
  136470. static static_codebook _44u7__p8_1 = {
  136471. 2, 121,
  136472. _vq_lengthlist__44u7__p8_1,
  136473. 1, -531365888, 1611661312, 4, 0,
  136474. _vq_quantlist__44u7__p8_1,
  136475. NULL,
  136476. &_vq_auxt__44u7__p8_1,
  136477. NULL,
  136478. 0
  136479. };
  136480. static long _vq_quantlist__44u7__p9_0[] = {
  136481. 5,
  136482. 4,
  136483. 6,
  136484. 3,
  136485. 7,
  136486. 2,
  136487. 8,
  136488. 1,
  136489. 9,
  136490. 0,
  136491. 10,
  136492. };
  136493. static long _vq_lengthlist__44u7__p9_0[] = {
  136494. 1, 3, 3,10,10,10,10,10,10,10,10, 4,10,10,10,10,
  136495. 10,10,10,10,10,10, 4,10,10,10,10,10,10,10,10,10,
  136496. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136497. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136498. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136499. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  136500. 10,10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9,
  136501. 9, 9, 9, 9, 9, 9, 9, 9, 9,
  136502. };
  136503. static float _vq_quantthresh__44u7__p9_0[] = {
  136504. -2866.5, -2229.5, -1592.5, -955.5, -318.5, 318.5, 955.5, 1592.5,
  136505. 2229.5, 2866.5,
  136506. };
  136507. static long _vq_quantmap__44u7__p9_0[] = {
  136508. 9, 7, 5, 3, 1, 0, 2, 4,
  136509. 6, 8, 10,
  136510. };
  136511. static encode_aux_threshmatch _vq_auxt__44u7__p9_0 = {
  136512. _vq_quantthresh__44u7__p9_0,
  136513. _vq_quantmap__44u7__p9_0,
  136514. 11,
  136515. 11
  136516. };
  136517. static static_codebook _44u7__p9_0 = {
  136518. 2, 121,
  136519. _vq_lengthlist__44u7__p9_0,
  136520. 1, -512171520, 1630791680, 4, 0,
  136521. _vq_quantlist__44u7__p9_0,
  136522. NULL,
  136523. &_vq_auxt__44u7__p9_0,
  136524. NULL,
  136525. 0
  136526. };
  136527. static long _vq_quantlist__44u7__p9_1[] = {
  136528. 6,
  136529. 5,
  136530. 7,
  136531. 4,
  136532. 8,
  136533. 3,
  136534. 9,
  136535. 2,
  136536. 10,
  136537. 1,
  136538. 11,
  136539. 0,
  136540. 12,
  136541. };
  136542. static long _vq_lengthlist__44u7__p9_1[] = {
  136543. 1, 4, 4, 6, 5, 8, 6, 9, 8,10, 9,11,10, 4, 6, 6,
  136544. 8, 8, 9, 9,11,10,11,11,11,11, 4, 6, 6, 8, 8,10,
  136545. 9,11,11,11,11,11,12, 6, 8, 8,10,10,11,11,12,12,
  136546. 13,12,13,13, 6, 8, 8,10,10,11,11,12,12,12,13,14,
  136547. 13, 8,10,10,11,11,12,13,14,14,14,14,15,15, 8,10,
  136548. 10,11,12,12,13,13,14,14,14,14,15, 9,11,11,13,13,
  136549. 14,14,15,14,16,15,17,15, 9,11,11,12,13,14,14,15,
  136550. 14,15,15,15,16,10,12,12,13,14,15,15,15,15,16,17,
  136551. 16,17,10,13,12,13,14,14,16,16,16,16,15,16,17,11,
  136552. 13,13,14,15,14,17,15,16,17,17,17,17,11,13,13,14,
  136553. 15,15,15,15,17,17,16,17,16,
  136554. };
  136555. static float _vq_quantthresh__44u7__p9_1[] = {
  136556. -269.5, -220.5, -171.5, -122.5, -73.5, -24.5, 24.5, 73.5,
  136557. 122.5, 171.5, 220.5, 269.5,
  136558. };
  136559. static long _vq_quantmap__44u7__p9_1[] = {
  136560. 11, 9, 7, 5, 3, 1, 0, 2,
  136561. 4, 6, 8, 10, 12,
  136562. };
  136563. static encode_aux_threshmatch _vq_auxt__44u7__p9_1 = {
  136564. _vq_quantthresh__44u7__p9_1,
  136565. _vq_quantmap__44u7__p9_1,
  136566. 13,
  136567. 13
  136568. };
  136569. static static_codebook _44u7__p9_1 = {
  136570. 2, 169,
  136571. _vq_lengthlist__44u7__p9_1,
  136572. 1, -518889472, 1622704128, 4, 0,
  136573. _vq_quantlist__44u7__p9_1,
  136574. NULL,
  136575. &_vq_auxt__44u7__p9_1,
  136576. NULL,
  136577. 0
  136578. };
  136579. static long _vq_quantlist__44u7__p9_2[] = {
  136580. 24,
  136581. 23,
  136582. 25,
  136583. 22,
  136584. 26,
  136585. 21,
  136586. 27,
  136587. 20,
  136588. 28,
  136589. 19,
  136590. 29,
  136591. 18,
  136592. 30,
  136593. 17,
  136594. 31,
  136595. 16,
  136596. 32,
  136597. 15,
  136598. 33,
  136599. 14,
  136600. 34,
  136601. 13,
  136602. 35,
  136603. 12,
  136604. 36,
  136605. 11,
  136606. 37,
  136607. 10,
  136608. 38,
  136609. 9,
  136610. 39,
  136611. 8,
  136612. 40,
  136613. 7,
  136614. 41,
  136615. 6,
  136616. 42,
  136617. 5,
  136618. 43,
  136619. 4,
  136620. 44,
  136621. 3,
  136622. 45,
  136623. 2,
  136624. 46,
  136625. 1,
  136626. 47,
  136627. 0,
  136628. 48,
  136629. };
  136630. static long _vq_lengthlist__44u7__p9_2[] = {
  136631. 2, 4, 4, 4, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  136632. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  136633. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
  136634. 8,
  136635. };
  136636. static float _vq_quantthresh__44u7__p9_2[] = {
  136637. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  136638. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  136639. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136640. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136641. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  136642. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  136643. };
  136644. static long _vq_quantmap__44u7__p9_2[] = {
  136645. 47, 45, 43, 41, 39, 37, 35, 33,
  136646. 31, 29, 27, 25, 23, 21, 19, 17,
  136647. 15, 13, 11, 9, 7, 5, 3, 1,
  136648. 0, 2, 4, 6, 8, 10, 12, 14,
  136649. 16, 18, 20, 22, 24, 26, 28, 30,
  136650. 32, 34, 36, 38, 40, 42, 44, 46,
  136651. 48,
  136652. };
  136653. static encode_aux_threshmatch _vq_auxt__44u7__p9_2 = {
  136654. _vq_quantthresh__44u7__p9_2,
  136655. _vq_quantmap__44u7__p9_2,
  136656. 49,
  136657. 49
  136658. };
  136659. static static_codebook _44u7__p9_2 = {
  136660. 1, 49,
  136661. _vq_lengthlist__44u7__p9_2,
  136662. 1, -526909440, 1611661312, 6, 0,
  136663. _vq_quantlist__44u7__p9_2,
  136664. NULL,
  136665. &_vq_auxt__44u7__p9_2,
  136666. NULL,
  136667. 0
  136668. };
  136669. static long _huff_lengthlist__44u7__short[] = {
  136670. 5,12,17,16,16,17,17,17,17,17, 4, 7,11,11,12, 9,
  136671. 17,10,17,17, 7, 7, 8, 9, 7, 9,11,10,15,17, 7, 9,
  136672. 10,11,10,12,14,12,16,17, 7, 8, 5, 7, 4, 7, 7, 8,
  136673. 16,16, 6,10, 9,10, 7,10,11,11,16,17, 6, 8, 8, 9,
  136674. 5, 7, 5, 8,16,17, 5, 5, 8, 7, 6, 7, 7, 6, 6,14,
  136675. 12,10,12,11, 7,11, 4, 4, 2, 7,17,15,15,15, 8,15,
  136676. 6, 8, 5, 9,
  136677. };
  136678. static static_codebook _huff_book__44u7__short = {
  136679. 2, 100,
  136680. _huff_lengthlist__44u7__short,
  136681. 0, 0, 0, 0, 0,
  136682. NULL,
  136683. NULL,
  136684. NULL,
  136685. NULL,
  136686. 0
  136687. };
  136688. static long _huff_lengthlist__44u8__long[] = {
  136689. 3, 9,13,14,14,15,14,14,15,15, 5, 4, 6, 8,10,12,
  136690. 12,14,15,15, 9, 5, 4, 5, 8,10,11,13,16,16,10, 7,
  136691. 4, 3, 5, 7, 9,11,13,13,10, 9, 7, 4, 4, 6, 8,10,
  136692. 12,14,13,11, 9, 6, 5, 5, 6, 8,12,14,13,11,10, 8,
  136693. 7, 6, 6, 7,10,14,13,11,12,10, 8, 7, 6, 6, 9,13,
  136694. 12,11,14,12,11, 9, 8, 7, 9,11,11,12,14,13,14,11,
  136695. 10, 8, 8, 9,
  136696. };
  136697. static static_codebook _huff_book__44u8__long = {
  136698. 2, 100,
  136699. _huff_lengthlist__44u8__long,
  136700. 0, 0, 0, 0, 0,
  136701. NULL,
  136702. NULL,
  136703. NULL,
  136704. NULL,
  136705. 0
  136706. };
  136707. static long _huff_lengthlist__44u8__short[] = {
  136708. 6,14,18,18,17,17,17,17,17,17, 4, 7, 9, 9,10,13,
  136709. 15,17,17,17, 6, 7, 5, 6, 8,11,16,17,16,17, 5, 7,
  136710. 5, 4, 6,10,14,17,17,17, 6, 6, 6, 5, 7,10,13,16,
  136711. 17,17, 7, 6, 7, 7, 7, 8, 7,10,15,16,12, 9, 9, 6,
  136712. 6, 5, 3, 5,11,15,14,14,13, 5, 5, 7, 3, 4, 8,15,
  136713. 17,17,13, 7, 7,10, 6, 6,10,15,17,17,16,10,11,14,
  136714. 10,10,15,17,
  136715. };
  136716. static static_codebook _huff_book__44u8__short = {
  136717. 2, 100,
  136718. _huff_lengthlist__44u8__short,
  136719. 0, 0, 0, 0, 0,
  136720. NULL,
  136721. NULL,
  136722. NULL,
  136723. NULL,
  136724. 0
  136725. };
  136726. static long _vq_quantlist__44u8_p1_0[] = {
  136727. 1,
  136728. 0,
  136729. 2,
  136730. };
  136731. static long _vq_lengthlist__44u8_p1_0[] = {
  136732. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 8, 9, 9, 7,
  136733. 9, 9, 5, 7, 7, 7, 9, 9, 8, 9, 9, 5, 7, 7, 7, 9,
  136734. 9, 7, 9, 9, 7, 9, 9, 9,10,11, 9,11,10, 7, 9, 9,
  136735. 9,11,10, 9,10,11, 5, 7, 7, 7, 9, 9, 7, 9, 9, 7,
  136736. 9, 9, 9,11,10, 9,10,10, 8, 9, 9, 9,11,11, 9,11,
  136737. 10,
  136738. };
  136739. static float _vq_quantthresh__44u8_p1_0[] = {
  136740. -0.5, 0.5,
  136741. };
  136742. static long _vq_quantmap__44u8_p1_0[] = {
  136743. 1, 0, 2,
  136744. };
  136745. static encode_aux_threshmatch _vq_auxt__44u8_p1_0 = {
  136746. _vq_quantthresh__44u8_p1_0,
  136747. _vq_quantmap__44u8_p1_0,
  136748. 3,
  136749. 3
  136750. };
  136751. static static_codebook _44u8_p1_0 = {
  136752. 4, 81,
  136753. _vq_lengthlist__44u8_p1_0,
  136754. 1, -535822336, 1611661312, 2, 0,
  136755. _vq_quantlist__44u8_p1_0,
  136756. NULL,
  136757. &_vq_auxt__44u8_p1_0,
  136758. NULL,
  136759. 0
  136760. };
  136761. static long _vq_quantlist__44u8_p2_0[] = {
  136762. 2,
  136763. 1,
  136764. 3,
  136765. 0,
  136766. 4,
  136767. };
  136768. static long _vq_lengthlist__44u8_p2_0[] = {
  136769. 4, 5, 5, 8, 8, 5, 7, 6, 9, 9, 5, 6, 7, 9, 9, 8,
  136770. 9, 9,11,11, 8, 9, 9,11,11, 5, 7, 7, 9, 9, 7, 8,
  136771. 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,10,
  136772. 11,12, 5, 7, 7, 9, 9, 7, 8, 7,10,10, 7, 8, 8,10,
  136773. 10, 9,10, 9,12,11, 9,10,10,12,12, 8, 9, 9,12,11,
  136774. 9,10,10,12,12, 9,10,10,12,12,11,12,12,14,14,11,
  136775. 11,12,13,14, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136776. 10,12,12,11,12,11,13,13,11,12,12,14,14, 5, 7, 7,
  136777. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  136778. 12, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  136779. 8, 9, 9,11,11,10,11,11,12,13,10,11,11,12,13, 6,
  136780. 8, 8,10,10, 8, 9, 8,11,10, 8, 9, 9,11,11,10,11,
  136781. 10,13,12,10,11,11,13,13, 9,10,10,12,12,10,11,11,
  136782. 13,13,10,11,11,13,13,12,12,13,13,14,12,13,13,14,
  136783. 14, 9,10,10,12,12,10,11,10,13,12,10,11,11,13,13,
  136784. 11,13,12,14,13,12,13,13,14,14, 5, 7, 7, 9, 9, 7,
  136785. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,12, 9,10,
  136786. 10,12,12, 7, 8, 8,10,10, 8, 9, 9,11,11, 8, 8, 9,
  136787. 10,11,10,11,11,13,13,10,10,11,12,13, 7, 8, 8,10,
  136788. 10, 8, 9, 9,11,11, 8, 9, 9,11,11,10,11,11,13,13,
  136789. 10,11,11,13,12, 9,10,10,12,12,10,11,11,13,13,10,
  136790. 10,11,12,13,12,13,13,14,14,12,12,13,13,14, 9,10,
  136791. 10,12,12,10,11,11,13,13,10,11,11,13,13,12,13,13,
  136792. 15,14,12,13,13,14,13, 8, 9, 9,11,11, 9,10,10,12,
  136793. 12, 9,10,10,12,12,12,12,12,14,13,11,12,12,14,14,
  136794. 9,10,10,12,12,10,11,11,13,13,10,11,11,13,13,12,
  136795. 13,13,14,15,12,13,13,14,15, 9,10,10,12,12,10,11,
  136796. 10,13,12,10,11,11,13,13,12,13,12,15,14,12,13,13,
  136797. 14,15,11,12,12,14,14,12,13,13,14,14,12,13,13,15,
  136798. 14,14,14,14,14,16,14,14,15,16,16,11,12,12,14,14,
  136799. 11,12,12,14,14,12,13,13,14,15,13,14,13,16,14,14,
  136800. 14,14,16,16, 8, 9, 9,11,11, 9,10,10,12,12, 9,10,
  136801. 10,12,12,11,12,12,14,13,11,12,12,14,14, 9,10,10,
  136802. 12,12,10,11,11,13,13,10,10,11,12,13,12,13,13,15,
  136803. 14,12,12,13,13,14, 9,10,10,12,12,10,11,11,13,13,
  136804. 10,11,11,13,13,12,13,13,14,14,12,13,13,15,14,11,
  136805. 12,12,14,13,12,13,13,15,14,11,12,12,13,14,14,15,
  136806. 14,16,15,13,13,14,13,16,11,12,12,14,14,12,13,13,
  136807. 14,15,12,13,12,15,14,14,14,14,16,15,14,15,13,16,
  136808. 14,
  136809. };
  136810. static float _vq_quantthresh__44u8_p2_0[] = {
  136811. -1.5, -0.5, 0.5, 1.5,
  136812. };
  136813. static long _vq_quantmap__44u8_p2_0[] = {
  136814. 3, 1, 0, 2, 4,
  136815. };
  136816. static encode_aux_threshmatch _vq_auxt__44u8_p2_0 = {
  136817. _vq_quantthresh__44u8_p2_0,
  136818. _vq_quantmap__44u8_p2_0,
  136819. 5,
  136820. 5
  136821. };
  136822. static static_codebook _44u8_p2_0 = {
  136823. 4, 625,
  136824. _vq_lengthlist__44u8_p2_0,
  136825. 1, -533725184, 1611661312, 3, 0,
  136826. _vq_quantlist__44u8_p2_0,
  136827. NULL,
  136828. &_vq_auxt__44u8_p2_0,
  136829. NULL,
  136830. 0
  136831. };
  136832. static long _vq_quantlist__44u8_p3_0[] = {
  136833. 4,
  136834. 3,
  136835. 5,
  136836. 2,
  136837. 6,
  136838. 1,
  136839. 7,
  136840. 0,
  136841. 8,
  136842. };
  136843. static long _vq_lengthlist__44u8_p3_0[] = {
  136844. 3, 4, 4, 5, 5, 7, 7, 9, 9, 4, 5, 4, 6, 6, 7, 7,
  136845. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  136846. 8, 8,10,10, 6, 6, 6, 7, 7, 8, 8,10,10, 7, 7, 7,
  136847. 8, 8, 9, 9,11,10, 7, 7, 7, 8, 8, 9, 9,10,11, 9,
  136848. 9, 9,10,10,11,10,12,11, 9, 9, 9, 9,10,11,11,11,
  136849. 12,
  136850. };
  136851. static float _vq_quantthresh__44u8_p3_0[] = {
  136852. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  136853. };
  136854. static long _vq_quantmap__44u8_p3_0[] = {
  136855. 7, 5, 3, 1, 0, 2, 4, 6,
  136856. 8,
  136857. };
  136858. static encode_aux_threshmatch _vq_auxt__44u8_p3_0 = {
  136859. _vq_quantthresh__44u8_p3_0,
  136860. _vq_quantmap__44u8_p3_0,
  136861. 9,
  136862. 9
  136863. };
  136864. static static_codebook _44u8_p3_0 = {
  136865. 2, 81,
  136866. _vq_lengthlist__44u8_p3_0,
  136867. 1, -531628032, 1611661312, 4, 0,
  136868. _vq_quantlist__44u8_p3_0,
  136869. NULL,
  136870. &_vq_auxt__44u8_p3_0,
  136871. NULL,
  136872. 0
  136873. };
  136874. static long _vq_quantlist__44u8_p4_0[] = {
  136875. 8,
  136876. 7,
  136877. 9,
  136878. 6,
  136879. 10,
  136880. 5,
  136881. 11,
  136882. 4,
  136883. 12,
  136884. 3,
  136885. 13,
  136886. 2,
  136887. 14,
  136888. 1,
  136889. 15,
  136890. 0,
  136891. 16,
  136892. };
  136893. static long _vq_lengthlist__44u8_p4_0[] = {
  136894. 4, 4, 4, 6, 6, 7, 7, 8, 8, 8, 8,10,10,11,11,11,
  136895. 11, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,
  136896. 12,12, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9,10,10,11,
  136897. 11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,10,
  136898. 11,11,12,12, 6, 6, 6, 7, 7, 8, 8, 9, 9, 9, 9,10,
  136899. 10,11,11,12,12, 7, 7, 7, 8, 8, 9, 8,10, 9,10, 9,
  136900. 11,10,12,11,13,12, 7, 7, 7, 8, 8, 8, 9, 9,10, 9,
  136901. 10,10,11,11,12,12,13, 8, 8, 8, 9, 9, 9, 9,10,10,
  136902. 11,10,11,11,12,12,13,13, 8, 8, 8, 9, 9, 9,10,10,
  136903. 10,10,11,11,11,12,12,12,13, 8, 9, 9, 9, 9,10, 9,
  136904. 11,10,11,11,12,11,13,12,13,13, 8, 9, 9, 9, 9, 9,
  136905. 10,10,11,11,11,11,12,12,13,13,13,10,10,10,10,10,
  136906. 11,10,11,11,12,11,13,12,13,13,14,13,10,10,10,10,
  136907. 10,10,11,11,11,11,12,12,13,13,13,13,14,11,11,11,
  136908. 11,11,12,11,12,12,13,12,13,13,14,13,14,14,11,11,
  136909. 11,11,11,11,12,12,12,12,13,13,13,13,14,14,14,11,
  136910. 12,12,12,12,13,12,13,12,13,13,14,13,14,14,14,14,
  136911. 11,12,12,12,12,12,12,13,13,13,13,13,14,14,14,14,
  136912. 14,
  136913. };
  136914. static float _vq_quantthresh__44u8_p4_0[] = {
  136915. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  136916. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  136917. };
  136918. static long _vq_quantmap__44u8_p4_0[] = {
  136919. 15, 13, 11, 9, 7, 5, 3, 1,
  136920. 0, 2, 4, 6, 8, 10, 12, 14,
  136921. 16,
  136922. };
  136923. static encode_aux_threshmatch _vq_auxt__44u8_p4_0 = {
  136924. _vq_quantthresh__44u8_p4_0,
  136925. _vq_quantmap__44u8_p4_0,
  136926. 17,
  136927. 17
  136928. };
  136929. static static_codebook _44u8_p4_0 = {
  136930. 2, 289,
  136931. _vq_lengthlist__44u8_p4_0,
  136932. 1, -529530880, 1611661312, 5, 0,
  136933. _vq_quantlist__44u8_p4_0,
  136934. NULL,
  136935. &_vq_auxt__44u8_p4_0,
  136936. NULL,
  136937. 0
  136938. };
  136939. static long _vq_quantlist__44u8_p5_0[] = {
  136940. 1,
  136941. 0,
  136942. 2,
  136943. };
  136944. static long _vq_lengthlist__44u8_p5_0[] = {
  136945. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  136946. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  136947. 10, 8,10,10, 7,10,10, 9,10,12, 9,12,11, 7,10,10,
  136948. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  136949. 10,10, 9,11,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  136950. 10,
  136951. };
  136952. static float _vq_quantthresh__44u8_p5_0[] = {
  136953. -5.5, 5.5,
  136954. };
  136955. static long _vq_quantmap__44u8_p5_0[] = {
  136956. 1, 0, 2,
  136957. };
  136958. static encode_aux_threshmatch _vq_auxt__44u8_p5_0 = {
  136959. _vq_quantthresh__44u8_p5_0,
  136960. _vq_quantmap__44u8_p5_0,
  136961. 3,
  136962. 3
  136963. };
  136964. static static_codebook _44u8_p5_0 = {
  136965. 4, 81,
  136966. _vq_lengthlist__44u8_p5_0,
  136967. 1, -529137664, 1618345984, 2, 0,
  136968. _vq_quantlist__44u8_p5_0,
  136969. NULL,
  136970. &_vq_auxt__44u8_p5_0,
  136971. NULL,
  136972. 0
  136973. };
  136974. static long _vq_quantlist__44u8_p5_1[] = {
  136975. 5,
  136976. 4,
  136977. 6,
  136978. 3,
  136979. 7,
  136980. 2,
  136981. 8,
  136982. 1,
  136983. 9,
  136984. 0,
  136985. 10,
  136986. };
  136987. static long _vq_lengthlist__44u8_p5_1[] = {
  136988. 4, 5, 5, 6, 6, 7, 7, 7, 7, 8, 8, 5, 5, 5, 6, 6,
  136989. 7, 7, 8, 8, 8, 8, 5, 5, 5, 6, 6, 7, 7, 7, 8, 8,
  136990. 8, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 6, 6, 6, 7,
  136991. 7, 7, 7, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8,
  136992. 8, 8, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 8, 7, 8, 7,
  136993. 8, 8, 8, 8, 8, 8, 8, 8, 7, 8, 8, 8, 8, 8, 8, 8,
  136994. 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 9, 9, 8, 8,
  136995. 8, 8, 8, 8, 8, 8, 8, 9, 9,
  136996. };
  136997. static float _vq_quantthresh__44u8_p5_1[] = {
  136998. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  136999. 3.5, 4.5,
  137000. };
  137001. static long _vq_quantmap__44u8_p5_1[] = {
  137002. 9, 7, 5, 3, 1, 0, 2, 4,
  137003. 6, 8, 10,
  137004. };
  137005. static encode_aux_threshmatch _vq_auxt__44u8_p5_1 = {
  137006. _vq_quantthresh__44u8_p5_1,
  137007. _vq_quantmap__44u8_p5_1,
  137008. 11,
  137009. 11
  137010. };
  137011. static static_codebook _44u8_p5_1 = {
  137012. 2, 121,
  137013. _vq_lengthlist__44u8_p5_1,
  137014. 1, -531365888, 1611661312, 4, 0,
  137015. _vq_quantlist__44u8_p5_1,
  137016. NULL,
  137017. &_vq_auxt__44u8_p5_1,
  137018. NULL,
  137019. 0
  137020. };
  137021. static long _vq_quantlist__44u8_p6_0[] = {
  137022. 6,
  137023. 5,
  137024. 7,
  137025. 4,
  137026. 8,
  137027. 3,
  137028. 9,
  137029. 2,
  137030. 10,
  137031. 1,
  137032. 11,
  137033. 0,
  137034. 12,
  137035. };
  137036. static long _vq_lengthlist__44u8_p6_0[] = {
  137037. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137038. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 6, 6, 7, 7, 8,
  137039. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 7, 8, 8, 8, 8, 9,
  137040. 9,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 8,10, 9,11,
  137041. 10, 7, 8, 8, 8, 8, 8, 9, 9, 9,10,10,11,11, 7, 8,
  137042. 8, 8, 8, 9, 8, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137043. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137044. 9,10,10,11,11, 9, 9, 9, 9,10,10,10,10,10,10,11,
  137045. 11,12, 9, 9, 9,10, 9,10,10,10,10,11,10,12,11,10,
  137046. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137047. 11,11,11,11,11,12,11,12,12,
  137048. };
  137049. static float _vq_quantthresh__44u8_p6_0[] = {
  137050. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137051. 12.5, 17.5, 22.5, 27.5,
  137052. };
  137053. static long _vq_quantmap__44u8_p6_0[] = {
  137054. 11, 9, 7, 5, 3, 1, 0, 2,
  137055. 4, 6, 8, 10, 12,
  137056. };
  137057. static encode_aux_threshmatch _vq_auxt__44u8_p6_0 = {
  137058. _vq_quantthresh__44u8_p6_0,
  137059. _vq_quantmap__44u8_p6_0,
  137060. 13,
  137061. 13
  137062. };
  137063. static static_codebook _44u8_p6_0 = {
  137064. 2, 169,
  137065. _vq_lengthlist__44u8_p6_0,
  137066. 1, -526516224, 1616117760, 4, 0,
  137067. _vq_quantlist__44u8_p6_0,
  137068. NULL,
  137069. &_vq_auxt__44u8_p6_0,
  137070. NULL,
  137071. 0
  137072. };
  137073. static long _vq_quantlist__44u8_p6_1[] = {
  137074. 2,
  137075. 1,
  137076. 3,
  137077. 0,
  137078. 4,
  137079. };
  137080. static long _vq_lengthlist__44u8_p6_1[] = {
  137081. 3, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5,
  137082. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137083. };
  137084. static float _vq_quantthresh__44u8_p6_1[] = {
  137085. -1.5, -0.5, 0.5, 1.5,
  137086. };
  137087. static long _vq_quantmap__44u8_p6_1[] = {
  137088. 3, 1, 0, 2, 4,
  137089. };
  137090. static encode_aux_threshmatch _vq_auxt__44u8_p6_1 = {
  137091. _vq_quantthresh__44u8_p6_1,
  137092. _vq_quantmap__44u8_p6_1,
  137093. 5,
  137094. 5
  137095. };
  137096. static static_codebook _44u8_p6_1 = {
  137097. 2, 25,
  137098. _vq_lengthlist__44u8_p6_1,
  137099. 1, -533725184, 1611661312, 3, 0,
  137100. _vq_quantlist__44u8_p6_1,
  137101. NULL,
  137102. &_vq_auxt__44u8_p6_1,
  137103. NULL,
  137104. 0
  137105. };
  137106. static long _vq_quantlist__44u8_p7_0[] = {
  137107. 6,
  137108. 5,
  137109. 7,
  137110. 4,
  137111. 8,
  137112. 3,
  137113. 9,
  137114. 2,
  137115. 10,
  137116. 1,
  137117. 11,
  137118. 0,
  137119. 12,
  137120. };
  137121. static long _vq_lengthlist__44u8_p7_0[] = {
  137122. 1, 4, 5, 6, 6, 7, 7, 8, 8,10,10,11,11, 5, 6, 6,
  137123. 7, 7, 8, 8, 9, 9,11,10,12,11, 5, 6, 6, 7, 7, 8,
  137124. 8, 9, 9,10,11,11,12, 6, 7, 7, 8, 8, 9, 9,10,10,
  137125. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,12,13,
  137126. 12, 7, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137127. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137128. 11,11,12,12,13,13,14,14, 9, 9, 9,10,10,11,11,12,
  137129. 12,13,13,14,14,10,11,11,12,11,13,12,13,13,14,14,
  137130. 15,15,10,11,11,11,12,12,13,13,14,14,14,15,15,11,
  137131. 12,12,13,13,14,13,15,14,15,15,16,15,11,11,12,13,
  137132. 13,13,14,14,14,15,15,15,16,
  137133. };
  137134. static float _vq_quantthresh__44u8_p7_0[] = {
  137135. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137136. 27.5, 38.5, 49.5, 60.5,
  137137. };
  137138. static long _vq_quantmap__44u8_p7_0[] = {
  137139. 11, 9, 7, 5, 3, 1, 0, 2,
  137140. 4, 6, 8, 10, 12,
  137141. };
  137142. static encode_aux_threshmatch _vq_auxt__44u8_p7_0 = {
  137143. _vq_quantthresh__44u8_p7_0,
  137144. _vq_quantmap__44u8_p7_0,
  137145. 13,
  137146. 13
  137147. };
  137148. static static_codebook _44u8_p7_0 = {
  137149. 2, 169,
  137150. _vq_lengthlist__44u8_p7_0,
  137151. 1, -523206656, 1618345984, 4, 0,
  137152. _vq_quantlist__44u8_p7_0,
  137153. NULL,
  137154. &_vq_auxt__44u8_p7_0,
  137155. NULL,
  137156. 0
  137157. };
  137158. static long _vq_quantlist__44u8_p7_1[] = {
  137159. 5,
  137160. 4,
  137161. 6,
  137162. 3,
  137163. 7,
  137164. 2,
  137165. 8,
  137166. 1,
  137167. 9,
  137168. 0,
  137169. 10,
  137170. };
  137171. static long _vq_lengthlist__44u8_p7_1[] = {
  137172. 4, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7,
  137173. 7, 7, 7, 7, 7, 7, 5, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  137174. 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 8, 8, 6, 7, 7, 7,
  137175. 7, 7, 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8,
  137176. 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 7, 7, 7,
  137177. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 7, 8, 8, 8,
  137178. 8, 8, 8, 7, 7, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 7,
  137179. 7, 8, 8, 8, 8, 8, 8, 8, 8,
  137180. };
  137181. static float _vq_quantthresh__44u8_p7_1[] = {
  137182. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137183. 3.5, 4.5,
  137184. };
  137185. static long _vq_quantmap__44u8_p7_1[] = {
  137186. 9, 7, 5, 3, 1, 0, 2, 4,
  137187. 6, 8, 10,
  137188. };
  137189. static encode_aux_threshmatch _vq_auxt__44u8_p7_1 = {
  137190. _vq_quantthresh__44u8_p7_1,
  137191. _vq_quantmap__44u8_p7_1,
  137192. 11,
  137193. 11
  137194. };
  137195. static static_codebook _44u8_p7_1 = {
  137196. 2, 121,
  137197. _vq_lengthlist__44u8_p7_1,
  137198. 1, -531365888, 1611661312, 4, 0,
  137199. _vq_quantlist__44u8_p7_1,
  137200. NULL,
  137201. &_vq_auxt__44u8_p7_1,
  137202. NULL,
  137203. 0
  137204. };
  137205. static long _vq_quantlist__44u8_p8_0[] = {
  137206. 7,
  137207. 6,
  137208. 8,
  137209. 5,
  137210. 9,
  137211. 4,
  137212. 10,
  137213. 3,
  137214. 11,
  137215. 2,
  137216. 12,
  137217. 1,
  137218. 13,
  137219. 0,
  137220. 14,
  137221. };
  137222. static long _vq_lengthlist__44u8_p8_0[] = {
  137223. 1, 4, 4, 7, 7, 8, 8, 8, 7, 9, 8,10, 9,11,10, 4,
  137224. 6, 6, 8, 8,10, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  137225. 6, 8, 8,10,10, 9, 9,10,10,11,11,11,12, 7, 8, 8,
  137226. 10,10,11,11,11,10,12,11,12,12,13,11, 7, 8, 8,10,
  137227. 10,11,11,10,10,11,11,12,12,13,13, 8,10,10,11,11,
  137228. 12,11,12,11,13,12,13,12,14,13, 8,10, 9,11,11,12,
  137229. 12,12,12,12,12,13,13,14,13, 8, 9, 9,11,10,12,11,
  137230. 13,12,13,13,14,13,14,13, 8, 9, 9,10,11,12,12,12,
  137231. 12,13,13,14,15,14,14, 9,10,10,12,11,13,12,13,13,
  137232. 14,13,14,14,14,14, 9,10,10,12,12,12,12,13,13,14,
  137233. 14,14,15,14,14,10,11,11,13,12,13,12,14,14,14,14,
  137234. 14,14,15,15,10,11,11,12,12,13,13,14,14,14,15,15,
  137235. 14,16,15,11,12,12,13,12,14,14,14,13,15,14,15,15,
  137236. 15,17,11,12,12,13,13,14,14,14,15,15,14,15,15,14,
  137237. 17,
  137238. };
  137239. static float _vq_quantthresh__44u8_p8_0[] = {
  137240. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  137241. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  137242. };
  137243. static long _vq_quantmap__44u8_p8_0[] = {
  137244. 13, 11, 9, 7, 5, 3, 1, 0,
  137245. 2, 4, 6, 8, 10, 12, 14,
  137246. };
  137247. static encode_aux_threshmatch _vq_auxt__44u8_p8_0 = {
  137248. _vq_quantthresh__44u8_p8_0,
  137249. _vq_quantmap__44u8_p8_0,
  137250. 15,
  137251. 15
  137252. };
  137253. static static_codebook _44u8_p8_0 = {
  137254. 2, 225,
  137255. _vq_lengthlist__44u8_p8_0,
  137256. 1, -520986624, 1620377600, 4, 0,
  137257. _vq_quantlist__44u8_p8_0,
  137258. NULL,
  137259. &_vq_auxt__44u8_p8_0,
  137260. NULL,
  137261. 0
  137262. };
  137263. static long _vq_quantlist__44u8_p8_1[] = {
  137264. 10,
  137265. 9,
  137266. 11,
  137267. 8,
  137268. 12,
  137269. 7,
  137270. 13,
  137271. 6,
  137272. 14,
  137273. 5,
  137274. 15,
  137275. 4,
  137276. 16,
  137277. 3,
  137278. 17,
  137279. 2,
  137280. 18,
  137281. 1,
  137282. 19,
  137283. 0,
  137284. 20,
  137285. };
  137286. static long _vq_lengthlist__44u8_p8_1[] = {
  137287. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  137288. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137289. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 5, 6, 6, 7, 7, 8,
  137290. 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  137291. 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137292. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  137293. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  137294. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10, 9,10, 8, 8,
  137295. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137296. 10, 9,10, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137297. 10,10,10,10,10,10,10,10, 8, 9, 8, 9, 9, 9, 9, 9,
  137298. 9, 9, 9, 9, 9, 9,10,10,10,10, 9,10,10, 9, 9, 9,
  137299. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137300. 10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,
  137301. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,
  137302. 10,10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  137303. 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,
  137304. 10, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  137305. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  137306. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  137307. 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  137308. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137309. 10,10,10,10,10, 9, 9, 9,10, 9,10,10,10,10,10,10,
  137310. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,10,
  137311. 9,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  137312. 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,
  137313. 10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,10,
  137314. 10,10,10,10,10,10,10,10,10,
  137315. };
  137316. static float _vq_quantthresh__44u8_p8_1[] = {
  137317. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  137318. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  137319. 6.5, 7.5, 8.5, 9.5,
  137320. };
  137321. static long _vq_quantmap__44u8_p8_1[] = {
  137322. 19, 17, 15, 13, 11, 9, 7, 5,
  137323. 3, 1, 0, 2, 4, 6, 8, 10,
  137324. 12, 14, 16, 18, 20,
  137325. };
  137326. static encode_aux_threshmatch _vq_auxt__44u8_p8_1 = {
  137327. _vq_quantthresh__44u8_p8_1,
  137328. _vq_quantmap__44u8_p8_1,
  137329. 21,
  137330. 21
  137331. };
  137332. static static_codebook _44u8_p8_1 = {
  137333. 2, 441,
  137334. _vq_lengthlist__44u8_p8_1,
  137335. 1, -529268736, 1611661312, 5, 0,
  137336. _vq_quantlist__44u8_p8_1,
  137337. NULL,
  137338. &_vq_auxt__44u8_p8_1,
  137339. NULL,
  137340. 0
  137341. };
  137342. static long _vq_quantlist__44u8_p9_0[] = {
  137343. 4,
  137344. 3,
  137345. 5,
  137346. 2,
  137347. 6,
  137348. 1,
  137349. 7,
  137350. 0,
  137351. 8,
  137352. };
  137353. static long _vq_lengthlist__44u8_p9_0[] = {
  137354. 1, 3, 3, 9, 9, 9, 9, 9, 9, 4, 9, 9, 9, 9, 9, 9,
  137355. 9, 9, 5, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137356. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137357. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  137358. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8,
  137359. 8,
  137360. };
  137361. static float _vq_quantthresh__44u8_p9_0[] = {
  137362. -3258.5, -2327.5, -1396.5, -465.5, 465.5, 1396.5, 2327.5, 3258.5,
  137363. };
  137364. static long _vq_quantmap__44u8_p9_0[] = {
  137365. 7, 5, 3, 1, 0, 2, 4, 6,
  137366. 8,
  137367. };
  137368. static encode_aux_threshmatch _vq_auxt__44u8_p9_0 = {
  137369. _vq_quantthresh__44u8_p9_0,
  137370. _vq_quantmap__44u8_p9_0,
  137371. 9,
  137372. 9
  137373. };
  137374. static static_codebook _44u8_p9_0 = {
  137375. 2, 81,
  137376. _vq_lengthlist__44u8_p9_0,
  137377. 1, -511895552, 1631393792, 4, 0,
  137378. _vq_quantlist__44u8_p9_0,
  137379. NULL,
  137380. &_vq_auxt__44u8_p9_0,
  137381. NULL,
  137382. 0
  137383. };
  137384. static long _vq_quantlist__44u8_p9_1[] = {
  137385. 9,
  137386. 8,
  137387. 10,
  137388. 7,
  137389. 11,
  137390. 6,
  137391. 12,
  137392. 5,
  137393. 13,
  137394. 4,
  137395. 14,
  137396. 3,
  137397. 15,
  137398. 2,
  137399. 16,
  137400. 1,
  137401. 17,
  137402. 0,
  137403. 18,
  137404. };
  137405. static long _vq_lengthlist__44u8_p9_1[] = {
  137406. 1, 4, 4, 7, 7, 8, 7, 8, 6, 9, 7,10, 8,11,10,11,
  137407. 11,11,11, 4, 7, 6, 9, 9,10, 9, 9, 9,10,10,11,10,
  137408. 11,10,11,11,13,11, 4, 7, 7, 9, 9, 9, 9, 9, 9,10,
  137409. 10,11,10,11,11,11,12,11,12, 7, 9, 8,11,11,11,11,
  137410. 10,10,11,11,12,12,12,12,12,12,14,13, 7, 8, 9,10,
  137411. 11,11,11,10,10,11,11,11,11,12,12,14,12,13,14, 8,
  137412. 9, 9,11,11,11,11,11,11,12,12,14,12,15,14,14,14,
  137413. 15,14, 8, 9, 9,11,11,11,11,12,11,12,12,13,13,13,
  137414. 13,13,13,14,14, 8, 9, 9,11,10,12,11,12,12,13,13,
  137415. 13,13,15,14,14,14,16,16, 8, 9, 9,10,11,11,12,12,
  137416. 12,13,13,13,14,14,14,15,16,15,15, 9,10,10,11,12,
  137417. 12,13,13,13,14,14,16,14,14,16,16,16,16,15, 9,10,
  137418. 10,11,11,12,13,13,14,15,14,16,14,15,16,16,16,16,
  137419. 15,10,11,11,12,13,13,14,15,15,15,15,15,16,15,16,
  137420. 15,16,15,15,10,11,11,13,13,14,13,13,15,14,15,15,
  137421. 16,15,15,15,16,15,16,10,12,12,14,14,14,14,14,16,
  137422. 16,15,15,15,16,16,16,16,16,16,11,12,12,14,14,14,
  137423. 14,15,15,16,15,16,15,16,15,16,16,16,16,12,12,13,
  137424. 14,14,15,16,16,16,16,16,16,15,16,16,16,16,16,16,
  137425. 12,13,13,14,14,14,14,15,16,15,16,16,16,16,16,16,
  137426. 16,16,16,12,13,14,14,14,16,15,16,15,16,16,16,16,
  137427. 16,16,16,16,16,16,12,14,13,14,15,15,15,16,15,16,
  137428. 16,15,16,16,16,16,16,16,16,
  137429. };
  137430. static float _vq_quantthresh__44u8_p9_1[] = {
  137431. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  137432. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  137433. 367.5, 416.5,
  137434. };
  137435. static long _vq_quantmap__44u8_p9_1[] = {
  137436. 17, 15, 13, 11, 9, 7, 5, 3,
  137437. 1, 0, 2, 4, 6, 8, 10, 12,
  137438. 14, 16, 18,
  137439. };
  137440. static encode_aux_threshmatch _vq_auxt__44u8_p9_1 = {
  137441. _vq_quantthresh__44u8_p9_1,
  137442. _vq_quantmap__44u8_p9_1,
  137443. 19,
  137444. 19
  137445. };
  137446. static static_codebook _44u8_p9_1 = {
  137447. 2, 361,
  137448. _vq_lengthlist__44u8_p9_1,
  137449. 1, -518287360, 1622704128, 5, 0,
  137450. _vq_quantlist__44u8_p9_1,
  137451. NULL,
  137452. &_vq_auxt__44u8_p9_1,
  137453. NULL,
  137454. 0
  137455. };
  137456. static long _vq_quantlist__44u8_p9_2[] = {
  137457. 24,
  137458. 23,
  137459. 25,
  137460. 22,
  137461. 26,
  137462. 21,
  137463. 27,
  137464. 20,
  137465. 28,
  137466. 19,
  137467. 29,
  137468. 18,
  137469. 30,
  137470. 17,
  137471. 31,
  137472. 16,
  137473. 32,
  137474. 15,
  137475. 33,
  137476. 14,
  137477. 34,
  137478. 13,
  137479. 35,
  137480. 12,
  137481. 36,
  137482. 11,
  137483. 37,
  137484. 10,
  137485. 38,
  137486. 9,
  137487. 39,
  137488. 8,
  137489. 40,
  137490. 7,
  137491. 41,
  137492. 6,
  137493. 42,
  137494. 5,
  137495. 43,
  137496. 4,
  137497. 44,
  137498. 3,
  137499. 45,
  137500. 2,
  137501. 46,
  137502. 1,
  137503. 47,
  137504. 0,
  137505. 48,
  137506. };
  137507. static long _vq_lengthlist__44u8_p9_2[] = {
  137508. 2, 3, 4, 5, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6, 6,
  137509. 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137510. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  137511. 7,
  137512. };
  137513. static float _vq_quantthresh__44u8_p9_2[] = {
  137514. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  137515. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  137516. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137517. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137518. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  137519. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  137520. };
  137521. static long _vq_quantmap__44u8_p9_2[] = {
  137522. 47, 45, 43, 41, 39, 37, 35, 33,
  137523. 31, 29, 27, 25, 23, 21, 19, 17,
  137524. 15, 13, 11, 9, 7, 5, 3, 1,
  137525. 0, 2, 4, 6, 8, 10, 12, 14,
  137526. 16, 18, 20, 22, 24, 26, 28, 30,
  137527. 32, 34, 36, 38, 40, 42, 44, 46,
  137528. 48,
  137529. };
  137530. static encode_aux_threshmatch _vq_auxt__44u8_p9_2 = {
  137531. _vq_quantthresh__44u8_p9_2,
  137532. _vq_quantmap__44u8_p9_2,
  137533. 49,
  137534. 49
  137535. };
  137536. static static_codebook _44u8_p9_2 = {
  137537. 1, 49,
  137538. _vq_lengthlist__44u8_p9_2,
  137539. 1, -526909440, 1611661312, 6, 0,
  137540. _vq_quantlist__44u8_p9_2,
  137541. NULL,
  137542. &_vq_auxt__44u8_p9_2,
  137543. NULL,
  137544. 0
  137545. };
  137546. static long _huff_lengthlist__44u9__long[] = {
  137547. 3, 9,13,13,14,15,14,14,15,15, 5, 5, 9,10,12,12,
  137548. 13,14,16,15,10, 6, 6, 6, 8,11,12,13,16,15,11, 7,
  137549. 5, 3, 5, 8,10,12,15,15,10,10, 7, 4, 3, 5, 8,10,
  137550. 12,12,12,12, 9, 7, 5, 4, 6, 8,10,13,13,12,11, 9,
  137551. 7, 5, 5, 6, 9,12,14,12,12,10, 8, 6, 6, 6, 7,11,
  137552. 13,12,14,13,10, 8, 7, 7, 7,10,11,11,12,13,12,11,
  137553. 10, 8, 8, 9,
  137554. };
  137555. static static_codebook _huff_book__44u9__long = {
  137556. 2, 100,
  137557. _huff_lengthlist__44u9__long,
  137558. 0, 0, 0, 0, 0,
  137559. NULL,
  137560. NULL,
  137561. NULL,
  137562. NULL,
  137563. 0
  137564. };
  137565. static long _huff_lengthlist__44u9__short[] = {
  137566. 9,16,18,18,17,17,17,17,17,17, 5, 8,11,12,11,12,
  137567. 17,17,16,16, 6, 6, 8, 8, 9,10,14,15,16,16, 6, 7,
  137568. 7, 4, 6, 9,13,16,16,16, 6, 6, 7, 4, 5, 8,11,15,
  137569. 17,16, 7, 6, 7, 6, 6, 8, 9,10,14,16,11, 8, 8, 7,
  137570. 6, 6, 3, 4,10,15,14,12,12,10, 5, 6, 3, 3, 8,13,
  137571. 15,17,15,11, 6, 8, 6, 6, 9,14,17,15,15,12, 8,10,
  137572. 9, 9,12,15,
  137573. };
  137574. static static_codebook _huff_book__44u9__short = {
  137575. 2, 100,
  137576. _huff_lengthlist__44u9__short,
  137577. 0, 0, 0, 0, 0,
  137578. NULL,
  137579. NULL,
  137580. NULL,
  137581. NULL,
  137582. 0
  137583. };
  137584. static long _vq_quantlist__44u9_p1_0[] = {
  137585. 1,
  137586. 0,
  137587. 2,
  137588. };
  137589. static long _vq_lengthlist__44u9_p1_0[] = {
  137590. 1, 5, 5, 5, 7, 7, 5, 7, 7, 5, 7, 7, 7, 9, 9, 7,
  137591. 9, 9, 5, 7, 7, 7, 9, 9, 7, 9, 9, 5, 7, 7, 7, 9,
  137592. 9, 7, 9, 9, 8, 9, 9, 9,10,11, 9,11,11, 7, 9, 9,
  137593. 9,11,10, 9,11,11, 5, 7, 7, 7, 9, 9, 8, 9,10, 7,
  137594. 9, 9, 9,11,11, 9,10,11, 7, 9,10, 9,11,11, 9,11,
  137595. 10,
  137596. };
  137597. static float _vq_quantthresh__44u9_p1_0[] = {
  137598. -0.5, 0.5,
  137599. };
  137600. static long _vq_quantmap__44u9_p1_0[] = {
  137601. 1, 0, 2,
  137602. };
  137603. static encode_aux_threshmatch _vq_auxt__44u9_p1_0 = {
  137604. _vq_quantthresh__44u9_p1_0,
  137605. _vq_quantmap__44u9_p1_0,
  137606. 3,
  137607. 3
  137608. };
  137609. static static_codebook _44u9_p1_0 = {
  137610. 4, 81,
  137611. _vq_lengthlist__44u9_p1_0,
  137612. 1, -535822336, 1611661312, 2, 0,
  137613. _vq_quantlist__44u9_p1_0,
  137614. NULL,
  137615. &_vq_auxt__44u9_p1_0,
  137616. NULL,
  137617. 0
  137618. };
  137619. static long _vq_quantlist__44u9_p2_0[] = {
  137620. 2,
  137621. 1,
  137622. 3,
  137623. 0,
  137624. 4,
  137625. };
  137626. static long _vq_lengthlist__44u9_p2_0[] = {
  137627. 3, 5, 5, 8, 8, 5, 7, 7, 9, 9, 6, 7, 7, 9, 9, 8,
  137628. 9, 9,11,10, 8, 9, 9,11,11, 6, 7, 7, 9, 9, 7, 8,
  137629. 8,10,10, 7, 8, 8, 9,10, 9,10,10,11,11, 9, 9,10,
  137630. 11,11, 6, 7, 7, 9, 9, 7, 8, 8,10, 9, 7, 8, 8,10,
  137631. 10, 9,10, 9,11,11, 9,10,10,11,11, 8, 9, 9,11,11,
  137632. 9,10,10,12,11, 9,10,10,11,12,11,11,11,13,13,11,
  137633. 11,11,12,13, 8, 9, 9,11,11, 9,10,10,11,11, 9,10,
  137634. 10,12,11,11,12,11,13,12,11,11,12,13,13, 6, 7, 7,
  137635. 9, 9, 7, 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,12,
  137636. 11, 9,10,10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,11,
  137637. 8, 9, 9,10,10,10,11,11,12,12,10,10,11,12,12, 7,
  137638. 8, 8,10,10, 8, 9, 8,10,10, 8, 9, 9,10,10,10,11,
  137639. 10,12,11,10,10,11,12,12, 9,10,10,11,12,10,11,11,
  137640. 12,12,10,11,10,12,12,12,12,12,13,13,11,12,12,13,
  137641. 13, 9,10,10,11,11, 9,10,10,12,12,10,11,11,12,13,
  137642. 11,12,11,13,12,12,12,12,13,14, 6, 7, 7, 9, 9, 7,
  137643. 8, 8,10,10, 7, 8, 8,10,10, 9,10,10,11,11, 9,10,
  137644. 10,11,12, 7, 8, 8,10,10, 8, 9, 9,11,10, 8, 8, 9,
  137645. 10,10,10,11,10,12,12,10,10,11,11,12, 7, 8, 8,10,
  137646. 10, 8, 9, 9,10,10, 8, 9, 9,10,10,10,11,10,12,12,
  137647. 10,11,10,12,12, 9,10,10,12,11,10,11,11,12,12, 9,
  137648. 10,10,12,12,12,12,12,13,13,11,11,12,12,14, 9,10,
  137649. 10,11,12,10,11,11,12,12,10,11,11,12,12,11,12,12,
  137650. 14,14,12,12,12,13,13, 8, 9, 9,11,11, 9,10,10,12,
  137651. 11, 9,10,10,12,12,11,12,11,13,13,11,11,12,13,13,
  137652. 9,10,10,12,12,10,11,11,12,12,10,11,11,12,12,12,
  137653. 12,12,14,14,12,12,12,13,13, 9,10,10,12,11,10,11,
  137654. 10,12,12,10,11,11,12,12,11,12,12,14,13,12,12,12,
  137655. 13,14,11,12,11,13,13,11,12,12,13,13,12,12,12,14,
  137656. 14,13,13,13,13,15,13,13,14,15,15,11,11,11,13,13,
  137657. 11,12,11,13,13,11,12,12,13,13,12,13,12,15,13,13,
  137658. 13,14,14,15, 8, 9, 9,11,11, 9,10,10,11,12, 9,10,
  137659. 10,11,12,11,12,11,13,13,11,12,12,13,13, 9,10,10,
  137660. 11,12,10,11,10,12,12,10,10,11,12,13,12,12,12,14,
  137661. 13,11,12,12,13,14, 9,10,10,12,12,10,11,11,12,12,
  137662. 10,11,11,12,12,12,12,12,14,13,12,12,12,14,13,11,
  137663. 11,11,13,13,11,12,12,14,13,11,11,12,13,13,13,13,
  137664. 13,15,14,12,12,13,13,15,11,12,12,13,13,12,12,12,
  137665. 13,14,11,12,12,13,13,13,13,14,14,15,13,13,13,14,
  137666. 14,
  137667. };
  137668. static float _vq_quantthresh__44u9_p2_0[] = {
  137669. -1.5, -0.5, 0.5, 1.5,
  137670. };
  137671. static long _vq_quantmap__44u9_p2_0[] = {
  137672. 3, 1, 0, 2, 4,
  137673. };
  137674. static encode_aux_threshmatch _vq_auxt__44u9_p2_0 = {
  137675. _vq_quantthresh__44u9_p2_0,
  137676. _vq_quantmap__44u9_p2_0,
  137677. 5,
  137678. 5
  137679. };
  137680. static static_codebook _44u9_p2_0 = {
  137681. 4, 625,
  137682. _vq_lengthlist__44u9_p2_0,
  137683. 1, -533725184, 1611661312, 3, 0,
  137684. _vq_quantlist__44u9_p2_0,
  137685. NULL,
  137686. &_vq_auxt__44u9_p2_0,
  137687. NULL,
  137688. 0
  137689. };
  137690. static long _vq_quantlist__44u9_p3_0[] = {
  137691. 4,
  137692. 3,
  137693. 5,
  137694. 2,
  137695. 6,
  137696. 1,
  137697. 7,
  137698. 0,
  137699. 8,
  137700. };
  137701. static long _vq_lengthlist__44u9_p3_0[] = {
  137702. 3, 4, 4, 5, 5, 7, 7, 8, 8, 4, 5, 5, 6, 6, 7, 7,
  137703. 9, 9, 4, 4, 5, 6, 6, 7, 7, 9, 9, 5, 6, 6, 7, 7,
  137704. 8, 8, 9, 9, 5, 6, 6, 7, 7, 8, 8, 9, 9, 7, 7, 7,
  137705. 8, 8, 9, 9,10,10, 7, 7, 7, 8, 8, 9, 9,10,10, 8,
  137706. 9, 9,10, 9,10,10,11,11, 8, 9, 9, 9,10,10,10,11,
  137707. 11,
  137708. };
  137709. static float _vq_quantthresh__44u9_p3_0[] = {
  137710. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  137711. };
  137712. static long _vq_quantmap__44u9_p3_0[] = {
  137713. 7, 5, 3, 1, 0, 2, 4, 6,
  137714. 8,
  137715. };
  137716. static encode_aux_threshmatch _vq_auxt__44u9_p3_0 = {
  137717. _vq_quantthresh__44u9_p3_0,
  137718. _vq_quantmap__44u9_p3_0,
  137719. 9,
  137720. 9
  137721. };
  137722. static static_codebook _44u9_p3_0 = {
  137723. 2, 81,
  137724. _vq_lengthlist__44u9_p3_0,
  137725. 1, -531628032, 1611661312, 4, 0,
  137726. _vq_quantlist__44u9_p3_0,
  137727. NULL,
  137728. &_vq_auxt__44u9_p3_0,
  137729. NULL,
  137730. 0
  137731. };
  137732. static long _vq_quantlist__44u9_p4_0[] = {
  137733. 8,
  137734. 7,
  137735. 9,
  137736. 6,
  137737. 10,
  137738. 5,
  137739. 11,
  137740. 4,
  137741. 12,
  137742. 3,
  137743. 13,
  137744. 2,
  137745. 14,
  137746. 1,
  137747. 15,
  137748. 0,
  137749. 16,
  137750. };
  137751. static long _vq_lengthlist__44u9_p4_0[] = {
  137752. 4, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,11,
  137753. 11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,
  137754. 11,11, 5, 5, 5, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,
  137755. 10,11,11, 6, 6, 6, 7, 6, 7, 7, 8, 8, 9, 9,10,10,
  137756. 11,11,12,11, 6, 6, 6, 6, 7, 7, 7, 8, 8, 9, 9,10,
  137757. 10,11,11,11,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9,
  137758. 10,10,11,11,12,12, 7, 7, 7, 7, 7, 8, 8, 9, 9, 9,
  137759. 9,10,10,11,11,12,12, 8, 8, 8, 8, 8, 9, 8,10, 9,
  137760. 10,10,11,10,12,11,13,12, 8, 8, 8, 8, 8, 9, 9, 9,
  137761. 10,10,10,10,11,11,12,12,12, 8, 8, 8, 9, 9, 9, 9,
  137762. 10,10,11,10,12,11,12,12,13,12, 8, 8, 8, 9, 9, 9,
  137763. 9,10,10,10,11,11,11,12,12,12,13, 9, 9, 9,10,10,
  137764. 10,10,11,10,11,11,12,11,13,12,13,13, 9, 9,10,10,
  137765. 10,10,10,10,11,11,11,11,12,12,13,13,13,10,11,10,
  137766. 11,11,11,11,12,11,12,12,13,12,13,13,14,13,10,10,
  137767. 10,11,11,11,11,11,12,12,12,12,13,13,13,13,14,11,
  137768. 11,11,12,11,12,12,12,12,13,13,13,13,14,13,14,14,
  137769. 11,11,11,11,12,12,12,12,12,12,13,13,13,13,14,14,
  137770. 14,
  137771. };
  137772. static float _vq_quantthresh__44u9_p4_0[] = {
  137773. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  137774. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  137775. };
  137776. static long _vq_quantmap__44u9_p4_0[] = {
  137777. 15, 13, 11, 9, 7, 5, 3, 1,
  137778. 0, 2, 4, 6, 8, 10, 12, 14,
  137779. 16,
  137780. };
  137781. static encode_aux_threshmatch _vq_auxt__44u9_p4_0 = {
  137782. _vq_quantthresh__44u9_p4_0,
  137783. _vq_quantmap__44u9_p4_0,
  137784. 17,
  137785. 17
  137786. };
  137787. static static_codebook _44u9_p4_0 = {
  137788. 2, 289,
  137789. _vq_lengthlist__44u9_p4_0,
  137790. 1, -529530880, 1611661312, 5, 0,
  137791. _vq_quantlist__44u9_p4_0,
  137792. NULL,
  137793. &_vq_auxt__44u9_p4_0,
  137794. NULL,
  137795. 0
  137796. };
  137797. static long _vq_quantlist__44u9_p5_0[] = {
  137798. 1,
  137799. 0,
  137800. 2,
  137801. };
  137802. static long _vq_lengthlist__44u9_p5_0[] = {
  137803. 1, 4, 4, 5, 7, 7, 5, 7, 7, 5, 8, 8, 8, 9, 9, 7,
  137804. 9, 9, 5, 8, 8, 7, 9, 9, 8, 9, 9, 5, 8, 8, 8,10,
  137805. 10, 8,10,10, 7,10,10, 9,10,12, 9,11,11, 7,10,10,
  137806. 9,11,10, 9,11,12, 5, 8, 8, 8,10,10, 8,10,10, 7,
  137807. 10,10, 9,12,11, 9,10,11, 7,10,10, 9,11,11,10,12,
  137808. 10,
  137809. };
  137810. static float _vq_quantthresh__44u9_p5_0[] = {
  137811. -5.5, 5.5,
  137812. };
  137813. static long _vq_quantmap__44u9_p5_0[] = {
  137814. 1, 0, 2,
  137815. };
  137816. static encode_aux_threshmatch _vq_auxt__44u9_p5_0 = {
  137817. _vq_quantthresh__44u9_p5_0,
  137818. _vq_quantmap__44u9_p5_0,
  137819. 3,
  137820. 3
  137821. };
  137822. static static_codebook _44u9_p5_0 = {
  137823. 4, 81,
  137824. _vq_lengthlist__44u9_p5_0,
  137825. 1, -529137664, 1618345984, 2, 0,
  137826. _vq_quantlist__44u9_p5_0,
  137827. NULL,
  137828. &_vq_auxt__44u9_p5_0,
  137829. NULL,
  137830. 0
  137831. };
  137832. static long _vq_quantlist__44u9_p5_1[] = {
  137833. 5,
  137834. 4,
  137835. 6,
  137836. 3,
  137837. 7,
  137838. 2,
  137839. 8,
  137840. 1,
  137841. 9,
  137842. 0,
  137843. 10,
  137844. };
  137845. static long _vq_lengthlist__44u9_p5_1[] = {
  137846. 5, 5, 5, 6, 6, 7, 7, 7, 7, 7, 7, 5, 6, 6, 6, 6,
  137847. 7, 7, 7, 7, 8, 7, 5, 6, 6, 6, 6, 7, 7, 7, 7, 7,
  137848. 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 8, 8, 6, 6, 6, 7,
  137849. 7, 7, 7, 7, 7, 8, 8, 7, 7, 7, 7, 7, 8, 7, 8, 8,
  137850. 8, 8, 7, 7, 7, 7, 7, 7, 8, 8, 8, 8, 8, 7, 7, 7,
  137851. 8, 7, 8, 8, 8, 8, 8, 8, 7, 7, 7, 7, 8, 8, 8, 8,
  137852. 8, 8, 8, 7, 8, 7, 8, 8, 8, 8, 8, 8, 8, 8, 7, 8,
  137853. 8, 8, 8, 8, 8, 8, 8, 8, 8,
  137854. };
  137855. static float _vq_quantthresh__44u9_p5_1[] = {
  137856. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  137857. 3.5, 4.5,
  137858. };
  137859. static long _vq_quantmap__44u9_p5_1[] = {
  137860. 9, 7, 5, 3, 1, 0, 2, 4,
  137861. 6, 8, 10,
  137862. };
  137863. static encode_aux_threshmatch _vq_auxt__44u9_p5_1 = {
  137864. _vq_quantthresh__44u9_p5_1,
  137865. _vq_quantmap__44u9_p5_1,
  137866. 11,
  137867. 11
  137868. };
  137869. static static_codebook _44u9_p5_1 = {
  137870. 2, 121,
  137871. _vq_lengthlist__44u9_p5_1,
  137872. 1, -531365888, 1611661312, 4, 0,
  137873. _vq_quantlist__44u9_p5_1,
  137874. NULL,
  137875. &_vq_auxt__44u9_p5_1,
  137876. NULL,
  137877. 0
  137878. };
  137879. static long _vq_quantlist__44u9_p6_0[] = {
  137880. 6,
  137881. 5,
  137882. 7,
  137883. 4,
  137884. 8,
  137885. 3,
  137886. 9,
  137887. 2,
  137888. 10,
  137889. 1,
  137890. 11,
  137891. 0,
  137892. 12,
  137893. };
  137894. static long _vq_lengthlist__44u9_p6_0[] = {
  137895. 2, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9,10,10, 4, 6, 5,
  137896. 7, 7, 8, 8, 8, 8, 9, 9,10,10, 4, 5, 6, 7, 7, 8,
  137897. 8, 8, 8, 9, 9,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  137898. 10,10,10,10, 6, 7, 7, 8, 8, 8, 8, 9, 9,10,10,10,
  137899. 10, 7, 8, 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 7, 8,
  137900. 8, 8, 8, 9, 9, 9, 9,10,10,11,11, 8, 8, 8, 9, 9,
  137901. 9, 9, 9,10,10,10,11,11, 8, 8, 8, 9, 9, 9, 9,10,
  137902. 9,10,10,11,11, 9, 9, 9,10,10,10,10,10,11,11,11,
  137903. 11,12, 9, 9, 9,10,10,10,10,10,10,11,10,12,11,10,
  137904. 10,10,10,10,11,11,11,11,11,12,12,12,10,10,10,10,
  137905. 10,11,11,11,11,12,11,12,12,
  137906. };
  137907. static float _vq_quantthresh__44u9_p6_0[] = {
  137908. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  137909. 12.5, 17.5, 22.5, 27.5,
  137910. };
  137911. static long _vq_quantmap__44u9_p6_0[] = {
  137912. 11, 9, 7, 5, 3, 1, 0, 2,
  137913. 4, 6, 8, 10, 12,
  137914. };
  137915. static encode_aux_threshmatch _vq_auxt__44u9_p6_0 = {
  137916. _vq_quantthresh__44u9_p6_0,
  137917. _vq_quantmap__44u9_p6_0,
  137918. 13,
  137919. 13
  137920. };
  137921. static static_codebook _44u9_p6_0 = {
  137922. 2, 169,
  137923. _vq_lengthlist__44u9_p6_0,
  137924. 1, -526516224, 1616117760, 4, 0,
  137925. _vq_quantlist__44u9_p6_0,
  137926. NULL,
  137927. &_vq_auxt__44u9_p6_0,
  137928. NULL,
  137929. 0
  137930. };
  137931. static long _vq_quantlist__44u9_p6_1[] = {
  137932. 2,
  137933. 1,
  137934. 3,
  137935. 0,
  137936. 4,
  137937. };
  137938. static long _vq_lengthlist__44u9_p6_1[] = {
  137939. 4, 4, 4, 5, 5, 4, 5, 4, 5, 5, 4, 4, 5, 5, 5, 5,
  137940. 5, 5, 5, 5, 5, 5, 5, 5, 5,
  137941. };
  137942. static float _vq_quantthresh__44u9_p6_1[] = {
  137943. -1.5, -0.5, 0.5, 1.5,
  137944. };
  137945. static long _vq_quantmap__44u9_p6_1[] = {
  137946. 3, 1, 0, 2, 4,
  137947. };
  137948. static encode_aux_threshmatch _vq_auxt__44u9_p6_1 = {
  137949. _vq_quantthresh__44u9_p6_1,
  137950. _vq_quantmap__44u9_p6_1,
  137951. 5,
  137952. 5
  137953. };
  137954. static static_codebook _44u9_p6_1 = {
  137955. 2, 25,
  137956. _vq_lengthlist__44u9_p6_1,
  137957. 1, -533725184, 1611661312, 3, 0,
  137958. _vq_quantlist__44u9_p6_1,
  137959. NULL,
  137960. &_vq_auxt__44u9_p6_1,
  137961. NULL,
  137962. 0
  137963. };
  137964. static long _vq_quantlist__44u9_p7_0[] = {
  137965. 6,
  137966. 5,
  137967. 7,
  137968. 4,
  137969. 8,
  137970. 3,
  137971. 9,
  137972. 2,
  137973. 10,
  137974. 1,
  137975. 11,
  137976. 0,
  137977. 12,
  137978. };
  137979. static long _vq_lengthlist__44u9_p7_0[] = {
  137980. 1, 4, 5, 6, 6, 7, 7, 8, 9,10,10,11,11, 5, 6, 6,
  137981. 7, 7, 8, 8, 9, 9,10,10,11,11, 5, 6, 6, 7, 7, 8,
  137982. 8, 9, 9,10,10,11,11, 6, 7, 7, 8, 8, 9, 9,10,10,
  137983. 11,11,12,12, 6, 7, 7, 8, 8, 9, 9,10,10,11,11,12,
  137984. 12, 8, 8, 8, 9, 9,10,10,11,11,12,12,13,13, 8, 8,
  137985. 8, 9, 9,10,10,11,11,12,12,13,13, 9, 9, 9,10,10,
  137986. 11,11,12,12,13,13,13,13, 9, 9, 9,10,10,11,11,12,
  137987. 12,13,13,14,14,10,10,10,11,11,12,12,13,13,14,13,
  137988. 15,14,10,10,10,11,11,12,12,13,13,14,14,14,14,11,
  137989. 11,12,12,12,13,13,14,14,14,14,15,15,11,11,12,12,
  137990. 12,13,13,14,14,14,15,15,15,
  137991. };
  137992. static float _vq_quantthresh__44u9_p7_0[] = {
  137993. -60.5, -49.5, -38.5, -27.5, -16.5, -5.5, 5.5, 16.5,
  137994. 27.5, 38.5, 49.5, 60.5,
  137995. };
  137996. static long _vq_quantmap__44u9_p7_0[] = {
  137997. 11, 9, 7, 5, 3, 1, 0, 2,
  137998. 4, 6, 8, 10, 12,
  137999. };
  138000. static encode_aux_threshmatch _vq_auxt__44u9_p7_0 = {
  138001. _vq_quantthresh__44u9_p7_0,
  138002. _vq_quantmap__44u9_p7_0,
  138003. 13,
  138004. 13
  138005. };
  138006. static static_codebook _44u9_p7_0 = {
  138007. 2, 169,
  138008. _vq_lengthlist__44u9_p7_0,
  138009. 1, -523206656, 1618345984, 4, 0,
  138010. _vq_quantlist__44u9_p7_0,
  138011. NULL,
  138012. &_vq_auxt__44u9_p7_0,
  138013. NULL,
  138014. 0
  138015. };
  138016. static long _vq_quantlist__44u9_p7_1[] = {
  138017. 5,
  138018. 4,
  138019. 6,
  138020. 3,
  138021. 7,
  138022. 2,
  138023. 8,
  138024. 1,
  138025. 9,
  138026. 0,
  138027. 10,
  138028. };
  138029. static long _vq_lengthlist__44u9_p7_1[] = {
  138030. 5, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7,
  138031. 7, 7, 7, 7, 7, 7, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7,
  138032. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 6, 7, 7, 7,
  138033. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138034. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138035. 7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138036. 7, 8, 8, 7, 7, 7, 7, 7, 7, 7, 8, 7, 8, 8, 7, 7,
  138037. 7, 7, 7, 7, 7, 8, 8, 8, 8,
  138038. };
  138039. static float _vq_quantthresh__44u9_p7_1[] = {
  138040. -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5,
  138041. 3.5, 4.5,
  138042. };
  138043. static long _vq_quantmap__44u9_p7_1[] = {
  138044. 9, 7, 5, 3, 1, 0, 2, 4,
  138045. 6, 8, 10,
  138046. };
  138047. static encode_aux_threshmatch _vq_auxt__44u9_p7_1 = {
  138048. _vq_quantthresh__44u9_p7_1,
  138049. _vq_quantmap__44u9_p7_1,
  138050. 11,
  138051. 11
  138052. };
  138053. static static_codebook _44u9_p7_1 = {
  138054. 2, 121,
  138055. _vq_lengthlist__44u9_p7_1,
  138056. 1, -531365888, 1611661312, 4, 0,
  138057. _vq_quantlist__44u9_p7_1,
  138058. NULL,
  138059. &_vq_auxt__44u9_p7_1,
  138060. NULL,
  138061. 0
  138062. };
  138063. static long _vq_quantlist__44u9_p8_0[] = {
  138064. 7,
  138065. 6,
  138066. 8,
  138067. 5,
  138068. 9,
  138069. 4,
  138070. 10,
  138071. 3,
  138072. 11,
  138073. 2,
  138074. 12,
  138075. 1,
  138076. 13,
  138077. 0,
  138078. 14,
  138079. };
  138080. static long _vq_lengthlist__44u9_p8_0[] = {
  138081. 1, 4, 4, 7, 7, 8, 8, 8, 8, 9, 9,10, 9,11,10, 4,
  138082. 6, 6, 8, 8, 9, 9, 9, 9,10,10,11,10,12,10, 4, 6,
  138083. 6, 8, 8, 9,10, 9, 9,10,10,11,11,12,12, 7, 8, 8,
  138084. 10,10,11,11,10,10,11,11,12,12,13,12, 7, 8, 8,10,
  138085. 10,11,11,10,10,11,11,12,12,12,13, 8,10, 9,11,11,
  138086. 12,12,11,11,12,12,13,13,14,13, 8, 9, 9,11,11,12,
  138087. 12,11,12,12,12,13,13,14,13, 8, 9, 9,10,10,12,11,
  138088. 13,12,13,13,14,13,15,14, 8, 9, 9,10,10,11,12,12,
  138089. 12,13,13,13,14,14,14, 9,10,10,12,11,13,12,13,13,
  138090. 14,13,14,14,14,15, 9,10,10,11,12,12,12,13,13,14,
  138091. 14,14,15,15,15,10,11,11,12,12,13,13,14,14,14,14,
  138092. 15,14,16,15,10,11,11,12,12,13,13,13,14,14,14,14,
  138093. 14,15,16,11,12,12,13,13,14,13,14,14,15,14,15,16,
  138094. 16,16,11,12,12,13,13,14,13,14,14,15,15,15,16,15,
  138095. 15,
  138096. };
  138097. static float _vq_quantthresh__44u9_p8_0[] = {
  138098. -136.5, -115.5, -94.5, -73.5, -52.5, -31.5, -10.5, 10.5,
  138099. 31.5, 52.5, 73.5, 94.5, 115.5, 136.5,
  138100. };
  138101. static long _vq_quantmap__44u9_p8_0[] = {
  138102. 13, 11, 9, 7, 5, 3, 1, 0,
  138103. 2, 4, 6, 8, 10, 12, 14,
  138104. };
  138105. static encode_aux_threshmatch _vq_auxt__44u9_p8_0 = {
  138106. _vq_quantthresh__44u9_p8_0,
  138107. _vq_quantmap__44u9_p8_0,
  138108. 15,
  138109. 15
  138110. };
  138111. static static_codebook _44u9_p8_0 = {
  138112. 2, 225,
  138113. _vq_lengthlist__44u9_p8_0,
  138114. 1, -520986624, 1620377600, 4, 0,
  138115. _vq_quantlist__44u9_p8_0,
  138116. NULL,
  138117. &_vq_auxt__44u9_p8_0,
  138118. NULL,
  138119. 0
  138120. };
  138121. static long _vq_quantlist__44u9_p8_1[] = {
  138122. 10,
  138123. 9,
  138124. 11,
  138125. 8,
  138126. 12,
  138127. 7,
  138128. 13,
  138129. 6,
  138130. 14,
  138131. 5,
  138132. 15,
  138133. 4,
  138134. 16,
  138135. 3,
  138136. 17,
  138137. 2,
  138138. 18,
  138139. 1,
  138140. 19,
  138141. 0,
  138142. 20,
  138143. };
  138144. static long _vq_lengthlist__44u9_p8_1[] = {
  138145. 4, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9,
  138146. 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8, 8, 8, 8, 9, 9,
  138147. 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 6, 6, 6, 7, 7, 8,
  138148. 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 7,
  138149. 7, 7, 8, 8, 8, 8, 9, 8, 9, 9, 9, 9, 9, 9, 9, 9,
  138150. 9, 9, 9, 9, 7, 7, 7, 8, 8, 8, 8, 9, 9, 9, 9, 9,
  138151. 9, 9, 9, 9, 9, 9, 9, 9, 9, 8, 8, 8, 8, 8, 9, 9,
  138152. 9, 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10, 8, 8,
  138153. 8, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138154. 9,10,10, 8, 8, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138155. 10, 9,10, 9,10,10,10,10, 8, 8, 8, 9, 9, 9, 9, 9,
  138156. 9, 9, 9, 9, 9,10,10, 9,10,10,10,10,10, 9, 9, 9,
  138157. 9, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  138158. 10,10, 8, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9,10,10,10,
  138159. 10,10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9, 9,
  138160. 9, 9,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9,
  138161. 9, 9, 9, 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  138162. 10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10,10,10,
  138163. 10,10,10,10,10,10, 9, 9, 9, 9, 9, 9, 9, 9,10,10,
  138164. 10,10,10,10,10,10,10,10,10,10,10, 9, 9, 9, 9, 9,
  138165. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138166. 9, 9, 9, 9,10, 9, 9,10,10,10,10,10,10,10,10,10,
  138167. 10,10,10,10,10, 9, 9, 9,10, 9,10, 9,10,10,10,10,
  138168. 10,10,10,10,10,10,10,10,10,10, 9, 9, 9,10, 9,10,
  138169. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10, 9,
  138170. 9, 9, 9, 9,10,10,10,10,10,10,10,10,10,10,10,10,
  138171. 10,10,10,10, 9, 9, 9,10,10,10,10,10,10,10,10,10,
  138172. 10,10,10,10,10,10,10,10,10,
  138173. };
  138174. static float _vq_quantthresh__44u9_p8_1[] = {
  138175. -9.5, -8.5, -7.5, -6.5, -5.5, -4.5, -3.5, -2.5,
  138176. -1.5, -0.5, 0.5, 1.5, 2.5, 3.5, 4.5, 5.5,
  138177. 6.5, 7.5, 8.5, 9.5,
  138178. };
  138179. static long _vq_quantmap__44u9_p8_1[] = {
  138180. 19, 17, 15, 13, 11, 9, 7, 5,
  138181. 3, 1, 0, 2, 4, 6, 8, 10,
  138182. 12, 14, 16, 18, 20,
  138183. };
  138184. static encode_aux_threshmatch _vq_auxt__44u9_p8_1 = {
  138185. _vq_quantthresh__44u9_p8_1,
  138186. _vq_quantmap__44u9_p8_1,
  138187. 21,
  138188. 21
  138189. };
  138190. static static_codebook _44u9_p8_1 = {
  138191. 2, 441,
  138192. _vq_lengthlist__44u9_p8_1,
  138193. 1, -529268736, 1611661312, 5, 0,
  138194. _vq_quantlist__44u9_p8_1,
  138195. NULL,
  138196. &_vq_auxt__44u9_p8_1,
  138197. NULL,
  138198. 0
  138199. };
  138200. static long _vq_quantlist__44u9_p9_0[] = {
  138201. 7,
  138202. 6,
  138203. 8,
  138204. 5,
  138205. 9,
  138206. 4,
  138207. 10,
  138208. 3,
  138209. 11,
  138210. 2,
  138211. 12,
  138212. 1,
  138213. 13,
  138214. 0,
  138215. 14,
  138216. };
  138217. static long _vq_lengthlist__44u9_p9_0[] = {
  138218. 1, 3, 3,11,11,11,11,11,11,11,11,11,11,11,11, 4,
  138219. 10,11,11,11,11,11,11,11,11,11,11,11,11,11, 4,10,
  138220. 10,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138221. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138222. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138223. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138224. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138225. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138226. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138227. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138228. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138229. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138230. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138231. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138232. 10,
  138233. };
  138234. static float _vq_quantthresh__44u9_p9_0[] = {
  138235. -6051.5, -5120.5, -4189.5, -3258.5, -2327.5, -1396.5, -465.5, 465.5,
  138236. 1396.5, 2327.5, 3258.5, 4189.5, 5120.5, 6051.5,
  138237. };
  138238. static long _vq_quantmap__44u9_p9_0[] = {
  138239. 13, 11, 9, 7, 5, 3, 1, 0,
  138240. 2, 4, 6, 8, 10, 12, 14,
  138241. };
  138242. static encode_aux_threshmatch _vq_auxt__44u9_p9_0 = {
  138243. _vq_quantthresh__44u9_p9_0,
  138244. _vq_quantmap__44u9_p9_0,
  138245. 15,
  138246. 15
  138247. };
  138248. static static_codebook _44u9_p9_0 = {
  138249. 2, 225,
  138250. _vq_lengthlist__44u9_p9_0,
  138251. 1, -510036736, 1631393792, 4, 0,
  138252. _vq_quantlist__44u9_p9_0,
  138253. NULL,
  138254. &_vq_auxt__44u9_p9_0,
  138255. NULL,
  138256. 0
  138257. };
  138258. static long _vq_quantlist__44u9_p9_1[] = {
  138259. 9,
  138260. 8,
  138261. 10,
  138262. 7,
  138263. 11,
  138264. 6,
  138265. 12,
  138266. 5,
  138267. 13,
  138268. 4,
  138269. 14,
  138270. 3,
  138271. 15,
  138272. 2,
  138273. 16,
  138274. 1,
  138275. 17,
  138276. 0,
  138277. 18,
  138278. };
  138279. static long _vq_lengthlist__44u9_p9_1[] = {
  138280. 1, 4, 4, 7, 7, 8, 7, 8, 7, 9, 8,10, 9,10,10,11,
  138281. 11,12,12, 4, 7, 6, 9, 9,10, 9, 9, 8,10,10,11,10,
  138282. 12,10,13,12,13,12, 4, 6, 6, 9, 9, 9, 9, 9, 9,10,
  138283. 10,11,11,11,12,12,12,12,12, 7, 9, 8,11,10,10,10,
  138284. 11,10,11,11,12,12,13,12,13,13,13,13, 7, 8, 9,10,
  138285. 10,11,11,10,10,11,11,11,12,13,13,13,13,14,14, 8,
  138286. 9, 9,11,11,12,11,12,12,13,12,12,13,13,14,15,14,
  138287. 14,14, 8, 9, 9,10,11,11,11,12,12,13,12,13,13,14,
  138288. 14,14,15,14,16, 8, 9, 9,11,10,12,12,12,12,15,13,
  138289. 13,13,17,14,15,15,15,14, 8, 9, 9,10,11,11,12,13,
  138290. 12,13,13,13,14,15,14,14,14,16,15, 9,11,10,12,12,
  138291. 13,13,13,13,14,14,16,15,14,14,14,15,15,17, 9,10,
  138292. 10,11,11,13,13,13,14,14,13,15,14,15,14,15,16,15,
  138293. 16,10,11,11,12,12,13,14,15,14,15,14,14,15,17,16,
  138294. 15,15,17,17,10,12,11,13,12,14,14,13,14,15,15,15,
  138295. 15,16,17,17,15,17,16,11,12,12,14,13,15,14,15,16,
  138296. 17,15,17,15,17,15,15,16,17,15,11,11,12,14,14,14,
  138297. 14,14,15,15,16,15,17,17,17,16,17,16,15,12,12,13,
  138298. 14,14,14,15,14,15,15,16,16,17,16,17,15,17,17,16,
  138299. 12,14,12,14,14,15,15,15,14,14,16,16,16,15,16,16,
  138300. 15,17,15,12,13,13,14,15,14,15,17,15,17,16,17,17,
  138301. 17,16,17,16,17,17,12,13,13,14,16,15,15,15,16,15,
  138302. 17,17,15,17,15,17,16,16,17,
  138303. };
  138304. static float _vq_quantthresh__44u9_p9_1[] = {
  138305. -416.5, -367.5, -318.5, -269.5, -220.5, -171.5, -122.5, -73.5,
  138306. -24.5, 24.5, 73.5, 122.5, 171.5, 220.5, 269.5, 318.5,
  138307. 367.5, 416.5,
  138308. };
  138309. static long _vq_quantmap__44u9_p9_1[] = {
  138310. 17, 15, 13, 11, 9, 7, 5, 3,
  138311. 1, 0, 2, 4, 6, 8, 10, 12,
  138312. 14, 16, 18,
  138313. };
  138314. static encode_aux_threshmatch _vq_auxt__44u9_p9_1 = {
  138315. _vq_quantthresh__44u9_p9_1,
  138316. _vq_quantmap__44u9_p9_1,
  138317. 19,
  138318. 19
  138319. };
  138320. static static_codebook _44u9_p9_1 = {
  138321. 2, 361,
  138322. _vq_lengthlist__44u9_p9_1,
  138323. 1, -518287360, 1622704128, 5, 0,
  138324. _vq_quantlist__44u9_p9_1,
  138325. NULL,
  138326. &_vq_auxt__44u9_p9_1,
  138327. NULL,
  138328. 0
  138329. };
  138330. static long _vq_quantlist__44u9_p9_2[] = {
  138331. 24,
  138332. 23,
  138333. 25,
  138334. 22,
  138335. 26,
  138336. 21,
  138337. 27,
  138338. 20,
  138339. 28,
  138340. 19,
  138341. 29,
  138342. 18,
  138343. 30,
  138344. 17,
  138345. 31,
  138346. 16,
  138347. 32,
  138348. 15,
  138349. 33,
  138350. 14,
  138351. 34,
  138352. 13,
  138353. 35,
  138354. 12,
  138355. 36,
  138356. 11,
  138357. 37,
  138358. 10,
  138359. 38,
  138360. 9,
  138361. 39,
  138362. 8,
  138363. 40,
  138364. 7,
  138365. 41,
  138366. 6,
  138367. 42,
  138368. 5,
  138369. 43,
  138370. 4,
  138371. 44,
  138372. 3,
  138373. 45,
  138374. 2,
  138375. 46,
  138376. 1,
  138377. 47,
  138378. 0,
  138379. 48,
  138380. };
  138381. static long _vq_lengthlist__44u9_p9_2[] = {
  138382. 2, 4, 4, 5, 4, 5, 5, 5, 5, 6, 6, 6, 6, 6, 6, 6,
  138383. 6, 6, 6, 7, 6, 7, 6, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138384. 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7,
  138385. 7,
  138386. };
  138387. static float _vq_quantthresh__44u9_p9_2[] = {
  138388. -23.5, -22.5, -21.5, -20.5, -19.5, -18.5, -17.5, -16.5,
  138389. -15.5, -14.5, -13.5, -12.5, -11.5, -10.5, -9.5, -8.5,
  138390. -7.5, -6.5, -5.5, -4.5, -3.5, -2.5, -1.5, -0.5,
  138391. 0.5, 1.5, 2.5, 3.5, 4.5, 5.5, 6.5, 7.5,
  138392. 8.5, 9.5, 10.5, 11.5, 12.5, 13.5, 14.5, 15.5,
  138393. 16.5, 17.5, 18.5, 19.5, 20.5, 21.5, 22.5, 23.5,
  138394. };
  138395. static long _vq_quantmap__44u9_p9_2[] = {
  138396. 47, 45, 43, 41, 39, 37, 35, 33,
  138397. 31, 29, 27, 25, 23, 21, 19, 17,
  138398. 15, 13, 11, 9, 7, 5, 3, 1,
  138399. 0, 2, 4, 6, 8, 10, 12, 14,
  138400. 16, 18, 20, 22, 24, 26, 28, 30,
  138401. 32, 34, 36, 38, 40, 42, 44, 46,
  138402. 48,
  138403. };
  138404. static encode_aux_threshmatch _vq_auxt__44u9_p9_2 = {
  138405. _vq_quantthresh__44u9_p9_2,
  138406. _vq_quantmap__44u9_p9_2,
  138407. 49,
  138408. 49
  138409. };
  138410. static static_codebook _44u9_p9_2 = {
  138411. 1, 49,
  138412. _vq_lengthlist__44u9_p9_2,
  138413. 1, -526909440, 1611661312, 6, 0,
  138414. _vq_quantlist__44u9_p9_2,
  138415. NULL,
  138416. &_vq_auxt__44u9_p9_2,
  138417. NULL,
  138418. 0
  138419. };
  138420. static long _huff_lengthlist__44un1__long[] = {
  138421. 5, 6,12, 9,14, 9, 9,19, 6, 1, 5, 5, 8, 7, 9,19,
  138422. 12, 4, 4, 7, 7, 9,11,18, 9, 5, 6, 6, 8, 7, 8,17,
  138423. 14, 8, 7, 8, 8,10,12,18, 9, 6, 8, 6, 8, 6, 8,18,
  138424. 9, 8,11, 8,11, 7, 5,15,16,18,18,18,17,15,11,18,
  138425. };
  138426. static static_codebook _huff_book__44un1__long = {
  138427. 2, 64,
  138428. _huff_lengthlist__44un1__long,
  138429. 0, 0, 0, 0, 0,
  138430. NULL,
  138431. NULL,
  138432. NULL,
  138433. NULL,
  138434. 0
  138435. };
  138436. static long _vq_quantlist__44un1__p1_0[] = {
  138437. 1,
  138438. 0,
  138439. 2,
  138440. };
  138441. static long _vq_lengthlist__44un1__p1_0[] = {
  138442. 1, 4, 4, 5, 8, 7, 5, 7, 8, 5, 8, 8, 8,10,11, 8,
  138443. 10,11, 5, 8, 8, 8,11,10, 8,11,10, 4, 9, 9, 8,11,
  138444. 11, 8,11,11, 8,12,11,10,12,14,11,13,13, 7,11,11,
  138445. 10,13,11,11,13,14, 4, 8, 9, 8,11,11, 8,11,12, 7,
  138446. 11,11,11,14,13,10,11,13, 8,11,12,11,13,13,10,14,
  138447. 12,
  138448. };
  138449. static float _vq_quantthresh__44un1__p1_0[] = {
  138450. -0.5, 0.5,
  138451. };
  138452. static long _vq_quantmap__44un1__p1_0[] = {
  138453. 1, 0, 2,
  138454. };
  138455. static encode_aux_threshmatch _vq_auxt__44un1__p1_0 = {
  138456. _vq_quantthresh__44un1__p1_0,
  138457. _vq_quantmap__44un1__p1_0,
  138458. 3,
  138459. 3
  138460. };
  138461. static static_codebook _44un1__p1_0 = {
  138462. 4, 81,
  138463. _vq_lengthlist__44un1__p1_0,
  138464. 1, -535822336, 1611661312, 2, 0,
  138465. _vq_quantlist__44un1__p1_0,
  138466. NULL,
  138467. &_vq_auxt__44un1__p1_0,
  138468. NULL,
  138469. 0
  138470. };
  138471. static long _vq_quantlist__44un1__p2_0[] = {
  138472. 1,
  138473. 0,
  138474. 2,
  138475. };
  138476. static long _vq_lengthlist__44un1__p2_0[] = {
  138477. 2, 4, 4, 5, 6, 6, 5, 6, 6, 5, 7, 7, 7, 8, 8, 6,
  138478. 7, 9, 5, 7, 7, 6, 8, 7, 7, 9, 8, 4, 7, 7, 7, 9,
  138479. 8, 7, 8, 8, 7, 9, 8, 8, 8,10, 9,10,10, 6, 8, 8,
  138480. 7,10, 8, 9,10,10, 5, 7, 7, 7, 8, 8, 7, 8, 9, 6,
  138481. 8, 8, 9,10,10, 7, 8,10, 6, 8, 9, 9,10,10, 8,10,
  138482. 8,
  138483. };
  138484. static float _vq_quantthresh__44un1__p2_0[] = {
  138485. -0.5, 0.5,
  138486. };
  138487. static long _vq_quantmap__44un1__p2_0[] = {
  138488. 1, 0, 2,
  138489. };
  138490. static encode_aux_threshmatch _vq_auxt__44un1__p2_0 = {
  138491. _vq_quantthresh__44un1__p2_0,
  138492. _vq_quantmap__44un1__p2_0,
  138493. 3,
  138494. 3
  138495. };
  138496. static static_codebook _44un1__p2_0 = {
  138497. 4, 81,
  138498. _vq_lengthlist__44un1__p2_0,
  138499. 1, -535822336, 1611661312, 2, 0,
  138500. _vq_quantlist__44un1__p2_0,
  138501. NULL,
  138502. &_vq_auxt__44un1__p2_0,
  138503. NULL,
  138504. 0
  138505. };
  138506. static long _vq_quantlist__44un1__p3_0[] = {
  138507. 2,
  138508. 1,
  138509. 3,
  138510. 0,
  138511. 4,
  138512. };
  138513. static long _vq_lengthlist__44un1__p3_0[] = {
  138514. 1, 5, 5, 8, 8, 5, 8, 7, 9, 9, 5, 7, 8, 9, 9, 9,
  138515. 10, 9,12,12, 9, 9,10,11,12, 6, 8, 8,10,10, 8,10,
  138516. 10,11,11, 8, 9,10,11,11,10,11,11,13,13,10,11,11,
  138517. 12,13, 6, 8, 8,10,10, 8,10, 9,11,11, 8,10,10,11,
  138518. 11,10,11,11,13,12,10,11,11,13,12, 9,11,11,15,13,
  138519. 10,12,11,15,13,10,11,11,15,14,12,14,13,16,15,12,
  138520. 13,13,17,16, 9,11,11,13,15,10,11,12,14,15,10,11,
  138521. 12,14,15,12,13,13,15,16,12,13,13,16,16, 5, 8, 8,
  138522. 11,11, 8,10,10,12,12, 8,10,10,12,12,11,12,12,14,
  138523. 14,11,12,12,14,14, 8,11,10,13,12,10,11,12,12,13,
  138524. 10,12,12,13,13,12,12,13,13,15,11,12,13,15,14, 7,
  138525. 10,10,12,12, 9,12,11,13,12,10,12,12,13,14,12,13,
  138526. 12,15,13,11,13,12,14,15,10,12,12,16,14,11,12,12,
  138527. 16,15,11,13,12,17,16,13,13,15,15,17,13,15,15,20,
  138528. 17,10,12,12,14,16,11,12,12,15,15,11,13,13,15,18,
  138529. 13,14,13,15,15,13,15,14,16,16, 5, 8, 8,11,11, 8,
  138530. 10,10,12,12, 8,10,10,12,12,11,12,12,14,14,11,12,
  138531. 12,14,15, 7,10,10,13,12,10,12,12,14,13, 9,10,12,
  138532. 12,13,11,13,13,15,15,11,12,13,13,15, 8,10,10,12,
  138533. 13,10,12,12,13,13,10,12,11,13,13,11,13,12,15,15,
  138534. 12,13,12,15,13,10,12,12,16,14,11,12,12,16,15,10,
  138535. 12,12,16,14,14,15,14,18,16,13,13,14,15,16,10,12,
  138536. 12,14,16,11,13,13,16,16,11,13,12,14,16,13,15,15,
  138537. 18,18,13,15,13,16,14, 8,11,11,16,16,10,13,13,17,
  138538. 16,10,12,12,16,15,14,16,15,20,17,13,14,14,17,17,
  138539. 9,12,12,16,16,11,13,14,16,17,11,13,13,16,16,15,
  138540. 15,19,18, 0,14,15,15,18,18, 9,12,12,17,16,11,13,
  138541. 12,17,16,11,12,13,15,17,15,16,15, 0,19,14,15,14,
  138542. 19,18,12,14,14, 0,16,13,14,14,19,18,13,15,16,17,
  138543. 16,15,15,17,18, 0,14,16,16,19, 0,12,14,14,16,18,
  138544. 13,15,13,17,18,13,15,14,17,18,15,18,14,18,18,16,
  138545. 17,16, 0,17, 8,11,11,15,15,10,12,12,16,16,10,13,
  138546. 13,16,16,13,15,14,17,17,14,15,17,17,18, 9,12,12,
  138547. 16,15,11,13,13,16,16,11,12,13,17,17,14,14,15,17,
  138548. 17,14,15,16, 0,18, 9,12,12,16,17,11,13,13,16,17,
  138549. 11,14,13,18,17,14,16,14,17,17,15,17,17,18,18,12,
  138550. 14,14, 0,16,13,15,15,19, 0,12,13,15, 0, 0,14,17,
  138551. 16,19, 0,16,15,18,18, 0,12,14,14,17, 0,13,14,14,
  138552. 17, 0,13,15,14, 0,18,15,16,16, 0,18,15,18,15, 0,
  138553. 17,
  138554. };
  138555. static float _vq_quantthresh__44un1__p3_0[] = {
  138556. -1.5, -0.5, 0.5, 1.5,
  138557. };
  138558. static long _vq_quantmap__44un1__p3_0[] = {
  138559. 3, 1, 0, 2, 4,
  138560. };
  138561. static encode_aux_threshmatch _vq_auxt__44un1__p3_0 = {
  138562. _vq_quantthresh__44un1__p3_0,
  138563. _vq_quantmap__44un1__p3_0,
  138564. 5,
  138565. 5
  138566. };
  138567. static static_codebook _44un1__p3_0 = {
  138568. 4, 625,
  138569. _vq_lengthlist__44un1__p3_0,
  138570. 1, -533725184, 1611661312, 3, 0,
  138571. _vq_quantlist__44un1__p3_0,
  138572. NULL,
  138573. &_vq_auxt__44un1__p3_0,
  138574. NULL,
  138575. 0
  138576. };
  138577. static long _vq_quantlist__44un1__p4_0[] = {
  138578. 2,
  138579. 1,
  138580. 3,
  138581. 0,
  138582. 4,
  138583. };
  138584. static long _vq_lengthlist__44un1__p4_0[] = {
  138585. 3, 5, 5, 9, 9, 5, 6, 6,10, 9, 5, 6, 6, 9,10,10,
  138586. 10,10,12,11, 9,10,10,12,12, 5, 7, 7,10,10, 7, 7,
  138587. 8,10,11, 7, 7, 8,10,11,10,10,11,11,13,10,10,11,
  138588. 11,13, 6, 7, 7,10,10, 7, 8, 7,11,10, 7, 8, 7,10,
  138589. 10,10,11, 9,13,11,10,11,10,13,11,10,10,10,14,13,
  138590. 10,11,11,14,13,10,10,11,13,14,12,12,13,15,15,12,
  138591. 12,13,13,14,10,10,10,12,13,10,11,10,13,13,10,11,
  138592. 11,13,13,12,13,12,14,13,12,13,13,14,13, 5, 7, 7,
  138593. 10,10, 7, 8, 8,11,10, 7, 8, 8,10,10,11,11,11,13,
  138594. 13,10,11,11,12,12, 7, 8, 8,11,11, 7, 8, 9,10,12,
  138595. 8, 9, 9,11,11,11,10,12,11,14,11,11,12,13,13, 6,
  138596. 8, 8,10,11, 7, 9, 7,12,10, 8, 9,10,11,12,10,12,
  138597. 10,14,11,11,12,11,13,13,10,11,11,14,14,10,10,11,
  138598. 13,14,11,12,12,15,13,12,11,14,12,16,12,13,14,15,
  138599. 16,10,10,11,13,14,10,11,10,14,12,11,12,12,13,14,
  138600. 12,13,11,15,12,14,14,14,15,15, 5, 7, 7,10,10, 7,
  138601. 8, 8,10,10, 7, 8, 8,10,11,10,11,10,12,12,10,11,
  138602. 11,12,13, 6, 8, 8,11,11, 8, 9, 9,12,11, 7, 7, 9,
  138603. 10,12,11,11,11,12,13,11,10,12,11,15, 7, 8, 8,11,
  138604. 11, 8, 9, 9,11,11, 7, 9, 8,12,10,11,12,11,13,12,
  138605. 11,12,10,15,11,10,11,10,14,12,11,12,11,14,13,10,
  138606. 10,11,13,14,13,13,13,17,15,12,11,14,12,15,10,10,
  138607. 11,13,14,11,12,12,14,14,10,11,10,14,13,13,14,13,
  138608. 16,17,12,14,11,16,12, 9,10,10,14,13,10,11,10,14,
  138609. 14,10,11,11,13,13,13,14,14,16,15,12,13,13,14,14,
  138610. 9,11,10,14,13,10,10,12,13,14,11,12,11,14,13,13,
  138611. 14,14,14,15,13,14,14,15,15, 9,10,11,13,14,10,11,
  138612. 10,15,13,11,11,12,12,15,13,14,12,15,14,13,13,14,
  138613. 14,15,12,13,12,16,14,11,11,12,15,14,13,15,13,16,
  138614. 14,13,12,15,12,17,15,16,15,16,16,12,12,13,13,15,
  138615. 11,13,11,15,14,13,13,14,15,17,13,14,12, 0,13,14,
  138616. 15,14,15, 0, 9,10,10,13,13,10,11,11,13,13,10,11,
  138617. 11,13,13,12,13,12,14,14,13,14,14,15,17, 9,10,10,
  138618. 13,13,11,12,11,15,12,10,10,11,13,16,13,14,13,15,
  138619. 14,13,13,14,15,16,10,10,11,13,14,11,11,12,13,14,
  138620. 10,12,11,14,14,13,13,13,14,15,13,15,13,16,15,12,
  138621. 13,12,15,13,12,15,13,15,15,11,11,13,14,15,15,15,
  138622. 15,15,17,13,12,14,13,17,12,12,14,14,15,13,13,14,
  138623. 14,16,11,13,11,16,15,14,16,16,17, 0,14,13,11,16,
  138624. 12,
  138625. };
  138626. static float _vq_quantthresh__44un1__p4_0[] = {
  138627. -1.5, -0.5, 0.5, 1.5,
  138628. };
  138629. static long _vq_quantmap__44un1__p4_0[] = {
  138630. 3, 1, 0, 2, 4,
  138631. };
  138632. static encode_aux_threshmatch _vq_auxt__44un1__p4_0 = {
  138633. _vq_quantthresh__44un1__p4_0,
  138634. _vq_quantmap__44un1__p4_0,
  138635. 5,
  138636. 5
  138637. };
  138638. static static_codebook _44un1__p4_0 = {
  138639. 4, 625,
  138640. _vq_lengthlist__44un1__p4_0,
  138641. 1, -533725184, 1611661312, 3, 0,
  138642. _vq_quantlist__44un1__p4_0,
  138643. NULL,
  138644. &_vq_auxt__44un1__p4_0,
  138645. NULL,
  138646. 0
  138647. };
  138648. static long _vq_quantlist__44un1__p5_0[] = {
  138649. 4,
  138650. 3,
  138651. 5,
  138652. 2,
  138653. 6,
  138654. 1,
  138655. 7,
  138656. 0,
  138657. 8,
  138658. };
  138659. static long _vq_lengthlist__44un1__p5_0[] = {
  138660. 1, 4, 4, 7, 7, 8, 8, 9, 9, 4, 6, 5, 8, 7, 8, 8,
  138661. 10, 9, 4, 6, 6, 8, 8, 8, 8,10,10, 7, 8, 7, 9, 9,
  138662. 9, 9,11,10, 7, 8, 8, 9, 9, 9, 9,10,11, 8, 8, 8,
  138663. 9, 9,10,10,11,11, 8, 8, 8, 9, 9,10,10,11,11, 9,
  138664. 10,10,11,10,11,11,12,12, 9,10,10,10,11,11,11,12,
  138665. 12,
  138666. };
  138667. static float _vq_quantthresh__44un1__p5_0[] = {
  138668. -3.5, -2.5, -1.5, -0.5, 0.5, 1.5, 2.5, 3.5,
  138669. };
  138670. static long _vq_quantmap__44un1__p5_0[] = {
  138671. 7, 5, 3, 1, 0, 2, 4, 6,
  138672. 8,
  138673. };
  138674. static encode_aux_threshmatch _vq_auxt__44un1__p5_0 = {
  138675. _vq_quantthresh__44un1__p5_0,
  138676. _vq_quantmap__44un1__p5_0,
  138677. 9,
  138678. 9
  138679. };
  138680. static static_codebook _44un1__p5_0 = {
  138681. 2, 81,
  138682. _vq_lengthlist__44un1__p5_0,
  138683. 1, -531628032, 1611661312, 4, 0,
  138684. _vq_quantlist__44un1__p5_0,
  138685. NULL,
  138686. &_vq_auxt__44un1__p5_0,
  138687. NULL,
  138688. 0
  138689. };
  138690. static long _vq_quantlist__44un1__p6_0[] = {
  138691. 6,
  138692. 5,
  138693. 7,
  138694. 4,
  138695. 8,
  138696. 3,
  138697. 9,
  138698. 2,
  138699. 10,
  138700. 1,
  138701. 11,
  138702. 0,
  138703. 12,
  138704. };
  138705. static long _vq_lengthlist__44un1__p6_0[] = {
  138706. 1, 4, 4, 6, 6, 8, 8,10,10,11,11,15,15, 4, 5, 5,
  138707. 8, 8, 9, 9,11,11,12,12,16,16, 4, 5, 6, 8, 8, 9,
  138708. 9,11,11,12,12,14,14, 7, 8, 8, 9, 9,10,10,11,12,
  138709. 13,13,16,17, 7, 8, 8, 9, 9,10,10,12,12,12,13,15,
  138710. 15, 9,10,10,10,10,11,11,12,12,13,13,15,16, 9, 9,
  138711. 9,10,10,11,11,13,12,13,13,17,17,10,11,11,11,12,
  138712. 12,12,13,13,14,15, 0,18,10,11,11,12,12,12,13,14,
  138713. 13,14,14,17,16,11,12,12,13,13,14,14,14,14,15,16,
  138714. 17,16,11,12,12,13,13,14,14,14,14,15,15,17,17,14,
  138715. 15,15,16,16,16,17,17,16, 0,17, 0,18,14,15,15,16,
  138716. 16, 0,15,18,18, 0,16, 0, 0,
  138717. };
  138718. static float _vq_quantthresh__44un1__p6_0[] = {
  138719. -27.5, -22.5, -17.5, -12.5, -7.5, -2.5, 2.5, 7.5,
  138720. 12.5, 17.5, 22.5, 27.5,
  138721. };
  138722. static long _vq_quantmap__44un1__p6_0[] = {
  138723. 11, 9, 7, 5, 3, 1, 0, 2,
  138724. 4, 6, 8, 10, 12,
  138725. };
  138726. static encode_aux_threshmatch _vq_auxt__44un1__p6_0 = {
  138727. _vq_quantthresh__44un1__p6_0,
  138728. _vq_quantmap__44un1__p6_0,
  138729. 13,
  138730. 13
  138731. };
  138732. static static_codebook _44un1__p6_0 = {
  138733. 2, 169,
  138734. _vq_lengthlist__44un1__p6_0,
  138735. 1, -526516224, 1616117760, 4, 0,
  138736. _vq_quantlist__44un1__p6_0,
  138737. NULL,
  138738. &_vq_auxt__44un1__p6_0,
  138739. NULL,
  138740. 0
  138741. };
  138742. static long _vq_quantlist__44un1__p6_1[] = {
  138743. 2,
  138744. 1,
  138745. 3,
  138746. 0,
  138747. 4,
  138748. };
  138749. static long _vq_lengthlist__44un1__p6_1[] = {
  138750. 2, 4, 4, 5, 5, 4, 5, 5, 5, 5, 4, 5, 5, 6, 5, 5,
  138751. 6, 5, 6, 6, 5, 6, 6, 6, 6,
  138752. };
  138753. static float _vq_quantthresh__44un1__p6_1[] = {
  138754. -1.5, -0.5, 0.5, 1.5,
  138755. };
  138756. static long _vq_quantmap__44un1__p6_1[] = {
  138757. 3, 1, 0, 2, 4,
  138758. };
  138759. static encode_aux_threshmatch _vq_auxt__44un1__p6_1 = {
  138760. _vq_quantthresh__44un1__p6_1,
  138761. _vq_quantmap__44un1__p6_1,
  138762. 5,
  138763. 5
  138764. };
  138765. static static_codebook _44un1__p6_1 = {
  138766. 2, 25,
  138767. _vq_lengthlist__44un1__p6_1,
  138768. 1, -533725184, 1611661312, 3, 0,
  138769. _vq_quantlist__44un1__p6_1,
  138770. NULL,
  138771. &_vq_auxt__44un1__p6_1,
  138772. NULL,
  138773. 0
  138774. };
  138775. static long _vq_quantlist__44un1__p7_0[] = {
  138776. 2,
  138777. 1,
  138778. 3,
  138779. 0,
  138780. 4,
  138781. };
  138782. static long _vq_lengthlist__44un1__p7_0[] = {
  138783. 1, 5, 3,11,11,11,11,11,11,11, 8,11,11,11,11,11,
  138784. 11,11,11,11,11,11,11,11,11,10,11,11,11,11,11,11,
  138785. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138786. 11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138787. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138788. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138789. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138790. 11,11,11,11,11,11,11,11,11,11,11,11,11, 8,11,11,
  138791. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138792. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138793. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,10,
  138794. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138795. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138796. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138797. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138798. 11,11,11,11,11,11,11,11,11,11, 7,11,11,11,11,11,
  138799. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138800. 11,11,11,10,11,11,11,11,11,11,11,11,11,11,11,11,
  138801. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138802. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138803. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138804. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138805. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138806. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138807. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138808. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138809. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138810. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138811. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138812. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138813. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138814. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138815. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138816. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138817. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138818. 11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,11,
  138819. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138820. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138821. 10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,
  138822. 10,
  138823. };
  138824. static float _vq_quantthresh__44un1__p7_0[] = {
  138825. -253.5, -84.5, 84.5, 253.5,
  138826. };
  138827. static long _vq_quantmap__44un1__p7_0[] = {
  138828. 3, 1, 0, 2, 4,
  138829. };
  138830. static encode_aux_threshmatch _vq_auxt__44un1__p7_0 = {
  138831. _vq_quantthresh__44un1__p7_0,
  138832. _vq_quantmap__44un1__p7_0,
  138833. 5,
  138834. 5
  138835. };
  138836. static static_codebook _44un1__p7_0 = {
  138837. 4, 625,
  138838. _vq_lengthlist__44un1__p7_0,
  138839. 1, -518709248, 1626677248, 3, 0,
  138840. _vq_quantlist__44un1__p7_0,
  138841. NULL,
  138842. &_vq_auxt__44un1__p7_0,
  138843. NULL,
  138844. 0
  138845. };
  138846. static long _vq_quantlist__44un1__p7_1[] = {
  138847. 6,
  138848. 5,
  138849. 7,
  138850. 4,
  138851. 8,
  138852. 3,
  138853. 9,
  138854. 2,
  138855. 10,
  138856. 1,
  138857. 11,
  138858. 0,
  138859. 12,
  138860. };
  138861. static long _vq_lengthlist__44un1__p7_1[] = {
  138862. 1, 4, 4, 6, 6, 6, 6, 9, 8, 9, 8, 8, 8, 5, 7, 7,
  138863. 7, 7, 8, 8, 8,10, 8,10, 8, 9, 5, 7, 7, 8, 7, 7,
  138864. 8,10,10,11,10,12,11, 7, 8, 8, 9, 9, 9,10,11,11,
  138865. 11,11,11,11, 7, 8, 8, 8, 9, 9, 9,10,10,10,11,11,
  138866. 12, 7, 8, 8, 9, 9,10,11,11,12,11,12,11,11, 7, 8,
  138867. 8, 9, 9,10,10,11,11,11,12,12,11, 8,10,10,10,10,
  138868. 11,11,14,11,12,12,12,13, 9,10,10,10,10,12,11,14,
  138869. 11,14,11,12,13,10,11,11,11,11,13,11,14,14,13,13,
  138870. 13,14,11,11,11,12,11,12,12,12,13,14,14,13,14,12,
  138871. 11,12,12,12,12,13,13,13,14,13,14,14,11,12,12,14,
  138872. 12,13,13,12,13,13,14,14,14,
  138873. };
  138874. static float _vq_quantthresh__44un1__p7_1[] = {
  138875. -71.5, -58.5, -45.5, -32.5, -19.5, -6.5, 6.5, 19.5,
  138876. 32.5, 45.5, 58.5, 71.5,
  138877. };
  138878. static long _vq_quantmap__44un1__p7_1[] = {
  138879. 11, 9, 7, 5, 3, 1, 0, 2,
  138880. 4, 6, 8, 10, 12,
  138881. };
  138882. static encode_aux_threshmatch _vq_auxt__44un1__p7_1 = {
  138883. _vq_quantthresh__44un1__p7_1,
  138884. _vq_quantmap__44un1__p7_1,
  138885. 13,
  138886. 13
  138887. };
  138888. static static_codebook _44un1__p7_1 = {
  138889. 2, 169,
  138890. _vq_lengthlist__44un1__p7_1,
  138891. 1, -523010048, 1618608128, 4, 0,
  138892. _vq_quantlist__44un1__p7_1,
  138893. NULL,
  138894. &_vq_auxt__44un1__p7_1,
  138895. NULL,
  138896. 0
  138897. };
  138898. static long _vq_quantlist__44un1__p7_2[] = {
  138899. 6,
  138900. 5,
  138901. 7,
  138902. 4,
  138903. 8,
  138904. 3,
  138905. 9,
  138906. 2,
  138907. 10,
  138908. 1,
  138909. 11,
  138910. 0,
  138911. 12,
  138912. };
  138913. static long _vq_lengthlist__44un1__p7_2[] = {
  138914. 3, 4, 4, 6, 6, 7, 7, 8, 8, 9, 9, 9, 8, 4, 5, 5,
  138915. 6, 6, 8, 8, 9, 8, 9, 9, 9, 9, 4, 5, 5, 7, 6, 8,
  138916. 8, 8, 8, 9, 8, 9, 8, 6, 7, 7, 7, 8, 8, 8, 9, 9,
  138917. 9, 9, 9, 9, 6, 7, 7, 7, 7, 8, 8, 9, 9, 9, 9, 9,
  138918. 9, 7, 8, 8, 8, 8, 9, 8, 9, 9,10, 9, 9,10, 7, 8,
  138919. 8, 8, 8, 9, 9, 9, 9, 9, 9,10,10, 8, 9, 9, 9, 9,
  138920. 9, 9, 9, 9,10,10, 9,10, 8, 9, 9, 9, 9, 9, 9, 9,
  138921. 9, 9, 9,10,10, 9, 9, 9,10, 9, 9,10, 9, 9,10,10,
  138922. 10,10, 9, 9, 9, 9, 9, 9, 9,10, 9,10,10,10,10, 9,
  138923. 9, 9,10, 9, 9,10,10, 9,10,10,10,10, 9, 9, 9,10,
  138924. 9, 9, 9,10,10,10,10,10,10,
  138925. };
  138926. static float _vq_quantthresh__44un1__p7_2[] = {
  138927. -5.5, -4.5, -3.5, -2.5, -1.5, -0.5, 0.5, 1.5,
  138928. 2.5, 3.5, 4.5, 5.5,
  138929. };
  138930. static long _vq_quantmap__44un1__p7_2[] = {
  138931. 11, 9, 7, 5, 3, 1, 0, 2,
  138932. 4, 6, 8, 10, 12,
  138933. };
  138934. static encode_aux_threshmatch _vq_auxt__44un1__p7_2 = {
  138935. _vq_quantthresh__44un1__p7_2,
  138936. _vq_quantmap__44un1__p7_2,
  138937. 13,
  138938. 13
  138939. };
  138940. static static_codebook _44un1__p7_2 = {
  138941. 2, 169,
  138942. _vq_lengthlist__44un1__p7_2,
  138943. 1, -531103744, 1611661312, 4, 0,
  138944. _vq_quantlist__44un1__p7_2,
  138945. NULL,
  138946. &_vq_auxt__44un1__p7_2,
  138947. NULL,
  138948. 0
  138949. };
  138950. static long _huff_lengthlist__44un1__short[] = {
  138951. 12,12,14,12,14,14,14,14,12, 6, 6, 8, 9, 9,11,14,
  138952. 12, 4, 2, 6, 6, 7,11,14,13, 6, 5, 7, 8, 9,11,14,
  138953. 13, 8, 5, 8, 6, 8,12,14,12, 7, 7, 8, 8, 8,10,14,
  138954. 12, 6, 3, 4, 4, 4, 7,14,11, 7, 4, 6, 6, 6, 8,14,
  138955. };
  138956. static static_codebook _huff_book__44un1__short = {
  138957. 2, 64,
  138958. _huff_lengthlist__44un1__short,
  138959. 0, 0, 0, 0, 0,
  138960. NULL,
  138961. NULL,
  138962. NULL,
  138963. NULL,
  138964. 0
  138965. };
  138966. /*** End of inlined file: res_books_uncoupled.h ***/
  138967. static vorbis_info_residue0 _residue_44_low_un={
  138968. 0,-1, -1, 8,-1,
  138969. {0},
  138970. {-1},
  138971. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 28.5},
  138972. { -1, 25, -1, 45, -1, -1, -1}
  138973. };
  138974. static vorbis_info_residue0 _residue_44_mid_un={
  138975. 0,-1, -1, 10,-1,
  138976. {0},
  138977. {-1},
  138978. { .5, 1.5, 1.5, 2.5, 2.5, 4.5, 4.5, 16.5, 60.5},
  138979. { -1, 30, -1, 50, -1, 80, -1, -1, -1}
  138980. };
  138981. static vorbis_info_residue0 _residue_44_hi_un={
  138982. 0,-1, -1, 10,-1,
  138983. {0},
  138984. {-1},
  138985. { .5, 1.5, 2.5, 4.5, 8.5, 16.5, 32.5, 71.5,157.5},
  138986. { -1, -1, -1, -1, -1, -1, -1, -1, -1}
  138987. };
  138988. static vorbis_info_mapping0 _map_nominal_u[2]={
  138989. {1, {0,0}, {0}, {0}, 0,{0},{0}},
  138990. {1, {0,0}, {1}, {1}, 0,{0},{0}}
  138991. };
  138992. static static_bookblock _resbook_44u_n1={
  138993. {
  138994. {0},
  138995. {0,0,&_44un1__p1_0},
  138996. {0,0,&_44un1__p2_0},
  138997. {0,0,&_44un1__p3_0},
  138998. {0,0,&_44un1__p4_0},
  138999. {0,0,&_44un1__p5_0},
  139000. {&_44un1__p6_0,&_44un1__p6_1},
  139001. {&_44un1__p7_0,&_44un1__p7_1,&_44un1__p7_2}
  139002. }
  139003. };
  139004. static static_bookblock _resbook_44u_0={
  139005. {
  139006. {0},
  139007. {0,0,&_44u0__p1_0},
  139008. {0,0,&_44u0__p2_0},
  139009. {0,0,&_44u0__p3_0},
  139010. {0,0,&_44u0__p4_0},
  139011. {0,0,&_44u0__p5_0},
  139012. {&_44u0__p6_0,&_44u0__p6_1},
  139013. {&_44u0__p7_0,&_44u0__p7_1,&_44u0__p7_2}
  139014. }
  139015. };
  139016. static static_bookblock _resbook_44u_1={
  139017. {
  139018. {0},
  139019. {0,0,&_44u1__p1_0},
  139020. {0,0,&_44u1__p2_0},
  139021. {0,0,&_44u1__p3_0},
  139022. {0,0,&_44u1__p4_0},
  139023. {0,0,&_44u1__p5_0},
  139024. {&_44u1__p6_0,&_44u1__p6_1},
  139025. {&_44u1__p7_0,&_44u1__p7_1,&_44u1__p7_2}
  139026. }
  139027. };
  139028. static static_bookblock _resbook_44u_2={
  139029. {
  139030. {0},
  139031. {0,0,&_44u2__p1_0},
  139032. {0,0,&_44u2__p2_0},
  139033. {0,0,&_44u2__p3_0},
  139034. {0,0,&_44u2__p4_0},
  139035. {0,0,&_44u2__p5_0},
  139036. {&_44u2__p6_0,&_44u2__p6_1},
  139037. {&_44u2__p7_0,&_44u2__p7_1,&_44u2__p7_2}
  139038. }
  139039. };
  139040. static static_bookblock _resbook_44u_3={
  139041. {
  139042. {0},
  139043. {0,0,&_44u3__p1_0},
  139044. {0,0,&_44u3__p2_0},
  139045. {0,0,&_44u3__p3_0},
  139046. {0,0,&_44u3__p4_0},
  139047. {0,0,&_44u3__p5_0},
  139048. {&_44u3__p6_0,&_44u3__p6_1},
  139049. {&_44u3__p7_0,&_44u3__p7_1,&_44u3__p7_2}
  139050. }
  139051. };
  139052. static static_bookblock _resbook_44u_4={
  139053. {
  139054. {0},
  139055. {0,0,&_44u4__p1_0},
  139056. {0,0,&_44u4__p2_0},
  139057. {0,0,&_44u4__p3_0},
  139058. {0,0,&_44u4__p4_0},
  139059. {0,0,&_44u4__p5_0},
  139060. {&_44u4__p6_0,&_44u4__p6_1},
  139061. {&_44u4__p7_0,&_44u4__p7_1,&_44u4__p7_2}
  139062. }
  139063. };
  139064. static static_bookblock _resbook_44u_5={
  139065. {
  139066. {0},
  139067. {0,0,&_44u5__p1_0},
  139068. {0,0,&_44u5__p2_0},
  139069. {0,0,&_44u5__p3_0},
  139070. {0,0,&_44u5__p4_0},
  139071. {0,0,&_44u5__p5_0},
  139072. {0,0,&_44u5__p6_0},
  139073. {&_44u5__p7_0,&_44u5__p7_1},
  139074. {&_44u5__p8_0,&_44u5__p8_1},
  139075. {&_44u5__p9_0,&_44u5__p9_1,&_44u5__p9_2}
  139076. }
  139077. };
  139078. static static_bookblock _resbook_44u_6={
  139079. {
  139080. {0},
  139081. {0,0,&_44u6__p1_0},
  139082. {0,0,&_44u6__p2_0},
  139083. {0,0,&_44u6__p3_0},
  139084. {0,0,&_44u6__p4_0},
  139085. {0,0,&_44u6__p5_0},
  139086. {0,0,&_44u6__p6_0},
  139087. {&_44u6__p7_0,&_44u6__p7_1},
  139088. {&_44u6__p8_0,&_44u6__p8_1},
  139089. {&_44u6__p9_0,&_44u6__p9_1,&_44u6__p9_2}
  139090. }
  139091. };
  139092. static static_bookblock _resbook_44u_7={
  139093. {
  139094. {0},
  139095. {0,0,&_44u7__p1_0},
  139096. {0,0,&_44u7__p2_0},
  139097. {0,0,&_44u7__p3_0},
  139098. {0,0,&_44u7__p4_0},
  139099. {0,0,&_44u7__p5_0},
  139100. {0,0,&_44u7__p6_0},
  139101. {&_44u7__p7_0,&_44u7__p7_1},
  139102. {&_44u7__p8_0,&_44u7__p8_1},
  139103. {&_44u7__p9_0,&_44u7__p9_1,&_44u7__p9_2}
  139104. }
  139105. };
  139106. static static_bookblock _resbook_44u_8={
  139107. {
  139108. {0},
  139109. {0,0,&_44u8_p1_0},
  139110. {0,0,&_44u8_p2_0},
  139111. {0,0,&_44u8_p3_0},
  139112. {0,0,&_44u8_p4_0},
  139113. {&_44u8_p5_0,&_44u8_p5_1},
  139114. {&_44u8_p6_0,&_44u8_p6_1},
  139115. {&_44u8_p7_0,&_44u8_p7_1},
  139116. {&_44u8_p8_0,&_44u8_p8_1},
  139117. {&_44u8_p9_0,&_44u8_p9_1,&_44u8_p9_2}
  139118. }
  139119. };
  139120. static static_bookblock _resbook_44u_9={
  139121. {
  139122. {0},
  139123. {0,0,&_44u9_p1_0},
  139124. {0,0,&_44u9_p2_0},
  139125. {0,0,&_44u9_p3_0},
  139126. {0,0,&_44u9_p4_0},
  139127. {&_44u9_p5_0,&_44u9_p5_1},
  139128. {&_44u9_p6_0,&_44u9_p6_1},
  139129. {&_44u9_p7_0,&_44u9_p7_1},
  139130. {&_44u9_p8_0,&_44u9_p8_1},
  139131. {&_44u9_p9_0,&_44u9_p9_1,&_44u9_p9_2}
  139132. }
  139133. };
  139134. static vorbis_residue_template _res_44u_n1[]={
  139135. {1,0, &_residue_44_low_un,
  139136. &_huff_book__44un1__short,&_huff_book__44un1__short,
  139137. &_resbook_44u_n1,&_resbook_44u_n1},
  139138. {1,0, &_residue_44_low_un,
  139139. &_huff_book__44un1__long,&_huff_book__44un1__long,
  139140. &_resbook_44u_n1,&_resbook_44u_n1}
  139141. };
  139142. static vorbis_residue_template _res_44u_0[]={
  139143. {1,0, &_residue_44_low_un,
  139144. &_huff_book__44u0__short,&_huff_book__44u0__short,
  139145. &_resbook_44u_0,&_resbook_44u_0},
  139146. {1,0, &_residue_44_low_un,
  139147. &_huff_book__44u0__long,&_huff_book__44u0__long,
  139148. &_resbook_44u_0,&_resbook_44u_0}
  139149. };
  139150. static vorbis_residue_template _res_44u_1[]={
  139151. {1,0, &_residue_44_low_un,
  139152. &_huff_book__44u1__short,&_huff_book__44u1__short,
  139153. &_resbook_44u_1,&_resbook_44u_1},
  139154. {1,0, &_residue_44_low_un,
  139155. &_huff_book__44u1__long,&_huff_book__44u1__long,
  139156. &_resbook_44u_1,&_resbook_44u_1}
  139157. };
  139158. static vorbis_residue_template _res_44u_2[]={
  139159. {1,0, &_residue_44_low_un,
  139160. &_huff_book__44u2__short,&_huff_book__44u2__short,
  139161. &_resbook_44u_2,&_resbook_44u_2},
  139162. {1,0, &_residue_44_low_un,
  139163. &_huff_book__44u2__long,&_huff_book__44u2__long,
  139164. &_resbook_44u_2,&_resbook_44u_2}
  139165. };
  139166. static vorbis_residue_template _res_44u_3[]={
  139167. {1,0, &_residue_44_low_un,
  139168. &_huff_book__44u3__short,&_huff_book__44u3__short,
  139169. &_resbook_44u_3,&_resbook_44u_3},
  139170. {1,0, &_residue_44_low_un,
  139171. &_huff_book__44u3__long,&_huff_book__44u3__long,
  139172. &_resbook_44u_3,&_resbook_44u_3}
  139173. };
  139174. static vorbis_residue_template _res_44u_4[]={
  139175. {1,0, &_residue_44_low_un,
  139176. &_huff_book__44u4__short,&_huff_book__44u4__short,
  139177. &_resbook_44u_4,&_resbook_44u_4},
  139178. {1,0, &_residue_44_low_un,
  139179. &_huff_book__44u4__long,&_huff_book__44u4__long,
  139180. &_resbook_44u_4,&_resbook_44u_4}
  139181. };
  139182. static vorbis_residue_template _res_44u_5[]={
  139183. {1,0, &_residue_44_mid_un,
  139184. &_huff_book__44u5__short,&_huff_book__44u5__short,
  139185. &_resbook_44u_5,&_resbook_44u_5},
  139186. {1,0, &_residue_44_mid_un,
  139187. &_huff_book__44u5__long,&_huff_book__44u5__long,
  139188. &_resbook_44u_5,&_resbook_44u_5}
  139189. };
  139190. static vorbis_residue_template _res_44u_6[]={
  139191. {1,0, &_residue_44_mid_un,
  139192. &_huff_book__44u6__short,&_huff_book__44u6__short,
  139193. &_resbook_44u_6,&_resbook_44u_6},
  139194. {1,0, &_residue_44_mid_un,
  139195. &_huff_book__44u6__long,&_huff_book__44u6__long,
  139196. &_resbook_44u_6,&_resbook_44u_6}
  139197. };
  139198. static vorbis_residue_template _res_44u_7[]={
  139199. {1,0, &_residue_44_mid_un,
  139200. &_huff_book__44u7__short,&_huff_book__44u7__short,
  139201. &_resbook_44u_7,&_resbook_44u_7},
  139202. {1,0, &_residue_44_mid_un,
  139203. &_huff_book__44u7__long,&_huff_book__44u7__long,
  139204. &_resbook_44u_7,&_resbook_44u_7}
  139205. };
  139206. static vorbis_residue_template _res_44u_8[]={
  139207. {1,0, &_residue_44_hi_un,
  139208. &_huff_book__44u8__short,&_huff_book__44u8__short,
  139209. &_resbook_44u_8,&_resbook_44u_8},
  139210. {1,0, &_residue_44_hi_un,
  139211. &_huff_book__44u8__long,&_huff_book__44u8__long,
  139212. &_resbook_44u_8,&_resbook_44u_8}
  139213. };
  139214. static vorbis_residue_template _res_44u_9[]={
  139215. {1,0, &_residue_44_hi_un,
  139216. &_huff_book__44u9__short,&_huff_book__44u9__short,
  139217. &_resbook_44u_9,&_resbook_44u_9},
  139218. {1,0, &_residue_44_hi_un,
  139219. &_huff_book__44u9__long,&_huff_book__44u9__long,
  139220. &_resbook_44u_9,&_resbook_44u_9}
  139221. };
  139222. static vorbis_mapping_template _mapres_template_44_uncoupled[]={
  139223. { _map_nominal_u, _res_44u_n1 }, /* -1 */
  139224. { _map_nominal_u, _res_44u_0 }, /* 0 */
  139225. { _map_nominal_u, _res_44u_1 }, /* 1 */
  139226. { _map_nominal_u, _res_44u_2 }, /* 2 */
  139227. { _map_nominal_u, _res_44u_3 }, /* 3 */
  139228. { _map_nominal_u, _res_44u_4 }, /* 4 */
  139229. { _map_nominal_u, _res_44u_5 }, /* 5 */
  139230. { _map_nominal_u, _res_44u_6 }, /* 6 */
  139231. { _map_nominal_u, _res_44u_7 }, /* 7 */
  139232. { _map_nominal_u, _res_44u_8 }, /* 8 */
  139233. { _map_nominal_u, _res_44u_9 }, /* 9 */
  139234. };
  139235. /*** End of inlined file: residue_44u.h ***/
  139236. static double rate_mapping_44_un[12]={
  139237. 32000.,48000.,60000.,70000.,80000.,86000.,
  139238. 96000.,110000.,120000.,140000.,160000.,240001.
  139239. };
  139240. ve_setup_data_template ve_setup_44_uncoupled={
  139241. 11,
  139242. rate_mapping_44_un,
  139243. quality_mapping_44,
  139244. -1,
  139245. 40000,
  139246. 50000,
  139247. blocksize_short_44,
  139248. blocksize_long_44,
  139249. _psy_tone_masteratt_44,
  139250. _psy_tone_0dB,
  139251. _psy_tone_suppress,
  139252. _vp_tonemask_adj_otherblock,
  139253. _vp_tonemask_adj_longblock,
  139254. _vp_tonemask_adj_otherblock,
  139255. _psy_noiseguards_44,
  139256. _psy_noisebias_impulse,
  139257. _psy_noisebias_padding,
  139258. _psy_noisebias_trans,
  139259. _psy_noisebias_long,
  139260. _psy_noise_suppress,
  139261. _psy_compand_44,
  139262. _psy_compand_short_mapping,
  139263. _psy_compand_long_mapping,
  139264. {_noise_start_short_44,_noise_start_long_44},
  139265. {_noise_part_short_44,_noise_part_long_44},
  139266. _noise_thresh_44,
  139267. _psy_ath_floater,
  139268. _psy_ath_abs,
  139269. _psy_lowpass_44,
  139270. _psy_global_44,
  139271. _global_mapping_44,
  139272. NULL,
  139273. _floor_books,
  139274. _floor,
  139275. _floor_short_mapping_44,
  139276. _floor_long_mapping_44,
  139277. _mapres_template_44_uncoupled
  139278. };
  139279. /*** End of inlined file: setup_44u.h ***/
  139280. /*** Start of inlined file: setup_32.h ***/
  139281. static double rate_mapping_32[12]={
  139282. 18000.,28000.,35000.,45000.,56000.,60000.,
  139283. 75000.,90000.,100000.,115000.,150000.,190000.,
  139284. };
  139285. static double rate_mapping_32_un[12]={
  139286. 30000.,42000.,52000.,64000.,72000.,78000.,
  139287. 86000.,92000.,110000.,120000.,140000.,190000.,
  139288. };
  139289. static double _psy_lowpass_32[12]={
  139290. 12.3,13.,13.,14.,15.,99.,99.,99.,99.,99.,99.,99.
  139291. };
  139292. ve_setup_data_template ve_setup_32_stereo={
  139293. 11,
  139294. rate_mapping_32,
  139295. quality_mapping_44,
  139296. 2,
  139297. 26000,
  139298. 40000,
  139299. blocksize_short_44,
  139300. blocksize_long_44,
  139301. _psy_tone_masteratt_44,
  139302. _psy_tone_0dB,
  139303. _psy_tone_suppress,
  139304. _vp_tonemask_adj_otherblock,
  139305. _vp_tonemask_adj_longblock,
  139306. _vp_tonemask_adj_otherblock,
  139307. _psy_noiseguards_44,
  139308. _psy_noisebias_impulse,
  139309. _psy_noisebias_padding,
  139310. _psy_noisebias_trans,
  139311. _psy_noisebias_long,
  139312. _psy_noise_suppress,
  139313. _psy_compand_44,
  139314. _psy_compand_short_mapping,
  139315. _psy_compand_long_mapping,
  139316. {_noise_start_short_44,_noise_start_long_44},
  139317. {_noise_part_short_44,_noise_part_long_44},
  139318. _noise_thresh_44,
  139319. _psy_ath_floater,
  139320. _psy_ath_abs,
  139321. _psy_lowpass_32,
  139322. _psy_global_44,
  139323. _global_mapping_44,
  139324. _psy_stereo_modes_44,
  139325. _floor_books,
  139326. _floor,
  139327. _floor_short_mapping_44,
  139328. _floor_long_mapping_44,
  139329. _mapres_template_44_stereo
  139330. };
  139331. ve_setup_data_template ve_setup_32_uncoupled={
  139332. 11,
  139333. rate_mapping_32_un,
  139334. quality_mapping_44,
  139335. -1,
  139336. 26000,
  139337. 40000,
  139338. blocksize_short_44,
  139339. blocksize_long_44,
  139340. _psy_tone_masteratt_44,
  139341. _psy_tone_0dB,
  139342. _psy_tone_suppress,
  139343. _vp_tonemask_adj_otherblock,
  139344. _vp_tonemask_adj_longblock,
  139345. _vp_tonemask_adj_otherblock,
  139346. _psy_noiseguards_44,
  139347. _psy_noisebias_impulse,
  139348. _psy_noisebias_padding,
  139349. _psy_noisebias_trans,
  139350. _psy_noisebias_long,
  139351. _psy_noise_suppress,
  139352. _psy_compand_44,
  139353. _psy_compand_short_mapping,
  139354. _psy_compand_long_mapping,
  139355. {_noise_start_short_44,_noise_start_long_44},
  139356. {_noise_part_short_44,_noise_part_long_44},
  139357. _noise_thresh_44,
  139358. _psy_ath_floater,
  139359. _psy_ath_abs,
  139360. _psy_lowpass_32,
  139361. _psy_global_44,
  139362. _global_mapping_44,
  139363. NULL,
  139364. _floor_books,
  139365. _floor,
  139366. _floor_short_mapping_44,
  139367. _floor_long_mapping_44,
  139368. _mapres_template_44_uncoupled
  139369. };
  139370. /*** End of inlined file: setup_32.h ***/
  139371. /*** Start of inlined file: setup_8.h ***/
  139372. /*** Start of inlined file: psych_8.h ***/
  139373. static att3 _psy_tone_masteratt_8[3]={
  139374. {{ 32, 25, 12}, 0, 0}, /* 0 */
  139375. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139376. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139377. };
  139378. static vp_adjblock _vp_tonemask_adj_8[3]={
  139379. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139380. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0,10, 0, 0,99,99,99}}, /* 1 */
  139381. {{-15,-15,-15,-15,-10,-10, -6, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 1 */
  139382. };
  139383. static noise3 _psy_noisebias_8[3]={
  139384. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139385. {-10,-10,-10,-10, -5, -5, -5, 0, 0, 4, 4, 4, 4, 4, 99, 99, 99},
  139386. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139387. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 8, 8, 8, 10, 10, 99, 99, 99},
  139388. {-10,-10,-10,-10,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139389. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139390. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139391. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139392. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139393. };
  139394. static adj_stereo _psy_stereo_modes_8[3]={
  139395. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139396. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139397. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139398. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139399. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139400. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139401. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139402. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139403. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139404. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139405. { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
  139406. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139407. };
  139408. static noiseguard _psy_noiseguards_8[2]={
  139409. {10,10,-1},
  139410. {10,10,-1},
  139411. };
  139412. static compandblock _psy_compand_8[2]={
  139413. {{
  139414. 0, 1, 2, 3, 4, 5, 6, 7, /* 7dB */
  139415. 8, 8, 9, 9,10,10,11, 11, /* 15dB */
  139416. 12,12,13,13,14,14,15, 15, /* 23dB */
  139417. 16,16,17,17,17,18,18, 19, /* 31dB */
  139418. 19,19,20,21,22,23,24, 25, /* 39dB */
  139419. }},
  139420. {{
  139421. 0, 1, 2, 3, 4, 5, 6, 6, /* 7dB */
  139422. 7, 7, 6, 6, 5, 5, 4, 4, /* 15dB */
  139423. 3, 3, 3, 4, 5, 6, 7, 8, /* 23dB */
  139424. 9,10,11,12,13,14,15, 16, /* 31dB */
  139425. 17,18,19,20,21,22,23, 24, /* 39dB */
  139426. }},
  139427. };
  139428. static double _psy_lowpass_8[3]={3.,4.,4.};
  139429. static int _noise_start_8[2]={
  139430. 64,64,
  139431. };
  139432. static int _noise_part_8[2]={
  139433. 8,8,
  139434. };
  139435. static int _psy_ath_floater_8[3]={
  139436. -100,-100,-105,
  139437. };
  139438. static int _psy_ath_abs_8[3]={
  139439. -130,-130,-140,
  139440. };
  139441. /*** End of inlined file: psych_8.h ***/
  139442. /*** Start of inlined file: residue_8.h ***/
  139443. static static_bookblock _resbook_8s_0={
  139444. {
  139445. {0},{0,0,&_8c0_s_p1_0},{0,0,&_8c0_s_p2_0},{0,0,&_8c0_s_p3_0},
  139446. {0,0,&_8c0_s_p4_0},{0,0,&_8c0_s_p5_0},{0,0,&_8c0_s_p6_0},
  139447. {&_8c0_s_p7_0,&_8c0_s_p7_1},{&_8c0_s_p8_0,&_8c0_s_p8_1},
  139448. {&_8c0_s_p9_0,&_8c0_s_p9_1,&_8c0_s_p9_2}
  139449. }
  139450. };
  139451. static static_bookblock _resbook_8s_1={
  139452. {
  139453. {0},{0,0,&_8c1_s_p1_0},{0,0,&_8c1_s_p2_0},{0,0,&_8c1_s_p3_0},
  139454. {0,0,&_8c1_s_p4_0},{0,0,&_8c1_s_p5_0},{0,0,&_8c1_s_p6_0},
  139455. {&_8c1_s_p7_0,&_8c1_s_p7_1},{&_8c1_s_p8_0,&_8c1_s_p8_1},
  139456. {&_8c1_s_p9_0,&_8c1_s_p9_1,&_8c1_s_p9_2}
  139457. }
  139458. };
  139459. static vorbis_residue_template _res_8s_0[]={
  139460. {2,0, &_residue_44_mid,
  139461. &_huff_book__8c0_s_single,&_huff_book__8c0_s_single,
  139462. &_resbook_8s_0,&_resbook_8s_0},
  139463. };
  139464. static vorbis_residue_template _res_8s_1[]={
  139465. {2,0, &_residue_44_mid,
  139466. &_huff_book__8c1_s_single,&_huff_book__8c1_s_single,
  139467. &_resbook_8s_1,&_resbook_8s_1},
  139468. };
  139469. static vorbis_mapping_template _mapres_template_8_stereo[2]={
  139470. { _map_nominal, _res_8s_0 }, /* 0 */
  139471. { _map_nominal, _res_8s_1 }, /* 1 */
  139472. };
  139473. static static_bookblock _resbook_8u_0={
  139474. {
  139475. {0},
  139476. {0,0,&_8u0__p1_0},
  139477. {0,0,&_8u0__p2_0},
  139478. {0,0,&_8u0__p3_0},
  139479. {0,0,&_8u0__p4_0},
  139480. {0,0,&_8u0__p5_0},
  139481. {&_8u0__p6_0,&_8u0__p6_1},
  139482. {&_8u0__p7_0,&_8u0__p7_1,&_8u0__p7_2}
  139483. }
  139484. };
  139485. static static_bookblock _resbook_8u_1={
  139486. {
  139487. {0},
  139488. {0,0,&_8u1__p1_0},
  139489. {0,0,&_8u1__p2_0},
  139490. {0,0,&_8u1__p3_0},
  139491. {0,0,&_8u1__p4_0},
  139492. {0,0,&_8u1__p5_0},
  139493. {0,0,&_8u1__p6_0},
  139494. {&_8u1__p7_0,&_8u1__p7_1},
  139495. {&_8u1__p8_0,&_8u1__p8_1},
  139496. {&_8u1__p9_0,&_8u1__p9_1,&_8u1__p9_2}
  139497. }
  139498. };
  139499. static vorbis_residue_template _res_8u_0[]={
  139500. {1,0, &_residue_44_low_un,
  139501. &_huff_book__8u0__single,&_huff_book__8u0__single,
  139502. &_resbook_8u_0,&_resbook_8u_0},
  139503. };
  139504. static vorbis_residue_template _res_8u_1[]={
  139505. {1,0, &_residue_44_mid_un,
  139506. &_huff_book__8u1__single,&_huff_book__8u1__single,
  139507. &_resbook_8u_1,&_resbook_8u_1},
  139508. };
  139509. static vorbis_mapping_template _mapres_template_8_uncoupled[2]={
  139510. { _map_nominal_u, _res_8u_0 }, /* 0 */
  139511. { _map_nominal_u, _res_8u_1 }, /* 1 */
  139512. };
  139513. /*** End of inlined file: residue_8.h ***/
  139514. static int blocksize_8[2]={
  139515. 512,512
  139516. };
  139517. static int _floor_mapping_8[2]={
  139518. 6,6,
  139519. };
  139520. static double rate_mapping_8[3]={
  139521. 6000.,9000.,32000.,
  139522. };
  139523. static double rate_mapping_8_uncoupled[3]={
  139524. 8000.,14000.,42000.,
  139525. };
  139526. static double quality_mapping_8[3]={
  139527. -.1,.0,1.
  139528. };
  139529. static double _psy_compand_8_mapping[3]={ 0., 1., 1.};
  139530. static double _global_mapping_8[3]={ 1., 2., 3. };
  139531. ve_setup_data_template ve_setup_8_stereo={
  139532. 2,
  139533. rate_mapping_8,
  139534. quality_mapping_8,
  139535. 2,
  139536. 8000,
  139537. 9000,
  139538. blocksize_8,
  139539. blocksize_8,
  139540. _psy_tone_masteratt_8,
  139541. _psy_tone_0dB,
  139542. _psy_tone_suppress,
  139543. _vp_tonemask_adj_8,
  139544. NULL,
  139545. _vp_tonemask_adj_8,
  139546. _psy_noiseguards_8,
  139547. _psy_noisebias_8,
  139548. _psy_noisebias_8,
  139549. NULL,
  139550. NULL,
  139551. _psy_noise_suppress,
  139552. _psy_compand_8,
  139553. _psy_compand_8_mapping,
  139554. NULL,
  139555. {_noise_start_8,_noise_start_8},
  139556. {_noise_part_8,_noise_part_8},
  139557. _noise_thresh_5only,
  139558. _psy_ath_floater_8,
  139559. _psy_ath_abs_8,
  139560. _psy_lowpass_8,
  139561. _psy_global_44,
  139562. _global_mapping_8,
  139563. _psy_stereo_modes_8,
  139564. _floor_books,
  139565. _floor,
  139566. _floor_mapping_8,
  139567. NULL,
  139568. _mapres_template_8_stereo
  139569. };
  139570. ve_setup_data_template ve_setup_8_uncoupled={
  139571. 2,
  139572. rate_mapping_8_uncoupled,
  139573. quality_mapping_8,
  139574. -1,
  139575. 8000,
  139576. 9000,
  139577. blocksize_8,
  139578. blocksize_8,
  139579. _psy_tone_masteratt_8,
  139580. _psy_tone_0dB,
  139581. _psy_tone_suppress,
  139582. _vp_tonemask_adj_8,
  139583. NULL,
  139584. _vp_tonemask_adj_8,
  139585. _psy_noiseguards_8,
  139586. _psy_noisebias_8,
  139587. _psy_noisebias_8,
  139588. NULL,
  139589. NULL,
  139590. _psy_noise_suppress,
  139591. _psy_compand_8,
  139592. _psy_compand_8_mapping,
  139593. NULL,
  139594. {_noise_start_8,_noise_start_8},
  139595. {_noise_part_8,_noise_part_8},
  139596. _noise_thresh_5only,
  139597. _psy_ath_floater_8,
  139598. _psy_ath_abs_8,
  139599. _psy_lowpass_8,
  139600. _psy_global_44,
  139601. _global_mapping_8,
  139602. _psy_stereo_modes_8,
  139603. _floor_books,
  139604. _floor,
  139605. _floor_mapping_8,
  139606. NULL,
  139607. _mapres_template_8_uncoupled
  139608. };
  139609. /*** End of inlined file: setup_8.h ***/
  139610. /*** Start of inlined file: setup_11.h ***/
  139611. /*** Start of inlined file: psych_11.h ***/
  139612. static double _psy_lowpass_11[3]={4.5,5.5,30.,};
  139613. static att3 _psy_tone_masteratt_11[3]={
  139614. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139615. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139616. {{ 20, 0, -14}, 0, 0}, /* 0 */
  139617. };
  139618. static vp_adjblock _vp_tonemask_adj_11[3]={
  139619. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 2, 0,99,99,99}}, /* 0 */
  139620. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 5, 0, 0,99,99,99}}, /* 1 */
  139621. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0,99,99,99}}, /* 2 */
  139622. };
  139623. static noise3 _psy_noisebias_11[3]={
  139624. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139625. {-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 4, 5, 5, 10, 99, 99, 99},
  139626. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139627. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 10, 10, 12, 12, 12, 99, 99, 99},
  139628. {-15,-15,-15,-15,-10,-10, -5, -5, -5, 0, 0, 0, 0, 0, 99, 99, 99},
  139629. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, 99, 99, 99}}},
  139630. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 99, 99, 99},
  139631. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10, 99, 99, 99},
  139632. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24, 99, 99, 99}}},
  139633. };
  139634. static double _noise_thresh_11[3]={ .3,.5,.5 };
  139635. /*** End of inlined file: psych_11.h ***/
  139636. static int blocksize_11[2]={
  139637. 512,512
  139638. };
  139639. static int _floor_mapping_11[2]={
  139640. 6,6,
  139641. };
  139642. static double rate_mapping_11[3]={
  139643. 8000.,13000.,44000.,
  139644. };
  139645. static double rate_mapping_11_uncoupled[3]={
  139646. 12000.,20000.,50000.,
  139647. };
  139648. static double quality_mapping_11[3]={
  139649. -.1,.0,1.
  139650. };
  139651. ve_setup_data_template ve_setup_11_stereo={
  139652. 2,
  139653. rate_mapping_11,
  139654. quality_mapping_11,
  139655. 2,
  139656. 9000,
  139657. 15000,
  139658. blocksize_11,
  139659. blocksize_11,
  139660. _psy_tone_masteratt_11,
  139661. _psy_tone_0dB,
  139662. _psy_tone_suppress,
  139663. _vp_tonemask_adj_11,
  139664. NULL,
  139665. _vp_tonemask_adj_11,
  139666. _psy_noiseguards_8,
  139667. _psy_noisebias_11,
  139668. _psy_noisebias_11,
  139669. NULL,
  139670. NULL,
  139671. _psy_noise_suppress,
  139672. _psy_compand_8,
  139673. _psy_compand_8_mapping,
  139674. NULL,
  139675. {_noise_start_8,_noise_start_8},
  139676. {_noise_part_8,_noise_part_8},
  139677. _noise_thresh_11,
  139678. _psy_ath_floater_8,
  139679. _psy_ath_abs_8,
  139680. _psy_lowpass_11,
  139681. _psy_global_44,
  139682. _global_mapping_8,
  139683. _psy_stereo_modes_8,
  139684. _floor_books,
  139685. _floor,
  139686. _floor_mapping_11,
  139687. NULL,
  139688. _mapres_template_8_stereo
  139689. };
  139690. ve_setup_data_template ve_setup_11_uncoupled={
  139691. 2,
  139692. rate_mapping_11_uncoupled,
  139693. quality_mapping_11,
  139694. -1,
  139695. 9000,
  139696. 15000,
  139697. blocksize_11,
  139698. blocksize_11,
  139699. _psy_tone_masteratt_11,
  139700. _psy_tone_0dB,
  139701. _psy_tone_suppress,
  139702. _vp_tonemask_adj_11,
  139703. NULL,
  139704. _vp_tonemask_adj_11,
  139705. _psy_noiseguards_8,
  139706. _psy_noisebias_11,
  139707. _psy_noisebias_11,
  139708. NULL,
  139709. NULL,
  139710. _psy_noise_suppress,
  139711. _psy_compand_8,
  139712. _psy_compand_8_mapping,
  139713. NULL,
  139714. {_noise_start_8,_noise_start_8},
  139715. {_noise_part_8,_noise_part_8},
  139716. _noise_thresh_11,
  139717. _psy_ath_floater_8,
  139718. _psy_ath_abs_8,
  139719. _psy_lowpass_11,
  139720. _psy_global_44,
  139721. _global_mapping_8,
  139722. _psy_stereo_modes_8,
  139723. _floor_books,
  139724. _floor,
  139725. _floor_mapping_11,
  139726. NULL,
  139727. _mapres_template_8_uncoupled
  139728. };
  139729. /*** End of inlined file: setup_11.h ***/
  139730. /*** Start of inlined file: setup_16.h ***/
  139731. /*** Start of inlined file: psych_16.h ***/
  139732. static adj_stereo _psy_stereo_modes_16[4]={
  139733. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139734. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139735. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 4, 4},
  139736. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139737. {{ 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139738. { 6, 5, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139739. { 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4},
  139740. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139741. {{ 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139742. { 5, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3},
  139743. { 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4},
  139744. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139745. {{ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139746. { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0},
  139747. { 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8},
  139748. { 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99, 99}},
  139749. };
  139750. static double _psy_lowpass_16[4]={6.5,8,30.,99.};
  139751. static att3 _psy_tone_masteratt_16[4]={
  139752. {{ 30, 25, 12}, 0, 0}, /* 0 */
  139753. {{ 25, 22, 12}, 0, 0}, /* 0 */
  139754. {{ 20, 12, 0}, 0, 0}, /* 0 */
  139755. {{ 15, 0, -14}, 0, 0}, /* 0 */
  139756. };
  139757. static vp_adjblock _vp_tonemask_adj_16[4]={
  139758. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 0 */
  139759. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0,10, 0, 0, 0, 0, 0}}, /* 1 */
  139760. {{-20,-20,-20,-20,-20,-16,-10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139761. {{-30,-30,-30,-30,-30,-26,-20,-10, -5, 0, 0, 0, 0, 0, 0, 0, 0}}, /* 2 */
  139762. };
  139763. static noise3 _psy_noisebias_16_short[4]={
  139764. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139765. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139766. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139767. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139768. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 4, 5, 6, 8, 8, 15},
  139769. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139770. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139771. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10, -8, 0, 0, 0, 0, 2, 5},
  139772. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139773. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139774. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139775. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139776. };
  139777. static noise3 _psy_noisebias_16_impulse[4]={
  139778. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 10, 10, 10, 10, 12, 12, 14, 20},
  139779. {-15,-15,-15,-15,-15,-10,-10, -5, 0, 0, 4, 5, 5, 6, 8, 8, 15},
  139780. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139781. {{{-15,-15,-15,-15,-15,-10,-10,-5, 4, 4, 4, 4, 5, 5, 6, 8, 15},
  139782. {-15,-15,-15,-15,-15,-15,-15,-10, -5, -5, -5, 0, 0, 0, 0, 4, 10},
  139783. {-30,-30,-30,-30,-30,-24,-20,-14,-10,-10,-10,-10,-10,-10,-10,-10,-10}}},
  139784. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 0, 0, 0, 0, 0, 0, 4, 10},
  139785. {-20,-20,-20,-20,-16,-12,-20,-14,-10,-10,-10,-10,-10,-10,-10, -7, -5},
  139786. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139787. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139788. {-30,-30,-30,-30,-26,-22,-20,-18,-18,-18,-20,-20,-20,-20,-20,-20,-16},
  139789. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139790. };
  139791. static noise3 _psy_noisebias_16[4]={
  139792. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 8, 8, 10, 10, 10, 14, 20},
  139793. {-10,-10,-10,-10,-10, -5, -2, -2, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139794. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139795. {{{-10,-10,-10,-10, -5, -5, -5, 0, 4, 6, 6, 6, 6, 8, 10, 12, 20},
  139796. {-15,-15,-15,-15,-15,-10, -5, -5, 0, 0, 0, 4, 5, 6, 8, 8, 15},
  139797. {-30,-30,-30,-30,-30,-24,-20,-14,-10, -6, -8, -8, -6, -6, -6, -6, -6}}},
  139798. {{{-15,-15,-15,-15,-15,-12,-10, -8, 0, 2, 4, 4, 5, 5, 5, 8, 12},
  139799. {-20,-20,-20,-20,-16,-12,-20,-10, -5, -5, 0, 0, 0, 0, 0, 2, 5},
  139800. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139801. {{{-15,-15,-15,-15,-15,-12,-10, -8, -5, -5, -5, -5, -5, 0, 0, 0, 6},
  139802. {-30,-30,-30,-30,-26,-22,-20,-14,-12,-12,-10,-10,-10,-10,-10,-10, -6},
  139803. {-30,-30,-30,-30,-26,-26,-26,-26,-26,-26,-26,-26,-26,-24,-20,-20,-20}}},
  139804. };
  139805. static double _noise_thresh_16[4]={ .3,.5,.5,.5 };
  139806. static int _noise_start_16[3]={ 256,256,9999 };
  139807. static int _noise_part_16[4]={ 8,8,8,8 };
  139808. static int _psy_ath_floater_16[4]={
  139809. -100,-100,-100,-105,
  139810. };
  139811. static int _psy_ath_abs_16[4]={
  139812. -130,-130,-130,-140,
  139813. };
  139814. /*** End of inlined file: psych_16.h ***/
  139815. /*** Start of inlined file: residue_16.h ***/
  139816. static static_bookblock _resbook_16s_0={
  139817. {
  139818. {0},
  139819. {0,0,&_16c0_s_p1_0},
  139820. {0,0,&_16c0_s_p2_0},
  139821. {0,0,&_16c0_s_p3_0},
  139822. {0,0,&_16c0_s_p4_0},
  139823. {0,0,&_16c0_s_p5_0},
  139824. {0,0,&_16c0_s_p6_0},
  139825. {&_16c0_s_p7_0,&_16c0_s_p7_1},
  139826. {&_16c0_s_p8_0,&_16c0_s_p8_1},
  139827. {&_16c0_s_p9_0,&_16c0_s_p9_1,&_16c0_s_p9_2}
  139828. }
  139829. };
  139830. static static_bookblock _resbook_16s_1={
  139831. {
  139832. {0},
  139833. {0,0,&_16c1_s_p1_0},
  139834. {0,0,&_16c1_s_p2_0},
  139835. {0,0,&_16c1_s_p3_0},
  139836. {0,0,&_16c1_s_p4_0},
  139837. {0,0,&_16c1_s_p5_0},
  139838. {0,0,&_16c1_s_p6_0},
  139839. {&_16c1_s_p7_0,&_16c1_s_p7_1},
  139840. {&_16c1_s_p8_0,&_16c1_s_p8_1},
  139841. {&_16c1_s_p9_0,&_16c1_s_p9_1,&_16c1_s_p9_2}
  139842. }
  139843. };
  139844. static static_bookblock _resbook_16s_2={
  139845. {
  139846. {0},
  139847. {0,0,&_16c2_s_p1_0},
  139848. {0,0,&_16c2_s_p2_0},
  139849. {0,0,&_16c2_s_p3_0},
  139850. {0,0,&_16c2_s_p4_0},
  139851. {&_16c2_s_p5_0,&_16c2_s_p5_1},
  139852. {&_16c2_s_p6_0,&_16c2_s_p6_1},
  139853. {&_16c2_s_p7_0,&_16c2_s_p7_1},
  139854. {&_16c2_s_p8_0,&_16c2_s_p8_1},
  139855. {&_16c2_s_p9_0,&_16c2_s_p9_1,&_16c2_s_p9_2}
  139856. }
  139857. };
  139858. static vorbis_residue_template _res_16s_0[]={
  139859. {2,0, &_residue_44_mid,
  139860. &_huff_book__16c0_s_single,&_huff_book__16c0_s_single,
  139861. &_resbook_16s_0,&_resbook_16s_0},
  139862. };
  139863. static vorbis_residue_template _res_16s_1[]={
  139864. {2,0, &_residue_44_mid,
  139865. &_huff_book__16c1_s_short,&_huff_book__16c1_s_short,
  139866. &_resbook_16s_1,&_resbook_16s_1},
  139867. {2,0, &_residue_44_mid,
  139868. &_huff_book__16c1_s_long,&_huff_book__16c1_s_long,
  139869. &_resbook_16s_1,&_resbook_16s_1}
  139870. };
  139871. static vorbis_residue_template _res_16s_2[]={
  139872. {2,0, &_residue_44_high,
  139873. &_huff_book__16c2_s_short,&_huff_book__16c2_s_short,
  139874. &_resbook_16s_2,&_resbook_16s_2},
  139875. {2,0, &_residue_44_high,
  139876. &_huff_book__16c2_s_long,&_huff_book__16c2_s_long,
  139877. &_resbook_16s_2,&_resbook_16s_2}
  139878. };
  139879. static vorbis_mapping_template _mapres_template_16_stereo[3]={
  139880. { _map_nominal, _res_16s_0 }, /* 0 */
  139881. { _map_nominal, _res_16s_1 }, /* 1 */
  139882. { _map_nominal, _res_16s_2 }, /* 2 */
  139883. };
  139884. static static_bookblock _resbook_16u_0={
  139885. {
  139886. {0},
  139887. {0,0,&_16u0__p1_0},
  139888. {0,0,&_16u0__p2_0},
  139889. {0,0,&_16u0__p3_0},
  139890. {0,0,&_16u0__p4_0},
  139891. {0,0,&_16u0__p5_0},
  139892. {&_16u0__p6_0,&_16u0__p6_1},
  139893. {&_16u0__p7_0,&_16u0__p7_1,&_16u0__p7_2}
  139894. }
  139895. };
  139896. static static_bookblock _resbook_16u_1={
  139897. {
  139898. {0},
  139899. {0,0,&_16u1__p1_0},
  139900. {0,0,&_16u1__p2_0},
  139901. {0,0,&_16u1__p3_0},
  139902. {0,0,&_16u1__p4_0},
  139903. {0,0,&_16u1__p5_0},
  139904. {0,0,&_16u1__p6_0},
  139905. {&_16u1__p7_0,&_16u1__p7_1},
  139906. {&_16u1__p8_0,&_16u1__p8_1},
  139907. {&_16u1__p9_0,&_16u1__p9_1,&_16u1__p9_2}
  139908. }
  139909. };
  139910. static static_bookblock _resbook_16u_2={
  139911. {
  139912. {0},
  139913. {0,0,&_16u2_p1_0},
  139914. {0,0,&_16u2_p2_0},
  139915. {0,0,&_16u2_p3_0},
  139916. {0,0,&_16u2_p4_0},
  139917. {&_16u2_p5_0,&_16u2_p5_1},
  139918. {&_16u2_p6_0,&_16u2_p6_1},
  139919. {&_16u2_p7_0,&_16u2_p7_1},
  139920. {&_16u2_p8_0,&_16u2_p8_1},
  139921. {&_16u2_p9_0,&_16u2_p9_1,&_16u2_p9_2}
  139922. }
  139923. };
  139924. static vorbis_residue_template _res_16u_0[]={
  139925. {1,0, &_residue_44_low_un,
  139926. &_huff_book__16u0__single,&_huff_book__16u0__single,
  139927. &_resbook_16u_0,&_resbook_16u_0},
  139928. };
  139929. static vorbis_residue_template _res_16u_1[]={
  139930. {1,0, &_residue_44_mid_un,
  139931. &_huff_book__16u1__short,&_huff_book__16u1__short,
  139932. &_resbook_16u_1,&_resbook_16u_1},
  139933. {1,0, &_residue_44_mid_un,
  139934. &_huff_book__16u1__long,&_huff_book__16u1__long,
  139935. &_resbook_16u_1,&_resbook_16u_1}
  139936. };
  139937. static vorbis_residue_template _res_16u_2[]={
  139938. {1,0, &_residue_44_hi_un,
  139939. &_huff_book__16u2__short,&_huff_book__16u2__short,
  139940. &_resbook_16u_2,&_resbook_16u_2},
  139941. {1,0, &_residue_44_hi_un,
  139942. &_huff_book__16u2__long,&_huff_book__16u2__long,
  139943. &_resbook_16u_2,&_resbook_16u_2}
  139944. };
  139945. static vorbis_mapping_template _mapres_template_16_uncoupled[3]={
  139946. { _map_nominal_u, _res_16u_0 }, /* 0 */
  139947. { _map_nominal_u, _res_16u_1 }, /* 1 */
  139948. { _map_nominal_u, _res_16u_2 }, /* 2 */
  139949. };
  139950. /*** End of inlined file: residue_16.h ***/
  139951. static int blocksize_16_short[3]={
  139952. 1024,512,512
  139953. };
  139954. static int blocksize_16_long[3]={
  139955. 1024,1024,1024
  139956. };
  139957. static int _floor_mapping_16_short[3]={
  139958. 9,3,3
  139959. };
  139960. static int _floor_mapping_16[3]={
  139961. 9,9,9
  139962. };
  139963. static double rate_mapping_16[4]={
  139964. 12000.,20000.,44000.,86000.
  139965. };
  139966. static double rate_mapping_16_uncoupled[4]={
  139967. 16000.,28000.,64000.,100000.
  139968. };
  139969. static double _global_mapping_16[4]={ 1., 2., 3., 4. };
  139970. static double quality_mapping_16[4]={ -.1,.05,.5,1. };
  139971. static double _psy_compand_16_mapping[4]={ 0., .8, 1., 1.};
  139972. ve_setup_data_template ve_setup_16_stereo={
  139973. 3,
  139974. rate_mapping_16,
  139975. quality_mapping_16,
  139976. 2,
  139977. 15000,
  139978. 19000,
  139979. blocksize_16_short,
  139980. blocksize_16_long,
  139981. _psy_tone_masteratt_16,
  139982. _psy_tone_0dB,
  139983. _psy_tone_suppress,
  139984. _vp_tonemask_adj_16,
  139985. _vp_tonemask_adj_16,
  139986. _vp_tonemask_adj_16,
  139987. _psy_noiseguards_8,
  139988. _psy_noisebias_16_impulse,
  139989. _psy_noisebias_16_short,
  139990. _psy_noisebias_16_short,
  139991. _psy_noisebias_16,
  139992. _psy_noise_suppress,
  139993. _psy_compand_8,
  139994. _psy_compand_16_mapping,
  139995. _psy_compand_16_mapping,
  139996. {_noise_start_16,_noise_start_16},
  139997. { _noise_part_16, _noise_part_16},
  139998. _noise_thresh_16,
  139999. _psy_ath_floater_16,
  140000. _psy_ath_abs_16,
  140001. _psy_lowpass_16,
  140002. _psy_global_44,
  140003. _global_mapping_16,
  140004. _psy_stereo_modes_16,
  140005. _floor_books,
  140006. _floor,
  140007. _floor_mapping_16_short,
  140008. _floor_mapping_16,
  140009. _mapres_template_16_stereo
  140010. };
  140011. ve_setup_data_template ve_setup_16_uncoupled={
  140012. 3,
  140013. rate_mapping_16_uncoupled,
  140014. quality_mapping_16,
  140015. -1,
  140016. 15000,
  140017. 19000,
  140018. blocksize_16_short,
  140019. blocksize_16_long,
  140020. _psy_tone_masteratt_16,
  140021. _psy_tone_0dB,
  140022. _psy_tone_suppress,
  140023. _vp_tonemask_adj_16,
  140024. _vp_tonemask_adj_16,
  140025. _vp_tonemask_adj_16,
  140026. _psy_noiseguards_8,
  140027. _psy_noisebias_16_impulse,
  140028. _psy_noisebias_16_short,
  140029. _psy_noisebias_16_short,
  140030. _psy_noisebias_16,
  140031. _psy_noise_suppress,
  140032. _psy_compand_8,
  140033. _psy_compand_16_mapping,
  140034. _psy_compand_16_mapping,
  140035. {_noise_start_16,_noise_start_16},
  140036. { _noise_part_16, _noise_part_16},
  140037. _noise_thresh_16,
  140038. _psy_ath_floater_16,
  140039. _psy_ath_abs_16,
  140040. _psy_lowpass_16,
  140041. _psy_global_44,
  140042. _global_mapping_16,
  140043. _psy_stereo_modes_16,
  140044. _floor_books,
  140045. _floor,
  140046. _floor_mapping_16_short,
  140047. _floor_mapping_16,
  140048. _mapres_template_16_uncoupled
  140049. };
  140050. /*** End of inlined file: setup_16.h ***/
  140051. /*** Start of inlined file: setup_22.h ***/
  140052. static double rate_mapping_22[4]={
  140053. 15000.,20000.,44000.,86000.
  140054. };
  140055. static double rate_mapping_22_uncoupled[4]={
  140056. 16000.,28000.,50000.,90000.
  140057. };
  140058. static double _psy_lowpass_22[4]={9.5,11.,30.,99.};
  140059. ve_setup_data_template ve_setup_22_stereo={
  140060. 3,
  140061. rate_mapping_22,
  140062. quality_mapping_16,
  140063. 2,
  140064. 19000,
  140065. 26000,
  140066. blocksize_16_short,
  140067. blocksize_16_long,
  140068. _psy_tone_masteratt_16,
  140069. _psy_tone_0dB,
  140070. _psy_tone_suppress,
  140071. _vp_tonemask_adj_16,
  140072. _vp_tonemask_adj_16,
  140073. _vp_tonemask_adj_16,
  140074. _psy_noiseguards_8,
  140075. _psy_noisebias_16_impulse,
  140076. _psy_noisebias_16_short,
  140077. _psy_noisebias_16_short,
  140078. _psy_noisebias_16,
  140079. _psy_noise_suppress,
  140080. _psy_compand_8,
  140081. _psy_compand_8_mapping,
  140082. _psy_compand_8_mapping,
  140083. {_noise_start_16,_noise_start_16},
  140084. { _noise_part_16, _noise_part_16},
  140085. _noise_thresh_16,
  140086. _psy_ath_floater_16,
  140087. _psy_ath_abs_16,
  140088. _psy_lowpass_22,
  140089. _psy_global_44,
  140090. _global_mapping_16,
  140091. _psy_stereo_modes_16,
  140092. _floor_books,
  140093. _floor,
  140094. _floor_mapping_16_short,
  140095. _floor_mapping_16,
  140096. _mapres_template_16_stereo
  140097. };
  140098. ve_setup_data_template ve_setup_22_uncoupled={
  140099. 3,
  140100. rate_mapping_22_uncoupled,
  140101. quality_mapping_16,
  140102. -1,
  140103. 19000,
  140104. 26000,
  140105. blocksize_16_short,
  140106. blocksize_16_long,
  140107. _psy_tone_masteratt_16,
  140108. _psy_tone_0dB,
  140109. _psy_tone_suppress,
  140110. _vp_tonemask_adj_16,
  140111. _vp_tonemask_adj_16,
  140112. _vp_tonemask_adj_16,
  140113. _psy_noiseguards_8,
  140114. _psy_noisebias_16_impulse,
  140115. _psy_noisebias_16_short,
  140116. _psy_noisebias_16_short,
  140117. _psy_noisebias_16,
  140118. _psy_noise_suppress,
  140119. _psy_compand_8,
  140120. _psy_compand_8_mapping,
  140121. _psy_compand_8_mapping,
  140122. {_noise_start_16,_noise_start_16},
  140123. { _noise_part_16, _noise_part_16},
  140124. _noise_thresh_16,
  140125. _psy_ath_floater_16,
  140126. _psy_ath_abs_16,
  140127. _psy_lowpass_22,
  140128. _psy_global_44,
  140129. _global_mapping_16,
  140130. _psy_stereo_modes_16,
  140131. _floor_books,
  140132. _floor,
  140133. _floor_mapping_16_short,
  140134. _floor_mapping_16,
  140135. _mapres_template_16_uncoupled
  140136. };
  140137. /*** End of inlined file: setup_22.h ***/
  140138. /*** Start of inlined file: setup_X.h ***/
  140139. static double rate_mapping_X[12]={
  140140. -1.,-1.,-1.,-1.,-1.,-1.,
  140141. -1.,-1.,-1.,-1.,-1.,-1.
  140142. };
  140143. ve_setup_data_template ve_setup_X_stereo={
  140144. 11,
  140145. rate_mapping_X,
  140146. quality_mapping_44,
  140147. 2,
  140148. 50000,
  140149. 200000,
  140150. blocksize_short_44,
  140151. blocksize_long_44,
  140152. _psy_tone_masteratt_44,
  140153. _psy_tone_0dB,
  140154. _psy_tone_suppress,
  140155. _vp_tonemask_adj_otherblock,
  140156. _vp_tonemask_adj_longblock,
  140157. _vp_tonemask_adj_otherblock,
  140158. _psy_noiseguards_44,
  140159. _psy_noisebias_impulse,
  140160. _psy_noisebias_padding,
  140161. _psy_noisebias_trans,
  140162. _psy_noisebias_long,
  140163. _psy_noise_suppress,
  140164. _psy_compand_44,
  140165. _psy_compand_short_mapping,
  140166. _psy_compand_long_mapping,
  140167. {_noise_start_short_44,_noise_start_long_44},
  140168. {_noise_part_short_44,_noise_part_long_44},
  140169. _noise_thresh_44,
  140170. _psy_ath_floater,
  140171. _psy_ath_abs,
  140172. _psy_lowpass_44,
  140173. _psy_global_44,
  140174. _global_mapping_44,
  140175. _psy_stereo_modes_44,
  140176. _floor_books,
  140177. _floor,
  140178. _floor_short_mapping_44,
  140179. _floor_long_mapping_44,
  140180. _mapres_template_44_stereo
  140181. };
  140182. ve_setup_data_template ve_setup_X_uncoupled={
  140183. 11,
  140184. rate_mapping_X,
  140185. quality_mapping_44,
  140186. -1,
  140187. 50000,
  140188. 200000,
  140189. blocksize_short_44,
  140190. blocksize_long_44,
  140191. _psy_tone_masteratt_44,
  140192. _psy_tone_0dB,
  140193. _psy_tone_suppress,
  140194. _vp_tonemask_adj_otherblock,
  140195. _vp_tonemask_adj_longblock,
  140196. _vp_tonemask_adj_otherblock,
  140197. _psy_noiseguards_44,
  140198. _psy_noisebias_impulse,
  140199. _psy_noisebias_padding,
  140200. _psy_noisebias_trans,
  140201. _psy_noisebias_long,
  140202. _psy_noise_suppress,
  140203. _psy_compand_44,
  140204. _psy_compand_short_mapping,
  140205. _psy_compand_long_mapping,
  140206. {_noise_start_short_44,_noise_start_long_44},
  140207. {_noise_part_short_44,_noise_part_long_44},
  140208. _noise_thresh_44,
  140209. _psy_ath_floater,
  140210. _psy_ath_abs,
  140211. _psy_lowpass_44,
  140212. _psy_global_44,
  140213. _global_mapping_44,
  140214. NULL,
  140215. _floor_books,
  140216. _floor,
  140217. _floor_short_mapping_44,
  140218. _floor_long_mapping_44,
  140219. _mapres_template_44_uncoupled
  140220. };
  140221. ve_setup_data_template ve_setup_XX_stereo={
  140222. 2,
  140223. rate_mapping_X,
  140224. quality_mapping_8,
  140225. 2,
  140226. 0,
  140227. 8000,
  140228. blocksize_8,
  140229. blocksize_8,
  140230. _psy_tone_masteratt_8,
  140231. _psy_tone_0dB,
  140232. _psy_tone_suppress,
  140233. _vp_tonemask_adj_8,
  140234. NULL,
  140235. _vp_tonemask_adj_8,
  140236. _psy_noiseguards_8,
  140237. _psy_noisebias_8,
  140238. _psy_noisebias_8,
  140239. NULL,
  140240. NULL,
  140241. _psy_noise_suppress,
  140242. _psy_compand_8,
  140243. _psy_compand_8_mapping,
  140244. NULL,
  140245. {_noise_start_8,_noise_start_8},
  140246. {_noise_part_8,_noise_part_8},
  140247. _noise_thresh_5only,
  140248. _psy_ath_floater_8,
  140249. _psy_ath_abs_8,
  140250. _psy_lowpass_8,
  140251. _psy_global_44,
  140252. _global_mapping_8,
  140253. _psy_stereo_modes_8,
  140254. _floor_books,
  140255. _floor,
  140256. _floor_mapping_8,
  140257. NULL,
  140258. _mapres_template_8_stereo
  140259. };
  140260. ve_setup_data_template ve_setup_XX_uncoupled={
  140261. 2,
  140262. rate_mapping_X,
  140263. quality_mapping_8,
  140264. -1,
  140265. 0,
  140266. 8000,
  140267. blocksize_8,
  140268. blocksize_8,
  140269. _psy_tone_masteratt_8,
  140270. _psy_tone_0dB,
  140271. _psy_tone_suppress,
  140272. _vp_tonemask_adj_8,
  140273. NULL,
  140274. _vp_tonemask_adj_8,
  140275. _psy_noiseguards_8,
  140276. _psy_noisebias_8,
  140277. _psy_noisebias_8,
  140278. NULL,
  140279. NULL,
  140280. _psy_noise_suppress,
  140281. _psy_compand_8,
  140282. _psy_compand_8_mapping,
  140283. NULL,
  140284. {_noise_start_8,_noise_start_8},
  140285. {_noise_part_8,_noise_part_8},
  140286. _noise_thresh_5only,
  140287. _psy_ath_floater_8,
  140288. _psy_ath_abs_8,
  140289. _psy_lowpass_8,
  140290. _psy_global_44,
  140291. _global_mapping_8,
  140292. _psy_stereo_modes_8,
  140293. _floor_books,
  140294. _floor,
  140295. _floor_mapping_8,
  140296. NULL,
  140297. _mapres_template_8_uncoupled
  140298. };
  140299. /*** End of inlined file: setup_X.h ***/
  140300. static ve_setup_data_template *setup_list[]={
  140301. &ve_setup_44_stereo,
  140302. &ve_setup_44_uncoupled,
  140303. &ve_setup_32_stereo,
  140304. &ve_setup_32_uncoupled,
  140305. &ve_setup_22_stereo,
  140306. &ve_setup_22_uncoupled,
  140307. &ve_setup_16_stereo,
  140308. &ve_setup_16_uncoupled,
  140309. &ve_setup_11_stereo,
  140310. &ve_setup_11_uncoupled,
  140311. &ve_setup_8_stereo,
  140312. &ve_setup_8_uncoupled,
  140313. &ve_setup_X_stereo,
  140314. &ve_setup_X_uncoupled,
  140315. &ve_setup_XX_stereo,
  140316. &ve_setup_XX_uncoupled,
  140317. 0
  140318. };
  140319. static int vorbis_encode_toplevel_setup(vorbis_info *vi,int ch,long rate){
  140320. if(vi && vi->codec_setup){
  140321. vi->version=0;
  140322. vi->channels=ch;
  140323. vi->rate=rate;
  140324. return(0);
  140325. }
  140326. return(OV_EINVAL);
  140327. }
  140328. static void vorbis_encode_floor_setup(vorbis_info *vi,double s,int block,
  140329. static_codebook ***books,
  140330. vorbis_info_floor1 *in,
  140331. int *x){
  140332. int i,k,is=s;
  140333. vorbis_info_floor1 *f=(vorbis_info_floor1*) _ogg_calloc(1,sizeof(*f));
  140334. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140335. memcpy(f,in+x[is],sizeof(*f));
  140336. f->n=ci->blocksizes[block]>>1;
  140337. {
  140338. int partitions=f->partitions;
  140339. int maxclass=-1;
  140340. int maxbook=-1;
  140341. for(i=0;i<partitions;i++)
  140342. if(f->partitionclass[i]>maxclass)maxclass=f->partitionclass[i];
  140343. for(i=0;i<=maxclass;i++){
  140344. if(f->class_book[i]>maxbook)maxbook=f->class_book[i];
  140345. f->class_book[i]+=ci->books;
  140346. for(k=0;k<(1<<f->class_subs[i]);k++){
  140347. if(f->class_subbook[i][k]>maxbook)maxbook=f->class_subbook[i][k];
  140348. if(f->class_subbook[i][k]>=0)f->class_subbook[i][k]+=ci->books;
  140349. }
  140350. }
  140351. for(i=0;i<=maxbook;i++)
  140352. ci->book_param[ci->books++]=books[x[is]][i];
  140353. }
  140354. ci->floor_type[ci->floors]=1;
  140355. ci->floor_param[ci->floors]=f;
  140356. ci->floors++;
  140357. return;
  140358. }
  140359. static void vorbis_encode_global_psych_setup(vorbis_info *vi,double s,
  140360. vorbis_info_psy_global *in,
  140361. double *x){
  140362. int i,is=s;
  140363. double ds=s-is;
  140364. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140365. vorbis_info_psy_global *g=&ci->psy_g_param;
  140366. memcpy(g,in+(int)x[is],sizeof(*g));
  140367. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140368. is=(int)ds;
  140369. ds-=is;
  140370. if(ds==0 && is>0){
  140371. is--;
  140372. ds=1.;
  140373. }
  140374. for(i=0;i<4;i++){
  140375. g->preecho_thresh[i]=in[is].preecho_thresh[i]*(1.-ds)+in[is+1].preecho_thresh[i]*ds;
  140376. g->postecho_thresh[i]=in[is].postecho_thresh[i]*(1.-ds)+in[is+1].postecho_thresh[i]*ds;
  140377. }
  140378. g->ampmax_att_per_sec=ci->hi.amplitude_track_dBpersec;
  140379. return;
  140380. }
  140381. static void vorbis_encode_global_stereo(vorbis_info *vi,
  140382. highlevel_encode_setup *hi,
  140383. adj_stereo *p){
  140384. float s=hi->stereo_point_setting;
  140385. int i,is=s;
  140386. double ds=s-is;
  140387. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140388. vorbis_info_psy_global *g=&ci->psy_g_param;
  140389. if(p){
  140390. memcpy(g->coupling_prepointamp,p[is].pre,sizeof(*p[is].pre)*PACKETBLOBS);
  140391. memcpy(g->coupling_postpointamp,p[is].post,sizeof(*p[is].post)*PACKETBLOBS);
  140392. if(hi->managed){
  140393. for(i=0;i<PACKETBLOBS;i++){
  140394. float kHz=p[is].kHz[i]*(1.-ds)+p[is+1].kHz[i]*ds;
  140395. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140396. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140397. g->coupling_pkHz[i]=kHz;
  140398. kHz=p[is].lowpasskHz[i]*(1.-ds)+p[is+1].lowpasskHz[i]*ds;
  140399. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140400. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140401. }
  140402. }else{
  140403. float kHz=p[is].kHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].kHz[PACKETBLOBS/2]*ds;
  140404. for(i=0;i<PACKETBLOBS;i++){
  140405. g->coupling_pointlimit[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140406. g->coupling_pointlimit[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140407. g->coupling_pkHz[i]=kHz;
  140408. }
  140409. kHz=p[is].lowpasskHz[PACKETBLOBS/2]*(1.-ds)+p[is+1].lowpasskHz[PACKETBLOBS/2]*ds;
  140410. for(i=0;i<PACKETBLOBS;i++){
  140411. g->sliding_lowpass[0][i]=kHz*1000./vi->rate*ci->blocksizes[0];
  140412. g->sliding_lowpass[1][i]=kHz*1000./vi->rate*ci->blocksizes[1];
  140413. }
  140414. }
  140415. }else{
  140416. for(i=0;i<PACKETBLOBS;i++){
  140417. g->sliding_lowpass[0][i]=ci->blocksizes[0];
  140418. g->sliding_lowpass[1][i]=ci->blocksizes[1];
  140419. }
  140420. }
  140421. return;
  140422. }
  140423. static void vorbis_encode_psyset_setup(vorbis_info *vi,double s,
  140424. int *nn_start,
  140425. int *nn_partition,
  140426. double *nn_thresh,
  140427. int block){
  140428. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140429. vorbis_info_psy *p=ci->psy_param[block];
  140430. highlevel_encode_setup *hi=&ci->hi;
  140431. int is=s;
  140432. if(block>=ci->psys)
  140433. ci->psys=block+1;
  140434. if(!p){
  140435. p=(vorbis_info_psy*)_ogg_calloc(1,sizeof(*p));
  140436. ci->psy_param[block]=p;
  140437. }
  140438. memcpy(p,&_psy_info_template,sizeof(*p));
  140439. p->blockflag=block>>1;
  140440. if(hi->noise_normalize_p){
  140441. p->normal_channel_p=1;
  140442. p->normal_point_p=1;
  140443. p->normal_start=nn_start[is];
  140444. p->normal_partition=nn_partition[is];
  140445. p->normal_thresh=nn_thresh[is];
  140446. }
  140447. return;
  140448. }
  140449. static void vorbis_encode_tonemask_setup(vorbis_info *vi,double s,int block,
  140450. att3 *att,
  140451. int *max,
  140452. vp_adjblock *in){
  140453. int i,is=s;
  140454. double ds=s-is;
  140455. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140456. vorbis_info_psy *p=ci->psy_param[block];
  140457. p->tone_masteratt[0]=att[is].att[0]*(1.-ds)+att[is+1].att[0]*ds;
  140458. p->tone_masteratt[1]=att[is].att[1]*(1.-ds)+att[is+1].att[1]*ds;
  140459. p->tone_masteratt[2]=att[is].att[2]*(1.-ds)+att[is+1].att[2]*ds;
  140460. p->tone_centerboost=att[is].boost*(1.-ds)+att[is+1].boost*ds;
  140461. p->tone_decay=att[is].decay*(1.-ds)+att[is+1].decay*ds;
  140462. p->max_curve_dB=max[is]*(1.-ds)+max[is+1]*ds;
  140463. for(i=0;i<P_BANDS;i++)
  140464. p->toneatt[i]=in[is].block[i]*(1.-ds)+in[is+1].block[i]*ds;
  140465. return;
  140466. }
  140467. static void vorbis_encode_compand_setup(vorbis_info *vi,double s,int block,
  140468. compandblock *in, double *x){
  140469. int i,is=s;
  140470. double ds=s-is;
  140471. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140472. vorbis_info_psy *p=ci->psy_param[block];
  140473. ds=x[is]*(1.-ds)+x[is+1]*ds;
  140474. is=(int)ds;
  140475. ds-=is;
  140476. if(ds==0 && is>0){
  140477. is--;
  140478. ds=1.;
  140479. }
  140480. for(i=0;i<NOISE_COMPAND_LEVELS;i++)
  140481. p->noisecompand[i]=in[is].data[i]*(1.-ds)+in[is+1].data[i]*ds;
  140482. return;
  140483. }
  140484. static void vorbis_encode_peak_setup(vorbis_info *vi,double s,int block,
  140485. int *suppress){
  140486. int is=s;
  140487. double ds=s-is;
  140488. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140489. vorbis_info_psy *p=ci->psy_param[block];
  140490. p->tone_abs_limit=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140491. return;
  140492. }
  140493. static void vorbis_encode_noisebias_setup(vorbis_info *vi,double s,int block,
  140494. int *suppress,
  140495. noise3 *in,
  140496. noiseguard *guard,
  140497. double userbias){
  140498. int i,is=s,j;
  140499. double ds=s-is;
  140500. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140501. vorbis_info_psy *p=ci->psy_param[block];
  140502. p->noisemaxsupp=suppress[is]*(1.-ds)+suppress[is+1]*ds;
  140503. p->noisewindowlomin=guard[block].lo;
  140504. p->noisewindowhimin=guard[block].hi;
  140505. p->noisewindowfixed=guard[block].fixed;
  140506. for(j=0;j<P_NOISECURVES;j++)
  140507. for(i=0;i<P_BANDS;i++)
  140508. p->noiseoff[j][i]=in[is].data[j][i]*(1.-ds)+in[is+1].data[j][i]*ds;
  140509. for(j=0;j<P_NOISECURVES;j++){
  140510. float min=p->noiseoff[j][0]+6; /* the lowest it can go */
  140511. for(i=0;i<P_BANDS;i++){
  140512. p->noiseoff[j][i]+=userbias;
  140513. if(p->noiseoff[j][i]<min)p->noiseoff[j][i]=min;
  140514. }
  140515. }
  140516. return;
  140517. }
  140518. static void vorbis_encode_ath_setup(vorbis_info *vi,int block){
  140519. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140520. vorbis_info_psy *p=ci->psy_param[block];
  140521. p->ath_adjatt=ci->hi.ath_floating_dB;
  140522. p->ath_maxatt=ci->hi.ath_absolute_dB;
  140523. return;
  140524. }
  140525. static int book_dup_or_new(codec_setup_info *ci,static_codebook *book){
  140526. int i;
  140527. for(i=0;i<ci->books;i++)
  140528. if(ci->book_param[i]==book)return(i);
  140529. return(ci->books++);
  140530. }
  140531. static void vorbis_encode_blocksize_setup(vorbis_info *vi,double s,
  140532. int *shortb,int *longb){
  140533. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140534. int is=s;
  140535. int blockshort=shortb[is];
  140536. int blocklong=longb[is];
  140537. ci->blocksizes[0]=blockshort;
  140538. ci->blocksizes[1]=blocklong;
  140539. }
  140540. static void vorbis_encode_residue_setup(vorbis_info *vi,
  140541. int number, int block,
  140542. vorbis_residue_template *res){
  140543. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140544. int i,n;
  140545. vorbis_info_residue0 *r=(vorbis_info_residue0*)(ci->residue_param[number]=
  140546. (vorbis_info_residue0*)_ogg_malloc(sizeof(*r)));
  140547. memcpy(r,res->res,sizeof(*r));
  140548. if(ci->residues<=number)ci->residues=number+1;
  140549. switch(ci->blocksizes[block]){
  140550. case 64:case 128:case 256:
  140551. r->grouping=16;
  140552. break;
  140553. default:
  140554. r->grouping=32;
  140555. break;
  140556. }
  140557. ci->residue_type[number]=res->res_type;
  140558. n=r->end=ci->blocksizes[block]>>1;
  140559. if(res->res_type==2)
  140560. n=r->end*=vi->channels;
  140561. {
  140562. int booklist=0,k;
  140563. if(ci->hi.managed){
  140564. for(i=0;i<r->partitions;i++)
  140565. for(k=0;k<3;k++)
  140566. if(res->books_base_managed->books[i][k])
  140567. r->secondstages[i]|=(1<<k);
  140568. r->groupbook=book_dup_or_new(ci,res->book_aux_managed);
  140569. ci->book_param[r->groupbook]=res->book_aux_managed;
  140570. for(i=0;i<r->partitions;i++){
  140571. for(k=0;k<3;k++){
  140572. if(res->books_base_managed->books[i][k]){
  140573. int bookid=book_dup_or_new(ci,res->books_base_managed->books[i][k]);
  140574. r->booklist[booklist++]=bookid;
  140575. ci->book_param[bookid]=res->books_base_managed->books[i][k];
  140576. }
  140577. }
  140578. }
  140579. }else{
  140580. for(i=0;i<r->partitions;i++)
  140581. for(k=0;k<3;k++)
  140582. if(res->books_base->books[i][k])
  140583. r->secondstages[i]|=(1<<k);
  140584. r->groupbook=book_dup_or_new(ci,res->book_aux);
  140585. ci->book_param[r->groupbook]=res->book_aux;
  140586. for(i=0;i<r->partitions;i++){
  140587. for(k=0;k<3;k++){
  140588. if(res->books_base->books[i][k]){
  140589. int bookid=book_dup_or_new(ci,res->books_base->books[i][k]);
  140590. r->booklist[booklist++]=bookid;
  140591. ci->book_param[bookid]=res->books_base->books[i][k];
  140592. }
  140593. }
  140594. }
  140595. }
  140596. }
  140597. {
  140598. double freq=ci->hi.lowpass_kHz*1000.;
  140599. vorbis_info_floor1 *f=(vorbis_info_floor1*)ci->floor_param[block]; /* by convention */
  140600. double nyq=vi->rate/2.;
  140601. long blocksize=ci->blocksizes[block]>>1;
  140602. if(freq>nyq)freq=nyq;
  140603. f->n=freq/nyq*blocksize;
  140604. if(res->limit_type){
  140605. if(ci->hi.managed)
  140606. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS-1]*1000.;
  140607. else
  140608. freq=ci->psy_g_param.coupling_pkHz[PACKETBLOBS/2]*1000.;
  140609. if(freq>nyq)freq=nyq;
  140610. }
  140611. if(ci->residue_type[block]==2)
  140612. r->end=(int)((freq/nyq*blocksize*2)/r->grouping+.9)* /* round up only if we're well past */
  140613. r->grouping;
  140614. else
  140615. r->end=(int)((freq/nyq*blocksize)/r->grouping+.9)* /* round up only if we're well past */
  140616. r->grouping;
  140617. }
  140618. }
  140619. static void vorbis_encode_map_n_res_setup(vorbis_info *vi,double s,
  140620. vorbis_mapping_template *maps){
  140621. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140622. int i,j,is=s,modes=2;
  140623. vorbis_info_mapping0 *map=maps[is].map;
  140624. vorbis_info_mode *mode=_mode_template;
  140625. vorbis_residue_template *res=maps[is].res;
  140626. if(ci->blocksizes[0]==ci->blocksizes[1])modes=1;
  140627. for(i=0;i<modes;i++){
  140628. ci->map_param[i]=_ogg_calloc(1,sizeof(*map));
  140629. ci->mode_param[i]=(vorbis_info_mode*)_ogg_calloc(1,sizeof(*mode));
  140630. memcpy(ci->mode_param[i],mode+i,sizeof(*_mode_template));
  140631. if(i>=ci->modes)ci->modes=i+1;
  140632. ci->map_type[i]=0;
  140633. memcpy(ci->map_param[i],map+i,sizeof(*map));
  140634. if(i>=ci->maps)ci->maps=i+1;
  140635. for(j=0;j<map[i].submaps;j++)
  140636. vorbis_encode_residue_setup(vi,map[i].residuesubmap[j],i
  140637. ,res+map[i].residuesubmap[j]);
  140638. }
  140639. }
  140640. static double setting_to_approx_bitrate(vorbis_info *vi){
  140641. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140642. highlevel_encode_setup *hi=&ci->hi;
  140643. ve_setup_data_template *setup=(ve_setup_data_template *)hi->setup;
  140644. int is=hi->base_setting;
  140645. double ds=hi->base_setting-is;
  140646. int ch=vi->channels;
  140647. double *r=setup->rate_mapping;
  140648. if(r==NULL)
  140649. return(-1);
  140650. return((r[is]*(1.-ds)+r[is+1]*ds)*ch);
  140651. }
  140652. static void get_setup_template(vorbis_info *vi,
  140653. long ch,long srate,
  140654. double req,int q_or_bitrate){
  140655. int i=0,j;
  140656. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140657. highlevel_encode_setup *hi=&ci->hi;
  140658. if(q_or_bitrate)req/=ch;
  140659. while(setup_list[i]){
  140660. if(setup_list[i]->coupling_restriction==-1 ||
  140661. setup_list[i]->coupling_restriction==ch){
  140662. if(srate>=setup_list[i]->samplerate_min_restriction &&
  140663. srate<=setup_list[i]->samplerate_max_restriction){
  140664. int mappings=setup_list[i]->mappings;
  140665. double *map=(q_or_bitrate?
  140666. setup_list[i]->rate_mapping:
  140667. setup_list[i]->quality_mapping);
  140668. if(req<map[0]){++i;continue;}
  140669. if(req>map[setup_list[i]->mappings]){++i;continue;}
  140670. for(j=0;j<mappings;j++)
  140671. if(req>=map[j] && req<map[j+1])break;
  140672. hi->setup=setup_list[i];
  140673. if(j==mappings)
  140674. hi->base_setting=j-.001;
  140675. else{
  140676. float low=map[j];
  140677. float high=map[j+1];
  140678. float del=(req-low)/(high-low);
  140679. hi->base_setting=j+del;
  140680. }
  140681. return;
  140682. }
  140683. }
  140684. i++;
  140685. }
  140686. hi->setup=NULL;
  140687. }
  140688. int vorbis_encode_setup_init(vorbis_info *vi){
  140689. int i0=0,singleblock=0;
  140690. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140691. ve_setup_data_template *setup=NULL;
  140692. highlevel_encode_setup *hi=&ci->hi;
  140693. if(ci==NULL)return(OV_EINVAL);
  140694. if(!hi->impulse_block_p)i0=1;
  140695. if(hi->ath_floating_dB>-80)hi->ath_floating_dB=-80;
  140696. if(hi->ath_floating_dB<-200)hi->ath_floating_dB=-200;
  140697. if(hi->amplitude_track_dBpersec>0.)hi->amplitude_track_dBpersec=0.;
  140698. if(hi->amplitude_track_dBpersec<-99999.)hi->amplitude_track_dBpersec=-99999.;
  140699. setup=(ve_setup_data_template *)hi->setup;
  140700. if(setup==NULL)return(OV_EINVAL);
  140701. hi->set_in_stone=1;
  140702. vorbis_encode_blocksize_setup(vi,hi->base_setting,
  140703. setup->blocksize_short,
  140704. setup->blocksize_long);
  140705. if(ci->blocksizes[0]==ci->blocksizes[1])singleblock=1;
  140706. vorbis_encode_floor_setup(vi,hi->short_setting,0,
  140707. setup->floor_books,
  140708. setup->floor_params,
  140709. setup->floor_short_mapping);
  140710. if(!singleblock)
  140711. vorbis_encode_floor_setup(vi,hi->long_setting,1,
  140712. setup->floor_books,
  140713. setup->floor_params,
  140714. setup->floor_long_mapping);
  140715. vorbis_encode_global_psych_setup(vi,hi->trigger_setting,
  140716. setup->global_params,
  140717. setup->global_mapping);
  140718. vorbis_encode_global_stereo(vi,hi,setup->stereo_modes);
  140719. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140720. setup->psy_noise_normal_start[0],
  140721. setup->psy_noise_normal_partition[0],
  140722. setup->psy_noise_normal_thresh,
  140723. 0);
  140724. vorbis_encode_psyset_setup(vi,hi->short_setting,
  140725. setup->psy_noise_normal_start[0],
  140726. setup->psy_noise_normal_partition[0],
  140727. setup->psy_noise_normal_thresh,
  140728. 1);
  140729. if(!singleblock){
  140730. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140731. setup->psy_noise_normal_start[1],
  140732. setup->psy_noise_normal_partition[1],
  140733. setup->psy_noise_normal_thresh,
  140734. 2);
  140735. vorbis_encode_psyset_setup(vi,hi->long_setting,
  140736. setup->psy_noise_normal_start[1],
  140737. setup->psy_noise_normal_partition[1],
  140738. setup->psy_noise_normal_thresh,
  140739. 3);
  140740. }
  140741. vorbis_encode_tonemask_setup(vi,hi->block[i0].tone_mask_setting,0,
  140742. setup->psy_tone_masteratt,
  140743. setup->psy_tone_0dB,
  140744. setup->psy_tone_adj_impulse);
  140745. vorbis_encode_tonemask_setup(vi,hi->block[1].tone_mask_setting,1,
  140746. setup->psy_tone_masteratt,
  140747. setup->psy_tone_0dB,
  140748. setup->psy_tone_adj_other);
  140749. if(!singleblock){
  140750. vorbis_encode_tonemask_setup(vi,hi->block[2].tone_mask_setting,2,
  140751. setup->psy_tone_masteratt,
  140752. setup->psy_tone_0dB,
  140753. setup->psy_tone_adj_other);
  140754. vorbis_encode_tonemask_setup(vi,hi->block[3].tone_mask_setting,3,
  140755. setup->psy_tone_masteratt,
  140756. setup->psy_tone_0dB,
  140757. setup->psy_tone_adj_long);
  140758. }
  140759. vorbis_encode_compand_setup(vi,hi->block[i0].noise_compand_setting,0,
  140760. setup->psy_noise_compand,
  140761. setup->psy_noise_compand_short_mapping);
  140762. vorbis_encode_compand_setup(vi,hi->block[1].noise_compand_setting,1,
  140763. setup->psy_noise_compand,
  140764. setup->psy_noise_compand_short_mapping);
  140765. if(!singleblock){
  140766. vorbis_encode_compand_setup(vi,hi->block[2].noise_compand_setting,2,
  140767. setup->psy_noise_compand,
  140768. setup->psy_noise_compand_long_mapping);
  140769. vorbis_encode_compand_setup(vi,hi->block[3].noise_compand_setting,3,
  140770. setup->psy_noise_compand,
  140771. setup->psy_noise_compand_long_mapping);
  140772. }
  140773. vorbis_encode_peak_setup(vi,hi->block[i0].tone_peaklimit_setting,0,
  140774. setup->psy_tone_dBsuppress);
  140775. vorbis_encode_peak_setup(vi,hi->block[1].tone_peaklimit_setting,1,
  140776. setup->psy_tone_dBsuppress);
  140777. if(!singleblock){
  140778. vorbis_encode_peak_setup(vi,hi->block[2].tone_peaklimit_setting,2,
  140779. setup->psy_tone_dBsuppress);
  140780. vorbis_encode_peak_setup(vi,hi->block[3].tone_peaklimit_setting,3,
  140781. setup->psy_tone_dBsuppress);
  140782. }
  140783. vorbis_encode_noisebias_setup(vi,hi->block[i0].noise_bias_setting,0,
  140784. setup->psy_noise_dBsuppress,
  140785. setup->psy_noise_bias_impulse,
  140786. setup->psy_noiseguards,
  140787. (i0==0?hi->impulse_noisetune:0.));
  140788. vorbis_encode_noisebias_setup(vi,hi->block[1].noise_bias_setting,1,
  140789. setup->psy_noise_dBsuppress,
  140790. setup->psy_noise_bias_padding,
  140791. setup->psy_noiseguards,0.);
  140792. if(!singleblock){
  140793. vorbis_encode_noisebias_setup(vi,hi->block[2].noise_bias_setting,2,
  140794. setup->psy_noise_dBsuppress,
  140795. setup->psy_noise_bias_trans,
  140796. setup->psy_noiseguards,0.);
  140797. vorbis_encode_noisebias_setup(vi,hi->block[3].noise_bias_setting,3,
  140798. setup->psy_noise_dBsuppress,
  140799. setup->psy_noise_bias_long,
  140800. setup->psy_noiseguards,0.);
  140801. }
  140802. vorbis_encode_ath_setup(vi,0);
  140803. vorbis_encode_ath_setup(vi,1);
  140804. if(!singleblock){
  140805. vorbis_encode_ath_setup(vi,2);
  140806. vorbis_encode_ath_setup(vi,3);
  140807. }
  140808. vorbis_encode_map_n_res_setup(vi,hi->base_setting,setup->maps);
  140809. if(hi->bitrate_av>0)
  140810. vi->bitrate_nominal=hi->bitrate_av;
  140811. else{
  140812. vi->bitrate_nominal=setting_to_approx_bitrate(vi);
  140813. }
  140814. vi->bitrate_lower=hi->bitrate_min;
  140815. vi->bitrate_upper=hi->bitrate_max;
  140816. if(hi->bitrate_av)
  140817. vi->bitrate_window=(double)hi->bitrate_reservoir/hi->bitrate_av;
  140818. else
  140819. vi->bitrate_window=0.;
  140820. if(hi->managed){
  140821. ci->bi.avg_rate=hi->bitrate_av;
  140822. ci->bi.min_rate=hi->bitrate_min;
  140823. ci->bi.max_rate=hi->bitrate_max;
  140824. ci->bi.reservoir_bits=hi->bitrate_reservoir;
  140825. ci->bi.reservoir_bias=
  140826. hi->bitrate_reservoir_bias;
  140827. ci->bi.slew_damp=hi->bitrate_av_damp;
  140828. }
  140829. return(0);
  140830. }
  140831. static int vorbis_encode_setup_setting(vorbis_info *vi,
  140832. long channels,
  140833. long rate){
  140834. int ret=0,i,is;
  140835. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140836. highlevel_encode_setup *hi=&ci->hi;
  140837. ve_setup_data_template *setup=(ve_setup_data_template*) hi->setup;
  140838. double ds;
  140839. ret=vorbis_encode_toplevel_setup(vi,channels,rate);
  140840. if(ret)return(ret);
  140841. is=hi->base_setting;
  140842. ds=hi->base_setting-is;
  140843. hi->short_setting=hi->base_setting;
  140844. hi->long_setting=hi->base_setting;
  140845. hi->managed=0;
  140846. hi->impulse_block_p=1;
  140847. hi->noise_normalize_p=1;
  140848. hi->stereo_point_setting=hi->base_setting;
  140849. hi->lowpass_kHz=
  140850. setup->psy_lowpass[is]*(1.-ds)+setup->psy_lowpass[is+1]*ds;
  140851. hi->ath_floating_dB=setup->psy_ath_float[is]*(1.-ds)+
  140852. setup->psy_ath_float[is+1]*ds;
  140853. hi->ath_absolute_dB=setup->psy_ath_abs[is]*(1.-ds)+
  140854. setup->psy_ath_abs[is+1]*ds;
  140855. hi->amplitude_track_dBpersec=-6.;
  140856. hi->trigger_setting=hi->base_setting;
  140857. for(i=0;i<4;i++){
  140858. hi->block[i].tone_mask_setting=hi->base_setting;
  140859. hi->block[i].tone_peaklimit_setting=hi->base_setting;
  140860. hi->block[i].noise_bias_setting=hi->base_setting;
  140861. hi->block[i].noise_compand_setting=hi->base_setting;
  140862. }
  140863. return(ret);
  140864. }
  140865. int vorbis_encode_setup_vbr(vorbis_info *vi,
  140866. long channels,
  140867. long rate,
  140868. float quality){
  140869. codec_setup_info *ci=(codec_setup_info*) vi->codec_setup;
  140870. highlevel_encode_setup *hi=&ci->hi;
  140871. quality+=.0000001;
  140872. if(quality>=1.)quality=.9999;
  140873. get_setup_template(vi,channels,rate,quality,0);
  140874. if(!hi->setup)return OV_EIMPL;
  140875. return vorbis_encode_setup_setting(vi,channels,rate);
  140876. }
  140877. int vorbis_encode_init_vbr(vorbis_info *vi,
  140878. long channels,
  140879. long rate,
  140880. float base_quality /* 0. to 1. */
  140881. ){
  140882. int ret=0;
  140883. ret=vorbis_encode_setup_vbr(vi,channels,rate,base_quality);
  140884. if(ret){
  140885. vorbis_info_clear(vi);
  140886. return ret;
  140887. }
  140888. ret=vorbis_encode_setup_init(vi);
  140889. if(ret)
  140890. vorbis_info_clear(vi);
  140891. return(ret);
  140892. }
  140893. int vorbis_encode_setup_managed(vorbis_info *vi,
  140894. long channels,
  140895. long rate,
  140896. long max_bitrate,
  140897. long nominal_bitrate,
  140898. long min_bitrate){
  140899. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140900. highlevel_encode_setup *hi=&ci->hi;
  140901. double tnominal=nominal_bitrate;
  140902. int ret=0;
  140903. if(nominal_bitrate<=0.){
  140904. if(max_bitrate>0.){
  140905. if(min_bitrate>0.)
  140906. nominal_bitrate=(max_bitrate+min_bitrate)*.5;
  140907. else
  140908. nominal_bitrate=max_bitrate*.875;
  140909. }else{
  140910. if(min_bitrate>0.){
  140911. nominal_bitrate=min_bitrate;
  140912. }else{
  140913. return(OV_EINVAL);
  140914. }
  140915. }
  140916. }
  140917. get_setup_template(vi,channels,rate,nominal_bitrate,1);
  140918. if(!hi->setup)return OV_EIMPL;
  140919. ret=vorbis_encode_setup_setting(vi,channels,rate);
  140920. if(ret){
  140921. vorbis_info_clear(vi);
  140922. return ret;
  140923. }
  140924. hi->managed=1;
  140925. hi->bitrate_min=min_bitrate;
  140926. hi->bitrate_max=max_bitrate;
  140927. hi->bitrate_av=tnominal;
  140928. hi->bitrate_av_damp=1.5f; /* full range in no less than 1.5 second */
  140929. hi->bitrate_reservoir=nominal_bitrate*2;
  140930. hi->bitrate_reservoir_bias=.1; /* bias toward hoarding bits */
  140931. return(ret);
  140932. }
  140933. int vorbis_encode_init(vorbis_info *vi,
  140934. long channels,
  140935. long rate,
  140936. long max_bitrate,
  140937. long nominal_bitrate,
  140938. long min_bitrate){
  140939. int ret=vorbis_encode_setup_managed(vi,channels,rate,
  140940. max_bitrate,
  140941. nominal_bitrate,
  140942. min_bitrate);
  140943. if(ret){
  140944. vorbis_info_clear(vi);
  140945. return(ret);
  140946. }
  140947. ret=vorbis_encode_setup_init(vi);
  140948. if(ret)
  140949. vorbis_info_clear(vi);
  140950. return(ret);
  140951. }
  140952. int vorbis_encode_ctl(vorbis_info *vi,int number,void *arg){
  140953. if(vi){
  140954. codec_setup_info *ci=(codec_setup_info*)vi->codec_setup;
  140955. highlevel_encode_setup *hi=&ci->hi;
  140956. int setp=(number&0xf); /* a read request has a low nibble of 0 */
  140957. if(setp && hi->set_in_stone)return(OV_EINVAL);
  140958. switch(number){
  140959. case OV_ECTL_RATEMANAGE_GET:
  140960. {
  140961. struct ovectl_ratemanage_arg *ai=
  140962. (struct ovectl_ratemanage_arg *)arg;
  140963. ai->management_active=hi->managed;
  140964. ai->bitrate_hard_window=ai->bitrate_av_window=
  140965. (double)hi->bitrate_reservoir/vi->rate;
  140966. ai->bitrate_av_window_center=1.;
  140967. ai->bitrate_hard_min=hi->bitrate_min;
  140968. ai->bitrate_hard_max=hi->bitrate_max;
  140969. ai->bitrate_av_lo=hi->bitrate_av;
  140970. ai->bitrate_av_hi=hi->bitrate_av;
  140971. }
  140972. return(0);
  140973. case OV_ECTL_RATEMANAGE_SET:
  140974. {
  140975. struct ovectl_ratemanage_arg *ai=
  140976. (struct ovectl_ratemanage_arg *)arg;
  140977. if(ai==NULL){
  140978. hi->managed=0;
  140979. }else{
  140980. hi->managed=ai->management_active;
  140981. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_AVG,arg);
  140982. vorbis_encode_ctl(vi,OV_ECTL_RATEMANAGE_HARD,arg);
  140983. }
  140984. }
  140985. return 0;
  140986. case OV_ECTL_RATEMANAGE_AVG:
  140987. {
  140988. struct ovectl_ratemanage_arg *ai=
  140989. (struct ovectl_ratemanage_arg *)arg;
  140990. if(ai==NULL){
  140991. hi->bitrate_av=0;
  140992. }else{
  140993. hi->bitrate_av=(ai->bitrate_av_lo+ai->bitrate_av_hi)*.5;
  140994. }
  140995. }
  140996. return(0);
  140997. case OV_ECTL_RATEMANAGE_HARD:
  140998. {
  140999. struct ovectl_ratemanage_arg *ai=
  141000. (struct ovectl_ratemanage_arg *)arg;
  141001. if(ai==NULL){
  141002. hi->bitrate_min=0;
  141003. hi->bitrate_max=0;
  141004. }else{
  141005. hi->bitrate_min=ai->bitrate_hard_min;
  141006. hi->bitrate_max=ai->bitrate_hard_max;
  141007. hi->bitrate_reservoir=ai->bitrate_hard_window*
  141008. (hi->bitrate_max+hi->bitrate_min)*.5;
  141009. }
  141010. if(hi->bitrate_reservoir<128.)
  141011. hi->bitrate_reservoir=128.;
  141012. }
  141013. return(0);
  141014. case OV_ECTL_RATEMANAGE2_GET:
  141015. {
  141016. struct ovectl_ratemanage2_arg *ai=
  141017. (struct ovectl_ratemanage2_arg *)arg;
  141018. if(ai==NULL)return OV_EINVAL;
  141019. ai->management_active=hi->managed;
  141020. ai->bitrate_limit_min_kbps=hi->bitrate_min/1000;
  141021. ai->bitrate_limit_max_kbps=hi->bitrate_max/1000;
  141022. ai->bitrate_average_kbps=hi->bitrate_av/1000;
  141023. ai->bitrate_average_damping=hi->bitrate_av_damp;
  141024. ai->bitrate_limit_reservoir_bits=hi->bitrate_reservoir;
  141025. ai->bitrate_limit_reservoir_bias=hi->bitrate_reservoir_bias;
  141026. }
  141027. return (0);
  141028. case OV_ECTL_RATEMANAGE2_SET:
  141029. {
  141030. struct ovectl_ratemanage2_arg *ai=
  141031. (struct ovectl_ratemanage2_arg *)arg;
  141032. if(ai==NULL){
  141033. hi->managed=0;
  141034. }else{
  141035. if(ai->bitrate_limit_min_kbps>0 &&
  141036. ai->bitrate_average_kbps>0 &&
  141037. ai->bitrate_limit_min_kbps>ai->bitrate_average_kbps)
  141038. return OV_EINVAL;
  141039. if(ai->bitrate_limit_max_kbps>0 &&
  141040. ai->bitrate_average_kbps>0 &&
  141041. ai->bitrate_limit_max_kbps<ai->bitrate_average_kbps)
  141042. return OV_EINVAL;
  141043. if(ai->bitrate_limit_min_kbps>0 &&
  141044. ai->bitrate_limit_max_kbps>0 &&
  141045. ai->bitrate_limit_min_kbps>ai->bitrate_limit_max_kbps)
  141046. return OV_EINVAL;
  141047. if(ai->bitrate_average_damping <= 0.)
  141048. return OV_EINVAL;
  141049. if(ai->bitrate_limit_reservoir_bits < 0)
  141050. return OV_EINVAL;
  141051. if(ai->bitrate_limit_reservoir_bias < 0.)
  141052. return OV_EINVAL;
  141053. if(ai->bitrate_limit_reservoir_bias > 1.)
  141054. return OV_EINVAL;
  141055. hi->managed=ai->management_active;
  141056. hi->bitrate_min=ai->bitrate_limit_min_kbps * 1000;
  141057. hi->bitrate_max=ai->bitrate_limit_max_kbps * 1000;
  141058. hi->bitrate_av=ai->bitrate_average_kbps * 1000;
  141059. hi->bitrate_av_damp=ai->bitrate_average_damping;
  141060. hi->bitrate_reservoir=ai->bitrate_limit_reservoir_bits;
  141061. hi->bitrate_reservoir_bias=ai->bitrate_limit_reservoir_bias;
  141062. }
  141063. }
  141064. return 0;
  141065. case OV_ECTL_LOWPASS_GET:
  141066. {
  141067. double *farg=(double *)arg;
  141068. *farg=hi->lowpass_kHz;
  141069. }
  141070. return(0);
  141071. case OV_ECTL_LOWPASS_SET:
  141072. {
  141073. double *farg=(double *)arg;
  141074. hi->lowpass_kHz=*farg;
  141075. if(hi->lowpass_kHz<2.)hi->lowpass_kHz=2.;
  141076. if(hi->lowpass_kHz>99.)hi->lowpass_kHz=99.;
  141077. }
  141078. return(0);
  141079. case OV_ECTL_IBLOCK_GET:
  141080. {
  141081. double *farg=(double *)arg;
  141082. *farg=hi->impulse_noisetune;
  141083. }
  141084. return(0);
  141085. case OV_ECTL_IBLOCK_SET:
  141086. {
  141087. double *farg=(double *)arg;
  141088. hi->impulse_noisetune=*farg;
  141089. if(hi->impulse_noisetune>0.)hi->impulse_noisetune=0.;
  141090. if(hi->impulse_noisetune<-15.)hi->impulse_noisetune=-15.;
  141091. }
  141092. return(0);
  141093. }
  141094. return(OV_EIMPL);
  141095. }
  141096. return(OV_EINVAL);
  141097. }
  141098. #endif
  141099. /*** End of inlined file: vorbisenc.c ***/
  141100. /*** Start of inlined file: vorbisfile.c ***/
  141101. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  141102. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  141103. // tasks..
  141104. #if JUCE_MSVC
  141105. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  141106. #endif
  141107. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  141108. #if JUCE_USE_OGGVORBIS
  141109. #include <stdlib.h>
  141110. #include <stdio.h>
  141111. #include <errno.h>
  141112. #include <string.h>
  141113. #include <math.h>
  141114. #define CHUNKSIZE 8500 /* a shade over 8k; anyone using pages well
  141115. over 8k gets what they deserve */
  141116. static long _get_data(OggVorbis_File *vf){
  141117. errno=0;
  141118. if(vf->datasource){
  141119. char *buffer=ogg_sync_buffer(&vf->oy,CHUNKSIZE);
  141120. long bytes=(vf->callbacks.read_func)(buffer,1,CHUNKSIZE,vf->datasource);
  141121. if(bytes>0)ogg_sync_wrote(&vf->oy,bytes);
  141122. if(bytes==0 && errno)return(-1);
  141123. return(bytes);
  141124. }else
  141125. return(0);
  141126. }
  141127. static void _seek_helper(OggVorbis_File *vf,ogg_int64_t offset){
  141128. if(vf->datasource){
  141129. (vf->callbacks.seek_func)(vf->datasource, offset, SEEK_SET);
  141130. vf->offset=offset;
  141131. ogg_sync_reset(&vf->oy);
  141132. }else{
  141133. return;
  141134. }
  141135. }
  141136. static ogg_int64_t _get_next_page(OggVorbis_File *vf,ogg_page *og,
  141137. ogg_int64_t boundary){
  141138. if(boundary>0)boundary+=vf->offset;
  141139. while(1){
  141140. long more;
  141141. if(boundary>0 && vf->offset>=boundary)return(OV_FALSE);
  141142. more=ogg_sync_pageseek(&vf->oy,og);
  141143. if(more<0){
  141144. vf->offset-=more;
  141145. }else{
  141146. if(more==0){
  141147. if(!boundary)return(OV_FALSE);
  141148. {
  141149. long ret=_get_data(vf);
  141150. if(ret==0)return(OV_EOF);
  141151. if(ret<0)return(OV_EREAD);
  141152. }
  141153. }else{
  141154. ogg_int64_t ret=vf->offset;
  141155. vf->offset+=more;
  141156. return(ret);
  141157. }
  141158. }
  141159. }
  141160. }
  141161. static ogg_int64_t _get_prev_page(OggVorbis_File *vf,ogg_page *og){
  141162. ogg_int64_t begin=vf->offset;
  141163. ogg_int64_t end=begin;
  141164. ogg_int64_t ret;
  141165. ogg_int64_t offset=-1;
  141166. while(offset==-1){
  141167. begin-=CHUNKSIZE;
  141168. if(begin<0)
  141169. begin=0;
  141170. _seek_helper(vf,begin);
  141171. while(vf->offset<end){
  141172. ret=_get_next_page(vf,og,end-vf->offset);
  141173. if(ret==OV_EREAD)return(OV_EREAD);
  141174. if(ret<0){
  141175. break;
  141176. }else{
  141177. offset=ret;
  141178. }
  141179. }
  141180. }
  141181. _seek_helper(vf,offset);
  141182. ret=_get_next_page(vf,og,CHUNKSIZE);
  141183. if(ret<0)
  141184. return(OV_EFAULT);
  141185. return(offset);
  141186. }
  141187. static int _bisect_forward_serialno(OggVorbis_File *vf,
  141188. ogg_int64_t begin,
  141189. ogg_int64_t searched,
  141190. ogg_int64_t end,
  141191. long currentno,
  141192. long m){
  141193. ogg_int64_t endsearched=end;
  141194. ogg_int64_t next=end;
  141195. ogg_page og;
  141196. ogg_int64_t ret;
  141197. while(searched<endsearched){
  141198. ogg_int64_t bisect;
  141199. if(endsearched-searched<CHUNKSIZE){
  141200. bisect=searched;
  141201. }else{
  141202. bisect=(searched+endsearched)/2;
  141203. }
  141204. _seek_helper(vf,bisect);
  141205. ret=_get_next_page(vf,&og,-1);
  141206. if(ret==OV_EREAD)return(OV_EREAD);
  141207. if(ret<0 || ogg_page_serialno(&og)!=currentno){
  141208. endsearched=bisect;
  141209. if(ret>=0)next=ret;
  141210. }else{
  141211. searched=ret+og.header_len+og.body_len;
  141212. }
  141213. }
  141214. _seek_helper(vf,next);
  141215. ret=_get_next_page(vf,&og,-1);
  141216. if(ret==OV_EREAD)return(OV_EREAD);
  141217. if(searched>=end || ret<0){
  141218. vf->links=m+1;
  141219. vf->offsets=(ogg_int64_t*)_ogg_malloc((vf->links+1)*sizeof(*vf->offsets));
  141220. vf->serialnos=(long*)_ogg_malloc(vf->links*sizeof(*vf->serialnos));
  141221. vf->offsets[m+1]=searched;
  141222. }else{
  141223. ret=_bisect_forward_serialno(vf,next,vf->offset,
  141224. end,ogg_page_serialno(&og),m+1);
  141225. if(ret==OV_EREAD)return(OV_EREAD);
  141226. }
  141227. vf->offsets[m]=begin;
  141228. vf->serialnos[m]=currentno;
  141229. return(0);
  141230. }
  141231. static int _fetch_headers(OggVorbis_File *vf,vorbis_info *vi,vorbis_comment *vc,
  141232. long *serialno,ogg_page *og_ptr){
  141233. ogg_page og;
  141234. ogg_packet op;
  141235. int i,ret;
  141236. if(!og_ptr){
  141237. ogg_int64_t llret=_get_next_page(vf,&og,CHUNKSIZE);
  141238. if(llret==OV_EREAD)return(OV_EREAD);
  141239. if(llret<0)return OV_ENOTVORBIS;
  141240. og_ptr=&og;
  141241. }
  141242. ogg_stream_reset_serialno(&vf->os,ogg_page_serialno(og_ptr));
  141243. if(serialno)*serialno=vf->os.serialno;
  141244. vf->ready_state=STREAMSET;
  141245. vorbis_info_init(vi);
  141246. vorbis_comment_init(vc);
  141247. i=0;
  141248. while(i<3){
  141249. ogg_stream_pagein(&vf->os,og_ptr);
  141250. while(i<3){
  141251. int result=ogg_stream_packetout(&vf->os,&op);
  141252. if(result==0)break;
  141253. if(result==-1){
  141254. ret=OV_EBADHEADER;
  141255. goto bail_header;
  141256. }
  141257. if((ret=vorbis_synthesis_headerin(vi,vc,&op))){
  141258. goto bail_header;
  141259. }
  141260. i++;
  141261. }
  141262. if(i<3)
  141263. if(_get_next_page(vf,og_ptr,CHUNKSIZE)<0){
  141264. ret=OV_EBADHEADER;
  141265. goto bail_header;
  141266. }
  141267. }
  141268. return 0;
  141269. bail_header:
  141270. vorbis_info_clear(vi);
  141271. vorbis_comment_clear(vc);
  141272. vf->ready_state=OPENED;
  141273. return ret;
  141274. }
  141275. static void _prefetch_all_headers(OggVorbis_File *vf, ogg_int64_t dataoffset){
  141276. ogg_page og;
  141277. int i;
  141278. ogg_int64_t ret;
  141279. vf->vi=(vorbis_info*) _ogg_realloc(vf->vi,vf->links*sizeof(*vf->vi));
  141280. vf->vc=(vorbis_comment*) _ogg_realloc(vf->vc,vf->links*sizeof(*vf->vc));
  141281. vf->dataoffsets=(ogg_int64_t*) _ogg_malloc(vf->links*sizeof(*vf->dataoffsets));
  141282. vf->pcmlengths=(ogg_int64_t*) _ogg_malloc(vf->links*2*sizeof(*vf->pcmlengths));
  141283. for(i=0;i<vf->links;i++){
  141284. if(i==0){
  141285. vf->dataoffsets[i]=dataoffset;
  141286. _seek_helper(vf,dataoffset);
  141287. }else{
  141288. _seek_helper(vf,vf->offsets[i]);
  141289. if(_fetch_headers(vf,vf->vi+i,vf->vc+i,NULL,NULL)<0){
  141290. vf->dataoffsets[i]=-1;
  141291. }else{
  141292. vf->dataoffsets[i]=vf->offset;
  141293. }
  141294. }
  141295. if(vf->dataoffsets[i]!=-1){
  141296. ogg_int64_t accumulated=0;
  141297. long lastblock=-1;
  141298. int result;
  141299. ogg_stream_reset_serialno(&vf->os,vf->serialnos[i]);
  141300. while(1){
  141301. ogg_packet op;
  141302. ret=_get_next_page(vf,&og,-1);
  141303. if(ret<0)
  141304. break;
  141305. if(ogg_page_serialno(&og)!=vf->serialnos[i])
  141306. break;
  141307. ogg_stream_pagein(&vf->os,&og);
  141308. while((result=ogg_stream_packetout(&vf->os,&op))){
  141309. if(result>0){ /* ignore holes */
  141310. long thisblock=vorbis_packet_blocksize(vf->vi+i,&op);
  141311. if(lastblock!=-1)
  141312. accumulated+=(lastblock+thisblock)>>2;
  141313. lastblock=thisblock;
  141314. }
  141315. }
  141316. if(ogg_page_granulepos(&og)!=-1){
  141317. accumulated= ogg_page_granulepos(&og)-accumulated;
  141318. break;
  141319. }
  141320. }
  141321. if(accumulated<0)accumulated=0;
  141322. vf->pcmlengths[i*2]=accumulated;
  141323. }
  141324. {
  141325. ogg_int64_t end=vf->offsets[i+1];
  141326. _seek_helper(vf,end);
  141327. while(1){
  141328. ret=_get_prev_page(vf,&og);
  141329. if(ret<0){
  141330. vorbis_info_clear(vf->vi+i);
  141331. vorbis_comment_clear(vf->vc+i);
  141332. break;
  141333. }
  141334. if(ogg_page_granulepos(&og)!=-1){
  141335. vf->pcmlengths[i*2+1]=ogg_page_granulepos(&og)-vf->pcmlengths[i*2];
  141336. break;
  141337. }
  141338. vf->offset=ret;
  141339. }
  141340. }
  141341. }
  141342. }
  141343. static int _make_decode_ready(OggVorbis_File *vf){
  141344. if(vf->ready_state>STREAMSET)return 0;
  141345. if(vf->ready_state<STREAMSET)return OV_EFAULT;
  141346. if(vf->seekable){
  141347. if(vorbis_synthesis_init(&vf->vd,vf->vi+vf->current_link))
  141348. return OV_EBADLINK;
  141349. }else{
  141350. if(vorbis_synthesis_init(&vf->vd,vf->vi))
  141351. return OV_EBADLINK;
  141352. }
  141353. vorbis_block_init(&vf->vd,&vf->vb);
  141354. vf->ready_state=INITSET;
  141355. vf->bittrack=0.f;
  141356. vf->samptrack=0.f;
  141357. return 0;
  141358. }
  141359. static int _open_seekable2(OggVorbis_File *vf){
  141360. long serialno=vf->current_serialno;
  141361. ogg_int64_t dataoffset=vf->offset, end;
  141362. ogg_page og;
  141363. (vf->callbacks.seek_func)(vf->datasource,0,SEEK_END);
  141364. vf->offset=vf->end=(vf->callbacks.tell_func)(vf->datasource);
  141365. end=_get_prev_page(vf,&og);
  141366. if(end<0)return(end);
  141367. if(ogg_page_serialno(&og)!=serialno){
  141368. if(_bisect_forward_serialno(vf,0,0,end+1,serialno,0)<0)return(OV_EREAD);
  141369. }else{
  141370. if(_bisect_forward_serialno(vf,0,end,end+1,serialno,0))return(OV_EREAD);
  141371. }
  141372. _prefetch_all_headers(vf,dataoffset);
  141373. return(ov_raw_seek(vf,0));
  141374. }
  141375. static void _decode_clear(OggVorbis_File *vf){
  141376. vorbis_dsp_clear(&vf->vd);
  141377. vorbis_block_clear(&vf->vb);
  141378. vf->ready_state=OPENED;
  141379. }
  141380. static int _fetch_and_process_packet(OggVorbis_File *vf,
  141381. ogg_packet *op_in,
  141382. int readp,
  141383. int spanp){
  141384. ogg_page og;
  141385. while(1){
  141386. if(vf->ready_state==INITSET){
  141387. while(1) {
  141388. ogg_packet op;
  141389. ogg_packet *op_ptr=(op_in?op_in:&op);
  141390. int result=ogg_stream_packetout(&vf->os,op_ptr);
  141391. ogg_int64_t granulepos;
  141392. op_in=NULL;
  141393. if(result==-1)return(OV_HOLE); /* hole in the data. */
  141394. if(result>0){
  141395. granulepos=op_ptr->granulepos;
  141396. if(!vorbis_synthesis(&vf->vb,op_ptr)){ /* lazy check for lazy
  141397. header handling. The
  141398. header packets aren't
  141399. audio, so if/when we
  141400. submit them,
  141401. vorbis_synthesis will
  141402. reject them */
  141403. {
  141404. int oldsamples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141405. if(oldsamples)return(OV_EFAULT);
  141406. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141407. vf->samptrack+=vorbis_synthesis_pcmout(&vf->vd,NULL)-oldsamples;
  141408. vf->bittrack+=op_ptr->bytes*8;
  141409. }
  141410. if(granulepos!=-1 && !op_ptr->e_o_s){
  141411. int link=(vf->seekable?vf->current_link:0);
  141412. int i,samples;
  141413. if(vf->seekable && link>0)
  141414. granulepos-=vf->pcmlengths[link*2];
  141415. if(granulepos<0)granulepos=0; /* actually, this
  141416. shouldn't be possible
  141417. here unless the stream
  141418. is very broken */
  141419. samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141420. granulepos-=samples;
  141421. for(i=0;i<link;i++)
  141422. granulepos+=vf->pcmlengths[i*2+1];
  141423. vf->pcm_offset=granulepos;
  141424. }
  141425. return(1);
  141426. }
  141427. }
  141428. else
  141429. break;
  141430. }
  141431. }
  141432. if(vf->ready_state>=OPENED){
  141433. ogg_int64_t ret;
  141434. if(!readp)return(0);
  141435. if((ret=_get_next_page(vf,&og,-1))<0){
  141436. return(OV_EOF); /* eof.
  141437. leave unitialized */
  141438. }
  141439. vf->bittrack+=og.header_len*8;
  141440. if(vf->ready_state==INITSET){
  141441. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141442. if(!spanp)
  141443. return(OV_EOF);
  141444. _decode_clear(vf);
  141445. if(!vf->seekable){
  141446. vorbis_info_clear(vf->vi);
  141447. vorbis_comment_clear(vf->vc);
  141448. }
  141449. }
  141450. }
  141451. }
  141452. if(vf->ready_state!=INITSET){
  141453. int link;
  141454. if(vf->ready_state<STREAMSET){
  141455. if(vf->seekable){
  141456. vf->current_serialno=ogg_page_serialno(&og);
  141457. for(link=0;link<vf->links;link++)
  141458. if(vf->serialnos[link]==vf->current_serialno)break;
  141459. if(link==vf->links)return(OV_EBADLINK); /* sign of a bogus
  141460. stream. error out,
  141461. leave machine
  141462. uninitialized */
  141463. vf->current_link=link;
  141464. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141465. vf->ready_state=STREAMSET;
  141466. }else{
  141467. int ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,&og);
  141468. if(ret)return(ret);
  141469. vf->current_link++;
  141470. link=0;
  141471. }
  141472. }
  141473. {
  141474. int ret=_make_decode_ready(vf);
  141475. if(ret<0)return ret;
  141476. }
  141477. }
  141478. ogg_stream_pagein(&vf->os,&og);
  141479. }
  141480. }
  141481. static int _fseek64_wrap(FILE *f,ogg_int64_t off,int whence){
  141482. if(f==NULL)return(-1);
  141483. return fseek(f,off,whence);
  141484. }
  141485. static int _ov_open1(void *f,OggVorbis_File *vf,char *initial,
  141486. long ibytes, ov_callbacks callbacks){
  141487. int offsettest=(f?callbacks.seek_func(f,0,SEEK_CUR):-1);
  141488. int ret;
  141489. memset(vf,0,sizeof(*vf));
  141490. vf->datasource=f;
  141491. vf->callbacks = callbacks;
  141492. ogg_sync_init(&vf->oy);
  141493. if(initial){
  141494. char *buffer=ogg_sync_buffer(&vf->oy,ibytes);
  141495. memcpy(buffer,initial,ibytes);
  141496. ogg_sync_wrote(&vf->oy,ibytes);
  141497. }
  141498. if(offsettest!=-1)vf->seekable=1;
  141499. vf->links=1;
  141500. vf->vi=(vorbis_info*) _ogg_calloc(vf->links,sizeof(*vf->vi));
  141501. vf->vc=(vorbis_comment*) _ogg_calloc(vf->links,sizeof(*vf->vc));
  141502. ogg_stream_init(&vf->os,-1); /* fill in the serialno later */
  141503. if((ret=_fetch_headers(vf,vf->vi,vf->vc,&vf->current_serialno,NULL))<0){
  141504. vf->datasource=NULL;
  141505. ov_clear(vf);
  141506. }else
  141507. vf->ready_state=PARTOPEN;
  141508. return(ret);
  141509. }
  141510. static int _ov_open2(OggVorbis_File *vf){
  141511. if(vf->ready_state != PARTOPEN) return OV_EINVAL;
  141512. vf->ready_state=OPENED;
  141513. if(vf->seekable){
  141514. int ret=_open_seekable2(vf);
  141515. if(ret){
  141516. vf->datasource=NULL;
  141517. ov_clear(vf);
  141518. }
  141519. return(ret);
  141520. }else
  141521. vf->ready_state=STREAMSET;
  141522. return 0;
  141523. }
  141524. int ov_clear(OggVorbis_File *vf){
  141525. if(vf){
  141526. vorbis_block_clear(&vf->vb);
  141527. vorbis_dsp_clear(&vf->vd);
  141528. ogg_stream_clear(&vf->os);
  141529. if(vf->vi && vf->links){
  141530. int i;
  141531. for(i=0;i<vf->links;i++){
  141532. vorbis_info_clear(vf->vi+i);
  141533. vorbis_comment_clear(vf->vc+i);
  141534. }
  141535. _ogg_free(vf->vi);
  141536. _ogg_free(vf->vc);
  141537. }
  141538. if(vf->dataoffsets)_ogg_free(vf->dataoffsets);
  141539. if(vf->pcmlengths)_ogg_free(vf->pcmlengths);
  141540. if(vf->serialnos)_ogg_free(vf->serialnos);
  141541. if(vf->offsets)_ogg_free(vf->offsets);
  141542. ogg_sync_clear(&vf->oy);
  141543. if(vf->datasource)(vf->callbacks.close_func)(vf->datasource);
  141544. memset(vf,0,sizeof(*vf));
  141545. }
  141546. #ifdef DEBUG_LEAKS
  141547. _VDBG_dump();
  141548. #endif
  141549. return(0);
  141550. }
  141551. int ov_open_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141552. ov_callbacks callbacks){
  141553. int ret=_ov_open1(f,vf,initial,ibytes,callbacks);
  141554. if(ret)return ret;
  141555. return _ov_open2(vf);
  141556. }
  141557. int ov_open(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141558. ov_callbacks callbacks = {
  141559. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141560. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141561. (int (*)(void *)) fclose,
  141562. (long (*)(void *)) ftell
  141563. };
  141564. return ov_open_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141565. }
  141566. int ov_halfrate(OggVorbis_File *vf,int flag){
  141567. int i;
  141568. if(vf->vi==NULL)return OV_EINVAL;
  141569. if(!vf->seekable)return OV_EINVAL;
  141570. if(vf->ready_state>=STREAMSET)
  141571. _decode_clear(vf); /* clear out stream state; later on libvorbis
  141572. will be able to swap this on the fly, but
  141573. for now dumping the decode machine is needed
  141574. to reinit the MDCT lookups. 1.1 libvorbis
  141575. is planned to be able to switch on the fly */
  141576. for(i=0;i<vf->links;i++){
  141577. if(vorbis_synthesis_halfrate(vf->vi+i,flag)){
  141578. ov_halfrate(vf,0);
  141579. return OV_EINVAL;
  141580. }
  141581. }
  141582. return 0;
  141583. }
  141584. int ov_halfrate_p(OggVorbis_File *vf){
  141585. if(vf->vi==NULL)return OV_EINVAL;
  141586. return vorbis_synthesis_halfrate_p(vf->vi);
  141587. }
  141588. int ov_test_callbacks(void *f,OggVorbis_File *vf,char *initial,long ibytes,
  141589. ov_callbacks callbacks)
  141590. {
  141591. return _ov_open1(f,vf,initial,ibytes,callbacks);
  141592. }
  141593. int ov_test(FILE *f,OggVorbis_File *vf,char *initial,long ibytes){
  141594. ov_callbacks callbacks = {
  141595. (size_t (*)(void *, size_t, size_t, void *)) fread,
  141596. (int (*)(void *, ogg_int64_t, int)) _fseek64_wrap,
  141597. (int (*)(void *)) fclose,
  141598. (long (*)(void *)) ftell
  141599. };
  141600. return ov_test_callbacks((void *)f, vf, initial, ibytes, callbacks);
  141601. }
  141602. int ov_test_open(OggVorbis_File *vf){
  141603. if(vf->ready_state!=PARTOPEN)return(OV_EINVAL);
  141604. return _ov_open2(vf);
  141605. }
  141606. long ov_streams(OggVorbis_File *vf){
  141607. return vf->links;
  141608. }
  141609. long ov_seekable(OggVorbis_File *vf){
  141610. return vf->seekable;
  141611. }
  141612. long ov_bitrate(OggVorbis_File *vf,int i){
  141613. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141614. if(i>=vf->links)return(OV_EINVAL);
  141615. if(!vf->seekable && i!=0)return(ov_bitrate(vf,0));
  141616. if(i<0){
  141617. ogg_int64_t bits=0;
  141618. int i;
  141619. float br;
  141620. for(i=0;i<vf->links;i++)
  141621. bits+=(vf->offsets[i+1]-vf->dataoffsets[i])*8;
  141622. br = bits/ov_time_total(vf,-1);
  141623. return(rint(br));
  141624. }else{
  141625. if(vf->seekable){
  141626. return(rint((vf->offsets[i+1]-vf->dataoffsets[i])*8/ov_time_total(vf,i)));
  141627. }else{
  141628. if(vf->vi[i].bitrate_nominal>0){
  141629. return vf->vi[i].bitrate_nominal;
  141630. }else{
  141631. if(vf->vi[i].bitrate_upper>0){
  141632. if(vf->vi[i].bitrate_lower>0){
  141633. return (vf->vi[i].bitrate_upper+vf->vi[i].bitrate_lower)/2;
  141634. }else{
  141635. return vf->vi[i].bitrate_upper;
  141636. }
  141637. }
  141638. return(OV_FALSE);
  141639. }
  141640. }
  141641. }
  141642. }
  141643. long ov_bitrate_instant(OggVorbis_File *vf){
  141644. int link=(vf->seekable?vf->current_link:0);
  141645. long ret;
  141646. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141647. if(vf->samptrack==0)return(OV_FALSE);
  141648. ret=vf->bittrack/vf->samptrack*vf->vi[link].rate+.5;
  141649. vf->bittrack=0.f;
  141650. vf->samptrack=0.f;
  141651. return(ret);
  141652. }
  141653. long ov_serialnumber(OggVorbis_File *vf,int i){
  141654. if(i>=vf->links)return(ov_serialnumber(vf,vf->links-1));
  141655. if(!vf->seekable && i>=0)return(ov_serialnumber(vf,-1));
  141656. if(i<0){
  141657. return(vf->current_serialno);
  141658. }else{
  141659. return(vf->serialnos[i]);
  141660. }
  141661. }
  141662. ogg_int64_t ov_raw_total(OggVorbis_File *vf,int i){
  141663. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141664. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141665. if(i<0){
  141666. ogg_int64_t acc=0;
  141667. int i;
  141668. for(i=0;i<vf->links;i++)
  141669. acc+=ov_raw_total(vf,i);
  141670. return(acc);
  141671. }else{
  141672. return(vf->offsets[i+1]-vf->offsets[i]);
  141673. }
  141674. }
  141675. ogg_int64_t ov_pcm_total(OggVorbis_File *vf,int i){
  141676. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141677. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141678. if(i<0){
  141679. ogg_int64_t acc=0;
  141680. int i;
  141681. for(i=0;i<vf->links;i++)
  141682. acc+=ov_pcm_total(vf,i);
  141683. return(acc);
  141684. }else{
  141685. return(vf->pcmlengths[i*2+1]);
  141686. }
  141687. }
  141688. double ov_time_total(OggVorbis_File *vf,int i){
  141689. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141690. if(!vf->seekable || i>=vf->links)return(OV_EINVAL);
  141691. if(i<0){
  141692. double acc=0;
  141693. int i;
  141694. for(i=0;i<vf->links;i++)
  141695. acc+=ov_time_total(vf,i);
  141696. return(acc);
  141697. }else{
  141698. return((double)(vf->pcmlengths[i*2+1])/vf->vi[i].rate);
  141699. }
  141700. }
  141701. int ov_raw_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141702. ogg_stream_state work_os;
  141703. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141704. if(!vf->seekable)
  141705. return(OV_ENOSEEK); /* don't dump machine if we can't seek */
  141706. if(pos<0 || pos>vf->end)return(OV_EINVAL);
  141707. vf->pcm_offset=-1;
  141708. ogg_stream_reset_serialno(&vf->os,
  141709. vf->current_serialno); /* must set serialno */
  141710. vorbis_synthesis_restart(&vf->vd);
  141711. _seek_helper(vf,pos);
  141712. {
  141713. ogg_page og;
  141714. ogg_packet op;
  141715. int lastblock=0;
  141716. int accblock=0;
  141717. int thisblock;
  141718. int eosflag;
  141719. ogg_stream_init(&work_os,vf->current_serialno); /* get the memory ready */
  141720. ogg_stream_reset(&work_os); /* eliminate the spurious OV_HOLE
  141721. return from not necessarily
  141722. starting from the beginning */
  141723. while(1){
  141724. if(vf->ready_state>=STREAMSET){
  141725. int result=ogg_stream_packetout(&work_os,&op);
  141726. if(result>0){
  141727. if(vf->vi[vf->current_link].codec_setup){
  141728. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141729. if(thisblock<0){
  141730. ogg_stream_packetout(&vf->os,NULL);
  141731. thisblock=0;
  141732. }else{
  141733. if(eosflag)
  141734. ogg_stream_packetout(&vf->os,NULL);
  141735. else
  141736. if(lastblock)accblock+=(lastblock+thisblock)>>2;
  141737. }
  141738. if(op.granulepos!=-1){
  141739. int i,link=vf->current_link;
  141740. ogg_int64_t granulepos=op.granulepos-vf->pcmlengths[link*2];
  141741. if(granulepos<0)granulepos=0;
  141742. for(i=0;i<link;i++)
  141743. granulepos+=vf->pcmlengths[i*2+1];
  141744. vf->pcm_offset=granulepos-accblock;
  141745. break;
  141746. }
  141747. lastblock=thisblock;
  141748. continue;
  141749. }else
  141750. ogg_stream_packetout(&vf->os,NULL);
  141751. }
  141752. }
  141753. if(!lastblock){
  141754. if(_get_next_page(vf,&og,-1)<0){
  141755. vf->pcm_offset=ov_pcm_total(vf,-1);
  141756. break;
  141757. }
  141758. }else{
  141759. vf->pcm_offset=-1;
  141760. break;
  141761. }
  141762. if(vf->ready_state>=STREAMSET)
  141763. if(vf->current_serialno!=ogg_page_serialno(&og)){
  141764. _decode_clear(vf); /* clear out stream state */
  141765. ogg_stream_clear(&work_os);
  141766. }
  141767. if(vf->ready_state<STREAMSET){
  141768. int link;
  141769. vf->current_serialno=ogg_page_serialno(&og);
  141770. for(link=0;link<vf->links;link++)
  141771. if(vf->serialnos[link]==vf->current_serialno)break;
  141772. if(link==vf->links)goto seek_error; /* sign of a bogus stream.
  141773. error out, leave
  141774. machine uninitialized */
  141775. vf->current_link=link;
  141776. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141777. ogg_stream_reset_serialno(&work_os,vf->current_serialno);
  141778. vf->ready_state=STREAMSET;
  141779. }
  141780. ogg_stream_pagein(&vf->os,&og);
  141781. ogg_stream_pagein(&work_os,&og);
  141782. eosflag=ogg_page_eos(&og);
  141783. }
  141784. }
  141785. ogg_stream_clear(&work_os);
  141786. vf->bittrack=0.f;
  141787. vf->samptrack=0.f;
  141788. return(0);
  141789. seek_error:
  141790. vf->pcm_offset=-1;
  141791. ogg_stream_clear(&work_os);
  141792. _decode_clear(vf);
  141793. return OV_EBADLINK;
  141794. }
  141795. int ov_pcm_seek_page(OggVorbis_File *vf,ogg_int64_t pos){
  141796. int link=-1;
  141797. ogg_int64_t result=0;
  141798. ogg_int64_t total=ov_pcm_total(vf,-1);
  141799. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141800. if(!vf->seekable)return(OV_ENOSEEK);
  141801. if(pos<0 || pos>total)return(OV_EINVAL);
  141802. for(link=vf->links-1;link>=0;link--){
  141803. total-=vf->pcmlengths[link*2+1];
  141804. if(pos>=total)break;
  141805. }
  141806. {
  141807. ogg_int64_t end=vf->offsets[link+1];
  141808. ogg_int64_t begin=vf->offsets[link];
  141809. ogg_int64_t begintime = vf->pcmlengths[link*2];
  141810. ogg_int64_t endtime = vf->pcmlengths[link*2+1]+begintime;
  141811. ogg_int64_t target=pos-total+begintime;
  141812. ogg_int64_t best=begin;
  141813. ogg_page og;
  141814. while(begin<end){
  141815. ogg_int64_t bisect;
  141816. if(end-begin<CHUNKSIZE){
  141817. bisect=begin;
  141818. }else{
  141819. bisect=begin +
  141820. (target-begintime)*(end-begin)/(endtime-begintime) - CHUNKSIZE;
  141821. if(bisect<=begin)
  141822. bisect=begin+1;
  141823. }
  141824. _seek_helper(vf,bisect);
  141825. while(begin<end){
  141826. result=_get_next_page(vf,&og,end-vf->offset);
  141827. if(result==OV_EREAD) goto seek_error;
  141828. if(result<0){
  141829. if(bisect<=begin+1)
  141830. end=begin; /* found it */
  141831. else{
  141832. if(bisect==0) goto seek_error;
  141833. bisect-=CHUNKSIZE;
  141834. if(bisect<=begin)bisect=begin+1;
  141835. _seek_helper(vf,bisect);
  141836. }
  141837. }else{
  141838. ogg_int64_t granulepos=ogg_page_granulepos(&og);
  141839. if(granulepos==-1)continue;
  141840. if(granulepos<target){
  141841. best=result; /* raw offset of packet with granulepos */
  141842. begin=vf->offset; /* raw offset of next page */
  141843. begintime=granulepos;
  141844. if(target-begintime>44100)break;
  141845. bisect=begin; /* *not* begin + 1 */
  141846. }else{
  141847. if(bisect<=begin+1)
  141848. end=begin; /* found it */
  141849. else{
  141850. if(end==vf->offset){ /* we're pretty close - we'd be stuck in */
  141851. end=result;
  141852. bisect-=CHUNKSIZE; /* an endless loop otherwise. */
  141853. if(bisect<=begin)bisect=begin+1;
  141854. _seek_helper(vf,bisect);
  141855. }else{
  141856. end=result;
  141857. endtime=granulepos;
  141858. break;
  141859. }
  141860. }
  141861. }
  141862. }
  141863. }
  141864. }
  141865. {
  141866. ogg_page og;
  141867. ogg_packet op;
  141868. _seek_helper(vf,best);
  141869. vf->pcm_offset=-1;
  141870. if(_get_next_page(vf,&og,-1)<0)return(OV_EOF); /* shouldn't happen */
  141871. if(link!=vf->current_link){
  141872. _decode_clear(vf);
  141873. vf->current_link=link;
  141874. vf->current_serialno=ogg_page_serialno(&og);
  141875. vf->ready_state=STREAMSET;
  141876. }else{
  141877. vorbis_synthesis_restart(&vf->vd);
  141878. }
  141879. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141880. ogg_stream_pagein(&vf->os,&og);
  141881. while(1){
  141882. result=ogg_stream_packetpeek(&vf->os,&op);
  141883. if(result==0){
  141884. _seek_helper(vf,best);
  141885. while(1){
  141886. result=_get_prev_page(vf,&og);
  141887. if(result<0) goto seek_error;
  141888. if(ogg_page_granulepos(&og)>-1 ||
  141889. !ogg_page_continued(&og)){
  141890. return ov_raw_seek(vf,result);
  141891. }
  141892. vf->offset=result;
  141893. }
  141894. }
  141895. if(result<0){
  141896. result = OV_EBADPACKET;
  141897. goto seek_error;
  141898. }
  141899. if(op.granulepos!=-1){
  141900. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141901. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141902. vf->pcm_offset+=total;
  141903. break;
  141904. }else
  141905. result=ogg_stream_packetout(&vf->os,NULL);
  141906. }
  141907. }
  141908. }
  141909. if(vf->pcm_offset>pos || pos>ov_pcm_total(vf,-1)){
  141910. result=OV_EFAULT;
  141911. goto seek_error;
  141912. }
  141913. vf->bittrack=0.f;
  141914. vf->samptrack=0.f;
  141915. return(0);
  141916. seek_error:
  141917. vf->pcm_offset=-1;
  141918. _decode_clear(vf);
  141919. return (int)result;
  141920. }
  141921. int ov_pcm_seek(OggVorbis_File *vf,ogg_int64_t pos){
  141922. int thisblock,lastblock=0;
  141923. int ret=ov_pcm_seek_page(vf,pos);
  141924. if(ret<0)return(ret);
  141925. if((ret=_make_decode_ready(vf)))return ret;
  141926. while(1){
  141927. ogg_packet op;
  141928. ogg_page og;
  141929. int ret=ogg_stream_packetpeek(&vf->os,&op);
  141930. if(ret>0){
  141931. thisblock=vorbis_packet_blocksize(vf->vi+vf->current_link,&op);
  141932. if(thisblock<0){
  141933. ogg_stream_packetout(&vf->os,NULL);
  141934. continue; /* non audio packet */
  141935. }
  141936. if(lastblock)vf->pcm_offset+=(lastblock+thisblock)>>2;
  141937. if(vf->pcm_offset+((thisblock+
  141938. vorbis_info_blocksize(vf->vi,1))>>2)>=pos)break;
  141939. ogg_stream_packetout(&vf->os,NULL);
  141940. vorbis_synthesis_trackonly(&vf->vb,&op); /* set up a vb with
  141941. only tracking, no
  141942. pcm_decode */
  141943. vorbis_synthesis_blockin(&vf->vd,&vf->vb);
  141944. if(op.granulepos>-1){
  141945. int i;
  141946. vf->pcm_offset=op.granulepos-vf->pcmlengths[vf->current_link*2];
  141947. if(vf->pcm_offset<0)vf->pcm_offset=0;
  141948. for(i=0;i<vf->current_link;i++)
  141949. vf->pcm_offset+=vf->pcmlengths[i*2+1];
  141950. }
  141951. lastblock=thisblock;
  141952. }else{
  141953. if(ret<0 && ret!=OV_HOLE)break;
  141954. if(_get_next_page(vf,&og,-1)<0)break;
  141955. if(vf->current_serialno!=ogg_page_serialno(&og))_decode_clear(vf);
  141956. if(vf->ready_state<STREAMSET){
  141957. int link;
  141958. vf->current_serialno=ogg_page_serialno(&og);
  141959. for(link=0;link<vf->links;link++)
  141960. if(vf->serialnos[link]==vf->current_serialno)break;
  141961. if(link==vf->links)return(OV_EBADLINK);
  141962. vf->current_link=link;
  141963. ogg_stream_reset_serialno(&vf->os,vf->current_serialno);
  141964. vf->ready_state=STREAMSET;
  141965. ret=_make_decode_ready(vf);
  141966. if(ret)return ret;
  141967. lastblock=0;
  141968. }
  141969. ogg_stream_pagein(&vf->os,&og);
  141970. }
  141971. }
  141972. vf->bittrack=0.f;
  141973. vf->samptrack=0.f;
  141974. while(vf->pcm_offset<pos){
  141975. ogg_int64_t target=pos-vf->pcm_offset;
  141976. long samples=vorbis_synthesis_pcmout(&vf->vd,NULL);
  141977. if(samples>target)samples=target;
  141978. vorbis_synthesis_read(&vf->vd,samples);
  141979. vf->pcm_offset+=samples;
  141980. if(samples<target)
  141981. if(_fetch_and_process_packet(vf,NULL,1,1)<=0)
  141982. vf->pcm_offset=ov_pcm_total(vf,-1); /* eof */
  141983. }
  141984. return 0;
  141985. }
  141986. int ov_time_seek(OggVorbis_File *vf,double seconds){
  141987. int link=-1;
  141988. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  141989. double time_total=ov_time_total(vf,-1);
  141990. if(vf->ready_state<OPENED)return(OV_EINVAL);
  141991. if(!vf->seekable)return(OV_ENOSEEK);
  141992. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  141993. for(link=vf->links-1;link>=0;link--){
  141994. pcm_total-=vf->pcmlengths[link*2+1];
  141995. time_total-=ov_time_total(vf,link);
  141996. if(seconds>=time_total)break;
  141997. }
  141998. {
  141999. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  142000. return(ov_pcm_seek(vf,target));
  142001. }
  142002. }
  142003. int ov_time_seek_page(OggVorbis_File *vf,double seconds){
  142004. int link=-1;
  142005. ogg_int64_t pcm_total=ov_pcm_total(vf,-1);
  142006. double time_total=ov_time_total(vf,-1);
  142007. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142008. if(!vf->seekable)return(OV_ENOSEEK);
  142009. if(seconds<0 || seconds>time_total)return(OV_EINVAL);
  142010. for(link=vf->links-1;link>=0;link--){
  142011. pcm_total-=vf->pcmlengths[link*2+1];
  142012. time_total-=ov_time_total(vf,link);
  142013. if(seconds>=time_total)break;
  142014. }
  142015. {
  142016. ogg_int64_t target=pcm_total+(seconds-time_total)*vf->vi[link].rate;
  142017. return(ov_pcm_seek_page(vf,target));
  142018. }
  142019. }
  142020. ogg_int64_t ov_raw_tell(OggVorbis_File *vf){
  142021. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142022. return(vf->offset);
  142023. }
  142024. ogg_int64_t ov_pcm_tell(OggVorbis_File *vf){
  142025. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142026. return(vf->pcm_offset);
  142027. }
  142028. double ov_time_tell(OggVorbis_File *vf){
  142029. int link=0;
  142030. ogg_int64_t pcm_total=0;
  142031. double time_total=0.f;
  142032. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142033. if(vf->seekable){
  142034. pcm_total=ov_pcm_total(vf,-1);
  142035. time_total=ov_time_total(vf,-1);
  142036. for(link=vf->links-1;link>=0;link--){
  142037. pcm_total-=vf->pcmlengths[link*2+1];
  142038. time_total-=ov_time_total(vf,link);
  142039. if(vf->pcm_offset>=pcm_total)break;
  142040. }
  142041. }
  142042. return((double)time_total+(double)(vf->pcm_offset-pcm_total)/vf->vi[link].rate);
  142043. }
  142044. vorbis_info *ov_info(OggVorbis_File *vf,int link){
  142045. if(vf->seekable){
  142046. if(link<0)
  142047. if(vf->ready_state>=STREAMSET)
  142048. return vf->vi+vf->current_link;
  142049. else
  142050. return vf->vi;
  142051. else
  142052. if(link>=vf->links)
  142053. return NULL;
  142054. else
  142055. return vf->vi+link;
  142056. }else{
  142057. return vf->vi;
  142058. }
  142059. }
  142060. vorbis_comment *ov_comment(OggVorbis_File *vf,int link){
  142061. if(vf->seekable){
  142062. if(link<0)
  142063. if(vf->ready_state>=STREAMSET)
  142064. return vf->vc+vf->current_link;
  142065. else
  142066. return vf->vc;
  142067. else
  142068. if(link>=vf->links)
  142069. return NULL;
  142070. else
  142071. return vf->vc+link;
  142072. }else{
  142073. return vf->vc;
  142074. }
  142075. }
  142076. static int host_is_big_endian() {
  142077. ogg_int32_t pattern = 0xfeedface; /* deadbeef */
  142078. unsigned char *bytewise = (unsigned char *)&pattern;
  142079. if (bytewise[0] == 0xfe) return 1;
  142080. return 0;
  142081. }
  142082. long ov_read(OggVorbis_File *vf,char *buffer,int length,
  142083. int bigendianp,int word,int sgned,int *bitstream){
  142084. int i,j;
  142085. int host_endian = host_is_big_endian();
  142086. float **pcm;
  142087. long samples;
  142088. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142089. while(1){
  142090. if(vf->ready_state==INITSET){
  142091. samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  142092. if(samples)break;
  142093. }
  142094. {
  142095. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  142096. if(ret==OV_EOF)
  142097. return(0);
  142098. if(ret<=0)
  142099. return(ret);
  142100. }
  142101. }
  142102. if(samples>0){
  142103. long channels=ov_info(vf,-1)->channels;
  142104. long bytespersample=word * channels;
  142105. vorbis_fpu_control fpu;
  142106. (void) fpu; // (to avoid a warning about it being unused)
  142107. if(samples>length/bytespersample)samples=length/bytespersample;
  142108. if(samples <= 0)
  142109. return OV_EINVAL;
  142110. {
  142111. int val;
  142112. if(word==1){
  142113. int off=(sgned?0:128);
  142114. vorbis_fpu_setround(&fpu);
  142115. for(j=0;j<samples;j++)
  142116. for(i=0;i<channels;i++){
  142117. val=vorbis_ftoi(pcm[i][j]*128.f);
  142118. if(val>127)val=127;
  142119. else if(val<-128)val=-128;
  142120. *buffer++=val+off;
  142121. }
  142122. vorbis_fpu_restore(fpu);
  142123. }else{
  142124. int off=(sgned?0:32768);
  142125. if(host_endian==bigendianp){
  142126. if(sgned){
  142127. vorbis_fpu_setround(&fpu);
  142128. for(i=0;i<channels;i++) { /* It's faster in this order */
  142129. float *src=pcm[i];
  142130. short *dest=((short *)buffer)+i;
  142131. for(j=0;j<samples;j++) {
  142132. val=vorbis_ftoi(src[j]*32768.f);
  142133. if(val>32767)val=32767;
  142134. else if(val<-32768)val=-32768;
  142135. *dest=val;
  142136. dest+=channels;
  142137. }
  142138. }
  142139. vorbis_fpu_restore(fpu);
  142140. }else{
  142141. vorbis_fpu_setround(&fpu);
  142142. for(i=0;i<channels;i++) {
  142143. float *src=pcm[i];
  142144. short *dest=((short *)buffer)+i;
  142145. for(j=0;j<samples;j++) {
  142146. val=vorbis_ftoi(src[j]*32768.f);
  142147. if(val>32767)val=32767;
  142148. else if(val<-32768)val=-32768;
  142149. *dest=val+off;
  142150. dest+=channels;
  142151. }
  142152. }
  142153. vorbis_fpu_restore(fpu);
  142154. }
  142155. }else if(bigendianp){
  142156. vorbis_fpu_setround(&fpu);
  142157. for(j=0;j<samples;j++)
  142158. for(i=0;i<channels;i++){
  142159. val=vorbis_ftoi(pcm[i][j]*32768.f);
  142160. if(val>32767)val=32767;
  142161. else if(val<-32768)val=-32768;
  142162. val+=off;
  142163. *buffer++=(val>>8);
  142164. *buffer++=(val&0xff);
  142165. }
  142166. vorbis_fpu_restore(fpu);
  142167. }else{
  142168. int val;
  142169. vorbis_fpu_setround(&fpu);
  142170. for(j=0;j<samples;j++)
  142171. for(i=0;i<channels;i++){
  142172. val=vorbis_ftoi(pcm[i][j]*32768.f);
  142173. if(val>32767)val=32767;
  142174. else if(val<-32768)val=-32768;
  142175. val+=off;
  142176. *buffer++=(val&0xff);
  142177. *buffer++=(val>>8);
  142178. }
  142179. vorbis_fpu_restore(fpu);
  142180. }
  142181. }
  142182. }
  142183. vorbis_synthesis_read(&vf->vd,samples);
  142184. vf->pcm_offset+=samples;
  142185. if(bitstream)*bitstream=vf->current_link;
  142186. return(samples*bytespersample);
  142187. }else{
  142188. return(samples);
  142189. }
  142190. }
  142191. long ov_read_float(OggVorbis_File *vf,float ***pcm_channels,int length,
  142192. int *bitstream){
  142193. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142194. while(1){
  142195. if(vf->ready_state==INITSET){
  142196. float **pcm;
  142197. long samples=vorbis_synthesis_pcmout(&vf->vd,&pcm);
  142198. if(samples){
  142199. if(pcm_channels)*pcm_channels=pcm;
  142200. if(samples>length)samples=length;
  142201. vorbis_synthesis_read(&vf->vd,samples);
  142202. vf->pcm_offset+=samples;
  142203. if(bitstream)*bitstream=vf->current_link;
  142204. return samples;
  142205. }
  142206. }
  142207. {
  142208. int ret=_fetch_and_process_packet(vf,NULL,1,1);
  142209. if(ret==OV_EOF)return(0);
  142210. if(ret<=0)return(ret);
  142211. }
  142212. }
  142213. }
  142214. extern float *vorbis_window(vorbis_dsp_state *v,int W);
  142215. extern void _analysis_output_always(const char *base,int i,float *v,int n,int bark,int dB,
  142216. ogg_int64_t off);
  142217. static void _ov_splice(float **pcm,float **lappcm,
  142218. int n1, int n2,
  142219. int ch1, int ch2,
  142220. float *w1, float *w2){
  142221. int i,j;
  142222. float *w=w1;
  142223. int n=n1;
  142224. if(n1>n2){
  142225. n=n2;
  142226. w=w2;
  142227. }
  142228. for(j=0;j<ch1 && j<ch2;j++){
  142229. float *s=lappcm[j];
  142230. float *d=pcm[j];
  142231. for(i=0;i<n;i++){
  142232. float wd=w[i]*w[i];
  142233. float ws=1.-wd;
  142234. d[i]=d[i]*wd + s[i]*ws;
  142235. }
  142236. }
  142237. for(;j<ch2;j++){
  142238. float *d=pcm[j];
  142239. for(i=0;i<n;i++){
  142240. float wd=w[i]*w[i];
  142241. d[i]=d[i]*wd;
  142242. }
  142243. }
  142244. }
  142245. static int _ov_initset(OggVorbis_File *vf){
  142246. while(1){
  142247. if(vf->ready_state==INITSET)break;
  142248. {
  142249. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  142250. if(ret<0 && ret!=OV_HOLE)return(ret);
  142251. }
  142252. }
  142253. return 0;
  142254. }
  142255. static int _ov_initprime(OggVorbis_File *vf){
  142256. vorbis_dsp_state *vd=&vf->vd;
  142257. while(1){
  142258. if(vf->ready_state==INITSET)
  142259. if(vorbis_synthesis_pcmout(vd,NULL))break;
  142260. {
  142261. int ret=_fetch_and_process_packet(vf,NULL,1,0);
  142262. if(ret<0 && ret!=OV_HOLE)return(ret);
  142263. }
  142264. }
  142265. return 0;
  142266. }
  142267. static void _ov_getlap(OggVorbis_File *vf,vorbis_info *vi,vorbis_dsp_state *vd,
  142268. float **lappcm,int lapsize){
  142269. int lapcount=0,i;
  142270. float **pcm;
  142271. while(lapcount<lapsize){
  142272. int samples=vorbis_synthesis_pcmout(vd,&pcm);
  142273. if(samples){
  142274. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142275. for(i=0;i<vi->channels;i++)
  142276. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142277. lapcount+=samples;
  142278. vorbis_synthesis_read(vd,samples);
  142279. }else{
  142280. int ret=_fetch_and_process_packet(vf,NULL,1,0); /* do *not* span */
  142281. if(ret==OV_EOF)break;
  142282. }
  142283. }
  142284. if(lapcount<lapsize){
  142285. int samples=vorbis_synthesis_lapout(&vf->vd,&pcm);
  142286. if(samples==0){
  142287. for(i=0;i<vi->channels;i++)
  142288. memset(lappcm[i]+lapcount,0,sizeof(**pcm)*lapsize-lapcount);
  142289. lapcount=lapsize;
  142290. }else{
  142291. if(samples>lapsize-lapcount)samples=lapsize-lapcount;
  142292. for(i=0;i<vi->channels;i++)
  142293. memcpy(lappcm[i]+lapcount,pcm[i],sizeof(**pcm)*samples);
  142294. lapcount+=samples;
  142295. }
  142296. }
  142297. }
  142298. int ov_crosslap(OggVorbis_File *vf1, OggVorbis_File *vf2){
  142299. vorbis_info *vi1,*vi2;
  142300. float **lappcm;
  142301. float **pcm;
  142302. float *w1,*w2;
  142303. int n1,n2,i,ret,hs1,hs2;
  142304. if(vf1==vf2)return(0); /* degenerate case */
  142305. if(vf1->ready_state<OPENED)return(OV_EINVAL);
  142306. if(vf2->ready_state<OPENED)return(OV_EINVAL);
  142307. ret=_ov_initset(vf1);
  142308. if(ret)return(ret);
  142309. ret=_ov_initprime(vf2);
  142310. if(ret)return(ret);
  142311. vi1=ov_info(vf1,-1);
  142312. vi2=ov_info(vf2,-1);
  142313. hs1=ov_halfrate_p(vf1);
  142314. hs2=ov_halfrate_p(vf2);
  142315. lappcm=(float**) alloca(sizeof(*lappcm)*vi1->channels);
  142316. n1=vorbis_info_blocksize(vi1,0)>>(1+hs1);
  142317. n2=vorbis_info_blocksize(vi2,0)>>(1+hs2);
  142318. w1=vorbis_window(&vf1->vd,0);
  142319. w2=vorbis_window(&vf2->vd,0);
  142320. for(i=0;i<vi1->channels;i++)
  142321. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142322. _ov_getlap(vf1,vi1,&vf1->vd,lappcm,n1);
  142323. vorbis_synthesis_lapout(&vf2->vd,&pcm);
  142324. _analysis_output_always("pcmL",0,pcm[0],n1*2,0,0,0);
  142325. _analysis_output_always("pcmR",0,pcm[1],n1*2,0,0,0);
  142326. _ov_splice(pcm,lappcm,n1,n2,vi1->channels,vi2->channels,w1,w2);
  142327. return(0);
  142328. }
  142329. static int _ov_64_seek_lap(OggVorbis_File *vf,ogg_int64_t pos,
  142330. int (*localseek)(OggVorbis_File *,ogg_int64_t)){
  142331. vorbis_info *vi;
  142332. float **lappcm;
  142333. float **pcm;
  142334. float *w1,*w2;
  142335. int n1,n2,ch1,ch2,hs;
  142336. int i,ret;
  142337. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142338. ret=_ov_initset(vf);
  142339. if(ret)return(ret);
  142340. vi=ov_info(vf,-1);
  142341. hs=ov_halfrate_p(vf);
  142342. ch1=vi->channels;
  142343. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142344. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142345. persistent; even if the decode state
  142346. from this link gets dumped, this
  142347. window array continues to exist */
  142348. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142349. for(i=0;i<ch1;i++)
  142350. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142351. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142352. ret=localseek(vf,pos);
  142353. if(ret)return ret;
  142354. ret=_ov_initprime(vf);
  142355. if(ret)return(ret);
  142356. vi=ov_info(vf,-1);
  142357. ch2=vi->channels;
  142358. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142359. w2=vorbis_window(&vf->vd,0);
  142360. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142361. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142362. return(0);
  142363. }
  142364. int ov_raw_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142365. return _ov_64_seek_lap(vf,pos,ov_raw_seek);
  142366. }
  142367. int ov_pcm_seek_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142368. return _ov_64_seek_lap(vf,pos,ov_pcm_seek);
  142369. }
  142370. int ov_pcm_seek_page_lap(OggVorbis_File *vf,ogg_int64_t pos){
  142371. return _ov_64_seek_lap(vf,pos,ov_pcm_seek_page);
  142372. }
  142373. static int _ov_d_seek_lap(OggVorbis_File *vf,double pos,
  142374. int (*localseek)(OggVorbis_File *,double)){
  142375. vorbis_info *vi;
  142376. float **lappcm;
  142377. float **pcm;
  142378. float *w1,*w2;
  142379. int n1,n2,ch1,ch2,hs;
  142380. int i,ret;
  142381. if(vf->ready_state<OPENED)return(OV_EINVAL);
  142382. ret=_ov_initset(vf);
  142383. if(ret)return(ret);
  142384. vi=ov_info(vf,-1);
  142385. hs=ov_halfrate_p(vf);
  142386. ch1=vi->channels;
  142387. n1=vorbis_info_blocksize(vi,0)>>(1+hs);
  142388. w1=vorbis_window(&vf->vd,0); /* window arrays from libvorbis are
  142389. persistent; even if the decode state
  142390. from this link gets dumped, this
  142391. window array continues to exist */
  142392. lappcm=(float**) alloca(sizeof(*lappcm)*ch1);
  142393. for(i=0;i<ch1;i++)
  142394. lappcm[i]=(float*) alloca(sizeof(**lappcm)*n1);
  142395. _ov_getlap(vf,vi,&vf->vd,lappcm,n1);
  142396. ret=localseek(vf,pos);
  142397. if(ret)return ret;
  142398. ret=_ov_initprime(vf);
  142399. if(ret)return(ret);
  142400. vi=ov_info(vf,-1);
  142401. ch2=vi->channels;
  142402. n2=vorbis_info_blocksize(vi,0)>>(1+hs);
  142403. w2=vorbis_window(&vf->vd,0);
  142404. vorbis_synthesis_lapout(&vf->vd,&pcm);
  142405. _ov_splice(pcm,lappcm,n1,n2,ch1,ch2,w1,w2);
  142406. return(0);
  142407. }
  142408. int ov_time_seek_lap(OggVorbis_File *vf,double pos){
  142409. return _ov_d_seek_lap(vf,pos,ov_time_seek);
  142410. }
  142411. int ov_time_seek_page_lap(OggVorbis_File *vf,double pos){
  142412. return _ov_d_seek_lap(vf,pos,ov_time_seek_page);
  142413. }
  142414. #endif
  142415. /*** End of inlined file: vorbisfile.c ***/
  142416. /*** Start of inlined file: window.c ***/
  142417. /*** Start of inlined file: juce_OggVorbisHeader.h ***/
  142418. // This file is included at the start of each Ogg-Vorbis .c file, just to do a few housekeeping
  142419. // tasks..
  142420. #if JUCE_MSVC
  142421. #pragma warning (disable: 4267 4127 4244 4996 4100 4701 4702 4013 4133 4206 4305 4189 4706)
  142422. #endif
  142423. /*** End of inlined file: juce_OggVorbisHeader.h ***/
  142424. #if JUCE_USE_OGGVORBIS
  142425. #include <stdlib.h>
  142426. #include <math.h>
  142427. static float vwin64[32] = {
  142428. 0.0009460463F, 0.0085006468F, 0.0235352254F, 0.0458950567F,
  142429. 0.0753351908F, 0.1115073077F, 0.1539457973F, 0.2020557475F,
  142430. 0.2551056759F, 0.3122276645F, 0.3724270287F, 0.4346027792F,
  142431. 0.4975789974F, 0.5601459521F, 0.6211085051F, 0.6793382689F,
  142432. 0.7338252629F, 0.7837245849F, 0.8283939355F, 0.8674186656F,
  142433. 0.9006222429F, 0.9280614787F, 0.9500073081F, 0.9669131782F,
  142434. 0.9793740220F, 0.9880792941F, 0.9937636139F, 0.9971582668F,
  142435. 0.9989462667F, 0.9997230082F, 0.9999638688F, 0.9999995525F,
  142436. };
  142437. static float vwin128[64] = {
  142438. 0.0002365472F, 0.0021280687F, 0.0059065254F, 0.0115626550F,
  142439. 0.0190823442F, 0.0284463735F, 0.0396300935F, 0.0526030430F,
  142440. 0.0673285281F, 0.0837631763F, 0.1018564887F, 0.1215504095F,
  142441. 0.1427789367F, 0.1654677960F, 0.1895342001F, 0.2148867160F,
  142442. 0.2414252576F, 0.2690412240F, 0.2976177952F, 0.3270303960F,
  142443. 0.3571473350F, 0.3878306189F, 0.4189369387F, 0.4503188188F,
  142444. 0.4818259135F, 0.5133064334F, 0.5446086751F, 0.5755826278F,
  142445. 0.6060816248F, 0.6359640047F, 0.6650947483F, 0.6933470543F,
  142446. 0.7206038179F, 0.7467589810F, 0.7717187213F, 0.7954024542F,
  142447. 0.8177436264F, 0.8386902831F, 0.8582053981F, 0.8762669622F,
  142448. 0.8928678298F, 0.9080153310F, 0.9217306608F, 0.9340480615F,
  142449. 0.9450138200F, 0.9546851041F, 0.9631286621F, 0.9704194171F,
  142450. 0.9766389810F, 0.9818741197F, 0.9862151938F, 0.9897546035F,
  142451. 0.9925852598F, 0.9947991032F, 0.9964856900F, 0.9977308602F,
  142452. 0.9986155015F, 0.9992144193F, 0.9995953200F, 0.9998179155F,
  142453. 0.9999331503F, 0.9999825563F, 0.9999977357F, 0.9999999720F,
  142454. };
  142455. static float vwin256[128] = {
  142456. 0.0000591390F, 0.0005321979F, 0.0014780301F, 0.0028960636F,
  142457. 0.0047854363F, 0.0071449926F, 0.0099732775F, 0.0132685298F,
  142458. 0.0170286741F, 0.0212513119F, 0.0259337111F, 0.0310727950F,
  142459. 0.0366651302F, 0.0427069140F, 0.0491939614F, 0.0561216907F,
  142460. 0.0634851102F, 0.0712788035F, 0.0794969160F, 0.0881331402F,
  142461. 0.0971807028F, 0.1066323515F, 0.1164803426F, 0.1267164297F,
  142462. 0.1373318534F, 0.1483173323F, 0.1596630553F, 0.1713586755F,
  142463. 0.1833933062F, 0.1957555184F, 0.2084333404F, 0.2214142599F,
  142464. 0.2346852280F, 0.2482326664F, 0.2620424757F, 0.2761000481F,
  142465. 0.2903902813F, 0.3048975959F, 0.3196059553F, 0.3344988887F,
  142466. 0.3495595160F, 0.3647705766F, 0.3801144597F, 0.3955732382F,
  142467. 0.4111287047F, 0.4267624093F, 0.4424557009F, 0.4581897696F,
  142468. 0.4739456913F, 0.4897044744F, 0.5054471075F, 0.5211546088F,
  142469. 0.5368080763F, 0.5523887395F, 0.5678780103F, 0.5832575361F,
  142470. 0.5985092508F, 0.6136154277F, 0.6285587300F, 0.6433222619F,
  142471. 0.6578896175F, 0.6722449294F, 0.6863729144F, 0.7002589187F,
  142472. 0.7138889597F, 0.7272497662F, 0.7403288154F, 0.7531143679F,
  142473. 0.7655954985F, 0.7777621249F, 0.7896050322F, 0.8011158947F,
  142474. 0.8122872932F, 0.8231127294F, 0.8335866365F, 0.8437043850F,
  142475. 0.8534622861F, 0.8628575905F, 0.8718884835F, 0.8805540765F,
  142476. 0.8888543947F, 0.8967903616F, 0.9043637797F, 0.9115773078F,
  142477. 0.9184344360F, 0.9249394562F, 0.9310974312F, 0.9369141608F,
  142478. 0.9423961446F, 0.9475505439F, 0.9523851406F, 0.9569082947F,
  142479. 0.9611289005F, 0.9650563408F, 0.9687004405F, 0.9720714191F,
  142480. 0.9751798427F, 0.9780365753F, 0.9806527301F, 0.9830396204F,
  142481. 0.9852087111F, 0.9871715701F, 0.9889398207F, 0.9905250941F,
  142482. 0.9919389832F, 0.9931929973F, 0.9942985174F, 0.9952667537F,
  142483. 0.9961087037F, 0.9968351119F, 0.9974564312F, 0.9979827858F,
  142484. 0.9984239359F, 0.9987892441F, 0.9990876435F, 0.9993276081F,
  142485. 0.9995171241F, 0.9996636648F, 0.9997741654F, 0.9998550016F,
  142486. 0.9999119692F, 0.9999502656F, 0.9999744742F, 0.9999885497F,
  142487. 0.9999958064F, 0.9999989077F, 0.9999998584F, 0.9999999983F,
  142488. };
  142489. static float vwin512[256] = {
  142490. 0.0000147849F, 0.0001330607F, 0.0003695946F, 0.0007243509F,
  142491. 0.0011972759F, 0.0017882983F, 0.0024973285F, 0.0033242588F,
  142492. 0.0042689632F, 0.0053312973F, 0.0065110982F, 0.0078081841F,
  142493. 0.0092223540F, 0.0107533880F, 0.0124010466F, 0.0141650703F,
  142494. 0.0160451800F, 0.0180410758F, 0.0201524373F, 0.0223789233F,
  142495. 0.0247201710F, 0.0271757958F, 0.0297453914F, 0.0324285286F,
  142496. 0.0352247556F, 0.0381335972F, 0.0411545545F, 0.0442871045F,
  142497. 0.0475306997F, 0.0508847676F, 0.0543487103F, 0.0579219038F,
  142498. 0.0616036982F, 0.0653934164F, 0.0692903546F, 0.0732937809F,
  142499. 0.0774029356F, 0.0816170305F, 0.0859352485F, 0.0903567428F,
  142500. 0.0948806375F, 0.0995060259F, 0.1042319712F, 0.1090575056F,
  142501. 0.1139816300F, 0.1190033137F, 0.1241214941F, 0.1293350764F,
  142502. 0.1346429333F, 0.1400439046F, 0.1455367974F, 0.1511203852F,
  142503. 0.1567934083F, 0.1625545735F, 0.1684025537F, 0.1743359881F,
  142504. 0.1803534820F, 0.1864536069F, 0.1926349000F, 0.1988958650F,
  142505. 0.2052349715F, 0.2116506555F, 0.2181413191F, 0.2247053313F,
  142506. 0.2313410275F, 0.2380467105F, 0.2448206500F, 0.2516610835F,
  142507. 0.2585662164F, 0.2655342226F, 0.2725632448F, 0.2796513950F,
  142508. 0.2867967551F, 0.2939973773F, 0.3012512852F, 0.3085564739F,
  142509. 0.3159109111F, 0.3233125375F, 0.3307592680F, 0.3382489922F,
  142510. 0.3457795756F, 0.3533488602F, 0.3609546657F, 0.3685947904F,
  142511. 0.3762670121F, 0.3839690896F, 0.3916987634F, 0.3994537572F,
  142512. 0.4072317788F, 0.4150305215F, 0.4228476653F, 0.4306808783F,
  142513. 0.4385278181F, 0.4463861329F, 0.4542534630F, 0.4621274424F,
  142514. 0.4700057001F, 0.4778858615F, 0.4857655502F, 0.4936423891F,
  142515. 0.5015140023F, 0.5093780165F, 0.5172320626F, 0.5250737772F,
  142516. 0.5329008043F, 0.5407107971F, 0.5485014192F, 0.5562703465F,
  142517. 0.5640152688F, 0.5717338914F, 0.5794239366F, 0.5870831457F,
  142518. 0.5947092801F, 0.6023001235F, 0.6098534829F, 0.6173671907F,
  142519. 0.6248391059F, 0.6322671161F, 0.6396491384F, 0.6469831217F,
  142520. 0.6542670475F, 0.6614989319F, 0.6686768267F, 0.6757988210F,
  142521. 0.6828630426F, 0.6898676592F, 0.6968108799F, 0.7036909564F,
  142522. 0.7105061843F, 0.7172549043F, 0.7239355032F, 0.7305464154F,
  142523. 0.7370861235F, 0.7435531598F, 0.7499461068F, 0.7562635986F,
  142524. 0.7625043214F, 0.7686670148F, 0.7747504721F, 0.7807535410F,
  142525. 0.7866751247F, 0.7925141825F, 0.7982697296F, 0.8039408387F,
  142526. 0.8095266395F, 0.8150263196F, 0.8204391248F, 0.8257643590F,
  142527. 0.8310013848F, 0.8361496236F, 0.8412085555F, 0.8461777194F,
  142528. 0.8510567129F, 0.8558451924F, 0.8605428730F, 0.8651495278F,
  142529. 0.8696649882F, 0.8740891432F, 0.8784219392F, 0.8826633797F,
  142530. 0.8868135244F, 0.8908724888F, 0.8948404441F, 0.8987176157F,
  142531. 0.9025042831F, 0.9062007791F, 0.9098074886F, 0.9133248482F,
  142532. 0.9167533451F, 0.9200935163F, 0.9233459472F, 0.9265112712F,
  142533. 0.9295901680F, 0.9325833632F, 0.9354916263F, 0.9383157705F,
  142534. 0.9410566504F, 0.9437151618F, 0.9462922398F, 0.9487888576F,
  142535. 0.9512060252F, 0.9535447882F, 0.9558062262F, 0.9579914516F,
  142536. 0.9601016078F, 0.9621378683F, 0.9641014348F, 0.9659935361F,
  142537. 0.9678154261F, 0.9695683830F, 0.9712537071F, 0.9728727198F,
  142538. 0.9744267618F, 0.9759171916F, 0.9773453842F, 0.9787127293F,
  142539. 0.9800206298F, 0.9812705006F, 0.9824637665F, 0.9836018613F,
  142540. 0.9846862258F, 0.9857183066F, 0.9866995544F, 0.9876314227F,
  142541. 0.9885153662F, 0.9893528393F, 0.9901452948F, 0.9908941823F,
  142542. 0.9916009470F, 0.9922670279F, 0.9928938570F, 0.9934828574F,
  142543. 0.9940354423F, 0.9945530133F, 0.9950369595F, 0.9954886562F,
  142544. 0.9959094633F, 0.9963007242F, 0.9966637649F, 0.9969998925F,
  142545. 0.9973103939F, 0.9975965351F, 0.9978595598F, 0.9981006885F,
  142546. 0.9983211172F, 0.9985220166F, 0.9987045311F, 0.9988697776F,
  142547. 0.9990188449F, 0.9991527924F, 0.9992726499F, 0.9993794157F,
  142548. 0.9994740570F, 0.9995575079F, 0.9996306699F, 0.9996944099F,
  142549. 0.9997495605F, 0.9997969190F, 0.9998372465F, 0.9998712678F,
  142550. 0.9998996704F, 0.9999231041F, 0.9999421807F, 0.9999574732F,
  142551. 0.9999695157F, 0.9999788026F, 0.9999857885F, 0.9999908879F,
  142552. 0.9999944746F, 0.9999968817F, 0.9999984010F, 0.9999992833F,
  142553. 0.9999997377F, 0.9999999317F, 0.9999999911F, 0.9999999999F,
  142554. };
  142555. static float vwin1024[512] = {
  142556. 0.0000036962F, 0.0000332659F, 0.0000924041F, 0.0001811086F,
  142557. 0.0002993761F, 0.0004472021F, 0.0006245811F, 0.0008315063F,
  142558. 0.0010679699F, 0.0013339631F, 0.0016294757F, 0.0019544965F,
  142559. 0.0023090133F, 0.0026930125F, 0.0031064797F, 0.0035493989F,
  142560. 0.0040217533F, 0.0045235250F, 0.0050546946F, 0.0056152418F,
  142561. 0.0062051451F, 0.0068243817F, 0.0074729278F, 0.0081507582F,
  142562. 0.0088578466F, 0.0095941655F, 0.0103596863F, 0.0111543789F,
  142563. 0.0119782122F, 0.0128311538F, 0.0137131701F, 0.0146242260F,
  142564. 0.0155642855F, 0.0165333111F, 0.0175312640F, 0.0185581042F,
  142565. 0.0196137903F, 0.0206982797F, 0.0218115284F, 0.0229534910F,
  142566. 0.0241241208F, 0.0253233698F, 0.0265511886F, 0.0278075263F,
  142567. 0.0290923308F, 0.0304055484F, 0.0317471241F, 0.0331170013F,
  142568. 0.0345151222F, 0.0359414274F, 0.0373958560F, 0.0388783456F,
  142569. 0.0403888325F, 0.0419272511F, 0.0434935347F, 0.0450876148F,
  142570. 0.0467094213F, 0.0483588828F, 0.0500359261F, 0.0517404765F,
  142571. 0.0534724575F, 0.0552317913F, 0.0570183983F, 0.0588321971F,
  142572. 0.0606731048F, 0.0625410369F, 0.0644359070F, 0.0663576272F,
  142573. 0.0683061077F, 0.0702812571F, 0.0722829821F, 0.0743111878F,
  142574. 0.0763657775F, 0.0784466526F, 0.0805537129F, 0.0826868561F,
  142575. 0.0848459782F, 0.0870309736F, 0.0892417345F, 0.0914781514F,
  142576. 0.0937401128F, 0.0960275056F, 0.0983402145F, 0.1006781223F,
  142577. 0.1030411101F, 0.1054290568F, 0.1078418397F, 0.1102793336F,
  142578. 0.1127414119F, 0.1152279457F, 0.1177388042F, 0.1202738544F,
  142579. 0.1228329618F, 0.1254159892F, 0.1280227980F, 0.1306532471F,
  142580. 0.1333071937F, 0.1359844927F, 0.1386849970F, 0.1414085575F,
  142581. 0.1441550230F, 0.1469242403F, 0.1497160539F, 0.1525303063F,
  142582. 0.1553668381F, 0.1582254875F, 0.1611060909F, 0.1640084822F,
  142583. 0.1669324936F, 0.1698779549F, 0.1728446939F, 0.1758325362F,
  142584. 0.1788413055F, 0.1818708232F, 0.1849209084F, 0.1879913785F,
  142585. 0.1910820485F, 0.1941927312F, 0.1973232376F, 0.2004733764F,
  142586. 0.2036429541F, 0.2068317752F, 0.2100396421F, 0.2132663552F,
  142587. 0.2165117125F, 0.2197755102F, 0.2230575422F, 0.2263576007F,
  142588. 0.2296754753F, 0.2330109540F, 0.2363638225F, 0.2397338646F,
  142589. 0.2431208619F, 0.2465245941F, 0.2499448389F, 0.2533813719F,
  142590. 0.2568339669F, 0.2603023956F, 0.2637864277F, 0.2672858312F,
  142591. 0.2708003718F, 0.2743298135F, 0.2778739186F, 0.2814324472F,
  142592. 0.2850051576F, 0.2885918065F, 0.2921921485F, 0.2958059366F,
  142593. 0.2994329219F, 0.3030728538F, 0.3067254799F, 0.3103905462F,
  142594. 0.3140677969F, 0.3177569747F, 0.3214578205F, 0.3251700736F,
  142595. 0.3288934718F, 0.3326277513F, 0.3363726468F, 0.3401278914F,
  142596. 0.3438932168F, 0.3476683533F, 0.3514530297F, 0.3552469734F,
  142597. 0.3590499106F, 0.3628615659F, 0.3666816630F, 0.3705099239F,
  142598. 0.3743460698F, 0.3781898204F, 0.3820408945F, 0.3858990095F,
  142599. 0.3897638820F, 0.3936352274F, 0.3975127601F, 0.4013961936F,
  142600. 0.4052852405F, 0.4091796123F, 0.4130790198F, 0.4169831732F,
  142601. 0.4208917815F, 0.4248045534F, 0.4287211965F, 0.4326414181F,
  142602. 0.4365649248F, 0.4404914225F, 0.4444206167F, 0.4483522125F,
  142603. 0.4522859146F, 0.4562214270F, 0.4601584538F, 0.4640966984F,
  142604. 0.4680358644F, 0.4719756548F, 0.4759157726F, 0.4798559209F,
  142605. 0.4837958024F, 0.4877351199F, 0.4916735765F, 0.4956108751F,
  142606. 0.4995467188F, 0.5034808109F, 0.5074128550F, 0.5113425550F,
  142607. 0.5152696149F, 0.5191937395F, 0.5231146336F, 0.5270320028F,
  142608. 0.5309455530F, 0.5348549910F, 0.5387600239F, 0.5426603597F,
  142609. 0.5465557070F, 0.5504457754F, 0.5543302752F, 0.5582089175F,
  142610. 0.5620814145F, 0.5659474793F, 0.5698068262F, 0.5736591704F,
  142611. 0.5775042283F, 0.5813417176F, 0.5851713571F, 0.5889928670F,
  142612. 0.5928059689F, 0.5966103856F, 0.6004058415F, 0.6041920626F,
  142613. 0.6079687761F, 0.6117357113F, 0.6154925986F, 0.6192391705F,
  142614. 0.6229751612F, 0.6267003064F, 0.6304143441F, 0.6341170137F,
  142615. 0.6378080569F, 0.6414872173F, 0.6451542405F, 0.6488088741F,
  142616. 0.6524508681F, 0.6560799742F, 0.6596959469F, 0.6632985424F,
  142617. 0.6668875197F, 0.6704626398F, 0.6740236662F, 0.6775703649F,
  142618. 0.6811025043F, 0.6846198554F, 0.6881221916F, 0.6916092892F,
  142619. 0.6950809269F, 0.6985368861F, 0.7019769510F, 0.7054009085F,
  142620. 0.7088085484F, 0.7121996632F, 0.7155740484F, 0.7189315023F,
  142621. 0.7222718263F, 0.7255948245F, 0.7289003043F, 0.7321880760F,
  142622. 0.7354579530F, 0.7387097518F, 0.7419432921F, 0.7451583966F,
  142623. 0.7483548915F, 0.7515326059F, 0.7546913723F, 0.7578310265F,
  142624. 0.7609514077F, 0.7640523581F, 0.7671337237F, 0.7701953535F,
  142625. 0.7732371001F, 0.7762588195F, 0.7792603711F, 0.7822416178F,
  142626. 0.7852024259F, 0.7881426654F, 0.7910622097F, 0.7939609356F,
  142627. 0.7968387237F, 0.7996954579F, 0.8025310261F, 0.8053453193F,
  142628. 0.8081382324F, 0.8109096638F, 0.8136595156F, 0.8163876936F,
  142629. 0.8190941071F, 0.8217786690F, 0.8244412960F, 0.8270819086F,
  142630. 0.8297004305F, 0.8322967896F, 0.8348709171F, 0.8374227481F,
  142631. 0.8399522213F, 0.8424592789F, 0.8449438672F, 0.8474059356F,
  142632. 0.8498454378F, 0.8522623306F, 0.8546565748F, 0.8570281348F,
  142633. 0.8593769787F, 0.8617030779F, 0.8640064080F, 0.8662869477F,
  142634. 0.8685446796F, 0.8707795899F, 0.8729916682F, 0.8751809079F,
  142635. 0.8773473059F, 0.8794908626F, 0.8816115819F, 0.8837094713F,
  142636. 0.8857845418F, 0.8878368079F, 0.8898662874F, 0.8918730019F,
  142637. 0.8938569760F, 0.8958182380F, 0.8977568194F, 0.8996727552F,
  142638. 0.9015660837F, 0.9034368465F, 0.9052850885F, 0.9071108577F,
  142639. 0.9089142057F, 0.9106951869F, 0.9124538591F, 0.9141902832F,
  142640. 0.9159045233F, 0.9175966464F, 0.9192667228F, 0.9209148257F,
  142641. 0.9225410313F, 0.9241454187F, 0.9257280701F, 0.9272890704F,
  142642. 0.9288285075F, 0.9303464720F, 0.9318430576F, 0.9333183603F,
  142643. 0.9347724792F, 0.9362055158F, 0.9376175745F, 0.9390087622F,
  142644. 0.9403791881F, 0.9417289644F, 0.9430582055F, 0.9443670283F,
  142645. 0.9456555521F, 0.9469238986F, 0.9481721917F, 0.9494005577F,
  142646. 0.9506091252F, 0.9517980248F, 0.9529673894F, 0.9541173540F,
  142647. 0.9552480557F, 0.9563596334F, 0.9574522282F, 0.9585259830F,
  142648. 0.9595810428F, 0.9606175542F, 0.9616356656F, 0.9626355274F,
  142649. 0.9636172915F, 0.9645811114F, 0.9655271425F, 0.9664555414F,
  142650. 0.9673664664F, 0.9682600774F, 0.9691365355F, 0.9699960034F,
  142651. 0.9708386448F, 0.9716646250F, 0.9724741103F, 0.9732672685F,
  142652. 0.9740442683F, 0.9748052795F, 0.9755504729F, 0.9762800205F,
  142653. 0.9769940950F, 0.9776928703F, 0.9783765210F, 0.9790452223F,
  142654. 0.9796991504F, 0.9803384823F, 0.9809633954F, 0.9815740679F,
  142655. 0.9821706784F, 0.9827534063F, 0.9833224312F, 0.9838779332F,
  142656. 0.9844200928F, 0.9849490910F, 0.9854651087F, 0.9859683274F,
  142657. 0.9864589286F, 0.9869370940F, 0.9874030054F, 0.9878568447F,
  142658. 0.9882987937F, 0.9887290343F, 0.9891477481F, 0.9895551169F,
  142659. 0.9899513220F, 0.9903365446F, 0.9907109658F, 0.9910747662F,
  142660. 0.9914281260F, 0.9917712252F, 0.9921042433F, 0.9924273593F,
  142661. 0.9927407516F, 0.9930445982F, 0.9933390763F, 0.9936243626F,
  142662. 0.9939006331F, 0.9941680631F, 0.9944268269F, 0.9946770982F,
  142663. 0.9949190498F, 0.9951528537F, 0.9953786808F, 0.9955967011F,
  142664. 0.9958070836F, 0.9960099963F, 0.9962056061F, 0.9963940787F,
  142665. 0.9965755786F, 0.9967502693F, 0.9969183129F, 0.9970798704F,
  142666. 0.9972351013F, 0.9973841640F, 0.9975272151F, 0.9976644103F,
  142667. 0.9977959036F, 0.9979218476F, 0.9980423932F, 0.9981576901F,
  142668. 0.9982678862F, 0.9983731278F, 0.9984735596F, 0.9985693247F,
  142669. 0.9986605645F, 0.9987474186F, 0.9988300248F, 0.9989085193F,
  142670. 0.9989830364F, 0.9990537085F, 0.9991206662F, 0.9991840382F,
  142671. 0.9992439513F, 0.9993005303F, 0.9993538982F, 0.9994041757F,
  142672. 0.9994514817F, 0.9994959330F, 0.9995376444F, 0.9995767286F,
  142673. 0.9996132960F, 0.9996474550F, 0.9996793121F, 0.9997089710F,
  142674. 0.9997365339F, 0.9997621003F, 0.9997857677F, 0.9998076311F,
  142675. 0.9998277836F, 0.9998463156F, 0.9998633155F, 0.9998788692F,
  142676. 0.9998930603F, 0.9999059701F, 0.9999176774F, 0.9999282586F,
  142677. 0.9999377880F, 0.9999463370F, 0.9999539749F, 0.9999607685F,
  142678. 0.9999667820F, 0.9999720773F, 0.9999767136F, 0.9999807479F,
  142679. 0.9999842344F, 0.9999872249F, 0.9999897688F, 0.9999919127F,
  142680. 0.9999937009F, 0.9999951749F, 0.9999963738F, 0.9999973342F,
  142681. 0.9999980900F, 0.9999986724F, 0.9999991103F, 0.9999994297F,
  142682. 0.9999996543F, 0.9999998049F, 0.9999999000F, 0.9999999552F,
  142683. 0.9999999836F, 0.9999999957F, 0.9999999994F, 1.0000000000F,
  142684. };
  142685. static float vwin2048[1024] = {
  142686. 0.0000009241F, 0.0000083165F, 0.0000231014F, 0.0000452785F,
  142687. 0.0000748476F, 0.0001118085F, 0.0001561608F, 0.0002079041F,
  142688. 0.0002670379F, 0.0003335617F, 0.0004074748F, 0.0004887765F,
  142689. 0.0005774661F, 0.0006735427F, 0.0007770054F, 0.0008878533F,
  142690. 0.0010060853F, 0.0011317002F, 0.0012646969F, 0.0014050742F,
  142691. 0.0015528307F, 0.0017079650F, 0.0018704756F, 0.0020403610F,
  142692. 0.0022176196F, 0.0024022497F, 0.0025942495F, 0.0027936173F,
  142693. 0.0030003511F, 0.0032144490F, 0.0034359088F, 0.0036647286F,
  142694. 0.0039009061F, 0.0041444391F, 0.0043953253F, 0.0046535621F,
  142695. 0.0049191472F, 0.0051920781F, 0.0054723520F, 0.0057599664F,
  142696. 0.0060549184F, 0.0063572052F, 0.0066668239F, 0.0069837715F,
  142697. 0.0073080449F, 0.0076396410F, 0.0079785566F, 0.0083247884F,
  142698. 0.0086783330F, 0.0090391871F, 0.0094073470F, 0.0097828092F,
  142699. 0.0101655700F, 0.0105556258F, 0.0109529726F, 0.0113576065F,
  142700. 0.0117695237F, 0.0121887200F, 0.0126151913F, 0.0130489335F,
  142701. 0.0134899422F, 0.0139382130F, 0.0143937415F, 0.0148565233F,
  142702. 0.0153265536F, 0.0158038279F, 0.0162883413F, 0.0167800889F,
  142703. 0.0172790660F, 0.0177852675F, 0.0182986882F, 0.0188193231F,
  142704. 0.0193471668F, 0.0198822141F, 0.0204244594F, 0.0209738974F,
  142705. 0.0215305225F, 0.0220943289F, 0.0226653109F, 0.0232434627F,
  142706. 0.0238287784F, 0.0244212519F, 0.0250208772F, 0.0256276481F,
  142707. 0.0262415582F, 0.0268626014F, 0.0274907711F, 0.0281260608F,
  142708. 0.0287684638F, 0.0294179736F, 0.0300745833F, 0.0307382859F,
  142709. 0.0314090747F, 0.0320869424F, 0.0327718819F, 0.0334638860F,
  142710. 0.0341629474F, 0.0348690586F, 0.0355822122F, 0.0363024004F,
  142711. 0.0370296157F, 0.0377638502F, 0.0385050960F, 0.0392533451F,
  142712. 0.0400085896F, 0.0407708211F, 0.0415400315F, 0.0423162123F,
  142713. 0.0430993552F, 0.0438894515F, 0.0446864926F, 0.0454904698F,
  142714. 0.0463013742F, 0.0471191969F, 0.0479439288F, 0.0487755607F,
  142715. 0.0496140836F, 0.0504594879F, 0.0513117642F, 0.0521709031F,
  142716. 0.0530368949F, 0.0539097297F, 0.0547893979F, 0.0556758894F,
  142717. 0.0565691941F, 0.0574693019F, 0.0583762026F, 0.0592898858F,
  142718. 0.0602103410F, 0.0611375576F, 0.0620715250F, 0.0630122324F,
  142719. 0.0639596688F, 0.0649138234F, 0.0658746848F, 0.0668422421F,
  142720. 0.0678164838F, 0.0687973985F, 0.0697849746F, 0.0707792005F,
  142721. 0.0717800645F, 0.0727875547F, 0.0738016591F, 0.0748223656F,
  142722. 0.0758496620F, 0.0768835359F, 0.0779239751F, 0.0789709668F,
  142723. 0.0800244985F, 0.0810845574F, 0.0821511306F, 0.0832242052F,
  142724. 0.0843037679F, 0.0853898056F, 0.0864823050F, 0.0875812525F,
  142725. 0.0886866347F, 0.0897984378F, 0.0909166480F, 0.0920412513F,
  142726. 0.0931722338F, 0.0943095813F, 0.0954532795F, 0.0966033140F,
  142727. 0.0977596702F, 0.0989223336F, 0.1000912894F, 0.1012665227F,
  142728. 0.1024480185F, 0.1036357616F, 0.1048297369F, 0.1060299290F,
  142729. 0.1072363224F, 0.1084489014F, 0.1096676504F, 0.1108925534F,
  142730. 0.1121235946F, 0.1133607577F, 0.1146040267F, 0.1158533850F,
  142731. 0.1171088163F, 0.1183703040F, 0.1196378312F, 0.1209113812F,
  142732. 0.1221909370F, 0.1234764815F, 0.1247679974F, 0.1260654674F,
  142733. 0.1273688740F, 0.1286781995F, 0.1299934263F, 0.1313145365F,
  142734. 0.1326415121F, 0.1339743349F, 0.1353129866F, 0.1366574490F,
  142735. 0.1380077035F, 0.1393637315F, 0.1407255141F, 0.1420930325F,
  142736. 0.1434662677F, 0.1448452004F, 0.1462298115F, 0.1476200814F,
  142737. 0.1490159906F, 0.1504175195F, 0.1518246482F, 0.1532373569F,
  142738. 0.1546556253F, 0.1560794333F, 0.1575087606F, 0.1589435866F,
  142739. 0.1603838909F, 0.1618296526F, 0.1632808509F, 0.1647374648F,
  142740. 0.1661994731F, 0.1676668546F, 0.1691395880F, 0.1706176516F,
  142741. 0.1721010238F, 0.1735896829F, 0.1750836068F, 0.1765827736F,
  142742. 0.1780871610F, 0.1795967468F, 0.1811115084F, 0.1826314234F,
  142743. 0.1841564689F, 0.1856866221F, 0.1872218600F, 0.1887621595F,
  142744. 0.1903074974F, 0.1918578503F, 0.1934131947F, 0.1949735068F,
  142745. 0.1965387630F, 0.1981089393F, 0.1996840117F, 0.2012639560F,
  142746. 0.2028487479F, 0.2044383630F, 0.2060327766F, 0.2076319642F,
  142747. 0.2092359007F, 0.2108445614F, 0.2124579211F, 0.2140759545F,
  142748. 0.2156986364F, 0.2173259411F, 0.2189578432F, 0.2205943168F,
  142749. 0.2222353361F, 0.2238808751F, 0.2255309076F, 0.2271854073F,
  142750. 0.2288443480F, 0.2305077030F, 0.2321754457F, 0.2338475493F,
  142751. 0.2355239869F, 0.2372047315F, 0.2388897560F, 0.2405790329F,
  142752. 0.2422725350F, 0.2439702347F, 0.2456721043F, 0.2473781159F,
  142753. 0.2490882418F, 0.2508024539F, 0.2525207240F, 0.2542430237F,
  142754. 0.2559693248F, 0.2576995986F, 0.2594338166F, 0.2611719498F,
  142755. 0.2629139695F, 0.2646598466F, 0.2664095520F, 0.2681630564F,
  142756. 0.2699203304F, 0.2716813445F, 0.2734460691F, 0.2752144744F,
  142757. 0.2769865307F, 0.2787622079F, 0.2805414760F, 0.2823243047F,
  142758. 0.2841106637F, 0.2859005227F, 0.2876938509F, 0.2894906179F,
  142759. 0.2912907928F, 0.2930943447F, 0.2949012426F, 0.2967114554F,
  142760. 0.2985249520F, 0.3003417009F, 0.3021616708F, 0.3039848301F,
  142761. 0.3058111471F, 0.3076405901F, 0.3094731273F, 0.3113087266F,
  142762. 0.3131473560F, 0.3149889833F, 0.3168335762F, 0.3186811024F,
  142763. 0.3205315294F, 0.3223848245F, 0.3242409552F, 0.3260998886F,
  142764. 0.3279615918F, 0.3298260319F, 0.3316931758F, 0.3335629903F,
  142765. 0.3354354423F, 0.3373104982F, 0.3391881247F, 0.3410682882F,
  142766. 0.3429509551F, 0.3448360917F, 0.3467236642F, 0.3486136387F,
  142767. 0.3505059811F, 0.3524006575F, 0.3542976336F, 0.3561968753F,
  142768. 0.3580983482F, 0.3600020179F, 0.3619078499F, 0.3638158096F,
  142769. 0.3657258625F, 0.3676379737F, 0.3695521086F, 0.3714682321F,
  142770. 0.3733863094F, 0.3753063055F, 0.3772281852F, 0.3791519134F,
  142771. 0.3810774548F, 0.3830047742F, 0.3849338362F, 0.3868646053F,
  142772. 0.3887970459F, 0.3907311227F, 0.3926667998F, 0.3946040417F,
  142773. 0.3965428125F, 0.3984830765F, 0.4004247978F, 0.4023679403F,
  142774. 0.4043124683F, 0.4062583455F, 0.4082055359F, 0.4101540034F,
  142775. 0.4121037117F, 0.4140546246F, 0.4160067058F, 0.4179599190F,
  142776. 0.4199142277F, 0.4218695956F, 0.4238259861F, 0.4257833627F,
  142777. 0.4277416888F, 0.4297009279F, 0.4316610433F, 0.4336219983F,
  142778. 0.4355837562F, 0.4375462803F, 0.4395095337F, 0.4414734797F,
  142779. 0.4434380815F, 0.4454033021F, 0.4473691046F, 0.4493354521F,
  142780. 0.4513023078F, 0.4532696345F, 0.4552373954F, 0.4572055533F,
  142781. 0.4591740713F, 0.4611429123F, 0.4631120393F, 0.4650814151F,
  142782. 0.4670510028F, 0.4690207650F, 0.4709906649F, 0.4729606651F,
  142783. 0.4749307287F, 0.4769008185F, 0.4788708972F, 0.4808409279F,
  142784. 0.4828108732F, 0.4847806962F, 0.4867503597F, 0.4887198264F,
  142785. 0.4906890593F, 0.4926580213F, 0.4946266753F, 0.4965949840F,
  142786. 0.4985629105F, 0.5005304176F, 0.5024974683F, 0.5044640255F,
  142787. 0.5064300522F, 0.5083955114F, 0.5103603659F, 0.5123245790F,
  142788. 0.5142881136F, 0.5162509328F, 0.5182129997F, 0.5201742774F,
  142789. 0.5221347290F, 0.5240943178F, 0.5260530070F, 0.5280107598F,
  142790. 0.5299675395F, 0.5319233095F, 0.5338780330F, 0.5358316736F,
  142791. 0.5377841946F, 0.5397355596F, 0.5416857320F, 0.5436346755F,
  142792. 0.5455823538F, 0.5475287304F, 0.5494737691F, 0.5514174337F,
  142793. 0.5533596881F, 0.5553004962F, 0.5572398218F, 0.5591776291F,
  142794. 0.5611138821F, 0.5630485449F, 0.5649815818F, 0.5669129570F,
  142795. 0.5688426349F, 0.5707705799F, 0.5726967564F, 0.5746211290F,
  142796. 0.5765436624F, 0.5784643212F, 0.5803830702F, 0.5822998743F,
  142797. 0.5842146984F, 0.5861275076F, 0.5880382669F, 0.5899469416F,
  142798. 0.5918534968F, 0.5937578981F, 0.5956601107F, 0.5975601004F,
  142799. 0.5994578326F, 0.6013532732F, 0.6032463880F, 0.6051371429F,
  142800. 0.6070255039F, 0.6089114372F, 0.6107949090F, 0.6126758856F,
  142801. 0.6145543334F, 0.6164302191F, 0.6183035092F, 0.6201741706F,
  142802. 0.6220421700F, 0.6239074745F, 0.6257700513F, 0.6276298674F,
  142803. 0.6294868903F, 0.6313410873F, 0.6331924262F, 0.6350408745F,
  142804. 0.6368864001F, 0.6387289710F, 0.6405685552F, 0.6424051209F,
  142805. 0.6442386364F, 0.6460690702F, 0.6478963910F, 0.6497205673F,
  142806. 0.6515415682F, 0.6533593625F, 0.6551739194F, 0.6569852082F,
  142807. 0.6587931984F, 0.6605978593F, 0.6623991609F, 0.6641970728F,
  142808. 0.6659915652F, 0.6677826081F, 0.6695701718F, 0.6713542268F,
  142809. 0.6731347437F, 0.6749116932F, 0.6766850461F, 0.6784547736F,
  142810. 0.6802208469F, 0.6819832374F, 0.6837419164F, 0.6854968559F,
  142811. 0.6872480275F, 0.6889954034F, 0.6907389556F, 0.6924786566F,
  142812. 0.6942144788F, 0.6959463950F, 0.6976743780F, 0.6993984008F,
  142813. 0.7011184365F, 0.7028344587F, 0.7045464407F, 0.7062543564F,
  142814. 0.7079581796F, 0.7096578844F, 0.7113534450F, 0.7130448359F,
  142815. 0.7147320316F, 0.7164150070F, 0.7180937371F, 0.7197681970F,
  142816. 0.7214383620F, 0.7231042077F, 0.7247657098F, 0.7264228443F,
  142817. 0.7280755871F, 0.7297239147F, 0.7313678035F, 0.7330072301F,
  142818. 0.7346421715F, 0.7362726046F, 0.7378985069F, 0.7395198556F,
  142819. 0.7411366285F, 0.7427488034F, 0.7443563584F, 0.7459592717F,
  142820. 0.7475575218F, 0.7491510873F, 0.7507399471F, 0.7523240803F,
  142821. 0.7539034661F, 0.7554780839F, 0.7570479136F, 0.7586129349F,
  142822. 0.7601731279F, 0.7617284730F, 0.7632789506F, 0.7648245416F,
  142823. 0.7663652267F, 0.7679009872F, 0.7694318044F, 0.7709576599F,
  142824. 0.7724785354F, 0.7739944130F, 0.7755052749F, 0.7770111035F,
  142825. 0.7785118815F, 0.7800075916F, 0.7814982170F, 0.7829837410F,
  142826. 0.7844641472F, 0.7859394191F, 0.7874095408F, 0.7888744965F,
  142827. 0.7903342706F, 0.7917888476F, 0.7932382124F, 0.7946823501F,
  142828. 0.7961212460F, 0.7975548855F, 0.7989832544F, 0.8004063386F,
  142829. 0.8018241244F, 0.8032365981F, 0.8046437463F, 0.8060455560F,
  142830. 0.8074420141F, 0.8088331080F, 0.8102188253F, 0.8115991536F,
  142831. 0.8129740810F, 0.8143435957F, 0.8157076861F, 0.8170663409F,
  142832. 0.8184195489F, 0.8197672994F, 0.8211095817F, 0.8224463853F,
  142833. 0.8237777001F, 0.8251035161F, 0.8264238235F, 0.8277386129F,
  142834. 0.8290478750F, 0.8303516008F, 0.8316497814F, 0.8329424083F,
  142835. 0.8342294731F, 0.8355109677F, 0.8367868841F, 0.8380572148F,
  142836. 0.8393219523F, 0.8405810893F, 0.8418346190F, 0.8430825345F,
  142837. 0.8443248294F, 0.8455614974F, 0.8467925323F, 0.8480179285F,
  142838. 0.8492376802F, 0.8504517822F, 0.8516602292F, 0.8528630164F,
  142839. 0.8540601391F, 0.8552515928F, 0.8564373733F, 0.8576174766F,
  142840. 0.8587918990F, 0.8599606368F, 0.8611236868F, 0.8622810460F,
  142841. 0.8634327113F, 0.8645786802F, 0.8657189504F, 0.8668535195F,
  142842. 0.8679823857F, 0.8691055472F, 0.8702230025F, 0.8713347503F,
  142843. 0.8724407896F, 0.8735411194F, 0.8746357394F, 0.8757246489F,
  142844. 0.8768078479F, 0.8778853364F, 0.8789571146F, 0.8800231832F,
  142845. 0.8810835427F, 0.8821381942F, 0.8831871387F, 0.8842303777F,
  142846. 0.8852679127F, 0.8862997456F, 0.8873258784F, 0.8883463132F,
  142847. 0.8893610527F, 0.8903700994F, 0.8913734562F, 0.8923711263F,
  142848. 0.8933631129F, 0.8943494196F, 0.8953300500F, 0.8963050083F,
  142849. 0.8972742985F, 0.8982379249F, 0.8991958922F, 0.9001482052F,
  142850. 0.9010948688F, 0.9020358883F, 0.9029712690F, 0.9039010165F,
  142851. 0.9048251367F, 0.9057436357F, 0.9066565195F, 0.9075637946F,
  142852. 0.9084654678F, 0.9093615456F, 0.9102520353F, 0.9111369440F,
  142853. 0.9120162792F, 0.9128900484F, 0.9137582595F, 0.9146209204F,
  142854. 0.9154780394F, 0.9163296248F, 0.9171756853F, 0.9180162296F,
  142855. 0.9188512667F, 0.9196808057F, 0.9205048559F, 0.9213234270F,
  142856. 0.9221365285F, 0.9229441704F, 0.9237463629F, 0.9245431160F,
  142857. 0.9253344404F, 0.9261203465F, 0.9269008453F, 0.9276759477F,
  142858. 0.9284456648F, 0.9292100080F, 0.9299689889F, 0.9307226190F,
  142859. 0.9314709103F, 0.9322138747F, 0.9329515245F, 0.9336838721F,
  142860. 0.9344109300F, 0.9351327108F, 0.9358492275F, 0.9365604931F,
  142861. 0.9372665208F, 0.9379673239F, 0.9386629160F, 0.9393533107F,
  142862. 0.9400385220F, 0.9407185637F, 0.9413934501F, 0.9420631954F,
  142863. 0.9427278141F, 0.9433873208F, 0.9440417304F, 0.9446910576F,
  142864. 0.9453353176F, 0.9459745255F, 0.9466086968F, 0.9472378469F,
  142865. 0.9478619915F, 0.9484811463F, 0.9490953274F, 0.9497045506F,
  142866. 0.9503088323F, 0.9509081888F, 0.9515026365F, 0.9520921921F,
  142867. 0.9526768723F, 0.9532566940F, 0.9538316742F, 0.9544018300F,
  142868. 0.9549671786F, 0.9555277375F, 0.9560835241F, 0.9566345562F,
  142869. 0.9571808513F, 0.9577224275F, 0.9582593027F, 0.9587914949F,
  142870. 0.9593190225F, 0.9598419038F, 0.9603601571F, 0.9608738012F,
  142871. 0.9613828546F, 0.9618873361F, 0.9623872646F, 0.9628826591F,
  142872. 0.9633735388F, 0.9638599227F, 0.9643418303F, 0.9648192808F,
  142873. 0.9652922939F, 0.9657608890F, 0.9662250860F, 0.9666849046F,
  142874. 0.9671403646F, 0.9675914861F, 0.9680382891F, 0.9684807937F,
  142875. 0.9689190202F, 0.9693529890F, 0.9697827203F, 0.9702082347F,
  142876. 0.9706295529F, 0.9710466953F, 0.9714596828F, 0.9718685362F,
  142877. 0.9722732762F, 0.9726739240F, 0.9730705005F, 0.9734630267F,
  142878. 0.9738515239F, 0.9742360134F, 0.9746165163F, 0.9749930540F,
  142879. 0.9753656481F, 0.9757343198F, 0.9760990909F, 0.9764599829F,
  142880. 0.9768170175F, 0.9771702164F, 0.9775196013F, 0.9778651941F,
  142881. 0.9782070167F, 0.9785450909F, 0.9788794388F, 0.9792100824F,
  142882. 0.9795370437F, 0.9798603449F, 0.9801800080F, 0.9804960554F,
  142883. 0.9808085092F, 0.9811173916F, 0.9814227251F, 0.9817245318F,
  142884. 0.9820228343F, 0.9823176549F, 0.9826090160F, 0.9828969402F,
  142885. 0.9831814498F, 0.9834625674F, 0.9837403156F, 0.9840147169F,
  142886. 0.9842857939F, 0.9845535692F, 0.9848180654F, 0.9850793052F,
  142887. 0.9853373113F, 0.9855921062F, 0.9858437127F, 0.9860921535F,
  142888. 0.9863374512F, 0.9865796287F, 0.9868187085F, 0.9870547136F,
  142889. 0.9872876664F, 0.9875175899F, 0.9877445067F, 0.9879684396F,
  142890. 0.9881894112F, 0.9884074444F, 0.9886225619F, 0.9888347863F,
  142891. 0.9890441404F, 0.9892506468F, 0.9894543284F, 0.9896552077F,
  142892. 0.9898533074F, 0.9900486502F, 0.9902412587F, 0.9904311555F,
  142893. 0.9906183633F, 0.9908029045F, 0.9909848019F, 0.9911640779F,
  142894. 0.9913407550F, 0.9915148557F, 0.9916864025F, 0.9918554179F,
  142895. 0.9920219241F, 0.9921859437F, 0.9923474989F, 0.9925066120F,
  142896. 0.9926633054F, 0.9928176012F, 0.9929695218F, 0.9931190891F,
  142897. 0.9932663254F, 0.9934112527F, 0.9935538932F, 0.9936942686F,
  142898. 0.9938324012F, 0.9939683126F, 0.9941020248F, 0.9942335597F,
  142899. 0.9943629388F, 0.9944901841F, 0.9946153170F, 0.9947383593F,
  142900. 0.9948593325F, 0.9949782579F, 0.9950951572F, 0.9952100516F,
  142901. 0.9953229625F, 0.9954339111F, 0.9955429186F, 0.9956500062F,
  142902. 0.9957551948F, 0.9958585056F, 0.9959599593F, 0.9960595769F,
  142903. 0.9961573792F, 0.9962533869F, 0.9963476206F, 0.9964401009F,
  142904. 0.9965308483F, 0.9966198833F, 0.9967072261F, 0.9967928971F,
  142905. 0.9968769164F, 0.9969593041F, 0.9970400804F, 0.9971192651F,
  142906. 0.9971968781F, 0.9972729391F, 0.9973474680F, 0.9974204842F,
  142907. 0.9974920074F, 0.9975620569F, 0.9976306521F, 0.9976978122F,
  142908. 0.9977635565F, 0.9978279039F, 0.9978908736F, 0.9979524842F,
  142909. 0.9980127547F, 0.9980717037F, 0.9981293499F, 0.9981857116F,
  142910. 0.9982408073F, 0.9982946554F, 0.9983472739F, 0.9983986810F,
  142911. 0.9984488947F, 0.9984979328F, 0.9985458132F, 0.9985925534F,
  142912. 0.9986381711F, 0.9986826838F, 0.9987261086F, 0.9987684630F,
  142913. 0.9988097640F, 0.9988500286F, 0.9988892738F, 0.9989275163F,
  142914. 0.9989647727F, 0.9990010597F, 0.9990363938F, 0.9990707911F,
  142915. 0.9991042679F, 0.9991368404F, 0.9991685244F, 0.9991993358F,
  142916. 0.9992292905F, 0.9992584038F, 0.9992866914F, 0.9993141686F,
  142917. 0.9993408506F, 0.9993667526F, 0.9993918895F, 0.9994162761F,
  142918. 0.9994399273F, 0.9994628576F, 0.9994850815F, 0.9995066133F,
  142919. 0.9995274672F, 0.9995476574F, 0.9995671978F, 0.9995861021F,
  142920. 0.9996043841F, 0.9996220573F, 0.9996391352F, 0.9996556310F,
  142921. 0.9996715579F, 0.9996869288F, 0.9997017568F, 0.9997160543F,
  142922. 0.9997298342F, 0.9997431088F, 0.9997558905F, 0.9997681914F,
  142923. 0.9997800236F, 0.9997913990F, 0.9998023292F, 0.9998128261F,
  142924. 0.9998229009F, 0.9998325650F, 0.9998418296F, 0.9998507058F,
  142925. 0.9998592044F, 0.9998673362F, 0.9998751117F, 0.9998825415F,
  142926. 0.9998896358F, 0.9998964047F, 0.9999028584F, 0.9999090066F,
  142927. 0.9999148590F, 0.9999204253F, 0.9999257148F, 0.9999307368F,
  142928. 0.9999355003F, 0.9999400144F, 0.9999442878F, 0.9999483293F,
  142929. 0.9999521472F, 0.9999557499F, 0.9999591457F, 0.9999623426F,
  142930. 0.9999653483F, 0.9999681708F, 0.9999708175F, 0.9999732959F,
  142931. 0.9999756132F, 0.9999777765F, 0.9999797928F, 0.9999816688F,
  142932. 0.9999834113F, 0.9999850266F, 0.9999865211F, 0.9999879009F,
  142933. 0.9999891721F, 0.9999903405F, 0.9999914118F, 0.9999923914F,
  142934. 0.9999932849F, 0.9999940972F, 0.9999948336F, 0.9999954989F,
  142935. 0.9999960978F, 0.9999966349F, 0.9999971146F, 0.9999975411F,
  142936. 0.9999979185F, 0.9999982507F, 0.9999985414F, 0.9999987944F,
  142937. 0.9999990129F, 0.9999992003F, 0.9999993596F, 0.9999994939F,
  142938. 0.9999996059F, 0.9999996981F, 0.9999997732F, 0.9999998333F,
  142939. 0.9999998805F, 0.9999999170F, 0.9999999444F, 0.9999999643F,
  142940. 0.9999999784F, 0.9999999878F, 0.9999999937F, 0.9999999972F,
  142941. 0.9999999990F, 0.9999999997F, 1.0000000000F, 1.0000000000F,
  142942. };
  142943. static float vwin4096[2048] = {
  142944. 0.0000002310F, 0.0000020791F, 0.0000057754F, 0.0000113197F,
  142945. 0.0000187121F, 0.0000279526F, 0.0000390412F, 0.0000519777F,
  142946. 0.0000667623F, 0.0000833949F, 0.0001018753F, 0.0001222036F,
  142947. 0.0001443798F, 0.0001684037F, 0.0001942754F, 0.0002219947F,
  142948. 0.0002515616F, 0.0002829761F, 0.0003162380F, 0.0003513472F,
  142949. 0.0003883038F, 0.0004271076F, 0.0004677584F, 0.0005102563F,
  142950. 0.0005546011F, 0.0006007928F, 0.0006488311F, 0.0006987160F,
  142951. 0.0007504474F, 0.0008040251F, 0.0008594490F, 0.0009167191F,
  142952. 0.0009758351F, 0.0010367969F, 0.0010996044F, 0.0011642574F,
  142953. 0.0012307558F, 0.0012990994F, 0.0013692880F, 0.0014413216F,
  142954. 0.0015151998F, 0.0015909226F, 0.0016684898F, 0.0017479011F,
  142955. 0.0018291565F, 0.0019122556F, 0.0019971983F, 0.0020839845F,
  142956. 0.0021726138F, 0.0022630861F, 0.0023554012F, 0.0024495588F,
  142957. 0.0025455588F, 0.0026434008F, 0.0027430847F, 0.0028446103F,
  142958. 0.0029479772F, 0.0030531853F, 0.0031602342F, 0.0032691238F,
  142959. 0.0033798538F, 0.0034924239F, 0.0036068338F, 0.0037230833F,
  142960. 0.0038411721F, 0.0039610999F, 0.0040828664F, 0.0042064714F,
  142961. 0.0043319145F, 0.0044591954F, 0.0045883139F, 0.0047192696F,
  142962. 0.0048520622F, 0.0049866914F, 0.0051231569F, 0.0052614583F,
  142963. 0.0054015953F, 0.0055435676F, 0.0056873748F, 0.0058330166F,
  142964. 0.0059804926F, 0.0061298026F, 0.0062809460F, 0.0064339226F,
  142965. 0.0065887320F, 0.0067453738F, 0.0069038476F, 0.0070641531F,
  142966. 0.0072262899F, 0.0073902575F, 0.0075560556F, 0.0077236838F,
  142967. 0.0078931417F, 0.0080644288F, 0.0082375447F, 0.0084124891F,
  142968. 0.0085892615F, 0.0087678614F, 0.0089482885F, 0.0091305422F,
  142969. 0.0093146223F, 0.0095005281F, 0.0096882592F, 0.0098778153F,
  142970. 0.0100691958F, 0.0102624002F, 0.0104574281F, 0.0106542791F,
  142971. 0.0108529525F, 0.0110534480F, 0.0112557651F, 0.0114599032F,
  142972. 0.0116658618F, 0.0118736405F, 0.0120832387F, 0.0122946560F,
  142973. 0.0125078917F, 0.0127229454F, 0.0129398166F, 0.0131585046F,
  142974. 0.0133790090F, 0.0136013292F, 0.0138254647F, 0.0140514149F,
  142975. 0.0142791792F, 0.0145087572F, 0.0147401481F, 0.0149733515F,
  142976. 0.0152083667F, 0.0154451932F, 0.0156838304F, 0.0159242777F,
  142977. 0.0161665345F, 0.0164106001F, 0.0166564741F, 0.0169041557F,
  142978. 0.0171536443F, 0.0174049393F, 0.0176580401F, 0.0179129461F,
  142979. 0.0181696565F, 0.0184281708F, 0.0186884883F, 0.0189506084F,
  142980. 0.0192145303F, 0.0194802535F, 0.0197477772F, 0.0200171008F,
  142981. 0.0202882236F, 0.0205611449F, 0.0208358639F, 0.0211123801F,
  142982. 0.0213906927F, 0.0216708011F, 0.0219527043F, 0.0222364019F,
  142983. 0.0225218930F, 0.0228091769F, 0.0230982529F, 0.0233891203F,
  142984. 0.0236817782F, 0.0239762259F, 0.0242724628F, 0.0245704880F,
  142985. 0.0248703007F, 0.0251719002F, 0.0254752858F, 0.0257804565F,
  142986. 0.0260874117F, 0.0263961506F, 0.0267066722F, 0.0270189760F,
  142987. 0.0273330609F, 0.0276489263F, 0.0279665712F, 0.0282859949F,
  142988. 0.0286071966F, 0.0289301753F, 0.0292549303F, 0.0295814607F,
  142989. 0.0299097656F, 0.0302398442F, 0.0305716957F, 0.0309053191F,
  142990. 0.0312407135F, 0.0315778782F, 0.0319168122F, 0.0322575145F,
  142991. 0.0325999844F, 0.0329442209F, 0.0332902231F, 0.0336379900F,
  142992. 0.0339875208F, 0.0343388146F, 0.0346918703F, 0.0350466871F,
  142993. 0.0354032640F, 0.0357616000F, 0.0361216943F, 0.0364835458F,
  142994. 0.0368471535F, 0.0372125166F, 0.0375796339F, 0.0379485046F,
  142995. 0.0383191276F, 0.0386915020F, 0.0390656267F, 0.0394415008F,
  142996. 0.0398191231F, 0.0401984927F, 0.0405796086F, 0.0409624698F,
  142997. 0.0413470751F, 0.0417334235F, 0.0421215141F, 0.0425113457F,
  142998. 0.0429029172F, 0.0432962277F, 0.0436912760F, 0.0440880610F,
  142999. 0.0444865817F, 0.0448868370F, 0.0452888257F, 0.0456925468F,
  143000. 0.0460979992F, 0.0465051816F, 0.0469140931F, 0.0473247325F,
  143001. 0.0477370986F, 0.0481511902F, 0.0485670064F, 0.0489845458F,
  143002. 0.0494038074F, 0.0498247899F, 0.0502474922F, 0.0506719131F,
  143003. 0.0510980514F, 0.0515259060F, 0.0519554756F, 0.0523867590F,
  143004. 0.0528197550F, 0.0532544624F, 0.0536908800F, 0.0541290066F,
  143005. 0.0545688408F, 0.0550103815F, 0.0554536274F, 0.0558985772F,
  143006. 0.0563452297F, 0.0567935837F, 0.0572436377F, 0.0576953907F,
  143007. 0.0581488412F, 0.0586039880F, 0.0590608297F, 0.0595193651F,
  143008. 0.0599795929F, 0.0604415117F, 0.0609051202F, 0.0613704170F,
  143009. 0.0618374009F, 0.0623060704F, 0.0627764243F, 0.0632484611F,
  143010. 0.0637221795F, 0.0641975781F, 0.0646746555F, 0.0651534104F,
  143011. 0.0656338413F, 0.0661159469F, 0.0665997257F, 0.0670851763F,
  143012. 0.0675722973F, 0.0680610873F, 0.0685515448F, 0.0690436684F,
  143013. 0.0695374567F, 0.0700329081F, 0.0705300213F, 0.0710287947F,
  143014. 0.0715292269F, 0.0720313163F, 0.0725350616F, 0.0730404612F,
  143015. 0.0735475136F, 0.0740562172F, 0.0745665707F, 0.0750785723F,
  143016. 0.0755922207F, 0.0761075143F, 0.0766244515F, 0.0771430307F,
  143017. 0.0776632505F, 0.0781851092F, 0.0787086052F, 0.0792337371F,
  143018. 0.0797605032F, 0.0802889018F, 0.0808189315F, 0.0813505905F,
  143019. 0.0818838773F, 0.0824187903F, 0.0829553277F, 0.0834934881F,
  143020. 0.0840332697F, 0.0845746708F, 0.0851176899F, 0.0856623252F,
  143021. 0.0862085751F, 0.0867564379F, 0.0873059119F, 0.0878569954F,
  143022. 0.0884096867F, 0.0889639840F, 0.0895198858F, 0.0900773902F,
  143023. 0.0906364955F, 0.0911972000F, 0.0917595019F, 0.0923233995F,
  143024. 0.0928888909F, 0.0934559745F, 0.0940246485F, 0.0945949110F,
  143025. 0.0951667604F, 0.0957401946F, 0.0963152121F, 0.0968918109F,
  143026. 0.0974699893F, 0.0980497454F, 0.0986310773F, 0.0992139832F,
  143027. 0.0997984614F, 0.1003845098F, 0.1009721267F, 0.1015613101F,
  143028. 0.1021520582F, 0.1027443692F, 0.1033382410F, 0.1039336718F,
  143029. 0.1045306597F, 0.1051292027F, 0.1057292990F, 0.1063309466F,
  143030. 0.1069341435F, 0.1075388878F, 0.1081451776F, 0.1087530108F,
  143031. 0.1093623856F, 0.1099732998F, 0.1105857516F, 0.1111997389F,
  143032. 0.1118152597F, 0.1124323121F, 0.1130508939F, 0.1136710032F,
  143033. 0.1142926379F, 0.1149157960F, 0.1155404755F, 0.1161666742F,
  143034. 0.1167943901F, 0.1174236211F, 0.1180543652F, 0.1186866202F,
  143035. 0.1193203841F, 0.1199556548F, 0.1205924300F, 0.1212307078F,
  143036. 0.1218704860F, 0.1225117624F, 0.1231545349F, 0.1237988013F,
  143037. 0.1244445596F, 0.1250918074F, 0.1257405427F, 0.1263907632F,
  143038. 0.1270424667F, 0.1276956512F, 0.1283503142F, 0.1290064537F,
  143039. 0.1296640674F, 0.1303231530F, 0.1309837084F, 0.1316457312F,
  143040. 0.1323092193F, 0.1329741703F, 0.1336405820F, 0.1343084520F,
  143041. 0.1349777782F, 0.1356485582F, 0.1363207897F, 0.1369944704F,
  143042. 0.1376695979F, 0.1383461700F, 0.1390241842F, 0.1397036384F,
  143043. 0.1403845300F, 0.1410668567F, 0.1417506162F, 0.1424358061F,
  143044. 0.1431224240F, 0.1438104674F, 0.1444999341F, 0.1451908216F,
  143045. 0.1458831274F, 0.1465768492F, 0.1472719844F, 0.1479685308F,
  143046. 0.1486664857F, 0.1493658468F, 0.1500666115F, 0.1507687775F,
  143047. 0.1514723422F, 0.1521773031F, 0.1528836577F, 0.1535914035F,
  143048. 0.1543005380F, 0.1550110587F, 0.1557229631F, 0.1564362485F,
  143049. 0.1571509124F, 0.1578669524F, 0.1585843657F, 0.1593031499F,
  143050. 0.1600233024F, 0.1607448205F, 0.1614677017F, 0.1621919433F,
  143051. 0.1629175428F, 0.1636444975F, 0.1643728047F, 0.1651024619F,
  143052. 0.1658334665F, 0.1665658156F, 0.1672995067F, 0.1680345371F,
  143053. 0.1687709041F, 0.1695086050F, 0.1702476372F, 0.1709879978F,
  143054. 0.1717296843F, 0.1724726938F, 0.1732170237F, 0.1739626711F,
  143055. 0.1747096335F, 0.1754579079F, 0.1762074916F, 0.1769583819F,
  143056. 0.1777105760F, 0.1784640710F, 0.1792188642F, 0.1799749529F,
  143057. 0.1807323340F, 0.1814910049F, 0.1822509628F, 0.1830122046F,
  143058. 0.1837747277F, 0.1845385292F, 0.1853036062F, 0.1860699558F,
  143059. 0.1868375751F, 0.1876064613F, 0.1883766114F, 0.1891480226F,
  143060. 0.1899206919F, 0.1906946164F, 0.1914697932F, 0.1922462194F,
  143061. 0.1930238919F, 0.1938028079F, 0.1945829643F, 0.1953643583F,
  143062. 0.1961469868F, 0.1969308468F, 0.1977159353F, 0.1985022494F,
  143063. 0.1992897859F, 0.2000785420F, 0.2008685145F, 0.2016597005F,
  143064. 0.2024520968F, 0.2032457005F, 0.2040405084F, 0.2048365175F,
  143065. 0.2056337247F, 0.2064321269F, 0.2072317211F, 0.2080325041F,
  143066. 0.2088344727F, 0.2096376240F, 0.2104419547F, 0.2112474618F,
  143067. 0.2120541420F, 0.2128619923F, 0.2136710094F, 0.2144811902F,
  143068. 0.2152925315F, 0.2161050301F, 0.2169186829F, 0.2177334866F,
  143069. 0.2185494381F, 0.2193665340F, 0.2201847712F, 0.2210041465F,
  143070. 0.2218246565F, 0.2226462981F, 0.2234690680F, 0.2242929629F,
  143071. 0.2251179796F, 0.2259441147F, 0.2267713650F, 0.2275997272F,
  143072. 0.2284291979F, 0.2292597739F, 0.2300914518F, 0.2309242283F,
  143073. 0.2317581001F, 0.2325930638F, 0.2334291160F, 0.2342662534F,
  143074. 0.2351044727F, 0.2359437703F, 0.2367841431F, 0.2376255875F,
  143075. 0.2384681001F, 0.2393116776F, 0.2401563165F, 0.2410020134F,
  143076. 0.2418487649F, 0.2426965675F, 0.2435454178F, 0.2443953122F,
  143077. 0.2452462474F, 0.2460982199F, 0.2469512262F, 0.2478052628F,
  143078. 0.2486603262F, 0.2495164129F, 0.2503735194F, 0.2512316421F,
  143079. 0.2520907776F, 0.2529509222F, 0.2538120726F, 0.2546742250F,
  143080. 0.2555373760F, 0.2564015219F, 0.2572666593F, 0.2581327845F,
  143081. 0.2589998939F, 0.2598679840F, 0.2607370510F, 0.2616070916F,
  143082. 0.2624781019F, 0.2633500783F, 0.2642230173F, 0.2650969152F,
  143083. 0.2659717684F, 0.2668475731F, 0.2677243257F, 0.2686020226F,
  143084. 0.2694806601F, 0.2703602344F, 0.2712407419F, 0.2721221789F,
  143085. 0.2730045417F, 0.2738878265F, 0.2747720297F, 0.2756571474F,
  143086. 0.2765431760F, 0.2774301117F, 0.2783179508F, 0.2792066895F,
  143087. 0.2800963240F, 0.2809868505F, 0.2818782654F, 0.2827705647F,
  143088. 0.2836637447F, 0.2845578016F, 0.2854527315F, 0.2863485307F,
  143089. 0.2872451953F, 0.2881427215F, 0.2890411055F, 0.2899403433F,
  143090. 0.2908404312F, 0.2917413654F, 0.2926431418F, 0.2935457567F,
  143091. 0.2944492061F, 0.2953534863F, 0.2962585932F, 0.2971645230F,
  143092. 0.2980712717F, 0.2989788356F, 0.2998872105F, 0.3007963927F,
  143093. 0.3017063781F, 0.3026171629F, 0.3035287430F, 0.3044411145F,
  143094. 0.3053542736F, 0.3062682161F, 0.3071829381F, 0.3080984356F,
  143095. 0.3090147047F, 0.3099317413F, 0.3108495414F, 0.3117681011F,
  143096. 0.3126874163F, 0.3136074830F, 0.3145282972F, 0.3154498548F,
  143097. 0.3163721517F, 0.3172951841F, 0.3182189477F, 0.3191434385F,
  143098. 0.3200686525F, 0.3209945856F, 0.3219212336F, 0.3228485927F,
  143099. 0.3237766585F, 0.3247054271F, 0.3256348943F, 0.3265650560F,
  143100. 0.3274959081F, 0.3284274465F, 0.3293596671F, 0.3302925657F,
  143101. 0.3312261382F, 0.3321603804F, 0.3330952882F, 0.3340308574F,
  143102. 0.3349670838F, 0.3359039634F, 0.3368414919F, 0.3377796651F,
  143103. 0.3387184789F, 0.3396579290F, 0.3405980113F, 0.3415387216F,
  143104. 0.3424800556F, 0.3434220091F, 0.3443645779F, 0.3453077578F,
  143105. 0.3462515446F, 0.3471959340F, 0.3481409217F, 0.3490865036F,
  143106. 0.3500326754F, 0.3509794328F, 0.3519267715F, 0.3528746873F,
  143107. 0.3538231759F, 0.3547722330F, 0.3557218544F, 0.3566720357F,
  143108. 0.3576227727F, 0.3585740610F, 0.3595258964F, 0.3604782745F,
  143109. 0.3614311910F, 0.3623846417F, 0.3633386221F, 0.3642931280F,
  143110. 0.3652481549F, 0.3662036987F, 0.3671597548F, 0.3681163191F,
  143111. 0.3690733870F, 0.3700309544F, 0.3709890167F, 0.3719475696F,
  143112. 0.3729066089F, 0.3738661299F, 0.3748261285F, 0.3757866002F,
  143113. 0.3767475406F, 0.3777089453F, 0.3786708100F, 0.3796331302F,
  143114. 0.3805959014F, 0.3815591194F, 0.3825227796F, 0.3834868777F,
  143115. 0.3844514093F, 0.3854163698F, 0.3863817549F, 0.3873475601F,
  143116. 0.3883137810F, 0.3892804131F, 0.3902474521F, 0.3912148933F,
  143117. 0.3921827325F, 0.3931509650F, 0.3941195865F, 0.3950885925F,
  143118. 0.3960579785F, 0.3970277400F, 0.3979978725F, 0.3989683716F,
  143119. 0.3999392328F, 0.4009104516F, 0.4018820234F, 0.4028539438F,
  143120. 0.4038262084F, 0.4047988125F, 0.4057717516F, 0.4067450214F,
  143121. 0.4077186172F, 0.4086925345F, 0.4096667688F, 0.4106413155F,
  143122. 0.4116161703F, 0.4125913284F, 0.4135667854F, 0.4145425368F,
  143123. 0.4155185780F, 0.4164949044F, 0.4174715116F, 0.4184483949F,
  143124. 0.4194255498F, 0.4204029718F, 0.4213806563F, 0.4223585987F,
  143125. 0.4233367946F, 0.4243152392F, 0.4252939281F, 0.4262728566F,
  143126. 0.4272520202F, 0.4282314144F, 0.4292110345F, 0.4301908760F,
  143127. 0.4311709343F, 0.4321512047F, 0.4331316828F, 0.4341123639F,
  143128. 0.4350932435F, 0.4360743168F, 0.4370555794F, 0.4380370267F,
  143129. 0.4390186540F, 0.4400004567F, 0.4409824303F, 0.4419645701F,
  143130. 0.4429468716F, 0.4439293300F, 0.4449119409F, 0.4458946996F,
  143131. 0.4468776014F, 0.4478606418F, 0.4488438162F, 0.4498271199F,
  143132. 0.4508105483F, 0.4517940967F, 0.4527777607F, 0.4537615355F,
  143133. 0.4547454165F, 0.4557293991F, 0.4567134786F, 0.4576976505F,
  143134. 0.4586819101F, 0.4596662527F, 0.4606506738F, 0.4616351687F,
  143135. 0.4626197328F, 0.4636043614F, 0.4645890499F, 0.4655737936F,
  143136. 0.4665585880F, 0.4675434284F, 0.4685283101F, 0.4695132286F,
  143137. 0.4704981791F, 0.4714831570F, 0.4724681577F, 0.4734531766F,
  143138. 0.4744382089F, 0.4754232501F, 0.4764082956F, 0.4773933406F,
  143139. 0.4783783806F, 0.4793634108F, 0.4803484267F, 0.4813334237F,
  143140. 0.4823183969F, 0.4833033419F, 0.4842882540F, 0.4852731285F,
  143141. 0.4862579608F, 0.4872427462F, 0.4882274802F, 0.4892121580F,
  143142. 0.4901967751F, 0.4911813267F, 0.4921658083F, 0.4931502151F,
  143143. 0.4941345427F, 0.4951187863F, 0.4961029412F, 0.4970870029F,
  143144. 0.4980709667F, 0.4990548280F, 0.5000385822F, 0.5010222245F,
  143145. 0.5020057505F, 0.5029891553F, 0.5039724345F, 0.5049555834F,
  143146. 0.5059385973F, 0.5069214716F, 0.5079042018F, 0.5088867831F,
  143147. 0.5098692110F, 0.5108514808F, 0.5118335879F, 0.5128155277F,
  143148. 0.5137972956F, 0.5147788869F, 0.5157602971F, 0.5167415215F,
  143149. 0.5177225555F, 0.5187033945F, 0.5196840339F, 0.5206644692F,
  143150. 0.5216446956F, 0.5226247086F, 0.5236045035F, 0.5245840759F,
  143151. 0.5255634211F, 0.5265425344F, 0.5275214114F, 0.5285000474F,
  143152. 0.5294784378F, 0.5304565781F, 0.5314344637F, 0.5324120899F,
  143153. 0.5333894522F, 0.5343665461F, 0.5353433670F, 0.5363199102F,
  143154. 0.5372961713F, 0.5382721457F, 0.5392478287F, 0.5402232159F,
  143155. 0.5411983027F, 0.5421730845F, 0.5431475569F, 0.5441217151F,
  143156. 0.5450955548F, 0.5460690714F, 0.5470422602F, 0.5480151169F,
  143157. 0.5489876368F, 0.5499598155F, 0.5509316484F, 0.5519031310F,
  143158. 0.5528742587F, 0.5538450271F, 0.5548154317F, 0.5557854680F,
  143159. 0.5567551314F, 0.5577244174F, 0.5586933216F, 0.5596618395F,
  143160. 0.5606299665F, 0.5615976983F, 0.5625650302F, 0.5635319580F,
  143161. 0.5644984770F, 0.5654645828F, 0.5664302709F, 0.5673955370F,
  143162. 0.5683603765F, 0.5693247850F, 0.5702887580F, 0.5712522912F,
  143163. 0.5722153800F, 0.5731780200F, 0.5741402069F, 0.5751019362F,
  143164. 0.5760632034F, 0.5770240042F, 0.5779843341F, 0.5789441889F,
  143165. 0.5799035639F, 0.5808624549F, 0.5818208575F, 0.5827787673F,
  143166. 0.5837361800F, 0.5846930910F, 0.5856494961F, 0.5866053910F,
  143167. 0.5875607712F, 0.5885156324F, 0.5894699703F, 0.5904237804F,
  143168. 0.5913770586F, 0.5923298004F, 0.5932820016F, 0.5942336578F,
  143169. 0.5951847646F, 0.5961353179F, 0.5970853132F, 0.5980347464F,
  143170. 0.5989836131F, 0.5999319090F, 0.6008796298F, 0.6018267713F,
  143171. 0.6027733292F, 0.6037192993F, 0.6046646773F, 0.6056094589F,
  143172. 0.6065536400F, 0.6074972162F, 0.6084401833F, 0.6093825372F,
  143173. 0.6103242736F, 0.6112653884F, 0.6122058772F, 0.6131457359F,
  143174. 0.6140849604F, 0.6150235464F, 0.6159614897F, 0.6168987862F,
  143175. 0.6178354318F, 0.6187714223F, 0.6197067535F, 0.6206414213F,
  143176. 0.6215754215F, 0.6225087501F, 0.6234414028F, 0.6243733757F,
  143177. 0.6253046646F, 0.6262352654F, 0.6271651739F, 0.6280943862F,
  143178. 0.6290228982F, 0.6299507057F, 0.6308778048F, 0.6318041913F,
  143179. 0.6327298612F, 0.6336548105F, 0.6345790352F, 0.6355025312F,
  143180. 0.6364252945F, 0.6373473211F, 0.6382686070F, 0.6391891483F,
  143181. 0.6401089409F, 0.6410279808F, 0.6419462642F, 0.6428637869F,
  143182. 0.6437805452F, 0.6446965350F, 0.6456117524F, 0.6465261935F,
  143183. 0.6474398544F, 0.6483527311F, 0.6492648197F, 0.6501761165F,
  143184. 0.6510866174F, 0.6519963186F, 0.6529052162F, 0.6538133064F,
  143185. 0.6547205854F, 0.6556270492F, 0.6565326941F, 0.6574375162F,
  143186. 0.6583415117F, 0.6592446769F, 0.6601470079F, 0.6610485009F,
  143187. 0.6619491521F, 0.6628489578F, 0.6637479143F, 0.6646460177F,
  143188. 0.6655432643F, 0.6664396505F, 0.6673351724F, 0.6682298264F,
  143189. 0.6691236087F, 0.6700165157F, 0.6709085436F, 0.6717996889F,
  143190. 0.6726899478F, 0.6735793167F, 0.6744677918F, 0.6753553697F,
  143191. 0.6762420466F, 0.6771278190F, 0.6780126832F, 0.6788966357F,
  143192. 0.6797796728F, 0.6806617909F, 0.6815429866F, 0.6824232562F,
  143193. 0.6833025961F, 0.6841810030F, 0.6850584731F, 0.6859350031F,
  143194. 0.6868105894F, 0.6876852284F, 0.6885589168F, 0.6894316510F,
  143195. 0.6903034275F, 0.6911742430F, 0.6920440939F, 0.6929129769F,
  143196. 0.6937808884F, 0.6946478251F, 0.6955137837F, 0.6963787606F,
  143197. 0.6972427525F, 0.6981057560F, 0.6989677678F, 0.6998287845F,
  143198. 0.7006888028F, 0.7015478194F, 0.7024058309F, 0.7032628340F,
  143199. 0.7041188254F, 0.7049738019F, 0.7058277601F, 0.7066806969F,
  143200. 0.7075326089F, 0.7083834929F, 0.7092333457F, 0.7100821640F,
  143201. 0.7109299447F, 0.7117766846F, 0.7126223804F, 0.7134670291F,
  143202. 0.7143106273F, 0.7151531721F, 0.7159946602F, 0.7168350885F,
  143203. 0.7176744539F, 0.7185127534F, 0.7193499837F, 0.7201861418F,
  143204. 0.7210212247F, 0.7218552293F, 0.7226881526F, 0.7235199914F,
  143205. 0.7243507428F, 0.7251804039F, 0.7260089715F, 0.7268364426F,
  143206. 0.7276628144F, 0.7284880839F, 0.7293122481F, 0.7301353040F,
  143207. 0.7309572487F, 0.7317780794F, 0.7325977930F, 0.7334163868F,
  143208. 0.7342338579F, 0.7350502033F, 0.7358654202F, 0.7366795059F,
  143209. 0.7374924573F, 0.7383042718F, 0.7391149465F, 0.7399244787F,
  143210. 0.7407328655F, 0.7415401041F, 0.7423461920F, 0.7431511261F,
  143211. 0.7439549040F, 0.7447575227F, 0.7455589797F, 0.7463592723F,
  143212. 0.7471583976F, 0.7479563532F, 0.7487531363F, 0.7495487443F,
  143213. 0.7503431745F, 0.7511364244F, 0.7519284913F, 0.7527193726F,
  143214. 0.7535090658F, 0.7542975683F, 0.7550848776F, 0.7558709910F,
  143215. 0.7566559062F, 0.7574396205F, 0.7582221314F, 0.7590034366F,
  143216. 0.7597835334F, 0.7605624194F, 0.7613400923F, 0.7621165495F,
  143217. 0.7628917886F, 0.7636658072F, 0.7644386030F, 0.7652101735F,
  143218. 0.7659805164F, 0.7667496292F, 0.7675175098F, 0.7682841556F,
  143219. 0.7690495645F, 0.7698137341F, 0.7705766622F, 0.7713383463F,
  143220. 0.7720987844F, 0.7728579741F, 0.7736159132F, 0.7743725994F,
  143221. 0.7751280306F, 0.7758822046F, 0.7766351192F, 0.7773867722F,
  143222. 0.7781371614F, 0.7788862848F, 0.7796341401F, 0.7803807253F,
  143223. 0.7811260383F, 0.7818700769F, 0.7826128392F, 0.7833543230F,
  143224. 0.7840945263F, 0.7848334471F, 0.7855710833F, 0.7863074330F,
  143225. 0.7870424941F, 0.7877762647F, 0.7885087428F, 0.7892399264F,
  143226. 0.7899698137F, 0.7906984026F, 0.7914256914F, 0.7921516780F,
  143227. 0.7928763607F, 0.7935997375F, 0.7943218065F, 0.7950425661F,
  143228. 0.7957620142F, 0.7964801492F, 0.7971969692F, 0.7979124724F,
  143229. 0.7986266570F, 0.7993395214F, 0.8000510638F, 0.8007612823F,
  143230. 0.8014701754F, 0.8021777413F, 0.8028839784F, 0.8035888849F,
  143231. 0.8042924592F, 0.8049946997F, 0.8056956048F, 0.8063951727F,
  143232. 0.8070934020F, 0.8077902910F, 0.8084858381F, 0.8091800419F,
  143233. 0.8098729007F, 0.8105644130F, 0.8112545774F, 0.8119433922F,
  143234. 0.8126308561F, 0.8133169676F, 0.8140017251F, 0.8146851272F,
  143235. 0.8153671726F, 0.8160478598F, 0.8167271874F, 0.8174051539F,
  143236. 0.8180817582F, 0.8187569986F, 0.8194308741F, 0.8201033831F,
  143237. 0.8207745244F, 0.8214442966F, 0.8221126986F, 0.8227797290F,
  143238. 0.8234453865F, 0.8241096700F, 0.8247725781F, 0.8254341097F,
  143239. 0.8260942636F, 0.8267530385F, 0.8274104334F, 0.8280664470F,
  143240. 0.8287210782F, 0.8293743259F, 0.8300261889F, 0.8306766662F,
  143241. 0.8313257566F, 0.8319734591F, 0.8326197727F, 0.8332646963F,
  143242. 0.8339082288F, 0.8345503692F, 0.8351911167F, 0.8358304700F,
  143243. 0.8364684284F, 0.8371049907F, 0.8377401562F, 0.8383739238F,
  143244. 0.8390062927F, 0.8396372618F, 0.8402668305F, 0.8408949977F,
  143245. 0.8415217626F, 0.8421471245F, 0.8427710823F, 0.8433936354F,
  143246. 0.8440147830F, 0.8446345242F, 0.8452528582F, 0.8458697844F,
  143247. 0.8464853020F, 0.8470994102F, 0.8477121084F, 0.8483233958F,
  143248. 0.8489332718F, 0.8495417356F, 0.8501487866F, 0.8507544243F,
  143249. 0.8513586479F, 0.8519614568F, 0.8525628505F, 0.8531628283F,
  143250. 0.8537613897F, 0.8543585341F, 0.8549542611F, 0.8555485699F,
  143251. 0.8561414603F, 0.8567329315F, 0.8573229832F, 0.8579116149F,
  143252. 0.8584988262F, 0.8590846165F, 0.8596689855F, 0.8602519327F,
  143253. 0.8608334577F, 0.8614135603F, 0.8619922399F, 0.8625694962F,
  143254. 0.8631453289F, 0.8637197377F, 0.8642927222F, 0.8648642821F,
  143255. 0.8654344172F, 0.8660031272F, 0.8665704118F, 0.8671362708F,
  143256. 0.8677007039F, 0.8682637109F, 0.8688252917F, 0.8693854460F,
  143257. 0.8699441737F, 0.8705014745F, 0.8710573485F, 0.8716117953F,
  143258. 0.8721648150F, 0.8727164073F, 0.8732665723F, 0.8738153098F,
  143259. 0.8743626197F, 0.8749085021F, 0.8754529569F, 0.8759959840F,
  143260. 0.8765375835F, 0.8770777553F, 0.8776164996F, 0.8781538162F,
  143261. 0.8786897054F, 0.8792241670F, 0.8797572013F, 0.8802888082F,
  143262. 0.8808189880F, 0.8813477407F, 0.8818750664F, 0.8824009653F,
  143263. 0.8829254375F, 0.8834484833F, 0.8839701028F, 0.8844902961F,
  143264. 0.8850090636F, 0.8855264054F, 0.8860423218F, 0.8865568131F,
  143265. 0.8870698794F, 0.8875815212F, 0.8880917386F, 0.8886005319F,
  143266. 0.8891079016F, 0.8896138479F, 0.8901183712F, 0.8906214719F,
  143267. 0.8911231503F, 0.8916234067F, 0.8921222417F, 0.8926196556F,
  143268. 0.8931156489F, 0.8936102219F, 0.8941033752F, 0.8945951092F,
  143269. 0.8950854244F, 0.8955743212F, 0.8960618003F, 0.8965478621F,
  143270. 0.8970325071F, 0.8975157359F, 0.8979975490F, 0.8984779471F,
  143271. 0.8989569307F, 0.8994345004F, 0.8999106568F, 0.9003854005F,
  143272. 0.9008587323F, 0.9013306526F, 0.9018011623F, 0.9022702619F,
  143273. 0.9027379521F, 0.9032042337F, 0.9036691074F, 0.9041325739F,
  143274. 0.9045946339F, 0.9050552882F, 0.9055145376F, 0.9059723828F,
  143275. 0.9064288246F, 0.9068838638F, 0.9073375013F, 0.9077897379F,
  143276. 0.9082405743F, 0.9086900115F, 0.9091380503F, 0.9095846917F,
  143277. 0.9100299364F, 0.9104737854F, 0.9109162397F, 0.9113573001F,
  143278. 0.9117969675F, 0.9122352430F, 0.9126721275F, 0.9131076219F,
  143279. 0.9135417273F, 0.9139744447F, 0.9144057750F, 0.9148357194F,
  143280. 0.9152642787F, 0.9156914542F, 0.9161172468F, 0.9165416576F,
  143281. 0.9169646877F, 0.9173863382F, 0.9178066102F, 0.9182255048F,
  143282. 0.9186430232F, 0.9190591665F, 0.9194739359F, 0.9198873324F,
  143283. 0.9202993574F, 0.9207100120F, 0.9211192973F, 0.9215272147F,
  143284. 0.9219337653F, 0.9223389504F, 0.9227427713F, 0.9231452290F,
  143285. 0.9235463251F, 0.9239460607F, 0.9243444371F, 0.9247414557F,
  143286. 0.9251371177F, 0.9255314245F, 0.9259243774F, 0.9263159778F,
  143287. 0.9267062270F, 0.9270951264F, 0.9274826774F, 0.9278688814F,
  143288. 0.9282537398F, 0.9286372540F, 0.9290194254F, 0.9294002555F,
  143289. 0.9297797458F, 0.9301578976F, 0.9305347125F, 0.9309101919F,
  143290. 0.9312843373F, 0.9316571503F, 0.9320286323F, 0.9323987849F,
  143291. 0.9327676097F, 0.9331351080F, 0.9335012816F, 0.9338661320F,
  143292. 0.9342296607F, 0.9345918694F, 0.9349527596F, 0.9353123330F,
  143293. 0.9356705911F, 0.9360275357F, 0.9363831683F, 0.9367374905F,
  143294. 0.9370905042F, 0.9374422108F, 0.9377926122F, 0.9381417099F,
  143295. 0.9384895057F, 0.9388360014F, 0.9391811985F, 0.9395250989F,
  143296. 0.9398677043F, 0.9402090165F, 0.9405490371F, 0.9408877680F,
  143297. 0.9412252110F, 0.9415613678F, 0.9418962402F, 0.9422298301F,
  143298. 0.9425621392F, 0.9428931695F, 0.9432229226F, 0.9435514005F,
  143299. 0.9438786050F, 0.9442045381F, 0.9445292014F, 0.9448525971F,
  143300. 0.9451747268F, 0.9454955926F, 0.9458151963F, 0.9461335399F,
  143301. 0.9464506253F, 0.9467664545F, 0.9470810293F, 0.9473943517F,
  143302. 0.9477064238F, 0.9480172474F, 0.9483268246F, 0.9486351573F,
  143303. 0.9489422475F, 0.9492480973F, 0.9495527087F, 0.9498560837F,
  143304. 0.9501582243F, 0.9504591325F, 0.9507588105F, 0.9510572603F,
  143305. 0.9513544839F, 0.9516504834F, 0.9519452609F, 0.9522388186F,
  143306. 0.9525311584F, 0.9528222826F, 0.9531121932F, 0.9534008923F,
  143307. 0.9536883821F, 0.9539746647F, 0.9542597424F, 0.9545436171F,
  143308. 0.9548262912F, 0.9551077667F, 0.9553880459F, 0.9556671309F,
  143309. 0.9559450239F, 0.9562217272F, 0.9564972429F, 0.9567715733F,
  143310. 0.9570447206F, 0.9573166871F, 0.9575874749F, 0.9578570863F,
  143311. 0.9581255236F, 0.9583927890F, 0.9586588849F, 0.9589238134F,
  143312. 0.9591875769F, 0.9594501777F, 0.9597116180F, 0.9599719003F,
  143313. 0.9602310267F, 0.9604889995F, 0.9607458213F, 0.9610014942F,
  143314. 0.9612560206F, 0.9615094028F, 0.9617616433F, 0.9620127443F,
  143315. 0.9622627083F, 0.9625115376F, 0.9627592345F, 0.9630058016F,
  143316. 0.9632512411F, 0.9634955555F, 0.9637387471F, 0.9639808185F,
  143317. 0.9642217720F, 0.9644616100F, 0.9647003349F, 0.9649379493F,
  143318. 0.9651744556F, 0.9654098561F, 0.9656441534F, 0.9658773499F,
  143319. 0.9661094480F, 0.9663404504F, 0.9665703593F, 0.9667991774F,
  143320. 0.9670269071F, 0.9672535509F, 0.9674791114F, 0.9677035909F,
  143321. 0.9679269921F, 0.9681493174F, 0.9683705694F, 0.9685907506F,
  143322. 0.9688098636F, 0.9690279108F, 0.9692448948F, 0.9694608182F,
  143323. 0.9696756836F, 0.9698894934F, 0.9701022503F, 0.9703139569F,
  143324. 0.9705246156F, 0.9707342291F, 0.9709428000F, 0.9711503309F,
  143325. 0.9713568243F, 0.9715622829F, 0.9717667093F, 0.9719701060F,
  143326. 0.9721724757F, 0.9723738210F, 0.9725741446F, 0.9727734490F,
  143327. 0.9729717369F, 0.9731690109F, 0.9733652737F, 0.9735605279F,
  143328. 0.9737547762F, 0.9739480212F, 0.9741402656F, 0.9743315120F,
  143329. 0.9745217631F, 0.9747110216F, 0.9748992901F, 0.9750865714F,
  143330. 0.9752728681F, 0.9754581829F, 0.9756425184F, 0.9758258775F,
  143331. 0.9760082627F, 0.9761896768F, 0.9763701224F, 0.9765496024F,
  143332. 0.9767281193F, 0.9769056760F, 0.9770822751F, 0.9772579193F,
  143333. 0.9774326114F, 0.9776063542F, 0.9777791502F, 0.9779510023F,
  143334. 0.9781219133F, 0.9782918858F, 0.9784609226F, 0.9786290264F,
  143335. 0.9787962000F, 0.9789624461F, 0.9791277676F, 0.9792921671F,
  143336. 0.9794556474F, 0.9796182113F, 0.9797798615F, 0.9799406009F,
  143337. 0.9801004321F, 0.9802593580F, 0.9804173813F, 0.9805745049F,
  143338. 0.9807307314F, 0.9808860637F, 0.9810405046F, 0.9811940568F,
  143339. 0.9813467232F, 0.9814985065F, 0.9816494095F, 0.9817994351F,
  143340. 0.9819485860F, 0.9820968650F, 0.9822442750F, 0.9823908186F,
  143341. 0.9825364988F, 0.9826813184F, 0.9828252801F, 0.9829683868F,
  143342. 0.9831106413F, 0.9832520463F, 0.9833926048F, 0.9835323195F,
  143343. 0.9836711932F, 0.9838092288F, 0.9839464291F, 0.9840827969F,
  143344. 0.9842183351F, 0.9843530464F, 0.9844869337F, 0.9846199998F,
  143345. 0.9847522475F, 0.9848836798F, 0.9850142993F, 0.9851441090F,
  143346. 0.9852731117F, 0.9854013101F, 0.9855287073F, 0.9856553058F,
  143347. 0.9857811087F, 0.9859061188F, 0.9860303388F, 0.9861537717F,
  143348. 0.9862764202F, 0.9863982872F, 0.9865193756F, 0.9866396882F,
  143349. 0.9867592277F, 0.9868779972F, 0.9869959993F, 0.9871132370F,
  143350. 0.9872297131F, 0.9873454304F, 0.9874603918F, 0.9875746001F,
  143351. 0.9876880581F, 0.9878007688F, 0.9879127348F, 0.9880239592F,
  143352. 0.9881344447F, 0.9882441941F, 0.9883532104F, 0.9884614962F,
  143353. 0.9885690546F, 0.9886758883F, 0.9887820001F, 0.9888873930F,
  143354. 0.9889920697F, 0.9890960331F, 0.9891992859F, 0.9893018312F,
  143355. 0.9894036716F, 0.9895048100F, 0.9896052493F, 0.9897049923F,
  143356. 0.9898040418F, 0.9899024006F, 0.9900000717F, 0.9900970577F,
  143357. 0.9901933616F, 0.9902889862F, 0.9903839343F, 0.9904782087F,
  143358. 0.9905718122F, 0.9906647477F, 0.9907570180F, 0.9908486259F,
  143359. 0.9909395742F, 0.9910298658F, 0.9911195034F, 0.9912084899F,
  143360. 0.9912968281F, 0.9913845208F, 0.9914715708F, 0.9915579810F,
  143361. 0.9916437540F, 0.9917288928F, 0.9918134001F, 0.9918972788F,
  143362. 0.9919805316F, 0.9920631613F, 0.9921451707F, 0.9922265626F,
  143363. 0.9923073399F, 0.9923875052F, 0.9924670615F, 0.9925460114F,
  143364. 0.9926243577F, 0.9927021033F, 0.9927792508F, 0.9928558032F,
  143365. 0.9929317631F, 0.9930071333F, 0.9930819167F, 0.9931561158F,
  143366. 0.9932297337F, 0.9933027728F, 0.9933752362F, 0.9934471264F,
  143367. 0.9935184462F, 0.9935891985F, 0.9936593859F, 0.9937290112F,
  143368. 0.9937980771F, 0.9938665864F, 0.9939345418F, 0.9940019460F,
  143369. 0.9940688018F, 0.9941351118F, 0.9942008789F, 0.9942661057F,
  143370. 0.9943307950F, 0.9943949494F, 0.9944585717F, 0.9945216645F,
  143371. 0.9945842307F, 0.9946462728F, 0.9947077936F, 0.9947687957F,
  143372. 0.9948292820F, 0.9948892550F, 0.9949487174F, 0.9950076719F,
  143373. 0.9950661212F, 0.9951240679F, 0.9951815148F, 0.9952384645F,
  143374. 0.9952949196F, 0.9953508828F, 0.9954063568F, 0.9954613442F,
  143375. 0.9955158476F, 0.9955698697F, 0.9956234132F, 0.9956764806F,
  143376. 0.9957290746F, 0.9957811978F, 0.9958328528F, 0.9958840423F,
  143377. 0.9959347688F, 0.9959850351F, 0.9960348435F, 0.9960841969F,
  143378. 0.9961330977F, 0.9961815486F, 0.9962295521F, 0.9962771108F,
  143379. 0.9963242274F, 0.9963709043F, 0.9964171441F, 0.9964629494F,
  143380. 0.9965083228F, 0.9965532668F, 0.9965977840F, 0.9966418768F,
  143381. 0.9966855479F, 0.9967287998F, 0.9967716350F, 0.9968140559F,
  143382. 0.9968560653F, 0.9968976655F, 0.9969388591F, 0.9969796485F,
  143383. 0.9970200363F, 0.9970600250F, 0.9970996170F, 0.9971388149F,
  143384. 0.9971776211F, 0.9972160380F, 0.9972540683F, 0.9972917142F,
  143385. 0.9973289783F, 0.9973658631F, 0.9974023709F, 0.9974385042F,
  143386. 0.9974742655F, 0.9975096571F, 0.9975446816F, 0.9975793413F,
  143387. 0.9976136386F, 0.9976475759F, 0.9976811557F, 0.9977143803F,
  143388. 0.9977472521F, 0.9977797736F, 0.9978119470F, 0.9978437748F,
  143389. 0.9978752593F, 0.9979064029F, 0.9979372079F, 0.9979676768F,
  143390. 0.9979978117F, 0.9980276151F, 0.9980570893F, 0.9980862367F,
  143391. 0.9981150595F, 0.9981435600F, 0.9981717406F, 0.9981996035F,
  143392. 0.9982271511F, 0.9982543856F, 0.9982813093F, 0.9983079246F,
  143393. 0.9983342336F, 0.9983602386F, 0.9983859418F, 0.9984113456F,
  143394. 0.9984364522F, 0.9984612638F, 0.9984857825F, 0.9985100108F,
  143395. 0.9985339507F, 0.9985576044F, 0.9985809743F, 0.9986040624F,
  143396. 0.9986268710F, 0.9986494022F, 0.9986716583F, 0.9986936413F,
  143397. 0.9987153535F, 0.9987367969F, 0.9987579738F, 0.9987788864F,
  143398. 0.9987995366F, 0.9988199267F, 0.9988400587F, 0.9988599348F,
  143399. 0.9988795572F, 0.9988989278F, 0.9989180487F, 0.9989369222F,
  143400. 0.9989555501F, 0.9989739347F, 0.9989920780F, 0.9990099820F,
  143401. 0.9990276487F, 0.9990450803F, 0.9990622787F, 0.9990792460F,
  143402. 0.9990959841F, 0.9991124952F, 0.9991287812F, 0.9991448440F,
  143403. 0.9991606858F, 0.9991763084F, 0.9991917139F, 0.9992069042F,
  143404. 0.9992218813F, 0.9992366471F, 0.9992512035F, 0.9992655525F,
  143405. 0.9992796961F, 0.9992936361F, 0.9993073744F, 0.9993209131F,
  143406. 0.9993342538F, 0.9993473987F, 0.9993603494F, 0.9993731080F,
  143407. 0.9993856762F, 0.9993980559F, 0.9994102490F, 0.9994222573F,
  143408. 0.9994340827F, 0.9994457269F, 0.9994571918F, 0.9994684793F,
  143409. 0.9994795910F, 0.9994905288F, 0.9995012945F, 0.9995118898F,
  143410. 0.9995223165F, 0.9995325765F, 0.9995426713F, 0.9995526029F,
  143411. 0.9995623728F, 0.9995719829F, 0.9995814349F, 0.9995907304F,
  143412. 0.9995998712F, 0.9996088590F, 0.9996176954F, 0.9996263821F,
  143413. 0.9996349208F, 0.9996433132F, 0.9996515609F, 0.9996596656F,
  143414. 0.9996676288F, 0.9996754522F, 0.9996831375F, 0.9996906862F,
  143415. 0.9996981000F, 0.9997053804F, 0.9997125290F, 0.9997195474F,
  143416. 0.9997264371F, 0.9997331998F, 0.9997398369F, 0.9997463500F,
  143417. 0.9997527406F, 0.9997590103F, 0.9997651606F, 0.9997711930F,
  143418. 0.9997771089F, 0.9997829098F, 0.9997885973F, 0.9997941728F,
  143419. 0.9997996378F, 0.9998049936F, 0.9998102419F, 0.9998153839F,
  143420. 0.9998204211F, 0.9998253550F, 0.9998301868F, 0.9998349182F,
  143421. 0.9998395503F, 0.9998440847F, 0.9998485226F, 0.9998528654F,
  143422. 0.9998571146F, 0.9998612713F, 0.9998653370F, 0.9998693130F,
  143423. 0.9998732007F, 0.9998770012F, 0.9998807159F, 0.9998843461F,
  143424. 0.9998878931F, 0.9998913581F, 0.9998947424F, 0.9998980473F,
  143425. 0.9999012740F, 0.9999044237F, 0.9999074976F, 0.9999104971F,
  143426. 0.9999134231F, 0.9999162771F, 0.9999190601F, 0.9999217733F,
  143427. 0.9999244179F, 0.9999269950F, 0.9999295058F, 0.9999319515F,
  143428. 0.9999343332F, 0.9999366519F, 0.9999389088F, 0.9999411050F,
  143429. 0.9999432416F, 0.9999453196F, 0.9999473402F, 0.9999493044F,
  143430. 0.9999512132F, 0.9999530677F, 0.9999548690F, 0.9999566180F,
  143431. 0.9999583157F, 0.9999599633F, 0.9999615616F, 0.9999631116F,
  143432. 0.9999646144F, 0.9999660709F, 0.9999674820F, 0.9999688487F,
  143433. 0.9999701719F, 0.9999714526F, 0.9999726917F, 0.9999738900F,
  143434. 0.9999750486F, 0.9999761682F, 0.9999772497F, 0.9999782941F,
  143435. 0.9999793021F, 0.9999802747F, 0.9999812126F, 0.9999821167F,
  143436. 0.9999829878F, 0.9999838268F, 0.9999846343F, 0.9999854113F,
  143437. 0.9999861584F, 0.9999868765F, 0.9999875664F, 0.9999882287F,
  143438. 0.9999888642F, 0.9999894736F, 0.9999900577F, 0.9999906172F,
  143439. 0.9999911528F, 0.9999916651F, 0.9999921548F, 0.9999926227F,
  143440. 0.9999930693F, 0.9999934954F, 0.9999939015F, 0.9999942883F,
  143441. 0.9999946564F, 0.9999950064F, 0.9999953390F, 0.9999956547F,
  143442. 0.9999959541F, 0.9999962377F, 0.9999965062F, 0.9999967601F,
  143443. 0.9999969998F, 0.9999972260F, 0.9999974392F, 0.9999976399F,
  143444. 0.9999978285F, 0.9999980056F, 0.9999981716F, 0.9999983271F,
  143445. 0.9999984724F, 0.9999986081F, 0.9999987345F, 0.9999988521F,
  143446. 0.9999989613F, 0.9999990625F, 0.9999991562F, 0.9999992426F,
  143447. 0.9999993223F, 0.9999993954F, 0.9999994625F, 0.9999995239F,
  143448. 0.9999995798F, 0.9999996307F, 0.9999996768F, 0.9999997184F,
  143449. 0.9999997559F, 0.9999997895F, 0.9999998195F, 0.9999998462F,
  143450. 0.9999998698F, 0.9999998906F, 0.9999999088F, 0.9999999246F,
  143451. 0.9999999383F, 0.9999999500F, 0.9999999600F, 0.9999999684F,
  143452. 0.9999999754F, 0.9999999811F, 0.9999999858F, 0.9999999896F,
  143453. 0.9999999925F, 0.9999999948F, 0.9999999965F, 0.9999999978F,
  143454. 0.9999999986F, 0.9999999992F, 0.9999999996F, 0.9999999998F,
  143455. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  143456. };
  143457. static float vwin8192[4096] = {
  143458. 0.0000000578F, 0.0000005198F, 0.0000014438F, 0.0000028299F,
  143459. 0.0000046780F, 0.0000069882F, 0.0000097604F, 0.0000129945F,
  143460. 0.0000166908F, 0.0000208490F, 0.0000254692F, 0.0000305515F,
  143461. 0.0000360958F, 0.0000421021F, 0.0000485704F, 0.0000555006F,
  143462. 0.0000628929F, 0.0000707472F, 0.0000790635F, 0.0000878417F,
  143463. 0.0000970820F, 0.0001067842F, 0.0001169483F, 0.0001275744F,
  143464. 0.0001386625F, 0.0001502126F, 0.0001622245F, 0.0001746984F,
  143465. 0.0001876343F, 0.0002010320F, 0.0002148917F, 0.0002292132F,
  143466. 0.0002439967F, 0.0002592421F, 0.0002749493F, 0.0002911184F,
  143467. 0.0003077493F, 0.0003248421F, 0.0003423967F, 0.0003604132F,
  143468. 0.0003788915F, 0.0003978316F, 0.0004172335F, 0.0004370971F,
  143469. 0.0004574226F, 0.0004782098F, 0.0004994587F, 0.0005211694F,
  143470. 0.0005433418F, 0.0005659759F, 0.0005890717F, 0.0006126292F,
  143471. 0.0006366484F, 0.0006611292F, 0.0006860716F, 0.0007114757F,
  143472. 0.0007373414F, 0.0007636687F, 0.0007904576F, 0.0008177080F,
  143473. 0.0008454200F, 0.0008735935F, 0.0009022285F, 0.0009313250F,
  143474. 0.0009608830F, 0.0009909025F, 0.0010213834F, 0.0010523257F,
  143475. 0.0010837295F, 0.0011155946F, 0.0011479211F, 0.0011807090F,
  143476. 0.0012139582F, 0.0012476687F, 0.0012818405F, 0.0013164736F,
  143477. 0.0013515679F, 0.0013871235F, 0.0014231402F, 0.0014596182F,
  143478. 0.0014965573F, 0.0015339576F, 0.0015718190F, 0.0016101415F,
  143479. 0.0016489251F, 0.0016881698F, 0.0017278754F, 0.0017680421F,
  143480. 0.0018086698F, 0.0018497584F, 0.0018913080F, 0.0019333185F,
  143481. 0.0019757898F, 0.0020187221F, 0.0020621151F, 0.0021059690F,
  143482. 0.0021502837F, 0.0021950591F, 0.0022402953F, 0.0022859921F,
  143483. 0.0023321497F, 0.0023787679F, 0.0024258467F, 0.0024733861F,
  143484. 0.0025213861F, 0.0025698466F, 0.0026187676F, 0.0026681491F,
  143485. 0.0027179911F, 0.0027682935F, 0.0028190562F, 0.0028702794F,
  143486. 0.0029219628F, 0.0029741066F, 0.0030267107F, 0.0030797749F,
  143487. 0.0031332994F, 0.0031872841F, 0.0032417289F, 0.0032966338F,
  143488. 0.0033519988F, 0.0034078238F, 0.0034641089F, 0.0035208539F,
  143489. 0.0035780589F, 0.0036357237F, 0.0036938485F, 0.0037524331F,
  143490. 0.0038114775F, 0.0038709817F, 0.0039309456F, 0.0039913692F,
  143491. 0.0040522524F, 0.0041135953F, 0.0041753978F, 0.0042376599F,
  143492. 0.0043003814F, 0.0043635624F, 0.0044272029F, 0.0044913028F,
  143493. 0.0045558620F, 0.0046208806F, 0.0046863585F, 0.0047522955F,
  143494. 0.0048186919F, 0.0048855473F, 0.0049528619F, 0.0050206356F,
  143495. 0.0050888684F, 0.0051575601F, 0.0052267108F, 0.0052963204F,
  143496. 0.0053663890F, 0.0054369163F, 0.0055079025F, 0.0055793474F,
  143497. 0.0056512510F, 0.0057236133F, 0.0057964342F, 0.0058697137F,
  143498. 0.0059434517F, 0.0060176482F, 0.0060923032F, 0.0061674166F,
  143499. 0.0062429883F, 0.0063190183F, 0.0063955066F, 0.0064724532F,
  143500. 0.0065498579F, 0.0066277207F, 0.0067060416F, 0.0067848205F,
  143501. 0.0068640575F, 0.0069437523F, 0.0070239051F, 0.0071045157F,
  143502. 0.0071855840F, 0.0072671102F, 0.0073490940F, 0.0074315355F,
  143503. 0.0075144345F, 0.0075977911F, 0.0076816052F, 0.0077658768F,
  143504. 0.0078506057F, 0.0079357920F, 0.0080214355F, 0.0081075363F,
  143505. 0.0081940943F, 0.0082811094F, 0.0083685816F, 0.0084565108F,
  143506. 0.0085448970F, 0.0086337401F, 0.0087230401F, 0.0088127969F,
  143507. 0.0089030104F, 0.0089936807F, 0.0090848076F, 0.0091763911F,
  143508. 0.0092684311F, 0.0093609276F, 0.0094538805F, 0.0095472898F,
  143509. 0.0096411554F, 0.0097354772F, 0.0098302552F, 0.0099254894F,
  143510. 0.0100211796F, 0.0101173259F, 0.0102139281F, 0.0103109863F,
  143511. 0.0104085002F, 0.0105064700F, 0.0106048955F, 0.0107037766F,
  143512. 0.0108031133F, 0.0109029056F, 0.0110031534F, 0.0111038565F,
  143513. 0.0112050151F, 0.0113066289F, 0.0114086980F, 0.0115112222F,
  143514. 0.0116142015F, 0.0117176359F, 0.0118215252F, 0.0119258695F,
  143515. 0.0120306686F, 0.0121359225F, 0.0122416312F, 0.0123477944F,
  143516. 0.0124544123F, 0.0125614847F, 0.0126690116F, 0.0127769928F,
  143517. 0.0128854284F, 0.0129943182F, 0.0131036623F, 0.0132134604F,
  143518. 0.0133237126F, 0.0134344188F, 0.0135455790F, 0.0136571929F,
  143519. 0.0137692607F, 0.0138817821F, 0.0139947572F, 0.0141081859F,
  143520. 0.0142220681F, 0.0143364037F, 0.0144511927F, 0.0145664350F,
  143521. 0.0146821304F, 0.0147982791F, 0.0149148808F, 0.0150319355F,
  143522. 0.0151494431F, 0.0152674036F, 0.0153858168F, 0.0155046828F,
  143523. 0.0156240014F, 0.0157437726F, 0.0158639962F, 0.0159846723F,
  143524. 0.0161058007F, 0.0162273814F, 0.0163494142F, 0.0164718991F,
  143525. 0.0165948361F, 0.0167182250F, 0.0168420658F, 0.0169663584F,
  143526. 0.0170911027F, 0.0172162987F, 0.0173419462F, 0.0174680452F,
  143527. 0.0175945956F, 0.0177215974F, 0.0178490504F, 0.0179769545F,
  143528. 0.0181053098F, 0.0182341160F, 0.0183633732F, 0.0184930812F,
  143529. 0.0186232399F, 0.0187538494F, 0.0188849094F, 0.0190164200F,
  143530. 0.0191483809F, 0.0192807923F, 0.0194136539F, 0.0195469656F,
  143531. 0.0196807275F, 0.0198149394F, 0.0199496012F, 0.0200847128F,
  143532. 0.0202202742F, 0.0203562853F, 0.0204927460F, 0.0206296561F,
  143533. 0.0207670157F, 0.0209048245F, 0.0210430826F, 0.0211817899F,
  143534. 0.0213209462F, 0.0214605515F, 0.0216006057F, 0.0217411086F,
  143535. 0.0218820603F, 0.0220234605F, 0.0221653093F, 0.0223076066F,
  143536. 0.0224503521F, 0.0225935459F, 0.0227371879F, 0.0228812779F,
  143537. 0.0230258160F, 0.0231708018F, 0.0233162355F, 0.0234621169F,
  143538. 0.0236084459F, 0.0237552224F, 0.0239024462F, 0.0240501175F,
  143539. 0.0241982359F, 0.0243468015F, 0.0244958141F, 0.0246452736F,
  143540. 0.0247951800F, 0.0249455331F, 0.0250963329F, 0.0252475792F,
  143541. 0.0253992720F, 0.0255514111F, 0.0257039965F, 0.0258570281F,
  143542. 0.0260105057F, 0.0261644293F, 0.0263187987F, 0.0264736139F,
  143543. 0.0266288747F, 0.0267845811F, 0.0269407330F, 0.0270973302F,
  143544. 0.0272543727F, 0.0274118604F, 0.0275697930F, 0.0277281707F,
  143545. 0.0278869932F, 0.0280462604F, 0.0282059723F, 0.0283661287F,
  143546. 0.0285267295F, 0.0286877747F, 0.0288492641F, 0.0290111976F,
  143547. 0.0291735751F, 0.0293363965F, 0.0294996617F, 0.0296633706F,
  143548. 0.0298275231F, 0.0299921190F, 0.0301571583F, 0.0303226409F,
  143549. 0.0304885667F, 0.0306549354F, 0.0308217472F, 0.0309890017F,
  143550. 0.0311566989F, 0.0313248388F, 0.0314934211F, 0.0316624459F,
  143551. 0.0318319128F, 0.0320018220F, 0.0321721732F, 0.0323429663F,
  143552. 0.0325142013F, 0.0326858779F, 0.0328579962F, 0.0330305559F,
  143553. 0.0332035570F, 0.0333769994F, 0.0335508829F, 0.0337252074F,
  143554. 0.0338999728F, 0.0340751790F, 0.0342508259F, 0.0344269134F,
  143555. 0.0346034412F, 0.0347804094F, 0.0349578178F, 0.0351356663F,
  143556. 0.0353139548F, 0.0354926831F, 0.0356718511F, 0.0358514588F,
  143557. 0.0360315059F, 0.0362119924F, 0.0363929182F, 0.0365742831F,
  143558. 0.0367560870F, 0.0369383297F, 0.0371210113F, 0.0373041315F,
  143559. 0.0374876902F, 0.0376716873F, 0.0378561226F, 0.0380409961F,
  143560. 0.0382263077F, 0.0384120571F, 0.0385982443F, 0.0387848691F,
  143561. 0.0389719315F, 0.0391594313F, 0.0393473683F, 0.0395357425F,
  143562. 0.0397245537F, 0.0399138017F, 0.0401034866F, 0.0402936080F,
  143563. 0.0404841660F, 0.0406751603F, 0.0408665909F, 0.0410584576F,
  143564. 0.0412507603F, 0.0414434988F, 0.0416366731F, 0.0418302829F,
  143565. 0.0420243282F, 0.0422188088F, 0.0424137246F, 0.0426090755F,
  143566. 0.0428048613F, 0.0430010819F, 0.0431977371F, 0.0433948269F,
  143567. 0.0435923511F, 0.0437903095F, 0.0439887020F, 0.0441875285F,
  143568. 0.0443867889F, 0.0445864830F, 0.0447866106F, 0.0449871717F,
  143569. 0.0451881661F, 0.0453895936F, 0.0455914542F, 0.0457937477F,
  143570. 0.0459964738F, 0.0461996326F, 0.0464032239F, 0.0466072475F,
  143571. 0.0468117032F, 0.0470165910F, 0.0472219107F, 0.0474276622F,
  143572. 0.0476338452F, 0.0478404597F, 0.0480475056F, 0.0482549827F,
  143573. 0.0484628907F, 0.0486712297F, 0.0488799994F, 0.0490891998F,
  143574. 0.0492988306F, 0.0495088917F, 0.0497193830F, 0.0499303043F,
  143575. 0.0501416554F, 0.0503534363F, 0.0505656468F, 0.0507782867F,
  143576. 0.0509913559F, 0.0512048542F, 0.0514187815F, 0.0516331376F,
  143577. 0.0518479225F, 0.0520631358F, 0.0522787775F, 0.0524948475F,
  143578. 0.0527113455F, 0.0529282715F, 0.0531456252F, 0.0533634066F,
  143579. 0.0535816154F, 0.0538002515F, 0.0540193148F, 0.0542388051F,
  143580. 0.0544587222F, 0.0546790660F, 0.0548998364F, 0.0551210331F,
  143581. 0.0553426561F, 0.0555647051F, 0.0557871801F, 0.0560100807F,
  143582. 0.0562334070F, 0.0564571587F, 0.0566813357F, 0.0569059378F,
  143583. 0.0571309649F, 0.0573564168F, 0.0575822933F, 0.0578085942F,
  143584. 0.0580353195F, 0.0582624689F, 0.0584900423F, 0.0587180396F,
  143585. 0.0589464605F, 0.0591753049F, 0.0594045726F, 0.0596342635F,
  143586. 0.0598643774F, 0.0600949141F, 0.0603258735F, 0.0605572555F,
  143587. 0.0607890597F, 0.0610212862F, 0.0612539346F, 0.0614870049F,
  143588. 0.0617204968F, 0.0619544103F, 0.0621887451F, 0.0624235010F,
  143589. 0.0626586780F, 0.0628942758F, 0.0631302942F, 0.0633667331F,
  143590. 0.0636035923F, 0.0638408717F, 0.0640785710F, 0.0643166901F,
  143591. 0.0645552288F, 0.0647941870F, 0.0650335645F, 0.0652733610F,
  143592. 0.0655135765F, 0.0657542108F, 0.0659952636F, 0.0662367348F,
  143593. 0.0664786242F, 0.0667209316F, 0.0669636570F, 0.0672068000F,
  143594. 0.0674503605F, 0.0676943384F, 0.0679387334F, 0.0681835454F,
  143595. 0.0684287742F, 0.0686744196F, 0.0689204814F, 0.0691669595F,
  143596. 0.0694138536F, 0.0696611637F, 0.0699088894F, 0.0701570307F,
  143597. 0.0704055873F, 0.0706545590F, 0.0709039458F, 0.0711537473F,
  143598. 0.0714039634F, 0.0716545939F, 0.0719056387F, 0.0721570975F,
  143599. 0.0724089702F, 0.0726612565F, 0.0729139563F, 0.0731670694F,
  143600. 0.0734205956F, 0.0736745347F, 0.0739288866F, 0.0741836510F,
  143601. 0.0744388277F, 0.0746944166F, 0.0749504175F, 0.0752068301F,
  143602. 0.0754636543F, 0.0757208899F, 0.0759785367F, 0.0762365946F,
  143603. 0.0764950632F, 0.0767539424F, 0.0770132320F, 0.0772729319F,
  143604. 0.0775330418F, 0.0777935616F, 0.0780544909F, 0.0783158298F,
  143605. 0.0785775778F, 0.0788397349F, 0.0791023009F, 0.0793652755F,
  143606. 0.0796286585F, 0.0798924498F, 0.0801566492F, 0.0804212564F,
  143607. 0.0806862712F, 0.0809516935F, 0.0812175231F, 0.0814837597F,
  143608. 0.0817504031F, 0.0820174532F, 0.0822849097F, 0.0825527724F,
  143609. 0.0828210412F, 0.0830897158F, 0.0833587960F, 0.0836282816F,
  143610. 0.0838981724F, 0.0841684682F, 0.0844391688F, 0.0847102740F,
  143611. 0.0849817835F, 0.0852536973F, 0.0855260150F, 0.0857987364F,
  143612. 0.0860718614F, 0.0863453897F, 0.0866193211F, 0.0868936554F,
  143613. 0.0871683924F, 0.0874435319F, 0.0877190737F, 0.0879950175F,
  143614. 0.0882713632F, 0.0885481105F, 0.0888252592F, 0.0891028091F,
  143615. 0.0893807600F, 0.0896591117F, 0.0899378639F, 0.0902170165F,
  143616. 0.0904965692F, 0.0907765218F, 0.0910568740F, 0.0913376258F,
  143617. 0.0916187767F, 0.0919003268F, 0.0921822756F, 0.0924646230F,
  143618. 0.0927473687F, 0.0930305126F, 0.0933140545F, 0.0935979940F,
  143619. 0.0938823310F, 0.0941670653F, 0.0944521966F, 0.0947377247F,
  143620. 0.0950236494F, 0.0953099704F, 0.0955966876F, 0.0958838007F,
  143621. 0.0961713094F, 0.0964592136F, 0.0967475131F, 0.0970362075F,
  143622. 0.0973252967F, 0.0976147805F, 0.0979046585F, 0.0981949307F,
  143623. 0.0984855967F, 0.0987766563F, 0.0990681093F, 0.0993599555F,
  143624. 0.0996521945F, 0.0999448263F, 0.1002378506F, 0.1005312671F,
  143625. 0.1008250755F, 0.1011192757F, 0.1014138675F, 0.1017088505F,
  143626. 0.1020042246F, 0.1022999895F, 0.1025961450F, 0.1028926909F,
  143627. 0.1031896268F, 0.1034869526F, 0.1037846680F, 0.1040827729F,
  143628. 0.1043812668F, 0.1046801497F, 0.1049794213F, 0.1052790813F,
  143629. 0.1055791294F, 0.1058795656F, 0.1061803894F, 0.1064816006F,
  143630. 0.1067831991F, 0.1070851846F, 0.1073875568F, 0.1076903155F,
  143631. 0.1079934604F, 0.1082969913F, 0.1086009079F, 0.1089052101F,
  143632. 0.1092098975F, 0.1095149699F, 0.1098204270F, 0.1101262687F,
  143633. 0.1104324946F, 0.1107391045F, 0.1110460982F, 0.1113534754F,
  143634. 0.1116612359F, 0.1119693793F, 0.1122779055F, 0.1125868142F,
  143635. 0.1128961052F, 0.1132057781F, 0.1135158328F, 0.1138262690F,
  143636. 0.1141370863F, 0.1144482847F, 0.1147598638F, 0.1150718233F,
  143637. 0.1153841631F, 0.1156968828F, 0.1160099822F, 0.1163234610F,
  143638. 0.1166373190F, 0.1169515559F, 0.1172661714F, 0.1175811654F,
  143639. 0.1178965374F, 0.1182122874F, 0.1185284149F, 0.1188449198F,
  143640. 0.1191618018F, 0.1194790606F, 0.1197966960F, 0.1201147076F,
  143641. 0.1204330953F, 0.1207518587F, 0.1210709976F, 0.1213905118F,
  143642. 0.1217104009F, 0.1220306647F, 0.1223513029F, 0.1226723153F,
  143643. 0.1229937016F, 0.1233154615F, 0.1236375948F, 0.1239601011F,
  143644. 0.1242829803F, 0.1246062319F, 0.1249298559F, 0.1252538518F,
  143645. 0.1255782195F, 0.1259029586F, 0.1262280689F, 0.1265535501F,
  143646. 0.1268794019F, 0.1272056241F, 0.1275322163F, 0.1278591784F,
  143647. 0.1281865099F, 0.1285142108F, 0.1288422805F, 0.1291707190F,
  143648. 0.1294995259F, 0.1298287009F, 0.1301582437F, 0.1304881542F,
  143649. 0.1308184319F, 0.1311490766F, 0.1314800881F, 0.1318114660F,
  143650. 0.1321432100F, 0.1324753200F, 0.1328077955F, 0.1331406364F,
  143651. 0.1334738422F, 0.1338074129F, 0.1341413479F, 0.1344756472F,
  143652. 0.1348103103F, 0.1351453370F, 0.1354807270F, 0.1358164801F,
  143653. 0.1361525959F, 0.1364890741F, 0.1368259145F, 0.1371631167F,
  143654. 0.1375006805F, 0.1378386056F, 0.1381768917F, 0.1385155384F,
  143655. 0.1388545456F, 0.1391939129F, 0.1395336400F, 0.1398737266F,
  143656. 0.1402141724F, 0.1405549772F, 0.1408961406F, 0.1412376623F,
  143657. 0.1415795421F, 0.1419217797F, 0.1422643746F, 0.1426073268F,
  143658. 0.1429506358F, 0.1432943013F, 0.1436383231F, 0.1439827008F,
  143659. 0.1443274342F, 0.1446725229F, 0.1450179667F, 0.1453637652F,
  143660. 0.1457099181F, 0.1460564252F, 0.1464032861F, 0.1467505006F,
  143661. 0.1470980682F, 0.1474459888F, 0.1477942620F, 0.1481428875F,
  143662. 0.1484918651F, 0.1488411942F, 0.1491908748F, 0.1495409065F,
  143663. 0.1498912889F, 0.1502420218F, 0.1505931048F, 0.1509445376F,
  143664. 0.1512963200F, 0.1516484516F, 0.1520009321F, 0.1523537612F,
  143665. 0.1527069385F, 0.1530604638F, 0.1534143368F, 0.1537685571F,
  143666. 0.1541231244F, 0.1544780384F, 0.1548332987F, 0.1551889052F,
  143667. 0.1555448574F, 0.1559011550F, 0.1562577978F, 0.1566147853F,
  143668. 0.1569721173F, 0.1573297935F, 0.1576878135F, 0.1580461771F,
  143669. 0.1584048838F, 0.1587639334F, 0.1591233255F, 0.1594830599F,
  143670. 0.1598431361F, 0.1602035540F, 0.1605643131F, 0.1609254131F,
  143671. 0.1612868537F, 0.1616486346F, 0.1620107555F, 0.1623732160F,
  143672. 0.1627360158F, 0.1630991545F, 0.1634626319F, 0.1638264476F,
  143673. 0.1641906013F, 0.1645550926F, 0.1649199212F, 0.1652850869F,
  143674. 0.1656505892F, 0.1660164278F, 0.1663826024F, 0.1667491127F,
  143675. 0.1671159583F, 0.1674831388F, 0.1678506541F, 0.1682185036F,
  143676. 0.1685866872F, 0.1689552044F, 0.1693240549F, 0.1696932384F,
  143677. 0.1700627545F, 0.1704326029F, 0.1708027833F, 0.1711732952F,
  143678. 0.1715441385F, 0.1719153127F, 0.1722868175F, 0.1726586526F,
  143679. 0.1730308176F, 0.1734033121F, 0.1737761359F, 0.1741492886F,
  143680. 0.1745227698F, 0.1748965792F, 0.1752707164F, 0.1756451812F,
  143681. 0.1760199731F, 0.1763950918F, 0.1767705370F, 0.1771463083F,
  143682. 0.1775224054F, 0.1778988279F, 0.1782755754F, 0.1786526477F,
  143683. 0.1790300444F, 0.1794077651F, 0.1797858094F, 0.1801641771F,
  143684. 0.1805428677F, 0.1809218810F, 0.1813012165F, 0.1816808739F,
  143685. 0.1820608528F, 0.1824411530F, 0.1828217739F, 0.1832027154F,
  143686. 0.1835839770F, 0.1839655584F, 0.1843474592F, 0.1847296790F,
  143687. 0.1851122175F, 0.1854950744F, 0.1858782492F, 0.1862617417F,
  143688. 0.1866455514F, 0.1870296780F, 0.1874141211F, 0.1877988804F,
  143689. 0.1881839555F, 0.1885693461F, 0.1889550517F, 0.1893410721F,
  143690. 0.1897274068F, 0.1901140555F, 0.1905010178F, 0.1908882933F,
  143691. 0.1912758818F, 0.1916637828F, 0.1920519959F, 0.1924405208F,
  143692. 0.1928293571F, 0.1932185044F, 0.1936079625F, 0.1939977308F,
  143693. 0.1943878091F, 0.1947781969F, 0.1951688939F, 0.1955598998F,
  143694. 0.1959512141F, 0.1963428364F, 0.1967347665F, 0.1971270038F,
  143695. 0.1975195482F, 0.1979123990F, 0.1983055561F, 0.1986990190F,
  143696. 0.1990927873F, 0.1994868607F, 0.1998812388F, 0.2002759212F,
  143697. 0.2006709075F, 0.2010661974F, 0.2014617904F, 0.2018576862F,
  143698. 0.2022538844F, 0.2026503847F, 0.2030471865F, 0.2034442897F,
  143699. 0.2038416937F, 0.2042393982F, 0.2046374028F, 0.2050357071F,
  143700. 0.2054343107F, 0.2058332133F, 0.2062324145F, 0.2066319138F,
  143701. 0.2070317110F, 0.2074318055F, 0.2078321970F, 0.2082328852F,
  143702. 0.2086338696F, 0.2090351498F, 0.2094367255F, 0.2098385962F,
  143703. 0.2102407617F, 0.2106432213F, 0.2110459749F, 0.2114490220F,
  143704. 0.2118523621F, 0.2122559950F, 0.2126599202F, 0.2130641373F,
  143705. 0.2134686459F, 0.2138734456F, 0.2142785361F, 0.2146839168F,
  143706. 0.2150895875F, 0.2154955478F, 0.2159017972F, 0.2163083353F,
  143707. 0.2167151617F, 0.2171222761F, 0.2175296780F, 0.2179373670F,
  143708. 0.2183453428F, 0.2187536049F, 0.2191621529F, 0.2195709864F,
  143709. 0.2199801051F, 0.2203895085F, 0.2207991961F, 0.2212091677F,
  143710. 0.2216194228F, 0.2220299610F, 0.2224407818F, 0.2228518850F,
  143711. 0.2232632699F, 0.2236749364F, 0.2240868839F, 0.2244991121F,
  143712. 0.2249116204F, 0.2253244086F, 0.2257374763F, 0.2261508229F,
  143713. 0.2265644481F, 0.2269783514F, 0.2273925326F, 0.2278069911F,
  143714. 0.2282217265F, 0.2286367384F, 0.2290520265F, 0.2294675902F,
  143715. 0.2298834292F, 0.2302995431F, 0.2307159314F, 0.2311325937F,
  143716. 0.2315495297F, 0.2319667388F, 0.2323842207F, 0.2328019749F,
  143717. 0.2332200011F, 0.2336382988F, 0.2340568675F, 0.2344757070F,
  143718. 0.2348948166F, 0.2353141961F, 0.2357338450F, 0.2361537629F,
  143719. 0.2365739493F, 0.2369944038F, 0.2374151261F, 0.2378361156F,
  143720. 0.2382573720F, 0.2386788948F, 0.2391006836F, 0.2395227380F,
  143721. 0.2399450575F, 0.2403676417F, 0.2407904902F, 0.2412136026F,
  143722. 0.2416369783F, 0.2420606171F, 0.2424845185F, 0.2429086820F,
  143723. 0.2433331072F, 0.2437577936F, 0.2441827409F, 0.2446079486F,
  143724. 0.2450334163F, 0.2454591435F, 0.2458851298F, 0.2463113747F,
  143725. 0.2467378779F, 0.2471646389F, 0.2475916573F, 0.2480189325F,
  143726. 0.2484464643F, 0.2488742521F, 0.2493022955F, 0.2497305940F,
  143727. 0.2501591473F, 0.2505879549F, 0.2510170163F, 0.2514463311F,
  143728. 0.2518758989F, 0.2523057193F, 0.2527357916F, 0.2531661157F,
  143729. 0.2535966909F, 0.2540275169F, 0.2544585931F, 0.2548899193F,
  143730. 0.2553214948F, 0.2557533193F, 0.2561853924F, 0.2566177135F,
  143731. 0.2570502822F, 0.2574830981F, 0.2579161608F, 0.2583494697F,
  143732. 0.2587830245F, 0.2592168246F, 0.2596508697F, 0.2600851593F,
  143733. 0.2605196929F, 0.2609544701F, 0.2613894904F, 0.2618247534F,
  143734. 0.2622602586F, 0.2626960055F, 0.2631319938F, 0.2635682230F,
  143735. 0.2640046925F, 0.2644414021F, 0.2648783511F, 0.2653155391F,
  143736. 0.2657529657F, 0.2661906305F, 0.2666285329F, 0.2670666725F,
  143737. 0.2675050489F, 0.2679436616F, 0.2683825101F, 0.2688215940F,
  143738. 0.2692609127F, 0.2697004660F, 0.2701402532F, 0.2705802739F,
  143739. 0.2710205278F, 0.2714610142F, 0.2719017327F, 0.2723426830F,
  143740. 0.2727838644F, 0.2732252766F, 0.2736669191F, 0.2741087914F,
  143741. 0.2745508930F, 0.2749932235F, 0.2754357824F, 0.2758785693F,
  143742. 0.2763215837F, 0.2767648251F, 0.2772082930F, 0.2776519870F,
  143743. 0.2780959066F, 0.2785400513F, 0.2789844207F, 0.2794290143F,
  143744. 0.2798738316F, 0.2803188722F, 0.2807641355F, 0.2812096211F,
  143745. 0.2816553286F, 0.2821012574F, 0.2825474071F, 0.2829937773F,
  143746. 0.2834403673F, 0.2838871768F, 0.2843342053F, 0.2847814523F,
  143747. 0.2852289174F, 0.2856765999F, 0.2861244996F, 0.2865726159F,
  143748. 0.2870209482F, 0.2874694962F, 0.2879182594F, 0.2883672372F,
  143749. 0.2888164293F, 0.2892658350F, 0.2897154540F, 0.2901652858F,
  143750. 0.2906153298F, 0.2910655856F, 0.2915160527F, 0.2919667306F,
  143751. 0.2924176189F, 0.2928687171F, 0.2933200246F, 0.2937715409F,
  143752. 0.2942232657F, 0.2946751984F, 0.2951273386F, 0.2955796856F,
  143753. 0.2960322391F, 0.2964849986F, 0.2969379636F, 0.2973911335F,
  143754. 0.2978445080F, 0.2982980864F, 0.2987518684F, 0.2992058534F,
  143755. 0.2996600409F, 0.3001144305F, 0.3005690217F, 0.3010238139F,
  143756. 0.3014788067F, 0.3019339995F, 0.3023893920F, 0.3028449835F,
  143757. 0.3033007736F, 0.3037567618F, 0.3042129477F, 0.3046693306F,
  143758. 0.3051259102F, 0.3055826859F, 0.3060396572F, 0.3064968236F,
  143759. 0.3069541847F, 0.3074117399F, 0.3078694887F, 0.3083274307F,
  143760. 0.3087855653F, 0.3092438920F, 0.3097024104F, 0.3101611199F,
  143761. 0.3106200200F, 0.3110791103F, 0.3115383902F, 0.3119978592F,
  143762. 0.3124575169F, 0.3129173627F, 0.3133773961F, 0.3138376166F,
  143763. 0.3142980238F, 0.3147586170F, 0.3152193959F, 0.3156803598F,
  143764. 0.3161415084F, 0.3166028410F, 0.3170643573F, 0.3175260566F,
  143765. 0.3179879384F, 0.3184500023F, 0.3189122478F, 0.3193746743F,
  143766. 0.3198372814F, 0.3203000685F, 0.3207630351F, 0.3212261807F,
  143767. 0.3216895048F, 0.3221530069F, 0.3226166865F, 0.3230805430F,
  143768. 0.3235445760F, 0.3240087849F, 0.3244731693F, 0.3249377285F,
  143769. 0.3254024622F, 0.3258673698F, 0.3263324507F, 0.3267977045F,
  143770. 0.3272631306F, 0.3277287286F, 0.3281944978F, 0.3286604379F,
  143771. 0.3291265482F, 0.3295928284F, 0.3300592777F, 0.3305258958F,
  143772. 0.3309926821F, 0.3314596361F, 0.3319267573F, 0.3323940451F,
  143773. 0.3328614990F, 0.3333291186F, 0.3337969033F, 0.3342648525F,
  143774. 0.3347329658F, 0.3352012427F, 0.3356696825F, 0.3361382849F,
  143775. 0.3366070492F, 0.3370759749F, 0.3375450616F, 0.3380143087F,
  143776. 0.3384837156F, 0.3389532819F, 0.3394230071F, 0.3398928905F,
  143777. 0.3403629317F, 0.3408331302F, 0.3413034854F, 0.3417739967F,
  143778. 0.3422446638F, 0.3427154860F, 0.3431864628F, 0.3436575938F,
  143779. 0.3441288782F, 0.3446003158F, 0.3450719058F, 0.3455436478F,
  143780. 0.3460155412F, 0.3464875856F, 0.3469597804F, 0.3474321250F,
  143781. 0.3479046189F, 0.3483772617F, 0.3488500527F, 0.3493229914F,
  143782. 0.3497960774F, 0.3502693100F, 0.3507426887F, 0.3512162131F,
  143783. 0.3516898825F, 0.3521636965F, 0.3526376545F, 0.3531117559F,
  143784. 0.3535860003F, 0.3540603870F, 0.3545349157F, 0.3550095856F,
  143785. 0.3554843964F, 0.3559593474F, 0.3564344381F, 0.3569096680F,
  143786. 0.3573850366F, 0.3578605432F, 0.3583361875F, 0.3588119687F,
  143787. 0.3592878865F, 0.3597639402F, 0.3602401293F, 0.3607164533F,
  143788. 0.3611929117F, 0.3616695038F, 0.3621462292F, 0.3626230873F,
  143789. 0.3631000776F, 0.3635771995F, 0.3640544525F, 0.3645318360F,
  143790. 0.3650093496F, 0.3654869926F, 0.3659647645F, 0.3664426648F,
  143791. 0.3669206930F, 0.3673988484F, 0.3678771306F, 0.3683555390F,
  143792. 0.3688340731F, 0.3693127322F, 0.3697915160F, 0.3702704237F,
  143793. 0.3707494549F, 0.3712286091F, 0.3717078857F, 0.3721872840F,
  143794. 0.3726668037F, 0.3731464441F, 0.3736262047F, 0.3741060850F,
  143795. 0.3745860843F, 0.3750662023F, 0.3755464382F, 0.3760267915F,
  143796. 0.3765072618F, 0.3769878484F, 0.3774685509F, 0.3779493686F,
  143797. 0.3784303010F, 0.3789113475F, 0.3793925076F, 0.3798737809F,
  143798. 0.3803551666F, 0.3808366642F, 0.3813182733F, 0.3817999932F,
  143799. 0.3822818234F, 0.3827637633F, 0.3832458124F, 0.3837279702F,
  143800. 0.3842102360F, 0.3846926093F, 0.3851750897F, 0.3856576764F,
  143801. 0.3861403690F, 0.3866231670F, 0.3871060696F, 0.3875890765F,
  143802. 0.3880721870F, 0.3885554007F, 0.3890387168F, 0.3895221349F,
  143803. 0.3900056544F, 0.3904892748F, 0.3909729955F, 0.3914568160F,
  143804. 0.3919407356F, 0.3924247539F, 0.3929088702F, 0.3933930841F,
  143805. 0.3938773949F, 0.3943618021F, 0.3948463052F, 0.3953309035F,
  143806. 0.3958155966F, 0.3963003838F, 0.3967852646F, 0.3972702385F,
  143807. 0.3977553048F, 0.3982404631F, 0.3987257127F, 0.3992110531F,
  143808. 0.3996964838F, 0.4001820041F, 0.4006676136F, 0.4011533116F,
  143809. 0.4016390976F, 0.4021249710F, 0.4026109313F, 0.4030969779F,
  143810. 0.4035831102F, 0.4040693277F, 0.4045556299F, 0.4050420160F,
  143811. 0.4055284857F, 0.4060150383F, 0.4065016732F, 0.4069883899F,
  143812. 0.4074751879F, 0.4079620665F, 0.4084490252F, 0.4089360635F,
  143813. 0.4094231807F, 0.4099103763F, 0.4103976498F, 0.4108850005F,
  143814. 0.4113724280F, 0.4118599315F, 0.4123475107F, 0.4128351648F,
  143815. 0.4133228934F, 0.4138106959F, 0.4142985716F, 0.4147865201F,
  143816. 0.4152745408F, 0.4157626330F, 0.4162507963F, 0.4167390301F,
  143817. 0.4172273337F, 0.4177157067F, 0.4182041484F, 0.4186926583F,
  143818. 0.4191812359F, 0.4196698805F, 0.4201585915F, 0.4206473685F,
  143819. 0.4211362108F, 0.4216251179F, 0.4221140892F, 0.4226031241F,
  143820. 0.4230922221F, 0.4235813826F, 0.4240706050F, 0.4245598887F,
  143821. 0.4250492332F, 0.4255386379F, 0.4260281022F, 0.4265176256F,
  143822. 0.4270072075F, 0.4274968473F, 0.4279865445F, 0.4284762984F,
  143823. 0.4289661086F, 0.4294559743F, 0.4299458951F, 0.4304358704F,
  143824. 0.4309258996F, 0.4314159822F, 0.4319061175F, 0.4323963050F,
  143825. 0.4328865441F, 0.4333768342F, 0.4338671749F, 0.4343575654F,
  143826. 0.4348480052F, 0.4353384938F, 0.4358290306F, 0.4363196149F,
  143827. 0.4368102463F, 0.4373009241F, 0.4377916478F, 0.4382824168F,
  143828. 0.4387732305F, 0.4392640884F, 0.4397549899F, 0.4402459343F,
  143829. 0.4407369212F, 0.4412279499F, 0.4417190198F, 0.4422101305F,
  143830. 0.4427012813F, 0.4431924717F, 0.4436837010F, 0.4441749686F,
  143831. 0.4446662742F, 0.4451576169F, 0.4456489963F, 0.4461404118F,
  143832. 0.4466318628F, 0.4471233487F, 0.4476148690F, 0.4481064230F,
  143833. 0.4485980103F, 0.4490896302F, 0.4495812821F, 0.4500729654F,
  143834. 0.4505646797F, 0.4510564243F, 0.4515481986F, 0.4520400021F,
  143835. 0.4525318341F, 0.4530236942F, 0.4535155816F, 0.4540074959F,
  143836. 0.4544994365F, 0.4549914028F, 0.4554833941F, 0.4559754100F,
  143837. 0.4564674499F, 0.4569595131F, 0.4574515991F, 0.4579437074F,
  143838. 0.4584358372F, 0.4589279881F, 0.4594201595F, 0.4599123508F,
  143839. 0.4604045615F, 0.4608967908F, 0.4613890383F, 0.4618813034F,
  143840. 0.4623735855F, 0.4628658841F, 0.4633581984F, 0.4638505281F,
  143841. 0.4643428724F, 0.4648352308F, 0.4653276028F, 0.4658199877F,
  143842. 0.4663123849F, 0.4668047940F, 0.4672972143F, 0.4677896451F,
  143843. 0.4682820861F, 0.4687745365F, 0.4692669958F, 0.4697594634F,
  143844. 0.4702519387F, 0.4707444211F, 0.4712369102F, 0.4717294052F,
  143845. 0.4722219056F, 0.4727144109F, 0.4732069204F, 0.4736994336F,
  143846. 0.4741919498F, 0.4746844686F, 0.4751769893F, 0.4756695113F,
  143847. 0.4761620341F, 0.4766545571F, 0.4771470797F, 0.4776396013F,
  143848. 0.4781321213F, 0.4786246392F, 0.4791171544F, 0.4796096663F,
  143849. 0.4801021744F, 0.4805946779F, 0.4810871765F, 0.4815796694F,
  143850. 0.4820721561F, 0.4825646360F, 0.4830571086F, 0.4835495732F,
  143851. 0.4840420293F, 0.4845344763F, 0.4850269136F, 0.4855193407F,
  143852. 0.4860117569F, 0.4865041617F, 0.4869965545F, 0.4874889347F,
  143853. 0.4879813018F, 0.4884736551F, 0.4889659941F, 0.4894583182F,
  143854. 0.4899506268F, 0.4904429193F, 0.4909351952F, 0.4914274538F,
  143855. 0.4919196947F, 0.4924119172F, 0.4929041207F, 0.4933963046F,
  143856. 0.4938884685F, 0.4943806116F, 0.4948727335F, 0.4953648335F,
  143857. 0.4958569110F, 0.4963489656F, 0.4968409965F, 0.4973330032F,
  143858. 0.4978249852F, 0.4983169419F, 0.4988088726F, 0.4993007768F,
  143859. 0.4997926539F, 0.5002845034F, 0.5007763247F, 0.5012681171F,
  143860. 0.5017598801F, 0.5022516132F, 0.5027433157F, 0.5032349871F,
  143861. 0.5037266268F, 0.5042182341F, 0.5047098086F, 0.5052013497F,
  143862. 0.5056928567F, 0.5061843292F, 0.5066757664F, 0.5071671679F,
  143863. 0.5076585330F, 0.5081498613F, 0.5086411520F, 0.5091324047F,
  143864. 0.5096236187F, 0.5101147934F, 0.5106059284F, 0.5110970230F,
  143865. 0.5115880766F, 0.5120790887F, 0.5125700587F, 0.5130609860F,
  143866. 0.5135518700F, 0.5140427102F, 0.5145335059F, 0.5150242566F,
  143867. 0.5155149618F, 0.5160056208F, 0.5164962331F, 0.5169867980F,
  143868. 0.5174773151F, 0.5179677837F, 0.5184582033F, 0.5189485733F,
  143869. 0.5194388931F, 0.5199291621F, 0.5204193798F, 0.5209095455F,
  143870. 0.5213996588F, 0.5218897190F, 0.5223797256F, 0.5228696779F,
  143871. 0.5233595755F, 0.5238494177F, 0.5243392039F, 0.5248289337F,
  143872. 0.5253186063F, 0.5258082213F, 0.5262977781F, 0.5267872760F,
  143873. 0.5272767146F, 0.5277660932F, 0.5282554112F, 0.5287446682F,
  143874. 0.5292338635F, 0.5297229965F, 0.5302120667F, 0.5307010736F,
  143875. 0.5311900164F, 0.5316788947F, 0.5321677079F, 0.5326564554F,
  143876. 0.5331451366F, 0.5336337511F, 0.5341222981F, 0.5346107771F,
  143877. 0.5350991876F, 0.5355875290F, 0.5360758007F, 0.5365640021F,
  143878. 0.5370521327F, 0.5375401920F, 0.5380281792F, 0.5385160939F,
  143879. 0.5390039355F, 0.5394917034F, 0.5399793971F, 0.5404670159F,
  143880. 0.5409545594F, 0.5414420269F, 0.5419294179F, 0.5424167318F,
  143881. 0.5429039680F, 0.5433911261F, 0.5438782053F, 0.5443652051F,
  143882. 0.5448521250F, 0.5453389644F, 0.5458257228F, 0.5463123995F,
  143883. 0.5467989940F, 0.5472855057F, 0.5477719341F, 0.5482582786F,
  143884. 0.5487445387F, 0.5492307137F, 0.5497168031F, 0.5502028063F,
  143885. 0.5506887228F, 0.5511745520F, 0.5516602934F, 0.5521459463F,
  143886. 0.5526315103F, 0.5531169847F, 0.5536023690F, 0.5540876626F,
  143887. 0.5545728649F, 0.5550579755F, 0.5555429937F, 0.5560279189F,
  143888. 0.5565127507F, 0.5569974884F, 0.5574821315F, 0.5579666794F,
  143889. 0.5584511316F, 0.5589354875F, 0.5594197465F, 0.5599039080F,
  143890. 0.5603879716F, 0.5608719367F, 0.5613558026F, 0.5618395689F,
  143891. 0.5623232350F, 0.5628068002F, 0.5632902642F, 0.5637736262F,
  143892. 0.5642568858F, 0.5647400423F, 0.5652230953F, 0.5657060442F,
  143893. 0.5661888883F, 0.5666716272F, 0.5671542603F, 0.5676367870F,
  143894. 0.5681192069F, 0.5686015192F, 0.5690837235F, 0.5695658192F,
  143895. 0.5700478058F, 0.5705296827F, 0.5710114494F, 0.5714931052F,
  143896. 0.5719746497F, 0.5724560822F, 0.5729374023F, 0.5734186094F,
  143897. 0.5738997029F, 0.5743806823F, 0.5748615470F, 0.5753422965F,
  143898. 0.5758229301F, 0.5763034475F, 0.5767838480F, 0.5772641310F,
  143899. 0.5777442960F, 0.5782243426F, 0.5787042700F, 0.5791840778F,
  143900. 0.5796637654F, 0.5801433322F, 0.5806227778F, 0.5811021016F,
  143901. 0.5815813029F, 0.5820603814F, 0.5825393363F, 0.5830181673F,
  143902. 0.5834968737F, 0.5839754549F, 0.5844539105F, 0.5849322399F,
  143903. 0.5854104425F, 0.5858885179F, 0.5863664653F, 0.5868442844F,
  143904. 0.5873219746F, 0.5877995353F, 0.5882769660F, 0.5887542661F,
  143905. 0.5892314351F, 0.5897084724F, 0.5901853776F, 0.5906621500F,
  143906. 0.5911387892F, 0.5916152945F, 0.5920916655F, 0.5925679016F,
  143907. 0.5930440022F, 0.5935199669F, 0.5939957950F, 0.5944714861F,
  143908. 0.5949470396F, 0.5954224550F, 0.5958977317F, 0.5963728692F,
  143909. 0.5968478669F, 0.5973227244F, 0.5977974411F, 0.5982720163F,
  143910. 0.5987464497F, 0.5992207407F, 0.5996948887F, 0.6001688932F,
  143911. 0.6006427537F, 0.6011164696F, 0.6015900405F, 0.6020634657F,
  143912. 0.6025367447F, 0.6030098770F, 0.6034828621F, 0.6039556995F,
  143913. 0.6044283885F, 0.6049009288F, 0.6053733196F, 0.6058455606F,
  143914. 0.6063176512F, 0.6067895909F, 0.6072613790F, 0.6077330152F,
  143915. 0.6082044989F, 0.6086758295F, 0.6091470065F, 0.6096180294F,
  143916. 0.6100888977F, 0.6105596108F, 0.6110301682F, 0.6115005694F,
  143917. 0.6119708139F, 0.6124409011F, 0.6129108305F, 0.6133806017F,
  143918. 0.6138502139F, 0.6143196669F, 0.6147889599F, 0.6152580926F,
  143919. 0.6157270643F, 0.6161958746F, 0.6166645230F, 0.6171330088F,
  143920. 0.6176013317F, 0.6180694910F, 0.6185374863F, 0.6190053171F,
  143921. 0.6194729827F, 0.6199404828F, 0.6204078167F, 0.6208749841F,
  143922. 0.6213419842F, 0.6218088168F, 0.6222754811F, 0.6227419768F,
  143923. 0.6232083032F, 0.6236744600F, 0.6241404465F, 0.6246062622F,
  143924. 0.6250719067F, 0.6255373795F, 0.6260026799F, 0.6264678076F,
  143925. 0.6269327619F, 0.6273975425F, 0.6278621487F, 0.6283265800F,
  143926. 0.6287908361F, 0.6292549163F, 0.6297188201F, 0.6301825471F,
  143927. 0.6306460966F, 0.6311094683F, 0.6315726617F, 0.6320356761F,
  143928. 0.6324985111F, 0.6329611662F, 0.6334236410F, 0.6338859348F,
  143929. 0.6343480472F, 0.6348099777F, 0.6352717257F, 0.6357332909F,
  143930. 0.6361946726F, 0.6366558704F, 0.6371168837F, 0.6375777122F,
  143931. 0.6380383552F, 0.6384988123F, 0.6389590830F, 0.6394191668F,
  143932. 0.6398790631F, 0.6403387716F, 0.6407982916F, 0.6412576228F,
  143933. 0.6417167645F, 0.6421757163F, 0.6426344778F, 0.6430930483F,
  143934. 0.6435514275F, 0.6440096149F, 0.6444676098F, 0.6449254119F,
  143935. 0.6453830207F, 0.6458404356F, 0.6462976562F, 0.6467546820F,
  143936. 0.6472115125F, 0.6476681472F, 0.6481245856F, 0.6485808273F,
  143937. 0.6490368717F, 0.6494927183F, 0.6499483667F, 0.6504038164F,
  143938. 0.6508590670F, 0.6513141178F, 0.6517689684F, 0.6522236185F,
  143939. 0.6526780673F, 0.6531323146F, 0.6535863598F, 0.6540402024F,
  143940. 0.6544938419F, 0.6549472779F, 0.6554005099F, 0.6558535373F,
  143941. 0.6563063598F, 0.6567589769F, 0.6572113880F, 0.6576635927F,
  143942. 0.6581155906F, 0.6585673810F, 0.6590189637F, 0.6594703380F,
  143943. 0.6599215035F, 0.6603724598F, 0.6608232064F, 0.6612737427F,
  143944. 0.6617240684F, 0.6621741829F, 0.6626240859F, 0.6630737767F,
  143945. 0.6635232550F, 0.6639725202F, 0.6644215720F, 0.6648704098F,
  143946. 0.6653190332F, 0.6657674417F, 0.6662156348F, 0.6666636121F,
  143947. 0.6671113731F, 0.6675589174F, 0.6680062445F, 0.6684533538F,
  143948. 0.6689002450F, 0.6693469177F, 0.6697933712F, 0.6702396052F,
  143949. 0.6706856193F, 0.6711314129F, 0.6715769855F, 0.6720223369F,
  143950. 0.6724674664F, 0.6729123736F, 0.6733570581F, 0.6738015194F,
  143951. 0.6742457570F, 0.6746897706F, 0.6751335596F, 0.6755771236F,
  143952. 0.6760204621F, 0.6764635747F, 0.6769064609F, 0.6773491204F,
  143953. 0.6777915525F, 0.6782337570F, 0.6786757332F, 0.6791174809F,
  143954. 0.6795589995F, 0.6800002886F, 0.6804413477F, 0.6808821765F,
  143955. 0.6813227743F, 0.6817631409F, 0.6822032758F, 0.6826431785F,
  143956. 0.6830828485F, 0.6835222855F, 0.6839614890F, 0.6844004585F,
  143957. 0.6848391936F, 0.6852776939F, 0.6857159589F, 0.6861539883F,
  143958. 0.6865917815F, 0.6870293381F, 0.6874666576F, 0.6879037398F,
  143959. 0.6883405840F, 0.6887771899F, 0.6892135571F, 0.6896496850F,
  143960. 0.6900855733F, 0.6905212216F, 0.6909566294F, 0.6913917963F,
  143961. 0.6918267218F, 0.6922614055F, 0.6926958471F, 0.6931300459F,
  143962. 0.6935640018F, 0.6939977141F, 0.6944311825F, 0.6948644066F,
  143963. 0.6952973859F, 0.6957301200F, 0.6961626085F, 0.6965948510F,
  143964. 0.6970268470F, 0.6974585961F, 0.6978900980F, 0.6983213521F,
  143965. 0.6987523580F, 0.6991831154F, 0.6996136238F, 0.7000438828F,
  143966. 0.7004738921F, 0.7009036510F, 0.7013331594F, 0.7017624166F,
  143967. 0.7021914224F, 0.7026201763F, 0.7030486779F, 0.7034769268F,
  143968. 0.7039049226F, 0.7043326648F, 0.7047601531F, 0.7051873870F,
  143969. 0.7056143662F, 0.7060410902F, 0.7064675586F, 0.7068937711F,
  143970. 0.7073197271F, 0.7077454264F, 0.7081708684F, 0.7085960529F,
  143971. 0.7090209793F, 0.7094456474F, 0.7098700566F, 0.7102942066F,
  143972. 0.7107180970F, 0.7111417274F, 0.7115650974F, 0.7119882066F,
  143973. 0.7124110545F, 0.7128336409F, 0.7132559653F, 0.7136780272F,
  143974. 0.7140998264F, 0.7145213624F, 0.7149426348F, 0.7153636433F,
  143975. 0.7157843874F, 0.7162048668F, 0.7166250810F, 0.7170450296F,
  143976. 0.7174647124F, 0.7178841289F, 0.7183032786F, 0.7187221613F,
  143977. 0.7191407765F, 0.7195591239F, 0.7199772030F, 0.7203950135F,
  143978. 0.7208125550F, 0.7212298271F, 0.7216468294F, 0.7220635616F,
  143979. 0.7224800233F, 0.7228962140F, 0.7233121335F, 0.7237277813F,
  143980. 0.7241431571F, 0.7245582604F, 0.7249730910F, 0.7253876484F,
  143981. 0.7258019322F, 0.7262159422F, 0.7266296778F, 0.7270431388F,
  143982. 0.7274563247F, 0.7278692353F, 0.7282818700F, 0.7286942287F,
  143983. 0.7291063108F, 0.7295181160F, 0.7299296440F, 0.7303408944F,
  143984. 0.7307518669F, 0.7311625609F, 0.7315729763F, 0.7319831126F,
  143985. 0.7323929695F, 0.7328025466F, 0.7332118435F, 0.7336208600F,
  143986. 0.7340295955F, 0.7344380499F, 0.7348462226F, 0.7352541134F,
  143987. 0.7356617220F, 0.7360690478F, 0.7364760907F, 0.7368828502F,
  143988. 0.7372893259F, 0.7376955176F, 0.7381014249F, 0.7385070475F,
  143989. 0.7389123849F, 0.7393174368F, 0.7397222029F, 0.7401266829F,
  143990. 0.7405308763F, 0.7409347829F, 0.7413384023F, 0.7417417341F,
  143991. 0.7421447780F, 0.7425475338F, 0.7429500009F, 0.7433521791F,
  143992. 0.7437540681F, 0.7441556674F, 0.7445569769F, 0.7449579960F,
  143993. 0.7453587245F, 0.7457591621F, 0.7461593084F, 0.7465591631F,
  143994. 0.7469587259F, 0.7473579963F, 0.7477569741F, 0.7481556590F,
  143995. 0.7485540506F, 0.7489521486F, 0.7493499526F, 0.7497474623F,
  143996. 0.7501446775F, 0.7505415977F, 0.7509382227F, 0.7513345521F,
  143997. 0.7517305856F, 0.7521263229F, 0.7525217636F, 0.7529169074F,
  143998. 0.7533117541F, 0.7537063032F, 0.7541005545F, 0.7544945076F,
  143999. 0.7548881623F, 0.7552815182F, 0.7556745749F, 0.7560673323F,
  144000. 0.7564597899F, 0.7568519474F, 0.7572438046F, 0.7576353611F,
  144001. 0.7580266166F, 0.7584175708F, 0.7588082235F, 0.7591985741F,
  144002. 0.7595886226F, 0.7599783685F, 0.7603678116F, 0.7607569515F,
  144003. 0.7611457879F, 0.7615343206F, 0.7619225493F, 0.7623104735F,
  144004. 0.7626980931F, 0.7630854078F, 0.7634724171F, 0.7638591209F,
  144005. 0.7642455188F, 0.7646316106F, 0.7650173959F, 0.7654028744F,
  144006. 0.7657880459F, 0.7661729100F, 0.7665574664F, 0.7669417150F,
  144007. 0.7673256553F, 0.7677092871F, 0.7680926100F, 0.7684756239F,
  144008. 0.7688583284F, 0.7692407232F, 0.7696228080F, 0.7700045826F,
  144009. 0.7703860467F, 0.7707671999F, 0.7711480420F, 0.7715285728F,
  144010. 0.7719087918F, 0.7722886989F, 0.7726682938F, 0.7730475762F,
  144011. 0.7734265458F, 0.7738052023F, 0.7741835454F, 0.7745615750F,
  144012. 0.7749392906F, 0.7753166921F, 0.7756937791F, 0.7760705514F,
  144013. 0.7764470087F, 0.7768231508F, 0.7771989773F, 0.7775744880F,
  144014. 0.7779496827F, 0.7783245610F, 0.7786991227F, 0.7790733676F,
  144015. 0.7794472953F, 0.7798209056F, 0.7801941982F, 0.7805671729F,
  144016. 0.7809398294F, 0.7813121675F, 0.7816841869F, 0.7820558873F,
  144017. 0.7824272684F, 0.7827983301F, 0.7831690720F, 0.7835394940F,
  144018. 0.7839095957F, 0.7842793768F, 0.7846488373F, 0.7850179767F,
  144019. 0.7853867948F, 0.7857552914F, 0.7861234663F, 0.7864913191F,
  144020. 0.7868588497F, 0.7872260578F, 0.7875929431F, 0.7879595055F,
  144021. 0.7883257445F, 0.7886916601F, 0.7890572520F, 0.7894225198F,
  144022. 0.7897874635F, 0.7901520827F, 0.7905163772F, 0.7908803468F,
  144023. 0.7912439912F, 0.7916073102F, 0.7919703035F, 0.7923329710F,
  144024. 0.7926953124F, 0.7930573274F, 0.7934190158F, 0.7937803774F,
  144025. 0.7941414120F, 0.7945021193F, 0.7948624991F, 0.7952225511F,
  144026. 0.7955822752F, 0.7959416711F, 0.7963007387F, 0.7966594775F,
  144027. 0.7970178875F, 0.7973759685F, 0.7977337201F, 0.7980911422F,
  144028. 0.7984482346F, 0.7988049970F, 0.7991614292F, 0.7995175310F,
  144029. 0.7998733022F, 0.8002287426F, 0.8005838519F, 0.8009386299F,
  144030. 0.8012930765F, 0.8016471914F, 0.8020009744F, 0.8023544253F,
  144031. 0.8027075438F, 0.8030603298F, 0.8034127831F, 0.8037649035F,
  144032. 0.8041166906F, 0.8044681445F, 0.8048192647F, 0.8051700512F,
  144033. 0.8055205038F, 0.8058706222F, 0.8062204062F, 0.8065698556F,
  144034. 0.8069189702F, 0.8072677499F, 0.8076161944F, 0.8079643036F,
  144035. 0.8083120772F, 0.8086595151F, 0.8090066170F, 0.8093533827F,
  144036. 0.8096998122F, 0.8100459051F, 0.8103916613F, 0.8107370806F,
  144037. 0.8110821628F, 0.8114269077F, 0.8117713151F, 0.8121153849F,
  144038. 0.8124591169F, 0.8128025108F, 0.8131455666F, 0.8134882839F,
  144039. 0.8138306627F, 0.8141727027F, 0.8145144038F, 0.8148557658F,
  144040. 0.8151967886F, 0.8155374718F, 0.8158778154F, 0.8162178192F,
  144041. 0.8165574830F, 0.8168968067F, 0.8172357900F, 0.8175744328F,
  144042. 0.8179127349F, 0.8182506962F, 0.8185883164F, 0.8189255955F,
  144043. 0.8192625332F, 0.8195991295F, 0.8199353840F, 0.8202712967F,
  144044. 0.8206068673F, 0.8209420958F, 0.8212769820F, 0.8216115256F,
  144045. 0.8219457266F, 0.8222795848F, 0.8226131000F, 0.8229462721F,
  144046. 0.8232791009F, 0.8236115863F, 0.8239437280F, 0.8242755260F,
  144047. 0.8246069801F, 0.8249380901F, 0.8252688559F, 0.8255992774F,
  144048. 0.8259293544F, 0.8262590867F, 0.8265884741F, 0.8269175167F,
  144049. 0.8272462141F, 0.8275745663F, 0.8279025732F, 0.8282302344F,
  144050. 0.8285575501F, 0.8288845199F, 0.8292111437F, 0.8295374215F,
  144051. 0.8298633530F, 0.8301889382F, 0.8305141768F, 0.8308390688F,
  144052. 0.8311636141F, 0.8314878124F, 0.8318116637F, 0.8321351678F,
  144053. 0.8324583246F, 0.8327811340F, 0.8331035957F, 0.8334257098F,
  144054. 0.8337474761F, 0.8340688944F, 0.8343899647F, 0.8347106867F,
  144055. 0.8350310605F, 0.8353510857F, 0.8356707624F, 0.8359900904F,
  144056. 0.8363090696F, 0.8366276999F, 0.8369459811F, 0.8372639131F,
  144057. 0.8375814958F, 0.8378987292F, 0.8382156130F, 0.8385321472F,
  144058. 0.8388483316F, 0.8391641662F, 0.8394796508F, 0.8397947853F,
  144059. 0.8401095697F, 0.8404240037F, 0.8407380873F, 0.8410518204F,
  144060. 0.8413652029F, 0.8416782347F, 0.8419909156F, 0.8423032456F,
  144061. 0.8426152245F, 0.8429268523F, 0.8432381289F, 0.8435490541F,
  144062. 0.8438596279F, 0.8441698502F, 0.8444797208F, 0.8447892396F,
  144063. 0.8450984067F, 0.8454072218F, 0.8457156849F, 0.8460237959F,
  144064. 0.8463315547F, 0.8466389612F, 0.8469460154F, 0.8472527170F,
  144065. 0.8475590661F, 0.8478650625F, 0.8481707063F, 0.8484759971F,
  144066. 0.8487809351F, 0.8490855201F, 0.8493897521F, 0.8496936308F,
  144067. 0.8499971564F, 0.8503003286F, 0.8506031474F, 0.8509056128F,
  144068. 0.8512077246F, 0.8515094828F, 0.8518108872F, 0.8521119379F,
  144069. 0.8524126348F, 0.8527129777F, 0.8530129666F, 0.8533126015F,
  144070. 0.8536118822F, 0.8539108087F, 0.8542093809F, 0.8545075988F,
  144071. 0.8548054623F, 0.8551029712F, 0.8554001257F, 0.8556969255F,
  144072. 0.8559933707F, 0.8562894611F, 0.8565851968F, 0.8568805775F,
  144073. 0.8571756034F, 0.8574702743F, 0.8577645902F, 0.8580585509F,
  144074. 0.8583521566F, 0.8586454070F, 0.8589383021F, 0.8592308420F,
  144075. 0.8595230265F, 0.8598148556F, 0.8601063292F, 0.8603974473F,
  144076. 0.8606882098F, 0.8609786167F, 0.8612686680F, 0.8615583636F,
  144077. 0.8618477034F, 0.8621366874F, 0.8624253156F, 0.8627135878F,
  144078. 0.8630015042F, 0.8632890646F, 0.8635762690F, 0.8638631173F,
  144079. 0.8641496096F, 0.8644357457F, 0.8647215257F, 0.8650069495F,
  144080. 0.8652920171F, 0.8655767283F, 0.8658610833F, 0.8661450820F,
  144081. 0.8664287243F, 0.8667120102F, 0.8669949397F, 0.8672775127F,
  144082. 0.8675597293F, 0.8678415894F, 0.8681230929F, 0.8684042398F,
  144083. 0.8686850302F, 0.8689654640F, 0.8692455412F, 0.8695252617F,
  144084. 0.8698046255F, 0.8700836327F, 0.8703622831F, 0.8706405768F,
  144085. 0.8709185138F, 0.8711960940F, 0.8714733174F, 0.8717501840F,
  144086. 0.8720266939F, 0.8723028469F, 0.8725786430F, 0.8728540824F,
  144087. 0.8731291648F, 0.8734038905F, 0.8736782592F, 0.8739522711F,
  144088. 0.8742259261F, 0.8744992242F, 0.8747721653F, 0.8750447496F,
  144089. 0.8753169770F, 0.8755888475F, 0.8758603611F, 0.8761315177F,
  144090. 0.8764023175F, 0.8766727603F, 0.8769428462F, 0.8772125752F,
  144091. 0.8774819474F, 0.8777509626F, 0.8780196209F, 0.8782879224F,
  144092. 0.8785558669F, 0.8788234546F, 0.8790906854F, 0.8793575594F,
  144093. 0.8796240765F, 0.8798902368F, 0.8801560403F, 0.8804214870F,
  144094. 0.8806865768F, 0.8809513099F, 0.8812156863F, 0.8814797059F,
  144095. 0.8817433687F, 0.8820066749F, 0.8822696243F, 0.8825322171F,
  144096. 0.8827944532F, 0.8830563327F, 0.8833178556F, 0.8835790219F,
  144097. 0.8838398316F, 0.8841002848F, 0.8843603815F, 0.8846201217F,
  144098. 0.8848795054F, 0.8851385327F, 0.8853972036F, 0.8856555182F,
  144099. 0.8859134764F, 0.8861710783F, 0.8864283239F, 0.8866852133F,
  144100. 0.8869417464F, 0.8871979234F, 0.8874537443F, 0.8877092090F,
  144101. 0.8879643177F, 0.8882190704F, 0.8884734671F, 0.8887275078F,
  144102. 0.8889811927F, 0.8892345216F, 0.8894874948F, 0.8897401122F,
  144103. 0.8899923738F, 0.8902442798F, 0.8904958301F, 0.8907470248F,
  144104. 0.8909978640F, 0.8912483477F, 0.8914984759F, 0.8917482487F,
  144105. 0.8919976662F, 0.8922467284F, 0.8924954353F, 0.8927437871F,
  144106. 0.8929917837F, 0.8932394252F, 0.8934867118F, 0.8937336433F,
  144107. 0.8939802199F, 0.8942264417F, 0.8944723087F, 0.8947178210F,
  144108. 0.8949629785F, 0.8952077815F, 0.8954522299F, 0.8956963239F,
  144109. 0.8959400634F, 0.8961834486F, 0.8964264795F, 0.8966691561F,
  144110. 0.8969114786F, 0.8971534470F, 0.8973950614F, 0.8976363219F,
  144111. 0.8978772284F, 0.8981177812F, 0.8983579802F, 0.8985978256F,
  144112. 0.8988373174F, 0.8990764556F, 0.8993152405F, 0.8995536720F,
  144113. 0.8997917502F, 0.9000294751F, 0.9002668470F, 0.9005038658F,
  144114. 0.9007405317F, 0.9009768446F, 0.9012128048F, 0.9014484123F,
  144115. 0.9016836671F, 0.9019185693F, 0.9021531191F, 0.9023873165F,
  144116. 0.9026211616F, 0.9028546546F, 0.9030877954F, 0.9033205841F,
  144117. 0.9035530210F, 0.9037851059F, 0.9040168392F, 0.9042482207F,
  144118. 0.9044792507F, 0.9047099293F, 0.9049402564F, 0.9051702323F,
  144119. 0.9053998569F, 0.9056291305F, 0.9058580531F, 0.9060866248F,
  144120. 0.9063148457F, 0.9065427159F, 0.9067702355F, 0.9069974046F,
  144121. 0.9072242233F, 0.9074506917F, 0.9076768100F, 0.9079025782F,
  144122. 0.9081279964F, 0.9083530647F, 0.9085777833F, 0.9088021523F,
  144123. 0.9090261717F, 0.9092498417F, 0.9094731623F, 0.9096961338F,
  144124. 0.9099187561F, 0.9101410295F, 0.9103629540F, 0.9105845297F,
  144125. 0.9108057568F, 0.9110266354F, 0.9112471656F, 0.9114673475F,
  144126. 0.9116871812F, 0.9119066668F, 0.9121258046F, 0.9123445945F,
  144127. 0.9125630367F, 0.9127811314F, 0.9129988786F, 0.9132162785F,
  144128. 0.9134333312F, 0.9136500368F, 0.9138663954F, 0.9140824073F,
  144129. 0.9142980724F, 0.9145133910F, 0.9147283632F, 0.9149429890F,
  144130. 0.9151572687F, 0.9153712023F, 0.9155847900F, 0.9157980319F,
  144131. 0.9160109282F, 0.9162234790F, 0.9164356844F, 0.9166475445F,
  144132. 0.9168590595F, 0.9170702296F, 0.9172810548F, 0.9174915354F,
  144133. 0.9177016714F, 0.9179114629F, 0.9181209102F, 0.9183300134F,
  144134. 0.9185387726F, 0.9187471879F, 0.9189552595F, 0.9191629876F,
  144135. 0.9193703723F, 0.9195774136F, 0.9197841119F, 0.9199904672F,
  144136. 0.9201964797F, 0.9204021495F, 0.9206074767F, 0.9208124616F,
  144137. 0.9210171043F, 0.9212214049F, 0.9214253636F, 0.9216289805F,
  144138. 0.9218322558F, 0.9220351896F, 0.9222377821F, 0.9224400335F,
  144139. 0.9226419439F, 0.9228435134F, 0.9230447423F, 0.9232456307F,
  144140. 0.9234461787F, 0.9236463865F, 0.9238462543F, 0.9240457822F,
  144141. 0.9242449704F, 0.9244438190F, 0.9246423282F, 0.9248404983F,
  144142. 0.9250383293F, 0.9252358214F, 0.9254329747F, 0.9256297896F,
  144143. 0.9258262660F, 0.9260224042F, 0.9262182044F, 0.9264136667F,
  144144. 0.9266087913F, 0.9268035783F, 0.9269980280F, 0.9271921405F,
  144145. 0.9273859160F, 0.9275793546F, 0.9277724566F, 0.9279652221F,
  144146. 0.9281576513F, 0.9283497443F, 0.9285415014F, 0.9287329227F,
  144147. 0.9289240084F, 0.9291147586F, 0.9293051737F, 0.9294952536F,
  144148. 0.9296849987F, 0.9298744091F, 0.9300634850F, 0.9302522266F,
  144149. 0.9304406340F, 0.9306287074F, 0.9308164471F, 0.9310038532F,
  144150. 0.9311909259F, 0.9313776654F, 0.9315640719F, 0.9317501455F,
  144151. 0.9319358865F, 0.9321212951F, 0.9323063713F, 0.9324911155F,
  144152. 0.9326755279F, 0.9328596085F, 0.9330433577F, 0.9332267756F,
  144153. 0.9334098623F, 0.9335926182F, 0.9337750434F, 0.9339571380F,
  144154. 0.9341389023F, 0.9343203366F, 0.9345014409F, 0.9346822155F,
  144155. 0.9348626606F, 0.9350427763F, 0.9352225630F, 0.9354020207F,
  144156. 0.9355811498F, 0.9357599503F, 0.9359384226F, 0.9361165667F,
  144157. 0.9362943830F, 0.9364718716F, 0.9366490327F, 0.9368258666F,
  144158. 0.9370023733F, 0.9371785533F, 0.9373544066F, 0.9375299335F,
  144159. 0.9377051341F, 0.9378800087F, 0.9380545576F, 0.9382287809F,
  144160. 0.9384026787F, 0.9385762515F, 0.9387494993F, 0.9389224223F,
  144161. 0.9390950209F, 0.9392672951F, 0.9394392453F, 0.9396108716F,
  144162. 0.9397821743F, 0.9399531536F, 0.9401238096F, 0.9402941427F,
  144163. 0.9404641530F, 0.9406338407F, 0.9408032061F, 0.9409722495F,
  144164. 0.9411409709F, 0.9413093707F, 0.9414774491F, 0.9416452062F,
  144165. 0.9418126424F, 0.9419797579F, 0.9421465528F, 0.9423130274F,
  144166. 0.9424791819F, 0.9426450166F, 0.9428105317F, 0.9429757274F,
  144167. 0.9431406039F, 0.9433051616F, 0.9434694005F, 0.9436333209F,
  144168. 0.9437969232F, 0.9439602074F, 0.9441231739F, 0.9442858229F,
  144169. 0.9444481545F, 0.9446101691F, 0.9447718669F, 0.9449332481F,
  144170. 0.9450943129F, 0.9452550617F, 0.9454154945F, 0.9455756118F,
  144171. 0.9457354136F, 0.9458949003F, 0.9460540721F, 0.9462129292F,
  144172. 0.9463714719F, 0.9465297003F, 0.9466876149F, 0.9468452157F,
  144173. 0.9470025031F, 0.9471594772F, 0.9473161384F, 0.9474724869F,
  144174. 0.9476285229F, 0.9477842466F, 0.9479396584F, 0.9480947585F,
  144175. 0.9482495470F, 0.9484040243F, 0.9485581906F, 0.9487120462F,
  144176. 0.9488655913F, 0.9490188262F, 0.9491717511F, 0.9493243662F,
  144177. 0.9494766718F, 0.9496286683F, 0.9497803557F, 0.9499317345F,
  144178. 0.9500828047F, 0.9502335668F, 0.9503840209F, 0.9505341673F,
  144179. 0.9506840062F, 0.9508335380F, 0.9509827629F, 0.9511316810F,
  144180. 0.9512802928F, 0.9514285984F, 0.9515765982F, 0.9517242923F,
  144181. 0.9518716810F, 0.9520187646F, 0.9521655434F, 0.9523120176F,
  144182. 0.9524581875F, 0.9526040534F, 0.9527496154F, 0.9528948739F,
  144183. 0.9530398292F, 0.9531844814F, 0.9533288310F, 0.9534728780F,
  144184. 0.9536166229F, 0.9537600659F, 0.9539032071F, 0.9540460470F,
  144185. 0.9541885858F, 0.9543308237F, 0.9544727611F, 0.9546143981F,
  144186. 0.9547557351F, 0.9548967723F, 0.9550375100F, 0.9551779485F,
  144187. 0.9553180881F, 0.9554579290F, 0.9555974714F, 0.9557367158F,
  144188. 0.9558756623F, 0.9560143112F, 0.9561526628F, 0.9562907174F,
  144189. 0.9564284752F, 0.9565659366F, 0.9567031017F, 0.9568399710F,
  144190. 0.9569765446F, 0.9571128229F, 0.9572488061F, 0.9573844944F,
  144191. 0.9575198883F, 0.9576549879F, 0.9577897936F, 0.9579243056F,
  144192. 0.9580585242F, 0.9581924497F, 0.9583260824F, 0.9584594226F,
  144193. 0.9585924705F, 0.9587252264F, 0.9588576906F, 0.9589898634F,
  144194. 0.9591217452F, 0.9592533360F, 0.9593846364F, 0.9595156465F,
  144195. 0.9596463666F, 0.9597767971F, 0.9599069382F, 0.9600367901F,
  144196. 0.9601663533F, 0.9602956279F, 0.9604246143F, 0.9605533128F,
  144197. 0.9606817236F, 0.9608098471F, 0.9609376835F, 0.9610652332F,
  144198. 0.9611924963F, 0.9613194733F, 0.9614461644F, 0.9615725699F,
  144199. 0.9616986901F, 0.9618245253F, 0.9619500757F, 0.9620753418F,
  144200. 0.9622003238F, 0.9623250219F, 0.9624494365F, 0.9625735679F,
  144201. 0.9626974163F, 0.9628209821F, 0.9629442656F, 0.9630672671F,
  144202. 0.9631899868F, 0.9633124251F, 0.9634345822F, 0.9635564585F,
  144203. 0.9636780543F, 0.9637993699F, 0.9639204056F, 0.9640411616F,
  144204. 0.9641616383F, 0.9642818359F, 0.9644017549F, 0.9645213955F,
  144205. 0.9646407579F, 0.9647598426F, 0.9648786497F, 0.9649971797F,
  144206. 0.9651154328F, 0.9652334092F, 0.9653511095F, 0.9654685337F,
  144207. 0.9655856823F, 0.9657025556F, 0.9658191538F, 0.9659354773F,
  144208. 0.9660515263F, 0.9661673013F, 0.9662828024F, 0.9663980300F,
  144209. 0.9665129845F, 0.9666276660F, 0.9667420750F, 0.9668562118F,
  144210. 0.9669700766F, 0.9670836698F, 0.9671969917F, 0.9673100425F,
  144211. 0.9674228227F, 0.9675353325F, 0.9676475722F, 0.9677595422F,
  144212. 0.9678712428F, 0.9679826742F, 0.9680938368F, 0.9682047309F,
  144213. 0.9683153569F, 0.9684257150F, 0.9685358056F, 0.9686456289F,
  144214. 0.9687551853F, 0.9688644752F, 0.9689734987F, 0.9690822564F,
  144215. 0.9691907483F, 0.9692989750F, 0.9694069367F, 0.9695146337F,
  144216. 0.9696220663F, 0.9697292349F, 0.9698361398F, 0.9699427813F,
  144217. 0.9700491597F, 0.9701552754F, 0.9702611286F, 0.9703667197F,
  144218. 0.9704720490F, 0.9705771169F, 0.9706819236F, 0.9707864695F,
  144219. 0.9708907549F, 0.9709947802F, 0.9710985456F, 0.9712020514F,
  144220. 0.9713052981F, 0.9714082859F, 0.9715110151F, 0.9716134862F,
  144221. 0.9717156993F, 0.9718176549F, 0.9719193532F, 0.9720207946F,
  144222. 0.9721219794F, 0.9722229080F, 0.9723235806F, 0.9724239976F,
  144223. 0.9725241593F, 0.9726240661F, 0.9727237183F, 0.9728231161F,
  144224. 0.9729222601F, 0.9730211503F, 0.9731197873F, 0.9732181713F,
  144225. 0.9733163027F, 0.9734141817F, 0.9735118088F, 0.9736091842F,
  144226. 0.9737063083F, 0.9738031814F, 0.9738998039F, 0.9739961760F,
  144227. 0.9740922981F, 0.9741881706F, 0.9742837938F, 0.9743791680F,
  144228. 0.9744742935F, 0.9745691707F, 0.9746637999F, 0.9747581814F,
  144229. 0.9748523157F, 0.9749462029F, 0.9750398435F, 0.9751332378F,
  144230. 0.9752263861F, 0.9753192887F, 0.9754119461F, 0.9755043585F,
  144231. 0.9755965262F, 0.9756884496F, 0.9757801291F, 0.9758715650F,
  144232. 0.9759627575F, 0.9760537071F, 0.9761444141F, 0.9762348789F,
  144233. 0.9763251016F, 0.9764150828F, 0.9765048228F, 0.9765943218F,
  144234. 0.9766835802F, 0.9767725984F, 0.9768613767F, 0.9769499154F,
  144235. 0.9770382149F, 0.9771262755F, 0.9772140976F, 0.9773016815F,
  144236. 0.9773890275F, 0.9774761360F, 0.9775630073F, 0.9776496418F,
  144237. 0.9777360398F, 0.9778222016F, 0.9779081277F, 0.9779938182F,
  144238. 0.9780792736F, 0.9781644943F, 0.9782494805F, 0.9783342326F,
  144239. 0.9784187509F, 0.9785030359F, 0.9785870877F, 0.9786709069F,
  144240. 0.9787544936F, 0.9788378484F, 0.9789209714F, 0.9790038631F,
  144241. 0.9790865238F, 0.9791689538F, 0.9792511535F, 0.9793331232F,
  144242. 0.9794148633F, 0.9794963742F, 0.9795776561F, 0.9796587094F,
  144243. 0.9797395345F, 0.9798201316F, 0.9799005013F, 0.9799806437F,
  144244. 0.9800605593F, 0.9801402483F, 0.9802197112F, 0.9802989483F,
  144245. 0.9803779600F, 0.9804567465F, 0.9805353082F, 0.9806136455F,
  144246. 0.9806917587F, 0.9807696482F, 0.9808473143F, 0.9809247574F,
  144247. 0.9810019778F, 0.9810789759F, 0.9811557519F, 0.9812323064F,
  144248. 0.9813086395F, 0.9813847517F, 0.9814606433F, 0.9815363147F,
  144249. 0.9816117662F, 0.9816869981F, 0.9817620108F, 0.9818368047F,
  144250. 0.9819113801F, 0.9819857374F, 0.9820598769F, 0.9821337989F,
  144251. 0.9822075038F, 0.9822809920F, 0.9823542638F, 0.9824273195F,
  144252. 0.9825001596F, 0.9825727843F, 0.9826451940F, 0.9827173891F,
  144253. 0.9827893700F, 0.9828611368F, 0.9829326901F, 0.9830040302F,
  144254. 0.9830751574F, 0.9831460720F, 0.9832167745F, 0.9832872652F,
  144255. 0.9833575444F, 0.9834276124F, 0.9834974697F, 0.9835671166F,
  144256. 0.9836365535F, 0.9837057806F, 0.9837747983F, 0.9838436071F,
  144257. 0.9839122072F, 0.9839805990F, 0.9840487829F, 0.9841167591F,
  144258. 0.9841845282F, 0.9842520903F, 0.9843194459F, 0.9843865953F,
  144259. 0.9844535389F, 0.9845202771F, 0.9845868101F, 0.9846531383F,
  144260. 0.9847192622F, 0.9847851820F, 0.9848508980F, 0.9849164108F,
  144261. 0.9849817205F, 0.9850468276F, 0.9851117324F, 0.9851764352F,
  144262. 0.9852409365F, 0.9853052366F, 0.9853693358F, 0.9854332344F,
  144263. 0.9854969330F, 0.9855604317F, 0.9856237309F, 0.9856868310F,
  144264. 0.9857497325F, 0.9858124355F, 0.9858749404F, 0.9859372477F,
  144265. 0.9859993577F, 0.9860612707F, 0.9861229871F, 0.9861845072F,
  144266. 0.9862458315F, 0.9863069601F, 0.9863678936F, 0.9864286322F,
  144267. 0.9864891764F, 0.9865495264F, 0.9866096826F, 0.9866696454F,
  144268. 0.9867294152F, 0.9867889922F, 0.9868483769F, 0.9869075695F,
  144269. 0.9869665706F, 0.9870253803F, 0.9870839991F, 0.9871424273F,
  144270. 0.9872006653F, 0.9872587135F, 0.9873165721F, 0.9873742415F,
  144271. 0.9874317222F, 0.9874890144F, 0.9875461185F, 0.9876030348F,
  144272. 0.9876597638F, 0.9877163057F, 0.9877726610F, 0.9878288300F,
  144273. 0.9878848130F, 0.9879406104F, 0.9879962225F, 0.9880516497F,
  144274. 0.9881068924F, 0.9881619509F, 0.9882168256F, 0.9882715168F,
  144275. 0.9883260249F, 0.9883803502F, 0.9884344931F, 0.9884884539F,
  144276. 0.9885422331F, 0.9885958309F, 0.9886492477F, 0.9887024838F,
  144277. 0.9887555397F, 0.9888084157F, 0.9888611120F, 0.9889136292F,
  144278. 0.9889659675F, 0.9890181273F, 0.9890701089F, 0.9891219128F,
  144279. 0.9891735392F, 0.9892249885F, 0.9892762610F, 0.9893273572F,
  144280. 0.9893782774F, 0.9894290219F, 0.9894795911F, 0.9895299853F,
  144281. 0.9895802049F, 0.9896302502F, 0.9896801217F, 0.9897298196F,
  144282. 0.9897793443F, 0.9898286961F, 0.9898778755F, 0.9899268828F,
  144283. 0.9899757183F, 0.9900243823F, 0.9900728753F, 0.9901211976F,
  144284. 0.9901693495F, 0.9902173314F, 0.9902651436F, 0.9903127865F,
  144285. 0.9903602605F, 0.9904075659F, 0.9904547031F, 0.9905016723F,
  144286. 0.9905484740F, 0.9905951086F, 0.9906415763F, 0.9906878775F,
  144287. 0.9907340126F, 0.9907799819F, 0.9908257858F, 0.9908714247F,
  144288. 0.9909168988F, 0.9909622086F, 0.9910073543F, 0.9910523364F,
  144289. 0.9910971552F, 0.9911418110F, 0.9911863042F, 0.9912306351F,
  144290. 0.9912748042F, 0.9913188117F, 0.9913626580F, 0.9914063435F,
  144291. 0.9914498684F, 0.9914932333F, 0.9915364383F, 0.9915794839F,
  144292. 0.9916223703F, 0.9916650981F, 0.9917076674F, 0.9917500787F,
  144293. 0.9917923323F, 0.9918344286F, 0.9918763679F, 0.9919181505F,
  144294. 0.9919597769F, 0.9920012473F, 0.9920425621F, 0.9920837217F,
  144295. 0.9921247263F, 0.9921655765F, 0.9922062724F, 0.9922468145F,
  144296. 0.9922872030F, 0.9923274385F, 0.9923675211F, 0.9924074513F,
  144297. 0.9924472294F, 0.9924868557F, 0.9925263306F, 0.9925656544F,
  144298. 0.9926048275F, 0.9926438503F, 0.9926827230F, 0.9927214461F,
  144299. 0.9927600199F, 0.9927984446F, 0.9928367208F, 0.9928748486F,
  144300. 0.9929128285F, 0.9929506608F, 0.9929883459F, 0.9930258841F,
  144301. 0.9930632757F, 0.9931005211F, 0.9931376207F, 0.9931745747F,
  144302. 0.9932113836F, 0.9932480476F, 0.9932845671F, 0.9933209425F,
  144303. 0.9933571742F, 0.9933932623F, 0.9934292074F, 0.9934650097F,
  144304. 0.9935006696F, 0.9935361874F, 0.9935715635F, 0.9936067982F,
  144305. 0.9936418919F, 0.9936768448F, 0.9937116574F, 0.9937463300F,
  144306. 0.9937808629F, 0.9938152565F, 0.9938495111F, 0.9938836271F,
  144307. 0.9939176047F, 0.9939514444F, 0.9939851465F, 0.9940187112F,
  144308. 0.9940521391F, 0.9940854303F, 0.9941185853F, 0.9941516044F,
  144309. 0.9941844879F, 0.9942172361F, 0.9942498495F, 0.9942823283F,
  144310. 0.9943146729F, 0.9943468836F, 0.9943789608F, 0.9944109047F,
  144311. 0.9944427158F, 0.9944743944F, 0.9945059408F, 0.9945373553F,
  144312. 0.9945686384F, 0.9945997902F, 0.9946308112F, 0.9946617017F,
  144313. 0.9946924621F, 0.9947230926F, 0.9947535937F, 0.9947839656F,
  144314. 0.9948142086F, 0.9948443232F, 0.9948743097F, 0.9949041683F,
  144315. 0.9949338995F, 0.9949635035F, 0.9949929807F, 0.9950223315F,
  144316. 0.9950515561F, 0.9950806549F, 0.9951096282F, 0.9951384764F,
  144317. 0.9951671998F, 0.9951957987F, 0.9952242735F, 0.9952526245F,
  144318. 0.9952808520F, 0.9953089564F, 0.9953369380F, 0.9953647971F,
  144319. 0.9953925340F, 0.9954201491F, 0.9954476428F, 0.9954750153F,
  144320. 0.9955022670F, 0.9955293981F, 0.9955564092F, 0.9955833003F,
  144321. 0.9956100720F, 0.9956367245F, 0.9956632582F, 0.9956896733F,
  144322. 0.9957159703F, 0.9957421494F, 0.9957682110F, 0.9957941553F,
  144323. 0.9958199828F, 0.9958456937F, 0.9958712884F, 0.9958967672F,
  144324. 0.9959221305F, 0.9959473784F, 0.9959725115F, 0.9959975300F,
  144325. 0.9960224342F, 0.9960472244F, 0.9960719011F, 0.9960964644F,
  144326. 0.9961209148F, 0.9961452525F, 0.9961694779F, 0.9961935913F,
  144327. 0.9962175930F, 0.9962414834F, 0.9962652627F, 0.9962889313F,
  144328. 0.9963124895F, 0.9963359377F, 0.9963592761F, 0.9963825051F,
  144329. 0.9964056250F, 0.9964286361F, 0.9964515387F, 0.9964743332F,
  144330. 0.9964970198F, 0.9965195990F, 0.9965420709F, 0.9965644360F,
  144331. 0.9965866946F, 0.9966088469F, 0.9966308932F, 0.9966528340F,
  144332. 0.9966746695F, 0.9966964001F, 0.9967180260F, 0.9967395475F,
  144333. 0.9967609651F, 0.9967822789F, 0.9968034894F, 0.9968245968F,
  144334. 0.9968456014F, 0.9968665036F, 0.9968873037F, 0.9969080019F,
  144335. 0.9969285987F, 0.9969490942F, 0.9969694889F, 0.9969897830F,
  144336. 0.9970099769F, 0.9970300708F, 0.9970500651F, 0.9970699601F,
  144337. 0.9970897561F, 0.9971094533F, 0.9971290522F, 0.9971485531F,
  144338. 0.9971679561F, 0.9971872617F, 0.9972064702F, 0.9972255818F,
  144339. 0.9972445968F, 0.9972635157F, 0.9972823386F, 0.9973010659F,
  144340. 0.9973196980F, 0.9973382350F, 0.9973566773F, 0.9973750253F,
  144341. 0.9973932791F, 0.9974114392F, 0.9974295059F, 0.9974474793F,
  144342. 0.9974653599F, 0.9974831480F, 0.9975008438F, 0.9975184476F,
  144343. 0.9975359598F, 0.9975533806F, 0.9975707104F, 0.9975879495F,
  144344. 0.9976050981F, 0.9976221566F, 0.9976391252F, 0.9976560043F,
  144345. 0.9976727941F, 0.9976894950F, 0.9977061073F, 0.9977226312F,
  144346. 0.9977390671F, 0.9977554152F, 0.9977716759F, 0.9977878495F,
  144347. 0.9978039361F, 0.9978199363F, 0.9978358501F, 0.9978516780F,
  144348. 0.9978674202F, 0.9978830771F, 0.9978986488F, 0.9979141358F,
  144349. 0.9979295383F, 0.9979448566F, 0.9979600909F, 0.9979752417F,
  144350. 0.9979903091F, 0.9980052936F, 0.9980201952F, 0.9980350145F,
  144351. 0.9980497515F, 0.9980644067F, 0.9980789804F, 0.9980934727F,
  144352. 0.9981078841F, 0.9981222147F, 0.9981364649F, 0.9981506350F,
  144353. 0.9981647253F, 0.9981787360F, 0.9981926674F, 0.9982065199F,
  144354. 0.9982202936F, 0.9982339890F, 0.9982476062F, 0.9982611456F,
  144355. 0.9982746074F, 0.9982879920F, 0.9983012996F, 0.9983145304F,
  144356. 0.9983276849F, 0.9983407632F, 0.9983537657F, 0.9983666926F,
  144357. 0.9983795442F, 0.9983923208F, 0.9984050226F, 0.9984176501F,
  144358. 0.9984302033F, 0.9984426827F, 0.9984550884F, 0.9984674208F,
  144359. 0.9984796802F, 0.9984918667F, 0.9985039808F, 0.9985160227F,
  144360. 0.9985279926F, 0.9985398909F, 0.9985517177F, 0.9985634734F,
  144361. 0.9985751583F, 0.9985867727F, 0.9985983167F, 0.9986097907F,
  144362. 0.9986211949F, 0.9986325297F, 0.9986437953F, 0.9986549919F,
  144363. 0.9986661199F, 0.9986771795F, 0.9986881710F, 0.9986990946F,
  144364. 0.9987099507F, 0.9987207394F, 0.9987314611F, 0.9987421161F,
  144365. 0.9987527045F, 0.9987632267F, 0.9987736829F, 0.9987840734F,
  144366. 0.9987943985F, 0.9988046584F, 0.9988148534F, 0.9988249838F,
  144367. 0.9988350498F, 0.9988450516F, 0.9988549897F, 0.9988648641F,
  144368. 0.9988746753F, 0.9988844233F, 0.9988941086F, 0.9989037313F,
  144369. 0.9989132918F, 0.9989227902F, 0.9989322269F, 0.9989416021F,
  144370. 0.9989509160F, 0.9989601690F, 0.9989693613F, 0.9989784931F,
  144371. 0.9989875647F, 0.9989965763F, 0.9990055283F, 0.9990144208F,
  144372. 0.9990232541F, 0.9990320286F, 0.9990407443F, 0.9990494016F,
  144373. 0.9990580008F, 0.9990665421F, 0.9990750257F, 0.9990834519F,
  144374. 0.9990918209F, 0.9991001331F, 0.9991083886F, 0.9991165877F,
  144375. 0.9991247307F, 0.9991328177F, 0.9991408491F, 0.9991488251F,
  144376. 0.9991567460F, 0.9991646119F, 0.9991724232F, 0.9991801801F,
  144377. 0.9991878828F, 0.9991955316F, 0.9992031267F, 0.9992106684F,
  144378. 0.9992181569F, 0.9992255925F, 0.9992329753F, 0.9992403057F,
  144379. 0.9992475839F, 0.9992548101F, 0.9992619846F, 0.9992691076F,
  144380. 0.9992761793F, 0.9992832001F, 0.9992901701F, 0.9992970895F,
  144381. 0.9993039587F, 0.9993107777F, 0.9993175470F, 0.9993242667F,
  144382. 0.9993309371F, 0.9993375583F, 0.9993441307F, 0.9993506545F,
  144383. 0.9993571298F, 0.9993635570F, 0.9993699362F, 0.9993762678F,
  144384. 0.9993825519F, 0.9993887887F, 0.9993949785F, 0.9994011216F,
  144385. 0.9994072181F, 0.9994132683F, 0.9994192725F, 0.9994252307F,
  144386. 0.9994311434F, 0.9994370107F, 0.9994428327F, 0.9994486099F,
  144387. 0.9994543423F, 0.9994600303F, 0.9994656739F, 0.9994712736F,
  144388. 0.9994768294F, 0.9994823417F, 0.9994878105F, 0.9994932363F,
  144389. 0.9994986191F, 0.9995039592F, 0.9995092568F, 0.9995145122F,
  144390. 0.9995197256F, 0.9995248971F, 0.9995300270F, 0.9995351156F,
  144391. 0.9995401630F, 0.9995451695F, 0.9995501352F, 0.9995550604F,
  144392. 0.9995599454F, 0.9995647903F, 0.9995695953F, 0.9995743607F,
  144393. 0.9995790866F, 0.9995837734F, 0.9995884211F, 0.9995930300F,
  144394. 0.9995976004F, 0.9996021324F, 0.9996066263F, 0.9996110822F,
  144395. 0.9996155004F, 0.9996198810F, 0.9996242244F, 0.9996285306F,
  144396. 0.9996327999F, 0.9996370326F, 0.9996412287F, 0.9996453886F,
  144397. 0.9996495125F, 0.9996536004F, 0.9996576527F, 0.9996616696F,
  144398. 0.9996656512F, 0.9996695977F, 0.9996735094F, 0.9996773865F,
  144399. 0.9996812291F, 0.9996850374F, 0.9996888118F, 0.9996925523F,
  144400. 0.9996962591F, 0.9996999325F, 0.9997035727F, 0.9997071798F,
  144401. 0.9997107541F, 0.9997142957F, 0.9997178049F, 0.9997212818F,
  144402. 0.9997247266F, 0.9997281396F, 0.9997315209F, 0.9997348708F,
  144403. 0.9997381893F, 0.9997414767F, 0.9997447333F, 0.9997479591F,
  144404. 0.9997511544F, 0.9997543194F, 0.9997574542F, 0.9997605591F,
  144405. 0.9997636342F, 0.9997666797F, 0.9997696958F, 0.9997726828F,
  144406. 0.9997756407F, 0.9997785698F, 0.9997814703F, 0.9997843423F,
  144407. 0.9997871860F, 0.9997900016F, 0.9997927894F, 0.9997955494F,
  144408. 0.9997982818F, 0.9998009869F, 0.9998036648F, 0.9998063157F,
  144409. 0.9998089398F, 0.9998115373F, 0.9998141082F, 0.9998166529F,
  144410. 0.9998191715F, 0.9998216642F, 0.9998241311F, 0.9998265724F,
  144411. 0.9998289884F, 0.9998313790F, 0.9998337447F, 0.9998360854F,
  144412. 0.9998384015F, 0.9998406930F, 0.9998429602F, 0.9998452031F,
  144413. 0.9998474221F, 0.9998496171F, 0.9998517885F, 0.9998539364F,
  144414. 0.9998560610F, 0.9998581624F, 0.9998602407F, 0.9998622962F,
  144415. 0.9998643291F, 0.9998663394F, 0.9998683274F, 0.9998702932F,
  144416. 0.9998722370F, 0.9998741589F, 0.9998760591F, 0.9998779378F,
  144417. 0.9998797952F, 0.9998816313F, 0.9998834464F, 0.9998852406F,
  144418. 0.9998870141F, 0.9998887670F, 0.9998904995F, 0.9998922117F,
  144419. 0.9998939039F, 0.9998955761F, 0.9998972285F, 0.9998988613F,
  144420. 0.9999004746F, 0.9999020686F, 0.9999036434F, 0.9999051992F,
  144421. 0.9999067362F, 0.9999082544F, 0.9999097541F, 0.9999112354F,
  144422. 0.9999126984F, 0.9999141433F, 0.9999155703F, 0.9999169794F,
  144423. 0.9999183709F, 0.9999197449F, 0.9999211014F, 0.9999224408F,
  144424. 0.9999237631F, 0.9999250684F, 0.9999263570F, 0.9999276289F,
  144425. 0.9999288843F, 0.9999301233F, 0.9999313461F, 0.9999325529F,
  144426. 0.9999337437F, 0.9999349187F, 0.9999360780F, 0.9999372218F,
  144427. 0.9999383503F, 0.9999394635F, 0.9999405616F, 0.9999416447F,
  144428. 0.9999427129F, 0.9999437665F, 0.9999448055F, 0.9999458301F,
  144429. 0.9999468404F, 0.9999478365F, 0.9999488185F, 0.9999497867F,
  144430. 0.9999507411F, 0.9999516819F, 0.9999526091F, 0.9999535230F,
  144431. 0.9999544236F, 0.9999553111F, 0.9999561856F, 0.9999570472F,
  144432. 0.9999578960F, 0.9999587323F, 0.9999595560F, 0.9999603674F,
  144433. 0.9999611666F, 0.9999619536F, 0.9999627286F, 0.9999634917F,
  144434. 0.9999642431F, 0.9999649828F, 0.9999657110F, 0.9999664278F,
  144435. 0.9999671334F, 0.9999678278F, 0.9999685111F, 0.9999691835F,
  144436. 0.9999698451F, 0.9999704960F, 0.9999711364F, 0.9999717662F,
  144437. 0.9999723858F, 0.9999729950F, 0.9999735942F, 0.9999741834F,
  144438. 0.9999747626F, 0.9999753321F, 0.9999758919F, 0.9999764421F,
  144439. 0.9999769828F, 0.9999775143F, 0.9999780364F, 0.9999785495F,
  144440. 0.9999790535F, 0.9999795485F, 0.9999800348F, 0.9999805124F,
  144441. 0.9999809813F, 0.9999814417F, 0.9999818938F, 0.9999823375F,
  144442. 0.9999827731F, 0.9999832005F, 0.9999836200F, 0.9999840316F,
  144443. 0.9999844353F, 0.9999848314F, 0.9999852199F, 0.9999856008F,
  144444. 0.9999859744F, 0.9999863407F, 0.9999866997F, 0.9999870516F,
  144445. 0.9999873965F, 0.9999877345F, 0.9999880656F, 0.9999883900F,
  144446. 0.9999887078F, 0.9999890190F, 0.9999893237F, 0.9999896220F,
  144447. 0.9999899140F, 0.9999901999F, 0.9999904796F, 0.9999907533F,
  144448. 0.9999910211F, 0.9999912830F, 0.9999915391F, 0.9999917896F,
  144449. 0.9999920345F, 0.9999922738F, 0.9999925077F, 0.9999927363F,
  144450. 0.9999929596F, 0.9999931777F, 0.9999933907F, 0.9999935987F,
  144451. 0.9999938018F, 0.9999940000F, 0.9999941934F, 0.9999943820F,
  144452. 0.9999945661F, 0.9999947456F, 0.9999949206F, 0.9999950912F,
  144453. 0.9999952575F, 0.9999954195F, 0.9999955773F, 0.9999957311F,
  144454. 0.9999958807F, 0.9999960265F, 0.9999961683F, 0.9999963063F,
  144455. 0.9999964405F, 0.9999965710F, 0.9999966979F, 0.9999968213F,
  144456. 0.9999969412F, 0.9999970576F, 0.9999971707F, 0.9999972805F,
  144457. 0.9999973871F, 0.9999974905F, 0.9999975909F, 0.9999976881F,
  144458. 0.9999977824F, 0.9999978738F, 0.9999979624F, 0.9999980481F,
  144459. 0.9999981311F, 0.9999982115F, 0.9999982892F, 0.9999983644F,
  144460. 0.9999984370F, 0.9999985072F, 0.9999985750F, 0.9999986405F,
  144461. 0.9999987037F, 0.9999987647F, 0.9999988235F, 0.9999988802F,
  144462. 0.9999989348F, 0.9999989873F, 0.9999990379F, 0.9999990866F,
  144463. 0.9999991334F, 0.9999991784F, 0.9999992217F, 0.9999992632F,
  144464. 0.9999993030F, 0.9999993411F, 0.9999993777F, 0.9999994128F,
  144465. 0.9999994463F, 0.9999994784F, 0.9999995091F, 0.9999995384F,
  144466. 0.9999995663F, 0.9999995930F, 0.9999996184F, 0.9999996426F,
  144467. 0.9999996657F, 0.9999996876F, 0.9999997084F, 0.9999997282F,
  144468. 0.9999997469F, 0.9999997647F, 0.9999997815F, 0.9999997973F,
  144469. 0.9999998123F, 0.9999998265F, 0.9999998398F, 0.9999998524F,
  144470. 0.9999998642F, 0.9999998753F, 0.9999998857F, 0.9999998954F,
  144471. 0.9999999045F, 0.9999999130F, 0.9999999209F, 0.9999999282F,
  144472. 0.9999999351F, 0.9999999414F, 0.9999999472F, 0.9999999526F,
  144473. 0.9999999576F, 0.9999999622F, 0.9999999664F, 0.9999999702F,
  144474. 0.9999999737F, 0.9999999769F, 0.9999999798F, 0.9999999824F,
  144475. 0.9999999847F, 0.9999999868F, 0.9999999887F, 0.9999999904F,
  144476. 0.9999999919F, 0.9999999932F, 0.9999999943F, 0.9999999953F,
  144477. 0.9999999961F, 0.9999999969F, 0.9999999975F, 0.9999999980F,
  144478. 0.9999999985F, 0.9999999988F, 0.9999999991F, 0.9999999993F,
  144479. 0.9999999995F, 0.9999999997F, 0.9999999998F, 0.9999999999F,
  144480. 0.9999999999F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144481. 1.0000000000F, 1.0000000000F, 1.0000000000F, 1.0000000000F,
  144482. };
  144483. static float *vwin[8] = {
  144484. vwin64,
  144485. vwin128,
  144486. vwin256,
  144487. vwin512,
  144488. vwin1024,
  144489. vwin2048,
  144490. vwin4096,
  144491. vwin8192,
  144492. };
  144493. float *_vorbis_window_get(int n){
  144494. return vwin[n];
  144495. }
  144496. void _vorbis_apply_window(float *d,int *winno,long *blocksizes,
  144497. int lW,int W,int nW){
  144498. lW=(W?lW:0);
  144499. nW=(W?nW:0);
  144500. {
  144501. float *windowLW=vwin[winno[lW]];
  144502. float *windowNW=vwin[winno[nW]];
  144503. long n=blocksizes[W];
  144504. long ln=blocksizes[lW];
  144505. long rn=blocksizes[nW];
  144506. long leftbegin=n/4-ln/4;
  144507. long leftend=leftbegin+ln/2;
  144508. long rightbegin=n/2+n/4-rn/4;
  144509. long rightend=rightbegin+rn/2;
  144510. int i,p;
  144511. for(i=0;i<leftbegin;i++)
  144512. d[i]=0.f;
  144513. for(p=0;i<leftend;i++,p++)
  144514. d[i]*=windowLW[p];
  144515. for(i=rightbegin,p=rn/2-1;i<rightend;i++,p--)
  144516. d[i]*=windowNW[p];
  144517. for(;i<n;i++)
  144518. d[i]=0.f;
  144519. }
  144520. }
  144521. #endif
  144522. /*** End of inlined file: window.c ***/
  144523. #else
  144524. #include <vorbis/vorbisenc.h>
  144525. #include <vorbis/codec.h>
  144526. #include <vorbis/vorbisfile.h>
  144527. #endif
  144528. }
  144529. BEGIN_JUCE_NAMESPACE
  144530. using namespace OggVorbisNamespace;
  144531. static const char* const oggFormatName = "Ogg-Vorbis file";
  144532. static const tchar* const oggExtensions[] = { T(".ogg"), 0 };
  144533. class OggReader : public AudioFormatReader
  144534. {
  144535. OggVorbis_File ovFile;
  144536. ov_callbacks callbacks;
  144537. AudioSampleBuffer reservoir;
  144538. int reservoirStart, samplesInReservoir;
  144539. public:
  144540. OggReader (InputStream* const inp)
  144541. : AudioFormatReader (inp, TRANS (oggFormatName)),
  144542. reservoir (2, 4096),
  144543. reservoirStart (0),
  144544. samplesInReservoir (0)
  144545. {
  144546. sampleRate = 0;
  144547. usesFloatingPointData = true;
  144548. callbacks.read_func = &oggReadCallback;
  144549. callbacks.seek_func = &oggSeekCallback;
  144550. callbacks.close_func = &oggCloseCallback;
  144551. callbacks.tell_func = &oggTellCallback;
  144552. const int err = ov_open_callbacks (input, &ovFile, 0, 0, callbacks);
  144553. if (err == 0)
  144554. {
  144555. vorbis_info* info = ov_info (&ovFile, -1);
  144556. lengthInSamples = (uint32) ov_pcm_total (&ovFile, -1);
  144557. numChannels = info->channels;
  144558. bitsPerSample = 16;
  144559. sampleRate = info->rate;
  144560. reservoir.setSize (numChannels,
  144561. (int) jmin (lengthInSamples, (int64) reservoir.getNumSamples()));
  144562. }
  144563. }
  144564. ~OggReader()
  144565. {
  144566. ov_clear (&ovFile);
  144567. }
  144568. bool readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  144569. int64 startSampleInFile, int numSamples)
  144570. {
  144571. while (numSamples > 0)
  144572. {
  144573. const int numAvailable = reservoirStart + samplesInReservoir - startSampleInFile;
  144574. if (startSampleInFile >= reservoirStart && numAvailable > 0)
  144575. {
  144576. // got a few samples overlapping, so use them before seeking..
  144577. const int numToUse = jmin (numSamples, numAvailable);
  144578. for (int i = jmin (numDestChannels, reservoir.getNumChannels()); --i >= 0;)
  144579. if (destSamples[i] != 0)
  144580. memcpy (destSamples[i] + startOffsetInDestBuffer,
  144581. reservoir.getSampleData (i, (int) (startSampleInFile - reservoirStart)),
  144582. sizeof (float) * numToUse);
  144583. startSampleInFile += numToUse;
  144584. numSamples -= numToUse;
  144585. startOffsetInDestBuffer += numToUse;
  144586. if (numSamples == 0)
  144587. break;
  144588. }
  144589. if (startSampleInFile < reservoirStart
  144590. || startSampleInFile + numSamples > reservoirStart + samplesInReservoir)
  144591. {
  144592. // buffer miss, so refill the reservoir
  144593. int bitStream = 0;
  144594. reservoirStart = jmax (0, (int) startSampleInFile);
  144595. samplesInReservoir = reservoir.getNumSamples();
  144596. if (reservoirStart != (int) ov_pcm_tell (&ovFile))
  144597. ov_pcm_seek (&ovFile, reservoirStart);
  144598. int offset = 0;
  144599. int numToRead = samplesInReservoir;
  144600. while (numToRead > 0)
  144601. {
  144602. float** dataIn = 0;
  144603. const int samps = ov_read_float (&ovFile, &dataIn, numToRead, &bitStream);
  144604. if (samps <= 0)
  144605. break;
  144606. jassert (samps <= numToRead);
  144607. for (int i = jmin ((int) numChannels, reservoir.getNumChannels()); --i >= 0;)
  144608. {
  144609. memcpy (reservoir.getSampleData (i, offset),
  144610. dataIn[i],
  144611. sizeof (float) * samps);
  144612. }
  144613. numToRead -= samps;
  144614. offset += samps;
  144615. }
  144616. if (numToRead > 0)
  144617. reservoir.clear (offset, numToRead);
  144618. }
  144619. }
  144620. if (numSamples > 0)
  144621. {
  144622. for (int i = numDestChannels; --i >= 0;)
  144623. if (destSamples[i] != 0)
  144624. zeromem (destSamples[i] + startOffsetInDestBuffer,
  144625. sizeof (int) * numSamples);
  144626. }
  144627. return true;
  144628. }
  144629. static size_t oggReadCallback (void* ptr, size_t size, size_t nmemb, void* datasource)
  144630. {
  144631. return (size_t) (((InputStream*) datasource)->read (ptr, (int) (size * nmemb)) / size);
  144632. }
  144633. static int oggSeekCallback (void* datasource, ogg_int64_t offset, int whence)
  144634. {
  144635. InputStream* const in = (InputStream*) datasource;
  144636. if (whence == SEEK_CUR)
  144637. offset += in->getPosition();
  144638. else if (whence == SEEK_END)
  144639. offset += in->getTotalLength();
  144640. in->setPosition (offset);
  144641. return 0;
  144642. }
  144643. static int oggCloseCallback (void*)
  144644. {
  144645. return 0;
  144646. }
  144647. static long oggTellCallback (void* datasource)
  144648. {
  144649. return (long) ((InputStream*) datasource)->getPosition();
  144650. }
  144651. juce_UseDebuggingNewOperator
  144652. };
  144653. class OggWriter : public AudioFormatWriter
  144654. {
  144655. ogg_stream_state os;
  144656. ogg_page og;
  144657. ogg_packet op;
  144658. vorbis_info vi;
  144659. vorbis_comment vc;
  144660. vorbis_dsp_state vd;
  144661. vorbis_block vb;
  144662. public:
  144663. bool ok;
  144664. OggWriter (OutputStream* const out,
  144665. const double sampleRate,
  144666. const int numChannels,
  144667. const int bitsPerSample,
  144668. const int qualityIndex)
  144669. : AudioFormatWriter (out, TRANS (oggFormatName),
  144670. sampleRate,
  144671. numChannels,
  144672. bitsPerSample)
  144673. {
  144674. ok = false;
  144675. vorbis_info_init (&vi);
  144676. if (vorbis_encode_init_vbr (&vi,
  144677. numChannels,
  144678. (int) sampleRate,
  144679. jlimit (0.0f, 1.0f, qualityIndex * 0.5f)) == 0)
  144680. {
  144681. vorbis_comment_init (&vc);
  144682. if (JUCEApplication::getInstance() != 0)
  144683. vorbis_comment_add_tag (&vc, "ENCODER", const_cast <char*> (JUCEApplication::getInstance()->getApplicationName().toUTF8()));
  144684. vorbis_analysis_init (&vd, &vi);
  144685. vorbis_block_init (&vd, &vb);
  144686. ogg_stream_init (&os, Random::getSystemRandom().nextInt());
  144687. ogg_packet header;
  144688. ogg_packet header_comm;
  144689. ogg_packet header_code;
  144690. vorbis_analysis_headerout (&vd, &vc, &header, &header_comm, &header_code);
  144691. ogg_stream_packetin (&os, &header);
  144692. ogg_stream_packetin (&os, &header_comm);
  144693. ogg_stream_packetin (&os, &header_code);
  144694. for (;;)
  144695. {
  144696. if (ogg_stream_flush (&os, &og) == 0)
  144697. break;
  144698. output->write (og.header, og.header_len);
  144699. output->write (og.body, og.body_len);
  144700. }
  144701. ok = true;
  144702. }
  144703. }
  144704. ~OggWriter()
  144705. {
  144706. if (ok)
  144707. {
  144708. // write a zero-length packet to show ogg that we're finished..
  144709. write (0, 0);
  144710. ogg_stream_clear (&os);
  144711. vorbis_block_clear (&vb);
  144712. vorbis_dsp_clear (&vd);
  144713. vorbis_comment_clear (&vc);
  144714. vorbis_info_clear (&vi);
  144715. output->flush();
  144716. }
  144717. else
  144718. {
  144719. vorbis_info_clear (&vi);
  144720. output = 0; // to stop the base class deleting this, as it needs to be returned
  144721. // to the caller of createWriter()
  144722. }
  144723. }
  144724. bool write (const int** samplesToWrite, int numSamples)
  144725. {
  144726. if (! ok)
  144727. return false;
  144728. if (numSamples > 0)
  144729. {
  144730. const double gain = 1.0 / 0x80000000u;
  144731. float** const vorbisBuffer = vorbis_analysis_buffer (&vd, numSamples);
  144732. for (int i = numChannels; --i >= 0;)
  144733. {
  144734. float* const dst = vorbisBuffer[i];
  144735. const int* const src = samplesToWrite [i];
  144736. if (src != 0 && dst != 0)
  144737. {
  144738. for (int j = 0; j < numSamples; ++j)
  144739. dst[j] = (float) (src[j] * gain);
  144740. }
  144741. }
  144742. }
  144743. vorbis_analysis_wrote (&vd, numSamples);
  144744. while (vorbis_analysis_blockout (&vd, &vb) == 1)
  144745. {
  144746. vorbis_analysis (&vb, 0);
  144747. vorbis_bitrate_addblock (&vb);
  144748. while (vorbis_bitrate_flushpacket (&vd, &op))
  144749. {
  144750. ogg_stream_packetin (&os, &op);
  144751. for (;;)
  144752. {
  144753. if (ogg_stream_pageout (&os, &og) == 0)
  144754. break;
  144755. output->write (og.header, og.header_len);
  144756. output->write (og.body, og.body_len);
  144757. if (ogg_page_eos (&og))
  144758. break;
  144759. }
  144760. }
  144761. }
  144762. return true;
  144763. }
  144764. juce_UseDebuggingNewOperator
  144765. };
  144766. OggVorbisAudioFormat::OggVorbisAudioFormat()
  144767. : AudioFormat (TRANS (oggFormatName), (const tchar**) oggExtensions)
  144768. {
  144769. }
  144770. OggVorbisAudioFormat::~OggVorbisAudioFormat()
  144771. {
  144772. }
  144773. const Array <int> OggVorbisAudioFormat::getPossibleSampleRates()
  144774. {
  144775. const int rates[] = { 22050, 32000, 44100, 48000, 0 };
  144776. return Array <int> (rates);
  144777. }
  144778. const Array <int> OggVorbisAudioFormat::getPossibleBitDepths()
  144779. {
  144780. Array <int> depths;
  144781. depths.add (32);
  144782. return depths;
  144783. }
  144784. bool OggVorbisAudioFormat::canDoStereo()
  144785. {
  144786. return true;
  144787. }
  144788. bool OggVorbisAudioFormat::canDoMono()
  144789. {
  144790. return true;
  144791. }
  144792. AudioFormatReader* OggVorbisAudioFormat::createReaderFor (InputStream* in,
  144793. const bool deleteStreamIfOpeningFails)
  144794. {
  144795. ScopedPointer <OggReader> r (new OggReader (in));
  144796. if (r->sampleRate != 0)
  144797. return r.release();
  144798. if (! deleteStreamIfOpeningFails)
  144799. r->input = 0;
  144800. return 0;
  144801. }
  144802. AudioFormatWriter* OggVorbisAudioFormat::createWriterFor (OutputStream* out,
  144803. double sampleRate,
  144804. unsigned int numChannels,
  144805. int bitsPerSample,
  144806. const StringPairArray& /*metadataValues*/,
  144807. int qualityOptionIndex)
  144808. {
  144809. ScopedPointer <OggWriter> w (new OggWriter (out,
  144810. sampleRate,
  144811. numChannels,
  144812. bitsPerSample,
  144813. qualityOptionIndex));
  144814. return w->ok ? w.release() : 0;
  144815. }
  144816. bool OggVorbisAudioFormat::isCompressed()
  144817. {
  144818. return true;
  144819. }
  144820. const StringArray OggVorbisAudioFormat::getQualityOptions()
  144821. {
  144822. StringArray s;
  144823. s.add ("Low Quality");
  144824. s.add ("Medium Quality");
  144825. s.add ("High Quality");
  144826. return s;
  144827. }
  144828. int OggVorbisAudioFormat::estimateOggFileQuality (const File& source)
  144829. {
  144830. FileInputStream* const in = source.createInputStream();
  144831. if (in != 0)
  144832. {
  144833. ScopedPointer <AudioFormatReader> r (createReaderFor (in, true));
  144834. if (r != 0)
  144835. {
  144836. const int64 numSamps = r->lengthInSamples;
  144837. r = 0;
  144838. const int64 fileNumSamps = source.getSize() / 4;
  144839. const double ratio = numSamps / (double) fileNumSamps;
  144840. if (ratio > 12.0)
  144841. return 0;
  144842. else if (ratio > 6.0)
  144843. return 1;
  144844. else
  144845. return 2;
  144846. }
  144847. }
  144848. return 1;
  144849. }
  144850. END_JUCE_NAMESPACE
  144851. #endif
  144852. /*** End of inlined file: juce_OggVorbisAudioFormat.cpp ***/
  144853. #endif
  144854. #if JUCE_BUILD_CORE && ! JUCE_ONLY_BUILD_CORE_LIBRARY // do these in the core section to help balance the sizes
  144855. /*** Start of inlined file: juce_JPEGLoader.cpp ***/
  144856. #if JUCE_MSVC
  144857. #pragma warning (push)
  144858. #endif
  144859. namespace jpeglibNamespace
  144860. {
  144861. #if JUCE_INCLUDE_JPEGLIB_CODE
  144862. #if JUCE_MINGW
  144863. typedef unsigned char boolean;
  144864. #endif
  144865. extern "C"
  144866. {
  144867. #define JPEG_INTERNALS
  144868. #undef FAR
  144869. /*** Start of inlined file: jpeglib.h ***/
  144870. #ifndef JPEGLIB_H
  144871. #define JPEGLIB_H
  144872. #ifndef JCONFIG_INCLUDED /* in case jinclude.h already did */
  144873. /*** Start of inlined file: jconfig.h ***/
  144874. // disable all the warnings under MSVC
  144875. #ifdef _MSC_VER
  144876. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  144877. #endif
  144878. #ifdef __BORLANDC__
  144879. #pragma warn -8057
  144880. #pragma warn -8019
  144881. #pragma warn -8004
  144882. #pragma warn -8008
  144883. #endif
  144884. #define HAVE_PROTOTYPES
  144885. #define HAVE_UNSIGNED_CHAR
  144886. #define HAVE_UNSIGNED_SHORT
  144887. #undef CHAR_IS_UNSIGNED
  144888. #define HAVE_STDDEF_H
  144889. #define HAVE_STDLIB_H
  144890. #undef NEED_BSD_STRINGS
  144891. #undef NEED_SYS_TYPES_H
  144892. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  144893. #undef NEED_SHORT_EXTERNAL_NAMES
  144894. #undef INCOMPLETE_TYPES_BROKEN
  144895. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  144896. typedef unsigned char boolean;
  144897. #endif
  144898. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  144899. #ifdef JPEG_INTERNALS
  144900. #undef RIGHT_SHIFT_IS_UNSIGNED
  144901. #endif /* JPEG_INTERNALS */
  144902. #ifdef JPEG_CJPEG_DJPEG
  144903. #define BMP_SUPPORTED /* BMP image file format */
  144904. #define GIF_SUPPORTED /* GIF image file format */
  144905. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  144906. #undef RLE_SUPPORTED /* Utah RLE image file format */
  144907. #define TARGA_SUPPORTED /* Targa image file format */
  144908. #define TWO_FILE_COMMANDLINE /* optional */
  144909. #define USE_SETMODE /* Microsoft has setmode() */
  144910. #undef NEED_SIGNAL_CATCHER
  144911. #undef DONT_USE_B_MODE
  144912. #undef PROGRESS_REPORT /* optional */
  144913. #endif /* JPEG_CJPEG_DJPEG */
  144914. /*** End of inlined file: jconfig.h ***/
  144915. /* widely used configuration options */
  144916. #endif
  144917. /*** Start of inlined file: jmorecfg.h ***/
  144918. #define BITS_IN_JSAMPLE 8 /* use 8 or 12 */
  144919. #define MAX_COMPONENTS 10 /* maximum number of image components */
  144920. #if BITS_IN_JSAMPLE == 8
  144921. #ifdef HAVE_UNSIGNED_CHAR
  144922. typedef unsigned char JSAMPLE;
  144923. #define GETJSAMPLE(value) ((int) (value))
  144924. #else /* not HAVE_UNSIGNED_CHAR */
  144925. typedef char JSAMPLE;
  144926. #ifdef CHAR_IS_UNSIGNED
  144927. #define GETJSAMPLE(value) ((int) (value))
  144928. #else
  144929. #define GETJSAMPLE(value) ((int) (value) & 0xFF)
  144930. #endif /* CHAR_IS_UNSIGNED */
  144931. #endif /* HAVE_UNSIGNED_CHAR */
  144932. #define MAXJSAMPLE 255
  144933. #define CENTERJSAMPLE 128
  144934. #endif /* BITS_IN_JSAMPLE == 8 */
  144935. #if BITS_IN_JSAMPLE == 12
  144936. typedef short JSAMPLE;
  144937. #define GETJSAMPLE(value) ((int) (value))
  144938. #define MAXJSAMPLE 4095
  144939. #define CENTERJSAMPLE 2048
  144940. #endif /* BITS_IN_JSAMPLE == 12 */
  144941. typedef short JCOEF;
  144942. #ifdef HAVE_UNSIGNED_CHAR
  144943. typedef unsigned char JOCTET;
  144944. #define GETJOCTET(value) (value)
  144945. #else /* not HAVE_UNSIGNED_CHAR */
  144946. typedef char JOCTET;
  144947. #ifdef CHAR_IS_UNSIGNED
  144948. #define GETJOCTET(value) (value)
  144949. #else
  144950. #define GETJOCTET(value) ((value) & 0xFF)
  144951. #endif /* CHAR_IS_UNSIGNED */
  144952. #endif /* HAVE_UNSIGNED_CHAR */
  144953. #ifdef HAVE_UNSIGNED_CHAR
  144954. typedef unsigned char UINT8;
  144955. #else /* not HAVE_UNSIGNED_CHAR */
  144956. #ifdef CHAR_IS_UNSIGNED
  144957. typedef char UINT8;
  144958. #else /* not CHAR_IS_UNSIGNED */
  144959. typedef short UINT8;
  144960. #endif /* CHAR_IS_UNSIGNED */
  144961. #endif /* HAVE_UNSIGNED_CHAR */
  144962. #ifdef HAVE_UNSIGNED_SHORT
  144963. typedef unsigned short UINT16;
  144964. #else /* not HAVE_UNSIGNED_SHORT */
  144965. typedef unsigned int UINT16;
  144966. #endif /* HAVE_UNSIGNED_SHORT */
  144967. #ifndef XMD_H /* X11/xmd.h correctly defines INT16 */
  144968. typedef short INT16;
  144969. #endif
  144970. #ifndef XMD_H /* X11/xmd.h correctly defines INT32 */
  144971. typedef long INT32;
  144972. #endif
  144973. typedef unsigned int JDIMENSION;
  144974. #define JPEG_MAX_DIMENSION 65500L /* a tad under 64K to prevent overflows */
  144975. #define METHODDEF(type) static type
  144976. #define LOCAL(type) static type
  144977. #define GLOBAL(type) type
  144978. #define EXTERN(type) extern type
  144979. #ifdef HAVE_PROTOTYPES
  144980. #define JMETHOD(type,methodname,arglist) type (*methodname) arglist
  144981. #else
  144982. #define JMETHOD(type,methodname,arglist) type (*methodname) ()
  144983. #endif
  144984. #ifdef NEED_FAR_POINTERS
  144985. #define FAR far
  144986. #else
  144987. #define FAR
  144988. #endif
  144989. #ifndef HAVE_BOOLEAN
  144990. typedef int boolean;
  144991. #endif
  144992. #ifndef FALSE /* in case these macros already exist */
  144993. #define FALSE 0 /* values of boolean */
  144994. #endif
  144995. #ifndef TRUE
  144996. #define TRUE 1
  144997. #endif
  144998. #ifdef JPEG_INTERNALS
  144999. #define JPEG_INTERNAL_OPTIONS
  145000. #endif
  145001. #ifdef JPEG_INTERNAL_OPTIONS
  145002. #define DCT_ISLOW_SUPPORTED /* slow but accurate integer algorithm */
  145003. #define DCT_IFAST_SUPPORTED /* faster, less accurate integer method */
  145004. #define DCT_FLOAT_SUPPORTED /* floating-point: accurate, fast on fast HW */
  145005. #undef C_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  145006. #define C_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  145007. #define C_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  145008. #define ENTROPY_OPT_SUPPORTED /* Optimization of entropy coding parms? */
  145009. #define INPUT_SMOOTHING_SUPPORTED /* Input image smoothing option? */
  145010. #undef D_ARITH_CODING_SUPPORTED /* Arithmetic coding back end? */
  145011. #define D_MULTISCAN_FILES_SUPPORTED /* Multiple-scan JPEG files? */
  145012. #define D_PROGRESSIVE_SUPPORTED /* Progressive JPEG? (Requires MULTISCAN)*/
  145013. #define SAVE_MARKERS_SUPPORTED /* jpeg_save_markers() needed? */
  145014. #define BLOCK_SMOOTHING_SUPPORTED /* Block smoothing? (Progressive only) */
  145015. #define IDCT_SCALING_SUPPORTED /* Output rescaling via IDCT? */
  145016. #undef UPSAMPLE_SCALING_SUPPORTED /* Output rescaling at upsample stage? */
  145017. #define UPSAMPLE_MERGING_SUPPORTED /* Fast path for sloppy upsampling? */
  145018. #define QUANT_1PASS_SUPPORTED /* 1-pass color quantization? */
  145019. #define QUANT_2PASS_SUPPORTED /* 2-pass color quantization? */
  145020. #define RGB_RED 0 /* Offset of Red in an RGB scanline element */
  145021. #define RGB_GREEN 1 /* Offset of Green */
  145022. #define RGB_BLUE 2 /* Offset of Blue */
  145023. #define RGB_PIXELSIZE 3 /* JSAMPLEs per RGB scanline element */
  145024. #ifndef INLINE
  145025. #ifdef __GNUC__ /* for instance, GNU C knows about inline */
  145026. #define INLINE __inline__
  145027. #endif
  145028. #ifndef INLINE
  145029. #define INLINE /* default is to define it as empty */
  145030. #endif
  145031. #endif
  145032. #ifndef MULTIPLIER
  145033. #define MULTIPLIER int /* type for fastest integer multiply */
  145034. #endif
  145035. #ifndef FAST_FLOAT
  145036. #ifdef HAVE_PROTOTYPES
  145037. #define FAST_FLOAT float
  145038. #else
  145039. #define FAST_FLOAT double
  145040. #endif
  145041. #endif
  145042. #endif /* JPEG_INTERNAL_OPTIONS */
  145043. /*** End of inlined file: jmorecfg.h ***/
  145044. /* seldom changed options */
  145045. #define JPEG_LIB_VERSION 62 /* Version 6b */
  145046. #define DCTSIZE 8 /* The basic DCT block is 8x8 samples */
  145047. #define DCTSIZE2 64 /* DCTSIZE squared; # of elements in a block */
  145048. #define NUM_QUANT_TBLS 4 /* Quantization tables are numbered 0..3 */
  145049. #define NUM_HUFF_TBLS 4 /* Huffman tables are numbered 0..3 */
  145050. #define NUM_ARITH_TBLS 16 /* Arith-coding tables are numbered 0..15 */
  145051. #define MAX_COMPS_IN_SCAN 4 /* JPEG limit on # of components in one scan */
  145052. #define MAX_SAMP_FACTOR 4 /* JPEG limit on sampling factors */
  145053. #define C_MAX_BLOCKS_IN_MCU 10 /* compressor's limit on blocks per MCU */
  145054. #ifndef D_MAX_BLOCKS_IN_MCU
  145055. #define D_MAX_BLOCKS_IN_MCU 10 /* decompressor's limit on blocks per MCU */
  145056. #endif
  145057. typedef JSAMPLE FAR *JSAMPROW; /* ptr to one image row of pixel samples. */
  145058. typedef JSAMPROW *JSAMPARRAY; /* ptr to some rows (a 2-D sample array) */
  145059. typedef JSAMPARRAY *JSAMPIMAGE; /* a 3-D sample array: top index is color */
  145060. typedef JCOEF JBLOCK[DCTSIZE2]; /* one block of coefficients */
  145061. typedef JBLOCK FAR *JBLOCKROW; /* pointer to one row of coefficient blocks */
  145062. typedef JBLOCKROW *JBLOCKARRAY; /* a 2-D array of coefficient blocks */
  145063. typedef JBLOCKARRAY *JBLOCKIMAGE; /* a 3-D array of coefficient blocks */
  145064. typedef JCOEF FAR *JCOEFPTR; /* useful in a couple of places */
  145065. typedef struct {
  145066. UINT16 quantval[DCTSIZE2]; /* quantization step for each coefficient */
  145067. boolean sent_table; /* TRUE when table has been output */
  145068. } JQUANT_TBL;
  145069. typedef struct {
  145070. UINT8 bits[17]; /* bits[k] = # of symbols with codes of */
  145071. UINT8 huffval[256]; /* The symbols, in order of incr code length */
  145072. boolean sent_table; /* TRUE when table has been output */
  145073. } JHUFF_TBL;
  145074. typedef struct {
  145075. int component_id; /* identifier for this component (0..255) */
  145076. int component_index; /* its index in SOF or cinfo->comp_info[] */
  145077. int h_samp_factor; /* horizontal sampling factor (1..4) */
  145078. int v_samp_factor; /* vertical sampling factor (1..4) */
  145079. int quant_tbl_no; /* quantization table selector (0..3) */
  145080. int dc_tbl_no; /* DC entropy table selector (0..3) */
  145081. int ac_tbl_no; /* AC entropy table selector (0..3) */
  145082. JDIMENSION width_in_blocks;
  145083. JDIMENSION height_in_blocks;
  145084. int DCT_scaled_size;
  145085. JDIMENSION downsampled_width; /* actual width in samples */
  145086. JDIMENSION downsampled_height; /* actual height in samples */
  145087. boolean component_needed; /* do we need the value of this component? */
  145088. int MCU_width; /* number of blocks per MCU, horizontally */
  145089. int MCU_height; /* number of blocks per MCU, vertically */
  145090. int MCU_blocks; /* MCU_width * MCU_height */
  145091. int MCU_sample_width; /* MCU width in samples, MCU_width*DCT_scaled_size */
  145092. int last_col_width; /* # of non-dummy blocks across in last MCU */
  145093. int last_row_height; /* # of non-dummy blocks down in last MCU */
  145094. JQUANT_TBL * quant_table;
  145095. void * dct_table;
  145096. } jpeg_component_info;
  145097. typedef struct {
  145098. int comps_in_scan; /* number of components encoded in this scan */
  145099. int component_index[MAX_COMPS_IN_SCAN]; /* their SOF/comp_info[] indexes */
  145100. int Ss, Se; /* progressive JPEG spectral selection parms */
  145101. int Ah, Al; /* progressive JPEG successive approx. parms */
  145102. } jpeg_scan_info;
  145103. typedef struct jpeg_marker_struct FAR * jpeg_saved_marker_ptr;
  145104. struct jpeg_marker_struct {
  145105. jpeg_saved_marker_ptr next; /* next in list, or NULL */
  145106. UINT8 marker; /* marker code: JPEG_COM, or JPEG_APP0+n */
  145107. unsigned int original_length; /* # bytes of data in the file */
  145108. unsigned int data_length; /* # bytes of data saved at data[] */
  145109. JOCTET FAR * data; /* the data contained in the marker */
  145110. };
  145111. typedef enum {
  145112. JCS_UNKNOWN, /* error/unspecified */
  145113. JCS_GRAYSCALE, /* monochrome */
  145114. JCS_RGB, /* red/green/blue */
  145115. JCS_YCbCr, /* Y/Cb/Cr (also known as YUV) */
  145116. JCS_CMYK, /* C/M/Y/K */
  145117. JCS_YCCK /* Y/Cb/Cr/K */
  145118. } J_COLOR_SPACE;
  145119. typedef enum {
  145120. JDCT_ISLOW, /* slow but accurate integer algorithm */
  145121. JDCT_IFAST, /* faster, less accurate integer method */
  145122. JDCT_FLOAT /* floating-point: accurate, fast on fast HW */
  145123. } J_DCT_METHOD;
  145124. #ifndef JDCT_DEFAULT /* may be overridden in jconfig.h */
  145125. #define JDCT_DEFAULT JDCT_ISLOW
  145126. #endif
  145127. #ifndef JDCT_FASTEST /* may be overridden in jconfig.h */
  145128. #define JDCT_FASTEST JDCT_IFAST
  145129. #endif
  145130. typedef enum {
  145131. JDITHER_NONE, /* no dithering */
  145132. JDITHER_ORDERED, /* simple ordered dither */
  145133. JDITHER_FS /* Floyd-Steinberg error diffusion dither */
  145134. } J_DITHER_MODE;
  145135. #define jpeg_common_fields \
  145136. struct jpeg_error_mgr * err; /* Error handler module */\
  145137. struct jpeg_memory_mgr * mem; /* Memory manager module */\
  145138. struct jpeg_progress_mgr * progress; /* Progress monitor, or NULL if none */\
  145139. void * client_data; /* Available for use by application */\
  145140. boolean is_decompressor; /* So common code can tell which is which */\
  145141. int global_state /* For checking call sequence validity */
  145142. struct jpeg_common_struct {
  145143. jpeg_common_fields; /* Fields common to both master struct types */
  145144. };
  145145. typedef struct jpeg_common_struct * j_common_ptr;
  145146. typedef struct jpeg_compress_struct * j_compress_ptr;
  145147. typedef struct jpeg_decompress_struct * j_decompress_ptr;
  145148. struct jpeg_compress_struct {
  145149. jpeg_common_fields; /* Fields shared with jpeg_decompress_struct */
  145150. struct jpeg_destination_mgr * dest;
  145151. JDIMENSION image_width; /* input image width */
  145152. JDIMENSION image_height; /* input image height */
  145153. int input_components; /* # of color components in input image */
  145154. J_COLOR_SPACE in_color_space; /* colorspace of input image */
  145155. double input_gamma; /* image gamma of input image */
  145156. int data_precision; /* bits of precision in image data */
  145157. int num_components; /* # of color components in JPEG image */
  145158. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  145159. jpeg_component_info * comp_info;
  145160. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  145161. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145162. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145163. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  145164. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  145165. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  145166. int num_scans; /* # of entries in scan_info array */
  145167. const jpeg_scan_info * scan_info; /* script for multi-scan file, or NULL */
  145168. boolean raw_data_in; /* TRUE=caller supplies downsampled data */
  145169. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  145170. boolean optimize_coding; /* TRUE=optimize entropy encoding parms */
  145171. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  145172. int smoothing_factor; /* 1..100, or 0 for no input smoothing */
  145173. J_DCT_METHOD dct_method; /* DCT algorithm selector */
  145174. unsigned int restart_interval; /* MCUs per restart, or 0 for no restart */
  145175. int restart_in_rows; /* if > 0, MCU rows per restart interval */
  145176. boolean write_JFIF_header; /* should a JFIF marker be written? */
  145177. UINT8 JFIF_major_version; /* What to write for the JFIF version number */
  145178. UINT8 JFIF_minor_version;
  145179. UINT8 density_unit; /* JFIF code for pixel size units */
  145180. UINT16 X_density; /* Horizontal pixel density */
  145181. UINT16 Y_density; /* Vertical pixel density */
  145182. boolean write_Adobe_marker; /* should an Adobe marker be written? */
  145183. JDIMENSION next_scanline; /* 0 .. image_height-1 */
  145184. boolean progressive_mode; /* TRUE if scan script uses progressive mode */
  145185. int max_h_samp_factor; /* largest h_samp_factor */
  145186. int max_v_samp_factor; /* largest v_samp_factor */
  145187. JDIMENSION total_iMCU_rows; /* # of iMCU rows to be input to coef ctlr */
  145188. int comps_in_scan; /* # of JPEG components in this scan */
  145189. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  145190. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  145191. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  145192. int blocks_in_MCU; /* # of DCT blocks per MCU */
  145193. int MCU_membership[C_MAX_BLOCKS_IN_MCU];
  145194. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  145195. struct jpeg_comp_master * master;
  145196. struct jpeg_c_main_controller * main;
  145197. struct jpeg_c_prep_controller * prep;
  145198. struct jpeg_c_coef_controller * coef;
  145199. struct jpeg_marker_writer * marker;
  145200. struct jpeg_color_converter * cconvert;
  145201. struct jpeg_downsampler * downsample;
  145202. struct jpeg_forward_dct * fdct;
  145203. struct jpeg_entropy_encoder * entropy;
  145204. jpeg_scan_info * script_space; /* workspace for jpeg_simple_progression */
  145205. int script_space_size;
  145206. };
  145207. struct jpeg_decompress_struct {
  145208. jpeg_common_fields; /* Fields shared with jpeg_compress_struct */
  145209. struct jpeg_source_mgr * src;
  145210. JDIMENSION image_width; /* nominal image width (from SOF marker) */
  145211. JDIMENSION image_height; /* nominal image height */
  145212. int num_components; /* # of color components in JPEG image */
  145213. J_COLOR_SPACE jpeg_color_space; /* colorspace of JPEG image */
  145214. J_COLOR_SPACE out_color_space; /* colorspace for output */
  145215. unsigned int scale_num, scale_denom; /* fraction by which to scale image */
  145216. double output_gamma; /* image gamma wanted in output */
  145217. boolean buffered_image; /* TRUE=multiple output passes */
  145218. boolean raw_data_out; /* TRUE=downsampled data wanted */
  145219. J_DCT_METHOD dct_method; /* IDCT algorithm selector */
  145220. boolean do_fancy_upsampling; /* TRUE=apply fancy upsampling */
  145221. boolean do_block_smoothing; /* TRUE=apply interblock smoothing */
  145222. boolean quantize_colors; /* TRUE=colormapped output wanted */
  145223. J_DITHER_MODE dither_mode; /* type of color dithering to use */
  145224. boolean two_pass_quantize; /* TRUE=use two-pass color quantization */
  145225. int desired_number_of_colors; /* max # colors to use in created colormap */
  145226. boolean enable_1pass_quant; /* enable future use of 1-pass quantizer */
  145227. boolean enable_external_quant;/* enable future use of external colormap */
  145228. boolean enable_2pass_quant; /* enable future use of 2-pass quantizer */
  145229. JDIMENSION output_width; /* scaled image width */
  145230. JDIMENSION output_height; /* scaled image height */
  145231. int out_color_components; /* # of color components in out_color_space */
  145232. int output_components; /* # of color components returned */
  145233. int rec_outbuf_height; /* min recommended height of scanline buffer */
  145234. int actual_number_of_colors; /* number of entries in use */
  145235. JSAMPARRAY colormap; /* The color map as a 2-D pixel array */
  145236. JDIMENSION output_scanline; /* 0 .. output_height-1 */
  145237. int input_scan_number; /* Number of SOS markers seen so far */
  145238. JDIMENSION input_iMCU_row; /* Number of iMCU rows completed */
  145239. int output_scan_number; /* Nominal scan number being displayed */
  145240. JDIMENSION output_iMCU_row; /* Number of iMCU rows read */
  145241. int (*coef_bits)[DCTSIZE2]; /* -1 or current Al value for each coef */
  145242. JQUANT_TBL * quant_tbl_ptrs[NUM_QUANT_TBLS];
  145243. JHUFF_TBL * dc_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145244. JHUFF_TBL * ac_huff_tbl_ptrs[NUM_HUFF_TBLS];
  145245. int data_precision; /* bits of precision in image data */
  145246. jpeg_component_info * comp_info;
  145247. boolean progressive_mode; /* TRUE if SOFn specifies progressive mode */
  145248. boolean arith_code; /* TRUE=arithmetic coding, FALSE=Huffman */
  145249. UINT8 arith_dc_L[NUM_ARITH_TBLS]; /* L values for DC arith-coding tables */
  145250. UINT8 arith_dc_U[NUM_ARITH_TBLS]; /* U values for DC arith-coding tables */
  145251. UINT8 arith_ac_K[NUM_ARITH_TBLS]; /* Kx values for AC arith-coding tables */
  145252. unsigned int restart_interval; /* MCUs per restart interval, or 0 for no restart */
  145253. boolean saw_JFIF_marker; /* TRUE iff a JFIF APP0 marker was found */
  145254. UINT8 JFIF_major_version; /* JFIF version number */
  145255. UINT8 JFIF_minor_version;
  145256. UINT8 density_unit; /* JFIF code for pixel size units */
  145257. UINT16 X_density; /* Horizontal pixel density */
  145258. UINT16 Y_density; /* Vertical pixel density */
  145259. boolean saw_Adobe_marker; /* TRUE iff an Adobe APP14 marker was found */
  145260. UINT8 Adobe_transform; /* Color transform code from Adobe marker */
  145261. boolean CCIR601_sampling; /* TRUE=first samples are cosited */
  145262. jpeg_saved_marker_ptr marker_list; /* Head of list of saved markers */
  145263. int max_h_samp_factor; /* largest h_samp_factor */
  145264. int max_v_samp_factor; /* largest v_samp_factor */
  145265. int min_DCT_scaled_size; /* smallest DCT_scaled_size of any component */
  145266. JDIMENSION total_iMCU_rows; /* # of iMCU rows in image */
  145267. JSAMPLE * sample_range_limit; /* table for fast range-limiting */
  145268. int comps_in_scan; /* # of JPEG components in this scan */
  145269. jpeg_component_info * cur_comp_info[MAX_COMPS_IN_SCAN];
  145270. JDIMENSION MCUs_per_row; /* # of MCUs across the image */
  145271. JDIMENSION MCU_rows_in_scan; /* # of MCU rows in the image */
  145272. int blocks_in_MCU; /* # of DCT blocks per MCU */
  145273. int MCU_membership[D_MAX_BLOCKS_IN_MCU];
  145274. int Ss, Se, Ah, Al; /* progressive JPEG parameters for scan */
  145275. int unread_marker;
  145276. struct jpeg_decomp_master * master;
  145277. struct jpeg_d_main_controller * main;
  145278. struct jpeg_d_coef_controller * coef;
  145279. struct jpeg_d_post_controller * post;
  145280. struct jpeg_input_controller * inputctl;
  145281. struct jpeg_marker_reader * marker;
  145282. struct jpeg_entropy_decoder * entropy;
  145283. struct jpeg_inverse_dct * idct;
  145284. struct jpeg_upsampler * upsample;
  145285. struct jpeg_color_deconverter * cconvert;
  145286. struct jpeg_color_quantizer * cquantize;
  145287. };
  145288. struct jpeg_error_mgr {
  145289. JMETHOD(void, error_exit, (j_common_ptr cinfo));
  145290. JMETHOD(void, emit_message, (j_common_ptr cinfo, int msg_level));
  145291. JMETHOD(void, output_message, (j_common_ptr cinfo));
  145292. JMETHOD(void, format_message, (j_common_ptr cinfo, char * buffer));
  145293. #define JMSG_LENGTH_MAX 200 /* recommended size of format_message buffer */
  145294. JMETHOD(void, reset_error_mgr, (j_common_ptr cinfo));
  145295. int msg_code;
  145296. #define JMSG_STR_PARM_MAX 80
  145297. union {
  145298. int i[8];
  145299. char s[JMSG_STR_PARM_MAX];
  145300. } msg_parm;
  145301. int trace_level; /* max msg_level that will be displayed */
  145302. long num_warnings; /* number of corrupt-data warnings */
  145303. const char * const * jpeg_message_table; /* Library errors */
  145304. int last_jpeg_message; /* Table contains strings 0..last_jpeg_message */
  145305. const char * const * addon_message_table; /* Non-library errors */
  145306. int first_addon_message; /* code for first string in addon table */
  145307. int last_addon_message; /* code for last string in addon table */
  145308. };
  145309. struct jpeg_progress_mgr {
  145310. JMETHOD(void, progress_monitor, (j_common_ptr cinfo));
  145311. long pass_counter; /* work units completed in this pass */
  145312. long pass_limit; /* total number of work units in this pass */
  145313. int completed_passes; /* passes completed so far */
  145314. int total_passes; /* total number of passes expected */
  145315. };
  145316. struct jpeg_destination_mgr {
  145317. JOCTET * next_output_byte; /* => next byte to write in buffer */
  145318. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  145319. JMETHOD(void, init_destination, (j_compress_ptr cinfo));
  145320. JMETHOD(boolean, empty_output_buffer, (j_compress_ptr cinfo));
  145321. JMETHOD(void, term_destination, (j_compress_ptr cinfo));
  145322. };
  145323. struct jpeg_source_mgr {
  145324. const JOCTET * next_input_byte; /* => next byte to read from buffer */
  145325. size_t bytes_in_buffer; /* # of bytes remaining in buffer */
  145326. JMETHOD(void, init_source, (j_decompress_ptr cinfo));
  145327. JMETHOD(boolean, fill_input_buffer, (j_decompress_ptr cinfo));
  145328. JMETHOD(void, skip_input_data, (j_decompress_ptr cinfo, long num_bytes));
  145329. JMETHOD(boolean, resync_to_restart, (j_decompress_ptr cinfo, int desired));
  145330. JMETHOD(void, term_source, (j_decompress_ptr cinfo));
  145331. };
  145332. #define JPOOL_PERMANENT 0 /* lasts until master record is destroyed */
  145333. #define JPOOL_IMAGE 1 /* lasts until done with image/datastream */
  145334. #define JPOOL_NUMPOOLS 2
  145335. typedef struct jvirt_sarray_control * jvirt_sarray_ptr;
  145336. typedef struct jvirt_barray_control * jvirt_barray_ptr;
  145337. struct jpeg_memory_mgr {
  145338. JMETHOD(void *, alloc_small, (j_common_ptr cinfo, int pool_id,
  145339. size_t sizeofobject));
  145340. JMETHOD(void FAR *, alloc_large, (j_common_ptr cinfo, int pool_id,
  145341. size_t sizeofobject));
  145342. JMETHOD(JSAMPARRAY, alloc_sarray, (j_common_ptr cinfo, int pool_id,
  145343. JDIMENSION samplesperrow,
  145344. JDIMENSION numrows));
  145345. JMETHOD(JBLOCKARRAY, alloc_barray, (j_common_ptr cinfo, int pool_id,
  145346. JDIMENSION blocksperrow,
  145347. JDIMENSION numrows));
  145348. JMETHOD(jvirt_sarray_ptr, request_virt_sarray, (j_common_ptr cinfo,
  145349. int pool_id,
  145350. boolean pre_zero,
  145351. JDIMENSION samplesperrow,
  145352. JDIMENSION numrows,
  145353. JDIMENSION maxaccess));
  145354. JMETHOD(jvirt_barray_ptr, request_virt_barray, (j_common_ptr cinfo,
  145355. int pool_id,
  145356. boolean pre_zero,
  145357. JDIMENSION blocksperrow,
  145358. JDIMENSION numrows,
  145359. JDIMENSION maxaccess));
  145360. JMETHOD(void, realize_virt_arrays, (j_common_ptr cinfo));
  145361. JMETHOD(JSAMPARRAY, access_virt_sarray, (j_common_ptr cinfo,
  145362. jvirt_sarray_ptr ptr,
  145363. JDIMENSION start_row,
  145364. JDIMENSION num_rows,
  145365. boolean writable));
  145366. JMETHOD(JBLOCKARRAY, access_virt_barray, (j_common_ptr cinfo,
  145367. jvirt_barray_ptr ptr,
  145368. JDIMENSION start_row,
  145369. JDIMENSION num_rows,
  145370. boolean writable));
  145371. JMETHOD(void, free_pool, (j_common_ptr cinfo, int pool_id));
  145372. JMETHOD(void, self_destruct, (j_common_ptr cinfo));
  145373. long max_memory_to_use;
  145374. long max_alloc_chunk;
  145375. };
  145376. typedef JMETHOD(boolean, jpeg_marker_parser_method, (j_decompress_ptr cinfo));
  145377. #ifdef HAVE_PROTOTYPES
  145378. #define JPP(arglist) arglist
  145379. #else
  145380. #define JPP(arglist) ()
  145381. #endif
  145382. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145383. #define jpeg_std_error jStdError
  145384. #define jpeg_CreateCompress jCreaCompress
  145385. #define jpeg_CreateDecompress jCreaDecompress
  145386. #define jpeg_destroy_compress jDestCompress
  145387. #define jpeg_destroy_decompress jDestDecompress
  145388. #define jpeg_stdio_dest jStdDest
  145389. #define jpeg_stdio_src jStdSrc
  145390. #define jpeg_set_defaults jSetDefaults
  145391. #define jpeg_set_colorspace jSetColorspace
  145392. #define jpeg_default_colorspace jDefColorspace
  145393. #define jpeg_set_quality jSetQuality
  145394. #define jpeg_set_linear_quality jSetLQuality
  145395. #define jpeg_add_quant_table jAddQuantTable
  145396. #define jpeg_quality_scaling jQualityScaling
  145397. #define jpeg_simple_progression jSimProgress
  145398. #define jpeg_suppress_tables jSuppressTables
  145399. #define jpeg_alloc_quant_table jAlcQTable
  145400. #define jpeg_alloc_huff_table jAlcHTable
  145401. #define jpeg_start_compress jStrtCompress
  145402. #define jpeg_write_scanlines jWrtScanlines
  145403. #define jpeg_finish_compress jFinCompress
  145404. #define jpeg_write_raw_data jWrtRawData
  145405. #define jpeg_write_marker jWrtMarker
  145406. #define jpeg_write_m_header jWrtMHeader
  145407. #define jpeg_write_m_byte jWrtMByte
  145408. #define jpeg_write_tables jWrtTables
  145409. #define jpeg_read_header jReadHeader
  145410. #define jpeg_start_decompress jStrtDecompress
  145411. #define jpeg_read_scanlines jReadScanlines
  145412. #define jpeg_finish_decompress jFinDecompress
  145413. #define jpeg_read_raw_data jReadRawData
  145414. #define jpeg_has_multiple_scans jHasMultScn
  145415. #define jpeg_start_output jStrtOutput
  145416. #define jpeg_finish_output jFinOutput
  145417. #define jpeg_input_complete jInComplete
  145418. #define jpeg_new_colormap jNewCMap
  145419. #define jpeg_consume_input jConsumeInput
  145420. #define jpeg_calc_output_dimensions jCalcDimensions
  145421. #define jpeg_save_markers jSaveMarkers
  145422. #define jpeg_set_marker_processor jSetMarker
  145423. #define jpeg_read_coefficients jReadCoefs
  145424. #define jpeg_write_coefficients jWrtCoefs
  145425. #define jpeg_copy_critical_parameters jCopyCrit
  145426. #define jpeg_abort_compress jAbrtCompress
  145427. #define jpeg_abort_decompress jAbrtDecompress
  145428. #define jpeg_abort jAbort
  145429. #define jpeg_destroy jDestroy
  145430. #define jpeg_resync_to_restart jResyncRestart
  145431. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145432. EXTERN(struct jpeg_error_mgr *) jpeg_std_error
  145433. JPP((struct jpeg_error_mgr * err));
  145434. #define jpeg_create_compress(cinfo) \
  145435. jpeg_CreateCompress((cinfo), JPEG_LIB_VERSION, \
  145436. (size_t) sizeof(struct jpeg_compress_struct))
  145437. #define jpeg_create_decompress(cinfo) \
  145438. jpeg_CreateDecompress((cinfo), JPEG_LIB_VERSION, \
  145439. (size_t) sizeof(struct jpeg_decompress_struct))
  145440. EXTERN(void) jpeg_CreateCompress JPP((j_compress_ptr cinfo,
  145441. int version, size_t structsize));
  145442. EXTERN(void) jpeg_CreateDecompress JPP((j_decompress_ptr cinfo,
  145443. int version, size_t structsize));
  145444. EXTERN(void) jpeg_destroy_compress JPP((j_compress_ptr cinfo));
  145445. EXTERN(void) jpeg_destroy_decompress JPP((j_decompress_ptr cinfo));
  145446. EXTERN(void) jpeg_stdio_dest JPP((j_compress_ptr cinfo, FILE * outfile));
  145447. EXTERN(void) jpeg_stdio_src JPP((j_decompress_ptr cinfo, FILE * infile));
  145448. EXTERN(void) jpeg_set_defaults JPP((j_compress_ptr cinfo));
  145449. EXTERN(void) jpeg_set_colorspace JPP((j_compress_ptr cinfo,
  145450. J_COLOR_SPACE colorspace));
  145451. EXTERN(void) jpeg_default_colorspace JPP((j_compress_ptr cinfo));
  145452. EXTERN(void) jpeg_set_quality JPP((j_compress_ptr cinfo, int quality,
  145453. boolean force_baseline));
  145454. EXTERN(void) jpeg_set_linear_quality JPP((j_compress_ptr cinfo,
  145455. int scale_factor,
  145456. boolean force_baseline));
  145457. EXTERN(void) jpeg_add_quant_table JPP((j_compress_ptr cinfo, int which_tbl,
  145458. const unsigned int *basic_table,
  145459. int scale_factor,
  145460. boolean force_baseline));
  145461. EXTERN(int) jpeg_quality_scaling JPP((int quality));
  145462. EXTERN(void) jpeg_simple_progression JPP((j_compress_ptr cinfo));
  145463. EXTERN(void) jpeg_suppress_tables JPP((j_compress_ptr cinfo,
  145464. boolean suppress));
  145465. EXTERN(JQUANT_TBL *) jpeg_alloc_quant_table JPP((j_common_ptr cinfo));
  145466. EXTERN(JHUFF_TBL *) jpeg_alloc_huff_table JPP((j_common_ptr cinfo));
  145467. EXTERN(void) jpeg_start_compress JPP((j_compress_ptr cinfo,
  145468. boolean write_all_tables));
  145469. EXTERN(JDIMENSION) jpeg_write_scanlines JPP((j_compress_ptr cinfo,
  145470. JSAMPARRAY scanlines,
  145471. JDIMENSION num_lines));
  145472. EXTERN(void) jpeg_finish_compress JPP((j_compress_ptr cinfo));
  145473. EXTERN(JDIMENSION) jpeg_write_raw_data JPP((j_compress_ptr cinfo,
  145474. JSAMPIMAGE data,
  145475. JDIMENSION num_lines));
  145476. EXTERN(void) jpeg_write_marker
  145477. JPP((j_compress_ptr cinfo, int marker,
  145478. const JOCTET * dataptr, unsigned int datalen));
  145479. EXTERN(void) jpeg_write_m_header
  145480. JPP((j_compress_ptr cinfo, int marker, unsigned int datalen));
  145481. EXTERN(void) jpeg_write_m_byte
  145482. JPP((j_compress_ptr cinfo, int val));
  145483. EXTERN(void) jpeg_write_tables JPP((j_compress_ptr cinfo));
  145484. EXTERN(int) jpeg_read_header JPP((j_decompress_ptr cinfo,
  145485. boolean require_image));
  145486. #define JPEG_SUSPENDED 0 /* Suspended due to lack of input data */
  145487. #define JPEG_HEADER_OK 1 /* Found valid image datastream */
  145488. #define JPEG_HEADER_TABLES_ONLY 2 /* Found valid table-specs-only datastream */
  145489. EXTERN(boolean) jpeg_start_decompress JPP((j_decompress_ptr cinfo));
  145490. EXTERN(JDIMENSION) jpeg_read_scanlines JPP((j_decompress_ptr cinfo,
  145491. JSAMPARRAY scanlines,
  145492. JDIMENSION max_lines));
  145493. EXTERN(boolean) jpeg_finish_decompress JPP((j_decompress_ptr cinfo));
  145494. EXTERN(JDIMENSION) jpeg_read_raw_data JPP((j_decompress_ptr cinfo,
  145495. JSAMPIMAGE data,
  145496. JDIMENSION max_lines));
  145497. EXTERN(boolean) jpeg_has_multiple_scans JPP((j_decompress_ptr cinfo));
  145498. EXTERN(boolean) jpeg_start_output JPP((j_decompress_ptr cinfo,
  145499. int scan_number));
  145500. EXTERN(boolean) jpeg_finish_output JPP((j_decompress_ptr cinfo));
  145501. EXTERN(boolean) jpeg_input_complete JPP((j_decompress_ptr cinfo));
  145502. EXTERN(void) jpeg_new_colormap JPP((j_decompress_ptr cinfo));
  145503. EXTERN(int) jpeg_consume_input JPP((j_decompress_ptr cinfo));
  145504. #define JPEG_REACHED_SOS 1 /* Reached start of new scan */
  145505. #define JPEG_REACHED_EOI 2 /* Reached end of image */
  145506. #define JPEG_ROW_COMPLETED 3 /* Completed one iMCU row */
  145507. #define JPEG_SCAN_COMPLETED 4 /* Completed last iMCU row of a scan */
  145508. EXTERN(void) jpeg_calc_output_dimensions JPP((j_decompress_ptr cinfo));
  145509. EXTERN(void) jpeg_save_markers
  145510. JPP((j_decompress_ptr cinfo, int marker_code,
  145511. unsigned int length_limit));
  145512. EXTERN(void) jpeg_set_marker_processor
  145513. JPP((j_decompress_ptr cinfo, int marker_code,
  145514. jpeg_marker_parser_method routine));
  145515. EXTERN(jvirt_barray_ptr *) jpeg_read_coefficients JPP((j_decompress_ptr cinfo));
  145516. EXTERN(void) jpeg_write_coefficients JPP((j_compress_ptr cinfo,
  145517. jvirt_barray_ptr * coef_arrays));
  145518. EXTERN(void) jpeg_copy_critical_parameters JPP((j_decompress_ptr srcinfo,
  145519. j_compress_ptr dstinfo));
  145520. EXTERN(void) jpeg_abort_compress JPP((j_compress_ptr cinfo));
  145521. EXTERN(void) jpeg_abort_decompress JPP((j_decompress_ptr cinfo));
  145522. EXTERN(void) jpeg_abort JPP((j_common_ptr cinfo));
  145523. EXTERN(void) jpeg_destroy JPP((j_common_ptr cinfo));
  145524. EXTERN(boolean) jpeg_resync_to_restart JPP((j_decompress_ptr cinfo,
  145525. int desired));
  145526. #define JPEG_RST0 0xD0 /* RST0 marker code */
  145527. #define JPEG_EOI 0xD9 /* EOI marker code */
  145528. #define JPEG_APP0 0xE0 /* APP0 marker code */
  145529. #define JPEG_COM 0xFE /* COM marker code */
  145530. #ifdef INCOMPLETE_TYPES_BROKEN
  145531. #ifndef JPEG_INTERNALS /* will be defined in jpegint.h */
  145532. struct jvirt_sarray_control { long dummy; };
  145533. struct jvirt_barray_control { long dummy; };
  145534. struct jpeg_comp_master { long dummy; };
  145535. struct jpeg_c_main_controller { long dummy; };
  145536. struct jpeg_c_prep_controller { long dummy; };
  145537. struct jpeg_c_coef_controller { long dummy; };
  145538. struct jpeg_marker_writer { long dummy; };
  145539. struct jpeg_color_converter { long dummy; };
  145540. struct jpeg_downsampler { long dummy; };
  145541. struct jpeg_forward_dct { long dummy; };
  145542. struct jpeg_entropy_encoder { long dummy; };
  145543. struct jpeg_decomp_master { long dummy; };
  145544. struct jpeg_d_main_controller { long dummy; };
  145545. struct jpeg_d_coef_controller { long dummy; };
  145546. struct jpeg_d_post_controller { long dummy; };
  145547. struct jpeg_input_controller { long dummy; };
  145548. struct jpeg_marker_reader { long dummy; };
  145549. struct jpeg_entropy_decoder { long dummy; };
  145550. struct jpeg_inverse_dct { long dummy; };
  145551. struct jpeg_upsampler { long dummy; };
  145552. struct jpeg_color_deconverter { long dummy; };
  145553. struct jpeg_color_quantizer { long dummy; };
  145554. #endif /* JPEG_INTERNALS */
  145555. #endif /* INCOMPLETE_TYPES_BROKEN */
  145556. #ifdef JPEG_INTERNALS
  145557. /*** Start of inlined file: jpegint.h ***/
  145558. typedef enum { /* Operating modes for buffer controllers */
  145559. JBUF_PASS_THRU, /* Plain stripwise operation */
  145560. JBUF_SAVE_SOURCE, /* Run source subobject only, save output */
  145561. JBUF_CRANK_DEST, /* Run dest subobject only, using saved data */
  145562. JBUF_SAVE_AND_PASS /* Run both subobjects, save output */
  145563. } J_BUF_MODE;
  145564. #define CSTATE_START 100 /* after create_compress */
  145565. #define CSTATE_SCANNING 101 /* start_compress done, write_scanlines OK */
  145566. #define CSTATE_RAW_OK 102 /* start_compress done, write_raw_data OK */
  145567. #define CSTATE_WRCOEFS 103 /* jpeg_write_coefficients done */
  145568. #define DSTATE_START 200 /* after create_decompress */
  145569. #define DSTATE_INHEADER 201 /* reading header markers, no SOS yet */
  145570. #define DSTATE_READY 202 /* found SOS, ready for start_decompress */
  145571. #define DSTATE_PRELOAD 203 /* reading multiscan file in start_decompress*/
  145572. #define DSTATE_PRESCAN 204 /* performing dummy pass for 2-pass quant */
  145573. #define DSTATE_SCANNING 205 /* start_decompress done, read_scanlines OK */
  145574. #define DSTATE_RAW_OK 206 /* start_decompress done, read_raw_data OK */
  145575. #define DSTATE_BUFIMAGE 207 /* expecting jpeg_start_output */
  145576. #define DSTATE_BUFPOST 208 /* looking for SOS/EOI in jpeg_finish_output */
  145577. #define DSTATE_RDCOEFS 209 /* reading file in jpeg_read_coefficients */
  145578. #define DSTATE_STOPPING 210 /* looking for EOI in jpeg_finish_decompress */
  145579. struct jpeg_comp_master {
  145580. JMETHOD(void, prepare_for_pass, (j_compress_ptr cinfo));
  145581. JMETHOD(void, pass_startup, (j_compress_ptr cinfo));
  145582. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145583. boolean call_pass_startup; /* True if pass_startup must be called */
  145584. boolean is_last_pass; /* True during last pass */
  145585. };
  145586. struct jpeg_c_main_controller {
  145587. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145588. JMETHOD(void, process_data, (j_compress_ptr cinfo,
  145589. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  145590. JDIMENSION in_rows_avail));
  145591. };
  145592. struct jpeg_c_prep_controller {
  145593. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145594. JMETHOD(void, pre_process_data, (j_compress_ptr cinfo,
  145595. JSAMPARRAY input_buf,
  145596. JDIMENSION *in_row_ctr,
  145597. JDIMENSION in_rows_avail,
  145598. JSAMPIMAGE output_buf,
  145599. JDIMENSION *out_row_group_ctr,
  145600. JDIMENSION out_row_groups_avail));
  145601. };
  145602. struct jpeg_c_coef_controller {
  145603. JMETHOD(void, start_pass, (j_compress_ptr cinfo, J_BUF_MODE pass_mode));
  145604. JMETHOD(boolean, compress_data, (j_compress_ptr cinfo,
  145605. JSAMPIMAGE input_buf));
  145606. };
  145607. struct jpeg_color_converter {
  145608. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145609. JMETHOD(void, color_convert, (j_compress_ptr cinfo,
  145610. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  145611. JDIMENSION output_row, int num_rows));
  145612. };
  145613. struct jpeg_downsampler {
  145614. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145615. JMETHOD(void, downsample, (j_compress_ptr cinfo,
  145616. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  145617. JSAMPIMAGE output_buf,
  145618. JDIMENSION out_row_group_index));
  145619. boolean need_context_rows; /* TRUE if need rows above & below */
  145620. };
  145621. struct jpeg_forward_dct {
  145622. JMETHOD(void, start_pass, (j_compress_ptr cinfo));
  145623. JMETHOD(void, forward_DCT, (j_compress_ptr cinfo,
  145624. jpeg_component_info * compptr,
  145625. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  145626. JDIMENSION start_row, JDIMENSION start_col,
  145627. JDIMENSION num_blocks));
  145628. };
  145629. struct jpeg_entropy_encoder {
  145630. JMETHOD(void, start_pass, (j_compress_ptr cinfo, boolean gather_statistics));
  145631. JMETHOD(boolean, encode_mcu, (j_compress_ptr cinfo, JBLOCKROW *MCU_data));
  145632. JMETHOD(void, finish_pass, (j_compress_ptr cinfo));
  145633. };
  145634. struct jpeg_marker_writer {
  145635. JMETHOD(void, write_file_header, (j_compress_ptr cinfo));
  145636. JMETHOD(void, write_frame_header, (j_compress_ptr cinfo));
  145637. JMETHOD(void, write_scan_header, (j_compress_ptr cinfo));
  145638. JMETHOD(void, write_file_trailer, (j_compress_ptr cinfo));
  145639. JMETHOD(void, write_tables_only, (j_compress_ptr cinfo));
  145640. JMETHOD(void, write_marker_header, (j_compress_ptr cinfo, int marker,
  145641. unsigned int datalen));
  145642. JMETHOD(void, write_marker_byte, (j_compress_ptr cinfo, int val));
  145643. };
  145644. struct jpeg_decomp_master {
  145645. JMETHOD(void, prepare_for_output_pass, (j_decompress_ptr cinfo));
  145646. JMETHOD(void, finish_output_pass, (j_decompress_ptr cinfo));
  145647. boolean is_dummy_pass; /* True during 1st pass for 2-pass quant */
  145648. };
  145649. struct jpeg_input_controller {
  145650. JMETHOD(int, consume_input, (j_decompress_ptr cinfo));
  145651. JMETHOD(void, reset_input_controller, (j_decompress_ptr cinfo));
  145652. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145653. JMETHOD(void, finish_input_pass, (j_decompress_ptr cinfo));
  145654. boolean has_multiple_scans; /* True if file has multiple scans */
  145655. boolean eoi_reached; /* True when EOI has been consumed */
  145656. };
  145657. struct jpeg_d_main_controller {
  145658. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145659. JMETHOD(void, process_data, (j_decompress_ptr cinfo,
  145660. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  145661. JDIMENSION out_rows_avail));
  145662. };
  145663. struct jpeg_d_coef_controller {
  145664. JMETHOD(void, start_input_pass, (j_decompress_ptr cinfo));
  145665. JMETHOD(int, consume_data, (j_decompress_ptr cinfo));
  145666. JMETHOD(void, start_output_pass, (j_decompress_ptr cinfo));
  145667. JMETHOD(int, decompress_data, (j_decompress_ptr cinfo,
  145668. JSAMPIMAGE output_buf));
  145669. jvirt_barray_ptr *coef_arrays;
  145670. };
  145671. struct jpeg_d_post_controller {
  145672. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, J_BUF_MODE pass_mode));
  145673. JMETHOD(void, post_process_data, (j_decompress_ptr cinfo,
  145674. JSAMPIMAGE input_buf,
  145675. JDIMENSION *in_row_group_ctr,
  145676. JDIMENSION in_row_groups_avail,
  145677. JSAMPARRAY output_buf,
  145678. JDIMENSION *out_row_ctr,
  145679. JDIMENSION out_rows_avail));
  145680. };
  145681. struct jpeg_marker_reader {
  145682. JMETHOD(void, reset_marker_reader, (j_decompress_ptr cinfo));
  145683. JMETHOD(int, read_markers, (j_decompress_ptr cinfo));
  145684. jpeg_marker_parser_method read_restart_marker;
  145685. boolean saw_SOI; /* found SOI? */
  145686. boolean saw_SOF; /* found SOF? */
  145687. int next_restart_num; /* next restart number expected (0-7) */
  145688. unsigned int discarded_bytes; /* # of bytes skipped looking for a marker */
  145689. };
  145690. struct jpeg_entropy_decoder {
  145691. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145692. JMETHOD(boolean, decode_mcu, (j_decompress_ptr cinfo,
  145693. JBLOCKROW *MCU_data));
  145694. boolean insufficient_data; /* set TRUE after emitting warning */
  145695. };
  145696. typedef JMETHOD(void, inverse_DCT_method_ptr,
  145697. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  145698. JCOEFPTR coef_block,
  145699. JSAMPARRAY output_buf, JDIMENSION output_col));
  145700. struct jpeg_inverse_dct {
  145701. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145702. inverse_DCT_method_ptr inverse_DCT[MAX_COMPONENTS];
  145703. };
  145704. struct jpeg_upsampler {
  145705. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145706. JMETHOD(void, upsample, (j_decompress_ptr cinfo,
  145707. JSAMPIMAGE input_buf,
  145708. JDIMENSION *in_row_group_ctr,
  145709. JDIMENSION in_row_groups_avail,
  145710. JSAMPARRAY output_buf,
  145711. JDIMENSION *out_row_ctr,
  145712. JDIMENSION out_rows_avail));
  145713. boolean need_context_rows; /* TRUE if need rows above & below */
  145714. };
  145715. struct jpeg_color_deconverter {
  145716. JMETHOD(void, start_pass, (j_decompress_ptr cinfo));
  145717. JMETHOD(void, color_convert, (j_decompress_ptr cinfo,
  145718. JSAMPIMAGE input_buf, JDIMENSION input_row,
  145719. JSAMPARRAY output_buf, int num_rows));
  145720. };
  145721. struct jpeg_color_quantizer {
  145722. JMETHOD(void, start_pass, (j_decompress_ptr cinfo, boolean is_pre_scan));
  145723. JMETHOD(void, color_quantize, (j_decompress_ptr cinfo,
  145724. JSAMPARRAY input_buf, JSAMPARRAY output_buf,
  145725. int num_rows));
  145726. JMETHOD(void, finish_pass, (j_decompress_ptr cinfo));
  145727. JMETHOD(void, new_color_map, (j_decompress_ptr cinfo));
  145728. };
  145729. #undef MAX
  145730. #define MAX(a,b) ((a) > (b) ? (a) : (b))
  145731. #undef MIN
  145732. #define MIN(a,b) ((a) < (b) ? (a) : (b))
  145733. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  145734. #define SHIFT_TEMPS INT32 shift_temp;
  145735. #define RIGHT_SHIFT(x,shft) \
  145736. ((shift_temp = (x)) < 0 ? \
  145737. (shift_temp >> (shft)) | ((~((INT32) 0)) << (32-(shft))) : \
  145738. (shift_temp >> (shft)))
  145739. #else
  145740. #define SHIFT_TEMPS
  145741. #define RIGHT_SHIFT(x,shft) ((x) >> (shft))
  145742. #endif
  145743. #ifdef NEED_SHORT_EXTERNAL_NAMES
  145744. #define jinit_compress_master jICompress
  145745. #define jinit_c_master_control jICMaster
  145746. #define jinit_c_main_controller jICMainC
  145747. #define jinit_c_prep_controller jICPrepC
  145748. #define jinit_c_coef_controller jICCoefC
  145749. #define jinit_color_converter jICColor
  145750. #define jinit_downsampler jIDownsampler
  145751. #define jinit_forward_dct jIFDCT
  145752. #define jinit_huff_encoder jIHEncoder
  145753. #define jinit_phuff_encoder jIPHEncoder
  145754. #define jinit_marker_writer jIMWriter
  145755. #define jinit_master_decompress jIDMaster
  145756. #define jinit_d_main_controller jIDMainC
  145757. #define jinit_d_coef_controller jIDCoefC
  145758. #define jinit_d_post_controller jIDPostC
  145759. #define jinit_input_controller jIInCtlr
  145760. #define jinit_marker_reader jIMReader
  145761. #define jinit_huff_decoder jIHDecoder
  145762. #define jinit_phuff_decoder jIPHDecoder
  145763. #define jinit_inverse_dct jIIDCT
  145764. #define jinit_upsampler jIUpsampler
  145765. #define jinit_color_deconverter jIDColor
  145766. #define jinit_1pass_quantizer jI1Quant
  145767. #define jinit_2pass_quantizer jI2Quant
  145768. #define jinit_merged_upsampler jIMUpsampler
  145769. #define jinit_memory_mgr jIMemMgr
  145770. #define jdiv_round_up jDivRound
  145771. #define jround_up jRound
  145772. #define jcopy_sample_rows jCopySamples
  145773. #define jcopy_block_row jCopyBlocks
  145774. #define jzero_far jZeroFar
  145775. #define jpeg_zigzag_order jZIGTable
  145776. #define jpeg_natural_order jZAGTable
  145777. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  145778. EXTERN(void) jinit_compress_master JPP((j_compress_ptr cinfo));
  145779. EXTERN(void) jinit_c_master_control JPP((j_compress_ptr cinfo,
  145780. boolean transcode_only));
  145781. EXTERN(void) jinit_c_main_controller JPP((j_compress_ptr cinfo,
  145782. boolean need_full_buffer));
  145783. EXTERN(void) jinit_c_prep_controller JPP((j_compress_ptr cinfo,
  145784. boolean need_full_buffer));
  145785. EXTERN(void) jinit_c_coef_controller JPP((j_compress_ptr cinfo,
  145786. boolean need_full_buffer));
  145787. EXTERN(void) jinit_color_converter JPP((j_compress_ptr cinfo));
  145788. EXTERN(void) jinit_downsampler JPP((j_compress_ptr cinfo));
  145789. EXTERN(void) jinit_forward_dct JPP((j_compress_ptr cinfo));
  145790. EXTERN(void) jinit_huff_encoder JPP((j_compress_ptr cinfo));
  145791. EXTERN(void) jinit_phuff_encoder JPP((j_compress_ptr cinfo));
  145792. EXTERN(void) jinit_marker_writer JPP((j_compress_ptr cinfo));
  145793. EXTERN(void) jinit_master_decompress JPP((j_decompress_ptr cinfo));
  145794. EXTERN(void) jinit_d_main_controller JPP((j_decompress_ptr cinfo,
  145795. boolean need_full_buffer));
  145796. EXTERN(void) jinit_d_coef_controller JPP((j_decompress_ptr cinfo,
  145797. boolean need_full_buffer));
  145798. EXTERN(void) jinit_d_post_controller JPP((j_decompress_ptr cinfo,
  145799. boolean need_full_buffer));
  145800. EXTERN(void) jinit_input_controller JPP((j_decompress_ptr cinfo));
  145801. EXTERN(void) jinit_marker_reader JPP((j_decompress_ptr cinfo));
  145802. EXTERN(void) jinit_huff_decoder JPP((j_decompress_ptr cinfo));
  145803. EXTERN(void) jinit_phuff_decoder JPP((j_decompress_ptr cinfo));
  145804. EXTERN(void) jinit_inverse_dct JPP((j_decompress_ptr cinfo));
  145805. EXTERN(void) jinit_upsampler JPP((j_decompress_ptr cinfo));
  145806. EXTERN(void) jinit_color_deconverter JPP((j_decompress_ptr cinfo));
  145807. EXTERN(void) jinit_1pass_quantizer JPP((j_decompress_ptr cinfo));
  145808. EXTERN(void) jinit_2pass_quantizer JPP((j_decompress_ptr cinfo));
  145809. EXTERN(void) jinit_merged_upsampler JPP((j_decompress_ptr cinfo));
  145810. EXTERN(void) jinit_memory_mgr JPP((j_common_ptr cinfo));
  145811. EXTERN(long) jdiv_round_up JPP((long a, long b));
  145812. EXTERN(long) jround_up JPP((long a, long b));
  145813. EXTERN(void) jcopy_sample_rows JPP((JSAMPARRAY input_array, int source_row,
  145814. JSAMPARRAY output_array, int dest_row,
  145815. int num_rows, JDIMENSION num_cols));
  145816. EXTERN(void) jcopy_block_row JPP((JBLOCKROW input_row, JBLOCKROW output_row,
  145817. JDIMENSION num_blocks));
  145818. EXTERN(void) jzero_far JPP((void FAR * target, size_t bytestozero));
  145819. #if 0 /* This table is not actually needed in v6a */
  145820. extern const int jpeg_zigzag_order[]; /* natural coef order to zigzag order */
  145821. #endif
  145822. extern const int jpeg_natural_order[]; /* zigzag coef order to natural order */
  145823. #ifdef INCOMPLETE_TYPES_BROKEN
  145824. #ifndef AM_MEMORY_MANAGER /* only jmemmgr.c defines these */
  145825. struct jvirt_sarray_control { long dummy; };
  145826. struct jvirt_barray_control { long dummy; };
  145827. #endif
  145828. #endif /* INCOMPLETE_TYPES_BROKEN */
  145829. /*** End of inlined file: jpegint.h ***/
  145830. /* fetch private declarations */
  145831. /*** Start of inlined file: jerror.h ***/
  145832. #ifndef JMESSAGE
  145833. #ifndef JERROR_H
  145834. #define JMAKE_ENUM_LIST
  145835. #else
  145836. #define JMESSAGE(code,string)
  145837. #endif /* JERROR_H */
  145838. #endif /* JMESSAGE */
  145839. #ifdef JMAKE_ENUM_LIST
  145840. typedef enum {
  145841. #define JMESSAGE(code,string) code ,
  145842. #endif /* JMAKE_ENUM_LIST */
  145843. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  145844. JMESSAGE(JERR_ARITH_NOTIMPL,
  145845. "Sorry, there are legal restrictions on arithmetic coding")
  145846. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  145847. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  145848. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  145849. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  145850. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  145851. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  145852. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  145853. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  145854. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  145855. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  145856. JMESSAGE(JERR_BAD_LIB_VERSION,
  145857. "Wrong JPEG library version: library is %d, caller expects %d")
  145858. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  145859. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  145860. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  145861. JMESSAGE(JERR_BAD_PROGRESSION,
  145862. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  145863. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  145864. "Invalid progressive parameters at scan script entry %d")
  145865. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  145866. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  145867. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  145868. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  145869. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  145870. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  145871. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  145872. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  145873. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  145874. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  145875. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  145876. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  145877. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  145878. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  145879. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  145880. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  145881. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  145882. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  145883. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  145884. JMESSAGE(JERR_FILE_READ, "Input file read error")
  145885. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  145886. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  145887. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  145888. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  145889. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  145890. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  145891. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  145892. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  145893. "Cannot transcode due to multiple use of quantization table %d")
  145894. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  145895. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  145896. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  145897. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  145898. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  145899. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  145900. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  145901. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  145902. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  145903. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  145904. JMESSAGE(JERR_QUANT_COMPONENTS,
  145905. "Cannot quantize more than %d color components")
  145906. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  145907. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  145908. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  145909. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  145910. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  145911. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  145912. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  145913. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  145914. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  145915. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  145916. JMESSAGE(JERR_TFILE_WRITE,
  145917. "Write failed on temporary file --- out of disk space?")
  145918. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  145919. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  145920. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  145921. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  145922. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  145923. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  145924. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  145925. JMESSAGE(JMSG_VERSION, JVERSION)
  145926. JMESSAGE(JTRC_16BIT_TABLES,
  145927. "Caution: quantization tables are too coarse for baseline JPEG")
  145928. JMESSAGE(JTRC_ADOBE,
  145929. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  145930. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  145931. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  145932. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  145933. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  145934. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  145935. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  145936. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  145937. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  145938. JMESSAGE(JTRC_EOI, "End Of Image")
  145939. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  145940. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  145941. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  145942. "Warning: thumbnail image size does not match data length %u")
  145943. JMESSAGE(JTRC_JFIF_EXTENSION,
  145944. "JFIF extension marker: type 0x%02x, length %u")
  145945. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  145946. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  145947. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  145948. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  145949. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  145950. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  145951. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  145952. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  145953. JMESSAGE(JTRC_RST, "RST%d")
  145954. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  145955. "Smoothing not supported with nonstandard sampling ratios")
  145956. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  145957. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  145958. JMESSAGE(JTRC_SOI, "Start of Image")
  145959. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  145960. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  145961. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  145962. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  145963. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  145964. JMESSAGE(JTRC_THUMB_JPEG,
  145965. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  145966. JMESSAGE(JTRC_THUMB_PALETTE,
  145967. "JFIF extension marker: palette thumbnail image, length %u")
  145968. JMESSAGE(JTRC_THUMB_RGB,
  145969. "JFIF extension marker: RGB thumbnail image, length %u")
  145970. JMESSAGE(JTRC_UNKNOWN_IDS,
  145971. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  145972. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  145973. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  145974. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  145975. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  145976. "Inconsistent progression sequence for component %d coefficient %d")
  145977. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  145978. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  145979. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  145980. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  145981. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  145982. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  145983. JMESSAGE(JWRN_MUST_RESYNC,
  145984. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  145985. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  145986. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  145987. #ifdef JMAKE_ENUM_LIST
  145988. JMSG_LASTMSGCODE
  145989. } J_MESSAGE_CODE;
  145990. #undef JMAKE_ENUM_LIST
  145991. #endif /* JMAKE_ENUM_LIST */
  145992. #undef JMESSAGE
  145993. #ifndef JERROR_H
  145994. #define JERROR_H
  145995. #define ERREXIT(cinfo,code) \
  145996. ((cinfo)->err->msg_code = (code), \
  145997. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  145998. #define ERREXIT1(cinfo,code,p1) \
  145999. ((cinfo)->err->msg_code = (code), \
  146000. (cinfo)->err->msg_parm.i[0] = (p1), \
  146001. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146002. #define ERREXIT2(cinfo,code,p1,p2) \
  146003. ((cinfo)->err->msg_code = (code), \
  146004. (cinfo)->err->msg_parm.i[0] = (p1), \
  146005. (cinfo)->err->msg_parm.i[1] = (p2), \
  146006. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146007. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  146008. ((cinfo)->err->msg_code = (code), \
  146009. (cinfo)->err->msg_parm.i[0] = (p1), \
  146010. (cinfo)->err->msg_parm.i[1] = (p2), \
  146011. (cinfo)->err->msg_parm.i[2] = (p3), \
  146012. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146013. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  146014. ((cinfo)->err->msg_code = (code), \
  146015. (cinfo)->err->msg_parm.i[0] = (p1), \
  146016. (cinfo)->err->msg_parm.i[1] = (p2), \
  146017. (cinfo)->err->msg_parm.i[2] = (p3), \
  146018. (cinfo)->err->msg_parm.i[3] = (p4), \
  146019. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146020. #define ERREXITS(cinfo,code,str) \
  146021. ((cinfo)->err->msg_code = (code), \
  146022. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  146023. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  146024. #define MAKESTMT(stuff) do { stuff } while (0)
  146025. #define WARNMS(cinfo,code) \
  146026. ((cinfo)->err->msg_code = (code), \
  146027. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146028. #define WARNMS1(cinfo,code,p1) \
  146029. ((cinfo)->err->msg_code = (code), \
  146030. (cinfo)->err->msg_parm.i[0] = (p1), \
  146031. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146032. #define WARNMS2(cinfo,code,p1,p2) \
  146033. ((cinfo)->err->msg_code = (code), \
  146034. (cinfo)->err->msg_parm.i[0] = (p1), \
  146035. (cinfo)->err->msg_parm.i[1] = (p2), \
  146036. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  146037. #define TRACEMS(cinfo,lvl,code) \
  146038. ((cinfo)->err->msg_code = (code), \
  146039. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146040. #define TRACEMS1(cinfo,lvl,code,p1) \
  146041. ((cinfo)->err->msg_code = (code), \
  146042. (cinfo)->err->msg_parm.i[0] = (p1), \
  146043. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146044. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  146045. ((cinfo)->err->msg_code = (code), \
  146046. (cinfo)->err->msg_parm.i[0] = (p1), \
  146047. (cinfo)->err->msg_parm.i[1] = (p2), \
  146048. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146049. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  146050. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146051. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  146052. (cinfo)->err->msg_code = (code); \
  146053. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146054. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  146055. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146056. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146057. (cinfo)->err->msg_code = (code); \
  146058. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146059. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  146060. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146061. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146062. _mp[4] = (p5); \
  146063. (cinfo)->err->msg_code = (code); \
  146064. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146065. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  146066. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  146067. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  146068. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  146069. (cinfo)->err->msg_code = (code); \
  146070. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  146071. #define TRACEMSS(cinfo,lvl,code,str) \
  146072. ((cinfo)->err->msg_code = (code), \
  146073. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  146074. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  146075. #endif /* JERROR_H */
  146076. /*** End of inlined file: jerror.h ***/
  146077. /* fetch error codes too */
  146078. #endif
  146079. #endif /* JPEGLIB_H */
  146080. /*** End of inlined file: jpeglib.h ***/
  146081. /*** Start of inlined file: jcapimin.c ***/
  146082. #define JPEG_INTERNALS
  146083. /*** Start of inlined file: jinclude.h ***/
  146084. #ifndef __jinclude_h__
  146085. #define __jinclude_h__
  146086. /*** Start of inlined file: jconfig.h ***/
  146087. // disable all the warnings under MSVC
  146088. #ifdef _MSC_VER
  146089. #pragma warning (disable: 4996 4267 4100 4127 4702 4244)
  146090. #endif
  146091. #ifdef __BORLANDC__
  146092. #pragma warn -8057
  146093. #pragma warn -8019
  146094. #pragma warn -8004
  146095. #pragma warn -8008
  146096. #endif
  146097. #define HAVE_PROTOTYPES
  146098. #define HAVE_UNSIGNED_CHAR
  146099. #define HAVE_UNSIGNED_SHORT
  146100. #undef CHAR_IS_UNSIGNED
  146101. #define HAVE_STDDEF_H
  146102. #define HAVE_STDLIB_H
  146103. #undef NEED_BSD_STRINGS
  146104. #undef NEED_SYS_TYPES_H
  146105. #undef NEED_FAR_POINTERS /* we presume a 32-bit flat memory model */
  146106. #undef NEED_SHORT_EXTERNAL_NAMES
  146107. #undef INCOMPLETE_TYPES_BROKEN
  146108. #ifndef __RPCNDR_H__ /* don't conflict if rpcndr.h already read */
  146109. typedef unsigned char boolean;
  146110. #endif
  146111. #define HAVE_BOOLEAN /* prevent jmorecfg.h from redefining it */
  146112. #ifdef JPEG_INTERNALS
  146113. #undef RIGHT_SHIFT_IS_UNSIGNED
  146114. #endif /* JPEG_INTERNALS */
  146115. #ifdef JPEG_CJPEG_DJPEG
  146116. #define BMP_SUPPORTED /* BMP image file format */
  146117. #define GIF_SUPPORTED /* GIF image file format */
  146118. #define PPM_SUPPORTED /* PBMPLUS PPM/PGM image file format */
  146119. #undef RLE_SUPPORTED /* Utah RLE image file format */
  146120. #define TARGA_SUPPORTED /* Targa image file format */
  146121. #define TWO_FILE_COMMANDLINE /* optional */
  146122. #define USE_SETMODE /* Microsoft has setmode() */
  146123. #undef NEED_SIGNAL_CATCHER
  146124. #undef DONT_USE_B_MODE
  146125. #undef PROGRESS_REPORT /* optional */
  146126. #endif /* JPEG_CJPEG_DJPEG */
  146127. /*** End of inlined file: jconfig.h ***/
  146128. /* auto configuration options */
  146129. #define JCONFIG_INCLUDED /* so that jpeglib.h doesn't do it again */
  146130. #ifdef HAVE_STDDEF_H
  146131. #include <stddef.h>
  146132. #endif
  146133. #ifdef HAVE_STDLIB_H
  146134. #include <stdlib.h>
  146135. #endif
  146136. #ifdef NEED_SYS_TYPES_H
  146137. #include <sys/types.h>
  146138. #endif
  146139. #include <stdio.h>
  146140. #ifdef NEED_BSD_STRINGS
  146141. #include <strings.h>
  146142. #define MEMZERO(target,size) bzero((void *)(target), (size_t)(size))
  146143. #define MEMCOPY(dest,src,size) bcopy((const void *)(src), (void *)(dest), (size_t)(size))
  146144. #else /* not BSD, assume ANSI/SysV string lib */
  146145. #include <string.h>
  146146. #define MEMZERO(target,size) memset((void *)(target), 0, (size_t)(size))
  146147. #define MEMCOPY(dest,src,size) memcpy((void *)(dest), (const void *)(src), (size_t)(size))
  146148. #endif
  146149. #define SIZEOF(object) ((size_t) sizeof(object))
  146150. #define JFREAD(file,buf,sizeofbuf) \
  146151. ((size_t) fread((void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  146152. #define JFWRITE(file,buf,sizeofbuf) \
  146153. ((size_t) fwrite((const void *) (buf), (size_t) 1, (size_t) (sizeofbuf), (file)))
  146154. typedef enum { /* JPEG marker codes */
  146155. M_SOF0 = 0xc0,
  146156. M_SOF1 = 0xc1,
  146157. M_SOF2 = 0xc2,
  146158. M_SOF3 = 0xc3,
  146159. M_SOF5 = 0xc5,
  146160. M_SOF6 = 0xc6,
  146161. M_SOF7 = 0xc7,
  146162. M_JPG = 0xc8,
  146163. M_SOF9 = 0xc9,
  146164. M_SOF10 = 0xca,
  146165. M_SOF11 = 0xcb,
  146166. M_SOF13 = 0xcd,
  146167. M_SOF14 = 0xce,
  146168. M_SOF15 = 0xcf,
  146169. M_DHT = 0xc4,
  146170. M_DAC = 0xcc,
  146171. M_RST0 = 0xd0,
  146172. M_RST1 = 0xd1,
  146173. M_RST2 = 0xd2,
  146174. M_RST3 = 0xd3,
  146175. M_RST4 = 0xd4,
  146176. M_RST5 = 0xd5,
  146177. M_RST6 = 0xd6,
  146178. M_RST7 = 0xd7,
  146179. M_SOI = 0xd8,
  146180. M_EOI = 0xd9,
  146181. M_SOS = 0xda,
  146182. M_DQT = 0xdb,
  146183. M_DNL = 0xdc,
  146184. M_DRI = 0xdd,
  146185. M_DHP = 0xde,
  146186. M_EXP = 0xdf,
  146187. M_APP0 = 0xe0,
  146188. M_APP1 = 0xe1,
  146189. M_APP2 = 0xe2,
  146190. M_APP3 = 0xe3,
  146191. M_APP4 = 0xe4,
  146192. M_APP5 = 0xe5,
  146193. M_APP6 = 0xe6,
  146194. M_APP7 = 0xe7,
  146195. M_APP8 = 0xe8,
  146196. M_APP9 = 0xe9,
  146197. M_APP10 = 0xea,
  146198. M_APP11 = 0xeb,
  146199. M_APP12 = 0xec,
  146200. M_APP13 = 0xed,
  146201. M_APP14 = 0xee,
  146202. M_APP15 = 0xef,
  146203. M_JPG0 = 0xf0,
  146204. M_JPG13 = 0xfd,
  146205. M_COM = 0xfe,
  146206. M_TEM = 0x01,
  146207. M_ERROR = 0x100
  146208. } JPEG_MARKER;
  146209. #ifdef AVOID_TABLES
  146210. #define HUFF_EXTEND(x,s) ((x) < (1<<((s)-1)) ? (x) + (((-1)<<(s)) + 1) : (x))
  146211. #else
  146212. #define HUFF_EXTEND(x,s) ((x) < extend_test[s] ? (x) + extend_offset[s] : (x))
  146213. static const int extend_test[16] = /* entry n is 2**(n-1) */
  146214. { 0, 0x0001, 0x0002, 0x0004, 0x0008, 0x0010, 0x0020, 0x0040, 0x0080,
  146215. 0x0100, 0x0200, 0x0400, 0x0800, 0x1000, 0x2000, 0x4000 };
  146216. static const int extend_offset[16] = /* entry n is (-1 << n) + 1 */
  146217. { 0, ((-1)<<1) + 1, ((-1)<<2) + 1, ((-1)<<3) + 1, ((-1)<<4) + 1,
  146218. ((-1)<<5) + 1, ((-1)<<6) + 1, ((-1)<<7) + 1, ((-1)<<8) + 1,
  146219. ((-1)<<9) + 1, ((-1)<<10) + 1, ((-1)<<11) + 1, ((-1)<<12) + 1,
  146220. ((-1)<<13) + 1, ((-1)<<14) + 1, ((-1)<<15) + 1 };
  146221. #endif /* AVOID_TABLES */
  146222. #endif
  146223. /*** End of inlined file: jinclude.h ***/
  146224. GLOBAL(void)
  146225. jpeg_CreateCompress (j_compress_ptr cinfo, int version, size_t structsize)
  146226. {
  146227. int i;
  146228. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  146229. if (version != JPEG_LIB_VERSION)
  146230. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  146231. if (structsize != SIZEOF(struct jpeg_compress_struct))
  146232. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  146233. (int) SIZEOF(struct jpeg_compress_struct), (int) structsize);
  146234. {
  146235. struct jpeg_error_mgr * err = cinfo->err;
  146236. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  146237. MEMZERO(cinfo, SIZEOF(struct jpeg_compress_struct));
  146238. cinfo->err = err;
  146239. cinfo->client_data = client_data;
  146240. }
  146241. cinfo->is_decompressor = FALSE;
  146242. jinit_memory_mgr((j_common_ptr) cinfo);
  146243. cinfo->progress = NULL;
  146244. cinfo->dest = NULL;
  146245. cinfo->comp_info = NULL;
  146246. for (i = 0; i < NUM_QUANT_TBLS; i++)
  146247. cinfo->quant_tbl_ptrs[i] = NULL;
  146248. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146249. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  146250. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  146251. }
  146252. cinfo->script_space = NULL;
  146253. cinfo->input_gamma = 1.0; /* in case application forgets */
  146254. cinfo->global_state = CSTATE_START;
  146255. }
  146256. GLOBAL(void)
  146257. jpeg_destroy_compress (j_compress_ptr cinfo)
  146258. {
  146259. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  146260. }
  146261. GLOBAL(void)
  146262. jpeg_abort_compress (j_compress_ptr cinfo)
  146263. {
  146264. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  146265. }
  146266. GLOBAL(void)
  146267. jpeg_suppress_tables (j_compress_ptr cinfo, boolean suppress)
  146268. {
  146269. int i;
  146270. JQUANT_TBL * qtbl;
  146271. JHUFF_TBL * htbl;
  146272. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  146273. if ((qtbl = cinfo->quant_tbl_ptrs[i]) != NULL)
  146274. qtbl->sent_table = suppress;
  146275. }
  146276. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  146277. if ((htbl = cinfo->dc_huff_tbl_ptrs[i]) != NULL)
  146278. htbl->sent_table = suppress;
  146279. if ((htbl = cinfo->ac_huff_tbl_ptrs[i]) != NULL)
  146280. htbl->sent_table = suppress;
  146281. }
  146282. }
  146283. GLOBAL(void)
  146284. jpeg_finish_compress (j_compress_ptr cinfo)
  146285. {
  146286. JDIMENSION iMCU_row;
  146287. if (cinfo->global_state == CSTATE_SCANNING ||
  146288. cinfo->global_state == CSTATE_RAW_OK) {
  146289. if (cinfo->next_scanline < cinfo->image_height)
  146290. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  146291. (*cinfo->master->finish_pass) (cinfo);
  146292. } else if (cinfo->global_state != CSTATE_WRCOEFS)
  146293. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146294. while (! cinfo->master->is_last_pass) {
  146295. (*cinfo->master->prepare_for_pass) (cinfo);
  146296. for (iMCU_row = 0; iMCU_row < cinfo->total_iMCU_rows; iMCU_row++) {
  146297. if (cinfo->progress != NULL) {
  146298. cinfo->progress->pass_counter = (long) iMCU_row;
  146299. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows;
  146300. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146301. }
  146302. if (! (*cinfo->coef->compress_data) (cinfo, (JSAMPIMAGE) NULL))
  146303. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  146304. }
  146305. (*cinfo->master->finish_pass) (cinfo);
  146306. }
  146307. (*cinfo->marker->write_file_trailer) (cinfo);
  146308. (*cinfo->dest->term_destination) (cinfo);
  146309. jpeg_abort((j_common_ptr) cinfo);
  146310. }
  146311. GLOBAL(void)
  146312. jpeg_write_marker (j_compress_ptr cinfo, int marker,
  146313. const JOCTET *dataptr, unsigned int datalen)
  146314. {
  146315. JMETHOD(void, write_marker_byte, (j_compress_ptr info, int val));
  146316. if (cinfo->next_scanline != 0 ||
  146317. (cinfo->global_state != CSTATE_SCANNING &&
  146318. cinfo->global_state != CSTATE_RAW_OK &&
  146319. cinfo->global_state != CSTATE_WRCOEFS))
  146320. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146321. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146322. write_marker_byte = cinfo->marker->write_marker_byte; /* copy for speed */
  146323. while (datalen--) {
  146324. (*write_marker_byte) (cinfo, *dataptr);
  146325. dataptr++;
  146326. }
  146327. }
  146328. GLOBAL(void)
  146329. jpeg_write_m_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  146330. {
  146331. if (cinfo->next_scanline != 0 ||
  146332. (cinfo->global_state != CSTATE_SCANNING &&
  146333. cinfo->global_state != CSTATE_RAW_OK &&
  146334. cinfo->global_state != CSTATE_WRCOEFS))
  146335. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146336. (*cinfo->marker->write_marker_header) (cinfo, marker, datalen);
  146337. }
  146338. GLOBAL(void)
  146339. jpeg_write_m_byte (j_compress_ptr cinfo, int val)
  146340. {
  146341. (*cinfo->marker->write_marker_byte) (cinfo, val);
  146342. }
  146343. GLOBAL(void)
  146344. jpeg_write_tables (j_compress_ptr cinfo)
  146345. {
  146346. if (cinfo->global_state != CSTATE_START)
  146347. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146348. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146349. (*cinfo->dest->init_destination) (cinfo);
  146350. jinit_marker_writer(cinfo);
  146351. (*cinfo->marker->write_tables_only) (cinfo);
  146352. (*cinfo->dest->term_destination) (cinfo);
  146353. }
  146354. /*** End of inlined file: jcapimin.c ***/
  146355. /*** Start of inlined file: jcapistd.c ***/
  146356. #define JPEG_INTERNALS
  146357. GLOBAL(void)
  146358. jpeg_start_compress (j_compress_ptr cinfo, boolean write_all_tables)
  146359. {
  146360. if (cinfo->global_state != CSTATE_START)
  146361. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146362. if (write_all_tables)
  146363. jpeg_suppress_tables(cinfo, FALSE); /* mark all tables to be written */
  146364. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  146365. (*cinfo->dest->init_destination) (cinfo);
  146366. jinit_compress_master(cinfo);
  146367. (*cinfo->master->prepare_for_pass) (cinfo);
  146368. cinfo->next_scanline = 0;
  146369. cinfo->global_state = (cinfo->raw_data_in ? CSTATE_RAW_OK : CSTATE_SCANNING);
  146370. }
  146371. GLOBAL(JDIMENSION)
  146372. jpeg_write_scanlines (j_compress_ptr cinfo, JSAMPARRAY scanlines,
  146373. JDIMENSION num_lines)
  146374. {
  146375. JDIMENSION row_ctr, rows_left;
  146376. if (cinfo->global_state != CSTATE_SCANNING)
  146377. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146378. if (cinfo->next_scanline >= cinfo->image_height)
  146379. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146380. if (cinfo->progress != NULL) {
  146381. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146382. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146383. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146384. }
  146385. if (cinfo->master->call_pass_startup)
  146386. (*cinfo->master->pass_startup) (cinfo);
  146387. rows_left = cinfo->image_height - cinfo->next_scanline;
  146388. if (num_lines > rows_left)
  146389. num_lines = rows_left;
  146390. row_ctr = 0;
  146391. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, num_lines);
  146392. cinfo->next_scanline += row_ctr;
  146393. return row_ctr;
  146394. }
  146395. GLOBAL(JDIMENSION)
  146396. jpeg_write_raw_data (j_compress_ptr cinfo, JSAMPIMAGE data,
  146397. JDIMENSION num_lines)
  146398. {
  146399. JDIMENSION lines_per_iMCU_row;
  146400. if (cinfo->global_state != CSTATE_RAW_OK)
  146401. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  146402. if (cinfo->next_scanline >= cinfo->image_height) {
  146403. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  146404. return 0;
  146405. }
  146406. if (cinfo->progress != NULL) {
  146407. cinfo->progress->pass_counter = (long) cinfo->next_scanline;
  146408. cinfo->progress->pass_limit = (long) cinfo->image_height;
  146409. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  146410. }
  146411. if (cinfo->master->call_pass_startup)
  146412. (*cinfo->master->pass_startup) (cinfo);
  146413. lines_per_iMCU_row = cinfo->max_v_samp_factor * DCTSIZE;
  146414. if (num_lines < lines_per_iMCU_row)
  146415. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  146416. if (! (*cinfo->coef->compress_data) (cinfo, data)) {
  146417. return 0;
  146418. }
  146419. cinfo->next_scanline += lines_per_iMCU_row;
  146420. return lines_per_iMCU_row;
  146421. }
  146422. /*** End of inlined file: jcapistd.c ***/
  146423. /*** Start of inlined file: jccoefct.c ***/
  146424. #define JPEG_INTERNALS
  146425. #ifdef ENTROPY_OPT_SUPPORTED
  146426. #define FULL_COEF_BUFFER_SUPPORTED
  146427. #else
  146428. #ifdef C_MULTISCAN_FILES_SUPPORTED
  146429. #define FULL_COEF_BUFFER_SUPPORTED
  146430. #endif
  146431. #endif
  146432. typedef struct {
  146433. struct jpeg_c_coef_controller pub; /* public fields */
  146434. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  146435. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  146436. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  146437. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  146438. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  146439. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  146440. } my_coef_controller;
  146441. typedef my_coef_controller * my_coef_ptr;
  146442. METHODDEF(boolean) compress_data
  146443. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146444. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146445. METHODDEF(boolean) compress_first_pass
  146446. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146447. METHODDEF(boolean) compress_output
  146448. JPP((j_compress_ptr cinfo, JSAMPIMAGE input_buf));
  146449. #endif
  146450. LOCAL(void)
  146451. start_iMCU_row (j_compress_ptr cinfo)
  146452. {
  146453. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146454. if (cinfo->comps_in_scan > 1) {
  146455. coef->MCU_rows_per_iMCU_row = 1;
  146456. } else {
  146457. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  146458. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  146459. else
  146460. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  146461. }
  146462. coef->mcu_ctr = 0;
  146463. coef->MCU_vert_offset = 0;
  146464. }
  146465. METHODDEF(void)
  146466. start_pass_coef (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  146467. {
  146468. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146469. coef->iMCU_row_num = 0;
  146470. start_iMCU_row(cinfo);
  146471. switch (pass_mode) {
  146472. case JBUF_PASS_THRU:
  146473. if (coef->whole_image[0] != NULL)
  146474. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146475. coef->pub.compress_data = compress_data;
  146476. break;
  146477. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146478. case JBUF_SAVE_AND_PASS:
  146479. if (coef->whole_image[0] == NULL)
  146480. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146481. coef->pub.compress_data = compress_first_pass;
  146482. break;
  146483. case JBUF_CRANK_DEST:
  146484. if (coef->whole_image[0] == NULL)
  146485. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146486. coef->pub.compress_data = compress_output;
  146487. break;
  146488. #endif
  146489. default:
  146490. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146491. break;
  146492. }
  146493. }
  146494. METHODDEF(boolean)
  146495. compress_data (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146496. {
  146497. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146498. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146499. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  146500. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146501. int blkn, bi, ci, yindex, yoffset, blockcnt;
  146502. JDIMENSION ypos, xpos;
  146503. jpeg_component_info *compptr;
  146504. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146505. yoffset++) {
  146506. for (MCU_col_num = coef->mcu_ctr; MCU_col_num <= last_MCU_col;
  146507. MCU_col_num++) {
  146508. blkn = 0;
  146509. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146510. compptr = cinfo->cur_comp_info[ci];
  146511. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  146512. : compptr->last_col_width;
  146513. xpos = MCU_col_num * compptr->MCU_sample_width;
  146514. ypos = yoffset * DCTSIZE; /* ypos == (yoffset+yindex) * DCTSIZE */
  146515. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146516. if (coef->iMCU_row_num < last_iMCU_row ||
  146517. yoffset+yindex < compptr->last_row_height) {
  146518. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146519. input_buf[compptr->component_index],
  146520. coef->MCU_buffer[blkn],
  146521. ypos, xpos, (JDIMENSION) blockcnt);
  146522. if (blockcnt < compptr->MCU_width) {
  146523. jzero_far((void FAR *) coef->MCU_buffer[blkn + blockcnt],
  146524. (compptr->MCU_width - blockcnt) * SIZEOF(JBLOCK));
  146525. for (bi = blockcnt; bi < compptr->MCU_width; bi++) {
  146526. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn+bi-1][0][0];
  146527. }
  146528. }
  146529. } else {
  146530. jzero_far((void FAR *) coef->MCU_buffer[blkn],
  146531. compptr->MCU_width * SIZEOF(JBLOCK));
  146532. for (bi = 0; bi < compptr->MCU_width; bi++) {
  146533. coef->MCU_buffer[blkn+bi][0][0] = coef->MCU_buffer[blkn-1][0][0];
  146534. }
  146535. }
  146536. blkn += compptr->MCU_width;
  146537. ypos += DCTSIZE;
  146538. }
  146539. }
  146540. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146541. coef->MCU_vert_offset = yoffset;
  146542. coef->mcu_ctr = MCU_col_num;
  146543. return FALSE;
  146544. }
  146545. }
  146546. coef->mcu_ctr = 0;
  146547. }
  146548. coef->iMCU_row_num++;
  146549. start_iMCU_row(cinfo);
  146550. return TRUE;
  146551. }
  146552. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146553. METHODDEF(boolean)
  146554. compress_first_pass (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146555. {
  146556. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146557. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  146558. JDIMENSION blocks_across, MCUs_across, MCUindex;
  146559. int bi, ci, h_samp_factor, block_row, block_rows, ndummy;
  146560. JCOEF lastDC;
  146561. jpeg_component_info *compptr;
  146562. JBLOCKARRAY buffer;
  146563. JBLOCKROW thisblockrow, lastblockrow;
  146564. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146565. ci++, compptr++) {
  146566. buffer = (*cinfo->mem->access_virt_barray)
  146567. ((j_common_ptr) cinfo, coef->whole_image[ci],
  146568. coef->iMCU_row_num * compptr->v_samp_factor,
  146569. (JDIMENSION) compptr->v_samp_factor, TRUE);
  146570. if (coef->iMCU_row_num < last_iMCU_row)
  146571. block_rows = compptr->v_samp_factor;
  146572. else {
  146573. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  146574. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  146575. }
  146576. blocks_across = compptr->width_in_blocks;
  146577. h_samp_factor = compptr->h_samp_factor;
  146578. ndummy = (int) (blocks_across % h_samp_factor);
  146579. if (ndummy > 0)
  146580. ndummy = h_samp_factor - ndummy;
  146581. for (block_row = 0; block_row < block_rows; block_row++) {
  146582. thisblockrow = buffer[block_row];
  146583. (*cinfo->fdct->forward_DCT) (cinfo, compptr,
  146584. input_buf[ci], thisblockrow,
  146585. (JDIMENSION) (block_row * DCTSIZE),
  146586. (JDIMENSION) 0, blocks_across);
  146587. if (ndummy > 0) {
  146588. thisblockrow += blocks_across; /* => first dummy block */
  146589. jzero_far((void FAR *) thisblockrow, ndummy * SIZEOF(JBLOCK));
  146590. lastDC = thisblockrow[-1][0];
  146591. for (bi = 0; bi < ndummy; bi++) {
  146592. thisblockrow[bi][0] = lastDC;
  146593. }
  146594. }
  146595. }
  146596. if (coef->iMCU_row_num == last_iMCU_row) {
  146597. blocks_across += ndummy; /* include lower right corner */
  146598. MCUs_across = blocks_across / h_samp_factor;
  146599. for (block_row = block_rows; block_row < compptr->v_samp_factor;
  146600. block_row++) {
  146601. thisblockrow = buffer[block_row];
  146602. lastblockrow = buffer[block_row-1];
  146603. jzero_far((void FAR *) thisblockrow,
  146604. (size_t) (blocks_across * SIZEOF(JBLOCK)));
  146605. for (MCUindex = 0; MCUindex < MCUs_across; MCUindex++) {
  146606. lastDC = lastblockrow[h_samp_factor-1][0];
  146607. for (bi = 0; bi < h_samp_factor; bi++) {
  146608. thisblockrow[bi][0] = lastDC;
  146609. }
  146610. thisblockrow += h_samp_factor; /* advance to next MCU in row */
  146611. lastblockrow += h_samp_factor;
  146612. }
  146613. }
  146614. }
  146615. }
  146616. return compress_output(cinfo, input_buf);
  146617. }
  146618. METHODDEF(boolean)
  146619. compress_output (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  146620. {
  146621. my_coef_ptr coef = (my_coef_ptr) cinfo->coef;
  146622. JDIMENSION MCU_col_num; /* index of current MCU within row */
  146623. int blkn, ci, xindex, yindex, yoffset;
  146624. JDIMENSION start_col;
  146625. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  146626. JBLOCKROW buffer_ptr;
  146627. jpeg_component_info *compptr;
  146628. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146629. compptr = cinfo->cur_comp_info[ci];
  146630. buffer[ci] = (*cinfo->mem->access_virt_barray)
  146631. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  146632. coef->iMCU_row_num * compptr->v_samp_factor,
  146633. (JDIMENSION) compptr->v_samp_factor, FALSE);
  146634. }
  146635. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  146636. yoffset++) {
  146637. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  146638. MCU_col_num++) {
  146639. blkn = 0; /* index of current DCT block within MCU */
  146640. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  146641. compptr = cinfo->cur_comp_info[ci];
  146642. start_col = MCU_col_num * compptr->MCU_width;
  146643. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  146644. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  146645. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  146646. coef->MCU_buffer[blkn++] = buffer_ptr++;
  146647. }
  146648. }
  146649. }
  146650. if (! (*cinfo->entropy->encode_mcu) (cinfo, coef->MCU_buffer)) {
  146651. coef->MCU_vert_offset = yoffset;
  146652. coef->mcu_ctr = MCU_col_num;
  146653. return FALSE;
  146654. }
  146655. }
  146656. coef->mcu_ctr = 0;
  146657. }
  146658. coef->iMCU_row_num++;
  146659. start_iMCU_row(cinfo);
  146660. return TRUE;
  146661. }
  146662. #endif /* FULL_COEF_BUFFER_SUPPORTED */
  146663. GLOBAL(void)
  146664. jinit_c_coef_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  146665. {
  146666. my_coef_ptr coef;
  146667. coef = (my_coef_ptr)
  146668. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146669. SIZEOF(my_coef_controller));
  146670. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  146671. coef->pub.start_pass = start_pass_coef;
  146672. if (need_full_buffer) {
  146673. #ifdef FULL_COEF_BUFFER_SUPPORTED
  146674. int ci;
  146675. jpeg_component_info *compptr;
  146676. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  146677. ci++, compptr++) {
  146678. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  146679. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  146680. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  146681. (long) compptr->h_samp_factor),
  146682. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  146683. (long) compptr->v_samp_factor),
  146684. (JDIMENSION) compptr->v_samp_factor);
  146685. }
  146686. #else
  146687. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  146688. #endif
  146689. } else {
  146690. JBLOCKROW buffer;
  146691. int i;
  146692. buffer = (JBLOCKROW)
  146693. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146694. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  146695. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  146696. coef->MCU_buffer[i] = buffer + i;
  146697. }
  146698. coef->whole_image[0] = NULL; /* flag for no virtual arrays */
  146699. }
  146700. }
  146701. /*** End of inlined file: jccoefct.c ***/
  146702. /*** Start of inlined file: jccolor.c ***/
  146703. #define JPEG_INTERNALS
  146704. typedef struct {
  146705. struct jpeg_color_converter pub; /* public fields */
  146706. INT32 * rgb_ycc_tab; /* => table for RGB to YCbCr conversion */
  146707. } my_color_converter;
  146708. typedef my_color_converter * my_cconvert_ptr;
  146709. #define SCALEBITS 16 /* speediest right-shift on some machines */
  146710. #define CBCR_OFFSET ((INT32) CENTERJSAMPLE << SCALEBITS)
  146711. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  146712. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  146713. #define R_Y_OFF 0 /* offset to R => Y section */
  146714. #define G_Y_OFF (1*(MAXJSAMPLE+1)) /* offset to G => Y section */
  146715. #define B_Y_OFF (2*(MAXJSAMPLE+1)) /* etc. */
  146716. #define R_CB_OFF (3*(MAXJSAMPLE+1))
  146717. #define G_CB_OFF (4*(MAXJSAMPLE+1))
  146718. #define B_CB_OFF (5*(MAXJSAMPLE+1))
  146719. #define R_CR_OFF B_CB_OFF /* B=>Cb, R=>Cr are the same */
  146720. #define G_CR_OFF (6*(MAXJSAMPLE+1))
  146721. #define B_CR_OFF (7*(MAXJSAMPLE+1))
  146722. #define TABLE_SIZE (8*(MAXJSAMPLE+1))
  146723. METHODDEF(void)
  146724. rgb_ycc_start (j_compress_ptr cinfo)
  146725. {
  146726. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146727. INT32 * rgb_ycc_tab;
  146728. INT32 i;
  146729. cconvert->rgb_ycc_tab = rgb_ycc_tab = (INT32 *)
  146730. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146731. (TABLE_SIZE * SIZEOF(INT32)));
  146732. for (i = 0; i <= MAXJSAMPLE; i++) {
  146733. rgb_ycc_tab[i+R_Y_OFF] = FIX(0.29900) * i;
  146734. rgb_ycc_tab[i+G_Y_OFF] = FIX(0.58700) * i;
  146735. rgb_ycc_tab[i+B_Y_OFF] = FIX(0.11400) * i + ONE_HALF;
  146736. rgb_ycc_tab[i+R_CB_OFF] = (-FIX(0.16874)) * i;
  146737. rgb_ycc_tab[i+G_CB_OFF] = (-FIX(0.33126)) * i;
  146738. rgb_ycc_tab[i+B_CB_OFF] = FIX(0.50000) * i + CBCR_OFFSET + ONE_HALF-1;
  146739. rgb_ycc_tab[i+G_CR_OFF] = (-FIX(0.41869)) * i;
  146740. rgb_ycc_tab[i+B_CR_OFF] = (-FIX(0.08131)) * i;
  146741. }
  146742. }
  146743. METHODDEF(void)
  146744. rgb_ycc_convert (j_compress_ptr cinfo,
  146745. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146746. JDIMENSION output_row, int num_rows)
  146747. {
  146748. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146749. register int r, g, b;
  146750. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146751. register JSAMPROW inptr;
  146752. register JSAMPROW outptr0, outptr1, outptr2;
  146753. register JDIMENSION col;
  146754. JDIMENSION num_cols = cinfo->image_width;
  146755. while (--num_rows >= 0) {
  146756. inptr = *input_buf++;
  146757. outptr0 = output_buf[0][output_row];
  146758. outptr1 = output_buf[1][output_row];
  146759. outptr2 = output_buf[2][output_row];
  146760. output_row++;
  146761. for (col = 0; col < num_cols; col++) {
  146762. r = GETJSAMPLE(inptr[RGB_RED]);
  146763. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146764. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146765. inptr += RGB_PIXELSIZE;
  146766. outptr0[col] = (JSAMPLE)
  146767. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146768. >> SCALEBITS);
  146769. outptr1[col] = (JSAMPLE)
  146770. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146771. >> SCALEBITS);
  146772. outptr2[col] = (JSAMPLE)
  146773. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146774. >> SCALEBITS);
  146775. }
  146776. }
  146777. }
  146778. METHODDEF(void)
  146779. rgb_gray_convert (j_compress_ptr cinfo,
  146780. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146781. JDIMENSION output_row, int num_rows)
  146782. {
  146783. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146784. register int r, g, b;
  146785. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146786. register JSAMPROW inptr;
  146787. register JSAMPROW outptr;
  146788. register JDIMENSION col;
  146789. JDIMENSION num_cols = cinfo->image_width;
  146790. while (--num_rows >= 0) {
  146791. inptr = *input_buf++;
  146792. outptr = output_buf[0][output_row];
  146793. output_row++;
  146794. for (col = 0; col < num_cols; col++) {
  146795. r = GETJSAMPLE(inptr[RGB_RED]);
  146796. g = GETJSAMPLE(inptr[RGB_GREEN]);
  146797. b = GETJSAMPLE(inptr[RGB_BLUE]);
  146798. inptr += RGB_PIXELSIZE;
  146799. outptr[col] = (JSAMPLE)
  146800. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146801. >> SCALEBITS);
  146802. }
  146803. }
  146804. }
  146805. METHODDEF(void)
  146806. cmyk_ycck_convert (j_compress_ptr cinfo,
  146807. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146808. JDIMENSION output_row, int num_rows)
  146809. {
  146810. my_cconvert_ptr cconvert = (my_cconvert_ptr) cinfo->cconvert;
  146811. register int r, g, b;
  146812. register INT32 * ctab = cconvert->rgb_ycc_tab;
  146813. register JSAMPROW inptr;
  146814. register JSAMPROW outptr0, outptr1, outptr2, outptr3;
  146815. register JDIMENSION col;
  146816. JDIMENSION num_cols = cinfo->image_width;
  146817. while (--num_rows >= 0) {
  146818. inptr = *input_buf++;
  146819. outptr0 = output_buf[0][output_row];
  146820. outptr1 = output_buf[1][output_row];
  146821. outptr2 = output_buf[2][output_row];
  146822. outptr3 = output_buf[3][output_row];
  146823. output_row++;
  146824. for (col = 0; col < num_cols; col++) {
  146825. r = MAXJSAMPLE - GETJSAMPLE(inptr[0]);
  146826. g = MAXJSAMPLE - GETJSAMPLE(inptr[1]);
  146827. b = MAXJSAMPLE - GETJSAMPLE(inptr[2]);
  146828. outptr3[col] = inptr[3]; /* don't need GETJSAMPLE here */
  146829. inptr += 4;
  146830. outptr0[col] = (JSAMPLE)
  146831. ((ctab[r+R_Y_OFF] + ctab[g+G_Y_OFF] + ctab[b+B_Y_OFF])
  146832. >> SCALEBITS);
  146833. outptr1[col] = (JSAMPLE)
  146834. ((ctab[r+R_CB_OFF] + ctab[g+G_CB_OFF] + ctab[b+B_CB_OFF])
  146835. >> SCALEBITS);
  146836. outptr2[col] = (JSAMPLE)
  146837. ((ctab[r+R_CR_OFF] + ctab[g+G_CR_OFF] + ctab[b+B_CR_OFF])
  146838. >> SCALEBITS);
  146839. }
  146840. }
  146841. }
  146842. METHODDEF(void)
  146843. grayscale_convert (j_compress_ptr cinfo,
  146844. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146845. JDIMENSION output_row, int num_rows)
  146846. {
  146847. register JSAMPROW inptr;
  146848. register JSAMPROW outptr;
  146849. register JDIMENSION col;
  146850. JDIMENSION num_cols = cinfo->image_width;
  146851. int instride = cinfo->input_components;
  146852. while (--num_rows >= 0) {
  146853. inptr = *input_buf++;
  146854. outptr = output_buf[0][output_row];
  146855. output_row++;
  146856. for (col = 0; col < num_cols; col++) {
  146857. outptr[col] = inptr[0]; /* don't need GETJSAMPLE() here */
  146858. inptr += instride;
  146859. }
  146860. }
  146861. }
  146862. METHODDEF(void)
  146863. null_convert (j_compress_ptr cinfo,
  146864. JSAMPARRAY input_buf, JSAMPIMAGE output_buf,
  146865. JDIMENSION output_row, int num_rows)
  146866. {
  146867. register JSAMPROW inptr;
  146868. register JSAMPROW outptr;
  146869. register JDIMENSION col;
  146870. register int ci;
  146871. int nc = cinfo->num_components;
  146872. JDIMENSION num_cols = cinfo->image_width;
  146873. while (--num_rows >= 0) {
  146874. for (ci = 0; ci < nc; ci++) {
  146875. inptr = *input_buf;
  146876. outptr = output_buf[ci][output_row];
  146877. for (col = 0; col < num_cols; col++) {
  146878. outptr[col] = inptr[ci]; /* don't need GETJSAMPLE() here */
  146879. inptr += nc;
  146880. }
  146881. }
  146882. input_buf++;
  146883. output_row++;
  146884. }
  146885. }
  146886. METHODDEF(void)
  146887. null_method (j_compress_ptr cinfo)
  146888. {
  146889. }
  146890. GLOBAL(void)
  146891. jinit_color_converter (j_compress_ptr cinfo)
  146892. {
  146893. my_cconvert_ptr cconvert;
  146894. cconvert = (my_cconvert_ptr)
  146895. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  146896. SIZEOF(my_color_converter));
  146897. cinfo->cconvert = (struct jpeg_color_converter *) cconvert;
  146898. cconvert->pub.start_pass = null_method;
  146899. switch (cinfo->in_color_space) {
  146900. case JCS_GRAYSCALE:
  146901. if (cinfo->input_components != 1)
  146902. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146903. break;
  146904. case JCS_RGB:
  146905. #if RGB_PIXELSIZE != 3
  146906. if (cinfo->input_components != RGB_PIXELSIZE)
  146907. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146908. break;
  146909. #endif /* else share code with YCbCr */
  146910. case JCS_YCbCr:
  146911. if (cinfo->input_components != 3)
  146912. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146913. break;
  146914. case JCS_CMYK:
  146915. case JCS_YCCK:
  146916. if (cinfo->input_components != 4)
  146917. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146918. break;
  146919. default: /* JCS_UNKNOWN can be anything */
  146920. if (cinfo->input_components < 1)
  146921. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  146922. break;
  146923. }
  146924. switch (cinfo->jpeg_color_space) {
  146925. case JCS_GRAYSCALE:
  146926. if (cinfo->num_components != 1)
  146927. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146928. if (cinfo->in_color_space == JCS_GRAYSCALE)
  146929. cconvert->pub.color_convert = grayscale_convert;
  146930. else if (cinfo->in_color_space == JCS_RGB) {
  146931. cconvert->pub.start_pass = rgb_ycc_start;
  146932. cconvert->pub.color_convert = rgb_gray_convert;
  146933. } else if (cinfo->in_color_space == JCS_YCbCr)
  146934. cconvert->pub.color_convert = grayscale_convert;
  146935. else
  146936. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146937. break;
  146938. case JCS_RGB:
  146939. if (cinfo->num_components != 3)
  146940. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146941. if (cinfo->in_color_space == JCS_RGB && RGB_PIXELSIZE == 3)
  146942. cconvert->pub.color_convert = null_convert;
  146943. else
  146944. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146945. break;
  146946. case JCS_YCbCr:
  146947. if (cinfo->num_components != 3)
  146948. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146949. if (cinfo->in_color_space == JCS_RGB) {
  146950. cconvert->pub.start_pass = rgb_ycc_start;
  146951. cconvert->pub.color_convert = rgb_ycc_convert;
  146952. } else if (cinfo->in_color_space == JCS_YCbCr)
  146953. cconvert->pub.color_convert = null_convert;
  146954. else
  146955. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146956. break;
  146957. case JCS_CMYK:
  146958. if (cinfo->num_components != 4)
  146959. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146960. if (cinfo->in_color_space == JCS_CMYK)
  146961. cconvert->pub.color_convert = null_convert;
  146962. else
  146963. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146964. break;
  146965. case JCS_YCCK:
  146966. if (cinfo->num_components != 4)
  146967. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  146968. if (cinfo->in_color_space == JCS_CMYK) {
  146969. cconvert->pub.start_pass = rgb_ycc_start;
  146970. cconvert->pub.color_convert = cmyk_ycck_convert;
  146971. } else if (cinfo->in_color_space == JCS_YCCK)
  146972. cconvert->pub.color_convert = null_convert;
  146973. else
  146974. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146975. break;
  146976. default: /* allow null conversion of JCS_UNKNOWN */
  146977. if (cinfo->jpeg_color_space != cinfo->in_color_space ||
  146978. cinfo->num_components != cinfo->input_components)
  146979. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  146980. cconvert->pub.color_convert = null_convert;
  146981. break;
  146982. }
  146983. }
  146984. /*** End of inlined file: jccolor.c ***/
  146985. #undef FIX
  146986. /*** Start of inlined file: jcdctmgr.c ***/
  146987. #define JPEG_INTERNALS
  146988. /*** Start of inlined file: jdct.h ***/
  146989. #ifndef __jdct_h__
  146990. #define __jdct_h__
  146991. #if BITS_IN_JSAMPLE == 8
  146992. typedef int DCTELEM; /* 16 or 32 bits is fine */
  146993. #else
  146994. typedef INT32 DCTELEM; /* must have 32 bits */
  146995. #endif
  146996. typedef JMETHOD(void, forward_DCT_method_ptr, (DCTELEM * data));
  146997. typedef JMETHOD(void, float_DCT_method_ptr, (FAST_FLOAT * data));
  146998. typedef MULTIPLIER ISLOW_MULT_TYPE; /* short or int, whichever is faster */
  146999. #if BITS_IN_JSAMPLE == 8
  147000. typedef MULTIPLIER IFAST_MULT_TYPE; /* 16 bits is OK, use short if faster */
  147001. #define IFAST_SCALE_BITS 2 /* fractional bits in scale factors */
  147002. #else
  147003. typedef INT32 IFAST_MULT_TYPE; /* need 32 bits for scaled quantizers */
  147004. #define IFAST_SCALE_BITS 13 /* fractional bits in scale factors */
  147005. #endif
  147006. typedef FAST_FLOAT FLOAT_MULT_TYPE; /* preferred floating type */
  147007. #define IDCT_range_limit(cinfo) ((cinfo)->sample_range_limit + CENTERJSAMPLE)
  147008. #define RANGE_MASK (MAXJSAMPLE * 4 + 3) /* 2 bits wider than legal samples */
  147009. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147010. #define jpeg_fdct_islow jFDislow
  147011. #define jpeg_fdct_ifast jFDifast
  147012. #define jpeg_fdct_float jFDfloat
  147013. #define jpeg_idct_islow jRDislow
  147014. #define jpeg_idct_ifast jRDifast
  147015. #define jpeg_idct_float jRDfloat
  147016. #define jpeg_idct_4x4 jRD4x4
  147017. #define jpeg_idct_2x2 jRD2x2
  147018. #define jpeg_idct_1x1 jRD1x1
  147019. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147020. EXTERN(void) jpeg_fdct_islow JPP((DCTELEM * data));
  147021. EXTERN(void) jpeg_fdct_ifast JPP((DCTELEM * data));
  147022. EXTERN(void) jpeg_fdct_float JPP((FAST_FLOAT * data));
  147023. EXTERN(void) jpeg_idct_islow
  147024. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147025. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147026. EXTERN(void) jpeg_idct_ifast
  147027. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147028. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147029. EXTERN(void) jpeg_idct_float
  147030. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147031. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147032. EXTERN(void) jpeg_idct_4x4
  147033. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147034. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147035. EXTERN(void) jpeg_idct_2x2
  147036. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147037. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147038. EXTERN(void) jpeg_idct_1x1
  147039. JPP((j_decompress_ptr cinfo, jpeg_component_info * compptr,
  147040. JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col));
  147041. #define ONE ((INT32) 1)
  147042. #define CONST_SCALE (ONE << CONST_BITS)
  147043. #define FIX(x) ((INT32) ((x) * CONST_SCALE + 0.5))
  147044. #define DESCALE(x,n) RIGHT_SHIFT((x) + (ONE << ((n)-1)), n)
  147045. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  147046. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT16) (const)))
  147047. #endif
  147048. #ifdef SHORTxLCONST_32 /* known to work with Microsoft C 6.0 */
  147049. #define MULTIPLY16C16(var,const) (((INT16) (var)) * ((INT32) (const)))
  147050. #endif
  147051. #ifndef MULTIPLY16C16 /* default definition */
  147052. #define MULTIPLY16C16(var,const) ((var) * (const))
  147053. #endif
  147054. #ifdef SHORTxSHORT_32 /* may work if 'int' is 32 bits */
  147055. #define MULTIPLY16V16(var1,var2) (((INT16) (var1)) * ((INT16) (var2)))
  147056. #endif
  147057. #ifndef MULTIPLY16V16 /* default definition */
  147058. #define MULTIPLY16V16(var1,var2) ((var1) * (var2))
  147059. #endif
  147060. #endif
  147061. /*** End of inlined file: jdct.h ***/
  147062. /* Private declarations for DCT subsystem */
  147063. typedef struct {
  147064. struct jpeg_forward_dct pub; /* public fields */
  147065. forward_DCT_method_ptr do_dct;
  147066. DCTELEM * divisors[NUM_QUANT_TBLS];
  147067. #ifdef DCT_FLOAT_SUPPORTED
  147068. float_DCT_method_ptr do_float_dct;
  147069. FAST_FLOAT * float_divisors[NUM_QUANT_TBLS];
  147070. #endif
  147071. } my_fdct_controller;
  147072. typedef my_fdct_controller * my_fdct_ptr;
  147073. METHODDEF(void)
  147074. start_pass_fdctmgr (j_compress_ptr cinfo)
  147075. {
  147076. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147077. int ci, qtblno, i;
  147078. jpeg_component_info *compptr;
  147079. JQUANT_TBL * qtbl;
  147080. DCTELEM * dtbl;
  147081. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147082. ci++, compptr++) {
  147083. qtblno = compptr->quant_tbl_no;
  147084. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  147085. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  147086. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  147087. qtbl = cinfo->quant_tbl_ptrs[qtblno];
  147088. switch (cinfo->dct_method) {
  147089. #ifdef DCT_ISLOW_SUPPORTED
  147090. case JDCT_ISLOW:
  147091. if (fdct->divisors[qtblno] == NULL) {
  147092. fdct->divisors[qtblno] = (DCTELEM *)
  147093. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147094. DCTSIZE2 * SIZEOF(DCTELEM));
  147095. }
  147096. dtbl = fdct->divisors[qtblno];
  147097. for (i = 0; i < DCTSIZE2; i++) {
  147098. dtbl[i] = ((DCTELEM) qtbl->quantval[i]) << 3;
  147099. }
  147100. break;
  147101. #endif
  147102. #ifdef DCT_IFAST_SUPPORTED
  147103. case JDCT_IFAST:
  147104. {
  147105. #define CONST_BITS 14
  147106. static const INT16 aanscales[DCTSIZE2] = {
  147107. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  147108. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  147109. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  147110. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  147111. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  147112. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  147113. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  147114. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  147115. };
  147116. SHIFT_TEMPS
  147117. if (fdct->divisors[qtblno] == NULL) {
  147118. fdct->divisors[qtblno] = (DCTELEM *)
  147119. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147120. DCTSIZE2 * SIZEOF(DCTELEM));
  147121. }
  147122. dtbl = fdct->divisors[qtblno];
  147123. for (i = 0; i < DCTSIZE2; i++) {
  147124. dtbl[i] = (DCTELEM)
  147125. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  147126. (INT32) aanscales[i]),
  147127. CONST_BITS-3);
  147128. }
  147129. }
  147130. break;
  147131. #endif
  147132. #ifdef DCT_FLOAT_SUPPORTED
  147133. case JDCT_FLOAT:
  147134. {
  147135. FAST_FLOAT * fdtbl;
  147136. int row, col;
  147137. static const double aanscalefactor[DCTSIZE] = {
  147138. 1.0, 1.387039845, 1.306562965, 1.175875602,
  147139. 1.0, 0.785694958, 0.541196100, 0.275899379
  147140. };
  147141. if (fdct->float_divisors[qtblno] == NULL) {
  147142. fdct->float_divisors[qtblno] = (FAST_FLOAT *)
  147143. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147144. DCTSIZE2 * SIZEOF(FAST_FLOAT));
  147145. }
  147146. fdtbl = fdct->float_divisors[qtblno];
  147147. i = 0;
  147148. for (row = 0; row < DCTSIZE; row++) {
  147149. for (col = 0; col < DCTSIZE; col++) {
  147150. fdtbl[i] = (FAST_FLOAT)
  147151. (1.0 / (((double) qtbl->quantval[i] *
  147152. aanscalefactor[row] * aanscalefactor[col] * 8.0)));
  147153. i++;
  147154. }
  147155. }
  147156. }
  147157. break;
  147158. #endif
  147159. default:
  147160. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147161. break;
  147162. }
  147163. }
  147164. }
  147165. METHODDEF(void)
  147166. forward_DCT (j_compress_ptr cinfo, jpeg_component_info * compptr,
  147167. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  147168. JDIMENSION start_row, JDIMENSION start_col,
  147169. JDIMENSION num_blocks)
  147170. {
  147171. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147172. forward_DCT_method_ptr do_dct = fdct->do_dct;
  147173. DCTELEM * divisors = fdct->divisors[compptr->quant_tbl_no];
  147174. DCTELEM workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  147175. JDIMENSION bi;
  147176. sample_data += start_row; /* fold in the vertical offset once */
  147177. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  147178. { register DCTELEM *workspaceptr;
  147179. register JSAMPROW elemptr;
  147180. register int elemr;
  147181. workspaceptr = workspace;
  147182. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  147183. elemptr = sample_data[elemr] + start_col;
  147184. #if DCTSIZE == 8 /* unroll the inner loop */
  147185. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147186. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147187. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147188. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147189. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147190. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147191. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147192. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147193. #else
  147194. { register int elemc;
  147195. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  147196. *workspaceptr++ = GETJSAMPLE(*elemptr++) - CENTERJSAMPLE;
  147197. }
  147198. }
  147199. #endif
  147200. }
  147201. }
  147202. (*do_dct) (workspace);
  147203. { register DCTELEM temp, qval;
  147204. register int i;
  147205. register JCOEFPTR output_ptr = coef_blocks[bi];
  147206. for (i = 0; i < DCTSIZE2; i++) {
  147207. qval = divisors[i];
  147208. temp = workspace[i];
  147209. #ifdef FAST_DIVIDE
  147210. #define DIVIDE_BY(a,b) a /= b
  147211. #else
  147212. #define DIVIDE_BY(a,b) if (a >= b) a /= b; else a = 0
  147213. #endif
  147214. if (temp < 0) {
  147215. temp = -temp;
  147216. temp += qval>>1; /* for rounding */
  147217. DIVIDE_BY(temp, qval);
  147218. temp = -temp;
  147219. } else {
  147220. temp += qval>>1; /* for rounding */
  147221. DIVIDE_BY(temp, qval);
  147222. }
  147223. output_ptr[i] = (JCOEF) temp;
  147224. }
  147225. }
  147226. }
  147227. }
  147228. #ifdef DCT_FLOAT_SUPPORTED
  147229. METHODDEF(void)
  147230. forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
  147231. JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
  147232. JDIMENSION start_row, JDIMENSION start_col,
  147233. JDIMENSION num_blocks)
  147234. {
  147235. my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  147236. float_DCT_method_ptr do_dct = fdct->do_float_dct;
  147237. FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  147238. FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  147239. JDIMENSION bi;
  147240. sample_data += start_row; /* fold in the vertical offset once */
  147241. for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
  147242. { register FAST_FLOAT *workspaceptr;
  147243. register JSAMPROW elemptr;
  147244. register int elemr;
  147245. workspaceptr = workspace;
  147246. for (elemr = 0; elemr < DCTSIZE; elemr++) {
  147247. elemptr = sample_data[elemr] + start_col;
  147248. #if DCTSIZE == 8 /* unroll the inner loop */
  147249. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147250. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147251. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147252. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147253. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147254. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147255. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147256. *workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147257. #else
  147258. { register int elemc;
  147259. for (elemc = DCTSIZE; elemc > 0; elemc--) {
  147260. *workspaceptr++ = (FAST_FLOAT)
  147261. (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
  147262. }
  147263. }
  147264. #endif
  147265. }
  147266. }
  147267. (*do_dct) (workspace);
  147268. { register FAST_FLOAT temp;
  147269. register int i;
  147270. register JCOEFPTR output_ptr = coef_blocks[bi];
  147271. for (i = 0; i < DCTSIZE2; i++) {
  147272. temp = workspace[i] * divisors[i];
  147273. output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
  147274. }
  147275. }
  147276. }
  147277. }
  147278. #endif /* DCT_FLOAT_SUPPORTED */
  147279. GLOBAL(void)
  147280. jinit_forward_dct (j_compress_ptr cinfo)
  147281. {
  147282. my_fdct_ptr fdct;
  147283. int i;
  147284. fdct = (my_fdct_ptr)
  147285. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147286. SIZEOF(my_fdct_controller));
  147287. cinfo->fdct = (struct jpeg_forward_dct *) fdct;
  147288. fdct->pub.start_pass = start_pass_fdctmgr;
  147289. switch (cinfo->dct_method) {
  147290. #ifdef DCT_ISLOW_SUPPORTED
  147291. case JDCT_ISLOW:
  147292. fdct->pub.forward_DCT = forward_DCT;
  147293. fdct->do_dct = jpeg_fdct_islow;
  147294. break;
  147295. #endif
  147296. #ifdef DCT_IFAST_SUPPORTED
  147297. case JDCT_IFAST:
  147298. fdct->pub.forward_DCT = forward_DCT;
  147299. fdct->do_dct = jpeg_fdct_ifast;
  147300. break;
  147301. #endif
  147302. #ifdef DCT_FLOAT_SUPPORTED
  147303. case JDCT_FLOAT:
  147304. fdct->pub.forward_DCT = forward_DCT_float;
  147305. fdct->do_float_dct = jpeg_fdct_float;
  147306. break;
  147307. #endif
  147308. default:
  147309. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147310. break;
  147311. }
  147312. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  147313. fdct->divisors[i] = NULL;
  147314. #ifdef DCT_FLOAT_SUPPORTED
  147315. fdct->float_divisors[i] = NULL;
  147316. #endif
  147317. }
  147318. }
  147319. /*** End of inlined file: jcdctmgr.c ***/
  147320. #undef CONST_BITS
  147321. /*** Start of inlined file: jchuff.c ***/
  147322. #define JPEG_INTERNALS
  147323. /*** Start of inlined file: jchuff.h ***/
  147324. #ifndef _jchuff_h_
  147325. #define _jchuff_h_
  147326. #if BITS_IN_JSAMPLE == 8
  147327. #define MAX_COEF_BITS 10
  147328. #else
  147329. #define MAX_COEF_BITS 14
  147330. #endif
  147331. typedef struct {
  147332. unsigned int ehufco[256]; /* code for each symbol */
  147333. char ehufsi[256]; /* length of code for each symbol */
  147334. } c_derived_tbl;
  147335. #ifdef NEED_SHORT_EXTERNAL_NAMES
  147336. #define jpeg_make_c_derived_tbl jMkCDerived
  147337. #define jpeg_gen_optimal_table jGenOptTbl
  147338. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  147339. EXTERN(void) jpeg_make_c_derived_tbl
  147340. JPP((j_compress_ptr cinfo, boolean isDC, int tblno,
  147341. c_derived_tbl ** pdtbl));
  147342. EXTERN(void) jpeg_gen_optimal_table
  147343. JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[]));
  147344. #endif
  147345. /*** End of inlined file: jchuff.h ***/
  147346. /* Declarations shared with jcphuff.c */
  147347. typedef struct {
  147348. INT32 put_buffer; /* current bit-accumulation buffer */
  147349. int put_bits; /* # of bits now in it */
  147350. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  147351. } savable_state;
  147352. #ifndef NO_STRUCT_ASSIGN
  147353. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  147354. #else
  147355. #if MAX_COMPS_IN_SCAN == 4
  147356. #define ASSIGN_STATE(dest,src) \
  147357. ((dest).put_buffer = (src).put_buffer, \
  147358. (dest).put_bits = (src).put_bits, \
  147359. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  147360. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  147361. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  147362. (dest).last_dc_val[3] = (src).last_dc_val[3])
  147363. #endif
  147364. #endif
  147365. typedef struct {
  147366. struct jpeg_entropy_encoder pub; /* public fields */
  147367. savable_state saved; /* Bit buffer & DC state at start of MCU */
  147368. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  147369. int next_restart_num; /* next restart number to write (0-7) */
  147370. c_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  147371. c_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  147372. #ifdef ENTROPY_OPT_SUPPORTED /* Statistics tables for optimization */
  147373. long * dc_count_ptrs[NUM_HUFF_TBLS];
  147374. long * ac_count_ptrs[NUM_HUFF_TBLS];
  147375. #endif
  147376. } huff_entropy_encoder;
  147377. typedef huff_entropy_encoder * huff_entropy_ptr;
  147378. typedef struct {
  147379. JOCTET * next_output_byte; /* => next byte to write in buffer */
  147380. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  147381. savable_state cur; /* Current bit buffer & DC state */
  147382. j_compress_ptr cinfo; /* dump_buffer needs access to this */
  147383. } working_state;
  147384. METHODDEF(boolean) encode_mcu_huff JPP((j_compress_ptr cinfo,
  147385. JBLOCKROW *MCU_data));
  147386. METHODDEF(void) finish_pass_huff JPP((j_compress_ptr cinfo));
  147387. #ifdef ENTROPY_OPT_SUPPORTED
  147388. METHODDEF(boolean) encode_mcu_gather JPP((j_compress_ptr cinfo,
  147389. JBLOCKROW *MCU_data));
  147390. METHODDEF(void) finish_pass_gather JPP((j_compress_ptr cinfo));
  147391. #endif
  147392. METHODDEF(void)
  147393. start_pass_huff (j_compress_ptr cinfo, boolean gather_statistics)
  147394. {
  147395. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147396. int ci, dctbl, actbl;
  147397. jpeg_component_info * compptr;
  147398. if (gather_statistics) {
  147399. #ifdef ENTROPY_OPT_SUPPORTED
  147400. entropy->pub.encode_mcu = encode_mcu_gather;
  147401. entropy->pub.finish_pass = finish_pass_gather;
  147402. #else
  147403. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147404. #endif
  147405. } else {
  147406. entropy->pub.encode_mcu = encode_mcu_huff;
  147407. entropy->pub.finish_pass = finish_pass_huff;
  147408. }
  147409. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147410. compptr = cinfo->cur_comp_info[ci];
  147411. dctbl = compptr->dc_tbl_no;
  147412. actbl = compptr->ac_tbl_no;
  147413. if (gather_statistics) {
  147414. #ifdef ENTROPY_OPT_SUPPORTED
  147415. if (dctbl < 0 || dctbl >= NUM_HUFF_TBLS)
  147416. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, dctbl);
  147417. if (actbl < 0 || actbl >= NUM_HUFF_TBLS)
  147418. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, actbl);
  147419. if (entropy->dc_count_ptrs[dctbl] == NULL)
  147420. entropy->dc_count_ptrs[dctbl] = (long *)
  147421. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147422. 257 * SIZEOF(long));
  147423. MEMZERO(entropy->dc_count_ptrs[dctbl], 257 * SIZEOF(long));
  147424. if (entropy->ac_count_ptrs[actbl] == NULL)
  147425. entropy->ac_count_ptrs[actbl] = (long *)
  147426. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147427. 257 * SIZEOF(long));
  147428. MEMZERO(entropy->ac_count_ptrs[actbl], 257 * SIZEOF(long));
  147429. #endif
  147430. } else {
  147431. jpeg_make_c_derived_tbl(cinfo, TRUE, dctbl,
  147432. & entropy->dc_derived_tbls[dctbl]);
  147433. jpeg_make_c_derived_tbl(cinfo, FALSE, actbl,
  147434. & entropy->ac_derived_tbls[actbl]);
  147435. }
  147436. entropy->saved.last_dc_val[ci] = 0;
  147437. }
  147438. entropy->saved.put_buffer = 0;
  147439. entropy->saved.put_bits = 0;
  147440. entropy->restarts_to_go = cinfo->restart_interval;
  147441. entropy->next_restart_num = 0;
  147442. }
  147443. GLOBAL(void)
  147444. jpeg_make_c_derived_tbl (j_compress_ptr cinfo, boolean isDC, int tblno,
  147445. c_derived_tbl ** pdtbl)
  147446. {
  147447. JHUFF_TBL *htbl;
  147448. c_derived_tbl *dtbl;
  147449. int p, i, l, lastp, si, maxsymbol;
  147450. char huffsize[257];
  147451. unsigned int huffcode[257];
  147452. unsigned int code;
  147453. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  147454. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147455. htbl =
  147456. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  147457. if (htbl == NULL)
  147458. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  147459. if (*pdtbl == NULL)
  147460. *pdtbl = (c_derived_tbl *)
  147461. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147462. SIZEOF(c_derived_tbl));
  147463. dtbl = *pdtbl;
  147464. p = 0;
  147465. for (l = 1; l <= 16; l++) {
  147466. i = (int) htbl->bits[l];
  147467. if (i < 0 || p + i > 256) /* protect against table overrun */
  147468. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147469. while (i--)
  147470. huffsize[p++] = (char) l;
  147471. }
  147472. huffsize[p] = 0;
  147473. lastp = p;
  147474. code = 0;
  147475. si = huffsize[0];
  147476. p = 0;
  147477. while (huffsize[p]) {
  147478. while (((int) huffsize[p]) == si) {
  147479. huffcode[p++] = code;
  147480. code++;
  147481. }
  147482. if (((INT32) code) >= (((INT32) 1) << si))
  147483. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147484. code <<= 1;
  147485. si++;
  147486. }
  147487. MEMZERO(dtbl->ehufsi, SIZEOF(dtbl->ehufsi));
  147488. maxsymbol = isDC ? 15 : 255;
  147489. for (p = 0; p < lastp; p++) {
  147490. i = htbl->huffval[p];
  147491. if (i < 0 || i > maxsymbol || dtbl->ehufsi[i])
  147492. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  147493. dtbl->ehufco[i] = huffcode[p];
  147494. dtbl->ehufsi[i] = huffsize[p];
  147495. }
  147496. }
  147497. #define emit_byte(state,val,action) \
  147498. { *(state)->next_output_byte++ = (JOCTET) (val); \
  147499. if (--(state)->free_in_buffer == 0) \
  147500. if (! dump_buffer(state)) \
  147501. { action; } }
  147502. LOCAL(boolean)
  147503. dump_buffer (working_state * state)
  147504. {
  147505. struct jpeg_destination_mgr * dest = state->cinfo->dest;
  147506. if (! (*dest->empty_output_buffer) (state->cinfo))
  147507. return FALSE;
  147508. state->next_output_byte = dest->next_output_byte;
  147509. state->free_in_buffer = dest->free_in_buffer;
  147510. return TRUE;
  147511. }
  147512. INLINE
  147513. LOCAL(boolean)
  147514. emit_bits (working_state * state, unsigned int code, int size)
  147515. {
  147516. register INT32 put_buffer = (INT32) code;
  147517. register int put_bits = state->cur.put_bits;
  147518. if (size == 0)
  147519. ERREXIT(state->cinfo, JERR_HUFF_MISSING_CODE);
  147520. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  147521. put_bits += size; /* new number of bits in buffer */
  147522. put_buffer <<= 24 - put_bits; /* align incoming bits */
  147523. put_buffer |= state->cur.put_buffer; /* and merge with old buffer contents */
  147524. while (put_bits >= 8) {
  147525. int c = (int) ((put_buffer >> 16) & 0xFF);
  147526. emit_byte(state, c, return FALSE);
  147527. if (c == 0xFF) { /* need to stuff a zero byte? */
  147528. emit_byte(state, 0, return FALSE);
  147529. }
  147530. put_buffer <<= 8;
  147531. put_bits -= 8;
  147532. }
  147533. state->cur.put_buffer = put_buffer; /* update state variables */
  147534. state->cur.put_bits = put_bits;
  147535. return TRUE;
  147536. }
  147537. LOCAL(boolean)
  147538. flush_bits (working_state * state)
  147539. {
  147540. if (! emit_bits(state, 0x7F, 7)) /* fill any partial byte with ones */
  147541. return FALSE;
  147542. state->cur.put_buffer = 0; /* and reset bit-buffer to empty */
  147543. state->cur.put_bits = 0;
  147544. return TRUE;
  147545. }
  147546. LOCAL(boolean)
  147547. encode_one_block (working_state * state, JCOEFPTR block, int last_dc_val,
  147548. c_derived_tbl *dctbl, c_derived_tbl *actbl)
  147549. {
  147550. register int temp, temp2;
  147551. register int nbits;
  147552. register int k, r, i;
  147553. temp = temp2 = block[0] - last_dc_val;
  147554. if (temp < 0) {
  147555. temp = -temp; /* temp is abs value of input */
  147556. temp2--;
  147557. }
  147558. nbits = 0;
  147559. while (temp) {
  147560. nbits++;
  147561. temp >>= 1;
  147562. }
  147563. if (nbits > MAX_COEF_BITS+1)
  147564. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147565. if (! emit_bits(state, dctbl->ehufco[nbits], dctbl->ehufsi[nbits]))
  147566. return FALSE;
  147567. if (nbits) /* emit_bits rejects calls with size 0 */
  147568. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147569. return FALSE;
  147570. r = 0; /* r = run length of zeros */
  147571. for (k = 1; k < DCTSIZE2; k++) {
  147572. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147573. r++;
  147574. } else {
  147575. while (r > 15) {
  147576. if (! emit_bits(state, actbl->ehufco[0xF0], actbl->ehufsi[0xF0]))
  147577. return FALSE;
  147578. r -= 16;
  147579. }
  147580. temp2 = temp;
  147581. if (temp < 0) {
  147582. temp = -temp; /* temp is abs value of input */
  147583. temp2--;
  147584. }
  147585. nbits = 1; /* there must be at least one 1 bit */
  147586. while ((temp >>= 1))
  147587. nbits++;
  147588. if (nbits > MAX_COEF_BITS)
  147589. ERREXIT(state->cinfo, JERR_BAD_DCT_COEF);
  147590. i = (r << 4) + nbits;
  147591. if (! emit_bits(state, actbl->ehufco[i], actbl->ehufsi[i]))
  147592. return FALSE;
  147593. if (! emit_bits(state, (unsigned int) temp2, nbits))
  147594. return FALSE;
  147595. r = 0;
  147596. }
  147597. }
  147598. if (r > 0)
  147599. if (! emit_bits(state, actbl->ehufco[0], actbl->ehufsi[0]))
  147600. return FALSE;
  147601. return TRUE;
  147602. }
  147603. LOCAL(boolean)
  147604. emit_restart (working_state * state, int restart_num)
  147605. {
  147606. int ci;
  147607. if (! flush_bits(state))
  147608. return FALSE;
  147609. emit_byte(state, 0xFF, return FALSE);
  147610. emit_byte(state, JPEG_RST0 + restart_num, return FALSE);
  147611. for (ci = 0; ci < state->cinfo->comps_in_scan; ci++)
  147612. state->cur.last_dc_val[ci] = 0;
  147613. return TRUE;
  147614. }
  147615. METHODDEF(boolean)
  147616. encode_mcu_huff (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147617. {
  147618. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147619. working_state state;
  147620. int blkn, ci;
  147621. jpeg_component_info * compptr;
  147622. state.next_output_byte = cinfo->dest->next_output_byte;
  147623. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147624. ASSIGN_STATE(state.cur, entropy->saved);
  147625. state.cinfo = cinfo;
  147626. if (cinfo->restart_interval) {
  147627. if (entropy->restarts_to_go == 0)
  147628. if (! emit_restart(&state, entropy->next_restart_num))
  147629. return FALSE;
  147630. }
  147631. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147632. ci = cinfo->MCU_membership[blkn];
  147633. compptr = cinfo->cur_comp_info[ci];
  147634. if (! encode_one_block(&state,
  147635. MCU_data[blkn][0], state.cur.last_dc_val[ci],
  147636. entropy->dc_derived_tbls[compptr->dc_tbl_no],
  147637. entropy->ac_derived_tbls[compptr->ac_tbl_no]))
  147638. return FALSE;
  147639. state.cur.last_dc_val[ci] = MCU_data[blkn][0][0];
  147640. }
  147641. cinfo->dest->next_output_byte = state.next_output_byte;
  147642. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147643. ASSIGN_STATE(entropy->saved, state.cur);
  147644. if (cinfo->restart_interval) {
  147645. if (entropy->restarts_to_go == 0) {
  147646. entropy->restarts_to_go = cinfo->restart_interval;
  147647. entropy->next_restart_num++;
  147648. entropy->next_restart_num &= 7;
  147649. }
  147650. entropy->restarts_to_go--;
  147651. }
  147652. return TRUE;
  147653. }
  147654. METHODDEF(void)
  147655. finish_pass_huff (j_compress_ptr cinfo)
  147656. {
  147657. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147658. working_state state;
  147659. state.next_output_byte = cinfo->dest->next_output_byte;
  147660. state.free_in_buffer = cinfo->dest->free_in_buffer;
  147661. ASSIGN_STATE(state.cur, entropy->saved);
  147662. state.cinfo = cinfo;
  147663. if (! flush_bits(&state))
  147664. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  147665. cinfo->dest->next_output_byte = state.next_output_byte;
  147666. cinfo->dest->free_in_buffer = state.free_in_buffer;
  147667. ASSIGN_STATE(entropy->saved, state.cur);
  147668. }
  147669. #ifdef ENTROPY_OPT_SUPPORTED
  147670. LOCAL(void)
  147671. htest_one_block (j_compress_ptr cinfo, JCOEFPTR block, int last_dc_val,
  147672. long dc_counts[], long ac_counts[])
  147673. {
  147674. register int temp;
  147675. register int nbits;
  147676. register int k, r;
  147677. temp = block[0] - last_dc_val;
  147678. if (temp < 0)
  147679. temp = -temp;
  147680. nbits = 0;
  147681. while (temp) {
  147682. nbits++;
  147683. temp >>= 1;
  147684. }
  147685. if (nbits > MAX_COEF_BITS+1)
  147686. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147687. dc_counts[nbits]++;
  147688. r = 0; /* r = run length of zeros */
  147689. for (k = 1; k < DCTSIZE2; k++) {
  147690. if ((temp = block[jpeg_natural_order[k]]) == 0) {
  147691. r++;
  147692. } else {
  147693. while (r > 15) {
  147694. ac_counts[0xF0]++;
  147695. r -= 16;
  147696. }
  147697. if (temp < 0)
  147698. temp = -temp;
  147699. nbits = 1; /* there must be at least one 1 bit */
  147700. while ((temp >>= 1))
  147701. nbits++;
  147702. if (nbits > MAX_COEF_BITS)
  147703. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  147704. ac_counts[(r << 4) + nbits]++;
  147705. r = 0;
  147706. }
  147707. }
  147708. if (r > 0)
  147709. ac_counts[0]++;
  147710. }
  147711. METHODDEF(boolean)
  147712. encode_mcu_gather (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  147713. {
  147714. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147715. int blkn, ci;
  147716. jpeg_component_info * compptr;
  147717. if (cinfo->restart_interval) {
  147718. if (entropy->restarts_to_go == 0) {
  147719. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  147720. entropy->saved.last_dc_val[ci] = 0;
  147721. entropy->restarts_to_go = cinfo->restart_interval;
  147722. }
  147723. entropy->restarts_to_go--;
  147724. }
  147725. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  147726. ci = cinfo->MCU_membership[blkn];
  147727. compptr = cinfo->cur_comp_info[ci];
  147728. htest_one_block(cinfo, MCU_data[blkn][0], entropy->saved.last_dc_val[ci],
  147729. entropy->dc_count_ptrs[compptr->dc_tbl_no],
  147730. entropy->ac_count_ptrs[compptr->ac_tbl_no]);
  147731. entropy->saved.last_dc_val[ci] = MCU_data[blkn][0][0];
  147732. }
  147733. return TRUE;
  147734. }
  147735. GLOBAL(void)
  147736. jpeg_gen_optimal_table (j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])
  147737. {
  147738. #define MAX_CLEN 32 /* assumed maximum initial code length */
  147739. UINT8 bits[MAX_CLEN+1]; /* bits[k] = # of symbols with code length k */
  147740. int codesize[257]; /* codesize[k] = code length of symbol k */
  147741. int others[257]; /* next symbol in current branch of tree */
  147742. int c1, c2;
  147743. int p, i, j;
  147744. long v;
  147745. MEMZERO(bits, SIZEOF(bits));
  147746. MEMZERO(codesize, SIZEOF(codesize));
  147747. for (i = 0; i < 257; i++)
  147748. others[i] = -1; /* init links to empty */
  147749. freq[256] = 1; /* make sure 256 has a nonzero count */
  147750. for (;;) {
  147751. c1 = -1;
  147752. v = 1000000000L;
  147753. for (i = 0; i <= 256; i++) {
  147754. if (freq[i] && freq[i] <= v) {
  147755. v = freq[i];
  147756. c1 = i;
  147757. }
  147758. }
  147759. c2 = -1;
  147760. v = 1000000000L;
  147761. for (i = 0; i <= 256; i++) {
  147762. if (freq[i] && freq[i] <= v && i != c1) {
  147763. v = freq[i];
  147764. c2 = i;
  147765. }
  147766. }
  147767. if (c2 < 0)
  147768. break;
  147769. freq[c1] += freq[c2];
  147770. freq[c2] = 0;
  147771. codesize[c1]++;
  147772. while (others[c1] >= 0) {
  147773. c1 = others[c1];
  147774. codesize[c1]++;
  147775. }
  147776. others[c1] = c2; /* chain c2 onto c1's tree branch */
  147777. codesize[c2]++;
  147778. while (others[c2] >= 0) {
  147779. c2 = others[c2];
  147780. codesize[c2]++;
  147781. }
  147782. }
  147783. for (i = 0; i <= 256; i++) {
  147784. if (codesize[i]) {
  147785. if (codesize[i] > MAX_CLEN)
  147786. ERREXIT(cinfo, JERR_HUFF_CLEN_OVERFLOW);
  147787. bits[codesize[i]]++;
  147788. }
  147789. }
  147790. for (i = MAX_CLEN; i > 16; i--) {
  147791. while (bits[i] > 0) {
  147792. j = i - 2; /* find length of new prefix to be used */
  147793. while (bits[j] == 0)
  147794. j--;
  147795. bits[i] -= 2; /* remove two symbols */
  147796. bits[i-1]++; /* one goes in this length */
  147797. bits[j+1] += 2; /* two new symbols in this length */
  147798. bits[j]--; /* symbol of this length is now a prefix */
  147799. }
  147800. }
  147801. while (bits[i] == 0) /* find largest codelength still in use */
  147802. i--;
  147803. bits[i]--;
  147804. MEMCOPY(htbl->bits, bits, SIZEOF(htbl->bits));
  147805. p = 0;
  147806. for (i = 1; i <= MAX_CLEN; i++) {
  147807. for (j = 0; j <= 255; j++) {
  147808. if (codesize[j] == i) {
  147809. htbl->huffval[p] = (UINT8) j;
  147810. p++;
  147811. }
  147812. }
  147813. }
  147814. htbl->sent_table = FALSE;
  147815. }
  147816. METHODDEF(void)
  147817. finish_pass_gather (j_compress_ptr cinfo)
  147818. {
  147819. huff_entropy_ptr entropy = (huff_entropy_ptr) cinfo->entropy;
  147820. int ci, dctbl, actbl;
  147821. jpeg_component_info * compptr;
  147822. JHUFF_TBL **htblptr;
  147823. boolean did_dc[NUM_HUFF_TBLS];
  147824. boolean did_ac[NUM_HUFF_TBLS];
  147825. MEMZERO(did_dc, SIZEOF(did_dc));
  147826. MEMZERO(did_ac, SIZEOF(did_ac));
  147827. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  147828. compptr = cinfo->cur_comp_info[ci];
  147829. dctbl = compptr->dc_tbl_no;
  147830. actbl = compptr->ac_tbl_no;
  147831. if (! did_dc[dctbl]) {
  147832. htblptr = & cinfo->dc_huff_tbl_ptrs[dctbl];
  147833. if (*htblptr == NULL)
  147834. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147835. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->dc_count_ptrs[dctbl]);
  147836. did_dc[dctbl] = TRUE;
  147837. }
  147838. if (! did_ac[actbl]) {
  147839. htblptr = & cinfo->ac_huff_tbl_ptrs[actbl];
  147840. if (*htblptr == NULL)
  147841. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  147842. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->ac_count_ptrs[actbl]);
  147843. did_ac[actbl] = TRUE;
  147844. }
  147845. }
  147846. }
  147847. #endif /* ENTROPY_OPT_SUPPORTED */
  147848. GLOBAL(void)
  147849. jinit_huff_encoder (j_compress_ptr cinfo)
  147850. {
  147851. huff_entropy_ptr entropy;
  147852. int i;
  147853. entropy = (huff_entropy_ptr)
  147854. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  147855. SIZEOF(huff_entropy_encoder));
  147856. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  147857. entropy->pub.start_pass = start_pass_huff;
  147858. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  147859. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  147860. #ifdef ENTROPY_OPT_SUPPORTED
  147861. entropy->dc_count_ptrs[i] = entropy->ac_count_ptrs[i] = NULL;
  147862. #endif
  147863. }
  147864. }
  147865. /*** End of inlined file: jchuff.c ***/
  147866. #undef emit_byte
  147867. /*** Start of inlined file: jcinit.c ***/
  147868. #define JPEG_INTERNALS
  147869. GLOBAL(void)
  147870. jinit_compress_master (j_compress_ptr cinfo)
  147871. {
  147872. jinit_c_master_control(cinfo, FALSE /* full compression */);
  147873. if (! cinfo->raw_data_in) {
  147874. jinit_color_converter(cinfo);
  147875. jinit_downsampler(cinfo);
  147876. jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */);
  147877. }
  147878. jinit_forward_dct(cinfo);
  147879. if (cinfo->arith_code) {
  147880. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  147881. } else {
  147882. if (cinfo->progressive_mode) {
  147883. #ifdef C_PROGRESSIVE_SUPPORTED
  147884. jinit_phuff_encoder(cinfo);
  147885. #else
  147886. ERREXIT(cinfo, JERR_NOT_COMPILED);
  147887. #endif
  147888. } else
  147889. jinit_huff_encoder(cinfo);
  147890. }
  147891. jinit_c_coef_controller(cinfo,
  147892. (boolean) (cinfo->num_scans > 1 || cinfo->optimize_coding));
  147893. jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */);
  147894. jinit_marker_writer(cinfo);
  147895. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  147896. (*cinfo->marker->write_file_header) (cinfo);
  147897. }
  147898. /*** End of inlined file: jcinit.c ***/
  147899. /*** Start of inlined file: jcmainct.c ***/
  147900. #define JPEG_INTERNALS
  147901. #undef FULL_MAIN_BUFFER_SUPPORTED
  147902. typedef struct {
  147903. struct jpeg_c_main_controller pub; /* public fields */
  147904. JDIMENSION cur_iMCU_row; /* number of current iMCU row */
  147905. JDIMENSION rowgroup_ctr; /* counts row groups received in iMCU row */
  147906. boolean suspended; /* remember if we suspended output */
  147907. J_BUF_MODE pass_mode; /* current operating mode */
  147908. JSAMPARRAY buffer[MAX_COMPONENTS];
  147909. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147910. jvirt_sarray_ptr whole_image[MAX_COMPONENTS];
  147911. #endif
  147912. } my_main_controller;
  147913. typedef my_main_controller * my_main_ptr;
  147914. METHODDEF(void) process_data_simple_main
  147915. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147916. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147917. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147918. METHODDEF(void) process_data_buffer_main
  147919. JPP((j_compress_ptr cinfo, JSAMPARRAY input_buf,
  147920. JDIMENSION *in_row_ctr, JDIMENSION in_rows_avail));
  147921. #endif
  147922. METHODDEF(void)
  147923. start_pass_main (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  147924. {
  147925. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147926. if (cinfo->raw_data_in)
  147927. return;
  147928. main_->cur_iMCU_row = 0; /* initialize counters */
  147929. main_->rowgroup_ctr = 0;
  147930. main_->suspended = FALSE;
  147931. main_->pass_mode = pass_mode; /* save mode for use by process_data */
  147932. switch (pass_mode) {
  147933. case JBUF_PASS_THRU:
  147934. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147935. if (main_->whole_image[0] != NULL)
  147936. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147937. #endif
  147938. main_->pub.process_data = process_data_simple_main;
  147939. break;
  147940. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147941. case JBUF_SAVE_SOURCE:
  147942. case JBUF_CRANK_DEST:
  147943. case JBUF_SAVE_AND_PASS:
  147944. if (main_->whole_image[0] == NULL)
  147945. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147946. main_->pub.process_data = process_data_buffer_main;
  147947. break;
  147948. #endif
  147949. default:
  147950. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  147951. break;
  147952. }
  147953. }
  147954. METHODDEF(void)
  147955. process_data_simple_main (j_compress_ptr cinfo,
  147956. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147957. JDIMENSION in_rows_avail)
  147958. {
  147959. my_main_ptr main_ = (my_main_ptr) cinfo->main;
  147960. while (main_->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147961. if (main_->rowgroup_ctr < DCTSIZE)
  147962. (*cinfo->prep->pre_process_data) (cinfo,
  147963. input_buf, in_row_ctr, in_rows_avail,
  147964. main_->buffer, &main_->rowgroup_ctr,
  147965. (JDIMENSION) DCTSIZE);
  147966. if (main_->rowgroup_ctr != DCTSIZE)
  147967. return;
  147968. if (! (*cinfo->coef->compress_data) (cinfo, main_->buffer)) {
  147969. if (! main_->suspended) {
  147970. (*in_row_ctr)--;
  147971. main_->suspended = TRUE;
  147972. }
  147973. return;
  147974. }
  147975. if (main_->suspended) {
  147976. (*in_row_ctr)++;
  147977. main_->suspended = FALSE;
  147978. }
  147979. main_->rowgroup_ctr = 0;
  147980. main_->cur_iMCU_row++;
  147981. }
  147982. }
  147983. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  147984. METHODDEF(void)
  147985. process_data_buffer_main (j_compress_ptr cinfo,
  147986. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  147987. JDIMENSION in_rows_avail)
  147988. {
  147989. my_main_ptr main = (my_main_ptr) cinfo->main;
  147990. int ci;
  147991. jpeg_component_info *compptr;
  147992. boolean writing = (main->pass_mode != JBUF_CRANK_DEST);
  147993. while (main->cur_iMCU_row < cinfo->total_iMCU_rows) {
  147994. if (main->rowgroup_ctr == 0) {
  147995. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  147996. ci++, compptr++) {
  147997. main->buffer[ci] = (*cinfo->mem->access_virt_sarray)
  147998. ((j_common_ptr) cinfo, main->whole_image[ci],
  147999. main->cur_iMCU_row * (compptr->v_samp_factor * DCTSIZE),
  148000. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE), writing);
  148001. }
  148002. if (! writing) {
  148003. *in_row_ctr += cinfo->max_v_samp_factor * DCTSIZE;
  148004. main->rowgroup_ctr = DCTSIZE;
  148005. }
  148006. }
  148007. if (writing) {
  148008. (*cinfo->prep->pre_process_data) (cinfo,
  148009. input_buf, in_row_ctr, in_rows_avail,
  148010. main->buffer, &main->rowgroup_ctr,
  148011. (JDIMENSION) DCTSIZE);
  148012. if (main->rowgroup_ctr < DCTSIZE)
  148013. return;
  148014. }
  148015. if (main->pass_mode != JBUF_SAVE_SOURCE) {
  148016. if (! (*cinfo->coef->compress_data) (cinfo, main->buffer)) {
  148017. if (! main->suspended) {
  148018. (*in_row_ctr)--;
  148019. main->suspended = TRUE;
  148020. }
  148021. return;
  148022. }
  148023. if (main->suspended) {
  148024. (*in_row_ctr)++;
  148025. main->suspended = FALSE;
  148026. }
  148027. }
  148028. main->rowgroup_ctr = 0;
  148029. main->cur_iMCU_row++;
  148030. }
  148031. }
  148032. #endif /* FULL_MAIN_BUFFER_SUPPORTED */
  148033. GLOBAL(void)
  148034. jinit_c_main_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  148035. {
  148036. my_main_ptr main_;
  148037. int ci;
  148038. jpeg_component_info *compptr;
  148039. main_ = (my_main_ptr)
  148040. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148041. SIZEOF(my_main_controller));
  148042. cinfo->main = (struct jpeg_c_main_controller *) main_;
  148043. main_->pub.start_pass = start_pass_main;
  148044. if (cinfo->raw_data_in)
  148045. return;
  148046. if (need_full_buffer) {
  148047. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148048. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148049. ci++, compptr++) {
  148050. main->whole_image[ci] = (*cinfo->mem->request_virt_sarray)
  148051. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  148052. compptr->width_in_blocks * DCTSIZE,
  148053. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  148054. (long) compptr->v_samp_factor) * DCTSIZE,
  148055. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  148056. }
  148057. #else
  148058. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  148059. #endif
  148060. } else {
  148061. #ifdef FULL_MAIN_BUFFER_SUPPORTED
  148062. main_->whole_image[0] = NULL; /* flag for no virtual arrays */
  148063. #endif
  148064. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148065. ci++, compptr++) {
  148066. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  148067. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148068. compptr->width_in_blocks * DCTSIZE,
  148069. (JDIMENSION) (compptr->v_samp_factor * DCTSIZE));
  148070. }
  148071. }
  148072. }
  148073. /*** End of inlined file: jcmainct.c ***/
  148074. /*** Start of inlined file: jcmarker.c ***/
  148075. #define JPEG_INTERNALS
  148076. typedef struct {
  148077. struct jpeg_marker_writer pub; /* public fields */
  148078. unsigned int last_restart_interval; /* last DRI value emitted; 0 after SOI */
  148079. } my_marker_writer;
  148080. typedef my_marker_writer * my_marker_ptr;
  148081. LOCAL(void)
  148082. emit_byte (j_compress_ptr cinfo, int val)
  148083. {
  148084. struct jpeg_destination_mgr * dest = cinfo->dest;
  148085. *(dest->next_output_byte)++ = (JOCTET) val;
  148086. if (--dest->free_in_buffer == 0) {
  148087. if (! (*dest->empty_output_buffer) (cinfo))
  148088. ERREXIT(cinfo, JERR_CANT_SUSPEND);
  148089. }
  148090. }
  148091. LOCAL(void)
  148092. emit_marker (j_compress_ptr cinfo, JPEG_MARKER mark)
  148093. {
  148094. emit_byte(cinfo, 0xFF);
  148095. emit_byte(cinfo, (int) mark);
  148096. }
  148097. LOCAL(void)
  148098. emit_2bytes (j_compress_ptr cinfo, int value)
  148099. {
  148100. emit_byte(cinfo, (value >> 8) & 0xFF);
  148101. emit_byte(cinfo, value & 0xFF);
  148102. }
  148103. LOCAL(int)
  148104. emit_dqt (j_compress_ptr cinfo, int index)
  148105. {
  148106. JQUANT_TBL * qtbl = cinfo->quant_tbl_ptrs[index];
  148107. int prec;
  148108. int i;
  148109. if (qtbl == NULL)
  148110. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, index);
  148111. prec = 0;
  148112. for (i = 0; i < DCTSIZE2; i++) {
  148113. if (qtbl->quantval[i] > 255)
  148114. prec = 1;
  148115. }
  148116. if (! qtbl->sent_table) {
  148117. emit_marker(cinfo, M_DQT);
  148118. emit_2bytes(cinfo, prec ? DCTSIZE2*2 + 1 + 2 : DCTSIZE2 + 1 + 2);
  148119. emit_byte(cinfo, index + (prec<<4));
  148120. for (i = 0; i < DCTSIZE2; i++) {
  148121. unsigned int qval = qtbl->quantval[jpeg_natural_order[i]];
  148122. if (prec)
  148123. emit_byte(cinfo, (int) (qval >> 8));
  148124. emit_byte(cinfo, (int) (qval & 0xFF));
  148125. }
  148126. qtbl->sent_table = TRUE;
  148127. }
  148128. return prec;
  148129. }
  148130. LOCAL(void)
  148131. emit_dht (j_compress_ptr cinfo, int index, boolean is_ac)
  148132. {
  148133. JHUFF_TBL * htbl;
  148134. int length, i;
  148135. if (is_ac) {
  148136. htbl = cinfo->ac_huff_tbl_ptrs[index];
  148137. index += 0x10; /* output index has AC bit set */
  148138. } else {
  148139. htbl = cinfo->dc_huff_tbl_ptrs[index];
  148140. }
  148141. if (htbl == NULL)
  148142. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, index);
  148143. if (! htbl->sent_table) {
  148144. emit_marker(cinfo, M_DHT);
  148145. length = 0;
  148146. for (i = 1; i <= 16; i++)
  148147. length += htbl->bits[i];
  148148. emit_2bytes(cinfo, length + 2 + 1 + 16);
  148149. emit_byte(cinfo, index);
  148150. for (i = 1; i <= 16; i++)
  148151. emit_byte(cinfo, htbl->bits[i]);
  148152. for (i = 0; i < length; i++)
  148153. emit_byte(cinfo, htbl->huffval[i]);
  148154. htbl->sent_table = TRUE;
  148155. }
  148156. }
  148157. LOCAL(void)
  148158. emit_dac (j_compress_ptr cinfo)
  148159. {
  148160. #ifdef C_ARITH_CODING_SUPPORTED
  148161. char dc_in_use[NUM_ARITH_TBLS];
  148162. char ac_in_use[NUM_ARITH_TBLS];
  148163. int length, i;
  148164. jpeg_component_info *compptr;
  148165. for (i = 0; i < NUM_ARITH_TBLS; i++)
  148166. dc_in_use[i] = ac_in_use[i] = 0;
  148167. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148168. compptr = cinfo->cur_comp_info[i];
  148169. dc_in_use[compptr->dc_tbl_no] = 1;
  148170. ac_in_use[compptr->ac_tbl_no] = 1;
  148171. }
  148172. length = 0;
  148173. for (i = 0; i < NUM_ARITH_TBLS; i++)
  148174. length += dc_in_use[i] + ac_in_use[i];
  148175. emit_marker(cinfo, M_DAC);
  148176. emit_2bytes(cinfo, length*2 + 2);
  148177. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  148178. if (dc_in_use[i]) {
  148179. emit_byte(cinfo, i);
  148180. emit_byte(cinfo, cinfo->arith_dc_L[i] + (cinfo->arith_dc_U[i]<<4));
  148181. }
  148182. if (ac_in_use[i]) {
  148183. emit_byte(cinfo, i + 0x10);
  148184. emit_byte(cinfo, cinfo->arith_ac_K[i]);
  148185. }
  148186. }
  148187. #endif /* C_ARITH_CODING_SUPPORTED */
  148188. }
  148189. LOCAL(void)
  148190. emit_dri (j_compress_ptr cinfo)
  148191. {
  148192. emit_marker(cinfo, M_DRI);
  148193. emit_2bytes(cinfo, 4); /* fixed length */
  148194. emit_2bytes(cinfo, (int) cinfo->restart_interval);
  148195. }
  148196. LOCAL(void)
  148197. emit_sof (j_compress_ptr cinfo, JPEG_MARKER code)
  148198. {
  148199. int ci;
  148200. jpeg_component_info *compptr;
  148201. emit_marker(cinfo, code);
  148202. emit_2bytes(cinfo, 3 * cinfo->num_components + 2 + 5 + 1); /* length */
  148203. if ((long) cinfo->image_height > 65535L ||
  148204. (long) cinfo->image_width > 65535L)
  148205. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) 65535);
  148206. emit_byte(cinfo, cinfo->data_precision);
  148207. emit_2bytes(cinfo, (int) cinfo->image_height);
  148208. emit_2bytes(cinfo, (int) cinfo->image_width);
  148209. emit_byte(cinfo, cinfo->num_components);
  148210. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148211. ci++, compptr++) {
  148212. emit_byte(cinfo, compptr->component_id);
  148213. emit_byte(cinfo, (compptr->h_samp_factor << 4) + compptr->v_samp_factor);
  148214. emit_byte(cinfo, compptr->quant_tbl_no);
  148215. }
  148216. }
  148217. LOCAL(void)
  148218. emit_sos (j_compress_ptr cinfo)
  148219. {
  148220. int i, td, ta;
  148221. jpeg_component_info *compptr;
  148222. emit_marker(cinfo, M_SOS);
  148223. emit_2bytes(cinfo, 2 * cinfo->comps_in_scan + 2 + 1 + 3); /* length */
  148224. emit_byte(cinfo, cinfo->comps_in_scan);
  148225. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148226. compptr = cinfo->cur_comp_info[i];
  148227. emit_byte(cinfo, compptr->component_id);
  148228. td = compptr->dc_tbl_no;
  148229. ta = compptr->ac_tbl_no;
  148230. if (cinfo->progressive_mode) {
  148231. if (cinfo->Ss == 0) {
  148232. ta = 0; /* DC scan */
  148233. if (cinfo->Ah != 0 && !cinfo->arith_code)
  148234. td = 0; /* no DC table either */
  148235. } else {
  148236. td = 0; /* AC scan */
  148237. }
  148238. }
  148239. emit_byte(cinfo, (td << 4) + ta);
  148240. }
  148241. emit_byte(cinfo, cinfo->Ss);
  148242. emit_byte(cinfo, cinfo->Se);
  148243. emit_byte(cinfo, (cinfo->Ah << 4) + cinfo->Al);
  148244. }
  148245. LOCAL(void)
  148246. emit_jfif_app0 (j_compress_ptr cinfo)
  148247. {
  148248. emit_marker(cinfo, M_APP0);
  148249. emit_2bytes(cinfo, 2 + 4 + 1 + 2 + 1 + 2 + 2 + 1 + 1); /* length */
  148250. emit_byte(cinfo, 0x4A); /* Identifier: ASCII "JFIF" */
  148251. emit_byte(cinfo, 0x46);
  148252. emit_byte(cinfo, 0x49);
  148253. emit_byte(cinfo, 0x46);
  148254. emit_byte(cinfo, 0);
  148255. emit_byte(cinfo, cinfo->JFIF_major_version); /* Version fields */
  148256. emit_byte(cinfo, cinfo->JFIF_minor_version);
  148257. emit_byte(cinfo, cinfo->density_unit); /* Pixel size information */
  148258. emit_2bytes(cinfo, (int) cinfo->X_density);
  148259. emit_2bytes(cinfo, (int) cinfo->Y_density);
  148260. emit_byte(cinfo, 0); /* No thumbnail image */
  148261. emit_byte(cinfo, 0);
  148262. }
  148263. LOCAL(void)
  148264. emit_adobe_app14 (j_compress_ptr cinfo)
  148265. {
  148266. emit_marker(cinfo, M_APP14);
  148267. emit_2bytes(cinfo, 2 + 5 + 2 + 2 + 2 + 1); /* length */
  148268. emit_byte(cinfo, 0x41); /* Identifier: ASCII "Adobe" */
  148269. emit_byte(cinfo, 0x64);
  148270. emit_byte(cinfo, 0x6F);
  148271. emit_byte(cinfo, 0x62);
  148272. emit_byte(cinfo, 0x65);
  148273. emit_2bytes(cinfo, 100); /* Version */
  148274. emit_2bytes(cinfo, 0); /* Flags0 */
  148275. emit_2bytes(cinfo, 0); /* Flags1 */
  148276. switch (cinfo->jpeg_color_space) {
  148277. case JCS_YCbCr:
  148278. emit_byte(cinfo, 1); /* Color transform = 1 */
  148279. break;
  148280. case JCS_YCCK:
  148281. emit_byte(cinfo, 2); /* Color transform = 2 */
  148282. break;
  148283. default:
  148284. emit_byte(cinfo, 0); /* Color transform = 0 */
  148285. break;
  148286. }
  148287. }
  148288. METHODDEF(void)
  148289. write_marker_header (j_compress_ptr cinfo, int marker, unsigned int datalen)
  148290. {
  148291. if (datalen > (unsigned int) 65533) /* safety check */
  148292. ERREXIT(cinfo, JERR_BAD_LENGTH);
  148293. emit_marker(cinfo, (JPEG_MARKER) marker);
  148294. emit_2bytes(cinfo, (int) (datalen + 2)); /* total length */
  148295. }
  148296. METHODDEF(void)
  148297. write_marker_byte (j_compress_ptr cinfo, int val)
  148298. {
  148299. emit_byte(cinfo, val);
  148300. }
  148301. METHODDEF(void)
  148302. write_file_header (j_compress_ptr cinfo)
  148303. {
  148304. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148305. emit_marker(cinfo, M_SOI); /* first the SOI */
  148306. marker->last_restart_interval = 0;
  148307. if (cinfo->write_JFIF_header) /* next an optional JFIF APP0 */
  148308. emit_jfif_app0(cinfo);
  148309. if (cinfo->write_Adobe_marker) /* next an optional Adobe APP14 */
  148310. emit_adobe_app14(cinfo);
  148311. }
  148312. METHODDEF(void)
  148313. write_frame_header (j_compress_ptr cinfo)
  148314. {
  148315. int ci, prec;
  148316. boolean is_baseline;
  148317. jpeg_component_info *compptr;
  148318. prec = 0;
  148319. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148320. ci++, compptr++) {
  148321. prec += emit_dqt(cinfo, compptr->quant_tbl_no);
  148322. }
  148323. if (cinfo->arith_code || cinfo->progressive_mode ||
  148324. cinfo->data_precision != 8) {
  148325. is_baseline = FALSE;
  148326. } else {
  148327. is_baseline = TRUE;
  148328. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148329. ci++, compptr++) {
  148330. if (compptr->dc_tbl_no > 1 || compptr->ac_tbl_no > 1)
  148331. is_baseline = FALSE;
  148332. }
  148333. if (prec && is_baseline) {
  148334. is_baseline = FALSE;
  148335. TRACEMS(cinfo, 0, JTRC_16BIT_TABLES);
  148336. }
  148337. }
  148338. if (cinfo->arith_code) {
  148339. emit_sof(cinfo, M_SOF9); /* SOF code for arithmetic coding */
  148340. } else {
  148341. if (cinfo->progressive_mode)
  148342. emit_sof(cinfo, M_SOF2); /* SOF code for progressive Huffman */
  148343. else if (is_baseline)
  148344. emit_sof(cinfo, M_SOF0); /* SOF code for baseline implementation */
  148345. else
  148346. emit_sof(cinfo, M_SOF1); /* SOF code for non-baseline Huffman file */
  148347. }
  148348. }
  148349. METHODDEF(void)
  148350. write_scan_header (j_compress_ptr cinfo)
  148351. {
  148352. my_marker_ptr marker = (my_marker_ptr) cinfo->marker;
  148353. int i;
  148354. jpeg_component_info *compptr;
  148355. if (cinfo->arith_code) {
  148356. emit_dac(cinfo);
  148357. } else {
  148358. for (i = 0; i < cinfo->comps_in_scan; i++) {
  148359. compptr = cinfo->cur_comp_info[i];
  148360. if (cinfo->progressive_mode) {
  148361. if (cinfo->Ss == 0) {
  148362. if (cinfo->Ah == 0) /* DC needs no table for refinement scan */
  148363. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148364. } else {
  148365. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148366. }
  148367. } else {
  148368. emit_dht(cinfo, compptr->dc_tbl_no, FALSE);
  148369. emit_dht(cinfo, compptr->ac_tbl_no, TRUE);
  148370. }
  148371. }
  148372. }
  148373. if (cinfo->restart_interval != marker->last_restart_interval) {
  148374. emit_dri(cinfo);
  148375. marker->last_restart_interval = cinfo->restart_interval;
  148376. }
  148377. emit_sos(cinfo);
  148378. }
  148379. METHODDEF(void)
  148380. write_file_trailer (j_compress_ptr cinfo)
  148381. {
  148382. emit_marker(cinfo, M_EOI);
  148383. }
  148384. METHODDEF(void)
  148385. write_tables_only (j_compress_ptr cinfo)
  148386. {
  148387. int i;
  148388. emit_marker(cinfo, M_SOI);
  148389. for (i = 0; i < NUM_QUANT_TBLS; i++) {
  148390. if (cinfo->quant_tbl_ptrs[i] != NULL)
  148391. (void) emit_dqt(cinfo, i);
  148392. }
  148393. if (! cinfo->arith_code) {
  148394. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  148395. if (cinfo->dc_huff_tbl_ptrs[i] != NULL)
  148396. emit_dht(cinfo, i, FALSE);
  148397. if (cinfo->ac_huff_tbl_ptrs[i] != NULL)
  148398. emit_dht(cinfo, i, TRUE);
  148399. }
  148400. }
  148401. emit_marker(cinfo, M_EOI);
  148402. }
  148403. GLOBAL(void)
  148404. jinit_marker_writer (j_compress_ptr cinfo)
  148405. {
  148406. my_marker_ptr marker;
  148407. marker = (my_marker_ptr)
  148408. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148409. SIZEOF(my_marker_writer));
  148410. cinfo->marker = (struct jpeg_marker_writer *) marker;
  148411. marker->pub.write_file_header = write_file_header;
  148412. marker->pub.write_frame_header = write_frame_header;
  148413. marker->pub.write_scan_header = write_scan_header;
  148414. marker->pub.write_file_trailer = write_file_trailer;
  148415. marker->pub.write_tables_only = write_tables_only;
  148416. marker->pub.write_marker_header = write_marker_header;
  148417. marker->pub.write_marker_byte = write_marker_byte;
  148418. marker->last_restart_interval = 0;
  148419. }
  148420. /*** End of inlined file: jcmarker.c ***/
  148421. /*** Start of inlined file: jcmaster.c ***/
  148422. #define JPEG_INTERNALS
  148423. typedef enum {
  148424. main_pass, /* input data, also do first output step */
  148425. huff_opt_pass, /* Huffman code optimization pass */
  148426. output_pass /* data output pass */
  148427. } c_pass_type;
  148428. typedef struct {
  148429. struct jpeg_comp_master pub; /* public fields */
  148430. c_pass_type pass_type; /* the type of the current pass */
  148431. int pass_number; /* # of passes completed */
  148432. int total_passes; /* total # of passes needed */
  148433. int scan_number; /* current index in scan_info[] */
  148434. } my_comp_master;
  148435. typedef my_comp_master * my_master_ptr;
  148436. LOCAL(void)
  148437. initial_setup (j_compress_ptr cinfo)
  148438. {
  148439. int ci;
  148440. jpeg_component_info *compptr;
  148441. long samplesperrow;
  148442. JDIMENSION jd_samplesperrow;
  148443. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  148444. || cinfo->num_components <= 0 || cinfo->input_components <= 0)
  148445. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  148446. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  148447. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  148448. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  148449. samplesperrow = (long) cinfo->image_width * (long) cinfo->input_components;
  148450. jd_samplesperrow = (JDIMENSION) samplesperrow;
  148451. if ((long) jd_samplesperrow != samplesperrow)
  148452. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  148453. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  148454. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  148455. if (cinfo->num_components > MAX_COMPONENTS)
  148456. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148457. MAX_COMPONENTS);
  148458. cinfo->max_h_samp_factor = 1;
  148459. cinfo->max_v_samp_factor = 1;
  148460. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148461. ci++, compptr++) {
  148462. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  148463. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  148464. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  148465. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  148466. compptr->h_samp_factor);
  148467. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  148468. compptr->v_samp_factor);
  148469. }
  148470. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  148471. ci++, compptr++) {
  148472. compptr->component_index = ci;
  148473. compptr->DCT_scaled_size = DCTSIZE;
  148474. compptr->width_in_blocks = (JDIMENSION)
  148475. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148476. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  148477. compptr->height_in_blocks = (JDIMENSION)
  148478. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148479. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  148480. compptr->downsampled_width = (JDIMENSION)
  148481. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  148482. (long) cinfo->max_h_samp_factor);
  148483. compptr->downsampled_height = (JDIMENSION)
  148484. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  148485. (long) cinfo->max_v_samp_factor);
  148486. compptr->component_needed = TRUE;
  148487. }
  148488. cinfo->total_iMCU_rows = (JDIMENSION)
  148489. jdiv_round_up((long) cinfo->image_height,
  148490. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148491. }
  148492. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148493. LOCAL(void)
  148494. validate_script (j_compress_ptr cinfo)
  148495. {
  148496. const jpeg_scan_info * scanptr;
  148497. int scanno, ncomps, ci, coefi, thisi;
  148498. int Ss, Se, Ah, Al;
  148499. boolean component_sent[MAX_COMPONENTS];
  148500. #ifdef C_PROGRESSIVE_SUPPORTED
  148501. int * last_bitpos_ptr;
  148502. int last_bitpos[MAX_COMPONENTS][DCTSIZE2];
  148503. #endif
  148504. if (cinfo->num_scans <= 0)
  148505. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, 0);
  148506. scanptr = cinfo->scan_info;
  148507. if (scanptr->Ss != 0 || scanptr->Se != DCTSIZE2-1) {
  148508. #ifdef C_PROGRESSIVE_SUPPORTED
  148509. cinfo->progressive_mode = TRUE;
  148510. last_bitpos_ptr = & last_bitpos[0][0];
  148511. for (ci = 0; ci < cinfo->num_components; ci++)
  148512. for (coefi = 0; coefi < DCTSIZE2; coefi++)
  148513. *last_bitpos_ptr++ = -1;
  148514. #else
  148515. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148516. #endif
  148517. } else {
  148518. cinfo->progressive_mode = FALSE;
  148519. for (ci = 0; ci < cinfo->num_components; ci++)
  148520. component_sent[ci] = FALSE;
  148521. }
  148522. for (scanno = 1; scanno <= cinfo->num_scans; scanptr++, scanno++) {
  148523. ncomps = scanptr->comps_in_scan;
  148524. if (ncomps <= 0 || ncomps > MAX_COMPS_IN_SCAN)
  148525. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, ncomps, MAX_COMPS_IN_SCAN);
  148526. for (ci = 0; ci < ncomps; ci++) {
  148527. thisi = scanptr->component_index[ci];
  148528. if (thisi < 0 || thisi >= cinfo->num_components)
  148529. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148530. if (ci > 0 && thisi <= scanptr->component_index[ci-1])
  148531. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148532. }
  148533. Ss = scanptr->Ss;
  148534. Se = scanptr->Se;
  148535. Ah = scanptr->Ah;
  148536. Al = scanptr->Al;
  148537. if (cinfo->progressive_mode) {
  148538. #ifdef C_PROGRESSIVE_SUPPORTED
  148539. #if BITS_IN_JSAMPLE == 8
  148540. #define MAX_AH_AL 10
  148541. #else
  148542. #define MAX_AH_AL 13
  148543. #endif
  148544. if (Ss < 0 || Ss >= DCTSIZE2 || Se < Ss || Se >= DCTSIZE2 ||
  148545. Ah < 0 || Ah > MAX_AH_AL || Al < 0 || Al > MAX_AH_AL)
  148546. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148547. if (Ss == 0) {
  148548. if (Se != 0) /* DC and AC together not OK */
  148549. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148550. } else {
  148551. if (ncomps != 1) /* AC scans must be for only one component */
  148552. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148553. }
  148554. for (ci = 0; ci < ncomps; ci++) {
  148555. last_bitpos_ptr = & last_bitpos[scanptr->component_index[ci]][0];
  148556. if (Ss != 0 && last_bitpos_ptr[0] < 0) /* AC without prior DC scan */
  148557. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148558. for (coefi = Ss; coefi <= Se; coefi++) {
  148559. if (last_bitpos_ptr[coefi] < 0) {
  148560. if (Ah != 0)
  148561. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148562. } else {
  148563. if (Ah != last_bitpos_ptr[coefi] || Al != Ah-1)
  148564. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148565. }
  148566. last_bitpos_ptr[coefi] = Al;
  148567. }
  148568. }
  148569. #endif
  148570. } else {
  148571. if (Ss != 0 || Se != DCTSIZE2-1 || Ah != 0 || Al != 0)
  148572. ERREXIT1(cinfo, JERR_BAD_PROG_SCRIPT, scanno);
  148573. for (ci = 0; ci < ncomps; ci++) {
  148574. thisi = scanptr->component_index[ci];
  148575. if (component_sent[thisi])
  148576. ERREXIT1(cinfo, JERR_BAD_SCAN_SCRIPT, scanno);
  148577. component_sent[thisi] = TRUE;
  148578. }
  148579. }
  148580. }
  148581. if (cinfo->progressive_mode) {
  148582. #ifdef C_PROGRESSIVE_SUPPORTED
  148583. for (ci = 0; ci < cinfo->num_components; ci++) {
  148584. if (last_bitpos[ci][0] < 0)
  148585. ERREXIT(cinfo, JERR_MISSING_DATA);
  148586. }
  148587. #endif
  148588. } else {
  148589. for (ci = 0; ci < cinfo->num_components; ci++) {
  148590. if (! component_sent[ci])
  148591. ERREXIT(cinfo, JERR_MISSING_DATA);
  148592. }
  148593. }
  148594. }
  148595. #endif /* C_MULTISCAN_FILES_SUPPORTED */
  148596. LOCAL(void)
  148597. select_scan_parameters (j_compress_ptr cinfo)
  148598. {
  148599. int ci;
  148600. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148601. if (cinfo->scan_info != NULL) {
  148602. my_master_ptr master = (my_master_ptr) cinfo->master;
  148603. const jpeg_scan_info * scanptr = cinfo->scan_info + master->scan_number;
  148604. cinfo->comps_in_scan = scanptr->comps_in_scan;
  148605. for (ci = 0; ci < scanptr->comps_in_scan; ci++) {
  148606. cinfo->cur_comp_info[ci] =
  148607. &cinfo->comp_info[scanptr->component_index[ci]];
  148608. }
  148609. cinfo->Ss = scanptr->Ss;
  148610. cinfo->Se = scanptr->Se;
  148611. cinfo->Ah = scanptr->Ah;
  148612. cinfo->Al = scanptr->Al;
  148613. }
  148614. else
  148615. #endif
  148616. {
  148617. if (cinfo->num_components > MAX_COMPS_IN_SCAN)
  148618. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  148619. MAX_COMPS_IN_SCAN);
  148620. cinfo->comps_in_scan = cinfo->num_components;
  148621. for (ci = 0; ci < cinfo->num_components; ci++) {
  148622. cinfo->cur_comp_info[ci] = &cinfo->comp_info[ci];
  148623. }
  148624. cinfo->Ss = 0;
  148625. cinfo->Se = DCTSIZE2-1;
  148626. cinfo->Ah = 0;
  148627. cinfo->Al = 0;
  148628. }
  148629. }
  148630. LOCAL(void)
  148631. per_scan_setup (j_compress_ptr cinfo)
  148632. {
  148633. int ci, mcublks, tmp;
  148634. jpeg_component_info *compptr;
  148635. if (cinfo->comps_in_scan == 1) {
  148636. compptr = cinfo->cur_comp_info[0];
  148637. cinfo->MCUs_per_row = compptr->width_in_blocks;
  148638. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  148639. compptr->MCU_width = 1;
  148640. compptr->MCU_height = 1;
  148641. compptr->MCU_blocks = 1;
  148642. compptr->MCU_sample_width = DCTSIZE;
  148643. compptr->last_col_width = 1;
  148644. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  148645. if (tmp == 0) tmp = compptr->v_samp_factor;
  148646. compptr->last_row_height = tmp;
  148647. cinfo->blocks_in_MCU = 1;
  148648. cinfo->MCU_membership[0] = 0;
  148649. } else {
  148650. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  148651. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  148652. MAX_COMPS_IN_SCAN);
  148653. cinfo->MCUs_per_row = (JDIMENSION)
  148654. jdiv_round_up((long) cinfo->image_width,
  148655. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  148656. cinfo->MCU_rows_in_scan = (JDIMENSION)
  148657. jdiv_round_up((long) cinfo->image_height,
  148658. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  148659. cinfo->blocks_in_MCU = 0;
  148660. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  148661. compptr = cinfo->cur_comp_info[ci];
  148662. compptr->MCU_width = compptr->h_samp_factor;
  148663. compptr->MCU_height = compptr->v_samp_factor;
  148664. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  148665. compptr->MCU_sample_width = compptr->MCU_width * DCTSIZE;
  148666. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  148667. if (tmp == 0) tmp = compptr->MCU_width;
  148668. compptr->last_col_width = tmp;
  148669. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  148670. if (tmp == 0) tmp = compptr->MCU_height;
  148671. compptr->last_row_height = tmp;
  148672. mcublks = compptr->MCU_blocks;
  148673. if (cinfo->blocks_in_MCU + mcublks > C_MAX_BLOCKS_IN_MCU)
  148674. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  148675. while (mcublks-- > 0) {
  148676. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  148677. }
  148678. }
  148679. }
  148680. if (cinfo->restart_in_rows > 0) {
  148681. long nominal = (long) cinfo->restart_in_rows * (long) cinfo->MCUs_per_row;
  148682. cinfo->restart_interval = (unsigned int) MIN(nominal, 65535L);
  148683. }
  148684. }
  148685. METHODDEF(void)
  148686. prepare_for_pass (j_compress_ptr cinfo)
  148687. {
  148688. my_master_ptr master = (my_master_ptr) cinfo->master;
  148689. switch (master->pass_type) {
  148690. case main_pass:
  148691. select_scan_parameters(cinfo);
  148692. per_scan_setup(cinfo);
  148693. if (! cinfo->raw_data_in) {
  148694. (*cinfo->cconvert->start_pass) (cinfo);
  148695. (*cinfo->downsample->start_pass) (cinfo);
  148696. (*cinfo->prep->start_pass) (cinfo, JBUF_PASS_THRU);
  148697. }
  148698. (*cinfo->fdct->start_pass) (cinfo);
  148699. (*cinfo->entropy->start_pass) (cinfo, cinfo->optimize_coding);
  148700. (*cinfo->coef->start_pass) (cinfo,
  148701. (master->total_passes > 1 ?
  148702. JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  148703. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  148704. if (cinfo->optimize_coding) {
  148705. master->pub.call_pass_startup = FALSE;
  148706. } else {
  148707. master->pub.call_pass_startup = TRUE;
  148708. }
  148709. break;
  148710. #ifdef ENTROPY_OPT_SUPPORTED
  148711. case huff_opt_pass:
  148712. select_scan_parameters(cinfo);
  148713. per_scan_setup(cinfo);
  148714. if (cinfo->Ss != 0 || cinfo->Ah == 0 || cinfo->arith_code) {
  148715. (*cinfo->entropy->start_pass) (cinfo, TRUE);
  148716. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148717. master->pub.call_pass_startup = FALSE;
  148718. break;
  148719. }
  148720. master->pass_type = output_pass;
  148721. master->pass_number++;
  148722. #endif
  148723. case output_pass:
  148724. if (! cinfo->optimize_coding) {
  148725. select_scan_parameters(cinfo);
  148726. per_scan_setup(cinfo);
  148727. }
  148728. (*cinfo->entropy->start_pass) (cinfo, FALSE);
  148729. (*cinfo->coef->start_pass) (cinfo, JBUF_CRANK_DEST);
  148730. if (master->scan_number == 0)
  148731. (*cinfo->marker->write_frame_header) (cinfo);
  148732. (*cinfo->marker->write_scan_header) (cinfo);
  148733. master->pub.call_pass_startup = FALSE;
  148734. break;
  148735. default:
  148736. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148737. }
  148738. master->pub.is_last_pass = (master->pass_number == master->total_passes-1);
  148739. if (cinfo->progress != NULL) {
  148740. cinfo->progress->completed_passes = master->pass_number;
  148741. cinfo->progress->total_passes = master->total_passes;
  148742. }
  148743. }
  148744. METHODDEF(void)
  148745. pass_startup (j_compress_ptr cinfo)
  148746. {
  148747. cinfo->master->call_pass_startup = FALSE; /* reset flag so call only once */
  148748. (*cinfo->marker->write_frame_header) (cinfo);
  148749. (*cinfo->marker->write_scan_header) (cinfo);
  148750. }
  148751. METHODDEF(void)
  148752. finish_pass_master (j_compress_ptr cinfo)
  148753. {
  148754. my_master_ptr master = (my_master_ptr) cinfo->master;
  148755. (*cinfo->entropy->finish_pass) (cinfo);
  148756. switch (master->pass_type) {
  148757. case main_pass:
  148758. master->pass_type = output_pass;
  148759. if (! cinfo->optimize_coding)
  148760. master->scan_number++;
  148761. break;
  148762. case huff_opt_pass:
  148763. master->pass_type = output_pass;
  148764. break;
  148765. case output_pass:
  148766. if (cinfo->optimize_coding)
  148767. master->pass_type = huff_opt_pass;
  148768. master->scan_number++;
  148769. break;
  148770. }
  148771. master->pass_number++;
  148772. }
  148773. GLOBAL(void)
  148774. jinit_c_master_control (j_compress_ptr cinfo, boolean transcode_only)
  148775. {
  148776. my_master_ptr master;
  148777. master = (my_master_ptr)
  148778. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  148779. SIZEOF(my_comp_master));
  148780. cinfo->master = (struct jpeg_comp_master *) master;
  148781. master->pub.prepare_for_pass = prepare_for_pass;
  148782. master->pub.pass_startup = pass_startup;
  148783. master->pub.finish_pass = finish_pass_master;
  148784. master->pub.is_last_pass = FALSE;
  148785. initial_setup(cinfo);
  148786. if (cinfo->scan_info != NULL) {
  148787. #ifdef C_MULTISCAN_FILES_SUPPORTED
  148788. validate_script(cinfo);
  148789. #else
  148790. ERREXIT(cinfo, JERR_NOT_COMPILED);
  148791. #endif
  148792. } else {
  148793. cinfo->progressive_mode = FALSE;
  148794. cinfo->num_scans = 1;
  148795. }
  148796. if (cinfo->progressive_mode) /* TEMPORARY HACK ??? */
  148797. cinfo->optimize_coding = TRUE; /* assume default tables no good for progressive mode */
  148798. if (transcode_only) {
  148799. if (cinfo->optimize_coding)
  148800. master->pass_type = huff_opt_pass;
  148801. else
  148802. master->pass_type = output_pass;
  148803. } else {
  148804. master->pass_type = main_pass;
  148805. }
  148806. master->scan_number = 0;
  148807. master->pass_number = 0;
  148808. if (cinfo->optimize_coding)
  148809. master->total_passes = cinfo->num_scans * 2;
  148810. else
  148811. master->total_passes = cinfo->num_scans;
  148812. }
  148813. /*** End of inlined file: jcmaster.c ***/
  148814. /*** Start of inlined file: jcomapi.c ***/
  148815. #define JPEG_INTERNALS
  148816. GLOBAL(void)
  148817. jpeg_abort (j_common_ptr cinfo)
  148818. {
  148819. int pool;
  148820. if (cinfo->mem == NULL)
  148821. return;
  148822. for (pool = JPOOL_NUMPOOLS-1; pool > JPOOL_PERMANENT; pool--) {
  148823. (*cinfo->mem->free_pool) (cinfo, pool);
  148824. }
  148825. if (cinfo->is_decompressor) {
  148826. cinfo->global_state = DSTATE_START;
  148827. ((j_decompress_ptr) cinfo)->marker_list = NULL;
  148828. } else {
  148829. cinfo->global_state = CSTATE_START;
  148830. }
  148831. }
  148832. GLOBAL(void)
  148833. jpeg_destroy (j_common_ptr cinfo)
  148834. {
  148835. if (cinfo->mem != NULL)
  148836. (*cinfo->mem->self_destruct) (cinfo);
  148837. cinfo->mem = NULL; /* be safe if jpeg_destroy is called twice */
  148838. cinfo->global_state = 0; /* mark it destroyed */
  148839. }
  148840. GLOBAL(JQUANT_TBL *)
  148841. jpeg_alloc_quant_table (j_common_ptr cinfo)
  148842. {
  148843. JQUANT_TBL *tbl;
  148844. tbl = (JQUANT_TBL *)
  148845. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JQUANT_TBL));
  148846. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148847. return tbl;
  148848. }
  148849. GLOBAL(JHUFF_TBL *)
  148850. jpeg_alloc_huff_table (j_common_ptr cinfo)
  148851. {
  148852. JHUFF_TBL *tbl;
  148853. tbl = (JHUFF_TBL *)
  148854. (*cinfo->mem->alloc_small) (cinfo, JPOOL_PERMANENT, SIZEOF(JHUFF_TBL));
  148855. tbl->sent_table = FALSE; /* make sure this is false in any new table */
  148856. return tbl;
  148857. }
  148858. /*** End of inlined file: jcomapi.c ***/
  148859. /*** Start of inlined file: jcparam.c ***/
  148860. #define JPEG_INTERNALS
  148861. GLOBAL(void)
  148862. jpeg_add_quant_table (j_compress_ptr cinfo, int which_tbl,
  148863. const unsigned int *basic_table,
  148864. int scale_factor, boolean force_baseline)
  148865. {
  148866. JQUANT_TBL ** qtblptr;
  148867. int i;
  148868. long temp;
  148869. if (cinfo->global_state != CSTATE_START)
  148870. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  148871. if (which_tbl < 0 || which_tbl >= NUM_QUANT_TBLS)
  148872. ERREXIT1(cinfo, JERR_DQT_INDEX, which_tbl);
  148873. qtblptr = & cinfo->quant_tbl_ptrs[which_tbl];
  148874. if (*qtblptr == NULL)
  148875. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  148876. for (i = 0; i < DCTSIZE2; i++) {
  148877. temp = ((long) basic_table[i] * scale_factor + 50L) / 100L;
  148878. if (temp <= 0L) temp = 1L;
  148879. if (temp > 32767L) temp = 32767L; /* max quantizer needed for 12 bits */
  148880. if (force_baseline && temp > 255L)
  148881. temp = 255L; /* limit to baseline range if requested */
  148882. (*qtblptr)->quantval[i] = (UINT16) temp;
  148883. }
  148884. (*qtblptr)->sent_table = FALSE;
  148885. }
  148886. GLOBAL(void)
  148887. jpeg_set_linear_quality (j_compress_ptr cinfo, int scale_factor,
  148888. boolean force_baseline)
  148889. {
  148890. static const unsigned int std_luminance_quant_tbl[DCTSIZE2] = {
  148891. 16, 11, 10, 16, 24, 40, 51, 61,
  148892. 12, 12, 14, 19, 26, 58, 60, 55,
  148893. 14, 13, 16, 24, 40, 57, 69, 56,
  148894. 14, 17, 22, 29, 51, 87, 80, 62,
  148895. 18, 22, 37, 56, 68, 109, 103, 77,
  148896. 24, 35, 55, 64, 81, 104, 113, 92,
  148897. 49, 64, 78, 87, 103, 121, 120, 101,
  148898. 72, 92, 95, 98, 112, 100, 103, 99
  148899. };
  148900. static const unsigned int std_chrominance_quant_tbl[DCTSIZE2] = {
  148901. 17, 18, 24, 47, 99, 99, 99, 99,
  148902. 18, 21, 26, 66, 99, 99, 99, 99,
  148903. 24, 26, 56, 99, 99, 99, 99, 99,
  148904. 47, 66, 99, 99, 99, 99, 99, 99,
  148905. 99, 99, 99, 99, 99, 99, 99, 99,
  148906. 99, 99, 99, 99, 99, 99, 99, 99,
  148907. 99, 99, 99, 99, 99, 99, 99, 99,
  148908. 99, 99, 99, 99, 99, 99, 99, 99
  148909. };
  148910. jpeg_add_quant_table(cinfo, 0, std_luminance_quant_tbl,
  148911. scale_factor, force_baseline);
  148912. jpeg_add_quant_table(cinfo, 1, std_chrominance_quant_tbl,
  148913. scale_factor, force_baseline);
  148914. }
  148915. GLOBAL(int)
  148916. jpeg_quality_scaling (int quality)
  148917. {
  148918. if (quality <= 0) quality = 1;
  148919. if (quality > 100) quality = 100;
  148920. if (quality < 50)
  148921. quality = 5000 / quality;
  148922. else
  148923. quality = 200 - quality*2;
  148924. return quality;
  148925. }
  148926. GLOBAL(void)
  148927. jpeg_set_quality (j_compress_ptr cinfo, int quality, boolean force_baseline)
  148928. {
  148929. quality = jpeg_quality_scaling(quality);
  148930. jpeg_set_linear_quality(cinfo, quality, force_baseline);
  148931. }
  148932. LOCAL(void)
  148933. add_huff_table (j_compress_ptr cinfo,
  148934. JHUFF_TBL **htblptr, const UINT8 *bits, const UINT8 *val)
  148935. {
  148936. int nsymbols, len;
  148937. if (*htblptr == NULL)
  148938. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  148939. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  148940. nsymbols = 0;
  148941. for (len = 1; len <= 16; len++)
  148942. nsymbols += bits[len];
  148943. if (nsymbols < 1 || nsymbols > 256)
  148944. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  148945. MEMCOPY((*htblptr)->huffval, val, nsymbols * SIZEOF(UINT8));
  148946. (*htblptr)->sent_table = FALSE;
  148947. }
  148948. LOCAL(void)
  148949. std_huff_tables (j_compress_ptr cinfo)
  148950. {
  148951. static const UINT8 bits_dc_luminance[17] =
  148952. { /* 0-base */ 0, 0, 1, 5, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0 };
  148953. static const UINT8 val_dc_luminance[] =
  148954. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148955. static const UINT8 bits_dc_chrominance[17] =
  148956. { /* 0-base */ 0, 0, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0 };
  148957. static const UINT8 val_dc_chrominance[] =
  148958. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 };
  148959. static const UINT8 bits_ac_luminance[17] =
  148960. { /* 0-base */ 0, 0, 2, 1, 3, 3, 2, 4, 3, 5, 5, 4, 4, 0, 0, 1, 0x7d };
  148961. static const UINT8 val_ac_luminance[] =
  148962. { 0x01, 0x02, 0x03, 0x00, 0x04, 0x11, 0x05, 0x12,
  148963. 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61, 0x07,
  148964. 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xa1, 0x08,
  148965. 0x23, 0x42, 0xb1, 0xc1, 0x15, 0x52, 0xd1, 0xf0,
  148966. 0x24, 0x33, 0x62, 0x72, 0x82, 0x09, 0x0a, 0x16,
  148967. 0x17, 0x18, 0x19, 0x1a, 0x25, 0x26, 0x27, 0x28,
  148968. 0x29, 0x2a, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39,
  148969. 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48, 0x49,
  148970. 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, 0x59,
  148971. 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68, 0x69,
  148972. 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, 0x79,
  148973. 0x7a, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88, 0x89,
  148974. 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
  148975. 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
  148976. 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6,
  148977. 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3, 0xc4, 0xc5,
  148978. 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2, 0xd3, 0xd4,
  148979. 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xe1, 0xe2,
  148980. 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea,
  148981. 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  148982. 0xf9, 0xfa };
  148983. static const UINT8 bits_ac_chrominance[17] =
  148984. { /* 0-base */ 0, 0, 2, 1, 2, 4, 4, 3, 4, 7, 5, 4, 4, 0, 1, 2, 0x77 };
  148985. static const UINT8 val_ac_chrominance[] =
  148986. { 0x00, 0x01, 0x02, 0x03, 0x11, 0x04, 0x05, 0x21,
  148987. 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
  148988. 0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
  148989. 0xa1, 0xb1, 0xc1, 0x09, 0x23, 0x33, 0x52, 0xf0,
  148990. 0x15, 0x62, 0x72, 0xd1, 0x0a, 0x16, 0x24, 0x34,
  148991. 0xe1, 0x25, 0xf1, 0x17, 0x18, 0x19, 0x1a, 0x26,
  148992. 0x27, 0x28, 0x29, 0x2a, 0x35, 0x36, 0x37, 0x38,
  148993. 0x39, 0x3a, 0x43, 0x44, 0x45, 0x46, 0x47, 0x48,
  148994. 0x49, 0x4a, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,
  148995. 0x59, 0x5a, 0x63, 0x64, 0x65, 0x66, 0x67, 0x68,
  148996. 0x69, 0x6a, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
  148997. 0x79, 0x7a, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
  148998. 0x88, 0x89, 0x8a, 0x92, 0x93, 0x94, 0x95, 0x96,
  148999. 0x97, 0x98, 0x99, 0x9a, 0xa2, 0xa3, 0xa4, 0xa5,
  149000. 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xb2, 0xb3, 0xb4,
  149001. 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xc2, 0xc3,
  149002. 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xd2,
  149003. 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda,
  149004. 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9,
  149005. 0xea, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8,
  149006. 0xf9, 0xfa };
  149007. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[0],
  149008. bits_dc_luminance, val_dc_luminance);
  149009. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[0],
  149010. bits_ac_luminance, val_ac_luminance);
  149011. add_huff_table(cinfo, &cinfo->dc_huff_tbl_ptrs[1],
  149012. bits_dc_chrominance, val_dc_chrominance);
  149013. add_huff_table(cinfo, &cinfo->ac_huff_tbl_ptrs[1],
  149014. bits_ac_chrominance, val_ac_chrominance);
  149015. }
  149016. GLOBAL(void)
  149017. jpeg_set_defaults (j_compress_ptr cinfo)
  149018. {
  149019. int i;
  149020. if (cinfo->global_state != CSTATE_START)
  149021. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149022. if (cinfo->comp_info == NULL)
  149023. cinfo->comp_info = (jpeg_component_info *)
  149024. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  149025. MAX_COMPONENTS * SIZEOF(jpeg_component_info));
  149026. cinfo->data_precision = BITS_IN_JSAMPLE;
  149027. jpeg_set_quality(cinfo, 75, TRUE);
  149028. std_huff_tables(cinfo);
  149029. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  149030. cinfo->arith_dc_L[i] = 0;
  149031. cinfo->arith_dc_U[i] = 1;
  149032. cinfo->arith_ac_K[i] = 5;
  149033. }
  149034. cinfo->scan_info = NULL;
  149035. cinfo->num_scans = 0;
  149036. cinfo->raw_data_in = FALSE;
  149037. cinfo->arith_code = FALSE;
  149038. cinfo->optimize_coding = FALSE;
  149039. if (cinfo->data_precision > 8)
  149040. cinfo->optimize_coding = TRUE;
  149041. cinfo->CCIR601_sampling = FALSE;
  149042. cinfo->smoothing_factor = 0;
  149043. cinfo->dct_method = JDCT_DEFAULT;
  149044. cinfo->restart_interval = 0;
  149045. cinfo->restart_in_rows = 0;
  149046. cinfo->JFIF_major_version = 1; /* Default JFIF version = 1.01 */
  149047. cinfo->JFIF_minor_version = 1;
  149048. cinfo->density_unit = 0; /* Pixel size is unknown by default */
  149049. cinfo->X_density = 1; /* Pixel aspect ratio is square by default */
  149050. cinfo->Y_density = 1;
  149051. jpeg_default_colorspace(cinfo);
  149052. }
  149053. GLOBAL(void)
  149054. jpeg_default_colorspace (j_compress_ptr cinfo)
  149055. {
  149056. switch (cinfo->in_color_space) {
  149057. case JCS_GRAYSCALE:
  149058. jpeg_set_colorspace(cinfo, JCS_GRAYSCALE);
  149059. break;
  149060. case JCS_RGB:
  149061. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  149062. break;
  149063. case JCS_YCbCr:
  149064. jpeg_set_colorspace(cinfo, JCS_YCbCr);
  149065. break;
  149066. case JCS_CMYK:
  149067. jpeg_set_colorspace(cinfo, JCS_CMYK); /* By default, no translation */
  149068. break;
  149069. case JCS_YCCK:
  149070. jpeg_set_colorspace(cinfo, JCS_YCCK);
  149071. break;
  149072. case JCS_UNKNOWN:
  149073. jpeg_set_colorspace(cinfo, JCS_UNKNOWN);
  149074. break;
  149075. default:
  149076. ERREXIT(cinfo, JERR_BAD_IN_COLORSPACE);
  149077. }
  149078. }
  149079. GLOBAL(void)
  149080. jpeg_set_colorspace (j_compress_ptr cinfo, J_COLOR_SPACE colorspace)
  149081. {
  149082. jpeg_component_info * compptr;
  149083. int ci;
  149084. #define SET_COMP(index,id,hsamp,vsamp,quant,dctbl,actbl) \
  149085. (compptr = &cinfo->comp_info[index], \
  149086. compptr->component_id = (id), \
  149087. compptr->h_samp_factor = (hsamp), \
  149088. compptr->v_samp_factor = (vsamp), \
  149089. compptr->quant_tbl_no = (quant), \
  149090. compptr->dc_tbl_no = (dctbl), \
  149091. compptr->ac_tbl_no = (actbl) )
  149092. if (cinfo->global_state != CSTATE_START)
  149093. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149094. cinfo->jpeg_color_space = colorspace;
  149095. cinfo->write_JFIF_header = FALSE; /* No marker for non-JFIF colorspaces */
  149096. cinfo->write_Adobe_marker = FALSE; /* write no Adobe marker by default */
  149097. switch (colorspace) {
  149098. case JCS_GRAYSCALE:
  149099. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  149100. cinfo->num_components = 1;
  149101. SET_COMP(0, 1, 1,1, 0, 0,0);
  149102. break;
  149103. case JCS_RGB:
  149104. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag RGB */
  149105. cinfo->num_components = 3;
  149106. SET_COMP(0, 0x52 /* 'R' */, 1,1, 0, 0,0);
  149107. SET_COMP(1, 0x47 /* 'G' */, 1,1, 0, 0,0);
  149108. SET_COMP(2, 0x42 /* 'B' */, 1,1, 0, 0,0);
  149109. break;
  149110. case JCS_YCbCr:
  149111. cinfo->write_JFIF_header = TRUE; /* Write a JFIF marker */
  149112. cinfo->num_components = 3;
  149113. SET_COMP(0, 1, 2,2, 0, 0,0);
  149114. SET_COMP(1, 2, 1,1, 1, 1,1);
  149115. SET_COMP(2, 3, 1,1, 1, 1,1);
  149116. break;
  149117. case JCS_CMYK:
  149118. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag CMYK */
  149119. cinfo->num_components = 4;
  149120. SET_COMP(0, 0x43 /* 'C' */, 1,1, 0, 0,0);
  149121. SET_COMP(1, 0x4D /* 'M' */, 1,1, 0, 0,0);
  149122. SET_COMP(2, 0x59 /* 'Y' */, 1,1, 0, 0,0);
  149123. SET_COMP(3, 0x4B /* 'K' */, 1,1, 0, 0,0);
  149124. break;
  149125. case JCS_YCCK:
  149126. cinfo->write_Adobe_marker = TRUE; /* write Adobe marker to flag YCCK */
  149127. cinfo->num_components = 4;
  149128. SET_COMP(0, 1, 2,2, 0, 0,0);
  149129. SET_COMP(1, 2, 1,1, 1, 1,1);
  149130. SET_COMP(2, 3, 1,1, 1, 1,1);
  149131. SET_COMP(3, 4, 2,2, 0, 0,0);
  149132. break;
  149133. case JCS_UNKNOWN:
  149134. cinfo->num_components = cinfo->input_components;
  149135. if (cinfo->num_components < 1 || cinfo->num_components > MAX_COMPONENTS)
  149136. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  149137. MAX_COMPONENTS);
  149138. for (ci = 0; ci < cinfo->num_components; ci++) {
  149139. SET_COMP(ci, ci, 1,1, 0, 0,0);
  149140. }
  149141. break;
  149142. default:
  149143. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  149144. }
  149145. }
  149146. #ifdef C_PROGRESSIVE_SUPPORTED
  149147. LOCAL(jpeg_scan_info *)
  149148. fill_a_scan (jpeg_scan_info * scanptr, int ci,
  149149. int Ss, int Se, int Ah, int Al)
  149150. {
  149151. scanptr->comps_in_scan = 1;
  149152. scanptr->component_index[0] = ci;
  149153. scanptr->Ss = Ss;
  149154. scanptr->Se = Se;
  149155. scanptr->Ah = Ah;
  149156. scanptr->Al = Al;
  149157. scanptr++;
  149158. return scanptr;
  149159. }
  149160. LOCAL(jpeg_scan_info *)
  149161. fill_scans (jpeg_scan_info * scanptr, int ncomps,
  149162. int Ss, int Se, int Ah, int Al)
  149163. {
  149164. int ci;
  149165. for (ci = 0; ci < ncomps; ci++) {
  149166. scanptr->comps_in_scan = 1;
  149167. scanptr->component_index[0] = ci;
  149168. scanptr->Ss = Ss;
  149169. scanptr->Se = Se;
  149170. scanptr->Ah = Ah;
  149171. scanptr->Al = Al;
  149172. scanptr++;
  149173. }
  149174. return scanptr;
  149175. }
  149176. LOCAL(jpeg_scan_info *)
  149177. fill_dc_scans (jpeg_scan_info * scanptr, int ncomps, int Ah, int Al)
  149178. {
  149179. int ci;
  149180. if (ncomps <= MAX_COMPS_IN_SCAN) {
  149181. scanptr->comps_in_scan = ncomps;
  149182. for (ci = 0; ci < ncomps; ci++)
  149183. scanptr->component_index[ci] = ci;
  149184. scanptr->Ss = scanptr->Se = 0;
  149185. scanptr->Ah = Ah;
  149186. scanptr->Al = Al;
  149187. scanptr++;
  149188. } else {
  149189. scanptr = fill_scans(scanptr, ncomps, 0, 0, Ah, Al);
  149190. }
  149191. return scanptr;
  149192. }
  149193. GLOBAL(void)
  149194. jpeg_simple_progression (j_compress_ptr cinfo)
  149195. {
  149196. int ncomps = cinfo->num_components;
  149197. int nscans;
  149198. jpeg_scan_info * scanptr;
  149199. if (cinfo->global_state != CSTATE_START)
  149200. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  149201. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  149202. nscans = 10;
  149203. } else {
  149204. if (ncomps > MAX_COMPS_IN_SCAN)
  149205. nscans = 6 * ncomps; /* 2 DC + 4 AC scans per component */
  149206. else
  149207. nscans = 2 + 4 * ncomps; /* 2 DC scans; 4 AC scans per component */
  149208. }
  149209. if (cinfo->script_space == NULL || cinfo->script_space_size < nscans) {
  149210. cinfo->script_space_size = MAX(nscans, 10);
  149211. cinfo->script_space = (jpeg_scan_info *)
  149212. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  149213. cinfo->script_space_size * SIZEOF(jpeg_scan_info));
  149214. }
  149215. scanptr = cinfo->script_space;
  149216. cinfo->scan_info = scanptr;
  149217. cinfo->num_scans = nscans;
  149218. if (ncomps == 3 && cinfo->jpeg_color_space == JCS_YCbCr) {
  149219. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  149220. scanptr = fill_a_scan(scanptr, 0, 1, 5, 0, 2);
  149221. scanptr = fill_a_scan(scanptr, 2, 1, 63, 0, 1);
  149222. scanptr = fill_a_scan(scanptr, 1, 1, 63, 0, 1);
  149223. scanptr = fill_a_scan(scanptr, 0, 6, 63, 0, 2);
  149224. scanptr = fill_a_scan(scanptr, 0, 1, 63, 2, 1);
  149225. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  149226. scanptr = fill_a_scan(scanptr, 2, 1, 63, 1, 0);
  149227. scanptr = fill_a_scan(scanptr, 1, 1, 63, 1, 0);
  149228. scanptr = fill_a_scan(scanptr, 0, 1, 63, 1, 0);
  149229. } else {
  149230. scanptr = fill_dc_scans(scanptr, ncomps, 0, 1);
  149231. scanptr = fill_scans(scanptr, ncomps, 1, 5, 0, 2);
  149232. scanptr = fill_scans(scanptr, ncomps, 6, 63, 0, 2);
  149233. scanptr = fill_scans(scanptr, ncomps, 1, 63, 2, 1);
  149234. scanptr = fill_dc_scans(scanptr, ncomps, 1, 0);
  149235. scanptr = fill_scans(scanptr, ncomps, 1, 63, 1, 0);
  149236. }
  149237. }
  149238. #endif /* C_PROGRESSIVE_SUPPORTED */
  149239. /*** End of inlined file: jcparam.c ***/
  149240. /*** Start of inlined file: jcphuff.c ***/
  149241. #define JPEG_INTERNALS
  149242. #ifdef C_PROGRESSIVE_SUPPORTED
  149243. typedef struct {
  149244. struct jpeg_entropy_encoder pub; /* public fields */
  149245. boolean gather_statistics;
  149246. JOCTET * next_output_byte; /* => next byte to write in buffer */
  149247. size_t free_in_buffer; /* # of byte spaces remaining in buffer */
  149248. INT32 put_buffer; /* current bit-accumulation buffer */
  149249. int put_bits; /* # of bits now in it */
  149250. j_compress_ptr cinfo; /* link to cinfo (needed for dump_buffer) */
  149251. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  149252. int ac_tbl_no; /* the table number of the single component */
  149253. unsigned int EOBRUN; /* run length of EOBs */
  149254. unsigned int BE; /* # of buffered correction bits before MCU */
  149255. char * bit_buffer; /* buffer for correction bits (1 per char) */
  149256. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  149257. int next_restart_num; /* next restart number to write (0-7) */
  149258. c_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  149259. long * count_ptrs[NUM_HUFF_TBLS];
  149260. } phuff_entropy_encoder;
  149261. typedef phuff_entropy_encoder * phuff_entropy_ptr;
  149262. #define MAX_CORR_BITS 1000 /* Max # of correction bits I can buffer */
  149263. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  149264. #define ISHIFT_TEMPS int ishift_temp;
  149265. #define IRIGHT_SHIFT(x,shft) \
  149266. ((ishift_temp = (x)) < 0 ? \
  149267. (ishift_temp >> (shft)) | ((~0) << (16-(shft))) : \
  149268. (ishift_temp >> (shft)))
  149269. #else
  149270. #define ISHIFT_TEMPS
  149271. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  149272. #endif
  149273. METHODDEF(boolean) encode_mcu_DC_first JPP((j_compress_ptr cinfo,
  149274. JBLOCKROW *MCU_data));
  149275. METHODDEF(boolean) encode_mcu_AC_first JPP((j_compress_ptr cinfo,
  149276. JBLOCKROW *MCU_data));
  149277. METHODDEF(boolean) encode_mcu_DC_refine JPP((j_compress_ptr cinfo,
  149278. JBLOCKROW *MCU_data));
  149279. METHODDEF(boolean) encode_mcu_AC_refine JPP((j_compress_ptr cinfo,
  149280. JBLOCKROW *MCU_data));
  149281. METHODDEF(void) finish_pass_phuff JPP((j_compress_ptr cinfo));
  149282. METHODDEF(void) finish_pass_gather_phuff JPP((j_compress_ptr cinfo));
  149283. METHODDEF(void)
  149284. start_pass_phuff (j_compress_ptr cinfo, boolean gather_statistics)
  149285. {
  149286. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149287. boolean is_DC_band;
  149288. int ci, tbl;
  149289. jpeg_component_info * compptr;
  149290. entropy->cinfo = cinfo;
  149291. entropy->gather_statistics = gather_statistics;
  149292. is_DC_band = (cinfo->Ss == 0);
  149293. if (cinfo->Ah == 0) {
  149294. if (is_DC_band)
  149295. entropy->pub.encode_mcu = encode_mcu_DC_first;
  149296. else
  149297. entropy->pub.encode_mcu = encode_mcu_AC_first;
  149298. } else {
  149299. if (is_DC_band)
  149300. entropy->pub.encode_mcu = encode_mcu_DC_refine;
  149301. else {
  149302. entropy->pub.encode_mcu = encode_mcu_AC_refine;
  149303. if (entropy->bit_buffer == NULL)
  149304. entropy->bit_buffer = (char *)
  149305. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149306. MAX_CORR_BITS * SIZEOF(char));
  149307. }
  149308. }
  149309. if (gather_statistics)
  149310. entropy->pub.finish_pass = finish_pass_gather_phuff;
  149311. else
  149312. entropy->pub.finish_pass = finish_pass_phuff;
  149313. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149314. compptr = cinfo->cur_comp_info[ci];
  149315. entropy->last_dc_val[ci] = 0;
  149316. if (is_DC_band) {
  149317. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149318. continue;
  149319. tbl = compptr->dc_tbl_no;
  149320. } else {
  149321. entropy->ac_tbl_no = tbl = compptr->ac_tbl_no;
  149322. }
  149323. if (gather_statistics) {
  149324. if (tbl < 0 || tbl >= NUM_HUFF_TBLS)
  149325. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tbl);
  149326. if (entropy->count_ptrs[tbl] == NULL)
  149327. entropy->count_ptrs[tbl] = (long *)
  149328. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149329. 257 * SIZEOF(long));
  149330. MEMZERO(entropy->count_ptrs[tbl], 257 * SIZEOF(long));
  149331. } else {
  149332. jpeg_make_c_derived_tbl(cinfo, is_DC_band, tbl,
  149333. & entropy->derived_tbls[tbl]);
  149334. }
  149335. }
  149336. entropy->EOBRUN = 0;
  149337. entropy->BE = 0;
  149338. entropy->put_buffer = 0;
  149339. entropy->put_bits = 0;
  149340. entropy->restarts_to_go = cinfo->restart_interval;
  149341. entropy->next_restart_num = 0;
  149342. }
  149343. #define emit_byte(entropy,val) \
  149344. { *(entropy)->next_output_byte++ = (JOCTET) (val); \
  149345. if (--(entropy)->free_in_buffer == 0) \
  149346. dump_buffer_p(entropy); }
  149347. LOCAL(void)
  149348. dump_buffer_p (phuff_entropy_ptr entropy)
  149349. {
  149350. struct jpeg_destination_mgr * dest = entropy->cinfo->dest;
  149351. if (! (*dest->empty_output_buffer) (entropy->cinfo))
  149352. ERREXIT(entropy->cinfo, JERR_CANT_SUSPEND);
  149353. entropy->next_output_byte = dest->next_output_byte;
  149354. entropy->free_in_buffer = dest->free_in_buffer;
  149355. }
  149356. INLINE
  149357. LOCAL(void)
  149358. emit_bits_p (phuff_entropy_ptr entropy, unsigned int code, int size)
  149359. {
  149360. register INT32 put_buffer = (INT32) code;
  149361. register int put_bits = entropy->put_bits;
  149362. if (size == 0)
  149363. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149364. if (entropy->gather_statistics)
  149365. return; /* do nothing if we're only getting stats */
  149366. put_buffer &= (((INT32) 1)<<size) - 1; /* mask off any extra bits in code */
  149367. put_bits += size; /* new number of bits in buffer */
  149368. put_buffer <<= 24 - put_bits; /* align incoming bits */
  149369. put_buffer |= entropy->put_buffer; /* and merge with old buffer contents */
  149370. while (put_bits >= 8) {
  149371. int c = (int) ((put_buffer >> 16) & 0xFF);
  149372. emit_byte(entropy, c);
  149373. if (c == 0xFF) { /* need to stuff a zero byte? */
  149374. emit_byte(entropy, 0);
  149375. }
  149376. put_buffer <<= 8;
  149377. put_bits -= 8;
  149378. }
  149379. entropy->put_buffer = put_buffer; /* update variables */
  149380. entropy->put_bits = put_bits;
  149381. }
  149382. LOCAL(void)
  149383. flush_bits_p (phuff_entropy_ptr entropy)
  149384. {
  149385. emit_bits_p(entropy, 0x7F, 7); /* fill any partial byte with ones */
  149386. entropy->put_buffer = 0; /* and reset bit-buffer to empty */
  149387. entropy->put_bits = 0;
  149388. }
  149389. INLINE
  149390. LOCAL(void)
  149391. emit_symbol (phuff_entropy_ptr entropy, int tbl_no, int symbol)
  149392. {
  149393. if (entropy->gather_statistics)
  149394. entropy->count_ptrs[tbl_no][symbol]++;
  149395. else {
  149396. c_derived_tbl * tbl = entropy->derived_tbls[tbl_no];
  149397. emit_bits_p(entropy, tbl->ehufco[symbol], tbl->ehufsi[symbol]);
  149398. }
  149399. }
  149400. LOCAL(void)
  149401. emit_buffered_bits (phuff_entropy_ptr entropy, char * bufstart,
  149402. unsigned int nbits)
  149403. {
  149404. if (entropy->gather_statistics)
  149405. return; /* no real work */
  149406. while (nbits > 0) {
  149407. emit_bits_p(entropy, (unsigned int) (*bufstart), 1);
  149408. bufstart++;
  149409. nbits--;
  149410. }
  149411. }
  149412. LOCAL(void)
  149413. emit_eobrun (phuff_entropy_ptr entropy)
  149414. {
  149415. register int temp, nbits;
  149416. if (entropy->EOBRUN > 0) { /* if there is any pending EOBRUN */
  149417. temp = entropy->EOBRUN;
  149418. nbits = 0;
  149419. while ((temp >>= 1))
  149420. nbits++;
  149421. if (nbits > 14)
  149422. ERREXIT(entropy->cinfo, JERR_HUFF_MISSING_CODE);
  149423. emit_symbol(entropy, entropy->ac_tbl_no, nbits << 4);
  149424. if (nbits)
  149425. emit_bits_p(entropy, entropy->EOBRUN, nbits);
  149426. entropy->EOBRUN = 0;
  149427. emit_buffered_bits(entropy, entropy->bit_buffer, entropy->BE);
  149428. entropy->BE = 0;
  149429. }
  149430. }
  149431. LOCAL(void)
  149432. emit_restart_p (phuff_entropy_ptr entropy, int restart_num)
  149433. {
  149434. int ci;
  149435. emit_eobrun(entropy);
  149436. if (! entropy->gather_statistics) {
  149437. flush_bits_p(entropy);
  149438. emit_byte(entropy, 0xFF);
  149439. emit_byte(entropy, JPEG_RST0 + restart_num);
  149440. }
  149441. if (entropy->cinfo->Ss == 0) {
  149442. for (ci = 0; ci < entropy->cinfo->comps_in_scan; ci++)
  149443. entropy->last_dc_val[ci] = 0;
  149444. } else {
  149445. entropy->EOBRUN = 0;
  149446. entropy->BE = 0;
  149447. }
  149448. }
  149449. METHODDEF(boolean)
  149450. encode_mcu_DC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149451. {
  149452. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149453. register int temp, temp2;
  149454. register int nbits;
  149455. int blkn, ci;
  149456. int Al = cinfo->Al;
  149457. JBLOCKROW block;
  149458. jpeg_component_info * compptr;
  149459. ISHIFT_TEMPS
  149460. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149461. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149462. if (cinfo->restart_interval)
  149463. if (entropy->restarts_to_go == 0)
  149464. emit_restart_p(entropy, entropy->next_restart_num);
  149465. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149466. block = MCU_data[blkn];
  149467. ci = cinfo->MCU_membership[blkn];
  149468. compptr = cinfo->cur_comp_info[ci];
  149469. temp2 = IRIGHT_SHIFT((int) ((*block)[0]), Al);
  149470. temp = temp2 - entropy->last_dc_val[ci];
  149471. entropy->last_dc_val[ci] = temp2;
  149472. temp2 = temp;
  149473. if (temp < 0) {
  149474. temp = -temp; /* temp is abs value of input */
  149475. temp2--;
  149476. }
  149477. nbits = 0;
  149478. while (temp) {
  149479. nbits++;
  149480. temp >>= 1;
  149481. }
  149482. if (nbits > MAX_COEF_BITS+1)
  149483. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149484. emit_symbol(entropy, compptr->dc_tbl_no, nbits);
  149485. if (nbits) /* emit_bits rejects calls with size 0 */
  149486. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149487. }
  149488. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149489. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149490. if (cinfo->restart_interval) {
  149491. if (entropy->restarts_to_go == 0) {
  149492. entropy->restarts_to_go = cinfo->restart_interval;
  149493. entropy->next_restart_num++;
  149494. entropy->next_restart_num &= 7;
  149495. }
  149496. entropy->restarts_to_go--;
  149497. }
  149498. return TRUE;
  149499. }
  149500. METHODDEF(boolean)
  149501. encode_mcu_AC_first (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149502. {
  149503. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149504. register int temp, temp2;
  149505. register int nbits;
  149506. register int r, k;
  149507. int Se = cinfo->Se;
  149508. int Al = cinfo->Al;
  149509. JBLOCKROW block;
  149510. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149511. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149512. if (cinfo->restart_interval)
  149513. if (entropy->restarts_to_go == 0)
  149514. emit_restart_p(entropy, entropy->next_restart_num);
  149515. block = MCU_data[0];
  149516. r = 0; /* r = run length of zeros */
  149517. for (k = cinfo->Ss; k <= Se; k++) {
  149518. if ((temp = (*block)[jpeg_natural_order[k]]) == 0) {
  149519. r++;
  149520. continue;
  149521. }
  149522. if (temp < 0) {
  149523. temp = -temp; /* temp is abs value of input */
  149524. temp >>= Al; /* apply the point transform */
  149525. temp2 = ~temp;
  149526. } else {
  149527. temp >>= Al; /* apply the point transform */
  149528. temp2 = temp;
  149529. }
  149530. if (temp == 0) {
  149531. r++;
  149532. continue;
  149533. }
  149534. if (entropy->EOBRUN > 0)
  149535. emit_eobrun(entropy);
  149536. while (r > 15) {
  149537. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149538. r -= 16;
  149539. }
  149540. nbits = 1; /* there must be at least one 1 bit */
  149541. while ((temp >>= 1))
  149542. nbits++;
  149543. if (nbits > MAX_COEF_BITS)
  149544. ERREXIT(cinfo, JERR_BAD_DCT_COEF);
  149545. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + nbits);
  149546. emit_bits_p(entropy, (unsigned int) temp2, nbits);
  149547. r = 0; /* reset zero run length */
  149548. }
  149549. if (r > 0) { /* If there are trailing zeroes, */
  149550. entropy->EOBRUN++; /* count an EOB */
  149551. if (entropy->EOBRUN == 0x7FFF)
  149552. emit_eobrun(entropy); /* force it out to avoid overflow */
  149553. }
  149554. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149555. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149556. if (cinfo->restart_interval) {
  149557. if (entropy->restarts_to_go == 0) {
  149558. entropy->restarts_to_go = cinfo->restart_interval;
  149559. entropy->next_restart_num++;
  149560. entropy->next_restart_num &= 7;
  149561. }
  149562. entropy->restarts_to_go--;
  149563. }
  149564. return TRUE;
  149565. }
  149566. METHODDEF(boolean)
  149567. encode_mcu_DC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149568. {
  149569. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149570. register int temp;
  149571. int blkn;
  149572. int Al = cinfo->Al;
  149573. JBLOCKROW block;
  149574. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149575. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149576. if (cinfo->restart_interval)
  149577. if (entropy->restarts_to_go == 0)
  149578. emit_restart_p(entropy, entropy->next_restart_num);
  149579. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  149580. block = MCU_data[blkn];
  149581. temp = (*block)[0];
  149582. emit_bits_p(entropy, (unsigned int) (temp >> Al), 1);
  149583. }
  149584. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149585. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149586. if (cinfo->restart_interval) {
  149587. if (entropy->restarts_to_go == 0) {
  149588. entropy->restarts_to_go = cinfo->restart_interval;
  149589. entropy->next_restart_num++;
  149590. entropy->next_restart_num &= 7;
  149591. }
  149592. entropy->restarts_to_go--;
  149593. }
  149594. return TRUE;
  149595. }
  149596. METHODDEF(boolean)
  149597. encode_mcu_AC_refine (j_compress_ptr cinfo, JBLOCKROW *MCU_data)
  149598. {
  149599. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149600. register int temp;
  149601. register int r, k;
  149602. int EOB;
  149603. char *BR_buffer;
  149604. unsigned int BR;
  149605. int Se = cinfo->Se;
  149606. int Al = cinfo->Al;
  149607. JBLOCKROW block;
  149608. int absvalues[DCTSIZE2];
  149609. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149610. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149611. if (cinfo->restart_interval)
  149612. if (entropy->restarts_to_go == 0)
  149613. emit_restart_p(entropy, entropy->next_restart_num);
  149614. block = MCU_data[0];
  149615. EOB = 0;
  149616. for (k = cinfo->Ss; k <= Se; k++) {
  149617. temp = (*block)[jpeg_natural_order[k]];
  149618. if (temp < 0)
  149619. temp = -temp; /* temp is abs value of input */
  149620. temp >>= Al; /* apply the point transform */
  149621. absvalues[k] = temp; /* save abs value for main pass */
  149622. if (temp == 1)
  149623. EOB = k; /* EOB = index of last newly-nonzero coef */
  149624. }
  149625. r = 0; /* r = run length of zeros */
  149626. BR = 0; /* BR = count of buffered bits added now */
  149627. BR_buffer = entropy->bit_buffer + entropy->BE; /* Append bits to buffer */
  149628. for (k = cinfo->Ss; k <= Se; k++) {
  149629. if ((temp = absvalues[k]) == 0) {
  149630. r++;
  149631. continue;
  149632. }
  149633. while (r > 15 && k <= EOB) {
  149634. emit_eobrun(entropy);
  149635. emit_symbol(entropy, entropy->ac_tbl_no, 0xF0);
  149636. r -= 16;
  149637. emit_buffered_bits(entropy, BR_buffer, BR);
  149638. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149639. BR = 0;
  149640. }
  149641. if (temp > 1) {
  149642. BR_buffer[BR++] = (char) (temp & 1);
  149643. continue;
  149644. }
  149645. emit_eobrun(entropy);
  149646. emit_symbol(entropy, entropy->ac_tbl_no, (r << 4) + 1);
  149647. temp = ((*block)[jpeg_natural_order[k]] < 0) ? 0 : 1;
  149648. emit_bits_p(entropy, (unsigned int) temp, 1);
  149649. emit_buffered_bits(entropy, BR_buffer, BR);
  149650. BR_buffer = entropy->bit_buffer; /* BE bits are gone now */
  149651. BR = 0;
  149652. r = 0; /* reset zero run length */
  149653. }
  149654. if (r > 0 || BR > 0) { /* If there are trailing zeroes, */
  149655. entropy->EOBRUN++; /* count an EOB */
  149656. entropy->BE += BR; /* concat my correction bits to older ones */
  149657. if (entropy->EOBRUN == 0x7FFF || entropy->BE > (MAX_CORR_BITS-DCTSIZE2+1))
  149658. emit_eobrun(entropy);
  149659. }
  149660. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149661. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149662. if (cinfo->restart_interval) {
  149663. if (entropy->restarts_to_go == 0) {
  149664. entropy->restarts_to_go = cinfo->restart_interval;
  149665. entropy->next_restart_num++;
  149666. entropy->next_restart_num &= 7;
  149667. }
  149668. entropy->restarts_to_go--;
  149669. }
  149670. return TRUE;
  149671. }
  149672. METHODDEF(void)
  149673. finish_pass_phuff (j_compress_ptr cinfo)
  149674. {
  149675. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149676. entropy->next_output_byte = cinfo->dest->next_output_byte;
  149677. entropy->free_in_buffer = cinfo->dest->free_in_buffer;
  149678. emit_eobrun(entropy);
  149679. flush_bits_p(entropy);
  149680. cinfo->dest->next_output_byte = entropy->next_output_byte;
  149681. cinfo->dest->free_in_buffer = entropy->free_in_buffer;
  149682. }
  149683. METHODDEF(void)
  149684. finish_pass_gather_phuff (j_compress_ptr cinfo)
  149685. {
  149686. phuff_entropy_ptr entropy = (phuff_entropy_ptr) cinfo->entropy;
  149687. boolean is_DC_band;
  149688. int ci, tbl;
  149689. jpeg_component_info * compptr;
  149690. JHUFF_TBL **htblptr;
  149691. boolean did[NUM_HUFF_TBLS];
  149692. emit_eobrun(entropy);
  149693. is_DC_band = (cinfo->Ss == 0);
  149694. MEMZERO(did, SIZEOF(did));
  149695. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  149696. compptr = cinfo->cur_comp_info[ci];
  149697. if (is_DC_band) {
  149698. if (cinfo->Ah != 0) /* DC refinement needs no table */
  149699. continue;
  149700. tbl = compptr->dc_tbl_no;
  149701. } else {
  149702. tbl = compptr->ac_tbl_no;
  149703. }
  149704. if (! did[tbl]) {
  149705. if (is_DC_band)
  149706. htblptr = & cinfo->dc_huff_tbl_ptrs[tbl];
  149707. else
  149708. htblptr = & cinfo->ac_huff_tbl_ptrs[tbl];
  149709. if (*htblptr == NULL)
  149710. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  149711. jpeg_gen_optimal_table(cinfo, *htblptr, entropy->count_ptrs[tbl]);
  149712. did[tbl] = TRUE;
  149713. }
  149714. }
  149715. }
  149716. GLOBAL(void)
  149717. jinit_phuff_encoder (j_compress_ptr cinfo)
  149718. {
  149719. phuff_entropy_ptr entropy;
  149720. int i;
  149721. entropy = (phuff_entropy_ptr)
  149722. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149723. SIZEOF(phuff_entropy_encoder));
  149724. cinfo->entropy = (struct jpeg_entropy_encoder *) entropy;
  149725. entropy->pub.start_pass = start_pass_phuff;
  149726. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  149727. entropy->derived_tbls[i] = NULL;
  149728. entropy->count_ptrs[i] = NULL;
  149729. }
  149730. entropy->bit_buffer = NULL; /* needed only in AC refinement scan */
  149731. }
  149732. #endif /* C_PROGRESSIVE_SUPPORTED */
  149733. /*** End of inlined file: jcphuff.c ***/
  149734. /*** Start of inlined file: jcprepct.c ***/
  149735. #define JPEG_INTERNALS
  149736. #ifdef INPUT_SMOOTHING_SUPPORTED
  149737. #define CONTEXT_ROWS_SUPPORTED
  149738. #endif
  149739. typedef struct {
  149740. struct jpeg_c_prep_controller pub; /* public fields */
  149741. JSAMPARRAY color_buf[MAX_COMPONENTS];
  149742. JDIMENSION rows_to_go; /* counts rows remaining in source image */
  149743. int next_buf_row; /* index of next row to store in color_buf */
  149744. #ifdef CONTEXT_ROWS_SUPPORTED /* only needed for context case */
  149745. int this_row_group; /* starting row index of group to process */
  149746. int next_buf_stop; /* downsample when we reach this index */
  149747. #endif
  149748. } my_prep_controller;
  149749. typedef my_prep_controller * my_prep_ptr;
  149750. METHODDEF(void)
  149751. start_pass_prep (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  149752. {
  149753. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149754. if (pass_mode != JBUF_PASS_THRU)
  149755. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149756. prep->rows_to_go = cinfo->image_height;
  149757. prep->next_buf_row = 0;
  149758. #ifdef CONTEXT_ROWS_SUPPORTED
  149759. prep->this_row_group = 0;
  149760. prep->next_buf_stop = 2 * cinfo->max_v_samp_factor;
  149761. #endif
  149762. }
  149763. LOCAL(void)
  149764. expand_bottom_edge (JSAMPARRAY image_data, JDIMENSION num_cols,
  149765. int input_rows, int output_rows)
  149766. {
  149767. register int row;
  149768. for (row = input_rows; row < output_rows; row++) {
  149769. jcopy_sample_rows(image_data, input_rows-1, image_data, row,
  149770. 1, num_cols);
  149771. }
  149772. }
  149773. METHODDEF(void)
  149774. pre_process_data (j_compress_ptr cinfo,
  149775. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149776. JDIMENSION in_rows_avail,
  149777. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149778. JDIMENSION out_row_groups_avail)
  149779. {
  149780. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149781. int numrows, ci;
  149782. JDIMENSION inrows;
  149783. jpeg_component_info * compptr;
  149784. while (*in_row_ctr < in_rows_avail &&
  149785. *out_row_group_ctr < out_row_groups_avail) {
  149786. inrows = in_rows_avail - *in_row_ctr;
  149787. numrows = cinfo->max_v_samp_factor - prep->next_buf_row;
  149788. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149789. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149790. prep->color_buf,
  149791. (JDIMENSION) prep->next_buf_row,
  149792. numrows);
  149793. *in_row_ctr += numrows;
  149794. prep->next_buf_row += numrows;
  149795. prep->rows_to_go -= numrows;
  149796. if (prep->rows_to_go == 0 &&
  149797. prep->next_buf_row < cinfo->max_v_samp_factor) {
  149798. for (ci = 0; ci < cinfo->num_components; ci++) {
  149799. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149800. prep->next_buf_row, cinfo->max_v_samp_factor);
  149801. }
  149802. prep->next_buf_row = cinfo->max_v_samp_factor;
  149803. }
  149804. if (prep->next_buf_row == cinfo->max_v_samp_factor) {
  149805. (*cinfo->downsample->downsample) (cinfo,
  149806. prep->color_buf, (JDIMENSION) 0,
  149807. output_buf, *out_row_group_ctr);
  149808. prep->next_buf_row = 0;
  149809. (*out_row_group_ctr)++;
  149810. }
  149811. if (prep->rows_to_go == 0 &&
  149812. *out_row_group_ctr < out_row_groups_avail) {
  149813. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149814. ci++, compptr++) {
  149815. expand_bottom_edge(output_buf[ci],
  149816. compptr->width_in_blocks * DCTSIZE,
  149817. (int) (*out_row_group_ctr * compptr->v_samp_factor),
  149818. (int) (out_row_groups_avail * compptr->v_samp_factor));
  149819. }
  149820. *out_row_group_ctr = out_row_groups_avail;
  149821. break; /* can exit outer loop without test */
  149822. }
  149823. }
  149824. }
  149825. #ifdef CONTEXT_ROWS_SUPPORTED
  149826. METHODDEF(void)
  149827. pre_process_context (j_compress_ptr cinfo,
  149828. JSAMPARRAY input_buf, JDIMENSION *in_row_ctr,
  149829. JDIMENSION in_rows_avail,
  149830. JSAMPIMAGE output_buf, JDIMENSION *out_row_group_ctr,
  149831. JDIMENSION out_row_groups_avail)
  149832. {
  149833. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149834. int numrows, ci;
  149835. int buf_height = cinfo->max_v_samp_factor * 3;
  149836. JDIMENSION inrows;
  149837. while (*out_row_group_ctr < out_row_groups_avail) {
  149838. if (*in_row_ctr < in_rows_avail) {
  149839. inrows = in_rows_avail - *in_row_ctr;
  149840. numrows = prep->next_buf_stop - prep->next_buf_row;
  149841. numrows = (int) MIN((JDIMENSION) numrows, inrows);
  149842. (*cinfo->cconvert->color_convert) (cinfo, input_buf + *in_row_ctr,
  149843. prep->color_buf,
  149844. (JDIMENSION) prep->next_buf_row,
  149845. numrows);
  149846. if (prep->rows_to_go == cinfo->image_height) {
  149847. for (ci = 0; ci < cinfo->num_components; ci++) {
  149848. int row;
  149849. for (row = 1; row <= cinfo->max_v_samp_factor; row++) {
  149850. jcopy_sample_rows(prep->color_buf[ci], 0,
  149851. prep->color_buf[ci], -row,
  149852. 1, cinfo->image_width);
  149853. }
  149854. }
  149855. }
  149856. *in_row_ctr += numrows;
  149857. prep->next_buf_row += numrows;
  149858. prep->rows_to_go -= numrows;
  149859. } else {
  149860. if (prep->rows_to_go != 0)
  149861. break;
  149862. if (prep->next_buf_row < prep->next_buf_stop) {
  149863. for (ci = 0; ci < cinfo->num_components; ci++) {
  149864. expand_bottom_edge(prep->color_buf[ci], cinfo->image_width,
  149865. prep->next_buf_row, prep->next_buf_stop);
  149866. }
  149867. prep->next_buf_row = prep->next_buf_stop;
  149868. }
  149869. }
  149870. if (prep->next_buf_row == prep->next_buf_stop) {
  149871. (*cinfo->downsample->downsample) (cinfo,
  149872. prep->color_buf,
  149873. (JDIMENSION) prep->this_row_group,
  149874. output_buf, *out_row_group_ctr);
  149875. (*out_row_group_ctr)++;
  149876. prep->this_row_group += cinfo->max_v_samp_factor;
  149877. if (prep->this_row_group >= buf_height)
  149878. prep->this_row_group = 0;
  149879. if (prep->next_buf_row >= buf_height)
  149880. prep->next_buf_row = 0;
  149881. prep->next_buf_stop = prep->next_buf_row + cinfo->max_v_samp_factor;
  149882. }
  149883. }
  149884. }
  149885. LOCAL(void)
  149886. create_context_buffer (j_compress_ptr cinfo)
  149887. {
  149888. my_prep_ptr prep = (my_prep_ptr) cinfo->prep;
  149889. int rgroup_height = cinfo->max_v_samp_factor;
  149890. int ci, i;
  149891. jpeg_component_info * compptr;
  149892. JSAMPARRAY true_buffer, fake_buffer;
  149893. fake_buffer = (JSAMPARRAY)
  149894. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149895. (cinfo->num_components * 5 * rgroup_height) *
  149896. SIZEOF(JSAMPROW));
  149897. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149898. ci++, compptr++) {
  149899. true_buffer = (*cinfo->mem->alloc_sarray)
  149900. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149901. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149902. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149903. (JDIMENSION) (3 * rgroup_height));
  149904. MEMCOPY(fake_buffer + rgroup_height, true_buffer,
  149905. 3 * rgroup_height * SIZEOF(JSAMPROW));
  149906. for (i = 0; i < rgroup_height; i++) {
  149907. fake_buffer[i] = true_buffer[2 * rgroup_height + i];
  149908. fake_buffer[4 * rgroup_height + i] = true_buffer[i];
  149909. }
  149910. prep->color_buf[ci] = fake_buffer + rgroup_height;
  149911. fake_buffer += 5 * rgroup_height; /* point to space for next component */
  149912. }
  149913. }
  149914. #endif /* CONTEXT_ROWS_SUPPORTED */
  149915. GLOBAL(void)
  149916. jinit_c_prep_controller (j_compress_ptr cinfo, boolean need_full_buffer)
  149917. {
  149918. my_prep_ptr prep;
  149919. int ci;
  149920. jpeg_component_info * compptr;
  149921. if (need_full_buffer) /* safety check */
  149922. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  149923. prep = (my_prep_ptr)
  149924. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149925. SIZEOF(my_prep_controller));
  149926. cinfo->prep = (struct jpeg_c_prep_controller *) prep;
  149927. prep->pub.start_pass = start_pass_prep;
  149928. if (cinfo->downsample->need_context_rows) {
  149929. #ifdef CONTEXT_ROWS_SUPPORTED
  149930. prep->pub.pre_process_data = pre_process_context;
  149931. create_context_buffer(cinfo);
  149932. #else
  149933. ERREXIT(cinfo, JERR_NOT_COMPILED);
  149934. #endif
  149935. } else {
  149936. prep->pub.pre_process_data = pre_process_data;
  149937. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149938. ci++, compptr++) {
  149939. prep->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  149940. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  149941. (JDIMENSION) (((long) compptr->width_in_blocks * DCTSIZE *
  149942. cinfo->max_h_samp_factor) / compptr->h_samp_factor),
  149943. (JDIMENSION) cinfo->max_v_samp_factor);
  149944. }
  149945. }
  149946. }
  149947. /*** End of inlined file: jcprepct.c ***/
  149948. /*** Start of inlined file: jcsample.c ***/
  149949. #define JPEG_INTERNALS
  149950. typedef JMETHOD(void, downsample1_ptr,
  149951. (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149952. JSAMPARRAY input_data, JSAMPARRAY output_data));
  149953. typedef struct {
  149954. struct jpeg_downsampler pub; /* public fields */
  149955. downsample1_ptr methods[MAX_COMPONENTS];
  149956. } my_downsampler;
  149957. typedef my_downsampler * my_downsample_ptr;
  149958. METHODDEF(void)
  149959. start_pass_downsample (j_compress_ptr cinfo)
  149960. {
  149961. }
  149962. LOCAL(void)
  149963. expand_right_edge (JSAMPARRAY image_data, int num_rows,
  149964. JDIMENSION input_cols, JDIMENSION output_cols)
  149965. {
  149966. register JSAMPROW ptr;
  149967. register JSAMPLE pixval;
  149968. register int count;
  149969. int row;
  149970. int numcols = (int) (output_cols - input_cols);
  149971. if (numcols > 0) {
  149972. for (row = 0; row < num_rows; row++) {
  149973. ptr = image_data[row] + input_cols;
  149974. pixval = ptr[-1]; /* don't need GETJSAMPLE() here */
  149975. for (count = numcols; count > 0; count--)
  149976. *ptr++ = pixval;
  149977. }
  149978. }
  149979. }
  149980. METHODDEF(void)
  149981. sep_downsample (j_compress_ptr cinfo,
  149982. JSAMPIMAGE input_buf, JDIMENSION in_row_index,
  149983. JSAMPIMAGE output_buf, JDIMENSION out_row_group_index)
  149984. {
  149985. my_downsample_ptr downsample = (my_downsample_ptr) cinfo->downsample;
  149986. int ci;
  149987. jpeg_component_info * compptr;
  149988. JSAMPARRAY in_ptr, out_ptr;
  149989. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  149990. ci++, compptr++) {
  149991. in_ptr = input_buf[ci] + in_row_index;
  149992. out_ptr = output_buf[ci] + (out_row_group_index * compptr->v_samp_factor);
  149993. (*downsample->methods[ci]) (cinfo, compptr, in_ptr, out_ptr);
  149994. }
  149995. }
  149996. METHODDEF(void)
  149997. int_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  149998. JSAMPARRAY input_data, JSAMPARRAY output_data)
  149999. {
  150000. int inrow, outrow, h_expand, v_expand, numpix, numpix2, h, v;
  150001. JDIMENSION outcol, outcol_h; /* outcol_h == outcol*h_expand */
  150002. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150003. JSAMPROW inptr, outptr;
  150004. INT32 outvalue;
  150005. h_expand = cinfo->max_h_samp_factor / compptr->h_samp_factor;
  150006. v_expand = cinfo->max_v_samp_factor / compptr->v_samp_factor;
  150007. numpix = h_expand * v_expand;
  150008. numpix2 = numpix/2;
  150009. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150010. cinfo->image_width, output_cols * h_expand);
  150011. inrow = 0;
  150012. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150013. outptr = output_data[outrow];
  150014. for (outcol = 0, outcol_h = 0; outcol < output_cols;
  150015. outcol++, outcol_h += h_expand) {
  150016. outvalue = 0;
  150017. for (v = 0; v < v_expand; v++) {
  150018. inptr = input_data[inrow+v] + outcol_h;
  150019. for (h = 0; h < h_expand; h++) {
  150020. outvalue += (INT32) GETJSAMPLE(*inptr++);
  150021. }
  150022. }
  150023. *outptr++ = (JSAMPLE) ((outvalue + numpix2) / numpix);
  150024. }
  150025. inrow += v_expand;
  150026. }
  150027. }
  150028. METHODDEF(void)
  150029. fullsize_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150030. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150031. {
  150032. jcopy_sample_rows(input_data, 0, output_data, 0,
  150033. cinfo->max_v_samp_factor, cinfo->image_width);
  150034. expand_right_edge(output_data, cinfo->max_v_samp_factor,
  150035. cinfo->image_width, compptr->width_in_blocks * DCTSIZE);
  150036. }
  150037. METHODDEF(void)
  150038. h2v1_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150039. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150040. {
  150041. int outrow;
  150042. JDIMENSION outcol;
  150043. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150044. register JSAMPROW inptr, outptr;
  150045. register int bias;
  150046. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150047. cinfo->image_width, output_cols * 2);
  150048. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150049. outptr = output_data[outrow];
  150050. inptr = input_data[outrow];
  150051. bias = 0; /* bias = 0,1,0,1,... for successive samples */
  150052. for (outcol = 0; outcol < output_cols; outcol++) {
  150053. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr) + GETJSAMPLE(inptr[1])
  150054. + bias) >> 1);
  150055. bias ^= 1; /* 0=>1, 1=>0 */
  150056. inptr += 2;
  150057. }
  150058. }
  150059. }
  150060. METHODDEF(void)
  150061. h2v2_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150062. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150063. {
  150064. int inrow, outrow;
  150065. JDIMENSION outcol;
  150066. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150067. register JSAMPROW inptr0, inptr1, outptr;
  150068. register int bias;
  150069. expand_right_edge(input_data, cinfo->max_v_samp_factor,
  150070. cinfo->image_width, output_cols * 2);
  150071. inrow = 0;
  150072. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150073. outptr = output_data[outrow];
  150074. inptr0 = input_data[inrow];
  150075. inptr1 = input_data[inrow+1];
  150076. bias = 1; /* bias = 1,2,1,2,... for successive samples */
  150077. for (outcol = 0; outcol < output_cols; outcol++) {
  150078. *outptr++ = (JSAMPLE) ((GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150079. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1])
  150080. + bias) >> 2);
  150081. bias ^= 3; /* 1=>2, 2=>1 */
  150082. inptr0 += 2; inptr1 += 2;
  150083. }
  150084. inrow += 2;
  150085. }
  150086. }
  150087. #ifdef INPUT_SMOOTHING_SUPPORTED
  150088. METHODDEF(void)
  150089. h2v2_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info * compptr,
  150090. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150091. {
  150092. int inrow, outrow;
  150093. JDIMENSION colctr;
  150094. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150095. register JSAMPROW inptr0, inptr1, above_ptr, below_ptr, outptr;
  150096. INT32 membersum, neighsum, memberscale, neighscale;
  150097. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  150098. cinfo->image_width, output_cols * 2);
  150099. memberscale = 16384 - cinfo->smoothing_factor * 80; /* scaled (1-5*SF)/4 */
  150100. neighscale = cinfo->smoothing_factor * 16; /* scaled SF/4 */
  150101. inrow = 0;
  150102. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150103. outptr = output_data[outrow];
  150104. inptr0 = input_data[inrow];
  150105. inptr1 = input_data[inrow+1];
  150106. above_ptr = input_data[inrow-1];
  150107. below_ptr = input_data[inrow+2];
  150108. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150109. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150110. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150111. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150112. GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[2]) +
  150113. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[2]);
  150114. neighsum += neighsum;
  150115. neighsum += GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[2]) +
  150116. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[2]);
  150117. membersum = membersum * memberscale + neighsum * neighscale;
  150118. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150119. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  150120. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  150121. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150122. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150123. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150124. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150125. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[2]) +
  150126. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[2]);
  150127. neighsum += neighsum;
  150128. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[2]) +
  150129. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[2]);
  150130. membersum = membersum * memberscale + neighsum * neighscale;
  150131. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150132. inptr0 += 2; inptr1 += 2; above_ptr += 2; below_ptr += 2;
  150133. }
  150134. membersum = GETJSAMPLE(*inptr0) + GETJSAMPLE(inptr0[1]) +
  150135. GETJSAMPLE(*inptr1) + GETJSAMPLE(inptr1[1]);
  150136. neighsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(above_ptr[1]) +
  150137. GETJSAMPLE(*below_ptr) + GETJSAMPLE(below_ptr[1]) +
  150138. GETJSAMPLE(inptr0[-1]) + GETJSAMPLE(inptr0[1]) +
  150139. GETJSAMPLE(inptr1[-1]) + GETJSAMPLE(inptr1[1]);
  150140. neighsum += neighsum;
  150141. neighsum += GETJSAMPLE(above_ptr[-1]) + GETJSAMPLE(above_ptr[1]) +
  150142. GETJSAMPLE(below_ptr[-1]) + GETJSAMPLE(below_ptr[1]);
  150143. membersum = membersum * memberscale + neighsum * neighscale;
  150144. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  150145. inrow += 2;
  150146. }
  150147. }
  150148. METHODDEF(void)
  150149. fullsize_smooth_downsample (j_compress_ptr cinfo, jpeg_component_info *compptr,
  150150. JSAMPARRAY input_data, JSAMPARRAY output_data)
  150151. {
  150152. int outrow;
  150153. JDIMENSION colctr;
  150154. JDIMENSION output_cols = compptr->width_in_blocks * DCTSIZE;
  150155. register JSAMPROW inptr, above_ptr, below_ptr, outptr;
  150156. INT32 membersum, neighsum, memberscale, neighscale;
  150157. int colsum, lastcolsum, nextcolsum;
  150158. expand_right_edge(input_data - 1, cinfo->max_v_samp_factor + 2,
  150159. cinfo->image_width, output_cols);
  150160. memberscale = 65536L - cinfo->smoothing_factor * 512L; /* scaled 1-8*SF */
  150161. neighscale = cinfo->smoothing_factor * 64; /* scaled SF */
  150162. for (outrow = 0; outrow < compptr->v_samp_factor; outrow++) {
  150163. outptr = output_data[outrow];
  150164. inptr = input_data[outrow];
  150165. above_ptr = input_data[outrow-1];
  150166. below_ptr = input_data[outrow+1];
  150167. colsum = GETJSAMPLE(*above_ptr++) + GETJSAMPLE(*below_ptr++) +
  150168. GETJSAMPLE(*inptr);
  150169. membersum = GETJSAMPLE(*inptr++);
  150170. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  150171. GETJSAMPLE(*inptr);
  150172. neighsum = colsum + (colsum - membersum) + nextcolsum;
  150173. membersum = membersum * memberscale + neighsum * neighscale;
  150174. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150175. lastcolsum = colsum; colsum = nextcolsum;
  150176. for (colctr = output_cols - 2; colctr > 0; colctr--) {
  150177. membersum = GETJSAMPLE(*inptr++);
  150178. above_ptr++; below_ptr++;
  150179. nextcolsum = GETJSAMPLE(*above_ptr) + GETJSAMPLE(*below_ptr) +
  150180. GETJSAMPLE(*inptr);
  150181. neighsum = lastcolsum + (colsum - membersum) + nextcolsum;
  150182. membersum = membersum * memberscale + neighsum * neighscale;
  150183. *outptr++ = (JSAMPLE) ((membersum + 32768) >> 16);
  150184. lastcolsum = colsum; colsum = nextcolsum;
  150185. }
  150186. membersum = GETJSAMPLE(*inptr);
  150187. neighsum = lastcolsum + (colsum - membersum) + colsum;
  150188. membersum = membersum * memberscale + neighsum * neighscale;
  150189. *outptr = (JSAMPLE) ((membersum + 32768) >> 16);
  150190. }
  150191. }
  150192. #endif /* INPUT_SMOOTHING_SUPPORTED */
  150193. GLOBAL(void)
  150194. jinit_downsampler (j_compress_ptr cinfo)
  150195. {
  150196. my_downsample_ptr downsample;
  150197. int ci;
  150198. jpeg_component_info * compptr;
  150199. boolean smoothok = TRUE;
  150200. downsample = (my_downsample_ptr)
  150201. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150202. SIZEOF(my_downsampler));
  150203. cinfo->downsample = (struct jpeg_downsampler *) downsample;
  150204. downsample->pub.start_pass = start_pass_downsample;
  150205. downsample->pub.downsample = sep_downsample;
  150206. downsample->pub.need_context_rows = FALSE;
  150207. if (cinfo->CCIR601_sampling)
  150208. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  150209. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  150210. ci++, compptr++) {
  150211. if (compptr->h_samp_factor == cinfo->max_h_samp_factor &&
  150212. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  150213. #ifdef INPUT_SMOOTHING_SUPPORTED
  150214. if (cinfo->smoothing_factor) {
  150215. downsample->methods[ci] = fullsize_smooth_downsample;
  150216. downsample->pub.need_context_rows = TRUE;
  150217. } else
  150218. #endif
  150219. downsample->methods[ci] = fullsize_downsample;
  150220. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  150221. compptr->v_samp_factor == cinfo->max_v_samp_factor) {
  150222. smoothok = FALSE;
  150223. downsample->methods[ci] = h2v1_downsample;
  150224. } else if (compptr->h_samp_factor * 2 == cinfo->max_h_samp_factor &&
  150225. compptr->v_samp_factor * 2 == cinfo->max_v_samp_factor) {
  150226. #ifdef INPUT_SMOOTHING_SUPPORTED
  150227. if (cinfo->smoothing_factor) {
  150228. downsample->methods[ci] = h2v2_smooth_downsample;
  150229. downsample->pub.need_context_rows = TRUE;
  150230. } else
  150231. #endif
  150232. downsample->methods[ci] = h2v2_downsample;
  150233. } else if ((cinfo->max_h_samp_factor % compptr->h_samp_factor) == 0 &&
  150234. (cinfo->max_v_samp_factor % compptr->v_samp_factor) == 0) {
  150235. smoothok = FALSE;
  150236. downsample->methods[ci] = int_downsample;
  150237. } else
  150238. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  150239. }
  150240. #ifdef INPUT_SMOOTHING_SUPPORTED
  150241. if (cinfo->smoothing_factor && !smoothok)
  150242. TRACEMS(cinfo, 0, JTRC_SMOOTH_NOTIMPL);
  150243. #endif
  150244. }
  150245. /*** End of inlined file: jcsample.c ***/
  150246. /*** Start of inlined file: jctrans.c ***/
  150247. #define JPEG_INTERNALS
  150248. LOCAL(void) transencode_master_selection
  150249. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  150250. LOCAL(void) transencode_coef_controller
  150251. JPP((j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays));
  150252. GLOBAL(void)
  150253. jpeg_write_coefficients (j_compress_ptr cinfo, jvirt_barray_ptr * coef_arrays)
  150254. {
  150255. if (cinfo->global_state != CSTATE_START)
  150256. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150257. jpeg_suppress_tables(cinfo, FALSE);
  150258. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  150259. (*cinfo->dest->init_destination) (cinfo);
  150260. transencode_master_selection(cinfo, coef_arrays);
  150261. cinfo->next_scanline = 0; /* so jpeg_write_marker works */
  150262. cinfo->global_state = CSTATE_WRCOEFS;
  150263. }
  150264. GLOBAL(void)
  150265. jpeg_copy_critical_parameters (j_decompress_ptr srcinfo,
  150266. j_compress_ptr dstinfo)
  150267. {
  150268. JQUANT_TBL ** qtblptr;
  150269. jpeg_component_info *incomp, *outcomp;
  150270. JQUANT_TBL *c_quant, *slot_quant;
  150271. int tblno, ci, coefi;
  150272. if (dstinfo->global_state != CSTATE_START)
  150273. ERREXIT1(dstinfo, JERR_BAD_STATE, dstinfo->global_state);
  150274. dstinfo->image_width = srcinfo->image_width;
  150275. dstinfo->image_height = srcinfo->image_height;
  150276. dstinfo->input_components = srcinfo->num_components;
  150277. dstinfo->in_color_space = srcinfo->jpeg_color_space;
  150278. jpeg_set_defaults(dstinfo);
  150279. jpeg_set_colorspace(dstinfo, srcinfo->jpeg_color_space);
  150280. dstinfo->data_precision = srcinfo->data_precision;
  150281. dstinfo->CCIR601_sampling = srcinfo->CCIR601_sampling;
  150282. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  150283. if (srcinfo->quant_tbl_ptrs[tblno] != NULL) {
  150284. qtblptr = & dstinfo->quant_tbl_ptrs[tblno];
  150285. if (*qtblptr == NULL)
  150286. *qtblptr = jpeg_alloc_quant_table((j_common_ptr) dstinfo);
  150287. MEMCOPY((*qtblptr)->quantval,
  150288. srcinfo->quant_tbl_ptrs[tblno]->quantval,
  150289. SIZEOF((*qtblptr)->quantval));
  150290. (*qtblptr)->sent_table = FALSE;
  150291. }
  150292. }
  150293. dstinfo->num_components = srcinfo->num_components;
  150294. if (dstinfo->num_components < 1 || dstinfo->num_components > MAX_COMPONENTS)
  150295. ERREXIT2(dstinfo, JERR_COMPONENT_COUNT, dstinfo->num_components,
  150296. MAX_COMPONENTS);
  150297. for (ci = 0, incomp = srcinfo->comp_info, outcomp = dstinfo->comp_info;
  150298. ci < dstinfo->num_components; ci++, incomp++, outcomp++) {
  150299. outcomp->component_id = incomp->component_id;
  150300. outcomp->h_samp_factor = incomp->h_samp_factor;
  150301. outcomp->v_samp_factor = incomp->v_samp_factor;
  150302. outcomp->quant_tbl_no = incomp->quant_tbl_no;
  150303. tblno = outcomp->quant_tbl_no;
  150304. if (tblno < 0 || tblno >= NUM_QUANT_TBLS ||
  150305. srcinfo->quant_tbl_ptrs[tblno] == NULL)
  150306. ERREXIT1(dstinfo, JERR_NO_QUANT_TABLE, tblno);
  150307. slot_quant = srcinfo->quant_tbl_ptrs[tblno];
  150308. c_quant = incomp->quant_table;
  150309. if (c_quant != NULL) {
  150310. for (coefi = 0; coefi < DCTSIZE2; coefi++) {
  150311. if (c_quant->quantval[coefi] != slot_quant->quantval[coefi])
  150312. ERREXIT1(dstinfo, JERR_MISMATCHED_QUANT_TABLE, tblno);
  150313. }
  150314. }
  150315. }
  150316. if (srcinfo->saw_JFIF_marker) {
  150317. if (srcinfo->JFIF_major_version == 1) {
  150318. dstinfo->JFIF_major_version = srcinfo->JFIF_major_version;
  150319. dstinfo->JFIF_minor_version = srcinfo->JFIF_minor_version;
  150320. }
  150321. dstinfo->density_unit = srcinfo->density_unit;
  150322. dstinfo->X_density = srcinfo->X_density;
  150323. dstinfo->Y_density = srcinfo->Y_density;
  150324. }
  150325. }
  150326. LOCAL(void)
  150327. transencode_master_selection (j_compress_ptr cinfo,
  150328. jvirt_barray_ptr * coef_arrays)
  150329. {
  150330. cinfo->input_components = 1;
  150331. jinit_c_master_control(cinfo, TRUE /* transcode only */);
  150332. if (cinfo->arith_code) {
  150333. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  150334. } else {
  150335. if (cinfo->progressive_mode) {
  150336. #ifdef C_PROGRESSIVE_SUPPORTED
  150337. jinit_phuff_encoder(cinfo);
  150338. #else
  150339. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150340. #endif
  150341. } else
  150342. jinit_huff_encoder(cinfo);
  150343. }
  150344. transencode_coef_controller(cinfo, coef_arrays);
  150345. jinit_marker_writer(cinfo);
  150346. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  150347. (*cinfo->marker->write_file_header) (cinfo);
  150348. }
  150349. typedef struct {
  150350. struct jpeg_c_coef_controller pub; /* public fields */
  150351. JDIMENSION iMCU_row_num; /* iMCU row # within image */
  150352. JDIMENSION mcu_ctr; /* counts MCUs processed in current row */
  150353. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  150354. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  150355. jvirt_barray_ptr * whole_image;
  150356. JBLOCKROW dummy_buffer[C_MAX_BLOCKS_IN_MCU];
  150357. } my_coef_controller2;
  150358. typedef my_coef_controller2 * my_coef_ptr2;
  150359. LOCAL(void)
  150360. start_iMCU_row2 (j_compress_ptr cinfo)
  150361. {
  150362. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150363. if (cinfo->comps_in_scan > 1) {
  150364. coef->MCU_rows_per_iMCU_row = 1;
  150365. } else {
  150366. if (coef->iMCU_row_num < (cinfo->total_iMCU_rows-1))
  150367. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  150368. else
  150369. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  150370. }
  150371. coef->mcu_ctr = 0;
  150372. coef->MCU_vert_offset = 0;
  150373. }
  150374. METHODDEF(void)
  150375. start_pass_coef2 (j_compress_ptr cinfo, J_BUF_MODE pass_mode)
  150376. {
  150377. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150378. if (pass_mode != JBUF_CRANK_DEST)
  150379. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  150380. coef->iMCU_row_num = 0;
  150381. start_iMCU_row2(cinfo);
  150382. }
  150383. METHODDEF(boolean)
  150384. compress_output2 (j_compress_ptr cinfo, JSAMPIMAGE input_buf)
  150385. {
  150386. my_coef_ptr2 coef = (my_coef_ptr2) cinfo->coef;
  150387. JDIMENSION MCU_col_num; /* index of current MCU within row */
  150388. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  150389. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  150390. int blkn, ci, xindex, yindex, yoffset, blockcnt;
  150391. JDIMENSION start_col;
  150392. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  150393. JBLOCKROW MCU_buffer[C_MAX_BLOCKS_IN_MCU];
  150394. JBLOCKROW buffer_ptr;
  150395. jpeg_component_info *compptr;
  150396. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150397. compptr = cinfo->cur_comp_info[ci];
  150398. buffer[ci] = (*cinfo->mem->access_virt_barray)
  150399. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  150400. coef->iMCU_row_num * compptr->v_samp_factor,
  150401. (JDIMENSION) compptr->v_samp_factor, FALSE);
  150402. }
  150403. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  150404. yoffset++) {
  150405. for (MCU_col_num = coef->mcu_ctr; MCU_col_num < cinfo->MCUs_per_row;
  150406. MCU_col_num++) {
  150407. blkn = 0; /* index of current DCT block within MCU */
  150408. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  150409. compptr = cinfo->cur_comp_info[ci];
  150410. start_col = MCU_col_num * compptr->MCU_width;
  150411. blockcnt = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  150412. : compptr->last_col_width;
  150413. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  150414. if (coef->iMCU_row_num < last_iMCU_row ||
  150415. yindex+yoffset < compptr->last_row_height) {
  150416. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  150417. for (xindex = 0; xindex < blockcnt; xindex++)
  150418. MCU_buffer[blkn++] = buffer_ptr++;
  150419. } else {
  150420. xindex = 0;
  150421. }
  150422. for (; xindex < compptr->MCU_width; xindex++) {
  150423. MCU_buffer[blkn] = coef->dummy_buffer[blkn];
  150424. MCU_buffer[blkn][0][0] = MCU_buffer[blkn-1][0][0];
  150425. blkn++;
  150426. }
  150427. }
  150428. }
  150429. if (! (*cinfo->entropy->encode_mcu) (cinfo, MCU_buffer)) {
  150430. coef->MCU_vert_offset = yoffset;
  150431. coef->mcu_ctr = MCU_col_num;
  150432. return FALSE;
  150433. }
  150434. }
  150435. coef->mcu_ctr = 0;
  150436. }
  150437. coef->iMCU_row_num++;
  150438. start_iMCU_row2(cinfo);
  150439. return TRUE;
  150440. }
  150441. LOCAL(void)
  150442. transencode_coef_controller (j_compress_ptr cinfo,
  150443. jvirt_barray_ptr * coef_arrays)
  150444. {
  150445. my_coef_ptr2 coef;
  150446. JBLOCKROW buffer;
  150447. int i;
  150448. coef = (my_coef_ptr2)
  150449. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150450. SIZEOF(my_coef_controller2));
  150451. cinfo->coef = (struct jpeg_c_coef_controller *) coef;
  150452. coef->pub.start_pass = start_pass_coef2;
  150453. coef->pub.compress_data = compress_output2;
  150454. coef->whole_image = coef_arrays;
  150455. buffer = (JBLOCKROW)
  150456. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  150457. C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150458. jzero_far((void FAR *) buffer, C_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  150459. for (i = 0; i < C_MAX_BLOCKS_IN_MCU; i++) {
  150460. coef->dummy_buffer[i] = buffer + i;
  150461. }
  150462. }
  150463. /*** End of inlined file: jctrans.c ***/
  150464. /*** Start of inlined file: jdapistd.c ***/
  150465. #define JPEG_INTERNALS
  150466. LOCAL(boolean) output_pass_setup JPP((j_decompress_ptr cinfo));
  150467. GLOBAL(boolean)
  150468. jpeg_start_decompress (j_decompress_ptr cinfo)
  150469. {
  150470. if (cinfo->global_state == DSTATE_READY) {
  150471. jinit_master_decompress(cinfo);
  150472. if (cinfo->buffered_image) {
  150473. cinfo->global_state = DSTATE_BUFIMAGE;
  150474. return TRUE;
  150475. }
  150476. cinfo->global_state = DSTATE_PRELOAD;
  150477. }
  150478. if (cinfo->global_state == DSTATE_PRELOAD) {
  150479. if (cinfo->inputctl->has_multiple_scans) {
  150480. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150481. for (;;) {
  150482. int retcode;
  150483. if (cinfo->progress != NULL)
  150484. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150485. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150486. if (retcode == JPEG_SUSPENDED)
  150487. return FALSE;
  150488. if (retcode == JPEG_REACHED_EOI)
  150489. break;
  150490. if (cinfo->progress != NULL &&
  150491. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  150492. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  150493. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  150494. }
  150495. }
  150496. }
  150497. #else
  150498. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150499. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150500. }
  150501. cinfo->output_scan_number = cinfo->input_scan_number;
  150502. } else if (cinfo->global_state != DSTATE_PRESCAN)
  150503. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150504. return output_pass_setup(cinfo);
  150505. }
  150506. LOCAL(boolean)
  150507. output_pass_setup (j_decompress_ptr cinfo)
  150508. {
  150509. if (cinfo->global_state != DSTATE_PRESCAN) {
  150510. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150511. cinfo->output_scanline = 0;
  150512. cinfo->global_state = DSTATE_PRESCAN;
  150513. }
  150514. while (cinfo->master->is_dummy_pass) {
  150515. #ifdef QUANT_2PASS_SUPPORTED
  150516. while (cinfo->output_scanline < cinfo->output_height) {
  150517. JDIMENSION last_scanline;
  150518. if (cinfo->progress != NULL) {
  150519. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150520. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150521. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150522. }
  150523. last_scanline = cinfo->output_scanline;
  150524. (*cinfo->main->process_data) (cinfo, (JSAMPARRAY) NULL,
  150525. &cinfo->output_scanline, (JDIMENSION) 0);
  150526. if (cinfo->output_scanline == last_scanline)
  150527. return FALSE; /* No progress made, must suspend */
  150528. }
  150529. (*cinfo->master->finish_output_pass) (cinfo);
  150530. (*cinfo->master->prepare_for_output_pass) (cinfo);
  150531. cinfo->output_scanline = 0;
  150532. #else
  150533. ERREXIT(cinfo, JERR_NOT_COMPILED);
  150534. #endif /* QUANT_2PASS_SUPPORTED */
  150535. }
  150536. cinfo->global_state = cinfo->raw_data_out ? DSTATE_RAW_OK : DSTATE_SCANNING;
  150537. return TRUE;
  150538. }
  150539. GLOBAL(JDIMENSION)
  150540. jpeg_read_scanlines (j_decompress_ptr cinfo, JSAMPARRAY scanlines,
  150541. JDIMENSION max_lines)
  150542. {
  150543. JDIMENSION row_ctr;
  150544. if (cinfo->global_state != DSTATE_SCANNING)
  150545. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150546. if (cinfo->output_scanline >= cinfo->output_height) {
  150547. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150548. return 0;
  150549. }
  150550. if (cinfo->progress != NULL) {
  150551. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150552. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150553. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150554. }
  150555. row_ctr = 0;
  150556. (*cinfo->main->process_data) (cinfo, scanlines, &row_ctr, max_lines);
  150557. cinfo->output_scanline += row_ctr;
  150558. return row_ctr;
  150559. }
  150560. GLOBAL(JDIMENSION)
  150561. jpeg_read_raw_data (j_decompress_ptr cinfo, JSAMPIMAGE data,
  150562. JDIMENSION max_lines)
  150563. {
  150564. JDIMENSION lines_per_iMCU_row;
  150565. if (cinfo->global_state != DSTATE_RAW_OK)
  150566. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150567. if (cinfo->output_scanline >= cinfo->output_height) {
  150568. WARNMS(cinfo, JWRN_TOO_MUCH_DATA);
  150569. return 0;
  150570. }
  150571. if (cinfo->progress != NULL) {
  150572. cinfo->progress->pass_counter = (long) cinfo->output_scanline;
  150573. cinfo->progress->pass_limit = (long) cinfo->output_height;
  150574. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  150575. }
  150576. lines_per_iMCU_row = cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size;
  150577. if (max_lines < lines_per_iMCU_row)
  150578. ERREXIT(cinfo, JERR_BUFFER_SIZE);
  150579. if (! (*cinfo->coef->decompress_data) (cinfo, data))
  150580. return 0; /* suspension forced, can do nothing more */
  150581. cinfo->output_scanline += lines_per_iMCU_row;
  150582. return lines_per_iMCU_row;
  150583. }
  150584. #ifdef D_MULTISCAN_FILES_SUPPORTED
  150585. GLOBAL(boolean)
  150586. jpeg_start_output (j_decompress_ptr cinfo, int scan_number)
  150587. {
  150588. if (cinfo->global_state != DSTATE_BUFIMAGE &&
  150589. cinfo->global_state != DSTATE_PRESCAN)
  150590. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150591. if (scan_number <= 0)
  150592. scan_number = 1;
  150593. if (cinfo->inputctl->eoi_reached &&
  150594. scan_number > cinfo->input_scan_number)
  150595. scan_number = cinfo->input_scan_number;
  150596. cinfo->output_scan_number = scan_number;
  150597. return output_pass_setup(cinfo);
  150598. }
  150599. GLOBAL(boolean)
  150600. jpeg_finish_output (j_decompress_ptr cinfo)
  150601. {
  150602. if ((cinfo->global_state == DSTATE_SCANNING ||
  150603. cinfo->global_state == DSTATE_RAW_OK) && cinfo->buffered_image) {
  150604. (*cinfo->master->finish_output_pass) (cinfo);
  150605. cinfo->global_state = DSTATE_BUFPOST;
  150606. } else if (cinfo->global_state != DSTATE_BUFPOST) {
  150607. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150608. }
  150609. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  150610. ! cinfo->inputctl->eoi_reached) {
  150611. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150612. return FALSE; /* Suspend, come back later */
  150613. }
  150614. cinfo->global_state = DSTATE_BUFIMAGE;
  150615. return TRUE;
  150616. }
  150617. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  150618. /*** End of inlined file: jdapistd.c ***/
  150619. /*** Start of inlined file: jdapimin.c ***/
  150620. #define JPEG_INTERNALS
  150621. GLOBAL(void)
  150622. jpeg_CreateDecompress (j_decompress_ptr cinfo, int version, size_t structsize)
  150623. {
  150624. int i;
  150625. cinfo->mem = NULL; /* so jpeg_destroy knows mem mgr not called */
  150626. if (version != JPEG_LIB_VERSION)
  150627. ERREXIT2(cinfo, JERR_BAD_LIB_VERSION, JPEG_LIB_VERSION, version);
  150628. if (structsize != SIZEOF(struct jpeg_decompress_struct))
  150629. ERREXIT2(cinfo, JERR_BAD_STRUCT_SIZE,
  150630. (int) SIZEOF(struct jpeg_decompress_struct), (int) structsize);
  150631. {
  150632. struct jpeg_error_mgr * err = cinfo->err;
  150633. void * client_data = cinfo->client_data; /* ignore Purify complaint here */
  150634. MEMZERO(cinfo, SIZEOF(struct jpeg_decompress_struct));
  150635. cinfo->err = err;
  150636. cinfo->client_data = client_data;
  150637. }
  150638. cinfo->is_decompressor = TRUE;
  150639. jinit_memory_mgr((j_common_ptr) cinfo);
  150640. cinfo->progress = NULL;
  150641. cinfo->src = NULL;
  150642. for (i = 0; i < NUM_QUANT_TBLS; i++)
  150643. cinfo->quant_tbl_ptrs[i] = NULL;
  150644. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  150645. cinfo->dc_huff_tbl_ptrs[i] = NULL;
  150646. cinfo->ac_huff_tbl_ptrs[i] = NULL;
  150647. }
  150648. cinfo->marker_list = NULL;
  150649. jinit_marker_reader(cinfo);
  150650. jinit_input_controller(cinfo);
  150651. cinfo->global_state = DSTATE_START;
  150652. }
  150653. GLOBAL(void)
  150654. jpeg_destroy_decompress (j_decompress_ptr cinfo)
  150655. {
  150656. jpeg_destroy((j_common_ptr) cinfo); /* use common routine */
  150657. }
  150658. GLOBAL(void)
  150659. jpeg_abort_decompress (j_decompress_ptr cinfo)
  150660. {
  150661. jpeg_abort((j_common_ptr) cinfo); /* use common routine */
  150662. }
  150663. LOCAL(void)
  150664. default_decompress_parms (j_decompress_ptr cinfo)
  150665. {
  150666. switch (cinfo->num_components) {
  150667. case 1:
  150668. cinfo->jpeg_color_space = JCS_GRAYSCALE;
  150669. cinfo->out_color_space = JCS_GRAYSCALE;
  150670. break;
  150671. case 3:
  150672. if (cinfo->saw_JFIF_marker) {
  150673. cinfo->jpeg_color_space = JCS_YCbCr; /* JFIF implies YCbCr */
  150674. } else if (cinfo->saw_Adobe_marker) {
  150675. switch (cinfo->Adobe_transform) {
  150676. case 0:
  150677. cinfo->jpeg_color_space = JCS_RGB;
  150678. break;
  150679. case 1:
  150680. cinfo->jpeg_color_space = JCS_YCbCr;
  150681. break;
  150682. default:
  150683. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150684. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150685. break;
  150686. }
  150687. } else {
  150688. int cid0 = cinfo->comp_info[0].component_id;
  150689. int cid1 = cinfo->comp_info[1].component_id;
  150690. int cid2 = cinfo->comp_info[2].component_id;
  150691. if (cid0 == 1 && cid1 == 2 && cid2 == 3)
  150692. cinfo->jpeg_color_space = JCS_YCbCr; /* assume JFIF w/out marker */
  150693. else if (cid0 == 82 && cid1 == 71 && cid2 == 66)
  150694. cinfo->jpeg_color_space = JCS_RGB; /* ASCII 'R', 'G', 'B' */
  150695. else {
  150696. TRACEMS3(cinfo, 1, JTRC_UNKNOWN_IDS, cid0, cid1, cid2);
  150697. cinfo->jpeg_color_space = JCS_YCbCr; /* assume it's YCbCr */
  150698. }
  150699. }
  150700. cinfo->out_color_space = JCS_RGB;
  150701. break;
  150702. case 4:
  150703. if (cinfo->saw_Adobe_marker) {
  150704. switch (cinfo->Adobe_transform) {
  150705. case 0:
  150706. cinfo->jpeg_color_space = JCS_CMYK;
  150707. break;
  150708. case 2:
  150709. cinfo->jpeg_color_space = JCS_YCCK;
  150710. break;
  150711. default:
  150712. WARNMS1(cinfo, JWRN_ADOBE_XFORM, cinfo->Adobe_transform);
  150713. cinfo->jpeg_color_space = JCS_YCCK; /* assume it's YCCK */
  150714. break;
  150715. }
  150716. } else {
  150717. cinfo->jpeg_color_space = JCS_CMYK;
  150718. }
  150719. cinfo->out_color_space = JCS_CMYK;
  150720. break;
  150721. default:
  150722. cinfo->jpeg_color_space = JCS_UNKNOWN;
  150723. cinfo->out_color_space = JCS_UNKNOWN;
  150724. break;
  150725. }
  150726. cinfo->scale_num = 1; /* 1:1 scaling */
  150727. cinfo->scale_denom = 1;
  150728. cinfo->output_gamma = 1.0;
  150729. cinfo->buffered_image = FALSE;
  150730. cinfo->raw_data_out = FALSE;
  150731. cinfo->dct_method = JDCT_DEFAULT;
  150732. cinfo->do_fancy_upsampling = TRUE;
  150733. cinfo->do_block_smoothing = TRUE;
  150734. cinfo->quantize_colors = FALSE;
  150735. cinfo->dither_mode = JDITHER_FS;
  150736. #ifdef QUANT_2PASS_SUPPORTED
  150737. cinfo->two_pass_quantize = TRUE;
  150738. #else
  150739. cinfo->two_pass_quantize = FALSE;
  150740. #endif
  150741. cinfo->desired_number_of_colors = 256;
  150742. cinfo->colormap = NULL;
  150743. cinfo->enable_1pass_quant = FALSE;
  150744. cinfo->enable_external_quant = FALSE;
  150745. cinfo->enable_2pass_quant = FALSE;
  150746. }
  150747. GLOBAL(int)
  150748. jpeg_read_header (j_decompress_ptr cinfo, boolean require_image)
  150749. {
  150750. int retcode;
  150751. if (cinfo->global_state != DSTATE_START &&
  150752. cinfo->global_state != DSTATE_INHEADER)
  150753. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150754. retcode = jpeg_consume_input(cinfo);
  150755. switch (retcode) {
  150756. case JPEG_REACHED_SOS:
  150757. retcode = JPEG_HEADER_OK;
  150758. break;
  150759. case JPEG_REACHED_EOI:
  150760. if (require_image) /* Complain if application wanted an image */
  150761. ERREXIT(cinfo, JERR_NO_IMAGE);
  150762. jpeg_abort((j_common_ptr) cinfo); /* sets state = DSTATE_START */
  150763. retcode = JPEG_HEADER_TABLES_ONLY;
  150764. break;
  150765. case JPEG_SUSPENDED:
  150766. break;
  150767. }
  150768. return retcode;
  150769. }
  150770. GLOBAL(int)
  150771. jpeg_consume_input (j_decompress_ptr cinfo)
  150772. {
  150773. int retcode = JPEG_SUSPENDED;
  150774. switch (cinfo->global_state) {
  150775. case DSTATE_START:
  150776. (*cinfo->inputctl->reset_input_controller) (cinfo);
  150777. (*cinfo->src->init_source) (cinfo);
  150778. cinfo->global_state = DSTATE_INHEADER;
  150779. case DSTATE_INHEADER:
  150780. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150781. if (retcode == JPEG_REACHED_SOS) { /* Found SOS, prepare to decompress */
  150782. default_decompress_parms(cinfo);
  150783. cinfo->global_state = DSTATE_READY;
  150784. }
  150785. break;
  150786. case DSTATE_READY:
  150787. retcode = JPEG_REACHED_SOS;
  150788. break;
  150789. case DSTATE_PRELOAD:
  150790. case DSTATE_PRESCAN:
  150791. case DSTATE_SCANNING:
  150792. case DSTATE_RAW_OK:
  150793. case DSTATE_BUFIMAGE:
  150794. case DSTATE_BUFPOST:
  150795. case DSTATE_STOPPING:
  150796. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  150797. break;
  150798. default:
  150799. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150800. }
  150801. return retcode;
  150802. }
  150803. GLOBAL(boolean)
  150804. jpeg_input_complete (j_decompress_ptr cinfo)
  150805. {
  150806. if (cinfo->global_state < DSTATE_START ||
  150807. cinfo->global_state > DSTATE_STOPPING)
  150808. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150809. return cinfo->inputctl->eoi_reached;
  150810. }
  150811. GLOBAL(boolean)
  150812. jpeg_has_multiple_scans (j_decompress_ptr cinfo)
  150813. {
  150814. if (cinfo->global_state < DSTATE_READY ||
  150815. cinfo->global_state > DSTATE_STOPPING)
  150816. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150817. return cinfo->inputctl->has_multiple_scans;
  150818. }
  150819. GLOBAL(boolean)
  150820. jpeg_finish_decompress (j_decompress_ptr cinfo)
  150821. {
  150822. if ((cinfo->global_state == DSTATE_SCANNING ||
  150823. cinfo->global_state == DSTATE_RAW_OK) && ! cinfo->buffered_image) {
  150824. if (cinfo->output_scanline < cinfo->output_height)
  150825. ERREXIT(cinfo, JERR_TOO_LITTLE_DATA);
  150826. (*cinfo->master->finish_output_pass) (cinfo);
  150827. cinfo->global_state = DSTATE_STOPPING;
  150828. } else if (cinfo->global_state == DSTATE_BUFIMAGE) {
  150829. cinfo->global_state = DSTATE_STOPPING;
  150830. } else if (cinfo->global_state != DSTATE_STOPPING) {
  150831. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  150832. }
  150833. while (! cinfo->inputctl->eoi_reached) {
  150834. if ((*cinfo->inputctl->consume_input) (cinfo) == JPEG_SUSPENDED)
  150835. return FALSE; /* Suspend, come back later */
  150836. }
  150837. (*cinfo->src->term_source) (cinfo);
  150838. jpeg_abort((j_common_ptr) cinfo);
  150839. return TRUE;
  150840. }
  150841. /*** End of inlined file: jdapimin.c ***/
  150842. /*** Start of inlined file: jdatasrc.c ***/
  150843. /*** Start of inlined file: jerror.h ***/
  150844. #ifndef JMESSAGE
  150845. #ifndef JERROR_H
  150846. #define JMAKE_ENUM_LIST
  150847. #else
  150848. #define JMESSAGE(code,string)
  150849. #endif /* JERROR_H */
  150850. #endif /* JMESSAGE */
  150851. #ifdef JMAKE_ENUM_LIST
  150852. typedef enum {
  150853. #define JMESSAGE(code,string) code ,
  150854. #endif /* JMAKE_ENUM_LIST */
  150855. JMESSAGE(JMSG_NOMESSAGE, "Bogus message code %d") /* Must be first entry! */
  150856. JMESSAGE(JERR_ARITH_NOTIMPL,
  150857. "Sorry, there are legal restrictions on arithmetic coding")
  150858. JMESSAGE(JERR_BAD_ALIGN_TYPE, "ALIGN_TYPE is wrong, please fix")
  150859. JMESSAGE(JERR_BAD_ALLOC_CHUNK, "MAX_ALLOC_CHUNK is wrong, please fix")
  150860. JMESSAGE(JERR_BAD_BUFFER_MODE, "Bogus buffer control mode")
  150861. JMESSAGE(JERR_BAD_COMPONENT_ID, "Invalid component ID %d in SOS")
  150862. JMESSAGE(JERR_BAD_DCT_COEF, "DCT coefficient out of range")
  150863. JMESSAGE(JERR_BAD_DCTSIZE, "IDCT output block size %d not supported")
  150864. JMESSAGE(JERR_BAD_HUFF_TABLE, "Bogus Huffman table definition")
  150865. JMESSAGE(JERR_BAD_IN_COLORSPACE, "Bogus input colorspace")
  150866. JMESSAGE(JERR_BAD_J_COLORSPACE, "Bogus JPEG colorspace")
  150867. JMESSAGE(JERR_BAD_LENGTH, "Bogus marker length")
  150868. JMESSAGE(JERR_BAD_LIB_VERSION,
  150869. "Wrong JPEG library version: library is %d, caller expects %d")
  150870. JMESSAGE(JERR_BAD_MCU_SIZE, "Sampling factors too large for interleaved scan")
  150871. JMESSAGE(JERR_BAD_POOL_ID, "Invalid memory pool code %d")
  150872. JMESSAGE(JERR_BAD_PRECISION, "Unsupported JPEG data precision %d")
  150873. JMESSAGE(JERR_BAD_PROGRESSION,
  150874. "Invalid progressive parameters Ss=%d Se=%d Ah=%d Al=%d")
  150875. JMESSAGE(JERR_BAD_PROG_SCRIPT,
  150876. "Invalid progressive parameters at scan script entry %d")
  150877. JMESSAGE(JERR_BAD_SAMPLING, "Bogus sampling factors")
  150878. JMESSAGE(JERR_BAD_SCAN_SCRIPT, "Invalid scan script at entry %d")
  150879. JMESSAGE(JERR_BAD_STATE, "Improper call to JPEG library in state %d")
  150880. JMESSAGE(JERR_BAD_STRUCT_SIZE,
  150881. "JPEG parameter struct mismatch: library thinks size is %u, caller expects %u")
  150882. JMESSAGE(JERR_BAD_VIRTUAL_ACCESS, "Bogus virtual array access")
  150883. JMESSAGE(JERR_BUFFER_SIZE, "Buffer passed to JPEG library is too small")
  150884. JMESSAGE(JERR_CANT_SUSPEND, "Suspension not allowed here")
  150885. JMESSAGE(JERR_CCIR601_NOTIMPL, "CCIR601 sampling not implemented yet")
  150886. JMESSAGE(JERR_COMPONENT_COUNT, "Too many color components: %d, max %d")
  150887. JMESSAGE(JERR_CONVERSION_NOTIMPL, "Unsupported color conversion request")
  150888. JMESSAGE(JERR_DAC_INDEX, "Bogus DAC index %d")
  150889. JMESSAGE(JERR_DAC_VALUE, "Bogus DAC value 0x%x")
  150890. JMESSAGE(JERR_DHT_INDEX, "Bogus DHT index %d")
  150891. JMESSAGE(JERR_DQT_INDEX, "Bogus DQT index %d")
  150892. JMESSAGE(JERR_EMPTY_IMAGE, "Empty JPEG image (DNL not supported)")
  150893. JMESSAGE(JERR_EMS_READ, "Read from EMS failed")
  150894. JMESSAGE(JERR_EMS_WRITE, "Write to EMS failed")
  150895. JMESSAGE(JERR_EOI_EXPECTED, "Didn't expect more than one scan")
  150896. JMESSAGE(JERR_FILE_READ, "Input file read error")
  150897. JMESSAGE(JERR_FILE_WRITE, "Output file write error --- out of disk space?")
  150898. JMESSAGE(JERR_FRACT_SAMPLE_NOTIMPL, "Fractional sampling not implemented yet")
  150899. JMESSAGE(JERR_HUFF_CLEN_OVERFLOW, "Huffman code size table overflow")
  150900. JMESSAGE(JERR_HUFF_MISSING_CODE, "Missing Huffman code table entry")
  150901. JMESSAGE(JERR_IMAGE_TOO_BIG, "Maximum supported image dimension is %u pixels")
  150902. JMESSAGE(JERR_INPUT_EMPTY, "Empty input file")
  150903. JMESSAGE(JERR_INPUT_EOF, "Premature end of input file")
  150904. JMESSAGE(JERR_MISMATCHED_QUANT_TABLE,
  150905. "Cannot transcode due to multiple use of quantization table %d")
  150906. JMESSAGE(JERR_MISSING_DATA, "Scan script does not transmit all data")
  150907. JMESSAGE(JERR_MODE_CHANGE, "Invalid color quantization mode change")
  150908. JMESSAGE(JERR_NOTIMPL, "Not implemented yet")
  150909. JMESSAGE(JERR_NOT_COMPILED, "Requested feature was omitted at compile time")
  150910. JMESSAGE(JERR_NO_BACKING_STORE, "Backing store not supported")
  150911. JMESSAGE(JERR_NO_HUFF_TABLE, "Huffman table 0x%02x was not defined")
  150912. JMESSAGE(JERR_NO_IMAGE, "JPEG datastream contains no image")
  150913. JMESSAGE(JERR_NO_QUANT_TABLE, "Quantization table 0x%02x was not defined")
  150914. JMESSAGE(JERR_NO_SOI, "Not a JPEG file: starts with 0x%02x 0x%02x")
  150915. JMESSAGE(JERR_OUT_OF_MEMORY, "Insufficient memory (case %d)")
  150916. JMESSAGE(JERR_QUANT_COMPONENTS,
  150917. "Cannot quantize more than %d color components")
  150918. JMESSAGE(JERR_QUANT_FEW_COLORS, "Cannot quantize to fewer than %d colors")
  150919. JMESSAGE(JERR_QUANT_MANY_COLORS, "Cannot quantize to more than %d colors")
  150920. JMESSAGE(JERR_SOF_DUPLICATE, "Invalid JPEG file structure: two SOF markers")
  150921. JMESSAGE(JERR_SOF_NO_SOS, "Invalid JPEG file structure: missing SOS marker")
  150922. JMESSAGE(JERR_SOF_UNSUPPORTED, "Unsupported JPEG process: SOF type 0x%02x")
  150923. JMESSAGE(JERR_SOI_DUPLICATE, "Invalid JPEG file structure: two SOI markers")
  150924. JMESSAGE(JERR_SOS_NO_SOF, "Invalid JPEG file structure: SOS before SOF")
  150925. JMESSAGE(JERR_TFILE_CREATE, "Failed to create temporary file %s")
  150926. JMESSAGE(JERR_TFILE_READ, "Read failed on temporary file")
  150927. JMESSAGE(JERR_TFILE_SEEK, "Seek failed on temporary file")
  150928. JMESSAGE(JERR_TFILE_WRITE,
  150929. "Write failed on temporary file --- out of disk space?")
  150930. JMESSAGE(JERR_TOO_LITTLE_DATA, "Application transferred too few scanlines")
  150931. JMESSAGE(JERR_UNKNOWN_MARKER, "Unsupported marker type 0x%02x")
  150932. JMESSAGE(JERR_VIRTUAL_BUG, "Virtual array controller messed up")
  150933. JMESSAGE(JERR_WIDTH_OVERFLOW, "Image too wide for this implementation")
  150934. JMESSAGE(JERR_XMS_READ, "Read from XMS failed")
  150935. JMESSAGE(JERR_XMS_WRITE, "Write to XMS failed")
  150936. JMESSAGE(JMSG_COPYRIGHT, JCOPYRIGHT)
  150937. JMESSAGE(JMSG_VERSION, JVERSION)
  150938. JMESSAGE(JTRC_16BIT_TABLES,
  150939. "Caution: quantization tables are too coarse for baseline JPEG")
  150940. JMESSAGE(JTRC_ADOBE,
  150941. "Adobe APP14 marker: version %d, flags 0x%04x 0x%04x, transform %d")
  150942. JMESSAGE(JTRC_APP0, "Unknown APP0 marker (not JFIF), length %u")
  150943. JMESSAGE(JTRC_APP14, "Unknown APP14 marker (not Adobe), length %u")
  150944. JMESSAGE(JTRC_DAC, "Define Arithmetic Table 0x%02x: 0x%02x")
  150945. JMESSAGE(JTRC_DHT, "Define Huffman Table 0x%02x")
  150946. JMESSAGE(JTRC_DQT, "Define Quantization Table %d precision %d")
  150947. JMESSAGE(JTRC_DRI, "Define Restart Interval %u")
  150948. JMESSAGE(JTRC_EMS_CLOSE, "Freed EMS handle %u")
  150949. JMESSAGE(JTRC_EMS_OPEN, "Obtained EMS handle %u")
  150950. JMESSAGE(JTRC_EOI, "End Of Image")
  150951. JMESSAGE(JTRC_HUFFBITS, " %3d %3d %3d %3d %3d %3d %3d %3d")
  150952. JMESSAGE(JTRC_JFIF, "JFIF APP0 marker: version %d.%02d, density %dx%d %d")
  150953. JMESSAGE(JTRC_JFIF_BADTHUMBNAILSIZE,
  150954. "Warning: thumbnail image size does not match data length %u")
  150955. JMESSAGE(JTRC_JFIF_EXTENSION,
  150956. "JFIF extension marker: type 0x%02x, length %u")
  150957. JMESSAGE(JTRC_JFIF_THUMBNAIL, " with %d x %d thumbnail image")
  150958. JMESSAGE(JTRC_MISC_MARKER, "Miscellaneous marker 0x%02x, length %u")
  150959. JMESSAGE(JTRC_PARMLESS_MARKER, "Unexpected marker 0x%02x")
  150960. JMESSAGE(JTRC_QUANTVALS, " %4u %4u %4u %4u %4u %4u %4u %4u")
  150961. JMESSAGE(JTRC_QUANT_3_NCOLORS, "Quantizing to %d = %d*%d*%d colors")
  150962. JMESSAGE(JTRC_QUANT_NCOLORS, "Quantizing to %d colors")
  150963. JMESSAGE(JTRC_QUANT_SELECTED, "Selected %d colors for quantization")
  150964. JMESSAGE(JTRC_RECOVERY_ACTION, "At marker 0x%02x, recovery action %d")
  150965. JMESSAGE(JTRC_RST, "RST%d")
  150966. JMESSAGE(JTRC_SMOOTH_NOTIMPL,
  150967. "Smoothing not supported with nonstandard sampling ratios")
  150968. JMESSAGE(JTRC_SOF, "Start Of Frame 0x%02x: width=%u, height=%u, components=%d")
  150969. JMESSAGE(JTRC_SOF_COMPONENT, " Component %d: %dhx%dv q=%d")
  150970. JMESSAGE(JTRC_SOI, "Start of Image")
  150971. JMESSAGE(JTRC_SOS, "Start Of Scan: %d components")
  150972. JMESSAGE(JTRC_SOS_COMPONENT, " Component %d: dc=%d ac=%d")
  150973. JMESSAGE(JTRC_SOS_PARAMS, " Ss=%d, Se=%d, Ah=%d, Al=%d")
  150974. JMESSAGE(JTRC_TFILE_CLOSE, "Closed temporary file %s")
  150975. JMESSAGE(JTRC_TFILE_OPEN, "Opened temporary file %s")
  150976. JMESSAGE(JTRC_THUMB_JPEG,
  150977. "JFIF extension marker: JPEG-compressed thumbnail image, length %u")
  150978. JMESSAGE(JTRC_THUMB_PALETTE,
  150979. "JFIF extension marker: palette thumbnail image, length %u")
  150980. JMESSAGE(JTRC_THUMB_RGB,
  150981. "JFIF extension marker: RGB thumbnail image, length %u")
  150982. JMESSAGE(JTRC_UNKNOWN_IDS,
  150983. "Unrecognized component IDs %d %d %d, assuming YCbCr")
  150984. JMESSAGE(JTRC_XMS_CLOSE, "Freed XMS handle %u")
  150985. JMESSAGE(JTRC_XMS_OPEN, "Obtained XMS handle %u")
  150986. JMESSAGE(JWRN_ADOBE_XFORM, "Unknown Adobe color transform code %d")
  150987. JMESSAGE(JWRN_BOGUS_PROGRESSION,
  150988. "Inconsistent progression sequence for component %d coefficient %d")
  150989. JMESSAGE(JWRN_EXTRANEOUS_DATA,
  150990. "Corrupt JPEG data: %u extraneous bytes before marker 0x%02x")
  150991. JMESSAGE(JWRN_HIT_MARKER, "Corrupt JPEG data: premature end of data segment")
  150992. JMESSAGE(JWRN_HUFF_BAD_CODE, "Corrupt JPEG data: bad Huffman code")
  150993. JMESSAGE(JWRN_JFIF_MAJOR, "Warning: unknown JFIF revision number %d.%02d")
  150994. JMESSAGE(JWRN_JPEG_EOF, "Premature end of JPEG file")
  150995. JMESSAGE(JWRN_MUST_RESYNC,
  150996. "Corrupt JPEG data: found marker 0x%02x instead of RST%d")
  150997. JMESSAGE(JWRN_NOT_SEQUENTIAL, "Invalid SOS parameters for sequential JPEG")
  150998. JMESSAGE(JWRN_TOO_MUCH_DATA, "Application transferred too many scanlines")
  150999. #ifdef JMAKE_ENUM_LIST
  151000. JMSG_LASTMSGCODE
  151001. } J_MESSAGE_CODE;
  151002. #undef JMAKE_ENUM_LIST
  151003. #endif /* JMAKE_ENUM_LIST */
  151004. #undef JMESSAGE
  151005. #ifndef JERROR_H
  151006. #define JERROR_H
  151007. #define ERREXIT(cinfo,code) \
  151008. ((cinfo)->err->msg_code = (code), \
  151009. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151010. #define ERREXIT1(cinfo,code,p1) \
  151011. ((cinfo)->err->msg_code = (code), \
  151012. (cinfo)->err->msg_parm.i[0] = (p1), \
  151013. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151014. #define ERREXIT2(cinfo,code,p1,p2) \
  151015. ((cinfo)->err->msg_code = (code), \
  151016. (cinfo)->err->msg_parm.i[0] = (p1), \
  151017. (cinfo)->err->msg_parm.i[1] = (p2), \
  151018. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151019. #define ERREXIT3(cinfo,code,p1,p2,p3) \
  151020. ((cinfo)->err->msg_code = (code), \
  151021. (cinfo)->err->msg_parm.i[0] = (p1), \
  151022. (cinfo)->err->msg_parm.i[1] = (p2), \
  151023. (cinfo)->err->msg_parm.i[2] = (p3), \
  151024. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151025. #define ERREXIT4(cinfo,code,p1,p2,p3,p4) \
  151026. ((cinfo)->err->msg_code = (code), \
  151027. (cinfo)->err->msg_parm.i[0] = (p1), \
  151028. (cinfo)->err->msg_parm.i[1] = (p2), \
  151029. (cinfo)->err->msg_parm.i[2] = (p3), \
  151030. (cinfo)->err->msg_parm.i[3] = (p4), \
  151031. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151032. #define ERREXITS(cinfo,code,str) \
  151033. ((cinfo)->err->msg_code = (code), \
  151034. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  151035. (*(cinfo)->err->error_exit) ((j_common_ptr) (cinfo)))
  151036. #define MAKESTMT(stuff) do { stuff } while (0)
  151037. #define WARNMS(cinfo,code) \
  151038. ((cinfo)->err->msg_code = (code), \
  151039. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151040. #define WARNMS1(cinfo,code,p1) \
  151041. ((cinfo)->err->msg_code = (code), \
  151042. (cinfo)->err->msg_parm.i[0] = (p1), \
  151043. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151044. #define WARNMS2(cinfo,code,p1,p2) \
  151045. ((cinfo)->err->msg_code = (code), \
  151046. (cinfo)->err->msg_parm.i[0] = (p1), \
  151047. (cinfo)->err->msg_parm.i[1] = (p2), \
  151048. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), -1))
  151049. #define TRACEMS(cinfo,lvl,code) \
  151050. ((cinfo)->err->msg_code = (code), \
  151051. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151052. #define TRACEMS1(cinfo,lvl,code,p1) \
  151053. ((cinfo)->err->msg_code = (code), \
  151054. (cinfo)->err->msg_parm.i[0] = (p1), \
  151055. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151056. #define TRACEMS2(cinfo,lvl,code,p1,p2) \
  151057. ((cinfo)->err->msg_code = (code), \
  151058. (cinfo)->err->msg_parm.i[0] = (p1), \
  151059. (cinfo)->err->msg_parm.i[1] = (p2), \
  151060. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151061. #define TRACEMS3(cinfo,lvl,code,p1,p2,p3) \
  151062. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151063. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); \
  151064. (cinfo)->err->msg_code = (code); \
  151065. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151066. #define TRACEMS4(cinfo,lvl,code,p1,p2,p3,p4) \
  151067. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151068. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151069. (cinfo)->err->msg_code = (code); \
  151070. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151071. #define TRACEMS5(cinfo,lvl,code,p1,p2,p3,p4,p5) \
  151072. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151073. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151074. _mp[4] = (p5); \
  151075. (cinfo)->err->msg_code = (code); \
  151076. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151077. #define TRACEMS8(cinfo,lvl,code,p1,p2,p3,p4,p5,p6,p7,p8) \
  151078. MAKESTMT(int * _mp = (cinfo)->err->msg_parm.i; \
  151079. _mp[0] = (p1); _mp[1] = (p2); _mp[2] = (p3); _mp[3] = (p4); \
  151080. _mp[4] = (p5); _mp[5] = (p6); _mp[6] = (p7); _mp[7] = (p8); \
  151081. (cinfo)->err->msg_code = (code); \
  151082. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)); )
  151083. #define TRACEMSS(cinfo,lvl,code,str) \
  151084. ((cinfo)->err->msg_code = (code), \
  151085. strncpy((cinfo)->err->msg_parm.s, (str), JMSG_STR_PARM_MAX), \
  151086. (*(cinfo)->err->emit_message) ((j_common_ptr) (cinfo), (lvl)))
  151087. #endif /* JERROR_H */
  151088. /*** End of inlined file: jerror.h ***/
  151089. typedef struct {
  151090. struct jpeg_source_mgr pub; /* public fields */
  151091. FILE * infile; /* source stream */
  151092. JOCTET * buffer; /* start of buffer */
  151093. boolean start_of_file; /* have we gotten any data yet? */
  151094. } my_source_mgr;
  151095. typedef my_source_mgr * my_src_ptr;
  151096. #define INPUT_BUF_SIZE 4096 /* choose an efficiently fread'able size */
  151097. METHODDEF(void)
  151098. init_source (j_decompress_ptr cinfo)
  151099. {
  151100. my_src_ptr src = (my_src_ptr) cinfo->src;
  151101. src->start_of_file = TRUE;
  151102. }
  151103. METHODDEF(boolean)
  151104. fill_input_buffer (j_decompress_ptr cinfo)
  151105. {
  151106. my_src_ptr src = (my_src_ptr) cinfo->src;
  151107. size_t nbytes;
  151108. nbytes = JFREAD(src->infile, src->buffer, INPUT_BUF_SIZE);
  151109. if (nbytes <= 0) {
  151110. if (src->start_of_file) /* Treat empty input file as fatal error */
  151111. ERREXIT(cinfo, JERR_INPUT_EMPTY);
  151112. WARNMS(cinfo, JWRN_JPEG_EOF);
  151113. src->buffer[0] = (JOCTET) 0xFF;
  151114. src->buffer[1] = (JOCTET) JPEG_EOI;
  151115. nbytes = 2;
  151116. }
  151117. src->pub.next_input_byte = src->buffer;
  151118. src->pub.bytes_in_buffer = nbytes;
  151119. src->start_of_file = FALSE;
  151120. return TRUE;
  151121. }
  151122. METHODDEF(void)
  151123. skip_input_data (j_decompress_ptr cinfo, long num_bytes)
  151124. {
  151125. my_src_ptr src = (my_src_ptr) cinfo->src;
  151126. if (num_bytes > 0) {
  151127. while (num_bytes > (long) src->pub.bytes_in_buffer) {
  151128. num_bytes -= (long) src->pub.bytes_in_buffer;
  151129. (void) fill_input_buffer(cinfo);
  151130. }
  151131. src->pub.next_input_byte += (size_t) num_bytes;
  151132. src->pub.bytes_in_buffer -= (size_t) num_bytes;
  151133. }
  151134. }
  151135. METHODDEF(void)
  151136. term_source (j_decompress_ptr cinfo)
  151137. {
  151138. }
  151139. GLOBAL(void)
  151140. jpeg_stdio_src (j_decompress_ptr cinfo, FILE * infile)
  151141. {
  151142. my_src_ptr src;
  151143. if (cinfo->src == NULL) { /* first time for this JPEG object? */
  151144. cinfo->src = (struct jpeg_source_mgr *)
  151145. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  151146. SIZEOF(my_source_mgr));
  151147. src = (my_src_ptr) cinfo->src;
  151148. src->buffer = (JOCTET *)
  151149. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  151150. INPUT_BUF_SIZE * SIZEOF(JOCTET));
  151151. }
  151152. src = (my_src_ptr) cinfo->src;
  151153. src->pub.init_source = init_source;
  151154. src->pub.fill_input_buffer = fill_input_buffer;
  151155. src->pub.skip_input_data = skip_input_data;
  151156. src->pub.resync_to_restart = jpeg_resync_to_restart; /* use default method */
  151157. src->pub.term_source = term_source;
  151158. src->infile = infile;
  151159. src->pub.bytes_in_buffer = 0; /* forces fill_input_buffer on first read */
  151160. src->pub.next_input_byte = NULL; /* until buffer loaded */
  151161. }
  151162. /*** End of inlined file: jdatasrc.c ***/
  151163. /*** Start of inlined file: jdcoefct.c ***/
  151164. #define JPEG_INTERNALS
  151165. #ifndef D_PROGRESSIVE_SUPPORTED
  151166. #undef BLOCK_SMOOTHING_SUPPORTED
  151167. #endif
  151168. typedef struct {
  151169. struct jpeg_d_coef_controller pub; /* public fields */
  151170. JDIMENSION MCU_ctr; /* counts MCUs processed in current row */
  151171. int MCU_vert_offset; /* counts MCU rows within iMCU row */
  151172. int MCU_rows_per_iMCU_row; /* number of such rows needed */
  151173. JBLOCKROW MCU_buffer[D_MAX_BLOCKS_IN_MCU];
  151174. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151175. jvirt_barray_ptr whole_image[MAX_COMPONENTS];
  151176. #endif
  151177. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151178. int * coef_bits_latch;
  151179. #define SAVED_COEFS 6 /* we save coef_bits[0..5] */
  151180. #endif
  151181. } my_coef_controller3;
  151182. typedef my_coef_controller3 * my_coef_ptr3;
  151183. METHODDEF(int) decompress_onepass
  151184. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151185. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151186. METHODDEF(int) decompress_data
  151187. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151188. #endif
  151189. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151190. LOCAL(boolean) smoothing_ok JPP((j_decompress_ptr cinfo));
  151191. METHODDEF(int) decompress_smooth_data
  151192. JPP((j_decompress_ptr cinfo, JSAMPIMAGE output_buf));
  151193. #endif
  151194. LOCAL(void)
  151195. start_iMCU_row3 (j_decompress_ptr cinfo)
  151196. {
  151197. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151198. if (cinfo->comps_in_scan > 1) {
  151199. coef->MCU_rows_per_iMCU_row = 1;
  151200. } else {
  151201. if (cinfo->input_iMCU_row < (cinfo->total_iMCU_rows-1))
  151202. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->v_samp_factor;
  151203. else
  151204. coef->MCU_rows_per_iMCU_row = cinfo->cur_comp_info[0]->last_row_height;
  151205. }
  151206. coef->MCU_ctr = 0;
  151207. coef->MCU_vert_offset = 0;
  151208. }
  151209. METHODDEF(void)
  151210. start_input_pass (j_decompress_ptr cinfo)
  151211. {
  151212. cinfo->input_iMCU_row = 0;
  151213. start_iMCU_row3(cinfo);
  151214. }
  151215. METHODDEF(void)
  151216. start_output_pass (j_decompress_ptr cinfo)
  151217. {
  151218. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151219. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151220. if (coef->pub.coef_arrays != NULL) {
  151221. if (cinfo->do_block_smoothing && smoothing_ok(cinfo))
  151222. coef->pub.decompress_data = decompress_smooth_data;
  151223. else
  151224. coef->pub.decompress_data = decompress_data;
  151225. }
  151226. #endif
  151227. cinfo->output_iMCU_row = 0;
  151228. }
  151229. METHODDEF(int)
  151230. decompress_onepass (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151231. {
  151232. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151233. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151234. JDIMENSION last_MCU_col = cinfo->MCUs_per_row - 1;
  151235. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151236. int blkn, ci, xindex, yindex, yoffset, useful_width;
  151237. JSAMPARRAY output_ptr;
  151238. JDIMENSION start_col, output_col;
  151239. jpeg_component_info *compptr;
  151240. inverse_DCT_method_ptr inverse_DCT;
  151241. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151242. yoffset++) {
  151243. for (MCU_col_num = coef->MCU_ctr; MCU_col_num <= last_MCU_col;
  151244. MCU_col_num++) {
  151245. jzero_far((void FAR *) coef->MCU_buffer[0],
  151246. (size_t) (cinfo->blocks_in_MCU * SIZEOF(JBLOCK)));
  151247. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151248. coef->MCU_vert_offset = yoffset;
  151249. coef->MCU_ctr = MCU_col_num;
  151250. return JPEG_SUSPENDED;
  151251. }
  151252. blkn = 0; /* index of current DCT block within MCU */
  151253. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151254. compptr = cinfo->cur_comp_info[ci];
  151255. if (! compptr->component_needed) {
  151256. blkn += compptr->MCU_blocks;
  151257. continue;
  151258. }
  151259. inverse_DCT = cinfo->idct->inverse_DCT[compptr->component_index];
  151260. useful_width = (MCU_col_num < last_MCU_col) ? compptr->MCU_width
  151261. : compptr->last_col_width;
  151262. output_ptr = output_buf[compptr->component_index] +
  151263. yoffset * compptr->DCT_scaled_size;
  151264. start_col = MCU_col_num * compptr->MCU_sample_width;
  151265. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151266. if (cinfo->input_iMCU_row < last_iMCU_row ||
  151267. yoffset+yindex < compptr->last_row_height) {
  151268. output_col = start_col;
  151269. for (xindex = 0; xindex < useful_width; xindex++) {
  151270. (*inverse_DCT) (cinfo, compptr,
  151271. (JCOEFPTR) coef->MCU_buffer[blkn+xindex],
  151272. output_ptr, output_col);
  151273. output_col += compptr->DCT_scaled_size;
  151274. }
  151275. }
  151276. blkn += compptr->MCU_width;
  151277. output_ptr += compptr->DCT_scaled_size;
  151278. }
  151279. }
  151280. }
  151281. coef->MCU_ctr = 0;
  151282. }
  151283. cinfo->output_iMCU_row++;
  151284. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151285. start_iMCU_row3(cinfo);
  151286. return JPEG_ROW_COMPLETED;
  151287. }
  151288. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151289. return JPEG_SCAN_COMPLETED;
  151290. }
  151291. METHODDEF(int)
  151292. dummy_consume_data (j_decompress_ptr cinfo)
  151293. {
  151294. return JPEG_SUSPENDED; /* Always indicate nothing was done */
  151295. }
  151296. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151297. METHODDEF(int)
  151298. consume_data (j_decompress_ptr cinfo)
  151299. {
  151300. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151301. JDIMENSION MCU_col_num; /* index of current MCU within row */
  151302. int blkn, ci, xindex, yindex, yoffset;
  151303. JDIMENSION start_col;
  151304. JBLOCKARRAY buffer[MAX_COMPS_IN_SCAN];
  151305. JBLOCKROW buffer_ptr;
  151306. jpeg_component_info *compptr;
  151307. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151308. compptr = cinfo->cur_comp_info[ci];
  151309. buffer[ci] = (*cinfo->mem->access_virt_barray)
  151310. ((j_common_ptr) cinfo, coef->whole_image[compptr->component_index],
  151311. cinfo->input_iMCU_row * compptr->v_samp_factor,
  151312. (JDIMENSION) compptr->v_samp_factor, TRUE);
  151313. }
  151314. for (yoffset = coef->MCU_vert_offset; yoffset < coef->MCU_rows_per_iMCU_row;
  151315. yoffset++) {
  151316. for (MCU_col_num = coef->MCU_ctr; MCU_col_num < cinfo->MCUs_per_row;
  151317. MCU_col_num++) {
  151318. blkn = 0; /* index of current DCT block within MCU */
  151319. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  151320. compptr = cinfo->cur_comp_info[ci];
  151321. start_col = MCU_col_num * compptr->MCU_width;
  151322. for (yindex = 0; yindex < compptr->MCU_height; yindex++) {
  151323. buffer_ptr = buffer[ci][yindex+yoffset] + start_col;
  151324. for (xindex = 0; xindex < compptr->MCU_width; xindex++) {
  151325. coef->MCU_buffer[blkn++] = buffer_ptr++;
  151326. }
  151327. }
  151328. }
  151329. if (! (*cinfo->entropy->decode_mcu) (cinfo, coef->MCU_buffer)) {
  151330. coef->MCU_vert_offset = yoffset;
  151331. coef->MCU_ctr = MCU_col_num;
  151332. return JPEG_SUSPENDED;
  151333. }
  151334. }
  151335. coef->MCU_ctr = 0;
  151336. }
  151337. if (++(cinfo->input_iMCU_row) < cinfo->total_iMCU_rows) {
  151338. start_iMCU_row3(cinfo);
  151339. return JPEG_ROW_COMPLETED;
  151340. }
  151341. (*cinfo->inputctl->finish_input_pass) (cinfo);
  151342. return JPEG_SCAN_COMPLETED;
  151343. }
  151344. METHODDEF(int)
  151345. decompress_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151346. {
  151347. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151348. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151349. JDIMENSION block_num;
  151350. int ci, block_row, block_rows;
  151351. JBLOCKARRAY buffer;
  151352. JBLOCKROW buffer_ptr;
  151353. JSAMPARRAY output_ptr;
  151354. JDIMENSION output_col;
  151355. jpeg_component_info *compptr;
  151356. inverse_DCT_method_ptr inverse_DCT;
  151357. while (cinfo->input_scan_number < cinfo->output_scan_number ||
  151358. (cinfo->input_scan_number == cinfo->output_scan_number &&
  151359. cinfo->input_iMCU_row <= cinfo->output_iMCU_row)) {
  151360. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151361. return JPEG_SUSPENDED;
  151362. }
  151363. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151364. ci++, compptr++) {
  151365. if (! compptr->component_needed)
  151366. continue;
  151367. buffer = (*cinfo->mem->access_virt_barray)
  151368. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151369. cinfo->output_iMCU_row * compptr->v_samp_factor,
  151370. (JDIMENSION) compptr->v_samp_factor, FALSE);
  151371. if (cinfo->output_iMCU_row < last_iMCU_row)
  151372. block_rows = compptr->v_samp_factor;
  151373. else {
  151374. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151375. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151376. }
  151377. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151378. output_ptr = output_buf[ci];
  151379. for (block_row = 0; block_row < block_rows; block_row++) {
  151380. buffer_ptr = buffer[block_row];
  151381. output_col = 0;
  151382. for (block_num = 0; block_num < compptr->width_in_blocks; block_num++) {
  151383. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) buffer_ptr,
  151384. output_ptr, output_col);
  151385. buffer_ptr++;
  151386. output_col += compptr->DCT_scaled_size;
  151387. }
  151388. output_ptr += compptr->DCT_scaled_size;
  151389. }
  151390. }
  151391. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151392. return JPEG_ROW_COMPLETED;
  151393. return JPEG_SCAN_COMPLETED;
  151394. }
  151395. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  151396. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151397. #define Q01_POS 1
  151398. #define Q10_POS 8
  151399. #define Q20_POS 16
  151400. #define Q11_POS 9
  151401. #define Q02_POS 2
  151402. LOCAL(boolean)
  151403. smoothing_ok (j_decompress_ptr cinfo)
  151404. {
  151405. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151406. boolean smoothing_useful = FALSE;
  151407. int ci, coefi;
  151408. jpeg_component_info *compptr;
  151409. JQUANT_TBL * qtable;
  151410. int * coef_bits;
  151411. int * coef_bits_latch;
  151412. if (! cinfo->progressive_mode || cinfo->coef_bits == NULL)
  151413. return FALSE;
  151414. if (coef->coef_bits_latch == NULL)
  151415. coef->coef_bits_latch = (int *)
  151416. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151417. cinfo->num_components *
  151418. (SAVED_COEFS * SIZEOF(int)));
  151419. coef_bits_latch = coef->coef_bits_latch;
  151420. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151421. ci++, compptr++) {
  151422. if ((qtable = compptr->quant_table) == NULL)
  151423. return FALSE;
  151424. if (qtable->quantval[0] == 0 ||
  151425. qtable->quantval[Q01_POS] == 0 ||
  151426. qtable->quantval[Q10_POS] == 0 ||
  151427. qtable->quantval[Q20_POS] == 0 ||
  151428. qtable->quantval[Q11_POS] == 0 ||
  151429. qtable->quantval[Q02_POS] == 0)
  151430. return FALSE;
  151431. coef_bits = cinfo->coef_bits[ci];
  151432. if (coef_bits[0] < 0)
  151433. return FALSE;
  151434. for (coefi = 1; coefi <= 5; coefi++) {
  151435. coef_bits_latch[coefi] = coef_bits[coefi];
  151436. if (coef_bits[coefi] != 0)
  151437. smoothing_useful = TRUE;
  151438. }
  151439. coef_bits_latch += SAVED_COEFS;
  151440. }
  151441. return smoothing_useful;
  151442. }
  151443. METHODDEF(int)
  151444. decompress_smooth_data (j_decompress_ptr cinfo, JSAMPIMAGE output_buf)
  151445. {
  151446. my_coef_ptr3 coef = (my_coef_ptr3) cinfo->coef;
  151447. JDIMENSION last_iMCU_row = cinfo->total_iMCU_rows - 1;
  151448. JDIMENSION block_num, last_block_column;
  151449. int ci, block_row, block_rows, access_rows;
  151450. JBLOCKARRAY buffer;
  151451. JBLOCKROW buffer_ptr, prev_block_row, next_block_row;
  151452. JSAMPARRAY output_ptr;
  151453. JDIMENSION output_col;
  151454. jpeg_component_info *compptr;
  151455. inverse_DCT_method_ptr inverse_DCT;
  151456. boolean first_row, last_row;
  151457. JBLOCK workspace;
  151458. int *coef_bits;
  151459. JQUANT_TBL *quanttbl;
  151460. INT32 Q00,Q01,Q02,Q10,Q11,Q20, num;
  151461. int DC1,DC2,DC3,DC4,DC5,DC6,DC7,DC8,DC9;
  151462. int Al, pred;
  151463. while (cinfo->input_scan_number <= cinfo->output_scan_number &&
  151464. ! cinfo->inputctl->eoi_reached) {
  151465. if (cinfo->input_scan_number == cinfo->output_scan_number) {
  151466. JDIMENSION delta = (cinfo->Ss == 0) ? 1 : 0;
  151467. if (cinfo->input_iMCU_row > cinfo->output_iMCU_row+delta)
  151468. break;
  151469. }
  151470. if ((*cinfo->inputctl->consume_input)(cinfo) == JPEG_SUSPENDED)
  151471. return JPEG_SUSPENDED;
  151472. }
  151473. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151474. ci++, compptr++) {
  151475. if (! compptr->component_needed)
  151476. continue;
  151477. if (cinfo->output_iMCU_row < last_iMCU_row) {
  151478. block_rows = compptr->v_samp_factor;
  151479. access_rows = block_rows * 2; /* this and next iMCU row */
  151480. last_row = FALSE;
  151481. } else {
  151482. block_rows = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  151483. if (block_rows == 0) block_rows = compptr->v_samp_factor;
  151484. access_rows = block_rows; /* this iMCU row only */
  151485. last_row = TRUE;
  151486. }
  151487. if (cinfo->output_iMCU_row > 0) {
  151488. access_rows += compptr->v_samp_factor; /* prior iMCU row too */
  151489. buffer = (*cinfo->mem->access_virt_barray)
  151490. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151491. (cinfo->output_iMCU_row - 1) * compptr->v_samp_factor,
  151492. (JDIMENSION) access_rows, FALSE);
  151493. buffer += compptr->v_samp_factor; /* point to current iMCU row */
  151494. first_row = FALSE;
  151495. } else {
  151496. buffer = (*cinfo->mem->access_virt_barray)
  151497. ((j_common_ptr) cinfo, coef->whole_image[ci],
  151498. (JDIMENSION) 0, (JDIMENSION) access_rows, FALSE);
  151499. first_row = TRUE;
  151500. }
  151501. coef_bits = coef->coef_bits_latch + (ci * SAVED_COEFS);
  151502. quanttbl = compptr->quant_table;
  151503. Q00 = quanttbl->quantval[0];
  151504. Q01 = quanttbl->quantval[Q01_POS];
  151505. Q10 = quanttbl->quantval[Q10_POS];
  151506. Q20 = quanttbl->quantval[Q20_POS];
  151507. Q11 = quanttbl->quantval[Q11_POS];
  151508. Q02 = quanttbl->quantval[Q02_POS];
  151509. inverse_DCT = cinfo->idct->inverse_DCT[ci];
  151510. output_ptr = output_buf[ci];
  151511. for (block_row = 0; block_row < block_rows; block_row++) {
  151512. buffer_ptr = buffer[block_row];
  151513. if (first_row && block_row == 0)
  151514. prev_block_row = buffer_ptr;
  151515. else
  151516. prev_block_row = buffer[block_row-1];
  151517. if (last_row && block_row == block_rows-1)
  151518. next_block_row = buffer_ptr;
  151519. else
  151520. next_block_row = buffer[block_row+1];
  151521. DC1 = DC2 = DC3 = (int) prev_block_row[0][0];
  151522. DC4 = DC5 = DC6 = (int) buffer_ptr[0][0];
  151523. DC7 = DC8 = DC9 = (int) next_block_row[0][0];
  151524. output_col = 0;
  151525. last_block_column = compptr->width_in_blocks - 1;
  151526. for (block_num = 0; block_num <= last_block_column; block_num++) {
  151527. jcopy_block_row(buffer_ptr, (JBLOCKROW) workspace, (JDIMENSION) 1);
  151528. if (block_num < last_block_column) {
  151529. DC3 = (int) prev_block_row[1][0];
  151530. DC6 = (int) buffer_ptr[1][0];
  151531. DC9 = (int) next_block_row[1][0];
  151532. }
  151533. if ((Al=coef_bits[1]) != 0 && workspace[1] == 0) {
  151534. num = 36 * Q00 * (DC4 - DC6);
  151535. if (num >= 0) {
  151536. pred = (int) (((Q01<<7) + num) / (Q01<<8));
  151537. if (Al > 0 && pred >= (1<<Al))
  151538. pred = (1<<Al)-1;
  151539. } else {
  151540. pred = (int) (((Q01<<7) - num) / (Q01<<8));
  151541. if (Al > 0 && pred >= (1<<Al))
  151542. pred = (1<<Al)-1;
  151543. pred = -pred;
  151544. }
  151545. workspace[1] = (JCOEF) pred;
  151546. }
  151547. if ((Al=coef_bits[2]) != 0 && workspace[8] == 0) {
  151548. num = 36 * Q00 * (DC2 - DC8);
  151549. if (num >= 0) {
  151550. pred = (int) (((Q10<<7) + num) / (Q10<<8));
  151551. if (Al > 0 && pred >= (1<<Al))
  151552. pred = (1<<Al)-1;
  151553. } else {
  151554. pred = (int) (((Q10<<7) - num) / (Q10<<8));
  151555. if (Al > 0 && pred >= (1<<Al))
  151556. pred = (1<<Al)-1;
  151557. pred = -pred;
  151558. }
  151559. workspace[8] = (JCOEF) pred;
  151560. }
  151561. if ((Al=coef_bits[3]) != 0 && workspace[16] == 0) {
  151562. num = 9 * Q00 * (DC2 + DC8 - 2*DC5);
  151563. if (num >= 0) {
  151564. pred = (int) (((Q20<<7) + num) / (Q20<<8));
  151565. if (Al > 0 && pred >= (1<<Al))
  151566. pred = (1<<Al)-1;
  151567. } else {
  151568. pred = (int) (((Q20<<7) - num) / (Q20<<8));
  151569. if (Al > 0 && pred >= (1<<Al))
  151570. pred = (1<<Al)-1;
  151571. pred = -pred;
  151572. }
  151573. workspace[16] = (JCOEF) pred;
  151574. }
  151575. if ((Al=coef_bits[4]) != 0 && workspace[9] == 0) {
  151576. num = 5 * Q00 * (DC1 - DC3 - DC7 + DC9);
  151577. if (num >= 0) {
  151578. pred = (int) (((Q11<<7) + num) / (Q11<<8));
  151579. if (Al > 0 && pred >= (1<<Al))
  151580. pred = (1<<Al)-1;
  151581. } else {
  151582. pred = (int) (((Q11<<7) - num) / (Q11<<8));
  151583. if (Al > 0 && pred >= (1<<Al))
  151584. pred = (1<<Al)-1;
  151585. pred = -pred;
  151586. }
  151587. workspace[9] = (JCOEF) pred;
  151588. }
  151589. if ((Al=coef_bits[5]) != 0 && workspace[2] == 0) {
  151590. num = 9 * Q00 * (DC4 + DC6 - 2*DC5);
  151591. if (num >= 0) {
  151592. pred = (int) (((Q02<<7) + num) / (Q02<<8));
  151593. if (Al > 0 && pred >= (1<<Al))
  151594. pred = (1<<Al)-1;
  151595. } else {
  151596. pred = (int) (((Q02<<7) - num) / (Q02<<8));
  151597. if (Al > 0 && pred >= (1<<Al))
  151598. pred = (1<<Al)-1;
  151599. pred = -pred;
  151600. }
  151601. workspace[2] = (JCOEF) pred;
  151602. }
  151603. (*inverse_DCT) (cinfo, compptr, (JCOEFPTR) workspace,
  151604. output_ptr, output_col);
  151605. DC1 = DC2; DC2 = DC3;
  151606. DC4 = DC5; DC5 = DC6;
  151607. DC7 = DC8; DC8 = DC9;
  151608. buffer_ptr++, prev_block_row++, next_block_row++;
  151609. output_col += compptr->DCT_scaled_size;
  151610. }
  151611. output_ptr += compptr->DCT_scaled_size;
  151612. }
  151613. }
  151614. if (++(cinfo->output_iMCU_row) < cinfo->total_iMCU_rows)
  151615. return JPEG_ROW_COMPLETED;
  151616. return JPEG_SCAN_COMPLETED;
  151617. }
  151618. #endif /* BLOCK_SMOOTHING_SUPPORTED */
  151619. GLOBAL(void)
  151620. jinit_d_coef_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  151621. {
  151622. my_coef_ptr3 coef;
  151623. coef = (my_coef_ptr3)
  151624. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151625. SIZEOF(my_coef_controller3));
  151626. cinfo->coef = (struct jpeg_d_coef_controller *) coef;
  151627. coef->pub.start_input_pass = start_input_pass;
  151628. coef->pub.start_output_pass = start_output_pass;
  151629. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151630. coef->coef_bits_latch = NULL;
  151631. #endif
  151632. if (need_full_buffer) {
  151633. #ifdef D_MULTISCAN_FILES_SUPPORTED
  151634. int ci, access_rows;
  151635. jpeg_component_info *compptr;
  151636. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151637. ci++, compptr++) {
  151638. access_rows = compptr->v_samp_factor;
  151639. #ifdef BLOCK_SMOOTHING_SUPPORTED
  151640. if (cinfo->progressive_mode)
  151641. access_rows *= 3;
  151642. #endif
  151643. coef->whole_image[ci] = (*cinfo->mem->request_virt_barray)
  151644. ((j_common_ptr) cinfo, JPOOL_IMAGE, TRUE,
  151645. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  151646. (long) compptr->h_samp_factor),
  151647. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  151648. (long) compptr->v_samp_factor),
  151649. (JDIMENSION) access_rows);
  151650. }
  151651. coef->pub.consume_data = consume_data;
  151652. coef->pub.decompress_data = decompress_data;
  151653. coef->pub.coef_arrays = coef->whole_image; /* link to virtual arrays */
  151654. #else
  151655. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151656. #endif
  151657. } else {
  151658. JBLOCKROW buffer;
  151659. int i;
  151660. buffer = (JBLOCKROW)
  151661. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151662. D_MAX_BLOCKS_IN_MCU * SIZEOF(JBLOCK));
  151663. for (i = 0; i < D_MAX_BLOCKS_IN_MCU; i++) {
  151664. coef->MCU_buffer[i] = buffer + i;
  151665. }
  151666. coef->pub.consume_data = dummy_consume_data;
  151667. coef->pub.decompress_data = decompress_onepass;
  151668. coef->pub.coef_arrays = NULL; /* flag for no virtual arrays */
  151669. }
  151670. }
  151671. /*** End of inlined file: jdcoefct.c ***/
  151672. #undef FIX
  151673. /*** Start of inlined file: jdcolor.c ***/
  151674. #define JPEG_INTERNALS
  151675. typedef struct {
  151676. struct jpeg_color_deconverter pub; /* public fields */
  151677. int * Cr_r_tab; /* => table for Cr to R conversion */
  151678. int * Cb_b_tab; /* => table for Cb to B conversion */
  151679. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  151680. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  151681. } my_color_deconverter2;
  151682. typedef my_color_deconverter2 * my_cconvert_ptr2;
  151683. #define SCALEBITS 16 /* speediest right-shift on some machines */
  151684. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  151685. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  151686. LOCAL(void)
  151687. build_ycc_rgb_table (j_decompress_ptr cinfo)
  151688. {
  151689. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151690. int i;
  151691. INT32 x;
  151692. SHIFT_TEMPS
  151693. cconvert->Cr_r_tab = (int *)
  151694. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151695. (MAXJSAMPLE+1) * SIZEOF(int));
  151696. cconvert->Cb_b_tab = (int *)
  151697. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151698. (MAXJSAMPLE+1) * SIZEOF(int));
  151699. cconvert->Cr_g_tab = (INT32 *)
  151700. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151701. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151702. cconvert->Cb_g_tab = (INT32 *)
  151703. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151704. (MAXJSAMPLE+1) * SIZEOF(INT32));
  151705. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  151706. cconvert->Cr_r_tab[i] = (int)
  151707. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  151708. cconvert->Cb_b_tab[i] = (int)
  151709. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  151710. cconvert->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  151711. cconvert->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  151712. }
  151713. }
  151714. METHODDEF(void)
  151715. ycc_rgb_convert (j_decompress_ptr cinfo,
  151716. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151717. JSAMPARRAY output_buf, int num_rows)
  151718. {
  151719. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151720. register int y, cb, cr;
  151721. register JSAMPROW outptr;
  151722. register JSAMPROW inptr0, inptr1, inptr2;
  151723. register JDIMENSION col;
  151724. JDIMENSION num_cols = cinfo->output_width;
  151725. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151726. register int * Crrtab = cconvert->Cr_r_tab;
  151727. register int * Cbbtab = cconvert->Cb_b_tab;
  151728. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151729. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151730. SHIFT_TEMPS
  151731. while (--num_rows >= 0) {
  151732. inptr0 = input_buf[0][input_row];
  151733. inptr1 = input_buf[1][input_row];
  151734. inptr2 = input_buf[2][input_row];
  151735. input_row++;
  151736. outptr = *output_buf++;
  151737. for (col = 0; col < num_cols; col++) {
  151738. y = GETJSAMPLE(inptr0[col]);
  151739. cb = GETJSAMPLE(inptr1[col]);
  151740. cr = GETJSAMPLE(inptr2[col]);
  151741. outptr[RGB_RED] = range_limit[y + Crrtab[cr]];
  151742. outptr[RGB_GREEN] = range_limit[y +
  151743. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151744. SCALEBITS))];
  151745. outptr[RGB_BLUE] = range_limit[y + Cbbtab[cb]];
  151746. outptr += RGB_PIXELSIZE;
  151747. }
  151748. }
  151749. }
  151750. METHODDEF(void)
  151751. null_convert2 (j_decompress_ptr cinfo,
  151752. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151753. JSAMPARRAY output_buf, int num_rows)
  151754. {
  151755. register JSAMPROW inptr, outptr;
  151756. register JDIMENSION count;
  151757. register int num_components = cinfo->num_components;
  151758. JDIMENSION num_cols = cinfo->output_width;
  151759. int ci;
  151760. while (--num_rows >= 0) {
  151761. for (ci = 0; ci < num_components; ci++) {
  151762. inptr = input_buf[ci][input_row];
  151763. outptr = output_buf[0] + ci;
  151764. for (count = num_cols; count > 0; count--) {
  151765. *outptr = *inptr++; /* needn't bother with GETJSAMPLE() here */
  151766. outptr += num_components;
  151767. }
  151768. }
  151769. input_row++;
  151770. output_buf++;
  151771. }
  151772. }
  151773. METHODDEF(void)
  151774. grayscale_convert2 (j_decompress_ptr cinfo,
  151775. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151776. JSAMPARRAY output_buf, int num_rows)
  151777. {
  151778. jcopy_sample_rows(input_buf[0], (int) input_row, output_buf, 0,
  151779. num_rows, cinfo->output_width);
  151780. }
  151781. METHODDEF(void)
  151782. gray_rgb_convert (j_decompress_ptr cinfo,
  151783. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151784. JSAMPARRAY output_buf, int num_rows)
  151785. {
  151786. register JSAMPROW inptr, outptr;
  151787. register JDIMENSION col;
  151788. JDIMENSION num_cols = cinfo->output_width;
  151789. while (--num_rows >= 0) {
  151790. inptr = input_buf[0][input_row++];
  151791. outptr = *output_buf++;
  151792. for (col = 0; col < num_cols; col++) {
  151793. outptr[RGB_RED] = outptr[RGB_GREEN] = outptr[RGB_BLUE] = inptr[col];
  151794. outptr += RGB_PIXELSIZE;
  151795. }
  151796. }
  151797. }
  151798. METHODDEF(void)
  151799. ycck_cmyk_convert (j_decompress_ptr cinfo,
  151800. JSAMPIMAGE input_buf, JDIMENSION input_row,
  151801. JSAMPARRAY output_buf, int num_rows)
  151802. {
  151803. my_cconvert_ptr2 cconvert = (my_cconvert_ptr2) cinfo->cconvert;
  151804. register int y, cb, cr;
  151805. register JSAMPROW outptr;
  151806. register JSAMPROW inptr0, inptr1, inptr2, inptr3;
  151807. register JDIMENSION col;
  151808. JDIMENSION num_cols = cinfo->output_width;
  151809. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  151810. register int * Crrtab = cconvert->Cr_r_tab;
  151811. register int * Cbbtab = cconvert->Cb_b_tab;
  151812. register INT32 * Crgtab = cconvert->Cr_g_tab;
  151813. register INT32 * Cbgtab = cconvert->Cb_g_tab;
  151814. SHIFT_TEMPS
  151815. while (--num_rows >= 0) {
  151816. inptr0 = input_buf[0][input_row];
  151817. inptr1 = input_buf[1][input_row];
  151818. inptr2 = input_buf[2][input_row];
  151819. inptr3 = input_buf[3][input_row];
  151820. input_row++;
  151821. outptr = *output_buf++;
  151822. for (col = 0; col < num_cols; col++) {
  151823. y = GETJSAMPLE(inptr0[col]);
  151824. cb = GETJSAMPLE(inptr1[col]);
  151825. cr = GETJSAMPLE(inptr2[col]);
  151826. outptr[0] = range_limit[MAXJSAMPLE - (y + Crrtab[cr])]; /* red */
  151827. outptr[1] = range_limit[MAXJSAMPLE - (y + /* green */
  151828. ((int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr],
  151829. SCALEBITS)))];
  151830. outptr[2] = range_limit[MAXJSAMPLE - (y + Cbbtab[cb])]; /* blue */
  151831. outptr[3] = inptr3[col]; /* don't need GETJSAMPLE here */
  151832. outptr += 4;
  151833. }
  151834. }
  151835. }
  151836. METHODDEF(void)
  151837. start_pass_dcolor (j_decompress_ptr cinfo)
  151838. {
  151839. }
  151840. GLOBAL(void)
  151841. jinit_color_deconverter (j_decompress_ptr cinfo)
  151842. {
  151843. my_cconvert_ptr2 cconvert;
  151844. int ci;
  151845. cconvert = (my_cconvert_ptr2)
  151846. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  151847. SIZEOF(my_color_deconverter2));
  151848. cinfo->cconvert = (struct jpeg_color_deconverter *) cconvert;
  151849. cconvert->pub.start_pass = start_pass_dcolor;
  151850. switch (cinfo->jpeg_color_space) {
  151851. case JCS_GRAYSCALE:
  151852. if (cinfo->num_components != 1)
  151853. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151854. break;
  151855. case JCS_RGB:
  151856. case JCS_YCbCr:
  151857. if (cinfo->num_components != 3)
  151858. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151859. break;
  151860. case JCS_CMYK:
  151861. case JCS_YCCK:
  151862. if (cinfo->num_components != 4)
  151863. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151864. break;
  151865. default: /* JCS_UNKNOWN can be anything */
  151866. if (cinfo->num_components < 1)
  151867. ERREXIT(cinfo, JERR_BAD_J_COLORSPACE);
  151868. break;
  151869. }
  151870. switch (cinfo->out_color_space) {
  151871. case JCS_GRAYSCALE:
  151872. cinfo->out_color_components = 1;
  151873. if (cinfo->jpeg_color_space == JCS_GRAYSCALE ||
  151874. cinfo->jpeg_color_space == JCS_YCbCr) {
  151875. cconvert->pub.color_convert = grayscale_convert2;
  151876. for (ci = 1; ci < cinfo->num_components; ci++)
  151877. cinfo->comp_info[ci].component_needed = FALSE;
  151878. } else
  151879. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151880. break;
  151881. case JCS_RGB:
  151882. cinfo->out_color_components = RGB_PIXELSIZE;
  151883. if (cinfo->jpeg_color_space == JCS_YCbCr) {
  151884. cconvert->pub.color_convert = ycc_rgb_convert;
  151885. build_ycc_rgb_table(cinfo);
  151886. } else if (cinfo->jpeg_color_space == JCS_GRAYSCALE) {
  151887. cconvert->pub.color_convert = gray_rgb_convert;
  151888. } else if (cinfo->jpeg_color_space == JCS_RGB && RGB_PIXELSIZE == 3) {
  151889. cconvert->pub.color_convert = null_convert2;
  151890. } else
  151891. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151892. break;
  151893. case JCS_CMYK:
  151894. cinfo->out_color_components = 4;
  151895. if (cinfo->jpeg_color_space == JCS_YCCK) {
  151896. cconvert->pub.color_convert = ycck_cmyk_convert;
  151897. build_ycc_rgb_table(cinfo);
  151898. } else if (cinfo->jpeg_color_space == JCS_CMYK) {
  151899. cconvert->pub.color_convert = null_convert2;
  151900. } else
  151901. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151902. break;
  151903. default:
  151904. if (cinfo->out_color_space == cinfo->jpeg_color_space) {
  151905. cinfo->out_color_components = cinfo->num_components;
  151906. cconvert->pub.color_convert = null_convert2;
  151907. } else /* unsupported non-null conversion */
  151908. ERREXIT(cinfo, JERR_CONVERSION_NOTIMPL);
  151909. break;
  151910. }
  151911. if (cinfo->quantize_colors)
  151912. cinfo->output_components = 1; /* single colormapped output component */
  151913. else
  151914. cinfo->output_components = cinfo->out_color_components;
  151915. }
  151916. /*** End of inlined file: jdcolor.c ***/
  151917. #undef FIX
  151918. /*** Start of inlined file: jddctmgr.c ***/
  151919. #define JPEG_INTERNALS
  151920. typedef struct {
  151921. struct jpeg_inverse_dct pub; /* public fields */
  151922. int cur_method[MAX_COMPONENTS];
  151923. } my_idct_controller;
  151924. typedef my_idct_controller * my_idct_ptr;
  151925. typedef union {
  151926. ISLOW_MULT_TYPE islow_array[DCTSIZE2];
  151927. #ifdef DCT_IFAST_SUPPORTED
  151928. IFAST_MULT_TYPE ifast_array[DCTSIZE2];
  151929. #endif
  151930. #ifdef DCT_FLOAT_SUPPORTED
  151931. FLOAT_MULT_TYPE float_array[DCTSIZE2];
  151932. #endif
  151933. } multiplier_table;
  151934. #ifdef DCT_ISLOW_SUPPORTED
  151935. #define PROVIDE_ISLOW_TABLES
  151936. #else
  151937. #ifdef IDCT_SCALING_SUPPORTED
  151938. #define PROVIDE_ISLOW_TABLES
  151939. #endif
  151940. #endif
  151941. METHODDEF(void)
  151942. start_pass (j_decompress_ptr cinfo)
  151943. {
  151944. my_idct_ptr idct = (my_idct_ptr) cinfo->idct;
  151945. int ci, i;
  151946. jpeg_component_info *compptr;
  151947. int method = 0;
  151948. inverse_DCT_method_ptr method_ptr = NULL;
  151949. JQUANT_TBL * qtbl;
  151950. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  151951. ci++, compptr++) {
  151952. switch (compptr->DCT_scaled_size) {
  151953. #ifdef IDCT_SCALING_SUPPORTED
  151954. case 1:
  151955. method_ptr = jpeg_idct_1x1;
  151956. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151957. break;
  151958. case 2:
  151959. method_ptr = jpeg_idct_2x2;
  151960. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151961. break;
  151962. case 4:
  151963. method_ptr = jpeg_idct_4x4;
  151964. method = JDCT_ISLOW; /* jidctred uses islow-style table */
  151965. break;
  151966. #endif
  151967. case DCTSIZE:
  151968. switch (cinfo->dct_method) {
  151969. #ifdef DCT_ISLOW_SUPPORTED
  151970. case JDCT_ISLOW:
  151971. method_ptr = jpeg_idct_islow;
  151972. method = JDCT_ISLOW;
  151973. break;
  151974. #endif
  151975. #ifdef DCT_IFAST_SUPPORTED
  151976. case JDCT_IFAST:
  151977. method_ptr = jpeg_idct_ifast;
  151978. method = JDCT_IFAST;
  151979. break;
  151980. #endif
  151981. #ifdef DCT_FLOAT_SUPPORTED
  151982. case JDCT_FLOAT:
  151983. method_ptr = jpeg_idct_float;
  151984. method = JDCT_FLOAT;
  151985. break;
  151986. #endif
  151987. default:
  151988. ERREXIT(cinfo, JERR_NOT_COMPILED);
  151989. break;
  151990. }
  151991. break;
  151992. default:
  151993. ERREXIT1(cinfo, JERR_BAD_DCTSIZE, compptr->DCT_scaled_size);
  151994. break;
  151995. }
  151996. idct->pub.inverse_DCT[ci] = method_ptr;
  151997. if (! compptr->component_needed || idct->cur_method[ci] == method)
  151998. continue;
  151999. qtbl = compptr->quant_table;
  152000. if (qtbl == NULL) /* happens if no data yet for component */
  152001. continue;
  152002. idct->cur_method[ci] = method;
  152003. switch (method) {
  152004. #ifdef PROVIDE_ISLOW_TABLES
  152005. case JDCT_ISLOW:
  152006. {
  152007. ISLOW_MULT_TYPE * ismtbl = (ISLOW_MULT_TYPE *) compptr->dct_table;
  152008. for (i = 0; i < DCTSIZE2; i++) {
  152009. ismtbl[i] = (ISLOW_MULT_TYPE) qtbl->quantval[i];
  152010. }
  152011. }
  152012. break;
  152013. #endif
  152014. #ifdef DCT_IFAST_SUPPORTED
  152015. case JDCT_IFAST:
  152016. {
  152017. IFAST_MULT_TYPE * ifmtbl = (IFAST_MULT_TYPE *) compptr->dct_table;
  152018. #define CONST_BITS 14
  152019. static const INT16 aanscales[DCTSIZE2] = {
  152020. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  152021. 22725, 31521, 29692, 26722, 22725, 17855, 12299, 6270,
  152022. 21407, 29692, 27969, 25172, 21407, 16819, 11585, 5906,
  152023. 19266, 26722, 25172, 22654, 19266, 15137, 10426, 5315,
  152024. 16384, 22725, 21407, 19266, 16384, 12873, 8867, 4520,
  152025. 12873, 17855, 16819, 15137, 12873, 10114, 6967, 3552,
  152026. 8867, 12299, 11585, 10426, 8867, 6967, 4799, 2446,
  152027. 4520, 6270, 5906, 5315, 4520, 3552, 2446, 1247
  152028. };
  152029. SHIFT_TEMPS
  152030. for (i = 0; i < DCTSIZE2; i++) {
  152031. ifmtbl[i] = (IFAST_MULT_TYPE)
  152032. DESCALE(MULTIPLY16V16((INT32) qtbl->quantval[i],
  152033. (INT32) aanscales[i]),
  152034. CONST_BITS-IFAST_SCALE_BITS);
  152035. }
  152036. }
  152037. break;
  152038. #endif
  152039. #ifdef DCT_FLOAT_SUPPORTED
  152040. case JDCT_FLOAT:
  152041. {
  152042. FLOAT_MULT_TYPE * fmtbl = (FLOAT_MULT_TYPE *) compptr->dct_table;
  152043. int row, col;
  152044. static const double aanscalefactor[DCTSIZE] = {
  152045. 1.0, 1.387039845, 1.306562965, 1.175875602,
  152046. 1.0, 0.785694958, 0.541196100, 0.275899379
  152047. };
  152048. i = 0;
  152049. for (row = 0; row < DCTSIZE; row++) {
  152050. for (col = 0; col < DCTSIZE; col++) {
  152051. fmtbl[i] = (FLOAT_MULT_TYPE)
  152052. ((double) qtbl->quantval[i] *
  152053. aanscalefactor[row] * aanscalefactor[col]);
  152054. i++;
  152055. }
  152056. }
  152057. }
  152058. break;
  152059. #endif
  152060. default:
  152061. ERREXIT(cinfo, JERR_NOT_COMPILED);
  152062. break;
  152063. }
  152064. }
  152065. }
  152066. GLOBAL(void)
  152067. jinit_inverse_dct (j_decompress_ptr cinfo)
  152068. {
  152069. my_idct_ptr idct;
  152070. int ci;
  152071. jpeg_component_info *compptr;
  152072. idct = (my_idct_ptr)
  152073. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152074. SIZEOF(my_idct_controller));
  152075. cinfo->idct = (struct jpeg_inverse_dct *) idct;
  152076. idct->pub.start_pass = start_pass;
  152077. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152078. ci++, compptr++) {
  152079. compptr->dct_table =
  152080. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152081. SIZEOF(multiplier_table));
  152082. MEMZERO(compptr->dct_table, SIZEOF(multiplier_table));
  152083. idct->cur_method[ci] = -1;
  152084. }
  152085. }
  152086. /*** End of inlined file: jddctmgr.c ***/
  152087. #undef CONST_BITS
  152088. #undef ASSIGN_STATE
  152089. /*** Start of inlined file: jdhuff.c ***/
  152090. #define JPEG_INTERNALS
  152091. /*** Start of inlined file: jdhuff.h ***/
  152092. #ifndef __jdhuff_h__
  152093. #define __jdhuff_h__
  152094. #ifdef NEED_SHORT_EXTERNAL_NAMES
  152095. #define jpeg_make_d_derived_tbl jMkDDerived
  152096. #define jpeg_fill_bit_buffer jFilBitBuf
  152097. #define jpeg_huff_decode jHufDecode
  152098. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  152099. #define HUFF_LOOKAHEAD 8 /* # of bits of lookahead */
  152100. typedef struct {
  152101. INT32 maxcode[18]; /* largest code of length k (-1 if none) */
  152102. INT32 valoffset[17]; /* huffval[] offset for codes of length k */
  152103. JHUFF_TBL *pub;
  152104. int look_nbits[1<<HUFF_LOOKAHEAD]; /* # bits, or 0 if too long */
  152105. UINT8 look_sym[1<<HUFF_LOOKAHEAD]; /* symbol, or unused */
  152106. } d_derived_tbl;
  152107. EXTERN(void) jpeg_make_d_derived_tbl
  152108. JPP((j_decompress_ptr cinfo, boolean isDC, int tblno,
  152109. d_derived_tbl ** pdtbl));
  152110. typedef INT32 bit_buf_type; /* type of bit-extraction buffer */
  152111. #define BIT_BUF_SIZE 32 /* size of buffer in bits */
  152112. typedef struct { /* Bitreading state saved across MCUs */
  152113. bit_buf_type get_buffer; /* current bit-extraction buffer */
  152114. int bits_left; /* # of unused bits in it */
  152115. } bitread_perm_state;
  152116. typedef struct { /* Bitreading working state within an MCU */
  152117. const JOCTET * next_input_byte; /* => next byte to read from source */
  152118. size_t bytes_in_buffer; /* # of bytes remaining in source buffer */
  152119. bit_buf_type get_buffer; /* current bit-extraction buffer */
  152120. int bits_left; /* # of unused bits in it */
  152121. j_decompress_ptr cinfo; /* back link to decompress master record */
  152122. } bitread_working_state;
  152123. #define BITREAD_STATE_VARS \
  152124. register bit_buf_type get_buffer; \
  152125. register int bits_left; \
  152126. bitread_working_state br_state
  152127. #define BITREAD_LOAD_STATE(cinfop,permstate) \
  152128. br_state.cinfo = cinfop; \
  152129. br_state.next_input_byte = cinfop->src->next_input_byte; \
  152130. br_state.bytes_in_buffer = cinfop->src->bytes_in_buffer; \
  152131. get_buffer = permstate.get_buffer; \
  152132. bits_left = permstate.bits_left;
  152133. #define BITREAD_SAVE_STATE(cinfop,permstate) \
  152134. cinfop->src->next_input_byte = br_state.next_input_byte; \
  152135. cinfop->src->bytes_in_buffer = br_state.bytes_in_buffer; \
  152136. permstate.get_buffer = get_buffer; \
  152137. permstate.bits_left = bits_left
  152138. #define CHECK_BIT_BUFFER(state,nbits,action) \
  152139. { if (bits_left < (nbits)) { \
  152140. if (! jpeg_fill_bit_buffer(&(state),get_buffer,bits_left,nbits)) \
  152141. { action; } \
  152142. get_buffer = (state).get_buffer; bits_left = (state).bits_left; } }
  152143. #define GET_BITS(nbits) \
  152144. (((int) (get_buffer >> (bits_left -= (nbits)))) & ((1<<(nbits))-1))
  152145. #define PEEK_BITS(nbits) \
  152146. (((int) (get_buffer >> (bits_left - (nbits)))) & ((1<<(nbits))-1))
  152147. #define DROP_BITS(nbits) \
  152148. (bits_left -= (nbits))
  152149. EXTERN(boolean) jpeg_fill_bit_buffer
  152150. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  152151. register int bits_left, int nbits));
  152152. #define HUFF_DECODE(result,state,htbl,failaction,slowlabel) \
  152153. { register int nb, look; \
  152154. if (bits_left < HUFF_LOOKAHEAD) { \
  152155. if (! jpeg_fill_bit_buffer(&state,get_buffer,bits_left, 0)) {failaction;} \
  152156. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  152157. if (bits_left < HUFF_LOOKAHEAD) { \
  152158. nb = 1; goto slowlabel; \
  152159. } \
  152160. } \
  152161. look = PEEK_BITS(HUFF_LOOKAHEAD); \
  152162. if ((nb = htbl->look_nbits[look]) != 0) { \
  152163. DROP_BITS(nb); \
  152164. result = htbl->look_sym[look]; \
  152165. } else { \
  152166. nb = HUFF_LOOKAHEAD+1; \
  152167. slowlabel: \
  152168. if ((result=jpeg_huff_decode(&state,get_buffer,bits_left,htbl,nb)) < 0) \
  152169. { failaction; } \
  152170. get_buffer = state.get_buffer; bits_left = state.bits_left; \
  152171. } \
  152172. }
  152173. EXTERN(int) jpeg_huff_decode
  152174. JPP((bitread_working_state * state, register bit_buf_type get_buffer,
  152175. register int bits_left, d_derived_tbl * htbl, int min_bits));
  152176. #endif
  152177. /*** End of inlined file: jdhuff.h ***/
  152178. /* Declarations shared with jdphuff.c */
  152179. typedef struct {
  152180. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  152181. } savable_state2;
  152182. #ifndef NO_STRUCT_ASSIGN
  152183. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  152184. #else
  152185. #if MAX_COMPS_IN_SCAN == 4
  152186. #define ASSIGN_STATE(dest,src) \
  152187. ((dest).last_dc_val[0] = (src).last_dc_val[0], \
  152188. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  152189. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  152190. (dest).last_dc_val[3] = (src).last_dc_val[3])
  152191. #endif
  152192. #endif
  152193. typedef struct {
  152194. struct jpeg_entropy_decoder pub; /* public fields */
  152195. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  152196. savable_state2 saved; /* Other state at start of MCU */
  152197. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  152198. d_derived_tbl * dc_derived_tbls[NUM_HUFF_TBLS];
  152199. d_derived_tbl * ac_derived_tbls[NUM_HUFF_TBLS];
  152200. d_derived_tbl * dc_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  152201. d_derived_tbl * ac_cur_tbls[D_MAX_BLOCKS_IN_MCU];
  152202. boolean dc_needed[D_MAX_BLOCKS_IN_MCU];
  152203. boolean ac_needed[D_MAX_BLOCKS_IN_MCU];
  152204. } huff_entropy_decoder2;
  152205. typedef huff_entropy_decoder2 * huff_entropy_ptr2;
  152206. METHODDEF(void)
  152207. start_pass_huff_decoder (j_decompress_ptr cinfo)
  152208. {
  152209. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152210. int ci, blkn, dctbl, actbl;
  152211. jpeg_component_info * compptr;
  152212. if (cinfo->Ss != 0 || cinfo->Se != DCTSIZE2-1 ||
  152213. cinfo->Ah != 0 || cinfo->Al != 0)
  152214. WARNMS(cinfo, JWRN_NOT_SEQUENTIAL);
  152215. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152216. compptr = cinfo->cur_comp_info[ci];
  152217. dctbl = compptr->dc_tbl_no;
  152218. actbl = compptr->ac_tbl_no;
  152219. jpeg_make_d_derived_tbl(cinfo, TRUE, dctbl,
  152220. & entropy->dc_derived_tbls[dctbl]);
  152221. jpeg_make_d_derived_tbl(cinfo, FALSE, actbl,
  152222. & entropy->ac_derived_tbls[actbl]);
  152223. entropy->saved.last_dc_val[ci] = 0;
  152224. }
  152225. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152226. ci = cinfo->MCU_membership[blkn];
  152227. compptr = cinfo->cur_comp_info[ci];
  152228. entropy->dc_cur_tbls[blkn] = entropy->dc_derived_tbls[compptr->dc_tbl_no];
  152229. entropy->ac_cur_tbls[blkn] = entropy->ac_derived_tbls[compptr->ac_tbl_no];
  152230. if (compptr->component_needed) {
  152231. entropy->dc_needed[blkn] = TRUE;
  152232. entropy->ac_needed[blkn] = (compptr->DCT_scaled_size > 1);
  152233. } else {
  152234. entropy->dc_needed[blkn] = entropy->ac_needed[blkn] = FALSE;
  152235. }
  152236. }
  152237. entropy->bitstate.bits_left = 0;
  152238. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  152239. entropy->pub.insufficient_data = FALSE;
  152240. entropy->restarts_to_go = cinfo->restart_interval;
  152241. }
  152242. GLOBAL(void)
  152243. jpeg_make_d_derived_tbl (j_decompress_ptr cinfo, boolean isDC, int tblno,
  152244. d_derived_tbl ** pdtbl)
  152245. {
  152246. JHUFF_TBL *htbl;
  152247. d_derived_tbl *dtbl;
  152248. int p, i, l, si, numsymbols;
  152249. int lookbits, ctr;
  152250. char huffsize[257];
  152251. unsigned int huffcode[257];
  152252. unsigned int code;
  152253. if (tblno < 0 || tblno >= NUM_HUFF_TBLS)
  152254. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  152255. htbl =
  152256. isDC ? cinfo->dc_huff_tbl_ptrs[tblno] : cinfo->ac_huff_tbl_ptrs[tblno];
  152257. if (htbl == NULL)
  152258. ERREXIT1(cinfo, JERR_NO_HUFF_TABLE, tblno);
  152259. if (*pdtbl == NULL)
  152260. *pdtbl = (d_derived_tbl *)
  152261. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152262. SIZEOF(d_derived_tbl));
  152263. dtbl = *pdtbl;
  152264. dtbl->pub = htbl; /* fill in back link */
  152265. p = 0;
  152266. for (l = 1; l <= 16; l++) {
  152267. i = (int) htbl->bits[l];
  152268. if (i < 0 || p + i > 256) /* protect against table overrun */
  152269. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152270. while (i--)
  152271. huffsize[p++] = (char) l;
  152272. }
  152273. huffsize[p] = 0;
  152274. numsymbols = p;
  152275. code = 0;
  152276. si = huffsize[0];
  152277. p = 0;
  152278. while (huffsize[p]) {
  152279. while (((int) huffsize[p]) == si) {
  152280. huffcode[p++] = code;
  152281. code++;
  152282. }
  152283. if (((INT32) code) >= (((INT32) 1) << si))
  152284. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152285. code <<= 1;
  152286. si++;
  152287. }
  152288. p = 0;
  152289. for (l = 1; l <= 16; l++) {
  152290. if (htbl->bits[l]) {
  152291. dtbl->valoffset[l] = (INT32) p - (INT32) huffcode[p];
  152292. p += htbl->bits[l];
  152293. dtbl->maxcode[l] = huffcode[p-1]; /* maximum code of length l */
  152294. } else {
  152295. dtbl->maxcode[l] = -1; /* -1 if no codes of this length */
  152296. }
  152297. }
  152298. dtbl->maxcode[17] = 0xFFFFFL; /* ensures jpeg_huff_decode terminates */
  152299. MEMZERO(dtbl->look_nbits, SIZEOF(dtbl->look_nbits));
  152300. p = 0;
  152301. for (l = 1; l <= HUFF_LOOKAHEAD; l++) {
  152302. for (i = 1; i <= (int) htbl->bits[l]; i++, p++) {
  152303. lookbits = huffcode[p] << (HUFF_LOOKAHEAD-l);
  152304. for (ctr = 1 << (HUFF_LOOKAHEAD-l); ctr > 0; ctr--) {
  152305. dtbl->look_nbits[lookbits] = l;
  152306. dtbl->look_sym[lookbits] = htbl->huffval[p];
  152307. lookbits++;
  152308. }
  152309. }
  152310. }
  152311. if (isDC) {
  152312. for (i = 0; i < numsymbols; i++) {
  152313. int sym = htbl->huffval[i];
  152314. if (sym < 0 || sym > 15)
  152315. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  152316. }
  152317. }
  152318. }
  152319. #ifdef SLOW_SHIFT_32
  152320. #define MIN_GET_BITS 15 /* minimum allowable value */
  152321. #else
  152322. #define MIN_GET_BITS (BIT_BUF_SIZE-7)
  152323. #endif
  152324. GLOBAL(boolean)
  152325. jpeg_fill_bit_buffer (bitread_working_state * state,
  152326. register bit_buf_type get_buffer, register int bits_left,
  152327. int nbits)
  152328. {
  152329. register const JOCTET * next_input_byte = state->next_input_byte;
  152330. register size_t bytes_in_buffer = state->bytes_in_buffer;
  152331. j_decompress_ptr cinfo = state->cinfo;
  152332. if (cinfo->unread_marker == 0) { /* cannot advance past a marker */
  152333. while (bits_left < MIN_GET_BITS) {
  152334. register int c;
  152335. if (bytes_in_buffer == 0) {
  152336. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152337. return FALSE;
  152338. next_input_byte = cinfo->src->next_input_byte;
  152339. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152340. }
  152341. bytes_in_buffer--;
  152342. c = GETJOCTET(*next_input_byte++);
  152343. if (c == 0xFF) {
  152344. do {
  152345. if (bytes_in_buffer == 0) {
  152346. if (! (*cinfo->src->fill_input_buffer) (cinfo))
  152347. return FALSE;
  152348. next_input_byte = cinfo->src->next_input_byte;
  152349. bytes_in_buffer = cinfo->src->bytes_in_buffer;
  152350. }
  152351. bytes_in_buffer--;
  152352. c = GETJOCTET(*next_input_byte++);
  152353. } while (c == 0xFF);
  152354. if (c == 0) {
  152355. c = 0xFF;
  152356. } else {
  152357. cinfo->unread_marker = c;
  152358. goto no_more_bytes;
  152359. }
  152360. }
  152361. get_buffer = (get_buffer << 8) | c;
  152362. bits_left += 8;
  152363. } /* end while */
  152364. } else {
  152365. no_more_bytes:
  152366. if (nbits > bits_left) {
  152367. if (! cinfo->entropy->insufficient_data) {
  152368. WARNMS(cinfo, JWRN_HIT_MARKER);
  152369. cinfo->entropy->insufficient_data = TRUE;
  152370. }
  152371. get_buffer <<= MIN_GET_BITS - bits_left;
  152372. bits_left = MIN_GET_BITS;
  152373. }
  152374. }
  152375. state->next_input_byte = next_input_byte;
  152376. state->bytes_in_buffer = bytes_in_buffer;
  152377. state->get_buffer = get_buffer;
  152378. state->bits_left = bits_left;
  152379. return TRUE;
  152380. }
  152381. GLOBAL(int)
  152382. jpeg_huff_decode (bitread_working_state * state,
  152383. register bit_buf_type get_buffer, register int bits_left,
  152384. d_derived_tbl * htbl, int min_bits)
  152385. {
  152386. register int l = min_bits;
  152387. register INT32 code;
  152388. CHECK_BIT_BUFFER(*state, l, return -1);
  152389. code = GET_BITS(l);
  152390. while (code > htbl->maxcode[l]) {
  152391. code <<= 1;
  152392. CHECK_BIT_BUFFER(*state, 1, return -1);
  152393. code |= GET_BITS(1);
  152394. l++;
  152395. }
  152396. state->get_buffer = get_buffer;
  152397. state->bits_left = bits_left;
  152398. if (l > 16) {
  152399. WARNMS(state->cinfo, JWRN_HUFF_BAD_CODE);
  152400. return 0; /* fake a zero as the safest result */
  152401. }
  152402. return htbl->pub->huffval[ (int) (code + htbl->valoffset[l]) ];
  152403. }
  152404. LOCAL(boolean)
  152405. process_restart (j_decompress_ptr cinfo)
  152406. {
  152407. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152408. int ci;
  152409. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  152410. entropy->bitstate.bits_left = 0;
  152411. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  152412. return FALSE;
  152413. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  152414. entropy->saved.last_dc_val[ci] = 0;
  152415. entropy->restarts_to_go = cinfo->restart_interval;
  152416. if (cinfo->unread_marker == 0)
  152417. entropy->pub.insufficient_data = FALSE;
  152418. return TRUE;
  152419. }
  152420. METHODDEF(boolean)
  152421. decode_mcu (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  152422. {
  152423. huff_entropy_ptr2 entropy = (huff_entropy_ptr2) cinfo->entropy;
  152424. int blkn;
  152425. BITREAD_STATE_VARS;
  152426. savable_state2 state;
  152427. if (cinfo->restart_interval) {
  152428. if (entropy->restarts_to_go == 0)
  152429. if (! process_restart(cinfo))
  152430. return FALSE;
  152431. }
  152432. if (! entropy->pub.insufficient_data) {
  152433. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  152434. ASSIGN_STATE(state, entropy->saved);
  152435. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  152436. JBLOCKROW block = MCU_data[blkn];
  152437. d_derived_tbl * dctbl = entropy->dc_cur_tbls[blkn];
  152438. d_derived_tbl * actbl = entropy->ac_cur_tbls[blkn];
  152439. register int s, k, r;
  152440. HUFF_DECODE(s, br_state, dctbl, return FALSE, label1);
  152441. if (s) {
  152442. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152443. r = GET_BITS(s);
  152444. s = HUFF_EXTEND(r, s);
  152445. }
  152446. if (entropy->dc_needed[blkn]) {
  152447. int ci = cinfo->MCU_membership[blkn];
  152448. s += state.last_dc_val[ci];
  152449. state.last_dc_val[ci] = s;
  152450. (*block)[0] = (JCOEF) s;
  152451. }
  152452. if (entropy->ac_needed[blkn]) {
  152453. for (k = 1; k < DCTSIZE2; k++) {
  152454. HUFF_DECODE(s, br_state, actbl, return FALSE, label2);
  152455. r = s >> 4;
  152456. s &= 15;
  152457. if (s) {
  152458. k += r;
  152459. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152460. r = GET_BITS(s);
  152461. s = HUFF_EXTEND(r, s);
  152462. (*block)[jpeg_natural_order[k]] = (JCOEF) s;
  152463. } else {
  152464. if (r != 15)
  152465. break;
  152466. k += 15;
  152467. }
  152468. }
  152469. } else {
  152470. for (k = 1; k < DCTSIZE2; k++) {
  152471. HUFF_DECODE(s, br_state, actbl, return FALSE, label3);
  152472. r = s >> 4;
  152473. s &= 15;
  152474. if (s) {
  152475. k += r;
  152476. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  152477. DROP_BITS(s);
  152478. } else {
  152479. if (r != 15)
  152480. break;
  152481. k += 15;
  152482. }
  152483. }
  152484. }
  152485. }
  152486. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  152487. ASSIGN_STATE(entropy->saved, state);
  152488. }
  152489. entropy->restarts_to_go--;
  152490. return TRUE;
  152491. }
  152492. GLOBAL(void)
  152493. jinit_huff_decoder (j_decompress_ptr cinfo)
  152494. {
  152495. huff_entropy_ptr2 entropy;
  152496. int i;
  152497. entropy = (huff_entropy_ptr2)
  152498. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152499. SIZEOF(huff_entropy_decoder2));
  152500. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  152501. entropy->pub.start_pass = start_pass_huff_decoder;
  152502. entropy->pub.decode_mcu = decode_mcu;
  152503. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  152504. entropy->dc_derived_tbls[i] = entropy->ac_derived_tbls[i] = NULL;
  152505. }
  152506. }
  152507. /*** End of inlined file: jdhuff.c ***/
  152508. /*** Start of inlined file: jdinput.c ***/
  152509. #define JPEG_INTERNALS
  152510. typedef struct {
  152511. struct jpeg_input_controller pub; /* public fields */
  152512. boolean inheaders; /* TRUE until first SOS is reached */
  152513. } my_input_controller;
  152514. typedef my_input_controller * my_inputctl_ptr;
  152515. METHODDEF(int) consume_markers JPP((j_decompress_ptr cinfo));
  152516. LOCAL(void)
  152517. initial_setup2 (j_decompress_ptr cinfo)
  152518. {
  152519. int ci;
  152520. jpeg_component_info *compptr;
  152521. if ((long) cinfo->image_height > (long) JPEG_MAX_DIMENSION ||
  152522. (long) cinfo->image_width > (long) JPEG_MAX_DIMENSION)
  152523. ERREXIT1(cinfo, JERR_IMAGE_TOO_BIG, (unsigned int) JPEG_MAX_DIMENSION);
  152524. if (cinfo->data_precision != BITS_IN_JSAMPLE)
  152525. ERREXIT1(cinfo, JERR_BAD_PRECISION, cinfo->data_precision);
  152526. if (cinfo->num_components > MAX_COMPONENTS)
  152527. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->num_components,
  152528. MAX_COMPONENTS);
  152529. cinfo->max_h_samp_factor = 1;
  152530. cinfo->max_v_samp_factor = 1;
  152531. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152532. ci++, compptr++) {
  152533. if (compptr->h_samp_factor<=0 || compptr->h_samp_factor>MAX_SAMP_FACTOR ||
  152534. compptr->v_samp_factor<=0 || compptr->v_samp_factor>MAX_SAMP_FACTOR)
  152535. ERREXIT(cinfo, JERR_BAD_SAMPLING);
  152536. cinfo->max_h_samp_factor = MAX(cinfo->max_h_samp_factor,
  152537. compptr->h_samp_factor);
  152538. cinfo->max_v_samp_factor = MAX(cinfo->max_v_samp_factor,
  152539. compptr->v_samp_factor);
  152540. }
  152541. cinfo->min_DCT_scaled_size = DCTSIZE;
  152542. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152543. ci++, compptr++) {
  152544. compptr->DCT_scaled_size = DCTSIZE;
  152545. compptr->width_in_blocks = (JDIMENSION)
  152546. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152547. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  152548. compptr->height_in_blocks = (JDIMENSION)
  152549. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152550. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  152551. compptr->downsampled_width = (JDIMENSION)
  152552. jdiv_round_up((long) cinfo->image_width * (long) compptr->h_samp_factor,
  152553. (long) cinfo->max_h_samp_factor);
  152554. compptr->downsampled_height = (JDIMENSION)
  152555. jdiv_round_up((long) cinfo->image_height * (long) compptr->v_samp_factor,
  152556. (long) cinfo->max_v_samp_factor);
  152557. compptr->component_needed = TRUE;
  152558. compptr->quant_table = NULL;
  152559. }
  152560. cinfo->total_iMCU_rows = (JDIMENSION)
  152561. jdiv_round_up((long) cinfo->image_height,
  152562. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152563. if (cinfo->comps_in_scan < cinfo->num_components || cinfo->progressive_mode)
  152564. cinfo->inputctl->has_multiple_scans = TRUE;
  152565. else
  152566. cinfo->inputctl->has_multiple_scans = FALSE;
  152567. }
  152568. LOCAL(void)
  152569. per_scan_setup2 (j_decompress_ptr cinfo)
  152570. {
  152571. int ci, mcublks, tmp;
  152572. jpeg_component_info *compptr;
  152573. if (cinfo->comps_in_scan == 1) {
  152574. compptr = cinfo->cur_comp_info[0];
  152575. cinfo->MCUs_per_row = compptr->width_in_blocks;
  152576. cinfo->MCU_rows_in_scan = compptr->height_in_blocks;
  152577. compptr->MCU_width = 1;
  152578. compptr->MCU_height = 1;
  152579. compptr->MCU_blocks = 1;
  152580. compptr->MCU_sample_width = compptr->DCT_scaled_size;
  152581. compptr->last_col_width = 1;
  152582. tmp = (int) (compptr->height_in_blocks % compptr->v_samp_factor);
  152583. if (tmp == 0) tmp = compptr->v_samp_factor;
  152584. compptr->last_row_height = tmp;
  152585. cinfo->blocks_in_MCU = 1;
  152586. cinfo->MCU_membership[0] = 0;
  152587. } else {
  152588. if (cinfo->comps_in_scan <= 0 || cinfo->comps_in_scan > MAX_COMPS_IN_SCAN)
  152589. ERREXIT2(cinfo, JERR_COMPONENT_COUNT, cinfo->comps_in_scan,
  152590. MAX_COMPS_IN_SCAN);
  152591. cinfo->MCUs_per_row = (JDIMENSION)
  152592. jdiv_round_up((long) cinfo->image_width,
  152593. (long) (cinfo->max_h_samp_factor*DCTSIZE));
  152594. cinfo->MCU_rows_in_scan = (JDIMENSION)
  152595. jdiv_round_up((long) cinfo->image_height,
  152596. (long) (cinfo->max_v_samp_factor*DCTSIZE));
  152597. cinfo->blocks_in_MCU = 0;
  152598. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152599. compptr = cinfo->cur_comp_info[ci];
  152600. compptr->MCU_width = compptr->h_samp_factor;
  152601. compptr->MCU_height = compptr->v_samp_factor;
  152602. compptr->MCU_blocks = compptr->MCU_width * compptr->MCU_height;
  152603. compptr->MCU_sample_width = compptr->MCU_width * compptr->DCT_scaled_size;
  152604. tmp = (int) (compptr->width_in_blocks % compptr->MCU_width);
  152605. if (tmp == 0) tmp = compptr->MCU_width;
  152606. compptr->last_col_width = tmp;
  152607. tmp = (int) (compptr->height_in_blocks % compptr->MCU_height);
  152608. if (tmp == 0) tmp = compptr->MCU_height;
  152609. compptr->last_row_height = tmp;
  152610. mcublks = compptr->MCU_blocks;
  152611. if (cinfo->blocks_in_MCU + mcublks > D_MAX_BLOCKS_IN_MCU)
  152612. ERREXIT(cinfo, JERR_BAD_MCU_SIZE);
  152613. while (mcublks-- > 0) {
  152614. cinfo->MCU_membership[cinfo->blocks_in_MCU++] = ci;
  152615. }
  152616. }
  152617. }
  152618. }
  152619. LOCAL(void)
  152620. latch_quant_tables (j_decompress_ptr cinfo)
  152621. {
  152622. int ci, qtblno;
  152623. jpeg_component_info *compptr;
  152624. JQUANT_TBL * qtbl;
  152625. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  152626. compptr = cinfo->cur_comp_info[ci];
  152627. if (compptr->quant_table != NULL)
  152628. continue;
  152629. qtblno = compptr->quant_tbl_no;
  152630. if (qtblno < 0 || qtblno >= NUM_QUANT_TBLS ||
  152631. cinfo->quant_tbl_ptrs[qtblno] == NULL)
  152632. ERREXIT1(cinfo, JERR_NO_QUANT_TABLE, qtblno);
  152633. qtbl = (JQUANT_TBL *)
  152634. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152635. SIZEOF(JQUANT_TBL));
  152636. MEMCOPY(qtbl, cinfo->quant_tbl_ptrs[qtblno], SIZEOF(JQUANT_TBL));
  152637. compptr->quant_table = qtbl;
  152638. }
  152639. }
  152640. METHODDEF(void)
  152641. start_input_pass2 (j_decompress_ptr cinfo)
  152642. {
  152643. per_scan_setup2(cinfo);
  152644. latch_quant_tables(cinfo);
  152645. (*cinfo->entropy->start_pass) (cinfo);
  152646. (*cinfo->coef->start_input_pass) (cinfo);
  152647. cinfo->inputctl->consume_input = cinfo->coef->consume_data;
  152648. }
  152649. METHODDEF(void)
  152650. finish_input_pass (j_decompress_ptr cinfo)
  152651. {
  152652. cinfo->inputctl->consume_input = consume_markers;
  152653. }
  152654. METHODDEF(int)
  152655. consume_markers (j_decompress_ptr cinfo)
  152656. {
  152657. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152658. int val;
  152659. if (inputctl->pub.eoi_reached) /* After hitting EOI, read no further */
  152660. return JPEG_REACHED_EOI;
  152661. val = (*cinfo->marker->read_markers) (cinfo);
  152662. switch (val) {
  152663. case JPEG_REACHED_SOS: /* Found SOS */
  152664. if (inputctl->inheaders) { /* 1st SOS */
  152665. initial_setup2(cinfo);
  152666. inputctl->inheaders = FALSE;
  152667. } else { /* 2nd or later SOS marker */
  152668. if (! inputctl->pub.has_multiple_scans)
  152669. ERREXIT(cinfo, JERR_EOI_EXPECTED); /* Oops, I wasn't expecting this! */
  152670. start_input_pass2(cinfo);
  152671. }
  152672. break;
  152673. case JPEG_REACHED_EOI: /* Found EOI */
  152674. inputctl->pub.eoi_reached = TRUE;
  152675. if (inputctl->inheaders) { /* Tables-only datastream, apparently */
  152676. if (cinfo->marker->saw_SOF)
  152677. ERREXIT(cinfo, JERR_SOF_NO_SOS);
  152678. } else {
  152679. if (cinfo->output_scan_number > cinfo->input_scan_number)
  152680. cinfo->output_scan_number = cinfo->input_scan_number;
  152681. }
  152682. break;
  152683. case JPEG_SUSPENDED:
  152684. break;
  152685. }
  152686. return val;
  152687. }
  152688. METHODDEF(void)
  152689. reset_input_controller (j_decompress_ptr cinfo)
  152690. {
  152691. my_inputctl_ptr inputctl = (my_inputctl_ptr) cinfo->inputctl;
  152692. inputctl->pub.consume_input = consume_markers;
  152693. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152694. inputctl->pub.eoi_reached = FALSE;
  152695. inputctl->inheaders = TRUE;
  152696. (*cinfo->err->reset_error_mgr) ((j_common_ptr) cinfo);
  152697. (*cinfo->marker->reset_marker_reader) (cinfo);
  152698. cinfo->coef_bits = NULL;
  152699. }
  152700. GLOBAL(void)
  152701. jinit_input_controller (j_decompress_ptr cinfo)
  152702. {
  152703. my_inputctl_ptr inputctl;
  152704. inputctl = (my_inputctl_ptr)
  152705. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  152706. SIZEOF(my_input_controller));
  152707. cinfo->inputctl = (struct jpeg_input_controller *) inputctl;
  152708. inputctl->pub.consume_input = consume_markers;
  152709. inputctl->pub.reset_input_controller = reset_input_controller;
  152710. inputctl->pub.start_input_pass = start_input_pass2;
  152711. inputctl->pub.finish_input_pass = finish_input_pass;
  152712. inputctl->pub.has_multiple_scans = FALSE; /* "unknown" would be better */
  152713. inputctl->pub.eoi_reached = FALSE;
  152714. inputctl->inheaders = TRUE;
  152715. }
  152716. /*** End of inlined file: jdinput.c ***/
  152717. /*** Start of inlined file: jdmainct.c ***/
  152718. #define JPEG_INTERNALS
  152719. typedef struct {
  152720. struct jpeg_d_main_controller pub; /* public fields */
  152721. JSAMPARRAY buffer[MAX_COMPONENTS];
  152722. boolean buffer_full; /* Have we gotten an iMCU row from decoder? */
  152723. JDIMENSION rowgroup_ctr; /* counts row groups output to postprocessor */
  152724. JSAMPIMAGE xbuffer[2]; /* pointers to weird pointer lists */
  152725. int whichptr; /* indicates which pointer set is now in use */
  152726. int context_state; /* process_data state machine status */
  152727. JDIMENSION rowgroups_avail; /* row groups available to postprocessor */
  152728. JDIMENSION iMCU_row_ctr; /* counts iMCU rows to detect image top/bot */
  152729. } my_main_controller4;
  152730. typedef my_main_controller4 * my_main_ptr4;
  152731. #define CTX_PREPARE_FOR_IMCU 0 /* need to prepare for MCU row */
  152732. #define CTX_PROCESS_IMCU 1 /* feeding iMCU to postprocessor */
  152733. #define CTX_POSTPONED_ROW 2 /* feeding postponed row group */
  152734. METHODDEF(void) process_data_simple_main2
  152735. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152736. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152737. METHODDEF(void) process_data_context_main
  152738. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152739. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152740. #ifdef QUANT_2PASS_SUPPORTED
  152741. METHODDEF(void) process_data_crank_post
  152742. JPP((j_decompress_ptr cinfo, JSAMPARRAY output_buf,
  152743. JDIMENSION *out_row_ctr, JDIMENSION out_rows_avail));
  152744. #endif
  152745. LOCAL(void)
  152746. alloc_funny_pointers (j_decompress_ptr cinfo)
  152747. {
  152748. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152749. int ci, rgroup;
  152750. int M = cinfo->min_DCT_scaled_size;
  152751. jpeg_component_info *compptr;
  152752. JSAMPARRAY xbuf;
  152753. main_->xbuffer[0] = (JSAMPIMAGE)
  152754. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152755. cinfo->num_components * 2 * SIZEOF(JSAMPARRAY));
  152756. main_->xbuffer[1] = main_->xbuffer[0] + cinfo->num_components;
  152757. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152758. ci++, compptr++) {
  152759. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152760. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152761. xbuf = (JSAMPARRAY)
  152762. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152763. 2 * (rgroup * (M + 4)) * SIZEOF(JSAMPROW));
  152764. xbuf += rgroup; /* want one row group at negative offsets */
  152765. main_->xbuffer[0][ci] = xbuf;
  152766. xbuf += rgroup * (M + 4);
  152767. main_->xbuffer[1][ci] = xbuf;
  152768. }
  152769. }
  152770. LOCAL(void)
  152771. make_funny_pointers (j_decompress_ptr cinfo)
  152772. {
  152773. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152774. int ci, i, rgroup;
  152775. int M = cinfo->min_DCT_scaled_size;
  152776. jpeg_component_info *compptr;
  152777. JSAMPARRAY buf, xbuf0, xbuf1;
  152778. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152779. ci++, compptr++) {
  152780. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152781. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152782. xbuf0 = main_->xbuffer[0][ci];
  152783. xbuf1 = main_->xbuffer[1][ci];
  152784. buf = main_->buffer[ci];
  152785. for (i = 0; i < rgroup * (M + 2); i++) {
  152786. xbuf0[i] = xbuf1[i] = buf[i];
  152787. }
  152788. for (i = 0; i < rgroup * 2; i++) {
  152789. xbuf1[rgroup*(M-2) + i] = buf[rgroup*M + i];
  152790. xbuf1[rgroup*M + i] = buf[rgroup*(M-2) + i];
  152791. }
  152792. for (i = 0; i < rgroup; i++) {
  152793. xbuf0[i - rgroup] = xbuf0[0];
  152794. }
  152795. }
  152796. }
  152797. LOCAL(void)
  152798. set_wraparound_pointers (j_decompress_ptr cinfo)
  152799. {
  152800. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152801. int ci, i, rgroup;
  152802. int M = cinfo->min_DCT_scaled_size;
  152803. jpeg_component_info *compptr;
  152804. JSAMPARRAY xbuf0, xbuf1;
  152805. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152806. ci++, compptr++) {
  152807. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152808. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152809. xbuf0 = main_->xbuffer[0][ci];
  152810. xbuf1 = main_->xbuffer[1][ci];
  152811. for (i = 0; i < rgroup; i++) {
  152812. xbuf0[i - rgroup] = xbuf0[rgroup*(M+1) + i];
  152813. xbuf1[i - rgroup] = xbuf1[rgroup*(M+1) + i];
  152814. xbuf0[rgroup*(M+2) + i] = xbuf0[i];
  152815. xbuf1[rgroup*(M+2) + i] = xbuf1[i];
  152816. }
  152817. }
  152818. }
  152819. LOCAL(void)
  152820. set_bottom_pointers (j_decompress_ptr cinfo)
  152821. {
  152822. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152823. int ci, i, rgroup, iMCUheight, rows_left;
  152824. jpeg_component_info *compptr;
  152825. JSAMPARRAY xbuf;
  152826. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152827. ci++, compptr++) {
  152828. iMCUheight = compptr->v_samp_factor * compptr->DCT_scaled_size;
  152829. rgroup = iMCUheight / cinfo->min_DCT_scaled_size;
  152830. rows_left = (int) (compptr->downsampled_height % (JDIMENSION) iMCUheight);
  152831. if (rows_left == 0) rows_left = iMCUheight;
  152832. if (ci == 0) {
  152833. main_->rowgroups_avail = (JDIMENSION) ((rows_left-1) / rgroup + 1);
  152834. }
  152835. xbuf = main_->xbuffer[main_->whichptr][ci];
  152836. for (i = 0; i < rgroup * 2; i++) {
  152837. xbuf[rows_left + i] = xbuf[rows_left-1];
  152838. }
  152839. }
  152840. }
  152841. METHODDEF(void)
  152842. start_pass_main2 (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  152843. {
  152844. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152845. switch (pass_mode) {
  152846. case JBUF_PASS_THRU:
  152847. if (cinfo->upsample->need_context_rows) {
  152848. main_->pub.process_data = process_data_context_main;
  152849. make_funny_pointers(cinfo); /* Create the xbuffer[] lists */
  152850. main_->whichptr = 0; /* Read first iMCU row into xbuffer[0] */
  152851. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152852. main_->iMCU_row_ctr = 0;
  152853. } else {
  152854. main_->pub.process_data = process_data_simple_main2;
  152855. }
  152856. main_->buffer_full = FALSE; /* Mark buffer empty */
  152857. main_->rowgroup_ctr = 0;
  152858. break;
  152859. #ifdef QUANT_2PASS_SUPPORTED
  152860. case JBUF_CRANK_DEST:
  152861. main_->pub.process_data = process_data_crank_post;
  152862. break;
  152863. #endif
  152864. default:
  152865. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152866. break;
  152867. }
  152868. }
  152869. METHODDEF(void)
  152870. process_data_simple_main2 (j_decompress_ptr cinfo,
  152871. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152872. JDIMENSION out_rows_avail)
  152873. {
  152874. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152875. JDIMENSION rowgroups_avail;
  152876. if (! main_->buffer_full) {
  152877. if (! (*cinfo->coef->decompress_data) (cinfo, main_->buffer))
  152878. return; /* suspension forced, can do nothing more */
  152879. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152880. }
  152881. rowgroups_avail = (JDIMENSION) cinfo->min_DCT_scaled_size;
  152882. (*cinfo->post->post_process_data) (cinfo, main_->buffer,
  152883. &main_->rowgroup_ctr, rowgroups_avail,
  152884. output_buf, out_row_ctr, out_rows_avail);
  152885. if (main_->rowgroup_ctr >= rowgroups_avail) {
  152886. main_->buffer_full = FALSE;
  152887. main_->rowgroup_ctr = 0;
  152888. }
  152889. }
  152890. METHODDEF(void)
  152891. process_data_context_main (j_decompress_ptr cinfo,
  152892. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152893. JDIMENSION out_rows_avail)
  152894. {
  152895. my_main_ptr4 main_ = (my_main_ptr4) cinfo->main;
  152896. if (! main_->buffer_full) {
  152897. if (! (*cinfo->coef->decompress_data) (cinfo,
  152898. main_->xbuffer[main_->whichptr]))
  152899. return; /* suspension forced, can do nothing more */
  152900. main_->buffer_full = TRUE; /* OK, we have an iMCU row to work with */
  152901. main_->iMCU_row_ctr++; /* count rows received */
  152902. }
  152903. switch (main_->context_state) {
  152904. case CTX_POSTPONED_ROW:
  152905. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152906. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152907. output_buf, out_row_ctr, out_rows_avail);
  152908. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152909. return; /* Need to suspend */
  152910. main_->context_state = CTX_PREPARE_FOR_IMCU;
  152911. if (*out_row_ctr >= out_rows_avail)
  152912. return; /* Postprocessor exactly filled output buf */
  152913. case CTX_PREPARE_FOR_IMCU:
  152914. main_->rowgroup_ctr = 0;
  152915. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size - 1);
  152916. if (main_->iMCU_row_ctr == cinfo->total_iMCU_rows)
  152917. set_bottom_pointers(cinfo);
  152918. main_->context_state = CTX_PROCESS_IMCU;
  152919. case CTX_PROCESS_IMCU:
  152920. (*cinfo->post->post_process_data) (cinfo, main_->xbuffer[main_->whichptr],
  152921. &main_->rowgroup_ctr, main_->rowgroups_avail,
  152922. output_buf, out_row_ctr, out_rows_avail);
  152923. if (main_->rowgroup_ctr < main_->rowgroups_avail)
  152924. return; /* Need to suspend */
  152925. if (main_->iMCU_row_ctr == 1)
  152926. set_wraparound_pointers(cinfo);
  152927. main_->whichptr ^= 1; /* 0=>1 or 1=>0 */
  152928. main_->buffer_full = FALSE;
  152929. main_->rowgroup_ctr = (JDIMENSION) (cinfo->min_DCT_scaled_size + 1);
  152930. main_->rowgroups_avail = (JDIMENSION) (cinfo->min_DCT_scaled_size + 2);
  152931. main_->context_state = CTX_POSTPONED_ROW;
  152932. }
  152933. }
  152934. #ifdef QUANT_2PASS_SUPPORTED
  152935. METHODDEF(void)
  152936. process_data_crank_post (j_decompress_ptr cinfo,
  152937. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  152938. JDIMENSION out_rows_avail)
  152939. {
  152940. (*cinfo->post->post_process_data) (cinfo, (JSAMPIMAGE) NULL,
  152941. (JDIMENSION *) NULL, (JDIMENSION) 0,
  152942. output_buf, out_row_ctr, out_rows_avail);
  152943. }
  152944. #endif /* QUANT_2PASS_SUPPORTED */
  152945. GLOBAL(void)
  152946. jinit_d_main_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  152947. {
  152948. my_main_ptr4 main_;
  152949. int ci, rgroup, ngroups;
  152950. jpeg_component_info *compptr;
  152951. main_ = (my_main_ptr4)
  152952. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152953. SIZEOF(my_main_controller4));
  152954. cinfo->main = (struct jpeg_d_main_controller *) main_;
  152955. main_->pub.start_pass = start_pass_main2;
  152956. if (need_full_buffer) /* shouldn't happen */
  152957. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  152958. if (cinfo->upsample->need_context_rows) {
  152959. if (cinfo->min_DCT_scaled_size < 2) /* unsupported, see comments above */
  152960. ERREXIT(cinfo, JERR_NOTIMPL);
  152961. alloc_funny_pointers(cinfo); /* Alloc space for xbuffer[] lists */
  152962. ngroups = cinfo->min_DCT_scaled_size + 2;
  152963. } else {
  152964. ngroups = cinfo->min_DCT_scaled_size;
  152965. }
  152966. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  152967. ci++, compptr++) {
  152968. rgroup = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  152969. cinfo->min_DCT_scaled_size; /* height of a row group of component */
  152970. main_->buffer[ci] = (*cinfo->mem->alloc_sarray)
  152971. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  152972. compptr->width_in_blocks * compptr->DCT_scaled_size,
  152973. (JDIMENSION) (rgroup * ngroups));
  152974. }
  152975. }
  152976. /*** End of inlined file: jdmainct.c ***/
  152977. /*** Start of inlined file: jdmarker.c ***/
  152978. #define JPEG_INTERNALS
  152979. typedef struct {
  152980. struct jpeg_marker_reader pub; /* public fields */
  152981. jpeg_marker_parser_method process_COM;
  152982. jpeg_marker_parser_method process_APPn[16];
  152983. unsigned int length_limit_COM;
  152984. unsigned int length_limit_APPn[16];
  152985. jpeg_saved_marker_ptr cur_marker; /* NULL if not processing a marker */
  152986. unsigned int bytes_read; /* data bytes read so far in marker */
  152987. } my_marker_reader;
  152988. typedef my_marker_reader * my_marker_ptr2;
  152989. #define INPUT_VARS(cinfo) \
  152990. struct jpeg_source_mgr * datasrc = (cinfo)->src; \
  152991. const JOCTET * next_input_byte = datasrc->next_input_byte; \
  152992. size_t bytes_in_buffer = datasrc->bytes_in_buffer
  152993. #define INPUT_SYNC(cinfo) \
  152994. ( datasrc->next_input_byte = next_input_byte, \
  152995. datasrc->bytes_in_buffer = bytes_in_buffer )
  152996. #define INPUT_RELOAD(cinfo) \
  152997. ( next_input_byte = datasrc->next_input_byte, \
  152998. bytes_in_buffer = datasrc->bytes_in_buffer )
  152999. #define MAKE_BYTE_AVAIL(cinfo,action) \
  153000. if (bytes_in_buffer == 0) { \
  153001. if (! (*datasrc->fill_input_buffer) (cinfo)) \
  153002. { action; } \
  153003. INPUT_RELOAD(cinfo); \
  153004. }
  153005. #define INPUT_BYTE(cinfo,V,action) \
  153006. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  153007. bytes_in_buffer--; \
  153008. V = GETJOCTET(*next_input_byte++); )
  153009. #define INPUT_2BYTES(cinfo,V,action) \
  153010. MAKESTMT( MAKE_BYTE_AVAIL(cinfo,action); \
  153011. bytes_in_buffer--; \
  153012. V = ((unsigned int) GETJOCTET(*next_input_byte++)) << 8; \
  153013. MAKE_BYTE_AVAIL(cinfo,action); \
  153014. bytes_in_buffer--; \
  153015. V += GETJOCTET(*next_input_byte++); )
  153016. LOCAL(boolean)
  153017. get_soi (j_decompress_ptr cinfo)
  153018. {
  153019. int i;
  153020. TRACEMS(cinfo, 1, JTRC_SOI);
  153021. if (cinfo->marker->saw_SOI)
  153022. ERREXIT(cinfo, JERR_SOI_DUPLICATE);
  153023. for (i = 0; i < NUM_ARITH_TBLS; i++) {
  153024. cinfo->arith_dc_L[i] = 0;
  153025. cinfo->arith_dc_U[i] = 1;
  153026. cinfo->arith_ac_K[i] = 5;
  153027. }
  153028. cinfo->restart_interval = 0;
  153029. cinfo->jpeg_color_space = JCS_UNKNOWN;
  153030. cinfo->CCIR601_sampling = FALSE; /* Assume non-CCIR sampling??? */
  153031. cinfo->saw_JFIF_marker = FALSE;
  153032. cinfo->JFIF_major_version = 1; /* set default JFIF APP0 values */
  153033. cinfo->JFIF_minor_version = 1;
  153034. cinfo->density_unit = 0;
  153035. cinfo->X_density = 1;
  153036. cinfo->Y_density = 1;
  153037. cinfo->saw_Adobe_marker = FALSE;
  153038. cinfo->Adobe_transform = 0;
  153039. cinfo->marker->saw_SOI = TRUE;
  153040. return TRUE;
  153041. }
  153042. LOCAL(boolean)
  153043. get_sof (j_decompress_ptr cinfo, boolean is_prog, boolean is_arith)
  153044. {
  153045. INT32 length;
  153046. int c, ci;
  153047. jpeg_component_info * compptr;
  153048. INPUT_VARS(cinfo);
  153049. cinfo->progressive_mode = is_prog;
  153050. cinfo->arith_code = is_arith;
  153051. INPUT_2BYTES(cinfo, length, return FALSE);
  153052. INPUT_BYTE(cinfo, cinfo->data_precision, return FALSE);
  153053. INPUT_2BYTES(cinfo, cinfo->image_height, return FALSE);
  153054. INPUT_2BYTES(cinfo, cinfo->image_width, return FALSE);
  153055. INPUT_BYTE(cinfo, cinfo->num_components, return FALSE);
  153056. length -= 8;
  153057. TRACEMS4(cinfo, 1, JTRC_SOF, cinfo->unread_marker,
  153058. (int) cinfo->image_width, (int) cinfo->image_height,
  153059. cinfo->num_components);
  153060. if (cinfo->marker->saw_SOF)
  153061. ERREXIT(cinfo, JERR_SOF_DUPLICATE);
  153062. if (cinfo->image_height <= 0 || cinfo->image_width <= 0
  153063. || cinfo->num_components <= 0)
  153064. ERREXIT(cinfo, JERR_EMPTY_IMAGE);
  153065. if (length != (cinfo->num_components * 3))
  153066. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153067. if (cinfo->comp_info == NULL) /* do only once, even if suspend */
  153068. cinfo->comp_info = (jpeg_component_info *) (*cinfo->mem->alloc_small)
  153069. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153070. cinfo->num_components * SIZEOF(jpeg_component_info));
  153071. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153072. ci++, compptr++) {
  153073. compptr->component_index = ci;
  153074. INPUT_BYTE(cinfo, compptr->component_id, return FALSE);
  153075. INPUT_BYTE(cinfo, c, return FALSE);
  153076. compptr->h_samp_factor = (c >> 4) & 15;
  153077. compptr->v_samp_factor = (c ) & 15;
  153078. INPUT_BYTE(cinfo, compptr->quant_tbl_no, return FALSE);
  153079. TRACEMS4(cinfo, 1, JTRC_SOF_COMPONENT,
  153080. compptr->component_id, compptr->h_samp_factor,
  153081. compptr->v_samp_factor, compptr->quant_tbl_no);
  153082. }
  153083. cinfo->marker->saw_SOF = TRUE;
  153084. INPUT_SYNC(cinfo);
  153085. return TRUE;
  153086. }
  153087. LOCAL(boolean)
  153088. get_sos (j_decompress_ptr cinfo)
  153089. {
  153090. INT32 length;
  153091. int i, ci, n, c, cc;
  153092. jpeg_component_info * compptr;
  153093. INPUT_VARS(cinfo);
  153094. if (! cinfo->marker->saw_SOF)
  153095. ERREXIT(cinfo, JERR_SOS_NO_SOF);
  153096. INPUT_2BYTES(cinfo, length, return FALSE);
  153097. INPUT_BYTE(cinfo, n, return FALSE); /* Number of components */
  153098. TRACEMS1(cinfo, 1, JTRC_SOS, n);
  153099. if (length != (n * 2 + 6) || n < 1 || n > MAX_COMPS_IN_SCAN)
  153100. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153101. cinfo->comps_in_scan = n;
  153102. for (i = 0; i < n; i++) {
  153103. INPUT_BYTE(cinfo, cc, return FALSE);
  153104. INPUT_BYTE(cinfo, c, return FALSE);
  153105. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153106. ci++, compptr++) {
  153107. if (cc == compptr->component_id)
  153108. goto id_found;
  153109. }
  153110. ERREXIT1(cinfo, JERR_BAD_COMPONENT_ID, cc);
  153111. id_found:
  153112. cinfo->cur_comp_info[i] = compptr;
  153113. compptr->dc_tbl_no = (c >> 4) & 15;
  153114. compptr->ac_tbl_no = (c ) & 15;
  153115. TRACEMS3(cinfo, 1, JTRC_SOS_COMPONENT, cc,
  153116. compptr->dc_tbl_no, compptr->ac_tbl_no);
  153117. }
  153118. INPUT_BYTE(cinfo, c, return FALSE);
  153119. cinfo->Ss = c;
  153120. INPUT_BYTE(cinfo, c, return FALSE);
  153121. cinfo->Se = c;
  153122. INPUT_BYTE(cinfo, c, return FALSE);
  153123. cinfo->Ah = (c >> 4) & 15;
  153124. cinfo->Al = (c ) & 15;
  153125. TRACEMS4(cinfo, 1, JTRC_SOS_PARAMS, cinfo->Ss, cinfo->Se,
  153126. cinfo->Ah, cinfo->Al);
  153127. cinfo->marker->next_restart_num = 0;
  153128. cinfo->input_scan_number++;
  153129. INPUT_SYNC(cinfo);
  153130. return TRUE;
  153131. }
  153132. #ifdef D_ARITH_CODING_SUPPORTED
  153133. LOCAL(boolean)
  153134. get_dac (j_decompress_ptr cinfo)
  153135. {
  153136. INT32 length;
  153137. int index, val;
  153138. INPUT_VARS(cinfo);
  153139. INPUT_2BYTES(cinfo, length, return FALSE);
  153140. length -= 2;
  153141. while (length > 0) {
  153142. INPUT_BYTE(cinfo, index, return FALSE);
  153143. INPUT_BYTE(cinfo, val, return FALSE);
  153144. length -= 2;
  153145. TRACEMS2(cinfo, 1, JTRC_DAC, index, val);
  153146. if (index < 0 || index >= (2*NUM_ARITH_TBLS))
  153147. ERREXIT1(cinfo, JERR_DAC_INDEX, index);
  153148. if (index >= NUM_ARITH_TBLS) { /* define AC table */
  153149. cinfo->arith_ac_K[index-NUM_ARITH_TBLS] = (UINT8) val;
  153150. } else { /* define DC table */
  153151. cinfo->arith_dc_L[index] = (UINT8) (val & 0x0F);
  153152. cinfo->arith_dc_U[index] = (UINT8) (val >> 4);
  153153. if (cinfo->arith_dc_L[index] > cinfo->arith_dc_U[index])
  153154. ERREXIT1(cinfo, JERR_DAC_VALUE, val);
  153155. }
  153156. }
  153157. if (length != 0)
  153158. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153159. INPUT_SYNC(cinfo);
  153160. return TRUE;
  153161. }
  153162. #else /* ! D_ARITH_CODING_SUPPORTED */
  153163. #define get_dac(cinfo) skip_variable(cinfo)
  153164. #endif /* D_ARITH_CODING_SUPPORTED */
  153165. LOCAL(boolean)
  153166. get_dht (j_decompress_ptr cinfo)
  153167. {
  153168. INT32 length;
  153169. UINT8 bits[17];
  153170. UINT8 huffval[256];
  153171. int i, index, count;
  153172. JHUFF_TBL **htblptr;
  153173. INPUT_VARS(cinfo);
  153174. INPUT_2BYTES(cinfo, length, return FALSE);
  153175. length -= 2;
  153176. while (length > 16) {
  153177. INPUT_BYTE(cinfo, index, return FALSE);
  153178. TRACEMS1(cinfo, 1, JTRC_DHT, index);
  153179. bits[0] = 0;
  153180. count = 0;
  153181. for (i = 1; i <= 16; i++) {
  153182. INPUT_BYTE(cinfo, bits[i], return FALSE);
  153183. count += bits[i];
  153184. }
  153185. length -= 1 + 16;
  153186. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  153187. bits[1], bits[2], bits[3], bits[4],
  153188. bits[5], bits[6], bits[7], bits[8]);
  153189. TRACEMS8(cinfo, 2, JTRC_HUFFBITS,
  153190. bits[9], bits[10], bits[11], bits[12],
  153191. bits[13], bits[14], bits[15], bits[16]);
  153192. if (count > 256 || ((INT32) count) > length)
  153193. ERREXIT(cinfo, JERR_BAD_HUFF_TABLE);
  153194. for (i = 0; i < count; i++)
  153195. INPUT_BYTE(cinfo, huffval[i], return FALSE);
  153196. length -= count;
  153197. if (index & 0x10) { /* AC table definition */
  153198. index -= 0x10;
  153199. htblptr = &cinfo->ac_huff_tbl_ptrs[index];
  153200. } else { /* DC table definition */
  153201. htblptr = &cinfo->dc_huff_tbl_ptrs[index];
  153202. }
  153203. if (index < 0 || index >= NUM_HUFF_TBLS)
  153204. ERREXIT1(cinfo, JERR_DHT_INDEX, index);
  153205. if (*htblptr == NULL)
  153206. *htblptr = jpeg_alloc_huff_table((j_common_ptr) cinfo);
  153207. MEMCOPY((*htblptr)->bits, bits, SIZEOF((*htblptr)->bits));
  153208. MEMCOPY((*htblptr)->huffval, huffval, SIZEOF((*htblptr)->huffval));
  153209. }
  153210. if (length != 0)
  153211. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153212. INPUT_SYNC(cinfo);
  153213. return TRUE;
  153214. }
  153215. LOCAL(boolean)
  153216. get_dqt (j_decompress_ptr cinfo)
  153217. {
  153218. INT32 length;
  153219. int n, i, prec;
  153220. unsigned int tmp;
  153221. JQUANT_TBL *quant_ptr;
  153222. INPUT_VARS(cinfo);
  153223. INPUT_2BYTES(cinfo, length, return FALSE);
  153224. length -= 2;
  153225. while (length > 0) {
  153226. INPUT_BYTE(cinfo, n, return FALSE);
  153227. prec = n >> 4;
  153228. n &= 0x0F;
  153229. TRACEMS2(cinfo, 1, JTRC_DQT, n, prec);
  153230. if (n >= NUM_QUANT_TBLS)
  153231. ERREXIT1(cinfo, JERR_DQT_INDEX, n);
  153232. if (cinfo->quant_tbl_ptrs[n] == NULL)
  153233. cinfo->quant_tbl_ptrs[n] = jpeg_alloc_quant_table((j_common_ptr) cinfo);
  153234. quant_ptr = cinfo->quant_tbl_ptrs[n];
  153235. for (i = 0; i < DCTSIZE2; i++) {
  153236. if (prec)
  153237. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153238. else
  153239. INPUT_BYTE(cinfo, tmp, return FALSE);
  153240. quant_ptr->quantval[jpeg_natural_order[i]] = (UINT16) tmp;
  153241. }
  153242. if (cinfo->err->trace_level >= 2) {
  153243. for (i = 0; i < DCTSIZE2; i += 8) {
  153244. TRACEMS8(cinfo, 2, JTRC_QUANTVALS,
  153245. quant_ptr->quantval[i], quant_ptr->quantval[i+1],
  153246. quant_ptr->quantval[i+2], quant_ptr->quantval[i+3],
  153247. quant_ptr->quantval[i+4], quant_ptr->quantval[i+5],
  153248. quant_ptr->quantval[i+6], quant_ptr->quantval[i+7]);
  153249. }
  153250. }
  153251. length -= DCTSIZE2+1;
  153252. if (prec) length -= DCTSIZE2;
  153253. }
  153254. if (length != 0)
  153255. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153256. INPUT_SYNC(cinfo);
  153257. return TRUE;
  153258. }
  153259. LOCAL(boolean)
  153260. get_dri (j_decompress_ptr cinfo)
  153261. {
  153262. INT32 length;
  153263. unsigned int tmp;
  153264. INPUT_VARS(cinfo);
  153265. INPUT_2BYTES(cinfo, length, return FALSE);
  153266. if (length != 4)
  153267. ERREXIT(cinfo, JERR_BAD_LENGTH);
  153268. INPUT_2BYTES(cinfo, tmp, return FALSE);
  153269. TRACEMS1(cinfo, 1, JTRC_DRI, tmp);
  153270. cinfo->restart_interval = tmp;
  153271. INPUT_SYNC(cinfo);
  153272. return TRUE;
  153273. }
  153274. #define APP0_DATA_LEN 14 /* Length of interesting data in APP0 */
  153275. #define APP14_DATA_LEN 12 /* Length of interesting data in APP14 */
  153276. #define APPN_DATA_LEN 14 /* Must be the largest of the above!! */
  153277. LOCAL(void)
  153278. examine_app0 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153279. unsigned int datalen, INT32 remaining)
  153280. {
  153281. INT32 totallen = (INT32) datalen + remaining;
  153282. if (datalen >= APP0_DATA_LEN &&
  153283. GETJOCTET(data[0]) == 0x4A &&
  153284. GETJOCTET(data[1]) == 0x46 &&
  153285. GETJOCTET(data[2]) == 0x49 &&
  153286. GETJOCTET(data[3]) == 0x46 &&
  153287. GETJOCTET(data[4]) == 0) {
  153288. cinfo->saw_JFIF_marker = TRUE;
  153289. cinfo->JFIF_major_version = GETJOCTET(data[5]);
  153290. cinfo->JFIF_minor_version = GETJOCTET(data[6]);
  153291. cinfo->density_unit = GETJOCTET(data[7]);
  153292. cinfo->X_density = (GETJOCTET(data[8]) << 8) + GETJOCTET(data[9]);
  153293. cinfo->Y_density = (GETJOCTET(data[10]) << 8) + GETJOCTET(data[11]);
  153294. if (cinfo->JFIF_major_version != 1)
  153295. WARNMS2(cinfo, JWRN_JFIF_MAJOR,
  153296. cinfo->JFIF_major_version, cinfo->JFIF_minor_version);
  153297. TRACEMS5(cinfo, 1, JTRC_JFIF,
  153298. cinfo->JFIF_major_version, cinfo->JFIF_minor_version,
  153299. cinfo->X_density, cinfo->Y_density, cinfo->density_unit);
  153300. if (GETJOCTET(data[12]) | GETJOCTET(data[13]))
  153301. TRACEMS2(cinfo, 1, JTRC_JFIF_THUMBNAIL,
  153302. GETJOCTET(data[12]), GETJOCTET(data[13]));
  153303. totallen -= APP0_DATA_LEN;
  153304. if (totallen !=
  153305. ((INT32)GETJOCTET(data[12]) * (INT32)GETJOCTET(data[13]) * (INT32) 3))
  153306. TRACEMS1(cinfo, 1, JTRC_JFIF_BADTHUMBNAILSIZE, (int) totallen);
  153307. } else if (datalen >= 6 &&
  153308. GETJOCTET(data[0]) == 0x4A &&
  153309. GETJOCTET(data[1]) == 0x46 &&
  153310. GETJOCTET(data[2]) == 0x58 &&
  153311. GETJOCTET(data[3]) == 0x58 &&
  153312. GETJOCTET(data[4]) == 0) {
  153313. switch (GETJOCTET(data[5])) {
  153314. case 0x10:
  153315. TRACEMS1(cinfo, 1, JTRC_THUMB_JPEG, (int) totallen);
  153316. break;
  153317. case 0x11:
  153318. TRACEMS1(cinfo, 1, JTRC_THUMB_PALETTE, (int) totallen);
  153319. break;
  153320. case 0x13:
  153321. TRACEMS1(cinfo, 1, JTRC_THUMB_RGB, (int) totallen);
  153322. break;
  153323. default:
  153324. TRACEMS2(cinfo, 1, JTRC_JFIF_EXTENSION,
  153325. GETJOCTET(data[5]), (int) totallen);
  153326. break;
  153327. }
  153328. } else {
  153329. TRACEMS1(cinfo, 1, JTRC_APP0, (int) totallen);
  153330. }
  153331. }
  153332. LOCAL(void)
  153333. examine_app14 (j_decompress_ptr cinfo, JOCTET FAR * data,
  153334. unsigned int datalen, INT32 remaining)
  153335. {
  153336. unsigned int version, flags0, flags1, transform;
  153337. if (datalen >= APP14_DATA_LEN &&
  153338. GETJOCTET(data[0]) == 0x41 &&
  153339. GETJOCTET(data[1]) == 0x64 &&
  153340. GETJOCTET(data[2]) == 0x6F &&
  153341. GETJOCTET(data[3]) == 0x62 &&
  153342. GETJOCTET(data[4]) == 0x65) {
  153343. version = (GETJOCTET(data[5]) << 8) + GETJOCTET(data[6]);
  153344. flags0 = (GETJOCTET(data[7]) << 8) + GETJOCTET(data[8]);
  153345. flags1 = (GETJOCTET(data[9]) << 8) + GETJOCTET(data[10]);
  153346. transform = GETJOCTET(data[11]);
  153347. TRACEMS4(cinfo, 1, JTRC_ADOBE, version, flags0, flags1, transform);
  153348. cinfo->saw_Adobe_marker = TRUE;
  153349. cinfo->Adobe_transform = (UINT8) transform;
  153350. } else {
  153351. TRACEMS1(cinfo, 1, JTRC_APP14, (int) (datalen + remaining));
  153352. }
  153353. }
  153354. METHODDEF(boolean)
  153355. get_interesting_appn (j_decompress_ptr cinfo)
  153356. {
  153357. INT32 length;
  153358. JOCTET b[APPN_DATA_LEN];
  153359. unsigned int i, numtoread;
  153360. INPUT_VARS(cinfo);
  153361. INPUT_2BYTES(cinfo, length, return FALSE);
  153362. length -= 2;
  153363. if (length >= APPN_DATA_LEN)
  153364. numtoread = APPN_DATA_LEN;
  153365. else if (length > 0)
  153366. numtoread = (unsigned int) length;
  153367. else
  153368. numtoread = 0;
  153369. for (i = 0; i < numtoread; i++)
  153370. INPUT_BYTE(cinfo, b[i], return FALSE);
  153371. length -= numtoread;
  153372. switch (cinfo->unread_marker) {
  153373. case M_APP0:
  153374. examine_app0(cinfo, (JOCTET FAR *) b, numtoread, length);
  153375. break;
  153376. case M_APP14:
  153377. examine_app14(cinfo, (JOCTET FAR *) b, numtoread, length);
  153378. break;
  153379. default:
  153380. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153381. break;
  153382. }
  153383. INPUT_SYNC(cinfo);
  153384. if (length > 0)
  153385. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153386. return TRUE;
  153387. }
  153388. #ifdef SAVE_MARKERS_SUPPORTED
  153389. METHODDEF(boolean)
  153390. save_marker (j_decompress_ptr cinfo)
  153391. {
  153392. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153393. jpeg_saved_marker_ptr cur_marker = marker->cur_marker;
  153394. unsigned int bytes_read, data_length;
  153395. JOCTET FAR * data;
  153396. INT32 length = 0;
  153397. INPUT_VARS(cinfo);
  153398. if (cur_marker == NULL) {
  153399. INPUT_2BYTES(cinfo, length, return FALSE);
  153400. length -= 2;
  153401. if (length >= 0) { /* watch out for bogus length word */
  153402. unsigned int limit;
  153403. if (cinfo->unread_marker == (int) M_COM)
  153404. limit = marker->length_limit_COM;
  153405. else
  153406. limit = marker->length_limit_APPn[cinfo->unread_marker - (int) M_APP0];
  153407. if ((unsigned int) length < limit)
  153408. limit = (unsigned int) length;
  153409. cur_marker = (jpeg_saved_marker_ptr)
  153410. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153411. SIZEOF(struct jpeg_marker_struct) + limit);
  153412. cur_marker->next = NULL;
  153413. cur_marker->marker = (UINT8) cinfo->unread_marker;
  153414. cur_marker->original_length = (unsigned int) length;
  153415. cur_marker->data_length = limit;
  153416. data = cur_marker->data = (JOCTET FAR *) (cur_marker + 1);
  153417. marker->cur_marker = cur_marker;
  153418. marker->bytes_read = 0;
  153419. bytes_read = 0;
  153420. data_length = limit;
  153421. } else {
  153422. bytes_read = data_length = 0;
  153423. data = NULL;
  153424. }
  153425. } else {
  153426. bytes_read = marker->bytes_read;
  153427. data_length = cur_marker->data_length;
  153428. data = cur_marker->data + bytes_read;
  153429. }
  153430. while (bytes_read < data_length) {
  153431. INPUT_SYNC(cinfo); /* move the restart point to here */
  153432. marker->bytes_read = bytes_read;
  153433. MAKE_BYTE_AVAIL(cinfo, return FALSE);
  153434. while (bytes_read < data_length && bytes_in_buffer > 0) {
  153435. *data++ = *next_input_byte++;
  153436. bytes_in_buffer--;
  153437. bytes_read++;
  153438. }
  153439. }
  153440. if (cur_marker != NULL) { /* will be NULL if bogus length word */
  153441. if (cinfo->marker_list == NULL) {
  153442. cinfo->marker_list = cur_marker;
  153443. } else {
  153444. jpeg_saved_marker_ptr prev = cinfo->marker_list;
  153445. while (prev->next != NULL)
  153446. prev = prev->next;
  153447. prev->next = cur_marker;
  153448. }
  153449. data = cur_marker->data;
  153450. length = cur_marker->original_length - data_length;
  153451. }
  153452. marker->cur_marker = NULL;
  153453. switch (cinfo->unread_marker) {
  153454. case M_APP0:
  153455. examine_app0(cinfo, data, data_length, length);
  153456. break;
  153457. case M_APP14:
  153458. examine_app14(cinfo, data, data_length, length);
  153459. break;
  153460. default:
  153461. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker,
  153462. (int) (data_length + length));
  153463. break;
  153464. }
  153465. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153466. if (length > 0)
  153467. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153468. return TRUE;
  153469. }
  153470. #endif /* SAVE_MARKERS_SUPPORTED */
  153471. METHODDEF(boolean)
  153472. skip_variable (j_decompress_ptr cinfo)
  153473. {
  153474. INT32 length;
  153475. INPUT_VARS(cinfo);
  153476. INPUT_2BYTES(cinfo, length, return FALSE);
  153477. length -= 2;
  153478. TRACEMS2(cinfo, 1, JTRC_MISC_MARKER, cinfo->unread_marker, (int) length);
  153479. INPUT_SYNC(cinfo); /* do before skip_input_data */
  153480. if (length > 0)
  153481. (*cinfo->src->skip_input_data) (cinfo, (long) length);
  153482. return TRUE;
  153483. }
  153484. LOCAL(boolean)
  153485. next_marker (j_decompress_ptr cinfo)
  153486. {
  153487. int c;
  153488. INPUT_VARS(cinfo);
  153489. for (;;) {
  153490. INPUT_BYTE(cinfo, c, return FALSE);
  153491. while (c != 0xFF) {
  153492. cinfo->marker->discarded_bytes++;
  153493. INPUT_SYNC(cinfo);
  153494. INPUT_BYTE(cinfo, c, return FALSE);
  153495. }
  153496. do {
  153497. INPUT_BYTE(cinfo, c, return FALSE);
  153498. } while (c == 0xFF);
  153499. if (c != 0)
  153500. break; /* found a valid marker, exit loop */
  153501. cinfo->marker->discarded_bytes += 2;
  153502. INPUT_SYNC(cinfo);
  153503. }
  153504. if (cinfo->marker->discarded_bytes != 0) {
  153505. WARNMS2(cinfo, JWRN_EXTRANEOUS_DATA, cinfo->marker->discarded_bytes, c);
  153506. cinfo->marker->discarded_bytes = 0;
  153507. }
  153508. cinfo->unread_marker = c;
  153509. INPUT_SYNC(cinfo);
  153510. return TRUE;
  153511. }
  153512. LOCAL(boolean)
  153513. first_marker (j_decompress_ptr cinfo)
  153514. {
  153515. int c, c2;
  153516. INPUT_VARS(cinfo);
  153517. INPUT_BYTE(cinfo, c, return FALSE);
  153518. INPUT_BYTE(cinfo, c2, return FALSE);
  153519. if (c != 0xFF || c2 != (int) M_SOI)
  153520. ERREXIT2(cinfo, JERR_NO_SOI, c, c2);
  153521. cinfo->unread_marker = c2;
  153522. INPUT_SYNC(cinfo);
  153523. return TRUE;
  153524. }
  153525. METHODDEF(int)
  153526. read_markers (j_decompress_ptr cinfo)
  153527. {
  153528. for (;;) {
  153529. if (cinfo->unread_marker == 0) {
  153530. if (! cinfo->marker->saw_SOI) {
  153531. if (! first_marker(cinfo))
  153532. return JPEG_SUSPENDED;
  153533. } else {
  153534. if (! next_marker(cinfo))
  153535. return JPEG_SUSPENDED;
  153536. }
  153537. }
  153538. switch (cinfo->unread_marker) {
  153539. case M_SOI:
  153540. if (! get_soi(cinfo))
  153541. return JPEG_SUSPENDED;
  153542. break;
  153543. case M_SOF0: /* Baseline */
  153544. case M_SOF1: /* Extended sequential, Huffman */
  153545. if (! get_sof(cinfo, FALSE, FALSE))
  153546. return JPEG_SUSPENDED;
  153547. break;
  153548. case M_SOF2: /* Progressive, Huffman */
  153549. if (! get_sof(cinfo, TRUE, FALSE))
  153550. return JPEG_SUSPENDED;
  153551. break;
  153552. case M_SOF9: /* Extended sequential, arithmetic */
  153553. if (! get_sof(cinfo, FALSE, TRUE))
  153554. return JPEG_SUSPENDED;
  153555. break;
  153556. case M_SOF10: /* Progressive, arithmetic */
  153557. if (! get_sof(cinfo, TRUE, TRUE))
  153558. return JPEG_SUSPENDED;
  153559. break;
  153560. case M_SOF3: /* Lossless, Huffman */
  153561. case M_SOF5: /* Differential sequential, Huffman */
  153562. case M_SOF6: /* Differential progressive, Huffman */
  153563. case M_SOF7: /* Differential lossless, Huffman */
  153564. case M_JPG: /* Reserved for JPEG extensions */
  153565. case M_SOF11: /* Lossless, arithmetic */
  153566. case M_SOF13: /* Differential sequential, arithmetic */
  153567. case M_SOF14: /* Differential progressive, arithmetic */
  153568. case M_SOF15: /* Differential lossless, arithmetic */
  153569. ERREXIT1(cinfo, JERR_SOF_UNSUPPORTED, cinfo->unread_marker);
  153570. break;
  153571. case M_SOS:
  153572. if (! get_sos(cinfo))
  153573. return JPEG_SUSPENDED;
  153574. cinfo->unread_marker = 0; /* processed the marker */
  153575. return JPEG_REACHED_SOS;
  153576. case M_EOI:
  153577. TRACEMS(cinfo, 1, JTRC_EOI);
  153578. cinfo->unread_marker = 0; /* processed the marker */
  153579. return JPEG_REACHED_EOI;
  153580. case M_DAC:
  153581. if (! get_dac(cinfo))
  153582. return JPEG_SUSPENDED;
  153583. break;
  153584. case M_DHT:
  153585. if (! get_dht(cinfo))
  153586. return JPEG_SUSPENDED;
  153587. break;
  153588. case M_DQT:
  153589. if (! get_dqt(cinfo))
  153590. return JPEG_SUSPENDED;
  153591. break;
  153592. case M_DRI:
  153593. if (! get_dri(cinfo))
  153594. return JPEG_SUSPENDED;
  153595. break;
  153596. case M_APP0:
  153597. case M_APP1:
  153598. case M_APP2:
  153599. case M_APP3:
  153600. case M_APP4:
  153601. case M_APP5:
  153602. case M_APP6:
  153603. case M_APP7:
  153604. case M_APP8:
  153605. case M_APP9:
  153606. case M_APP10:
  153607. case M_APP11:
  153608. case M_APP12:
  153609. case M_APP13:
  153610. case M_APP14:
  153611. case M_APP15:
  153612. if (! (*((my_marker_ptr2) cinfo->marker)->process_APPn[
  153613. cinfo->unread_marker - (int) M_APP0]) (cinfo))
  153614. return JPEG_SUSPENDED;
  153615. break;
  153616. case M_COM:
  153617. if (! (*((my_marker_ptr2) cinfo->marker)->process_COM) (cinfo))
  153618. return JPEG_SUSPENDED;
  153619. break;
  153620. case M_RST0: /* these are all parameterless */
  153621. case M_RST1:
  153622. case M_RST2:
  153623. case M_RST3:
  153624. case M_RST4:
  153625. case M_RST5:
  153626. case M_RST6:
  153627. case M_RST7:
  153628. case M_TEM:
  153629. TRACEMS1(cinfo, 1, JTRC_PARMLESS_MARKER, cinfo->unread_marker);
  153630. break;
  153631. case M_DNL: /* Ignore DNL ... perhaps the wrong thing */
  153632. if (! skip_variable(cinfo))
  153633. return JPEG_SUSPENDED;
  153634. break;
  153635. default: /* must be DHP, EXP, JPGn, or RESn */
  153636. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, cinfo->unread_marker);
  153637. break;
  153638. }
  153639. cinfo->unread_marker = 0;
  153640. } /* end loop */
  153641. }
  153642. METHODDEF(boolean)
  153643. read_restart_marker (j_decompress_ptr cinfo)
  153644. {
  153645. if (cinfo->unread_marker == 0) {
  153646. if (! next_marker(cinfo))
  153647. return FALSE;
  153648. }
  153649. if (cinfo->unread_marker ==
  153650. ((int) M_RST0 + cinfo->marker->next_restart_num)) {
  153651. TRACEMS1(cinfo, 3, JTRC_RST, cinfo->marker->next_restart_num);
  153652. cinfo->unread_marker = 0;
  153653. } else {
  153654. if (! (*cinfo->src->resync_to_restart) (cinfo,
  153655. cinfo->marker->next_restart_num))
  153656. return FALSE;
  153657. }
  153658. cinfo->marker->next_restart_num = (cinfo->marker->next_restart_num + 1) & 7;
  153659. return TRUE;
  153660. }
  153661. GLOBAL(boolean)
  153662. jpeg_resync_to_restart (j_decompress_ptr cinfo, int desired)
  153663. {
  153664. int marker = cinfo->unread_marker;
  153665. int action = 1;
  153666. WARNMS2(cinfo, JWRN_MUST_RESYNC, marker, desired);
  153667. for (;;) {
  153668. if (marker < (int) M_SOF0)
  153669. action = 2; /* invalid marker */
  153670. else if (marker < (int) M_RST0 || marker > (int) M_RST7)
  153671. action = 3; /* valid non-restart marker */
  153672. else {
  153673. if (marker == ((int) M_RST0 + ((desired+1) & 7)) ||
  153674. marker == ((int) M_RST0 + ((desired+2) & 7)))
  153675. action = 3; /* one of the next two expected restarts */
  153676. else if (marker == ((int) M_RST0 + ((desired-1) & 7)) ||
  153677. marker == ((int) M_RST0 + ((desired-2) & 7)))
  153678. action = 2; /* a prior restart, so advance */
  153679. else
  153680. action = 1; /* desired restart or too far away */
  153681. }
  153682. TRACEMS2(cinfo, 4, JTRC_RECOVERY_ACTION, marker, action);
  153683. switch (action) {
  153684. case 1:
  153685. cinfo->unread_marker = 0;
  153686. return TRUE;
  153687. case 2:
  153688. if (! next_marker(cinfo))
  153689. return FALSE;
  153690. marker = cinfo->unread_marker;
  153691. break;
  153692. case 3:
  153693. return TRUE;
  153694. }
  153695. } /* end loop */
  153696. }
  153697. METHODDEF(void)
  153698. reset_marker_reader (j_decompress_ptr cinfo)
  153699. {
  153700. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153701. cinfo->comp_info = NULL; /* until allocated by get_sof */
  153702. cinfo->input_scan_number = 0; /* no SOS seen yet */
  153703. cinfo->unread_marker = 0; /* no pending marker */
  153704. marker->pub.saw_SOI = FALSE; /* set internal state too */
  153705. marker->pub.saw_SOF = FALSE;
  153706. marker->pub.discarded_bytes = 0;
  153707. marker->cur_marker = NULL;
  153708. }
  153709. GLOBAL(void)
  153710. jinit_marker_reader (j_decompress_ptr cinfo)
  153711. {
  153712. my_marker_ptr2 marker;
  153713. int i;
  153714. marker = (my_marker_ptr2)
  153715. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_PERMANENT,
  153716. SIZEOF(my_marker_reader));
  153717. cinfo->marker = (struct jpeg_marker_reader *) marker;
  153718. marker->pub.reset_marker_reader = reset_marker_reader;
  153719. marker->pub.read_markers = read_markers;
  153720. marker->pub.read_restart_marker = read_restart_marker;
  153721. marker->process_COM = skip_variable;
  153722. marker->length_limit_COM = 0;
  153723. for (i = 0; i < 16; i++) {
  153724. marker->process_APPn[i] = skip_variable;
  153725. marker->length_limit_APPn[i] = 0;
  153726. }
  153727. marker->process_APPn[0] = get_interesting_appn;
  153728. marker->process_APPn[14] = get_interesting_appn;
  153729. reset_marker_reader(cinfo);
  153730. }
  153731. #ifdef SAVE_MARKERS_SUPPORTED
  153732. GLOBAL(void)
  153733. jpeg_save_markers (j_decompress_ptr cinfo, int marker_code,
  153734. unsigned int length_limit)
  153735. {
  153736. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153737. long maxlength;
  153738. jpeg_marker_parser_method processor;
  153739. maxlength = cinfo->mem->max_alloc_chunk - SIZEOF(struct jpeg_marker_struct);
  153740. if (((long) length_limit) > maxlength)
  153741. length_limit = (unsigned int) maxlength;
  153742. if (length_limit) {
  153743. processor = save_marker;
  153744. if (marker_code == (int) M_APP0 && length_limit < APP0_DATA_LEN)
  153745. length_limit = APP0_DATA_LEN;
  153746. else if (marker_code == (int) M_APP14 && length_limit < APP14_DATA_LEN)
  153747. length_limit = APP14_DATA_LEN;
  153748. } else {
  153749. processor = skip_variable;
  153750. if (marker_code == (int) M_APP0 || marker_code == (int) M_APP14)
  153751. processor = get_interesting_appn;
  153752. }
  153753. if (marker_code == (int) M_COM) {
  153754. marker->process_COM = processor;
  153755. marker->length_limit_COM = length_limit;
  153756. } else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15) {
  153757. marker->process_APPn[marker_code - (int) M_APP0] = processor;
  153758. marker->length_limit_APPn[marker_code - (int) M_APP0] = length_limit;
  153759. } else
  153760. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153761. }
  153762. #endif /* SAVE_MARKERS_SUPPORTED */
  153763. GLOBAL(void)
  153764. jpeg_set_marker_processor (j_decompress_ptr cinfo, int marker_code,
  153765. jpeg_marker_parser_method routine)
  153766. {
  153767. my_marker_ptr2 marker = (my_marker_ptr2) cinfo->marker;
  153768. if (marker_code == (int) M_COM)
  153769. marker->process_COM = routine;
  153770. else if (marker_code >= (int) M_APP0 && marker_code <= (int) M_APP15)
  153771. marker->process_APPn[marker_code - (int) M_APP0] = routine;
  153772. else
  153773. ERREXIT1(cinfo, JERR_UNKNOWN_MARKER, marker_code);
  153774. }
  153775. /*** End of inlined file: jdmarker.c ***/
  153776. /*** Start of inlined file: jdmaster.c ***/
  153777. #define JPEG_INTERNALS
  153778. typedef struct {
  153779. struct jpeg_decomp_master pub; /* public fields */
  153780. int pass_number; /* # of passes completed */
  153781. boolean using_merged_upsample; /* TRUE if using merged upsample/cconvert */
  153782. struct jpeg_color_quantizer * quantizer_1pass;
  153783. struct jpeg_color_quantizer * quantizer_2pass;
  153784. } my_decomp_master;
  153785. typedef my_decomp_master * my_master_ptr6;
  153786. LOCAL(boolean)
  153787. use_merged_upsample (j_decompress_ptr cinfo)
  153788. {
  153789. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153790. if (cinfo->do_fancy_upsampling || cinfo->CCIR601_sampling)
  153791. return FALSE;
  153792. if (cinfo->jpeg_color_space != JCS_YCbCr || cinfo->num_components != 3 ||
  153793. cinfo->out_color_space != JCS_RGB ||
  153794. cinfo->out_color_components != RGB_PIXELSIZE)
  153795. return FALSE;
  153796. if (cinfo->comp_info[0].h_samp_factor != 2 ||
  153797. cinfo->comp_info[1].h_samp_factor != 1 ||
  153798. cinfo->comp_info[2].h_samp_factor != 1 ||
  153799. cinfo->comp_info[0].v_samp_factor > 2 ||
  153800. cinfo->comp_info[1].v_samp_factor != 1 ||
  153801. cinfo->comp_info[2].v_samp_factor != 1)
  153802. return FALSE;
  153803. if (cinfo->comp_info[0].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153804. cinfo->comp_info[1].DCT_scaled_size != cinfo->min_DCT_scaled_size ||
  153805. cinfo->comp_info[2].DCT_scaled_size != cinfo->min_DCT_scaled_size)
  153806. return FALSE;
  153807. return TRUE; /* by golly, it'll work... */
  153808. #else
  153809. return FALSE;
  153810. #endif
  153811. }
  153812. GLOBAL(void)
  153813. jpeg_calc_output_dimensions (j_decompress_ptr cinfo)
  153814. {
  153815. #ifdef IDCT_SCALING_SUPPORTED
  153816. int ci;
  153817. jpeg_component_info *compptr;
  153818. #endif
  153819. if (cinfo->global_state != DSTATE_READY)
  153820. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  153821. #ifdef IDCT_SCALING_SUPPORTED
  153822. if (cinfo->scale_num * 8 <= cinfo->scale_denom) {
  153823. cinfo->output_width = (JDIMENSION)
  153824. jdiv_round_up((long) cinfo->image_width, 8L);
  153825. cinfo->output_height = (JDIMENSION)
  153826. jdiv_round_up((long) cinfo->image_height, 8L);
  153827. cinfo->min_DCT_scaled_size = 1;
  153828. } else if (cinfo->scale_num * 4 <= cinfo->scale_denom) {
  153829. cinfo->output_width = (JDIMENSION)
  153830. jdiv_round_up((long) cinfo->image_width, 4L);
  153831. cinfo->output_height = (JDIMENSION)
  153832. jdiv_round_up((long) cinfo->image_height, 4L);
  153833. cinfo->min_DCT_scaled_size = 2;
  153834. } else if (cinfo->scale_num * 2 <= cinfo->scale_denom) {
  153835. cinfo->output_width = (JDIMENSION)
  153836. jdiv_round_up((long) cinfo->image_width, 2L);
  153837. cinfo->output_height = (JDIMENSION)
  153838. jdiv_round_up((long) cinfo->image_height, 2L);
  153839. cinfo->min_DCT_scaled_size = 4;
  153840. } else {
  153841. cinfo->output_width = cinfo->image_width;
  153842. cinfo->output_height = cinfo->image_height;
  153843. cinfo->min_DCT_scaled_size = DCTSIZE;
  153844. }
  153845. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153846. ci++, compptr++) {
  153847. int ssize = cinfo->min_DCT_scaled_size;
  153848. while (ssize < DCTSIZE &&
  153849. (compptr->h_samp_factor * ssize * 2 <=
  153850. cinfo->max_h_samp_factor * cinfo->min_DCT_scaled_size) &&
  153851. (compptr->v_samp_factor * ssize * 2 <=
  153852. cinfo->max_v_samp_factor * cinfo->min_DCT_scaled_size)) {
  153853. ssize = ssize * 2;
  153854. }
  153855. compptr->DCT_scaled_size = ssize;
  153856. }
  153857. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  153858. ci++, compptr++) {
  153859. compptr->downsampled_width = (JDIMENSION)
  153860. jdiv_round_up((long) cinfo->image_width *
  153861. (long) (compptr->h_samp_factor * compptr->DCT_scaled_size),
  153862. (long) (cinfo->max_h_samp_factor * DCTSIZE));
  153863. compptr->downsampled_height = (JDIMENSION)
  153864. jdiv_round_up((long) cinfo->image_height *
  153865. (long) (compptr->v_samp_factor * compptr->DCT_scaled_size),
  153866. (long) (cinfo->max_v_samp_factor * DCTSIZE));
  153867. }
  153868. #else /* !IDCT_SCALING_SUPPORTED */
  153869. cinfo->output_width = cinfo->image_width;
  153870. cinfo->output_height = cinfo->image_height;
  153871. #endif /* IDCT_SCALING_SUPPORTED */
  153872. switch (cinfo->out_color_space) {
  153873. case JCS_GRAYSCALE:
  153874. cinfo->out_color_components = 1;
  153875. break;
  153876. case JCS_RGB:
  153877. #if RGB_PIXELSIZE != 3
  153878. cinfo->out_color_components = RGB_PIXELSIZE;
  153879. break;
  153880. #endif /* else share code with YCbCr */
  153881. case JCS_YCbCr:
  153882. cinfo->out_color_components = 3;
  153883. break;
  153884. case JCS_CMYK:
  153885. case JCS_YCCK:
  153886. cinfo->out_color_components = 4;
  153887. break;
  153888. default: /* else must be same colorspace as in file */
  153889. cinfo->out_color_components = cinfo->num_components;
  153890. break;
  153891. }
  153892. cinfo->output_components = (cinfo->quantize_colors ? 1 :
  153893. cinfo->out_color_components);
  153894. if (use_merged_upsample(cinfo))
  153895. cinfo->rec_outbuf_height = cinfo->max_v_samp_factor;
  153896. else
  153897. cinfo->rec_outbuf_height = 1;
  153898. }
  153899. LOCAL(void)
  153900. prepare_range_limit_table (j_decompress_ptr cinfo)
  153901. {
  153902. JSAMPLE * table;
  153903. int i;
  153904. table = (JSAMPLE *)
  153905. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  153906. (5 * (MAXJSAMPLE+1) + CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153907. table += (MAXJSAMPLE+1); /* allow negative subscripts of simple table */
  153908. cinfo->sample_range_limit = table;
  153909. MEMZERO(table - (MAXJSAMPLE+1), (MAXJSAMPLE+1) * SIZEOF(JSAMPLE));
  153910. for (i = 0; i <= MAXJSAMPLE; i++)
  153911. table[i] = (JSAMPLE) i;
  153912. table += CENTERJSAMPLE; /* Point to where post-IDCT table starts */
  153913. for (i = CENTERJSAMPLE; i < 2*(MAXJSAMPLE+1); i++)
  153914. table[i] = MAXJSAMPLE;
  153915. MEMZERO(table + (2 * (MAXJSAMPLE+1)),
  153916. (2 * (MAXJSAMPLE+1) - CENTERJSAMPLE) * SIZEOF(JSAMPLE));
  153917. MEMCOPY(table + (4 * (MAXJSAMPLE+1) - CENTERJSAMPLE),
  153918. cinfo->sample_range_limit, CENTERJSAMPLE * SIZEOF(JSAMPLE));
  153919. }
  153920. LOCAL(void)
  153921. master_selection (j_decompress_ptr cinfo)
  153922. {
  153923. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  153924. boolean use_c_buffer;
  153925. long samplesperrow;
  153926. JDIMENSION jd_samplesperrow;
  153927. jpeg_calc_output_dimensions(cinfo);
  153928. prepare_range_limit_table(cinfo);
  153929. samplesperrow = (long) cinfo->output_width * (long) cinfo->out_color_components;
  153930. jd_samplesperrow = (JDIMENSION) samplesperrow;
  153931. if ((long) jd_samplesperrow != samplesperrow)
  153932. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  153933. master->pass_number = 0;
  153934. master->using_merged_upsample = use_merged_upsample(cinfo);
  153935. master->quantizer_1pass = NULL;
  153936. master->quantizer_2pass = NULL;
  153937. if (! cinfo->quantize_colors || ! cinfo->buffered_image) {
  153938. cinfo->enable_1pass_quant = FALSE;
  153939. cinfo->enable_external_quant = FALSE;
  153940. cinfo->enable_2pass_quant = FALSE;
  153941. }
  153942. if (cinfo->quantize_colors) {
  153943. if (cinfo->raw_data_out)
  153944. ERREXIT(cinfo, JERR_NOTIMPL);
  153945. if (cinfo->out_color_components != 3) {
  153946. cinfo->enable_1pass_quant = TRUE;
  153947. cinfo->enable_external_quant = FALSE;
  153948. cinfo->enable_2pass_quant = FALSE;
  153949. cinfo->colormap = NULL;
  153950. } else if (cinfo->colormap != NULL) {
  153951. cinfo->enable_external_quant = TRUE;
  153952. } else if (cinfo->two_pass_quantize) {
  153953. cinfo->enable_2pass_quant = TRUE;
  153954. } else {
  153955. cinfo->enable_1pass_quant = TRUE;
  153956. }
  153957. if (cinfo->enable_1pass_quant) {
  153958. #ifdef QUANT_1PASS_SUPPORTED
  153959. jinit_1pass_quantizer(cinfo);
  153960. master->quantizer_1pass = cinfo->cquantize;
  153961. #else
  153962. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153963. #endif
  153964. }
  153965. if (cinfo->enable_2pass_quant || cinfo->enable_external_quant) {
  153966. #ifdef QUANT_2PASS_SUPPORTED
  153967. jinit_2pass_quantizer(cinfo);
  153968. master->quantizer_2pass = cinfo->cquantize;
  153969. #else
  153970. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153971. #endif
  153972. }
  153973. }
  153974. if (! cinfo->raw_data_out) {
  153975. if (master->using_merged_upsample) {
  153976. #ifdef UPSAMPLE_MERGING_SUPPORTED
  153977. jinit_merged_upsampler(cinfo); /* does color conversion too */
  153978. #else
  153979. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153980. #endif
  153981. } else {
  153982. jinit_color_deconverter(cinfo);
  153983. jinit_upsampler(cinfo);
  153984. }
  153985. jinit_d_post_controller(cinfo, cinfo->enable_2pass_quant);
  153986. }
  153987. jinit_inverse_dct(cinfo);
  153988. if (cinfo->arith_code) {
  153989. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  153990. } else {
  153991. if (cinfo->progressive_mode) {
  153992. #ifdef D_PROGRESSIVE_SUPPORTED
  153993. jinit_phuff_decoder(cinfo);
  153994. #else
  153995. ERREXIT(cinfo, JERR_NOT_COMPILED);
  153996. #endif
  153997. } else
  153998. jinit_huff_decoder(cinfo);
  153999. }
  154000. use_c_buffer = cinfo->inputctl->has_multiple_scans || cinfo->buffered_image;
  154001. jinit_d_coef_controller(cinfo, use_c_buffer);
  154002. if (! cinfo->raw_data_out)
  154003. jinit_d_main_controller(cinfo, FALSE /* never need full buffer here */);
  154004. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  154005. (*cinfo->inputctl->start_input_pass) (cinfo);
  154006. #ifdef D_MULTISCAN_FILES_SUPPORTED
  154007. if (cinfo->progress != NULL && ! cinfo->buffered_image &&
  154008. cinfo->inputctl->has_multiple_scans) {
  154009. int nscans;
  154010. if (cinfo->progressive_mode) {
  154011. nscans = 2 + 3 * cinfo->num_components;
  154012. } else {
  154013. nscans = cinfo->num_components;
  154014. }
  154015. cinfo->progress->pass_counter = 0L;
  154016. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  154017. cinfo->progress->completed_passes = 0;
  154018. cinfo->progress->total_passes = (cinfo->enable_2pass_quant ? 3 : 2);
  154019. master->pass_number++;
  154020. }
  154021. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  154022. }
  154023. METHODDEF(void)
  154024. prepare_for_output_pass (j_decompress_ptr cinfo)
  154025. {
  154026. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154027. if (master->pub.is_dummy_pass) {
  154028. #ifdef QUANT_2PASS_SUPPORTED
  154029. master->pub.is_dummy_pass = FALSE;
  154030. (*cinfo->cquantize->start_pass) (cinfo, FALSE);
  154031. (*cinfo->post->start_pass) (cinfo, JBUF_CRANK_DEST);
  154032. (*cinfo->main->start_pass) (cinfo, JBUF_CRANK_DEST);
  154033. #else
  154034. ERREXIT(cinfo, JERR_NOT_COMPILED);
  154035. #endif /* QUANT_2PASS_SUPPORTED */
  154036. } else {
  154037. if (cinfo->quantize_colors && cinfo->colormap == NULL) {
  154038. if (cinfo->two_pass_quantize && cinfo->enable_2pass_quant) {
  154039. cinfo->cquantize = master->quantizer_2pass;
  154040. master->pub.is_dummy_pass = TRUE;
  154041. } else if (cinfo->enable_1pass_quant) {
  154042. cinfo->cquantize = master->quantizer_1pass;
  154043. } else {
  154044. ERREXIT(cinfo, JERR_MODE_CHANGE);
  154045. }
  154046. }
  154047. (*cinfo->idct->start_pass) (cinfo);
  154048. (*cinfo->coef->start_output_pass) (cinfo);
  154049. if (! cinfo->raw_data_out) {
  154050. if (! master->using_merged_upsample)
  154051. (*cinfo->cconvert->start_pass) (cinfo);
  154052. (*cinfo->upsample->start_pass) (cinfo);
  154053. if (cinfo->quantize_colors)
  154054. (*cinfo->cquantize->start_pass) (cinfo, master->pub.is_dummy_pass);
  154055. (*cinfo->post->start_pass) (cinfo,
  154056. (master->pub.is_dummy_pass ? JBUF_SAVE_AND_PASS : JBUF_PASS_THRU));
  154057. (*cinfo->main->start_pass) (cinfo, JBUF_PASS_THRU);
  154058. }
  154059. }
  154060. if (cinfo->progress != NULL) {
  154061. cinfo->progress->completed_passes = master->pass_number;
  154062. cinfo->progress->total_passes = master->pass_number +
  154063. (master->pub.is_dummy_pass ? 2 : 1);
  154064. if (cinfo->buffered_image && ! cinfo->inputctl->eoi_reached) {
  154065. cinfo->progress->total_passes += (cinfo->enable_2pass_quant ? 2 : 1);
  154066. }
  154067. }
  154068. }
  154069. METHODDEF(void)
  154070. finish_output_pass (j_decompress_ptr cinfo)
  154071. {
  154072. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154073. if (cinfo->quantize_colors)
  154074. (*cinfo->cquantize->finish_pass) (cinfo);
  154075. master->pass_number++;
  154076. }
  154077. #ifdef D_MULTISCAN_FILES_SUPPORTED
  154078. GLOBAL(void)
  154079. jpeg_new_colormap (j_decompress_ptr cinfo)
  154080. {
  154081. my_master_ptr6 master = (my_master_ptr6) cinfo->master;
  154082. if (cinfo->global_state != DSTATE_BUFIMAGE)
  154083. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  154084. if (cinfo->quantize_colors && cinfo->enable_external_quant &&
  154085. cinfo->colormap != NULL) {
  154086. cinfo->cquantize = master->quantizer_2pass;
  154087. (*cinfo->cquantize->new_color_map) (cinfo);
  154088. master->pub.is_dummy_pass = FALSE; /* just in case */
  154089. } else
  154090. ERREXIT(cinfo, JERR_MODE_CHANGE);
  154091. }
  154092. #endif /* D_MULTISCAN_FILES_SUPPORTED */
  154093. GLOBAL(void)
  154094. jinit_master_decompress (j_decompress_ptr cinfo)
  154095. {
  154096. my_master_ptr6 master;
  154097. master = (my_master_ptr6)
  154098. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154099. SIZEOF(my_decomp_master));
  154100. cinfo->master = (struct jpeg_decomp_master *) master;
  154101. master->pub.prepare_for_output_pass = prepare_for_output_pass;
  154102. master->pub.finish_output_pass = finish_output_pass;
  154103. master->pub.is_dummy_pass = FALSE;
  154104. master_selection(cinfo);
  154105. }
  154106. /*** End of inlined file: jdmaster.c ***/
  154107. #undef FIX
  154108. /*** Start of inlined file: jdmerge.c ***/
  154109. #define JPEG_INTERNALS
  154110. #ifdef UPSAMPLE_MERGING_SUPPORTED
  154111. typedef struct {
  154112. struct jpeg_upsampler pub; /* public fields */
  154113. JMETHOD(void, upmethod, (j_decompress_ptr cinfo,
  154114. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154115. JSAMPARRAY output_buf));
  154116. int * Cr_r_tab; /* => table for Cr to R conversion */
  154117. int * Cb_b_tab; /* => table for Cb to B conversion */
  154118. INT32 * Cr_g_tab; /* => table for Cr to G conversion */
  154119. INT32 * Cb_g_tab; /* => table for Cb to G conversion */
  154120. JSAMPROW spare_row;
  154121. boolean spare_full; /* T if spare buffer is occupied */
  154122. JDIMENSION out_row_width; /* samples per output row */
  154123. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154124. } my_upsampler;
  154125. typedef my_upsampler * my_upsample_ptr;
  154126. #define SCALEBITS 16 /* speediest right-shift on some machines */
  154127. #define ONE_HALF ((INT32) 1 << (SCALEBITS-1))
  154128. #define FIX(x) ((INT32) ((x) * (1L<<SCALEBITS) + 0.5))
  154129. LOCAL(void)
  154130. build_ycc_rgb_table2 (j_decompress_ptr cinfo)
  154131. {
  154132. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154133. int i;
  154134. INT32 x;
  154135. SHIFT_TEMPS
  154136. upsample->Cr_r_tab = (int *)
  154137. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154138. (MAXJSAMPLE+1) * SIZEOF(int));
  154139. upsample->Cb_b_tab = (int *)
  154140. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154141. (MAXJSAMPLE+1) * SIZEOF(int));
  154142. upsample->Cr_g_tab = (INT32 *)
  154143. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154144. (MAXJSAMPLE+1) * SIZEOF(INT32));
  154145. upsample->Cb_g_tab = (INT32 *)
  154146. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154147. (MAXJSAMPLE+1) * SIZEOF(INT32));
  154148. for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
  154149. upsample->Cr_r_tab[i] = (int)
  154150. RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
  154151. upsample->Cb_b_tab[i] = (int)
  154152. RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
  154153. upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
  154154. upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  154155. }
  154156. }
  154157. METHODDEF(void)
  154158. start_pass_merged_upsample (j_decompress_ptr cinfo)
  154159. {
  154160. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154161. upsample->spare_full = FALSE;
  154162. upsample->rows_to_go = cinfo->output_height;
  154163. }
  154164. METHODDEF(void)
  154165. merged_2v_upsample (j_decompress_ptr cinfo,
  154166. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154167. JDIMENSION in_row_groups_avail,
  154168. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154169. JDIMENSION out_rows_avail)
  154170. {
  154171. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154172. JSAMPROW work_ptrs[2];
  154173. JDIMENSION num_rows; /* number of rows returned to caller */
  154174. if (upsample->spare_full) {
  154175. jcopy_sample_rows(& upsample->spare_row, 0, output_buf + *out_row_ctr, 0,
  154176. 1, upsample->out_row_width);
  154177. num_rows = 1;
  154178. upsample->spare_full = FALSE;
  154179. } else {
  154180. num_rows = 2;
  154181. if (num_rows > upsample->rows_to_go)
  154182. num_rows = upsample->rows_to_go;
  154183. out_rows_avail -= *out_row_ctr;
  154184. if (num_rows > out_rows_avail)
  154185. num_rows = out_rows_avail;
  154186. work_ptrs[0] = output_buf[*out_row_ctr];
  154187. if (num_rows > 1) {
  154188. work_ptrs[1] = output_buf[*out_row_ctr + 1];
  154189. } else {
  154190. work_ptrs[1] = upsample->spare_row;
  154191. upsample->spare_full = TRUE;
  154192. }
  154193. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr, work_ptrs);
  154194. }
  154195. *out_row_ctr += num_rows;
  154196. upsample->rows_to_go -= num_rows;
  154197. if (! upsample->spare_full)
  154198. (*in_row_group_ctr)++;
  154199. }
  154200. METHODDEF(void)
  154201. merged_1v_upsample (j_decompress_ptr cinfo,
  154202. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154203. JDIMENSION in_row_groups_avail,
  154204. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154205. JDIMENSION out_rows_avail)
  154206. {
  154207. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154208. (*upsample->upmethod) (cinfo, input_buf, *in_row_group_ctr,
  154209. output_buf + *out_row_ctr);
  154210. (*out_row_ctr)++;
  154211. (*in_row_group_ctr)++;
  154212. }
  154213. METHODDEF(void)
  154214. h2v1_merged_upsample (j_decompress_ptr cinfo,
  154215. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154216. JSAMPARRAY output_buf)
  154217. {
  154218. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154219. register int y, cred, cgreen, cblue;
  154220. int cb, cr;
  154221. register JSAMPROW outptr;
  154222. JSAMPROW inptr0, inptr1, inptr2;
  154223. JDIMENSION col;
  154224. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154225. int * Crrtab = upsample->Cr_r_tab;
  154226. int * Cbbtab = upsample->Cb_b_tab;
  154227. INT32 * Crgtab = upsample->Cr_g_tab;
  154228. INT32 * Cbgtab = upsample->Cb_g_tab;
  154229. SHIFT_TEMPS
  154230. inptr0 = input_buf[0][in_row_group_ctr];
  154231. inptr1 = input_buf[1][in_row_group_ctr];
  154232. inptr2 = input_buf[2][in_row_group_ctr];
  154233. outptr = output_buf[0];
  154234. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154235. cb = GETJSAMPLE(*inptr1++);
  154236. cr = GETJSAMPLE(*inptr2++);
  154237. cred = Crrtab[cr];
  154238. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154239. cblue = Cbbtab[cb];
  154240. y = GETJSAMPLE(*inptr0++);
  154241. outptr[RGB_RED] = range_limit[y + cred];
  154242. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154243. outptr[RGB_BLUE] = range_limit[y + cblue];
  154244. outptr += RGB_PIXELSIZE;
  154245. y = GETJSAMPLE(*inptr0++);
  154246. outptr[RGB_RED] = range_limit[y + cred];
  154247. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154248. outptr[RGB_BLUE] = range_limit[y + cblue];
  154249. outptr += RGB_PIXELSIZE;
  154250. }
  154251. if (cinfo->output_width & 1) {
  154252. cb = GETJSAMPLE(*inptr1);
  154253. cr = GETJSAMPLE(*inptr2);
  154254. cred = Crrtab[cr];
  154255. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154256. cblue = Cbbtab[cb];
  154257. y = GETJSAMPLE(*inptr0);
  154258. outptr[RGB_RED] = range_limit[y + cred];
  154259. outptr[RGB_GREEN] = range_limit[y + cgreen];
  154260. outptr[RGB_BLUE] = range_limit[y + cblue];
  154261. }
  154262. }
  154263. METHODDEF(void)
  154264. h2v2_merged_upsample (j_decompress_ptr cinfo,
  154265. JSAMPIMAGE input_buf, JDIMENSION in_row_group_ctr,
  154266. JSAMPARRAY output_buf)
  154267. {
  154268. my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  154269. register int y, cred, cgreen, cblue;
  154270. int cb, cr;
  154271. register JSAMPROW outptr0, outptr1;
  154272. JSAMPROW inptr00, inptr01, inptr1, inptr2;
  154273. JDIMENSION col;
  154274. register JSAMPLE * range_limit = cinfo->sample_range_limit;
  154275. int * Crrtab = upsample->Cr_r_tab;
  154276. int * Cbbtab = upsample->Cb_b_tab;
  154277. INT32 * Crgtab = upsample->Cr_g_tab;
  154278. INT32 * Cbgtab = upsample->Cb_g_tab;
  154279. SHIFT_TEMPS
  154280. inptr00 = input_buf[0][in_row_group_ctr*2];
  154281. inptr01 = input_buf[0][in_row_group_ctr*2 + 1];
  154282. inptr1 = input_buf[1][in_row_group_ctr];
  154283. inptr2 = input_buf[2][in_row_group_ctr];
  154284. outptr0 = output_buf[0];
  154285. outptr1 = output_buf[1];
  154286. for (col = cinfo->output_width >> 1; col > 0; col--) {
  154287. cb = GETJSAMPLE(*inptr1++);
  154288. cr = GETJSAMPLE(*inptr2++);
  154289. cred = Crrtab[cr];
  154290. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154291. cblue = Cbbtab[cb];
  154292. y = GETJSAMPLE(*inptr00++);
  154293. outptr0[RGB_RED] = range_limit[y + cred];
  154294. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154295. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154296. outptr0 += RGB_PIXELSIZE;
  154297. y = GETJSAMPLE(*inptr00++);
  154298. outptr0[RGB_RED] = range_limit[y + cred];
  154299. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154300. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154301. outptr0 += RGB_PIXELSIZE;
  154302. y = GETJSAMPLE(*inptr01++);
  154303. outptr1[RGB_RED] = range_limit[y + cred];
  154304. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154305. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154306. outptr1 += RGB_PIXELSIZE;
  154307. y = GETJSAMPLE(*inptr01++);
  154308. outptr1[RGB_RED] = range_limit[y + cred];
  154309. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154310. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154311. outptr1 += RGB_PIXELSIZE;
  154312. }
  154313. if (cinfo->output_width & 1) {
  154314. cb = GETJSAMPLE(*inptr1);
  154315. cr = GETJSAMPLE(*inptr2);
  154316. cred = Crrtab[cr];
  154317. cgreen = (int) RIGHT_SHIFT(Cbgtab[cb] + Crgtab[cr], SCALEBITS);
  154318. cblue = Cbbtab[cb];
  154319. y = GETJSAMPLE(*inptr00);
  154320. outptr0[RGB_RED] = range_limit[y + cred];
  154321. outptr0[RGB_GREEN] = range_limit[y + cgreen];
  154322. outptr0[RGB_BLUE] = range_limit[y + cblue];
  154323. y = GETJSAMPLE(*inptr01);
  154324. outptr1[RGB_RED] = range_limit[y + cred];
  154325. outptr1[RGB_GREEN] = range_limit[y + cgreen];
  154326. outptr1[RGB_BLUE] = range_limit[y + cblue];
  154327. }
  154328. }
  154329. GLOBAL(void)
  154330. jinit_merged_upsampler (j_decompress_ptr cinfo)
  154331. {
  154332. my_upsample_ptr upsample;
  154333. upsample = (my_upsample_ptr)
  154334. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154335. SIZEOF(my_upsampler));
  154336. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  154337. upsample->pub.start_pass = start_pass_merged_upsample;
  154338. upsample->pub.need_context_rows = FALSE;
  154339. upsample->out_row_width = cinfo->output_width * cinfo->out_color_components;
  154340. if (cinfo->max_v_samp_factor == 2) {
  154341. upsample->pub.upsample = merged_2v_upsample;
  154342. upsample->upmethod = h2v2_merged_upsample;
  154343. upsample->spare_row = (JSAMPROW)
  154344. (*cinfo->mem->alloc_large) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154345. (size_t) (upsample->out_row_width * SIZEOF(JSAMPLE)));
  154346. } else {
  154347. upsample->pub.upsample = merged_1v_upsample;
  154348. upsample->upmethod = h2v1_merged_upsample;
  154349. upsample->spare_row = NULL;
  154350. }
  154351. build_ycc_rgb_table2(cinfo);
  154352. }
  154353. #endif /* UPSAMPLE_MERGING_SUPPORTED */
  154354. /*** End of inlined file: jdmerge.c ***/
  154355. #undef ASSIGN_STATE
  154356. /*** Start of inlined file: jdphuff.c ***/
  154357. #define JPEG_INTERNALS
  154358. #ifdef D_PROGRESSIVE_SUPPORTED
  154359. typedef struct {
  154360. unsigned int EOBRUN; /* remaining EOBs in EOBRUN */
  154361. int last_dc_val[MAX_COMPS_IN_SCAN]; /* last DC coef for each component */
  154362. } savable_state3;
  154363. #ifndef NO_STRUCT_ASSIGN
  154364. #define ASSIGN_STATE(dest,src) ((dest) = (src))
  154365. #else
  154366. #if MAX_COMPS_IN_SCAN == 4
  154367. #define ASSIGN_STATE(dest,src) \
  154368. ((dest).EOBRUN = (src).EOBRUN, \
  154369. (dest).last_dc_val[0] = (src).last_dc_val[0], \
  154370. (dest).last_dc_val[1] = (src).last_dc_val[1], \
  154371. (dest).last_dc_val[2] = (src).last_dc_val[2], \
  154372. (dest).last_dc_val[3] = (src).last_dc_val[3])
  154373. #endif
  154374. #endif
  154375. typedef struct {
  154376. struct jpeg_entropy_decoder pub; /* public fields */
  154377. bitread_perm_state bitstate; /* Bit buffer at start of MCU */
  154378. savable_state3 saved; /* Other state at start of MCU */
  154379. unsigned int restarts_to_go; /* MCUs left in this restart interval */
  154380. d_derived_tbl * derived_tbls[NUM_HUFF_TBLS];
  154381. d_derived_tbl * ac_derived_tbl; /* active table during an AC scan */
  154382. } phuff_entropy_decoder;
  154383. typedef phuff_entropy_decoder * phuff_entropy_ptr2;
  154384. METHODDEF(boolean) decode_mcu_DC_first JPP((j_decompress_ptr cinfo,
  154385. JBLOCKROW *MCU_data));
  154386. METHODDEF(boolean) decode_mcu_AC_first JPP((j_decompress_ptr cinfo,
  154387. JBLOCKROW *MCU_data));
  154388. METHODDEF(boolean) decode_mcu_DC_refine JPP((j_decompress_ptr cinfo,
  154389. JBLOCKROW *MCU_data));
  154390. METHODDEF(boolean) decode_mcu_AC_refine JPP((j_decompress_ptr cinfo,
  154391. JBLOCKROW *MCU_data));
  154392. METHODDEF(void)
  154393. start_pass_phuff_decoder (j_decompress_ptr cinfo)
  154394. {
  154395. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154396. boolean is_DC_band, bad;
  154397. int ci, coefi, tbl;
  154398. int *coef_bit_ptr;
  154399. jpeg_component_info * compptr;
  154400. is_DC_band = (cinfo->Ss == 0);
  154401. bad = FALSE;
  154402. if (is_DC_band) {
  154403. if (cinfo->Se != 0)
  154404. bad = TRUE;
  154405. } else {
  154406. if (cinfo->Ss > cinfo->Se || cinfo->Se >= DCTSIZE2)
  154407. bad = TRUE;
  154408. if (cinfo->comps_in_scan != 1)
  154409. bad = TRUE;
  154410. }
  154411. if (cinfo->Ah != 0) {
  154412. if (cinfo->Al != cinfo->Ah-1)
  154413. bad = TRUE;
  154414. }
  154415. if (cinfo->Al > 13) /* need not check for < 0 */
  154416. bad = TRUE;
  154417. if (bad)
  154418. ERREXIT4(cinfo, JERR_BAD_PROGRESSION,
  154419. cinfo->Ss, cinfo->Se, cinfo->Ah, cinfo->Al);
  154420. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154421. int cindex = cinfo->cur_comp_info[ci]->component_index;
  154422. coef_bit_ptr = & cinfo->coef_bits[cindex][0];
  154423. if (!is_DC_band && coef_bit_ptr[0] < 0) /* AC without prior DC scan */
  154424. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, 0);
  154425. for (coefi = cinfo->Ss; coefi <= cinfo->Se; coefi++) {
  154426. int expected = (coef_bit_ptr[coefi] < 0) ? 0 : coef_bit_ptr[coefi];
  154427. if (cinfo->Ah != expected)
  154428. WARNMS2(cinfo, JWRN_BOGUS_PROGRESSION, cindex, coefi);
  154429. coef_bit_ptr[coefi] = cinfo->Al;
  154430. }
  154431. }
  154432. if (cinfo->Ah == 0) {
  154433. if (is_DC_band)
  154434. entropy->pub.decode_mcu = decode_mcu_DC_first;
  154435. else
  154436. entropy->pub.decode_mcu = decode_mcu_AC_first;
  154437. } else {
  154438. if (is_DC_band)
  154439. entropy->pub.decode_mcu = decode_mcu_DC_refine;
  154440. else
  154441. entropy->pub.decode_mcu = decode_mcu_AC_refine;
  154442. }
  154443. for (ci = 0; ci < cinfo->comps_in_scan; ci++) {
  154444. compptr = cinfo->cur_comp_info[ci];
  154445. if (is_DC_band) {
  154446. if (cinfo->Ah == 0) { /* DC refinement needs no table */
  154447. tbl = compptr->dc_tbl_no;
  154448. jpeg_make_d_derived_tbl(cinfo, TRUE, tbl,
  154449. & entropy->derived_tbls[tbl]);
  154450. }
  154451. } else {
  154452. tbl = compptr->ac_tbl_no;
  154453. jpeg_make_d_derived_tbl(cinfo, FALSE, tbl,
  154454. & entropy->derived_tbls[tbl]);
  154455. entropy->ac_derived_tbl = entropy->derived_tbls[tbl];
  154456. }
  154457. entropy->saved.last_dc_val[ci] = 0;
  154458. }
  154459. entropy->bitstate.bits_left = 0;
  154460. entropy->bitstate.get_buffer = 0; /* unnecessary, but keeps Purify quiet */
  154461. entropy->pub.insufficient_data = FALSE;
  154462. entropy->saved.EOBRUN = 0;
  154463. entropy->restarts_to_go = cinfo->restart_interval;
  154464. }
  154465. LOCAL(boolean)
  154466. process_restartp (j_decompress_ptr cinfo)
  154467. {
  154468. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154469. int ci;
  154470. cinfo->marker->discarded_bytes += entropy->bitstate.bits_left / 8;
  154471. entropy->bitstate.bits_left = 0;
  154472. if (! (*cinfo->marker->read_restart_marker) (cinfo))
  154473. return FALSE;
  154474. for (ci = 0; ci < cinfo->comps_in_scan; ci++)
  154475. entropy->saved.last_dc_val[ci] = 0;
  154476. entropy->saved.EOBRUN = 0;
  154477. entropy->restarts_to_go = cinfo->restart_interval;
  154478. if (cinfo->unread_marker == 0)
  154479. entropy->pub.insufficient_data = FALSE;
  154480. return TRUE;
  154481. }
  154482. METHODDEF(boolean)
  154483. decode_mcu_DC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154484. {
  154485. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154486. int Al = cinfo->Al;
  154487. register int s, r;
  154488. int blkn, ci;
  154489. JBLOCKROW block;
  154490. BITREAD_STATE_VARS;
  154491. savable_state3 state;
  154492. d_derived_tbl * tbl;
  154493. jpeg_component_info * compptr;
  154494. if (cinfo->restart_interval) {
  154495. if (entropy->restarts_to_go == 0)
  154496. if (! process_restartp(cinfo))
  154497. return FALSE;
  154498. }
  154499. if (! entropy->pub.insufficient_data) {
  154500. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154501. ASSIGN_STATE(state, entropy->saved);
  154502. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154503. block = MCU_data[blkn];
  154504. ci = cinfo->MCU_membership[blkn];
  154505. compptr = cinfo->cur_comp_info[ci];
  154506. tbl = entropy->derived_tbls[compptr->dc_tbl_no];
  154507. HUFF_DECODE(s, br_state, tbl, return FALSE, label1);
  154508. if (s) {
  154509. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154510. r = GET_BITS(s);
  154511. s = HUFF_EXTEND(r, s);
  154512. }
  154513. s += state.last_dc_val[ci];
  154514. state.last_dc_val[ci] = s;
  154515. (*block)[0] = (JCOEF) (s << Al);
  154516. }
  154517. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154518. ASSIGN_STATE(entropy->saved, state);
  154519. }
  154520. entropy->restarts_to_go--;
  154521. return TRUE;
  154522. }
  154523. METHODDEF(boolean)
  154524. decode_mcu_AC_first (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154525. {
  154526. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154527. int Se = cinfo->Se;
  154528. int Al = cinfo->Al;
  154529. register int s, k, r;
  154530. unsigned int EOBRUN;
  154531. JBLOCKROW block;
  154532. BITREAD_STATE_VARS;
  154533. d_derived_tbl * tbl;
  154534. if (cinfo->restart_interval) {
  154535. if (entropy->restarts_to_go == 0)
  154536. if (! process_restartp(cinfo))
  154537. return FALSE;
  154538. }
  154539. if (! entropy->pub.insufficient_data) {
  154540. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154541. if (EOBRUN > 0) /* if it's a band of zeroes... */
  154542. EOBRUN--; /* ...process it now (we do nothing) */
  154543. else {
  154544. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154545. block = MCU_data[0];
  154546. tbl = entropy->ac_derived_tbl;
  154547. for (k = cinfo->Ss; k <= Se; k++) {
  154548. HUFF_DECODE(s, br_state, tbl, return FALSE, label2);
  154549. r = s >> 4;
  154550. s &= 15;
  154551. if (s) {
  154552. k += r;
  154553. CHECK_BIT_BUFFER(br_state, s, return FALSE);
  154554. r = GET_BITS(s);
  154555. s = HUFF_EXTEND(r, s);
  154556. (*block)[jpeg_natural_order[k]] = (JCOEF) (s << Al);
  154557. } else {
  154558. if (r == 15) { /* ZRL */
  154559. k += 15; /* skip 15 zeroes in band */
  154560. } else { /* EOBr, run length is 2^r + appended bits */
  154561. EOBRUN = 1 << r;
  154562. if (r) { /* EOBr, r > 0 */
  154563. CHECK_BIT_BUFFER(br_state, r, return FALSE);
  154564. r = GET_BITS(r);
  154565. EOBRUN += r;
  154566. }
  154567. EOBRUN--; /* this band is processed at this moment */
  154568. break; /* force end-of-band */
  154569. }
  154570. }
  154571. }
  154572. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154573. }
  154574. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154575. }
  154576. entropy->restarts_to_go--;
  154577. return TRUE;
  154578. }
  154579. METHODDEF(boolean)
  154580. decode_mcu_DC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154581. {
  154582. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154583. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154584. int blkn;
  154585. JBLOCKROW block;
  154586. BITREAD_STATE_VARS;
  154587. if (cinfo->restart_interval) {
  154588. if (entropy->restarts_to_go == 0)
  154589. if (! process_restartp(cinfo))
  154590. return FALSE;
  154591. }
  154592. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154593. for (blkn = 0; blkn < cinfo->blocks_in_MCU; blkn++) {
  154594. block = MCU_data[blkn];
  154595. CHECK_BIT_BUFFER(br_state, 1, return FALSE);
  154596. if (GET_BITS(1))
  154597. (*block)[0] |= p1;
  154598. }
  154599. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154600. entropy->restarts_to_go--;
  154601. return TRUE;
  154602. }
  154603. METHODDEF(boolean)
  154604. decode_mcu_AC_refine (j_decompress_ptr cinfo, JBLOCKROW *MCU_data)
  154605. {
  154606. phuff_entropy_ptr2 entropy = (phuff_entropy_ptr2) cinfo->entropy;
  154607. int Se = cinfo->Se;
  154608. int p1 = 1 << cinfo->Al; /* 1 in the bit position being coded */
  154609. int m1 = (-1) << cinfo->Al; /* -1 in the bit position being coded */
  154610. register int s, k, r;
  154611. unsigned int EOBRUN;
  154612. JBLOCKROW block;
  154613. JCOEFPTR thiscoef;
  154614. BITREAD_STATE_VARS;
  154615. d_derived_tbl * tbl;
  154616. int num_newnz;
  154617. int newnz_pos[DCTSIZE2];
  154618. if (cinfo->restart_interval) {
  154619. if (entropy->restarts_to_go == 0)
  154620. if (! process_restartp(cinfo))
  154621. return FALSE;
  154622. }
  154623. if (! entropy->pub.insufficient_data) {
  154624. BITREAD_LOAD_STATE(cinfo,entropy->bitstate);
  154625. EOBRUN = entropy->saved.EOBRUN; /* only part of saved state we need */
  154626. block = MCU_data[0];
  154627. tbl = entropy->ac_derived_tbl;
  154628. num_newnz = 0;
  154629. k = cinfo->Ss;
  154630. if (EOBRUN == 0) {
  154631. for (; k <= Se; k++) {
  154632. HUFF_DECODE(s, br_state, tbl, goto undoit, label3);
  154633. r = s >> 4;
  154634. s &= 15;
  154635. if (s) {
  154636. if (s != 1) /* size of new coef should always be 1 */
  154637. WARNMS(cinfo, JWRN_HUFF_BAD_CODE);
  154638. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154639. if (GET_BITS(1))
  154640. s = p1; /* newly nonzero coef is positive */
  154641. else
  154642. s = m1; /* newly nonzero coef is negative */
  154643. } else {
  154644. if (r != 15) {
  154645. EOBRUN = 1 << r; /* EOBr, run length is 2^r + appended bits */
  154646. if (r) {
  154647. CHECK_BIT_BUFFER(br_state, r, goto undoit);
  154648. r = GET_BITS(r);
  154649. EOBRUN += r;
  154650. }
  154651. break; /* rest of block is handled by EOB logic */
  154652. }
  154653. }
  154654. do {
  154655. thiscoef = *block + jpeg_natural_order[k];
  154656. if (*thiscoef != 0) {
  154657. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154658. if (GET_BITS(1)) {
  154659. if ((*thiscoef & p1) == 0) { /* do nothing if already set it */
  154660. if (*thiscoef >= 0)
  154661. *thiscoef += p1;
  154662. else
  154663. *thiscoef += m1;
  154664. }
  154665. }
  154666. } else {
  154667. if (--r < 0)
  154668. break; /* reached target zero coefficient */
  154669. }
  154670. k++;
  154671. } while (k <= Se);
  154672. if (s) {
  154673. int pos = jpeg_natural_order[k];
  154674. (*block)[pos] = (JCOEF) s;
  154675. newnz_pos[num_newnz++] = pos;
  154676. }
  154677. }
  154678. }
  154679. if (EOBRUN > 0) {
  154680. for (; k <= Se; k++) {
  154681. thiscoef = *block + jpeg_natural_order[k];
  154682. if (*thiscoef != 0) {
  154683. CHECK_BIT_BUFFER(br_state, 1, goto undoit);
  154684. if (GET_BITS(1)) {
  154685. if ((*thiscoef & p1) == 0) { /* do nothing if already changed it */
  154686. if (*thiscoef >= 0)
  154687. *thiscoef += p1;
  154688. else
  154689. *thiscoef += m1;
  154690. }
  154691. }
  154692. }
  154693. }
  154694. EOBRUN--;
  154695. }
  154696. BITREAD_SAVE_STATE(cinfo,entropy->bitstate);
  154697. entropy->saved.EOBRUN = EOBRUN; /* only part of saved state we need */
  154698. }
  154699. entropy->restarts_to_go--;
  154700. return TRUE;
  154701. undoit:
  154702. while (num_newnz > 0)
  154703. (*block)[newnz_pos[--num_newnz]] = 0;
  154704. return FALSE;
  154705. }
  154706. GLOBAL(void)
  154707. jinit_phuff_decoder (j_decompress_ptr cinfo)
  154708. {
  154709. phuff_entropy_ptr2 entropy;
  154710. int *coef_bit_ptr;
  154711. int ci, i;
  154712. entropy = (phuff_entropy_ptr2)
  154713. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154714. SIZEOF(phuff_entropy_decoder));
  154715. cinfo->entropy = (struct jpeg_entropy_decoder *) entropy;
  154716. entropy->pub.start_pass = start_pass_phuff_decoder;
  154717. for (i = 0; i < NUM_HUFF_TBLS; i++) {
  154718. entropy->derived_tbls[i] = NULL;
  154719. }
  154720. cinfo->coef_bits = (int (*)[DCTSIZE2])
  154721. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154722. cinfo->num_components*DCTSIZE2*SIZEOF(int));
  154723. coef_bit_ptr = & cinfo->coef_bits[0][0];
  154724. for (ci = 0; ci < cinfo->num_components; ci++)
  154725. for (i = 0; i < DCTSIZE2; i++)
  154726. *coef_bit_ptr++ = -1;
  154727. }
  154728. #endif /* D_PROGRESSIVE_SUPPORTED */
  154729. /*** End of inlined file: jdphuff.c ***/
  154730. /*** Start of inlined file: jdpostct.c ***/
  154731. #define JPEG_INTERNALS
  154732. typedef struct {
  154733. struct jpeg_d_post_controller pub; /* public fields */
  154734. jvirt_sarray_ptr whole_image; /* virtual array, or NULL if one-pass */
  154735. JSAMPARRAY buffer; /* strip buffer, or current strip of virtual */
  154736. JDIMENSION strip_height; /* buffer size in rows */
  154737. JDIMENSION starting_row; /* row # of first row in current strip */
  154738. JDIMENSION next_row; /* index of next row to fill/empty in strip */
  154739. } my_post_controller;
  154740. typedef my_post_controller * my_post_ptr;
  154741. METHODDEF(void) post_process_1pass
  154742. JPP((j_decompress_ptr cinfo,
  154743. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154744. JDIMENSION in_row_groups_avail,
  154745. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154746. JDIMENSION out_rows_avail));
  154747. #ifdef QUANT_2PASS_SUPPORTED
  154748. METHODDEF(void) post_process_prepass
  154749. JPP((j_decompress_ptr cinfo,
  154750. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154751. JDIMENSION in_row_groups_avail,
  154752. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154753. JDIMENSION out_rows_avail));
  154754. METHODDEF(void) post_process_2pass
  154755. JPP((j_decompress_ptr cinfo,
  154756. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154757. JDIMENSION in_row_groups_avail,
  154758. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154759. JDIMENSION out_rows_avail));
  154760. #endif
  154761. METHODDEF(void)
  154762. start_pass_dpost (j_decompress_ptr cinfo, J_BUF_MODE pass_mode)
  154763. {
  154764. my_post_ptr post = (my_post_ptr) cinfo->post;
  154765. switch (pass_mode) {
  154766. case JBUF_PASS_THRU:
  154767. if (cinfo->quantize_colors) {
  154768. post->pub.post_process_data = post_process_1pass;
  154769. if (post->buffer == NULL) {
  154770. post->buffer = (*cinfo->mem->access_virt_sarray)
  154771. ((j_common_ptr) cinfo, post->whole_image,
  154772. (JDIMENSION) 0, post->strip_height, TRUE);
  154773. }
  154774. } else {
  154775. post->pub.post_process_data = cinfo->upsample->upsample;
  154776. }
  154777. break;
  154778. #ifdef QUANT_2PASS_SUPPORTED
  154779. case JBUF_SAVE_AND_PASS:
  154780. if (post->whole_image == NULL)
  154781. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154782. post->pub.post_process_data = post_process_prepass;
  154783. break;
  154784. case JBUF_CRANK_DEST:
  154785. if (post->whole_image == NULL)
  154786. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154787. post->pub.post_process_data = post_process_2pass;
  154788. break;
  154789. #endif /* QUANT_2PASS_SUPPORTED */
  154790. default:
  154791. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154792. break;
  154793. }
  154794. post->starting_row = post->next_row = 0;
  154795. }
  154796. METHODDEF(void)
  154797. post_process_1pass (j_decompress_ptr cinfo,
  154798. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154799. JDIMENSION in_row_groups_avail,
  154800. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154801. JDIMENSION out_rows_avail)
  154802. {
  154803. my_post_ptr post = (my_post_ptr) cinfo->post;
  154804. JDIMENSION num_rows, max_rows;
  154805. max_rows = out_rows_avail - *out_row_ctr;
  154806. if (max_rows > post->strip_height)
  154807. max_rows = post->strip_height;
  154808. num_rows = 0;
  154809. (*cinfo->upsample->upsample) (cinfo,
  154810. input_buf, in_row_group_ctr, in_row_groups_avail,
  154811. post->buffer, &num_rows, max_rows);
  154812. (*cinfo->cquantize->color_quantize) (cinfo,
  154813. post->buffer, output_buf + *out_row_ctr, (int) num_rows);
  154814. *out_row_ctr += num_rows;
  154815. }
  154816. #ifdef QUANT_2PASS_SUPPORTED
  154817. METHODDEF(void)
  154818. post_process_prepass (j_decompress_ptr cinfo,
  154819. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154820. JDIMENSION in_row_groups_avail,
  154821. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154822. JDIMENSION out_rows_avail)
  154823. {
  154824. my_post_ptr post = (my_post_ptr) cinfo->post;
  154825. JDIMENSION old_next_row, num_rows;
  154826. if (post->next_row == 0) {
  154827. post->buffer = (*cinfo->mem->access_virt_sarray)
  154828. ((j_common_ptr) cinfo, post->whole_image,
  154829. post->starting_row, post->strip_height, TRUE);
  154830. }
  154831. old_next_row = post->next_row;
  154832. (*cinfo->upsample->upsample) (cinfo,
  154833. input_buf, in_row_group_ctr, in_row_groups_avail,
  154834. post->buffer, &post->next_row, post->strip_height);
  154835. if (post->next_row > old_next_row) {
  154836. num_rows = post->next_row - old_next_row;
  154837. (*cinfo->cquantize->color_quantize) (cinfo, post->buffer + old_next_row,
  154838. (JSAMPARRAY) NULL, (int) num_rows);
  154839. *out_row_ctr += num_rows;
  154840. }
  154841. if (post->next_row >= post->strip_height) {
  154842. post->starting_row += post->strip_height;
  154843. post->next_row = 0;
  154844. }
  154845. }
  154846. METHODDEF(void)
  154847. post_process_2pass (j_decompress_ptr cinfo,
  154848. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154849. JDIMENSION in_row_groups_avail,
  154850. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154851. JDIMENSION out_rows_avail)
  154852. {
  154853. my_post_ptr post = (my_post_ptr) cinfo->post;
  154854. JDIMENSION num_rows, max_rows;
  154855. if (post->next_row == 0) {
  154856. post->buffer = (*cinfo->mem->access_virt_sarray)
  154857. ((j_common_ptr) cinfo, post->whole_image,
  154858. post->starting_row, post->strip_height, FALSE);
  154859. }
  154860. num_rows = post->strip_height - post->next_row; /* available in strip */
  154861. max_rows = out_rows_avail - *out_row_ctr; /* available in output area */
  154862. if (num_rows > max_rows)
  154863. num_rows = max_rows;
  154864. max_rows = cinfo->output_height - post->starting_row;
  154865. if (num_rows > max_rows)
  154866. num_rows = max_rows;
  154867. (*cinfo->cquantize->color_quantize) (cinfo,
  154868. post->buffer + post->next_row, output_buf + *out_row_ctr,
  154869. (int) num_rows);
  154870. *out_row_ctr += num_rows;
  154871. post->next_row += num_rows;
  154872. if (post->next_row >= post->strip_height) {
  154873. post->starting_row += post->strip_height;
  154874. post->next_row = 0;
  154875. }
  154876. }
  154877. #endif /* QUANT_2PASS_SUPPORTED */
  154878. GLOBAL(void)
  154879. jinit_d_post_controller (j_decompress_ptr cinfo, boolean need_full_buffer)
  154880. {
  154881. my_post_ptr post;
  154882. post = (my_post_ptr)
  154883. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154884. SIZEOF(my_post_controller));
  154885. cinfo->post = (struct jpeg_d_post_controller *) post;
  154886. post->pub.start_pass = start_pass_dpost;
  154887. post->whole_image = NULL; /* flag for no virtual arrays */
  154888. post->buffer = NULL; /* flag for no strip buffer */
  154889. if (cinfo->quantize_colors) {
  154890. post->strip_height = (JDIMENSION) cinfo->max_v_samp_factor;
  154891. if (need_full_buffer) {
  154892. #ifdef QUANT_2PASS_SUPPORTED
  154893. post->whole_image = (*cinfo->mem->request_virt_sarray)
  154894. ((j_common_ptr) cinfo, JPOOL_IMAGE, FALSE,
  154895. cinfo->output_width * cinfo->out_color_components,
  154896. (JDIMENSION) jround_up((long) cinfo->output_height,
  154897. (long) post->strip_height),
  154898. post->strip_height);
  154899. #else
  154900. ERREXIT(cinfo, JERR_BAD_BUFFER_MODE);
  154901. #endif /* QUANT_2PASS_SUPPORTED */
  154902. } else {
  154903. post->buffer = (*cinfo->mem->alloc_sarray)
  154904. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  154905. cinfo->output_width * cinfo->out_color_components,
  154906. post->strip_height);
  154907. }
  154908. }
  154909. }
  154910. /*** End of inlined file: jdpostct.c ***/
  154911. #undef FIX
  154912. /*** Start of inlined file: jdsample.c ***/
  154913. #define JPEG_INTERNALS
  154914. typedef JMETHOD(void, upsample1_ptr,
  154915. (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154916. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr));
  154917. typedef struct {
  154918. struct jpeg_upsampler pub; /* public fields */
  154919. JSAMPARRAY color_buf[MAX_COMPONENTS];
  154920. upsample1_ptr methods[MAX_COMPONENTS];
  154921. int next_row_out; /* counts rows emitted from color_buf */
  154922. JDIMENSION rows_to_go; /* counts rows remaining in image */
  154923. int rowgroup_height[MAX_COMPONENTS];
  154924. UINT8 h_expand[MAX_COMPONENTS];
  154925. UINT8 v_expand[MAX_COMPONENTS];
  154926. } my_upsampler2;
  154927. typedef my_upsampler2 * my_upsample_ptr2;
  154928. METHODDEF(void)
  154929. start_pass_upsample (j_decompress_ptr cinfo)
  154930. {
  154931. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154932. upsample->next_row_out = cinfo->max_v_samp_factor;
  154933. upsample->rows_to_go = cinfo->output_height;
  154934. }
  154935. METHODDEF(void)
  154936. sep_upsample (j_decompress_ptr cinfo,
  154937. JSAMPIMAGE input_buf, JDIMENSION *in_row_group_ctr,
  154938. JDIMENSION in_row_groups_avail,
  154939. JSAMPARRAY output_buf, JDIMENSION *out_row_ctr,
  154940. JDIMENSION out_rows_avail)
  154941. {
  154942. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154943. int ci;
  154944. jpeg_component_info * compptr;
  154945. JDIMENSION num_rows;
  154946. if (upsample->next_row_out >= cinfo->max_v_samp_factor) {
  154947. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  154948. ci++, compptr++) {
  154949. (*upsample->methods[ci]) (cinfo, compptr,
  154950. input_buf[ci] + (*in_row_group_ctr * upsample->rowgroup_height[ci]),
  154951. upsample->color_buf + ci);
  154952. }
  154953. upsample->next_row_out = 0;
  154954. }
  154955. num_rows = (JDIMENSION) (cinfo->max_v_samp_factor - upsample->next_row_out);
  154956. if (num_rows > upsample->rows_to_go)
  154957. num_rows = upsample->rows_to_go;
  154958. out_rows_avail -= *out_row_ctr;
  154959. if (num_rows > out_rows_avail)
  154960. num_rows = out_rows_avail;
  154961. (*cinfo->cconvert->color_convert) (cinfo, upsample->color_buf,
  154962. (JDIMENSION) upsample->next_row_out,
  154963. output_buf + *out_row_ctr,
  154964. (int) num_rows);
  154965. *out_row_ctr += num_rows;
  154966. upsample->rows_to_go -= num_rows;
  154967. upsample->next_row_out += num_rows;
  154968. if (upsample->next_row_out >= cinfo->max_v_samp_factor)
  154969. (*in_row_group_ctr)++;
  154970. }
  154971. METHODDEF(void)
  154972. fullsize_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154973. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154974. {
  154975. *output_data_ptr = input_data;
  154976. }
  154977. METHODDEF(void)
  154978. noop_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154979. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154980. {
  154981. *output_data_ptr = NULL; /* safety check */
  154982. }
  154983. METHODDEF(void)
  154984. int_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  154985. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  154986. {
  154987. my_upsample_ptr2 upsample = (my_upsample_ptr2) cinfo->upsample;
  154988. JSAMPARRAY output_data = *output_data_ptr;
  154989. register JSAMPROW inptr, outptr;
  154990. register JSAMPLE invalue;
  154991. register int h;
  154992. JSAMPROW outend;
  154993. int h_expand, v_expand;
  154994. int inrow, outrow;
  154995. h_expand = upsample->h_expand[compptr->component_index];
  154996. v_expand = upsample->v_expand[compptr->component_index];
  154997. inrow = outrow = 0;
  154998. while (outrow < cinfo->max_v_samp_factor) {
  154999. inptr = input_data[inrow];
  155000. outptr = output_data[outrow];
  155001. outend = outptr + cinfo->output_width;
  155002. while (outptr < outend) {
  155003. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155004. for (h = h_expand; h > 0; h--) {
  155005. *outptr++ = invalue;
  155006. }
  155007. }
  155008. if (v_expand > 1) {
  155009. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  155010. v_expand-1, cinfo->output_width);
  155011. }
  155012. inrow++;
  155013. outrow += v_expand;
  155014. }
  155015. }
  155016. METHODDEF(void)
  155017. h2v1_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155018. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155019. {
  155020. JSAMPARRAY output_data = *output_data_ptr;
  155021. register JSAMPROW inptr, outptr;
  155022. register JSAMPLE invalue;
  155023. JSAMPROW outend;
  155024. int inrow;
  155025. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  155026. inptr = input_data[inrow];
  155027. outptr = output_data[inrow];
  155028. outend = outptr + cinfo->output_width;
  155029. while (outptr < outend) {
  155030. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155031. *outptr++ = invalue;
  155032. *outptr++ = invalue;
  155033. }
  155034. }
  155035. }
  155036. METHODDEF(void)
  155037. h2v2_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155038. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155039. {
  155040. JSAMPARRAY output_data = *output_data_ptr;
  155041. register JSAMPROW inptr, outptr;
  155042. register JSAMPLE invalue;
  155043. JSAMPROW outend;
  155044. int inrow, outrow;
  155045. inrow = outrow = 0;
  155046. while (outrow < cinfo->max_v_samp_factor) {
  155047. inptr = input_data[inrow];
  155048. outptr = output_data[outrow];
  155049. outend = outptr + cinfo->output_width;
  155050. while (outptr < outend) {
  155051. invalue = *inptr++; /* don't need GETJSAMPLE() here */
  155052. *outptr++ = invalue;
  155053. *outptr++ = invalue;
  155054. }
  155055. jcopy_sample_rows(output_data, outrow, output_data, outrow+1,
  155056. 1, cinfo->output_width);
  155057. inrow++;
  155058. outrow += 2;
  155059. }
  155060. }
  155061. METHODDEF(void)
  155062. h2v1_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155063. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155064. {
  155065. JSAMPARRAY output_data = *output_data_ptr;
  155066. register JSAMPROW inptr, outptr;
  155067. register int invalue;
  155068. register JDIMENSION colctr;
  155069. int inrow;
  155070. for (inrow = 0; inrow < cinfo->max_v_samp_factor; inrow++) {
  155071. inptr = input_data[inrow];
  155072. outptr = output_data[inrow];
  155073. invalue = GETJSAMPLE(*inptr++);
  155074. *outptr++ = (JSAMPLE) invalue;
  155075. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(*inptr) + 2) >> 2);
  155076. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  155077. invalue = GETJSAMPLE(*inptr++) * 3;
  155078. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(inptr[-2]) + 1) >> 2);
  155079. *outptr++ = (JSAMPLE) ((invalue + GETJSAMPLE(*inptr) + 2) >> 2);
  155080. }
  155081. invalue = GETJSAMPLE(*inptr);
  155082. *outptr++ = (JSAMPLE) ((invalue * 3 + GETJSAMPLE(inptr[-1]) + 1) >> 2);
  155083. *outptr++ = (JSAMPLE) invalue;
  155084. }
  155085. }
  155086. METHODDEF(void)
  155087. h2v2_fancy_upsample (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155088. JSAMPARRAY input_data, JSAMPARRAY * output_data_ptr)
  155089. {
  155090. JSAMPARRAY output_data = *output_data_ptr;
  155091. register JSAMPROW inptr0, inptr1, outptr;
  155092. #if BITS_IN_JSAMPLE == 8
  155093. register int thiscolsum, lastcolsum, nextcolsum;
  155094. #else
  155095. register INT32 thiscolsum, lastcolsum, nextcolsum;
  155096. #endif
  155097. register JDIMENSION colctr;
  155098. int inrow, outrow, v;
  155099. inrow = outrow = 0;
  155100. while (outrow < cinfo->max_v_samp_factor) {
  155101. for (v = 0; v < 2; v++) {
  155102. inptr0 = input_data[inrow];
  155103. if (v == 0) /* next nearest is row above */
  155104. inptr1 = input_data[inrow-1];
  155105. else /* next nearest is row below */
  155106. inptr1 = input_data[inrow+1];
  155107. outptr = output_data[outrow++];
  155108. thiscolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155109. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155110. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 8) >> 4);
  155111. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  155112. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  155113. for (colctr = compptr->downsampled_width - 2; colctr > 0; colctr--) {
  155114. nextcolsum = GETJSAMPLE(*inptr0++) * 3 + GETJSAMPLE(*inptr1++);
  155115. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  155116. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + nextcolsum + 7) >> 4);
  155117. lastcolsum = thiscolsum; thiscolsum = nextcolsum;
  155118. }
  155119. *outptr++ = (JSAMPLE) ((thiscolsum * 3 + lastcolsum + 8) >> 4);
  155120. *outptr++ = (JSAMPLE) ((thiscolsum * 4 + 7) >> 4);
  155121. }
  155122. inrow++;
  155123. }
  155124. }
  155125. GLOBAL(void)
  155126. jinit_upsampler (j_decompress_ptr cinfo)
  155127. {
  155128. my_upsample_ptr2 upsample;
  155129. int ci;
  155130. jpeg_component_info * compptr;
  155131. boolean need_buffer, do_fancy;
  155132. int h_in_group, v_in_group, h_out_group, v_out_group;
  155133. upsample = (my_upsample_ptr2)
  155134. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155135. SIZEOF(my_upsampler2));
  155136. cinfo->upsample = (struct jpeg_upsampler *) upsample;
  155137. upsample->pub.start_pass = start_pass_upsample;
  155138. upsample->pub.upsample = sep_upsample;
  155139. upsample->pub.need_context_rows = FALSE; /* until we find out differently */
  155140. if (cinfo->CCIR601_sampling) /* this isn't supported */
  155141. ERREXIT(cinfo, JERR_CCIR601_NOTIMPL);
  155142. do_fancy = cinfo->do_fancy_upsampling && cinfo->min_DCT_scaled_size > 1;
  155143. for (ci = 0, compptr = cinfo->comp_info; ci < cinfo->num_components;
  155144. ci++, compptr++) {
  155145. h_in_group = (compptr->h_samp_factor * compptr->DCT_scaled_size) /
  155146. cinfo->min_DCT_scaled_size;
  155147. v_in_group = (compptr->v_samp_factor * compptr->DCT_scaled_size) /
  155148. cinfo->min_DCT_scaled_size;
  155149. h_out_group = cinfo->max_h_samp_factor;
  155150. v_out_group = cinfo->max_v_samp_factor;
  155151. upsample->rowgroup_height[ci] = v_in_group; /* save for use later */
  155152. need_buffer = TRUE;
  155153. if (! compptr->component_needed) {
  155154. upsample->methods[ci] = noop_upsample;
  155155. need_buffer = FALSE;
  155156. } else if (h_in_group == h_out_group && v_in_group == v_out_group) {
  155157. upsample->methods[ci] = fullsize_upsample;
  155158. need_buffer = FALSE;
  155159. } else if (h_in_group * 2 == h_out_group &&
  155160. v_in_group == v_out_group) {
  155161. if (do_fancy && compptr->downsampled_width > 2)
  155162. upsample->methods[ci] = h2v1_fancy_upsample;
  155163. else
  155164. upsample->methods[ci] = h2v1_upsample;
  155165. } else if (h_in_group * 2 == h_out_group &&
  155166. v_in_group * 2 == v_out_group) {
  155167. if (do_fancy && compptr->downsampled_width > 2) {
  155168. upsample->methods[ci] = h2v2_fancy_upsample;
  155169. upsample->pub.need_context_rows = TRUE;
  155170. } else
  155171. upsample->methods[ci] = h2v2_upsample;
  155172. } else if ((h_out_group % h_in_group) == 0 &&
  155173. (v_out_group % v_in_group) == 0) {
  155174. upsample->methods[ci] = int_upsample;
  155175. upsample->h_expand[ci] = (UINT8) (h_out_group / h_in_group);
  155176. upsample->v_expand[ci] = (UINT8) (v_out_group / v_in_group);
  155177. } else
  155178. ERREXIT(cinfo, JERR_FRACT_SAMPLE_NOTIMPL);
  155179. if (need_buffer) {
  155180. upsample->color_buf[ci] = (*cinfo->mem->alloc_sarray)
  155181. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  155182. (JDIMENSION) jround_up((long) cinfo->output_width,
  155183. (long) cinfo->max_h_samp_factor),
  155184. (JDIMENSION) cinfo->max_v_samp_factor);
  155185. }
  155186. }
  155187. }
  155188. /*** End of inlined file: jdsample.c ***/
  155189. /*** Start of inlined file: jdtrans.c ***/
  155190. #define JPEG_INTERNALS
  155191. LOCAL(void) transdecode_master_selection JPP((j_decompress_ptr cinfo));
  155192. GLOBAL(jvirt_barray_ptr *)
  155193. jpeg_read_coefficients (j_decompress_ptr cinfo)
  155194. {
  155195. if (cinfo->global_state == DSTATE_READY) {
  155196. transdecode_master_selection(cinfo);
  155197. cinfo->global_state = DSTATE_RDCOEFS;
  155198. }
  155199. if (cinfo->global_state == DSTATE_RDCOEFS) {
  155200. for (;;) {
  155201. int retcode;
  155202. if (cinfo->progress != NULL)
  155203. (*cinfo->progress->progress_monitor) ((j_common_ptr) cinfo);
  155204. retcode = (*cinfo->inputctl->consume_input) (cinfo);
  155205. if (retcode == JPEG_SUSPENDED)
  155206. return NULL;
  155207. if (retcode == JPEG_REACHED_EOI)
  155208. break;
  155209. if (cinfo->progress != NULL &&
  155210. (retcode == JPEG_ROW_COMPLETED || retcode == JPEG_REACHED_SOS)) {
  155211. if (++cinfo->progress->pass_counter >= cinfo->progress->pass_limit) {
  155212. cinfo->progress->pass_limit += (long) cinfo->total_iMCU_rows;
  155213. }
  155214. }
  155215. }
  155216. cinfo->global_state = DSTATE_STOPPING;
  155217. }
  155218. if ((cinfo->global_state == DSTATE_STOPPING ||
  155219. cinfo->global_state == DSTATE_BUFIMAGE) && cinfo->buffered_image) {
  155220. return cinfo->coef->coef_arrays;
  155221. }
  155222. ERREXIT1(cinfo, JERR_BAD_STATE, cinfo->global_state);
  155223. return NULL; /* keep compiler happy */
  155224. }
  155225. LOCAL(void)
  155226. transdecode_master_selection (j_decompress_ptr cinfo)
  155227. {
  155228. cinfo->buffered_image = TRUE;
  155229. if (cinfo->arith_code) {
  155230. ERREXIT(cinfo, JERR_ARITH_NOTIMPL);
  155231. } else {
  155232. if (cinfo->progressive_mode) {
  155233. #ifdef D_PROGRESSIVE_SUPPORTED
  155234. jinit_phuff_decoder(cinfo);
  155235. #else
  155236. ERREXIT(cinfo, JERR_NOT_COMPILED);
  155237. #endif
  155238. } else
  155239. jinit_huff_decoder(cinfo);
  155240. }
  155241. jinit_d_coef_controller(cinfo, TRUE);
  155242. (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo);
  155243. (*cinfo->inputctl->start_input_pass) (cinfo);
  155244. if (cinfo->progress != NULL) {
  155245. int nscans;
  155246. if (cinfo->progressive_mode) {
  155247. nscans = 2 + 3 * cinfo->num_components;
  155248. } else if (cinfo->inputctl->has_multiple_scans) {
  155249. nscans = cinfo->num_components;
  155250. } else {
  155251. nscans = 1;
  155252. }
  155253. cinfo->progress->pass_counter = 0L;
  155254. cinfo->progress->pass_limit = (long) cinfo->total_iMCU_rows * nscans;
  155255. cinfo->progress->completed_passes = 0;
  155256. cinfo->progress->total_passes = 1;
  155257. }
  155258. }
  155259. /*** End of inlined file: jdtrans.c ***/
  155260. /*** Start of inlined file: jfdctflt.c ***/
  155261. #define JPEG_INTERNALS
  155262. #ifdef DCT_FLOAT_SUPPORTED
  155263. #if DCTSIZE != 8
  155264. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155265. #endif
  155266. GLOBAL(void)
  155267. jpeg_fdct_float (FAST_FLOAT * data)
  155268. {
  155269. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155270. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155271. FAST_FLOAT z1, z2, z3, z4, z5, z11, z13;
  155272. FAST_FLOAT *dataptr;
  155273. int ctr;
  155274. dataptr = data;
  155275. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155276. tmp0 = dataptr[0] + dataptr[7];
  155277. tmp7 = dataptr[0] - dataptr[7];
  155278. tmp1 = dataptr[1] + dataptr[6];
  155279. tmp6 = dataptr[1] - dataptr[6];
  155280. tmp2 = dataptr[2] + dataptr[5];
  155281. tmp5 = dataptr[2] - dataptr[5];
  155282. tmp3 = dataptr[3] + dataptr[4];
  155283. tmp4 = dataptr[3] - dataptr[4];
  155284. tmp10 = tmp0 + tmp3; /* phase 2 */
  155285. tmp13 = tmp0 - tmp3;
  155286. tmp11 = tmp1 + tmp2;
  155287. tmp12 = tmp1 - tmp2;
  155288. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155289. dataptr[4] = tmp10 - tmp11;
  155290. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155291. dataptr[2] = tmp13 + z1; /* phase 5 */
  155292. dataptr[6] = tmp13 - z1;
  155293. tmp10 = tmp4 + tmp5; /* phase 2 */
  155294. tmp11 = tmp5 + tmp6;
  155295. tmp12 = tmp6 + tmp7;
  155296. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155297. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155298. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155299. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155300. z11 = tmp7 + z3; /* phase 5 */
  155301. z13 = tmp7 - z3;
  155302. dataptr[5] = z13 + z2; /* phase 6 */
  155303. dataptr[3] = z13 - z2;
  155304. dataptr[1] = z11 + z4;
  155305. dataptr[7] = z11 - z4;
  155306. dataptr += DCTSIZE; /* advance pointer to next row */
  155307. }
  155308. dataptr = data;
  155309. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155310. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155311. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155312. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155313. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155314. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155315. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155316. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155317. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155318. tmp10 = tmp0 + tmp3; /* phase 2 */
  155319. tmp13 = tmp0 - tmp3;
  155320. tmp11 = tmp1 + tmp2;
  155321. tmp12 = tmp1 - tmp2;
  155322. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155323. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155324. z1 = (tmp12 + tmp13) * ((FAST_FLOAT) 0.707106781); /* c4 */
  155325. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155326. dataptr[DCTSIZE*6] = tmp13 - z1;
  155327. tmp10 = tmp4 + tmp5; /* phase 2 */
  155328. tmp11 = tmp5 + tmp6;
  155329. tmp12 = tmp6 + tmp7;
  155330. z5 = (tmp10 - tmp12) * ((FAST_FLOAT) 0.382683433); /* c6 */
  155331. z2 = ((FAST_FLOAT) 0.541196100) * tmp10 + z5; /* c2-c6 */
  155332. z4 = ((FAST_FLOAT) 1.306562965) * tmp12 + z5; /* c2+c6 */
  155333. z3 = tmp11 * ((FAST_FLOAT) 0.707106781); /* c4 */
  155334. z11 = tmp7 + z3; /* phase 5 */
  155335. z13 = tmp7 - z3;
  155336. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155337. dataptr[DCTSIZE*3] = z13 - z2;
  155338. dataptr[DCTSIZE*1] = z11 + z4;
  155339. dataptr[DCTSIZE*7] = z11 - z4;
  155340. dataptr++; /* advance pointer to next column */
  155341. }
  155342. }
  155343. #endif /* DCT_FLOAT_SUPPORTED */
  155344. /*** End of inlined file: jfdctflt.c ***/
  155345. /*** Start of inlined file: jfdctint.c ***/
  155346. #define JPEG_INTERNALS
  155347. #ifdef DCT_ISLOW_SUPPORTED
  155348. #if DCTSIZE != 8
  155349. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155350. #endif
  155351. #if BITS_IN_JSAMPLE == 8
  155352. #define CONST_BITS 13
  155353. #define PASS1_BITS 2
  155354. #else
  155355. #define CONST_BITS 13
  155356. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155357. #endif
  155358. #if CONST_BITS == 13
  155359. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155360. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155361. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155362. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155363. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155364. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155365. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155366. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155367. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155368. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155369. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155370. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155371. #else
  155372. #define FIX_0_298631336 FIX(0.298631336)
  155373. #define FIX_0_390180644 FIX(0.390180644)
  155374. #define FIX_0_541196100 FIX(0.541196100)
  155375. #define FIX_0_765366865 FIX(0.765366865)
  155376. #define FIX_0_899976223 FIX(0.899976223)
  155377. #define FIX_1_175875602 FIX(1.175875602)
  155378. #define FIX_1_501321110 FIX(1.501321110)
  155379. #define FIX_1_847759065 FIX(1.847759065)
  155380. #define FIX_1_961570560 FIX(1.961570560)
  155381. #define FIX_2_053119869 FIX(2.053119869)
  155382. #define FIX_2_562915447 FIX(2.562915447)
  155383. #define FIX_3_072711026 FIX(3.072711026)
  155384. #endif
  155385. #if BITS_IN_JSAMPLE == 8
  155386. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155387. #else
  155388. #define MULTIPLY(var,const) ((var) * (const))
  155389. #endif
  155390. GLOBAL(void)
  155391. jpeg_fdct_islow (DCTELEM * data)
  155392. {
  155393. INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155394. INT32 tmp10, tmp11, tmp12, tmp13;
  155395. INT32 z1, z2, z3, z4, z5;
  155396. DCTELEM *dataptr;
  155397. int ctr;
  155398. SHIFT_TEMPS
  155399. dataptr = data;
  155400. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155401. tmp0 = dataptr[0] + dataptr[7];
  155402. tmp7 = dataptr[0] - dataptr[7];
  155403. tmp1 = dataptr[1] + dataptr[6];
  155404. tmp6 = dataptr[1] - dataptr[6];
  155405. tmp2 = dataptr[2] + dataptr[5];
  155406. tmp5 = dataptr[2] - dataptr[5];
  155407. tmp3 = dataptr[3] + dataptr[4];
  155408. tmp4 = dataptr[3] - dataptr[4];
  155409. tmp10 = tmp0 + tmp3;
  155410. tmp13 = tmp0 - tmp3;
  155411. tmp11 = tmp1 + tmp2;
  155412. tmp12 = tmp1 - tmp2;
  155413. dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
  155414. dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
  155415. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155416. dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155417. CONST_BITS-PASS1_BITS);
  155418. dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155419. CONST_BITS-PASS1_BITS);
  155420. z1 = tmp4 + tmp7;
  155421. z2 = tmp5 + tmp6;
  155422. z3 = tmp4 + tmp6;
  155423. z4 = tmp5 + tmp7;
  155424. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155425. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155426. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155427. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155428. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155429. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155430. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155431. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155432. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155433. z3 += z5;
  155434. z4 += z5;
  155435. dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
  155436. dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
  155437. dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
  155438. dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
  155439. dataptr += DCTSIZE; /* advance pointer to next row */
  155440. }
  155441. dataptr = data;
  155442. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155443. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155444. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155445. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155446. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155447. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155448. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155449. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155450. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155451. tmp10 = tmp0 + tmp3;
  155452. tmp13 = tmp0 - tmp3;
  155453. tmp11 = tmp1 + tmp2;
  155454. tmp12 = tmp1 - tmp2;
  155455. dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
  155456. dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
  155457. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
  155458. dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
  155459. CONST_BITS+PASS1_BITS);
  155460. dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
  155461. CONST_BITS+PASS1_BITS);
  155462. z1 = tmp4 + tmp7;
  155463. z2 = tmp5 + tmp6;
  155464. z3 = tmp4 + tmp6;
  155465. z4 = tmp5 + tmp7;
  155466. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  155467. tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  155468. tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  155469. tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  155470. tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  155471. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  155472. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  155473. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  155474. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  155475. z3 += z5;
  155476. z4 += z5;
  155477. dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
  155478. CONST_BITS+PASS1_BITS);
  155479. dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
  155480. CONST_BITS+PASS1_BITS);
  155481. dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
  155482. CONST_BITS+PASS1_BITS);
  155483. dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
  155484. CONST_BITS+PASS1_BITS);
  155485. dataptr++; /* advance pointer to next column */
  155486. }
  155487. }
  155488. #endif /* DCT_ISLOW_SUPPORTED */
  155489. /*** End of inlined file: jfdctint.c ***/
  155490. #undef CONST_BITS
  155491. #undef MULTIPLY
  155492. #undef FIX_0_541196100
  155493. /*** Start of inlined file: jfdctfst.c ***/
  155494. #define JPEG_INTERNALS
  155495. #ifdef DCT_IFAST_SUPPORTED
  155496. #if DCTSIZE != 8
  155497. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155498. #endif
  155499. #define CONST_BITS 8
  155500. #if CONST_BITS == 8
  155501. #define FIX_0_382683433 ((INT32) 98) /* FIX(0.382683433) */
  155502. #define FIX_0_541196100 ((INT32) 139) /* FIX(0.541196100) */
  155503. #define FIX_0_707106781 ((INT32) 181) /* FIX(0.707106781) */
  155504. #define FIX_1_306562965 ((INT32) 334) /* FIX(1.306562965) */
  155505. #else
  155506. #define FIX_0_382683433 FIX(0.382683433)
  155507. #define FIX_0_541196100 FIX(0.541196100)
  155508. #define FIX_0_707106781 FIX(0.707106781)
  155509. #define FIX_1_306562965 FIX(1.306562965)
  155510. #endif
  155511. #ifndef USE_ACCURATE_ROUNDING
  155512. #undef DESCALE
  155513. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155514. #endif
  155515. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155516. GLOBAL(void)
  155517. jpeg_fdct_ifast (DCTELEM * data)
  155518. {
  155519. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155520. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155521. DCTELEM z1, z2, z3, z4, z5, z11, z13;
  155522. DCTELEM *dataptr;
  155523. int ctr;
  155524. SHIFT_TEMPS
  155525. dataptr = data;
  155526. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155527. tmp0 = dataptr[0] + dataptr[7];
  155528. tmp7 = dataptr[0] - dataptr[7];
  155529. tmp1 = dataptr[1] + dataptr[6];
  155530. tmp6 = dataptr[1] - dataptr[6];
  155531. tmp2 = dataptr[2] + dataptr[5];
  155532. tmp5 = dataptr[2] - dataptr[5];
  155533. tmp3 = dataptr[3] + dataptr[4];
  155534. tmp4 = dataptr[3] - dataptr[4];
  155535. tmp10 = tmp0 + tmp3; /* phase 2 */
  155536. tmp13 = tmp0 - tmp3;
  155537. tmp11 = tmp1 + tmp2;
  155538. tmp12 = tmp1 - tmp2;
  155539. dataptr[0] = tmp10 + tmp11; /* phase 3 */
  155540. dataptr[4] = tmp10 - tmp11;
  155541. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155542. dataptr[2] = tmp13 + z1; /* phase 5 */
  155543. dataptr[6] = tmp13 - z1;
  155544. tmp10 = tmp4 + tmp5; /* phase 2 */
  155545. tmp11 = tmp5 + tmp6;
  155546. tmp12 = tmp6 + tmp7;
  155547. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155548. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155549. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155550. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155551. z11 = tmp7 + z3; /* phase 5 */
  155552. z13 = tmp7 - z3;
  155553. dataptr[5] = z13 + z2; /* phase 6 */
  155554. dataptr[3] = z13 - z2;
  155555. dataptr[1] = z11 + z4;
  155556. dataptr[7] = z11 - z4;
  155557. dataptr += DCTSIZE; /* advance pointer to next row */
  155558. }
  155559. dataptr = data;
  155560. for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
  155561. tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
  155562. tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
  155563. tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
  155564. tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
  155565. tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
  155566. tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
  155567. tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
  155568. tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
  155569. tmp10 = tmp0 + tmp3; /* phase 2 */
  155570. tmp13 = tmp0 - tmp3;
  155571. tmp11 = tmp1 + tmp2;
  155572. tmp12 = tmp1 - tmp2;
  155573. dataptr[DCTSIZE*0] = tmp10 + tmp11; /* phase 3 */
  155574. dataptr[DCTSIZE*4] = tmp10 - tmp11;
  155575. z1 = MULTIPLY(tmp12 + tmp13, FIX_0_707106781); /* c4 */
  155576. dataptr[DCTSIZE*2] = tmp13 + z1; /* phase 5 */
  155577. dataptr[DCTSIZE*6] = tmp13 - z1;
  155578. tmp10 = tmp4 + tmp5; /* phase 2 */
  155579. tmp11 = tmp5 + tmp6;
  155580. tmp12 = tmp6 + tmp7;
  155581. z5 = MULTIPLY(tmp10 - tmp12, FIX_0_382683433); /* c6 */
  155582. z2 = MULTIPLY(tmp10, FIX_0_541196100) + z5; /* c2-c6 */
  155583. z4 = MULTIPLY(tmp12, FIX_1_306562965) + z5; /* c2+c6 */
  155584. z3 = MULTIPLY(tmp11, FIX_0_707106781); /* c4 */
  155585. z11 = tmp7 + z3; /* phase 5 */
  155586. z13 = tmp7 - z3;
  155587. dataptr[DCTSIZE*5] = z13 + z2; /* phase 6 */
  155588. dataptr[DCTSIZE*3] = z13 - z2;
  155589. dataptr[DCTSIZE*1] = z11 + z4;
  155590. dataptr[DCTSIZE*7] = z11 - z4;
  155591. dataptr++; /* advance pointer to next column */
  155592. }
  155593. }
  155594. #endif /* DCT_IFAST_SUPPORTED */
  155595. /*** End of inlined file: jfdctfst.c ***/
  155596. #undef FIX_0_541196100
  155597. /*** Start of inlined file: jidctflt.c ***/
  155598. #define JPEG_INTERNALS
  155599. #ifdef DCT_FLOAT_SUPPORTED
  155600. #if DCTSIZE != 8
  155601. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155602. #endif
  155603. #define DEQUANTIZE(coef,quantval) (((FAST_FLOAT) (coef)) * (quantval))
  155604. GLOBAL(void)
  155605. jpeg_idct_float (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155606. JCOEFPTR coef_block,
  155607. JSAMPARRAY output_buf, JDIMENSION output_col)
  155608. {
  155609. FAST_FLOAT tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155610. FAST_FLOAT tmp10, tmp11, tmp12, tmp13;
  155611. FAST_FLOAT z5, z10, z11, z12, z13;
  155612. JCOEFPTR inptr;
  155613. FLOAT_MULT_TYPE * quantptr;
  155614. FAST_FLOAT * wsptr;
  155615. JSAMPROW outptr;
  155616. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155617. int ctr;
  155618. FAST_FLOAT workspace[DCTSIZE2]; /* buffers data between passes */
  155619. SHIFT_TEMPS
  155620. inptr = coef_block;
  155621. quantptr = (FLOAT_MULT_TYPE *) compptr->dct_table;
  155622. wsptr = workspace;
  155623. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155624. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155625. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155626. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155627. inptr[DCTSIZE*7] == 0) {
  155628. FAST_FLOAT dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155629. wsptr[DCTSIZE*0] = dcval;
  155630. wsptr[DCTSIZE*1] = dcval;
  155631. wsptr[DCTSIZE*2] = dcval;
  155632. wsptr[DCTSIZE*3] = dcval;
  155633. wsptr[DCTSIZE*4] = dcval;
  155634. wsptr[DCTSIZE*5] = dcval;
  155635. wsptr[DCTSIZE*6] = dcval;
  155636. wsptr[DCTSIZE*7] = dcval;
  155637. inptr++; /* advance pointers to next column */
  155638. quantptr++;
  155639. wsptr++;
  155640. continue;
  155641. }
  155642. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155643. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155644. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155645. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155646. tmp10 = tmp0 + tmp2; /* phase 3 */
  155647. tmp11 = tmp0 - tmp2;
  155648. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155649. tmp12 = (tmp1 - tmp3) * ((FAST_FLOAT) 1.414213562) - tmp13; /* 2*c4 */
  155650. tmp0 = tmp10 + tmp13; /* phase 2 */
  155651. tmp3 = tmp10 - tmp13;
  155652. tmp1 = tmp11 + tmp12;
  155653. tmp2 = tmp11 - tmp12;
  155654. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155655. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155656. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155657. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155658. z13 = tmp6 + tmp5; /* phase 6 */
  155659. z10 = tmp6 - tmp5;
  155660. z11 = tmp4 + tmp7;
  155661. z12 = tmp4 - tmp7;
  155662. tmp7 = z11 + z13; /* phase 5 */
  155663. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562); /* 2*c4 */
  155664. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155665. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155666. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155667. tmp6 = tmp12 - tmp7; /* phase 2 */
  155668. tmp5 = tmp11 - tmp6;
  155669. tmp4 = tmp10 + tmp5;
  155670. wsptr[DCTSIZE*0] = tmp0 + tmp7;
  155671. wsptr[DCTSIZE*7] = tmp0 - tmp7;
  155672. wsptr[DCTSIZE*1] = tmp1 + tmp6;
  155673. wsptr[DCTSIZE*6] = tmp1 - tmp6;
  155674. wsptr[DCTSIZE*2] = tmp2 + tmp5;
  155675. wsptr[DCTSIZE*5] = tmp2 - tmp5;
  155676. wsptr[DCTSIZE*4] = tmp3 + tmp4;
  155677. wsptr[DCTSIZE*3] = tmp3 - tmp4;
  155678. inptr++; /* advance pointers to next column */
  155679. quantptr++;
  155680. wsptr++;
  155681. }
  155682. wsptr = workspace;
  155683. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155684. outptr = output_buf[ctr] + output_col;
  155685. tmp10 = wsptr[0] + wsptr[4];
  155686. tmp11 = wsptr[0] - wsptr[4];
  155687. tmp13 = wsptr[2] + wsptr[6];
  155688. tmp12 = (wsptr[2] - wsptr[6]) * ((FAST_FLOAT) 1.414213562) - tmp13;
  155689. tmp0 = tmp10 + tmp13;
  155690. tmp3 = tmp10 - tmp13;
  155691. tmp1 = tmp11 + tmp12;
  155692. tmp2 = tmp11 - tmp12;
  155693. z13 = wsptr[5] + wsptr[3];
  155694. z10 = wsptr[5] - wsptr[3];
  155695. z11 = wsptr[1] + wsptr[7];
  155696. z12 = wsptr[1] - wsptr[7];
  155697. tmp7 = z11 + z13;
  155698. tmp11 = (z11 - z13) * ((FAST_FLOAT) 1.414213562);
  155699. z5 = (z10 + z12) * ((FAST_FLOAT) 1.847759065); /* 2*c2 */
  155700. tmp10 = ((FAST_FLOAT) 1.082392200) * z12 - z5; /* 2*(c2-c6) */
  155701. tmp12 = ((FAST_FLOAT) -2.613125930) * z10 + z5; /* -2*(c2+c6) */
  155702. tmp6 = tmp12 - tmp7;
  155703. tmp5 = tmp11 - tmp6;
  155704. tmp4 = tmp10 + tmp5;
  155705. outptr[0] = range_limit[(int) DESCALE((INT32) (tmp0 + tmp7), 3)
  155706. & RANGE_MASK];
  155707. outptr[7] = range_limit[(int) DESCALE((INT32) (tmp0 - tmp7), 3)
  155708. & RANGE_MASK];
  155709. outptr[1] = range_limit[(int) DESCALE((INT32) (tmp1 + tmp6), 3)
  155710. & RANGE_MASK];
  155711. outptr[6] = range_limit[(int) DESCALE((INT32) (tmp1 - tmp6), 3)
  155712. & RANGE_MASK];
  155713. outptr[2] = range_limit[(int) DESCALE((INT32) (tmp2 + tmp5), 3)
  155714. & RANGE_MASK];
  155715. outptr[5] = range_limit[(int) DESCALE((INT32) (tmp2 - tmp5), 3)
  155716. & RANGE_MASK];
  155717. outptr[4] = range_limit[(int) DESCALE((INT32) (tmp3 + tmp4), 3)
  155718. & RANGE_MASK];
  155719. outptr[3] = range_limit[(int) DESCALE((INT32) (tmp3 - tmp4), 3)
  155720. & RANGE_MASK];
  155721. wsptr += DCTSIZE; /* advance pointer to next row */
  155722. }
  155723. }
  155724. #endif /* DCT_FLOAT_SUPPORTED */
  155725. /*** End of inlined file: jidctflt.c ***/
  155726. #undef CONST_BITS
  155727. #undef FIX_1_847759065
  155728. #undef MULTIPLY
  155729. #undef DEQUANTIZE
  155730. #undef DESCALE
  155731. /*** Start of inlined file: jidctfst.c ***/
  155732. #define JPEG_INTERNALS
  155733. #ifdef DCT_IFAST_SUPPORTED
  155734. #if DCTSIZE != 8
  155735. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155736. #endif
  155737. #if BITS_IN_JSAMPLE == 8
  155738. #define CONST_BITS 8
  155739. #define PASS1_BITS 2
  155740. #else
  155741. #define CONST_BITS 8
  155742. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155743. #endif
  155744. #if CONST_BITS == 8
  155745. #define FIX_1_082392200 ((INT32) 277) /* FIX(1.082392200) */
  155746. #define FIX_1_414213562 ((INT32) 362) /* FIX(1.414213562) */
  155747. #define FIX_1_847759065 ((INT32) 473) /* FIX(1.847759065) */
  155748. #define FIX_2_613125930 ((INT32) 669) /* FIX(2.613125930) */
  155749. #else
  155750. #define FIX_1_082392200 FIX(1.082392200)
  155751. #define FIX_1_414213562 FIX(1.414213562)
  155752. #define FIX_1_847759065 FIX(1.847759065)
  155753. #define FIX_2_613125930 FIX(2.613125930)
  155754. #endif
  155755. #ifndef USE_ACCURATE_ROUNDING
  155756. #undef DESCALE
  155757. #define DESCALE(x,n) RIGHT_SHIFT(x, n)
  155758. #endif
  155759. #define MULTIPLY(var,const) ((DCTELEM) DESCALE((var) * (const), CONST_BITS))
  155760. #if BITS_IN_JSAMPLE == 8
  155761. #define DEQUANTIZE(coef,quantval) (((IFAST_MULT_TYPE) (coef)) * (quantval))
  155762. #else
  155763. #define DEQUANTIZE(coef,quantval) \
  155764. DESCALE((coef)*(quantval), IFAST_SCALE_BITS-PASS1_BITS)
  155765. #endif
  155766. #ifdef RIGHT_SHIFT_IS_UNSIGNED
  155767. #define ISHIFT_TEMPS DCTELEM ishift_temp;
  155768. #if BITS_IN_JSAMPLE == 8
  155769. #define DCTELEMBITS 16 /* DCTELEM may be 16 or 32 bits */
  155770. #else
  155771. #define DCTELEMBITS 32 /* DCTELEM must be 32 bits */
  155772. #endif
  155773. #define IRIGHT_SHIFT(x,shft) \
  155774. ((ishift_temp = (x)) < 0 ? \
  155775. (ishift_temp >> (shft)) | ((~((DCTELEM) 0)) << (DCTELEMBITS-(shft))) : \
  155776. (ishift_temp >> (shft)))
  155777. #else
  155778. #define ISHIFT_TEMPS
  155779. #define IRIGHT_SHIFT(x,shft) ((x) >> (shft))
  155780. #endif
  155781. #ifdef USE_ACCURATE_ROUNDING
  155782. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT((x) + (1 << ((n)-1)), n))
  155783. #else
  155784. #define IDESCALE(x,n) ((int) IRIGHT_SHIFT(x, n))
  155785. #endif
  155786. GLOBAL(void)
  155787. jpeg_idct_ifast (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155788. JCOEFPTR coef_block,
  155789. JSAMPARRAY output_buf, JDIMENSION output_col)
  155790. {
  155791. DCTELEM tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  155792. DCTELEM tmp10, tmp11, tmp12, tmp13;
  155793. DCTELEM z5, z10, z11, z12, z13;
  155794. JCOEFPTR inptr;
  155795. IFAST_MULT_TYPE * quantptr;
  155796. int * wsptr;
  155797. JSAMPROW outptr;
  155798. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155799. int ctr;
  155800. int workspace[DCTSIZE2]; /* buffers data between passes */
  155801. SHIFT_TEMPS /* for DESCALE */
  155802. ISHIFT_TEMPS /* for IDESCALE */
  155803. inptr = coef_block;
  155804. quantptr = (IFAST_MULT_TYPE *) compptr->dct_table;
  155805. wsptr = workspace;
  155806. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155807. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155808. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155809. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  155810. inptr[DCTSIZE*7] == 0) {
  155811. int dcval = (int) DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155812. wsptr[DCTSIZE*0] = dcval;
  155813. wsptr[DCTSIZE*1] = dcval;
  155814. wsptr[DCTSIZE*2] = dcval;
  155815. wsptr[DCTSIZE*3] = dcval;
  155816. wsptr[DCTSIZE*4] = dcval;
  155817. wsptr[DCTSIZE*5] = dcval;
  155818. wsptr[DCTSIZE*6] = dcval;
  155819. wsptr[DCTSIZE*7] = dcval;
  155820. inptr++; /* advance pointers to next column */
  155821. quantptr++;
  155822. wsptr++;
  155823. continue;
  155824. }
  155825. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  155826. tmp1 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  155827. tmp2 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  155828. tmp3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  155829. tmp10 = tmp0 + tmp2; /* phase 3 */
  155830. tmp11 = tmp0 - tmp2;
  155831. tmp13 = tmp1 + tmp3; /* phases 5-3 */
  155832. tmp12 = MULTIPLY(tmp1 - tmp3, FIX_1_414213562) - tmp13; /* 2*c4 */
  155833. tmp0 = tmp10 + tmp13; /* phase 2 */
  155834. tmp3 = tmp10 - tmp13;
  155835. tmp1 = tmp11 + tmp12;
  155836. tmp2 = tmp11 - tmp12;
  155837. tmp4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  155838. tmp5 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  155839. tmp6 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  155840. tmp7 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  155841. z13 = tmp6 + tmp5; /* phase 6 */
  155842. z10 = tmp6 - tmp5;
  155843. z11 = tmp4 + tmp7;
  155844. z12 = tmp4 - tmp7;
  155845. tmp7 = z11 + z13; /* phase 5 */
  155846. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155847. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155848. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155849. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155850. tmp6 = tmp12 - tmp7; /* phase 2 */
  155851. tmp5 = tmp11 - tmp6;
  155852. tmp4 = tmp10 + tmp5;
  155853. wsptr[DCTSIZE*0] = (int) (tmp0 + tmp7);
  155854. wsptr[DCTSIZE*7] = (int) (tmp0 - tmp7);
  155855. wsptr[DCTSIZE*1] = (int) (tmp1 + tmp6);
  155856. wsptr[DCTSIZE*6] = (int) (tmp1 - tmp6);
  155857. wsptr[DCTSIZE*2] = (int) (tmp2 + tmp5);
  155858. wsptr[DCTSIZE*5] = (int) (tmp2 - tmp5);
  155859. wsptr[DCTSIZE*4] = (int) (tmp3 + tmp4);
  155860. wsptr[DCTSIZE*3] = (int) (tmp3 - tmp4);
  155861. inptr++; /* advance pointers to next column */
  155862. quantptr++;
  155863. wsptr++;
  155864. }
  155865. wsptr = workspace;
  155866. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  155867. outptr = output_buf[ctr] + output_col;
  155868. #ifndef NO_ZERO_ROW_TEST
  155869. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  155870. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  155871. JSAMPLE dcval = range_limit[IDESCALE(wsptr[0], PASS1_BITS+3)
  155872. & RANGE_MASK];
  155873. outptr[0] = dcval;
  155874. outptr[1] = dcval;
  155875. outptr[2] = dcval;
  155876. outptr[3] = dcval;
  155877. outptr[4] = dcval;
  155878. outptr[5] = dcval;
  155879. outptr[6] = dcval;
  155880. outptr[7] = dcval;
  155881. wsptr += DCTSIZE; /* advance pointer to next row */
  155882. continue;
  155883. }
  155884. #endif
  155885. tmp10 = ((DCTELEM) wsptr[0] + (DCTELEM) wsptr[4]);
  155886. tmp11 = ((DCTELEM) wsptr[0] - (DCTELEM) wsptr[4]);
  155887. tmp13 = ((DCTELEM) wsptr[2] + (DCTELEM) wsptr[6]);
  155888. tmp12 = MULTIPLY((DCTELEM) wsptr[2] - (DCTELEM) wsptr[6], FIX_1_414213562)
  155889. - tmp13;
  155890. tmp0 = tmp10 + tmp13;
  155891. tmp3 = tmp10 - tmp13;
  155892. tmp1 = tmp11 + tmp12;
  155893. tmp2 = tmp11 - tmp12;
  155894. z13 = (DCTELEM) wsptr[5] + (DCTELEM) wsptr[3];
  155895. z10 = (DCTELEM) wsptr[5] - (DCTELEM) wsptr[3];
  155896. z11 = (DCTELEM) wsptr[1] + (DCTELEM) wsptr[7];
  155897. z12 = (DCTELEM) wsptr[1] - (DCTELEM) wsptr[7];
  155898. tmp7 = z11 + z13; /* phase 5 */
  155899. tmp11 = MULTIPLY(z11 - z13, FIX_1_414213562); /* 2*c4 */
  155900. z5 = MULTIPLY(z10 + z12, FIX_1_847759065); /* 2*c2 */
  155901. tmp10 = MULTIPLY(z12, FIX_1_082392200) - z5; /* 2*(c2-c6) */
  155902. tmp12 = MULTIPLY(z10, - FIX_2_613125930) + z5; /* -2*(c2+c6) */
  155903. tmp6 = tmp12 - tmp7; /* phase 2 */
  155904. tmp5 = tmp11 - tmp6;
  155905. tmp4 = tmp10 + tmp5;
  155906. outptr[0] = range_limit[IDESCALE(tmp0 + tmp7, PASS1_BITS+3)
  155907. & RANGE_MASK];
  155908. outptr[7] = range_limit[IDESCALE(tmp0 - tmp7, PASS1_BITS+3)
  155909. & RANGE_MASK];
  155910. outptr[1] = range_limit[IDESCALE(tmp1 + tmp6, PASS1_BITS+3)
  155911. & RANGE_MASK];
  155912. outptr[6] = range_limit[IDESCALE(tmp1 - tmp6, PASS1_BITS+3)
  155913. & RANGE_MASK];
  155914. outptr[2] = range_limit[IDESCALE(tmp2 + tmp5, PASS1_BITS+3)
  155915. & RANGE_MASK];
  155916. outptr[5] = range_limit[IDESCALE(tmp2 - tmp5, PASS1_BITS+3)
  155917. & RANGE_MASK];
  155918. outptr[4] = range_limit[IDESCALE(tmp3 + tmp4, PASS1_BITS+3)
  155919. & RANGE_MASK];
  155920. outptr[3] = range_limit[IDESCALE(tmp3 - tmp4, PASS1_BITS+3)
  155921. & RANGE_MASK];
  155922. wsptr += DCTSIZE; /* advance pointer to next row */
  155923. }
  155924. }
  155925. #endif /* DCT_IFAST_SUPPORTED */
  155926. /*** End of inlined file: jidctfst.c ***/
  155927. #undef CONST_BITS
  155928. #undef FIX_1_847759065
  155929. #undef MULTIPLY
  155930. #undef DEQUANTIZE
  155931. /*** Start of inlined file: jidctint.c ***/
  155932. #define JPEG_INTERNALS
  155933. #ifdef DCT_ISLOW_SUPPORTED
  155934. #if DCTSIZE != 8
  155935. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  155936. #endif
  155937. #if BITS_IN_JSAMPLE == 8
  155938. #define CONST_BITS 13
  155939. #define PASS1_BITS 2
  155940. #else
  155941. #define CONST_BITS 13
  155942. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  155943. #endif
  155944. #if CONST_BITS == 13
  155945. #define FIX_0_298631336 ((INT32) 2446) /* FIX(0.298631336) */
  155946. #define FIX_0_390180644 ((INT32) 3196) /* FIX(0.390180644) */
  155947. #define FIX_0_541196100 ((INT32) 4433) /* FIX(0.541196100) */
  155948. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  155949. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  155950. #define FIX_1_175875602 ((INT32) 9633) /* FIX(1.175875602) */
  155951. #define FIX_1_501321110 ((INT32) 12299) /* FIX(1.501321110) */
  155952. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  155953. #define FIX_1_961570560 ((INT32) 16069) /* FIX(1.961570560) */
  155954. #define FIX_2_053119869 ((INT32) 16819) /* FIX(2.053119869) */
  155955. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  155956. #define FIX_3_072711026 ((INT32) 25172) /* FIX(3.072711026) */
  155957. #else
  155958. #define FIX_0_298631336 FIX(0.298631336)
  155959. #define FIX_0_390180644 FIX(0.390180644)
  155960. #define FIX_0_541196100 FIX(0.541196100)
  155961. #define FIX_0_765366865 FIX(0.765366865)
  155962. #define FIX_0_899976223 FIX(0.899976223)
  155963. #define FIX_1_175875602 FIX(1.175875602)
  155964. #define FIX_1_501321110 FIX(1.501321110)
  155965. #define FIX_1_847759065 FIX(1.847759065)
  155966. #define FIX_1_961570560 FIX(1.961570560)
  155967. #define FIX_2_053119869 FIX(2.053119869)
  155968. #define FIX_2_562915447 FIX(2.562915447)
  155969. #define FIX_3_072711026 FIX(3.072711026)
  155970. #endif
  155971. #if BITS_IN_JSAMPLE == 8
  155972. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  155973. #else
  155974. #define MULTIPLY(var,const) ((var) * (const))
  155975. #endif
  155976. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  155977. GLOBAL(void)
  155978. jpeg_idct_islow (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  155979. JCOEFPTR coef_block,
  155980. JSAMPARRAY output_buf, JDIMENSION output_col)
  155981. {
  155982. INT32 tmp0, tmp1, tmp2, tmp3;
  155983. INT32 tmp10, tmp11, tmp12, tmp13;
  155984. INT32 z1, z2, z3, z4, z5;
  155985. JCOEFPTR inptr;
  155986. ISLOW_MULT_TYPE * quantptr;
  155987. int * wsptr;
  155988. JSAMPROW outptr;
  155989. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  155990. int ctr;
  155991. int workspace[DCTSIZE2]; /* buffers data between passes */
  155992. SHIFT_TEMPS
  155993. inptr = coef_block;
  155994. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  155995. wsptr = workspace;
  155996. for (ctr = DCTSIZE; ctr > 0; ctr--) {
  155997. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  155998. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 &&
  155999. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 &&
  156000. inptr[DCTSIZE*7] == 0) {
  156001. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156002. wsptr[DCTSIZE*0] = dcval;
  156003. wsptr[DCTSIZE*1] = dcval;
  156004. wsptr[DCTSIZE*2] = dcval;
  156005. wsptr[DCTSIZE*3] = dcval;
  156006. wsptr[DCTSIZE*4] = dcval;
  156007. wsptr[DCTSIZE*5] = dcval;
  156008. wsptr[DCTSIZE*6] = dcval;
  156009. wsptr[DCTSIZE*7] = dcval;
  156010. inptr++; /* advance pointers to next column */
  156011. quantptr++;
  156012. wsptr++;
  156013. continue;
  156014. }
  156015. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156016. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156017. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  156018. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  156019. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  156020. z2 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156021. z3 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]);
  156022. tmp0 = (z2 + z3) << CONST_BITS;
  156023. tmp1 = (z2 - z3) << CONST_BITS;
  156024. tmp10 = tmp0 + tmp3;
  156025. tmp13 = tmp0 - tmp3;
  156026. tmp11 = tmp1 + tmp2;
  156027. tmp12 = tmp1 - tmp2;
  156028. tmp0 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156029. tmp1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156030. tmp2 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156031. tmp3 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156032. z1 = tmp0 + tmp3;
  156033. z2 = tmp1 + tmp2;
  156034. z3 = tmp0 + tmp2;
  156035. z4 = tmp1 + tmp3;
  156036. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  156037. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  156038. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  156039. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  156040. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  156041. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  156042. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  156043. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  156044. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  156045. z3 += z5;
  156046. z4 += z5;
  156047. tmp0 += z1 + z3;
  156048. tmp1 += z2 + z4;
  156049. tmp2 += z2 + z3;
  156050. tmp3 += z1 + z4;
  156051. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp3, CONST_BITS-PASS1_BITS);
  156052. wsptr[DCTSIZE*7] = (int) DESCALE(tmp10 - tmp3, CONST_BITS-PASS1_BITS);
  156053. wsptr[DCTSIZE*1] = (int) DESCALE(tmp11 + tmp2, CONST_BITS-PASS1_BITS);
  156054. wsptr[DCTSIZE*6] = (int) DESCALE(tmp11 - tmp2, CONST_BITS-PASS1_BITS);
  156055. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 + tmp1, CONST_BITS-PASS1_BITS);
  156056. wsptr[DCTSIZE*5] = (int) DESCALE(tmp12 - tmp1, CONST_BITS-PASS1_BITS);
  156057. wsptr[DCTSIZE*3] = (int) DESCALE(tmp13 + tmp0, CONST_BITS-PASS1_BITS);
  156058. wsptr[DCTSIZE*4] = (int) DESCALE(tmp13 - tmp0, CONST_BITS-PASS1_BITS);
  156059. inptr++; /* advance pointers to next column */
  156060. quantptr++;
  156061. wsptr++;
  156062. }
  156063. wsptr = workspace;
  156064. for (ctr = 0; ctr < DCTSIZE; ctr++) {
  156065. outptr = output_buf[ctr] + output_col;
  156066. #ifndef NO_ZERO_ROW_TEST
  156067. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 &&
  156068. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  156069. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156070. & RANGE_MASK];
  156071. outptr[0] = dcval;
  156072. outptr[1] = dcval;
  156073. outptr[2] = dcval;
  156074. outptr[3] = dcval;
  156075. outptr[4] = dcval;
  156076. outptr[5] = dcval;
  156077. outptr[6] = dcval;
  156078. outptr[7] = dcval;
  156079. wsptr += DCTSIZE; /* advance pointer to next row */
  156080. continue;
  156081. }
  156082. #endif
  156083. z2 = (INT32) wsptr[2];
  156084. z3 = (INT32) wsptr[6];
  156085. z1 = MULTIPLY(z2 + z3, FIX_0_541196100);
  156086. tmp2 = z1 + MULTIPLY(z3, - FIX_1_847759065);
  156087. tmp3 = z1 + MULTIPLY(z2, FIX_0_765366865);
  156088. tmp0 = ((INT32) wsptr[0] + (INT32) wsptr[4]) << CONST_BITS;
  156089. tmp1 = ((INT32) wsptr[0] - (INT32) wsptr[4]) << CONST_BITS;
  156090. tmp10 = tmp0 + tmp3;
  156091. tmp13 = tmp0 - tmp3;
  156092. tmp11 = tmp1 + tmp2;
  156093. tmp12 = tmp1 - tmp2;
  156094. tmp0 = (INT32) wsptr[7];
  156095. tmp1 = (INT32) wsptr[5];
  156096. tmp2 = (INT32) wsptr[3];
  156097. tmp3 = (INT32) wsptr[1];
  156098. z1 = tmp0 + tmp3;
  156099. z2 = tmp1 + tmp2;
  156100. z3 = tmp0 + tmp2;
  156101. z4 = tmp1 + tmp3;
  156102. z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
  156103. tmp0 = MULTIPLY(tmp0, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
  156104. tmp1 = MULTIPLY(tmp1, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
  156105. tmp2 = MULTIPLY(tmp2, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
  156106. tmp3 = MULTIPLY(tmp3, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
  156107. z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
  156108. z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
  156109. z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
  156110. z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
  156111. z3 += z5;
  156112. z4 += z5;
  156113. tmp0 += z1 + z3;
  156114. tmp1 += z2 + z4;
  156115. tmp2 += z2 + z3;
  156116. tmp3 += z1 + z4;
  156117. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp3,
  156118. CONST_BITS+PASS1_BITS+3)
  156119. & RANGE_MASK];
  156120. outptr[7] = range_limit[(int) DESCALE(tmp10 - tmp3,
  156121. CONST_BITS+PASS1_BITS+3)
  156122. & RANGE_MASK];
  156123. outptr[1] = range_limit[(int) DESCALE(tmp11 + tmp2,
  156124. CONST_BITS+PASS1_BITS+3)
  156125. & RANGE_MASK];
  156126. outptr[6] = range_limit[(int) DESCALE(tmp11 - tmp2,
  156127. CONST_BITS+PASS1_BITS+3)
  156128. & RANGE_MASK];
  156129. outptr[2] = range_limit[(int) DESCALE(tmp12 + tmp1,
  156130. CONST_BITS+PASS1_BITS+3)
  156131. & RANGE_MASK];
  156132. outptr[5] = range_limit[(int) DESCALE(tmp12 - tmp1,
  156133. CONST_BITS+PASS1_BITS+3)
  156134. & RANGE_MASK];
  156135. outptr[3] = range_limit[(int) DESCALE(tmp13 + tmp0,
  156136. CONST_BITS+PASS1_BITS+3)
  156137. & RANGE_MASK];
  156138. outptr[4] = range_limit[(int) DESCALE(tmp13 - tmp0,
  156139. CONST_BITS+PASS1_BITS+3)
  156140. & RANGE_MASK];
  156141. wsptr += DCTSIZE; /* advance pointer to next row */
  156142. }
  156143. }
  156144. #endif /* DCT_ISLOW_SUPPORTED */
  156145. /*** End of inlined file: jidctint.c ***/
  156146. /*** Start of inlined file: jidctred.c ***/
  156147. #define JPEG_INTERNALS
  156148. #ifdef IDCT_SCALING_SUPPORTED
  156149. #if DCTSIZE != 8
  156150. Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */
  156151. #endif
  156152. #if BITS_IN_JSAMPLE == 8
  156153. #define CONST_BITS 13
  156154. #define PASS1_BITS 2
  156155. #else
  156156. #define CONST_BITS 13
  156157. #define PASS1_BITS 1 /* lose a little precision to avoid overflow */
  156158. #endif
  156159. #if CONST_BITS == 13
  156160. #define FIX_0_211164243 ((INT32) 1730) /* FIX(0.211164243) */
  156161. #define FIX_0_509795579 ((INT32) 4176) /* FIX(0.509795579) */
  156162. #define FIX_0_601344887 ((INT32) 4926) /* FIX(0.601344887) */
  156163. #define FIX_0_720959822 ((INT32) 5906) /* FIX(0.720959822) */
  156164. #define FIX_0_765366865 ((INT32) 6270) /* FIX(0.765366865) */
  156165. #define FIX_0_850430095 ((INT32) 6967) /* FIX(0.850430095) */
  156166. #define FIX_0_899976223 ((INT32) 7373) /* FIX(0.899976223) */
  156167. #define FIX_1_061594337 ((INT32) 8697) /* FIX(1.061594337) */
  156168. #define FIX_1_272758580 ((INT32) 10426) /* FIX(1.272758580) */
  156169. #define FIX_1_451774981 ((INT32) 11893) /* FIX(1.451774981) */
  156170. #define FIX_1_847759065 ((INT32) 15137) /* FIX(1.847759065) */
  156171. #define FIX_2_172734803 ((INT32) 17799) /* FIX(2.172734803) */
  156172. #define FIX_2_562915447 ((INT32) 20995) /* FIX(2.562915447) */
  156173. #define FIX_3_624509785 ((INT32) 29692) /* FIX(3.624509785) */
  156174. #else
  156175. #define FIX_0_211164243 FIX(0.211164243)
  156176. #define FIX_0_509795579 FIX(0.509795579)
  156177. #define FIX_0_601344887 FIX(0.601344887)
  156178. #define FIX_0_720959822 FIX(0.720959822)
  156179. #define FIX_0_765366865 FIX(0.765366865)
  156180. #define FIX_0_850430095 FIX(0.850430095)
  156181. #define FIX_0_899976223 FIX(0.899976223)
  156182. #define FIX_1_061594337 FIX(1.061594337)
  156183. #define FIX_1_272758580 FIX(1.272758580)
  156184. #define FIX_1_451774981 FIX(1.451774981)
  156185. #define FIX_1_847759065 FIX(1.847759065)
  156186. #define FIX_2_172734803 FIX(2.172734803)
  156187. #define FIX_2_562915447 FIX(2.562915447)
  156188. #define FIX_3_624509785 FIX(3.624509785)
  156189. #endif
  156190. #if BITS_IN_JSAMPLE == 8
  156191. #define MULTIPLY(var,const) MULTIPLY16C16(var,const)
  156192. #else
  156193. #define MULTIPLY(var,const) ((var) * (const))
  156194. #endif
  156195. #define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))
  156196. GLOBAL(void)
  156197. jpeg_idct_4x4 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156198. JCOEFPTR coef_block,
  156199. JSAMPARRAY output_buf, JDIMENSION output_col)
  156200. {
  156201. INT32 tmp0, tmp2, tmp10, tmp12;
  156202. INT32 z1, z2, z3, z4;
  156203. JCOEFPTR inptr;
  156204. ISLOW_MULT_TYPE * quantptr;
  156205. int * wsptr;
  156206. JSAMPROW outptr;
  156207. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156208. int ctr;
  156209. int workspace[DCTSIZE*4]; /* buffers data between passes */
  156210. SHIFT_TEMPS
  156211. inptr = coef_block;
  156212. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156213. wsptr = workspace;
  156214. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156215. if (ctr == DCTSIZE-4)
  156216. continue;
  156217. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 &&
  156218. inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*5] == 0 &&
  156219. inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) {
  156220. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156221. wsptr[DCTSIZE*0] = dcval;
  156222. wsptr[DCTSIZE*1] = dcval;
  156223. wsptr[DCTSIZE*2] = dcval;
  156224. wsptr[DCTSIZE*3] = dcval;
  156225. continue;
  156226. }
  156227. tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156228. tmp0 <<= (CONST_BITS+1);
  156229. z2 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]);
  156230. z3 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]);
  156231. tmp2 = MULTIPLY(z2, FIX_1_847759065) + MULTIPLY(z3, - FIX_0_765366865);
  156232. tmp10 = tmp0 + tmp2;
  156233. tmp12 = tmp0 - tmp2;
  156234. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156235. z2 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156236. z3 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156237. z4 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156238. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156239. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156240. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156241. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156242. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156243. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156244. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156245. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156246. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp2, CONST_BITS-PASS1_BITS+1);
  156247. wsptr[DCTSIZE*3] = (int) DESCALE(tmp10 - tmp2, CONST_BITS-PASS1_BITS+1);
  156248. wsptr[DCTSIZE*1] = (int) DESCALE(tmp12 + tmp0, CONST_BITS-PASS1_BITS+1);
  156249. wsptr[DCTSIZE*2] = (int) DESCALE(tmp12 - tmp0, CONST_BITS-PASS1_BITS+1);
  156250. }
  156251. wsptr = workspace;
  156252. for (ctr = 0; ctr < 4; ctr++) {
  156253. outptr = output_buf[ctr] + output_col;
  156254. #ifndef NO_ZERO_ROW_TEST
  156255. if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 &&
  156256. wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) {
  156257. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156258. & RANGE_MASK];
  156259. outptr[0] = dcval;
  156260. outptr[1] = dcval;
  156261. outptr[2] = dcval;
  156262. outptr[3] = dcval;
  156263. wsptr += DCTSIZE; /* advance pointer to next row */
  156264. continue;
  156265. }
  156266. #endif
  156267. tmp0 = ((INT32) wsptr[0]) << (CONST_BITS+1);
  156268. tmp2 = MULTIPLY((INT32) wsptr[2], FIX_1_847759065)
  156269. + MULTIPLY((INT32) wsptr[6], - FIX_0_765366865);
  156270. tmp10 = tmp0 + tmp2;
  156271. tmp12 = tmp0 - tmp2;
  156272. z1 = (INT32) wsptr[7];
  156273. z2 = (INT32) wsptr[5];
  156274. z3 = (INT32) wsptr[3];
  156275. z4 = (INT32) wsptr[1];
  156276. tmp0 = MULTIPLY(z1, - FIX_0_211164243) /* sqrt(2) * (c3-c1) */
  156277. + MULTIPLY(z2, FIX_1_451774981) /* sqrt(2) * (c3+c7) */
  156278. + MULTIPLY(z3, - FIX_2_172734803) /* sqrt(2) * (-c1-c5) */
  156279. + MULTIPLY(z4, FIX_1_061594337); /* sqrt(2) * (c5+c7) */
  156280. tmp2 = MULTIPLY(z1, - FIX_0_509795579) /* sqrt(2) * (c7-c5) */
  156281. + MULTIPLY(z2, - FIX_0_601344887) /* sqrt(2) * (c5-c1) */
  156282. + MULTIPLY(z3, FIX_0_899976223) /* sqrt(2) * (c3-c7) */
  156283. + MULTIPLY(z4, FIX_2_562915447); /* sqrt(2) * (c1+c3) */
  156284. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp2,
  156285. CONST_BITS+PASS1_BITS+3+1)
  156286. & RANGE_MASK];
  156287. outptr[3] = range_limit[(int) DESCALE(tmp10 - tmp2,
  156288. CONST_BITS+PASS1_BITS+3+1)
  156289. & RANGE_MASK];
  156290. outptr[1] = range_limit[(int) DESCALE(tmp12 + tmp0,
  156291. CONST_BITS+PASS1_BITS+3+1)
  156292. & RANGE_MASK];
  156293. outptr[2] = range_limit[(int) DESCALE(tmp12 - tmp0,
  156294. CONST_BITS+PASS1_BITS+3+1)
  156295. & RANGE_MASK];
  156296. wsptr += DCTSIZE; /* advance pointer to next row */
  156297. }
  156298. }
  156299. GLOBAL(void)
  156300. jpeg_idct_2x2 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156301. JCOEFPTR coef_block,
  156302. JSAMPARRAY output_buf, JDIMENSION output_col)
  156303. {
  156304. INT32 tmp0, tmp10, z1;
  156305. JCOEFPTR inptr;
  156306. ISLOW_MULT_TYPE * quantptr;
  156307. int * wsptr;
  156308. JSAMPROW outptr;
  156309. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156310. int ctr;
  156311. int workspace[DCTSIZE*2]; /* buffers data between passes */
  156312. SHIFT_TEMPS
  156313. inptr = coef_block;
  156314. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156315. wsptr = workspace;
  156316. for (ctr = DCTSIZE; ctr > 0; inptr++, quantptr++, wsptr++, ctr--) {
  156317. if (ctr == DCTSIZE-2 || ctr == DCTSIZE-4 || ctr == DCTSIZE-6)
  156318. continue;
  156319. if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*3] == 0 &&
  156320. inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*7] == 0) {
  156321. int dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) << PASS1_BITS;
  156322. wsptr[DCTSIZE*0] = dcval;
  156323. wsptr[DCTSIZE*1] = dcval;
  156324. continue;
  156325. }
  156326. z1 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]);
  156327. tmp10 = z1 << (CONST_BITS+2);
  156328. z1 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]);
  156329. tmp0 = MULTIPLY(z1, - FIX_0_720959822); /* sqrt(2) * (c7-c5+c3-c1) */
  156330. z1 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]);
  156331. tmp0 += MULTIPLY(z1, FIX_0_850430095); /* sqrt(2) * (-c1+c3+c5+c7) */
  156332. z1 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]);
  156333. tmp0 += MULTIPLY(z1, - FIX_1_272758580); /* sqrt(2) * (-c1+c3-c5-c7) */
  156334. z1 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]);
  156335. tmp0 += MULTIPLY(z1, FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156336. wsptr[DCTSIZE*0] = (int) DESCALE(tmp10 + tmp0, CONST_BITS-PASS1_BITS+2);
  156337. wsptr[DCTSIZE*1] = (int) DESCALE(tmp10 - tmp0, CONST_BITS-PASS1_BITS+2);
  156338. }
  156339. wsptr = workspace;
  156340. for (ctr = 0; ctr < 2; ctr++) {
  156341. outptr = output_buf[ctr] + output_col;
  156342. #ifndef NO_ZERO_ROW_TEST
  156343. if (wsptr[1] == 0 && wsptr[3] == 0 && wsptr[5] == 0 && wsptr[7] == 0) {
  156344. JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], PASS1_BITS+3)
  156345. & RANGE_MASK];
  156346. outptr[0] = dcval;
  156347. outptr[1] = dcval;
  156348. wsptr += DCTSIZE; /* advance pointer to next row */
  156349. continue;
  156350. }
  156351. #endif
  156352. tmp10 = ((INT32) wsptr[0]) << (CONST_BITS+2);
  156353. tmp0 = MULTIPLY((INT32) wsptr[7], - FIX_0_720959822) /* sqrt(2) * (c7-c5+c3-c1) */
  156354. + MULTIPLY((INT32) wsptr[5], FIX_0_850430095) /* sqrt(2) * (-c1+c3+c5+c7) */
  156355. + MULTIPLY((INT32) wsptr[3], - FIX_1_272758580) /* sqrt(2) * (-c1+c3-c5-c7) */
  156356. + MULTIPLY((INT32) wsptr[1], FIX_3_624509785); /* sqrt(2) * (c1+c3+c5+c7) */
  156357. outptr[0] = range_limit[(int) DESCALE(tmp10 + tmp0,
  156358. CONST_BITS+PASS1_BITS+3+2)
  156359. & RANGE_MASK];
  156360. outptr[1] = range_limit[(int) DESCALE(tmp10 - tmp0,
  156361. CONST_BITS+PASS1_BITS+3+2)
  156362. & RANGE_MASK];
  156363. wsptr += DCTSIZE; /* advance pointer to next row */
  156364. }
  156365. }
  156366. GLOBAL(void)
  156367. jpeg_idct_1x1 (j_decompress_ptr cinfo, jpeg_component_info * compptr,
  156368. JCOEFPTR coef_block,
  156369. JSAMPARRAY output_buf, JDIMENSION output_col)
  156370. {
  156371. int dcval;
  156372. ISLOW_MULT_TYPE * quantptr;
  156373. JSAMPLE *range_limit = IDCT_range_limit(cinfo);
  156374. SHIFT_TEMPS
  156375. quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table;
  156376. dcval = DEQUANTIZE(coef_block[0], quantptr[0]);
  156377. dcval = (int) DESCALE((INT32) dcval, 3);
  156378. output_buf[0][output_col] = range_limit[dcval & RANGE_MASK];
  156379. }
  156380. #endif /* IDCT_SCALING_SUPPORTED */
  156381. /*** End of inlined file: jidctred.c ***/
  156382. /*** Start of inlined file: jmemmgr.c ***/
  156383. #define JPEG_INTERNALS
  156384. #define AM_MEMORY_MANAGER /* we define jvirt_Xarray_control structs */
  156385. /*** Start of inlined file: jmemsys.h ***/
  156386. #ifndef __jmemsys_h__
  156387. #define __jmemsys_h__
  156388. #ifdef NEED_SHORT_EXTERNAL_NAMES
  156389. #define jpeg_get_small jGetSmall
  156390. #define jpeg_free_small jFreeSmall
  156391. #define jpeg_get_large jGetLarge
  156392. #define jpeg_free_large jFreeLarge
  156393. #define jpeg_mem_available jMemAvail
  156394. #define jpeg_open_backing_store jOpenBackStore
  156395. #define jpeg_mem_init jMemInit
  156396. #define jpeg_mem_term jMemTerm
  156397. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  156398. EXTERN(void *) jpeg_get_small JPP((j_common_ptr cinfo, size_t sizeofobject));
  156399. EXTERN(void) jpeg_free_small JPP((j_common_ptr cinfo, void * object,
  156400. size_t sizeofobject));
  156401. EXTERN(void FAR *) jpeg_get_large JPP((j_common_ptr cinfo,
  156402. size_t sizeofobject));
  156403. EXTERN(void) jpeg_free_large JPP((j_common_ptr cinfo, void FAR * object,
  156404. size_t sizeofobject));
  156405. #ifndef MAX_ALLOC_CHUNK /* may be overridden in jconfig.h */
  156406. #define MAX_ALLOC_CHUNK 1000000000L
  156407. #endif
  156408. EXTERN(long) jpeg_mem_available JPP((j_common_ptr cinfo,
  156409. long min_bytes_needed,
  156410. long max_bytes_needed,
  156411. long already_allocated));
  156412. #define TEMP_NAME_LENGTH 64 /* max length of a temporary file's name */
  156413. #ifdef USE_MSDOS_MEMMGR /* DOS-specific junk */
  156414. typedef unsigned short XMSH; /* type of extended-memory handles */
  156415. typedef unsigned short EMSH; /* type of expanded-memory handles */
  156416. typedef union {
  156417. short file_handle; /* DOS file handle if it's a temp file */
  156418. XMSH xms_handle; /* handle if it's a chunk of XMS */
  156419. EMSH ems_handle; /* handle if it's a chunk of EMS */
  156420. } handle_union;
  156421. #endif /* USE_MSDOS_MEMMGR */
  156422. #ifdef USE_MAC_MEMMGR /* Mac-specific junk */
  156423. #include <Files.h>
  156424. #endif /* USE_MAC_MEMMGR */
  156425. //typedef struct backing_store_struct * backing_store_ptr;
  156426. typedef struct backing_store_struct {
  156427. JMETHOD(void, read_backing_store, (j_common_ptr cinfo,
  156428. struct backing_store_struct *info,
  156429. void FAR * buffer_address,
  156430. long file_offset, long byte_count));
  156431. JMETHOD(void, write_backing_store, (j_common_ptr cinfo,
  156432. struct backing_store_struct *info,
  156433. void FAR * buffer_address,
  156434. long file_offset, long byte_count));
  156435. JMETHOD(void, close_backing_store, (j_common_ptr cinfo,
  156436. struct backing_store_struct *info));
  156437. #ifdef USE_MSDOS_MEMMGR
  156438. handle_union handle; /* reference to backing-store storage object */
  156439. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156440. #else
  156441. #ifdef USE_MAC_MEMMGR
  156442. short temp_file; /* file reference number to temp file */
  156443. FSSpec tempSpec; /* the FSSpec for the temp file */
  156444. char temp_name[TEMP_NAME_LENGTH]; /* name if it's a file */
  156445. #else
  156446. FILE * temp_file; /* stdio reference to temp file */
  156447. char temp_name[TEMP_NAME_LENGTH]; /* name of temp file */
  156448. #endif
  156449. #endif
  156450. } backing_store_info;
  156451. EXTERN(void) jpeg_open_backing_store JPP((j_common_ptr cinfo,
  156452. struct backing_store_struct *info,
  156453. long total_bytes_needed));
  156454. EXTERN(long) jpeg_mem_init JPP((j_common_ptr cinfo));
  156455. EXTERN(void) jpeg_mem_term JPP((j_common_ptr cinfo));
  156456. #endif
  156457. /*** End of inlined file: jmemsys.h ***/
  156458. /* import the system-dependent declarations */
  156459. #ifndef NO_GETENV
  156460. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare getenv() */
  156461. extern char * getenv JPP((const char * name));
  156462. #endif
  156463. #endif
  156464. #ifndef ALIGN_TYPE /* so can override from jconfig.h */
  156465. #define ALIGN_TYPE double
  156466. #endif
  156467. typedef union small_pool_struct * small_pool_ptr;
  156468. typedef union small_pool_struct {
  156469. struct {
  156470. small_pool_ptr next; /* next in list of pools */
  156471. size_t bytes_used; /* how many bytes already used within pool */
  156472. size_t bytes_left; /* bytes still available in this pool */
  156473. } hdr;
  156474. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156475. } small_pool_hdr;
  156476. typedef union large_pool_struct FAR * large_pool_ptr;
  156477. typedef union large_pool_struct {
  156478. struct {
  156479. large_pool_ptr next; /* next in list of pools */
  156480. size_t bytes_used; /* how many bytes already used within pool */
  156481. size_t bytes_left; /* bytes still available in this pool */
  156482. } hdr;
  156483. ALIGN_TYPE dummy; /* included in union to ensure alignment */
  156484. } large_pool_hdr;
  156485. typedef struct {
  156486. struct jpeg_memory_mgr pub; /* public fields */
  156487. small_pool_ptr small_list[JPOOL_NUMPOOLS];
  156488. large_pool_ptr large_list[JPOOL_NUMPOOLS];
  156489. jvirt_sarray_ptr virt_sarray_list;
  156490. jvirt_barray_ptr virt_barray_list;
  156491. long total_space_allocated;
  156492. JDIMENSION last_rowsperchunk; /* from most recent alloc_sarray/barray */
  156493. } my_memory_mgr;
  156494. typedef my_memory_mgr * my_mem_ptr;
  156495. struct jvirt_sarray_control {
  156496. JSAMPARRAY mem_buffer; /* => the in-memory buffer */
  156497. JDIMENSION rows_in_array; /* total virtual array height */
  156498. JDIMENSION samplesperrow; /* width of array (and of memory buffer) */
  156499. JDIMENSION maxaccess; /* max rows accessed by access_virt_sarray */
  156500. JDIMENSION rows_in_mem; /* height of memory buffer */
  156501. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156502. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156503. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156504. boolean pre_zero; /* pre-zero mode requested? */
  156505. boolean dirty; /* do current buffer contents need written? */
  156506. boolean b_s_open; /* is backing-store data valid? */
  156507. jvirt_sarray_ptr next; /* link to next virtual sarray control block */
  156508. backing_store_info b_s_info; /* System-dependent control info */
  156509. };
  156510. struct jvirt_barray_control {
  156511. JBLOCKARRAY mem_buffer; /* => the in-memory buffer */
  156512. JDIMENSION rows_in_array; /* total virtual array height */
  156513. JDIMENSION blocksperrow; /* width of array (and of memory buffer) */
  156514. JDIMENSION maxaccess; /* max rows accessed by access_virt_barray */
  156515. JDIMENSION rows_in_mem; /* height of memory buffer */
  156516. JDIMENSION rowsperchunk; /* allocation chunk size in mem_buffer */
  156517. JDIMENSION cur_start_row; /* first logical row # in the buffer */
  156518. JDIMENSION first_undef_row; /* row # of first uninitialized row */
  156519. boolean pre_zero; /* pre-zero mode requested? */
  156520. boolean dirty; /* do current buffer contents need written? */
  156521. boolean b_s_open; /* is backing-store data valid? */
  156522. jvirt_barray_ptr next; /* link to next virtual barray control block */
  156523. backing_store_info b_s_info; /* System-dependent control info */
  156524. };
  156525. #ifdef MEM_STATS /* optional extra stuff for statistics */
  156526. LOCAL(void)
  156527. print_mem_stats (j_common_ptr cinfo, int pool_id)
  156528. {
  156529. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156530. small_pool_ptr shdr_ptr;
  156531. large_pool_ptr lhdr_ptr;
  156532. fprintf(stderr, "Freeing pool %d, total space = %ld\n",
  156533. pool_id, mem->total_space_allocated);
  156534. for (lhdr_ptr = mem->large_list[pool_id]; lhdr_ptr != NULL;
  156535. lhdr_ptr = lhdr_ptr->hdr.next) {
  156536. fprintf(stderr, " Large chunk used %ld\n",
  156537. (long) lhdr_ptr->hdr.bytes_used);
  156538. }
  156539. for (shdr_ptr = mem->small_list[pool_id]; shdr_ptr != NULL;
  156540. shdr_ptr = shdr_ptr->hdr.next) {
  156541. fprintf(stderr, " Small chunk used %ld free %ld\n",
  156542. (long) shdr_ptr->hdr.bytes_used,
  156543. (long) shdr_ptr->hdr.bytes_left);
  156544. }
  156545. }
  156546. #endif /* MEM_STATS */
  156547. LOCAL(void)
  156548. out_of_memory (j_common_ptr cinfo, int which)
  156549. {
  156550. #ifdef MEM_STATS
  156551. cinfo->err->trace_level = 2; /* force self_destruct to report stats */
  156552. #endif
  156553. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, which);
  156554. }
  156555. static const size_t first_pool_slop[JPOOL_NUMPOOLS] =
  156556. {
  156557. 1600, /* first PERMANENT pool */
  156558. 16000 /* first IMAGE pool */
  156559. };
  156560. static const size_t extra_pool_slop[JPOOL_NUMPOOLS] =
  156561. {
  156562. 0, /* additional PERMANENT pools */
  156563. 5000 /* additional IMAGE pools */
  156564. };
  156565. #define MIN_SLOP 50 /* greater than 0 to avoid futile looping */
  156566. METHODDEF(void *)
  156567. alloc_small (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156568. {
  156569. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156570. small_pool_ptr hdr_ptr, prev_hdr_ptr;
  156571. char * data_ptr;
  156572. size_t odd_bytes, min_request, slop;
  156573. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(small_pool_hdr)))
  156574. out_of_memory(cinfo, 1); /* request exceeds malloc's ability */
  156575. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156576. if (odd_bytes > 0)
  156577. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156578. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156579. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156580. prev_hdr_ptr = NULL;
  156581. hdr_ptr = mem->small_list[pool_id];
  156582. while (hdr_ptr != NULL) {
  156583. if (hdr_ptr->hdr.bytes_left >= sizeofobject)
  156584. break; /* found pool with enough space */
  156585. prev_hdr_ptr = hdr_ptr;
  156586. hdr_ptr = hdr_ptr->hdr.next;
  156587. }
  156588. if (hdr_ptr == NULL) {
  156589. min_request = sizeofobject + SIZEOF(small_pool_hdr);
  156590. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156591. slop = first_pool_slop[pool_id];
  156592. else
  156593. slop = extra_pool_slop[pool_id];
  156594. if (slop > (size_t) (MAX_ALLOC_CHUNK-min_request))
  156595. slop = (size_t) (MAX_ALLOC_CHUNK-min_request);
  156596. for (;;) {
  156597. hdr_ptr = (small_pool_ptr) jpeg_get_small(cinfo, min_request + slop);
  156598. if (hdr_ptr != NULL)
  156599. break;
  156600. slop /= 2;
  156601. if (slop < MIN_SLOP) /* give up when it gets real small */
  156602. out_of_memory(cinfo, 2); /* jpeg_get_small failed */
  156603. }
  156604. mem->total_space_allocated += min_request + slop;
  156605. hdr_ptr->hdr.next = NULL;
  156606. hdr_ptr->hdr.bytes_used = 0;
  156607. hdr_ptr->hdr.bytes_left = sizeofobject + slop;
  156608. if (prev_hdr_ptr == NULL) /* first pool in class? */
  156609. mem->small_list[pool_id] = hdr_ptr;
  156610. else
  156611. prev_hdr_ptr->hdr.next = hdr_ptr;
  156612. }
  156613. data_ptr = (char *) (hdr_ptr + 1); /* point to first data byte in pool */
  156614. data_ptr += hdr_ptr->hdr.bytes_used; /* point to place for object */
  156615. hdr_ptr->hdr.bytes_used += sizeofobject;
  156616. hdr_ptr->hdr.bytes_left -= sizeofobject;
  156617. return (void *) data_ptr;
  156618. }
  156619. METHODDEF(void FAR *)
  156620. alloc_large (j_common_ptr cinfo, int pool_id, size_t sizeofobject)
  156621. {
  156622. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156623. large_pool_ptr hdr_ptr;
  156624. size_t odd_bytes;
  156625. if (sizeofobject > (size_t) (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)))
  156626. out_of_memory(cinfo, 3); /* request exceeds malloc's ability */
  156627. odd_bytes = sizeofobject % SIZEOF(ALIGN_TYPE);
  156628. if (odd_bytes > 0)
  156629. sizeofobject += SIZEOF(ALIGN_TYPE) - odd_bytes;
  156630. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  156631. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156632. hdr_ptr = (large_pool_ptr) jpeg_get_large(cinfo, sizeofobject +
  156633. SIZEOF(large_pool_hdr));
  156634. if (hdr_ptr == NULL)
  156635. out_of_memory(cinfo, 4); /* jpeg_get_large failed */
  156636. mem->total_space_allocated += sizeofobject + SIZEOF(large_pool_hdr);
  156637. hdr_ptr->hdr.next = mem->large_list[pool_id];
  156638. hdr_ptr->hdr.bytes_used = sizeofobject;
  156639. hdr_ptr->hdr.bytes_left = 0;
  156640. mem->large_list[pool_id] = hdr_ptr;
  156641. return (void FAR *) (hdr_ptr + 1); /* point to first data byte in pool */
  156642. }
  156643. METHODDEF(JSAMPARRAY)
  156644. alloc_sarray (j_common_ptr cinfo, int pool_id,
  156645. JDIMENSION samplesperrow, JDIMENSION numrows)
  156646. {
  156647. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156648. JSAMPARRAY result;
  156649. JSAMPROW workspace;
  156650. JDIMENSION rowsperchunk, currow, i;
  156651. long ltemp;
  156652. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156653. ((long) samplesperrow * SIZEOF(JSAMPLE));
  156654. if (ltemp <= 0)
  156655. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156656. if (ltemp < (long) numrows)
  156657. rowsperchunk = (JDIMENSION) ltemp;
  156658. else
  156659. rowsperchunk = numrows;
  156660. mem->last_rowsperchunk = rowsperchunk;
  156661. result = (JSAMPARRAY) alloc_small(cinfo, pool_id,
  156662. (size_t) (numrows * SIZEOF(JSAMPROW)));
  156663. currow = 0;
  156664. while (currow < numrows) {
  156665. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156666. workspace = (JSAMPROW) alloc_large(cinfo, pool_id,
  156667. (size_t) ((size_t) rowsperchunk * (size_t) samplesperrow
  156668. * SIZEOF(JSAMPLE)));
  156669. for (i = rowsperchunk; i > 0; i--) {
  156670. result[currow++] = workspace;
  156671. workspace += samplesperrow;
  156672. }
  156673. }
  156674. return result;
  156675. }
  156676. METHODDEF(JBLOCKARRAY)
  156677. alloc_barray (j_common_ptr cinfo, int pool_id,
  156678. JDIMENSION blocksperrow, JDIMENSION numrows)
  156679. {
  156680. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156681. JBLOCKARRAY result;
  156682. JBLOCKROW workspace;
  156683. JDIMENSION rowsperchunk, currow, i;
  156684. long ltemp;
  156685. ltemp = (MAX_ALLOC_CHUNK-SIZEOF(large_pool_hdr)) /
  156686. ((long) blocksperrow * SIZEOF(JBLOCK));
  156687. if (ltemp <= 0)
  156688. ERREXIT(cinfo, JERR_WIDTH_OVERFLOW);
  156689. if (ltemp < (long) numrows)
  156690. rowsperchunk = (JDIMENSION) ltemp;
  156691. else
  156692. rowsperchunk = numrows;
  156693. mem->last_rowsperchunk = rowsperchunk;
  156694. result = (JBLOCKARRAY) alloc_small(cinfo, pool_id,
  156695. (size_t) (numrows * SIZEOF(JBLOCKROW)));
  156696. currow = 0;
  156697. while (currow < numrows) {
  156698. rowsperchunk = MIN(rowsperchunk, numrows - currow);
  156699. workspace = (JBLOCKROW) alloc_large(cinfo, pool_id,
  156700. (size_t) ((size_t) rowsperchunk * (size_t) blocksperrow
  156701. * SIZEOF(JBLOCK)));
  156702. for (i = rowsperchunk; i > 0; i--) {
  156703. result[currow++] = workspace;
  156704. workspace += blocksperrow;
  156705. }
  156706. }
  156707. return result;
  156708. }
  156709. METHODDEF(jvirt_sarray_ptr)
  156710. request_virt_sarray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156711. JDIMENSION samplesperrow, JDIMENSION numrows,
  156712. JDIMENSION maxaccess)
  156713. {
  156714. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156715. jvirt_sarray_ptr result;
  156716. if (pool_id != JPOOL_IMAGE)
  156717. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156718. result = (jvirt_sarray_ptr) alloc_small(cinfo, pool_id,
  156719. SIZEOF(struct jvirt_sarray_control));
  156720. result->mem_buffer = NULL; /* marks array not yet realized */
  156721. result->rows_in_array = numrows;
  156722. result->samplesperrow = samplesperrow;
  156723. result->maxaccess = maxaccess;
  156724. result->pre_zero = pre_zero;
  156725. result->b_s_open = FALSE; /* no associated backing-store object */
  156726. result->next = mem->virt_sarray_list; /* add to list of virtual arrays */
  156727. mem->virt_sarray_list = result;
  156728. return result;
  156729. }
  156730. METHODDEF(jvirt_barray_ptr)
  156731. request_virt_barray (j_common_ptr cinfo, int pool_id, boolean pre_zero,
  156732. JDIMENSION blocksperrow, JDIMENSION numrows,
  156733. JDIMENSION maxaccess)
  156734. {
  156735. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156736. jvirt_barray_ptr result;
  156737. if (pool_id != JPOOL_IMAGE)
  156738. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  156739. result = (jvirt_barray_ptr) alloc_small(cinfo, pool_id,
  156740. SIZEOF(struct jvirt_barray_control));
  156741. result->mem_buffer = NULL; /* marks array not yet realized */
  156742. result->rows_in_array = numrows;
  156743. result->blocksperrow = blocksperrow;
  156744. result->maxaccess = maxaccess;
  156745. result->pre_zero = pre_zero;
  156746. result->b_s_open = FALSE; /* no associated backing-store object */
  156747. result->next = mem->virt_barray_list; /* add to list of virtual arrays */
  156748. mem->virt_barray_list = result;
  156749. return result;
  156750. }
  156751. METHODDEF(void)
  156752. realize_virt_arrays (j_common_ptr cinfo)
  156753. {
  156754. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156755. long space_per_minheight, maximum_space, avail_mem;
  156756. long minheights, max_minheights;
  156757. jvirt_sarray_ptr sptr;
  156758. jvirt_barray_ptr bptr;
  156759. space_per_minheight = 0;
  156760. maximum_space = 0;
  156761. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156762. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156763. space_per_minheight += (long) sptr->maxaccess *
  156764. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156765. maximum_space += (long) sptr->rows_in_array *
  156766. (long) sptr->samplesperrow * SIZEOF(JSAMPLE);
  156767. }
  156768. }
  156769. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156770. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156771. space_per_minheight += (long) bptr->maxaccess *
  156772. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156773. maximum_space += (long) bptr->rows_in_array *
  156774. (long) bptr->blocksperrow * SIZEOF(JBLOCK);
  156775. }
  156776. }
  156777. if (space_per_minheight <= 0)
  156778. return; /* no unrealized arrays, no work */
  156779. avail_mem = jpeg_mem_available(cinfo, space_per_minheight, maximum_space,
  156780. mem->total_space_allocated);
  156781. if (avail_mem >= maximum_space)
  156782. max_minheights = 1000000000L;
  156783. else {
  156784. max_minheights = avail_mem / space_per_minheight;
  156785. if (max_minheights <= 0)
  156786. max_minheights = 1;
  156787. }
  156788. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  156789. if (sptr->mem_buffer == NULL) { /* if not realized yet */
  156790. minheights = ((long) sptr->rows_in_array - 1L) / sptr->maxaccess + 1L;
  156791. if (minheights <= max_minheights) {
  156792. sptr->rows_in_mem = sptr->rows_in_array;
  156793. } else {
  156794. sptr->rows_in_mem = (JDIMENSION) (max_minheights * sptr->maxaccess);
  156795. jpeg_open_backing_store(cinfo, & sptr->b_s_info,
  156796. (long) sptr->rows_in_array *
  156797. (long) sptr->samplesperrow *
  156798. (long) SIZEOF(JSAMPLE));
  156799. sptr->b_s_open = TRUE;
  156800. }
  156801. sptr->mem_buffer = alloc_sarray(cinfo, JPOOL_IMAGE,
  156802. sptr->samplesperrow, sptr->rows_in_mem);
  156803. sptr->rowsperchunk = mem->last_rowsperchunk;
  156804. sptr->cur_start_row = 0;
  156805. sptr->first_undef_row = 0;
  156806. sptr->dirty = FALSE;
  156807. }
  156808. }
  156809. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  156810. if (bptr->mem_buffer == NULL) { /* if not realized yet */
  156811. minheights = ((long) bptr->rows_in_array - 1L) / bptr->maxaccess + 1L;
  156812. if (minheights <= max_minheights) {
  156813. bptr->rows_in_mem = bptr->rows_in_array;
  156814. } else {
  156815. bptr->rows_in_mem = (JDIMENSION) (max_minheights * bptr->maxaccess);
  156816. jpeg_open_backing_store(cinfo, & bptr->b_s_info,
  156817. (long) bptr->rows_in_array *
  156818. (long) bptr->blocksperrow *
  156819. (long) SIZEOF(JBLOCK));
  156820. bptr->b_s_open = TRUE;
  156821. }
  156822. bptr->mem_buffer = alloc_barray(cinfo, JPOOL_IMAGE,
  156823. bptr->blocksperrow, bptr->rows_in_mem);
  156824. bptr->rowsperchunk = mem->last_rowsperchunk;
  156825. bptr->cur_start_row = 0;
  156826. bptr->first_undef_row = 0;
  156827. bptr->dirty = FALSE;
  156828. }
  156829. }
  156830. }
  156831. LOCAL(void)
  156832. do_sarray_io (j_common_ptr cinfo, jvirt_sarray_ptr ptr, boolean writing)
  156833. {
  156834. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156835. bytesperrow = (long) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156836. file_offset = ptr->cur_start_row * bytesperrow;
  156837. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156838. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156839. thisrow = (long) ptr->cur_start_row + i;
  156840. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156841. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156842. if (rows <= 0) /* this chunk might be past end of file! */
  156843. break;
  156844. byte_count = rows * bytesperrow;
  156845. if (writing)
  156846. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156847. (void FAR *) ptr->mem_buffer[i],
  156848. file_offset, byte_count);
  156849. else
  156850. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156851. (void FAR *) ptr->mem_buffer[i],
  156852. file_offset, byte_count);
  156853. file_offset += byte_count;
  156854. }
  156855. }
  156856. LOCAL(void)
  156857. do_barray_io (j_common_ptr cinfo, jvirt_barray_ptr ptr, boolean writing)
  156858. {
  156859. long bytesperrow, file_offset, byte_count, rows, thisrow, i;
  156860. bytesperrow = (long) ptr->blocksperrow * SIZEOF(JBLOCK);
  156861. file_offset = ptr->cur_start_row * bytesperrow;
  156862. for (i = 0; i < (long) ptr->rows_in_mem; i += ptr->rowsperchunk) {
  156863. rows = MIN((long) ptr->rowsperchunk, (long) ptr->rows_in_mem - i);
  156864. thisrow = (long) ptr->cur_start_row + i;
  156865. rows = MIN(rows, (long) ptr->first_undef_row - thisrow);
  156866. rows = MIN(rows, (long) ptr->rows_in_array - thisrow);
  156867. if (rows <= 0) /* this chunk might be past end of file! */
  156868. break;
  156869. byte_count = rows * bytesperrow;
  156870. if (writing)
  156871. (*ptr->b_s_info.write_backing_store) (cinfo, & ptr->b_s_info,
  156872. (void FAR *) ptr->mem_buffer[i],
  156873. file_offset, byte_count);
  156874. else
  156875. (*ptr->b_s_info.read_backing_store) (cinfo, & ptr->b_s_info,
  156876. (void FAR *) ptr->mem_buffer[i],
  156877. file_offset, byte_count);
  156878. file_offset += byte_count;
  156879. }
  156880. }
  156881. METHODDEF(JSAMPARRAY)
  156882. access_virt_sarray (j_common_ptr cinfo, jvirt_sarray_ptr ptr,
  156883. JDIMENSION start_row, JDIMENSION num_rows,
  156884. boolean writable)
  156885. {
  156886. JDIMENSION end_row = start_row + num_rows;
  156887. JDIMENSION undef_row;
  156888. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156889. ptr->mem_buffer == NULL)
  156890. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156891. if (start_row < ptr->cur_start_row ||
  156892. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156893. if (! ptr->b_s_open)
  156894. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156895. if (ptr->dirty) {
  156896. do_sarray_io(cinfo, ptr, TRUE);
  156897. ptr->dirty = FALSE;
  156898. }
  156899. if (start_row > ptr->cur_start_row) {
  156900. ptr->cur_start_row = start_row;
  156901. } else {
  156902. long ltemp;
  156903. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156904. if (ltemp < 0)
  156905. ltemp = 0; /* don't fall off front end of file */
  156906. ptr->cur_start_row = (JDIMENSION) ltemp;
  156907. }
  156908. do_sarray_io(cinfo, ptr, FALSE);
  156909. }
  156910. if (ptr->first_undef_row < end_row) {
  156911. if (ptr->first_undef_row < start_row) {
  156912. if (writable) /* writer skipped over a section of array */
  156913. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156914. undef_row = start_row; /* but reader is allowed to read ahead */
  156915. } else {
  156916. undef_row = ptr->first_undef_row;
  156917. }
  156918. if (writable)
  156919. ptr->first_undef_row = end_row;
  156920. if (ptr->pre_zero) {
  156921. size_t bytesperrow = (size_t) ptr->samplesperrow * SIZEOF(JSAMPLE);
  156922. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156923. end_row -= ptr->cur_start_row;
  156924. while (undef_row < end_row) {
  156925. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156926. undef_row++;
  156927. }
  156928. } else {
  156929. if (! writable) /* reader looking at undefined data */
  156930. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156931. }
  156932. }
  156933. if (writable)
  156934. ptr->dirty = TRUE;
  156935. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156936. }
  156937. METHODDEF(JBLOCKARRAY)
  156938. access_virt_barray (j_common_ptr cinfo, jvirt_barray_ptr ptr,
  156939. JDIMENSION start_row, JDIMENSION num_rows,
  156940. boolean writable)
  156941. {
  156942. JDIMENSION end_row = start_row + num_rows;
  156943. JDIMENSION undef_row;
  156944. if (end_row > ptr->rows_in_array || num_rows > ptr->maxaccess ||
  156945. ptr->mem_buffer == NULL)
  156946. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156947. if (start_row < ptr->cur_start_row ||
  156948. end_row > ptr->cur_start_row+ptr->rows_in_mem) {
  156949. if (! ptr->b_s_open)
  156950. ERREXIT(cinfo, JERR_VIRTUAL_BUG);
  156951. if (ptr->dirty) {
  156952. do_barray_io(cinfo, ptr, TRUE);
  156953. ptr->dirty = FALSE;
  156954. }
  156955. if (start_row > ptr->cur_start_row) {
  156956. ptr->cur_start_row = start_row;
  156957. } else {
  156958. long ltemp;
  156959. ltemp = (long) end_row - (long) ptr->rows_in_mem;
  156960. if (ltemp < 0)
  156961. ltemp = 0; /* don't fall off front end of file */
  156962. ptr->cur_start_row = (JDIMENSION) ltemp;
  156963. }
  156964. do_barray_io(cinfo, ptr, FALSE);
  156965. }
  156966. if (ptr->first_undef_row < end_row) {
  156967. if (ptr->first_undef_row < start_row) {
  156968. if (writable) /* writer skipped over a section of array */
  156969. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156970. undef_row = start_row; /* but reader is allowed to read ahead */
  156971. } else {
  156972. undef_row = ptr->first_undef_row;
  156973. }
  156974. if (writable)
  156975. ptr->first_undef_row = end_row;
  156976. if (ptr->pre_zero) {
  156977. size_t bytesperrow = (size_t) ptr->blocksperrow * SIZEOF(JBLOCK);
  156978. undef_row -= ptr->cur_start_row; /* make indexes relative to buffer */
  156979. end_row -= ptr->cur_start_row;
  156980. while (undef_row < end_row) {
  156981. jzero_far((void FAR *) ptr->mem_buffer[undef_row], bytesperrow);
  156982. undef_row++;
  156983. }
  156984. } else {
  156985. if (! writable) /* reader looking at undefined data */
  156986. ERREXIT(cinfo, JERR_BAD_VIRTUAL_ACCESS);
  156987. }
  156988. }
  156989. if (writable)
  156990. ptr->dirty = TRUE;
  156991. return ptr->mem_buffer + (start_row - ptr->cur_start_row);
  156992. }
  156993. METHODDEF(void)
  156994. free_pool (j_common_ptr cinfo, int pool_id)
  156995. {
  156996. my_mem_ptr mem = (my_mem_ptr) cinfo->mem;
  156997. small_pool_ptr shdr_ptr;
  156998. large_pool_ptr lhdr_ptr;
  156999. size_t space_freed;
  157000. if (pool_id < 0 || pool_id >= JPOOL_NUMPOOLS)
  157001. ERREXIT1(cinfo, JERR_BAD_POOL_ID, pool_id); /* safety check */
  157002. #ifdef MEM_STATS
  157003. if (cinfo->err->trace_level > 1)
  157004. print_mem_stats(cinfo, pool_id); /* print pool's memory usage statistics */
  157005. #endif
  157006. if (pool_id == JPOOL_IMAGE) {
  157007. jvirt_sarray_ptr sptr;
  157008. jvirt_barray_ptr bptr;
  157009. for (sptr = mem->virt_sarray_list; sptr != NULL; sptr = sptr->next) {
  157010. if (sptr->b_s_open) { /* there may be no backing store */
  157011. sptr->b_s_open = FALSE; /* prevent recursive close if error */
  157012. (*sptr->b_s_info.close_backing_store) (cinfo, & sptr->b_s_info);
  157013. }
  157014. }
  157015. mem->virt_sarray_list = NULL;
  157016. for (bptr = mem->virt_barray_list; bptr != NULL; bptr = bptr->next) {
  157017. if (bptr->b_s_open) { /* there may be no backing store */
  157018. bptr->b_s_open = FALSE; /* prevent recursive close if error */
  157019. (*bptr->b_s_info.close_backing_store) (cinfo, & bptr->b_s_info);
  157020. }
  157021. }
  157022. mem->virt_barray_list = NULL;
  157023. }
  157024. lhdr_ptr = mem->large_list[pool_id];
  157025. mem->large_list[pool_id] = NULL;
  157026. while (lhdr_ptr != NULL) {
  157027. large_pool_ptr next_lhdr_ptr = lhdr_ptr->hdr.next;
  157028. space_freed = lhdr_ptr->hdr.bytes_used +
  157029. lhdr_ptr->hdr.bytes_left +
  157030. SIZEOF(large_pool_hdr);
  157031. jpeg_free_large(cinfo, (void FAR *) lhdr_ptr, space_freed);
  157032. mem->total_space_allocated -= space_freed;
  157033. lhdr_ptr = next_lhdr_ptr;
  157034. }
  157035. shdr_ptr = mem->small_list[pool_id];
  157036. mem->small_list[pool_id] = NULL;
  157037. while (shdr_ptr != NULL) {
  157038. small_pool_ptr next_shdr_ptr = shdr_ptr->hdr.next;
  157039. space_freed = shdr_ptr->hdr.bytes_used +
  157040. shdr_ptr->hdr.bytes_left +
  157041. SIZEOF(small_pool_hdr);
  157042. jpeg_free_small(cinfo, (void *) shdr_ptr, space_freed);
  157043. mem->total_space_allocated -= space_freed;
  157044. shdr_ptr = next_shdr_ptr;
  157045. }
  157046. }
  157047. METHODDEF(void)
  157048. self_destruct (j_common_ptr cinfo)
  157049. {
  157050. int pool;
  157051. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  157052. free_pool(cinfo, pool);
  157053. }
  157054. jpeg_free_small(cinfo, (void *) cinfo->mem, SIZEOF(my_memory_mgr));
  157055. cinfo->mem = NULL; /* ensures I will be called only once */
  157056. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  157057. }
  157058. GLOBAL(void)
  157059. jinit_memory_mgr (j_common_ptr cinfo)
  157060. {
  157061. my_mem_ptr mem;
  157062. long max_to_use;
  157063. int pool;
  157064. size_t test_mac;
  157065. cinfo->mem = NULL; /* for safety if init fails */
  157066. if ((SIZEOF(ALIGN_TYPE) & (SIZEOF(ALIGN_TYPE)-1)) != 0)
  157067. ERREXIT(cinfo, JERR_BAD_ALIGN_TYPE);
  157068. test_mac = (size_t) MAX_ALLOC_CHUNK;
  157069. if ((long) test_mac != MAX_ALLOC_CHUNK ||
  157070. (MAX_ALLOC_CHUNK % SIZEOF(ALIGN_TYPE)) != 0)
  157071. ERREXIT(cinfo, JERR_BAD_ALLOC_CHUNK);
  157072. max_to_use = jpeg_mem_init(cinfo); /* system-dependent initialization */
  157073. mem = (my_mem_ptr) jpeg_get_small(cinfo, SIZEOF(my_memory_mgr));
  157074. if (mem == NULL) {
  157075. jpeg_mem_term(cinfo); /* system-dependent cleanup */
  157076. ERREXIT1(cinfo, JERR_OUT_OF_MEMORY, 0);
  157077. }
  157078. mem->pub.alloc_small = alloc_small;
  157079. mem->pub.alloc_large = alloc_large;
  157080. mem->pub.alloc_sarray = alloc_sarray;
  157081. mem->pub.alloc_barray = alloc_barray;
  157082. mem->pub.request_virt_sarray = request_virt_sarray;
  157083. mem->pub.request_virt_barray = request_virt_barray;
  157084. mem->pub.realize_virt_arrays = realize_virt_arrays;
  157085. mem->pub.access_virt_sarray = access_virt_sarray;
  157086. mem->pub.access_virt_barray = access_virt_barray;
  157087. mem->pub.free_pool = free_pool;
  157088. mem->pub.self_destruct = self_destruct;
  157089. mem->pub.max_alloc_chunk = MAX_ALLOC_CHUNK;
  157090. mem->pub.max_memory_to_use = max_to_use;
  157091. for (pool = JPOOL_NUMPOOLS-1; pool >= JPOOL_PERMANENT; pool--) {
  157092. mem->small_list[pool] = NULL;
  157093. mem->large_list[pool] = NULL;
  157094. }
  157095. mem->virt_sarray_list = NULL;
  157096. mem->virt_barray_list = NULL;
  157097. mem->total_space_allocated = SIZEOF(my_memory_mgr);
  157098. cinfo->mem = & mem->pub;
  157099. #ifndef NO_GETENV
  157100. { char * memenv;
  157101. if ((memenv = getenv("JPEGMEM")) != NULL) {
  157102. char ch = 'x';
  157103. if (sscanf(memenv, "%ld%c", &max_to_use, &ch) > 0) {
  157104. if (ch == 'm' || ch == 'M')
  157105. max_to_use *= 1000L;
  157106. mem->pub.max_memory_to_use = max_to_use * 1000L;
  157107. }
  157108. }
  157109. }
  157110. #endif
  157111. }
  157112. /*** End of inlined file: jmemmgr.c ***/
  157113. /*** Start of inlined file: jmemnobs.c ***/
  157114. #define JPEG_INTERNALS
  157115. #ifndef HAVE_STDLIB_H /* <stdlib.h> should declare malloc(),free() */
  157116. extern void * malloc JPP((size_t size));
  157117. extern void free JPP((void *ptr));
  157118. #endif
  157119. GLOBAL(void *)
  157120. jpeg_get_small (j_common_ptr cinfo, size_t sizeofobject)
  157121. {
  157122. return (void *) malloc(sizeofobject);
  157123. }
  157124. GLOBAL(void)
  157125. jpeg_free_small (j_common_ptr cinfo, void * object, size_t sizeofobject)
  157126. {
  157127. free(object);
  157128. }
  157129. GLOBAL(void FAR *)
  157130. jpeg_get_large (j_common_ptr cinfo, size_t sizeofobject)
  157131. {
  157132. return (void FAR *) malloc(sizeofobject);
  157133. }
  157134. GLOBAL(void)
  157135. jpeg_free_large (j_common_ptr cinfo, void FAR * object, size_t sizeofobject)
  157136. {
  157137. free(object);
  157138. }
  157139. GLOBAL(long)
  157140. jpeg_mem_available (j_common_ptr cinfo, long min_bytes_needed,
  157141. long max_bytes_needed, long already_allocated)
  157142. {
  157143. return max_bytes_needed;
  157144. }
  157145. GLOBAL(void)
  157146. jpeg_open_backing_store (j_common_ptr cinfo, struct backing_store_struct *info,
  157147. long total_bytes_needed)
  157148. {
  157149. ERREXIT(cinfo, JERR_NO_BACKING_STORE);
  157150. }
  157151. GLOBAL(long)
  157152. jpeg_mem_init (j_common_ptr cinfo)
  157153. {
  157154. return 0; /* just set max_memory_to_use to 0 */
  157155. }
  157156. GLOBAL(void)
  157157. jpeg_mem_term (j_common_ptr cinfo)
  157158. {
  157159. }
  157160. /*** End of inlined file: jmemnobs.c ***/
  157161. /*** Start of inlined file: jquant1.c ***/
  157162. #define JPEG_INTERNALS
  157163. #ifdef QUANT_1PASS_SUPPORTED
  157164. #define ODITHER_SIZE 16 /* dimension of dither matrix */
  157165. #define ODITHER_CELLS (ODITHER_SIZE*ODITHER_SIZE) /* # cells in matrix */
  157166. #define ODITHER_MASK (ODITHER_SIZE-1) /* mask for wrapping around counters */
  157167. typedef int ODITHER_MATRIX[ODITHER_SIZE][ODITHER_SIZE];
  157168. typedef int (*ODITHER_MATRIX_PTR)[ODITHER_SIZE];
  157169. static const UINT8 base_dither_matrix[ODITHER_SIZE][ODITHER_SIZE] = {
  157170. { 0,192, 48,240, 12,204, 60,252, 3,195, 51,243, 15,207, 63,255 },
  157171. { 128, 64,176,112,140, 76,188,124,131, 67,179,115,143, 79,191,127 },
  157172. { 32,224, 16,208, 44,236, 28,220, 35,227, 19,211, 47,239, 31,223 },
  157173. { 160, 96,144, 80,172,108,156, 92,163, 99,147, 83,175,111,159, 95 },
  157174. { 8,200, 56,248, 4,196, 52,244, 11,203, 59,251, 7,199, 55,247 },
  157175. { 136, 72,184,120,132, 68,180,116,139, 75,187,123,135, 71,183,119 },
  157176. { 40,232, 24,216, 36,228, 20,212, 43,235, 27,219, 39,231, 23,215 },
  157177. { 168,104,152, 88,164,100,148, 84,171,107,155, 91,167,103,151, 87 },
  157178. { 2,194, 50,242, 14,206, 62,254, 1,193, 49,241, 13,205, 61,253 },
  157179. { 130, 66,178,114,142, 78,190,126,129, 65,177,113,141, 77,189,125 },
  157180. { 34,226, 18,210, 46,238, 30,222, 33,225, 17,209, 45,237, 29,221 },
  157181. { 162, 98,146, 82,174,110,158, 94,161, 97,145, 81,173,109,157, 93 },
  157182. { 10,202, 58,250, 6,198, 54,246, 9,201, 57,249, 5,197, 53,245 },
  157183. { 138, 74,186,122,134, 70,182,118,137, 73,185,121,133, 69,181,117 },
  157184. { 42,234, 26,218, 38,230, 22,214, 41,233, 25,217, 37,229, 21,213 },
  157185. { 170,106,154, 90,166,102,150, 86,169,105,153, 89,165,101,149, 85 }
  157186. };
  157187. #if BITS_IN_JSAMPLE == 8
  157188. typedef INT16 FSERROR; /* 16 bits should be enough */
  157189. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157190. #else
  157191. typedef INT32 FSERROR; /* may need more than 16 bits */
  157192. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157193. #endif
  157194. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157195. #define MAX_Q_COMPS 4 /* max components I can handle */
  157196. typedef struct {
  157197. struct jpeg_color_quantizer pub; /* public fields */
  157198. JSAMPARRAY sv_colormap; /* The color map as a 2-D pixel array */
  157199. int sv_actual; /* number of entries in use */
  157200. JSAMPARRAY colorindex; /* Precomputed mapping for speed */
  157201. boolean is_padded; /* is the colorindex padded for odither? */
  157202. int Ncolors[MAX_Q_COMPS]; /* # of values alloced to each component */
  157203. int row_index; /* cur row's vertical index in dither matrix */
  157204. ODITHER_MATRIX_PTR odither[MAX_Q_COMPS]; /* one dither array per component */
  157205. FSERRPTR fserrors[MAX_Q_COMPS]; /* accumulated errors */
  157206. boolean on_odd_row; /* flag to remember which row we are on */
  157207. } my_cquantizer;
  157208. typedef my_cquantizer * my_cquantize_ptr;
  157209. LOCAL(int)
  157210. select_ncolors (j_decompress_ptr cinfo, int Ncolors[])
  157211. {
  157212. int nc = cinfo->out_color_components; /* number of color components */
  157213. int max_colors = cinfo->desired_number_of_colors;
  157214. int total_colors, iroot, i, j;
  157215. boolean changed;
  157216. long temp;
  157217. static const int RGB_order[3] = { RGB_GREEN, RGB_RED, RGB_BLUE };
  157218. iroot = 1;
  157219. do {
  157220. iroot++;
  157221. temp = iroot; /* set temp = iroot ** nc */
  157222. for (i = 1; i < nc; i++)
  157223. temp *= iroot;
  157224. } while (temp <= (long) max_colors); /* repeat till iroot exceeds root */
  157225. iroot--; /* now iroot = floor(root) */
  157226. if (iroot < 2)
  157227. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, (int) temp);
  157228. total_colors = 1;
  157229. for (i = 0; i < nc; i++) {
  157230. Ncolors[i] = iroot;
  157231. total_colors *= iroot;
  157232. }
  157233. do {
  157234. changed = FALSE;
  157235. for (i = 0; i < nc; i++) {
  157236. j = (cinfo->out_color_space == JCS_RGB ? RGB_order[i] : i);
  157237. temp = total_colors / Ncolors[j];
  157238. temp *= Ncolors[j]+1; /* done in long arith to avoid oflo */
  157239. if (temp > (long) max_colors)
  157240. break; /* won't fit, done with this pass */
  157241. Ncolors[j]++; /* OK, apply the increment */
  157242. total_colors = (int) temp;
  157243. changed = TRUE;
  157244. }
  157245. } while (changed);
  157246. return total_colors;
  157247. }
  157248. LOCAL(int)
  157249. output_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  157250. {
  157251. return (int) (((INT32) j * MAXJSAMPLE + maxj/2) / maxj);
  157252. }
  157253. LOCAL(int)
  157254. largest_input_value (j_decompress_ptr cinfo, int ci, int j, int maxj)
  157255. {
  157256. return (int) (((INT32) (2*j + 1) * MAXJSAMPLE + maxj) / (2*maxj));
  157257. }
  157258. LOCAL(void)
  157259. create_colormap (j_decompress_ptr cinfo)
  157260. {
  157261. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157262. JSAMPARRAY colormap; /* Created colormap */
  157263. int total_colors; /* Number of distinct output colors */
  157264. int i,j,k, nci, blksize, blkdist, ptr, val;
  157265. total_colors = select_ncolors(cinfo, cquantize->Ncolors);
  157266. if (cinfo->out_color_components == 3)
  157267. TRACEMS4(cinfo, 1, JTRC_QUANT_3_NCOLORS,
  157268. total_colors, cquantize->Ncolors[0],
  157269. cquantize->Ncolors[1], cquantize->Ncolors[2]);
  157270. else
  157271. TRACEMS1(cinfo, 1, JTRC_QUANT_NCOLORS, total_colors);
  157272. colormap = (*cinfo->mem->alloc_sarray)
  157273. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157274. (JDIMENSION) total_colors, (JDIMENSION) cinfo->out_color_components);
  157275. blkdist = total_colors;
  157276. for (i = 0; i < cinfo->out_color_components; i++) {
  157277. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157278. blksize = blkdist / nci;
  157279. for (j = 0; j < nci; j++) {
  157280. val = output_value(cinfo, i, j, nci-1);
  157281. for (ptr = j * blksize; ptr < total_colors; ptr += blkdist) {
  157282. for (k = 0; k < blksize; k++)
  157283. colormap[i][ptr+k] = (JSAMPLE) val;
  157284. }
  157285. }
  157286. blkdist = blksize; /* blksize of this color is blkdist of next */
  157287. }
  157288. cquantize->sv_colormap = colormap;
  157289. cquantize->sv_actual = total_colors;
  157290. }
  157291. LOCAL(void)
  157292. create_colorindex (j_decompress_ptr cinfo)
  157293. {
  157294. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157295. JSAMPROW indexptr;
  157296. int i,j,k, nci, blksize, val, pad;
  157297. if (cinfo->dither_mode == JDITHER_ORDERED) {
  157298. pad = MAXJSAMPLE*2;
  157299. cquantize->is_padded = TRUE;
  157300. } else {
  157301. pad = 0;
  157302. cquantize->is_padded = FALSE;
  157303. }
  157304. cquantize->colorindex = (*cinfo->mem->alloc_sarray)
  157305. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157306. (JDIMENSION) (MAXJSAMPLE+1 + pad),
  157307. (JDIMENSION) cinfo->out_color_components);
  157308. blksize = cquantize->sv_actual;
  157309. for (i = 0; i < cinfo->out_color_components; i++) {
  157310. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157311. blksize = blksize / nci;
  157312. if (pad)
  157313. cquantize->colorindex[i] += MAXJSAMPLE;
  157314. indexptr = cquantize->colorindex[i];
  157315. val = 0;
  157316. k = largest_input_value(cinfo, i, 0, nci-1);
  157317. for (j = 0; j <= MAXJSAMPLE; j++) {
  157318. while (j > k) /* advance val if past boundary */
  157319. k = largest_input_value(cinfo, i, ++val, nci-1);
  157320. indexptr[j] = (JSAMPLE) (val * blksize);
  157321. }
  157322. if (pad)
  157323. for (j = 1; j <= MAXJSAMPLE; j++) {
  157324. indexptr[-j] = indexptr[0];
  157325. indexptr[MAXJSAMPLE+j] = indexptr[MAXJSAMPLE];
  157326. }
  157327. }
  157328. }
  157329. LOCAL(ODITHER_MATRIX_PTR)
  157330. make_odither_array (j_decompress_ptr cinfo, int ncolors)
  157331. {
  157332. ODITHER_MATRIX_PTR odither;
  157333. int j,k;
  157334. INT32 num,den;
  157335. odither = (ODITHER_MATRIX_PTR)
  157336. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157337. SIZEOF(ODITHER_MATRIX));
  157338. den = 2 * ODITHER_CELLS * ((INT32) (ncolors - 1));
  157339. for (j = 0; j < ODITHER_SIZE; j++) {
  157340. for (k = 0; k < ODITHER_SIZE; k++) {
  157341. num = ((INT32) (ODITHER_CELLS-1 - 2*((int)base_dither_matrix[j][k])))
  157342. * MAXJSAMPLE;
  157343. odither[j][k] = (int) (num<0 ? -((-num)/den) : num/den);
  157344. }
  157345. }
  157346. return odither;
  157347. }
  157348. LOCAL(void)
  157349. create_odither_tables (j_decompress_ptr cinfo)
  157350. {
  157351. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157352. ODITHER_MATRIX_PTR odither;
  157353. int i, j, nci;
  157354. for (i = 0; i < cinfo->out_color_components; i++) {
  157355. nci = cquantize->Ncolors[i]; /* # of distinct values for this color */
  157356. odither = NULL; /* search for matching prior component */
  157357. for (j = 0; j < i; j++) {
  157358. if (nci == cquantize->Ncolors[j]) {
  157359. odither = cquantize->odither[j];
  157360. break;
  157361. }
  157362. }
  157363. if (odither == NULL) /* need a new table? */
  157364. odither = make_odither_array(cinfo, nci);
  157365. cquantize->odither[i] = odither;
  157366. }
  157367. }
  157368. METHODDEF(void)
  157369. color_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157370. JSAMPARRAY output_buf, int num_rows)
  157371. {
  157372. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157373. JSAMPARRAY colorindex = cquantize->colorindex;
  157374. register int pixcode, ci;
  157375. register JSAMPROW ptrin, ptrout;
  157376. int row;
  157377. JDIMENSION col;
  157378. JDIMENSION width = cinfo->output_width;
  157379. register int nc = cinfo->out_color_components;
  157380. for (row = 0; row < num_rows; row++) {
  157381. ptrin = input_buf[row];
  157382. ptrout = output_buf[row];
  157383. for (col = width; col > 0; col--) {
  157384. pixcode = 0;
  157385. for (ci = 0; ci < nc; ci++) {
  157386. pixcode += GETJSAMPLE(colorindex[ci][GETJSAMPLE(*ptrin++)]);
  157387. }
  157388. *ptrout++ = (JSAMPLE) pixcode;
  157389. }
  157390. }
  157391. }
  157392. METHODDEF(void)
  157393. color_quantize3 (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157394. JSAMPARRAY output_buf, int num_rows)
  157395. {
  157396. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157397. register int pixcode;
  157398. register JSAMPROW ptrin, ptrout;
  157399. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157400. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157401. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157402. int row;
  157403. JDIMENSION col;
  157404. JDIMENSION width = cinfo->output_width;
  157405. for (row = 0; row < num_rows; row++) {
  157406. ptrin = input_buf[row];
  157407. ptrout = output_buf[row];
  157408. for (col = width; col > 0; col--) {
  157409. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*ptrin++)]);
  157410. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*ptrin++)]);
  157411. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*ptrin++)]);
  157412. *ptrout++ = (JSAMPLE) pixcode;
  157413. }
  157414. }
  157415. }
  157416. METHODDEF(void)
  157417. quantize_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157418. JSAMPARRAY output_buf, int num_rows)
  157419. {
  157420. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157421. register JSAMPROW input_ptr;
  157422. register JSAMPROW output_ptr;
  157423. JSAMPROW colorindex_ci;
  157424. int * dither; /* points to active row of dither matrix */
  157425. int row_index, col_index; /* current indexes into dither matrix */
  157426. int nc = cinfo->out_color_components;
  157427. int ci;
  157428. int row;
  157429. JDIMENSION col;
  157430. JDIMENSION width = cinfo->output_width;
  157431. for (row = 0; row < num_rows; row++) {
  157432. jzero_far((void FAR *) output_buf[row],
  157433. (size_t) (width * SIZEOF(JSAMPLE)));
  157434. row_index = cquantize->row_index;
  157435. for (ci = 0; ci < nc; ci++) {
  157436. input_ptr = input_buf[row] + ci;
  157437. output_ptr = output_buf[row];
  157438. colorindex_ci = cquantize->colorindex[ci];
  157439. dither = cquantize->odither[ci][row_index];
  157440. col_index = 0;
  157441. for (col = width; col > 0; col--) {
  157442. *output_ptr += colorindex_ci[GETJSAMPLE(*input_ptr)+dither[col_index]];
  157443. input_ptr += nc;
  157444. output_ptr++;
  157445. col_index = (col_index + 1) & ODITHER_MASK;
  157446. }
  157447. }
  157448. row_index = (row_index + 1) & ODITHER_MASK;
  157449. cquantize->row_index = row_index;
  157450. }
  157451. }
  157452. METHODDEF(void)
  157453. quantize3_ord_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157454. JSAMPARRAY output_buf, int num_rows)
  157455. {
  157456. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157457. register int pixcode;
  157458. register JSAMPROW input_ptr;
  157459. register JSAMPROW output_ptr;
  157460. JSAMPROW colorindex0 = cquantize->colorindex[0];
  157461. JSAMPROW colorindex1 = cquantize->colorindex[1];
  157462. JSAMPROW colorindex2 = cquantize->colorindex[2];
  157463. int * dither0; /* points to active row of dither matrix */
  157464. int * dither1;
  157465. int * dither2;
  157466. int row_index, col_index; /* current indexes into dither matrix */
  157467. int row;
  157468. JDIMENSION col;
  157469. JDIMENSION width = cinfo->output_width;
  157470. for (row = 0; row < num_rows; row++) {
  157471. row_index = cquantize->row_index;
  157472. input_ptr = input_buf[row];
  157473. output_ptr = output_buf[row];
  157474. dither0 = cquantize->odither[0][row_index];
  157475. dither1 = cquantize->odither[1][row_index];
  157476. dither2 = cquantize->odither[2][row_index];
  157477. col_index = 0;
  157478. for (col = width; col > 0; col--) {
  157479. pixcode = GETJSAMPLE(colorindex0[GETJSAMPLE(*input_ptr++) +
  157480. dither0[col_index]]);
  157481. pixcode += GETJSAMPLE(colorindex1[GETJSAMPLE(*input_ptr++) +
  157482. dither1[col_index]]);
  157483. pixcode += GETJSAMPLE(colorindex2[GETJSAMPLE(*input_ptr++) +
  157484. dither2[col_index]]);
  157485. *output_ptr++ = (JSAMPLE) pixcode;
  157486. col_index = (col_index + 1) & ODITHER_MASK;
  157487. }
  157488. row_index = (row_index + 1) & ODITHER_MASK;
  157489. cquantize->row_index = row_index;
  157490. }
  157491. }
  157492. METHODDEF(void)
  157493. quantize_fs_dither (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157494. JSAMPARRAY output_buf, int num_rows)
  157495. {
  157496. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157497. register LOCFSERROR cur; /* current error or pixel value */
  157498. LOCFSERROR belowerr; /* error for pixel below cur */
  157499. LOCFSERROR bpreverr; /* error for below/prev col */
  157500. LOCFSERROR bnexterr; /* error for below/next col */
  157501. LOCFSERROR delta;
  157502. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  157503. register JSAMPROW input_ptr;
  157504. register JSAMPROW output_ptr;
  157505. JSAMPROW colorindex_ci;
  157506. JSAMPROW colormap_ci;
  157507. int pixcode;
  157508. int nc = cinfo->out_color_components;
  157509. int dir; /* 1 for left-to-right, -1 for right-to-left */
  157510. int dirnc; /* dir * nc */
  157511. int ci;
  157512. int row;
  157513. JDIMENSION col;
  157514. JDIMENSION width = cinfo->output_width;
  157515. JSAMPLE *range_limit = cinfo->sample_range_limit;
  157516. SHIFT_TEMPS
  157517. for (row = 0; row < num_rows; row++) {
  157518. jzero_far((void FAR *) output_buf[row],
  157519. (size_t) (width * SIZEOF(JSAMPLE)));
  157520. for (ci = 0; ci < nc; ci++) {
  157521. input_ptr = input_buf[row] + ci;
  157522. output_ptr = output_buf[row];
  157523. if (cquantize->on_odd_row) {
  157524. input_ptr += (width-1) * nc; /* so point to rightmost pixel */
  157525. output_ptr += width-1;
  157526. dir = -1;
  157527. dirnc = -nc;
  157528. errorptr = cquantize->fserrors[ci] + (width+1); /* => entry after last column */
  157529. } else {
  157530. dir = 1;
  157531. dirnc = nc;
  157532. errorptr = cquantize->fserrors[ci]; /* => entry before first column */
  157533. }
  157534. colorindex_ci = cquantize->colorindex[ci];
  157535. colormap_ci = cquantize->sv_colormap[ci];
  157536. cur = 0;
  157537. belowerr = bpreverr = 0;
  157538. for (col = width; col > 0; col--) {
  157539. cur = RIGHT_SHIFT(cur + errorptr[dir] + 8, 4);
  157540. cur += GETJSAMPLE(*input_ptr);
  157541. cur = GETJSAMPLE(range_limit[cur]);
  157542. pixcode = GETJSAMPLE(colorindex_ci[cur]);
  157543. *output_ptr += (JSAMPLE) pixcode;
  157544. cur -= GETJSAMPLE(colormap_ci[pixcode]);
  157545. bnexterr = cur;
  157546. delta = cur * 2;
  157547. cur += delta; /* form error * 3 */
  157548. errorptr[0] = (FSERROR) (bpreverr + cur);
  157549. cur += delta; /* form error * 5 */
  157550. bpreverr = belowerr + cur;
  157551. belowerr = bnexterr;
  157552. cur += delta; /* form error * 7 */
  157553. input_ptr += dirnc; /* advance input ptr to next column */
  157554. output_ptr += dir; /* advance output ptr to next column */
  157555. errorptr += dir; /* advance errorptr to current column */
  157556. }
  157557. errorptr[0] = (FSERROR) bpreverr; /* unload prev err into array */
  157558. }
  157559. cquantize->on_odd_row = (cquantize->on_odd_row ? FALSE : TRUE);
  157560. }
  157561. }
  157562. LOCAL(void)
  157563. alloc_fs_workspace (j_decompress_ptr cinfo)
  157564. {
  157565. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157566. size_t arraysize;
  157567. int i;
  157568. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157569. for (i = 0; i < cinfo->out_color_components; i++) {
  157570. cquantize->fserrors[i] = (FSERRPTR)
  157571. (*cinfo->mem->alloc_large)((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  157572. }
  157573. }
  157574. METHODDEF(void)
  157575. start_pass_1_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  157576. {
  157577. my_cquantize_ptr cquantize = (my_cquantize_ptr) cinfo->cquantize;
  157578. size_t arraysize;
  157579. int i;
  157580. cinfo->colormap = cquantize->sv_colormap;
  157581. cinfo->actual_number_of_colors = cquantize->sv_actual;
  157582. switch (cinfo->dither_mode) {
  157583. case JDITHER_NONE:
  157584. if (cinfo->out_color_components == 3)
  157585. cquantize->pub.color_quantize = color_quantize3;
  157586. else
  157587. cquantize->pub.color_quantize = color_quantize;
  157588. break;
  157589. case JDITHER_ORDERED:
  157590. if (cinfo->out_color_components == 3)
  157591. cquantize->pub.color_quantize = quantize3_ord_dither;
  157592. else
  157593. cquantize->pub.color_quantize = quantize_ord_dither;
  157594. cquantize->row_index = 0; /* initialize state for ordered dither */
  157595. if (! cquantize->is_padded)
  157596. create_colorindex(cinfo);
  157597. if (cquantize->odither[0] == NULL)
  157598. create_odither_tables(cinfo);
  157599. break;
  157600. case JDITHER_FS:
  157601. cquantize->pub.color_quantize = quantize_fs_dither;
  157602. cquantize->on_odd_row = FALSE; /* initialize state for F-S dither */
  157603. if (cquantize->fserrors[0] == NULL)
  157604. alloc_fs_workspace(cinfo);
  157605. arraysize = (size_t) ((cinfo->output_width + 2) * SIZEOF(FSERROR));
  157606. for (i = 0; i < cinfo->out_color_components; i++)
  157607. jzero_far((void FAR *) cquantize->fserrors[i], arraysize);
  157608. break;
  157609. default:
  157610. ERREXIT(cinfo, JERR_NOT_COMPILED);
  157611. break;
  157612. }
  157613. }
  157614. METHODDEF(void)
  157615. finish_pass_1_quant (j_decompress_ptr cinfo)
  157616. {
  157617. }
  157618. METHODDEF(void)
  157619. new_color_map_1_quant (j_decompress_ptr cinfo)
  157620. {
  157621. ERREXIT(cinfo, JERR_MODE_CHANGE);
  157622. }
  157623. GLOBAL(void)
  157624. jinit_1pass_quantizer (j_decompress_ptr cinfo)
  157625. {
  157626. my_cquantize_ptr cquantize;
  157627. cquantize = (my_cquantize_ptr)
  157628. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  157629. SIZEOF(my_cquantizer));
  157630. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  157631. cquantize->pub.start_pass = start_pass_1_quant;
  157632. cquantize->pub.finish_pass = finish_pass_1_quant;
  157633. cquantize->pub.new_color_map = new_color_map_1_quant;
  157634. cquantize->fserrors[0] = NULL; /* Flag FS workspace not allocated */
  157635. cquantize->odither[0] = NULL; /* Also flag odither arrays not allocated */
  157636. if (cinfo->out_color_components > MAX_Q_COMPS)
  157637. ERREXIT1(cinfo, JERR_QUANT_COMPONENTS, MAX_Q_COMPS);
  157638. if (cinfo->desired_number_of_colors > (MAXJSAMPLE+1))
  157639. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXJSAMPLE+1);
  157640. create_colormap(cinfo);
  157641. create_colorindex(cinfo);
  157642. if (cinfo->dither_mode == JDITHER_FS)
  157643. alloc_fs_workspace(cinfo);
  157644. }
  157645. #endif /* QUANT_1PASS_SUPPORTED */
  157646. /*** End of inlined file: jquant1.c ***/
  157647. /*** Start of inlined file: jquant2.c ***/
  157648. #define JPEG_INTERNALS
  157649. #ifdef QUANT_2PASS_SUPPORTED
  157650. #define R_SCALE 2 /* scale R distances by this much */
  157651. #define G_SCALE 3 /* scale G distances by this much */
  157652. #define B_SCALE 1 /* and B by this much */
  157653. #if RGB_RED == 0
  157654. #define C0_SCALE R_SCALE
  157655. #endif
  157656. #if RGB_BLUE == 0
  157657. #define C0_SCALE B_SCALE
  157658. #endif
  157659. #if RGB_GREEN == 1
  157660. #define C1_SCALE G_SCALE
  157661. #endif
  157662. #if RGB_RED == 2
  157663. #define C2_SCALE R_SCALE
  157664. #endif
  157665. #if RGB_BLUE == 2
  157666. #define C2_SCALE B_SCALE
  157667. #endif
  157668. #define MAXNUMCOLORS (MAXJSAMPLE+1) /* maximum size of colormap */
  157669. #define HIST_C0_BITS 5 /* bits of precision in R/B histogram */
  157670. #define HIST_C1_BITS 6 /* bits of precision in G histogram */
  157671. #define HIST_C2_BITS 5 /* bits of precision in B/R histogram */
  157672. #define HIST_C0_ELEMS (1<<HIST_C0_BITS)
  157673. #define HIST_C1_ELEMS (1<<HIST_C1_BITS)
  157674. #define HIST_C2_ELEMS (1<<HIST_C2_BITS)
  157675. #define C0_SHIFT (BITS_IN_JSAMPLE-HIST_C0_BITS)
  157676. #define C1_SHIFT (BITS_IN_JSAMPLE-HIST_C1_BITS)
  157677. #define C2_SHIFT (BITS_IN_JSAMPLE-HIST_C2_BITS)
  157678. typedef UINT16 histcell; /* histogram cell; prefer an unsigned type */
  157679. typedef histcell FAR * histptr; /* for pointers to histogram cells */
  157680. typedef histcell hist1d[HIST_C2_ELEMS]; /* typedefs for the array */
  157681. typedef hist1d FAR * hist2d; /* type for the 2nd-level pointers */
  157682. typedef hist2d * hist3d; /* type for top-level pointer */
  157683. #if BITS_IN_JSAMPLE == 8
  157684. typedef INT16 FSERROR; /* 16 bits should be enough */
  157685. typedef int LOCFSERROR; /* use 'int' for calculation temps */
  157686. #else
  157687. typedef INT32 FSERROR; /* may need more than 16 bits */
  157688. typedef INT32 LOCFSERROR; /* be sure calculation temps are big enough */
  157689. #endif
  157690. typedef FSERROR FAR *FSERRPTR; /* pointer to error array (in FAR storage!) */
  157691. typedef struct {
  157692. struct jpeg_color_quantizer pub; /* public fields */
  157693. JSAMPARRAY sv_colormap; /* colormap allocated at init time */
  157694. int desired; /* desired # of colors = size of colormap */
  157695. hist3d histogram; /* pointer to the histogram */
  157696. boolean needs_zeroed; /* TRUE if next pass must zero histogram */
  157697. FSERRPTR fserrors; /* accumulated errors */
  157698. boolean on_odd_row; /* flag to remember which row we are on */
  157699. int * error_limiter; /* table for clamping the applied error */
  157700. } my_cquantizer2;
  157701. typedef my_cquantizer2 * my_cquantize_ptr2;
  157702. METHODDEF(void)
  157703. prescan_quantize (j_decompress_ptr cinfo, JSAMPARRAY input_buf,
  157704. JSAMPARRAY output_buf, int num_rows)
  157705. {
  157706. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157707. register JSAMPROW ptr;
  157708. register histptr histp;
  157709. register hist3d histogram = cquantize->histogram;
  157710. int row;
  157711. JDIMENSION col;
  157712. JDIMENSION width = cinfo->output_width;
  157713. for (row = 0; row < num_rows; row++) {
  157714. ptr = input_buf[row];
  157715. for (col = width; col > 0; col--) {
  157716. histp = & histogram[GETJSAMPLE(ptr[0]) >> C0_SHIFT]
  157717. [GETJSAMPLE(ptr[1]) >> C1_SHIFT]
  157718. [GETJSAMPLE(ptr[2]) >> C2_SHIFT];
  157719. if (++(*histp) <= 0)
  157720. (*histp)--;
  157721. ptr += 3;
  157722. }
  157723. }
  157724. }
  157725. typedef struct {
  157726. int c0min, c0max;
  157727. int c1min, c1max;
  157728. int c2min, c2max;
  157729. INT32 volume;
  157730. long colorcount;
  157731. } box;
  157732. typedef box * boxptr;
  157733. LOCAL(boxptr)
  157734. find_biggest_color_pop (boxptr boxlist, int numboxes)
  157735. {
  157736. register boxptr boxp;
  157737. register int i;
  157738. register long maxc = 0;
  157739. boxptr which = NULL;
  157740. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157741. if (boxp->colorcount > maxc && boxp->volume > 0) {
  157742. which = boxp;
  157743. maxc = boxp->colorcount;
  157744. }
  157745. }
  157746. return which;
  157747. }
  157748. LOCAL(boxptr)
  157749. find_biggest_volume (boxptr boxlist, int numboxes)
  157750. {
  157751. register boxptr boxp;
  157752. register int i;
  157753. register INT32 maxv = 0;
  157754. boxptr which = NULL;
  157755. for (i = 0, boxp = boxlist; i < numboxes; i++, boxp++) {
  157756. if (boxp->volume > maxv) {
  157757. which = boxp;
  157758. maxv = boxp->volume;
  157759. }
  157760. }
  157761. return which;
  157762. }
  157763. LOCAL(void)
  157764. update_box (j_decompress_ptr cinfo, boxptr boxp)
  157765. {
  157766. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157767. hist3d histogram = cquantize->histogram;
  157768. histptr histp;
  157769. int c0,c1,c2;
  157770. int c0min,c0max,c1min,c1max,c2min,c2max;
  157771. INT32 dist0,dist1,dist2;
  157772. long ccount;
  157773. c0min = boxp->c0min; c0max = boxp->c0max;
  157774. c1min = boxp->c1min; c1max = boxp->c1max;
  157775. c2min = boxp->c2min; c2max = boxp->c2max;
  157776. if (c0max > c0min)
  157777. for (c0 = c0min; c0 <= c0max; c0++)
  157778. for (c1 = c1min; c1 <= c1max; c1++) {
  157779. histp = & histogram[c0][c1][c2min];
  157780. for (c2 = c2min; c2 <= c2max; c2++)
  157781. if (*histp++ != 0) {
  157782. boxp->c0min = c0min = c0;
  157783. goto have_c0min;
  157784. }
  157785. }
  157786. have_c0min:
  157787. if (c0max > c0min)
  157788. for (c0 = c0max; c0 >= c0min; c0--)
  157789. for (c1 = c1min; c1 <= c1max; c1++) {
  157790. histp = & histogram[c0][c1][c2min];
  157791. for (c2 = c2min; c2 <= c2max; c2++)
  157792. if (*histp++ != 0) {
  157793. boxp->c0max = c0max = c0;
  157794. goto have_c0max;
  157795. }
  157796. }
  157797. have_c0max:
  157798. if (c1max > c1min)
  157799. for (c1 = c1min; c1 <= c1max; c1++)
  157800. for (c0 = c0min; c0 <= c0max; c0++) {
  157801. histp = & histogram[c0][c1][c2min];
  157802. for (c2 = c2min; c2 <= c2max; c2++)
  157803. if (*histp++ != 0) {
  157804. boxp->c1min = c1min = c1;
  157805. goto have_c1min;
  157806. }
  157807. }
  157808. have_c1min:
  157809. if (c1max > c1min)
  157810. for (c1 = c1max; c1 >= c1min; c1--)
  157811. for (c0 = c0min; c0 <= c0max; c0++) {
  157812. histp = & histogram[c0][c1][c2min];
  157813. for (c2 = c2min; c2 <= c2max; c2++)
  157814. if (*histp++ != 0) {
  157815. boxp->c1max = c1max = c1;
  157816. goto have_c1max;
  157817. }
  157818. }
  157819. have_c1max:
  157820. if (c2max > c2min)
  157821. for (c2 = c2min; c2 <= c2max; c2++)
  157822. for (c0 = c0min; c0 <= c0max; c0++) {
  157823. histp = & histogram[c0][c1min][c2];
  157824. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157825. if (*histp != 0) {
  157826. boxp->c2min = c2min = c2;
  157827. goto have_c2min;
  157828. }
  157829. }
  157830. have_c2min:
  157831. if (c2max > c2min)
  157832. for (c2 = c2max; c2 >= c2min; c2--)
  157833. for (c0 = c0min; c0 <= c0max; c0++) {
  157834. histp = & histogram[c0][c1min][c2];
  157835. for (c1 = c1min; c1 <= c1max; c1++, histp += HIST_C2_ELEMS)
  157836. if (*histp != 0) {
  157837. boxp->c2max = c2max = c2;
  157838. goto have_c2max;
  157839. }
  157840. }
  157841. have_c2max:
  157842. dist0 = ((c0max - c0min) << C0_SHIFT) * C0_SCALE;
  157843. dist1 = ((c1max - c1min) << C1_SHIFT) * C1_SCALE;
  157844. dist2 = ((c2max - c2min) << C2_SHIFT) * C2_SCALE;
  157845. boxp->volume = dist0*dist0 + dist1*dist1 + dist2*dist2;
  157846. ccount = 0;
  157847. for (c0 = c0min; c0 <= c0max; c0++)
  157848. for (c1 = c1min; c1 <= c1max; c1++) {
  157849. histp = & histogram[c0][c1][c2min];
  157850. for (c2 = c2min; c2 <= c2max; c2++, histp++)
  157851. if (*histp != 0) {
  157852. ccount++;
  157853. }
  157854. }
  157855. boxp->colorcount = ccount;
  157856. }
  157857. LOCAL(int)
  157858. median_cut (j_decompress_ptr cinfo, boxptr boxlist, int numboxes,
  157859. int desired_colors)
  157860. {
  157861. int n,lb;
  157862. int c0,c1,c2,cmax;
  157863. register boxptr b1,b2;
  157864. while (numboxes < desired_colors) {
  157865. if (numboxes*2 <= desired_colors) {
  157866. b1 = find_biggest_color_pop(boxlist, numboxes);
  157867. } else {
  157868. b1 = find_biggest_volume(boxlist, numboxes);
  157869. }
  157870. if (b1 == NULL) /* no splittable boxes left! */
  157871. break;
  157872. b2 = &boxlist[numboxes]; /* where new box will go */
  157873. b2->c0max = b1->c0max; b2->c1max = b1->c1max; b2->c2max = b1->c2max;
  157874. b2->c0min = b1->c0min; b2->c1min = b1->c1min; b2->c2min = b1->c2min;
  157875. c0 = ((b1->c0max - b1->c0min) << C0_SHIFT) * C0_SCALE;
  157876. c1 = ((b1->c1max - b1->c1min) << C1_SHIFT) * C1_SCALE;
  157877. c2 = ((b1->c2max - b1->c2min) << C2_SHIFT) * C2_SCALE;
  157878. #if RGB_RED == 0
  157879. cmax = c1; n = 1;
  157880. if (c0 > cmax) { cmax = c0; n = 0; }
  157881. if (c2 > cmax) { n = 2; }
  157882. #else
  157883. cmax = c1; n = 1;
  157884. if (c2 > cmax) { cmax = c2; n = 2; }
  157885. if (c0 > cmax) { n = 0; }
  157886. #endif
  157887. switch (n) {
  157888. case 0:
  157889. lb = (b1->c0max + b1->c0min) / 2;
  157890. b1->c0max = lb;
  157891. b2->c0min = lb+1;
  157892. break;
  157893. case 1:
  157894. lb = (b1->c1max + b1->c1min) / 2;
  157895. b1->c1max = lb;
  157896. b2->c1min = lb+1;
  157897. break;
  157898. case 2:
  157899. lb = (b1->c2max + b1->c2min) / 2;
  157900. b1->c2max = lb;
  157901. b2->c2min = lb+1;
  157902. break;
  157903. }
  157904. update_box(cinfo, b1);
  157905. update_box(cinfo, b2);
  157906. numboxes++;
  157907. }
  157908. return numboxes;
  157909. }
  157910. LOCAL(void)
  157911. compute_color (j_decompress_ptr cinfo, boxptr boxp, int icolor)
  157912. {
  157913. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  157914. hist3d histogram = cquantize->histogram;
  157915. histptr histp;
  157916. int c0,c1,c2;
  157917. int c0min,c0max,c1min,c1max,c2min,c2max;
  157918. long count;
  157919. long total = 0;
  157920. long c0total = 0;
  157921. long c1total = 0;
  157922. long c2total = 0;
  157923. c0min = boxp->c0min; c0max = boxp->c0max;
  157924. c1min = boxp->c1min; c1max = boxp->c1max;
  157925. c2min = boxp->c2min; c2max = boxp->c2max;
  157926. for (c0 = c0min; c0 <= c0max; c0++)
  157927. for (c1 = c1min; c1 <= c1max; c1++) {
  157928. histp = & histogram[c0][c1][c2min];
  157929. for (c2 = c2min; c2 <= c2max; c2++) {
  157930. if ((count = *histp++) != 0) {
  157931. total += count;
  157932. c0total += ((c0 << C0_SHIFT) + ((1<<C0_SHIFT)>>1)) * count;
  157933. c1total += ((c1 << C1_SHIFT) + ((1<<C1_SHIFT)>>1)) * count;
  157934. c2total += ((c2 << C2_SHIFT) + ((1<<C2_SHIFT)>>1)) * count;
  157935. }
  157936. }
  157937. }
  157938. cinfo->colormap[0][icolor] = (JSAMPLE) ((c0total + (total>>1)) / total);
  157939. cinfo->colormap[1][icolor] = (JSAMPLE) ((c1total + (total>>1)) / total);
  157940. cinfo->colormap[2][icolor] = (JSAMPLE) ((c2total + (total>>1)) / total);
  157941. }
  157942. LOCAL(void)
  157943. select_colors (j_decompress_ptr cinfo, int desired_colors)
  157944. {
  157945. boxptr boxlist;
  157946. int numboxes;
  157947. int i;
  157948. boxlist = (boxptr) (*cinfo->mem->alloc_small)
  157949. ((j_common_ptr) cinfo, JPOOL_IMAGE, desired_colors * SIZEOF(box));
  157950. numboxes = 1;
  157951. boxlist[0].c0min = 0;
  157952. boxlist[0].c0max = MAXJSAMPLE >> C0_SHIFT;
  157953. boxlist[0].c1min = 0;
  157954. boxlist[0].c1max = MAXJSAMPLE >> C1_SHIFT;
  157955. boxlist[0].c2min = 0;
  157956. boxlist[0].c2max = MAXJSAMPLE >> C2_SHIFT;
  157957. update_box(cinfo, & boxlist[0]);
  157958. numboxes = median_cut(cinfo, boxlist, numboxes, desired_colors);
  157959. for (i = 0; i < numboxes; i++)
  157960. compute_color(cinfo, & boxlist[i], i);
  157961. cinfo->actual_number_of_colors = numboxes;
  157962. TRACEMS1(cinfo, 1, JTRC_QUANT_SELECTED, numboxes);
  157963. }
  157964. #define BOX_C0_LOG (HIST_C0_BITS-3)
  157965. #define BOX_C1_LOG (HIST_C1_BITS-3)
  157966. #define BOX_C2_LOG (HIST_C2_BITS-3)
  157967. #define BOX_C0_ELEMS (1<<BOX_C0_LOG) /* # of hist cells in update box */
  157968. #define BOX_C1_ELEMS (1<<BOX_C1_LOG)
  157969. #define BOX_C2_ELEMS (1<<BOX_C2_LOG)
  157970. #define BOX_C0_SHIFT (C0_SHIFT + BOX_C0_LOG)
  157971. #define BOX_C1_SHIFT (C1_SHIFT + BOX_C1_LOG)
  157972. #define BOX_C2_SHIFT (C2_SHIFT + BOX_C2_LOG)
  157973. LOCAL(int)
  157974. find_nearby_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  157975. JSAMPLE colorlist[])
  157976. {
  157977. int numcolors = cinfo->actual_number_of_colors;
  157978. int maxc0, maxc1, maxc2;
  157979. int centerc0, centerc1, centerc2;
  157980. int i, x, ncolors;
  157981. INT32 minmaxdist, min_dist, max_dist, tdist;
  157982. INT32 mindist[MAXNUMCOLORS]; /* min distance to colormap entry i */
  157983. maxc0 = minc0 + ((1 << BOX_C0_SHIFT) - (1 << C0_SHIFT));
  157984. centerc0 = (minc0 + maxc0) >> 1;
  157985. maxc1 = minc1 + ((1 << BOX_C1_SHIFT) - (1 << C1_SHIFT));
  157986. centerc1 = (minc1 + maxc1) >> 1;
  157987. maxc2 = minc2 + ((1 << BOX_C2_SHIFT) - (1 << C2_SHIFT));
  157988. centerc2 = (minc2 + maxc2) >> 1;
  157989. minmaxdist = 0x7FFFFFFFL;
  157990. for (i = 0; i < numcolors; i++) {
  157991. x = GETJSAMPLE(cinfo->colormap[0][i]);
  157992. if (x < minc0) {
  157993. tdist = (x - minc0) * C0_SCALE;
  157994. min_dist = tdist*tdist;
  157995. tdist = (x - maxc0) * C0_SCALE;
  157996. max_dist = tdist*tdist;
  157997. } else if (x > maxc0) {
  157998. tdist = (x - maxc0) * C0_SCALE;
  157999. min_dist = tdist*tdist;
  158000. tdist = (x - minc0) * C0_SCALE;
  158001. max_dist = tdist*tdist;
  158002. } else {
  158003. min_dist = 0;
  158004. if (x <= centerc0) {
  158005. tdist = (x - maxc0) * C0_SCALE;
  158006. max_dist = tdist*tdist;
  158007. } else {
  158008. tdist = (x - minc0) * C0_SCALE;
  158009. max_dist = tdist*tdist;
  158010. }
  158011. }
  158012. x = GETJSAMPLE(cinfo->colormap[1][i]);
  158013. if (x < minc1) {
  158014. tdist = (x - minc1) * C1_SCALE;
  158015. min_dist += tdist*tdist;
  158016. tdist = (x - maxc1) * C1_SCALE;
  158017. max_dist += tdist*tdist;
  158018. } else if (x > maxc1) {
  158019. tdist = (x - maxc1) * C1_SCALE;
  158020. min_dist += tdist*tdist;
  158021. tdist = (x - minc1) * C1_SCALE;
  158022. max_dist += tdist*tdist;
  158023. } else {
  158024. if (x <= centerc1) {
  158025. tdist = (x - maxc1) * C1_SCALE;
  158026. max_dist += tdist*tdist;
  158027. } else {
  158028. tdist = (x - minc1) * C1_SCALE;
  158029. max_dist += tdist*tdist;
  158030. }
  158031. }
  158032. x = GETJSAMPLE(cinfo->colormap[2][i]);
  158033. if (x < minc2) {
  158034. tdist = (x - minc2) * C2_SCALE;
  158035. min_dist += tdist*tdist;
  158036. tdist = (x - maxc2) * C2_SCALE;
  158037. max_dist += tdist*tdist;
  158038. } else if (x > maxc2) {
  158039. tdist = (x - maxc2) * C2_SCALE;
  158040. min_dist += tdist*tdist;
  158041. tdist = (x - minc2) * C2_SCALE;
  158042. max_dist += tdist*tdist;
  158043. } else {
  158044. if (x <= centerc2) {
  158045. tdist = (x - maxc2) * C2_SCALE;
  158046. max_dist += tdist*tdist;
  158047. } else {
  158048. tdist = (x - minc2) * C2_SCALE;
  158049. max_dist += tdist*tdist;
  158050. }
  158051. }
  158052. mindist[i] = min_dist; /* save away the results */
  158053. if (max_dist < minmaxdist)
  158054. minmaxdist = max_dist;
  158055. }
  158056. ncolors = 0;
  158057. for (i = 0; i < numcolors; i++) {
  158058. if (mindist[i] <= minmaxdist)
  158059. colorlist[ncolors++] = (JSAMPLE) i;
  158060. }
  158061. return ncolors;
  158062. }
  158063. LOCAL(void)
  158064. find_best_colors (j_decompress_ptr cinfo, int minc0, int minc1, int minc2,
  158065. int numcolors, JSAMPLE colorlist[], JSAMPLE bestcolor[])
  158066. {
  158067. int ic0, ic1, ic2;
  158068. int i, icolor;
  158069. register INT32 * bptr; /* pointer into bestdist[] array */
  158070. JSAMPLE * cptr; /* pointer into bestcolor[] array */
  158071. INT32 dist0, dist1; /* initial distance values */
  158072. register INT32 dist2; /* current distance in inner loop */
  158073. INT32 xx0, xx1; /* distance increments */
  158074. register INT32 xx2;
  158075. INT32 inc0, inc1, inc2; /* initial values for increments */
  158076. INT32 bestdist[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  158077. bptr = bestdist;
  158078. for (i = BOX_C0_ELEMS*BOX_C1_ELEMS*BOX_C2_ELEMS-1; i >= 0; i--)
  158079. *bptr++ = 0x7FFFFFFFL;
  158080. #define STEP_C0 ((1 << C0_SHIFT) * C0_SCALE)
  158081. #define STEP_C1 ((1 << C1_SHIFT) * C1_SCALE)
  158082. #define STEP_C2 ((1 << C2_SHIFT) * C2_SCALE)
  158083. for (i = 0; i < numcolors; i++) {
  158084. icolor = GETJSAMPLE(colorlist[i]);
  158085. inc0 = (minc0 - GETJSAMPLE(cinfo->colormap[0][icolor])) * C0_SCALE;
  158086. dist0 = inc0*inc0;
  158087. inc1 = (minc1 - GETJSAMPLE(cinfo->colormap[1][icolor])) * C1_SCALE;
  158088. dist0 += inc1*inc1;
  158089. inc2 = (minc2 - GETJSAMPLE(cinfo->colormap[2][icolor])) * C2_SCALE;
  158090. dist0 += inc2*inc2;
  158091. inc0 = inc0 * (2 * STEP_C0) + STEP_C0 * STEP_C0;
  158092. inc1 = inc1 * (2 * STEP_C1) + STEP_C1 * STEP_C1;
  158093. inc2 = inc2 * (2 * STEP_C2) + STEP_C2 * STEP_C2;
  158094. bptr = bestdist;
  158095. cptr = bestcolor;
  158096. xx0 = inc0;
  158097. for (ic0 = BOX_C0_ELEMS-1; ic0 >= 0; ic0--) {
  158098. dist1 = dist0;
  158099. xx1 = inc1;
  158100. for (ic1 = BOX_C1_ELEMS-1; ic1 >= 0; ic1--) {
  158101. dist2 = dist1;
  158102. xx2 = inc2;
  158103. for (ic2 = BOX_C2_ELEMS-1; ic2 >= 0; ic2--) {
  158104. if (dist2 < *bptr) {
  158105. *bptr = dist2;
  158106. *cptr = (JSAMPLE) icolor;
  158107. }
  158108. dist2 += xx2;
  158109. xx2 += 2 * STEP_C2 * STEP_C2;
  158110. bptr++;
  158111. cptr++;
  158112. }
  158113. dist1 += xx1;
  158114. xx1 += 2 * STEP_C1 * STEP_C1;
  158115. }
  158116. dist0 += xx0;
  158117. xx0 += 2 * STEP_C0 * STEP_C0;
  158118. }
  158119. }
  158120. }
  158121. LOCAL(void)
  158122. fill_inverse_cmap (j_decompress_ptr cinfo, int c0, int c1, int c2)
  158123. {
  158124. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158125. hist3d histogram = cquantize->histogram;
  158126. int minc0, minc1, minc2; /* lower left corner of update box */
  158127. int ic0, ic1, ic2;
  158128. register JSAMPLE * cptr; /* pointer into bestcolor[] array */
  158129. register histptr cachep; /* pointer into main cache array */
  158130. JSAMPLE colorlist[MAXNUMCOLORS];
  158131. int numcolors; /* number of candidate colors */
  158132. JSAMPLE bestcolor[BOX_C0_ELEMS * BOX_C1_ELEMS * BOX_C2_ELEMS];
  158133. c0 >>= BOX_C0_LOG;
  158134. c1 >>= BOX_C1_LOG;
  158135. c2 >>= BOX_C2_LOG;
  158136. minc0 = (c0 << BOX_C0_SHIFT) + ((1 << C0_SHIFT) >> 1);
  158137. minc1 = (c1 << BOX_C1_SHIFT) + ((1 << C1_SHIFT) >> 1);
  158138. minc2 = (c2 << BOX_C2_SHIFT) + ((1 << C2_SHIFT) >> 1);
  158139. numcolors = find_nearby_colors(cinfo, minc0, minc1, minc2, colorlist);
  158140. find_best_colors(cinfo, minc0, minc1, minc2, numcolors, colorlist,
  158141. bestcolor);
  158142. c0 <<= BOX_C0_LOG; /* convert ID back to base cell indexes */
  158143. c1 <<= BOX_C1_LOG;
  158144. c2 <<= BOX_C2_LOG;
  158145. cptr = bestcolor;
  158146. for (ic0 = 0; ic0 < BOX_C0_ELEMS; ic0++) {
  158147. for (ic1 = 0; ic1 < BOX_C1_ELEMS; ic1++) {
  158148. cachep = & histogram[c0+ic0][c1+ic1][c2];
  158149. for (ic2 = 0; ic2 < BOX_C2_ELEMS; ic2++) {
  158150. *cachep++ = (histcell) (GETJSAMPLE(*cptr++) + 1);
  158151. }
  158152. }
  158153. }
  158154. }
  158155. METHODDEF(void)
  158156. pass2_no_dither (j_decompress_ptr cinfo,
  158157. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  158158. {
  158159. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158160. hist3d histogram = cquantize->histogram;
  158161. register JSAMPROW inptr, outptr;
  158162. register histptr cachep;
  158163. register int c0, c1, c2;
  158164. int row;
  158165. JDIMENSION col;
  158166. JDIMENSION width = cinfo->output_width;
  158167. for (row = 0; row < num_rows; row++) {
  158168. inptr = input_buf[row];
  158169. outptr = output_buf[row];
  158170. for (col = width; col > 0; col--) {
  158171. c0 = GETJSAMPLE(*inptr++) >> C0_SHIFT;
  158172. c1 = GETJSAMPLE(*inptr++) >> C1_SHIFT;
  158173. c2 = GETJSAMPLE(*inptr++) >> C2_SHIFT;
  158174. cachep = & histogram[c0][c1][c2];
  158175. if (*cachep == 0)
  158176. fill_inverse_cmap(cinfo, c0,c1,c2);
  158177. *outptr++ = (JSAMPLE) (*cachep - 1);
  158178. }
  158179. }
  158180. }
  158181. METHODDEF(void)
  158182. pass2_fs_dither (j_decompress_ptr cinfo,
  158183. JSAMPARRAY input_buf, JSAMPARRAY output_buf, int num_rows)
  158184. {
  158185. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158186. hist3d histogram = cquantize->histogram;
  158187. register LOCFSERROR cur0, cur1, cur2; /* current error or pixel value */
  158188. LOCFSERROR belowerr0, belowerr1, belowerr2; /* error for pixel below cur */
  158189. LOCFSERROR bpreverr0, bpreverr1, bpreverr2; /* error for below/prev col */
  158190. register FSERRPTR errorptr; /* => fserrors[] at column before current */
  158191. JSAMPROW inptr; /* => current input pixel */
  158192. JSAMPROW outptr; /* => current output pixel */
  158193. histptr cachep;
  158194. int dir; /* +1 or -1 depending on direction */
  158195. int dir3; /* 3*dir, for advancing inptr & errorptr */
  158196. int row;
  158197. JDIMENSION col;
  158198. JDIMENSION width = cinfo->output_width;
  158199. JSAMPLE *range_limit = cinfo->sample_range_limit;
  158200. int *error_limit = cquantize->error_limiter;
  158201. JSAMPROW colormap0 = cinfo->colormap[0];
  158202. JSAMPROW colormap1 = cinfo->colormap[1];
  158203. JSAMPROW colormap2 = cinfo->colormap[2];
  158204. SHIFT_TEMPS
  158205. for (row = 0; row < num_rows; row++) {
  158206. inptr = input_buf[row];
  158207. outptr = output_buf[row];
  158208. if (cquantize->on_odd_row) {
  158209. inptr += (width-1) * 3; /* so point to rightmost pixel */
  158210. outptr += width-1;
  158211. dir = -1;
  158212. dir3 = -3;
  158213. errorptr = cquantize->fserrors + (width+1)*3; /* => entry after last column */
  158214. cquantize->on_odd_row = FALSE; /* flip for next time */
  158215. } else {
  158216. dir = 1;
  158217. dir3 = 3;
  158218. errorptr = cquantize->fserrors; /* => entry before first real column */
  158219. cquantize->on_odd_row = TRUE; /* flip for next time */
  158220. }
  158221. cur0 = cur1 = cur2 = 0;
  158222. belowerr0 = belowerr1 = belowerr2 = 0;
  158223. bpreverr0 = bpreverr1 = bpreverr2 = 0;
  158224. for (col = width; col > 0; col--) {
  158225. cur0 = RIGHT_SHIFT(cur0 + errorptr[dir3+0] + 8, 4);
  158226. cur1 = RIGHT_SHIFT(cur1 + errorptr[dir3+1] + 8, 4);
  158227. cur2 = RIGHT_SHIFT(cur2 + errorptr[dir3+2] + 8, 4);
  158228. cur0 = error_limit[cur0];
  158229. cur1 = error_limit[cur1];
  158230. cur2 = error_limit[cur2];
  158231. cur0 += GETJSAMPLE(inptr[0]);
  158232. cur1 += GETJSAMPLE(inptr[1]);
  158233. cur2 += GETJSAMPLE(inptr[2]);
  158234. cur0 = GETJSAMPLE(range_limit[cur0]);
  158235. cur1 = GETJSAMPLE(range_limit[cur1]);
  158236. cur2 = GETJSAMPLE(range_limit[cur2]);
  158237. cachep = & histogram[cur0>>C0_SHIFT][cur1>>C1_SHIFT][cur2>>C2_SHIFT];
  158238. if (*cachep == 0)
  158239. fill_inverse_cmap(cinfo, cur0>>C0_SHIFT,cur1>>C1_SHIFT,cur2>>C2_SHIFT);
  158240. { register int pixcode = *cachep - 1;
  158241. *outptr = (JSAMPLE) pixcode;
  158242. cur0 -= GETJSAMPLE(colormap0[pixcode]);
  158243. cur1 -= GETJSAMPLE(colormap1[pixcode]);
  158244. cur2 -= GETJSAMPLE(colormap2[pixcode]);
  158245. }
  158246. { register LOCFSERROR bnexterr, delta;
  158247. bnexterr = cur0; /* Process component 0 */
  158248. delta = cur0 * 2;
  158249. cur0 += delta; /* form error * 3 */
  158250. errorptr[0] = (FSERROR) (bpreverr0 + cur0);
  158251. cur0 += delta; /* form error * 5 */
  158252. bpreverr0 = belowerr0 + cur0;
  158253. belowerr0 = bnexterr;
  158254. cur0 += delta; /* form error * 7 */
  158255. bnexterr = cur1; /* Process component 1 */
  158256. delta = cur1 * 2;
  158257. cur1 += delta; /* form error * 3 */
  158258. errorptr[1] = (FSERROR) (bpreverr1 + cur1);
  158259. cur1 += delta; /* form error * 5 */
  158260. bpreverr1 = belowerr1 + cur1;
  158261. belowerr1 = bnexterr;
  158262. cur1 += delta; /* form error * 7 */
  158263. bnexterr = cur2; /* Process component 2 */
  158264. delta = cur2 * 2;
  158265. cur2 += delta; /* form error * 3 */
  158266. errorptr[2] = (FSERROR) (bpreverr2 + cur2);
  158267. cur2 += delta; /* form error * 5 */
  158268. bpreverr2 = belowerr2 + cur2;
  158269. belowerr2 = bnexterr;
  158270. cur2 += delta; /* form error * 7 */
  158271. }
  158272. inptr += dir3; /* Advance pixel pointers to next column */
  158273. outptr += dir;
  158274. errorptr += dir3; /* advance errorptr to current column */
  158275. }
  158276. errorptr[0] = (FSERROR) bpreverr0; /* unload prev errs into array */
  158277. errorptr[1] = (FSERROR) bpreverr1;
  158278. errorptr[2] = (FSERROR) bpreverr2;
  158279. }
  158280. }
  158281. LOCAL(void)
  158282. init_error_limit (j_decompress_ptr cinfo)
  158283. {
  158284. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158285. int * table;
  158286. int in, out;
  158287. table = (int *) (*cinfo->mem->alloc_small)
  158288. ((j_common_ptr) cinfo, JPOOL_IMAGE, (MAXJSAMPLE*2+1) * SIZEOF(int));
  158289. table += MAXJSAMPLE; /* so can index -MAXJSAMPLE .. +MAXJSAMPLE */
  158290. cquantize->error_limiter = table;
  158291. #define STEPSIZE ((MAXJSAMPLE+1)/16)
  158292. out = 0;
  158293. for (in = 0; in < STEPSIZE; in++, out++) {
  158294. table[in] = out; table[-in] = -out;
  158295. }
  158296. for (; in < STEPSIZE*3; in++, out += (in&1) ? 0 : 1) {
  158297. table[in] = out; table[-in] = -out;
  158298. }
  158299. for (; in <= MAXJSAMPLE; in++) {
  158300. table[in] = out; table[-in] = -out;
  158301. }
  158302. #undef STEPSIZE
  158303. }
  158304. METHODDEF(void)
  158305. finish_pass1 (j_decompress_ptr cinfo)
  158306. {
  158307. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158308. cinfo->colormap = cquantize->sv_colormap;
  158309. select_colors(cinfo, cquantize->desired);
  158310. cquantize->needs_zeroed = TRUE;
  158311. }
  158312. METHODDEF(void)
  158313. finish_pass2 (j_decompress_ptr cinfo)
  158314. {
  158315. }
  158316. METHODDEF(void)
  158317. start_pass_2_quant (j_decompress_ptr cinfo, boolean is_pre_scan)
  158318. {
  158319. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158320. hist3d histogram = cquantize->histogram;
  158321. int i;
  158322. if (cinfo->dither_mode != JDITHER_NONE)
  158323. cinfo->dither_mode = JDITHER_FS;
  158324. if (is_pre_scan) {
  158325. cquantize->pub.color_quantize = prescan_quantize;
  158326. cquantize->pub.finish_pass = finish_pass1;
  158327. cquantize->needs_zeroed = TRUE; /* Always zero histogram */
  158328. } else {
  158329. if (cinfo->dither_mode == JDITHER_FS)
  158330. cquantize->pub.color_quantize = pass2_fs_dither;
  158331. else
  158332. cquantize->pub.color_quantize = pass2_no_dither;
  158333. cquantize->pub.finish_pass = finish_pass2;
  158334. i = cinfo->actual_number_of_colors;
  158335. if (i < 1)
  158336. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 1);
  158337. if (i > MAXNUMCOLORS)
  158338. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158339. if (cinfo->dither_mode == JDITHER_FS) {
  158340. size_t arraysize = (size_t) ((cinfo->output_width + 2) *
  158341. (3 * SIZEOF(FSERROR)));
  158342. if (cquantize->fserrors == NULL)
  158343. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158344. ((j_common_ptr) cinfo, JPOOL_IMAGE, arraysize);
  158345. jzero_far((void FAR *) cquantize->fserrors, arraysize);
  158346. if (cquantize->error_limiter == NULL)
  158347. init_error_limit(cinfo);
  158348. cquantize->on_odd_row = FALSE;
  158349. }
  158350. }
  158351. if (cquantize->needs_zeroed) {
  158352. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158353. jzero_far((void FAR *) histogram[i],
  158354. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158355. }
  158356. cquantize->needs_zeroed = FALSE;
  158357. }
  158358. }
  158359. METHODDEF(void)
  158360. new_color_map_2_quant (j_decompress_ptr cinfo)
  158361. {
  158362. my_cquantize_ptr2 cquantize = (my_cquantize_ptr2) cinfo->cquantize;
  158363. cquantize->needs_zeroed = TRUE;
  158364. }
  158365. GLOBAL(void)
  158366. jinit_2pass_quantizer (j_decompress_ptr cinfo)
  158367. {
  158368. my_cquantize_ptr2 cquantize;
  158369. int i;
  158370. cquantize = (my_cquantize_ptr2)
  158371. (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158372. SIZEOF(my_cquantizer2));
  158373. cinfo->cquantize = (struct jpeg_color_quantizer *) cquantize;
  158374. cquantize->pub.start_pass = start_pass_2_quant;
  158375. cquantize->pub.new_color_map = new_color_map_2_quant;
  158376. cquantize->fserrors = NULL; /* flag optional arrays not allocated */
  158377. cquantize->error_limiter = NULL;
  158378. if (cinfo->out_color_components != 3)
  158379. ERREXIT(cinfo, JERR_NOTIMPL);
  158380. cquantize->histogram = (hist3d) (*cinfo->mem->alloc_small)
  158381. ((j_common_ptr) cinfo, JPOOL_IMAGE, HIST_C0_ELEMS * SIZEOF(hist2d));
  158382. for (i = 0; i < HIST_C0_ELEMS; i++) {
  158383. cquantize->histogram[i] = (hist2d) (*cinfo->mem->alloc_large)
  158384. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158385. HIST_C1_ELEMS*HIST_C2_ELEMS * SIZEOF(histcell));
  158386. }
  158387. cquantize->needs_zeroed = TRUE; /* histogram is garbage now */
  158388. if (cinfo->enable_2pass_quant) {
  158389. int desired = cinfo->desired_number_of_colors;
  158390. if (desired < 8)
  158391. ERREXIT1(cinfo, JERR_QUANT_FEW_COLORS, 8);
  158392. if (desired > MAXNUMCOLORS)
  158393. ERREXIT1(cinfo, JERR_QUANT_MANY_COLORS, MAXNUMCOLORS);
  158394. cquantize->sv_colormap = (*cinfo->mem->alloc_sarray)
  158395. ((j_common_ptr) cinfo,JPOOL_IMAGE, (JDIMENSION) desired, (JDIMENSION) 3);
  158396. cquantize->desired = desired;
  158397. } else
  158398. cquantize->sv_colormap = NULL;
  158399. if (cinfo->dither_mode != JDITHER_NONE)
  158400. cinfo->dither_mode = JDITHER_FS;
  158401. if (cinfo->dither_mode == JDITHER_FS) {
  158402. cquantize->fserrors = (FSERRPTR) (*cinfo->mem->alloc_large)
  158403. ((j_common_ptr) cinfo, JPOOL_IMAGE,
  158404. (size_t) ((cinfo->output_width + 2) * (3 * SIZEOF(FSERROR))));
  158405. init_error_limit(cinfo);
  158406. }
  158407. }
  158408. #endif /* QUANT_2PASS_SUPPORTED */
  158409. /*** End of inlined file: jquant2.c ***/
  158410. /*** Start of inlined file: jutils.c ***/
  158411. #define JPEG_INTERNALS
  158412. #if 0 /* This table is not actually needed in v6a */
  158413. const int jpeg_zigzag_order[DCTSIZE2] = {
  158414. 0, 1, 5, 6, 14, 15, 27, 28,
  158415. 2, 4, 7, 13, 16, 26, 29, 42,
  158416. 3, 8, 12, 17, 25, 30, 41, 43,
  158417. 9, 11, 18, 24, 31, 40, 44, 53,
  158418. 10, 19, 23, 32, 39, 45, 52, 54,
  158419. 20, 22, 33, 38, 46, 51, 55, 60,
  158420. 21, 34, 37, 47, 50, 56, 59, 61,
  158421. 35, 36, 48, 49, 57, 58, 62, 63
  158422. };
  158423. #endif
  158424. const int jpeg_natural_order[DCTSIZE2+16] = {
  158425. 0, 1, 8, 16, 9, 2, 3, 10,
  158426. 17, 24, 32, 25, 18, 11, 4, 5,
  158427. 12, 19, 26, 33, 40, 48, 41, 34,
  158428. 27, 20, 13, 6, 7, 14, 21, 28,
  158429. 35, 42, 49, 56, 57, 50, 43, 36,
  158430. 29, 22, 15, 23, 30, 37, 44, 51,
  158431. 58, 59, 52, 45, 38, 31, 39, 46,
  158432. 53, 60, 61, 54, 47, 55, 62, 63,
  158433. 63, 63, 63, 63, 63, 63, 63, 63, /* extra entries for safety in decoder */
  158434. 63, 63, 63, 63, 63, 63, 63, 63
  158435. };
  158436. GLOBAL(long)
  158437. jdiv_round_up (long a, long b)
  158438. {
  158439. return (a + b - 1L) / b;
  158440. }
  158441. GLOBAL(long)
  158442. jround_up (long a, long b)
  158443. {
  158444. a += b - 1L;
  158445. return a - (a % b);
  158446. }
  158447. #ifndef NEED_FAR_POINTERS /* normal case, same as regular macros */
  158448. #define FMEMCOPY(dest,src,size) MEMCOPY(dest,src,size)
  158449. #define FMEMZERO(target,size) MEMZERO(target,size)
  158450. #else /* 80x86 case, define if we can */
  158451. #ifdef USE_FMEM
  158452. #define FMEMCOPY(dest,src,size) _fmemcpy((void FAR *)(dest), (const void FAR *)(src), (size_t)(size))
  158453. #define FMEMZERO(target,size) _fmemset((void FAR *)(target), 0, (size_t)(size))
  158454. #endif
  158455. #endif
  158456. GLOBAL(void)
  158457. jcopy_sample_rows (JSAMPARRAY input_array, int source_row,
  158458. JSAMPARRAY output_array, int dest_row,
  158459. int num_rows, JDIMENSION num_cols)
  158460. {
  158461. register JSAMPROW inptr, outptr;
  158462. #ifdef FMEMCOPY
  158463. register size_t count = (size_t) (num_cols * SIZEOF(JSAMPLE));
  158464. #else
  158465. register JDIMENSION count;
  158466. #endif
  158467. register int row;
  158468. input_array += source_row;
  158469. output_array += dest_row;
  158470. for (row = num_rows; row > 0; row--) {
  158471. inptr = *input_array++;
  158472. outptr = *output_array++;
  158473. #ifdef FMEMCOPY
  158474. FMEMCOPY(outptr, inptr, count);
  158475. #else
  158476. for (count = num_cols; count > 0; count--)
  158477. *outptr++ = *inptr++; /* needn't bother with GETJSAMPLE() here */
  158478. #endif
  158479. }
  158480. }
  158481. GLOBAL(void)
  158482. jcopy_block_row (JBLOCKROW input_row, JBLOCKROW output_row,
  158483. JDIMENSION num_blocks)
  158484. {
  158485. #ifdef FMEMCOPY
  158486. FMEMCOPY(output_row, input_row, num_blocks * (DCTSIZE2 * SIZEOF(JCOEF)));
  158487. #else
  158488. register JCOEFPTR inptr, outptr;
  158489. register long count;
  158490. inptr = (JCOEFPTR) input_row;
  158491. outptr = (JCOEFPTR) output_row;
  158492. for (count = (long) num_blocks * DCTSIZE2; count > 0; count--) {
  158493. *outptr++ = *inptr++;
  158494. }
  158495. #endif
  158496. }
  158497. GLOBAL(void)
  158498. jzero_far (void FAR * target, size_t bytestozero)
  158499. {
  158500. #ifdef FMEMZERO
  158501. FMEMZERO(target, bytestozero);
  158502. #else
  158503. register char FAR * ptr = (char FAR *) target;
  158504. register size_t count;
  158505. for (count = bytestozero; count > 0; count--) {
  158506. *ptr++ = 0;
  158507. }
  158508. #endif
  158509. }
  158510. /*** End of inlined file: jutils.c ***/
  158511. /*** Start of inlined file: transupp.c ***/
  158512. #define JPEG_INTERNALS
  158513. /*** Start of inlined file: transupp.h ***/
  158514. #ifndef TRANSFORMS_SUPPORTED
  158515. #define TRANSFORMS_SUPPORTED 1 /* 0 disables transform code */
  158516. #endif
  158517. #ifdef NEED_SHORT_EXTERNAL_NAMES
  158518. #define jtransform_request_workspace jTrRequest
  158519. #define jtransform_adjust_parameters jTrAdjust
  158520. #define jtransform_execute_transformation jTrExec
  158521. #define jcopy_markers_setup jCMrkSetup
  158522. #define jcopy_markers_execute jCMrkExec
  158523. #endif /* NEED_SHORT_EXTERNAL_NAMES */
  158524. typedef enum {
  158525. JXFORM_NONE, /* no transformation */
  158526. JXFORM_FLIP_H, /* horizontal flip */
  158527. JXFORM_FLIP_V, /* vertical flip */
  158528. JXFORM_TRANSPOSE, /* transpose across UL-to-LR axis */
  158529. JXFORM_TRANSVERSE, /* transpose across UR-to-LL axis */
  158530. JXFORM_ROT_90, /* 90-degree clockwise rotation */
  158531. JXFORM_ROT_180, /* 180-degree rotation */
  158532. JXFORM_ROT_270 /* 270-degree clockwise (or 90 ccw) */
  158533. } JXFORM_CODE;
  158534. typedef struct {
  158535. JXFORM_CODE transform; /* image transform operator */
  158536. boolean trim; /* if TRUE, trim partial MCUs as needed */
  158537. boolean force_grayscale; /* if TRUE, convert color image to grayscale */
  158538. int num_components; /* # of components in workspace */
  158539. jvirt_barray_ptr * workspace_coef_arrays; /* workspace for transformations */
  158540. } jpeg_transform_info;
  158541. #if TRANSFORMS_SUPPORTED
  158542. EXTERN(void) jtransform_request_workspace
  158543. JPP((j_decompress_ptr srcinfo, jpeg_transform_info *info));
  158544. EXTERN(jvirt_barray_ptr *) jtransform_adjust_parameters
  158545. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158546. jvirt_barray_ptr *src_coef_arrays,
  158547. jpeg_transform_info *info));
  158548. EXTERN(void) jtransform_execute_transformation
  158549. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158550. jvirt_barray_ptr *src_coef_arrays,
  158551. jpeg_transform_info *info));
  158552. #endif /* TRANSFORMS_SUPPORTED */
  158553. typedef enum {
  158554. JCOPYOPT_NONE, /* copy no optional markers */
  158555. JCOPYOPT_COMMENTS, /* copy only comment (COM) markers */
  158556. JCOPYOPT_ALL /* copy all optional markers */
  158557. } JCOPY_OPTION;
  158558. #define JCOPYOPT_DEFAULT JCOPYOPT_COMMENTS /* recommended default */
  158559. EXTERN(void) jcopy_markers_setup
  158560. JPP((j_decompress_ptr srcinfo, JCOPY_OPTION option));
  158561. EXTERN(void) jcopy_markers_execute
  158562. JPP((j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158563. JCOPY_OPTION option));
  158564. /*** End of inlined file: transupp.h ***/
  158565. /* My own external interface */
  158566. #if TRANSFORMS_SUPPORTED
  158567. LOCAL(void)
  158568. do_flip_h (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158569. jvirt_barray_ptr *src_coef_arrays)
  158570. {
  158571. JDIMENSION MCU_cols, comp_width, blk_x, blk_y;
  158572. int ci, k, offset_y;
  158573. JBLOCKARRAY buffer;
  158574. JCOEFPTR ptr1, ptr2;
  158575. JCOEF temp1, temp2;
  158576. jpeg_component_info *compptr;
  158577. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158578. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158579. compptr = dstinfo->comp_info + ci;
  158580. comp_width = MCU_cols * compptr->h_samp_factor;
  158581. for (blk_y = 0; blk_y < compptr->height_in_blocks;
  158582. blk_y += compptr->v_samp_factor) {
  158583. buffer = (*srcinfo->mem->access_virt_barray)
  158584. ((j_common_ptr) srcinfo, src_coef_arrays[ci], blk_y,
  158585. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158586. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158587. for (blk_x = 0; blk_x * 2 < comp_width; blk_x++) {
  158588. ptr1 = buffer[offset_y][blk_x];
  158589. ptr2 = buffer[offset_y][comp_width - blk_x - 1];
  158590. for (k = 0; k < DCTSIZE2; k += 2) {
  158591. temp1 = *ptr1; /* swap even column */
  158592. temp2 = *ptr2;
  158593. *ptr1++ = temp2;
  158594. *ptr2++ = temp1;
  158595. temp1 = *ptr1; /* swap odd column with sign change */
  158596. temp2 = *ptr2;
  158597. *ptr1++ = -temp2;
  158598. *ptr2++ = -temp1;
  158599. }
  158600. }
  158601. }
  158602. }
  158603. }
  158604. }
  158605. LOCAL(void)
  158606. do_flip_v (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158607. jvirt_barray_ptr *src_coef_arrays,
  158608. jvirt_barray_ptr *dst_coef_arrays)
  158609. {
  158610. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158611. int ci, i, j, offset_y;
  158612. JBLOCKARRAY src_buffer, dst_buffer;
  158613. JBLOCKROW src_row_ptr, dst_row_ptr;
  158614. JCOEFPTR src_ptr, dst_ptr;
  158615. jpeg_component_info *compptr;
  158616. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158617. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158618. compptr = dstinfo->comp_info + ci;
  158619. comp_height = MCU_rows * compptr->v_samp_factor;
  158620. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158621. dst_blk_y += compptr->v_samp_factor) {
  158622. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158623. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158624. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158625. if (dst_blk_y < comp_height) {
  158626. src_buffer = (*srcinfo->mem->access_virt_barray)
  158627. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158628. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158629. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158630. } else {
  158631. src_buffer = (*srcinfo->mem->access_virt_barray)
  158632. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158633. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158634. }
  158635. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158636. if (dst_blk_y < comp_height) {
  158637. dst_row_ptr = dst_buffer[offset_y];
  158638. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158639. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158640. dst_blk_x++) {
  158641. dst_ptr = dst_row_ptr[dst_blk_x];
  158642. src_ptr = src_row_ptr[dst_blk_x];
  158643. for (i = 0; i < DCTSIZE; i += 2) {
  158644. for (j = 0; j < DCTSIZE; j++)
  158645. *dst_ptr++ = *src_ptr++;
  158646. for (j = 0; j < DCTSIZE; j++)
  158647. *dst_ptr++ = - *src_ptr++;
  158648. }
  158649. }
  158650. } else {
  158651. jcopy_block_row(src_buffer[offset_y], dst_buffer[offset_y],
  158652. compptr->width_in_blocks);
  158653. }
  158654. }
  158655. }
  158656. }
  158657. }
  158658. LOCAL(void)
  158659. do_transpose (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158660. jvirt_barray_ptr *src_coef_arrays,
  158661. jvirt_barray_ptr *dst_coef_arrays)
  158662. {
  158663. JDIMENSION dst_blk_x, dst_blk_y;
  158664. int ci, i, j, offset_x, offset_y;
  158665. JBLOCKARRAY src_buffer, dst_buffer;
  158666. JCOEFPTR src_ptr, dst_ptr;
  158667. jpeg_component_info *compptr;
  158668. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158669. compptr = dstinfo->comp_info + ci;
  158670. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158671. dst_blk_y += compptr->v_samp_factor) {
  158672. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158673. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158674. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158675. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158676. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158677. dst_blk_x += compptr->h_samp_factor) {
  158678. src_buffer = (*srcinfo->mem->access_virt_barray)
  158679. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158680. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158681. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158682. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158683. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158684. for (i = 0; i < DCTSIZE; i++)
  158685. for (j = 0; j < DCTSIZE; j++)
  158686. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158687. }
  158688. }
  158689. }
  158690. }
  158691. }
  158692. }
  158693. LOCAL(void)
  158694. do_rot_90 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158695. jvirt_barray_ptr *src_coef_arrays,
  158696. jvirt_barray_ptr *dst_coef_arrays)
  158697. {
  158698. JDIMENSION MCU_cols, comp_width, dst_blk_x, dst_blk_y;
  158699. int ci, i, j, offset_x, offset_y;
  158700. JBLOCKARRAY src_buffer, dst_buffer;
  158701. JCOEFPTR src_ptr, dst_ptr;
  158702. jpeg_component_info *compptr;
  158703. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158704. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158705. compptr = dstinfo->comp_info + ci;
  158706. comp_width = MCU_cols * compptr->h_samp_factor;
  158707. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158708. dst_blk_y += compptr->v_samp_factor) {
  158709. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158710. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158711. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158712. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158713. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158714. dst_blk_x += compptr->h_samp_factor) {
  158715. src_buffer = (*srcinfo->mem->access_virt_barray)
  158716. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158717. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158718. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158719. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158720. if (dst_blk_x < comp_width) {
  158721. dst_ptr = dst_buffer[offset_y]
  158722. [comp_width - dst_blk_x - offset_x - 1];
  158723. for (i = 0; i < DCTSIZE; i++) {
  158724. for (j = 0; j < DCTSIZE; j++)
  158725. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158726. i++;
  158727. for (j = 0; j < DCTSIZE; j++)
  158728. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158729. }
  158730. } else {
  158731. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158732. for (i = 0; i < DCTSIZE; i++)
  158733. for (j = 0; j < DCTSIZE; j++)
  158734. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158735. }
  158736. }
  158737. }
  158738. }
  158739. }
  158740. }
  158741. }
  158742. LOCAL(void)
  158743. do_rot_270 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158744. jvirt_barray_ptr *src_coef_arrays,
  158745. jvirt_barray_ptr *dst_coef_arrays)
  158746. {
  158747. JDIMENSION MCU_rows, comp_height, dst_blk_x, dst_blk_y;
  158748. int ci, i, j, offset_x, offset_y;
  158749. JBLOCKARRAY src_buffer, dst_buffer;
  158750. JCOEFPTR src_ptr, dst_ptr;
  158751. jpeg_component_info *compptr;
  158752. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158753. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158754. compptr = dstinfo->comp_info + ci;
  158755. comp_height = MCU_rows * compptr->v_samp_factor;
  158756. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158757. dst_blk_y += compptr->v_samp_factor) {
  158758. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158759. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158760. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158761. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158762. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158763. dst_blk_x += compptr->h_samp_factor) {
  158764. src_buffer = (*srcinfo->mem->access_virt_barray)
  158765. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158766. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158767. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158768. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158769. if (dst_blk_y < comp_height) {
  158770. src_ptr = src_buffer[offset_x]
  158771. [comp_height - dst_blk_y - offset_y - 1];
  158772. for (i = 0; i < DCTSIZE; i++) {
  158773. for (j = 0; j < DCTSIZE; j++) {
  158774. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158775. j++;
  158776. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158777. }
  158778. }
  158779. } else {
  158780. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158781. for (i = 0; i < DCTSIZE; i++)
  158782. for (j = 0; j < DCTSIZE; j++)
  158783. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158784. }
  158785. }
  158786. }
  158787. }
  158788. }
  158789. }
  158790. }
  158791. LOCAL(void)
  158792. do_rot_180 (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158793. jvirt_barray_ptr *src_coef_arrays,
  158794. jvirt_barray_ptr *dst_coef_arrays)
  158795. {
  158796. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158797. int ci, i, j, offset_y;
  158798. JBLOCKARRAY src_buffer, dst_buffer;
  158799. JBLOCKROW src_row_ptr, dst_row_ptr;
  158800. JCOEFPTR src_ptr, dst_ptr;
  158801. jpeg_component_info *compptr;
  158802. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158803. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158804. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158805. compptr = dstinfo->comp_info + ci;
  158806. comp_width = MCU_cols * compptr->h_samp_factor;
  158807. comp_height = MCU_rows * compptr->v_samp_factor;
  158808. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158809. dst_blk_y += compptr->v_samp_factor) {
  158810. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158811. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158812. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158813. if (dst_blk_y < comp_height) {
  158814. src_buffer = (*srcinfo->mem->access_virt_barray)
  158815. ((j_common_ptr) srcinfo, src_coef_arrays[ci],
  158816. comp_height - dst_blk_y - (JDIMENSION) compptr->v_samp_factor,
  158817. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158818. } else {
  158819. src_buffer = (*srcinfo->mem->access_virt_barray)
  158820. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_y,
  158821. (JDIMENSION) compptr->v_samp_factor, FALSE);
  158822. }
  158823. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158824. if (dst_blk_y < comp_height) {
  158825. dst_row_ptr = dst_buffer[offset_y];
  158826. src_row_ptr = src_buffer[compptr->v_samp_factor - offset_y - 1];
  158827. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158828. dst_ptr = dst_row_ptr[dst_blk_x];
  158829. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158830. for (i = 0; i < DCTSIZE; i += 2) {
  158831. for (j = 0; j < DCTSIZE; j += 2) {
  158832. *dst_ptr++ = *src_ptr++;
  158833. *dst_ptr++ = - *src_ptr++;
  158834. }
  158835. for (j = 0; j < DCTSIZE; j += 2) {
  158836. *dst_ptr++ = - *src_ptr++;
  158837. *dst_ptr++ = *src_ptr++;
  158838. }
  158839. }
  158840. }
  158841. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158842. dst_ptr = dst_row_ptr[dst_blk_x];
  158843. src_ptr = src_row_ptr[dst_blk_x];
  158844. for (i = 0; i < DCTSIZE; i += 2) {
  158845. for (j = 0; j < DCTSIZE; j++)
  158846. *dst_ptr++ = *src_ptr++;
  158847. for (j = 0; j < DCTSIZE; j++)
  158848. *dst_ptr++ = - *src_ptr++;
  158849. }
  158850. }
  158851. } else {
  158852. dst_row_ptr = dst_buffer[offset_y];
  158853. src_row_ptr = src_buffer[offset_y];
  158854. for (dst_blk_x = 0; dst_blk_x < comp_width; dst_blk_x++) {
  158855. dst_ptr = dst_row_ptr[dst_blk_x];
  158856. src_ptr = src_row_ptr[comp_width - dst_blk_x - 1];
  158857. for (i = 0; i < DCTSIZE2; i += 2) {
  158858. *dst_ptr++ = *src_ptr++;
  158859. *dst_ptr++ = - *src_ptr++;
  158860. }
  158861. }
  158862. for (; dst_blk_x < compptr->width_in_blocks; dst_blk_x++) {
  158863. dst_ptr = dst_row_ptr[dst_blk_x];
  158864. src_ptr = src_row_ptr[dst_blk_x];
  158865. for (i = 0; i < DCTSIZE2; i++)
  158866. *dst_ptr++ = *src_ptr++;
  158867. }
  158868. }
  158869. }
  158870. }
  158871. }
  158872. }
  158873. LOCAL(void)
  158874. do_transverse (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  158875. jvirt_barray_ptr *src_coef_arrays,
  158876. jvirt_barray_ptr *dst_coef_arrays)
  158877. {
  158878. JDIMENSION MCU_cols, MCU_rows, comp_width, comp_height, dst_blk_x, dst_blk_y;
  158879. int ci, i, j, offset_x, offset_y;
  158880. JBLOCKARRAY src_buffer, dst_buffer;
  158881. JCOEFPTR src_ptr, dst_ptr;
  158882. jpeg_component_info *compptr;
  158883. MCU_cols = dstinfo->image_width / (dstinfo->max_h_samp_factor * DCTSIZE);
  158884. MCU_rows = dstinfo->image_height / (dstinfo->max_v_samp_factor * DCTSIZE);
  158885. for (ci = 0; ci < dstinfo->num_components; ci++) {
  158886. compptr = dstinfo->comp_info + ci;
  158887. comp_width = MCU_cols * compptr->h_samp_factor;
  158888. comp_height = MCU_rows * compptr->v_samp_factor;
  158889. for (dst_blk_y = 0; dst_blk_y < compptr->height_in_blocks;
  158890. dst_blk_y += compptr->v_samp_factor) {
  158891. dst_buffer = (*srcinfo->mem->access_virt_barray)
  158892. ((j_common_ptr) srcinfo, dst_coef_arrays[ci], dst_blk_y,
  158893. (JDIMENSION) compptr->v_samp_factor, TRUE);
  158894. for (offset_y = 0; offset_y < compptr->v_samp_factor; offset_y++) {
  158895. for (dst_blk_x = 0; dst_blk_x < compptr->width_in_blocks;
  158896. dst_blk_x += compptr->h_samp_factor) {
  158897. src_buffer = (*srcinfo->mem->access_virt_barray)
  158898. ((j_common_ptr) srcinfo, src_coef_arrays[ci], dst_blk_x,
  158899. (JDIMENSION) compptr->h_samp_factor, FALSE);
  158900. for (offset_x = 0; offset_x < compptr->h_samp_factor; offset_x++) {
  158901. if (dst_blk_y < comp_height) {
  158902. src_ptr = src_buffer[offset_x]
  158903. [comp_height - dst_blk_y - offset_y - 1];
  158904. if (dst_blk_x < comp_width) {
  158905. dst_ptr = dst_buffer[offset_y]
  158906. [comp_width - dst_blk_x - offset_x - 1];
  158907. for (i = 0; i < DCTSIZE; i++) {
  158908. for (j = 0; j < DCTSIZE; j++) {
  158909. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158910. j++;
  158911. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158912. }
  158913. i++;
  158914. for (j = 0; j < DCTSIZE; j++) {
  158915. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158916. j++;
  158917. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158918. }
  158919. }
  158920. } else {
  158921. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158922. for (i = 0; i < DCTSIZE; i++) {
  158923. for (j = 0; j < DCTSIZE; j++) {
  158924. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158925. j++;
  158926. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158927. }
  158928. }
  158929. }
  158930. } else {
  158931. src_ptr = src_buffer[offset_x][dst_blk_y + offset_y];
  158932. if (dst_blk_x < comp_width) {
  158933. dst_ptr = dst_buffer[offset_y]
  158934. [comp_width - dst_blk_x - offset_x - 1];
  158935. for (i = 0; i < DCTSIZE; i++) {
  158936. for (j = 0; j < DCTSIZE; j++)
  158937. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158938. i++;
  158939. for (j = 0; j < DCTSIZE; j++)
  158940. dst_ptr[j*DCTSIZE+i] = -src_ptr[i*DCTSIZE+j];
  158941. }
  158942. } else {
  158943. dst_ptr = dst_buffer[offset_y][dst_blk_x + offset_x];
  158944. for (i = 0; i < DCTSIZE; i++)
  158945. for (j = 0; j < DCTSIZE; j++)
  158946. dst_ptr[j*DCTSIZE+i] = src_ptr[i*DCTSIZE+j];
  158947. }
  158948. }
  158949. }
  158950. }
  158951. }
  158952. }
  158953. }
  158954. }
  158955. GLOBAL(void)
  158956. jtransform_request_workspace (j_decompress_ptr srcinfo,
  158957. jpeg_transform_info *info)
  158958. {
  158959. jvirt_barray_ptr *coef_arrays = NULL;
  158960. jpeg_component_info *compptr;
  158961. int ci;
  158962. if (info->force_grayscale &&
  158963. srcinfo->jpeg_color_space == JCS_YCbCr &&
  158964. srcinfo->num_components == 3) {
  158965. info->num_components = 1;
  158966. } else {
  158967. info->num_components = srcinfo->num_components;
  158968. }
  158969. switch (info->transform) {
  158970. case JXFORM_NONE:
  158971. case JXFORM_FLIP_H:
  158972. break;
  158973. case JXFORM_FLIP_V:
  158974. case JXFORM_ROT_180:
  158975. coef_arrays = (jvirt_barray_ptr *)
  158976. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158977. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158978. for (ci = 0; ci < info->num_components; ci++) {
  158979. compptr = srcinfo->comp_info + ci;
  158980. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158981. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  158982. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  158983. (long) compptr->h_samp_factor),
  158984. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  158985. (long) compptr->v_samp_factor),
  158986. (JDIMENSION) compptr->v_samp_factor);
  158987. }
  158988. break;
  158989. case JXFORM_TRANSPOSE:
  158990. case JXFORM_TRANSVERSE:
  158991. case JXFORM_ROT_90:
  158992. case JXFORM_ROT_270:
  158993. coef_arrays = (jvirt_barray_ptr *)
  158994. (*srcinfo->mem->alloc_small) ((j_common_ptr) srcinfo, JPOOL_IMAGE,
  158995. SIZEOF(jvirt_barray_ptr) * info->num_components);
  158996. for (ci = 0; ci < info->num_components; ci++) {
  158997. compptr = srcinfo->comp_info + ci;
  158998. coef_arrays[ci] = (*srcinfo->mem->request_virt_barray)
  158999. ((j_common_ptr) srcinfo, JPOOL_IMAGE, FALSE,
  159000. (JDIMENSION) jround_up((long) compptr->height_in_blocks,
  159001. (long) compptr->v_samp_factor),
  159002. (JDIMENSION) jround_up((long) compptr->width_in_blocks,
  159003. (long) compptr->h_samp_factor),
  159004. (JDIMENSION) compptr->h_samp_factor);
  159005. }
  159006. break;
  159007. }
  159008. info->workspace_coef_arrays = coef_arrays;
  159009. }
  159010. LOCAL(void)
  159011. transpose_critical_parameters (j_compress_ptr dstinfo)
  159012. {
  159013. int tblno, i, j, ci, itemp;
  159014. jpeg_component_info *compptr;
  159015. JQUANT_TBL *qtblptr;
  159016. JDIMENSION dtemp;
  159017. UINT16 qtemp;
  159018. dtemp = dstinfo->image_width;
  159019. dstinfo->image_width = dstinfo->image_height;
  159020. dstinfo->image_height = dtemp;
  159021. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159022. compptr = dstinfo->comp_info + ci;
  159023. itemp = compptr->h_samp_factor;
  159024. compptr->h_samp_factor = compptr->v_samp_factor;
  159025. compptr->v_samp_factor = itemp;
  159026. }
  159027. for (tblno = 0; tblno < NUM_QUANT_TBLS; tblno++) {
  159028. qtblptr = dstinfo->quant_tbl_ptrs[tblno];
  159029. if (qtblptr != NULL) {
  159030. for (i = 0; i < DCTSIZE; i++) {
  159031. for (j = 0; j < i; j++) {
  159032. qtemp = qtblptr->quantval[i*DCTSIZE+j];
  159033. qtblptr->quantval[i*DCTSIZE+j] = qtblptr->quantval[j*DCTSIZE+i];
  159034. qtblptr->quantval[j*DCTSIZE+i] = qtemp;
  159035. }
  159036. }
  159037. }
  159038. }
  159039. }
  159040. LOCAL(void)
  159041. trim_right_edge (j_compress_ptr dstinfo)
  159042. {
  159043. int ci, max_h_samp_factor;
  159044. JDIMENSION MCU_cols;
  159045. max_h_samp_factor = 1;
  159046. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159047. int h_samp_factor = dstinfo->comp_info[ci].h_samp_factor;
  159048. max_h_samp_factor = MAX(max_h_samp_factor, h_samp_factor);
  159049. }
  159050. MCU_cols = dstinfo->image_width / (max_h_samp_factor * DCTSIZE);
  159051. if (MCU_cols > 0) /* can't trim to 0 pixels */
  159052. dstinfo->image_width = MCU_cols * (max_h_samp_factor * DCTSIZE);
  159053. }
  159054. LOCAL(void)
  159055. trim_bottom_edge (j_compress_ptr dstinfo)
  159056. {
  159057. int ci, max_v_samp_factor;
  159058. JDIMENSION MCU_rows;
  159059. max_v_samp_factor = 1;
  159060. for (ci = 0; ci < dstinfo->num_components; ci++) {
  159061. int v_samp_factor = dstinfo->comp_info[ci].v_samp_factor;
  159062. max_v_samp_factor = MAX(max_v_samp_factor, v_samp_factor);
  159063. }
  159064. MCU_rows = dstinfo->image_height / (max_v_samp_factor * DCTSIZE);
  159065. if (MCU_rows > 0) /* can't trim to 0 pixels */
  159066. dstinfo->image_height = MCU_rows * (max_v_samp_factor * DCTSIZE);
  159067. }
  159068. GLOBAL(jvirt_barray_ptr *)
  159069. jtransform_adjust_parameters (j_decompress_ptr srcinfo,
  159070. j_compress_ptr dstinfo,
  159071. jvirt_barray_ptr *src_coef_arrays,
  159072. jpeg_transform_info *info)
  159073. {
  159074. if (info->force_grayscale) {
  159075. if ((dstinfo->jpeg_color_space == JCS_YCbCr &&
  159076. dstinfo->num_components == 3) ||
  159077. (dstinfo->jpeg_color_space == JCS_GRAYSCALE &&
  159078. dstinfo->num_components == 1)) {
  159079. int sv_quant_tbl_no = dstinfo->comp_info[0].quant_tbl_no;
  159080. jpeg_set_colorspace(dstinfo, JCS_GRAYSCALE);
  159081. dstinfo->comp_info[0].quant_tbl_no = sv_quant_tbl_no;
  159082. } else {
  159083. ERREXIT(dstinfo, JERR_CONVERSION_NOTIMPL);
  159084. }
  159085. }
  159086. switch (info->transform) {
  159087. case JXFORM_NONE:
  159088. break;
  159089. case JXFORM_FLIP_H:
  159090. if (info->trim)
  159091. trim_right_edge(dstinfo);
  159092. break;
  159093. case JXFORM_FLIP_V:
  159094. if (info->trim)
  159095. trim_bottom_edge(dstinfo);
  159096. break;
  159097. case JXFORM_TRANSPOSE:
  159098. transpose_critical_parameters(dstinfo);
  159099. break;
  159100. case JXFORM_TRANSVERSE:
  159101. transpose_critical_parameters(dstinfo);
  159102. if (info->trim) {
  159103. trim_right_edge(dstinfo);
  159104. trim_bottom_edge(dstinfo);
  159105. }
  159106. break;
  159107. case JXFORM_ROT_90:
  159108. transpose_critical_parameters(dstinfo);
  159109. if (info->trim)
  159110. trim_right_edge(dstinfo);
  159111. break;
  159112. case JXFORM_ROT_180:
  159113. if (info->trim) {
  159114. trim_right_edge(dstinfo);
  159115. trim_bottom_edge(dstinfo);
  159116. }
  159117. break;
  159118. case JXFORM_ROT_270:
  159119. transpose_critical_parameters(dstinfo);
  159120. if (info->trim)
  159121. trim_bottom_edge(dstinfo);
  159122. break;
  159123. }
  159124. if (info->workspace_coef_arrays != NULL)
  159125. return info->workspace_coef_arrays;
  159126. return src_coef_arrays;
  159127. }
  159128. GLOBAL(void)
  159129. jtransform_execute_transformation (j_decompress_ptr srcinfo,
  159130. j_compress_ptr dstinfo,
  159131. jvirt_barray_ptr *src_coef_arrays,
  159132. jpeg_transform_info *info)
  159133. {
  159134. jvirt_barray_ptr *dst_coef_arrays = info->workspace_coef_arrays;
  159135. switch (info->transform) {
  159136. case JXFORM_NONE:
  159137. break;
  159138. case JXFORM_FLIP_H:
  159139. do_flip_h(srcinfo, dstinfo, src_coef_arrays);
  159140. break;
  159141. case JXFORM_FLIP_V:
  159142. do_flip_v(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159143. break;
  159144. case JXFORM_TRANSPOSE:
  159145. do_transpose(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159146. break;
  159147. case JXFORM_TRANSVERSE:
  159148. do_transverse(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159149. break;
  159150. case JXFORM_ROT_90:
  159151. do_rot_90(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159152. break;
  159153. case JXFORM_ROT_180:
  159154. do_rot_180(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159155. break;
  159156. case JXFORM_ROT_270:
  159157. do_rot_270(srcinfo, dstinfo, src_coef_arrays, dst_coef_arrays);
  159158. break;
  159159. }
  159160. }
  159161. #endif /* TRANSFORMS_SUPPORTED */
  159162. GLOBAL(void)
  159163. jcopy_markers_setup (j_decompress_ptr srcinfo, JCOPY_OPTION option)
  159164. {
  159165. #ifdef SAVE_MARKERS_SUPPORTED
  159166. int m;
  159167. if (option != JCOPYOPT_NONE) {
  159168. jpeg_save_markers(srcinfo, JPEG_COM, 0xFFFF);
  159169. }
  159170. if (option == JCOPYOPT_ALL) {
  159171. for (m = 0; m < 16; m++)
  159172. jpeg_save_markers(srcinfo, JPEG_APP0 + m, 0xFFFF);
  159173. }
  159174. #endif /* SAVE_MARKERS_SUPPORTED */
  159175. }
  159176. GLOBAL(void)
  159177. jcopy_markers_execute (j_decompress_ptr srcinfo, j_compress_ptr dstinfo,
  159178. JCOPY_OPTION option)
  159179. {
  159180. jpeg_saved_marker_ptr marker;
  159181. for (marker = srcinfo->marker_list; marker != NULL; marker = marker->next) {
  159182. if (dstinfo->write_JFIF_header &&
  159183. marker->marker == JPEG_APP0 &&
  159184. marker->data_length >= 5 &&
  159185. GETJOCTET(marker->data[0]) == 0x4A &&
  159186. GETJOCTET(marker->data[1]) == 0x46 &&
  159187. GETJOCTET(marker->data[2]) == 0x49 &&
  159188. GETJOCTET(marker->data[3]) == 0x46 &&
  159189. GETJOCTET(marker->data[4]) == 0)
  159190. continue; /* reject duplicate JFIF */
  159191. if (dstinfo->write_Adobe_marker &&
  159192. marker->marker == JPEG_APP0+14 &&
  159193. marker->data_length >= 5 &&
  159194. GETJOCTET(marker->data[0]) == 0x41 &&
  159195. GETJOCTET(marker->data[1]) == 0x64 &&
  159196. GETJOCTET(marker->data[2]) == 0x6F &&
  159197. GETJOCTET(marker->data[3]) == 0x62 &&
  159198. GETJOCTET(marker->data[4]) == 0x65)
  159199. continue; /* reject duplicate Adobe */
  159200. #ifdef NEED_FAR_POINTERS
  159201. {
  159202. unsigned int i;
  159203. jpeg_write_m_header(dstinfo, marker->marker, marker->data_length);
  159204. for (i = 0; i < marker->data_length; i++)
  159205. jpeg_write_m_byte(dstinfo, marker->data[i]);
  159206. }
  159207. #else
  159208. jpeg_write_marker(dstinfo, marker->marker,
  159209. marker->data, marker->data_length);
  159210. #endif
  159211. }
  159212. }
  159213. /*** End of inlined file: transupp.c ***/
  159214. }
  159215. #else
  159216. #define JPEG_INTERNALS
  159217. #undef FAR
  159218. #include <jpeglib.h>
  159219. #endif
  159220. }
  159221. #if JUCE_MSVC
  159222. #pragma warning (pop)
  159223. #endif
  159224. BEGIN_JUCE_NAMESPACE
  159225. using namespace jpeglibNamespace;
  159226. #if ! JUCE_MSVC
  159227. using jpeglibNamespace::boolean;
  159228. #endif
  159229. struct JPEGDecodingFailure {};
  159230. static void fatalErrorHandler (j_common_ptr)
  159231. {
  159232. throw JPEGDecodingFailure();
  159233. }
  159234. static void silentErrorCallback1 (j_common_ptr) {}
  159235. static void silentErrorCallback2 (j_common_ptr, int) {}
  159236. static void silentErrorCallback3 (j_common_ptr, char*) {}
  159237. static void setupSilentErrorHandler (struct jpeg_error_mgr& err)
  159238. {
  159239. zerostruct (err);
  159240. err.error_exit = fatalErrorHandler;
  159241. err.emit_message = silentErrorCallback2;
  159242. err.output_message = silentErrorCallback1;
  159243. err.format_message = silentErrorCallback3;
  159244. err.reset_error_mgr = silentErrorCallback1;
  159245. }
  159246. static void dummyCallback1 (j_decompress_ptr)
  159247. {
  159248. }
  159249. static void jpegSkip (j_decompress_ptr decompStruct, long num)
  159250. {
  159251. decompStruct->src->next_input_byte += num;
  159252. num = jmin (num, (long) decompStruct->src->bytes_in_buffer);
  159253. decompStruct->src->bytes_in_buffer -= num;
  159254. }
  159255. static boolean jpegFill (j_decompress_ptr)
  159256. {
  159257. return 0;
  159258. }
  159259. Image* juce_loadJPEGImageFromStream (InputStream& in)
  159260. {
  159261. MemoryBlock mb;
  159262. in.readIntoMemoryBlock (mb);
  159263. Image* image = 0;
  159264. if (mb.getSize() > 16)
  159265. {
  159266. struct jpeg_decompress_struct jpegDecompStruct;
  159267. struct jpeg_error_mgr jerr;
  159268. setupSilentErrorHandler (jerr);
  159269. jpegDecompStruct.err = &jerr;
  159270. jpeg_create_decompress (&jpegDecompStruct);
  159271. jpegDecompStruct.src = (jpeg_source_mgr*)(jpegDecompStruct.mem->alloc_small)
  159272. ((j_common_ptr)(&jpegDecompStruct), JPOOL_PERMANENT, sizeof (jpeg_source_mgr));
  159273. jpegDecompStruct.src->init_source = dummyCallback1;
  159274. jpegDecompStruct.src->fill_input_buffer = jpegFill;
  159275. jpegDecompStruct.src->skip_input_data = jpegSkip;
  159276. jpegDecompStruct.src->resync_to_restart = jpeg_resync_to_restart;
  159277. jpegDecompStruct.src->term_source = dummyCallback1;
  159278. jpegDecompStruct.src->next_input_byte = (const unsigned char*) mb.getData();
  159279. jpegDecompStruct.src->bytes_in_buffer = mb.getSize();
  159280. try
  159281. {
  159282. jpeg_read_header (&jpegDecompStruct, TRUE);
  159283. jpeg_calc_output_dimensions (&jpegDecompStruct);
  159284. const int width = jpegDecompStruct.output_width;
  159285. const int height = jpegDecompStruct.output_height;
  159286. jpegDecompStruct.out_color_space = JCS_RGB;
  159287. JSAMPARRAY buffer
  159288. = (*jpegDecompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegDecompStruct,
  159289. JPOOL_IMAGE,
  159290. width * 3, 1);
  159291. if (jpeg_start_decompress (&jpegDecompStruct))
  159292. {
  159293. image = Image::createNativeImage (Image::RGB, width, height, false);
  159294. const bool hasAlphaChan = image->hasAlphaChannel();
  159295. const Image::BitmapData destData (*image, 0, 0, width, height, true);
  159296. for (int y = 0; y < height; ++y)
  159297. {
  159298. jpeg_read_scanlines (&jpegDecompStruct, buffer, 1);
  159299. const uint8* src = *buffer;
  159300. uint8* dest = destData.getLinePointer (y);
  159301. if (hasAlphaChan)
  159302. {
  159303. for (int i = width; --i >= 0;)
  159304. {
  159305. ((PixelARGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159306. ((PixelARGB*) dest)->premultiply();
  159307. dest += destData.pixelStride;
  159308. src += 3;
  159309. }
  159310. }
  159311. else
  159312. {
  159313. for (int i = width; --i >= 0;)
  159314. {
  159315. ((PixelRGB*) dest)->setARGB (0xff, src[0], src[1], src[2]);
  159316. dest += destData.pixelStride;
  159317. src += 3;
  159318. }
  159319. }
  159320. }
  159321. jpeg_finish_decompress (&jpegDecompStruct);
  159322. in.setPosition (((char*) jpegDecompStruct.src->next_input_byte) - (char*) mb.getData());
  159323. }
  159324. jpeg_destroy_decompress (&jpegDecompStruct);
  159325. }
  159326. catch (...)
  159327. {}
  159328. }
  159329. return image;
  159330. }
  159331. static const int jpegBufferSize = 512;
  159332. struct JuceJpegDest : public jpeg_destination_mgr
  159333. {
  159334. OutputStream* output;
  159335. char* buffer;
  159336. };
  159337. static void jpegWriteInit (j_compress_ptr)
  159338. {
  159339. }
  159340. static void jpegWriteTerminate (j_compress_ptr cinfo)
  159341. {
  159342. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159343. const size_t numToWrite = jpegBufferSize - dest->free_in_buffer;
  159344. dest->output->write (dest->buffer, (int) numToWrite);
  159345. }
  159346. static boolean jpegWriteFlush (j_compress_ptr cinfo)
  159347. {
  159348. JuceJpegDest* const dest = (JuceJpegDest*) cinfo->dest;
  159349. const int numToWrite = jpegBufferSize;
  159350. dest->next_output_byte = (JOCTET*) dest->buffer;
  159351. dest->free_in_buffer = jpegBufferSize;
  159352. return dest->output->write (dest->buffer, numToWrite);
  159353. }
  159354. bool juce_writeJPEGImageToStream (const Image& image,
  159355. OutputStream& out,
  159356. float quality)
  159357. {
  159358. if (image.hasAlphaChannel())
  159359. {
  159360. // this method could fill the background in white and still save the image..
  159361. jassertfalse
  159362. return true;
  159363. }
  159364. struct jpeg_compress_struct jpegCompStruct;
  159365. struct jpeg_error_mgr jerr;
  159366. setupSilentErrorHandler (jerr);
  159367. jpegCompStruct.err = &jerr;
  159368. jpeg_create_compress (&jpegCompStruct);
  159369. JuceJpegDest dest;
  159370. jpegCompStruct.dest = &dest;
  159371. dest.output = &out;
  159372. HeapBlock <char> tempBuffer (jpegBufferSize);
  159373. dest.buffer = (char*) tempBuffer;
  159374. dest.next_output_byte = (JOCTET*) dest.buffer;
  159375. dest.free_in_buffer = jpegBufferSize;
  159376. dest.init_destination = jpegWriteInit;
  159377. dest.empty_output_buffer = jpegWriteFlush;
  159378. dest.term_destination = jpegWriteTerminate;
  159379. jpegCompStruct.image_width = image.getWidth();
  159380. jpegCompStruct.image_height = image.getHeight();
  159381. jpegCompStruct.input_components = 3;
  159382. jpegCompStruct.in_color_space = JCS_RGB;
  159383. jpegCompStruct.write_JFIF_header = 1;
  159384. jpegCompStruct.X_density = 72;
  159385. jpegCompStruct.Y_density = 72;
  159386. jpeg_set_defaults (&jpegCompStruct);
  159387. jpegCompStruct.dct_method = JDCT_FLOAT;
  159388. jpegCompStruct.optimize_coding = 1;
  159389. // jpegCompStruct.smoothing_factor = 10;
  159390. if (quality < 0.0f)
  159391. quality = 0.85f;
  159392. jpeg_set_quality (&jpegCompStruct, jlimit (0, 100, roundToInt (quality * 100.0f)), TRUE);
  159393. jpeg_start_compress (&jpegCompStruct, TRUE);
  159394. const int strideBytes = jpegCompStruct.image_width * jpegCompStruct.input_components;
  159395. JSAMPARRAY buffer = (*jpegCompStruct.mem->alloc_sarray) ((j_common_ptr) &jpegCompStruct,
  159396. JPOOL_IMAGE,
  159397. strideBytes, 1);
  159398. const Image::BitmapData srcData (image, 0, 0, jpegCompStruct.image_width, jpegCompStruct.image_height);
  159399. while (jpegCompStruct.next_scanline < jpegCompStruct.image_height)
  159400. {
  159401. const uint8* src = srcData.getLinePointer (jpegCompStruct.next_scanline);
  159402. uint8* dst = *buffer;
  159403. for (int i = jpegCompStruct.image_width; --i >= 0;)
  159404. {
  159405. *dst++ = ((const PixelRGB*) src)->getRed();
  159406. *dst++ = ((const PixelRGB*) src)->getGreen();
  159407. *dst++ = ((const PixelRGB*) src)->getBlue();
  159408. src += srcData.pixelStride;
  159409. }
  159410. jpeg_write_scanlines (&jpegCompStruct, buffer, 1);
  159411. }
  159412. jpeg_finish_compress (&jpegCompStruct);
  159413. jpeg_destroy_compress (&jpegCompStruct);
  159414. out.flush();
  159415. return true;
  159416. }
  159417. END_JUCE_NAMESPACE
  159418. /*** End of inlined file: juce_JPEGLoader.cpp ***/
  159419. /*** Start of inlined file: juce_PNGLoader.cpp ***/
  159420. #ifdef _MSC_VER
  159421. #pragma warning (push)
  159422. #pragma warning (disable: 4390 4611)
  159423. #endif
  159424. namespace zlibNamespace
  159425. {
  159426. #if JUCE_INCLUDE_ZLIB_CODE
  159427. #undef OS_CODE
  159428. #undef fdopen
  159429. #undef OS_CODE
  159430. #else
  159431. #include <zlib.h>
  159432. #endif
  159433. }
  159434. namespace pnglibNamespace
  159435. {
  159436. using namespace zlibNamespace;
  159437. #if JUCE_INCLUDE_PNGLIB_CODE
  159438. #if _MSC_VER != 1310
  159439. using ::calloc; // (causes conflict in VS.NET 2003)
  159440. using ::malloc;
  159441. using ::free;
  159442. #endif
  159443. extern "C"
  159444. {
  159445. using ::abs;
  159446. #define PNG_INTERNAL
  159447. #define NO_DUMMY_DECL
  159448. #define PNG_SETJMP_NOT_SUPPORTED
  159449. /*** Start of inlined file: png.h ***/
  159450. #ifndef PNG_H
  159451. #define PNG_H
  159452. #define PNG_LIBPNG_VER_STRING "1.2.21"
  159453. #define PNG_HEADER_VERSION_STRING \
  159454. " libpng version 1.2.21 - October 4, 2007\n"
  159455. #define PNG_LIBPNG_VER_SONUM 0
  159456. #define PNG_LIBPNG_VER_DLLNUM 13
  159457. #define PNG_LIBPNG_VER_MAJOR 1
  159458. #define PNG_LIBPNG_VER_MINOR 2
  159459. #define PNG_LIBPNG_VER_RELEASE 21
  159460. #define PNG_LIBPNG_VER_BUILD 0
  159461. #define PNG_LIBPNG_BUILD_ALPHA 1
  159462. #define PNG_LIBPNG_BUILD_BETA 2
  159463. #define PNG_LIBPNG_BUILD_RC 3
  159464. #define PNG_LIBPNG_BUILD_STABLE 4
  159465. #define PNG_LIBPNG_BUILD_RELEASE_STATUS_MASK 7
  159466. #define PNG_LIBPNG_BUILD_PATCH 8 /* Can be OR'ed with
  159467. PNG_LIBPNG_BUILD_STABLE only */
  159468. #define PNG_LIBPNG_BUILD_PRIVATE 16 /* Cannot be OR'ed with
  159469. PNG_LIBPNG_BUILD_SPECIAL */
  159470. #define PNG_LIBPNG_BUILD_SPECIAL 32 /* Cannot be OR'ed with
  159471. PNG_LIBPNG_BUILD_PRIVATE */
  159472. #define PNG_LIBPNG_BUILD_BASE_TYPE PNG_LIBPNG_BUILD_STABLE
  159473. #define PNG_LIBPNG_VER 10221 /* 1.2.21 */
  159474. #ifndef PNG_VERSION_INFO_ONLY
  159475. #endif
  159476. /*** Start of inlined file: pngconf.h ***/
  159477. #ifndef PNGCONF_H
  159478. #define PNGCONF_H
  159479. #define PNG_1_2_X
  159480. // These are some Juce config settings that should remove any unnecessary code bloat..
  159481. #define PNG_NO_STDIO 1
  159482. #define PNG_DEBUG 0
  159483. #define PNG_NO_WARNINGS 1
  159484. #define PNG_NO_ERROR_TEXT 1
  159485. #define PNG_NO_ERROR_NUMBERS 1
  159486. #define PNG_NO_USER_MEM 1
  159487. #define PNG_NO_READ_iCCP 1
  159488. #define PNG_NO_READ_UNKNOWN_CHUNKS 1
  159489. #define PNG_NO_READ_USER_CHUNKS 1
  159490. #define PNG_NO_READ_iTXt 1
  159491. #define PNG_NO_READ_sCAL 1
  159492. #define PNG_NO_READ_sPLT 1
  159493. #define png_error(a, b) png_err(a)
  159494. #define png_warning(a, b)
  159495. #define png_chunk_error(a, b) png_err(a)
  159496. #define png_chunk_warning(a, b)
  159497. #ifdef PNG_USER_CONFIG
  159498. # ifndef PNG_USER_PRIVATEBUILD
  159499. # define PNG_USER_PRIVATEBUILD
  159500. # endif
  159501. #include "pngusr.h"
  159502. #endif
  159503. #ifdef PNG_CONFIGURE_LIBPNG
  159504. #ifdef HAVE_CONFIG_H
  159505. #include "config.h"
  159506. #endif
  159507. #endif
  159508. #ifdef __STDC__
  159509. #ifdef SPECIALBUILD
  159510. # pragma message("PNG_LIBPNG_SPECIALBUILD (and deprecated SPECIALBUILD)\
  159511. are now LIBPNG reserved macros. Use PNG_USER_PRIVATEBUILD instead.")
  159512. #endif
  159513. #ifdef PRIVATEBUILD
  159514. # pragma message("PRIVATEBUILD is deprecated.\
  159515. Use PNG_USER_PRIVATEBUILD instead.")
  159516. # define PNG_USER_PRIVATEBUILD PRIVATEBUILD
  159517. #endif
  159518. #endif /* __STDC__ */
  159519. #ifndef PNG_VERSION_INFO_ONLY
  159520. # define PNG_WARN_UNINITIALIZED_ROW 1
  159521. #ifndef PNG_ZBUF_SIZE
  159522. # define PNG_ZBUF_SIZE 8192
  159523. #endif
  159524. #ifndef PNG_NO_READ_SUPPORTED
  159525. # define PNG_READ_SUPPORTED
  159526. #endif
  159527. #ifndef PNG_NO_WRITE_SUPPORTED
  159528. # define PNG_WRITE_SUPPORTED
  159529. #endif
  159530. #if !defined(PNG_1_0_X) && !defined(PNG_NO_MNG_FEATURES)
  159531. # ifndef PNG_MNG_FEATURES_SUPPORTED
  159532. # define PNG_MNG_FEATURES_SUPPORTED
  159533. # endif
  159534. #endif
  159535. #ifndef PNG_NO_FLOATING_POINT_SUPPORTED
  159536. # ifndef PNG_FLOATING_POINT_SUPPORTED
  159537. # define PNG_FLOATING_POINT_SUPPORTED
  159538. # endif
  159539. #endif
  159540. #if defined(MAXSEG_64K) && !defined(PNG_MAX_MALLOC_64K)
  159541. # define PNG_MAX_MALLOC_64K
  159542. #endif
  159543. #if defined(__CYGWIN__)
  159544. # if defined(ALL_STATIC)
  159545. # if defined(PNG_BUILD_DLL)
  159546. # undef PNG_BUILD_DLL
  159547. # endif
  159548. # if defined(PNG_USE_DLL)
  159549. # undef PNG_USE_DLL
  159550. # endif
  159551. # if defined(PNG_DLL)
  159552. # undef PNG_DLL
  159553. # endif
  159554. # if !defined(PNG_STATIC)
  159555. # define PNG_STATIC
  159556. # endif
  159557. # else
  159558. # if defined (PNG_BUILD_DLL)
  159559. # if defined(PNG_STATIC)
  159560. # undef PNG_STATIC
  159561. # endif
  159562. # if defined(PNG_USE_DLL)
  159563. # undef PNG_USE_DLL
  159564. # endif
  159565. # if !defined(PNG_DLL)
  159566. # define PNG_DLL
  159567. # endif
  159568. # else
  159569. # if defined(PNG_STATIC)
  159570. # if defined(PNG_USE_DLL)
  159571. # undef PNG_USE_DLL
  159572. # endif
  159573. # if defined(PNG_DLL)
  159574. # undef PNG_DLL
  159575. # endif
  159576. # else
  159577. # if !defined(PNG_USE_DLL)
  159578. # define PNG_USE_DLL
  159579. # endif
  159580. # if !defined(PNG_DLL)
  159581. # define PNG_DLL
  159582. # endif
  159583. # endif
  159584. # endif
  159585. # endif
  159586. #endif
  159587. #if defined(_WIN32_WCE)
  159588. # include <windows.h>
  159589. # define PNG_NO_CONSOLE_IO
  159590. # ifdef PNG_DEBUG
  159591. # undef PNG_DEBUG
  159592. # endif
  159593. #endif
  159594. #ifdef PNG_BUILD_DLL
  159595. # ifndef PNG_CONSOLE_IO_SUPPORTED
  159596. # ifndef PNG_NO_CONSOLE_IO
  159597. # define PNG_NO_CONSOLE_IO
  159598. # endif
  159599. # endif
  159600. #endif
  159601. # ifdef PNG_NO_STDIO
  159602. # ifndef PNG_NO_CONSOLE_IO
  159603. # define PNG_NO_CONSOLE_IO
  159604. # endif
  159605. # ifdef PNG_DEBUG
  159606. # if (PNG_DEBUG > 0)
  159607. # include <stdio.h>
  159608. # endif
  159609. # endif
  159610. # else
  159611. # if !defined(_WIN32_WCE)
  159612. # include <stdio.h>
  159613. # endif
  159614. # endif
  159615. #ifndef PNGARG
  159616. #ifdef OF /* zlib prototype munger */
  159617. # define PNGARG(arglist) OF(arglist)
  159618. #else
  159619. #ifdef _NO_PROTO
  159620. # define PNGARG(arglist) ()
  159621. # ifndef PNG_TYPECAST_NULL
  159622. # define PNG_TYPECAST_NULL
  159623. # endif
  159624. #else
  159625. # define PNGARG(arglist) arglist
  159626. #endif /* _NO_PROTO */
  159627. #endif /* OF */
  159628. #endif /* PNGARG */
  159629. #ifndef MACOS
  159630. # if (defined(__MWERKS__) && defined(macintosh)) || defined(applec) || \
  159631. defined(THINK_C) || defined(__SC__) || defined(TARGET_OS_MAC)
  159632. # define MACOS
  159633. # endif
  159634. #endif
  159635. #if !defined(MACOS) && !defined(RISCOS) && !defined(_WIN32_WCE)
  159636. # include <sys/types.h>
  159637. #endif
  159638. #if !defined(PNG_SETJMP_NOT_SUPPORTED) && !defined(PNG_NO_SETJMP_SUPPORTED)
  159639. # define PNG_SETJMP_SUPPORTED
  159640. #endif
  159641. #ifdef PNG_SETJMP_SUPPORTED
  159642. # ifdef __linux__
  159643. # ifdef _BSD_SOURCE
  159644. # define PNG_SAVE_BSD_SOURCE
  159645. # undef _BSD_SOURCE
  159646. # endif
  159647. # ifdef _SETJMP_H
  159648. __png.h__ already includes setjmp.h;
  159649. __dont__ include it again.;
  159650. # endif
  159651. # endif /* __linux__ */
  159652. # include <setjmp.h>
  159653. # ifdef __linux__
  159654. # ifdef PNG_SAVE_BSD_SOURCE
  159655. # define _BSD_SOURCE
  159656. # undef PNG_SAVE_BSD_SOURCE
  159657. # endif
  159658. # endif /* __linux__ */
  159659. #endif /* PNG_SETJMP_SUPPORTED */
  159660. #ifdef BSD
  159661. #if ! JUCE_MAC
  159662. # include <strings.h>
  159663. #endif
  159664. #else
  159665. # include <string.h>
  159666. #endif
  159667. #ifdef PNG_INTERNAL
  159668. #include <stdlib.h>
  159669. #define PNG_EXTERN
  159670. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  159671. # if defined(MACOS)
  159672. # if !defined(__MATH_H__) && !defined(__MATH_H) && !defined(__cmath__)
  159673. # include <fp.h>
  159674. # endif
  159675. # else
  159676. # include <math.h>
  159677. # endif
  159678. # if defined(_AMIGA) && defined(__SASC) && defined(_M68881)
  159679. # include <m68881.h>
  159680. # endif
  159681. #endif
  159682. #if (defined(__MWERKS__) && defined(WIN32)) || defined(__STDC__)
  159683. # define PNG_ALWAYS_EXTERN
  159684. #endif
  159685. #if defined(__TURBOC__) && defined(__MSDOS__)
  159686. # include <mem.h>
  159687. # include <alloc.h>
  159688. #endif
  159689. #if defined(_MSC_VER) && (defined(WIN32) || defined(_Windows) || \
  159690. defined(_WINDOWS) || defined(_WIN32) || defined(__WIN32__))
  159691. # include <malloc.h>
  159692. #endif
  159693. #ifndef PNG_DITHER_RED_BITS
  159694. # define PNG_DITHER_RED_BITS 5
  159695. #endif
  159696. #ifndef PNG_DITHER_GREEN_BITS
  159697. # define PNG_DITHER_GREEN_BITS 5
  159698. #endif
  159699. #ifndef PNG_DITHER_BLUE_BITS
  159700. # define PNG_DITHER_BLUE_BITS 5
  159701. #endif
  159702. #ifndef PNG_MAX_GAMMA_8
  159703. # define PNG_MAX_GAMMA_8 11
  159704. #endif
  159705. #ifndef PNG_GAMMA_THRESHOLD
  159706. # define PNG_GAMMA_THRESHOLD 0.05
  159707. #endif
  159708. #endif /* PNG_INTERNAL */
  159709. #ifndef PNG_NO_CONST
  159710. # define PNG_CONST const
  159711. #else
  159712. # define PNG_CONST
  159713. #endif
  159714. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159715. # ifndef PNG_NO_iTXt_SUPPORTED
  159716. # define PNG_NO_iTXt_SUPPORTED
  159717. # endif
  159718. # ifndef PNG_NO_READ_iTXt
  159719. # define PNG_NO_READ_iTXt
  159720. # endif
  159721. # ifndef PNG_NO_WRITE_iTXt
  159722. # define PNG_NO_WRITE_iTXt
  159723. # endif
  159724. #endif
  159725. #if !defined(PNG_NO_iTXt_SUPPORTED)
  159726. # if !defined(PNG_READ_iTXt_SUPPORTED) && !defined(PNG_NO_READ_iTXt)
  159727. # define PNG_READ_iTXt
  159728. # endif
  159729. # if !defined(PNG_WRITE_iTXt_SUPPORTED) && !defined(PNG_NO_WRITE_iTXt)
  159730. # define PNG_WRITE_iTXt
  159731. # endif
  159732. #endif
  159733. #ifdef PNG_LEGACY_SUPPORTED
  159734. # define PNG_NO_FREE_ME
  159735. # define PNG_NO_READ_UNKNOWN_CHUNKS
  159736. # define PNG_NO_WRITE_UNKNOWN_CHUNKS
  159737. # define PNG_NO_READ_USER_CHUNKS
  159738. # define PNG_NO_READ_iCCP
  159739. # define PNG_NO_WRITE_iCCP
  159740. # define PNG_NO_READ_iTXt
  159741. # define PNG_NO_WRITE_iTXt
  159742. # define PNG_NO_READ_sCAL
  159743. # define PNG_NO_WRITE_sCAL
  159744. # define PNG_NO_READ_sPLT
  159745. # define PNG_NO_WRITE_sPLT
  159746. # define PNG_NO_INFO_IMAGE
  159747. # define PNG_NO_READ_RGB_TO_GRAY
  159748. # define PNG_NO_READ_USER_TRANSFORM
  159749. # define PNG_NO_WRITE_USER_TRANSFORM
  159750. # define PNG_NO_USER_MEM
  159751. # define PNG_NO_READ_EMPTY_PLTE
  159752. # define PNG_NO_MNG_FEATURES
  159753. # define PNG_NO_FIXED_POINT_SUPPORTED
  159754. #endif
  159755. #if !defined(PNG_FLOATING_POINT_SUPPORTED) || \
  159756. !defined(PNG_NO_FIXED_POINT_SUPPORTED)
  159757. # define PNG_FIXED_POINT_SUPPORTED
  159758. #endif
  159759. #ifndef PNG_NO_FREE_ME
  159760. # define PNG_FREE_ME_SUPPORTED
  159761. #endif
  159762. #if defined(PNG_READ_SUPPORTED)
  159763. #if !defined(PNG_READ_TRANSFORMS_NOT_SUPPORTED) && \
  159764. !defined(PNG_NO_READ_TRANSFORMS)
  159765. # define PNG_READ_TRANSFORMS_SUPPORTED
  159766. #endif
  159767. #ifdef PNG_READ_TRANSFORMS_SUPPORTED
  159768. # ifndef PNG_NO_READ_EXPAND
  159769. # define PNG_READ_EXPAND_SUPPORTED
  159770. # endif
  159771. # ifndef PNG_NO_READ_SHIFT
  159772. # define PNG_READ_SHIFT_SUPPORTED
  159773. # endif
  159774. # ifndef PNG_NO_READ_PACK
  159775. # define PNG_READ_PACK_SUPPORTED
  159776. # endif
  159777. # ifndef PNG_NO_READ_BGR
  159778. # define PNG_READ_BGR_SUPPORTED
  159779. # endif
  159780. # ifndef PNG_NO_READ_SWAP
  159781. # define PNG_READ_SWAP_SUPPORTED
  159782. # endif
  159783. # ifndef PNG_NO_READ_PACKSWAP
  159784. # define PNG_READ_PACKSWAP_SUPPORTED
  159785. # endif
  159786. # ifndef PNG_NO_READ_INVERT
  159787. # define PNG_READ_INVERT_SUPPORTED
  159788. # endif
  159789. # ifndef PNG_NO_READ_DITHER
  159790. # define PNG_READ_DITHER_SUPPORTED
  159791. # endif
  159792. # ifndef PNG_NO_READ_BACKGROUND
  159793. # define PNG_READ_BACKGROUND_SUPPORTED
  159794. # endif
  159795. # ifndef PNG_NO_READ_16_TO_8
  159796. # define PNG_READ_16_TO_8_SUPPORTED
  159797. # endif
  159798. # ifndef PNG_NO_READ_FILLER
  159799. # define PNG_READ_FILLER_SUPPORTED
  159800. # endif
  159801. # ifndef PNG_NO_READ_GAMMA
  159802. # define PNG_READ_GAMMA_SUPPORTED
  159803. # endif
  159804. # ifndef PNG_NO_READ_GRAY_TO_RGB
  159805. # define PNG_READ_GRAY_TO_RGB_SUPPORTED
  159806. # endif
  159807. # ifndef PNG_NO_READ_SWAP_ALPHA
  159808. # define PNG_READ_SWAP_ALPHA_SUPPORTED
  159809. # endif
  159810. # ifndef PNG_NO_READ_INVERT_ALPHA
  159811. # define PNG_READ_INVERT_ALPHA_SUPPORTED
  159812. # endif
  159813. # ifndef PNG_NO_READ_STRIP_ALPHA
  159814. # define PNG_READ_STRIP_ALPHA_SUPPORTED
  159815. # endif
  159816. # ifndef PNG_NO_READ_USER_TRANSFORM
  159817. # define PNG_READ_USER_TRANSFORM_SUPPORTED
  159818. # endif
  159819. # ifndef PNG_NO_READ_RGB_TO_GRAY
  159820. # define PNG_READ_RGB_TO_GRAY_SUPPORTED
  159821. # endif
  159822. #endif /* PNG_READ_TRANSFORMS_SUPPORTED */
  159823. #if !defined(PNG_NO_PROGRESSIVE_READ) && \
  159824. !defined(PNG_PROGRESSIVE_READ_SUPPORTED) /* if you don't do progressive */
  159825. # define PNG_PROGRESSIVE_READ_SUPPORTED /* reading. This is not talking */
  159826. #endif /* about interlacing capability! You'll */
  159827. #define PNG_READ_INTERLACING_SUPPORTED /* required in PNG-compliant decoders */
  159828. #ifndef PNG_NO_READ_COMPOSITE_NODIV
  159829. # ifndef PNG_NO_READ_COMPOSITED_NODIV /* libpng-1.0.x misspelling */
  159830. # define PNG_READ_COMPOSITE_NODIV_SUPPORTED /* well tested on Intel, SGI */
  159831. # endif
  159832. #endif
  159833. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159834. #ifndef PNG_NO_READ_EMPTY_PLTE
  159835. # define PNG_READ_EMPTY_PLTE_SUPPORTED
  159836. #endif
  159837. #endif
  159838. #endif /* PNG_READ_SUPPORTED */
  159839. #if defined(PNG_WRITE_SUPPORTED)
  159840. # if !defined(PNG_WRITE_TRANSFORMS_NOT_SUPPORTED) && \
  159841. !defined(PNG_NO_WRITE_TRANSFORMS)
  159842. # define PNG_WRITE_TRANSFORMS_SUPPORTED
  159843. #endif
  159844. #ifdef PNG_WRITE_TRANSFORMS_SUPPORTED
  159845. # ifndef PNG_NO_WRITE_SHIFT
  159846. # define PNG_WRITE_SHIFT_SUPPORTED
  159847. # endif
  159848. # ifndef PNG_NO_WRITE_PACK
  159849. # define PNG_WRITE_PACK_SUPPORTED
  159850. # endif
  159851. # ifndef PNG_NO_WRITE_BGR
  159852. # define PNG_WRITE_BGR_SUPPORTED
  159853. # endif
  159854. # ifndef PNG_NO_WRITE_SWAP
  159855. # define PNG_WRITE_SWAP_SUPPORTED
  159856. # endif
  159857. # ifndef PNG_NO_WRITE_PACKSWAP
  159858. # define PNG_WRITE_PACKSWAP_SUPPORTED
  159859. # endif
  159860. # ifndef PNG_NO_WRITE_INVERT
  159861. # define PNG_WRITE_INVERT_SUPPORTED
  159862. # endif
  159863. # ifndef PNG_NO_WRITE_FILLER
  159864. # define PNG_WRITE_FILLER_SUPPORTED /* same as WRITE_STRIP_ALPHA */
  159865. # endif
  159866. # ifndef PNG_NO_WRITE_SWAP_ALPHA
  159867. # define PNG_WRITE_SWAP_ALPHA_SUPPORTED
  159868. # endif
  159869. # ifndef PNG_NO_WRITE_INVERT_ALPHA
  159870. # define PNG_WRITE_INVERT_ALPHA_SUPPORTED
  159871. # endif
  159872. # ifndef PNG_NO_WRITE_USER_TRANSFORM
  159873. # define PNG_WRITE_USER_TRANSFORM_SUPPORTED
  159874. # endif
  159875. #endif /* PNG_WRITE_TRANSFORMS_SUPPORTED */
  159876. #if !defined(PNG_NO_WRITE_INTERLACING_SUPPORTED) && \
  159877. !defined(PNG_WRITE_INTERLACING_SUPPORTED)
  159878. #define PNG_WRITE_INTERLACING_SUPPORTED /* not required for PNG-compliant
  159879. encoders, but can cause trouble
  159880. if left undefined */
  159881. #endif
  159882. #if !defined(PNG_NO_WRITE_WEIGHTED_FILTER) && \
  159883. !defined(PNG_WRITE_WEIGHTED_FILTER) && \
  159884. defined(PNG_FLOATING_POINT_SUPPORTED)
  159885. # define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED
  159886. #endif
  159887. #ifndef PNG_NO_WRITE_FLUSH
  159888. # define PNG_WRITE_FLUSH_SUPPORTED
  159889. #endif
  159890. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  159891. #ifndef PNG_NO_WRITE_EMPTY_PLTE
  159892. # define PNG_WRITE_EMPTY_PLTE_SUPPORTED
  159893. #endif
  159894. #endif
  159895. #endif /* PNG_WRITE_SUPPORTED */
  159896. #ifndef PNG_1_0_X
  159897. # ifndef PNG_NO_ERROR_NUMBERS
  159898. # define PNG_ERROR_NUMBERS_SUPPORTED
  159899. # endif
  159900. #endif /* PNG_1_0_X */
  159901. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  159902. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  159903. # ifndef PNG_NO_USER_TRANSFORM_PTR
  159904. # define PNG_USER_TRANSFORM_PTR_SUPPORTED
  159905. # endif
  159906. #endif
  159907. #ifndef PNG_NO_STDIO
  159908. # define PNG_TIME_RFC1123_SUPPORTED
  159909. #endif
  159910. #if !defined(PNG_NO_EASY_ACCESS) && !defined(PNG_EASY_ACCESS_SUPPORTED)
  159911. # define PNG_EASY_ACCESS_SUPPORTED
  159912. #endif
  159913. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_OPTIMIZED_CODE)
  159914. # ifndef PNG_OPTIMIZED_CODE_SUPPORTED
  159915. # define PNG_OPTIMIZED_CODE_SUPPORTED
  159916. # endif
  159917. #endif
  159918. #if defined(PNG_READ_SUPPORTED) && !defined(PNG_NO_ASSEMBLER_CODE)
  159919. # ifndef PNG_ASSEMBLER_CODE_SUPPORTED
  159920. # define PNG_ASSEMBLER_CODE_SUPPORTED
  159921. # endif
  159922. # if defined(__GNUC__) && defined(__x86_64__) && (__GNUC__ < 4)
  159923. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159924. # define PNG_NO_MMX_CODE
  159925. # endif
  159926. # endif
  159927. # if defined(__APPLE__)
  159928. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159929. # define PNG_NO_MMX_CODE
  159930. # endif
  159931. # endif
  159932. # if (defined(__MWERKS__) && ((__MWERKS__ < 0x0900) || macintosh))
  159933. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159934. # define PNG_NO_MMX_CODE
  159935. # endif
  159936. # endif
  159937. # if !defined(PNG_MMX_CODE_SUPPORTED) && !defined(PNG_NO_MMX_CODE)
  159938. # define PNG_MMX_CODE_SUPPORTED
  159939. # endif
  159940. #endif
  159941. #if !defined(PNG_1_0_X)
  159942. #if !defined(PNG_NO_USER_MEM) && !defined(PNG_USER_MEM_SUPPORTED)
  159943. # define PNG_USER_MEM_SUPPORTED
  159944. #endif
  159945. #endif /* PNG_1_0_X */
  159946. #if !defined(PNG_1_0_X)
  159947. #ifndef PNG_SET_USER_LIMITS_SUPPORTED
  159948. #if !defined(PNG_NO_SET_USER_LIMITS) && !defined(PNG_SET_USER_LIMITS_SUPPORTED)
  159949. # define PNG_SET_USER_LIMITS_SUPPORTED
  159950. #endif
  159951. #endif
  159952. #endif /* PNG_1_0_X */
  159953. #ifndef PNG_USER_WIDTH_MAX
  159954. # define PNG_USER_WIDTH_MAX 1000000L
  159955. #endif
  159956. #ifndef PNG_USER_HEIGHT_MAX
  159957. # define PNG_USER_HEIGHT_MAX 1000000L
  159958. #endif
  159959. #if defined(PNG_READ_SUPPORTED) && \
  159960. !defined(PNG_READ_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159961. !defined(PNG_NO_READ_ANCILLARY_CHUNKS)
  159962. # define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159963. #endif
  159964. #if defined(PNG_WRITE_SUPPORTED) && \
  159965. !defined(PNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED) && \
  159966. !defined(PNG_NO_WRITE_ANCILLARY_CHUNKS)
  159967. # define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  159968. #endif
  159969. #ifdef PNG_READ_ANCILLARY_CHUNKS_SUPPORTED
  159970. #ifdef PNG_NO_READ_TEXT
  159971. # define PNG_NO_READ_iTXt
  159972. # define PNG_NO_READ_tEXt
  159973. # define PNG_NO_READ_zTXt
  159974. #endif
  159975. #ifndef PNG_NO_READ_bKGD
  159976. # define PNG_READ_bKGD_SUPPORTED
  159977. # define PNG_bKGD_SUPPORTED
  159978. #endif
  159979. #ifndef PNG_NO_READ_cHRM
  159980. # define PNG_READ_cHRM_SUPPORTED
  159981. # define PNG_cHRM_SUPPORTED
  159982. #endif
  159983. #ifndef PNG_NO_READ_gAMA
  159984. # define PNG_READ_gAMA_SUPPORTED
  159985. # define PNG_gAMA_SUPPORTED
  159986. #endif
  159987. #ifndef PNG_NO_READ_hIST
  159988. # define PNG_READ_hIST_SUPPORTED
  159989. # define PNG_hIST_SUPPORTED
  159990. #endif
  159991. #ifndef PNG_NO_READ_iCCP
  159992. # define PNG_READ_iCCP_SUPPORTED
  159993. # define PNG_iCCP_SUPPORTED
  159994. #endif
  159995. #ifndef PNG_NO_READ_iTXt
  159996. # ifndef PNG_READ_iTXt_SUPPORTED
  159997. # define PNG_READ_iTXt_SUPPORTED
  159998. # endif
  159999. # ifndef PNG_iTXt_SUPPORTED
  160000. # define PNG_iTXt_SUPPORTED
  160001. # endif
  160002. #endif
  160003. #ifndef PNG_NO_READ_oFFs
  160004. # define PNG_READ_oFFs_SUPPORTED
  160005. # define PNG_oFFs_SUPPORTED
  160006. #endif
  160007. #ifndef PNG_NO_READ_pCAL
  160008. # define PNG_READ_pCAL_SUPPORTED
  160009. # define PNG_pCAL_SUPPORTED
  160010. #endif
  160011. #ifndef PNG_NO_READ_sCAL
  160012. # define PNG_READ_sCAL_SUPPORTED
  160013. # define PNG_sCAL_SUPPORTED
  160014. #endif
  160015. #ifndef PNG_NO_READ_pHYs
  160016. # define PNG_READ_pHYs_SUPPORTED
  160017. # define PNG_pHYs_SUPPORTED
  160018. #endif
  160019. #ifndef PNG_NO_READ_sBIT
  160020. # define PNG_READ_sBIT_SUPPORTED
  160021. # define PNG_sBIT_SUPPORTED
  160022. #endif
  160023. #ifndef PNG_NO_READ_sPLT
  160024. # define PNG_READ_sPLT_SUPPORTED
  160025. # define PNG_sPLT_SUPPORTED
  160026. #endif
  160027. #ifndef PNG_NO_READ_sRGB
  160028. # define PNG_READ_sRGB_SUPPORTED
  160029. # define PNG_sRGB_SUPPORTED
  160030. #endif
  160031. #ifndef PNG_NO_READ_tEXt
  160032. # define PNG_READ_tEXt_SUPPORTED
  160033. # define PNG_tEXt_SUPPORTED
  160034. #endif
  160035. #ifndef PNG_NO_READ_tIME
  160036. # define PNG_READ_tIME_SUPPORTED
  160037. # define PNG_tIME_SUPPORTED
  160038. #endif
  160039. #ifndef PNG_NO_READ_tRNS
  160040. # define PNG_READ_tRNS_SUPPORTED
  160041. # define PNG_tRNS_SUPPORTED
  160042. #endif
  160043. #ifndef PNG_NO_READ_zTXt
  160044. # define PNG_READ_zTXt_SUPPORTED
  160045. # define PNG_zTXt_SUPPORTED
  160046. #endif
  160047. #ifndef PNG_NO_READ_UNKNOWN_CHUNKS
  160048. # define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED
  160049. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  160050. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  160051. # endif
  160052. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  160053. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160054. # endif
  160055. #endif
  160056. #if !defined(PNG_NO_READ_USER_CHUNKS) && \
  160057. defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  160058. # define PNG_READ_USER_CHUNKS_SUPPORTED
  160059. # define PNG_USER_CHUNKS_SUPPORTED
  160060. # ifdef PNG_NO_READ_UNKNOWN_CHUNKS
  160061. # undef PNG_NO_READ_UNKNOWN_CHUNKS
  160062. # endif
  160063. # ifdef PNG_NO_HANDLE_AS_UNKNOWN
  160064. # undef PNG_NO_HANDLE_AS_UNKNOWN
  160065. # endif
  160066. #endif
  160067. #ifndef PNG_NO_READ_OPT_PLTE
  160068. # define PNG_READ_OPT_PLTE_SUPPORTED /* only affects support of the */
  160069. #endif /* optional PLTE chunk in RGB and RGBA images */
  160070. #if defined(PNG_READ_iTXt_SUPPORTED) || defined(PNG_READ_tEXt_SUPPORTED) || \
  160071. defined(PNG_READ_zTXt_SUPPORTED)
  160072. # define PNG_READ_TEXT_SUPPORTED
  160073. # define PNG_TEXT_SUPPORTED
  160074. #endif
  160075. #endif /* PNG_READ_ANCILLARY_CHUNKS_SUPPORTED */
  160076. #ifdef PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED
  160077. #ifdef PNG_NO_WRITE_TEXT
  160078. # define PNG_NO_WRITE_iTXt
  160079. # define PNG_NO_WRITE_tEXt
  160080. # define PNG_NO_WRITE_zTXt
  160081. #endif
  160082. #ifndef PNG_NO_WRITE_bKGD
  160083. # define PNG_WRITE_bKGD_SUPPORTED
  160084. # ifndef PNG_bKGD_SUPPORTED
  160085. # define PNG_bKGD_SUPPORTED
  160086. # endif
  160087. #endif
  160088. #ifndef PNG_NO_WRITE_cHRM
  160089. # define PNG_WRITE_cHRM_SUPPORTED
  160090. # ifndef PNG_cHRM_SUPPORTED
  160091. # define PNG_cHRM_SUPPORTED
  160092. # endif
  160093. #endif
  160094. #ifndef PNG_NO_WRITE_gAMA
  160095. # define PNG_WRITE_gAMA_SUPPORTED
  160096. # ifndef PNG_gAMA_SUPPORTED
  160097. # define PNG_gAMA_SUPPORTED
  160098. # endif
  160099. #endif
  160100. #ifndef PNG_NO_WRITE_hIST
  160101. # define PNG_WRITE_hIST_SUPPORTED
  160102. # ifndef PNG_hIST_SUPPORTED
  160103. # define PNG_hIST_SUPPORTED
  160104. # endif
  160105. #endif
  160106. #ifndef PNG_NO_WRITE_iCCP
  160107. # define PNG_WRITE_iCCP_SUPPORTED
  160108. # ifndef PNG_iCCP_SUPPORTED
  160109. # define PNG_iCCP_SUPPORTED
  160110. # endif
  160111. #endif
  160112. #ifndef PNG_NO_WRITE_iTXt
  160113. # ifndef PNG_WRITE_iTXt_SUPPORTED
  160114. # define PNG_WRITE_iTXt_SUPPORTED
  160115. # endif
  160116. # ifndef PNG_iTXt_SUPPORTED
  160117. # define PNG_iTXt_SUPPORTED
  160118. # endif
  160119. #endif
  160120. #ifndef PNG_NO_WRITE_oFFs
  160121. # define PNG_WRITE_oFFs_SUPPORTED
  160122. # ifndef PNG_oFFs_SUPPORTED
  160123. # define PNG_oFFs_SUPPORTED
  160124. # endif
  160125. #endif
  160126. #ifndef PNG_NO_WRITE_pCAL
  160127. # define PNG_WRITE_pCAL_SUPPORTED
  160128. # ifndef PNG_pCAL_SUPPORTED
  160129. # define PNG_pCAL_SUPPORTED
  160130. # endif
  160131. #endif
  160132. #ifndef PNG_NO_WRITE_sCAL
  160133. # define PNG_WRITE_sCAL_SUPPORTED
  160134. # ifndef PNG_sCAL_SUPPORTED
  160135. # define PNG_sCAL_SUPPORTED
  160136. # endif
  160137. #endif
  160138. #ifndef PNG_NO_WRITE_pHYs
  160139. # define PNG_WRITE_pHYs_SUPPORTED
  160140. # ifndef PNG_pHYs_SUPPORTED
  160141. # define PNG_pHYs_SUPPORTED
  160142. # endif
  160143. #endif
  160144. #ifndef PNG_NO_WRITE_sBIT
  160145. # define PNG_WRITE_sBIT_SUPPORTED
  160146. # ifndef PNG_sBIT_SUPPORTED
  160147. # define PNG_sBIT_SUPPORTED
  160148. # endif
  160149. #endif
  160150. #ifndef PNG_NO_WRITE_sPLT
  160151. # define PNG_WRITE_sPLT_SUPPORTED
  160152. # ifndef PNG_sPLT_SUPPORTED
  160153. # define PNG_sPLT_SUPPORTED
  160154. # endif
  160155. #endif
  160156. #ifndef PNG_NO_WRITE_sRGB
  160157. # define PNG_WRITE_sRGB_SUPPORTED
  160158. # ifndef PNG_sRGB_SUPPORTED
  160159. # define PNG_sRGB_SUPPORTED
  160160. # endif
  160161. #endif
  160162. #ifndef PNG_NO_WRITE_tEXt
  160163. # define PNG_WRITE_tEXt_SUPPORTED
  160164. # ifndef PNG_tEXt_SUPPORTED
  160165. # define PNG_tEXt_SUPPORTED
  160166. # endif
  160167. #endif
  160168. #ifndef PNG_NO_WRITE_tIME
  160169. # define PNG_WRITE_tIME_SUPPORTED
  160170. # ifndef PNG_tIME_SUPPORTED
  160171. # define PNG_tIME_SUPPORTED
  160172. # endif
  160173. #endif
  160174. #ifndef PNG_NO_WRITE_tRNS
  160175. # define PNG_WRITE_tRNS_SUPPORTED
  160176. # ifndef PNG_tRNS_SUPPORTED
  160177. # define PNG_tRNS_SUPPORTED
  160178. # endif
  160179. #endif
  160180. #ifndef PNG_NO_WRITE_zTXt
  160181. # define PNG_WRITE_zTXt_SUPPORTED
  160182. # ifndef PNG_zTXt_SUPPORTED
  160183. # define PNG_zTXt_SUPPORTED
  160184. # endif
  160185. #endif
  160186. #ifndef PNG_NO_WRITE_UNKNOWN_CHUNKS
  160187. # define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED
  160188. # ifndef PNG_UNKNOWN_CHUNKS_SUPPORTED
  160189. # define PNG_UNKNOWN_CHUNKS_SUPPORTED
  160190. # endif
  160191. # ifndef PNG_NO_HANDLE_AS_UNKNOWN
  160192. # ifndef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160193. # define PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  160194. # endif
  160195. # endif
  160196. #endif
  160197. #if defined(PNG_WRITE_iTXt_SUPPORTED) || defined(PNG_WRITE_tEXt_SUPPORTED) || \
  160198. defined(PNG_WRITE_zTXt_SUPPORTED)
  160199. # define PNG_WRITE_TEXT_SUPPORTED
  160200. # ifndef PNG_TEXT_SUPPORTED
  160201. # define PNG_TEXT_SUPPORTED
  160202. # endif
  160203. #endif
  160204. #endif /* PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED */
  160205. #ifndef PNG_NO_INFO_IMAGE
  160206. # define PNG_INFO_IMAGE_SUPPORTED
  160207. #endif
  160208. #if defined(PNG_tIME_SUPPORTED)
  160209. # if !defined(_WIN32_WCE)
  160210. # include <time.h>
  160211. # endif
  160212. #endif
  160213. typedef unsigned long png_uint_32;
  160214. typedef long png_int_32;
  160215. typedef unsigned short png_uint_16;
  160216. typedef short png_int_16;
  160217. typedef unsigned char png_byte;
  160218. #ifdef PNG_SIZE_T
  160219. typedef PNG_SIZE_T png_size_t;
  160220. # define png_sizeof(x) png_convert_size(sizeof (x))
  160221. #else
  160222. typedef size_t png_size_t;
  160223. # define png_sizeof(x) sizeof (x)
  160224. #endif
  160225. #ifdef __BORLANDC__
  160226. # if defined(__LARGE__) || defined(__HUGE__) || defined(__COMPACT__)
  160227. # define LDATA 1
  160228. # else
  160229. # define LDATA 0
  160230. # endif
  160231. # if !defined(__WIN32__) && !defined(__FLAT__) && !defined(__CYGWIN__)
  160232. # define PNG_MAX_MALLOC_64K
  160233. # if (LDATA != 1)
  160234. # ifndef FAR
  160235. # define FAR __far
  160236. # endif
  160237. # define USE_FAR_KEYWORD
  160238. # endif /* LDATA != 1 */
  160239. # endif /* __WIN32__, __FLAT__, __CYGWIN__ */
  160240. #endif /* __BORLANDC__ */
  160241. #if defined(FAR)
  160242. # if defined(M_I86MM)
  160243. # define USE_FAR_KEYWORD
  160244. # define FARDATA FAR
  160245. # include <dos.h>
  160246. # endif
  160247. #endif
  160248. #ifndef FAR
  160249. # define FAR
  160250. #endif
  160251. #ifndef FARDATA
  160252. # define FARDATA
  160253. #endif
  160254. typedef png_int_32 png_fixed_point;
  160255. typedef void FAR * png_voidp;
  160256. typedef png_byte FAR * png_bytep;
  160257. typedef png_uint_32 FAR * png_uint_32p;
  160258. typedef png_int_32 FAR * png_int_32p;
  160259. typedef png_uint_16 FAR * png_uint_16p;
  160260. typedef png_int_16 FAR * png_int_16p;
  160261. typedef PNG_CONST char FAR * png_const_charp;
  160262. typedef char FAR * png_charp;
  160263. typedef png_fixed_point FAR * png_fixed_point_p;
  160264. #ifndef PNG_NO_STDIO
  160265. #if defined(_WIN32_WCE)
  160266. typedef HANDLE png_FILE_p;
  160267. #else
  160268. typedef FILE * png_FILE_p;
  160269. #endif
  160270. #endif
  160271. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160272. typedef double FAR * png_doublep;
  160273. #endif
  160274. typedef png_byte FAR * FAR * png_bytepp;
  160275. typedef png_uint_32 FAR * FAR * png_uint_32pp;
  160276. typedef png_int_32 FAR * FAR * png_int_32pp;
  160277. typedef png_uint_16 FAR * FAR * png_uint_16pp;
  160278. typedef png_int_16 FAR * FAR * png_int_16pp;
  160279. typedef PNG_CONST char FAR * FAR * png_const_charpp;
  160280. typedef char FAR * FAR * png_charpp;
  160281. typedef png_fixed_point FAR * FAR * png_fixed_point_pp;
  160282. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160283. typedef double FAR * FAR * png_doublepp;
  160284. #endif
  160285. typedef char FAR * FAR * FAR * png_charppp;
  160286. #if 0
  160287. typedef charf * png_zcharp;
  160288. typedef charf * FAR * png_zcharpp;
  160289. typedef z_stream FAR * png_zstreamp;
  160290. #endif /* (PNG_1_0_X) || defined(PNG_1_2_X) */
  160291. #if !defined(PNG_DLL) && (defined(PNG_BUILD_DLL) || defined(PNG_USE_DLL))
  160292. # define PNG_DLL
  160293. #endif
  160294. #if defined(__CYGWIN__)
  160295. # if !defined(PNG_STATIC)
  160296. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160297. # undef PNG_USE_GLOBAL_ARRAYS
  160298. # endif
  160299. # if !defined(PNG_USE_LOCAL_ARRAYS)
  160300. # define PNG_USE_LOCAL_ARRAYS
  160301. # endif
  160302. # else
  160303. # if defined(PNG_USE_LOCAL_ARRAYS) || defined(PNG_NO_GLOBAL_ARRAYS)
  160304. # if defined(PNG_USE_GLOBAL_ARRAYS)
  160305. # undef PNG_USE_GLOBAL_ARRAYS
  160306. # endif
  160307. # endif
  160308. # endif
  160309. # if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160310. # define PNG_USE_LOCAL_ARRAYS
  160311. # endif
  160312. #endif
  160313. #if !defined(PNG_USE_LOCAL_ARRAYS) && !defined(PNG_USE_GLOBAL_ARRAYS)
  160314. # if defined(PNG_NO_GLOBAL_ARRAYS) || \
  160315. (defined(__GNUC__) && defined(PNG_DLL)) || defined(_MSC_VER)
  160316. # define PNG_USE_LOCAL_ARRAYS
  160317. # else
  160318. # define PNG_USE_GLOBAL_ARRAYS
  160319. # endif
  160320. #endif
  160321. #if defined(__CYGWIN__)
  160322. # undef PNGAPI
  160323. # define PNGAPI __cdecl
  160324. # undef PNG_IMPEXP
  160325. # define PNG_IMPEXP
  160326. #endif
  160327. #if defined(__MINGW32__) && !defined(PNG_MODULEDEF)
  160328. # ifndef PNG_NO_MODULEDEF
  160329. # define PNG_NO_MODULEDEF
  160330. # endif
  160331. #endif
  160332. #if !defined(PNG_IMPEXP) && defined(PNG_BUILD_DLL) && !defined(PNG_NO_MODULEDEF)
  160333. # define PNG_IMPEXP
  160334. #endif
  160335. #if defined(PNG_DLL) || defined(_DLL) || defined(__DLL__ ) || \
  160336. (( defined(_Windows) || defined(_WINDOWS) || \
  160337. defined(WIN32) || defined(_WIN32) || defined(__WIN32__) ))
  160338. # ifndef PNGAPI
  160339. # if defined(__GNUC__) || (defined (_MSC_VER) && (_MSC_VER >= 800))
  160340. # define PNGAPI __cdecl
  160341. # else
  160342. # define PNGAPI _cdecl
  160343. # endif
  160344. # endif
  160345. # if !defined(PNG_IMPEXP) && (!defined(PNG_DLL) || \
  160346. 0 /* WINCOMPILER_WITH_NO_SUPPORT_FOR_DECLIMPEXP */)
  160347. # define PNG_IMPEXP
  160348. # endif
  160349. # if !defined(PNG_IMPEXP)
  160350. # define PNG_EXPORT_TYPE1(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160351. # define PNG_EXPORT_TYPE2(type,symbol) type PNG_IMPEXP PNGAPI symbol
  160352. # if defined(_MSC_VER) || defined(__BORLANDC__)
  160353. # if (_MSC_VER >= 800) || (__BORLANDC__ >= 0x500)
  160354. # define PNG_EXPORT PNG_EXPORT_TYPE1
  160355. # else
  160356. # define PNG_EXPORT PNG_EXPORT_TYPE2
  160357. # if defined(PNG_BUILD_DLL)
  160358. # define PNG_IMPEXP __export
  160359. # else
  160360. # define PNG_IMPEXP /*__import */ /* doesn't exist AFAIK in
  160361. VC++ */
  160362. # endif /* Exists in Borland C++ for
  160363. C++ classes (== huge) */
  160364. # endif
  160365. # endif
  160366. # if !defined(PNG_IMPEXP)
  160367. # if defined(PNG_BUILD_DLL)
  160368. # define PNG_IMPEXP __declspec(dllexport)
  160369. # else
  160370. # define PNG_IMPEXP __declspec(dllimport)
  160371. # endif
  160372. # endif
  160373. # endif /* PNG_IMPEXP */
  160374. #else /* !(DLL || non-cygwin WINDOWS) */
  160375. # if (defined(__IBMC__) || defined(__IBMCPP__)) && defined(__OS2__)
  160376. # ifndef PNGAPI
  160377. # define PNGAPI _System
  160378. # endif
  160379. # else
  160380. # if 0 /* ... other platforms, with other meanings */
  160381. # endif
  160382. # endif
  160383. #endif
  160384. #ifndef PNGAPI
  160385. # define PNGAPI
  160386. #endif
  160387. #ifndef PNG_IMPEXP
  160388. # define PNG_IMPEXP
  160389. #endif
  160390. #ifdef PNG_BUILDSYMS
  160391. # ifndef PNG_EXPORT
  160392. # define PNG_EXPORT(type,symbol) PNG_FUNCTION_EXPORT symbol END
  160393. # endif
  160394. # ifdef PNG_USE_GLOBAL_ARRAYS
  160395. # ifndef PNG_EXPORT_VAR
  160396. # define PNG_EXPORT_VAR(type) PNG_DATA_EXPORT
  160397. # endif
  160398. # endif
  160399. #endif
  160400. #ifndef PNG_EXPORT
  160401. # define PNG_EXPORT(type,symbol) PNG_IMPEXP type PNGAPI symbol
  160402. #endif
  160403. #ifdef PNG_USE_GLOBAL_ARRAYS
  160404. # ifndef PNG_EXPORT_VAR
  160405. # define PNG_EXPORT_VAR(type) extern PNG_IMPEXP type
  160406. # endif
  160407. #endif
  160408. #ifndef PNG_ABORT
  160409. # define PNG_ABORT() abort()
  160410. #endif
  160411. #ifdef PNG_SETJMP_SUPPORTED
  160412. # define png_jmpbuf(png_ptr) ((png_ptr)->jmpbuf)
  160413. #else
  160414. # define png_jmpbuf(png_ptr) \
  160415. (LIBPNG_WAS_COMPILED_WITH__PNG_SETJMP_NOT_SUPPORTED)
  160416. #endif
  160417. #if defined(USE_FAR_KEYWORD) /* memory model independent fns */
  160418. # define CHECK 1
  160419. # define NOCHECK 0
  160420. # define CVT_PTR(ptr) (png_far_to_near(png_ptr,ptr,CHECK))
  160421. # define CVT_PTR_NOCHECK(ptr) (png_far_to_near(png_ptr,ptr,NOCHECK))
  160422. # define png_snprintf _fsnprintf /* Added to v 1.2.19 */
  160423. # define png_strcpy _fstrcpy
  160424. # define png_strncpy _fstrncpy /* Added to v 1.2.6 */
  160425. # define png_strlen _fstrlen
  160426. # define png_memcmp _fmemcmp /* SJT: added */
  160427. # define png_memcpy _fmemcpy
  160428. # define png_memset _fmemset
  160429. #else /* use the usual functions */
  160430. # define CVT_PTR(ptr) (ptr)
  160431. # define CVT_PTR_NOCHECK(ptr) (ptr)
  160432. # ifndef PNG_NO_SNPRINTF
  160433. # ifdef _MSC_VER
  160434. # define png_snprintf _snprintf /* Added to v 1.2.19 */
  160435. # define png_snprintf2 _snprintf
  160436. # define png_snprintf6 _snprintf
  160437. # else
  160438. # define png_snprintf snprintf /* Added to v 1.2.19 */
  160439. # define png_snprintf2 snprintf
  160440. # define png_snprintf6 snprintf
  160441. # endif
  160442. # else
  160443. # define png_snprintf(s1,n,fmt,x1) sprintf(s1,fmt,x1)
  160444. # define png_snprintf2(s1,n,fmt,x1,x2) sprintf(s1,fmt,x1,x2)
  160445. # define png_snprintf6(s1,n,fmt,x1,x2,x3,x4,x5,x6) \
  160446. sprintf(s1,fmt,x1,x2,x3,x4,x5,x6)
  160447. # endif
  160448. # define png_strcpy strcpy
  160449. # define png_strncpy strncpy /* Added to v 1.2.6 */
  160450. # define png_strlen strlen
  160451. # define png_memcmp memcmp /* SJT: added */
  160452. # define png_memcpy memcpy
  160453. # define png_memset memset
  160454. #endif
  160455. #if (PNG_ZBUF_SIZE > 65536L) && defined(PNG_MAX_MALLOC_64K)
  160456. # undef PNG_ZBUF_SIZE
  160457. # define PNG_ZBUF_SIZE 65536L
  160458. #endif
  160459. #endif /* PNG_VERSION_INFO_ONLY */
  160460. #endif /* PNGCONF_H */
  160461. /*** End of inlined file: pngconf.h ***/
  160462. #ifdef _MSC_VER
  160463. #pragma warning (disable: 4996 4100)
  160464. #endif
  160465. #if defined(PNG_USER_PRIVATEBUILD)
  160466. # define PNG_LIBPNG_BUILD_TYPE \
  160467. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_PRIVATE)
  160468. #else
  160469. # if defined(PNG_LIBPNG_SPECIALBUILD)
  160470. # define PNG_LIBPNG_BUILD_TYPE \
  160471. (PNG_LIBPNG_BUILD_BASE_TYPE | PNG_LIBPNG_BUILD_SPECIAL)
  160472. # else
  160473. # define PNG_LIBPNG_BUILD_TYPE (PNG_LIBPNG_BUILD_BASE_TYPE)
  160474. # endif
  160475. #endif
  160476. #ifndef PNG_VERSION_INFO_ONLY
  160477. #ifdef __cplusplus
  160478. extern "C" {
  160479. #endif /* __cplusplus */
  160480. #ifndef PNG_NO_TYPECAST_NULL
  160481. #define int_p_NULL (int *)NULL
  160482. #define png_bytep_NULL (png_bytep)NULL
  160483. #define png_bytepp_NULL (png_bytepp)NULL
  160484. #define png_doublep_NULL (png_doublep)NULL
  160485. #define png_error_ptr_NULL (png_error_ptr)NULL
  160486. #define png_flush_ptr_NULL (png_flush_ptr)NULL
  160487. #define png_free_ptr_NULL (png_free_ptr)NULL
  160488. #define png_infopp_NULL (png_infopp)NULL
  160489. #define png_malloc_ptr_NULL (png_malloc_ptr)NULL
  160490. #define png_read_status_ptr_NULL (png_read_status_ptr)NULL
  160491. #define png_rw_ptr_NULL (png_rw_ptr)NULL
  160492. #define png_structp_NULL (png_structp)NULL
  160493. #define png_uint_16p_NULL (png_uint_16p)NULL
  160494. #define png_voidp_NULL (png_voidp)NULL
  160495. #define png_write_status_ptr_NULL (png_write_status_ptr)NULL
  160496. #else
  160497. #define int_p_NULL NULL
  160498. #define png_bytep_NULL NULL
  160499. #define png_bytepp_NULL NULL
  160500. #define png_doublep_NULL NULL
  160501. #define png_error_ptr_NULL NULL
  160502. #define png_flush_ptr_NULL NULL
  160503. #define png_free_ptr_NULL NULL
  160504. #define png_infopp_NULL NULL
  160505. #define png_malloc_ptr_NULL NULL
  160506. #define png_read_status_ptr_NULL NULL
  160507. #define png_rw_ptr_NULL NULL
  160508. #define png_structp_NULL NULL
  160509. #define png_uint_16p_NULL NULL
  160510. #define png_voidp_NULL NULL
  160511. #define png_write_status_ptr_NULL NULL
  160512. #endif
  160513. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  160514. #ifdef PNG_USE_GLOBAL_ARRAYS
  160515. PNG_EXPORT_VAR (PNG_CONST char) png_libpng_ver[18];
  160516. #else
  160517. #define png_libpng_ver png_get_header_ver(NULL)
  160518. #endif
  160519. #ifdef PNG_USE_GLOBAL_ARRAYS
  160520. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_start[7];
  160521. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_inc[7];
  160522. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_ystart[7];
  160523. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_yinc[7];
  160524. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_mask[7];
  160525. PNG_EXPORT_VAR (PNG_CONST int FARDATA) png_pass_dsp_mask[7];
  160526. #endif
  160527. #endif /* PNG_NO_EXTERN */
  160528. typedef struct png_color_struct
  160529. {
  160530. png_byte red;
  160531. png_byte green;
  160532. png_byte blue;
  160533. } png_color;
  160534. typedef png_color FAR * png_colorp;
  160535. typedef png_color FAR * FAR * png_colorpp;
  160536. typedef struct png_color_16_struct
  160537. {
  160538. png_byte index; /* used for palette files */
  160539. png_uint_16 red; /* for use in red green blue files */
  160540. png_uint_16 green;
  160541. png_uint_16 blue;
  160542. png_uint_16 gray; /* for use in grayscale files */
  160543. } png_color_16;
  160544. typedef png_color_16 FAR * png_color_16p;
  160545. typedef png_color_16 FAR * FAR * png_color_16pp;
  160546. typedef struct png_color_8_struct
  160547. {
  160548. png_byte red; /* for use in red green blue files */
  160549. png_byte green;
  160550. png_byte blue;
  160551. png_byte gray; /* for use in grayscale files */
  160552. png_byte alpha; /* for alpha channel files */
  160553. } png_color_8;
  160554. typedef png_color_8 FAR * png_color_8p;
  160555. typedef png_color_8 FAR * FAR * png_color_8pp;
  160556. typedef struct png_sPLT_entry_struct
  160557. {
  160558. png_uint_16 red;
  160559. png_uint_16 green;
  160560. png_uint_16 blue;
  160561. png_uint_16 alpha;
  160562. png_uint_16 frequency;
  160563. } png_sPLT_entry;
  160564. typedef png_sPLT_entry FAR * png_sPLT_entryp;
  160565. typedef png_sPLT_entry FAR * FAR * png_sPLT_entrypp;
  160566. typedef struct png_sPLT_struct
  160567. {
  160568. png_charp name; /* palette name */
  160569. png_byte depth; /* depth of palette samples */
  160570. png_sPLT_entryp entries; /* palette entries */
  160571. png_int_32 nentries; /* number of palette entries */
  160572. } png_sPLT_t;
  160573. typedef png_sPLT_t FAR * png_sPLT_tp;
  160574. typedef png_sPLT_t FAR * FAR * png_sPLT_tpp;
  160575. #ifdef PNG_TEXT_SUPPORTED
  160576. typedef struct png_text_struct
  160577. {
  160578. int compression; /* compression value:
  160579. -1: tEXt, none
  160580. 0: zTXt, deflate
  160581. 1: iTXt, none
  160582. 2: iTXt, deflate */
  160583. png_charp key; /* keyword, 1-79 character description of "text" */
  160584. png_charp text; /* comment, may be an empty string (ie "")
  160585. or a NULL pointer */
  160586. png_size_t text_length; /* length of the text string */
  160587. #ifdef PNG_iTXt_SUPPORTED
  160588. png_size_t itxt_length; /* length of the itxt string */
  160589. png_charp lang; /* language code, 0-79 characters
  160590. or a NULL pointer */
  160591. png_charp lang_key; /* keyword translated UTF-8 string, 0 or more
  160592. chars or a NULL pointer */
  160593. #endif
  160594. } png_text;
  160595. typedef png_text FAR * png_textp;
  160596. typedef png_text FAR * FAR * png_textpp;
  160597. #endif
  160598. #define PNG_TEXT_COMPRESSION_NONE_WR -3
  160599. #define PNG_TEXT_COMPRESSION_zTXt_WR -2
  160600. #define PNG_TEXT_COMPRESSION_NONE -1
  160601. #define PNG_TEXT_COMPRESSION_zTXt 0
  160602. #define PNG_ITXT_COMPRESSION_NONE 1
  160603. #define PNG_ITXT_COMPRESSION_zTXt 2
  160604. #define PNG_TEXT_COMPRESSION_LAST 3 /* Not a valid value */
  160605. typedef struct png_time_struct
  160606. {
  160607. png_uint_16 year; /* full year, as in, 1995 */
  160608. png_byte month; /* month of year, 1 - 12 */
  160609. png_byte day; /* day of month, 1 - 31 */
  160610. png_byte hour; /* hour of day, 0 - 23 */
  160611. png_byte minute; /* minute of hour, 0 - 59 */
  160612. png_byte second; /* second of minute, 0 - 60 (for leap seconds) */
  160613. } png_time;
  160614. typedef png_time FAR * png_timep;
  160615. typedef png_time FAR * FAR * png_timepp;
  160616. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160617. typedef struct png_unknown_chunk_t
  160618. {
  160619. png_byte name[5];
  160620. png_byte *data;
  160621. png_size_t size;
  160622. png_byte location; /* mode of operation at read time */
  160623. }
  160624. png_unknown_chunk;
  160625. typedef png_unknown_chunk FAR * png_unknown_chunkp;
  160626. typedef png_unknown_chunk FAR * FAR * png_unknown_chunkpp;
  160627. #endif
  160628. typedef struct png_info_struct
  160629. {
  160630. png_uint_32 width; /* width of image in pixels (from IHDR) */
  160631. png_uint_32 height; /* height of image in pixels (from IHDR) */
  160632. png_uint_32 valid; /* valid chunk data (see PNG_INFO_ below) */
  160633. png_uint_32 rowbytes; /* bytes needed to hold an untransformed row */
  160634. png_colorp palette; /* array of color values (valid & PNG_INFO_PLTE) */
  160635. png_uint_16 num_palette; /* number of color entries in "palette" (PLTE) */
  160636. png_uint_16 num_trans; /* number of transparent palette color (tRNS) */
  160637. png_byte bit_depth; /* 1, 2, 4, 8, or 16 bits/channel (from IHDR) */
  160638. png_byte color_type; /* see PNG_COLOR_TYPE_ below (from IHDR) */
  160639. png_byte compression_type; /* must be PNG_COMPRESSION_TYPE_BASE (IHDR) */
  160640. png_byte filter_type; /* must be PNG_FILTER_TYPE_BASE (from IHDR) */
  160641. png_byte interlace_type; /* One of PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160642. png_byte channels; /* number of data channels per pixel (1, 2, 3, 4) */
  160643. png_byte pixel_depth; /* number of bits per pixel */
  160644. png_byte spare_byte; /* to align the data, and for future use */
  160645. png_byte signature[8]; /* magic bytes read by libpng from start of file */
  160646. #if defined(PNG_gAMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  160647. float gamma; /* gamma value of image, if (valid & PNG_INFO_gAMA) */
  160648. #endif
  160649. #if defined(PNG_sRGB_SUPPORTED)
  160650. png_byte srgb_intent; /* sRGB rendering intent [0, 1, 2, or 3] */
  160651. #endif
  160652. #if defined(PNG_TEXT_SUPPORTED)
  160653. int num_text; /* number of comments read/to write */
  160654. int max_text; /* current size of text array */
  160655. png_textp text; /* array of comments read/to write */
  160656. #endif /* PNG_TEXT_SUPPORTED */
  160657. #if defined(PNG_tIME_SUPPORTED)
  160658. png_time mod_time;
  160659. #endif
  160660. #if defined(PNG_sBIT_SUPPORTED)
  160661. png_color_8 sig_bit; /* significant bits in color channels */
  160662. #endif
  160663. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_EXPAND_SUPPORTED) || \
  160664. defined(PNG_READ_BACKGROUND_SUPPORTED)
  160665. png_bytep trans; /* transparent values for paletted image */
  160666. png_color_16 trans_values; /* transparent color for non-palette image */
  160667. #endif
  160668. #if defined(PNG_bKGD_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160669. png_color_16 background;
  160670. #endif
  160671. #if defined(PNG_oFFs_SUPPORTED)
  160672. png_int_32 x_offset; /* x offset on page */
  160673. png_int_32 y_offset; /* y offset on page */
  160674. png_byte offset_unit_type; /* offset units type */
  160675. #endif
  160676. #if defined(PNG_pHYs_SUPPORTED)
  160677. png_uint_32 x_pixels_per_unit; /* horizontal pixel density */
  160678. png_uint_32 y_pixels_per_unit; /* vertical pixel density */
  160679. png_byte phys_unit_type; /* resolution type (see PNG_RESOLUTION_ below) */
  160680. #endif
  160681. #if defined(PNG_hIST_SUPPORTED)
  160682. png_uint_16p hist;
  160683. #endif
  160684. #ifdef PNG_cHRM_SUPPORTED
  160685. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160686. float x_white;
  160687. float y_white;
  160688. float x_red;
  160689. float y_red;
  160690. float x_green;
  160691. float y_green;
  160692. float x_blue;
  160693. float y_blue;
  160694. #endif
  160695. #endif
  160696. #if defined(PNG_pCAL_SUPPORTED)
  160697. png_charp pcal_purpose; /* pCAL chunk description string */
  160698. png_int_32 pcal_X0; /* minimum value */
  160699. png_int_32 pcal_X1; /* maximum value */
  160700. png_charp pcal_units; /* Latin-1 string giving physical units */
  160701. png_charpp pcal_params; /* ASCII strings containing parameter values */
  160702. png_byte pcal_type; /* equation type (see PNG_EQUATION_ below) */
  160703. png_byte pcal_nparams; /* number of parameters given in pcal_params */
  160704. #endif
  160705. #ifdef PNG_FREE_ME_SUPPORTED
  160706. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  160707. #endif
  160708. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160709. png_unknown_chunkp unknown_chunks;
  160710. png_size_t unknown_chunks_num;
  160711. #endif
  160712. #if defined(PNG_iCCP_SUPPORTED)
  160713. png_charp iccp_name; /* profile name */
  160714. png_charp iccp_profile; /* International Color Consortium profile data */
  160715. png_uint_32 iccp_proflen; /* ICC profile data length */
  160716. png_byte iccp_compression; /* Always zero */
  160717. #endif
  160718. #if defined(PNG_sPLT_SUPPORTED)
  160719. png_sPLT_tp splt_palettes;
  160720. png_uint_32 splt_palettes_num;
  160721. #endif
  160722. #if defined(PNG_sCAL_SUPPORTED)
  160723. png_byte scal_unit; /* unit of physical scale */
  160724. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160725. double scal_pixel_width; /* width of one pixel */
  160726. double scal_pixel_height; /* height of one pixel */
  160727. #endif
  160728. #ifdef PNG_FIXED_POINT_SUPPORTED
  160729. png_charp scal_s_width; /* string containing height */
  160730. png_charp scal_s_height; /* string containing width */
  160731. #endif
  160732. #endif
  160733. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  160734. png_bytepp row_pointers; /* the image bits */
  160735. #endif
  160736. #if defined(PNG_FIXED_POINT_SUPPORTED) && defined(PNG_gAMA_SUPPORTED)
  160737. png_fixed_point int_gamma; /* gamma of image, if (valid & PNG_INFO_gAMA) */
  160738. #endif
  160739. #if defined(PNG_cHRM_SUPPORTED) && defined(PNG_FIXED_POINT_SUPPORTED)
  160740. png_fixed_point int_x_white;
  160741. png_fixed_point int_y_white;
  160742. png_fixed_point int_x_red;
  160743. png_fixed_point int_y_red;
  160744. png_fixed_point int_x_green;
  160745. png_fixed_point int_y_green;
  160746. png_fixed_point int_x_blue;
  160747. png_fixed_point int_y_blue;
  160748. #endif
  160749. } png_info;
  160750. typedef png_info FAR * png_infop;
  160751. typedef png_info FAR * FAR * png_infopp;
  160752. #define PNG_UINT_31_MAX ((png_uint_32)0x7fffffffL)
  160753. #define PNG_UINT_32_MAX ((png_uint_32)(-1))
  160754. #define PNG_SIZE_MAX ((png_size_t)(-1))
  160755. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  160756. #define PNG_MAX_UINT PNG_UINT_31_MAX
  160757. #endif
  160758. #define PNG_COLOR_MASK_PALETTE 1
  160759. #define PNG_COLOR_MASK_COLOR 2
  160760. #define PNG_COLOR_MASK_ALPHA 4
  160761. #define PNG_COLOR_TYPE_GRAY 0
  160762. #define PNG_COLOR_TYPE_PALETTE (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_PALETTE)
  160763. #define PNG_COLOR_TYPE_RGB (PNG_COLOR_MASK_COLOR)
  160764. #define PNG_COLOR_TYPE_RGB_ALPHA (PNG_COLOR_MASK_COLOR | PNG_COLOR_MASK_ALPHA)
  160765. #define PNG_COLOR_TYPE_GRAY_ALPHA (PNG_COLOR_MASK_ALPHA)
  160766. #define PNG_COLOR_TYPE_RGBA PNG_COLOR_TYPE_RGB_ALPHA
  160767. #define PNG_COLOR_TYPE_GA PNG_COLOR_TYPE_GRAY_ALPHA
  160768. #define PNG_COMPRESSION_TYPE_BASE 0 /* Deflate method 8, 32K window */
  160769. #define PNG_COMPRESSION_TYPE_DEFAULT PNG_COMPRESSION_TYPE_BASE
  160770. #define PNG_FILTER_TYPE_BASE 0 /* Single row per-byte filtering */
  160771. #define PNG_INTRAPIXEL_DIFFERENCING 64 /* Used only in MNG datastreams */
  160772. #define PNG_FILTER_TYPE_DEFAULT PNG_FILTER_TYPE_BASE
  160773. #define PNG_INTERLACE_NONE 0 /* Non-interlaced image */
  160774. #define PNG_INTERLACE_ADAM7 1 /* Adam7 interlacing */
  160775. #define PNG_INTERLACE_LAST 2 /* Not a valid value */
  160776. #define PNG_OFFSET_PIXEL 0 /* Offset in pixels */
  160777. #define PNG_OFFSET_MICROMETER 1 /* Offset in micrometers (1/10^6 meter) */
  160778. #define PNG_OFFSET_LAST 2 /* Not a valid value */
  160779. #define PNG_EQUATION_LINEAR 0 /* Linear transformation */
  160780. #define PNG_EQUATION_BASE_E 1 /* Exponential base e transform */
  160781. #define PNG_EQUATION_ARBITRARY 2 /* Arbitrary base exponential transform */
  160782. #define PNG_EQUATION_HYPERBOLIC 3 /* Hyperbolic sine transformation */
  160783. #define PNG_EQUATION_LAST 4 /* Not a valid value */
  160784. #define PNG_SCALE_UNKNOWN 0 /* unknown unit (image scale) */
  160785. #define PNG_SCALE_METER 1 /* meters per pixel */
  160786. #define PNG_SCALE_RADIAN 2 /* radians per pixel */
  160787. #define PNG_SCALE_LAST 3 /* Not a valid value */
  160788. #define PNG_RESOLUTION_UNKNOWN 0 /* pixels/unknown unit (aspect ratio) */
  160789. #define PNG_RESOLUTION_METER 1 /* pixels/meter */
  160790. #define PNG_RESOLUTION_LAST 2 /* Not a valid value */
  160791. #define PNG_sRGB_INTENT_PERCEPTUAL 0
  160792. #define PNG_sRGB_INTENT_RELATIVE 1
  160793. #define PNG_sRGB_INTENT_SATURATION 2
  160794. #define PNG_sRGB_INTENT_ABSOLUTE 3
  160795. #define PNG_sRGB_INTENT_LAST 4 /* Not a valid value */
  160796. #define PNG_KEYWORD_MAX_LENGTH 79
  160797. #define PNG_MAX_PALETTE_LENGTH 256
  160798. #define PNG_INFO_gAMA 0x0001
  160799. #define PNG_INFO_sBIT 0x0002
  160800. #define PNG_INFO_cHRM 0x0004
  160801. #define PNG_INFO_PLTE 0x0008
  160802. #define PNG_INFO_tRNS 0x0010
  160803. #define PNG_INFO_bKGD 0x0020
  160804. #define PNG_INFO_hIST 0x0040
  160805. #define PNG_INFO_pHYs 0x0080
  160806. #define PNG_INFO_oFFs 0x0100
  160807. #define PNG_INFO_tIME 0x0200
  160808. #define PNG_INFO_pCAL 0x0400
  160809. #define PNG_INFO_sRGB 0x0800 /* GR-P, 0.96a */
  160810. #define PNG_INFO_iCCP 0x1000 /* ESR, 1.0.6 */
  160811. #define PNG_INFO_sPLT 0x2000 /* ESR, 1.0.6 */
  160812. #define PNG_INFO_sCAL 0x4000 /* ESR, 1.0.6 */
  160813. #define PNG_INFO_IDAT 0x8000L /* ESR, 1.0.6 */
  160814. typedef struct png_row_info_struct
  160815. {
  160816. png_uint_32 width; /* width of row */
  160817. png_uint_32 rowbytes; /* number of bytes in row */
  160818. png_byte color_type; /* color type of row */
  160819. png_byte bit_depth; /* bit depth of row */
  160820. png_byte channels; /* number of channels (1, 2, 3, or 4) */
  160821. png_byte pixel_depth; /* bits per pixel (depth * channels) */
  160822. } png_row_info;
  160823. typedef png_row_info FAR * png_row_infop;
  160824. typedef png_row_info FAR * FAR * png_row_infopp;
  160825. typedef struct png_struct_def png_struct;
  160826. typedef png_struct FAR * png_structp;
  160827. typedef void (PNGAPI *png_error_ptr) PNGARG((png_structp, png_const_charp));
  160828. typedef void (PNGAPI *png_rw_ptr) PNGARG((png_structp, png_bytep, png_size_t));
  160829. typedef void (PNGAPI *png_flush_ptr) PNGARG((png_structp));
  160830. typedef void (PNGAPI *png_read_status_ptr) PNGARG((png_structp, png_uint_32,
  160831. int));
  160832. typedef void (PNGAPI *png_write_status_ptr) PNGARG((png_structp, png_uint_32,
  160833. int));
  160834. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160835. typedef void (PNGAPI *png_progressive_info_ptr) PNGARG((png_structp, png_infop));
  160836. typedef void (PNGAPI *png_progressive_end_ptr) PNGARG((png_structp, png_infop));
  160837. typedef void (PNGAPI *png_progressive_row_ptr) PNGARG((png_structp, png_bytep,
  160838. png_uint_32, int));
  160839. #endif
  160840. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160841. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  160842. defined(PNG_LEGACY_SUPPORTED)
  160843. typedef void (PNGAPI *png_user_transform_ptr) PNGARG((png_structp,
  160844. png_row_infop, png_bytep));
  160845. #endif
  160846. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  160847. typedef int (PNGAPI *png_user_chunk_ptr) PNGARG((png_structp, png_unknown_chunkp));
  160848. #endif
  160849. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  160850. typedef void (PNGAPI *png_unknown_chunk_ptr) PNGARG((png_structp));
  160851. #endif
  160852. #define PNG_TRANSFORM_IDENTITY 0x0000 /* read and write */
  160853. #define PNG_TRANSFORM_STRIP_16 0x0001 /* read only */
  160854. #define PNG_TRANSFORM_STRIP_ALPHA 0x0002 /* read only */
  160855. #define PNG_TRANSFORM_PACKING 0x0004 /* read and write */
  160856. #define PNG_TRANSFORM_PACKSWAP 0x0008 /* read and write */
  160857. #define PNG_TRANSFORM_EXPAND 0x0010 /* read only */
  160858. #define PNG_TRANSFORM_INVERT_MONO 0x0020 /* read and write */
  160859. #define PNG_TRANSFORM_SHIFT 0x0040 /* read and write */
  160860. #define PNG_TRANSFORM_BGR 0x0080 /* read and write */
  160861. #define PNG_TRANSFORM_SWAP_ALPHA 0x0100 /* read and write */
  160862. #define PNG_TRANSFORM_SWAP_ENDIAN 0x0200 /* read and write */
  160863. #define PNG_TRANSFORM_INVERT_ALPHA 0x0400 /* read and write */
  160864. #define PNG_TRANSFORM_STRIP_FILLER 0x0800 /* WRITE only */
  160865. #define PNG_FLAG_MNG_EMPTY_PLTE 0x01
  160866. #define PNG_FLAG_MNG_FILTER_64 0x04
  160867. #define PNG_ALL_MNG_FEATURES 0x05
  160868. typedef png_voidp (*png_malloc_ptr) PNGARG((png_structp, png_size_t));
  160869. typedef void (*png_free_ptr) PNGARG((png_structp, png_voidp));
  160870. struct png_struct_def
  160871. {
  160872. #ifdef PNG_SETJMP_SUPPORTED
  160873. jmp_buf jmpbuf; /* used in png_error */
  160874. #endif
  160875. png_error_ptr error_fn; /* function for printing errors and aborting */
  160876. png_error_ptr warning_fn; /* function for printing warnings */
  160877. png_voidp error_ptr; /* user supplied struct for error functions */
  160878. png_rw_ptr write_data_fn; /* function for writing output data */
  160879. png_rw_ptr read_data_fn; /* function for reading input data */
  160880. png_voidp io_ptr; /* ptr to application struct for I/O functions */
  160881. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  160882. png_user_transform_ptr read_user_transform_fn; /* user read transform */
  160883. #endif
  160884. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160885. png_user_transform_ptr write_user_transform_fn; /* user write transform */
  160886. #endif
  160887. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  160888. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  160889. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  160890. png_voidp user_transform_ptr; /* user supplied struct for user transform */
  160891. png_byte user_transform_depth; /* bit depth of user transformed pixels */
  160892. png_byte user_transform_channels; /* channels in user transformed pixels */
  160893. #endif
  160894. #endif
  160895. png_uint_32 mode; /* tells us where we are in the PNG file */
  160896. png_uint_32 flags; /* flags indicating various things to libpng */
  160897. png_uint_32 transformations; /* which transformations to perform */
  160898. z_stream zstream; /* pointer to decompression structure (below) */
  160899. png_bytep zbuf; /* buffer for zlib */
  160900. png_size_t zbuf_size; /* size of zbuf */
  160901. int zlib_level; /* holds zlib compression level */
  160902. int zlib_method; /* holds zlib compression method */
  160903. int zlib_window_bits; /* holds zlib compression window bits */
  160904. int zlib_mem_level; /* holds zlib compression memory level */
  160905. int zlib_strategy; /* holds zlib compression strategy */
  160906. png_uint_32 width; /* width of image in pixels */
  160907. png_uint_32 height; /* height of image in pixels */
  160908. png_uint_32 num_rows; /* number of rows in current pass */
  160909. png_uint_32 usr_width; /* width of row at start of write */
  160910. png_uint_32 rowbytes; /* size of row in bytes */
  160911. png_uint_32 irowbytes; /* size of current interlaced row in bytes */
  160912. png_uint_32 iwidth; /* width of current interlaced row in pixels */
  160913. png_uint_32 row_number; /* current row in interlace pass */
  160914. png_bytep prev_row; /* buffer to save previous (unfiltered) row */
  160915. png_bytep row_buf; /* buffer to save current (unfiltered) row */
  160916. png_bytep sub_row; /* buffer to save "sub" row when filtering */
  160917. png_bytep up_row; /* buffer to save "up" row when filtering */
  160918. png_bytep avg_row; /* buffer to save "avg" row when filtering */
  160919. png_bytep paeth_row; /* buffer to save "Paeth" row when filtering */
  160920. png_row_info row_info; /* used for transformation routines */
  160921. png_uint_32 idat_size; /* current IDAT size for read */
  160922. png_uint_32 crc; /* current chunk CRC value */
  160923. png_colorp palette; /* palette from the input file */
  160924. png_uint_16 num_palette; /* number of color entries in palette */
  160925. png_uint_16 num_trans; /* number of transparency values */
  160926. png_byte chunk_name[5]; /* null-terminated name of current chunk */
  160927. png_byte compression; /* file compression type (always 0) */
  160928. png_byte filter; /* file filter type (always 0) */
  160929. png_byte interlaced; /* PNG_INTERLACE_NONE, PNG_INTERLACE_ADAM7 */
  160930. png_byte pass; /* current interlace pass (0 - 6) */
  160931. png_byte do_filter; /* row filter flags (see PNG_FILTER_ below ) */
  160932. png_byte color_type; /* color type of file */
  160933. png_byte bit_depth; /* bit depth of file */
  160934. png_byte usr_bit_depth; /* bit depth of users row */
  160935. png_byte pixel_depth; /* number of bits per pixel */
  160936. png_byte channels; /* number of channels in file */
  160937. png_byte usr_channels; /* channels at start of write */
  160938. png_byte sig_bytes; /* magic bytes read/written from start of file */
  160939. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  160940. #ifdef PNG_LEGACY_SUPPORTED
  160941. png_byte filler; /* filler byte for pixel expansion */
  160942. #else
  160943. png_uint_16 filler; /* filler bytes for pixel expansion */
  160944. #endif
  160945. #endif
  160946. #if defined(PNG_bKGD_SUPPORTED)
  160947. png_byte background_gamma_type;
  160948. # ifdef PNG_FLOATING_POINT_SUPPORTED
  160949. float background_gamma;
  160950. # endif
  160951. png_color_16 background; /* background color in screen gamma space */
  160952. #if defined(PNG_READ_GAMMA_SUPPORTED)
  160953. png_color_16 background_1; /* background normalized to gamma 1.0 */
  160954. #endif
  160955. #endif /* PNG_bKGD_SUPPORTED */
  160956. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  160957. png_flush_ptr output_flush_fn;/* Function for flushing output */
  160958. png_uint_32 flush_dist; /* how many rows apart to flush, 0 - no flush */
  160959. png_uint_32 flush_rows; /* number of rows written since last flush */
  160960. #endif
  160961. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160962. int gamma_shift; /* number of "insignificant" bits 16-bit gamma */
  160963. #ifdef PNG_FLOATING_POINT_SUPPORTED
  160964. float gamma; /* file gamma value */
  160965. float screen_gamma; /* screen gamma value (display_exponent) */
  160966. #endif
  160967. #endif
  160968. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160969. png_bytep gamma_table; /* gamma table for 8-bit depth files */
  160970. png_bytep gamma_from_1; /* converts from 1.0 to screen */
  160971. png_bytep gamma_to_1; /* converts from file to 1.0 */
  160972. png_uint_16pp gamma_16_table; /* gamma table for 16-bit depth files */
  160973. png_uint_16pp gamma_16_from_1; /* converts from 1.0 to screen */
  160974. png_uint_16pp gamma_16_to_1; /* converts from file to 1.0 */
  160975. #endif
  160976. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_sBIT_SUPPORTED)
  160977. png_color_8 sig_bit; /* significant bits in each available channel */
  160978. #endif
  160979. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  160980. png_color_8 shift; /* shift for significant bit tranformation */
  160981. #endif
  160982. #if defined(PNG_tRNS_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED) \
  160983. || defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  160984. png_bytep trans; /* transparency values for paletted files */
  160985. png_color_16 trans_values; /* transparency values for non-paletted files */
  160986. #endif
  160987. png_read_status_ptr read_row_fn; /* called after each row is decoded */
  160988. png_write_status_ptr write_row_fn; /* called after each row is encoded */
  160989. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  160990. png_progressive_info_ptr info_fn; /* called after header data fully read */
  160991. png_progressive_row_ptr row_fn; /* called after each prog. row is decoded */
  160992. png_progressive_end_ptr end_fn; /* called after image is complete */
  160993. png_bytep save_buffer_ptr; /* current location in save_buffer */
  160994. png_bytep save_buffer; /* buffer for previously read data */
  160995. png_bytep current_buffer_ptr; /* current location in current_buffer */
  160996. png_bytep current_buffer; /* buffer for recently used data */
  160997. png_uint_32 push_length; /* size of current input chunk */
  160998. png_uint_32 skip_length; /* bytes to skip in input data */
  160999. png_size_t save_buffer_size; /* amount of data now in save_buffer */
  161000. png_size_t save_buffer_max; /* total size of save_buffer */
  161001. png_size_t buffer_size; /* total amount of available input data */
  161002. png_size_t current_buffer_size; /* amount of data now in current_buffer */
  161003. int process_mode; /* what push library is currently doing */
  161004. int cur_palette; /* current push library palette index */
  161005. # if defined(PNG_TEXT_SUPPORTED)
  161006. png_size_t current_text_size; /* current size of text input data */
  161007. png_size_t current_text_left; /* how much text left to read in input */
  161008. png_charp current_text; /* current text chunk buffer */
  161009. png_charp current_text_ptr; /* current location in current_text */
  161010. # endif /* PNG_TEXT_SUPPORTED */
  161011. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161012. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  161013. png_bytepp offset_table_ptr;
  161014. png_bytep offset_table;
  161015. png_uint_16 offset_table_number;
  161016. png_uint_16 offset_table_count;
  161017. png_uint_16 offset_table_count_free;
  161018. #endif
  161019. #if defined(PNG_READ_DITHER_SUPPORTED)
  161020. png_bytep palette_lookup; /* lookup table for dithering */
  161021. png_bytep dither_index; /* index translation for palette files */
  161022. #endif
  161023. #if defined(PNG_READ_DITHER_SUPPORTED) || defined(PNG_hIST_SUPPORTED)
  161024. png_uint_16p hist; /* histogram */
  161025. #endif
  161026. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  161027. png_byte heuristic_method; /* heuristic for row filter selection */
  161028. png_byte num_prev_filters; /* number of weights for previous rows */
  161029. png_bytep prev_filters; /* filter type(s) of previous row(s) */
  161030. png_uint_16p filter_weights; /* weight(s) for previous line(s) */
  161031. png_uint_16p inv_filter_weights; /* 1/weight(s) for previous line(s) */
  161032. png_uint_16p filter_costs; /* relative filter calculation cost */
  161033. png_uint_16p inv_filter_costs; /* 1/relative filter calculation cost */
  161034. #endif
  161035. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  161036. png_charp time_buffer; /* String to hold RFC 1123 time text */
  161037. #endif
  161038. #ifdef PNG_FREE_ME_SUPPORTED
  161039. png_uint_32 free_me; /* flags items libpng is responsible for freeing */
  161040. #endif
  161041. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  161042. png_voidp user_chunk_ptr;
  161043. png_user_chunk_ptr read_user_chunk_fn; /* user read chunk handler */
  161044. #endif
  161045. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161046. int num_chunk_list;
  161047. png_bytep chunk_list;
  161048. #endif
  161049. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161050. png_byte rgb_to_gray_status;
  161051. png_uint_16 rgb_to_gray_red_coeff;
  161052. png_uint_16 rgb_to_gray_green_coeff;
  161053. png_uint_16 rgb_to_gray_blue_coeff;
  161054. #endif
  161055. #if defined(PNG_MNG_FEATURES_SUPPORTED) || \
  161056. defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  161057. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  161058. #ifdef PNG_1_0_X
  161059. png_byte mng_features_permitted;
  161060. #else
  161061. png_uint_32 mng_features_permitted;
  161062. #endif /* PNG_1_0_X */
  161063. #endif
  161064. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  161065. png_fixed_point int_gamma;
  161066. #endif
  161067. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  161068. png_byte filter_type;
  161069. #endif
  161070. #if defined(PNG_1_0_X)
  161071. png_uint_32 row_buf_size;
  161072. #endif
  161073. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161074. # if !defined(PNG_1_0_X)
  161075. # if defined(PNG_MMX_CODE_SUPPORTED)
  161076. png_byte mmx_bitdepth_threshold;
  161077. png_uint_32 mmx_rowbytes_threshold;
  161078. # endif
  161079. png_uint_32 asm_flags;
  161080. # endif
  161081. #endif
  161082. #ifdef PNG_USER_MEM_SUPPORTED
  161083. png_voidp mem_ptr; /* user supplied struct for mem functions */
  161084. png_malloc_ptr malloc_fn; /* function for allocating memory */
  161085. png_free_ptr free_fn; /* function for freeing memory */
  161086. #endif
  161087. png_bytep big_row_buf; /* buffer to save current (unfiltered) row */
  161088. #if defined(PNG_READ_DITHER_SUPPORTED)
  161089. png_bytep dither_sort; /* working sort array */
  161090. png_bytep index_to_palette; /* where the original index currently is */
  161091. png_bytep palette_to_index; /* which original index points to this */
  161092. #endif
  161093. png_byte compression_type;
  161094. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161095. png_uint_32 user_width_max;
  161096. png_uint_32 user_height_max;
  161097. #endif
  161098. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161099. png_unknown_chunk unknown_chunk;
  161100. #endif
  161101. };
  161102. typedef png_structp version_1_2_21;
  161103. typedef png_struct FAR * FAR * png_structpp;
  161104. extern PNG_EXPORT(png_uint_32,png_access_version_number) PNGARG((void));
  161105. extern PNG_EXPORT(void,png_set_sig_bytes) PNGARG((png_structp png_ptr,
  161106. int num_bytes));
  161107. extern PNG_EXPORT(int,png_sig_cmp) PNGARG((png_bytep sig, png_size_t start,
  161108. png_size_t num_to_check));
  161109. extern PNG_EXPORT(int,png_check_sig) PNGARG((png_bytep sig, int num));
  161110. extern PNG_EXPORT(png_structp,png_create_read_struct)
  161111. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161112. png_error_ptr error_fn, png_error_ptr warn_fn));
  161113. extern PNG_EXPORT(png_structp,png_create_write_struct)
  161114. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161115. png_error_ptr error_fn, png_error_ptr warn_fn));
  161116. #ifdef PNG_WRITE_SUPPORTED
  161117. extern PNG_EXPORT(png_uint_32,png_get_compression_buffer_size)
  161118. PNGARG((png_structp png_ptr));
  161119. #endif
  161120. #ifdef PNG_WRITE_SUPPORTED
  161121. extern PNG_EXPORT(void,png_set_compression_buffer_size)
  161122. PNGARG((png_structp png_ptr, png_uint_32 size));
  161123. #endif
  161124. extern PNG_EXPORT(int,png_reset_zstream) PNGARG((png_structp png_ptr));
  161125. #ifdef PNG_USER_MEM_SUPPORTED
  161126. extern PNG_EXPORT(png_structp,png_create_read_struct_2)
  161127. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161128. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  161129. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161130. extern PNG_EXPORT(png_structp,png_create_write_struct_2)
  161131. PNGARG((png_const_charp user_png_ver, png_voidp error_ptr,
  161132. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  161133. png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161134. #endif
  161135. extern PNG_EXPORT(void,png_write_chunk) PNGARG((png_structp png_ptr,
  161136. png_bytep chunk_name, png_bytep data, png_size_t length));
  161137. extern PNG_EXPORT(void,png_write_chunk_start) PNGARG((png_structp png_ptr,
  161138. png_bytep chunk_name, png_uint_32 length));
  161139. extern PNG_EXPORT(void,png_write_chunk_data) PNGARG((png_structp png_ptr,
  161140. png_bytep data, png_size_t length));
  161141. extern PNG_EXPORT(void,png_write_chunk_end) PNGARG((png_structp png_ptr));
  161142. extern PNG_EXPORT(png_infop,png_create_info_struct)
  161143. PNGARG((png_structp png_ptr));
  161144. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161145. extern PNG_EXPORT(void,png_info_init) PNGARG((png_infop info_ptr));
  161146. #undef png_info_init
  161147. #define png_info_init(info_ptr) png_info_init_3(&info_ptr,\
  161148. png_sizeof(png_info));
  161149. #endif
  161150. extern PNG_EXPORT(void,png_info_init_3) PNGARG((png_infopp info_ptr,
  161151. png_size_t png_info_struct_size));
  161152. extern PNG_EXPORT(void,png_write_info_before_PLTE) PNGARG((png_structp png_ptr,
  161153. png_infop info_ptr));
  161154. extern PNG_EXPORT(void,png_write_info) PNGARG((png_structp png_ptr,
  161155. png_infop info_ptr));
  161156. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161157. extern PNG_EXPORT(void,png_read_info) PNGARG((png_structp png_ptr,
  161158. png_infop info_ptr));
  161159. #endif
  161160. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  161161. extern PNG_EXPORT(png_charp,png_convert_to_rfc1123)
  161162. PNGARG((png_structp png_ptr, png_timep ptime));
  161163. #endif
  161164. #if !defined(_WIN32_WCE)
  161165. #if defined(PNG_WRITE_tIME_SUPPORTED)
  161166. extern PNG_EXPORT(void,png_convert_from_struct_tm) PNGARG((png_timep ptime,
  161167. struct tm FAR * ttime));
  161168. extern PNG_EXPORT(void,png_convert_from_time_t) PNGARG((png_timep ptime,
  161169. time_t ttime));
  161170. #endif /* PNG_WRITE_tIME_SUPPORTED */
  161171. #endif /* _WIN32_WCE */
  161172. #if defined(PNG_READ_EXPAND_SUPPORTED)
  161173. extern PNG_EXPORT(void,png_set_expand) PNGARG((png_structp png_ptr));
  161174. #if !defined(PNG_1_0_X)
  161175. extern PNG_EXPORT(void,png_set_expand_gray_1_2_4_to_8) PNGARG((png_structp
  161176. png_ptr));
  161177. #endif
  161178. extern PNG_EXPORT(void,png_set_palette_to_rgb) PNGARG((png_structp png_ptr));
  161179. extern PNG_EXPORT(void,png_set_tRNS_to_alpha) PNGARG((png_structp png_ptr));
  161180. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161181. extern PNG_EXPORT(void,png_set_gray_1_2_4_to_8) PNGARG((png_structp png_ptr));
  161182. #endif
  161183. #endif
  161184. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  161185. extern PNG_EXPORT(void,png_set_bgr) PNGARG((png_structp png_ptr));
  161186. #endif
  161187. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  161188. extern PNG_EXPORT(void,png_set_gray_to_rgb) PNGARG((png_structp png_ptr));
  161189. #endif
  161190. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  161191. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161192. extern PNG_EXPORT(void,png_set_rgb_to_gray) PNGARG((png_structp png_ptr,
  161193. int error_action, double red, double green ));
  161194. #endif
  161195. extern PNG_EXPORT(void,png_set_rgb_to_gray_fixed) PNGARG((png_structp png_ptr,
  161196. int error_action, png_fixed_point red, png_fixed_point green ));
  161197. extern PNG_EXPORT(png_byte,png_get_rgb_to_gray_status) PNGARG((png_structp
  161198. png_ptr));
  161199. #endif
  161200. extern PNG_EXPORT(void,png_build_grayscale_palette) PNGARG((int bit_depth,
  161201. png_colorp palette));
  161202. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  161203. extern PNG_EXPORT(void,png_set_strip_alpha) PNGARG((png_structp png_ptr));
  161204. #endif
  161205. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  161206. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  161207. extern PNG_EXPORT(void,png_set_swap_alpha) PNGARG((png_structp png_ptr));
  161208. #endif
  161209. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  161210. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  161211. extern PNG_EXPORT(void,png_set_invert_alpha) PNGARG((png_structp png_ptr));
  161212. #endif
  161213. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  161214. extern PNG_EXPORT(void,png_set_filler) PNGARG((png_structp png_ptr,
  161215. png_uint_32 filler, int flags));
  161216. #define PNG_FILLER_BEFORE 0
  161217. #define PNG_FILLER_AFTER 1
  161218. #if !defined(PNG_1_0_X)
  161219. extern PNG_EXPORT(void,png_set_add_alpha) PNGARG((png_structp png_ptr,
  161220. png_uint_32 filler, int flags));
  161221. #endif
  161222. #endif /* PNG_READ_FILLER_SUPPORTED || PNG_WRITE_FILLER_SUPPORTED */
  161223. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  161224. extern PNG_EXPORT(void,png_set_swap) PNGARG((png_structp png_ptr));
  161225. #endif
  161226. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  161227. extern PNG_EXPORT(void,png_set_packing) PNGARG((png_structp png_ptr));
  161228. #endif
  161229. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  161230. extern PNG_EXPORT(void,png_set_packswap) PNGARG((png_structp png_ptr));
  161231. #endif
  161232. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  161233. extern PNG_EXPORT(void,png_set_shift) PNGARG((png_structp png_ptr,
  161234. png_color_8p true_bits));
  161235. #endif
  161236. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  161237. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  161238. extern PNG_EXPORT(int,png_set_interlace_handling) PNGARG((png_structp png_ptr));
  161239. #endif
  161240. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  161241. extern PNG_EXPORT(void,png_set_invert_mono) PNGARG((png_structp png_ptr));
  161242. #endif
  161243. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  161244. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161245. extern PNG_EXPORT(void,png_set_background) PNGARG((png_structp png_ptr,
  161246. png_color_16p background_color, int background_gamma_code,
  161247. int need_expand, double background_gamma));
  161248. #endif
  161249. #define PNG_BACKGROUND_GAMMA_UNKNOWN 0
  161250. #define PNG_BACKGROUND_GAMMA_SCREEN 1
  161251. #define PNG_BACKGROUND_GAMMA_FILE 2
  161252. #define PNG_BACKGROUND_GAMMA_UNIQUE 3
  161253. #endif
  161254. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  161255. extern PNG_EXPORT(void,png_set_strip_16) PNGARG((png_structp png_ptr));
  161256. #endif
  161257. #if defined(PNG_READ_DITHER_SUPPORTED)
  161258. extern PNG_EXPORT(void,png_set_dither) PNGARG((png_structp png_ptr,
  161259. png_colorp palette, int num_palette, int maximum_colors,
  161260. png_uint_16p histogram, int full_dither));
  161261. #endif
  161262. #if defined(PNG_READ_GAMMA_SUPPORTED)
  161263. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161264. extern PNG_EXPORT(void,png_set_gamma) PNGARG((png_structp png_ptr,
  161265. double screen_gamma, double default_file_gamma));
  161266. #endif
  161267. #endif
  161268. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  161269. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  161270. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  161271. extern PNG_EXPORT(void,png_permit_empty_plte) PNGARG((png_structp png_ptr,
  161272. int empty_plte_permitted));
  161273. #endif
  161274. #endif
  161275. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  161276. extern PNG_EXPORT(void,png_set_flush) PNGARG((png_structp png_ptr, int nrows));
  161277. extern PNG_EXPORT(void,png_write_flush) PNGARG((png_structp png_ptr));
  161278. #endif
  161279. extern PNG_EXPORT(void,png_start_read_image) PNGARG((png_structp png_ptr));
  161280. extern PNG_EXPORT(void,png_read_update_info) PNGARG((png_structp png_ptr,
  161281. png_infop info_ptr));
  161282. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161283. extern PNG_EXPORT(void,png_read_rows) PNGARG((png_structp png_ptr,
  161284. png_bytepp row, png_bytepp display_row, png_uint_32 num_rows));
  161285. #endif
  161286. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161287. extern PNG_EXPORT(void,png_read_row) PNGARG((png_structp png_ptr,
  161288. png_bytep row,
  161289. png_bytep display_row));
  161290. #endif
  161291. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161292. extern PNG_EXPORT(void,png_read_image) PNGARG((png_structp png_ptr,
  161293. png_bytepp image));
  161294. #endif
  161295. extern PNG_EXPORT(void,png_write_row) PNGARG((png_structp png_ptr,
  161296. png_bytep row));
  161297. extern PNG_EXPORT(void,png_write_rows) PNGARG((png_structp png_ptr,
  161298. png_bytepp row, png_uint_32 num_rows));
  161299. extern PNG_EXPORT(void,png_write_image) PNGARG((png_structp png_ptr,
  161300. png_bytepp image));
  161301. extern PNG_EXPORT(void,png_write_end) PNGARG((png_structp png_ptr,
  161302. png_infop info_ptr));
  161303. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  161304. extern PNG_EXPORT(void,png_read_end) PNGARG((png_structp png_ptr,
  161305. png_infop info_ptr));
  161306. #endif
  161307. extern PNG_EXPORT(void,png_destroy_info_struct) PNGARG((png_structp png_ptr,
  161308. png_infopp info_ptr_ptr));
  161309. extern PNG_EXPORT(void,png_destroy_read_struct) PNGARG((png_structpp
  161310. png_ptr_ptr, png_infopp info_ptr_ptr, png_infopp end_info_ptr_ptr));
  161311. extern void png_read_destroy PNGARG((png_structp png_ptr, png_infop info_ptr,
  161312. png_infop end_info_ptr));
  161313. extern PNG_EXPORT(void,png_destroy_write_struct)
  161314. PNGARG((png_structpp png_ptr_ptr, png_infopp info_ptr_ptr));
  161315. extern void png_write_destroy PNGARG((png_structp png_ptr));
  161316. extern PNG_EXPORT(void,png_set_crc_action) PNGARG((png_structp png_ptr,
  161317. int crit_action, int ancil_action));
  161318. #define PNG_CRC_DEFAULT 0 /* error/quit warn/discard data */
  161319. #define PNG_CRC_ERROR_QUIT 1 /* error/quit error/quit */
  161320. #define PNG_CRC_WARN_DISCARD 2 /* (INVALID) warn/discard data */
  161321. #define PNG_CRC_WARN_USE 3 /* warn/use data warn/use data */
  161322. #define PNG_CRC_QUIET_USE 4 /* quiet/use data quiet/use data */
  161323. #define PNG_CRC_NO_CHANGE 5 /* use current value use current value */
  161324. extern PNG_EXPORT(void,png_set_filter) PNGARG((png_structp png_ptr, int method,
  161325. int filters));
  161326. #define PNG_NO_FILTERS 0x00
  161327. #define PNG_FILTER_NONE 0x08
  161328. #define PNG_FILTER_SUB 0x10
  161329. #define PNG_FILTER_UP 0x20
  161330. #define PNG_FILTER_AVG 0x40
  161331. #define PNG_FILTER_PAETH 0x80
  161332. #define PNG_ALL_FILTERS (PNG_FILTER_NONE | PNG_FILTER_SUB | PNG_FILTER_UP | \
  161333. PNG_FILTER_AVG | PNG_FILTER_PAETH)
  161334. #define PNG_FILTER_VALUE_NONE 0
  161335. #define PNG_FILTER_VALUE_SUB 1
  161336. #define PNG_FILTER_VALUE_UP 2
  161337. #define PNG_FILTER_VALUE_AVG 3
  161338. #define PNG_FILTER_VALUE_PAETH 4
  161339. #define PNG_FILTER_VALUE_LAST 5
  161340. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* EXPERIMENTAL */
  161341. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161342. extern PNG_EXPORT(void,png_set_filter_heuristics) PNGARG((png_structp png_ptr,
  161343. int heuristic_method, int num_weights, png_doublep filter_weights,
  161344. png_doublep filter_costs));
  161345. #endif
  161346. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  161347. #define PNG_FILTER_HEURISTIC_DEFAULT 0 /* Currently "UNWEIGHTED" */
  161348. #define PNG_FILTER_HEURISTIC_UNWEIGHTED 1 /* Used by libpng < 0.95 */
  161349. #define PNG_FILTER_HEURISTIC_WEIGHTED 2 /* Experimental feature */
  161350. #define PNG_FILTER_HEURISTIC_LAST 3 /* Not a valid value */
  161351. extern PNG_EXPORT(void,png_set_compression_level) PNGARG((png_structp png_ptr,
  161352. int level));
  161353. extern PNG_EXPORT(void,png_set_compression_mem_level)
  161354. PNGARG((png_structp png_ptr, int mem_level));
  161355. extern PNG_EXPORT(void,png_set_compression_strategy)
  161356. PNGARG((png_structp png_ptr, int strategy));
  161357. extern PNG_EXPORT(void,png_set_compression_window_bits)
  161358. PNGARG((png_structp png_ptr, int window_bits));
  161359. extern PNG_EXPORT(void,png_set_compression_method) PNGARG((png_structp png_ptr,
  161360. int method));
  161361. #if !defined(PNG_NO_STDIO)
  161362. extern PNG_EXPORT(void,png_init_io) PNGARG((png_structp png_ptr, png_FILE_p fp));
  161363. #endif
  161364. extern PNG_EXPORT(void,png_set_error_fn) PNGARG((png_structp png_ptr,
  161365. png_voidp error_ptr, png_error_ptr error_fn, png_error_ptr warning_fn));
  161366. extern PNG_EXPORT(png_voidp,png_get_error_ptr) PNGARG((png_structp png_ptr));
  161367. extern PNG_EXPORT(void,png_set_write_fn) PNGARG((png_structp png_ptr,
  161368. png_voidp io_ptr, png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn));
  161369. extern PNG_EXPORT(void,png_set_read_fn) PNGARG((png_structp png_ptr,
  161370. png_voidp io_ptr, png_rw_ptr read_data_fn));
  161371. extern PNG_EXPORT(png_voidp,png_get_io_ptr) PNGARG((png_structp png_ptr));
  161372. extern PNG_EXPORT(void,png_set_read_status_fn) PNGARG((png_structp png_ptr,
  161373. png_read_status_ptr read_row_fn));
  161374. extern PNG_EXPORT(void,png_set_write_status_fn) PNGARG((png_structp png_ptr,
  161375. png_write_status_ptr write_row_fn));
  161376. #ifdef PNG_USER_MEM_SUPPORTED
  161377. extern PNG_EXPORT(void,png_set_mem_fn) PNGARG((png_structp png_ptr,
  161378. png_voidp mem_ptr, png_malloc_ptr malloc_fn, png_free_ptr free_fn));
  161379. extern PNG_EXPORT(png_voidp,png_get_mem_ptr) PNGARG((png_structp png_ptr));
  161380. #endif
  161381. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161382. defined(PNG_LEGACY_SUPPORTED)
  161383. extern PNG_EXPORT(void,png_set_read_user_transform_fn) PNGARG((png_structp
  161384. png_ptr, png_user_transform_ptr read_user_transform_fn));
  161385. #endif
  161386. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161387. defined(PNG_LEGACY_SUPPORTED)
  161388. extern PNG_EXPORT(void,png_set_write_user_transform_fn) PNGARG((png_structp
  161389. png_ptr, png_user_transform_ptr write_user_transform_fn));
  161390. #endif
  161391. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  161392. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  161393. defined(PNG_LEGACY_SUPPORTED)
  161394. extern PNG_EXPORT(void,png_set_user_transform_info) PNGARG((png_structp
  161395. png_ptr, png_voidp user_transform_ptr, int user_transform_depth,
  161396. int user_transform_channels));
  161397. extern PNG_EXPORT(png_voidp,png_get_user_transform_ptr)
  161398. PNGARG((png_structp png_ptr));
  161399. #endif
  161400. #ifdef PNG_USER_CHUNKS_SUPPORTED
  161401. extern PNG_EXPORT(void,png_set_read_user_chunk_fn) PNGARG((png_structp png_ptr,
  161402. png_voidp user_chunk_ptr, png_user_chunk_ptr read_user_chunk_fn));
  161403. extern PNG_EXPORT(png_voidp,png_get_user_chunk_ptr) PNGARG((png_structp
  161404. png_ptr));
  161405. #endif
  161406. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  161407. extern PNG_EXPORT(void,png_set_progressive_read_fn) PNGARG((png_structp png_ptr,
  161408. png_voidp progressive_ptr,
  161409. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  161410. png_progressive_end_ptr end_fn));
  161411. extern PNG_EXPORT(png_voidp,png_get_progressive_ptr)
  161412. PNGARG((png_structp png_ptr));
  161413. extern PNG_EXPORT(void,png_process_data) PNGARG((png_structp png_ptr,
  161414. png_infop info_ptr, png_bytep buffer, png_size_t buffer_size));
  161415. extern PNG_EXPORT(void,png_progressive_combine_row) PNGARG((png_structp png_ptr,
  161416. png_bytep old_row, png_bytep new_row));
  161417. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  161418. extern PNG_EXPORT(png_voidp,png_malloc) PNGARG((png_structp png_ptr,
  161419. png_uint_32 size));
  161420. #if defined(PNG_1_0_X)
  161421. # define png_malloc_warn png_malloc
  161422. #else
  161423. extern PNG_EXPORT(png_voidp,png_malloc_warn) PNGARG((png_structp png_ptr,
  161424. png_uint_32 size));
  161425. #endif
  161426. extern PNG_EXPORT(void,png_free) PNGARG((png_structp png_ptr, png_voidp ptr));
  161427. #if defined(PNG_1_0_X)
  161428. extern PNG_EXPORT(voidpf,png_zalloc) PNGARG((voidpf png_ptr, uInt items,
  161429. uInt size));
  161430. extern PNG_EXPORT(void,png_zfree) PNGARG((voidpf png_ptr, voidpf ptr));
  161431. #endif
  161432. extern PNG_EXPORT(void,png_free_data) PNGARG((png_structp png_ptr,
  161433. png_infop info_ptr, png_uint_32 free_me, int num));
  161434. #ifdef PNG_FREE_ME_SUPPORTED
  161435. extern PNG_EXPORT(void,png_data_freer) PNGARG((png_structp png_ptr,
  161436. png_infop info_ptr, int freer, png_uint_32 mask));
  161437. #endif
  161438. #define PNG_DESTROY_WILL_FREE_DATA 1
  161439. #define PNG_SET_WILL_FREE_DATA 1
  161440. #define PNG_USER_WILL_FREE_DATA 2
  161441. #define PNG_FREE_HIST 0x0008
  161442. #define PNG_FREE_ICCP 0x0010
  161443. #define PNG_FREE_SPLT 0x0020
  161444. #define PNG_FREE_ROWS 0x0040
  161445. #define PNG_FREE_PCAL 0x0080
  161446. #define PNG_FREE_SCAL 0x0100
  161447. #define PNG_FREE_UNKN 0x0200
  161448. #define PNG_FREE_LIST 0x0400
  161449. #define PNG_FREE_PLTE 0x1000
  161450. #define PNG_FREE_TRNS 0x2000
  161451. #define PNG_FREE_TEXT 0x4000
  161452. #define PNG_FREE_ALL 0x7fff
  161453. #define PNG_FREE_MUL 0x4220 /* PNG_FREE_SPLT|PNG_FREE_TEXT|PNG_FREE_UNKN */
  161454. #ifdef PNG_USER_MEM_SUPPORTED
  161455. extern PNG_EXPORT(png_voidp,png_malloc_default) PNGARG((png_structp png_ptr,
  161456. png_uint_32 size));
  161457. extern PNG_EXPORT(void,png_free_default) PNGARG((png_structp png_ptr,
  161458. png_voidp ptr));
  161459. #endif
  161460. extern PNG_EXPORT(png_voidp,png_memcpy_check) PNGARG((png_structp png_ptr,
  161461. png_voidp s1, png_voidp s2, png_uint_32 size));
  161462. extern PNG_EXPORT(png_voidp,png_memset_check) PNGARG((png_structp png_ptr,
  161463. png_voidp s1, int value, png_uint_32 size));
  161464. #if defined(USE_FAR_KEYWORD) /* memory model conversion function */
  161465. extern void *png_far_to_near PNGARG((png_structp png_ptr,png_voidp ptr,
  161466. int check));
  161467. #endif /* USE_FAR_KEYWORD */
  161468. #ifndef PNG_NO_ERROR_TEXT
  161469. extern PNG_EXPORT(void,png_error) PNGARG((png_structp png_ptr,
  161470. png_const_charp error_message));
  161471. extern PNG_EXPORT(void,png_chunk_error) PNGARG((png_structp png_ptr,
  161472. png_const_charp error_message));
  161473. #else
  161474. extern PNG_EXPORT(void,png_err) PNGARG((png_structp png_ptr));
  161475. #endif
  161476. #ifndef PNG_NO_WARNINGS
  161477. extern PNG_EXPORT(void,png_warning) PNGARG((png_structp png_ptr,
  161478. png_const_charp warning_message));
  161479. #ifdef PNG_READ_SUPPORTED
  161480. extern PNG_EXPORT(void,png_chunk_warning) PNGARG((png_structp png_ptr,
  161481. png_const_charp warning_message));
  161482. #endif /* PNG_READ_SUPPORTED */
  161483. #endif /* PNG_NO_WARNINGS */
  161484. extern PNG_EXPORT(png_uint_32,png_get_valid) PNGARG((png_structp png_ptr,
  161485. png_infop info_ptr, png_uint_32 flag));
  161486. extern PNG_EXPORT(png_uint_32,png_get_rowbytes) PNGARG((png_structp png_ptr,
  161487. png_infop info_ptr));
  161488. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161489. extern PNG_EXPORT(png_bytepp,png_get_rows) PNGARG((png_structp png_ptr,
  161490. png_infop info_ptr));
  161491. extern PNG_EXPORT(void,png_set_rows) PNGARG((png_structp png_ptr,
  161492. png_infop info_ptr, png_bytepp row_pointers));
  161493. #endif
  161494. extern PNG_EXPORT(png_byte,png_get_channels) PNGARG((png_structp png_ptr,
  161495. png_infop info_ptr));
  161496. #ifdef PNG_EASY_ACCESS_SUPPORTED
  161497. extern PNG_EXPORT(png_uint_32, png_get_image_width) PNGARG((png_structp
  161498. png_ptr, png_infop info_ptr));
  161499. extern PNG_EXPORT(png_uint_32, png_get_image_height) PNGARG((png_structp
  161500. png_ptr, png_infop info_ptr));
  161501. extern PNG_EXPORT(png_byte, png_get_bit_depth) PNGARG((png_structp
  161502. png_ptr, png_infop info_ptr));
  161503. extern PNG_EXPORT(png_byte, png_get_color_type) PNGARG((png_structp
  161504. png_ptr, png_infop info_ptr));
  161505. extern PNG_EXPORT(png_byte, png_get_filter_type) PNGARG((png_structp
  161506. png_ptr, png_infop info_ptr));
  161507. extern PNG_EXPORT(png_byte, png_get_interlace_type) PNGARG((png_structp
  161508. png_ptr, png_infop info_ptr));
  161509. extern PNG_EXPORT(png_byte, png_get_compression_type) PNGARG((png_structp
  161510. png_ptr, png_infop info_ptr));
  161511. extern PNG_EXPORT(png_uint_32, png_get_pixels_per_meter) PNGARG((png_structp
  161512. png_ptr, png_infop info_ptr));
  161513. extern PNG_EXPORT(png_uint_32, png_get_x_pixels_per_meter) PNGARG((png_structp
  161514. png_ptr, png_infop info_ptr));
  161515. extern PNG_EXPORT(png_uint_32, png_get_y_pixels_per_meter) PNGARG((png_structp
  161516. png_ptr, png_infop info_ptr));
  161517. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161518. extern PNG_EXPORT(float, png_get_pixel_aspect_ratio) PNGARG((png_structp
  161519. png_ptr, png_infop info_ptr));
  161520. #endif
  161521. extern PNG_EXPORT(png_int_32, png_get_x_offset_pixels) PNGARG((png_structp
  161522. png_ptr, png_infop info_ptr));
  161523. extern PNG_EXPORT(png_int_32, png_get_y_offset_pixels) PNGARG((png_structp
  161524. png_ptr, png_infop info_ptr));
  161525. extern PNG_EXPORT(png_int_32, png_get_x_offset_microns) PNGARG((png_structp
  161526. png_ptr, png_infop info_ptr));
  161527. extern PNG_EXPORT(png_int_32, png_get_y_offset_microns) PNGARG((png_structp
  161528. png_ptr, png_infop info_ptr));
  161529. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  161530. extern PNG_EXPORT(png_bytep,png_get_signature) PNGARG((png_structp png_ptr,
  161531. png_infop info_ptr));
  161532. #if defined(PNG_bKGD_SUPPORTED)
  161533. extern PNG_EXPORT(png_uint_32,png_get_bKGD) PNGARG((png_structp png_ptr,
  161534. png_infop info_ptr, png_color_16p *background));
  161535. #endif
  161536. #if defined(PNG_bKGD_SUPPORTED)
  161537. extern PNG_EXPORT(void,png_set_bKGD) PNGARG((png_structp png_ptr,
  161538. png_infop info_ptr, png_color_16p background));
  161539. #endif
  161540. #if defined(PNG_cHRM_SUPPORTED)
  161541. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161542. extern PNG_EXPORT(png_uint_32,png_get_cHRM) PNGARG((png_structp png_ptr,
  161543. png_infop info_ptr, double *white_x, double *white_y, double *red_x,
  161544. double *red_y, double *green_x, double *green_y, double *blue_x,
  161545. double *blue_y));
  161546. #endif
  161547. #ifdef PNG_FIXED_POINT_SUPPORTED
  161548. extern PNG_EXPORT(png_uint_32,png_get_cHRM_fixed) PNGARG((png_structp png_ptr,
  161549. png_infop info_ptr, png_fixed_point *int_white_x, png_fixed_point
  161550. *int_white_y, png_fixed_point *int_red_x, png_fixed_point *int_red_y,
  161551. png_fixed_point *int_green_x, png_fixed_point *int_green_y, png_fixed_point
  161552. *int_blue_x, png_fixed_point *int_blue_y));
  161553. #endif
  161554. #endif
  161555. #if defined(PNG_cHRM_SUPPORTED)
  161556. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161557. extern PNG_EXPORT(void,png_set_cHRM) PNGARG((png_structp png_ptr,
  161558. png_infop info_ptr, double white_x, double white_y, double red_x,
  161559. double red_y, double green_x, double green_y, double blue_x, double blue_y));
  161560. #endif
  161561. #ifdef PNG_FIXED_POINT_SUPPORTED
  161562. extern PNG_EXPORT(void,png_set_cHRM_fixed) PNGARG((png_structp png_ptr,
  161563. png_infop info_ptr, png_fixed_point int_white_x, png_fixed_point int_white_y,
  161564. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  161565. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  161566. png_fixed_point int_blue_y));
  161567. #endif
  161568. #endif
  161569. #if defined(PNG_gAMA_SUPPORTED)
  161570. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161571. extern PNG_EXPORT(png_uint_32,png_get_gAMA) PNGARG((png_structp png_ptr,
  161572. png_infop info_ptr, double *file_gamma));
  161573. #endif
  161574. extern PNG_EXPORT(png_uint_32,png_get_gAMA_fixed) PNGARG((png_structp png_ptr,
  161575. png_infop info_ptr, png_fixed_point *int_file_gamma));
  161576. #endif
  161577. #if defined(PNG_gAMA_SUPPORTED)
  161578. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161579. extern PNG_EXPORT(void,png_set_gAMA) PNGARG((png_structp png_ptr,
  161580. png_infop info_ptr, double file_gamma));
  161581. #endif
  161582. extern PNG_EXPORT(void,png_set_gAMA_fixed) PNGARG((png_structp png_ptr,
  161583. png_infop info_ptr, png_fixed_point int_file_gamma));
  161584. #endif
  161585. #if defined(PNG_hIST_SUPPORTED)
  161586. extern PNG_EXPORT(png_uint_32,png_get_hIST) PNGARG((png_structp png_ptr,
  161587. png_infop info_ptr, png_uint_16p *hist));
  161588. #endif
  161589. #if defined(PNG_hIST_SUPPORTED)
  161590. extern PNG_EXPORT(void,png_set_hIST) PNGARG((png_structp png_ptr,
  161591. png_infop info_ptr, png_uint_16p hist));
  161592. #endif
  161593. extern PNG_EXPORT(png_uint_32,png_get_IHDR) PNGARG((png_structp png_ptr,
  161594. png_infop info_ptr, png_uint_32 *width, png_uint_32 *height,
  161595. int *bit_depth, int *color_type, int *interlace_method,
  161596. int *compression_method, int *filter_method));
  161597. extern PNG_EXPORT(void,png_set_IHDR) PNGARG((png_structp png_ptr,
  161598. png_infop info_ptr, png_uint_32 width, png_uint_32 height, int bit_depth,
  161599. int color_type, int interlace_method, int compression_method,
  161600. int filter_method));
  161601. #if defined(PNG_oFFs_SUPPORTED)
  161602. extern PNG_EXPORT(png_uint_32,png_get_oFFs) PNGARG((png_structp png_ptr,
  161603. png_infop info_ptr, png_int_32 *offset_x, png_int_32 *offset_y,
  161604. int *unit_type));
  161605. #endif
  161606. #if defined(PNG_oFFs_SUPPORTED)
  161607. extern PNG_EXPORT(void,png_set_oFFs) PNGARG((png_structp png_ptr,
  161608. png_infop info_ptr, png_int_32 offset_x, png_int_32 offset_y,
  161609. int unit_type));
  161610. #endif
  161611. #if defined(PNG_pCAL_SUPPORTED)
  161612. extern PNG_EXPORT(png_uint_32,png_get_pCAL) PNGARG((png_structp png_ptr,
  161613. png_infop info_ptr, png_charp *purpose, png_int_32 *X0, png_int_32 *X1,
  161614. int *type, int *nparams, png_charp *units, png_charpp *params));
  161615. #endif
  161616. #if defined(PNG_pCAL_SUPPORTED)
  161617. extern PNG_EXPORT(void,png_set_pCAL) PNGARG((png_structp png_ptr,
  161618. png_infop info_ptr, png_charp purpose, png_int_32 X0, png_int_32 X1,
  161619. int type, int nparams, png_charp units, png_charpp params));
  161620. #endif
  161621. #if defined(PNG_pHYs_SUPPORTED)
  161622. extern PNG_EXPORT(png_uint_32,png_get_pHYs) PNGARG((png_structp png_ptr,
  161623. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  161624. #endif
  161625. #if defined(PNG_pHYs_SUPPORTED)
  161626. extern PNG_EXPORT(void,png_set_pHYs) PNGARG((png_structp png_ptr,
  161627. png_infop info_ptr, png_uint_32 res_x, png_uint_32 res_y, int unit_type));
  161628. #endif
  161629. extern PNG_EXPORT(png_uint_32,png_get_PLTE) PNGARG((png_structp png_ptr,
  161630. png_infop info_ptr, png_colorp *palette, int *num_palette));
  161631. extern PNG_EXPORT(void,png_set_PLTE) PNGARG((png_structp png_ptr,
  161632. png_infop info_ptr, png_colorp palette, int num_palette));
  161633. #if defined(PNG_sBIT_SUPPORTED)
  161634. extern PNG_EXPORT(png_uint_32,png_get_sBIT) PNGARG((png_structp png_ptr,
  161635. png_infop info_ptr, png_color_8p *sig_bit));
  161636. #endif
  161637. #if defined(PNG_sBIT_SUPPORTED)
  161638. extern PNG_EXPORT(void,png_set_sBIT) PNGARG((png_structp png_ptr,
  161639. png_infop info_ptr, png_color_8p sig_bit));
  161640. #endif
  161641. #if defined(PNG_sRGB_SUPPORTED)
  161642. extern PNG_EXPORT(png_uint_32,png_get_sRGB) PNGARG((png_structp png_ptr,
  161643. png_infop info_ptr, int *intent));
  161644. #endif
  161645. #if defined(PNG_sRGB_SUPPORTED)
  161646. extern PNG_EXPORT(void,png_set_sRGB) PNGARG((png_structp png_ptr,
  161647. png_infop info_ptr, int intent));
  161648. extern PNG_EXPORT(void,png_set_sRGB_gAMA_and_cHRM) PNGARG((png_structp png_ptr,
  161649. png_infop info_ptr, int intent));
  161650. #endif
  161651. #if defined(PNG_iCCP_SUPPORTED)
  161652. extern PNG_EXPORT(png_uint_32,png_get_iCCP) PNGARG((png_structp png_ptr,
  161653. png_infop info_ptr, png_charpp name, int *compression_type,
  161654. png_charpp profile, png_uint_32 *proflen));
  161655. #endif
  161656. #if defined(PNG_iCCP_SUPPORTED)
  161657. extern PNG_EXPORT(void,png_set_iCCP) PNGARG((png_structp png_ptr,
  161658. png_infop info_ptr, png_charp name, int compression_type,
  161659. png_charp profile, png_uint_32 proflen));
  161660. #endif
  161661. #if defined(PNG_sPLT_SUPPORTED)
  161662. extern PNG_EXPORT(png_uint_32,png_get_sPLT) PNGARG((png_structp png_ptr,
  161663. png_infop info_ptr, png_sPLT_tpp entries));
  161664. #endif
  161665. #if defined(PNG_sPLT_SUPPORTED)
  161666. extern PNG_EXPORT(void,png_set_sPLT) PNGARG((png_structp png_ptr,
  161667. png_infop info_ptr, png_sPLT_tp entries, int nentries));
  161668. #endif
  161669. #if defined(PNG_TEXT_SUPPORTED)
  161670. extern PNG_EXPORT(png_uint_32,png_get_text) PNGARG((png_structp png_ptr,
  161671. png_infop info_ptr, png_textp *text_ptr, int *num_text));
  161672. #endif
  161673. #if defined(PNG_TEXT_SUPPORTED)
  161674. extern PNG_EXPORT(void,png_set_text) PNGARG((png_structp png_ptr,
  161675. png_infop info_ptr, png_textp text_ptr, int num_text));
  161676. #endif
  161677. #if defined(PNG_tIME_SUPPORTED)
  161678. extern PNG_EXPORT(png_uint_32,png_get_tIME) PNGARG((png_structp png_ptr,
  161679. png_infop info_ptr, png_timep *mod_time));
  161680. #endif
  161681. #if defined(PNG_tIME_SUPPORTED)
  161682. extern PNG_EXPORT(void,png_set_tIME) PNGARG((png_structp png_ptr,
  161683. png_infop info_ptr, png_timep mod_time));
  161684. #endif
  161685. #if defined(PNG_tRNS_SUPPORTED)
  161686. extern PNG_EXPORT(png_uint_32,png_get_tRNS) PNGARG((png_structp png_ptr,
  161687. png_infop info_ptr, png_bytep *trans, int *num_trans,
  161688. png_color_16p *trans_values));
  161689. #endif
  161690. #if defined(PNG_tRNS_SUPPORTED)
  161691. extern PNG_EXPORT(void,png_set_tRNS) PNGARG((png_structp png_ptr,
  161692. png_infop info_ptr, png_bytep trans, int num_trans,
  161693. png_color_16p trans_values));
  161694. #endif
  161695. #if defined(PNG_tRNS_SUPPORTED)
  161696. #endif
  161697. #if defined(PNG_sCAL_SUPPORTED)
  161698. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161699. extern PNG_EXPORT(png_uint_32,png_get_sCAL) PNGARG((png_structp png_ptr,
  161700. png_infop info_ptr, int *unit, double *width, double *height));
  161701. #else
  161702. #ifdef PNG_FIXED_POINT_SUPPORTED
  161703. extern PNG_EXPORT(png_uint_32,png_get_sCAL_s) PNGARG((png_structp png_ptr,
  161704. png_infop info_ptr, int *unit, png_charpp swidth, png_charpp sheight));
  161705. #endif
  161706. #endif
  161707. #endif /* PNG_sCAL_SUPPORTED */
  161708. #if defined(PNG_sCAL_SUPPORTED)
  161709. #ifdef PNG_FLOATING_POINT_SUPPORTED
  161710. extern PNG_EXPORT(void,png_set_sCAL) PNGARG((png_structp png_ptr,
  161711. png_infop info_ptr, int unit, double width, double height));
  161712. #else
  161713. #ifdef PNG_FIXED_POINT_SUPPORTED
  161714. extern PNG_EXPORT(void,png_set_sCAL_s) PNGARG((png_structp png_ptr,
  161715. png_infop info_ptr, int unit, png_charp swidth, png_charp sheight));
  161716. #endif
  161717. #endif
  161718. #endif /* PNG_sCAL_SUPPORTED || PNG_WRITE_sCAL_SUPPORTED */
  161719. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  161720. extern PNG_EXPORT(void, png_set_keep_unknown_chunks) PNGARG((png_structp
  161721. png_ptr, int keep, png_bytep chunk_list, int num_chunks));
  161722. extern PNG_EXPORT(void, png_set_unknown_chunks) PNGARG((png_structp png_ptr,
  161723. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns));
  161724. extern PNG_EXPORT(void, png_set_unknown_chunk_location)
  161725. PNGARG((png_structp png_ptr, png_infop info_ptr, int chunk, int location));
  161726. extern PNG_EXPORT(png_uint_32,png_get_unknown_chunks) PNGARG((png_structp
  161727. png_ptr, png_infop info_ptr, png_unknown_chunkpp entries));
  161728. #endif
  161729. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  161730. PNG_EXPORT(int,png_handle_as_unknown) PNGARG((png_structp png_ptr, png_bytep
  161731. chunk_name));
  161732. #endif
  161733. extern PNG_EXPORT(void, png_set_invalid) PNGARG((png_structp png_ptr,
  161734. png_infop info_ptr, int mask));
  161735. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  161736. extern PNG_EXPORT(void, png_read_png) PNGARG((png_structp png_ptr,
  161737. png_infop info_ptr,
  161738. int transforms,
  161739. png_voidp params));
  161740. extern PNG_EXPORT(void, png_write_png) PNGARG((png_structp png_ptr,
  161741. png_infop info_ptr,
  161742. int transforms,
  161743. png_voidp params));
  161744. #endif
  161745. #ifdef PNG_DEBUG
  161746. #if (PNG_DEBUG > 0)
  161747. #if !defined(PNG_DEBUG_FILE) && defined(_MSC_VER)
  161748. #include <crtdbg.h>
  161749. #if (PNG_DEBUG > 1)
  161750. #define png_debug(l,m) _RPT0(_CRT_WARN,m)
  161751. #define png_debug1(l,m,p1) _RPT1(_CRT_WARN,m,p1)
  161752. #define png_debug2(l,m,p1,p2) _RPT2(_CRT_WARN,m,p1,p2)
  161753. #endif
  161754. #else /* PNG_DEBUG_FILE || !_MSC_VER */
  161755. #ifndef PNG_DEBUG_FILE
  161756. #define PNG_DEBUG_FILE stderr
  161757. #endif /* PNG_DEBUG_FILE */
  161758. #if (PNG_DEBUG > 1)
  161759. #define png_debug(l,m) \
  161760. { \
  161761. int num_tabs=l; \
  161762. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161763. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":"")))); \
  161764. }
  161765. #define png_debug1(l,m,p1) \
  161766. { \
  161767. int num_tabs=l; \
  161768. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161769. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1); \
  161770. }
  161771. #define png_debug2(l,m,p1,p2) \
  161772. { \
  161773. int num_tabs=l; \
  161774. fprintf(PNG_DEBUG_FILE,"%s"m,(num_tabs==1 ? "\t" : \
  161775. (num_tabs==2 ? "\t\t":(num_tabs>2 ? "\t\t\t":""))),p1,p2); \
  161776. }
  161777. #endif /* (PNG_DEBUG > 1) */
  161778. #endif /* _MSC_VER */
  161779. #endif /* (PNG_DEBUG > 0) */
  161780. #endif /* PNG_DEBUG */
  161781. #ifndef png_debug
  161782. #define png_debug(l, m)
  161783. #endif
  161784. #ifndef png_debug1
  161785. #define png_debug1(l, m, p1)
  161786. #endif
  161787. #ifndef png_debug2
  161788. #define png_debug2(l, m, p1, p2)
  161789. #endif
  161790. extern PNG_EXPORT(png_charp,png_get_copyright) PNGARG((png_structp png_ptr));
  161791. extern PNG_EXPORT(png_charp,png_get_header_ver) PNGARG((png_structp png_ptr));
  161792. extern PNG_EXPORT(png_charp,png_get_header_version) PNGARG((png_structp png_ptr));
  161793. extern PNG_EXPORT(png_charp,png_get_libpng_ver) PNGARG((png_structp png_ptr));
  161794. #ifdef PNG_MNG_FEATURES_SUPPORTED
  161795. extern PNG_EXPORT(png_uint_32,png_permit_mng_features) PNGARG((png_structp
  161796. png_ptr, png_uint_32 mng_features_permitted));
  161797. #endif
  161798. #define PNG_HANDLE_CHUNK_AS_DEFAULT 0
  161799. #define PNG_HANDLE_CHUNK_NEVER 1
  161800. #define PNG_HANDLE_CHUNK_IF_SAFE 2
  161801. #define PNG_HANDLE_CHUNK_ALWAYS 3
  161802. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  161803. #if defined(PNG_MMX_CODE_SUPPORTED)
  161804. #define PNG_ASM_FLAG_MMX_SUPPORT_COMPILED 0x01 /* not user-settable */
  161805. #define PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU 0x02 /* not user-settable */
  161806. #define PNG_ASM_FLAG_MMX_READ_COMBINE_ROW 0x04
  161807. #define PNG_ASM_FLAG_MMX_READ_INTERLACE 0x08
  161808. #define PNG_ASM_FLAG_MMX_READ_FILTER_SUB 0x10
  161809. #define PNG_ASM_FLAG_MMX_READ_FILTER_UP 0x20
  161810. #define PNG_ASM_FLAG_MMX_READ_FILTER_AVG 0x40
  161811. #define PNG_ASM_FLAG_MMX_READ_FILTER_PAETH 0x80
  161812. #define PNG_ASM_FLAGS_INITIALIZED 0x80000000 /* not user-settable */
  161813. #define PNG_MMX_READ_FLAGS ( PNG_ASM_FLAG_MMX_READ_COMBINE_ROW \
  161814. | PNG_ASM_FLAG_MMX_READ_INTERLACE \
  161815. | PNG_ASM_FLAG_MMX_READ_FILTER_SUB \
  161816. | PNG_ASM_FLAG_MMX_READ_FILTER_UP \
  161817. | PNG_ASM_FLAG_MMX_READ_FILTER_AVG \
  161818. | PNG_ASM_FLAG_MMX_READ_FILTER_PAETH )
  161819. #define PNG_MMX_WRITE_FLAGS ( 0 )
  161820. #define PNG_MMX_FLAGS ( PNG_ASM_FLAG_MMX_SUPPORT_COMPILED \
  161821. | PNG_ASM_FLAG_MMX_SUPPORT_IN_CPU \
  161822. | PNG_MMX_READ_FLAGS \
  161823. | PNG_MMX_WRITE_FLAGS )
  161824. #define PNG_SELECT_READ 1
  161825. #define PNG_SELECT_WRITE 2
  161826. #endif /* PNG_MMX_CODE_SUPPORTED */
  161827. #if !defined(PNG_1_0_X)
  161828. extern PNG_EXPORT(png_uint_32,png_get_mmx_flagmask)
  161829. PNGARG((int flag_select, int *compilerID));
  161830. extern PNG_EXPORT(png_uint_32,png_get_asm_flagmask)
  161831. PNGARG((int flag_select));
  161832. extern PNG_EXPORT(png_uint_32,png_get_asm_flags)
  161833. PNGARG((png_structp png_ptr));
  161834. extern PNG_EXPORT(png_byte,png_get_mmx_bitdepth_threshold)
  161835. PNGARG((png_structp png_ptr));
  161836. extern PNG_EXPORT(png_uint_32,png_get_mmx_rowbytes_threshold)
  161837. PNGARG((png_structp png_ptr));
  161838. extern PNG_EXPORT(void,png_set_asm_flags)
  161839. PNGARG((png_structp png_ptr, png_uint_32 asm_flags));
  161840. extern PNG_EXPORT(void,png_set_mmx_thresholds)
  161841. PNGARG((png_structp png_ptr, png_byte mmx_bitdepth_threshold,
  161842. png_uint_32 mmx_rowbytes_threshold));
  161843. #endif /* PNG_1_0_X */
  161844. #if !defined(PNG_1_0_X)
  161845. extern PNG_EXPORT(int,png_mmx_support) PNGARG((void));
  161846. #endif /* PNG_ASSEMBLER_CODE_SUPPORTED */
  161847. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  161848. extern PNG_EXPORT(void,png_set_strip_error_numbers) PNGARG((png_structp
  161849. png_ptr, png_uint_32 strip_mode));
  161850. #endif
  161851. #endif /* PNG_1_0_X */
  161852. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  161853. extern PNG_EXPORT(void,png_set_user_limits) PNGARG((png_structp
  161854. png_ptr, png_uint_32 user_width_max, png_uint_32 user_height_max));
  161855. extern PNG_EXPORT(png_uint_32,png_get_user_width_max) PNGARG((png_structp
  161856. png_ptr));
  161857. extern PNG_EXPORT(png_uint_32,png_get_user_height_max) PNGARG((png_structp
  161858. png_ptr));
  161859. #endif
  161860. #ifdef PNG_READ_COMPOSITE_NODIV_SUPPORTED
  161861. # define png_composite(composite, fg, alpha, bg) \
  161862. { png_uint_16 temp = (png_uint_16)((png_uint_16)(fg) * (png_uint_16)(alpha) \
  161863. + (png_uint_16)(bg)*(png_uint_16)(255 - \
  161864. (png_uint_16)(alpha)) + (png_uint_16)128); \
  161865. (composite) = (png_byte)((temp + (temp >> 8)) >> 8); }
  161866. # define png_composite_16(composite, fg, alpha, bg) \
  161867. { png_uint_32 temp = (png_uint_32)((png_uint_32)(fg) * (png_uint_32)(alpha) \
  161868. + (png_uint_32)(bg)*(png_uint_32)(65535L - \
  161869. (png_uint_32)(alpha)) + (png_uint_32)32768L); \
  161870. (composite) = (png_uint_16)((temp + (temp >> 16)) >> 16); }
  161871. #else /* standard method using integer division */
  161872. # define png_composite(composite, fg, alpha, bg) \
  161873. (composite) = (png_byte)(((png_uint_16)(fg) * (png_uint_16)(alpha) + \
  161874. (png_uint_16)(bg) * (png_uint_16)(255 - (png_uint_16)(alpha)) + \
  161875. (png_uint_16)127) / 255)
  161876. # define png_composite_16(composite, fg, alpha, bg) \
  161877. (composite) = (png_uint_16)(((png_uint_32)(fg) * (png_uint_32)(alpha) + \
  161878. (png_uint_32)(bg)*(png_uint_32)(65535L - (png_uint_32)(alpha)) + \
  161879. (png_uint_32)32767) / (png_uint_32)65535L)
  161880. #endif /* PNG_READ_COMPOSITE_NODIV_SUPPORTED */
  161881. #if defined(PNG_READ_BIG_ENDIAN_SUPPORTED)
  161882. # define png_get_uint_32(buf) ( *((png_uint_32p) (buf)))
  161883. # define png_get_uint_16(buf) ( *((png_uint_16p) (buf)))
  161884. # define png_get_int_32(buf) ( *((png_int_32p) (buf)))
  161885. #else
  161886. extern PNG_EXPORT(png_uint_32,png_get_uint_32) PNGARG((png_bytep buf));
  161887. extern PNG_EXPORT(png_uint_16,png_get_uint_16) PNGARG((png_bytep buf));
  161888. extern PNG_EXPORT(png_int_32,png_get_int_32) PNGARG((png_bytep buf));
  161889. #endif /* !PNG_READ_BIG_ENDIAN_SUPPORTED */
  161890. extern PNG_EXPORT(png_uint_32,png_get_uint_31)
  161891. PNGARG((png_structp png_ptr, png_bytep buf));
  161892. extern PNG_EXPORT(void,png_save_uint_32)
  161893. PNGARG((png_bytep buf, png_uint_32 i));
  161894. extern PNG_EXPORT(void,png_save_int_32)
  161895. PNGARG((png_bytep buf, png_int_32 i));
  161896. extern PNG_EXPORT(void,png_save_uint_16)
  161897. PNGARG((png_bytep buf, unsigned int i));
  161898. #define PNG_HAVE_IHDR 0x01
  161899. #define PNG_HAVE_PLTE 0x02
  161900. #define PNG_HAVE_IDAT 0x04
  161901. #define PNG_AFTER_IDAT 0x08 /* Have complete zlib datastream */
  161902. #define PNG_HAVE_IEND 0x10
  161903. #if defined(PNG_INTERNAL)
  161904. #define PNG_HAVE_gAMA 0x20
  161905. #define PNG_HAVE_cHRM 0x40
  161906. #define PNG_HAVE_sRGB 0x80
  161907. #define PNG_HAVE_CHUNK_HEADER 0x100
  161908. #define PNG_WROTE_tIME 0x200
  161909. #define PNG_WROTE_INFO_BEFORE_PLTE 0x400
  161910. #define PNG_BACKGROUND_IS_GRAY 0x800
  161911. #define PNG_HAVE_PNG_SIGNATURE 0x1000
  161912. #define PNG_HAVE_CHUNK_AFTER_IDAT 0x2000 /* Have another chunk after IDAT */
  161913. #define PNG_BGR 0x0001
  161914. #define PNG_INTERLACE 0x0002
  161915. #define PNG_PACK 0x0004
  161916. #define PNG_SHIFT 0x0008
  161917. #define PNG_SWAP_BYTES 0x0010
  161918. #define PNG_INVERT_MONO 0x0020
  161919. #define PNG_DITHER 0x0040
  161920. #define PNG_BACKGROUND 0x0080
  161921. #define PNG_BACKGROUND_EXPAND 0x0100
  161922. #define PNG_16_TO_8 0x0400
  161923. #define PNG_RGBA 0x0800
  161924. #define PNG_EXPAND 0x1000
  161925. #define PNG_GAMMA 0x2000
  161926. #define PNG_GRAY_TO_RGB 0x4000
  161927. #define PNG_FILLER 0x8000L
  161928. #define PNG_PACKSWAP 0x10000L
  161929. #define PNG_SWAP_ALPHA 0x20000L
  161930. #define PNG_STRIP_ALPHA 0x40000L
  161931. #define PNG_INVERT_ALPHA 0x80000L
  161932. #define PNG_USER_TRANSFORM 0x100000L
  161933. #define PNG_RGB_TO_GRAY_ERR 0x200000L
  161934. #define PNG_RGB_TO_GRAY_WARN 0x400000L
  161935. #define PNG_RGB_TO_GRAY 0x600000L /* two bits, RGB_TO_GRAY_ERR|WARN */
  161936. #define PNG_ADD_ALPHA 0x1000000L /* Added to libpng-1.2.7 */
  161937. #define PNG_EXPAND_tRNS 0x2000000L /* Added to libpng-1.2.9 */
  161938. #define PNG_STRUCT_PNG 0x0001
  161939. #define PNG_STRUCT_INFO 0x0002
  161940. #define PNG_WEIGHT_SHIFT 8
  161941. #define PNG_WEIGHT_FACTOR (1<<(PNG_WEIGHT_SHIFT))
  161942. #define PNG_COST_SHIFT 3
  161943. #define PNG_COST_FACTOR (1<<(PNG_COST_SHIFT))
  161944. #define PNG_FLAG_ZLIB_CUSTOM_STRATEGY 0x0001
  161945. #define PNG_FLAG_ZLIB_CUSTOM_LEVEL 0x0002
  161946. #define PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL 0x0004
  161947. #define PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS 0x0008
  161948. #define PNG_FLAG_ZLIB_CUSTOM_METHOD 0x0010
  161949. #define PNG_FLAG_ZLIB_FINISHED 0x0020
  161950. #define PNG_FLAG_ROW_INIT 0x0040
  161951. #define PNG_FLAG_FILLER_AFTER 0x0080
  161952. #define PNG_FLAG_CRC_ANCILLARY_USE 0x0100
  161953. #define PNG_FLAG_CRC_ANCILLARY_NOWARN 0x0200
  161954. #define PNG_FLAG_CRC_CRITICAL_USE 0x0400
  161955. #define PNG_FLAG_CRC_CRITICAL_IGNORE 0x0800
  161956. #define PNG_FLAG_FREE_PLTE 0x1000
  161957. #define PNG_FLAG_FREE_TRNS 0x2000
  161958. #define PNG_FLAG_FREE_HIST 0x4000
  161959. #define PNG_FLAG_KEEP_UNKNOWN_CHUNKS 0x8000L
  161960. #define PNG_FLAG_KEEP_UNSAFE_CHUNKS 0x10000L
  161961. #define PNG_FLAG_LIBRARY_MISMATCH 0x20000L
  161962. #define PNG_FLAG_STRIP_ERROR_NUMBERS 0x40000L
  161963. #define PNG_FLAG_STRIP_ERROR_TEXT 0x80000L
  161964. #define PNG_FLAG_MALLOC_NULL_MEM_OK 0x100000L
  161965. #define PNG_FLAG_ADD_ALPHA 0x200000L /* Added to libpng-1.2.8 */
  161966. #define PNG_FLAG_STRIP_ALPHA 0x400000L /* Added to libpng-1.2.8 */
  161967. #define PNG_FLAG_CRC_ANCILLARY_MASK (PNG_FLAG_CRC_ANCILLARY_USE | \
  161968. PNG_FLAG_CRC_ANCILLARY_NOWARN)
  161969. #define PNG_FLAG_CRC_CRITICAL_MASK (PNG_FLAG_CRC_CRITICAL_USE | \
  161970. PNG_FLAG_CRC_CRITICAL_IGNORE)
  161971. #define PNG_FLAG_CRC_MASK (PNG_FLAG_CRC_ANCILLARY_MASK | \
  161972. PNG_FLAG_CRC_CRITICAL_MASK)
  161973. #define PNG_COLOR_DIST(c1, c2) (abs((int)((c1).red) - (int)((c2).red)) + \
  161974. abs((int)((c1).green) - (int)((c2).green)) + \
  161975. abs((int)((c1).blue) - (int)((c2).blue)))
  161976. #define PNG_ROWBYTES(pixel_bits, width) \
  161977. ((pixel_bits) >= 8 ? \
  161978. ((width) * (((png_uint_32)(pixel_bits)) >> 3)) : \
  161979. (( ((width) * ((png_uint_32)(pixel_bits))) + 7) >> 3) )
  161980. #define PNG_OUT_OF_RANGE(value, ideal, delta) \
  161981. ( (value) < (ideal)-(delta) || (value) > (ideal)+(delta) )
  161982. #if !defined(PNG_NO_EXTERN) || defined(PNG_ALWAYS_EXTERN)
  161983. #ifdef PNG_USE_GLOBAL_ARRAYS
  161984. PNG_EXPORT_VAR (PNG_CONST png_byte FARDATA) png_sig[8];
  161985. #else
  161986. #endif
  161987. #endif /* PNG_NO_EXTERN */
  161988. #define PNG_IHDR png_byte png_IHDR[5] = { 73, 72, 68, 82, '\0'}
  161989. #define PNG_IDAT png_byte png_IDAT[5] = { 73, 68, 65, 84, '\0'}
  161990. #define PNG_IEND png_byte png_IEND[5] = { 73, 69, 78, 68, '\0'}
  161991. #define PNG_PLTE png_byte png_PLTE[5] = { 80, 76, 84, 69, '\0'}
  161992. #define PNG_bKGD png_byte png_bKGD[5] = { 98, 75, 71, 68, '\0'}
  161993. #define PNG_cHRM png_byte png_cHRM[5] = { 99, 72, 82, 77, '\0'}
  161994. #define PNG_gAMA png_byte png_gAMA[5] = {103, 65, 77, 65, '\0'}
  161995. #define PNG_hIST png_byte png_hIST[5] = {104, 73, 83, 84, '\0'}
  161996. #define PNG_iCCP png_byte png_iCCP[5] = {105, 67, 67, 80, '\0'}
  161997. #define PNG_iTXt png_byte png_iTXt[5] = {105, 84, 88, 116, '\0'}
  161998. #define PNG_oFFs png_byte png_oFFs[5] = {111, 70, 70, 115, '\0'}
  161999. #define PNG_pCAL png_byte png_pCAL[5] = {112, 67, 65, 76, '\0'}
  162000. #define PNG_sCAL png_byte png_sCAL[5] = {115, 67, 65, 76, '\0'}
  162001. #define PNG_pHYs png_byte png_pHYs[5] = {112, 72, 89, 115, '\0'}
  162002. #define PNG_sBIT png_byte png_sBIT[5] = {115, 66, 73, 84, '\0'}
  162003. #define PNG_sPLT png_byte png_sPLT[5] = {115, 80, 76, 84, '\0'}
  162004. #define PNG_sRGB png_byte png_sRGB[5] = {115, 82, 71, 66, '\0'}
  162005. #define PNG_tEXt png_byte png_tEXt[5] = {116, 69, 88, 116, '\0'}
  162006. #define PNG_tIME png_byte png_tIME[5] = {116, 73, 77, 69, '\0'}
  162007. #define PNG_tRNS png_byte png_tRNS[5] = {116, 82, 78, 83, '\0'}
  162008. #define PNG_zTXt png_byte png_zTXt[5] = {122, 84, 88, 116, '\0'}
  162009. #ifdef PNG_USE_GLOBAL_ARRAYS
  162010. PNG_EXPORT_VAR (png_byte FARDATA) png_IHDR[5];
  162011. PNG_EXPORT_VAR (png_byte FARDATA) png_IDAT[5];
  162012. PNG_EXPORT_VAR (png_byte FARDATA) png_IEND[5];
  162013. PNG_EXPORT_VAR (png_byte FARDATA) png_PLTE[5];
  162014. PNG_EXPORT_VAR (png_byte FARDATA) png_bKGD[5];
  162015. PNG_EXPORT_VAR (png_byte FARDATA) png_cHRM[5];
  162016. PNG_EXPORT_VAR (png_byte FARDATA) png_gAMA[5];
  162017. PNG_EXPORT_VAR (png_byte FARDATA) png_hIST[5];
  162018. PNG_EXPORT_VAR (png_byte FARDATA) png_iCCP[5];
  162019. PNG_EXPORT_VAR (png_byte FARDATA) png_iTXt[5];
  162020. PNG_EXPORT_VAR (png_byte FARDATA) png_oFFs[5];
  162021. PNG_EXPORT_VAR (png_byte FARDATA) png_pCAL[5];
  162022. PNG_EXPORT_VAR (png_byte FARDATA) png_sCAL[5];
  162023. PNG_EXPORT_VAR (png_byte FARDATA) png_pHYs[5];
  162024. PNG_EXPORT_VAR (png_byte FARDATA) png_sBIT[5];
  162025. PNG_EXPORT_VAR (png_byte FARDATA) png_sPLT[5];
  162026. PNG_EXPORT_VAR (png_byte FARDATA) png_sRGB[5];
  162027. PNG_EXPORT_VAR (png_byte FARDATA) png_tEXt[5];
  162028. PNG_EXPORT_VAR (png_byte FARDATA) png_tIME[5];
  162029. PNG_EXPORT_VAR (png_byte FARDATA) png_tRNS[5];
  162030. PNG_EXPORT_VAR (png_byte FARDATA) png_zTXt[5];
  162031. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162032. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162033. extern PNG_EXPORT(void,png_read_init) PNGARG((png_structp png_ptr));
  162034. #undef png_read_init
  162035. #define png_read_init(png_ptr) png_read_init_3(&png_ptr, \
  162036. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  162037. #endif
  162038. extern PNG_EXPORT(void,png_read_init_3) PNGARG((png_structpp ptr_ptr,
  162039. png_const_charp user_png_ver, png_size_t png_struct_size));
  162040. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162041. extern PNG_EXPORT(void,png_read_init_2) PNGARG((png_structp png_ptr,
  162042. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  162043. png_info_size));
  162044. #endif
  162045. #if defined(PNG_1_0_X) || defined (PNG_1_2_X)
  162046. extern PNG_EXPORT(void,png_write_init) PNGARG((png_structp png_ptr));
  162047. #undef png_write_init
  162048. #define png_write_init(png_ptr) png_write_init_3(&png_ptr, \
  162049. PNG_LIBPNG_VER_STRING, png_sizeof(png_struct));
  162050. #endif
  162051. extern PNG_EXPORT(void,png_write_init_3) PNGARG((png_structpp ptr_ptr,
  162052. png_const_charp user_png_ver, png_size_t png_struct_size));
  162053. extern PNG_EXPORT(void,png_write_init_2) PNGARG((png_structp png_ptr,
  162054. png_const_charp user_png_ver, png_size_t png_struct_size, png_size_t
  162055. png_info_size));
  162056. PNG_EXTERN png_voidp png_create_struct PNGARG((int type));
  162057. PNG_EXTERN void png_destroy_struct PNGARG((png_voidp struct_ptr));
  162058. PNG_EXTERN png_voidp png_create_struct_2 PNGARG((int type, png_malloc_ptr
  162059. malloc_fn, png_voidp mem_ptr));
  162060. PNG_EXTERN void png_destroy_struct_2 PNGARG((png_voidp struct_ptr,
  162061. png_free_ptr free_fn, png_voidp mem_ptr));
  162062. PNG_EXTERN void png_info_destroy PNGARG((png_structp png_ptr,
  162063. png_infop info_ptr));
  162064. #ifndef PNG_1_0_X
  162065. PNG_EXTERN voidpf png_zalloc PNGARG((voidpf png_ptr, uInt items, uInt size));
  162066. PNG_EXTERN void png_zfree PNGARG((voidpf png_ptr, voidpf ptr));
  162067. #ifdef PNG_SIZE_T
  162068. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  162069. #endif
  162070. PNG_EXTERN void PNGAPI png_default_read_data PNGARG((png_structp png_ptr,
  162071. png_bytep data, png_size_t length));
  162072. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162073. PNG_EXTERN void PNGAPI png_push_fill_buffer PNGARG((png_structp png_ptr,
  162074. png_bytep buffer, png_size_t length));
  162075. #endif
  162076. PNG_EXTERN void PNGAPI png_default_write_data PNGARG((png_structp png_ptr,
  162077. png_bytep data, png_size_t length));
  162078. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  162079. #if !defined(PNG_NO_STDIO)
  162080. PNG_EXTERN void PNGAPI png_default_flush PNGARG((png_structp png_ptr));
  162081. #endif
  162082. #endif
  162083. #else /* PNG_1_0_X */
  162084. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162085. PNG_EXTERN void png_push_fill_buffer PNGARG((png_structp png_ptr,
  162086. png_bytep buffer, png_size_t length));
  162087. #endif
  162088. #endif /* PNG_1_0_X */
  162089. PNG_EXTERN void png_reset_crc PNGARG((png_structp png_ptr));
  162090. PNG_EXTERN void png_write_data PNGARG((png_structp png_ptr, png_bytep data,
  162091. png_size_t length));
  162092. PNG_EXTERN void png_read_data PNGARG((png_structp png_ptr, png_bytep data,
  162093. png_size_t length));
  162094. PNG_EXTERN void png_crc_read PNGARG((png_structp png_ptr, png_bytep buf,
  162095. png_size_t length));
  162096. #if defined(PNG_zTXt_SUPPORTED) || defined(PNG_iTXt_SUPPORTED) || \
  162097. defined(PNG_iCCP_SUPPORTED) || defined(PNG_sPLT_SUPPORTED)
  162098. PNG_EXTERN png_charp png_decompress_chunk PNGARG((png_structp png_ptr,
  162099. int comp_type, png_charp chunkdata, png_size_t chunklength,
  162100. png_size_t prefix_length, png_size_t *data_length));
  162101. #endif
  162102. PNG_EXTERN int png_crc_finish PNGARG((png_structp png_ptr, png_uint_32 skip));
  162103. PNG_EXTERN int png_crc_error PNGARG((png_structp png_ptr));
  162104. PNG_EXTERN void png_calculate_crc PNGARG((png_structp png_ptr, png_bytep ptr,
  162105. png_size_t length));
  162106. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  162107. PNG_EXTERN void png_flush PNGARG((png_structp png_ptr));
  162108. #endif
  162109. PNG_EXTERN void png_write_sig PNGARG((png_structp png_ptr));
  162110. PNG_EXTERN void png_write_IHDR PNGARG((png_structp png_ptr, png_uint_32 width,
  162111. png_uint_32 height,
  162112. int bit_depth, int color_type, int compression_method, int filter_method,
  162113. int interlace_method));
  162114. PNG_EXTERN void png_write_PLTE PNGARG((png_structp png_ptr, png_colorp palette,
  162115. png_uint_32 num_pal));
  162116. PNG_EXTERN void png_write_IDAT PNGARG((png_structp png_ptr, png_bytep data,
  162117. png_size_t length));
  162118. PNG_EXTERN void png_write_IEND PNGARG((png_structp png_ptr));
  162119. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  162120. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162121. PNG_EXTERN void png_write_gAMA PNGARG((png_structp png_ptr, double file_gamma));
  162122. #endif
  162123. #ifdef PNG_FIXED_POINT_SUPPORTED
  162124. PNG_EXTERN void png_write_gAMA_fixed PNGARG((png_structp png_ptr, png_fixed_point
  162125. file_gamma));
  162126. #endif
  162127. #endif
  162128. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  162129. PNG_EXTERN void png_write_sBIT PNGARG((png_structp png_ptr, png_color_8p sbit,
  162130. int color_type));
  162131. #endif
  162132. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  162133. #ifdef PNG_FLOATING_POINT_SUPPORTED
  162134. PNG_EXTERN void png_write_cHRM PNGARG((png_structp png_ptr,
  162135. double white_x, double white_y,
  162136. double red_x, double red_y, double green_x, double green_y,
  162137. double blue_x, double blue_y));
  162138. #endif
  162139. #ifdef PNG_FIXED_POINT_SUPPORTED
  162140. PNG_EXTERN void png_write_cHRM_fixed PNGARG((png_structp png_ptr,
  162141. png_fixed_point int_white_x, png_fixed_point int_white_y,
  162142. png_fixed_point int_red_x, png_fixed_point int_red_y, png_fixed_point
  162143. int_green_x, png_fixed_point int_green_y, png_fixed_point int_blue_x,
  162144. png_fixed_point int_blue_y));
  162145. #endif
  162146. #endif
  162147. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  162148. PNG_EXTERN void png_write_sRGB PNGARG((png_structp png_ptr,
  162149. int intent));
  162150. #endif
  162151. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  162152. PNG_EXTERN void png_write_iCCP PNGARG((png_structp png_ptr,
  162153. png_charp name, int compression_type,
  162154. png_charp profile, int proflen));
  162155. #endif
  162156. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  162157. PNG_EXTERN void png_write_sPLT PNGARG((png_structp png_ptr,
  162158. png_sPLT_tp palette));
  162159. #endif
  162160. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  162161. PNG_EXTERN void png_write_tRNS PNGARG((png_structp png_ptr, png_bytep trans,
  162162. png_color_16p values, int number, int color_type));
  162163. #endif
  162164. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  162165. PNG_EXTERN void png_write_bKGD PNGARG((png_structp png_ptr,
  162166. png_color_16p values, int color_type));
  162167. #endif
  162168. #if defined(PNG_WRITE_hIST_SUPPORTED)
  162169. PNG_EXTERN void png_write_hIST PNGARG((png_structp png_ptr, png_uint_16p hist,
  162170. int num_hist));
  162171. #endif
  162172. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  162173. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  162174. PNG_EXTERN png_size_t png_check_keyword PNGARG((png_structp png_ptr,
  162175. png_charp key, png_charpp new_key));
  162176. #endif
  162177. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  162178. PNG_EXTERN void png_write_tEXt PNGARG((png_structp png_ptr, png_charp key,
  162179. png_charp text, png_size_t text_len));
  162180. #endif
  162181. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  162182. PNG_EXTERN void png_write_zTXt PNGARG((png_structp png_ptr, png_charp key,
  162183. png_charp text, png_size_t text_len, int compression));
  162184. #endif
  162185. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  162186. PNG_EXTERN void png_write_iTXt PNGARG((png_structp png_ptr,
  162187. int compression, png_charp key, png_charp lang, png_charp lang_key,
  162188. png_charp text));
  162189. #endif
  162190. #if defined(PNG_TEXT_SUPPORTED) /* Added at version 1.0.14 and 1.2.4 */
  162191. PNG_EXTERN int png_set_text_2 PNGARG((png_structp png_ptr,
  162192. png_infop info_ptr, png_textp text_ptr, int num_text));
  162193. #endif
  162194. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  162195. PNG_EXTERN void png_write_oFFs PNGARG((png_structp png_ptr,
  162196. png_int_32 x_offset, png_int_32 y_offset, int unit_type));
  162197. #endif
  162198. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  162199. PNG_EXTERN void png_write_pCAL PNGARG((png_structp png_ptr, png_charp purpose,
  162200. png_int_32 X0, png_int_32 X1, int type, int nparams,
  162201. png_charp units, png_charpp params));
  162202. #endif
  162203. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  162204. PNG_EXTERN void png_write_pHYs PNGARG((png_structp png_ptr,
  162205. png_uint_32 x_pixels_per_unit, png_uint_32 y_pixels_per_unit,
  162206. int unit_type));
  162207. #endif
  162208. #if defined(PNG_WRITE_tIME_SUPPORTED)
  162209. PNG_EXTERN void png_write_tIME PNGARG((png_structp png_ptr,
  162210. png_timep mod_time));
  162211. #endif
  162212. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  162213. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  162214. PNG_EXTERN void png_write_sCAL PNGARG((png_structp png_ptr,
  162215. int unit, double width, double height));
  162216. #else
  162217. #ifdef PNG_FIXED_POINT_SUPPORTED
  162218. PNG_EXTERN void png_write_sCAL_s PNGARG((png_structp png_ptr,
  162219. int unit, png_charp width, png_charp height));
  162220. #endif
  162221. #endif
  162222. #endif
  162223. PNG_EXTERN void png_write_finish_row PNGARG((png_structp png_ptr));
  162224. PNG_EXTERN void png_write_start_row PNGARG((png_structp png_ptr));
  162225. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162226. PNG_EXTERN void png_build_gamma_table PNGARG((png_structp png_ptr));
  162227. #endif
  162228. PNG_EXTERN void png_combine_row PNGARG((png_structp png_ptr, png_bytep row,
  162229. int mask));
  162230. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  162231. PNG_EXTERN void png_do_read_interlace PNGARG((png_structp png_ptr));
  162232. #endif
  162233. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  162234. PNG_EXTERN void png_do_write_interlace PNGARG((png_row_infop row_info,
  162235. png_bytep row, int pass));
  162236. #endif
  162237. PNG_EXTERN void png_read_filter_row PNGARG((png_structp png_ptr,
  162238. png_row_infop row_info, png_bytep row, png_bytep prev_row, int filter));
  162239. PNG_EXTERN void png_write_find_filter PNGARG((png_structp png_ptr,
  162240. png_row_infop row_info));
  162241. PNG_EXTERN void png_write_filtered_row PNGARG((png_structp png_ptr,
  162242. png_bytep filtered_row));
  162243. PNG_EXTERN void png_read_finish_row PNGARG((png_structp png_ptr));
  162244. PNG_EXTERN void png_read_start_row PNGARG((png_structp png_ptr));
  162245. PNG_EXTERN void png_read_transform_info PNGARG((png_structp png_ptr,
  162246. png_infop info_ptr));
  162247. #if defined(PNG_READ_FILLER_SUPPORTED)
  162248. PNG_EXTERN void png_do_read_filler PNGARG((png_row_infop row_info,
  162249. png_bytep row, png_uint_32 filler, png_uint_32 flags));
  162250. #endif
  162251. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  162252. PNG_EXTERN void png_do_read_swap_alpha PNGARG((png_row_infop row_info,
  162253. png_bytep row));
  162254. #endif
  162255. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  162256. PNG_EXTERN void png_do_write_swap_alpha PNGARG((png_row_infop row_info,
  162257. png_bytep row));
  162258. #endif
  162259. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  162260. PNG_EXTERN void png_do_read_invert_alpha PNGARG((png_row_infop row_info,
  162261. png_bytep row));
  162262. #endif
  162263. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  162264. PNG_EXTERN void png_do_write_invert_alpha PNGARG((png_row_infop row_info,
  162265. png_bytep row));
  162266. #endif
  162267. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  162268. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  162269. PNG_EXTERN void png_do_strip_filler PNGARG((png_row_infop row_info,
  162270. png_bytep row, png_uint_32 flags));
  162271. #endif
  162272. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  162273. PNG_EXTERN void png_do_swap PNGARG((png_row_infop row_info, png_bytep row));
  162274. #endif
  162275. #if defined(PNG_READ_PACKSWAP_SUPPORTED) || defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  162276. PNG_EXTERN void png_do_packswap PNGARG((png_row_infop row_info, png_bytep row));
  162277. #endif
  162278. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  162279. PNG_EXTERN int png_do_rgb_to_gray PNGARG((png_structp png_ptr, png_row_infop
  162280. row_info, png_bytep row));
  162281. #endif
  162282. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  162283. PNG_EXTERN void png_do_gray_to_rgb PNGARG((png_row_infop row_info,
  162284. png_bytep row));
  162285. #endif
  162286. #if defined(PNG_READ_PACK_SUPPORTED)
  162287. PNG_EXTERN void png_do_unpack PNGARG((png_row_infop row_info, png_bytep row));
  162288. #endif
  162289. #if defined(PNG_READ_SHIFT_SUPPORTED)
  162290. PNG_EXTERN void png_do_unshift PNGARG((png_row_infop row_info, png_bytep row,
  162291. png_color_8p sig_bits));
  162292. #endif
  162293. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  162294. PNG_EXTERN void png_do_invert PNGARG((png_row_infop row_info, png_bytep row));
  162295. #endif
  162296. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  162297. PNG_EXTERN void png_do_chop PNGARG((png_row_infop row_info, png_bytep row));
  162298. #endif
  162299. #if defined(PNG_READ_DITHER_SUPPORTED)
  162300. PNG_EXTERN void png_do_dither PNGARG((png_row_infop row_info,
  162301. png_bytep row, png_bytep palette_lookup, png_bytep dither_lookup));
  162302. # if defined(PNG_CORRECT_PALETTE_SUPPORTED)
  162303. PNG_EXTERN void png_correct_palette PNGARG((png_structp png_ptr,
  162304. png_colorp palette, int num_palette));
  162305. # endif
  162306. #endif
  162307. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  162308. PNG_EXTERN void png_do_bgr PNGARG((png_row_infop row_info, png_bytep row));
  162309. #endif
  162310. #if defined(PNG_WRITE_PACK_SUPPORTED)
  162311. PNG_EXTERN void png_do_pack PNGARG((png_row_infop row_info,
  162312. png_bytep row, png_uint_32 bit_depth));
  162313. #endif
  162314. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  162315. PNG_EXTERN void png_do_shift PNGARG((png_row_infop row_info, png_bytep row,
  162316. png_color_8p bit_depth));
  162317. #endif
  162318. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  162319. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162320. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162321. png_color_16p trans_values, png_color_16p background,
  162322. png_color_16p background_1,
  162323. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  162324. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  162325. png_uint_16pp gamma_16_to_1, int gamma_shift));
  162326. #else
  162327. PNG_EXTERN void png_do_background PNGARG((png_row_infop row_info, png_bytep row,
  162328. png_color_16p trans_values, png_color_16p background));
  162329. #endif
  162330. #endif
  162331. #if defined(PNG_READ_GAMMA_SUPPORTED)
  162332. PNG_EXTERN void png_do_gamma PNGARG((png_row_infop row_info, png_bytep row,
  162333. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  162334. int gamma_shift));
  162335. #endif
  162336. #if defined(PNG_READ_EXPAND_SUPPORTED)
  162337. PNG_EXTERN void png_do_expand_palette PNGARG((png_row_infop row_info,
  162338. png_bytep row, png_colorp palette, png_bytep trans, int num_trans));
  162339. PNG_EXTERN void png_do_expand PNGARG((png_row_infop row_info,
  162340. png_bytep row, png_color_16p trans_value));
  162341. #endif
  162342. PNG_EXTERN void png_handle_IHDR PNGARG((png_structp png_ptr, png_infop info_ptr,
  162343. png_uint_32 length));
  162344. PNG_EXTERN void png_handle_PLTE PNGARG((png_structp png_ptr, png_infop info_ptr,
  162345. png_uint_32 length));
  162346. PNG_EXTERN void png_handle_IEND PNGARG((png_structp png_ptr, png_infop info_ptr,
  162347. png_uint_32 length));
  162348. #if defined(PNG_READ_bKGD_SUPPORTED)
  162349. PNG_EXTERN void png_handle_bKGD PNGARG((png_structp png_ptr, png_infop info_ptr,
  162350. png_uint_32 length));
  162351. #endif
  162352. #if defined(PNG_READ_cHRM_SUPPORTED)
  162353. PNG_EXTERN void png_handle_cHRM PNGARG((png_structp png_ptr, png_infop info_ptr,
  162354. png_uint_32 length));
  162355. #endif
  162356. #if defined(PNG_READ_gAMA_SUPPORTED)
  162357. PNG_EXTERN void png_handle_gAMA PNGARG((png_structp png_ptr, png_infop info_ptr,
  162358. png_uint_32 length));
  162359. #endif
  162360. #if defined(PNG_READ_hIST_SUPPORTED)
  162361. PNG_EXTERN void png_handle_hIST PNGARG((png_structp png_ptr, png_infop info_ptr,
  162362. png_uint_32 length));
  162363. #endif
  162364. #if defined(PNG_READ_iCCP_SUPPORTED)
  162365. extern void png_handle_iCCP PNGARG((png_structp png_ptr, png_infop info_ptr,
  162366. png_uint_32 length));
  162367. #endif /* PNG_READ_iCCP_SUPPORTED */
  162368. #if defined(PNG_READ_iTXt_SUPPORTED)
  162369. PNG_EXTERN void png_handle_iTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162370. png_uint_32 length));
  162371. #endif
  162372. #if defined(PNG_READ_oFFs_SUPPORTED)
  162373. PNG_EXTERN void png_handle_oFFs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162374. png_uint_32 length));
  162375. #endif
  162376. #if defined(PNG_READ_pCAL_SUPPORTED)
  162377. PNG_EXTERN void png_handle_pCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162378. png_uint_32 length));
  162379. #endif
  162380. #if defined(PNG_READ_pHYs_SUPPORTED)
  162381. PNG_EXTERN void png_handle_pHYs PNGARG((png_structp png_ptr, png_infop info_ptr,
  162382. png_uint_32 length));
  162383. #endif
  162384. #if defined(PNG_READ_sBIT_SUPPORTED)
  162385. PNG_EXTERN void png_handle_sBIT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162386. png_uint_32 length));
  162387. #endif
  162388. #if defined(PNG_READ_sCAL_SUPPORTED)
  162389. PNG_EXTERN void png_handle_sCAL PNGARG((png_structp png_ptr, png_infop info_ptr,
  162390. png_uint_32 length));
  162391. #endif
  162392. #if defined(PNG_READ_sPLT_SUPPORTED)
  162393. extern void png_handle_sPLT PNGARG((png_structp png_ptr, png_infop info_ptr,
  162394. png_uint_32 length));
  162395. #endif /* PNG_READ_sPLT_SUPPORTED */
  162396. #if defined(PNG_READ_sRGB_SUPPORTED)
  162397. PNG_EXTERN void png_handle_sRGB PNGARG((png_structp png_ptr, png_infop info_ptr,
  162398. png_uint_32 length));
  162399. #endif
  162400. #if defined(PNG_READ_tEXt_SUPPORTED)
  162401. PNG_EXTERN void png_handle_tEXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162402. png_uint_32 length));
  162403. #endif
  162404. #if defined(PNG_READ_tIME_SUPPORTED)
  162405. PNG_EXTERN void png_handle_tIME PNGARG((png_structp png_ptr, png_infop info_ptr,
  162406. png_uint_32 length));
  162407. #endif
  162408. #if defined(PNG_READ_tRNS_SUPPORTED)
  162409. PNG_EXTERN void png_handle_tRNS PNGARG((png_structp png_ptr, png_infop info_ptr,
  162410. png_uint_32 length));
  162411. #endif
  162412. #if defined(PNG_READ_zTXt_SUPPORTED)
  162413. PNG_EXTERN void png_handle_zTXt PNGARG((png_structp png_ptr, png_infop info_ptr,
  162414. png_uint_32 length));
  162415. #endif
  162416. PNG_EXTERN void png_handle_unknown PNGARG((png_structp png_ptr,
  162417. png_infop info_ptr, png_uint_32 length));
  162418. PNG_EXTERN void png_check_chunk_name PNGARG((png_structp png_ptr,
  162419. png_bytep chunk_name));
  162420. PNG_EXTERN void png_do_read_transformations PNGARG((png_structp png_ptr));
  162421. PNG_EXTERN void png_do_write_transformations PNGARG((png_structp png_ptr));
  162422. PNG_EXTERN void png_init_read_transformations PNGARG((png_structp png_ptr));
  162423. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  162424. PNG_EXTERN void png_push_read_chunk PNGARG((png_structp png_ptr,
  162425. png_infop info_ptr));
  162426. PNG_EXTERN void png_push_read_sig PNGARG((png_structp png_ptr,
  162427. png_infop info_ptr));
  162428. PNG_EXTERN void png_push_check_crc PNGARG((png_structp png_ptr));
  162429. PNG_EXTERN void png_push_crc_skip PNGARG((png_structp png_ptr,
  162430. png_uint_32 length));
  162431. PNG_EXTERN void png_push_crc_finish PNGARG((png_structp png_ptr));
  162432. PNG_EXTERN void png_push_save_buffer PNGARG((png_structp png_ptr));
  162433. PNG_EXTERN void png_push_restore_buffer PNGARG((png_structp png_ptr,
  162434. png_bytep buffer, png_size_t buffer_length));
  162435. PNG_EXTERN void png_push_read_IDAT PNGARG((png_structp png_ptr));
  162436. PNG_EXTERN void png_process_IDAT_data PNGARG((png_structp png_ptr,
  162437. png_bytep buffer, png_size_t buffer_length));
  162438. PNG_EXTERN void png_push_process_row PNGARG((png_structp png_ptr));
  162439. PNG_EXTERN void png_push_handle_unknown PNGARG((png_structp png_ptr,
  162440. png_infop info_ptr, png_uint_32 length));
  162441. PNG_EXTERN void png_push_have_info PNGARG((png_structp png_ptr,
  162442. png_infop info_ptr));
  162443. PNG_EXTERN void png_push_have_end PNGARG((png_structp png_ptr,
  162444. png_infop info_ptr));
  162445. PNG_EXTERN void png_push_have_row PNGARG((png_structp png_ptr, png_bytep row));
  162446. PNG_EXTERN void png_push_read_end PNGARG((png_structp png_ptr,
  162447. png_infop info_ptr));
  162448. PNG_EXTERN void png_process_some_data PNGARG((png_structp png_ptr,
  162449. png_infop info_ptr));
  162450. PNG_EXTERN void png_read_push_finish_row PNGARG((png_structp png_ptr));
  162451. #if defined(PNG_READ_tEXt_SUPPORTED)
  162452. PNG_EXTERN void png_push_handle_tEXt PNGARG((png_structp png_ptr,
  162453. png_infop info_ptr, png_uint_32 length));
  162454. PNG_EXTERN void png_push_read_tEXt PNGARG((png_structp png_ptr,
  162455. png_infop info_ptr));
  162456. #endif
  162457. #if defined(PNG_READ_zTXt_SUPPORTED)
  162458. PNG_EXTERN void png_push_handle_zTXt PNGARG((png_structp png_ptr,
  162459. png_infop info_ptr, png_uint_32 length));
  162460. PNG_EXTERN void png_push_read_zTXt PNGARG((png_structp png_ptr,
  162461. png_infop info_ptr));
  162462. #endif
  162463. #if defined(PNG_READ_iTXt_SUPPORTED)
  162464. PNG_EXTERN void png_push_handle_iTXt PNGARG((png_structp png_ptr,
  162465. png_infop info_ptr, png_uint_32 length));
  162466. PNG_EXTERN void png_push_read_iTXt PNGARG((png_structp png_ptr,
  162467. png_infop info_ptr));
  162468. #endif
  162469. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  162470. #ifdef PNG_MNG_FEATURES_SUPPORTED
  162471. PNG_EXTERN void png_do_read_intrapixel PNGARG((png_row_infop row_info,
  162472. png_bytep row));
  162473. PNG_EXTERN void png_do_write_intrapixel PNGARG((png_row_infop row_info,
  162474. png_bytep row));
  162475. #endif
  162476. #if defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  162477. #if defined(PNG_MMX_CODE_SUPPORTED)
  162478. /* PRIVATE */
  162479. PNG_EXTERN void png_init_mmx_flags PNGARG((png_structp png_ptr));
  162480. #endif
  162481. #endif
  162482. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  162483. PNG_EXTERN png_uint_32 png_get_pixels_per_inch PNGARG((png_structp png_ptr,
  162484. png_infop info_ptr));
  162485. PNG_EXTERN png_uint_32 png_get_x_pixels_per_inch PNGARG((png_structp png_ptr,
  162486. png_infop info_ptr));
  162487. PNG_EXTERN png_uint_32 png_get_y_pixels_per_inch PNGARG((png_structp png_ptr,
  162488. png_infop info_ptr));
  162489. PNG_EXTERN float png_get_x_offset_inches PNGARG((png_structp png_ptr,
  162490. png_infop info_ptr));
  162491. PNG_EXTERN float png_get_y_offset_inches PNGARG((png_structp png_ptr,
  162492. png_infop info_ptr));
  162493. #if defined(PNG_pHYs_SUPPORTED)
  162494. PNG_EXTERN png_uint_32 png_get_pHYs_dpi PNGARG((png_structp png_ptr,
  162495. png_infop info_ptr, png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type));
  162496. #endif /* PNG_pHYs_SUPPORTED */
  162497. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  162498. #endif /* PNG_INTERNAL */
  162499. #ifdef __cplusplus
  162500. }
  162501. #endif
  162502. #endif /* PNG_VERSION_INFO_ONLY */
  162503. #endif /* PNG_H */
  162504. /*** End of inlined file: png.h ***/
  162505. #define PNG_NO_EXTERN
  162506. /*** Start of inlined file: png.c ***/
  162507. #define PNG_INTERNAL
  162508. #define PNG_NO_EXTERN
  162509. typedef version_1_2_21 Your_png_h_is_not_version_1_2_21;
  162510. #ifdef PNG_USE_GLOBAL_ARRAYS
  162511. PNG_CONST char png_libpng_ver[18] = PNG_LIBPNG_VER_STRING;
  162512. #ifdef PNG_READ_SUPPORTED
  162513. PNG_CONST png_byte FARDATA png_sig[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162514. #endif /* PNG_READ_SUPPORTED */
  162515. PNG_IHDR;
  162516. PNG_IDAT;
  162517. PNG_IEND;
  162518. PNG_PLTE;
  162519. PNG_bKGD;
  162520. PNG_cHRM;
  162521. PNG_gAMA;
  162522. PNG_hIST;
  162523. PNG_iCCP;
  162524. PNG_iTXt;
  162525. PNG_oFFs;
  162526. PNG_pCAL;
  162527. PNG_sCAL;
  162528. PNG_pHYs;
  162529. PNG_sBIT;
  162530. PNG_sPLT;
  162531. PNG_sRGB;
  162532. PNG_tEXt;
  162533. PNG_tIME;
  162534. PNG_tRNS;
  162535. PNG_zTXt;
  162536. #ifdef PNG_READ_SUPPORTED
  162537. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  162538. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  162539. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  162540. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  162541. PNG_CONST int FARDATA png_pass_mask[] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  162542. PNG_CONST int FARDATA png_pass_dsp_mask[]
  162543. = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  162544. #endif /* PNG_READ_SUPPORTED */
  162545. #endif /* PNG_USE_GLOBAL_ARRAYS */
  162546. #ifdef PNG_READ_SUPPORTED
  162547. void PNGAPI
  162548. png_set_sig_bytes(png_structp png_ptr, int num_bytes)
  162549. {
  162550. if(png_ptr == NULL) return;
  162551. png_debug(1, "in png_set_sig_bytes\n");
  162552. if (num_bytes > 8)
  162553. png_error(png_ptr, "Too many bytes for PNG signature.");
  162554. png_ptr->sig_bytes = (png_byte)(num_bytes < 0 ? 0 : num_bytes);
  162555. }
  162556. int PNGAPI
  162557. png_sig_cmp(png_bytep sig, png_size_t start, png_size_t num_to_check)
  162558. {
  162559. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  162560. if (num_to_check > 8)
  162561. num_to_check = 8;
  162562. else if (num_to_check < 1)
  162563. return (-1);
  162564. if (start > 7)
  162565. return (-1);
  162566. if (start + num_to_check > 8)
  162567. num_to_check = 8 - start;
  162568. return ((int)(png_memcmp(&sig[start], &png_signature[start], num_to_check)));
  162569. }
  162570. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162571. int PNGAPI
  162572. png_check_sig(png_bytep sig, int num)
  162573. {
  162574. return ((int)!png_sig_cmp(sig, (png_size_t)0, (png_size_t)num));
  162575. }
  162576. #endif
  162577. #endif /* PNG_READ_SUPPORTED */
  162578. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162579. #ifdef PNG_1_0_X
  162580. voidpf PNGAPI
  162581. #else
  162582. voidpf /* private */
  162583. #endif
  162584. png_zalloc(voidpf png_ptr, uInt items, uInt size)
  162585. {
  162586. png_voidp ptr;
  162587. png_structp p=(png_structp)png_ptr;
  162588. png_uint_32 save_flags=p->flags;
  162589. png_uint_32 num_bytes;
  162590. if(png_ptr == NULL) return (NULL);
  162591. if (items > PNG_UINT_32_MAX/size)
  162592. {
  162593. png_warning (p, "Potential overflow in png_zalloc()");
  162594. return (NULL);
  162595. }
  162596. num_bytes = (png_uint_32)items * size;
  162597. p->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  162598. ptr = (png_voidp)png_malloc((png_structp)png_ptr, num_bytes);
  162599. p->flags=save_flags;
  162600. #if defined(PNG_1_0_X) && !defined(PNG_NO_ZALLOC_ZERO)
  162601. if (ptr == NULL)
  162602. return ((voidpf)ptr);
  162603. if (num_bytes > (png_uint_32)0x8000L)
  162604. {
  162605. png_memset(ptr, 0, (png_size_t)0x8000L);
  162606. png_memset((png_bytep)ptr + (png_size_t)0x8000L, 0,
  162607. (png_size_t)(num_bytes - (png_uint_32)0x8000L));
  162608. }
  162609. else
  162610. {
  162611. png_memset(ptr, 0, (png_size_t)num_bytes);
  162612. }
  162613. #endif
  162614. return ((voidpf)ptr);
  162615. }
  162616. #ifdef PNG_1_0_X
  162617. void PNGAPI
  162618. #else
  162619. void /* private */
  162620. #endif
  162621. png_zfree(voidpf png_ptr, voidpf ptr)
  162622. {
  162623. png_free((png_structp)png_ptr, (png_voidp)ptr);
  162624. }
  162625. void /* PRIVATE */
  162626. png_reset_crc(png_structp png_ptr)
  162627. {
  162628. png_ptr->crc = crc32(0, Z_NULL, 0);
  162629. }
  162630. void /* PRIVATE */
  162631. png_calculate_crc(png_structp png_ptr, png_bytep ptr, png_size_t length)
  162632. {
  162633. int need_crc = 1;
  162634. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  162635. {
  162636. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  162637. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  162638. need_crc = 0;
  162639. }
  162640. else /* critical */
  162641. {
  162642. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  162643. need_crc = 0;
  162644. }
  162645. if (need_crc)
  162646. png_ptr->crc = crc32(png_ptr->crc, ptr, (uInt)length);
  162647. }
  162648. png_infop PNGAPI
  162649. png_create_info_struct(png_structp png_ptr)
  162650. {
  162651. png_infop info_ptr;
  162652. png_debug(1, "in png_create_info_struct\n");
  162653. if(png_ptr == NULL) return (NULL);
  162654. #ifdef PNG_USER_MEM_SUPPORTED
  162655. info_ptr = (png_infop)png_create_struct_2(PNG_STRUCT_INFO,
  162656. png_ptr->malloc_fn, png_ptr->mem_ptr);
  162657. #else
  162658. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162659. #endif
  162660. if (info_ptr != NULL)
  162661. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162662. return (info_ptr);
  162663. }
  162664. void PNGAPI
  162665. png_destroy_info_struct(png_structp png_ptr, png_infopp info_ptr_ptr)
  162666. {
  162667. png_infop info_ptr = NULL;
  162668. if(png_ptr == NULL) return;
  162669. png_debug(1, "in png_destroy_info_struct\n");
  162670. if (info_ptr_ptr != NULL)
  162671. info_ptr = *info_ptr_ptr;
  162672. if (info_ptr != NULL)
  162673. {
  162674. png_info_destroy(png_ptr, info_ptr);
  162675. #ifdef PNG_USER_MEM_SUPPORTED
  162676. png_destroy_struct_2((png_voidp)info_ptr, png_ptr->free_fn,
  162677. png_ptr->mem_ptr);
  162678. #else
  162679. png_destroy_struct((png_voidp)info_ptr);
  162680. #endif
  162681. *info_ptr_ptr = NULL;
  162682. }
  162683. }
  162684. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  162685. #undef png_info_init
  162686. void PNGAPI
  162687. png_info_init(png_infop info_ptr)
  162688. {
  162689. png_info_init_3(&info_ptr, 0);
  162690. }
  162691. #endif
  162692. void PNGAPI
  162693. png_info_init_3(png_infopp ptr_ptr, png_size_t png_info_struct_size)
  162694. {
  162695. png_infop info_ptr = *ptr_ptr;
  162696. if(info_ptr == NULL) return;
  162697. png_debug(1, "in png_info_init_3\n");
  162698. if(png_sizeof(png_info) > png_info_struct_size)
  162699. {
  162700. png_destroy_struct(info_ptr);
  162701. info_ptr = (png_infop)png_create_struct(PNG_STRUCT_INFO);
  162702. *ptr_ptr = info_ptr;
  162703. }
  162704. png_memset(info_ptr, 0, png_sizeof (png_info));
  162705. }
  162706. #ifdef PNG_FREE_ME_SUPPORTED
  162707. void PNGAPI
  162708. png_data_freer(png_structp png_ptr, png_infop info_ptr,
  162709. int freer, png_uint_32 mask)
  162710. {
  162711. png_debug(1, "in png_data_freer\n");
  162712. if (png_ptr == NULL || info_ptr == NULL)
  162713. return;
  162714. if(freer == PNG_DESTROY_WILL_FREE_DATA)
  162715. info_ptr->free_me |= mask;
  162716. else if(freer == PNG_USER_WILL_FREE_DATA)
  162717. info_ptr->free_me &= ~mask;
  162718. else
  162719. png_warning(png_ptr,
  162720. "Unknown freer parameter in png_data_freer.");
  162721. }
  162722. #endif
  162723. void PNGAPI
  162724. png_free_data(png_structp png_ptr, png_infop info_ptr, png_uint_32 mask,
  162725. int num)
  162726. {
  162727. png_debug(1, "in png_free_data\n");
  162728. if (png_ptr == NULL || info_ptr == NULL)
  162729. return;
  162730. #if defined(PNG_TEXT_SUPPORTED)
  162731. #ifdef PNG_FREE_ME_SUPPORTED
  162732. if ((mask & PNG_FREE_TEXT) & info_ptr->free_me)
  162733. #else
  162734. if (mask & PNG_FREE_TEXT)
  162735. #endif
  162736. {
  162737. if (num != -1)
  162738. {
  162739. if (info_ptr->text && info_ptr->text[num].key)
  162740. {
  162741. png_free(png_ptr, info_ptr->text[num].key);
  162742. info_ptr->text[num].key = NULL;
  162743. }
  162744. }
  162745. else
  162746. {
  162747. int i;
  162748. for (i = 0; i < info_ptr->num_text; i++)
  162749. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, i);
  162750. png_free(png_ptr, info_ptr->text);
  162751. info_ptr->text = NULL;
  162752. info_ptr->num_text=0;
  162753. }
  162754. }
  162755. #endif
  162756. #if defined(PNG_tRNS_SUPPORTED)
  162757. #ifdef PNG_FREE_ME_SUPPORTED
  162758. if ((mask & PNG_FREE_TRNS) & info_ptr->free_me)
  162759. #else
  162760. if ((mask & PNG_FREE_TRNS) && (png_ptr->flags & PNG_FLAG_FREE_TRNS))
  162761. #endif
  162762. {
  162763. png_free(png_ptr, info_ptr->trans);
  162764. info_ptr->valid &= ~PNG_INFO_tRNS;
  162765. #ifndef PNG_FREE_ME_SUPPORTED
  162766. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  162767. #endif
  162768. info_ptr->trans = NULL;
  162769. }
  162770. #endif
  162771. #if defined(PNG_sCAL_SUPPORTED)
  162772. #ifdef PNG_FREE_ME_SUPPORTED
  162773. if ((mask & PNG_FREE_SCAL) & info_ptr->free_me)
  162774. #else
  162775. if (mask & PNG_FREE_SCAL)
  162776. #endif
  162777. {
  162778. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  162779. png_free(png_ptr, info_ptr->scal_s_width);
  162780. png_free(png_ptr, info_ptr->scal_s_height);
  162781. info_ptr->scal_s_width = NULL;
  162782. info_ptr->scal_s_height = NULL;
  162783. #endif
  162784. info_ptr->valid &= ~PNG_INFO_sCAL;
  162785. }
  162786. #endif
  162787. #if defined(PNG_pCAL_SUPPORTED)
  162788. #ifdef PNG_FREE_ME_SUPPORTED
  162789. if ((mask & PNG_FREE_PCAL) & info_ptr->free_me)
  162790. #else
  162791. if (mask & PNG_FREE_PCAL)
  162792. #endif
  162793. {
  162794. png_free(png_ptr, info_ptr->pcal_purpose);
  162795. png_free(png_ptr, info_ptr->pcal_units);
  162796. info_ptr->pcal_purpose = NULL;
  162797. info_ptr->pcal_units = NULL;
  162798. if (info_ptr->pcal_params != NULL)
  162799. {
  162800. int i;
  162801. for (i = 0; i < (int)info_ptr->pcal_nparams; i++)
  162802. {
  162803. png_free(png_ptr, info_ptr->pcal_params[i]);
  162804. info_ptr->pcal_params[i]=NULL;
  162805. }
  162806. png_free(png_ptr, info_ptr->pcal_params);
  162807. info_ptr->pcal_params = NULL;
  162808. }
  162809. info_ptr->valid &= ~PNG_INFO_pCAL;
  162810. }
  162811. #endif
  162812. #if defined(PNG_iCCP_SUPPORTED)
  162813. #ifdef PNG_FREE_ME_SUPPORTED
  162814. if ((mask & PNG_FREE_ICCP) & info_ptr->free_me)
  162815. #else
  162816. if (mask & PNG_FREE_ICCP)
  162817. #endif
  162818. {
  162819. png_free(png_ptr, info_ptr->iccp_name);
  162820. png_free(png_ptr, info_ptr->iccp_profile);
  162821. info_ptr->iccp_name = NULL;
  162822. info_ptr->iccp_profile = NULL;
  162823. info_ptr->valid &= ~PNG_INFO_iCCP;
  162824. }
  162825. #endif
  162826. #if defined(PNG_sPLT_SUPPORTED)
  162827. #ifdef PNG_FREE_ME_SUPPORTED
  162828. if ((mask & PNG_FREE_SPLT) & info_ptr->free_me)
  162829. #else
  162830. if (mask & PNG_FREE_SPLT)
  162831. #endif
  162832. {
  162833. if (num != -1)
  162834. {
  162835. if(info_ptr->splt_palettes)
  162836. {
  162837. png_free(png_ptr, info_ptr->splt_palettes[num].name);
  162838. png_free(png_ptr, info_ptr->splt_palettes[num].entries);
  162839. info_ptr->splt_palettes[num].name = NULL;
  162840. info_ptr->splt_palettes[num].entries = NULL;
  162841. }
  162842. }
  162843. else
  162844. {
  162845. if(info_ptr->splt_palettes_num)
  162846. {
  162847. int i;
  162848. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  162849. png_free_data(png_ptr, info_ptr, PNG_FREE_SPLT, i);
  162850. png_free(png_ptr, info_ptr->splt_palettes);
  162851. info_ptr->splt_palettes = NULL;
  162852. info_ptr->splt_palettes_num = 0;
  162853. }
  162854. info_ptr->valid &= ~PNG_INFO_sPLT;
  162855. }
  162856. }
  162857. #endif
  162858. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162859. if(png_ptr->unknown_chunk.data)
  162860. {
  162861. png_free(png_ptr, png_ptr->unknown_chunk.data);
  162862. png_ptr->unknown_chunk.data = NULL;
  162863. }
  162864. #ifdef PNG_FREE_ME_SUPPORTED
  162865. if ((mask & PNG_FREE_UNKN) & info_ptr->free_me)
  162866. #else
  162867. if (mask & PNG_FREE_UNKN)
  162868. #endif
  162869. {
  162870. if (num != -1)
  162871. {
  162872. if(info_ptr->unknown_chunks)
  162873. {
  162874. png_free(png_ptr, info_ptr->unknown_chunks[num].data);
  162875. info_ptr->unknown_chunks[num].data = NULL;
  162876. }
  162877. }
  162878. else
  162879. {
  162880. int i;
  162881. if(info_ptr->unknown_chunks_num)
  162882. {
  162883. for (i = 0; i < (int)info_ptr->unknown_chunks_num; i++)
  162884. png_free_data(png_ptr, info_ptr, PNG_FREE_UNKN, i);
  162885. png_free(png_ptr, info_ptr->unknown_chunks);
  162886. info_ptr->unknown_chunks = NULL;
  162887. info_ptr->unknown_chunks_num = 0;
  162888. }
  162889. }
  162890. }
  162891. #endif
  162892. #if defined(PNG_hIST_SUPPORTED)
  162893. #ifdef PNG_FREE_ME_SUPPORTED
  162894. if ((mask & PNG_FREE_HIST) & info_ptr->free_me)
  162895. #else
  162896. if ((mask & PNG_FREE_HIST) && (png_ptr->flags & PNG_FLAG_FREE_HIST))
  162897. #endif
  162898. {
  162899. png_free(png_ptr, info_ptr->hist);
  162900. info_ptr->hist = NULL;
  162901. info_ptr->valid &= ~PNG_INFO_hIST;
  162902. #ifndef PNG_FREE_ME_SUPPORTED
  162903. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  162904. #endif
  162905. }
  162906. #endif
  162907. #ifdef PNG_FREE_ME_SUPPORTED
  162908. if ((mask & PNG_FREE_PLTE) & info_ptr->free_me)
  162909. #else
  162910. if ((mask & PNG_FREE_PLTE) && (png_ptr->flags & PNG_FLAG_FREE_PLTE))
  162911. #endif
  162912. {
  162913. png_zfree(png_ptr, info_ptr->palette);
  162914. info_ptr->palette = NULL;
  162915. info_ptr->valid &= ~PNG_INFO_PLTE;
  162916. #ifndef PNG_FREE_ME_SUPPORTED
  162917. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  162918. #endif
  162919. info_ptr->num_palette = 0;
  162920. }
  162921. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  162922. #ifdef PNG_FREE_ME_SUPPORTED
  162923. if ((mask & PNG_FREE_ROWS) & info_ptr->free_me)
  162924. #else
  162925. if (mask & PNG_FREE_ROWS)
  162926. #endif
  162927. {
  162928. if(info_ptr->row_pointers)
  162929. {
  162930. int row;
  162931. for (row = 0; row < (int)info_ptr->height; row++)
  162932. {
  162933. png_free(png_ptr, info_ptr->row_pointers[row]);
  162934. info_ptr->row_pointers[row]=NULL;
  162935. }
  162936. png_free(png_ptr, info_ptr->row_pointers);
  162937. info_ptr->row_pointers=NULL;
  162938. }
  162939. info_ptr->valid &= ~PNG_INFO_IDAT;
  162940. }
  162941. #endif
  162942. #ifdef PNG_FREE_ME_SUPPORTED
  162943. if(num == -1)
  162944. info_ptr->free_me &= ~mask;
  162945. else
  162946. info_ptr->free_me &= ~(mask & ~PNG_FREE_MUL);
  162947. #endif
  162948. }
  162949. void /* PRIVATE */
  162950. png_info_destroy(png_structp png_ptr, png_infop info_ptr)
  162951. {
  162952. png_debug(1, "in png_info_destroy\n");
  162953. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  162954. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  162955. if (png_ptr->num_chunk_list)
  162956. {
  162957. png_free(png_ptr, png_ptr->chunk_list);
  162958. png_ptr->chunk_list=NULL;
  162959. png_ptr->num_chunk_list=0;
  162960. }
  162961. #endif
  162962. png_info_init_3(&info_ptr, png_sizeof(png_info));
  162963. }
  162964. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  162965. png_voidp PNGAPI
  162966. png_get_io_ptr(png_structp png_ptr)
  162967. {
  162968. if(png_ptr == NULL) return (NULL);
  162969. return (png_ptr->io_ptr);
  162970. }
  162971. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  162972. #if !defined(PNG_NO_STDIO)
  162973. void PNGAPI
  162974. png_init_io(png_structp png_ptr, png_FILE_p fp)
  162975. {
  162976. png_debug(1, "in png_init_io\n");
  162977. if(png_ptr == NULL) return;
  162978. png_ptr->io_ptr = (png_voidp)fp;
  162979. }
  162980. #endif
  162981. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  162982. png_charp PNGAPI
  162983. png_convert_to_rfc1123(png_structp png_ptr, png_timep ptime)
  162984. {
  162985. static PNG_CONST char short_months[12][4] =
  162986. {"Jan", "Feb", "Mar", "Apr", "May", "Jun",
  162987. "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
  162988. if(png_ptr == NULL) return (NULL);
  162989. if (png_ptr->time_buffer == NULL)
  162990. {
  162991. png_ptr->time_buffer = (png_charp)png_malloc(png_ptr, (png_uint_32)(29*
  162992. png_sizeof(char)));
  162993. }
  162994. #if defined(_WIN32_WCE)
  162995. {
  162996. wchar_t time_buf[29];
  162997. wsprintf(time_buf, TEXT("%d %S %d %02d:%02d:%02d +0000"),
  162998. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  162999. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163000. ptime->second % 61);
  163001. WideCharToMultiByte(CP_ACP, 0, time_buf, -1, png_ptr->time_buffer, 29,
  163002. NULL, NULL);
  163003. }
  163004. #else
  163005. #ifdef USE_FAR_KEYWORD
  163006. {
  163007. char near_time_buf[29];
  163008. png_snprintf6(near_time_buf,29,"%d %s %d %02d:%02d:%02d +0000",
  163009. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163010. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163011. ptime->second % 61);
  163012. png_memcpy(png_ptr->time_buffer, near_time_buf,
  163013. 29*png_sizeof(char));
  163014. }
  163015. #else
  163016. png_snprintf6(png_ptr->time_buffer,29,"%d %s %d %02d:%02d:%02d +0000",
  163017. ptime->day % 32, short_months[(ptime->month - 1) % 12],
  163018. ptime->year, ptime->hour % 24, ptime->minute % 60,
  163019. ptime->second % 61);
  163020. #endif
  163021. #endif /* _WIN32_WCE */
  163022. return ((png_charp)png_ptr->time_buffer);
  163023. }
  163024. #endif /* PNG_TIME_RFC1123_SUPPORTED */
  163025. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163026. png_charp PNGAPI
  163027. png_get_copyright(png_structp png_ptr)
  163028. {
  163029. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163030. return ((png_charp) "\n libpng version 1.2.21 - October 4, 2007\n\
  163031. Copyright (c) 1998-2007 Glenn Randers-Pehrson\n\
  163032. Copyright (c) 1996-1997 Andreas Dilger\n\
  163033. Copyright (c) 1995-1996 Guy Eric Schalnat, Group 42, Inc.\n");
  163034. }
  163035. png_charp PNGAPI
  163036. png_get_libpng_ver(png_structp png_ptr)
  163037. {
  163038. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163039. return ((png_charp) PNG_LIBPNG_VER_STRING);
  163040. }
  163041. png_charp PNGAPI
  163042. png_get_header_ver(png_structp png_ptr)
  163043. {
  163044. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163045. return ((png_charp) PNG_LIBPNG_VER_STRING);
  163046. }
  163047. png_charp PNGAPI
  163048. png_get_header_version(png_structp png_ptr)
  163049. {
  163050. png_ptr = png_ptr; /* silence compiler warning about unused png_ptr */
  163051. return ((png_charp) PNG_HEADER_VERSION_STRING
  163052. #ifndef PNG_READ_SUPPORTED
  163053. " (NO READ SUPPORT)"
  163054. #endif
  163055. "\n");
  163056. }
  163057. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163058. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  163059. int PNGAPI
  163060. png_handle_as_unknown(png_structp png_ptr, png_bytep chunk_name)
  163061. {
  163062. int i;
  163063. png_bytep p;
  163064. if(png_ptr == NULL || chunk_name == NULL || png_ptr->num_chunk_list<=0)
  163065. return 0;
  163066. p=png_ptr->chunk_list+png_ptr->num_chunk_list*5-5;
  163067. for (i = png_ptr->num_chunk_list; i; i--, p-=5)
  163068. if (!png_memcmp(chunk_name, p, 4))
  163069. return ((int)*(p+4));
  163070. return 0;
  163071. }
  163072. #endif
  163073. int PNGAPI
  163074. png_reset_zstream(png_structp png_ptr)
  163075. {
  163076. if (png_ptr == NULL) return Z_STREAM_ERROR;
  163077. return (inflateReset(&png_ptr->zstream));
  163078. }
  163079. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163080. png_uint_32 PNGAPI
  163081. png_access_version_number(void)
  163082. {
  163083. return((png_uint_32) PNG_LIBPNG_VER);
  163084. }
  163085. #if defined(PNG_READ_SUPPORTED) && defined(PNG_ASSEMBLER_CODE_SUPPORTED)
  163086. #if !defined(PNG_1_0_X)
  163087. int PNGAPI
  163088. png_mmx_support(void)
  163089. {
  163090. return -1;
  163091. }
  163092. #endif /* PNG_1_0_X */
  163093. #endif /* PNG_READ_SUPPORTED && PNG_ASSEMBLER_CODE_SUPPORTED */
  163094. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163095. #ifdef PNG_SIZE_T
  163096. PNG_EXTERN png_size_t PNGAPI png_convert_size PNGARG((size_t size));
  163097. png_size_t PNGAPI
  163098. png_convert_size(size_t size)
  163099. {
  163100. if (size > (png_size_t)-1)
  163101. PNG_ABORT(); /* We haven't got access to png_ptr, so no png_error() */
  163102. return ((png_size_t)size);
  163103. }
  163104. #endif /* PNG_SIZE_T */
  163105. #endif /* defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED) */
  163106. /*** End of inlined file: png.c ***/
  163107. /*** Start of inlined file: pngerror.c ***/
  163108. #define PNG_INTERNAL
  163109. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163110. static void /* PRIVATE */
  163111. png_default_error PNGARG((png_structp png_ptr,
  163112. png_const_charp error_message));
  163113. #ifndef PNG_NO_WARNINGS
  163114. static void /* PRIVATE */
  163115. png_default_warning PNGARG((png_structp png_ptr,
  163116. png_const_charp warning_message));
  163117. #endif /* PNG_NO_WARNINGS */
  163118. #ifndef PNG_NO_ERROR_TEXT
  163119. void PNGAPI
  163120. png_error(png_structp png_ptr, png_const_charp error_message)
  163121. {
  163122. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163123. char msg[16];
  163124. if (png_ptr != NULL)
  163125. {
  163126. if (png_ptr->flags&
  163127. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  163128. {
  163129. if (*error_message == '#')
  163130. {
  163131. int offset;
  163132. for (offset=1; offset<15; offset++)
  163133. if (*(error_message+offset) == ' ')
  163134. break;
  163135. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  163136. {
  163137. int i;
  163138. for (i=0; i<offset-1; i++)
  163139. msg[i]=error_message[i+1];
  163140. msg[i]='\0';
  163141. error_message=msg;
  163142. }
  163143. else
  163144. error_message+=offset;
  163145. }
  163146. else
  163147. {
  163148. if (png_ptr->flags&PNG_FLAG_STRIP_ERROR_TEXT)
  163149. {
  163150. msg[0]='0';
  163151. msg[1]='\0';
  163152. error_message=msg;
  163153. }
  163154. }
  163155. }
  163156. }
  163157. #endif
  163158. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  163159. (*(png_ptr->error_fn))(png_ptr, error_message);
  163160. png_default_error(png_ptr, error_message);
  163161. }
  163162. #else
  163163. void PNGAPI
  163164. png_err(png_structp png_ptr)
  163165. {
  163166. if (png_ptr != NULL && png_ptr->error_fn != NULL)
  163167. (*(png_ptr->error_fn))(png_ptr, '\0');
  163168. png_default_error(png_ptr, '\0');
  163169. }
  163170. #endif /* PNG_NO_ERROR_TEXT */
  163171. #ifndef PNG_NO_WARNINGS
  163172. void PNGAPI
  163173. png_warning(png_structp png_ptr, png_const_charp warning_message)
  163174. {
  163175. int offset = 0;
  163176. if (png_ptr != NULL)
  163177. {
  163178. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163179. if (png_ptr->flags&
  163180. (PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))
  163181. #endif
  163182. {
  163183. if (*warning_message == '#')
  163184. {
  163185. for (offset=1; offset<15; offset++)
  163186. if (*(warning_message+offset) == ' ')
  163187. break;
  163188. }
  163189. }
  163190. if (png_ptr != NULL && png_ptr->warning_fn != NULL)
  163191. (*(png_ptr->warning_fn))(png_ptr, warning_message+offset);
  163192. }
  163193. else
  163194. png_default_warning(png_ptr, warning_message+offset);
  163195. }
  163196. #endif /* PNG_NO_WARNINGS */
  163197. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  163198. #if !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT)
  163199. static void /* PRIVATE */
  163200. png_format_buffer(png_structp png_ptr, png_charp buffer, png_const_charp
  163201. error_message)
  163202. {
  163203. int iout = 0, iin = 0;
  163204. while (iin < 4)
  163205. {
  163206. int c = png_ptr->chunk_name[iin++];
  163207. if (isnonalpha(c))
  163208. {
  163209. buffer[iout++] = '[';
  163210. buffer[iout++] = png_digit[(c & 0xf0) >> 4];
  163211. buffer[iout++] = png_digit[c & 0x0f];
  163212. buffer[iout++] = ']';
  163213. }
  163214. else
  163215. {
  163216. buffer[iout++] = (png_byte)c;
  163217. }
  163218. }
  163219. if (error_message == NULL)
  163220. buffer[iout] = 0;
  163221. else
  163222. {
  163223. buffer[iout++] = ':';
  163224. buffer[iout++] = ' ';
  163225. png_strncpy(buffer+iout, error_message, 63);
  163226. buffer[iout+63] = 0;
  163227. }
  163228. }
  163229. #ifdef PNG_READ_SUPPORTED
  163230. void PNGAPI
  163231. png_chunk_error(png_structp png_ptr, png_const_charp error_message)
  163232. {
  163233. char msg[18+64];
  163234. if (png_ptr == NULL)
  163235. png_error(png_ptr, error_message);
  163236. else
  163237. {
  163238. png_format_buffer(png_ptr, msg, error_message);
  163239. png_error(png_ptr, msg);
  163240. }
  163241. }
  163242. #endif /* PNG_READ_SUPPORTED */
  163243. #endif /* !defined(PNG_NO_WARNINGS) || !defined(PNG_NO_ERROR_TEXT) */
  163244. #ifndef PNG_NO_WARNINGS
  163245. void PNGAPI
  163246. png_chunk_warning(png_structp png_ptr, png_const_charp warning_message)
  163247. {
  163248. char msg[18+64];
  163249. if (png_ptr == NULL)
  163250. png_warning(png_ptr, warning_message);
  163251. else
  163252. {
  163253. png_format_buffer(png_ptr, msg, warning_message);
  163254. png_warning(png_ptr, msg);
  163255. }
  163256. }
  163257. #endif /* PNG_NO_WARNINGS */
  163258. static void /* PRIVATE */
  163259. png_default_error(png_structp png_ptr, png_const_charp error_message)
  163260. {
  163261. #ifndef PNG_NO_CONSOLE_IO
  163262. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163263. if (*error_message == '#')
  163264. {
  163265. int offset;
  163266. char error_number[16];
  163267. for (offset=0; offset<15; offset++)
  163268. {
  163269. error_number[offset] = *(error_message+offset+1);
  163270. if (*(error_message+offset) == ' ')
  163271. break;
  163272. }
  163273. if((offset > 1) && (offset < 15))
  163274. {
  163275. error_number[offset-1]='\0';
  163276. fprintf(stderr, "libpng error no. %s: %s\n", error_number,
  163277. error_message+offset);
  163278. }
  163279. else
  163280. fprintf(stderr, "libpng error: %s, offset=%d\n", error_message,offset);
  163281. }
  163282. else
  163283. #endif
  163284. fprintf(stderr, "libpng error: %s\n", error_message);
  163285. #endif
  163286. #ifdef PNG_SETJMP_SUPPORTED
  163287. if (png_ptr)
  163288. {
  163289. # ifdef USE_FAR_KEYWORD
  163290. {
  163291. jmp_buf jmpbuf;
  163292. png_memcpy(jmpbuf, png_ptr->jmpbuf, png_sizeof(jmp_buf));
  163293. longjmp(jmpbuf, 1);
  163294. }
  163295. # else
  163296. longjmp(png_ptr->jmpbuf, 1);
  163297. # endif
  163298. }
  163299. #else
  163300. PNG_ABORT();
  163301. #endif
  163302. #ifdef PNG_NO_CONSOLE_IO
  163303. error_message = error_message; /* make compiler happy */
  163304. #endif
  163305. }
  163306. #ifndef PNG_NO_WARNINGS
  163307. static void /* PRIVATE */
  163308. png_default_warning(png_structp png_ptr, png_const_charp warning_message)
  163309. {
  163310. #ifndef PNG_NO_CONSOLE_IO
  163311. # ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163312. if (*warning_message == '#')
  163313. {
  163314. int offset;
  163315. char warning_number[16];
  163316. for (offset=0; offset<15; offset++)
  163317. {
  163318. warning_number[offset]=*(warning_message+offset+1);
  163319. if (*(warning_message+offset) == ' ')
  163320. break;
  163321. }
  163322. if((offset > 1) && (offset < 15))
  163323. {
  163324. warning_number[offset-1]='\0';
  163325. fprintf(stderr, "libpng warning no. %s: %s\n", warning_number,
  163326. warning_message+offset);
  163327. }
  163328. else
  163329. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163330. }
  163331. else
  163332. # endif
  163333. fprintf(stderr, "libpng warning: %s\n", warning_message);
  163334. #else
  163335. warning_message = warning_message; /* make compiler happy */
  163336. #endif
  163337. png_ptr = png_ptr; /* make compiler happy */
  163338. }
  163339. #endif /* PNG_NO_WARNINGS */
  163340. void PNGAPI
  163341. png_set_error_fn(png_structp png_ptr, png_voidp error_ptr,
  163342. png_error_ptr error_fn, png_error_ptr warning_fn)
  163343. {
  163344. if (png_ptr == NULL)
  163345. return;
  163346. png_ptr->error_ptr = error_ptr;
  163347. png_ptr->error_fn = error_fn;
  163348. png_ptr->warning_fn = warning_fn;
  163349. }
  163350. png_voidp PNGAPI
  163351. png_get_error_ptr(png_structp png_ptr)
  163352. {
  163353. if (png_ptr == NULL)
  163354. return NULL;
  163355. return ((png_voidp)png_ptr->error_ptr);
  163356. }
  163357. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  163358. void PNGAPI
  163359. png_set_strip_error_numbers(png_structp png_ptr, png_uint_32 strip_mode)
  163360. {
  163361. if(png_ptr != NULL)
  163362. {
  163363. png_ptr->flags &=
  163364. ((~(PNG_FLAG_STRIP_ERROR_NUMBERS|PNG_FLAG_STRIP_ERROR_TEXT))&strip_mode);
  163365. }
  163366. }
  163367. #endif
  163368. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  163369. /*** End of inlined file: pngerror.c ***/
  163370. /*** Start of inlined file: pngget.c ***/
  163371. #define PNG_INTERNAL
  163372. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  163373. png_uint_32 PNGAPI
  163374. png_get_valid(png_structp png_ptr, png_infop info_ptr, png_uint_32 flag)
  163375. {
  163376. if (png_ptr != NULL && info_ptr != NULL)
  163377. return(info_ptr->valid & flag);
  163378. else
  163379. return(0);
  163380. }
  163381. png_uint_32 PNGAPI
  163382. png_get_rowbytes(png_structp png_ptr, png_infop info_ptr)
  163383. {
  163384. if (png_ptr != NULL && info_ptr != NULL)
  163385. return(info_ptr->rowbytes);
  163386. else
  163387. return(0);
  163388. }
  163389. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  163390. png_bytepp PNGAPI
  163391. png_get_rows(png_structp png_ptr, png_infop info_ptr)
  163392. {
  163393. if (png_ptr != NULL && info_ptr != NULL)
  163394. return(info_ptr->row_pointers);
  163395. else
  163396. return(0);
  163397. }
  163398. #endif
  163399. #ifdef PNG_EASY_ACCESS_SUPPORTED
  163400. png_uint_32 PNGAPI
  163401. png_get_image_width(png_structp png_ptr, png_infop info_ptr)
  163402. {
  163403. if (png_ptr != NULL && info_ptr != NULL)
  163404. {
  163405. return info_ptr->width;
  163406. }
  163407. return (0);
  163408. }
  163409. png_uint_32 PNGAPI
  163410. png_get_image_height(png_structp png_ptr, png_infop info_ptr)
  163411. {
  163412. if (png_ptr != NULL && info_ptr != NULL)
  163413. {
  163414. return info_ptr->height;
  163415. }
  163416. return (0);
  163417. }
  163418. png_byte PNGAPI
  163419. png_get_bit_depth(png_structp png_ptr, png_infop info_ptr)
  163420. {
  163421. if (png_ptr != NULL && info_ptr != NULL)
  163422. {
  163423. return info_ptr->bit_depth;
  163424. }
  163425. return (0);
  163426. }
  163427. png_byte PNGAPI
  163428. png_get_color_type(png_structp png_ptr, png_infop info_ptr)
  163429. {
  163430. if (png_ptr != NULL && info_ptr != NULL)
  163431. {
  163432. return info_ptr->color_type;
  163433. }
  163434. return (0);
  163435. }
  163436. png_byte PNGAPI
  163437. png_get_filter_type(png_structp png_ptr, png_infop info_ptr)
  163438. {
  163439. if (png_ptr != NULL && info_ptr != NULL)
  163440. {
  163441. return info_ptr->filter_type;
  163442. }
  163443. return (0);
  163444. }
  163445. png_byte PNGAPI
  163446. png_get_interlace_type(png_structp png_ptr, png_infop info_ptr)
  163447. {
  163448. if (png_ptr != NULL && info_ptr != NULL)
  163449. {
  163450. return info_ptr->interlace_type;
  163451. }
  163452. return (0);
  163453. }
  163454. png_byte PNGAPI
  163455. png_get_compression_type(png_structp png_ptr, png_infop info_ptr)
  163456. {
  163457. if (png_ptr != NULL && info_ptr != NULL)
  163458. {
  163459. return info_ptr->compression_type;
  163460. }
  163461. return (0);
  163462. }
  163463. png_uint_32 PNGAPI
  163464. png_get_x_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163465. {
  163466. if (png_ptr != NULL && info_ptr != NULL)
  163467. #if defined(PNG_pHYs_SUPPORTED)
  163468. if (info_ptr->valid & PNG_INFO_pHYs)
  163469. {
  163470. png_debug1(1, "in %s retrieval function\n", "png_get_x_pixels_per_meter");
  163471. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163472. return (0);
  163473. else return (info_ptr->x_pixels_per_unit);
  163474. }
  163475. #else
  163476. return (0);
  163477. #endif
  163478. return (0);
  163479. }
  163480. png_uint_32 PNGAPI
  163481. png_get_y_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163482. {
  163483. if (png_ptr != NULL && info_ptr != NULL)
  163484. #if defined(PNG_pHYs_SUPPORTED)
  163485. if (info_ptr->valid & PNG_INFO_pHYs)
  163486. {
  163487. png_debug1(1, "in %s retrieval function\n", "png_get_y_pixels_per_meter");
  163488. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER)
  163489. return (0);
  163490. else return (info_ptr->y_pixels_per_unit);
  163491. }
  163492. #else
  163493. return (0);
  163494. #endif
  163495. return (0);
  163496. }
  163497. png_uint_32 PNGAPI
  163498. png_get_pixels_per_meter(png_structp png_ptr, png_infop info_ptr)
  163499. {
  163500. if (png_ptr != NULL && info_ptr != NULL)
  163501. #if defined(PNG_pHYs_SUPPORTED)
  163502. if (info_ptr->valid & PNG_INFO_pHYs)
  163503. {
  163504. png_debug1(1, "in %s retrieval function\n", "png_get_pixels_per_meter");
  163505. if(info_ptr->phys_unit_type != PNG_RESOLUTION_METER ||
  163506. info_ptr->x_pixels_per_unit != info_ptr->y_pixels_per_unit)
  163507. return (0);
  163508. else return (info_ptr->x_pixels_per_unit);
  163509. }
  163510. #else
  163511. return (0);
  163512. #endif
  163513. return (0);
  163514. }
  163515. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163516. float PNGAPI
  163517. png_get_pixel_aspect_ratio(png_structp png_ptr, png_infop info_ptr)
  163518. {
  163519. if (png_ptr != NULL && info_ptr != NULL)
  163520. #if defined(PNG_pHYs_SUPPORTED)
  163521. if (info_ptr->valid & PNG_INFO_pHYs)
  163522. {
  163523. png_debug1(1, "in %s retrieval function\n", "png_get_aspect_ratio");
  163524. if (info_ptr->x_pixels_per_unit == 0)
  163525. return ((float)0.0);
  163526. else
  163527. return ((float)((float)info_ptr->y_pixels_per_unit
  163528. /(float)info_ptr->x_pixels_per_unit));
  163529. }
  163530. #else
  163531. return (0.0);
  163532. #endif
  163533. return ((float)0.0);
  163534. }
  163535. #endif
  163536. png_int_32 PNGAPI
  163537. png_get_x_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163538. {
  163539. if (png_ptr != NULL && info_ptr != NULL)
  163540. #if defined(PNG_oFFs_SUPPORTED)
  163541. if (info_ptr->valid & PNG_INFO_oFFs)
  163542. {
  163543. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163544. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163545. return (0);
  163546. else return (info_ptr->x_offset);
  163547. }
  163548. #else
  163549. return (0);
  163550. #endif
  163551. return (0);
  163552. }
  163553. png_int_32 PNGAPI
  163554. png_get_y_offset_microns(png_structp png_ptr, png_infop info_ptr)
  163555. {
  163556. if (png_ptr != NULL && info_ptr != NULL)
  163557. #if defined(PNG_oFFs_SUPPORTED)
  163558. if (info_ptr->valid & PNG_INFO_oFFs)
  163559. {
  163560. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163561. if(info_ptr->offset_unit_type != PNG_OFFSET_MICROMETER)
  163562. return (0);
  163563. else return (info_ptr->y_offset);
  163564. }
  163565. #else
  163566. return (0);
  163567. #endif
  163568. return (0);
  163569. }
  163570. png_int_32 PNGAPI
  163571. png_get_x_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163572. {
  163573. if (png_ptr != NULL && info_ptr != NULL)
  163574. #if defined(PNG_oFFs_SUPPORTED)
  163575. if (info_ptr->valid & PNG_INFO_oFFs)
  163576. {
  163577. png_debug1(1, "in %s retrieval function\n", "png_get_x_offset_microns");
  163578. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163579. return (0);
  163580. else return (info_ptr->x_offset);
  163581. }
  163582. #else
  163583. return (0);
  163584. #endif
  163585. return (0);
  163586. }
  163587. png_int_32 PNGAPI
  163588. png_get_y_offset_pixels(png_structp png_ptr, png_infop info_ptr)
  163589. {
  163590. if (png_ptr != NULL && info_ptr != NULL)
  163591. #if defined(PNG_oFFs_SUPPORTED)
  163592. if (info_ptr->valid & PNG_INFO_oFFs)
  163593. {
  163594. png_debug1(1, "in %s retrieval function\n", "png_get_y_offset_microns");
  163595. if(info_ptr->offset_unit_type != PNG_OFFSET_PIXEL)
  163596. return (0);
  163597. else return (info_ptr->y_offset);
  163598. }
  163599. #else
  163600. return (0);
  163601. #endif
  163602. return (0);
  163603. }
  163604. #if defined(PNG_INCH_CONVERSIONS) && defined(PNG_FLOATING_POINT_SUPPORTED)
  163605. png_uint_32 PNGAPI
  163606. png_get_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163607. {
  163608. return ((png_uint_32)((float)png_get_pixels_per_meter(png_ptr, info_ptr)
  163609. *.0254 +.5));
  163610. }
  163611. png_uint_32 PNGAPI
  163612. png_get_x_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163613. {
  163614. return ((png_uint_32)((float)png_get_x_pixels_per_meter(png_ptr, info_ptr)
  163615. *.0254 +.5));
  163616. }
  163617. png_uint_32 PNGAPI
  163618. png_get_y_pixels_per_inch(png_structp png_ptr, png_infop info_ptr)
  163619. {
  163620. return ((png_uint_32)((float)png_get_y_pixels_per_meter(png_ptr, info_ptr)
  163621. *.0254 +.5));
  163622. }
  163623. float PNGAPI
  163624. png_get_x_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163625. {
  163626. return ((float)png_get_x_offset_microns(png_ptr, info_ptr)
  163627. *.00003937);
  163628. }
  163629. float PNGAPI
  163630. png_get_y_offset_inches(png_structp png_ptr, png_infop info_ptr)
  163631. {
  163632. return ((float)png_get_y_offset_microns(png_ptr, info_ptr)
  163633. *.00003937);
  163634. }
  163635. #if defined(PNG_pHYs_SUPPORTED)
  163636. png_uint_32 PNGAPI
  163637. png_get_pHYs_dpi(png_structp png_ptr, png_infop info_ptr,
  163638. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163639. {
  163640. png_uint_32 retval = 0;
  163641. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  163642. {
  163643. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163644. if (res_x != NULL)
  163645. {
  163646. *res_x = info_ptr->x_pixels_per_unit;
  163647. retval |= PNG_INFO_pHYs;
  163648. }
  163649. if (res_y != NULL)
  163650. {
  163651. *res_y = info_ptr->y_pixels_per_unit;
  163652. retval |= PNG_INFO_pHYs;
  163653. }
  163654. if (unit_type != NULL)
  163655. {
  163656. *unit_type = (int)info_ptr->phys_unit_type;
  163657. retval |= PNG_INFO_pHYs;
  163658. if(*unit_type == 1)
  163659. {
  163660. if (res_x != NULL) *res_x = (png_uint_32)(*res_x * .0254 + .50);
  163661. if (res_y != NULL) *res_y = (png_uint_32)(*res_y * .0254 + .50);
  163662. }
  163663. }
  163664. }
  163665. return (retval);
  163666. }
  163667. #endif /* PNG_pHYs_SUPPORTED */
  163668. #endif /* PNG_INCH_CONVERSIONS && PNG_FLOATING_POINT_SUPPORTED */
  163669. #endif /* PNG_EASY_ACCESS_SUPPORTED */
  163670. png_byte PNGAPI
  163671. png_get_channels(png_structp png_ptr, png_infop info_ptr)
  163672. {
  163673. if (png_ptr != NULL && info_ptr != NULL)
  163674. return(info_ptr->channels);
  163675. else
  163676. return (0);
  163677. }
  163678. png_bytep PNGAPI
  163679. png_get_signature(png_structp png_ptr, png_infop info_ptr)
  163680. {
  163681. if (png_ptr != NULL && info_ptr != NULL)
  163682. return(info_ptr->signature);
  163683. else
  163684. return (NULL);
  163685. }
  163686. #if defined(PNG_bKGD_SUPPORTED)
  163687. png_uint_32 PNGAPI
  163688. png_get_bKGD(png_structp png_ptr, png_infop info_ptr,
  163689. png_color_16p *background)
  163690. {
  163691. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD)
  163692. && background != NULL)
  163693. {
  163694. png_debug1(1, "in %s retrieval function\n", "bKGD");
  163695. *background = &(info_ptr->background);
  163696. return (PNG_INFO_bKGD);
  163697. }
  163698. return (0);
  163699. }
  163700. #endif
  163701. #if defined(PNG_cHRM_SUPPORTED)
  163702. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163703. png_uint_32 PNGAPI
  163704. png_get_cHRM(png_structp png_ptr, png_infop info_ptr,
  163705. double *white_x, double *white_y, double *red_x, double *red_y,
  163706. double *green_x, double *green_y, double *blue_x, double *blue_y)
  163707. {
  163708. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163709. {
  163710. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163711. if (white_x != NULL)
  163712. *white_x = (double)info_ptr->x_white;
  163713. if (white_y != NULL)
  163714. *white_y = (double)info_ptr->y_white;
  163715. if (red_x != NULL)
  163716. *red_x = (double)info_ptr->x_red;
  163717. if (red_y != NULL)
  163718. *red_y = (double)info_ptr->y_red;
  163719. if (green_x != NULL)
  163720. *green_x = (double)info_ptr->x_green;
  163721. if (green_y != NULL)
  163722. *green_y = (double)info_ptr->y_green;
  163723. if (blue_x != NULL)
  163724. *blue_x = (double)info_ptr->x_blue;
  163725. if (blue_y != NULL)
  163726. *blue_y = (double)info_ptr->y_blue;
  163727. return (PNG_INFO_cHRM);
  163728. }
  163729. return (0);
  163730. }
  163731. #endif
  163732. #ifdef PNG_FIXED_POINT_SUPPORTED
  163733. png_uint_32 PNGAPI
  163734. png_get_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  163735. png_fixed_point *white_x, png_fixed_point *white_y, png_fixed_point *red_x,
  163736. png_fixed_point *red_y, png_fixed_point *green_x, png_fixed_point *green_y,
  163737. png_fixed_point *blue_x, png_fixed_point *blue_y)
  163738. {
  163739. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  163740. {
  163741. png_debug1(1, "in %s retrieval function\n", "cHRM");
  163742. if (white_x != NULL)
  163743. *white_x = info_ptr->int_x_white;
  163744. if (white_y != NULL)
  163745. *white_y = info_ptr->int_y_white;
  163746. if (red_x != NULL)
  163747. *red_x = info_ptr->int_x_red;
  163748. if (red_y != NULL)
  163749. *red_y = info_ptr->int_y_red;
  163750. if (green_x != NULL)
  163751. *green_x = info_ptr->int_x_green;
  163752. if (green_y != NULL)
  163753. *green_y = info_ptr->int_y_green;
  163754. if (blue_x != NULL)
  163755. *blue_x = info_ptr->int_x_blue;
  163756. if (blue_y != NULL)
  163757. *blue_y = info_ptr->int_y_blue;
  163758. return (PNG_INFO_cHRM);
  163759. }
  163760. return (0);
  163761. }
  163762. #endif
  163763. #endif
  163764. #if defined(PNG_gAMA_SUPPORTED)
  163765. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163766. png_uint_32 PNGAPI
  163767. png_get_gAMA(png_structp png_ptr, png_infop info_ptr, double *file_gamma)
  163768. {
  163769. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163770. && file_gamma != NULL)
  163771. {
  163772. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163773. *file_gamma = (double)info_ptr->gamma;
  163774. return (PNG_INFO_gAMA);
  163775. }
  163776. return (0);
  163777. }
  163778. #endif
  163779. #ifdef PNG_FIXED_POINT_SUPPORTED
  163780. png_uint_32 PNGAPI
  163781. png_get_gAMA_fixed(png_structp png_ptr, png_infop info_ptr,
  163782. png_fixed_point *int_file_gamma)
  163783. {
  163784. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  163785. && int_file_gamma != NULL)
  163786. {
  163787. png_debug1(1, "in %s retrieval function\n", "gAMA");
  163788. *int_file_gamma = info_ptr->int_gamma;
  163789. return (PNG_INFO_gAMA);
  163790. }
  163791. return (0);
  163792. }
  163793. #endif
  163794. #endif
  163795. #if defined(PNG_sRGB_SUPPORTED)
  163796. png_uint_32 PNGAPI
  163797. png_get_sRGB(png_structp png_ptr, png_infop info_ptr, int *file_srgb_intent)
  163798. {
  163799. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB)
  163800. && file_srgb_intent != NULL)
  163801. {
  163802. png_debug1(1, "in %s retrieval function\n", "sRGB");
  163803. *file_srgb_intent = (int)info_ptr->srgb_intent;
  163804. return (PNG_INFO_sRGB);
  163805. }
  163806. return (0);
  163807. }
  163808. #endif
  163809. #if defined(PNG_iCCP_SUPPORTED)
  163810. png_uint_32 PNGAPI
  163811. png_get_iCCP(png_structp png_ptr, png_infop info_ptr,
  163812. png_charpp name, int *compression_type,
  163813. png_charpp profile, png_uint_32 *proflen)
  163814. {
  163815. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP)
  163816. && name != NULL && profile != NULL && proflen != NULL)
  163817. {
  163818. png_debug1(1, "in %s retrieval function\n", "iCCP");
  163819. *name = info_ptr->iccp_name;
  163820. *profile = info_ptr->iccp_profile;
  163821. *proflen = (int)info_ptr->iccp_proflen;
  163822. *compression_type = (int)info_ptr->iccp_compression;
  163823. return (PNG_INFO_iCCP);
  163824. }
  163825. return (0);
  163826. }
  163827. #endif
  163828. #if defined(PNG_sPLT_SUPPORTED)
  163829. png_uint_32 PNGAPI
  163830. png_get_sPLT(png_structp png_ptr, png_infop info_ptr,
  163831. png_sPLT_tpp spalettes)
  163832. {
  163833. if (png_ptr != NULL && info_ptr != NULL && spalettes != NULL)
  163834. {
  163835. *spalettes = info_ptr->splt_palettes;
  163836. return ((png_uint_32)info_ptr->splt_palettes_num);
  163837. }
  163838. return (0);
  163839. }
  163840. #endif
  163841. #if defined(PNG_hIST_SUPPORTED)
  163842. png_uint_32 PNGAPI
  163843. png_get_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p *hist)
  163844. {
  163845. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST)
  163846. && hist != NULL)
  163847. {
  163848. png_debug1(1, "in %s retrieval function\n", "hIST");
  163849. *hist = info_ptr->hist;
  163850. return (PNG_INFO_hIST);
  163851. }
  163852. return (0);
  163853. }
  163854. #endif
  163855. png_uint_32 PNGAPI
  163856. png_get_IHDR(png_structp png_ptr, png_infop info_ptr,
  163857. png_uint_32 *width, png_uint_32 *height, int *bit_depth,
  163858. int *color_type, int *interlace_type, int *compression_type,
  163859. int *filter_type)
  163860. {
  163861. if (png_ptr != NULL && info_ptr != NULL && width != NULL && height != NULL &&
  163862. bit_depth != NULL && color_type != NULL)
  163863. {
  163864. png_debug1(1, "in %s retrieval function\n", "IHDR");
  163865. *width = info_ptr->width;
  163866. *height = info_ptr->height;
  163867. *bit_depth = info_ptr->bit_depth;
  163868. if (info_ptr->bit_depth < 1 || info_ptr->bit_depth > 16)
  163869. png_error(png_ptr, "Invalid bit depth");
  163870. *color_type = info_ptr->color_type;
  163871. if (info_ptr->color_type > 6)
  163872. png_error(png_ptr, "Invalid color type");
  163873. if (compression_type != NULL)
  163874. *compression_type = info_ptr->compression_type;
  163875. if (filter_type != NULL)
  163876. *filter_type = info_ptr->filter_type;
  163877. if (interlace_type != NULL)
  163878. *interlace_type = info_ptr->interlace_type;
  163879. if (*width == 0 || *width > PNG_UINT_31_MAX)
  163880. png_error(png_ptr, "Invalid image width");
  163881. if (*height == 0 || *height > PNG_UINT_31_MAX)
  163882. png_error(png_ptr, "Invalid image height");
  163883. if (info_ptr->width > (PNG_UINT_32_MAX
  163884. >> 3) /* 8-byte RGBA pixels */
  163885. - 64 /* bigrowbuf hack */
  163886. - 1 /* filter byte */
  163887. - 7*8 /* rounding of width to multiple of 8 pixels */
  163888. - 8) /* extra max_pixel_depth pad */
  163889. {
  163890. png_warning(png_ptr,
  163891. "Width too large for libpng to process image data.");
  163892. }
  163893. return (1);
  163894. }
  163895. return (0);
  163896. }
  163897. #if defined(PNG_oFFs_SUPPORTED)
  163898. png_uint_32 PNGAPI
  163899. png_get_oFFs(png_structp png_ptr, png_infop info_ptr,
  163900. png_int_32 *offset_x, png_int_32 *offset_y, int *unit_type)
  163901. {
  163902. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs)
  163903. && offset_x != NULL && offset_y != NULL && unit_type != NULL)
  163904. {
  163905. png_debug1(1, "in %s retrieval function\n", "oFFs");
  163906. *offset_x = info_ptr->x_offset;
  163907. *offset_y = info_ptr->y_offset;
  163908. *unit_type = (int)info_ptr->offset_unit_type;
  163909. return (PNG_INFO_oFFs);
  163910. }
  163911. return (0);
  163912. }
  163913. #endif
  163914. #if defined(PNG_pCAL_SUPPORTED)
  163915. png_uint_32 PNGAPI
  163916. png_get_pCAL(png_structp png_ptr, png_infop info_ptr,
  163917. png_charp *purpose, png_int_32 *X0, png_int_32 *X1, int *type, int *nparams,
  163918. png_charp *units, png_charpp *params)
  163919. {
  163920. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL)
  163921. && purpose != NULL && X0 != NULL && X1 != NULL && type != NULL &&
  163922. nparams != NULL && units != NULL && params != NULL)
  163923. {
  163924. png_debug1(1, "in %s retrieval function\n", "pCAL");
  163925. *purpose = info_ptr->pcal_purpose;
  163926. *X0 = info_ptr->pcal_X0;
  163927. *X1 = info_ptr->pcal_X1;
  163928. *type = (int)info_ptr->pcal_type;
  163929. *nparams = (int)info_ptr->pcal_nparams;
  163930. *units = info_ptr->pcal_units;
  163931. *params = info_ptr->pcal_params;
  163932. return (PNG_INFO_pCAL);
  163933. }
  163934. return (0);
  163935. }
  163936. #endif
  163937. #if defined(PNG_sCAL_SUPPORTED)
  163938. #ifdef PNG_FLOATING_POINT_SUPPORTED
  163939. png_uint_32 PNGAPI
  163940. png_get_sCAL(png_structp png_ptr, png_infop info_ptr,
  163941. int *unit, double *width, double *height)
  163942. {
  163943. if (png_ptr != NULL && info_ptr != NULL &&
  163944. (info_ptr->valid & PNG_INFO_sCAL))
  163945. {
  163946. *unit = info_ptr->scal_unit;
  163947. *width = info_ptr->scal_pixel_width;
  163948. *height = info_ptr->scal_pixel_height;
  163949. return (PNG_INFO_sCAL);
  163950. }
  163951. return(0);
  163952. }
  163953. #else
  163954. #ifdef PNG_FIXED_POINT_SUPPORTED
  163955. png_uint_32 PNGAPI
  163956. png_get_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  163957. int *unit, png_charpp width, png_charpp height)
  163958. {
  163959. if (png_ptr != NULL && info_ptr != NULL &&
  163960. (info_ptr->valid & PNG_INFO_sCAL))
  163961. {
  163962. *unit = info_ptr->scal_unit;
  163963. *width = info_ptr->scal_s_width;
  163964. *height = info_ptr->scal_s_height;
  163965. return (PNG_INFO_sCAL);
  163966. }
  163967. return(0);
  163968. }
  163969. #endif
  163970. #endif
  163971. #endif
  163972. #if defined(PNG_pHYs_SUPPORTED)
  163973. png_uint_32 PNGAPI
  163974. png_get_pHYs(png_structp png_ptr, png_infop info_ptr,
  163975. png_uint_32 *res_x, png_uint_32 *res_y, int *unit_type)
  163976. {
  163977. png_uint_32 retval = 0;
  163978. if (png_ptr != NULL && info_ptr != NULL &&
  163979. (info_ptr->valid & PNG_INFO_pHYs))
  163980. {
  163981. png_debug1(1, "in %s retrieval function\n", "pHYs");
  163982. if (res_x != NULL)
  163983. {
  163984. *res_x = info_ptr->x_pixels_per_unit;
  163985. retval |= PNG_INFO_pHYs;
  163986. }
  163987. if (res_y != NULL)
  163988. {
  163989. *res_y = info_ptr->y_pixels_per_unit;
  163990. retval |= PNG_INFO_pHYs;
  163991. }
  163992. if (unit_type != NULL)
  163993. {
  163994. *unit_type = (int)info_ptr->phys_unit_type;
  163995. retval |= PNG_INFO_pHYs;
  163996. }
  163997. }
  163998. return (retval);
  163999. }
  164000. #endif
  164001. png_uint_32 PNGAPI
  164002. png_get_PLTE(png_structp png_ptr, png_infop info_ptr, png_colorp *palette,
  164003. int *num_palette)
  164004. {
  164005. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_PLTE)
  164006. && palette != NULL)
  164007. {
  164008. png_debug1(1, "in %s retrieval function\n", "PLTE");
  164009. *palette = info_ptr->palette;
  164010. *num_palette = info_ptr->num_palette;
  164011. png_debug1(3, "num_palette = %d\n", *num_palette);
  164012. return (PNG_INFO_PLTE);
  164013. }
  164014. return (0);
  164015. }
  164016. #if defined(PNG_sBIT_SUPPORTED)
  164017. png_uint_32 PNGAPI
  164018. png_get_sBIT(png_structp png_ptr, png_infop info_ptr, png_color_8p *sig_bit)
  164019. {
  164020. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT)
  164021. && sig_bit != NULL)
  164022. {
  164023. png_debug1(1, "in %s retrieval function\n", "sBIT");
  164024. *sig_bit = &(info_ptr->sig_bit);
  164025. return (PNG_INFO_sBIT);
  164026. }
  164027. return (0);
  164028. }
  164029. #endif
  164030. #if defined(PNG_TEXT_SUPPORTED)
  164031. png_uint_32 PNGAPI
  164032. png_get_text(png_structp png_ptr, png_infop info_ptr, png_textp *text_ptr,
  164033. int *num_text)
  164034. {
  164035. if (png_ptr != NULL && info_ptr != NULL && info_ptr->num_text > 0)
  164036. {
  164037. png_debug1(1, "in %s retrieval function\n",
  164038. (png_ptr->chunk_name[0] == '\0' ? "text"
  164039. : (png_const_charp)png_ptr->chunk_name));
  164040. if (text_ptr != NULL)
  164041. *text_ptr = info_ptr->text;
  164042. if (num_text != NULL)
  164043. *num_text = info_ptr->num_text;
  164044. return ((png_uint_32)info_ptr->num_text);
  164045. }
  164046. if (num_text != NULL)
  164047. *num_text = 0;
  164048. return(0);
  164049. }
  164050. #endif
  164051. #if defined(PNG_tIME_SUPPORTED)
  164052. png_uint_32 PNGAPI
  164053. png_get_tIME(png_structp png_ptr, png_infop info_ptr, png_timep *mod_time)
  164054. {
  164055. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME)
  164056. && mod_time != NULL)
  164057. {
  164058. png_debug1(1, "in %s retrieval function\n", "tIME");
  164059. *mod_time = &(info_ptr->mod_time);
  164060. return (PNG_INFO_tIME);
  164061. }
  164062. return (0);
  164063. }
  164064. #endif
  164065. #if defined(PNG_tRNS_SUPPORTED)
  164066. png_uint_32 PNGAPI
  164067. png_get_tRNS(png_structp png_ptr, png_infop info_ptr,
  164068. png_bytep *trans, int *num_trans, png_color_16p *trans_values)
  164069. {
  164070. png_uint_32 retval = 0;
  164071. if (png_ptr != NULL && info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  164072. {
  164073. png_debug1(1, "in %s retrieval function\n", "tRNS");
  164074. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  164075. {
  164076. if (trans != NULL)
  164077. {
  164078. *trans = info_ptr->trans;
  164079. retval |= PNG_INFO_tRNS;
  164080. }
  164081. if (trans_values != NULL)
  164082. *trans_values = &(info_ptr->trans_values);
  164083. }
  164084. else /* if (info_ptr->color_type != PNG_COLOR_TYPE_PALETTE) */
  164085. {
  164086. if (trans_values != NULL)
  164087. {
  164088. *trans_values = &(info_ptr->trans_values);
  164089. retval |= PNG_INFO_tRNS;
  164090. }
  164091. if(trans != NULL)
  164092. *trans = NULL;
  164093. }
  164094. if(num_trans != NULL)
  164095. {
  164096. *num_trans = info_ptr->num_trans;
  164097. retval |= PNG_INFO_tRNS;
  164098. }
  164099. }
  164100. return (retval);
  164101. }
  164102. #endif
  164103. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  164104. png_uint_32 PNGAPI
  164105. png_get_unknown_chunks(png_structp png_ptr, png_infop info_ptr,
  164106. png_unknown_chunkpp unknowns)
  164107. {
  164108. if (png_ptr != NULL && info_ptr != NULL && unknowns != NULL)
  164109. {
  164110. *unknowns = info_ptr->unknown_chunks;
  164111. return ((png_uint_32)info_ptr->unknown_chunks_num);
  164112. }
  164113. return (0);
  164114. }
  164115. #endif
  164116. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  164117. png_byte PNGAPI
  164118. png_get_rgb_to_gray_status (png_structp png_ptr)
  164119. {
  164120. return (png_byte)(png_ptr? png_ptr->rgb_to_gray_status : 0);
  164121. }
  164122. #endif
  164123. #if defined(PNG_USER_CHUNKS_SUPPORTED)
  164124. png_voidp PNGAPI
  164125. png_get_user_chunk_ptr(png_structp png_ptr)
  164126. {
  164127. return (png_ptr? png_ptr->user_chunk_ptr : NULL);
  164128. }
  164129. #endif
  164130. #ifdef PNG_WRITE_SUPPORTED
  164131. png_uint_32 PNGAPI
  164132. png_get_compression_buffer_size(png_structp png_ptr)
  164133. {
  164134. return (png_uint_32)(png_ptr? png_ptr->zbuf_size : 0L);
  164135. }
  164136. #endif
  164137. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  164138. #ifndef PNG_1_0_X
  164139. png_uint_32 PNGAPI
  164140. png_get_asm_flags (png_structp png_ptr)
  164141. {
  164142. return (png_ptr? 0L: 0L);
  164143. }
  164144. png_uint_32 PNGAPI
  164145. png_get_asm_flagmask (int flag_select)
  164146. {
  164147. flag_select=flag_select;
  164148. return 0L;
  164149. }
  164150. png_uint_32 PNGAPI
  164151. png_get_mmx_flagmask (int flag_select, int *compilerID)
  164152. {
  164153. flag_select=flag_select;
  164154. *compilerID = -1; /* unknown (i.e., no asm/MMX code compiled) */
  164155. return 0L;
  164156. }
  164157. png_byte PNGAPI
  164158. png_get_mmx_bitdepth_threshold (png_structp png_ptr)
  164159. {
  164160. return (png_ptr? 0: 0);
  164161. }
  164162. png_uint_32 PNGAPI
  164163. png_get_mmx_rowbytes_threshold (png_structp png_ptr)
  164164. {
  164165. return (png_ptr? 0L: 0L);
  164166. }
  164167. #endif /* ?PNG_1_0_X */
  164168. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  164169. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164170. png_uint_32 PNGAPI
  164171. png_get_user_width_max (png_structp png_ptr)
  164172. {
  164173. return (png_ptr? png_ptr->user_width_max : 0);
  164174. }
  164175. png_uint_32 PNGAPI
  164176. png_get_user_height_max (png_structp png_ptr)
  164177. {
  164178. return (png_ptr? png_ptr->user_height_max : 0);
  164179. }
  164180. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  164181. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164182. /*** End of inlined file: pngget.c ***/
  164183. /*** Start of inlined file: pngmem.c ***/
  164184. #define PNG_INTERNAL
  164185. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  164186. #if defined(__TURBOC__) && !defined(_Windows) && !defined(__FLAT__)
  164187. png_voidp /* PRIVATE */
  164188. png_create_struct(int type)
  164189. {
  164190. #ifdef PNG_USER_MEM_SUPPORTED
  164191. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164192. }
  164193. png_voidp /* PRIVATE */
  164194. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164195. {
  164196. #endif /* PNG_USER_MEM_SUPPORTED */
  164197. png_size_t size;
  164198. png_voidp struct_ptr;
  164199. if (type == PNG_STRUCT_INFO)
  164200. size = png_sizeof(png_info);
  164201. else if (type == PNG_STRUCT_PNG)
  164202. size = png_sizeof(png_struct);
  164203. else
  164204. return (png_get_copyright(NULL));
  164205. #ifdef PNG_USER_MEM_SUPPORTED
  164206. if(malloc_fn != NULL)
  164207. {
  164208. png_struct dummy_struct;
  164209. png_structp png_ptr = &dummy_struct;
  164210. png_ptr->mem_ptr=mem_ptr;
  164211. struct_ptr = (*(malloc_fn))(png_ptr, (png_uint_32)size);
  164212. }
  164213. else
  164214. #endif /* PNG_USER_MEM_SUPPORTED */
  164215. struct_ptr = (png_voidp)farmalloc(size);
  164216. if (struct_ptr != NULL)
  164217. png_memset(struct_ptr, 0, size);
  164218. return (struct_ptr);
  164219. }
  164220. void /* PRIVATE */
  164221. png_destroy_struct(png_voidp struct_ptr)
  164222. {
  164223. #ifdef PNG_USER_MEM_SUPPORTED
  164224. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164225. }
  164226. void /* PRIVATE */
  164227. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164228. png_voidp mem_ptr)
  164229. {
  164230. #endif
  164231. if (struct_ptr != NULL)
  164232. {
  164233. #ifdef PNG_USER_MEM_SUPPORTED
  164234. if(free_fn != NULL)
  164235. {
  164236. png_struct dummy_struct;
  164237. png_structp png_ptr = &dummy_struct;
  164238. png_ptr->mem_ptr=mem_ptr;
  164239. (*(free_fn))(png_ptr, struct_ptr);
  164240. return;
  164241. }
  164242. #endif /* PNG_USER_MEM_SUPPORTED */
  164243. farfree (struct_ptr);
  164244. }
  164245. }
  164246. png_voidp PNGAPI
  164247. png_malloc(png_structp png_ptr, png_uint_32 size)
  164248. {
  164249. png_voidp ret;
  164250. if (png_ptr == NULL || size == 0)
  164251. return (NULL);
  164252. #ifdef PNG_USER_MEM_SUPPORTED
  164253. if(png_ptr->malloc_fn != NULL)
  164254. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164255. else
  164256. ret = (png_malloc_default(png_ptr, size));
  164257. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164258. png_error(png_ptr, "Out of memory!");
  164259. return (ret);
  164260. }
  164261. png_voidp PNGAPI
  164262. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164263. {
  164264. png_voidp ret;
  164265. #endif /* PNG_USER_MEM_SUPPORTED */
  164266. if (png_ptr == NULL || size == 0)
  164267. return (NULL);
  164268. #ifdef PNG_MAX_MALLOC_64K
  164269. if (size > (png_uint_32)65536L)
  164270. {
  164271. png_warning(png_ptr, "Cannot Allocate > 64K");
  164272. ret = NULL;
  164273. }
  164274. else
  164275. #endif
  164276. if (size != (size_t)size)
  164277. ret = NULL;
  164278. else if (size == (png_uint_32)65536L)
  164279. {
  164280. if (png_ptr->offset_table == NULL)
  164281. {
  164282. ret = farmalloc(size);
  164283. if (ret == NULL || ((png_size_t)ret & 0xffff))
  164284. {
  164285. int num_blocks;
  164286. png_uint_32 total_size;
  164287. png_bytep table;
  164288. int i;
  164289. png_byte huge * hptr;
  164290. if (ret != NULL)
  164291. {
  164292. farfree(ret);
  164293. ret = NULL;
  164294. }
  164295. if(png_ptr->zlib_window_bits > 14)
  164296. num_blocks = (int)(1 << (png_ptr->zlib_window_bits - 14));
  164297. else
  164298. num_blocks = 1;
  164299. if (png_ptr->zlib_mem_level >= 7)
  164300. num_blocks += (int)(1 << (png_ptr->zlib_mem_level - 7));
  164301. else
  164302. num_blocks++;
  164303. total_size = ((png_uint_32)65536L) * (png_uint_32)num_blocks+16;
  164304. table = farmalloc(total_size);
  164305. if (table == NULL)
  164306. {
  164307. #ifndef PNG_USER_MEM_SUPPORTED
  164308. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164309. png_error(png_ptr, "Out Of Memory."); /* Note "O" and "M" */
  164310. else
  164311. png_warning(png_ptr, "Out Of Memory.");
  164312. #endif
  164313. return (NULL);
  164314. }
  164315. if ((png_size_t)table & 0xfff0)
  164316. {
  164317. #ifndef PNG_USER_MEM_SUPPORTED
  164318. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164319. png_error(png_ptr,
  164320. "Farmalloc didn't return normalized pointer");
  164321. else
  164322. png_warning(png_ptr,
  164323. "Farmalloc didn't return normalized pointer");
  164324. #endif
  164325. return (NULL);
  164326. }
  164327. png_ptr->offset_table = table;
  164328. png_ptr->offset_table_ptr = farmalloc(num_blocks *
  164329. png_sizeof (png_bytep));
  164330. if (png_ptr->offset_table_ptr == NULL)
  164331. {
  164332. #ifndef PNG_USER_MEM_SUPPORTED
  164333. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164334. png_error(png_ptr, "Out Of memory."); /* Note "O" and "M" */
  164335. else
  164336. png_warning(png_ptr, "Out Of memory.");
  164337. #endif
  164338. return (NULL);
  164339. }
  164340. hptr = (png_byte huge *)table;
  164341. if ((png_size_t)hptr & 0xf)
  164342. {
  164343. hptr = (png_byte huge *)((long)(hptr) & 0xfffffff0L);
  164344. hptr = hptr + 16L; /* "hptr += 16L" fails on Turbo C++ 3.0 */
  164345. }
  164346. for (i = 0; i < num_blocks; i++)
  164347. {
  164348. png_ptr->offset_table_ptr[i] = (png_bytep)hptr;
  164349. hptr = hptr + (png_uint_32)65536L; /* "+=" fails on TC++3.0 */
  164350. }
  164351. png_ptr->offset_table_number = num_blocks;
  164352. png_ptr->offset_table_count = 0;
  164353. png_ptr->offset_table_count_free = 0;
  164354. }
  164355. }
  164356. if (png_ptr->offset_table_count >= png_ptr->offset_table_number)
  164357. {
  164358. #ifndef PNG_USER_MEM_SUPPORTED
  164359. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164360. png_error(png_ptr, "Out of Memory."); /* Note "o" and "M" */
  164361. else
  164362. png_warning(png_ptr, "Out of Memory.");
  164363. #endif
  164364. return (NULL);
  164365. }
  164366. ret = png_ptr->offset_table_ptr[png_ptr->offset_table_count++];
  164367. }
  164368. else
  164369. ret = farmalloc(size);
  164370. #ifndef PNG_USER_MEM_SUPPORTED
  164371. if (ret == NULL)
  164372. {
  164373. if ((png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164374. png_error(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164375. else
  164376. png_warning(png_ptr, "Out of memory."); /* Note "o" and "m" */
  164377. }
  164378. #endif
  164379. return (ret);
  164380. }
  164381. void PNGAPI
  164382. png_free(png_structp png_ptr, png_voidp ptr)
  164383. {
  164384. if (png_ptr == NULL || ptr == NULL)
  164385. return;
  164386. #ifdef PNG_USER_MEM_SUPPORTED
  164387. if (png_ptr->free_fn != NULL)
  164388. {
  164389. (*(png_ptr->free_fn))(png_ptr, ptr);
  164390. return;
  164391. }
  164392. else png_free_default(png_ptr, ptr);
  164393. }
  164394. void PNGAPI
  164395. png_free_default(png_structp png_ptr, png_voidp ptr)
  164396. {
  164397. #endif /* PNG_USER_MEM_SUPPORTED */
  164398. if(png_ptr == NULL) return;
  164399. if (png_ptr->offset_table != NULL)
  164400. {
  164401. int i;
  164402. for (i = 0; i < png_ptr->offset_table_count; i++)
  164403. {
  164404. if (ptr == png_ptr->offset_table_ptr[i])
  164405. {
  164406. ptr = NULL;
  164407. png_ptr->offset_table_count_free++;
  164408. break;
  164409. }
  164410. }
  164411. if (png_ptr->offset_table_count_free == png_ptr->offset_table_count)
  164412. {
  164413. farfree(png_ptr->offset_table);
  164414. farfree(png_ptr->offset_table_ptr);
  164415. png_ptr->offset_table = NULL;
  164416. png_ptr->offset_table_ptr = NULL;
  164417. }
  164418. }
  164419. if (ptr != NULL)
  164420. {
  164421. farfree(ptr);
  164422. }
  164423. }
  164424. #else /* Not the Borland DOS special memory handler */
  164425. png_voidp /* PRIVATE */
  164426. png_create_struct(int type)
  164427. {
  164428. #ifdef PNG_USER_MEM_SUPPORTED
  164429. return (png_create_struct_2(type, png_malloc_ptr_NULL, png_voidp_NULL));
  164430. }
  164431. png_voidp /* PRIVATE */
  164432. png_create_struct_2(int type, png_malloc_ptr malloc_fn, png_voidp mem_ptr)
  164433. {
  164434. #endif /* PNG_USER_MEM_SUPPORTED */
  164435. png_size_t size;
  164436. png_voidp struct_ptr;
  164437. if (type == PNG_STRUCT_INFO)
  164438. size = png_sizeof(png_info);
  164439. else if (type == PNG_STRUCT_PNG)
  164440. size = png_sizeof(png_struct);
  164441. else
  164442. return (NULL);
  164443. #ifdef PNG_USER_MEM_SUPPORTED
  164444. if(malloc_fn != NULL)
  164445. {
  164446. png_struct dummy_struct;
  164447. png_structp png_ptr = &dummy_struct;
  164448. png_ptr->mem_ptr=mem_ptr;
  164449. struct_ptr = (*(malloc_fn))(png_ptr, size);
  164450. if (struct_ptr != NULL)
  164451. png_memset(struct_ptr, 0, size);
  164452. return (struct_ptr);
  164453. }
  164454. #endif /* PNG_USER_MEM_SUPPORTED */
  164455. #if defined(__TURBOC__) && !defined(__FLAT__)
  164456. struct_ptr = (png_voidp)farmalloc(size);
  164457. #else
  164458. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164459. struct_ptr = (png_voidp)halloc(size,1);
  164460. # else
  164461. struct_ptr = (png_voidp)malloc(size);
  164462. # endif
  164463. #endif
  164464. if (struct_ptr != NULL)
  164465. png_memset(struct_ptr, 0, size);
  164466. return (struct_ptr);
  164467. }
  164468. void /* PRIVATE */
  164469. png_destroy_struct(png_voidp struct_ptr)
  164470. {
  164471. #ifdef PNG_USER_MEM_SUPPORTED
  164472. png_destroy_struct_2(struct_ptr, png_free_ptr_NULL, png_voidp_NULL);
  164473. }
  164474. void /* PRIVATE */
  164475. png_destroy_struct_2(png_voidp struct_ptr, png_free_ptr free_fn,
  164476. png_voidp mem_ptr)
  164477. {
  164478. #endif /* PNG_USER_MEM_SUPPORTED */
  164479. if (struct_ptr != NULL)
  164480. {
  164481. #ifdef PNG_USER_MEM_SUPPORTED
  164482. if(free_fn != NULL)
  164483. {
  164484. png_struct dummy_struct;
  164485. png_structp png_ptr = &dummy_struct;
  164486. png_ptr->mem_ptr=mem_ptr;
  164487. (*(free_fn))(png_ptr, struct_ptr);
  164488. return;
  164489. }
  164490. #endif /* PNG_USER_MEM_SUPPORTED */
  164491. #if defined(__TURBOC__) && !defined(__FLAT__)
  164492. farfree(struct_ptr);
  164493. #else
  164494. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164495. hfree(struct_ptr);
  164496. # else
  164497. free(struct_ptr);
  164498. # endif
  164499. #endif
  164500. }
  164501. }
  164502. png_voidp PNGAPI
  164503. png_malloc(png_structp png_ptr, png_uint_32 size)
  164504. {
  164505. png_voidp ret;
  164506. #ifdef PNG_USER_MEM_SUPPORTED
  164507. if (png_ptr == NULL || size == 0)
  164508. return (NULL);
  164509. if(png_ptr->malloc_fn != NULL)
  164510. ret = ((png_voidp)(*(png_ptr->malloc_fn))(png_ptr, (png_size_t)size));
  164511. else
  164512. ret = (png_malloc_default(png_ptr, size));
  164513. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164514. png_error(png_ptr, "Out of Memory!");
  164515. return (ret);
  164516. }
  164517. png_voidp PNGAPI
  164518. png_malloc_default(png_structp png_ptr, png_uint_32 size)
  164519. {
  164520. png_voidp ret;
  164521. #endif /* PNG_USER_MEM_SUPPORTED */
  164522. if (png_ptr == NULL || size == 0)
  164523. return (NULL);
  164524. #ifdef PNG_MAX_MALLOC_64K
  164525. if (size > (png_uint_32)65536L)
  164526. {
  164527. #ifndef PNG_USER_MEM_SUPPORTED
  164528. if(png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164529. png_error(png_ptr, "Cannot Allocate > 64K");
  164530. else
  164531. #endif
  164532. return NULL;
  164533. }
  164534. #endif
  164535. #if defined(__TURBOC__) && !defined(__FLAT__)
  164536. if (size != (unsigned long)size)
  164537. ret = NULL;
  164538. else
  164539. ret = farmalloc(size);
  164540. #else
  164541. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164542. if (size != (unsigned long)size)
  164543. ret = NULL;
  164544. else
  164545. ret = halloc(size, 1);
  164546. # else
  164547. if (size != (size_t)size)
  164548. ret = NULL;
  164549. else
  164550. ret = malloc((size_t)size);
  164551. # endif
  164552. #endif
  164553. #ifndef PNG_USER_MEM_SUPPORTED
  164554. if (ret == NULL && (png_ptr->flags&PNG_FLAG_MALLOC_NULL_MEM_OK) == 0)
  164555. png_error(png_ptr, "Out of Memory");
  164556. #endif
  164557. return (ret);
  164558. }
  164559. void PNGAPI
  164560. png_free(png_structp png_ptr, png_voidp ptr)
  164561. {
  164562. if (png_ptr == NULL || ptr == NULL)
  164563. return;
  164564. #ifdef PNG_USER_MEM_SUPPORTED
  164565. if (png_ptr->free_fn != NULL)
  164566. {
  164567. (*(png_ptr->free_fn))(png_ptr, ptr);
  164568. return;
  164569. }
  164570. else png_free_default(png_ptr, ptr);
  164571. }
  164572. void PNGAPI
  164573. png_free_default(png_structp png_ptr, png_voidp ptr)
  164574. {
  164575. if (png_ptr == NULL || ptr == NULL)
  164576. return;
  164577. #endif /* PNG_USER_MEM_SUPPORTED */
  164578. #if defined(__TURBOC__) && !defined(__FLAT__)
  164579. farfree(ptr);
  164580. #else
  164581. # if defined(_MSC_VER) && defined(MAXSEG_64K)
  164582. hfree(ptr);
  164583. # else
  164584. free(ptr);
  164585. # endif
  164586. #endif
  164587. }
  164588. #endif /* Not Borland DOS special memory handler */
  164589. #if defined(PNG_1_0_X)
  164590. # define png_malloc_warn png_malloc
  164591. #else
  164592. png_voidp PNGAPI
  164593. png_malloc_warn(png_structp png_ptr, png_uint_32 size)
  164594. {
  164595. png_voidp ptr;
  164596. png_uint_32 save_flags;
  164597. if(png_ptr == NULL) return (NULL);
  164598. save_flags=png_ptr->flags;
  164599. png_ptr->flags|=PNG_FLAG_MALLOC_NULL_MEM_OK;
  164600. ptr = (png_voidp)png_malloc((png_structp)png_ptr, size);
  164601. png_ptr->flags=save_flags;
  164602. return(ptr);
  164603. }
  164604. #endif
  164605. png_voidp PNGAPI
  164606. png_memcpy_check (png_structp png_ptr, png_voidp s1, png_voidp s2,
  164607. png_uint_32 length)
  164608. {
  164609. png_size_t size;
  164610. size = (png_size_t)length;
  164611. if ((png_uint_32)size != length)
  164612. png_error(png_ptr,"Overflow in png_memcpy_check.");
  164613. return(png_memcpy (s1, s2, size));
  164614. }
  164615. png_voidp PNGAPI
  164616. png_memset_check (png_structp png_ptr, png_voidp s1, int value,
  164617. png_uint_32 length)
  164618. {
  164619. png_size_t size;
  164620. size = (png_size_t)length;
  164621. if ((png_uint_32)size != length)
  164622. png_error(png_ptr,"Overflow in png_memset_check.");
  164623. return (png_memset (s1, value, size));
  164624. }
  164625. #ifdef PNG_USER_MEM_SUPPORTED
  164626. void PNGAPI
  164627. png_set_mem_fn(png_structp png_ptr, png_voidp mem_ptr, png_malloc_ptr
  164628. malloc_fn, png_free_ptr free_fn)
  164629. {
  164630. if(png_ptr != NULL) {
  164631. png_ptr->mem_ptr = mem_ptr;
  164632. png_ptr->malloc_fn = malloc_fn;
  164633. png_ptr->free_fn = free_fn;
  164634. }
  164635. }
  164636. png_voidp PNGAPI
  164637. png_get_mem_ptr(png_structp png_ptr)
  164638. {
  164639. if(png_ptr == NULL) return (NULL);
  164640. return ((png_voidp)png_ptr->mem_ptr);
  164641. }
  164642. #endif /* PNG_USER_MEM_SUPPORTED */
  164643. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  164644. /*** End of inlined file: pngmem.c ***/
  164645. /*** Start of inlined file: pngread.c ***/
  164646. #define PNG_INTERNAL
  164647. #if defined(PNG_READ_SUPPORTED)
  164648. png_structp PNGAPI
  164649. png_create_read_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  164650. png_error_ptr error_fn, png_error_ptr warn_fn)
  164651. {
  164652. #ifdef PNG_USER_MEM_SUPPORTED
  164653. return (png_create_read_struct_2(user_png_ver, error_ptr, error_fn,
  164654. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  164655. }
  164656. png_structp PNGAPI
  164657. png_create_read_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  164658. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  164659. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  164660. {
  164661. #endif /* PNG_USER_MEM_SUPPORTED */
  164662. png_structp png_ptr;
  164663. #ifdef PNG_SETJMP_SUPPORTED
  164664. #ifdef USE_FAR_KEYWORD
  164665. jmp_buf jmpbuf;
  164666. #endif
  164667. #endif
  164668. int i;
  164669. png_debug(1, "in png_create_read_struct\n");
  164670. #ifdef PNG_USER_MEM_SUPPORTED
  164671. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  164672. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  164673. #else
  164674. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164675. #endif
  164676. if (png_ptr == NULL)
  164677. return (NULL);
  164678. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164679. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164680. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164681. #endif
  164682. #ifdef PNG_SETJMP_SUPPORTED
  164683. #ifdef USE_FAR_KEYWORD
  164684. if (setjmp(jmpbuf))
  164685. #else
  164686. if (setjmp(png_ptr->jmpbuf))
  164687. #endif
  164688. {
  164689. png_free(png_ptr, png_ptr->zbuf);
  164690. png_ptr->zbuf=NULL;
  164691. #ifdef PNG_USER_MEM_SUPPORTED
  164692. png_destroy_struct_2((png_voidp)png_ptr,
  164693. (png_free_ptr)free_fn, (png_voidp)mem_ptr);
  164694. #else
  164695. png_destroy_struct((png_voidp)png_ptr);
  164696. #endif
  164697. return (NULL);
  164698. }
  164699. #ifdef USE_FAR_KEYWORD
  164700. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164701. #endif
  164702. #endif
  164703. #ifdef PNG_USER_MEM_SUPPORTED
  164704. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  164705. #endif
  164706. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  164707. i=0;
  164708. do
  164709. {
  164710. if(user_png_ver[i] != png_libpng_ver[i])
  164711. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164712. } while (png_libpng_ver[i++]);
  164713. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  164714. {
  164715. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  164716. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  164717. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  164718. {
  164719. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164720. char msg[80];
  164721. if (user_png_ver)
  164722. {
  164723. png_snprintf(msg, 80,
  164724. "Application was compiled with png.h from libpng-%.20s",
  164725. user_png_ver);
  164726. png_warning(png_ptr, msg);
  164727. }
  164728. png_snprintf(msg, 80,
  164729. "Application is running with png.c from libpng-%.20s",
  164730. png_libpng_ver);
  164731. png_warning(png_ptr, msg);
  164732. #endif
  164733. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164734. png_ptr->flags=0;
  164735. #endif
  164736. png_error(png_ptr,
  164737. "Incompatible libpng version in application and library");
  164738. }
  164739. }
  164740. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164741. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164742. (png_uint_32)png_ptr->zbuf_size);
  164743. png_ptr->zstream.zalloc = png_zalloc;
  164744. png_ptr->zstream.zfree = png_zfree;
  164745. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164746. switch (inflateInit(&png_ptr->zstream))
  164747. {
  164748. case Z_OK: /* Do nothing */ break;
  164749. case Z_MEM_ERROR:
  164750. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory error"); break;
  164751. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version error"); break;
  164752. default: png_error(png_ptr, "Unknown zlib error");
  164753. }
  164754. png_ptr->zstream.next_out = png_ptr->zbuf;
  164755. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164756. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164757. #ifdef PNG_SETJMP_SUPPORTED
  164758. #ifdef USE_FAR_KEYWORD
  164759. if (setjmp(jmpbuf))
  164760. PNG_ABORT();
  164761. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  164762. #else
  164763. if (setjmp(png_ptr->jmpbuf))
  164764. PNG_ABORT();
  164765. #endif
  164766. #endif
  164767. return (png_ptr);
  164768. }
  164769. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  164770. #undef png_read_init
  164771. void PNGAPI
  164772. png_read_init(png_structp png_ptr)
  164773. {
  164774. png_read_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  164775. }
  164776. void PNGAPI
  164777. png_read_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  164778. png_size_t png_struct_size, png_size_t png_info_size)
  164779. {
  164780. if(png_ptr == NULL) return;
  164781. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  164782. if(png_sizeof(png_struct) > png_struct_size ||
  164783. png_sizeof(png_info) > png_info_size)
  164784. {
  164785. char msg[80];
  164786. png_ptr->warning_fn=NULL;
  164787. if (user_png_ver)
  164788. {
  164789. png_snprintf(msg, 80,
  164790. "Application was compiled with png.h from libpng-%.20s",
  164791. user_png_ver);
  164792. png_warning(png_ptr, msg);
  164793. }
  164794. png_snprintf(msg, 80,
  164795. "Application is running with png.c from libpng-%.20s",
  164796. png_libpng_ver);
  164797. png_warning(png_ptr, msg);
  164798. }
  164799. #endif
  164800. if(png_sizeof(png_struct) > png_struct_size)
  164801. {
  164802. png_ptr->error_fn=NULL;
  164803. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164804. png_ptr->flags=0;
  164805. #endif
  164806. png_error(png_ptr,
  164807. "The png struct allocated by the application for reading is too small.");
  164808. }
  164809. if(png_sizeof(png_info) > png_info_size)
  164810. {
  164811. png_ptr->error_fn=NULL;
  164812. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  164813. png_ptr->flags=0;
  164814. #endif
  164815. png_error(png_ptr,
  164816. "The info struct allocated by application for reading is too small.");
  164817. }
  164818. png_read_init_3(&png_ptr, user_png_ver, png_struct_size);
  164819. }
  164820. #endif /* PNG_1_0_X || PNG_1_2_X */
  164821. void PNGAPI
  164822. png_read_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  164823. png_size_t png_struct_size)
  164824. {
  164825. #ifdef PNG_SETJMP_SUPPORTED
  164826. jmp_buf tmp_jmp; /* to save current jump buffer */
  164827. #endif
  164828. int i=0;
  164829. png_structp png_ptr=*ptr_ptr;
  164830. if(png_ptr == NULL) return;
  164831. do
  164832. {
  164833. if(user_png_ver[i] != png_libpng_ver[i])
  164834. {
  164835. #ifdef PNG_LEGACY_SUPPORTED
  164836. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  164837. #else
  164838. png_ptr->warning_fn=NULL;
  164839. png_warning(png_ptr,
  164840. "Application uses deprecated png_read_init() and should be recompiled.");
  164841. break;
  164842. #endif
  164843. }
  164844. } while (png_libpng_ver[i++]);
  164845. png_debug(1, "in png_read_init_3\n");
  164846. #ifdef PNG_SETJMP_SUPPORTED
  164847. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  164848. #endif
  164849. if(png_sizeof(png_struct) > png_struct_size)
  164850. {
  164851. png_destroy_struct(png_ptr);
  164852. *ptr_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  164853. png_ptr = *ptr_ptr;
  164854. }
  164855. png_memset(png_ptr, 0, png_sizeof (png_struct));
  164856. #ifdef PNG_SETJMP_SUPPORTED
  164857. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  164858. #endif
  164859. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  164860. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  164861. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  164862. #endif
  164863. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  164864. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  164865. (png_uint_32)png_ptr->zbuf_size);
  164866. png_ptr->zstream.zalloc = png_zalloc;
  164867. png_ptr->zstream.zfree = png_zfree;
  164868. png_ptr->zstream.opaque = (voidpf)png_ptr;
  164869. switch (inflateInit(&png_ptr->zstream))
  164870. {
  164871. case Z_OK: /* Do nothing */ break;
  164872. case Z_MEM_ERROR:
  164873. case Z_STREAM_ERROR: png_error(png_ptr, "zlib memory"); break;
  164874. case Z_VERSION_ERROR: png_error(png_ptr, "zlib version"); break;
  164875. default: png_error(png_ptr, "Unknown zlib error");
  164876. }
  164877. png_ptr->zstream.next_out = png_ptr->zbuf;
  164878. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  164879. png_set_read_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL);
  164880. }
  164881. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  164882. void PNGAPI
  164883. png_read_info(png_structp png_ptr, png_infop info_ptr)
  164884. {
  164885. if(png_ptr == NULL) return;
  164886. png_debug(1, "in png_read_info\n");
  164887. if (png_ptr->sig_bytes < 8)
  164888. {
  164889. png_size_t num_checked = png_ptr->sig_bytes,
  164890. num_to_check = 8 - num_checked;
  164891. png_read_data(png_ptr, &(info_ptr->signature[num_checked]), num_to_check);
  164892. png_ptr->sig_bytes = 8;
  164893. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  164894. {
  164895. if (num_checked < 4 &&
  164896. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  164897. png_error(png_ptr, "Not a PNG file");
  164898. else
  164899. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  164900. }
  164901. if (num_checked < 3)
  164902. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  164903. }
  164904. for(;;)
  164905. {
  164906. #ifdef PNG_USE_LOCAL_ARRAYS
  164907. PNG_CONST PNG_IHDR;
  164908. PNG_CONST PNG_IDAT;
  164909. PNG_CONST PNG_IEND;
  164910. PNG_CONST PNG_PLTE;
  164911. #if defined(PNG_READ_bKGD_SUPPORTED)
  164912. PNG_CONST PNG_bKGD;
  164913. #endif
  164914. #if defined(PNG_READ_cHRM_SUPPORTED)
  164915. PNG_CONST PNG_cHRM;
  164916. #endif
  164917. #if defined(PNG_READ_gAMA_SUPPORTED)
  164918. PNG_CONST PNG_gAMA;
  164919. #endif
  164920. #if defined(PNG_READ_hIST_SUPPORTED)
  164921. PNG_CONST PNG_hIST;
  164922. #endif
  164923. #if defined(PNG_READ_iCCP_SUPPORTED)
  164924. PNG_CONST PNG_iCCP;
  164925. #endif
  164926. #if defined(PNG_READ_iTXt_SUPPORTED)
  164927. PNG_CONST PNG_iTXt;
  164928. #endif
  164929. #if defined(PNG_READ_oFFs_SUPPORTED)
  164930. PNG_CONST PNG_oFFs;
  164931. #endif
  164932. #if defined(PNG_READ_pCAL_SUPPORTED)
  164933. PNG_CONST PNG_pCAL;
  164934. #endif
  164935. #if defined(PNG_READ_pHYs_SUPPORTED)
  164936. PNG_CONST PNG_pHYs;
  164937. #endif
  164938. #if defined(PNG_READ_sBIT_SUPPORTED)
  164939. PNG_CONST PNG_sBIT;
  164940. #endif
  164941. #if defined(PNG_READ_sCAL_SUPPORTED)
  164942. PNG_CONST PNG_sCAL;
  164943. #endif
  164944. #if defined(PNG_READ_sPLT_SUPPORTED)
  164945. PNG_CONST PNG_sPLT;
  164946. #endif
  164947. #if defined(PNG_READ_sRGB_SUPPORTED)
  164948. PNG_CONST PNG_sRGB;
  164949. #endif
  164950. #if defined(PNG_READ_tEXt_SUPPORTED)
  164951. PNG_CONST PNG_tEXt;
  164952. #endif
  164953. #if defined(PNG_READ_tIME_SUPPORTED)
  164954. PNG_CONST PNG_tIME;
  164955. #endif
  164956. #if defined(PNG_READ_tRNS_SUPPORTED)
  164957. PNG_CONST PNG_tRNS;
  164958. #endif
  164959. #if defined(PNG_READ_zTXt_SUPPORTED)
  164960. PNG_CONST PNG_zTXt;
  164961. #endif
  164962. #endif /* PNG_USE_LOCAL_ARRAYS */
  164963. png_byte chunk_length[4];
  164964. png_uint_32 length;
  164965. png_read_data(png_ptr, chunk_length, 4);
  164966. length = png_get_uint_31(png_ptr,chunk_length);
  164967. png_reset_crc(png_ptr);
  164968. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  164969. png_debug2(0, "Reading %s chunk, length=%lu.\n", png_ptr->chunk_name,
  164970. length);
  164971. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164972. if(png_ptr->mode & PNG_AFTER_IDAT)
  164973. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  164974. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  164975. png_handle_IHDR(png_ptr, info_ptr, length);
  164976. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  164977. png_handle_IEND(png_ptr, info_ptr, length);
  164978. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  164979. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  164980. {
  164981. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164982. png_ptr->mode |= PNG_HAVE_IDAT;
  164983. png_handle_unknown(png_ptr, info_ptr, length);
  164984. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164985. png_ptr->mode |= PNG_HAVE_PLTE;
  164986. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  164987. {
  164988. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  164989. png_error(png_ptr, "Missing IHDR before IDAT");
  164990. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  164991. !(png_ptr->mode & PNG_HAVE_PLTE))
  164992. png_error(png_ptr, "Missing PLTE before IDAT");
  164993. break;
  164994. }
  164995. }
  164996. #endif
  164997. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  164998. png_handle_PLTE(png_ptr, info_ptr, length);
  164999. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165000. {
  165001. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  165002. png_error(png_ptr, "Missing IHDR before IDAT");
  165003. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  165004. !(png_ptr->mode & PNG_HAVE_PLTE))
  165005. png_error(png_ptr, "Missing PLTE before IDAT");
  165006. png_ptr->idat_size = length;
  165007. png_ptr->mode |= PNG_HAVE_IDAT;
  165008. break;
  165009. }
  165010. #if defined(PNG_READ_bKGD_SUPPORTED)
  165011. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165012. png_handle_bKGD(png_ptr, info_ptr, length);
  165013. #endif
  165014. #if defined(PNG_READ_cHRM_SUPPORTED)
  165015. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165016. png_handle_cHRM(png_ptr, info_ptr, length);
  165017. #endif
  165018. #if defined(PNG_READ_gAMA_SUPPORTED)
  165019. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165020. png_handle_gAMA(png_ptr, info_ptr, length);
  165021. #endif
  165022. #if defined(PNG_READ_hIST_SUPPORTED)
  165023. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165024. png_handle_hIST(png_ptr, info_ptr, length);
  165025. #endif
  165026. #if defined(PNG_READ_oFFs_SUPPORTED)
  165027. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165028. png_handle_oFFs(png_ptr, info_ptr, length);
  165029. #endif
  165030. #if defined(PNG_READ_pCAL_SUPPORTED)
  165031. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165032. png_handle_pCAL(png_ptr, info_ptr, length);
  165033. #endif
  165034. #if defined(PNG_READ_sCAL_SUPPORTED)
  165035. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165036. png_handle_sCAL(png_ptr, info_ptr, length);
  165037. #endif
  165038. #if defined(PNG_READ_pHYs_SUPPORTED)
  165039. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165040. png_handle_pHYs(png_ptr, info_ptr, length);
  165041. #endif
  165042. #if defined(PNG_READ_sBIT_SUPPORTED)
  165043. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165044. png_handle_sBIT(png_ptr, info_ptr, length);
  165045. #endif
  165046. #if defined(PNG_READ_sRGB_SUPPORTED)
  165047. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165048. png_handle_sRGB(png_ptr, info_ptr, length);
  165049. #endif
  165050. #if defined(PNG_READ_iCCP_SUPPORTED)
  165051. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165052. png_handle_iCCP(png_ptr, info_ptr, length);
  165053. #endif
  165054. #if defined(PNG_READ_sPLT_SUPPORTED)
  165055. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165056. png_handle_sPLT(png_ptr, info_ptr, length);
  165057. #endif
  165058. #if defined(PNG_READ_tEXt_SUPPORTED)
  165059. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165060. png_handle_tEXt(png_ptr, info_ptr, length);
  165061. #endif
  165062. #if defined(PNG_READ_tIME_SUPPORTED)
  165063. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165064. png_handle_tIME(png_ptr, info_ptr, length);
  165065. #endif
  165066. #if defined(PNG_READ_tRNS_SUPPORTED)
  165067. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165068. png_handle_tRNS(png_ptr, info_ptr, length);
  165069. #endif
  165070. #if defined(PNG_READ_zTXt_SUPPORTED)
  165071. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165072. png_handle_zTXt(png_ptr, info_ptr, length);
  165073. #endif
  165074. #if defined(PNG_READ_iTXt_SUPPORTED)
  165075. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165076. png_handle_iTXt(png_ptr, info_ptr, length);
  165077. #endif
  165078. else
  165079. png_handle_unknown(png_ptr, info_ptr, length);
  165080. }
  165081. }
  165082. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165083. void PNGAPI
  165084. png_read_update_info(png_structp png_ptr, png_infop info_ptr)
  165085. {
  165086. png_debug(1, "in png_read_update_info\n");
  165087. if(png_ptr == NULL) return;
  165088. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165089. png_read_start_row(png_ptr);
  165090. else
  165091. png_warning(png_ptr,
  165092. "Ignoring extra png_read_update_info() call; row buffer not reallocated");
  165093. png_read_transform_info(png_ptr, info_ptr);
  165094. }
  165095. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165096. void PNGAPI
  165097. png_start_read_image(png_structp png_ptr)
  165098. {
  165099. png_debug(1, "in png_start_read_image\n");
  165100. if(png_ptr == NULL) return;
  165101. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165102. png_read_start_row(png_ptr);
  165103. }
  165104. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165105. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165106. void PNGAPI
  165107. png_read_row(png_structp png_ptr, png_bytep row, png_bytep dsp_row)
  165108. {
  165109. #ifdef PNG_USE_LOCAL_ARRAYS
  165110. PNG_CONST PNG_IDAT;
  165111. PNG_CONST int png_pass_dsp_mask[7] = {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55,
  165112. 0xff};
  165113. PNG_CONST int png_pass_mask[7] = {0x80, 0x08, 0x88, 0x22, 0xaa, 0x55, 0xff};
  165114. #endif
  165115. int ret;
  165116. if(png_ptr == NULL) return;
  165117. png_debug2(1, "in png_read_row (row %lu, pass %d)\n",
  165118. png_ptr->row_number, png_ptr->pass);
  165119. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  165120. png_read_start_row(png_ptr);
  165121. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  165122. {
  165123. #if defined(PNG_WRITE_INVERT_SUPPORTED) && !defined(PNG_READ_INVERT_SUPPORTED)
  165124. if (png_ptr->transformations & PNG_INVERT_MONO)
  165125. png_warning(png_ptr, "PNG_READ_INVERT_SUPPORTED is not defined.");
  165126. #endif
  165127. #if defined(PNG_WRITE_FILLER_SUPPORTED) && !defined(PNG_READ_FILLER_SUPPORTED)
  165128. if (png_ptr->transformations & PNG_FILLER)
  165129. png_warning(png_ptr, "PNG_READ_FILLER_SUPPORTED is not defined.");
  165130. #endif
  165131. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED) && !defined(PNG_READ_PACKSWAP_SUPPORTED)
  165132. if (png_ptr->transformations & PNG_PACKSWAP)
  165133. png_warning(png_ptr, "PNG_READ_PACKSWAP_SUPPORTED is not defined.");
  165134. #endif
  165135. #if defined(PNG_WRITE_PACK_SUPPORTED) && !defined(PNG_READ_PACK_SUPPORTED)
  165136. if (png_ptr->transformations & PNG_PACK)
  165137. png_warning(png_ptr, "PNG_READ_PACK_SUPPORTED is not defined.");
  165138. #endif
  165139. #if defined(PNG_WRITE_SHIFT_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED)
  165140. if (png_ptr->transformations & PNG_SHIFT)
  165141. png_warning(png_ptr, "PNG_READ_SHIFT_SUPPORTED is not defined.");
  165142. #endif
  165143. #if defined(PNG_WRITE_BGR_SUPPORTED) && !defined(PNG_READ_BGR_SUPPORTED)
  165144. if (png_ptr->transformations & PNG_BGR)
  165145. png_warning(png_ptr, "PNG_READ_BGR_SUPPORTED is not defined.");
  165146. #endif
  165147. #if defined(PNG_WRITE_SWAP_SUPPORTED) && !defined(PNG_READ_SWAP_SUPPORTED)
  165148. if (png_ptr->transformations & PNG_SWAP_BYTES)
  165149. png_warning(png_ptr, "PNG_READ_SWAP_SUPPORTED is not defined.");
  165150. #endif
  165151. }
  165152. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165153. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  165154. {
  165155. switch (png_ptr->pass)
  165156. {
  165157. case 0:
  165158. if (png_ptr->row_number & 0x07)
  165159. {
  165160. if (dsp_row != NULL)
  165161. png_combine_row(png_ptr, dsp_row,
  165162. png_pass_dsp_mask[png_ptr->pass]);
  165163. png_read_finish_row(png_ptr);
  165164. return;
  165165. }
  165166. break;
  165167. case 1:
  165168. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  165169. {
  165170. if (dsp_row != NULL)
  165171. png_combine_row(png_ptr, dsp_row,
  165172. png_pass_dsp_mask[png_ptr->pass]);
  165173. png_read_finish_row(png_ptr);
  165174. return;
  165175. }
  165176. break;
  165177. case 2:
  165178. if ((png_ptr->row_number & 0x07) != 4)
  165179. {
  165180. if (dsp_row != NULL && (png_ptr->row_number & 4))
  165181. png_combine_row(png_ptr, dsp_row,
  165182. png_pass_dsp_mask[png_ptr->pass]);
  165183. png_read_finish_row(png_ptr);
  165184. return;
  165185. }
  165186. break;
  165187. case 3:
  165188. if ((png_ptr->row_number & 3) || png_ptr->width < 3)
  165189. {
  165190. if (dsp_row != NULL)
  165191. png_combine_row(png_ptr, dsp_row,
  165192. png_pass_dsp_mask[png_ptr->pass]);
  165193. png_read_finish_row(png_ptr);
  165194. return;
  165195. }
  165196. break;
  165197. case 4:
  165198. if ((png_ptr->row_number & 3) != 2)
  165199. {
  165200. if (dsp_row != NULL && (png_ptr->row_number & 2))
  165201. png_combine_row(png_ptr, dsp_row,
  165202. png_pass_dsp_mask[png_ptr->pass]);
  165203. png_read_finish_row(png_ptr);
  165204. return;
  165205. }
  165206. break;
  165207. case 5:
  165208. if ((png_ptr->row_number & 1) || png_ptr->width < 2)
  165209. {
  165210. if (dsp_row != NULL)
  165211. png_combine_row(png_ptr, dsp_row,
  165212. png_pass_dsp_mask[png_ptr->pass]);
  165213. png_read_finish_row(png_ptr);
  165214. return;
  165215. }
  165216. break;
  165217. case 6:
  165218. if (!(png_ptr->row_number & 1))
  165219. {
  165220. png_read_finish_row(png_ptr);
  165221. return;
  165222. }
  165223. break;
  165224. }
  165225. }
  165226. #endif
  165227. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  165228. png_error(png_ptr, "Invalid attempt to read row data");
  165229. png_ptr->zstream.next_out = png_ptr->row_buf;
  165230. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  165231. do
  165232. {
  165233. if (!(png_ptr->zstream.avail_in))
  165234. {
  165235. while (!png_ptr->idat_size)
  165236. {
  165237. png_byte chunk_length[4];
  165238. png_crc_finish(png_ptr, 0);
  165239. png_read_data(png_ptr, chunk_length, 4);
  165240. png_ptr->idat_size = png_get_uint_31(png_ptr,chunk_length);
  165241. png_reset_crc(png_ptr);
  165242. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165243. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165244. png_error(png_ptr, "Not enough image data");
  165245. }
  165246. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  165247. png_ptr->zstream.next_in = png_ptr->zbuf;
  165248. if (png_ptr->zbuf_size > png_ptr->idat_size)
  165249. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  165250. png_crc_read(png_ptr, png_ptr->zbuf,
  165251. (png_size_t)png_ptr->zstream.avail_in);
  165252. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  165253. }
  165254. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  165255. if (ret == Z_STREAM_END)
  165256. {
  165257. if (png_ptr->zstream.avail_out || png_ptr->zstream.avail_in ||
  165258. png_ptr->idat_size)
  165259. png_error(png_ptr, "Extra compressed data");
  165260. png_ptr->mode |= PNG_AFTER_IDAT;
  165261. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  165262. break;
  165263. }
  165264. if (ret != Z_OK)
  165265. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  165266. "Decompression error");
  165267. } while (png_ptr->zstream.avail_out);
  165268. png_ptr->row_info.color_type = png_ptr->color_type;
  165269. png_ptr->row_info.width = png_ptr->iwidth;
  165270. png_ptr->row_info.channels = png_ptr->channels;
  165271. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  165272. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  165273. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  165274. png_ptr->row_info.width);
  165275. if(png_ptr->row_buf[0])
  165276. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  165277. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  165278. (int)(png_ptr->row_buf[0]));
  165279. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  165280. png_ptr->rowbytes + 1);
  165281. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  165282. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  165283. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  165284. {
  165285. png_do_read_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  165286. }
  165287. #endif
  165288. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  165289. png_do_read_transformations(png_ptr);
  165290. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  165291. if (png_ptr->interlaced &&
  165292. (png_ptr->transformations & PNG_INTERLACE))
  165293. {
  165294. if (png_ptr->pass < 6)
  165295. png_do_read_interlace(png_ptr);
  165296. if (dsp_row != NULL)
  165297. png_combine_row(png_ptr, dsp_row,
  165298. png_pass_dsp_mask[png_ptr->pass]);
  165299. if (row != NULL)
  165300. png_combine_row(png_ptr, row,
  165301. png_pass_mask[png_ptr->pass]);
  165302. }
  165303. else
  165304. #endif
  165305. {
  165306. if (row != NULL)
  165307. png_combine_row(png_ptr, row, 0xff);
  165308. if (dsp_row != NULL)
  165309. png_combine_row(png_ptr, dsp_row, 0xff);
  165310. }
  165311. png_read_finish_row(png_ptr);
  165312. if (png_ptr->read_row_fn != NULL)
  165313. (*(png_ptr->read_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  165314. }
  165315. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165316. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165317. void PNGAPI
  165318. png_read_rows(png_structp png_ptr, png_bytepp row,
  165319. png_bytepp display_row, png_uint_32 num_rows)
  165320. {
  165321. png_uint_32 i;
  165322. png_bytepp rp;
  165323. png_bytepp dp;
  165324. png_debug(1, "in png_read_rows\n");
  165325. if(png_ptr == NULL) return;
  165326. rp = row;
  165327. dp = display_row;
  165328. if (rp != NULL && dp != NULL)
  165329. for (i = 0; i < num_rows; i++)
  165330. {
  165331. png_bytep rptr = *rp++;
  165332. png_bytep dptr = *dp++;
  165333. png_read_row(png_ptr, rptr, dptr);
  165334. }
  165335. else if(rp != NULL)
  165336. for (i = 0; i < num_rows; i++)
  165337. {
  165338. png_bytep rptr = *rp;
  165339. png_read_row(png_ptr, rptr, png_bytep_NULL);
  165340. rp++;
  165341. }
  165342. else if(dp != NULL)
  165343. for (i = 0; i < num_rows; i++)
  165344. {
  165345. png_bytep dptr = *dp;
  165346. png_read_row(png_ptr, png_bytep_NULL, dptr);
  165347. dp++;
  165348. }
  165349. }
  165350. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165351. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165352. void PNGAPI
  165353. png_read_image(png_structp png_ptr, png_bytepp image)
  165354. {
  165355. png_uint_32 i,image_height;
  165356. int pass, j;
  165357. png_bytepp rp;
  165358. png_debug(1, "in png_read_image\n");
  165359. if(png_ptr == NULL) return;
  165360. #ifdef PNG_READ_INTERLACING_SUPPORTED
  165361. pass = png_set_interlace_handling(png_ptr);
  165362. #else
  165363. if (png_ptr->interlaced)
  165364. png_error(png_ptr,
  165365. "Cannot read interlaced image -- interlace handler disabled.");
  165366. pass = 1;
  165367. #endif
  165368. image_height=png_ptr->height;
  165369. png_ptr->num_rows = image_height; /* Make sure this is set correctly */
  165370. for (j = 0; j < pass; j++)
  165371. {
  165372. rp = image;
  165373. for (i = 0; i < image_height; i++)
  165374. {
  165375. png_read_row(png_ptr, *rp, png_bytep_NULL);
  165376. rp++;
  165377. }
  165378. }
  165379. }
  165380. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165381. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165382. void PNGAPI
  165383. png_read_end(png_structp png_ptr, png_infop info_ptr)
  165384. {
  165385. png_byte chunk_length[4];
  165386. png_uint_32 length;
  165387. png_debug(1, "in png_read_end\n");
  165388. if(png_ptr == NULL) return;
  165389. png_crc_finish(png_ptr, 0); /* Finish off CRC from last IDAT chunk */
  165390. do
  165391. {
  165392. #ifdef PNG_USE_LOCAL_ARRAYS
  165393. PNG_CONST PNG_IHDR;
  165394. PNG_CONST PNG_IDAT;
  165395. PNG_CONST PNG_IEND;
  165396. PNG_CONST PNG_PLTE;
  165397. #if defined(PNG_READ_bKGD_SUPPORTED)
  165398. PNG_CONST PNG_bKGD;
  165399. #endif
  165400. #if defined(PNG_READ_cHRM_SUPPORTED)
  165401. PNG_CONST PNG_cHRM;
  165402. #endif
  165403. #if defined(PNG_READ_gAMA_SUPPORTED)
  165404. PNG_CONST PNG_gAMA;
  165405. #endif
  165406. #if defined(PNG_READ_hIST_SUPPORTED)
  165407. PNG_CONST PNG_hIST;
  165408. #endif
  165409. #if defined(PNG_READ_iCCP_SUPPORTED)
  165410. PNG_CONST PNG_iCCP;
  165411. #endif
  165412. #if defined(PNG_READ_iTXt_SUPPORTED)
  165413. PNG_CONST PNG_iTXt;
  165414. #endif
  165415. #if defined(PNG_READ_oFFs_SUPPORTED)
  165416. PNG_CONST PNG_oFFs;
  165417. #endif
  165418. #if defined(PNG_READ_pCAL_SUPPORTED)
  165419. PNG_CONST PNG_pCAL;
  165420. #endif
  165421. #if defined(PNG_READ_pHYs_SUPPORTED)
  165422. PNG_CONST PNG_pHYs;
  165423. #endif
  165424. #if defined(PNG_READ_sBIT_SUPPORTED)
  165425. PNG_CONST PNG_sBIT;
  165426. #endif
  165427. #if defined(PNG_READ_sCAL_SUPPORTED)
  165428. PNG_CONST PNG_sCAL;
  165429. #endif
  165430. #if defined(PNG_READ_sPLT_SUPPORTED)
  165431. PNG_CONST PNG_sPLT;
  165432. #endif
  165433. #if defined(PNG_READ_sRGB_SUPPORTED)
  165434. PNG_CONST PNG_sRGB;
  165435. #endif
  165436. #if defined(PNG_READ_tEXt_SUPPORTED)
  165437. PNG_CONST PNG_tEXt;
  165438. #endif
  165439. #if defined(PNG_READ_tIME_SUPPORTED)
  165440. PNG_CONST PNG_tIME;
  165441. #endif
  165442. #if defined(PNG_READ_tRNS_SUPPORTED)
  165443. PNG_CONST PNG_tRNS;
  165444. #endif
  165445. #if defined(PNG_READ_zTXt_SUPPORTED)
  165446. PNG_CONST PNG_zTXt;
  165447. #endif
  165448. #endif /* PNG_USE_LOCAL_ARRAYS */
  165449. png_read_data(png_ptr, chunk_length, 4);
  165450. length = png_get_uint_31(png_ptr,chunk_length);
  165451. png_reset_crc(png_ptr);
  165452. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  165453. png_debug1(0, "Reading %s chunk.\n", png_ptr->chunk_name);
  165454. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  165455. png_handle_IHDR(png_ptr, info_ptr, length);
  165456. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  165457. png_handle_IEND(png_ptr, info_ptr, length);
  165458. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  165459. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  165460. {
  165461. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165462. {
  165463. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165464. png_error(png_ptr, "Too many IDAT's found");
  165465. }
  165466. png_handle_unknown(png_ptr, info_ptr, length);
  165467. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165468. png_ptr->mode |= PNG_HAVE_PLTE;
  165469. }
  165470. #endif
  165471. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  165472. {
  165473. if ((length > 0) || (png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  165474. png_error(png_ptr, "Too many IDAT's found");
  165475. png_crc_finish(png_ptr, length);
  165476. }
  165477. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  165478. png_handle_PLTE(png_ptr, info_ptr, length);
  165479. #if defined(PNG_READ_bKGD_SUPPORTED)
  165480. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  165481. png_handle_bKGD(png_ptr, info_ptr, length);
  165482. #endif
  165483. #if defined(PNG_READ_cHRM_SUPPORTED)
  165484. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  165485. png_handle_cHRM(png_ptr, info_ptr, length);
  165486. #endif
  165487. #if defined(PNG_READ_gAMA_SUPPORTED)
  165488. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  165489. png_handle_gAMA(png_ptr, info_ptr, length);
  165490. #endif
  165491. #if defined(PNG_READ_hIST_SUPPORTED)
  165492. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  165493. png_handle_hIST(png_ptr, info_ptr, length);
  165494. #endif
  165495. #if defined(PNG_READ_oFFs_SUPPORTED)
  165496. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  165497. png_handle_oFFs(png_ptr, info_ptr, length);
  165498. #endif
  165499. #if defined(PNG_READ_pCAL_SUPPORTED)
  165500. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  165501. png_handle_pCAL(png_ptr, info_ptr, length);
  165502. #endif
  165503. #if defined(PNG_READ_sCAL_SUPPORTED)
  165504. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  165505. png_handle_sCAL(png_ptr, info_ptr, length);
  165506. #endif
  165507. #if defined(PNG_READ_pHYs_SUPPORTED)
  165508. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  165509. png_handle_pHYs(png_ptr, info_ptr, length);
  165510. #endif
  165511. #if defined(PNG_READ_sBIT_SUPPORTED)
  165512. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  165513. png_handle_sBIT(png_ptr, info_ptr, length);
  165514. #endif
  165515. #if defined(PNG_READ_sRGB_SUPPORTED)
  165516. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  165517. png_handle_sRGB(png_ptr, info_ptr, length);
  165518. #endif
  165519. #if defined(PNG_READ_iCCP_SUPPORTED)
  165520. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  165521. png_handle_iCCP(png_ptr, info_ptr, length);
  165522. #endif
  165523. #if defined(PNG_READ_sPLT_SUPPORTED)
  165524. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  165525. png_handle_sPLT(png_ptr, info_ptr, length);
  165526. #endif
  165527. #if defined(PNG_READ_tEXt_SUPPORTED)
  165528. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  165529. png_handle_tEXt(png_ptr, info_ptr, length);
  165530. #endif
  165531. #if defined(PNG_READ_tIME_SUPPORTED)
  165532. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  165533. png_handle_tIME(png_ptr, info_ptr, length);
  165534. #endif
  165535. #if defined(PNG_READ_tRNS_SUPPORTED)
  165536. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  165537. png_handle_tRNS(png_ptr, info_ptr, length);
  165538. #endif
  165539. #if defined(PNG_READ_zTXt_SUPPORTED)
  165540. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  165541. png_handle_zTXt(png_ptr, info_ptr, length);
  165542. #endif
  165543. #if defined(PNG_READ_iTXt_SUPPORTED)
  165544. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  165545. png_handle_iTXt(png_ptr, info_ptr, length);
  165546. #endif
  165547. else
  165548. png_handle_unknown(png_ptr, info_ptr, length);
  165549. } while (!(png_ptr->mode & PNG_HAVE_IEND));
  165550. }
  165551. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165552. void PNGAPI
  165553. png_destroy_read_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr,
  165554. png_infopp end_info_ptr_ptr)
  165555. {
  165556. png_structp png_ptr = NULL;
  165557. png_infop info_ptr = NULL, end_info_ptr = NULL;
  165558. #ifdef PNG_USER_MEM_SUPPORTED
  165559. png_free_ptr free_fn;
  165560. png_voidp mem_ptr;
  165561. #endif
  165562. png_debug(1, "in png_destroy_read_struct\n");
  165563. if (png_ptr_ptr != NULL)
  165564. png_ptr = *png_ptr_ptr;
  165565. if (info_ptr_ptr != NULL)
  165566. info_ptr = *info_ptr_ptr;
  165567. if (end_info_ptr_ptr != NULL)
  165568. end_info_ptr = *end_info_ptr_ptr;
  165569. #ifdef PNG_USER_MEM_SUPPORTED
  165570. free_fn = png_ptr->free_fn;
  165571. mem_ptr = png_ptr->mem_ptr;
  165572. #endif
  165573. png_read_destroy(png_ptr, info_ptr, end_info_ptr);
  165574. if (info_ptr != NULL)
  165575. {
  165576. #if defined(PNG_TEXT_SUPPORTED)
  165577. png_free_data(png_ptr, info_ptr, PNG_FREE_TEXT, -1);
  165578. #endif
  165579. #ifdef PNG_USER_MEM_SUPPORTED
  165580. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  165581. (png_voidp)mem_ptr);
  165582. #else
  165583. png_destroy_struct((png_voidp)info_ptr);
  165584. #endif
  165585. *info_ptr_ptr = NULL;
  165586. }
  165587. if (end_info_ptr != NULL)
  165588. {
  165589. #if defined(PNG_READ_TEXT_SUPPORTED)
  165590. png_free_data(png_ptr, end_info_ptr, PNG_FREE_TEXT, -1);
  165591. #endif
  165592. #ifdef PNG_USER_MEM_SUPPORTED
  165593. png_destroy_struct_2((png_voidp)end_info_ptr, (png_free_ptr)free_fn,
  165594. (png_voidp)mem_ptr);
  165595. #else
  165596. png_destroy_struct((png_voidp)end_info_ptr);
  165597. #endif
  165598. *end_info_ptr_ptr = NULL;
  165599. }
  165600. if (png_ptr != NULL)
  165601. {
  165602. #ifdef PNG_USER_MEM_SUPPORTED
  165603. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  165604. (png_voidp)mem_ptr);
  165605. #else
  165606. png_destroy_struct((png_voidp)png_ptr);
  165607. #endif
  165608. *png_ptr_ptr = NULL;
  165609. }
  165610. }
  165611. void /* PRIVATE */
  165612. png_read_destroy(png_structp png_ptr, png_infop info_ptr, png_infop end_info_ptr)
  165613. {
  165614. #ifdef PNG_SETJMP_SUPPORTED
  165615. jmp_buf tmp_jmp;
  165616. #endif
  165617. png_error_ptr error_fn;
  165618. png_error_ptr warning_fn;
  165619. png_voidp error_ptr;
  165620. #ifdef PNG_USER_MEM_SUPPORTED
  165621. png_free_ptr free_fn;
  165622. #endif
  165623. png_debug(1, "in png_read_destroy\n");
  165624. if (info_ptr != NULL)
  165625. png_info_destroy(png_ptr, info_ptr);
  165626. if (end_info_ptr != NULL)
  165627. png_info_destroy(png_ptr, end_info_ptr);
  165628. png_free(png_ptr, png_ptr->zbuf);
  165629. png_free(png_ptr, png_ptr->big_row_buf);
  165630. png_free(png_ptr, png_ptr->prev_row);
  165631. #if defined(PNG_READ_DITHER_SUPPORTED)
  165632. png_free(png_ptr, png_ptr->palette_lookup);
  165633. png_free(png_ptr, png_ptr->dither_index);
  165634. #endif
  165635. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165636. png_free(png_ptr, png_ptr->gamma_table);
  165637. #endif
  165638. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165639. png_free(png_ptr, png_ptr->gamma_from_1);
  165640. png_free(png_ptr, png_ptr->gamma_to_1);
  165641. #endif
  165642. #ifdef PNG_FREE_ME_SUPPORTED
  165643. if (png_ptr->free_me & PNG_FREE_PLTE)
  165644. png_zfree(png_ptr, png_ptr->palette);
  165645. png_ptr->free_me &= ~PNG_FREE_PLTE;
  165646. #else
  165647. if (png_ptr->flags & PNG_FLAG_FREE_PLTE)
  165648. png_zfree(png_ptr, png_ptr->palette);
  165649. png_ptr->flags &= ~PNG_FLAG_FREE_PLTE;
  165650. #endif
  165651. #if defined(PNG_tRNS_SUPPORTED) || \
  165652. defined(PNG_READ_EXPAND_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  165653. #ifdef PNG_FREE_ME_SUPPORTED
  165654. if (png_ptr->free_me & PNG_FREE_TRNS)
  165655. png_free(png_ptr, png_ptr->trans);
  165656. png_ptr->free_me &= ~PNG_FREE_TRNS;
  165657. #else
  165658. if (png_ptr->flags & PNG_FLAG_FREE_TRNS)
  165659. png_free(png_ptr, png_ptr->trans);
  165660. png_ptr->flags &= ~PNG_FLAG_FREE_TRNS;
  165661. #endif
  165662. #endif
  165663. #if defined(PNG_READ_hIST_SUPPORTED)
  165664. #ifdef PNG_FREE_ME_SUPPORTED
  165665. if (png_ptr->free_me & PNG_FREE_HIST)
  165666. png_free(png_ptr, png_ptr->hist);
  165667. png_ptr->free_me &= ~PNG_FREE_HIST;
  165668. #else
  165669. if (png_ptr->flags & PNG_FLAG_FREE_HIST)
  165670. png_free(png_ptr, png_ptr->hist);
  165671. png_ptr->flags &= ~PNG_FLAG_FREE_HIST;
  165672. #endif
  165673. #endif
  165674. #if defined(PNG_READ_GAMMA_SUPPORTED)
  165675. if (png_ptr->gamma_16_table != NULL)
  165676. {
  165677. int i;
  165678. int istop = (1 << (8 - png_ptr->gamma_shift));
  165679. for (i = 0; i < istop; i++)
  165680. {
  165681. png_free(png_ptr, png_ptr->gamma_16_table[i]);
  165682. }
  165683. png_free(png_ptr, png_ptr->gamma_16_table);
  165684. }
  165685. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  165686. if (png_ptr->gamma_16_from_1 != NULL)
  165687. {
  165688. int i;
  165689. int istop = (1 << (8 - png_ptr->gamma_shift));
  165690. for (i = 0; i < istop; i++)
  165691. {
  165692. png_free(png_ptr, png_ptr->gamma_16_from_1[i]);
  165693. }
  165694. png_free(png_ptr, png_ptr->gamma_16_from_1);
  165695. }
  165696. if (png_ptr->gamma_16_to_1 != NULL)
  165697. {
  165698. int i;
  165699. int istop = (1 << (8 - png_ptr->gamma_shift));
  165700. for (i = 0; i < istop; i++)
  165701. {
  165702. png_free(png_ptr, png_ptr->gamma_16_to_1[i]);
  165703. }
  165704. png_free(png_ptr, png_ptr->gamma_16_to_1);
  165705. }
  165706. #endif
  165707. #endif
  165708. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  165709. png_free(png_ptr, png_ptr->time_buffer);
  165710. #endif
  165711. inflateEnd(&png_ptr->zstream);
  165712. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165713. png_free(png_ptr, png_ptr->save_buffer);
  165714. #endif
  165715. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165716. #ifdef PNG_TEXT_SUPPORTED
  165717. png_free(png_ptr, png_ptr->current_text);
  165718. #endif /* PNG_TEXT_SUPPORTED */
  165719. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  165720. #ifdef PNG_SETJMP_SUPPORTED
  165721. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  165722. #endif
  165723. error_fn = png_ptr->error_fn;
  165724. warning_fn = png_ptr->warning_fn;
  165725. error_ptr = png_ptr->error_ptr;
  165726. #ifdef PNG_USER_MEM_SUPPORTED
  165727. free_fn = png_ptr->free_fn;
  165728. #endif
  165729. png_memset(png_ptr, 0, png_sizeof (png_struct));
  165730. png_ptr->error_fn = error_fn;
  165731. png_ptr->warning_fn = warning_fn;
  165732. png_ptr->error_ptr = error_ptr;
  165733. #ifdef PNG_USER_MEM_SUPPORTED
  165734. png_ptr->free_fn = free_fn;
  165735. #endif
  165736. #ifdef PNG_SETJMP_SUPPORTED
  165737. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  165738. #endif
  165739. }
  165740. void PNGAPI
  165741. png_set_read_status_fn(png_structp png_ptr, png_read_status_ptr read_row_fn)
  165742. {
  165743. if(png_ptr == NULL) return;
  165744. png_ptr->read_row_fn = read_row_fn;
  165745. }
  165746. #ifndef PNG_NO_SEQUENTIAL_READ_SUPPORTED
  165747. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  165748. void PNGAPI
  165749. png_read_png(png_structp png_ptr, png_infop info_ptr,
  165750. int transforms,
  165751. voidp params)
  165752. {
  165753. int row;
  165754. if(png_ptr == NULL) return;
  165755. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  165756. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  165757. png_set_invert_alpha(png_ptr);
  165758. #endif
  165759. png_read_info(png_ptr, info_ptr);
  165760. if (info_ptr->height > PNG_UINT_32_MAX/png_sizeof(png_bytep))
  165761. png_error(png_ptr,"Image is too high to process with png_read_png()");
  165762. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  165763. if (transforms & PNG_TRANSFORM_STRIP_16)
  165764. png_set_strip_16(png_ptr);
  165765. #endif
  165766. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  165767. if (transforms & PNG_TRANSFORM_STRIP_ALPHA)
  165768. png_set_strip_alpha(png_ptr);
  165769. #endif
  165770. #if defined(PNG_READ_PACK_SUPPORTED) && !defined(PNG_READ_EXPAND_SUPPORTED)
  165771. if (transforms & PNG_TRANSFORM_PACKING)
  165772. png_set_packing(png_ptr);
  165773. #endif
  165774. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  165775. if (transforms & PNG_TRANSFORM_PACKSWAP)
  165776. png_set_packswap(png_ptr);
  165777. #endif
  165778. #if defined(PNG_READ_EXPAND_SUPPORTED)
  165779. if (transforms & PNG_TRANSFORM_EXPAND)
  165780. if ((png_ptr->bit_depth < 8) ||
  165781. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE) ||
  165782. (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)))
  165783. png_set_expand(png_ptr);
  165784. #endif
  165785. #if defined(PNG_READ_INVERT_SUPPORTED)
  165786. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  165787. png_set_invert_mono(png_ptr);
  165788. #endif
  165789. #if defined(PNG_READ_SHIFT_SUPPORTED)
  165790. if ((transforms & PNG_TRANSFORM_SHIFT)
  165791. && png_get_valid(png_ptr, info_ptr, PNG_INFO_sBIT))
  165792. {
  165793. png_color_8p sig_bit;
  165794. png_get_sBIT(png_ptr, info_ptr, &sig_bit);
  165795. png_set_shift(png_ptr, sig_bit);
  165796. }
  165797. #endif
  165798. #if defined(PNG_READ_BGR_SUPPORTED)
  165799. if (transforms & PNG_TRANSFORM_BGR)
  165800. png_set_bgr(png_ptr);
  165801. #endif
  165802. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  165803. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  165804. png_set_swap_alpha(png_ptr);
  165805. #endif
  165806. #if defined(PNG_READ_SWAP_SUPPORTED)
  165807. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  165808. png_set_swap(png_ptr);
  165809. #endif
  165810. png_read_update_info(png_ptr, info_ptr);
  165811. #ifdef PNG_FREE_ME_SUPPORTED
  165812. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  165813. #endif
  165814. if(info_ptr->row_pointers == NULL)
  165815. {
  165816. info_ptr->row_pointers = (png_bytepp)png_malloc(png_ptr,
  165817. info_ptr->height * png_sizeof(png_bytep));
  165818. #ifdef PNG_FREE_ME_SUPPORTED
  165819. info_ptr->free_me |= PNG_FREE_ROWS;
  165820. #endif
  165821. for (row = 0; row < (int)info_ptr->height; row++)
  165822. {
  165823. info_ptr->row_pointers[row] = (png_bytep)png_malloc(png_ptr,
  165824. png_get_rowbytes(png_ptr, info_ptr));
  165825. }
  165826. }
  165827. png_read_image(png_ptr, info_ptr->row_pointers);
  165828. info_ptr->valid |= PNG_INFO_IDAT;
  165829. png_read_end(png_ptr, info_ptr);
  165830. transforms = transforms; /* quiet compiler warnings */
  165831. params = params;
  165832. }
  165833. #endif /* PNG_INFO_IMAGE_SUPPORTED */
  165834. #endif /* PNG_NO_SEQUENTIAL_READ_SUPPORTED */
  165835. #endif /* PNG_READ_SUPPORTED */
  165836. /*** End of inlined file: pngread.c ***/
  165837. /*** Start of inlined file: pngpread.c ***/
  165838. #define PNG_INTERNAL
  165839. #ifdef PNG_PROGRESSIVE_READ_SUPPORTED
  165840. #define PNG_READ_SIG_MODE 0
  165841. #define PNG_READ_CHUNK_MODE 1
  165842. #define PNG_READ_IDAT_MODE 2
  165843. #define PNG_SKIP_MODE 3
  165844. #define PNG_READ_tEXt_MODE 4
  165845. #define PNG_READ_zTXt_MODE 5
  165846. #define PNG_READ_DONE_MODE 6
  165847. #define PNG_READ_iTXt_MODE 7
  165848. #define PNG_ERROR_MODE 8
  165849. void PNGAPI
  165850. png_process_data(png_structp png_ptr, png_infop info_ptr,
  165851. png_bytep buffer, png_size_t buffer_size)
  165852. {
  165853. if(png_ptr == NULL) return;
  165854. png_push_restore_buffer(png_ptr, buffer, buffer_size);
  165855. while (png_ptr->buffer_size)
  165856. {
  165857. png_process_some_data(png_ptr, info_ptr);
  165858. }
  165859. }
  165860. void /* PRIVATE */
  165861. png_process_some_data(png_structp png_ptr, png_infop info_ptr)
  165862. {
  165863. if(png_ptr == NULL) return;
  165864. switch (png_ptr->process_mode)
  165865. {
  165866. case PNG_READ_SIG_MODE:
  165867. {
  165868. png_push_read_sig(png_ptr, info_ptr);
  165869. break;
  165870. }
  165871. case PNG_READ_CHUNK_MODE:
  165872. {
  165873. png_push_read_chunk(png_ptr, info_ptr);
  165874. break;
  165875. }
  165876. case PNG_READ_IDAT_MODE:
  165877. {
  165878. png_push_read_IDAT(png_ptr);
  165879. break;
  165880. }
  165881. #if defined(PNG_READ_tEXt_SUPPORTED)
  165882. case PNG_READ_tEXt_MODE:
  165883. {
  165884. png_push_read_tEXt(png_ptr, info_ptr);
  165885. break;
  165886. }
  165887. #endif
  165888. #if defined(PNG_READ_zTXt_SUPPORTED)
  165889. case PNG_READ_zTXt_MODE:
  165890. {
  165891. png_push_read_zTXt(png_ptr, info_ptr);
  165892. break;
  165893. }
  165894. #endif
  165895. #if defined(PNG_READ_iTXt_SUPPORTED)
  165896. case PNG_READ_iTXt_MODE:
  165897. {
  165898. png_push_read_iTXt(png_ptr, info_ptr);
  165899. break;
  165900. }
  165901. #endif
  165902. case PNG_SKIP_MODE:
  165903. {
  165904. png_push_crc_finish(png_ptr);
  165905. break;
  165906. }
  165907. default:
  165908. {
  165909. png_ptr->buffer_size = 0;
  165910. break;
  165911. }
  165912. }
  165913. }
  165914. void /* PRIVATE */
  165915. png_push_read_sig(png_structp png_ptr, png_infop info_ptr)
  165916. {
  165917. png_size_t num_checked = png_ptr->sig_bytes,
  165918. num_to_check = 8 - num_checked;
  165919. if (png_ptr->buffer_size < num_to_check)
  165920. {
  165921. num_to_check = png_ptr->buffer_size;
  165922. }
  165923. png_push_fill_buffer(png_ptr, &(info_ptr->signature[num_checked]),
  165924. num_to_check);
  165925. png_ptr->sig_bytes = (png_byte)(png_ptr->sig_bytes+num_to_check);
  165926. if (png_sig_cmp(info_ptr->signature, num_checked, num_to_check))
  165927. {
  165928. if (num_checked < 4 &&
  165929. png_sig_cmp(info_ptr->signature, num_checked, num_to_check - 4))
  165930. png_error(png_ptr, "Not a PNG file");
  165931. else
  165932. png_error(png_ptr, "PNG file corrupted by ASCII conversion");
  165933. }
  165934. else
  165935. {
  165936. if (png_ptr->sig_bytes >= 8)
  165937. {
  165938. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  165939. }
  165940. }
  165941. }
  165942. void /* PRIVATE */
  165943. png_push_read_chunk(png_structp png_ptr, png_infop info_ptr)
  165944. {
  165945. #ifdef PNG_USE_LOCAL_ARRAYS
  165946. PNG_CONST PNG_IHDR;
  165947. PNG_CONST PNG_IDAT;
  165948. PNG_CONST PNG_IEND;
  165949. PNG_CONST PNG_PLTE;
  165950. #if defined(PNG_READ_bKGD_SUPPORTED)
  165951. PNG_CONST PNG_bKGD;
  165952. #endif
  165953. #if defined(PNG_READ_cHRM_SUPPORTED)
  165954. PNG_CONST PNG_cHRM;
  165955. #endif
  165956. #if defined(PNG_READ_gAMA_SUPPORTED)
  165957. PNG_CONST PNG_gAMA;
  165958. #endif
  165959. #if defined(PNG_READ_hIST_SUPPORTED)
  165960. PNG_CONST PNG_hIST;
  165961. #endif
  165962. #if defined(PNG_READ_iCCP_SUPPORTED)
  165963. PNG_CONST PNG_iCCP;
  165964. #endif
  165965. #if defined(PNG_READ_iTXt_SUPPORTED)
  165966. PNG_CONST PNG_iTXt;
  165967. #endif
  165968. #if defined(PNG_READ_oFFs_SUPPORTED)
  165969. PNG_CONST PNG_oFFs;
  165970. #endif
  165971. #if defined(PNG_READ_pCAL_SUPPORTED)
  165972. PNG_CONST PNG_pCAL;
  165973. #endif
  165974. #if defined(PNG_READ_pHYs_SUPPORTED)
  165975. PNG_CONST PNG_pHYs;
  165976. #endif
  165977. #if defined(PNG_READ_sBIT_SUPPORTED)
  165978. PNG_CONST PNG_sBIT;
  165979. #endif
  165980. #if defined(PNG_READ_sCAL_SUPPORTED)
  165981. PNG_CONST PNG_sCAL;
  165982. #endif
  165983. #if defined(PNG_READ_sRGB_SUPPORTED)
  165984. PNG_CONST PNG_sRGB;
  165985. #endif
  165986. #if defined(PNG_READ_sPLT_SUPPORTED)
  165987. PNG_CONST PNG_sPLT;
  165988. #endif
  165989. #if defined(PNG_READ_tEXt_SUPPORTED)
  165990. PNG_CONST PNG_tEXt;
  165991. #endif
  165992. #if defined(PNG_READ_tIME_SUPPORTED)
  165993. PNG_CONST PNG_tIME;
  165994. #endif
  165995. #if defined(PNG_READ_tRNS_SUPPORTED)
  165996. PNG_CONST PNG_tRNS;
  165997. #endif
  165998. #if defined(PNG_READ_zTXt_SUPPORTED)
  165999. PNG_CONST PNG_zTXt;
  166000. #endif
  166001. #endif /* PNG_USE_LOCAL_ARRAYS */
  166002. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166003. {
  166004. png_byte chunk_length[4];
  166005. if (png_ptr->buffer_size < 8)
  166006. {
  166007. png_push_save_buffer(png_ptr);
  166008. return;
  166009. }
  166010. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166011. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166012. png_reset_crc(png_ptr);
  166013. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166014. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166015. }
  166016. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166017. if(png_ptr->mode & PNG_AFTER_IDAT)
  166018. png_ptr->mode |= PNG_HAVE_CHUNK_AFTER_IDAT;
  166019. if (!png_memcmp(png_ptr->chunk_name, png_IHDR, 4))
  166020. {
  166021. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166022. {
  166023. png_push_save_buffer(png_ptr);
  166024. return;
  166025. }
  166026. png_handle_IHDR(png_ptr, info_ptr, png_ptr->push_length);
  166027. }
  166028. else if (!png_memcmp(png_ptr->chunk_name, png_IEND, 4))
  166029. {
  166030. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166031. {
  166032. png_push_save_buffer(png_ptr);
  166033. return;
  166034. }
  166035. png_handle_IEND(png_ptr, info_ptr, png_ptr->push_length);
  166036. png_ptr->process_mode = PNG_READ_DONE_MODE;
  166037. png_push_have_end(png_ptr, info_ptr);
  166038. }
  166039. #ifdef PNG_HANDLE_AS_UNKNOWN_SUPPORTED
  166040. else if (png_handle_as_unknown(png_ptr, png_ptr->chunk_name))
  166041. {
  166042. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166043. {
  166044. png_push_save_buffer(png_ptr);
  166045. return;
  166046. }
  166047. if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166048. png_ptr->mode |= PNG_HAVE_IDAT;
  166049. png_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  166050. if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  166051. png_ptr->mode |= PNG_HAVE_PLTE;
  166052. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166053. {
  166054. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  166055. png_error(png_ptr, "Missing IHDR before IDAT");
  166056. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  166057. !(png_ptr->mode & PNG_HAVE_PLTE))
  166058. png_error(png_ptr, "Missing PLTE before IDAT");
  166059. }
  166060. }
  166061. #endif
  166062. else if (!png_memcmp(png_ptr->chunk_name, png_PLTE, 4))
  166063. {
  166064. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166065. {
  166066. png_push_save_buffer(png_ptr);
  166067. return;
  166068. }
  166069. png_handle_PLTE(png_ptr, info_ptr, png_ptr->push_length);
  166070. }
  166071. else if (!png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166072. {
  166073. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  166074. png_error(png_ptr, "Missing IHDR before IDAT");
  166075. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  166076. !(png_ptr->mode & PNG_HAVE_PLTE))
  166077. png_error(png_ptr, "Missing PLTE before IDAT");
  166078. if (png_ptr->mode & PNG_HAVE_IDAT)
  166079. {
  166080. if (!(png_ptr->mode & PNG_HAVE_CHUNK_AFTER_IDAT))
  166081. if (png_ptr->push_length == 0)
  166082. return;
  166083. if (png_ptr->mode & PNG_AFTER_IDAT)
  166084. png_error(png_ptr, "Too many IDAT's found");
  166085. }
  166086. png_ptr->idat_size = png_ptr->push_length;
  166087. png_ptr->mode |= PNG_HAVE_IDAT;
  166088. png_ptr->process_mode = PNG_READ_IDAT_MODE;
  166089. png_push_have_info(png_ptr, info_ptr);
  166090. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166091. png_ptr->zstream.next_out = png_ptr->row_buf;
  166092. return;
  166093. }
  166094. #if defined(PNG_READ_gAMA_SUPPORTED)
  166095. else if (!png_memcmp(png_ptr->chunk_name, png_gAMA, 4))
  166096. {
  166097. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166098. {
  166099. png_push_save_buffer(png_ptr);
  166100. return;
  166101. }
  166102. png_handle_gAMA(png_ptr, info_ptr, png_ptr->push_length);
  166103. }
  166104. #endif
  166105. #if defined(PNG_READ_sBIT_SUPPORTED)
  166106. else if (!png_memcmp(png_ptr->chunk_name, png_sBIT, 4))
  166107. {
  166108. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166109. {
  166110. png_push_save_buffer(png_ptr);
  166111. return;
  166112. }
  166113. png_handle_sBIT(png_ptr, info_ptr, png_ptr->push_length);
  166114. }
  166115. #endif
  166116. #if defined(PNG_READ_cHRM_SUPPORTED)
  166117. else if (!png_memcmp(png_ptr->chunk_name, png_cHRM, 4))
  166118. {
  166119. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166120. {
  166121. png_push_save_buffer(png_ptr);
  166122. return;
  166123. }
  166124. png_handle_cHRM(png_ptr, info_ptr, png_ptr->push_length);
  166125. }
  166126. #endif
  166127. #if defined(PNG_READ_sRGB_SUPPORTED)
  166128. else if (!png_memcmp(png_ptr->chunk_name, png_sRGB, 4))
  166129. {
  166130. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166131. {
  166132. png_push_save_buffer(png_ptr);
  166133. return;
  166134. }
  166135. png_handle_sRGB(png_ptr, info_ptr, png_ptr->push_length);
  166136. }
  166137. #endif
  166138. #if defined(PNG_READ_iCCP_SUPPORTED)
  166139. else if (!png_memcmp(png_ptr->chunk_name, png_iCCP, 4))
  166140. {
  166141. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166142. {
  166143. png_push_save_buffer(png_ptr);
  166144. return;
  166145. }
  166146. png_handle_iCCP(png_ptr, info_ptr, png_ptr->push_length);
  166147. }
  166148. #endif
  166149. #if defined(PNG_READ_sPLT_SUPPORTED)
  166150. else if (!png_memcmp(png_ptr->chunk_name, png_sPLT, 4))
  166151. {
  166152. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166153. {
  166154. png_push_save_buffer(png_ptr);
  166155. return;
  166156. }
  166157. png_handle_sPLT(png_ptr, info_ptr, png_ptr->push_length);
  166158. }
  166159. #endif
  166160. #if defined(PNG_READ_tRNS_SUPPORTED)
  166161. else if (!png_memcmp(png_ptr->chunk_name, png_tRNS, 4))
  166162. {
  166163. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166164. {
  166165. png_push_save_buffer(png_ptr);
  166166. return;
  166167. }
  166168. png_handle_tRNS(png_ptr, info_ptr, png_ptr->push_length);
  166169. }
  166170. #endif
  166171. #if defined(PNG_READ_bKGD_SUPPORTED)
  166172. else if (!png_memcmp(png_ptr->chunk_name, png_bKGD, 4))
  166173. {
  166174. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166175. {
  166176. png_push_save_buffer(png_ptr);
  166177. return;
  166178. }
  166179. png_handle_bKGD(png_ptr, info_ptr, png_ptr->push_length);
  166180. }
  166181. #endif
  166182. #if defined(PNG_READ_hIST_SUPPORTED)
  166183. else if (!png_memcmp(png_ptr->chunk_name, png_hIST, 4))
  166184. {
  166185. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166186. {
  166187. png_push_save_buffer(png_ptr);
  166188. return;
  166189. }
  166190. png_handle_hIST(png_ptr, info_ptr, png_ptr->push_length);
  166191. }
  166192. #endif
  166193. #if defined(PNG_READ_pHYs_SUPPORTED)
  166194. else if (!png_memcmp(png_ptr->chunk_name, png_pHYs, 4))
  166195. {
  166196. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166197. {
  166198. png_push_save_buffer(png_ptr);
  166199. return;
  166200. }
  166201. png_handle_pHYs(png_ptr, info_ptr, png_ptr->push_length);
  166202. }
  166203. #endif
  166204. #if defined(PNG_READ_oFFs_SUPPORTED)
  166205. else if (!png_memcmp(png_ptr->chunk_name, png_oFFs, 4))
  166206. {
  166207. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166208. {
  166209. png_push_save_buffer(png_ptr);
  166210. return;
  166211. }
  166212. png_handle_oFFs(png_ptr, info_ptr, png_ptr->push_length);
  166213. }
  166214. #endif
  166215. #if defined(PNG_READ_pCAL_SUPPORTED)
  166216. else if (!png_memcmp(png_ptr->chunk_name, png_pCAL, 4))
  166217. {
  166218. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166219. {
  166220. png_push_save_buffer(png_ptr);
  166221. return;
  166222. }
  166223. png_handle_pCAL(png_ptr, info_ptr, png_ptr->push_length);
  166224. }
  166225. #endif
  166226. #if defined(PNG_READ_sCAL_SUPPORTED)
  166227. else if (!png_memcmp(png_ptr->chunk_name, png_sCAL, 4))
  166228. {
  166229. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166230. {
  166231. png_push_save_buffer(png_ptr);
  166232. return;
  166233. }
  166234. png_handle_sCAL(png_ptr, info_ptr, png_ptr->push_length);
  166235. }
  166236. #endif
  166237. #if defined(PNG_READ_tIME_SUPPORTED)
  166238. else if (!png_memcmp(png_ptr->chunk_name, png_tIME, 4))
  166239. {
  166240. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166241. {
  166242. png_push_save_buffer(png_ptr);
  166243. return;
  166244. }
  166245. png_handle_tIME(png_ptr, info_ptr, png_ptr->push_length);
  166246. }
  166247. #endif
  166248. #if defined(PNG_READ_tEXt_SUPPORTED)
  166249. else if (!png_memcmp(png_ptr->chunk_name, png_tEXt, 4))
  166250. {
  166251. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166252. {
  166253. png_push_save_buffer(png_ptr);
  166254. return;
  166255. }
  166256. png_push_handle_tEXt(png_ptr, info_ptr, png_ptr->push_length);
  166257. }
  166258. #endif
  166259. #if defined(PNG_READ_zTXt_SUPPORTED)
  166260. else if (!png_memcmp(png_ptr->chunk_name, png_zTXt, 4))
  166261. {
  166262. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166263. {
  166264. png_push_save_buffer(png_ptr);
  166265. return;
  166266. }
  166267. png_push_handle_zTXt(png_ptr, info_ptr, png_ptr->push_length);
  166268. }
  166269. #endif
  166270. #if defined(PNG_READ_iTXt_SUPPORTED)
  166271. else if (!png_memcmp(png_ptr->chunk_name, png_iTXt, 4))
  166272. {
  166273. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166274. {
  166275. png_push_save_buffer(png_ptr);
  166276. return;
  166277. }
  166278. png_push_handle_iTXt(png_ptr, info_ptr, png_ptr->push_length);
  166279. }
  166280. #endif
  166281. else
  166282. {
  166283. if (png_ptr->push_length + 4 > png_ptr->buffer_size)
  166284. {
  166285. png_push_save_buffer(png_ptr);
  166286. return;
  166287. }
  166288. png_push_handle_unknown(png_ptr, info_ptr, png_ptr->push_length);
  166289. }
  166290. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166291. }
  166292. void /* PRIVATE */
  166293. png_push_crc_skip(png_structp png_ptr, png_uint_32 skip)
  166294. {
  166295. png_ptr->process_mode = PNG_SKIP_MODE;
  166296. png_ptr->skip_length = skip;
  166297. }
  166298. void /* PRIVATE */
  166299. png_push_crc_finish(png_structp png_ptr)
  166300. {
  166301. if (png_ptr->skip_length && png_ptr->save_buffer_size)
  166302. {
  166303. png_size_t save_size;
  166304. if (png_ptr->skip_length < (png_uint_32)png_ptr->save_buffer_size)
  166305. save_size = (png_size_t)png_ptr->skip_length;
  166306. else
  166307. save_size = png_ptr->save_buffer_size;
  166308. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166309. png_ptr->skip_length -= save_size;
  166310. png_ptr->buffer_size -= save_size;
  166311. png_ptr->save_buffer_size -= save_size;
  166312. png_ptr->save_buffer_ptr += save_size;
  166313. }
  166314. if (png_ptr->skip_length && png_ptr->current_buffer_size)
  166315. {
  166316. png_size_t save_size;
  166317. if (png_ptr->skip_length < (png_uint_32)png_ptr->current_buffer_size)
  166318. save_size = (png_size_t)png_ptr->skip_length;
  166319. else
  166320. save_size = png_ptr->current_buffer_size;
  166321. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166322. png_ptr->skip_length -= save_size;
  166323. png_ptr->buffer_size -= save_size;
  166324. png_ptr->current_buffer_size -= save_size;
  166325. png_ptr->current_buffer_ptr += save_size;
  166326. }
  166327. if (!png_ptr->skip_length)
  166328. {
  166329. if (png_ptr->buffer_size < 4)
  166330. {
  166331. png_push_save_buffer(png_ptr);
  166332. return;
  166333. }
  166334. png_crc_finish(png_ptr, 0);
  166335. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166336. }
  166337. }
  166338. void PNGAPI
  166339. png_push_fill_buffer(png_structp png_ptr, png_bytep buffer, png_size_t length)
  166340. {
  166341. png_bytep ptr;
  166342. if(png_ptr == NULL) return;
  166343. ptr = buffer;
  166344. if (png_ptr->save_buffer_size)
  166345. {
  166346. png_size_t save_size;
  166347. if (length < png_ptr->save_buffer_size)
  166348. save_size = length;
  166349. else
  166350. save_size = png_ptr->save_buffer_size;
  166351. png_memcpy(ptr, png_ptr->save_buffer_ptr, save_size);
  166352. length -= save_size;
  166353. ptr += save_size;
  166354. png_ptr->buffer_size -= save_size;
  166355. png_ptr->save_buffer_size -= save_size;
  166356. png_ptr->save_buffer_ptr += save_size;
  166357. }
  166358. if (length && png_ptr->current_buffer_size)
  166359. {
  166360. png_size_t save_size;
  166361. if (length < png_ptr->current_buffer_size)
  166362. save_size = length;
  166363. else
  166364. save_size = png_ptr->current_buffer_size;
  166365. png_memcpy(ptr, png_ptr->current_buffer_ptr, save_size);
  166366. png_ptr->buffer_size -= save_size;
  166367. png_ptr->current_buffer_size -= save_size;
  166368. png_ptr->current_buffer_ptr += save_size;
  166369. }
  166370. }
  166371. void /* PRIVATE */
  166372. png_push_save_buffer(png_structp png_ptr)
  166373. {
  166374. if (png_ptr->save_buffer_size)
  166375. {
  166376. if (png_ptr->save_buffer_ptr != png_ptr->save_buffer)
  166377. {
  166378. png_size_t i,istop;
  166379. png_bytep sp;
  166380. png_bytep dp;
  166381. istop = png_ptr->save_buffer_size;
  166382. for (i = 0, sp = png_ptr->save_buffer_ptr, dp = png_ptr->save_buffer;
  166383. i < istop; i++, sp++, dp++)
  166384. {
  166385. *dp = *sp;
  166386. }
  166387. }
  166388. }
  166389. if (png_ptr->save_buffer_size + png_ptr->current_buffer_size >
  166390. png_ptr->save_buffer_max)
  166391. {
  166392. png_size_t new_max;
  166393. png_bytep old_buffer;
  166394. if (png_ptr->save_buffer_size > PNG_SIZE_MAX -
  166395. (png_ptr->current_buffer_size + 256))
  166396. {
  166397. png_error(png_ptr, "Potential overflow of save_buffer");
  166398. }
  166399. new_max = png_ptr->save_buffer_size + png_ptr->current_buffer_size + 256;
  166400. old_buffer = png_ptr->save_buffer;
  166401. png_ptr->save_buffer = (png_bytep)png_malloc(png_ptr,
  166402. (png_uint_32)new_max);
  166403. png_memcpy(png_ptr->save_buffer, old_buffer, png_ptr->save_buffer_size);
  166404. png_free(png_ptr, old_buffer);
  166405. png_ptr->save_buffer_max = new_max;
  166406. }
  166407. if (png_ptr->current_buffer_size)
  166408. {
  166409. png_memcpy(png_ptr->save_buffer + png_ptr->save_buffer_size,
  166410. png_ptr->current_buffer_ptr, png_ptr->current_buffer_size);
  166411. png_ptr->save_buffer_size += png_ptr->current_buffer_size;
  166412. png_ptr->current_buffer_size = 0;
  166413. }
  166414. png_ptr->save_buffer_ptr = png_ptr->save_buffer;
  166415. png_ptr->buffer_size = 0;
  166416. }
  166417. void /* PRIVATE */
  166418. png_push_restore_buffer(png_structp png_ptr, png_bytep buffer,
  166419. png_size_t buffer_length)
  166420. {
  166421. png_ptr->current_buffer = buffer;
  166422. png_ptr->current_buffer_size = buffer_length;
  166423. png_ptr->buffer_size = buffer_length + png_ptr->save_buffer_size;
  166424. png_ptr->current_buffer_ptr = png_ptr->current_buffer;
  166425. }
  166426. void /* PRIVATE */
  166427. png_push_read_IDAT(png_structp png_ptr)
  166428. {
  166429. #ifdef PNG_USE_LOCAL_ARRAYS
  166430. PNG_CONST PNG_IDAT;
  166431. #endif
  166432. if (!(png_ptr->mode & PNG_HAVE_CHUNK_HEADER))
  166433. {
  166434. png_byte chunk_length[4];
  166435. if (png_ptr->buffer_size < 8)
  166436. {
  166437. png_push_save_buffer(png_ptr);
  166438. return;
  166439. }
  166440. png_push_fill_buffer(png_ptr, chunk_length, 4);
  166441. png_ptr->push_length = png_get_uint_31(png_ptr,chunk_length);
  166442. png_reset_crc(png_ptr);
  166443. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  166444. png_ptr->mode |= PNG_HAVE_CHUNK_HEADER;
  166445. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  166446. {
  166447. png_ptr->process_mode = PNG_READ_CHUNK_MODE;
  166448. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166449. png_error(png_ptr, "Not enough compressed data");
  166450. return;
  166451. }
  166452. png_ptr->idat_size = png_ptr->push_length;
  166453. }
  166454. if (png_ptr->idat_size && png_ptr->save_buffer_size)
  166455. {
  166456. png_size_t save_size;
  166457. if (png_ptr->idat_size < (png_uint_32)png_ptr->save_buffer_size)
  166458. {
  166459. save_size = (png_size_t)png_ptr->idat_size;
  166460. if((png_uint_32)save_size != png_ptr->idat_size)
  166461. png_error(png_ptr, "save_size overflowed in pngpread");
  166462. }
  166463. else
  166464. save_size = png_ptr->save_buffer_size;
  166465. png_calculate_crc(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166466. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166467. png_process_IDAT_data(png_ptr, png_ptr->save_buffer_ptr, save_size);
  166468. png_ptr->idat_size -= save_size;
  166469. png_ptr->buffer_size -= save_size;
  166470. png_ptr->save_buffer_size -= save_size;
  166471. png_ptr->save_buffer_ptr += save_size;
  166472. }
  166473. if (png_ptr->idat_size && png_ptr->current_buffer_size)
  166474. {
  166475. png_size_t save_size;
  166476. if (png_ptr->idat_size < (png_uint_32)png_ptr->current_buffer_size)
  166477. {
  166478. save_size = (png_size_t)png_ptr->idat_size;
  166479. if((png_uint_32)save_size != png_ptr->idat_size)
  166480. png_error(png_ptr, "save_size overflowed in pngpread");
  166481. }
  166482. else
  166483. save_size = png_ptr->current_buffer_size;
  166484. png_calculate_crc(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166485. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  166486. png_process_IDAT_data(png_ptr, png_ptr->current_buffer_ptr, save_size);
  166487. png_ptr->idat_size -= save_size;
  166488. png_ptr->buffer_size -= save_size;
  166489. png_ptr->current_buffer_size -= save_size;
  166490. png_ptr->current_buffer_ptr += save_size;
  166491. }
  166492. if (!png_ptr->idat_size)
  166493. {
  166494. if (png_ptr->buffer_size < 4)
  166495. {
  166496. png_push_save_buffer(png_ptr);
  166497. return;
  166498. }
  166499. png_crc_finish(png_ptr, 0);
  166500. png_ptr->mode &= ~PNG_HAVE_CHUNK_HEADER;
  166501. png_ptr->mode |= PNG_AFTER_IDAT;
  166502. }
  166503. }
  166504. void /* PRIVATE */
  166505. png_process_IDAT_data(png_structp png_ptr, png_bytep buffer,
  166506. png_size_t buffer_length)
  166507. {
  166508. int ret;
  166509. if ((png_ptr->flags & PNG_FLAG_ZLIB_FINISHED) && buffer_length)
  166510. png_error(png_ptr, "Extra compression data");
  166511. png_ptr->zstream.next_in = buffer;
  166512. png_ptr->zstream.avail_in = (uInt)buffer_length;
  166513. for(;;)
  166514. {
  166515. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166516. if (ret != Z_OK)
  166517. {
  166518. if (ret == Z_STREAM_END)
  166519. {
  166520. if (png_ptr->zstream.avail_in)
  166521. png_error(png_ptr, "Extra compressed data");
  166522. if (!(png_ptr->zstream.avail_out))
  166523. {
  166524. png_push_process_row(png_ptr);
  166525. }
  166526. png_ptr->mode |= PNG_AFTER_IDAT;
  166527. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166528. break;
  166529. }
  166530. else if (ret == Z_BUF_ERROR)
  166531. break;
  166532. else
  166533. png_error(png_ptr, "Decompression Error");
  166534. }
  166535. if (!(png_ptr->zstream.avail_out))
  166536. {
  166537. if ((
  166538. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166539. png_ptr->interlaced && png_ptr->pass > 6) ||
  166540. (!png_ptr->interlaced &&
  166541. #endif
  166542. png_ptr->row_number == png_ptr->num_rows))
  166543. {
  166544. if (png_ptr->zstream.avail_in)
  166545. {
  166546. png_warning(png_ptr, "Too much data in IDAT chunks");
  166547. }
  166548. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  166549. break;
  166550. }
  166551. png_push_process_row(png_ptr);
  166552. png_ptr->zstream.avail_out = (uInt)png_ptr->irowbytes;
  166553. png_ptr->zstream.next_out = png_ptr->row_buf;
  166554. }
  166555. else
  166556. break;
  166557. }
  166558. }
  166559. void /* PRIVATE */
  166560. png_push_process_row(png_structp png_ptr)
  166561. {
  166562. png_ptr->row_info.color_type = png_ptr->color_type;
  166563. png_ptr->row_info.width = png_ptr->iwidth;
  166564. png_ptr->row_info.channels = png_ptr->channels;
  166565. png_ptr->row_info.bit_depth = png_ptr->bit_depth;
  166566. png_ptr->row_info.pixel_depth = png_ptr->pixel_depth;
  166567. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  166568. png_ptr->row_info.width);
  166569. png_read_filter_row(png_ptr, &(png_ptr->row_info),
  166570. png_ptr->row_buf + 1, png_ptr->prev_row + 1,
  166571. (int)(png_ptr->row_buf[0]));
  166572. png_memcpy_check(png_ptr, png_ptr->prev_row, png_ptr->row_buf,
  166573. png_ptr->rowbytes + 1);
  166574. if (png_ptr->transformations || (png_ptr->flags&PNG_FLAG_STRIP_ALPHA))
  166575. png_do_read_transformations(png_ptr);
  166576. #if defined(PNG_READ_INTERLACING_SUPPORTED)
  166577. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  166578. {
  166579. if (png_ptr->pass < 6)
  166580. png_do_read_interlace(png_ptr);
  166581. switch (png_ptr->pass)
  166582. {
  166583. case 0:
  166584. {
  166585. int i;
  166586. for (i = 0; i < 8 && png_ptr->pass == 0; i++)
  166587. {
  166588. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166589. png_read_push_finish_row(png_ptr); /* updates png_ptr->pass */
  166590. }
  166591. if (png_ptr->pass == 2) /* pass 1 might be empty */
  166592. {
  166593. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166594. {
  166595. png_push_have_row(png_ptr, png_bytep_NULL);
  166596. png_read_push_finish_row(png_ptr);
  166597. }
  166598. }
  166599. if (png_ptr->pass == 4 && png_ptr->height <= 4)
  166600. {
  166601. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166602. {
  166603. png_push_have_row(png_ptr, png_bytep_NULL);
  166604. png_read_push_finish_row(png_ptr);
  166605. }
  166606. }
  166607. if (png_ptr->pass == 6 && png_ptr->height <= 4)
  166608. {
  166609. png_push_have_row(png_ptr, png_bytep_NULL);
  166610. png_read_push_finish_row(png_ptr);
  166611. }
  166612. break;
  166613. }
  166614. case 1:
  166615. {
  166616. int i;
  166617. for (i = 0; i < 8 && png_ptr->pass == 1; i++)
  166618. {
  166619. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166620. png_read_push_finish_row(png_ptr);
  166621. }
  166622. if (png_ptr->pass == 2) /* skip top 4 generated rows */
  166623. {
  166624. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166625. {
  166626. png_push_have_row(png_ptr, png_bytep_NULL);
  166627. png_read_push_finish_row(png_ptr);
  166628. }
  166629. }
  166630. break;
  166631. }
  166632. case 2:
  166633. {
  166634. int i;
  166635. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166636. {
  166637. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166638. png_read_push_finish_row(png_ptr);
  166639. }
  166640. for (i = 0; i < 4 && png_ptr->pass == 2; i++)
  166641. {
  166642. png_push_have_row(png_ptr, png_bytep_NULL);
  166643. png_read_push_finish_row(png_ptr);
  166644. }
  166645. if (png_ptr->pass == 4) /* pass 3 might be empty */
  166646. {
  166647. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166648. {
  166649. png_push_have_row(png_ptr, png_bytep_NULL);
  166650. png_read_push_finish_row(png_ptr);
  166651. }
  166652. }
  166653. break;
  166654. }
  166655. case 3:
  166656. {
  166657. int i;
  166658. for (i = 0; i < 4 && png_ptr->pass == 3; i++)
  166659. {
  166660. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166661. png_read_push_finish_row(png_ptr);
  166662. }
  166663. if (png_ptr->pass == 4) /* skip top two generated rows */
  166664. {
  166665. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166666. {
  166667. png_push_have_row(png_ptr, png_bytep_NULL);
  166668. png_read_push_finish_row(png_ptr);
  166669. }
  166670. }
  166671. break;
  166672. }
  166673. case 4:
  166674. {
  166675. int i;
  166676. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166677. {
  166678. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166679. png_read_push_finish_row(png_ptr);
  166680. }
  166681. for (i = 0; i < 2 && png_ptr->pass == 4; i++)
  166682. {
  166683. png_push_have_row(png_ptr, png_bytep_NULL);
  166684. png_read_push_finish_row(png_ptr);
  166685. }
  166686. if (png_ptr->pass == 6) /* pass 5 might be empty */
  166687. {
  166688. png_push_have_row(png_ptr, png_bytep_NULL);
  166689. png_read_push_finish_row(png_ptr);
  166690. }
  166691. break;
  166692. }
  166693. case 5:
  166694. {
  166695. int i;
  166696. for (i = 0; i < 2 && png_ptr->pass == 5; i++)
  166697. {
  166698. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166699. png_read_push_finish_row(png_ptr);
  166700. }
  166701. if (png_ptr->pass == 6) /* skip top generated row */
  166702. {
  166703. png_push_have_row(png_ptr, png_bytep_NULL);
  166704. png_read_push_finish_row(png_ptr);
  166705. }
  166706. break;
  166707. }
  166708. case 6:
  166709. {
  166710. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166711. png_read_push_finish_row(png_ptr);
  166712. if (png_ptr->pass != 6)
  166713. break;
  166714. png_push_have_row(png_ptr, png_bytep_NULL);
  166715. png_read_push_finish_row(png_ptr);
  166716. }
  166717. }
  166718. }
  166719. else
  166720. #endif
  166721. {
  166722. png_push_have_row(png_ptr, png_ptr->row_buf + 1);
  166723. png_read_push_finish_row(png_ptr);
  166724. }
  166725. }
  166726. void /* PRIVATE */
  166727. png_read_push_finish_row(png_structp png_ptr)
  166728. {
  166729. #ifdef PNG_USE_LOCAL_ARRAYS
  166730. PNG_CONST int FARDATA png_pass_start[] = {0, 4, 0, 2, 0, 1, 0};
  166731. PNG_CONST int FARDATA png_pass_inc[] = {8, 8, 4, 4, 2, 2, 1};
  166732. PNG_CONST int FARDATA png_pass_ystart[] = {0, 0, 4, 0, 2, 0, 1};
  166733. PNG_CONST int FARDATA png_pass_yinc[] = {8, 8, 8, 4, 4, 2, 2};
  166734. #endif
  166735. png_ptr->row_number++;
  166736. if (png_ptr->row_number < png_ptr->num_rows)
  166737. return;
  166738. if (png_ptr->interlaced)
  166739. {
  166740. png_ptr->row_number = 0;
  166741. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  166742. png_ptr->rowbytes + 1);
  166743. do
  166744. {
  166745. png_ptr->pass++;
  166746. if ((png_ptr->pass == 1 && png_ptr->width < 5) ||
  166747. (png_ptr->pass == 3 && png_ptr->width < 3) ||
  166748. (png_ptr->pass == 5 && png_ptr->width < 2))
  166749. png_ptr->pass++;
  166750. if (png_ptr->pass > 7)
  166751. png_ptr->pass--;
  166752. if (png_ptr->pass >= 7)
  166753. break;
  166754. png_ptr->iwidth = (png_ptr->width +
  166755. png_pass_inc[png_ptr->pass] - 1 -
  166756. png_pass_start[png_ptr->pass]) /
  166757. png_pass_inc[png_ptr->pass];
  166758. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  166759. png_ptr->iwidth) + 1;
  166760. if (png_ptr->transformations & PNG_INTERLACE)
  166761. break;
  166762. png_ptr->num_rows = (png_ptr->height +
  166763. png_pass_yinc[png_ptr->pass] - 1 -
  166764. png_pass_ystart[png_ptr->pass]) /
  166765. png_pass_yinc[png_ptr->pass];
  166766. } while (png_ptr->iwidth == 0 || png_ptr->num_rows == 0);
  166767. }
  166768. }
  166769. #if defined(PNG_READ_tEXt_SUPPORTED)
  166770. void /* PRIVATE */
  166771. png_push_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166772. length)
  166773. {
  166774. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166775. {
  166776. png_error(png_ptr, "Out of place tEXt");
  166777. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166778. }
  166779. #ifdef PNG_MAX_MALLOC_64K
  166780. png_ptr->skip_length = 0; /* This may not be necessary */
  166781. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  166782. {
  166783. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  166784. png_ptr->skip_length = length - (png_uint_32)65535L;
  166785. length = (png_uint_32)65535L;
  166786. }
  166787. #endif
  166788. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166789. (png_uint_32)(length+1));
  166790. png_ptr->current_text[length] = '\0';
  166791. png_ptr->current_text_ptr = png_ptr->current_text;
  166792. png_ptr->current_text_size = (png_size_t)length;
  166793. png_ptr->current_text_left = (png_size_t)length;
  166794. png_ptr->process_mode = PNG_READ_tEXt_MODE;
  166795. }
  166796. void /* PRIVATE */
  166797. png_push_read_tEXt(png_structp png_ptr, png_infop info_ptr)
  166798. {
  166799. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166800. {
  166801. png_size_t text_size;
  166802. if (png_ptr->buffer_size < png_ptr->current_text_left)
  166803. text_size = png_ptr->buffer_size;
  166804. else
  166805. text_size = png_ptr->current_text_left;
  166806. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166807. png_ptr->current_text_left -= text_size;
  166808. png_ptr->current_text_ptr += text_size;
  166809. }
  166810. if (!(png_ptr->current_text_left))
  166811. {
  166812. png_textp text_ptr;
  166813. png_charp text;
  166814. png_charp key;
  166815. int ret;
  166816. if (png_ptr->buffer_size < 4)
  166817. {
  166818. png_push_save_buffer(png_ptr);
  166819. return;
  166820. }
  166821. png_push_crc_finish(png_ptr);
  166822. #if defined(PNG_MAX_MALLOC_64K)
  166823. if (png_ptr->skip_length)
  166824. return;
  166825. #endif
  166826. key = png_ptr->current_text;
  166827. for (text = key; *text; text++)
  166828. ;
  166829. if (text < key + png_ptr->current_text_size)
  166830. text++;
  166831. text_ptr = (png_textp)png_malloc(png_ptr,
  166832. (png_uint_32)png_sizeof(png_text));
  166833. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  166834. text_ptr->key = key;
  166835. #ifdef PNG_iTXt_SUPPORTED
  166836. text_ptr->lang = NULL;
  166837. text_ptr->lang_key = NULL;
  166838. #endif
  166839. text_ptr->text = text;
  166840. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  166841. png_free(png_ptr, key);
  166842. png_free(png_ptr, text_ptr);
  166843. png_ptr->current_text = NULL;
  166844. if (ret)
  166845. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  166846. }
  166847. }
  166848. #endif
  166849. #if defined(PNG_READ_zTXt_SUPPORTED)
  166850. void /* PRIVATE */
  166851. png_push_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  166852. length)
  166853. {
  166854. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  166855. {
  166856. png_error(png_ptr, "Out of place zTXt");
  166857. info_ptr = info_ptr; /* to quiet some compiler warnings */
  166858. }
  166859. #ifdef PNG_MAX_MALLOC_64K
  166860. if (length > (png_uint_32)65535L)
  166861. {
  166862. png_warning(png_ptr, "zTXt chunk too large to fit in memory");
  166863. png_push_crc_skip(png_ptr, length);
  166864. return;
  166865. }
  166866. #endif
  166867. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  166868. (png_uint_32)(length+1));
  166869. png_ptr->current_text[length] = '\0';
  166870. png_ptr->current_text_ptr = png_ptr->current_text;
  166871. png_ptr->current_text_size = (png_size_t)length;
  166872. png_ptr->current_text_left = (png_size_t)length;
  166873. png_ptr->process_mode = PNG_READ_zTXt_MODE;
  166874. }
  166875. void /* PRIVATE */
  166876. png_push_read_zTXt(png_structp png_ptr, png_infop info_ptr)
  166877. {
  166878. if (png_ptr->buffer_size && png_ptr->current_text_left)
  166879. {
  166880. png_size_t text_size;
  166881. if (png_ptr->buffer_size < (png_uint_32)png_ptr->current_text_left)
  166882. text_size = png_ptr->buffer_size;
  166883. else
  166884. text_size = png_ptr->current_text_left;
  166885. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  166886. png_ptr->current_text_left -= text_size;
  166887. png_ptr->current_text_ptr += text_size;
  166888. }
  166889. if (!(png_ptr->current_text_left))
  166890. {
  166891. png_textp text_ptr;
  166892. png_charp text;
  166893. png_charp key;
  166894. int ret;
  166895. png_size_t text_size, key_size;
  166896. if (png_ptr->buffer_size < 4)
  166897. {
  166898. png_push_save_buffer(png_ptr);
  166899. return;
  166900. }
  166901. png_push_crc_finish(png_ptr);
  166902. key = png_ptr->current_text;
  166903. for (text = key; *text; text++)
  166904. ;
  166905. if (text >= key + png_ptr->current_text_size)
  166906. {
  166907. png_ptr->current_text = NULL;
  166908. png_free(png_ptr, key);
  166909. return;
  166910. }
  166911. text++;
  166912. if (*text != PNG_TEXT_COMPRESSION_zTXt) /* check compression byte */
  166913. {
  166914. png_ptr->current_text = NULL;
  166915. png_free(png_ptr, key);
  166916. return;
  166917. }
  166918. text++;
  166919. png_ptr->zstream.next_in = (png_bytep )text;
  166920. png_ptr->zstream.avail_in = (uInt)(png_ptr->current_text_size -
  166921. (text - key));
  166922. png_ptr->zstream.next_out = png_ptr->zbuf;
  166923. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166924. key_size = text - key;
  166925. text_size = 0;
  166926. text = NULL;
  166927. ret = Z_STREAM_END;
  166928. while (png_ptr->zstream.avail_in)
  166929. {
  166930. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  166931. if (ret != Z_OK && ret != Z_STREAM_END)
  166932. {
  166933. inflateReset(&png_ptr->zstream);
  166934. png_ptr->zstream.avail_in = 0;
  166935. png_ptr->current_text = NULL;
  166936. png_free(png_ptr, key);
  166937. png_free(png_ptr, text);
  166938. return;
  166939. }
  166940. if (!(png_ptr->zstream.avail_out) || ret == Z_STREAM_END)
  166941. {
  166942. if (text == NULL)
  166943. {
  166944. text = (png_charp)png_malloc(png_ptr,
  166945. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166946. + key_size + 1));
  166947. png_memcpy(text + key_size, png_ptr->zbuf,
  166948. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166949. png_memcpy(text, key, key_size);
  166950. text_size = key_size + png_ptr->zbuf_size -
  166951. png_ptr->zstream.avail_out;
  166952. *(text + text_size) = '\0';
  166953. }
  166954. else
  166955. {
  166956. png_charp tmp;
  166957. tmp = text;
  166958. text = (png_charp)png_malloc(png_ptr, text_size +
  166959. (png_uint_32)(png_ptr->zbuf_size - png_ptr->zstream.avail_out
  166960. + 1));
  166961. png_memcpy(text, tmp, text_size);
  166962. png_free(png_ptr, tmp);
  166963. png_memcpy(text + text_size, png_ptr->zbuf,
  166964. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  166965. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  166966. *(text + text_size) = '\0';
  166967. }
  166968. if (ret != Z_STREAM_END)
  166969. {
  166970. png_ptr->zstream.next_out = png_ptr->zbuf;
  166971. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  166972. }
  166973. }
  166974. else
  166975. {
  166976. break;
  166977. }
  166978. if (ret == Z_STREAM_END)
  166979. break;
  166980. }
  166981. inflateReset(&png_ptr->zstream);
  166982. png_ptr->zstream.avail_in = 0;
  166983. if (ret != Z_STREAM_END)
  166984. {
  166985. png_ptr->current_text = NULL;
  166986. png_free(png_ptr, key);
  166987. png_free(png_ptr, text);
  166988. return;
  166989. }
  166990. png_ptr->current_text = NULL;
  166991. png_free(png_ptr, key);
  166992. key = text;
  166993. text += key_size;
  166994. text_ptr = (png_textp)png_malloc(png_ptr,
  166995. (png_uint_32)png_sizeof(png_text));
  166996. text_ptr->compression = PNG_TEXT_COMPRESSION_zTXt;
  166997. text_ptr->key = key;
  166998. #ifdef PNG_iTXt_SUPPORTED
  166999. text_ptr->lang = NULL;
  167000. text_ptr->lang_key = NULL;
  167001. #endif
  167002. text_ptr->text = text;
  167003. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  167004. png_free(png_ptr, key);
  167005. png_free(png_ptr, text_ptr);
  167006. if (ret)
  167007. png_warning(png_ptr, "Insufficient memory to store text chunk.");
  167008. }
  167009. }
  167010. #endif
  167011. #if defined(PNG_READ_iTXt_SUPPORTED)
  167012. void /* PRIVATE */
  167013. png_push_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167014. length)
  167015. {
  167016. if (!(png_ptr->mode & PNG_HAVE_IHDR) || (png_ptr->mode & PNG_HAVE_IEND))
  167017. {
  167018. png_error(png_ptr, "Out of place iTXt");
  167019. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167020. }
  167021. #ifdef PNG_MAX_MALLOC_64K
  167022. png_ptr->skip_length = 0; /* This may not be necessary */
  167023. if (length > (png_uint_32)65535L) /* Can't hold entire string in memory */
  167024. {
  167025. png_warning(png_ptr, "iTXt chunk too large to fit in memory");
  167026. png_ptr->skip_length = length - (png_uint_32)65535L;
  167027. length = (png_uint_32)65535L;
  167028. }
  167029. #endif
  167030. png_ptr->current_text = (png_charp)png_malloc(png_ptr,
  167031. (png_uint_32)(length+1));
  167032. png_ptr->current_text[length] = '\0';
  167033. png_ptr->current_text_ptr = png_ptr->current_text;
  167034. png_ptr->current_text_size = (png_size_t)length;
  167035. png_ptr->current_text_left = (png_size_t)length;
  167036. png_ptr->process_mode = PNG_READ_iTXt_MODE;
  167037. }
  167038. void /* PRIVATE */
  167039. png_push_read_iTXt(png_structp png_ptr, png_infop info_ptr)
  167040. {
  167041. if (png_ptr->buffer_size && png_ptr->current_text_left)
  167042. {
  167043. png_size_t text_size;
  167044. if (png_ptr->buffer_size < png_ptr->current_text_left)
  167045. text_size = png_ptr->buffer_size;
  167046. else
  167047. text_size = png_ptr->current_text_left;
  167048. png_crc_read(png_ptr, (png_bytep)png_ptr->current_text_ptr, text_size);
  167049. png_ptr->current_text_left -= text_size;
  167050. png_ptr->current_text_ptr += text_size;
  167051. }
  167052. if (!(png_ptr->current_text_left))
  167053. {
  167054. png_textp text_ptr;
  167055. png_charp key;
  167056. int comp_flag;
  167057. png_charp lang;
  167058. png_charp lang_key;
  167059. png_charp text;
  167060. int ret;
  167061. if (png_ptr->buffer_size < 4)
  167062. {
  167063. png_push_save_buffer(png_ptr);
  167064. return;
  167065. }
  167066. png_push_crc_finish(png_ptr);
  167067. #if defined(PNG_MAX_MALLOC_64K)
  167068. if (png_ptr->skip_length)
  167069. return;
  167070. #endif
  167071. key = png_ptr->current_text;
  167072. for (lang = key; *lang; lang++)
  167073. ;
  167074. if (lang < key + png_ptr->current_text_size - 3)
  167075. lang++;
  167076. comp_flag = *lang++;
  167077. lang++; /* skip comp_type, always zero */
  167078. for (lang_key = lang; *lang_key; lang_key++)
  167079. ;
  167080. lang_key++; /* skip NUL separator */
  167081. text=lang_key;
  167082. if (lang_key < key + png_ptr->current_text_size - 1)
  167083. {
  167084. for (; *text; text++)
  167085. ;
  167086. }
  167087. if (text < key + png_ptr->current_text_size)
  167088. text++;
  167089. text_ptr = (png_textp)png_malloc(png_ptr,
  167090. (png_uint_32)png_sizeof(png_text));
  167091. text_ptr->compression = comp_flag + 2;
  167092. text_ptr->key = key;
  167093. text_ptr->lang = lang;
  167094. text_ptr->lang_key = lang_key;
  167095. text_ptr->text = text;
  167096. text_ptr->text_length = 0;
  167097. text_ptr->itxt_length = png_strlen(text);
  167098. ret = png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  167099. png_ptr->current_text = NULL;
  167100. png_free(png_ptr, text_ptr);
  167101. if (ret)
  167102. png_warning(png_ptr, "Insufficient memory to store iTXt chunk.");
  167103. }
  167104. }
  167105. #endif
  167106. void /* PRIVATE */
  167107. png_push_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32
  167108. length)
  167109. {
  167110. png_uint_32 skip=0;
  167111. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  167112. if (!(png_ptr->chunk_name[0] & 0x20))
  167113. {
  167114. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  167115. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  167116. PNG_HANDLE_CHUNK_ALWAYS
  167117. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  167118. && png_ptr->read_user_chunk_fn == NULL
  167119. #endif
  167120. )
  167121. #endif
  167122. png_chunk_error(png_ptr, "unknown critical chunk");
  167123. info_ptr = info_ptr; /* to quiet some compiler warnings */
  167124. }
  167125. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  167126. if (png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS)
  167127. {
  167128. #ifdef PNG_MAX_MALLOC_64K
  167129. if (length > (png_uint_32)65535L)
  167130. {
  167131. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  167132. skip = length - (png_uint_32)65535L;
  167133. length = (png_uint_32)65535L;
  167134. }
  167135. #endif
  167136. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  167137. (png_charp)png_ptr->chunk_name, 5);
  167138. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  167139. png_ptr->unknown_chunk.size = (png_size_t)length;
  167140. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  167141. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  167142. if(png_ptr->read_user_chunk_fn != NULL)
  167143. {
  167144. int ret;
  167145. ret = (*(png_ptr->read_user_chunk_fn))
  167146. (png_ptr, &png_ptr->unknown_chunk);
  167147. if (ret < 0)
  167148. png_chunk_error(png_ptr, "error in user chunk");
  167149. if (ret == 0)
  167150. {
  167151. if (!(png_ptr->chunk_name[0] & 0x20))
  167152. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  167153. PNG_HANDLE_CHUNK_ALWAYS)
  167154. png_chunk_error(png_ptr, "unknown critical chunk");
  167155. png_set_unknown_chunks(png_ptr, info_ptr,
  167156. &png_ptr->unknown_chunk, 1);
  167157. }
  167158. }
  167159. #else
  167160. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  167161. #endif
  167162. png_free(png_ptr, png_ptr->unknown_chunk.data);
  167163. png_ptr->unknown_chunk.data = NULL;
  167164. }
  167165. else
  167166. #endif
  167167. skip=length;
  167168. png_push_crc_skip(png_ptr, skip);
  167169. }
  167170. void /* PRIVATE */
  167171. png_push_have_info(png_structp png_ptr, png_infop info_ptr)
  167172. {
  167173. if (png_ptr->info_fn != NULL)
  167174. (*(png_ptr->info_fn))(png_ptr, info_ptr);
  167175. }
  167176. void /* PRIVATE */
  167177. png_push_have_end(png_structp png_ptr, png_infop info_ptr)
  167178. {
  167179. if (png_ptr->end_fn != NULL)
  167180. (*(png_ptr->end_fn))(png_ptr, info_ptr);
  167181. }
  167182. void /* PRIVATE */
  167183. png_push_have_row(png_structp png_ptr, png_bytep row)
  167184. {
  167185. if (png_ptr->row_fn != NULL)
  167186. (*(png_ptr->row_fn))(png_ptr, row, png_ptr->row_number,
  167187. (int)png_ptr->pass);
  167188. }
  167189. void PNGAPI
  167190. png_progressive_combine_row (png_structp png_ptr,
  167191. png_bytep old_row, png_bytep new_row)
  167192. {
  167193. #ifdef PNG_USE_LOCAL_ARRAYS
  167194. PNG_CONST int FARDATA png_pass_dsp_mask[7] =
  167195. {0xff, 0x0f, 0xff, 0x33, 0xff, 0x55, 0xff};
  167196. #endif
  167197. if(png_ptr == NULL) return;
  167198. if (new_row != NULL) /* new_row must == png_ptr->row_buf here. */
  167199. png_combine_row(png_ptr, old_row, png_pass_dsp_mask[png_ptr->pass]);
  167200. }
  167201. void PNGAPI
  167202. png_set_progressive_read_fn(png_structp png_ptr, png_voidp progressive_ptr,
  167203. png_progressive_info_ptr info_fn, png_progressive_row_ptr row_fn,
  167204. png_progressive_end_ptr end_fn)
  167205. {
  167206. if(png_ptr == NULL) return;
  167207. png_ptr->info_fn = info_fn;
  167208. png_ptr->row_fn = row_fn;
  167209. png_ptr->end_fn = end_fn;
  167210. png_set_read_fn(png_ptr, progressive_ptr, png_push_fill_buffer);
  167211. }
  167212. png_voidp PNGAPI
  167213. png_get_progressive_ptr(png_structp png_ptr)
  167214. {
  167215. if(png_ptr == NULL) return (NULL);
  167216. return png_ptr->io_ptr;
  167217. }
  167218. #endif /* PNG_PROGRESSIVE_READ_SUPPORTED */
  167219. /*** End of inlined file: pngpread.c ***/
  167220. /*** Start of inlined file: pngrio.c ***/
  167221. #define PNG_INTERNAL
  167222. #if defined(PNG_READ_SUPPORTED)
  167223. void /* PRIVATE */
  167224. png_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167225. {
  167226. png_debug1(4,"reading %d bytes\n", (int)length);
  167227. if (png_ptr->read_data_fn != NULL)
  167228. (*(png_ptr->read_data_fn))(png_ptr, data, length);
  167229. else
  167230. png_error(png_ptr, "Call to NULL read function");
  167231. }
  167232. #if !defined(PNG_NO_STDIO)
  167233. #ifndef USE_FAR_KEYWORD
  167234. void PNGAPI
  167235. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167236. {
  167237. png_size_t check;
  167238. if(png_ptr == NULL) return;
  167239. #if defined(_WIN32_WCE)
  167240. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167241. check = 0;
  167242. #else
  167243. check = (png_size_t)fread(data, (png_size_t)1, length,
  167244. (png_FILE_p)png_ptr->io_ptr);
  167245. #endif
  167246. if (check != length)
  167247. png_error(png_ptr, "Read Error");
  167248. }
  167249. #else
  167250. #define NEAR_BUF_SIZE 1024
  167251. #define MIN(a,b) (a <= b ? a : b)
  167252. static void PNGAPI
  167253. png_default_read_data(png_structp png_ptr, png_bytep data, png_size_t length)
  167254. {
  167255. int check;
  167256. png_byte *n_data;
  167257. png_FILE_p io_ptr;
  167258. if(png_ptr == NULL) return;
  167259. n_data = (png_byte *)CVT_PTR_NOCHECK(data);
  167260. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  167261. if ((png_bytep)n_data == data)
  167262. {
  167263. #if defined(_WIN32_WCE)
  167264. if ( !ReadFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  167265. check = 0;
  167266. #else
  167267. check = fread(n_data, 1, length, io_ptr);
  167268. #endif
  167269. }
  167270. else
  167271. {
  167272. png_byte buf[NEAR_BUF_SIZE];
  167273. png_size_t read, remaining, err;
  167274. check = 0;
  167275. remaining = length;
  167276. do
  167277. {
  167278. read = MIN(NEAR_BUF_SIZE, remaining);
  167279. #if defined(_WIN32_WCE)
  167280. if ( !ReadFile((HANDLE)(io_ptr), buf, read, &err, NULL) )
  167281. err = 0;
  167282. #else
  167283. err = fread(buf, (png_size_t)1, read, io_ptr);
  167284. #endif
  167285. png_memcpy(data, buf, read); /* copy far buffer to near buffer */
  167286. if(err != read)
  167287. break;
  167288. else
  167289. check += err;
  167290. data += read;
  167291. remaining -= read;
  167292. }
  167293. while (remaining != 0);
  167294. }
  167295. if ((png_uint_32)check != (png_uint_32)length)
  167296. png_error(png_ptr, "read Error");
  167297. }
  167298. #endif
  167299. #endif
  167300. void PNGAPI
  167301. png_set_read_fn(png_structp png_ptr, png_voidp io_ptr,
  167302. png_rw_ptr read_data_fn)
  167303. {
  167304. if(png_ptr == NULL) return;
  167305. png_ptr->io_ptr = io_ptr;
  167306. #if !defined(PNG_NO_STDIO)
  167307. if (read_data_fn != NULL)
  167308. png_ptr->read_data_fn = read_data_fn;
  167309. else
  167310. png_ptr->read_data_fn = png_default_read_data;
  167311. #else
  167312. png_ptr->read_data_fn = read_data_fn;
  167313. #endif
  167314. if (png_ptr->write_data_fn != NULL)
  167315. {
  167316. png_ptr->write_data_fn = NULL;
  167317. png_warning(png_ptr,
  167318. "It's an error to set both read_data_fn and write_data_fn in the ");
  167319. png_warning(png_ptr,
  167320. "same structure. Resetting write_data_fn to NULL.");
  167321. }
  167322. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  167323. png_ptr->output_flush_fn = NULL;
  167324. #endif
  167325. }
  167326. #endif /* PNG_READ_SUPPORTED */
  167327. /*** End of inlined file: pngrio.c ***/
  167328. /*** Start of inlined file: pngrtran.c ***/
  167329. #define PNG_INTERNAL
  167330. #if defined(PNG_READ_SUPPORTED)
  167331. void PNGAPI
  167332. png_set_crc_action(png_structp png_ptr, int crit_action, int ancil_action)
  167333. {
  167334. png_debug(1, "in png_set_crc_action\n");
  167335. if(png_ptr == NULL) return;
  167336. switch (crit_action)
  167337. {
  167338. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167339. break;
  167340. case PNG_CRC_WARN_USE: /* warn/use data */
  167341. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167342. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE;
  167343. break;
  167344. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167345. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167346. png_ptr->flags |= PNG_FLAG_CRC_CRITICAL_USE |
  167347. PNG_FLAG_CRC_CRITICAL_IGNORE;
  167348. break;
  167349. case PNG_CRC_WARN_DISCARD: /* not a valid action for critical data */
  167350. png_warning(png_ptr, "Can't discard critical data on CRC error.");
  167351. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167352. case PNG_CRC_DEFAULT:
  167353. default:
  167354. png_ptr->flags &= ~PNG_FLAG_CRC_CRITICAL_MASK;
  167355. break;
  167356. }
  167357. switch (ancil_action)
  167358. {
  167359. case PNG_CRC_NO_CHANGE: /* leave setting as is */
  167360. break;
  167361. case PNG_CRC_WARN_USE: /* warn/use data */
  167362. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167363. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE;
  167364. break;
  167365. case PNG_CRC_QUIET_USE: /* quiet/use data */
  167366. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167367. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_USE |
  167368. PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167369. break;
  167370. case PNG_CRC_ERROR_QUIT: /* error/quit */
  167371. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167372. png_ptr->flags |= PNG_FLAG_CRC_ANCILLARY_NOWARN;
  167373. break;
  167374. case PNG_CRC_WARN_DISCARD: /* warn/discard data */
  167375. case PNG_CRC_DEFAULT:
  167376. default:
  167377. png_ptr->flags &= ~PNG_FLAG_CRC_ANCILLARY_MASK;
  167378. break;
  167379. }
  167380. }
  167381. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  167382. defined(PNG_FLOATING_POINT_SUPPORTED)
  167383. void PNGAPI
  167384. png_set_background(png_structp png_ptr,
  167385. png_color_16p background_color, int background_gamma_code,
  167386. int need_expand, double background_gamma)
  167387. {
  167388. png_debug(1, "in png_set_background\n");
  167389. if(png_ptr == NULL) return;
  167390. if (background_gamma_code == PNG_BACKGROUND_GAMMA_UNKNOWN)
  167391. {
  167392. png_warning(png_ptr, "Application must supply a known background gamma");
  167393. return;
  167394. }
  167395. png_ptr->transformations |= PNG_BACKGROUND;
  167396. png_memcpy(&(png_ptr->background), background_color,
  167397. png_sizeof(png_color_16));
  167398. png_ptr->background_gamma = (float)background_gamma;
  167399. png_ptr->background_gamma_type = (png_byte)(background_gamma_code);
  167400. png_ptr->transformations |= (need_expand ? PNG_BACKGROUND_EXPAND : 0);
  167401. }
  167402. #endif
  167403. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  167404. void PNGAPI
  167405. png_set_strip_16(png_structp png_ptr)
  167406. {
  167407. png_debug(1, "in png_set_strip_16\n");
  167408. if(png_ptr == NULL) return;
  167409. png_ptr->transformations |= PNG_16_TO_8;
  167410. }
  167411. #endif
  167412. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  167413. void PNGAPI
  167414. png_set_strip_alpha(png_structp png_ptr)
  167415. {
  167416. png_debug(1, "in png_set_strip_alpha\n");
  167417. if(png_ptr == NULL) return;
  167418. png_ptr->flags |= PNG_FLAG_STRIP_ALPHA;
  167419. }
  167420. #endif
  167421. #if defined(PNG_READ_DITHER_SUPPORTED)
  167422. typedef struct png_dsort_struct
  167423. {
  167424. struct png_dsort_struct FAR * next;
  167425. png_byte left;
  167426. png_byte right;
  167427. } png_dsort;
  167428. typedef png_dsort FAR * png_dsortp;
  167429. typedef png_dsort FAR * FAR * png_dsortpp;
  167430. void PNGAPI
  167431. png_set_dither(png_structp png_ptr, png_colorp palette,
  167432. int num_palette, int maximum_colors, png_uint_16p histogram,
  167433. int full_dither)
  167434. {
  167435. png_debug(1, "in png_set_dither\n");
  167436. if(png_ptr == NULL) return;
  167437. png_ptr->transformations |= PNG_DITHER;
  167438. if (!full_dither)
  167439. {
  167440. int i;
  167441. png_ptr->dither_index = (png_bytep)png_malloc(png_ptr,
  167442. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167443. for (i = 0; i < num_palette; i++)
  167444. png_ptr->dither_index[i] = (png_byte)i;
  167445. }
  167446. if (num_palette > maximum_colors)
  167447. {
  167448. if (histogram != NULL)
  167449. {
  167450. int i;
  167451. png_ptr->dither_sort = (png_bytep)png_malloc(png_ptr,
  167452. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167453. for (i = 0; i < num_palette; i++)
  167454. png_ptr->dither_sort[i] = (png_byte)i;
  167455. for (i = num_palette - 1; i >= maximum_colors; i--)
  167456. {
  167457. int done; /* to stop early if the list is pre-sorted */
  167458. int j;
  167459. done = 1;
  167460. for (j = 0; j < i; j++)
  167461. {
  167462. if (histogram[png_ptr->dither_sort[j]]
  167463. < histogram[png_ptr->dither_sort[j + 1]])
  167464. {
  167465. png_byte t;
  167466. t = png_ptr->dither_sort[j];
  167467. png_ptr->dither_sort[j] = png_ptr->dither_sort[j + 1];
  167468. png_ptr->dither_sort[j + 1] = t;
  167469. done = 0;
  167470. }
  167471. }
  167472. if (done)
  167473. break;
  167474. }
  167475. if (full_dither)
  167476. {
  167477. int j = num_palette;
  167478. for (i = 0; i < maximum_colors; i++)
  167479. {
  167480. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167481. {
  167482. do
  167483. j--;
  167484. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167485. palette[i] = palette[j];
  167486. }
  167487. }
  167488. }
  167489. else
  167490. {
  167491. int j = num_palette;
  167492. for (i = 0; i < maximum_colors; i++)
  167493. {
  167494. if ((int)png_ptr->dither_sort[i] >= maximum_colors)
  167495. {
  167496. png_color tmp_color;
  167497. do
  167498. j--;
  167499. while ((int)png_ptr->dither_sort[j] >= maximum_colors);
  167500. tmp_color = palette[j];
  167501. palette[j] = palette[i];
  167502. palette[i] = tmp_color;
  167503. png_ptr->dither_index[j] = (png_byte)i;
  167504. png_ptr->dither_index[i] = (png_byte)j;
  167505. }
  167506. }
  167507. for (i = 0; i < num_palette; i++)
  167508. {
  167509. if ((int)png_ptr->dither_index[i] >= maximum_colors)
  167510. {
  167511. int min_d, k, min_k, d_index;
  167512. d_index = png_ptr->dither_index[i];
  167513. min_d = PNG_COLOR_DIST(palette[d_index], palette[0]);
  167514. for (k = 1, min_k = 0; k < maximum_colors; k++)
  167515. {
  167516. int d;
  167517. d = PNG_COLOR_DIST(palette[d_index], palette[k]);
  167518. if (d < min_d)
  167519. {
  167520. min_d = d;
  167521. min_k = k;
  167522. }
  167523. }
  167524. png_ptr->dither_index[i] = (png_byte)min_k;
  167525. }
  167526. }
  167527. }
  167528. png_free(png_ptr, png_ptr->dither_sort);
  167529. png_ptr->dither_sort=NULL;
  167530. }
  167531. else
  167532. {
  167533. int i;
  167534. int max_d;
  167535. int num_new_palette;
  167536. png_dsortp t;
  167537. png_dsortpp hash;
  167538. t=NULL;
  167539. png_ptr->index_to_palette = (png_bytep)png_malloc(png_ptr,
  167540. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167541. png_ptr->palette_to_index = (png_bytep)png_malloc(png_ptr,
  167542. (png_uint_32)(num_palette * png_sizeof (png_byte)));
  167543. for (i = 0; i < num_palette; i++)
  167544. {
  167545. png_ptr->index_to_palette[i] = (png_byte)i;
  167546. png_ptr->palette_to_index[i] = (png_byte)i;
  167547. }
  167548. hash = (png_dsortpp)png_malloc(png_ptr, (png_uint_32)(769 *
  167549. png_sizeof (png_dsortp)));
  167550. for (i = 0; i < 769; i++)
  167551. hash[i] = NULL;
  167552. num_new_palette = num_palette;
  167553. max_d = 96;
  167554. while (num_new_palette > maximum_colors)
  167555. {
  167556. for (i = 0; i < num_new_palette - 1; i++)
  167557. {
  167558. int j;
  167559. for (j = i + 1; j < num_new_palette; j++)
  167560. {
  167561. int d;
  167562. d = PNG_COLOR_DIST(palette[i], palette[j]);
  167563. if (d <= max_d)
  167564. {
  167565. t = (png_dsortp)png_malloc_warn(png_ptr,
  167566. (png_uint_32)(png_sizeof(png_dsort)));
  167567. if (t == NULL)
  167568. break;
  167569. t->next = hash[d];
  167570. t->left = (png_byte)i;
  167571. t->right = (png_byte)j;
  167572. hash[d] = t;
  167573. }
  167574. }
  167575. if (t == NULL)
  167576. break;
  167577. }
  167578. if (t != NULL)
  167579. for (i = 0; i <= max_d; i++)
  167580. {
  167581. if (hash[i] != NULL)
  167582. {
  167583. png_dsortp p;
  167584. for (p = hash[i]; p; p = p->next)
  167585. {
  167586. if ((int)png_ptr->index_to_palette[p->left]
  167587. < num_new_palette &&
  167588. (int)png_ptr->index_to_palette[p->right]
  167589. < num_new_palette)
  167590. {
  167591. int j, next_j;
  167592. if (num_new_palette & 0x01)
  167593. {
  167594. j = p->left;
  167595. next_j = p->right;
  167596. }
  167597. else
  167598. {
  167599. j = p->right;
  167600. next_j = p->left;
  167601. }
  167602. num_new_palette--;
  167603. palette[png_ptr->index_to_palette[j]]
  167604. = palette[num_new_palette];
  167605. if (!full_dither)
  167606. {
  167607. int k;
  167608. for (k = 0; k < num_palette; k++)
  167609. {
  167610. if (png_ptr->dither_index[k] ==
  167611. png_ptr->index_to_palette[j])
  167612. png_ptr->dither_index[k] =
  167613. png_ptr->index_to_palette[next_j];
  167614. if ((int)png_ptr->dither_index[k] ==
  167615. num_new_palette)
  167616. png_ptr->dither_index[k] =
  167617. png_ptr->index_to_palette[j];
  167618. }
  167619. }
  167620. png_ptr->index_to_palette[png_ptr->palette_to_index
  167621. [num_new_palette]] = png_ptr->index_to_palette[j];
  167622. png_ptr->palette_to_index[png_ptr->index_to_palette[j]]
  167623. = png_ptr->palette_to_index[num_new_palette];
  167624. png_ptr->index_to_palette[j] = (png_byte)num_new_palette;
  167625. png_ptr->palette_to_index[num_new_palette] = (png_byte)j;
  167626. }
  167627. if (num_new_palette <= maximum_colors)
  167628. break;
  167629. }
  167630. if (num_new_palette <= maximum_colors)
  167631. break;
  167632. }
  167633. }
  167634. for (i = 0; i < 769; i++)
  167635. {
  167636. if (hash[i] != NULL)
  167637. {
  167638. png_dsortp p = hash[i];
  167639. while (p)
  167640. {
  167641. t = p->next;
  167642. png_free(png_ptr, p);
  167643. p = t;
  167644. }
  167645. }
  167646. hash[i] = 0;
  167647. }
  167648. max_d += 96;
  167649. }
  167650. png_free(png_ptr, hash);
  167651. png_free(png_ptr, png_ptr->palette_to_index);
  167652. png_free(png_ptr, png_ptr->index_to_palette);
  167653. png_ptr->palette_to_index=NULL;
  167654. png_ptr->index_to_palette=NULL;
  167655. }
  167656. num_palette = maximum_colors;
  167657. }
  167658. if (png_ptr->palette == NULL)
  167659. {
  167660. png_ptr->palette = palette;
  167661. }
  167662. png_ptr->num_palette = (png_uint_16)num_palette;
  167663. if (full_dither)
  167664. {
  167665. int i;
  167666. png_bytep distance;
  167667. int total_bits = PNG_DITHER_RED_BITS + PNG_DITHER_GREEN_BITS +
  167668. PNG_DITHER_BLUE_BITS;
  167669. int num_red = (1 << PNG_DITHER_RED_BITS);
  167670. int num_green = (1 << PNG_DITHER_GREEN_BITS);
  167671. int num_blue = (1 << PNG_DITHER_BLUE_BITS);
  167672. png_size_t num_entries = ((png_size_t)1 << total_bits);
  167673. png_ptr->palette_lookup = (png_bytep )png_malloc(png_ptr,
  167674. (png_uint_32)(num_entries * png_sizeof (png_byte)));
  167675. png_memset(png_ptr->palette_lookup, 0, num_entries *
  167676. png_sizeof (png_byte));
  167677. distance = (png_bytep)png_malloc(png_ptr, (png_uint_32)(num_entries *
  167678. png_sizeof(png_byte)));
  167679. png_memset(distance, 0xff, num_entries * png_sizeof(png_byte));
  167680. for (i = 0; i < num_palette; i++)
  167681. {
  167682. int ir, ig, ib;
  167683. int r = (palette[i].red >> (8 - PNG_DITHER_RED_BITS));
  167684. int g = (palette[i].green >> (8 - PNG_DITHER_GREEN_BITS));
  167685. int b = (palette[i].blue >> (8 - PNG_DITHER_BLUE_BITS));
  167686. for (ir = 0; ir < num_red; ir++)
  167687. {
  167688. int dr = ((ir > r) ? ir - r : r - ir);
  167689. int index_r = (ir << (PNG_DITHER_BLUE_BITS + PNG_DITHER_GREEN_BITS));
  167690. for (ig = 0; ig < num_green; ig++)
  167691. {
  167692. int dg = ((ig > g) ? ig - g : g - ig);
  167693. int dt = dr + dg;
  167694. int dm = ((dr > dg) ? dr : dg);
  167695. int index_g = index_r | (ig << PNG_DITHER_BLUE_BITS);
  167696. for (ib = 0; ib < num_blue; ib++)
  167697. {
  167698. int d_index = index_g | ib;
  167699. int db = ((ib > b) ? ib - b : b - ib);
  167700. int dmax = ((dm > db) ? dm : db);
  167701. int d = dmax + dt + db;
  167702. if (d < (int)distance[d_index])
  167703. {
  167704. distance[d_index] = (png_byte)d;
  167705. png_ptr->palette_lookup[d_index] = (png_byte)i;
  167706. }
  167707. }
  167708. }
  167709. }
  167710. }
  167711. png_free(png_ptr, distance);
  167712. }
  167713. }
  167714. #endif
  167715. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167716. void PNGAPI
  167717. png_set_gamma(png_structp png_ptr, double scrn_gamma, double file_gamma)
  167718. {
  167719. png_debug(1, "in png_set_gamma\n");
  167720. if(png_ptr == NULL) return;
  167721. if ((fabs(scrn_gamma * file_gamma - 1.0) > PNG_GAMMA_THRESHOLD) ||
  167722. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA) ||
  167723. (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE))
  167724. png_ptr->transformations |= PNG_GAMMA;
  167725. png_ptr->gamma = (float)file_gamma;
  167726. png_ptr->screen_gamma = (float)scrn_gamma;
  167727. }
  167728. #endif
  167729. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167730. void PNGAPI
  167731. png_set_expand(png_structp png_ptr)
  167732. {
  167733. png_debug(1, "in png_set_expand\n");
  167734. if(png_ptr == NULL) return;
  167735. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167736. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167737. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167738. #endif
  167739. }
  167740. void PNGAPI
  167741. png_set_palette_to_rgb(png_structp png_ptr)
  167742. {
  167743. png_debug(1, "in png_set_palette_to_rgb\n");
  167744. if(png_ptr == NULL) return;
  167745. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167746. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167747. png_ptr->flags &= !(PNG_FLAG_ROW_INIT);
  167748. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167749. #endif
  167750. }
  167751. #if !defined(PNG_1_0_X)
  167752. void PNGAPI
  167753. png_set_expand_gray_1_2_4_to_8(png_structp png_ptr)
  167754. {
  167755. png_debug(1, "in png_set_expand_gray_1_2_4_to_8\n");
  167756. if(png_ptr == NULL) return;
  167757. png_ptr->transformations |= PNG_EXPAND;
  167758. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167759. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167760. #endif
  167761. }
  167762. #endif
  167763. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  167764. void PNGAPI
  167765. png_set_gray_1_2_4_to_8(png_structp png_ptr)
  167766. {
  167767. png_debug(1, "in png_set_gray_1_2_4_to_8\n");
  167768. if(png_ptr == NULL) return;
  167769. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167770. }
  167771. #endif
  167772. void PNGAPI
  167773. png_set_tRNS_to_alpha(png_structp png_ptr)
  167774. {
  167775. png_debug(1, "in png_set_tRNS_to_alpha\n");
  167776. png_ptr->transformations |= (PNG_EXPAND | PNG_EXPAND_tRNS);
  167777. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167778. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167779. #endif
  167780. }
  167781. #endif /* defined(PNG_READ_EXPAND_SUPPORTED) */
  167782. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167783. void PNGAPI
  167784. png_set_gray_to_rgb(png_structp png_ptr)
  167785. {
  167786. png_debug(1, "in png_set_gray_to_rgb\n");
  167787. png_ptr->transformations |= PNG_GRAY_TO_RGB;
  167788. #ifdef PNG_WARN_UNINITIALIZED_ROW
  167789. png_ptr->flags &= ~PNG_FLAG_ROW_INIT;
  167790. #endif
  167791. }
  167792. #endif
  167793. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  167794. #if defined(PNG_FLOATING_POINT_SUPPORTED)
  167795. void PNGAPI
  167796. png_set_rgb_to_gray(png_structp png_ptr, int error_action, double red,
  167797. double green)
  167798. {
  167799. int red_fixed = (int)((float)red*100000.0 + 0.5);
  167800. int green_fixed = (int)((float)green*100000.0 + 0.5);
  167801. if(png_ptr == NULL) return;
  167802. png_set_rgb_to_gray_fixed(png_ptr, error_action, red_fixed, green_fixed);
  167803. }
  167804. #endif
  167805. void PNGAPI
  167806. png_set_rgb_to_gray_fixed(png_structp png_ptr, int error_action,
  167807. png_fixed_point red, png_fixed_point green)
  167808. {
  167809. png_debug(1, "in png_set_rgb_to_gray\n");
  167810. if(png_ptr == NULL) return;
  167811. switch(error_action)
  167812. {
  167813. case 1: png_ptr->transformations |= PNG_RGB_TO_GRAY;
  167814. break;
  167815. case 2: png_ptr->transformations |= PNG_RGB_TO_GRAY_WARN;
  167816. break;
  167817. case 3: png_ptr->transformations |= PNG_RGB_TO_GRAY_ERR;
  167818. }
  167819. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  167820. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167821. png_ptr->transformations |= PNG_EXPAND;
  167822. #else
  167823. {
  167824. png_warning(png_ptr, "Cannot do RGB_TO_GRAY without EXPAND_SUPPORTED.");
  167825. png_ptr->transformations &= ~PNG_RGB_TO_GRAY;
  167826. }
  167827. #endif
  167828. {
  167829. png_uint_16 red_int, green_int;
  167830. if(red < 0 || green < 0)
  167831. {
  167832. red_int = 6968; /* .212671 * 32768 + .5 */
  167833. green_int = 23434; /* .715160 * 32768 + .5 */
  167834. }
  167835. else if(red + green < 100000L)
  167836. {
  167837. red_int = (png_uint_16)(((png_uint_32)red*32768L)/100000L);
  167838. green_int = (png_uint_16)(((png_uint_32)green*32768L)/100000L);
  167839. }
  167840. else
  167841. {
  167842. png_warning(png_ptr, "ignoring out of range rgb_to_gray coefficients");
  167843. red_int = 6968;
  167844. green_int = 23434;
  167845. }
  167846. png_ptr->rgb_to_gray_red_coeff = red_int;
  167847. png_ptr->rgb_to_gray_green_coeff = green_int;
  167848. png_ptr->rgb_to_gray_blue_coeff = (png_uint_16)(32768-red_int-green_int);
  167849. }
  167850. }
  167851. #endif
  167852. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  167853. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  167854. defined(PNG_LEGACY_SUPPORTED)
  167855. void PNGAPI
  167856. png_set_read_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  167857. read_user_transform_fn)
  167858. {
  167859. png_debug(1, "in png_set_read_user_transform_fn\n");
  167860. if(png_ptr == NULL) return;
  167861. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  167862. png_ptr->transformations |= PNG_USER_TRANSFORM;
  167863. png_ptr->read_user_transform_fn = read_user_transform_fn;
  167864. #endif
  167865. #ifdef PNG_LEGACY_SUPPORTED
  167866. if(read_user_transform_fn)
  167867. png_warning(png_ptr,
  167868. "This version of libpng does not support user transforms");
  167869. #endif
  167870. }
  167871. #endif
  167872. void /* PRIVATE */
  167873. png_init_read_transformations(png_structp png_ptr)
  167874. {
  167875. png_debug(1, "in png_init_read_transformations\n");
  167876. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  167877. if(png_ptr != NULL)
  167878. #endif
  167879. {
  167880. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || defined(PNG_READ_SHIFT_SUPPORTED) \
  167881. || defined(PNG_READ_GAMMA_SUPPORTED)
  167882. int color_type = png_ptr->color_type;
  167883. #endif
  167884. #if defined(PNG_READ_EXPAND_SUPPORTED) && defined(PNG_READ_BACKGROUND_SUPPORTED)
  167885. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  167886. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167887. !(color_type & PNG_COLOR_MASK_COLOR))
  167888. {
  167889. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167890. } else if ((png_ptr->transformations & PNG_BACKGROUND) &&
  167891. !(png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167892. (png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  167893. png_ptr->background.red == png_ptr->background.green &&
  167894. png_ptr->background.red == png_ptr->background.blue)
  167895. {
  167896. png_ptr->mode |= PNG_BACKGROUND_IS_GRAY;
  167897. png_ptr->background.gray = png_ptr->background.red;
  167898. }
  167899. #endif
  167900. if ((png_ptr->transformations & PNG_BACKGROUND_EXPAND) &&
  167901. (png_ptr->transformations & PNG_EXPAND))
  167902. {
  167903. if (!(color_type & PNG_COLOR_MASK_COLOR)) /* i.e., GRAY or GRAY_ALPHA */
  167904. {
  167905. switch (png_ptr->bit_depth)
  167906. {
  167907. case 1:
  167908. png_ptr->background.gray *= (png_uint_16)0xff;
  167909. png_ptr->background.red = png_ptr->background.green
  167910. = png_ptr->background.blue = png_ptr->background.gray;
  167911. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167912. {
  167913. png_ptr->trans_values.gray *= (png_uint_16)0xff;
  167914. png_ptr->trans_values.red = png_ptr->trans_values.green
  167915. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167916. }
  167917. break;
  167918. case 2:
  167919. png_ptr->background.gray *= (png_uint_16)0x55;
  167920. png_ptr->background.red = png_ptr->background.green
  167921. = png_ptr->background.blue = png_ptr->background.gray;
  167922. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167923. {
  167924. png_ptr->trans_values.gray *= (png_uint_16)0x55;
  167925. png_ptr->trans_values.red = png_ptr->trans_values.green
  167926. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167927. }
  167928. break;
  167929. case 4:
  167930. png_ptr->background.gray *= (png_uint_16)0x11;
  167931. png_ptr->background.red = png_ptr->background.green
  167932. = png_ptr->background.blue = png_ptr->background.gray;
  167933. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167934. {
  167935. png_ptr->trans_values.gray *= (png_uint_16)0x11;
  167936. png_ptr->trans_values.red = png_ptr->trans_values.green
  167937. = png_ptr->trans_values.blue = png_ptr->trans_values.gray;
  167938. }
  167939. break;
  167940. case 8:
  167941. case 16:
  167942. png_ptr->background.red = png_ptr->background.green
  167943. = png_ptr->background.blue = png_ptr->background.gray;
  167944. break;
  167945. }
  167946. }
  167947. else if (color_type == PNG_COLOR_TYPE_PALETTE)
  167948. {
  167949. png_ptr->background.red =
  167950. png_ptr->palette[png_ptr->background.index].red;
  167951. png_ptr->background.green =
  167952. png_ptr->palette[png_ptr->background.index].green;
  167953. png_ptr->background.blue =
  167954. png_ptr->palette[png_ptr->background.index].blue;
  167955. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  167956. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  167957. {
  167958. #if defined(PNG_READ_EXPAND_SUPPORTED)
  167959. if (!(png_ptr->transformations & PNG_EXPAND_tRNS))
  167960. #endif
  167961. {
  167962. int i,istop;
  167963. istop=(int)png_ptr->num_trans;
  167964. for (i=0; i<istop; i++)
  167965. png_ptr->trans[i] = (png_byte)(255 - png_ptr->trans[i]);
  167966. }
  167967. }
  167968. #endif
  167969. }
  167970. }
  167971. #endif
  167972. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  167973. png_ptr->background_1 = png_ptr->background;
  167974. #endif
  167975. #if defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  167976. if ((color_type == PNG_COLOR_TYPE_PALETTE && png_ptr->num_trans != 0)
  167977. && (fabs(png_ptr->screen_gamma * png_ptr->gamma - 1.0)
  167978. < PNG_GAMMA_THRESHOLD))
  167979. {
  167980. int i,k;
  167981. k=0;
  167982. for (i=0; i<png_ptr->num_trans; i++)
  167983. {
  167984. if (png_ptr->trans[i] != 0 && png_ptr->trans[i] != 0xff)
  167985. k=1; /* partial transparency is present */
  167986. }
  167987. if (k == 0)
  167988. png_ptr->transformations &= (~PNG_GAMMA);
  167989. }
  167990. if ((png_ptr->transformations & (PNG_GAMMA | PNG_RGB_TO_GRAY)) &&
  167991. png_ptr->gamma != 0.0)
  167992. {
  167993. png_build_gamma_table(png_ptr);
  167994. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  167995. if (png_ptr->transformations & PNG_BACKGROUND)
  167996. {
  167997. if (color_type == PNG_COLOR_TYPE_PALETTE)
  167998. {
  167999. png_color back, back_1;
  168000. png_colorp palette = png_ptr->palette;
  168001. int num_palette = png_ptr->num_palette;
  168002. int i;
  168003. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  168004. {
  168005. back.red = png_ptr->gamma_table[png_ptr->background.red];
  168006. back.green = png_ptr->gamma_table[png_ptr->background.green];
  168007. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  168008. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  168009. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  168010. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  168011. }
  168012. else
  168013. {
  168014. double g, gs;
  168015. switch (png_ptr->background_gamma_type)
  168016. {
  168017. case PNG_BACKGROUND_GAMMA_SCREEN:
  168018. g = (png_ptr->screen_gamma);
  168019. gs = 1.0;
  168020. break;
  168021. case PNG_BACKGROUND_GAMMA_FILE:
  168022. g = 1.0 / (png_ptr->gamma);
  168023. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  168024. break;
  168025. case PNG_BACKGROUND_GAMMA_UNIQUE:
  168026. g = 1.0 / (png_ptr->background_gamma);
  168027. gs = 1.0 / (png_ptr->background_gamma *
  168028. png_ptr->screen_gamma);
  168029. break;
  168030. default:
  168031. g = 1.0; /* back_1 */
  168032. gs = 1.0; /* back */
  168033. }
  168034. if ( fabs(gs - 1.0) < PNG_GAMMA_THRESHOLD)
  168035. {
  168036. back.red = (png_byte)png_ptr->background.red;
  168037. back.green = (png_byte)png_ptr->background.green;
  168038. back.blue = (png_byte)png_ptr->background.blue;
  168039. }
  168040. else
  168041. {
  168042. back.red = (png_byte)(pow(
  168043. (double)png_ptr->background.red/255, gs) * 255.0 + .5);
  168044. back.green = (png_byte)(pow(
  168045. (double)png_ptr->background.green/255, gs) * 255.0 + .5);
  168046. back.blue = (png_byte)(pow(
  168047. (double)png_ptr->background.blue/255, gs) * 255.0 + .5);
  168048. }
  168049. back_1.red = (png_byte)(pow(
  168050. (double)png_ptr->background.red/255, g) * 255.0 + .5);
  168051. back_1.green = (png_byte)(pow(
  168052. (double)png_ptr->background.green/255, g) * 255.0 + .5);
  168053. back_1.blue = (png_byte)(pow(
  168054. (double)png_ptr->background.blue/255, g) * 255.0 + .5);
  168055. }
  168056. for (i = 0; i < num_palette; i++)
  168057. {
  168058. if (i < (int)png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  168059. {
  168060. if (png_ptr->trans[i] == 0)
  168061. {
  168062. palette[i] = back;
  168063. }
  168064. else /* if (png_ptr->trans[i] != 0xff) */
  168065. {
  168066. png_byte v, w;
  168067. v = png_ptr->gamma_to_1[palette[i].red];
  168068. png_composite(w, v, png_ptr->trans[i], back_1.red);
  168069. palette[i].red = png_ptr->gamma_from_1[w];
  168070. v = png_ptr->gamma_to_1[palette[i].green];
  168071. png_composite(w, v, png_ptr->trans[i], back_1.green);
  168072. palette[i].green = png_ptr->gamma_from_1[w];
  168073. v = png_ptr->gamma_to_1[palette[i].blue];
  168074. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  168075. palette[i].blue = png_ptr->gamma_from_1[w];
  168076. }
  168077. }
  168078. else
  168079. {
  168080. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168081. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168082. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168083. }
  168084. }
  168085. }
  168086. else
  168087. {
  168088. double m = (double)(((png_uint_32)1 << png_ptr->bit_depth) - 1);
  168089. double g = 1.0;
  168090. double gs = 1.0;
  168091. switch (png_ptr->background_gamma_type)
  168092. {
  168093. case PNG_BACKGROUND_GAMMA_SCREEN:
  168094. g = (png_ptr->screen_gamma);
  168095. gs = 1.0;
  168096. break;
  168097. case PNG_BACKGROUND_GAMMA_FILE:
  168098. g = 1.0 / (png_ptr->gamma);
  168099. gs = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  168100. break;
  168101. case PNG_BACKGROUND_GAMMA_UNIQUE:
  168102. g = 1.0 / (png_ptr->background_gamma);
  168103. gs = 1.0 / (png_ptr->background_gamma *
  168104. png_ptr->screen_gamma);
  168105. break;
  168106. }
  168107. png_ptr->background_1.gray = (png_uint_16)(pow(
  168108. (double)png_ptr->background.gray / m, g) * m + .5);
  168109. png_ptr->background.gray = (png_uint_16)(pow(
  168110. (double)png_ptr->background.gray / m, gs) * m + .5);
  168111. if ((png_ptr->background.red != png_ptr->background.green) ||
  168112. (png_ptr->background.red != png_ptr->background.blue) ||
  168113. (png_ptr->background.red != png_ptr->background.gray))
  168114. {
  168115. png_ptr->background_1.red = (png_uint_16)(pow(
  168116. (double)png_ptr->background.red / m, g) * m + .5);
  168117. png_ptr->background_1.green = (png_uint_16)(pow(
  168118. (double)png_ptr->background.green / m, g) * m + .5);
  168119. png_ptr->background_1.blue = (png_uint_16)(pow(
  168120. (double)png_ptr->background.blue / m, g) * m + .5);
  168121. png_ptr->background.red = (png_uint_16)(pow(
  168122. (double)png_ptr->background.red / m, gs) * m + .5);
  168123. png_ptr->background.green = (png_uint_16)(pow(
  168124. (double)png_ptr->background.green / m, gs) * m + .5);
  168125. png_ptr->background.blue = (png_uint_16)(pow(
  168126. (double)png_ptr->background.blue / m, gs) * m + .5);
  168127. }
  168128. else
  168129. {
  168130. png_ptr->background_1.red = png_ptr->background_1.green
  168131. = png_ptr->background_1.blue = png_ptr->background_1.gray;
  168132. png_ptr->background.red = png_ptr->background.green
  168133. = png_ptr->background.blue = png_ptr->background.gray;
  168134. }
  168135. }
  168136. }
  168137. else
  168138. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  168139. if (color_type == PNG_COLOR_TYPE_PALETTE)
  168140. {
  168141. png_colorp palette = png_ptr->palette;
  168142. int num_palette = png_ptr->num_palette;
  168143. int i;
  168144. for (i = 0; i < num_palette; i++)
  168145. {
  168146. palette[i].red = png_ptr->gamma_table[palette[i].red];
  168147. palette[i].green = png_ptr->gamma_table[palette[i].green];
  168148. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  168149. }
  168150. }
  168151. }
  168152. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168153. else
  168154. #endif
  168155. #endif /* PNG_READ_GAMMA_SUPPORTED && PNG_FLOATING_POINT_SUPPORTED */
  168156. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168157. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168158. (color_type == PNG_COLOR_TYPE_PALETTE))
  168159. {
  168160. int i;
  168161. int istop = (int)png_ptr->num_trans;
  168162. png_color back;
  168163. png_colorp palette = png_ptr->palette;
  168164. back.red = (png_byte)png_ptr->background.red;
  168165. back.green = (png_byte)png_ptr->background.green;
  168166. back.blue = (png_byte)png_ptr->background.blue;
  168167. for (i = 0; i < istop; i++)
  168168. {
  168169. if (png_ptr->trans[i] == 0)
  168170. {
  168171. palette[i] = back;
  168172. }
  168173. else if (png_ptr->trans[i] != 0xff)
  168174. {
  168175. png_composite(palette[i].red, palette[i].red,
  168176. png_ptr->trans[i], back.red);
  168177. png_composite(palette[i].green, palette[i].green,
  168178. png_ptr->trans[i], back.green);
  168179. png_composite(palette[i].blue, palette[i].blue,
  168180. png_ptr->trans[i], back.blue);
  168181. }
  168182. }
  168183. }
  168184. #endif /* PNG_READ_BACKGROUND_SUPPORTED */
  168185. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168186. if ((png_ptr->transformations & PNG_SHIFT) &&
  168187. (color_type == PNG_COLOR_TYPE_PALETTE))
  168188. {
  168189. png_uint_16 i;
  168190. png_uint_16 istop = png_ptr->num_palette;
  168191. int sr = 8 - png_ptr->sig_bit.red;
  168192. int sg = 8 - png_ptr->sig_bit.green;
  168193. int sb = 8 - png_ptr->sig_bit.blue;
  168194. if (sr < 0 || sr > 8)
  168195. sr = 0;
  168196. if (sg < 0 || sg > 8)
  168197. sg = 0;
  168198. if (sb < 0 || sb > 8)
  168199. sb = 0;
  168200. for (i = 0; i < istop; i++)
  168201. {
  168202. png_ptr->palette[i].red >>= sr;
  168203. png_ptr->palette[i].green >>= sg;
  168204. png_ptr->palette[i].blue >>= sb;
  168205. }
  168206. }
  168207. #endif /* PNG_READ_SHIFT_SUPPORTED */
  168208. }
  168209. #if !defined(PNG_READ_GAMMA_SUPPORTED) && !defined(PNG_READ_SHIFT_SUPPORTED) \
  168210. && !defined(PNG_READ_BACKGROUND_SUPPORTED)
  168211. if(png_ptr)
  168212. return;
  168213. #endif
  168214. }
  168215. void /* PRIVATE */
  168216. png_read_transform_info(png_structp png_ptr, png_infop info_ptr)
  168217. {
  168218. png_debug(1, "in png_read_transform_info\n");
  168219. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168220. if (png_ptr->transformations & PNG_EXPAND)
  168221. {
  168222. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168223. {
  168224. if (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND_tRNS))
  168225. info_ptr->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  168226. else
  168227. info_ptr->color_type = PNG_COLOR_TYPE_RGB;
  168228. info_ptr->bit_depth = 8;
  168229. info_ptr->num_trans = 0;
  168230. }
  168231. else
  168232. {
  168233. if (png_ptr->num_trans)
  168234. {
  168235. if (png_ptr->transformations & PNG_EXPAND_tRNS)
  168236. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168237. else
  168238. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168239. }
  168240. if (info_ptr->bit_depth < 8)
  168241. info_ptr->bit_depth = 8;
  168242. info_ptr->num_trans = 0;
  168243. }
  168244. }
  168245. #endif
  168246. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168247. if (png_ptr->transformations & PNG_BACKGROUND)
  168248. {
  168249. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168250. info_ptr->num_trans = 0;
  168251. info_ptr->background = png_ptr->background;
  168252. }
  168253. #endif
  168254. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168255. if (png_ptr->transformations & PNG_GAMMA)
  168256. {
  168257. #ifdef PNG_FLOATING_POINT_SUPPORTED
  168258. info_ptr->gamma = png_ptr->gamma;
  168259. #endif
  168260. #ifdef PNG_FIXED_POINT_SUPPORTED
  168261. info_ptr->int_gamma = png_ptr->int_gamma;
  168262. #endif
  168263. }
  168264. #endif
  168265. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168266. if ((png_ptr->transformations & PNG_16_TO_8) && (info_ptr->bit_depth == 16))
  168267. info_ptr->bit_depth = 8;
  168268. #endif
  168269. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168270. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  168271. info_ptr->color_type |= PNG_COLOR_MASK_COLOR;
  168272. #endif
  168273. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168274. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168275. info_ptr->color_type &= ~PNG_COLOR_MASK_COLOR;
  168276. #endif
  168277. #if defined(PNG_READ_DITHER_SUPPORTED)
  168278. if (png_ptr->transformations & PNG_DITHER)
  168279. {
  168280. if (((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168281. (info_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)) &&
  168282. png_ptr->palette_lookup && info_ptr->bit_depth == 8)
  168283. {
  168284. info_ptr->color_type = PNG_COLOR_TYPE_PALETTE;
  168285. }
  168286. }
  168287. #endif
  168288. #if defined(PNG_READ_PACK_SUPPORTED)
  168289. if ((png_ptr->transformations & PNG_PACK) && (info_ptr->bit_depth < 8))
  168290. info_ptr->bit_depth = 8;
  168291. #endif
  168292. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  168293. info_ptr->channels = 1;
  168294. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  168295. info_ptr->channels = 3;
  168296. else
  168297. info_ptr->channels = 1;
  168298. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168299. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168300. info_ptr->color_type &= ~PNG_COLOR_MASK_ALPHA;
  168301. #endif
  168302. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  168303. info_ptr->channels++;
  168304. #if defined(PNG_READ_FILLER_SUPPORTED)
  168305. if ((png_ptr->transformations & PNG_FILLER) &&
  168306. ((info_ptr->color_type == PNG_COLOR_TYPE_RGB) ||
  168307. (info_ptr->color_type == PNG_COLOR_TYPE_GRAY)))
  168308. {
  168309. info_ptr->channels++;
  168310. #if !defined(PNG_1_0_X)
  168311. if (png_ptr->transformations & PNG_ADD_ALPHA)
  168312. info_ptr->color_type |= PNG_COLOR_MASK_ALPHA;
  168313. #endif
  168314. }
  168315. #endif
  168316. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED) && \
  168317. defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168318. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  168319. {
  168320. if(info_ptr->bit_depth < png_ptr->user_transform_depth)
  168321. info_ptr->bit_depth = png_ptr->user_transform_depth;
  168322. if(info_ptr->channels < png_ptr->user_transform_channels)
  168323. info_ptr->channels = png_ptr->user_transform_channels;
  168324. }
  168325. #endif
  168326. info_ptr->pixel_depth = (png_byte)(info_ptr->channels *
  168327. info_ptr->bit_depth);
  168328. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,info_ptr->width);
  168329. #if !defined(PNG_READ_EXPAND_SUPPORTED)
  168330. if(png_ptr)
  168331. return;
  168332. #endif
  168333. }
  168334. void /* PRIVATE */
  168335. png_do_read_transformations(png_structp png_ptr)
  168336. {
  168337. png_debug(1, "in png_do_read_transformations\n");
  168338. if (png_ptr->row_buf == NULL)
  168339. {
  168340. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  168341. char msg[50];
  168342. png_snprintf2(msg, 50,
  168343. "NULL row buffer for row %ld, pass %d", png_ptr->row_number,
  168344. png_ptr->pass);
  168345. png_error(png_ptr, msg);
  168346. #else
  168347. png_error(png_ptr, "NULL row buffer");
  168348. #endif
  168349. }
  168350. #ifdef PNG_WARN_UNINITIALIZED_ROW
  168351. if (!(png_ptr->flags & PNG_FLAG_ROW_INIT))
  168352. #if (PNG_WARN_UNINITIALIZED_ROW==1)
  168353. png_error(png_ptr, "Uninitialized row");
  168354. #else
  168355. png_warning(png_ptr, "Uninitialized row");
  168356. #endif
  168357. #endif
  168358. #if defined(PNG_READ_EXPAND_SUPPORTED)
  168359. if (png_ptr->transformations & PNG_EXPAND)
  168360. {
  168361. if (png_ptr->row_info.color_type == PNG_COLOR_TYPE_PALETTE)
  168362. {
  168363. png_do_expand_palette(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168364. png_ptr->palette, png_ptr->trans, png_ptr->num_trans);
  168365. }
  168366. else
  168367. {
  168368. if (png_ptr->num_trans &&
  168369. (png_ptr->transformations & PNG_EXPAND_tRNS))
  168370. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168371. &(png_ptr->trans_values));
  168372. else
  168373. png_do_expand(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168374. NULL);
  168375. }
  168376. }
  168377. #endif
  168378. #if defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  168379. if (png_ptr->flags & PNG_FLAG_STRIP_ALPHA)
  168380. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168381. PNG_FLAG_FILLER_AFTER | (png_ptr->flags & PNG_FLAG_STRIP_ALPHA));
  168382. #endif
  168383. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  168384. if (png_ptr->transformations & PNG_RGB_TO_GRAY)
  168385. {
  168386. int rgb_error =
  168387. png_do_rgb_to_gray(png_ptr, &(png_ptr->row_info), png_ptr->row_buf + 1);
  168388. if(rgb_error)
  168389. {
  168390. png_ptr->rgb_to_gray_status=1;
  168391. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168392. PNG_RGB_TO_GRAY_WARN)
  168393. png_warning(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168394. if((png_ptr->transformations & PNG_RGB_TO_GRAY) ==
  168395. PNG_RGB_TO_GRAY_ERR)
  168396. png_error(png_ptr, "png_do_rgb_to_gray found nongray pixel");
  168397. }
  168398. }
  168399. #endif
  168400. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168401. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168402. !(png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168403. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168404. #endif
  168405. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168406. if ((png_ptr->transformations & PNG_BACKGROUND) &&
  168407. ((png_ptr->num_trans != 0 ) ||
  168408. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA)))
  168409. png_do_background(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168410. &(png_ptr->trans_values), &(png_ptr->background)
  168411. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168412. , &(png_ptr->background_1),
  168413. png_ptr->gamma_table, png_ptr->gamma_from_1,
  168414. png_ptr->gamma_to_1, png_ptr->gamma_16_table,
  168415. png_ptr->gamma_16_from_1, png_ptr->gamma_16_to_1,
  168416. png_ptr->gamma_shift
  168417. #endif
  168418. );
  168419. #endif
  168420. #if defined(PNG_READ_GAMMA_SUPPORTED)
  168421. if ((png_ptr->transformations & PNG_GAMMA) &&
  168422. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  168423. !((png_ptr->transformations & PNG_BACKGROUND) &&
  168424. ((png_ptr->num_trans != 0) ||
  168425. (png_ptr->color_type & PNG_COLOR_MASK_ALPHA))) &&
  168426. #endif
  168427. (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE))
  168428. png_do_gamma(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168429. png_ptr->gamma_table, png_ptr->gamma_16_table,
  168430. png_ptr->gamma_shift);
  168431. #endif
  168432. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168433. if (png_ptr->transformations & PNG_16_TO_8)
  168434. png_do_chop(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168435. #endif
  168436. #if defined(PNG_READ_DITHER_SUPPORTED)
  168437. if (png_ptr->transformations & PNG_DITHER)
  168438. {
  168439. png_do_dither((png_row_infop)&(png_ptr->row_info), png_ptr->row_buf + 1,
  168440. png_ptr->palette_lookup, png_ptr->dither_index);
  168441. if(png_ptr->row_info.rowbytes == (png_uint_32)0)
  168442. png_error(png_ptr, "png_do_dither returned rowbytes=0");
  168443. }
  168444. #endif
  168445. #if defined(PNG_READ_INVERT_SUPPORTED)
  168446. if (png_ptr->transformations & PNG_INVERT_MONO)
  168447. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168448. #endif
  168449. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168450. if (png_ptr->transformations & PNG_SHIFT)
  168451. png_do_unshift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168452. &(png_ptr->shift));
  168453. #endif
  168454. #if defined(PNG_READ_PACK_SUPPORTED)
  168455. if (png_ptr->transformations & PNG_PACK)
  168456. png_do_unpack(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168457. #endif
  168458. #if defined(PNG_READ_BGR_SUPPORTED)
  168459. if (png_ptr->transformations & PNG_BGR)
  168460. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168461. #endif
  168462. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  168463. if (png_ptr->transformations & PNG_PACKSWAP)
  168464. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168465. #endif
  168466. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  168467. if ((png_ptr->transformations & PNG_GRAY_TO_RGB) &&
  168468. (png_ptr->mode & PNG_BACKGROUND_IS_GRAY))
  168469. png_do_gray_to_rgb(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168470. #endif
  168471. #if defined(PNG_READ_FILLER_SUPPORTED)
  168472. if (png_ptr->transformations & PNG_FILLER)
  168473. png_do_read_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  168474. (png_uint_32)png_ptr->filler, png_ptr->flags);
  168475. #endif
  168476. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168477. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  168478. png_do_read_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168479. #endif
  168480. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168481. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  168482. png_do_read_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168483. #endif
  168484. #if defined(PNG_READ_SWAP_SUPPORTED)
  168485. if (png_ptr->transformations & PNG_SWAP_BYTES)
  168486. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  168487. #endif
  168488. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED)
  168489. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  168490. {
  168491. if(png_ptr->read_user_transform_fn != NULL)
  168492. (*(png_ptr->read_user_transform_fn)) /* user read transform function */
  168493. (png_ptr, /* png_ptr */
  168494. &(png_ptr->row_info), /* row_info: */
  168495. png_ptr->row_buf + 1); /* start of pixel data for row */
  168496. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  168497. if(png_ptr->user_transform_depth)
  168498. png_ptr->row_info.bit_depth = png_ptr->user_transform_depth;
  168499. if(png_ptr->user_transform_channels)
  168500. png_ptr->row_info.channels = png_ptr->user_transform_channels;
  168501. #endif
  168502. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  168503. png_ptr->row_info.channels);
  168504. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  168505. png_ptr->row_info.width);
  168506. }
  168507. #endif
  168508. }
  168509. #if defined(PNG_READ_PACK_SUPPORTED)
  168510. void /* PRIVATE */
  168511. png_do_unpack(png_row_infop row_info, png_bytep row)
  168512. {
  168513. png_debug(1, "in png_do_unpack\n");
  168514. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168515. if (row != NULL && row_info != NULL && row_info->bit_depth < 8)
  168516. #else
  168517. if (row_info->bit_depth < 8)
  168518. #endif
  168519. {
  168520. png_uint_32 i;
  168521. png_uint_32 row_width=row_info->width;
  168522. switch (row_info->bit_depth)
  168523. {
  168524. case 1:
  168525. {
  168526. png_bytep sp = row + (png_size_t)((row_width - 1) >> 3);
  168527. png_bytep dp = row + (png_size_t)row_width - 1;
  168528. png_uint_32 shift = 7 - (int)((row_width + 7) & 0x07);
  168529. for (i = 0; i < row_width; i++)
  168530. {
  168531. *dp = (png_byte)((*sp >> shift) & 0x01);
  168532. if (shift == 7)
  168533. {
  168534. shift = 0;
  168535. sp--;
  168536. }
  168537. else
  168538. shift++;
  168539. dp--;
  168540. }
  168541. break;
  168542. }
  168543. case 2:
  168544. {
  168545. png_bytep sp = row + (png_size_t)((row_width - 1) >> 2);
  168546. png_bytep dp = row + (png_size_t)row_width - 1;
  168547. png_uint_32 shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  168548. for (i = 0; i < row_width; i++)
  168549. {
  168550. *dp = (png_byte)((*sp >> shift) & 0x03);
  168551. if (shift == 6)
  168552. {
  168553. shift = 0;
  168554. sp--;
  168555. }
  168556. else
  168557. shift += 2;
  168558. dp--;
  168559. }
  168560. break;
  168561. }
  168562. case 4:
  168563. {
  168564. png_bytep sp = row + (png_size_t)((row_width - 1) >> 1);
  168565. png_bytep dp = row + (png_size_t)row_width - 1;
  168566. png_uint_32 shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  168567. for (i = 0; i < row_width; i++)
  168568. {
  168569. *dp = (png_byte)((*sp >> shift) & 0x0f);
  168570. if (shift == 4)
  168571. {
  168572. shift = 0;
  168573. sp--;
  168574. }
  168575. else
  168576. shift = 4;
  168577. dp--;
  168578. }
  168579. break;
  168580. }
  168581. }
  168582. row_info->bit_depth = 8;
  168583. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168584. row_info->rowbytes = row_width * row_info->channels;
  168585. }
  168586. }
  168587. #endif
  168588. #if defined(PNG_READ_SHIFT_SUPPORTED)
  168589. void /* PRIVATE */
  168590. png_do_unshift(png_row_infop row_info, png_bytep row, png_color_8p sig_bits)
  168591. {
  168592. png_debug(1, "in png_do_unshift\n");
  168593. if (
  168594. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168595. row != NULL && row_info != NULL && sig_bits != NULL &&
  168596. #endif
  168597. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  168598. {
  168599. int shift[4];
  168600. int channels = 0;
  168601. int c;
  168602. png_uint_16 value = 0;
  168603. png_uint_32 row_width = row_info->width;
  168604. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  168605. {
  168606. shift[channels++] = row_info->bit_depth - sig_bits->red;
  168607. shift[channels++] = row_info->bit_depth - sig_bits->green;
  168608. shift[channels++] = row_info->bit_depth - sig_bits->blue;
  168609. }
  168610. else
  168611. {
  168612. shift[channels++] = row_info->bit_depth - sig_bits->gray;
  168613. }
  168614. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  168615. {
  168616. shift[channels++] = row_info->bit_depth - sig_bits->alpha;
  168617. }
  168618. for (c = 0; c < channels; c++)
  168619. {
  168620. if (shift[c] <= 0)
  168621. shift[c] = 0;
  168622. else
  168623. value = 1;
  168624. }
  168625. if (!value)
  168626. return;
  168627. switch (row_info->bit_depth)
  168628. {
  168629. case 2:
  168630. {
  168631. png_bytep bp;
  168632. png_uint_32 i;
  168633. png_uint_32 istop = row_info->rowbytes;
  168634. for (bp = row, i = 0; i < istop; i++)
  168635. {
  168636. *bp >>= 1;
  168637. *bp++ &= 0x55;
  168638. }
  168639. break;
  168640. }
  168641. case 4:
  168642. {
  168643. png_bytep bp = row;
  168644. png_uint_32 i;
  168645. png_uint_32 istop = row_info->rowbytes;
  168646. png_byte mask = (png_byte)((((int)0xf0 >> shift[0]) & (int)0xf0) |
  168647. (png_byte)((int)0xf >> shift[0]));
  168648. for (i = 0; i < istop; i++)
  168649. {
  168650. *bp >>= shift[0];
  168651. *bp++ &= mask;
  168652. }
  168653. break;
  168654. }
  168655. case 8:
  168656. {
  168657. png_bytep bp = row;
  168658. png_uint_32 i;
  168659. png_uint_32 istop = row_width * channels;
  168660. for (i = 0; i < istop; i++)
  168661. {
  168662. *bp++ >>= shift[i%channels];
  168663. }
  168664. break;
  168665. }
  168666. case 16:
  168667. {
  168668. png_bytep bp = row;
  168669. png_uint_32 i;
  168670. png_uint_32 istop = channels * row_width;
  168671. for (i = 0; i < istop; i++)
  168672. {
  168673. value = (png_uint_16)((*bp << 8) + *(bp + 1));
  168674. value >>= shift[i%channels];
  168675. *bp++ = (png_byte)(value >> 8);
  168676. *bp++ = (png_byte)(value & 0xff);
  168677. }
  168678. break;
  168679. }
  168680. }
  168681. }
  168682. }
  168683. #endif
  168684. #if defined(PNG_READ_16_TO_8_SUPPORTED)
  168685. void /* PRIVATE */
  168686. png_do_chop(png_row_infop row_info, png_bytep row)
  168687. {
  168688. png_debug(1, "in png_do_chop\n");
  168689. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168690. if (row != NULL && row_info != NULL && row_info->bit_depth == 16)
  168691. #else
  168692. if (row_info->bit_depth == 16)
  168693. #endif
  168694. {
  168695. png_bytep sp = row;
  168696. png_bytep dp = row;
  168697. png_uint_32 i;
  168698. png_uint_32 istop = row_info->width * row_info->channels;
  168699. for (i = 0; i<istop; i++, sp += 2, dp++)
  168700. {
  168701. #if defined(PNG_READ_16_TO_8_ACCURATE_SCALE_SUPPORTED)
  168702. *dp = *sp + ((((int)(*(sp + 1)) - *sp) > 128) ? 1 : 0);
  168703. #else
  168704. *dp = *sp;
  168705. #endif
  168706. }
  168707. row_info->bit_depth = 8;
  168708. row_info->pixel_depth = (png_byte)(8 * row_info->channels);
  168709. row_info->rowbytes = row_info->width * row_info->channels;
  168710. }
  168711. }
  168712. #endif
  168713. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED)
  168714. void /* PRIVATE */
  168715. png_do_read_swap_alpha(png_row_infop row_info, png_bytep row)
  168716. {
  168717. png_debug(1, "in png_do_read_swap_alpha\n");
  168718. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168719. if (row != NULL && row_info != NULL)
  168720. #endif
  168721. {
  168722. png_uint_32 row_width = row_info->width;
  168723. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168724. {
  168725. if (row_info->bit_depth == 8)
  168726. {
  168727. png_bytep sp = row + row_info->rowbytes;
  168728. png_bytep dp = sp;
  168729. png_byte save;
  168730. png_uint_32 i;
  168731. for (i = 0; i < row_width; i++)
  168732. {
  168733. save = *(--sp);
  168734. *(--dp) = *(--sp);
  168735. *(--dp) = *(--sp);
  168736. *(--dp) = *(--sp);
  168737. *(--dp) = save;
  168738. }
  168739. }
  168740. else
  168741. {
  168742. png_bytep sp = row + row_info->rowbytes;
  168743. png_bytep dp = sp;
  168744. png_byte save[2];
  168745. png_uint_32 i;
  168746. for (i = 0; i < row_width; i++)
  168747. {
  168748. save[0] = *(--sp);
  168749. save[1] = *(--sp);
  168750. *(--dp) = *(--sp);
  168751. *(--dp) = *(--sp);
  168752. *(--dp) = *(--sp);
  168753. *(--dp) = *(--sp);
  168754. *(--dp) = *(--sp);
  168755. *(--dp) = *(--sp);
  168756. *(--dp) = save[0];
  168757. *(--dp) = save[1];
  168758. }
  168759. }
  168760. }
  168761. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168762. {
  168763. if (row_info->bit_depth == 8)
  168764. {
  168765. png_bytep sp = row + row_info->rowbytes;
  168766. png_bytep dp = sp;
  168767. png_byte save;
  168768. png_uint_32 i;
  168769. for (i = 0; i < row_width; i++)
  168770. {
  168771. save = *(--sp);
  168772. *(--dp) = *(--sp);
  168773. *(--dp) = save;
  168774. }
  168775. }
  168776. else
  168777. {
  168778. png_bytep sp = row + row_info->rowbytes;
  168779. png_bytep dp = sp;
  168780. png_byte save[2];
  168781. png_uint_32 i;
  168782. for (i = 0; i < row_width; i++)
  168783. {
  168784. save[0] = *(--sp);
  168785. save[1] = *(--sp);
  168786. *(--dp) = *(--sp);
  168787. *(--dp) = *(--sp);
  168788. *(--dp) = save[0];
  168789. *(--dp) = save[1];
  168790. }
  168791. }
  168792. }
  168793. }
  168794. }
  168795. #endif
  168796. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED)
  168797. void /* PRIVATE */
  168798. png_do_read_invert_alpha(png_row_infop row_info, png_bytep row)
  168799. {
  168800. png_debug(1, "in png_do_read_invert_alpha\n");
  168801. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168802. if (row != NULL && row_info != NULL)
  168803. #endif
  168804. {
  168805. png_uint_32 row_width = row_info->width;
  168806. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  168807. {
  168808. if (row_info->bit_depth == 8)
  168809. {
  168810. png_bytep sp = row + row_info->rowbytes;
  168811. png_bytep dp = sp;
  168812. png_uint_32 i;
  168813. for (i = 0; i < row_width; i++)
  168814. {
  168815. *(--dp) = (png_byte)(255 - *(--sp));
  168816. sp-=3;
  168817. dp=sp;
  168818. }
  168819. }
  168820. else
  168821. {
  168822. png_bytep sp = row + row_info->rowbytes;
  168823. png_bytep dp = sp;
  168824. png_uint_32 i;
  168825. for (i = 0; i < row_width; i++)
  168826. {
  168827. *(--dp) = (png_byte)(255 - *(--sp));
  168828. *(--dp) = (png_byte)(255 - *(--sp));
  168829. sp-=6;
  168830. dp=sp;
  168831. }
  168832. }
  168833. }
  168834. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  168835. {
  168836. if (row_info->bit_depth == 8)
  168837. {
  168838. png_bytep sp = row + row_info->rowbytes;
  168839. png_bytep dp = sp;
  168840. png_uint_32 i;
  168841. for (i = 0; i < row_width; i++)
  168842. {
  168843. *(--dp) = (png_byte)(255 - *(--sp));
  168844. *(--dp) = *(--sp);
  168845. }
  168846. }
  168847. else
  168848. {
  168849. png_bytep sp = row + row_info->rowbytes;
  168850. png_bytep dp = sp;
  168851. png_uint_32 i;
  168852. for (i = 0; i < row_width; i++)
  168853. {
  168854. *(--dp) = (png_byte)(255 - *(--sp));
  168855. *(--dp) = (png_byte)(255 - *(--sp));
  168856. sp-=2;
  168857. dp=sp;
  168858. }
  168859. }
  168860. }
  168861. }
  168862. }
  168863. #endif
  168864. #if defined(PNG_READ_FILLER_SUPPORTED)
  168865. void /* PRIVATE */
  168866. png_do_read_filler(png_row_infop row_info, png_bytep row,
  168867. png_uint_32 filler, png_uint_32 flags)
  168868. {
  168869. png_uint_32 i;
  168870. png_uint_32 row_width = row_info->width;
  168871. png_byte hi_filler = (png_byte)((filler>>8) & 0xff);
  168872. png_byte lo_filler = (png_byte)(filler & 0xff);
  168873. png_debug(1, "in png_do_read_filler\n");
  168874. if (
  168875. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  168876. row != NULL && row_info != NULL &&
  168877. #endif
  168878. row_info->color_type == PNG_COLOR_TYPE_GRAY)
  168879. {
  168880. if(row_info->bit_depth == 8)
  168881. {
  168882. if (flags & PNG_FLAG_FILLER_AFTER)
  168883. {
  168884. png_bytep sp = row + (png_size_t)row_width;
  168885. png_bytep dp = sp + (png_size_t)row_width;
  168886. for (i = 1; i < row_width; i++)
  168887. {
  168888. *(--dp) = lo_filler;
  168889. *(--dp) = *(--sp);
  168890. }
  168891. *(--dp) = lo_filler;
  168892. row_info->channels = 2;
  168893. row_info->pixel_depth = 16;
  168894. row_info->rowbytes = row_width * 2;
  168895. }
  168896. else
  168897. {
  168898. png_bytep sp = row + (png_size_t)row_width;
  168899. png_bytep dp = sp + (png_size_t)row_width;
  168900. for (i = 0; i < row_width; i++)
  168901. {
  168902. *(--dp) = *(--sp);
  168903. *(--dp) = lo_filler;
  168904. }
  168905. row_info->channels = 2;
  168906. row_info->pixel_depth = 16;
  168907. row_info->rowbytes = row_width * 2;
  168908. }
  168909. }
  168910. else if(row_info->bit_depth == 16)
  168911. {
  168912. if (flags & PNG_FLAG_FILLER_AFTER)
  168913. {
  168914. png_bytep sp = row + (png_size_t)row_width * 2;
  168915. png_bytep dp = sp + (png_size_t)row_width * 2;
  168916. for (i = 1; i < row_width; i++)
  168917. {
  168918. *(--dp) = hi_filler;
  168919. *(--dp) = lo_filler;
  168920. *(--dp) = *(--sp);
  168921. *(--dp) = *(--sp);
  168922. }
  168923. *(--dp) = hi_filler;
  168924. *(--dp) = lo_filler;
  168925. row_info->channels = 2;
  168926. row_info->pixel_depth = 32;
  168927. row_info->rowbytes = row_width * 4;
  168928. }
  168929. else
  168930. {
  168931. png_bytep sp = row + (png_size_t)row_width * 2;
  168932. png_bytep dp = sp + (png_size_t)row_width * 2;
  168933. for (i = 0; i < row_width; i++)
  168934. {
  168935. *(--dp) = *(--sp);
  168936. *(--dp) = *(--sp);
  168937. *(--dp) = hi_filler;
  168938. *(--dp) = lo_filler;
  168939. }
  168940. row_info->channels = 2;
  168941. row_info->pixel_depth = 32;
  168942. row_info->rowbytes = row_width * 4;
  168943. }
  168944. }
  168945. } /* COLOR_TYPE == GRAY */
  168946. else if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  168947. {
  168948. if(row_info->bit_depth == 8)
  168949. {
  168950. if (flags & PNG_FLAG_FILLER_AFTER)
  168951. {
  168952. png_bytep sp = row + (png_size_t)row_width * 3;
  168953. png_bytep dp = sp + (png_size_t)row_width;
  168954. for (i = 1; i < row_width; i++)
  168955. {
  168956. *(--dp) = lo_filler;
  168957. *(--dp) = *(--sp);
  168958. *(--dp) = *(--sp);
  168959. *(--dp) = *(--sp);
  168960. }
  168961. *(--dp) = lo_filler;
  168962. row_info->channels = 4;
  168963. row_info->pixel_depth = 32;
  168964. row_info->rowbytes = row_width * 4;
  168965. }
  168966. else
  168967. {
  168968. png_bytep sp = row + (png_size_t)row_width * 3;
  168969. png_bytep dp = sp + (png_size_t)row_width;
  168970. for (i = 0; i < row_width; i++)
  168971. {
  168972. *(--dp) = *(--sp);
  168973. *(--dp) = *(--sp);
  168974. *(--dp) = *(--sp);
  168975. *(--dp) = lo_filler;
  168976. }
  168977. row_info->channels = 4;
  168978. row_info->pixel_depth = 32;
  168979. row_info->rowbytes = row_width * 4;
  168980. }
  168981. }
  168982. else if(row_info->bit_depth == 16)
  168983. {
  168984. if (flags & PNG_FLAG_FILLER_AFTER)
  168985. {
  168986. png_bytep sp = row + (png_size_t)row_width * 6;
  168987. png_bytep dp = sp + (png_size_t)row_width * 2;
  168988. for (i = 1; i < row_width; i++)
  168989. {
  168990. *(--dp) = hi_filler;
  168991. *(--dp) = lo_filler;
  168992. *(--dp) = *(--sp);
  168993. *(--dp) = *(--sp);
  168994. *(--dp) = *(--sp);
  168995. *(--dp) = *(--sp);
  168996. *(--dp) = *(--sp);
  168997. *(--dp) = *(--sp);
  168998. }
  168999. *(--dp) = hi_filler;
  169000. *(--dp) = lo_filler;
  169001. row_info->channels = 4;
  169002. row_info->pixel_depth = 64;
  169003. row_info->rowbytes = row_width * 8;
  169004. }
  169005. else
  169006. {
  169007. png_bytep sp = row + (png_size_t)row_width * 6;
  169008. png_bytep dp = sp + (png_size_t)row_width * 2;
  169009. for (i = 0; i < row_width; i++)
  169010. {
  169011. *(--dp) = *(--sp);
  169012. *(--dp) = *(--sp);
  169013. *(--dp) = *(--sp);
  169014. *(--dp) = *(--sp);
  169015. *(--dp) = *(--sp);
  169016. *(--dp) = *(--sp);
  169017. *(--dp) = hi_filler;
  169018. *(--dp) = lo_filler;
  169019. }
  169020. row_info->channels = 4;
  169021. row_info->pixel_depth = 64;
  169022. row_info->rowbytes = row_width * 8;
  169023. }
  169024. }
  169025. } /* COLOR_TYPE == RGB */
  169026. }
  169027. #endif
  169028. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  169029. void /* PRIVATE */
  169030. png_do_gray_to_rgb(png_row_infop row_info, png_bytep row)
  169031. {
  169032. png_uint_32 i;
  169033. png_uint_32 row_width = row_info->width;
  169034. png_debug(1, "in png_do_gray_to_rgb\n");
  169035. if (row_info->bit_depth >= 8 &&
  169036. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169037. row != NULL && row_info != NULL &&
  169038. #endif
  169039. !(row_info->color_type & PNG_COLOR_MASK_COLOR))
  169040. {
  169041. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  169042. {
  169043. if (row_info->bit_depth == 8)
  169044. {
  169045. png_bytep sp = row + (png_size_t)row_width - 1;
  169046. png_bytep dp = sp + (png_size_t)row_width * 2;
  169047. for (i = 0; i < row_width; i++)
  169048. {
  169049. *(dp--) = *sp;
  169050. *(dp--) = *sp;
  169051. *(dp--) = *(sp--);
  169052. }
  169053. }
  169054. else
  169055. {
  169056. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  169057. png_bytep dp = sp + (png_size_t)row_width * 4;
  169058. for (i = 0; i < row_width; i++)
  169059. {
  169060. *(dp--) = *sp;
  169061. *(dp--) = *(sp - 1);
  169062. *(dp--) = *sp;
  169063. *(dp--) = *(sp - 1);
  169064. *(dp--) = *(sp--);
  169065. *(dp--) = *(sp--);
  169066. }
  169067. }
  169068. }
  169069. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  169070. {
  169071. if (row_info->bit_depth == 8)
  169072. {
  169073. png_bytep sp = row + (png_size_t)row_width * 2 - 1;
  169074. png_bytep dp = sp + (png_size_t)row_width * 2;
  169075. for (i = 0; i < row_width; i++)
  169076. {
  169077. *(dp--) = *(sp--);
  169078. *(dp--) = *sp;
  169079. *(dp--) = *sp;
  169080. *(dp--) = *(sp--);
  169081. }
  169082. }
  169083. else
  169084. {
  169085. png_bytep sp = row + (png_size_t)row_width * 4 - 1;
  169086. png_bytep dp = sp + (png_size_t)row_width * 4;
  169087. for (i = 0; i < row_width; i++)
  169088. {
  169089. *(dp--) = *(sp--);
  169090. *(dp--) = *(sp--);
  169091. *(dp--) = *sp;
  169092. *(dp--) = *(sp - 1);
  169093. *(dp--) = *sp;
  169094. *(dp--) = *(sp - 1);
  169095. *(dp--) = *(sp--);
  169096. *(dp--) = *(sp--);
  169097. }
  169098. }
  169099. }
  169100. row_info->channels += (png_byte)2;
  169101. row_info->color_type |= PNG_COLOR_MASK_COLOR;
  169102. row_info->pixel_depth = (png_byte)(row_info->channels *
  169103. row_info->bit_depth);
  169104. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169105. }
  169106. }
  169107. #endif
  169108. #if defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  169109. int /* PRIVATE */
  169110. png_do_rgb_to_gray(png_structp png_ptr, png_row_infop row_info, png_bytep row)
  169111. {
  169112. png_uint_32 i;
  169113. png_uint_32 row_width = row_info->width;
  169114. int rgb_error = 0;
  169115. png_debug(1, "in png_do_rgb_to_gray\n");
  169116. if (
  169117. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169118. row != NULL && row_info != NULL &&
  169119. #endif
  169120. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  169121. {
  169122. png_uint_32 rc = png_ptr->rgb_to_gray_red_coeff;
  169123. png_uint_32 gc = png_ptr->rgb_to_gray_green_coeff;
  169124. png_uint_32 bc = png_ptr->rgb_to_gray_blue_coeff;
  169125. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  169126. {
  169127. if (row_info->bit_depth == 8)
  169128. {
  169129. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169130. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  169131. {
  169132. png_bytep sp = row;
  169133. png_bytep dp = row;
  169134. for (i = 0; i < row_width; i++)
  169135. {
  169136. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  169137. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  169138. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  169139. if(red != green || red != blue)
  169140. {
  169141. rgb_error |= 1;
  169142. *(dp++) = png_ptr->gamma_from_1[
  169143. (rc*red+gc*green+bc*blue)>>15];
  169144. }
  169145. else
  169146. *(dp++) = *(sp-1);
  169147. }
  169148. }
  169149. else
  169150. #endif
  169151. {
  169152. png_bytep sp = row;
  169153. png_bytep dp = row;
  169154. for (i = 0; i < row_width; i++)
  169155. {
  169156. png_byte red = *(sp++);
  169157. png_byte green = *(sp++);
  169158. png_byte blue = *(sp++);
  169159. if(red != green || red != blue)
  169160. {
  169161. rgb_error |= 1;
  169162. *(dp++) = (png_byte)((rc*red+gc*green+bc*blue)>>15);
  169163. }
  169164. else
  169165. *(dp++) = *(sp-1);
  169166. }
  169167. }
  169168. }
  169169. else /* RGB bit_depth == 16 */
  169170. {
  169171. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169172. if (png_ptr->gamma_16_to_1 != NULL &&
  169173. png_ptr->gamma_16_from_1 != NULL)
  169174. {
  169175. png_bytep sp = row;
  169176. png_bytep dp = row;
  169177. for (i = 0; i < row_width; i++)
  169178. {
  169179. png_uint_16 red, green, blue, w;
  169180. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169181. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169182. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169183. if(red == green && red == blue)
  169184. w = red;
  169185. else
  169186. {
  169187. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  169188. png_ptr->gamma_shift][red>>8];
  169189. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  169190. png_ptr->gamma_shift][green>>8];
  169191. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  169192. png_ptr->gamma_shift][blue>>8];
  169193. png_uint_16 gray16 = (png_uint_16)((rc*red_1 + gc*green_1
  169194. + bc*blue_1)>>15);
  169195. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  169196. png_ptr->gamma_shift][gray16 >> 8];
  169197. rgb_error |= 1;
  169198. }
  169199. *(dp++) = (png_byte)((w>>8) & 0xff);
  169200. *(dp++) = (png_byte)(w & 0xff);
  169201. }
  169202. }
  169203. else
  169204. #endif
  169205. {
  169206. png_bytep sp = row;
  169207. png_bytep dp = row;
  169208. for (i = 0; i < row_width; i++)
  169209. {
  169210. png_uint_16 red, green, blue, gray16;
  169211. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169212. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169213. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169214. if(red != green || red != blue)
  169215. rgb_error |= 1;
  169216. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169217. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169218. *(dp++) = (png_byte)(gray16 & 0xff);
  169219. }
  169220. }
  169221. }
  169222. }
  169223. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  169224. {
  169225. if (row_info->bit_depth == 8)
  169226. {
  169227. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169228. if (png_ptr->gamma_from_1 != NULL && png_ptr->gamma_to_1 != NULL)
  169229. {
  169230. png_bytep sp = row;
  169231. png_bytep dp = row;
  169232. for (i = 0; i < row_width; i++)
  169233. {
  169234. png_byte red = png_ptr->gamma_to_1[*(sp++)];
  169235. png_byte green = png_ptr->gamma_to_1[*(sp++)];
  169236. png_byte blue = png_ptr->gamma_to_1[*(sp++)];
  169237. if(red != green || red != blue)
  169238. rgb_error |= 1;
  169239. *(dp++) = png_ptr->gamma_from_1
  169240. [(rc*red + gc*green + bc*blue)>>15];
  169241. *(dp++) = *(sp++); /* alpha */
  169242. }
  169243. }
  169244. else
  169245. #endif
  169246. {
  169247. png_bytep sp = row;
  169248. png_bytep dp = row;
  169249. for (i = 0; i < row_width; i++)
  169250. {
  169251. png_byte red = *(sp++);
  169252. png_byte green = *(sp++);
  169253. png_byte blue = *(sp++);
  169254. if(red != green || red != blue)
  169255. rgb_error |= 1;
  169256. *(dp++) = (png_byte)((rc*red + gc*green + bc*blue)>>15);
  169257. *(dp++) = *(sp++); /* alpha */
  169258. }
  169259. }
  169260. }
  169261. else /* RGBA bit_depth == 16 */
  169262. {
  169263. #if defined(PNG_READ_GAMMA_SUPPORTED) || defined(PNG_READ_BACKGROUND_SUPPORTED)
  169264. if (png_ptr->gamma_16_to_1 != NULL &&
  169265. png_ptr->gamma_16_from_1 != NULL)
  169266. {
  169267. png_bytep sp = row;
  169268. png_bytep dp = row;
  169269. for (i = 0; i < row_width; i++)
  169270. {
  169271. png_uint_16 red, green, blue, w;
  169272. red = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169273. green = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169274. blue = (png_uint_16)(((*(sp))<<8) | *(sp+1)); sp+=2;
  169275. if(red == green && red == blue)
  169276. w = red;
  169277. else
  169278. {
  169279. png_uint_16 red_1 = png_ptr->gamma_16_to_1[(red&0xff) >>
  169280. png_ptr->gamma_shift][red>>8];
  169281. png_uint_16 green_1 = png_ptr->gamma_16_to_1[(green&0xff) >>
  169282. png_ptr->gamma_shift][green>>8];
  169283. png_uint_16 blue_1 = png_ptr->gamma_16_to_1[(blue&0xff) >>
  169284. png_ptr->gamma_shift][blue>>8];
  169285. png_uint_16 gray16 = (png_uint_16)((rc * red_1
  169286. + gc * green_1 + bc * blue_1)>>15);
  169287. w = png_ptr->gamma_16_from_1[(gray16&0xff) >>
  169288. png_ptr->gamma_shift][gray16 >> 8];
  169289. rgb_error |= 1;
  169290. }
  169291. *(dp++) = (png_byte)((w>>8) & 0xff);
  169292. *(dp++) = (png_byte)(w & 0xff);
  169293. *(dp++) = *(sp++); /* alpha */
  169294. *(dp++) = *(sp++);
  169295. }
  169296. }
  169297. else
  169298. #endif
  169299. {
  169300. png_bytep sp = row;
  169301. png_bytep dp = row;
  169302. for (i = 0; i < row_width; i++)
  169303. {
  169304. png_uint_16 red, green, blue, gray16;
  169305. red = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169306. green = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169307. blue = (png_uint_16)((*(sp)<<8) | *(sp+1)); sp+=2;
  169308. if(red != green || red != blue)
  169309. rgb_error |= 1;
  169310. gray16 = (png_uint_16)((rc*red + gc*green + bc*blue)>>15);
  169311. *(dp++) = (png_byte)((gray16>>8) & 0xff);
  169312. *(dp++) = (png_byte)(gray16 & 0xff);
  169313. *(dp++) = *(sp++); /* alpha */
  169314. *(dp++) = *(sp++);
  169315. }
  169316. }
  169317. }
  169318. }
  169319. row_info->channels -= (png_byte)2;
  169320. row_info->color_type &= ~PNG_COLOR_MASK_COLOR;
  169321. row_info->pixel_depth = (png_byte)(row_info->channels *
  169322. row_info->bit_depth);
  169323. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  169324. }
  169325. return rgb_error;
  169326. }
  169327. #endif
  169328. void PNGAPI
  169329. png_build_grayscale_palette(int bit_depth, png_colorp palette)
  169330. {
  169331. int num_palette;
  169332. int color_inc;
  169333. int i;
  169334. int v;
  169335. png_debug(1, "in png_do_build_grayscale_palette\n");
  169336. if (palette == NULL)
  169337. return;
  169338. switch (bit_depth)
  169339. {
  169340. case 1:
  169341. num_palette = 2;
  169342. color_inc = 0xff;
  169343. break;
  169344. case 2:
  169345. num_palette = 4;
  169346. color_inc = 0x55;
  169347. break;
  169348. case 4:
  169349. num_palette = 16;
  169350. color_inc = 0x11;
  169351. break;
  169352. case 8:
  169353. num_palette = 256;
  169354. color_inc = 1;
  169355. break;
  169356. default:
  169357. num_palette = 0;
  169358. color_inc = 0;
  169359. break;
  169360. }
  169361. for (i = 0, v = 0; i < num_palette; i++, v += color_inc)
  169362. {
  169363. palette[i].red = (png_byte)v;
  169364. palette[i].green = (png_byte)v;
  169365. palette[i].blue = (png_byte)v;
  169366. }
  169367. }
  169368. #if defined(PNG_READ_DITHER_SUPPORTED) && defined(PNG_CORRECT_PALETTE_SUPPORTED)
  169369. void /* PRIVATE */
  169370. png_correct_palette(png_structp png_ptr, png_colorp palette,
  169371. int num_palette)
  169372. {
  169373. png_debug(1, "in png_correct_palette\n");
  169374. #if defined(PNG_READ_BACKGROUND_SUPPORTED) && \
  169375. defined(PNG_READ_GAMMA_SUPPORTED) && defined(PNG_FLOATING_POINT_SUPPORTED)
  169376. if (png_ptr->transformations & (PNG_GAMMA | PNG_BACKGROUND))
  169377. {
  169378. png_color back, back_1;
  169379. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_FILE)
  169380. {
  169381. back.red = png_ptr->gamma_table[png_ptr->background.red];
  169382. back.green = png_ptr->gamma_table[png_ptr->background.green];
  169383. back.blue = png_ptr->gamma_table[png_ptr->background.blue];
  169384. back_1.red = png_ptr->gamma_to_1[png_ptr->background.red];
  169385. back_1.green = png_ptr->gamma_to_1[png_ptr->background.green];
  169386. back_1.blue = png_ptr->gamma_to_1[png_ptr->background.blue];
  169387. }
  169388. else
  169389. {
  169390. double g;
  169391. g = 1.0 / (png_ptr->background_gamma * png_ptr->screen_gamma);
  169392. if (png_ptr->background_gamma_type == PNG_BACKGROUND_GAMMA_SCREEN ||
  169393. fabs(g - 1.0) < PNG_GAMMA_THRESHOLD)
  169394. {
  169395. back.red = png_ptr->background.red;
  169396. back.green = png_ptr->background.green;
  169397. back.blue = png_ptr->background.blue;
  169398. }
  169399. else
  169400. {
  169401. back.red =
  169402. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169403. 255.0 + 0.5);
  169404. back.green =
  169405. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169406. 255.0 + 0.5);
  169407. back.blue =
  169408. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169409. 255.0 + 0.5);
  169410. }
  169411. g = 1.0 / png_ptr->background_gamma;
  169412. back_1.red =
  169413. (png_byte)(pow((double)png_ptr->background.red/255, g) *
  169414. 255.0 + 0.5);
  169415. back_1.green =
  169416. (png_byte)(pow((double)png_ptr->background.green/255, g) *
  169417. 255.0 + 0.5);
  169418. back_1.blue =
  169419. (png_byte)(pow((double)png_ptr->background.blue/255, g) *
  169420. 255.0 + 0.5);
  169421. }
  169422. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169423. {
  169424. png_uint_32 i;
  169425. for (i = 0; i < (png_uint_32)num_palette; i++)
  169426. {
  169427. if (i < png_ptr->num_trans && png_ptr->trans[i] == 0)
  169428. {
  169429. palette[i] = back;
  169430. }
  169431. else if (i < png_ptr->num_trans && png_ptr->trans[i] != 0xff)
  169432. {
  169433. png_byte v, w;
  169434. v = png_ptr->gamma_to_1[png_ptr->palette[i].red];
  169435. png_composite(w, v, png_ptr->trans[i], back_1.red);
  169436. palette[i].red = png_ptr->gamma_from_1[w];
  169437. v = png_ptr->gamma_to_1[png_ptr->palette[i].green];
  169438. png_composite(w, v, png_ptr->trans[i], back_1.green);
  169439. palette[i].green = png_ptr->gamma_from_1[w];
  169440. v = png_ptr->gamma_to_1[png_ptr->palette[i].blue];
  169441. png_composite(w, v, png_ptr->trans[i], back_1.blue);
  169442. palette[i].blue = png_ptr->gamma_from_1[w];
  169443. }
  169444. else
  169445. {
  169446. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169447. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169448. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169449. }
  169450. }
  169451. }
  169452. else
  169453. {
  169454. int i;
  169455. for (i = 0; i < num_palette; i++)
  169456. {
  169457. if (palette[i].red == (png_byte)png_ptr->trans_values.gray)
  169458. {
  169459. palette[i] = back;
  169460. }
  169461. else
  169462. {
  169463. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169464. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169465. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169466. }
  169467. }
  169468. }
  169469. }
  169470. else
  169471. #endif
  169472. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169473. if (png_ptr->transformations & PNG_GAMMA)
  169474. {
  169475. int i;
  169476. for (i = 0; i < num_palette; i++)
  169477. {
  169478. palette[i].red = png_ptr->gamma_table[palette[i].red];
  169479. palette[i].green = png_ptr->gamma_table[palette[i].green];
  169480. palette[i].blue = png_ptr->gamma_table[palette[i].blue];
  169481. }
  169482. }
  169483. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169484. else
  169485. #endif
  169486. #endif
  169487. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169488. if (png_ptr->transformations & PNG_BACKGROUND)
  169489. {
  169490. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  169491. {
  169492. png_color back;
  169493. back.red = (png_byte)png_ptr->background.red;
  169494. back.green = (png_byte)png_ptr->background.green;
  169495. back.blue = (png_byte)png_ptr->background.blue;
  169496. for (i = 0; i < (int)png_ptr->num_trans; i++)
  169497. {
  169498. if (png_ptr->trans[i] == 0)
  169499. {
  169500. palette[i].red = back.red;
  169501. palette[i].green = back.green;
  169502. palette[i].blue = back.blue;
  169503. }
  169504. else if (png_ptr->trans[i] != 0xff)
  169505. {
  169506. png_composite(palette[i].red, png_ptr->palette[i].red,
  169507. png_ptr->trans[i], back.red);
  169508. png_composite(palette[i].green, png_ptr->palette[i].green,
  169509. png_ptr->trans[i], back.green);
  169510. png_composite(palette[i].blue, png_ptr->palette[i].blue,
  169511. png_ptr->trans[i], back.blue);
  169512. }
  169513. }
  169514. }
  169515. else /* assume grayscale palette (what else could it be?) */
  169516. {
  169517. int i;
  169518. for (i = 0; i < num_palette; i++)
  169519. {
  169520. if (i == (png_byte)png_ptr->trans_values.gray)
  169521. {
  169522. palette[i].red = (png_byte)png_ptr->background.red;
  169523. palette[i].green = (png_byte)png_ptr->background.green;
  169524. palette[i].blue = (png_byte)png_ptr->background.blue;
  169525. }
  169526. }
  169527. }
  169528. }
  169529. #endif
  169530. }
  169531. #endif
  169532. #if defined(PNG_READ_BACKGROUND_SUPPORTED)
  169533. void /* PRIVATE */
  169534. png_do_background(png_row_infop row_info, png_bytep row,
  169535. png_color_16p trans_values, png_color_16p background
  169536. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169537. , png_color_16p background_1,
  169538. png_bytep gamma_table, png_bytep gamma_from_1, png_bytep gamma_to_1,
  169539. png_uint_16pp gamma_16, png_uint_16pp gamma_16_from_1,
  169540. png_uint_16pp gamma_16_to_1, int gamma_shift
  169541. #endif
  169542. )
  169543. {
  169544. png_bytep sp, dp;
  169545. png_uint_32 i;
  169546. png_uint_32 row_width=row_info->width;
  169547. int shift;
  169548. png_debug(1, "in png_do_background\n");
  169549. if (background != NULL &&
  169550. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  169551. row != NULL && row_info != NULL &&
  169552. #endif
  169553. (!(row_info->color_type & PNG_COLOR_MASK_ALPHA) ||
  169554. (row_info->color_type != PNG_COLOR_TYPE_PALETTE && trans_values)))
  169555. {
  169556. switch (row_info->color_type)
  169557. {
  169558. case PNG_COLOR_TYPE_GRAY:
  169559. {
  169560. switch (row_info->bit_depth)
  169561. {
  169562. case 1:
  169563. {
  169564. sp = row;
  169565. shift = 7;
  169566. for (i = 0; i < row_width; i++)
  169567. {
  169568. if ((png_uint_16)((*sp >> shift) & 0x01)
  169569. == trans_values->gray)
  169570. {
  169571. *sp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  169572. *sp |= (png_byte)(background->gray << shift);
  169573. }
  169574. if (!shift)
  169575. {
  169576. shift = 7;
  169577. sp++;
  169578. }
  169579. else
  169580. shift--;
  169581. }
  169582. break;
  169583. }
  169584. case 2:
  169585. {
  169586. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169587. if (gamma_table != NULL)
  169588. {
  169589. sp = row;
  169590. shift = 6;
  169591. for (i = 0; i < row_width; i++)
  169592. {
  169593. if ((png_uint_16)((*sp >> shift) & 0x03)
  169594. == trans_values->gray)
  169595. {
  169596. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169597. *sp |= (png_byte)(background->gray << shift);
  169598. }
  169599. else
  169600. {
  169601. png_byte p = (png_byte)((*sp >> shift) & 0x03);
  169602. png_byte g = (png_byte)((gamma_table [p | (p << 2) |
  169603. (p << 4) | (p << 6)] >> 6) & 0x03);
  169604. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169605. *sp |= (png_byte)(g << shift);
  169606. }
  169607. if (!shift)
  169608. {
  169609. shift = 6;
  169610. sp++;
  169611. }
  169612. else
  169613. shift -= 2;
  169614. }
  169615. }
  169616. else
  169617. #endif
  169618. {
  169619. sp = row;
  169620. shift = 6;
  169621. for (i = 0; i < row_width; i++)
  169622. {
  169623. if ((png_uint_16)((*sp >> shift) & 0x03)
  169624. == trans_values->gray)
  169625. {
  169626. *sp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  169627. *sp |= (png_byte)(background->gray << shift);
  169628. }
  169629. if (!shift)
  169630. {
  169631. shift = 6;
  169632. sp++;
  169633. }
  169634. else
  169635. shift -= 2;
  169636. }
  169637. }
  169638. break;
  169639. }
  169640. case 4:
  169641. {
  169642. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169643. if (gamma_table != NULL)
  169644. {
  169645. sp = row;
  169646. shift = 4;
  169647. for (i = 0; i < row_width; i++)
  169648. {
  169649. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169650. == trans_values->gray)
  169651. {
  169652. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169653. *sp |= (png_byte)(background->gray << shift);
  169654. }
  169655. else
  169656. {
  169657. png_byte p = (png_byte)((*sp >> shift) & 0x0f);
  169658. png_byte g = (png_byte)((gamma_table[p |
  169659. (p << 4)] >> 4) & 0x0f);
  169660. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169661. *sp |= (png_byte)(g << shift);
  169662. }
  169663. if (!shift)
  169664. {
  169665. shift = 4;
  169666. sp++;
  169667. }
  169668. else
  169669. shift -= 4;
  169670. }
  169671. }
  169672. else
  169673. #endif
  169674. {
  169675. sp = row;
  169676. shift = 4;
  169677. for (i = 0; i < row_width; i++)
  169678. {
  169679. if ((png_uint_16)((*sp >> shift) & 0x0f)
  169680. == trans_values->gray)
  169681. {
  169682. *sp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  169683. *sp |= (png_byte)(background->gray << shift);
  169684. }
  169685. if (!shift)
  169686. {
  169687. shift = 4;
  169688. sp++;
  169689. }
  169690. else
  169691. shift -= 4;
  169692. }
  169693. }
  169694. break;
  169695. }
  169696. case 8:
  169697. {
  169698. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169699. if (gamma_table != NULL)
  169700. {
  169701. sp = row;
  169702. for (i = 0; i < row_width; i++, sp++)
  169703. {
  169704. if (*sp == trans_values->gray)
  169705. {
  169706. *sp = (png_byte)background->gray;
  169707. }
  169708. else
  169709. {
  169710. *sp = gamma_table[*sp];
  169711. }
  169712. }
  169713. }
  169714. else
  169715. #endif
  169716. {
  169717. sp = row;
  169718. for (i = 0; i < row_width; i++, sp++)
  169719. {
  169720. if (*sp == trans_values->gray)
  169721. {
  169722. *sp = (png_byte)background->gray;
  169723. }
  169724. }
  169725. }
  169726. break;
  169727. }
  169728. case 16:
  169729. {
  169730. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169731. if (gamma_16 != NULL)
  169732. {
  169733. sp = row;
  169734. for (i = 0; i < row_width; i++, sp += 2)
  169735. {
  169736. png_uint_16 v;
  169737. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169738. if (v == trans_values->gray)
  169739. {
  169740. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169741. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169742. }
  169743. else
  169744. {
  169745. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169746. *sp = (png_byte)((v >> 8) & 0xff);
  169747. *(sp + 1) = (png_byte)(v & 0xff);
  169748. }
  169749. }
  169750. }
  169751. else
  169752. #endif
  169753. {
  169754. sp = row;
  169755. for (i = 0; i < row_width; i++, sp += 2)
  169756. {
  169757. png_uint_16 v;
  169758. v = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169759. if (v == trans_values->gray)
  169760. {
  169761. *sp = (png_byte)((background->gray >> 8) & 0xff);
  169762. *(sp + 1) = (png_byte)(background->gray & 0xff);
  169763. }
  169764. }
  169765. }
  169766. break;
  169767. }
  169768. }
  169769. break;
  169770. }
  169771. case PNG_COLOR_TYPE_RGB:
  169772. {
  169773. if (row_info->bit_depth == 8)
  169774. {
  169775. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169776. if (gamma_table != NULL)
  169777. {
  169778. sp = row;
  169779. for (i = 0; i < row_width; i++, sp += 3)
  169780. {
  169781. if (*sp == trans_values->red &&
  169782. *(sp + 1) == trans_values->green &&
  169783. *(sp + 2) == trans_values->blue)
  169784. {
  169785. *sp = (png_byte)background->red;
  169786. *(sp + 1) = (png_byte)background->green;
  169787. *(sp + 2) = (png_byte)background->blue;
  169788. }
  169789. else
  169790. {
  169791. *sp = gamma_table[*sp];
  169792. *(sp + 1) = gamma_table[*(sp + 1)];
  169793. *(sp + 2) = gamma_table[*(sp + 2)];
  169794. }
  169795. }
  169796. }
  169797. else
  169798. #endif
  169799. {
  169800. sp = row;
  169801. for (i = 0; i < row_width; i++, sp += 3)
  169802. {
  169803. if (*sp == trans_values->red &&
  169804. *(sp + 1) == trans_values->green &&
  169805. *(sp + 2) == trans_values->blue)
  169806. {
  169807. *sp = (png_byte)background->red;
  169808. *(sp + 1) = (png_byte)background->green;
  169809. *(sp + 2) = (png_byte)background->blue;
  169810. }
  169811. }
  169812. }
  169813. }
  169814. else /* if (row_info->bit_depth == 16) */
  169815. {
  169816. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169817. if (gamma_16 != NULL)
  169818. {
  169819. sp = row;
  169820. for (i = 0; i < row_width; i++, sp += 6)
  169821. {
  169822. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169823. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169824. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169825. if (r == trans_values->red && g == trans_values->green &&
  169826. b == trans_values->blue)
  169827. {
  169828. *sp = (png_byte)((background->red >> 8) & 0xff);
  169829. *(sp + 1) = (png_byte)(background->red & 0xff);
  169830. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169831. *(sp + 3) = (png_byte)(background->green & 0xff);
  169832. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169833. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169834. }
  169835. else
  169836. {
  169837. png_uint_16 v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169838. *sp = (png_byte)((v >> 8) & 0xff);
  169839. *(sp + 1) = (png_byte)(v & 0xff);
  169840. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  169841. *(sp + 2) = (png_byte)((v >> 8) & 0xff);
  169842. *(sp + 3) = (png_byte)(v & 0xff);
  169843. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  169844. *(sp + 4) = (png_byte)((v >> 8) & 0xff);
  169845. *(sp + 5) = (png_byte)(v & 0xff);
  169846. }
  169847. }
  169848. }
  169849. else
  169850. #endif
  169851. {
  169852. sp = row;
  169853. for (i = 0; i < row_width; i++, sp += 6)
  169854. {
  169855. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp+1));
  169856. png_uint_16 g = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169857. png_uint_16 b = (png_uint_16)(((*(sp+4)) << 8) + *(sp+5));
  169858. if (r == trans_values->red && g == trans_values->green &&
  169859. b == trans_values->blue)
  169860. {
  169861. *sp = (png_byte)((background->red >> 8) & 0xff);
  169862. *(sp + 1) = (png_byte)(background->red & 0xff);
  169863. *(sp + 2) = (png_byte)((background->green >> 8) & 0xff);
  169864. *(sp + 3) = (png_byte)(background->green & 0xff);
  169865. *(sp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  169866. *(sp + 5) = (png_byte)(background->blue & 0xff);
  169867. }
  169868. }
  169869. }
  169870. }
  169871. break;
  169872. }
  169873. case PNG_COLOR_TYPE_GRAY_ALPHA:
  169874. {
  169875. if (row_info->bit_depth == 8)
  169876. {
  169877. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169878. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  169879. gamma_table != NULL)
  169880. {
  169881. sp = row;
  169882. dp = row;
  169883. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169884. {
  169885. png_uint_16 a = *(sp + 1);
  169886. if (a == 0xff)
  169887. {
  169888. *dp = gamma_table[*sp];
  169889. }
  169890. else if (a == 0)
  169891. {
  169892. *dp = (png_byte)background->gray;
  169893. }
  169894. else
  169895. {
  169896. png_byte v, w;
  169897. v = gamma_to_1[*sp];
  169898. png_composite(w, v, a, background_1->gray);
  169899. *dp = gamma_from_1[w];
  169900. }
  169901. }
  169902. }
  169903. else
  169904. #endif
  169905. {
  169906. sp = row;
  169907. dp = row;
  169908. for (i = 0; i < row_width; i++, sp += 2, dp++)
  169909. {
  169910. png_byte a = *(sp + 1);
  169911. if (a == 0xff)
  169912. {
  169913. *dp = *sp;
  169914. }
  169915. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169916. else if (a == 0)
  169917. {
  169918. *dp = (png_byte)background->gray;
  169919. }
  169920. else
  169921. {
  169922. png_composite(*dp, *sp, a, background_1->gray);
  169923. }
  169924. #else
  169925. *dp = (png_byte)background->gray;
  169926. #endif
  169927. }
  169928. }
  169929. }
  169930. else /* if (png_ptr->bit_depth == 16) */
  169931. {
  169932. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169933. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  169934. gamma_16_to_1 != NULL)
  169935. {
  169936. sp = row;
  169937. dp = row;
  169938. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169939. {
  169940. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169941. if (a == (png_uint_16)0xffff)
  169942. {
  169943. png_uint_16 v;
  169944. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  169945. *dp = (png_byte)((v >> 8) & 0xff);
  169946. *(dp + 1) = (png_byte)(v & 0xff);
  169947. }
  169948. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169949. else if (a == 0)
  169950. #else
  169951. else
  169952. #endif
  169953. {
  169954. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169955. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169956. }
  169957. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169958. else
  169959. {
  169960. png_uint_16 g, v, w;
  169961. g = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  169962. png_composite_16(v, g, a, background_1->gray);
  169963. w = gamma_16_from_1[(v&0xff) >> gamma_shift][v >> 8];
  169964. *dp = (png_byte)((w >> 8) & 0xff);
  169965. *(dp + 1) = (png_byte)(w & 0xff);
  169966. }
  169967. #endif
  169968. }
  169969. }
  169970. else
  169971. #endif
  169972. {
  169973. sp = row;
  169974. dp = row;
  169975. for (i = 0; i < row_width; i++, sp += 4, dp += 2)
  169976. {
  169977. png_uint_16 a = (png_uint_16)(((*(sp+2)) << 8) + *(sp+3));
  169978. if (a == (png_uint_16)0xffff)
  169979. {
  169980. png_memcpy(dp, sp, 2);
  169981. }
  169982. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169983. else if (a == 0)
  169984. #else
  169985. else
  169986. #endif
  169987. {
  169988. *dp = (png_byte)((background->gray >> 8) & 0xff);
  169989. *(dp + 1) = (png_byte)(background->gray & 0xff);
  169990. }
  169991. #if defined(PNG_READ_GAMMA_SUPPORTED)
  169992. else
  169993. {
  169994. png_uint_16 g, v;
  169995. g = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  169996. png_composite_16(v, g, a, background_1->gray);
  169997. *dp = (png_byte)((v >> 8) & 0xff);
  169998. *(dp + 1) = (png_byte)(v & 0xff);
  169999. }
  170000. #endif
  170001. }
  170002. }
  170003. }
  170004. break;
  170005. }
  170006. case PNG_COLOR_TYPE_RGB_ALPHA:
  170007. {
  170008. if (row_info->bit_depth == 8)
  170009. {
  170010. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170011. if (gamma_to_1 != NULL && gamma_from_1 != NULL &&
  170012. gamma_table != NULL)
  170013. {
  170014. sp = row;
  170015. dp = row;
  170016. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  170017. {
  170018. png_byte a = *(sp + 3);
  170019. if (a == 0xff)
  170020. {
  170021. *dp = gamma_table[*sp];
  170022. *(dp + 1) = gamma_table[*(sp + 1)];
  170023. *(dp + 2) = gamma_table[*(sp + 2)];
  170024. }
  170025. else if (a == 0)
  170026. {
  170027. *dp = (png_byte)background->red;
  170028. *(dp + 1) = (png_byte)background->green;
  170029. *(dp + 2) = (png_byte)background->blue;
  170030. }
  170031. else
  170032. {
  170033. png_byte v, w;
  170034. v = gamma_to_1[*sp];
  170035. png_composite(w, v, a, background_1->red);
  170036. *dp = gamma_from_1[w];
  170037. v = gamma_to_1[*(sp + 1)];
  170038. png_composite(w, v, a, background_1->green);
  170039. *(dp + 1) = gamma_from_1[w];
  170040. v = gamma_to_1[*(sp + 2)];
  170041. png_composite(w, v, a, background_1->blue);
  170042. *(dp + 2) = gamma_from_1[w];
  170043. }
  170044. }
  170045. }
  170046. else
  170047. #endif
  170048. {
  170049. sp = row;
  170050. dp = row;
  170051. for (i = 0; i < row_width; i++, sp += 4, dp += 3)
  170052. {
  170053. png_byte a = *(sp + 3);
  170054. if (a == 0xff)
  170055. {
  170056. *dp = *sp;
  170057. *(dp + 1) = *(sp + 1);
  170058. *(dp + 2) = *(sp + 2);
  170059. }
  170060. else if (a == 0)
  170061. {
  170062. *dp = (png_byte)background->red;
  170063. *(dp + 1) = (png_byte)background->green;
  170064. *(dp + 2) = (png_byte)background->blue;
  170065. }
  170066. else
  170067. {
  170068. png_composite(*dp, *sp, a, background->red);
  170069. png_composite(*(dp + 1), *(sp + 1), a,
  170070. background->green);
  170071. png_composite(*(dp + 2), *(sp + 2), a,
  170072. background->blue);
  170073. }
  170074. }
  170075. }
  170076. }
  170077. else /* if (row_info->bit_depth == 16) */
  170078. {
  170079. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170080. if (gamma_16 != NULL && gamma_16_from_1 != NULL &&
  170081. gamma_16_to_1 != NULL)
  170082. {
  170083. sp = row;
  170084. dp = row;
  170085. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  170086. {
  170087. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  170088. << 8) + (png_uint_16)(*(sp + 7)));
  170089. if (a == (png_uint_16)0xffff)
  170090. {
  170091. png_uint_16 v;
  170092. v = gamma_16[*(sp + 1) >> gamma_shift][*sp];
  170093. *dp = (png_byte)((v >> 8) & 0xff);
  170094. *(dp + 1) = (png_byte)(v & 0xff);
  170095. v = gamma_16[*(sp + 3) >> gamma_shift][*(sp + 2)];
  170096. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  170097. *(dp + 3) = (png_byte)(v & 0xff);
  170098. v = gamma_16[*(sp + 5) >> gamma_shift][*(sp + 4)];
  170099. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  170100. *(dp + 5) = (png_byte)(v & 0xff);
  170101. }
  170102. else if (a == 0)
  170103. {
  170104. *dp = (png_byte)((background->red >> 8) & 0xff);
  170105. *(dp + 1) = (png_byte)(background->red & 0xff);
  170106. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170107. *(dp + 3) = (png_byte)(background->green & 0xff);
  170108. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170109. *(dp + 5) = (png_byte)(background->blue & 0xff);
  170110. }
  170111. else
  170112. {
  170113. png_uint_16 v, w, x;
  170114. v = gamma_16_to_1[*(sp + 1) >> gamma_shift][*sp];
  170115. png_composite_16(w, v, a, background_1->red);
  170116. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  170117. *dp = (png_byte)((x >> 8) & 0xff);
  170118. *(dp + 1) = (png_byte)(x & 0xff);
  170119. v = gamma_16_to_1[*(sp + 3) >> gamma_shift][*(sp + 2)];
  170120. png_composite_16(w, v, a, background_1->green);
  170121. x = gamma_16_from_1[((w&0xff) >> gamma_shift)][w >> 8];
  170122. *(dp + 2) = (png_byte)((x >> 8) & 0xff);
  170123. *(dp + 3) = (png_byte)(x & 0xff);
  170124. v = gamma_16_to_1[*(sp + 5) >> gamma_shift][*(sp + 4)];
  170125. png_composite_16(w, v, a, background_1->blue);
  170126. x = gamma_16_from_1[(w & 0xff) >> gamma_shift][w >> 8];
  170127. *(dp + 4) = (png_byte)((x >> 8) & 0xff);
  170128. *(dp + 5) = (png_byte)(x & 0xff);
  170129. }
  170130. }
  170131. }
  170132. else
  170133. #endif
  170134. {
  170135. sp = row;
  170136. dp = row;
  170137. for (i = 0; i < row_width; i++, sp += 8, dp += 6)
  170138. {
  170139. png_uint_16 a = (png_uint_16)(((png_uint_16)(*(sp + 6))
  170140. << 8) + (png_uint_16)(*(sp + 7)));
  170141. if (a == (png_uint_16)0xffff)
  170142. {
  170143. png_memcpy(dp, sp, 6);
  170144. }
  170145. else if (a == 0)
  170146. {
  170147. *dp = (png_byte)((background->red >> 8) & 0xff);
  170148. *(dp + 1) = (png_byte)(background->red & 0xff);
  170149. *(dp + 2) = (png_byte)((background->green >> 8) & 0xff);
  170150. *(dp + 3) = (png_byte)(background->green & 0xff);
  170151. *(dp + 4) = (png_byte)((background->blue >> 8) & 0xff);
  170152. *(dp + 5) = (png_byte)(background->blue & 0xff);
  170153. }
  170154. else
  170155. {
  170156. png_uint_16 v;
  170157. png_uint_16 r = (png_uint_16)(((*sp) << 8) + *(sp + 1));
  170158. png_uint_16 g = (png_uint_16)(((*(sp + 2)) << 8)
  170159. + *(sp + 3));
  170160. png_uint_16 b = (png_uint_16)(((*(sp + 4)) << 8)
  170161. + *(sp + 5));
  170162. png_composite_16(v, r, a, background->red);
  170163. *dp = (png_byte)((v >> 8) & 0xff);
  170164. *(dp + 1) = (png_byte)(v & 0xff);
  170165. png_composite_16(v, g, a, background->green);
  170166. *(dp + 2) = (png_byte)((v >> 8) & 0xff);
  170167. *(dp + 3) = (png_byte)(v & 0xff);
  170168. png_composite_16(v, b, a, background->blue);
  170169. *(dp + 4) = (png_byte)((v >> 8) & 0xff);
  170170. *(dp + 5) = (png_byte)(v & 0xff);
  170171. }
  170172. }
  170173. }
  170174. }
  170175. break;
  170176. }
  170177. }
  170178. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  170179. {
  170180. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  170181. row_info->channels--;
  170182. row_info->pixel_depth = (png_byte)(row_info->channels *
  170183. row_info->bit_depth);
  170184. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170185. }
  170186. }
  170187. }
  170188. #endif
  170189. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170190. void /* PRIVATE */
  170191. png_do_gamma(png_row_infop row_info, png_bytep row,
  170192. png_bytep gamma_table, png_uint_16pp gamma_16_table,
  170193. int gamma_shift)
  170194. {
  170195. png_bytep sp;
  170196. png_uint_32 i;
  170197. png_uint_32 row_width=row_info->width;
  170198. png_debug(1, "in png_do_gamma\n");
  170199. if (
  170200. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170201. row != NULL && row_info != NULL &&
  170202. #endif
  170203. ((row_info->bit_depth <= 8 && gamma_table != NULL) ||
  170204. (row_info->bit_depth == 16 && gamma_16_table != NULL)))
  170205. {
  170206. switch (row_info->color_type)
  170207. {
  170208. case PNG_COLOR_TYPE_RGB:
  170209. {
  170210. if (row_info->bit_depth == 8)
  170211. {
  170212. sp = row;
  170213. for (i = 0; i < row_width; i++)
  170214. {
  170215. *sp = gamma_table[*sp];
  170216. sp++;
  170217. *sp = gamma_table[*sp];
  170218. sp++;
  170219. *sp = gamma_table[*sp];
  170220. sp++;
  170221. }
  170222. }
  170223. else /* if (row_info->bit_depth == 16) */
  170224. {
  170225. sp = row;
  170226. for (i = 0; i < row_width; i++)
  170227. {
  170228. png_uint_16 v;
  170229. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170230. *sp = (png_byte)((v >> 8) & 0xff);
  170231. *(sp + 1) = (png_byte)(v & 0xff);
  170232. sp += 2;
  170233. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170234. *sp = (png_byte)((v >> 8) & 0xff);
  170235. *(sp + 1) = (png_byte)(v & 0xff);
  170236. sp += 2;
  170237. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170238. *sp = (png_byte)((v >> 8) & 0xff);
  170239. *(sp + 1) = (png_byte)(v & 0xff);
  170240. sp += 2;
  170241. }
  170242. }
  170243. break;
  170244. }
  170245. case PNG_COLOR_TYPE_RGB_ALPHA:
  170246. {
  170247. if (row_info->bit_depth == 8)
  170248. {
  170249. sp = row;
  170250. for (i = 0; i < row_width; i++)
  170251. {
  170252. *sp = gamma_table[*sp];
  170253. sp++;
  170254. *sp = gamma_table[*sp];
  170255. sp++;
  170256. *sp = gamma_table[*sp];
  170257. sp++;
  170258. sp++;
  170259. }
  170260. }
  170261. else /* if (row_info->bit_depth == 16) */
  170262. {
  170263. sp = row;
  170264. for (i = 0; i < row_width; i++)
  170265. {
  170266. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170267. *sp = (png_byte)((v >> 8) & 0xff);
  170268. *(sp + 1) = (png_byte)(v & 0xff);
  170269. sp += 2;
  170270. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170271. *sp = (png_byte)((v >> 8) & 0xff);
  170272. *(sp + 1) = (png_byte)(v & 0xff);
  170273. sp += 2;
  170274. v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170275. *sp = (png_byte)((v >> 8) & 0xff);
  170276. *(sp + 1) = (png_byte)(v & 0xff);
  170277. sp += 4;
  170278. }
  170279. }
  170280. break;
  170281. }
  170282. case PNG_COLOR_TYPE_GRAY_ALPHA:
  170283. {
  170284. if (row_info->bit_depth == 8)
  170285. {
  170286. sp = row;
  170287. for (i = 0; i < row_width; i++)
  170288. {
  170289. *sp = gamma_table[*sp];
  170290. sp += 2;
  170291. }
  170292. }
  170293. else /* if (row_info->bit_depth == 16) */
  170294. {
  170295. sp = row;
  170296. for (i = 0; i < row_width; i++)
  170297. {
  170298. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170299. *sp = (png_byte)((v >> 8) & 0xff);
  170300. *(sp + 1) = (png_byte)(v & 0xff);
  170301. sp += 4;
  170302. }
  170303. }
  170304. break;
  170305. }
  170306. case PNG_COLOR_TYPE_GRAY:
  170307. {
  170308. if (row_info->bit_depth == 2)
  170309. {
  170310. sp = row;
  170311. for (i = 0; i < row_width; i += 4)
  170312. {
  170313. int a = *sp & 0xc0;
  170314. int b = *sp & 0x30;
  170315. int c = *sp & 0x0c;
  170316. int d = *sp & 0x03;
  170317. *sp = (png_byte)(
  170318. ((((int)gamma_table[a|(a>>2)|(a>>4)|(a>>6)]) ) & 0xc0)|
  170319. ((((int)gamma_table[(b<<2)|b|(b>>2)|(b>>4)])>>2) & 0x30)|
  170320. ((((int)gamma_table[(c<<4)|(c<<2)|c|(c>>2)])>>4) & 0x0c)|
  170321. ((((int)gamma_table[(d<<6)|(d<<4)|(d<<2)|d])>>6) ));
  170322. sp++;
  170323. }
  170324. }
  170325. if (row_info->bit_depth == 4)
  170326. {
  170327. sp = row;
  170328. for (i = 0; i < row_width; i += 2)
  170329. {
  170330. int msb = *sp & 0xf0;
  170331. int lsb = *sp & 0x0f;
  170332. *sp = (png_byte)((((int)gamma_table[msb | (msb >> 4)]) & 0xf0)
  170333. | (((int)gamma_table[(lsb << 4) | lsb]) >> 4));
  170334. sp++;
  170335. }
  170336. }
  170337. else if (row_info->bit_depth == 8)
  170338. {
  170339. sp = row;
  170340. for (i = 0; i < row_width; i++)
  170341. {
  170342. *sp = gamma_table[*sp];
  170343. sp++;
  170344. }
  170345. }
  170346. else if (row_info->bit_depth == 16)
  170347. {
  170348. sp = row;
  170349. for (i = 0; i < row_width; i++)
  170350. {
  170351. png_uint_16 v = gamma_16_table[*(sp + 1) >> gamma_shift][*sp];
  170352. *sp = (png_byte)((v >> 8) & 0xff);
  170353. *(sp + 1) = (png_byte)(v & 0xff);
  170354. sp += 2;
  170355. }
  170356. }
  170357. break;
  170358. }
  170359. }
  170360. }
  170361. }
  170362. #endif
  170363. #if defined(PNG_READ_EXPAND_SUPPORTED)
  170364. void /* PRIVATE */
  170365. png_do_expand_palette(png_row_infop row_info, png_bytep row,
  170366. png_colorp palette, png_bytep trans, int num_trans)
  170367. {
  170368. int shift, value;
  170369. png_bytep sp, dp;
  170370. png_uint_32 i;
  170371. png_uint_32 row_width=row_info->width;
  170372. png_debug(1, "in png_do_expand_palette\n");
  170373. if (
  170374. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170375. row != NULL && row_info != NULL &&
  170376. #endif
  170377. row_info->color_type == PNG_COLOR_TYPE_PALETTE)
  170378. {
  170379. if (row_info->bit_depth < 8)
  170380. {
  170381. switch (row_info->bit_depth)
  170382. {
  170383. case 1:
  170384. {
  170385. sp = row + (png_size_t)((row_width - 1) >> 3);
  170386. dp = row + (png_size_t)row_width - 1;
  170387. shift = 7 - (int)((row_width + 7) & 0x07);
  170388. for (i = 0; i < row_width; i++)
  170389. {
  170390. if ((*sp >> shift) & 0x01)
  170391. *dp = 1;
  170392. else
  170393. *dp = 0;
  170394. if (shift == 7)
  170395. {
  170396. shift = 0;
  170397. sp--;
  170398. }
  170399. else
  170400. shift++;
  170401. dp--;
  170402. }
  170403. break;
  170404. }
  170405. case 2:
  170406. {
  170407. sp = row + (png_size_t)((row_width - 1) >> 2);
  170408. dp = row + (png_size_t)row_width - 1;
  170409. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170410. for (i = 0; i < row_width; i++)
  170411. {
  170412. value = (*sp >> shift) & 0x03;
  170413. *dp = (png_byte)value;
  170414. if (shift == 6)
  170415. {
  170416. shift = 0;
  170417. sp--;
  170418. }
  170419. else
  170420. shift += 2;
  170421. dp--;
  170422. }
  170423. break;
  170424. }
  170425. case 4:
  170426. {
  170427. sp = row + (png_size_t)((row_width - 1) >> 1);
  170428. dp = row + (png_size_t)row_width - 1;
  170429. shift = (int)((row_width & 0x01) << 2);
  170430. for (i = 0; i < row_width; i++)
  170431. {
  170432. value = (*sp >> shift) & 0x0f;
  170433. *dp = (png_byte)value;
  170434. if (shift == 4)
  170435. {
  170436. shift = 0;
  170437. sp--;
  170438. }
  170439. else
  170440. shift += 4;
  170441. dp--;
  170442. }
  170443. break;
  170444. }
  170445. }
  170446. row_info->bit_depth = 8;
  170447. row_info->pixel_depth = 8;
  170448. row_info->rowbytes = row_width;
  170449. }
  170450. switch (row_info->bit_depth)
  170451. {
  170452. case 8:
  170453. {
  170454. if (trans != NULL)
  170455. {
  170456. sp = row + (png_size_t)row_width - 1;
  170457. dp = row + (png_size_t)(row_width << 2) - 1;
  170458. for (i = 0; i < row_width; i++)
  170459. {
  170460. if ((int)(*sp) >= num_trans)
  170461. *dp-- = 0xff;
  170462. else
  170463. *dp-- = trans[*sp];
  170464. *dp-- = palette[*sp].blue;
  170465. *dp-- = palette[*sp].green;
  170466. *dp-- = palette[*sp].red;
  170467. sp--;
  170468. }
  170469. row_info->bit_depth = 8;
  170470. row_info->pixel_depth = 32;
  170471. row_info->rowbytes = row_width * 4;
  170472. row_info->color_type = 6;
  170473. row_info->channels = 4;
  170474. }
  170475. else
  170476. {
  170477. sp = row + (png_size_t)row_width - 1;
  170478. dp = row + (png_size_t)(row_width * 3) - 1;
  170479. for (i = 0; i < row_width; i++)
  170480. {
  170481. *dp-- = palette[*sp].blue;
  170482. *dp-- = palette[*sp].green;
  170483. *dp-- = palette[*sp].red;
  170484. sp--;
  170485. }
  170486. row_info->bit_depth = 8;
  170487. row_info->pixel_depth = 24;
  170488. row_info->rowbytes = row_width * 3;
  170489. row_info->color_type = 2;
  170490. row_info->channels = 3;
  170491. }
  170492. break;
  170493. }
  170494. }
  170495. }
  170496. }
  170497. void /* PRIVATE */
  170498. png_do_expand(png_row_infop row_info, png_bytep row,
  170499. png_color_16p trans_value)
  170500. {
  170501. int shift, value;
  170502. png_bytep sp, dp;
  170503. png_uint_32 i;
  170504. png_uint_32 row_width=row_info->width;
  170505. png_debug(1, "in png_do_expand\n");
  170506. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170507. if (row != NULL && row_info != NULL)
  170508. #endif
  170509. {
  170510. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  170511. {
  170512. png_uint_16 gray = (png_uint_16)(trans_value ? trans_value->gray : 0);
  170513. if (row_info->bit_depth < 8)
  170514. {
  170515. switch (row_info->bit_depth)
  170516. {
  170517. case 1:
  170518. {
  170519. gray = (png_uint_16)((gray&0x01)*0xff);
  170520. sp = row + (png_size_t)((row_width - 1) >> 3);
  170521. dp = row + (png_size_t)row_width - 1;
  170522. shift = 7 - (int)((row_width + 7) & 0x07);
  170523. for (i = 0; i < row_width; i++)
  170524. {
  170525. if ((*sp >> shift) & 0x01)
  170526. *dp = 0xff;
  170527. else
  170528. *dp = 0;
  170529. if (shift == 7)
  170530. {
  170531. shift = 0;
  170532. sp--;
  170533. }
  170534. else
  170535. shift++;
  170536. dp--;
  170537. }
  170538. break;
  170539. }
  170540. case 2:
  170541. {
  170542. gray = (png_uint_16)((gray&0x03)*0x55);
  170543. sp = row + (png_size_t)((row_width - 1) >> 2);
  170544. dp = row + (png_size_t)row_width - 1;
  170545. shift = (int)((3 - ((row_width + 3) & 0x03)) << 1);
  170546. for (i = 0; i < row_width; i++)
  170547. {
  170548. value = (*sp >> shift) & 0x03;
  170549. *dp = (png_byte)(value | (value << 2) | (value << 4) |
  170550. (value << 6));
  170551. if (shift == 6)
  170552. {
  170553. shift = 0;
  170554. sp--;
  170555. }
  170556. else
  170557. shift += 2;
  170558. dp--;
  170559. }
  170560. break;
  170561. }
  170562. case 4:
  170563. {
  170564. gray = (png_uint_16)((gray&0x0f)*0x11);
  170565. sp = row + (png_size_t)((row_width - 1) >> 1);
  170566. dp = row + (png_size_t)row_width - 1;
  170567. shift = (int)((1 - ((row_width + 1) & 0x01)) << 2);
  170568. for (i = 0; i < row_width; i++)
  170569. {
  170570. value = (*sp >> shift) & 0x0f;
  170571. *dp = (png_byte)(value | (value << 4));
  170572. if (shift == 4)
  170573. {
  170574. shift = 0;
  170575. sp--;
  170576. }
  170577. else
  170578. shift = 4;
  170579. dp--;
  170580. }
  170581. break;
  170582. }
  170583. }
  170584. row_info->bit_depth = 8;
  170585. row_info->pixel_depth = 8;
  170586. row_info->rowbytes = row_width;
  170587. }
  170588. if (trans_value != NULL)
  170589. {
  170590. if (row_info->bit_depth == 8)
  170591. {
  170592. gray = gray & 0xff;
  170593. sp = row + (png_size_t)row_width - 1;
  170594. dp = row + (png_size_t)(row_width << 1) - 1;
  170595. for (i = 0; i < row_width; i++)
  170596. {
  170597. if (*sp == gray)
  170598. *dp-- = 0;
  170599. else
  170600. *dp-- = 0xff;
  170601. *dp-- = *sp--;
  170602. }
  170603. }
  170604. else if (row_info->bit_depth == 16)
  170605. {
  170606. png_byte gray_high = (gray >> 8) & 0xff;
  170607. png_byte gray_low = gray & 0xff;
  170608. sp = row + row_info->rowbytes - 1;
  170609. dp = row + (row_info->rowbytes << 1) - 1;
  170610. for (i = 0; i < row_width; i++)
  170611. {
  170612. if (*(sp-1) == gray_high && *(sp) == gray_low)
  170613. {
  170614. *dp-- = 0;
  170615. *dp-- = 0;
  170616. }
  170617. else
  170618. {
  170619. *dp-- = 0xff;
  170620. *dp-- = 0xff;
  170621. }
  170622. *dp-- = *sp--;
  170623. *dp-- = *sp--;
  170624. }
  170625. }
  170626. row_info->color_type = PNG_COLOR_TYPE_GRAY_ALPHA;
  170627. row_info->channels = 2;
  170628. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 1);
  170629. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  170630. row_width);
  170631. }
  170632. }
  170633. else if (row_info->color_type == PNG_COLOR_TYPE_RGB && trans_value)
  170634. {
  170635. if (row_info->bit_depth == 8)
  170636. {
  170637. png_byte red = trans_value->red & 0xff;
  170638. png_byte green = trans_value->green & 0xff;
  170639. png_byte blue = trans_value->blue & 0xff;
  170640. sp = row + (png_size_t)row_info->rowbytes - 1;
  170641. dp = row + (png_size_t)(row_width << 2) - 1;
  170642. for (i = 0; i < row_width; i++)
  170643. {
  170644. if (*(sp - 2) == red && *(sp - 1) == green && *(sp) == blue)
  170645. *dp-- = 0;
  170646. else
  170647. *dp-- = 0xff;
  170648. *dp-- = *sp--;
  170649. *dp-- = *sp--;
  170650. *dp-- = *sp--;
  170651. }
  170652. }
  170653. else if (row_info->bit_depth == 16)
  170654. {
  170655. png_byte red_high = (trans_value->red >> 8) & 0xff;
  170656. png_byte green_high = (trans_value->green >> 8) & 0xff;
  170657. png_byte blue_high = (trans_value->blue >> 8) & 0xff;
  170658. png_byte red_low = trans_value->red & 0xff;
  170659. png_byte green_low = trans_value->green & 0xff;
  170660. png_byte blue_low = trans_value->blue & 0xff;
  170661. sp = row + row_info->rowbytes - 1;
  170662. dp = row + (png_size_t)(row_width << 3) - 1;
  170663. for (i = 0; i < row_width; i++)
  170664. {
  170665. if (*(sp - 5) == red_high &&
  170666. *(sp - 4) == red_low &&
  170667. *(sp - 3) == green_high &&
  170668. *(sp - 2) == green_low &&
  170669. *(sp - 1) == blue_high &&
  170670. *(sp ) == blue_low)
  170671. {
  170672. *dp-- = 0;
  170673. *dp-- = 0;
  170674. }
  170675. else
  170676. {
  170677. *dp-- = 0xff;
  170678. *dp-- = 0xff;
  170679. }
  170680. *dp-- = *sp--;
  170681. *dp-- = *sp--;
  170682. *dp-- = *sp--;
  170683. *dp-- = *sp--;
  170684. *dp-- = *sp--;
  170685. *dp-- = *sp--;
  170686. }
  170687. }
  170688. row_info->color_type = PNG_COLOR_TYPE_RGB_ALPHA;
  170689. row_info->channels = 4;
  170690. row_info->pixel_depth = (png_byte)(row_info->bit_depth << 2);
  170691. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170692. }
  170693. }
  170694. }
  170695. #endif
  170696. #if defined(PNG_READ_DITHER_SUPPORTED)
  170697. void /* PRIVATE */
  170698. png_do_dither(png_row_infop row_info, png_bytep row,
  170699. png_bytep palette_lookup, png_bytep dither_lookup)
  170700. {
  170701. png_bytep sp, dp;
  170702. png_uint_32 i;
  170703. png_uint_32 row_width=row_info->width;
  170704. png_debug(1, "in png_do_dither\n");
  170705. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170706. if (row != NULL && row_info != NULL)
  170707. #endif
  170708. {
  170709. if (row_info->color_type == PNG_COLOR_TYPE_RGB &&
  170710. palette_lookup && row_info->bit_depth == 8)
  170711. {
  170712. int r, g, b, p;
  170713. sp = row;
  170714. dp = row;
  170715. for (i = 0; i < row_width; i++)
  170716. {
  170717. r = *sp++;
  170718. g = *sp++;
  170719. b = *sp++;
  170720. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170721. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170722. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170723. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170724. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170725. (PNG_DITHER_BLUE_BITS)) |
  170726. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170727. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170728. *dp++ = palette_lookup[p];
  170729. }
  170730. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170731. row_info->channels = 1;
  170732. row_info->pixel_depth = row_info->bit_depth;
  170733. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170734. }
  170735. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  170736. palette_lookup != NULL && row_info->bit_depth == 8)
  170737. {
  170738. int r, g, b, p;
  170739. sp = row;
  170740. dp = row;
  170741. for (i = 0; i < row_width; i++)
  170742. {
  170743. r = *sp++;
  170744. g = *sp++;
  170745. b = *sp++;
  170746. sp++;
  170747. p = (((r >> (8 - PNG_DITHER_RED_BITS)) &
  170748. ((1 << PNG_DITHER_RED_BITS) - 1)) <<
  170749. (PNG_DITHER_GREEN_BITS + PNG_DITHER_BLUE_BITS)) |
  170750. (((g >> (8 - PNG_DITHER_GREEN_BITS)) &
  170751. ((1 << PNG_DITHER_GREEN_BITS) - 1)) <<
  170752. (PNG_DITHER_BLUE_BITS)) |
  170753. ((b >> (8 - PNG_DITHER_BLUE_BITS)) &
  170754. ((1 << PNG_DITHER_BLUE_BITS) - 1));
  170755. *dp++ = palette_lookup[p];
  170756. }
  170757. row_info->color_type = PNG_COLOR_TYPE_PALETTE;
  170758. row_info->channels = 1;
  170759. row_info->pixel_depth = row_info->bit_depth;
  170760. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,row_width);
  170761. }
  170762. else if (row_info->color_type == PNG_COLOR_TYPE_PALETTE &&
  170763. dither_lookup && row_info->bit_depth == 8)
  170764. {
  170765. sp = row;
  170766. for (i = 0; i < row_width; i++, sp++)
  170767. {
  170768. *sp = dither_lookup[*sp];
  170769. }
  170770. }
  170771. }
  170772. }
  170773. #endif
  170774. #ifdef PNG_FLOATING_POINT_SUPPORTED
  170775. #if defined(PNG_READ_GAMMA_SUPPORTED)
  170776. static PNG_CONST int png_gamma_shift[] =
  170777. {0x10, 0x21, 0x42, 0x84, 0x110, 0x248, 0x550, 0xff0, 0x00};
  170778. void /* PRIVATE */
  170779. png_build_gamma_table(png_structp png_ptr)
  170780. {
  170781. png_debug(1, "in png_build_gamma_table\n");
  170782. if (png_ptr->bit_depth <= 8)
  170783. {
  170784. int i;
  170785. double g;
  170786. if (png_ptr->screen_gamma > .000001)
  170787. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170788. else
  170789. g = 1.0;
  170790. png_ptr->gamma_table = (png_bytep)png_malloc(png_ptr,
  170791. (png_uint_32)256);
  170792. for (i = 0; i < 256; i++)
  170793. {
  170794. png_ptr->gamma_table[i] = (png_byte)(pow((double)i / 255.0,
  170795. g) * 255.0 + .5);
  170796. }
  170797. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170798. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170799. if (png_ptr->transformations & ((PNG_BACKGROUND) | PNG_RGB_TO_GRAY))
  170800. {
  170801. g = 1.0 / (png_ptr->gamma);
  170802. png_ptr->gamma_to_1 = (png_bytep)png_malloc(png_ptr,
  170803. (png_uint_32)256);
  170804. for (i = 0; i < 256; i++)
  170805. {
  170806. png_ptr->gamma_to_1[i] = (png_byte)(pow((double)i / 255.0,
  170807. g) * 255.0 + .5);
  170808. }
  170809. png_ptr->gamma_from_1 = (png_bytep)png_malloc(png_ptr,
  170810. (png_uint_32)256);
  170811. if(png_ptr->screen_gamma > 0.000001)
  170812. g = 1.0 / png_ptr->screen_gamma;
  170813. else
  170814. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170815. for (i = 0; i < 256; i++)
  170816. {
  170817. png_ptr->gamma_from_1[i] = (png_byte)(pow((double)i / 255.0,
  170818. g) * 255.0 + .5);
  170819. }
  170820. }
  170821. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170822. }
  170823. else
  170824. {
  170825. double g;
  170826. int i, j, shift, num;
  170827. int sig_bit;
  170828. png_uint_32 ig;
  170829. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  170830. {
  170831. sig_bit = (int)png_ptr->sig_bit.red;
  170832. if ((int)png_ptr->sig_bit.green > sig_bit)
  170833. sig_bit = png_ptr->sig_bit.green;
  170834. if ((int)png_ptr->sig_bit.blue > sig_bit)
  170835. sig_bit = png_ptr->sig_bit.blue;
  170836. }
  170837. else
  170838. {
  170839. sig_bit = (int)png_ptr->sig_bit.gray;
  170840. }
  170841. if (sig_bit > 0)
  170842. shift = 16 - sig_bit;
  170843. else
  170844. shift = 0;
  170845. if (png_ptr->transformations & PNG_16_TO_8)
  170846. {
  170847. if (shift < (16 - PNG_MAX_GAMMA_8))
  170848. shift = (16 - PNG_MAX_GAMMA_8);
  170849. }
  170850. if (shift > 8)
  170851. shift = 8;
  170852. if (shift < 0)
  170853. shift = 0;
  170854. png_ptr->gamma_shift = (png_byte)shift;
  170855. num = (1 << (8 - shift));
  170856. if (png_ptr->screen_gamma > .000001)
  170857. g = 1.0 / (png_ptr->gamma * png_ptr->screen_gamma);
  170858. else
  170859. g = 1.0;
  170860. png_ptr->gamma_16_table = (png_uint_16pp)png_malloc(png_ptr,
  170861. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170862. if (png_ptr->transformations & (PNG_16_TO_8 | PNG_BACKGROUND))
  170863. {
  170864. double fin, fout;
  170865. png_uint_32 last, max;
  170866. for (i = 0; i < num; i++)
  170867. {
  170868. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170869. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170870. }
  170871. g = 1.0 / g;
  170872. last = 0;
  170873. for (i = 0; i < 256; i++)
  170874. {
  170875. fout = ((double)i + 0.5) / 256.0;
  170876. fin = pow(fout, g);
  170877. max = (png_uint_32)(fin * (double)((png_uint_32)num << 8));
  170878. while (last <= max)
  170879. {
  170880. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170881. [(int)(last >> (8 - shift))] = (png_uint_16)(
  170882. (png_uint_16)i | ((png_uint_16)i << 8));
  170883. last++;
  170884. }
  170885. }
  170886. while (last < ((png_uint_32)num << 8))
  170887. {
  170888. png_ptr->gamma_16_table[(int)(last & (0xff >> shift))]
  170889. [(int)(last >> (8 - shift))] = (png_uint_16)65535L;
  170890. last++;
  170891. }
  170892. }
  170893. else
  170894. {
  170895. for (i = 0; i < num; i++)
  170896. {
  170897. png_ptr->gamma_16_table[i] = (png_uint_16p)png_malloc(png_ptr,
  170898. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170899. ig = (((png_uint_32)i * (png_uint_32)png_gamma_shift[shift]) >> 4);
  170900. for (j = 0; j < 256; j++)
  170901. {
  170902. png_ptr->gamma_16_table[i][j] =
  170903. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170904. 65535.0, g) * 65535.0 + .5);
  170905. }
  170906. }
  170907. }
  170908. #if defined(PNG_READ_BACKGROUND_SUPPORTED) || \
  170909. defined(PNG_READ_RGB_TO_GRAY_SUPPORTED)
  170910. if (png_ptr->transformations & (PNG_BACKGROUND | PNG_RGB_TO_GRAY))
  170911. {
  170912. g = 1.0 / (png_ptr->gamma);
  170913. png_ptr->gamma_16_to_1 = (png_uint_16pp)png_malloc(png_ptr,
  170914. (png_uint_32)(num * png_sizeof (png_uint_16p )));
  170915. for (i = 0; i < num; i++)
  170916. {
  170917. png_ptr->gamma_16_to_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170918. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170919. ig = (((png_uint_32)i *
  170920. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170921. for (j = 0; j < 256; j++)
  170922. {
  170923. png_ptr->gamma_16_to_1[i][j] =
  170924. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170925. 65535.0, g) * 65535.0 + .5);
  170926. }
  170927. }
  170928. if(png_ptr->screen_gamma > 0.000001)
  170929. g = 1.0 / png_ptr->screen_gamma;
  170930. else
  170931. g = png_ptr->gamma; /* probably doing rgb_to_gray */
  170932. png_ptr->gamma_16_from_1 = (png_uint_16pp)png_malloc(png_ptr,
  170933. (png_uint_32)(num * png_sizeof (png_uint_16p)));
  170934. for (i = 0; i < num; i++)
  170935. {
  170936. png_ptr->gamma_16_from_1[i] = (png_uint_16p)png_malloc(png_ptr,
  170937. (png_uint_32)(256 * png_sizeof (png_uint_16)));
  170938. ig = (((png_uint_32)i *
  170939. (png_uint_32)png_gamma_shift[shift]) >> 4);
  170940. for (j = 0; j < 256; j++)
  170941. {
  170942. png_ptr->gamma_16_from_1[i][j] =
  170943. (png_uint_16)(pow((double)(ig + ((png_uint_32)j << 8)) /
  170944. 65535.0, g) * 65535.0 + .5);
  170945. }
  170946. }
  170947. }
  170948. #endif /* PNG_READ_BACKGROUND_SUPPORTED || PNG_RGB_TO_GRAY_SUPPORTED */
  170949. }
  170950. }
  170951. #endif
  170952. #endif
  170953. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  170954. void /* PRIVATE */
  170955. png_do_read_intrapixel(png_row_infop row_info, png_bytep row)
  170956. {
  170957. png_debug(1, "in png_do_read_intrapixel\n");
  170958. if (
  170959. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  170960. row != NULL && row_info != NULL &&
  170961. #endif
  170962. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  170963. {
  170964. int bytes_per_pixel;
  170965. png_uint_32 row_width = row_info->width;
  170966. if (row_info->bit_depth == 8)
  170967. {
  170968. png_bytep rp;
  170969. png_uint_32 i;
  170970. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170971. bytes_per_pixel = 3;
  170972. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170973. bytes_per_pixel = 4;
  170974. else
  170975. return;
  170976. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170977. {
  170978. *(rp) = (png_byte)((256 + *rp + *(rp+1))&0xff);
  170979. *(rp+2) = (png_byte)((256 + *(rp+2) + *(rp+1))&0xff);
  170980. }
  170981. }
  170982. else if (row_info->bit_depth == 16)
  170983. {
  170984. png_bytep rp;
  170985. png_uint_32 i;
  170986. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  170987. bytes_per_pixel = 6;
  170988. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  170989. bytes_per_pixel = 8;
  170990. else
  170991. return;
  170992. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  170993. {
  170994. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  170995. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  170996. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  170997. png_uint_32 red = (png_uint_32)((s0+s1+65536L) & 0xffffL);
  170998. png_uint_32 blue = (png_uint_32)((s2+s1+65536L) & 0xffffL);
  170999. *(rp ) = (png_byte)((red >> 8) & 0xff);
  171000. *(rp+1) = (png_byte)(red & 0xff);
  171001. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  171002. *(rp+5) = (png_byte)(blue & 0xff);
  171003. }
  171004. }
  171005. }
  171006. }
  171007. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  171008. #endif /* PNG_READ_SUPPORTED */
  171009. /*** End of inlined file: pngrtran.c ***/
  171010. /*** Start of inlined file: pngrutil.c ***/
  171011. #define PNG_INTERNAL
  171012. #if defined(PNG_READ_SUPPORTED)
  171013. #if defined(_WIN32_WCE) && (_WIN32_WCE<0x500)
  171014. # define WIN32_WCE_OLD
  171015. #endif
  171016. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171017. # if defined(WIN32_WCE_OLD)
  171018. __inline double png_strtod(png_structp png_ptr, PNG_CONST char *nptr, char **endptr)
  171019. {
  171020. double result = 0;
  171021. int len;
  171022. wchar_t *str, *end;
  171023. len = MultiByteToWideChar(CP_ACP, 0, nptr, -1, NULL, 0);
  171024. str = (wchar_t *)png_malloc(png_ptr, len * sizeof(wchar_t));
  171025. if ( NULL != str )
  171026. {
  171027. MultiByteToWideChar(CP_ACP, 0, nptr, -1, str, len);
  171028. result = wcstod(str, &end);
  171029. len = WideCharToMultiByte(CP_ACP, 0, end, -1, NULL, 0, NULL, NULL);
  171030. *endptr = (char *)nptr + (png_strlen(nptr) - len + 1);
  171031. png_free(png_ptr, str);
  171032. }
  171033. return result;
  171034. }
  171035. # else
  171036. # define png_strtod(p,a,b) strtod(a,b)
  171037. # endif
  171038. #endif
  171039. png_uint_32 PNGAPI
  171040. png_get_uint_31(png_structp png_ptr, png_bytep buf)
  171041. {
  171042. png_uint_32 i = png_get_uint_32(buf);
  171043. if (i > PNG_UINT_31_MAX)
  171044. png_error(png_ptr, "PNG unsigned integer out of range.");
  171045. return (i);
  171046. }
  171047. #ifndef PNG_READ_BIG_ENDIAN_SUPPORTED
  171048. png_uint_32 PNGAPI
  171049. png_get_uint_32(png_bytep buf)
  171050. {
  171051. png_uint_32 i = ((png_uint_32)(*buf) << 24) +
  171052. ((png_uint_32)(*(buf + 1)) << 16) +
  171053. ((png_uint_32)(*(buf + 2)) << 8) +
  171054. (png_uint_32)(*(buf + 3));
  171055. return (i);
  171056. }
  171057. png_int_32 PNGAPI
  171058. png_get_int_32(png_bytep buf)
  171059. {
  171060. png_int_32 i = ((png_int_32)(*buf) << 24) +
  171061. ((png_int_32)(*(buf + 1)) << 16) +
  171062. ((png_int_32)(*(buf + 2)) << 8) +
  171063. (png_int_32)(*(buf + 3));
  171064. return (i);
  171065. }
  171066. png_uint_16 PNGAPI
  171067. png_get_uint_16(png_bytep buf)
  171068. {
  171069. png_uint_16 i = (png_uint_16)(((png_uint_16)(*buf) << 8) +
  171070. (png_uint_16)(*(buf + 1)));
  171071. return (i);
  171072. }
  171073. #endif /* PNG_READ_BIG_ENDIAN_SUPPORTED */
  171074. void /* PRIVATE */
  171075. png_crc_read(png_structp png_ptr, png_bytep buf, png_size_t length)
  171076. {
  171077. if(png_ptr == NULL) return;
  171078. png_read_data(png_ptr, buf, length);
  171079. png_calculate_crc(png_ptr, buf, length);
  171080. }
  171081. int /* PRIVATE */
  171082. png_crc_finish(png_structp png_ptr, png_uint_32 skip)
  171083. {
  171084. png_size_t i;
  171085. png_size_t istop = png_ptr->zbuf_size;
  171086. for (i = (png_size_t)skip; i > istop; i -= istop)
  171087. {
  171088. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  171089. }
  171090. if (i)
  171091. {
  171092. png_crc_read(png_ptr, png_ptr->zbuf, i);
  171093. }
  171094. if (png_crc_error(png_ptr))
  171095. {
  171096. if (((png_ptr->chunk_name[0] & 0x20) && /* Ancillary */
  171097. !(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)) ||
  171098. (!(png_ptr->chunk_name[0] & 0x20) && /* Critical */
  171099. (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_USE)))
  171100. {
  171101. png_chunk_warning(png_ptr, "CRC error");
  171102. }
  171103. else
  171104. {
  171105. png_chunk_error(png_ptr, "CRC error");
  171106. }
  171107. return (1);
  171108. }
  171109. return (0);
  171110. }
  171111. int /* PRIVATE */
  171112. png_crc_error(png_structp png_ptr)
  171113. {
  171114. png_byte crc_bytes[4];
  171115. png_uint_32 crc;
  171116. int need_crc = 1;
  171117. if (png_ptr->chunk_name[0] & 0x20) /* ancillary */
  171118. {
  171119. if ((png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_MASK) ==
  171120. (PNG_FLAG_CRC_ANCILLARY_USE | PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171121. need_crc = 0;
  171122. }
  171123. else /* critical */
  171124. {
  171125. if (png_ptr->flags & PNG_FLAG_CRC_CRITICAL_IGNORE)
  171126. need_crc = 0;
  171127. }
  171128. png_read_data(png_ptr, crc_bytes, 4);
  171129. if (need_crc)
  171130. {
  171131. crc = png_get_uint_32(crc_bytes);
  171132. return ((int)(crc != png_ptr->crc));
  171133. }
  171134. else
  171135. return (0);
  171136. }
  171137. #if defined(PNG_READ_zTXt_SUPPORTED) || defined(PNG_READ_iTXt_SUPPORTED) || \
  171138. defined(PNG_READ_iCCP_SUPPORTED)
  171139. png_charp /* PRIVATE */
  171140. png_decompress_chunk(png_structp png_ptr, int comp_type,
  171141. png_charp chunkdata, png_size_t chunklength,
  171142. png_size_t prefix_size, png_size_t *newlength)
  171143. {
  171144. static PNG_CONST char msg[] = "Error decoding compressed text";
  171145. png_charp text;
  171146. png_size_t text_size;
  171147. if (comp_type == PNG_COMPRESSION_TYPE_BASE)
  171148. {
  171149. int ret = Z_OK;
  171150. png_ptr->zstream.next_in = (png_bytep)(chunkdata + prefix_size);
  171151. png_ptr->zstream.avail_in = (uInt)(chunklength - prefix_size);
  171152. png_ptr->zstream.next_out = png_ptr->zbuf;
  171153. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  171154. text_size = 0;
  171155. text = NULL;
  171156. while (png_ptr->zstream.avail_in)
  171157. {
  171158. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  171159. if (ret != Z_OK && ret != Z_STREAM_END)
  171160. {
  171161. if (png_ptr->zstream.msg != NULL)
  171162. png_warning(png_ptr, png_ptr->zstream.msg);
  171163. else
  171164. png_warning(png_ptr, msg);
  171165. inflateReset(&png_ptr->zstream);
  171166. png_ptr->zstream.avail_in = 0;
  171167. if (text == NULL)
  171168. {
  171169. text_size = prefix_size + png_sizeof(msg) + 1;
  171170. text = (png_charp)png_malloc_warn(png_ptr, text_size);
  171171. if (text == NULL)
  171172. {
  171173. png_free(png_ptr,chunkdata);
  171174. png_error(png_ptr,"Not enough memory to decompress chunk");
  171175. }
  171176. png_memcpy(text, chunkdata, prefix_size);
  171177. }
  171178. text[text_size - 1] = 0x00;
  171179. text_size = (png_size_t)(chunklength - (text - chunkdata) - 1);
  171180. text_size = png_sizeof(msg) > text_size ? text_size :
  171181. png_sizeof(msg);
  171182. png_memcpy(text + prefix_size, msg, text_size + 1);
  171183. break;
  171184. }
  171185. if (!png_ptr->zstream.avail_out || ret == Z_STREAM_END)
  171186. {
  171187. if (text == NULL)
  171188. {
  171189. text_size = prefix_size +
  171190. png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  171191. text = (png_charp)png_malloc_warn(png_ptr, text_size + 1);
  171192. if (text == NULL)
  171193. {
  171194. png_free(png_ptr,chunkdata);
  171195. png_error(png_ptr,"Not enough memory to decompress chunk.");
  171196. }
  171197. png_memcpy(text + prefix_size, png_ptr->zbuf,
  171198. text_size - prefix_size);
  171199. png_memcpy(text, chunkdata, prefix_size);
  171200. *(text + text_size) = 0x00;
  171201. }
  171202. else
  171203. {
  171204. png_charp tmp;
  171205. tmp = text;
  171206. text = (png_charp)png_malloc_warn(png_ptr,
  171207. (png_uint_32)(text_size +
  171208. png_ptr->zbuf_size - png_ptr->zstream.avail_out + 1));
  171209. if (text == NULL)
  171210. {
  171211. png_free(png_ptr, tmp);
  171212. png_free(png_ptr, chunkdata);
  171213. png_error(png_ptr,"Not enough memory to decompress chunk..");
  171214. }
  171215. png_memcpy(text, tmp, text_size);
  171216. png_free(png_ptr, tmp);
  171217. png_memcpy(text + text_size, png_ptr->zbuf,
  171218. (png_ptr->zbuf_size - png_ptr->zstream.avail_out));
  171219. text_size += png_ptr->zbuf_size - png_ptr->zstream.avail_out;
  171220. *(text + text_size) = 0x00;
  171221. }
  171222. if (ret == Z_STREAM_END)
  171223. break;
  171224. else
  171225. {
  171226. png_ptr->zstream.next_out = png_ptr->zbuf;
  171227. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  171228. }
  171229. }
  171230. }
  171231. if (ret != Z_STREAM_END)
  171232. {
  171233. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171234. char umsg[52];
  171235. if (ret == Z_BUF_ERROR)
  171236. png_snprintf(umsg, 52,
  171237. "Buffer error in compressed datastream in %s chunk",
  171238. png_ptr->chunk_name);
  171239. else if (ret == Z_DATA_ERROR)
  171240. png_snprintf(umsg, 52,
  171241. "Data error in compressed datastream in %s chunk",
  171242. png_ptr->chunk_name);
  171243. else
  171244. png_snprintf(umsg, 52,
  171245. "Incomplete compressed datastream in %s chunk",
  171246. png_ptr->chunk_name);
  171247. png_warning(png_ptr, umsg);
  171248. #else
  171249. png_warning(png_ptr,
  171250. "Incomplete compressed datastream in chunk other than IDAT");
  171251. #endif
  171252. text_size=prefix_size;
  171253. if (text == NULL)
  171254. {
  171255. text = (png_charp)png_malloc_warn(png_ptr, text_size+1);
  171256. if (text == NULL)
  171257. {
  171258. png_free(png_ptr, chunkdata);
  171259. png_error(png_ptr,"Not enough memory for text.");
  171260. }
  171261. png_memcpy(text, chunkdata, prefix_size);
  171262. }
  171263. *(text + text_size) = 0x00;
  171264. }
  171265. inflateReset(&png_ptr->zstream);
  171266. png_ptr->zstream.avail_in = 0;
  171267. png_free(png_ptr, chunkdata);
  171268. chunkdata = text;
  171269. *newlength=text_size;
  171270. }
  171271. else /* if (comp_type != PNG_COMPRESSION_TYPE_BASE) */
  171272. {
  171273. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  171274. char umsg[50];
  171275. png_snprintf(umsg, 50,
  171276. "Unknown zTXt compression type %d", comp_type);
  171277. png_warning(png_ptr, umsg);
  171278. #else
  171279. png_warning(png_ptr, "Unknown zTXt compression type");
  171280. #endif
  171281. *(chunkdata + prefix_size) = 0x00;
  171282. *newlength=prefix_size;
  171283. }
  171284. return chunkdata;
  171285. }
  171286. #endif
  171287. void /* PRIVATE */
  171288. png_handle_IHDR(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171289. {
  171290. png_byte buf[13];
  171291. png_uint_32 width, height;
  171292. int bit_depth, color_type, compression_type, filter_type;
  171293. int interlace_type;
  171294. png_debug(1, "in png_handle_IHDR\n");
  171295. if (png_ptr->mode & PNG_HAVE_IHDR)
  171296. png_error(png_ptr, "Out of place IHDR");
  171297. if (length != 13)
  171298. png_error(png_ptr, "Invalid IHDR chunk");
  171299. png_ptr->mode |= PNG_HAVE_IHDR;
  171300. png_crc_read(png_ptr, buf, 13);
  171301. png_crc_finish(png_ptr, 0);
  171302. width = png_get_uint_31(png_ptr, buf);
  171303. height = png_get_uint_31(png_ptr, buf + 4);
  171304. bit_depth = buf[8];
  171305. color_type = buf[9];
  171306. compression_type = buf[10];
  171307. filter_type = buf[11];
  171308. interlace_type = buf[12];
  171309. png_ptr->width = width;
  171310. png_ptr->height = height;
  171311. png_ptr->bit_depth = (png_byte)bit_depth;
  171312. png_ptr->interlaced = (png_byte)interlace_type;
  171313. png_ptr->color_type = (png_byte)color_type;
  171314. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  171315. png_ptr->filter_type = (png_byte)filter_type;
  171316. #endif
  171317. png_ptr->compression_type = (png_byte)compression_type;
  171318. switch (png_ptr->color_type)
  171319. {
  171320. case PNG_COLOR_TYPE_GRAY:
  171321. case PNG_COLOR_TYPE_PALETTE:
  171322. png_ptr->channels = 1;
  171323. break;
  171324. case PNG_COLOR_TYPE_RGB:
  171325. png_ptr->channels = 3;
  171326. break;
  171327. case PNG_COLOR_TYPE_GRAY_ALPHA:
  171328. png_ptr->channels = 2;
  171329. break;
  171330. case PNG_COLOR_TYPE_RGB_ALPHA:
  171331. png_ptr->channels = 4;
  171332. break;
  171333. }
  171334. png_ptr->pixel_depth = (png_byte)(png_ptr->bit_depth *
  171335. png_ptr->channels);
  171336. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->width);
  171337. png_debug1(3,"bit_depth = %d\n", png_ptr->bit_depth);
  171338. png_debug1(3,"channels = %d\n", png_ptr->channels);
  171339. png_debug1(3,"rowbytes = %lu\n", png_ptr->rowbytes);
  171340. png_set_IHDR(png_ptr, info_ptr, width, height, bit_depth,
  171341. color_type, interlace_type, compression_type, filter_type);
  171342. }
  171343. void /* PRIVATE */
  171344. png_handle_PLTE(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171345. {
  171346. png_color palette[PNG_MAX_PALETTE_LENGTH];
  171347. int num, i;
  171348. #ifndef PNG_NO_POINTER_INDEXING
  171349. png_colorp pal_ptr;
  171350. #endif
  171351. png_debug(1, "in png_handle_PLTE\n");
  171352. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171353. png_error(png_ptr, "Missing IHDR before PLTE");
  171354. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171355. {
  171356. png_warning(png_ptr, "Invalid PLTE after IDAT");
  171357. png_crc_finish(png_ptr, length);
  171358. return;
  171359. }
  171360. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171361. png_error(png_ptr, "Duplicate PLTE chunk");
  171362. png_ptr->mode |= PNG_HAVE_PLTE;
  171363. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  171364. {
  171365. png_warning(png_ptr,
  171366. "Ignoring PLTE chunk in grayscale PNG");
  171367. png_crc_finish(png_ptr, length);
  171368. return;
  171369. }
  171370. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171371. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171372. {
  171373. png_crc_finish(png_ptr, length);
  171374. return;
  171375. }
  171376. #endif
  171377. if (length > 3*PNG_MAX_PALETTE_LENGTH || length % 3)
  171378. {
  171379. if (png_ptr->color_type != PNG_COLOR_TYPE_PALETTE)
  171380. {
  171381. png_warning(png_ptr, "Invalid palette chunk");
  171382. png_crc_finish(png_ptr, length);
  171383. return;
  171384. }
  171385. else
  171386. {
  171387. png_error(png_ptr, "Invalid palette chunk");
  171388. }
  171389. }
  171390. num = (int)length / 3;
  171391. #ifndef PNG_NO_POINTER_INDEXING
  171392. for (i = 0, pal_ptr = palette; i < num; i++, pal_ptr++)
  171393. {
  171394. png_byte buf[3];
  171395. png_crc_read(png_ptr, buf, 3);
  171396. pal_ptr->red = buf[0];
  171397. pal_ptr->green = buf[1];
  171398. pal_ptr->blue = buf[2];
  171399. }
  171400. #else
  171401. for (i = 0; i < num; i++)
  171402. {
  171403. png_byte buf[3];
  171404. png_crc_read(png_ptr, buf, 3);
  171405. palette[i].red = buf[0];
  171406. palette[i].green = buf[1];
  171407. palette[i].blue = buf[2];
  171408. }
  171409. #endif
  171410. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171411. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171412. #endif
  171413. {
  171414. png_crc_finish(png_ptr, 0);
  171415. }
  171416. #if !defined(PNG_READ_OPT_PLTE_SUPPORTED)
  171417. else if (png_crc_error(png_ptr)) /* Only if we have a CRC error */
  171418. {
  171419. if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_USE))
  171420. {
  171421. if (png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN)
  171422. {
  171423. png_chunk_error(png_ptr, "CRC error");
  171424. }
  171425. else
  171426. {
  171427. png_chunk_warning(png_ptr, "CRC error");
  171428. return;
  171429. }
  171430. }
  171431. else if (!(png_ptr->flags & PNG_FLAG_CRC_ANCILLARY_NOWARN))
  171432. {
  171433. png_chunk_warning(png_ptr, "CRC error");
  171434. }
  171435. }
  171436. #endif
  171437. png_set_PLTE(png_ptr, info_ptr, palette, num);
  171438. #if defined(PNG_READ_tRNS_SUPPORTED)
  171439. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171440. {
  171441. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  171442. {
  171443. if (png_ptr->num_trans > (png_uint_16)num)
  171444. {
  171445. png_warning(png_ptr, "Truncating incorrect tRNS chunk length");
  171446. png_ptr->num_trans = (png_uint_16)num;
  171447. }
  171448. if (info_ptr->num_trans > (png_uint_16)num)
  171449. {
  171450. png_warning(png_ptr, "Truncating incorrect info tRNS chunk length");
  171451. info_ptr->num_trans = (png_uint_16)num;
  171452. }
  171453. }
  171454. }
  171455. #endif
  171456. }
  171457. void /* PRIVATE */
  171458. png_handle_IEND(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171459. {
  171460. png_debug(1, "in png_handle_IEND\n");
  171461. if (!(png_ptr->mode & PNG_HAVE_IHDR) || !(png_ptr->mode & PNG_HAVE_IDAT))
  171462. {
  171463. png_error(png_ptr, "No image in file");
  171464. }
  171465. png_ptr->mode |= (PNG_AFTER_IDAT | PNG_HAVE_IEND);
  171466. if (length != 0)
  171467. {
  171468. png_warning(png_ptr, "Incorrect IEND chunk length");
  171469. }
  171470. png_crc_finish(png_ptr, length);
  171471. info_ptr =info_ptr; /* quiet compiler warnings about unused info_ptr */
  171472. }
  171473. #if defined(PNG_READ_gAMA_SUPPORTED)
  171474. void /* PRIVATE */
  171475. png_handle_gAMA(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171476. {
  171477. png_fixed_point igamma;
  171478. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171479. float file_gamma;
  171480. #endif
  171481. png_byte buf[4];
  171482. png_debug(1, "in png_handle_gAMA\n");
  171483. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171484. png_error(png_ptr, "Missing IHDR before gAMA");
  171485. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171486. {
  171487. png_warning(png_ptr, "Invalid gAMA after IDAT");
  171488. png_crc_finish(png_ptr, length);
  171489. return;
  171490. }
  171491. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171492. png_warning(png_ptr, "Out of place gAMA chunk");
  171493. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA)
  171494. #if defined(PNG_READ_sRGB_SUPPORTED)
  171495. && !(info_ptr->valid & PNG_INFO_sRGB)
  171496. #endif
  171497. )
  171498. {
  171499. png_warning(png_ptr, "Duplicate gAMA chunk");
  171500. png_crc_finish(png_ptr, length);
  171501. return;
  171502. }
  171503. if (length != 4)
  171504. {
  171505. png_warning(png_ptr, "Incorrect gAMA chunk length");
  171506. png_crc_finish(png_ptr, length);
  171507. return;
  171508. }
  171509. png_crc_read(png_ptr, buf, 4);
  171510. if (png_crc_finish(png_ptr, 0))
  171511. return;
  171512. igamma = (png_fixed_point)png_get_uint_32(buf);
  171513. if (igamma == 0)
  171514. {
  171515. png_warning(png_ptr,
  171516. "Ignoring gAMA chunk with gamma=0");
  171517. return;
  171518. }
  171519. #if defined(PNG_READ_sRGB_SUPPORTED)
  171520. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171521. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171522. {
  171523. png_warning(png_ptr,
  171524. "Ignoring incorrect gAMA value when sRGB is also present");
  171525. #ifndef PNG_NO_CONSOLE_IO
  171526. fprintf(stderr, "gamma = (%d/100000)\n", (int)igamma);
  171527. #endif
  171528. return;
  171529. }
  171530. #endif /* PNG_READ_sRGB_SUPPORTED */
  171531. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171532. file_gamma = (float)igamma / (float)100000.0;
  171533. # ifdef PNG_READ_GAMMA_SUPPORTED
  171534. png_ptr->gamma = file_gamma;
  171535. # endif
  171536. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  171537. #endif
  171538. #ifdef PNG_FIXED_POINT_SUPPORTED
  171539. png_set_gAMA_fixed(png_ptr, info_ptr, igamma);
  171540. #endif
  171541. }
  171542. #endif
  171543. #if defined(PNG_READ_sBIT_SUPPORTED)
  171544. void /* PRIVATE */
  171545. png_handle_sBIT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171546. {
  171547. png_size_t truelen;
  171548. png_byte buf[4];
  171549. png_debug(1, "in png_handle_sBIT\n");
  171550. buf[0] = buf[1] = buf[2] = buf[3] = 0;
  171551. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171552. png_error(png_ptr, "Missing IHDR before sBIT");
  171553. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171554. {
  171555. png_warning(png_ptr, "Invalid sBIT after IDAT");
  171556. png_crc_finish(png_ptr, length);
  171557. return;
  171558. }
  171559. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171560. {
  171561. png_warning(png_ptr, "Out of place sBIT chunk");
  171562. }
  171563. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sBIT))
  171564. {
  171565. png_warning(png_ptr, "Duplicate sBIT chunk");
  171566. png_crc_finish(png_ptr, length);
  171567. return;
  171568. }
  171569. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  171570. truelen = 3;
  171571. else
  171572. truelen = (png_size_t)png_ptr->channels;
  171573. if (length != truelen || length > 4)
  171574. {
  171575. png_warning(png_ptr, "Incorrect sBIT chunk length");
  171576. png_crc_finish(png_ptr, length);
  171577. return;
  171578. }
  171579. png_crc_read(png_ptr, buf, truelen);
  171580. if (png_crc_finish(png_ptr, 0))
  171581. return;
  171582. if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  171583. {
  171584. png_ptr->sig_bit.red = buf[0];
  171585. png_ptr->sig_bit.green = buf[1];
  171586. png_ptr->sig_bit.blue = buf[2];
  171587. png_ptr->sig_bit.alpha = buf[3];
  171588. }
  171589. else
  171590. {
  171591. png_ptr->sig_bit.gray = buf[0];
  171592. png_ptr->sig_bit.red = buf[0];
  171593. png_ptr->sig_bit.green = buf[0];
  171594. png_ptr->sig_bit.blue = buf[0];
  171595. png_ptr->sig_bit.alpha = buf[1];
  171596. }
  171597. png_set_sBIT(png_ptr, info_ptr, &(png_ptr->sig_bit));
  171598. }
  171599. #endif
  171600. #if defined(PNG_READ_cHRM_SUPPORTED)
  171601. void /* PRIVATE */
  171602. png_handle_cHRM(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171603. {
  171604. png_byte buf[4];
  171605. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171606. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  171607. #endif
  171608. png_fixed_point int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171609. int_y_green, int_x_blue, int_y_blue;
  171610. png_uint_32 uint_x, uint_y;
  171611. png_debug(1, "in png_handle_cHRM\n");
  171612. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171613. png_error(png_ptr, "Missing IHDR before cHRM");
  171614. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171615. {
  171616. png_warning(png_ptr, "Invalid cHRM after IDAT");
  171617. png_crc_finish(png_ptr, length);
  171618. return;
  171619. }
  171620. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171621. png_warning(png_ptr, "Missing PLTE before cHRM");
  171622. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM)
  171623. #if defined(PNG_READ_sRGB_SUPPORTED)
  171624. && !(info_ptr->valid & PNG_INFO_sRGB)
  171625. #endif
  171626. )
  171627. {
  171628. png_warning(png_ptr, "Duplicate cHRM chunk");
  171629. png_crc_finish(png_ptr, length);
  171630. return;
  171631. }
  171632. if (length != 32)
  171633. {
  171634. png_warning(png_ptr, "Incorrect cHRM chunk length");
  171635. png_crc_finish(png_ptr, length);
  171636. return;
  171637. }
  171638. png_crc_read(png_ptr, buf, 4);
  171639. uint_x = png_get_uint_32(buf);
  171640. png_crc_read(png_ptr, buf, 4);
  171641. uint_y = png_get_uint_32(buf);
  171642. if (uint_x > 80000L || uint_y > 80000L ||
  171643. uint_x + uint_y > 100000L)
  171644. {
  171645. png_warning(png_ptr, "Invalid cHRM white point");
  171646. png_crc_finish(png_ptr, 24);
  171647. return;
  171648. }
  171649. int_x_white = (png_fixed_point)uint_x;
  171650. int_y_white = (png_fixed_point)uint_y;
  171651. png_crc_read(png_ptr, buf, 4);
  171652. uint_x = png_get_uint_32(buf);
  171653. png_crc_read(png_ptr, buf, 4);
  171654. uint_y = png_get_uint_32(buf);
  171655. if (uint_x + uint_y > 100000L)
  171656. {
  171657. png_warning(png_ptr, "Invalid cHRM red point");
  171658. png_crc_finish(png_ptr, 16);
  171659. return;
  171660. }
  171661. int_x_red = (png_fixed_point)uint_x;
  171662. int_y_red = (png_fixed_point)uint_y;
  171663. png_crc_read(png_ptr, buf, 4);
  171664. uint_x = png_get_uint_32(buf);
  171665. png_crc_read(png_ptr, buf, 4);
  171666. uint_y = png_get_uint_32(buf);
  171667. if (uint_x + uint_y > 100000L)
  171668. {
  171669. png_warning(png_ptr, "Invalid cHRM green point");
  171670. png_crc_finish(png_ptr, 8);
  171671. return;
  171672. }
  171673. int_x_green = (png_fixed_point)uint_x;
  171674. int_y_green = (png_fixed_point)uint_y;
  171675. png_crc_read(png_ptr, buf, 4);
  171676. uint_x = png_get_uint_32(buf);
  171677. png_crc_read(png_ptr, buf, 4);
  171678. uint_y = png_get_uint_32(buf);
  171679. if (uint_x + uint_y > 100000L)
  171680. {
  171681. png_warning(png_ptr, "Invalid cHRM blue point");
  171682. png_crc_finish(png_ptr, 0);
  171683. return;
  171684. }
  171685. int_x_blue = (png_fixed_point)uint_x;
  171686. int_y_blue = (png_fixed_point)uint_y;
  171687. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171688. white_x = (float)int_x_white / (float)100000.0;
  171689. white_y = (float)int_y_white / (float)100000.0;
  171690. red_x = (float)int_x_red / (float)100000.0;
  171691. red_y = (float)int_y_red / (float)100000.0;
  171692. green_x = (float)int_x_green / (float)100000.0;
  171693. green_y = (float)int_y_green / (float)100000.0;
  171694. blue_x = (float)int_x_blue / (float)100000.0;
  171695. blue_y = (float)int_y_blue / (float)100000.0;
  171696. #endif
  171697. #if defined(PNG_READ_sRGB_SUPPORTED)
  171698. if ((info_ptr != NULL) && (info_ptr->valid & PNG_INFO_sRGB))
  171699. {
  171700. if (PNG_OUT_OF_RANGE(int_x_white, 31270, 1000) ||
  171701. PNG_OUT_OF_RANGE(int_y_white, 32900, 1000) ||
  171702. PNG_OUT_OF_RANGE(int_x_red, 64000L, 1000) ||
  171703. PNG_OUT_OF_RANGE(int_y_red, 33000, 1000) ||
  171704. PNG_OUT_OF_RANGE(int_x_green, 30000, 1000) ||
  171705. PNG_OUT_OF_RANGE(int_y_green, 60000L, 1000) ||
  171706. PNG_OUT_OF_RANGE(int_x_blue, 15000, 1000) ||
  171707. PNG_OUT_OF_RANGE(int_y_blue, 6000, 1000))
  171708. {
  171709. png_warning(png_ptr,
  171710. "Ignoring incorrect cHRM value when sRGB is also present");
  171711. #ifndef PNG_NO_CONSOLE_IO
  171712. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171713. fprintf(stderr,"wx=%f, wy=%f, rx=%f, ry=%f\n",
  171714. white_x, white_y, red_x, red_y);
  171715. fprintf(stderr,"gx=%f, gy=%f, bx=%f, by=%f\n",
  171716. green_x, green_y, blue_x, blue_y);
  171717. #else
  171718. fprintf(stderr,"wx=%ld, wy=%ld, rx=%ld, ry=%ld\n",
  171719. int_x_white, int_y_white, int_x_red, int_y_red);
  171720. fprintf(stderr,"gx=%ld, gy=%ld, bx=%ld, by=%ld\n",
  171721. int_x_green, int_y_green, int_x_blue, int_y_blue);
  171722. #endif
  171723. #endif /* PNG_NO_CONSOLE_IO */
  171724. }
  171725. png_crc_finish(png_ptr, 0);
  171726. return;
  171727. }
  171728. #endif /* PNG_READ_sRGB_SUPPORTED */
  171729. #ifdef PNG_FLOATING_POINT_SUPPORTED
  171730. png_set_cHRM(png_ptr, info_ptr,
  171731. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  171732. #endif
  171733. #ifdef PNG_FIXED_POINT_SUPPORTED
  171734. png_set_cHRM_fixed(png_ptr, info_ptr,
  171735. int_x_white, int_y_white, int_x_red, int_y_red, int_x_green,
  171736. int_y_green, int_x_blue, int_y_blue);
  171737. #endif
  171738. if (png_crc_finish(png_ptr, 0))
  171739. return;
  171740. }
  171741. #endif
  171742. #if defined(PNG_READ_sRGB_SUPPORTED)
  171743. void /* PRIVATE */
  171744. png_handle_sRGB(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171745. {
  171746. int intent;
  171747. png_byte buf[1];
  171748. png_debug(1, "in png_handle_sRGB\n");
  171749. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171750. png_error(png_ptr, "Missing IHDR before sRGB");
  171751. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171752. {
  171753. png_warning(png_ptr, "Invalid sRGB after IDAT");
  171754. png_crc_finish(png_ptr, length);
  171755. return;
  171756. }
  171757. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171758. png_warning(png_ptr, "Out of place sRGB chunk");
  171759. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sRGB))
  171760. {
  171761. png_warning(png_ptr, "Duplicate sRGB chunk");
  171762. png_crc_finish(png_ptr, length);
  171763. return;
  171764. }
  171765. if (length != 1)
  171766. {
  171767. png_warning(png_ptr, "Incorrect sRGB chunk length");
  171768. png_crc_finish(png_ptr, length);
  171769. return;
  171770. }
  171771. png_crc_read(png_ptr, buf, 1);
  171772. if (png_crc_finish(png_ptr, 0))
  171773. return;
  171774. intent = buf[0];
  171775. if (intent >= PNG_sRGB_INTENT_LAST)
  171776. {
  171777. png_warning(png_ptr, "Unknown sRGB intent");
  171778. return;
  171779. }
  171780. #if defined(PNG_READ_gAMA_SUPPORTED) && defined(PNG_READ_GAMMA_SUPPORTED)
  171781. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_gAMA))
  171782. {
  171783. png_fixed_point igamma;
  171784. #ifdef PNG_FIXED_POINT_SUPPORTED
  171785. igamma=info_ptr->int_gamma;
  171786. #else
  171787. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171788. igamma=(png_fixed_point)(info_ptr->gamma * 100000.);
  171789. # endif
  171790. #endif
  171791. if (PNG_OUT_OF_RANGE(igamma, 45500L, 500))
  171792. {
  171793. png_warning(png_ptr,
  171794. "Ignoring incorrect gAMA value when sRGB is also present");
  171795. #ifndef PNG_NO_CONSOLE_IO
  171796. # ifdef PNG_FIXED_POINT_SUPPORTED
  171797. fprintf(stderr,"incorrect gamma=(%d/100000)\n",(int)png_ptr->int_gamma);
  171798. # else
  171799. # ifdef PNG_FLOATING_POINT_SUPPORTED
  171800. fprintf(stderr,"incorrect gamma=%f\n",png_ptr->gamma);
  171801. # endif
  171802. # endif
  171803. #endif
  171804. }
  171805. }
  171806. #endif /* PNG_READ_gAMA_SUPPORTED */
  171807. #ifdef PNG_READ_cHRM_SUPPORTED
  171808. #ifdef PNG_FIXED_POINT_SUPPORTED
  171809. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_cHRM))
  171810. if (PNG_OUT_OF_RANGE(info_ptr->int_x_white, 31270, 1000) ||
  171811. PNG_OUT_OF_RANGE(info_ptr->int_y_white, 32900, 1000) ||
  171812. PNG_OUT_OF_RANGE(info_ptr->int_x_red, 64000L, 1000) ||
  171813. PNG_OUT_OF_RANGE(info_ptr->int_y_red, 33000, 1000) ||
  171814. PNG_OUT_OF_RANGE(info_ptr->int_x_green, 30000, 1000) ||
  171815. PNG_OUT_OF_RANGE(info_ptr->int_y_green, 60000L, 1000) ||
  171816. PNG_OUT_OF_RANGE(info_ptr->int_x_blue, 15000, 1000) ||
  171817. PNG_OUT_OF_RANGE(info_ptr->int_y_blue, 6000, 1000))
  171818. {
  171819. png_warning(png_ptr,
  171820. "Ignoring incorrect cHRM value when sRGB is also present");
  171821. }
  171822. #endif /* PNG_FIXED_POINT_SUPPORTED */
  171823. #endif /* PNG_READ_cHRM_SUPPORTED */
  171824. png_set_sRGB_gAMA_and_cHRM(png_ptr, info_ptr, intent);
  171825. }
  171826. #endif /* PNG_READ_sRGB_SUPPORTED */
  171827. #if defined(PNG_READ_iCCP_SUPPORTED)
  171828. void /* PRIVATE */
  171829. png_handle_iCCP(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171830. {
  171831. png_charp chunkdata;
  171832. png_byte compression_type;
  171833. png_bytep pC;
  171834. png_charp profile;
  171835. png_uint_32 skip = 0;
  171836. png_uint_32 profile_size, profile_length;
  171837. png_size_t slength, prefix_length, data_length;
  171838. png_debug(1, "in png_handle_iCCP\n");
  171839. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171840. png_error(png_ptr, "Missing IHDR before iCCP");
  171841. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171842. {
  171843. png_warning(png_ptr, "Invalid iCCP after IDAT");
  171844. png_crc_finish(png_ptr, length);
  171845. return;
  171846. }
  171847. else if (png_ptr->mode & PNG_HAVE_PLTE)
  171848. png_warning(png_ptr, "Out of place iCCP chunk");
  171849. if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_iCCP))
  171850. {
  171851. png_warning(png_ptr, "Duplicate iCCP chunk");
  171852. png_crc_finish(png_ptr, length);
  171853. return;
  171854. }
  171855. #ifdef PNG_MAX_MALLOC_64K
  171856. if (length > (png_uint_32)65535L)
  171857. {
  171858. png_warning(png_ptr, "iCCP chunk too large to fit in memory");
  171859. skip = length - (png_uint_32)65535L;
  171860. length = (png_uint_32)65535L;
  171861. }
  171862. #endif
  171863. chunkdata = (png_charp)png_malloc(png_ptr, length + 1);
  171864. slength = (png_size_t)length;
  171865. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171866. if (png_crc_finish(png_ptr, skip))
  171867. {
  171868. png_free(png_ptr, chunkdata);
  171869. return;
  171870. }
  171871. chunkdata[slength] = 0x00;
  171872. for (profile = chunkdata; *profile; profile++)
  171873. ;
  171874. ++profile;
  171875. if ( profile >= chunkdata + slength - 1)
  171876. {
  171877. png_free(png_ptr, chunkdata);
  171878. png_warning(png_ptr, "Malformed iCCP chunk");
  171879. return;
  171880. }
  171881. compression_type = *profile++;
  171882. if (compression_type)
  171883. {
  171884. png_warning(png_ptr, "Ignoring nonzero compression type in iCCP chunk");
  171885. compression_type=0x00; /* Reset it to zero (libpng-1.0.6 through 1.0.8
  171886. wrote nonzero) */
  171887. }
  171888. prefix_length = profile - chunkdata;
  171889. chunkdata = png_decompress_chunk(png_ptr, compression_type, chunkdata,
  171890. slength, prefix_length, &data_length);
  171891. profile_length = data_length - prefix_length;
  171892. if ( prefix_length > data_length || profile_length < 4)
  171893. {
  171894. png_free(png_ptr, chunkdata);
  171895. png_warning(png_ptr, "Profile size field missing from iCCP chunk");
  171896. return;
  171897. }
  171898. pC = (png_bytep)(chunkdata+prefix_length);
  171899. profile_size = ((*(pC ))<<24) |
  171900. ((*(pC+1))<<16) |
  171901. ((*(pC+2))<< 8) |
  171902. ((*(pC+3)) );
  171903. if(profile_size < profile_length)
  171904. profile_length = profile_size;
  171905. if(profile_size > profile_length)
  171906. {
  171907. png_free(png_ptr, chunkdata);
  171908. png_warning(png_ptr, "Ignoring truncated iCCP profile.");
  171909. return;
  171910. }
  171911. png_set_iCCP(png_ptr, info_ptr, chunkdata, compression_type,
  171912. chunkdata + prefix_length, profile_length);
  171913. png_free(png_ptr, chunkdata);
  171914. }
  171915. #endif /* PNG_READ_iCCP_SUPPORTED */
  171916. #if defined(PNG_READ_sPLT_SUPPORTED)
  171917. void /* PRIVATE */
  171918. png_handle_sPLT(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  171919. {
  171920. png_bytep chunkdata;
  171921. png_bytep entry_start;
  171922. png_sPLT_t new_palette;
  171923. #ifdef PNG_NO_POINTER_INDEXING
  171924. png_sPLT_entryp pp;
  171925. #endif
  171926. int data_length, entry_size, i;
  171927. png_uint_32 skip = 0;
  171928. png_size_t slength;
  171929. png_debug(1, "in png_handle_sPLT\n");
  171930. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  171931. png_error(png_ptr, "Missing IHDR before sPLT");
  171932. else if (png_ptr->mode & PNG_HAVE_IDAT)
  171933. {
  171934. png_warning(png_ptr, "Invalid sPLT after IDAT");
  171935. png_crc_finish(png_ptr, length);
  171936. return;
  171937. }
  171938. #ifdef PNG_MAX_MALLOC_64K
  171939. if (length > (png_uint_32)65535L)
  171940. {
  171941. png_warning(png_ptr, "sPLT chunk too large to fit in memory");
  171942. skip = length - (png_uint_32)65535L;
  171943. length = (png_uint_32)65535L;
  171944. }
  171945. #endif
  171946. chunkdata = (png_bytep)png_malloc(png_ptr, length + 1);
  171947. slength = (png_size_t)length;
  171948. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  171949. if (png_crc_finish(png_ptr, skip))
  171950. {
  171951. png_free(png_ptr, chunkdata);
  171952. return;
  171953. }
  171954. chunkdata[slength] = 0x00;
  171955. for (entry_start = chunkdata; *entry_start; entry_start++)
  171956. ;
  171957. ++entry_start;
  171958. if (entry_start > chunkdata + slength - 2)
  171959. {
  171960. png_free(png_ptr, chunkdata);
  171961. png_warning(png_ptr, "malformed sPLT chunk");
  171962. return;
  171963. }
  171964. new_palette.depth = *entry_start++;
  171965. entry_size = (new_palette.depth == 8 ? 6 : 10);
  171966. data_length = (slength - (entry_start - chunkdata));
  171967. if (data_length % entry_size)
  171968. {
  171969. png_free(png_ptr, chunkdata);
  171970. png_warning(png_ptr, "sPLT chunk has bad length");
  171971. return;
  171972. }
  171973. new_palette.nentries = (png_int_32) ( data_length / entry_size);
  171974. if ((png_uint_32) new_palette.nentries > (png_uint_32) (PNG_SIZE_MAX /
  171975. png_sizeof(png_sPLT_entry)))
  171976. {
  171977. png_warning(png_ptr, "sPLT chunk too long");
  171978. return;
  171979. }
  171980. new_palette.entries = (png_sPLT_entryp)png_malloc_warn(
  171981. png_ptr, new_palette.nentries * png_sizeof(png_sPLT_entry));
  171982. if (new_palette.entries == NULL)
  171983. {
  171984. png_warning(png_ptr, "sPLT chunk requires too much memory");
  171985. return;
  171986. }
  171987. #ifndef PNG_NO_POINTER_INDEXING
  171988. for (i = 0; i < new_palette.nentries; i++)
  171989. {
  171990. png_sPLT_entryp pp = new_palette.entries + i;
  171991. if (new_palette.depth == 8)
  171992. {
  171993. pp->red = *entry_start++;
  171994. pp->green = *entry_start++;
  171995. pp->blue = *entry_start++;
  171996. pp->alpha = *entry_start++;
  171997. }
  171998. else
  171999. {
  172000. pp->red = png_get_uint_16(entry_start); entry_start += 2;
  172001. pp->green = png_get_uint_16(entry_start); entry_start += 2;
  172002. pp->blue = png_get_uint_16(entry_start); entry_start += 2;
  172003. pp->alpha = png_get_uint_16(entry_start); entry_start += 2;
  172004. }
  172005. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  172006. }
  172007. #else
  172008. pp = new_palette.entries;
  172009. for (i = 0; i < new_palette.nentries; i++)
  172010. {
  172011. if (new_palette.depth == 8)
  172012. {
  172013. pp[i].red = *entry_start++;
  172014. pp[i].green = *entry_start++;
  172015. pp[i].blue = *entry_start++;
  172016. pp[i].alpha = *entry_start++;
  172017. }
  172018. else
  172019. {
  172020. pp[i].red = png_get_uint_16(entry_start); entry_start += 2;
  172021. pp[i].green = png_get_uint_16(entry_start); entry_start += 2;
  172022. pp[i].blue = png_get_uint_16(entry_start); entry_start += 2;
  172023. pp[i].alpha = png_get_uint_16(entry_start); entry_start += 2;
  172024. }
  172025. pp->frequency = png_get_uint_16(entry_start); entry_start += 2;
  172026. }
  172027. #endif
  172028. new_palette.name = (png_charp)chunkdata;
  172029. png_set_sPLT(png_ptr, info_ptr, &new_palette, 1);
  172030. png_free(png_ptr, chunkdata);
  172031. png_free(png_ptr, new_palette.entries);
  172032. }
  172033. #endif /* PNG_READ_sPLT_SUPPORTED */
  172034. #if defined(PNG_READ_tRNS_SUPPORTED)
  172035. void /* PRIVATE */
  172036. png_handle_tRNS(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172037. {
  172038. png_byte readbuf[PNG_MAX_PALETTE_LENGTH];
  172039. int bit_mask;
  172040. png_debug(1, "in png_handle_tRNS\n");
  172041. bit_mask = (1 << png_ptr->bit_depth) - 1;
  172042. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172043. png_error(png_ptr, "Missing IHDR before tRNS");
  172044. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172045. {
  172046. png_warning(png_ptr, "Invalid tRNS after IDAT");
  172047. png_crc_finish(png_ptr, length);
  172048. return;
  172049. }
  172050. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tRNS))
  172051. {
  172052. png_warning(png_ptr, "Duplicate tRNS chunk");
  172053. png_crc_finish(png_ptr, length);
  172054. return;
  172055. }
  172056. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  172057. {
  172058. png_byte buf[2];
  172059. if (length != 2)
  172060. {
  172061. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172062. png_crc_finish(png_ptr, length);
  172063. return;
  172064. }
  172065. png_crc_read(png_ptr, buf, 2);
  172066. png_ptr->num_trans = 1;
  172067. png_ptr->trans_values.gray = png_get_uint_16(buf) & bit_mask;
  172068. }
  172069. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  172070. {
  172071. png_byte buf[6];
  172072. if (length != 6)
  172073. {
  172074. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172075. png_crc_finish(png_ptr, length);
  172076. return;
  172077. }
  172078. png_crc_read(png_ptr, buf, (png_size_t)length);
  172079. png_ptr->num_trans = 1;
  172080. png_ptr->trans_values.red = png_get_uint_16(buf) & bit_mask;
  172081. png_ptr->trans_values.green = png_get_uint_16(buf + 2) & bit_mask;
  172082. png_ptr->trans_values.blue = png_get_uint_16(buf + 4) & bit_mask;
  172083. }
  172084. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172085. {
  172086. if (!(png_ptr->mode & PNG_HAVE_PLTE))
  172087. {
  172088. png_warning(png_ptr, "Missing PLTE before tRNS");
  172089. }
  172090. if (length > (png_uint_32)png_ptr->num_palette ||
  172091. length > PNG_MAX_PALETTE_LENGTH)
  172092. {
  172093. png_warning(png_ptr, "Incorrect tRNS chunk length");
  172094. png_crc_finish(png_ptr, length);
  172095. return;
  172096. }
  172097. if (length == 0)
  172098. {
  172099. png_warning(png_ptr, "Zero length tRNS chunk");
  172100. png_crc_finish(png_ptr, length);
  172101. return;
  172102. }
  172103. png_crc_read(png_ptr, readbuf, (png_size_t)length);
  172104. png_ptr->num_trans = (png_uint_16)length;
  172105. }
  172106. else
  172107. {
  172108. png_warning(png_ptr, "tRNS chunk not allowed with alpha channel");
  172109. png_crc_finish(png_ptr, length);
  172110. return;
  172111. }
  172112. if (png_crc_finish(png_ptr, 0))
  172113. {
  172114. png_ptr->num_trans = 0;
  172115. return;
  172116. }
  172117. png_set_tRNS(png_ptr, info_ptr, readbuf, png_ptr->num_trans,
  172118. &(png_ptr->trans_values));
  172119. }
  172120. #endif
  172121. #if defined(PNG_READ_bKGD_SUPPORTED)
  172122. void /* PRIVATE */
  172123. png_handle_bKGD(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172124. {
  172125. png_size_t truelen;
  172126. png_byte buf[6];
  172127. png_debug(1, "in png_handle_bKGD\n");
  172128. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172129. png_error(png_ptr, "Missing IHDR before bKGD");
  172130. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172131. {
  172132. png_warning(png_ptr, "Invalid bKGD after IDAT");
  172133. png_crc_finish(png_ptr, length);
  172134. return;
  172135. }
  172136. else if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE &&
  172137. !(png_ptr->mode & PNG_HAVE_PLTE))
  172138. {
  172139. png_warning(png_ptr, "Missing PLTE before bKGD");
  172140. png_crc_finish(png_ptr, length);
  172141. return;
  172142. }
  172143. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_bKGD))
  172144. {
  172145. png_warning(png_ptr, "Duplicate bKGD chunk");
  172146. png_crc_finish(png_ptr, length);
  172147. return;
  172148. }
  172149. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172150. truelen = 1;
  172151. else if (png_ptr->color_type & PNG_COLOR_MASK_COLOR)
  172152. truelen = 6;
  172153. else
  172154. truelen = 2;
  172155. if (length != truelen)
  172156. {
  172157. png_warning(png_ptr, "Incorrect bKGD chunk length");
  172158. png_crc_finish(png_ptr, length);
  172159. return;
  172160. }
  172161. png_crc_read(png_ptr, buf, truelen);
  172162. if (png_crc_finish(png_ptr, 0))
  172163. return;
  172164. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  172165. {
  172166. png_ptr->background.index = buf[0];
  172167. if(info_ptr->num_palette)
  172168. {
  172169. if(buf[0] > info_ptr->num_palette)
  172170. {
  172171. png_warning(png_ptr, "Incorrect bKGD chunk index value");
  172172. return;
  172173. }
  172174. png_ptr->background.red =
  172175. (png_uint_16)png_ptr->palette[buf[0]].red;
  172176. png_ptr->background.green =
  172177. (png_uint_16)png_ptr->palette[buf[0]].green;
  172178. png_ptr->background.blue =
  172179. (png_uint_16)png_ptr->palette[buf[0]].blue;
  172180. }
  172181. }
  172182. else if (!(png_ptr->color_type & PNG_COLOR_MASK_COLOR)) /* GRAY */
  172183. {
  172184. png_ptr->background.red =
  172185. png_ptr->background.green =
  172186. png_ptr->background.blue =
  172187. png_ptr->background.gray = png_get_uint_16(buf);
  172188. }
  172189. else
  172190. {
  172191. png_ptr->background.red = png_get_uint_16(buf);
  172192. png_ptr->background.green = png_get_uint_16(buf + 2);
  172193. png_ptr->background.blue = png_get_uint_16(buf + 4);
  172194. }
  172195. png_set_bKGD(png_ptr, info_ptr, &(png_ptr->background));
  172196. }
  172197. #endif
  172198. #if defined(PNG_READ_hIST_SUPPORTED)
  172199. void /* PRIVATE */
  172200. png_handle_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172201. {
  172202. unsigned int num, i;
  172203. png_uint_16 readbuf[PNG_MAX_PALETTE_LENGTH];
  172204. png_debug(1, "in png_handle_hIST\n");
  172205. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172206. png_error(png_ptr, "Missing IHDR before hIST");
  172207. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172208. {
  172209. png_warning(png_ptr, "Invalid hIST after IDAT");
  172210. png_crc_finish(png_ptr, length);
  172211. return;
  172212. }
  172213. else if (!(png_ptr->mode & PNG_HAVE_PLTE))
  172214. {
  172215. png_warning(png_ptr, "Missing PLTE before hIST");
  172216. png_crc_finish(png_ptr, length);
  172217. return;
  172218. }
  172219. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_hIST))
  172220. {
  172221. png_warning(png_ptr, "Duplicate hIST chunk");
  172222. png_crc_finish(png_ptr, length);
  172223. return;
  172224. }
  172225. num = length / 2 ;
  172226. if (num != (unsigned int) png_ptr->num_palette || num >
  172227. (unsigned int) PNG_MAX_PALETTE_LENGTH)
  172228. {
  172229. png_warning(png_ptr, "Incorrect hIST chunk length");
  172230. png_crc_finish(png_ptr, length);
  172231. return;
  172232. }
  172233. for (i = 0; i < num; i++)
  172234. {
  172235. png_byte buf[2];
  172236. png_crc_read(png_ptr, buf, 2);
  172237. readbuf[i] = png_get_uint_16(buf);
  172238. }
  172239. if (png_crc_finish(png_ptr, 0))
  172240. return;
  172241. png_set_hIST(png_ptr, info_ptr, readbuf);
  172242. }
  172243. #endif
  172244. #if defined(PNG_READ_pHYs_SUPPORTED)
  172245. void /* PRIVATE */
  172246. png_handle_pHYs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172247. {
  172248. png_byte buf[9];
  172249. png_uint_32 res_x, res_y;
  172250. int unit_type;
  172251. png_debug(1, "in png_handle_pHYs\n");
  172252. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172253. png_error(png_ptr, "Missing IHDR before pHYs");
  172254. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172255. {
  172256. png_warning(png_ptr, "Invalid pHYs after IDAT");
  172257. png_crc_finish(png_ptr, length);
  172258. return;
  172259. }
  172260. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pHYs))
  172261. {
  172262. png_warning(png_ptr, "Duplicate pHYs chunk");
  172263. png_crc_finish(png_ptr, length);
  172264. return;
  172265. }
  172266. if (length != 9)
  172267. {
  172268. png_warning(png_ptr, "Incorrect pHYs chunk length");
  172269. png_crc_finish(png_ptr, length);
  172270. return;
  172271. }
  172272. png_crc_read(png_ptr, buf, 9);
  172273. if (png_crc_finish(png_ptr, 0))
  172274. return;
  172275. res_x = png_get_uint_32(buf);
  172276. res_y = png_get_uint_32(buf + 4);
  172277. unit_type = buf[8];
  172278. png_set_pHYs(png_ptr, info_ptr, res_x, res_y, unit_type);
  172279. }
  172280. #endif
  172281. #if defined(PNG_READ_oFFs_SUPPORTED)
  172282. void /* PRIVATE */
  172283. png_handle_oFFs(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172284. {
  172285. png_byte buf[9];
  172286. png_int_32 offset_x, offset_y;
  172287. int unit_type;
  172288. png_debug(1, "in png_handle_oFFs\n");
  172289. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172290. png_error(png_ptr, "Missing IHDR before oFFs");
  172291. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172292. {
  172293. png_warning(png_ptr, "Invalid oFFs after IDAT");
  172294. png_crc_finish(png_ptr, length);
  172295. return;
  172296. }
  172297. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_oFFs))
  172298. {
  172299. png_warning(png_ptr, "Duplicate oFFs chunk");
  172300. png_crc_finish(png_ptr, length);
  172301. return;
  172302. }
  172303. if (length != 9)
  172304. {
  172305. png_warning(png_ptr, "Incorrect oFFs chunk length");
  172306. png_crc_finish(png_ptr, length);
  172307. return;
  172308. }
  172309. png_crc_read(png_ptr, buf, 9);
  172310. if (png_crc_finish(png_ptr, 0))
  172311. return;
  172312. offset_x = png_get_int_32(buf);
  172313. offset_y = png_get_int_32(buf + 4);
  172314. unit_type = buf[8];
  172315. png_set_oFFs(png_ptr, info_ptr, offset_x, offset_y, unit_type);
  172316. }
  172317. #endif
  172318. #if defined(PNG_READ_pCAL_SUPPORTED)
  172319. void /* PRIVATE */
  172320. png_handle_pCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172321. {
  172322. png_charp purpose;
  172323. png_int_32 X0, X1;
  172324. png_byte type, nparams;
  172325. png_charp buf, units, endptr;
  172326. png_charpp params;
  172327. png_size_t slength;
  172328. int i;
  172329. png_debug(1, "in png_handle_pCAL\n");
  172330. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172331. png_error(png_ptr, "Missing IHDR before pCAL");
  172332. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172333. {
  172334. png_warning(png_ptr, "Invalid pCAL after IDAT");
  172335. png_crc_finish(png_ptr, length);
  172336. return;
  172337. }
  172338. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_pCAL))
  172339. {
  172340. png_warning(png_ptr, "Duplicate pCAL chunk");
  172341. png_crc_finish(png_ptr, length);
  172342. return;
  172343. }
  172344. png_debug1(2, "Allocating and reading pCAL chunk data (%lu bytes)\n",
  172345. length + 1);
  172346. purpose = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172347. if (purpose == NULL)
  172348. {
  172349. png_warning(png_ptr, "No memory for pCAL purpose.");
  172350. return;
  172351. }
  172352. slength = (png_size_t)length;
  172353. png_crc_read(png_ptr, (png_bytep)purpose, slength);
  172354. if (png_crc_finish(png_ptr, 0))
  172355. {
  172356. png_free(png_ptr, purpose);
  172357. return;
  172358. }
  172359. purpose[slength] = 0x00; /* null terminate the last string */
  172360. png_debug(3, "Finding end of pCAL purpose string\n");
  172361. for (buf = purpose; *buf; buf++)
  172362. ;
  172363. endptr = purpose + slength;
  172364. if (endptr <= buf + 12)
  172365. {
  172366. png_warning(png_ptr, "Invalid pCAL data");
  172367. png_free(png_ptr, purpose);
  172368. return;
  172369. }
  172370. png_debug(3, "Reading pCAL X0, X1, type, nparams, and units\n");
  172371. X0 = png_get_int_32((png_bytep)buf+1);
  172372. X1 = png_get_int_32((png_bytep)buf+5);
  172373. type = buf[9];
  172374. nparams = buf[10];
  172375. units = buf + 11;
  172376. png_debug(3, "Checking pCAL equation type and number of parameters\n");
  172377. if ((type == PNG_EQUATION_LINEAR && nparams != 2) ||
  172378. (type == PNG_EQUATION_BASE_E && nparams != 3) ||
  172379. (type == PNG_EQUATION_ARBITRARY && nparams != 3) ||
  172380. (type == PNG_EQUATION_HYPERBOLIC && nparams != 4))
  172381. {
  172382. png_warning(png_ptr, "Invalid pCAL parameters for equation type");
  172383. png_free(png_ptr, purpose);
  172384. return;
  172385. }
  172386. else if (type >= PNG_EQUATION_LAST)
  172387. {
  172388. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  172389. }
  172390. for (buf = units; *buf; buf++)
  172391. ;
  172392. png_debug(3, "Allocating pCAL parameters array\n");
  172393. params = (png_charpp)png_malloc_warn(png_ptr, (png_uint_32)(nparams
  172394. *png_sizeof(png_charp))) ;
  172395. if (params == NULL)
  172396. {
  172397. png_free(png_ptr, purpose);
  172398. png_warning(png_ptr, "No memory for pCAL params.");
  172399. return;
  172400. }
  172401. for (i = 0; i < (int)nparams; i++)
  172402. {
  172403. buf++; /* Skip the null string terminator from previous parameter. */
  172404. png_debug1(3, "Reading pCAL parameter %d\n", i);
  172405. for (params[i] = buf; buf <= endptr && *buf != 0x00; buf++)
  172406. ;
  172407. if (buf > endptr)
  172408. {
  172409. png_warning(png_ptr, "Invalid pCAL data");
  172410. png_free(png_ptr, purpose);
  172411. png_free(png_ptr, params);
  172412. return;
  172413. }
  172414. }
  172415. png_set_pCAL(png_ptr, info_ptr, purpose, X0, X1, type, nparams,
  172416. units, params);
  172417. png_free(png_ptr, purpose);
  172418. png_free(png_ptr, params);
  172419. }
  172420. #endif
  172421. #if defined(PNG_READ_sCAL_SUPPORTED)
  172422. void /* PRIVATE */
  172423. png_handle_sCAL(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172424. {
  172425. png_charp buffer, ep;
  172426. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172427. double width, height;
  172428. png_charp vp;
  172429. #else
  172430. #ifdef PNG_FIXED_POINT_SUPPORTED
  172431. png_charp swidth, sheight;
  172432. #endif
  172433. #endif
  172434. png_size_t slength;
  172435. png_debug(1, "in png_handle_sCAL\n");
  172436. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172437. png_error(png_ptr, "Missing IHDR before sCAL");
  172438. else if (png_ptr->mode & PNG_HAVE_IDAT)
  172439. {
  172440. png_warning(png_ptr, "Invalid sCAL after IDAT");
  172441. png_crc_finish(png_ptr, length);
  172442. return;
  172443. }
  172444. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_sCAL))
  172445. {
  172446. png_warning(png_ptr, "Duplicate sCAL chunk");
  172447. png_crc_finish(png_ptr, length);
  172448. return;
  172449. }
  172450. png_debug1(2, "Allocating and reading sCAL chunk data (%lu bytes)\n",
  172451. length + 1);
  172452. buffer = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172453. if (buffer == NULL)
  172454. {
  172455. png_warning(png_ptr, "Out of memory while processing sCAL chunk");
  172456. return;
  172457. }
  172458. slength = (png_size_t)length;
  172459. png_crc_read(png_ptr, (png_bytep)buffer, slength);
  172460. if (png_crc_finish(png_ptr, 0))
  172461. {
  172462. png_free(png_ptr, buffer);
  172463. return;
  172464. }
  172465. buffer[slength] = 0x00; /* null terminate the last string */
  172466. ep = buffer + 1; /* skip unit byte */
  172467. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172468. width = png_strtod(png_ptr, ep, &vp);
  172469. if (*vp)
  172470. {
  172471. png_warning(png_ptr, "malformed width string in sCAL chunk");
  172472. return;
  172473. }
  172474. #else
  172475. #ifdef PNG_FIXED_POINT_SUPPORTED
  172476. swidth = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172477. if (swidth == NULL)
  172478. {
  172479. png_warning(png_ptr, "Out of memory while processing sCAL chunk width");
  172480. return;
  172481. }
  172482. png_memcpy(swidth, ep, (png_size_t)png_strlen(ep));
  172483. #endif
  172484. #endif
  172485. for (ep = buffer; *ep; ep++)
  172486. ;
  172487. ep++;
  172488. if (buffer + slength < ep)
  172489. {
  172490. png_warning(png_ptr, "Truncated sCAL chunk");
  172491. #if defined(PNG_FIXED_POINT_SUPPORTED) && \
  172492. !defined(PNG_FLOATING_POINT_SUPPORTED)
  172493. png_free(png_ptr, swidth);
  172494. #endif
  172495. png_free(png_ptr, buffer);
  172496. return;
  172497. }
  172498. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172499. height = png_strtod(png_ptr, ep, &vp);
  172500. if (*vp)
  172501. {
  172502. png_warning(png_ptr, "malformed height string in sCAL chunk");
  172503. return;
  172504. }
  172505. #else
  172506. #ifdef PNG_FIXED_POINT_SUPPORTED
  172507. sheight = (png_charp)png_malloc_warn(png_ptr, png_strlen(ep) + 1);
  172508. if (swidth == NULL)
  172509. {
  172510. png_warning(png_ptr, "Out of memory while processing sCAL chunk height");
  172511. return;
  172512. }
  172513. png_memcpy(sheight, ep, (png_size_t)png_strlen(ep));
  172514. #endif
  172515. #endif
  172516. if (buffer + slength < ep
  172517. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172518. || width <= 0. || height <= 0.
  172519. #endif
  172520. )
  172521. {
  172522. png_warning(png_ptr, "Invalid sCAL data");
  172523. png_free(png_ptr, buffer);
  172524. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172525. png_free(png_ptr, swidth);
  172526. png_free(png_ptr, sheight);
  172527. #endif
  172528. return;
  172529. }
  172530. #ifdef PNG_FLOATING_POINT_SUPPORTED
  172531. png_set_sCAL(png_ptr, info_ptr, buffer[0], width, height);
  172532. #else
  172533. #ifdef PNG_FIXED_POINT_SUPPORTED
  172534. png_set_sCAL_s(png_ptr, info_ptr, buffer[0], swidth, sheight);
  172535. #endif
  172536. #endif
  172537. png_free(png_ptr, buffer);
  172538. #if defined(PNG_FIXED_POINT_SUPPORTED) && !defined(PNG_FLOATING_POINT_SUPPORTED)
  172539. png_free(png_ptr, swidth);
  172540. png_free(png_ptr, sheight);
  172541. #endif
  172542. }
  172543. #endif
  172544. #if defined(PNG_READ_tIME_SUPPORTED)
  172545. void /* PRIVATE */
  172546. png_handle_tIME(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172547. {
  172548. png_byte buf[7];
  172549. png_time mod_time;
  172550. png_debug(1, "in png_handle_tIME\n");
  172551. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172552. png_error(png_ptr, "Out of place tIME chunk");
  172553. else if (info_ptr != NULL && (info_ptr->valid & PNG_INFO_tIME))
  172554. {
  172555. png_warning(png_ptr, "Duplicate tIME chunk");
  172556. png_crc_finish(png_ptr, length);
  172557. return;
  172558. }
  172559. if (png_ptr->mode & PNG_HAVE_IDAT)
  172560. png_ptr->mode |= PNG_AFTER_IDAT;
  172561. if (length != 7)
  172562. {
  172563. png_warning(png_ptr, "Incorrect tIME chunk length");
  172564. png_crc_finish(png_ptr, length);
  172565. return;
  172566. }
  172567. png_crc_read(png_ptr, buf, 7);
  172568. if (png_crc_finish(png_ptr, 0))
  172569. return;
  172570. mod_time.second = buf[6];
  172571. mod_time.minute = buf[5];
  172572. mod_time.hour = buf[4];
  172573. mod_time.day = buf[3];
  172574. mod_time.month = buf[2];
  172575. mod_time.year = png_get_uint_16(buf);
  172576. png_set_tIME(png_ptr, info_ptr, &mod_time);
  172577. }
  172578. #endif
  172579. #if defined(PNG_READ_tEXt_SUPPORTED)
  172580. void /* PRIVATE */
  172581. png_handle_tEXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172582. {
  172583. png_textp text_ptr;
  172584. png_charp key;
  172585. png_charp text;
  172586. png_uint_32 skip = 0;
  172587. png_size_t slength;
  172588. int ret;
  172589. png_debug(1, "in png_handle_tEXt\n");
  172590. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172591. png_error(png_ptr, "Missing IHDR before tEXt");
  172592. if (png_ptr->mode & PNG_HAVE_IDAT)
  172593. png_ptr->mode |= PNG_AFTER_IDAT;
  172594. #ifdef PNG_MAX_MALLOC_64K
  172595. if (length > (png_uint_32)65535L)
  172596. {
  172597. png_warning(png_ptr, "tEXt chunk too large to fit in memory");
  172598. skip = length - (png_uint_32)65535L;
  172599. length = (png_uint_32)65535L;
  172600. }
  172601. #endif
  172602. key = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172603. if (key == NULL)
  172604. {
  172605. png_warning(png_ptr, "No memory to process text chunk.");
  172606. return;
  172607. }
  172608. slength = (png_size_t)length;
  172609. png_crc_read(png_ptr, (png_bytep)key, slength);
  172610. if (png_crc_finish(png_ptr, skip))
  172611. {
  172612. png_free(png_ptr, key);
  172613. return;
  172614. }
  172615. key[slength] = 0x00;
  172616. for (text = key; *text; text++)
  172617. ;
  172618. if (text != key + slength)
  172619. text++;
  172620. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172621. (png_uint_32)png_sizeof(png_text));
  172622. if (text_ptr == NULL)
  172623. {
  172624. png_warning(png_ptr, "Not enough memory to process text chunk.");
  172625. png_free(png_ptr, key);
  172626. return;
  172627. }
  172628. text_ptr->compression = PNG_TEXT_COMPRESSION_NONE;
  172629. text_ptr->key = key;
  172630. #ifdef PNG_iTXt_SUPPORTED
  172631. text_ptr->lang = NULL;
  172632. text_ptr->lang_key = NULL;
  172633. text_ptr->itxt_length = 0;
  172634. #endif
  172635. text_ptr->text = text;
  172636. text_ptr->text_length = png_strlen(text);
  172637. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172638. png_free(png_ptr, key);
  172639. png_free(png_ptr, text_ptr);
  172640. if (ret)
  172641. png_warning(png_ptr, "Insufficient memory to process text chunk.");
  172642. }
  172643. #endif
  172644. #if defined(PNG_READ_zTXt_SUPPORTED)
  172645. void /* PRIVATE */
  172646. png_handle_zTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172647. {
  172648. png_textp text_ptr;
  172649. png_charp chunkdata;
  172650. png_charp text;
  172651. int comp_type;
  172652. int ret;
  172653. png_size_t slength, prefix_len, data_len;
  172654. png_debug(1, "in png_handle_zTXt\n");
  172655. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172656. png_error(png_ptr, "Missing IHDR before zTXt");
  172657. if (png_ptr->mode & PNG_HAVE_IDAT)
  172658. png_ptr->mode |= PNG_AFTER_IDAT;
  172659. #ifdef PNG_MAX_MALLOC_64K
  172660. if (length > (png_uint_32)65535L)
  172661. {
  172662. png_warning(png_ptr,"zTXt chunk too large to fit in memory");
  172663. png_crc_finish(png_ptr, length);
  172664. return;
  172665. }
  172666. #endif
  172667. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172668. if (chunkdata == NULL)
  172669. {
  172670. png_warning(png_ptr,"Out of memory processing zTXt chunk.");
  172671. return;
  172672. }
  172673. slength = (png_size_t)length;
  172674. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172675. if (png_crc_finish(png_ptr, 0))
  172676. {
  172677. png_free(png_ptr, chunkdata);
  172678. return;
  172679. }
  172680. chunkdata[slength] = 0x00;
  172681. for (text = chunkdata; *text; text++)
  172682. ;
  172683. if (text >= chunkdata + slength - 2)
  172684. {
  172685. png_warning(png_ptr, "Truncated zTXt chunk");
  172686. png_free(png_ptr, chunkdata);
  172687. return;
  172688. }
  172689. else
  172690. {
  172691. comp_type = *(++text);
  172692. if (comp_type != PNG_TEXT_COMPRESSION_zTXt)
  172693. {
  172694. png_warning(png_ptr, "Unknown compression type in zTXt chunk");
  172695. comp_type = PNG_TEXT_COMPRESSION_zTXt;
  172696. }
  172697. text++; /* skip the compression_method byte */
  172698. }
  172699. prefix_len = text - chunkdata;
  172700. chunkdata = (png_charp)png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172701. (png_size_t)length, prefix_len, &data_len);
  172702. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172703. (png_uint_32)png_sizeof(png_text));
  172704. if (text_ptr == NULL)
  172705. {
  172706. png_warning(png_ptr,"Not enough memory to process zTXt chunk.");
  172707. png_free(png_ptr, chunkdata);
  172708. return;
  172709. }
  172710. text_ptr->compression = comp_type;
  172711. text_ptr->key = chunkdata;
  172712. #ifdef PNG_iTXt_SUPPORTED
  172713. text_ptr->lang = NULL;
  172714. text_ptr->lang_key = NULL;
  172715. text_ptr->itxt_length = 0;
  172716. #endif
  172717. text_ptr->text = chunkdata + prefix_len;
  172718. text_ptr->text_length = data_len;
  172719. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172720. png_free(png_ptr, text_ptr);
  172721. png_free(png_ptr, chunkdata);
  172722. if (ret)
  172723. png_error(png_ptr, "Insufficient memory to store zTXt chunk.");
  172724. }
  172725. #endif
  172726. #if defined(PNG_READ_iTXt_SUPPORTED)
  172727. void /* PRIVATE */
  172728. png_handle_iTXt(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172729. {
  172730. png_textp text_ptr;
  172731. png_charp chunkdata;
  172732. png_charp key, lang, text, lang_key;
  172733. int comp_flag;
  172734. int comp_type = 0;
  172735. int ret;
  172736. png_size_t slength, prefix_len, data_len;
  172737. png_debug(1, "in png_handle_iTXt\n");
  172738. if (!(png_ptr->mode & PNG_HAVE_IHDR))
  172739. png_error(png_ptr, "Missing IHDR before iTXt");
  172740. if (png_ptr->mode & PNG_HAVE_IDAT)
  172741. png_ptr->mode |= PNG_AFTER_IDAT;
  172742. #ifdef PNG_MAX_MALLOC_64K
  172743. if (length > (png_uint_32)65535L)
  172744. {
  172745. png_warning(png_ptr,"iTXt chunk too large to fit in memory");
  172746. png_crc_finish(png_ptr, length);
  172747. return;
  172748. }
  172749. #endif
  172750. chunkdata = (png_charp)png_malloc_warn(png_ptr, length + 1);
  172751. if (chunkdata == NULL)
  172752. {
  172753. png_warning(png_ptr, "No memory to process iTXt chunk.");
  172754. return;
  172755. }
  172756. slength = (png_size_t)length;
  172757. png_crc_read(png_ptr, (png_bytep)chunkdata, slength);
  172758. if (png_crc_finish(png_ptr, 0))
  172759. {
  172760. png_free(png_ptr, chunkdata);
  172761. return;
  172762. }
  172763. chunkdata[slength] = 0x00;
  172764. for (lang = chunkdata; *lang; lang++)
  172765. ;
  172766. lang++; /* skip NUL separator */
  172767. if (lang >= chunkdata + slength - 3)
  172768. {
  172769. png_warning(png_ptr, "Truncated iTXt chunk");
  172770. png_free(png_ptr, chunkdata);
  172771. return;
  172772. }
  172773. else
  172774. {
  172775. comp_flag = *lang++;
  172776. comp_type = *lang++;
  172777. }
  172778. for (lang_key = lang; *lang_key; lang_key++)
  172779. ;
  172780. lang_key++; /* skip NUL separator */
  172781. if (lang_key >= chunkdata + slength)
  172782. {
  172783. png_warning(png_ptr, "Truncated iTXt chunk");
  172784. png_free(png_ptr, chunkdata);
  172785. return;
  172786. }
  172787. for (text = lang_key; *text; text++)
  172788. ;
  172789. text++; /* skip NUL separator */
  172790. if (text >= chunkdata + slength)
  172791. {
  172792. png_warning(png_ptr, "Malformed iTXt chunk");
  172793. png_free(png_ptr, chunkdata);
  172794. return;
  172795. }
  172796. prefix_len = text - chunkdata;
  172797. key=chunkdata;
  172798. if (comp_flag)
  172799. chunkdata = png_decompress_chunk(png_ptr, comp_type, chunkdata,
  172800. (size_t)length, prefix_len, &data_len);
  172801. else
  172802. data_len=png_strlen(chunkdata + prefix_len);
  172803. text_ptr = (png_textp)png_malloc_warn(png_ptr,
  172804. (png_uint_32)png_sizeof(png_text));
  172805. if (text_ptr == NULL)
  172806. {
  172807. png_warning(png_ptr,"Not enough memory to process iTXt chunk.");
  172808. png_free(png_ptr, chunkdata);
  172809. return;
  172810. }
  172811. text_ptr->compression = (int)comp_flag + 1;
  172812. text_ptr->lang_key = chunkdata+(lang_key-key);
  172813. text_ptr->lang = chunkdata+(lang-key);
  172814. text_ptr->itxt_length = data_len;
  172815. text_ptr->text_length = 0;
  172816. text_ptr->key = chunkdata;
  172817. text_ptr->text = chunkdata + prefix_len;
  172818. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, 1);
  172819. png_free(png_ptr, text_ptr);
  172820. png_free(png_ptr, chunkdata);
  172821. if (ret)
  172822. png_error(png_ptr, "Insufficient memory to store iTXt chunk.");
  172823. }
  172824. #endif
  172825. void /* PRIVATE */
  172826. png_handle_unknown(png_structp png_ptr, png_infop info_ptr, png_uint_32 length)
  172827. {
  172828. png_uint_32 skip = 0;
  172829. png_debug(1, "in png_handle_unknown\n");
  172830. if (png_ptr->mode & PNG_HAVE_IDAT)
  172831. {
  172832. #ifdef PNG_USE_LOCAL_ARRAYS
  172833. PNG_CONST PNG_IDAT;
  172834. #endif
  172835. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4)) /* not an IDAT */
  172836. png_ptr->mode |= PNG_AFTER_IDAT;
  172837. }
  172838. png_check_chunk_name(png_ptr, png_ptr->chunk_name);
  172839. if (!(png_ptr->chunk_name[0] & 0x20))
  172840. {
  172841. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172842. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172843. PNG_HANDLE_CHUNK_ALWAYS
  172844. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172845. && png_ptr->read_user_chunk_fn == NULL
  172846. #endif
  172847. )
  172848. #endif
  172849. png_chunk_error(png_ptr, "unknown critical chunk");
  172850. }
  172851. #if defined(PNG_READ_UNKNOWN_CHUNKS_SUPPORTED)
  172852. if ((png_ptr->flags & PNG_FLAG_KEEP_UNKNOWN_CHUNKS) ||
  172853. (png_ptr->read_user_chunk_fn != NULL))
  172854. {
  172855. #ifdef PNG_MAX_MALLOC_64K
  172856. if (length > (png_uint_32)65535L)
  172857. {
  172858. png_warning(png_ptr, "unknown chunk too large to fit in memory");
  172859. skip = length - (png_uint_32)65535L;
  172860. length = (png_uint_32)65535L;
  172861. }
  172862. #endif
  172863. png_strncpy((png_charp)png_ptr->unknown_chunk.name,
  172864. (png_charp)png_ptr->chunk_name, 5);
  172865. png_ptr->unknown_chunk.data = (png_bytep)png_malloc(png_ptr, length);
  172866. png_ptr->unknown_chunk.size = (png_size_t)length;
  172867. png_crc_read(png_ptr, (png_bytep)png_ptr->unknown_chunk.data, length);
  172868. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172869. if(png_ptr->read_user_chunk_fn != NULL)
  172870. {
  172871. int ret;
  172872. ret = (*(png_ptr->read_user_chunk_fn))
  172873. (png_ptr, &png_ptr->unknown_chunk);
  172874. if (ret < 0)
  172875. png_chunk_error(png_ptr, "error in user chunk");
  172876. if (ret == 0)
  172877. {
  172878. if (!(png_ptr->chunk_name[0] & 0x20))
  172879. if(png_handle_as_unknown(png_ptr, png_ptr->chunk_name) !=
  172880. PNG_HANDLE_CHUNK_ALWAYS)
  172881. png_chunk_error(png_ptr, "unknown critical chunk");
  172882. png_set_unknown_chunks(png_ptr, info_ptr,
  172883. &png_ptr->unknown_chunk, 1);
  172884. }
  172885. }
  172886. #else
  172887. png_set_unknown_chunks(png_ptr, info_ptr, &png_ptr->unknown_chunk, 1);
  172888. #endif
  172889. png_free(png_ptr, png_ptr->unknown_chunk.data);
  172890. png_ptr->unknown_chunk.data = NULL;
  172891. }
  172892. else
  172893. #endif
  172894. skip = length;
  172895. png_crc_finish(png_ptr, skip);
  172896. #if !defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  172897. info_ptr = info_ptr; /* quiet compiler warnings about unused info_ptr */
  172898. #endif
  172899. }
  172900. #define isnonalpha(c) ((c) < 65 || (c) > 122 || ((c) > 90 && (c) < 97))
  172901. void /* PRIVATE */
  172902. png_check_chunk_name(png_structp png_ptr, png_bytep chunk_name)
  172903. {
  172904. png_debug(1, "in png_check_chunk_name\n");
  172905. if (isnonalpha(chunk_name[0]) || isnonalpha(chunk_name[1]) ||
  172906. isnonalpha(chunk_name[2]) || isnonalpha(chunk_name[3]))
  172907. {
  172908. png_chunk_error(png_ptr, "invalid chunk type");
  172909. }
  172910. }
  172911. void /* PRIVATE */
  172912. png_combine_row(png_structp png_ptr, png_bytep row, int mask)
  172913. {
  172914. png_debug(1,"in png_combine_row\n");
  172915. if (mask == 0xff)
  172916. {
  172917. png_memcpy(row, png_ptr->row_buf + 1,
  172918. PNG_ROWBYTES(png_ptr->row_info.pixel_depth, png_ptr->width));
  172919. }
  172920. else
  172921. {
  172922. switch (png_ptr->row_info.pixel_depth)
  172923. {
  172924. case 1:
  172925. {
  172926. png_bytep sp = png_ptr->row_buf + 1;
  172927. png_bytep dp = row;
  172928. int s_inc, s_start, s_end;
  172929. int m = 0x80;
  172930. int shift;
  172931. png_uint_32 i;
  172932. png_uint_32 row_width = png_ptr->width;
  172933. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172934. if (png_ptr->transformations & PNG_PACKSWAP)
  172935. {
  172936. s_start = 0;
  172937. s_end = 7;
  172938. s_inc = 1;
  172939. }
  172940. else
  172941. #endif
  172942. {
  172943. s_start = 7;
  172944. s_end = 0;
  172945. s_inc = -1;
  172946. }
  172947. shift = s_start;
  172948. for (i = 0; i < row_width; i++)
  172949. {
  172950. if (m & mask)
  172951. {
  172952. int value;
  172953. value = (*sp >> shift) & 0x01;
  172954. *dp &= (png_byte)((0x7f7f >> (7 - shift)) & 0xff);
  172955. *dp |= (png_byte)(value << shift);
  172956. }
  172957. if (shift == s_end)
  172958. {
  172959. shift = s_start;
  172960. sp++;
  172961. dp++;
  172962. }
  172963. else
  172964. shift += s_inc;
  172965. if (m == 1)
  172966. m = 0x80;
  172967. else
  172968. m >>= 1;
  172969. }
  172970. break;
  172971. }
  172972. case 2:
  172973. {
  172974. png_bytep sp = png_ptr->row_buf + 1;
  172975. png_bytep dp = row;
  172976. int s_start, s_end, s_inc;
  172977. int m = 0x80;
  172978. int shift;
  172979. png_uint_32 i;
  172980. png_uint_32 row_width = png_ptr->width;
  172981. int value;
  172982. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  172983. if (png_ptr->transformations & PNG_PACKSWAP)
  172984. {
  172985. s_start = 0;
  172986. s_end = 6;
  172987. s_inc = 2;
  172988. }
  172989. else
  172990. #endif
  172991. {
  172992. s_start = 6;
  172993. s_end = 0;
  172994. s_inc = -2;
  172995. }
  172996. shift = s_start;
  172997. for (i = 0; i < row_width; i++)
  172998. {
  172999. if (m & mask)
  173000. {
  173001. value = (*sp >> shift) & 0x03;
  173002. *dp &= (png_byte)((0x3f3f >> (6 - shift)) & 0xff);
  173003. *dp |= (png_byte)(value << shift);
  173004. }
  173005. if (shift == s_end)
  173006. {
  173007. shift = s_start;
  173008. sp++;
  173009. dp++;
  173010. }
  173011. else
  173012. shift += s_inc;
  173013. if (m == 1)
  173014. m = 0x80;
  173015. else
  173016. m >>= 1;
  173017. }
  173018. break;
  173019. }
  173020. case 4:
  173021. {
  173022. png_bytep sp = png_ptr->row_buf + 1;
  173023. png_bytep dp = row;
  173024. int s_start, s_end, s_inc;
  173025. int m = 0x80;
  173026. int shift;
  173027. png_uint_32 i;
  173028. png_uint_32 row_width = png_ptr->width;
  173029. int value;
  173030. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173031. if (png_ptr->transformations & PNG_PACKSWAP)
  173032. {
  173033. s_start = 0;
  173034. s_end = 4;
  173035. s_inc = 4;
  173036. }
  173037. else
  173038. #endif
  173039. {
  173040. s_start = 4;
  173041. s_end = 0;
  173042. s_inc = -4;
  173043. }
  173044. shift = s_start;
  173045. for (i = 0; i < row_width; i++)
  173046. {
  173047. if (m & mask)
  173048. {
  173049. value = (*sp >> shift) & 0xf;
  173050. *dp &= (png_byte)((0xf0f >> (4 - shift)) & 0xff);
  173051. *dp |= (png_byte)(value << shift);
  173052. }
  173053. if (shift == s_end)
  173054. {
  173055. shift = s_start;
  173056. sp++;
  173057. dp++;
  173058. }
  173059. else
  173060. shift += s_inc;
  173061. if (m == 1)
  173062. m = 0x80;
  173063. else
  173064. m >>= 1;
  173065. }
  173066. break;
  173067. }
  173068. default:
  173069. {
  173070. png_bytep sp = png_ptr->row_buf + 1;
  173071. png_bytep dp = row;
  173072. png_size_t pixel_bytes = (png_ptr->row_info.pixel_depth >> 3);
  173073. png_uint_32 i;
  173074. png_uint_32 row_width = png_ptr->width;
  173075. png_byte m = 0x80;
  173076. for (i = 0; i < row_width; i++)
  173077. {
  173078. if (m & mask)
  173079. {
  173080. png_memcpy(dp, sp, pixel_bytes);
  173081. }
  173082. sp += pixel_bytes;
  173083. dp += pixel_bytes;
  173084. if (m == 1)
  173085. m = 0x80;
  173086. else
  173087. m >>= 1;
  173088. }
  173089. break;
  173090. }
  173091. }
  173092. }
  173093. }
  173094. #ifdef PNG_READ_INTERLACING_SUPPORTED
  173095. void /* PRIVATE */
  173096. png_do_read_interlace(png_structp png_ptr)
  173097. {
  173098. png_row_infop row_info = &(png_ptr->row_info);
  173099. png_bytep row = png_ptr->row_buf + 1;
  173100. int pass = png_ptr->pass;
  173101. png_uint_32 transformations = png_ptr->transformations;
  173102. #ifdef PNG_USE_LOCAL_ARRAYS
  173103. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173104. #endif
  173105. png_debug(1,"in png_do_read_interlace\n");
  173106. if (row != NULL && row_info != NULL)
  173107. {
  173108. png_uint_32 final_width;
  173109. final_width = row_info->width * png_pass_inc[pass];
  173110. switch (row_info->pixel_depth)
  173111. {
  173112. case 1:
  173113. {
  173114. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 3);
  173115. png_bytep dp = row + (png_size_t)((final_width - 1) >> 3);
  173116. int sshift, dshift;
  173117. int s_start, s_end, s_inc;
  173118. int jstop = png_pass_inc[pass];
  173119. png_byte v;
  173120. png_uint_32 i;
  173121. int j;
  173122. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173123. if (transformations & PNG_PACKSWAP)
  173124. {
  173125. sshift = (int)((row_info->width + 7) & 0x07);
  173126. dshift = (int)((final_width + 7) & 0x07);
  173127. s_start = 7;
  173128. s_end = 0;
  173129. s_inc = -1;
  173130. }
  173131. else
  173132. #endif
  173133. {
  173134. sshift = 7 - (int)((row_info->width + 7) & 0x07);
  173135. dshift = 7 - (int)((final_width + 7) & 0x07);
  173136. s_start = 0;
  173137. s_end = 7;
  173138. s_inc = 1;
  173139. }
  173140. for (i = 0; i < row_info->width; i++)
  173141. {
  173142. v = (png_byte)((*sp >> sshift) & 0x01);
  173143. for (j = 0; j < jstop; j++)
  173144. {
  173145. *dp &= (png_byte)((0x7f7f >> (7 - dshift)) & 0xff);
  173146. *dp |= (png_byte)(v << dshift);
  173147. if (dshift == s_end)
  173148. {
  173149. dshift = s_start;
  173150. dp--;
  173151. }
  173152. else
  173153. dshift += s_inc;
  173154. }
  173155. if (sshift == s_end)
  173156. {
  173157. sshift = s_start;
  173158. sp--;
  173159. }
  173160. else
  173161. sshift += s_inc;
  173162. }
  173163. break;
  173164. }
  173165. case 2:
  173166. {
  173167. png_bytep sp = row + (png_uint_32)((row_info->width - 1) >> 2);
  173168. png_bytep dp = row + (png_uint_32)((final_width - 1) >> 2);
  173169. int sshift, dshift;
  173170. int s_start, s_end, s_inc;
  173171. int jstop = png_pass_inc[pass];
  173172. png_uint_32 i;
  173173. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173174. if (transformations & PNG_PACKSWAP)
  173175. {
  173176. sshift = (int)(((row_info->width + 3) & 0x03) << 1);
  173177. dshift = (int)(((final_width + 3) & 0x03) << 1);
  173178. s_start = 6;
  173179. s_end = 0;
  173180. s_inc = -2;
  173181. }
  173182. else
  173183. #endif
  173184. {
  173185. sshift = (int)((3 - ((row_info->width + 3) & 0x03)) << 1);
  173186. dshift = (int)((3 - ((final_width + 3) & 0x03)) << 1);
  173187. s_start = 0;
  173188. s_end = 6;
  173189. s_inc = 2;
  173190. }
  173191. for (i = 0; i < row_info->width; i++)
  173192. {
  173193. png_byte v;
  173194. int j;
  173195. v = (png_byte)((*sp >> sshift) & 0x03);
  173196. for (j = 0; j < jstop; j++)
  173197. {
  173198. *dp &= (png_byte)((0x3f3f >> (6 - dshift)) & 0xff);
  173199. *dp |= (png_byte)(v << dshift);
  173200. if (dshift == s_end)
  173201. {
  173202. dshift = s_start;
  173203. dp--;
  173204. }
  173205. else
  173206. dshift += s_inc;
  173207. }
  173208. if (sshift == s_end)
  173209. {
  173210. sshift = s_start;
  173211. sp--;
  173212. }
  173213. else
  173214. sshift += s_inc;
  173215. }
  173216. break;
  173217. }
  173218. case 4:
  173219. {
  173220. png_bytep sp = row + (png_size_t)((row_info->width - 1) >> 1);
  173221. png_bytep dp = row + (png_size_t)((final_width - 1) >> 1);
  173222. int sshift, dshift;
  173223. int s_start, s_end, s_inc;
  173224. png_uint_32 i;
  173225. int jstop = png_pass_inc[pass];
  173226. #if defined(PNG_READ_PACKSWAP_SUPPORTED)
  173227. if (transformations & PNG_PACKSWAP)
  173228. {
  173229. sshift = (int)(((row_info->width + 1) & 0x01) << 2);
  173230. dshift = (int)(((final_width + 1) & 0x01) << 2);
  173231. s_start = 4;
  173232. s_end = 0;
  173233. s_inc = -4;
  173234. }
  173235. else
  173236. #endif
  173237. {
  173238. sshift = (int)((1 - ((row_info->width + 1) & 0x01)) << 2);
  173239. dshift = (int)((1 - ((final_width + 1) & 0x01)) << 2);
  173240. s_start = 0;
  173241. s_end = 4;
  173242. s_inc = 4;
  173243. }
  173244. for (i = 0; i < row_info->width; i++)
  173245. {
  173246. png_byte v = (png_byte)((*sp >> sshift) & 0xf);
  173247. int j;
  173248. for (j = 0; j < jstop; j++)
  173249. {
  173250. *dp &= (png_byte)((0xf0f >> (4 - dshift)) & 0xff);
  173251. *dp |= (png_byte)(v << dshift);
  173252. if (dshift == s_end)
  173253. {
  173254. dshift = s_start;
  173255. dp--;
  173256. }
  173257. else
  173258. dshift += s_inc;
  173259. }
  173260. if (sshift == s_end)
  173261. {
  173262. sshift = s_start;
  173263. sp--;
  173264. }
  173265. else
  173266. sshift += s_inc;
  173267. }
  173268. break;
  173269. }
  173270. default:
  173271. {
  173272. png_size_t pixel_bytes = (row_info->pixel_depth >> 3);
  173273. png_bytep sp = row + (png_size_t)(row_info->width - 1) * pixel_bytes;
  173274. png_bytep dp = row + (png_size_t)(final_width - 1) * pixel_bytes;
  173275. int jstop = png_pass_inc[pass];
  173276. png_uint_32 i;
  173277. for (i = 0; i < row_info->width; i++)
  173278. {
  173279. png_byte v[8];
  173280. int j;
  173281. png_memcpy(v, sp, pixel_bytes);
  173282. for (j = 0; j < jstop; j++)
  173283. {
  173284. png_memcpy(dp, v, pixel_bytes);
  173285. dp -= pixel_bytes;
  173286. }
  173287. sp -= pixel_bytes;
  173288. }
  173289. break;
  173290. }
  173291. }
  173292. row_info->width = final_width;
  173293. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,final_width);
  173294. }
  173295. #if !defined(PNG_READ_PACKSWAP_SUPPORTED)
  173296. transformations = transformations; /* silence compiler warning */
  173297. #endif
  173298. }
  173299. #endif /* PNG_READ_INTERLACING_SUPPORTED */
  173300. void /* PRIVATE */
  173301. png_read_filter_row(png_structp png_ptr, png_row_infop row_info, png_bytep row,
  173302. png_bytep prev_row, int filter)
  173303. {
  173304. png_debug(1, "in png_read_filter_row\n");
  173305. png_debug2(2,"row = %lu, filter = %d\n", png_ptr->row_number, filter);
  173306. switch (filter)
  173307. {
  173308. case PNG_FILTER_VALUE_NONE:
  173309. break;
  173310. case PNG_FILTER_VALUE_SUB:
  173311. {
  173312. png_uint_32 i;
  173313. png_uint_32 istop = row_info->rowbytes;
  173314. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173315. png_bytep rp = row + bpp;
  173316. png_bytep lp = row;
  173317. for (i = bpp; i < istop; i++)
  173318. {
  173319. *rp = (png_byte)(((int)(*rp) + (int)(*lp++)) & 0xff);
  173320. rp++;
  173321. }
  173322. break;
  173323. }
  173324. case PNG_FILTER_VALUE_UP:
  173325. {
  173326. png_uint_32 i;
  173327. png_uint_32 istop = row_info->rowbytes;
  173328. png_bytep rp = row;
  173329. png_bytep pp = prev_row;
  173330. for (i = 0; i < istop; i++)
  173331. {
  173332. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173333. rp++;
  173334. }
  173335. break;
  173336. }
  173337. case PNG_FILTER_VALUE_AVG:
  173338. {
  173339. png_uint_32 i;
  173340. png_bytep rp = row;
  173341. png_bytep pp = prev_row;
  173342. png_bytep lp = row;
  173343. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173344. png_uint_32 istop = row_info->rowbytes - bpp;
  173345. for (i = 0; i < bpp; i++)
  173346. {
  173347. *rp = (png_byte)(((int)(*rp) +
  173348. ((int)(*pp++) / 2 )) & 0xff);
  173349. rp++;
  173350. }
  173351. for (i = 0; i < istop; i++)
  173352. {
  173353. *rp = (png_byte)(((int)(*rp) +
  173354. (int)(*pp++ + *lp++) / 2 ) & 0xff);
  173355. rp++;
  173356. }
  173357. break;
  173358. }
  173359. case PNG_FILTER_VALUE_PAETH:
  173360. {
  173361. png_uint_32 i;
  173362. png_bytep rp = row;
  173363. png_bytep pp = prev_row;
  173364. png_bytep lp = row;
  173365. png_bytep cp = prev_row;
  173366. png_uint_32 bpp = (row_info->pixel_depth + 7) >> 3;
  173367. png_uint_32 istop=row_info->rowbytes - bpp;
  173368. for (i = 0; i < bpp; i++)
  173369. {
  173370. *rp = (png_byte)(((int)(*rp) + (int)(*pp++)) & 0xff);
  173371. rp++;
  173372. }
  173373. for (i = 0; i < istop; i++) /* use leftover rp,pp */
  173374. {
  173375. int a, b, c, pa, pb, pc, p;
  173376. a = *lp++;
  173377. b = *pp++;
  173378. c = *cp++;
  173379. p = b - c;
  173380. pc = a - c;
  173381. #ifdef PNG_USE_ABS
  173382. pa = abs(p);
  173383. pb = abs(pc);
  173384. pc = abs(p + pc);
  173385. #else
  173386. pa = p < 0 ? -p : p;
  173387. pb = pc < 0 ? -pc : pc;
  173388. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  173389. #endif
  173390. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  173391. *rp = (png_byte)(((int)(*rp) + p) & 0xff);
  173392. rp++;
  173393. }
  173394. break;
  173395. }
  173396. default:
  173397. png_warning(png_ptr, "Ignoring bad adaptive filter type");
  173398. *row=0;
  173399. break;
  173400. }
  173401. }
  173402. void /* PRIVATE */
  173403. png_read_finish_row(png_structp png_ptr)
  173404. {
  173405. #ifdef PNG_USE_LOCAL_ARRAYS
  173406. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173407. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173408. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173409. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173410. #endif
  173411. png_debug(1, "in png_read_finish_row\n");
  173412. png_ptr->row_number++;
  173413. if (png_ptr->row_number < png_ptr->num_rows)
  173414. return;
  173415. if (png_ptr->interlaced)
  173416. {
  173417. png_ptr->row_number = 0;
  173418. png_memset_check(png_ptr, png_ptr->prev_row, 0,
  173419. png_ptr->rowbytes + 1);
  173420. do
  173421. {
  173422. png_ptr->pass++;
  173423. if (png_ptr->pass >= 7)
  173424. break;
  173425. png_ptr->iwidth = (png_ptr->width +
  173426. png_pass_inc[png_ptr->pass] - 1 -
  173427. png_pass_start[png_ptr->pass]) /
  173428. png_pass_inc[png_ptr->pass];
  173429. png_ptr->irowbytes = PNG_ROWBYTES(png_ptr->pixel_depth,
  173430. png_ptr->iwidth) + 1;
  173431. if (!(png_ptr->transformations & PNG_INTERLACE))
  173432. {
  173433. png_ptr->num_rows = (png_ptr->height +
  173434. png_pass_yinc[png_ptr->pass] - 1 -
  173435. png_pass_ystart[png_ptr->pass]) /
  173436. png_pass_yinc[png_ptr->pass];
  173437. if (!(png_ptr->num_rows))
  173438. continue;
  173439. }
  173440. else /* if (png_ptr->transformations & PNG_INTERLACE) */
  173441. break;
  173442. } while (png_ptr->iwidth == 0);
  173443. if (png_ptr->pass < 7)
  173444. return;
  173445. }
  173446. if (!(png_ptr->flags & PNG_FLAG_ZLIB_FINISHED))
  173447. {
  173448. #ifdef PNG_USE_LOCAL_ARRAYS
  173449. PNG_CONST PNG_IDAT;
  173450. #endif
  173451. char extra;
  173452. int ret;
  173453. png_ptr->zstream.next_out = (Bytef *)&extra;
  173454. png_ptr->zstream.avail_out = (uInt)1;
  173455. for(;;)
  173456. {
  173457. if (!(png_ptr->zstream.avail_in))
  173458. {
  173459. while (!png_ptr->idat_size)
  173460. {
  173461. png_byte chunk_length[4];
  173462. png_crc_finish(png_ptr, 0);
  173463. png_read_data(png_ptr, chunk_length, 4);
  173464. png_ptr->idat_size = png_get_uint_31(png_ptr, chunk_length);
  173465. png_reset_crc(png_ptr);
  173466. png_crc_read(png_ptr, png_ptr->chunk_name, 4);
  173467. if (png_memcmp(png_ptr->chunk_name, png_IDAT, 4))
  173468. png_error(png_ptr, "Not enough image data");
  173469. }
  173470. png_ptr->zstream.avail_in = (uInt)png_ptr->zbuf_size;
  173471. png_ptr->zstream.next_in = png_ptr->zbuf;
  173472. if (png_ptr->zbuf_size > png_ptr->idat_size)
  173473. png_ptr->zstream.avail_in = (uInt)png_ptr->idat_size;
  173474. png_crc_read(png_ptr, png_ptr->zbuf, png_ptr->zstream.avail_in);
  173475. png_ptr->idat_size -= png_ptr->zstream.avail_in;
  173476. }
  173477. ret = inflate(&png_ptr->zstream, Z_PARTIAL_FLUSH);
  173478. if (ret == Z_STREAM_END)
  173479. {
  173480. if (!(png_ptr->zstream.avail_out) || png_ptr->zstream.avail_in ||
  173481. png_ptr->idat_size)
  173482. png_warning(png_ptr, "Extra compressed data");
  173483. png_ptr->mode |= PNG_AFTER_IDAT;
  173484. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173485. break;
  173486. }
  173487. if (ret != Z_OK)
  173488. png_error(png_ptr, png_ptr->zstream.msg ? png_ptr->zstream.msg :
  173489. "Decompression Error");
  173490. if (!(png_ptr->zstream.avail_out))
  173491. {
  173492. png_warning(png_ptr, "Extra compressed data.");
  173493. png_ptr->mode |= PNG_AFTER_IDAT;
  173494. png_ptr->flags |= PNG_FLAG_ZLIB_FINISHED;
  173495. break;
  173496. }
  173497. }
  173498. png_ptr->zstream.avail_out = 0;
  173499. }
  173500. if (png_ptr->idat_size || png_ptr->zstream.avail_in)
  173501. png_warning(png_ptr, "Extra compression data");
  173502. inflateReset(&png_ptr->zstream);
  173503. png_ptr->mode |= PNG_AFTER_IDAT;
  173504. }
  173505. void /* PRIVATE */
  173506. png_read_start_row(png_structp png_ptr)
  173507. {
  173508. #ifdef PNG_USE_LOCAL_ARRAYS
  173509. PNG_CONST int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  173510. PNG_CONST int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  173511. PNG_CONST int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  173512. PNG_CONST int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  173513. #endif
  173514. int max_pixel_depth;
  173515. png_uint_32 row_bytes;
  173516. png_debug(1, "in png_read_start_row\n");
  173517. png_ptr->zstream.avail_in = 0;
  173518. png_init_read_transformations(png_ptr);
  173519. if (png_ptr->interlaced)
  173520. {
  173521. if (!(png_ptr->transformations & PNG_INTERLACE))
  173522. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  173523. png_pass_ystart[0]) / png_pass_yinc[0];
  173524. else
  173525. png_ptr->num_rows = png_ptr->height;
  173526. png_ptr->iwidth = (png_ptr->width +
  173527. png_pass_inc[png_ptr->pass] - 1 -
  173528. png_pass_start[png_ptr->pass]) /
  173529. png_pass_inc[png_ptr->pass];
  173530. row_bytes = PNG_ROWBYTES(png_ptr->pixel_depth,png_ptr->iwidth) + 1;
  173531. png_ptr->irowbytes = (png_size_t)row_bytes;
  173532. if((png_uint_32)png_ptr->irowbytes != row_bytes)
  173533. png_error(png_ptr, "Rowbytes overflow in png_read_start_row");
  173534. }
  173535. else
  173536. {
  173537. png_ptr->num_rows = png_ptr->height;
  173538. png_ptr->iwidth = png_ptr->width;
  173539. png_ptr->irowbytes = png_ptr->rowbytes + 1;
  173540. }
  173541. max_pixel_depth = png_ptr->pixel_depth;
  173542. #if defined(PNG_READ_PACK_SUPPORTED)
  173543. if ((png_ptr->transformations & PNG_PACK) && png_ptr->bit_depth < 8)
  173544. max_pixel_depth = 8;
  173545. #endif
  173546. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173547. if (png_ptr->transformations & PNG_EXPAND)
  173548. {
  173549. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173550. {
  173551. if (png_ptr->num_trans)
  173552. max_pixel_depth = 32;
  173553. else
  173554. max_pixel_depth = 24;
  173555. }
  173556. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173557. {
  173558. if (max_pixel_depth < 8)
  173559. max_pixel_depth = 8;
  173560. if (png_ptr->num_trans)
  173561. max_pixel_depth *= 2;
  173562. }
  173563. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173564. {
  173565. if (png_ptr->num_trans)
  173566. {
  173567. max_pixel_depth *= 4;
  173568. max_pixel_depth /= 3;
  173569. }
  173570. }
  173571. }
  173572. #endif
  173573. #if defined(PNG_READ_FILLER_SUPPORTED)
  173574. if (png_ptr->transformations & (PNG_FILLER))
  173575. {
  173576. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173577. max_pixel_depth = 32;
  173578. else if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY)
  173579. {
  173580. if (max_pixel_depth <= 8)
  173581. max_pixel_depth = 16;
  173582. else
  173583. max_pixel_depth = 32;
  173584. }
  173585. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  173586. {
  173587. if (max_pixel_depth <= 32)
  173588. max_pixel_depth = 32;
  173589. else
  173590. max_pixel_depth = 64;
  173591. }
  173592. }
  173593. #endif
  173594. #if defined(PNG_READ_GRAY_TO_RGB_SUPPORTED)
  173595. if (png_ptr->transformations & PNG_GRAY_TO_RGB)
  173596. {
  173597. if (
  173598. #if defined(PNG_READ_EXPAND_SUPPORTED)
  173599. (png_ptr->num_trans && (png_ptr->transformations & PNG_EXPAND)) ||
  173600. #endif
  173601. #if defined(PNG_READ_FILLER_SUPPORTED)
  173602. (png_ptr->transformations & (PNG_FILLER)) ||
  173603. #endif
  173604. png_ptr->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  173605. {
  173606. if (max_pixel_depth <= 16)
  173607. max_pixel_depth = 32;
  173608. else
  173609. max_pixel_depth = 64;
  173610. }
  173611. else
  173612. {
  173613. if (max_pixel_depth <= 8)
  173614. {
  173615. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173616. max_pixel_depth = 32;
  173617. else
  173618. max_pixel_depth = 24;
  173619. }
  173620. else if (png_ptr->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  173621. max_pixel_depth = 64;
  173622. else
  173623. max_pixel_depth = 48;
  173624. }
  173625. }
  173626. #endif
  173627. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) && \
  173628. defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  173629. if(png_ptr->transformations & PNG_USER_TRANSFORM)
  173630. {
  173631. int user_pixel_depth=png_ptr->user_transform_depth*
  173632. png_ptr->user_transform_channels;
  173633. if(user_pixel_depth > max_pixel_depth)
  173634. max_pixel_depth=user_pixel_depth;
  173635. }
  173636. #endif
  173637. row_bytes = ((png_ptr->width + 7) & ~((png_uint_32)7));
  173638. row_bytes = PNG_ROWBYTES(max_pixel_depth,row_bytes) +
  173639. 1 + ((max_pixel_depth + 7) >> 3);
  173640. #ifdef PNG_MAX_MALLOC_64K
  173641. if (row_bytes > (png_uint_32)65536L)
  173642. png_error(png_ptr, "This image requires a row greater than 64KB");
  173643. #endif
  173644. png_ptr->big_row_buf = (png_bytep)png_malloc(png_ptr, row_bytes+64);
  173645. png_ptr->row_buf = png_ptr->big_row_buf+32;
  173646. #ifdef PNG_MAX_MALLOC_64K
  173647. if ((png_uint_32)png_ptr->rowbytes + 1 > (png_uint_32)65536L)
  173648. png_error(png_ptr, "This image requires a row greater than 64KB");
  173649. #endif
  173650. if ((png_uint_32)png_ptr->rowbytes > (png_uint_32)(PNG_SIZE_MAX - 1))
  173651. png_error(png_ptr, "Row has too many bytes to allocate in memory.");
  173652. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)(
  173653. png_ptr->rowbytes + 1));
  173654. png_memset_check(png_ptr, png_ptr->prev_row, 0, png_ptr->rowbytes + 1);
  173655. png_debug1(3, "width = %lu,\n", png_ptr->width);
  173656. png_debug1(3, "height = %lu,\n", png_ptr->height);
  173657. png_debug1(3, "iwidth = %lu,\n", png_ptr->iwidth);
  173658. png_debug1(3, "num_rows = %lu\n", png_ptr->num_rows);
  173659. png_debug1(3, "rowbytes = %lu,\n", png_ptr->rowbytes);
  173660. png_debug1(3, "irowbytes = %lu,\n", png_ptr->irowbytes);
  173661. png_ptr->flags |= PNG_FLAG_ROW_INIT;
  173662. }
  173663. #endif /* PNG_READ_SUPPORTED */
  173664. /*** End of inlined file: pngrutil.c ***/
  173665. /*** Start of inlined file: pngset.c ***/
  173666. #define PNG_INTERNAL
  173667. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  173668. #if defined(PNG_bKGD_SUPPORTED)
  173669. void PNGAPI
  173670. png_set_bKGD(png_structp png_ptr, png_infop info_ptr, png_color_16p background)
  173671. {
  173672. png_debug1(1, "in %s storage function\n", "bKGD");
  173673. if (png_ptr == NULL || info_ptr == NULL)
  173674. return;
  173675. png_memcpy(&(info_ptr->background), background, png_sizeof(png_color_16));
  173676. info_ptr->valid |= PNG_INFO_bKGD;
  173677. }
  173678. #endif
  173679. #if defined(PNG_cHRM_SUPPORTED)
  173680. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173681. void PNGAPI
  173682. png_set_cHRM(png_structp png_ptr, png_infop info_ptr,
  173683. double white_x, double white_y, double red_x, double red_y,
  173684. double green_x, double green_y, double blue_x, double blue_y)
  173685. {
  173686. png_debug1(1, "in %s storage function\n", "cHRM");
  173687. if (png_ptr == NULL || info_ptr == NULL)
  173688. return;
  173689. if (white_x < 0.0 || white_y < 0.0 ||
  173690. red_x < 0.0 || red_y < 0.0 ||
  173691. green_x < 0.0 || green_y < 0.0 ||
  173692. blue_x < 0.0 || blue_y < 0.0)
  173693. {
  173694. png_warning(png_ptr,
  173695. "Ignoring attempt to set negative chromaticity value");
  173696. return;
  173697. }
  173698. if (white_x > 21474.83 || white_y > 21474.83 ||
  173699. red_x > 21474.83 || red_y > 21474.83 ||
  173700. green_x > 21474.83 || green_y > 21474.83 ||
  173701. blue_x > 21474.83 || blue_y > 21474.83)
  173702. {
  173703. png_warning(png_ptr,
  173704. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173705. return;
  173706. }
  173707. info_ptr->x_white = (float)white_x;
  173708. info_ptr->y_white = (float)white_y;
  173709. info_ptr->x_red = (float)red_x;
  173710. info_ptr->y_red = (float)red_y;
  173711. info_ptr->x_green = (float)green_x;
  173712. info_ptr->y_green = (float)green_y;
  173713. info_ptr->x_blue = (float)blue_x;
  173714. info_ptr->y_blue = (float)blue_y;
  173715. #ifdef PNG_FIXED_POINT_SUPPORTED
  173716. info_ptr->int_x_white = (png_fixed_point)(white_x*100000.+0.5);
  173717. info_ptr->int_y_white = (png_fixed_point)(white_y*100000.+0.5);
  173718. info_ptr->int_x_red = (png_fixed_point)( red_x*100000.+0.5);
  173719. info_ptr->int_y_red = (png_fixed_point)( red_y*100000.+0.5);
  173720. info_ptr->int_x_green = (png_fixed_point)(green_x*100000.+0.5);
  173721. info_ptr->int_y_green = (png_fixed_point)(green_y*100000.+0.5);
  173722. info_ptr->int_x_blue = (png_fixed_point)( blue_x*100000.+0.5);
  173723. info_ptr->int_y_blue = (png_fixed_point)( blue_y*100000.+0.5);
  173724. #endif
  173725. info_ptr->valid |= PNG_INFO_cHRM;
  173726. }
  173727. #endif
  173728. #ifdef PNG_FIXED_POINT_SUPPORTED
  173729. void PNGAPI
  173730. png_set_cHRM_fixed(png_structp png_ptr, png_infop info_ptr,
  173731. png_fixed_point white_x, png_fixed_point white_y, png_fixed_point red_x,
  173732. png_fixed_point red_y, png_fixed_point green_x, png_fixed_point green_y,
  173733. png_fixed_point blue_x, png_fixed_point blue_y)
  173734. {
  173735. png_debug1(1, "in %s storage function\n", "cHRM");
  173736. if (png_ptr == NULL || info_ptr == NULL)
  173737. return;
  173738. if (white_x < 0 || white_y < 0 ||
  173739. red_x < 0 || red_y < 0 ||
  173740. green_x < 0 || green_y < 0 ||
  173741. blue_x < 0 || blue_y < 0)
  173742. {
  173743. png_warning(png_ptr,
  173744. "Ignoring attempt to set negative chromaticity value");
  173745. return;
  173746. }
  173747. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173748. if (white_x > (double) PNG_UINT_31_MAX ||
  173749. white_y > (double) PNG_UINT_31_MAX ||
  173750. red_x > (double) PNG_UINT_31_MAX ||
  173751. red_y > (double) PNG_UINT_31_MAX ||
  173752. green_x > (double) PNG_UINT_31_MAX ||
  173753. green_y > (double) PNG_UINT_31_MAX ||
  173754. blue_x > (double) PNG_UINT_31_MAX ||
  173755. blue_y > (double) PNG_UINT_31_MAX)
  173756. #else
  173757. if (white_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173758. white_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173759. red_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173760. red_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173761. green_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173762. green_y > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173763. blue_x > (png_fixed_point) PNG_UINT_31_MAX/100000L ||
  173764. blue_y > (png_fixed_point) PNG_UINT_31_MAX/100000L)
  173765. #endif
  173766. {
  173767. png_warning(png_ptr,
  173768. "Ignoring attempt to set chromaticity value exceeding 21474.83");
  173769. return;
  173770. }
  173771. info_ptr->int_x_white = white_x;
  173772. info_ptr->int_y_white = white_y;
  173773. info_ptr->int_x_red = red_x;
  173774. info_ptr->int_y_red = red_y;
  173775. info_ptr->int_x_green = green_x;
  173776. info_ptr->int_y_green = green_y;
  173777. info_ptr->int_x_blue = blue_x;
  173778. info_ptr->int_y_blue = blue_y;
  173779. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173780. info_ptr->x_white = (float)(white_x/100000.);
  173781. info_ptr->y_white = (float)(white_y/100000.);
  173782. info_ptr->x_red = (float)( red_x/100000.);
  173783. info_ptr->y_red = (float)( red_y/100000.);
  173784. info_ptr->x_green = (float)(green_x/100000.);
  173785. info_ptr->y_green = (float)(green_y/100000.);
  173786. info_ptr->x_blue = (float)( blue_x/100000.);
  173787. info_ptr->y_blue = (float)( blue_y/100000.);
  173788. #endif
  173789. info_ptr->valid |= PNG_INFO_cHRM;
  173790. }
  173791. #endif
  173792. #endif
  173793. #if defined(PNG_gAMA_SUPPORTED)
  173794. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173795. void PNGAPI
  173796. png_set_gAMA(png_structp png_ptr, png_infop info_ptr, double file_gamma)
  173797. {
  173798. double gamma;
  173799. png_debug1(1, "in %s storage function\n", "gAMA");
  173800. if (png_ptr == NULL || info_ptr == NULL)
  173801. return;
  173802. if (file_gamma > 21474.83)
  173803. {
  173804. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173805. gamma=21474.83;
  173806. }
  173807. else
  173808. gamma=file_gamma;
  173809. info_ptr->gamma = (float)gamma;
  173810. #ifdef PNG_FIXED_POINT_SUPPORTED
  173811. info_ptr->int_gamma = (int)(gamma*100000.+.5);
  173812. #endif
  173813. info_ptr->valid |= PNG_INFO_gAMA;
  173814. if(gamma == 0.0)
  173815. png_warning(png_ptr, "Setting gamma=0");
  173816. }
  173817. #endif
  173818. void PNGAPI
  173819. png_set_gAMA_fixed(png_structp png_ptr, png_infop info_ptr, png_fixed_point
  173820. int_gamma)
  173821. {
  173822. png_fixed_point gamma;
  173823. png_debug1(1, "in %s storage function\n", "gAMA");
  173824. if (png_ptr == NULL || info_ptr == NULL)
  173825. return;
  173826. if (int_gamma > (png_fixed_point) PNG_UINT_31_MAX)
  173827. {
  173828. png_warning(png_ptr, "Limiting gamma to 21474.83");
  173829. gamma=PNG_UINT_31_MAX;
  173830. }
  173831. else
  173832. {
  173833. if (int_gamma < 0)
  173834. {
  173835. png_warning(png_ptr, "Setting negative gamma to zero");
  173836. gamma=0;
  173837. }
  173838. else
  173839. gamma=int_gamma;
  173840. }
  173841. #ifdef PNG_FLOATING_POINT_SUPPORTED
  173842. info_ptr->gamma = (float)(gamma/100000.);
  173843. #endif
  173844. #ifdef PNG_FIXED_POINT_SUPPORTED
  173845. info_ptr->int_gamma = gamma;
  173846. #endif
  173847. info_ptr->valid |= PNG_INFO_gAMA;
  173848. if(gamma == 0)
  173849. png_warning(png_ptr, "Setting gamma=0");
  173850. }
  173851. #endif
  173852. #if defined(PNG_hIST_SUPPORTED)
  173853. void PNGAPI
  173854. png_set_hIST(png_structp png_ptr, png_infop info_ptr, png_uint_16p hist)
  173855. {
  173856. int i;
  173857. png_debug1(1, "in %s storage function\n", "hIST");
  173858. if (png_ptr == NULL || info_ptr == NULL)
  173859. return;
  173860. if (info_ptr->num_palette == 0 || info_ptr->num_palette
  173861. > PNG_MAX_PALETTE_LENGTH)
  173862. {
  173863. png_warning(png_ptr,
  173864. "Invalid palette size, hIST allocation skipped.");
  173865. return;
  173866. }
  173867. #ifdef PNG_FREE_ME_SUPPORTED
  173868. png_free_data(png_ptr, info_ptr, PNG_FREE_HIST, 0);
  173869. #endif
  173870. png_ptr->hist = (png_uint_16p)png_malloc_warn(png_ptr,
  173871. (png_uint_32)(PNG_MAX_PALETTE_LENGTH * png_sizeof (png_uint_16)));
  173872. if (png_ptr->hist == NULL)
  173873. {
  173874. png_warning(png_ptr, "Insufficient memory for hIST chunk data.");
  173875. return;
  173876. }
  173877. for (i = 0; i < info_ptr->num_palette; i++)
  173878. png_ptr->hist[i] = hist[i];
  173879. info_ptr->hist = png_ptr->hist;
  173880. info_ptr->valid |= PNG_INFO_hIST;
  173881. #ifdef PNG_FREE_ME_SUPPORTED
  173882. info_ptr->free_me |= PNG_FREE_HIST;
  173883. #else
  173884. png_ptr->flags |= PNG_FLAG_FREE_HIST;
  173885. #endif
  173886. }
  173887. #endif
  173888. void PNGAPI
  173889. png_set_IHDR(png_structp png_ptr, png_infop info_ptr,
  173890. png_uint_32 width, png_uint_32 height, int bit_depth,
  173891. int color_type, int interlace_type, int compression_type,
  173892. int filter_type)
  173893. {
  173894. png_debug1(1, "in %s storage function\n", "IHDR");
  173895. if (png_ptr == NULL || info_ptr == NULL)
  173896. return;
  173897. if (width == 0 || height == 0)
  173898. png_error(png_ptr, "Image width or height is zero in IHDR");
  173899. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  173900. if (width > png_ptr->user_width_max || height > png_ptr->user_height_max)
  173901. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173902. #else
  173903. if (width > PNG_USER_WIDTH_MAX || height > PNG_USER_HEIGHT_MAX)
  173904. png_error(png_ptr, "image size exceeds user limits in IHDR");
  173905. #endif
  173906. if (width > PNG_UINT_31_MAX || height > PNG_UINT_31_MAX)
  173907. png_error(png_ptr, "Invalid image size in IHDR");
  173908. if ( width > (PNG_UINT_32_MAX
  173909. >> 3) /* 8-byte RGBA pixels */
  173910. - 64 /* bigrowbuf hack */
  173911. - 1 /* filter byte */
  173912. - 7*8 /* rounding of width to multiple of 8 pixels */
  173913. - 8) /* extra max_pixel_depth pad */
  173914. png_warning(png_ptr, "Width is too large for libpng to process pixels");
  173915. if (bit_depth != 1 && bit_depth != 2 && bit_depth != 4 &&
  173916. bit_depth != 8 && bit_depth != 16)
  173917. png_error(png_ptr, "Invalid bit depth in IHDR");
  173918. if (color_type < 0 || color_type == 1 ||
  173919. color_type == 5 || color_type > 6)
  173920. png_error(png_ptr, "Invalid color type in IHDR");
  173921. if (((color_type == PNG_COLOR_TYPE_PALETTE) && bit_depth > 8) ||
  173922. ((color_type == PNG_COLOR_TYPE_RGB ||
  173923. color_type == PNG_COLOR_TYPE_GRAY_ALPHA ||
  173924. color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8))
  173925. png_error(png_ptr, "Invalid color type/bit depth combination in IHDR");
  173926. if (interlace_type >= PNG_INTERLACE_LAST)
  173927. png_error(png_ptr, "Unknown interlace method in IHDR");
  173928. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  173929. png_error(png_ptr, "Unknown compression method in IHDR");
  173930. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  173931. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&png_ptr->mng_features_permitted)
  173932. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  173933. if(filter_type != PNG_FILTER_TYPE_BASE)
  173934. {
  173935. if(!((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  173936. (filter_type == PNG_INTRAPIXEL_DIFFERENCING) &&
  173937. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  173938. (color_type == PNG_COLOR_TYPE_RGB ||
  173939. color_type == PNG_COLOR_TYPE_RGB_ALPHA)))
  173940. png_error(png_ptr, "Unknown filter method in IHDR");
  173941. if(png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)
  173942. png_warning(png_ptr, "Invalid filter method in IHDR");
  173943. }
  173944. #else
  173945. if(filter_type != PNG_FILTER_TYPE_BASE)
  173946. png_error(png_ptr, "Unknown filter method in IHDR");
  173947. #endif
  173948. info_ptr->width = width;
  173949. info_ptr->height = height;
  173950. info_ptr->bit_depth = (png_byte)bit_depth;
  173951. info_ptr->color_type =(png_byte) color_type;
  173952. info_ptr->compression_type = (png_byte)compression_type;
  173953. info_ptr->filter_type = (png_byte)filter_type;
  173954. info_ptr->interlace_type = (png_byte)interlace_type;
  173955. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  173956. info_ptr->channels = 1;
  173957. else if (info_ptr->color_type & PNG_COLOR_MASK_COLOR)
  173958. info_ptr->channels = 3;
  173959. else
  173960. info_ptr->channels = 1;
  173961. if (info_ptr->color_type & PNG_COLOR_MASK_ALPHA)
  173962. info_ptr->channels++;
  173963. info_ptr->pixel_depth = (png_byte)(info_ptr->channels * info_ptr->bit_depth);
  173964. if (width > (PNG_UINT_32_MAX
  173965. >> 3) /* 8-byte RGBA pixels */
  173966. - 64 /* bigrowbuf hack */
  173967. - 1 /* filter byte */
  173968. - 7*8 /* rounding of width to multiple of 8 pixels */
  173969. - 8) /* extra max_pixel_depth pad */
  173970. info_ptr->rowbytes = (png_size_t)0;
  173971. else
  173972. info_ptr->rowbytes = PNG_ROWBYTES(info_ptr->pixel_depth,width);
  173973. }
  173974. #if defined(PNG_oFFs_SUPPORTED)
  173975. void PNGAPI
  173976. png_set_oFFs(png_structp png_ptr, png_infop info_ptr,
  173977. png_int_32 offset_x, png_int_32 offset_y, int unit_type)
  173978. {
  173979. png_debug1(1, "in %s storage function\n", "oFFs");
  173980. if (png_ptr == NULL || info_ptr == NULL)
  173981. return;
  173982. info_ptr->x_offset = offset_x;
  173983. info_ptr->y_offset = offset_y;
  173984. info_ptr->offset_unit_type = (png_byte)unit_type;
  173985. info_ptr->valid |= PNG_INFO_oFFs;
  173986. }
  173987. #endif
  173988. #if defined(PNG_pCAL_SUPPORTED)
  173989. void PNGAPI
  173990. png_set_pCAL(png_structp png_ptr, png_infop info_ptr,
  173991. png_charp purpose, png_int_32 X0, png_int_32 X1, int type, int nparams,
  173992. png_charp units, png_charpp params)
  173993. {
  173994. png_uint_32 length;
  173995. int i;
  173996. png_debug1(1, "in %s storage function\n", "pCAL");
  173997. if (png_ptr == NULL || info_ptr == NULL)
  173998. return;
  173999. length = png_strlen(purpose) + 1;
  174000. png_debug1(3, "allocating purpose for info (%lu bytes)\n", length);
  174001. info_ptr->pcal_purpose = (png_charp)png_malloc_warn(png_ptr, length);
  174002. if (info_ptr->pcal_purpose == NULL)
  174003. {
  174004. png_warning(png_ptr, "Insufficient memory for pCAL purpose.");
  174005. return;
  174006. }
  174007. png_memcpy(info_ptr->pcal_purpose, purpose, (png_size_t)length);
  174008. png_debug(3, "storing X0, X1, type, and nparams in info\n");
  174009. info_ptr->pcal_X0 = X0;
  174010. info_ptr->pcal_X1 = X1;
  174011. info_ptr->pcal_type = (png_byte)type;
  174012. info_ptr->pcal_nparams = (png_byte)nparams;
  174013. length = png_strlen(units) + 1;
  174014. png_debug1(3, "allocating units for info (%lu bytes)\n", length);
  174015. info_ptr->pcal_units = (png_charp)png_malloc_warn(png_ptr, length);
  174016. if (info_ptr->pcal_units == NULL)
  174017. {
  174018. png_warning(png_ptr, "Insufficient memory for pCAL units.");
  174019. return;
  174020. }
  174021. png_memcpy(info_ptr->pcal_units, units, (png_size_t)length);
  174022. info_ptr->pcal_params = (png_charpp)png_malloc_warn(png_ptr,
  174023. (png_uint_32)((nparams + 1) * png_sizeof(png_charp)));
  174024. if (info_ptr->pcal_params == NULL)
  174025. {
  174026. png_warning(png_ptr, "Insufficient memory for pCAL params.");
  174027. return;
  174028. }
  174029. info_ptr->pcal_params[nparams] = NULL;
  174030. for (i = 0; i < nparams; i++)
  174031. {
  174032. length = png_strlen(params[i]) + 1;
  174033. png_debug2(3, "allocating parameter %d for info (%lu bytes)\n", i, length);
  174034. info_ptr->pcal_params[i] = (png_charp)png_malloc_warn(png_ptr, length);
  174035. if (info_ptr->pcal_params[i] == NULL)
  174036. {
  174037. png_warning(png_ptr, "Insufficient memory for pCAL parameter.");
  174038. return;
  174039. }
  174040. png_memcpy(info_ptr->pcal_params[i], params[i], (png_size_t)length);
  174041. }
  174042. info_ptr->valid |= PNG_INFO_pCAL;
  174043. #ifdef PNG_FREE_ME_SUPPORTED
  174044. info_ptr->free_me |= PNG_FREE_PCAL;
  174045. #endif
  174046. }
  174047. #endif
  174048. #if defined(PNG_READ_sCAL_SUPPORTED) || defined(PNG_WRITE_sCAL_SUPPORTED)
  174049. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174050. void PNGAPI
  174051. png_set_sCAL(png_structp png_ptr, png_infop info_ptr,
  174052. int unit, double width, double height)
  174053. {
  174054. png_debug1(1, "in %s storage function\n", "sCAL");
  174055. if (png_ptr == NULL || info_ptr == NULL)
  174056. return;
  174057. info_ptr->scal_unit = (png_byte)unit;
  174058. info_ptr->scal_pixel_width = width;
  174059. info_ptr->scal_pixel_height = height;
  174060. info_ptr->valid |= PNG_INFO_sCAL;
  174061. }
  174062. #else
  174063. #ifdef PNG_FIXED_POINT_SUPPORTED
  174064. void PNGAPI
  174065. png_set_sCAL_s(png_structp png_ptr, png_infop info_ptr,
  174066. int unit, png_charp swidth, png_charp sheight)
  174067. {
  174068. png_uint_32 length;
  174069. png_debug1(1, "in %s storage function\n", "sCAL");
  174070. if (png_ptr == NULL || info_ptr == NULL)
  174071. return;
  174072. info_ptr->scal_unit = (png_byte)unit;
  174073. length = png_strlen(swidth) + 1;
  174074. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  174075. info_ptr->scal_s_width = (png_charp)png_malloc_warn(png_ptr, length);
  174076. if (info_ptr->scal_s_width == NULL)
  174077. {
  174078. png_warning(png_ptr,
  174079. "Memory allocation failed while processing sCAL.");
  174080. }
  174081. png_memcpy(info_ptr->scal_s_width, swidth, (png_size_t)length);
  174082. length = png_strlen(sheight) + 1;
  174083. png_debug1(3, "allocating unit for info (%d bytes)\n", length);
  174084. info_ptr->scal_s_height = (png_charp)png_malloc_warn(png_ptr, length);
  174085. if (info_ptr->scal_s_height == NULL)
  174086. {
  174087. png_free (png_ptr, info_ptr->scal_s_width);
  174088. png_warning(png_ptr,
  174089. "Memory allocation failed while processing sCAL.");
  174090. }
  174091. png_memcpy(info_ptr->scal_s_height, sheight, (png_size_t)length);
  174092. info_ptr->valid |= PNG_INFO_sCAL;
  174093. #ifdef PNG_FREE_ME_SUPPORTED
  174094. info_ptr->free_me |= PNG_FREE_SCAL;
  174095. #endif
  174096. }
  174097. #endif
  174098. #endif
  174099. #endif
  174100. #if defined(PNG_pHYs_SUPPORTED)
  174101. void PNGAPI
  174102. png_set_pHYs(png_structp png_ptr, png_infop info_ptr,
  174103. png_uint_32 res_x, png_uint_32 res_y, int unit_type)
  174104. {
  174105. png_debug1(1, "in %s storage function\n", "pHYs");
  174106. if (png_ptr == NULL || info_ptr == NULL)
  174107. return;
  174108. info_ptr->x_pixels_per_unit = res_x;
  174109. info_ptr->y_pixels_per_unit = res_y;
  174110. info_ptr->phys_unit_type = (png_byte)unit_type;
  174111. info_ptr->valid |= PNG_INFO_pHYs;
  174112. }
  174113. #endif
  174114. void PNGAPI
  174115. png_set_PLTE(png_structp png_ptr, png_infop info_ptr,
  174116. png_colorp palette, int num_palette)
  174117. {
  174118. png_debug1(1, "in %s storage function\n", "PLTE");
  174119. if (png_ptr == NULL || info_ptr == NULL)
  174120. return;
  174121. if (num_palette < 0 || num_palette > PNG_MAX_PALETTE_LENGTH)
  174122. {
  174123. if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  174124. png_error(png_ptr, "Invalid palette length");
  174125. else
  174126. {
  174127. png_warning(png_ptr, "Invalid palette length");
  174128. return;
  174129. }
  174130. }
  174131. #ifdef PNG_FREE_ME_SUPPORTED
  174132. png_free_data(png_ptr, info_ptr, PNG_FREE_PLTE, 0);
  174133. #endif
  174134. png_ptr->palette = (png_colorp)png_malloc(png_ptr,
  174135. PNG_MAX_PALETTE_LENGTH * png_sizeof(png_color));
  174136. png_memset(png_ptr->palette, 0, PNG_MAX_PALETTE_LENGTH *
  174137. png_sizeof(png_color));
  174138. png_memcpy(png_ptr->palette, palette, num_palette * png_sizeof (png_color));
  174139. info_ptr->palette = png_ptr->palette;
  174140. info_ptr->num_palette = png_ptr->num_palette = (png_uint_16)num_palette;
  174141. #ifdef PNG_FREE_ME_SUPPORTED
  174142. info_ptr->free_me |= PNG_FREE_PLTE;
  174143. #else
  174144. png_ptr->flags |= PNG_FLAG_FREE_PLTE;
  174145. #endif
  174146. info_ptr->valid |= PNG_INFO_PLTE;
  174147. }
  174148. #if defined(PNG_sBIT_SUPPORTED)
  174149. void PNGAPI
  174150. png_set_sBIT(png_structp png_ptr, png_infop info_ptr,
  174151. png_color_8p sig_bit)
  174152. {
  174153. png_debug1(1, "in %s storage function\n", "sBIT");
  174154. if (png_ptr == NULL || info_ptr == NULL)
  174155. return;
  174156. png_memcpy(&(info_ptr->sig_bit), sig_bit, png_sizeof (png_color_8));
  174157. info_ptr->valid |= PNG_INFO_sBIT;
  174158. }
  174159. #endif
  174160. #if defined(PNG_sRGB_SUPPORTED)
  174161. void PNGAPI
  174162. png_set_sRGB(png_structp png_ptr, png_infop info_ptr, int intent)
  174163. {
  174164. png_debug1(1, "in %s storage function\n", "sRGB");
  174165. if (png_ptr == NULL || info_ptr == NULL)
  174166. return;
  174167. info_ptr->srgb_intent = (png_byte)intent;
  174168. info_ptr->valid |= PNG_INFO_sRGB;
  174169. }
  174170. void PNGAPI
  174171. png_set_sRGB_gAMA_and_cHRM(png_structp png_ptr, png_infop info_ptr,
  174172. int intent)
  174173. {
  174174. #if defined(PNG_gAMA_SUPPORTED)
  174175. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174176. float file_gamma;
  174177. #endif
  174178. #ifdef PNG_FIXED_POINT_SUPPORTED
  174179. png_fixed_point int_file_gamma;
  174180. #endif
  174181. #endif
  174182. #if defined(PNG_cHRM_SUPPORTED)
  174183. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174184. float white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y;
  174185. #endif
  174186. #ifdef PNG_FIXED_POINT_SUPPORTED
  174187. png_fixed_point int_white_x, int_white_y, int_red_x, int_red_y, int_green_x,
  174188. int_green_y, int_blue_x, int_blue_y;
  174189. #endif
  174190. #endif
  174191. png_debug1(1, "in %s storage function\n", "sRGB_gAMA_and_cHRM");
  174192. if (png_ptr == NULL || info_ptr == NULL)
  174193. return;
  174194. png_set_sRGB(png_ptr, info_ptr, intent);
  174195. #if defined(PNG_gAMA_SUPPORTED)
  174196. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174197. file_gamma = (float).45455;
  174198. png_set_gAMA(png_ptr, info_ptr, file_gamma);
  174199. #endif
  174200. #ifdef PNG_FIXED_POINT_SUPPORTED
  174201. int_file_gamma = 45455L;
  174202. png_set_gAMA_fixed(png_ptr, info_ptr, int_file_gamma);
  174203. #endif
  174204. #endif
  174205. #if defined(PNG_cHRM_SUPPORTED)
  174206. #ifdef PNG_FIXED_POINT_SUPPORTED
  174207. int_white_x = 31270L;
  174208. int_white_y = 32900L;
  174209. int_red_x = 64000L;
  174210. int_red_y = 33000L;
  174211. int_green_x = 30000L;
  174212. int_green_y = 60000L;
  174213. int_blue_x = 15000L;
  174214. int_blue_y = 6000L;
  174215. png_set_cHRM_fixed(png_ptr, info_ptr,
  174216. int_white_x, int_white_y, int_red_x, int_red_y, int_green_x, int_green_y,
  174217. int_blue_x, int_blue_y);
  174218. #endif
  174219. #ifdef PNG_FLOATING_POINT_SUPPORTED
  174220. white_x = (float).3127;
  174221. white_y = (float).3290;
  174222. red_x = (float).64;
  174223. red_y = (float).33;
  174224. green_x = (float).30;
  174225. green_y = (float).60;
  174226. blue_x = (float).15;
  174227. blue_y = (float).06;
  174228. png_set_cHRM(png_ptr, info_ptr,
  174229. white_x, white_y, red_x, red_y, green_x, green_y, blue_x, blue_y);
  174230. #endif
  174231. #endif
  174232. }
  174233. #endif
  174234. #if defined(PNG_iCCP_SUPPORTED)
  174235. void PNGAPI
  174236. png_set_iCCP(png_structp png_ptr, png_infop info_ptr,
  174237. png_charp name, int compression_type,
  174238. png_charp profile, png_uint_32 proflen)
  174239. {
  174240. png_charp new_iccp_name;
  174241. png_charp new_iccp_profile;
  174242. png_debug1(1, "in %s storage function\n", "iCCP");
  174243. if (png_ptr == NULL || info_ptr == NULL || name == NULL || profile == NULL)
  174244. return;
  174245. new_iccp_name = (png_charp)png_malloc_warn(png_ptr, png_strlen(name)+1);
  174246. if (new_iccp_name == NULL)
  174247. {
  174248. png_warning(png_ptr, "Insufficient memory to process iCCP chunk.");
  174249. return;
  174250. }
  174251. png_strncpy(new_iccp_name, name, png_strlen(name)+1);
  174252. new_iccp_profile = (png_charp)png_malloc_warn(png_ptr, proflen);
  174253. if (new_iccp_profile == NULL)
  174254. {
  174255. png_free (png_ptr, new_iccp_name);
  174256. png_warning(png_ptr, "Insufficient memory to process iCCP profile.");
  174257. return;
  174258. }
  174259. png_memcpy(new_iccp_profile, profile, (png_size_t)proflen);
  174260. png_free_data(png_ptr, info_ptr, PNG_FREE_ICCP, 0);
  174261. info_ptr->iccp_proflen = proflen;
  174262. info_ptr->iccp_name = new_iccp_name;
  174263. info_ptr->iccp_profile = new_iccp_profile;
  174264. info_ptr->iccp_compression = (png_byte)compression_type;
  174265. #ifdef PNG_FREE_ME_SUPPORTED
  174266. info_ptr->free_me |= PNG_FREE_ICCP;
  174267. #endif
  174268. info_ptr->valid |= PNG_INFO_iCCP;
  174269. }
  174270. #endif
  174271. #if defined(PNG_TEXT_SUPPORTED)
  174272. void PNGAPI
  174273. png_set_text(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174274. int num_text)
  174275. {
  174276. int ret;
  174277. ret=png_set_text_2(png_ptr, info_ptr, text_ptr, num_text);
  174278. if (ret)
  174279. png_error(png_ptr, "Insufficient memory to store text");
  174280. }
  174281. int /* PRIVATE */
  174282. png_set_text_2(png_structp png_ptr, png_infop info_ptr, png_textp text_ptr,
  174283. int num_text)
  174284. {
  174285. int i;
  174286. png_debug1(1, "in %s storage function\n", (png_ptr->chunk_name[0] == '\0' ?
  174287. "text" : (png_const_charp)png_ptr->chunk_name));
  174288. if (png_ptr == NULL || info_ptr == NULL || num_text == 0)
  174289. return(0);
  174290. if (info_ptr->num_text + num_text > info_ptr->max_text)
  174291. {
  174292. if (info_ptr->text != NULL)
  174293. {
  174294. png_textp old_text;
  174295. int old_max;
  174296. old_max = info_ptr->max_text;
  174297. info_ptr->max_text = info_ptr->num_text + num_text + 8;
  174298. old_text = info_ptr->text;
  174299. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174300. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174301. if (info_ptr->text == NULL)
  174302. {
  174303. png_free(png_ptr, old_text);
  174304. return(1);
  174305. }
  174306. png_memcpy(info_ptr->text, old_text, (png_size_t)(old_max *
  174307. png_sizeof(png_text)));
  174308. png_free(png_ptr, old_text);
  174309. }
  174310. else
  174311. {
  174312. info_ptr->max_text = num_text + 8;
  174313. info_ptr->num_text = 0;
  174314. info_ptr->text = (png_textp)png_malloc_warn(png_ptr,
  174315. (png_uint_32)(info_ptr->max_text * png_sizeof (png_text)));
  174316. if (info_ptr->text == NULL)
  174317. return(1);
  174318. #ifdef PNG_FREE_ME_SUPPORTED
  174319. info_ptr->free_me |= PNG_FREE_TEXT;
  174320. #endif
  174321. }
  174322. png_debug1(3, "allocated %d entries for info_ptr->text\n",
  174323. info_ptr->max_text);
  174324. }
  174325. for (i = 0; i < num_text; i++)
  174326. {
  174327. png_size_t text_length,key_len;
  174328. png_size_t lang_len,lang_key_len;
  174329. png_textp textp = &(info_ptr->text[info_ptr->num_text]);
  174330. if (text_ptr[i].key == NULL)
  174331. continue;
  174332. key_len = png_strlen(text_ptr[i].key);
  174333. if(text_ptr[i].compression <= 0)
  174334. {
  174335. lang_len = 0;
  174336. lang_key_len = 0;
  174337. }
  174338. else
  174339. #ifdef PNG_iTXt_SUPPORTED
  174340. {
  174341. if (text_ptr[i].lang != NULL)
  174342. lang_len = png_strlen(text_ptr[i].lang);
  174343. else
  174344. lang_len = 0;
  174345. if (text_ptr[i].lang_key != NULL)
  174346. lang_key_len = png_strlen(text_ptr[i].lang_key);
  174347. else
  174348. lang_key_len = 0;
  174349. }
  174350. #else
  174351. {
  174352. png_warning(png_ptr, "iTXt chunk not supported.");
  174353. continue;
  174354. }
  174355. #endif
  174356. if (text_ptr[i].text == NULL || text_ptr[i].text[0] == '\0')
  174357. {
  174358. text_length = 0;
  174359. #ifdef PNG_iTXt_SUPPORTED
  174360. if(text_ptr[i].compression > 0)
  174361. textp->compression = PNG_ITXT_COMPRESSION_NONE;
  174362. else
  174363. #endif
  174364. textp->compression = PNG_TEXT_COMPRESSION_NONE;
  174365. }
  174366. else
  174367. {
  174368. text_length = png_strlen(text_ptr[i].text);
  174369. textp->compression = text_ptr[i].compression;
  174370. }
  174371. textp->key = (png_charp)png_malloc_warn(png_ptr,
  174372. (png_uint_32)(key_len + text_length + lang_len + lang_key_len + 4));
  174373. if (textp->key == NULL)
  174374. return(1);
  174375. png_debug2(2, "Allocated %lu bytes at %x in png_set_text\n",
  174376. (png_uint_32)(key_len + lang_len + lang_key_len + text_length + 4),
  174377. (int)textp->key);
  174378. png_memcpy(textp->key, text_ptr[i].key,
  174379. (png_size_t)(key_len));
  174380. *(textp->key+key_len) = '\0';
  174381. #ifdef PNG_iTXt_SUPPORTED
  174382. if (text_ptr[i].compression > 0)
  174383. {
  174384. textp->lang=textp->key + key_len + 1;
  174385. png_memcpy(textp->lang, text_ptr[i].lang, lang_len);
  174386. *(textp->lang+lang_len) = '\0';
  174387. textp->lang_key=textp->lang + lang_len + 1;
  174388. png_memcpy(textp->lang_key, text_ptr[i].lang_key, lang_key_len);
  174389. *(textp->lang_key+lang_key_len) = '\0';
  174390. textp->text=textp->lang_key + lang_key_len + 1;
  174391. }
  174392. else
  174393. #endif
  174394. {
  174395. #ifdef PNG_iTXt_SUPPORTED
  174396. textp->lang=NULL;
  174397. textp->lang_key=NULL;
  174398. #endif
  174399. textp->text=textp->key + key_len + 1;
  174400. }
  174401. if(text_length)
  174402. png_memcpy(textp->text, text_ptr[i].text,
  174403. (png_size_t)(text_length));
  174404. *(textp->text+text_length) = '\0';
  174405. #ifdef PNG_iTXt_SUPPORTED
  174406. if(textp->compression > 0)
  174407. {
  174408. textp->text_length = 0;
  174409. textp->itxt_length = text_length;
  174410. }
  174411. else
  174412. #endif
  174413. {
  174414. textp->text_length = text_length;
  174415. #ifdef PNG_iTXt_SUPPORTED
  174416. textp->itxt_length = 0;
  174417. #endif
  174418. }
  174419. info_ptr->num_text++;
  174420. png_debug1(3, "transferred text chunk %d\n", info_ptr->num_text);
  174421. }
  174422. return(0);
  174423. }
  174424. #endif
  174425. #if defined(PNG_tIME_SUPPORTED)
  174426. void PNGAPI
  174427. png_set_tIME(png_structp png_ptr, png_infop info_ptr, png_timep mod_time)
  174428. {
  174429. png_debug1(1, "in %s storage function\n", "tIME");
  174430. if (png_ptr == NULL || info_ptr == NULL ||
  174431. (png_ptr->mode & PNG_WROTE_tIME))
  174432. return;
  174433. png_memcpy(&(info_ptr->mod_time), mod_time, png_sizeof (png_time));
  174434. info_ptr->valid |= PNG_INFO_tIME;
  174435. }
  174436. #endif
  174437. #if defined(PNG_tRNS_SUPPORTED)
  174438. void PNGAPI
  174439. png_set_tRNS(png_structp png_ptr, png_infop info_ptr,
  174440. png_bytep trans, int num_trans, png_color_16p trans_values)
  174441. {
  174442. png_debug1(1, "in %s storage function\n", "tRNS");
  174443. if (png_ptr == NULL || info_ptr == NULL)
  174444. return;
  174445. if (trans != NULL)
  174446. {
  174447. #ifdef PNG_FREE_ME_SUPPORTED
  174448. png_free_data(png_ptr, info_ptr, PNG_FREE_TRNS, 0);
  174449. #endif
  174450. png_ptr->trans = info_ptr->trans = (png_bytep)png_malloc(png_ptr,
  174451. (png_uint_32)PNG_MAX_PALETTE_LENGTH);
  174452. if (num_trans <= PNG_MAX_PALETTE_LENGTH)
  174453. png_memcpy(info_ptr->trans, trans, (png_size_t)num_trans);
  174454. #ifdef PNG_FREE_ME_SUPPORTED
  174455. info_ptr->free_me |= PNG_FREE_TRNS;
  174456. #else
  174457. png_ptr->flags |= PNG_FLAG_FREE_TRNS;
  174458. #endif
  174459. }
  174460. if (trans_values != NULL)
  174461. {
  174462. png_memcpy(&(info_ptr->trans_values), trans_values,
  174463. png_sizeof(png_color_16));
  174464. if (num_trans == 0)
  174465. num_trans = 1;
  174466. }
  174467. info_ptr->num_trans = (png_uint_16)num_trans;
  174468. info_ptr->valid |= PNG_INFO_tRNS;
  174469. }
  174470. #endif
  174471. #if defined(PNG_sPLT_SUPPORTED)
  174472. void PNGAPI
  174473. png_set_sPLT(png_structp png_ptr,
  174474. png_infop info_ptr, png_sPLT_tp entries, int nentries)
  174475. {
  174476. png_sPLT_tp np;
  174477. int i;
  174478. if (png_ptr == NULL || info_ptr == NULL)
  174479. return;
  174480. np = (png_sPLT_tp)png_malloc_warn(png_ptr,
  174481. (info_ptr->splt_palettes_num + nentries) * png_sizeof(png_sPLT_t));
  174482. if (np == NULL)
  174483. {
  174484. png_warning(png_ptr, "No memory for sPLT palettes.");
  174485. return;
  174486. }
  174487. png_memcpy(np, info_ptr->splt_palettes,
  174488. info_ptr->splt_palettes_num * png_sizeof(png_sPLT_t));
  174489. png_free(png_ptr, info_ptr->splt_palettes);
  174490. info_ptr->splt_palettes=NULL;
  174491. for (i = 0; i < nentries; i++)
  174492. {
  174493. png_sPLT_tp to = np + info_ptr->splt_palettes_num + i;
  174494. png_sPLT_tp from = entries + i;
  174495. to->name = (png_charp)png_malloc_warn(png_ptr,
  174496. png_strlen(from->name) + 1);
  174497. if (to->name == NULL)
  174498. {
  174499. png_warning(png_ptr,
  174500. "Out of memory while processing sPLT chunk");
  174501. }
  174502. png_strncpy(to->name, from->name, png_strlen(from->name)+1);
  174503. to->entries = (png_sPLT_entryp)png_malloc_warn(png_ptr,
  174504. from->nentries * png_sizeof(png_sPLT_entry));
  174505. png_memcpy(to->entries, from->entries,
  174506. from->nentries * png_sizeof(png_sPLT_entry));
  174507. if (to->entries == NULL)
  174508. {
  174509. png_warning(png_ptr,
  174510. "Out of memory while processing sPLT chunk");
  174511. png_free(png_ptr,to->name);
  174512. to->name = NULL;
  174513. }
  174514. to->nentries = from->nentries;
  174515. to->depth = from->depth;
  174516. }
  174517. info_ptr->splt_palettes = np;
  174518. info_ptr->splt_palettes_num += nentries;
  174519. info_ptr->valid |= PNG_INFO_sPLT;
  174520. #ifdef PNG_FREE_ME_SUPPORTED
  174521. info_ptr->free_me |= PNG_FREE_SPLT;
  174522. #endif
  174523. }
  174524. #endif /* PNG_sPLT_SUPPORTED */
  174525. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174526. void PNGAPI
  174527. png_set_unknown_chunks(png_structp png_ptr,
  174528. png_infop info_ptr, png_unknown_chunkp unknowns, int num_unknowns)
  174529. {
  174530. png_unknown_chunkp np;
  174531. int i;
  174532. if (png_ptr == NULL || info_ptr == NULL || num_unknowns == 0)
  174533. return;
  174534. np = (png_unknown_chunkp)png_malloc_warn(png_ptr,
  174535. (info_ptr->unknown_chunks_num + num_unknowns) *
  174536. png_sizeof(png_unknown_chunk));
  174537. if (np == NULL)
  174538. {
  174539. png_warning(png_ptr,
  174540. "Out of memory while processing unknown chunk.");
  174541. return;
  174542. }
  174543. png_memcpy(np, info_ptr->unknown_chunks,
  174544. info_ptr->unknown_chunks_num * png_sizeof(png_unknown_chunk));
  174545. png_free(png_ptr, info_ptr->unknown_chunks);
  174546. info_ptr->unknown_chunks=NULL;
  174547. for (i = 0; i < num_unknowns; i++)
  174548. {
  174549. png_unknown_chunkp to = np + info_ptr->unknown_chunks_num + i;
  174550. png_unknown_chunkp from = unknowns + i;
  174551. png_strncpy((png_charp)to->name, (png_charp)from->name, 5);
  174552. to->data = (png_bytep)png_malloc_warn(png_ptr, from->size);
  174553. if (to->data == NULL)
  174554. {
  174555. png_warning(png_ptr,
  174556. "Out of memory while processing unknown chunk.");
  174557. }
  174558. else
  174559. {
  174560. png_memcpy(to->data, from->data, from->size);
  174561. to->size = from->size;
  174562. to->location = (png_byte)(png_ptr->mode & 0xff);
  174563. }
  174564. }
  174565. info_ptr->unknown_chunks = np;
  174566. info_ptr->unknown_chunks_num += num_unknowns;
  174567. #ifdef PNG_FREE_ME_SUPPORTED
  174568. info_ptr->free_me |= PNG_FREE_UNKN;
  174569. #endif
  174570. }
  174571. void PNGAPI
  174572. png_set_unknown_chunk_location(png_structp png_ptr, png_infop info_ptr,
  174573. int chunk, int location)
  174574. {
  174575. if(png_ptr != NULL && info_ptr != NULL && chunk >= 0 && chunk <
  174576. (int)info_ptr->unknown_chunks_num)
  174577. info_ptr->unknown_chunks[chunk].location = (png_byte)location;
  174578. }
  174579. #endif
  174580. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  174581. #if defined(PNG_READ_EMPTY_PLTE_SUPPORTED) || \
  174582. defined(PNG_WRITE_EMPTY_PLTE_SUPPORTED)
  174583. void PNGAPI
  174584. png_permit_empty_plte (png_structp png_ptr, int empty_plte_permitted)
  174585. {
  174586. png_debug(1, "in png_permit_empty_plte, DEPRECATED.\n");
  174587. if (png_ptr == NULL)
  174588. return;
  174589. png_ptr->mng_features_permitted = (png_byte)
  174590. ((png_ptr->mng_features_permitted & (~(PNG_FLAG_MNG_EMPTY_PLTE))) |
  174591. ((empty_plte_permitted & PNG_FLAG_MNG_EMPTY_PLTE)));
  174592. }
  174593. #endif
  174594. #endif
  174595. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  174596. png_uint_32 PNGAPI
  174597. png_permit_mng_features (png_structp png_ptr, png_uint_32 mng_features)
  174598. {
  174599. png_debug(1, "in png_permit_mng_features\n");
  174600. if (png_ptr == NULL)
  174601. return (png_uint_32)0;
  174602. png_ptr->mng_features_permitted =
  174603. (png_byte)(mng_features & PNG_ALL_MNG_FEATURES);
  174604. return (png_uint_32)png_ptr->mng_features_permitted;
  174605. }
  174606. #endif
  174607. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  174608. void PNGAPI
  174609. png_set_keep_unknown_chunks(png_structp png_ptr, int keep, png_bytep
  174610. chunk_list, int num_chunks)
  174611. {
  174612. png_bytep new_list, p;
  174613. int i, old_num_chunks;
  174614. if (png_ptr == NULL)
  174615. return;
  174616. if (num_chunks == 0)
  174617. {
  174618. if(keep == PNG_HANDLE_CHUNK_ALWAYS || keep == PNG_HANDLE_CHUNK_IF_SAFE)
  174619. png_ptr->flags |= PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174620. else
  174621. png_ptr->flags &= ~PNG_FLAG_KEEP_UNKNOWN_CHUNKS;
  174622. if(keep == PNG_HANDLE_CHUNK_ALWAYS)
  174623. png_ptr->flags |= PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174624. else
  174625. png_ptr->flags &= ~PNG_FLAG_KEEP_UNSAFE_CHUNKS;
  174626. return;
  174627. }
  174628. if (chunk_list == NULL)
  174629. return;
  174630. old_num_chunks=png_ptr->num_chunk_list;
  174631. new_list=(png_bytep)png_malloc(png_ptr,
  174632. (png_uint_32)(5*(num_chunks+old_num_chunks)));
  174633. if(png_ptr->chunk_list != NULL)
  174634. {
  174635. png_memcpy(new_list, png_ptr->chunk_list,
  174636. (png_size_t)(5*old_num_chunks));
  174637. png_free(png_ptr, png_ptr->chunk_list);
  174638. png_ptr->chunk_list=NULL;
  174639. }
  174640. png_memcpy(new_list+5*old_num_chunks, chunk_list,
  174641. (png_size_t)(5*num_chunks));
  174642. for (p=new_list+5*old_num_chunks+4, i=0; i<num_chunks; i++, p+=5)
  174643. *p=(png_byte)keep;
  174644. png_ptr->num_chunk_list=old_num_chunks+num_chunks;
  174645. png_ptr->chunk_list=new_list;
  174646. #ifdef PNG_FREE_ME_SUPPORTED
  174647. png_ptr->free_me |= PNG_FREE_LIST;
  174648. #endif
  174649. }
  174650. #endif
  174651. #if defined(PNG_READ_USER_CHUNKS_SUPPORTED)
  174652. void PNGAPI
  174653. png_set_read_user_chunk_fn(png_structp png_ptr, png_voidp user_chunk_ptr,
  174654. png_user_chunk_ptr read_user_chunk_fn)
  174655. {
  174656. png_debug(1, "in png_set_read_user_chunk_fn\n");
  174657. if (png_ptr == NULL)
  174658. return;
  174659. png_ptr->read_user_chunk_fn = read_user_chunk_fn;
  174660. png_ptr->user_chunk_ptr = user_chunk_ptr;
  174661. }
  174662. #endif
  174663. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  174664. void PNGAPI
  174665. png_set_rows(png_structp png_ptr, png_infop info_ptr, png_bytepp row_pointers)
  174666. {
  174667. png_debug1(1, "in %s storage function\n", "rows");
  174668. if (png_ptr == NULL || info_ptr == NULL)
  174669. return;
  174670. if(info_ptr->row_pointers && (info_ptr->row_pointers != row_pointers))
  174671. png_free_data(png_ptr, info_ptr, PNG_FREE_ROWS, 0);
  174672. info_ptr->row_pointers = row_pointers;
  174673. if(row_pointers)
  174674. info_ptr->valid |= PNG_INFO_IDAT;
  174675. }
  174676. #endif
  174677. #ifdef PNG_WRITE_SUPPORTED
  174678. void PNGAPI
  174679. png_set_compression_buffer_size(png_structp png_ptr, png_uint_32 size)
  174680. {
  174681. if (png_ptr == NULL)
  174682. return;
  174683. if(png_ptr->zbuf)
  174684. png_free(png_ptr, png_ptr->zbuf);
  174685. png_ptr->zbuf_size = (png_size_t)size;
  174686. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr, size);
  174687. png_ptr->zstream.next_out = png_ptr->zbuf;
  174688. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  174689. }
  174690. #endif
  174691. void PNGAPI
  174692. png_set_invalid(png_structp png_ptr, png_infop info_ptr, int mask)
  174693. {
  174694. if (png_ptr && info_ptr)
  174695. info_ptr->valid &= ~(mask);
  174696. }
  174697. #ifndef PNG_1_0_X
  174698. #ifdef PNG_ASSEMBLER_CODE_SUPPORTED
  174699. void PNGAPI
  174700. png_set_asm_flags (png_structp png_ptr, png_uint_32 asm_flags)
  174701. {
  174702. if (png_ptr != NULL)
  174703. png_ptr->asm_flags = 0;
  174704. }
  174705. void PNGAPI
  174706. png_set_mmx_thresholds (png_structp png_ptr,
  174707. png_byte mmx_bitdepth_threshold,
  174708. png_uint_32 mmx_rowbytes_threshold)
  174709. {
  174710. if (png_ptr == NULL)
  174711. return;
  174712. }
  174713. #endif /* ?PNG_ASSEMBLER_CODE_SUPPORTED */
  174714. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  174715. void PNGAPI
  174716. png_set_user_limits (png_structp png_ptr, png_uint_32 user_width_max,
  174717. png_uint_32 user_height_max)
  174718. {
  174719. if(png_ptr == NULL) return;
  174720. png_ptr->user_width_max = user_width_max;
  174721. png_ptr->user_height_max = user_height_max;
  174722. }
  174723. #endif /* ?PNG_SET_USER_LIMITS_SUPPORTED */
  174724. #endif /* ?PNG_1_0_X */
  174725. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  174726. /*** End of inlined file: pngset.c ***/
  174727. /*** Start of inlined file: pngtrans.c ***/
  174728. #define PNG_INTERNAL
  174729. #if defined(PNG_READ_SUPPORTED) || defined(PNG_WRITE_SUPPORTED)
  174730. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  174731. void PNGAPI
  174732. png_set_bgr(png_structp png_ptr)
  174733. {
  174734. png_debug(1, "in png_set_bgr\n");
  174735. if(png_ptr == NULL) return;
  174736. png_ptr->transformations |= PNG_BGR;
  174737. }
  174738. #endif
  174739. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174740. void PNGAPI
  174741. png_set_swap(png_structp png_ptr)
  174742. {
  174743. png_debug(1, "in png_set_swap\n");
  174744. if(png_ptr == NULL) return;
  174745. if (png_ptr->bit_depth == 16)
  174746. png_ptr->transformations |= PNG_SWAP_BYTES;
  174747. }
  174748. #endif
  174749. #if defined(PNG_READ_PACK_SUPPORTED) || defined(PNG_WRITE_PACK_SUPPORTED)
  174750. void PNGAPI
  174751. png_set_packing(png_structp png_ptr)
  174752. {
  174753. png_debug(1, "in png_set_packing\n");
  174754. if(png_ptr == NULL) return;
  174755. if (png_ptr->bit_depth < 8)
  174756. {
  174757. png_ptr->transformations |= PNG_PACK;
  174758. png_ptr->usr_bit_depth = 8;
  174759. }
  174760. }
  174761. #endif
  174762. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174763. void PNGAPI
  174764. png_set_packswap(png_structp png_ptr)
  174765. {
  174766. png_debug(1, "in png_set_packswap\n");
  174767. if(png_ptr == NULL) return;
  174768. if (png_ptr->bit_depth < 8)
  174769. png_ptr->transformations |= PNG_PACKSWAP;
  174770. }
  174771. #endif
  174772. #if defined(PNG_READ_SHIFT_SUPPORTED) || defined(PNG_WRITE_SHIFT_SUPPORTED)
  174773. void PNGAPI
  174774. png_set_shift(png_structp png_ptr, png_color_8p true_bits)
  174775. {
  174776. png_debug(1, "in png_set_shift\n");
  174777. if(png_ptr == NULL) return;
  174778. png_ptr->transformations |= PNG_SHIFT;
  174779. png_ptr->shift = *true_bits;
  174780. }
  174781. #endif
  174782. #if defined(PNG_READ_INTERLACING_SUPPORTED) || \
  174783. defined(PNG_WRITE_INTERLACING_SUPPORTED)
  174784. int PNGAPI
  174785. png_set_interlace_handling(png_structp png_ptr)
  174786. {
  174787. png_debug(1, "in png_set_interlace handling\n");
  174788. if (png_ptr && png_ptr->interlaced)
  174789. {
  174790. png_ptr->transformations |= PNG_INTERLACE;
  174791. return (7);
  174792. }
  174793. return (1);
  174794. }
  174795. #endif
  174796. #if defined(PNG_READ_FILLER_SUPPORTED) || defined(PNG_WRITE_FILLER_SUPPORTED)
  174797. void PNGAPI
  174798. png_set_filler(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174799. {
  174800. png_debug(1, "in png_set_filler\n");
  174801. if(png_ptr == NULL) return;
  174802. png_ptr->transformations |= PNG_FILLER;
  174803. png_ptr->filler = (png_byte)filler;
  174804. if (filler_loc == PNG_FILLER_AFTER)
  174805. png_ptr->flags |= PNG_FLAG_FILLER_AFTER;
  174806. else
  174807. png_ptr->flags &= ~PNG_FLAG_FILLER_AFTER;
  174808. if (png_ptr->color_type == PNG_COLOR_TYPE_RGB)
  174809. {
  174810. png_ptr->usr_channels = 4;
  174811. }
  174812. if (png_ptr->color_type == PNG_COLOR_TYPE_GRAY && png_ptr->bit_depth >= 8)
  174813. {
  174814. png_ptr->usr_channels = 2;
  174815. }
  174816. }
  174817. #if !defined(PNG_1_0_X)
  174818. void PNGAPI
  174819. png_set_add_alpha(png_structp png_ptr, png_uint_32 filler, int filler_loc)
  174820. {
  174821. png_debug(1, "in png_set_add_alpha\n");
  174822. if(png_ptr == NULL) return;
  174823. png_set_filler(png_ptr, filler, filler_loc);
  174824. png_ptr->transformations |= PNG_ADD_ALPHA;
  174825. }
  174826. #endif
  174827. #endif
  174828. #if defined(PNG_READ_SWAP_ALPHA_SUPPORTED) || \
  174829. defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  174830. void PNGAPI
  174831. png_set_swap_alpha(png_structp png_ptr)
  174832. {
  174833. png_debug(1, "in png_set_swap_alpha\n");
  174834. if(png_ptr == NULL) return;
  174835. png_ptr->transformations |= PNG_SWAP_ALPHA;
  174836. }
  174837. #endif
  174838. #if defined(PNG_READ_INVERT_ALPHA_SUPPORTED) || \
  174839. defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  174840. void PNGAPI
  174841. png_set_invert_alpha(png_structp png_ptr)
  174842. {
  174843. png_debug(1, "in png_set_invert_alpha\n");
  174844. if(png_ptr == NULL) return;
  174845. png_ptr->transformations |= PNG_INVERT_ALPHA;
  174846. }
  174847. #endif
  174848. #if defined(PNG_READ_INVERT_SUPPORTED) || defined(PNG_WRITE_INVERT_SUPPORTED)
  174849. void PNGAPI
  174850. png_set_invert_mono(png_structp png_ptr)
  174851. {
  174852. png_debug(1, "in png_set_invert_mono\n");
  174853. if(png_ptr == NULL) return;
  174854. png_ptr->transformations |= PNG_INVERT_MONO;
  174855. }
  174856. void /* PRIVATE */
  174857. png_do_invert(png_row_infop row_info, png_bytep row)
  174858. {
  174859. png_debug(1, "in png_do_invert\n");
  174860. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174861. if (row == NULL || row_info == NULL)
  174862. return;
  174863. #endif
  174864. if (row_info->color_type == PNG_COLOR_TYPE_GRAY)
  174865. {
  174866. png_bytep rp = row;
  174867. png_uint_32 i;
  174868. png_uint_32 istop = row_info->rowbytes;
  174869. for (i = 0; i < istop; i++)
  174870. {
  174871. *rp = (png_byte)(~(*rp));
  174872. rp++;
  174873. }
  174874. }
  174875. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174876. row_info->bit_depth == 8)
  174877. {
  174878. png_bytep rp = row;
  174879. png_uint_32 i;
  174880. png_uint_32 istop = row_info->rowbytes;
  174881. for (i = 0; i < istop; i+=2)
  174882. {
  174883. *rp = (png_byte)(~(*rp));
  174884. rp+=2;
  174885. }
  174886. }
  174887. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  174888. row_info->bit_depth == 16)
  174889. {
  174890. png_bytep rp = row;
  174891. png_uint_32 i;
  174892. png_uint_32 istop = row_info->rowbytes;
  174893. for (i = 0; i < istop; i+=4)
  174894. {
  174895. *rp = (png_byte)(~(*rp));
  174896. *(rp+1) = (png_byte)(~(*(rp+1)));
  174897. rp+=4;
  174898. }
  174899. }
  174900. }
  174901. #endif
  174902. #if defined(PNG_READ_SWAP_SUPPORTED) || defined(PNG_WRITE_SWAP_SUPPORTED)
  174903. void /* PRIVATE */
  174904. png_do_swap(png_row_infop row_info, png_bytep row)
  174905. {
  174906. png_debug(1, "in png_do_swap\n");
  174907. if (
  174908. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  174909. row != NULL && row_info != NULL &&
  174910. #endif
  174911. row_info->bit_depth == 16)
  174912. {
  174913. png_bytep rp = row;
  174914. png_uint_32 i;
  174915. png_uint_32 istop= row_info->width * row_info->channels;
  174916. for (i = 0; i < istop; i++, rp += 2)
  174917. {
  174918. png_byte t = *rp;
  174919. *rp = *(rp + 1);
  174920. *(rp + 1) = t;
  174921. }
  174922. }
  174923. }
  174924. #endif
  174925. #if defined(PNG_READ_PACKSWAP_SUPPORTED)||defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  174926. static PNG_CONST png_byte onebppswaptable[256] = {
  174927. 0x00, 0x80, 0x40, 0xC0, 0x20, 0xA0, 0x60, 0xE0,
  174928. 0x10, 0x90, 0x50, 0xD0, 0x30, 0xB0, 0x70, 0xF0,
  174929. 0x08, 0x88, 0x48, 0xC8, 0x28, 0xA8, 0x68, 0xE8,
  174930. 0x18, 0x98, 0x58, 0xD8, 0x38, 0xB8, 0x78, 0xF8,
  174931. 0x04, 0x84, 0x44, 0xC4, 0x24, 0xA4, 0x64, 0xE4,
  174932. 0x14, 0x94, 0x54, 0xD4, 0x34, 0xB4, 0x74, 0xF4,
  174933. 0x0C, 0x8C, 0x4C, 0xCC, 0x2C, 0xAC, 0x6C, 0xEC,
  174934. 0x1C, 0x9C, 0x5C, 0xDC, 0x3C, 0xBC, 0x7C, 0xFC,
  174935. 0x02, 0x82, 0x42, 0xC2, 0x22, 0xA2, 0x62, 0xE2,
  174936. 0x12, 0x92, 0x52, 0xD2, 0x32, 0xB2, 0x72, 0xF2,
  174937. 0x0A, 0x8A, 0x4A, 0xCA, 0x2A, 0xAA, 0x6A, 0xEA,
  174938. 0x1A, 0x9A, 0x5A, 0xDA, 0x3A, 0xBA, 0x7A, 0xFA,
  174939. 0x06, 0x86, 0x46, 0xC6, 0x26, 0xA6, 0x66, 0xE6,
  174940. 0x16, 0x96, 0x56, 0xD6, 0x36, 0xB6, 0x76, 0xF6,
  174941. 0x0E, 0x8E, 0x4E, 0xCE, 0x2E, 0xAE, 0x6E, 0xEE,
  174942. 0x1E, 0x9E, 0x5E, 0xDE, 0x3E, 0xBE, 0x7E, 0xFE,
  174943. 0x01, 0x81, 0x41, 0xC1, 0x21, 0xA1, 0x61, 0xE1,
  174944. 0x11, 0x91, 0x51, 0xD1, 0x31, 0xB1, 0x71, 0xF1,
  174945. 0x09, 0x89, 0x49, 0xC9, 0x29, 0xA9, 0x69, 0xE9,
  174946. 0x19, 0x99, 0x59, 0xD9, 0x39, 0xB9, 0x79, 0xF9,
  174947. 0x05, 0x85, 0x45, 0xC5, 0x25, 0xA5, 0x65, 0xE5,
  174948. 0x15, 0x95, 0x55, 0xD5, 0x35, 0xB5, 0x75, 0xF5,
  174949. 0x0D, 0x8D, 0x4D, 0xCD, 0x2D, 0xAD, 0x6D, 0xED,
  174950. 0x1D, 0x9D, 0x5D, 0xDD, 0x3D, 0xBD, 0x7D, 0xFD,
  174951. 0x03, 0x83, 0x43, 0xC3, 0x23, 0xA3, 0x63, 0xE3,
  174952. 0x13, 0x93, 0x53, 0xD3, 0x33, 0xB3, 0x73, 0xF3,
  174953. 0x0B, 0x8B, 0x4B, 0xCB, 0x2B, 0xAB, 0x6B, 0xEB,
  174954. 0x1B, 0x9B, 0x5B, 0xDB, 0x3B, 0xBB, 0x7B, 0xFB,
  174955. 0x07, 0x87, 0x47, 0xC7, 0x27, 0xA7, 0x67, 0xE7,
  174956. 0x17, 0x97, 0x57, 0xD7, 0x37, 0xB7, 0x77, 0xF7,
  174957. 0x0F, 0x8F, 0x4F, 0xCF, 0x2F, 0xAF, 0x6F, 0xEF,
  174958. 0x1F, 0x9F, 0x5F, 0xDF, 0x3F, 0xBF, 0x7F, 0xFF
  174959. };
  174960. static PNG_CONST png_byte twobppswaptable[256] = {
  174961. 0x00, 0x40, 0x80, 0xC0, 0x10, 0x50, 0x90, 0xD0,
  174962. 0x20, 0x60, 0xA0, 0xE0, 0x30, 0x70, 0xB0, 0xF0,
  174963. 0x04, 0x44, 0x84, 0xC4, 0x14, 0x54, 0x94, 0xD4,
  174964. 0x24, 0x64, 0xA4, 0xE4, 0x34, 0x74, 0xB4, 0xF4,
  174965. 0x08, 0x48, 0x88, 0xC8, 0x18, 0x58, 0x98, 0xD8,
  174966. 0x28, 0x68, 0xA8, 0xE8, 0x38, 0x78, 0xB8, 0xF8,
  174967. 0x0C, 0x4C, 0x8C, 0xCC, 0x1C, 0x5C, 0x9C, 0xDC,
  174968. 0x2C, 0x6C, 0xAC, 0xEC, 0x3C, 0x7C, 0xBC, 0xFC,
  174969. 0x01, 0x41, 0x81, 0xC1, 0x11, 0x51, 0x91, 0xD1,
  174970. 0x21, 0x61, 0xA1, 0xE1, 0x31, 0x71, 0xB1, 0xF1,
  174971. 0x05, 0x45, 0x85, 0xC5, 0x15, 0x55, 0x95, 0xD5,
  174972. 0x25, 0x65, 0xA5, 0xE5, 0x35, 0x75, 0xB5, 0xF5,
  174973. 0x09, 0x49, 0x89, 0xC9, 0x19, 0x59, 0x99, 0xD9,
  174974. 0x29, 0x69, 0xA9, 0xE9, 0x39, 0x79, 0xB9, 0xF9,
  174975. 0x0D, 0x4D, 0x8D, 0xCD, 0x1D, 0x5D, 0x9D, 0xDD,
  174976. 0x2D, 0x6D, 0xAD, 0xED, 0x3D, 0x7D, 0xBD, 0xFD,
  174977. 0x02, 0x42, 0x82, 0xC2, 0x12, 0x52, 0x92, 0xD2,
  174978. 0x22, 0x62, 0xA2, 0xE2, 0x32, 0x72, 0xB2, 0xF2,
  174979. 0x06, 0x46, 0x86, 0xC6, 0x16, 0x56, 0x96, 0xD6,
  174980. 0x26, 0x66, 0xA6, 0xE6, 0x36, 0x76, 0xB6, 0xF6,
  174981. 0x0A, 0x4A, 0x8A, 0xCA, 0x1A, 0x5A, 0x9A, 0xDA,
  174982. 0x2A, 0x6A, 0xAA, 0xEA, 0x3A, 0x7A, 0xBA, 0xFA,
  174983. 0x0E, 0x4E, 0x8E, 0xCE, 0x1E, 0x5E, 0x9E, 0xDE,
  174984. 0x2E, 0x6E, 0xAE, 0xEE, 0x3E, 0x7E, 0xBE, 0xFE,
  174985. 0x03, 0x43, 0x83, 0xC3, 0x13, 0x53, 0x93, 0xD3,
  174986. 0x23, 0x63, 0xA3, 0xE3, 0x33, 0x73, 0xB3, 0xF3,
  174987. 0x07, 0x47, 0x87, 0xC7, 0x17, 0x57, 0x97, 0xD7,
  174988. 0x27, 0x67, 0xA7, 0xE7, 0x37, 0x77, 0xB7, 0xF7,
  174989. 0x0B, 0x4B, 0x8B, 0xCB, 0x1B, 0x5B, 0x9B, 0xDB,
  174990. 0x2B, 0x6B, 0xAB, 0xEB, 0x3B, 0x7B, 0xBB, 0xFB,
  174991. 0x0F, 0x4F, 0x8F, 0xCF, 0x1F, 0x5F, 0x9F, 0xDF,
  174992. 0x2F, 0x6F, 0xAF, 0xEF, 0x3F, 0x7F, 0xBF, 0xFF
  174993. };
  174994. static PNG_CONST png_byte fourbppswaptable[256] = {
  174995. 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70,
  174996. 0x80, 0x90, 0xA0, 0xB0, 0xC0, 0xD0, 0xE0, 0xF0,
  174997. 0x01, 0x11, 0x21, 0x31, 0x41, 0x51, 0x61, 0x71,
  174998. 0x81, 0x91, 0xA1, 0xB1, 0xC1, 0xD1, 0xE1, 0xF1,
  174999. 0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
  175000. 0x82, 0x92, 0xA2, 0xB2, 0xC2, 0xD2, 0xE2, 0xF2,
  175001. 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63, 0x73,
  175002. 0x83, 0x93, 0xA3, 0xB3, 0xC3, 0xD3, 0xE3, 0xF3,
  175003. 0x04, 0x14, 0x24, 0x34, 0x44, 0x54, 0x64, 0x74,
  175004. 0x84, 0x94, 0xA4, 0xB4, 0xC4, 0xD4, 0xE4, 0xF4,
  175005. 0x05, 0x15, 0x25, 0x35, 0x45, 0x55, 0x65, 0x75,
  175006. 0x85, 0x95, 0xA5, 0xB5, 0xC5, 0xD5, 0xE5, 0xF5,
  175007. 0x06, 0x16, 0x26, 0x36, 0x46, 0x56, 0x66, 0x76,
  175008. 0x86, 0x96, 0xA6, 0xB6, 0xC6, 0xD6, 0xE6, 0xF6,
  175009. 0x07, 0x17, 0x27, 0x37, 0x47, 0x57, 0x67, 0x77,
  175010. 0x87, 0x97, 0xA7, 0xB7, 0xC7, 0xD7, 0xE7, 0xF7,
  175011. 0x08, 0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78,
  175012. 0x88, 0x98, 0xA8, 0xB8, 0xC8, 0xD8, 0xE8, 0xF8,
  175013. 0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0x79,
  175014. 0x89, 0x99, 0xA9, 0xB9, 0xC9, 0xD9, 0xE9, 0xF9,
  175015. 0x0A, 0x1A, 0x2A, 0x3A, 0x4A, 0x5A, 0x6A, 0x7A,
  175016. 0x8A, 0x9A, 0xAA, 0xBA, 0xCA, 0xDA, 0xEA, 0xFA,
  175017. 0x0B, 0x1B, 0x2B, 0x3B, 0x4B, 0x5B, 0x6B, 0x7B,
  175018. 0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
  175019. 0x0C, 0x1C, 0x2C, 0x3C, 0x4C, 0x5C, 0x6C, 0x7C,
  175020. 0x8C, 0x9C, 0xAC, 0xBC, 0xCC, 0xDC, 0xEC, 0xFC,
  175021. 0x0D, 0x1D, 0x2D, 0x3D, 0x4D, 0x5D, 0x6D, 0x7D,
  175022. 0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
  175023. 0x0E, 0x1E, 0x2E, 0x3E, 0x4E, 0x5E, 0x6E, 0x7E,
  175024. 0x8E, 0x9E, 0xAE, 0xBE, 0xCE, 0xDE, 0xEE, 0xFE,
  175025. 0x0F, 0x1F, 0x2F, 0x3F, 0x4F, 0x5F, 0x6F, 0x7F,
  175026. 0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
  175027. };
  175028. void /* PRIVATE */
  175029. png_do_packswap(png_row_infop row_info, png_bytep row)
  175030. {
  175031. png_debug(1, "in png_do_packswap\n");
  175032. if (
  175033. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175034. row != NULL && row_info != NULL &&
  175035. #endif
  175036. row_info->bit_depth < 8)
  175037. {
  175038. png_bytep rp, end, table;
  175039. end = row + row_info->rowbytes;
  175040. if (row_info->bit_depth == 1)
  175041. table = (png_bytep)onebppswaptable;
  175042. else if (row_info->bit_depth == 2)
  175043. table = (png_bytep)twobppswaptable;
  175044. else if (row_info->bit_depth == 4)
  175045. table = (png_bytep)fourbppswaptable;
  175046. else
  175047. return;
  175048. for (rp = row; rp < end; rp++)
  175049. *rp = table[*rp];
  175050. }
  175051. }
  175052. #endif /* PNG_READ_PACKSWAP_SUPPORTED or PNG_WRITE_PACKSWAP_SUPPORTED */
  175053. #if defined(PNG_WRITE_FILLER_SUPPORTED) || \
  175054. defined(PNG_READ_STRIP_ALPHA_SUPPORTED)
  175055. void /* PRIVATE */
  175056. png_do_strip_filler(png_row_infop row_info, png_bytep row, png_uint_32 flags)
  175057. {
  175058. png_debug(1, "in png_do_strip_filler\n");
  175059. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175060. if (row != NULL && row_info != NULL)
  175061. #endif
  175062. {
  175063. png_bytep sp=row;
  175064. png_bytep dp=row;
  175065. png_uint_32 row_width=row_info->width;
  175066. png_uint_32 i;
  175067. if ((row_info->color_type == PNG_COLOR_TYPE_RGB ||
  175068. (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA &&
  175069. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  175070. row_info->channels == 4)
  175071. {
  175072. if (row_info->bit_depth == 8)
  175073. {
  175074. if (flags & PNG_FLAG_FILLER_AFTER)
  175075. {
  175076. dp+=3; sp+=4;
  175077. for (i = 1; i < row_width; i++)
  175078. {
  175079. *dp++ = *sp++;
  175080. *dp++ = *sp++;
  175081. *dp++ = *sp++;
  175082. sp++;
  175083. }
  175084. }
  175085. else
  175086. {
  175087. for (i = 0; i < row_width; i++)
  175088. {
  175089. sp++;
  175090. *dp++ = *sp++;
  175091. *dp++ = *sp++;
  175092. *dp++ = *sp++;
  175093. }
  175094. }
  175095. row_info->pixel_depth = 24;
  175096. row_info->rowbytes = row_width * 3;
  175097. }
  175098. else /* if (row_info->bit_depth == 16) */
  175099. {
  175100. if (flags & PNG_FLAG_FILLER_AFTER)
  175101. {
  175102. sp += 8; dp += 6;
  175103. for (i = 1; i < row_width; i++)
  175104. {
  175105. *dp++ = *sp++;
  175106. *dp++ = *sp++;
  175107. *dp++ = *sp++;
  175108. *dp++ = *sp++;
  175109. *dp++ = *sp++;
  175110. *dp++ = *sp++;
  175111. sp += 2;
  175112. }
  175113. }
  175114. else
  175115. {
  175116. for (i = 0; i < row_width; i++)
  175117. {
  175118. sp+=2;
  175119. *dp++ = *sp++;
  175120. *dp++ = *sp++;
  175121. *dp++ = *sp++;
  175122. *dp++ = *sp++;
  175123. *dp++ = *sp++;
  175124. *dp++ = *sp++;
  175125. }
  175126. }
  175127. row_info->pixel_depth = 48;
  175128. row_info->rowbytes = row_width * 6;
  175129. }
  175130. row_info->channels = 3;
  175131. }
  175132. else if ((row_info->color_type == PNG_COLOR_TYPE_GRAY ||
  175133. (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA &&
  175134. (flags & PNG_FLAG_STRIP_ALPHA))) &&
  175135. row_info->channels == 2)
  175136. {
  175137. if (row_info->bit_depth == 8)
  175138. {
  175139. if (flags & PNG_FLAG_FILLER_AFTER)
  175140. {
  175141. for (i = 0; i < row_width; i++)
  175142. {
  175143. *dp++ = *sp++;
  175144. sp++;
  175145. }
  175146. }
  175147. else
  175148. {
  175149. for (i = 0; i < row_width; i++)
  175150. {
  175151. sp++;
  175152. *dp++ = *sp++;
  175153. }
  175154. }
  175155. row_info->pixel_depth = 8;
  175156. row_info->rowbytes = row_width;
  175157. }
  175158. else /* if (row_info->bit_depth == 16) */
  175159. {
  175160. if (flags & PNG_FLAG_FILLER_AFTER)
  175161. {
  175162. sp += 4; dp += 2;
  175163. for (i = 1; i < row_width; i++)
  175164. {
  175165. *dp++ = *sp++;
  175166. *dp++ = *sp++;
  175167. sp += 2;
  175168. }
  175169. }
  175170. else
  175171. {
  175172. for (i = 0; i < row_width; i++)
  175173. {
  175174. sp += 2;
  175175. *dp++ = *sp++;
  175176. *dp++ = *sp++;
  175177. }
  175178. }
  175179. row_info->pixel_depth = 16;
  175180. row_info->rowbytes = row_width * 2;
  175181. }
  175182. row_info->channels = 1;
  175183. }
  175184. if (flags & PNG_FLAG_STRIP_ALPHA)
  175185. row_info->color_type &= ~PNG_COLOR_MASK_ALPHA;
  175186. }
  175187. }
  175188. #endif
  175189. #if defined(PNG_READ_BGR_SUPPORTED) || defined(PNG_WRITE_BGR_SUPPORTED)
  175190. void /* PRIVATE */
  175191. png_do_bgr(png_row_infop row_info, png_bytep row)
  175192. {
  175193. png_debug(1, "in png_do_bgr\n");
  175194. if (
  175195. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  175196. row != NULL && row_info != NULL &&
  175197. #endif
  175198. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  175199. {
  175200. png_uint_32 row_width = row_info->width;
  175201. if (row_info->bit_depth == 8)
  175202. {
  175203. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  175204. {
  175205. png_bytep rp;
  175206. png_uint_32 i;
  175207. for (i = 0, rp = row; i < row_width; i++, rp += 3)
  175208. {
  175209. png_byte save = *rp;
  175210. *rp = *(rp + 2);
  175211. *(rp + 2) = save;
  175212. }
  175213. }
  175214. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  175215. {
  175216. png_bytep rp;
  175217. png_uint_32 i;
  175218. for (i = 0, rp = row; i < row_width; i++, rp += 4)
  175219. {
  175220. png_byte save = *rp;
  175221. *rp = *(rp + 2);
  175222. *(rp + 2) = save;
  175223. }
  175224. }
  175225. }
  175226. else if (row_info->bit_depth == 16)
  175227. {
  175228. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  175229. {
  175230. png_bytep rp;
  175231. png_uint_32 i;
  175232. for (i = 0, rp = row; i < row_width; i++, rp += 6)
  175233. {
  175234. png_byte save = *rp;
  175235. *rp = *(rp + 4);
  175236. *(rp + 4) = save;
  175237. save = *(rp + 1);
  175238. *(rp + 1) = *(rp + 5);
  175239. *(rp + 5) = save;
  175240. }
  175241. }
  175242. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  175243. {
  175244. png_bytep rp;
  175245. png_uint_32 i;
  175246. for (i = 0, rp = row; i < row_width; i++, rp += 8)
  175247. {
  175248. png_byte save = *rp;
  175249. *rp = *(rp + 4);
  175250. *(rp + 4) = save;
  175251. save = *(rp + 1);
  175252. *(rp + 1) = *(rp + 5);
  175253. *(rp + 5) = save;
  175254. }
  175255. }
  175256. }
  175257. }
  175258. }
  175259. #endif /* PNG_READ_BGR_SUPPORTED or PNG_WRITE_BGR_SUPPORTED */
  175260. #if defined(PNG_READ_USER_TRANSFORM_SUPPORTED) || \
  175261. defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED) || \
  175262. defined(PNG_LEGACY_SUPPORTED)
  175263. void PNGAPI
  175264. png_set_user_transform_info(png_structp png_ptr, png_voidp
  175265. user_transform_ptr, int user_transform_depth, int user_transform_channels)
  175266. {
  175267. png_debug(1, "in png_set_user_transform_info\n");
  175268. if(png_ptr == NULL) return;
  175269. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175270. png_ptr->user_transform_ptr = user_transform_ptr;
  175271. png_ptr->user_transform_depth = (png_byte)user_transform_depth;
  175272. png_ptr->user_transform_channels = (png_byte)user_transform_channels;
  175273. #else
  175274. if(user_transform_ptr || user_transform_depth || user_transform_channels)
  175275. png_warning(png_ptr,
  175276. "This version of libpng does not support user transform info");
  175277. #endif
  175278. }
  175279. #endif
  175280. png_voidp PNGAPI
  175281. png_get_user_transform_ptr(png_structp png_ptr)
  175282. {
  175283. #if defined(PNG_USER_TRANSFORM_PTR_SUPPORTED)
  175284. if (png_ptr == NULL) return (NULL);
  175285. return ((png_voidp)png_ptr->user_transform_ptr);
  175286. #else
  175287. return (NULL);
  175288. #endif
  175289. }
  175290. #endif /* PNG_READ_SUPPORTED || PNG_WRITE_SUPPORTED */
  175291. /*** End of inlined file: pngtrans.c ***/
  175292. /*** Start of inlined file: pngwio.c ***/
  175293. #define PNG_INTERNAL
  175294. #ifdef PNG_WRITE_SUPPORTED
  175295. void /* PRIVATE */
  175296. png_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175297. {
  175298. if (png_ptr->write_data_fn != NULL )
  175299. (*(png_ptr->write_data_fn))(png_ptr, data, length);
  175300. else
  175301. png_error(png_ptr, "Call to NULL write function");
  175302. }
  175303. #if !defined(PNG_NO_STDIO)
  175304. #ifndef USE_FAR_KEYWORD
  175305. void PNGAPI
  175306. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175307. {
  175308. png_uint_32 check;
  175309. if(png_ptr == NULL) return;
  175310. #if defined(_WIN32_WCE)
  175311. if ( !WriteFile((HANDLE)(png_ptr->io_ptr), data, length, &check, NULL) )
  175312. check = 0;
  175313. #else
  175314. check = fwrite(data, 1, length, (png_FILE_p)(png_ptr->io_ptr));
  175315. #endif
  175316. if (check != length)
  175317. png_error(png_ptr, "Write Error");
  175318. }
  175319. #else
  175320. #define NEAR_BUF_SIZE 1024
  175321. #define MIN(a,b) (a <= b ? a : b)
  175322. void PNGAPI
  175323. png_default_write_data(png_structp png_ptr, png_bytep data, png_size_t length)
  175324. {
  175325. png_uint_32 check;
  175326. png_byte *near_data; /* Needs to be "png_byte *" instead of "png_bytep" */
  175327. png_FILE_p io_ptr;
  175328. if(png_ptr == NULL) return;
  175329. near_data = (png_byte *)CVT_PTR_NOCHECK(data);
  175330. io_ptr = (png_FILE_p)CVT_PTR(png_ptr->io_ptr);
  175331. if ((png_bytep)near_data == data)
  175332. {
  175333. #if defined(_WIN32_WCE)
  175334. if ( !WriteFile(io_ptr, near_data, length, &check, NULL) )
  175335. check = 0;
  175336. #else
  175337. check = fwrite(near_data, 1, length, io_ptr);
  175338. #endif
  175339. }
  175340. else
  175341. {
  175342. png_byte buf[NEAR_BUF_SIZE];
  175343. png_size_t written, remaining, err;
  175344. check = 0;
  175345. remaining = length;
  175346. do
  175347. {
  175348. written = MIN(NEAR_BUF_SIZE, remaining);
  175349. png_memcpy(buf, data, written); /* copy far buffer to near buffer */
  175350. #if defined(_WIN32_WCE)
  175351. if ( !WriteFile(io_ptr, buf, written, &err, NULL) )
  175352. err = 0;
  175353. #else
  175354. err = fwrite(buf, 1, written, io_ptr);
  175355. #endif
  175356. if (err != written)
  175357. break;
  175358. else
  175359. check += err;
  175360. data += written;
  175361. remaining -= written;
  175362. }
  175363. while (remaining != 0);
  175364. }
  175365. if (check != length)
  175366. png_error(png_ptr, "Write Error");
  175367. }
  175368. #endif
  175369. #endif
  175370. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175371. void /* PRIVATE */
  175372. png_flush(png_structp png_ptr)
  175373. {
  175374. if (png_ptr->output_flush_fn != NULL)
  175375. (*(png_ptr->output_flush_fn))(png_ptr);
  175376. }
  175377. #if !defined(PNG_NO_STDIO)
  175378. void PNGAPI
  175379. png_default_flush(png_structp png_ptr)
  175380. {
  175381. #if !defined(_WIN32_WCE)
  175382. png_FILE_p io_ptr;
  175383. #endif
  175384. if(png_ptr == NULL) return;
  175385. #if !defined(_WIN32_WCE)
  175386. io_ptr = (png_FILE_p)CVT_PTR((png_ptr->io_ptr));
  175387. if (io_ptr != NULL)
  175388. fflush(io_ptr);
  175389. #endif
  175390. }
  175391. #endif
  175392. #endif
  175393. void PNGAPI
  175394. png_set_write_fn(png_structp png_ptr, png_voidp io_ptr,
  175395. png_rw_ptr write_data_fn, png_flush_ptr output_flush_fn)
  175396. {
  175397. if(png_ptr == NULL) return;
  175398. png_ptr->io_ptr = io_ptr;
  175399. #if !defined(PNG_NO_STDIO)
  175400. if (write_data_fn != NULL)
  175401. png_ptr->write_data_fn = write_data_fn;
  175402. else
  175403. png_ptr->write_data_fn = png_default_write_data;
  175404. #else
  175405. png_ptr->write_data_fn = write_data_fn;
  175406. #endif
  175407. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  175408. #if !defined(PNG_NO_STDIO)
  175409. if (output_flush_fn != NULL)
  175410. png_ptr->output_flush_fn = output_flush_fn;
  175411. else
  175412. png_ptr->output_flush_fn = png_default_flush;
  175413. #else
  175414. png_ptr->output_flush_fn = output_flush_fn;
  175415. #endif
  175416. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  175417. if (png_ptr->read_data_fn != NULL)
  175418. {
  175419. png_ptr->read_data_fn = NULL;
  175420. png_warning(png_ptr,
  175421. "Attempted to set both read_data_fn and write_data_fn in");
  175422. png_warning(png_ptr,
  175423. "the same structure. Resetting read_data_fn to NULL.");
  175424. }
  175425. }
  175426. #if defined(USE_FAR_KEYWORD)
  175427. #if defined(_MSC_VER)
  175428. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175429. {
  175430. void *near_ptr;
  175431. void FAR *far_ptr;
  175432. FP_OFF(near_ptr) = FP_OFF(ptr);
  175433. far_ptr = (void FAR *)near_ptr;
  175434. if(check != 0)
  175435. if(FP_SEG(ptr) != FP_SEG(far_ptr))
  175436. png_error(png_ptr,"segment lost in conversion");
  175437. return(near_ptr);
  175438. }
  175439. # else
  175440. void *png_far_to_near(png_structp png_ptr,png_voidp ptr, int check)
  175441. {
  175442. void *near_ptr;
  175443. void FAR *far_ptr;
  175444. near_ptr = (void FAR *)ptr;
  175445. far_ptr = (void FAR *)near_ptr;
  175446. if(check != 0)
  175447. if(far_ptr != ptr)
  175448. png_error(png_ptr,"segment lost in conversion");
  175449. return(near_ptr);
  175450. }
  175451. # endif
  175452. # endif
  175453. #endif /* PNG_WRITE_SUPPORTED */
  175454. /*** End of inlined file: pngwio.c ***/
  175455. /*** Start of inlined file: pngwrite.c ***/
  175456. #define PNG_INTERNAL
  175457. #ifdef PNG_WRITE_SUPPORTED
  175458. void PNGAPI
  175459. png_write_info_before_PLTE(png_structp png_ptr, png_infop info_ptr)
  175460. {
  175461. png_debug(1, "in png_write_info_before_PLTE\n");
  175462. if (png_ptr == NULL || info_ptr == NULL)
  175463. return;
  175464. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  175465. {
  175466. png_write_sig(png_ptr); /* write PNG signature */
  175467. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  175468. if((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE)&&(png_ptr->mng_features_permitted))
  175469. {
  175470. png_warning(png_ptr,"MNG features are not allowed in a PNG datastream");
  175471. png_ptr->mng_features_permitted=0;
  175472. }
  175473. #endif
  175474. png_write_IHDR(png_ptr, info_ptr->width, info_ptr->height,
  175475. info_ptr->bit_depth, info_ptr->color_type, info_ptr->compression_type,
  175476. info_ptr->filter_type,
  175477. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  175478. info_ptr->interlace_type);
  175479. #else
  175480. 0);
  175481. #endif
  175482. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  175483. if (info_ptr->valid & PNG_INFO_gAMA)
  175484. {
  175485. # ifdef PNG_FLOATING_POINT_SUPPORTED
  175486. png_write_gAMA(png_ptr, info_ptr->gamma);
  175487. #else
  175488. #ifdef PNG_FIXED_POINT_SUPPORTED
  175489. png_write_gAMA_fixed(png_ptr, info_ptr->int_gamma);
  175490. # endif
  175491. #endif
  175492. }
  175493. #endif
  175494. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  175495. if (info_ptr->valid & PNG_INFO_sRGB)
  175496. png_write_sRGB(png_ptr, (int)info_ptr->srgb_intent);
  175497. #endif
  175498. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  175499. if (info_ptr->valid & PNG_INFO_iCCP)
  175500. png_write_iCCP(png_ptr, info_ptr->iccp_name, PNG_COMPRESSION_TYPE_BASE,
  175501. info_ptr->iccp_profile, (int)info_ptr->iccp_proflen);
  175502. #endif
  175503. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  175504. if (info_ptr->valid & PNG_INFO_sBIT)
  175505. png_write_sBIT(png_ptr, &(info_ptr->sig_bit), info_ptr->color_type);
  175506. #endif
  175507. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  175508. if (info_ptr->valid & PNG_INFO_cHRM)
  175509. {
  175510. #ifdef PNG_FLOATING_POINT_SUPPORTED
  175511. png_write_cHRM(png_ptr,
  175512. info_ptr->x_white, info_ptr->y_white,
  175513. info_ptr->x_red, info_ptr->y_red,
  175514. info_ptr->x_green, info_ptr->y_green,
  175515. info_ptr->x_blue, info_ptr->y_blue);
  175516. #else
  175517. # ifdef PNG_FIXED_POINT_SUPPORTED
  175518. png_write_cHRM_fixed(png_ptr,
  175519. info_ptr->int_x_white, info_ptr->int_y_white,
  175520. info_ptr->int_x_red, info_ptr->int_y_red,
  175521. info_ptr->int_x_green, info_ptr->int_y_green,
  175522. info_ptr->int_x_blue, info_ptr->int_y_blue);
  175523. # endif
  175524. #endif
  175525. }
  175526. #endif
  175527. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175528. if (info_ptr->unknown_chunks_num)
  175529. {
  175530. png_unknown_chunk *up;
  175531. png_debug(5, "writing extra chunks\n");
  175532. for (up = info_ptr->unknown_chunks;
  175533. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175534. up++)
  175535. {
  175536. int keep=png_handle_as_unknown(png_ptr, up->name);
  175537. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175538. up->location && !(up->location & PNG_HAVE_PLTE) &&
  175539. !(up->location & PNG_HAVE_IDAT) &&
  175540. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175541. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175542. {
  175543. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175544. }
  175545. }
  175546. }
  175547. #endif
  175548. png_ptr->mode |= PNG_WROTE_INFO_BEFORE_PLTE;
  175549. }
  175550. }
  175551. void PNGAPI
  175552. png_write_info(png_structp png_ptr, png_infop info_ptr)
  175553. {
  175554. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  175555. int i;
  175556. #endif
  175557. png_debug(1, "in png_write_info\n");
  175558. if (png_ptr == NULL || info_ptr == NULL)
  175559. return;
  175560. png_write_info_before_PLTE(png_ptr, info_ptr);
  175561. if (info_ptr->valid & PNG_INFO_PLTE)
  175562. png_write_PLTE(png_ptr, info_ptr->palette,
  175563. (png_uint_32)info_ptr->num_palette);
  175564. else if (info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175565. png_error(png_ptr, "Valid palette required for paletted images");
  175566. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  175567. if (info_ptr->valid & PNG_INFO_tRNS)
  175568. {
  175569. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  175570. if ((png_ptr->transformations & PNG_INVERT_ALPHA) &&
  175571. info_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  175572. {
  175573. int j;
  175574. for (j=0; j<(int)info_ptr->num_trans; j++)
  175575. info_ptr->trans[j] = (png_byte)(255 - info_ptr->trans[j]);
  175576. }
  175577. #endif
  175578. png_write_tRNS(png_ptr, info_ptr->trans, &(info_ptr->trans_values),
  175579. info_ptr->num_trans, info_ptr->color_type);
  175580. }
  175581. #endif
  175582. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  175583. if (info_ptr->valid & PNG_INFO_bKGD)
  175584. png_write_bKGD(png_ptr, &(info_ptr->background), info_ptr->color_type);
  175585. #endif
  175586. #if defined(PNG_WRITE_hIST_SUPPORTED)
  175587. if (info_ptr->valid & PNG_INFO_hIST)
  175588. png_write_hIST(png_ptr, info_ptr->hist, info_ptr->num_palette);
  175589. #endif
  175590. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  175591. if (info_ptr->valid & PNG_INFO_oFFs)
  175592. png_write_oFFs(png_ptr, info_ptr->x_offset, info_ptr->y_offset,
  175593. info_ptr->offset_unit_type);
  175594. #endif
  175595. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  175596. if (info_ptr->valid & PNG_INFO_pCAL)
  175597. png_write_pCAL(png_ptr, info_ptr->pcal_purpose, info_ptr->pcal_X0,
  175598. info_ptr->pcal_X1, info_ptr->pcal_type, info_ptr->pcal_nparams,
  175599. info_ptr->pcal_units, info_ptr->pcal_params);
  175600. #endif
  175601. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  175602. if (info_ptr->valid & PNG_INFO_sCAL)
  175603. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  175604. png_write_sCAL(png_ptr, (int)info_ptr->scal_unit,
  175605. info_ptr->scal_pixel_width, info_ptr->scal_pixel_height);
  175606. #else
  175607. #ifdef PNG_FIXED_POINT_SUPPORTED
  175608. png_write_sCAL_s(png_ptr, (int)info_ptr->scal_unit,
  175609. info_ptr->scal_s_width, info_ptr->scal_s_height);
  175610. #else
  175611. png_warning(png_ptr,
  175612. "png_write_sCAL not supported; sCAL chunk not written.");
  175613. #endif
  175614. #endif
  175615. #endif
  175616. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  175617. if (info_ptr->valid & PNG_INFO_pHYs)
  175618. png_write_pHYs(png_ptr, info_ptr->x_pixels_per_unit,
  175619. info_ptr->y_pixels_per_unit, info_ptr->phys_unit_type);
  175620. #endif
  175621. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175622. if (info_ptr->valid & PNG_INFO_tIME)
  175623. {
  175624. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175625. png_ptr->mode |= PNG_WROTE_tIME;
  175626. }
  175627. #endif
  175628. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  175629. if (info_ptr->valid & PNG_INFO_sPLT)
  175630. for (i = 0; i < (int)info_ptr->splt_palettes_num; i++)
  175631. png_write_sPLT(png_ptr, info_ptr->splt_palettes + i);
  175632. #endif
  175633. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175634. for (i = 0; i < info_ptr->num_text; i++)
  175635. {
  175636. png_debug2(2, "Writing header text chunk %d, type %d\n", i,
  175637. info_ptr->text[i].compression);
  175638. if (info_ptr->text[i].compression > 0)
  175639. {
  175640. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175641. png_write_iTXt(png_ptr,
  175642. info_ptr->text[i].compression,
  175643. info_ptr->text[i].key,
  175644. info_ptr->text[i].lang,
  175645. info_ptr->text[i].lang_key,
  175646. info_ptr->text[i].text);
  175647. #else
  175648. png_warning(png_ptr, "Unable to write international text");
  175649. #endif
  175650. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175651. }
  175652. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_zTXt)
  175653. {
  175654. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175655. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175656. info_ptr->text[i].text, 0,
  175657. info_ptr->text[i].compression);
  175658. #else
  175659. png_warning(png_ptr, "Unable to write compressed text");
  175660. #endif
  175661. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175662. }
  175663. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175664. {
  175665. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175666. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175667. info_ptr->text[i].text,
  175668. 0);
  175669. #else
  175670. png_warning(png_ptr, "Unable to write uncompressed text");
  175671. #endif
  175672. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175673. }
  175674. }
  175675. #endif
  175676. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175677. if (info_ptr->unknown_chunks_num)
  175678. {
  175679. png_unknown_chunk *up;
  175680. png_debug(5, "writing extra chunks\n");
  175681. for (up = info_ptr->unknown_chunks;
  175682. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175683. up++)
  175684. {
  175685. int keep=png_handle_as_unknown(png_ptr, up->name);
  175686. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175687. up->location && (up->location & PNG_HAVE_PLTE) &&
  175688. !(up->location & PNG_HAVE_IDAT) &&
  175689. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175690. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175691. {
  175692. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175693. }
  175694. }
  175695. }
  175696. #endif
  175697. }
  175698. void PNGAPI
  175699. png_write_end(png_structp png_ptr, png_infop info_ptr)
  175700. {
  175701. png_debug(1, "in png_write_end\n");
  175702. if (png_ptr == NULL)
  175703. return;
  175704. if (!(png_ptr->mode & PNG_HAVE_IDAT))
  175705. png_error(png_ptr, "No IDATs written into file");
  175706. if (info_ptr != NULL)
  175707. {
  175708. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175709. int i; /* local index variable */
  175710. #endif
  175711. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175712. if ((info_ptr->valid & PNG_INFO_tIME) &&
  175713. !(png_ptr->mode & PNG_WROTE_tIME))
  175714. png_write_tIME(png_ptr, &(info_ptr->mod_time));
  175715. #endif
  175716. #if defined(PNG_WRITE_TEXT_SUPPORTED)
  175717. for (i = 0; i < info_ptr->num_text; i++)
  175718. {
  175719. png_debug2(2, "Writing trailer text chunk %d, type %d\n", i,
  175720. info_ptr->text[i].compression);
  175721. if (info_ptr->text[i].compression > 0)
  175722. {
  175723. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  175724. png_write_iTXt(png_ptr,
  175725. info_ptr->text[i].compression,
  175726. info_ptr->text[i].key,
  175727. info_ptr->text[i].lang,
  175728. info_ptr->text[i].lang_key,
  175729. info_ptr->text[i].text);
  175730. #else
  175731. png_warning(png_ptr, "Unable to write international text");
  175732. #endif
  175733. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175734. }
  175735. else if (info_ptr->text[i].compression >= PNG_TEXT_COMPRESSION_zTXt)
  175736. {
  175737. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  175738. png_write_zTXt(png_ptr, info_ptr->text[i].key,
  175739. info_ptr->text[i].text, 0,
  175740. info_ptr->text[i].compression);
  175741. #else
  175742. png_warning(png_ptr, "Unable to write compressed text");
  175743. #endif
  175744. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_zTXt_WR;
  175745. }
  175746. else if (info_ptr->text[i].compression == PNG_TEXT_COMPRESSION_NONE)
  175747. {
  175748. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  175749. png_write_tEXt(png_ptr, info_ptr->text[i].key,
  175750. info_ptr->text[i].text, 0);
  175751. #else
  175752. png_warning(png_ptr, "Unable to write uncompressed text");
  175753. #endif
  175754. info_ptr->text[i].compression = PNG_TEXT_COMPRESSION_NONE_WR;
  175755. }
  175756. }
  175757. #endif
  175758. #if defined(PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED)
  175759. if (info_ptr->unknown_chunks_num)
  175760. {
  175761. png_unknown_chunk *up;
  175762. png_debug(5, "writing extra chunks\n");
  175763. for (up = info_ptr->unknown_chunks;
  175764. up < info_ptr->unknown_chunks + info_ptr->unknown_chunks_num;
  175765. up++)
  175766. {
  175767. int keep=png_handle_as_unknown(png_ptr, up->name);
  175768. if (keep != PNG_HANDLE_CHUNK_NEVER &&
  175769. up->location && (up->location & PNG_AFTER_IDAT) &&
  175770. ((up->name[3] & 0x20) || keep == PNG_HANDLE_CHUNK_ALWAYS ||
  175771. (png_ptr->flags & PNG_FLAG_KEEP_UNSAFE_CHUNKS)))
  175772. {
  175773. png_write_chunk(png_ptr, up->name, up->data, up->size);
  175774. }
  175775. }
  175776. }
  175777. #endif
  175778. }
  175779. png_ptr->mode |= PNG_AFTER_IDAT;
  175780. png_write_IEND(png_ptr);
  175781. }
  175782. #if defined(PNG_WRITE_tIME_SUPPORTED)
  175783. #if !defined(_WIN32_WCE)
  175784. void PNGAPI
  175785. png_convert_from_struct_tm(png_timep ptime, struct tm FAR * ttime)
  175786. {
  175787. png_debug(1, "in png_convert_from_struct_tm\n");
  175788. ptime->year = (png_uint_16)(1900 + ttime->tm_year);
  175789. ptime->month = (png_byte)(ttime->tm_mon + 1);
  175790. ptime->day = (png_byte)ttime->tm_mday;
  175791. ptime->hour = (png_byte)ttime->tm_hour;
  175792. ptime->minute = (png_byte)ttime->tm_min;
  175793. ptime->second = (png_byte)ttime->tm_sec;
  175794. }
  175795. void PNGAPI
  175796. png_convert_from_time_t(png_timep ptime, time_t ttime)
  175797. {
  175798. struct tm *tbuf;
  175799. png_debug(1, "in png_convert_from_time_t\n");
  175800. tbuf = gmtime(&ttime);
  175801. png_convert_from_struct_tm(ptime, tbuf);
  175802. }
  175803. #endif
  175804. #endif
  175805. png_structp PNGAPI
  175806. png_create_write_struct(png_const_charp user_png_ver, png_voidp error_ptr,
  175807. png_error_ptr error_fn, png_error_ptr warn_fn)
  175808. {
  175809. #ifdef PNG_USER_MEM_SUPPORTED
  175810. return (png_create_write_struct_2(user_png_ver, error_ptr, error_fn,
  175811. warn_fn, png_voidp_NULL, png_malloc_ptr_NULL, png_free_ptr_NULL));
  175812. }
  175813. png_structp PNGAPI
  175814. png_create_write_struct_2(png_const_charp user_png_ver, png_voidp error_ptr,
  175815. png_error_ptr error_fn, png_error_ptr warn_fn, png_voidp mem_ptr,
  175816. png_malloc_ptr malloc_fn, png_free_ptr free_fn)
  175817. {
  175818. #endif /* PNG_USER_MEM_SUPPORTED */
  175819. png_structp png_ptr;
  175820. #ifdef PNG_SETJMP_SUPPORTED
  175821. #ifdef USE_FAR_KEYWORD
  175822. jmp_buf jmpbuf;
  175823. #endif
  175824. #endif
  175825. int i;
  175826. png_debug(1, "in png_create_write_struct\n");
  175827. #ifdef PNG_USER_MEM_SUPPORTED
  175828. png_ptr = (png_structp)png_create_struct_2(PNG_STRUCT_PNG,
  175829. (png_malloc_ptr)malloc_fn, (png_voidp)mem_ptr);
  175830. #else
  175831. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175832. #endif /* PNG_USER_MEM_SUPPORTED */
  175833. if (png_ptr == NULL)
  175834. return (NULL);
  175835. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  175836. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  175837. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  175838. #endif
  175839. #ifdef PNG_SETJMP_SUPPORTED
  175840. #ifdef USE_FAR_KEYWORD
  175841. if (setjmp(jmpbuf))
  175842. #else
  175843. if (setjmp(png_ptr->jmpbuf))
  175844. #endif
  175845. {
  175846. png_free(png_ptr, png_ptr->zbuf);
  175847. png_ptr->zbuf=NULL;
  175848. png_destroy_struct(png_ptr);
  175849. return (NULL);
  175850. }
  175851. #ifdef USE_FAR_KEYWORD
  175852. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175853. #endif
  175854. #endif
  175855. #ifdef PNG_USER_MEM_SUPPORTED
  175856. png_set_mem_fn(png_ptr, mem_ptr, malloc_fn, free_fn);
  175857. #endif /* PNG_USER_MEM_SUPPORTED */
  175858. png_set_error_fn(png_ptr, error_ptr, error_fn, warn_fn);
  175859. i=0;
  175860. do
  175861. {
  175862. if(user_png_ver[i] != png_libpng_ver[i])
  175863. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175864. } while (png_libpng_ver[i++]);
  175865. if (png_ptr->flags & PNG_FLAG_LIBRARY_MISMATCH)
  175866. {
  175867. if (user_png_ver == NULL || user_png_ver[0] != png_libpng_ver[0] ||
  175868. (user_png_ver[0] == '1' && user_png_ver[2] != png_libpng_ver[2]) ||
  175869. (user_png_ver[0] == '0' && user_png_ver[2] < '9'))
  175870. {
  175871. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175872. char msg[80];
  175873. if (user_png_ver)
  175874. {
  175875. png_snprintf(msg, 80,
  175876. "Application was compiled with png.h from libpng-%.20s",
  175877. user_png_ver);
  175878. png_warning(png_ptr, msg);
  175879. }
  175880. png_snprintf(msg, 80,
  175881. "Application is running with png.c from libpng-%.20s",
  175882. png_libpng_ver);
  175883. png_warning(png_ptr, msg);
  175884. #endif
  175885. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175886. png_ptr->flags=0;
  175887. #endif
  175888. png_error(png_ptr,
  175889. "Incompatible libpng version in application and library");
  175890. }
  175891. }
  175892. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  175893. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  175894. (png_uint_32)png_ptr->zbuf_size);
  175895. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  175896. png_flush_ptr_NULL);
  175897. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  175898. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  175899. 1, png_doublep_NULL, png_doublep_NULL);
  175900. #endif
  175901. #ifdef PNG_SETJMP_SUPPORTED
  175902. #ifdef USE_FAR_KEYWORD
  175903. if (setjmp(jmpbuf))
  175904. PNG_ABORT();
  175905. png_memcpy(png_ptr->jmpbuf,jmpbuf,png_sizeof(jmp_buf));
  175906. #else
  175907. if (setjmp(png_ptr->jmpbuf))
  175908. PNG_ABORT();
  175909. #endif
  175910. #endif
  175911. return (png_ptr);
  175912. }
  175913. #if defined(PNG_1_0_X) || defined(PNG_1_2_X)
  175914. #undef png_write_init
  175915. void PNGAPI
  175916. png_write_init(png_structp png_ptr)
  175917. {
  175918. png_write_init_2(png_ptr, "1.0.6 or earlier", 0, 0);
  175919. }
  175920. void PNGAPI
  175921. png_write_init_2(png_structp png_ptr, png_const_charp user_png_ver,
  175922. png_size_t png_struct_size, png_size_t png_info_size)
  175923. {
  175924. if(png_ptr == NULL) return;
  175925. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  175926. if(png_sizeof(png_struct) > png_struct_size ||
  175927. png_sizeof(png_info) > png_info_size)
  175928. {
  175929. char msg[80];
  175930. png_ptr->warning_fn=NULL;
  175931. if (user_png_ver)
  175932. {
  175933. png_snprintf(msg, 80,
  175934. "Application was compiled with png.h from libpng-%.20s",
  175935. user_png_ver);
  175936. png_warning(png_ptr, msg);
  175937. }
  175938. png_snprintf(msg, 80,
  175939. "Application is running with png.c from libpng-%.20s",
  175940. png_libpng_ver);
  175941. png_warning(png_ptr, msg);
  175942. }
  175943. #endif
  175944. if(png_sizeof(png_struct) > png_struct_size)
  175945. {
  175946. png_ptr->error_fn=NULL;
  175947. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175948. png_ptr->flags=0;
  175949. #endif
  175950. png_error(png_ptr,
  175951. "The png struct allocated by the application for writing is too small.");
  175952. }
  175953. if(png_sizeof(png_info) > png_info_size)
  175954. {
  175955. png_ptr->error_fn=NULL;
  175956. #ifdef PNG_ERROR_NUMBERS_SUPPORTED
  175957. png_ptr->flags=0;
  175958. #endif
  175959. png_error(png_ptr,
  175960. "The info struct allocated by the application for writing is too small.");
  175961. }
  175962. png_write_init_3(&png_ptr, user_png_ver, png_struct_size);
  175963. }
  175964. #endif /* PNG_1_0_X || PNG_1_2_X */
  175965. void PNGAPI
  175966. png_write_init_3(png_structpp ptr_ptr, png_const_charp user_png_ver,
  175967. png_size_t png_struct_size)
  175968. {
  175969. png_structp png_ptr=*ptr_ptr;
  175970. #ifdef PNG_SETJMP_SUPPORTED
  175971. jmp_buf tmp_jmp; /* to save current jump buffer */
  175972. #endif
  175973. int i = 0;
  175974. if (png_ptr == NULL)
  175975. return;
  175976. do
  175977. {
  175978. if (user_png_ver[i] != png_libpng_ver[i])
  175979. {
  175980. #ifdef PNG_LEGACY_SUPPORTED
  175981. png_ptr->flags |= PNG_FLAG_LIBRARY_MISMATCH;
  175982. #else
  175983. png_ptr->warning_fn=NULL;
  175984. png_warning(png_ptr,
  175985. "Application uses deprecated png_write_init() and should be recompiled.");
  175986. break;
  175987. #endif
  175988. }
  175989. } while (png_libpng_ver[i++]);
  175990. png_debug(1, "in png_write_init_3\n");
  175991. #ifdef PNG_SETJMP_SUPPORTED
  175992. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  175993. #endif
  175994. if (png_sizeof(png_struct) > png_struct_size)
  175995. {
  175996. png_destroy_struct(png_ptr);
  175997. png_ptr = (png_structp)png_create_struct(PNG_STRUCT_PNG);
  175998. *ptr_ptr = png_ptr;
  175999. }
  176000. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176001. #ifdef PNG_SET_USER_LIMITS_SUPPORTED
  176002. png_ptr->user_width_max=PNG_USER_WIDTH_MAX;
  176003. png_ptr->user_height_max=PNG_USER_HEIGHT_MAX;
  176004. #endif
  176005. #ifdef PNG_SETJMP_SUPPORTED
  176006. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176007. #endif
  176008. png_set_write_fn(png_ptr, png_voidp_NULL, png_rw_ptr_NULL,
  176009. png_flush_ptr_NULL);
  176010. png_ptr->zbuf_size = PNG_ZBUF_SIZE;
  176011. png_ptr->zbuf = (png_bytep)png_malloc(png_ptr,
  176012. (png_uint_32)png_ptr->zbuf_size);
  176013. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176014. png_set_filter_heuristics(png_ptr, PNG_FILTER_HEURISTIC_DEFAULT,
  176015. 1, png_doublep_NULL, png_doublep_NULL);
  176016. #endif
  176017. }
  176018. void PNGAPI
  176019. png_write_rows(png_structp png_ptr, png_bytepp row,
  176020. png_uint_32 num_rows)
  176021. {
  176022. png_uint_32 i; /* row counter */
  176023. png_bytepp rp; /* row pointer */
  176024. png_debug(1, "in png_write_rows\n");
  176025. if (png_ptr == NULL)
  176026. return;
  176027. for (i = 0, rp = row; i < num_rows; i++, rp++)
  176028. {
  176029. png_write_row(png_ptr, *rp);
  176030. }
  176031. }
  176032. void PNGAPI
  176033. png_write_image(png_structp png_ptr, png_bytepp image)
  176034. {
  176035. png_uint_32 i; /* row index */
  176036. int pass, num_pass; /* pass variables */
  176037. png_bytepp rp; /* points to current row */
  176038. if (png_ptr == NULL)
  176039. return;
  176040. png_debug(1, "in png_write_image\n");
  176041. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176042. num_pass = png_set_interlace_handling(png_ptr);
  176043. #else
  176044. num_pass = 1;
  176045. #endif
  176046. for (pass = 0; pass < num_pass; pass++)
  176047. {
  176048. for (i = 0, rp = image; i < png_ptr->height; i++, rp++)
  176049. {
  176050. png_write_row(png_ptr, *rp);
  176051. }
  176052. }
  176053. }
  176054. void PNGAPI
  176055. png_write_row(png_structp png_ptr, png_bytep row)
  176056. {
  176057. if (png_ptr == NULL)
  176058. return;
  176059. png_debug2(1, "in png_write_row (row %ld, pass %d)\n",
  176060. png_ptr->row_number, png_ptr->pass);
  176061. if (png_ptr->row_number == 0 && png_ptr->pass == 0)
  176062. {
  176063. if (!(png_ptr->mode & PNG_WROTE_INFO_BEFORE_PLTE))
  176064. png_error(png_ptr,
  176065. "png_write_info was never called before png_write_row.");
  176066. #if !defined(PNG_WRITE_INVERT_SUPPORTED) && defined(PNG_READ_INVERT_SUPPORTED)
  176067. if (png_ptr->transformations & PNG_INVERT_MONO)
  176068. png_warning(png_ptr, "PNG_WRITE_INVERT_SUPPORTED is not defined.");
  176069. #endif
  176070. #if !defined(PNG_WRITE_FILLER_SUPPORTED) && defined(PNG_READ_FILLER_SUPPORTED)
  176071. if (png_ptr->transformations & PNG_FILLER)
  176072. png_warning(png_ptr, "PNG_WRITE_FILLER_SUPPORTED is not defined.");
  176073. #endif
  176074. #if !defined(PNG_WRITE_PACKSWAP_SUPPORTED) && defined(PNG_READ_PACKSWAP_SUPPORTED)
  176075. if (png_ptr->transformations & PNG_PACKSWAP)
  176076. png_warning(png_ptr, "PNG_WRITE_PACKSWAP_SUPPORTED is not defined.");
  176077. #endif
  176078. #if !defined(PNG_WRITE_PACK_SUPPORTED) && defined(PNG_READ_PACK_SUPPORTED)
  176079. if (png_ptr->transformations & PNG_PACK)
  176080. png_warning(png_ptr, "PNG_WRITE_PACK_SUPPORTED is not defined.");
  176081. #endif
  176082. #if !defined(PNG_WRITE_SHIFT_SUPPORTED) && defined(PNG_READ_SHIFT_SUPPORTED)
  176083. if (png_ptr->transformations & PNG_SHIFT)
  176084. png_warning(png_ptr, "PNG_WRITE_SHIFT_SUPPORTED is not defined.");
  176085. #endif
  176086. #if !defined(PNG_WRITE_BGR_SUPPORTED) && defined(PNG_READ_BGR_SUPPORTED)
  176087. if (png_ptr->transformations & PNG_BGR)
  176088. png_warning(png_ptr, "PNG_WRITE_BGR_SUPPORTED is not defined.");
  176089. #endif
  176090. #if !defined(PNG_WRITE_SWAP_SUPPORTED) && defined(PNG_READ_SWAP_SUPPORTED)
  176091. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176092. png_warning(png_ptr, "PNG_WRITE_SWAP_SUPPORTED is not defined.");
  176093. #endif
  176094. png_write_start_row(png_ptr);
  176095. }
  176096. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176097. if (png_ptr->interlaced && (png_ptr->transformations & PNG_INTERLACE))
  176098. {
  176099. switch (png_ptr->pass)
  176100. {
  176101. case 0:
  176102. if (png_ptr->row_number & 0x07)
  176103. {
  176104. png_write_finish_row(png_ptr);
  176105. return;
  176106. }
  176107. break;
  176108. case 1:
  176109. if ((png_ptr->row_number & 0x07) || png_ptr->width < 5)
  176110. {
  176111. png_write_finish_row(png_ptr);
  176112. return;
  176113. }
  176114. break;
  176115. case 2:
  176116. if ((png_ptr->row_number & 0x07) != 4)
  176117. {
  176118. png_write_finish_row(png_ptr);
  176119. return;
  176120. }
  176121. break;
  176122. case 3:
  176123. if ((png_ptr->row_number & 0x03) || png_ptr->width < 3)
  176124. {
  176125. png_write_finish_row(png_ptr);
  176126. return;
  176127. }
  176128. break;
  176129. case 4:
  176130. if ((png_ptr->row_number & 0x03) != 2)
  176131. {
  176132. png_write_finish_row(png_ptr);
  176133. return;
  176134. }
  176135. break;
  176136. case 5:
  176137. if ((png_ptr->row_number & 0x01) || png_ptr->width < 2)
  176138. {
  176139. png_write_finish_row(png_ptr);
  176140. return;
  176141. }
  176142. break;
  176143. case 6:
  176144. if (!(png_ptr->row_number & 0x01))
  176145. {
  176146. png_write_finish_row(png_ptr);
  176147. return;
  176148. }
  176149. break;
  176150. }
  176151. }
  176152. #endif
  176153. png_ptr->row_info.color_type = png_ptr->color_type;
  176154. png_ptr->row_info.width = png_ptr->usr_width;
  176155. png_ptr->row_info.channels = png_ptr->usr_channels;
  176156. png_ptr->row_info.bit_depth = png_ptr->usr_bit_depth;
  176157. png_ptr->row_info.pixel_depth = (png_byte)(png_ptr->row_info.bit_depth *
  176158. png_ptr->row_info.channels);
  176159. png_ptr->row_info.rowbytes = PNG_ROWBYTES(png_ptr->row_info.pixel_depth,
  176160. png_ptr->row_info.width);
  176161. png_debug1(3, "row_info->color_type = %d\n", png_ptr->row_info.color_type);
  176162. png_debug1(3, "row_info->width = %lu\n", png_ptr->row_info.width);
  176163. png_debug1(3, "row_info->channels = %d\n", png_ptr->row_info.channels);
  176164. png_debug1(3, "row_info->bit_depth = %d\n", png_ptr->row_info.bit_depth);
  176165. png_debug1(3, "row_info->pixel_depth = %d\n", png_ptr->row_info.pixel_depth);
  176166. png_debug1(3, "row_info->rowbytes = %lu\n", png_ptr->row_info.rowbytes);
  176167. png_memcpy_check(png_ptr, png_ptr->row_buf + 1, row,
  176168. png_ptr->row_info.rowbytes);
  176169. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  176170. if (png_ptr->interlaced && png_ptr->pass < 6 &&
  176171. (png_ptr->transformations & PNG_INTERLACE))
  176172. {
  176173. png_do_write_interlace(&(png_ptr->row_info),
  176174. png_ptr->row_buf + 1, png_ptr->pass);
  176175. if (!(png_ptr->row_info.width))
  176176. {
  176177. png_write_finish_row(png_ptr);
  176178. return;
  176179. }
  176180. }
  176181. #endif
  176182. if (png_ptr->transformations)
  176183. png_do_write_transformations(png_ptr);
  176184. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176185. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176186. (png_ptr->filter_type == PNG_INTRAPIXEL_DIFFERENCING))
  176187. {
  176188. png_do_write_intrapixel(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176189. }
  176190. #endif
  176191. png_write_find_filter(png_ptr, &(png_ptr->row_info));
  176192. if (png_ptr->write_row_fn != NULL)
  176193. (*(png_ptr->write_row_fn))(png_ptr, png_ptr->row_number, png_ptr->pass);
  176194. }
  176195. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  176196. void PNGAPI
  176197. png_set_flush(png_structp png_ptr, int nrows)
  176198. {
  176199. png_debug(1, "in png_set_flush\n");
  176200. if (png_ptr == NULL)
  176201. return;
  176202. png_ptr->flush_dist = (nrows < 0 ? 0 : nrows);
  176203. }
  176204. void PNGAPI
  176205. png_write_flush(png_structp png_ptr)
  176206. {
  176207. int wrote_IDAT;
  176208. png_debug(1, "in png_write_flush\n");
  176209. if (png_ptr == NULL)
  176210. return;
  176211. if (png_ptr->row_number >= png_ptr->num_rows)
  176212. return;
  176213. do
  176214. {
  176215. int ret;
  176216. ret = deflate(&png_ptr->zstream, Z_SYNC_FLUSH);
  176217. wrote_IDAT = 0;
  176218. if (ret != Z_OK)
  176219. {
  176220. if (png_ptr->zstream.msg != NULL)
  176221. png_error(png_ptr, png_ptr->zstream.msg);
  176222. else
  176223. png_error(png_ptr, "zlib error");
  176224. }
  176225. if (!(png_ptr->zstream.avail_out))
  176226. {
  176227. png_write_IDAT(png_ptr, png_ptr->zbuf,
  176228. png_ptr->zbuf_size);
  176229. png_ptr->zstream.next_out = png_ptr->zbuf;
  176230. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176231. wrote_IDAT = 1;
  176232. }
  176233. } while(wrote_IDAT == 1);
  176234. if (png_ptr->zbuf_size != png_ptr->zstream.avail_out)
  176235. {
  176236. png_write_IDAT(png_ptr, png_ptr->zbuf,
  176237. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  176238. png_ptr->zstream.next_out = png_ptr->zbuf;
  176239. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  176240. }
  176241. png_ptr->flush_rows = 0;
  176242. png_flush(png_ptr);
  176243. }
  176244. #endif /* PNG_WRITE_FLUSH_SUPPORTED */
  176245. void PNGAPI
  176246. png_destroy_write_struct(png_structpp png_ptr_ptr, png_infopp info_ptr_ptr)
  176247. {
  176248. png_structp png_ptr = NULL;
  176249. png_infop info_ptr = NULL;
  176250. #ifdef PNG_USER_MEM_SUPPORTED
  176251. png_free_ptr free_fn = NULL;
  176252. png_voidp mem_ptr = NULL;
  176253. #endif
  176254. png_debug(1, "in png_destroy_write_struct\n");
  176255. if (png_ptr_ptr != NULL)
  176256. {
  176257. png_ptr = *png_ptr_ptr;
  176258. #ifdef PNG_USER_MEM_SUPPORTED
  176259. free_fn = png_ptr->free_fn;
  176260. mem_ptr = png_ptr->mem_ptr;
  176261. #endif
  176262. }
  176263. if (info_ptr_ptr != NULL)
  176264. info_ptr = *info_ptr_ptr;
  176265. if (info_ptr != NULL)
  176266. {
  176267. png_free_data(png_ptr, info_ptr, PNG_FREE_ALL, -1);
  176268. #if defined(PNG_UNKNOWN_CHUNKS_SUPPORTED)
  176269. if (png_ptr->num_chunk_list)
  176270. {
  176271. png_free(png_ptr, png_ptr->chunk_list);
  176272. png_ptr->chunk_list=NULL;
  176273. png_ptr->num_chunk_list=0;
  176274. }
  176275. #endif
  176276. #ifdef PNG_USER_MEM_SUPPORTED
  176277. png_destroy_struct_2((png_voidp)info_ptr, (png_free_ptr)free_fn,
  176278. (png_voidp)mem_ptr);
  176279. #else
  176280. png_destroy_struct((png_voidp)info_ptr);
  176281. #endif
  176282. *info_ptr_ptr = NULL;
  176283. }
  176284. if (png_ptr != NULL)
  176285. {
  176286. png_write_destroy(png_ptr);
  176287. #ifdef PNG_USER_MEM_SUPPORTED
  176288. png_destroy_struct_2((png_voidp)png_ptr, (png_free_ptr)free_fn,
  176289. (png_voidp)mem_ptr);
  176290. #else
  176291. png_destroy_struct((png_voidp)png_ptr);
  176292. #endif
  176293. *png_ptr_ptr = NULL;
  176294. }
  176295. }
  176296. void /* PRIVATE */
  176297. png_write_destroy(png_structp png_ptr)
  176298. {
  176299. #ifdef PNG_SETJMP_SUPPORTED
  176300. jmp_buf tmp_jmp; /* save jump buffer */
  176301. #endif
  176302. png_error_ptr error_fn;
  176303. png_error_ptr warning_fn;
  176304. png_voidp error_ptr;
  176305. #ifdef PNG_USER_MEM_SUPPORTED
  176306. png_free_ptr free_fn;
  176307. #endif
  176308. png_debug(1, "in png_write_destroy\n");
  176309. deflateEnd(&png_ptr->zstream);
  176310. png_free(png_ptr, png_ptr->zbuf);
  176311. png_free(png_ptr, png_ptr->row_buf);
  176312. png_free(png_ptr, png_ptr->prev_row);
  176313. png_free(png_ptr, png_ptr->sub_row);
  176314. png_free(png_ptr, png_ptr->up_row);
  176315. png_free(png_ptr, png_ptr->avg_row);
  176316. png_free(png_ptr, png_ptr->paeth_row);
  176317. #if defined(PNG_TIME_RFC1123_SUPPORTED)
  176318. png_free(png_ptr, png_ptr->time_buffer);
  176319. #endif
  176320. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  176321. png_free(png_ptr, png_ptr->prev_filters);
  176322. png_free(png_ptr, png_ptr->filter_weights);
  176323. png_free(png_ptr, png_ptr->inv_filter_weights);
  176324. png_free(png_ptr, png_ptr->filter_costs);
  176325. png_free(png_ptr, png_ptr->inv_filter_costs);
  176326. #endif
  176327. #ifdef PNG_SETJMP_SUPPORTED
  176328. png_memcpy(tmp_jmp, png_ptr->jmpbuf, png_sizeof (jmp_buf));
  176329. #endif
  176330. error_fn = png_ptr->error_fn;
  176331. warning_fn = png_ptr->warning_fn;
  176332. error_ptr = png_ptr->error_ptr;
  176333. #ifdef PNG_USER_MEM_SUPPORTED
  176334. free_fn = png_ptr->free_fn;
  176335. #endif
  176336. png_memset(png_ptr, 0, png_sizeof (png_struct));
  176337. png_ptr->error_fn = error_fn;
  176338. png_ptr->warning_fn = warning_fn;
  176339. png_ptr->error_ptr = error_ptr;
  176340. #ifdef PNG_USER_MEM_SUPPORTED
  176341. png_ptr->free_fn = free_fn;
  176342. #endif
  176343. #ifdef PNG_SETJMP_SUPPORTED
  176344. png_memcpy(png_ptr->jmpbuf, tmp_jmp, png_sizeof (jmp_buf));
  176345. #endif
  176346. }
  176347. void PNGAPI
  176348. png_set_filter(png_structp png_ptr, int method, int filters)
  176349. {
  176350. png_debug(1, "in png_set_filter\n");
  176351. if (png_ptr == NULL)
  176352. return;
  176353. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  176354. if((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  176355. (method == PNG_INTRAPIXEL_DIFFERENCING))
  176356. method = PNG_FILTER_TYPE_BASE;
  176357. #endif
  176358. if (method == PNG_FILTER_TYPE_BASE)
  176359. {
  176360. switch (filters & (PNG_ALL_FILTERS | 0x07))
  176361. {
  176362. #ifndef PNG_NO_WRITE_FILTER
  176363. case 5:
  176364. case 6:
  176365. case 7: png_warning(png_ptr, "Unknown row filter for method 0");
  176366. #endif /* PNG_NO_WRITE_FILTER */
  176367. case PNG_FILTER_VALUE_NONE:
  176368. png_ptr->do_filter=PNG_FILTER_NONE; break;
  176369. #ifndef PNG_NO_WRITE_FILTER
  176370. case PNG_FILTER_VALUE_SUB:
  176371. png_ptr->do_filter=PNG_FILTER_SUB; break;
  176372. case PNG_FILTER_VALUE_UP:
  176373. png_ptr->do_filter=PNG_FILTER_UP; break;
  176374. case PNG_FILTER_VALUE_AVG:
  176375. png_ptr->do_filter=PNG_FILTER_AVG; break;
  176376. case PNG_FILTER_VALUE_PAETH:
  176377. png_ptr->do_filter=PNG_FILTER_PAETH; break;
  176378. default: png_ptr->do_filter = (png_byte)filters; break;
  176379. #else
  176380. default: png_warning(png_ptr, "Unknown row filter for method 0");
  176381. #endif /* PNG_NO_WRITE_FILTER */
  176382. }
  176383. if (png_ptr->row_buf != NULL)
  176384. {
  176385. #ifndef PNG_NO_WRITE_FILTER
  176386. if ((png_ptr->do_filter & PNG_FILTER_SUB) && png_ptr->sub_row == NULL)
  176387. {
  176388. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  176389. (png_ptr->rowbytes + 1));
  176390. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  176391. }
  176392. if ((png_ptr->do_filter & PNG_FILTER_UP) && png_ptr->up_row == NULL)
  176393. {
  176394. if (png_ptr->prev_row == NULL)
  176395. {
  176396. png_warning(png_ptr, "Can't add Up filter after starting");
  176397. png_ptr->do_filter &= ~PNG_FILTER_UP;
  176398. }
  176399. else
  176400. {
  176401. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  176402. (png_ptr->rowbytes + 1));
  176403. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  176404. }
  176405. }
  176406. if ((png_ptr->do_filter & PNG_FILTER_AVG) && png_ptr->avg_row == NULL)
  176407. {
  176408. if (png_ptr->prev_row == NULL)
  176409. {
  176410. png_warning(png_ptr, "Can't add Average filter after starting");
  176411. png_ptr->do_filter &= ~PNG_FILTER_AVG;
  176412. }
  176413. else
  176414. {
  176415. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  176416. (png_ptr->rowbytes + 1));
  176417. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  176418. }
  176419. }
  176420. if ((png_ptr->do_filter & PNG_FILTER_PAETH) &&
  176421. png_ptr->paeth_row == NULL)
  176422. {
  176423. if (png_ptr->prev_row == NULL)
  176424. {
  176425. png_warning(png_ptr, "Can't add Paeth filter after starting");
  176426. png_ptr->do_filter &= (png_byte)(~PNG_FILTER_PAETH);
  176427. }
  176428. else
  176429. {
  176430. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  176431. (png_ptr->rowbytes + 1));
  176432. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  176433. }
  176434. }
  176435. if (png_ptr->do_filter == PNG_NO_FILTERS)
  176436. #endif /* PNG_NO_WRITE_FILTER */
  176437. png_ptr->do_filter = PNG_FILTER_NONE;
  176438. }
  176439. }
  176440. else
  176441. png_error(png_ptr, "Unknown custom filter method");
  176442. }
  176443. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED) /* GRR 970116 */
  176444. void PNGAPI
  176445. png_set_filter_heuristics(png_structp png_ptr, int heuristic_method,
  176446. int num_weights, png_doublep filter_weights,
  176447. png_doublep filter_costs)
  176448. {
  176449. int i;
  176450. png_debug(1, "in png_set_filter_heuristics\n");
  176451. if (png_ptr == NULL)
  176452. return;
  176453. if (heuristic_method >= PNG_FILTER_HEURISTIC_LAST)
  176454. {
  176455. png_warning(png_ptr, "Unknown filter heuristic method");
  176456. return;
  176457. }
  176458. if (heuristic_method == PNG_FILTER_HEURISTIC_DEFAULT)
  176459. {
  176460. heuristic_method = PNG_FILTER_HEURISTIC_UNWEIGHTED;
  176461. }
  176462. if (num_weights < 0 || filter_weights == NULL ||
  176463. heuristic_method == PNG_FILTER_HEURISTIC_UNWEIGHTED)
  176464. {
  176465. num_weights = 0;
  176466. }
  176467. png_ptr->num_prev_filters = (png_byte)num_weights;
  176468. png_ptr->heuristic_method = (png_byte)heuristic_method;
  176469. if (num_weights > 0)
  176470. {
  176471. if (png_ptr->prev_filters == NULL)
  176472. {
  176473. png_ptr->prev_filters = (png_bytep)png_malloc(png_ptr,
  176474. (png_uint_32)(png_sizeof(png_byte) * num_weights));
  176475. for (i = 0; i < num_weights; i++)
  176476. {
  176477. png_ptr->prev_filters[i] = 255;
  176478. }
  176479. }
  176480. if (png_ptr->filter_weights == NULL)
  176481. {
  176482. png_ptr->filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176483. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176484. png_ptr->inv_filter_weights = (png_uint_16p)png_malloc(png_ptr,
  176485. (png_uint_32)(png_sizeof(png_uint_16) * num_weights));
  176486. for (i = 0; i < num_weights; i++)
  176487. {
  176488. png_ptr->inv_filter_weights[i] =
  176489. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176490. }
  176491. }
  176492. for (i = 0; i < num_weights; i++)
  176493. {
  176494. if (filter_weights[i] < 0.0)
  176495. {
  176496. png_ptr->inv_filter_weights[i] =
  176497. png_ptr->filter_weights[i] = PNG_WEIGHT_FACTOR;
  176498. }
  176499. else
  176500. {
  176501. png_ptr->inv_filter_weights[i] =
  176502. (png_uint_16)((double)PNG_WEIGHT_FACTOR*filter_weights[i]+0.5);
  176503. png_ptr->filter_weights[i] =
  176504. (png_uint_16)((double)PNG_WEIGHT_FACTOR/filter_weights[i]+0.5);
  176505. }
  176506. }
  176507. }
  176508. if (png_ptr->filter_costs == NULL)
  176509. {
  176510. png_ptr->filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176511. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176512. png_ptr->inv_filter_costs = (png_uint_16p)png_malloc(png_ptr,
  176513. (png_uint_32)(png_sizeof(png_uint_16) * PNG_FILTER_VALUE_LAST));
  176514. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176515. {
  176516. png_ptr->inv_filter_costs[i] =
  176517. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176518. }
  176519. }
  176520. for (i = 0; i < PNG_FILTER_VALUE_LAST; i++)
  176521. {
  176522. if (filter_costs == NULL || filter_costs[i] < 0.0)
  176523. {
  176524. png_ptr->inv_filter_costs[i] =
  176525. png_ptr->filter_costs[i] = PNG_COST_FACTOR;
  176526. }
  176527. else if (filter_costs[i] >= 1.0)
  176528. {
  176529. png_ptr->inv_filter_costs[i] =
  176530. (png_uint_16)((double)PNG_COST_FACTOR / filter_costs[i] + 0.5);
  176531. png_ptr->filter_costs[i] =
  176532. (png_uint_16)((double)PNG_COST_FACTOR * filter_costs[i] + 0.5);
  176533. }
  176534. }
  176535. }
  176536. #endif /* PNG_WRITE_WEIGHTED_FILTER_SUPPORTED */
  176537. void PNGAPI
  176538. png_set_compression_level(png_structp png_ptr, int level)
  176539. {
  176540. png_debug(1, "in png_set_compression_level\n");
  176541. if (png_ptr == NULL)
  176542. return;
  176543. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_LEVEL;
  176544. png_ptr->zlib_level = level;
  176545. }
  176546. void PNGAPI
  176547. png_set_compression_mem_level(png_structp png_ptr, int mem_level)
  176548. {
  176549. png_debug(1, "in png_set_compression_mem_level\n");
  176550. if (png_ptr == NULL)
  176551. return;
  176552. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL;
  176553. png_ptr->zlib_mem_level = mem_level;
  176554. }
  176555. void PNGAPI
  176556. png_set_compression_strategy(png_structp png_ptr, int strategy)
  176557. {
  176558. png_debug(1, "in png_set_compression_strategy\n");
  176559. if (png_ptr == NULL)
  176560. return;
  176561. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_STRATEGY;
  176562. png_ptr->zlib_strategy = strategy;
  176563. }
  176564. void PNGAPI
  176565. png_set_compression_window_bits(png_structp png_ptr, int window_bits)
  176566. {
  176567. if (png_ptr == NULL)
  176568. return;
  176569. if (window_bits > 15)
  176570. png_warning(png_ptr, "Only compression windows <= 32k supported by PNG");
  176571. else if (window_bits < 8)
  176572. png_warning(png_ptr, "Only compression windows >= 256 supported by PNG");
  176573. #ifndef WBITS_8_OK
  176574. if (window_bits == 8)
  176575. {
  176576. png_warning(png_ptr, "Compression window is being reset to 512");
  176577. window_bits=9;
  176578. }
  176579. #endif
  176580. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS;
  176581. png_ptr->zlib_window_bits = window_bits;
  176582. }
  176583. void PNGAPI
  176584. png_set_compression_method(png_structp png_ptr, int method)
  176585. {
  176586. png_debug(1, "in png_set_compression_method\n");
  176587. if (png_ptr == NULL)
  176588. return;
  176589. if (method != 8)
  176590. png_warning(png_ptr, "Only compression method 8 is supported by PNG");
  176591. png_ptr->flags |= PNG_FLAG_ZLIB_CUSTOM_METHOD;
  176592. png_ptr->zlib_method = method;
  176593. }
  176594. void PNGAPI
  176595. png_set_write_status_fn(png_structp png_ptr, png_write_status_ptr write_row_fn)
  176596. {
  176597. if (png_ptr == NULL)
  176598. return;
  176599. png_ptr->write_row_fn = write_row_fn;
  176600. }
  176601. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176602. void PNGAPI
  176603. png_set_write_user_transform_fn(png_structp png_ptr, png_user_transform_ptr
  176604. write_user_transform_fn)
  176605. {
  176606. png_debug(1, "in png_set_write_user_transform_fn\n");
  176607. if (png_ptr == NULL)
  176608. return;
  176609. png_ptr->transformations |= PNG_USER_TRANSFORM;
  176610. png_ptr->write_user_transform_fn = write_user_transform_fn;
  176611. }
  176612. #endif
  176613. #if defined(PNG_INFO_IMAGE_SUPPORTED)
  176614. void PNGAPI
  176615. png_write_png(png_structp png_ptr, png_infop info_ptr,
  176616. int transforms, voidp params)
  176617. {
  176618. if (png_ptr == NULL || info_ptr == NULL)
  176619. return;
  176620. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176621. if (transforms & PNG_TRANSFORM_INVERT_ALPHA)
  176622. png_set_invert_alpha(png_ptr);
  176623. #endif
  176624. png_write_info(png_ptr, info_ptr);
  176625. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176626. if (transforms & PNG_TRANSFORM_INVERT_MONO)
  176627. png_set_invert_mono(png_ptr);
  176628. #endif
  176629. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176630. if ((transforms & PNG_TRANSFORM_SHIFT)
  176631. && (info_ptr->valid & PNG_INFO_sBIT))
  176632. png_set_shift(png_ptr, &info_ptr->sig_bit);
  176633. #endif
  176634. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176635. if (transforms & PNG_TRANSFORM_PACKING)
  176636. png_set_packing(png_ptr);
  176637. #endif
  176638. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176639. if (transforms & PNG_TRANSFORM_SWAP_ALPHA)
  176640. png_set_swap_alpha(png_ptr);
  176641. #endif
  176642. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176643. if (transforms & PNG_TRANSFORM_STRIP_FILLER)
  176644. png_set_filler(png_ptr, 0, PNG_FILLER_BEFORE);
  176645. #endif
  176646. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176647. if (transforms & PNG_TRANSFORM_BGR)
  176648. png_set_bgr(png_ptr);
  176649. #endif
  176650. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176651. if (transforms & PNG_TRANSFORM_SWAP_ENDIAN)
  176652. png_set_swap(png_ptr);
  176653. #endif
  176654. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176655. if (transforms & PNG_TRANSFORM_PACKSWAP)
  176656. png_set_packswap(png_ptr);
  176657. #endif
  176658. if (info_ptr->valid & PNG_INFO_IDAT)
  176659. png_write_image(png_ptr, info_ptr->row_pointers);
  176660. png_write_end(png_ptr, info_ptr);
  176661. transforms = transforms; /* quiet compiler warnings */
  176662. params = params;
  176663. }
  176664. #endif
  176665. #endif /* PNG_WRITE_SUPPORTED */
  176666. /*** End of inlined file: pngwrite.c ***/
  176667. /*** Start of inlined file: pngwtran.c ***/
  176668. #define PNG_INTERNAL
  176669. #ifdef PNG_WRITE_SUPPORTED
  176670. void /* PRIVATE */
  176671. png_do_write_transformations(png_structp png_ptr)
  176672. {
  176673. png_debug(1, "in png_do_write_transformations\n");
  176674. if (png_ptr == NULL)
  176675. return;
  176676. #if defined(PNG_WRITE_USER_TRANSFORM_SUPPORTED)
  176677. if (png_ptr->transformations & PNG_USER_TRANSFORM)
  176678. if(png_ptr->write_user_transform_fn != NULL)
  176679. (*(png_ptr->write_user_transform_fn)) /* user write transform function */
  176680. (png_ptr, /* png_ptr */
  176681. &(png_ptr->row_info), /* row_info: */
  176682. png_ptr->row_buf + 1); /* start of pixel data for row */
  176683. #endif
  176684. #if defined(PNG_WRITE_FILLER_SUPPORTED)
  176685. if (png_ptr->transformations & PNG_FILLER)
  176686. png_do_strip_filler(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176687. png_ptr->flags);
  176688. #endif
  176689. #if defined(PNG_WRITE_PACKSWAP_SUPPORTED)
  176690. if (png_ptr->transformations & PNG_PACKSWAP)
  176691. png_do_packswap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176692. #endif
  176693. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176694. if (png_ptr->transformations & PNG_PACK)
  176695. png_do_pack(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176696. (png_uint_32)png_ptr->bit_depth);
  176697. #endif
  176698. #if defined(PNG_WRITE_SWAP_SUPPORTED)
  176699. if (png_ptr->transformations & PNG_SWAP_BYTES)
  176700. png_do_swap(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176701. #endif
  176702. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176703. if (png_ptr->transformations & PNG_SHIFT)
  176704. png_do_shift(&(png_ptr->row_info), png_ptr->row_buf + 1,
  176705. &(png_ptr->shift));
  176706. #endif
  176707. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176708. if (png_ptr->transformations & PNG_SWAP_ALPHA)
  176709. png_do_write_swap_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176710. #endif
  176711. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  176712. if (png_ptr->transformations & PNG_INVERT_ALPHA)
  176713. png_do_write_invert_alpha(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176714. #endif
  176715. #if defined(PNG_WRITE_BGR_SUPPORTED)
  176716. if (png_ptr->transformations & PNG_BGR)
  176717. png_do_bgr(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176718. #endif
  176719. #if defined(PNG_WRITE_INVERT_SUPPORTED)
  176720. if (png_ptr->transformations & PNG_INVERT_MONO)
  176721. png_do_invert(&(png_ptr->row_info), png_ptr->row_buf + 1);
  176722. #endif
  176723. }
  176724. #if defined(PNG_WRITE_PACK_SUPPORTED)
  176725. void /* PRIVATE */
  176726. png_do_pack(png_row_infop row_info, png_bytep row, png_uint_32 bit_depth)
  176727. {
  176728. png_debug(1, "in png_do_pack\n");
  176729. if (row_info->bit_depth == 8 &&
  176730. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176731. row != NULL && row_info != NULL &&
  176732. #endif
  176733. row_info->channels == 1)
  176734. {
  176735. switch ((int)bit_depth)
  176736. {
  176737. case 1:
  176738. {
  176739. png_bytep sp, dp;
  176740. int mask, v;
  176741. png_uint_32 i;
  176742. png_uint_32 row_width = row_info->width;
  176743. sp = row;
  176744. dp = row;
  176745. mask = 0x80;
  176746. v = 0;
  176747. for (i = 0; i < row_width; i++)
  176748. {
  176749. if (*sp != 0)
  176750. v |= mask;
  176751. sp++;
  176752. if (mask > 1)
  176753. mask >>= 1;
  176754. else
  176755. {
  176756. mask = 0x80;
  176757. *dp = (png_byte)v;
  176758. dp++;
  176759. v = 0;
  176760. }
  176761. }
  176762. if (mask != 0x80)
  176763. *dp = (png_byte)v;
  176764. break;
  176765. }
  176766. case 2:
  176767. {
  176768. png_bytep sp, dp;
  176769. int shift, v;
  176770. png_uint_32 i;
  176771. png_uint_32 row_width = row_info->width;
  176772. sp = row;
  176773. dp = row;
  176774. shift = 6;
  176775. v = 0;
  176776. for (i = 0; i < row_width; i++)
  176777. {
  176778. png_byte value;
  176779. value = (png_byte)(*sp & 0x03);
  176780. v |= (value << shift);
  176781. if (shift == 0)
  176782. {
  176783. shift = 6;
  176784. *dp = (png_byte)v;
  176785. dp++;
  176786. v = 0;
  176787. }
  176788. else
  176789. shift -= 2;
  176790. sp++;
  176791. }
  176792. if (shift != 6)
  176793. *dp = (png_byte)v;
  176794. break;
  176795. }
  176796. case 4:
  176797. {
  176798. png_bytep sp, dp;
  176799. int shift, v;
  176800. png_uint_32 i;
  176801. png_uint_32 row_width = row_info->width;
  176802. sp = row;
  176803. dp = row;
  176804. shift = 4;
  176805. v = 0;
  176806. for (i = 0; i < row_width; i++)
  176807. {
  176808. png_byte value;
  176809. value = (png_byte)(*sp & 0x0f);
  176810. v |= (value << shift);
  176811. if (shift == 0)
  176812. {
  176813. shift = 4;
  176814. *dp = (png_byte)v;
  176815. dp++;
  176816. v = 0;
  176817. }
  176818. else
  176819. shift -= 4;
  176820. sp++;
  176821. }
  176822. if (shift != 4)
  176823. *dp = (png_byte)v;
  176824. break;
  176825. }
  176826. }
  176827. row_info->bit_depth = (png_byte)bit_depth;
  176828. row_info->pixel_depth = (png_byte)(bit_depth * row_info->channels);
  176829. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  176830. row_info->width);
  176831. }
  176832. }
  176833. #endif
  176834. #if defined(PNG_WRITE_SHIFT_SUPPORTED)
  176835. void /* PRIVATE */
  176836. png_do_shift(png_row_infop row_info, png_bytep row, png_color_8p bit_depth)
  176837. {
  176838. png_debug(1, "in png_do_shift\n");
  176839. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176840. if (row != NULL && row_info != NULL &&
  176841. #else
  176842. if (
  176843. #endif
  176844. row_info->color_type != PNG_COLOR_TYPE_PALETTE)
  176845. {
  176846. int shift_start[4], shift_dec[4];
  176847. int channels = 0;
  176848. if (row_info->color_type & PNG_COLOR_MASK_COLOR)
  176849. {
  176850. shift_start[channels] = row_info->bit_depth - bit_depth->red;
  176851. shift_dec[channels] = bit_depth->red;
  176852. channels++;
  176853. shift_start[channels] = row_info->bit_depth - bit_depth->green;
  176854. shift_dec[channels] = bit_depth->green;
  176855. channels++;
  176856. shift_start[channels] = row_info->bit_depth - bit_depth->blue;
  176857. shift_dec[channels] = bit_depth->blue;
  176858. channels++;
  176859. }
  176860. else
  176861. {
  176862. shift_start[channels] = row_info->bit_depth - bit_depth->gray;
  176863. shift_dec[channels] = bit_depth->gray;
  176864. channels++;
  176865. }
  176866. if (row_info->color_type & PNG_COLOR_MASK_ALPHA)
  176867. {
  176868. shift_start[channels] = row_info->bit_depth - bit_depth->alpha;
  176869. shift_dec[channels] = bit_depth->alpha;
  176870. channels++;
  176871. }
  176872. if (row_info->bit_depth < 8)
  176873. {
  176874. png_bytep bp = row;
  176875. png_uint_32 i;
  176876. png_byte mask;
  176877. png_uint_32 row_bytes = row_info->rowbytes;
  176878. if (bit_depth->gray == 1 && row_info->bit_depth == 2)
  176879. mask = 0x55;
  176880. else if (row_info->bit_depth == 4 && bit_depth->gray == 3)
  176881. mask = 0x11;
  176882. else
  176883. mask = 0xff;
  176884. for (i = 0; i < row_bytes; i++, bp++)
  176885. {
  176886. png_uint_16 v;
  176887. int j;
  176888. v = *bp;
  176889. *bp = 0;
  176890. for (j = shift_start[0]; j > -shift_dec[0]; j -= shift_dec[0])
  176891. {
  176892. if (j > 0)
  176893. *bp |= (png_byte)((v << j) & 0xff);
  176894. else
  176895. *bp |= (png_byte)((v >> (-j)) & mask);
  176896. }
  176897. }
  176898. }
  176899. else if (row_info->bit_depth == 8)
  176900. {
  176901. png_bytep bp = row;
  176902. png_uint_32 i;
  176903. png_uint_32 istop = channels * row_info->width;
  176904. for (i = 0; i < istop; i++, bp++)
  176905. {
  176906. png_uint_16 v;
  176907. int j;
  176908. int c = (int)(i%channels);
  176909. v = *bp;
  176910. *bp = 0;
  176911. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176912. {
  176913. if (j > 0)
  176914. *bp |= (png_byte)((v << j) & 0xff);
  176915. else
  176916. *bp |= (png_byte)((v >> (-j)) & 0xff);
  176917. }
  176918. }
  176919. }
  176920. else
  176921. {
  176922. png_bytep bp;
  176923. png_uint_32 i;
  176924. png_uint_32 istop = channels * row_info->width;
  176925. for (bp = row, i = 0; i < istop; i++)
  176926. {
  176927. int c = (int)(i%channels);
  176928. png_uint_16 value, v;
  176929. int j;
  176930. v = (png_uint_16)(((png_uint_16)(*bp) << 8) + *(bp + 1));
  176931. value = 0;
  176932. for (j = shift_start[c]; j > -shift_dec[c]; j -= shift_dec[c])
  176933. {
  176934. if (j > 0)
  176935. value |= (png_uint_16)((v << j) & (png_uint_16)0xffff);
  176936. else
  176937. value |= (png_uint_16)((v >> (-j)) & (png_uint_16)0xffff);
  176938. }
  176939. *bp++ = (png_byte)(value >> 8);
  176940. *bp++ = (png_byte)(value & 0xff);
  176941. }
  176942. }
  176943. }
  176944. }
  176945. #endif
  176946. #if defined(PNG_WRITE_SWAP_ALPHA_SUPPORTED)
  176947. void /* PRIVATE */
  176948. png_do_write_swap_alpha(png_row_infop row_info, png_bytep row)
  176949. {
  176950. png_debug(1, "in png_do_write_swap_alpha\n");
  176951. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  176952. if (row != NULL && row_info != NULL)
  176953. #endif
  176954. {
  176955. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  176956. {
  176957. if (row_info->bit_depth == 8)
  176958. {
  176959. png_bytep sp, dp;
  176960. png_uint_32 i;
  176961. png_uint_32 row_width = row_info->width;
  176962. for (i = 0, sp = dp = row; i < row_width; i++)
  176963. {
  176964. png_byte save = *(sp++);
  176965. *(dp++) = *(sp++);
  176966. *(dp++) = *(sp++);
  176967. *(dp++) = *(sp++);
  176968. *(dp++) = save;
  176969. }
  176970. }
  176971. else
  176972. {
  176973. png_bytep sp, dp;
  176974. png_uint_32 i;
  176975. png_uint_32 row_width = row_info->width;
  176976. for (i = 0, sp = dp = row; i < row_width; i++)
  176977. {
  176978. png_byte save[2];
  176979. save[0] = *(sp++);
  176980. save[1] = *(sp++);
  176981. *(dp++) = *(sp++);
  176982. *(dp++) = *(sp++);
  176983. *(dp++) = *(sp++);
  176984. *(dp++) = *(sp++);
  176985. *(dp++) = *(sp++);
  176986. *(dp++) = *(sp++);
  176987. *(dp++) = save[0];
  176988. *(dp++) = save[1];
  176989. }
  176990. }
  176991. }
  176992. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  176993. {
  176994. if (row_info->bit_depth == 8)
  176995. {
  176996. png_bytep sp, dp;
  176997. png_uint_32 i;
  176998. png_uint_32 row_width = row_info->width;
  176999. for (i = 0, sp = dp = row; i < row_width; i++)
  177000. {
  177001. png_byte save = *(sp++);
  177002. *(dp++) = *(sp++);
  177003. *(dp++) = save;
  177004. }
  177005. }
  177006. else
  177007. {
  177008. png_bytep sp, dp;
  177009. png_uint_32 i;
  177010. png_uint_32 row_width = row_info->width;
  177011. for (i = 0, sp = dp = row; i < row_width; i++)
  177012. {
  177013. png_byte save[2];
  177014. save[0] = *(sp++);
  177015. save[1] = *(sp++);
  177016. *(dp++) = *(sp++);
  177017. *(dp++) = *(sp++);
  177018. *(dp++) = save[0];
  177019. *(dp++) = save[1];
  177020. }
  177021. }
  177022. }
  177023. }
  177024. }
  177025. #endif
  177026. #if defined(PNG_WRITE_INVERT_ALPHA_SUPPORTED)
  177027. void /* PRIVATE */
  177028. png_do_write_invert_alpha(png_row_infop row_info, png_bytep row)
  177029. {
  177030. png_debug(1, "in png_do_write_invert_alpha\n");
  177031. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177032. if (row != NULL && row_info != NULL)
  177033. #endif
  177034. {
  177035. if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177036. {
  177037. if (row_info->bit_depth == 8)
  177038. {
  177039. png_bytep sp, dp;
  177040. png_uint_32 i;
  177041. png_uint_32 row_width = row_info->width;
  177042. for (i = 0, sp = dp = row; i < row_width; i++)
  177043. {
  177044. sp+=3; dp = sp;
  177045. *(dp++) = (png_byte)(255 - *(sp++));
  177046. }
  177047. }
  177048. else
  177049. {
  177050. png_bytep sp, dp;
  177051. png_uint_32 i;
  177052. png_uint_32 row_width = row_info->width;
  177053. for (i = 0, sp = dp = row; i < row_width; i++)
  177054. {
  177055. sp+=6; dp = sp;
  177056. *(dp++) = (png_byte)(255 - *(sp++));
  177057. *(dp++) = (png_byte)(255 - *(sp++));
  177058. }
  177059. }
  177060. }
  177061. else if (row_info->color_type == PNG_COLOR_TYPE_GRAY_ALPHA)
  177062. {
  177063. if (row_info->bit_depth == 8)
  177064. {
  177065. png_bytep sp, dp;
  177066. png_uint_32 i;
  177067. png_uint_32 row_width = row_info->width;
  177068. for (i = 0, sp = dp = row; i < row_width; i++)
  177069. {
  177070. *(dp++) = *(sp++);
  177071. *(dp++) = (png_byte)(255 - *(sp++));
  177072. }
  177073. }
  177074. else
  177075. {
  177076. png_bytep sp, dp;
  177077. png_uint_32 i;
  177078. png_uint_32 row_width = row_info->width;
  177079. for (i = 0, sp = dp = row; i < row_width; i++)
  177080. {
  177081. sp+=2; dp = sp;
  177082. *(dp++) = (png_byte)(255 - *(sp++));
  177083. *(dp++) = (png_byte)(255 - *(sp++));
  177084. }
  177085. }
  177086. }
  177087. }
  177088. }
  177089. #endif
  177090. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177091. void /* PRIVATE */
  177092. png_do_write_intrapixel(png_row_infop row_info, png_bytep row)
  177093. {
  177094. png_debug(1, "in png_do_write_intrapixel\n");
  177095. if (
  177096. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  177097. row != NULL && row_info != NULL &&
  177098. #endif
  177099. (row_info->color_type & PNG_COLOR_MASK_COLOR))
  177100. {
  177101. int bytes_per_pixel;
  177102. png_uint_32 row_width = row_info->width;
  177103. if (row_info->bit_depth == 8)
  177104. {
  177105. png_bytep rp;
  177106. png_uint_32 i;
  177107. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  177108. bytes_per_pixel = 3;
  177109. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177110. bytes_per_pixel = 4;
  177111. else
  177112. return;
  177113. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  177114. {
  177115. *(rp) = (png_byte)((*rp - *(rp+1))&0xff);
  177116. *(rp+2) = (png_byte)((*(rp+2) - *(rp+1))&0xff);
  177117. }
  177118. }
  177119. else if (row_info->bit_depth == 16)
  177120. {
  177121. png_bytep rp;
  177122. png_uint_32 i;
  177123. if (row_info->color_type == PNG_COLOR_TYPE_RGB)
  177124. bytes_per_pixel = 6;
  177125. else if (row_info->color_type == PNG_COLOR_TYPE_RGB_ALPHA)
  177126. bytes_per_pixel = 8;
  177127. else
  177128. return;
  177129. for (i = 0, rp = row; i < row_width; i++, rp += bytes_per_pixel)
  177130. {
  177131. png_uint_32 s0 = (*(rp ) << 8) | *(rp+1);
  177132. png_uint_32 s1 = (*(rp+2) << 8) | *(rp+3);
  177133. png_uint_32 s2 = (*(rp+4) << 8) | *(rp+5);
  177134. png_uint_32 red = (png_uint_32)((s0-s1) & 0xffffL);
  177135. png_uint_32 blue = (png_uint_32)((s2-s1) & 0xffffL);
  177136. *(rp ) = (png_byte)((red >> 8) & 0xff);
  177137. *(rp+1) = (png_byte)(red & 0xff);
  177138. *(rp+4) = (png_byte)((blue >> 8) & 0xff);
  177139. *(rp+5) = (png_byte)(blue & 0xff);
  177140. }
  177141. }
  177142. }
  177143. }
  177144. #endif /* PNG_MNG_FEATURES_SUPPORTED */
  177145. #endif /* PNG_WRITE_SUPPORTED */
  177146. /*** End of inlined file: pngwtran.c ***/
  177147. /*** Start of inlined file: pngwutil.c ***/
  177148. #define PNG_INTERNAL
  177149. #ifdef PNG_WRITE_SUPPORTED
  177150. void PNGAPI
  177151. png_save_uint_32(png_bytep buf, png_uint_32 i)
  177152. {
  177153. buf[0] = (png_byte)((i >> 24) & 0xff);
  177154. buf[1] = (png_byte)((i >> 16) & 0xff);
  177155. buf[2] = (png_byte)((i >> 8) & 0xff);
  177156. buf[3] = (png_byte)(i & 0xff);
  177157. }
  177158. void PNGAPI
  177159. png_save_int_32(png_bytep buf, png_int_32 i)
  177160. {
  177161. buf[0] = (png_byte)((i >> 24) & 0xff);
  177162. buf[1] = (png_byte)((i >> 16) & 0xff);
  177163. buf[2] = (png_byte)((i >> 8) & 0xff);
  177164. buf[3] = (png_byte)(i & 0xff);
  177165. }
  177166. void PNGAPI
  177167. png_save_uint_16(png_bytep buf, unsigned int i)
  177168. {
  177169. buf[0] = (png_byte)((i >> 8) & 0xff);
  177170. buf[1] = (png_byte)(i & 0xff);
  177171. }
  177172. void PNGAPI
  177173. png_write_chunk(png_structp png_ptr, png_bytep chunk_name,
  177174. png_bytep data, png_size_t length)
  177175. {
  177176. if(png_ptr == NULL) return;
  177177. png_write_chunk_start(png_ptr, chunk_name, (png_uint_32)length);
  177178. png_write_chunk_data(png_ptr, data, length);
  177179. png_write_chunk_end(png_ptr);
  177180. }
  177181. void PNGAPI
  177182. png_write_chunk_start(png_structp png_ptr, png_bytep chunk_name,
  177183. png_uint_32 length)
  177184. {
  177185. png_byte buf[4];
  177186. png_debug2(0, "Writing %s chunk (%lu bytes)\n", chunk_name, length);
  177187. if(png_ptr == NULL) return;
  177188. png_save_uint_32(buf, length);
  177189. png_write_data(png_ptr, buf, (png_size_t)4);
  177190. png_write_data(png_ptr, chunk_name, (png_size_t)4);
  177191. png_reset_crc(png_ptr);
  177192. png_calculate_crc(png_ptr, chunk_name, (png_size_t)4);
  177193. }
  177194. void PNGAPI
  177195. png_write_chunk_data(png_structp png_ptr, png_bytep data, png_size_t length)
  177196. {
  177197. if(png_ptr == NULL) return;
  177198. if (data != NULL && length > 0)
  177199. {
  177200. png_calculate_crc(png_ptr, data, length);
  177201. png_write_data(png_ptr, data, length);
  177202. }
  177203. }
  177204. void PNGAPI
  177205. png_write_chunk_end(png_structp png_ptr)
  177206. {
  177207. png_byte buf[4];
  177208. if(png_ptr == NULL) return;
  177209. png_save_uint_32(buf, png_ptr->crc);
  177210. png_write_data(png_ptr, buf, (png_size_t)4);
  177211. }
  177212. void /* PRIVATE */
  177213. png_write_sig(png_structp png_ptr)
  177214. {
  177215. png_byte png_signature[8] = {137, 80, 78, 71, 13, 10, 26, 10};
  177216. png_write_data(png_ptr, &png_signature[png_ptr->sig_bytes],
  177217. (png_size_t)8 - png_ptr->sig_bytes);
  177218. if(png_ptr->sig_bytes < 3)
  177219. png_ptr->mode |= PNG_HAVE_PNG_SIGNATURE;
  177220. }
  177221. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_iCCP_SUPPORTED)
  177222. typedef struct
  177223. {
  177224. char *input; /* the uncompressed input data */
  177225. int input_len; /* its length */
  177226. int num_output_ptr; /* number of output pointers used */
  177227. int max_output_ptr; /* size of output_ptr */
  177228. png_charpp output_ptr; /* array of pointers to output */
  177229. } compression_state;
  177230. static int /* PRIVATE */
  177231. png_text_compress(png_structp png_ptr,
  177232. png_charp text, png_size_t text_len, int compression,
  177233. compression_state *comp)
  177234. {
  177235. int ret;
  177236. comp->num_output_ptr = 0;
  177237. comp->max_output_ptr = 0;
  177238. comp->output_ptr = NULL;
  177239. comp->input = NULL;
  177240. comp->input_len = 0;
  177241. if (compression == PNG_TEXT_COMPRESSION_NONE)
  177242. {
  177243. comp->input = text;
  177244. comp->input_len = text_len;
  177245. return((int)text_len);
  177246. }
  177247. if (compression >= PNG_TEXT_COMPRESSION_LAST)
  177248. {
  177249. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  177250. char msg[50];
  177251. png_snprintf(msg, 50, "Unknown compression type %d", compression);
  177252. png_warning(png_ptr, msg);
  177253. #else
  177254. png_warning(png_ptr, "Unknown compression type");
  177255. #endif
  177256. }
  177257. png_ptr->zstream.avail_in = (uInt)text_len;
  177258. png_ptr->zstream.next_in = (Bytef *)text;
  177259. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177260. png_ptr->zstream.next_out = (Bytef *)png_ptr->zbuf;
  177261. do
  177262. {
  177263. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  177264. if (ret != Z_OK)
  177265. {
  177266. if (png_ptr->zstream.msg != NULL)
  177267. png_error(png_ptr, png_ptr->zstream.msg);
  177268. else
  177269. png_error(png_ptr, "zlib error");
  177270. }
  177271. if (!(png_ptr->zstream.avail_out))
  177272. {
  177273. if (comp->num_output_ptr >= comp->max_output_ptr)
  177274. {
  177275. int old_max;
  177276. old_max = comp->max_output_ptr;
  177277. comp->max_output_ptr = comp->num_output_ptr + 4;
  177278. if (comp->output_ptr != NULL)
  177279. {
  177280. png_charpp old_ptr;
  177281. old_ptr = comp->output_ptr;
  177282. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177283. (png_uint_32)(comp->max_output_ptr *
  177284. png_sizeof (png_charpp)));
  177285. png_memcpy(comp->output_ptr, old_ptr, old_max
  177286. * png_sizeof (png_charp));
  177287. png_free(png_ptr, old_ptr);
  177288. }
  177289. else
  177290. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177291. (png_uint_32)(comp->max_output_ptr *
  177292. png_sizeof (png_charp)));
  177293. }
  177294. comp->output_ptr[comp->num_output_ptr] = (png_charp)png_malloc(png_ptr,
  177295. (png_uint_32)png_ptr->zbuf_size);
  177296. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177297. png_ptr->zbuf_size);
  177298. comp->num_output_ptr++;
  177299. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177300. png_ptr->zstream.next_out = png_ptr->zbuf;
  177301. }
  177302. } while (png_ptr->zstream.avail_in);
  177303. do
  177304. {
  177305. ret = deflate(&png_ptr->zstream, Z_FINISH);
  177306. if (ret == Z_OK)
  177307. {
  177308. if (!(png_ptr->zstream.avail_out))
  177309. {
  177310. if (comp->num_output_ptr >= comp->max_output_ptr)
  177311. {
  177312. int old_max;
  177313. old_max = comp->max_output_ptr;
  177314. comp->max_output_ptr = comp->num_output_ptr + 4;
  177315. if (comp->output_ptr != NULL)
  177316. {
  177317. png_charpp old_ptr;
  177318. old_ptr = comp->output_ptr;
  177319. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177320. (png_uint_32)(comp->max_output_ptr *
  177321. png_sizeof (png_charpp)));
  177322. png_memcpy(comp->output_ptr, old_ptr,
  177323. old_max * png_sizeof (png_charp));
  177324. png_free(png_ptr, old_ptr);
  177325. }
  177326. else
  177327. comp->output_ptr = (png_charpp)png_malloc(png_ptr,
  177328. (png_uint_32)(comp->max_output_ptr *
  177329. png_sizeof (png_charp)));
  177330. }
  177331. comp->output_ptr[comp->num_output_ptr] =
  177332. (png_charp)png_malloc(png_ptr, (png_uint_32)png_ptr->zbuf_size);
  177333. png_memcpy(comp->output_ptr[comp->num_output_ptr], png_ptr->zbuf,
  177334. png_ptr->zbuf_size);
  177335. comp->num_output_ptr++;
  177336. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177337. png_ptr->zstream.next_out = png_ptr->zbuf;
  177338. }
  177339. }
  177340. else if (ret != Z_STREAM_END)
  177341. {
  177342. if (png_ptr->zstream.msg != NULL)
  177343. png_error(png_ptr, png_ptr->zstream.msg);
  177344. else
  177345. png_error(png_ptr, "zlib error");
  177346. }
  177347. } while (ret != Z_STREAM_END);
  177348. text_len = png_ptr->zbuf_size * comp->num_output_ptr;
  177349. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  177350. text_len += png_ptr->zbuf_size - (png_size_t)png_ptr->zstream.avail_out;
  177351. return((int)text_len);
  177352. }
  177353. static void /* PRIVATE */
  177354. png_write_compressed_data_out(png_structp png_ptr, compression_state *comp)
  177355. {
  177356. int i;
  177357. if (comp->input)
  177358. {
  177359. png_write_chunk_data(png_ptr, (png_bytep)comp->input,
  177360. (png_size_t)comp->input_len);
  177361. return;
  177362. }
  177363. for (i = 0; i < comp->num_output_ptr; i++)
  177364. {
  177365. png_write_chunk_data(png_ptr,(png_bytep)comp->output_ptr[i],
  177366. png_ptr->zbuf_size);
  177367. png_free(png_ptr, comp->output_ptr[i]);
  177368. comp->output_ptr[i]=NULL;
  177369. }
  177370. if (comp->max_output_ptr != 0)
  177371. png_free(png_ptr, comp->output_ptr);
  177372. comp->output_ptr=NULL;
  177373. if (png_ptr->zstream.avail_out < (png_uint_32)png_ptr->zbuf_size)
  177374. png_write_chunk_data(png_ptr, png_ptr->zbuf,
  177375. png_ptr->zbuf_size - png_ptr->zstream.avail_out);
  177376. deflateReset(&png_ptr->zstream);
  177377. png_ptr->zstream.data_type = Z_BINARY;
  177378. }
  177379. #endif
  177380. void /* PRIVATE */
  177381. png_write_IHDR(png_structp png_ptr, png_uint_32 width, png_uint_32 height,
  177382. int bit_depth, int color_type, int compression_type, int filter_type,
  177383. int interlace_type)
  177384. {
  177385. #ifdef PNG_USE_LOCAL_ARRAYS
  177386. PNG_IHDR;
  177387. #endif
  177388. png_byte buf[13]; /* buffer to store the IHDR info */
  177389. png_debug(1, "in png_write_IHDR\n");
  177390. switch (color_type)
  177391. {
  177392. case PNG_COLOR_TYPE_GRAY:
  177393. switch (bit_depth)
  177394. {
  177395. case 1:
  177396. case 2:
  177397. case 4:
  177398. case 8:
  177399. case 16: png_ptr->channels = 1; break;
  177400. default: png_error(png_ptr,"Invalid bit depth for grayscale image");
  177401. }
  177402. break;
  177403. case PNG_COLOR_TYPE_RGB:
  177404. if (bit_depth != 8 && bit_depth != 16)
  177405. png_error(png_ptr, "Invalid bit depth for RGB image");
  177406. png_ptr->channels = 3;
  177407. break;
  177408. case PNG_COLOR_TYPE_PALETTE:
  177409. switch (bit_depth)
  177410. {
  177411. case 1:
  177412. case 2:
  177413. case 4:
  177414. case 8: png_ptr->channels = 1; break;
  177415. default: png_error(png_ptr, "Invalid bit depth for paletted image");
  177416. }
  177417. break;
  177418. case PNG_COLOR_TYPE_GRAY_ALPHA:
  177419. if (bit_depth != 8 && bit_depth != 16)
  177420. png_error(png_ptr, "Invalid bit depth for grayscale+alpha image");
  177421. png_ptr->channels = 2;
  177422. break;
  177423. case PNG_COLOR_TYPE_RGB_ALPHA:
  177424. if (bit_depth != 8 && bit_depth != 16)
  177425. png_error(png_ptr, "Invalid bit depth for RGBA image");
  177426. png_ptr->channels = 4;
  177427. break;
  177428. default:
  177429. png_error(png_ptr, "Invalid image color type specified");
  177430. }
  177431. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177432. {
  177433. png_warning(png_ptr, "Invalid compression type specified");
  177434. compression_type = PNG_COMPRESSION_TYPE_BASE;
  177435. }
  177436. if (
  177437. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177438. !((png_ptr->mng_features_permitted & PNG_FLAG_MNG_FILTER_64) &&
  177439. ((png_ptr->mode&PNG_HAVE_PNG_SIGNATURE) == 0) &&
  177440. (color_type == PNG_COLOR_TYPE_RGB ||
  177441. color_type == PNG_COLOR_TYPE_RGB_ALPHA) &&
  177442. (filter_type == PNG_INTRAPIXEL_DIFFERENCING)) &&
  177443. #endif
  177444. filter_type != PNG_FILTER_TYPE_BASE)
  177445. {
  177446. png_warning(png_ptr, "Invalid filter type specified");
  177447. filter_type = PNG_FILTER_TYPE_BASE;
  177448. }
  177449. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  177450. if (interlace_type != PNG_INTERLACE_NONE &&
  177451. interlace_type != PNG_INTERLACE_ADAM7)
  177452. {
  177453. png_warning(png_ptr, "Invalid interlace type specified");
  177454. interlace_type = PNG_INTERLACE_ADAM7;
  177455. }
  177456. #else
  177457. interlace_type=PNG_INTERLACE_NONE;
  177458. #endif
  177459. png_ptr->bit_depth = (png_byte)bit_depth;
  177460. png_ptr->color_type = (png_byte)color_type;
  177461. png_ptr->interlaced = (png_byte)interlace_type;
  177462. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177463. png_ptr->filter_type = (png_byte)filter_type;
  177464. #endif
  177465. png_ptr->compression_type = (png_byte)compression_type;
  177466. png_ptr->width = width;
  177467. png_ptr->height = height;
  177468. png_ptr->pixel_depth = (png_byte)(bit_depth * png_ptr->channels);
  177469. png_ptr->rowbytes = PNG_ROWBYTES(png_ptr->pixel_depth, width);
  177470. png_ptr->usr_width = png_ptr->width;
  177471. png_ptr->usr_bit_depth = png_ptr->bit_depth;
  177472. png_ptr->usr_channels = png_ptr->channels;
  177473. png_save_uint_32(buf, width);
  177474. png_save_uint_32(buf + 4, height);
  177475. buf[8] = (png_byte)bit_depth;
  177476. buf[9] = (png_byte)color_type;
  177477. buf[10] = (png_byte)compression_type;
  177478. buf[11] = (png_byte)filter_type;
  177479. buf[12] = (png_byte)interlace_type;
  177480. png_write_chunk(png_ptr, png_IHDR, buf, (png_size_t)13);
  177481. png_ptr->zstream.zalloc = png_zalloc;
  177482. png_ptr->zstream.zfree = png_zfree;
  177483. png_ptr->zstream.opaque = (voidpf)png_ptr;
  177484. if (!(png_ptr->do_filter))
  177485. {
  177486. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE ||
  177487. png_ptr->bit_depth < 8)
  177488. png_ptr->do_filter = PNG_FILTER_NONE;
  177489. else
  177490. png_ptr->do_filter = PNG_ALL_FILTERS;
  177491. }
  177492. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_STRATEGY))
  177493. {
  177494. if (png_ptr->do_filter != PNG_FILTER_NONE)
  177495. png_ptr->zlib_strategy = Z_FILTERED;
  177496. else
  177497. png_ptr->zlib_strategy = Z_DEFAULT_STRATEGY;
  177498. }
  177499. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_LEVEL))
  177500. png_ptr->zlib_level = Z_DEFAULT_COMPRESSION;
  177501. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_MEM_LEVEL))
  177502. png_ptr->zlib_mem_level = 8;
  177503. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_WINDOW_BITS))
  177504. png_ptr->zlib_window_bits = 15;
  177505. if (!(png_ptr->flags & PNG_FLAG_ZLIB_CUSTOM_METHOD))
  177506. png_ptr->zlib_method = 8;
  177507. if (deflateInit2(&png_ptr->zstream, png_ptr->zlib_level,
  177508. png_ptr->zlib_method, png_ptr->zlib_window_bits,
  177509. png_ptr->zlib_mem_level, png_ptr->zlib_strategy) != Z_OK)
  177510. png_error(png_ptr, "zlib failed to initialize compressor");
  177511. png_ptr->zstream.next_out = png_ptr->zbuf;
  177512. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  177513. png_ptr->zstream.data_type = Z_BINARY;
  177514. png_ptr->mode = PNG_HAVE_IHDR;
  177515. }
  177516. void /* PRIVATE */
  177517. png_write_PLTE(png_structp png_ptr, png_colorp palette, png_uint_32 num_pal)
  177518. {
  177519. #ifdef PNG_USE_LOCAL_ARRAYS
  177520. PNG_PLTE;
  177521. #endif
  177522. png_uint_32 i;
  177523. png_colorp pal_ptr;
  177524. png_byte buf[3];
  177525. png_debug(1, "in png_write_PLTE\n");
  177526. if ((
  177527. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  177528. !(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE) &&
  177529. #endif
  177530. num_pal == 0) || num_pal > 256)
  177531. {
  177532. if (png_ptr->color_type == PNG_COLOR_TYPE_PALETTE)
  177533. {
  177534. png_error(png_ptr, "Invalid number of colors in palette");
  177535. }
  177536. else
  177537. {
  177538. png_warning(png_ptr, "Invalid number of colors in palette");
  177539. return;
  177540. }
  177541. }
  177542. if (!(png_ptr->color_type&PNG_COLOR_MASK_COLOR))
  177543. {
  177544. png_warning(png_ptr,
  177545. "Ignoring request to write a PLTE chunk in grayscale PNG");
  177546. return;
  177547. }
  177548. png_ptr->num_palette = (png_uint_16)num_pal;
  177549. png_debug1(3, "num_palette = %d\n", png_ptr->num_palette);
  177550. png_write_chunk_start(png_ptr, png_PLTE, num_pal * 3);
  177551. #ifndef PNG_NO_POINTER_INDEXING
  177552. for (i = 0, pal_ptr = palette; i < num_pal; i++, pal_ptr++)
  177553. {
  177554. buf[0] = pal_ptr->red;
  177555. buf[1] = pal_ptr->green;
  177556. buf[2] = pal_ptr->blue;
  177557. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177558. }
  177559. #else
  177560. pal_ptr=palette;
  177561. for (i = 0; i < num_pal; i++)
  177562. {
  177563. buf[0] = pal_ptr[i].red;
  177564. buf[1] = pal_ptr[i].green;
  177565. buf[2] = pal_ptr[i].blue;
  177566. png_write_chunk_data(png_ptr, buf, (png_size_t)3);
  177567. }
  177568. #endif
  177569. png_write_chunk_end(png_ptr);
  177570. png_ptr->mode |= PNG_HAVE_PLTE;
  177571. }
  177572. void /* PRIVATE */
  177573. png_write_IDAT(png_structp png_ptr, png_bytep data, png_size_t length)
  177574. {
  177575. #ifdef PNG_USE_LOCAL_ARRAYS
  177576. PNG_IDAT;
  177577. #endif
  177578. png_debug(1, "in png_write_IDAT\n");
  177579. if (!(png_ptr->mode & PNG_HAVE_IDAT) &&
  177580. png_ptr->compression_type == PNG_COMPRESSION_TYPE_BASE)
  177581. {
  177582. unsigned int z_cmf = data[0]; /* zlib compression method and flags */
  177583. if ((z_cmf & 0x0f) == 8 && (z_cmf & 0xf0) <= 0x70)
  177584. {
  177585. if (length >= 2 &&
  177586. png_ptr->height < 16384 && png_ptr->width < 16384)
  177587. {
  177588. png_uint_32 uncompressed_idat_size = png_ptr->height *
  177589. ((png_ptr->width *
  177590. png_ptr->channels * png_ptr->bit_depth + 15) >> 3);
  177591. unsigned int z_cinfo = z_cmf >> 4;
  177592. unsigned int half_z_window_size = 1 << (z_cinfo + 7);
  177593. while (uncompressed_idat_size <= half_z_window_size &&
  177594. half_z_window_size >= 256)
  177595. {
  177596. z_cinfo--;
  177597. half_z_window_size >>= 1;
  177598. }
  177599. z_cmf = (z_cmf & 0x0f) | (z_cinfo << 4);
  177600. if (data[0] != (png_byte)z_cmf)
  177601. {
  177602. data[0] = (png_byte)z_cmf;
  177603. data[1] &= 0xe0;
  177604. data[1] += (png_byte)(0x1f - ((z_cmf << 8) + data[1]) % 0x1f);
  177605. }
  177606. }
  177607. }
  177608. else
  177609. png_error(png_ptr,
  177610. "Invalid zlib compression method or flags in IDAT");
  177611. }
  177612. png_write_chunk(png_ptr, png_IDAT, data, length);
  177613. png_ptr->mode |= PNG_HAVE_IDAT;
  177614. }
  177615. void /* PRIVATE */
  177616. png_write_IEND(png_structp png_ptr)
  177617. {
  177618. #ifdef PNG_USE_LOCAL_ARRAYS
  177619. PNG_IEND;
  177620. #endif
  177621. png_debug(1, "in png_write_IEND\n");
  177622. png_write_chunk(png_ptr, png_IEND, png_bytep_NULL,
  177623. (png_size_t)0);
  177624. png_ptr->mode |= PNG_HAVE_IEND;
  177625. }
  177626. #if defined(PNG_WRITE_gAMA_SUPPORTED)
  177627. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177628. void /* PRIVATE */
  177629. png_write_gAMA(png_structp png_ptr, double file_gamma)
  177630. {
  177631. #ifdef PNG_USE_LOCAL_ARRAYS
  177632. PNG_gAMA;
  177633. #endif
  177634. png_uint_32 igamma;
  177635. png_byte buf[4];
  177636. png_debug(1, "in png_write_gAMA\n");
  177637. igamma = (png_uint_32)(file_gamma * 100000.0 + 0.5);
  177638. png_save_uint_32(buf, igamma);
  177639. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177640. }
  177641. #endif
  177642. #ifdef PNG_FIXED_POINT_SUPPORTED
  177643. void /* PRIVATE */
  177644. png_write_gAMA_fixed(png_structp png_ptr, png_fixed_point file_gamma)
  177645. {
  177646. #ifdef PNG_USE_LOCAL_ARRAYS
  177647. PNG_gAMA;
  177648. #endif
  177649. png_byte buf[4];
  177650. png_debug(1, "in png_write_gAMA\n");
  177651. png_save_uint_32(buf, (png_uint_32)file_gamma);
  177652. png_write_chunk(png_ptr, png_gAMA, buf, (png_size_t)4);
  177653. }
  177654. #endif
  177655. #endif
  177656. #if defined(PNG_WRITE_sRGB_SUPPORTED)
  177657. void /* PRIVATE */
  177658. png_write_sRGB(png_structp png_ptr, int srgb_intent)
  177659. {
  177660. #ifdef PNG_USE_LOCAL_ARRAYS
  177661. PNG_sRGB;
  177662. #endif
  177663. png_byte buf[1];
  177664. png_debug(1, "in png_write_sRGB\n");
  177665. if(srgb_intent >= PNG_sRGB_INTENT_LAST)
  177666. png_warning(png_ptr,
  177667. "Invalid sRGB rendering intent specified");
  177668. buf[0]=(png_byte)srgb_intent;
  177669. png_write_chunk(png_ptr, png_sRGB, buf, (png_size_t)1);
  177670. }
  177671. #endif
  177672. #if defined(PNG_WRITE_iCCP_SUPPORTED)
  177673. void /* PRIVATE */
  177674. png_write_iCCP(png_structp png_ptr, png_charp name, int compression_type,
  177675. png_charp profile, int profile_len)
  177676. {
  177677. #ifdef PNG_USE_LOCAL_ARRAYS
  177678. PNG_iCCP;
  177679. #endif
  177680. png_size_t name_len;
  177681. png_charp new_name;
  177682. compression_state comp;
  177683. int embedded_profile_len = 0;
  177684. png_debug(1, "in png_write_iCCP\n");
  177685. comp.num_output_ptr = 0;
  177686. comp.max_output_ptr = 0;
  177687. comp.output_ptr = NULL;
  177688. comp.input = NULL;
  177689. comp.input_len = 0;
  177690. if (name == NULL || (name_len = png_check_keyword(png_ptr, name,
  177691. &new_name)) == 0)
  177692. {
  177693. png_warning(png_ptr, "Empty keyword in iCCP chunk");
  177694. return;
  177695. }
  177696. if (compression_type != PNG_COMPRESSION_TYPE_BASE)
  177697. png_warning(png_ptr, "Unknown compression type in iCCP chunk");
  177698. if (profile == NULL)
  177699. profile_len = 0;
  177700. if (profile_len > 3)
  177701. embedded_profile_len =
  177702. ((*( (png_bytep)profile ))<<24) |
  177703. ((*( (png_bytep)profile+1))<<16) |
  177704. ((*( (png_bytep)profile+2))<< 8) |
  177705. ((*( (png_bytep)profile+3)) );
  177706. if (profile_len < embedded_profile_len)
  177707. {
  177708. png_warning(png_ptr,
  177709. "Embedded profile length too large in iCCP chunk");
  177710. return;
  177711. }
  177712. if (profile_len > embedded_profile_len)
  177713. {
  177714. png_warning(png_ptr,
  177715. "Truncating profile to actual length in iCCP chunk");
  177716. profile_len = embedded_profile_len;
  177717. }
  177718. if (profile_len)
  177719. profile_len = png_text_compress(png_ptr, profile, (png_size_t)profile_len,
  177720. PNG_COMPRESSION_TYPE_BASE, &comp);
  177721. png_write_chunk_start(png_ptr, png_iCCP,
  177722. (png_uint_32)name_len+profile_len+2);
  177723. new_name[name_len+1]=0x00;
  177724. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 2);
  177725. if (profile_len)
  177726. png_write_compressed_data_out(png_ptr, &comp);
  177727. png_write_chunk_end(png_ptr);
  177728. png_free(png_ptr, new_name);
  177729. }
  177730. #endif
  177731. #if defined(PNG_WRITE_sPLT_SUPPORTED)
  177732. void /* PRIVATE */
  177733. png_write_sPLT(png_structp png_ptr, png_sPLT_tp spalette)
  177734. {
  177735. #ifdef PNG_USE_LOCAL_ARRAYS
  177736. PNG_sPLT;
  177737. #endif
  177738. png_size_t name_len;
  177739. png_charp new_name;
  177740. png_byte entrybuf[10];
  177741. int entry_size = (spalette->depth == 8 ? 6 : 10);
  177742. int palette_size = entry_size * spalette->nentries;
  177743. png_sPLT_entryp ep;
  177744. #ifdef PNG_NO_POINTER_INDEXING
  177745. int i;
  177746. #endif
  177747. png_debug(1, "in png_write_sPLT\n");
  177748. if (spalette->name == NULL || (name_len = png_check_keyword(png_ptr,
  177749. spalette->name, &new_name))==0)
  177750. {
  177751. png_warning(png_ptr, "Empty keyword in sPLT chunk");
  177752. return;
  177753. }
  177754. png_write_chunk_start(png_ptr, png_sPLT,
  177755. (png_uint_32)(name_len + 2 + palette_size));
  177756. png_write_chunk_data(png_ptr, (png_bytep)new_name, name_len + 1);
  177757. png_write_chunk_data(png_ptr, (png_bytep)&spalette->depth, 1);
  177758. #ifndef PNG_NO_POINTER_INDEXING
  177759. for (ep = spalette->entries; ep<spalette->entries+spalette->nentries; ep++)
  177760. {
  177761. if (spalette->depth == 8)
  177762. {
  177763. entrybuf[0] = (png_byte)ep->red;
  177764. entrybuf[1] = (png_byte)ep->green;
  177765. entrybuf[2] = (png_byte)ep->blue;
  177766. entrybuf[3] = (png_byte)ep->alpha;
  177767. png_save_uint_16(entrybuf + 4, ep->frequency);
  177768. }
  177769. else
  177770. {
  177771. png_save_uint_16(entrybuf + 0, ep->red);
  177772. png_save_uint_16(entrybuf + 2, ep->green);
  177773. png_save_uint_16(entrybuf + 4, ep->blue);
  177774. png_save_uint_16(entrybuf + 6, ep->alpha);
  177775. png_save_uint_16(entrybuf + 8, ep->frequency);
  177776. }
  177777. png_write_chunk_data(png_ptr, entrybuf, (png_size_t)entry_size);
  177778. }
  177779. #else
  177780. ep=spalette->entries;
  177781. for (i=0; i>spalette->nentries; i++)
  177782. {
  177783. if (spalette->depth == 8)
  177784. {
  177785. entrybuf[0] = (png_byte)ep[i].red;
  177786. entrybuf[1] = (png_byte)ep[i].green;
  177787. entrybuf[2] = (png_byte)ep[i].blue;
  177788. entrybuf[3] = (png_byte)ep[i].alpha;
  177789. png_save_uint_16(entrybuf + 4, ep[i].frequency);
  177790. }
  177791. else
  177792. {
  177793. png_save_uint_16(entrybuf + 0, ep[i].red);
  177794. png_save_uint_16(entrybuf + 2, ep[i].green);
  177795. png_save_uint_16(entrybuf + 4, ep[i].blue);
  177796. png_save_uint_16(entrybuf + 6, ep[i].alpha);
  177797. png_save_uint_16(entrybuf + 8, ep[i].frequency);
  177798. }
  177799. png_write_chunk_data(png_ptr, entrybuf, entry_size);
  177800. }
  177801. #endif
  177802. png_write_chunk_end(png_ptr);
  177803. png_free(png_ptr, new_name);
  177804. }
  177805. #endif
  177806. #if defined(PNG_WRITE_sBIT_SUPPORTED)
  177807. void /* PRIVATE */
  177808. png_write_sBIT(png_structp png_ptr, png_color_8p sbit, int color_type)
  177809. {
  177810. #ifdef PNG_USE_LOCAL_ARRAYS
  177811. PNG_sBIT;
  177812. #endif
  177813. png_byte buf[4];
  177814. png_size_t size;
  177815. png_debug(1, "in png_write_sBIT\n");
  177816. if (color_type & PNG_COLOR_MASK_COLOR)
  177817. {
  177818. png_byte maxbits;
  177819. maxbits = (png_byte)(color_type==PNG_COLOR_TYPE_PALETTE ? 8 :
  177820. png_ptr->usr_bit_depth);
  177821. if (sbit->red == 0 || sbit->red > maxbits ||
  177822. sbit->green == 0 || sbit->green > maxbits ||
  177823. sbit->blue == 0 || sbit->blue > maxbits)
  177824. {
  177825. png_warning(png_ptr, "Invalid sBIT depth specified");
  177826. return;
  177827. }
  177828. buf[0] = sbit->red;
  177829. buf[1] = sbit->green;
  177830. buf[2] = sbit->blue;
  177831. size = 3;
  177832. }
  177833. else
  177834. {
  177835. if (sbit->gray == 0 || sbit->gray > png_ptr->usr_bit_depth)
  177836. {
  177837. png_warning(png_ptr, "Invalid sBIT depth specified");
  177838. return;
  177839. }
  177840. buf[0] = sbit->gray;
  177841. size = 1;
  177842. }
  177843. if (color_type & PNG_COLOR_MASK_ALPHA)
  177844. {
  177845. if (sbit->alpha == 0 || sbit->alpha > png_ptr->usr_bit_depth)
  177846. {
  177847. png_warning(png_ptr, "Invalid sBIT depth specified");
  177848. return;
  177849. }
  177850. buf[size++] = sbit->alpha;
  177851. }
  177852. png_write_chunk(png_ptr, png_sBIT, buf, size);
  177853. }
  177854. #endif
  177855. #if defined(PNG_WRITE_cHRM_SUPPORTED)
  177856. #ifdef PNG_FLOATING_POINT_SUPPORTED
  177857. void /* PRIVATE */
  177858. png_write_cHRM(png_structp png_ptr, double white_x, double white_y,
  177859. double red_x, double red_y, double green_x, double green_y,
  177860. double blue_x, double blue_y)
  177861. {
  177862. #ifdef PNG_USE_LOCAL_ARRAYS
  177863. PNG_cHRM;
  177864. #endif
  177865. png_byte buf[32];
  177866. png_uint_32 itemp;
  177867. png_debug(1, "in png_write_cHRM\n");
  177868. if (white_x < 0 || white_x > 0.8 || white_y < 0 || white_y > 0.8 ||
  177869. white_x + white_y > 1.0)
  177870. {
  177871. png_warning(png_ptr, "Invalid cHRM white point specified");
  177872. #if !defined(PNG_NO_CONSOLE_IO)
  177873. fprintf(stderr,"white_x=%f, white_y=%f\n",white_x, white_y);
  177874. #endif
  177875. return;
  177876. }
  177877. itemp = (png_uint_32)(white_x * 100000.0 + 0.5);
  177878. png_save_uint_32(buf, itemp);
  177879. itemp = (png_uint_32)(white_y * 100000.0 + 0.5);
  177880. png_save_uint_32(buf + 4, itemp);
  177881. if (red_x < 0 || red_y < 0 || red_x + red_y > 1.0)
  177882. {
  177883. png_warning(png_ptr, "Invalid cHRM red point specified");
  177884. return;
  177885. }
  177886. itemp = (png_uint_32)(red_x * 100000.0 + 0.5);
  177887. png_save_uint_32(buf + 8, itemp);
  177888. itemp = (png_uint_32)(red_y * 100000.0 + 0.5);
  177889. png_save_uint_32(buf + 12, itemp);
  177890. if (green_x < 0 || green_y < 0 || green_x + green_y > 1.0)
  177891. {
  177892. png_warning(png_ptr, "Invalid cHRM green point specified");
  177893. return;
  177894. }
  177895. itemp = (png_uint_32)(green_x * 100000.0 + 0.5);
  177896. png_save_uint_32(buf + 16, itemp);
  177897. itemp = (png_uint_32)(green_y * 100000.0 + 0.5);
  177898. png_save_uint_32(buf + 20, itemp);
  177899. if (blue_x < 0 || blue_y < 0 || blue_x + blue_y > 1.0)
  177900. {
  177901. png_warning(png_ptr, "Invalid cHRM blue point specified");
  177902. return;
  177903. }
  177904. itemp = (png_uint_32)(blue_x * 100000.0 + 0.5);
  177905. png_save_uint_32(buf + 24, itemp);
  177906. itemp = (png_uint_32)(blue_y * 100000.0 + 0.5);
  177907. png_save_uint_32(buf + 28, itemp);
  177908. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177909. }
  177910. #endif
  177911. #ifdef PNG_FIXED_POINT_SUPPORTED
  177912. void /* PRIVATE */
  177913. png_write_cHRM_fixed(png_structp png_ptr, png_fixed_point white_x,
  177914. png_fixed_point white_y, png_fixed_point red_x, png_fixed_point red_y,
  177915. png_fixed_point green_x, png_fixed_point green_y, png_fixed_point blue_x,
  177916. png_fixed_point blue_y)
  177917. {
  177918. #ifdef PNG_USE_LOCAL_ARRAYS
  177919. PNG_cHRM;
  177920. #endif
  177921. png_byte buf[32];
  177922. png_debug(1, "in png_write_cHRM\n");
  177923. if (white_x > 80000L || white_y > 80000L || white_x + white_y > 100000L)
  177924. {
  177925. png_warning(png_ptr, "Invalid fixed cHRM white point specified");
  177926. #if !defined(PNG_NO_CONSOLE_IO)
  177927. fprintf(stderr,"white_x=%ld, white_y=%ld\n",white_x, white_y);
  177928. #endif
  177929. return;
  177930. }
  177931. png_save_uint_32(buf, (png_uint_32)white_x);
  177932. png_save_uint_32(buf + 4, (png_uint_32)white_y);
  177933. if (red_x + red_y > 100000L)
  177934. {
  177935. png_warning(png_ptr, "Invalid cHRM fixed red point specified");
  177936. return;
  177937. }
  177938. png_save_uint_32(buf + 8, (png_uint_32)red_x);
  177939. png_save_uint_32(buf + 12, (png_uint_32)red_y);
  177940. if (green_x + green_y > 100000L)
  177941. {
  177942. png_warning(png_ptr, "Invalid fixed cHRM green point specified");
  177943. return;
  177944. }
  177945. png_save_uint_32(buf + 16, (png_uint_32)green_x);
  177946. png_save_uint_32(buf + 20, (png_uint_32)green_y);
  177947. if (blue_x + blue_y > 100000L)
  177948. {
  177949. png_warning(png_ptr, "Invalid fixed cHRM blue point specified");
  177950. return;
  177951. }
  177952. png_save_uint_32(buf + 24, (png_uint_32)blue_x);
  177953. png_save_uint_32(buf + 28, (png_uint_32)blue_y);
  177954. png_write_chunk(png_ptr, png_cHRM, buf, (png_size_t)32);
  177955. }
  177956. #endif
  177957. #endif
  177958. #if defined(PNG_WRITE_tRNS_SUPPORTED)
  177959. void /* PRIVATE */
  177960. png_write_tRNS(png_structp png_ptr, png_bytep trans, png_color_16p tran,
  177961. int num_trans, int color_type)
  177962. {
  177963. #ifdef PNG_USE_LOCAL_ARRAYS
  177964. PNG_tRNS;
  177965. #endif
  177966. png_byte buf[6];
  177967. png_debug(1, "in png_write_tRNS\n");
  177968. if (color_type == PNG_COLOR_TYPE_PALETTE)
  177969. {
  177970. if (num_trans <= 0 || num_trans > (int)png_ptr->num_palette)
  177971. {
  177972. png_warning(png_ptr,"Invalid number of transparent colors specified");
  177973. return;
  177974. }
  177975. png_write_chunk(png_ptr, png_tRNS, trans, (png_size_t)num_trans);
  177976. }
  177977. else if (color_type == PNG_COLOR_TYPE_GRAY)
  177978. {
  177979. if(tran->gray >= (1 << png_ptr->bit_depth))
  177980. {
  177981. png_warning(png_ptr,
  177982. "Ignoring attempt to write tRNS chunk out-of-range for bit_depth");
  177983. return;
  177984. }
  177985. png_save_uint_16(buf, tran->gray);
  177986. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)2);
  177987. }
  177988. else if (color_type == PNG_COLOR_TYPE_RGB)
  177989. {
  177990. png_save_uint_16(buf, tran->red);
  177991. png_save_uint_16(buf + 2, tran->green);
  177992. png_save_uint_16(buf + 4, tran->blue);
  177993. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  177994. {
  177995. png_warning(png_ptr,
  177996. "Ignoring attempt to write 16-bit tRNS chunk when bit_depth is 8");
  177997. return;
  177998. }
  177999. png_write_chunk(png_ptr, png_tRNS, buf, (png_size_t)6);
  178000. }
  178001. else
  178002. {
  178003. png_warning(png_ptr, "Can't write tRNS with an alpha channel");
  178004. }
  178005. }
  178006. #endif
  178007. #if defined(PNG_WRITE_bKGD_SUPPORTED)
  178008. void /* PRIVATE */
  178009. png_write_bKGD(png_structp png_ptr, png_color_16p back, int color_type)
  178010. {
  178011. #ifdef PNG_USE_LOCAL_ARRAYS
  178012. PNG_bKGD;
  178013. #endif
  178014. png_byte buf[6];
  178015. png_debug(1, "in png_write_bKGD\n");
  178016. if (color_type == PNG_COLOR_TYPE_PALETTE)
  178017. {
  178018. if (
  178019. #if defined(PNG_MNG_FEATURES_SUPPORTED)
  178020. (png_ptr->num_palette ||
  178021. (!(png_ptr->mng_features_permitted & PNG_FLAG_MNG_EMPTY_PLTE))) &&
  178022. #endif
  178023. back->index > png_ptr->num_palette)
  178024. {
  178025. png_warning(png_ptr, "Invalid background palette index");
  178026. return;
  178027. }
  178028. buf[0] = back->index;
  178029. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)1);
  178030. }
  178031. else if (color_type & PNG_COLOR_MASK_COLOR)
  178032. {
  178033. png_save_uint_16(buf, back->red);
  178034. png_save_uint_16(buf + 2, back->green);
  178035. png_save_uint_16(buf + 4, back->blue);
  178036. if(png_ptr->bit_depth == 8 && (buf[0] | buf[2] | buf[4]))
  178037. {
  178038. png_warning(png_ptr,
  178039. "Ignoring attempt to write 16-bit bKGD chunk when bit_depth is 8");
  178040. return;
  178041. }
  178042. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)6);
  178043. }
  178044. else
  178045. {
  178046. if(back->gray >= (1 << png_ptr->bit_depth))
  178047. {
  178048. png_warning(png_ptr,
  178049. "Ignoring attempt to write bKGD chunk out-of-range for bit_depth");
  178050. return;
  178051. }
  178052. png_save_uint_16(buf, back->gray);
  178053. png_write_chunk(png_ptr, png_bKGD, buf, (png_size_t)2);
  178054. }
  178055. }
  178056. #endif
  178057. #if defined(PNG_WRITE_hIST_SUPPORTED)
  178058. void /* PRIVATE */
  178059. png_write_hIST(png_structp png_ptr, png_uint_16p hist, int num_hist)
  178060. {
  178061. #ifdef PNG_USE_LOCAL_ARRAYS
  178062. PNG_hIST;
  178063. #endif
  178064. int i;
  178065. png_byte buf[3];
  178066. png_debug(1, "in png_write_hIST\n");
  178067. if (num_hist > (int)png_ptr->num_palette)
  178068. {
  178069. png_debug2(3, "num_hist = %d, num_palette = %d\n", num_hist,
  178070. png_ptr->num_palette);
  178071. png_warning(png_ptr, "Invalid number of histogram entries specified");
  178072. return;
  178073. }
  178074. png_write_chunk_start(png_ptr, png_hIST, (png_uint_32)(num_hist * 2));
  178075. for (i = 0; i < num_hist; i++)
  178076. {
  178077. png_save_uint_16(buf, hist[i]);
  178078. png_write_chunk_data(png_ptr, buf, (png_size_t)2);
  178079. }
  178080. png_write_chunk_end(png_ptr);
  178081. }
  178082. #endif
  178083. #if defined(PNG_WRITE_TEXT_SUPPORTED) || defined(PNG_WRITE_pCAL_SUPPORTED) || \
  178084. defined(PNG_WRITE_iCCP_SUPPORTED) || defined(PNG_WRITE_sPLT_SUPPORTED)
  178085. png_size_t /* PRIVATE */
  178086. png_check_keyword(png_structp png_ptr, png_charp key, png_charpp new_key)
  178087. {
  178088. png_size_t key_len;
  178089. png_charp kp, dp;
  178090. int kflag;
  178091. int kwarn=0;
  178092. png_debug(1, "in png_check_keyword\n");
  178093. *new_key = NULL;
  178094. if (key == NULL || (key_len = png_strlen(key)) == 0)
  178095. {
  178096. png_warning(png_ptr, "zero length keyword");
  178097. return ((png_size_t)0);
  178098. }
  178099. png_debug1(2, "Keyword to be checked is '%s'\n", key);
  178100. *new_key = (png_charp)png_malloc_warn(png_ptr, (png_uint_32)(key_len + 2));
  178101. if (*new_key == NULL)
  178102. {
  178103. png_warning(png_ptr, "Out of memory while procesing keyword");
  178104. return ((png_size_t)0);
  178105. }
  178106. for (kp = key, dp = *new_key; *kp != '\0'; kp++, dp++)
  178107. {
  178108. if ((png_byte)*kp < 0x20 ||
  178109. ((png_byte)*kp > 0x7E && (png_byte)*kp < 0xA1))
  178110. {
  178111. #if !defined(PNG_NO_STDIO) && !defined(_WIN32_WCE)
  178112. char msg[40];
  178113. png_snprintf(msg, 40,
  178114. "invalid keyword character 0x%02X", (png_byte)*kp);
  178115. png_warning(png_ptr, msg);
  178116. #else
  178117. png_warning(png_ptr, "invalid character in keyword");
  178118. #endif
  178119. *dp = ' ';
  178120. }
  178121. else
  178122. {
  178123. *dp = *kp;
  178124. }
  178125. }
  178126. *dp = '\0';
  178127. kp = *new_key + key_len - 1;
  178128. if (*kp == ' ')
  178129. {
  178130. png_warning(png_ptr, "trailing spaces removed from keyword");
  178131. while (*kp == ' ')
  178132. {
  178133. *(kp--) = '\0';
  178134. key_len--;
  178135. }
  178136. }
  178137. kp = *new_key;
  178138. if (*kp == ' ')
  178139. {
  178140. png_warning(png_ptr, "leading spaces removed from keyword");
  178141. while (*kp == ' ')
  178142. {
  178143. kp++;
  178144. key_len--;
  178145. }
  178146. }
  178147. png_debug1(2, "Checking for multiple internal spaces in '%s'\n", kp);
  178148. for (kflag = 0, dp = *new_key; *kp != '\0'; kp++)
  178149. {
  178150. if (*kp == ' ' && kflag == 0)
  178151. {
  178152. *(dp++) = *kp;
  178153. kflag = 1;
  178154. }
  178155. else if (*kp == ' ')
  178156. {
  178157. key_len--;
  178158. kwarn=1;
  178159. }
  178160. else
  178161. {
  178162. *(dp++) = *kp;
  178163. kflag = 0;
  178164. }
  178165. }
  178166. *dp = '\0';
  178167. if(kwarn)
  178168. png_warning(png_ptr, "extra interior spaces removed from keyword");
  178169. if (key_len == 0)
  178170. {
  178171. png_free(png_ptr, *new_key);
  178172. *new_key=NULL;
  178173. png_warning(png_ptr, "Zero length keyword");
  178174. }
  178175. if (key_len > 79)
  178176. {
  178177. png_warning(png_ptr, "keyword length must be 1 - 79 characters");
  178178. new_key[79] = '\0';
  178179. key_len = 79;
  178180. }
  178181. return (key_len);
  178182. }
  178183. #endif
  178184. #if defined(PNG_WRITE_tEXt_SUPPORTED)
  178185. void /* PRIVATE */
  178186. png_write_tEXt(png_structp png_ptr, png_charp key, png_charp text,
  178187. png_size_t text_len)
  178188. {
  178189. #ifdef PNG_USE_LOCAL_ARRAYS
  178190. PNG_tEXt;
  178191. #endif
  178192. png_size_t key_len;
  178193. png_charp new_key;
  178194. png_debug(1, "in png_write_tEXt\n");
  178195. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178196. {
  178197. png_warning(png_ptr, "Empty keyword in tEXt chunk");
  178198. return;
  178199. }
  178200. if (text == NULL || *text == '\0')
  178201. text_len = 0;
  178202. else
  178203. text_len = png_strlen(text);
  178204. png_write_chunk_start(png_ptr, png_tEXt, (png_uint_32)key_len+text_len+1);
  178205. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178206. if (text_len)
  178207. png_write_chunk_data(png_ptr, (png_bytep)text, text_len);
  178208. png_write_chunk_end(png_ptr);
  178209. png_free(png_ptr, new_key);
  178210. }
  178211. #endif
  178212. #if defined(PNG_WRITE_zTXt_SUPPORTED)
  178213. void /* PRIVATE */
  178214. png_write_zTXt(png_structp png_ptr, png_charp key, png_charp text,
  178215. png_size_t text_len, int compression)
  178216. {
  178217. #ifdef PNG_USE_LOCAL_ARRAYS
  178218. PNG_zTXt;
  178219. #endif
  178220. png_size_t key_len;
  178221. char buf[1];
  178222. png_charp new_key;
  178223. compression_state comp;
  178224. png_debug(1, "in png_write_zTXt\n");
  178225. comp.num_output_ptr = 0;
  178226. comp.max_output_ptr = 0;
  178227. comp.output_ptr = NULL;
  178228. comp.input = NULL;
  178229. comp.input_len = 0;
  178230. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178231. {
  178232. png_warning(png_ptr, "Empty keyword in zTXt chunk");
  178233. return;
  178234. }
  178235. if (text == NULL || *text == '\0' || compression==PNG_TEXT_COMPRESSION_NONE)
  178236. {
  178237. png_write_tEXt(png_ptr, new_key, text, (png_size_t)0);
  178238. png_free(png_ptr, new_key);
  178239. return;
  178240. }
  178241. text_len = png_strlen(text);
  178242. text_len = png_text_compress(png_ptr, text, text_len, compression,
  178243. &comp);
  178244. png_write_chunk_start(png_ptr, png_zTXt, (png_uint_32)
  178245. (key_len+text_len+2));
  178246. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178247. png_free(png_ptr, new_key);
  178248. buf[0] = (png_byte)compression;
  178249. png_write_chunk_data(png_ptr, (png_bytep)buf, (png_size_t)1);
  178250. png_write_compressed_data_out(png_ptr, &comp);
  178251. png_write_chunk_end(png_ptr);
  178252. }
  178253. #endif
  178254. #if defined(PNG_WRITE_iTXt_SUPPORTED)
  178255. void /* PRIVATE */
  178256. png_write_iTXt(png_structp png_ptr, int compression, png_charp key,
  178257. png_charp lang, png_charp lang_key, png_charp text)
  178258. {
  178259. #ifdef PNG_USE_LOCAL_ARRAYS
  178260. PNG_iTXt;
  178261. #endif
  178262. png_size_t lang_len, key_len, lang_key_len, text_len;
  178263. png_charp new_lang, new_key;
  178264. png_byte cbuf[2];
  178265. compression_state comp;
  178266. png_debug(1, "in png_write_iTXt\n");
  178267. comp.num_output_ptr = 0;
  178268. comp.max_output_ptr = 0;
  178269. comp.output_ptr = NULL;
  178270. comp.input = NULL;
  178271. if (key == NULL || (key_len = png_check_keyword(png_ptr, key, &new_key))==0)
  178272. {
  178273. png_warning(png_ptr, "Empty keyword in iTXt chunk");
  178274. return;
  178275. }
  178276. if (lang == NULL || (lang_len = png_check_keyword(png_ptr, lang, &new_lang))==0)
  178277. {
  178278. png_warning(png_ptr, "Empty language field in iTXt chunk");
  178279. new_lang = NULL;
  178280. lang_len = 0;
  178281. }
  178282. if (lang_key == NULL)
  178283. lang_key_len = 0;
  178284. else
  178285. lang_key_len = png_strlen(lang_key);
  178286. if (text == NULL)
  178287. text_len = 0;
  178288. else
  178289. text_len = png_strlen(text);
  178290. text_len = png_text_compress(png_ptr, text, text_len, compression-2,
  178291. &comp);
  178292. png_write_chunk_start(png_ptr, png_iTXt,
  178293. (png_uint_32)(
  178294. 5 /* comp byte, comp flag, terminators for key, lang and lang_key */
  178295. + key_len
  178296. + lang_len
  178297. + lang_key_len
  178298. + text_len));
  178299. png_write_chunk_data(png_ptr, (png_bytep)new_key, key_len + 1);
  178300. if (compression == PNG_ITXT_COMPRESSION_NONE || \
  178301. compression == PNG_TEXT_COMPRESSION_NONE)
  178302. cbuf[0] = 0;
  178303. else /* compression == PNG_ITXT_COMPRESSION_zTXt */
  178304. cbuf[0] = 1;
  178305. cbuf[1] = 0;
  178306. png_write_chunk_data(png_ptr, cbuf, 2);
  178307. cbuf[0] = 0;
  178308. png_write_chunk_data(png_ptr, (new_lang ? (png_bytep)new_lang : cbuf), lang_len + 1);
  178309. png_write_chunk_data(png_ptr, (lang_key ? (png_bytep)lang_key : cbuf), lang_key_len + 1);
  178310. png_write_compressed_data_out(png_ptr, &comp);
  178311. png_write_chunk_end(png_ptr);
  178312. png_free(png_ptr, new_key);
  178313. if (new_lang)
  178314. png_free(png_ptr, new_lang);
  178315. }
  178316. #endif
  178317. #if defined(PNG_WRITE_oFFs_SUPPORTED)
  178318. void /* PRIVATE */
  178319. png_write_oFFs(png_structp png_ptr, png_int_32 x_offset, png_int_32 y_offset,
  178320. int unit_type)
  178321. {
  178322. #ifdef PNG_USE_LOCAL_ARRAYS
  178323. PNG_oFFs;
  178324. #endif
  178325. png_byte buf[9];
  178326. png_debug(1, "in png_write_oFFs\n");
  178327. if (unit_type >= PNG_OFFSET_LAST)
  178328. png_warning(png_ptr, "Unrecognized unit type for oFFs chunk");
  178329. png_save_int_32(buf, x_offset);
  178330. png_save_int_32(buf + 4, y_offset);
  178331. buf[8] = (png_byte)unit_type;
  178332. png_write_chunk(png_ptr, png_oFFs, buf, (png_size_t)9);
  178333. }
  178334. #endif
  178335. #if defined(PNG_WRITE_pCAL_SUPPORTED)
  178336. void /* PRIVATE */
  178337. png_write_pCAL(png_structp png_ptr, png_charp purpose, png_int_32 X0,
  178338. png_int_32 X1, int type, int nparams, png_charp units, png_charpp params)
  178339. {
  178340. #ifdef PNG_USE_LOCAL_ARRAYS
  178341. PNG_pCAL;
  178342. #endif
  178343. png_size_t purpose_len, units_len, total_len;
  178344. png_uint_32p params_len;
  178345. png_byte buf[10];
  178346. png_charp new_purpose;
  178347. int i;
  178348. png_debug1(1, "in png_write_pCAL (%d parameters)\n", nparams);
  178349. if (type >= PNG_EQUATION_LAST)
  178350. png_warning(png_ptr, "Unrecognized equation type for pCAL chunk");
  178351. purpose_len = png_check_keyword(png_ptr, purpose, &new_purpose) + 1;
  178352. png_debug1(3, "pCAL purpose length = %d\n", (int)purpose_len);
  178353. units_len = png_strlen(units) + (nparams == 0 ? 0 : 1);
  178354. png_debug1(3, "pCAL units length = %d\n", (int)units_len);
  178355. total_len = purpose_len + units_len + 10;
  178356. params_len = (png_uint_32p)png_malloc(png_ptr, (png_uint_32)(nparams
  178357. *png_sizeof(png_uint_32)));
  178358. for (i = 0; i < nparams; i++)
  178359. {
  178360. params_len[i] = png_strlen(params[i]) + (i == nparams - 1 ? 0 : 1);
  178361. png_debug2(3, "pCAL parameter %d length = %lu\n", i, params_len[i]);
  178362. total_len += (png_size_t)params_len[i];
  178363. }
  178364. png_debug1(3, "pCAL total length = %d\n", (int)total_len);
  178365. png_write_chunk_start(png_ptr, png_pCAL, (png_uint_32)total_len);
  178366. png_write_chunk_data(png_ptr, (png_bytep)new_purpose, purpose_len);
  178367. png_save_int_32(buf, X0);
  178368. png_save_int_32(buf + 4, X1);
  178369. buf[8] = (png_byte)type;
  178370. buf[9] = (png_byte)nparams;
  178371. png_write_chunk_data(png_ptr, buf, (png_size_t)10);
  178372. png_write_chunk_data(png_ptr, (png_bytep)units, (png_size_t)units_len);
  178373. png_free(png_ptr, new_purpose);
  178374. for (i = 0; i < nparams; i++)
  178375. {
  178376. png_write_chunk_data(png_ptr, (png_bytep)params[i],
  178377. (png_size_t)params_len[i]);
  178378. }
  178379. png_free(png_ptr, params_len);
  178380. png_write_chunk_end(png_ptr);
  178381. }
  178382. #endif
  178383. #if defined(PNG_WRITE_sCAL_SUPPORTED)
  178384. #if defined(PNG_FLOATING_POINT_SUPPORTED) && !defined(PNG_NO_STDIO)
  178385. void /* PRIVATE */
  178386. png_write_sCAL(png_structp png_ptr, int unit, double width, double height)
  178387. {
  178388. #ifdef PNG_USE_LOCAL_ARRAYS
  178389. PNG_sCAL;
  178390. #endif
  178391. char buf[64];
  178392. png_size_t total_len;
  178393. png_debug(1, "in png_write_sCAL\n");
  178394. buf[0] = (char)unit;
  178395. #if defined(_WIN32_WCE)
  178396. {
  178397. wchar_t wc_buf[32];
  178398. size_t wc_len;
  178399. swprintf(wc_buf, TEXT("%12.12e"), width);
  178400. wc_len = wcslen(wc_buf);
  178401. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + 1, wc_len, NULL, NULL);
  178402. total_len = wc_len + 2;
  178403. swprintf(wc_buf, TEXT("%12.12e"), height);
  178404. wc_len = wcslen(wc_buf);
  178405. WideCharToMultiByte(CP_ACP, 0, wc_buf, -1, buf + total_len, wc_len,
  178406. NULL, NULL);
  178407. total_len += wc_len;
  178408. }
  178409. #else
  178410. png_snprintf(buf + 1, 63, "%12.12e", width);
  178411. total_len = 1 + png_strlen(buf + 1) + 1;
  178412. png_snprintf(buf + total_len, 64-total_len, "%12.12e", height);
  178413. total_len += png_strlen(buf + total_len);
  178414. #endif
  178415. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178416. png_write_chunk(png_ptr, png_sCAL, (png_bytep)buf, total_len);
  178417. }
  178418. #else
  178419. #ifdef PNG_FIXED_POINT_SUPPORTED
  178420. void /* PRIVATE */
  178421. png_write_sCAL_s(png_structp png_ptr, int unit, png_charp width,
  178422. png_charp height)
  178423. {
  178424. #ifdef PNG_USE_LOCAL_ARRAYS
  178425. PNG_sCAL;
  178426. #endif
  178427. png_byte buf[64];
  178428. png_size_t wlen, hlen, total_len;
  178429. png_debug(1, "in png_write_sCAL_s\n");
  178430. wlen = png_strlen(width);
  178431. hlen = png_strlen(height);
  178432. total_len = wlen + hlen + 2;
  178433. if (total_len > 64)
  178434. {
  178435. png_warning(png_ptr, "Can't write sCAL (buffer too small)");
  178436. return;
  178437. }
  178438. buf[0] = (png_byte)unit;
  178439. png_memcpy(buf + 1, width, wlen + 1); /* append the '\0' here */
  178440. png_memcpy(buf + wlen + 2, height, hlen); /* do NOT append the '\0' here */
  178441. png_debug1(3, "sCAL total length = %u\n", (unsigned int)total_len);
  178442. png_write_chunk(png_ptr, png_sCAL, buf, total_len);
  178443. }
  178444. #endif
  178445. #endif
  178446. #endif
  178447. #if defined(PNG_WRITE_pHYs_SUPPORTED)
  178448. void /* PRIVATE */
  178449. png_write_pHYs(png_structp png_ptr, png_uint_32 x_pixels_per_unit,
  178450. png_uint_32 y_pixels_per_unit,
  178451. int unit_type)
  178452. {
  178453. #ifdef PNG_USE_LOCAL_ARRAYS
  178454. PNG_pHYs;
  178455. #endif
  178456. png_byte buf[9];
  178457. png_debug(1, "in png_write_pHYs\n");
  178458. if (unit_type >= PNG_RESOLUTION_LAST)
  178459. png_warning(png_ptr, "Unrecognized unit type for pHYs chunk");
  178460. png_save_uint_32(buf, x_pixels_per_unit);
  178461. png_save_uint_32(buf + 4, y_pixels_per_unit);
  178462. buf[8] = (png_byte)unit_type;
  178463. png_write_chunk(png_ptr, png_pHYs, buf, (png_size_t)9);
  178464. }
  178465. #endif
  178466. #if defined(PNG_WRITE_tIME_SUPPORTED)
  178467. void /* PRIVATE */
  178468. png_write_tIME(png_structp png_ptr, png_timep mod_time)
  178469. {
  178470. #ifdef PNG_USE_LOCAL_ARRAYS
  178471. PNG_tIME;
  178472. #endif
  178473. png_byte buf[7];
  178474. png_debug(1, "in png_write_tIME\n");
  178475. if (mod_time->month > 12 || mod_time->month < 1 ||
  178476. mod_time->day > 31 || mod_time->day < 1 ||
  178477. mod_time->hour > 23 || mod_time->second > 60)
  178478. {
  178479. png_warning(png_ptr, "Invalid time specified for tIME chunk");
  178480. return;
  178481. }
  178482. png_save_uint_16(buf, mod_time->year);
  178483. buf[2] = mod_time->month;
  178484. buf[3] = mod_time->day;
  178485. buf[4] = mod_time->hour;
  178486. buf[5] = mod_time->minute;
  178487. buf[6] = mod_time->second;
  178488. png_write_chunk(png_ptr, png_tIME, buf, (png_size_t)7);
  178489. }
  178490. #endif
  178491. void /* PRIVATE */
  178492. png_write_start_row(png_structp png_ptr)
  178493. {
  178494. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178495. #ifdef PNG_USE_LOCAL_ARRAYS
  178496. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178497. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178498. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178499. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178500. #endif
  178501. #endif
  178502. png_size_t buf_size;
  178503. png_debug(1, "in png_write_start_row\n");
  178504. buf_size = (png_size_t)(PNG_ROWBYTES(
  178505. png_ptr->usr_channels*png_ptr->usr_bit_depth,png_ptr->width)+1);
  178506. png_ptr->row_buf = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178507. png_ptr->row_buf[0] = PNG_FILTER_VALUE_NONE;
  178508. #ifndef PNG_NO_WRITE_FILTERING
  178509. if (png_ptr->do_filter & PNG_FILTER_SUB)
  178510. {
  178511. png_ptr->sub_row = (png_bytep)png_malloc(png_ptr,
  178512. (png_ptr->rowbytes + 1));
  178513. png_ptr->sub_row[0] = PNG_FILTER_VALUE_SUB;
  178514. }
  178515. if (png_ptr->do_filter & (PNG_FILTER_AVG | PNG_FILTER_UP | PNG_FILTER_PAETH))
  178516. {
  178517. png_ptr->prev_row = (png_bytep)png_malloc(png_ptr, (png_uint_32)buf_size);
  178518. png_memset(png_ptr->prev_row, 0, buf_size);
  178519. if (png_ptr->do_filter & PNG_FILTER_UP)
  178520. {
  178521. png_ptr->up_row = (png_bytep)png_malloc(png_ptr,
  178522. (png_ptr->rowbytes + 1));
  178523. png_ptr->up_row[0] = PNG_FILTER_VALUE_UP;
  178524. }
  178525. if (png_ptr->do_filter & PNG_FILTER_AVG)
  178526. {
  178527. png_ptr->avg_row = (png_bytep)png_malloc(png_ptr,
  178528. (png_ptr->rowbytes + 1));
  178529. png_ptr->avg_row[0] = PNG_FILTER_VALUE_AVG;
  178530. }
  178531. if (png_ptr->do_filter & PNG_FILTER_PAETH)
  178532. {
  178533. png_ptr->paeth_row = (png_bytep)png_malloc(png_ptr,
  178534. (png_ptr->rowbytes + 1));
  178535. png_ptr->paeth_row[0] = PNG_FILTER_VALUE_PAETH;
  178536. }
  178537. #endif /* PNG_NO_WRITE_FILTERING */
  178538. }
  178539. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178540. if (png_ptr->interlaced)
  178541. {
  178542. if (!(png_ptr->transformations & PNG_INTERLACE))
  178543. {
  178544. png_ptr->num_rows = (png_ptr->height + png_pass_yinc[0] - 1 -
  178545. png_pass_ystart[0]) / png_pass_yinc[0];
  178546. png_ptr->usr_width = (png_ptr->width + png_pass_inc[0] - 1 -
  178547. png_pass_start[0]) / png_pass_inc[0];
  178548. }
  178549. else
  178550. {
  178551. png_ptr->num_rows = png_ptr->height;
  178552. png_ptr->usr_width = png_ptr->width;
  178553. }
  178554. }
  178555. else
  178556. #endif
  178557. {
  178558. png_ptr->num_rows = png_ptr->height;
  178559. png_ptr->usr_width = png_ptr->width;
  178560. }
  178561. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178562. png_ptr->zstream.next_out = png_ptr->zbuf;
  178563. }
  178564. void /* PRIVATE */
  178565. png_write_finish_row(png_structp png_ptr)
  178566. {
  178567. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178568. #ifdef PNG_USE_LOCAL_ARRAYS
  178569. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178570. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178571. int png_pass_ystart[7] = {0, 0, 4, 0, 2, 0, 1};
  178572. int png_pass_yinc[7] = {8, 8, 8, 4, 4, 2, 2};
  178573. #endif
  178574. #endif
  178575. int ret;
  178576. png_debug(1, "in png_write_finish_row\n");
  178577. png_ptr->row_number++;
  178578. if (png_ptr->row_number < png_ptr->num_rows)
  178579. return;
  178580. #ifdef PNG_WRITE_INTERLACING_SUPPORTED
  178581. if (png_ptr->interlaced)
  178582. {
  178583. png_ptr->row_number = 0;
  178584. if (png_ptr->transformations & PNG_INTERLACE)
  178585. {
  178586. png_ptr->pass++;
  178587. }
  178588. else
  178589. {
  178590. do
  178591. {
  178592. png_ptr->pass++;
  178593. if (png_ptr->pass >= 7)
  178594. break;
  178595. png_ptr->usr_width = (png_ptr->width +
  178596. png_pass_inc[png_ptr->pass] - 1 -
  178597. png_pass_start[png_ptr->pass]) /
  178598. png_pass_inc[png_ptr->pass];
  178599. png_ptr->num_rows = (png_ptr->height +
  178600. png_pass_yinc[png_ptr->pass] - 1 -
  178601. png_pass_ystart[png_ptr->pass]) /
  178602. png_pass_yinc[png_ptr->pass];
  178603. if (png_ptr->transformations & PNG_INTERLACE)
  178604. break;
  178605. } while (png_ptr->usr_width == 0 || png_ptr->num_rows == 0);
  178606. }
  178607. if (png_ptr->pass < 7)
  178608. {
  178609. if (png_ptr->prev_row != NULL)
  178610. png_memset(png_ptr->prev_row, 0,
  178611. (png_size_t)(PNG_ROWBYTES(png_ptr->usr_channels*
  178612. png_ptr->usr_bit_depth,png_ptr->width))+1);
  178613. return;
  178614. }
  178615. }
  178616. #endif
  178617. do
  178618. {
  178619. ret = deflate(&png_ptr->zstream, Z_FINISH);
  178620. if (ret == Z_OK)
  178621. {
  178622. if (!(png_ptr->zstream.avail_out))
  178623. {
  178624. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  178625. png_ptr->zstream.next_out = png_ptr->zbuf;
  178626. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  178627. }
  178628. }
  178629. else if (ret != Z_STREAM_END)
  178630. {
  178631. if (png_ptr->zstream.msg != NULL)
  178632. png_error(png_ptr, png_ptr->zstream.msg);
  178633. else
  178634. png_error(png_ptr, "zlib error");
  178635. }
  178636. } while (ret != Z_STREAM_END);
  178637. if (png_ptr->zstream.avail_out < png_ptr->zbuf_size)
  178638. {
  178639. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size -
  178640. png_ptr->zstream.avail_out);
  178641. }
  178642. deflateReset(&png_ptr->zstream);
  178643. png_ptr->zstream.data_type = Z_BINARY;
  178644. }
  178645. #if defined(PNG_WRITE_INTERLACING_SUPPORTED)
  178646. void /* PRIVATE */
  178647. png_do_write_interlace(png_row_infop row_info, png_bytep row, int pass)
  178648. {
  178649. #ifdef PNG_USE_LOCAL_ARRAYS
  178650. int png_pass_start[7] = {0, 4, 0, 2, 0, 1, 0};
  178651. int png_pass_inc[7] = {8, 8, 4, 4, 2, 2, 1};
  178652. #endif
  178653. png_debug(1, "in png_do_write_interlace\n");
  178654. #if defined(PNG_USELESS_TESTS_SUPPORTED)
  178655. if (row != NULL && row_info != NULL && pass < 6)
  178656. #else
  178657. if (pass < 6)
  178658. #endif
  178659. {
  178660. switch (row_info->pixel_depth)
  178661. {
  178662. case 1:
  178663. {
  178664. png_bytep sp;
  178665. png_bytep dp;
  178666. int shift;
  178667. int d;
  178668. int value;
  178669. png_uint_32 i;
  178670. png_uint_32 row_width = row_info->width;
  178671. dp = row;
  178672. d = 0;
  178673. shift = 7;
  178674. for (i = png_pass_start[pass]; i < row_width;
  178675. i += png_pass_inc[pass])
  178676. {
  178677. sp = row + (png_size_t)(i >> 3);
  178678. value = (int)(*sp >> (7 - (int)(i & 0x07))) & 0x01;
  178679. d |= (value << shift);
  178680. if (shift == 0)
  178681. {
  178682. shift = 7;
  178683. *dp++ = (png_byte)d;
  178684. d = 0;
  178685. }
  178686. else
  178687. shift--;
  178688. }
  178689. if (shift != 7)
  178690. *dp = (png_byte)d;
  178691. break;
  178692. }
  178693. case 2:
  178694. {
  178695. png_bytep sp;
  178696. png_bytep dp;
  178697. int shift;
  178698. int d;
  178699. int value;
  178700. png_uint_32 i;
  178701. png_uint_32 row_width = row_info->width;
  178702. dp = row;
  178703. shift = 6;
  178704. d = 0;
  178705. for (i = png_pass_start[pass]; i < row_width;
  178706. i += png_pass_inc[pass])
  178707. {
  178708. sp = row + (png_size_t)(i >> 2);
  178709. value = (*sp >> ((3 - (int)(i & 0x03)) << 1)) & 0x03;
  178710. d |= (value << shift);
  178711. if (shift == 0)
  178712. {
  178713. shift = 6;
  178714. *dp++ = (png_byte)d;
  178715. d = 0;
  178716. }
  178717. else
  178718. shift -= 2;
  178719. }
  178720. if (shift != 6)
  178721. *dp = (png_byte)d;
  178722. break;
  178723. }
  178724. case 4:
  178725. {
  178726. png_bytep sp;
  178727. png_bytep dp;
  178728. int shift;
  178729. int d;
  178730. int value;
  178731. png_uint_32 i;
  178732. png_uint_32 row_width = row_info->width;
  178733. dp = row;
  178734. shift = 4;
  178735. d = 0;
  178736. for (i = png_pass_start[pass]; i < row_width;
  178737. i += png_pass_inc[pass])
  178738. {
  178739. sp = row + (png_size_t)(i >> 1);
  178740. value = (*sp >> ((1 - (int)(i & 0x01)) << 2)) & 0x0f;
  178741. d |= (value << shift);
  178742. if (shift == 0)
  178743. {
  178744. shift = 4;
  178745. *dp++ = (png_byte)d;
  178746. d = 0;
  178747. }
  178748. else
  178749. shift -= 4;
  178750. }
  178751. if (shift != 4)
  178752. *dp = (png_byte)d;
  178753. break;
  178754. }
  178755. default:
  178756. {
  178757. png_bytep sp;
  178758. png_bytep dp;
  178759. png_uint_32 i;
  178760. png_uint_32 row_width = row_info->width;
  178761. png_size_t pixel_bytes;
  178762. dp = row;
  178763. pixel_bytes = (row_info->pixel_depth >> 3);
  178764. for (i = png_pass_start[pass]; i < row_width;
  178765. i += png_pass_inc[pass])
  178766. {
  178767. sp = row + (png_size_t)i * pixel_bytes;
  178768. if (dp != sp)
  178769. png_memcpy(dp, sp, pixel_bytes);
  178770. dp += pixel_bytes;
  178771. }
  178772. break;
  178773. }
  178774. }
  178775. row_info->width = (row_info->width +
  178776. png_pass_inc[pass] - 1 -
  178777. png_pass_start[pass]) /
  178778. png_pass_inc[pass];
  178779. row_info->rowbytes = PNG_ROWBYTES(row_info->pixel_depth,
  178780. row_info->width);
  178781. }
  178782. }
  178783. #endif
  178784. #define PNG_MAXSUM (((png_uint_32)(-1)) >> 1)
  178785. #define PNG_HISHIFT 10
  178786. #define PNG_LOMASK ((png_uint_32)0xffffL)
  178787. #define PNG_HIMASK ((png_uint_32)(~PNG_LOMASK >> PNG_HISHIFT))
  178788. void /* PRIVATE */
  178789. png_write_find_filter(png_structp png_ptr, png_row_infop row_info)
  178790. {
  178791. png_bytep best_row;
  178792. #ifndef PNG_NO_WRITE_FILTER
  178793. png_bytep prev_row, row_buf;
  178794. png_uint_32 mins, bpp;
  178795. png_byte filter_to_do = png_ptr->do_filter;
  178796. png_uint_32 row_bytes = row_info->rowbytes;
  178797. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178798. int num_p_filters = (int)png_ptr->num_prev_filters;
  178799. #endif
  178800. png_debug(1, "in png_write_find_filter\n");
  178801. bpp = (row_info->pixel_depth + 7) >> 3;
  178802. prev_row = png_ptr->prev_row;
  178803. #endif
  178804. best_row = png_ptr->row_buf;
  178805. #ifndef PNG_NO_WRITE_FILTER
  178806. row_buf = best_row;
  178807. mins = PNG_MAXSUM;
  178808. if ((filter_to_do & PNG_FILTER_NONE) &&
  178809. filter_to_do != PNG_FILTER_NONE)
  178810. {
  178811. png_bytep rp;
  178812. png_uint_32 sum = 0;
  178813. png_uint_32 i;
  178814. int v;
  178815. for (i = 0, rp = row_buf + 1; i < row_bytes; i++, rp++)
  178816. {
  178817. v = *rp;
  178818. sum += (v < 128) ? v : 256 - v;
  178819. }
  178820. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178821. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178822. {
  178823. png_uint_32 sumhi, sumlo;
  178824. int j;
  178825. sumlo = sum & PNG_LOMASK;
  178826. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK; /* Gives us some footroom */
  178827. for (j = 0; j < num_p_filters; j++)
  178828. {
  178829. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  178830. {
  178831. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  178832. PNG_WEIGHT_SHIFT;
  178833. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  178834. PNG_WEIGHT_SHIFT;
  178835. }
  178836. }
  178837. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178838. PNG_COST_SHIFT;
  178839. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_NONE]) >>
  178840. PNG_COST_SHIFT;
  178841. if (sumhi > PNG_HIMASK)
  178842. sum = PNG_MAXSUM;
  178843. else
  178844. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178845. }
  178846. #endif
  178847. mins = sum;
  178848. }
  178849. if (filter_to_do == PNG_FILTER_SUB)
  178850. {
  178851. png_bytep rp, lp, dp;
  178852. png_uint_32 i;
  178853. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178854. i++, rp++, dp++)
  178855. {
  178856. *dp = *rp;
  178857. }
  178858. for (lp = row_buf + 1; i < row_bytes;
  178859. i++, rp++, lp++, dp++)
  178860. {
  178861. *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178862. }
  178863. best_row = png_ptr->sub_row;
  178864. }
  178865. else if (filter_to_do & PNG_FILTER_SUB)
  178866. {
  178867. png_bytep rp, dp, lp;
  178868. png_uint_32 sum = 0, lmins = mins;
  178869. png_uint_32 i;
  178870. int v;
  178871. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178872. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178873. {
  178874. int j;
  178875. png_uint_32 lmhi, lmlo;
  178876. lmlo = lmins & PNG_LOMASK;
  178877. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178878. for (j = 0; j < num_p_filters; j++)
  178879. {
  178880. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178881. {
  178882. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178883. PNG_WEIGHT_SHIFT;
  178884. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178885. PNG_WEIGHT_SHIFT;
  178886. }
  178887. }
  178888. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178889. PNG_COST_SHIFT;
  178890. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178891. PNG_COST_SHIFT;
  178892. if (lmhi > PNG_HIMASK)
  178893. lmins = PNG_MAXSUM;
  178894. else
  178895. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178896. }
  178897. #endif
  178898. for (i = 0, rp = row_buf + 1, dp = png_ptr->sub_row + 1; i < bpp;
  178899. i++, rp++, dp++)
  178900. {
  178901. v = *dp = *rp;
  178902. sum += (v < 128) ? v : 256 - v;
  178903. }
  178904. for (lp = row_buf + 1; i < row_bytes;
  178905. i++, rp++, lp++, dp++)
  178906. {
  178907. v = *dp = (png_byte)(((int)*rp - (int)*lp) & 0xff);
  178908. sum += (v < 128) ? v : 256 - v;
  178909. if (sum > lmins) /* We are already worse, don't continue. */
  178910. break;
  178911. }
  178912. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178913. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178914. {
  178915. int j;
  178916. png_uint_32 sumhi, sumlo;
  178917. sumlo = sum & PNG_LOMASK;
  178918. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  178919. for (j = 0; j < num_p_filters; j++)
  178920. {
  178921. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_SUB)
  178922. {
  178923. sumlo = (sumlo * png_ptr->inv_filter_weights[j]) >>
  178924. PNG_WEIGHT_SHIFT;
  178925. sumhi = (sumhi * png_ptr->inv_filter_weights[j]) >>
  178926. PNG_WEIGHT_SHIFT;
  178927. }
  178928. }
  178929. sumlo = (sumlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178930. PNG_COST_SHIFT;
  178931. sumhi = (sumhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_SUB]) >>
  178932. PNG_COST_SHIFT;
  178933. if (sumhi > PNG_HIMASK)
  178934. sum = PNG_MAXSUM;
  178935. else
  178936. sum = (sumhi << PNG_HISHIFT) + sumlo;
  178937. }
  178938. #endif
  178939. if (sum < mins)
  178940. {
  178941. mins = sum;
  178942. best_row = png_ptr->sub_row;
  178943. }
  178944. }
  178945. if (filter_to_do == PNG_FILTER_UP)
  178946. {
  178947. png_bytep rp, dp, pp;
  178948. png_uint_32 i;
  178949. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178950. pp = prev_row + 1; i < row_bytes;
  178951. i++, rp++, pp++, dp++)
  178952. {
  178953. *dp = (png_byte)(((int)*rp - (int)*pp) & 0xff);
  178954. }
  178955. best_row = png_ptr->up_row;
  178956. }
  178957. else if (filter_to_do & PNG_FILTER_UP)
  178958. {
  178959. png_bytep rp, dp, pp;
  178960. png_uint_32 sum = 0, lmins = mins;
  178961. png_uint_32 i;
  178962. int v;
  178963. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178964. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  178965. {
  178966. int j;
  178967. png_uint_32 lmhi, lmlo;
  178968. lmlo = lmins & PNG_LOMASK;
  178969. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  178970. for (j = 0; j < num_p_filters; j++)
  178971. {
  178972. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  178973. {
  178974. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  178975. PNG_WEIGHT_SHIFT;
  178976. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  178977. PNG_WEIGHT_SHIFT;
  178978. }
  178979. }
  178980. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178981. PNG_COST_SHIFT;
  178982. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_UP]) >>
  178983. PNG_COST_SHIFT;
  178984. if (lmhi > PNG_HIMASK)
  178985. lmins = PNG_MAXSUM;
  178986. else
  178987. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  178988. }
  178989. #endif
  178990. for (i = 0, rp = row_buf + 1, dp = png_ptr->up_row + 1,
  178991. pp = prev_row + 1; i < row_bytes; i++)
  178992. {
  178993. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  178994. sum += (v < 128) ? v : 256 - v;
  178995. if (sum > lmins) /* We are already worse, don't continue. */
  178996. break;
  178997. }
  178998. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  178999. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179000. {
  179001. int j;
  179002. png_uint_32 sumhi, sumlo;
  179003. sumlo = sum & PNG_LOMASK;
  179004. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179005. for (j = 0; j < num_p_filters; j++)
  179006. {
  179007. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_UP)
  179008. {
  179009. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179010. PNG_WEIGHT_SHIFT;
  179011. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179012. PNG_WEIGHT_SHIFT;
  179013. }
  179014. }
  179015. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  179016. PNG_COST_SHIFT;
  179017. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_UP]) >>
  179018. PNG_COST_SHIFT;
  179019. if (sumhi > PNG_HIMASK)
  179020. sum = PNG_MAXSUM;
  179021. else
  179022. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179023. }
  179024. #endif
  179025. if (sum < mins)
  179026. {
  179027. mins = sum;
  179028. best_row = png_ptr->up_row;
  179029. }
  179030. }
  179031. if (filter_to_do == PNG_FILTER_AVG)
  179032. {
  179033. png_bytep rp, dp, pp, lp;
  179034. png_uint_32 i;
  179035. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  179036. pp = prev_row + 1; i < bpp; i++)
  179037. {
  179038. *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  179039. }
  179040. for (lp = row_buf + 1; i < row_bytes; i++)
  179041. {
  179042. *dp++ = (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2))
  179043. & 0xff);
  179044. }
  179045. best_row = png_ptr->avg_row;
  179046. }
  179047. else if (filter_to_do & PNG_FILTER_AVG)
  179048. {
  179049. png_bytep rp, dp, pp, lp;
  179050. png_uint_32 sum = 0, lmins = mins;
  179051. png_uint_32 i;
  179052. int v;
  179053. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179054. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179055. {
  179056. int j;
  179057. png_uint_32 lmhi, lmlo;
  179058. lmlo = lmins & PNG_LOMASK;
  179059. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179060. for (j = 0; j < num_p_filters; j++)
  179061. {
  179062. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_AVG)
  179063. {
  179064. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179065. PNG_WEIGHT_SHIFT;
  179066. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179067. PNG_WEIGHT_SHIFT;
  179068. }
  179069. }
  179070. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179071. PNG_COST_SHIFT;
  179072. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179073. PNG_COST_SHIFT;
  179074. if (lmhi > PNG_HIMASK)
  179075. lmins = PNG_MAXSUM;
  179076. else
  179077. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179078. }
  179079. #endif
  179080. for (i = 0, rp = row_buf + 1, dp = png_ptr->avg_row + 1,
  179081. pp = prev_row + 1; i < bpp; i++)
  179082. {
  179083. v = *dp++ = (png_byte)(((int)*rp++ - ((int)*pp++ / 2)) & 0xff);
  179084. sum += (v < 128) ? v : 256 - v;
  179085. }
  179086. for (lp = row_buf + 1; i < row_bytes; i++)
  179087. {
  179088. v = *dp++ =
  179089. (png_byte)(((int)*rp++ - (((int)*pp++ + (int)*lp++) / 2)) & 0xff);
  179090. sum += (v < 128) ? v : 256 - v;
  179091. if (sum > lmins) /* We are already worse, don't continue. */
  179092. break;
  179093. }
  179094. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179095. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179096. {
  179097. int j;
  179098. png_uint_32 sumhi, sumlo;
  179099. sumlo = sum & PNG_LOMASK;
  179100. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179101. for (j = 0; j < num_p_filters; j++)
  179102. {
  179103. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_NONE)
  179104. {
  179105. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179106. PNG_WEIGHT_SHIFT;
  179107. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179108. PNG_WEIGHT_SHIFT;
  179109. }
  179110. }
  179111. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179112. PNG_COST_SHIFT;
  179113. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_AVG]) >>
  179114. PNG_COST_SHIFT;
  179115. if (sumhi > PNG_HIMASK)
  179116. sum = PNG_MAXSUM;
  179117. else
  179118. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179119. }
  179120. #endif
  179121. if (sum < mins)
  179122. {
  179123. mins = sum;
  179124. best_row = png_ptr->avg_row;
  179125. }
  179126. }
  179127. if (filter_to_do == PNG_FILTER_PAETH)
  179128. {
  179129. png_bytep rp, dp, pp, cp, lp;
  179130. png_uint_32 i;
  179131. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  179132. pp = prev_row + 1; i < bpp; i++)
  179133. {
  179134. *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179135. }
  179136. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  179137. {
  179138. int a, b, c, pa, pb, pc, p;
  179139. b = *pp++;
  179140. c = *cp++;
  179141. a = *lp++;
  179142. p = b - c;
  179143. pc = a - c;
  179144. #ifdef PNG_USE_ABS
  179145. pa = abs(p);
  179146. pb = abs(pc);
  179147. pc = abs(p + pc);
  179148. #else
  179149. pa = p < 0 ? -p : p;
  179150. pb = pc < 0 ? -pc : pc;
  179151. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  179152. #endif
  179153. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  179154. *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  179155. }
  179156. best_row = png_ptr->paeth_row;
  179157. }
  179158. else if (filter_to_do & PNG_FILTER_PAETH)
  179159. {
  179160. png_bytep rp, dp, pp, cp, lp;
  179161. png_uint_32 sum = 0, lmins = mins;
  179162. png_uint_32 i;
  179163. int v;
  179164. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179165. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179166. {
  179167. int j;
  179168. png_uint_32 lmhi, lmlo;
  179169. lmlo = lmins & PNG_LOMASK;
  179170. lmhi = (lmins >> PNG_HISHIFT) & PNG_HIMASK;
  179171. for (j = 0; j < num_p_filters; j++)
  179172. {
  179173. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  179174. {
  179175. lmlo = (lmlo * png_ptr->inv_filter_weights[j]) >>
  179176. PNG_WEIGHT_SHIFT;
  179177. lmhi = (lmhi * png_ptr->inv_filter_weights[j]) >>
  179178. PNG_WEIGHT_SHIFT;
  179179. }
  179180. }
  179181. lmlo = (lmlo * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179182. PNG_COST_SHIFT;
  179183. lmhi = (lmhi * png_ptr->inv_filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179184. PNG_COST_SHIFT;
  179185. if (lmhi > PNG_HIMASK)
  179186. lmins = PNG_MAXSUM;
  179187. else
  179188. lmins = (lmhi << PNG_HISHIFT) + lmlo;
  179189. }
  179190. #endif
  179191. for (i = 0, rp = row_buf + 1, dp = png_ptr->paeth_row + 1,
  179192. pp = prev_row + 1; i < bpp; i++)
  179193. {
  179194. v = *dp++ = (png_byte)(((int)*rp++ - (int)*pp++) & 0xff);
  179195. sum += (v < 128) ? v : 256 - v;
  179196. }
  179197. for (lp = row_buf + 1, cp = prev_row + 1; i < row_bytes; i++)
  179198. {
  179199. int a, b, c, pa, pb, pc, p;
  179200. b = *pp++;
  179201. c = *cp++;
  179202. a = *lp++;
  179203. #ifndef PNG_SLOW_PAETH
  179204. p = b - c;
  179205. pc = a - c;
  179206. #ifdef PNG_USE_ABS
  179207. pa = abs(p);
  179208. pb = abs(pc);
  179209. pc = abs(p + pc);
  179210. #else
  179211. pa = p < 0 ? -p : p;
  179212. pb = pc < 0 ? -pc : pc;
  179213. pc = (p + pc) < 0 ? -(p + pc) : p + pc;
  179214. #endif
  179215. p = (pa <= pb && pa <=pc) ? a : (pb <= pc) ? b : c;
  179216. #else /* PNG_SLOW_PAETH */
  179217. p = a + b - c;
  179218. pa = abs(p - a);
  179219. pb = abs(p - b);
  179220. pc = abs(p - c);
  179221. if (pa <= pb && pa <= pc)
  179222. p = a;
  179223. else if (pb <= pc)
  179224. p = b;
  179225. else
  179226. p = c;
  179227. #endif /* PNG_SLOW_PAETH */
  179228. v = *dp++ = (png_byte)(((int)*rp++ - p) & 0xff);
  179229. sum += (v < 128) ? v : 256 - v;
  179230. if (sum > lmins) /* We are already worse, don't continue. */
  179231. break;
  179232. }
  179233. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179234. if (png_ptr->heuristic_method == PNG_FILTER_HEURISTIC_WEIGHTED)
  179235. {
  179236. int j;
  179237. png_uint_32 sumhi, sumlo;
  179238. sumlo = sum & PNG_LOMASK;
  179239. sumhi = (sum >> PNG_HISHIFT) & PNG_HIMASK;
  179240. for (j = 0; j < num_p_filters; j++)
  179241. {
  179242. if (png_ptr->prev_filters[j] == PNG_FILTER_VALUE_PAETH)
  179243. {
  179244. sumlo = (sumlo * png_ptr->filter_weights[j]) >>
  179245. PNG_WEIGHT_SHIFT;
  179246. sumhi = (sumhi * png_ptr->filter_weights[j]) >>
  179247. PNG_WEIGHT_SHIFT;
  179248. }
  179249. }
  179250. sumlo = (sumlo * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179251. PNG_COST_SHIFT;
  179252. sumhi = (sumhi * png_ptr->filter_costs[PNG_FILTER_VALUE_PAETH]) >>
  179253. PNG_COST_SHIFT;
  179254. if (sumhi > PNG_HIMASK)
  179255. sum = PNG_MAXSUM;
  179256. else
  179257. sum = (sumhi << PNG_HISHIFT) + sumlo;
  179258. }
  179259. #endif
  179260. if (sum < mins)
  179261. {
  179262. best_row = png_ptr->paeth_row;
  179263. }
  179264. }
  179265. #endif /* PNG_NO_WRITE_FILTER */
  179266. png_write_filtered_row(png_ptr, best_row);
  179267. #ifndef PNG_NO_WRITE_FILTER
  179268. #if defined(PNG_WRITE_WEIGHTED_FILTER_SUPPORTED)
  179269. if (png_ptr->num_prev_filters > 0)
  179270. {
  179271. int j;
  179272. for (j = 1; j < num_p_filters; j++)
  179273. {
  179274. png_ptr->prev_filters[j] = png_ptr->prev_filters[j - 1];
  179275. }
  179276. png_ptr->prev_filters[j] = best_row[0];
  179277. }
  179278. #endif
  179279. #endif /* PNG_NO_WRITE_FILTER */
  179280. }
  179281. void /* PRIVATE */
  179282. png_write_filtered_row(png_structp png_ptr, png_bytep filtered_row)
  179283. {
  179284. png_debug(1, "in png_write_filtered_row\n");
  179285. png_debug1(2, "filter = %d\n", filtered_row[0]);
  179286. png_ptr->zstream.next_in = filtered_row;
  179287. png_ptr->zstream.avail_in = (uInt)png_ptr->row_info.rowbytes + 1;
  179288. do
  179289. {
  179290. int ret; /* return of zlib */
  179291. ret = deflate(&png_ptr->zstream, Z_NO_FLUSH);
  179292. if (ret != Z_OK)
  179293. {
  179294. if (png_ptr->zstream.msg != NULL)
  179295. png_error(png_ptr, png_ptr->zstream.msg);
  179296. else
  179297. png_error(png_ptr, "zlib error");
  179298. }
  179299. if (!(png_ptr->zstream.avail_out))
  179300. {
  179301. png_write_IDAT(png_ptr, png_ptr->zbuf, png_ptr->zbuf_size);
  179302. png_ptr->zstream.next_out = png_ptr->zbuf;
  179303. png_ptr->zstream.avail_out = (uInt)png_ptr->zbuf_size;
  179304. }
  179305. } while (png_ptr->zstream.avail_in);
  179306. if (png_ptr->prev_row != NULL)
  179307. {
  179308. png_bytep tptr;
  179309. tptr = png_ptr->prev_row;
  179310. png_ptr->prev_row = png_ptr->row_buf;
  179311. png_ptr->row_buf = tptr;
  179312. }
  179313. png_write_finish_row(png_ptr);
  179314. #if defined(PNG_WRITE_FLUSH_SUPPORTED)
  179315. png_ptr->flush_rows++;
  179316. if (png_ptr->flush_dist > 0 &&
  179317. png_ptr->flush_rows >= png_ptr->flush_dist)
  179318. {
  179319. png_write_flush(png_ptr);
  179320. }
  179321. #endif
  179322. }
  179323. #endif /* PNG_WRITE_SUPPORTED */
  179324. /*** End of inlined file: pngwutil.c ***/
  179325. }
  179326. #else
  179327. #define PNG_INTERNAL
  179328. #define PNG_SETJMP_NOT_SUPPORTED
  179329. #include <png.h>
  179330. #include <pngconf.h>
  179331. #endif
  179332. }
  179333. #ifdef _MSC_VER
  179334. #pragma warning (pop)
  179335. #endif
  179336. BEGIN_JUCE_NAMESPACE
  179337. using namespace pnglibNamespace;
  179338. using ::calloc;
  179339. using ::malloc;
  179340. using ::free;
  179341. static void pngReadCallback (png_structp pngReadStruct, png_bytep data, png_size_t length)
  179342. {
  179343. InputStream* const in = (InputStream*) png_get_io_ptr (pngReadStruct);
  179344. in->read (data, (int) length);
  179345. }
  179346. struct PNGErrorStruct {};
  179347. static void pngErrorCallback (png_structp, png_const_charp)
  179348. {
  179349. throw PNGErrorStruct();
  179350. }
  179351. Image* juce_loadPNGImageFromStream (InputStream& in)
  179352. {
  179353. Image* image = 0;
  179354. png_structp pngReadStruct;
  179355. png_infop pngInfoStruct;
  179356. pngReadStruct = png_create_read_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179357. if (pngReadStruct != 0)
  179358. {
  179359. pngInfoStruct = png_create_info_struct (pngReadStruct);
  179360. if (pngInfoStruct == 0)
  179361. {
  179362. png_destroy_read_struct (&pngReadStruct, 0, 0);
  179363. return 0;
  179364. }
  179365. png_set_error_fn (pngReadStruct, 0, pngErrorCallback, pngErrorCallback);
  179366. // read the header..
  179367. png_set_read_fn (pngReadStruct, &in, pngReadCallback);
  179368. png_uint_32 width, height;
  179369. int bitDepth, colorType, interlaceType;
  179370. png_read_info (pngReadStruct, pngInfoStruct);
  179371. png_get_IHDR (pngReadStruct, pngInfoStruct,
  179372. &width, &height,
  179373. &bitDepth, &colorType,
  179374. &interlaceType, 0, 0);
  179375. if (bitDepth == 16)
  179376. png_set_strip_16 (pngReadStruct);
  179377. if (colorType == PNG_COLOR_TYPE_PALETTE)
  179378. png_set_expand (pngReadStruct);
  179379. if (bitDepth < 8)
  179380. png_set_expand (pngReadStruct);
  179381. if (png_get_valid (pngReadStruct, pngInfoStruct, PNG_INFO_tRNS))
  179382. png_set_expand (pngReadStruct);
  179383. if (colorType == PNG_COLOR_TYPE_GRAY || colorType == PNG_COLOR_TYPE_GRAY_ALPHA)
  179384. png_set_gray_to_rgb (pngReadStruct);
  179385. png_set_add_alpha (pngReadStruct, 0xff, PNG_FILLER_AFTER);
  179386. bool hasAlphaChan = (colorType & PNG_COLOR_MASK_ALPHA) != 0
  179387. || pngInfoStruct->num_trans > 0;
  179388. // Load the image into a temp buffer in the pnglib format..
  179389. HeapBlock <uint8> tempBuffer (height * (width << 2));
  179390. {
  179391. HeapBlock <png_bytep> rows (height);
  179392. for (int y = (int) height; --y >= 0;)
  179393. rows[y] = (png_bytep) (tempBuffer + (width << 2) * y);
  179394. png_read_image (pngReadStruct, rows);
  179395. png_read_end (pngReadStruct, pngInfoStruct);
  179396. }
  179397. png_destroy_read_struct (&pngReadStruct, &pngInfoStruct, 0);
  179398. // now convert the data to a juce image format..
  179399. image = Image::createNativeImage (hasAlphaChan ? Image::ARGB : Image::RGB,
  179400. (int) width, (int) height, hasAlphaChan);
  179401. hasAlphaChan = image->hasAlphaChannel(); // (the native image creator may not give back what we expect)
  179402. const Image::BitmapData destData (*image, 0, 0, (int) width, (int) height, true);
  179403. uint8* srcRow = tempBuffer;
  179404. uint8* destRow = destData.data;
  179405. for (int y = 0; y < (int) height; ++y)
  179406. {
  179407. const uint8* src = srcRow;
  179408. srcRow += (width << 2);
  179409. uint8* dest = destRow;
  179410. destRow += destData.lineStride;
  179411. if (hasAlphaChan)
  179412. {
  179413. for (int i = (int) width; --i >= 0;)
  179414. {
  179415. ((PixelARGB*) dest)->setARGB (src[3], src[0], src[1], src[2]);
  179416. ((PixelARGB*) dest)->premultiply();
  179417. dest += destData.pixelStride;
  179418. src += 4;
  179419. }
  179420. }
  179421. else
  179422. {
  179423. for (int i = (int) width; --i >= 0;)
  179424. {
  179425. ((PixelRGB*) dest)->setARGB (0, src[0], src[1], src[2]);
  179426. dest += destData.pixelStride;
  179427. src += 4;
  179428. }
  179429. }
  179430. }
  179431. }
  179432. return image;
  179433. }
  179434. static void pngWriteDataCallback (png_structp png_ptr, png_bytep data, png_size_t length)
  179435. {
  179436. OutputStream* const out = (OutputStream*) png_ptr->io_ptr;
  179437. const bool ok = out->write (data, (int) length);
  179438. (void) ok;
  179439. jassert (ok);
  179440. }
  179441. bool juce_writePNGImageToStream (const Image& image, OutputStream& out)
  179442. {
  179443. const int width = image.getWidth();
  179444. const int height = image.getHeight();
  179445. png_structp pngWriteStruct = png_create_write_struct (PNG_LIBPNG_VER_STRING, 0, 0, 0);
  179446. if (pngWriteStruct == 0)
  179447. return false;
  179448. png_infop pngInfoStruct = png_create_info_struct (pngWriteStruct);
  179449. if (pngInfoStruct == 0)
  179450. {
  179451. png_destroy_write_struct (&pngWriteStruct, (png_infopp) 0);
  179452. return false;
  179453. }
  179454. png_set_write_fn (pngWriteStruct, &out, pngWriteDataCallback, 0);
  179455. png_set_IHDR (pngWriteStruct, pngInfoStruct, width, height, 8,
  179456. image.hasAlphaChannel() ? PNG_COLOR_TYPE_RGB_ALPHA
  179457. : PNG_COLOR_TYPE_RGB,
  179458. PNG_INTERLACE_NONE,
  179459. PNG_COMPRESSION_TYPE_BASE,
  179460. PNG_FILTER_TYPE_BASE);
  179461. HeapBlock <png_byte> rowData (width * 4);
  179462. png_color_8 sig_bit;
  179463. sig_bit.red = 8;
  179464. sig_bit.green = 8;
  179465. sig_bit.blue = 8;
  179466. sig_bit.alpha = 8;
  179467. png_set_sBIT (pngWriteStruct, pngInfoStruct, &sig_bit);
  179468. png_write_info (pngWriteStruct, pngInfoStruct);
  179469. png_set_shift (pngWriteStruct, &sig_bit);
  179470. png_set_packing (pngWriteStruct);
  179471. const Image::BitmapData srcData (image, 0, 0, width, height);
  179472. for (int y = 0; y < height; ++y)
  179473. {
  179474. uint8* dst = (uint8*) rowData;
  179475. const uint8* src = srcData.getLinePointer (y);
  179476. if (image.hasAlphaChannel())
  179477. {
  179478. for (int i = width; --i >= 0;)
  179479. {
  179480. PixelARGB p (*(const PixelARGB*) src);
  179481. p.unpremultiply();
  179482. *dst++ = p.getRed();
  179483. *dst++ = p.getGreen();
  179484. *dst++ = p.getBlue();
  179485. *dst++ = p.getAlpha();
  179486. src += srcData.pixelStride;
  179487. }
  179488. }
  179489. else
  179490. {
  179491. for (int i = width; --i >= 0;)
  179492. {
  179493. *dst++ = ((const PixelRGB*) src)->getRed();
  179494. *dst++ = ((const PixelRGB*) src)->getGreen();
  179495. *dst++ = ((const PixelRGB*) src)->getBlue();
  179496. src += srcData.pixelStride;
  179497. }
  179498. }
  179499. png_write_rows (pngWriteStruct, &rowData, 1);
  179500. }
  179501. png_write_end (pngWriteStruct, pngInfoStruct);
  179502. png_destroy_write_struct (&pngWriteStruct, &pngInfoStruct);
  179503. out.flush();
  179504. return true;
  179505. }
  179506. END_JUCE_NAMESPACE
  179507. /*** End of inlined file: juce_PNGLoader.cpp ***/
  179508. #endif
  179509. //==============================================================================
  179510. #if JUCE_BUILD_NATIVE
  179511. #if JUCE_WINDOWS
  179512. /*** Start of inlined file: juce_win32_NativeCode.cpp ***/
  179513. BEGIN_JUCE_NAMESPACE
  179514. #define JUCE_INCLUDED_FILE 1
  179515. // Now include the actual code files..
  179516. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179517. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179518. // compiled on its own).
  179519. #if JUCE_INCLUDED_FILE
  179520. /*** Start of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179521. #ifndef __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179522. #define __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179523. #ifndef DOXYGEN
  179524. // use with DynamicLibraryLoader to simplify importing functions
  179525. //
  179526. // functionName: function to import
  179527. // localFunctionName: name you want to use to actually call it (must be different)
  179528. // returnType: the return type
  179529. // object: the DynamicLibraryLoader to use
  179530. // params: list of params (bracketed)
  179531. //
  179532. #define DynamicLibraryImport(functionName, localFunctionName, returnType, object, params) \
  179533. typedef returnType (WINAPI *type##localFunctionName) params; \
  179534. type##localFunctionName localFunctionName \
  179535. = (type##localFunctionName)object.findProcAddress (#functionName);
  179536. // loads and unloads a DLL automatically
  179537. class JUCE_API DynamicLibraryLoader
  179538. {
  179539. public:
  179540. DynamicLibraryLoader (const String& name);
  179541. ~DynamicLibraryLoader();
  179542. void* findProcAddress (const String& functionName);
  179543. private:
  179544. void* libHandle;
  179545. };
  179546. #endif
  179547. #endif // __JUCE_WIN32_DYNAMICLIBRARYLOADER_JUCEHEADER__
  179548. /*** End of inlined file: juce_win32_DynamicLibraryLoader.h ***/
  179549. DynamicLibraryLoader::DynamicLibraryLoader (const String& name)
  179550. {
  179551. libHandle = LoadLibrary (name);
  179552. }
  179553. DynamicLibraryLoader::~DynamicLibraryLoader()
  179554. {
  179555. FreeLibrary ((HMODULE) libHandle);
  179556. }
  179557. void* DynamicLibraryLoader::findProcAddress (const String& functionName)
  179558. {
  179559. return (void*) GetProcAddress ((HMODULE) libHandle, functionName.toCString());
  179560. }
  179561. #endif
  179562. /*** End of inlined file: juce_win32_DynamicLibraryLoader.cpp ***/
  179563. /*** Start of inlined file: juce_win32_SystemStats.cpp ***/
  179564. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179565. // compiled on its own).
  179566. #if JUCE_INCLUDED_FILE
  179567. extern void juce_initialiseThreadEvents();
  179568. void Logger::outputDebugString (const String& text) throw()
  179569. {
  179570. OutputDebugString (text + T("\n"));
  179571. }
  179572. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  179573. {
  179574. String text;
  179575. va_list args;
  179576. va_start (args, format);
  179577. text.vprintf(format, args);
  179578. outputDebugString (text);
  179579. }
  179580. static int64 hiResTicksPerSecond;
  179581. static double hiResTicksScaleFactor;
  179582. #if JUCE_USE_INTRINSICS
  179583. // CPU info functions using intrinsics...
  179584. #pragma intrinsic (__cpuid)
  179585. #pragma intrinsic (__rdtsc)
  179586. const String SystemStats::getCpuVendor() throw()
  179587. {
  179588. int info [4];
  179589. __cpuid (info, 0);
  179590. char v [12];
  179591. memcpy (v, info + 1, 4);
  179592. memcpy (v + 4, info + 3, 4);
  179593. memcpy (v + 8, info + 2, 4);
  179594. return String (v, 12);
  179595. }
  179596. #else
  179597. // CPU info functions using old fashioned inline asm...
  179598. static void juce_getCpuVendor (char* const v)
  179599. {
  179600. int vendor[4];
  179601. zeromem (vendor, 16);
  179602. #ifdef JUCE_64BIT
  179603. #else
  179604. #ifndef __MINGW32__
  179605. __try
  179606. #endif
  179607. {
  179608. #if JUCE_GCC
  179609. unsigned int dummy = 0;
  179610. __asm__ ("cpuid" : "=a" (dummy), "=b" (vendor[0]), "=c" (vendor[2]),"=d" (vendor[1]) : "a" (0));
  179611. #else
  179612. __asm
  179613. {
  179614. mov eax, 0
  179615. cpuid
  179616. mov [vendor], ebx
  179617. mov [vendor + 4], edx
  179618. mov [vendor + 8], ecx
  179619. }
  179620. #endif
  179621. }
  179622. #ifndef __MINGW32__
  179623. __except (EXCEPTION_EXECUTE_HANDLER)
  179624. {
  179625. *v = 0;
  179626. }
  179627. #endif
  179628. #endif
  179629. memcpy (v, vendor, 16);
  179630. }
  179631. const String SystemStats::getCpuVendor() throw()
  179632. {
  179633. char v [16];
  179634. juce_getCpuVendor (v);
  179635. return String (v, 16);
  179636. }
  179637. #endif
  179638. struct CPUFlags
  179639. {
  179640. bool hasMMX : 1;
  179641. bool hasSSE : 1;
  179642. bool hasSSE2 : 1;
  179643. bool has3DNow : 1;
  179644. };
  179645. static CPUFlags cpuFlags;
  179646. bool SystemStats::hasMMX() throw()
  179647. {
  179648. return cpuFlags.hasMMX;
  179649. }
  179650. bool SystemStats::hasSSE() throw()
  179651. {
  179652. return cpuFlags.hasSSE;
  179653. }
  179654. bool SystemStats::hasSSE2() throw()
  179655. {
  179656. return cpuFlags.hasSSE2;
  179657. }
  179658. bool SystemStats::has3DNow() throw()
  179659. {
  179660. return cpuFlags.has3DNow;
  179661. }
  179662. void SystemStats::initialiseStats() throw()
  179663. {
  179664. juce_initialiseThreadEvents();
  179665. cpuFlags.hasMMX = IsProcessorFeaturePresent (PF_MMX_INSTRUCTIONS_AVAILABLE) != 0;
  179666. cpuFlags.hasSSE = IsProcessorFeaturePresent (PF_XMMI_INSTRUCTIONS_AVAILABLE) != 0;
  179667. cpuFlags.hasSSE2 = IsProcessorFeaturePresent (PF_XMMI64_INSTRUCTIONS_AVAILABLE) != 0;
  179668. #ifdef PF_AMD3D_INSTRUCTIONS_AVAILABLE
  179669. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_AMD3D_INSTRUCTIONS_AVAILABLE) != 0;
  179670. #else
  179671. cpuFlags.has3DNow = IsProcessorFeaturePresent (PF_3DNOW_INSTRUCTIONS_AVAILABLE) != 0;
  179672. #endif
  179673. LARGE_INTEGER f;
  179674. QueryPerformanceFrequency (&f);
  179675. hiResTicksPerSecond = f.QuadPart;
  179676. hiResTicksScaleFactor = 1000.0 / hiResTicksPerSecond;
  179677. String s (SystemStats::getJUCEVersion());
  179678. #ifdef JUCE_DEBUG
  179679. const MMRESULT res = timeBeginPeriod (1);
  179680. jassert (res == TIMERR_NOERROR);
  179681. #else
  179682. timeBeginPeriod (1);
  179683. #endif
  179684. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  179685. _CrtSetDbgFlag (_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
  179686. #endif
  179687. }
  179688. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  179689. {
  179690. OSVERSIONINFO info;
  179691. info.dwOSVersionInfoSize = sizeof (info);
  179692. GetVersionEx (&info);
  179693. if (info.dwPlatformId == VER_PLATFORM_WIN32_NT)
  179694. {
  179695. switch (info.dwMajorVersion)
  179696. {
  179697. case 5: return (info.dwMinorVersion == 0) ? Win2000 : WinXP;
  179698. case 6: return (info.dwMinorVersion == 0) ? WinVista : Windows7;
  179699. default: jassertfalse; break; // !! not a supported OS!
  179700. }
  179701. }
  179702. else if (info.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS)
  179703. {
  179704. jassert (info.dwMinorVersion != 0); // !! still running on Windows 95??
  179705. return Win98;
  179706. }
  179707. return UnknownOS;
  179708. }
  179709. const String SystemStats::getOperatingSystemName() throw()
  179710. {
  179711. const char* name = "Unknown OS";
  179712. switch (getOperatingSystemType())
  179713. {
  179714. case Windows7: name = "Windows 7"; break;
  179715. case WinVista: name = "Windows Vista"; break;
  179716. case WinXP: name = "Windows XP"; break;
  179717. case Win2000: name = "Windows 2000"; break;
  179718. case Win98: name = "Windows 98"; break;
  179719. default: jassertfalse; break; // !! new type of OS?
  179720. }
  179721. return name;
  179722. }
  179723. bool SystemStats::isOperatingSystem64Bit() throw()
  179724. {
  179725. #ifdef _WIN64
  179726. return true;
  179727. #else
  179728. typedef BOOL (WINAPI* LPFN_ISWOW64PROCESS) (HANDLE, PBOOL);
  179729. LPFN_ISWOW64PROCESS fnIsWow64Process = (LPFN_ISWOW64PROCESS) GetProcAddress (GetModuleHandle (L"kernel32"), "IsWow64Process");
  179730. BOOL isWow64 = FALSE;
  179731. return (fnIsWow64Process != 0)
  179732. && fnIsWow64Process (GetCurrentProcess(), &isWow64)
  179733. && (isWow64 != FALSE);
  179734. #endif
  179735. }
  179736. int SystemStats::getMemorySizeInMegabytes() throw()
  179737. {
  179738. MEMORYSTATUSEX mem;
  179739. mem.dwLength = sizeof (mem);
  179740. GlobalMemoryStatusEx (&mem);
  179741. return (int) (mem.ullTotalPhys / (1024 * 1024)) + 1;
  179742. }
  179743. int SystemStats::getNumCpus() throw()
  179744. {
  179745. SYSTEM_INFO systemInfo;
  179746. GetSystemInfo (&systemInfo);
  179747. return systemInfo.dwNumberOfProcessors;
  179748. }
  179749. uint32 juce_millisecondsSinceStartup() throw()
  179750. {
  179751. return (uint32) GetTickCount();
  179752. }
  179753. int64 Time::getHighResolutionTicks() throw()
  179754. {
  179755. LARGE_INTEGER ticks;
  179756. QueryPerformanceCounter (&ticks);
  179757. const int64 mainCounterAsHiResTicks = (GetTickCount() * hiResTicksPerSecond) / 1000;
  179758. const int64 newOffset = mainCounterAsHiResTicks - ticks.QuadPart;
  179759. // fix for a very obscure PCI hardware bug that can make the counter
  179760. // sometimes jump forwards by a few seconds..
  179761. static int64 hiResTicksOffset = 0;
  179762. const int64 offsetDrift = abs64 (newOffset - hiResTicksOffset);
  179763. if (offsetDrift > (hiResTicksPerSecond >> 1))
  179764. hiResTicksOffset = newOffset;
  179765. return ticks.QuadPart + hiResTicksOffset;
  179766. }
  179767. double Time::getMillisecondCounterHiRes() throw()
  179768. {
  179769. return getHighResolutionTicks() * hiResTicksScaleFactor;
  179770. }
  179771. int64 Time::getHighResolutionTicksPerSecond() throw()
  179772. {
  179773. return hiResTicksPerSecond;
  179774. }
  179775. int64 SystemStats::getClockCycleCounter() throw()
  179776. {
  179777. #if JUCE_USE_INTRINSICS
  179778. // MS intrinsics version...
  179779. return __rdtsc();
  179780. #elif JUCE_GCC
  179781. // GNU inline asm version...
  179782. unsigned int hi = 0, lo = 0;
  179783. __asm__ __volatile__ (
  179784. "xor %%eax, %%eax \n\
  179785. xor %%edx, %%edx \n\
  179786. rdtsc \n\
  179787. movl %%eax, %[lo] \n\
  179788. movl %%edx, %[hi]"
  179789. :
  179790. : [hi] "m" (hi),
  179791. [lo] "m" (lo)
  179792. : "cc", "eax", "ebx", "ecx", "edx", "memory");
  179793. return (int64) ((((uint64) hi) << 32) | lo);
  179794. #else
  179795. // MSVC inline asm version...
  179796. unsigned int hi = 0, lo = 0;
  179797. __asm
  179798. {
  179799. xor eax, eax
  179800. xor edx, edx
  179801. rdtsc
  179802. mov lo, eax
  179803. mov hi, edx
  179804. }
  179805. return (int64) ((((uint64) hi) << 32) | lo);
  179806. #endif
  179807. }
  179808. int SystemStats::getCpuSpeedInMegaherz() throw()
  179809. {
  179810. const int64 cycles = SystemStats::getClockCycleCounter();
  179811. const uint32 millis = Time::getMillisecondCounter();
  179812. int lastResult = 0;
  179813. for (;;)
  179814. {
  179815. int n = 1000000;
  179816. while (--n > 0) {}
  179817. const uint32 millisElapsed = Time::getMillisecondCounter() - millis;
  179818. const int64 cyclesNow = SystemStats::getClockCycleCounter();
  179819. if (millisElapsed > 80)
  179820. {
  179821. const int newResult = (int) (((cyclesNow - cycles) / millisElapsed) / 1000);
  179822. if (millisElapsed > 500 || (lastResult == newResult && newResult > 100))
  179823. return newResult;
  179824. lastResult = newResult;
  179825. }
  179826. }
  179827. }
  179828. bool Time::setSystemTimeToThisTime() const throw()
  179829. {
  179830. SYSTEMTIME st;
  179831. st.wDayOfWeek = 0;
  179832. st.wYear = (WORD) getYear();
  179833. st.wMonth = (WORD) (getMonth() + 1);
  179834. st.wDay = (WORD) getDayOfMonth();
  179835. st.wHour = (WORD) getHours();
  179836. st.wMinute = (WORD) getMinutes();
  179837. st.wSecond = (WORD) getSeconds();
  179838. st.wMilliseconds = (WORD) (millisSinceEpoch % 1000);
  179839. // do this twice because of daylight saving conversion problems - the
  179840. // first one sets it up, the second one kicks it in.
  179841. return SetLocalTime (&st) != 0
  179842. && SetLocalTime (&st) != 0;
  179843. }
  179844. int SystemStats::getPageSize() throw()
  179845. {
  179846. SYSTEM_INFO systemInfo;
  179847. GetSystemInfo (&systemInfo);
  179848. return systemInfo.dwPageSize;
  179849. }
  179850. const String SystemStats::getLogonName()
  179851. {
  179852. TCHAR text [256];
  179853. DWORD len = numElementsInArray (text) - 2;
  179854. zerostruct (text);
  179855. GetUserName (text, &len);
  179856. return String (text, len);
  179857. }
  179858. const String SystemStats::getFullUserName()
  179859. {
  179860. return getLogonName();
  179861. }
  179862. #endif
  179863. /*** End of inlined file: juce_win32_SystemStats.cpp ***/
  179864. /*** Start of inlined file: juce_win32_Threads.cpp ***/
  179865. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  179866. // compiled on its own).
  179867. #if JUCE_INCLUDED_FILE
  179868. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179869. extern HWND juce_messageWindowHandle;
  179870. #endif
  179871. #if ! JUCE_USE_INTRINSICS
  179872. // In newer compilers, the inline versions of these are used (in juce_Atomic.h), but in
  179873. // older ones we have to actually call the ops as win32 functions..
  179874. void Atomic::increment (int32& variable) { InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179875. int32 Atomic::incrementAndReturn (int32& variable) { return InterlockedIncrement (reinterpret_cast <volatile long*> (&variable)); }
  179876. void Atomic::decrement (int32& variable) { InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179877. int32 Atomic::decrementAndReturn (int32& variable) { return InterlockedDecrement (reinterpret_cast <volatile long*> (&variable)); }
  179878. int32 Atomic::compareAndExchange (int32& destination, int32 newValue, int32 oldValue)
  179879. { return InterlockedCompareExchange (reinterpret_cast <volatile long*> (&destination), newValue, oldValue); }
  179880. #endif
  179881. void* Atomic::swapPointers (void* volatile* value1, void* volatile value2) { return InterlockedExchangePointer (value1, value2); }
  179882. CriticalSection::CriticalSection() throw()
  179883. {
  179884. // (just to check the MS haven't changed this structure and broken things...)
  179885. #if _MSC_VER >= 1400
  179886. static_jassert (sizeof (CRITICAL_SECTION) <= sizeof (internal));
  179887. #else
  179888. static_jassert (sizeof (CRITICAL_SECTION) <= 24);
  179889. #endif
  179890. InitializeCriticalSection ((CRITICAL_SECTION*) internal);
  179891. }
  179892. CriticalSection::~CriticalSection() throw()
  179893. {
  179894. DeleteCriticalSection ((CRITICAL_SECTION*) internal);
  179895. }
  179896. void CriticalSection::enter() const throw()
  179897. {
  179898. EnterCriticalSection ((CRITICAL_SECTION*) internal);
  179899. }
  179900. bool CriticalSection::tryEnter() const throw()
  179901. {
  179902. return TryEnterCriticalSection ((CRITICAL_SECTION*) internal) != FALSE;
  179903. }
  179904. void CriticalSection::exit() const throw()
  179905. {
  179906. LeaveCriticalSection ((CRITICAL_SECTION*) internal);
  179907. }
  179908. WaitableEvent::WaitableEvent() throw()
  179909. : internal (CreateEvent (0, FALSE, FALSE, 0))
  179910. {
  179911. }
  179912. WaitableEvent::~WaitableEvent() throw()
  179913. {
  179914. CloseHandle (internal);
  179915. }
  179916. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  179917. {
  179918. return WaitForSingleObject (internal, timeOutMillisecs) == WAIT_OBJECT_0;
  179919. }
  179920. void WaitableEvent::signal() const throw()
  179921. {
  179922. SetEvent (internal);
  179923. }
  179924. void WaitableEvent::reset() const throw()
  179925. {
  179926. ResetEvent (internal);
  179927. }
  179928. void JUCE_API juce_threadEntryPoint (void*);
  179929. static unsigned int __stdcall threadEntryProc (void* userData)
  179930. {
  179931. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  179932. AttachThreadInput (GetWindowThreadProcessId (juce_messageWindowHandle, 0),
  179933. GetCurrentThreadId(), TRUE);
  179934. #endif
  179935. juce_threadEntryPoint (userData);
  179936. _endthreadex (0);
  179937. return 0;
  179938. }
  179939. void juce_CloseThreadHandle (void* handle)
  179940. {
  179941. CloseHandle ((HANDLE) handle);
  179942. }
  179943. void* juce_createThread (void* userData)
  179944. {
  179945. unsigned int threadId;
  179946. return (void*) _beginthreadex (0, 0,
  179947. &threadEntryProc,
  179948. userData,
  179949. 0, &threadId);
  179950. }
  179951. void juce_killThread (void* handle)
  179952. {
  179953. if (handle != 0)
  179954. {
  179955. #ifdef JUCE_DEBUG
  179956. OutputDebugString (_T("** Warning - Forced thread termination **\n"));
  179957. #endif
  179958. TerminateThread (handle, 0);
  179959. }
  179960. }
  179961. void juce_setCurrentThreadName (const String& name)
  179962. {
  179963. #if defined (JUCE_DEBUG) && JUCE_MSVC
  179964. struct
  179965. {
  179966. DWORD dwType;
  179967. LPCSTR szName;
  179968. DWORD dwThreadID;
  179969. DWORD dwFlags;
  179970. } info;
  179971. info.dwType = 0x1000;
  179972. info.szName = name.toCString();
  179973. info.dwThreadID = GetCurrentThreadId();
  179974. info.dwFlags = 0;
  179975. #define MS_VC_EXCEPTION 0x406d1388
  179976. __try
  179977. {
  179978. RaiseException (MS_VC_EXCEPTION, 0, sizeof (info) / sizeof (ULONG_PTR), (ULONG_PTR*) &info);
  179979. }
  179980. __except (EXCEPTION_CONTINUE_EXECUTION)
  179981. {}
  179982. #else
  179983. (void) name;
  179984. #endif
  179985. }
  179986. Thread::ThreadID Thread::getCurrentThreadId()
  179987. {
  179988. return (ThreadID) (pointer_sized_int) GetCurrentThreadId();
  179989. }
  179990. // priority 1 to 10 where 5=normal, 1=low
  179991. bool juce_setThreadPriority (void* threadHandle, int priority)
  179992. {
  179993. int pri = THREAD_PRIORITY_TIME_CRITICAL;
  179994. if (priority < 1)
  179995. pri = THREAD_PRIORITY_IDLE;
  179996. else if (priority < 2)
  179997. pri = THREAD_PRIORITY_LOWEST;
  179998. else if (priority < 5)
  179999. pri = THREAD_PRIORITY_BELOW_NORMAL;
  180000. else if (priority < 7)
  180001. pri = THREAD_PRIORITY_NORMAL;
  180002. else if (priority < 9)
  180003. pri = THREAD_PRIORITY_ABOVE_NORMAL;
  180004. else if (priority < 10)
  180005. pri = THREAD_PRIORITY_HIGHEST;
  180006. if (threadHandle == 0)
  180007. threadHandle = GetCurrentThread();
  180008. return SetThreadPriority (threadHandle, pri) != FALSE;
  180009. }
  180010. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  180011. {
  180012. SetThreadAffinityMask (GetCurrentThread(), affinityMask);
  180013. }
  180014. static HANDLE sleepEvent = 0;
  180015. void juce_initialiseThreadEvents()
  180016. {
  180017. if (sleepEvent == 0)
  180018. #ifdef JUCE_DEBUG
  180019. sleepEvent = CreateEvent (0, 0, 0, _T("Juce Sleep Event"));
  180020. #else
  180021. sleepEvent = CreateEvent (0, 0, 0, 0);
  180022. #endif
  180023. }
  180024. void Thread::yield()
  180025. {
  180026. Sleep (0);
  180027. }
  180028. void JUCE_CALLTYPE Thread::sleep (const int millisecs)
  180029. {
  180030. if (millisecs >= 10)
  180031. {
  180032. Sleep (millisecs);
  180033. }
  180034. else
  180035. {
  180036. jassert (sleepEvent != 0);
  180037. // unlike Sleep() this is guaranteed to return to the current thread after
  180038. // the time expires, so we'll use this for short waits, which are more likely
  180039. // to need to be accurate
  180040. WaitForSingleObject (sleepEvent, millisecs);
  180041. }
  180042. }
  180043. static int lastProcessPriority = -1;
  180044. // called by WindowDriver because Windows does wierd things to process priority
  180045. // when you swap apps, and this forces an update when the app is brought to the front.
  180046. void juce_repeatLastProcessPriority()
  180047. {
  180048. if (lastProcessPriority >= 0) // (avoid changing this if it's not been explicitly set by the app..)
  180049. {
  180050. DWORD p;
  180051. switch (lastProcessPriority)
  180052. {
  180053. case Process::LowPriority:
  180054. p = IDLE_PRIORITY_CLASS;
  180055. break;
  180056. case Process::NormalPriority:
  180057. p = NORMAL_PRIORITY_CLASS;
  180058. break;
  180059. case Process::HighPriority:
  180060. p = HIGH_PRIORITY_CLASS;
  180061. break;
  180062. case Process::RealtimePriority:
  180063. p = REALTIME_PRIORITY_CLASS;
  180064. break;
  180065. default:
  180066. jassertfalse // bad priority value
  180067. return;
  180068. }
  180069. SetPriorityClass (GetCurrentProcess(), p);
  180070. }
  180071. }
  180072. void Process::setPriority (ProcessPriority prior)
  180073. {
  180074. if (lastProcessPriority != (int) prior)
  180075. {
  180076. lastProcessPriority = (int) prior;
  180077. juce_repeatLastProcessPriority();
  180078. }
  180079. }
  180080. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  180081. {
  180082. return IsDebuggerPresent() != FALSE;
  180083. }
  180084. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  180085. {
  180086. return juce_isRunningUnderDebugger();
  180087. }
  180088. void Process::raisePrivilege()
  180089. {
  180090. jassertfalse // xxx not implemented
  180091. }
  180092. void Process::lowerPrivilege()
  180093. {
  180094. jassertfalse // xxx not implemented
  180095. }
  180096. void Process::terminate()
  180097. {
  180098. #if defined (JUCE_DEBUG) && JUCE_MSVC && JUCE_CHECK_MEMORY_LEAKS
  180099. _CrtDumpMemoryLeaks();
  180100. #endif
  180101. // bullet in the head in case there's a problem shutting down..
  180102. ExitProcess (0);
  180103. }
  180104. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  180105. {
  180106. void* result = 0;
  180107. JUCE_TRY
  180108. {
  180109. result = (void*) LoadLibrary (name);
  180110. }
  180111. JUCE_CATCH_ALL
  180112. return result;
  180113. }
  180114. void PlatformUtilities::freeDynamicLibrary (void* h)
  180115. {
  180116. JUCE_TRY
  180117. {
  180118. if (h != 0)
  180119. FreeLibrary ((HMODULE) h);
  180120. }
  180121. JUCE_CATCH_ALL
  180122. }
  180123. void* PlatformUtilities::getProcedureEntryPoint (void* h, const String& name)
  180124. {
  180125. return (h != 0) ? (void*) GetProcAddress ((HMODULE) h, name.toCString()) : 0;
  180126. }
  180127. InterProcessLock::InterProcessLock (const String& name_)
  180128. : internal (0),
  180129. name (name_),
  180130. reentrancyLevel (0)
  180131. {
  180132. }
  180133. InterProcessLock::~InterProcessLock()
  180134. {
  180135. exit();
  180136. }
  180137. bool InterProcessLock::enter (const int timeOutMillisecs)
  180138. {
  180139. if (reentrancyLevel++ == 0)
  180140. {
  180141. internal = CreateMutex (0, TRUE, "Global\\" + name);
  180142. if (internal != 0 && GetLastError() == ERROR_ALREADY_EXISTS)
  180143. {
  180144. if (timeOutMillisecs == 0
  180145. || WaitForSingleObject (internal, (timeOutMillisecs < 0) ? INFINITE : timeOutMillisecs)
  180146. == WAIT_TIMEOUT)
  180147. {
  180148. ReleaseMutex (internal);
  180149. CloseHandle (internal);
  180150. internal = 0;
  180151. }
  180152. }
  180153. }
  180154. return (internal != 0);
  180155. }
  180156. void InterProcessLock::exit()
  180157. {
  180158. if (--reentrancyLevel == 0 && internal != 0)
  180159. {
  180160. ReleaseMutex (internal);
  180161. CloseHandle (internal);
  180162. internal = 0;
  180163. }
  180164. }
  180165. #endif
  180166. /*** End of inlined file: juce_win32_Threads.cpp ***/
  180167. /*** Start of inlined file: juce_win32_Files.cpp ***/
  180168. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180169. // compiled on its own).
  180170. #if JUCE_INCLUDED_FILE
  180171. #ifndef CSIDL_MYMUSIC
  180172. #define CSIDL_MYMUSIC 0x000d
  180173. #endif
  180174. #ifndef CSIDL_MYVIDEO
  180175. #define CSIDL_MYVIDEO 0x000e
  180176. #endif
  180177. const tchar File::separator = T('\\');
  180178. const tchar* File::separatorString = T("\\");
  180179. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  180180. {
  180181. if (fileName.isEmpty())
  180182. return false;
  180183. const DWORD attr = GetFileAttributes (fileName);
  180184. return dontCountDirectories ? ((attr & FILE_ATTRIBUTE_DIRECTORY) == 0)
  180185. : (attr != 0xffffffff);
  180186. }
  180187. bool juce_isDirectory (const String& fileName)
  180188. {
  180189. const DWORD attr = GetFileAttributes (fileName);
  180190. return (attr != 0xffffffff)
  180191. && ((attr & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180192. }
  180193. bool juce_canWriteToFile (const String& fileName)
  180194. {
  180195. const DWORD attr = GetFileAttributes (fileName);
  180196. return ((attr & FILE_ATTRIBUTE_READONLY) == 0);
  180197. }
  180198. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  180199. {
  180200. DWORD attr = GetFileAttributes (fileName);
  180201. if (attr == 0xffffffff)
  180202. return false;
  180203. if (isReadOnly != juce_canWriteToFile (fileName))
  180204. return true;
  180205. if (isReadOnly)
  180206. attr |= FILE_ATTRIBUTE_READONLY;
  180207. else
  180208. attr &= ~FILE_ATTRIBUTE_READONLY;
  180209. return SetFileAttributes (fileName, attr) != FALSE;
  180210. }
  180211. bool File::isHidden() const
  180212. {
  180213. return (GetFileAttributes (getFullPathName()) & FILE_ATTRIBUTE_HIDDEN) != 0;
  180214. }
  180215. bool juce_deleteFile (const String& fileName)
  180216. {
  180217. if (juce_isDirectory (fileName))
  180218. return RemoveDirectory (fileName) != 0;
  180219. return DeleteFile (fileName) != 0;
  180220. }
  180221. bool File::moveToTrash() const
  180222. {
  180223. if (! exists())
  180224. return true;
  180225. SHFILEOPSTRUCT fos;
  180226. zerostruct (fos);
  180227. // The string we pass in must be double null terminated..
  180228. String doubleNullTermPath (getFullPathName() + " ");
  180229. TCHAR* p = (TCHAR*) (const TCHAR*) doubleNullTermPath;
  180230. p [getFullPathName().length()] = 0;
  180231. fos.wFunc = FO_DELETE;
  180232. fos.hwnd = (HWND) 0;
  180233. fos.pFrom = p;
  180234. fos.pTo = NULL;
  180235. fos.fFlags = FOF_ALLOWUNDO | FOF_NOERRORUI | FOF_SILENT | FOF_NOCONFIRMATION
  180236. | FOF_NOCONFIRMMKDIR | FOF_RENAMEONCOLLISION;
  180237. return SHFileOperation (&fos) == 0;
  180238. }
  180239. bool juce_moveFile (const String& source, const String& dest)
  180240. {
  180241. return MoveFile (source, dest) != 0;
  180242. }
  180243. bool juce_copyFile (const String& source, const String& dest)
  180244. {
  180245. return CopyFile (source, dest, false) != 0;
  180246. }
  180247. void juce_createDirectory (const String& fileName)
  180248. {
  180249. if (! juce_fileExists (fileName, true))
  180250. {
  180251. CreateDirectory (fileName, 0);
  180252. }
  180253. }
  180254. // return 0 if not possible
  180255. void* juce_fileOpen (const String& fileName, bool forWriting)
  180256. {
  180257. HANDLE h;
  180258. if (forWriting)
  180259. {
  180260. h = CreateFile (fileName, GENERIC_WRITE, FILE_SHARE_READ, 0,
  180261. OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0);
  180262. if (h != INVALID_HANDLE_VALUE)
  180263. SetFilePointer (h, 0, 0, FILE_END);
  180264. else
  180265. h = 0;
  180266. }
  180267. else
  180268. {
  180269. h = CreateFile (fileName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0,
  180270. OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_SEQUENTIAL_SCAN, 0);
  180271. if (h == INVALID_HANDLE_VALUE)
  180272. h = 0;
  180273. }
  180274. return (void*) h;
  180275. }
  180276. void juce_fileClose (void* handle)
  180277. {
  180278. CloseHandle (handle);
  180279. }
  180280. int juce_fileRead (void* handle, void* buffer, int size)
  180281. {
  180282. DWORD num = 0;
  180283. ReadFile ((HANDLE) handle, buffer, size, &num, 0);
  180284. return num;
  180285. }
  180286. int juce_fileWrite (void* handle, const void* buffer, int size)
  180287. {
  180288. DWORD num;
  180289. WriteFile ((HANDLE) handle,
  180290. buffer, size,
  180291. &num, 0);
  180292. return num;
  180293. }
  180294. int64 juce_fileSetPosition (void* handle, int64 pos)
  180295. {
  180296. LARGE_INTEGER li;
  180297. li.QuadPart = pos;
  180298. li.LowPart = SetFilePointer ((HANDLE) handle,
  180299. li.LowPart,
  180300. &li.HighPart,
  180301. FILE_BEGIN); // (returns -1 if it fails)
  180302. return li.QuadPart;
  180303. }
  180304. int64 juce_fileGetPosition (void* handle)
  180305. {
  180306. LARGE_INTEGER li;
  180307. li.QuadPart = 0;
  180308. li.LowPart = SetFilePointer ((HANDLE) handle,
  180309. 0, &li.HighPart,
  180310. FILE_CURRENT); // (returns -1 if it fails)
  180311. return jmax ((int64) 0, li.QuadPart);
  180312. }
  180313. void juce_fileFlush (void* handle)
  180314. {
  180315. FlushFileBuffers ((HANDLE) handle);
  180316. }
  180317. int64 juce_getFileSize (const String& fileName)
  180318. {
  180319. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180320. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180321. {
  180322. return (((int64) attributes.nFileSizeHigh) << 32)
  180323. | attributes.nFileSizeLow;
  180324. }
  180325. return 0;
  180326. }
  180327. static int64 fileTimeToTime (const FILETIME* const ft)
  180328. {
  180329. // tell me if this fails!
  180330. static_jassert (sizeof (ULARGE_INTEGER) == sizeof (FILETIME));
  180331. #if JUCE_GCC
  180332. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000LL) / 10000;
  180333. #else
  180334. return (((const ULARGE_INTEGER*) ft)->QuadPart - 116444736000000000) / 10000;
  180335. #endif
  180336. }
  180337. static void timeToFileTime (const int64 time, FILETIME* const ft)
  180338. {
  180339. #if JUCE_GCC
  180340. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000LL;
  180341. #else
  180342. ((ULARGE_INTEGER*) ft)->QuadPart = time * 10000 + 116444736000000000;
  180343. #endif
  180344. }
  180345. void juce_getFileTimes (const String& fileName,
  180346. int64& modificationTime,
  180347. int64& accessTime,
  180348. int64& creationTime)
  180349. {
  180350. WIN32_FILE_ATTRIBUTE_DATA attributes;
  180351. if (GetFileAttributesEx (fileName, GetFileExInfoStandard, &attributes))
  180352. {
  180353. modificationTime = fileTimeToTime (&attributes.ftLastWriteTime);
  180354. creationTime = fileTimeToTime (&attributes.ftCreationTime);
  180355. accessTime = fileTimeToTime (&attributes.ftLastAccessTime);
  180356. }
  180357. else
  180358. {
  180359. creationTime = accessTime = modificationTime = 0;
  180360. }
  180361. }
  180362. bool juce_setFileTimes (const String& fileName,
  180363. int64 modificationTime,
  180364. int64 accessTime,
  180365. int64 creationTime)
  180366. {
  180367. FILETIME m, a, c;
  180368. if (modificationTime > 0)
  180369. timeToFileTime (modificationTime, &m);
  180370. if (accessTime > 0)
  180371. timeToFileTime (accessTime, &a);
  180372. if (creationTime > 0)
  180373. timeToFileTime (creationTime, &c);
  180374. void* const h = juce_fileOpen (fileName, true);
  180375. bool ok = false;
  180376. if (h != 0)
  180377. {
  180378. ok = SetFileTime ((HANDLE) h,
  180379. (creationTime > 0) ? &c : 0,
  180380. (accessTime > 0) ? &a : 0,
  180381. (modificationTime > 0) ? &m : 0) != 0;
  180382. juce_fileClose (h);
  180383. }
  180384. return ok;
  180385. }
  180386. // return '\0' separated list of strings
  180387. const StringArray juce_getFileSystemRoots()
  180388. {
  180389. TCHAR buffer [2048];
  180390. buffer[0] = 0;
  180391. buffer[1] = 0;
  180392. GetLogicalDriveStrings (2048, buffer);
  180393. TCHAR* n = buffer;
  180394. StringArray roots;
  180395. while (*n != 0)
  180396. {
  180397. roots.add (String (n));
  180398. while (*n++ != 0)
  180399. {
  180400. }
  180401. }
  180402. roots.sort (true);
  180403. return roots;
  180404. }
  180405. const String juce_getVolumeLabel (const String& filenameOnVolume,
  180406. int& volumeSerialNumber)
  180407. {
  180408. TCHAR n [4];
  180409. n[0] = *(const TCHAR*) filenameOnVolume;
  180410. n[1] = L':';
  180411. n[2] = L'\\';
  180412. n[3] = 0;
  180413. TCHAR dest [64];
  180414. DWORD serialNum;
  180415. if (! GetVolumeInformation (n, dest, 64, (DWORD*) &serialNum, 0, 0, 0, 0))
  180416. {
  180417. dest[0] = 0;
  180418. serialNum = 0;
  180419. }
  180420. volumeSerialNumber = serialNum;
  180421. return String (dest);
  180422. }
  180423. static int64 getDiskSpaceInfo (String fn, const bool total)
  180424. {
  180425. if (fn[1] == T(':'))
  180426. fn = fn.substring (0, 2) + T("\\");
  180427. ULARGE_INTEGER spc, tot, totFree;
  180428. if (GetDiskFreeSpaceEx (fn, &spc, &tot, &totFree))
  180429. return (int64) (total ? tot.QuadPart
  180430. : spc.QuadPart);
  180431. return 0;
  180432. }
  180433. int64 File::getBytesFreeOnVolume() const
  180434. {
  180435. return getDiskSpaceInfo (getFullPathName(), false);
  180436. }
  180437. int64 File::getVolumeTotalSize() const
  180438. {
  180439. return getDiskSpaceInfo (getFullPathName(), true);
  180440. }
  180441. static unsigned int getWindowsDriveType (const String& fileName)
  180442. {
  180443. TCHAR n[4];
  180444. n[0] = *(const TCHAR*) fileName;
  180445. n[1] = L':';
  180446. n[2] = L'\\';
  180447. n[3] = 0;
  180448. return GetDriveType (n);
  180449. }
  180450. bool File::isOnCDRomDrive() const
  180451. {
  180452. return getWindowsDriveType (getFullPathName()) == DRIVE_CDROM;
  180453. }
  180454. bool File::isOnHardDisk() const
  180455. {
  180456. if (fullPath.isEmpty())
  180457. return false;
  180458. const unsigned int n = getWindowsDriveType (getFullPathName());
  180459. if (fullPath.toLowerCase()[0] <= 'b'
  180460. && fullPath[1] == T(':'))
  180461. {
  180462. return n != DRIVE_REMOVABLE;
  180463. }
  180464. else
  180465. {
  180466. return n != DRIVE_CDROM && n != DRIVE_REMOTE;
  180467. }
  180468. }
  180469. bool File::isOnRemovableDrive() const
  180470. {
  180471. if (fullPath.isEmpty())
  180472. return false;
  180473. const unsigned int n = getWindowsDriveType (getFullPathName());
  180474. return n == DRIVE_CDROM
  180475. || n == DRIVE_REMOTE
  180476. || n == DRIVE_REMOVABLE
  180477. || n == DRIVE_RAMDISK;
  180478. }
  180479. #define MAX_PATH_CHARS (MAX_PATH + 256)
  180480. static const File juce_getSpecialFolderPath (int type)
  180481. {
  180482. WCHAR path [MAX_PATH_CHARS];
  180483. if (SHGetSpecialFolderPath (0, path, type, 0))
  180484. return File (String (path));
  180485. return File::nonexistent;
  180486. }
  180487. const File JUCE_CALLTYPE File::getSpecialLocation (const SpecialLocationType type)
  180488. {
  180489. int csidlType = 0;
  180490. switch (type)
  180491. {
  180492. case userHomeDirectory:
  180493. csidlType = CSIDL_PROFILE;
  180494. break;
  180495. case userDocumentsDirectory:
  180496. csidlType = CSIDL_PERSONAL;
  180497. break;
  180498. case userDesktopDirectory:
  180499. csidlType = CSIDL_DESKTOP;
  180500. break;
  180501. case userApplicationDataDirectory:
  180502. csidlType = CSIDL_APPDATA;
  180503. break;
  180504. case commonApplicationDataDirectory:
  180505. csidlType = CSIDL_COMMON_APPDATA;
  180506. break;
  180507. case globalApplicationsDirectory:
  180508. csidlType = CSIDL_PROGRAM_FILES;
  180509. break;
  180510. case userMusicDirectory:
  180511. csidlType = CSIDL_MYMUSIC;
  180512. break;
  180513. case userMoviesDirectory:
  180514. csidlType = CSIDL_MYVIDEO;
  180515. break;
  180516. case tempDirectory:
  180517. {
  180518. WCHAR dest [2048];
  180519. dest[0] = 0;
  180520. GetTempPath (2048, dest);
  180521. return File (String (dest));
  180522. }
  180523. case invokedExecutableFile:
  180524. case currentExecutableFile:
  180525. case currentApplicationFile:
  180526. {
  180527. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  180528. WCHAR dest [MAX_PATH_CHARS];
  180529. dest[0] = 0;
  180530. GetModuleFileName (moduleHandle, dest, MAX_PATH_CHARS);
  180531. return File (String (dest));
  180532. }
  180533. break;
  180534. default:
  180535. jassertfalse // unknown type?
  180536. return File::nonexistent;
  180537. }
  180538. return juce_getSpecialFolderPath (csidlType);
  180539. }
  180540. const File File::getCurrentWorkingDirectory()
  180541. {
  180542. WCHAR dest [MAX_PATH_CHARS];
  180543. dest[0] = 0;
  180544. GetCurrentDirectory (MAX_PATH_CHARS, dest);
  180545. return File (String (dest));
  180546. }
  180547. bool File::setAsCurrentWorkingDirectory() const
  180548. {
  180549. return SetCurrentDirectory (getFullPathName()) != FALSE;
  180550. }
  180551. const String File::getVersion() const
  180552. {
  180553. String result;
  180554. DWORD handle = 0;
  180555. DWORD bufferSize = GetFileVersionInfoSize (getFullPathName(), &handle);
  180556. HeapBlock <char> buffer;
  180557. buffer.calloc (bufferSize);
  180558. if (GetFileVersionInfo (getFullPathName(), 0, bufferSize, buffer))
  180559. {
  180560. VS_FIXEDFILEINFO* vffi;
  180561. UINT len = 0;
  180562. if (VerQueryValue (buffer, (LPTSTR) _T("\\"), (LPVOID*) &vffi, &len))
  180563. {
  180564. result << (int) HIWORD (vffi->dwFileVersionMS) << "."
  180565. << (int) LOWORD (vffi->dwFileVersionMS) << "."
  180566. << (int) HIWORD (vffi->dwFileVersionLS) << "."
  180567. << (int) LOWORD (vffi->dwFileVersionLS);
  180568. }
  180569. }
  180570. return result;
  180571. }
  180572. const File File::getLinkedTarget() const
  180573. {
  180574. File result (*this);
  180575. String p (getFullPathName());
  180576. if (! exists())
  180577. p += T(".lnk");
  180578. else if (getFileExtension() != T(".lnk"))
  180579. return result;
  180580. ComSmartPtr <IShellLink> shellLink;
  180581. if (SUCCEEDED (shellLink.CoCreateInstance (CLSID_ShellLink, CLSCTX_INPROC_SERVER)))
  180582. {
  180583. ComSmartPtr <IPersistFile> persistFile;
  180584. if (SUCCEEDED (shellLink->QueryInterface (IID_IPersistFile, (LPVOID*) &persistFile)))
  180585. {
  180586. if (SUCCEEDED (persistFile->Load ((const WCHAR*) p, STGM_READ))
  180587. && SUCCEEDED (shellLink->Resolve (0, SLR_ANY_MATCH | SLR_NO_UI)))
  180588. {
  180589. WIN32_FIND_DATA winFindData;
  180590. WCHAR resolvedPath [MAX_PATH];
  180591. if (SUCCEEDED (shellLink->GetPath (resolvedPath, MAX_PATH, &winFindData, SLGP_UNCPRIORITY)))
  180592. result = File (resolvedPath);
  180593. }
  180594. }
  180595. }
  180596. return result;
  180597. }
  180598. template <class FindDataType>
  180599. static void getFindFileInfo (FindDataType& findData,
  180600. String& filename, bool* const isDir, bool* const isHidden,
  180601. int64* const fileSize, Time* const modTime, Time* const creationTime,
  180602. bool* const isReadOnly)
  180603. {
  180604. filename = findData.cFileName;
  180605. if (isDir != 0)
  180606. *isDir = ((findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);
  180607. if (isHidden != 0)
  180608. *isHidden = ((findData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) != 0);
  180609. if (fileSize != 0)
  180610. *fileSize = findData.nFileSizeLow + (((int64) findData.nFileSizeHigh) << 32);
  180611. if (modTime != 0)
  180612. *modTime = fileTimeToTime (&findData.ftLastWriteTime);
  180613. if (creationTime != 0)
  180614. *creationTime = fileTimeToTime (&findData.ftCreationTime);
  180615. if (isReadOnly != 0)
  180616. *isReadOnly = ((findData.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
  180617. }
  180618. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResult,
  180619. bool* isDir, bool* isHidden, int64* fileSize,
  180620. Time* modTime, Time* creationTime, bool* isReadOnly)
  180621. {
  180622. String wc (directory);
  180623. if (! wc.endsWithChar (File::separator))
  180624. wc += File::separator;
  180625. wc += wildCard;
  180626. WIN32_FIND_DATA findData;
  180627. HANDLE h = FindFirstFile (wc, &findData);
  180628. if (h != INVALID_HANDLE_VALUE)
  180629. {
  180630. getFindFileInfo (findData, firstResult, isDir, isHidden, fileSize,
  180631. modTime, creationTime, isReadOnly);
  180632. return h;
  180633. }
  180634. firstResult = String::empty;
  180635. return 0;
  180636. }
  180637. bool juce_findFileNext (void* handle, String& resultFile,
  180638. bool* isDir, bool* isHidden, int64* fileSize,
  180639. Time* modTime, Time* creationTime, bool* isReadOnly)
  180640. {
  180641. WIN32_FIND_DATA findData;
  180642. if (handle != 0 && FindNextFile ((HANDLE) handle, &findData) != 0)
  180643. {
  180644. getFindFileInfo (findData, resultFile, isDir, isHidden, fileSize,
  180645. modTime, creationTime, isReadOnly);
  180646. return true;
  180647. }
  180648. resultFile = String::empty;
  180649. return false;
  180650. }
  180651. void juce_findFileClose (void* handle)
  180652. {
  180653. FindClose (handle);
  180654. }
  180655. bool juce_launchFile (const String& fileName,
  180656. const String& parameters)
  180657. {
  180658. HINSTANCE hInstance = 0;
  180659. JUCE_TRY
  180660. {
  180661. hInstance = ShellExecute (0, 0, fileName, parameters, 0, SW_SHOWDEFAULT);
  180662. }
  180663. JUCE_CATCH_ALL
  180664. return hInstance > (HINSTANCE) 32;
  180665. }
  180666. void File::revealToUser() const
  180667. {
  180668. if (isDirectory())
  180669. startAsProcess();
  180670. else if (getParentDirectory().exists())
  180671. getParentDirectory().startAsProcess();
  180672. }
  180673. struct NamedPipeInternal
  180674. {
  180675. HANDLE pipeH;
  180676. HANDLE cancelEvent;
  180677. bool connected, createdPipe;
  180678. NamedPipeInternal()
  180679. : pipeH (0),
  180680. cancelEvent (0),
  180681. connected (false),
  180682. createdPipe (false)
  180683. {
  180684. cancelEvent = CreateEvent (0, FALSE, FALSE, 0);
  180685. }
  180686. ~NamedPipeInternal()
  180687. {
  180688. disconnect();
  180689. if (pipeH != 0)
  180690. CloseHandle (pipeH);
  180691. CloseHandle (cancelEvent);
  180692. }
  180693. bool connect (const int timeOutMs)
  180694. {
  180695. if (! createdPipe)
  180696. return true;
  180697. if (! connected)
  180698. {
  180699. OVERLAPPED over;
  180700. zerostruct (over);
  180701. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180702. if (ConnectNamedPipe (pipeH, &over))
  180703. {
  180704. connected = false; // yes, you read that right. In overlapped mode it should always return 0.
  180705. }
  180706. else
  180707. {
  180708. const int err = GetLastError();
  180709. if (err == ERROR_IO_PENDING || err == ERROR_PIPE_LISTENING)
  180710. {
  180711. HANDLE handles[] = { over.hEvent, cancelEvent };
  180712. if (WaitForMultipleObjects (2, handles, FALSE,
  180713. timeOutMs >= 0 ? timeOutMs : INFINITE) == WAIT_OBJECT_0)
  180714. connected = true;
  180715. }
  180716. else if (err == ERROR_PIPE_CONNECTED)
  180717. {
  180718. connected = true;
  180719. }
  180720. }
  180721. CloseHandle (over.hEvent);
  180722. }
  180723. return connected;
  180724. }
  180725. void disconnect()
  180726. {
  180727. if (connected)
  180728. {
  180729. DisconnectNamedPipe (pipeH);
  180730. connected = false;
  180731. }
  180732. }
  180733. };
  180734. void NamedPipe::close()
  180735. {
  180736. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180737. delete intern;
  180738. internal = 0;
  180739. }
  180740. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  180741. {
  180742. close();
  180743. NamedPipeInternal* const intern = new NamedPipeInternal();
  180744. String file ("\\\\.\\pipe\\");
  180745. file += pipeName;
  180746. intern->createdPipe = createPipe;
  180747. if (createPipe)
  180748. {
  180749. intern->pipeH = CreateNamedPipe (file, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED, 0,
  180750. PIPE_UNLIMITED_INSTANCES,
  180751. 4096, 4096, 0, NULL);
  180752. }
  180753. else
  180754. {
  180755. intern->pipeH = CreateFile (file, GENERIC_READ | GENERIC_WRITE, 0, 0, OPEN_EXISTING,
  180756. FILE_FLAG_OVERLAPPED, 0);
  180757. }
  180758. if (intern->pipeH != INVALID_HANDLE_VALUE)
  180759. {
  180760. internal = intern;
  180761. return true;
  180762. }
  180763. delete intern;
  180764. return false;
  180765. }
  180766. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int timeOutMilliseconds)
  180767. {
  180768. int bytesRead = -1;
  180769. bool waitAgain = true;
  180770. while (waitAgain && internal != 0)
  180771. {
  180772. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180773. waitAgain = false;
  180774. if (! intern->connect (timeOutMilliseconds))
  180775. break;
  180776. if (maxBytesToRead <= 0)
  180777. return 0;
  180778. OVERLAPPED over;
  180779. zerostruct (over);
  180780. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180781. unsigned long numRead;
  180782. if (ReadFile (intern->pipeH, destBuffer, maxBytesToRead, &numRead, &over))
  180783. {
  180784. bytesRead = (int) numRead;
  180785. }
  180786. else if (GetLastError() == ERROR_IO_PENDING)
  180787. {
  180788. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180789. DWORD waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180790. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180791. : INFINITE);
  180792. if (waitResult != WAIT_OBJECT_0)
  180793. {
  180794. // if the operation timed out, let's cancel it...
  180795. CancelIo (intern->pipeH);
  180796. WaitForSingleObject (over.hEvent, INFINITE); // makes sure cancel is complete
  180797. }
  180798. if (GetOverlappedResult (intern->pipeH, &over, &numRead, FALSE))
  180799. {
  180800. bytesRead = (int) numRead;
  180801. }
  180802. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  180803. {
  180804. intern->disconnect();
  180805. waitAgain = true;
  180806. }
  180807. }
  180808. else
  180809. {
  180810. waitAgain = internal != 0;
  180811. Sleep (5);
  180812. }
  180813. CloseHandle (over.hEvent);
  180814. }
  180815. return bytesRead;
  180816. }
  180817. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  180818. {
  180819. int bytesWritten = -1;
  180820. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180821. if (intern != 0 && intern->connect (timeOutMilliseconds))
  180822. {
  180823. if (numBytesToWrite <= 0)
  180824. return 0;
  180825. OVERLAPPED over;
  180826. zerostruct (over);
  180827. over.hEvent = CreateEvent (0, TRUE, FALSE, 0);
  180828. unsigned long numWritten;
  180829. if (WriteFile (intern->pipeH, sourceBuffer, numBytesToWrite, &numWritten, &over))
  180830. {
  180831. bytesWritten = (int) numWritten;
  180832. }
  180833. else if (GetLastError() == ERROR_IO_PENDING)
  180834. {
  180835. HANDLE handles[] = { over.hEvent, intern->cancelEvent };
  180836. DWORD waitResult;
  180837. waitResult = WaitForMultipleObjects (2, handles, FALSE,
  180838. timeOutMilliseconds >= 0 ? timeOutMilliseconds
  180839. : INFINITE);
  180840. if (waitResult != WAIT_OBJECT_0)
  180841. {
  180842. CancelIo (intern->pipeH);
  180843. WaitForSingleObject (over.hEvent, INFINITE);
  180844. }
  180845. if (GetOverlappedResult (intern->pipeH, &over, &numWritten, FALSE))
  180846. {
  180847. bytesWritten = (int) numWritten;
  180848. }
  180849. else if (GetLastError() == ERROR_BROKEN_PIPE && intern->createdPipe)
  180850. {
  180851. intern->disconnect();
  180852. }
  180853. }
  180854. CloseHandle (over.hEvent);
  180855. }
  180856. return bytesWritten;
  180857. }
  180858. void NamedPipe::cancelPendingReads()
  180859. {
  180860. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  180861. if (intern != 0)
  180862. SetEvent (intern->cancelEvent);
  180863. }
  180864. #endif
  180865. /*** End of inlined file: juce_win32_Files.cpp ***/
  180866. /*** Start of inlined file: juce_win32_Network.cpp ***/
  180867. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  180868. // compiled on its own).
  180869. #if JUCE_INCLUDED_FILE
  180870. #ifndef INTERNET_FLAG_NEED_FILE
  180871. #define INTERNET_FLAG_NEED_FILE 0x00000010
  180872. #endif
  180873. #ifndef INTERNET_OPTION_DISABLE_AUTODIAL
  180874. #define INTERNET_OPTION_DISABLE_AUTODIAL 70
  180875. #endif
  180876. bool juce_isOnLine()
  180877. {
  180878. DWORD connectionType;
  180879. return InternetGetConnectedState (&connectionType, 0) != 0
  180880. || (connectionType & (INTERNET_CONNECTION_LAN | INTERNET_CONNECTION_PROXY)) != 0;
  180881. }
  180882. struct ConnectionAndRequestStruct
  180883. {
  180884. HINTERNET connection, request;
  180885. };
  180886. static HINTERNET sessionHandle = 0;
  180887. #ifndef WORKAROUND_TIMEOUT_BUG
  180888. //#define WORKAROUND_TIMEOUT_BUG 1
  180889. #endif
  180890. #if WORKAROUND_TIMEOUT_BUG
  180891. // Required because of a Microsoft bug in setting a timeout
  180892. class InternetConnectThread : public Thread
  180893. {
  180894. public:
  180895. InternetConnectThread (URL_COMPONENTS& uc_, HINTERNET& connection_, const bool isFtp_)
  180896. : Thread ("Internet"), uc (uc_), connection (connection_), isFtp (isFtp_)
  180897. {
  180898. startThread();
  180899. }
  180900. ~InternetConnectThread()
  180901. {
  180902. stopThread (60000);
  180903. }
  180904. void run()
  180905. {
  180906. connection = InternetConnect (sessionHandle, uc.lpszHostName,
  180907. uc.nPort, _T(""), _T(""),
  180908. isFtp ? INTERNET_SERVICE_FTP
  180909. : INTERNET_SERVICE_HTTP,
  180910. 0, 0);
  180911. notify();
  180912. }
  180913. juce_UseDebuggingNewOperator
  180914. private:
  180915. URL_COMPONENTS& uc;
  180916. HINTERNET& connection;
  180917. const bool isFtp;
  180918. InternetConnectThread (const InternetConnectThread&);
  180919. InternetConnectThread& operator= (const InternetConnectThread&);
  180920. };
  180921. #endif
  180922. void* juce_openInternetFile (const String& url,
  180923. const String& headers,
  180924. const MemoryBlock& postData,
  180925. const bool isPost,
  180926. URL::OpenStreamProgressCallback* callback,
  180927. void* callbackContext,
  180928. int timeOutMs)
  180929. {
  180930. if (sessionHandle == 0)
  180931. sessionHandle = InternetOpen (_T("juce"),
  180932. INTERNET_OPEN_TYPE_PRECONFIG,
  180933. 0, 0, 0);
  180934. if (sessionHandle != 0)
  180935. {
  180936. // break up the url..
  180937. TCHAR file[1024], server[1024];
  180938. URL_COMPONENTS uc;
  180939. zerostruct (uc);
  180940. uc.dwStructSize = sizeof (uc);
  180941. uc.dwUrlPathLength = sizeof (file);
  180942. uc.dwHostNameLength = sizeof (server);
  180943. uc.lpszUrlPath = file;
  180944. uc.lpszHostName = server;
  180945. if (InternetCrackUrl (url, 0, 0, &uc))
  180946. {
  180947. int disable = 1;
  180948. InternetSetOption (sessionHandle, INTERNET_OPTION_DISABLE_AUTODIAL, &disable, sizeof (disable));
  180949. if (timeOutMs == 0)
  180950. timeOutMs = 30000;
  180951. else if (timeOutMs < 0)
  180952. timeOutMs = -1;
  180953. InternetSetOption (sessionHandle, INTERNET_OPTION_CONNECT_TIMEOUT, &timeOutMs, sizeof (timeOutMs));
  180954. const bool isFtp = url.startsWithIgnoreCase (T("ftp:"));
  180955. #if WORKAROUND_TIMEOUT_BUG
  180956. HINTERNET connection = 0;
  180957. {
  180958. InternetConnectThread connectThread (uc, connection, isFtp);
  180959. connectThread.wait (timeOutMs);
  180960. if (connection == 0)
  180961. {
  180962. InternetCloseHandle (sessionHandle);
  180963. sessionHandle = 0;
  180964. }
  180965. }
  180966. #else
  180967. HINTERNET connection = InternetConnect (sessionHandle,
  180968. uc.lpszHostName,
  180969. uc.nPort,
  180970. _T(""), _T(""),
  180971. isFtp ? INTERNET_SERVICE_FTP
  180972. : INTERNET_SERVICE_HTTP,
  180973. 0, 0);
  180974. #endif
  180975. if (connection != 0)
  180976. {
  180977. if (isFtp)
  180978. {
  180979. HINTERNET request = FtpOpenFile (connection,
  180980. uc.lpszUrlPath,
  180981. GENERIC_READ,
  180982. FTP_TRANSFER_TYPE_BINARY | INTERNET_FLAG_NEED_FILE,
  180983. 0);
  180984. ConnectionAndRequestStruct* const result = new ConnectionAndRequestStruct();
  180985. result->connection = connection;
  180986. result->request = request;
  180987. return result;
  180988. }
  180989. else
  180990. {
  180991. const TCHAR* mimeTypes[] = { _T("*/*"), 0 };
  180992. DWORD flags = INTERNET_FLAG_RELOAD | INTERNET_FLAG_NO_CACHE_WRITE;
  180993. if (url.startsWithIgnoreCase (T("https:")))
  180994. flags |= INTERNET_FLAG_SECURE; // (this flag only seems necessary if the OS is running IE6 -
  180995. // IE7 seems to automatically work out when it's https)
  180996. HINTERNET request = HttpOpenRequest (connection,
  180997. isPost ? _T("POST")
  180998. : _T("GET"),
  180999. uc.lpszUrlPath,
  181000. 0, 0, mimeTypes, flags, 0);
  181001. if (request != 0)
  181002. {
  181003. INTERNET_BUFFERS buffers;
  181004. zerostruct (buffers);
  181005. buffers.dwStructSize = sizeof (INTERNET_BUFFERS);
  181006. buffers.lpcszHeader = (LPCTSTR) headers;
  181007. buffers.dwHeadersLength = headers.length();
  181008. buffers.dwBufferTotal = (DWORD) postData.getSize();
  181009. ConnectionAndRequestStruct* result = 0;
  181010. if (HttpSendRequestEx (request, &buffers, 0, HSR_INITIATE, 0))
  181011. {
  181012. int bytesSent = 0;
  181013. for (;;)
  181014. {
  181015. const int bytesToDo = jmin (1024, (int) postData.getSize() - bytesSent);
  181016. DWORD bytesDone = 0;
  181017. if (bytesToDo > 0
  181018. && ! InternetWriteFile (request,
  181019. ((const char*) postData.getData()) + bytesSent,
  181020. bytesToDo, &bytesDone))
  181021. {
  181022. break;
  181023. }
  181024. if (bytesToDo == 0 || (int) bytesDone < bytesToDo)
  181025. {
  181026. result = new ConnectionAndRequestStruct();
  181027. result->connection = connection;
  181028. result->request = request;
  181029. HttpEndRequest (request, 0, 0, 0);
  181030. return result;
  181031. }
  181032. bytesSent += bytesDone;
  181033. if (callback != 0 && ! callback (callbackContext, bytesSent, postData.getSize()))
  181034. break;
  181035. }
  181036. }
  181037. InternetCloseHandle (request);
  181038. }
  181039. InternetCloseHandle (connection);
  181040. }
  181041. }
  181042. }
  181043. }
  181044. return 0;
  181045. }
  181046. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  181047. {
  181048. DWORD bytesRead = 0;
  181049. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181050. if (crs != 0)
  181051. InternetReadFile (crs->request,
  181052. buffer, bytesToRead,
  181053. &bytesRead);
  181054. return bytesRead;
  181055. }
  181056. int juce_seekInInternetFile (void* handle, int newPosition)
  181057. {
  181058. if (handle != 0)
  181059. {
  181060. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181061. return InternetSetFilePointer (crs->request,
  181062. newPosition, 0,
  181063. FILE_BEGIN, 0);
  181064. }
  181065. else
  181066. {
  181067. return -1;
  181068. }
  181069. }
  181070. int64 juce_getInternetFileContentLength (void* handle)
  181071. {
  181072. const ConnectionAndRequestStruct* const crs = (const ConnectionAndRequestStruct*) handle;
  181073. if (crs != 0)
  181074. {
  181075. DWORD index = 0;
  181076. DWORD result = 0;
  181077. DWORD size = sizeof (result);
  181078. if (HttpQueryInfo (crs->request,
  181079. HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER,
  181080. &result,
  181081. &size,
  181082. &index))
  181083. {
  181084. return (int64) result;
  181085. }
  181086. }
  181087. return -1;
  181088. }
  181089. void juce_closeInternetFile (void* handle)
  181090. {
  181091. if (handle != 0)
  181092. {
  181093. ConnectionAndRequestStruct* const crs = (ConnectionAndRequestStruct*) handle;
  181094. InternetCloseHandle (crs->request);
  181095. InternetCloseHandle (crs->connection);
  181096. delete crs;
  181097. }
  181098. }
  181099. static int getMACAddressViaGetAdaptersInfo (int64* addresses, int maxNum, const bool littleEndian) throw()
  181100. {
  181101. int numFound = 0;
  181102. DynamicLibraryLoader dll ("iphlpapi.dll");
  181103. DynamicLibraryImport (GetAdaptersInfo, getAdaptersInfo, DWORD, dll, (PIP_ADAPTER_INFO, PULONG))
  181104. if (getAdaptersInfo != 0)
  181105. {
  181106. ULONG len = sizeof (IP_ADAPTER_INFO);
  181107. MemoryBlock mb;
  181108. PIP_ADAPTER_INFO adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  181109. if (getAdaptersInfo (adapterInfo, &len) == ERROR_BUFFER_OVERFLOW)
  181110. {
  181111. mb.setSize (len);
  181112. adapterInfo = (PIP_ADAPTER_INFO) mb.getData();
  181113. }
  181114. if (getAdaptersInfo (adapterInfo, &len) == NO_ERROR)
  181115. {
  181116. PIP_ADAPTER_INFO adapter = adapterInfo;
  181117. while (adapter != 0)
  181118. {
  181119. int64 mac = 0;
  181120. for (unsigned int i = 0; i < adapter->AddressLength; ++i)
  181121. mac = (mac << 8) | adapter->Address[i];
  181122. if (littleEndian)
  181123. mac = (int64) ByteOrder::swap ((uint64) mac);
  181124. if (numFound < maxNum && mac != 0)
  181125. addresses [numFound++] = mac;
  181126. adapter = adapter->Next;
  181127. }
  181128. }
  181129. }
  181130. return numFound;
  181131. }
  181132. struct ASTAT
  181133. {
  181134. ADAPTER_STATUS adapt;
  181135. NAME_BUFFER NameBuff [30];
  181136. };
  181137. static int getMACAddressesViaNetBios (int64* addresses, int maxNum, const bool littleEndian) throw()
  181138. {
  181139. int numFound = 0;
  181140. DynamicLibraryLoader dll ("netapi32.dll");
  181141. DynamicLibraryImport (Netbios, NetbiosCall, UCHAR, dll, (PNCB))
  181142. if (NetbiosCall != 0)
  181143. {
  181144. NCB ncb;
  181145. zerostruct (ncb);
  181146. ASTAT astat;
  181147. zerostruct (astat);
  181148. LANA_ENUM enums;
  181149. zerostruct (enums);
  181150. ncb.ncb_command = NCBENUM;
  181151. ncb.ncb_buffer = (unsigned char*) &enums;
  181152. ncb.ncb_length = sizeof (LANA_ENUM);
  181153. NetbiosCall (&ncb);
  181154. for (int i = 0; i < enums.length; ++i)
  181155. {
  181156. zerostruct (ncb);
  181157. ncb.ncb_command = NCBRESET;
  181158. ncb.ncb_lana_num = enums.lana[i];
  181159. if (NetbiosCall (&ncb) == 0)
  181160. {
  181161. zerostruct (ncb);
  181162. memcpy (ncb.ncb_callname, "* ", NCBNAMSZ);
  181163. ncb.ncb_command = NCBASTAT;
  181164. ncb.ncb_lana_num = enums.lana[i];
  181165. ncb.ncb_buffer = (unsigned char*) &astat;
  181166. ncb.ncb_length = sizeof (ASTAT);
  181167. if (NetbiosCall (&ncb) == 0)
  181168. {
  181169. if (astat.adapt.adapter_type == 0xfe)
  181170. {
  181171. uint64 mac = 0;
  181172. for (int i = 6; --i >= 0;)
  181173. mac = (mac << 8) | astat.adapt.adapter_address [littleEndian ? i : (5 - i)];
  181174. if (numFound < maxNum && mac != 0)
  181175. addresses [numFound++] = mac;
  181176. }
  181177. }
  181178. }
  181179. }
  181180. }
  181181. return numFound;
  181182. }
  181183. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  181184. {
  181185. int numFound = getMACAddressViaGetAdaptersInfo (addresses, maxNum, littleEndian);
  181186. if (numFound == 0)
  181187. numFound = getMACAddressesViaNetBios (addresses, maxNum, littleEndian);
  181188. return numFound;
  181189. }
  181190. typedef ULONG (WINAPI *MAPISendMailType) (LHANDLE, ULONG, lpMapiMessage, ::FLAGS, ULONG);
  181191. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  181192. const String& emailSubject,
  181193. const String& bodyText,
  181194. const StringArray& filesToAttach)
  181195. {
  181196. HMODULE h = LoadLibraryA ("MAPI32.dll");
  181197. MAPISendMailType mapiSendMail = (MAPISendMailType) GetProcAddress (h, "MAPISendMail");
  181198. bool ok = false;
  181199. if (mapiSendMail != 0)
  181200. {
  181201. MapiMessage message;
  181202. zerostruct (message);
  181203. message.lpszSubject = (LPSTR) emailSubject.toCString();
  181204. message.lpszNoteText = (LPSTR) bodyText.toCString();
  181205. MapiRecipDesc recip;
  181206. zerostruct (recip);
  181207. recip.ulRecipClass = MAPI_TO;
  181208. String targetEmailAddress_ (targetEmailAddress);
  181209. if (targetEmailAddress_.isEmpty())
  181210. targetEmailAddress_ = " "; // (Windows Mail can't deal with a blank address)
  181211. recip.lpszName = (LPSTR) targetEmailAddress_.toCString();
  181212. message.nRecipCount = 1;
  181213. message.lpRecips = &recip;
  181214. MemoryBlock mb (sizeof (MapiFileDesc) * filesToAttach.size());
  181215. mb.fillWith (0);
  181216. MapiFileDesc* files = (MapiFileDesc*) mb.getData();
  181217. message.nFileCount = filesToAttach.size();
  181218. message.lpFiles = files;
  181219. for (int i = 0; i < filesToAttach.size(); ++i)
  181220. {
  181221. files[i].nPosition = (ULONG) -1;
  181222. files[i].lpszPathName = (LPSTR) filesToAttach[i].toCString();
  181223. }
  181224. ok = (mapiSendMail (0, 0, &message, MAPI_DIALOG | MAPI_LOGON_UI, 0) == SUCCESS_SUCCESS);
  181225. }
  181226. FreeLibrary (h);
  181227. return ok;
  181228. }
  181229. #endif
  181230. /*** End of inlined file: juce_win32_Network.cpp ***/
  181231. /*** Start of inlined file: juce_win32_PlatformUtils.cpp ***/
  181232. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181233. // compiled on its own).
  181234. #if JUCE_INCLUDED_FILE
  181235. static HKEY findKeyForPath (String name,
  181236. const bool createForWriting,
  181237. String& valueName)
  181238. {
  181239. HKEY rootKey = 0;
  181240. if (name.startsWithIgnoreCase (T("HKEY_CURRENT_USER\\")))
  181241. rootKey = HKEY_CURRENT_USER;
  181242. else if (name.startsWithIgnoreCase (T("HKEY_LOCAL_MACHINE\\")))
  181243. rootKey = HKEY_LOCAL_MACHINE;
  181244. else if (name.startsWithIgnoreCase (T("HKEY_CLASSES_ROOT\\")))
  181245. rootKey = HKEY_CLASSES_ROOT;
  181246. if (rootKey != 0)
  181247. {
  181248. name = name.substring (name.indexOfChar (T('\\')) + 1);
  181249. const int lastSlash = name.lastIndexOfChar (T('\\'));
  181250. valueName = name.substring (lastSlash + 1);
  181251. name = name.substring (0, lastSlash);
  181252. HKEY key;
  181253. DWORD result;
  181254. if (createForWriting)
  181255. {
  181256. if (RegCreateKeyEx (rootKey, name, 0, 0, REG_OPTION_NON_VOLATILE,
  181257. (KEY_WRITE | KEY_QUERY_VALUE), 0, &key, &result) == ERROR_SUCCESS)
  181258. return key;
  181259. }
  181260. else
  181261. {
  181262. if (RegOpenKeyEx (rootKey, name, 0, KEY_READ, &key) == ERROR_SUCCESS)
  181263. return key;
  181264. }
  181265. }
  181266. return 0;
  181267. }
  181268. const String PlatformUtilities::getRegistryValue (const String& regValuePath,
  181269. const String& defaultValue)
  181270. {
  181271. String valueName, result (defaultValue);
  181272. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181273. if (k != 0)
  181274. {
  181275. WCHAR buffer [2048];
  181276. unsigned long bufferSize = sizeof (buffer);
  181277. DWORD type = REG_SZ;
  181278. if (RegQueryValueEx (k, valueName, 0, &type, (LPBYTE) buffer, &bufferSize) == ERROR_SUCCESS)
  181279. {
  181280. if (type == REG_SZ)
  181281. result = buffer;
  181282. else if (type == REG_DWORD)
  181283. result = String ((int) *(DWORD*) buffer);
  181284. }
  181285. RegCloseKey (k);
  181286. }
  181287. return result;
  181288. }
  181289. void PlatformUtilities::setRegistryValue (const String& regValuePath,
  181290. const String& value)
  181291. {
  181292. String valueName;
  181293. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181294. if (k != 0)
  181295. {
  181296. RegSetValueEx (k, valueName, 0, REG_SZ,
  181297. (const BYTE*) (const WCHAR*) value,
  181298. sizeof (WCHAR) * (value.length() + 1));
  181299. RegCloseKey (k);
  181300. }
  181301. }
  181302. bool PlatformUtilities::registryValueExists (const String& regValuePath)
  181303. {
  181304. bool exists = false;
  181305. String valueName;
  181306. HKEY k = findKeyForPath (regValuePath, false, valueName);
  181307. if (k != 0)
  181308. {
  181309. unsigned char buffer [2048];
  181310. unsigned long bufferSize = sizeof (buffer);
  181311. DWORD type = 0;
  181312. if (RegQueryValueEx (k, valueName, 0, &type, buffer, &bufferSize) == ERROR_SUCCESS)
  181313. exists = true;
  181314. RegCloseKey (k);
  181315. }
  181316. return exists;
  181317. }
  181318. void PlatformUtilities::deleteRegistryValue (const String& regValuePath)
  181319. {
  181320. String valueName;
  181321. HKEY k = findKeyForPath (regValuePath, true, valueName);
  181322. if (k != 0)
  181323. {
  181324. RegDeleteValue (k, valueName);
  181325. RegCloseKey (k);
  181326. }
  181327. }
  181328. void PlatformUtilities::deleteRegistryKey (const String& regKeyPath)
  181329. {
  181330. String valueName;
  181331. HKEY k = findKeyForPath (regKeyPath, true, valueName);
  181332. if (k != 0)
  181333. {
  181334. RegDeleteKey (k, valueName);
  181335. RegCloseKey (k);
  181336. }
  181337. }
  181338. void PlatformUtilities::registerFileAssociation (const String& fileExtension,
  181339. const String& symbolicDescription,
  181340. const String& fullDescription,
  181341. const File& targetExecutable,
  181342. int iconResourceNumber)
  181343. {
  181344. setRegistryValue ("HKEY_CLASSES_ROOT\\" + fileExtension + "\\", symbolicDescription);
  181345. const String key ("HKEY_CLASSES_ROOT\\" + symbolicDescription);
  181346. if (iconResourceNumber != 0)
  181347. setRegistryValue (key + "\\DefaultIcon\\",
  181348. targetExecutable.getFullPathName() + "," + String (-iconResourceNumber));
  181349. setRegistryValue (key + "\\", fullDescription);
  181350. setRegistryValue (key + "\\shell\\open\\command\\",
  181351. targetExecutable.getFullPathName() + " %1");
  181352. }
  181353. bool juce_IsRunningInWine()
  181354. {
  181355. HKEY key;
  181356. if (RegOpenKeyEx (HKEY_CURRENT_USER, _T("Software\\Wine"), 0, KEY_READ, &key) == ERROR_SUCCESS)
  181357. {
  181358. RegCloseKey (key);
  181359. return true;
  181360. }
  181361. return false;
  181362. }
  181363. const String JUCE_CALLTYPE PlatformUtilities::getCurrentCommandLineParams() throw()
  181364. {
  181365. String s (::GetCommandLineW());
  181366. StringArray tokens;
  181367. tokens.addTokens (s, true); // tokenise so that we can remove the initial filename argument
  181368. return tokens.joinIntoString (T(" "), 1);
  181369. }
  181370. static void* currentModuleHandle = 0;
  181371. void* PlatformUtilities::getCurrentModuleInstanceHandle() throw()
  181372. {
  181373. if (currentModuleHandle == 0)
  181374. currentModuleHandle = GetModuleHandle (0);
  181375. return currentModuleHandle;
  181376. }
  181377. void PlatformUtilities::setCurrentModuleInstanceHandle (void* const newHandle) throw()
  181378. {
  181379. currentModuleHandle = newHandle;
  181380. }
  181381. void PlatformUtilities::fpuReset()
  181382. {
  181383. #if JUCE_MSVC
  181384. _clearfp();
  181385. #endif
  181386. }
  181387. void PlatformUtilities::beep()
  181388. {
  181389. MessageBeep (MB_OK);
  181390. }
  181391. #endif
  181392. /*** End of inlined file: juce_win32_PlatformUtils.cpp ***/
  181393. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  181394. /*** Start of inlined file: juce_win32_Messaging.cpp ***/
  181395. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181396. // compiled on its own).
  181397. #if JUCE_INCLUDED_FILE
  181398. static const unsigned int specialId = WM_APP + 0x4400;
  181399. static const unsigned int broadcastId = WM_APP + 0x4403;
  181400. static const unsigned int specialCallbackId = WM_APP + 0x4402;
  181401. static const TCHAR* const messageWindowName = _T("JUCEWindow");
  181402. HWND juce_messageWindowHandle = 0;
  181403. extern long improbableWindowNumber; // defined in windowing.cpp
  181404. #ifndef WM_APPCOMMAND
  181405. #define WM_APPCOMMAND 0x0319
  181406. #endif
  181407. static LRESULT CALLBACK juce_MessageWndProc (HWND h,
  181408. const UINT message,
  181409. const WPARAM wParam,
  181410. const LPARAM lParam) throw()
  181411. {
  181412. JUCE_TRY
  181413. {
  181414. if (h == juce_messageWindowHandle)
  181415. {
  181416. if (message == specialCallbackId)
  181417. {
  181418. MessageCallbackFunction* const func = (MessageCallbackFunction*) wParam;
  181419. return (LRESULT) (*func) ((void*) lParam);
  181420. }
  181421. else if (message == specialId)
  181422. {
  181423. // these are trapped early in the dispatch call, but must also be checked
  181424. // here in case there are windows modal dialog boxes doing their own
  181425. // dispatch loop and not calling our version
  181426. MessageManager::getInstance()->deliverMessage ((void*) lParam);
  181427. return 0;
  181428. }
  181429. else if (message == broadcastId)
  181430. {
  181431. const ScopedPointer <String> messageString ((String*) lParam);
  181432. MessageManager::getInstance()->deliverBroadcastMessage (*messageString);
  181433. return 0;
  181434. }
  181435. else if (message == WM_COPYDATA && ((const COPYDATASTRUCT*) lParam)->dwData == broadcastId)
  181436. {
  181437. const String messageString ((const juce_wchar*) ((const COPYDATASTRUCT*) lParam)->lpData,
  181438. ((const COPYDATASTRUCT*) lParam)->cbData / sizeof (juce_wchar));
  181439. PostMessage (juce_messageWindowHandle, broadcastId, 0, (LPARAM) new String (messageString));
  181440. return 0;
  181441. }
  181442. }
  181443. }
  181444. JUCE_CATCH_EXCEPTION
  181445. return DefWindowProc (h, message, wParam, lParam);
  181446. }
  181447. static bool isEventBlockedByModalComps (MSG& m)
  181448. {
  181449. if (Component::getNumCurrentlyModalComponents() == 0
  181450. || GetWindowLong (m.hwnd, GWLP_USERDATA) == improbableWindowNumber)
  181451. return false;
  181452. switch (m.message)
  181453. {
  181454. case WM_MOUSEMOVE:
  181455. case WM_NCMOUSEMOVE:
  181456. case 0x020A: /* WM_MOUSEWHEEL */
  181457. case 0x020E: /* WM_MOUSEHWHEEL */
  181458. case WM_KEYUP:
  181459. case WM_SYSKEYUP:
  181460. case WM_CHAR:
  181461. case WM_APPCOMMAND:
  181462. case WM_LBUTTONUP:
  181463. case WM_MBUTTONUP:
  181464. case WM_RBUTTONUP:
  181465. case WM_MOUSEACTIVATE:
  181466. case WM_NCMOUSEHOVER:
  181467. case WM_MOUSEHOVER:
  181468. return true;
  181469. case WM_NCLBUTTONDOWN:
  181470. case WM_NCLBUTTONDBLCLK:
  181471. case WM_NCRBUTTONDOWN:
  181472. case WM_NCRBUTTONDBLCLK:
  181473. case WM_NCMBUTTONDOWN:
  181474. case WM_NCMBUTTONDBLCLK:
  181475. case WM_LBUTTONDOWN:
  181476. case WM_LBUTTONDBLCLK:
  181477. case WM_MBUTTONDOWN:
  181478. case WM_MBUTTONDBLCLK:
  181479. case WM_RBUTTONDOWN:
  181480. case WM_RBUTTONDBLCLK:
  181481. case WM_KEYDOWN:
  181482. case WM_SYSKEYDOWN:
  181483. {
  181484. Component* const modal = Component::getCurrentlyModalComponent (0);
  181485. if (modal != 0)
  181486. modal->inputAttemptWhenModal();
  181487. return true;
  181488. }
  181489. default:
  181490. break;
  181491. }
  181492. return false;
  181493. }
  181494. bool juce_dispatchNextMessageOnSystemQueue (const bool returnIfNoPendingMessages)
  181495. {
  181496. MSG m;
  181497. if (returnIfNoPendingMessages && ! PeekMessage (&m, (HWND) 0, 0, 0, 0))
  181498. return false;
  181499. if (GetMessage (&m, (HWND) 0, 0, 0) >= 0)
  181500. {
  181501. if (m.message == specialId && m.hwnd == juce_messageWindowHandle)
  181502. {
  181503. MessageManager::getInstance()->deliverMessage ((void*) m.lParam);
  181504. }
  181505. else if (m.message == WM_QUIT)
  181506. {
  181507. if (JUCEApplication::getInstance())
  181508. JUCEApplication::getInstance()->systemRequestedQuit();
  181509. }
  181510. else if (! isEventBlockedByModalComps (m))
  181511. {
  181512. if ((m.message == WM_LBUTTONDOWN || m.message == WM_RBUTTONDOWN)
  181513. && GetWindowLong (m.hwnd, GWLP_USERDATA) != improbableWindowNumber)
  181514. {
  181515. // if it's someone else's window being clicked on, and the focus is
  181516. // currently on a juce window, pass the kb focus over..
  181517. HWND currentFocus = GetFocus();
  181518. if (currentFocus == 0 || GetWindowLong (currentFocus, GWLP_USERDATA) == improbableWindowNumber)
  181519. SetFocus (m.hwnd);
  181520. }
  181521. TranslateMessage (&m);
  181522. DispatchMessage (&m);
  181523. }
  181524. }
  181525. return true;
  181526. }
  181527. bool juce_postMessageToSystemQueue (void* message)
  181528. {
  181529. return PostMessage (juce_messageWindowHandle, specialId, 0, (LPARAM) message) != 0;
  181530. }
  181531. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  181532. void* userData)
  181533. {
  181534. if (MessageManager::getInstance()->isThisTheMessageThread())
  181535. {
  181536. return (*callback) (userData);
  181537. }
  181538. else
  181539. {
  181540. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  181541. // deadlock because the message manager is blocked from running, and can't
  181542. // call your function..
  181543. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  181544. return (void*) SendMessage (juce_messageWindowHandle,
  181545. specialCallbackId,
  181546. (WPARAM) callback,
  181547. (LPARAM) userData);
  181548. }
  181549. }
  181550. static BOOL CALLBACK BroadcastEnumWindowProc (HWND hwnd, LPARAM lParam)
  181551. {
  181552. if (hwnd != juce_messageWindowHandle)
  181553. (reinterpret_cast <VoidArray*> (lParam))->add ((void*) hwnd);
  181554. return TRUE;
  181555. }
  181556. void MessageManager::broadcastMessage (const String& value) throw()
  181557. {
  181558. VoidArray windows;
  181559. EnumWindows (&BroadcastEnumWindowProc, (LPARAM) &windows);
  181560. const String localCopy (value);
  181561. COPYDATASTRUCT data;
  181562. data.dwData = broadcastId;
  181563. data.cbData = (localCopy.length() + 1) * sizeof (juce_wchar);
  181564. data.lpData = (void*) (const juce_wchar*) localCopy;
  181565. for (int i = windows.size(); --i >= 0;)
  181566. {
  181567. HWND hwnd = (HWND) windows.getUnchecked(i);
  181568. TCHAR windowName [64]; // no need to read longer strings than this
  181569. GetWindowText (hwnd, windowName, 64);
  181570. windowName [63] = 0;
  181571. if (String (windowName) == String (messageWindowName))
  181572. {
  181573. DWORD_PTR result;
  181574. SendMessageTimeout (hwnd, WM_COPYDATA,
  181575. (WPARAM) juce_messageWindowHandle,
  181576. (LPARAM) &data,
  181577. SMTO_BLOCK | SMTO_ABORTIFHUNG,
  181578. 8000,
  181579. &result);
  181580. }
  181581. }
  181582. }
  181583. static const String getMessageWindowClassName()
  181584. {
  181585. // this name has to be different for each app/dll instance because otherwise
  181586. // poor old Win32 can get a bit confused (even despite it not being a process-global
  181587. // window class).
  181588. static int number = 0;
  181589. if (number == 0)
  181590. number = 0x7fffffff & (int) Time::getHighResolutionTicks();
  181591. return T("JUCEcs_") + String (number);
  181592. }
  181593. void MessageManager::doPlatformSpecificInitialisation()
  181594. {
  181595. OleInitialize (0);
  181596. const String className (getMessageWindowClassName());
  181597. HMODULE hmod = (HMODULE) PlatformUtilities::getCurrentModuleInstanceHandle();
  181598. WNDCLASSEX wc;
  181599. zerostruct (wc);
  181600. wc.cbSize = sizeof (wc);
  181601. wc.lpfnWndProc = (WNDPROC) juce_MessageWndProc;
  181602. wc.cbWndExtra = 4;
  181603. wc.hInstance = hmod;
  181604. wc.lpszClassName = className;
  181605. RegisterClassEx (&wc);
  181606. juce_messageWindowHandle = CreateWindow (wc.lpszClassName,
  181607. messageWindowName,
  181608. 0, 0, 0, 0, 0, 0, 0,
  181609. hmod, 0);
  181610. }
  181611. void MessageManager::doPlatformSpecificShutdown()
  181612. {
  181613. DestroyWindow (juce_messageWindowHandle);
  181614. UnregisterClass (getMessageWindowClassName(), 0);
  181615. OleUninitialize();
  181616. }
  181617. #endif
  181618. /*** End of inlined file: juce_win32_Messaging.cpp ***/
  181619. /*** Start of inlined file: juce_win32_Windowing.cpp ***/
  181620. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  181621. // compiled on its own).
  181622. #if JUCE_INCLUDED_FILE
  181623. #undef GetSystemMetrics // multimon overrides this for some reason and causes a mess..
  181624. // these are in the windows SDK, but need to be repeated here for GCC..
  181625. #ifndef GET_APPCOMMAND_LPARAM
  181626. #define FAPPCOMMAND_MASK 0xF000
  181627. #define GET_APPCOMMAND_LPARAM(lParam) ((short) (HIWORD (lParam) & ~FAPPCOMMAND_MASK))
  181628. #define APPCOMMAND_MEDIA_NEXTTRACK 11
  181629. #define APPCOMMAND_MEDIA_PREVIOUSTRACK 12
  181630. #define APPCOMMAND_MEDIA_STOP 13
  181631. #define APPCOMMAND_MEDIA_PLAY_PAUSE 14
  181632. #define WM_APPCOMMAND 0x0319
  181633. #endif
  181634. extern void juce_repeatLastProcessPriority(); // in juce_win32_Threads.cpp
  181635. extern void juce_CheckCurrentlyFocusedTopLevelWindow(); // in juce_TopLevelWindow.cpp
  181636. extern bool juce_IsRunningInWine();
  181637. #ifndef ULW_ALPHA
  181638. #define ULW_ALPHA 0x00000002
  181639. #endif
  181640. #ifndef AC_SRC_ALPHA
  181641. #define AC_SRC_ALPHA 0x01
  181642. #endif
  181643. #define DEBUG_REPAINT_TIMES 0
  181644. static HPALETTE palette = 0;
  181645. static bool createPaletteIfNeeded = true;
  181646. static bool shouldDeactivateTitleBar = true;
  181647. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw();
  181648. #define WM_TRAYNOTIFY WM_USER + 100
  181649. using ::abs;
  181650. typedef BOOL (WINAPI* UpdateLayeredWinFunc) (HWND, HDC, POINT*, SIZE*, HDC, POINT*, COLORREF, BLENDFUNCTION*, DWORD);
  181651. static UpdateLayeredWinFunc updateLayeredWindow = 0;
  181652. bool Desktop::canUseSemiTransparentWindows() throw()
  181653. {
  181654. if (updateLayeredWindow == 0)
  181655. {
  181656. if (! juce_IsRunningInWine())
  181657. {
  181658. HMODULE user32Mod = GetModuleHandle (_T("user32.dll"));
  181659. updateLayeredWindow = (UpdateLayeredWinFunc) GetProcAddress (user32Mod, "UpdateLayeredWindow");
  181660. }
  181661. }
  181662. return updateLayeredWindow != 0;
  181663. }
  181664. #undef DefWindowProc
  181665. #define DefWindowProc DefWindowProcW
  181666. const int extendedKeyModifier = 0x10000;
  181667. const int KeyPress::spaceKey = VK_SPACE;
  181668. const int KeyPress::returnKey = VK_RETURN;
  181669. const int KeyPress::escapeKey = VK_ESCAPE;
  181670. const int KeyPress::backspaceKey = VK_BACK;
  181671. const int KeyPress::deleteKey = VK_DELETE | extendedKeyModifier;
  181672. const int KeyPress::insertKey = VK_INSERT | extendedKeyModifier;
  181673. const int KeyPress::tabKey = VK_TAB;
  181674. const int KeyPress::leftKey = VK_LEFT | extendedKeyModifier;
  181675. const int KeyPress::rightKey = VK_RIGHT | extendedKeyModifier;
  181676. const int KeyPress::upKey = VK_UP | extendedKeyModifier;
  181677. const int KeyPress::downKey = VK_DOWN | extendedKeyModifier;
  181678. const int KeyPress::homeKey = VK_HOME | extendedKeyModifier;
  181679. const int KeyPress::endKey = VK_END | extendedKeyModifier;
  181680. const int KeyPress::pageUpKey = VK_PRIOR | extendedKeyModifier;
  181681. const int KeyPress::pageDownKey = VK_NEXT | extendedKeyModifier;
  181682. const int KeyPress::F1Key = VK_F1 | extendedKeyModifier;
  181683. const int KeyPress::F2Key = VK_F2 | extendedKeyModifier;
  181684. const int KeyPress::F3Key = VK_F3 | extendedKeyModifier;
  181685. const int KeyPress::F4Key = VK_F4 | extendedKeyModifier;
  181686. const int KeyPress::F5Key = VK_F5 | extendedKeyModifier;
  181687. const int KeyPress::F6Key = VK_F6 | extendedKeyModifier;
  181688. const int KeyPress::F7Key = VK_F7 | extendedKeyModifier;
  181689. const int KeyPress::F8Key = VK_F8 | extendedKeyModifier;
  181690. const int KeyPress::F9Key = VK_F9 | extendedKeyModifier;
  181691. const int KeyPress::F10Key = VK_F10 | extendedKeyModifier;
  181692. const int KeyPress::F11Key = VK_F11 | extendedKeyModifier;
  181693. const int KeyPress::F12Key = VK_F12 | extendedKeyModifier;
  181694. const int KeyPress::F13Key = VK_F13 | extendedKeyModifier;
  181695. const int KeyPress::F14Key = VK_F14 | extendedKeyModifier;
  181696. const int KeyPress::F15Key = VK_F15 | extendedKeyModifier;
  181697. const int KeyPress::F16Key = VK_F16 | extendedKeyModifier;
  181698. const int KeyPress::numberPad0 = VK_NUMPAD0 | extendedKeyModifier;
  181699. const int KeyPress::numberPad1 = VK_NUMPAD1 | extendedKeyModifier;
  181700. const int KeyPress::numberPad2 = VK_NUMPAD2 | extendedKeyModifier;
  181701. const int KeyPress::numberPad3 = VK_NUMPAD3 | extendedKeyModifier;
  181702. const int KeyPress::numberPad4 = VK_NUMPAD4 | extendedKeyModifier;
  181703. const int KeyPress::numberPad5 = VK_NUMPAD5 | extendedKeyModifier;
  181704. const int KeyPress::numberPad6 = VK_NUMPAD6 | extendedKeyModifier;
  181705. const int KeyPress::numberPad7 = VK_NUMPAD7 | extendedKeyModifier;
  181706. const int KeyPress::numberPad8 = VK_NUMPAD8 | extendedKeyModifier;
  181707. const int KeyPress::numberPad9 = VK_NUMPAD9 | extendedKeyModifier;
  181708. const int KeyPress::numberPadAdd = VK_ADD | extendedKeyModifier;
  181709. const int KeyPress::numberPadSubtract = VK_SUBTRACT | extendedKeyModifier;
  181710. const int KeyPress::numberPadMultiply = VK_MULTIPLY | extendedKeyModifier;
  181711. const int KeyPress::numberPadDivide = VK_DIVIDE | extendedKeyModifier;
  181712. const int KeyPress::numberPadSeparator = VK_SEPARATOR | extendedKeyModifier;
  181713. const int KeyPress::numberPadDecimalPoint = VK_DECIMAL | extendedKeyModifier;
  181714. const int KeyPress::numberPadEquals = 0x92 /*VK_OEM_NEC_EQUAL*/ | extendedKeyModifier;
  181715. const int KeyPress::numberPadDelete = VK_DELETE | extendedKeyModifier;
  181716. const int KeyPress::playKey = 0x30000;
  181717. const int KeyPress::stopKey = 0x30001;
  181718. const int KeyPress::fastForwardKey = 0x30002;
  181719. const int KeyPress::rewindKey = 0x30003;
  181720. class WindowsBitmapImage : public Image
  181721. {
  181722. public:
  181723. HBITMAP hBitmap;
  181724. BITMAPV4HEADER bitmapInfo;
  181725. HDC hdc;
  181726. unsigned char* bitmapData;
  181727. WindowsBitmapImage (const PixelFormat format_,
  181728. const int w, const int h, const bool clearImage)
  181729. : Image (format_, w, h)
  181730. {
  181731. jassert (format_ == RGB || format_ == ARGB);
  181732. pixelStride = (format_ == RGB) ? 3 : 4;
  181733. zerostruct (bitmapInfo);
  181734. bitmapInfo.bV4Size = sizeof (BITMAPV4HEADER);
  181735. bitmapInfo.bV4Width = w;
  181736. bitmapInfo.bV4Height = h;
  181737. bitmapInfo.bV4Planes = 1;
  181738. bitmapInfo.bV4CSType = 1;
  181739. bitmapInfo.bV4BitCount = (unsigned short) (pixelStride * 8);
  181740. if (format_ == ARGB)
  181741. {
  181742. bitmapInfo.bV4AlphaMask = 0xff000000;
  181743. bitmapInfo.bV4RedMask = 0xff0000;
  181744. bitmapInfo.bV4GreenMask = 0xff00;
  181745. bitmapInfo.bV4BlueMask = 0xff;
  181746. bitmapInfo.bV4V4Compression = BI_BITFIELDS;
  181747. }
  181748. else
  181749. {
  181750. bitmapInfo.bV4V4Compression = BI_RGB;
  181751. }
  181752. lineStride = -((w * pixelStride + 3) & ~3);
  181753. HDC dc = GetDC (0);
  181754. hdc = CreateCompatibleDC (dc);
  181755. ReleaseDC (0, dc);
  181756. SetMapMode (hdc, MM_TEXT);
  181757. hBitmap = CreateDIBSection (hdc,
  181758. (BITMAPINFO*) &(bitmapInfo),
  181759. DIB_RGB_COLORS,
  181760. (void**) &bitmapData,
  181761. 0, 0);
  181762. SelectObject (hdc, hBitmap);
  181763. if (format_ == ARGB && clearImage)
  181764. zeromem (bitmapData, abs (h * lineStride));
  181765. imageData = bitmapData - (lineStride * (h - 1));
  181766. }
  181767. ~WindowsBitmapImage()
  181768. {
  181769. DeleteDC (hdc);
  181770. DeleteObject (hBitmap);
  181771. }
  181772. void blitToWindow (HWND hwnd, HDC dc, const bool transparent,
  181773. const int x, const int y,
  181774. const RectangleList& maskedRegion) throw()
  181775. {
  181776. static HDRAWDIB hdd = 0;
  181777. static bool needToCreateDrawDib = true;
  181778. if (needToCreateDrawDib)
  181779. {
  181780. needToCreateDrawDib = false;
  181781. HDC dc = GetDC (0);
  181782. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181783. ReleaseDC (0, dc);
  181784. // only open if we're not palettised
  181785. if (n > 8)
  181786. hdd = DrawDibOpen();
  181787. }
  181788. if (createPaletteIfNeeded)
  181789. {
  181790. HDC dc = GetDC (0);
  181791. const int n = GetDeviceCaps (dc, BITSPIXEL);
  181792. ReleaseDC (0, dc);
  181793. if (n <= 8)
  181794. palette = CreateHalftonePalette (dc);
  181795. createPaletteIfNeeded = false;
  181796. }
  181797. if (palette != 0)
  181798. {
  181799. SelectPalette (dc, palette, FALSE);
  181800. RealizePalette (dc);
  181801. SetStretchBltMode (dc, HALFTONE);
  181802. }
  181803. SetMapMode (dc, MM_TEXT);
  181804. if (transparent)
  181805. {
  181806. POINT p, pos;
  181807. SIZE size;
  181808. RECT windowBounds;
  181809. GetWindowRect (hwnd, &windowBounds);
  181810. p.x = -x;
  181811. p.y = -y;
  181812. pos.x = windowBounds.left;
  181813. pos.y = windowBounds.top;
  181814. size.cx = windowBounds.right - windowBounds.left;
  181815. size.cy = windowBounds.bottom - windowBounds.top;
  181816. BLENDFUNCTION bf;
  181817. bf.AlphaFormat = AC_SRC_ALPHA;
  181818. bf.BlendFlags = 0;
  181819. bf.BlendOp = AC_SRC_OVER;
  181820. bf.SourceConstantAlpha = 0xff;
  181821. if (! maskedRegion.isEmpty())
  181822. {
  181823. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181824. {
  181825. const Rectangle<int>& r = *i.getRectangle();
  181826. ExcludeClipRect (hdc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181827. }
  181828. }
  181829. updateLayeredWindow (hwnd, 0, &pos, &size, hdc, &p, 0, &bf, ULW_ALPHA);
  181830. }
  181831. else
  181832. {
  181833. int savedDC = 0;
  181834. if (! maskedRegion.isEmpty())
  181835. {
  181836. savedDC = SaveDC (dc);
  181837. for (RectangleList::Iterator i (maskedRegion); i.next();)
  181838. {
  181839. const Rectangle<int>& r = *i.getRectangle();
  181840. ExcludeClipRect (dc, r.getX(), r.getY(), r.getRight(), r.getBottom());
  181841. }
  181842. }
  181843. const int w = getWidth();
  181844. const int h = getHeight();
  181845. if (hdd == 0)
  181846. {
  181847. StretchDIBits (dc,
  181848. x, y, w, h,
  181849. 0, 0, w, h,
  181850. bitmapData, (const BITMAPINFO*) &bitmapInfo,
  181851. DIB_RGB_COLORS, SRCCOPY);
  181852. }
  181853. else
  181854. {
  181855. DrawDibDraw (hdd, dc, x, y, -1, -1,
  181856. (BITMAPINFOHEADER*) &bitmapInfo, bitmapData,
  181857. 0, 0, w, h, 0);
  181858. }
  181859. if (! maskedRegion.isEmpty())
  181860. RestoreDC (dc, savedDC);
  181861. }
  181862. }
  181863. juce_UseDebuggingNewOperator
  181864. private:
  181865. WindowsBitmapImage (const WindowsBitmapImage&);
  181866. WindowsBitmapImage& operator= (const WindowsBitmapImage&);
  181867. };
  181868. long improbableWindowNumber = 0xf965aa01; // also referenced by messaging.cpp
  181869. static int currentModifiers = 0;
  181870. static int modifiersAtLastCallback = 0;
  181871. static void updateKeyModifiers() throw()
  181872. {
  181873. currentModifiers &= ~(ModifierKeys::shiftModifier
  181874. | ModifierKeys::ctrlModifier
  181875. | ModifierKeys::altModifier);
  181876. if ((GetKeyState (VK_SHIFT) & 0x8000) != 0)
  181877. currentModifiers |= ModifierKeys::shiftModifier;
  181878. if ((GetKeyState (VK_CONTROL) & 0x8000) != 0)
  181879. currentModifiers |= ModifierKeys::ctrlModifier;
  181880. if ((GetKeyState (VK_MENU) & 0x8000) != 0)
  181881. currentModifiers |= ModifierKeys::altModifier;
  181882. if ((GetKeyState (VK_RMENU) & 0x8000) != 0)
  181883. currentModifiers &= ~(ModifierKeys::ctrlModifier | ModifierKeys::altModifier);
  181884. }
  181885. void ModifierKeys::updateCurrentModifiers() throw()
  181886. {
  181887. currentModifierFlags = currentModifiers;
  181888. }
  181889. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  181890. {
  181891. SHORT k = (SHORT) keyCode;
  181892. if ((keyCode & extendedKeyModifier) == 0
  181893. && (k >= (SHORT) T('a') && k <= (SHORT) T('z')))
  181894. k += (SHORT) T('A') - (SHORT) T('a');
  181895. const SHORT translatedValues[] = { (SHORT) ',', VK_OEM_COMMA,
  181896. (SHORT) '+', VK_OEM_PLUS,
  181897. (SHORT) '-', VK_OEM_MINUS,
  181898. (SHORT) '.', VK_OEM_PERIOD,
  181899. (SHORT) ';', VK_OEM_1,
  181900. (SHORT) ':', VK_OEM_1,
  181901. (SHORT) '/', VK_OEM_2,
  181902. (SHORT) '?', VK_OEM_2,
  181903. (SHORT) '[', VK_OEM_4,
  181904. (SHORT) ']', VK_OEM_6 };
  181905. for (int i = 0; i < numElementsInArray (translatedValues); i += 2)
  181906. if (k == translatedValues [i])
  181907. k = translatedValues [i + 1];
  181908. return (GetKeyState (k) & 0x8000) != 0;
  181909. }
  181910. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  181911. {
  181912. updateKeyModifiers();
  181913. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  181914. if ((GetKeyState (VK_LBUTTON) & 0x8000) != 0)
  181915. currentModifiers |= ModifierKeys::leftButtonModifier;
  181916. if ((GetKeyState (VK_RBUTTON) & 0x8000) != 0)
  181917. currentModifiers |= ModifierKeys::rightButtonModifier;
  181918. if ((GetKeyState (VK_MBUTTON) & 0x8000) != 0)
  181919. currentModifiers |= ModifierKeys::middleButtonModifier;
  181920. return ModifierKeys (currentModifiers);
  181921. }
  181922. static int64 getMouseEventTime() throw()
  181923. {
  181924. static int64 eventTimeOffset = 0;
  181925. static DWORD lastMessageTime = 0;
  181926. const DWORD thisMessageTime = GetMessageTime();
  181927. if (thisMessageTime < lastMessageTime || lastMessageTime == 0)
  181928. {
  181929. lastMessageTime = thisMessageTime;
  181930. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  181931. }
  181932. return eventTimeOffset + thisMessageTime;
  181933. }
  181934. static void* callFunctionIfNotLocked (MessageCallbackFunction* callback, void* userData)
  181935. {
  181936. if (MessageManager::getInstance()->currentThreadHasLockedMessageManager())
  181937. return callback (userData);
  181938. else
  181939. return MessageManager::getInstance()->callFunctionOnMessageThread (callback, userData);
  181940. }
  181941. class Win32ComponentPeer : public ComponentPeer
  181942. {
  181943. public:
  181944. Win32ComponentPeer (Component* const component,
  181945. const int windowStyleFlags)
  181946. : ComponentPeer (component, windowStyleFlags),
  181947. dontRepaint (false),
  181948. fullScreen (false),
  181949. isDragging (false),
  181950. isMouseOver (false),
  181951. hasCreatedCaret (false),
  181952. currentWindowIcon (0),
  181953. taskBarIcon (0),
  181954. dropTarget (0)
  181955. {
  181956. callFunctionIfNotLocked (&createWindowCallback, (void*) this);
  181957. setTitle (component->getName());
  181958. if ((windowStyleFlags & windowHasDropShadow) != 0
  181959. && Desktop::canUseSemiTransparentWindows())
  181960. {
  181961. shadower = component->getLookAndFeel().createDropShadowerForComponent (component);
  181962. if (shadower != 0)
  181963. shadower->setOwner (component);
  181964. }
  181965. else
  181966. {
  181967. shadower = 0;
  181968. }
  181969. }
  181970. ~Win32ComponentPeer()
  181971. {
  181972. setTaskBarIcon (0);
  181973. deleteAndZero (shadower);
  181974. // do this before the next bit to avoid messages arriving for this window
  181975. // before it's destroyed
  181976. SetWindowLongPtr (hwnd, GWLP_USERDATA, 0);
  181977. callFunctionIfNotLocked (&destroyWindowCallback, (void*) hwnd);
  181978. if (currentWindowIcon != 0)
  181979. DestroyIcon (currentWindowIcon);
  181980. if (dropTarget != 0)
  181981. {
  181982. dropTarget->Release();
  181983. dropTarget = 0;
  181984. }
  181985. }
  181986. void* getNativeHandle() const
  181987. {
  181988. return (void*) hwnd;
  181989. }
  181990. void setVisible (bool shouldBeVisible)
  181991. {
  181992. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  181993. if (shouldBeVisible)
  181994. InvalidateRect (hwnd, 0, 0);
  181995. else
  181996. lastPaintTime = 0;
  181997. }
  181998. void setTitle (const String& title)
  181999. {
  182000. SetWindowText (hwnd, title);
  182001. }
  182002. void setPosition (int x, int y)
  182003. {
  182004. offsetWithinParent (x, y);
  182005. SetWindowPos (hwnd, 0,
  182006. x - windowBorder.getLeft(),
  182007. y - windowBorder.getTop(),
  182008. 0, 0,
  182009. SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182010. }
  182011. void repaintNowIfTransparent()
  182012. {
  182013. if (isTransparent() && lastPaintTime > 0 && Time::getMillisecondCounter() > lastPaintTime + 30)
  182014. handlePaintMessage();
  182015. }
  182016. void updateBorderSize()
  182017. {
  182018. WINDOWINFO info;
  182019. info.cbSize = sizeof (info);
  182020. if (GetWindowInfo (hwnd, &info))
  182021. {
  182022. windowBorder = BorderSize (info.rcClient.top - info.rcWindow.top,
  182023. info.rcClient.left - info.rcWindow.left,
  182024. info.rcWindow.bottom - info.rcClient.bottom,
  182025. info.rcWindow.right - info.rcClient.right);
  182026. }
  182027. }
  182028. void setSize (int w, int h)
  182029. {
  182030. SetWindowPos (hwnd, 0, 0, 0,
  182031. w + windowBorder.getLeftAndRight(),
  182032. h + windowBorder.getTopAndBottom(),
  182033. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182034. updateBorderSize();
  182035. repaintNowIfTransparent();
  182036. }
  182037. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  182038. {
  182039. fullScreen = isNowFullScreen;
  182040. offsetWithinParent (x, y);
  182041. SetWindowPos (hwnd, 0,
  182042. x - windowBorder.getLeft(),
  182043. y - windowBorder.getTop(),
  182044. w + windowBorder.getLeftAndRight(),
  182045. h + windowBorder.getTopAndBottom(),
  182046. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  182047. updateBorderSize();
  182048. repaintNowIfTransparent();
  182049. }
  182050. const Rectangle<int> getBounds() const
  182051. {
  182052. RECT r;
  182053. GetWindowRect (hwnd, &r);
  182054. Rectangle<int> bounds (r.left, r.top, r.right - r.left, r.bottom - r.top);
  182055. HWND parentH = GetParent (hwnd);
  182056. if (parentH != 0)
  182057. {
  182058. GetWindowRect (parentH, &r);
  182059. bounds.translate (-r.left, -r.top);
  182060. }
  182061. return windowBorder.subtractedFrom (bounds);
  182062. }
  182063. const Point<int> getScreenPosition() const
  182064. {
  182065. RECT r;
  182066. GetWindowRect (hwnd, &r);
  182067. return Point<int> (r.left + windowBorder.getLeft(),
  182068. r.top + windowBorder.getTop());
  182069. }
  182070. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  182071. {
  182072. return relativePosition + getScreenPosition();
  182073. }
  182074. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  182075. {
  182076. return screenPosition - getScreenPosition();
  182077. }
  182078. void setMinimised (bool shouldBeMinimised)
  182079. {
  182080. if (shouldBeMinimised != isMinimised())
  182081. ShowWindow (hwnd, shouldBeMinimised ? SW_MINIMIZE : SW_SHOWNORMAL);
  182082. }
  182083. bool isMinimised() const
  182084. {
  182085. WINDOWPLACEMENT wp;
  182086. wp.length = sizeof (WINDOWPLACEMENT);
  182087. GetWindowPlacement (hwnd, &wp);
  182088. return wp.showCmd == SW_SHOWMINIMIZED;
  182089. }
  182090. void setFullScreen (bool shouldBeFullScreen)
  182091. {
  182092. setMinimised (false);
  182093. if (fullScreen != shouldBeFullScreen)
  182094. {
  182095. fullScreen = shouldBeFullScreen;
  182096. const ComponentDeletionWatcher deletionChecker (component);
  182097. if (! fullScreen)
  182098. {
  182099. const Rectangle<int> boundsCopy (lastNonFullscreenBounds);
  182100. if (hasTitleBar())
  182101. ShowWindow (hwnd, SW_SHOWNORMAL);
  182102. if (! boundsCopy.isEmpty())
  182103. {
  182104. setBounds (boundsCopy.getX(),
  182105. boundsCopy.getY(),
  182106. boundsCopy.getWidth(),
  182107. boundsCopy.getHeight(),
  182108. false);
  182109. }
  182110. }
  182111. else
  182112. {
  182113. if (hasTitleBar())
  182114. ShowWindow (hwnd, SW_SHOWMAXIMIZED);
  182115. else
  182116. SendMessageW (hwnd, WM_SETTINGCHANGE, 0, 0);
  182117. }
  182118. if (! deletionChecker.hasBeenDeleted())
  182119. handleMovedOrResized();
  182120. }
  182121. }
  182122. bool isFullScreen() const
  182123. {
  182124. if (! hasTitleBar())
  182125. return fullScreen;
  182126. WINDOWPLACEMENT wp;
  182127. wp.length = sizeof (wp);
  182128. GetWindowPlacement (hwnd, &wp);
  182129. return wp.showCmd == SW_SHOWMAXIMIZED;
  182130. }
  182131. bool contains (int x, int y, bool trueIfInAChildWindow) const
  182132. {
  182133. RECT r;
  182134. GetWindowRect (hwnd, &r);
  182135. POINT p;
  182136. p.x = x + r.left + windowBorder.getLeft();
  182137. p.y = y + r.top + windowBorder.getTop();
  182138. HWND w = WindowFromPoint (p);
  182139. return w == hwnd || (trueIfInAChildWindow && (IsChild (hwnd, w) != 0));
  182140. }
  182141. const BorderSize getFrameSize() const
  182142. {
  182143. return windowBorder;
  182144. }
  182145. bool setAlwaysOnTop (bool alwaysOnTop)
  182146. {
  182147. const bool oldDeactivate = shouldDeactivateTitleBar;
  182148. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182149. SetWindowPos (hwnd, alwaysOnTop ? HWND_TOPMOST : HWND_NOTOPMOST,
  182150. 0, 0, 0, 0,
  182151. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182152. shouldDeactivateTitleBar = oldDeactivate;
  182153. if (shadower != 0)
  182154. shadower->componentBroughtToFront (*component);
  182155. return true;
  182156. }
  182157. void toFront (bool makeActive)
  182158. {
  182159. setMinimised (false);
  182160. const bool oldDeactivate = shouldDeactivateTitleBar;
  182161. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182162. callFunctionIfNotLocked (makeActive ? &toFrontCallback1
  182163. : &toFrontCallback2,
  182164. (void*) hwnd);
  182165. shouldDeactivateTitleBar = oldDeactivate;
  182166. if (! makeActive)
  182167. {
  182168. // in this case a broughttofront call won't have occured, so do it now..
  182169. handleBroughtToFront();
  182170. }
  182171. }
  182172. void toBehind (ComponentPeer* other)
  182173. {
  182174. Win32ComponentPeer* const otherPeer = dynamic_cast <Win32ComponentPeer*> (other);
  182175. jassert (otherPeer != 0); // wrong type of window?
  182176. if (otherPeer != 0)
  182177. {
  182178. setMinimised (false);
  182179. // must be careful not to try to put a topmost window behind a normal one, or win32
  182180. // promotes the normal one to be topmost!
  182181. if (getComponent()->isAlwaysOnTop() == otherPeer->getComponent()->isAlwaysOnTop())
  182182. SetWindowPos (hwnd, otherPeer->hwnd, 0, 0, 0, 0,
  182183. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182184. else if (otherPeer->getComponent()->isAlwaysOnTop())
  182185. SetWindowPos (hwnd, HWND_TOP, 0, 0, 0, 0,
  182186. SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182187. }
  182188. }
  182189. bool isFocused() const
  182190. {
  182191. return callFunctionIfNotLocked (&getFocusCallback, 0) == (void*) hwnd;
  182192. }
  182193. void grabFocus()
  182194. {
  182195. const bool oldDeactivate = shouldDeactivateTitleBar;
  182196. shouldDeactivateTitleBar = ((styleFlags & windowIsTemporary) == 0);
  182197. callFunctionIfNotLocked (&setFocusCallback, (void*) hwnd);
  182198. shouldDeactivateTitleBar = oldDeactivate;
  182199. }
  182200. void textInputRequired (const Point<int>&)
  182201. {
  182202. if (! hasCreatedCaret)
  182203. {
  182204. hasCreatedCaret = true;
  182205. CreateCaret (hwnd, (HBITMAP) 1, 0, 0);
  182206. }
  182207. ShowCaret (hwnd);
  182208. SetCaretPos (0, 0);
  182209. }
  182210. void repaint (int x, int y, int w, int h)
  182211. {
  182212. const RECT r = { x, y, x + w, y + h };
  182213. InvalidateRect (hwnd, &r, FALSE);
  182214. }
  182215. void performAnyPendingRepaintsNow()
  182216. {
  182217. MSG m;
  182218. if (component->isVisible() && PeekMessage (&m, hwnd, WM_PAINT, WM_PAINT, PM_REMOVE))
  182219. DispatchMessage (&m);
  182220. }
  182221. static Win32ComponentPeer* getOwnerOfWindow (HWND h) throw()
  182222. {
  182223. if (h != 0 && GetWindowLongPtr (h, GWLP_USERDATA) == improbableWindowNumber)
  182224. return (Win32ComponentPeer*) (pointer_sized_int) GetWindowLongPtr (h, 8);
  182225. return 0;
  182226. }
  182227. void setTaskBarIcon (const Image* const image)
  182228. {
  182229. if (image != 0)
  182230. {
  182231. HICON hicon = createHICONFromImage (*image, TRUE, 0, 0);
  182232. if (taskBarIcon == 0)
  182233. {
  182234. taskBarIcon = new NOTIFYICONDATA();
  182235. taskBarIcon->cbSize = sizeof (NOTIFYICONDATA);
  182236. taskBarIcon->hWnd = (HWND) hwnd;
  182237. taskBarIcon->uID = (int) (pointer_sized_int) hwnd;
  182238. taskBarIcon->uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  182239. taskBarIcon->uCallbackMessage = WM_TRAYNOTIFY;
  182240. taskBarIcon->hIcon = hicon;
  182241. taskBarIcon->szTip[0] = 0;
  182242. Shell_NotifyIcon (NIM_ADD, taskBarIcon);
  182243. }
  182244. else
  182245. {
  182246. HICON oldIcon = taskBarIcon->hIcon;
  182247. taskBarIcon->hIcon = hicon;
  182248. taskBarIcon->uFlags = NIF_ICON;
  182249. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  182250. DestroyIcon (oldIcon);
  182251. }
  182252. DestroyIcon (hicon);
  182253. }
  182254. else if (taskBarIcon != 0)
  182255. {
  182256. taskBarIcon->uFlags = 0;
  182257. Shell_NotifyIcon (NIM_DELETE, taskBarIcon);
  182258. DestroyIcon (taskBarIcon->hIcon);
  182259. deleteAndZero (taskBarIcon);
  182260. }
  182261. }
  182262. void setTaskBarIconToolTip (const String& toolTip) const
  182263. {
  182264. if (taskBarIcon != 0)
  182265. {
  182266. taskBarIcon->uFlags = NIF_TIP;
  182267. toolTip.copyToUnicode (taskBarIcon->szTip, sizeof (taskBarIcon->szTip) - 1);
  182268. Shell_NotifyIcon (NIM_MODIFY, taskBarIcon);
  182269. }
  182270. }
  182271. bool isInside (HWND h) const
  182272. {
  182273. return GetAncestor (hwnd, GA_ROOT) == h;
  182274. }
  182275. juce_UseDebuggingNewOperator
  182276. bool dontRepaint;
  182277. private:
  182278. HWND hwnd;
  182279. DropShadower* shadower;
  182280. bool fullScreen, isDragging, isMouseOver, hasCreatedCaret;
  182281. BorderSize windowBorder;
  182282. HICON currentWindowIcon;
  182283. NOTIFYICONDATA* taskBarIcon;
  182284. IDropTarget* dropTarget;
  182285. class TemporaryImage : public Timer
  182286. {
  182287. public:
  182288. TemporaryImage()
  182289. : image (0)
  182290. {
  182291. }
  182292. ~TemporaryImage()
  182293. {
  182294. delete image;
  182295. }
  182296. WindowsBitmapImage* getImage (const bool transparent, const int w, const int h) throw()
  182297. {
  182298. const Image::PixelFormat format = transparent ? Image::ARGB : Image::RGB;
  182299. if (image == 0 || image->getWidth() < w || image->getHeight() < h || image->getFormat() != format)
  182300. {
  182301. delete image;
  182302. image = new WindowsBitmapImage (format, (w + 31) & ~31, (h + 31) & ~31, false);
  182303. }
  182304. startTimer (3000);
  182305. return image;
  182306. }
  182307. void timerCallback()
  182308. {
  182309. stopTimer();
  182310. deleteAndZero (image);
  182311. }
  182312. private:
  182313. WindowsBitmapImage* image;
  182314. TemporaryImage (const TemporaryImage&);
  182315. TemporaryImage& operator= (const TemporaryImage&);
  182316. };
  182317. TemporaryImage offscreenImageGenerator;
  182318. class WindowClassHolder : public DeletedAtShutdown
  182319. {
  182320. public:
  182321. WindowClassHolder()
  182322. : windowClassName ("JUCE_")
  182323. {
  182324. // this name has to be different for each app/dll instance because otherwise
  182325. // poor old Win32 can get a bit confused (even despite it not being a process-global
  182326. // window class).
  182327. windowClassName << (int) (Time::currentTimeMillis() & 0x7fffffff);
  182328. HINSTANCE moduleHandle = (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle();
  182329. TCHAR moduleFile [1024];
  182330. moduleFile[0] = 0;
  182331. GetModuleFileName (moduleHandle, moduleFile, 1024);
  182332. WORD iconNum = 0;
  182333. WNDCLASSEX wcex;
  182334. wcex.cbSize = sizeof (wcex);
  182335. wcex.style = CS_OWNDC;
  182336. wcex.lpfnWndProc = (WNDPROC) windowProc;
  182337. wcex.lpszClassName = windowClassName;
  182338. wcex.cbClsExtra = 0;
  182339. wcex.cbWndExtra = 32;
  182340. wcex.hInstance = moduleHandle;
  182341. wcex.hIcon = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182342. iconNum = 1;
  182343. wcex.hIconSm = ExtractAssociatedIcon (moduleHandle, moduleFile, &iconNum);
  182344. wcex.hCursor = 0;
  182345. wcex.hbrBackground = 0;
  182346. wcex.lpszMenuName = 0;
  182347. RegisterClassEx (&wcex);
  182348. }
  182349. ~WindowClassHolder()
  182350. {
  182351. if (ComponentPeer::getNumPeers() == 0)
  182352. UnregisterClass (windowClassName, (HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle());
  182353. clearSingletonInstance();
  182354. }
  182355. String windowClassName;
  182356. juce_DeclareSingleton_SingleThreaded_Minimal (WindowClassHolder);
  182357. };
  182358. static void* createWindowCallback (void* userData)
  182359. {
  182360. ((Win32ComponentPeer*) userData)->createWindow();
  182361. return 0;
  182362. }
  182363. void createWindow()
  182364. {
  182365. DWORD exstyle = WS_EX_ACCEPTFILES;
  182366. DWORD type = WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
  182367. if (hasTitleBar())
  182368. {
  182369. type |= WS_OVERLAPPED;
  182370. exstyle |= WS_EX_APPWINDOW;
  182371. if ((styleFlags & windowHasCloseButton) != 0)
  182372. {
  182373. type |= WS_SYSMENU;
  182374. }
  182375. else
  182376. {
  182377. // annoyingly, windows won't let you have a min/max button without a close button
  182378. jassert ((styleFlags & (windowHasMinimiseButton | windowHasMaximiseButton)) == 0);
  182379. }
  182380. if ((styleFlags & windowIsResizable) != 0)
  182381. type |= WS_THICKFRAME;
  182382. }
  182383. else
  182384. {
  182385. type |= WS_POPUP | WS_SYSMENU;
  182386. if ((styleFlags & windowAppearsOnTaskbar) == 0)
  182387. exstyle |= WS_EX_TOOLWINDOW;
  182388. else
  182389. exstyle |= WS_EX_APPWINDOW;
  182390. }
  182391. if ((styleFlags & windowHasMinimiseButton) != 0)
  182392. type |= WS_MINIMIZEBOX;
  182393. if ((styleFlags & windowHasMaximiseButton) != 0)
  182394. type |= WS_MAXIMIZEBOX;
  182395. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  182396. exstyle |= WS_EX_TRANSPARENT;
  182397. if ((styleFlags & windowIsSemiTransparent) != 0
  182398. && Desktop::canUseSemiTransparentWindows())
  182399. exstyle |= WS_EX_LAYERED;
  182400. hwnd = CreateWindowEx (exstyle, WindowClassHolder::getInstance()->windowClassName, L"", type, 0, 0, 0, 0, 0, 0, 0, 0);
  182401. if (hwnd != 0)
  182402. {
  182403. SetWindowLongPtr (hwnd, 0, 0);
  182404. SetWindowLongPtr (hwnd, 8, (LONG_PTR) this);
  182405. SetWindowLongPtr (hwnd, GWLP_USERDATA, improbableWindowNumber);
  182406. if (dropTarget == 0)
  182407. dropTarget = new JuceDropTarget (this);
  182408. RegisterDragDrop (hwnd, dropTarget);
  182409. updateBorderSize();
  182410. // Calling this function here is (for some reason) necessary to make Windows
  182411. // correctly enable the menu items that we specify in the wm_initmenu message.
  182412. GetSystemMenu (hwnd, false);
  182413. }
  182414. else
  182415. {
  182416. jassertfalse
  182417. }
  182418. }
  182419. static void* destroyWindowCallback (void* handle)
  182420. {
  182421. RevokeDragDrop ((HWND) handle);
  182422. DestroyWindow ((HWND) handle);
  182423. return 0;
  182424. }
  182425. static void* toFrontCallback1 (void* h)
  182426. {
  182427. SetForegroundWindow ((HWND) h);
  182428. return 0;
  182429. }
  182430. static void* toFrontCallback2 (void* h)
  182431. {
  182432. SetWindowPos ((HWND) h, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE | SWP_NOSENDCHANGING);
  182433. return 0;
  182434. }
  182435. static void* setFocusCallback (void* h)
  182436. {
  182437. SetFocus ((HWND) h);
  182438. return 0;
  182439. }
  182440. static void* getFocusCallback (void*)
  182441. {
  182442. return (void*) GetFocus();
  182443. }
  182444. void offsetWithinParent (int& x, int& y) const
  182445. {
  182446. if (isTransparent())
  182447. {
  182448. HWND parentHwnd = GetParent (hwnd);
  182449. if (parentHwnd != 0)
  182450. {
  182451. RECT parentRect;
  182452. GetWindowRect (parentHwnd, &parentRect);
  182453. x += parentRect.left;
  182454. y += parentRect.top;
  182455. }
  182456. }
  182457. }
  182458. bool isTransparent() const
  182459. {
  182460. return (GetWindowLong (hwnd, GWL_EXSTYLE) & WS_EX_LAYERED) != 0;
  182461. }
  182462. inline bool hasTitleBar() const throw() { return (styleFlags & windowHasTitleBar) != 0; }
  182463. void setIcon (const Image& newIcon)
  182464. {
  182465. HICON hicon = createHICONFromImage (newIcon, TRUE, 0, 0);
  182466. if (hicon != 0)
  182467. {
  182468. SendMessage (hwnd, WM_SETICON, ICON_BIG, (LPARAM) hicon);
  182469. SendMessage (hwnd, WM_SETICON, ICON_SMALL, (LPARAM) hicon);
  182470. if (currentWindowIcon != 0)
  182471. DestroyIcon (currentWindowIcon);
  182472. currentWindowIcon = hicon;
  182473. }
  182474. }
  182475. void handlePaintMessage()
  182476. {
  182477. #if DEBUG_REPAINT_TIMES
  182478. const double paintStart = Time::getMillisecondCounterHiRes();
  182479. #endif
  182480. HRGN rgn = CreateRectRgn (0, 0, 0, 0);
  182481. const int regionType = GetUpdateRgn (hwnd, rgn, false);
  182482. PAINTSTRUCT paintStruct;
  182483. HDC dc = BeginPaint (hwnd, &paintStruct); // Note this can immediately generate a WM_NCPAINT
  182484. // message and become re-entrant, but that's OK
  182485. // if something in a paint handler calls, e.g. a message box, this can become reentrant and
  182486. // corrupt the image it's using to paint into, so do a check here.
  182487. static bool reentrant = false;
  182488. if (reentrant)
  182489. {
  182490. DeleteObject (rgn);
  182491. EndPaint (hwnd, &paintStruct);
  182492. return;
  182493. }
  182494. reentrant = true;
  182495. // this is the rectangle to update..
  182496. int x = paintStruct.rcPaint.left;
  182497. int y = paintStruct.rcPaint.top;
  182498. int w = paintStruct.rcPaint.right - x;
  182499. int h = paintStruct.rcPaint.bottom - y;
  182500. const bool transparent = isTransparent();
  182501. if (transparent)
  182502. {
  182503. // it's not possible to have a transparent window with a title bar at the moment!
  182504. jassert (! hasTitleBar());
  182505. RECT r;
  182506. GetWindowRect (hwnd, &r);
  182507. x = y = 0;
  182508. w = r.right - r.left;
  182509. h = r.bottom - r.top;
  182510. }
  182511. if (w > 0 && h > 0)
  182512. {
  182513. clearMaskedRegion();
  182514. WindowsBitmapImage* const offscreenImage = offscreenImageGenerator.getImage (transparent, w, h);
  182515. RectangleList contextClip;
  182516. bool needToPaintAll = true;
  182517. if (regionType == COMPLEXREGION && ! transparent)
  182518. {
  182519. HRGN clipRgn = CreateRectRgnIndirect (&paintStruct.rcPaint);
  182520. CombineRgn (rgn, rgn, clipRgn, RGN_AND);
  182521. DeleteObject (clipRgn);
  182522. char rgnData [8192];
  182523. const DWORD res = GetRegionData (rgn, sizeof (rgnData), (RGNDATA*) rgnData);
  182524. if (res > 0 && res <= sizeof (rgnData))
  182525. {
  182526. const RGNDATAHEADER* const hdr = &(((const RGNDATA*) rgnData)->rdh);
  182527. if (hdr->iType == RDH_RECTANGLES
  182528. && hdr->rcBound.right - hdr->rcBound.left >= w
  182529. && hdr->rcBound.bottom - hdr->rcBound.top >= h)
  182530. {
  182531. needToPaintAll = false;
  182532. const RECT* rects = (const RECT*) (rgnData + sizeof (RGNDATAHEADER));
  182533. int num = ((RGNDATA*) rgnData)->rdh.nCount;
  182534. while (--num >= 0)
  182535. {
  182536. // (need to move this one pixel to the left because of a win32 bug)
  182537. const int cx = jmax (x, (int) rects->left - 1);
  182538. const int cy = rects->top;
  182539. const int cw = rects->right - cx;
  182540. const int ch = rects->bottom - rects->top;
  182541. if (cx + cw - x <= w && cy + ch - y <= h)
  182542. {
  182543. contextClip.addWithoutMerging (Rectangle<int> (cx - x, cy - y, cw, ch));
  182544. }
  182545. else
  182546. {
  182547. needToPaintAll = true;
  182548. break;
  182549. }
  182550. ++rects;
  182551. }
  182552. }
  182553. }
  182554. }
  182555. if (needToPaintAll)
  182556. {
  182557. contextClip.clear();
  182558. contextClip.addWithoutMerging (Rectangle<int> (0, 0, w, h));
  182559. }
  182560. if (transparent)
  182561. {
  182562. RectangleList::Iterator i (contextClip);
  182563. while (i.next())
  182564. {
  182565. const Rectangle<int>& r = *i.getRectangle();
  182566. offscreenImage->clear (r.getX(), r.getY(), r.getWidth(), r.getHeight());
  182567. }
  182568. }
  182569. // if the component's not opaque, this won't draw properly unless the platform can support this
  182570. jassert (Desktop::canUseSemiTransparentWindows() || component->isOpaque());
  182571. updateCurrentModifiers();
  182572. LowLevelGraphicsSoftwareRenderer context (*offscreenImage);
  182573. context.clipToRectangleList (contextClip);
  182574. context.setOrigin (-x, -y);
  182575. handlePaint (context);
  182576. if (! dontRepaint)
  182577. offscreenImage->blitToWindow (hwnd, dc, transparent, x, y, maskedRegion);
  182578. }
  182579. DeleteObject (rgn);
  182580. EndPaint (hwnd, &paintStruct);
  182581. reentrant = false;
  182582. #ifndef JUCE_GCC //xxx should add this fn for gcc..
  182583. _fpreset(); // because some graphics cards can unmask FP exceptions
  182584. #endif
  182585. lastPaintTime = Time::getMillisecondCounter();
  182586. #if DEBUG_REPAINT_TIMES
  182587. const double elapsed = Time::getMillisecondCounterHiRes() - paintStart;
  182588. Logger::outputDebugString (T("repaint time: ") + String (elapsed, 2));
  182589. #endif
  182590. }
  182591. void doMouseMove (const int x, const int y)
  182592. {
  182593. static uint32 lastMouseTime = 0;
  182594. // this can be set to throttle the mouse-messages to less than a
  182595. // certain number per second, as things can get unresponsive
  182596. // if each drag or move callback has to do a lot of work.
  182597. const int maxMouseMovesPerSecond = 60;
  182598. const int64 mouseEventTime = getMouseEventTime();
  182599. if (! isMouseOver)
  182600. {
  182601. isMouseOver = true;
  182602. TRACKMOUSEEVENT tme;
  182603. tme.cbSize = sizeof (tme);
  182604. tme.dwFlags = TME_LEAVE;
  182605. tme.hwndTrack = hwnd;
  182606. tme.dwHoverTime = 0;
  182607. if (! TrackMouseEvent (&tme))
  182608. {
  182609. jassertfalse;
  182610. }
  182611. updateKeyModifiers();
  182612. handleMouseEnter (Point<int> (x, y), mouseEventTime);
  182613. }
  182614. else if (! isDragging)
  182615. {
  182616. if (((unsigned int) x) < (unsigned int) component->getWidth()
  182617. && ((unsigned int) y) < (unsigned int) component->getHeight())
  182618. {
  182619. RECT r;
  182620. GetWindowRect (hwnd, &r);
  182621. POINT p;
  182622. p.x = x + r.left + windowBorder.getLeft();
  182623. p.y = y + r.top + windowBorder.getTop();
  182624. if (WindowFromPoint (p) == hwnd)
  182625. {
  182626. const uint32 now = Time::getMillisecondCounter();
  182627. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182628. {
  182629. lastMouseTime = now;
  182630. handleMouseMove (Point<int> (x, y), mouseEventTime);
  182631. }
  182632. }
  182633. }
  182634. }
  182635. else
  182636. {
  182637. const uint32 now = Time::getMillisecondCounter();
  182638. if (now > lastMouseTime + 1000 / maxMouseMovesPerSecond)
  182639. {
  182640. lastMouseTime = now;
  182641. handleMouseDrag (Point<int> (x, y), mouseEventTime);
  182642. }
  182643. }
  182644. }
  182645. void doMouseDown (const int x, const int y, const WPARAM wParam)
  182646. {
  182647. if (GetCapture() != hwnd)
  182648. SetCapture (hwnd);
  182649. doMouseMove (x, y);
  182650. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  182651. if ((wParam & MK_LBUTTON) != 0)
  182652. currentModifiers |= ModifierKeys::leftButtonModifier;
  182653. if ((wParam & MK_RBUTTON) != 0)
  182654. currentModifiers |= ModifierKeys::rightButtonModifier;
  182655. if ((wParam & MK_MBUTTON) != 0)
  182656. currentModifiers |= ModifierKeys::middleButtonModifier;
  182657. updateKeyModifiers();
  182658. isDragging = true;
  182659. handleMouseDown (Point<int> (x, y), getMouseEventTime());
  182660. }
  182661. void doMouseUp (const int x, const int y, const WPARAM wParam)
  182662. {
  182663. int numButtons = 0;
  182664. if ((wParam & MK_LBUTTON) != 0)
  182665. ++numButtons;
  182666. if ((wParam & MK_RBUTTON) != 0)
  182667. ++numButtons;
  182668. if ((wParam & MK_MBUTTON) != 0)
  182669. ++numButtons;
  182670. const int oldModifiers = currentModifiers;
  182671. // update the currentmodifiers only after the callback, so the callback
  182672. // knows which button was released.
  182673. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  182674. if ((wParam & MK_LBUTTON) != 0)
  182675. currentModifiers |= ModifierKeys::leftButtonModifier;
  182676. if ((wParam & MK_RBUTTON) != 0)
  182677. currentModifiers |= ModifierKeys::rightButtonModifier;
  182678. if ((wParam & MK_MBUTTON) != 0)
  182679. currentModifiers |= ModifierKeys::middleButtonModifier;
  182680. updateKeyModifiers();
  182681. isDragging = false;
  182682. // release the mouse capture if the user's not still got a button down
  182683. if (numButtons == 0 && hwnd == GetCapture())
  182684. ReleaseCapture();
  182685. handleMouseUp (oldModifiers, Point<int> (x, y), getMouseEventTime());
  182686. }
  182687. void doCaptureChanged()
  182688. {
  182689. if (isDragging)
  182690. {
  182691. RECT wr;
  182692. GetWindowRect (hwnd, &wr);
  182693. const DWORD mp = GetMessagePos();
  182694. doMouseUp (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182695. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop(),
  182696. (WPARAM) getMouseEventTime());
  182697. }
  182698. }
  182699. void doMouseExit()
  182700. {
  182701. if (isMouseOver)
  182702. {
  182703. isMouseOver = false;
  182704. RECT wr;
  182705. GetWindowRect (hwnd, &wr);
  182706. const DWORD mp = GetMessagePos();
  182707. handleMouseExit (Point<int> (GET_X_LPARAM (mp) - wr.left - windowBorder.getLeft(),
  182708. GET_Y_LPARAM (mp) - wr.top - windowBorder.getTop()),
  182709. getMouseEventTime());
  182710. }
  182711. }
  182712. void doMouseWheel (const WPARAM wParam, const bool isVertical)
  182713. {
  182714. updateKeyModifiers();
  182715. const int amount = jlimit (-1000, 1000, (int) (0.75f * (short) HIWORD (wParam)));
  182716. handleMouseWheel (isVertical ? 0 : amount,
  182717. isVertical ? amount : 0,
  182718. getMouseEventTime());
  182719. }
  182720. void sendModifierKeyChangeIfNeeded()
  182721. {
  182722. if (modifiersAtLastCallback != currentModifiers)
  182723. {
  182724. modifiersAtLastCallback = currentModifiers;
  182725. handleModifierKeysChange();
  182726. }
  182727. }
  182728. bool doKeyUp (const WPARAM key)
  182729. {
  182730. updateKeyModifiers();
  182731. switch (key)
  182732. {
  182733. case VK_SHIFT:
  182734. case VK_CONTROL:
  182735. case VK_MENU:
  182736. case VK_CAPITAL:
  182737. case VK_LWIN:
  182738. case VK_RWIN:
  182739. case VK_APPS:
  182740. case VK_NUMLOCK:
  182741. case VK_SCROLL:
  182742. case VK_LSHIFT:
  182743. case VK_RSHIFT:
  182744. case VK_LCONTROL:
  182745. case VK_LMENU:
  182746. case VK_RCONTROL:
  182747. case VK_RMENU:
  182748. sendModifierKeyChangeIfNeeded();
  182749. }
  182750. return handleKeyUpOrDown (false)
  182751. || Component::getCurrentlyModalComponent() != 0;
  182752. }
  182753. bool doKeyDown (const WPARAM key)
  182754. {
  182755. updateKeyModifiers();
  182756. bool used = false;
  182757. switch (key)
  182758. {
  182759. case VK_SHIFT:
  182760. case VK_LSHIFT:
  182761. case VK_RSHIFT:
  182762. case VK_CONTROL:
  182763. case VK_LCONTROL:
  182764. case VK_RCONTROL:
  182765. case VK_MENU:
  182766. case VK_LMENU:
  182767. case VK_RMENU:
  182768. case VK_LWIN:
  182769. case VK_RWIN:
  182770. case VK_CAPITAL:
  182771. case VK_NUMLOCK:
  182772. case VK_SCROLL:
  182773. case VK_APPS:
  182774. sendModifierKeyChangeIfNeeded();
  182775. break;
  182776. case VK_LEFT:
  182777. case VK_RIGHT:
  182778. case VK_UP:
  182779. case VK_DOWN:
  182780. case VK_PRIOR:
  182781. case VK_NEXT:
  182782. case VK_HOME:
  182783. case VK_END:
  182784. case VK_DELETE:
  182785. case VK_INSERT:
  182786. case VK_F1:
  182787. case VK_F2:
  182788. case VK_F3:
  182789. case VK_F4:
  182790. case VK_F5:
  182791. case VK_F6:
  182792. case VK_F7:
  182793. case VK_F8:
  182794. case VK_F9:
  182795. case VK_F10:
  182796. case VK_F11:
  182797. case VK_F12:
  182798. case VK_F13:
  182799. case VK_F14:
  182800. case VK_F15:
  182801. case VK_F16:
  182802. used = handleKeyUpOrDown (true);
  182803. used = handleKeyPress (extendedKeyModifier | (int) key, 0) || used;
  182804. break;
  182805. case VK_ADD:
  182806. case VK_SUBTRACT:
  182807. case VK_MULTIPLY:
  182808. case VK_DIVIDE:
  182809. case VK_SEPARATOR:
  182810. case VK_DECIMAL:
  182811. used = handleKeyUpOrDown (true);
  182812. break;
  182813. default:
  182814. used = handleKeyUpOrDown (true);
  182815. {
  182816. MSG msg;
  182817. if (! PeekMessage (&msg, hwnd, WM_CHAR, WM_DEADCHAR, PM_NOREMOVE))
  182818. {
  182819. // if there isn't a WM_CHAR or WM_DEADCHAR message pending, we need to
  182820. // manually generate the key-press event that matches this key-down.
  182821. const UINT keyChar = MapVirtualKey (key, 2);
  182822. used = handleKeyPress ((int) LOWORD (keyChar), 0) || used;
  182823. }
  182824. }
  182825. break;
  182826. }
  182827. if (Component::getCurrentlyModalComponent() != 0)
  182828. used = true;
  182829. return used;
  182830. }
  182831. bool doKeyChar (int key, const LPARAM flags)
  182832. {
  182833. updateKeyModifiers();
  182834. juce_wchar textChar = (juce_wchar) key;
  182835. const int virtualScanCode = (flags >> 16) & 0xff;
  182836. if (key >= '0' && key <= '9')
  182837. {
  182838. switch (virtualScanCode) // check for a numeric keypad scan-code
  182839. {
  182840. case 0x52:
  182841. case 0x4f:
  182842. case 0x50:
  182843. case 0x51:
  182844. case 0x4b:
  182845. case 0x4c:
  182846. case 0x4d:
  182847. case 0x47:
  182848. case 0x48:
  182849. case 0x49:
  182850. key = (key - '0') + KeyPress::numberPad0;
  182851. break;
  182852. default:
  182853. break;
  182854. }
  182855. }
  182856. else
  182857. {
  182858. // convert the scan code to an unmodified character code..
  182859. const UINT virtualKey = MapVirtualKey (virtualScanCode, 1);
  182860. UINT keyChar = MapVirtualKey (virtualKey, 2);
  182861. keyChar = LOWORD (keyChar);
  182862. if (keyChar != 0)
  182863. key = (int) keyChar;
  182864. // avoid sending junk text characters for some control-key combinations
  182865. if (textChar < ' ' && (currentModifiers & (ModifierKeys::ctrlModifier | ModifierKeys::altModifier)) != 0)
  182866. textChar = 0;
  182867. }
  182868. return handleKeyPress (key, textChar);
  182869. }
  182870. bool doAppCommand (const LPARAM lParam)
  182871. {
  182872. int key = 0;
  182873. switch (GET_APPCOMMAND_LPARAM (lParam))
  182874. {
  182875. case APPCOMMAND_MEDIA_PLAY_PAUSE:
  182876. key = KeyPress::playKey;
  182877. break;
  182878. case APPCOMMAND_MEDIA_STOP:
  182879. key = KeyPress::stopKey;
  182880. break;
  182881. case APPCOMMAND_MEDIA_NEXTTRACK:
  182882. key = KeyPress::fastForwardKey;
  182883. break;
  182884. case APPCOMMAND_MEDIA_PREVIOUSTRACK:
  182885. key = KeyPress::rewindKey;
  182886. break;
  182887. }
  182888. if (key != 0)
  182889. {
  182890. updateKeyModifiers();
  182891. if (hwnd == GetActiveWindow())
  182892. {
  182893. handleKeyPress (key, 0);
  182894. return true;
  182895. }
  182896. }
  182897. return false;
  182898. }
  182899. class JuceDropTarget : public IDropTarget
  182900. {
  182901. public:
  182902. JuceDropTarget (Win32ComponentPeer* const owner_)
  182903. : owner (owner_),
  182904. refCount (1)
  182905. {
  182906. }
  182907. virtual ~JuceDropTarget()
  182908. {
  182909. jassert (refCount == 0);
  182910. }
  182911. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  182912. {
  182913. if (id == IID_IUnknown || id == IID_IDropTarget)
  182914. {
  182915. AddRef();
  182916. *result = this;
  182917. return S_OK;
  182918. }
  182919. *result = 0;
  182920. return E_NOINTERFACE;
  182921. }
  182922. ULONG __stdcall AddRef() { return ++refCount; }
  182923. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  182924. HRESULT __stdcall DragEnter (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182925. {
  182926. updateFileList (pDataObject);
  182927. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182928. *pdwEffect = DROPEFFECT_COPY;
  182929. return S_OK;
  182930. }
  182931. HRESULT __stdcall DragLeave()
  182932. {
  182933. owner->handleFileDragExit (files);
  182934. return S_OK;
  182935. }
  182936. HRESULT __stdcall DragOver (DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182937. {
  182938. owner->handleFileDragMove (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182939. *pdwEffect = DROPEFFECT_COPY;
  182940. return S_OK;
  182941. }
  182942. HRESULT __stdcall Drop (IDataObject* pDataObject, DWORD /*grfKeyState*/, POINTL mousePos, DWORD* pdwEffect)
  182943. {
  182944. updateFileList (pDataObject);
  182945. owner->handleFileDragDrop (files, owner->globalPositionToRelative (Point<int> (mousePos.x, mousePos.y)));
  182946. *pdwEffect = DROPEFFECT_COPY;
  182947. return S_OK;
  182948. }
  182949. private:
  182950. Win32ComponentPeer* const owner;
  182951. int refCount;
  182952. StringArray files;
  182953. void updateFileList (IDataObject* const pDataObject)
  182954. {
  182955. files.clear();
  182956. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  182957. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  182958. if (pDataObject->GetData (&format, &medium) == S_OK)
  182959. {
  182960. const SIZE_T totalLen = GlobalSize (medium.hGlobal);
  182961. const LPDROPFILES pDropFiles = (const LPDROPFILES) GlobalLock (medium.hGlobal);
  182962. unsigned int i = 0;
  182963. if (pDropFiles->fWide)
  182964. {
  182965. const WCHAR* const fname = (WCHAR*) (((const char*) pDropFiles) + sizeof (DROPFILES));
  182966. for (;;)
  182967. {
  182968. unsigned int len = 0;
  182969. while (i + len < totalLen && fname [i + len] != 0)
  182970. ++len;
  182971. if (len == 0)
  182972. break;
  182973. files.add (String (fname + i, len));
  182974. i += len + 1;
  182975. }
  182976. }
  182977. else
  182978. {
  182979. const char* const fname = ((const char*) pDropFiles) + sizeof (DROPFILES);
  182980. for (;;)
  182981. {
  182982. unsigned int len = 0;
  182983. while (i + len < totalLen && fname [i + len] != 0)
  182984. ++len;
  182985. if (len == 0)
  182986. break;
  182987. files.add (String (fname + i, len));
  182988. i += len + 1;
  182989. }
  182990. }
  182991. GlobalUnlock (medium.hGlobal);
  182992. }
  182993. }
  182994. JuceDropTarget (const JuceDropTarget&);
  182995. JuceDropTarget& operator= (const JuceDropTarget&);
  182996. };
  182997. void doSettingChange()
  182998. {
  182999. Desktop::getInstance().refreshMonitorSizes();
  183000. if (fullScreen && ! isMinimised())
  183001. {
  183002. const Rectangle<int> r (component->getParentMonitorArea());
  183003. SetWindowPos (hwnd, 0,
  183004. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  183005. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER | SWP_NOSENDCHANGING);
  183006. }
  183007. }
  183008. public:
  183009. static LRESULT CALLBACK windowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  183010. {
  183011. Win32ComponentPeer* const peer = getOwnerOfWindow (h);
  183012. if (peer != 0)
  183013. return peer->peerWindowProc (h, message, wParam, lParam);
  183014. return DefWindowProc (h, message, wParam, lParam);
  183015. }
  183016. private:
  183017. LRESULT peerWindowProc (HWND h, UINT message, WPARAM wParam, LPARAM lParam)
  183018. {
  183019. if (isValidPeer (this))
  183020. {
  183021. switch (message)
  183022. {
  183023. case WM_NCHITTEST:
  183024. if ((styleFlags & windowIgnoresMouseClicks) != 0)
  183025. return HTTRANSPARENT;
  183026. if (hasTitleBar())
  183027. break;
  183028. return HTCLIENT;
  183029. case WM_PAINT:
  183030. handlePaintMessage();
  183031. return 0;
  183032. case WM_NCPAINT:
  183033. if (wParam != 1)
  183034. handlePaintMessage();
  183035. if (hasTitleBar())
  183036. break;
  183037. return 0;
  183038. case WM_ERASEBKGND:
  183039. case WM_NCCALCSIZE:
  183040. if (hasTitleBar())
  183041. break;
  183042. return 1;
  183043. case WM_MOUSEMOVE:
  183044. doMouseMove (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam));
  183045. return 0;
  183046. case WM_MOUSELEAVE:
  183047. doMouseExit();
  183048. return 0;
  183049. case WM_LBUTTONDOWN:
  183050. case WM_MBUTTONDOWN:
  183051. case WM_RBUTTONDOWN:
  183052. doMouseDown (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam), wParam);
  183053. return 0;
  183054. case WM_LBUTTONUP:
  183055. case WM_MBUTTONUP:
  183056. case WM_RBUTTONUP:
  183057. doMouseUp (GET_X_LPARAM (lParam), GET_Y_LPARAM (lParam), wParam);
  183058. return 0;
  183059. case WM_CAPTURECHANGED:
  183060. doCaptureChanged();
  183061. return 0;
  183062. case WM_NCMOUSEMOVE:
  183063. if (hasTitleBar())
  183064. break;
  183065. return 0;
  183066. case 0x020A: /* WM_MOUSEWHEEL */
  183067. doMouseWheel (wParam, true);
  183068. return 0;
  183069. case 0x020E: /* WM_MOUSEHWHEEL */
  183070. doMouseWheel (wParam, false);
  183071. return 0;
  183072. case WM_WINDOWPOSCHANGING:
  183073. if ((styleFlags & (windowHasTitleBar | windowIsResizable)) == (windowHasTitleBar | windowIsResizable))
  183074. {
  183075. WINDOWPOS* const wp = (WINDOWPOS*) lParam;
  183076. if ((wp->flags & (SWP_NOMOVE | SWP_NOSIZE)) != (SWP_NOMOVE | SWP_NOSIZE))
  183077. {
  183078. if (constrainer != 0)
  183079. {
  183080. const Rectangle<int> current (component->getX() - windowBorder.getLeft(),
  183081. component->getY() - windowBorder.getTop(),
  183082. component->getWidth() + windowBorder.getLeftAndRight(),
  183083. component->getHeight() + windowBorder.getTopAndBottom());
  183084. Rectangle<int> pos (wp->x, wp->y, wp->cx, wp->cy);
  183085. constrainer->checkBounds (pos, current,
  183086. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  183087. pos.getY() != current.getY() && pos.getBottom() == current.getBottom(),
  183088. pos.getX() != current.getX() && pos.getRight() == current.getRight(),
  183089. pos.getY() == current.getY() && pos.getBottom() != current.getBottom(),
  183090. pos.getX() == current.getX() && pos.getRight() != current.getRight());
  183091. wp->x = pos.getX();
  183092. wp->y = pos.getY();
  183093. wp->cx = pos.getWidth();
  183094. wp->cy = pos.getHeight();
  183095. }
  183096. }
  183097. }
  183098. return 0;
  183099. case WM_WINDOWPOSCHANGED:
  183100. handleMovedOrResized();
  183101. if (dontRepaint)
  183102. break; // needed for non-accelerated openGL windows to draw themselves correctly..
  183103. return 0;
  183104. case WM_KEYDOWN:
  183105. case WM_SYSKEYDOWN:
  183106. if (doKeyDown (wParam))
  183107. return 0;
  183108. break;
  183109. case WM_KEYUP:
  183110. case WM_SYSKEYUP:
  183111. if (doKeyUp (wParam))
  183112. return 0;
  183113. break;
  183114. case WM_CHAR:
  183115. if (doKeyChar ((int) wParam, lParam))
  183116. return 0;
  183117. break;
  183118. case WM_APPCOMMAND:
  183119. if (doAppCommand (lParam))
  183120. return TRUE;
  183121. break;
  183122. case WM_SETFOCUS:
  183123. updateKeyModifiers();
  183124. handleFocusGain();
  183125. break;
  183126. case WM_KILLFOCUS:
  183127. if (hasCreatedCaret)
  183128. {
  183129. hasCreatedCaret = false;
  183130. DestroyCaret();
  183131. }
  183132. handleFocusLoss();
  183133. break;
  183134. case WM_ACTIVATEAPP:
  183135. // Windows does weird things to process priority when you swap apps,
  183136. // so this forces an update when the app is brought to the front
  183137. if (wParam != FALSE)
  183138. juce_repeatLastProcessPriority();
  183139. else
  183140. Desktop::getInstance().setKioskModeComponent (0); // turn kiosk mode off if we lose focus
  183141. juce_CheckCurrentlyFocusedTopLevelWindow();
  183142. modifiersAtLastCallback = -1;
  183143. return 0;
  183144. case WM_ACTIVATE:
  183145. if (LOWORD (wParam) == WA_ACTIVE || LOWORD (wParam) == WA_CLICKACTIVE)
  183146. {
  183147. modifiersAtLastCallback = -1;
  183148. updateKeyModifiers();
  183149. if (isMinimised())
  183150. {
  183151. component->repaint();
  183152. handleMovedOrResized();
  183153. if (! isValidMessageListener())
  183154. return 0;
  183155. }
  183156. if (LOWORD (wParam) == WA_CLICKACTIVE
  183157. && component->isCurrentlyBlockedByAnotherModalComponent())
  183158. {
  183159. const Point<int> mousePos (component->getMouseXYRelative());
  183160. Component* const underMouse = component->getComponentAt (mousePos.getX(), mousePos.getY());
  183161. if (underMouse != 0 && underMouse->isCurrentlyBlockedByAnotherModalComponent())
  183162. Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  183163. return 0;
  183164. }
  183165. handleBroughtToFront();
  183166. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183167. Component::getCurrentlyModalComponent()->toFront (true);
  183168. return 0;
  183169. }
  183170. break;
  183171. case WM_NCACTIVATE:
  183172. // while a temporary window is being shown, prevent Windows from deactivating the
  183173. // title bars of our main windows.
  183174. if (wParam == 0 && ! shouldDeactivateTitleBar)
  183175. wParam = TRUE; // change this and let it get passed to the DefWindowProc.
  183176. break;
  183177. case WM_MOUSEACTIVATE:
  183178. if (! component->getMouseClickGrabsKeyboardFocus())
  183179. return MA_NOACTIVATE;
  183180. break;
  183181. case WM_SHOWWINDOW:
  183182. if (wParam != 0)
  183183. handleBroughtToFront();
  183184. break;
  183185. case WM_CLOSE:
  183186. if (! component->isCurrentlyBlockedByAnotherModalComponent())
  183187. handleUserClosingWindow();
  183188. return 0;
  183189. case WM_QUERYENDSESSION:
  183190. if (JUCEApplication::getInstance() != 0)
  183191. {
  183192. JUCEApplication::getInstance()->systemRequestedQuit();
  183193. return MessageManager::getInstance()->hasStopMessageBeenSent();
  183194. }
  183195. return TRUE;
  183196. case WM_TRAYNOTIFY:
  183197. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183198. {
  183199. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN
  183200. || lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  183201. {
  183202. Component* const current = Component::getCurrentlyModalComponent();
  183203. if (current != 0)
  183204. current->inputAttemptWhenModal();
  183205. }
  183206. }
  183207. else
  183208. {
  183209. const int oldModifiers = currentModifiers;
  183210. MouseEvent e (Point<int>(), ModifierKeys::getCurrentModifiersRealtime(), component,
  183211. getMouseEventTime(), Point<int>(), getMouseEventTime(), 1, false);
  183212. if (lParam == WM_LBUTTONDOWN || lParam == WM_LBUTTONDBLCLK)
  183213. e.mods = ModifierKeys (e.mods.getRawFlags() | ModifierKeys::leftButtonModifier);
  183214. else if (lParam == WM_RBUTTONDOWN || lParam == WM_RBUTTONDBLCLK)
  183215. e.mods = ModifierKeys (e.mods.getRawFlags() | ModifierKeys::rightButtonModifier);
  183216. if (lParam == WM_LBUTTONDOWN || lParam == WM_RBUTTONDOWN)
  183217. {
  183218. SetFocus (hwnd);
  183219. SetForegroundWindow (hwnd);
  183220. component->mouseDown (e);
  183221. }
  183222. else if (lParam == WM_LBUTTONUP || lParam == WM_RBUTTONUP)
  183223. {
  183224. e.mods = ModifierKeys (oldModifiers);
  183225. component->mouseUp (e);
  183226. }
  183227. else if (lParam == WM_LBUTTONDBLCLK || lParam == WM_LBUTTONDBLCLK)
  183228. {
  183229. e.mods = ModifierKeys (oldModifiers);
  183230. component->mouseDoubleClick (e);
  183231. }
  183232. else if (lParam == WM_MOUSEMOVE)
  183233. {
  183234. component->mouseMove (e);
  183235. }
  183236. }
  183237. break;
  183238. case WM_SYNCPAINT:
  183239. return 0;
  183240. case WM_PALETTECHANGED:
  183241. InvalidateRect (h, 0, 0);
  183242. break;
  183243. case WM_DISPLAYCHANGE:
  183244. InvalidateRect (h, 0, 0);
  183245. createPaletteIfNeeded = true;
  183246. // intentional fall-through...
  183247. case WM_SETTINGCHANGE: // note the fall-through in the previous case!
  183248. doSettingChange();
  183249. break;
  183250. case WM_INITMENU:
  183251. if (! hasTitleBar())
  183252. {
  183253. if (isFullScreen())
  183254. {
  183255. EnableMenuItem ((HMENU) wParam, SC_RESTORE, MF_BYCOMMAND | MF_ENABLED);
  183256. EnableMenuItem ((HMENU) wParam, SC_MOVE, MF_BYCOMMAND | MF_GRAYED);
  183257. }
  183258. else if (! isMinimised())
  183259. {
  183260. EnableMenuItem ((HMENU) wParam, SC_MAXIMIZE, MF_BYCOMMAND | MF_GRAYED);
  183261. }
  183262. }
  183263. break;
  183264. case WM_SYSCOMMAND:
  183265. switch (wParam & 0xfff0)
  183266. {
  183267. case SC_CLOSE:
  183268. if (sendInputAttemptWhenModalMessage())
  183269. return 0;
  183270. if (hasTitleBar())
  183271. {
  183272. PostMessage (h, WM_CLOSE, 0, 0);
  183273. return 0;
  183274. }
  183275. break;
  183276. case SC_KEYMENU:
  183277. // (NB mustn't call sendInputAttemptWhenModalMessage() here because of very
  183278. // obscure situations that can arise if a modal loop is started from an alt-key
  183279. // keypress).
  183280. if (hasTitleBar() && h == GetCapture())
  183281. ReleaseCapture();
  183282. break;
  183283. case SC_MAXIMIZE:
  183284. if (sendInputAttemptWhenModalMessage())
  183285. return 0;
  183286. setFullScreen (true);
  183287. return 0;
  183288. case SC_MINIMIZE:
  183289. if (sendInputAttemptWhenModalMessage())
  183290. return 0;
  183291. if (! hasTitleBar())
  183292. {
  183293. setMinimised (true);
  183294. return 0;
  183295. }
  183296. break;
  183297. case SC_RESTORE:
  183298. if (sendInputAttemptWhenModalMessage())
  183299. return 0;
  183300. if (hasTitleBar())
  183301. {
  183302. if (isFullScreen())
  183303. {
  183304. setFullScreen (false);
  183305. return 0;
  183306. }
  183307. }
  183308. else
  183309. {
  183310. if (isMinimised())
  183311. setMinimised (false);
  183312. else if (isFullScreen())
  183313. setFullScreen (false);
  183314. return 0;
  183315. }
  183316. break;
  183317. }
  183318. break;
  183319. case WM_NCLBUTTONDOWN:
  183320. case WM_NCRBUTTONDOWN:
  183321. case WM_NCMBUTTONDOWN:
  183322. sendInputAttemptWhenModalMessage();
  183323. break;
  183324. //case WM_IME_STARTCOMPOSITION;
  183325. // return 0;
  183326. case WM_GETDLGCODE:
  183327. return DLGC_WANTALLKEYS;
  183328. default:
  183329. break;
  183330. }
  183331. }
  183332. return DefWindowProc (h, message, wParam, lParam);
  183333. }
  183334. bool sendInputAttemptWhenModalMessage()
  183335. {
  183336. if (component->isCurrentlyBlockedByAnotherModalComponent())
  183337. {
  183338. Component* const current = Component::getCurrentlyModalComponent();
  183339. if (current != 0)
  183340. current->inputAttemptWhenModal();
  183341. return true;
  183342. }
  183343. return false;
  183344. }
  183345. Win32ComponentPeer (const Win32ComponentPeer&);
  183346. Win32ComponentPeer& operator= (const Win32ComponentPeer&);
  183347. };
  183348. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  183349. {
  183350. return new Win32ComponentPeer (this, styleFlags);
  183351. }
  183352. juce_ImplementSingleton_SingleThreaded (Win32ComponentPeer::WindowClassHolder);
  183353. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  183354. {
  183355. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183356. if (wp != 0)
  183357. wp->setTaskBarIcon (&newImage);
  183358. }
  183359. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  183360. {
  183361. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (getPeer());
  183362. if (wp != 0)
  183363. wp->setTaskBarIconToolTip (tooltip);
  183364. }
  183365. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw()
  183366. {
  183367. DWORD val = GetWindowLong (h, styleType);
  183368. if (bitIsSet)
  183369. val |= feature;
  183370. else
  183371. val &= ~feature;
  183372. SetWindowLongPtr (h, styleType, val);
  183373. SetWindowPos (h, 0, 0, 0, 0, 0,
  183374. SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER
  183375. | SWP_NOOWNERZORDER | SWP_FRAMECHANGED | SWP_NOSENDCHANGING);
  183376. }
  183377. bool Process::isForegroundProcess()
  183378. {
  183379. HWND fg = GetForegroundWindow();
  183380. if (fg == 0)
  183381. return true;
  183382. // when running as a plugin in IE8, the browser UI runs in a different process to the plugin, so
  183383. // process ID isn't a reliable way to check if the foreground window belongs to us - instead, we
  183384. // have to see if any of our windows are children of the foreground window
  183385. fg = GetAncestor (fg, GA_ROOT);
  183386. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  183387. {
  183388. Win32ComponentPeer* const wp = dynamic_cast <Win32ComponentPeer*> (ComponentPeer::getPeer (i));
  183389. if (wp != 0 && wp->isInside (fg))
  183390. return true;
  183391. }
  183392. return false;
  183393. }
  183394. bool AlertWindow::showNativeDialogBox (const String& title,
  183395. const String& bodyText,
  183396. bool isOkCancel)
  183397. {
  183398. return MessageBox (0, bodyText, title,
  183399. MB_SETFOREGROUND | (isOkCancel ? MB_OKCANCEL
  183400. : MB_OK)) == IDOK;
  183401. }
  183402. const Point<int> Desktop::getMousePosition()
  183403. {
  183404. POINT mousePos;
  183405. GetCursorPos (&mousePos);
  183406. return Point<int> (mousePos.x, mousePos.y);
  183407. }
  183408. void Desktop::setMousePosition (const Point<int>& newPosition)
  183409. {
  183410. SetCursorPos (newPosition.getX(), newPosition.getY());
  183411. }
  183412. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  183413. {
  183414. return new Image (format, imageWidth, imageHeight, clearImage);
  183415. }
  183416. class ScreenSaverDefeater : public Timer,
  183417. public DeletedAtShutdown
  183418. {
  183419. public:
  183420. ScreenSaverDefeater() throw()
  183421. {
  183422. startTimer (10000);
  183423. timerCallback();
  183424. }
  183425. ~ScreenSaverDefeater() {}
  183426. void timerCallback()
  183427. {
  183428. if (Process::isForegroundProcess())
  183429. {
  183430. // simulate a shift key getting pressed..
  183431. INPUT input[2];
  183432. input[0].type = INPUT_KEYBOARD;
  183433. input[0].ki.wVk = VK_SHIFT;
  183434. input[0].ki.dwFlags = 0;
  183435. input[0].ki.dwExtraInfo = 0;
  183436. input[1].type = INPUT_KEYBOARD;
  183437. input[1].ki.wVk = VK_SHIFT;
  183438. input[1].ki.dwFlags = KEYEVENTF_KEYUP;
  183439. input[1].ki.dwExtraInfo = 0;
  183440. SendInput (2, input, sizeof (INPUT));
  183441. }
  183442. }
  183443. };
  183444. static ScreenSaverDefeater* screenSaverDefeater = 0;
  183445. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  183446. {
  183447. if (isEnabled)
  183448. {
  183449. deleteAndZero (screenSaverDefeater);
  183450. }
  183451. else if (screenSaverDefeater == 0)
  183452. {
  183453. screenSaverDefeater = new ScreenSaverDefeater();
  183454. }
  183455. }
  183456. bool Desktop::isScreenSaverEnabled() throw()
  183457. {
  183458. return screenSaverDefeater == 0;
  183459. }
  183460. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool /*allowMenusAndBars*/)
  183461. {
  183462. if (enableOrDisable)
  183463. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  183464. }
  183465. static BOOL CALLBACK enumMonitorsProc (HMONITOR, HDC, LPRECT r, LPARAM userInfo)
  183466. {
  183467. Array <Rectangle<int> >* const monitorCoords = (Array <Rectangle<int> >*) userInfo;
  183468. monitorCoords->add (Rectangle<int> (r->left, r->top, r->right - r->left, r->bottom - r->top));
  183469. return TRUE;
  183470. }
  183471. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  183472. {
  183473. EnumDisplayMonitors (0, 0, &enumMonitorsProc, (LPARAM) &monitorCoords);
  183474. // make sure the first in the list is the main monitor
  183475. for (int i = 1; i < monitorCoords.size(); ++i)
  183476. if (monitorCoords[i].getX() == 0 && monitorCoords[i].getY() == 0)
  183477. monitorCoords.swap (i, 0);
  183478. if (monitorCoords.size() == 0)
  183479. {
  183480. RECT r;
  183481. GetWindowRect (GetDesktopWindow(), &r);
  183482. monitorCoords.add (Rectangle<int> (r.left, r.top, r.right - r.left, r.bottom - r.top));
  183483. }
  183484. if (clipToWorkArea)
  183485. {
  183486. // clip the main monitor to the active non-taskbar area
  183487. RECT r;
  183488. SystemParametersInfo (SPI_GETWORKAREA, 0, &r, 0);
  183489. Rectangle<int>& screen = monitorCoords.getReference (0);
  183490. screen.setPosition (jmax (screen.getX(), (int) r.left),
  183491. jmax (screen.getY(), (int) r.top));
  183492. screen.setSize (jmin (screen.getRight(), (int) r.right) - screen.getX(),
  183493. jmin (screen.getBottom(), (int) r.bottom) - screen.getY());
  183494. }
  183495. }
  183496. static Image* createImageFromHBITMAP (HBITMAP bitmap) throw()
  183497. {
  183498. Image* im = 0;
  183499. if (bitmap != 0)
  183500. {
  183501. BITMAP bm;
  183502. if (GetObject (bitmap, sizeof (BITMAP), &bm)
  183503. && bm.bmWidth > 0 && bm.bmHeight > 0)
  183504. {
  183505. HDC tempDC = GetDC (0);
  183506. HDC dc = CreateCompatibleDC (tempDC);
  183507. ReleaseDC (0, tempDC);
  183508. SelectObject (dc, bitmap);
  183509. im = new Image (Image::ARGB, bm.bmWidth, bm.bmHeight, true);
  183510. for (int y = bm.bmHeight; --y >= 0;)
  183511. {
  183512. for (int x = bm.bmWidth; --x >= 0;)
  183513. {
  183514. COLORREF col = GetPixel (dc, x, y);
  183515. im->setPixelAt (x, y, Colour ((uint8) GetRValue (col),
  183516. (uint8) GetGValue (col),
  183517. (uint8) GetBValue (col)));
  183518. }
  183519. }
  183520. DeleteDC (dc);
  183521. }
  183522. }
  183523. return im;
  183524. }
  183525. static Image* createImageFromHICON (HICON icon) throw()
  183526. {
  183527. ICONINFO info;
  183528. if (GetIconInfo (icon, &info))
  183529. {
  183530. Image* const mask = createImageFromHBITMAP (info.hbmMask);
  183531. if (mask == 0)
  183532. return 0;
  183533. Image* const image = createImageFromHBITMAP (info.hbmColor);
  183534. if (image == 0)
  183535. return mask;
  183536. for (int y = image->getHeight(); --y >= 0;)
  183537. {
  183538. for (int x = image->getWidth(); --x >= 0;)
  183539. {
  183540. const float brightness = mask->getPixelAt (x, y).getBrightness();
  183541. if (brightness > 0.0f)
  183542. image->multiplyAlphaAt (x, y, 1.0f - brightness);
  183543. }
  183544. }
  183545. delete mask;
  183546. return image;
  183547. }
  183548. return 0;
  183549. }
  183550. static HICON createHICONFromImage (const Image& image, const BOOL isIcon, int hotspotX, int hotspotY) throw()
  183551. {
  183552. HBITMAP mask = CreateBitmap (image.getWidth(), image.getHeight(), 1, 1, 0);
  183553. ICONINFO info;
  183554. info.fIcon = isIcon;
  183555. info.xHotspot = hotspotX;
  183556. info.yHotspot = hotspotY;
  183557. info.hbmMask = mask;
  183558. HICON hi = 0;
  183559. if (SystemStats::getOperatingSystemType() >= SystemStats::WinXP)
  183560. {
  183561. WindowsBitmapImage bitmap (Image::ARGB, image.getWidth(), image.getHeight(), true);
  183562. Graphics g (bitmap);
  183563. g.drawImageAt (&image, 0, 0);
  183564. info.hbmColor = bitmap.hBitmap;
  183565. hi = CreateIconIndirect (&info);
  183566. }
  183567. else
  183568. {
  183569. HBITMAP colour = CreateCompatibleBitmap (GetDC (0), image.getWidth(), image.getHeight());
  183570. HDC colDC = CreateCompatibleDC (GetDC (0));
  183571. HDC alphaDC = CreateCompatibleDC (GetDC (0));
  183572. SelectObject (colDC, colour);
  183573. SelectObject (alphaDC, mask);
  183574. for (int y = image.getHeight(); --y >= 0;)
  183575. {
  183576. for (int x = image.getWidth(); --x >= 0;)
  183577. {
  183578. const Colour c (image.getPixelAt (x, y));
  183579. SetPixel (colDC, x, y, COLORREF (c.getRed() | (c.getGreen() << 8) | (c.getBlue() << 16)));
  183580. SetPixel (alphaDC, x, y, COLORREF (0xffffff - (c.getAlpha() | (c.getAlpha() << 8) | (c.getAlpha() << 16))));
  183581. }
  183582. }
  183583. DeleteDC (colDC);
  183584. DeleteDC (alphaDC);
  183585. info.hbmColor = colour;
  183586. hi = CreateIconIndirect (&info);
  183587. DeleteObject (colour);
  183588. }
  183589. DeleteObject (mask);
  183590. return hi;
  183591. }
  183592. Image* juce_createIconForFile (const File& file)
  183593. {
  183594. Image* image = 0;
  183595. WCHAR filename [1024];
  183596. file.getFullPathName().copyToUnicode (filename, 1023);
  183597. WORD iconNum = 0;
  183598. HICON icon = ExtractAssociatedIcon ((HINSTANCE) PlatformUtilities::getCurrentModuleInstanceHandle(),
  183599. filename, &iconNum);
  183600. if (icon != 0)
  183601. {
  183602. image = createImageFromHICON (icon);
  183603. DestroyIcon (icon);
  183604. }
  183605. return image;
  183606. }
  183607. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  183608. {
  183609. const int maxW = GetSystemMetrics (SM_CXCURSOR);
  183610. const int maxH = GetSystemMetrics (SM_CYCURSOR);
  183611. const Image* im = &image;
  183612. Image* newIm = 0;
  183613. if (image.getWidth() > maxW || image.getHeight() > maxH)
  183614. {
  183615. im = newIm = image.createCopy (maxW, maxH);
  183616. hotspotX = (hotspotX * maxW) / image.getWidth();
  183617. hotspotY = (hotspotY * maxH) / image.getHeight();
  183618. }
  183619. void* cursorH = 0;
  183620. const SystemStats::OperatingSystemType os = SystemStats::getOperatingSystemType();
  183621. if (os == SystemStats::WinXP)
  183622. {
  183623. cursorH = (void*) createHICONFromImage (*im, FALSE, hotspotX, hotspotY);
  183624. }
  183625. else
  183626. {
  183627. const int stride = (maxW + 7) >> 3;
  183628. HeapBlock <uint8> andPlane, xorPlane;
  183629. andPlane.calloc (stride * maxH);
  183630. xorPlane.calloc (stride * maxH);
  183631. int index = 0;
  183632. for (int y = 0; y < maxH; ++y)
  183633. {
  183634. for (int x = 0; x < maxW; ++x)
  183635. {
  183636. const unsigned char bit = (unsigned char) (1 << (7 - (x & 7)));
  183637. const Colour pixelColour (im->getPixelAt (x, y));
  183638. if (pixelColour.getAlpha() < 127)
  183639. andPlane [index + (x >> 3)] |= bit;
  183640. else if (pixelColour.getBrightness() >= 0.5f)
  183641. xorPlane [index + (x >> 3)] |= bit;
  183642. }
  183643. index += stride;
  183644. }
  183645. cursorH = CreateCursor (0, hotspotX, hotspotY, maxW, maxH, andPlane, xorPlane);
  183646. }
  183647. delete newIm;
  183648. return cursorH;
  183649. }
  183650. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  183651. {
  183652. if (cursorHandle != 0 && ! isStandard)
  183653. DestroyCursor ((HCURSOR) cursorHandle);
  183654. }
  183655. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  183656. {
  183657. LPCTSTR cursorName = IDC_ARROW;
  183658. switch (type)
  183659. {
  183660. case MouseCursor::NormalCursor:
  183661. cursorName = IDC_ARROW;
  183662. break;
  183663. case MouseCursor::NoCursor:
  183664. return 0;
  183665. case MouseCursor::DraggingHandCursor:
  183666. {
  183667. static void* dragHandCursor = 0;
  183668. if (dragHandCursor == 0)
  183669. {
  183670. static const unsigned char dragHandData[] =
  183671. { 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,
  183672. 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,
  183673. 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 };
  183674. const ScopedPointer <Image> image (ImageFileFormat::loadFrom ((const char*) dragHandData, sizeof (dragHandData)));
  183675. dragHandCursor = juce_createMouseCursorFromImage (*image, 8, 7);
  183676. }
  183677. return dragHandCursor;
  183678. }
  183679. case MouseCursor::WaitCursor:
  183680. cursorName = IDC_WAIT;
  183681. break;
  183682. case MouseCursor::IBeamCursor:
  183683. cursorName = IDC_IBEAM;
  183684. break;
  183685. case MouseCursor::PointingHandCursor:
  183686. cursorName = MAKEINTRESOURCE(32649);
  183687. break;
  183688. case MouseCursor::LeftRightResizeCursor:
  183689. case MouseCursor::LeftEdgeResizeCursor:
  183690. case MouseCursor::RightEdgeResizeCursor:
  183691. cursorName = IDC_SIZEWE;
  183692. break;
  183693. case MouseCursor::UpDownResizeCursor:
  183694. case MouseCursor::TopEdgeResizeCursor:
  183695. case MouseCursor::BottomEdgeResizeCursor:
  183696. cursorName = IDC_SIZENS;
  183697. break;
  183698. case MouseCursor::TopLeftCornerResizeCursor:
  183699. case MouseCursor::BottomRightCornerResizeCursor:
  183700. cursorName = IDC_SIZENWSE;
  183701. break;
  183702. case MouseCursor::TopRightCornerResizeCursor:
  183703. case MouseCursor::BottomLeftCornerResizeCursor:
  183704. cursorName = IDC_SIZENESW;
  183705. break;
  183706. case MouseCursor::UpDownLeftRightResizeCursor:
  183707. cursorName = IDC_SIZEALL;
  183708. break;
  183709. case MouseCursor::CrosshairCursor:
  183710. cursorName = IDC_CROSS;
  183711. break;
  183712. case MouseCursor::CopyingCursor:
  183713. // can't seem to find one of these in the win32 list..
  183714. break;
  183715. }
  183716. HCURSOR cursorH = LoadCursor (0, cursorName);
  183717. if (cursorH == 0)
  183718. cursorH = LoadCursor (0, IDC_ARROW);
  183719. return (void*) cursorH;
  183720. }
  183721. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  183722. {
  183723. SetCursor ((HCURSOR) getHandle());
  183724. }
  183725. void MouseCursor::showInAllWindows() const throw()
  183726. {
  183727. showInWindow (0);
  183728. }
  183729. class JuceDropSource : public IDropSource
  183730. {
  183731. int refCount;
  183732. public:
  183733. JuceDropSource()
  183734. : refCount (1)
  183735. {
  183736. }
  183737. virtual ~JuceDropSource()
  183738. {
  183739. jassert (refCount == 0);
  183740. }
  183741. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183742. {
  183743. if (id == IID_IUnknown || id == IID_IDropSource)
  183744. {
  183745. AddRef();
  183746. *result = this;
  183747. return S_OK;
  183748. }
  183749. *result = 0;
  183750. return E_NOINTERFACE;
  183751. }
  183752. ULONG __stdcall AddRef() { return ++refCount; }
  183753. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183754. HRESULT __stdcall QueryContinueDrag (BOOL escapePressed, DWORD keys)
  183755. {
  183756. if (escapePressed)
  183757. return DRAGDROP_S_CANCEL;
  183758. if ((keys & (MK_LBUTTON | MK_RBUTTON)) == 0)
  183759. return DRAGDROP_S_DROP;
  183760. return S_OK;
  183761. }
  183762. HRESULT __stdcall GiveFeedback (DWORD)
  183763. {
  183764. return DRAGDROP_S_USEDEFAULTCURSORS;
  183765. }
  183766. };
  183767. class JuceEnumFormatEtc : public IEnumFORMATETC
  183768. {
  183769. public:
  183770. JuceEnumFormatEtc (const FORMATETC* const format_)
  183771. : refCount (1),
  183772. format (format_),
  183773. index (0)
  183774. {
  183775. }
  183776. virtual ~JuceEnumFormatEtc()
  183777. {
  183778. jassert (refCount == 0);
  183779. }
  183780. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183781. {
  183782. if (id == IID_IUnknown || id == IID_IEnumFORMATETC)
  183783. {
  183784. AddRef();
  183785. *result = this;
  183786. return S_OK;
  183787. }
  183788. *result = 0;
  183789. return E_NOINTERFACE;
  183790. }
  183791. ULONG __stdcall AddRef() { return ++refCount; }
  183792. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183793. HRESULT __stdcall Clone (IEnumFORMATETC** result)
  183794. {
  183795. if (result == 0)
  183796. return E_POINTER;
  183797. JuceEnumFormatEtc* const newOne = new JuceEnumFormatEtc (format);
  183798. newOne->index = index;
  183799. *result = newOne;
  183800. return S_OK;
  183801. }
  183802. HRESULT __stdcall Next (ULONG celt, LPFORMATETC lpFormatEtc, ULONG* pceltFetched)
  183803. {
  183804. if (pceltFetched != 0)
  183805. *pceltFetched = 0;
  183806. else if (celt != 1)
  183807. return S_FALSE;
  183808. if (index == 0 && celt > 0 && lpFormatEtc != 0)
  183809. {
  183810. copyFormatEtc (lpFormatEtc [0], *format);
  183811. ++index;
  183812. if (pceltFetched != 0)
  183813. *pceltFetched = 1;
  183814. return S_OK;
  183815. }
  183816. return S_FALSE;
  183817. }
  183818. HRESULT __stdcall Skip (ULONG celt)
  183819. {
  183820. if (index + (int) celt >= 1)
  183821. return S_FALSE;
  183822. index += celt;
  183823. return S_OK;
  183824. }
  183825. HRESULT __stdcall Reset()
  183826. {
  183827. index = 0;
  183828. return S_OK;
  183829. }
  183830. private:
  183831. int refCount;
  183832. const FORMATETC* const format;
  183833. int index;
  183834. static void copyFormatEtc (FORMATETC& dest, const FORMATETC& source)
  183835. {
  183836. dest = source;
  183837. if (source.ptd != 0)
  183838. {
  183839. dest.ptd = (DVTARGETDEVICE*) CoTaskMemAlloc (sizeof (DVTARGETDEVICE));
  183840. *(dest.ptd) = *(source.ptd);
  183841. }
  183842. }
  183843. JuceEnumFormatEtc (const JuceEnumFormatEtc&);
  183844. JuceEnumFormatEtc& operator= (const JuceEnumFormatEtc&);
  183845. };
  183846. class JuceDataObject : public IDataObject
  183847. {
  183848. JuceDropSource* const dropSource;
  183849. const FORMATETC* const format;
  183850. const STGMEDIUM* const medium;
  183851. int refCount;
  183852. JuceDataObject (const JuceDataObject&);
  183853. JuceDataObject& operator= (const JuceDataObject&);
  183854. public:
  183855. JuceDataObject (JuceDropSource* const dropSource_,
  183856. const FORMATETC* const format_,
  183857. const STGMEDIUM* const medium_)
  183858. : dropSource (dropSource_),
  183859. format (format_),
  183860. medium (medium_),
  183861. refCount (1)
  183862. {
  183863. }
  183864. virtual ~JuceDataObject()
  183865. {
  183866. jassert (refCount == 0);
  183867. }
  183868. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  183869. {
  183870. if (id == IID_IUnknown || id == IID_IDataObject)
  183871. {
  183872. AddRef();
  183873. *result = this;
  183874. return S_OK;
  183875. }
  183876. *result = 0;
  183877. return E_NOINTERFACE;
  183878. }
  183879. ULONG __stdcall AddRef() { return ++refCount; }
  183880. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  183881. HRESULT __stdcall GetData (FORMATETC __RPC_FAR* pFormatEtc, STGMEDIUM __RPC_FAR* pMedium)
  183882. {
  183883. if ((pFormatEtc->tymed & format->tymed) != 0
  183884. && pFormatEtc->cfFormat == format->cfFormat
  183885. && pFormatEtc->dwAspect == format->dwAspect)
  183886. {
  183887. pMedium->tymed = format->tymed;
  183888. pMedium->pUnkForRelease = 0;
  183889. if (format->tymed == TYMED_HGLOBAL)
  183890. {
  183891. const SIZE_T len = GlobalSize (medium->hGlobal);
  183892. void* const src = GlobalLock (medium->hGlobal);
  183893. void* const dst = GlobalAlloc (GMEM_FIXED, len);
  183894. memcpy (dst, src, len);
  183895. GlobalUnlock (medium->hGlobal);
  183896. pMedium->hGlobal = dst;
  183897. return S_OK;
  183898. }
  183899. }
  183900. return DV_E_FORMATETC;
  183901. }
  183902. HRESULT __stdcall QueryGetData (FORMATETC __RPC_FAR* f)
  183903. {
  183904. if (f == 0)
  183905. return E_INVALIDARG;
  183906. if (f->tymed == format->tymed
  183907. && f->cfFormat == format->cfFormat
  183908. && f->dwAspect == format->dwAspect)
  183909. return S_OK;
  183910. return DV_E_FORMATETC;
  183911. }
  183912. HRESULT __stdcall GetCanonicalFormatEtc (FORMATETC __RPC_FAR*, FORMATETC __RPC_FAR* pFormatEtcOut)
  183913. {
  183914. pFormatEtcOut->ptd = 0;
  183915. return E_NOTIMPL;
  183916. }
  183917. HRESULT __stdcall EnumFormatEtc (DWORD direction, IEnumFORMATETC __RPC_FAR *__RPC_FAR *result)
  183918. {
  183919. if (result == 0)
  183920. return E_POINTER;
  183921. if (direction == DATADIR_GET)
  183922. {
  183923. *result = new JuceEnumFormatEtc (format);
  183924. return S_OK;
  183925. }
  183926. *result = 0;
  183927. return E_NOTIMPL;
  183928. }
  183929. HRESULT __stdcall GetDataHere (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*) { return DATA_E_FORMATETC; }
  183930. HRESULT __stdcall SetData (FORMATETC __RPC_FAR*, STGMEDIUM __RPC_FAR*, BOOL) { return E_NOTIMPL; }
  183931. HRESULT __stdcall DAdvise (FORMATETC __RPC_FAR*, DWORD, IAdviseSink __RPC_FAR*, DWORD __RPC_FAR*) { return OLE_E_ADVISENOTSUPPORTED; }
  183932. HRESULT __stdcall DUnadvise (DWORD) { return E_NOTIMPL; }
  183933. HRESULT __stdcall EnumDAdvise (IEnumSTATDATA __RPC_FAR *__RPC_FAR *) { return OLE_E_ADVISENOTSUPPORTED; }
  183934. };
  183935. static HDROP createHDrop (const StringArray& fileNames) throw()
  183936. {
  183937. int totalChars = 0;
  183938. for (int i = fileNames.size(); --i >= 0;)
  183939. totalChars += fileNames[i].length() + 1;
  183940. HDROP hDrop = (HDROP) GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT,
  183941. sizeof (DROPFILES)
  183942. + sizeof (WCHAR) * (totalChars + 2));
  183943. if (hDrop != 0)
  183944. {
  183945. LPDROPFILES pDropFiles = (LPDROPFILES) GlobalLock (hDrop);
  183946. pDropFiles->pFiles = sizeof (DROPFILES);
  183947. pDropFiles->fWide = true;
  183948. WCHAR* fname = (WCHAR*) (((char*) pDropFiles) + sizeof (DROPFILES));
  183949. for (int i = 0; i < fileNames.size(); ++i)
  183950. {
  183951. fileNames[i].copyToUnicode (fname, 2048);
  183952. fname += fileNames[i].length() + 1;
  183953. }
  183954. *fname = 0;
  183955. GlobalUnlock (hDrop);
  183956. }
  183957. return hDrop;
  183958. }
  183959. static bool performDragDrop (FORMATETC* const format, STGMEDIUM* const medium, const DWORD whatToDo) throw()
  183960. {
  183961. JuceDropSource* const source = new JuceDropSource();
  183962. JuceDataObject* const data = new JuceDataObject (source, format, medium);
  183963. DWORD effect;
  183964. const HRESULT res = DoDragDrop (data, source, whatToDo, &effect);
  183965. data->Release();
  183966. source->Release();
  183967. return res == DRAGDROP_S_DROP;
  183968. }
  183969. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMove)
  183970. {
  183971. FORMATETC format = { CF_HDROP, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183972. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183973. medium.hGlobal = createHDrop (files);
  183974. return performDragDrop (&format, &medium, canMove ? (DROPEFFECT_COPY | DROPEFFECT_MOVE)
  183975. : DROPEFFECT_COPY);
  183976. }
  183977. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  183978. {
  183979. FORMATETC format = { CF_TEXT, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL };
  183980. STGMEDIUM medium = { TYMED_HGLOBAL, { 0 }, 0 };
  183981. const int numChars = text.length();
  183982. medium.hGlobal = GlobalAlloc (GMEM_MOVEABLE | GMEM_ZEROINIT, (numChars + 2) * sizeof (WCHAR));
  183983. char* d = (char*) GlobalLock (medium.hGlobal);
  183984. text.copyToUnicode ((WCHAR*) d, numChars + 1);
  183985. format.cfFormat = CF_UNICODETEXT;
  183986. GlobalUnlock (medium.hGlobal);
  183987. return performDragDrop (&format, &medium, DROPEFFECT_COPY | DROPEFFECT_MOVE);
  183988. }
  183989. #endif
  183990. /*** End of inlined file: juce_win32_Windowing.cpp ***/
  183991. /*** Start of inlined file: juce_win32_Fonts.cpp ***/
  183992. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  183993. // compiled on its own).
  183994. #if JUCE_INCLUDED_FILE
  183995. static int CALLBACK wfontEnum2 (ENUMLOGFONTEXW* lpelfe,
  183996. NEWTEXTMETRICEXW*,
  183997. int type,
  183998. LPARAM lParam)
  183999. {
  184000. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  184001. {
  184002. const String fontName (lpelfe->elfLogFont.lfFaceName);
  184003. ((StringArray*) lParam)->addIfNotAlreadyThere (fontName.removeCharacters (T("@")));
  184004. }
  184005. return 1;
  184006. }
  184007. static int CALLBACK wfontEnum1 (ENUMLOGFONTEXW* lpelfe,
  184008. NEWTEXTMETRICEXW*,
  184009. int type,
  184010. LPARAM lParam)
  184011. {
  184012. if (lpelfe != 0 && (type & RASTER_FONTTYPE) == 0)
  184013. {
  184014. LOGFONTW lf;
  184015. zerostruct (lf);
  184016. lf.lfWeight = FW_DONTCARE;
  184017. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184018. lf.lfQuality = DEFAULT_QUALITY;
  184019. lf.lfCharSet = DEFAULT_CHARSET;
  184020. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184021. lf.lfPitchAndFamily = FF_DONTCARE;
  184022. const String fontName (lpelfe->elfLogFont.lfFaceName);
  184023. fontName.copyToUnicode (lf.lfFaceName, LF_FACESIZE - 1);
  184024. HDC dc = CreateCompatibleDC (0);
  184025. EnumFontFamiliesEx (dc, &lf,
  184026. (FONTENUMPROCW) &wfontEnum2,
  184027. lParam, 0);
  184028. DeleteDC (dc);
  184029. }
  184030. return 1;
  184031. }
  184032. const StringArray Font::findAllTypefaceNames() throw()
  184033. {
  184034. StringArray results;
  184035. HDC dc = CreateCompatibleDC (0);
  184036. {
  184037. LOGFONTW lf;
  184038. zerostruct (lf);
  184039. lf.lfWeight = FW_DONTCARE;
  184040. lf.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184041. lf.lfQuality = DEFAULT_QUALITY;
  184042. lf.lfCharSet = DEFAULT_CHARSET;
  184043. lf.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184044. lf.lfPitchAndFamily = FF_DONTCARE;
  184045. lf.lfFaceName[0] = 0;
  184046. EnumFontFamiliesEx (dc, &lf,
  184047. (FONTENUMPROCW) &wfontEnum1,
  184048. (LPARAM) &results, 0);
  184049. }
  184050. DeleteDC (dc);
  184051. results.sort (true);
  184052. return results;
  184053. }
  184054. extern bool juce_IsRunningInWine();
  184055. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  184056. {
  184057. if (juce_IsRunningInWine())
  184058. {
  184059. // If we're running in Wine, then use fonts that might be available on Linux..
  184060. defaultSans = "Bitstream Vera Sans";
  184061. defaultSerif = "Bitstream Vera Serif";
  184062. defaultFixed = "Bitstream Vera Sans Mono";
  184063. }
  184064. else
  184065. {
  184066. defaultSans = "Verdana";
  184067. defaultSerif = "Times";
  184068. defaultFixed = "Lucida Console";
  184069. }
  184070. }
  184071. class FontDCHolder : private DeletedAtShutdown
  184072. {
  184073. public:
  184074. FontDCHolder() throw()
  184075. : dc (0), numKPs (0), size (0),
  184076. bold (false), italic (false)
  184077. {
  184078. }
  184079. ~FontDCHolder() throw()
  184080. {
  184081. if (dc != 0)
  184082. {
  184083. DeleteDC (dc);
  184084. DeleteObject (fontH);
  184085. }
  184086. clearSingletonInstance();
  184087. }
  184088. juce_DeclareSingleton_SingleThreaded_Minimal (FontDCHolder);
  184089. HDC loadFont (const String& fontName_, const bool bold_, const bool italic_, const int size_) throw()
  184090. {
  184091. if (fontName != fontName_ || bold != bold_ || italic != italic_ || size != size_)
  184092. {
  184093. fontName = fontName_;
  184094. bold = bold_;
  184095. italic = italic_;
  184096. size = size_;
  184097. if (dc != 0)
  184098. {
  184099. DeleteDC (dc);
  184100. DeleteObject (fontH);
  184101. kps.free();
  184102. }
  184103. fontH = 0;
  184104. dc = CreateCompatibleDC (0);
  184105. SetMapperFlags (dc, 0);
  184106. SetMapMode (dc, MM_TEXT);
  184107. LOGFONTW lfw;
  184108. zerostruct (lfw);
  184109. lfw.lfCharSet = DEFAULT_CHARSET;
  184110. lfw.lfClipPrecision = CLIP_DEFAULT_PRECIS;
  184111. lfw.lfOutPrecision = OUT_OUTLINE_PRECIS;
  184112. lfw.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
  184113. lfw.lfQuality = PROOF_QUALITY;
  184114. lfw.lfItalic = (BYTE) (italic ? TRUE : FALSE);
  184115. lfw.lfWeight = bold ? FW_BOLD : FW_NORMAL;
  184116. fontName.copyToUnicode (lfw.lfFaceName, LF_FACESIZE - 1);
  184117. lfw.lfHeight = size > 0 ? size : -256;
  184118. HFONT standardSizedFont = CreateFontIndirect (&lfw);
  184119. if (standardSizedFont != 0)
  184120. {
  184121. if (SelectObject (dc, standardSizedFont) != 0)
  184122. {
  184123. fontH = standardSizedFont;
  184124. if (size == 0)
  184125. {
  184126. OUTLINETEXTMETRIC otm;
  184127. if (GetOutlineTextMetrics (dc, sizeof (otm), &otm) != 0)
  184128. {
  184129. lfw.lfHeight = -(int) otm.otmEMSquare;
  184130. fontH = CreateFontIndirect (&lfw);
  184131. SelectObject (dc, fontH);
  184132. DeleteObject (standardSizedFont);
  184133. }
  184134. }
  184135. }
  184136. else
  184137. {
  184138. jassertfalse
  184139. }
  184140. }
  184141. else
  184142. {
  184143. jassertfalse
  184144. }
  184145. }
  184146. return dc;
  184147. }
  184148. KERNINGPAIR* getKerningPairs (int& numKPs_) throw()
  184149. {
  184150. if (kps == 0)
  184151. {
  184152. numKPs = GetKerningPairs (dc, 0, 0);
  184153. kps.calloc (numKPs);
  184154. GetKerningPairs (dc, numKPs, kps);
  184155. }
  184156. numKPs_ = numKPs;
  184157. return kps;
  184158. }
  184159. private:
  184160. HFONT fontH;
  184161. HDC dc;
  184162. String fontName;
  184163. HeapBlock <KERNINGPAIR> kps;
  184164. int numKPs, size;
  184165. bool bold, italic;
  184166. FontDCHolder (const FontDCHolder&);
  184167. FontDCHolder& operator= (const FontDCHolder&);
  184168. };
  184169. juce_ImplementSingleton_SingleThreaded (FontDCHolder);
  184170. class WindowsTypeface : public CustomTypeface
  184171. {
  184172. public:
  184173. WindowsTypeface (const Font& font)
  184174. {
  184175. HDC dc = FontDCHolder::getInstance()->loadFont (font.getTypefaceName(),
  184176. font.isBold(), font.isItalic(), 0);
  184177. TEXTMETRIC tm;
  184178. tm.tmAscent = tm.tmHeight = 1;
  184179. tm.tmDefaultChar = 0;
  184180. GetTextMetrics (dc, &tm);
  184181. setCharacteristics (font.getTypefaceName(),
  184182. tm.tmAscent / (float) tm.tmHeight,
  184183. font.isBold(), font.isItalic(),
  184184. tm.tmDefaultChar);
  184185. }
  184186. bool loadGlyphIfPossible (const juce_wchar character)
  184187. {
  184188. HDC dc = FontDCHolder::getInstance()->loadFont (name, isBold, isItalic, 0);
  184189. GLYPHMETRICS gm;
  184190. {
  184191. const WCHAR charToTest[] = { (WCHAR) character, 0 };
  184192. WORD index = 0;
  184193. if (GetGlyphIndices (dc, charToTest, 1, &index, GGI_MARK_NONEXISTING_GLYPHS) != GDI_ERROR
  184194. && index == 0xffff)
  184195. {
  184196. return false;
  184197. }
  184198. }
  184199. Path glyphPath;
  184200. TEXTMETRIC tm;
  184201. if (! GetTextMetrics (dc, &tm))
  184202. {
  184203. addGlyph (character, glyphPath, 0);
  184204. return true;
  184205. }
  184206. const float height = (float) tm.tmHeight;
  184207. static const MAT2 identityMatrix = { { 0, 1 }, { 0, 0 }, { 0, 0 }, { 0, 1 } };
  184208. const int bufSize = GetGlyphOutline (dc, character, GGO_NATIVE,
  184209. &gm, 0, 0, &identityMatrix);
  184210. if (bufSize > 0)
  184211. {
  184212. HeapBlock <char> data (bufSize);
  184213. GetGlyphOutline (dc, character, GGO_NATIVE, &gm,
  184214. bufSize, data, &identityMatrix);
  184215. const TTPOLYGONHEADER* pheader = (TTPOLYGONHEADER*) data;
  184216. const float scaleX = 1.0f / height;
  184217. const float scaleY = -1.0f / height;
  184218. while ((char*) pheader < data + bufSize)
  184219. {
  184220. #define remapX(v) (scaleX * (v).x.value)
  184221. #define remapY(v) (scaleY * (v).y.value)
  184222. float x = remapX (pheader->pfxStart);
  184223. float y = remapY (pheader->pfxStart);
  184224. glyphPath.startNewSubPath (x, y);
  184225. const TTPOLYCURVE* curve = (const TTPOLYCURVE*) ((const char*) pheader + sizeof (TTPOLYGONHEADER));
  184226. const char* const curveEnd = ((const char*) pheader) + pheader->cb;
  184227. while ((const char*) curve < curveEnd)
  184228. {
  184229. if (curve->wType == TT_PRIM_LINE)
  184230. {
  184231. for (int i = 0; i < curve->cpfx; ++i)
  184232. {
  184233. x = remapX (curve->apfx [i]);
  184234. y = remapY (curve->apfx [i]);
  184235. glyphPath.lineTo (x, y);
  184236. }
  184237. }
  184238. else if (curve->wType == TT_PRIM_QSPLINE)
  184239. {
  184240. for (int i = 0; i < curve->cpfx - 1; ++i)
  184241. {
  184242. const float x2 = remapX (curve->apfx [i]);
  184243. const float y2 = remapY (curve->apfx [i]);
  184244. float x3, y3;
  184245. if (i < curve->cpfx - 2)
  184246. {
  184247. x3 = 0.5f * (x2 + remapX (curve->apfx [i + 1]));
  184248. y3 = 0.5f * (y2 + remapY (curve->apfx [i + 1]));
  184249. }
  184250. else
  184251. {
  184252. x3 = remapX (curve->apfx [i + 1]);
  184253. y3 = remapY (curve->apfx [i + 1]);
  184254. }
  184255. glyphPath.quadraticTo (x2, y2, x3, y3);
  184256. x = x3;
  184257. y = y3;
  184258. }
  184259. }
  184260. curve = (const TTPOLYCURVE*) &(curve->apfx [curve->cpfx]);
  184261. }
  184262. pheader = (const TTPOLYGONHEADER*) curve;
  184263. glyphPath.closeSubPath();
  184264. }
  184265. }
  184266. addGlyph (character, glyphPath, gm.gmCellIncX / height);
  184267. int numKPs;
  184268. const KERNINGPAIR* const kps = FontDCHolder::getInstance()->getKerningPairs (numKPs);
  184269. for (int i = 0; i < numKPs; ++i)
  184270. {
  184271. if (kps[i].wFirst == character)
  184272. addKerningPair (kps[i].wFirst, kps[i].wSecond,
  184273. kps[i].iKernAmount / height);
  184274. }
  184275. return true;
  184276. }
  184277. };
  184278. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  184279. {
  184280. return new WindowsTypeface (font);
  184281. }
  184282. #endif
  184283. /*** End of inlined file: juce_win32_Fonts.cpp ***/
  184284. /*** Start of inlined file: juce_win32_FileChooser.cpp ***/
  184285. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184286. // compiled on its own).
  184287. #if JUCE_INCLUDED_FILE
  184288. static const void* defaultDirPath = 0;
  184289. static String returnedString; // need this to get non-existent pathnames from the directory chooser
  184290. static Component* currentExtraFileWin = 0;
  184291. static bool areThereAnyAlwaysOnTopWindows()
  184292. {
  184293. for (int i = Desktop::getInstance().getNumComponents(); --i >= 0;)
  184294. {
  184295. Component* c = Desktop::getInstance().getComponent (i);
  184296. if (c != 0 && c->isAlwaysOnTop() && c->isShowing())
  184297. return true;
  184298. }
  184299. return false;
  184300. }
  184301. static int CALLBACK browseCallbackProc (HWND hWnd, UINT msg, LPARAM lParam, LPARAM /*lpData*/)
  184302. {
  184303. if (msg == BFFM_INITIALIZED)
  184304. {
  184305. SendMessage (hWnd, BFFM_SETSELECTIONW, TRUE, (LPARAM) defaultDirPath);
  184306. }
  184307. else if (msg == BFFM_VALIDATEFAILEDW)
  184308. {
  184309. returnedString = (LPCWSTR) lParam;
  184310. }
  184311. else if (msg == BFFM_VALIDATEFAILEDA)
  184312. {
  184313. returnedString = (const char*) lParam;
  184314. }
  184315. return 0;
  184316. }
  184317. void juce_setWindowStyleBit (HWND h, const int styleType, const int feature, const bool bitIsSet) throw();
  184318. static UINT_PTR CALLBACK openCallback (HWND hdlg, UINT uiMsg, WPARAM /*wParam*/, LPARAM lParam)
  184319. {
  184320. if (currentExtraFileWin != 0)
  184321. {
  184322. if (uiMsg == WM_INITDIALOG)
  184323. {
  184324. HWND dialogH = GetParent (hdlg);
  184325. jassert (dialogH != 0);
  184326. if (dialogH == 0)
  184327. dialogH = hdlg;
  184328. RECT r, cr;
  184329. GetWindowRect (dialogH, &r);
  184330. GetClientRect (dialogH, &cr);
  184331. SetWindowPos (dialogH, 0,
  184332. r.left, r.top,
  184333. currentExtraFileWin->getWidth() + jmax (150, (int) (r.right - r.left)),
  184334. jmax (150, (int) (r.bottom - r.top)),
  184335. SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOZORDER);
  184336. currentExtraFileWin->setBounds (cr.right, cr.top, currentExtraFileWin->getWidth(), cr.bottom - cr.top);
  184337. currentExtraFileWin->getChildComponent(0)->setBounds (0, 0, currentExtraFileWin->getWidth(), currentExtraFileWin->getHeight());
  184338. SetParent ((HWND) currentExtraFileWin->getWindowHandle(), (HWND) dialogH);
  184339. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_CHILD, (dialogH != 0));
  184340. juce_setWindowStyleBit ((HWND)currentExtraFileWin->getWindowHandle(), GWL_STYLE, WS_POPUP, (dialogH == 0));
  184341. }
  184342. else if (uiMsg == WM_NOTIFY)
  184343. {
  184344. LPOFNOTIFY ofn = (LPOFNOTIFY) lParam;
  184345. if (ofn->hdr.code == CDN_SELCHANGE)
  184346. {
  184347. FilePreviewComponent* comp = (FilePreviewComponent*) currentExtraFileWin->getChildComponent(0);
  184348. if (comp != 0)
  184349. {
  184350. TCHAR path [MAX_PATH * 2];
  184351. path[0] = 0;
  184352. CommDlg_OpenSave_GetFilePath (GetParent (hdlg), (LPARAM) &path, MAX_PATH);
  184353. const String fn ((const WCHAR*) path);
  184354. comp->selectedFileChanged (File (fn));
  184355. }
  184356. }
  184357. }
  184358. }
  184359. return 0;
  184360. }
  184361. class FPComponentHolder : public Component
  184362. {
  184363. public:
  184364. FPComponentHolder()
  184365. {
  184366. setVisible (true);
  184367. setOpaque (true);
  184368. }
  184369. ~FPComponentHolder()
  184370. {
  184371. }
  184372. void paint (Graphics& g)
  184373. {
  184374. g.fillAll (Colours::lightgrey);
  184375. }
  184376. private:
  184377. FPComponentHolder (const FPComponentHolder&);
  184378. FPComponentHolder& operator= (const FPComponentHolder&);
  184379. };
  184380. void FileChooser::showPlatformDialog (Array<File>& results,
  184381. const String& title,
  184382. const File& currentFileOrDirectory,
  184383. const String& filter,
  184384. bool selectsDirectory,
  184385. bool /*selectsFiles*/,
  184386. bool isSaveDialogue,
  184387. bool warnAboutOverwritingExistingFiles,
  184388. bool selectMultipleFiles,
  184389. FilePreviewComponent* extraInfoComponent)
  184390. {
  184391. const int numCharsAvailable = 32768;
  184392. MemoryBlock filenameSpace ((numCharsAvailable + 1) * sizeof (WCHAR), true);
  184393. WCHAR* const fname = (WCHAR*) filenameSpace.getData();
  184394. int fnameIdx = 0;
  184395. JUCE_TRY
  184396. {
  184397. // use a modal window as the parent for this dialog box
  184398. // to block input from other app windows
  184399. const Rectangle<int> mainMon (Desktop::getInstance().getMainMonitorArea());
  184400. Component w (String::empty);
  184401. w.setBounds (mainMon.getX() + mainMon.getWidth() / 4,
  184402. mainMon.getY() + mainMon.getHeight() / 4,
  184403. 0, 0);
  184404. w.setOpaque (true);
  184405. w.setAlwaysOnTop (areThereAnyAlwaysOnTopWindows());
  184406. w.addToDesktop (0);
  184407. if (extraInfoComponent == 0)
  184408. w.enterModalState();
  184409. String initialDir;
  184410. if (currentFileOrDirectory.isDirectory())
  184411. {
  184412. initialDir = currentFileOrDirectory.getFullPathName();
  184413. }
  184414. else
  184415. {
  184416. currentFileOrDirectory.getFileName().copyToUnicode (fname, numCharsAvailable);
  184417. initialDir = currentFileOrDirectory.getParentDirectory().getFullPathName();
  184418. }
  184419. if (currentExtraFileWin->isValidComponent())
  184420. {
  184421. jassertfalse
  184422. return;
  184423. }
  184424. if (selectsDirectory)
  184425. {
  184426. LPITEMIDLIST list = 0;
  184427. filenameSpace.fillWith (0);
  184428. {
  184429. BROWSEINFO bi;
  184430. zerostruct (bi);
  184431. bi.hwndOwner = (HWND) w.getWindowHandle();
  184432. bi.pszDisplayName = fname;
  184433. bi.lpszTitle = title;
  184434. bi.lpfn = browseCallbackProc;
  184435. #ifdef BIF_USENEWUI
  184436. bi.ulFlags = BIF_USENEWUI | BIF_VALIDATE;
  184437. #else
  184438. bi.ulFlags = 0x50;
  184439. #endif
  184440. defaultDirPath = (const WCHAR*) initialDir;
  184441. list = SHBrowseForFolder (&bi);
  184442. if (! SHGetPathFromIDListW (list, fname))
  184443. {
  184444. fname[0] = 0;
  184445. returnedString = String::empty;
  184446. }
  184447. }
  184448. LPMALLOC al;
  184449. if (list != 0 && SUCCEEDED (SHGetMalloc (&al)))
  184450. al->Free (list);
  184451. defaultDirPath = 0;
  184452. if (returnedString.isNotEmpty())
  184453. {
  184454. const String stringFName (fname);
  184455. results.add (File (stringFName).getSiblingFile (returnedString));
  184456. returnedString = String::empty;
  184457. return;
  184458. }
  184459. }
  184460. else
  184461. {
  184462. DWORD flags = OFN_EXPLORER | OFN_PATHMUSTEXIST | OFN_NOCHANGEDIR | OFN_HIDEREADONLY;
  184463. if (warnAboutOverwritingExistingFiles)
  184464. flags |= OFN_OVERWRITEPROMPT;
  184465. if (selectMultipleFiles)
  184466. flags |= OFN_ALLOWMULTISELECT;
  184467. if (extraInfoComponent != 0)
  184468. {
  184469. flags |= OFN_ENABLEHOOK;
  184470. currentExtraFileWin = new FPComponentHolder();
  184471. currentExtraFileWin->addAndMakeVisible (extraInfoComponent);
  184472. currentExtraFileWin->setSize (jlimit (20, 800, extraInfoComponent->getWidth()),
  184473. extraInfoComponent->getHeight());
  184474. currentExtraFileWin->addToDesktop (0);
  184475. currentExtraFileWin->enterModalState();
  184476. }
  184477. {
  184478. WCHAR filters [1024];
  184479. zeromem (filters, sizeof (filters));
  184480. filter.copyToUnicode (filters, 1024);
  184481. filter.copyToUnicode (filters + filter.length() + 1,
  184482. 1022 - filter.length());
  184483. OPENFILENAMEW of;
  184484. zerostruct (of);
  184485. #ifdef OPENFILENAME_SIZE_VERSION_400W
  184486. of.lStructSize = OPENFILENAME_SIZE_VERSION_400W;
  184487. #else
  184488. of.lStructSize = sizeof (of);
  184489. #endif
  184490. of.hwndOwner = (HWND) w.getWindowHandle();
  184491. of.lpstrFilter = filters;
  184492. of.nFilterIndex = 1;
  184493. of.lpstrFile = fname;
  184494. of.nMaxFile = numCharsAvailable;
  184495. of.lpstrInitialDir = initialDir;
  184496. of.lpstrTitle = title;
  184497. of.Flags = flags;
  184498. if (extraInfoComponent != 0)
  184499. of.lpfnHook = &openCallback;
  184500. if (isSaveDialogue)
  184501. {
  184502. if (! GetSaveFileName (&of))
  184503. fname[0] = 0;
  184504. else
  184505. fnameIdx = of.nFileOffset;
  184506. }
  184507. else
  184508. {
  184509. if (! GetOpenFileName (&of))
  184510. fname[0] = 0;
  184511. else
  184512. fnameIdx = of.nFileOffset;
  184513. }
  184514. }
  184515. }
  184516. }
  184517. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  184518. catch (...)
  184519. {
  184520. fname[0] = 0;
  184521. }
  184522. #endif
  184523. deleteAndZero (currentExtraFileWin);
  184524. const WCHAR* const files = fname;
  184525. if (selectMultipleFiles && fnameIdx > 0 && files [fnameIdx - 1] == 0)
  184526. {
  184527. const WCHAR* filename = files + fnameIdx;
  184528. while (*filename != 0)
  184529. {
  184530. const String filepath (String (files) + T("\\") + String (filename));
  184531. results.add (File (filepath));
  184532. filename += CharacterFunctions::length (filename) + 1;
  184533. }
  184534. }
  184535. else if (files[0] != 0)
  184536. {
  184537. results.add (File (files));
  184538. }
  184539. }
  184540. #endif
  184541. /*** End of inlined file: juce_win32_FileChooser.cpp ***/
  184542. /*** Start of inlined file: juce_win32_Misc.cpp ***/
  184543. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184544. // compiled on its own).
  184545. #if JUCE_INCLUDED_FILE
  184546. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  184547. {
  184548. if (OpenClipboard (0) != 0)
  184549. {
  184550. if (EmptyClipboard() != 0)
  184551. {
  184552. const int len = text.length();
  184553. if (len > 0)
  184554. {
  184555. HGLOBAL bufH = GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE,
  184556. (len + 1) * sizeof (wchar_t));
  184557. if (bufH != 0)
  184558. {
  184559. WCHAR* const data = (WCHAR*) GlobalLock (bufH);
  184560. text.copyToUnicode (data, len);
  184561. GlobalUnlock (bufH);
  184562. SetClipboardData (CF_UNICODETEXT, bufH);
  184563. }
  184564. }
  184565. }
  184566. CloseClipboard();
  184567. }
  184568. }
  184569. const String SystemClipboard::getTextFromClipboard() throw()
  184570. {
  184571. String result;
  184572. if (OpenClipboard (0) != 0)
  184573. {
  184574. HANDLE bufH = GetClipboardData (CF_UNICODETEXT);
  184575. if (bufH != 0)
  184576. {
  184577. const wchar_t* const data = (const wchar_t*) GlobalLock (bufH);
  184578. if (data != 0)
  184579. {
  184580. result = String (data, (int) (GlobalSize (bufH) / sizeof (tchar)));
  184581. GlobalUnlock (bufH);
  184582. }
  184583. }
  184584. CloseClipboard();
  184585. }
  184586. return result;
  184587. }
  184588. #endif
  184589. /*** End of inlined file: juce_win32_Misc.cpp ***/
  184590. /*** Start of inlined file: juce_win32_ActiveXComponent.cpp ***/
  184591. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  184592. // compiled on its own).
  184593. #if JUCE_INCLUDED_FILE
  184594. class JuceIStorage : public IStorage
  184595. {
  184596. int refCount;
  184597. public:
  184598. JuceIStorage() : refCount (1) {}
  184599. virtual ~JuceIStorage()
  184600. {
  184601. jassert (refCount == 0);
  184602. }
  184603. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184604. {
  184605. if (id == IID_IUnknown || id == IID_IStorage)
  184606. {
  184607. AddRef();
  184608. *result = this;
  184609. return S_OK;
  184610. }
  184611. *result = 0;
  184612. return E_NOINTERFACE;
  184613. }
  184614. ULONG __stdcall AddRef() { return ++refCount; }
  184615. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184616. HRESULT __stdcall CreateStream (const WCHAR*, DWORD, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184617. HRESULT __stdcall OpenStream (const WCHAR*, void*, DWORD, DWORD, IStream**) { return E_NOTIMPL; }
  184618. HRESULT __stdcall CreateStorage (const WCHAR*, DWORD, DWORD, DWORD, IStorage**) { return E_NOTIMPL; }
  184619. HRESULT __stdcall OpenStorage (const WCHAR*, IStorage*, DWORD, SNB, DWORD, IStorage**) { return E_NOTIMPL; }
  184620. HRESULT __stdcall CopyTo (DWORD, IID const*, SNB, IStorage*) { return E_NOTIMPL; }
  184621. HRESULT __stdcall MoveElementTo (const OLECHAR*,IStorage*, const OLECHAR*, DWORD) { return E_NOTIMPL; }
  184622. HRESULT __stdcall Commit (DWORD) { return E_NOTIMPL; }
  184623. HRESULT __stdcall Revert() { return E_NOTIMPL; }
  184624. HRESULT __stdcall EnumElements (DWORD, void*, DWORD, IEnumSTATSTG**) { return E_NOTIMPL; }
  184625. HRESULT __stdcall DestroyElement (const OLECHAR*) { return E_NOTIMPL; }
  184626. HRESULT __stdcall RenameElement (const WCHAR*, const WCHAR*) { return E_NOTIMPL; }
  184627. HRESULT __stdcall SetElementTimes (const WCHAR*, FILETIME const*, FILETIME const*, FILETIME const*) { return E_NOTIMPL; }
  184628. HRESULT __stdcall SetClass (REFCLSID) { return S_OK; }
  184629. HRESULT __stdcall SetStateBits (DWORD, DWORD) { return E_NOTIMPL; }
  184630. HRESULT __stdcall Stat (STATSTG*, DWORD) { return E_NOTIMPL; }
  184631. juce_UseDebuggingNewOperator
  184632. };
  184633. class JuceOleInPlaceFrame : public IOleInPlaceFrame
  184634. {
  184635. int refCount;
  184636. HWND window;
  184637. public:
  184638. JuceOleInPlaceFrame (HWND window_)
  184639. : refCount (1),
  184640. window (window_)
  184641. {
  184642. }
  184643. virtual ~JuceOleInPlaceFrame()
  184644. {
  184645. jassert (refCount == 0);
  184646. }
  184647. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184648. {
  184649. if (id == IID_IUnknown || id == IID_IOleInPlaceFrame)
  184650. {
  184651. AddRef();
  184652. *result = this;
  184653. return S_OK;
  184654. }
  184655. *result = 0;
  184656. return E_NOINTERFACE;
  184657. }
  184658. ULONG __stdcall AddRef() { return ++refCount; }
  184659. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184660. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184661. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184662. HRESULT __stdcall GetBorder (LPRECT) { return E_NOTIMPL; }
  184663. HRESULT __stdcall RequestBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184664. HRESULT __stdcall SetBorderSpace (LPCBORDERWIDTHS) { return E_NOTIMPL; }
  184665. HRESULT __stdcall SetActiveObject (IOleInPlaceActiveObject*, LPCOLESTR) { return S_OK; }
  184666. HRESULT __stdcall InsertMenus (HMENU, LPOLEMENUGROUPWIDTHS) { return E_NOTIMPL; }
  184667. HRESULT __stdcall SetMenu (HMENU, HOLEMENU, HWND) { return S_OK; }
  184668. HRESULT __stdcall RemoveMenus (HMENU) { return E_NOTIMPL; }
  184669. HRESULT __stdcall SetStatusText (LPCOLESTR) { return S_OK; }
  184670. HRESULT __stdcall EnableModeless (BOOL) { return S_OK; }
  184671. HRESULT __stdcall TranslateAccelerator(LPMSG, WORD) { return E_NOTIMPL; }
  184672. juce_UseDebuggingNewOperator
  184673. };
  184674. class JuceIOleInPlaceSite : public IOleInPlaceSite
  184675. {
  184676. int refCount;
  184677. HWND window;
  184678. JuceOleInPlaceFrame* frame;
  184679. public:
  184680. JuceIOleInPlaceSite (HWND window_)
  184681. : refCount (1),
  184682. window (window_)
  184683. {
  184684. frame = new JuceOleInPlaceFrame (window);
  184685. }
  184686. virtual ~JuceIOleInPlaceSite()
  184687. {
  184688. jassert (refCount == 0);
  184689. frame->Release();
  184690. }
  184691. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184692. {
  184693. if (id == IID_IUnknown || id == IID_IOleInPlaceSite)
  184694. {
  184695. AddRef();
  184696. *result = this;
  184697. return S_OK;
  184698. }
  184699. *result = 0;
  184700. return E_NOINTERFACE;
  184701. }
  184702. ULONG __stdcall AddRef() { return ++refCount; }
  184703. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184704. HRESULT __stdcall GetWindow (HWND* lphwnd) { *lphwnd = window; return S_OK; }
  184705. HRESULT __stdcall ContextSensitiveHelp (BOOL) { return E_NOTIMPL; }
  184706. HRESULT __stdcall CanInPlaceActivate() { return S_OK; }
  184707. HRESULT __stdcall OnInPlaceActivate() { return S_OK; }
  184708. HRESULT __stdcall OnUIActivate() { return S_OK; }
  184709. HRESULT __stdcall GetWindowContext (LPOLEINPLACEFRAME* lplpFrame, LPOLEINPLACEUIWINDOW* lplpDoc, LPRECT, LPRECT, LPOLEINPLACEFRAMEINFO lpFrameInfo)
  184710. {
  184711. // frame->AddRef(); // MS docs are unclear about whether this is needed, but it seems to lead to a memory leak..
  184712. *lplpFrame = frame;
  184713. *lplpDoc = 0;
  184714. lpFrameInfo->fMDIApp = FALSE;
  184715. lpFrameInfo->hwndFrame = window;
  184716. lpFrameInfo->haccel = 0;
  184717. lpFrameInfo->cAccelEntries = 0;
  184718. return S_OK;
  184719. }
  184720. HRESULT __stdcall Scroll (SIZE) { return E_NOTIMPL; }
  184721. HRESULT __stdcall OnUIDeactivate (BOOL) { return S_OK; }
  184722. HRESULT __stdcall OnInPlaceDeactivate() { return S_OK; }
  184723. HRESULT __stdcall DiscardUndoState() { return E_NOTIMPL; }
  184724. HRESULT __stdcall DeactivateAndUndo() { return E_NOTIMPL; }
  184725. HRESULT __stdcall OnPosRectChange (LPCRECT) { return S_OK; }
  184726. juce_UseDebuggingNewOperator
  184727. };
  184728. class JuceIOleClientSite : public IOleClientSite
  184729. {
  184730. int refCount;
  184731. JuceIOleInPlaceSite* inplaceSite;
  184732. public:
  184733. JuceIOleClientSite (HWND window)
  184734. : refCount (1)
  184735. {
  184736. inplaceSite = new JuceIOleInPlaceSite (window);
  184737. }
  184738. virtual ~JuceIOleClientSite()
  184739. {
  184740. jassert (refCount == 0);
  184741. inplaceSite->Release();
  184742. }
  184743. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  184744. {
  184745. if (id == IID_IUnknown || id == IID_IOleClientSite)
  184746. {
  184747. AddRef();
  184748. *result = this;
  184749. return S_OK;
  184750. }
  184751. else if (id == IID_IOleInPlaceSite)
  184752. {
  184753. inplaceSite->AddRef();
  184754. *result = inplaceSite;
  184755. return S_OK;
  184756. }
  184757. *result = 0;
  184758. return E_NOINTERFACE;
  184759. }
  184760. ULONG __stdcall AddRef() { return ++refCount; }
  184761. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  184762. HRESULT __stdcall SaveObject() { return E_NOTIMPL; }
  184763. HRESULT __stdcall GetMoniker (DWORD, DWORD, IMoniker**) { return E_NOTIMPL; }
  184764. HRESULT __stdcall GetContainer (LPOLECONTAINER* ppContainer) { *ppContainer = 0; return E_NOINTERFACE; }
  184765. HRESULT __stdcall ShowObject() { return S_OK; }
  184766. HRESULT __stdcall OnShowWindow (BOOL) { return E_NOTIMPL; }
  184767. HRESULT __stdcall RequestNewObjectLayout() { return E_NOTIMPL; }
  184768. juce_UseDebuggingNewOperator
  184769. };
  184770. class ActiveXControlData : public ComponentMovementWatcher
  184771. {
  184772. ActiveXControlComponent* const owner;
  184773. bool wasShowing;
  184774. public:
  184775. HWND controlHWND;
  184776. IStorage* storage;
  184777. IOleClientSite* clientSite;
  184778. IOleObject* control;
  184779. ActiveXControlData (HWND hwnd,
  184780. ActiveXControlComponent* const owner_)
  184781. : ComponentMovementWatcher (owner_),
  184782. owner (owner_),
  184783. wasShowing (owner_ != 0 && owner_->isShowing()),
  184784. controlHWND (0),
  184785. storage (new JuceIStorage()),
  184786. clientSite (new JuceIOleClientSite (hwnd)),
  184787. control (0)
  184788. {
  184789. }
  184790. ~ActiveXControlData()
  184791. {
  184792. if (control != 0)
  184793. {
  184794. control->Close (OLECLOSE_NOSAVE);
  184795. control->Release();
  184796. }
  184797. clientSite->Release();
  184798. storage->Release();
  184799. }
  184800. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  184801. {
  184802. Component* const topComp = owner->getTopLevelComponent();
  184803. if (topComp->getPeer() != 0)
  184804. {
  184805. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  184806. owner->setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), owner->getWidth(), owner->getHeight()));
  184807. }
  184808. }
  184809. void componentPeerChanged()
  184810. {
  184811. const bool isShowingNow = owner->isShowing();
  184812. if (wasShowing != isShowingNow)
  184813. {
  184814. wasShowing = isShowingNow;
  184815. owner->setControlVisible (isShowingNow);
  184816. }
  184817. componentMovedOrResized (true, true);
  184818. }
  184819. void componentVisibilityChanged (Component&)
  184820. {
  184821. componentPeerChanged();
  184822. }
  184823. static bool doesWindowMatch (const ActiveXControlComponent* const ax, HWND hwnd)
  184824. {
  184825. return ((ActiveXControlData*) ax->control) != 0
  184826. && ((ActiveXControlData*) ax->control)->controlHWND == hwnd;
  184827. }
  184828. };
  184829. static VoidArray activeXComps;
  184830. static HWND getHWND (const ActiveXControlComponent* const component)
  184831. {
  184832. HWND hwnd = 0;
  184833. const IID iid = IID_IOleWindow;
  184834. IOleWindow* const window = (IOleWindow*) component->queryInterface (&iid);
  184835. if (window != 0)
  184836. {
  184837. window->GetWindow (&hwnd);
  184838. window->Release();
  184839. }
  184840. return hwnd;
  184841. }
  184842. static void offerActiveXMouseEventToPeer (ComponentPeer* const peer, HWND hwnd, UINT message, LPARAM lParam)
  184843. {
  184844. RECT activeXRect, peerRect;
  184845. GetWindowRect (hwnd, &activeXRect);
  184846. GetWindowRect ((HWND) peer->getNativeHandle(), &peerRect);
  184847. const Point<int> mousePos (GET_X_LPARAM (lParam) + activeXRect.left - peerRect.left,
  184848. GET_Y_LPARAM (lParam) + activeXRect.top - peerRect.top);
  184849. const int64 mouseEventTime = getMouseEventTime();
  184850. const int oldModifiers = currentModifiers;
  184851. ModifierKeys::getCurrentModifiersRealtime(); // to update the mouse button flags
  184852. switch (message)
  184853. {
  184854. case WM_MOUSEMOVE:
  184855. if (ModifierKeys (currentModifiers).isAnyMouseButtonDown())
  184856. peer->handleMouseDrag (mousePos, mouseEventTime);
  184857. else
  184858. peer->handleMouseMove (mousePos, mouseEventTime);
  184859. break;
  184860. case WM_LBUTTONDOWN:
  184861. case WM_MBUTTONDOWN:
  184862. case WM_RBUTTONDOWN:
  184863. peer->handleMouseDown (mousePos, mouseEventTime);
  184864. break;
  184865. case WM_LBUTTONUP:
  184866. case WM_MBUTTONUP:
  184867. case WM_RBUTTONUP:
  184868. peer->handleMouseUp (oldModifiers, mousePos, mouseEventTime);
  184869. break;
  184870. default:
  184871. break;
  184872. }
  184873. }
  184874. // intercepts events going to an activeX control, so we can sneakily use the mouse events
  184875. static LRESULT CALLBACK activeXHookWndProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  184876. {
  184877. for (int i = activeXComps.size(); --i >= 0;)
  184878. {
  184879. const ActiveXControlComponent* const ax = (const ActiveXControlComponent*) activeXComps.getUnchecked(i);
  184880. if (ActiveXControlData::doesWindowMatch (ax, hwnd))
  184881. {
  184882. switch (message)
  184883. {
  184884. case WM_MOUSEMOVE:
  184885. case WM_LBUTTONDOWN:
  184886. case WM_MBUTTONDOWN:
  184887. case WM_RBUTTONDOWN:
  184888. case WM_LBUTTONUP:
  184889. case WM_MBUTTONUP:
  184890. case WM_RBUTTONUP:
  184891. case WM_LBUTTONDBLCLK:
  184892. case WM_MBUTTONDBLCLK:
  184893. case WM_RBUTTONDBLCLK:
  184894. if (ax->isShowing())
  184895. {
  184896. ComponentPeer* const peer = ax->getPeer();
  184897. if (peer != 0)
  184898. {
  184899. offerActiveXMouseEventToPeer (peer, hwnd, message, lParam);
  184900. if (! ax->areMouseEventsAllowed())
  184901. return 0;
  184902. }
  184903. }
  184904. break;
  184905. default:
  184906. break;
  184907. }
  184908. return CallWindowProc ((WNDPROC) (ax->originalWndProc), hwnd, message, wParam, lParam);
  184909. }
  184910. }
  184911. return DefWindowProc (hwnd, message, wParam, lParam);
  184912. }
  184913. ActiveXControlComponent::ActiveXControlComponent()
  184914. : originalWndProc (0),
  184915. control (0),
  184916. mouseEventsAllowed (true)
  184917. {
  184918. activeXComps.add (this);
  184919. }
  184920. ActiveXControlComponent::~ActiveXControlComponent()
  184921. {
  184922. deleteControl();
  184923. activeXComps.removeValue (this);
  184924. }
  184925. void ActiveXControlComponent::paint (Graphics& g)
  184926. {
  184927. if (control == 0)
  184928. g.fillAll (Colours::lightgrey);
  184929. }
  184930. bool ActiveXControlComponent::createControl (const void* controlIID)
  184931. {
  184932. deleteControl();
  184933. ComponentPeer* const peer = getPeer();
  184934. // the component must have already been added to a real window when you call this!
  184935. jassert (dynamic_cast <Win32ComponentPeer*> (peer) != 0);
  184936. if (dynamic_cast <Win32ComponentPeer*> (peer) != 0)
  184937. {
  184938. const Point<int> pos (relativePositionToOtherComponent (getTopLevelComponent(), Point<int>()));
  184939. HWND hwnd = (HWND) peer->getNativeHandle();
  184940. ScopedPointer <ActiveXControlData> info (new ActiveXControlData (hwnd, this));
  184941. HRESULT hr;
  184942. if ((hr = OleCreate (*(const IID*) controlIID, IID_IOleObject, 1 /*OLERENDER_DRAW*/, 0,
  184943. info->clientSite, info->storage,
  184944. (void**) &(info->control))) == S_OK)
  184945. {
  184946. info->control->SetHostNames (L"Juce", 0);
  184947. if (OleSetContainedObject (info->control, TRUE) == S_OK)
  184948. {
  184949. RECT rect;
  184950. rect.left = pos.getX();
  184951. rect.top = pos.getY();
  184952. rect.right = pos.getX() + getWidth();
  184953. rect.bottom = pos.getY() + getHeight();
  184954. if (info->control->DoVerb (OLEIVERB_SHOW, 0, info->clientSite, 0, hwnd, &rect) == S_OK)
  184955. {
  184956. control = info.release();
  184957. setControlBounds (Rectangle<int> (pos.getX(), pos.getY(), getWidth(), getHeight()));
  184958. ((ActiveXControlData*) control)->controlHWND = getHWND (this);
  184959. if (((ActiveXControlData*) control)->controlHWND != 0)
  184960. {
  184961. originalWndProc = (void*) (pointer_sized_int) GetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC);
  184962. SetWindowLongPtr ((HWND) ((ActiveXControlData*) control)->controlHWND, GWLP_WNDPROC, (LONG_PTR) activeXHookWndProc);
  184963. }
  184964. return true;
  184965. }
  184966. }
  184967. }
  184968. }
  184969. return false;
  184970. }
  184971. void ActiveXControlComponent::deleteControl()
  184972. {
  184973. ActiveXControlData* const info = (ActiveXControlData*) control;
  184974. if (info != 0)
  184975. {
  184976. delete info;
  184977. control = 0;
  184978. originalWndProc = 0;
  184979. }
  184980. }
  184981. void* ActiveXControlComponent::queryInterface (const void* iid) const
  184982. {
  184983. ActiveXControlData* const info = (ActiveXControlData*) control;
  184984. void* result = 0;
  184985. if (info != 0 && info->control != 0
  184986. && info->control->QueryInterface (*(const IID*) iid, &result) == S_OK)
  184987. return result;
  184988. return 0;
  184989. }
  184990. void ActiveXControlComponent::setControlBounds (const Rectangle<int>& newBounds) const
  184991. {
  184992. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184993. if (hwnd != 0)
  184994. MoveWindow (hwnd, newBounds.getX(), newBounds.getY(), newBounds.getWidth(), newBounds.getHeight(), TRUE);
  184995. }
  184996. void ActiveXControlComponent::setControlVisible (const bool shouldBeVisible) const
  184997. {
  184998. HWND hwnd = ((ActiveXControlData*) control)->controlHWND;
  184999. if (hwnd != 0)
  185000. ShowWindow (hwnd, shouldBeVisible ? SW_SHOWNA : SW_HIDE);
  185001. }
  185002. void ActiveXControlComponent::setMouseEventsAllowed (const bool eventsCanReachControl)
  185003. {
  185004. mouseEventsAllowed = eventsCanReachControl;
  185005. }
  185006. #endif
  185007. /*** End of inlined file: juce_win32_ActiveXComponent.cpp ***/
  185008. /*** Start of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  185009. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185010. // compiled on its own).
  185011. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  185012. using namespace QTOLibrary;
  185013. using namespace QTOControlLib;
  185014. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle);
  185015. static bool isQTAvailable = false;
  185016. struct QTMovieCompInternal
  185017. {
  185018. QTMovieCompInternal()
  185019. : dataHandle (0)
  185020. {
  185021. }
  185022. ~QTMovieCompInternal()
  185023. {
  185024. clearHandle();
  185025. }
  185026. IQTControlPtr qtControlInternal;
  185027. IQTMoviePtr qtMovieInternal;
  185028. Handle dataHandle;
  185029. void clearHandle()
  185030. {
  185031. if (dataHandle != 0)
  185032. {
  185033. DisposeHandle (dataHandle);
  185034. dataHandle = 0;
  185035. }
  185036. }
  185037. };
  185038. #define qtControl (((QTMovieCompInternal*) internal)->qtControlInternal)
  185039. #define qtMovie (((QTMovieCompInternal*) internal)->qtMovieInternal)
  185040. QuickTimeMovieComponent::QuickTimeMovieComponent()
  185041. : movieLoaded (false),
  185042. controllerVisible (true)
  185043. {
  185044. internal = new QTMovieCompInternal();
  185045. setMouseEventsAllowed (false);
  185046. }
  185047. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  185048. {
  185049. closeMovie();
  185050. qtControl = 0;
  185051. deleteControl();
  185052. delete internal;
  185053. internal = 0;
  185054. }
  185055. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  185056. {
  185057. if (! isQTAvailable)
  185058. {
  185059. isQTAvailable = (InitializeQTML (0) == noErr)
  185060. && (EnterMovies() == noErr);
  185061. }
  185062. return isQTAvailable;
  185063. }
  185064. void QuickTimeMovieComponent::createControlIfNeeded()
  185065. {
  185066. if (isShowing() && ! isControlCreated())
  185067. {
  185068. const IID qtIID = __uuidof (QTControl);
  185069. if (createControl (&qtIID))
  185070. {
  185071. const IID qtInterfaceIID = __uuidof (IQTControl);
  185072. qtControl = (IQTControl*) queryInterface (&qtInterfaceIID);
  185073. if (qtControl != 0)
  185074. {
  185075. qtControl->Release(); // it has one ref too many at this point
  185076. qtControl->QuickTimeInitialize();
  185077. qtControl->PutSizing (qtMovieFitsControl);
  185078. if (movieFile != File::nonexistent)
  185079. loadMovie (movieFile, controllerVisible);
  185080. }
  185081. }
  185082. }
  185083. }
  185084. bool QuickTimeMovieComponent::isControlCreated() const
  185085. {
  185086. return isControlOpen();
  185087. }
  185088. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  185089. const bool isControllerVisible)
  185090. {
  185091. movieFile = File::nonexistent;
  185092. movieLoaded = false;
  185093. qtMovie = 0;
  185094. controllerVisible = isControllerVisible;
  185095. createControlIfNeeded();
  185096. if (isControlCreated())
  185097. {
  185098. if (qtControl != 0)
  185099. {
  185100. qtControl->Put_MovieHandle (0);
  185101. ((QTMovieCompInternal*) internal)->clearHandle();
  185102. Movie movie;
  185103. if (juce_OpenQuickTimeMovieFromStream (movieStream, movie, ((QTMovieCompInternal*) internal)->dataHandle))
  185104. {
  185105. qtControl->Put_MovieHandle ((long) (pointer_sized_int) movie);
  185106. qtMovie = qtControl->GetMovie();
  185107. if (qtMovie != 0)
  185108. qtMovie->PutMovieControllerType (isControllerVisible ? qtMovieControllerTypeStandard
  185109. : qtMovieControllerTypeNone);
  185110. }
  185111. if (movie == 0)
  185112. ((QTMovieCompInternal*) internal)->clearHandle();
  185113. }
  185114. movieLoaded = (qtMovie != 0);
  185115. }
  185116. else
  185117. {
  185118. // You're trying to open a movie when the control hasn't yet been created, probably because
  185119. // you've not yet added this component to a Window and made the whole component hierarchy visible.
  185120. jassertfalse
  185121. }
  185122. delete movieStream;
  185123. return movieLoaded;
  185124. }
  185125. void QuickTimeMovieComponent::closeMovie()
  185126. {
  185127. stop();
  185128. movieFile = File::nonexistent;
  185129. movieLoaded = false;
  185130. qtMovie = 0;
  185131. if (qtControl != 0)
  185132. qtControl->Put_MovieHandle (0);
  185133. ((QTMovieCompInternal*) internal)->clearHandle();
  185134. }
  185135. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  185136. {
  185137. return movieFile;
  185138. }
  185139. bool QuickTimeMovieComponent::isMovieOpen() const
  185140. {
  185141. return movieLoaded;
  185142. }
  185143. double QuickTimeMovieComponent::getMovieDuration() const
  185144. {
  185145. if (qtMovie != 0)
  185146. return qtMovie->GetDuration() / (double) qtMovie->GetTimeScale();
  185147. return 0.0;
  185148. }
  185149. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  185150. {
  185151. if (qtMovie != 0)
  185152. {
  185153. struct QTRECT r = qtMovie->GetNaturalRect();
  185154. width = r.right - r.left;
  185155. height = r.bottom - r.top;
  185156. }
  185157. else
  185158. {
  185159. width = height = 0;
  185160. }
  185161. }
  185162. void QuickTimeMovieComponent::play()
  185163. {
  185164. if (qtMovie != 0)
  185165. qtMovie->Play();
  185166. }
  185167. void QuickTimeMovieComponent::stop()
  185168. {
  185169. if (qtMovie != 0)
  185170. qtMovie->Stop();
  185171. }
  185172. bool QuickTimeMovieComponent::isPlaying() const
  185173. {
  185174. return qtMovie != 0 && qtMovie->GetRate() != 0.0f;
  185175. }
  185176. void QuickTimeMovieComponent::setPosition (const double seconds)
  185177. {
  185178. if (qtMovie != 0)
  185179. qtMovie->PutTime ((long) (seconds * qtMovie->GetTimeScale()));
  185180. }
  185181. double QuickTimeMovieComponent::getPosition() const
  185182. {
  185183. if (qtMovie != 0)
  185184. return qtMovie->GetTime() / (double) qtMovie->GetTimeScale();
  185185. return 0.0;
  185186. }
  185187. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  185188. {
  185189. if (qtMovie != 0)
  185190. qtMovie->PutRate (newSpeed);
  185191. }
  185192. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  185193. {
  185194. if (qtMovie != 0)
  185195. {
  185196. qtMovie->PutAudioVolume (newVolume);
  185197. qtMovie->PutAudioMute (newVolume <= 0);
  185198. }
  185199. }
  185200. float QuickTimeMovieComponent::getMovieVolume() const
  185201. {
  185202. if (qtMovie != 0)
  185203. return qtMovie->GetAudioVolume();
  185204. return 0.0f;
  185205. }
  185206. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  185207. {
  185208. if (qtMovie != 0)
  185209. qtMovie->PutLoop (shouldLoop);
  185210. }
  185211. bool QuickTimeMovieComponent::isLooping() const
  185212. {
  185213. return qtMovie != 0 && qtMovie->GetLoop();
  185214. }
  185215. bool QuickTimeMovieComponent::isControllerVisible() const
  185216. {
  185217. return controllerVisible;
  185218. }
  185219. void QuickTimeMovieComponent::parentHierarchyChanged()
  185220. {
  185221. createControlIfNeeded();
  185222. QTCompBaseClass::parentHierarchyChanged();
  185223. }
  185224. void QuickTimeMovieComponent::visibilityChanged()
  185225. {
  185226. createControlIfNeeded();
  185227. QTCompBaseClass::visibilityChanged();
  185228. }
  185229. void QuickTimeMovieComponent::paint (Graphics& g)
  185230. {
  185231. if (! isControlCreated())
  185232. g.fillAll (Colours::black);
  185233. }
  185234. static Handle createHandleDataRef (Handle dataHandle, const char* fileName)
  185235. {
  185236. Handle dataRef = 0;
  185237. OSStatus err = PtrToHand (&dataHandle, &dataRef, sizeof (Handle));
  185238. if (err == noErr)
  185239. {
  185240. Str255 suffix;
  185241. CharacterFunctions::copy ((char*) suffix, fileName, 128);
  185242. StringPtr name = suffix;
  185243. err = PtrAndHand (name, dataRef, name[0] + 1);
  185244. if (err == noErr)
  185245. {
  185246. long atoms[3];
  185247. atoms[0] = EndianU32_NtoB (3 * sizeof (long));
  185248. atoms[1] = EndianU32_NtoB (kDataRefExtensionMacOSFileType);
  185249. atoms[2] = EndianU32_NtoB (MovieFileType);
  185250. err = PtrAndHand (atoms, dataRef, 3 * sizeof (long));
  185251. if (err == noErr)
  185252. return dataRef;
  185253. }
  185254. DisposeHandle (dataRef);
  185255. }
  185256. return 0;
  185257. }
  185258. static CFStringRef juceStringToCFString (const String& s)
  185259. {
  185260. const int len = s.length();
  185261. const juce_wchar* const t = (const juce_wchar*) s;
  185262. HeapBlock <UniChar> temp (len + 2);
  185263. for (int i = 0; i <= len; ++i)
  185264. temp[i] = t[i];
  185265. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  185266. }
  185267. static bool openMovie (QTNewMoviePropertyElement* props, int prop, Movie& movie)
  185268. {
  185269. Boolean trueBool = true;
  185270. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  185271. props[prop].propID = kQTMovieInstantiationPropertyID_DontResolveDataRefs;
  185272. props[prop].propValueSize = sizeof (trueBool);
  185273. props[prop].propValueAddress = &trueBool;
  185274. ++prop;
  185275. props[prop].propClass = kQTPropertyClass_MovieInstantiation;
  185276. props[prop].propID = kQTMovieInstantiationPropertyID_AsyncOK;
  185277. props[prop].propValueSize = sizeof (trueBool);
  185278. props[prop].propValueAddress = &trueBool;
  185279. ++prop;
  185280. Boolean isActive = true;
  185281. props[prop].propClass = kQTPropertyClass_NewMovieProperty;
  185282. props[prop].propID = kQTNewMoviePropertyID_Active;
  185283. props[prop].propValueSize = sizeof (isActive);
  185284. props[prop].propValueAddress = &isActive;
  185285. ++prop;
  185286. MacSetPort (0);
  185287. jassert (prop <= 5);
  185288. OSStatus err = NewMovieFromProperties (prop, props, 0, 0, &movie);
  185289. return err == noErr;
  185290. }
  185291. bool juce_OpenQuickTimeMovieFromStream (InputStream* input, Movie& movie, Handle& dataHandle)
  185292. {
  185293. if (input == 0)
  185294. return false;
  185295. dataHandle = 0;
  185296. bool ok = false;
  185297. QTNewMoviePropertyElement props[5];
  185298. zeromem (props, sizeof (props));
  185299. int prop = 0;
  185300. DataReferenceRecord dr;
  185301. props[prop].propClass = kQTPropertyClass_DataLocation;
  185302. props[prop].propID = kQTDataLocationPropertyID_DataReference;
  185303. props[prop].propValueSize = sizeof (dr);
  185304. props[prop].propValueAddress = (void*) &dr;
  185305. ++prop;
  185306. FileInputStream* const fin = dynamic_cast <FileInputStream*> (input);
  185307. if (fin != 0)
  185308. {
  185309. CFStringRef filePath = juceStringToCFString (fin->getFile().getFullPathName());
  185310. QTNewDataReferenceFromFullPathCFString (filePath, (QTPathStyle) kQTNativeDefaultPathStyle, 0,
  185311. &dr.dataRef, &dr.dataRefType);
  185312. ok = openMovie (props, prop, movie);
  185313. DisposeHandle (dr.dataRef);
  185314. CFRelease (filePath);
  185315. }
  185316. else
  185317. {
  185318. // sanity-check because this currently needs to load the whole stream into memory..
  185319. jassert (input->getTotalLength() < 50 * 1024 * 1024);
  185320. dataHandle = NewHandle ((Size) input->getTotalLength());
  185321. HLock (dataHandle);
  185322. // read the entire stream into memory - this is a pain, but can't get it to work
  185323. // properly using a custom callback to supply the data.
  185324. input->read (*dataHandle, (int) input->getTotalLength());
  185325. HUnlock (dataHandle);
  185326. // different types to get QT to try. (We should really be a bit smarter here by
  185327. // working out in advance which one the stream contains, rather than just trying
  185328. // each one)
  185329. const char* const suffixesToTry[] = { "\04.mov", "\04.mp3",
  185330. "\04.avi", "\04.m4a" };
  185331. for (int i = 0; i < numElementsInArray (suffixesToTry) && ! ok; ++i)
  185332. {
  185333. dr.dataRef = createHandleDataRef (dataHandle, suffixesToTry [i]);
  185334. dr.dataRefType = HandleDataHandlerSubType;
  185335. ok = openMovie (props, prop, movie);
  185336. DisposeHandle (dr.dataRef);
  185337. }
  185338. }
  185339. return ok;
  185340. }
  185341. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  185342. const bool isControllerVisible)
  185343. {
  185344. const bool ok = loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible);
  185345. movieFile = movieFile_;
  185346. return ok;
  185347. }
  185348. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  185349. const bool isControllerVisible)
  185350. {
  185351. return loadMovie ((InputStream*) movieURL.createInputStream (false), isControllerVisible);
  185352. }
  185353. void QuickTimeMovieComponent::goToStart()
  185354. {
  185355. setPosition (0.0);
  185356. }
  185357. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  185358. const RectanglePlacement& placement)
  185359. {
  185360. int normalWidth, normalHeight;
  185361. getMovieNormalSize (normalWidth, normalHeight);
  185362. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  185363. {
  185364. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  185365. placement.applyTo (x, y, w, h,
  185366. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  185367. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  185368. if (w > 0 && h > 0)
  185369. {
  185370. setBounds (roundToInt (x), roundToInt (y),
  185371. roundToInt (w), roundToInt (h));
  185372. }
  185373. }
  185374. else
  185375. {
  185376. setBounds (spaceToFitWithin);
  185377. }
  185378. }
  185379. #endif
  185380. /*** End of inlined file: juce_win32_QuickTimeMovieComponent.cpp ***/
  185381. /*** Start of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185382. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185383. // compiled on its own).
  185384. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  185385. class WebBrowserComponentInternal : public ActiveXControlComponent
  185386. {
  185387. public:
  185388. WebBrowserComponentInternal()
  185389. : browser (0),
  185390. connectionPoint (0),
  185391. adviseCookie (0)
  185392. {
  185393. }
  185394. ~WebBrowserComponentInternal()
  185395. {
  185396. if (connectionPoint != 0)
  185397. connectionPoint->Unadvise (adviseCookie);
  185398. if (browser != 0)
  185399. browser->Release();
  185400. }
  185401. void createBrowser()
  185402. {
  185403. createControl (&CLSID_WebBrowser);
  185404. browser = (IWebBrowser2*) queryInterface (&IID_IWebBrowser2);
  185405. IConnectionPointContainer* connectionPointContainer = (IConnectionPointContainer*) queryInterface (&IID_IConnectionPointContainer);
  185406. if (connectionPointContainer != 0)
  185407. {
  185408. connectionPointContainer->FindConnectionPoint (DIID_DWebBrowserEvents2,
  185409. &connectionPoint);
  185410. if (connectionPoint != 0)
  185411. {
  185412. WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
  185413. jassert (owner != 0);
  185414. EventHandler* handler = new EventHandler (owner);
  185415. connectionPoint->Advise (handler, &adviseCookie);
  185416. }
  185417. }
  185418. }
  185419. void goToURL (const String& url,
  185420. const StringArray* headers,
  185421. const MemoryBlock* postData)
  185422. {
  185423. if (browser != 0)
  185424. {
  185425. LPSAFEARRAY sa = 0;
  185426. VARIANT flags, frame, postDataVar, headersVar; // (_variant_t isn't available in all compilers)
  185427. VariantInit (&flags);
  185428. VariantInit (&frame);
  185429. VariantInit (&postDataVar);
  185430. VariantInit (&headersVar);
  185431. if (headers != 0)
  185432. {
  185433. V_VT (&headersVar) = VT_BSTR;
  185434. V_BSTR (&headersVar) = SysAllocString ((const tchar*) headers->joinIntoString ("\r\n"));
  185435. }
  185436. if (postData != 0 && postData->getSize() > 0)
  185437. {
  185438. LPSAFEARRAY sa = SafeArrayCreateVector (VT_UI1, 0, postData->getSize());
  185439. if (sa != 0)
  185440. {
  185441. void* data = 0;
  185442. SafeArrayAccessData (sa, &data);
  185443. jassert (data != 0);
  185444. if (data != 0)
  185445. {
  185446. postData->copyTo (data, 0, postData->getSize());
  185447. SafeArrayUnaccessData (sa);
  185448. VARIANT postDataVar2;
  185449. VariantInit (&postDataVar2);
  185450. V_VT (&postDataVar2) = VT_ARRAY | VT_UI1;
  185451. V_ARRAY (&postDataVar2) = sa;
  185452. postDataVar = postDataVar2;
  185453. }
  185454. }
  185455. }
  185456. browser->Navigate ((BSTR) (const OLECHAR*) url,
  185457. &flags, &frame,
  185458. &postDataVar, &headersVar);
  185459. if (sa != 0)
  185460. SafeArrayDestroy (sa);
  185461. VariantClear (&flags);
  185462. VariantClear (&frame);
  185463. VariantClear (&postDataVar);
  185464. VariantClear (&headersVar);
  185465. }
  185466. }
  185467. IWebBrowser2* browser;
  185468. juce_UseDebuggingNewOperator
  185469. private:
  185470. IConnectionPoint* connectionPoint;
  185471. DWORD adviseCookie;
  185472. class EventHandler : public IDispatch,
  185473. public ComponentMovementWatcher
  185474. {
  185475. public:
  185476. EventHandler (WebBrowserComponent* owner_)
  185477. : ComponentMovementWatcher (owner_),
  185478. owner (owner_),
  185479. refCount (0)
  185480. {
  185481. }
  185482. ~EventHandler()
  185483. {
  185484. }
  185485. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  185486. {
  185487. if (id == IID_IUnknown || id == IID_IDispatch || id == DIID_DWebBrowserEvents2)
  185488. {
  185489. AddRef();
  185490. *result = this;
  185491. return S_OK;
  185492. }
  185493. *result = 0;
  185494. return E_NOINTERFACE;
  185495. }
  185496. ULONG __stdcall AddRef() { return ++refCount; }
  185497. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  185498. HRESULT __stdcall GetTypeInfoCount (UINT __RPC_FAR*) { return E_NOTIMPL; }
  185499. HRESULT __stdcall GetTypeInfo (UINT, LCID, ITypeInfo __RPC_FAR *__RPC_FAR*) { return E_NOTIMPL; }
  185500. HRESULT __stdcall GetIDsOfNames (REFIID, LPOLESTR __RPC_FAR*, UINT, LCID, DISPID __RPC_FAR*) { return E_NOTIMPL; }
  185501. HRESULT __stdcall Invoke (DISPID dispIdMember, REFIID /*riid*/, LCID /*lcid*/,
  185502. WORD /*wFlags*/, DISPPARAMS __RPC_FAR* pDispParams,
  185503. VARIANT __RPC_FAR* /*pVarResult*/, EXCEPINFO __RPC_FAR* /*pExcepInfo*/,
  185504. UINT __RPC_FAR* /*puArgErr*/)
  185505. {
  185506. switch (dispIdMember)
  185507. {
  185508. case DISPID_BEFORENAVIGATE2:
  185509. {
  185510. VARIANT* const vurl = pDispParams->rgvarg[5].pvarVal;
  185511. String url;
  185512. if ((vurl->vt & VT_BYREF) != 0)
  185513. url = *vurl->pbstrVal;
  185514. else
  185515. url = vurl->bstrVal;
  185516. *pDispParams->rgvarg->pboolVal
  185517. = owner->pageAboutToLoad (url) ? VARIANT_FALSE
  185518. : VARIANT_TRUE;
  185519. return S_OK;
  185520. }
  185521. default:
  185522. break;
  185523. }
  185524. return E_NOTIMPL;
  185525. }
  185526. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/) {}
  185527. void componentPeerChanged() {}
  185528. void componentVisibilityChanged (Component&)
  185529. {
  185530. owner->visibilityChanged();
  185531. }
  185532. juce_UseDebuggingNewOperator
  185533. private:
  185534. WebBrowserComponent* const owner;
  185535. int refCount;
  185536. EventHandler (const EventHandler&);
  185537. EventHandler& operator= (const EventHandler&);
  185538. };
  185539. };
  185540. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  185541. : browser (0),
  185542. blankPageShown (false),
  185543. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  185544. {
  185545. setOpaque (true);
  185546. addAndMakeVisible (browser = new WebBrowserComponentInternal());
  185547. }
  185548. WebBrowserComponent::~WebBrowserComponent()
  185549. {
  185550. delete browser;
  185551. }
  185552. void WebBrowserComponent::goToURL (const String& url,
  185553. const StringArray* headers,
  185554. const MemoryBlock* postData)
  185555. {
  185556. lastURL = url;
  185557. lastHeaders.clear();
  185558. if (headers != 0)
  185559. lastHeaders = *headers;
  185560. lastPostData.setSize (0);
  185561. if (postData != 0)
  185562. lastPostData = *postData;
  185563. blankPageShown = false;
  185564. browser->goToURL (url, headers, postData);
  185565. }
  185566. void WebBrowserComponent::stop()
  185567. {
  185568. if (browser->browser != 0)
  185569. browser->browser->Stop();
  185570. }
  185571. void WebBrowserComponent::goBack()
  185572. {
  185573. lastURL = String::empty;
  185574. blankPageShown = false;
  185575. if (browser->browser != 0)
  185576. browser->browser->GoBack();
  185577. }
  185578. void WebBrowserComponent::goForward()
  185579. {
  185580. lastURL = String::empty;
  185581. if (browser->browser != 0)
  185582. browser->browser->GoForward();
  185583. }
  185584. void WebBrowserComponent::refresh()
  185585. {
  185586. if (browser->browser != 0)
  185587. browser->browser->Refresh();
  185588. }
  185589. void WebBrowserComponent::paint (Graphics& g)
  185590. {
  185591. if (browser->browser == 0)
  185592. g.fillAll (Colours::white);
  185593. }
  185594. void WebBrowserComponent::checkWindowAssociation()
  185595. {
  185596. if (isShowing())
  185597. {
  185598. if (browser->browser == 0 && getPeer() != 0)
  185599. {
  185600. browser->createBrowser();
  185601. reloadLastURL();
  185602. }
  185603. else
  185604. {
  185605. if (blankPageShown)
  185606. goBack();
  185607. }
  185608. }
  185609. else
  185610. {
  185611. if (browser != 0 && unloadPageWhenBrowserIsHidden && ! blankPageShown)
  185612. {
  185613. // when the component becomes invisible, some stuff like flash
  185614. // carries on playing audio, so we need to force it onto a blank
  185615. // page to avoid this..
  185616. blankPageShown = true;
  185617. browser->goToURL ("about:blank", 0, 0);
  185618. }
  185619. }
  185620. }
  185621. void WebBrowserComponent::reloadLastURL()
  185622. {
  185623. if (lastURL.isNotEmpty())
  185624. {
  185625. goToURL (lastURL, &lastHeaders, &lastPostData);
  185626. lastURL = String::empty;
  185627. }
  185628. }
  185629. void WebBrowserComponent::parentHierarchyChanged()
  185630. {
  185631. checkWindowAssociation();
  185632. }
  185633. void WebBrowserComponent::resized()
  185634. {
  185635. browser->setSize (getWidth(), getHeight());
  185636. }
  185637. void WebBrowserComponent::visibilityChanged()
  185638. {
  185639. checkWindowAssociation();
  185640. }
  185641. bool WebBrowserComponent::pageAboutToLoad (const String&)
  185642. {
  185643. return true;
  185644. }
  185645. #endif
  185646. /*** End of inlined file: juce_win32_WebBrowserComponent.cpp ***/
  185647. /*** Start of inlined file: juce_win32_OpenGLComponent.cpp ***/
  185648. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  185649. // compiled on its own).
  185650. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  185651. #define WGL_EXT_FUNCTION_INIT(extType, extFunc) \
  185652. ((extFunc = (extType) wglGetProcAddress (#extFunc)) != 0)
  185653. typedef const char* (WINAPI* PFNWGLGETEXTENSIONSSTRINGARBPROC) (HDC hdc);
  185654. typedef BOOL (WINAPI * PFNWGLGETPIXELFORMATATTRIBIVARBPROC) (HDC hdc, int iPixelFormat, int iLayerPlane, UINT nAttributes, const int *piAttributes, int *piValues);
  185655. typedef BOOL (WINAPI * PFNWGLCHOOSEPIXELFORMATARBPROC) (HDC hdc, const int* piAttribIList, const FLOAT *pfAttribFList, UINT nMaxFormats, int *piFormats, UINT *nNumFormats);
  185656. typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
  185657. typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
  185658. #define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
  185659. #define WGL_DRAW_TO_WINDOW_ARB 0x2001
  185660. #define WGL_ACCELERATION_ARB 0x2003
  185661. #define WGL_SWAP_METHOD_ARB 0x2007
  185662. #define WGL_SUPPORT_OPENGL_ARB 0x2010
  185663. #define WGL_PIXEL_TYPE_ARB 0x2013
  185664. #define WGL_DOUBLE_BUFFER_ARB 0x2011
  185665. #define WGL_COLOR_BITS_ARB 0x2014
  185666. #define WGL_RED_BITS_ARB 0x2015
  185667. #define WGL_GREEN_BITS_ARB 0x2017
  185668. #define WGL_BLUE_BITS_ARB 0x2019
  185669. #define WGL_ALPHA_BITS_ARB 0x201B
  185670. #define WGL_DEPTH_BITS_ARB 0x2022
  185671. #define WGL_STENCIL_BITS_ARB 0x2023
  185672. #define WGL_FULL_ACCELERATION_ARB 0x2027
  185673. #define WGL_ACCUM_RED_BITS_ARB 0x201E
  185674. #define WGL_ACCUM_GREEN_BITS_ARB 0x201F
  185675. #define WGL_ACCUM_BLUE_BITS_ARB 0x2020
  185676. #define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
  185677. #define WGL_STEREO_ARB 0x2012
  185678. #define WGL_SAMPLE_BUFFERS_ARB 0x2041
  185679. #define WGL_SAMPLES_ARB 0x2042
  185680. #define WGL_TYPE_RGBA_ARB 0x202B
  185681. static void getWglExtensions (HDC dc, StringArray& result) throw()
  185682. {
  185683. PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = 0;
  185684. if (WGL_EXT_FUNCTION_INIT (PFNWGLGETEXTENSIONSSTRINGARBPROC, wglGetExtensionsStringARB))
  185685. result.addTokens (String (wglGetExtensionsStringARB (dc)), false);
  185686. else
  185687. jassertfalse // If this fails, it may be because you didn't activate the openGL context
  185688. }
  185689. class WindowedGLContext : public OpenGLContext
  185690. {
  185691. public:
  185692. WindowedGLContext (Component* const component_,
  185693. HGLRC contextToShareWith,
  185694. const OpenGLPixelFormat& pixelFormat)
  185695. : renderContext (0),
  185696. nativeWindow (0),
  185697. dc (0),
  185698. component (component_)
  185699. {
  185700. jassert (component != 0);
  185701. createNativeWindow();
  185702. // Use a default pixel format that should be supported everywhere
  185703. PIXELFORMATDESCRIPTOR pfd;
  185704. zerostruct (pfd);
  185705. pfd.nSize = sizeof (pfd);
  185706. pfd.nVersion = 1;
  185707. pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER;
  185708. pfd.iPixelType = PFD_TYPE_RGBA;
  185709. pfd.cColorBits = 24;
  185710. pfd.cDepthBits = 16;
  185711. const int format = ChoosePixelFormat (dc, &pfd);
  185712. if (format != 0)
  185713. SetPixelFormat (dc, format, &pfd);
  185714. renderContext = wglCreateContext (dc);
  185715. makeActive();
  185716. setPixelFormat (pixelFormat);
  185717. if (contextToShareWith != 0 && renderContext != 0)
  185718. wglShareLists (contextToShareWith, renderContext);
  185719. }
  185720. ~WindowedGLContext()
  185721. {
  185722. makeInactive();
  185723. wglDeleteContext (renderContext);
  185724. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185725. delete nativeWindow;
  185726. }
  185727. bool makeActive() const throw()
  185728. {
  185729. jassert (renderContext != 0);
  185730. return wglMakeCurrent (dc, renderContext) != 0;
  185731. }
  185732. bool makeInactive() const throw()
  185733. {
  185734. return (! isActive()) || (wglMakeCurrent (0, 0) != 0);
  185735. }
  185736. bool isActive() const throw()
  185737. {
  185738. return wglGetCurrentContext() == renderContext;
  185739. }
  185740. const OpenGLPixelFormat getPixelFormat() const
  185741. {
  185742. OpenGLPixelFormat pf;
  185743. makeActive();
  185744. StringArray availableExtensions;
  185745. getWglExtensions (dc, availableExtensions);
  185746. fillInPixelFormatDetails (GetPixelFormat (dc), pf, availableExtensions);
  185747. return pf;
  185748. }
  185749. void* getRawContext() const throw()
  185750. {
  185751. return renderContext;
  185752. }
  185753. bool setPixelFormat (const OpenGLPixelFormat& pixelFormat)
  185754. {
  185755. makeActive();
  185756. PIXELFORMATDESCRIPTOR pfd;
  185757. zerostruct (pfd);
  185758. pfd.nSize = sizeof (pfd);
  185759. pfd.nVersion = 1;
  185760. pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_DRAW_TO_WINDOW | PFD_DOUBLEBUFFER;
  185761. pfd.iPixelType = PFD_TYPE_RGBA;
  185762. pfd.iLayerType = PFD_MAIN_PLANE;
  185763. pfd.cColorBits = (BYTE) (pixelFormat.redBits + pixelFormat.greenBits + pixelFormat.blueBits);
  185764. pfd.cRedBits = (BYTE) pixelFormat.redBits;
  185765. pfd.cGreenBits = (BYTE) pixelFormat.greenBits;
  185766. pfd.cBlueBits = (BYTE) pixelFormat.blueBits;
  185767. pfd.cAlphaBits = (BYTE) pixelFormat.alphaBits;
  185768. pfd.cDepthBits = (BYTE) pixelFormat.depthBufferBits;
  185769. pfd.cStencilBits = (BYTE) pixelFormat.stencilBufferBits;
  185770. pfd.cAccumBits = (BYTE) (pixelFormat.accumulationBufferRedBits + pixelFormat.accumulationBufferGreenBits
  185771. + pixelFormat.accumulationBufferBlueBits + pixelFormat.accumulationBufferAlphaBits);
  185772. pfd.cAccumRedBits = (BYTE) pixelFormat.accumulationBufferRedBits;
  185773. pfd.cAccumGreenBits = (BYTE) pixelFormat.accumulationBufferGreenBits;
  185774. pfd.cAccumBlueBits = (BYTE) pixelFormat.accumulationBufferBlueBits;
  185775. pfd.cAccumAlphaBits = (BYTE) pixelFormat.accumulationBufferAlphaBits;
  185776. int format = 0;
  185777. PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = 0;
  185778. StringArray availableExtensions;
  185779. getWglExtensions (dc, availableExtensions);
  185780. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185781. && WGL_EXT_FUNCTION_INIT (PFNWGLCHOOSEPIXELFORMATARBPROC, wglChoosePixelFormatARB))
  185782. {
  185783. int attributes[64];
  185784. int n = 0;
  185785. attributes[n++] = WGL_DRAW_TO_WINDOW_ARB;
  185786. attributes[n++] = GL_TRUE;
  185787. attributes[n++] = WGL_SUPPORT_OPENGL_ARB;
  185788. attributes[n++] = GL_TRUE;
  185789. attributes[n++] = WGL_ACCELERATION_ARB;
  185790. attributes[n++] = WGL_FULL_ACCELERATION_ARB;
  185791. attributes[n++] = WGL_DOUBLE_BUFFER_ARB;
  185792. attributes[n++] = GL_TRUE;
  185793. attributes[n++] = WGL_PIXEL_TYPE_ARB;
  185794. attributes[n++] = WGL_TYPE_RGBA_ARB;
  185795. attributes[n++] = WGL_COLOR_BITS_ARB;
  185796. attributes[n++] = pfd.cColorBits;
  185797. attributes[n++] = WGL_RED_BITS_ARB;
  185798. attributes[n++] = pixelFormat.redBits;
  185799. attributes[n++] = WGL_GREEN_BITS_ARB;
  185800. attributes[n++] = pixelFormat.greenBits;
  185801. attributes[n++] = WGL_BLUE_BITS_ARB;
  185802. attributes[n++] = pixelFormat.blueBits;
  185803. attributes[n++] = WGL_ALPHA_BITS_ARB;
  185804. attributes[n++] = pixelFormat.alphaBits;
  185805. attributes[n++] = WGL_DEPTH_BITS_ARB;
  185806. attributes[n++] = pixelFormat.depthBufferBits;
  185807. if (pixelFormat.stencilBufferBits > 0)
  185808. {
  185809. attributes[n++] = WGL_STENCIL_BITS_ARB;
  185810. attributes[n++] = pixelFormat.stencilBufferBits;
  185811. }
  185812. attributes[n++] = WGL_ACCUM_RED_BITS_ARB;
  185813. attributes[n++] = pixelFormat.accumulationBufferRedBits;
  185814. attributes[n++] = WGL_ACCUM_GREEN_BITS_ARB;
  185815. attributes[n++] = pixelFormat.accumulationBufferGreenBits;
  185816. attributes[n++] = WGL_ACCUM_BLUE_BITS_ARB;
  185817. attributes[n++] = pixelFormat.accumulationBufferBlueBits;
  185818. attributes[n++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185819. attributes[n++] = pixelFormat.accumulationBufferAlphaBits;
  185820. if (availableExtensions.contains ("WGL_ARB_multisample")
  185821. && pixelFormat.fullSceneAntiAliasingNumSamples > 0)
  185822. {
  185823. attributes[n++] = WGL_SAMPLE_BUFFERS_ARB;
  185824. attributes[n++] = 1;
  185825. attributes[n++] = WGL_SAMPLES_ARB;
  185826. attributes[n++] = pixelFormat.fullSceneAntiAliasingNumSamples;
  185827. }
  185828. attributes[n++] = 0;
  185829. UINT formatsCount;
  185830. const BOOL ok = wglChoosePixelFormatARB (dc, attributes, 0, 1, &format, &formatsCount);
  185831. (void) ok;
  185832. jassert (ok);
  185833. }
  185834. else
  185835. {
  185836. format = ChoosePixelFormat (dc, &pfd);
  185837. }
  185838. if (format != 0)
  185839. {
  185840. makeInactive();
  185841. // win32 can't change the pixel format of a window, so need to delete the
  185842. // old one and create a new one..
  185843. jassert (nativeWindow != 0);
  185844. ReleaseDC ((HWND) nativeWindow->getNativeHandle(), dc);
  185845. delete nativeWindow;
  185846. createNativeWindow();
  185847. if (SetPixelFormat (dc, format, &pfd))
  185848. {
  185849. wglDeleteContext (renderContext);
  185850. renderContext = wglCreateContext (dc);
  185851. jassert (renderContext != 0);
  185852. return renderContext != 0;
  185853. }
  185854. }
  185855. return false;
  185856. }
  185857. void updateWindowPosition (int x, int y, int w, int h, int)
  185858. {
  185859. SetWindowPos ((HWND) nativeWindow->getNativeHandle(), 0,
  185860. x, y, w, h,
  185861. SWP_NOACTIVATE | SWP_NOZORDER | SWP_NOOWNERZORDER);
  185862. }
  185863. void repaint()
  185864. {
  185865. const Rectangle<int> bounds (nativeWindow->getBounds());
  185866. nativeWindow->repaint (0, 0, bounds.getWidth(), bounds.getHeight());
  185867. }
  185868. void swapBuffers()
  185869. {
  185870. SwapBuffers (dc);
  185871. }
  185872. bool setSwapInterval (const int numFramesPerSwap)
  185873. {
  185874. makeActive();
  185875. StringArray availableExtensions;
  185876. getWglExtensions (dc, availableExtensions);
  185877. PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = 0;
  185878. return availableExtensions.contains ("WGL_EXT_swap_control")
  185879. && WGL_EXT_FUNCTION_INIT (PFNWGLSWAPINTERVALEXTPROC, wglSwapIntervalEXT)
  185880. && wglSwapIntervalEXT (numFramesPerSwap) != FALSE;
  185881. }
  185882. int getSwapInterval() const
  185883. {
  185884. makeActive();
  185885. StringArray availableExtensions;
  185886. getWglExtensions (dc, availableExtensions);
  185887. PFNWGLGETSWAPINTERVALEXTPROC wglGetSwapIntervalEXT = 0;
  185888. if (availableExtensions.contains ("WGL_EXT_swap_control")
  185889. && WGL_EXT_FUNCTION_INIT (PFNWGLGETSWAPINTERVALEXTPROC, wglGetSwapIntervalEXT))
  185890. return wglGetSwapIntervalEXT();
  185891. return 0;
  185892. }
  185893. void findAlternativeOpenGLPixelFormats (OwnedArray <OpenGLPixelFormat>& results)
  185894. {
  185895. jassert (isActive());
  185896. StringArray availableExtensions;
  185897. getWglExtensions (dc, availableExtensions);
  185898. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185899. int numTypes = 0;
  185900. if (availableExtensions.contains("WGL_ARB_pixel_format")
  185901. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185902. {
  185903. int attributes = WGL_NUMBER_PIXEL_FORMATS_ARB;
  185904. if (! wglGetPixelFormatAttribivARB (dc, 1, 0, 1, &attributes, &numTypes))
  185905. jassertfalse
  185906. }
  185907. else
  185908. {
  185909. numTypes = DescribePixelFormat (dc, 0, 0, 0);
  185910. }
  185911. OpenGLPixelFormat pf;
  185912. for (int i = 0; i < numTypes; ++i)
  185913. {
  185914. if (fillInPixelFormatDetails (i + 1, pf, availableExtensions))
  185915. {
  185916. bool alreadyListed = false;
  185917. for (int j = results.size(); --j >= 0;)
  185918. if (pf == *results.getUnchecked(j))
  185919. alreadyListed = true;
  185920. if (! alreadyListed)
  185921. results.add (new OpenGLPixelFormat (pf));
  185922. }
  185923. }
  185924. }
  185925. void* getNativeWindowHandle() const
  185926. {
  185927. return nativeWindow != 0 ? nativeWindow->getNativeHandle() : 0;
  185928. }
  185929. juce_UseDebuggingNewOperator
  185930. HGLRC renderContext;
  185931. private:
  185932. Win32ComponentPeer* nativeWindow;
  185933. Component* const component;
  185934. HDC dc;
  185935. void createNativeWindow()
  185936. {
  185937. nativeWindow = new Win32ComponentPeer (component, 0);
  185938. nativeWindow->dontRepaint = true;
  185939. nativeWindow->setVisible (true);
  185940. HWND hwnd = (HWND) nativeWindow->getNativeHandle();
  185941. Win32ComponentPeer* const peer = dynamic_cast <Win32ComponentPeer*> (component->getTopLevelComponent()->getPeer());
  185942. if (peer != 0)
  185943. {
  185944. SetParent (hwnd, (HWND) peer->getNativeHandle());
  185945. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_CHILD, true);
  185946. juce_setWindowStyleBit (hwnd, GWL_STYLE, WS_POPUP, false);
  185947. }
  185948. dc = GetDC (hwnd);
  185949. }
  185950. bool fillInPixelFormatDetails (const int pixelFormatIndex,
  185951. OpenGLPixelFormat& result,
  185952. const StringArray& availableExtensions) const throw()
  185953. {
  185954. PFNWGLGETPIXELFORMATATTRIBIVARBPROC wglGetPixelFormatAttribivARB = 0;
  185955. if (availableExtensions.contains ("WGL_ARB_pixel_format")
  185956. && WGL_EXT_FUNCTION_INIT (PFNWGLGETPIXELFORMATATTRIBIVARBPROC, wglGetPixelFormatAttribivARB))
  185957. {
  185958. int attributes[32];
  185959. int numAttributes = 0;
  185960. attributes[numAttributes++] = WGL_DRAW_TO_WINDOW_ARB;
  185961. attributes[numAttributes++] = WGL_SUPPORT_OPENGL_ARB;
  185962. attributes[numAttributes++] = WGL_ACCELERATION_ARB;
  185963. attributes[numAttributes++] = WGL_DOUBLE_BUFFER_ARB;
  185964. attributes[numAttributes++] = WGL_PIXEL_TYPE_ARB;
  185965. attributes[numAttributes++] = WGL_RED_BITS_ARB;
  185966. attributes[numAttributes++] = WGL_GREEN_BITS_ARB;
  185967. attributes[numAttributes++] = WGL_BLUE_BITS_ARB;
  185968. attributes[numAttributes++] = WGL_ALPHA_BITS_ARB;
  185969. attributes[numAttributes++] = WGL_DEPTH_BITS_ARB;
  185970. attributes[numAttributes++] = WGL_STENCIL_BITS_ARB;
  185971. attributes[numAttributes++] = WGL_ACCUM_RED_BITS_ARB;
  185972. attributes[numAttributes++] = WGL_ACCUM_GREEN_BITS_ARB;
  185973. attributes[numAttributes++] = WGL_ACCUM_BLUE_BITS_ARB;
  185974. attributes[numAttributes++] = WGL_ACCUM_ALPHA_BITS_ARB;
  185975. if (availableExtensions.contains ("WGL_ARB_multisample"))
  185976. attributes[numAttributes++] = WGL_SAMPLES_ARB;
  185977. int values[32];
  185978. zeromem (values, sizeof (values));
  185979. if (wglGetPixelFormatAttribivARB (dc, pixelFormatIndex, 0, numAttributes, attributes, values))
  185980. {
  185981. int n = 0;
  185982. bool isValidFormat = (values[n++] == GL_TRUE); // WGL_DRAW_TO_WINDOW_ARB
  185983. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_SUPPORT_OPENGL_ARB
  185984. isValidFormat = (values[n++] == WGL_FULL_ACCELERATION_ARB) && isValidFormat; // WGL_ACCELERATION_ARB
  185985. isValidFormat = (values[n++] == GL_TRUE) && isValidFormat; // WGL_DOUBLE_BUFFER_ARB:
  185986. isValidFormat = (values[n++] == WGL_TYPE_RGBA_ARB) && isValidFormat; // WGL_PIXEL_TYPE_ARB
  185987. result.redBits = values[n++]; // WGL_RED_BITS_ARB
  185988. result.greenBits = values[n++]; // WGL_GREEN_BITS_ARB
  185989. result.blueBits = values[n++]; // WGL_BLUE_BITS_ARB
  185990. result.alphaBits = values[n++]; // WGL_ALPHA_BITS_ARB
  185991. result.depthBufferBits = values[n++]; // WGL_DEPTH_BITS_ARB
  185992. result.stencilBufferBits = values[n++]; // WGL_STENCIL_BITS_ARB
  185993. result.accumulationBufferRedBits = values[n++]; // WGL_ACCUM_RED_BITS_ARB
  185994. result.accumulationBufferGreenBits = values[n++]; // WGL_ACCUM_GREEN_BITS_ARB
  185995. result.accumulationBufferBlueBits = values[n++]; // WGL_ACCUM_BLUE_BITS_ARB
  185996. result.accumulationBufferAlphaBits = values[n++]; // WGL_ACCUM_ALPHA_BITS_ARB
  185997. result.fullSceneAntiAliasingNumSamples = (uint8) values[n++]; // WGL_SAMPLES_ARB
  185998. return isValidFormat;
  185999. }
  186000. else
  186001. {
  186002. jassertfalse
  186003. }
  186004. }
  186005. else
  186006. {
  186007. PIXELFORMATDESCRIPTOR pfd;
  186008. if (DescribePixelFormat (dc, pixelFormatIndex, sizeof (pfd), &pfd))
  186009. {
  186010. result.redBits = pfd.cRedBits;
  186011. result.greenBits = pfd.cGreenBits;
  186012. result.blueBits = pfd.cBlueBits;
  186013. result.alphaBits = pfd.cAlphaBits;
  186014. result.depthBufferBits = pfd.cDepthBits;
  186015. result.stencilBufferBits = pfd.cStencilBits;
  186016. result.accumulationBufferRedBits = pfd.cAccumRedBits;
  186017. result.accumulationBufferGreenBits = pfd.cAccumGreenBits;
  186018. result.accumulationBufferBlueBits = pfd.cAccumBlueBits;
  186019. result.accumulationBufferAlphaBits = pfd.cAccumAlphaBits;
  186020. result.fullSceneAntiAliasingNumSamples = 0;
  186021. return true;
  186022. }
  186023. else
  186024. {
  186025. jassertfalse
  186026. }
  186027. }
  186028. return false;
  186029. }
  186030. WindowedGLContext (const WindowedGLContext&);
  186031. WindowedGLContext& operator= (const WindowedGLContext&);
  186032. };
  186033. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  186034. const OpenGLPixelFormat& pixelFormat,
  186035. const OpenGLContext* const contextToShareWith)
  186036. {
  186037. WindowedGLContext* c = new WindowedGLContext (component,
  186038. contextToShareWith != 0 ? (HGLRC) contextToShareWith->getRawContext() : 0,
  186039. pixelFormat);
  186040. if (c->renderContext == 0)
  186041. deleteAndZero (c);
  186042. return c;
  186043. }
  186044. void* OpenGLComponent::getNativeWindowHandle() const
  186045. {
  186046. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle() : 0;
  186047. }
  186048. void juce_glViewport (const int w, const int h)
  186049. {
  186050. glViewport (0, 0, w, h);
  186051. }
  186052. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  186053. OwnedArray <OpenGLPixelFormat>& results)
  186054. {
  186055. Component tempComp;
  186056. {
  186057. WindowedGLContext wc (component, 0, OpenGLPixelFormat (8, 8, 16, 0));
  186058. wc.makeActive();
  186059. wc.findAlternativeOpenGLPixelFormats (results);
  186060. }
  186061. }
  186062. #endif
  186063. /*** End of inlined file: juce_win32_OpenGLComponent.cpp ***/
  186064. /*** Start of inlined file: juce_win32_AudioCDReader.cpp ***/
  186065. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  186066. // compiled on its own).
  186067. #if JUCE_INCLUDED_FILE
  186068. #if JUCE_USE_CDREADER
  186069. //***************************************************************************
  186070. // %%% TARGET STATUS VALUES %%%
  186071. //***************************************************************************
  186072. #define STATUS_GOOD 0x00 // Status Good
  186073. #define STATUS_CHKCOND 0x02 // Check Condition
  186074. #define STATUS_CONDMET 0x04 // Condition Met
  186075. #define STATUS_BUSY 0x08 // Busy
  186076. #define STATUS_INTERM 0x10 // Intermediate
  186077. #define STATUS_INTCDMET 0x14 // Intermediate-condition met
  186078. #define STATUS_RESCONF 0x18 // Reservation conflict
  186079. #define STATUS_COMTERM 0x22 // Command Terminated
  186080. #define STATUS_QFULL 0x28 // Queue full
  186081. //***************************************************************************
  186082. // %%% SCSI MISCELLANEOUS EQUATES %%%
  186083. //***************************************************************************
  186084. #define MAXLUN 7 // Maximum Logical Unit Id
  186085. #define MAXTARG 7 // Maximum Target Id
  186086. #define MAX_SCSI_LUNS 64 // Maximum Number of SCSI LUNs
  186087. #define MAX_NUM_HA 8 // Maximum Number of SCSI HA's
  186088. //***************************************************************************
  186089. // %%% Commands for all Device Types %%%
  186090. //***************************************************************************
  186091. #define SCSI_CHANGE_DEF 0x40 // Change Definition (Optional)
  186092. #define SCSI_COMPARE 0x39 // Compare (O)
  186093. #define SCSI_COPY 0x18 // Copy (O)
  186094. #define SCSI_COP_VERIFY 0x3A // Copy and Verify (O)
  186095. #define SCSI_INQUIRY 0x12 // Inquiry (MANDATORY)
  186096. #define SCSI_LOG_SELECT 0x4C // Log Select (O)
  186097. #define SCSI_LOG_SENSE 0x4D // Log Sense (O)
  186098. #define SCSI_MODE_SEL6 0x15 // Mode Select 6-byte (Device Specific)
  186099. #define SCSI_MODE_SEL10 0x55 // Mode Select 10-byte (Device Specific)
  186100. #define SCSI_MODE_SEN6 0x1A // Mode Sense 6-byte (Device Specific)
  186101. #define SCSI_MODE_SEN10 0x5A // Mode Sense 10-byte (Device Specific)
  186102. #define SCSI_READ_BUFF 0x3C // Read Buffer (O)
  186103. #define SCSI_REQ_SENSE 0x03 // Request Sense (MANDATORY)
  186104. #define SCSI_SEND_DIAG 0x1D // Send Diagnostic (O)
  186105. #define SCSI_TST_U_RDY 0x00 // Test Unit Ready (MANDATORY)
  186106. #define SCSI_WRITE_BUFF 0x3B // Write Buffer (O)
  186107. //***************************************************************************
  186108. // %%% Commands Unique to Direct Access Devices %%%
  186109. //***************************************************************************
  186110. #define SCSI_COMPARE 0x39 // Compare (O)
  186111. #define SCSI_FORMAT 0x04 // Format Unit (MANDATORY)
  186112. #define SCSI_LCK_UN_CAC 0x36 // Lock Unlock Cache (O)
  186113. #define SCSI_PREFETCH 0x34 // Prefetch (O)
  186114. #define SCSI_MED_REMOVL 0x1E // Prevent/Allow medium Removal (O)
  186115. #define SCSI_READ6 0x08 // Read 6-byte (MANDATORY)
  186116. #define SCSI_READ10 0x28 // Read 10-byte (MANDATORY)
  186117. #define SCSI_RD_CAPAC 0x25 // Read Capacity (MANDATORY)
  186118. #define SCSI_RD_DEFECT 0x37 // Read Defect Data (O)
  186119. #define SCSI_READ_LONG 0x3E // Read Long (O)
  186120. #define SCSI_REASS_BLK 0x07 // Reassign Blocks (O)
  186121. #define SCSI_RCV_DIAG 0x1C // Receive Diagnostic Results (O)
  186122. #define SCSI_RELEASE 0x17 // Release Unit (MANDATORY)
  186123. #define SCSI_REZERO 0x01 // Rezero Unit (O)
  186124. #define SCSI_SRCH_DAT_E 0x31 // Search Data Equal (O)
  186125. #define SCSI_SRCH_DAT_H 0x30 // Search Data High (O)
  186126. #define SCSI_SRCH_DAT_L 0x32 // Search Data Low (O)
  186127. #define SCSI_SEEK6 0x0B // Seek 6-Byte (O)
  186128. #define SCSI_SEEK10 0x2B // Seek 10-Byte (O)
  186129. #define SCSI_SEND_DIAG 0x1D // Send Diagnostics (MANDATORY)
  186130. #define SCSI_SET_LIMIT 0x33 // Set Limits (O)
  186131. #define SCSI_START_STP 0x1B // Start/Stop Unit (O)
  186132. #define SCSI_SYNC_CACHE 0x35 // Synchronize Cache (O)
  186133. #define SCSI_VERIFY 0x2F // Verify (O)
  186134. #define SCSI_WRITE6 0x0A // Write 6-Byte (MANDATORY)
  186135. #define SCSI_WRITE10 0x2A // Write 10-Byte (MANDATORY)
  186136. #define SCSI_WRT_VERIFY 0x2E // Write and Verify (O)
  186137. #define SCSI_WRITE_LONG 0x3F // Write Long (O)
  186138. #define SCSI_WRITE_SAME 0x41 // Write Same (O)
  186139. //***************************************************************************
  186140. // %%% Commands Unique to Sequential Access Devices %%%
  186141. //***************************************************************************
  186142. #define SCSI_ERASE 0x19 // Erase (MANDATORY)
  186143. #define SCSI_LOAD_UN 0x1b // Load/Unload (O)
  186144. #define SCSI_LOCATE 0x2B // Locate (O)
  186145. #define SCSI_RD_BLK_LIM 0x05 // Read Block Limits (MANDATORY)
  186146. #define SCSI_READ_POS 0x34 // Read Position (O)
  186147. #define SCSI_READ_REV 0x0F // Read Reverse (O)
  186148. #define SCSI_REC_BF_DAT 0x14 // Recover Buffer Data (O)
  186149. #define SCSI_RESERVE 0x16 // Reserve Unit (MANDATORY)
  186150. #define SCSI_REWIND 0x01 // Rewind (MANDATORY)
  186151. #define SCSI_SPACE 0x11 // Space (MANDATORY)
  186152. #define SCSI_VERIFY_T 0x13 // Verify (Tape) (O)
  186153. #define SCSI_WRT_FILE 0x10 // Write Filemarks (MANDATORY)
  186154. //***************************************************************************
  186155. // %%% Commands Unique to Printer Devices %%%
  186156. //***************************************************************************
  186157. #define SCSI_PRINT 0x0A // Print (MANDATORY)
  186158. #define SCSI_SLEW_PNT 0x0B // Slew and Print (O)
  186159. #define SCSI_STOP_PNT 0x1B // Stop Print (O)
  186160. #define SCSI_SYNC_BUFF 0x10 // Synchronize Buffer (O)
  186161. //***************************************************************************
  186162. // %%% Commands Unique to Processor Devices %%%
  186163. //***************************************************************************
  186164. #define SCSI_RECEIVE 0x08 // Receive (O)
  186165. #define SCSI_SEND 0x0A // Send (O)
  186166. //***************************************************************************
  186167. // %%% Commands Unique to Write-Once Devices %%%
  186168. //***************************************************************************
  186169. #define SCSI_MEDIUM_SCN 0x38 // Medium Scan (O)
  186170. #define SCSI_SRCHDATE10 0x31 // Search Data Equal 10-Byte (O)
  186171. #define SCSI_SRCHDATE12 0xB1 // Search Data Equal 12-Byte (O)
  186172. #define SCSI_SRCHDATH10 0x30 // Search Data High 10-Byte (O)
  186173. #define SCSI_SRCHDATH12 0xB0 // Search Data High 12-Byte (O)
  186174. #define SCSI_SRCHDATL10 0x32 // Search Data Low 10-Byte (O)
  186175. #define SCSI_SRCHDATL12 0xB2 // Search Data Low 12-Byte (O)
  186176. #define SCSI_SET_LIM_10 0x33 // Set Limits 10-Byte (O)
  186177. #define SCSI_SET_LIM_12 0xB3 // Set Limits 10-Byte (O)
  186178. #define SCSI_VERIFY10 0x2F // Verify 10-Byte (O)
  186179. #define SCSI_VERIFY12 0xAF // Verify 12-Byte (O)
  186180. #define SCSI_WRITE12 0xAA // Write 12-Byte (O)
  186181. #define SCSI_WRT_VER10 0x2E // Write and Verify 10-Byte (O)
  186182. #define SCSI_WRT_VER12 0xAE // Write and Verify 12-Byte (O)
  186183. //***************************************************************************
  186184. // %%% Commands Unique to CD-ROM Devices %%%
  186185. //***************************************************************************
  186186. #define SCSI_PLAYAUD_10 0x45 // Play Audio 10-Byte (O)
  186187. #define SCSI_PLAYAUD_12 0xA5 // Play Audio 12-Byte 12-Byte (O)
  186188. #define SCSI_PLAYAUDMSF 0x47 // Play Audio MSF (O)
  186189. #define SCSI_PLAYA_TKIN 0x48 // Play Audio Track/Index (O)
  186190. #define SCSI_PLYTKREL10 0x49 // Play Track Relative 10-Byte (O)
  186191. #define SCSI_PLYTKREL12 0xA9 // Play Track Relative 12-Byte (O)
  186192. #define SCSI_READCDCAP 0x25 // Read CD-ROM Capacity (MANDATORY)
  186193. #define SCSI_READHEADER 0x44 // Read Header (O)
  186194. #define SCSI_SUBCHANNEL 0x42 // Read Subchannel (O)
  186195. #define SCSI_READ_TOC 0x43 // Read TOC (O)
  186196. //***************************************************************************
  186197. // %%% Commands Unique to Scanner Devices %%%
  186198. //***************************************************************************
  186199. #define SCSI_GETDBSTAT 0x34 // Get Data Buffer Status (O)
  186200. #define SCSI_GETWINDOW 0x25 // Get Window (O)
  186201. #define SCSI_OBJECTPOS 0x31 // Object Postion (O)
  186202. #define SCSI_SCAN 0x1B // Scan (O)
  186203. #define SCSI_SETWINDOW 0x24 // Set Window (MANDATORY)
  186204. //***************************************************************************
  186205. // %%% Commands Unique to Optical Memory Devices %%%
  186206. //***************************************************************************
  186207. #define SCSI_UpdateBlk 0x3D // Update Block (O)
  186208. //***************************************************************************
  186209. // %%% Commands Unique to Medium Changer Devices %%%
  186210. //***************************************************************************
  186211. #define SCSI_EXCHMEDIUM 0xA6 // Exchange Medium (O)
  186212. #define SCSI_INITELSTAT 0x07 // Initialize Element Status (O)
  186213. #define SCSI_POSTOELEM 0x2B // Position to Element (O)
  186214. #define SCSI_REQ_VE_ADD 0xB5 // Request Volume Element Address (O)
  186215. #define SCSI_SENDVOLTAG 0xB6 // Send Volume Tag (O)
  186216. //***************************************************************************
  186217. // %%% Commands Unique to Communication Devices %%%
  186218. //***************************************************************************
  186219. #define SCSI_GET_MSG_6 0x08 // Get Message 6-Byte (MANDATORY)
  186220. #define SCSI_GET_MSG_10 0x28 // Get Message 10-Byte (O)
  186221. #define SCSI_GET_MSG_12 0xA8 // Get Message 12-Byte (O)
  186222. #define SCSI_SND_MSG_6 0x0A // Send Message 6-Byte (MANDATORY)
  186223. #define SCSI_SND_MSG_10 0x2A // Send Message 10-Byte (O)
  186224. #define SCSI_SND_MSG_12 0xAA // Send Message 12-Byte (O)
  186225. //***************************************************************************
  186226. // %%% Request Sense Data Format %%%
  186227. //***************************************************************************
  186228. typedef struct {
  186229. BYTE ErrorCode; // Error Code (70H or 71H)
  186230. BYTE SegmentNum; // Number of current segment descriptor
  186231. BYTE SenseKey; // Sense Key(See bit definitions too)
  186232. BYTE InfoByte0; // Information MSB
  186233. BYTE InfoByte1; // Information MID
  186234. BYTE InfoByte2; // Information MID
  186235. BYTE InfoByte3; // Information LSB
  186236. BYTE AddSenLen; // Additional Sense Length
  186237. BYTE ComSpecInf0; // Command Specific Information MSB
  186238. BYTE ComSpecInf1; // Command Specific Information MID
  186239. BYTE ComSpecInf2; // Command Specific Information MID
  186240. BYTE ComSpecInf3; // Command Specific Information LSB
  186241. BYTE AddSenseCode; // Additional Sense Code
  186242. BYTE AddSenQual; // Additional Sense Code Qualifier
  186243. BYTE FieldRepUCode; // Field Replaceable Unit Code
  186244. BYTE SenKeySpec15; // Sense Key Specific 15th byte
  186245. BYTE SenKeySpec16; // Sense Key Specific 16th byte
  186246. BYTE SenKeySpec17; // Sense Key Specific 17th byte
  186247. BYTE AddSenseBytes; // Additional Sense Bytes
  186248. } SENSE_DATA_FMT;
  186249. //***************************************************************************
  186250. // %%% REQUEST SENSE ERROR CODE %%%
  186251. //***************************************************************************
  186252. #define SERROR_CURRENT 0x70 // Current Errors
  186253. #define SERROR_DEFERED 0x71 // Deferred Errors
  186254. //***************************************************************************
  186255. // %%% REQUEST SENSE BIT DEFINITIONS %%%
  186256. //***************************************************************************
  186257. #define SENSE_VALID 0x80 // Byte 0 Bit 7
  186258. #define SENSE_FILEMRK 0x80 // Byte 2 Bit 7
  186259. #define SENSE_EOM 0x40 // Byte 2 Bit 6
  186260. #define SENSE_ILI 0x20 // Byte 2 Bit 5
  186261. //***************************************************************************
  186262. // %%% REQUEST SENSE SENSE KEY DEFINITIONS %%%
  186263. //***************************************************************************
  186264. #define KEY_NOSENSE 0x00 // No Sense
  186265. #define KEY_RECERROR 0x01 // Recovered Error
  186266. #define KEY_NOTREADY 0x02 // Not Ready
  186267. #define KEY_MEDIUMERR 0x03 // Medium Error
  186268. #define KEY_HARDERROR 0x04 // Hardware Error
  186269. #define KEY_ILLGLREQ 0x05 // Illegal Request
  186270. #define KEY_UNITATT 0x06 // Unit Attention
  186271. #define KEY_DATAPROT 0x07 // Data Protect
  186272. #define KEY_BLANKCHK 0x08 // Blank Check
  186273. #define KEY_VENDSPEC 0x09 // Vendor Specific
  186274. #define KEY_COPYABORT 0x0A // Copy Abort
  186275. #define KEY_EQUAL 0x0C // Equal (Search)
  186276. #define KEY_VOLOVRFLW 0x0D // Volume Overflow
  186277. #define KEY_MISCOMP 0x0E // Miscompare (Search)
  186278. #define KEY_RESERVED 0x0F // Reserved
  186279. //***************************************************************************
  186280. // %%% PERIPHERAL DEVICE TYPE DEFINITIONS %%%
  186281. //***************************************************************************
  186282. #define DTYPE_DASD 0x00 // Disk Device
  186283. #define DTYPE_SEQD 0x01 // Tape Device
  186284. #define DTYPE_PRNT 0x02 // Printer
  186285. #define DTYPE_PROC 0x03 // Processor
  186286. #define DTYPE_WORM 0x04 // Write-once read-multiple
  186287. #define DTYPE_CROM 0x05 // CD-ROM device
  186288. #define DTYPE_SCAN 0x06 // Scanner device
  186289. #define DTYPE_OPTI 0x07 // Optical memory device
  186290. #define DTYPE_JUKE 0x08 // Medium Changer device
  186291. #define DTYPE_COMM 0x09 // Communications device
  186292. #define DTYPE_RESL 0x0A // Reserved (low)
  186293. #define DTYPE_RESH 0x1E // Reserved (high)
  186294. #define DTYPE_UNKNOWN 0x1F // Unknown or no device type
  186295. //***************************************************************************
  186296. // %%% ANSI APPROVED VERSION DEFINITIONS %%%
  186297. //***************************************************************************
  186298. #define ANSI_MAYBE 0x0 // Device may or may not be ANSI approved stand
  186299. #define ANSI_SCSI1 0x1 // Device complies to ANSI X3.131-1986 (SCSI-1)
  186300. #define ANSI_SCSI2 0x2 // Device complies to SCSI-2
  186301. #define ANSI_RESLO 0x3 // Reserved (low)
  186302. #define ANSI_RESHI 0x7 // Reserved (high)
  186303. typedef struct
  186304. {
  186305. USHORT Length;
  186306. UCHAR ScsiStatus;
  186307. UCHAR PathId;
  186308. UCHAR TargetId;
  186309. UCHAR Lun;
  186310. UCHAR CdbLength;
  186311. UCHAR SenseInfoLength;
  186312. UCHAR DataIn;
  186313. ULONG DataTransferLength;
  186314. ULONG TimeOutValue;
  186315. ULONG DataBufferOffset;
  186316. ULONG SenseInfoOffset;
  186317. UCHAR Cdb[16];
  186318. } SCSI_PASS_THROUGH, *PSCSI_PASS_THROUGH;
  186319. typedef struct
  186320. {
  186321. USHORT Length;
  186322. UCHAR ScsiStatus;
  186323. UCHAR PathId;
  186324. UCHAR TargetId;
  186325. UCHAR Lun;
  186326. UCHAR CdbLength;
  186327. UCHAR SenseInfoLength;
  186328. UCHAR DataIn;
  186329. ULONG DataTransferLength;
  186330. ULONG TimeOutValue;
  186331. PVOID DataBuffer;
  186332. ULONG SenseInfoOffset;
  186333. UCHAR Cdb[16];
  186334. } SCSI_PASS_THROUGH_DIRECT, *PSCSI_PASS_THROUGH_DIRECT;
  186335. typedef struct
  186336. {
  186337. SCSI_PASS_THROUGH_DIRECT spt;
  186338. ULONG Filler;
  186339. UCHAR ucSenseBuf[32];
  186340. } SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, *PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER;
  186341. typedef struct
  186342. {
  186343. ULONG Length;
  186344. UCHAR PortNumber;
  186345. UCHAR PathId;
  186346. UCHAR TargetId;
  186347. UCHAR Lun;
  186348. } SCSI_ADDRESS, *PSCSI_ADDRESS;
  186349. #define METHOD_BUFFERED 0
  186350. #define METHOD_IN_DIRECT 1
  186351. #define METHOD_OUT_DIRECT 2
  186352. #define METHOD_NEITHER 3
  186353. #define FILE_ANY_ACCESS 0
  186354. #ifndef FILE_READ_ACCESS
  186355. #define FILE_READ_ACCESS (0x0001)
  186356. #endif
  186357. #ifndef FILE_WRITE_ACCESS
  186358. #define FILE_WRITE_ACCESS (0x0002)
  186359. #endif
  186360. #define IOCTL_SCSI_BASE 0x00000004
  186361. #define SCSI_IOCTL_DATA_OUT 0
  186362. #define SCSI_IOCTL_DATA_IN 1
  186363. #define SCSI_IOCTL_DATA_UNSPECIFIED 2
  186364. #define CTL_CODE2( DevType, Function, Method, Access ) ( \
  186365. ((DevType) << 16) | ((Access) << 14) | ((Function) << 2) | (Method) \
  186366. )
  186367. #define IOCTL_SCSI_PASS_THROUGH CTL_CODE2( IOCTL_SCSI_BASE, 0x0401, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186368. #define IOCTL_SCSI_GET_CAPABILITIES CTL_CODE2( IOCTL_SCSI_BASE, 0x0404, METHOD_BUFFERED, FILE_ANY_ACCESS)
  186369. #define IOCTL_SCSI_PASS_THROUGH_DIRECT CTL_CODE2( IOCTL_SCSI_BASE, 0x0405, METHOD_BUFFERED, FILE_READ_ACCESS | FILE_WRITE_ACCESS )
  186370. #define IOCTL_SCSI_GET_ADDRESS CTL_CODE2( IOCTL_SCSI_BASE, 0x0406, METHOD_BUFFERED, FILE_ANY_ACCESS )
  186371. #define SENSE_LEN 14
  186372. #define SRB_DIR_SCSI 0x00
  186373. #define SRB_POSTING 0x01
  186374. #define SRB_ENABLE_RESIDUAL_COUNT 0x04
  186375. #define SRB_DIR_IN 0x08
  186376. #define SRB_DIR_OUT 0x10
  186377. #define SRB_EVENT_NOTIFY 0x40
  186378. #define RESIDUAL_COUNT_SUPPORTED 0x02
  186379. #define MAX_SRB_TIMEOUT 1080001u
  186380. #define DEFAULT_SRB_TIMEOUT 1080001u
  186381. #define SC_HA_INQUIRY 0x00
  186382. #define SC_GET_DEV_TYPE 0x01
  186383. #define SC_EXEC_SCSI_CMD 0x02
  186384. #define SC_ABORT_SRB 0x03
  186385. #define SC_RESET_DEV 0x04
  186386. #define SC_SET_HA_PARMS 0x05
  186387. #define SC_GET_DISK_INFO 0x06
  186388. #define SC_RESCAN_SCSI_BUS 0x07
  186389. #define SC_GETSET_TIMEOUTS 0x08
  186390. #define SS_PENDING 0x00
  186391. #define SS_COMP 0x01
  186392. #define SS_ABORTED 0x02
  186393. #define SS_ABORT_FAIL 0x03
  186394. #define SS_ERR 0x04
  186395. #define SS_INVALID_CMD 0x80
  186396. #define SS_INVALID_HA 0x81
  186397. #define SS_NO_DEVICE 0x82
  186398. #define SS_INVALID_SRB 0xE0
  186399. #define SS_OLD_MANAGER 0xE1
  186400. #define SS_BUFFER_ALIGN 0xE1
  186401. #define SS_ILLEGAL_MODE 0xE2
  186402. #define SS_NO_ASPI 0xE3
  186403. #define SS_FAILED_INIT 0xE4
  186404. #define SS_ASPI_IS_BUSY 0xE5
  186405. #define SS_BUFFER_TO_BIG 0xE6
  186406. #define SS_BUFFER_TOO_BIG 0xE6
  186407. #define SS_MISMATCHED_COMPONENTS 0xE7
  186408. #define SS_NO_ADAPTERS 0xE8
  186409. #define SS_INSUFFICIENT_RESOURCES 0xE9
  186410. #define SS_ASPI_IS_SHUTDOWN 0xEA
  186411. #define SS_BAD_INSTALL 0xEB
  186412. #define HASTAT_OK 0x00
  186413. #define HASTAT_SEL_TO 0x11
  186414. #define HASTAT_DO_DU 0x12
  186415. #define HASTAT_BUS_FREE 0x13
  186416. #define HASTAT_PHASE_ERR 0x14
  186417. #define HASTAT_TIMEOUT 0x09
  186418. #define HASTAT_COMMAND_TIMEOUT 0x0B
  186419. #define HASTAT_MESSAGE_REJECT 0x0D
  186420. #define HASTAT_BUS_RESET 0x0E
  186421. #define HASTAT_PARITY_ERROR 0x0F
  186422. #define HASTAT_REQUEST_SENSE_FAILED 0x10
  186423. #define PACKED
  186424. #pragma pack(1)
  186425. typedef struct
  186426. {
  186427. BYTE SRB_Cmd;
  186428. BYTE SRB_Status;
  186429. BYTE SRB_HaID;
  186430. BYTE SRB_Flags;
  186431. DWORD SRB_Hdr_Rsvd;
  186432. BYTE HA_Count;
  186433. BYTE HA_SCSI_ID;
  186434. BYTE HA_ManagerId[16];
  186435. BYTE HA_Identifier[16];
  186436. BYTE HA_Unique[16];
  186437. WORD HA_Rsvd1;
  186438. BYTE pad[20];
  186439. } PACKED SRB_HAInquiry, *PSRB_HAInquiry, FAR *LPSRB_HAInquiry;
  186440. typedef struct
  186441. {
  186442. BYTE SRB_Cmd;
  186443. BYTE SRB_Status;
  186444. BYTE SRB_HaID;
  186445. BYTE SRB_Flags;
  186446. DWORD SRB_Hdr_Rsvd;
  186447. BYTE SRB_Target;
  186448. BYTE SRB_Lun;
  186449. BYTE SRB_DeviceType;
  186450. BYTE SRB_Rsvd1;
  186451. BYTE pad[68];
  186452. } PACKED SRB_GDEVBlock, *PSRB_GDEVBlock, FAR *LPSRB_GDEVBlock;
  186453. typedef struct
  186454. {
  186455. BYTE SRB_Cmd;
  186456. BYTE SRB_Status;
  186457. BYTE SRB_HaID;
  186458. BYTE SRB_Flags;
  186459. DWORD SRB_Hdr_Rsvd;
  186460. BYTE SRB_Target;
  186461. BYTE SRB_Lun;
  186462. WORD SRB_Rsvd1;
  186463. DWORD SRB_BufLen;
  186464. BYTE FAR *SRB_BufPointer;
  186465. BYTE SRB_SenseLen;
  186466. BYTE SRB_CDBLen;
  186467. BYTE SRB_HaStat;
  186468. BYTE SRB_TargStat;
  186469. VOID FAR *SRB_PostProc;
  186470. BYTE SRB_Rsvd2[20];
  186471. BYTE CDBByte[16];
  186472. BYTE SenseArea[SENSE_LEN+2];
  186473. } PACKED SRB_ExecSCSICmd, *PSRB_ExecSCSICmd, FAR *LPSRB_ExecSCSICmd;
  186474. typedef struct
  186475. {
  186476. BYTE SRB_Cmd;
  186477. BYTE SRB_Status;
  186478. BYTE SRB_HaId;
  186479. BYTE SRB_Flags;
  186480. DWORD SRB_Hdr_Rsvd;
  186481. } PACKED SRB, *PSRB, FAR *LPSRB;
  186482. #pragma pack()
  186483. struct CDDeviceInfo
  186484. {
  186485. char vendor[9];
  186486. char productId[17];
  186487. char rev[5];
  186488. char vendorSpec[21];
  186489. BYTE ha;
  186490. BYTE tgt;
  186491. BYTE lun;
  186492. char scsiDriveLetter; // will be 0 if not using scsi
  186493. };
  186494. class CDReadBuffer
  186495. {
  186496. public:
  186497. int startFrame;
  186498. int numFrames;
  186499. int dataStartOffset;
  186500. int dataLength;
  186501. BYTE* buffer;
  186502. int bufferSize;
  186503. int index;
  186504. bool wantsIndex;
  186505. CDReadBuffer (const int numberOfFrames)
  186506. : startFrame (0),
  186507. numFrames (0),
  186508. dataStartOffset (0),
  186509. dataLength (0),
  186510. index (0),
  186511. wantsIndex (false)
  186512. {
  186513. bufferSize = 2352 * numberOfFrames;
  186514. buffer = (BYTE*) malloc (bufferSize);
  186515. }
  186516. ~CDReadBuffer()
  186517. {
  186518. free (buffer);
  186519. }
  186520. bool isZero() const
  186521. {
  186522. BYTE* p = buffer + dataStartOffset;
  186523. for (int i = dataLength; --i >= 0;)
  186524. if (*p++ != 0)
  186525. return false;
  186526. return true;
  186527. }
  186528. };
  186529. class CDDeviceHandle;
  186530. class CDController
  186531. {
  186532. public:
  186533. CDController();
  186534. virtual ~CDController();
  186535. virtual bool read (CDReadBuffer* t) = 0;
  186536. virtual void shutDown();
  186537. bool readAudio (CDReadBuffer* t, CDReadBuffer* overlapBuffer = 0);
  186538. int getLastIndex();
  186539. public:
  186540. bool initialised;
  186541. CDDeviceHandle* deviceInfo;
  186542. int framesToCheck, framesOverlap;
  186543. void prepare (SRB_ExecSCSICmd& s);
  186544. void perform (SRB_ExecSCSICmd& s);
  186545. void setPaused (bool paused);
  186546. };
  186547. #pragma pack(1)
  186548. struct TOCTRACK
  186549. {
  186550. BYTE rsvd;
  186551. BYTE ADR;
  186552. BYTE trackNumber;
  186553. BYTE rsvd2;
  186554. BYTE addr[4];
  186555. };
  186556. struct TOC
  186557. {
  186558. WORD tocLen;
  186559. BYTE firstTrack;
  186560. BYTE lastTrack;
  186561. TOCTRACK tracks[100];
  186562. };
  186563. #pragma pack()
  186564. enum
  186565. {
  186566. READTYPE_ANY = 0,
  186567. READTYPE_ATAPI1 = 1,
  186568. READTYPE_ATAPI2 = 2,
  186569. READTYPE_READ6 = 3,
  186570. READTYPE_READ10 = 4,
  186571. READTYPE_READ_D8 = 5,
  186572. READTYPE_READ_D4 = 6,
  186573. READTYPE_READ_D4_1 = 7,
  186574. READTYPE_READ10_2 = 8
  186575. };
  186576. class CDDeviceHandle
  186577. {
  186578. public:
  186579. CDDeviceHandle (const CDDeviceInfo* const device)
  186580. : scsiHandle (0),
  186581. readType (READTYPE_ANY),
  186582. controller (0)
  186583. {
  186584. memcpy (&info, device, sizeof (info));
  186585. }
  186586. ~CDDeviceHandle()
  186587. {
  186588. if (controller != 0)
  186589. {
  186590. controller->shutDown();
  186591. delete controller;
  186592. }
  186593. if (scsiHandle != 0)
  186594. CloseHandle (scsiHandle);
  186595. }
  186596. bool readTOC (TOC* lpToc, bool useMSF);
  186597. bool readAudio (CDReadBuffer* buffer, CDReadBuffer* overlapBuffer = 0);
  186598. void openDrawer (bool shouldBeOpen);
  186599. CDDeviceInfo info;
  186600. HANDLE scsiHandle;
  186601. BYTE readType;
  186602. private:
  186603. CDController* controller;
  186604. bool testController (const int readType,
  186605. CDController* const newController,
  186606. CDReadBuffer* const bufferToUse);
  186607. };
  186608. DWORD (*fGetASPI32SupportInfo)(void);
  186609. DWORD (*fSendASPI32Command)(LPSRB);
  186610. static HINSTANCE winAspiLib = 0;
  186611. static bool usingScsi = false;
  186612. static bool initialised = false;
  186613. static bool InitialiseCDRipper()
  186614. {
  186615. if (! initialised)
  186616. {
  186617. initialised = true;
  186618. OSVERSIONINFO info;
  186619. info.dwOSVersionInfoSize = sizeof (info);
  186620. GetVersionEx (&info);
  186621. usingScsi = (info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4);
  186622. if (! usingScsi)
  186623. {
  186624. fGetASPI32SupportInfo = 0;
  186625. fSendASPI32Command = 0;
  186626. winAspiLib = LoadLibrary (_T("WNASPI32.DLL"));
  186627. if (winAspiLib != 0)
  186628. {
  186629. fGetASPI32SupportInfo = (DWORD(*)(void)) GetProcAddress (winAspiLib, "GetASPI32SupportInfo");
  186630. fSendASPI32Command = (DWORD(*)(LPSRB)) GetProcAddress (winAspiLib, "SendASPI32Command");
  186631. if (fGetASPI32SupportInfo == 0 || fSendASPI32Command == 0)
  186632. return false;
  186633. }
  186634. else
  186635. {
  186636. usingScsi = true;
  186637. }
  186638. }
  186639. }
  186640. return true;
  186641. }
  186642. static void DeinitialiseCDRipper()
  186643. {
  186644. if (winAspiLib != 0)
  186645. {
  186646. fGetASPI32SupportInfo = 0;
  186647. fSendASPI32Command = 0;
  186648. FreeLibrary (winAspiLib);
  186649. winAspiLib = 0;
  186650. }
  186651. initialised = false;
  186652. }
  186653. static HANDLE CreateSCSIDeviceHandle (char driveLetter)
  186654. {
  186655. TCHAR devicePath[8];
  186656. devicePath[0] = '\\';
  186657. devicePath[1] = '\\';
  186658. devicePath[2] = '.';
  186659. devicePath[3] = '\\';
  186660. devicePath[4] = driveLetter;
  186661. devicePath[5] = ':';
  186662. devicePath[6] = 0;
  186663. OSVERSIONINFO info;
  186664. info.dwOSVersionInfoSize = sizeof (info);
  186665. GetVersionEx (&info);
  186666. DWORD flags = GENERIC_READ;
  186667. if ((info.dwPlatformId == VER_PLATFORM_WIN32_NT) && (info.dwMajorVersion > 4))
  186668. flags = GENERIC_READ | GENERIC_WRITE;
  186669. HANDLE h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186670. if (h == INVALID_HANDLE_VALUE)
  186671. {
  186672. flags ^= GENERIC_WRITE;
  186673. h = CreateFile (devicePath, flags, FILE_SHARE_WRITE | FILE_SHARE_READ, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
  186674. }
  186675. return h;
  186676. }
  186677. static DWORD performScsiPassThroughCommand (const LPSRB_ExecSCSICmd srb,
  186678. const char driveLetter,
  186679. HANDLE& deviceHandle,
  186680. const bool retryOnFailure = true)
  186681. {
  186682. SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER s;
  186683. zerostruct (s);
  186684. s.spt.Length = sizeof (SCSI_PASS_THROUGH);
  186685. s.spt.CdbLength = srb->SRB_CDBLen;
  186686. s.spt.DataIn = (BYTE) ((srb->SRB_Flags & SRB_DIR_IN)
  186687. ? SCSI_IOCTL_DATA_IN
  186688. : ((srb->SRB_Flags & SRB_DIR_OUT)
  186689. ? SCSI_IOCTL_DATA_OUT
  186690. : SCSI_IOCTL_DATA_UNSPECIFIED));
  186691. s.spt.DataTransferLength = srb->SRB_BufLen;
  186692. s.spt.TimeOutValue = 5;
  186693. s.spt.DataBuffer = srb->SRB_BufPointer;
  186694. s.spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  186695. memcpy (s.spt.Cdb, srb->CDBByte, srb->SRB_CDBLen);
  186696. srb->SRB_Status = SS_ERR;
  186697. srb->SRB_TargStat = 0x0004;
  186698. DWORD bytesReturned = 0;
  186699. if (DeviceIoControl (deviceHandle, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  186700. &s, sizeof (s),
  186701. &s, sizeof (s),
  186702. &bytesReturned, 0) != 0)
  186703. {
  186704. srb->SRB_Status = SS_COMP;
  186705. }
  186706. else if (retryOnFailure)
  186707. {
  186708. const DWORD error = GetLastError();
  186709. if ((error == ERROR_MEDIA_CHANGED) || (error == ERROR_INVALID_HANDLE))
  186710. {
  186711. if (error != ERROR_INVALID_HANDLE)
  186712. CloseHandle (deviceHandle);
  186713. deviceHandle = CreateSCSIDeviceHandle (driveLetter);
  186714. return performScsiPassThroughCommand (srb, driveLetter, deviceHandle, false);
  186715. }
  186716. }
  186717. return srb->SRB_Status;
  186718. }
  186719. // Controller types..
  186720. class ControllerType1 : public CDController
  186721. {
  186722. public:
  186723. ControllerType1() {}
  186724. ~ControllerType1() {}
  186725. bool read (CDReadBuffer* rb)
  186726. {
  186727. if (rb->numFrames * 2352 > rb->bufferSize)
  186728. return false;
  186729. SRB_ExecSCSICmd s;
  186730. prepare (s);
  186731. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186732. s.SRB_BufLen = rb->bufferSize;
  186733. s.SRB_BufPointer = rb->buffer;
  186734. s.SRB_CDBLen = 12;
  186735. s.CDBByte[0] = 0xBE;
  186736. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186737. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186738. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186739. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186740. s.CDBByte[9] = (BYTE)((deviceInfo->readType == READTYPE_ATAPI1) ? 0x10 : 0xF0);
  186741. perform (s);
  186742. if (s.SRB_Status != SS_COMP)
  186743. return false;
  186744. rb->dataLength = rb->numFrames * 2352;
  186745. rb->dataStartOffset = 0;
  186746. return true;
  186747. }
  186748. };
  186749. class ControllerType2 : public CDController
  186750. {
  186751. public:
  186752. ControllerType2() {}
  186753. ~ControllerType2() {}
  186754. void shutDown()
  186755. {
  186756. if (initialised)
  186757. {
  186758. BYTE bufPointer[] = { 0, 0, 0, 8, 83, 0, 0, 0, 0, 0, 8, 0 };
  186759. SRB_ExecSCSICmd s;
  186760. prepare (s);
  186761. s.SRB_Flags = SRB_EVENT_NOTIFY | SRB_ENABLE_RESIDUAL_COUNT;
  186762. s.SRB_BufLen = 0x0C;
  186763. s.SRB_BufPointer = bufPointer;
  186764. s.SRB_CDBLen = 6;
  186765. s.CDBByte[0] = 0x15;
  186766. s.CDBByte[4] = 0x0C;
  186767. perform (s);
  186768. }
  186769. }
  186770. bool init()
  186771. {
  186772. SRB_ExecSCSICmd s;
  186773. s.SRB_Status = SS_ERR;
  186774. if (deviceInfo->readType == READTYPE_READ10_2)
  186775. {
  186776. BYTE bufPointer1[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 35, 6, 0, 0, 0, 0, 0, 128 };
  186777. BYTE bufPointer2[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48, 1, 6, 32, 7, 0, 0, 0, 0 };
  186778. for (int i = 0; i < 2; ++i)
  186779. {
  186780. prepare (s);
  186781. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186782. s.SRB_BufLen = 0x14;
  186783. s.SRB_BufPointer = (i == 0) ? bufPointer1 : bufPointer2;
  186784. s.SRB_CDBLen = 6;
  186785. s.CDBByte[0] = 0x15;
  186786. s.CDBByte[1] = 0x10;
  186787. s.CDBByte[4] = 0x14;
  186788. perform (s);
  186789. if (s.SRB_Status != SS_COMP)
  186790. return false;
  186791. }
  186792. }
  186793. else
  186794. {
  186795. BYTE bufPointer[] = { 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 9, 48 };
  186796. prepare (s);
  186797. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186798. s.SRB_BufLen = 0x0C;
  186799. s.SRB_BufPointer = bufPointer;
  186800. s.SRB_CDBLen = 6;
  186801. s.CDBByte[0] = 0x15;
  186802. s.CDBByte[4] = 0x0C;
  186803. perform (s);
  186804. }
  186805. return s.SRB_Status == SS_COMP;
  186806. }
  186807. bool read (CDReadBuffer* rb)
  186808. {
  186809. if (rb->numFrames * 2352 > rb->bufferSize)
  186810. return false;
  186811. if (!initialised)
  186812. {
  186813. initialised = init();
  186814. if (!initialised)
  186815. return false;
  186816. }
  186817. SRB_ExecSCSICmd s;
  186818. prepare (s);
  186819. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186820. s.SRB_BufLen = rb->bufferSize;
  186821. s.SRB_BufPointer = rb->buffer;
  186822. s.SRB_CDBLen = 10;
  186823. s.CDBByte[0] = 0x28;
  186824. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  186825. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186826. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186827. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186828. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186829. perform (s);
  186830. if (s.SRB_Status != SS_COMP)
  186831. return false;
  186832. rb->dataLength = rb->numFrames * 2352;
  186833. rb->dataStartOffset = 0;
  186834. return true;
  186835. }
  186836. };
  186837. class ControllerType3 : public CDController
  186838. {
  186839. public:
  186840. ControllerType3() {}
  186841. ~ControllerType3() {}
  186842. bool read (CDReadBuffer* rb)
  186843. {
  186844. if (rb->numFrames * 2352 > rb->bufferSize)
  186845. return false;
  186846. if (!initialised)
  186847. {
  186848. setPaused (false);
  186849. initialised = true;
  186850. }
  186851. SRB_ExecSCSICmd s;
  186852. prepare (s);
  186853. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186854. s.SRB_BufLen = rb->numFrames * 2352;
  186855. s.SRB_BufPointer = rb->buffer;
  186856. s.SRB_CDBLen = 12;
  186857. s.CDBByte[0] = 0xD8;
  186858. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186859. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186860. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186861. s.CDBByte[9] = (BYTE)(rb->numFrames & 0xFF);
  186862. perform (s);
  186863. if (s.SRB_Status != SS_COMP)
  186864. return false;
  186865. rb->dataLength = rb->numFrames * 2352;
  186866. rb->dataStartOffset = 0;
  186867. return true;
  186868. }
  186869. };
  186870. class ControllerType4 : public CDController
  186871. {
  186872. public:
  186873. ControllerType4() {}
  186874. ~ControllerType4() {}
  186875. bool selectD4Mode()
  186876. {
  186877. BYTE bufPointer[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 9, 48 };
  186878. SRB_ExecSCSICmd s;
  186879. prepare (s);
  186880. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186881. s.SRB_CDBLen = 6;
  186882. s.SRB_BufLen = 12;
  186883. s.SRB_BufPointer = bufPointer;
  186884. s.CDBByte[0] = 0x15;
  186885. s.CDBByte[1] = 0x10;
  186886. s.CDBByte[4] = 0x08;
  186887. perform (s);
  186888. return s.SRB_Status == SS_COMP;
  186889. }
  186890. bool read (CDReadBuffer* rb)
  186891. {
  186892. if (rb->numFrames * 2352 > rb->bufferSize)
  186893. return false;
  186894. if (!initialised)
  186895. {
  186896. setPaused (true);
  186897. if (deviceInfo->readType == READTYPE_READ_D4_1)
  186898. selectD4Mode();
  186899. initialised = true;
  186900. }
  186901. SRB_ExecSCSICmd s;
  186902. prepare (s);
  186903. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  186904. s.SRB_BufLen = rb->bufferSize;
  186905. s.SRB_BufPointer = rb->buffer;
  186906. s.SRB_CDBLen = 10;
  186907. s.CDBByte[0] = 0xD4;
  186908. s.CDBByte[3] = (BYTE)((rb->startFrame >> 16) & 0xFF);
  186909. s.CDBByte[4] = (BYTE)((rb->startFrame >> 8) & 0xFF);
  186910. s.CDBByte[5] = (BYTE)(rb->startFrame & 0xFF);
  186911. s.CDBByte[8] = (BYTE)(rb->numFrames & 0xFF);
  186912. perform (s);
  186913. if (s.SRB_Status != SS_COMP)
  186914. return false;
  186915. rb->dataLength = rb->numFrames * 2352;
  186916. rb->dataStartOffset = 0;
  186917. return true;
  186918. }
  186919. };
  186920. CDController::CDController() : initialised (false)
  186921. {
  186922. }
  186923. CDController::~CDController()
  186924. {
  186925. }
  186926. void CDController::prepare (SRB_ExecSCSICmd& s)
  186927. {
  186928. zerostruct (s);
  186929. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  186930. s.SRB_HaID = deviceInfo->info.ha;
  186931. s.SRB_Target = deviceInfo->info.tgt;
  186932. s.SRB_Lun = deviceInfo->info.lun;
  186933. s.SRB_SenseLen = SENSE_LEN;
  186934. }
  186935. void CDController::perform (SRB_ExecSCSICmd& s)
  186936. {
  186937. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  186938. s.SRB_PostProc = (void*)event;
  186939. ResetEvent (event);
  186940. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s,
  186941. deviceInfo->info.scsiDriveLetter,
  186942. deviceInfo->scsiHandle)
  186943. : fSendASPI32Command ((LPSRB)&s);
  186944. if (status == SS_PENDING)
  186945. WaitForSingleObject (event, 4000);
  186946. CloseHandle (event);
  186947. }
  186948. void CDController::setPaused (bool paused)
  186949. {
  186950. SRB_ExecSCSICmd s;
  186951. prepare (s);
  186952. s.SRB_Flags = SRB_EVENT_NOTIFY;
  186953. s.SRB_CDBLen = 10;
  186954. s.CDBByte[0] = 0x4B;
  186955. s.CDBByte[8] = (BYTE) (paused ? 0 : 1);
  186956. perform (s);
  186957. }
  186958. void CDController::shutDown()
  186959. {
  186960. }
  186961. bool CDController::readAudio (CDReadBuffer* rb, CDReadBuffer* overlapBuffer)
  186962. {
  186963. if (overlapBuffer != 0)
  186964. {
  186965. const bool canDoJitter = (overlapBuffer->bufferSize >= 2352 * framesToCheck);
  186966. const bool doJitter = canDoJitter && ! overlapBuffer->isZero();
  186967. if (doJitter
  186968. && overlapBuffer->startFrame > 0
  186969. && overlapBuffer->numFrames > 0
  186970. && overlapBuffer->dataLength > 0)
  186971. {
  186972. const int numFrames = rb->numFrames;
  186973. if (overlapBuffer->startFrame == (rb->startFrame - framesToCheck))
  186974. {
  186975. rb->startFrame -= framesOverlap;
  186976. if (framesToCheck < framesOverlap
  186977. && numFrames + framesOverlap <= rb->bufferSize / 2352)
  186978. rb->numFrames += framesOverlap;
  186979. }
  186980. else
  186981. {
  186982. overlapBuffer->dataLength = 0;
  186983. overlapBuffer->startFrame = 0;
  186984. overlapBuffer->numFrames = 0;
  186985. }
  186986. }
  186987. if (! read (rb))
  186988. return false;
  186989. if (doJitter)
  186990. {
  186991. const int checkLen = framesToCheck * 2352;
  186992. const int maxToCheck = rb->dataLength - checkLen;
  186993. if (overlapBuffer->dataLength == 0 || overlapBuffer->isZero())
  186994. return true;
  186995. BYTE* const p = overlapBuffer->buffer + overlapBuffer->dataStartOffset;
  186996. bool found = false;
  186997. for (int i = 0; i < maxToCheck; ++i)
  186998. {
  186999. if (!memcmp (p, rb->buffer + i, checkLen))
  187000. {
  187001. i += checkLen;
  187002. rb->dataStartOffset = i;
  187003. rb->dataLength -= i;
  187004. rb->startFrame = overlapBuffer->startFrame + framesToCheck;
  187005. found = true;
  187006. break;
  187007. }
  187008. }
  187009. rb->numFrames = rb->dataLength / 2352;
  187010. rb->dataLength = 2352 * rb->numFrames;
  187011. if (!found)
  187012. return false;
  187013. }
  187014. if (canDoJitter)
  187015. {
  187016. memcpy (overlapBuffer->buffer,
  187017. rb->buffer + rb->dataStartOffset + 2352 * (rb->numFrames - framesToCheck),
  187018. 2352 * framesToCheck);
  187019. overlapBuffer->startFrame = rb->startFrame + rb->numFrames - framesToCheck;
  187020. overlapBuffer->numFrames = framesToCheck;
  187021. overlapBuffer->dataLength = 2352 * framesToCheck;
  187022. overlapBuffer->dataStartOffset = 0;
  187023. }
  187024. else
  187025. {
  187026. overlapBuffer->startFrame = 0;
  187027. overlapBuffer->numFrames = 0;
  187028. overlapBuffer->dataLength = 0;
  187029. }
  187030. return true;
  187031. }
  187032. else
  187033. {
  187034. return read (rb);
  187035. }
  187036. }
  187037. int CDController::getLastIndex()
  187038. {
  187039. char qdata[100];
  187040. SRB_ExecSCSICmd s;
  187041. prepare (s);
  187042. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187043. s.SRB_BufLen = sizeof (qdata);
  187044. s.SRB_BufPointer = (BYTE*)qdata;
  187045. s.SRB_CDBLen = 12;
  187046. s.CDBByte[0] = 0x42;
  187047. s.CDBByte[1] = (BYTE)(deviceInfo->info.lun << 5);
  187048. s.CDBByte[2] = 64;
  187049. s.CDBByte[3] = 1; // get current position
  187050. s.CDBByte[7] = 0;
  187051. s.CDBByte[8] = (BYTE)sizeof (qdata);
  187052. perform (s);
  187053. if (s.SRB_Status == SS_COMP)
  187054. return qdata[7];
  187055. return 0;
  187056. }
  187057. bool CDDeviceHandle::readTOC (TOC* lpToc, bool useMSF)
  187058. {
  187059. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187060. SRB_ExecSCSICmd s;
  187061. zerostruct (s);
  187062. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187063. s.SRB_HaID = info.ha;
  187064. s.SRB_Target = info.tgt;
  187065. s.SRB_Lun = info.lun;
  187066. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187067. s.SRB_BufLen = 0x324;
  187068. s.SRB_BufPointer = (BYTE*)lpToc;
  187069. s.SRB_SenseLen = 0x0E;
  187070. s.SRB_CDBLen = 0x0A;
  187071. s.SRB_PostProc = (void*)event;
  187072. s.CDBByte[0] = 0x43;
  187073. s.CDBByte[1] = (BYTE)(useMSF ? 0x02 : 0x00);
  187074. s.CDBByte[7] = 0x03;
  187075. s.CDBByte[8] = 0x24;
  187076. ResetEvent (event);
  187077. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  187078. : fSendASPI32Command ((LPSRB)&s);
  187079. if (status == SS_PENDING)
  187080. WaitForSingleObject (event, 4000);
  187081. CloseHandle (event);
  187082. return (s.SRB_Status == SS_COMP);
  187083. }
  187084. bool CDDeviceHandle::readAudio (CDReadBuffer* const buffer,
  187085. CDReadBuffer* const overlapBuffer)
  187086. {
  187087. if (controller == 0)
  187088. {
  187089. testController (READTYPE_ATAPI2, new ControllerType1(), buffer)
  187090. || testController (READTYPE_ATAPI1, new ControllerType1(), buffer)
  187091. || testController (READTYPE_READ10_2, new ControllerType2(), buffer)
  187092. || testController (READTYPE_READ10, new ControllerType2(), buffer)
  187093. || testController (READTYPE_READ_D8, new ControllerType3(), buffer)
  187094. || testController (READTYPE_READ_D4, new ControllerType4(), buffer)
  187095. || testController (READTYPE_READ_D4_1, new ControllerType4(), buffer);
  187096. }
  187097. buffer->index = 0;
  187098. if ((controller != 0)
  187099. && controller->readAudio (buffer, overlapBuffer))
  187100. {
  187101. if (buffer->wantsIndex)
  187102. buffer->index = controller->getLastIndex();
  187103. return true;
  187104. }
  187105. return false;
  187106. }
  187107. void CDDeviceHandle::openDrawer (bool shouldBeOpen)
  187108. {
  187109. if (shouldBeOpen)
  187110. {
  187111. if (controller != 0)
  187112. {
  187113. controller->shutDown();
  187114. delete controller;
  187115. controller = 0;
  187116. }
  187117. if (scsiHandle != 0)
  187118. {
  187119. CloseHandle (scsiHandle);
  187120. scsiHandle = 0;
  187121. }
  187122. }
  187123. SRB_ExecSCSICmd s;
  187124. zerostruct (s);
  187125. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187126. s.SRB_HaID = info.ha;
  187127. s.SRB_Target = info.tgt;
  187128. s.SRB_Lun = info.lun;
  187129. s.SRB_SenseLen = SENSE_LEN;
  187130. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187131. s.SRB_BufLen = 0;
  187132. s.SRB_BufPointer = 0;
  187133. s.SRB_CDBLen = 12;
  187134. s.CDBByte[0] = 0x1b;
  187135. s.CDBByte[1] = (BYTE)(info.lun << 5);
  187136. s.CDBByte[4] = (BYTE)((shouldBeOpen) ? 2 : 3);
  187137. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187138. s.SRB_PostProc = (void*)event;
  187139. ResetEvent (event);
  187140. DWORD status = (usingScsi) ? performScsiPassThroughCommand ((LPSRB_ExecSCSICmd)&s, info.scsiDriveLetter, scsiHandle)
  187141. : fSendASPI32Command ((LPSRB)&s);
  187142. if (status == SS_PENDING)
  187143. WaitForSingleObject (event, 4000);
  187144. CloseHandle (event);
  187145. }
  187146. bool CDDeviceHandle::testController (const int type,
  187147. CDController* const newController,
  187148. CDReadBuffer* const rb)
  187149. {
  187150. controller = newController;
  187151. readType = (BYTE)type;
  187152. controller->deviceInfo = this;
  187153. controller->framesToCheck = 1;
  187154. controller->framesOverlap = 3;
  187155. bool passed = false;
  187156. memset (rb->buffer, 0xcd, rb->bufferSize);
  187157. if (controller->read (rb))
  187158. {
  187159. passed = true;
  187160. int* p = (int*) (rb->buffer + rb->dataStartOffset);
  187161. int wrong = 0;
  187162. for (int i = rb->dataLength / 4; --i >= 0;)
  187163. {
  187164. if (*p++ == (int) 0xcdcdcdcd)
  187165. {
  187166. if (++wrong == 4)
  187167. {
  187168. passed = false;
  187169. break;
  187170. }
  187171. }
  187172. else
  187173. {
  187174. wrong = 0;
  187175. }
  187176. }
  187177. }
  187178. if (! passed)
  187179. {
  187180. controller->shutDown();
  187181. delete controller;
  187182. controller = 0;
  187183. }
  187184. return passed;
  187185. }
  187186. static void GetAspiDeviceInfo (CDDeviceInfo* dev, BYTE ha, BYTE tgt, BYTE lun)
  187187. {
  187188. HANDLE event = CreateEvent (0, TRUE, FALSE, 0);
  187189. const int bufSize = 128;
  187190. BYTE buffer[bufSize];
  187191. zeromem (buffer, bufSize);
  187192. SRB_ExecSCSICmd s;
  187193. zerostruct (s);
  187194. s.SRB_Cmd = SC_EXEC_SCSI_CMD;
  187195. s.SRB_HaID = ha;
  187196. s.SRB_Target = tgt;
  187197. s.SRB_Lun = lun;
  187198. s.SRB_Flags = SRB_DIR_IN | SRB_EVENT_NOTIFY;
  187199. s.SRB_BufLen = bufSize;
  187200. s.SRB_BufPointer = buffer;
  187201. s.SRB_SenseLen = SENSE_LEN;
  187202. s.SRB_CDBLen = 6;
  187203. s.SRB_PostProc = (void*)event;
  187204. s.CDBByte[0] = SCSI_INQUIRY;
  187205. s.CDBByte[4] = 100;
  187206. ResetEvent (event);
  187207. if (fSendASPI32Command ((LPSRB)&s) == SS_PENDING)
  187208. WaitForSingleObject (event, 4000);
  187209. CloseHandle (event);
  187210. if (s.SRB_Status == SS_COMP)
  187211. {
  187212. memcpy (dev->vendor, &buffer[8], 8);
  187213. memcpy (dev->productId, &buffer[16], 16);
  187214. memcpy (dev->rev, &buffer[32], 4);
  187215. memcpy (dev->vendorSpec, &buffer[36], 20);
  187216. }
  187217. }
  187218. static int FindCDDevices (CDDeviceInfo* const list,
  187219. int maxItems)
  187220. {
  187221. int count = 0;
  187222. if (usingScsi)
  187223. {
  187224. for (char driveLetter = 'b'; driveLetter <= 'z'; ++driveLetter)
  187225. {
  187226. TCHAR drivePath[8];
  187227. drivePath[0] = driveLetter;
  187228. drivePath[1] = ':';
  187229. drivePath[2] = '\\';
  187230. drivePath[3] = 0;
  187231. if (GetDriveType (drivePath) == DRIVE_CDROM)
  187232. {
  187233. HANDLE h = CreateSCSIDeviceHandle (driveLetter);
  187234. if (h != INVALID_HANDLE_VALUE)
  187235. {
  187236. BYTE buffer[100], passThroughStruct[1024];
  187237. zeromem (buffer, sizeof (buffer));
  187238. zeromem (passThroughStruct, sizeof (passThroughStruct));
  187239. PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER p = (PSCSI_PASS_THROUGH_DIRECT_WITH_BUFFER)passThroughStruct;
  187240. p->spt.Length = sizeof (SCSI_PASS_THROUGH);
  187241. p->spt.CdbLength = 6;
  187242. p->spt.SenseInfoLength = 24;
  187243. p->spt.DataIn = SCSI_IOCTL_DATA_IN;
  187244. p->spt.DataTransferLength = 100;
  187245. p->spt.TimeOutValue = 2;
  187246. p->spt.DataBuffer = buffer;
  187247. p->spt.SenseInfoOffset = offsetof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER, ucSenseBuf);
  187248. p->spt.Cdb[0] = 0x12;
  187249. p->spt.Cdb[4] = 100;
  187250. DWORD bytesReturned = 0;
  187251. if (DeviceIoControl (h, IOCTL_SCSI_PASS_THROUGH_DIRECT,
  187252. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  187253. p, sizeof (SCSI_PASS_THROUGH_DIRECT_WITH_BUFFER),
  187254. &bytesReturned, 0) != 0)
  187255. {
  187256. zeromem (&list[count], sizeof (CDDeviceInfo));
  187257. list[count].scsiDriveLetter = driveLetter;
  187258. memcpy (list[count].vendor, &buffer[8], 8);
  187259. memcpy (list[count].productId, &buffer[16], 16);
  187260. memcpy (list[count].rev, &buffer[32], 4);
  187261. memcpy (list[count].vendorSpec, &buffer[36], 20);
  187262. zeromem (passThroughStruct, sizeof (passThroughStruct));
  187263. PSCSI_ADDRESS scsiAddr = (PSCSI_ADDRESS)passThroughStruct;
  187264. scsiAddr->Length = sizeof (SCSI_ADDRESS);
  187265. if (DeviceIoControl (h, IOCTL_SCSI_GET_ADDRESS,
  187266. 0, 0, scsiAddr, sizeof (SCSI_ADDRESS),
  187267. &bytesReturned, 0) != 0)
  187268. {
  187269. list[count].ha = scsiAddr->PortNumber;
  187270. list[count].tgt = scsiAddr->TargetId;
  187271. list[count].lun = scsiAddr->Lun;
  187272. ++count;
  187273. }
  187274. }
  187275. CloseHandle (h);
  187276. }
  187277. }
  187278. }
  187279. }
  187280. else
  187281. {
  187282. const DWORD d = fGetASPI32SupportInfo();
  187283. BYTE status = HIBYTE (LOWORD (d));
  187284. if (status != SS_COMP || status == SS_NO_ADAPTERS)
  187285. return 0;
  187286. const int numAdapters = LOBYTE (LOWORD (d));
  187287. for (BYTE ha = 0; ha < numAdapters; ++ha)
  187288. {
  187289. SRB_HAInquiry s;
  187290. zerostruct (s);
  187291. s.SRB_Cmd = SC_HA_INQUIRY;
  187292. s.SRB_HaID = ha;
  187293. fSendASPI32Command ((LPSRB)&s);
  187294. if (s.SRB_Status == SS_COMP)
  187295. {
  187296. maxItems = (int)s.HA_Unique[3];
  187297. if (maxItems == 0)
  187298. maxItems = 8;
  187299. for (BYTE tgt = 0; tgt < maxItems; ++tgt)
  187300. {
  187301. for (BYTE lun = 0; lun < 8; ++lun)
  187302. {
  187303. SRB_GDEVBlock sb;
  187304. zerostruct (sb);
  187305. sb.SRB_Cmd = SC_GET_DEV_TYPE;
  187306. sb.SRB_HaID = ha;
  187307. sb.SRB_Target = tgt;
  187308. sb.SRB_Lun = lun;
  187309. fSendASPI32Command ((LPSRB) &sb);
  187310. if (sb.SRB_Status == SS_COMP
  187311. && sb.SRB_DeviceType == DTYPE_CROM)
  187312. {
  187313. zeromem (&list[count], sizeof (CDDeviceInfo));
  187314. list[count].ha = ha;
  187315. list[count].tgt = tgt;
  187316. list[count].lun = lun;
  187317. GetAspiDeviceInfo (&(list[count]), ha, tgt, lun);
  187318. ++count;
  187319. }
  187320. }
  187321. }
  187322. }
  187323. }
  187324. }
  187325. return count;
  187326. }
  187327. static int ripperUsers = 0;
  187328. static bool initialisedOk = false;
  187329. class DeinitialiseTimer : private Timer,
  187330. private DeletedAtShutdown
  187331. {
  187332. DeinitialiseTimer (const DeinitialiseTimer&);
  187333. DeinitialiseTimer& operator= (const DeinitialiseTimer&);
  187334. public:
  187335. DeinitialiseTimer()
  187336. {
  187337. startTimer (4000);
  187338. }
  187339. ~DeinitialiseTimer()
  187340. {
  187341. if (--ripperUsers == 0)
  187342. DeinitialiseCDRipper();
  187343. }
  187344. void timerCallback()
  187345. {
  187346. delete this;
  187347. }
  187348. juce_UseDebuggingNewOperator
  187349. };
  187350. static void incUserCount()
  187351. {
  187352. if (ripperUsers++ == 0)
  187353. initialisedOk = InitialiseCDRipper();
  187354. }
  187355. static void decUserCount()
  187356. {
  187357. new DeinitialiseTimer();
  187358. }
  187359. struct CDDeviceWrapper
  187360. {
  187361. CDDeviceHandle* cdH;
  187362. CDReadBuffer* overlapBuffer;
  187363. bool jitter;
  187364. };
  187365. static int getAddressOf (const TOCTRACK* const t)
  187366. {
  187367. return (((DWORD)t->addr[0]) << 24) + (((DWORD)t->addr[1]) << 16) +
  187368. (((DWORD)t->addr[2]) << 8) + ((DWORD)t->addr[3]);
  187369. }
  187370. static int getMSFAddressOf (const TOCTRACK* const t)
  187371. {
  187372. return 60 * t->addr[1] + t->addr[2];
  187373. }
  187374. static const int samplesPerFrame = 44100 / 75;
  187375. static const int bytesPerFrame = samplesPerFrame * 4;
  187376. const StringArray AudioCDReader::getAvailableCDNames()
  187377. {
  187378. StringArray results;
  187379. incUserCount();
  187380. if (initialisedOk)
  187381. {
  187382. CDDeviceInfo list[8];
  187383. const int num = FindCDDevices (list, 8);
  187384. decUserCount();
  187385. for (int i = 0; i < num; ++i)
  187386. {
  187387. String s;
  187388. if (list[i].scsiDriveLetter > 0)
  187389. s << String::charToString (list[i].scsiDriveLetter).toUpperCase() << T(": ");
  187390. s << String (list[i].vendor).trim()
  187391. << T(" ") << String (list[i].productId).trim()
  187392. << T(" ") << String (list[i].rev).trim();
  187393. results.add (s);
  187394. }
  187395. }
  187396. return results;
  187397. }
  187398. static CDDeviceHandle* openHandle (const CDDeviceInfo* const device)
  187399. {
  187400. SRB_GDEVBlock s;
  187401. zerostruct (s);
  187402. s.SRB_Cmd = SC_GET_DEV_TYPE;
  187403. s.SRB_HaID = device->ha;
  187404. s.SRB_Target = device->tgt;
  187405. s.SRB_Lun = device->lun;
  187406. if (usingScsi)
  187407. {
  187408. HANDLE h = CreateSCSIDeviceHandle (device->scsiDriveLetter);
  187409. if (h != INVALID_HANDLE_VALUE)
  187410. {
  187411. CDDeviceHandle* cdh = new CDDeviceHandle (device);
  187412. cdh->scsiHandle = h;
  187413. return cdh;
  187414. }
  187415. }
  187416. else
  187417. {
  187418. if (fSendASPI32Command ((LPSRB)&s) == SS_COMP
  187419. && s.SRB_DeviceType == DTYPE_CROM)
  187420. {
  187421. return new CDDeviceHandle (device);
  187422. }
  187423. }
  187424. return 0;
  187425. }
  187426. AudioCDReader* AudioCDReader::createReaderForCD (const int deviceIndex)
  187427. {
  187428. incUserCount();
  187429. if (initialisedOk)
  187430. {
  187431. CDDeviceInfo list[8];
  187432. const int num = FindCDDevices (list, 8);
  187433. if (((unsigned int) deviceIndex) < (unsigned int) num)
  187434. {
  187435. CDDeviceHandle* const handle = openHandle (&(list[deviceIndex]));
  187436. if (handle != 0)
  187437. {
  187438. CDDeviceWrapper* const d = new CDDeviceWrapper();
  187439. d->cdH = handle;
  187440. d->overlapBuffer = new CDReadBuffer(3);
  187441. return new AudioCDReader (d);
  187442. }
  187443. }
  187444. }
  187445. decUserCount();
  187446. return 0;
  187447. }
  187448. AudioCDReader::AudioCDReader (void* handle_)
  187449. : AudioFormatReader (0, T("CD Audio")),
  187450. handle (handle_),
  187451. indexingEnabled (false),
  187452. lastIndex (0),
  187453. firstFrameInBuffer (0),
  187454. samplesInBuffer (0)
  187455. {
  187456. jassert (handle_ != 0);
  187457. refreshTrackLengths();
  187458. sampleRate = 44100.0;
  187459. bitsPerSample = 16;
  187460. lengthInSamples = getPositionOfTrackStart (numTracks);
  187461. numChannels = 2;
  187462. usesFloatingPointData = false;
  187463. buffer.setSize (4 * bytesPerFrame, true);
  187464. }
  187465. AudioCDReader::~AudioCDReader()
  187466. {
  187467. CDDeviceWrapper* const device = (CDDeviceWrapper*)handle;
  187468. delete device->cdH;
  187469. delete device->overlapBuffer;
  187470. delete device;
  187471. decUserCount();
  187472. }
  187473. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  187474. int64 startSampleInFile, int numSamples)
  187475. {
  187476. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187477. bool ok = true;
  187478. while (numSamples > 0)
  187479. {
  187480. const int bufferStartSample = firstFrameInBuffer * samplesPerFrame;
  187481. const int bufferEndSample = bufferStartSample + samplesInBuffer;
  187482. if (startSampleInFile >= bufferStartSample
  187483. && startSampleInFile < bufferEndSample)
  187484. {
  187485. const int toDo = (int) jmin ((int64) numSamples, bufferEndSample - startSampleInFile);
  187486. int* const l = destSamples[0] + startOffsetInDestBuffer;
  187487. int* const r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187488. const short* src = (const short*) buffer.getData();
  187489. src += 2 * (startSampleInFile - bufferStartSample);
  187490. for (int i = 0; i < toDo; ++i)
  187491. {
  187492. l[i] = src [i << 1] << 16;
  187493. if (r != 0)
  187494. r[i] = src [(i << 1) + 1] << 16;
  187495. }
  187496. startOffsetInDestBuffer += toDo;
  187497. startSampleInFile += toDo;
  187498. numSamples -= toDo;
  187499. }
  187500. else
  187501. {
  187502. const int framesInBuffer = buffer.getSize() / bytesPerFrame;
  187503. const int frameNeeded = (int) (startSampleInFile / samplesPerFrame);
  187504. if (firstFrameInBuffer + framesInBuffer != frameNeeded)
  187505. {
  187506. device->overlapBuffer->dataLength = 0;
  187507. device->overlapBuffer->startFrame = 0;
  187508. device->overlapBuffer->numFrames = 0;
  187509. device->jitter = false;
  187510. }
  187511. firstFrameInBuffer = frameNeeded;
  187512. lastIndex = 0;
  187513. CDReadBuffer readBuffer (framesInBuffer + 4);
  187514. readBuffer.wantsIndex = indexingEnabled;
  187515. int i;
  187516. for (i = 5; --i >= 0;)
  187517. {
  187518. readBuffer.startFrame = frameNeeded;
  187519. readBuffer.numFrames = framesInBuffer;
  187520. if (device->cdH->readAudio (&readBuffer, (device->jitter) ? device->overlapBuffer : 0))
  187521. break;
  187522. else
  187523. device->overlapBuffer->dataLength = 0;
  187524. }
  187525. if (i >= 0)
  187526. {
  187527. memcpy ((char*) buffer.getData(),
  187528. readBuffer.buffer + readBuffer.dataStartOffset,
  187529. readBuffer.dataLength);
  187530. samplesInBuffer = readBuffer.dataLength >> 2;
  187531. lastIndex = readBuffer.index;
  187532. }
  187533. else
  187534. {
  187535. int* l = destSamples[0] + startOffsetInDestBuffer;
  187536. int* r = numDestChannels > 1 ? (destSamples[1] + startOffsetInDestBuffer) : 0;
  187537. while (--numSamples >= 0)
  187538. {
  187539. *l++ = 0;
  187540. if (r != 0)
  187541. *r++ = 0;
  187542. }
  187543. // sometimes the read fails for just the very last couple of blocks, so
  187544. // we'll ignore and errors in the last half-second of the disk..
  187545. ok = startSampleInFile > (trackStarts [numTracks] - 20000);
  187546. break;
  187547. }
  187548. }
  187549. }
  187550. return ok;
  187551. }
  187552. bool AudioCDReader::isCDStillPresent() const
  187553. {
  187554. TOC toc;
  187555. zerostruct (toc);
  187556. return ((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false);
  187557. }
  187558. int AudioCDReader::getNumTracks() const
  187559. {
  187560. return numTracks;
  187561. }
  187562. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  187563. {
  187564. return (trackNum >= 0 && trackNum <= numTracks) ? trackStarts [trackNum] * samplesPerFrame
  187565. : 0;
  187566. }
  187567. void AudioCDReader::refreshTrackLengths()
  187568. {
  187569. zeromem (trackStarts, sizeof (trackStarts));
  187570. zeromem (audioTracks, sizeof (audioTracks));
  187571. TOC toc;
  187572. zerostruct (toc);
  187573. if (((CDDeviceWrapper*)handle)->cdH->readTOC (&toc, false))
  187574. {
  187575. numTracks = 1 + toc.lastTrack - toc.firstTrack;
  187576. for (int i = 0; i <= numTracks; ++i)
  187577. {
  187578. trackStarts[i] = getAddressOf (&toc.tracks[i]);
  187579. audioTracks[i] = ((toc.tracks[i].ADR & 4) == 0);
  187580. }
  187581. }
  187582. else
  187583. {
  187584. numTracks = 0;
  187585. }
  187586. }
  187587. bool AudioCDReader::isTrackAudio (int trackNum) const
  187588. {
  187589. return (trackNum >= 0 && trackNum <= numTracks) ? audioTracks [trackNum]
  187590. : false;
  187591. }
  187592. void AudioCDReader::enableIndexScanning (bool b)
  187593. {
  187594. indexingEnabled = b;
  187595. }
  187596. int AudioCDReader::getLastIndex() const
  187597. {
  187598. return lastIndex;
  187599. }
  187600. const int framesPerIndexRead = 4;
  187601. int AudioCDReader::getIndexAt (int samplePos)
  187602. {
  187603. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187604. const int frameNeeded = samplePos / samplesPerFrame;
  187605. device->overlapBuffer->dataLength = 0;
  187606. device->overlapBuffer->startFrame = 0;
  187607. device->overlapBuffer->numFrames = 0;
  187608. device->jitter = false;
  187609. firstFrameInBuffer = 0;
  187610. lastIndex = 0;
  187611. CDReadBuffer readBuffer (4 + framesPerIndexRead);
  187612. readBuffer.wantsIndex = true;
  187613. int i;
  187614. for (i = 5; --i >= 0;)
  187615. {
  187616. readBuffer.startFrame = frameNeeded;
  187617. readBuffer.numFrames = framesPerIndexRead;
  187618. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187619. break;
  187620. }
  187621. if (i >= 0)
  187622. return readBuffer.index;
  187623. return -1;
  187624. }
  187625. const Array <int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  187626. {
  187627. Array <int> indexes;
  187628. const int trackStart = getPositionOfTrackStart (trackNumber);
  187629. const int trackEnd = getPositionOfTrackStart (trackNumber + 1);
  187630. bool needToScan = true;
  187631. if (trackEnd - trackStart > 20 * 44100)
  187632. {
  187633. // check the end of the track for indexes before scanning the whole thing
  187634. needToScan = false;
  187635. int pos = jmax (trackStart, trackEnd - 44100 * 5);
  187636. bool seenAnIndex = false;
  187637. while (pos <= trackEnd - samplesPerFrame)
  187638. {
  187639. const int index = getIndexAt (pos);
  187640. if (index == 0)
  187641. {
  187642. // lead-out, so skip back a bit if we've not found any indexes yet..
  187643. if (seenAnIndex)
  187644. break;
  187645. pos -= 44100 * 5;
  187646. if (pos < trackStart)
  187647. break;
  187648. }
  187649. else
  187650. {
  187651. if (index > 0)
  187652. seenAnIndex = true;
  187653. if (index > 1)
  187654. {
  187655. needToScan = true;
  187656. break;
  187657. }
  187658. pos += samplesPerFrame * framesPerIndexRead;
  187659. }
  187660. }
  187661. }
  187662. if (needToScan)
  187663. {
  187664. CDDeviceWrapper* const device = (CDDeviceWrapper*) handle;
  187665. int pos = trackStart;
  187666. int last = -1;
  187667. while (pos < trackEnd - samplesPerFrame * 10)
  187668. {
  187669. const int frameNeeded = pos / samplesPerFrame;
  187670. device->overlapBuffer->dataLength = 0;
  187671. device->overlapBuffer->startFrame = 0;
  187672. device->overlapBuffer->numFrames = 0;
  187673. device->jitter = false;
  187674. firstFrameInBuffer = 0;
  187675. CDReadBuffer readBuffer (4);
  187676. readBuffer.wantsIndex = true;
  187677. int i;
  187678. for (i = 5; --i >= 0;)
  187679. {
  187680. readBuffer.startFrame = frameNeeded;
  187681. readBuffer.numFrames = framesPerIndexRead;
  187682. if (device->cdH->readAudio (&readBuffer, (false) ? device->overlapBuffer : 0))
  187683. break;
  187684. }
  187685. if (i < 0)
  187686. break;
  187687. if (readBuffer.index > last && readBuffer.index > 1)
  187688. {
  187689. last = readBuffer.index;
  187690. indexes.add (pos);
  187691. }
  187692. pos += samplesPerFrame * framesPerIndexRead;
  187693. }
  187694. indexes.removeValue (trackStart);
  187695. }
  187696. return indexes;
  187697. }
  187698. int AudioCDReader::getCDDBId()
  187699. {
  187700. refreshTrackLengths();
  187701. if (numTracks > 0)
  187702. {
  187703. TOC toc;
  187704. zerostruct (toc);
  187705. if (((CDDeviceWrapper*) handle)->cdH->readTOC (&toc, true))
  187706. {
  187707. int n = 0;
  187708. for (int i = numTracks; --i >= 0;)
  187709. {
  187710. int j = getMSFAddressOf (&toc.tracks[i]);
  187711. while (j > 0)
  187712. {
  187713. n += (j % 10);
  187714. j /= 10;
  187715. }
  187716. }
  187717. if (n != 0)
  187718. {
  187719. const int t = getMSFAddressOf (&toc.tracks[numTracks])
  187720. - getMSFAddressOf (&toc.tracks[0]);
  187721. return ((n % 0xff) << 24) | (t << 8) | numTracks;
  187722. }
  187723. }
  187724. }
  187725. return 0;
  187726. }
  187727. void AudioCDReader::ejectDisk()
  187728. {
  187729. ((CDDeviceWrapper*) handle)->cdH->openDrawer (true);
  187730. }
  187731. #endif
  187732. #if JUCE_USE_CDBURNER
  187733. static IDiscRecorder* enumCDBurners (StringArray* list, int indexToOpen, IDiscMaster** master)
  187734. {
  187735. CoInitialize (0);
  187736. IDiscMaster* dm;
  187737. IDiscRecorder* result = 0;
  187738. if (SUCCEEDED (CoCreateInstance (CLSID_MSDiscMasterObj, 0,
  187739. CLSCTX_INPROC_SERVER | CLSCTX_LOCAL_SERVER,
  187740. IID_IDiscMaster,
  187741. (void**) &dm)))
  187742. {
  187743. if (SUCCEEDED (dm->Open()))
  187744. {
  187745. IEnumDiscRecorders* drEnum = 0;
  187746. if (SUCCEEDED (dm->EnumDiscRecorders (&drEnum)))
  187747. {
  187748. IDiscRecorder* dr = 0;
  187749. DWORD dummy;
  187750. int index = 0;
  187751. while (drEnum->Next (1, &dr, &dummy) == S_OK)
  187752. {
  187753. if (indexToOpen == index)
  187754. {
  187755. result = dr;
  187756. break;
  187757. }
  187758. else if (list != 0)
  187759. {
  187760. BSTR path;
  187761. if (SUCCEEDED (dr->GetPath (&path)))
  187762. list->add ((const WCHAR*) path);
  187763. }
  187764. ++index;
  187765. dr->Release();
  187766. }
  187767. drEnum->Release();
  187768. }
  187769. if (master == 0)
  187770. dm->Close();
  187771. }
  187772. if (master != 0)
  187773. *master = dm;
  187774. else
  187775. dm->Release();
  187776. }
  187777. return result;
  187778. }
  187779. class AudioCDBurner::Pimpl : public IDiscMasterProgressEvents,
  187780. public Timer
  187781. {
  187782. public:
  187783. Pimpl (AudioCDBurner& owner_, IDiscMaster* discMaster_, IDiscRecorder* discRecorder_)
  187784. : owner (owner_), discMaster (discMaster_), discRecorder (discRecorder_), redbook (0),
  187785. listener (0), progress (0), shouldCancel (false), refCount (1)
  187786. {
  187787. HRESULT hr = discMaster->SetActiveDiscMasterFormat (IID_IRedbookDiscMaster, (void**) &redbook);
  187788. jassert (SUCCEEDED (hr));
  187789. hr = discMaster->SetActiveDiscRecorder (discRecorder);
  187790. //jassert (SUCCEEDED (hr));
  187791. lastState = getDiskState();
  187792. startTimer (2000);
  187793. }
  187794. ~Pimpl() {}
  187795. void releaseObjects()
  187796. {
  187797. discRecorder->Close();
  187798. if (redbook != 0)
  187799. redbook->Release();
  187800. discRecorder->Release();
  187801. discMaster->Release();
  187802. Release();
  187803. }
  187804. HRESULT __stdcall QueryInterface (REFIID id, void __RPC_FAR* __RPC_FAR* result)
  187805. {
  187806. if (result == 0)
  187807. return E_POINTER;
  187808. if (id == IID_IUnknown || id == IID_IDiscMasterProgressEvents)
  187809. {
  187810. AddRef();
  187811. *result = this;
  187812. return S_OK;
  187813. }
  187814. *result = 0;
  187815. return E_NOINTERFACE;
  187816. }
  187817. ULONG __stdcall AddRef() { return ++refCount; }
  187818. ULONG __stdcall Release() { jassert (refCount > 0); const int r = --refCount; if (r == 0) delete this; return r; }
  187819. HRESULT __stdcall QueryCancel (boolean* pbCancel)
  187820. {
  187821. if (listener != 0 && ! shouldCancel)
  187822. shouldCancel = listener->audioCDBurnProgress (progress);
  187823. *pbCancel = shouldCancel;
  187824. return S_OK;
  187825. }
  187826. HRESULT __stdcall NotifyBlockProgress (long nCompleted, long nTotal)
  187827. {
  187828. progress = nCompleted / (float) nTotal;
  187829. shouldCancel = listener != 0 && listener->audioCDBurnProgress (progress);
  187830. return E_NOTIMPL;
  187831. }
  187832. HRESULT __stdcall NotifyPnPActivity (void) { return E_NOTIMPL; }
  187833. HRESULT __stdcall NotifyAddProgress (long /*nCompletedSteps*/, long /*nTotalSteps*/) { return E_NOTIMPL; }
  187834. HRESULT __stdcall NotifyTrackProgress (long /*nCurrentTrack*/, long /*nTotalTracks*/) { return E_NOTIMPL; }
  187835. HRESULT __stdcall NotifyPreparingBurn (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187836. HRESULT __stdcall NotifyClosingDisc (long /*nEstimatedSeconds*/) { return E_NOTIMPL; }
  187837. HRESULT __stdcall NotifyBurnComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187838. HRESULT __stdcall NotifyEraseComplete (HRESULT /*status*/) { return E_NOTIMPL; }
  187839. class ScopedDiscOpener
  187840. {
  187841. public:
  187842. ScopedDiscOpener (Pimpl& p) : pimpl (p) { pimpl.discRecorder->OpenExclusive(); }
  187843. ~ScopedDiscOpener() { pimpl.discRecorder->Close(); }
  187844. private:
  187845. Pimpl& pimpl;
  187846. };
  187847. DiskState getDiskState()
  187848. {
  187849. const ScopedDiscOpener opener (*this);
  187850. long type, flags;
  187851. HRESULT hr = discRecorder->QueryMediaType (&type, &flags);
  187852. if (FAILED (hr))
  187853. return unknown;
  187854. if (type != 0 && (flags & MEDIA_WRITABLE) != 0)
  187855. return writableDiskPresent;
  187856. if (type == 0)
  187857. return noDisc;
  187858. else
  187859. return readOnlyDiskPresent;
  187860. }
  187861. int getIntProperty (const LPOLESTR name, const int defaultReturn) const
  187862. {
  187863. ComSmartPtr<IPropertyStorage> prop;
  187864. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187865. return defaultReturn;
  187866. PROPSPEC iPropSpec;
  187867. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187868. iPropSpec.lpwstr = name;
  187869. PROPVARIANT iPropVariant;
  187870. return FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant))
  187871. ? defaultReturn : (int) iPropVariant.lVal;
  187872. }
  187873. bool setIntProperty (const LPOLESTR name, const int value) const
  187874. {
  187875. ComSmartPtr<IPropertyStorage> prop;
  187876. if (FAILED (discRecorder->GetRecorderProperties (&prop)))
  187877. return false;
  187878. PROPSPEC iPropSpec;
  187879. iPropSpec.ulKind = PRSPEC_LPWSTR;
  187880. iPropSpec.lpwstr = name;
  187881. PROPVARIANT iPropVariant;
  187882. if (FAILED (prop->ReadMultiple (1, &iPropSpec, &iPropVariant)))
  187883. return false;
  187884. iPropVariant.lVal = (long) value;
  187885. return SUCCEEDED (prop->WriteMultiple (1, &iPropSpec, &iPropVariant, iPropVariant.vt))
  187886. && SUCCEEDED (discRecorder->SetRecorderProperties (prop));
  187887. }
  187888. void timerCallback()
  187889. {
  187890. const DiskState state = getDiskState();
  187891. if (state != lastState)
  187892. {
  187893. lastState = state;
  187894. owner.sendChangeMessage (&owner);
  187895. }
  187896. }
  187897. AudioCDBurner& owner;
  187898. DiskState lastState;
  187899. IDiscMaster* discMaster;
  187900. IDiscRecorder* discRecorder;
  187901. IRedbookDiscMaster* redbook;
  187902. AudioCDBurner::BurnProgressListener* listener;
  187903. float progress;
  187904. bool shouldCancel;
  187905. private:
  187906. int refCount;
  187907. };
  187908. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  187909. {
  187910. IDiscMaster* discMaster = 0;
  187911. IDiscRecorder* discRecorder = enumCDBurners (0, deviceIndex, &discMaster);
  187912. if (discRecorder != 0)
  187913. pimpl = new Pimpl (*this, discMaster, discRecorder);
  187914. }
  187915. AudioCDBurner::~AudioCDBurner()
  187916. {
  187917. if (pimpl != 0)
  187918. pimpl.release()->releaseObjects();
  187919. }
  187920. const StringArray AudioCDBurner::findAvailableDevices()
  187921. {
  187922. StringArray devs;
  187923. enumCDBurners (&devs, -1, 0);
  187924. return devs;
  187925. }
  187926. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  187927. {
  187928. ScopedPointer<AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  187929. if (b->pimpl == 0)
  187930. b = 0;
  187931. return b.release();
  187932. }
  187933. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  187934. {
  187935. return pimpl->getDiskState();
  187936. }
  187937. bool AudioCDBurner::isDiskPresent() const
  187938. {
  187939. return getDiskState() == writableDiskPresent;
  187940. }
  187941. bool AudioCDBurner::openTray()
  187942. {
  187943. const Pimpl::ScopedDiscOpener opener (*pimpl);
  187944. return SUCCEEDED (pimpl->discRecorder->Eject());
  187945. }
  187946. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  187947. {
  187948. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  187949. DiskState oldState = getDiskState();
  187950. DiskState newState = oldState;
  187951. while (newState == oldState && Time::currentTimeMillis() < timeout)
  187952. {
  187953. newState = getDiskState();
  187954. Thread::sleep (jmin (250, (int) (timeout - Time::currentTimeMillis())));
  187955. }
  187956. return newState;
  187957. }
  187958. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  187959. {
  187960. Array<int> results;
  187961. const int maxSpeed = pimpl->getIntProperty (L"MaxWriteSpeed", 1);
  187962. const int speeds[] = { 1, 2, 4, 8, 12, 16, 20, 24, 32, 40, 64, 80 };
  187963. for (int i = 0; i < numElementsInArray (speeds); ++i)
  187964. if (speeds[i] <= maxSpeed)
  187965. results.add (speeds[i]);
  187966. results.addIfNotAlreadyThere (maxSpeed);
  187967. return results;
  187968. }
  187969. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  187970. {
  187971. if (pimpl->getIntProperty (L"BufferUnderrunFreeCapable", 0) == 0)
  187972. return false;
  187973. pimpl->setIntProperty (L"EnableBufferUnderrunFree", shouldBeEnabled ? -1 : 0);
  187974. return pimpl->getIntProperty (L"EnableBufferUnderrunFree", 0) != 0;
  187975. }
  187976. int AudioCDBurner::getNumAvailableAudioBlocks() const
  187977. {
  187978. long blocksFree = 0;
  187979. pimpl->redbook->GetAvailableAudioTrackBlocks (&blocksFree);
  187980. return blocksFree;
  187981. }
  187982. const String AudioCDBurner::burn (AudioCDBurner::BurnProgressListener* listener, bool ejectDiscAfterwards,
  187983. bool performFakeBurnForTesting, int writeSpeed)
  187984. {
  187985. pimpl->listener = listener;
  187986. pimpl->progress = 0;
  187987. pimpl->shouldCancel = false;
  187988. UINT_PTR cookie;
  187989. HRESULT hr = pimpl->discMaster->ProgressAdvise ((AudioCDBurner::Pimpl*) pimpl, &cookie);
  187990. hr = pimpl->discMaster->RecordDisc (performFakeBurnForTesting,
  187991. ejectDiscAfterwards);
  187992. String error;
  187993. if (hr != S_OK)
  187994. {
  187995. const char* e = "Couldn't open or write to the CD device";
  187996. if (hr == IMAPI_E_USERABORT)
  187997. e = "User cancelled the write operation";
  187998. else if (hr == IMAPI_E_MEDIUM_NOTPRESENT || hr == IMAPI_E_TRACKOPEN)
  187999. e = "No Disk present";
  188000. error = e;
  188001. }
  188002. pimpl->discMaster->ProgressUnadvise (cookie);
  188003. pimpl->listener = 0;
  188004. return error;
  188005. }
  188006. bool AudioCDBurner::addAudioTrack (AudioSource* audioSource, int numSamples)
  188007. {
  188008. if (audioSource == 0)
  188009. return false;
  188010. ScopedPointer<AudioSource> source (audioSource);
  188011. long bytesPerBlock;
  188012. HRESULT hr = pimpl->redbook->GetAudioBlockSize (&bytesPerBlock);
  188013. const int samplesPerBlock = bytesPerBlock / 4;
  188014. bool ok = true;
  188015. hr = pimpl->redbook->CreateAudioTrack ((long) numSamples / (bytesPerBlock * 4));
  188016. HeapBlock <byte> buffer (bytesPerBlock);
  188017. AudioSampleBuffer sourceBuffer (2, samplesPerBlock);
  188018. int samplesDone = 0;
  188019. source->prepareToPlay (samplesPerBlock, 44100.0);
  188020. while (ok)
  188021. {
  188022. {
  188023. AudioSourceChannelInfo info;
  188024. info.buffer = &sourceBuffer;
  188025. info.numSamples = samplesPerBlock;
  188026. info.startSample = 0;
  188027. sourceBuffer.clear();
  188028. source->getNextAudioBlock (info);
  188029. }
  188030. zeromem (buffer, bytesPerBlock);
  188031. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (0, 0),
  188032. buffer, samplesPerBlock, 4);
  188033. AudioDataConverters::convertFloatToInt16LE (sourceBuffer.getSampleData (1, 0),
  188034. buffer + 2, samplesPerBlock, 4);
  188035. hr = pimpl->redbook->AddAudioTrackBlocks (buffer, bytesPerBlock);
  188036. if (FAILED (hr))
  188037. ok = false;
  188038. samplesDone += samplesPerBlock;
  188039. if (samplesDone >= numSamples)
  188040. break;
  188041. }
  188042. hr = pimpl->redbook->CloseAudioTrack();
  188043. return ok && hr == S_OK;
  188044. }
  188045. #endif
  188046. #endif
  188047. /*** End of inlined file: juce_win32_AudioCDReader.cpp ***/
  188048. /*** Start of inlined file: juce_win32_Midi.cpp ***/
  188049. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188050. // compiled on its own).
  188051. #if JUCE_INCLUDED_FILE
  188052. static const int midiBufferSize = 1024 * 10;
  188053. static const int numInHeaders = 32;
  188054. static const int inBufferSize = 256;
  188055. static Array <void*, CriticalSection> activeMidiThreads;
  188056. using ::free;
  188057. class MidiInThread : public Thread
  188058. {
  188059. public:
  188060. MidiInThread (MidiInput* const input_,
  188061. MidiInputCallback* const callback_)
  188062. : Thread ("Juce Midi"),
  188063. hIn (0),
  188064. input (input_),
  188065. callback (callback_),
  188066. isStarted (false),
  188067. startTime (0),
  188068. pendingLength(0)
  188069. {
  188070. for (int i = numInHeaders; --i >= 0;)
  188071. {
  188072. zeromem (&hdr[i], sizeof (MIDIHDR));
  188073. hdr[i].lpData = inData[i];
  188074. hdr[i].dwBufferLength = inBufferSize;
  188075. }
  188076. };
  188077. ~MidiInThread()
  188078. {
  188079. stop();
  188080. if (hIn != 0)
  188081. {
  188082. int count = 5;
  188083. while (--count >= 0)
  188084. {
  188085. if (midiInClose (hIn) == MMSYSERR_NOERROR)
  188086. break;
  188087. Sleep (20);
  188088. }
  188089. }
  188090. }
  188091. void handle (const uint32 message, const uint32 timeStamp) throw()
  188092. {
  188093. const int byte = message & 0xff;
  188094. if (byte < 0x80)
  188095. return;
  188096. const int numBytes = MidiMessage::getMessageLengthFromFirstByte ((uint8) byte);
  188097. const double time = timeStampToTime (timeStamp);
  188098. {
  188099. const ScopedLock sl (lock);
  188100. if (pendingLength < midiBufferSize - 12)
  188101. {
  188102. char* const p = pending + pendingLength;
  188103. *(double*) p = time;
  188104. *(uint32*) (p + 8) = numBytes;
  188105. *(uint32*) (p + 12) = message;
  188106. pendingLength += 12 + numBytes;
  188107. }
  188108. else
  188109. {
  188110. jassertfalse // midi buffer overflow! You might need to increase the size..
  188111. }
  188112. }
  188113. notify();
  188114. }
  188115. void handleSysEx (MIDIHDR* const hdr, const uint32 timeStamp) throw()
  188116. {
  188117. const int num = hdr->dwBytesRecorded;
  188118. if (num > 0)
  188119. {
  188120. const double time = timeStampToTime (timeStamp);
  188121. {
  188122. const ScopedLock sl (lock);
  188123. if (pendingLength < midiBufferSize - (8 + num))
  188124. {
  188125. char* const p = pending + pendingLength;
  188126. *(double*) p = time;
  188127. *(uint32*) (p + 8) = num;
  188128. memcpy (p + 12, hdr->lpData, num);
  188129. pendingLength += 12 + num;
  188130. }
  188131. else
  188132. {
  188133. jassertfalse // midi buffer overflow! You might need to increase the size..
  188134. }
  188135. }
  188136. notify();
  188137. }
  188138. }
  188139. void writeBlock (const int i) throw()
  188140. {
  188141. hdr[i].dwBytesRecorded = 0;
  188142. MMRESULT res = midiInPrepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  188143. jassert (res == MMSYSERR_NOERROR);
  188144. res = midiInAddBuffer (hIn, &hdr[i], sizeof (MIDIHDR));
  188145. jassert (res == MMSYSERR_NOERROR);
  188146. }
  188147. void run()
  188148. {
  188149. MemoryBlock pendingCopy (64);
  188150. while (! threadShouldExit())
  188151. {
  188152. for (int i = 0; i < numInHeaders; ++i)
  188153. {
  188154. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  188155. {
  188156. MMRESULT res = midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR));
  188157. (void) res;
  188158. jassert (res == MMSYSERR_NOERROR);
  188159. writeBlock (i);
  188160. }
  188161. }
  188162. int len;
  188163. {
  188164. const ScopedLock sl (lock);
  188165. len = pendingLength;
  188166. if (len > 0)
  188167. {
  188168. pendingCopy.ensureSize (len);
  188169. pendingCopy.copyFrom (pending, 0, len);
  188170. pendingLength = 0;
  188171. }
  188172. }
  188173. //xxx needs to figure out if blocks are broken up or not
  188174. if (len == 0)
  188175. {
  188176. wait (500);
  188177. }
  188178. else
  188179. {
  188180. const char* p = (const char*) pendingCopy.getData();
  188181. while (len > 0)
  188182. {
  188183. const double time = *(const double*) p;
  188184. const int messageLen = *(const int*) (p + 8);
  188185. const MidiMessage message ((const uint8*) (p + 12), messageLen, time);
  188186. callback->handleIncomingMidiMessage (input, message);
  188187. p += 12 + messageLen;
  188188. len -= 12 + messageLen;
  188189. }
  188190. }
  188191. }
  188192. }
  188193. void start() throw()
  188194. {
  188195. jassert (hIn != 0);
  188196. if (hIn != 0 && ! isStarted)
  188197. {
  188198. stop();
  188199. activeMidiThreads.addIfNotAlreadyThere (this);
  188200. int i;
  188201. for (i = 0; i < numInHeaders; ++i)
  188202. writeBlock (i);
  188203. startTime = Time::getMillisecondCounter();
  188204. MMRESULT res = midiInStart (hIn);
  188205. jassert (res == MMSYSERR_NOERROR);
  188206. if (res == MMSYSERR_NOERROR)
  188207. {
  188208. isStarted = true;
  188209. pendingLength = 0;
  188210. startThread (6);
  188211. }
  188212. }
  188213. }
  188214. void stop() throw()
  188215. {
  188216. if (isStarted)
  188217. {
  188218. stopThread (5000);
  188219. midiInReset (hIn);
  188220. midiInStop (hIn);
  188221. activeMidiThreads.removeValue (this);
  188222. { const ScopedLock sl (lock); }
  188223. for (int i = numInHeaders; --i >= 0;)
  188224. {
  188225. if ((hdr[i].dwFlags & WHDR_DONE) != 0)
  188226. {
  188227. int c = 10;
  188228. while (--c >= 0 && midiInUnprepareHeader (hIn, &hdr[i], sizeof (MIDIHDR)) == MIDIERR_STILLPLAYING)
  188229. Sleep (20);
  188230. jassert (c >= 0);
  188231. }
  188232. }
  188233. isStarted = false;
  188234. pendingLength = 0;
  188235. }
  188236. }
  188237. juce_UseDebuggingNewOperator
  188238. HMIDIIN hIn;
  188239. private:
  188240. MidiInput* input;
  188241. MidiInputCallback* callback;
  188242. bool isStarted;
  188243. uint32 startTime;
  188244. CriticalSection lock;
  188245. MIDIHDR hdr [numInHeaders];
  188246. char inData [numInHeaders] [inBufferSize];
  188247. int pendingLength;
  188248. char pending [midiBufferSize];
  188249. double timeStampToTime (uint32 timeStamp) throw()
  188250. {
  188251. timeStamp += startTime;
  188252. const uint32 now = Time::getMillisecondCounter();
  188253. if (timeStamp > now)
  188254. {
  188255. if (timeStamp > now + 2)
  188256. --startTime;
  188257. timeStamp = now;
  188258. }
  188259. return 0.001 * timeStamp;
  188260. }
  188261. MidiInThread (const MidiInThread&);
  188262. MidiInThread& operator= (const MidiInThread&);
  188263. };
  188264. static void CALLBACK midiInCallback (HMIDIIN,
  188265. UINT uMsg,
  188266. DWORD_PTR dwInstance,
  188267. DWORD_PTR midiMessage,
  188268. DWORD_PTR timeStamp)
  188269. {
  188270. MidiInThread* const thread = (MidiInThread*) dwInstance;
  188271. if (thread != 0 && activeMidiThreads.contains (thread))
  188272. {
  188273. if (uMsg == MIM_DATA)
  188274. thread->handle ((uint32) midiMessage, (uint32) timeStamp);
  188275. else if (uMsg == MIM_LONGDATA)
  188276. thread->handleSysEx ((MIDIHDR*) midiMessage, (uint32) timeStamp);
  188277. }
  188278. }
  188279. const StringArray MidiInput::getDevices()
  188280. {
  188281. StringArray s;
  188282. const int num = midiInGetNumDevs();
  188283. for (int i = 0; i < num; ++i)
  188284. {
  188285. MIDIINCAPS mc;
  188286. zerostruct (mc);
  188287. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188288. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188289. }
  188290. return s;
  188291. }
  188292. int MidiInput::getDefaultDeviceIndex()
  188293. {
  188294. return 0;
  188295. }
  188296. MidiInput* MidiInput::openDevice (const int index, MidiInputCallback* const callback)
  188297. {
  188298. if (callback == 0)
  188299. return 0;
  188300. UINT deviceId = MIDI_MAPPER;
  188301. int n = 0;
  188302. String name;
  188303. const int num = midiInGetNumDevs();
  188304. for (int i = 0; i < num; ++i)
  188305. {
  188306. MIDIINCAPS mc;
  188307. zerostruct (mc);
  188308. if (midiInGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188309. {
  188310. if (index == n)
  188311. {
  188312. deviceId = i;
  188313. name = String (mc.szPname, sizeof (mc.szPname));
  188314. break;
  188315. }
  188316. ++n;
  188317. }
  188318. }
  188319. ScopedPointer <MidiInput> in (new MidiInput (name));
  188320. ScopedPointer <MidiInThread> thread (new MidiInThread (in, callback));
  188321. HMIDIIN h;
  188322. HRESULT err = midiInOpen (&h, deviceId,
  188323. (DWORD_PTR) &midiInCallback,
  188324. (DWORD_PTR) (MidiInThread*) thread,
  188325. CALLBACK_FUNCTION);
  188326. if (err == MMSYSERR_NOERROR)
  188327. {
  188328. thread->hIn = h;
  188329. in->internal = (void*) thread.release();
  188330. return in.release();
  188331. }
  188332. return 0;
  188333. }
  188334. MidiInput::MidiInput (const String& name_)
  188335. : name (name_),
  188336. internal (0)
  188337. {
  188338. }
  188339. MidiInput::~MidiInput()
  188340. {
  188341. if (internal != 0)
  188342. {
  188343. MidiInThread* const thread = (MidiInThread*) internal;
  188344. delete thread;
  188345. }
  188346. }
  188347. void MidiInput::start()
  188348. {
  188349. ((MidiInThread*) internal)->start();
  188350. }
  188351. void MidiInput::stop()
  188352. {
  188353. ((MidiInThread*) internal)->stop();
  188354. }
  188355. struct MidiOutHandle
  188356. {
  188357. int refCount;
  188358. UINT deviceId;
  188359. HMIDIOUT handle;
  188360. juce_UseDebuggingNewOperator
  188361. };
  188362. static Array <MidiOutHandle*> midiOutputHandles;
  188363. const StringArray MidiOutput::getDevices()
  188364. {
  188365. StringArray s;
  188366. const int num = midiOutGetNumDevs();
  188367. for (int i = 0; i < num; ++i)
  188368. {
  188369. MIDIOUTCAPS mc;
  188370. zerostruct (mc);
  188371. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188372. s.add (String (mc.szPname, sizeof (mc.szPname)));
  188373. }
  188374. return s;
  188375. }
  188376. int MidiOutput::getDefaultDeviceIndex()
  188377. {
  188378. const int num = midiOutGetNumDevs();
  188379. int n = 0;
  188380. for (int i = 0; i < num; ++i)
  188381. {
  188382. MIDIOUTCAPS mc;
  188383. zerostruct (mc);
  188384. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188385. {
  188386. if ((mc.wTechnology & MOD_MAPPER) != 0)
  188387. return n;
  188388. ++n;
  188389. }
  188390. }
  188391. return 0;
  188392. }
  188393. MidiOutput* MidiOutput::openDevice (int index)
  188394. {
  188395. UINT deviceId = MIDI_MAPPER;
  188396. const int num = midiOutGetNumDevs();
  188397. int i, n = 0;
  188398. for (i = 0; i < num; ++i)
  188399. {
  188400. MIDIOUTCAPS mc;
  188401. zerostruct (mc);
  188402. if (midiOutGetDevCaps (i, &mc, sizeof (mc)) == MMSYSERR_NOERROR)
  188403. {
  188404. // use the microsoft sw synth as a default - best not to allow deviceId
  188405. // to be MIDI_MAPPER, or else device sharing breaks
  188406. if (String (mc.szPname, sizeof (mc.szPname)).containsIgnoreCase (T("microsoft")))
  188407. deviceId = i;
  188408. if (index == n)
  188409. {
  188410. deviceId = i;
  188411. break;
  188412. }
  188413. ++n;
  188414. }
  188415. }
  188416. for (i = midiOutputHandles.size(); --i >= 0;)
  188417. {
  188418. MidiOutHandle* const han = midiOutputHandles.getUnchecked(i);
  188419. if (han != 0 && han->deviceId == deviceId)
  188420. {
  188421. han->refCount++;
  188422. MidiOutput* const out = new MidiOutput();
  188423. out->internal = (void*) han;
  188424. return out;
  188425. }
  188426. }
  188427. for (i = 4; --i >= 0;)
  188428. {
  188429. HMIDIOUT h = 0;
  188430. MMRESULT res = midiOutOpen (&h, deviceId, 0, 0, CALLBACK_NULL);
  188431. if (res == MMSYSERR_NOERROR)
  188432. {
  188433. MidiOutHandle* const han = new MidiOutHandle();
  188434. han->deviceId = deviceId;
  188435. han->refCount = 1;
  188436. han->handle = h;
  188437. midiOutputHandles.add (han);
  188438. MidiOutput* const out = new MidiOutput();
  188439. out->internal = (void*) han;
  188440. return out;
  188441. }
  188442. else if (res == MMSYSERR_ALLOCATED)
  188443. {
  188444. Sleep (100);
  188445. }
  188446. else
  188447. {
  188448. break;
  188449. }
  188450. }
  188451. return 0;
  188452. }
  188453. MidiOutput::~MidiOutput()
  188454. {
  188455. MidiOutHandle* const h = (MidiOutHandle*) internal;
  188456. if (midiOutputHandles.contains (h) && --(h->refCount) == 0)
  188457. {
  188458. midiOutClose (h->handle);
  188459. midiOutputHandles.removeValue (h);
  188460. delete h;
  188461. }
  188462. }
  188463. void MidiOutput::reset()
  188464. {
  188465. const MidiOutHandle* const h = (MidiOutHandle*) internal;
  188466. midiOutReset (h->handle);
  188467. }
  188468. bool MidiOutput::getVolume (float& leftVol,
  188469. float& rightVol)
  188470. {
  188471. const MidiOutHandle* const handle = (const MidiOutHandle*) internal;
  188472. DWORD n;
  188473. if (midiOutGetVolume (handle->handle, &n) == MMSYSERR_NOERROR)
  188474. {
  188475. const unsigned short* const nn = (const unsigned short*) &n;
  188476. rightVol = nn[0] / (float) 0xffff;
  188477. leftVol = nn[1] / (float) 0xffff;
  188478. return true;
  188479. }
  188480. else
  188481. {
  188482. rightVol = leftVol = 1.0f;
  188483. return false;
  188484. }
  188485. }
  188486. void MidiOutput::setVolume (float leftVol,
  188487. float rightVol)
  188488. {
  188489. const MidiOutHandle* const handle = (MidiOutHandle*) internal;
  188490. DWORD n;
  188491. unsigned short* const nn = (unsigned short*) &n;
  188492. nn[0] = (unsigned short) jlimit (0, 0xffff, (int)(rightVol * 0xffff));
  188493. nn[1] = (unsigned short) jlimit (0, 0xffff, (int)(leftVol * 0xffff));
  188494. midiOutSetVolume (handle->handle, n);
  188495. }
  188496. void MidiOutput::sendMessageNow (const MidiMessage& message)
  188497. {
  188498. const MidiOutHandle* const handle = (const MidiOutHandle*) internal;
  188499. if (message.getRawDataSize() > 3
  188500. || message.isSysEx())
  188501. {
  188502. MIDIHDR h;
  188503. zerostruct (h);
  188504. h.lpData = (char*) message.getRawData();
  188505. h.dwBufferLength = message.getRawDataSize();
  188506. h.dwBytesRecorded = message.getRawDataSize();
  188507. if (midiOutPrepareHeader (handle->handle, &h, sizeof (MIDIHDR)) == MMSYSERR_NOERROR)
  188508. {
  188509. MMRESULT res = midiOutLongMsg (handle->handle, &h, sizeof (MIDIHDR));
  188510. if (res == MMSYSERR_NOERROR)
  188511. {
  188512. while ((h.dwFlags & MHDR_DONE) == 0)
  188513. Sleep (1);
  188514. int count = 500; // 1 sec timeout
  188515. while (--count >= 0)
  188516. {
  188517. res = midiOutUnprepareHeader (handle->handle, &h, sizeof (MIDIHDR));
  188518. if (res == MIDIERR_STILLPLAYING)
  188519. Sleep (2);
  188520. else
  188521. break;
  188522. }
  188523. }
  188524. }
  188525. }
  188526. else
  188527. {
  188528. midiOutShortMsg (handle->handle,
  188529. *(unsigned int*) message.getRawData());
  188530. }
  188531. }
  188532. #endif
  188533. /*** End of inlined file: juce_win32_Midi.cpp ***/
  188534. /*** Start of inlined file: juce_win32_ASIO.cpp ***/
  188535. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  188536. // compiled on its own).
  188537. #if JUCE_INCLUDED_FILE && JUCE_ASIO
  188538. #undef WINDOWS
  188539. // #define ASIO_DEBUGGING
  188540. #ifdef ASIO_DEBUGGING
  188541. #define log(a) { Logger::writeToLog (a); DBG (a) }
  188542. #else
  188543. #define log(a) {}
  188544. #endif
  188545. #ifdef ASIO_DEBUGGING
  188546. static void logError (const String& context, long error)
  188547. {
  188548. String err ("unknown error");
  188549. if (error == ASE_NotPresent)
  188550. err = "Not Present";
  188551. else if (error == ASE_HWMalfunction)
  188552. err = "Hardware Malfunction";
  188553. else if (error == ASE_InvalidParameter)
  188554. err = "Invalid Parameter";
  188555. else if (error == ASE_InvalidMode)
  188556. err = "Invalid Mode";
  188557. else if (error == ASE_SPNotAdvancing)
  188558. err = "Sample position not advancing";
  188559. else if (error == ASE_NoClock)
  188560. err = "No Clock";
  188561. else if (error == ASE_NoMemory)
  188562. err = "Out of memory";
  188563. log (T("!!error: ") + context + T(" - ") + err);
  188564. }
  188565. #else
  188566. #define logError(a, b) {}
  188567. #endif
  188568. class ASIOAudioIODevice;
  188569. static ASIOAudioIODevice* volatile currentASIODev[3] = { 0, 0, 0 };
  188570. static const int maxASIOChannels = 160;
  188571. class JUCE_API ASIOAudioIODevice : public AudioIODevice,
  188572. private Timer
  188573. {
  188574. public:
  188575. Component ourWindow;
  188576. ASIOAudioIODevice (const String& name_, const CLSID classId_, const int slotNumber,
  188577. const String& optionalDllForDirectLoading_)
  188578. : AudioIODevice (name_, T("ASIO")),
  188579. asioObject (0),
  188580. classId (classId_),
  188581. optionalDllForDirectLoading (optionalDllForDirectLoading_),
  188582. currentBitDepth (16),
  188583. currentSampleRate (0),
  188584. isOpen_ (false),
  188585. isStarted (false),
  188586. postOutput (true),
  188587. insideControlPanelModalLoop (false),
  188588. shouldUsePreferredSize (false)
  188589. {
  188590. name = name_;
  188591. ourWindow.addToDesktop (0);
  188592. windowHandle = ourWindow.getWindowHandle();
  188593. jassert (currentASIODev [slotNumber] == 0);
  188594. currentASIODev [slotNumber] = this;
  188595. openDevice();
  188596. }
  188597. ~ASIOAudioIODevice()
  188598. {
  188599. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  188600. if (currentASIODev[i] == this)
  188601. currentASIODev[i] = 0;
  188602. close();
  188603. log ("ASIO - exiting");
  188604. removeCurrentDriver();
  188605. }
  188606. void updateSampleRates()
  188607. {
  188608. // find a list of sample rates..
  188609. const double possibleSampleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  188610. sampleRates.clear();
  188611. if (asioObject != 0)
  188612. {
  188613. for (int index = 0; index < numElementsInArray (possibleSampleRates); ++index)
  188614. {
  188615. const long err = asioObject->canSampleRate (possibleSampleRates[index]);
  188616. if (err == 0)
  188617. {
  188618. sampleRates.add ((int) possibleSampleRates[index]);
  188619. log (T("rate: ") + String ((int) possibleSampleRates[index]));
  188620. }
  188621. else if (err != ASE_NoClock)
  188622. {
  188623. logError (T("CanSampleRate"), err);
  188624. }
  188625. }
  188626. if (sampleRates.size() == 0)
  188627. {
  188628. double cr = 0;
  188629. const long err = asioObject->getSampleRate (&cr);
  188630. log (T("No sample rates supported - current rate: ") + String ((int) cr));
  188631. if (err == 0)
  188632. sampleRates.add ((int) cr);
  188633. }
  188634. }
  188635. }
  188636. const StringArray getOutputChannelNames()
  188637. {
  188638. return outputChannelNames;
  188639. }
  188640. const StringArray getInputChannelNames()
  188641. {
  188642. return inputChannelNames;
  188643. }
  188644. int getNumSampleRates()
  188645. {
  188646. return sampleRates.size();
  188647. }
  188648. double getSampleRate (int index)
  188649. {
  188650. return sampleRates [index];
  188651. }
  188652. int getNumBufferSizesAvailable()
  188653. {
  188654. return bufferSizes.size();
  188655. }
  188656. int getBufferSizeSamples (int index)
  188657. {
  188658. return bufferSizes [index];
  188659. }
  188660. int getDefaultBufferSize()
  188661. {
  188662. return preferredSize;
  188663. }
  188664. const String open (const BitArray& inputChannels,
  188665. const BitArray& outputChannels,
  188666. double sr,
  188667. int bufferSizeSamples)
  188668. {
  188669. close();
  188670. currentCallback = 0;
  188671. if (bufferSizeSamples <= 0)
  188672. shouldUsePreferredSize = true;
  188673. if (asioObject == 0 || ! isASIOOpen)
  188674. {
  188675. log ("Warning: device not open");
  188676. const String err (openDevice());
  188677. if (asioObject == 0 || ! isASIOOpen)
  188678. return err;
  188679. }
  188680. isStarted = false;
  188681. bufferIndex = -1;
  188682. long err = 0;
  188683. long newPreferredSize = 0;
  188684. // if the preferred size has just changed, assume it's a control panel thing and use it as the new value.
  188685. minSize = 0;
  188686. maxSize = 0;
  188687. newPreferredSize = 0;
  188688. granularity = 0;
  188689. if (asioObject->getBufferSize (&minSize, &maxSize, &newPreferredSize, &granularity) == 0)
  188690. {
  188691. if (preferredSize != 0 && newPreferredSize != 0 && newPreferredSize != preferredSize)
  188692. shouldUsePreferredSize = true;
  188693. preferredSize = newPreferredSize;
  188694. }
  188695. // unfortunate workaround for certain manufacturers whose drivers crash horribly if you make
  188696. // dynamic changes to the buffer size...
  188697. shouldUsePreferredSize = shouldUsePreferredSize
  188698. || getName().containsIgnoreCase (T("Digidesign"));
  188699. if (shouldUsePreferredSize)
  188700. {
  188701. log ("Using preferred size for buffer..");
  188702. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  188703. {
  188704. bufferSizeSamples = preferredSize;
  188705. }
  188706. else
  188707. {
  188708. bufferSizeSamples = 1024;
  188709. logError ("GetBufferSize1", err);
  188710. }
  188711. shouldUsePreferredSize = false;
  188712. }
  188713. int sampleRate = roundDoubleToInt (sr);
  188714. currentSampleRate = sampleRate;
  188715. currentBlockSizeSamples = bufferSizeSamples;
  188716. currentChansOut.clear();
  188717. currentChansIn.clear();
  188718. zeromem (inBuffers, sizeof (inBuffers));
  188719. zeromem (outBuffers, sizeof (outBuffers));
  188720. updateSampleRates();
  188721. if (sampleRate == 0 || (sampleRates.size() > 0 && ! sampleRates.contains (sampleRate)))
  188722. sampleRate = sampleRates[0];
  188723. jassert (sampleRate != 0);
  188724. if (sampleRate == 0)
  188725. sampleRate = 44100;
  188726. long numSources = 32;
  188727. ASIOClockSource clocks[32];
  188728. zeromem (clocks, sizeof (clocks));
  188729. asioObject->getClockSources (clocks, &numSources);
  188730. bool isSourceSet = false;
  188731. // careful not to remove this loop because it does more than just logging!
  188732. int i;
  188733. for (i = 0; i < numSources; ++i)
  188734. {
  188735. String s ("clock: ");
  188736. s += clocks[i].name;
  188737. if (clocks[i].isCurrentSource)
  188738. {
  188739. isSourceSet = true;
  188740. s << " (cur)";
  188741. }
  188742. log (s);
  188743. }
  188744. if (numSources > 1 && ! isSourceSet)
  188745. {
  188746. log ("setting clock source");
  188747. asioObject->setClockSource (clocks[0].index);
  188748. Thread::sleep (20);
  188749. }
  188750. else
  188751. {
  188752. if (numSources == 0)
  188753. {
  188754. log ("ASIO - no clock sources!");
  188755. }
  188756. }
  188757. double cr = 0;
  188758. err = asioObject->getSampleRate (&cr);
  188759. if (err == 0)
  188760. {
  188761. currentSampleRate = cr;
  188762. }
  188763. else
  188764. {
  188765. logError ("GetSampleRate", err);
  188766. currentSampleRate = 0;
  188767. }
  188768. error = String::empty;
  188769. needToReset = false;
  188770. isReSync = false;
  188771. err = 0;
  188772. bool buffersCreated = false;
  188773. if (currentSampleRate != sampleRate)
  188774. {
  188775. log (T("ASIO samplerate: ") + String (currentSampleRate) + T(" to ") + String (sampleRate));
  188776. err = asioObject->setSampleRate (sampleRate);
  188777. if (err == ASE_NoClock && numSources > 0)
  188778. {
  188779. log ("trying to set a clock source..");
  188780. Thread::sleep (10);
  188781. err = asioObject->setClockSource (clocks[0].index);
  188782. if (err != 0)
  188783. {
  188784. logError ("SetClock", err);
  188785. }
  188786. Thread::sleep (10);
  188787. err = asioObject->setSampleRate (sampleRate);
  188788. }
  188789. }
  188790. if (err == 0)
  188791. {
  188792. currentSampleRate = sampleRate;
  188793. if (needToReset)
  188794. {
  188795. if (isReSync)
  188796. {
  188797. log ("Resync request");
  188798. }
  188799. log ("! Resetting ASIO after sample rate change");
  188800. removeCurrentDriver();
  188801. loadDriver();
  188802. const String error (initDriver());
  188803. if (error.isNotEmpty())
  188804. {
  188805. log (T("ASIOInit: ") + error);
  188806. }
  188807. needToReset = false;
  188808. isReSync = false;
  188809. }
  188810. numActiveInputChans = 0;
  188811. numActiveOutputChans = 0;
  188812. ASIOBufferInfo* info = bufferInfos;
  188813. int i;
  188814. for (i = 0; i < totalNumInputChans; ++i)
  188815. {
  188816. if (inputChannels[i])
  188817. {
  188818. currentChansIn.setBit (i);
  188819. info->isInput = 1;
  188820. info->channelNum = i;
  188821. info->buffers[0] = info->buffers[1] = 0;
  188822. ++info;
  188823. ++numActiveInputChans;
  188824. }
  188825. }
  188826. for (i = 0; i < totalNumOutputChans; ++i)
  188827. {
  188828. if (outputChannels[i])
  188829. {
  188830. currentChansOut.setBit (i);
  188831. info->isInput = 0;
  188832. info->channelNum = i;
  188833. info->buffers[0] = info->buffers[1] = 0;
  188834. ++info;
  188835. ++numActiveOutputChans;
  188836. }
  188837. }
  188838. const int totalBuffers = numActiveInputChans + numActiveOutputChans;
  188839. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  188840. if (currentASIODev[0] == this)
  188841. {
  188842. callbacks.bufferSwitch = &bufferSwitchCallback0;
  188843. callbacks.asioMessage = &asioMessagesCallback0;
  188844. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  188845. }
  188846. else if (currentASIODev[1] == this)
  188847. {
  188848. callbacks.bufferSwitch = &bufferSwitchCallback1;
  188849. callbacks.asioMessage = &asioMessagesCallback1;
  188850. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  188851. }
  188852. else if (currentASIODev[2] == this)
  188853. {
  188854. callbacks.bufferSwitch = &bufferSwitchCallback2;
  188855. callbacks.asioMessage = &asioMessagesCallback2;
  188856. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  188857. }
  188858. else
  188859. {
  188860. jassertfalse
  188861. }
  188862. log ("disposing buffers");
  188863. err = asioObject->disposeBuffers();
  188864. log (T("creating buffers: ") + String (totalBuffers) + T(", ") + String (currentBlockSizeSamples));
  188865. err = asioObject->createBuffers (bufferInfos,
  188866. totalBuffers,
  188867. currentBlockSizeSamples,
  188868. &callbacks);
  188869. if (err != 0)
  188870. {
  188871. currentBlockSizeSamples = preferredSize;
  188872. logError ("create buffers 2", err);
  188873. asioObject->disposeBuffers();
  188874. err = asioObject->createBuffers (bufferInfos,
  188875. totalBuffers,
  188876. currentBlockSizeSamples,
  188877. &callbacks);
  188878. }
  188879. if (err == 0)
  188880. {
  188881. buffersCreated = true;
  188882. tempBuffer.calloc (totalBuffers * currentBlockSizeSamples + 32);
  188883. int n = 0;
  188884. Array <int> types;
  188885. currentBitDepth = 16;
  188886. for (i = 0; i < jmin ((int) totalNumInputChans, maxASIOChannels); ++i)
  188887. {
  188888. if (inputChannels[i])
  188889. {
  188890. inBuffers[n] = tempBuffer + (currentBlockSizeSamples * n);
  188891. ASIOChannelInfo channelInfo;
  188892. zerostruct (channelInfo);
  188893. channelInfo.channel = i;
  188894. channelInfo.isInput = 1;
  188895. asioObject->getChannelInfo (&channelInfo);
  188896. types.addIfNotAlreadyThere (channelInfo.type);
  188897. typeToFormatParameters (channelInfo.type,
  188898. inputChannelBitDepths[n],
  188899. inputChannelBytesPerSample[n],
  188900. inputChannelIsFloat[n],
  188901. inputChannelLittleEndian[n]);
  188902. currentBitDepth = jmax (currentBitDepth, inputChannelBitDepths[n]);
  188903. ++n;
  188904. }
  188905. }
  188906. jassert (numActiveInputChans == n);
  188907. n = 0;
  188908. for (i = 0; i < jmin ((int) totalNumOutputChans, maxASIOChannels); ++i)
  188909. {
  188910. if (outputChannels[i])
  188911. {
  188912. outBuffers[n] = tempBuffer + (currentBlockSizeSamples * (numActiveInputChans + n));
  188913. ASIOChannelInfo channelInfo;
  188914. zerostruct (channelInfo);
  188915. channelInfo.channel = i;
  188916. channelInfo.isInput = 0;
  188917. asioObject->getChannelInfo (&channelInfo);
  188918. types.addIfNotAlreadyThere (channelInfo.type);
  188919. typeToFormatParameters (channelInfo.type,
  188920. outputChannelBitDepths[n],
  188921. outputChannelBytesPerSample[n],
  188922. outputChannelIsFloat[n],
  188923. outputChannelLittleEndian[n]);
  188924. currentBitDepth = jmax (currentBitDepth, outputChannelBitDepths[n]);
  188925. ++n;
  188926. }
  188927. }
  188928. jassert (numActiveOutputChans == n);
  188929. for (i = types.size(); --i >= 0;)
  188930. {
  188931. log (T("channel format: ") + String (types[i]));
  188932. }
  188933. jassert (n <= totalBuffers);
  188934. for (i = 0; i < numActiveOutputChans; ++i)
  188935. {
  188936. const int size = currentBlockSizeSamples * (outputChannelBitDepths[i] >> 3);
  188937. if (bufferInfos [numActiveInputChans + i].buffers[0] == 0
  188938. || bufferInfos [numActiveInputChans + i].buffers[1] == 0)
  188939. {
  188940. log ("!! Null buffers");
  188941. }
  188942. else
  188943. {
  188944. zeromem (bufferInfos[numActiveInputChans + i].buffers[0], size);
  188945. zeromem (bufferInfos[numActiveInputChans + i].buffers[1], size);
  188946. }
  188947. }
  188948. inputLatency = outputLatency = 0;
  188949. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  188950. {
  188951. log ("ASIO - no latencies");
  188952. }
  188953. else
  188954. {
  188955. log (T("ASIO latencies: ")
  188956. + String ((int) outputLatency)
  188957. + T(", ")
  188958. + String ((int) inputLatency));
  188959. }
  188960. isOpen_ = true;
  188961. log ("starting ASIO");
  188962. calledback = false;
  188963. err = asioObject->start();
  188964. if (err != 0)
  188965. {
  188966. isOpen_ = false;
  188967. log ("ASIO - stop on failure");
  188968. Thread::sleep (10);
  188969. asioObject->stop();
  188970. error = "Can't start device";
  188971. Thread::sleep (10);
  188972. }
  188973. else
  188974. {
  188975. int count = 300;
  188976. while (--count > 0 && ! calledback)
  188977. Thread::sleep (10);
  188978. isStarted = true;
  188979. if (! calledback)
  188980. {
  188981. error = "Device didn't start correctly";
  188982. log ("ASIO didn't callback - stopping..");
  188983. asioObject->stop();
  188984. }
  188985. }
  188986. }
  188987. else
  188988. {
  188989. error = "Can't create i/o buffers";
  188990. }
  188991. }
  188992. else
  188993. {
  188994. error = "Can't set sample rate: ";
  188995. error << sampleRate;
  188996. }
  188997. if (error.isNotEmpty())
  188998. {
  188999. logError (error, err);
  189000. if (asioObject != 0 && buffersCreated)
  189001. asioObject->disposeBuffers();
  189002. Thread::sleep (20);
  189003. isStarted = false;
  189004. isOpen_ = false;
  189005. close();
  189006. }
  189007. needToReset = false;
  189008. isReSync = false;
  189009. return error;
  189010. }
  189011. void close()
  189012. {
  189013. error = String::empty;
  189014. stopTimer();
  189015. stop();
  189016. if (isASIOOpen && isOpen_)
  189017. {
  189018. const ScopedLock sl (callbackLock);
  189019. isOpen_ = false;
  189020. isStarted = false;
  189021. needToReset = false;
  189022. isReSync = false;
  189023. log ("ASIO - stopping");
  189024. if (asioObject != 0)
  189025. {
  189026. Thread::sleep (20);
  189027. asioObject->stop();
  189028. Thread::sleep (10);
  189029. asioObject->disposeBuffers();
  189030. }
  189031. Thread::sleep (10);
  189032. }
  189033. }
  189034. bool isOpen()
  189035. {
  189036. return isOpen_ || insideControlPanelModalLoop;
  189037. }
  189038. int getCurrentBufferSizeSamples()
  189039. {
  189040. return currentBlockSizeSamples;
  189041. }
  189042. double getCurrentSampleRate()
  189043. {
  189044. return currentSampleRate;
  189045. }
  189046. const BitArray getActiveOutputChannels() const
  189047. {
  189048. return currentChansOut;
  189049. }
  189050. const BitArray getActiveInputChannels() const
  189051. {
  189052. return currentChansIn;
  189053. }
  189054. int getCurrentBitDepth()
  189055. {
  189056. return currentBitDepth;
  189057. }
  189058. int getOutputLatencyInSamples()
  189059. {
  189060. return outputLatency + currentBlockSizeSamples / 4;
  189061. }
  189062. int getInputLatencyInSamples()
  189063. {
  189064. return inputLatency + currentBlockSizeSamples / 4;
  189065. }
  189066. void start (AudioIODeviceCallback* callback)
  189067. {
  189068. if (callback != 0)
  189069. {
  189070. callback->audioDeviceAboutToStart (this);
  189071. const ScopedLock sl (callbackLock);
  189072. currentCallback = callback;
  189073. }
  189074. }
  189075. void stop()
  189076. {
  189077. AudioIODeviceCallback* const lastCallback = currentCallback;
  189078. {
  189079. const ScopedLock sl (callbackLock);
  189080. currentCallback = 0;
  189081. }
  189082. if (lastCallback != 0)
  189083. lastCallback->audioDeviceStopped();
  189084. }
  189085. bool isPlaying()
  189086. {
  189087. return isASIOOpen && (currentCallback != 0);
  189088. }
  189089. const String getLastError()
  189090. {
  189091. return error;
  189092. }
  189093. bool hasControlPanel() const
  189094. {
  189095. return true;
  189096. }
  189097. bool showControlPanel()
  189098. {
  189099. log ("ASIO - showing control panel");
  189100. Component modalWindow (String::empty);
  189101. modalWindow.setOpaque (true);
  189102. modalWindow.addToDesktop (0);
  189103. modalWindow.enterModalState();
  189104. bool done = false;
  189105. JUCE_TRY
  189106. {
  189107. // are there are devices that need to be closed before showing their control panel?
  189108. // close();
  189109. insideControlPanelModalLoop = true;
  189110. const uint32 started = Time::getMillisecondCounter();
  189111. if (asioObject != 0)
  189112. {
  189113. asioObject->controlPanel();
  189114. const int spent = (int) Time::getMillisecondCounter() - (int) started;
  189115. log (T("spent: ") + String (spent));
  189116. if (spent > 300)
  189117. {
  189118. shouldUsePreferredSize = true;
  189119. done = true;
  189120. }
  189121. }
  189122. }
  189123. JUCE_CATCH_ALL
  189124. insideControlPanelModalLoop = false;
  189125. return done;
  189126. }
  189127. void resetRequest() throw()
  189128. {
  189129. needToReset = true;
  189130. }
  189131. void resyncRequest() throw()
  189132. {
  189133. needToReset = true;
  189134. isReSync = true;
  189135. }
  189136. void timerCallback()
  189137. {
  189138. if (! insideControlPanelModalLoop)
  189139. {
  189140. stopTimer();
  189141. // used to cause a reset
  189142. log ("! ASIO restart request!");
  189143. if (isOpen_)
  189144. {
  189145. AudioIODeviceCallback* const oldCallback = currentCallback;
  189146. close();
  189147. open (BitArray (currentChansIn), BitArray (currentChansOut),
  189148. currentSampleRate, currentBlockSizeSamples);
  189149. if (oldCallback != 0)
  189150. start (oldCallback);
  189151. }
  189152. }
  189153. else
  189154. {
  189155. startTimer (100);
  189156. }
  189157. }
  189158. juce_UseDebuggingNewOperator
  189159. private:
  189160. IASIO* volatile asioObject;
  189161. ASIOCallbacks callbacks;
  189162. void* windowHandle;
  189163. CLSID classId;
  189164. const String optionalDllForDirectLoading;
  189165. String error;
  189166. long totalNumInputChans, totalNumOutputChans;
  189167. StringArray inputChannelNames, outputChannelNames;
  189168. Array<int> sampleRates, bufferSizes;
  189169. long inputLatency, outputLatency;
  189170. long minSize, maxSize, preferredSize, granularity;
  189171. int volatile currentBlockSizeSamples;
  189172. int volatile currentBitDepth;
  189173. double volatile currentSampleRate;
  189174. BitArray currentChansOut, currentChansIn;
  189175. AudioIODeviceCallback* volatile currentCallback;
  189176. CriticalSection callbackLock;
  189177. ASIOBufferInfo bufferInfos [maxASIOChannels];
  189178. float* inBuffers [maxASIOChannels];
  189179. float* outBuffers [maxASIOChannels];
  189180. int inputChannelBitDepths [maxASIOChannels];
  189181. int outputChannelBitDepths [maxASIOChannels];
  189182. int inputChannelBytesPerSample [maxASIOChannels];
  189183. int outputChannelBytesPerSample [maxASIOChannels];
  189184. bool inputChannelIsFloat [maxASIOChannels];
  189185. bool outputChannelIsFloat [maxASIOChannels];
  189186. bool inputChannelLittleEndian [maxASIOChannels];
  189187. bool outputChannelLittleEndian [maxASIOChannels];
  189188. WaitableEvent event1;
  189189. HeapBlock <float> tempBuffer;
  189190. int volatile bufferIndex, numActiveInputChans, numActiveOutputChans;
  189191. bool isOpen_, isStarted;
  189192. bool volatile isASIOOpen;
  189193. bool volatile calledback;
  189194. bool volatile littleEndian, postOutput, needToReset, isReSync;
  189195. bool volatile insideControlPanelModalLoop;
  189196. bool volatile shouldUsePreferredSize;
  189197. void removeCurrentDriver()
  189198. {
  189199. if (asioObject != 0)
  189200. {
  189201. asioObject->Release();
  189202. asioObject = 0;
  189203. }
  189204. }
  189205. bool loadDriver()
  189206. {
  189207. removeCurrentDriver();
  189208. JUCE_TRY
  189209. {
  189210. if (CoCreateInstance (classId, 0, CLSCTX_INPROC_SERVER,
  189211. classId, (void**) &asioObject) == S_OK)
  189212. {
  189213. return true;
  189214. }
  189215. // If a class isn't registered but we have a path for it, we can fallback to
  189216. // doing a direct load of the COM object (only available via the juce_createASIOAudioIODeviceForGUID function).
  189217. if (optionalDllForDirectLoading.isNotEmpty())
  189218. {
  189219. HMODULE h = LoadLibrary (optionalDllForDirectLoading);
  189220. if (h != 0)
  189221. {
  189222. typedef HRESULT (CALLBACK* DllGetClassObjectFunc) (REFCLSID clsid, REFIID iid, LPVOID* ppv);
  189223. DllGetClassObjectFunc dllGetClassObject = (DllGetClassObjectFunc) GetProcAddress (h, "DllGetClassObject");
  189224. if (dllGetClassObject != 0)
  189225. {
  189226. IClassFactory* classFactory = 0;
  189227. HRESULT hr = dllGetClassObject (classId, IID_IClassFactory, (void**) &classFactory);
  189228. if (classFactory != 0)
  189229. {
  189230. hr = classFactory->CreateInstance (0, classId, (void**) &asioObject);
  189231. classFactory->Release();
  189232. }
  189233. return asioObject != 0;
  189234. }
  189235. }
  189236. }
  189237. }
  189238. JUCE_CATCH_ALL
  189239. asioObject = 0;
  189240. return false;
  189241. }
  189242. const String initDriver()
  189243. {
  189244. if (asioObject != 0)
  189245. {
  189246. char buffer [256];
  189247. zeromem (buffer, sizeof (buffer));
  189248. if (! asioObject->init (windowHandle))
  189249. {
  189250. asioObject->getErrorMessage (buffer);
  189251. return String (buffer, sizeof (buffer) - 1);
  189252. }
  189253. // just in case any daft drivers expect this to be called..
  189254. asioObject->getDriverName (buffer);
  189255. return String::empty;
  189256. }
  189257. return "No Driver";
  189258. }
  189259. const String openDevice()
  189260. {
  189261. // use this in case the driver starts opening dialog boxes..
  189262. Component modalWindow (String::empty);
  189263. modalWindow.setOpaque (true);
  189264. modalWindow.addToDesktop (0);
  189265. modalWindow.enterModalState();
  189266. // open the device and get its info..
  189267. log (T("opening ASIO device: ") + getName());
  189268. needToReset = false;
  189269. isReSync = false;
  189270. outputChannelNames.clear();
  189271. inputChannelNames.clear();
  189272. bufferSizes.clear();
  189273. sampleRates.clear();
  189274. isASIOOpen = false;
  189275. isOpen_ = false;
  189276. totalNumInputChans = 0;
  189277. totalNumOutputChans = 0;
  189278. numActiveInputChans = 0;
  189279. numActiveOutputChans = 0;
  189280. currentCallback = 0;
  189281. error = String::empty;
  189282. if (getName().isEmpty())
  189283. return error;
  189284. long err = 0;
  189285. if (loadDriver())
  189286. {
  189287. if ((error = initDriver()).isEmpty())
  189288. {
  189289. numActiveInputChans = 0;
  189290. numActiveOutputChans = 0;
  189291. totalNumInputChans = 0;
  189292. totalNumOutputChans = 0;
  189293. if (asioObject != 0
  189294. && (err = asioObject->getChannels (&totalNumInputChans, &totalNumOutputChans)) == 0)
  189295. {
  189296. log (String ((int) totalNumInputChans) + T(" in, ") + String ((int) totalNumOutputChans) + T(" out"));
  189297. if ((err = asioObject->getBufferSize (&minSize, &maxSize, &preferredSize, &granularity)) == 0)
  189298. {
  189299. // find a list of buffer sizes..
  189300. log (String ((int) minSize) + T(" ") + String ((int) maxSize) + T(" ") + String ((int)preferredSize) + T(" ") + String ((int)granularity));
  189301. if (granularity >= 0)
  189302. {
  189303. granularity = jmax (1, (int) granularity);
  189304. for (int i = jmax ((int) minSize, (int) granularity); i < jmin (6400, (int) maxSize); i += granularity)
  189305. bufferSizes.addIfNotAlreadyThere (granularity * (i / granularity));
  189306. }
  189307. else if (granularity < 0)
  189308. {
  189309. for (int i = 0; i < 18; ++i)
  189310. {
  189311. const int s = (1 << i);
  189312. if (s >= minSize && s <= maxSize)
  189313. bufferSizes.add (s);
  189314. }
  189315. }
  189316. if (! bufferSizes.contains (preferredSize))
  189317. bufferSizes.insert (0, preferredSize);
  189318. double currentRate = 0;
  189319. asioObject->getSampleRate (&currentRate);
  189320. if (currentRate <= 0.0 || currentRate > 192001.0)
  189321. {
  189322. log ("setting sample rate");
  189323. err = asioObject->setSampleRate (44100.0);
  189324. if (err != 0)
  189325. {
  189326. logError ("setting sample rate", err);
  189327. }
  189328. asioObject->getSampleRate (&currentRate);
  189329. }
  189330. currentSampleRate = currentRate;
  189331. postOutput = (asioObject->outputReady() == 0);
  189332. if (postOutput)
  189333. {
  189334. log ("ASIO outputReady = ok");
  189335. }
  189336. updateSampleRates();
  189337. // ..because cubase does it at this point
  189338. inputLatency = outputLatency = 0;
  189339. if (asioObject->getLatencies (&inputLatency, &outputLatency) != 0)
  189340. {
  189341. log ("ASIO - no latencies");
  189342. }
  189343. log (String ("latencies: ")
  189344. + String ((int) inputLatency)
  189345. + T(", ") + String ((int) outputLatency));
  189346. // create some dummy buffers now.. because cubase does..
  189347. numActiveInputChans = 0;
  189348. numActiveOutputChans = 0;
  189349. ASIOBufferInfo* info = bufferInfos;
  189350. int i, numChans = 0;
  189351. for (i = 0; i < jmin (2, (int) totalNumInputChans); ++i)
  189352. {
  189353. info->isInput = 1;
  189354. info->channelNum = i;
  189355. info->buffers[0] = info->buffers[1] = 0;
  189356. ++info;
  189357. ++numChans;
  189358. }
  189359. const int outputBufferIndex = numChans;
  189360. for (i = 0; i < jmin (2, (int) totalNumOutputChans); ++i)
  189361. {
  189362. info->isInput = 0;
  189363. info->channelNum = i;
  189364. info->buffers[0] = info->buffers[1] = 0;
  189365. ++info;
  189366. ++numChans;
  189367. }
  189368. callbacks.sampleRateDidChange = &sampleRateChangedCallback;
  189369. if (currentASIODev[0] == this)
  189370. {
  189371. callbacks.bufferSwitch = &bufferSwitchCallback0;
  189372. callbacks.asioMessage = &asioMessagesCallback0;
  189373. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback0;
  189374. }
  189375. else if (currentASIODev[1] == this)
  189376. {
  189377. callbacks.bufferSwitch = &bufferSwitchCallback1;
  189378. callbacks.asioMessage = &asioMessagesCallback1;
  189379. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback1;
  189380. }
  189381. else if (currentASIODev[2] == this)
  189382. {
  189383. callbacks.bufferSwitch = &bufferSwitchCallback2;
  189384. callbacks.asioMessage = &asioMessagesCallback2;
  189385. callbacks.bufferSwitchTimeInfo = &bufferSwitchTimeInfoCallback2;
  189386. }
  189387. else
  189388. {
  189389. jassertfalse
  189390. }
  189391. log (T("creating buffers (dummy): ") + String (numChans)
  189392. + T(", ") + String ((int) preferredSize));
  189393. if (preferredSize > 0)
  189394. {
  189395. err = asioObject->createBuffers (bufferInfos, numChans, preferredSize, &callbacks);
  189396. if (err != 0)
  189397. {
  189398. logError ("dummy buffers", err);
  189399. }
  189400. }
  189401. long newInps = 0, newOuts = 0;
  189402. asioObject->getChannels (&newInps, &newOuts);
  189403. if (totalNumInputChans != newInps || totalNumOutputChans != newOuts)
  189404. {
  189405. totalNumInputChans = newInps;
  189406. totalNumOutputChans = newOuts;
  189407. log (String ((int) totalNumInputChans) + T(" in; ")
  189408. + String ((int) totalNumOutputChans) + T(" out"));
  189409. }
  189410. updateSampleRates();
  189411. ASIOChannelInfo channelInfo;
  189412. channelInfo.type = 0;
  189413. for (i = 0; i < totalNumInputChans; ++i)
  189414. {
  189415. zerostruct (channelInfo);
  189416. channelInfo.channel = i;
  189417. channelInfo.isInput = 1;
  189418. asioObject->getChannelInfo (&channelInfo);
  189419. inputChannelNames.add (String (channelInfo.name));
  189420. }
  189421. for (i = 0; i < totalNumOutputChans; ++i)
  189422. {
  189423. zerostruct (channelInfo);
  189424. channelInfo.channel = i;
  189425. channelInfo.isInput = 0;
  189426. asioObject->getChannelInfo (&channelInfo);
  189427. outputChannelNames.add (String (channelInfo.name));
  189428. typeToFormatParameters (channelInfo.type,
  189429. outputChannelBitDepths[i],
  189430. outputChannelBytesPerSample[i],
  189431. outputChannelIsFloat[i],
  189432. outputChannelLittleEndian[i]);
  189433. if (i < 2)
  189434. {
  189435. // clear the channels that are used with the dummy stuff
  189436. const int bytesPerBuffer = preferredSize * (outputChannelBitDepths[i] >> 3);
  189437. zeromem (bufferInfos [outputBufferIndex + i].buffers[0], bytesPerBuffer);
  189438. zeromem (bufferInfos [outputBufferIndex + i].buffers[1], bytesPerBuffer);
  189439. }
  189440. }
  189441. outputChannelNames.trim();
  189442. inputChannelNames.trim();
  189443. outputChannelNames.appendNumbersToDuplicates (false, true);
  189444. inputChannelNames.appendNumbersToDuplicates (false, true);
  189445. // start and stop because cubase does it..
  189446. asioObject->getLatencies (&inputLatency, &outputLatency);
  189447. if ((err = asioObject->start()) != 0)
  189448. {
  189449. // ignore an error here, as it might start later after setting other stuff up
  189450. logError ("ASIO start", err);
  189451. }
  189452. Thread::sleep (100);
  189453. asioObject->stop();
  189454. }
  189455. else
  189456. {
  189457. error = "Can't detect buffer sizes";
  189458. }
  189459. }
  189460. else
  189461. {
  189462. error = "Can't detect asio channels";
  189463. }
  189464. }
  189465. }
  189466. else
  189467. {
  189468. error = "No such device";
  189469. }
  189470. if (error.isNotEmpty())
  189471. {
  189472. logError (error, err);
  189473. if (asioObject != 0)
  189474. asioObject->disposeBuffers();
  189475. removeCurrentDriver();
  189476. isASIOOpen = false;
  189477. }
  189478. else
  189479. {
  189480. isASIOOpen = true;
  189481. log ("ASIO device open");
  189482. }
  189483. isOpen_ = false;
  189484. needToReset = false;
  189485. isReSync = false;
  189486. return error;
  189487. }
  189488. void callback (const long index) throw()
  189489. {
  189490. if (isStarted)
  189491. {
  189492. bufferIndex = index;
  189493. processBuffer();
  189494. }
  189495. else
  189496. {
  189497. if (postOutput && (asioObject != 0))
  189498. asioObject->outputReady();
  189499. }
  189500. calledback = true;
  189501. }
  189502. void processBuffer() throw()
  189503. {
  189504. const ASIOBufferInfo* const infos = bufferInfos;
  189505. const int bi = bufferIndex;
  189506. const ScopedLock sl (callbackLock);
  189507. if (needToReset)
  189508. {
  189509. needToReset = false;
  189510. if (isReSync)
  189511. {
  189512. log ("! ASIO resync");
  189513. isReSync = false;
  189514. }
  189515. else
  189516. {
  189517. startTimer (20);
  189518. }
  189519. }
  189520. if (bi >= 0)
  189521. {
  189522. const int samps = currentBlockSizeSamples;
  189523. if (currentCallback != 0)
  189524. {
  189525. int i;
  189526. for (i = 0; i < numActiveInputChans; ++i)
  189527. {
  189528. float* const dst = inBuffers[i];
  189529. jassert (dst != 0);
  189530. const char* const src = (const char*) (infos[i].buffers[bi]);
  189531. if (inputChannelIsFloat[i])
  189532. {
  189533. memcpy (dst, src, samps * sizeof (float));
  189534. }
  189535. else
  189536. {
  189537. jassert (dst == tempBuffer + (samps * i));
  189538. switch (inputChannelBitDepths[i])
  189539. {
  189540. case 16:
  189541. convertInt16ToFloat (src, dst, inputChannelBytesPerSample[i],
  189542. samps, inputChannelLittleEndian[i]);
  189543. break;
  189544. case 24:
  189545. convertInt24ToFloat (src, dst, inputChannelBytesPerSample[i],
  189546. samps, inputChannelLittleEndian[i]);
  189547. break;
  189548. case 32:
  189549. convertInt32ToFloat (src, dst, inputChannelBytesPerSample[i],
  189550. samps, inputChannelLittleEndian[i]);
  189551. break;
  189552. case 64:
  189553. jassertfalse
  189554. break;
  189555. }
  189556. }
  189557. }
  189558. currentCallback->audioDeviceIOCallback ((const float**) inBuffers,
  189559. numActiveInputChans,
  189560. outBuffers,
  189561. numActiveOutputChans,
  189562. samps);
  189563. for (i = 0; i < numActiveOutputChans; ++i)
  189564. {
  189565. float* const src = outBuffers[i];
  189566. jassert (src != 0);
  189567. char* const dst = (char*) (infos [numActiveInputChans + i].buffers[bi]);
  189568. if (outputChannelIsFloat[i])
  189569. {
  189570. memcpy (dst, src, samps * sizeof (float));
  189571. }
  189572. else
  189573. {
  189574. jassert (src == tempBuffer + (samps * (numActiveInputChans + i)));
  189575. switch (outputChannelBitDepths[i])
  189576. {
  189577. case 16:
  189578. convertFloatToInt16 (src, dst, outputChannelBytesPerSample[i],
  189579. samps, outputChannelLittleEndian[i]);
  189580. break;
  189581. case 24:
  189582. convertFloatToInt24 (src, dst, outputChannelBytesPerSample[i],
  189583. samps, outputChannelLittleEndian[i]);
  189584. break;
  189585. case 32:
  189586. convertFloatToInt32 (src, dst, outputChannelBytesPerSample[i],
  189587. samps, outputChannelLittleEndian[i]);
  189588. break;
  189589. case 64:
  189590. jassertfalse
  189591. break;
  189592. }
  189593. }
  189594. }
  189595. }
  189596. else
  189597. {
  189598. for (int i = 0; i < numActiveOutputChans; ++i)
  189599. {
  189600. const int bytesPerBuffer = samps * (outputChannelBitDepths[i] >> 3);
  189601. zeromem (infos[numActiveInputChans + i].buffers[bi], bytesPerBuffer);
  189602. }
  189603. }
  189604. }
  189605. if (postOutput)
  189606. asioObject->outputReady();
  189607. }
  189608. static ASIOTime* bufferSwitchTimeInfoCallback0 (ASIOTime*, long index, long) throw()
  189609. {
  189610. if (currentASIODev[0] != 0)
  189611. currentASIODev[0]->callback (index);
  189612. return 0;
  189613. }
  189614. static ASIOTime* bufferSwitchTimeInfoCallback1 (ASIOTime*, long index, long) throw()
  189615. {
  189616. if (currentASIODev[1] != 0)
  189617. currentASIODev[1]->callback (index);
  189618. return 0;
  189619. }
  189620. static ASIOTime* bufferSwitchTimeInfoCallback2 (ASIOTime*, long index, long) throw()
  189621. {
  189622. if (currentASIODev[2] != 0)
  189623. currentASIODev[2]->callback (index);
  189624. return 0;
  189625. }
  189626. static void bufferSwitchCallback0 (long index, long) throw()
  189627. {
  189628. if (currentASIODev[0] != 0)
  189629. currentASIODev[0]->callback (index);
  189630. }
  189631. static void bufferSwitchCallback1 (long index, long) throw()
  189632. {
  189633. if (currentASIODev[1] != 0)
  189634. currentASIODev[1]->callback (index);
  189635. }
  189636. static void bufferSwitchCallback2 (long index, long) throw()
  189637. {
  189638. if (currentASIODev[2] != 0)
  189639. currentASIODev[2]->callback (index);
  189640. }
  189641. static long asioMessagesCallback0 (long selector, long value, void*, double*) throw()
  189642. {
  189643. return asioMessagesCallback (selector, value, 0);
  189644. }
  189645. static long asioMessagesCallback1 (long selector, long value, void*, double*) throw()
  189646. {
  189647. return asioMessagesCallback (selector, value, 1);
  189648. }
  189649. static long asioMessagesCallback2 (long selector, long value, void*, double*) throw()
  189650. {
  189651. return asioMessagesCallback (selector, value, 2);
  189652. }
  189653. static long asioMessagesCallback (long selector, long value, const int deviceIndex) throw()
  189654. {
  189655. switch (selector)
  189656. {
  189657. case kAsioSelectorSupported:
  189658. if (value == kAsioResetRequest
  189659. || value == kAsioEngineVersion
  189660. || value == kAsioResyncRequest
  189661. || value == kAsioLatenciesChanged
  189662. || value == kAsioSupportsInputMonitor)
  189663. return 1;
  189664. break;
  189665. case kAsioBufferSizeChange:
  189666. break;
  189667. case kAsioResetRequest:
  189668. if (currentASIODev[deviceIndex] != 0)
  189669. currentASIODev[deviceIndex]->resetRequest();
  189670. return 1;
  189671. case kAsioResyncRequest:
  189672. if (currentASIODev[deviceIndex] != 0)
  189673. currentASIODev[deviceIndex]->resyncRequest();
  189674. return 1;
  189675. case kAsioLatenciesChanged:
  189676. return 1;
  189677. case kAsioEngineVersion:
  189678. return 2;
  189679. case kAsioSupportsTimeInfo:
  189680. case kAsioSupportsTimeCode:
  189681. return 0;
  189682. }
  189683. return 0;
  189684. }
  189685. static void sampleRateChangedCallback (ASIOSampleRate) throw()
  189686. {
  189687. }
  189688. static void convertInt16ToFloat (const char* src,
  189689. float* dest,
  189690. const int srcStrideBytes,
  189691. int numSamples,
  189692. const bool littleEndian) throw()
  189693. {
  189694. const double g = 1.0 / 32768.0;
  189695. if (littleEndian)
  189696. {
  189697. while (--numSamples >= 0)
  189698. {
  189699. *dest++ = (float) (g * (short) ByteOrder::littleEndianShort (src));
  189700. src += srcStrideBytes;
  189701. }
  189702. }
  189703. else
  189704. {
  189705. while (--numSamples >= 0)
  189706. {
  189707. *dest++ = (float) (g * (short) ByteOrder::bigEndianShort (src));
  189708. src += srcStrideBytes;
  189709. }
  189710. }
  189711. }
  189712. static void convertFloatToInt16 (const float* src,
  189713. char* dest,
  189714. const int dstStrideBytes,
  189715. int numSamples,
  189716. const bool littleEndian) throw()
  189717. {
  189718. const double maxVal = (double) 0x7fff;
  189719. if (littleEndian)
  189720. {
  189721. while (--numSamples >= 0)
  189722. {
  189723. *(uint16*) dest = ByteOrder::swapIfBigEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189724. dest += dstStrideBytes;
  189725. }
  189726. }
  189727. else
  189728. {
  189729. while (--numSamples >= 0)
  189730. {
  189731. *(uint16*) dest = ByteOrder::swapIfLittleEndian ((uint16) (short) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189732. dest += dstStrideBytes;
  189733. }
  189734. }
  189735. }
  189736. static void convertInt24ToFloat (const char* src,
  189737. float* dest,
  189738. const int srcStrideBytes,
  189739. int numSamples,
  189740. const bool littleEndian) throw()
  189741. {
  189742. const double g = 1.0 / 0x7fffff;
  189743. if (littleEndian)
  189744. {
  189745. while (--numSamples >= 0)
  189746. {
  189747. *dest++ = (float) (g * ByteOrder::littleEndian24Bit (src));
  189748. src += srcStrideBytes;
  189749. }
  189750. }
  189751. else
  189752. {
  189753. while (--numSamples >= 0)
  189754. {
  189755. *dest++ = (float) (g * ByteOrder::bigEndian24Bit (src));
  189756. src += srcStrideBytes;
  189757. }
  189758. }
  189759. }
  189760. static void convertFloatToInt24 (const float* src,
  189761. char* dest,
  189762. const int dstStrideBytes,
  189763. int numSamples,
  189764. const bool littleEndian) throw()
  189765. {
  189766. const double maxVal = (double) 0x7fffff;
  189767. if (littleEndian)
  189768. {
  189769. while (--numSamples >= 0)
  189770. {
  189771. ByteOrder::littleEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189772. dest += dstStrideBytes;
  189773. }
  189774. }
  189775. else
  189776. {
  189777. while (--numSamples >= 0)
  189778. {
  189779. ByteOrder::bigEndian24BitToChars ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)), dest);
  189780. dest += dstStrideBytes;
  189781. }
  189782. }
  189783. }
  189784. static void convertInt32ToFloat (const char* src,
  189785. float* dest,
  189786. const int srcStrideBytes,
  189787. int numSamples,
  189788. const bool littleEndian) throw()
  189789. {
  189790. const double g = 1.0 / 0x7fffffff;
  189791. if (littleEndian)
  189792. {
  189793. while (--numSamples >= 0)
  189794. {
  189795. *dest++ = (float) (g * (int) ByteOrder::littleEndianInt (src));
  189796. src += srcStrideBytes;
  189797. }
  189798. }
  189799. else
  189800. {
  189801. while (--numSamples >= 0)
  189802. {
  189803. *dest++ = (float) (g * (int) ByteOrder::bigEndianInt (src));
  189804. src += srcStrideBytes;
  189805. }
  189806. }
  189807. }
  189808. static void convertFloatToInt32 (const float* src,
  189809. char* dest,
  189810. const int dstStrideBytes,
  189811. int numSamples,
  189812. const bool littleEndian) throw()
  189813. {
  189814. const double maxVal = (double) 0x7fffffff;
  189815. if (littleEndian)
  189816. {
  189817. while (--numSamples >= 0)
  189818. {
  189819. *(uint32*) dest = ByteOrder::swapIfBigEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189820. dest += dstStrideBytes;
  189821. }
  189822. }
  189823. else
  189824. {
  189825. while (--numSamples >= 0)
  189826. {
  189827. *(uint32*) dest = ByteOrder::swapIfLittleEndian ((uint32) roundDoubleToInt (jlimit (-maxVal, maxVal, maxVal * *src++)));
  189828. dest += dstStrideBytes;
  189829. }
  189830. }
  189831. }
  189832. static void typeToFormatParameters (const long type,
  189833. int& bitDepth,
  189834. int& byteStride,
  189835. bool& formatIsFloat,
  189836. bool& littleEndian) throw()
  189837. {
  189838. bitDepth = 0;
  189839. littleEndian = false;
  189840. formatIsFloat = false;
  189841. switch (type)
  189842. {
  189843. case ASIOSTInt16MSB:
  189844. case ASIOSTInt16LSB:
  189845. case ASIOSTInt32MSB16:
  189846. case ASIOSTInt32LSB16:
  189847. bitDepth = 16; break;
  189848. case ASIOSTFloat32MSB:
  189849. case ASIOSTFloat32LSB:
  189850. formatIsFloat = true;
  189851. bitDepth = 32; break;
  189852. case ASIOSTInt32MSB:
  189853. case ASIOSTInt32LSB:
  189854. bitDepth = 32; break;
  189855. case ASIOSTInt24MSB:
  189856. case ASIOSTInt24LSB:
  189857. case ASIOSTInt32MSB24:
  189858. case ASIOSTInt32LSB24:
  189859. case ASIOSTInt32MSB18:
  189860. case ASIOSTInt32MSB20:
  189861. case ASIOSTInt32LSB18:
  189862. case ASIOSTInt32LSB20:
  189863. bitDepth = 24; break;
  189864. case ASIOSTFloat64MSB:
  189865. case ASIOSTFloat64LSB:
  189866. default:
  189867. bitDepth = 64;
  189868. break;
  189869. }
  189870. switch (type)
  189871. {
  189872. case ASIOSTInt16MSB:
  189873. case ASIOSTInt32MSB16:
  189874. case ASIOSTFloat32MSB:
  189875. case ASIOSTFloat64MSB:
  189876. case ASIOSTInt32MSB:
  189877. case ASIOSTInt32MSB18:
  189878. case ASIOSTInt32MSB20:
  189879. case ASIOSTInt32MSB24:
  189880. case ASIOSTInt24MSB:
  189881. littleEndian = false; break;
  189882. case ASIOSTInt16LSB:
  189883. case ASIOSTInt32LSB16:
  189884. case ASIOSTFloat32LSB:
  189885. case ASIOSTFloat64LSB:
  189886. case ASIOSTInt32LSB:
  189887. case ASIOSTInt32LSB18:
  189888. case ASIOSTInt32LSB20:
  189889. case ASIOSTInt32LSB24:
  189890. case ASIOSTInt24LSB:
  189891. littleEndian = true; break;
  189892. default:
  189893. break;
  189894. }
  189895. switch (type)
  189896. {
  189897. case ASIOSTInt16LSB:
  189898. case ASIOSTInt16MSB:
  189899. byteStride = 2; break;
  189900. case ASIOSTInt24LSB:
  189901. case ASIOSTInt24MSB:
  189902. byteStride = 3; break;
  189903. case ASIOSTInt32MSB16:
  189904. case ASIOSTInt32LSB16:
  189905. case ASIOSTInt32MSB:
  189906. case ASIOSTInt32MSB18:
  189907. case ASIOSTInt32MSB20:
  189908. case ASIOSTInt32MSB24:
  189909. case ASIOSTInt32LSB:
  189910. case ASIOSTInt32LSB18:
  189911. case ASIOSTInt32LSB20:
  189912. case ASIOSTInt32LSB24:
  189913. case ASIOSTFloat32LSB:
  189914. case ASIOSTFloat32MSB:
  189915. byteStride = 4; break;
  189916. case ASIOSTFloat64MSB:
  189917. case ASIOSTFloat64LSB:
  189918. byteStride = 8; break;
  189919. default:
  189920. break;
  189921. }
  189922. }
  189923. };
  189924. class ASIOAudioIODeviceType : public AudioIODeviceType
  189925. {
  189926. public:
  189927. ASIOAudioIODeviceType()
  189928. : AudioIODeviceType (T("ASIO")),
  189929. hasScanned (false)
  189930. {
  189931. CoInitialize (0);
  189932. }
  189933. ~ASIOAudioIODeviceType()
  189934. {
  189935. }
  189936. void scanForDevices()
  189937. {
  189938. hasScanned = true;
  189939. deviceNames.clear();
  189940. classIds.clear();
  189941. HKEY hk = 0;
  189942. int index = 0;
  189943. if (RegOpenKeyA (HKEY_LOCAL_MACHINE, "software\\asio", &hk) == ERROR_SUCCESS)
  189944. {
  189945. for (;;)
  189946. {
  189947. char name [256];
  189948. if (RegEnumKeyA (hk, index++, name, 256) == ERROR_SUCCESS)
  189949. {
  189950. addDriverInfo (name, hk);
  189951. }
  189952. else
  189953. {
  189954. break;
  189955. }
  189956. }
  189957. RegCloseKey (hk);
  189958. }
  189959. }
  189960. const StringArray getDeviceNames (const bool /*wantInputNames*/) const
  189961. {
  189962. jassert (hasScanned); // need to call scanForDevices() before doing this
  189963. return deviceNames;
  189964. }
  189965. int getDefaultDeviceIndex (const bool) const
  189966. {
  189967. jassert (hasScanned); // need to call scanForDevices() before doing this
  189968. for (int i = deviceNames.size(); --i >= 0;)
  189969. if (deviceNames[i].containsIgnoreCase (T("asio4all")))
  189970. return i; // asio4all is a safe choice for a default..
  189971. #if JUCE_DEBUG
  189972. if (deviceNames.size() > 1 && deviceNames[0].containsIgnoreCase (T("digidesign")))
  189973. return 1; // (the digi m-box driver crashes the app when you run
  189974. // it in the debugger, which can be a bit annoying)
  189975. #endif
  189976. return 0;
  189977. }
  189978. static int findFreeSlot()
  189979. {
  189980. for (int i = 0; i < numElementsInArray (currentASIODev); ++i)
  189981. if (currentASIODev[i] == 0)
  189982. return i;
  189983. jassertfalse; // unfortunately you can only have a finite number
  189984. // of ASIO devices open at the same time..
  189985. return -1;
  189986. }
  189987. int getIndexOfDevice (AudioIODevice* d, const bool /*asInput*/) const
  189988. {
  189989. jassert (hasScanned); // need to call scanForDevices() before doing this
  189990. return d == 0 ? -1 : deviceNames.indexOf (d->getName());
  189991. }
  189992. bool hasSeparateInputsAndOutputs() const { return false; }
  189993. AudioIODevice* createDevice (const String& outputDeviceName,
  189994. const String& inputDeviceName)
  189995. {
  189996. // ASIO can't open two different devices for input and output - they must be the same one.
  189997. jassert (inputDeviceName == outputDeviceName || outputDeviceName.isEmpty() || inputDeviceName.isEmpty());
  189998. jassert (hasScanned); // need to call scanForDevices() before doing this
  189999. const int index = deviceNames.indexOf (outputDeviceName.isNotEmpty() ? outputDeviceName
  190000. : inputDeviceName);
  190001. if (index >= 0)
  190002. {
  190003. const int freeSlot = findFreeSlot();
  190004. if (freeSlot >= 0)
  190005. return new ASIOAudioIODevice (outputDeviceName, *(classIds [index]), freeSlot, String::empty);
  190006. }
  190007. return 0;
  190008. }
  190009. juce_UseDebuggingNewOperator
  190010. private:
  190011. StringArray deviceNames;
  190012. OwnedArray <CLSID> classIds;
  190013. bool hasScanned;
  190014. static bool checkClassIsOk (const String& classId)
  190015. {
  190016. HKEY hk = 0;
  190017. bool ok = false;
  190018. if (RegOpenKey (HKEY_CLASSES_ROOT, _T("clsid"), &hk) == ERROR_SUCCESS)
  190019. {
  190020. int index = 0;
  190021. for (;;)
  190022. {
  190023. WCHAR buf [512];
  190024. if (RegEnumKey (hk, index++, buf, 512) == ERROR_SUCCESS)
  190025. {
  190026. if (classId.equalsIgnoreCase (buf))
  190027. {
  190028. HKEY subKey, pathKey;
  190029. if (RegOpenKeyEx (hk, buf, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  190030. {
  190031. if (RegOpenKeyEx (subKey, _T("InprocServer32"), 0, KEY_READ, &pathKey) == ERROR_SUCCESS)
  190032. {
  190033. WCHAR pathName [1024];
  190034. DWORD dtype = REG_SZ;
  190035. DWORD dsize = sizeof (pathName);
  190036. if (RegQueryValueEx (pathKey, 0, 0, &dtype, (LPBYTE) pathName, &dsize) == ERROR_SUCCESS)
  190037. ok = File (pathName).exists();
  190038. RegCloseKey (pathKey);
  190039. }
  190040. RegCloseKey (subKey);
  190041. }
  190042. break;
  190043. }
  190044. }
  190045. else
  190046. {
  190047. break;
  190048. }
  190049. }
  190050. RegCloseKey (hk);
  190051. }
  190052. return ok;
  190053. }
  190054. void addDriverInfo (const String& keyName, HKEY hk)
  190055. {
  190056. HKEY subKey;
  190057. if (RegOpenKeyEx (hk, keyName, 0, KEY_READ, &subKey) == ERROR_SUCCESS)
  190058. {
  190059. WCHAR buf [256];
  190060. zerostruct (buf);
  190061. DWORD dtype = REG_SZ;
  190062. DWORD dsize = sizeof (buf);
  190063. if (RegQueryValueEx (subKey, _T("clsid"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  190064. {
  190065. if (dsize > 0 && checkClassIsOk (buf))
  190066. {
  190067. CLSID classId;
  190068. if (CLSIDFromString ((LPOLESTR) buf, &classId) == S_OK)
  190069. {
  190070. dtype = REG_SZ;
  190071. dsize = sizeof (buf);
  190072. String deviceName;
  190073. if (RegQueryValueEx (subKey, _T("description"), 0, &dtype, (LPBYTE) buf, &dsize) == ERROR_SUCCESS)
  190074. deviceName = buf;
  190075. else
  190076. deviceName = keyName;
  190077. log (T("found ") + deviceName);
  190078. deviceNames.add (deviceName);
  190079. classIds.add (new CLSID (classId));
  190080. }
  190081. }
  190082. RegCloseKey (subKey);
  190083. }
  190084. }
  190085. }
  190086. ASIOAudioIODeviceType (const ASIOAudioIODeviceType&);
  190087. ASIOAudioIODeviceType& operator= (const ASIOAudioIODeviceType&);
  190088. };
  190089. AudioIODeviceType* juce_createAudioIODeviceType_ASIO()
  190090. {
  190091. return new ASIOAudioIODeviceType();
  190092. }
  190093. AudioIODevice* juce_createASIOAudioIODeviceForGUID (const String& name,
  190094. void* guid,
  190095. const String& optionalDllForDirectLoading)
  190096. {
  190097. const int freeSlot = ASIOAudioIODeviceType::findFreeSlot();
  190098. if (freeSlot < 0)
  190099. return 0;
  190100. return new ASIOAudioIODevice (name, *(CLSID*) guid, freeSlot, optionalDllForDirectLoading);
  190101. }
  190102. #undef log
  190103. #endif
  190104. /*** End of inlined file: juce_win32_ASIO.cpp ***/
  190105. /*** Start of inlined file: juce_win32_DirectSound.cpp ***/
  190106. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  190107. // compiled on its own).
  190108. #if JUCE_INCLUDED_FILE && JUCE_DIRECTSOUND
  190109. END_JUCE_NAMESPACE
  190110. extern "C"
  190111. {
  190112. // Declare just the minimum number of interfaces for the DSound objects that we need..
  190113. typedef struct typeDSBUFFERDESC
  190114. {
  190115. DWORD dwSize;
  190116. DWORD dwFlags;
  190117. DWORD dwBufferBytes;
  190118. DWORD dwReserved;
  190119. LPWAVEFORMATEX lpwfxFormat;
  190120. GUID guid3DAlgorithm;
  190121. } DSBUFFERDESC;
  190122. struct IDirectSoundBuffer;
  190123. #undef INTERFACE
  190124. #define INTERFACE IDirectSound
  190125. DECLARE_INTERFACE_(IDirectSound, IUnknown)
  190126. {
  190127. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190128. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190129. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190130. STDMETHOD(CreateSoundBuffer) (THIS_ DSBUFFERDESC*, IDirectSoundBuffer**, LPUNKNOWN) PURE;
  190131. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190132. STDMETHOD(DuplicateSoundBuffer) (THIS_ IDirectSoundBuffer*, IDirectSoundBuffer**) PURE;
  190133. STDMETHOD(SetCooperativeLevel) (THIS_ HWND, DWORD) PURE;
  190134. STDMETHOD(Compact) (THIS) PURE;
  190135. STDMETHOD(GetSpeakerConfig) (THIS_ LPDWORD) PURE;
  190136. STDMETHOD(SetSpeakerConfig) (THIS_ DWORD) PURE;
  190137. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  190138. };
  190139. #undef INTERFACE
  190140. #define INTERFACE IDirectSoundBuffer
  190141. DECLARE_INTERFACE_(IDirectSoundBuffer, IUnknown)
  190142. {
  190143. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190144. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190145. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190146. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190147. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  190148. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  190149. STDMETHOD(GetVolume) (THIS_ LPLONG) PURE;
  190150. STDMETHOD(GetPan) (THIS_ LPLONG) PURE;
  190151. STDMETHOD(GetFrequency) (THIS_ LPDWORD) PURE;
  190152. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  190153. STDMETHOD(Initialize) (THIS_ IDirectSound*, DSBUFFERDESC*) PURE;
  190154. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  190155. STDMETHOD(Play) (THIS_ DWORD, DWORD, DWORD) PURE;
  190156. STDMETHOD(SetCurrentPosition) (THIS_ DWORD) PURE;
  190157. STDMETHOD(SetFormat) (THIS_ const WAVEFORMATEX*) PURE;
  190158. STDMETHOD(SetVolume) (THIS_ LONG) PURE;
  190159. STDMETHOD(SetPan) (THIS_ LONG) PURE;
  190160. STDMETHOD(SetFrequency) (THIS_ DWORD) PURE;
  190161. STDMETHOD(Stop) (THIS) PURE;
  190162. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  190163. STDMETHOD(Restore) (THIS) PURE;
  190164. };
  190165. typedef struct typeDSCBUFFERDESC
  190166. {
  190167. DWORD dwSize;
  190168. DWORD dwFlags;
  190169. DWORD dwBufferBytes;
  190170. DWORD dwReserved;
  190171. LPWAVEFORMATEX lpwfxFormat;
  190172. } DSCBUFFERDESC;
  190173. struct IDirectSoundCaptureBuffer;
  190174. #undef INTERFACE
  190175. #define INTERFACE IDirectSoundCapture
  190176. DECLARE_INTERFACE_(IDirectSoundCapture, IUnknown)
  190177. {
  190178. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190179. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190180. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190181. STDMETHOD(CreateCaptureBuffer) (THIS_ DSCBUFFERDESC*, IDirectSoundCaptureBuffer**, LPUNKNOWN) PURE;
  190182. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190183. STDMETHOD(Initialize) (THIS_ const GUID*) PURE;
  190184. };
  190185. #undef INTERFACE
  190186. #define INTERFACE IDirectSoundCaptureBuffer
  190187. DECLARE_INTERFACE_(IDirectSoundCaptureBuffer, IUnknown)
  190188. {
  190189. STDMETHOD(QueryInterface) (THIS_ REFIID, LPVOID*) PURE;
  190190. STDMETHOD_(ULONG,AddRef) (THIS) PURE;
  190191. STDMETHOD_(ULONG,Release) (THIS) PURE;
  190192. STDMETHOD(GetCaps) (THIS_ void*) PURE;
  190193. STDMETHOD(GetCurrentPosition) (THIS_ LPDWORD, LPDWORD) PURE;
  190194. STDMETHOD(GetFormat) (THIS_ LPWAVEFORMATEX, DWORD, LPDWORD) PURE;
  190195. STDMETHOD(GetStatus) (THIS_ LPDWORD) PURE;
  190196. STDMETHOD(Initialize) (THIS_ IDirectSoundCapture*, DSCBUFFERDESC*) PURE;
  190197. STDMETHOD(Lock) (THIS_ DWORD, DWORD, LPVOID*, LPDWORD, LPVOID*, LPDWORD, DWORD) PURE;
  190198. STDMETHOD(Start) (THIS_ DWORD) PURE;
  190199. STDMETHOD(Stop) (THIS) PURE;
  190200. STDMETHOD(Unlock) (THIS_ LPVOID, DWORD, LPVOID, DWORD) PURE;
  190201. };
  190202. };
  190203. BEGIN_JUCE_NAMESPACE
  190204. static const String getDSErrorMessage (HRESULT hr)
  190205. {
  190206. const char* result = 0;
  190207. switch (hr)
  190208. {
  190209. case MAKE_HRESULT(1, 0x878, 10):
  190210. result = "Device already allocated";
  190211. break;
  190212. case MAKE_HRESULT(1, 0x878, 30):
  190213. result = "Control unavailable";
  190214. break;
  190215. case E_INVALIDARG:
  190216. result = "Invalid parameter";
  190217. break;
  190218. case MAKE_HRESULT(1, 0x878, 50):
  190219. result = "Invalid call";
  190220. break;
  190221. case E_FAIL:
  190222. result = "Generic error";
  190223. break;
  190224. case MAKE_HRESULT(1, 0x878, 70):
  190225. result = "Priority level error";
  190226. break;
  190227. case E_OUTOFMEMORY:
  190228. result = "Out of memory";
  190229. break;
  190230. case MAKE_HRESULT(1, 0x878, 100):
  190231. result = "Bad format";
  190232. break;
  190233. case E_NOTIMPL:
  190234. result = "Unsupported function";
  190235. break;
  190236. case MAKE_HRESULT(1, 0x878, 120):
  190237. result = "No driver";
  190238. break;
  190239. case MAKE_HRESULT(1, 0x878, 130):
  190240. result = "Already initialised";
  190241. break;
  190242. case CLASS_E_NOAGGREGATION:
  190243. result = "No aggregation";
  190244. break;
  190245. case MAKE_HRESULT(1, 0x878, 150):
  190246. result = "Buffer lost";
  190247. break;
  190248. case MAKE_HRESULT(1, 0x878, 160):
  190249. result = "Another app has priority";
  190250. break;
  190251. case MAKE_HRESULT(1, 0x878, 170):
  190252. result = "Uninitialised";
  190253. break;
  190254. case E_NOINTERFACE:
  190255. result = "No interface";
  190256. break;
  190257. case S_OK:
  190258. result = "No error";
  190259. break;
  190260. default:
  190261. return "Unknown error: " + String ((int) hr);
  190262. }
  190263. return result;
  190264. }
  190265. #define DS_DEBUGGING 1
  190266. #ifdef DS_DEBUGGING
  190267. #define CATCH JUCE_CATCH_EXCEPTION
  190268. #undef log
  190269. #define log(a) Logger::writeToLog(a);
  190270. #undef logError
  190271. #define logError(a) logDSError(a, __LINE__);
  190272. static void logDSError (HRESULT hr, int lineNum)
  190273. {
  190274. if (hr != S_OK)
  190275. {
  190276. String error ("DS error at line ");
  190277. error << lineNum << T(" - ") << getDSErrorMessage (hr);
  190278. log (error);
  190279. }
  190280. }
  190281. #else
  190282. #define CATCH JUCE_CATCH_ALL
  190283. #define log(a)
  190284. #define logError(a)
  190285. #endif
  190286. #define DSOUND_FUNCTION(functionName, params) \
  190287. typedef HRESULT (WINAPI *type##functionName) params; \
  190288. static type##functionName ds##functionName = 0;
  190289. #define DSOUND_FUNCTION_LOAD(functionName) \
  190290. ds##functionName = (type##functionName) GetProcAddress (h, #functionName); \
  190291. jassert (ds##functionName != 0);
  190292. typedef BOOL (CALLBACK *LPDSENUMCALLBACKW) (LPGUID, LPCWSTR, LPCWSTR, LPVOID);
  190293. typedef BOOL (CALLBACK *LPDSENUMCALLBACKA) (LPGUID, LPCSTR, LPCSTR, LPVOID);
  190294. DSOUND_FUNCTION (DirectSoundCreate, (const GUID*, IDirectSound**, LPUNKNOWN))
  190295. DSOUND_FUNCTION (DirectSoundCaptureCreate, (const GUID*, IDirectSoundCapture**, LPUNKNOWN))
  190296. DSOUND_FUNCTION (DirectSoundEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  190297. DSOUND_FUNCTION (DirectSoundCaptureEnumerateW, (LPDSENUMCALLBACKW, LPVOID))
  190298. static void initialiseDSoundFunctions()
  190299. {
  190300. if (dsDirectSoundCreate == 0)
  190301. {
  190302. HMODULE h = LoadLibraryA ("dsound.dll");
  190303. DSOUND_FUNCTION_LOAD (DirectSoundCreate)
  190304. DSOUND_FUNCTION_LOAD (DirectSoundCaptureCreate)
  190305. DSOUND_FUNCTION_LOAD (DirectSoundEnumerateW)
  190306. DSOUND_FUNCTION_LOAD (DirectSoundCaptureEnumerateW)
  190307. }
  190308. }
  190309. class DSoundInternalOutChannel
  190310. {
  190311. String name;
  190312. LPGUID guid;
  190313. int sampleRate, bufferSizeSamples;
  190314. float* leftBuffer;
  190315. float* rightBuffer;
  190316. IDirectSound* pDirectSound;
  190317. IDirectSoundBuffer* pOutputBuffer;
  190318. DWORD writeOffset;
  190319. int totalBytesPerBuffer;
  190320. int bytesPerBuffer;
  190321. unsigned int lastPlayCursor;
  190322. public:
  190323. int bitDepth;
  190324. bool doneFlag;
  190325. DSoundInternalOutChannel (const String& name_,
  190326. LPGUID guid_,
  190327. int rate,
  190328. int bufferSize,
  190329. float* left,
  190330. float* right)
  190331. : name (name_),
  190332. guid (guid_),
  190333. sampleRate (rate),
  190334. bufferSizeSamples (bufferSize),
  190335. leftBuffer (left),
  190336. rightBuffer (right),
  190337. pDirectSound (0),
  190338. pOutputBuffer (0),
  190339. bitDepth (16)
  190340. {
  190341. }
  190342. ~DSoundInternalOutChannel()
  190343. {
  190344. close();
  190345. }
  190346. void close()
  190347. {
  190348. HRESULT hr;
  190349. if (pOutputBuffer != 0)
  190350. {
  190351. JUCE_TRY
  190352. {
  190353. log (T("closing dsound out: ") + name);
  190354. hr = pOutputBuffer->Stop();
  190355. logError (hr);
  190356. }
  190357. CATCH
  190358. JUCE_TRY
  190359. {
  190360. hr = pOutputBuffer->Release();
  190361. logError (hr);
  190362. }
  190363. CATCH
  190364. pOutputBuffer = 0;
  190365. }
  190366. if (pDirectSound != 0)
  190367. {
  190368. JUCE_TRY
  190369. {
  190370. hr = pDirectSound->Release();
  190371. logError (hr);
  190372. }
  190373. CATCH
  190374. pDirectSound = 0;
  190375. }
  190376. }
  190377. const String open()
  190378. {
  190379. log (T("opening dsound out device: ") + name
  190380. + T(" rate=") + String (sampleRate)
  190381. + T(" bits=") + String (bitDepth)
  190382. + T(" buf=") + String (bufferSizeSamples));
  190383. pDirectSound = 0;
  190384. pOutputBuffer = 0;
  190385. writeOffset = 0;
  190386. String error;
  190387. HRESULT hr = E_NOINTERFACE;
  190388. if (dsDirectSoundCreate != 0)
  190389. hr = dsDirectSoundCreate (guid, &pDirectSound, 0);
  190390. if (hr == S_OK)
  190391. {
  190392. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190393. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190394. const int numChannels = 2;
  190395. hr = pDirectSound->SetCooperativeLevel (GetDesktopWindow(), 2 /* DSSCL_PRIORITY */);
  190396. logError (hr);
  190397. if (hr == S_OK)
  190398. {
  190399. IDirectSoundBuffer* pPrimaryBuffer;
  190400. DSBUFFERDESC primaryDesc;
  190401. zerostruct (primaryDesc);
  190402. primaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190403. primaryDesc.dwFlags = 1 /* DSBCAPS_PRIMARYBUFFER */;
  190404. primaryDesc.dwBufferBytes = 0;
  190405. primaryDesc.lpwfxFormat = 0;
  190406. log ("opening dsound out step 2");
  190407. hr = pDirectSound->CreateSoundBuffer (&primaryDesc, &pPrimaryBuffer, 0);
  190408. logError (hr);
  190409. if (hr == S_OK)
  190410. {
  190411. WAVEFORMATEX wfFormat;
  190412. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190413. wfFormat.nChannels = (unsigned short) numChannels;
  190414. wfFormat.nSamplesPerSec = sampleRate;
  190415. wfFormat.wBitsPerSample = (unsigned short) bitDepth;
  190416. wfFormat.nBlockAlign = (unsigned short) (wfFormat.nChannels * wfFormat.wBitsPerSample / 8);
  190417. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190418. wfFormat.cbSize = 0;
  190419. hr = pPrimaryBuffer->SetFormat (&wfFormat);
  190420. logError (hr);
  190421. if (hr == S_OK)
  190422. {
  190423. DSBUFFERDESC secondaryDesc;
  190424. zerostruct (secondaryDesc);
  190425. secondaryDesc.dwSize = sizeof (DSBUFFERDESC);
  190426. secondaryDesc.dwFlags = 0x8000 /* DSBCAPS_GLOBALFOCUS */
  190427. | 0x10000 /* DSBCAPS_GETCURRENTPOSITION2 */;
  190428. secondaryDesc.dwBufferBytes = totalBytesPerBuffer;
  190429. secondaryDesc.lpwfxFormat = &wfFormat;
  190430. hr = pDirectSound->CreateSoundBuffer (&secondaryDesc, &pOutputBuffer, 0);
  190431. logError (hr);
  190432. if (hr == S_OK)
  190433. {
  190434. log ("opening dsound out step 3");
  190435. DWORD dwDataLen;
  190436. unsigned char* pDSBuffData;
  190437. hr = pOutputBuffer->Lock (0, totalBytesPerBuffer,
  190438. (LPVOID*) &pDSBuffData, &dwDataLen, 0, 0, 0);
  190439. logError (hr);
  190440. if (hr == S_OK)
  190441. {
  190442. zeromem (pDSBuffData, dwDataLen);
  190443. hr = pOutputBuffer->Unlock (pDSBuffData, dwDataLen, 0, 0);
  190444. if (hr == S_OK)
  190445. {
  190446. hr = pOutputBuffer->SetCurrentPosition (0);
  190447. if (hr == S_OK)
  190448. {
  190449. hr = pOutputBuffer->Play (0, 0, 1 /* DSBPLAY_LOOPING */);
  190450. if (hr == S_OK)
  190451. return String::empty;
  190452. }
  190453. }
  190454. }
  190455. }
  190456. }
  190457. }
  190458. }
  190459. }
  190460. error = getDSErrorMessage (hr);
  190461. close();
  190462. return error;
  190463. }
  190464. void synchronisePosition()
  190465. {
  190466. if (pOutputBuffer != 0)
  190467. {
  190468. DWORD playCursor;
  190469. pOutputBuffer->GetCurrentPosition (&playCursor, &writeOffset);
  190470. }
  190471. }
  190472. bool service()
  190473. {
  190474. if (pOutputBuffer == 0)
  190475. return true;
  190476. DWORD playCursor, writeCursor;
  190477. for (;;)
  190478. {
  190479. HRESULT hr = pOutputBuffer->GetCurrentPosition (&playCursor, &writeCursor);
  190480. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190481. {
  190482. pOutputBuffer->Restore();
  190483. continue;
  190484. }
  190485. if (hr == S_OK)
  190486. break;
  190487. logError (hr);
  190488. jassertfalse
  190489. return true;
  190490. }
  190491. int playWriteGap = writeCursor - playCursor;
  190492. if (playWriteGap < 0)
  190493. playWriteGap += totalBytesPerBuffer;
  190494. int bytesEmpty = playCursor - writeOffset;
  190495. if (bytesEmpty < 0)
  190496. bytesEmpty += totalBytesPerBuffer;
  190497. if (bytesEmpty > (totalBytesPerBuffer - playWriteGap))
  190498. {
  190499. writeOffset = writeCursor;
  190500. bytesEmpty = totalBytesPerBuffer - playWriteGap;
  190501. }
  190502. if (bytesEmpty >= bytesPerBuffer)
  190503. {
  190504. LPBYTE lpbuf1 = 0;
  190505. LPBYTE lpbuf2 = 0;
  190506. DWORD dwSize1 = 0;
  190507. DWORD dwSize2 = 0;
  190508. HRESULT hr = pOutputBuffer->Lock (writeOffset,
  190509. bytesPerBuffer,
  190510. (void**) &lpbuf1, &dwSize1,
  190511. (void**) &lpbuf2, &dwSize2, 0);
  190512. if (hr == MAKE_HRESULT (1, 0x878, 150)) // DSERR_BUFFERLOST
  190513. {
  190514. pOutputBuffer->Restore();
  190515. hr = pOutputBuffer->Lock (writeOffset,
  190516. bytesPerBuffer,
  190517. (void**) &lpbuf1, &dwSize1,
  190518. (void**) &lpbuf2, &dwSize2, 0);
  190519. }
  190520. if (hr == S_OK)
  190521. {
  190522. if (bitDepth == 16)
  190523. {
  190524. const float gainL = 32767.0f;
  190525. const float gainR = 32767.0f;
  190526. int* dest = (int*)lpbuf1;
  190527. const float* left = leftBuffer;
  190528. const float* right = rightBuffer;
  190529. int samples1 = dwSize1 >> 2;
  190530. int samples2 = dwSize2 >> 2;
  190531. if (left == 0)
  190532. {
  190533. while (--samples1 >= 0)
  190534. {
  190535. int r = roundToInt (gainR * *right++);
  190536. if (r < -32768)
  190537. r = -32768;
  190538. else if (r > 32767)
  190539. r = 32767;
  190540. *dest++ = (r << 16);
  190541. }
  190542. dest = (int*)lpbuf2;
  190543. while (--samples2 >= 0)
  190544. {
  190545. int r = roundToInt (gainR * *right++);
  190546. if (r < -32768)
  190547. r = -32768;
  190548. else if (r > 32767)
  190549. r = 32767;
  190550. *dest++ = (r << 16);
  190551. }
  190552. }
  190553. else if (right == 0)
  190554. {
  190555. while (--samples1 >= 0)
  190556. {
  190557. int l = roundToInt (gainL * *left++);
  190558. if (l < -32768)
  190559. l = -32768;
  190560. else if (l > 32767)
  190561. l = 32767;
  190562. l &= 0xffff;
  190563. *dest++ = l;
  190564. }
  190565. dest = (int*)lpbuf2;
  190566. while (--samples2 >= 0)
  190567. {
  190568. int l = roundToInt (gainL * *left++);
  190569. if (l < -32768)
  190570. l = -32768;
  190571. else if (l > 32767)
  190572. l = 32767;
  190573. l &= 0xffff;
  190574. *dest++ = l;
  190575. }
  190576. }
  190577. else
  190578. {
  190579. while (--samples1 >= 0)
  190580. {
  190581. int l = roundToInt (gainL * *left++);
  190582. if (l < -32768)
  190583. l = -32768;
  190584. else if (l > 32767)
  190585. l = 32767;
  190586. l &= 0xffff;
  190587. int r = roundToInt (gainR * *right++);
  190588. if (r < -32768)
  190589. r = -32768;
  190590. else if (r > 32767)
  190591. r = 32767;
  190592. *dest++ = (r << 16) | l;
  190593. }
  190594. dest = (int*)lpbuf2;
  190595. while (--samples2 >= 0)
  190596. {
  190597. int l = roundToInt (gainL * *left++);
  190598. if (l < -32768)
  190599. l = -32768;
  190600. else if (l > 32767)
  190601. l = 32767;
  190602. l &= 0xffff;
  190603. int r = roundToInt (gainR * *right++);
  190604. if (r < -32768)
  190605. r = -32768;
  190606. else if (r > 32767)
  190607. r = 32767;
  190608. *dest++ = (r << 16) | l;
  190609. }
  190610. }
  190611. }
  190612. else
  190613. {
  190614. jassertfalse
  190615. }
  190616. writeOffset = (writeOffset + dwSize1 + dwSize2) % totalBytesPerBuffer;
  190617. pOutputBuffer->Unlock (lpbuf1, dwSize1, lpbuf2, dwSize2);
  190618. }
  190619. else
  190620. {
  190621. jassertfalse
  190622. logError (hr);
  190623. }
  190624. bytesEmpty -= bytesPerBuffer;
  190625. return true;
  190626. }
  190627. else
  190628. {
  190629. return false;
  190630. }
  190631. }
  190632. };
  190633. struct DSoundInternalInChannel
  190634. {
  190635. String name;
  190636. LPGUID guid;
  190637. int sampleRate, bufferSizeSamples;
  190638. float* leftBuffer;
  190639. float* rightBuffer;
  190640. IDirectSound* pDirectSound;
  190641. IDirectSoundCapture* pDirectSoundCapture;
  190642. IDirectSoundCaptureBuffer* pInputBuffer;
  190643. public:
  190644. unsigned int readOffset;
  190645. int bytesPerBuffer, totalBytesPerBuffer;
  190646. int bitDepth;
  190647. bool doneFlag;
  190648. DSoundInternalInChannel (const String& name_,
  190649. LPGUID guid_,
  190650. int rate,
  190651. int bufferSize,
  190652. float* left,
  190653. float* right)
  190654. : name (name_),
  190655. guid (guid_),
  190656. sampleRate (rate),
  190657. bufferSizeSamples (bufferSize),
  190658. leftBuffer (left),
  190659. rightBuffer (right),
  190660. pDirectSound (0),
  190661. pDirectSoundCapture (0),
  190662. pInputBuffer (0),
  190663. bitDepth (16)
  190664. {
  190665. }
  190666. ~DSoundInternalInChannel()
  190667. {
  190668. close();
  190669. }
  190670. void close()
  190671. {
  190672. HRESULT hr;
  190673. if (pInputBuffer != 0)
  190674. {
  190675. JUCE_TRY
  190676. {
  190677. log (T("closing dsound in: ") + name);
  190678. hr = pInputBuffer->Stop();
  190679. logError (hr);
  190680. }
  190681. CATCH
  190682. JUCE_TRY
  190683. {
  190684. hr = pInputBuffer->Release();
  190685. logError (hr);
  190686. }
  190687. CATCH
  190688. pInputBuffer = 0;
  190689. }
  190690. if (pDirectSoundCapture != 0)
  190691. {
  190692. JUCE_TRY
  190693. {
  190694. hr = pDirectSoundCapture->Release();
  190695. logError (hr);
  190696. }
  190697. CATCH
  190698. pDirectSoundCapture = 0;
  190699. }
  190700. if (pDirectSound != 0)
  190701. {
  190702. JUCE_TRY
  190703. {
  190704. hr = pDirectSound->Release();
  190705. logError (hr);
  190706. }
  190707. CATCH
  190708. pDirectSound = 0;
  190709. }
  190710. }
  190711. const String open()
  190712. {
  190713. log (T("opening dsound in device: ") + name
  190714. + T(" rate=") + String (sampleRate) + T(" bits=") + String (bitDepth) + T(" buf=") + String (bufferSizeSamples));
  190715. pDirectSound = 0;
  190716. pDirectSoundCapture = 0;
  190717. pInputBuffer = 0;
  190718. readOffset = 0;
  190719. totalBytesPerBuffer = 0;
  190720. String error;
  190721. HRESULT hr = E_NOINTERFACE;
  190722. if (dsDirectSoundCaptureCreate != 0)
  190723. hr = dsDirectSoundCaptureCreate (guid, &pDirectSoundCapture, 0);
  190724. logError (hr);
  190725. if (hr == S_OK)
  190726. {
  190727. const int numChannels = 2;
  190728. bytesPerBuffer = (bufferSizeSamples * (bitDepth >> 2)) & ~15;
  190729. totalBytesPerBuffer = (3 * bytesPerBuffer) & ~15;
  190730. WAVEFORMATEX wfFormat;
  190731. wfFormat.wFormatTag = WAVE_FORMAT_PCM;
  190732. wfFormat.nChannels = (unsigned short)numChannels;
  190733. wfFormat.nSamplesPerSec = sampleRate;
  190734. wfFormat.wBitsPerSample = (unsigned short)bitDepth;
  190735. wfFormat.nBlockAlign = (unsigned short)(wfFormat.nChannels * (wfFormat.wBitsPerSample / 8));
  190736. wfFormat.nAvgBytesPerSec = wfFormat.nSamplesPerSec * wfFormat.nBlockAlign;
  190737. wfFormat.cbSize = 0;
  190738. DSCBUFFERDESC captureDesc;
  190739. zerostruct (captureDesc);
  190740. captureDesc.dwSize = sizeof (DSCBUFFERDESC);
  190741. captureDesc.dwFlags = 0;
  190742. captureDesc.dwBufferBytes = totalBytesPerBuffer;
  190743. captureDesc.lpwfxFormat = &wfFormat;
  190744. log (T("opening dsound in step 2"));
  190745. hr = pDirectSoundCapture->CreateCaptureBuffer (&captureDesc, &pInputBuffer, 0);
  190746. logError (hr);
  190747. if (hr == S_OK)
  190748. {
  190749. hr = pInputBuffer->Start (1 /* DSCBSTART_LOOPING */);
  190750. logError (hr);
  190751. if (hr == S_OK)
  190752. return String::empty;
  190753. }
  190754. }
  190755. error = getDSErrorMessage (hr);
  190756. close();
  190757. return error;
  190758. }
  190759. void synchronisePosition()
  190760. {
  190761. if (pInputBuffer != 0)
  190762. {
  190763. DWORD capturePos;
  190764. pInputBuffer->GetCurrentPosition (&capturePos, (DWORD*)&readOffset);
  190765. }
  190766. }
  190767. bool service()
  190768. {
  190769. if (pInputBuffer == 0)
  190770. return true;
  190771. DWORD capturePos, readPos;
  190772. HRESULT hr = pInputBuffer->GetCurrentPosition (&capturePos, &readPos);
  190773. logError (hr);
  190774. if (hr != S_OK)
  190775. return true;
  190776. int bytesFilled = readPos - readOffset;
  190777. if (bytesFilled < 0)
  190778. bytesFilled += totalBytesPerBuffer;
  190779. if (bytesFilled >= bytesPerBuffer)
  190780. {
  190781. LPBYTE lpbuf1 = 0;
  190782. LPBYTE lpbuf2 = 0;
  190783. DWORD dwsize1 = 0;
  190784. DWORD dwsize2 = 0;
  190785. HRESULT hr = pInputBuffer->Lock (readOffset,
  190786. bytesPerBuffer,
  190787. (void**) &lpbuf1, &dwsize1,
  190788. (void**) &lpbuf2, &dwsize2, 0);
  190789. if (hr == S_OK)
  190790. {
  190791. if (bitDepth == 16)
  190792. {
  190793. const float g = 1.0f / 32768.0f;
  190794. float* destL = leftBuffer;
  190795. float* destR = rightBuffer;
  190796. int samples1 = dwsize1 >> 2;
  190797. int samples2 = dwsize2 >> 2;
  190798. const short* src = (const short*)lpbuf1;
  190799. if (destL == 0)
  190800. {
  190801. while (--samples1 >= 0)
  190802. {
  190803. ++src;
  190804. *destR++ = *src++ * g;
  190805. }
  190806. src = (const short*)lpbuf2;
  190807. while (--samples2 >= 0)
  190808. {
  190809. ++src;
  190810. *destR++ = *src++ * g;
  190811. }
  190812. }
  190813. else if (destR == 0)
  190814. {
  190815. while (--samples1 >= 0)
  190816. {
  190817. *destL++ = *src++ * g;
  190818. ++src;
  190819. }
  190820. src = (const short*)lpbuf2;
  190821. while (--samples2 >= 0)
  190822. {
  190823. *destL++ = *src++ * g;
  190824. ++src;
  190825. }
  190826. }
  190827. else
  190828. {
  190829. while (--samples1 >= 0)
  190830. {
  190831. *destL++ = *src++ * g;
  190832. *destR++ = *src++ * g;
  190833. }
  190834. src = (const short*)lpbuf2;
  190835. while (--samples2 >= 0)
  190836. {
  190837. *destL++ = *src++ * g;
  190838. *destR++ = *src++ * g;
  190839. }
  190840. }
  190841. }
  190842. else
  190843. {
  190844. jassertfalse
  190845. }
  190846. readOffset = (readOffset + dwsize1 + dwsize2) % totalBytesPerBuffer;
  190847. pInputBuffer->Unlock (lpbuf1, dwsize1, lpbuf2, dwsize2);
  190848. }
  190849. else
  190850. {
  190851. logError (hr);
  190852. jassertfalse
  190853. }
  190854. bytesFilled -= bytesPerBuffer;
  190855. return true;
  190856. }
  190857. else
  190858. {
  190859. return false;
  190860. }
  190861. }
  190862. };
  190863. class DSoundAudioIODevice : public AudioIODevice,
  190864. public Thread
  190865. {
  190866. public:
  190867. DSoundAudioIODevice (const String& deviceName,
  190868. const int outputDeviceIndex_,
  190869. const int inputDeviceIndex_)
  190870. : AudioIODevice (deviceName, "DirectSound"),
  190871. Thread ("Juce DSound"),
  190872. isOpen_ (false),
  190873. isStarted (false),
  190874. outputDeviceIndex (outputDeviceIndex_),
  190875. inputDeviceIndex (inputDeviceIndex_),
  190876. numInputBuffers (0),
  190877. numOutputBuffers (0),
  190878. totalSamplesOut (0),
  190879. sampleRate (0.0),
  190880. inputBuffers (0),
  190881. outputBuffers (0),
  190882. callback (0),
  190883. bufferSizeSamples (0)
  190884. {
  190885. if (outputDeviceIndex_ >= 0)
  190886. {
  190887. outChannels.add (TRANS("Left"));
  190888. outChannels.add (TRANS("Right"));
  190889. }
  190890. if (inputDeviceIndex_ >= 0)
  190891. {
  190892. inChannels.add (TRANS("Left"));
  190893. inChannels.add (TRANS("Right"));
  190894. }
  190895. }
  190896. ~DSoundAudioIODevice()
  190897. {
  190898. close();
  190899. }
  190900. const StringArray getOutputChannelNames()
  190901. {
  190902. return outChannels;
  190903. }
  190904. const StringArray getInputChannelNames()
  190905. {
  190906. return inChannels;
  190907. }
  190908. int getNumSampleRates()
  190909. {
  190910. return 4;
  190911. }
  190912. double getSampleRate (int index)
  190913. {
  190914. const double samps[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  190915. return samps [jlimit (0, 3, index)];
  190916. }
  190917. int getNumBufferSizesAvailable()
  190918. {
  190919. return 50;
  190920. }
  190921. int getBufferSizeSamples (int index)
  190922. {
  190923. int n = 64;
  190924. for (int i = 0; i < index; ++i)
  190925. n += (n < 512) ? 32
  190926. : ((n < 1024) ? 64
  190927. : ((n < 2048) ? 128 : 256));
  190928. return n;
  190929. }
  190930. int getDefaultBufferSize()
  190931. {
  190932. return 2560;
  190933. }
  190934. const String open (const BitArray& inputChannels,
  190935. const BitArray& outputChannels,
  190936. double sampleRate,
  190937. int bufferSizeSamples)
  190938. {
  190939. lastError = openDevice (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  190940. isOpen_ = lastError.isEmpty();
  190941. return lastError;
  190942. }
  190943. void close()
  190944. {
  190945. stop();
  190946. if (isOpen_)
  190947. {
  190948. closeDevice();
  190949. isOpen_ = false;
  190950. }
  190951. }
  190952. bool isOpen()
  190953. {
  190954. return isOpen_ && isThreadRunning();
  190955. }
  190956. int getCurrentBufferSizeSamples()
  190957. {
  190958. return bufferSizeSamples;
  190959. }
  190960. double getCurrentSampleRate()
  190961. {
  190962. return sampleRate;
  190963. }
  190964. int getCurrentBitDepth()
  190965. {
  190966. int i, bits = 256;
  190967. for (i = inChans.size(); --i >= 0;)
  190968. bits = jmin (bits, inChans[i]->bitDepth);
  190969. for (i = outChans.size(); --i >= 0;)
  190970. bits = jmin (bits, outChans[i]->bitDepth);
  190971. if (bits > 32)
  190972. bits = 16;
  190973. return bits;
  190974. }
  190975. const BitArray getActiveOutputChannels() const
  190976. {
  190977. return enabledOutputs;
  190978. }
  190979. const BitArray getActiveInputChannels() const
  190980. {
  190981. return enabledInputs;
  190982. }
  190983. int getOutputLatencyInSamples()
  190984. {
  190985. return (int) (getCurrentBufferSizeSamples() * 1.5);
  190986. }
  190987. int getInputLatencyInSamples()
  190988. {
  190989. return getOutputLatencyInSamples();
  190990. }
  190991. void start (AudioIODeviceCallback* call)
  190992. {
  190993. if (isOpen_ && call != 0 && ! isStarted)
  190994. {
  190995. if (! isThreadRunning())
  190996. {
  190997. // something gone wrong and the thread's stopped..
  190998. isOpen_ = false;
  190999. return;
  191000. }
  191001. call->audioDeviceAboutToStart (this);
  191002. const ScopedLock sl (startStopLock);
  191003. callback = call;
  191004. isStarted = true;
  191005. }
  191006. }
  191007. void stop()
  191008. {
  191009. if (isStarted)
  191010. {
  191011. AudioIODeviceCallback* const callbackLocal = callback;
  191012. {
  191013. const ScopedLock sl (startStopLock);
  191014. isStarted = false;
  191015. }
  191016. if (callbackLocal != 0)
  191017. callbackLocal->audioDeviceStopped();
  191018. }
  191019. }
  191020. bool isPlaying()
  191021. {
  191022. return isStarted && isOpen_ && isThreadRunning();
  191023. }
  191024. const String getLastError()
  191025. {
  191026. return lastError;
  191027. }
  191028. juce_UseDebuggingNewOperator
  191029. StringArray inChannels, outChannels;
  191030. int outputDeviceIndex, inputDeviceIndex;
  191031. private:
  191032. bool isOpen_;
  191033. bool isStarted;
  191034. String lastError;
  191035. OwnedArray <DSoundInternalInChannel> inChans;
  191036. OwnedArray <DSoundInternalOutChannel> outChans;
  191037. WaitableEvent startEvent;
  191038. int numInputBuffers, numOutputBuffers, bufferSizeSamples;
  191039. int volatile totalSamplesOut;
  191040. int64 volatile lastBlockTime;
  191041. double sampleRate;
  191042. BitArray enabledInputs, enabledOutputs;
  191043. HeapBlock <float*> inputBuffers, outputBuffers;
  191044. AudioIODeviceCallback* callback;
  191045. CriticalSection startStopLock;
  191046. DSoundAudioIODevice (const DSoundAudioIODevice&);
  191047. DSoundAudioIODevice& operator= (const DSoundAudioIODevice&);
  191048. const String openDevice (const BitArray& inputChannels,
  191049. const BitArray& outputChannels,
  191050. double sampleRate_,
  191051. int bufferSizeSamples_);
  191052. void closeDevice()
  191053. {
  191054. isStarted = false;
  191055. stopThread (5000);
  191056. inChans.clear();
  191057. outChans.clear();
  191058. int i;
  191059. for (i = 0; i < numInputBuffers; ++i)
  191060. juce_free (inputBuffers[i]);
  191061. inputBuffers.free();
  191062. numInputBuffers = 0;
  191063. for (i = 0; i < numOutputBuffers; ++i)
  191064. juce_free (outputBuffers[i]);
  191065. outputBuffers.free();
  191066. numOutputBuffers = 0;
  191067. }
  191068. void resync()
  191069. {
  191070. if (! threadShouldExit())
  191071. {
  191072. sleep (5);
  191073. int i;
  191074. for (i = 0; i < outChans.size(); ++i)
  191075. outChans.getUnchecked(i)->synchronisePosition();
  191076. for (i = 0; i < inChans.size(); ++i)
  191077. inChans.getUnchecked(i)->synchronisePosition();
  191078. }
  191079. }
  191080. public:
  191081. void run()
  191082. {
  191083. while (! threadShouldExit())
  191084. {
  191085. if (wait (100))
  191086. break;
  191087. }
  191088. const int latencyMs = (int) (bufferSizeSamples * 1000.0 / sampleRate);
  191089. const int maxTimeMS = jmax (5, 3 * latencyMs);
  191090. while (! threadShouldExit())
  191091. {
  191092. int numToDo = 0;
  191093. uint32 startTime = Time::getMillisecondCounter();
  191094. int i;
  191095. for (i = inChans.size(); --i >= 0;)
  191096. {
  191097. inChans.getUnchecked(i)->doneFlag = false;
  191098. ++numToDo;
  191099. }
  191100. for (i = outChans.size(); --i >= 0;)
  191101. {
  191102. outChans.getUnchecked(i)->doneFlag = false;
  191103. ++numToDo;
  191104. }
  191105. if (numToDo > 0)
  191106. {
  191107. const int maxCount = 3;
  191108. int count = maxCount;
  191109. for (;;)
  191110. {
  191111. for (i = inChans.size(); --i >= 0;)
  191112. {
  191113. DSoundInternalInChannel* const in = inChans.getUnchecked(i);
  191114. if ((! in->doneFlag) && in->service())
  191115. {
  191116. in->doneFlag = true;
  191117. --numToDo;
  191118. }
  191119. }
  191120. for (i = outChans.size(); --i >= 0;)
  191121. {
  191122. DSoundInternalOutChannel* const out = outChans.getUnchecked(i);
  191123. if ((! out->doneFlag) && out->service())
  191124. {
  191125. out->doneFlag = true;
  191126. --numToDo;
  191127. }
  191128. }
  191129. if (numToDo <= 0)
  191130. break;
  191131. if (Time::getMillisecondCounter() > startTime + maxTimeMS)
  191132. {
  191133. resync();
  191134. break;
  191135. }
  191136. if (--count <= 0)
  191137. {
  191138. Sleep (1);
  191139. count = maxCount;
  191140. }
  191141. if (threadShouldExit())
  191142. return;
  191143. }
  191144. }
  191145. else
  191146. {
  191147. sleep (1);
  191148. }
  191149. const ScopedLock sl (startStopLock);
  191150. if (isStarted)
  191151. {
  191152. JUCE_TRY
  191153. {
  191154. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  191155. numInputBuffers,
  191156. outputBuffers,
  191157. numOutputBuffers,
  191158. bufferSizeSamples);
  191159. }
  191160. JUCE_CATCH_EXCEPTION
  191161. totalSamplesOut += bufferSizeSamples;
  191162. }
  191163. else
  191164. {
  191165. for (i = 0; i < numOutputBuffers; ++i)
  191166. if (outputBuffers[i] != 0)
  191167. zeromem (outputBuffers[i], bufferSizeSamples * sizeof (float));
  191168. totalSamplesOut = 0;
  191169. sleep (1);
  191170. }
  191171. }
  191172. }
  191173. };
  191174. class DSoundAudioIODeviceType : public AudioIODeviceType
  191175. {
  191176. public:
  191177. DSoundAudioIODeviceType()
  191178. : AudioIODeviceType (T("DirectSound")),
  191179. hasScanned (false)
  191180. {
  191181. initialiseDSoundFunctions();
  191182. }
  191183. ~DSoundAudioIODeviceType()
  191184. {
  191185. }
  191186. void scanForDevices()
  191187. {
  191188. hasScanned = true;
  191189. outputDeviceNames.clear();
  191190. outputGuids.clear();
  191191. inputDeviceNames.clear();
  191192. inputGuids.clear();
  191193. if (dsDirectSoundEnumerateW != 0)
  191194. {
  191195. dsDirectSoundEnumerateW (outputEnumProcW, this);
  191196. dsDirectSoundCaptureEnumerateW (inputEnumProcW, this);
  191197. }
  191198. }
  191199. const StringArray getDeviceNames (const bool wantInputNames) const
  191200. {
  191201. jassert (hasScanned); // need to call scanForDevices() before doing this
  191202. return wantInputNames ? inputDeviceNames
  191203. : outputDeviceNames;
  191204. }
  191205. int getDefaultDeviceIndex (const bool /*forInput*/) const
  191206. {
  191207. jassert (hasScanned); // need to call scanForDevices() before doing this
  191208. return 0;
  191209. }
  191210. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  191211. {
  191212. jassert (hasScanned); // need to call scanForDevices() before doing this
  191213. DSoundAudioIODevice* const d = dynamic_cast <DSoundAudioIODevice*> (device);
  191214. if (d == 0)
  191215. return -1;
  191216. return asInput ? d->inputDeviceIndex
  191217. : d->outputDeviceIndex;
  191218. }
  191219. bool hasSeparateInputsAndOutputs() const { return true; }
  191220. AudioIODevice* createDevice (const String& outputDeviceName,
  191221. const String& inputDeviceName)
  191222. {
  191223. jassert (hasScanned); // need to call scanForDevices() before doing this
  191224. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  191225. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  191226. if (outputIndex >= 0 || inputIndex >= 0)
  191227. return new DSoundAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  191228. : inputDeviceName,
  191229. outputIndex, inputIndex);
  191230. return 0;
  191231. }
  191232. juce_UseDebuggingNewOperator
  191233. StringArray outputDeviceNames;
  191234. OwnedArray <GUID> outputGuids;
  191235. StringArray inputDeviceNames;
  191236. OwnedArray <GUID> inputGuids;
  191237. private:
  191238. bool hasScanned;
  191239. BOOL outputEnumProc (LPGUID lpGUID, String desc)
  191240. {
  191241. desc = desc.trim();
  191242. if (desc.isNotEmpty())
  191243. {
  191244. const String origDesc (desc);
  191245. int n = 2;
  191246. while (outputDeviceNames.contains (desc))
  191247. desc = origDesc + T(" (") + String (n++) + T(")");
  191248. outputDeviceNames.add (desc);
  191249. if (lpGUID != 0)
  191250. outputGuids.add (new GUID (*lpGUID));
  191251. else
  191252. outputGuids.add (0);
  191253. }
  191254. return TRUE;
  191255. }
  191256. static BOOL CALLBACK outputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  191257. {
  191258. return ((DSoundAudioIODeviceType*) object)
  191259. ->outputEnumProc (lpGUID, String (description));
  191260. }
  191261. static BOOL CALLBACK outputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  191262. {
  191263. return ((DSoundAudioIODeviceType*) object)
  191264. ->outputEnumProc (lpGUID, String (description));
  191265. }
  191266. BOOL CALLBACK inputEnumProc (LPGUID lpGUID, String desc)
  191267. {
  191268. desc = desc.trim();
  191269. if (desc.isNotEmpty())
  191270. {
  191271. const String origDesc (desc);
  191272. int n = 2;
  191273. while (inputDeviceNames.contains (desc))
  191274. desc = origDesc + T(" (") + String (n++) + T(")");
  191275. inputDeviceNames.add (desc);
  191276. if (lpGUID != 0)
  191277. inputGuids.add (new GUID (*lpGUID));
  191278. else
  191279. inputGuids.add (0);
  191280. }
  191281. return TRUE;
  191282. }
  191283. static BOOL CALLBACK inputEnumProcW (LPGUID lpGUID, LPCWSTR description, LPCWSTR, LPVOID object)
  191284. {
  191285. return ((DSoundAudioIODeviceType*) object)
  191286. ->inputEnumProc (lpGUID, String (description));
  191287. }
  191288. static BOOL CALLBACK inputEnumProcA (LPGUID lpGUID, LPCTSTR description, LPCTSTR, LPVOID object)
  191289. {
  191290. return ((DSoundAudioIODeviceType*) object)
  191291. ->inputEnumProc (lpGUID, String (description));
  191292. }
  191293. DSoundAudioIODeviceType (const DSoundAudioIODeviceType&);
  191294. DSoundAudioIODeviceType& operator= (const DSoundAudioIODeviceType&);
  191295. };
  191296. const String DSoundAudioIODevice::openDevice (const BitArray& inputChannels,
  191297. const BitArray& outputChannels,
  191298. double sampleRate_,
  191299. int bufferSizeSamples_)
  191300. {
  191301. closeDevice();
  191302. totalSamplesOut = 0;
  191303. sampleRate = sampleRate_;
  191304. if (bufferSizeSamples_ <= 0)
  191305. bufferSizeSamples_ = 960; // use as a default size if none is set.
  191306. bufferSizeSamples = bufferSizeSamples_ & ~7;
  191307. DSoundAudioIODeviceType dlh;
  191308. dlh.scanForDevices();
  191309. enabledInputs = inputChannels;
  191310. enabledInputs.setRange (inChannels.size(),
  191311. enabledInputs.getHighestBit() + 1 - inChannels.size(),
  191312. false);
  191313. numInputBuffers = enabledInputs.countNumberOfSetBits();
  191314. inputBuffers.calloc (numInputBuffers + 2);
  191315. int i, numIns = 0;
  191316. for (i = 0; i <= enabledInputs.getHighestBit(); i += 2)
  191317. {
  191318. float* left = 0;
  191319. float* right = 0;
  191320. if (enabledInputs[i])
  191321. left = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191322. if (enabledInputs[i + 1])
  191323. right = inputBuffers[numIns++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191324. if (left != 0 || right != 0)
  191325. inChans.add (new DSoundInternalInChannel (dlh.inputDeviceNames [inputDeviceIndex],
  191326. dlh.inputGuids [inputDeviceIndex],
  191327. (int) sampleRate, bufferSizeSamples,
  191328. left, right));
  191329. }
  191330. enabledOutputs = outputChannels;
  191331. enabledOutputs.setRange (outChannels.size(),
  191332. enabledOutputs.getHighestBit() + 1 - outChannels.size(),
  191333. false);
  191334. numOutputBuffers = enabledOutputs.countNumberOfSetBits();
  191335. outputBuffers.calloc (numOutputBuffers + 2);
  191336. int numOuts = 0;
  191337. for (i = 0; i <= enabledOutputs.getHighestBit(); i += 2)
  191338. {
  191339. float* left = 0;
  191340. float* right = 0;
  191341. if (enabledOutputs[i])
  191342. left = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191343. if (enabledOutputs[i + 1])
  191344. right = outputBuffers[numOuts++] = (float*) juce_calloc ((bufferSizeSamples + 16) * sizeof (float));
  191345. if (left != 0 || right != 0)
  191346. outChans.add (new DSoundInternalOutChannel (dlh.outputDeviceNames[outputDeviceIndex],
  191347. dlh.outputGuids [outputDeviceIndex],
  191348. (int) sampleRate, bufferSizeSamples,
  191349. left, right));
  191350. }
  191351. String error;
  191352. // boost our priority while opening the devices to try to get better sync between them
  191353. const int oldThreadPri = GetThreadPriority (GetCurrentThread());
  191354. const int oldProcPri = GetPriorityClass (GetCurrentProcess());
  191355. SetThreadPriority (GetCurrentThread(), THREAD_PRIORITY_TIME_CRITICAL);
  191356. SetPriorityClass (GetCurrentProcess(), REALTIME_PRIORITY_CLASS);
  191357. for (i = 0; i < outChans.size(); ++i)
  191358. {
  191359. error = outChans[i]->open();
  191360. if (error.isNotEmpty())
  191361. {
  191362. error = T("Error opening ") + dlh.outputDeviceNames[i]
  191363. + T(": \"") + error + T("\"");
  191364. break;
  191365. }
  191366. }
  191367. if (error.isEmpty())
  191368. {
  191369. for (i = 0; i < inChans.size(); ++i)
  191370. {
  191371. error = inChans[i]->open();
  191372. if (error.isNotEmpty())
  191373. {
  191374. error = T("Error opening ") + dlh.inputDeviceNames[i]
  191375. + T(": \"") + error + T("\"");
  191376. break;
  191377. }
  191378. }
  191379. }
  191380. if (error.isEmpty())
  191381. {
  191382. totalSamplesOut = 0;
  191383. for (i = 0; i < outChans.size(); ++i)
  191384. outChans.getUnchecked(i)->synchronisePosition();
  191385. for (i = 0; i < inChans.size(); ++i)
  191386. inChans.getUnchecked(i)->synchronisePosition();
  191387. startThread (9);
  191388. sleep (10);
  191389. notify();
  191390. }
  191391. else
  191392. {
  191393. log (error);
  191394. }
  191395. SetThreadPriority (GetCurrentThread(), oldThreadPri);
  191396. SetPriorityClass (GetCurrentProcess(), oldProcPri);
  191397. return error;
  191398. }
  191399. AudioIODeviceType* juce_createAudioIODeviceType_DirectSound()
  191400. {
  191401. return new DSoundAudioIODeviceType();
  191402. }
  191403. #undef log
  191404. #endif
  191405. /*** End of inlined file: juce_win32_DirectSound.cpp ***/
  191406. /*** Start of inlined file: juce_win32_WASAPI.cpp ***/
  191407. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  191408. // compiled on its own).
  191409. #if JUCE_INCLUDED_FILE && JUCE_WASAPI
  191410. #if 1
  191411. const String getAudioErrorDesc (HRESULT hr)
  191412. {
  191413. const char* e = 0;
  191414. switch (hr)
  191415. {
  191416. case E_POINTER: e = "E_POINTER"; break;
  191417. case E_INVALIDARG: e = "E_INVALIDARG"; break;
  191418. case AUDCLNT_E_NOT_INITIALIZED: e = "AUDCLNT_E_NOT_INITIALIZED"; break;
  191419. case AUDCLNT_E_ALREADY_INITIALIZED: e = "AUDCLNT_E_ALREADY_INITIALIZED"; break;
  191420. case AUDCLNT_E_WRONG_ENDPOINT_TYPE: e = "AUDCLNT_E_WRONG_ENDPOINT_TYPE"; break;
  191421. case AUDCLNT_E_DEVICE_INVALIDATED: e = "AUDCLNT_E_DEVICE_INVALIDATED"; break;
  191422. case AUDCLNT_E_NOT_STOPPED: e = "AUDCLNT_E_NOT_STOPPED"; break;
  191423. case AUDCLNT_E_BUFFER_TOO_LARGE: e = "AUDCLNT_E_BUFFER_TOO_LARGE"; break;
  191424. case AUDCLNT_E_OUT_OF_ORDER: e = "AUDCLNT_E_OUT_OF_ORDER"; break;
  191425. case AUDCLNT_E_UNSUPPORTED_FORMAT: e = "AUDCLNT_E_UNSUPPORTED_FORMAT"; break;
  191426. case AUDCLNT_E_INVALID_SIZE: e = "AUDCLNT_E_INVALID_SIZE"; break;
  191427. case AUDCLNT_E_DEVICE_IN_USE: e = "AUDCLNT_E_DEVICE_IN_USE"; break;
  191428. case AUDCLNT_E_BUFFER_OPERATION_PENDING: e = "AUDCLNT_E_BUFFER_OPERATION_PENDING"; break;
  191429. case AUDCLNT_E_THREAD_NOT_REGISTERED: e = "AUDCLNT_E_THREAD_NOT_REGISTERED"; break;
  191430. case AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED: e = "AUDCLNT_E_EXCLUSIVE_MODE_NOT_ALLOWED"; break;
  191431. case AUDCLNT_E_ENDPOINT_CREATE_FAILED: e = "AUDCLNT_E_ENDPOINT_CREATE_FAILED"; break;
  191432. case AUDCLNT_E_SERVICE_NOT_RUNNING: e = "AUDCLNT_E_SERVICE_NOT_RUNNING"; break;
  191433. case AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED: e = "AUDCLNT_E_EVENTHANDLE_NOT_EXPECTED"; break;
  191434. case AUDCLNT_E_EXCLUSIVE_MODE_ONLY: e = "AUDCLNT_E_EXCLUSIVE_MODE_ONLY"; break;
  191435. case AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL: e = "AUDCLNT_E_BUFDURATION_PERIOD_NOT_EQUAL"; break;
  191436. case AUDCLNT_E_EVENTHANDLE_NOT_SET: e = "AUDCLNT_E_EVENTHANDLE_NOT_SET"; break;
  191437. case AUDCLNT_E_INCORRECT_BUFFER_SIZE: e = "AUDCLNT_E_INCORRECT_BUFFER_SIZE"; break;
  191438. case AUDCLNT_E_BUFFER_SIZE_ERROR: e = "AUDCLNT_E_BUFFER_SIZE_ERROR"; break;
  191439. case AUDCLNT_S_BUFFER_EMPTY: e = "AUDCLNT_S_BUFFER_EMPTY"; break;
  191440. case AUDCLNT_S_THREAD_ALREADY_REGISTERED: e = "AUDCLNT_S_THREAD_ALREADY_REGISTERED"; break;
  191441. default: return String::toHexString ((int) hr);
  191442. }
  191443. return e;
  191444. }
  191445. #define logFailure(hr) { if (FAILED (hr)) { DBG ("WASAPI FAIL! " + getAudioErrorDesc (hr)); jassertfalse } }
  191446. #define OK(a) wasapi_checkResult(a)
  191447. static bool wasapi_checkResult (HRESULT hr)
  191448. {
  191449. logFailure (hr);
  191450. return SUCCEEDED (hr);
  191451. }
  191452. #else
  191453. #define logFailure(hr) {}
  191454. #define OK(a) SUCCEEDED(a)
  191455. #endif
  191456. static const String wasapi_getDeviceID (IMMDevice* const device)
  191457. {
  191458. String s;
  191459. WCHAR* deviceId = 0;
  191460. if (OK (device->GetId (&deviceId)))
  191461. {
  191462. s = String (deviceId);
  191463. CoTaskMemFree (deviceId);
  191464. }
  191465. return s;
  191466. }
  191467. static EDataFlow wasapi_getDataFlow (IMMDevice* const device)
  191468. {
  191469. EDataFlow flow = eRender;
  191470. ComSmartPtr <IMMEndpoint> endPoint;
  191471. if (OK (device->QueryInterface (__uuidof (IMMEndpoint), (void**) &endPoint)))
  191472. (void) OK (endPoint->GetDataFlow (&flow));
  191473. return flow;
  191474. }
  191475. static int wasapi_refTimeToSamples (const REFERENCE_TIME& t, const double sampleRate) throw()
  191476. {
  191477. return roundDoubleToInt (sampleRate * ((double) t) * 0.0000001);
  191478. }
  191479. static void wasapi_copyWavFormat (WAVEFORMATEXTENSIBLE& dest, const WAVEFORMATEX* const src) throw()
  191480. {
  191481. memcpy (&dest, src, src->wFormatTag == WAVE_FORMAT_EXTENSIBLE ? sizeof (WAVEFORMATEXTENSIBLE)
  191482. : sizeof (WAVEFORMATEX));
  191483. }
  191484. class WASAPIDeviceBase
  191485. {
  191486. public:
  191487. WASAPIDeviceBase (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191488. : device (device_),
  191489. sampleRate (0),
  191490. numChannels (0),
  191491. actualNumChannels (0),
  191492. defaultSampleRate (0),
  191493. minBufferSize (0),
  191494. defaultBufferSize (0),
  191495. latencySamples (0),
  191496. useExclusiveMode (useExclusiveMode_)
  191497. {
  191498. clientEvent = CreateEvent (0, false, false, _T("JuceWASAPI"));
  191499. ComSmartPtr <IAudioClient> tempClient (createClient());
  191500. if (tempClient == 0)
  191501. return;
  191502. REFERENCE_TIME defaultPeriod, minPeriod;
  191503. if (! OK (tempClient->GetDevicePeriod (&defaultPeriod, &minPeriod)))
  191504. return;
  191505. WAVEFORMATEX* mixFormat = 0;
  191506. if (! OK (tempClient->GetMixFormat (&mixFormat)))
  191507. return;
  191508. WAVEFORMATEXTENSIBLE format;
  191509. wasapi_copyWavFormat (format, mixFormat);
  191510. CoTaskMemFree (mixFormat);
  191511. actualNumChannels = numChannels = format.Format.nChannels;
  191512. defaultSampleRate = format.Format.nSamplesPerSec;
  191513. minBufferSize = wasapi_refTimeToSamples (minPeriod, defaultSampleRate);
  191514. defaultBufferSize = wasapi_refTimeToSamples (defaultPeriod, defaultSampleRate);
  191515. FloatElementComparator<double> comparator;
  191516. rates.addSorted (comparator, defaultSampleRate);
  191517. static const double ratesToTest[] = { 44100.0, 48000.0, 88200.0, 96000.0 };
  191518. for (int i = 0; i < numElementsInArray (ratesToTest); ++i)
  191519. {
  191520. if (ratesToTest[i] == defaultSampleRate)
  191521. continue;
  191522. format.Format.nSamplesPerSec = roundDoubleToInt (ratesToTest[i]);
  191523. if (SUCCEEDED (tempClient->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191524. (WAVEFORMATEX*) &format, 0)))
  191525. if (! rates.contains (ratesToTest[i]))
  191526. rates.addSorted (comparator, ratesToTest[i]);
  191527. }
  191528. }
  191529. ~WASAPIDeviceBase()
  191530. {
  191531. device = 0;
  191532. CloseHandle (clientEvent);
  191533. }
  191534. bool isOk() const throw() { return defaultBufferSize > 0 && defaultSampleRate > 0; }
  191535. bool openClient (const double newSampleRate, const BitArray& newChannels)
  191536. {
  191537. sampleRate = newSampleRate;
  191538. channels = newChannels;
  191539. channels.setRange (actualNumChannels, channels.getHighestBit() + 1 - actualNumChannels, false);
  191540. numChannels = channels.getHighestBit() + 1;
  191541. if (numChannels == 0)
  191542. return true;
  191543. client = createClient();
  191544. if (client != 0
  191545. && (tryInitialisingWithFormat (true, 4) || tryInitialisingWithFormat (false, 4)
  191546. || tryInitialisingWithFormat (false, 3) || tryInitialisingWithFormat (false, 2)))
  191547. {
  191548. channelMaps.clear();
  191549. for (int i = 0; i <= channels.getHighestBit(); ++i)
  191550. if (channels[i])
  191551. channelMaps.add (i);
  191552. REFERENCE_TIME latency;
  191553. if (OK (client->GetStreamLatency (&latency)))
  191554. latencySamples = wasapi_refTimeToSamples (latency, sampleRate);
  191555. (void) OK (client->GetBufferSize (&actualBufferSize));
  191556. return OK (client->SetEventHandle (clientEvent));
  191557. }
  191558. return false;
  191559. }
  191560. void closeClient()
  191561. {
  191562. if (client != 0)
  191563. client->Stop();
  191564. client = 0;
  191565. ResetEvent (clientEvent);
  191566. }
  191567. ComSmartPtr <IMMDevice> device;
  191568. ComSmartPtr <IAudioClient> client;
  191569. double sampleRate, defaultSampleRate;
  191570. int numChannels, actualNumChannels;
  191571. int minBufferSize, defaultBufferSize, latencySamples;
  191572. const bool useExclusiveMode;
  191573. Array <double> rates;
  191574. HANDLE clientEvent;
  191575. BitArray channels;
  191576. AudioDataConverters::DataFormat dataFormat;
  191577. Array <int> channelMaps;
  191578. UINT32 actualBufferSize;
  191579. int bytesPerSample;
  191580. private:
  191581. const ComSmartPtr <IAudioClient> createClient()
  191582. {
  191583. ComSmartPtr <IAudioClient> client;
  191584. if (device != 0)
  191585. {
  191586. HRESULT hr = device->Activate (__uuidof (IAudioClient), CLSCTX_INPROC_SERVER, 0, (void**) &client);
  191587. logFailure (hr);
  191588. }
  191589. return client;
  191590. }
  191591. bool tryInitialisingWithFormat (const bool useFloat, const int bytesPerSampleToTry)
  191592. {
  191593. WAVEFORMATEXTENSIBLE format;
  191594. zerostruct (format);
  191595. if (numChannels <= 2 && bytesPerSampleToTry <= 2)
  191596. {
  191597. format.Format.wFormatTag = WAVE_FORMAT_PCM;
  191598. }
  191599. else
  191600. {
  191601. format.Format.wFormatTag = WAVE_FORMAT_EXTENSIBLE;
  191602. format.Format.cbSize = sizeof (WAVEFORMATEXTENSIBLE) - sizeof (WAVEFORMATEX);
  191603. }
  191604. format.Format.nSamplesPerSec = roundDoubleToInt (sampleRate);
  191605. format.Format.nChannels = (WORD) numChannels;
  191606. format.Format.wBitsPerSample = (WORD) (8 * bytesPerSampleToTry);
  191607. format.Format.nAvgBytesPerSec = (DWORD) (format.Format.nSamplesPerSec * numChannels * bytesPerSampleToTry);
  191608. format.Format.nBlockAlign = (WORD) (numChannels * bytesPerSampleToTry);
  191609. format.SubFormat = useFloat ? KSDATAFORMAT_SUBTYPE_IEEE_FLOAT : KSDATAFORMAT_SUBTYPE_PCM;
  191610. format.Samples.wValidBitsPerSample = format.Format.wBitsPerSample;
  191611. switch (numChannels)
  191612. {
  191613. case 1: format.dwChannelMask = SPEAKER_FRONT_CENTER; break;
  191614. case 2: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT; break;
  191615. case 4: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191616. case 6: format.dwChannelMask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT | SPEAKER_FRONT_CENTER | SPEAKER_LOW_FREQUENCY | SPEAKER_BACK_LEFT | SPEAKER_BACK_RIGHT; break;
  191617. 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;
  191618. default: break;
  191619. }
  191620. WAVEFORMATEXTENSIBLE* nearestFormat = 0;
  191621. HRESULT hr = client->IsFormatSupported (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191622. (WAVEFORMATEX*) &format, useExclusiveMode ? 0 : (WAVEFORMATEX**) &nearestFormat);
  191623. logFailure (hr);
  191624. if (hr == S_FALSE && format.Format.nSamplesPerSec == nearestFormat->Format.nSamplesPerSec)
  191625. {
  191626. wasapi_copyWavFormat (format, (WAVEFORMATEX*) nearestFormat);
  191627. hr = S_OK;
  191628. }
  191629. CoTaskMemFree (nearestFormat);
  191630. REFERENCE_TIME defaultPeriod = 0, minPeriod = 0;
  191631. if (useExclusiveMode)
  191632. OK (client->GetDevicePeriod (&defaultPeriod, &minPeriod));
  191633. GUID session;
  191634. if (hr == S_OK
  191635. && OK (client->Initialize (useExclusiveMode ? AUDCLNT_SHAREMODE_EXCLUSIVE : AUDCLNT_SHAREMODE_SHARED,
  191636. AUDCLNT_STREAMFLAGS_EVENTCALLBACK,
  191637. defaultPeriod, defaultPeriod, (WAVEFORMATEX*) &format, &session)))
  191638. {
  191639. actualNumChannels = format.Format.nChannels;
  191640. const bool isFloat = format.Format.wFormatTag == WAVE_FORMAT_EXTENSIBLE && format.SubFormat == KSDATAFORMAT_SUBTYPE_IEEE_FLOAT;
  191641. bytesPerSample = format.Format.wBitsPerSample / 8;
  191642. dataFormat = isFloat ? AudioDataConverters::float32LE
  191643. : (bytesPerSample == 4 ? AudioDataConverters::int32LE
  191644. : ((bytesPerSample == 3 ? AudioDataConverters::int24LE
  191645. : AudioDataConverters::int16LE)));
  191646. return true;
  191647. }
  191648. return false;
  191649. }
  191650. };
  191651. class WASAPIInputDevice : public WASAPIDeviceBase
  191652. {
  191653. public:
  191654. WASAPIInputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191655. : WASAPIDeviceBase (device_, useExclusiveMode_),
  191656. reservoir (1, 1)
  191657. {
  191658. }
  191659. ~WASAPIInputDevice()
  191660. {
  191661. close();
  191662. }
  191663. bool open (const double newSampleRate, const BitArray& newChannels)
  191664. {
  191665. reservoirSize = 0;
  191666. reservoirCapacity = 16384;
  191667. reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
  191668. return openClient (newSampleRate, newChannels)
  191669. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
  191670. }
  191671. void close()
  191672. {
  191673. closeClient();
  191674. captureClient = 0;
  191675. reservoir.setSize (0);
  191676. }
  191677. void copyBuffers (float** destBuffers, int numDestBuffers, int bufferSize, Thread& thread)
  191678. {
  191679. if (numChannels <= 0)
  191680. return;
  191681. int offset = 0;
  191682. while (bufferSize > 0)
  191683. {
  191684. if (reservoirSize > 0) // There's stuff in the reservoir, so use that...
  191685. {
  191686. const int samplesToDo = jmin (bufferSize, (int) reservoirSize);
  191687. for (int i = 0; i < numDestBuffers; ++i)
  191688. {
  191689. float* const dest = destBuffers[i] + offset;
  191690. const int srcChan = channelMaps.getUnchecked(i);
  191691. switch (dataFormat)
  191692. {
  191693. case AudioDataConverters::float32LE:
  191694. AudioDataConverters::convertFloat32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191695. break;
  191696. case AudioDataConverters::int32LE:
  191697. AudioDataConverters::convertInt32LEToFloat (((uint8*) reservoir.getData()) + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191698. break;
  191699. case AudioDataConverters::int24LE:
  191700. AudioDataConverters::convertInt24LEToFloat (((uint8*) reservoir.getData()) + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191701. break;
  191702. case AudioDataConverters::int16LE:
  191703. AudioDataConverters::convertInt16LEToFloat (((uint8*) reservoir.getData()) + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191704. break;
  191705. default: jassertfalse; break;
  191706. }
  191707. }
  191708. bufferSize -= samplesToDo;
  191709. offset += samplesToDo;
  191710. reservoirSize -= samplesToDo;
  191711. }
  191712. else
  191713. {
  191714. UINT32 packetLength = 0;
  191715. if (! OK (captureClient->GetNextPacketSize (&packetLength)))
  191716. break;
  191717. if (packetLength == 0)
  191718. {
  191719. if (thread.threadShouldExit())
  191720. break;
  191721. Thread::sleep (1);
  191722. continue;
  191723. }
  191724. uint8* inputData = 0;
  191725. UINT32 numSamplesAvailable;
  191726. DWORD flags;
  191727. if (OK (captureClient->GetBuffer (&inputData, &numSamplesAvailable, &flags, 0, 0)))
  191728. {
  191729. const int samplesToDo = jmin (bufferSize, (int) numSamplesAvailable);
  191730. for (int i = 0; i < numDestBuffers; ++i)
  191731. {
  191732. float* const dest = destBuffers[i] + offset;
  191733. const int srcChan = channelMaps.getUnchecked(i);
  191734. switch (dataFormat)
  191735. {
  191736. case AudioDataConverters::float32LE:
  191737. AudioDataConverters::convertFloat32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191738. break;
  191739. case AudioDataConverters::int32LE:
  191740. AudioDataConverters::convertInt32LEToFloat (inputData + 4 * srcChan, dest, samplesToDo, 4 * actualNumChannels);
  191741. break;
  191742. case AudioDataConverters::int24LE:
  191743. AudioDataConverters::convertInt24LEToFloat (inputData + 3 * srcChan, dest, samplesToDo, 3 * actualNumChannels);
  191744. break;
  191745. case AudioDataConverters::int16LE:
  191746. AudioDataConverters::convertInt16LEToFloat (inputData + 2 * srcChan, dest, samplesToDo, 2 * actualNumChannels);
  191747. break;
  191748. default: jassertfalse; break;
  191749. }
  191750. }
  191751. bufferSize -= samplesToDo;
  191752. offset += samplesToDo;
  191753. if (samplesToDo < (int) numSamplesAvailable)
  191754. {
  191755. reservoirSize = jmin ((int) (numSamplesAvailable - samplesToDo), reservoirCapacity);
  191756. memcpy ((uint8*) reservoir.getData(), inputData + bytesPerSample * actualNumChannels * samplesToDo,
  191757. bytesPerSample * actualNumChannels * reservoirSize);
  191758. }
  191759. captureClient->ReleaseBuffer (numSamplesAvailable);
  191760. }
  191761. }
  191762. }
  191763. }
  191764. ComSmartPtr <IAudioCaptureClient> captureClient;
  191765. MemoryBlock reservoir;
  191766. int reservoirSize, reservoirCapacity;
  191767. };
  191768. class WASAPIOutputDevice : public WASAPIDeviceBase
  191769. {
  191770. public:
  191771. WASAPIOutputDevice (const ComSmartPtr <IMMDevice>& device_, const bool useExclusiveMode_)
  191772. : WASAPIDeviceBase (device_, useExclusiveMode_)
  191773. {
  191774. }
  191775. ~WASAPIOutputDevice()
  191776. {
  191777. close();
  191778. }
  191779. bool open (const double newSampleRate, const BitArray& newChannels)
  191780. {
  191781. return openClient (newSampleRate, newChannels)
  191782. && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
  191783. }
  191784. void close()
  191785. {
  191786. closeClient();
  191787. renderClient = 0;
  191788. }
  191789. void copyBuffers (const float** const srcBuffers, const int numSrcBuffers, int bufferSize, Thread& thread)
  191790. {
  191791. if (numChannels <= 0)
  191792. return;
  191793. int offset = 0;
  191794. while (bufferSize > 0)
  191795. {
  191796. UINT32 padding = 0;
  191797. if (! OK (client->GetCurrentPadding (&padding)))
  191798. return;
  191799. int samplesToDo = useExclusiveMode ? bufferSize
  191800. : jmin ((int) (actualBufferSize - padding), bufferSize);
  191801. if (samplesToDo <= 0)
  191802. {
  191803. if (thread.threadShouldExit())
  191804. break;
  191805. Thread::sleep (0);
  191806. continue;
  191807. }
  191808. uint8* outputData = 0;
  191809. if (OK (renderClient->GetBuffer (samplesToDo, &outputData)))
  191810. {
  191811. for (int i = 0; i < numSrcBuffers; ++i)
  191812. {
  191813. const float* const source = srcBuffers[i] + offset;
  191814. const int destChan = channelMaps.getUnchecked(i);
  191815. switch (dataFormat)
  191816. {
  191817. case AudioDataConverters::float32LE:
  191818. AudioDataConverters::convertFloatToFloat32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191819. break;
  191820. case AudioDataConverters::int32LE:
  191821. AudioDataConverters::convertFloatToInt32LE (source, outputData + 4 * destChan, samplesToDo, 4 * actualNumChannels);
  191822. break;
  191823. case AudioDataConverters::int24LE:
  191824. AudioDataConverters::convertFloatToInt24LE (source, outputData + 3 * destChan, samplesToDo, 3 * actualNumChannels);
  191825. break;
  191826. case AudioDataConverters::int16LE:
  191827. AudioDataConverters::convertFloatToInt16LE (source, outputData + 2 * destChan, samplesToDo, 2 * actualNumChannels);
  191828. break;
  191829. default: jassertfalse; break;
  191830. }
  191831. }
  191832. renderClient->ReleaseBuffer (samplesToDo, 0);
  191833. offset += samplesToDo;
  191834. bufferSize -= samplesToDo;
  191835. }
  191836. }
  191837. }
  191838. ComSmartPtr <IAudioRenderClient> renderClient;
  191839. };
  191840. class WASAPIAudioIODevice : public AudioIODevice,
  191841. public Thread
  191842. {
  191843. public:
  191844. WASAPIAudioIODevice (const String& deviceName,
  191845. const String& outputDeviceId_,
  191846. const String& inputDeviceId_,
  191847. const bool useExclusiveMode_)
  191848. : AudioIODevice (deviceName, "Windows Audio"),
  191849. Thread ("Juce WASAPI"),
  191850. isOpen_ (false),
  191851. isStarted (false),
  191852. outputDevice (0),
  191853. outputDeviceId (outputDeviceId_),
  191854. inputDevice (0),
  191855. inputDeviceId (inputDeviceId_),
  191856. useExclusiveMode (useExclusiveMode_),
  191857. currentBufferSizeSamples (0),
  191858. currentSampleRate (0),
  191859. callback (0)
  191860. {
  191861. }
  191862. ~WASAPIAudioIODevice()
  191863. {
  191864. close();
  191865. deleteAndZero (inputDevice);
  191866. deleteAndZero (outputDevice);
  191867. }
  191868. bool initialise()
  191869. {
  191870. double defaultSampleRateIn = 0, defaultSampleRateOut = 0;
  191871. int minBufferSizeIn = 0, defaultBufferSizeIn = 0, minBufferSizeOut = 0, defaultBufferSizeOut = 0;
  191872. latencyIn = latencyOut = 0;
  191873. Array <double> ratesIn, ratesOut;
  191874. if (createDevices())
  191875. {
  191876. jassert (inputDevice != 0 || outputDevice != 0);
  191877. if (inputDevice != 0 && outputDevice != 0)
  191878. {
  191879. defaultSampleRate = jmin (inputDevice->defaultSampleRate, outputDevice->defaultSampleRate);
  191880. minBufferSize = jmin (inputDevice->minBufferSize, outputDevice->minBufferSize);
  191881. defaultBufferSize = jmax (inputDevice->defaultBufferSize, outputDevice->defaultBufferSize);
  191882. sampleRates = inputDevice->rates;
  191883. sampleRates.removeValuesNotIn (outputDevice->rates);
  191884. }
  191885. else
  191886. {
  191887. WASAPIDeviceBase* const d = inputDevice != 0 ? (WASAPIDeviceBase*) inputDevice : (WASAPIDeviceBase*) outputDevice;
  191888. defaultSampleRate = d->defaultSampleRate;
  191889. minBufferSize = d->minBufferSize;
  191890. defaultBufferSize = d->defaultBufferSize;
  191891. sampleRates = d->rates;
  191892. }
  191893. IntegerElementComparator<int> comparator;
  191894. bufferSizes.addSorted (comparator, defaultBufferSize);
  191895. if (minBufferSize != defaultBufferSize)
  191896. bufferSizes.addSorted (comparator, minBufferSize);
  191897. int n = 64;
  191898. for (int i = 0; i < 40; ++i)
  191899. {
  191900. if (n >= minBufferSize && n <= 2048 && ! bufferSizes.contains (n))
  191901. bufferSizes.addSorted (comparator, n);
  191902. n += (n < 512) ? 32 : (n < 1024 ? 64 : 128);
  191903. }
  191904. return true;
  191905. }
  191906. return false;
  191907. }
  191908. const StringArray getOutputChannelNames()
  191909. {
  191910. StringArray outChannels;
  191911. if (outputDevice != 0)
  191912. for (int i = 1; i <= outputDevice->actualNumChannels; ++i)
  191913. outChannels.add ("Output channel " + String (i));
  191914. return outChannels;
  191915. }
  191916. const StringArray getInputChannelNames()
  191917. {
  191918. StringArray inChannels;
  191919. if (inputDevice != 0)
  191920. for (int i = 1; i <= inputDevice->actualNumChannels; ++i)
  191921. inChannels.add ("Input channel " + String (i));
  191922. return inChannels;
  191923. }
  191924. int getNumSampleRates() { return sampleRates.size(); }
  191925. double getSampleRate (int index) { return sampleRates [index]; }
  191926. int getNumBufferSizesAvailable() { return bufferSizes.size(); }
  191927. int getBufferSizeSamples (int index) { return bufferSizes [index]; }
  191928. int getDefaultBufferSize() { return defaultBufferSize; }
  191929. int getCurrentBufferSizeSamples() { return currentBufferSizeSamples; }
  191930. double getCurrentSampleRate() { return currentSampleRate; }
  191931. int getCurrentBitDepth() { return 32; }
  191932. int getOutputLatencyInSamples() { return latencyOut; }
  191933. int getInputLatencyInSamples() { return latencyIn; }
  191934. const BitArray getActiveOutputChannels() const { return outputDevice != 0 ? outputDevice->channels : BitArray(); }
  191935. const BitArray getActiveInputChannels() const { return inputDevice != 0 ? inputDevice->channels : BitArray(); }
  191936. const String getLastError() { return lastError; }
  191937. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  191938. double sampleRate, int bufferSizeSamples)
  191939. {
  191940. close();
  191941. lastError = String::empty;
  191942. if (sampleRates.size() == 0 && inputDevice != 0 && outputDevice != 0)
  191943. {
  191944. lastError = "The input and output devices don't share a common sample rate!";
  191945. return lastError;
  191946. }
  191947. currentBufferSizeSamples = bufferSizeSamples <= 0 ? defaultBufferSize : jmax (bufferSizeSamples, minBufferSize);
  191948. currentSampleRate = sampleRate > 0 ? sampleRate : defaultSampleRate;
  191949. if (inputDevice != 0 && ! inputDevice->open (currentSampleRate, inputChannels))
  191950. {
  191951. lastError = "Couldn't open the input device!";
  191952. return lastError;
  191953. }
  191954. if (outputDevice != 0 && ! outputDevice->open (currentSampleRate, outputChannels))
  191955. {
  191956. close();
  191957. lastError = "Couldn't open the output device!";
  191958. return lastError;
  191959. }
  191960. if (inputDevice != 0)
  191961. ResetEvent (inputDevice->clientEvent);
  191962. if (outputDevice != 0)
  191963. ResetEvent (outputDevice->clientEvent);
  191964. startThread (8);
  191965. Thread::sleep (5);
  191966. if (inputDevice != 0 && inputDevice->client != 0)
  191967. {
  191968. latencyIn = inputDevice->latencySamples + inputDevice->actualBufferSize + inputDevice->minBufferSize;
  191969. HRESULT hr = inputDevice->client->Start();
  191970. logFailure (hr); //xxx handle this
  191971. }
  191972. if (outputDevice != 0 && outputDevice->client != 0)
  191973. {
  191974. latencyOut = outputDevice->latencySamples + outputDevice->actualBufferSize + outputDevice->minBufferSize;
  191975. HRESULT hr = outputDevice->client->Start();
  191976. logFailure (hr); //xxx handle this
  191977. }
  191978. isOpen_ = true;
  191979. return lastError;
  191980. }
  191981. void close()
  191982. {
  191983. stop();
  191984. if (inputDevice != 0)
  191985. SetEvent (inputDevice->clientEvent);
  191986. if (outputDevice != 0)
  191987. SetEvent (outputDevice->clientEvent);
  191988. stopThread (5000);
  191989. if (inputDevice != 0)
  191990. inputDevice->close();
  191991. if (outputDevice != 0)
  191992. outputDevice->close();
  191993. isOpen_ = false;
  191994. }
  191995. bool isOpen() { return isOpen_ && isThreadRunning(); }
  191996. bool isPlaying() { return isStarted && isOpen_ && isThreadRunning(); }
  191997. void start (AudioIODeviceCallback* call)
  191998. {
  191999. if (isOpen_ && call != 0 && ! isStarted)
  192000. {
  192001. if (! isThreadRunning())
  192002. {
  192003. // something's gone wrong and the thread's stopped..
  192004. isOpen_ = false;
  192005. return;
  192006. }
  192007. call->audioDeviceAboutToStart (this);
  192008. const ScopedLock sl (startStopLock);
  192009. callback = call;
  192010. isStarted = true;
  192011. }
  192012. }
  192013. void stop()
  192014. {
  192015. if (isStarted)
  192016. {
  192017. AudioIODeviceCallback* const callbackLocal = callback;
  192018. {
  192019. const ScopedLock sl (startStopLock);
  192020. isStarted = false;
  192021. }
  192022. if (callbackLocal != 0)
  192023. callbackLocal->audioDeviceStopped();
  192024. }
  192025. }
  192026. void setMMThreadPriority()
  192027. {
  192028. DynamicLibraryLoader dll ("avrt.dll");
  192029. DynamicLibraryImport (AvSetMmThreadCharacteristics, avSetMmThreadCharacteristics, HANDLE, dll, (LPCTSTR, LPDWORD))
  192030. DynamicLibraryImport (AvSetMmThreadPriority, avSetMmThreadPriority, HANDLE, dll, (HANDLE, AVRT_PRIORITY))
  192031. if (avSetMmThreadCharacteristics != 0 && avSetMmThreadPriority != 0)
  192032. {
  192033. DWORD dummy = 0;
  192034. HANDLE h = avSetMmThreadCharacteristics (_T("Pro Audio"), &dummy);
  192035. if (h != 0)
  192036. avSetMmThreadPriority (h, AVRT_PRIORITY_NORMAL);
  192037. }
  192038. }
  192039. void run()
  192040. {
  192041. setMMThreadPriority();
  192042. const int bufferSize = currentBufferSizeSamples;
  192043. HANDLE events[2];
  192044. int numEvents = 0;
  192045. if (inputDevice != 0)
  192046. events [numEvents++] = inputDevice->clientEvent;
  192047. if (outputDevice != 0)
  192048. events [numEvents++] = outputDevice->clientEvent;
  192049. const int numInputBuffers = getActiveInputChannels().countNumberOfSetBits();
  192050. const int numOutputBuffers = getActiveOutputChannels().countNumberOfSetBits();
  192051. AudioSampleBuffer ins (jmax (1, numInputBuffers), bufferSize + 32);
  192052. AudioSampleBuffer outs (jmax (1, numOutputBuffers), bufferSize + 32);
  192053. float** const inputBuffers = ins.getArrayOfChannels();
  192054. float** const outputBuffers = outs.getArrayOfChannels();
  192055. ins.clear();
  192056. while (! threadShouldExit())
  192057. {
  192058. const DWORD result = useExclusiveMode ? WaitForSingleObject (inputDevice->clientEvent, 1000)
  192059. : WaitForMultipleObjects (numEvents, events, true, 1000);
  192060. if (result == WAIT_TIMEOUT)
  192061. continue;
  192062. if (threadShouldExit())
  192063. break;
  192064. if (inputDevice != 0)
  192065. inputDevice->copyBuffers (inputBuffers, numInputBuffers, bufferSize, *this);
  192066. // Make the callback..
  192067. {
  192068. const ScopedLock sl (startStopLock);
  192069. if (isStarted)
  192070. {
  192071. JUCE_TRY
  192072. {
  192073. callback->audioDeviceIOCallback ((const float**) inputBuffers,
  192074. numInputBuffers,
  192075. outputBuffers,
  192076. numOutputBuffers,
  192077. bufferSize);
  192078. }
  192079. JUCE_CATCH_EXCEPTION
  192080. }
  192081. else
  192082. {
  192083. outs.clear();
  192084. }
  192085. }
  192086. if (useExclusiveMode && WaitForSingleObject (outputDevice->clientEvent, 1000) == WAIT_TIMEOUT)
  192087. continue;
  192088. if (outputDevice != 0)
  192089. outputDevice->copyBuffers ((const float**) outputBuffers, numOutputBuffers, bufferSize, *this);
  192090. }
  192091. }
  192092. juce_UseDebuggingNewOperator
  192093. String outputDeviceId, inputDeviceId;
  192094. String lastError;
  192095. private:
  192096. // Device stats...
  192097. WASAPIInputDevice* inputDevice;
  192098. WASAPIOutputDevice* outputDevice;
  192099. const bool useExclusiveMode;
  192100. double defaultSampleRate;
  192101. int minBufferSize, defaultBufferSize;
  192102. int latencyIn, latencyOut;
  192103. Array <double> sampleRates;
  192104. Array <int> bufferSizes;
  192105. // Active state...
  192106. bool isOpen_, isStarted;
  192107. int currentBufferSizeSamples;
  192108. double currentSampleRate;
  192109. AudioIODeviceCallback* callback;
  192110. CriticalSection startStopLock;
  192111. bool createDevices()
  192112. {
  192113. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  192114. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  192115. return false;
  192116. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  192117. if (! OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection)))
  192118. return false;
  192119. UINT32 numDevices = 0;
  192120. if (! OK (deviceCollection->GetCount (&numDevices)))
  192121. return false;
  192122. for (UINT32 i = 0; i < numDevices; ++i)
  192123. {
  192124. ComSmartPtr <IMMDevice> device;
  192125. if (! OK (deviceCollection->Item (i, &device)))
  192126. continue;
  192127. const String deviceId (wasapi_getDeviceID (device));
  192128. if (deviceId.isEmpty())
  192129. continue;
  192130. const EDataFlow flow = wasapi_getDataFlow (device);
  192131. if (deviceId == inputDeviceId && flow == eCapture)
  192132. inputDevice = new WASAPIInputDevice (device, useExclusiveMode);
  192133. else if (deviceId == outputDeviceId && flow == eRender)
  192134. outputDevice = new WASAPIOutputDevice (device, useExclusiveMode);
  192135. }
  192136. return (outputDeviceId.isEmpty() || (outputDevice != 0 && outputDevice->isOk()))
  192137. && (inputDeviceId.isEmpty() || (inputDevice != 0 && inputDevice->isOk()));
  192138. }
  192139. WASAPIAudioIODevice (const WASAPIAudioIODevice&);
  192140. WASAPIAudioIODevice& operator= (const WASAPIAudioIODevice&);
  192141. };
  192142. class WASAPIAudioIODeviceType : public AudioIODeviceType
  192143. {
  192144. public:
  192145. WASAPIAudioIODeviceType()
  192146. : AudioIODeviceType (T("Windows Audio")),
  192147. hasScanned (false)
  192148. {
  192149. }
  192150. ~WASAPIAudioIODeviceType()
  192151. {
  192152. }
  192153. void scanForDevices()
  192154. {
  192155. hasScanned = true;
  192156. outputDeviceNames.clear();
  192157. inputDeviceNames.clear();
  192158. outputDeviceIds.clear();
  192159. inputDeviceIds.clear();
  192160. ComSmartPtr <IMMDeviceEnumerator> enumerator;
  192161. if (! OK (enumerator.CoCreateInstance (__uuidof (MMDeviceEnumerator), CLSCTX_INPROC_SERVER)))
  192162. return;
  192163. const String defaultRenderer = getDefaultEndpoint (enumerator, false);
  192164. const String defaultCapture = getDefaultEndpoint (enumerator, true);
  192165. ComSmartPtr <IMMDeviceCollection> deviceCollection;
  192166. UINT32 numDevices = 0;
  192167. if (! (OK (enumerator->EnumAudioEndpoints (eAll, DEVICE_STATE_ACTIVE, &deviceCollection))
  192168. && OK (deviceCollection->GetCount (&numDevices))))
  192169. return;
  192170. for (UINT32 i = 0; i < numDevices; ++i)
  192171. {
  192172. ComSmartPtr <IMMDevice> device;
  192173. if (! OK (deviceCollection->Item (i, &device)))
  192174. continue;
  192175. const String deviceId (wasapi_getDeviceID (device));
  192176. DWORD state = 0;
  192177. if (! OK (device->GetState (&state)))
  192178. continue;
  192179. if (state != DEVICE_STATE_ACTIVE)
  192180. continue;
  192181. String name;
  192182. {
  192183. ComSmartPtr <IPropertyStore> properties;
  192184. if (! OK (device->OpenPropertyStore (STGM_READ, &properties)))
  192185. continue;
  192186. PROPVARIANT value;
  192187. PropVariantInit (&value);
  192188. if (OK (properties->GetValue (PKEY_Device_FriendlyName, &value)))
  192189. name = value.pwszVal;
  192190. PropVariantClear (&value);
  192191. }
  192192. const EDataFlow flow = wasapi_getDataFlow (device);
  192193. if (flow == eRender)
  192194. {
  192195. const int index = (deviceId == defaultRenderer) ? 0 : -1;
  192196. outputDeviceIds.insert (index, deviceId);
  192197. outputDeviceNames.insert (index, name);
  192198. }
  192199. else if (flow == eCapture)
  192200. {
  192201. const int index = (deviceId == defaultCapture) ? 0 : -1;
  192202. inputDeviceIds.insert (index, deviceId);
  192203. inputDeviceNames.insert (index, name);
  192204. }
  192205. }
  192206. inputDeviceNames.appendNumbersToDuplicates (false, false);
  192207. outputDeviceNames.appendNumbersToDuplicates (false, false);
  192208. }
  192209. const StringArray getDeviceNames (const bool wantInputNames) const
  192210. {
  192211. jassert (hasScanned); // need to call scanForDevices() before doing this
  192212. return wantInputNames ? inputDeviceNames
  192213. : outputDeviceNames;
  192214. }
  192215. int getDefaultDeviceIndex (const bool /*forInput*/) const
  192216. {
  192217. jassert (hasScanned); // need to call scanForDevices() before doing this
  192218. return 0;
  192219. }
  192220. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  192221. {
  192222. jassert (hasScanned); // need to call scanForDevices() before doing this
  192223. WASAPIAudioIODevice* const d = dynamic_cast <WASAPIAudioIODevice*> (device);
  192224. return d == 0 ? -1 : (asInput ? inputDeviceIds.indexOf (d->inputDeviceId)
  192225. : outputDeviceIds.indexOf (d->outputDeviceId));
  192226. }
  192227. bool hasSeparateInputsAndOutputs() const { return true; }
  192228. AudioIODevice* createDevice (const String& outputDeviceName,
  192229. const String& inputDeviceName)
  192230. {
  192231. jassert (hasScanned); // need to call scanForDevices() before doing this
  192232. const bool useExclusiveMode = false;
  192233. WASAPIAudioIODevice* d = 0;
  192234. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  192235. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  192236. if (outputIndex >= 0 || inputIndex >= 0)
  192237. {
  192238. d = new WASAPIAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  192239. : inputDeviceName,
  192240. outputDeviceIds [outputIndex],
  192241. inputDeviceIds [inputIndex],
  192242. useExclusiveMode);
  192243. if (! d->initialise())
  192244. deleteAndZero (d);
  192245. }
  192246. return d;
  192247. }
  192248. juce_UseDebuggingNewOperator
  192249. StringArray outputDeviceNames, outputDeviceIds;
  192250. StringArray inputDeviceNames, inputDeviceIds;
  192251. private:
  192252. bool hasScanned;
  192253. static const String getDefaultEndpoint (IMMDeviceEnumerator* const enumerator, const bool forCapture)
  192254. {
  192255. String s;
  192256. IMMDevice* dev = 0;
  192257. if (OK (enumerator->GetDefaultAudioEndpoint (forCapture ? eCapture : eRender,
  192258. eMultimedia, &dev)))
  192259. {
  192260. WCHAR* deviceId = 0;
  192261. if (OK (dev->GetId (&deviceId)))
  192262. {
  192263. s = String (deviceId);
  192264. CoTaskMemFree (deviceId);
  192265. }
  192266. dev->Release();
  192267. }
  192268. return s;
  192269. }
  192270. WASAPIAudioIODeviceType (const WASAPIAudioIODeviceType&);
  192271. WASAPIAudioIODeviceType& operator= (const WASAPIAudioIODeviceType&);
  192272. };
  192273. AudioIODeviceType* juce_createAudioIODeviceType_WASAPI()
  192274. {
  192275. return new WASAPIAudioIODeviceType();
  192276. }
  192277. #undef logFailure
  192278. #undef OK
  192279. #endif
  192280. /*** End of inlined file: juce_win32_WASAPI.cpp ***/
  192281. /*** Start of inlined file: juce_win32_CameraDevice.cpp ***/
  192282. // (This file gets included by juce_win32_NativeCode.cpp, rather than being
  192283. // compiled on its own).
  192284. #if JUCE_INCLUDED_FILE && JUCE_USE_CAMERA
  192285. class DShowCameraDeviceInteral : public ChangeBroadcaster
  192286. {
  192287. public:
  192288. DShowCameraDeviceInteral (CameraDevice* const owner_,
  192289. const ComSmartPtr <ICaptureGraphBuilder2>& captureGraphBuilder_,
  192290. const ComSmartPtr <IBaseFilter>& filter_,
  192291. int minWidth, int minHeight,
  192292. int maxWidth, int maxHeight)
  192293. : owner (owner_),
  192294. captureGraphBuilder (captureGraphBuilder_),
  192295. filter (filter_),
  192296. ok (false),
  192297. imageNeedsFlipping (false),
  192298. width (0),
  192299. height (0),
  192300. activeUsers (0),
  192301. recordNextFrameTime (false),
  192302. activeImage (0),
  192303. loadingImage (0)
  192304. {
  192305. HRESULT hr = graphBuilder.CoCreateInstance (CLSID_FilterGraph, CLSCTX_INPROC);
  192306. if (FAILED (hr))
  192307. return;
  192308. hr = captureGraphBuilder->SetFiltergraph (graphBuilder);
  192309. if (FAILED (hr))
  192310. return;
  192311. hr = graphBuilder->QueryInterface (IID_IMediaControl, (void**) &mediaControl);
  192312. if (FAILED (hr))
  192313. return;
  192314. {
  192315. ComSmartPtr <IAMStreamConfig> streamConfig;
  192316. hr = captureGraphBuilder->FindInterface (&PIN_CATEGORY_CAPTURE,
  192317. 0,
  192318. filter,
  192319. IID_IAMStreamConfig,
  192320. (void**) &streamConfig);
  192321. if (streamConfig != 0)
  192322. {
  192323. getVideoSizes (streamConfig);
  192324. if (! selectVideoSize (streamConfig, minWidth, minHeight, maxWidth, maxHeight))
  192325. return;
  192326. }
  192327. }
  192328. hr = graphBuilder->AddFilter (filter, _T("Video Capture"));
  192329. if (FAILED (hr))
  192330. return;
  192331. hr = smartTee.CoCreateInstance (CLSID_SmartTee, CLSCTX_INPROC_SERVER);
  192332. if (FAILED (hr))
  192333. return;
  192334. hr = graphBuilder->AddFilter (smartTee, _T("Smart Tee"));
  192335. if (FAILED (hr))
  192336. return;
  192337. if (! connectFilters (filter, smartTee))
  192338. return;
  192339. ComSmartPtr <IBaseFilter> sampleGrabberBase;
  192340. hr = sampleGrabberBase.CoCreateInstance (CLSID_SampleGrabber, CLSCTX_INPROC_SERVER);
  192341. if (FAILED (hr))
  192342. return;
  192343. hr = sampleGrabberBase->QueryInterface (IID_ISampleGrabber, (void**) &sampleGrabber);
  192344. if (FAILED (hr))
  192345. return;
  192346. AM_MEDIA_TYPE mt;
  192347. zerostruct (mt);
  192348. mt.majortype = MEDIATYPE_Video;
  192349. mt.subtype = MEDIASUBTYPE_RGB24;
  192350. mt.formattype = FORMAT_VideoInfo;
  192351. sampleGrabber->SetMediaType (&mt);
  192352. callback = new GrabberCallback (*this);
  192353. sampleGrabber->SetCallback (callback, 1);
  192354. hr = graphBuilder->AddFilter (sampleGrabberBase, _T("Sample Grabber"));
  192355. if (FAILED (hr))
  192356. return;
  192357. ComSmartPtr <IPin> grabberInputPin;
  192358. if (! (getPin (smartTee, PINDIR_OUTPUT, &smartTeeCaptureOutputPin, "capture")
  192359. && getPin (smartTee, PINDIR_OUTPUT, &smartTeePreviewOutputPin, "preview")
  192360. && getPin (sampleGrabberBase, PINDIR_INPUT, &grabberInputPin)))
  192361. return;
  192362. hr = graphBuilder->Connect (smartTeePreviewOutputPin, grabberInputPin);
  192363. if (FAILED (hr))
  192364. return;
  192365. zerostruct (mt);
  192366. hr = sampleGrabber->GetConnectedMediaType (&mt);
  192367. VIDEOINFOHEADER* pVih = (VIDEOINFOHEADER*) (mt.pbFormat);
  192368. width = pVih->bmiHeader.biWidth;
  192369. height = pVih->bmiHeader.biHeight;
  192370. ComSmartPtr <IBaseFilter> nullFilter;
  192371. hr = nullFilter.CoCreateInstance (CLSID_NullRenderer, CLSCTX_INPROC_SERVER);
  192372. hr = graphBuilder->AddFilter (nullFilter, _T("Null Renderer"));
  192373. if (connectFilters (sampleGrabberBase, nullFilter)
  192374. && addGraphToRot())
  192375. {
  192376. activeImage = new Image (Image::RGB, width, height, true);
  192377. loadingImage = new Image (Image::RGB, width, height, true);
  192378. ok = true;
  192379. }
  192380. }
  192381. ~DShowCameraDeviceInteral()
  192382. {
  192383. if (mediaControl != 0)
  192384. mediaControl->Stop();
  192385. removeGraphFromRot();
  192386. for (int i = viewerComps.size(); --i >= 0;)
  192387. ((DShowCaptureViewerComp*) viewerComps.getUnchecked(i))->ownerDeleted();
  192388. callback = 0;
  192389. graphBuilder = 0;
  192390. sampleGrabber = 0;
  192391. mediaControl = 0;
  192392. filter = 0;
  192393. captureGraphBuilder = 0;
  192394. smartTee = 0;
  192395. smartTeePreviewOutputPin = 0;
  192396. smartTeeCaptureOutputPin = 0;
  192397. mux = 0;
  192398. fileWriter = 0;
  192399. delete activeImage;
  192400. delete loadingImage;
  192401. }
  192402. void addUser()
  192403. {
  192404. if (ok && activeUsers++ == 0)
  192405. mediaControl->Run();
  192406. }
  192407. void removeUser()
  192408. {
  192409. if (ok && --activeUsers == 0)
  192410. mediaControl->Stop();
  192411. }
  192412. void handleFrame (double /*time*/, BYTE* buffer, long /*bufferSize*/)
  192413. {
  192414. if (recordNextFrameTime)
  192415. {
  192416. const double defaultCameraLatency = 0.1;
  192417. firstRecordedTime = Time::getCurrentTime() - RelativeTime (defaultCameraLatency);
  192418. recordNextFrameTime = false;
  192419. ComSmartPtr <IPin> pin;
  192420. if (getPin (filter, PINDIR_OUTPUT, &pin))
  192421. {
  192422. ComSmartPtr <IAMPushSource> pushSource;
  192423. HRESULT hr = pin->QueryInterface (IID_IAMPushSource, (void**) &pushSource);
  192424. if (pushSource != 0)
  192425. {
  192426. REFERENCE_TIME latency = 0;
  192427. hr = pushSource->GetLatency (&latency);
  192428. firstRecordedTime = firstRecordedTime - RelativeTime ((double) latency);
  192429. }
  192430. }
  192431. }
  192432. {
  192433. const int lineStride = width * 3;
  192434. const ScopedLock sl (imageSwapLock);
  192435. {
  192436. const Image::BitmapData destData (*loadingImage, 0, 0, width, height, true);
  192437. for (int i = 0; i < height; ++i)
  192438. memcpy (destData.getLinePointer ((height - 1) - i),
  192439. buffer + lineStride * i,
  192440. lineStride);
  192441. }
  192442. imageNeedsFlipping = true;
  192443. }
  192444. if (listeners.size() > 0)
  192445. callListeners (*loadingImage);
  192446. sendChangeMessage (this);
  192447. }
  192448. void drawCurrentImage (Graphics& g, int x, int y, int w, int h)
  192449. {
  192450. if (imageNeedsFlipping)
  192451. {
  192452. const ScopedLock sl (imageSwapLock);
  192453. swapVariables (loadingImage, activeImage);
  192454. imageNeedsFlipping = false;
  192455. }
  192456. RectanglePlacement rp (RectanglePlacement::centred);
  192457. double dx = 0, dy = 0, dw = width, dh = height;
  192458. rp.applyTo (dx, dy, dw, dh, x, y, w, h);
  192459. const int rx = roundToInt (dx), ry = roundToInt (dy);
  192460. const int rw = roundToInt (dw), rh = roundToInt (dh);
  192461. g.saveState();
  192462. g.excludeClipRegion (rx, ry, rw, rh);
  192463. g.fillAll (Colours::black);
  192464. g.restoreState();
  192465. g.drawImage (activeImage, rx, ry, rw, rh, 0, 0, width, height);
  192466. }
  192467. bool createFileCaptureFilter (const File& file)
  192468. {
  192469. removeFileCaptureFilter();
  192470. file.deleteFile();
  192471. mediaControl->Stop();
  192472. firstRecordedTime = Time();
  192473. recordNextFrameTime = true;
  192474. HRESULT hr = mux.CoCreateInstance (CLSID_AviDest, CLSCTX_INPROC_SERVER);
  192475. if (SUCCEEDED (hr))
  192476. {
  192477. hr = graphBuilder->AddFilter (mux, _T("AVI Mux"));
  192478. if (SUCCEEDED (hr))
  192479. {
  192480. hr = fileWriter.CoCreateInstance (CLSID_FileWriter, CLSCTX_INPROC_SERVER);
  192481. if (SUCCEEDED (hr))
  192482. {
  192483. ComSmartPtr <IFileSinkFilter> fileSink;
  192484. hr = fileWriter->QueryInterface (IID_IFileSinkFilter, (void**) &fileSink);
  192485. if (SUCCEEDED (hr))
  192486. {
  192487. AM_MEDIA_TYPE mt;
  192488. zerostruct (mt);
  192489. mt.majortype = MEDIATYPE_Stream;
  192490. mt.subtype = MEDIASUBTYPE_Avi;
  192491. mt.formattype = FORMAT_VideoInfo;
  192492. hr = fileSink->SetFileName (file.getFullPathName(), &mt);
  192493. if (SUCCEEDED (hr))
  192494. {
  192495. hr = graphBuilder->AddFilter (fileWriter, _T("File Writer"));
  192496. if (SUCCEEDED (hr))
  192497. {
  192498. ComSmartPtr <IPin> muxInputPin, muxOutputPin, writerInput;
  192499. if (getPin (mux, PINDIR_INPUT, &muxInputPin)
  192500. && getPin (mux, PINDIR_OUTPUT, &muxOutputPin)
  192501. && getPin (fileWriter, PINDIR_INPUT, &writerInput))
  192502. {
  192503. hr = graphBuilder->Connect (smartTeeCaptureOutputPin, muxInputPin);
  192504. if (SUCCEEDED (hr))
  192505. {
  192506. hr = graphBuilder->Connect (muxOutputPin, writerInput);
  192507. if (SUCCEEDED (hr))
  192508. {
  192509. if (ok && activeUsers > 0)
  192510. mediaControl->Run();
  192511. return true;
  192512. }
  192513. }
  192514. }
  192515. }
  192516. }
  192517. }
  192518. }
  192519. }
  192520. }
  192521. removeFileCaptureFilter();
  192522. if (ok && activeUsers > 0)
  192523. mediaControl->Run();
  192524. return false;
  192525. }
  192526. void removeFileCaptureFilter()
  192527. {
  192528. mediaControl->Stop();
  192529. if (mux != 0)
  192530. {
  192531. graphBuilder->RemoveFilter (mux);
  192532. mux = 0;
  192533. }
  192534. if (fileWriter != 0)
  192535. {
  192536. graphBuilder->RemoveFilter (fileWriter);
  192537. fileWriter = 0;
  192538. }
  192539. if (ok && activeUsers > 0)
  192540. mediaControl->Run();
  192541. }
  192542. void addListener (CameraImageListener* listenerToAdd)
  192543. {
  192544. const ScopedLock sl (listenerLock);
  192545. if (listeners.size() == 0)
  192546. addUser();
  192547. listeners.addIfNotAlreadyThere (listenerToAdd);
  192548. }
  192549. void removeListener (CameraImageListener* listenerToRemove)
  192550. {
  192551. const ScopedLock sl (listenerLock);
  192552. listeners.removeValue (listenerToRemove);
  192553. if (listeners.size() == 0)
  192554. removeUser();
  192555. }
  192556. void callListeners (Image& image)
  192557. {
  192558. const ScopedLock sl (listenerLock);
  192559. for (int i = listeners.size(); --i >= 0;)
  192560. {
  192561. CameraImageListener* l = (CameraImageListener*) listeners[i];
  192562. if (l != 0)
  192563. l->imageReceived (image);
  192564. }
  192565. }
  192566. class DShowCaptureViewerComp : public Component,
  192567. public ChangeListener
  192568. {
  192569. public:
  192570. DShowCaptureViewerComp (DShowCameraDeviceInteral* const owner_)
  192571. : owner (owner_)
  192572. {
  192573. setOpaque (true);
  192574. owner->addChangeListener (this);
  192575. owner->addUser();
  192576. owner->viewerComps.add (this);
  192577. setSize (owner_->width, owner_->height);
  192578. }
  192579. ~DShowCaptureViewerComp()
  192580. {
  192581. if (owner != 0)
  192582. {
  192583. owner->viewerComps.removeValue (this);
  192584. owner->removeUser();
  192585. owner->removeChangeListener (this);
  192586. }
  192587. }
  192588. void ownerDeleted()
  192589. {
  192590. owner = 0;
  192591. }
  192592. void paint (Graphics& g)
  192593. {
  192594. g.setColour (Colours::black);
  192595. g.setImageResamplingQuality (Graphics::lowResamplingQuality);
  192596. if (owner != 0)
  192597. owner->drawCurrentImage (g, 0, 0, getWidth(), getHeight());
  192598. else
  192599. g.fillAll (Colours::black);
  192600. }
  192601. void changeListenerCallback (void*)
  192602. {
  192603. repaint();
  192604. }
  192605. private:
  192606. DShowCameraDeviceInteral* owner;
  192607. };
  192608. bool ok;
  192609. int width, height;
  192610. Time firstRecordedTime;
  192611. VoidArray viewerComps;
  192612. private:
  192613. CameraDevice* const owner;
  192614. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192615. ComSmartPtr <IBaseFilter> filter;
  192616. ComSmartPtr <IBaseFilter> smartTee;
  192617. ComSmartPtr <IGraphBuilder> graphBuilder;
  192618. ComSmartPtr <ISampleGrabber> sampleGrabber;
  192619. ComSmartPtr <IMediaControl> mediaControl;
  192620. ComSmartPtr <IPin> smartTeePreviewOutputPin;
  192621. ComSmartPtr <IPin> smartTeeCaptureOutputPin;
  192622. ComSmartPtr <IBaseFilter> mux, fileWriter;
  192623. int activeUsers;
  192624. Array <int> widths, heights;
  192625. DWORD graphRegistrationID;
  192626. CriticalSection imageSwapLock;
  192627. bool imageNeedsFlipping;
  192628. Image* loadingImage;
  192629. Image* activeImage;
  192630. bool recordNextFrameTime;
  192631. void getVideoSizes (IAMStreamConfig* const streamConfig)
  192632. {
  192633. widths.clear();
  192634. heights.clear();
  192635. int count = 0, size = 0;
  192636. streamConfig->GetNumberOfCapabilities (&count, &size);
  192637. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192638. {
  192639. for (int i = 0; i < count; ++i)
  192640. {
  192641. VIDEO_STREAM_CONFIG_CAPS scc;
  192642. AM_MEDIA_TYPE* config;
  192643. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192644. if (SUCCEEDED (hr))
  192645. {
  192646. const int w = scc.InputSize.cx;
  192647. const int h = scc.InputSize.cy;
  192648. bool duplicate = false;
  192649. for (int j = widths.size(); --j >= 0;)
  192650. {
  192651. if (w == widths.getUnchecked (j) && h == heights.getUnchecked (j))
  192652. {
  192653. duplicate = true;
  192654. break;
  192655. }
  192656. }
  192657. if (! duplicate)
  192658. {
  192659. DBG ("Camera capture size: " + String (w) + ", " + String (h));
  192660. widths.add (w);
  192661. heights.add (h);
  192662. }
  192663. deleteMediaType (config);
  192664. }
  192665. }
  192666. }
  192667. }
  192668. bool selectVideoSize (IAMStreamConfig* const streamConfig,
  192669. const int minWidth, const int minHeight,
  192670. const int maxWidth, const int maxHeight)
  192671. {
  192672. int count = 0, size = 0, bestArea = 0, bestIndex = -1;
  192673. streamConfig->GetNumberOfCapabilities (&count, &size);
  192674. if (size == sizeof (VIDEO_STREAM_CONFIG_CAPS))
  192675. {
  192676. AM_MEDIA_TYPE* config;
  192677. VIDEO_STREAM_CONFIG_CAPS scc;
  192678. for (int i = 0; i < count; ++i)
  192679. {
  192680. HRESULT hr = streamConfig->GetStreamCaps (i, &config, (BYTE*) &scc);
  192681. if (SUCCEEDED (hr))
  192682. {
  192683. if (scc.InputSize.cx >= minWidth
  192684. && scc.InputSize.cy >= minHeight
  192685. && scc.InputSize.cx <= maxWidth
  192686. && scc.InputSize.cy <= maxHeight)
  192687. {
  192688. int area = scc.InputSize.cx * scc.InputSize.cy;
  192689. if (area > bestArea)
  192690. {
  192691. bestIndex = i;
  192692. bestArea = area;
  192693. }
  192694. }
  192695. deleteMediaType (config);
  192696. }
  192697. }
  192698. if (bestIndex >= 0)
  192699. {
  192700. HRESULT hr = streamConfig->GetStreamCaps (bestIndex, &config, (BYTE*) &scc);
  192701. hr = streamConfig->SetFormat (config);
  192702. deleteMediaType (config);
  192703. return SUCCEEDED (hr);
  192704. }
  192705. }
  192706. return false;
  192707. }
  192708. static bool getPin (IBaseFilter* filter, const PIN_DIRECTION wantedDirection, IPin** result, const char* pinName = 0)
  192709. {
  192710. ComSmartPtr <IEnumPins> enumerator;
  192711. ComSmartPtr <IPin> pin;
  192712. filter->EnumPins (&enumerator);
  192713. while (enumerator->Next (1, &pin, 0) == S_OK)
  192714. {
  192715. PIN_DIRECTION dir;
  192716. pin->QueryDirection (&dir);
  192717. if (wantedDirection == dir)
  192718. {
  192719. PIN_INFO info;
  192720. zerostruct (info);
  192721. pin->QueryPinInfo (&info);
  192722. if (pinName == 0 || String (pinName).equalsIgnoreCase (String (info.achName)))
  192723. {
  192724. pin.p->AddRef();
  192725. *result = pin;
  192726. return true;
  192727. }
  192728. }
  192729. }
  192730. return false;
  192731. }
  192732. bool connectFilters (IBaseFilter* const first, IBaseFilter* const second) const
  192733. {
  192734. ComSmartPtr <IPin> in, out;
  192735. return getPin (first, PINDIR_OUTPUT, &out)
  192736. && getPin (second, PINDIR_INPUT, &in)
  192737. && SUCCEEDED (graphBuilder->Connect (out, in));
  192738. }
  192739. bool addGraphToRot()
  192740. {
  192741. ComSmartPtr <IRunningObjectTable> rot;
  192742. if (FAILED (GetRunningObjectTable (0, &rot)))
  192743. return false;
  192744. ComSmartPtr <IMoniker> moniker;
  192745. WCHAR buffer[128];
  192746. HRESULT hr = CreateItemMoniker (_T("!"), buffer, &moniker);
  192747. if (FAILED (hr))
  192748. return false;
  192749. graphRegistrationID = 0;
  192750. return SUCCEEDED (rot->Register (0, graphBuilder, moniker, &graphRegistrationID));
  192751. }
  192752. void removeGraphFromRot()
  192753. {
  192754. ComSmartPtr <IRunningObjectTable> rot;
  192755. if (SUCCEEDED (GetRunningObjectTable (0, &rot)))
  192756. rot->Revoke (graphRegistrationID);
  192757. }
  192758. static void deleteMediaType (AM_MEDIA_TYPE* const pmt)
  192759. {
  192760. if (pmt->cbFormat != 0)
  192761. CoTaskMemFree ((PVOID) pmt->pbFormat);
  192762. if (pmt->pUnk != 0)
  192763. pmt->pUnk->Release();
  192764. CoTaskMemFree (pmt);
  192765. }
  192766. class GrabberCallback : public ISampleGrabberCB
  192767. {
  192768. public:
  192769. GrabberCallback (DShowCameraDeviceInteral& owner_)
  192770. : owner (owner_)
  192771. {
  192772. }
  192773. HRESULT __stdcall QueryInterface (REFIID id, void** result)
  192774. {
  192775. if (id == IID_IUnknown)
  192776. *result = dynamic_cast <IUnknown*> (this);
  192777. else if (id == IID_ISampleGrabberCB)
  192778. *result = dynamic_cast <ISampleGrabberCB*> (this);
  192779. else
  192780. {
  192781. *result = 0;
  192782. return E_NOINTERFACE;
  192783. }
  192784. AddRef();
  192785. return S_OK;
  192786. }
  192787. ULONG __stdcall AddRef() { return ++refCount; }
  192788. ULONG __stdcall Release() { const int r = --refCount; if (r == 0) delete this; return r; }
  192789. STDMETHODIMP SampleCB (double /*SampleTime*/, IMediaSample* /*pSample*/)
  192790. {
  192791. return E_FAIL;
  192792. }
  192793. STDMETHODIMP BufferCB (double time, BYTE* buffer, long bufferSize)
  192794. {
  192795. owner.handleFrame (time, buffer, bufferSize);
  192796. return S_OK;
  192797. }
  192798. private:
  192799. int refCount;
  192800. DShowCameraDeviceInteral& owner;
  192801. GrabberCallback (const GrabberCallback&);
  192802. GrabberCallback& operator= (const GrabberCallback&);
  192803. };
  192804. ComSmartPtr <GrabberCallback> callback;
  192805. VoidArray listeners;
  192806. CriticalSection listenerLock;
  192807. DShowCameraDeviceInteral (const DShowCameraDeviceInteral&);
  192808. DShowCameraDeviceInteral& operator= (const DShowCameraDeviceInteral&);
  192809. };
  192810. CameraDevice::CameraDevice (const String& name_, int /*index*/)
  192811. : name (name_)
  192812. {
  192813. isRecording = false;
  192814. }
  192815. CameraDevice::~CameraDevice()
  192816. {
  192817. stopRecording();
  192818. delete (DShowCameraDeviceInteral*) internal;
  192819. internal = 0;
  192820. }
  192821. Component* CameraDevice::createViewerComponent()
  192822. {
  192823. return new DShowCameraDeviceInteral::DShowCaptureViewerComp ((DShowCameraDeviceInteral*) internal);
  192824. }
  192825. const String CameraDevice::getFileExtension()
  192826. {
  192827. return ".avi";
  192828. }
  192829. void CameraDevice::startRecordingToFile (const File& file, int /*quality*/)
  192830. {
  192831. stopRecording();
  192832. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192833. d->addUser();
  192834. isRecording = d->createFileCaptureFilter (file);
  192835. }
  192836. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  192837. {
  192838. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192839. return d->firstRecordedTime;
  192840. }
  192841. void CameraDevice::stopRecording()
  192842. {
  192843. if (isRecording)
  192844. {
  192845. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192846. d->removeFileCaptureFilter();
  192847. d->removeUser();
  192848. isRecording = false;
  192849. }
  192850. }
  192851. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  192852. {
  192853. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192854. if (listenerToAdd != 0)
  192855. d->addListener (listenerToAdd);
  192856. }
  192857. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  192858. {
  192859. DShowCameraDeviceInteral* const d = (DShowCameraDeviceInteral*) internal;
  192860. if (listenerToRemove != 0)
  192861. d->removeListener (listenerToRemove);
  192862. }
  192863. static ComSmartPtr <IBaseFilter> enumerateCameras (StringArray* const names,
  192864. const int deviceIndexToOpen,
  192865. String& name)
  192866. {
  192867. int index = 0;
  192868. ComSmartPtr <IBaseFilter> result;
  192869. ComSmartPtr <ICreateDevEnum> pDevEnum;
  192870. HRESULT hr = pDevEnum.CoCreateInstance (CLSID_SystemDeviceEnum, CLSCTX_INPROC);
  192871. if (SUCCEEDED (hr))
  192872. {
  192873. ComSmartPtr <IEnumMoniker> enumerator;
  192874. hr = pDevEnum->CreateClassEnumerator (CLSID_VideoInputDeviceCategory, &enumerator, 0);
  192875. if (SUCCEEDED (hr) && enumerator != 0)
  192876. {
  192877. ComSmartPtr <IBaseFilter> captureFilter;
  192878. ComSmartPtr <IMoniker> moniker;
  192879. ULONG fetched;
  192880. while (enumerator->Next (1, &moniker, &fetched) == S_OK)
  192881. {
  192882. hr = moniker->BindToObject (0, 0, IID_IBaseFilter, (void**) &captureFilter);
  192883. if (SUCCEEDED (hr))
  192884. {
  192885. ComSmartPtr <IPropertyBag> propertyBag;
  192886. hr = moniker->BindToStorage (0, 0, IID_IPropertyBag, (void**) &propertyBag);
  192887. if (SUCCEEDED (hr))
  192888. {
  192889. VARIANT var;
  192890. var.vt = VT_BSTR;
  192891. hr = propertyBag->Read (_T("FriendlyName"), &var, 0);
  192892. propertyBag = 0;
  192893. if (SUCCEEDED (hr))
  192894. {
  192895. if (names != 0)
  192896. names->add (var.bstrVal);
  192897. if (index == deviceIndexToOpen)
  192898. {
  192899. name = var.bstrVal;
  192900. result = captureFilter;
  192901. captureFilter = 0;
  192902. break;
  192903. }
  192904. ++index;
  192905. }
  192906. moniker = 0;
  192907. }
  192908. captureFilter = 0;
  192909. }
  192910. }
  192911. }
  192912. }
  192913. return result;
  192914. }
  192915. const StringArray CameraDevice::getAvailableDevices()
  192916. {
  192917. StringArray devs;
  192918. String dummy;
  192919. enumerateCameras (&devs, -1, dummy);
  192920. return devs;
  192921. }
  192922. CameraDevice* CameraDevice::openDevice (int index,
  192923. int minWidth, int minHeight,
  192924. int maxWidth, int maxHeight)
  192925. {
  192926. ComSmartPtr <ICaptureGraphBuilder2> captureGraphBuilder;
  192927. HRESULT hr = captureGraphBuilder.CoCreateInstance (CLSID_CaptureGraphBuilder2, CLSCTX_INPROC);
  192928. if (SUCCEEDED (hr))
  192929. {
  192930. String name;
  192931. const ComSmartPtr <IBaseFilter> filter (enumerateCameras (0, index, name));
  192932. if (filter != 0)
  192933. {
  192934. CameraDevice* const cam = new CameraDevice (name, index);
  192935. DShowCameraDeviceInteral* const intern
  192936. = new DShowCameraDeviceInteral (cam, captureGraphBuilder, filter,
  192937. minWidth, minHeight, maxWidth, maxHeight);
  192938. cam->internal = intern;
  192939. if (intern->ok)
  192940. return cam;
  192941. else
  192942. delete cam;
  192943. }
  192944. }
  192945. return 0;
  192946. }
  192947. #endif
  192948. /*** End of inlined file: juce_win32_CameraDevice.cpp ***/
  192949. #endif
  192950. // Auto-link the other win32 libs that are needed by library calls..
  192951. #if (JUCE_AMALGAMATED_TEMPLATE || defined (JUCE_DLL_BUILD)) && JUCE_MSVC && ! DONT_AUTOLINK_TO_WIN32_LIBRARIES
  192952. /*** Start of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192953. // Auto-links to various win32 libs that are needed by library calls..
  192954. #pragma comment(lib, "kernel32.lib")
  192955. #pragma comment(lib, "user32.lib")
  192956. #pragma comment(lib, "shell32.lib")
  192957. #pragma comment(lib, "gdi32.lib")
  192958. #pragma comment(lib, "vfw32.lib")
  192959. #pragma comment(lib, "comdlg32.lib")
  192960. #pragma comment(lib, "winmm.lib")
  192961. #pragma comment(lib, "wininet.lib")
  192962. #pragma comment(lib, "ole32.lib")
  192963. #pragma comment(lib, "oleaut32.lib")
  192964. #pragma comment(lib, "advapi32.lib")
  192965. #pragma comment(lib, "ws2_32.lib")
  192966. #pragma comment(lib, "comsupp.lib")
  192967. #pragma comment(lib, "version.lib")
  192968. #if JUCE_OPENGL
  192969. #pragma comment(lib, "OpenGL32.Lib")
  192970. #pragma comment(lib, "GlU32.Lib")
  192971. #endif
  192972. #if JUCE_QUICKTIME
  192973. #pragma comment (lib, "QTMLClient.lib")
  192974. #endif
  192975. #if JUCE_USE_CAMERA
  192976. #pragma comment (lib, "Strmiids.lib")
  192977. #endif
  192978. /*** End of inlined file: juce_win32_AutoLinkLibraries.h ***/
  192979. #endif
  192980. END_JUCE_NAMESPACE
  192981. /*** End of inlined file: juce_win32_NativeCode.cpp ***/
  192982. #endif
  192983. #if JUCE_LINUX
  192984. /*** Start of inlined file: juce_linux_NativeCode.cpp ***/
  192985. BEGIN_JUCE_NAMESPACE
  192986. #if defined (CPU_ISSET) && ! defined (SUPPORT_AFFINITIES)
  192987. #define SUPPORT_AFFINITIES 1
  192988. #endif
  192989. #define JUCE_INCLUDED_FILE 1
  192990. // Now include the actual code files..
  192991. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  192992. CriticalSection::CriticalSection() throw()
  192993. {
  192994. pthread_mutexattr_t atts;
  192995. pthread_mutexattr_init (&atts);
  192996. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  192997. pthread_mutex_init (&internal, &atts);
  192998. }
  192999. CriticalSection::~CriticalSection() throw()
  193000. {
  193001. pthread_mutex_destroy (&internal);
  193002. }
  193003. void CriticalSection::enter() const throw()
  193004. {
  193005. pthread_mutex_lock (&internal);
  193006. }
  193007. bool CriticalSection::tryEnter() const throw()
  193008. {
  193009. return pthread_mutex_trylock (&internal) == 0;
  193010. }
  193011. void CriticalSection::exit() const throw()
  193012. {
  193013. pthread_mutex_unlock (&internal);
  193014. }
  193015. struct EventStruct
  193016. {
  193017. pthread_cond_t condition;
  193018. pthread_mutex_t mutex;
  193019. bool triggered;
  193020. };
  193021. WaitableEvent::WaitableEvent() throw()
  193022. {
  193023. EventStruct* const es = new EventStruct();
  193024. es->triggered = false;
  193025. pthread_cond_init (&es->condition, 0);
  193026. pthread_mutex_init (&es->mutex, 0);
  193027. internal = es;
  193028. }
  193029. WaitableEvent::~WaitableEvent() throw()
  193030. {
  193031. EventStruct* const es = (EventStruct*) internal;
  193032. pthread_cond_destroy (&es->condition);
  193033. pthread_mutex_destroy (&es->mutex);
  193034. delete es;
  193035. }
  193036. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  193037. {
  193038. EventStruct* const es = (EventStruct*) internal;
  193039. pthread_mutex_lock (&es->mutex);
  193040. if (timeOutMillisecs < 0)
  193041. {
  193042. while (! es->triggered)
  193043. pthread_cond_wait (&es->condition, &es->mutex);
  193044. }
  193045. else
  193046. {
  193047. while (! es->triggered)
  193048. {
  193049. struct timeval t;
  193050. gettimeofday (&t, 0);
  193051. struct timespec time;
  193052. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  193053. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  193054. if (time.tv_nsec >= 1000000000)
  193055. {
  193056. time.tv_nsec -= 1000000000;
  193057. time.tv_sec++;
  193058. }
  193059. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  193060. {
  193061. pthread_mutex_unlock (&es->mutex);
  193062. return false;
  193063. }
  193064. }
  193065. }
  193066. es->triggered = false;
  193067. pthread_mutex_unlock (&es->mutex);
  193068. return true;
  193069. }
  193070. void WaitableEvent::signal() const throw()
  193071. {
  193072. EventStruct* const es = (EventStruct*) internal;
  193073. pthread_mutex_lock (&es->mutex);
  193074. es->triggered = true;
  193075. pthread_cond_broadcast (&es->condition);
  193076. pthread_mutex_unlock (&es->mutex);
  193077. }
  193078. void WaitableEvent::reset() const throw()
  193079. {
  193080. EventStruct* const es = (EventStruct*) internal;
  193081. pthread_mutex_lock (&es->mutex);
  193082. es->triggered = false;
  193083. pthread_mutex_unlock (&es->mutex);
  193084. }
  193085. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  193086. {
  193087. struct timespec time;
  193088. time.tv_sec = millisecs / 1000;
  193089. time.tv_nsec = (millisecs % 1000) * 1000000;
  193090. nanosleep (&time, 0);
  193091. }
  193092. const tchar File::separator = T('/');
  193093. const tchar* File::separatorString = T("/");
  193094. const File File::getCurrentWorkingDirectory()
  193095. {
  193096. HeapBlock<char> heapBuffer;
  193097. char localBuffer [1024];
  193098. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  193099. int bufferSize = 4096;
  193100. while (cwd == 0 && errno == ERANGE)
  193101. {
  193102. heapBuffer.malloc (bufferSize);
  193103. cwd = getcwd (heapBuffer, bufferSize - 1);
  193104. bufferSize += 1024;
  193105. }
  193106. return File (String::fromUTF8 (cwd));
  193107. }
  193108. bool File::setAsCurrentWorkingDirectory() const
  193109. {
  193110. return chdir (getFullPathName().toUTF8()) == 0;
  193111. }
  193112. bool juce_copyFile (const String& s, const String& d);
  193113. static bool juce_stat (const String& fileName, struct stat& info)
  193114. {
  193115. return fileName.isNotEmpty()
  193116. && (stat (fileName.toUTF8(), &info) == 0);
  193117. }
  193118. bool juce_isDirectory (const String& fileName)
  193119. {
  193120. struct stat info;
  193121. return fileName.isEmpty()
  193122. || (juce_stat (fileName, info)
  193123. && ((info.st_mode & S_IFDIR) != 0));
  193124. }
  193125. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  193126. {
  193127. if (fileName.isEmpty())
  193128. return false;
  193129. const char* const fileNameUTF8 = fileName.toUTF8();
  193130. bool exists = access (fileNameUTF8, F_OK) == 0;
  193131. if (exists && dontCountDirectories)
  193132. {
  193133. struct stat info;
  193134. const int res = stat (fileNameUTF8, &info);
  193135. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  193136. exists = false;
  193137. }
  193138. return exists;
  193139. }
  193140. int64 juce_getFileSize (const String& fileName)
  193141. {
  193142. struct stat info;
  193143. return juce_stat (fileName, info) ? info.st_size : 0;
  193144. }
  193145. bool juce_canWriteToFile (const String& fileName)
  193146. {
  193147. return access (fileName.toUTF8(), W_OK) == 0;
  193148. }
  193149. bool juce_deleteFile (const String& fileName)
  193150. {
  193151. if (juce_isDirectory (fileName))
  193152. return rmdir ((const char*) fileName.toUTF8()) == 0;
  193153. else
  193154. return remove ((const char*) fileName.toUTF8()) == 0;
  193155. }
  193156. bool juce_moveFile (const String& source, const String& dest)
  193157. {
  193158. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  193159. return true;
  193160. if (juce_canWriteToFile (source)
  193161. && juce_copyFile (source, dest))
  193162. {
  193163. if (juce_deleteFile (source))
  193164. return true;
  193165. juce_deleteFile (dest);
  193166. }
  193167. return false;
  193168. }
  193169. void juce_createDirectory (const String& fileName)
  193170. {
  193171. mkdir (fileName.toUTF8(), 0777);
  193172. }
  193173. void* juce_fileOpen (const String& fileName, bool forWriting)
  193174. {
  193175. int flags = O_RDONLY;
  193176. if (forWriting)
  193177. {
  193178. if (juce_fileExists (fileName, false))
  193179. {
  193180. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  193181. if (f != -1)
  193182. lseek (f, 0, SEEK_END);
  193183. return (void*) f;
  193184. }
  193185. else
  193186. {
  193187. flags = O_RDWR + O_CREAT;
  193188. }
  193189. }
  193190. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  193191. }
  193192. void juce_fileClose (void* handle)
  193193. {
  193194. if (handle != 0)
  193195. close ((int) (pointer_sized_int) handle);
  193196. }
  193197. int juce_fileRead (void* handle, void* buffer, int size)
  193198. {
  193199. if (handle != 0)
  193200. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  193201. return 0;
  193202. }
  193203. int juce_fileWrite (void* handle, const void* buffer, int size)
  193204. {
  193205. if (handle != 0)
  193206. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  193207. return 0;
  193208. }
  193209. int64 juce_fileSetPosition (void* handle, int64 pos)
  193210. {
  193211. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  193212. return pos;
  193213. return -1;
  193214. }
  193215. int64 juce_fileGetPosition (void* handle)
  193216. {
  193217. if (handle != 0)
  193218. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  193219. else
  193220. return -1;
  193221. }
  193222. void juce_fileFlush (void* handle)
  193223. {
  193224. if (handle != 0)
  193225. fsync ((int) (pointer_sized_int) handle);
  193226. }
  193227. const File juce_getExecutableFile()
  193228. {
  193229. Dl_info exeInfo;
  193230. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  193231. return File (String::fromUTF8 (exeInfo.dli_fname));
  193232. }
  193233. // if this file doesn't exist, find a parent of it that does..
  193234. static bool doStatFS (const File* file, struct statfs& result)
  193235. {
  193236. File f (*file);
  193237. for (int i = 5; --i >= 0;)
  193238. {
  193239. if (f.exists())
  193240. break;
  193241. f = f.getParentDirectory();
  193242. }
  193243. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  193244. }
  193245. int64 File::getBytesFreeOnVolume() const
  193246. {
  193247. struct statfs buf;
  193248. if (doStatFS (this, buf))
  193249. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  193250. return 0;
  193251. }
  193252. int64 File::getVolumeTotalSize() const
  193253. {
  193254. struct statfs buf;
  193255. if (doStatFS (this, buf))
  193256. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  193257. return 0;
  193258. }
  193259. const String juce_getVolumeLabel (const String& filenameOnVolume,
  193260. int& volumeSerialNumber)
  193261. {
  193262. volumeSerialNumber = 0;
  193263. #if JUCE_MAC
  193264. struct VolAttrBuf
  193265. {
  193266. u_int32_t length;
  193267. attrreference_t mountPointRef;
  193268. char mountPointSpace [MAXPATHLEN];
  193269. } attrBuf;
  193270. struct attrlist attrList;
  193271. zerostruct (attrList);
  193272. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  193273. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  193274. File f (filenameOnVolume);
  193275. for (;;)
  193276. {
  193277. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  193278. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  193279. {
  193280. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  193281. (int) attrBuf.mountPointRef.attr_length);
  193282. }
  193283. const File parent (f.getParentDirectory());
  193284. if (f == parent)
  193285. break;
  193286. f = parent;
  193287. }
  193288. #endif
  193289. return String::empty;
  193290. }
  193291. void juce_runSystemCommand (const String& command)
  193292. {
  193293. int result = system ((const char*) command.toUTF8());
  193294. (void) result;
  193295. }
  193296. const String juce_getOutputFromCommand (const String& command)
  193297. {
  193298. // slight bodge here, as we just pipe the output into a temp file and read it...
  193299. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  193300. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  193301. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  193302. String result (tempFile.loadFileAsString());
  193303. tempFile.deleteFile();
  193304. return result;
  193305. }
  193306. InterProcessLock::InterProcessLock (const String& name_)
  193307. : internal (0),
  193308. name (name_),
  193309. reentrancyLevel (0)
  193310. {
  193311. #if JUCE_MAC
  193312. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  193313. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  193314. #else
  193315. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  193316. #endif
  193317. temp.create();
  193318. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  193319. }
  193320. InterProcessLock::~InterProcessLock()
  193321. {
  193322. while (reentrancyLevel > 0)
  193323. this->exit();
  193324. close (internal);
  193325. }
  193326. bool InterProcessLock::enter (const int timeOutMillisecs)
  193327. {
  193328. if (internal == 0)
  193329. return false;
  193330. if (reentrancyLevel != 0)
  193331. return true;
  193332. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  193333. struct flock fl;
  193334. zerostruct (fl);
  193335. fl.l_whence = SEEK_SET;
  193336. fl.l_type = F_WRLCK;
  193337. for (;;)
  193338. {
  193339. const int result = fcntl (internal, F_SETLK, &fl);
  193340. if (result >= 0)
  193341. {
  193342. ++reentrancyLevel;
  193343. return true;
  193344. }
  193345. if (errno != EINTR)
  193346. {
  193347. if (timeOutMillisecs == 0
  193348. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  193349. break;
  193350. Thread::sleep (10);
  193351. }
  193352. }
  193353. return false;
  193354. }
  193355. void InterProcessLock::exit()
  193356. {
  193357. if (reentrancyLevel > 0 && internal != 0)
  193358. {
  193359. --reentrancyLevel;
  193360. struct flock fl;
  193361. zerostruct (fl);
  193362. fl.l_whence = SEEK_SET;
  193363. fl.l_type = F_UNLCK;
  193364. for (;;)
  193365. {
  193366. const int result = fcntl (internal, F_SETLKW, &fl);
  193367. if (result >= 0 || errno != EINTR)
  193368. break;
  193369. }
  193370. }
  193371. }
  193372. /*** End of inlined file: juce_posix_SharedCode.h ***/
  193373. /*** Start of inlined file: juce_linux_Files.cpp ***/
  193374. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193375. // compiled on its own).
  193376. #if JUCE_INCLUDED_FILE
  193377. #define U_ISOFS_SUPER_MAGIC (short) 0x9660 // linux/iso_fs.h
  193378. #define U_MSDOS_SUPER_MAGIC (short) 0x4d44 // linux/msdos_fs.h
  193379. #define U_NFS_SUPER_MAGIC (short) 0x6969 // linux/nfs_fs.h
  193380. #define U_SMB_SUPER_MAGIC (short) 0x517B // linux/smb_fs.h
  193381. void juce_getFileTimes (const String& fileName,
  193382. int64& modificationTime,
  193383. int64& accessTime,
  193384. int64& creationTime)
  193385. {
  193386. modificationTime = 0;
  193387. accessTime = 0;
  193388. creationTime = 0;
  193389. struct stat info;
  193390. const int res = stat (fileName.toUTF8(), &info);
  193391. if (res == 0)
  193392. {
  193393. modificationTime = (int64) info.st_mtime * 1000;
  193394. accessTime = (int64) info.st_atime * 1000;
  193395. creationTime = (int64) info.st_ctime * 1000;
  193396. }
  193397. }
  193398. bool juce_setFileTimes (const String& fileName,
  193399. int64 modificationTime,
  193400. int64 accessTime,
  193401. int64 creationTime)
  193402. {
  193403. struct utimbuf times;
  193404. times.actime = (time_t) (accessTime / 1000);
  193405. times.modtime = (time_t) (modificationTime / 1000);
  193406. return utime (fileName.toUTF8(), &times) == 0;
  193407. }
  193408. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  193409. {
  193410. struct stat info;
  193411. const int res = stat (fileName.toUTF8(), &info);
  193412. if (res != 0)
  193413. return false;
  193414. info.st_mode &= 0777; // Just permissions
  193415. if( isReadOnly )
  193416. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  193417. else
  193418. // Give everybody write permission?
  193419. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  193420. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  193421. }
  193422. bool juce_copyFile (const String& s, const String& d)
  193423. {
  193424. const File source (s), dest (d);
  193425. FileInputStream* in = source.createInputStream();
  193426. bool ok = false;
  193427. if (in != 0)
  193428. {
  193429. if (dest.deleteFile())
  193430. {
  193431. FileOutputStream* const out = dest.createOutputStream();
  193432. if (out != 0)
  193433. {
  193434. const int bytesCopied = out->writeFromInputStream (*in, -1);
  193435. delete out;
  193436. ok = (bytesCopied == source.getSize());
  193437. if (! ok)
  193438. dest.deleteFile();
  193439. }
  193440. }
  193441. delete in;
  193442. }
  193443. return ok;
  193444. }
  193445. const StringArray juce_getFileSystemRoots()
  193446. {
  193447. StringArray s;
  193448. s.add (T("/"));
  193449. return s;
  193450. }
  193451. bool File::isOnCDRomDrive() const
  193452. {
  193453. struct statfs buf;
  193454. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193455. return (buf.f_type == U_ISOFS_SUPER_MAGIC);
  193456. // Assume not if this fails for some reason
  193457. return false;
  193458. }
  193459. bool File::isOnHardDisk() const
  193460. {
  193461. struct statfs buf;
  193462. if (statfs (getFullPathName().toUTF8(), &buf) == 0)
  193463. {
  193464. switch (buf.f_type)
  193465. {
  193466. case U_ISOFS_SUPER_MAGIC: // CD-ROM
  193467. case U_MSDOS_SUPER_MAGIC: // Probably floppy (but could be mounted FAT filesystem)
  193468. case U_NFS_SUPER_MAGIC: // Network NFS
  193469. case U_SMB_SUPER_MAGIC: // Network Samba
  193470. return false;
  193471. default:
  193472. // Assume anything else is a hard-disk (but note it could
  193473. // be a RAM disk. There isn't a good way of determining
  193474. // this for sure)
  193475. return true;
  193476. }
  193477. }
  193478. // Assume so if this fails for some reason
  193479. return true;
  193480. }
  193481. bool File::isOnRemovableDrive() const
  193482. {
  193483. jassertfalse // xxx not implemented for linux!
  193484. return false;
  193485. }
  193486. bool File::isHidden() const
  193487. {
  193488. return getFileName().startsWithChar (T('.'));
  193489. }
  193490. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  193491. const File File::getSpecialLocation (const SpecialLocationType type)
  193492. {
  193493. switch (type)
  193494. {
  193495. case userHomeDirectory:
  193496. {
  193497. const char* homeDir = getenv ("HOME");
  193498. if (homeDir == 0)
  193499. {
  193500. struct passwd* const pw = getpwuid (getuid());
  193501. if (pw != 0)
  193502. homeDir = pw->pw_dir;
  193503. }
  193504. return File (String::fromUTF8 (homeDir));
  193505. }
  193506. case userDocumentsDirectory:
  193507. case userMusicDirectory:
  193508. case userMoviesDirectory:
  193509. case userApplicationDataDirectory:
  193510. return File ("~");
  193511. case userDesktopDirectory:
  193512. return File ("~/Desktop");
  193513. case commonApplicationDataDirectory:
  193514. return File ("/var");
  193515. case globalApplicationsDirectory:
  193516. return File ("/usr");
  193517. case tempDirectory:
  193518. {
  193519. File tmp ("/var/tmp");
  193520. if (! tmp.isDirectory())
  193521. {
  193522. tmp = T("/tmp");
  193523. if (! tmp.isDirectory())
  193524. tmp = File::getCurrentWorkingDirectory();
  193525. }
  193526. return tmp;
  193527. }
  193528. case invokedExecutableFile:
  193529. if (juce_Argv0 != 0)
  193530. return File (String::fromUTF8 (juce_Argv0));
  193531. // deliberate fall-through...
  193532. case currentExecutableFile:
  193533. case currentApplicationFile:
  193534. return juce_getExecutableFile();
  193535. default:
  193536. jassertfalse // unknown type?
  193537. break;
  193538. }
  193539. return File::nonexistent;
  193540. }
  193541. const String File::getVersion() const
  193542. {
  193543. return String::empty; // xxx not yet implemented
  193544. }
  193545. const File File::getLinkedTarget() const
  193546. {
  193547. char buffer [4096];
  193548. size_t numChars = readlink (getFullPathName().toUTF8(),
  193549. buffer, sizeof (buffer));
  193550. if (numChars > 0 && numChars <= sizeof (buffer))
  193551. return File (String::fromUTF8 (buffer, (int) numChars));
  193552. return *this;
  193553. }
  193554. bool File::moveToTrash() const
  193555. {
  193556. if (! exists())
  193557. return true;
  193558. File trashCan (T("~/.Trash"));
  193559. if (! trashCan.isDirectory())
  193560. trashCan = T("~/.local/share/Trash/files");
  193561. if (! trashCan.isDirectory())
  193562. return false;
  193563. return moveFileTo (trashCan.getNonexistentChildFile (getFileNameWithoutExtension(),
  193564. getFileExtension()));
  193565. }
  193566. struct FindFileStruct
  193567. {
  193568. String parentDir, wildCard;
  193569. DIR* dir;
  193570. bool getNextMatch (String& result, bool* const isDir, bool* const isHidden, int64* const fileSize,
  193571. Time* const modTime, Time* const creationTime, bool* const isReadOnly)
  193572. {
  193573. const char* const wildcardUTF8 = wildCard.toUTF8();
  193574. for (;;)
  193575. {
  193576. struct dirent* const de = readdir (dir);
  193577. if (de == 0)
  193578. break;
  193579. if (fnmatch (wildcardUTF8, de->d_name, FNM_CASEFOLD) == 0)
  193580. {
  193581. result = String::fromUTF8 (de->d_name);
  193582. const String path (parentDir + result);
  193583. if (isDir != 0 || fileSize != 0)
  193584. {
  193585. struct stat info;
  193586. const bool statOk = (stat (path.toUTF8(), &info) == 0);
  193587. if (isDir != 0)
  193588. *isDir = path.isEmpty() || (statOk && ((info.st_mode & S_IFDIR) != 0));
  193589. if (isHidden != 0)
  193590. *isHidden = (de->d_name[0] == '.');
  193591. if (fileSize != 0)
  193592. *fileSize = statOk ? info.st_size : 0;
  193593. }
  193594. if (modTime != 0 || creationTime != 0)
  193595. {
  193596. int64 m, a, c;
  193597. juce_getFileTimes (path, m, a, c);
  193598. if (modTime != 0)
  193599. *modTime = m;
  193600. if (creationTime != 0)
  193601. *creationTime = c;
  193602. }
  193603. if (isReadOnly != 0)
  193604. *isReadOnly = ! juce_canWriteToFile (path);
  193605. return true;
  193606. }
  193607. }
  193608. return false;
  193609. }
  193610. };
  193611. // returns 0 on failure
  193612. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  193613. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  193614. Time* creationTime, bool* isReadOnly)
  193615. {
  193616. DIR* d = opendir (directory.toUTF8());
  193617. if (d != 0)
  193618. {
  193619. FindFileStruct* ff = new FindFileStruct();
  193620. ff->parentDir = directory;
  193621. if (!ff->parentDir.endsWithChar (File::separator))
  193622. ff->parentDir += File::separator;
  193623. ff->wildCard = wildCard;
  193624. if (wildCard == T("*.*"))
  193625. ff->wildCard = T("*");
  193626. ff->dir = d;
  193627. if (ff->getNextMatch (firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  193628. {
  193629. return ff;
  193630. }
  193631. else
  193632. {
  193633. firstResultFile = String::empty;
  193634. isDir = false;
  193635. isHidden = false;
  193636. closedir (d);
  193637. delete ff;
  193638. }
  193639. }
  193640. return 0;
  193641. }
  193642. bool juce_findFileNext (void* handle, String& resultFile,
  193643. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  193644. {
  193645. FindFileStruct* const ff = (FindFileStruct*) handle;
  193646. if (ff != 0)
  193647. return ff->getNextMatch (resultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly);
  193648. return false;
  193649. }
  193650. void juce_findFileClose (void* handle)
  193651. {
  193652. FindFileStruct* const ff = (FindFileStruct*) handle;
  193653. if (ff != 0)
  193654. {
  193655. closedir (ff->dir);
  193656. delete ff;
  193657. }
  193658. }
  193659. bool juce_launchFile (const String& fileName,
  193660. const String& parameters)
  193661. {
  193662. String cmdString (fileName.replace (T(" "), T("\\ "),false));
  193663. cmdString << " " << parameters;
  193664. if (URL::isProbablyAWebsiteURL (fileName)
  193665. || cmdString.startsWithIgnoreCase (T("file:"))
  193666. || URL::isProbablyAnEmailAddress (fileName))
  193667. {
  193668. // create a command that tries to launch a bunch of likely browsers
  193669. const char* const browserNames[] = { "xdg-open", "/etc/alternatives/x-www-browser", "firefox", "mozilla", "konqueror", "opera" };
  193670. StringArray cmdLines;
  193671. for (int i = 0; i < numElementsInArray (browserNames); ++i)
  193672. cmdLines.add (String (browserNames[i]) + T(" ") + cmdString.trim().quoted());
  193673. cmdString = cmdLines.joinIntoString (T(" || "));
  193674. }
  193675. const char* const argv[4] = { "/bin/sh", "-c", (const char*) cmdString.toUTF8(), 0 };
  193676. const int cpid = fork();
  193677. if (cpid == 0)
  193678. {
  193679. setsid();
  193680. // Child process
  193681. execve (argv[0], (char**) argv, environ);
  193682. exit (0);
  193683. }
  193684. return cpid >= 0;
  193685. }
  193686. void File::revealToUser() const
  193687. {
  193688. if (isDirectory())
  193689. startAsProcess();
  193690. else if (getParentDirectory().exists())
  193691. getParentDirectory().startAsProcess();
  193692. }
  193693. #endif
  193694. /*** End of inlined file: juce_linux_Files.cpp ***/
  193695. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  193696. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  193697. // compiled on its own).
  193698. #if JUCE_INCLUDED_FILE
  193699. struct NamedPipeInternal
  193700. {
  193701. String pipeInName, pipeOutName;
  193702. int pipeIn, pipeOut;
  193703. bool volatile createdPipe, blocked, stopReadOperation;
  193704. static void signalHandler (int) {}
  193705. };
  193706. void NamedPipe::cancelPendingReads()
  193707. {
  193708. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  193709. {
  193710. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193711. intern->stopReadOperation = true;
  193712. char buffer [1] = { 0 };
  193713. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  193714. (void) bytesWritten;
  193715. int timeout = 2000;
  193716. while (intern->blocked && --timeout >= 0)
  193717. Thread::sleep (2);
  193718. intern->stopReadOperation = false;
  193719. }
  193720. }
  193721. void NamedPipe::close()
  193722. {
  193723. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193724. if (intern != 0)
  193725. {
  193726. internal = 0;
  193727. if (intern->pipeIn != -1)
  193728. ::close (intern->pipeIn);
  193729. if (intern->pipeOut != -1)
  193730. ::close (intern->pipeOut);
  193731. if (intern->createdPipe)
  193732. {
  193733. unlink (intern->pipeInName.toUTF8());
  193734. unlink (intern->pipeOutName.toUTF8());
  193735. }
  193736. delete intern;
  193737. }
  193738. }
  193739. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  193740. {
  193741. close();
  193742. NamedPipeInternal* const intern = new NamedPipeInternal();
  193743. internal = intern;
  193744. intern->createdPipe = createPipe;
  193745. intern->blocked = false;
  193746. intern->stopReadOperation = false;
  193747. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  193748. siginterrupt (SIGPIPE, 1);
  193749. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  193750. intern->pipeInName = pipePath + T("_in");
  193751. intern->pipeOutName = pipePath + T("_out");
  193752. intern->pipeIn = -1;
  193753. intern->pipeOut = -1;
  193754. if (createPipe)
  193755. {
  193756. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  193757. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  193758. {
  193759. delete intern;
  193760. internal = 0;
  193761. return false;
  193762. }
  193763. }
  193764. return true;
  193765. }
  193766. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  193767. {
  193768. int bytesRead = -1;
  193769. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193770. if (intern != 0)
  193771. {
  193772. intern->blocked = true;
  193773. if (intern->pipeIn == -1)
  193774. {
  193775. if (intern->createdPipe)
  193776. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  193777. else
  193778. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  193779. if (intern->pipeIn == -1)
  193780. {
  193781. intern->blocked = false;
  193782. return -1;
  193783. }
  193784. }
  193785. bytesRead = 0;
  193786. char* p = (char*) destBuffer;
  193787. while (bytesRead < maxBytesToRead)
  193788. {
  193789. const int bytesThisTime = maxBytesToRead - bytesRead;
  193790. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  193791. if (numRead <= 0 || intern->stopReadOperation)
  193792. {
  193793. bytesRead = -1;
  193794. break;
  193795. }
  193796. bytesRead += numRead;
  193797. p += bytesRead;
  193798. }
  193799. intern->blocked = false;
  193800. }
  193801. return bytesRead;
  193802. }
  193803. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  193804. {
  193805. int bytesWritten = -1;
  193806. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  193807. if (intern != 0)
  193808. {
  193809. if (intern->pipeOut == -1)
  193810. {
  193811. if (intern->createdPipe)
  193812. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  193813. else
  193814. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  193815. if (intern->pipeOut == -1)
  193816. {
  193817. return -1;
  193818. }
  193819. }
  193820. const char* p = (const char*) sourceBuffer;
  193821. bytesWritten = 0;
  193822. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  193823. while (bytesWritten < numBytesToWrite
  193824. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  193825. {
  193826. const int bytesThisTime = numBytesToWrite - bytesWritten;
  193827. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  193828. if (numWritten <= 0)
  193829. {
  193830. bytesWritten = -1;
  193831. break;
  193832. }
  193833. bytesWritten += numWritten;
  193834. p += bytesWritten;
  193835. }
  193836. }
  193837. return bytesWritten;
  193838. }
  193839. #endif
  193840. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  193841. /*** Start of inlined file: juce_linux_Network.cpp ***/
  193842. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  193843. // compiled on its own).
  193844. #if JUCE_INCLUDED_FILE
  193845. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  193846. {
  193847. int numResults = 0;
  193848. const int s = socket (AF_INET, SOCK_DGRAM, 0);
  193849. if (s != -1)
  193850. {
  193851. char buf [1024];
  193852. struct ifconf ifc;
  193853. ifc.ifc_len = sizeof (buf);
  193854. ifc.ifc_buf = buf;
  193855. ioctl (s, SIOCGIFCONF, &ifc);
  193856. for (unsigned int i = 0; i < ifc.ifc_len / sizeof (struct ifreq); ++i)
  193857. {
  193858. struct ifreq ifr;
  193859. strcpy (ifr.ifr_name, ifc.ifc_req[i].ifr_name);
  193860. if (ioctl (s, SIOCGIFFLAGS, &ifr) == 0
  193861. && (ifr.ifr_flags & IFF_LOOPBACK) == 0
  193862. && ioctl (s, SIOCGIFHWADDR, &ifr) == 0
  193863. && numResults < maxNum)
  193864. {
  193865. int64 a = 0;
  193866. for (int j = 6; --j >= 0;)
  193867. a = (a << 8) | (uint8) ifr.ifr_hwaddr.sa_data [littleEndian ? j : (5 - j)];
  193868. *addresses++ = a;
  193869. ++numResults;
  193870. }
  193871. }
  193872. close (s);
  193873. }
  193874. return numResults;
  193875. }
  193876. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  193877. const String& emailSubject,
  193878. const String& bodyText,
  193879. const StringArray& filesToAttach)
  193880. {
  193881. jassertfalse // xxx todo
  193882. return false;
  193883. }
  193884. class JUCE_HTTPSocketStream
  193885. {
  193886. public:
  193887. JUCE_HTTPSocketStream()
  193888. : readPosition (0),
  193889. socketHandle (-1),
  193890. levelsOfRedirection (0),
  193891. timeoutSeconds (15)
  193892. {
  193893. }
  193894. ~JUCE_HTTPSocketStream()
  193895. {
  193896. closeSocket();
  193897. }
  193898. bool open (const String& url,
  193899. const String& headers,
  193900. const MemoryBlock& postData,
  193901. const bool isPost,
  193902. URL::OpenStreamProgressCallback* callback,
  193903. void* callbackContext,
  193904. int timeOutMs)
  193905. {
  193906. closeSocket();
  193907. uint32 timeOutTime = Time::getMillisecondCounter();
  193908. if (timeOutMs == 0)
  193909. timeOutTime += 60000;
  193910. else if (timeOutMs < 0)
  193911. timeOutTime = 0xffffffff;
  193912. else
  193913. timeOutTime += timeOutMs;
  193914. String hostName, hostPath;
  193915. int hostPort;
  193916. if (! decomposeURL (url, hostName, hostPath, hostPort))
  193917. return false;
  193918. const struct hostent* host = 0;
  193919. int port = 0;
  193920. String proxyName, proxyPath;
  193921. int proxyPort = 0;
  193922. String proxyURL (getenv ("http_proxy"));
  193923. if (proxyURL.startsWithIgnoreCase (T("http://")))
  193924. {
  193925. if (! decomposeURL (proxyURL, proxyName, proxyPath, proxyPort))
  193926. return false;
  193927. host = gethostbyname ((const char*) proxyName.toUTF8());
  193928. port = proxyPort;
  193929. }
  193930. else
  193931. {
  193932. host = gethostbyname ((const char*) hostName.toUTF8());
  193933. port = hostPort;
  193934. }
  193935. if (host == 0)
  193936. return false;
  193937. struct sockaddr_in address;
  193938. zerostruct (address);
  193939. memcpy ((void*) &address.sin_addr, (const void*) host->h_addr, host->h_length);
  193940. address.sin_family = host->h_addrtype;
  193941. address.sin_port = htons (port);
  193942. socketHandle = socket (host->h_addrtype, SOCK_STREAM, 0);
  193943. if (socketHandle == -1)
  193944. return false;
  193945. int receiveBufferSize = 16384;
  193946. setsockopt (socketHandle, SOL_SOCKET, SO_RCVBUF, (char*) &receiveBufferSize, sizeof (receiveBufferSize));
  193947. setsockopt (socketHandle, SOL_SOCKET, SO_KEEPALIVE, 0, 0);
  193948. #if JUCE_MAC
  193949. setsockopt (socketHandle, SOL_SOCKET, SO_NOSIGPIPE, 0, 0);
  193950. #endif
  193951. if (connect (socketHandle, (struct sockaddr*) &address, sizeof (address)) == -1)
  193952. {
  193953. closeSocket();
  193954. return false;
  193955. }
  193956. const MemoryBlock requestHeader (createRequestHeader (hostName, hostPort,
  193957. proxyName, proxyPort,
  193958. hostPath, url,
  193959. headers, postData,
  193960. isPost));
  193961. size_t totalHeaderSent = 0;
  193962. while (totalHeaderSent < requestHeader.getSize())
  193963. {
  193964. if (Time::getMillisecondCounter() > timeOutTime)
  193965. {
  193966. closeSocket();
  193967. return false;
  193968. }
  193969. const int numToSend = jmin (1024, (int) (requestHeader.getSize() - totalHeaderSent));
  193970. if (send (socketHandle,
  193971. ((const char*) requestHeader.getData()) + totalHeaderSent,
  193972. numToSend, 0)
  193973. != numToSend)
  193974. {
  193975. closeSocket();
  193976. return false;
  193977. }
  193978. totalHeaderSent += numToSend;
  193979. if (callback != 0 && ! callback (callbackContext, totalHeaderSent, requestHeader.getSize()))
  193980. {
  193981. closeSocket();
  193982. return false;
  193983. }
  193984. }
  193985. const String responseHeader (readResponse (timeOutTime));
  193986. if (responseHeader.isNotEmpty())
  193987. {
  193988. //DBG (responseHeader);
  193989. StringArray lines;
  193990. lines.addLines (responseHeader);
  193991. // NB - using charToString() here instead of just T(" "), because that was
  193992. // causing a mysterious gcc internal compiler error...
  193993. const int statusCode = responseHeader.fromFirstOccurrenceOf (String::charToString (T(' ')), false, false)
  193994. .substring (0, 3).getIntValue();
  193995. //int contentLength = findHeaderItem (lines, T("Content-Length:")).getIntValue();
  193996. //bool isChunked = findHeaderItem (lines, T("Transfer-Encoding:")).equalsIgnoreCase ("chunked");
  193997. String location (findHeaderItem (lines, T("Location:")));
  193998. if (statusCode >= 300 && statusCode < 400
  193999. && location.isNotEmpty())
  194000. {
  194001. if (! location.startsWithIgnoreCase (T("http://")))
  194002. location = T("http://") + location;
  194003. if (levelsOfRedirection++ < 3)
  194004. return open (location, headers, postData, isPost, callback, callbackContext, timeOutMs);
  194005. }
  194006. else
  194007. {
  194008. levelsOfRedirection = 0;
  194009. return true;
  194010. }
  194011. }
  194012. closeSocket();
  194013. return false;
  194014. }
  194015. int read (void* buffer, int bytesToRead)
  194016. {
  194017. fd_set readbits;
  194018. FD_ZERO (&readbits);
  194019. FD_SET (socketHandle, &readbits);
  194020. struct timeval tv;
  194021. tv.tv_sec = timeoutSeconds;
  194022. tv.tv_usec = 0;
  194023. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  194024. return 0; // (timeout)
  194025. const int bytesRead = jmax (0, (int) recv (socketHandle, buffer, bytesToRead, MSG_WAITALL));
  194026. readPosition += bytesRead;
  194027. return bytesRead;
  194028. }
  194029. int readPosition;
  194030. juce_UseDebuggingNewOperator
  194031. private:
  194032. int socketHandle, levelsOfRedirection;
  194033. const int timeoutSeconds;
  194034. void closeSocket()
  194035. {
  194036. if (socketHandle >= 0)
  194037. close (socketHandle);
  194038. socketHandle = -1;
  194039. }
  194040. const MemoryBlock createRequestHeader (const String& hostName,
  194041. const int hostPort,
  194042. const String& proxyName,
  194043. const int proxyPort,
  194044. const String& hostPath,
  194045. const String& originalURL,
  194046. const String& headers,
  194047. const MemoryBlock& postData,
  194048. const bool isPost)
  194049. {
  194050. String header (isPost ? "POST " : "GET ");
  194051. if (proxyName.isEmpty())
  194052. {
  194053. header << hostPath << " HTTP/1.0\r\nHost: "
  194054. << hostName << ':' << hostPort;
  194055. }
  194056. else
  194057. {
  194058. header << originalURL << " HTTP/1.0\r\nHost: "
  194059. << proxyName << ':' << proxyPort;
  194060. }
  194061. header << "\r\nUser-Agent: JUCE/"
  194062. << JUCE_MAJOR_VERSION << '.' << JUCE_MINOR_VERSION
  194063. << "\r\nConnection: Close\r\nContent-Length: "
  194064. << postData.getSize() << "\r\n"
  194065. << headers << "\r\n";
  194066. MemoryBlock mb;
  194067. mb.append (header.toUTF8(), (int) strlen (header.toUTF8()));
  194068. mb.append (postData.getData(), postData.getSize());
  194069. return mb;
  194070. }
  194071. const String readResponse (const uint32 timeOutTime)
  194072. {
  194073. int bytesRead = 0, numConsecutiveLFs = 0;
  194074. MemoryBlock buffer (1024, true);
  194075. while (numConsecutiveLFs < 2 && bytesRead < 32768
  194076. && Time::getMillisecondCounter() <= timeOutTime)
  194077. {
  194078. fd_set readbits;
  194079. FD_ZERO (&readbits);
  194080. FD_SET (socketHandle, &readbits);
  194081. struct timeval tv;
  194082. tv.tv_sec = timeoutSeconds;
  194083. tv.tv_usec = 0;
  194084. if (select (socketHandle + 1, &readbits, 0, 0, &tv) <= 0)
  194085. return String::empty; // (timeout)
  194086. buffer.ensureSize (bytesRead + 8, true);
  194087. char* const dest = (char*) buffer.getData() + bytesRead;
  194088. if (recv (socketHandle, dest, 1, 0) == -1)
  194089. return String::empty;
  194090. const char lastByte = *dest;
  194091. ++bytesRead;
  194092. if (lastByte == '\n')
  194093. ++numConsecutiveLFs;
  194094. else if (lastByte != '\r')
  194095. numConsecutiveLFs = 0;
  194096. }
  194097. const String header (String::fromUTF8 ((const char*) buffer.getData()));
  194098. if (header.startsWithIgnoreCase (T("HTTP/")))
  194099. return header.trimEnd();
  194100. return String::empty;
  194101. }
  194102. static bool decomposeURL (const String& url,
  194103. String& host, String& path, int& port)
  194104. {
  194105. if (! url.startsWithIgnoreCase (T("http://")))
  194106. return false;
  194107. const int nextSlash = url.indexOfChar (7, '/');
  194108. int nextColon = url.indexOfChar (7, ':');
  194109. if (nextColon > nextSlash && nextSlash > 0)
  194110. nextColon = -1;
  194111. if (nextColon >= 0)
  194112. {
  194113. host = url.substring (7, nextColon);
  194114. if (nextSlash >= 0)
  194115. port = url.substring (nextColon + 1, nextSlash).getIntValue();
  194116. else
  194117. port = url.substring (nextColon + 1).getIntValue();
  194118. }
  194119. else
  194120. {
  194121. port = 80;
  194122. if (nextSlash >= 0)
  194123. host = url.substring (7, nextSlash);
  194124. else
  194125. host = url.substring (7);
  194126. }
  194127. if (nextSlash >= 0)
  194128. path = url.substring (nextSlash);
  194129. else
  194130. path = T("/");
  194131. return true;
  194132. }
  194133. static const String findHeaderItem (const StringArray& lines, const String& itemName)
  194134. {
  194135. for (int i = 0; i < lines.size(); ++i)
  194136. if (lines[i].startsWithIgnoreCase (itemName))
  194137. return lines[i].substring (itemName.length()).trim();
  194138. return String::empty;
  194139. }
  194140. };
  194141. bool juce_isOnLine()
  194142. {
  194143. return true;
  194144. }
  194145. void* juce_openInternetFile (const String& url,
  194146. const String& headers,
  194147. const MemoryBlock& postData,
  194148. const bool isPost,
  194149. URL::OpenStreamProgressCallback* callback,
  194150. void* callbackContext,
  194151. int timeOutMs)
  194152. {
  194153. JUCE_HTTPSocketStream* const s = new JUCE_HTTPSocketStream();
  194154. if (s->open (url, headers, postData, isPost,
  194155. callback, callbackContext, timeOutMs))
  194156. return s;
  194157. delete s;
  194158. return 0;
  194159. }
  194160. void juce_closeInternetFile (void* handle)
  194161. {
  194162. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194163. if (s != 0)
  194164. delete s;
  194165. }
  194166. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  194167. {
  194168. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194169. if (s != 0)
  194170. return s->read (buffer, bytesToRead);
  194171. return 0;
  194172. }
  194173. int64 juce_getInternetFileContentLength (void* handle)
  194174. {
  194175. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194176. if (s != 0)
  194177. {
  194178. //xxx todo
  194179. jassertfalse
  194180. }
  194181. return -1;
  194182. }
  194183. int juce_seekInInternetFile (void* handle, int newPosition)
  194184. {
  194185. JUCE_HTTPSocketStream* const s = (JUCE_HTTPSocketStream*) handle;
  194186. if (s != 0)
  194187. return s->readPosition;
  194188. return 0;
  194189. }
  194190. #endif
  194191. /*** End of inlined file: juce_linux_Network.cpp ***/
  194192. /*** Start of inlined file: juce_linux_SystemStats.cpp ***/
  194193. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194194. // compiled on its own).
  194195. #if JUCE_INCLUDED_FILE
  194196. void Logger::outputDebugString (const String& text) throw()
  194197. {
  194198. fputs (text.toUTF8(), stdout);
  194199. fputs ("\n", stdout);
  194200. }
  194201. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  194202. {
  194203. String text;
  194204. va_list args;
  194205. va_start (args, format);
  194206. text.vprintf(format, args);
  194207. outputDebugString(text);
  194208. }
  194209. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  194210. {
  194211. return Linux;
  194212. }
  194213. const String SystemStats::getOperatingSystemName() throw()
  194214. {
  194215. return T("Linux");
  194216. }
  194217. bool SystemStats::isOperatingSystem64Bit() throw()
  194218. {
  194219. #if JUCE_64BIT
  194220. return true;
  194221. #else
  194222. //xxx not sure how to find this out?..
  194223. return false;
  194224. #endif
  194225. }
  194226. static const String getCpuInfo (const char* key, bool lastOne = false) throw()
  194227. {
  194228. String info;
  194229. char buf [256];
  194230. FILE* f = fopen ("/proc/cpuinfo", "r");
  194231. while (f != 0 && fgets (buf, sizeof(buf), f))
  194232. {
  194233. if (strncmp (buf, key, strlen (key)) == 0)
  194234. {
  194235. char* p = buf;
  194236. while (*p && *p != '\n')
  194237. ++p;
  194238. if (*p != 0)
  194239. *p = 0;
  194240. p = buf;
  194241. while (*p != 0 && *p != ':')
  194242. ++p;
  194243. if (*p != 0 && *(p + 1) != 0)
  194244. info = p + 2;
  194245. if (! lastOne)
  194246. break;
  194247. }
  194248. }
  194249. fclose (f);
  194250. return info;
  194251. }
  194252. bool SystemStats::hasMMX() throw()
  194253. {
  194254. return getCpuInfo ("flags").contains (T("mmx"));
  194255. }
  194256. bool SystemStats::hasSSE() throw()
  194257. {
  194258. return getCpuInfo ("flags").contains (T("sse"));
  194259. }
  194260. bool SystemStats::hasSSE2() throw()
  194261. {
  194262. return getCpuInfo ("flags").contains (T("sse2"));
  194263. }
  194264. bool SystemStats::has3DNow() throw()
  194265. {
  194266. return getCpuInfo ("flags").contains (T("3dnow"));
  194267. }
  194268. const String SystemStats::getCpuVendor() throw()
  194269. {
  194270. return getCpuInfo ("vendor_id");
  194271. }
  194272. int SystemStats::getCpuSpeedInMegaherz() throw()
  194273. {
  194274. const String speed (getCpuInfo ("cpu MHz"));
  194275. return (int) (speed.getFloatValue() + 0.5f);
  194276. }
  194277. int SystemStats::getMemorySizeInMegabytes() throw()
  194278. {
  194279. struct sysinfo sysi;
  194280. if (sysinfo (&sysi) == 0)
  194281. return (sysi.totalram * sysi.mem_unit / (1024 * 1024));
  194282. return 0;
  194283. }
  194284. uint32 juce_millisecondsSinceStartup() throw()
  194285. {
  194286. static unsigned int calibrate = 0;
  194287. static bool calibrated = false;
  194288. timeval t;
  194289. unsigned int ret = 0;
  194290. if (! gettimeofday (&t, 0))
  194291. {
  194292. if (! calibrated)
  194293. {
  194294. struct sysinfo sysi;
  194295. if (sysinfo (&sysi) == 0)
  194296. // Safe to assume system was not brought up earlier than 1970!
  194297. calibrate = t.tv_sec - sysi.uptime;
  194298. calibrated = true;
  194299. }
  194300. ret = 1000 * (t.tv_sec - calibrate) + (t.tv_usec / 1000);
  194301. }
  194302. return ret;
  194303. }
  194304. double Time::getMillisecondCounterHiRes() throw()
  194305. {
  194306. return getHighResolutionTicks() * 0.001;
  194307. }
  194308. int64 Time::getHighResolutionTicks() throw()
  194309. {
  194310. timeval t;
  194311. if (gettimeofday (&t, 0))
  194312. return 0;
  194313. return ((int64) t.tv_sec * (int64) 1000000) + (int64) t.tv_usec;
  194314. }
  194315. int64 Time::getHighResolutionTicksPerSecond() throw()
  194316. {
  194317. // Microseconds
  194318. return 1000000;
  194319. }
  194320. bool Time::setSystemTimeToThisTime() const throw()
  194321. {
  194322. timeval t;
  194323. t.tv_sec = millisSinceEpoch % 1000000;
  194324. t.tv_usec = millisSinceEpoch - t.tv_sec;
  194325. return settimeofday (&t, NULL) ? false : true;
  194326. }
  194327. int SystemStats::getPageSize() throw()
  194328. {
  194329. static int systemPageSize = 0;
  194330. if (systemPageSize == 0)
  194331. systemPageSize = sysconf (_SC_PAGESIZE);
  194332. return systemPageSize;
  194333. }
  194334. int SystemStats::getNumCpus() throw()
  194335. {
  194336. const int lastCpu = getCpuInfo ("processor", true).getIntValue();
  194337. return lastCpu + 1;
  194338. }
  194339. const String SystemStats::getLogonName()
  194340. {
  194341. const char* user = getenv ("USER");
  194342. if (user == 0)
  194343. {
  194344. struct passwd* const pw = getpwuid (getuid());
  194345. if (pw != 0)
  194346. user = pw->pw_name;
  194347. }
  194348. return String::fromUTF8 (user);
  194349. }
  194350. const String SystemStats::getFullUserName()
  194351. {
  194352. return getLogonName();
  194353. }
  194354. void SystemStats::initialiseStats() throw()
  194355. {
  194356. // Process starts off as root when running suid
  194357. Process::lowerPrivilege();
  194358. String s (SystemStats::getJUCEVersion());
  194359. }
  194360. void PlatformUtilities::fpuReset()
  194361. {
  194362. }
  194363. #endif
  194364. /*** End of inlined file: juce_linux_SystemStats.cpp ***/
  194365. /*** Start of inlined file: juce_linux_Threads.cpp ***/
  194366. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194367. // compiled on its own).
  194368. #if JUCE_INCLUDED_FILE
  194369. void JUCE_API juce_threadEntryPoint (void*);
  194370. void* threadEntryProc (void* value)
  194371. {
  194372. // New threads start off as root when running suid
  194373. Process::lowerPrivilege();
  194374. juce_threadEntryPoint (value);
  194375. return 0;
  194376. }
  194377. void* juce_createThread (void* userData)
  194378. {
  194379. pthread_t handle = 0;
  194380. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  194381. {
  194382. pthread_detach (handle);
  194383. return (void*)handle;
  194384. }
  194385. return 0;
  194386. }
  194387. void juce_killThread (void* handle)
  194388. {
  194389. if (handle != 0)
  194390. pthread_cancel ((pthread_t)handle);
  194391. }
  194392. void juce_setCurrentThreadName (const String& /*name*/)
  194393. {
  194394. }
  194395. Thread::ThreadID Thread::getCurrentThreadId()
  194396. {
  194397. return (ThreadID) pthread_self();
  194398. }
  194399. // priority 1 to 10 where 5=normal, 1=low. If the handle is 0, sets the
  194400. // priority of the current thread
  194401. bool juce_setThreadPriority (void* handle, int priority)
  194402. {
  194403. struct sched_param param;
  194404. int policy, maxp, minp, pri;
  194405. if (handle == 0)
  194406. handle = (void*) pthread_self();
  194407. if (pthread_getschedparam ((pthread_t) handle, &policy, &param) == 0
  194408. && policy != SCHED_OTHER)
  194409. {
  194410. minp = sched_get_priority_min(policy);
  194411. maxp = sched_get_priority_max(policy);
  194412. pri = ((maxp - minp) / 2) * (priority - 1) / 9;
  194413. if (param.__sched_priority >= (minp + (maxp - minp) / 2))
  194414. // Realtime process priority
  194415. param.__sched_priority = minp + ((maxp - minp) / 2) + pri;
  194416. else
  194417. // High process priority
  194418. param.__sched_priority = minp + pri;
  194419. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  194420. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  194421. }
  194422. return false;
  194423. }
  194424. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  194425. {
  194426. #if SUPPORT_AFFINITIES
  194427. cpu_set_t affinity;
  194428. CPU_ZERO (&affinity);
  194429. for (int i = 0; i < 32; ++i)
  194430. if ((affinityMask & (1 << i)) != 0)
  194431. CPU_SET (i, &affinity);
  194432. sched_setaffinity (getpid(), sizeof (cpu_set_t), &affinity);
  194433. sched_yield();
  194434. #else
  194435. /* affinities aren't supported because either the appropriate header files weren't found,
  194436. or the SUPPORT_AFFINITIES macro was turned off in linuxheaders.h
  194437. */
  194438. jassertfalse
  194439. #endif
  194440. }
  194441. void Thread::yield()
  194442. {
  194443. sched_yield();
  194444. }
  194445. // sets the process to 0=low priority, 1=normal, 2=high, 3=realtime
  194446. void Process::setPriority (ProcessPriority prior)
  194447. {
  194448. struct sched_param param;
  194449. int policy, maxp, minp;
  194450. const int p = (int) prior;
  194451. if (p <= 1)
  194452. policy = SCHED_OTHER;
  194453. else
  194454. policy = SCHED_RR;
  194455. minp = sched_get_priority_min (policy);
  194456. maxp = sched_get_priority_max (policy);
  194457. if (p < 2)
  194458. param.__sched_priority = 0;
  194459. else if (p == 2 )
  194460. // Set to middle of lower realtime priority range
  194461. param.__sched_priority = minp + (maxp - minp) / 4;
  194462. else
  194463. // Set to middle of higher realtime priority range
  194464. param.__sched_priority = minp + (3 * (maxp - minp) / 4);
  194465. pthread_setschedparam (pthread_self(), policy, &param);
  194466. }
  194467. void Process::terminate()
  194468. {
  194469. exit (0);
  194470. }
  194471. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  194472. {
  194473. static char testResult = 0;
  194474. if (testResult == 0)
  194475. {
  194476. testResult = (char) ptrace (PT_TRACE_ME, 0, 0, 0);
  194477. if (testResult >= 0)
  194478. {
  194479. ptrace (PT_DETACH, 0, (caddr_t) 1, 0);
  194480. testResult = 1;
  194481. }
  194482. }
  194483. return testResult < 0;
  194484. }
  194485. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  194486. {
  194487. return juce_isRunningUnderDebugger();
  194488. }
  194489. void Process::raisePrivilege()
  194490. {
  194491. // If running suid root, change effective user
  194492. // to root
  194493. if (geteuid() != 0 && getuid() == 0)
  194494. {
  194495. setreuid (geteuid(), getuid());
  194496. setregid (getegid(), getgid());
  194497. }
  194498. }
  194499. void Process::lowerPrivilege()
  194500. {
  194501. // If runing suid root, change effective user
  194502. // back to real user
  194503. if (geteuid() == 0 && getuid() != 0)
  194504. {
  194505. setreuid (geteuid(), getuid());
  194506. setregid (getegid(), getgid());
  194507. }
  194508. }
  194509. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194510. void* PlatformUtilities::loadDynamicLibrary (const String& name)
  194511. {
  194512. return dlopen ((const char*) name.toUTF8(), RTLD_LOCAL | RTLD_NOW);
  194513. }
  194514. void PlatformUtilities::freeDynamicLibrary (void* handle)
  194515. {
  194516. dlclose(handle);
  194517. }
  194518. void* PlatformUtilities::getProcedureEntryPoint (void* libraryHandle, const String& procedureName)
  194519. {
  194520. return dlsym (libraryHandle, procedureName.toCString());
  194521. }
  194522. #endif
  194523. #endif
  194524. /*** End of inlined file: juce_linux_Threads.cpp ***/
  194525. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  194526. /*** Start of inlined file: juce_linux_Clipboard.cpp ***/
  194527. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194528. // compiled on its own).
  194529. #if JUCE_INCLUDED_FILE
  194530. #ifdef JUCE_DEBUG
  194531. #define JUCE_DEBUG_XERRORS 1
  194532. #endif
  194533. extern Display* display;
  194534. extern Window juce_messageWindowHandle;
  194535. static String localClipboardContent;
  194536. static Atom atom_UTF8_STRING;
  194537. static Atom atom_CLIPBOARD;
  194538. static Atom atom_TARGETS;
  194539. static void initSelectionAtoms()
  194540. {
  194541. static bool isInitialised = false;
  194542. if (! isInitialised)
  194543. {
  194544. atom_UTF8_STRING = XInternAtom (display, "UTF8_STRING", False);
  194545. atom_CLIPBOARD = XInternAtom (display, "CLIPBOARD", False);
  194546. atom_TARGETS = XInternAtom (display, "TARGETS", False);
  194547. }
  194548. }
  194549. // Read the content of a window property as either a locale-dependent string or an utf8 string
  194550. // works only for strings shorter than 1000000 bytes
  194551. static String juce_readWindowProperty (Window window, Atom prop,
  194552. Atom fmt, // XA_STRING or UTF8_STRING
  194553. bool deleteAfterReading)
  194554. {
  194555. String returnData;
  194556. char* clipData;
  194557. Atom actualType;
  194558. int actualFormat;
  194559. unsigned long numItems, bytesLeft;
  194560. if (XGetWindowProperty (display, window, prop,
  194561. 0L /* offset */, 1000000 /* length (max) */, False,
  194562. AnyPropertyType /* format */,
  194563. &actualType, &actualFormat, &numItems, &bytesLeft,
  194564. (unsigned char**) &clipData) == Success)
  194565. {
  194566. if (actualType == atom_UTF8_STRING && actualFormat == 8)
  194567. {
  194568. returnData = String::fromUTF8 (clipData, numItems);
  194569. }
  194570. else if (actualType == XA_STRING && actualFormat == 8)
  194571. {
  194572. returnData = String (clipData, numItems);
  194573. }
  194574. if (clipData != 0)
  194575. XFree (clipData);
  194576. jassert (bytesLeft == 0 || numItems == 1000000);
  194577. }
  194578. if (deleteAfterReading)
  194579. XDeleteProperty (display, window, prop);
  194580. return returnData;
  194581. }
  194582. // Send a SelectionRequest to the window owning the selection and waits for its answer (with a timeout) */
  194583. static bool juce_requestSelectionContent (String &selection_content, Atom selection, Atom requested_format)
  194584. {
  194585. Atom property_name = XInternAtom (display, "JUCE_SEL", false);
  194586. // The selection owner will be asked to set the JUCE_SEL property on the
  194587. // juce_messageWindowHandle with the selection content
  194588. XConvertSelection (display, selection, requested_format, property_name,
  194589. juce_messageWindowHandle, CurrentTime);
  194590. int timeoutMs = 200; // will wait at most for 200 ms
  194591. do
  194592. {
  194593. XEvent event;
  194594. if (XCheckTypedWindowEvent (display, juce_messageWindowHandle, SelectionNotify, &event))
  194595. {
  194596. if (event.xselection.property == property_name)
  194597. {
  194598. jassert (event.xselection.requestor == juce_messageWindowHandle);
  194599. selection_content = juce_readWindowProperty (event.xselection.requestor,
  194600. event.xselection.property,
  194601. requested_format, true);
  194602. return true;
  194603. }
  194604. else
  194605. {
  194606. return false; // the format we asked for was denied.. (event.xselection.property == None)
  194607. }
  194608. }
  194609. // not very elegant.. we could do a select() or something like that...
  194610. // however clipboard content requesting is inherently slow on x11, it
  194611. // often takes 50ms or more so...
  194612. Thread::sleep (4);
  194613. timeoutMs -= 4;
  194614. }
  194615. while (timeoutMs > 0);
  194616. DBG("timeout for juce_requestSelectionContent");
  194617. return false;
  194618. }
  194619. // Called from the event loop in juce_linux_Messaging in response to SelectionRequest events
  194620. void juce_handleSelectionRequest (XSelectionRequestEvent &evt)
  194621. {
  194622. initSelectionAtoms();
  194623. // the selection content is sent to the target window as a window property
  194624. XSelectionEvent reply;
  194625. reply.type = SelectionNotify;
  194626. reply.display = evt.display;
  194627. reply.requestor = evt.requestor;
  194628. reply.selection = evt.selection;
  194629. reply.target = evt.target;
  194630. reply.property = None; // == "fail"
  194631. reply.time = evt.time;
  194632. HeapBlock <char> data;
  194633. int propertyFormat = 0, numDataItems = 0;
  194634. if (evt.selection == XA_PRIMARY || evt.selection == atom_CLIPBOARD)
  194635. {
  194636. if (evt.target == XA_STRING)
  194637. {
  194638. // format data according to system locale
  194639. numDataItems = localClipboardContent.getNumBytesAsCString() + 1;
  194640. data.calloc (numDataItems + 1);
  194641. localClipboardContent.copyToCString (data, numDataItems);
  194642. propertyFormat = 8; // bits/item
  194643. }
  194644. else if (evt.target == atom_UTF8_STRING)
  194645. {
  194646. // translate to utf8
  194647. numDataItems = localClipboardContent.getNumBytesAsUTF8() + 1;
  194648. data.calloc (numDataItems + 1);
  194649. localClipboardContent.copyToUTF8 (data, numDataItems);
  194650. propertyFormat = 8; // bits/item
  194651. }
  194652. else if (evt.target == atom_TARGETS)
  194653. {
  194654. // another application wants to know what we are able to send
  194655. numDataItems = 2;
  194656. propertyFormat = 32; // atoms are 32-bit
  194657. data.calloc (numDataItems * 4);
  194658. ((Atom*) data)[0] = atom_UTF8_STRING;
  194659. ((Atom*) data)[1] = XA_STRING;
  194660. }
  194661. }
  194662. else
  194663. {
  194664. DBG ("requested unsupported clipboard");
  194665. }
  194666. if (data != 0)
  194667. {
  194668. const int maxReasonableSelectionSize = 1000000;
  194669. // for very big chunks of data, we should use the "INCR" protocol , which is a pain in the *ss
  194670. if (evt.property != None && numDataItems < maxReasonableSelectionSize)
  194671. {
  194672. XChangeProperty (evt.display, evt.requestor,
  194673. evt.property, evt.target,
  194674. propertyFormat /* 8 or 32 */, PropModeReplace,
  194675. (const unsigned char*) data, numDataItems);
  194676. reply.property = evt.property; // " == success"
  194677. }
  194678. }
  194679. XSendEvent (evt.display, evt.requestor, 0, NoEventMask, (XEvent*) &reply);
  194680. }
  194681. void SystemClipboard::copyTextToClipboard (const String& clipText) throw()
  194682. {
  194683. initSelectionAtoms();
  194684. localClipboardContent = clipText;
  194685. XSetSelectionOwner (display, XA_PRIMARY, juce_messageWindowHandle, CurrentTime);
  194686. XSetSelectionOwner (display, atom_CLIPBOARD, juce_messageWindowHandle, CurrentTime);
  194687. }
  194688. const String SystemClipboard::getTextFromClipboard() throw()
  194689. {
  194690. initSelectionAtoms();
  194691. String content;
  194692. Atom selection = XA_PRIMARY;
  194693. Window selectionOwner = None;
  194694. if ((selectionOwner = XGetSelectionOwner (display, selection)) == None)
  194695. {
  194696. selection = atom_CLIPBOARD;
  194697. selectionOwner = XGetSelectionOwner (display, selection);
  194698. }
  194699. if (selectionOwner != None)
  194700. {
  194701. if (selectionOwner == juce_messageWindowHandle)
  194702. {
  194703. content = localClipboardContent;
  194704. }
  194705. else
  194706. {
  194707. // first try: we want an utf8 string
  194708. bool ok = juce_requestSelectionContent (content, selection, atom_UTF8_STRING);
  194709. if (! ok)
  194710. {
  194711. // second chance, ask for a good old locale-dependent string ..
  194712. ok = juce_requestSelectionContent (content, selection, XA_STRING);
  194713. }
  194714. }
  194715. }
  194716. return content;
  194717. }
  194718. #endif
  194719. /*** End of inlined file: juce_linux_Clipboard.cpp ***/
  194720. /*** Start of inlined file: juce_linux_Messaging.cpp ***/
  194721. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  194722. // compiled on its own).
  194723. #if JUCE_INCLUDED_FILE
  194724. #ifdef JUCE_DEBUG
  194725. #define JUCE_DEBUG_XERRORS 1
  194726. #endif
  194727. Display* display = 0; // This is also referenced from WindowDriver.cpp
  194728. Window juce_messageWindowHandle = None;
  194729. #define SpecialAtom "JUCESpecialAtom"
  194730. #define BroadcastAtom "JUCEBroadcastAtom"
  194731. #define SpecialCallbackAtom "JUCESpecialCallbackAtom"
  194732. static Atom specialId;
  194733. static Atom broadcastId;
  194734. static Atom specialCallbackId;
  194735. // This is referenced from Windowing.cpp
  194736. XContext improbableNumber;
  194737. // Defined in Windowing.cpp
  194738. extern void juce_windowMessageReceive (XEvent* event);
  194739. // Defined in Clipboard.cpp
  194740. extern void juce_handleSelectionRequest (XSelectionRequestEvent &evt);
  194741. ScopedXLock::ScopedXLock() { XLockDisplay (display); }
  194742. ScopedXLock::~ScopedXLock() { XUnlockDisplay (display); }
  194743. class InternalMessageQueue
  194744. {
  194745. public:
  194746. InternalMessageQueue()
  194747. : bytesInSocket (0)
  194748. {
  194749. int ret = ::socketpair (AF_LOCAL, SOCK_STREAM, 0, fd);
  194750. (void) ret; jassert (ret == 0);
  194751. setNonBlocking (fd[0]);
  194752. setNonBlocking (fd[1]);
  194753. }
  194754. ~InternalMessageQueue()
  194755. {
  194756. close (fd[0]);
  194757. close (fd[1]);
  194758. }
  194759. void postMessage (Message* msg)
  194760. {
  194761. const int maxBytesInSocketQueue = 128;
  194762. ScopedLock sl (lock);
  194763. queue.add (msg);
  194764. if (bytesInSocket < maxBytesInSocketQueue)
  194765. {
  194766. ++bytesInSocket;
  194767. ScopedUnlock ul (lock);
  194768. const unsigned char x = 0xff;
  194769. size_t bytesWritten = write (fd[0], &x, 1);
  194770. (void) bytesWritten;
  194771. }
  194772. }
  194773. bool isEmpty() const
  194774. {
  194775. ScopedLock sl (lock);
  194776. return queue.size() == 0;
  194777. }
  194778. Message* popNextMessage()
  194779. {
  194780. ScopedLock sl (lock);
  194781. if (bytesInSocket > 0)
  194782. {
  194783. --bytesInSocket;
  194784. ScopedUnlock ul (lock);
  194785. unsigned char x;
  194786. size_t numBytes = read (fd[1], &x, 1);
  194787. (void) numBytes;
  194788. }
  194789. Message* m = queue[0];
  194790. queue.remove (0, false /* deleteObject */);
  194791. return m;
  194792. }
  194793. int getWaitHandle() const { return fd[1]; }
  194794. private:
  194795. CriticalSection lock;
  194796. OwnedArray <Message> queue;
  194797. int fd[2];
  194798. int bytesInSocket;
  194799. static bool setNonBlocking (int handle)
  194800. {
  194801. int socketFlags = fcntl (handle, F_GETFL, 0);
  194802. if (socketFlags == -1)
  194803. return false;
  194804. socketFlags |= O_NONBLOCK;
  194805. return fcntl (handle, F_SETFL, socketFlags) == 0;
  194806. }
  194807. };
  194808. struct MessageThreadFuncCall
  194809. {
  194810. enum { uniqueID = 0x73774623 };
  194811. MessageCallbackFunction* func;
  194812. void* parameter;
  194813. void* result;
  194814. CriticalSection lock;
  194815. WaitableEvent event;
  194816. };
  194817. static InternalMessageQueue* juce_internalMessageQueue = 0;
  194818. // error handling in X11
  194819. static bool errorOccurred = false;
  194820. static bool keyboardBreakOccurred = false;
  194821. static XErrorHandler oldErrorHandler = (XErrorHandler) 0;
  194822. static XIOErrorHandler oldIOErrorHandler = (XIOErrorHandler) 0;
  194823. // Usually happens when client-server connection is broken
  194824. static int ioErrorHandler (Display* display)
  194825. {
  194826. DBG (T("ERROR: connection to X server broken.. terminating."));
  194827. errorOccurred = true;
  194828. if (JUCEApplication::getInstance() != 0)
  194829. Process::terminate();
  194830. return 0;
  194831. }
  194832. // A protocol error has occurred
  194833. static int errorHandler (Display* display, XErrorEvent* event)
  194834. {
  194835. #ifdef JUCE_DEBUG_XERRORS
  194836. char errorStr[64] = { 0 };
  194837. char requestStr[64] = { 0 };
  194838. XGetErrorText (display, event->error_code, errorStr, 64);
  194839. XGetErrorDatabaseText (display, "XRequest", String (event->request_code).toCString(),
  194840. "Unknown", requestStr, 64);
  194841. DBG (T("ERROR: X returned ") + String (errorStr) + T(" for operation ") + String (requestStr));
  194842. #endif
  194843. return 0;
  194844. }
  194845. // Breakin from keyboard
  194846. static void signalHandler (int sig)
  194847. {
  194848. if (sig == SIGINT)
  194849. {
  194850. keyboardBreakOccurred = true;
  194851. return;
  194852. }
  194853. static bool reentrant = false;
  194854. if (! reentrant)
  194855. {
  194856. reentrant = true;
  194857. // Illegal instruction
  194858. fflush (stdout);
  194859. Logger::outputDebugString ("ERROR: Program executed illegal instruction.. terminating");
  194860. errorOccurred = true;
  194861. if (JUCEApplication::getInstance() != 0)
  194862. Process::terminate();
  194863. }
  194864. else
  194865. {
  194866. if (JUCEApplication::getInstance() != 0)
  194867. exit(0);
  194868. }
  194869. }
  194870. void MessageManager::doPlatformSpecificInitialisation()
  194871. {
  194872. // Initialise xlib for multiple thread support
  194873. static bool initThreadCalled = false;
  194874. if (! initThreadCalled)
  194875. {
  194876. if (! XInitThreads())
  194877. {
  194878. // This is fatal! Print error and closedown
  194879. Logger::outputDebugString ("Failed to initialise xlib thread support.");
  194880. if (JUCEApplication::getInstance() != 0)
  194881. Process::terminate();
  194882. return;
  194883. }
  194884. initThreadCalled = true;
  194885. }
  194886. // This is called if the client/server connection is broken
  194887. oldIOErrorHandler = XSetIOErrorHandler (ioErrorHandler);
  194888. // This is called if a protocol error occurs
  194889. oldErrorHandler = XSetErrorHandler (errorHandler);
  194890. // Install signal handler for break-in
  194891. struct sigaction saction;
  194892. sigset_t maskSet;
  194893. sigemptyset (&maskSet);
  194894. saction.sa_handler = signalHandler;
  194895. saction.sa_mask = maskSet;
  194896. saction.sa_flags = 0;
  194897. sigaction (SIGINT, &saction, NULL);
  194898. #ifndef _DEBUG
  194899. // Setup signal handlers for various fatal errors
  194900. sigaction (SIGILL, &saction, NULL);
  194901. sigaction (SIGBUS, &saction, NULL);
  194902. sigaction (SIGFPE, &saction, NULL);
  194903. sigaction (SIGSEGV, &saction, NULL);
  194904. sigaction (SIGSYS, &saction, NULL);
  194905. #endif
  194906. // Create the internal message queue
  194907. juce_internalMessageQueue = new InternalMessageQueue();
  194908. // Try to connect to a display
  194909. String displayName (getenv ("DISPLAY"));
  194910. if (displayName.isEmpty())
  194911. displayName = ":0.0";
  194912. display = XOpenDisplay (displayName.toCString());
  194913. if (display == 0)
  194914. {
  194915. // This is not fatal! we can run headless.
  194916. return;
  194917. }
  194918. // Get defaults for various properties
  194919. int screen = DefaultScreen (display);
  194920. Window root = RootWindow (display, screen);
  194921. Visual* visual = DefaultVisual (display, screen);
  194922. // Create atoms for our ClientMessages (these cannot be deleted)
  194923. specialId = XInternAtom (display, SpecialAtom, false);
  194924. broadcastId = XInternAtom (display, BroadcastAtom, false);
  194925. specialCallbackId = XInternAtom (display, SpecialCallbackAtom, false);
  194926. // Create a context to store user data associated with Windows we
  194927. // create in WindowDriver
  194928. improbableNumber = XUniqueContext();
  194929. // We're only interested in client messages for this window
  194930. // which are always sent
  194931. XSetWindowAttributes swa;
  194932. swa.event_mask = NoEventMask;
  194933. // Create our message window (this will never be mapped)
  194934. juce_messageWindowHandle = XCreateWindow (display, root,
  194935. 0, 0, 1, 1, 0, 0, InputOnly,
  194936. visual, CWEventMask, &swa);
  194937. }
  194938. void MessageManager::doPlatformSpecificShutdown()
  194939. {
  194940. deleteAndZero (juce_internalMessageQueue);
  194941. if (display != 0 && ! errorOccurred)
  194942. {
  194943. XDestroyWindow (display, juce_messageWindowHandle);
  194944. XCloseDisplay (display);
  194945. // reset pointers
  194946. juce_messageWindowHandle = 0;
  194947. display = 0;
  194948. // Restore original error handlers
  194949. XSetIOErrorHandler (oldIOErrorHandler);
  194950. oldIOErrorHandler = 0;
  194951. XSetErrorHandler (oldErrorHandler);
  194952. oldErrorHandler = 0;
  194953. }
  194954. }
  194955. bool juce_postMessageToSystemQueue (void* message)
  194956. {
  194957. if (errorOccurred)
  194958. return false;
  194959. juce_internalMessageQueue->postMessage ((Message*) message);
  194960. return true;
  194961. }
  194962. void MessageManager::broadcastMessage (const String& value) throw()
  194963. {
  194964. }
  194965. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* func,
  194966. void* parameter)
  194967. {
  194968. if (errorOccurred)
  194969. return 0;
  194970. if (! isThisTheMessageThread())
  194971. {
  194972. MessageThreadFuncCall messageCallContext;
  194973. messageCallContext.func = func;
  194974. messageCallContext.parameter = parameter;
  194975. juce_internalMessageQueue->postMessage (new Message (MessageThreadFuncCall::uniqueID,
  194976. 0, 0, &messageCallContext));
  194977. // Wait for it to complete before continuing
  194978. messageCallContext.event.wait();
  194979. return messageCallContext.result;
  194980. }
  194981. else
  194982. {
  194983. // Just call the function directly
  194984. return func (parameter);
  194985. }
  194986. }
  194987. // Wait for an event (either XEvent, or an internal Message)
  194988. static bool juce_sleepUntilEvent (const int timeoutMs)
  194989. {
  194990. if (! juce_internalMessageQueue->isEmpty())
  194991. return true;
  194992. if (display != 0)
  194993. {
  194994. ScopedXLock xlock;
  194995. if (XPending (display))
  194996. return true;
  194997. }
  194998. struct timeval tv;
  194999. tv.tv_sec = 0;
  195000. tv.tv_usec = timeoutMs * 1000;
  195001. int fd0 = juce_internalMessageQueue->getWaitHandle();
  195002. int fdmax = fd0;
  195003. fd_set readset;
  195004. FD_ZERO (&readset);
  195005. FD_SET (fd0, &readset);
  195006. if (display != 0)
  195007. {
  195008. ScopedXLock xlock;
  195009. int fd1 = XConnectionNumber (display);
  195010. FD_SET (fd1, &readset);
  195011. fdmax = jmax (fd0, fd1);
  195012. }
  195013. const int ret = select (fdmax + 1, &readset, 0, 0, &tv);
  195014. return (ret > 0); // ret <= 0 if error or timeout
  195015. }
  195016. // Handle next XEvent (if any)
  195017. static bool juce_dispatchNextXEvent()
  195018. {
  195019. if (display == 0)
  195020. return false;
  195021. XEvent evt;
  195022. {
  195023. ScopedXLock xlock;
  195024. if (! XPending (display))
  195025. return false;
  195026. XNextEvent (display, &evt);
  195027. }
  195028. if (evt.type == SelectionRequest && evt.xany.window == juce_messageWindowHandle)
  195029. {
  195030. juce_handleSelectionRequest (evt.xselectionrequest);
  195031. }
  195032. else if (evt.xany.window != juce_messageWindowHandle)
  195033. {
  195034. juce_windowMessageReceive (&evt);
  195035. }
  195036. return true;
  195037. }
  195038. // Handle next internal Message (if any)
  195039. static bool juce_dispatchNextInternalMessage()
  195040. {
  195041. ScopedPointer <Message> msg (juce_internalMessageQueue->popNextMessage());
  195042. if (msg == 0)
  195043. return false;
  195044. if (msg->intParameter1 == MessageThreadFuncCall::uniqueID)
  195045. {
  195046. // Handle callback message
  195047. MessageThreadFuncCall* const call = (MessageThreadFuncCall*) msg->pointerParameter;
  195048. call->result = (*(call->func)) (call->parameter);
  195049. call->event.signal();
  195050. }
  195051. else
  195052. {
  195053. // Handle "normal" messages
  195054. MessageManager::getInstance()->deliverMessage (msg.release());
  195055. }
  195056. return true;
  195057. }
  195058. // this function expects that it will NEVER be called simultaneously for two concurrent threads
  195059. bool juce_dispatchNextMessageOnSystemQueue (bool returnIfNoPendingMessages)
  195060. {
  195061. for (;;)
  195062. {
  195063. if (errorOccurred)
  195064. break;
  195065. if (keyboardBreakOccurred)
  195066. {
  195067. errorOccurred = true;
  195068. if (JUCEApplication::getInstance() != 0)
  195069. Process::terminate();
  195070. break;
  195071. }
  195072. static int totalEventCount = 0;
  195073. ++totalEventCount;
  195074. // The purpose here is to give either priority to XEvents or
  195075. // to internal messages This is necessary to keep a "good"
  195076. // behaviour when the cpu is overloaded
  195077. if (totalEventCount & 1)
  195078. {
  195079. if (juce_dispatchNextXEvent() || juce_dispatchNextInternalMessage())
  195080. return true;
  195081. }
  195082. else
  195083. {
  195084. if (juce_dispatchNextInternalMessage() || juce_dispatchNextXEvent())
  195085. return true;
  195086. }
  195087. if (returnIfNoPendingMessages) // early exit
  195088. break;
  195089. // the timeout is to be on the safe side, but it does not seem to be useful
  195090. juce_sleepUntilEvent (2000);
  195091. }
  195092. return false;
  195093. }
  195094. #endif
  195095. /*** End of inlined file: juce_linux_Messaging.cpp ***/
  195096. /*** Start of inlined file: juce_linux_Fonts.cpp ***/
  195097. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195098. // compiled on its own).
  195099. #if JUCE_INCLUDED_FILE
  195100. class FreeTypeFontFace
  195101. {
  195102. public:
  195103. enum FontStyle
  195104. {
  195105. Plain = 0,
  195106. Bold = 1,
  195107. Italic = 2
  195108. };
  195109. struct FontNameIndex
  195110. {
  195111. String fileName;
  195112. int faceIndex;
  195113. };
  195114. FreeTypeFontFace (const String& familyName) throw()
  195115. : hasSerif (false),
  195116. monospaced (false)
  195117. {
  195118. family = familyName;
  195119. }
  195120. void setFileName (const String& name, const int faceIndex, FontStyle style) throw()
  195121. {
  195122. if (names [(int) style].fileName.isEmpty())
  195123. {
  195124. names [(int) style].fileName = name;
  195125. names [(int) style].faceIndex = faceIndex;
  195126. }
  195127. }
  195128. const String& getFamilyName() const throw() { return family; }
  195129. const String& getFileName (const int style, int& faceIndex) const throw()
  195130. {
  195131. faceIndex = names[style].faceIndex;
  195132. return names[style].fileName;
  195133. }
  195134. void setMonospaced (bool mono) throw() { monospaced = mono; }
  195135. bool getMonospaced() const throw() { return monospaced; }
  195136. void setSerif (const bool serif) throw() { hasSerif = serif; }
  195137. bool getSerif() const throw() { return hasSerif; }
  195138. private:
  195139. String family;
  195140. FontNameIndex names[4];
  195141. bool hasSerif, monospaced;
  195142. };
  195143. class FreeTypeInterface : public DeletedAtShutdown
  195144. {
  195145. public:
  195146. FreeTypeInterface() throw()
  195147. : lastFace (0),
  195148. lastBold (false),
  195149. lastItalic (false)
  195150. {
  195151. if (FT_Init_FreeType (&ftLib) != 0)
  195152. {
  195153. ftLib = 0;
  195154. DBG (T("Failed to initialize FreeType"));
  195155. }
  195156. StringArray fontDirs;
  195157. fontDirs.addTokens (String (getenv ("JUCE_FONT_PATH")), T(";,"), 0);
  195158. fontDirs.removeEmptyStrings (true);
  195159. if (fontDirs.size() == 0)
  195160. {
  195161. XmlDocument fontsConfig (File ("/etc/fonts/fonts.conf"));
  195162. XmlElement* const fontsInfo = fontsConfig.getDocumentElement();
  195163. if (fontsInfo != 0)
  195164. {
  195165. forEachXmlChildElementWithTagName (*fontsInfo, e, T("dir"))
  195166. {
  195167. fontDirs.add (e->getAllSubText().trim());
  195168. }
  195169. delete fontsInfo;
  195170. }
  195171. }
  195172. if (fontDirs.size() == 0)
  195173. fontDirs.add ("/usr/X11R6/lib/X11/fonts");
  195174. for (int i = 0; i < fontDirs.size(); ++i)
  195175. enumerateFaces (fontDirs[i]);
  195176. }
  195177. ~FreeTypeInterface() throw()
  195178. {
  195179. if (lastFace != 0)
  195180. FT_Done_Face (lastFace);
  195181. if (ftLib != 0)
  195182. FT_Done_FreeType (ftLib);
  195183. clearSingletonInstance();
  195184. }
  195185. FreeTypeFontFace* findOrCreate (const String& familyName,
  195186. const bool create = false) throw()
  195187. {
  195188. for (int i = 0; i < faces.size(); i++)
  195189. if (faces[i]->getFamilyName() == familyName)
  195190. return faces[i];
  195191. if (! create)
  195192. return NULL;
  195193. FreeTypeFontFace* newFace = new FreeTypeFontFace (familyName);
  195194. faces.add (newFace);
  195195. return newFace;
  195196. }
  195197. // Enumerate all font faces available in a given directory
  195198. void enumerateFaces (const String& path) throw()
  195199. {
  195200. File dirPath (path);
  195201. if (path.isEmpty() || ! dirPath.isDirectory())
  195202. return;
  195203. DirectoryIterator di (dirPath, true);
  195204. while (di.next())
  195205. {
  195206. File possible (di.getFile());
  195207. if (possible.hasFileExtension (T("ttf"))
  195208. || possible.hasFileExtension (T("pfb"))
  195209. || possible.hasFileExtension (T("pcf")))
  195210. {
  195211. FT_Face face;
  195212. int faceIndex = 0;
  195213. int numFaces = 0;
  195214. do
  195215. {
  195216. if (FT_New_Face (ftLib, possible.getFullPathName().toUTF8(),
  195217. faceIndex, &face) == 0)
  195218. {
  195219. if (faceIndex == 0)
  195220. numFaces = face->num_faces;
  195221. if ((face->face_flags & FT_FACE_FLAG_SCALABLE) != 0)
  195222. {
  195223. FreeTypeFontFace* const newFace = findOrCreate (face->family_name, true);
  195224. int style = (int) FreeTypeFontFace::Plain;
  195225. if ((face->style_flags & FT_STYLE_FLAG_BOLD) != 0)
  195226. style |= (int) FreeTypeFontFace::Bold;
  195227. if ((face->style_flags & FT_STYLE_FLAG_ITALIC) != 0)
  195228. style |= (int) FreeTypeFontFace::Italic;
  195229. newFace->setFileName (possible.getFullPathName(), faceIndex, (FreeTypeFontFace::FontStyle) style);
  195230. newFace->setMonospaced ((face->face_flags & FT_FACE_FLAG_FIXED_WIDTH) != 0);
  195231. // Surely there must be a better way to do this?
  195232. const String name (face->family_name);
  195233. newFace->setSerif (! (name.containsIgnoreCase (T("Sans"))
  195234. || name.containsIgnoreCase (T("Verdana"))
  195235. || name.containsIgnoreCase (T("Arial"))));
  195236. }
  195237. FT_Done_Face (face);
  195238. }
  195239. ++faceIndex;
  195240. }
  195241. while (faceIndex < numFaces);
  195242. }
  195243. }
  195244. }
  195245. // Create a FreeType face object for a given font
  195246. FT_Face createFT_Face (const String& fontName,
  195247. const bool bold,
  195248. const bool italic) throw()
  195249. {
  195250. FT_Face face = 0;
  195251. if (fontName == lastFontName && bold == lastBold && italic == lastItalic)
  195252. {
  195253. face = lastFace;
  195254. }
  195255. else
  195256. {
  195257. if (lastFace != 0)
  195258. {
  195259. FT_Done_Face (lastFace);
  195260. lastFace = 0;
  195261. }
  195262. lastFontName = fontName;
  195263. lastBold = bold;
  195264. lastItalic = italic;
  195265. FreeTypeFontFace* const ftFace = findOrCreate (fontName);
  195266. if (ftFace != 0)
  195267. {
  195268. int style = (int) FreeTypeFontFace::Plain;
  195269. if (bold)
  195270. style |= (int) FreeTypeFontFace::Bold;
  195271. if (italic)
  195272. style |= (int) FreeTypeFontFace::Italic;
  195273. int faceIndex;
  195274. String fileName (ftFace->getFileName (style, faceIndex));
  195275. if (fileName.isEmpty())
  195276. {
  195277. style ^= (int) FreeTypeFontFace::Bold;
  195278. fileName = ftFace->getFileName (style, faceIndex);
  195279. if (fileName.isEmpty())
  195280. {
  195281. style ^= (int) FreeTypeFontFace::Bold;
  195282. style ^= (int) FreeTypeFontFace::Italic;
  195283. fileName = ftFace->getFileName (style, faceIndex);
  195284. if (! fileName.length())
  195285. {
  195286. style ^= (int) FreeTypeFontFace::Bold;
  195287. fileName = ftFace->getFileName (style, faceIndex);
  195288. }
  195289. }
  195290. }
  195291. if (! FT_New_Face (ftLib, fileName.toUTF8(), faceIndex, &lastFace))
  195292. {
  195293. face = lastFace;
  195294. // If there isn't a unicode charmap then select the first one.
  195295. if (FT_Select_Charmap (face, ft_encoding_unicode))
  195296. FT_Set_Charmap (face, face->charmaps[0]);
  195297. }
  195298. }
  195299. }
  195300. return face;
  195301. }
  195302. bool addGlyph (FT_Face face, CustomTypeface& dest, uint32 character) throw()
  195303. {
  195304. const unsigned int glyphIndex = FT_Get_Char_Index (face, character);
  195305. const float height = (float) (face->ascender - face->descender);
  195306. const float scaleX = 1.0f / height;
  195307. const float scaleY = -1.0f / height;
  195308. Path destShape;
  195309. #define CONVERTX(val) (scaleX * (val).x)
  195310. #define CONVERTY(val) (scaleY * (val).y)
  195311. if (FT_Load_Glyph (face, glyphIndex, FT_LOAD_NO_SCALE | FT_LOAD_NO_BITMAP | FT_LOAD_IGNORE_TRANSFORM) != 0
  195312. || face->glyph->format != ft_glyph_format_outline)
  195313. {
  195314. return false;
  195315. }
  195316. const FT_Outline* const outline = &face->glyph->outline;
  195317. const short* const contours = outline->contours;
  195318. const char* const tags = outline->tags;
  195319. FT_Vector* const points = outline->points;
  195320. for (int c = 0; c < outline->n_contours; c++)
  195321. {
  195322. const int startPoint = (c == 0) ? 0 : contours [c - 1] + 1;
  195323. const int endPoint = contours[c];
  195324. for (int p = startPoint; p <= endPoint; p++)
  195325. {
  195326. const float x = CONVERTX (points[p]);
  195327. const float y = CONVERTY (points[p]);
  195328. if (p == startPoint)
  195329. {
  195330. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195331. {
  195332. float x2 = CONVERTX (points [endPoint]);
  195333. float y2 = CONVERTY (points [endPoint]);
  195334. if (FT_CURVE_TAG (tags[endPoint]) != FT_Curve_Tag_On)
  195335. {
  195336. x2 = (x + x2) * 0.5f;
  195337. y2 = (y + y2) * 0.5f;
  195338. }
  195339. destShape.startNewSubPath (x2, y2);
  195340. }
  195341. else
  195342. {
  195343. destShape.startNewSubPath (x, y);
  195344. }
  195345. }
  195346. if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_On)
  195347. {
  195348. if (p != startPoint)
  195349. destShape.lineTo (x, y);
  195350. }
  195351. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Conic)
  195352. {
  195353. const int nextIndex = (p == endPoint) ? startPoint : p + 1;
  195354. float x2 = CONVERTX (points [nextIndex]);
  195355. float y2 = CONVERTY (points [nextIndex]);
  195356. if (FT_CURVE_TAG (tags [nextIndex]) == FT_Curve_Tag_Conic)
  195357. {
  195358. x2 = (x + x2) * 0.5f;
  195359. y2 = (y + y2) * 0.5f;
  195360. }
  195361. else
  195362. {
  195363. ++p;
  195364. }
  195365. destShape.quadraticTo (x, y, x2, y2);
  195366. }
  195367. else if (FT_CURVE_TAG (tags[p]) == FT_Curve_Tag_Cubic)
  195368. {
  195369. if (p >= endPoint)
  195370. return false;
  195371. const int next1 = p + 1;
  195372. const int next2 = (p == (endPoint - 1)) ? startPoint : p + 2;
  195373. const float x2 = CONVERTX (points [next1]);
  195374. const float y2 = CONVERTY (points [next1]);
  195375. const float x3 = CONVERTX (points [next2]);
  195376. const float y3 = CONVERTY (points [next2]);
  195377. if (FT_CURVE_TAG (tags[next1]) != FT_Curve_Tag_Cubic
  195378. || FT_CURVE_TAG (tags[next2]) != FT_Curve_Tag_On)
  195379. return false;
  195380. destShape.cubicTo (x, y, x2, y2, x3, y3);
  195381. p += 2;
  195382. }
  195383. }
  195384. destShape.closeSubPath();
  195385. }
  195386. dest.addGlyph (character, destShape, face->glyph->metrics.horiAdvance / height);
  195387. if ((face->face_flags & FT_FACE_FLAG_KERNING) != 0)
  195388. addKerning (face, dest, character, glyphIndex);
  195389. return true;
  195390. }
  195391. void addKerning (FT_Face face, CustomTypeface& dest, const uint32 character, const uint32 glyphIndex) throw()
  195392. {
  195393. const float height = (float) (face->ascender - face->descender);
  195394. uint32 rightGlyphIndex;
  195395. uint32 rightCharCode = FT_Get_First_Char (face, &rightGlyphIndex);
  195396. while (rightGlyphIndex != 0)
  195397. {
  195398. FT_Vector kerning;
  195399. if (FT_Get_Kerning (face, glyphIndex, rightGlyphIndex, ft_kerning_unscaled, &kerning) == 0)
  195400. {
  195401. if (kerning.x != 0)
  195402. dest.addKerningPair (character, rightCharCode, kerning.x / height);
  195403. }
  195404. rightCharCode = FT_Get_Next_Char (face, rightCharCode, &rightGlyphIndex);
  195405. }
  195406. }
  195407. // Add a glyph to a font
  195408. bool addGlyphToFont (const uint32 character,
  195409. const tchar* fontName, bool bold, bool italic,
  195410. CustomTypeface& dest) throw()
  195411. {
  195412. FT_Face face = createFT_Face (fontName, bold, italic);
  195413. if (face != 0)
  195414. return addGlyph (face, dest, character);
  195415. return false;
  195416. }
  195417. void getFamilyNames (StringArray& familyNames) const throw()
  195418. {
  195419. for (int i = 0; i < faces.size(); i++)
  195420. familyNames.add (faces[i]->getFamilyName());
  195421. }
  195422. void getMonospacedNames (StringArray& monoSpaced) const throw()
  195423. {
  195424. for (int i = 0; i < faces.size(); i++)
  195425. if (faces[i]->getMonospaced())
  195426. monoSpaced.add (faces[i]->getFamilyName());
  195427. }
  195428. void getSerifNames (StringArray& serif) const throw()
  195429. {
  195430. for (int i = 0; i < faces.size(); i++)
  195431. if (faces[i]->getSerif())
  195432. serif.add (faces[i]->getFamilyName());
  195433. }
  195434. void getSansSerifNames (StringArray& sansSerif) const throw()
  195435. {
  195436. for (int i = 0; i < faces.size(); i++)
  195437. if (! faces[i]->getSerif())
  195438. sansSerif.add (faces[i]->getFamilyName());
  195439. }
  195440. juce_DeclareSingleton_SingleThreaded_Minimal (FreeTypeInterface)
  195441. private:
  195442. FT_Library ftLib;
  195443. FT_Face lastFace;
  195444. String lastFontName;
  195445. bool lastBold, lastItalic;
  195446. OwnedArray<FreeTypeFontFace> faces;
  195447. };
  195448. juce_ImplementSingleton_SingleThreaded (FreeTypeInterface)
  195449. class FreetypeTypeface : public CustomTypeface
  195450. {
  195451. public:
  195452. FreetypeTypeface (const Font& font)
  195453. {
  195454. FT_Face face = FreeTypeInterface::getInstance()
  195455. ->createFT_Face (font.getTypefaceName(), font.isBold(), font.isItalic());
  195456. if (face == 0)
  195457. {
  195458. #ifdef JUCE_DEBUG
  195459. String msg (T("Failed to create typeface: "));
  195460. msg << font.getTypefaceName() << " " << (font.isBold() ? 'B' : ' ') << (font.isItalic() ? 'I' : ' ');
  195461. DBG (msg);
  195462. #endif
  195463. }
  195464. else
  195465. {
  195466. setCharacteristics (font.getTypefaceName(),
  195467. face->ascender / (float) (face->ascender - face->descender),
  195468. font.isBold(), font.isItalic(),
  195469. L' ');
  195470. }
  195471. }
  195472. bool loadGlyphIfPossible (const juce_wchar character)
  195473. {
  195474. return FreeTypeInterface::getInstance()
  195475. ->addGlyphToFont (character, name, isBold, isItalic, *this);
  195476. }
  195477. };
  195478. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  195479. {
  195480. return new FreetypeTypeface (font);
  195481. }
  195482. const StringArray Font::findAllTypefaceNames() throw()
  195483. {
  195484. StringArray s;
  195485. FreeTypeInterface::getInstance()->getFamilyNames (s);
  195486. s.sort (true);
  195487. return s;
  195488. }
  195489. static const String pickBestFont (const StringArray& names,
  195490. const char* const choicesString)
  195491. {
  195492. StringArray choices;
  195493. choices.addTokens (String (choicesString), T(","), 0);
  195494. choices.trim();
  195495. choices.removeEmptyStrings();
  195496. int i, j;
  195497. for (j = 0; j < choices.size(); ++j)
  195498. if (names.contains (choices[j], true))
  195499. return choices[j];
  195500. for (j = 0; j < choices.size(); ++j)
  195501. for (i = 0; i < names.size(); i++)
  195502. if (names[i].startsWithIgnoreCase (choices[j]))
  195503. return names[i];
  195504. for (j = 0; j < choices.size(); ++j)
  195505. for (i = 0; i < names.size(); i++)
  195506. if (names[i].containsIgnoreCase (choices[j]))
  195507. return names[i];
  195508. return names[0];
  195509. }
  195510. static const String linux_getDefaultSansSerifFontName()
  195511. {
  195512. StringArray allFonts;
  195513. FreeTypeInterface::getInstance()->getSansSerifNames (allFonts);
  195514. return pickBestFont (allFonts, "Verdana, Bitstream Vera Sans, Luxi Sans, Sans");
  195515. }
  195516. static const String linux_getDefaultSerifFontName()
  195517. {
  195518. StringArray allFonts;
  195519. FreeTypeInterface::getInstance()->getSerifNames (allFonts);
  195520. return pickBestFont (allFonts, "Bitstream Vera Serif, Times, Nimbus Roman, Serif");
  195521. }
  195522. static const String linux_getDefaultMonospacedFontName()
  195523. {
  195524. StringArray allFonts;
  195525. FreeTypeInterface::getInstance()->getMonospacedNames (allFonts);
  195526. return pickBestFont (allFonts, "Bitstream Vera Sans Mono, Courier, Sans Mono, Mono");
  195527. }
  195528. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  195529. {
  195530. defaultSans = linux_getDefaultSansSerifFontName();
  195531. defaultSerif = linux_getDefaultSerifFontName();
  195532. defaultFixed = linux_getDefaultMonospacedFontName();
  195533. }
  195534. #endif
  195535. /*** End of inlined file: juce_linux_Fonts.cpp ***/
  195536. /*** Start of inlined file: juce_linux_Windowing.cpp ***/
  195537. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  195538. // compiled on its own).
  195539. #if JUCE_INCLUDED_FILE
  195540. #define TAKE_FOCUS 0
  195541. #define DELETE_WINDOW 1
  195542. #define SYSTEM_TRAY_REQUEST_DOCK 0
  195543. #define SYSTEM_TRAY_BEGIN_MESSAGE 1
  195544. #define SYSTEM_TRAY_CANCEL_MESSAGE 2
  195545. static const int repaintTimerPeriod = 1000 / 100; // 100 fps maximum
  195546. static Atom wm_ChangeState = None;
  195547. static Atom wm_State = None;
  195548. static Atom wm_Protocols = None;
  195549. static Atom wm_ProtocolList [2] = { None, None };
  195550. static Atom wm_ActiveWin = None;
  195551. #define ourDndVersion 3
  195552. static Atom XA_XdndAware = None;
  195553. static Atom XA_XdndEnter = None;
  195554. static Atom XA_XdndLeave = None;
  195555. static Atom XA_XdndPosition = None;
  195556. static Atom XA_XdndStatus = None;
  195557. static Atom XA_XdndDrop = None;
  195558. static Atom XA_XdndFinished = None;
  195559. static Atom XA_XdndSelection = None;
  195560. static Atom XA_XdndProxy = None;
  195561. static Atom XA_XdndTypeList = None;
  195562. static Atom XA_XdndActionList = None;
  195563. static Atom XA_XdndActionDescription = None;
  195564. static Atom XA_XdndActionCopy = None;
  195565. static Atom XA_XdndActionMove = None;
  195566. static Atom XA_XdndActionLink = None;
  195567. static Atom XA_XdndActionAsk = None;
  195568. static Atom XA_XdndActionPrivate = None;
  195569. static Atom XA_JXSelectionWindowProperty = None;
  195570. static Atom XA_MimeTextPlain = None;
  195571. static Atom XA_MimeTextUriList = None;
  195572. static Atom XA_MimeRootDrop = None;
  195573. static XErrorHandler oldHandler = 0;
  195574. static int trappedErrorCode = 0;
  195575. extern "C" int errorTrapHandler (Display* dpy, XErrorEvent* err)
  195576. {
  195577. trappedErrorCode = err->error_code;
  195578. return 0;
  195579. }
  195580. static void trapErrors()
  195581. {
  195582. trappedErrorCode = 0;
  195583. oldHandler = XSetErrorHandler (errorTrapHandler);
  195584. }
  195585. static bool untrapErrors()
  195586. {
  195587. XSetErrorHandler (oldHandler);
  195588. return (trappedErrorCode == 0);
  195589. }
  195590. static bool isActiveApplication = false;
  195591. bool Process::isForegroundProcess()
  195592. {
  195593. return isActiveApplication;
  195594. }
  195595. // These are defined in juce_linux_Messaging.cpp
  195596. extern Display* display;
  195597. extern XContext improbableNumber;
  195598. static const int eventMask = NoEventMask | KeyPressMask | KeyReleaseMask | ButtonPressMask | ButtonReleaseMask
  195599. | EnterWindowMask | LeaveWindowMask | PointerMotionMask | KeymapStateMask
  195600. | ExposureMask | StructureNotifyMask | FocusChangeMask;
  195601. enum MouseButtons
  195602. {
  195603. NoButton = 0,
  195604. LeftButton = 1,
  195605. MiddleButton = 2,
  195606. RightButton = 3,
  195607. WheelUp = 4,
  195608. WheelDown = 5
  195609. };
  195610. static const Point<int> getMousePos (int& mouseMods) throw()
  195611. {
  195612. Window root, child;
  195613. int x, y, winx, winy;
  195614. unsigned int mask;
  195615. mouseMods = 0;
  195616. ScopedXLock xlock;
  195617. if (XQueryPointer (display,
  195618. RootWindow (display, DefaultScreen (display)),
  195619. &root, &child,
  195620. &x, &y, &winx, &winy, &mask) == False)
  195621. {
  195622. // Pointer not on the default screen
  195623. x = y = -1;
  195624. }
  195625. else
  195626. {
  195627. if ((mask & Button1Mask) != 0) mouseMods |= ModifierKeys::leftButtonModifier;
  195628. if ((mask & Button2Mask) != 0) mouseMods |= ModifierKeys::middleButtonModifier;
  195629. if ((mask & Button3Mask) != 0) mouseMods |= ModifierKeys::rightButtonModifier;
  195630. }
  195631. return Point<int> (x, y);
  195632. }
  195633. static int AltMask = 0;
  195634. static int NumLockMask = 0;
  195635. static bool numLock = 0;
  195636. static bool capsLock = 0;
  195637. static char keyStates [32];
  195638. static void updateKeyStates (const int keycode, const bool press) throw()
  195639. {
  195640. const int keybyte = keycode >> 3;
  195641. const int keybit = (1 << (keycode & 7));
  195642. if (press)
  195643. keyStates [keybyte] |= keybit;
  195644. else
  195645. keyStates [keybyte] &= ~keybit;
  195646. }
  195647. static bool keyDown (const int keycode) throw()
  195648. {
  195649. const int keybyte = keycode >> 3;
  195650. const int keybit = (1 << (keycode & 7));
  195651. return (keyStates [keybyte] & keybit) != 0;
  195652. }
  195653. static const int extendedKeyModifier = 0x10000000;
  195654. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  195655. {
  195656. int keysym;
  195657. if (keyCode & extendedKeyModifier)
  195658. {
  195659. keysym = 0xff00 | (keyCode & 0xff);
  195660. }
  195661. else
  195662. {
  195663. keysym = keyCode;
  195664. if (keysym == (XK_Tab & 0xff)
  195665. || keysym == (XK_Return & 0xff)
  195666. || keysym == (XK_Escape & 0xff)
  195667. || keysym == (XK_BackSpace & 0xff))
  195668. {
  195669. keysym |= 0xff00;
  195670. }
  195671. }
  195672. ScopedXLock xlock;
  195673. return keyDown (XKeysymToKeycode (display, keysym));
  195674. }
  195675. // Alt and Num lock are not defined by standard X
  195676. // modifier constants: check what they're mapped to
  195677. static void getModifierMapping() throw()
  195678. {
  195679. ScopedXLock xlock;
  195680. const int altLeftCode = XKeysymToKeycode (display, XK_Alt_L);
  195681. const int numLockCode = XKeysymToKeycode (display, XK_Num_Lock);
  195682. AltMask = 0;
  195683. NumLockMask = 0;
  195684. XModifierKeymap* mapping = XGetModifierMapping (display);
  195685. if (mapping)
  195686. {
  195687. for (int i = 0; i < 8; i++)
  195688. {
  195689. if (mapping->modifiermap [i << 1] == altLeftCode)
  195690. AltMask = 1 << i;
  195691. else if (mapping->modifiermap [i << 1] == numLockCode)
  195692. NumLockMask = 1 << i;
  195693. }
  195694. XFreeModifiermap (mapping);
  195695. }
  195696. }
  195697. static int currentModifiers = 0;
  195698. void ModifierKeys::updateCurrentModifiers() throw()
  195699. {
  195700. currentModifierFlags = currentModifiers;
  195701. }
  195702. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  195703. {
  195704. int mouseMods;
  195705. getMousePos (mouseMods);
  195706. currentModifiers &= ~ModifierKeys::allMouseButtonModifiers;
  195707. currentModifiers |= mouseMods;
  195708. return ModifierKeys (currentModifiers);
  195709. }
  195710. static void updateKeyModifiers (const int status) throw()
  195711. {
  195712. currentModifiers &= ~(ModifierKeys::shiftModifier
  195713. | ModifierKeys::ctrlModifier
  195714. | ModifierKeys::altModifier);
  195715. if (status & ShiftMask)
  195716. currentModifiers |= ModifierKeys::shiftModifier;
  195717. if (status & ControlMask)
  195718. currentModifiers |= ModifierKeys::ctrlModifier;
  195719. if (status & AltMask)
  195720. currentModifiers |= ModifierKeys::altModifier;
  195721. numLock = ((status & NumLockMask) != 0);
  195722. capsLock = ((status & LockMask) != 0);
  195723. }
  195724. static bool updateKeyModifiersFromSym (KeySym sym, const bool press) throw()
  195725. {
  195726. int modifier = 0;
  195727. bool isModifier = true;
  195728. switch (sym)
  195729. {
  195730. case XK_Shift_L:
  195731. case XK_Shift_R:
  195732. modifier = ModifierKeys::shiftModifier;
  195733. break;
  195734. case XK_Control_L:
  195735. case XK_Control_R:
  195736. modifier = ModifierKeys::ctrlModifier;
  195737. break;
  195738. case XK_Alt_L:
  195739. case XK_Alt_R:
  195740. modifier = ModifierKeys::altModifier;
  195741. break;
  195742. case XK_Num_Lock:
  195743. if (press)
  195744. numLock = ! numLock;
  195745. break;
  195746. case XK_Caps_Lock:
  195747. if (press)
  195748. capsLock = ! capsLock;
  195749. break;
  195750. case XK_Scroll_Lock:
  195751. break;
  195752. default:
  195753. isModifier = false;
  195754. break;
  195755. }
  195756. if (modifier != 0)
  195757. {
  195758. if (press)
  195759. currentModifiers |= modifier;
  195760. else
  195761. currentModifiers &= ~modifier;
  195762. }
  195763. return isModifier;
  195764. }
  195765. #if JUCE_USE_XSHM
  195766. static bool isShmAvailable() throw()
  195767. {
  195768. ScopedXLock xlock;
  195769. static bool isChecked = false;
  195770. static bool isAvailable = false;
  195771. if (! isChecked)
  195772. {
  195773. isChecked = true;
  195774. int major, minor;
  195775. Bool pixmaps;
  195776. if (XShmQueryVersion (display, &major, &minor, &pixmaps))
  195777. {
  195778. trapErrors();
  195779. XShmSegmentInfo segmentInfo;
  195780. zerostruct (segmentInfo);
  195781. XImage* xImage = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  195782. 24, ZPixmap, 0, &segmentInfo, 50, 50);
  195783. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195784. xImage->bytes_per_line * xImage->height,
  195785. IPC_CREAT | 0777)) >= 0)
  195786. {
  195787. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195788. if (segmentInfo.shmaddr != (void*) -1)
  195789. {
  195790. segmentInfo.readOnly = False;
  195791. xImage->data = segmentInfo.shmaddr;
  195792. XSync (display, False);
  195793. if (XShmAttach (display, &segmentInfo) != 0)
  195794. {
  195795. XSync (display, False);
  195796. XShmDetach (display, &segmentInfo);
  195797. isAvailable = true;
  195798. }
  195799. }
  195800. XFlush (display);
  195801. XDestroyImage (xImage);
  195802. shmdt (segmentInfo.shmaddr);
  195803. }
  195804. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195805. isAvailable &= untrapErrors();
  195806. }
  195807. }
  195808. return isAvailable;
  195809. }
  195810. #endif
  195811. class XBitmapImage : public Image
  195812. {
  195813. public:
  195814. XBitmapImage (const PixelFormat format_, const int w, const int h,
  195815. const bool clearImage, const bool is16Bit_)
  195816. : Image (format_, w, h),
  195817. is16Bit (is16Bit_)
  195818. {
  195819. jassert (format_ == RGB || format_ == ARGB);
  195820. pixelStride = (format_ == RGB) ? 3 : 4;
  195821. lineStride = ((w * pixelStride + 3) & ~3);
  195822. ScopedXLock xlock;
  195823. Visual* const visual = DefaultVisual (display, DefaultScreen (display));
  195824. #if JUCE_USE_XSHM
  195825. usingXShm = false;
  195826. if ((! is16Bit) && isShmAvailable())
  195827. {
  195828. zerostruct (segmentInfo);
  195829. xImage = XShmCreateImage (display, visual, 24, ZPixmap, 0, &segmentInfo, w, h);
  195830. if (xImage != 0)
  195831. {
  195832. if ((segmentInfo.shmid = shmget (IPC_PRIVATE,
  195833. xImage->bytes_per_line * xImage->height,
  195834. IPC_CREAT | 0777)) >= 0)
  195835. {
  195836. segmentInfo.shmaddr = (char*) shmat (segmentInfo.shmid, 0, 0);
  195837. if (segmentInfo.shmaddr != (void*) -1)
  195838. {
  195839. segmentInfo.readOnly = False;
  195840. xImage->data = segmentInfo.shmaddr;
  195841. imageData = (uint8*) segmentInfo.shmaddr;
  195842. XSync (display, False);
  195843. if (XShmAttach (display, &segmentInfo) != 0)
  195844. {
  195845. XSync (display, False);
  195846. usingXShm = true;
  195847. }
  195848. else
  195849. {
  195850. jassertfalse
  195851. }
  195852. }
  195853. else
  195854. {
  195855. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195856. }
  195857. }
  195858. }
  195859. }
  195860. if (! usingXShm)
  195861. #endif
  195862. {
  195863. imageDataAllocated.malloc (lineStride * h);
  195864. imageData = imageDataAllocated;
  195865. if (format_ == ARGB && clearImage)
  195866. zeromem (imageData, h * lineStride);
  195867. xImage = (XImage*) juce_calloc (sizeof (XImage));
  195868. xImage->width = w;
  195869. xImage->height = h;
  195870. xImage->xoffset = 0;
  195871. xImage->format = ZPixmap;
  195872. xImage->data = (char*) imageData;
  195873. xImage->byte_order = ImageByteOrder (display);
  195874. xImage->bitmap_unit = BitmapUnit (display);
  195875. xImage->bitmap_bit_order = BitmapBitOrder (display);
  195876. xImage->bitmap_pad = 32;
  195877. xImage->depth = pixelStride * 8;
  195878. xImage->bytes_per_line = lineStride;
  195879. xImage->bits_per_pixel = pixelStride * 8;
  195880. xImage->red_mask = 0x00FF0000;
  195881. xImage->green_mask = 0x0000FF00;
  195882. xImage->blue_mask = 0x000000FF;
  195883. if (is16Bit)
  195884. {
  195885. const int pixelStride = 2;
  195886. const int lineStride = ((w * pixelStride + 3) & ~3);
  195887. imageData16Bit.malloc (lineStride * h);
  195888. xImage->data = imageData16Bit;
  195889. xImage->bitmap_pad = 16;
  195890. xImage->depth = pixelStride * 8;
  195891. xImage->bytes_per_line = lineStride;
  195892. xImage->bits_per_pixel = pixelStride * 8;
  195893. xImage->red_mask = visual->red_mask;
  195894. xImage->green_mask = visual->green_mask;
  195895. xImage->blue_mask = visual->blue_mask;
  195896. }
  195897. if (! XInitImage (xImage))
  195898. {
  195899. jassertfalse
  195900. }
  195901. }
  195902. }
  195903. ~XBitmapImage()
  195904. {
  195905. ScopedXLock xlock;
  195906. #if JUCE_USE_XSHM
  195907. if (usingXShm)
  195908. {
  195909. XShmDetach (display, &segmentInfo);
  195910. XFlush (display);
  195911. XDestroyImage (xImage);
  195912. shmdt (segmentInfo.shmaddr);
  195913. shmctl (segmentInfo.shmid, IPC_RMID, 0);
  195914. }
  195915. else
  195916. #endif
  195917. {
  195918. xImage->data = 0;
  195919. XDestroyImage (xImage);
  195920. }
  195921. }
  195922. void blitToWindow (Window window, int dx, int dy, int dw, int dh, int sx, int sy)
  195923. {
  195924. ScopedXLock xlock;
  195925. static GC gc = 0;
  195926. if (gc == 0)
  195927. gc = DefaultGC (display, DefaultScreen (display));
  195928. if (is16Bit)
  195929. {
  195930. const uint32 rMask = xImage->red_mask;
  195931. const uint32 rShiftL = jmax (0, getShiftNeeded (rMask));
  195932. const uint32 rShiftR = jmax (0, -getShiftNeeded (rMask));
  195933. const uint32 gMask = xImage->green_mask;
  195934. const uint32 gShiftL = jmax (0, getShiftNeeded (gMask));
  195935. const uint32 gShiftR = jmax (0, -getShiftNeeded (gMask));
  195936. const uint32 bMask = xImage->blue_mask;
  195937. const uint32 bShiftL = jmax (0, getShiftNeeded (bMask));
  195938. const uint32 bShiftR = jmax (0, -getShiftNeeded (bMask));
  195939. const Image::BitmapData srcData (*this, 0, 0, getWidth(), getHeight());
  195940. for (int y = sy; y < sy + dh; ++y)
  195941. {
  195942. const uint8* p = srcData.getPixelPointer (sx, y);
  195943. for (int x = sx; x < sx + dw; ++x)
  195944. {
  195945. const PixelRGB* const pixel = (const PixelRGB*) p;
  195946. p += srcData.pixelStride;
  195947. XPutPixel (xImage, x, y,
  195948. (((((uint32) pixel->getRed()) << rShiftL) >> rShiftR) & rMask)
  195949. | (((((uint32) pixel->getGreen()) << gShiftL) >> gShiftR) & gMask)
  195950. | (((((uint32) pixel->getBlue()) << bShiftL) >> bShiftR) & bMask));
  195951. }
  195952. }
  195953. }
  195954. // blit results to screen.
  195955. #if JUCE_USE_XSHM
  195956. if (usingXShm)
  195957. XShmPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh, True);
  195958. else
  195959. #endif
  195960. XPutImage (display, (::Drawable) window, gc, xImage, sx, sy, dx, dy, dw, dh);
  195961. }
  195962. juce_UseDebuggingNewOperator
  195963. private:
  195964. XImage* xImage;
  195965. const bool is16Bit;
  195966. HeapBlock <char> imageData16Bit;
  195967. #if JUCE_USE_XSHM
  195968. XShmSegmentInfo segmentInfo;
  195969. bool usingXShm;
  195970. #endif
  195971. static int getShiftNeeded (const uint32 mask) throw()
  195972. {
  195973. for (int i = 32; --i >= 0;)
  195974. if (((mask >> i) & 1) != 0)
  195975. return i - 7;
  195976. jassertfalse
  195977. return 0;
  195978. }
  195979. };
  195980. #define checkMessageManagerIsLocked jassert (MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  195981. class LinuxComponentPeer : public ComponentPeer
  195982. {
  195983. public:
  195984. LinuxComponentPeer (Component* const component, const int windowStyleFlags)
  195985. : ComponentPeer (component, windowStyleFlags),
  195986. windowH (0),
  195987. parentWindow (0),
  195988. wx (0),
  195989. wy (0),
  195990. ww (0),
  195991. wh (0),
  195992. taskbarImage (0),
  195993. fullScreen (false),
  195994. entered (false),
  195995. mapped (false)
  195996. {
  195997. // it's dangerous to create a window on a thread other than the message thread..
  195998. checkMessageManagerIsLocked
  195999. repainter = new LinuxRepaintManager (this);
  196000. createWindow();
  196001. setTitle (component->getName());
  196002. }
  196003. ~LinuxComponentPeer()
  196004. {
  196005. // it's dangerous to delete a window on a thread other than the message thread..
  196006. checkMessageManagerIsLocked
  196007. deleteTaskBarIcon();
  196008. deleteIconPixmaps();
  196009. destroyWindow();
  196010. windowH = 0;
  196011. }
  196012. void* getNativeHandle() const
  196013. {
  196014. return (void*) windowH;
  196015. }
  196016. static LinuxComponentPeer* getPeerFor (Window windowHandle) throw()
  196017. {
  196018. XPointer peer = 0;
  196019. ScopedXLock xlock;
  196020. if (! XFindContext (display, (XID) windowHandle, improbableNumber, &peer))
  196021. {
  196022. if (peer != 0 && ! ((LinuxComponentPeer*) peer)->isValidMessageListener())
  196023. peer = 0;
  196024. }
  196025. return (LinuxComponentPeer*) peer;
  196026. }
  196027. void setVisible (bool shouldBeVisible)
  196028. {
  196029. ScopedXLock xlock;
  196030. if (shouldBeVisible)
  196031. XMapWindow (display, windowH);
  196032. else
  196033. XUnmapWindow (display, windowH);
  196034. }
  196035. void setTitle (const String& title)
  196036. {
  196037. setWindowTitle (windowH, title);
  196038. }
  196039. void setPosition (int x, int y)
  196040. {
  196041. setBounds (x, y, ww, wh, false);
  196042. }
  196043. void setSize (int w, int h)
  196044. {
  196045. setBounds (wx, wy, w, h, false);
  196046. }
  196047. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  196048. {
  196049. fullScreen = isNowFullScreen;
  196050. if (windowH != 0)
  196051. {
  196052. const ComponentDeletionWatcher deletionChecker (component);
  196053. wx = x;
  196054. wy = y;
  196055. ww = jmax (1, w);
  196056. wh = jmax (1, h);
  196057. ScopedXLock xlock;
  196058. // Make sure the Window manager does what we want
  196059. XSizeHints* hints = XAllocSizeHints();
  196060. hints->flags = USSize | USPosition;
  196061. hints->width = ww;
  196062. hints->height = wh;
  196063. hints->x = wx;
  196064. hints->y = wy;
  196065. if ((getStyleFlags() & (windowHasTitleBar | windowIsResizable)) == windowHasTitleBar)
  196066. {
  196067. hints->min_width = hints->max_width = hints->width;
  196068. hints->min_height = hints->max_height = hints->height;
  196069. hints->flags |= PMinSize | PMaxSize;
  196070. }
  196071. XSetWMNormalHints (display, windowH, hints);
  196072. XFree (hints);
  196073. XMoveResizeWindow (display, windowH,
  196074. wx - windowBorder.getLeft(),
  196075. wy - windowBorder.getTop(), ww, wh);
  196076. if (! deletionChecker.hasBeenDeleted())
  196077. {
  196078. updateBorderSize();
  196079. handleMovedOrResized();
  196080. }
  196081. }
  196082. }
  196083. const Rectangle<int> getBounds() const { return Rectangle<int> (wx, wy, ww, wh); }
  196084. const Point<int> getScreenPosition() const { return Point<int> (wx, wy); }
  196085. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition)
  196086. {
  196087. return relativePosition + getScreenPosition();
  196088. }
  196089. const Point<int> globalPositionToRelative (const Point<int>& screenPosition)
  196090. {
  196091. return screenPosition - getScreenPosition();
  196092. }
  196093. void setMinimised (bool shouldBeMinimised)
  196094. {
  196095. if (shouldBeMinimised)
  196096. {
  196097. Window root = RootWindow (display, DefaultScreen (display));
  196098. XClientMessageEvent clientMsg;
  196099. clientMsg.display = display;
  196100. clientMsg.window = windowH;
  196101. clientMsg.type = ClientMessage;
  196102. clientMsg.format = 32;
  196103. clientMsg.message_type = wm_ChangeState;
  196104. clientMsg.data.l[0] = IconicState;
  196105. ScopedXLock xlock;
  196106. XSendEvent (display, root, false,
  196107. SubstructureRedirectMask | SubstructureNotifyMask,
  196108. (XEvent*) &clientMsg);
  196109. }
  196110. else
  196111. {
  196112. setVisible (true);
  196113. }
  196114. }
  196115. bool isMinimised() const
  196116. {
  196117. bool minimised = false;
  196118. unsigned char* stateProp;
  196119. unsigned long nitems, bytesLeft;
  196120. Atom actualType;
  196121. int actualFormat;
  196122. ScopedXLock xlock;
  196123. if (XGetWindowProperty (display, windowH, wm_State, 0, 64, False,
  196124. wm_State, &actualType, &actualFormat, &nitems, &bytesLeft,
  196125. &stateProp) == Success
  196126. && actualType == wm_State
  196127. && actualFormat == 32
  196128. && nitems > 0)
  196129. {
  196130. if (((unsigned long*) stateProp)[0] == IconicState)
  196131. minimised = true;
  196132. XFree (stateProp);
  196133. }
  196134. return minimised;
  196135. }
  196136. void setFullScreen (const bool shouldBeFullScreen)
  196137. {
  196138. Rectangle<int> r (lastNonFullscreenBounds); // (get a copy of this before de-minimising)
  196139. setMinimised (false);
  196140. if (fullScreen != shouldBeFullScreen)
  196141. {
  196142. if (shouldBeFullScreen)
  196143. r = Desktop::getInstance().getMainMonitorArea();
  196144. if (! r.isEmpty())
  196145. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  196146. getComponent()->repaint();
  196147. }
  196148. }
  196149. bool isFullScreen() const
  196150. {
  196151. return fullScreen;
  196152. }
  196153. bool isChildWindowOf (Window possibleParent) const
  196154. {
  196155. Window* windowList = 0;
  196156. uint32 windowListSize = 0;
  196157. Window parent, root;
  196158. ScopedXLock xlock;
  196159. if (XQueryTree (display, windowH, &root, &parent, &windowList, &windowListSize) != 0)
  196160. {
  196161. if (windowList != 0)
  196162. XFree (windowList);
  196163. return parent == possibleParent;
  196164. }
  196165. return false;
  196166. }
  196167. bool isFrontWindow() const
  196168. {
  196169. Window* windowList = 0;
  196170. uint32 windowListSize = 0;
  196171. bool result = false;
  196172. ScopedXLock xlock;
  196173. Window parent, root = RootWindow (display, DefaultScreen (display));
  196174. if (XQueryTree (display, root, &root, &parent, &windowList, &windowListSize) != 0)
  196175. {
  196176. for (int i = windowListSize; --i >= 0;)
  196177. {
  196178. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (windowList[i]);
  196179. if (peer != 0)
  196180. {
  196181. result = (peer == this);
  196182. break;
  196183. }
  196184. }
  196185. }
  196186. if (windowList != 0)
  196187. XFree (windowList);
  196188. return result;
  196189. }
  196190. bool contains (int x, int y, bool trueIfInAChildWindow) const
  196191. {
  196192. jassert (x >= 0 && y >= 0 && x < ww && y < wh); // should only be called for points that are actually inside the bounds
  196193. if (((unsigned int) x) >= (unsigned int) ww
  196194. || ((unsigned int) y) >= (unsigned int) wh)
  196195. return false;
  196196. bool inFront = false;
  196197. for (int i = 0; i < Desktop::getInstance().getNumComponents(); ++i)
  196198. {
  196199. Component* const c = Desktop::getInstance().getComponent (i);
  196200. if (inFront)
  196201. {
  196202. if (c->contains (x + wx - c->getScreenX(),
  196203. y + wy - c->getScreenY()))
  196204. {
  196205. return false;
  196206. }
  196207. }
  196208. else if (c == getComponent())
  196209. {
  196210. inFront = true;
  196211. }
  196212. }
  196213. if (trueIfInAChildWindow)
  196214. return true;
  196215. ::Window root, child;
  196216. unsigned int bw, depth;
  196217. int wx, wy, w, h;
  196218. ScopedXLock xlock;
  196219. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  196220. &wx, &wy, (unsigned int*) &w, (unsigned int*) &h,
  196221. &bw, &depth))
  196222. {
  196223. return false;
  196224. }
  196225. if (! XTranslateCoordinates (display, windowH, windowH, x, y, &wx, &wy, &child))
  196226. return false;
  196227. return child == None;
  196228. }
  196229. const BorderSize getFrameSize() const
  196230. {
  196231. return BorderSize();
  196232. }
  196233. bool setAlwaysOnTop (bool alwaysOnTop)
  196234. {
  196235. if (windowH != 0)
  196236. {
  196237. const bool wasVisible = component->isVisible();
  196238. if (wasVisible)
  196239. setVisible (false); // doesn't always seem to work if the window is visible when this is done..
  196240. {
  196241. ScopedXLock xlock;
  196242. XSetWindowAttributes swa;
  196243. swa.override_redirect = alwaysOnTop ? True : False;
  196244. XChangeWindowAttributes (display, windowH, CWOverrideRedirect, &swa);
  196245. }
  196246. if (wasVisible)
  196247. setVisible (true);
  196248. }
  196249. return true;
  196250. }
  196251. void toFront (bool makeActive)
  196252. {
  196253. if (makeActive)
  196254. {
  196255. setVisible (true);
  196256. grabFocus();
  196257. }
  196258. XEvent ev;
  196259. ev.xclient.type = ClientMessage;
  196260. ev.xclient.serial = 0;
  196261. ev.xclient.send_event = True;
  196262. ev.xclient.message_type = wm_ActiveWin;
  196263. ev.xclient.window = windowH;
  196264. ev.xclient.format = 32;
  196265. ev.xclient.data.l[0] = 2;
  196266. ev.xclient.data.l[1] = CurrentTime;
  196267. ev.xclient.data.l[2] = 0;
  196268. ev.xclient.data.l[3] = 0;
  196269. ev.xclient.data.l[4] = 0;
  196270. {
  196271. ScopedXLock xlock;
  196272. XSendEvent (display, RootWindow (display, DefaultScreen (display)),
  196273. False,
  196274. SubstructureRedirectMask | SubstructureNotifyMask,
  196275. &ev);
  196276. XWindowAttributes attr;
  196277. XGetWindowAttributes (display, windowH, &attr);
  196278. if (attr.override_redirect)
  196279. XRaiseWindow (display, windowH);
  196280. XSync (display, False);
  196281. }
  196282. handleBroughtToFront();
  196283. }
  196284. void toBehind (ComponentPeer* other)
  196285. {
  196286. LinuxComponentPeer* const otherPeer = dynamic_cast <LinuxComponentPeer*> (other);
  196287. jassert (otherPeer != 0); // wrong type of window?
  196288. if (otherPeer != 0)
  196289. {
  196290. setMinimised (false);
  196291. Window newStack[] = { otherPeer->windowH, windowH };
  196292. ScopedXLock xlock;
  196293. XRestackWindows (display, newStack, 2);
  196294. }
  196295. }
  196296. bool isFocused() const
  196297. {
  196298. int revert;
  196299. Window focusedWindow = 0;
  196300. ScopedXLock xlock;
  196301. XGetInputFocus (display, &focusedWindow, &revert);
  196302. return focusedWindow == windowH;
  196303. }
  196304. void grabFocus()
  196305. {
  196306. XWindowAttributes atts;
  196307. ScopedXLock xlock;
  196308. if (windowH != 0
  196309. && XGetWindowAttributes (display, windowH, &atts)
  196310. && atts.map_state == IsViewable
  196311. && ! isFocused())
  196312. {
  196313. XSetInputFocus (display, windowH, RevertToParent, CurrentTime);
  196314. isActiveApplication = true;
  196315. }
  196316. }
  196317. void textInputRequired (const Point<int>&)
  196318. {
  196319. }
  196320. void repaint (int x, int y, int w, int h)
  196321. {
  196322. if (Rectangle<int>::intersectRectangles (x, y, w, h,
  196323. 0, 0,
  196324. getComponent()->getWidth(),
  196325. getComponent()->getHeight()))
  196326. {
  196327. repainter->repaint (x, y, w, h);
  196328. }
  196329. }
  196330. void performAnyPendingRepaintsNow()
  196331. {
  196332. repainter->performAnyPendingRepaintsNow();
  196333. }
  196334. static Pixmap juce_createColourPixmapFromImage (Display* display, const Image& image)
  196335. {
  196336. ScopedXLock xlock;
  196337. const int width = image.getWidth();
  196338. const int height = image.getHeight();
  196339. HeapBlock <uint32> colour (width * height);
  196340. int index = 0;
  196341. for (int y = 0; y < height; ++y)
  196342. for (int x = 0; x < width; ++x)
  196343. colour[index++] = image.getPixelAt (x, y).getARGB();
  196344. XImage* ximage = XCreateImage (display, CopyFromParent, 24, ZPixmap,
  196345. 0, (char*) colour, width, height, 32, 0);
  196346. Pixmap pixmap = XCreatePixmap (display, DefaultRootWindow (display),
  196347. width, height, 24);
  196348. GC gc = XCreateGC (display, pixmap, 0, 0);
  196349. XPutImage (display, pixmap, gc, ximage, 0, 0, 0, 0, width, height);
  196350. XFreeGC (display, gc);
  196351. return pixmap;
  196352. }
  196353. static Pixmap juce_createMaskPixmapFromImage (Display* display, const Image& image)
  196354. {
  196355. ScopedXLock xlock;
  196356. const int width = image.getWidth();
  196357. const int height = image.getHeight();
  196358. const int stride = (width + 7) >> 3;
  196359. HeapBlock <uint8> mask;
  196360. mask.calloc (stride * height);
  196361. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  196362. for (int y = 0; y < height; ++y)
  196363. {
  196364. for (int x = 0; x < width; ++x)
  196365. {
  196366. const uint8 bit = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  196367. const int offset = y * stride + (x >> 3);
  196368. if (image.getPixelAt (x, y).getAlpha() >= 128)
  196369. mask[offset] |= bit;
  196370. }
  196371. }
  196372. return XCreatePixmapFromBitmapData (display, DefaultRootWindow (display),
  196373. (char*) mask, width, height, 1, 0, 1);
  196374. }
  196375. void setIcon (const Image& newIcon)
  196376. {
  196377. const int dataSize = newIcon.getWidth() * newIcon.getHeight() + 2;
  196378. HeapBlock <unsigned long> data (dataSize);
  196379. int index = 0;
  196380. data[index++] = newIcon.getWidth();
  196381. data[index++] = newIcon.getHeight();
  196382. for (int y = 0; y < newIcon.getHeight(); ++y)
  196383. for (int x = 0; x < newIcon.getWidth(); ++x)
  196384. data[index++] = newIcon.getPixelAt (x, y).getARGB();
  196385. ScopedXLock xlock;
  196386. XChangeProperty (display, windowH,
  196387. XInternAtom (display, "_NET_WM_ICON", False),
  196388. XA_CARDINAL, 32, PropModeReplace,
  196389. (unsigned char*) data, dataSize);
  196390. deleteIconPixmaps();
  196391. XWMHints* wmHints = XGetWMHints (display, windowH);
  196392. if (wmHints == 0)
  196393. wmHints = XAllocWMHints();
  196394. wmHints->flags |= IconPixmapHint | IconMaskHint;
  196395. wmHints->icon_pixmap = juce_createColourPixmapFromImage (display, newIcon);
  196396. wmHints->icon_mask = juce_createMaskPixmapFromImage (display, newIcon);
  196397. XSetWMHints (display, windowH, wmHints);
  196398. XFree (wmHints);
  196399. XSync (display, False);
  196400. }
  196401. void deleteIconPixmaps()
  196402. {
  196403. ScopedXLock xlock;
  196404. XWMHints* wmHints = XGetWMHints (display, windowH);
  196405. if (wmHints != 0)
  196406. {
  196407. if ((wmHints->flags & IconPixmapHint) != 0)
  196408. {
  196409. wmHints->flags &= ~IconPixmapHint;
  196410. XFreePixmap (display, wmHints->icon_pixmap);
  196411. }
  196412. if ((wmHints->flags & IconMaskHint) != 0)
  196413. {
  196414. wmHints->flags &= ~IconMaskHint;
  196415. XFreePixmap (display, wmHints->icon_mask);
  196416. }
  196417. XSetWMHints (display, windowH, wmHints);
  196418. XFree (wmHints);
  196419. }
  196420. }
  196421. void handleWindowMessage (XEvent* event)
  196422. {
  196423. switch (event->xany.type)
  196424. {
  196425. case 2: // 'KeyPress'
  196426. {
  196427. ScopedXLock xlock;
  196428. XKeyEvent* const keyEvent = (XKeyEvent*) &event->xkey;
  196429. updateKeyStates (keyEvent->keycode, true);
  196430. char utf8 [64];
  196431. zeromem (utf8, sizeof (utf8));
  196432. KeySym sym;
  196433. XLookupString (keyEvent, utf8, sizeof (utf8), &sym, 0);
  196434. const juce_wchar unicodeChar = *(const juce_wchar*) String::fromUTF8 (utf8, sizeof (utf8) - 1);
  196435. int keyCode = (int) unicodeChar;
  196436. if (keyCode < 0x20)
  196437. keyCode = XKeycodeToKeysym (display, keyEvent->keycode,
  196438. (currentModifiers & ModifierKeys::shiftModifier) != 0 ? 1 : 0);
  196439. const int oldMods = currentModifiers;
  196440. bool keyPressed = false;
  196441. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, true);
  196442. if ((sym & 0xff00) == 0xff00)
  196443. {
  196444. // Translate keypad
  196445. if (sym == XK_KP_Divide)
  196446. keyCode = XK_slash;
  196447. else if (sym == XK_KP_Multiply)
  196448. keyCode = XK_asterisk;
  196449. else if (sym == XK_KP_Subtract)
  196450. keyCode = XK_hyphen;
  196451. else if (sym == XK_KP_Add)
  196452. keyCode = XK_plus;
  196453. else if (sym == XK_KP_Enter)
  196454. keyCode = XK_Return;
  196455. else if (sym == XK_KP_Decimal)
  196456. keyCode = numLock ? XK_period : XK_Delete;
  196457. else if (sym == XK_KP_0)
  196458. keyCode = numLock ? XK_0 : XK_Insert;
  196459. else if (sym == XK_KP_1)
  196460. keyCode = numLock ? XK_1 : XK_End;
  196461. else if (sym == XK_KP_2)
  196462. keyCode = numLock ? XK_2 : XK_Down;
  196463. else if (sym == XK_KP_3)
  196464. keyCode = numLock ? XK_3 : XK_Page_Down;
  196465. else if (sym == XK_KP_4)
  196466. keyCode = numLock ? XK_4 : XK_Left;
  196467. else if (sym == XK_KP_5)
  196468. keyCode = XK_5;
  196469. else if (sym == XK_KP_6)
  196470. keyCode = numLock ? XK_6 : XK_Right;
  196471. else if (sym == XK_KP_7)
  196472. keyCode = numLock ? XK_7 : XK_Home;
  196473. else if (sym == XK_KP_8)
  196474. keyCode = numLock ? XK_8 : XK_Up;
  196475. else if (sym == XK_KP_9)
  196476. keyCode = numLock ? XK_9 : XK_Page_Up;
  196477. switch (sym)
  196478. {
  196479. case XK_Left:
  196480. case XK_Right:
  196481. case XK_Up:
  196482. case XK_Down:
  196483. case XK_Page_Up:
  196484. case XK_Page_Down:
  196485. case XK_End:
  196486. case XK_Home:
  196487. case XK_Delete:
  196488. case XK_Insert:
  196489. keyPressed = true;
  196490. keyCode = (sym & 0xff) | extendedKeyModifier;
  196491. break;
  196492. case XK_Tab:
  196493. case XK_Return:
  196494. case XK_Escape:
  196495. case XK_BackSpace:
  196496. keyPressed = true;
  196497. keyCode &= 0xff;
  196498. break;
  196499. default:
  196500. {
  196501. if (sym >= XK_F1 && sym <= XK_F16)
  196502. {
  196503. keyPressed = true;
  196504. keyCode = (sym & 0xff) | extendedKeyModifier;
  196505. }
  196506. break;
  196507. }
  196508. }
  196509. }
  196510. if (utf8[0] != 0 || ((sym & 0xff00) == 0 && sym >= 8))
  196511. keyPressed = true;
  196512. if (oldMods != currentModifiers)
  196513. handleModifierKeysChange();
  196514. if (keyDownChange)
  196515. handleKeyUpOrDown (true);
  196516. if (keyPressed)
  196517. handleKeyPress (keyCode, unicodeChar);
  196518. break;
  196519. }
  196520. case KeyRelease:
  196521. {
  196522. const XKeyEvent* const keyEvent = (const XKeyEvent*) &event->xkey;
  196523. updateKeyStates (keyEvent->keycode, false);
  196524. ScopedXLock xlock;
  196525. KeySym sym = XKeycodeToKeysym (display, keyEvent->keycode, 0);
  196526. const int oldMods = currentModifiers;
  196527. const bool keyDownChange = (sym != NoSymbol) && ! updateKeyModifiersFromSym (sym, false);
  196528. if (oldMods != currentModifiers)
  196529. handleModifierKeysChange();
  196530. if (keyDownChange)
  196531. handleKeyUpOrDown (false);
  196532. break;
  196533. }
  196534. case ButtonPress:
  196535. {
  196536. const XButtonPressedEvent* const buttonPressEvent = (const XButtonPressedEvent*) &event->xbutton;
  196537. bool buttonMsg = false;
  196538. bool wheelUpMsg = false;
  196539. bool wheelDownMsg = false;
  196540. const int map = pointerMap [buttonPressEvent->button - Button1];
  196541. if (map == LeftButton)
  196542. {
  196543. currentModifiers |= ModifierKeys::leftButtonModifier;
  196544. buttonMsg = true;
  196545. }
  196546. else if (map == RightButton)
  196547. {
  196548. currentModifiers |= ModifierKeys::rightButtonModifier;
  196549. buttonMsg = true;
  196550. }
  196551. else if (map == MiddleButton)
  196552. {
  196553. currentModifiers |= ModifierKeys::middleButtonModifier;
  196554. buttonMsg = true;
  196555. }
  196556. else if (map == WheelUp)
  196557. {
  196558. wheelUpMsg = true;
  196559. }
  196560. else if (map == WheelDown)
  196561. {
  196562. wheelDownMsg = true;
  196563. }
  196564. updateKeyModifiers (buttonPressEvent->state);
  196565. if (buttonMsg)
  196566. {
  196567. toFront (true);
  196568. handleMouseDown (Point<int> (buttonPressEvent->x, buttonPressEvent->y),
  196569. getEventTime (buttonPressEvent->time));
  196570. }
  196571. else if (wheelUpMsg || wheelDownMsg)
  196572. {
  196573. handleMouseWheel (0, wheelDownMsg ? -84 : 84,
  196574. getEventTime (buttonPressEvent->time));
  196575. }
  196576. clearLastMousePos();
  196577. break;
  196578. }
  196579. case ButtonRelease:
  196580. {
  196581. const XButtonReleasedEvent* const buttonRelEvent = (const XButtonReleasedEvent*) &event->xbutton;
  196582. const int oldModifiers = currentModifiers;
  196583. const int map = pointerMap [buttonRelEvent->button - Button1];
  196584. if (map == LeftButton)
  196585. currentModifiers &= ~ModifierKeys::leftButtonModifier;
  196586. else if (map == RightButton)
  196587. currentModifiers &= ~ModifierKeys::rightButtonModifier;
  196588. else if (map == MiddleButton)
  196589. currentModifiers &= ~ModifierKeys::middleButtonModifier;
  196590. updateKeyModifiers (buttonRelEvent->state);
  196591. handleMouseUp (oldModifiers,
  196592. Point<int> (buttonRelEvent->x, buttonRelEvent->y),
  196593. getEventTime (buttonRelEvent->time));
  196594. clearLastMousePos();
  196595. break;
  196596. }
  196597. case MotionNotify:
  196598. {
  196599. const XPointerMovedEvent* const movedEvent = (const XPointerMovedEvent*) &event->xmotion;
  196600. updateKeyModifiers (movedEvent->state);
  196601. Point<int> mousePos (Desktop::getMousePosition());
  196602. if (lastMousePos != mousePos)
  196603. {
  196604. lastMousePos = mousePos;
  196605. if (parentWindow != 0 && (styleFlags & windowHasTitleBar) == 0)
  196606. {
  196607. Window wRoot = 0, wParent = 0;
  196608. Window* wChild = 0;
  196609. unsigned int numChildren;
  196610. {
  196611. ScopedXLock xlock;
  196612. XQueryTree (display, windowH, &wRoot, &wParent, &wChild, &numChildren);
  196613. }
  196614. if (wParent != 0
  196615. && wParent != windowH
  196616. && wParent != wRoot)
  196617. {
  196618. parentWindow = wParent;
  196619. updateBounds();
  196620. mousePos -= getScreenPosition();
  196621. }
  196622. else
  196623. {
  196624. parentWindow = 0;
  196625. mousePos -= getScreenPosition();
  196626. }
  196627. }
  196628. else
  196629. {
  196630. mousePos -= getScreenPosition();
  196631. }
  196632. if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0)
  196633. handleMouseMove (mousePos, getEventTime (movedEvent->time));
  196634. else
  196635. handleMouseDrag (mousePos, getEventTime (movedEvent->time));
  196636. }
  196637. break;
  196638. }
  196639. case EnterNotify:
  196640. {
  196641. clearLastMousePos();
  196642. const XEnterWindowEvent* const enterEvent = (const XEnterWindowEvent*) &event->xcrossing;
  196643. if ((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0
  196644. && ! entered)
  196645. {
  196646. updateKeyModifiers (enterEvent->state);
  196647. handleMouseEnter (Point<int> (enterEvent->x, enterEvent->y), getEventTime (enterEvent->time));
  196648. entered = true;
  196649. }
  196650. break;
  196651. }
  196652. case LeaveNotify:
  196653. {
  196654. const XLeaveWindowEvent* const leaveEvent = (const XLeaveWindowEvent*) &event->xcrossing;
  196655. // Suppress the normal leave if we've got a pointer grab, or if
  196656. // it's a bogus one caused by clicking a mouse button when running
  196657. // in a Window manager
  196658. if (((currentModifiers & ModifierKeys::allMouseButtonModifiers) == 0
  196659. && leaveEvent->mode == NotifyNormal)
  196660. || leaveEvent->mode == NotifyUngrab)
  196661. {
  196662. updateKeyModifiers (leaveEvent->state);
  196663. handleMouseExit (Point<int> (leaveEvent->x, leaveEvent->y), getEventTime (leaveEvent->time));
  196664. entered = false;
  196665. }
  196666. break;
  196667. }
  196668. case FocusIn:
  196669. {
  196670. isActiveApplication = true;
  196671. if (isFocused())
  196672. handleFocusGain();
  196673. break;
  196674. }
  196675. case FocusOut:
  196676. {
  196677. isActiveApplication = false;
  196678. if (! isFocused())
  196679. handleFocusLoss();
  196680. break;
  196681. }
  196682. case Expose:
  196683. {
  196684. // Batch together all pending expose events
  196685. XExposeEvent* exposeEvent = (XExposeEvent*) &event->xexpose;
  196686. XEvent nextEvent;
  196687. ScopedXLock xlock;
  196688. if (exposeEvent->window != windowH)
  196689. {
  196690. Window child;
  196691. XTranslateCoordinates (display, exposeEvent->window, windowH,
  196692. exposeEvent->x, exposeEvent->y, &exposeEvent->x, &exposeEvent->y,
  196693. &child);
  196694. }
  196695. repaint (exposeEvent->x, exposeEvent->y,
  196696. exposeEvent->width, exposeEvent->height);
  196697. while (XEventsQueued (display, QueuedAfterFlush) > 0)
  196698. {
  196699. XPeekEvent (display, (XEvent*) &nextEvent);
  196700. if (nextEvent.type != Expose || nextEvent.xany.window != event->xany.window)
  196701. break;
  196702. XNextEvent (display, (XEvent*) &nextEvent);
  196703. XExposeEvent* nextExposeEvent = (XExposeEvent*) &nextEvent.xexpose;
  196704. repaint (nextExposeEvent->x, nextExposeEvent->y,
  196705. nextExposeEvent->width, nextExposeEvent->height);
  196706. }
  196707. break;
  196708. }
  196709. case CirculateNotify:
  196710. case CreateNotify:
  196711. case DestroyNotify:
  196712. // Think we can ignore these
  196713. break;
  196714. case ConfigureNotify:
  196715. {
  196716. updateBounds();
  196717. updateBorderSize();
  196718. handleMovedOrResized();
  196719. // if the native title bar is dragged, need to tell any active menus, etc.
  196720. if ((styleFlags & windowHasTitleBar) != 0
  196721. && component->isCurrentlyBlockedByAnotherModalComponent())
  196722. {
  196723. Component* const currentModalComp = Component::getCurrentlyModalComponent();
  196724. if (currentModalComp != 0)
  196725. currentModalComp->inputAttemptWhenModal();
  196726. }
  196727. XConfigureEvent* const confEvent = (XConfigureEvent*) &event->xconfigure;
  196728. if (confEvent->window == windowH
  196729. && confEvent->above != 0
  196730. && isFrontWindow())
  196731. {
  196732. handleBroughtToFront();
  196733. }
  196734. break;
  196735. }
  196736. case ReparentNotify:
  196737. case GravityNotify:
  196738. {
  196739. parentWindow = 0;
  196740. Window wRoot = 0;
  196741. Window* wChild = 0;
  196742. unsigned int numChildren;
  196743. {
  196744. ScopedXLock xlock;
  196745. XQueryTree (display, windowH, &wRoot, &parentWindow, &wChild, &numChildren);
  196746. }
  196747. if (parentWindow == windowH || parentWindow == wRoot)
  196748. parentWindow = 0;
  196749. updateBounds();
  196750. updateBorderSize();
  196751. handleMovedOrResized();
  196752. break;
  196753. }
  196754. case MapNotify:
  196755. mapped = true;
  196756. handleBroughtToFront();
  196757. break;
  196758. case UnmapNotify:
  196759. mapped = false;
  196760. break;
  196761. case MappingNotify:
  196762. {
  196763. XMappingEvent* mappingEvent = (XMappingEvent*) &event->xmapping;
  196764. if (mappingEvent->request != MappingPointer)
  196765. {
  196766. // Deal with modifier/keyboard mapping
  196767. ScopedXLock xlock;
  196768. XRefreshKeyboardMapping (mappingEvent);
  196769. getModifierMapping();
  196770. }
  196771. break;
  196772. }
  196773. case ClientMessage:
  196774. {
  196775. const XClientMessageEvent* const clientMsg = (const XClientMessageEvent*) &event->xclient;
  196776. if (clientMsg->message_type == wm_Protocols && clientMsg->format == 32)
  196777. {
  196778. const Atom atom = (Atom) clientMsg->data.l[0];
  196779. if (atom == wm_ProtocolList [TAKE_FOCUS])
  196780. {
  196781. XWindowAttributes atts;
  196782. ScopedXLock xlock;
  196783. if (clientMsg->window != 0
  196784. && XGetWindowAttributes (display, clientMsg->window, &atts))
  196785. {
  196786. if (atts.map_state == IsViewable)
  196787. XSetInputFocus (display, clientMsg->window, RevertToParent, clientMsg->data.l[1]);
  196788. }
  196789. }
  196790. else if (atom == wm_ProtocolList [DELETE_WINDOW])
  196791. {
  196792. handleUserClosingWindow();
  196793. }
  196794. }
  196795. else if (clientMsg->message_type == XA_XdndEnter)
  196796. {
  196797. handleDragAndDropEnter (clientMsg);
  196798. }
  196799. else if (clientMsg->message_type == XA_XdndLeave)
  196800. {
  196801. resetDragAndDrop();
  196802. }
  196803. else if (clientMsg->message_type == XA_XdndPosition)
  196804. {
  196805. handleDragAndDropPosition (clientMsg);
  196806. }
  196807. else if (clientMsg->message_type == XA_XdndDrop)
  196808. {
  196809. handleDragAndDropDrop (clientMsg);
  196810. }
  196811. else if (clientMsg->message_type == XA_XdndStatus)
  196812. {
  196813. handleDragAndDropStatus (clientMsg);
  196814. }
  196815. else if (clientMsg->message_type == XA_XdndFinished)
  196816. {
  196817. resetDragAndDrop();
  196818. }
  196819. break;
  196820. }
  196821. case SelectionNotify:
  196822. handleDragAndDropSelection (event);
  196823. break;
  196824. case SelectionClear:
  196825. case SelectionRequest:
  196826. break;
  196827. default:
  196828. #if JUCE_USE_XSHM
  196829. {
  196830. ScopedXLock xlock;
  196831. if (event->xany.type == XShmGetEventBase (display))
  196832. repainter->notifyPaintCompleted();
  196833. }
  196834. #endif
  196835. break;
  196836. }
  196837. }
  196838. void showMouseCursor (Cursor cursor) throw()
  196839. {
  196840. ScopedXLock xlock;
  196841. XDefineCursor (display, windowH, cursor);
  196842. }
  196843. void setTaskBarIcon (const Image& image)
  196844. {
  196845. ScopedXLock xlock;
  196846. deleteTaskBarIcon();
  196847. taskbarImage = image.createCopy();
  196848. Screen* const screen = XDefaultScreenOfDisplay (display);
  196849. const int screenNumber = XScreenNumberOfScreen (screen);
  196850. String screenAtom ("_NET_SYSTEM_TRAY_S");
  196851. screenAtom << screenNumber;
  196852. Atom selectionAtom = XInternAtom (display, screenAtom.toUTF8(), false);
  196853. XGrabServer (display);
  196854. Window managerWin = XGetSelectionOwner (display, selectionAtom);
  196855. if (managerWin != None)
  196856. XSelectInput (display, managerWin, StructureNotifyMask);
  196857. XUngrabServer (display);
  196858. XFlush (display);
  196859. if (managerWin != None)
  196860. {
  196861. XEvent ev;
  196862. zerostruct (ev);
  196863. ev.xclient.type = ClientMessage;
  196864. ev.xclient.window = managerWin;
  196865. ev.xclient.message_type = XInternAtom (display, "_NET_SYSTEM_TRAY_OPCODE", False);
  196866. ev.xclient.format = 32;
  196867. ev.xclient.data.l[0] = CurrentTime;
  196868. ev.xclient.data.l[1] = SYSTEM_TRAY_REQUEST_DOCK;
  196869. ev.xclient.data.l[2] = windowH;
  196870. ev.xclient.data.l[3] = 0;
  196871. ev.xclient.data.l[4] = 0;
  196872. XSendEvent (display, managerWin, False, NoEventMask, &ev);
  196873. XSync (display, False);
  196874. }
  196875. // For older KDE's ...
  196876. long atomData = 1;
  196877. Atom trayAtom = XInternAtom (display, "KWM_DOCKWINDOW", false);
  196878. XChangeProperty (display, windowH, trayAtom, trayAtom, 32, PropModeReplace, (unsigned char*) &atomData, 1);
  196879. // For more recent KDE's...
  196880. trayAtom = XInternAtom (display, "_KDE_NET_WM_SYSTEM_TRAY_WINDOW_FOR", false);
  196881. XChangeProperty (display, windowH, trayAtom, XA_WINDOW, 32, PropModeReplace, (unsigned char*) &windowH, 1);
  196882. // a minimum size must be specified for GNOME and Xfce, otherwise the icon is displayed with a width of 1
  196883. XSizeHints* hints = XAllocSizeHints();
  196884. hints->flags = PMinSize;
  196885. hints->min_width = 22;
  196886. hints->min_height = 22;
  196887. XSetWMNormalHints (display, windowH, hints);
  196888. XFree (hints);
  196889. }
  196890. void deleteTaskBarIcon()
  196891. {
  196892. deleteAndZero (taskbarImage);
  196893. }
  196894. const Image* getTaskbarIcon() const throw() { return taskbarImage; }
  196895. juce_UseDebuggingNewOperator
  196896. bool dontRepaint;
  196897. private:
  196898. class LinuxRepaintManager : public Timer
  196899. {
  196900. public:
  196901. LinuxRepaintManager (LinuxComponentPeer* const peer_)
  196902. : peer (peer_),
  196903. lastTimeImageUsed (0)
  196904. {
  196905. #if JUCE_USE_XSHM
  196906. shmCompletedDrawing = true;
  196907. useARGBImagesForRendering = isShmAvailable();
  196908. if (useARGBImagesForRendering)
  196909. {
  196910. ScopedXLock xlock;
  196911. XShmSegmentInfo segmentinfo;
  196912. XImage* const testImage
  196913. = XShmCreateImage (display, DefaultVisual (display, DefaultScreen (display)),
  196914. 24, ZPixmap, 0, &segmentinfo, 64, 64);
  196915. useARGBImagesForRendering = (testImage->bits_per_pixel == 32);
  196916. XDestroyImage (testImage);
  196917. }
  196918. #endif
  196919. }
  196920. ~LinuxRepaintManager()
  196921. {
  196922. }
  196923. void timerCallback()
  196924. {
  196925. #if JUCE_USE_XSHM
  196926. if (! shmCompletedDrawing)
  196927. return;
  196928. #endif
  196929. if (! regionsNeedingRepaint.isEmpty())
  196930. {
  196931. stopTimer();
  196932. performAnyPendingRepaintsNow();
  196933. }
  196934. else if (Time::getApproximateMillisecondCounter() > lastTimeImageUsed + 3000)
  196935. {
  196936. stopTimer();
  196937. image = 0;
  196938. }
  196939. }
  196940. void repaint (int x, int y, int w, int h)
  196941. {
  196942. if (! isTimerRunning())
  196943. startTimer (repaintTimerPeriod);
  196944. regionsNeedingRepaint.add (x, y, w, h);
  196945. }
  196946. void performAnyPendingRepaintsNow()
  196947. {
  196948. #if JUCE_USE_XSHM
  196949. if (! shmCompletedDrawing)
  196950. {
  196951. startTimer (repaintTimerPeriod);
  196952. return;
  196953. }
  196954. #endif
  196955. peer->clearMaskedRegion();
  196956. RectangleList originalRepaintRegion (regionsNeedingRepaint);
  196957. regionsNeedingRepaint.clear();
  196958. const Rectangle<int> totalArea (originalRepaintRegion.getBounds());
  196959. if (! totalArea.isEmpty())
  196960. {
  196961. if (image == 0 || image->getWidth() < totalArea.getWidth()
  196962. || image->getHeight() < totalArea.getHeight())
  196963. {
  196964. #if JUCE_USE_XSHM
  196965. image = new XBitmapImage (useARGBImagesForRendering ? Image::ARGB
  196966. : Image::RGB,
  196967. #else
  196968. image = new XBitmapImage (Image::RGB,
  196969. #endif
  196970. (totalArea.getWidth() + 31) & ~31,
  196971. (totalArea.getHeight() + 31) & ~31,
  196972. false,
  196973. peer->depthIs16Bit);
  196974. }
  196975. startTimer (repaintTimerPeriod);
  196976. LowLevelGraphicsSoftwareRenderer context (*image);
  196977. context.setOrigin (-totalArea.getX(), -totalArea.getY());
  196978. if (context.clipToRectangleList (originalRepaintRegion))
  196979. peer->handlePaint (context);
  196980. if (! peer->maskedRegion.isEmpty())
  196981. originalRepaintRegion.subtract (peer->maskedRegion);
  196982. for (RectangleList::Iterator i (originalRepaintRegion); i.next();)
  196983. {
  196984. #if JUCE_USE_XSHM
  196985. shmCompletedDrawing = false;
  196986. #endif
  196987. const Rectangle<int>& r = *i.getRectangle();
  196988. image->blitToWindow (peer->windowH,
  196989. r.getX(), r.getY(), r.getWidth(), r.getHeight(),
  196990. r.getX() - totalArea.getX(), r.getY() - totalArea.getY());
  196991. }
  196992. }
  196993. lastTimeImageUsed = Time::getApproximateMillisecondCounter();
  196994. startTimer (repaintTimerPeriod);
  196995. }
  196996. #if JUCE_USE_XSHM
  196997. void notifyPaintCompleted() { shmCompletedDrawing = true; }
  196998. #endif
  196999. private:
  197000. LinuxComponentPeer* const peer;
  197001. ScopedPointer <XBitmapImage> image;
  197002. uint32 lastTimeImageUsed;
  197003. RectangleList regionsNeedingRepaint;
  197004. #if JUCE_USE_XSHM
  197005. bool useARGBImagesForRendering, shmCompletedDrawing;
  197006. #endif
  197007. LinuxRepaintManager (const LinuxRepaintManager&);
  197008. LinuxRepaintManager& operator= (const LinuxRepaintManager&);
  197009. };
  197010. ScopedPointer <LinuxRepaintManager> repainter;
  197011. friend class LinuxRepaintManager;
  197012. Window windowH, parentWindow;
  197013. int wx, wy, ww, wh;
  197014. Image* taskbarImage;
  197015. bool fullScreen, entered, mapped, depthIs16Bit;
  197016. BorderSize windowBorder;
  197017. struct MotifWmHints
  197018. {
  197019. unsigned long flags;
  197020. unsigned long functions;
  197021. unsigned long decorations;
  197022. long input_mode;
  197023. unsigned long status;
  197024. };
  197025. void removeWindowDecorations (Window wndH)
  197026. {
  197027. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  197028. if (hints != None)
  197029. {
  197030. MotifWmHints motifHints;
  197031. zerostruct (motifHints);
  197032. motifHints.flags = 2; /* MWM_HINTS_DECORATIONS */
  197033. motifHints.decorations = 0;
  197034. ScopedXLock xlock;
  197035. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197036. (unsigned char*) &motifHints, 4);
  197037. }
  197038. hints = XInternAtom (display, "_WIN_HINTS", True);
  197039. if (hints != None)
  197040. {
  197041. long gnomeHints = 0;
  197042. ScopedXLock xlock;
  197043. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197044. (unsigned char*) &gnomeHints, 1);
  197045. }
  197046. hints = XInternAtom (display, "KWM_WIN_DECORATION", True);
  197047. if (hints != None)
  197048. {
  197049. long kwmHints = 2; /*KDE_tinyDecoration*/
  197050. ScopedXLock xlock;
  197051. XChangeProperty (display, wndH, hints, hints, 32, PropModeReplace,
  197052. (unsigned char*) &kwmHints, 1);
  197053. }
  197054. hints = XInternAtom (display, "_NET_WM_WINDOW_TYPE", True);
  197055. if (hints != None)
  197056. {
  197057. ScopedXLock xlock;
  197058. int netHints [2];
  197059. int numHints = 0;
  197060. if ((styleFlags & windowIsTemporary) != 0)
  197061. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_MENU", True);
  197062. else
  197063. netHints [numHints] = XInternAtom (display, "_NET_WM_WINDOW_TYPE_NORMAL", True);
  197064. if (netHints [numHints] != 0)
  197065. ++numHints;
  197066. netHints[numHints] = XInternAtom (display, "_KDE_NET_WM_WINDOW_TYPE_OVERRIDE", True);
  197067. if (netHints [numHints] != 0)
  197068. ++numHints;
  197069. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  197070. (unsigned char*) &netHints, numHints);
  197071. }
  197072. }
  197073. void addWindowButtons (Window wndH)
  197074. {
  197075. ScopedXLock xlock;
  197076. Atom hints = XInternAtom (display, "_MOTIF_WM_HINTS", True);
  197077. if (hints != None)
  197078. {
  197079. MotifWmHints motifHints;
  197080. zerostruct (motifHints);
  197081. motifHints.flags = 1 | 2; /* MWM_HINTS_FUNCTIONS | MWM_HINTS_DECORATIONS */
  197082. motifHints.decorations = 2 /* MWM_DECOR_BORDER */ | 8 /* MWM_DECOR_TITLE */ | 16; /* MWM_DECOR_MENU */
  197083. motifHints.functions = 4 /* MWM_FUNC_MOVE */;
  197084. if ((styleFlags & windowHasCloseButton) != 0)
  197085. motifHints.functions |= 32; /* MWM_FUNC_CLOSE */
  197086. if ((styleFlags & windowHasMinimiseButton) != 0)
  197087. {
  197088. motifHints.functions |= 8; /* MWM_FUNC_MINIMIZE */
  197089. motifHints.decorations |= 0x20; /* MWM_DECOR_MINIMIZE */
  197090. }
  197091. if ((styleFlags & windowHasMaximiseButton) != 0)
  197092. {
  197093. motifHints.functions |= 0x10; /* MWM_FUNC_MAXIMIZE */
  197094. motifHints.decorations |= 0x40; /* MWM_DECOR_MAXIMIZE */
  197095. }
  197096. if ((styleFlags & windowIsResizable) != 0)
  197097. {
  197098. motifHints.functions |= 2; /* MWM_FUNC_RESIZE */
  197099. motifHints.decorations |= 0x4; /* MWM_DECOR_RESIZEH */
  197100. }
  197101. XChangeProperty (display, wndH, hints, hints, 32, 0, (unsigned char*) &motifHints, 5);
  197102. }
  197103. hints = XInternAtom (display, "_NET_WM_ALLOWED_ACTIONS", True);
  197104. if (hints != None)
  197105. {
  197106. int netHints [6];
  197107. int num = 0;
  197108. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_RESIZE", (styleFlags & windowIsResizable) ? True : False);
  197109. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_FULLSCREEN", (styleFlags & windowHasMaximiseButton) ? True : False);
  197110. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_MINIMIZE", (styleFlags & windowHasMinimiseButton) ? True : False);
  197111. netHints [num++] = XInternAtom (display, "_NET_WM_ACTION_CLOSE", (styleFlags & windowHasCloseButton) ? True : False);
  197112. XChangeProperty (display, wndH, hints, XA_ATOM, 32, PropModeReplace,
  197113. (unsigned char*) &netHints, num);
  197114. }
  197115. }
  197116. void createWindow()
  197117. {
  197118. ScopedXLock xlock;
  197119. static bool atomsInitialised = false;
  197120. if (! atomsInitialised)
  197121. {
  197122. atomsInitialised = true;
  197123. wm_Protocols = XInternAtom (display, "WM_PROTOCOLS", 1);
  197124. wm_ProtocolList [TAKE_FOCUS] = XInternAtom (display, "WM_TAKE_FOCUS", 1);
  197125. wm_ProtocolList [DELETE_WINDOW] = XInternAtom (display, "WM_DELETE_WINDOW", 1);
  197126. wm_ChangeState = XInternAtom (display, "WM_CHANGE_STATE", 1);
  197127. wm_State = XInternAtom (display, "WM_STATE", 1);
  197128. wm_ActiveWin = XInternAtom (display, "_NET_ACTIVE_WINDOW", False);
  197129. XA_XdndAware = XInternAtom (display, "XdndAware", 0);
  197130. XA_XdndEnter = XInternAtom (display, "XdndEnter", 0);
  197131. XA_XdndLeave = XInternAtom (display, "XdndLeave", 0);
  197132. XA_XdndPosition = XInternAtom (display, "XdndPosition", 0);
  197133. XA_XdndStatus = XInternAtom (display, "XdndStatus", 0);
  197134. XA_XdndDrop = XInternAtom (display, "XdndDrop", 0);
  197135. XA_XdndFinished = XInternAtom (display, "XdndFinished", 0);
  197136. XA_XdndSelection = XInternAtom (display, "XdndSelection", 0);
  197137. XA_XdndProxy = XInternAtom (display, "XdndProxy", 0);
  197138. XA_XdndTypeList = XInternAtom (display, "XdndTypeList", 0);
  197139. XA_XdndActionList = XInternAtom (display, "XdndActionList", 0);
  197140. XA_XdndActionCopy = XInternAtom (display, "XdndActionCopy", 0);
  197141. XA_XdndActionMove = XInternAtom (display, "XdndActionMove", 0);
  197142. XA_XdndActionLink = XInternAtom (display, "XdndActionLink", 0);
  197143. XA_XdndActionAsk = XInternAtom (display, "XdndActionAsk", 0);
  197144. XA_XdndActionPrivate = XInternAtom (display, "XdndActionPrivate", 0);
  197145. XA_XdndActionDescription = XInternAtom (display, "XdndActionDescription", 0);
  197146. XA_JXSelectionWindowProperty = XInternAtom (display, "JXSelectionWindowProperty", 0);
  197147. XA_MimeTextPlain = XInternAtom (display, "text/plain", 0);
  197148. XA_MimeTextUriList = XInternAtom (display, "text/uri-list", 0);
  197149. XA_MimeRootDrop = XInternAtom (display, "application/x-rootwindow-drop", 0);
  197150. }
  197151. resetDragAndDrop();
  197152. XA_OtherMime = XA_MimeTextPlain; // xxx why??
  197153. allowedMimeTypeAtoms [0] = XA_MimeTextPlain;
  197154. allowedMimeTypeAtoms [1] = XA_OtherMime;
  197155. allowedMimeTypeAtoms [2] = XA_MimeTextUriList;
  197156. allowedActions [0] = XA_XdndActionMove;
  197157. allowedActions [1] = XA_XdndActionCopy;
  197158. allowedActions [2] = XA_XdndActionLink;
  197159. allowedActions [3] = XA_XdndActionAsk;
  197160. allowedActions [4] = XA_XdndActionPrivate;
  197161. // Get defaults for various properties
  197162. const int screen = DefaultScreen (display);
  197163. Window root = RootWindow (display, screen);
  197164. // Attempt to create a 24-bit window on the default screen. If this is not
  197165. // possible then exit
  197166. XVisualInfo desiredVisual;
  197167. desiredVisual.screen = screen;
  197168. desiredVisual.depth = 24;
  197169. depthIs16Bit = false;
  197170. int numVisuals;
  197171. XVisualInfo* visuals = XGetVisualInfo (display, VisualScreenMask | VisualDepthMask,
  197172. &desiredVisual, &numVisuals);
  197173. if (numVisuals < 1 || visuals == 0)
  197174. {
  197175. XFree (visuals);
  197176. desiredVisual.depth = 16;
  197177. visuals = XGetVisualInfo (display, VisualScreenMask | VisualDepthMask,
  197178. &desiredVisual, &numVisuals);
  197179. if (numVisuals < 1 || visuals == 0)
  197180. {
  197181. Logger::outputDebugString ("ERROR: System doesn't support 24 or 16 bit RGB display.\n");
  197182. Process::terminate();
  197183. }
  197184. depthIs16Bit = true;
  197185. }
  197186. XFree (visuals);
  197187. // Set up the window attributes
  197188. XSetWindowAttributes swa;
  197189. swa.border_pixel = 0;
  197190. swa.background_pixmap = None;
  197191. swa.colormap = DefaultColormap (display, screen);
  197192. swa.override_redirect = getComponent()->isAlwaysOnTop() ? True : False;
  197193. swa.event_mask = eventMask;
  197194. Window wndH = XCreateWindow (display, root,
  197195. 0, 0, 1, 1,
  197196. 0, 0, InputOutput, (Visual*) CopyFromParent,
  197197. CWBorderPixel | CWColormap | CWBackPixmap | CWEventMask | CWOverrideRedirect,
  197198. &swa);
  197199. XGrabButton (display, AnyButton, AnyModifier, wndH, False,
  197200. ButtonPressMask | ButtonReleaseMask | EnterWindowMask | LeaveWindowMask | PointerMotionMask,
  197201. GrabModeAsync, GrabModeAsync, None, None);
  197202. // Set the window context to identify the window handle object
  197203. if (XSaveContext (display, (XID) wndH, improbableNumber, (XPointer) this))
  197204. {
  197205. // Failed
  197206. jassertfalse
  197207. Logger::outputDebugString ("Failed to create context information for window.\n");
  197208. XDestroyWindow (display, wndH);
  197209. wndH = 0;
  197210. }
  197211. // Set window manager hints
  197212. XWMHints* wmHints = XAllocWMHints();
  197213. wmHints->flags = InputHint | StateHint;
  197214. wmHints->input = True; // Locally active input model
  197215. wmHints->initial_state = NormalState;
  197216. XSetWMHints (display, wndH, wmHints);
  197217. XFree (wmHints);
  197218. if ((styleFlags & windowIsSemiTransparent) != 0)
  197219. {
  197220. //xxx
  197221. }
  197222. if ((styleFlags & windowAppearsOnTaskbar) != 0)
  197223. {
  197224. //xxx
  197225. }
  197226. //XSetTransientForHint (display, wndH, RootWindow (display, DefaultScreen (display)));
  197227. if ((styleFlags & windowHasTitleBar) == 0)
  197228. removeWindowDecorations (wndH);
  197229. else
  197230. addWindowButtons (wndH);
  197231. // Set window manager protocols
  197232. XChangeProperty (display, wndH, wm_Protocols, XA_ATOM, 32, PropModeReplace,
  197233. (unsigned char*) wm_ProtocolList, 2);
  197234. // Set drag and drop flags
  197235. XChangeProperty (display, wndH, XA_XdndTypeList, XA_ATOM, 32, PropModeReplace,
  197236. (const unsigned char*) allowedMimeTypeAtoms, numElementsInArray (allowedMimeTypeAtoms));
  197237. XChangeProperty (display, wndH, XA_XdndActionList, XA_ATOM, 32, PropModeReplace,
  197238. (const unsigned char*) allowedActions, numElementsInArray (allowedActions));
  197239. XChangeProperty (display, wndH, XA_XdndActionDescription, XA_STRING, 8, PropModeReplace,
  197240. (const unsigned char*) "", 0);
  197241. unsigned long dndVersion = ourDndVersion;
  197242. XChangeProperty (display, wndH, XA_XdndAware, XA_ATOM, 32, PropModeReplace,
  197243. (const unsigned char*) &dndVersion, 1);
  197244. // Set window name
  197245. setWindowTitle (wndH, getComponent()->getName());
  197246. // Initialise the pointer and keyboard mapping
  197247. // This is not the same as the logical pointer mapping the X server uses:
  197248. // we don't mess with this.
  197249. static bool mappingInitialised = false;
  197250. if (! mappingInitialised)
  197251. {
  197252. mappingInitialised = true;
  197253. const int numButtons = XGetPointerMapping (display, 0, 0);
  197254. if (numButtons == 2)
  197255. {
  197256. pointerMap[0] = LeftButton;
  197257. pointerMap[1] = RightButton;
  197258. pointerMap[2] = pointerMap[3] = pointerMap[4] = NoButton;
  197259. }
  197260. else if (numButtons >= 3)
  197261. {
  197262. pointerMap[0] = LeftButton;
  197263. pointerMap[1] = MiddleButton;
  197264. pointerMap[2] = RightButton;
  197265. if (numButtons >= 5)
  197266. {
  197267. pointerMap[3] = WheelUp;
  197268. pointerMap[4] = WheelDown;
  197269. }
  197270. }
  197271. getModifierMapping();
  197272. }
  197273. windowH = wndH;
  197274. }
  197275. void destroyWindow()
  197276. {
  197277. ScopedXLock xlock;
  197278. XPointer handlePointer;
  197279. if (! XFindContext (display, (XID) windowH, improbableNumber, &handlePointer))
  197280. XDeleteContext (display, (XID) windowH, improbableNumber);
  197281. XDestroyWindow (display, windowH);
  197282. // Wait for it to complete and then remove any events for this
  197283. // window from the event queue.
  197284. XSync (display, false);
  197285. XEvent event;
  197286. while (XCheckWindowEvent (display, windowH, eventMask, &event) == True)
  197287. {}
  197288. }
  197289. static int64 getEventTime (::Time t) throw()
  197290. {
  197291. static int64 eventTimeOffset = 0x12345678;
  197292. const int64 thisMessageTime = t;
  197293. if (eventTimeOffset == 0x12345678)
  197294. eventTimeOffset = Time::currentTimeMillis() - thisMessageTime;
  197295. return eventTimeOffset + thisMessageTime;
  197296. }
  197297. static void setWindowTitle (Window xwin, const String& title)
  197298. {
  197299. XTextProperty nameProperty;
  197300. char* strings[] = { const_cast <char*> (title.toUTF8()) };
  197301. ScopedXLock xlock;
  197302. if (XStringListToTextProperty (strings, 1, &nameProperty))
  197303. {
  197304. XSetWMName (display, xwin, &nameProperty);
  197305. XSetWMIconName (display, xwin, &nameProperty);
  197306. XFree (nameProperty.value);
  197307. }
  197308. }
  197309. void updateBorderSize()
  197310. {
  197311. if ((styleFlags & windowHasTitleBar) == 0)
  197312. {
  197313. windowBorder = BorderSize (0);
  197314. }
  197315. else if (windowBorder.getTopAndBottom() == 0 && windowBorder.getLeftAndRight() == 0)
  197316. {
  197317. ScopedXLock xlock;
  197318. Atom hints = XInternAtom (display, "_NET_FRAME_EXTENTS", True);
  197319. if (hints != None)
  197320. {
  197321. unsigned char* data = 0;
  197322. unsigned long nitems, bytesLeft;
  197323. Atom actualType;
  197324. int actualFormat;
  197325. if (XGetWindowProperty (display, windowH, hints, 0, 4, False,
  197326. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197327. &data) == Success)
  197328. {
  197329. const unsigned long* const sizes = (const unsigned long*) data;
  197330. if (actualFormat == 32)
  197331. windowBorder = BorderSize ((int) sizes[2], (int) sizes[0],
  197332. (int) sizes[3], (int) sizes[1]);
  197333. XFree (data);
  197334. }
  197335. }
  197336. }
  197337. }
  197338. void updateBounds()
  197339. {
  197340. jassert (windowH != 0);
  197341. if (windowH != 0)
  197342. {
  197343. Window root, child;
  197344. unsigned int bw, depth;
  197345. ScopedXLock xlock;
  197346. if (! XGetGeometry (display, (::Drawable) windowH, &root,
  197347. &wx, &wy, (unsigned int*) &ww, (unsigned int*) &wh,
  197348. &bw, &depth))
  197349. {
  197350. wx = wy = ww = wh = 0;
  197351. }
  197352. else if (! XTranslateCoordinates (display, windowH, root, 0, 0, &wx, &wy, &child))
  197353. {
  197354. wx = wy = 0;
  197355. }
  197356. }
  197357. }
  197358. void resetDragAndDrop()
  197359. {
  197360. dragAndDropFiles.clear();
  197361. lastDropPos = Point<int> (-1, -1);
  197362. dragAndDropCurrentMimeType = 0;
  197363. dragAndDropSourceWindow = 0;
  197364. srcMimeTypeAtomList.clear();
  197365. }
  197366. void sendDragAndDropMessage (XClientMessageEvent& msg)
  197367. {
  197368. msg.type = ClientMessage;
  197369. msg.display = display;
  197370. msg.window = dragAndDropSourceWindow;
  197371. msg.format = 32;
  197372. msg.data.l[0] = windowH;
  197373. ScopedXLock xlock;
  197374. XSendEvent (display, dragAndDropSourceWindow, False, 0, (XEvent*) &msg);
  197375. }
  197376. void sendDragAndDropStatus (const bool acceptDrop, Atom dropAction)
  197377. {
  197378. XClientMessageEvent msg;
  197379. zerostruct (msg);
  197380. msg.message_type = XA_XdndStatus;
  197381. msg.data.l[1] = (acceptDrop ? 1 : 0) | 2; // 2 indicates that we want to receive position messages
  197382. msg.data.l[4] = dropAction;
  197383. sendDragAndDropMessage (msg);
  197384. }
  197385. void sendDragAndDropLeave()
  197386. {
  197387. XClientMessageEvent msg;
  197388. zerostruct (msg);
  197389. msg.message_type = XA_XdndLeave;
  197390. sendDragAndDropMessage (msg);
  197391. }
  197392. void sendDragAndDropFinish()
  197393. {
  197394. XClientMessageEvent msg;
  197395. zerostruct (msg);
  197396. msg.message_type = XA_XdndFinished;
  197397. sendDragAndDropMessage (msg);
  197398. }
  197399. void handleDragAndDropStatus (const XClientMessageEvent* const clientMsg)
  197400. {
  197401. if ((clientMsg->data.l[1] & 1) == 0)
  197402. {
  197403. sendDragAndDropLeave();
  197404. if (dragAndDropFiles.size() > 0)
  197405. handleFileDragExit (dragAndDropFiles);
  197406. dragAndDropFiles.clear();
  197407. }
  197408. }
  197409. void handleDragAndDropPosition (const XClientMessageEvent* const clientMsg)
  197410. {
  197411. if (dragAndDropSourceWindow == 0)
  197412. return;
  197413. dragAndDropSourceWindow = clientMsg->data.l[0];
  197414. Point<int> dropPos ((int) clientMsg->data.l[2] >> 16,
  197415. (int) clientMsg->data.l[2] & 0xffff);
  197416. dropPos -= getScreenPosition();
  197417. if (lastDropPos != dropPos)
  197418. {
  197419. lastDropPos = dropPos;
  197420. dragAndDropTimestamp = clientMsg->data.l[3];
  197421. Atom targetAction = XA_XdndActionCopy;
  197422. for (int i = numElementsInArray (allowedActions); --i >= 0;)
  197423. {
  197424. if ((Atom) clientMsg->data.l[4] == allowedActions[i])
  197425. {
  197426. targetAction = allowedActions[i];
  197427. break;
  197428. }
  197429. }
  197430. sendDragAndDropStatus (true, targetAction);
  197431. if (dragAndDropFiles.size() == 0)
  197432. updateDraggedFileList (clientMsg);
  197433. if (dragAndDropFiles.size() > 0)
  197434. handleFileDragMove (dragAndDropFiles, dropPos);
  197435. }
  197436. }
  197437. void handleDragAndDropDrop (const XClientMessageEvent* const clientMsg)
  197438. {
  197439. if (dragAndDropFiles.size() == 0)
  197440. updateDraggedFileList (clientMsg);
  197441. const StringArray files (dragAndDropFiles);
  197442. const Point<int> lastPos (lastDropPos);
  197443. sendDragAndDropFinish();
  197444. resetDragAndDrop();
  197445. if (files.size() > 0)
  197446. handleFileDragDrop (files, lastPos);
  197447. }
  197448. void handleDragAndDropEnter (const XClientMessageEvent* const clientMsg)
  197449. {
  197450. dragAndDropFiles.clear();
  197451. srcMimeTypeAtomList.clear();
  197452. dragAndDropCurrentMimeType = 0;
  197453. const int dndCurrentVersion = (int) (clientMsg->data.l[1] & 0xff000000) >> 24;
  197454. if (dndCurrentVersion < 3 || dndCurrentVersion > ourDndVersion)
  197455. {
  197456. dragAndDropSourceWindow = 0;
  197457. return;
  197458. }
  197459. dragAndDropSourceWindow = clientMsg->data.l[0];
  197460. if ((clientMsg->data.l[1] & 1) != 0)
  197461. {
  197462. Atom actual;
  197463. int format;
  197464. unsigned long count = 0, remaining = 0;
  197465. unsigned char* data = 0;
  197466. ScopedXLock xlock;
  197467. XGetWindowProperty (display, dragAndDropSourceWindow, XA_XdndTypeList,
  197468. 0, 0x8000000L, False, XA_ATOM, &actual, &format,
  197469. &count, &remaining, &data);
  197470. if (data != 0)
  197471. {
  197472. if (actual == XA_ATOM && format == 32 && count != 0)
  197473. {
  197474. const unsigned long* const types = (const unsigned long*) data;
  197475. for (unsigned int i = 0; i < count; ++i)
  197476. if (types[i] != None)
  197477. srcMimeTypeAtomList.add (types[i]);
  197478. }
  197479. XFree (data);
  197480. }
  197481. }
  197482. if (srcMimeTypeAtomList.size() == 0)
  197483. {
  197484. for (int i = 2; i < 5; ++i)
  197485. if (clientMsg->data.l[i] != None)
  197486. srcMimeTypeAtomList.add (clientMsg->data.l[i]);
  197487. if (srcMimeTypeAtomList.size() == 0)
  197488. {
  197489. dragAndDropSourceWindow = 0;
  197490. return;
  197491. }
  197492. }
  197493. for (int i = 0; i < srcMimeTypeAtomList.size() && dragAndDropCurrentMimeType == 0; ++i)
  197494. for (int j = 0; j < numElementsInArray (allowedMimeTypeAtoms); ++j)
  197495. if (srcMimeTypeAtomList[i] == allowedMimeTypeAtoms[j])
  197496. dragAndDropCurrentMimeType = allowedMimeTypeAtoms[j];
  197497. handleDragAndDropPosition (clientMsg);
  197498. }
  197499. void handleDragAndDropSelection (const XEvent* const evt)
  197500. {
  197501. dragAndDropFiles.clear();
  197502. if (evt->xselection.property != 0)
  197503. {
  197504. StringArray lines;
  197505. {
  197506. MemoryBlock dropData;
  197507. for (;;)
  197508. {
  197509. Atom actual;
  197510. uint8* data = 0;
  197511. unsigned long count = 0, remaining = 0;
  197512. int format = 0;
  197513. ScopedXLock xlock;
  197514. if (XGetWindowProperty (display, evt->xany.window, evt->xselection.property,
  197515. dropData.getSize() / 4, 65536, 1, AnyPropertyType, &actual,
  197516. &format, &count, &remaining, &data) == Success)
  197517. {
  197518. dropData.append (data, count * format / 8);
  197519. XFree (data);
  197520. if (remaining == 0)
  197521. break;
  197522. }
  197523. else
  197524. {
  197525. XFree (data);
  197526. break;
  197527. }
  197528. }
  197529. lines.addLines (dropData.toString());
  197530. }
  197531. for (int i = 0; i < lines.size(); ++i)
  197532. dragAndDropFiles.add (URL::removeEscapeChars (lines[i].fromFirstOccurrenceOf (T("file://"), false, true)));
  197533. dragAndDropFiles.trim();
  197534. dragAndDropFiles.removeEmptyStrings();
  197535. }
  197536. }
  197537. void updateDraggedFileList (const XClientMessageEvent* const clientMsg)
  197538. {
  197539. dragAndDropFiles.clear();
  197540. if (dragAndDropSourceWindow != None
  197541. && dragAndDropCurrentMimeType != 0)
  197542. {
  197543. dragAndDropTimestamp = clientMsg->data.l[2];
  197544. ScopedXLock xlock;
  197545. XConvertSelection (display,
  197546. XA_XdndSelection,
  197547. dragAndDropCurrentMimeType,
  197548. XA_JXSelectionWindowProperty,
  197549. windowH,
  197550. dragAndDropTimestamp);
  197551. }
  197552. }
  197553. StringArray dragAndDropFiles;
  197554. int dragAndDropTimestamp;
  197555. Point<int> lastDropPos;
  197556. Atom XA_OtherMime, dragAndDropCurrentMimeType;
  197557. Window dragAndDropSourceWindow;
  197558. unsigned int allowedActions[5];
  197559. unsigned int allowedMimeTypeAtoms[3];
  197560. Array <Atom> srcMimeTypeAtomList;
  197561. static int pointerMap[5];
  197562. static Point<int> lastMousePos;
  197563. static void clearLastMousePos() throw()
  197564. {
  197565. lastMousePos = Point<int> (0x100000, 0x100000);
  197566. }
  197567. };
  197568. int LinuxComponentPeer::pointerMap[5];
  197569. Point<int> LinuxComponentPeer::lastMousePos;
  197570. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  197571. {
  197572. if (enableOrDisable)
  197573. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  197574. }
  197575. ComponentPeer* Component::createNewPeer (int styleFlags, void* /*nativeWindowToAttachTo*/)
  197576. {
  197577. return new LinuxComponentPeer (this, styleFlags);
  197578. }
  197579. // (this callback is hooked up in the messaging code)
  197580. void juce_windowMessageReceive (XEvent* event)
  197581. {
  197582. if (event->xany.window != None)
  197583. {
  197584. LinuxComponentPeer* const peer = LinuxComponentPeer::getPeerFor (event->xany.window);
  197585. if (ComponentPeer::isValidPeer (peer))
  197586. peer->handleWindowMessage (event);
  197587. }
  197588. else
  197589. {
  197590. switch (event->xany.type)
  197591. {
  197592. case KeymapNotify:
  197593. {
  197594. const XKeymapEvent* const keymapEvent = (const XKeymapEvent*) &event->xkeymap;
  197595. memcpy (keyStates, keymapEvent->key_vector, 32);
  197596. break;
  197597. }
  197598. default:
  197599. break;
  197600. }
  197601. }
  197602. }
  197603. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool /*clipToWorkArea*/)
  197604. {
  197605. if (display == 0)
  197606. return;
  197607. #if JUCE_USE_XINERAMA
  197608. int major_opcode, first_event, first_error;
  197609. ScopedXLock xlock;
  197610. if (XQueryExtension (display, "XINERAMA", &major_opcode, &first_event, &first_error))
  197611. {
  197612. typedef Bool (*tXineramaIsActive) (Display*);
  197613. typedef XineramaScreenInfo* (*tXineramaQueryScreens) (Display*, int*);
  197614. static tXineramaIsActive xXineramaIsActive = 0;
  197615. static tXineramaQueryScreens xXineramaQueryScreens = 0;
  197616. if (xXineramaIsActive == 0 || xXineramaQueryScreens == 0)
  197617. {
  197618. void* h = dlopen ("libXinerama.so", RTLD_GLOBAL | RTLD_NOW);
  197619. if (h != 0)
  197620. {
  197621. xXineramaIsActive = (tXineramaIsActive) dlsym (h, "XineramaIsActive");
  197622. xXineramaQueryScreens = (tXineramaQueryScreens) dlsym (h, "XineramaQueryScreens");
  197623. }
  197624. }
  197625. if (xXineramaIsActive != 0
  197626. && xXineramaQueryScreens != 0
  197627. && xXineramaIsActive (display))
  197628. {
  197629. int numMonitors = 0;
  197630. XineramaScreenInfo* const screens = xXineramaQueryScreens (display, &numMonitors);
  197631. if (screens != 0)
  197632. {
  197633. for (int i = numMonitors; --i >= 0;)
  197634. {
  197635. int index = screens[i].screen_number;
  197636. if (index >= 0)
  197637. {
  197638. while (monitorCoords.size() < index)
  197639. monitorCoords.add (Rectangle<int>());
  197640. monitorCoords.set (index, Rectangle<int> (screens[i].x_org,
  197641. screens[i].y_org,
  197642. screens[i].width,
  197643. screens[i].height));
  197644. }
  197645. }
  197646. XFree (screens);
  197647. }
  197648. }
  197649. }
  197650. if (monitorCoords.size() == 0)
  197651. #endif
  197652. {
  197653. Atom hints = XInternAtom (display, "_NET_WORKAREA", True);
  197654. if (hints != None)
  197655. {
  197656. const int numMonitors = ScreenCount (display);
  197657. for (int i = 0; i < numMonitors; ++i)
  197658. {
  197659. Window root = RootWindow (display, i);
  197660. unsigned long nitems, bytesLeft;
  197661. Atom actualType;
  197662. int actualFormat;
  197663. unsigned char* data = 0;
  197664. if (XGetWindowProperty (display, root, hints, 0, 4, False,
  197665. XA_CARDINAL, &actualType, &actualFormat, &nitems, &bytesLeft,
  197666. &data) == Success)
  197667. {
  197668. const long* const position = (const long*) data;
  197669. if (actualType == XA_CARDINAL && actualFormat == 32 && nitems == 4)
  197670. monitorCoords.add (Rectangle<int> (position[0], position[1],
  197671. position[2], position[3]));
  197672. XFree (data);
  197673. }
  197674. }
  197675. }
  197676. if (monitorCoords.size() == 0)
  197677. {
  197678. monitorCoords.add (Rectangle<int> (0, 0,
  197679. DisplayWidth (display, DefaultScreen (display)),
  197680. DisplayHeight (display, DefaultScreen (display))));
  197681. }
  197682. }
  197683. }
  197684. bool Desktop::canUseSemiTransparentWindows() throw()
  197685. {
  197686. return false;
  197687. }
  197688. const Point<int> Desktop::getMousePosition()
  197689. {
  197690. int mouseMods;
  197691. return getMousePos (mouseMods);
  197692. }
  197693. void Desktop::setMousePosition (const Point<int>& newPosition)
  197694. {
  197695. ScopedXLock xlock;
  197696. Window root = RootWindow (display, DefaultScreen (display));
  197697. XWarpPointer (display, None, root, 0, 0, 0, 0, newPosition.getX(), newPosition.getY());
  197698. }
  197699. static bool screenSaverAllowed = true;
  197700. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  197701. {
  197702. if (screenSaverAllowed != isEnabled)
  197703. {
  197704. screenSaverAllowed = isEnabled;
  197705. typedef void (*tXScreenSaverSuspend) (Display*, Bool);
  197706. static tXScreenSaverSuspend xScreenSaverSuspend = 0;
  197707. if (xScreenSaverSuspend == 0)
  197708. {
  197709. void* h = dlopen ("libXss.so", RTLD_GLOBAL | RTLD_NOW);
  197710. if (h != 0)
  197711. xScreenSaverSuspend = (tXScreenSaverSuspend) dlsym (h, "XScreenSaverSuspend");
  197712. }
  197713. ScopedXLock xlock;
  197714. if (xScreenSaverSuspend != 0)
  197715. xScreenSaverSuspend (display, ! isEnabled);
  197716. }
  197717. }
  197718. bool Desktop::isScreenSaverEnabled() throw()
  197719. {
  197720. return screenSaverAllowed;
  197721. }
  197722. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  197723. {
  197724. ScopedXLock xlock;
  197725. Window root = RootWindow (display, DefaultScreen (display));
  197726. const unsigned int imageW = image.getWidth();
  197727. const unsigned int imageH = image.getHeight();
  197728. unsigned int cursorW, cursorH;
  197729. if (! XQueryBestCursor (display, root, imageW, imageH, &cursorW, &cursorH))
  197730. return 0;
  197731. Image im (Image::ARGB, cursorW, cursorH, true);
  197732. Graphics g (im);
  197733. if (imageW > cursorW || imageH > cursorH)
  197734. {
  197735. hotspotX = (hotspotX * cursorW) / imageW;
  197736. hotspotY = (hotspotY * cursorH) / imageH;
  197737. g.drawImageWithin (&image, 0, 0, imageW, imageH,
  197738. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  197739. false);
  197740. }
  197741. else
  197742. {
  197743. g.drawImageAt (&image, 0, 0);
  197744. }
  197745. const int stride = (cursorW + 7) >> 3;
  197746. HeapBlock <uint8> maskPlane, sourcePlane;
  197747. maskPlane.calloc (stride * cursorH);
  197748. sourcePlane.calloc (stride * cursorH);
  197749. const bool msbfirst = (BitmapBitOrder (display) == MSBFirst);
  197750. for (int y = cursorH; --y >= 0;)
  197751. {
  197752. for (int x = cursorW; --x >= 0;)
  197753. {
  197754. const uint8 mask = (uint8) (1 << (msbfirst ? (7 - (x & 7)) : (x & 7)));
  197755. const int offset = y * stride + (x >> 3);
  197756. const Colour c (im.getPixelAt (x, y));
  197757. if (c.getAlpha() >= 128)
  197758. maskPlane[offset] |= mask;
  197759. if (c.getBrightness() >= 0.5f)
  197760. sourcePlane[offset] |= mask;
  197761. }
  197762. }
  197763. Pixmap sourcePixmap = XCreatePixmapFromBitmapData (display, root, (char*) sourcePlane, cursorW, cursorH, 0xffff, 0, 1);
  197764. Pixmap maskPixmap = XCreatePixmapFromBitmapData (display, root, (char*) maskPlane, cursorW, cursorH, 0xffff, 0, 1);
  197765. XColor white, black;
  197766. black.red = black.green = black.blue = 0;
  197767. white.red = white.green = white.blue = 0xffff;
  197768. void* result = (void*) XCreatePixmapCursor (display, sourcePixmap, maskPixmap, &white, &black, hotspotX, hotspotY);
  197769. XFreePixmap (display, sourcePixmap);
  197770. XFreePixmap (display, maskPixmap);
  197771. return result;
  197772. }
  197773. void juce_deleteMouseCursor (void* const cursorHandle, const bool) throw()
  197774. {
  197775. ScopedXLock xlock;
  197776. if (cursorHandle != None)
  197777. XFreeCursor (display, (Cursor) cursorHandle);
  197778. }
  197779. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  197780. {
  197781. unsigned int shape;
  197782. switch (type)
  197783. {
  197784. case MouseCursor::NoCursor:
  197785. {
  197786. const Image im (Image::ARGB, 16, 16, true);
  197787. return juce_createMouseCursorFromImage (im, 0, 0);
  197788. }
  197789. case MouseCursor::NormalCursor:
  197790. return (void*) None; // Use parent cursor
  197791. case MouseCursor::DraggingHandCursor:
  197792. {
  197793. static unsigned char dragHandData[] = {71,73,70,56,57,97,16,0,16,0,145,2,0,0,0,0,255,255,255,0,
  197794. 0,0,0,0,0,33,249,4,1,0,0,2,0,44,0,0,0,0,16,0,
  197795. 16,0,0,2,52,148,47,0,200,185,16,130,90,12,74,139,107,84,123,39,
  197796. 132,117,151,116,132,146,248,60,209,138,98,22,203,114,34,236,37,52,77,217,
  197797. 247,154,191,119,110,240,193,128,193,95,163,56,60,234,98,135,2,0,59 };
  197798. const int dragHandDataSize = 99;
  197799. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) dragHandData, dragHandDataSize));
  197800. return juce_createMouseCursorFromImage (*im, 8, 7);
  197801. }
  197802. case MouseCursor::CopyingCursor:
  197803. {
  197804. static unsigned char copyCursorData[] = {71,73,70,56,57,97,21,0,21,0,145,0,0,0,0,0,255,255,255,0,
  197805. 128,128,255,255,255,33,249,4,1,0,0,3,0,44,0,0,0,0,21,0,
  197806. 21,0,0,2,72,4,134,169,171,16,199,98,11,79,90,71,161,93,56,111,
  197807. 78,133,218,215,137,31,82,154,100,200,86,91,202,142,12,108,212,87,235,174,
  197808. 15,54,214,126,237,226,37,96,59,141,16,37,18,201,142,157,230,204,51,112,
  197809. 252,114,147,74,83,5,50,68,147,208,217,16,71,149,252,124,5,0,59,0,0 };
  197810. const int copyCursorSize = 119;
  197811. const ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) copyCursorData, copyCursorSize));
  197812. return juce_createMouseCursorFromImage (*im, 1, 3);
  197813. }
  197814. case MouseCursor::WaitCursor:
  197815. shape = XC_watch;
  197816. break;
  197817. case MouseCursor::IBeamCursor:
  197818. shape = XC_xterm;
  197819. break;
  197820. case MouseCursor::PointingHandCursor:
  197821. shape = XC_hand2;
  197822. break;
  197823. case MouseCursor::LeftRightResizeCursor:
  197824. shape = XC_sb_h_double_arrow;
  197825. break;
  197826. case MouseCursor::UpDownResizeCursor:
  197827. shape = XC_sb_v_double_arrow;
  197828. break;
  197829. case MouseCursor::UpDownLeftRightResizeCursor:
  197830. shape = XC_fleur;
  197831. break;
  197832. case MouseCursor::TopEdgeResizeCursor:
  197833. shape = XC_top_side;
  197834. break;
  197835. case MouseCursor::BottomEdgeResizeCursor:
  197836. shape = XC_bottom_side;
  197837. break;
  197838. case MouseCursor::LeftEdgeResizeCursor:
  197839. shape = XC_left_side;
  197840. break;
  197841. case MouseCursor::RightEdgeResizeCursor:
  197842. shape = XC_right_side;
  197843. break;
  197844. case MouseCursor::TopLeftCornerResizeCursor:
  197845. shape = XC_top_left_corner;
  197846. break;
  197847. case MouseCursor::TopRightCornerResizeCursor:
  197848. shape = XC_top_right_corner;
  197849. break;
  197850. case MouseCursor::BottomLeftCornerResizeCursor:
  197851. shape = XC_bottom_left_corner;
  197852. break;
  197853. case MouseCursor::BottomRightCornerResizeCursor:
  197854. shape = XC_bottom_right_corner;
  197855. break;
  197856. case MouseCursor::CrosshairCursor:
  197857. shape = XC_crosshair;
  197858. break;
  197859. default:
  197860. return (void*) None; // Use parent cursor
  197861. }
  197862. ScopedXLock xlock;
  197863. return (void*) XCreateFontCursor (display, shape);
  197864. }
  197865. void MouseCursor::showInWindow (ComponentPeer* peer) const throw()
  197866. {
  197867. LinuxComponentPeer* const lp = dynamic_cast <LinuxComponentPeer*> (peer);
  197868. if (lp != 0)
  197869. lp->showMouseCursor ((Cursor) getHandle());
  197870. }
  197871. void MouseCursor::showInAllWindows() const throw()
  197872. {
  197873. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  197874. showInWindow (ComponentPeer::getPeer (i));
  197875. }
  197876. Image* juce_createIconForFile (const File& file)
  197877. {
  197878. return 0;
  197879. }
  197880. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  197881. {
  197882. return new Image (format, imageWidth, imageHeight, clearImage);
  197883. }
  197884. #if JUCE_OPENGL
  197885. class WindowedGLContext : public OpenGLContext
  197886. {
  197887. public:
  197888. WindowedGLContext (Component* const component,
  197889. const OpenGLPixelFormat& pixelFormat_,
  197890. GLXContext sharedContext)
  197891. : renderContext (0),
  197892. embeddedWindow (0),
  197893. pixelFormat (pixelFormat_)
  197894. {
  197895. jassert (component != 0);
  197896. LinuxComponentPeer* const peer = dynamic_cast <LinuxComponentPeer*> (component->getTopLevelComponent()->getPeer());
  197897. if (peer == 0)
  197898. return;
  197899. ScopedXLock xlock;
  197900. XSync (display, False);
  197901. GLint attribs [64];
  197902. int n = 0;
  197903. attribs[n++] = GLX_RGBA;
  197904. attribs[n++] = GLX_DOUBLEBUFFER;
  197905. attribs[n++] = GLX_RED_SIZE;
  197906. attribs[n++] = pixelFormat.redBits;
  197907. attribs[n++] = GLX_GREEN_SIZE;
  197908. attribs[n++] = pixelFormat.greenBits;
  197909. attribs[n++] = GLX_BLUE_SIZE;
  197910. attribs[n++] = pixelFormat.blueBits;
  197911. attribs[n++] = GLX_ALPHA_SIZE;
  197912. attribs[n++] = pixelFormat.alphaBits;
  197913. attribs[n++] = GLX_DEPTH_SIZE;
  197914. attribs[n++] = pixelFormat.depthBufferBits;
  197915. attribs[n++] = GLX_STENCIL_SIZE;
  197916. attribs[n++] = pixelFormat.stencilBufferBits;
  197917. attribs[n++] = GLX_ACCUM_RED_SIZE;
  197918. attribs[n++] = pixelFormat.accumulationBufferRedBits;
  197919. attribs[n++] = GLX_ACCUM_GREEN_SIZE;
  197920. attribs[n++] = pixelFormat.accumulationBufferGreenBits;
  197921. attribs[n++] = GLX_ACCUM_BLUE_SIZE;
  197922. attribs[n++] = pixelFormat.accumulationBufferBlueBits;
  197923. attribs[n++] = GLX_ACCUM_ALPHA_SIZE;
  197924. attribs[n++] = pixelFormat.accumulationBufferAlphaBits;
  197925. // xxx not sure how to do fullSceneAntiAliasingNumSamples on linux..
  197926. attribs[n++] = None;
  197927. XVisualInfo* const bestVisual = glXChooseVisual (display, DefaultScreen (display), attribs);
  197928. if (bestVisual == 0)
  197929. return;
  197930. renderContext = glXCreateContext (display, bestVisual, sharedContext, GL_TRUE);
  197931. Window windowH = (Window) peer->getNativeHandle();
  197932. Colormap colourMap = XCreateColormap (display, windowH, bestVisual->visual, AllocNone);
  197933. XSetWindowAttributes swa;
  197934. swa.colormap = colourMap;
  197935. swa.border_pixel = 0;
  197936. swa.event_mask = ExposureMask | StructureNotifyMask;
  197937. embeddedWindow = XCreateWindow (display, windowH,
  197938. 0, 0, 1, 1, 0,
  197939. bestVisual->depth,
  197940. InputOutput,
  197941. bestVisual->visual,
  197942. CWBorderPixel | CWColormap | CWEventMask,
  197943. &swa);
  197944. XSaveContext (display, (XID) embeddedWindow, improbableNumber, (XPointer) peer);
  197945. XMapWindow (display, embeddedWindow);
  197946. XFreeColormap (display, colourMap);
  197947. XFree (bestVisual);
  197948. XSync (display, False);
  197949. }
  197950. ~WindowedGLContext()
  197951. {
  197952. makeInactive();
  197953. ScopedXLock xlock;
  197954. glXDestroyContext (display, renderContext);
  197955. XUnmapWindow (display, embeddedWindow);
  197956. XDestroyWindow (display, embeddedWindow);
  197957. }
  197958. bool makeActive() const throw()
  197959. {
  197960. jassert (renderContext != 0);
  197961. ScopedXLock xlock;
  197962. return glXMakeCurrent (display, embeddedWindow, renderContext)
  197963. && XSync (display, False);
  197964. }
  197965. bool makeInactive() const throw()
  197966. {
  197967. ScopedXLock xlock;
  197968. return (! isActive()) || glXMakeCurrent (display, None, 0);
  197969. }
  197970. bool isActive() const throw()
  197971. {
  197972. ScopedXLock xlock;
  197973. return glXGetCurrentContext() == renderContext;
  197974. }
  197975. const OpenGLPixelFormat getPixelFormat() const
  197976. {
  197977. return pixelFormat;
  197978. }
  197979. void* getRawContext() const throw()
  197980. {
  197981. return renderContext;
  197982. }
  197983. void updateWindowPosition (int x, int y, int w, int h, int)
  197984. {
  197985. ScopedXLock xlock;
  197986. XMoveResizeWindow (display, embeddedWindow,
  197987. x, y, jmax (1, w), jmax (1, h));
  197988. }
  197989. void swapBuffers()
  197990. {
  197991. ScopedXLock xlock;
  197992. glXSwapBuffers (display, embeddedWindow);
  197993. }
  197994. bool setSwapInterval (const int numFramesPerSwap)
  197995. {
  197996. // xxx needs doing..
  197997. return false;
  197998. }
  197999. int getSwapInterval() const
  198000. {
  198001. // xxx needs doing..
  198002. return 0;
  198003. }
  198004. void repaint()
  198005. {
  198006. }
  198007. juce_UseDebuggingNewOperator
  198008. GLXContext renderContext;
  198009. private:
  198010. Window embeddedWindow;
  198011. OpenGLPixelFormat pixelFormat;
  198012. WindowedGLContext (const WindowedGLContext&);
  198013. WindowedGLContext& operator= (const WindowedGLContext&);
  198014. };
  198015. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  198016. const OpenGLPixelFormat& pixelFormat,
  198017. const OpenGLContext* const contextToShareWith)
  198018. {
  198019. WindowedGLContext* c = new WindowedGLContext (component, pixelFormat,
  198020. contextToShareWith != 0 ? (GLXContext) contextToShareWith->getRawContext() : 0);
  198021. if (c->renderContext == 0)
  198022. deleteAndZero (c);
  198023. return c;
  198024. }
  198025. void juce_glViewport (const int w, const int h)
  198026. {
  198027. glViewport (0, 0, w, h);
  198028. }
  198029. void OpenGLPixelFormat::getAvailablePixelFormats (Component* component,
  198030. OwnedArray <OpenGLPixelFormat>& results)
  198031. {
  198032. results.add (new OpenGLPixelFormat()); // xxx
  198033. }
  198034. #endif
  198035. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  198036. {
  198037. jassertfalse // not implemented!
  198038. return false;
  198039. }
  198040. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  198041. {
  198042. jassertfalse // not implemented!
  198043. return false;
  198044. }
  198045. void SystemTrayIconComponent::setIconImage (const Image& newImage)
  198046. {
  198047. if (! isOnDesktop ())
  198048. addToDesktop (0);
  198049. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  198050. if (wp != 0)
  198051. {
  198052. wp->setTaskBarIcon (newImage);
  198053. setVisible (true);
  198054. toFront (false);
  198055. repaint();
  198056. }
  198057. }
  198058. void SystemTrayIconComponent::paint (Graphics& g)
  198059. {
  198060. LinuxComponentPeer* const wp = dynamic_cast <LinuxComponentPeer*> (getPeer());
  198061. if (wp != 0)
  198062. {
  198063. const Image* const image = wp->getTaskbarIcon();
  198064. if (image != 0)
  198065. {
  198066. g.drawImageWithin (image, 0, 0, getWidth(), getHeight(),
  198067. RectanglePlacement::xLeft | RectanglePlacement::yTop | RectanglePlacement::onlyReduceInSize,
  198068. false);
  198069. }
  198070. }
  198071. }
  198072. void SystemTrayIconComponent::setIconTooltip (const String& tooltip)
  198073. {
  198074. // xxx not yet implemented!
  198075. }
  198076. void PlatformUtilities::beep()
  198077. {
  198078. std::cout << "\a" << std::flush;
  198079. }
  198080. bool AlertWindow::showNativeDialogBox (const String& title,
  198081. const String& bodyText,
  198082. bool isOkCancel)
  198083. {
  198084. // xxx this is supposed to pop up an alert!
  198085. Logger::outputDebugString (title + ": " + bodyText);
  198086. // use a non-native one for the time being..
  198087. if (isOkCancel)
  198088. return AlertWindow::showOkCancelBox (AlertWindow::NoIcon, title, bodyText);
  198089. else
  198090. AlertWindow::showMessageBox (AlertWindow::NoIcon, title, bodyText);
  198091. return true;
  198092. }
  198093. const int KeyPress::spaceKey = XK_space & 0xff;
  198094. const int KeyPress::returnKey = XK_Return & 0xff;
  198095. const int KeyPress::escapeKey = XK_Escape & 0xff;
  198096. const int KeyPress::backspaceKey = XK_BackSpace & 0xff;
  198097. const int KeyPress::leftKey = (XK_Left & 0xff) | extendedKeyModifier;
  198098. const int KeyPress::rightKey = (XK_Right & 0xff) | extendedKeyModifier;
  198099. const int KeyPress::upKey = (XK_Up & 0xff) | extendedKeyModifier;
  198100. const int KeyPress::downKey = (XK_Down & 0xff) | extendedKeyModifier;
  198101. const int KeyPress::pageUpKey = (XK_Page_Up & 0xff) | extendedKeyModifier;
  198102. const int KeyPress::pageDownKey = (XK_Page_Down & 0xff) | extendedKeyModifier;
  198103. const int KeyPress::endKey = (XK_End & 0xff) | extendedKeyModifier;
  198104. const int KeyPress::homeKey = (XK_Home & 0xff) | extendedKeyModifier;
  198105. const int KeyPress::insertKey = (XK_Insert & 0xff) | extendedKeyModifier;
  198106. const int KeyPress::deleteKey = (XK_Delete & 0xff) | extendedKeyModifier;
  198107. const int KeyPress::tabKey = XK_Tab & 0xff;
  198108. const int KeyPress::F1Key = (XK_F1 & 0xff) | extendedKeyModifier;
  198109. const int KeyPress::F2Key = (XK_F2 & 0xff) | extendedKeyModifier;
  198110. const int KeyPress::F3Key = (XK_F3 & 0xff) | extendedKeyModifier;
  198111. const int KeyPress::F4Key = (XK_F4 & 0xff) | extendedKeyModifier;
  198112. const int KeyPress::F5Key = (XK_F5 & 0xff) | extendedKeyModifier;
  198113. const int KeyPress::F6Key = (XK_F6 & 0xff) | extendedKeyModifier;
  198114. const int KeyPress::F7Key = (XK_F7 & 0xff) | extendedKeyModifier;
  198115. const int KeyPress::F8Key = (XK_F8 & 0xff) | extendedKeyModifier;
  198116. const int KeyPress::F9Key = (XK_F9 & 0xff) | extendedKeyModifier;
  198117. const int KeyPress::F10Key = (XK_F10 & 0xff) | extendedKeyModifier;
  198118. const int KeyPress::F11Key = (XK_F11 & 0xff) | extendedKeyModifier;
  198119. const int KeyPress::F12Key = (XK_F12 & 0xff) | extendedKeyModifier;
  198120. const int KeyPress::F13Key = (XK_F13 & 0xff) | extendedKeyModifier;
  198121. const int KeyPress::F14Key = (XK_F14 & 0xff) | extendedKeyModifier;
  198122. const int KeyPress::F15Key = (XK_F15 & 0xff) | extendedKeyModifier;
  198123. const int KeyPress::F16Key = (XK_F16 & 0xff) | extendedKeyModifier;
  198124. const int KeyPress::numberPad0 = (XK_KP_0 & 0xff) | extendedKeyModifier;
  198125. const int KeyPress::numberPad1 = (XK_KP_1 & 0xff) | extendedKeyModifier;
  198126. const int KeyPress::numberPad2 = (XK_KP_2 & 0xff) | extendedKeyModifier;
  198127. const int KeyPress::numberPad3 = (XK_KP_3 & 0xff) | extendedKeyModifier;
  198128. const int KeyPress::numberPad4 = (XK_KP_4 & 0xff) | extendedKeyModifier;
  198129. const int KeyPress::numberPad5 = (XK_KP_5 & 0xff) | extendedKeyModifier;
  198130. const int KeyPress::numberPad6 = (XK_KP_6 & 0xff) | extendedKeyModifier;
  198131. const int KeyPress::numberPad7 = (XK_KP_7 & 0xff)| extendedKeyModifier;
  198132. const int KeyPress::numberPad8 = (XK_KP_8 & 0xff)| extendedKeyModifier;
  198133. const int KeyPress::numberPad9 = (XK_KP_9 & 0xff)| extendedKeyModifier;
  198134. const int KeyPress::numberPadAdd = (XK_KP_Add & 0xff)| extendedKeyModifier;
  198135. const int KeyPress::numberPadSubtract = (XK_KP_Subtract & 0xff)| extendedKeyModifier;
  198136. const int KeyPress::numberPadMultiply = (XK_KP_Multiply & 0xff)| extendedKeyModifier;
  198137. const int KeyPress::numberPadDivide = (XK_KP_Divide & 0xff)| extendedKeyModifier;
  198138. const int KeyPress::numberPadSeparator = (XK_KP_Separator & 0xff)| extendedKeyModifier;
  198139. const int KeyPress::numberPadDecimalPoint = (XK_KP_Decimal & 0xff)| extendedKeyModifier;
  198140. const int KeyPress::numberPadEquals = (XK_KP_Equal & 0xff)| extendedKeyModifier;
  198141. const int KeyPress::numberPadDelete = (XK_KP_Delete & 0xff)| extendedKeyModifier;
  198142. const int KeyPress::playKey = (0xffeeff00) | extendedKeyModifier;
  198143. const int KeyPress::stopKey = (0xffeeff01) | extendedKeyModifier;
  198144. const int KeyPress::fastForwardKey = (0xffeeff02) | extendedKeyModifier;
  198145. const int KeyPress::rewindKey = (0xffeeff03) | extendedKeyModifier;
  198146. #endif
  198147. /*** End of inlined file: juce_linux_Windowing.cpp ***/
  198148. /*** Start of inlined file: juce_linux_Audio.cpp ***/
  198149. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198150. // compiled on its own).
  198151. #if JUCE_INCLUDED_FILE && JUCE_ALSA
  198152. static const int maxNumChans = 64;
  198153. static void getDeviceSampleRates (snd_pcm_t* handle, Array <int>& rates)
  198154. {
  198155. const int ratesToTry[] = { 22050, 32000, 44100, 48000, 88200, 96000, 176400, 192000, 0 };
  198156. snd_pcm_hw_params_t* hwParams;
  198157. snd_pcm_hw_params_alloca (&hwParams);
  198158. for (int i = 0; ratesToTry[i] != 0; ++i)
  198159. {
  198160. if (snd_pcm_hw_params_any (handle, hwParams) >= 0
  198161. && snd_pcm_hw_params_test_rate (handle, hwParams, ratesToTry[i], 0) == 0)
  198162. {
  198163. rates.addIfNotAlreadyThere (ratesToTry[i]);
  198164. }
  198165. }
  198166. }
  198167. static void getDeviceNumChannels (snd_pcm_t* handle, unsigned int* minChans, unsigned int* maxChans)
  198168. {
  198169. snd_pcm_hw_params_t *params;
  198170. snd_pcm_hw_params_alloca (&params);
  198171. if (snd_pcm_hw_params_any (handle, params) >= 0)
  198172. {
  198173. snd_pcm_hw_params_get_channels_min (params, minChans);
  198174. snd_pcm_hw_params_get_channels_max (params, maxChans);
  198175. }
  198176. }
  198177. static void getDeviceProperties (const String& deviceID,
  198178. unsigned int& minChansOut,
  198179. unsigned int& maxChansOut,
  198180. unsigned int& minChansIn,
  198181. unsigned int& maxChansIn,
  198182. Array <int>& rates)
  198183. {
  198184. if (deviceID.isEmpty())
  198185. return;
  198186. snd_ctl_t* handle;
  198187. if (snd_ctl_open (&handle, deviceID.upToLastOccurrenceOf (T(","), false, false).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  198188. {
  198189. snd_pcm_info_t* info;
  198190. snd_pcm_info_alloca (&info);
  198191. snd_pcm_info_set_stream (info, SND_PCM_STREAM_PLAYBACK);
  198192. snd_pcm_info_set_device (info, deviceID.fromLastOccurrenceOf (T(","), false, false).getIntValue());
  198193. snd_pcm_info_set_subdevice (info, 0);
  198194. if (snd_ctl_pcm_info (handle, info) >= 0)
  198195. {
  198196. snd_pcm_t* pcmHandle;
  198197. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_PLAYBACK, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198198. {
  198199. getDeviceNumChannels (pcmHandle, &minChansOut, &maxChansOut);
  198200. getDeviceSampleRates (pcmHandle, rates);
  198201. snd_pcm_close (pcmHandle);
  198202. }
  198203. }
  198204. snd_pcm_info_set_stream (info, SND_PCM_STREAM_CAPTURE);
  198205. if (snd_ctl_pcm_info (handle, info) >= 0)
  198206. {
  198207. snd_pcm_t* pcmHandle;
  198208. if (snd_pcm_open (&pcmHandle, deviceID.toUTF8(), SND_PCM_STREAM_CAPTURE, SND_PCM_ASYNC | SND_PCM_NONBLOCK ) >= 0)
  198209. {
  198210. getDeviceNumChannels (pcmHandle, &minChansIn, &maxChansIn);
  198211. if (rates.size() == 0)
  198212. getDeviceSampleRates (pcmHandle, rates);
  198213. snd_pcm_close (pcmHandle);
  198214. }
  198215. }
  198216. snd_ctl_close (handle);
  198217. }
  198218. }
  198219. class ALSADevice
  198220. {
  198221. public:
  198222. ALSADevice (const String& deviceID,
  198223. const bool forInput)
  198224. : handle (0),
  198225. bitDepth (16),
  198226. numChannelsRunning (0),
  198227. isInput (forInput),
  198228. sampleFormat (AudioDataConverters::int16LE)
  198229. {
  198230. failed (snd_pcm_open (&handle, deviceID.toUTF8(),
  198231. forInput ? SND_PCM_STREAM_CAPTURE : SND_PCM_STREAM_PLAYBACK,
  198232. SND_PCM_ASYNC));
  198233. }
  198234. ~ALSADevice()
  198235. {
  198236. if (handle != 0)
  198237. snd_pcm_close (handle);
  198238. }
  198239. bool setParameters (unsigned int sampleRate, int numChannels, int bufferSize)
  198240. {
  198241. if (handle == 0)
  198242. return false;
  198243. snd_pcm_hw_params_t* hwParams;
  198244. snd_pcm_hw_params_alloca (&hwParams);
  198245. if (failed (snd_pcm_hw_params_any (handle, hwParams)))
  198246. return false;
  198247. if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_NONINTERLEAVED) >= 0)
  198248. isInterleaved = false;
  198249. else if (snd_pcm_hw_params_set_access (handle, hwParams, SND_PCM_ACCESS_RW_INTERLEAVED) >= 0)
  198250. isInterleaved = true;
  198251. else
  198252. {
  198253. jassertfalse
  198254. return false;
  198255. }
  198256. const int formatsToTry[] = { SND_PCM_FORMAT_FLOAT_LE, 32, AudioDataConverters::float32LE,
  198257. SND_PCM_FORMAT_FLOAT_BE, 32, AudioDataConverters::float32BE,
  198258. SND_PCM_FORMAT_S32_LE, 32, AudioDataConverters::int32LE,
  198259. SND_PCM_FORMAT_S32_BE, 32, AudioDataConverters::int32BE,
  198260. SND_PCM_FORMAT_S24_3LE, 24, AudioDataConverters::int24LE,
  198261. SND_PCM_FORMAT_S24_3BE, 24, AudioDataConverters::int24BE,
  198262. SND_PCM_FORMAT_S16_LE, 16, AudioDataConverters::int16LE,
  198263. SND_PCM_FORMAT_S16_BE, 16, AudioDataConverters::int16BE };
  198264. bitDepth = 0;
  198265. for (int i = 0; i < numElementsInArray (formatsToTry); i += 3)
  198266. {
  198267. if (snd_pcm_hw_params_set_format (handle, hwParams, (_snd_pcm_format) formatsToTry [i]) >= 0)
  198268. {
  198269. bitDepth = formatsToTry [i + 1];
  198270. sampleFormat = (AudioDataConverters::DataFormat) formatsToTry [i + 2];
  198271. break;
  198272. }
  198273. }
  198274. if (bitDepth == 0)
  198275. {
  198276. error = "device doesn't support a compatible PCM format";
  198277. DBG (T("ALSA error: ") + error + T("\n"));
  198278. return false;
  198279. }
  198280. int dir = 0;
  198281. unsigned int periods = 4;
  198282. snd_pcm_uframes_t samplesPerPeriod = bufferSize;
  198283. if (failed (snd_pcm_hw_params_set_rate_near (handle, hwParams, &sampleRate, 0))
  198284. || failed (snd_pcm_hw_params_set_channels (handle, hwParams, numChannels))
  198285. || failed (snd_pcm_hw_params_set_periods_near (handle, hwParams, &periods, &dir))
  198286. || failed (snd_pcm_hw_params_set_period_size_near (handle, hwParams, &samplesPerPeriod, &dir))
  198287. || failed (snd_pcm_hw_params (handle, hwParams)))
  198288. {
  198289. return false;
  198290. }
  198291. snd_pcm_sw_params_t* swParams;
  198292. snd_pcm_sw_params_alloca (&swParams);
  198293. snd_pcm_uframes_t boundary;
  198294. if (failed (snd_pcm_sw_params_current (handle, swParams))
  198295. || failed (snd_pcm_sw_params_get_boundary (swParams, &boundary))
  198296. || failed (snd_pcm_sw_params_set_silence_threshold (handle, swParams, 0))
  198297. || failed (snd_pcm_sw_params_set_silence_size (handle, swParams, boundary))
  198298. || failed (snd_pcm_sw_params_set_start_threshold (handle, swParams, samplesPerPeriod))
  198299. || failed (snd_pcm_sw_params_set_stop_threshold (handle, swParams, boundary))
  198300. || failed (snd_pcm_sw_params (handle, swParams)))
  198301. {
  198302. return false;
  198303. }
  198304. numChannelsRunning = numChannels;
  198305. return true;
  198306. }
  198307. bool write (float** const data, const int numSamples)
  198308. {
  198309. if (isInterleaved)
  198310. {
  198311. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198312. float* interleaved = (float*) scratch;
  198313. AudioDataConverters::interleaveSamples ((const float**) data, interleaved, numSamples, numChannelsRunning);
  198314. AudioDataConverters::convertFloatToFormat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198315. snd_pcm_sframes_t num = snd_pcm_writei (handle, (void*) interleaved, numSamples);
  198316. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198317. return false;
  198318. }
  198319. else
  198320. {
  198321. for (int i = 0; i < numChannelsRunning; ++i)
  198322. if (data[i] != 0)
  198323. AudioDataConverters::convertFloatToFormat (sampleFormat, data[i], data[i], numSamples);
  198324. snd_pcm_sframes_t num = snd_pcm_writen (handle, (void**) data, numSamples);
  198325. if (failed (num))
  198326. {
  198327. if (num == -EPIPE)
  198328. {
  198329. if (failed (snd_pcm_prepare (handle)))
  198330. return false;
  198331. }
  198332. else if (num != -ESTRPIPE)
  198333. return false;
  198334. }
  198335. }
  198336. return true;
  198337. }
  198338. bool read (float** const data, const int numSamples)
  198339. {
  198340. if (isInterleaved)
  198341. {
  198342. scratch.ensureSize (sizeof (float) * numSamples * numChannelsRunning, false);
  198343. float* interleaved = (float*) scratch;
  198344. snd_pcm_sframes_t num = snd_pcm_readi (handle, (void*) interleaved, numSamples);
  198345. if (failed (num))
  198346. {
  198347. if (num == -EPIPE)
  198348. {
  198349. if (failed (snd_pcm_prepare (handle)))
  198350. return false;
  198351. }
  198352. else if (num != -ESTRPIPE)
  198353. return false;
  198354. }
  198355. AudioDataConverters::convertFormatToFloat (sampleFormat, interleaved, interleaved, numSamples * numChannelsRunning);
  198356. AudioDataConverters::deinterleaveSamples (interleaved, data, numSamples, numChannelsRunning);
  198357. }
  198358. else
  198359. {
  198360. snd_pcm_sframes_t num = snd_pcm_readn (handle, (void**) data, numSamples);
  198361. if (failed (num) && num != -EPIPE && num != -ESTRPIPE)
  198362. return false;
  198363. for (int i = 0; i < numChannelsRunning; ++i)
  198364. if (data[i] != 0)
  198365. AudioDataConverters::convertFormatToFloat (sampleFormat, data[i], data[i], numSamples);
  198366. }
  198367. return true;
  198368. }
  198369. juce_UseDebuggingNewOperator
  198370. snd_pcm_t* handle;
  198371. String error;
  198372. int bitDepth, numChannelsRunning;
  198373. private:
  198374. const bool isInput;
  198375. bool isInterleaved;
  198376. MemoryBlock scratch;
  198377. AudioDataConverters::DataFormat sampleFormat;
  198378. bool failed (const int errorNum)
  198379. {
  198380. if (errorNum >= 0)
  198381. return false;
  198382. error = snd_strerror (errorNum);
  198383. DBG (T("ALSA error: ") + error + T("\n"));
  198384. return true;
  198385. }
  198386. };
  198387. class ALSAThread : public Thread
  198388. {
  198389. public:
  198390. ALSAThread (const String& inputId_,
  198391. const String& outputId_)
  198392. : Thread ("Juce ALSA"),
  198393. sampleRate (0),
  198394. bufferSize (0),
  198395. callback (0),
  198396. inputId (inputId_),
  198397. outputId (outputId_),
  198398. outputDevice (0),
  198399. inputDevice (0),
  198400. numCallbacks (0),
  198401. totalNumInputChannels (0),
  198402. totalNumOutputChannels (0)
  198403. {
  198404. zeromem (outputChannelData, sizeof (outputChannelData));
  198405. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198406. zeromem (inputChannelData, sizeof (inputChannelData));
  198407. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198408. initialiseRatesAndChannels();
  198409. }
  198410. ~ALSAThread()
  198411. {
  198412. close();
  198413. }
  198414. void open (BitArray inputChannels,
  198415. BitArray outputChannels,
  198416. const double sampleRate_,
  198417. const int bufferSize_)
  198418. {
  198419. close();
  198420. error = String::empty;
  198421. sampleRate = sampleRate_;
  198422. bufferSize = bufferSize_;
  198423. currentInputChans.clear();
  198424. currentOutputChans.clear();
  198425. if (inputChannels.getHighestBit() >= 0)
  198426. {
  198427. for (int i = 0; i <= jmax (inputChannels.getHighestBit(), (int) minChansIn); ++i)
  198428. {
  198429. inputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198430. if (inputChannels[i])
  198431. {
  198432. inputChannelDataForCallback [totalNumInputChannels++] = inputChannelData [i];
  198433. currentInputChans.setBit (i);
  198434. }
  198435. }
  198436. }
  198437. if (outputChannels.getHighestBit() >= 0)
  198438. {
  198439. for (int i = 0; i <= jmax (outputChannels.getHighestBit(), (int) minChansOut); ++i)
  198440. {
  198441. outputChannelData [i] = (float*) juce_calloc (sizeof (float) * bufferSize);
  198442. if (outputChannels[i])
  198443. {
  198444. outputChannelDataForCallback [totalNumOutputChannels++] = outputChannelData [i];
  198445. currentOutputChans.setBit (i);
  198446. }
  198447. }
  198448. }
  198449. if (totalNumOutputChannels > 0 && outputId.isNotEmpty())
  198450. {
  198451. outputDevice = new ALSADevice (outputId, false);
  198452. if (outputDevice->error.isNotEmpty())
  198453. {
  198454. error = outputDevice->error;
  198455. deleteAndZero (outputDevice);
  198456. return;
  198457. }
  198458. currentOutputChans.setRange (0, minChansOut, true);
  198459. if (! outputDevice->setParameters ((unsigned int) sampleRate,
  198460. jlimit ((int) minChansOut, (int) maxChansOut, currentOutputChans.getHighestBit() + 1),
  198461. bufferSize))
  198462. {
  198463. error = outputDevice->error;
  198464. deleteAndZero (outputDevice);
  198465. return;
  198466. }
  198467. }
  198468. if (totalNumInputChannels > 0 && inputId.isNotEmpty())
  198469. {
  198470. inputDevice = new ALSADevice (inputId, true);
  198471. if (inputDevice->error.isNotEmpty())
  198472. {
  198473. error = inputDevice->error;
  198474. deleteAndZero (inputDevice);
  198475. return;
  198476. }
  198477. currentInputChans.setRange (0, minChansIn, true);
  198478. if (! inputDevice->setParameters ((unsigned int) sampleRate,
  198479. jlimit ((int) minChansIn, (int) maxChansIn, currentInputChans.getHighestBit() + 1),
  198480. bufferSize))
  198481. {
  198482. error = inputDevice->error;
  198483. deleteAndZero (inputDevice);
  198484. return;
  198485. }
  198486. }
  198487. if (outputDevice == 0 && inputDevice == 0)
  198488. {
  198489. error = "no channels";
  198490. return;
  198491. }
  198492. if (outputDevice != 0 && inputDevice != 0)
  198493. {
  198494. snd_pcm_link (outputDevice->handle, inputDevice->handle);
  198495. }
  198496. if (inputDevice != 0 && failed (snd_pcm_prepare (inputDevice->handle)))
  198497. return;
  198498. if (outputDevice != 0 && failed (snd_pcm_prepare (outputDevice->handle)))
  198499. return;
  198500. startThread (9);
  198501. int count = 1000;
  198502. while (numCallbacks == 0)
  198503. {
  198504. sleep (5);
  198505. if (--count < 0 || ! isThreadRunning())
  198506. {
  198507. error = "device didn't start";
  198508. break;
  198509. }
  198510. }
  198511. }
  198512. void close()
  198513. {
  198514. stopThread (6000);
  198515. deleteAndZero (inputDevice);
  198516. deleteAndZero (outputDevice);
  198517. for (int i = 0; i < maxNumChans; ++i)
  198518. {
  198519. juce_free (inputChannelData [i]);
  198520. juce_free (outputChannelData [i]);
  198521. }
  198522. zeromem (outputChannelData, sizeof (outputChannelData));
  198523. zeromem (outputChannelDataForCallback, sizeof (outputChannelDataForCallback));
  198524. zeromem (inputChannelData, sizeof (inputChannelData));
  198525. zeromem (inputChannelDataForCallback, sizeof (inputChannelDataForCallback));
  198526. totalNumOutputChannels = 0;
  198527. totalNumInputChannels = 0;
  198528. numCallbacks = 0;
  198529. }
  198530. void setCallback (AudioIODeviceCallback* const newCallback) throw()
  198531. {
  198532. const ScopedLock sl (callbackLock);
  198533. callback = newCallback;
  198534. }
  198535. void run()
  198536. {
  198537. while (! threadShouldExit())
  198538. {
  198539. if (inputDevice != 0)
  198540. {
  198541. if (! inputDevice->read (inputChannelData, bufferSize))
  198542. {
  198543. DBG ("ALSA: read failure");
  198544. break;
  198545. }
  198546. }
  198547. if (threadShouldExit())
  198548. break;
  198549. {
  198550. const ScopedLock sl (callbackLock);
  198551. ++numCallbacks;
  198552. if (callback != 0)
  198553. {
  198554. callback->audioDeviceIOCallback ((const float**) inputChannelDataForCallback,
  198555. totalNumInputChannels,
  198556. outputChannelDataForCallback,
  198557. totalNumOutputChannels,
  198558. bufferSize);
  198559. }
  198560. else
  198561. {
  198562. for (int i = 0; i < totalNumOutputChannels; ++i)
  198563. zeromem (outputChannelDataForCallback[i], sizeof (float) * bufferSize);
  198564. }
  198565. }
  198566. if (outputDevice != 0)
  198567. {
  198568. failed (snd_pcm_wait (outputDevice->handle, 2000));
  198569. if (threadShouldExit())
  198570. break;
  198571. failed (snd_pcm_avail_update (outputDevice->handle));
  198572. if (! outputDevice->write (outputChannelData, bufferSize))
  198573. {
  198574. DBG ("ALSA: write failure");
  198575. break;
  198576. }
  198577. }
  198578. }
  198579. }
  198580. int getBitDepth() const throw()
  198581. {
  198582. if (outputDevice != 0)
  198583. return outputDevice->bitDepth;
  198584. if (inputDevice != 0)
  198585. return inputDevice->bitDepth;
  198586. return 16;
  198587. }
  198588. juce_UseDebuggingNewOperator
  198589. String error;
  198590. double sampleRate;
  198591. int bufferSize;
  198592. BitArray currentInputChans, currentOutputChans;
  198593. Array <int> sampleRates;
  198594. StringArray channelNamesOut, channelNamesIn;
  198595. AudioIODeviceCallback* callback;
  198596. private:
  198597. const String inputId, outputId;
  198598. ALSADevice* outputDevice;
  198599. ALSADevice* inputDevice;
  198600. int numCallbacks;
  198601. CriticalSection callbackLock;
  198602. float* outputChannelData [maxNumChans];
  198603. float* outputChannelDataForCallback [maxNumChans];
  198604. int totalNumInputChannels;
  198605. float* inputChannelData [maxNumChans];
  198606. float* inputChannelDataForCallback [maxNumChans];
  198607. int totalNumOutputChannels;
  198608. unsigned int minChansOut, maxChansOut;
  198609. unsigned int minChansIn, maxChansIn;
  198610. bool failed (const int errorNum) throw()
  198611. {
  198612. if (errorNum >= 0)
  198613. return false;
  198614. error = snd_strerror (errorNum);
  198615. DBG (T("ALSA error: ") + error + T("\n"));
  198616. return true;
  198617. }
  198618. void initialiseRatesAndChannels() throw()
  198619. {
  198620. sampleRates.clear();
  198621. channelNamesOut.clear();
  198622. channelNamesIn.clear();
  198623. minChansOut = 0;
  198624. maxChansOut = 0;
  198625. minChansIn = 0;
  198626. maxChansIn = 0;
  198627. unsigned int dummy = 0;
  198628. getDeviceProperties (inputId, dummy, dummy, minChansIn, maxChansIn, sampleRates);
  198629. getDeviceProperties (outputId, minChansOut, maxChansOut, dummy, dummy, sampleRates);
  198630. unsigned int i;
  198631. for (i = 0; i < maxChansOut; ++i)
  198632. channelNamesOut.add (T("channel ") + String ((int) i + 1));
  198633. for (i = 0; i < maxChansIn; ++i)
  198634. channelNamesIn.add (T("channel ") + String ((int) i + 1));
  198635. }
  198636. };
  198637. class ALSAAudioIODevice : public AudioIODevice
  198638. {
  198639. public:
  198640. ALSAAudioIODevice (const String& deviceName,
  198641. const String& inputId_,
  198642. const String& outputId_)
  198643. : AudioIODevice (deviceName, T("ALSA")),
  198644. inputId (inputId_),
  198645. outputId (outputId_),
  198646. isOpen_ (false),
  198647. isStarted (false),
  198648. internal (0)
  198649. {
  198650. internal = new ALSAThread (inputId, outputId);
  198651. }
  198652. ~ALSAAudioIODevice()
  198653. {
  198654. delete internal;
  198655. }
  198656. const StringArray getOutputChannelNames()
  198657. {
  198658. return internal->channelNamesOut;
  198659. }
  198660. const StringArray getInputChannelNames()
  198661. {
  198662. return internal->channelNamesIn;
  198663. }
  198664. int getNumSampleRates()
  198665. {
  198666. return internal->sampleRates.size();
  198667. }
  198668. double getSampleRate (int index)
  198669. {
  198670. return internal->sampleRates [index];
  198671. }
  198672. int getNumBufferSizesAvailable()
  198673. {
  198674. return 50;
  198675. }
  198676. int getBufferSizeSamples (int index)
  198677. {
  198678. int n = 16;
  198679. for (int i = 0; i < index; ++i)
  198680. n += n < 64 ? 16
  198681. : (n < 512 ? 32
  198682. : (n < 1024 ? 64
  198683. : (n < 2048 ? 128 : 256)));
  198684. return n;
  198685. }
  198686. int getDefaultBufferSize()
  198687. {
  198688. return 512;
  198689. }
  198690. const String open (const BitArray& inputChannels,
  198691. const BitArray& outputChannels,
  198692. double sampleRate,
  198693. int bufferSizeSamples)
  198694. {
  198695. close();
  198696. if (bufferSizeSamples <= 0)
  198697. bufferSizeSamples = getDefaultBufferSize();
  198698. if (sampleRate <= 0)
  198699. {
  198700. for (int i = 0; i < getNumSampleRates(); ++i)
  198701. {
  198702. if (getSampleRate (i) >= 44100)
  198703. {
  198704. sampleRate = getSampleRate (i);
  198705. break;
  198706. }
  198707. }
  198708. }
  198709. internal->open (inputChannels, outputChannels,
  198710. sampleRate, bufferSizeSamples);
  198711. isOpen_ = internal->error.isEmpty();
  198712. return internal->error;
  198713. }
  198714. void close()
  198715. {
  198716. stop();
  198717. internal->close();
  198718. isOpen_ = false;
  198719. }
  198720. bool isOpen()
  198721. {
  198722. return isOpen_;
  198723. }
  198724. int getCurrentBufferSizeSamples()
  198725. {
  198726. return internal->bufferSize;
  198727. }
  198728. double getCurrentSampleRate()
  198729. {
  198730. return internal->sampleRate;
  198731. }
  198732. int getCurrentBitDepth()
  198733. {
  198734. return internal->getBitDepth();
  198735. }
  198736. const BitArray getActiveOutputChannels() const
  198737. {
  198738. return internal->currentOutputChans;
  198739. }
  198740. const BitArray getActiveInputChannels() const
  198741. {
  198742. return internal->currentInputChans;
  198743. }
  198744. int getOutputLatencyInSamples()
  198745. {
  198746. return 0;
  198747. }
  198748. int getInputLatencyInSamples()
  198749. {
  198750. return 0;
  198751. }
  198752. void start (AudioIODeviceCallback* callback)
  198753. {
  198754. if (! isOpen_)
  198755. callback = 0;
  198756. internal->setCallback (callback);
  198757. if (callback != 0)
  198758. callback->audioDeviceAboutToStart (this);
  198759. isStarted = (callback != 0);
  198760. }
  198761. void stop()
  198762. {
  198763. AudioIODeviceCallback* const oldCallback = internal->callback;
  198764. start (0);
  198765. if (oldCallback != 0)
  198766. oldCallback->audioDeviceStopped();
  198767. }
  198768. bool isPlaying()
  198769. {
  198770. return isStarted && internal->error.isEmpty();
  198771. }
  198772. const String getLastError()
  198773. {
  198774. return internal->error;
  198775. }
  198776. String inputId, outputId;
  198777. private:
  198778. bool isOpen_, isStarted;
  198779. ALSAThread* internal;
  198780. };
  198781. class ALSAAudioIODeviceType : public AudioIODeviceType
  198782. {
  198783. public:
  198784. ALSAAudioIODeviceType()
  198785. : AudioIODeviceType (T("ALSA")),
  198786. hasScanned (false)
  198787. {
  198788. }
  198789. ~ALSAAudioIODeviceType()
  198790. {
  198791. }
  198792. void scanForDevices()
  198793. {
  198794. if (hasScanned)
  198795. return;
  198796. hasScanned = true;
  198797. inputNames.clear();
  198798. inputIds.clear();
  198799. outputNames.clear();
  198800. outputIds.clear();
  198801. snd_ctl_t* handle;
  198802. snd_ctl_card_info_t* info;
  198803. snd_ctl_card_info_alloca (&info);
  198804. int cardNum = -1;
  198805. while (outputIds.size() + inputIds.size() <= 32)
  198806. {
  198807. snd_card_next (&cardNum);
  198808. if (cardNum < 0)
  198809. break;
  198810. if (snd_ctl_open (&handle, ("hw:" + String (cardNum)).toUTF8(), SND_CTL_NONBLOCK) >= 0)
  198811. {
  198812. if (snd_ctl_card_info (handle, info) >= 0)
  198813. {
  198814. String cardId (snd_ctl_card_info_get_id (info));
  198815. if (cardId.removeCharacters (T("0123456789")).isEmpty())
  198816. cardId = String (cardNum);
  198817. int device = -1;
  198818. for (;;)
  198819. {
  198820. if (snd_ctl_pcm_next_device (handle, &device) < 0 || device < 0)
  198821. break;
  198822. String id, name;
  198823. id << "hw:" << cardId << ',' << device;
  198824. bool isInput, isOutput;
  198825. if (testDevice (id, isInput, isOutput))
  198826. {
  198827. name << snd_ctl_card_info_get_name (info);
  198828. if (name.isEmpty())
  198829. name = id;
  198830. if (isInput)
  198831. {
  198832. inputNames.add (name);
  198833. inputIds.add (id);
  198834. }
  198835. if (isOutput)
  198836. {
  198837. outputNames.add (name);
  198838. outputIds.add (id);
  198839. }
  198840. }
  198841. }
  198842. }
  198843. snd_ctl_close (handle);
  198844. }
  198845. }
  198846. inputNames.appendNumbersToDuplicates (false, true);
  198847. outputNames.appendNumbersToDuplicates (false, true);
  198848. }
  198849. const StringArray getDeviceNames (const bool wantInputNames) const
  198850. {
  198851. jassert (hasScanned); // need to call scanForDevices() before doing this
  198852. return wantInputNames ? inputNames : outputNames;
  198853. }
  198854. int getDefaultDeviceIndex (const bool forInput) const
  198855. {
  198856. jassert (hasScanned); // need to call scanForDevices() before doing this
  198857. return 0;
  198858. }
  198859. bool hasSeparateInputsAndOutputs() const { return true; }
  198860. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  198861. {
  198862. jassert (hasScanned); // need to call scanForDevices() before doing this
  198863. ALSAAudioIODevice* const d = dynamic_cast <ALSAAudioIODevice*> (device);
  198864. if (d == 0)
  198865. return -1;
  198866. return asInput ? inputIds.indexOf (d->inputId)
  198867. : outputIds.indexOf (d->outputId);
  198868. }
  198869. AudioIODevice* createDevice (const String& outputDeviceName,
  198870. const String& inputDeviceName)
  198871. {
  198872. jassert (hasScanned); // need to call scanForDevices() before doing this
  198873. const int inputIndex = inputNames.indexOf (inputDeviceName);
  198874. const int outputIndex = outputNames.indexOf (outputDeviceName);
  198875. String deviceName (outputIndex >= 0 ? outputDeviceName
  198876. : inputDeviceName);
  198877. if (inputIndex >= 0 || outputIndex >= 0)
  198878. return new ALSAAudioIODevice (deviceName,
  198879. inputIds [inputIndex],
  198880. outputIds [outputIndex]);
  198881. return 0;
  198882. }
  198883. juce_UseDebuggingNewOperator
  198884. private:
  198885. StringArray inputNames, outputNames, inputIds, outputIds;
  198886. bool hasScanned;
  198887. static bool testDevice (const String& id, bool& isInput, bool& isOutput)
  198888. {
  198889. unsigned int minChansOut = 0, maxChansOut = 0;
  198890. unsigned int minChansIn = 0, maxChansIn = 0;
  198891. Array <int> rates;
  198892. getDeviceProperties (id, minChansOut, maxChansOut, minChansIn, maxChansIn, rates);
  198893. DBG (T("ALSA device: ") + id
  198894. + T(" outs=") + String ((int) minChansOut) + T("-") + String ((int) maxChansOut)
  198895. + T(" ins=") + String ((int) minChansIn) + T("-") + String ((int) maxChansIn)
  198896. + T(" rates=") + String (rates.size()));
  198897. isInput = maxChansIn > 0;
  198898. isOutput = maxChansOut > 0;
  198899. return (isInput || isOutput) && rates.size() > 0;
  198900. }
  198901. ALSAAudioIODeviceType (const ALSAAudioIODeviceType&);
  198902. ALSAAudioIODeviceType& operator= (const ALSAAudioIODeviceType&);
  198903. };
  198904. AudioIODeviceType* juce_createAudioIODeviceType_ALSA()
  198905. {
  198906. return new ALSAAudioIODeviceType();
  198907. }
  198908. #endif
  198909. /*** End of inlined file: juce_linux_Audio.cpp ***/
  198910. /*** Start of inlined file: juce_linux_JackAudio.cpp ***/
  198911. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  198912. // compiled on its own).
  198913. #ifdef JUCE_INCLUDED_FILE
  198914. #if JUCE_JACK
  198915. static void* juce_libjack_handle = 0;
  198916. void* juce_load_jack_function (const char* const name)
  198917. {
  198918. if (juce_libjack_handle == 0)
  198919. return 0;
  198920. return dlsym (juce_libjack_handle, name);
  198921. }
  198922. #define JUCE_DECL_JACK_FUNCTION(return_type, fn_name, argument_types, arguments) \
  198923. typedef return_type (*fn_name##_ptr_t)argument_types; \
  198924. return_type fn_name argument_types { \
  198925. static fn_name##_ptr_t fn = 0; \
  198926. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198927. if (fn) return (*fn)arguments; \
  198928. else return 0; \
  198929. }
  198930. #define JUCE_DECL_VOID_JACK_FUNCTION(fn_name, argument_types, arguments) \
  198931. typedef void (*fn_name##_ptr_t)argument_types; \
  198932. void fn_name argument_types { \
  198933. static fn_name##_ptr_t fn = 0; \
  198934. if (fn == 0) { fn = (fn_name##_ptr_t)juce_load_jack_function(#fn_name); } \
  198935. if (fn) (*fn)arguments; \
  198936. }
  198937. 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));
  198938. JUCE_DECL_JACK_FUNCTION (int, jack_client_close, (jack_client_t *client), (client));
  198939. JUCE_DECL_JACK_FUNCTION (int, jack_activate, (jack_client_t* client), (client));
  198940. JUCE_DECL_JACK_FUNCTION (int, jack_deactivate, (jack_client_t* client), (client));
  198941. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_buffer_size, (jack_client_t* client), (client));
  198942. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_get_sample_rate, (jack_client_t* client), (client));
  198943. JUCE_DECL_VOID_JACK_FUNCTION (jack_on_shutdown, (jack_client_t* client, void (*function)(void* arg), void* arg), (client, function, arg));
  198944. JUCE_DECL_JACK_FUNCTION (void* , jack_port_get_buffer, (jack_port_t* port, jack_nframes_t nframes), (port, nframes));
  198945. JUCE_DECL_JACK_FUNCTION (jack_nframes_t, jack_port_get_total_latency, (jack_client_t* client, jack_port_t* port), (client, port));
  198946. 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));
  198947. JUCE_DECL_VOID_JACK_FUNCTION (jack_set_error_function, (void (*func)(const char*)), (func));
  198948. JUCE_DECL_JACK_FUNCTION (int, jack_set_process_callback, (jack_client_t* client, JackProcessCallback process_callback, void* arg), (client, process_callback, arg));
  198949. 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));
  198950. JUCE_DECL_JACK_FUNCTION (int, jack_connect, (jack_client_t* client, const char* source_port, const char* destination_port), (client, source_port, destination_port));
  198951. JUCE_DECL_JACK_FUNCTION (const char*, jack_port_name, (const jack_port_t* port), (port));
  198952. JUCE_DECL_JACK_FUNCTION (int, jack_set_port_connect_callback, (jack_client_t* client, JackPortConnectCallback connect_callback, void* arg), (client, connect_callback, arg));
  198953. JUCE_DECL_JACK_FUNCTION (jack_port_t* , jack_port_by_id, (jack_client_t* client, jack_port_id_t port_id), (client, port_id));
  198954. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected, (const jack_port_t* port), (port));
  198955. JUCE_DECL_JACK_FUNCTION (int, jack_port_connected_to, (const jack_port_t* port, const char* port_name), (port, port_name));
  198956. #if JUCE_DEBUG
  198957. #define JACK_LOGGING_ENABLED 1
  198958. #endif
  198959. #if JACK_LOGGING_ENABLED
  198960. static void jack_Log (const String& s)
  198961. {
  198962. std::cerr << s << std::endl;
  198963. }
  198964. static void dumpJackErrorMessage (const jack_status_t status) throw()
  198965. {
  198966. if (status & JackServerFailed || status & JackServerError)
  198967. jack_Log ("Unable to connect to JACK server");
  198968. if (status & JackVersionError)
  198969. jack_Log ("Client's protocol version does not match");
  198970. if (status & JackInvalidOption)
  198971. jack_Log ("The operation contained an invalid or unsupported option");
  198972. if (status & JackNameNotUnique)
  198973. jack_Log ("The desired client name was not unique");
  198974. if (status & JackNoSuchClient)
  198975. jack_Log ("Requested client does not exist");
  198976. if (status & JackInitFailure)
  198977. jack_Log ("Unable to initialize client");
  198978. }
  198979. #else
  198980. #define dumpJackErrorMessage(a) {}
  198981. #define jack_Log(...) {}
  198982. #endif
  198983. #ifndef JUCE_JACK_CLIENT_NAME
  198984. #define JUCE_JACK_CLIENT_NAME "JuceJack"
  198985. #endif
  198986. class JackAudioIODevice : public AudioIODevice
  198987. {
  198988. public:
  198989. JackAudioIODevice (const String& deviceName,
  198990. const String& inputId_,
  198991. const String& outputId_)
  198992. : AudioIODevice (deviceName, T("JACK")),
  198993. inputId (inputId_),
  198994. outputId (outputId_),
  198995. isOpen_ (false),
  198996. callback (0),
  198997. totalNumberOfInputChannels (0),
  198998. totalNumberOfOutputChannels (0)
  198999. {
  199000. jassert (deviceName.isNotEmpty());
  199001. jack_status_t status;
  199002. client = JUCE_NAMESPACE::jack_client_open (JUCE_JACK_CLIENT_NAME, JackNoStartServer, &status);
  199003. if (client == 0)
  199004. {
  199005. dumpJackErrorMessage (status);
  199006. }
  199007. else
  199008. {
  199009. JUCE_NAMESPACE::jack_set_error_function (errorCallback);
  199010. // open input ports
  199011. const StringArray inputChannels (getInputChannelNames());
  199012. for (int i = 0; i < inputChannels.size(); i++)
  199013. {
  199014. String inputName;
  199015. inputName << "in_" << ++totalNumberOfInputChannels;
  199016. inputPorts.add (JUCE_NAMESPACE::jack_port_register (client, inputName.toUTF8(),
  199017. JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0));
  199018. }
  199019. // open output ports
  199020. const StringArray outputChannels (getOutputChannelNames());
  199021. for (int i = 0; i < outputChannels.size (); i++)
  199022. {
  199023. String outputName;
  199024. outputName << "out_" << ++totalNumberOfOutputChannels;
  199025. outputPorts.add (JUCE_NAMESPACE::jack_port_register (client, outputName.toUTF8(),
  199026. JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0));
  199027. }
  199028. inChans.calloc (totalNumberOfInputChannels + 2);
  199029. outChans.calloc (totalNumberOfOutputChannels + 2);
  199030. }
  199031. }
  199032. ~JackAudioIODevice()
  199033. {
  199034. close();
  199035. if (client != 0)
  199036. {
  199037. JUCE_NAMESPACE::jack_client_close (client);
  199038. client = 0;
  199039. }
  199040. }
  199041. const StringArray getChannelNames (bool forInput) const
  199042. {
  199043. StringArray names;
  199044. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */
  199045. forInput ? JackPortIsInput : JackPortIsOutput);
  199046. if (ports != 0)
  199047. {
  199048. int j = 0;
  199049. while (ports[j] != 0)
  199050. {
  199051. const String portName (ports [j++]);
  199052. if (portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199053. names.add (portName.fromFirstOccurrenceOf (T(":"), false, false));
  199054. }
  199055. free (ports);
  199056. }
  199057. return names;
  199058. }
  199059. const StringArray getOutputChannelNames() { return getChannelNames (false); }
  199060. const StringArray getInputChannelNames() { return getChannelNames (true); }
  199061. int getNumSampleRates() { return client != 0 ? 1 : 0; }
  199062. double getSampleRate (int index) { return client != 0 ? JUCE_NAMESPACE::jack_get_sample_rate (client) : 0; }
  199063. int getNumBufferSizesAvailable() { return client != 0 ? 1 : 0; }
  199064. int getBufferSizeSamples (int index) { return getDefaultBufferSize(); }
  199065. int getDefaultBufferSize() { return client != 0 ? JUCE_NAMESPACE::jack_get_buffer_size (client) : 0; }
  199066. const String open (const BitArray& inputChannels, const BitArray& outputChannels,
  199067. double sampleRate, int bufferSizeSamples)
  199068. {
  199069. if (client == 0)
  199070. {
  199071. lastError = T("No JACK client running");
  199072. return lastError;
  199073. }
  199074. lastError = String::empty;
  199075. close();
  199076. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, this);
  199077. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, this);
  199078. JUCE_NAMESPACE::jack_activate (client);
  199079. isOpen_ = true;
  199080. if (! inputChannels.isEmpty())
  199081. {
  199082. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199083. if (ports != 0)
  199084. {
  199085. const int numInputChannels = inputChannels.getHighestBit () + 1;
  199086. for (int i = 0; i < numInputChannels; ++i)
  199087. {
  199088. const String portName (ports[i]);
  199089. if (inputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199090. {
  199091. int error = JUCE_NAMESPACE::jack_connect (client, ports[i], JUCE_NAMESPACE::jack_port_name ((jack_port_t*) inputPorts[i]));
  199092. if (error != 0)
  199093. jack_Log ("Cannot connect input port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  199094. }
  199095. }
  199096. free (ports);
  199097. }
  199098. }
  199099. if (! outputChannels.isEmpty())
  199100. {
  199101. const char** const ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199102. if (ports != 0)
  199103. {
  199104. const int numOutputChannels = outputChannels.getHighestBit () + 1;
  199105. for (int i = 0; i < numOutputChannels; ++i)
  199106. {
  199107. const String portName (ports[i]);
  199108. if (outputChannels[i] && portName.upToFirstOccurrenceOf (T(":"), false, false) == getName())
  199109. {
  199110. int error = JUCE_NAMESPACE::jack_connect (client, JUCE_NAMESPACE::jack_port_name ((jack_port_t*) outputPorts[i]), ports[i]);
  199111. if (error != 0)
  199112. jack_Log ("Cannot connect output port " + String (i) + " (" + String (ports[i]) + "), error " + String (error));
  199113. }
  199114. }
  199115. free (ports);
  199116. }
  199117. }
  199118. return lastError;
  199119. }
  199120. void close()
  199121. {
  199122. stop();
  199123. if (client != 0)
  199124. {
  199125. JUCE_NAMESPACE::jack_deactivate (client);
  199126. JUCE_NAMESPACE::jack_set_process_callback (client, processCallback, 0);
  199127. JUCE_NAMESPACE::jack_on_shutdown (client, shutdownCallback, 0);
  199128. }
  199129. isOpen_ = false;
  199130. }
  199131. void start (AudioIODeviceCallback* newCallback)
  199132. {
  199133. if (isOpen_ && newCallback != callback)
  199134. {
  199135. if (newCallback != 0)
  199136. newCallback->audioDeviceAboutToStart (this);
  199137. AudioIODeviceCallback* const oldCallback = callback;
  199138. {
  199139. const ScopedLock sl (callbackLock);
  199140. callback = newCallback;
  199141. }
  199142. if (oldCallback != 0)
  199143. oldCallback->audioDeviceStopped();
  199144. }
  199145. }
  199146. void stop()
  199147. {
  199148. start (0);
  199149. }
  199150. bool isOpen() { return isOpen_; }
  199151. bool isPlaying() { return callback != 0; }
  199152. int getCurrentBufferSizeSamples() { return getBufferSizeSamples (0); }
  199153. double getCurrentSampleRate() { return getSampleRate (0); }
  199154. int getCurrentBitDepth() { return 32; }
  199155. const String getLastError() { return lastError; }
  199156. const BitArray getActiveOutputChannels() const
  199157. {
  199158. BitArray outputBits;
  199159. for (int i = 0; i < outputPorts.size(); i++)
  199160. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) outputPorts [i]))
  199161. outputBits.setBit (i);
  199162. return outputBits;
  199163. }
  199164. const BitArray getActiveInputChannels() const
  199165. {
  199166. BitArray inputBits;
  199167. for (int i = 0; i < inputPorts.size(); i++)
  199168. if (JUCE_NAMESPACE::jack_port_connected ((jack_port_t*) inputPorts [i]))
  199169. inputBits.setBit (i);
  199170. return inputBits;
  199171. }
  199172. int getOutputLatencyInSamples()
  199173. {
  199174. int latency = 0;
  199175. for (int i = 0; i < outputPorts.size(); i++)
  199176. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) outputPorts [i]));
  199177. return latency;
  199178. }
  199179. int getInputLatencyInSamples()
  199180. {
  199181. int latency = 0;
  199182. for (int i = 0; i < inputPorts.size(); i++)
  199183. latency = jmax (latency, (int) JUCE_NAMESPACE::jack_port_get_total_latency (client, (jack_port_t*) inputPorts [i]));
  199184. return latency;
  199185. }
  199186. String inputId, outputId;
  199187. private:
  199188. void process (const int numSamples)
  199189. {
  199190. int i, numActiveInChans = 0, numActiveOutChans = 0;
  199191. for (i = 0; i < totalNumberOfInputChannels; ++i)
  199192. {
  199193. jack_default_audio_sample_t* in
  199194. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) inputPorts.getUnchecked(i), numSamples);
  199195. if (in != 0)
  199196. inChans [numActiveInChans++] = (float*) in;
  199197. }
  199198. for (i = 0; i < totalNumberOfOutputChannels; ++i)
  199199. {
  199200. jack_default_audio_sample_t* out
  199201. = (jack_default_audio_sample_t*) JUCE_NAMESPACE::jack_port_get_buffer ((jack_port_t*) outputPorts.getUnchecked(i), numSamples);
  199202. if (out != 0)
  199203. outChans [numActiveOutChans++] = (float*) out;
  199204. }
  199205. const ScopedLock sl (callbackLock);
  199206. if (callback != 0)
  199207. {
  199208. callback->audioDeviceIOCallback ((const float**) inChans, numActiveInChans,
  199209. outChans, numActiveOutChans, numSamples);
  199210. }
  199211. else
  199212. {
  199213. for (i = 0; i < numActiveOutChans; ++i)
  199214. zeromem (outChans[i], sizeof (float) * numSamples);
  199215. }
  199216. }
  199217. static int processCallback (jack_nframes_t nframes, void* callbackArgument)
  199218. {
  199219. if (callbackArgument != 0)
  199220. ((JackAudioIODevice*) callbackArgument)->process (nframes);
  199221. return 0;
  199222. }
  199223. static void threadInitCallback (void* callbackArgument)
  199224. {
  199225. jack_Log ("JackAudioIODevice::initialise");
  199226. }
  199227. static void shutdownCallback (void* callbackArgument)
  199228. {
  199229. jack_Log ("JackAudioIODevice::shutdown");
  199230. JackAudioIODevice* device = (JackAudioIODevice*) callbackArgument;
  199231. if (device != 0)
  199232. {
  199233. device->client = 0;
  199234. device->close();
  199235. }
  199236. }
  199237. static void errorCallback (const char* msg)
  199238. {
  199239. jack_Log ("JackAudioIODevice::errorCallback " + String (msg));
  199240. }
  199241. bool isOpen_;
  199242. jack_client_t* client;
  199243. String lastError;
  199244. AudioIODeviceCallback* callback;
  199245. CriticalSection callbackLock;
  199246. HeapBlock <float*> inChans, outChans;
  199247. int totalNumberOfInputChannels;
  199248. int totalNumberOfOutputChannels;
  199249. VoidArray inputPorts, outputPorts;
  199250. };
  199251. class JackAudioIODeviceType : public AudioIODeviceType
  199252. {
  199253. public:
  199254. JackAudioIODeviceType()
  199255. : AudioIODeviceType (T("JACK")),
  199256. hasScanned (false)
  199257. {
  199258. }
  199259. ~JackAudioIODeviceType()
  199260. {
  199261. }
  199262. void scanForDevices()
  199263. {
  199264. hasScanned = true;
  199265. inputNames.clear();
  199266. inputIds.clear();
  199267. outputNames.clear();
  199268. outputIds.clear();
  199269. if (juce_libjack_handle == 0)
  199270. {
  199271. juce_libjack_handle = dlopen ("libjack.so", RTLD_LAZY);
  199272. if (juce_libjack_handle == 0)
  199273. return;
  199274. }
  199275. // open a dummy client
  199276. jack_status_t status;
  199277. jack_client_t* client = JUCE_NAMESPACE::jack_client_open ("JuceJackDummy", JackNoStartServer, &status);
  199278. if (client == 0)
  199279. {
  199280. dumpJackErrorMessage (status);
  199281. }
  199282. else
  199283. {
  199284. // scan for output devices
  199285. const char** ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsOutput);
  199286. if (ports != 0)
  199287. {
  199288. int j = 0;
  199289. while (ports[j] != 0)
  199290. {
  199291. String clientName (ports[j]);
  199292. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199293. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199294. && ! inputNames.contains (clientName))
  199295. {
  199296. inputNames.add (clientName);
  199297. inputIds.add (ports [j]);
  199298. }
  199299. ++j;
  199300. }
  199301. free (ports);
  199302. }
  199303. // scan for input devices
  199304. ports = JUCE_NAMESPACE::jack_get_ports (client, 0, 0, /* JackPortIsPhysical | */ JackPortIsInput);
  199305. if (ports != 0)
  199306. {
  199307. int j = 0;
  199308. while (ports[j] != 0)
  199309. {
  199310. String clientName (ports[j]);
  199311. clientName = clientName.upToFirstOccurrenceOf (T(":"), false, false);
  199312. if (clientName != String (JUCE_JACK_CLIENT_NAME)
  199313. && ! outputNames.contains (clientName))
  199314. {
  199315. outputNames.add (clientName);
  199316. outputIds.add (ports [j]);
  199317. }
  199318. ++j;
  199319. }
  199320. free (ports);
  199321. }
  199322. JUCE_NAMESPACE::jack_client_close (client);
  199323. }
  199324. }
  199325. const StringArray getDeviceNames (const bool wantInputNames) const
  199326. {
  199327. jassert (hasScanned); // need to call scanForDevices() before doing this
  199328. return wantInputNames ? inputNames : outputNames;
  199329. }
  199330. int getDefaultDeviceIndex (const bool forInput) const
  199331. {
  199332. jassert (hasScanned); // need to call scanForDevices() before doing this
  199333. return 0;
  199334. }
  199335. bool hasSeparateInputsAndOutputs() const { return true; }
  199336. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  199337. {
  199338. jassert (hasScanned); // need to call scanForDevices() before doing this
  199339. JackAudioIODevice* const d = dynamic_cast <JackAudioIODevice*> (device);
  199340. if (d == 0)
  199341. return -1;
  199342. return asInput ? inputIds.indexOf (d->inputId)
  199343. : outputIds.indexOf (d->outputId);
  199344. }
  199345. AudioIODevice* createDevice (const String& outputDeviceName,
  199346. const String& inputDeviceName)
  199347. {
  199348. jassert (hasScanned); // need to call scanForDevices() before doing this
  199349. const int inputIndex = inputNames.indexOf (inputDeviceName);
  199350. const int outputIndex = outputNames.indexOf (outputDeviceName);
  199351. if (inputIndex >= 0 || outputIndex >= 0)
  199352. return new JackAudioIODevice (outputIndex >= 0 ? outputDeviceName
  199353. : inputDeviceName,
  199354. inputIds [inputIndex],
  199355. outputIds [outputIndex]);
  199356. return 0;
  199357. }
  199358. juce_UseDebuggingNewOperator
  199359. private:
  199360. StringArray inputNames, outputNames, inputIds, outputIds;
  199361. bool hasScanned;
  199362. JackAudioIODeviceType (const JackAudioIODeviceType&);
  199363. JackAudioIODeviceType& operator= (const JackAudioIODeviceType&);
  199364. };
  199365. AudioIODeviceType* juce_createAudioIODeviceType_JACK()
  199366. {
  199367. return new JackAudioIODeviceType();
  199368. }
  199369. #else // if JACK is turned off..
  199370. AudioIODeviceType* juce_createAudioIODeviceType_JACK() { return 0; }
  199371. #endif
  199372. #endif
  199373. /*** End of inlined file: juce_linux_JackAudio.cpp ***/
  199374. /*** Start of inlined file: juce_linux_Midi.cpp ***/
  199375. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199376. // compiled on its own).
  199377. #if JUCE_INCLUDED_FILE
  199378. #if JUCE_ALSA
  199379. static snd_seq_t* iterateDevices (const bool forInput,
  199380. StringArray& deviceNamesFound,
  199381. const int deviceIndexToOpen)
  199382. {
  199383. snd_seq_t* returnedHandle = 0;
  199384. snd_seq_t* seqHandle;
  199385. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199386. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199387. {
  199388. snd_seq_system_info_t* systemInfo;
  199389. snd_seq_client_info_t* clientInfo;
  199390. if (snd_seq_system_info_malloc (&systemInfo) == 0)
  199391. {
  199392. if (snd_seq_system_info (seqHandle, systemInfo) == 0
  199393. && snd_seq_client_info_malloc (&clientInfo) == 0)
  199394. {
  199395. int numClients = snd_seq_system_info_get_cur_clients (systemInfo);
  199396. while (--numClients >= 0 && returnedHandle == 0)
  199397. {
  199398. if (snd_seq_query_next_client (seqHandle, clientInfo) == 0)
  199399. {
  199400. snd_seq_port_info_t* portInfo;
  199401. if (snd_seq_port_info_malloc (&portInfo) == 0)
  199402. {
  199403. int numPorts = snd_seq_client_info_get_num_ports (clientInfo);
  199404. const int client = snd_seq_client_info_get_client (clientInfo);
  199405. snd_seq_port_info_set_client (portInfo, client);
  199406. snd_seq_port_info_set_port (portInfo, -1);
  199407. while (--numPorts >= 0)
  199408. {
  199409. if (snd_seq_query_next_port (seqHandle, portInfo) == 0
  199410. && (snd_seq_port_info_get_capability (portInfo)
  199411. & (forInput ? SND_SEQ_PORT_CAP_READ
  199412. : SND_SEQ_PORT_CAP_WRITE)) != 0)
  199413. {
  199414. deviceNamesFound.add (snd_seq_client_info_get_name (clientInfo));
  199415. if (deviceNamesFound.size() == deviceIndexToOpen + 1)
  199416. {
  199417. const int sourcePort = snd_seq_port_info_get_port (portInfo);
  199418. const int sourceClient = snd_seq_client_info_get_client (clientInfo);
  199419. if (sourcePort != -1)
  199420. {
  199421. snd_seq_set_client_name (seqHandle,
  199422. forInput ? "Juce Midi Input"
  199423. : "Juce Midi Output");
  199424. const int portId
  199425. = snd_seq_create_simple_port (seqHandle,
  199426. forInput ? "Juce Midi In Port"
  199427. : "Juce Midi Out Port",
  199428. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199429. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199430. SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199431. snd_seq_connect_from (seqHandle, portId, sourceClient, sourcePort);
  199432. returnedHandle = seqHandle;
  199433. }
  199434. }
  199435. }
  199436. }
  199437. snd_seq_port_info_free (portInfo);
  199438. }
  199439. }
  199440. }
  199441. snd_seq_client_info_free (clientInfo);
  199442. }
  199443. snd_seq_system_info_free (systemInfo);
  199444. }
  199445. if (returnedHandle == 0)
  199446. snd_seq_close (seqHandle);
  199447. }
  199448. deviceNamesFound.appendNumbersToDuplicates (true, true);
  199449. return returnedHandle;
  199450. }
  199451. static snd_seq_t* createDevice (const bool forInput,
  199452. const String& deviceNameToOpen)
  199453. {
  199454. snd_seq_t* seqHandle = 0;
  199455. if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT
  199456. : SND_SEQ_OPEN_OUTPUT, 0) == 0)
  199457. {
  199458. snd_seq_set_client_name (seqHandle,
  199459. (deviceNameToOpen + (forInput ? " Input" : " Output")).toCString());
  199460. const int portId
  199461. = snd_seq_create_simple_port (seqHandle,
  199462. forInput ? "in"
  199463. : "out",
  199464. forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE)
  199465. : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ),
  199466. forInput ? SND_SEQ_PORT_TYPE_APPLICATION
  199467. : SND_SEQ_PORT_TYPE_MIDI_GENERIC);
  199468. if (portId < 0)
  199469. {
  199470. snd_seq_close (seqHandle);
  199471. seqHandle = 0;
  199472. }
  199473. }
  199474. return seqHandle;
  199475. }
  199476. class MidiOutputDevice
  199477. {
  199478. public:
  199479. MidiOutputDevice (MidiOutput* const midiOutput_,
  199480. snd_seq_t* const seqHandle_)
  199481. :
  199482. midiOutput (midiOutput_),
  199483. seqHandle (seqHandle_),
  199484. maxEventSize (16 * 1024)
  199485. {
  199486. jassert (seqHandle != 0 && midiOutput != 0);
  199487. snd_midi_event_new (maxEventSize, &midiParser);
  199488. }
  199489. ~MidiOutputDevice()
  199490. {
  199491. snd_midi_event_free (midiParser);
  199492. snd_seq_close (seqHandle);
  199493. }
  199494. void sendMessageNow (const MidiMessage& message)
  199495. {
  199496. if (message.getRawDataSize() > maxEventSize)
  199497. {
  199498. maxEventSize = message.getRawDataSize();
  199499. snd_midi_event_free (midiParser);
  199500. snd_midi_event_new (maxEventSize, &midiParser);
  199501. }
  199502. snd_seq_event_t event;
  199503. snd_seq_ev_clear (&event);
  199504. snd_midi_event_encode (midiParser,
  199505. message.getRawData(),
  199506. message.getRawDataSize(),
  199507. &event);
  199508. snd_midi_event_reset_encode (midiParser);
  199509. snd_seq_ev_set_source (&event, 0);
  199510. snd_seq_ev_set_subs (&event);
  199511. snd_seq_ev_set_direct (&event);
  199512. snd_seq_event_output (seqHandle, &event);
  199513. snd_seq_drain_output (seqHandle);
  199514. }
  199515. juce_UseDebuggingNewOperator
  199516. private:
  199517. MidiOutput* const midiOutput;
  199518. snd_seq_t* const seqHandle;
  199519. snd_midi_event_t* midiParser;
  199520. int maxEventSize;
  199521. };
  199522. const StringArray MidiOutput::getDevices()
  199523. {
  199524. StringArray devices;
  199525. iterateDevices (false, devices, -1);
  199526. return devices;
  199527. }
  199528. int MidiOutput::getDefaultDeviceIndex()
  199529. {
  199530. return 0;
  199531. }
  199532. MidiOutput* MidiOutput::openDevice (int deviceIndex)
  199533. {
  199534. MidiOutput* newDevice = 0;
  199535. StringArray devices;
  199536. snd_seq_t* const handle = iterateDevices (false, devices, deviceIndex);
  199537. if (handle != 0)
  199538. {
  199539. newDevice = new MidiOutput();
  199540. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199541. }
  199542. return newDevice;
  199543. }
  199544. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  199545. {
  199546. MidiOutput* newDevice = 0;
  199547. snd_seq_t* const handle = createDevice (false, deviceName);
  199548. if (handle != 0)
  199549. {
  199550. newDevice = new MidiOutput();
  199551. newDevice->internal = new MidiOutputDevice (newDevice, handle);
  199552. }
  199553. return newDevice;
  199554. }
  199555. MidiOutput::~MidiOutput()
  199556. {
  199557. MidiOutputDevice* const device = (MidiOutputDevice*) internal;
  199558. delete device;
  199559. }
  199560. void MidiOutput::reset()
  199561. {
  199562. }
  199563. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  199564. {
  199565. return false;
  199566. }
  199567. void MidiOutput::setVolume (float leftVol, float rightVol)
  199568. {
  199569. }
  199570. void MidiOutput::sendMessageNow (const MidiMessage& message)
  199571. {
  199572. ((MidiOutputDevice*) internal)->sendMessageNow (message);
  199573. }
  199574. class MidiInputThread : public Thread
  199575. {
  199576. public:
  199577. MidiInputThread (MidiInput* const midiInput_,
  199578. snd_seq_t* const seqHandle_,
  199579. MidiInputCallback* const callback_)
  199580. : Thread (T("Juce MIDI Input")),
  199581. midiInput (midiInput_),
  199582. seqHandle (seqHandle_),
  199583. callback (callback_)
  199584. {
  199585. jassert (seqHandle != 0 && callback != 0 && midiInput != 0);
  199586. }
  199587. ~MidiInputThread()
  199588. {
  199589. snd_seq_close (seqHandle);
  199590. }
  199591. void run()
  199592. {
  199593. const int maxEventSize = 16 * 1024;
  199594. snd_midi_event_t* midiParser;
  199595. if (snd_midi_event_new (maxEventSize, &midiParser) >= 0)
  199596. {
  199597. HeapBlock <uint8> buffer (maxEventSize);
  199598. const int numPfds = snd_seq_poll_descriptors_count (seqHandle, POLLIN);
  199599. struct pollfd* const pfd = (struct pollfd*) alloca (numPfds * sizeof (struct pollfd));
  199600. snd_seq_poll_descriptors (seqHandle, pfd, numPfds, POLLIN);
  199601. while (! threadShouldExit())
  199602. {
  199603. if (poll (pfd, numPfds, 500) > 0)
  199604. {
  199605. snd_seq_event_t* inputEvent = 0;
  199606. snd_seq_nonblock (seqHandle, 1);
  199607. do
  199608. {
  199609. if (snd_seq_event_input (seqHandle, &inputEvent) >= 0)
  199610. {
  199611. // xxx what about SYSEXes that are too big for the buffer?
  199612. const int numBytes = snd_midi_event_decode (midiParser, buffer, maxEventSize, inputEvent);
  199613. snd_midi_event_reset_decode (midiParser);
  199614. if (numBytes > 0)
  199615. {
  199616. const MidiMessage message ((const uint8*) buffer,
  199617. numBytes,
  199618. Time::getMillisecondCounter() * 0.001);
  199619. callback->handleIncomingMidiMessage (midiInput, message);
  199620. }
  199621. snd_seq_free_event (inputEvent);
  199622. }
  199623. }
  199624. while (snd_seq_event_input_pending (seqHandle, 0) > 0);
  199625. snd_seq_free_event (inputEvent);
  199626. }
  199627. }
  199628. snd_midi_event_free (midiParser);
  199629. }
  199630. };
  199631. juce_UseDebuggingNewOperator
  199632. private:
  199633. MidiInput* const midiInput;
  199634. snd_seq_t* const seqHandle;
  199635. MidiInputCallback* const callback;
  199636. };
  199637. MidiInput::MidiInput (const String& name_)
  199638. : name (name_),
  199639. internal (0)
  199640. {
  199641. }
  199642. MidiInput::~MidiInput()
  199643. {
  199644. stop();
  199645. MidiInputThread* const thread = (MidiInputThread*) internal;
  199646. delete thread;
  199647. }
  199648. void MidiInput::start()
  199649. {
  199650. ((MidiInputThread*) internal)->startThread();
  199651. }
  199652. void MidiInput::stop()
  199653. {
  199654. ((MidiInputThread*) internal)->stopThread (3000);
  199655. }
  199656. int MidiInput::getDefaultDeviceIndex()
  199657. {
  199658. return 0;
  199659. }
  199660. const StringArray MidiInput::getDevices()
  199661. {
  199662. StringArray devices;
  199663. iterateDevices (true, devices, -1);
  199664. return devices;
  199665. }
  199666. MidiInput* MidiInput::openDevice (int deviceIndex, MidiInputCallback* callback)
  199667. {
  199668. MidiInput* newDevice = 0;
  199669. StringArray devices;
  199670. snd_seq_t* const handle = iterateDevices (true, devices, deviceIndex);
  199671. if (handle != 0)
  199672. {
  199673. newDevice = new MidiInput (devices [deviceIndex]);
  199674. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199675. }
  199676. return newDevice;
  199677. }
  199678. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  199679. {
  199680. MidiInput* newDevice = 0;
  199681. snd_seq_t* const handle = createDevice (true, deviceName);
  199682. if (handle != 0)
  199683. {
  199684. newDevice = new MidiInput (deviceName);
  199685. newDevice->internal = new MidiInputThread (newDevice, handle, callback);
  199686. }
  199687. return newDevice;
  199688. }
  199689. #else
  199690. // (These are just stub functions if ALSA is unavailable...)
  199691. const StringArray MidiOutput::getDevices() { return StringArray(); }
  199692. int MidiOutput::getDefaultDeviceIndex() { return 0; }
  199693. MidiOutput* MidiOutput::openDevice (int) { return 0; }
  199694. MidiOutput* MidiOutput::createNewDevice (const String&) { return 0; }
  199695. MidiOutput::~MidiOutput() {}
  199696. void MidiOutput::reset() {}
  199697. bool MidiOutput::getVolume (float&, float&) { return false; }
  199698. void MidiOutput::setVolume (float, float) {}
  199699. void MidiOutput::sendMessageNow (const MidiMessage&) {}
  199700. MidiInput::MidiInput (const String& name_) : name (name_), internal (0) {}
  199701. MidiInput::~MidiInput() {}
  199702. void MidiInput::start() {}
  199703. void MidiInput::stop() {}
  199704. int MidiInput::getDefaultDeviceIndex() { return 0; }
  199705. const StringArray MidiInput::getDevices() { return StringArray(); }
  199706. MidiInput* MidiInput::openDevice (int, MidiInputCallback*) { return 0; }
  199707. MidiInput* MidiInput::createNewDevice (const String&, MidiInputCallback*) { return 0; }
  199708. #endif
  199709. #endif
  199710. /*** End of inlined file: juce_linux_Midi.cpp ***/
  199711. /*** Start of inlined file: juce_linux_AudioCDReader.cpp ***/
  199712. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199713. // compiled on its own).
  199714. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  199715. AudioCDReader::AudioCDReader()
  199716. : AudioFormatReader (0, T("CD Audio"))
  199717. {
  199718. }
  199719. const StringArray AudioCDReader::getAvailableCDNames()
  199720. {
  199721. StringArray names;
  199722. return names;
  199723. }
  199724. AudioCDReader* AudioCDReader::createReaderForCD (const int index)
  199725. {
  199726. return 0;
  199727. }
  199728. AudioCDReader::~AudioCDReader()
  199729. {
  199730. }
  199731. void AudioCDReader::refreshTrackLengths()
  199732. {
  199733. }
  199734. bool AudioCDReader::readSamples (int** destSamples, int numDestChannels, int startOffsetInDestBuffer,
  199735. int64 startSampleInFile, int numSamples)
  199736. {
  199737. return false;
  199738. }
  199739. bool AudioCDReader::isCDStillPresent() const
  199740. {
  199741. return false;
  199742. }
  199743. int AudioCDReader::getNumTracks() const
  199744. {
  199745. return 0;
  199746. }
  199747. int AudioCDReader::getPositionOfTrackStart (int trackNum) const
  199748. {
  199749. return 0;
  199750. }
  199751. bool AudioCDReader::isTrackAudio (int trackNum) const
  199752. {
  199753. return false;
  199754. }
  199755. void AudioCDReader::enableIndexScanning (bool b)
  199756. {
  199757. }
  199758. int AudioCDReader::getLastIndex() const
  199759. {
  199760. return 0;
  199761. }
  199762. const Array<int> AudioCDReader::findIndexesInTrack (const int trackNumber)
  199763. {
  199764. return Array<int>();
  199765. }
  199766. int AudioCDReader::getCDDBId()
  199767. {
  199768. return 0;
  199769. }
  199770. #endif
  199771. /*** End of inlined file: juce_linux_AudioCDReader.cpp ***/
  199772. /*** Start of inlined file: juce_linux_FileChooser.cpp ***/
  199773. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199774. // compiled on its own).
  199775. #if JUCE_INCLUDED_FILE
  199776. void FileChooser::showPlatformDialog (Array<File>& results,
  199777. const String& title,
  199778. const File& file,
  199779. const String& filters,
  199780. bool isDirectory,
  199781. bool selectsFiles,
  199782. bool isSave,
  199783. bool warnAboutOverwritingExistingFiles,
  199784. bool selectMultipleFiles,
  199785. FilePreviewComponent* previewComponent)
  199786. {
  199787. const tchar* const separator = T(":");
  199788. String command ("zenity --file-selection");
  199789. if (title.isNotEmpty())
  199790. command << " --title=\"" << title << "\"";
  199791. if (file != File::nonexistent)
  199792. command << " --filename=\"" << file.getFullPathName () << "\"";
  199793. if (isDirectory)
  199794. command << " --directory";
  199795. if (isSave)
  199796. command << " --save";
  199797. if (selectMultipleFiles)
  199798. command << " --multiple --separator=\"" << separator << "\"";
  199799. command << " 2>&1";
  199800. MemoryOutputStream result;
  199801. int status = -1;
  199802. FILE* stream = popen ((const char*) command.toUTF8(), "r");
  199803. if (stream != 0)
  199804. {
  199805. for (;;)
  199806. {
  199807. char buffer [1024];
  199808. const int bytesRead = fread (buffer, 1, sizeof (buffer), stream);
  199809. if (bytesRead <= 0)
  199810. break;
  199811. result.write (buffer, bytesRead);
  199812. }
  199813. status = pclose (stream);
  199814. }
  199815. if (status == 0)
  199816. {
  199817. String resultString (String::fromUTF8 ((const char*) result.getData(), result.getDataSize()));
  199818. StringArray tokens;
  199819. if (selectMultipleFiles)
  199820. tokens.addTokens (resultString, separator, 0);
  199821. else
  199822. tokens.add (resultString);
  199823. for (int i = 0; i < tokens.size(); i++)
  199824. results.add (File (tokens[i]));
  199825. return;
  199826. }
  199827. //xxx ain't got one!
  199828. jassertfalse
  199829. }
  199830. #endif
  199831. /*** End of inlined file: juce_linux_FileChooser.cpp ***/
  199832. /*** Start of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199833. // (This file gets included by juce_linux_NativeCode.cpp, rather than being
  199834. // compiled on its own).
  199835. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  199836. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  199837. : browser (0),
  199838. blankPageShown (false),
  199839. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  199840. {
  199841. setOpaque (true);
  199842. }
  199843. WebBrowserComponent::~WebBrowserComponent()
  199844. {
  199845. }
  199846. void WebBrowserComponent::goToURL (const String& url,
  199847. const StringArray* headers,
  199848. const MemoryBlock* postData)
  199849. {
  199850. lastURL = url;
  199851. lastHeaders.clear();
  199852. if (headers != 0)
  199853. lastHeaders = *headers;
  199854. lastPostData.setSize (0);
  199855. if (postData != 0)
  199856. lastPostData = *postData;
  199857. blankPageShown = false;
  199858. }
  199859. void WebBrowserComponent::stop()
  199860. {
  199861. }
  199862. void WebBrowserComponent::goBack()
  199863. {
  199864. lastURL = String::empty;
  199865. blankPageShown = false;
  199866. }
  199867. void WebBrowserComponent::goForward()
  199868. {
  199869. lastURL = String::empty;
  199870. }
  199871. void WebBrowserComponent::refresh()
  199872. {
  199873. }
  199874. void WebBrowserComponent::paint (Graphics& g)
  199875. {
  199876. g.fillAll (Colours::white);
  199877. }
  199878. void WebBrowserComponent::checkWindowAssociation()
  199879. {
  199880. }
  199881. void WebBrowserComponent::reloadLastURL()
  199882. {
  199883. if (lastURL.isNotEmpty())
  199884. {
  199885. goToURL (lastURL, &lastHeaders, &lastPostData);
  199886. lastURL = String::empty;
  199887. }
  199888. }
  199889. void WebBrowserComponent::parentHierarchyChanged()
  199890. {
  199891. checkWindowAssociation();
  199892. }
  199893. void WebBrowserComponent::resized()
  199894. {
  199895. }
  199896. void WebBrowserComponent::visibilityChanged()
  199897. {
  199898. checkWindowAssociation();
  199899. }
  199900. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  199901. {
  199902. return true;
  199903. }
  199904. #endif
  199905. /*** End of inlined file: juce_linux_WebBrowserComponent.cpp ***/
  199906. #endif
  199907. END_JUCE_NAMESPACE
  199908. /*** End of inlined file: juce_linux_NativeCode.cpp ***/
  199909. #endif
  199910. #if JUCE_MAC || JUCE_IPHONE
  199911. /*** Start of inlined file: juce_mac_NativeCode.mm ***/
  199912. BEGIN_JUCE_NAMESPACE
  199913. #undef Point
  199914. #define JUCE_INCLUDED_FILE 1
  199915. // Now include the actual code files..
  199916. /*** Start of inlined file: juce_mac_ObjCSuffix.h ***/
  199917. #ifndef JUCE_ObjCExtraSuffix
  199918. #define JUCE_ObjCExtraSuffix 3
  199919. #endif
  199920. #define appendMacro1(a, b, c, d, e) a ## _ ## b ## _ ## c ## _ ## d ## _ ## e
  199921. #define appendMacro2(a, b, c, d, e) appendMacro1(a, b, c, d, e)
  199922. #define MakeObjCClassName(rootName) appendMacro2 (rootName, JUCE_MAJOR_VERSION, JUCE_MINOR_VERSION, JUCE_BUILDNUMBER, JUCE_ObjCExtraSuffix)
  199923. /*** End of inlined file: juce_mac_ObjCSuffix.h ***/
  199924. /*** Start of inlined file: juce_mac_Strings.mm ***/
  199925. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  199926. // compiled on its own).
  199927. #if JUCE_INCLUDED_FILE
  199928. static const String nsStringToJuce (NSString* s)
  199929. {
  199930. return String::fromUTF8 ([s UTF8String]);
  199931. }
  199932. static NSString* juceStringToNS (const String& s)
  199933. {
  199934. return [NSString stringWithUTF8String: s.toUTF8()];
  199935. }
  199936. static const String convertUTF16ToString (const UniChar* utf16)
  199937. {
  199938. String s;
  199939. while (*utf16 != 0)
  199940. s += (juce_wchar) *utf16++;
  199941. return s;
  199942. }
  199943. const String PlatformUtilities::cfStringToJuceString (CFStringRef cfString)
  199944. {
  199945. String result;
  199946. if (cfString != 0)
  199947. {
  199948. CFRange range = { 0, CFStringGetLength (cfString) };
  199949. HeapBlock <UniChar> u (range.length + 1);
  199950. CFStringGetCharacters (cfString, range, u);
  199951. u[range.length] = 0;
  199952. result = convertUTF16ToString (u);
  199953. }
  199954. return result;
  199955. }
  199956. CFStringRef PlatformUtilities::juceStringToCFString (const String& s)
  199957. {
  199958. const int len = s.length();
  199959. const juce_wchar* t = (const juce_wchar*) s;
  199960. HeapBlock <UniChar> temp (len + 2);
  199961. for (int i = 0; i <= len; ++i)
  199962. temp[i] = t[i];
  199963. return CFStringCreateWithCharacters (kCFAllocatorDefault, temp, len);
  199964. }
  199965. const String PlatformUtilities::convertToPrecomposedUnicode (const String& s)
  199966. {
  199967. #if JUCE_IPHONE
  199968. const ScopedAutoReleasePool pool;
  199969. return nsStringToJuce ([juceStringToNS (s) precomposedStringWithCanonicalMapping]);
  199970. #else
  199971. UnicodeMapping map;
  199972. map.unicodeEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199973. kUnicodeNoSubset,
  199974. kTextEncodingDefaultFormat);
  199975. map.otherEncoding = CreateTextEncoding (kTextEncodingUnicodeDefault,
  199976. kUnicodeCanonicalCompVariant,
  199977. kTextEncodingDefaultFormat);
  199978. map.mappingVersion = kUnicodeUseLatestMapping;
  199979. UnicodeToTextInfo conversionInfo = 0;
  199980. String result;
  199981. if (CreateUnicodeToTextInfo (&map, &conversionInfo) == noErr)
  199982. {
  199983. const int len = s.length();
  199984. HeapBlock <UniChar> tempIn, tempOut;
  199985. tempIn.calloc (len + 2);
  199986. tempOut.calloc (len + 2);
  199987. for (int i = 0; i <= len; ++i)
  199988. tempIn[i] = s[i];
  199989. ByteCount bytesRead = 0;
  199990. ByteCount outputBufferSize = 0;
  199991. if (ConvertFromUnicodeToText (conversionInfo,
  199992. len * sizeof (UniChar), tempIn,
  199993. kUnicodeDefaultDirectionMask,
  199994. 0, 0, 0, 0,
  199995. len * sizeof (UniChar), &bytesRead,
  199996. &outputBufferSize, tempOut) == noErr)
  199997. {
  199998. result.preallocateStorage (bytesRead / sizeof (UniChar) + 2);
  199999. tchar* t = const_cast <tchar*> ((const tchar*) result);
  200000. unsigned int i;
  200001. for (i = 0; i < bytesRead / sizeof (UniChar); ++i)
  200002. t[i] = (tchar) tempOut[i];
  200003. t[i] = 0;
  200004. }
  200005. DisposeUnicodeToTextInfo (&conversionInfo);
  200006. }
  200007. return result;
  200008. #endif
  200009. }
  200010. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  200011. void SystemClipboard::copyTextToClipboard (const String& text) throw()
  200012. {
  200013. #if JUCE_IPHONE
  200014. [[UIPasteboard generalPasteboard] setValue: juceStringToNS (text)
  200015. forPasteboardType: @"public.text"];
  200016. #else
  200017. [[NSPasteboard generalPasteboard] declareTypes: [NSArray arrayWithObject: NSStringPboardType]
  200018. owner: nil];
  200019. [[NSPasteboard generalPasteboard] setString: juceStringToNS (text)
  200020. forType: NSStringPboardType];
  200021. #endif
  200022. }
  200023. const String SystemClipboard::getTextFromClipboard() throw()
  200024. {
  200025. #if JUCE_IPHONE
  200026. NSString* text = [[UIPasteboard generalPasteboard] valueForPasteboardType: @"public.text"];
  200027. #else
  200028. NSString* text = [[NSPasteboard generalPasteboard] stringForType: NSStringPboardType];
  200029. #endif
  200030. return text == 0 ? String::empty
  200031. : nsStringToJuce (text);
  200032. }
  200033. #endif
  200034. #endif
  200035. /*** End of inlined file: juce_mac_Strings.mm ***/
  200036. /*** Start of inlined file: juce_mac_SystemStats.mm ***/
  200037. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200038. // compiled on its own).
  200039. #if JUCE_INCLUDED_FILE
  200040. static int64 highResTimerFrequency = 0;
  200041. static double highResTimerToMillisecRatio = 0;
  200042. #if JUCE_INTEL
  200043. static void juce_getCpuVendor (char* const v) throw()
  200044. {
  200045. int vendor[4];
  200046. zerostruct (vendor);
  200047. int dummy = 0;
  200048. asm ("mov %%ebx, %%esi \n\t"
  200049. "cpuid \n\t"
  200050. "xchg %%esi, %%ebx"
  200051. : "=a" (dummy), "=S" (vendor[0]), "=c" (vendor[2]), "=d" (vendor[1]) : "a" (0));
  200052. memcpy (v, vendor, 16);
  200053. }
  200054. static unsigned int getCPUIDWord (unsigned int& familyModel, unsigned int& extFeatures)
  200055. {
  200056. unsigned int cpu = 0;
  200057. unsigned int ext = 0;
  200058. unsigned int family = 0;
  200059. unsigned int dummy = 0;
  200060. asm ("mov %%ebx, %%esi \n\t"
  200061. "cpuid \n\t"
  200062. "xchg %%esi, %%ebx"
  200063. : "=a" (family), "=S" (ext), "=c" (dummy), "=d" (cpu) : "a" (1));
  200064. familyModel = family;
  200065. extFeatures = ext;
  200066. return cpu;
  200067. }
  200068. struct CPUFlags
  200069. {
  200070. bool hasMMX : 1;
  200071. bool hasSSE : 1;
  200072. bool hasSSE2 : 1;
  200073. bool has3DNow : 1;
  200074. };
  200075. static CPUFlags cpuFlags;
  200076. #endif
  200077. void SystemStats::initialiseStats() throw()
  200078. {
  200079. static bool initialised = false;
  200080. if (! initialised)
  200081. {
  200082. initialised = true;
  200083. #if JUCE_MAC
  200084. // extremely annoying: adding this line stops the apple menu items from working. Of
  200085. // course, not adding it means that carbon windows (e.g. in plugins) won't get
  200086. // any events.
  200087. //NSApplicationLoad();
  200088. [NSApplication sharedApplication];
  200089. #endif
  200090. #if JUCE_INTEL
  200091. {
  200092. unsigned int familyModel, extFeatures;
  200093. const unsigned int features = getCPUIDWord (familyModel, extFeatures);
  200094. cpuFlags.hasMMX = ((features & (1 << 23)) != 0);
  200095. cpuFlags.hasSSE = ((features & (1 << 25)) != 0);
  200096. cpuFlags.hasSSE2 = ((features & (1 << 26)) != 0);
  200097. cpuFlags.has3DNow = ((extFeatures & (1 << 31)) != 0);
  200098. }
  200099. #endif
  200100. mach_timebase_info_data_t timebase;
  200101. (void) mach_timebase_info (&timebase);
  200102. highResTimerFrequency = (int64) (1.0e9 * timebase.denom / timebase.numer);
  200103. highResTimerToMillisecRatio = timebase.numer / (1.0e6 * timebase.denom);
  200104. String s (SystemStats::getJUCEVersion());
  200105. rlimit lim;
  200106. getrlimit (RLIMIT_NOFILE, &lim);
  200107. lim.rlim_cur = lim.rlim_max = RLIM_INFINITY;
  200108. setrlimit (RLIMIT_NOFILE, &lim);
  200109. }
  200110. }
  200111. SystemStats::OperatingSystemType SystemStats::getOperatingSystemType() throw()
  200112. {
  200113. return MacOSX;
  200114. }
  200115. const String SystemStats::getOperatingSystemName() throw()
  200116. {
  200117. return T("Mac OS X");
  200118. }
  200119. bool SystemStats::isOperatingSystem64Bit() throw()
  200120. {
  200121. #if JUCE_64BIT
  200122. return true;
  200123. #else
  200124. //xxx not sure how to find this out?..
  200125. return false;
  200126. #endif
  200127. }
  200128. int SystemStats::getMemorySizeInMegabytes() throw()
  200129. {
  200130. uint64 mem = 0;
  200131. size_t memSize = sizeof (mem);
  200132. int mib[] = { CTL_HW, HW_MEMSIZE };
  200133. sysctl (mib, 2, &mem, &memSize, 0, 0);
  200134. return (int) (mem / (1024 * 1024));
  200135. }
  200136. bool SystemStats::hasMMX() throw()
  200137. {
  200138. #if JUCE_INTEL
  200139. return cpuFlags.hasMMX;
  200140. #else
  200141. return false;
  200142. #endif
  200143. }
  200144. bool SystemStats::hasSSE() throw()
  200145. {
  200146. #if JUCE_INTEL
  200147. return cpuFlags.hasSSE;
  200148. #else
  200149. return false;
  200150. #endif
  200151. }
  200152. bool SystemStats::hasSSE2() throw()
  200153. {
  200154. #if JUCE_INTEL
  200155. return cpuFlags.hasSSE2;
  200156. #else
  200157. return false;
  200158. #endif
  200159. }
  200160. bool SystemStats::has3DNow() throw()
  200161. {
  200162. #if JUCE_INTEL
  200163. return cpuFlags.has3DNow;
  200164. #else
  200165. return false;
  200166. #endif
  200167. }
  200168. const String SystemStats::getCpuVendor() throw()
  200169. {
  200170. #if JUCE_INTEL
  200171. char v [16];
  200172. juce_getCpuVendor (v);
  200173. return String (v, 16);
  200174. #else
  200175. return String::empty;
  200176. #endif
  200177. }
  200178. int SystemStats::getCpuSpeedInMegaherz() throw()
  200179. {
  200180. uint64 speedHz = 0;
  200181. size_t speedSize = sizeof (speedHz);
  200182. int mib[] = { CTL_HW, HW_CPU_FREQ };
  200183. sysctl (mib, 2, &speedHz, &speedSize, 0, 0);
  200184. #if JUCE_BIG_ENDIAN
  200185. if (speedSize == 4)
  200186. speedHz >>= 32;
  200187. #endif
  200188. return (int) (speedHz / 1000000);
  200189. }
  200190. int SystemStats::getNumCpus() throw()
  200191. {
  200192. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  200193. return (int) [[NSProcessInfo processInfo] activeProcessorCount];
  200194. #else
  200195. return MPProcessors();
  200196. #endif
  200197. }
  200198. const String SystemStats::getLogonName()
  200199. {
  200200. return nsStringToJuce (NSUserName());
  200201. }
  200202. const String SystemStats::getFullUserName()
  200203. {
  200204. return nsStringToJuce (NSFullUserName());
  200205. }
  200206. uint32 juce_millisecondsSinceStartup() throw()
  200207. {
  200208. return (uint32) (mach_absolute_time() * highResTimerToMillisecRatio);
  200209. }
  200210. double Time::getMillisecondCounterHiRes() throw()
  200211. {
  200212. return mach_absolute_time() * highResTimerToMillisecRatio;
  200213. }
  200214. int64 Time::getHighResolutionTicks() throw()
  200215. {
  200216. return (int64) mach_absolute_time();
  200217. }
  200218. int64 Time::getHighResolutionTicksPerSecond() throw()
  200219. {
  200220. return highResTimerFrequency;
  200221. }
  200222. int64 SystemStats::getClockCycleCounter() throw()
  200223. {
  200224. return (int64) mach_absolute_time();
  200225. }
  200226. bool Time::setSystemTimeToThisTime() const throw()
  200227. {
  200228. jassertfalse
  200229. return false;
  200230. }
  200231. int SystemStats::getPageSize() throw()
  200232. {
  200233. return (int) NSPageSize();
  200234. }
  200235. void PlatformUtilities::fpuReset()
  200236. {
  200237. }
  200238. #endif
  200239. /*** End of inlined file: juce_mac_SystemStats.mm ***/
  200240. /*** Start of inlined file: juce_mac_Network.mm ***/
  200241. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200242. // compiled on its own).
  200243. #if JUCE_INCLUDED_FILE
  200244. int SystemStats::getMACAddresses (int64* addresses, int maxNum, const bool littleEndian) throw()
  200245. {
  200246. #ifndef IFT_ETHER
  200247. #define IFT_ETHER 6
  200248. #endif
  200249. ifaddrs* addrs = 0;
  200250. int numResults = 0;
  200251. if (getifaddrs (&addrs) == 0)
  200252. {
  200253. const ifaddrs* cursor = addrs;
  200254. while (cursor != 0 && numResults < maxNum)
  200255. {
  200256. sockaddr_storage* sto = (sockaddr_storage*) cursor->ifa_addr;
  200257. if (sto->ss_family == AF_LINK)
  200258. {
  200259. const sockaddr_dl* const sadd = (const sockaddr_dl*) cursor->ifa_addr;
  200260. if (sadd->sdl_type == IFT_ETHER)
  200261. {
  200262. const uint8* const addr = ((const uint8*) sadd->sdl_data) + sadd->sdl_nlen;
  200263. uint64 a = 0;
  200264. for (int i = 6; --i >= 0;)
  200265. a = (a << 8) | addr [littleEndian ? i : (5 - i)];
  200266. *addresses++ = (int64) a;
  200267. ++numResults;
  200268. }
  200269. }
  200270. cursor = cursor->ifa_next;
  200271. }
  200272. freeifaddrs (addrs);
  200273. }
  200274. return numResults;
  200275. }
  200276. bool PlatformUtilities::launchEmailWithAttachments (const String& targetEmailAddress,
  200277. const String& emailSubject,
  200278. const String& bodyText,
  200279. const StringArray& filesToAttach)
  200280. {
  200281. #if JUCE_IPHONE
  200282. //xxx probably need to use MFMailComposeViewController
  200283. jassertfalse
  200284. return false;
  200285. #else
  200286. const ScopedAutoReleasePool pool;
  200287. String script;
  200288. script << "tell application \"Mail\"\r\n"
  200289. "set newMessage to make new outgoing message with properties {subject:\""
  200290. << emailSubject.replace (T("\""), T("\\\""))
  200291. << "\", content:\""
  200292. << bodyText.replace (T("\""), T("\\\""))
  200293. << "\" & return & return}\r\n"
  200294. "tell newMessage\r\n"
  200295. "set visible to true\r\n"
  200296. "set sender to \"sdfsdfsdfewf\"\r\n"
  200297. "make new to recipient at end of to recipients with properties {address:\""
  200298. << targetEmailAddress
  200299. << "\"}\r\n";
  200300. for (int i = 0; i < filesToAttach.size(); ++i)
  200301. {
  200302. script << "tell content\r\n"
  200303. "make new attachment with properties {file name:\""
  200304. << filesToAttach[i].replace (T("\""), T("\\\""))
  200305. << "\"} at after the last paragraph\r\n"
  200306. "end tell\r\n";
  200307. }
  200308. script << "end tell\r\n"
  200309. "end tell\r\n";
  200310. NSAppleScript* s = [[NSAppleScript alloc]
  200311. initWithSource: juceStringToNS (script)];
  200312. NSDictionary* error = 0;
  200313. const bool ok = [s executeAndReturnError: &error] != nil;
  200314. [s release];
  200315. return ok;
  200316. #endif
  200317. }
  200318. END_JUCE_NAMESPACE
  200319. using namespace JUCE_NAMESPACE;
  200320. #define JuceURLConnection MakeObjCClassName(JuceURLConnection)
  200321. @interface JuceURLConnection : NSObject
  200322. {
  200323. @public
  200324. NSURLRequest* request;
  200325. NSURLConnection* connection;
  200326. NSMutableData* data;
  200327. Thread* runLoopThread;
  200328. bool initialised, hasFailed, hasFinished;
  200329. int position;
  200330. int64 contentLength;
  200331. NSLock* dataLock;
  200332. }
  200333. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req withCallback: (URL::OpenStreamProgressCallback*) callback withContext: (void*) context;
  200334. - (void) dealloc;
  200335. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response;
  200336. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error;
  200337. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) data;
  200338. - (void) connectionDidFinishLoading: (NSURLConnection*) connection;
  200339. - (BOOL) isOpen;
  200340. - (int) read: (char*) dest numBytes: (int) num;
  200341. - (int) readPosition;
  200342. - (void) stop;
  200343. - (void) createConnection;
  200344. @end
  200345. class JuceURLConnectionMessageThread : public Thread
  200346. {
  200347. JuceURLConnection* owner;
  200348. public:
  200349. JuceURLConnectionMessageThread (JuceURLConnection* owner_)
  200350. : Thread (T("http connection")),
  200351. owner (owner_)
  200352. {
  200353. }
  200354. ~JuceURLConnectionMessageThread()
  200355. {
  200356. stopThread (10000);
  200357. }
  200358. void run()
  200359. {
  200360. [owner createConnection];
  200361. while (! threadShouldExit())
  200362. {
  200363. const ScopedAutoReleasePool pool;
  200364. [[NSRunLoop currentRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  200365. }
  200366. }
  200367. };
  200368. @implementation JuceURLConnection
  200369. - (JuceURLConnection*) initWithRequest: (NSURLRequest*) req
  200370. withCallback: (URL::OpenStreamProgressCallback*) callback
  200371. withContext: (void*) context;
  200372. {
  200373. [super init];
  200374. request = req;
  200375. [request retain];
  200376. data = [[NSMutableData data] retain];
  200377. dataLock = [[NSLock alloc] init];
  200378. connection = 0;
  200379. initialised = false;
  200380. hasFailed = false;
  200381. hasFinished = false;
  200382. contentLength = -1;
  200383. runLoopThread = new JuceURLConnectionMessageThread (self);
  200384. runLoopThread->startThread();
  200385. while (runLoopThread->isThreadRunning() && ! initialised)
  200386. {
  200387. if (callback != 0)
  200388. callback (context, -1, (int) [[request HTTPBody] length]);
  200389. Thread::sleep (1);
  200390. }
  200391. return self;
  200392. }
  200393. - (void) dealloc
  200394. {
  200395. [self stop];
  200396. delete runLoopThread;
  200397. [connection release];
  200398. [data release];
  200399. [dataLock release];
  200400. [request release];
  200401. [super dealloc];
  200402. }
  200403. - (void) createConnection
  200404. {
  200405. connection = [[NSURLConnection alloc] initWithRequest: request
  200406. delegate: [self retain]];
  200407. if (connection == nil)
  200408. runLoopThread->signalThreadShouldExit();
  200409. }
  200410. - (void) connection: (NSURLConnection*) connection didReceiveResponse: (NSURLResponse*) response
  200411. {
  200412. [dataLock lock];
  200413. [data setLength: 0];
  200414. [dataLock unlock];
  200415. initialised = true;
  200416. contentLength = [response expectedContentLength];
  200417. }
  200418. - (void) connection: (NSURLConnection*) connection didFailWithError: (NSError*) error
  200419. {
  200420. DBG (nsStringToJuce ([error description]));
  200421. hasFailed = true;
  200422. initialised = true;
  200423. runLoopThread->signalThreadShouldExit();
  200424. }
  200425. - (void) connection: (NSURLConnection*) connection didReceiveData: (NSData*) newData
  200426. {
  200427. [dataLock lock];
  200428. [data appendData: newData];
  200429. [dataLock unlock];
  200430. initialised = true;
  200431. }
  200432. - (void) connectionDidFinishLoading: (NSURLConnection*) connection
  200433. {
  200434. hasFinished = true;
  200435. initialised = true;
  200436. runLoopThread->signalThreadShouldExit();
  200437. }
  200438. - (BOOL) isOpen
  200439. {
  200440. return connection != 0 && ! hasFailed;
  200441. }
  200442. - (int) readPosition
  200443. {
  200444. return position;
  200445. }
  200446. - (int) read: (char*) dest numBytes: (int) numNeeded
  200447. {
  200448. int numDone = 0;
  200449. while (numNeeded > 0)
  200450. {
  200451. int available = jmin (numNeeded, (int) [data length]);
  200452. if (available > 0)
  200453. {
  200454. [dataLock lock];
  200455. [data getBytes: dest length: available];
  200456. [data replaceBytesInRange: NSMakeRange (0, available) withBytes: nil length: 0];
  200457. [dataLock unlock];
  200458. numDone += available;
  200459. numNeeded -= available;
  200460. dest += available;
  200461. }
  200462. else
  200463. {
  200464. if (hasFailed || hasFinished)
  200465. break;
  200466. Thread::sleep (1);
  200467. }
  200468. }
  200469. position += numDone;
  200470. return numDone;
  200471. }
  200472. - (void) stop
  200473. {
  200474. [connection cancel];
  200475. runLoopThread->stopThread (10000);
  200476. }
  200477. @end
  200478. BEGIN_JUCE_NAMESPACE
  200479. bool juce_isOnLine()
  200480. {
  200481. return true;
  200482. }
  200483. void* juce_openInternetFile (const String& url,
  200484. const String& headers,
  200485. const MemoryBlock& postData,
  200486. const bool isPost,
  200487. URL::OpenStreamProgressCallback* callback,
  200488. void* callbackContext,
  200489. int timeOutMs)
  200490. {
  200491. const ScopedAutoReleasePool pool;
  200492. NSMutableURLRequest* req = [NSMutableURLRequest
  200493. requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  200494. cachePolicy: NSURLRequestUseProtocolCachePolicy
  200495. timeoutInterval: timeOutMs <= 0 ? 60.0 : (timeOutMs / 1000.0)];
  200496. if (req == nil)
  200497. return 0;
  200498. [req setHTTPMethod: isPost ? @"POST" : @"GET"];
  200499. //[req setCachePolicy: NSURLRequestReloadIgnoringLocalAndRemoteCacheData];
  200500. StringArray headerLines;
  200501. headerLines.addLines (headers);
  200502. headerLines.removeEmptyStrings (true);
  200503. for (int i = 0; i < headerLines.size(); ++i)
  200504. {
  200505. const String key (headerLines[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  200506. const String value (headerLines[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  200507. if (key.isNotEmpty() && value.isNotEmpty())
  200508. [req addValue: juceStringToNS (value) forHTTPHeaderField: juceStringToNS (key)];
  200509. }
  200510. if (isPost && postData.getSize() > 0)
  200511. {
  200512. [req setHTTPBody: [NSData dataWithBytes: postData.getData()
  200513. length: postData.getSize()]];
  200514. }
  200515. JuceURLConnection* const s = [[JuceURLConnection alloc] initWithRequest: req
  200516. withCallback: callback
  200517. withContext: callbackContext];
  200518. if ([s isOpen])
  200519. return s;
  200520. [s release];
  200521. return 0;
  200522. }
  200523. void juce_closeInternetFile (void* handle)
  200524. {
  200525. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200526. if (s != 0)
  200527. {
  200528. const ScopedAutoReleasePool pool;
  200529. [s stop];
  200530. [s release];
  200531. }
  200532. }
  200533. int juce_readFromInternetFile (void* handle, void* buffer, int bytesToRead)
  200534. {
  200535. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200536. if (s != 0)
  200537. {
  200538. const ScopedAutoReleasePool pool;
  200539. return [s read: (char*) buffer numBytes: bytesToRead];
  200540. }
  200541. return 0;
  200542. }
  200543. int64 juce_getInternetFileContentLength (void* handle)
  200544. {
  200545. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200546. if (s != 0)
  200547. return s->contentLength;
  200548. return -1;
  200549. }
  200550. int juce_seekInInternetFile (void* handle, int newPosition)
  200551. {
  200552. JuceURLConnection* const s = (JuceURLConnection*) handle;
  200553. if (s != 0)
  200554. return [s readPosition];
  200555. return 0;
  200556. }
  200557. #endif
  200558. /*** End of inlined file: juce_mac_Network.mm ***/
  200559. /*** Start of inlined file: juce_posix_NamedPipe.cpp ***/
  200560. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200561. // compiled on its own).
  200562. #if JUCE_INCLUDED_FILE
  200563. struct NamedPipeInternal
  200564. {
  200565. String pipeInName, pipeOutName;
  200566. int pipeIn, pipeOut;
  200567. bool volatile createdPipe, blocked, stopReadOperation;
  200568. static void signalHandler (int) {}
  200569. };
  200570. void NamedPipe::cancelPendingReads()
  200571. {
  200572. while (internal != 0 && ((NamedPipeInternal*) internal)->blocked)
  200573. {
  200574. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200575. intern->stopReadOperation = true;
  200576. char buffer [1] = { 0 };
  200577. int bytesWritten = (int) ::write (intern->pipeIn, buffer, 1);
  200578. (void) bytesWritten;
  200579. int timeout = 2000;
  200580. while (intern->blocked && --timeout >= 0)
  200581. Thread::sleep (2);
  200582. intern->stopReadOperation = false;
  200583. }
  200584. }
  200585. void NamedPipe::close()
  200586. {
  200587. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200588. if (intern != 0)
  200589. {
  200590. internal = 0;
  200591. if (intern->pipeIn != -1)
  200592. ::close (intern->pipeIn);
  200593. if (intern->pipeOut != -1)
  200594. ::close (intern->pipeOut);
  200595. if (intern->createdPipe)
  200596. {
  200597. unlink (intern->pipeInName.toUTF8());
  200598. unlink (intern->pipeOutName.toUTF8());
  200599. }
  200600. delete intern;
  200601. }
  200602. }
  200603. bool NamedPipe::openInternal (const String& pipeName, const bool createPipe)
  200604. {
  200605. close();
  200606. NamedPipeInternal* const intern = new NamedPipeInternal();
  200607. internal = intern;
  200608. intern->createdPipe = createPipe;
  200609. intern->blocked = false;
  200610. intern->stopReadOperation = false;
  200611. signal (SIGPIPE, NamedPipeInternal::signalHandler);
  200612. siginterrupt (SIGPIPE, 1);
  200613. const String pipePath (T("/tmp/") + File::createLegalFileName (pipeName));
  200614. intern->pipeInName = pipePath + T("_in");
  200615. intern->pipeOutName = pipePath + T("_out");
  200616. intern->pipeIn = -1;
  200617. intern->pipeOut = -1;
  200618. if (createPipe)
  200619. {
  200620. if ((mkfifo (intern->pipeInName.toUTF8(), 0666) && errno != EEXIST)
  200621. || (mkfifo (intern->pipeOutName.toUTF8(), 0666) && errno != EEXIST))
  200622. {
  200623. delete intern;
  200624. internal = 0;
  200625. return false;
  200626. }
  200627. }
  200628. return true;
  200629. }
  200630. int NamedPipe::read (void* destBuffer, int maxBytesToRead, int /*timeOutMilliseconds*/)
  200631. {
  200632. int bytesRead = -1;
  200633. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200634. if (intern != 0)
  200635. {
  200636. intern->blocked = true;
  200637. if (intern->pipeIn == -1)
  200638. {
  200639. if (intern->createdPipe)
  200640. intern->pipeIn = ::open (intern->pipeInName.toUTF8(), O_RDWR);
  200641. else
  200642. intern->pipeIn = ::open (intern->pipeOutName.toUTF8(), O_RDWR);
  200643. if (intern->pipeIn == -1)
  200644. {
  200645. intern->blocked = false;
  200646. return -1;
  200647. }
  200648. }
  200649. bytesRead = 0;
  200650. char* p = (char*) destBuffer;
  200651. while (bytesRead < maxBytesToRead)
  200652. {
  200653. const int bytesThisTime = maxBytesToRead - bytesRead;
  200654. const int numRead = (int) ::read (intern->pipeIn, p, bytesThisTime);
  200655. if (numRead <= 0 || intern->stopReadOperation)
  200656. {
  200657. bytesRead = -1;
  200658. break;
  200659. }
  200660. bytesRead += numRead;
  200661. p += bytesRead;
  200662. }
  200663. intern->blocked = false;
  200664. }
  200665. return bytesRead;
  200666. }
  200667. int NamedPipe::write (const void* sourceBuffer, int numBytesToWrite, int timeOutMilliseconds)
  200668. {
  200669. int bytesWritten = -1;
  200670. NamedPipeInternal* const intern = (NamedPipeInternal*) internal;
  200671. if (intern != 0)
  200672. {
  200673. if (intern->pipeOut == -1)
  200674. {
  200675. if (intern->createdPipe)
  200676. intern->pipeOut = ::open (intern->pipeOutName.toUTF8(), O_WRONLY);
  200677. else
  200678. intern->pipeOut = ::open (intern->pipeInName.toUTF8(), O_WRONLY);
  200679. if (intern->pipeOut == -1)
  200680. {
  200681. return -1;
  200682. }
  200683. }
  200684. const char* p = (const char*) sourceBuffer;
  200685. bytesWritten = 0;
  200686. const uint32 timeOutTime = Time::getMillisecondCounter() + timeOutMilliseconds;
  200687. while (bytesWritten < numBytesToWrite
  200688. && (timeOutMilliseconds < 0 || Time::getMillisecondCounter() < timeOutTime))
  200689. {
  200690. const int bytesThisTime = numBytesToWrite - bytesWritten;
  200691. const int numWritten = (int) ::write (intern->pipeOut, p, bytesThisTime);
  200692. if (numWritten <= 0)
  200693. {
  200694. bytesWritten = -1;
  200695. break;
  200696. }
  200697. bytesWritten += numWritten;
  200698. p += bytesWritten;
  200699. }
  200700. }
  200701. return bytesWritten;
  200702. }
  200703. #endif
  200704. /*** End of inlined file: juce_posix_NamedPipe.cpp ***/
  200705. /*** Start of inlined file: juce_mac_Threads.mm ***/
  200706. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  200707. // compiled on its own).
  200708. #if JUCE_INCLUDED_FILE
  200709. void JUCE_API juce_threadEntryPoint (void*);
  200710. void* threadEntryProc (void* userData)
  200711. {
  200712. const ScopedAutoReleasePool pool;
  200713. juce_threadEntryPoint (userData);
  200714. return 0;
  200715. }
  200716. void* juce_createThread (void* userData)
  200717. {
  200718. pthread_t handle = 0;
  200719. if (pthread_create (&handle, 0, threadEntryProc, userData) == 0)
  200720. {
  200721. pthread_detach (handle);
  200722. return (void*) handle;
  200723. }
  200724. return 0;
  200725. }
  200726. void juce_killThread (void* handle)
  200727. {
  200728. if (handle != 0)
  200729. pthread_cancel ((pthread_t) handle);
  200730. }
  200731. void juce_setCurrentThreadName (const String& /*name*/)
  200732. {
  200733. }
  200734. Thread::ThreadID Thread::getCurrentThreadId()
  200735. {
  200736. return (ThreadID) pthread_self();
  200737. }
  200738. bool juce_setThreadPriority (void* handle, int priority)
  200739. {
  200740. if (handle == 0)
  200741. handle = (void*) pthread_self();
  200742. struct sched_param param;
  200743. int policy;
  200744. pthread_getschedparam ((pthread_t) handle, &policy, &param);
  200745. param.sched_priority = jlimit (1, 127, 1 + (priority * 126) / 11);
  200746. return pthread_setschedparam ((pthread_t) handle, policy, &param) == 0;
  200747. }
  200748. void Thread::yield()
  200749. {
  200750. sched_yield();
  200751. }
  200752. void Thread::setCurrentThreadAffinityMask (const uint32 affinityMask)
  200753. {
  200754. // xxx
  200755. jassertfalse
  200756. }
  200757. bool Process::isForegroundProcess()
  200758. {
  200759. #if JUCE_MAC
  200760. return [NSApp isActive];
  200761. #else
  200762. return true; // xxx change this if more than one app is ever possible on the iPhone!
  200763. #endif
  200764. }
  200765. void Process::raisePrivilege()
  200766. {
  200767. jassertfalse
  200768. }
  200769. void Process::lowerPrivilege()
  200770. {
  200771. jassertfalse
  200772. }
  200773. void Process::terminate()
  200774. {
  200775. exit (0);
  200776. }
  200777. void Process::setPriority (ProcessPriority p)
  200778. {
  200779. // xxx
  200780. }
  200781. #endif
  200782. /*** End of inlined file: juce_mac_Threads.mm ***/
  200783. /*** Start of inlined file: juce_posix_SharedCode.h ***/
  200784. CriticalSection::CriticalSection() throw()
  200785. {
  200786. pthread_mutexattr_t atts;
  200787. pthread_mutexattr_init (&atts);
  200788. pthread_mutexattr_settype (&atts, PTHREAD_MUTEX_RECURSIVE);
  200789. pthread_mutex_init (&internal, &atts);
  200790. }
  200791. CriticalSection::~CriticalSection() throw()
  200792. {
  200793. pthread_mutex_destroy (&internal);
  200794. }
  200795. void CriticalSection::enter() const throw()
  200796. {
  200797. pthread_mutex_lock (&internal);
  200798. }
  200799. bool CriticalSection::tryEnter() const throw()
  200800. {
  200801. return pthread_mutex_trylock (&internal) == 0;
  200802. }
  200803. void CriticalSection::exit() const throw()
  200804. {
  200805. pthread_mutex_unlock (&internal);
  200806. }
  200807. struct EventStruct
  200808. {
  200809. pthread_cond_t condition;
  200810. pthread_mutex_t mutex;
  200811. bool triggered;
  200812. };
  200813. WaitableEvent::WaitableEvent() throw()
  200814. {
  200815. EventStruct* const es = new EventStruct();
  200816. es->triggered = false;
  200817. pthread_cond_init (&es->condition, 0);
  200818. pthread_mutex_init (&es->mutex, 0);
  200819. internal = es;
  200820. }
  200821. WaitableEvent::~WaitableEvent() throw()
  200822. {
  200823. EventStruct* const es = (EventStruct*) internal;
  200824. pthread_cond_destroy (&es->condition);
  200825. pthread_mutex_destroy (&es->mutex);
  200826. delete es;
  200827. }
  200828. bool WaitableEvent::wait (const int timeOutMillisecs) const throw()
  200829. {
  200830. EventStruct* const es = (EventStruct*) internal;
  200831. pthread_mutex_lock (&es->mutex);
  200832. if (timeOutMillisecs < 0)
  200833. {
  200834. while (! es->triggered)
  200835. pthread_cond_wait (&es->condition, &es->mutex);
  200836. }
  200837. else
  200838. {
  200839. while (! es->triggered)
  200840. {
  200841. struct timeval t;
  200842. gettimeofday (&t, 0);
  200843. struct timespec time;
  200844. time.tv_sec = t.tv_sec + (timeOutMillisecs / 1000);
  200845. time.tv_nsec = (t.tv_usec + ((timeOutMillisecs % 1000) * 1000)) * 1000;
  200846. if (time.tv_nsec >= 1000000000)
  200847. {
  200848. time.tv_nsec -= 1000000000;
  200849. time.tv_sec++;
  200850. }
  200851. if (pthread_cond_timedwait (&es->condition, &es->mutex, &time) == ETIMEDOUT)
  200852. {
  200853. pthread_mutex_unlock (&es->mutex);
  200854. return false;
  200855. }
  200856. }
  200857. }
  200858. es->triggered = false;
  200859. pthread_mutex_unlock (&es->mutex);
  200860. return true;
  200861. }
  200862. void WaitableEvent::signal() const throw()
  200863. {
  200864. EventStruct* const es = (EventStruct*) internal;
  200865. pthread_mutex_lock (&es->mutex);
  200866. es->triggered = true;
  200867. pthread_cond_broadcast (&es->condition);
  200868. pthread_mutex_unlock (&es->mutex);
  200869. }
  200870. void WaitableEvent::reset() const throw()
  200871. {
  200872. EventStruct* const es = (EventStruct*) internal;
  200873. pthread_mutex_lock (&es->mutex);
  200874. es->triggered = false;
  200875. pthread_mutex_unlock (&es->mutex);
  200876. }
  200877. void JUCE_CALLTYPE Thread::sleep (int millisecs)
  200878. {
  200879. struct timespec time;
  200880. time.tv_sec = millisecs / 1000;
  200881. time.tv_nsec = (millisecs % 1000) * 1000000;
  200882. nanosleep (&time, 0);
  200883. }
  200884. const tchar File::separator = T('/');
  200885. const tchar* File::separatorString = T("/");
  200886. const File File::getCurrentWorkingDirectory()
  200887. {
  200888. HeapBlock<char> heapBuffer;
  200889. char localBuffer [1024];
  200890. char* cwd = getcwd (localBuffer, sizeof (localBuffer) - 1);
  200891. int bufferSize = 4096;
  200892. while (cwd == 0 && errno == ERANGE)
  200893. {
  200894. heapBuffer.malloc (bufferSize);
  200895. cwd = getcwd (heapBuffer, bufferSize - 1);
  200896. bufferSize += 1024;
  200897. }
  200898. return File (String::fromUTF8 (cwd));
  200899. }
  200900. bool File::setAsCurrentWorkingDirectory() const
  200901. {
  200902. return chdir (getFullPathName().toUTF8()) == 0;
  200903. }
  200904. bool juce_copyFile (const String& s, const String& d);
  200905. static bool juce_stat (const String& fileName, struct stat& info)
  200906. {
  200907. return fileName.isNotEmpty()
  200908. && (stat (fileName.toUTF8(), &info) == 0);
  200909. }
  200910. bool juce_isDirectory (const String& fileName)
  200911. {
  200912. struct stat info;
  200913. return fileName.isEmpty()
  200914. || (juce_stat (fileName, info)
  200915. && ((info.st_mode & S_IFDIR) != 0));
  200916. }
  200917. bool juce_fileExists (const String& fileName, const bool dontCountDirectories)
  200918. {
  200919. if (fileName.isEmpty())
  200920. return false;
  200921. const char* const fileNameUTF8 = fileName.toUTF8();
  200922. bool exists = access (fileNameUTF8, F_OK) == 0;
  200923. if (exists && dontCountDirectories)
  200924. {
  200925. struct stat info;
  200926. const int res = stat (fileNameUTF8, &info);
  200927. if (res == 0 && (info.st_mode & S_IFDIR) != 0)
  200928. exists = false;
  200929. }
  200930. return exists;
  200931. }
  200932. int64 juce_getFileSize (const String& fileName)
  200933. {
  200934. struct stat info;
  200935. return juce_stat (fileName, info) ? info.st_size : 0;
  200936. }
  200937. bool juce_canWriteToFile (const String& fileName)
  200938. {
  200939. return access (fileName.toUTF8(), W_OK) == 0;
  200940. }
  200941. bool juce_deleteFile (const String& fileName)
  200942. {
  200943. if (juce_isDirectory (fileName))
  200944. return rmdir ((const char*) fileName.toUTF8()) == 0;
  200945. else
  200946. return remove ((const char*) fileName.toUTF8()) == 0;
  200947. }
  200948. bool juce_moveFile (const String& source, const String& dest)
  200949. {
  200950. if (rename (source.toUTF8(), dest.toUTF8()) == 0)
  200951. return true;
  200952. if (juce_canWriteToFile (source)
  200953. && juce_copyFile (source, dest))
  200954. {
  200955. if (juce_deleteFile (source))
  200956. return true;
  200957. juce_deleteFile (dest);
  200958. }
  200959. return false;
  200960. }
  200961. void juce_createDirectory (const String& fileName)
  200962. {
  200963. mkdir (fileName.toUTF8(), 0777);
  200964. }
  200965. void* juce_fileOpen (const String& fileName, bool forWriting)
  200966. {
  200967. int flags = O_RDONLY;
  200968. if (forWriting)
  200969. {
  200970. if (juce_fileExists (fileName, false))
  200971. {
  200972. const int f = open ((const char*) fileName.toUTF8(), O_RDWR, 00644);
  200973. if (f != -1)
  200974. lseek (f, 0, SEEK_END);
  200975. return (void*) f;
  200976. }
  200977. else
  200978. {
  200979. flags = O_RDWR + O_CREAT;
  200980. }
  200981. }
  200982. return (void*) open ((const char*) fileName.toUTF8(), flags, 00644);
  200983. }
  200984. void juce_fileClose (void* handle)
  200985. {
  200986. if (handle != 0)
  200987. close ((int) (pointer_sized_int) handle);
  200988. }
  200989. int juce_fileRead (void* handle, void* buffer, int size)
  200990. {
  200991. if (handle != 0)
  200992. return (int) read ((int) (pointer_sized_int) handle, buffer, size);
  200993. return 0;
  200994. }
  200995. int juce_fileWrite (void* handle, const void* buffer, int size)
  200996. {
  200997. if (handle != 0)
  200998. return (int) write ((int) (pointer_sized_int) handle, buffer, size);
  200999. return 0;
  201000. }
  201001. int64 juce_fileSetPosition (void* handle, int64 pos)
  201002. {
  201003. if (handle != 0 && lseek ((int) (pointer_sized_int) handle, pos, SEEK_SET) == pos)
  201004. return pos;
  201005. return -1;
  201006. }
  201007. int64 juce_fileGetPosition (void* handle)
  201008. {
  201009. if (handle != 0)
  201010. return lseek ((int) (pointer_sized_int) handle, 0, SEEK_CUR);
  201011. else
  201012. return -1;
  201013. }
  201014. void juce_fileFlush (void* handle)
  201015. {
  201016. if (handle != 0)
  201017. fsync ((int) (pointer_sized_int) handle);
  201018. }
  201019. const File juce_getExecutableFile()
  201020. {
  201021. Dl_info exeInfo;
  201022. dladdr ((const void*) juce_getExecutableFile, &exeInfo);
  201023. return File (String::fromUTF8 (exeInfo.dli_fname));
  201024. }
  201025. // if this file doesn't exist, find a parent of it that does..
  201026. static bool doStatFS (const File* file, struct statfs& result)
  201027. {
  201028. File f (*file);
  201029. for (int i = 5; --i >= 0;)
  201030. {
  201031. if (f.exists())
  201032. break;
  201033. f = f.getParentDirectory();
  201034. }
  201035. return statfs (f.getFullPathName().toUTF8(), &result) == 0;
  201036. }
  201037. int64 File::getBytesFreeOnVolume() const
  201038. {
  201039. struct statfs buf;
  201040. if (doStatFS (this, buf))
  201041. return (int64) buf.f_bsize * (int64) buf.f_bavail; // Note: this returns space available to non-super user
  201042. return 0;
  201043. }
  201044. int64 File::getVolumeTotalSize() const
  201045. {
  201046. struct statfs buf;
  201047. if (doStatFS (this, buf))
  201048. return (int64) buf.f_bsize * (int64) buf.f_blocks;
  201049. return 0;
  201050. }
  201051. const String juce_getVolumeLabel (const String& filenameOnVolume,
  201052. int& volumeSerialNumber)
  201053. {
  201054. volumeSerialNumber = 0;
  201055. #if JUCE_MAC
  201056. struct VolAttrBuf
  201057. {
  201058. u_int32_t length;
  201059. attrreference_t mountPointRef;
  201060. char mountPointSpace [MAXPATHLEN];
  201061. } attrBuf;
  201062. struct attrlist attrList;
  201063. zerostruct (attrList);
  201064. attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
  201065. attrList.volattr = ATTR_VOL_INFO | ATTR_VOL_NAME;
  201066. File f (filenameOnVolume);
  201067. for (;;)
  201068. {
  201069. if (getattrlist ((const char*) f.getFullPathName().toUTF8(),
  201070. &attrList, &attrBuf, sizeof(attrBuf), 0) == 0)
  201071. {
  201072. return String::fromUTF8 (((const char*) &attrBuf.mountPointRef) + attrBuf.mountPointRef.attr_dataoffset,
  201073. (int) attrBuf.mountPointRef.attr_length);
  201074. }
  201075. const File parent (f.getParentDirectory());
  201076. if (f == parent)
  201077. break;
  201078. f = parent;
  201079. }
  201080. #endif
  201081. return String::empty;
  201082. }
  201083. void juce_runSystemCommand (const String& command)
  201084. {
  201085. int result = system ((const char*) command.toUTF8());
  201086. (void) result;
  201087. }
  201088. const String juce_getOutputFromCommand (const String& command)
  201089. {
  201090. // slight bodge here, as we just pipe the output into a temp file and read it...
  201091. const File tempFile (File::getSpecialLocation (File::tempDirectory)
  201092. .getNonexistentChildFile (String::toHexString (Random::getSystemRandom().nextInt()), ".tmp", false));
  201093. juce_runSystemCommand (command + " > " + tempFile.getFullPathName());
  201094. String result (tempFile.loadFileAsString());
  201095. tempFile.deleteFile();
  201096. return result;
  201097. }
  201098. InterProcessLock::InterProcessLock (const String& name_)
  201099. : internal (0),
  201100. name (name_),
  201101. reentrancyLevel (0)
  201102. {
  201103. #if JUCE_MAC
  201104. // (don't use getSpecialLocation() to avoid the temp folder being different for each app)
  201105. const File temp (File (T("~/Library/Caches/Juce")).getChildFile (name));
  201106. #else
  201107. const File temp (File::getSpecialLocation (File::tempDirectory).getChildFile (name));
  201108. #endif
  201109. temp.create();
  201110. internal = open (temp.getFullPathName().toUTF8(), O_RDWR);
  201111. }
  201112. InterProcessLock::~InterProcessLock()
  201113. {
  201114. while (reentrancyLevel > 0)
  201115. this->exit();
  201116. close (internal);
  201117. }
  201118. bool InterProcessLock::enter (const int timeOutMillisecs)
  201119. {
  201120. if (internal == 0)
  201121. return false;
  201122. if (reentrancyLevel != 0)
  201123. return true;
  201124. const int64 endTime = Time::currentTimeMillis() + timeOutMillisecs;
  201125. struct flock fl;
  201126. zerostruct (fl);
  201127. fl.l_whence = SEEK_SET;
  201128. fl.l_type = F_WRLCK;
  201129. for (;;)
  201130. {
  201131. const int result = fcntl (internal, F_SETLK, &fl);
  201132. if (result >= 0)
  201133. {
  201134. ++reentrancyLevel;
  201135. return true;
  201136. }
  201137. if (errno != EINTR)
  201138. {
  201139. if (timeOutMillisecs == 0
  201140. || (timeOutMillisecs > 0 && Time::currentTimeMillis() >= endTime))
  201141. break;
  201142. Thread::sleep (10);
  201143. }
  201144. }
  201145. return false;
  201146. }
  201147. void InterProcessLock::exit()
  201148. {
  201149. if (reentrancyLevel > 0 && internal != 0)
  201150. {
  201151. --reentrancyLevel;
  201152. struct flock fl;
  201153. zerostruct (fl);
  201154. fl.l_whence = SEEK_SET;
  201155. fl.l_type = F_UNLCK;
  201156. for (;;)
  201157. {
  201158. const int result = fcntl (internal, F_SETLKW, &fl);
  201159. if (result >= 0 || errno != EINTR)
  201160. break;
  201161. }
  201162. }
  201163. }
  201164. /*** End of inlined file: juce_posix_SharedCode.h ***/
  201165. /*** Start of inlined file: juce_mac_Files.mm ***/
  201166. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201167. // compiled on its own).
  201168. #if JUCE_INCLUDED_FILE
  201169. void juce_getFileTimes (const String& fileName,
  201170. int64& modificationTime,
  201171. int64& accessTime,
  201172. int64& creationTime)
  201173. {
  201174. modificationTime = 0;
  201175. accessTime = 0;
  201176. creationTime = 0;
  201177. struct stat info;
  201178. const int res = stat (fileName.toUTF8(), &info);
  201179. if (res == 0)
  201180. {
  201181. modificationTime = (int64) info.st_mtime * 1000;
  201182. accessTime = (int64) info.st_atime * 1000;
  201183. creationTime = (int64) info.st_ctime * 1000;
  201184. }
  201185. }
  201186. bool juce_setFileTimes (const String& fileName,
  201187. int64 modificationTime,
  201188. int64 accessTime,
  201189. int64 creationTime)
  201190. {
  201191. struct utimbuf times;
  201192. times.actime = (time_t) (accessTime / 1000);
  201193. times.modtime = (time_t) (modificationTime / 1000);
  201194. return utime (fileName.toUTF8(), &times) == 0;
  201195. }
  201196. bool juce_setFileReadOnly (const String& fileName, bool isReadOnly)
  201197. {
  201198. struct stat info;
  201199. const int res = stat (fileName.toUTF8(), &info);
  201200. if (res != 0)
  201201. return false;
  201202. info.st_mode &= 0777; // Just permissions
  201203. if (isReadOnly)
  201204. info.st_mode &= ~(S_IWUSR | S_IWGRP | S_IWOTH);
  201205. else
  201206. // Give everybody write permission?
  201207. info.st_mode |= S_IWUSR | S_IWGRP | S_IWOTH;
  201208. return chmod (fileName.toUTF8(), info.st_mode) == 0;
  201209. }
  201210. bool juce_copyFile (const String& src, const String& dst)
  201211. {
  201212. const ScopedAutoReleasePool pool;
  201213. NSFileManager* fm = [NSFileManager defaultManager];
  201214. return [fm fileExistsAtPath: juceStringToNS (src)]
  201215. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201216. && [fm copyItemAtPath: juceStringToNS (src)
  201217. toPath: juceStringToNS (dst)
  201218. error: nil];
  201219. #else
  201220. && [fm copyPath: juceStringToNS (src)
  201221. toPath: juceStringToNS (dst)
  201222. handler: nil];
  201223. #endif
  201224. }
  201225. const StringArray juce_getFileSystemRoots()
  201226. {
  201227. StringArray s;
  201228. s.add (T("/"));
  201229. return s;
  201230. }
  201231. static bool isFileOnDriveType (const File* const f, const char** types)
  201232. {
  201233. struct statfs buf;
  201234. if (doStatFS (f, buf))
  201235. {
  201236. const String type (buf.f_fstypename);
  201237. while (*types != 0)
  201238. if (type.equalsIgnoreCase (*types++))
  201239. return true;
  201240. }
  201241. return false;
  201242. }
  201243. bool File::isOnCDRomDrive() const
  201244. {
  201245. static const char* const cdTypes[] = { "cd9660", "cdfs", "cddafs", "udf", 0 };
  201246. return isFileOnDriveType (this, (const char**) cdTypes);
  201247. }
  201248. bool File::isOnHardDisk() const
  201249. {
  201250. static const char* const nonHDTypes[] = { "nfs", "smbfs", "ramfs", 0 };
  201251. return ! (isOnCDRomDrive() || isFileOnDriveType (this, (const char**) nonHDTypes));
  201252. }
  201253. bool File::isOnRemovableDrive() const
  201254. {
  201255. #if JUCE_IPHONE
  201256. return false; // xxx is this possible?
  201257. #else
  201258. const ScopedAutoReleasePool pool;
  201259. BOOL removable = false;
  201260. [[NSWorkspace sharedWorkspace]
  201261. getFileSystemInfoForPath: juceStringToNS (getFullPathName())
  201262. isRemovable: &removable
  201263. isWritable: nil
  201264. isUnmountable: nil
  201265. description: nil
  201266. type: nil];
  201267. return removable;
  201268. #endif
  201269. }
  201270. static bool juce_isHiddenFile (const String& path)
  201271. {
  201272. #if JUCE_IPHONE
  201273. return File (path).getFileName().startsWithChar (T('.'));
  201274. #else
  201275. FSRef ref;
  201276. if (! PlatformUtilities::makeFSRefFromPath (&ref, path))
  201277. return false;
  201278. FSCatalogInfo info;
  201279. FSGetCatalogInfo (&ref, kFSCatInfoNodeFlags | kFSCatInfoFinderInfo, &info, 0, 0, 0);
  201280. if ((info.nodeFlags & kFSNodeIsDirectoryBit) != 0)
  201281. return (((FolderInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201282. return (((FileInfo*) &info.finderInfo)->finderFlags & kIsInvisible) != 0;
  201283. #endif
  201284. }
  201285. bool File::isHidden() const
  201286. {
  201287. return juce_isHiddenFile (getFullPathName());
  201288. }
  201289. const char* juce_Argv0 = 0; // referenced from juce_Application.cpp
  201290. const File File::getSpecialLocation (const SpecialLocationType type)
  201291. {
  201292. const ScopedAutoReleasePool pool;
  201293. String resultPath;
  201294. switch (type)
  201295. {
  201296. case userHomeDirectory:
  201297. resultPath = nsStringToJuce (NSHomeDirectory());
  201298. break;
  201299. case userDocumentsDirectory:
  201300. resultPath = "~/Documents";
  201301. break;
  201302. case userDesktopDirectory:
  201303. resultPath = "~/Desktop";
  201304. break;
  201305. case userApplicationDataDirectory:
  201306. resultPath = "~/Library";
  201307. break;
  201308. case commonApplicationDataDirectory:
  201309. resultPath = "/Library";
  201310. break;
  201311. case globalApplicationsDirectory:
  201312. resultPath = "/Applications";
  201313. break;
  201314. case userMusicDirectory:
  201315. resultPath = "~/Music";
  201316. break;
  201317. case userMoviesDirectory:
  201318. resultPath = "~/Movies";
  201319. break;
  201320. case tempDirectory:
  201321. {
  201322. File tmp (T("~/Library/Caches/") + juce_getExecutableFile().getFileNameWithoutExtension());
  201323. tmp.createDirectory();
  201324. return tmp.getFullPathName();
  201325. }
  201326. case invokedExecutableFile:
  201327. if (juce_Argv0 != 0)
  201328. return File (String::fromUTF8 (juce_Argv0));
  201329. // deliberate fall-through...
  201330. case currentExecutableFile:
  201331. return juce_getExecutableFile();
  201332. case currentApplicationFile:
  201333. {
  201334. const File exe (juce_getExecutableFile());
  201335. const File parent (exe.getParentDirectory());
  201336. return parent.getFullPathName().endsWithIgnoreCase (T("Contents/MacOS"))
  201337. ? parent.getParentDirectory().getParentDirectory()
  201338. : exe;
  201339. }
  201340. default:
  201341. jassertfalse // unknown type?
  201342. break;
  201343. }
  201344. if (resultPath.isNotEmpty())
  201345. return File (PlatformUtilities::convertToPrecomposedUnicode (resultPath));
  201346. return File::nonexistent;
  201347. }
  201348. const String File::getVersion() const
  201349. {
  201350. const ScopedAutoReleasePool pool;
  201351. String result;
  201352. NSBundle* bundle = [NSBundle bundleWithPath: juceStringToNS (getFullPathName())];
  201353. if (bundle != 0)
  201354. {
  201355. NSDictionary* info = [bundle infoDictionary];
  201356. if (info != 0)
  201357. {
  201358. NSString* name = [info valueForKey: @"CFBundleShortVersionString"];
  201359. if (name != nil)
  201360. result = nsStringToJuce (name);
  201361. }
  201362. }
  201363. return result;
  201364. }
  201365. const File File::getLinkedTarget() const
  201366. {
  201367. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201368. NSString* dest = [[NSFileManager defaultManager] destinationOfSymbolicLinkAtPath: juceStringToNS (getFullPathName()) error: nil];
  201369. #else
  201370. NSString* dest = [[NSFileManager defaultManager] pathContentOfSymbolicLinkAtPath: juceStringToNS (getFullPathName())];
  201371. #endif
  201372. if (dest != nil)
  201373. return File (nsStringToJuce (dest));
  201374. return *this;
  201375. }
  201376. bool File::moveToTrash() const
  201377. {
  201378. if (! exists())
  201379. return true;
  201380. #if JUCE_IPHONE
  201381. return deleteFile(); //xxx is there a trashcan on the iPhone?
  201382. #else
  201383. const ScopedAutoReleasePool pool;
  201384. NSString* p = juceStringToNS (getFullPathName());
  201385. return [[NSWorkspace sharedWorkspace]
  201386. performFileOperation: NSWorkspaceRecycleOperation
  201387. source: [p stringByDeletingLastPathComponent]
  201388. destination: @""
  201389. files: [NSArray arrayWithObject: [p lastPathComponent]]
  201390. tag: nil ];
  201391. #endif
  201392. }
  201393. struct FindFileStruct
  201394. {
  201395. NSDirectoryEnumerator* enumerator;
  201396. String parentDir, wildCard;
  201397. };
  201398. bool juce_findFileNext (void* handle, String& resultFile,
  201399. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime, Time* creationTime, bool* isReadOnly)
  201400. {
  201401. ScopedAutoReleasePool pool;
  201402. FindFileStruct* ff = (FindFileStruct*) handle;
  201403. NSString* file;
  201404. const char* const wildcardUTF8 = ff->wildCard.toUTF8();
  201405. for (;;)
  201406. {
  201407. if (ff == 0 || (file = [ff->enumerator nextObject]) == 0)
  201408. return false;
  201409. [ff->enumerator skipDescendents];
  201410. resultFile = nsStringToJuce (file);
  201411. if (fnmatch (wildcardUTF8, resultFile.toUTF8(), FNM_CASEFOLD) != 0)
  201412. continue;
  201413. const String path (ff->parentDir + resultFile);
  201414. if (isDir != 0 || fileSize != 0)
  201415. {
  201416. struct stat info;
  201417. const bool statOk = juce_stat (path, info);
  201418. if (isDir != 0)
  201419. *isDir = statOk && ((info.st_mode & S_IFDIR) != 0);
  201420. if (isHidden != 0)
  201421. *isHidden = juce_isHiddenFile (path);
  201422. if (fileSize != 0)
  201423. *fileSize = statOk ? info.st_size : 0;
  201424. }
  201425. if (modTime != 0 || creationTime != 0)
  201426. {
  201427. int64 m, a, c;
  201428. juce_getFileTimes (path, m, a, c);
  201429. if (modTime != 0)
  201430. *modTime = m;
  201431. if (creationTime != 0)
  201432. *creationTime = c;
  201433. }
  201434. if (isReadOnly != 0)
  201435. *isReadOnly = ! juce_canWriteToFile (path);
  201436. return true;
  201437. }
  201438. }
  201439. void* juce_findFileStart (const String& directory, const String& wildCard, String& firstResultFile,
  201440. bool* isDir, bool* isHidden, int64* fileSize, Time* modTime,
  201441. Time* creationTime, bool* isReadOnly)
  201442. {
  201443. ScopedAutoReleasePool pool;
  201444. NSDirectoryEnumerator* e = [[NSFileManager defaultManager] enumeratorAtPath: juceStringToNS (directory)];
  201445. if (e != 0)
  201446. {
  201447. ScopedPointer <FindFileStruct> ff (new FindFileStruct());
  201448. ff->enumerator = [e retain];
  201449. ff->parentDir = directory;
  201450. ff->wildCard = wildCard;
  201451. if (! ff->parentDir.endsWithChar (File::separator))
  201452. ff->parentDir += File::separator;
  201453. if (juce_findFileNext (ff, firstResultFile, isDir, isHidden, fileSize, modTime, creationTime, isReadOnly))
  201454. return ff.release();
  201455. [e release];
  201456. }
  201457. return 0;
  201458. }
  201459. void juce_findFileClose (void* handle)
  201460. {
  201461. ScopedAutoReleasePool pool;
  201462. ScopedPointer <FindFileStruct> ff ((FindFileStruct*) handle);
  201463. [ff->enumerator release];
  201464. }
  201465. bool juce_launchExecutable (const String& pathAndArguments)
  201466. {
  201467. const char* const argv[4] = { "/bin/sh", "-c", pathAndArguments.toUTF8(), 0 };
  201468. const int cpid = fork();
  201469. if (cpid == 0)
  201470. {
  201471. // Child process
  201472. if (execve (argv[0], (char**) argv, 0) < 0)
  201473. exit (0);
  201474. }
  201475. else
  201476. {
  201477. if (cpid < 0)
  201478. return false;
  201479. }
  201480. return true;
  201481. }
  201482. bool juce_launchFile (const String& fileName, const String& parameters)
  201483. {
  201484. #if JUCE_IPHONE
  201485. return [[UIApplication sharedApplication] openURL: [NSURL fileURLWithPath: juceStringToNS (fileName)]];
  201486. #else
  201487. const ScopedAutoReleasePool pool;
  201488. if (parameters.isEmpty())
  201489. {
  201490. return [[NSWorkspace sharedWorkspace] openFile: juceStringToNS (fileName)]
  201491. || [[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: juceStringToNS (fileName)]];
  201492. }
  201493. bool ok = false;
  201494. FSRef ref;
  201495. if (PlatformUtilities::makeFSRefFromPath (&ref, fileName))
  201496. {
  201497. if (PlatformUtilities::isBundle (fileName))
  201498. {
  201499. NSMutableArray* urls = [NSMutableArray array];
  201500. StringArray docs;
  201501. docs.addTokens (parameters, true);
  201502. for (int i = 0; i < docs.size(); ++i)
  201503. [urls addObject: juceStringToNS (docs[i])];
  201504. ok = [[NSWorkspace sharedWorkspace] openURLs: urls
  201505. withAppBundleIdentifier: [[NSBundle bundleWithPath: juceStringToNS (fileName)] bundleIdentifier]
  201506. options: 0
  201507. additionalEventParamDescriptor: nil
  201508. launchIdentifiers: nil];
  201509. }
  201510. else
  201511. {
  201512. ok = juce_launchExecutable (T("\"") + fileName + T("\" ") + parameters);
  201513. }
  201514. }
  201515. return ok;
  201516. #endif
  201517. }
  201518. void File::revealToUser() const
  201519. {
  201520. #if ! JUCE_IPHONE
  201521. if (exists())
  201522. [[NSWorkspace sharedWorkspace] selectFile: juceStringToNS (getFullPathName()) inFileViewerRootedAtPath: @""];
  201523. else if (getParentDirectory().exists())
  201524. getParentDirectory().revealToUser();
  201525. #endif
  201526. }
  201527. #if ! JUCE_IPHONE
  201528. bool PlatformUtilities::makeFSRefFromPath (FSRef* destFSRef, const String& path)
  201529. {
  201530. return FSPathMakeRef ((const UInt8*) path.toUTF8(), destFSRef, 0) == noErr;
  201531. }
  201532. const String PlatformUtilities::makePathFromFSRef (FSRef* file)
  201533. {
  201534. char path [2048];
  201535. zerostruct (path);
  201536. if (FSRefMakePath (file, (UInt8*) path, sizeof (path) - 1) == noErr)
  201537. return PlatformUtilities::convertToPrecomposedUnicode (String::fromUTF8 (path));
  201538. return String::empty;
  201539. }
  201540. #endif
  201541. OSType PlatformUtilities::getTypeOfFile (const String& filename)
  201542. {
  201543. const ScopedAutoReleasePool pool;
  201544. #if JUCE_IPHONE || (defined (MAC_OS_X_VERSION_10_5) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
  201545. NSDictionary* fileDict = [[NSFileManager defaultManager] attributesOfItemAtPath: juceStringToNS (filename) error: nil];
  201546. #else
  201547. NSDictionary* fileDict = [[NSFileManager defaultManager] fileAttributesAtPath: juceStringToNS (filename) traverseLink: NO];
  201548. #endif
  201549. //return (OSType) [fileDict objectForKey: NSFileHFSTypeCode];
  201550. return [fileDict fileHFSTypeCode];
  201551. }
  201552. bool PlatformUtilities::isBundle (const String& filename)
  201553. {
  201554. #if JUCE_IPHONE
  201555. return false; // xxx can't find a sensible way to do this without trying to open the bundle..
  201556. #else
  201557. const ScopedAutoReleasePool pool;
  201558. return [[NSWorkspace sharedWorkspace] isFilePackageAtPath: juceStringToNS (filename)];
  201559. #endif
  201560. }
  201561. #endif
  201562. /*** End of inlined file: juce_mac_Files.mm ***/
  201563. #if JUCE_IPHONE
  201564. /*** Start of inlined file: juce_iphone_MiscUtilities.mm ***/
  201565. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201566. // compiled on its own).
  201567. #if JUCE_INCLUDED_FILE
  201568. static JUCEApplication* juce_intialisingApp;
  201569. END_JUCE_NAMESPACE
  201570. @interface JuceAppStartupDelegate : NSObject <UIApplicationDelegate>
  201571. {
  201572. }
  201573. - (void) applicationDidFinishLaunching: (UIApplication*) application;
  201574. - (void) applicationWillResignActive: (UIApplication*) application;
  201575. @end
  201576. @implementation JuceAppStartupDelegate
  201577. - (void) applicationDidFinishLaunching: (UIApplication*) application
  201578. {
  201579. String dummy;
  201580. if (! juce_intialisingApp->initialiseApp (dummy))
  201581. exit (0);
  201582. }
  201583. - (void) applicationWillResignActive: (UIApplication*) application
  201584. {
  201585. JUCEApplication::shutdownAppAndClearUp();
  201586. }
  201587. @end
  201588. BEGIN_JUCE_NAMESPACE
  201589. int juce_IPhoneMain (int argc, const char* argv[], JUCEApplication* app)
  201590. {
  201591. juce_intialisingApp = app;
  201592. return UIApplicationMain (argc, const_cast<char**> (argv), nil, @"JuceAppStartupDelegate");
  201593. }
  201594. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201595. {
  201596. pool = [[NSAutoreleasePool alloc] init];
  201597. }
  201598. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201599. {
  201600. [((NSAutoreleasePool*) pool) release];
  201601. }
  201602. void PlatformUtilities::beep()
  201603. {
  201604. //xxx
  201605. //AudioServicesPlaySystemSound ();
  201606. }
  201607. void PlatformUtilities::addItemToDock (const File& file)
  201608. {
  201609. }
  201610. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201611. END_JUCE_NAMESPACE
  201612. @interface JuceAlertBoxDelegate : NSObject
  201613. {
  201614. @public
  201615. bool clickedOk;
  201616. }
  201617. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex;
  201618. @end
  201619. @implementation JuceAlertBoxDelegate
  201620. - (void) alertView: (UIAlertView*) alertView clickedButtonAtIndex: (NSInteger) buttonIndex
  201621. {
  201622. clickedOk = (buttonIndex == 0);
  201623. alertView.hidden = true;
  201624. }
  201625. @end
  201626. BEGIN_JUCE_NAMESPACE
  201627. // (This function is used directly by other bits of code)
  201628. bool juce_iPhoneShowModalAlert (const String& title,
  201629. const String& bodyText,
  201630. NSString* okButtonText,
  201631. NSString* cancelButtonText)
  201632. {
  201633. const ScopedAutoReleasePool pool;
  201634. JuceAlertBoxDelegate* callback = [[JuceAlertBoxDelegate alloc] init];
  201635. UIAlertView* alert = [[UIAlertView alloc] initWithTitle: juceStringToNS (title)
  201636. message: juceStringToNS (bodyText)
  201637. delegate: callback
  201638. cancelButtonTitle: okButtonText
  201639. otherButtonTitles: cancelButtonText, nil];
  201640. [alert retain];
  201641. [alert show];
  201642. while (! alert.hidden && alert.superview != nil)
  201643. [[NSRunLoop mainRunLoop] runUntilDate: [NSDate dateWithTimeIntervalSinceNow: 0.01]];
  201644. const bool result = callback->clickedOk;
  201645. [alert release];
  201646. [callback release];
  201647. return result;
  201648. }
  201649. bool AlertWindow::showNativeDialogBox (const String& title,
  201650. const String& bodyText,
  201651. bool isOkCancel)
  201652. {
  201653. return juce_iPhoneShowModalAlert (title, bodyText,
  201654. @"OK",
  201655. isOkCancel ? @"Cancel" : nil);
  201656. }
  201657. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201658. {
  201659. jassertfalse // no such thing on the iphone!
  201660. return false;
  201661. }
  201662. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201663. {
  201664. jassertfalse // no such thing on the iphone!
  201665. return false;
  201666. }
  201667. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201668. {
  201669. [[UIApplication sharedApplication] setIdleTimerDisabled: ! isEnabled];
  201670. }
  201671. bool Desktop::isScreenSaverEnabled() throw()
  201672. {
  201673. return ! [[UIApplication sharedApplication] isIdleTimerDisabled];
  201674. }
  201675. void juce_updateMultiMonitorInfo (Array <Rectangle <int> >& monitorCoords, const bool clipToWorkArea)
  201676. {
  201677. const ScopedAutoReleasePool pool;
  201678. monitorCoords.clear();
  201679. CGRect r = clipToWorkArea ? [[UIScreen mainScreen] applicationFrame]
  201680. : [[UIScreen mainScreen] bounds];
  201681. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201682. (int) r.origin.y,
  201683. (int) r.size.width,
  201684. (int) r.size.height));
  201685. }
  201686. #endif
  201687. #endif
  201688. /*** End of inlined file: juce_iphone_MiscUtilities.mm ***/
  201689. #else
  201690. /*** Start of inlined file: juce_mac_MiscUtilities.mm ***/
  201691. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201692. // compiled on its own).
  201693. #if JUCE_INCLUDED_FILE
  201694. ScopedAutoReleasePool::ScopedAutoReleasePool()
  201695. {
  201696. pool = [[NSAutoreleasePool alloc] init];
  201697. }
  201698. ScopedAutoReleasePool::~ScopedAutoReleasePool()
  201699. {
  201700. [((NSAutoreleasePool*) pool) release];
  201701. }
  201702. void PlatformUtilities::beep()
  201703. {
  201704. NSBeep();
  201705. }
  201706. void PlatformUtilities::addItemToDock (const File& file)
  201707. {
  201708. // check that it's not already there...
  201709. if (! juce_getOutputFromCommand ("defaults read com.apple.dock persistent-apps")
  201710. .containsIgnoreCase (file.getFullPathName()))
  201711. {
  201712. 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>"
  201713. + file.getFullPathName() + "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>\"");
  201714. juce_runSystemCommand ("osascript -e \"tell application \\\"Dock\\\" to quit\"");
  201715. }
  201716. }
  201717. int PlatformUtilities::getOSXMinorVersionNumber()
  201718. {
  201719. SInt32 versionMinor = 0;
  201720. OSErr err = Gestalt (gestaltSystemVersionMinor, &versionMinor);
  201721. (void) err;
  201722. jassert (err == noErr);
  201723. return (int) versionMinor;
  201724. }
  201725. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201726. bool AlertWindow::showNativeDialogBox (const String& title,
  201727. const String& bodyText,
  201728. bool isOkCancel)
  201729. {
  201730. const ScopedAutoReleasePool pool;
  201731. return NSRunAlertPanel (juceStringToNS (title),
  201732. juceStringToNS (bodyText),
  201733. @"Ok",
  201734. isOkCancel ? @"Cancel" : nil,
  201735. nil) == NSAlertDefaultReturn;
  201736. }
  201737. bool DragAndDropContainer::performExternalDragDropOfFiles (const StringArray& files, const bool canMoveFiles)
  201738. {
  201739. if (files.size() == 0)
  201740. return false;
  201741. Component* sourceComp = Component::getComponentUnderMouse();
  201742. if (sourceComp == 0)
  201743. {
  201744. jassertfalse // this method must be called in response to a
  201745. // component's mouseDrag event!
  201746. return false;
  201747. }
  201748. const ScopedAutoReleasePool pool;
  201749. NSView* view = (NSView*) sourceComp->getWindowHandle();
  201750. if (view == 0)
  201751. return false;
  201752. NSPasteboard* pboard = [NSPasteboard pasteboardWithName: NSDragPboard];
  201753. [pboard declareTypes: [NSArray arrayWithObject: NSFilenamesPboardType]
  201754. owner: nil];
  201755. NSMutableArray* filesArray = [NSMutableArray arrayWithCapacity: 4];
  201756. for (int i = 0; i < files.size(); ++i)
  201757. [filesArray addObject: juceStringToNS (files[i])];
  201758. [pboard setPropertyList: filesArray
  201759. forType: NSFilenamesPboardType];
  201760. NSPoint dragPosition = [view convertPoint: [[[view window] currentEvent] locationInWindow]
  201761. fromView: nil];
  201762. dragPosition.x -= 16;
  201763. dragPosition.y -= 16;
  201764. [view dragImage: [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (files[0])]
  201765. at: dragPosition
  201766. offset: NSMakeSize (0, 0)
  201767. event: [[view window] currentEvent]
  201768. pasteboard: pboard
  201769. source: view
  201770. slideBack: YES];
  201771. return true;
  201772. }
  201773. bool DragAndDropContainer::performExternalDragDropOfText (const String& text)
  201774. {
  201775. jassertfalse // not implemented!
  201776. return false;
  201777. }
  201778. bool Desktop::canUseSemiTransparentWindows() throw()
  201779. {
  201780. return true;
  201781. }
  201782. const Point<int> Desktop::getMousePosition()
  201783. {
  201784. const ScopedAutoReleasePool pool;
  201785. const NSPoint p ([NSEvent mouseLocation]);
  201786. return Point<int> (roundToInt (p.x), roundToInt ([[[NSScreen screens] objectAtIndex: 0] frame].size.height - p.y));
  201787. }
  201788. void Desktop::setMousePosition (const Point<int>& newPosition)
  201789. {
  201790. // this rubbish needs to be done around the warp call, to avoid causing a
  201791. // bizarre glitch..
  201792. CGAssociateMouseAndMouseCursorPosition (false);
  201793. CGWarpMouseCursorPosition (CGPointMake (newPosition.getX(), newPosition.getY()));
  201794. CGAssociateMouseAndMouseCursorPosition (true);
  201795. }
  201796. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201797. class ScreenSaverDefeater : public Timer,
  201798. public DeletedAtShutdown
  201799. {
  201800. public:
  201801. ScreenSaverDefeater() throw()
  201802. {
  201803. startTimer (10000);
  201804. timerCallback();
  201805. }
  201806. ~ScreenSaverDefeater() {}
  201807. void timerCallback()
  201808. {
  201809. if (Process::isForegroundProcess())
  201810. UpdateSystemActivity (UsrActivity);
  201811. }
  201812. };
  201813. static ScreenSaverDefeater* screenSaverDefeater = 0;
  201814. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201815. {
  201816. if (isEnabled)
  201817. {
  201818. deleteAndZero (screenSaverDefeater);
  201819. }
  201820. else if (screenSaverDefeater == 0)
  201821. {
  201822. screenSaverDefeater = new ScreenSaverDefeater();
  201823. }
  201824. }
  201825. bool Desktop::isScreenSaverEnabled() throw()
  201826. {
  201827. return screenSaverDefeater == 0;
  201828. }
  201829. #else
  201830. static IOPMAssertionID screenSaverDisablerID = 0;
  201831. void Desktop::setScreenSaverEnabled (const bool isEnabled) throw()
  201832. {
  201833. if (isEnabled)
  201834. {
  201835. if (screenSaverDisablerID != 0)
  201836. {
  201837. IOPMAssertionRelease (screenSaverDisablerID);
  201838. screenSaverDisablerID = 0;
  201839. }
  201840. }
  201841. else
  201842. {
  201843. if (screenSaverDisablerID == 0)
  201844. {
  201845. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  201846. IOPMAssertionCreateWithName (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201847. CFSTR ("Juce"), &screenSaverDisablerID);
  201848. #else
  201849. IOPMAssertionCreate (kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn,
  201850. &screenSaverDisablerID);
  201851. #endif
  201852. }
  201853. }
  201854. }
  201855. bool Desktop::isScreenSaverEnabled() throw()
  201856. {
  201857. return screenSaverDisablerID == 0;
  201858. }
  201859. #endif
  201860. void juce_updateMultiMonitorInfo (Array <Rectangle<int> >& monitorCoords, const bool clipToWorkArea)
  201861. {
  201862. const ScopedAutoReleasePool pool;
  201863. monitorCoords.clear();
  201864. NSArray* screens = [NSScreen screens];
  201865. const CGFloat mainScreenBottom = [[[NSScreen screens] objectAtIndex: 0] frame].size.height;
  201866. for (unsigned int i = 0; i < [screens count]; ++i)
  201867. {
  201868. NSScreen* s = (NSScreen*) [screens objectAtIndex: i];
  201869. NSRect r = clipToWorkArea ? [s visibleFrame]
  201870. : [s frame];
  201871. monitorCoords.add (Rectangle<int> ((int) r.origin.x,
  201872. (int) (mainScreenBottom - (r.origin.y + r.size.height)),
  201873. (int) r.size.width,
  201874. (int) r.size.height));
  201875. }
  201876. jassert (monitorCoords.size() > 0);
  201877. }
  201878. #endif
  201879. #endif
  201880. /*** End of inlined file: juce_mac_MiscUtilities.mm ***/
  201881. #endif
  201882. /*** Start of inlined file: juce_mac_Debugging.mm ***/
  201883. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201884. // compiled on its own).
  201885. #if JUCE_INCLUDED_FILE
  201886. void Logger::outputDebugString (const String& text) throw()
  201887. {
  201888. std::cerr << (const char*) text.toUTF8() << std::endl;
  201889. }
  201890. void Logger::outputDebugPrintf (const tchar* format, ...) throw()
  201891. {
  201892. String text;
  201893. va_list args;
  201894. va_start (args, format);
  201895. text.vprintf (format, args);
  201896. outputDebugString (text);
  201897. }
  201898. bool JUCE_PUBLIC_FUNCTION juce_isRunningUnderDebugger()
  201899. {
  201900. static char testResult = 0;
  201901. if (testResult == 0)
  201902. {
  201903. struct kinfo_proc info;
  201904. int m[] = { CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid() };
  201905. size_t sz = sizeof (info);
  201906. sysctl (m, 4, &info, &sz, 0, 0);
  201907. testResult = ((info.kp_proc.p_flag & P_TRACED) != 0) ? 1 : -1;
  201908. }
  201909. return testResult > 0;
  201910. }
  201911. bool JUCE_CALLTYPE Process::isRunningUnderDebugger()
  201912. {
  201913. return juce_isRunningUnderDebugger();
  201914. }
  201915. #endif
  201916. /*** End of inlined file: juce_mac_Debugging.mm ***/
  201917. #if ! JUCE_ONLY_BUILD_CORE_LIBRARY
  201918. #if JUCE_IPHONE
  201919. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  201920. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  201921. // compiled on its own).
  201922. #if JUCE_INCLUDED_FILE
  201923. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  201924. #define SUPPORT_10_4_FONTS 1
  201925. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  201926. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  201927. #define SUPPORT_ONLY_10_4_FONTS 1
  201928. #endif
  201929. END_JUCE_NAMESPACE
  201930. @interface NSFont (PrivateHack)
  201931. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  201932. @end
  201933. BEGIN_JUCE_NAMESPACE
  201934. #endif
  201935. class MacTypeface : public Typeface
  201936. {
  201937. public:
  201938. MacTypeface (const Font& font)
  201939. : Typeface (font.getTypefaceName())
  201940. {
  201941. const ScopedAutoReleasePool pool;
  201942. renderingTransform = CGAffineTransformIdentity;
  201943. bool needsItalicTransform = false;
  201944. #if JUCE_IPHONE
  201945. NSString* fontName = juceStringToNS (font.getTypefaceName());
  201946. if (font.isItalic() || font.isBold())
  201947. {
  201948. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  201949. for (NSString* i in familyFonts)
  201950. {
  201951. const String fn (nsStringToJuce (i));
  201952. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  201953. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  201954. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  201955. || afterDash.containsIgnoreCase (T("italic"))
  201956. || fn.endsWithIgnoreCase (T("oblique"))
  201957. || fn.endsWithIgnoreCase (T("italic"));
  201958. if (probablyBold == font.isBold()
  201959. && probablyItalic == font.isItalic())
  201960. {
  201961. fontName = i;
  201962. needsItalicTransform = false;
  201963. break;
  201964. }
  201965. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  201966. {
  201967. fontName = i;
  201968. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  201969. }
  201970. }
  201971. if (needsItalicTransform)
  201972. renderingTransform.c = 0.15f;
  201973. }
  201974. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  201975. const int ascender = abs (CGFontGetAscent (fontRef));
  201976. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  201977. ascent = ascender / totalHeight;
  201978. unitsToHeightScaleFactor = 1.0f / totalHeight;
  201979. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  201980. #else
  201981. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  201982. if (font.isItalic())
  201983. {
  201984. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  201985. toHaveTrait: NSItalicFontMask];
  201986. if (newFont == nsFont)
  201987. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  201988. nsFont = newFont;
  201989. }
  201990. if (font.isBold())
  201991. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  201992. [nsFont retain];
  201993. ascent = fabsf ((float) [nsFont ascender]);
  201994. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  201995. ascent /= totalSize;
  201996. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  201997. if (needsItalicTransform)
  201998. {
  201999. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  202000. renderingTransform.c = 0.15f;
  202001. }
  202002. #if SUPPORT_ONLY_10_4_FONTS
  202003. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202004. if (atsFont == 0)
  202005. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202006. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  202007. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  202008. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202009. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  202010. #else
  202011. #if SUPPORT_10_4_FONTS
  202012. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202013. {
  202014. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202015. if (atsFont == 0)
  202016. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  202017. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  202018. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  202019. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202020. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  202021. }
  202022. else
  202023. #endif
  202024. {
  202025. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  202026. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  202027. unitsToHeightScaleFactor = 1.0f / totalHeight;
  202028. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  202029. }
  202030. #endif
  202031. #endif
  202032. }
  202033. ~MacTypeface()
  202034. {
  202035. #if ! JUCE_IPHONE
  202036. [nsFont release];
  202037. #endif
  202038. if (fontRef != 0)
  202039. CGFontRelease (fontRef);
  202040. }
  202041. float getAscent() const
  202042. {
  202043. return ascent;
  202044. }
  202045. float getDescent() const
  202046. {
  202047. return 1.0f - ascent;
  202048. }
  202049. float getStringWidth (const String& text)
  202050. {
  202051. if (fontRef == 0 || text.isEmpty())
  202052. return 0;
  202053. const int length = text.length();
  202054. HeapBlock <CGGlyph> glyphs;
  202055. createGlyphsForString (text, length, glyphs);
  202056. float x = 0;
  202057. #if SUPPORT_ONLY_10_4_FONTS
  202058. HeapBlock <NSSize> advances (length);
  202059. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202060. for (int i = 0; i < length; ++i)
  202061. x += advances[i].width;
  202062. #else
  202063. #if SUPPORT_10_4_FONTS
  202064. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202065. {
  202066. HeapBlock <NSSize> advances (length);
  202067. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202068. for (int i = 0; i < length; ++i)
  202069. x += advances[i].width;
  202070. }
  202071. else
  202072. #endif
  202073. {
  202074. HeapBlock <int> advances (length);
  202075. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  202076. for (int i = 0; i < length; ++i)
  202077. x += advances[i];
  202078. }
  202079. #endif
  202080. return x * unitsToHeightScaleFactor;
  202081. }
  202082. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  202083. {
  202084. xOffsets.add (0);
  202085. if (fontRef == 0 || text.isEmpty())
  202086. return;
  202087. const int length = text.length();
  202088. HeapBlock <CGGlyph> glyphs;
  202089. createGlyphsForString (text, length, glyphs);
  202090. #if SUPPORT_ONLY_10_4_FONTS
  202091. HeapBlock <NSSize> advances (length);
  202092. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202093. int x = 0;
  202094. for (int i = 0; i < length; ++i)
  202095. {
  202096. x += advances[i].width;
  202097. xOffsets.add (x * unitsToHeightScaleFactor);
  202098. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  202099. }
  202100. #else
  202101. #if SUPPORT_10_4_FONTS
  202102. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202103. {
  202104. HeapBlock <NSSize> advances (length);
  202105. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  202106. float x = 0;
  202107. for (int i = 0; i < length; ++i)
  202108. {
  202109. x += advances[i].width;
  202110. xOffsets.add (x * unitsToHeightScaleFactor);
  202111. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  202112. }
  202113. }
  202114. else
  202115. #endif
  202116. {
  202117. HeapBlock <int> advances (length);
  202118. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  202119. {
  202120. int x = 0;
  202121. for (int i = 0; i < length; ++i)
  202122. {
  202123. x += advances [i];
  202124. xOffsets.add (x * unitsToHeightScaleFactor);
  202125. resultGlyphs.add (glyphs[i]);
  202126. }
  202127. }
  202128. }
  202129. #endif
  202130. }
  202131. bool getOutlineForGlyph (int glyphNumber, Path& path)
  202132. {
  202133. #if JUCE_IPHONE
  202134. return false;
  202135. #else
  202136. if (nsFont == 0)
  202137. return false;
  202138. // we might need to apply a transform to the path, so it mustn't have anything else in it
  202139. jassert (path.isEmpty());
  202140. const ScopedAutoReleasePool pool;
  202141. NSBezierPath* bez = [NSBezierPath bezierPath];
  202142. [bez moveToPoint: NSMakePoint (0, 0)];
  202143. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  202144. inFont: nsFont];
  202145. for (int i = 0; i < [bez elementCount]; ++i)
  202146. {
  202147. NSPoint p[3];
  202148. switch ([bez elementAtIndex: i associatedPoints: p])
  202149. {
  202150. case NSMoveToBezierPathElement:
  202151. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  202152. break;
  202153. case NSLineToBezierPathElement:
  202154. path.lineTo ((float) p[0].x, (float) -p[0].y);
  202155. break;
  202156. case NSCurveToBezierPathElement:
  202157. 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);
  202158. break;
  202159. case NSClosePathBezierPathElement:
  202160. path.closeSubPath();
  202161. break;
  202162. default:
  202163. jassertfalse
  202164. break;
  202165. }
  202166. }
  202167. path.applyTransform (pathTransform);
  202168. return true;
  202169. #endif
  202170. }
  202171. juce_UseDebuggingNewOperator
  202172. CGFontRef fontRef;
  202173. float fontHeightToCGSizeFactor;
  202174. CGAffineTransform renderingTransform;
  202175. private:
  202176. float ascent, unitsToHeightScaleFactor;
  202177. #if JUCE_IPHONE
  202178. #else
  202179. NSFont* nsFont;
  202180. AffineTransform pathTransform;
  202181. #endif
  202182. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  202183. {
  202184. #if SUPPORT_10_4_FONTS
  202185. #if ! SUPPORT_ONLY_10_4_FONTS
  202186. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  202187. #endif
  202188. {
  202189. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  202190. NSGlyph* const g = (NSGlyph*) glyphs;
  202191. for (int i = 0; i < length; ++i)
  202192. g[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  202193. return;
  202194. }
  202195. #endif
  202196. #if ! SUPPORT_ONLY_10_4_FONTS
  202197. if (charToGlyphMapper == 0)
  202198. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  202199. glyphs.malloc (length);
  202200. for (int i = 0; i < length; ++i)
  202201. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  202202. #endif
  202203. }
  202204. #if ! SUPPORT_ONLY_10_4_FONTS
  202205. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  202206. class CharToGlyphMapper
  202207. {
  202208. public:
  202209. CharToGlyphMapper (CGFontRef fontRef)
  202210. : segCount (0), endCode (0), startCode (0), idDelta (0),
  202211. idRangeOffset (0), glyphIndexes (0)
  202212. {
  202213. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  202214. if (cmapTable != 0)
  202215. {
  202216. const int numSubtables = getValue16 (cmapTable, 2);
  202217. for (int i = 0; i < numSubtables; ++i)
  202218. {
  202219. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  202220. {
  202221. const int offset = getValue32 (cmapTable, i * 8 + 8);
  202222. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  202223. {
  202224. const int length = getValue16 (cmapTable, offset + 2);
  202225. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  202226. segCount = segCountX2 / 2;
  202227. const int endCodeOffset = offset + 14;
  202228. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  202229. const int idDeltaOffset = startCodeOffset + segCountX2;
  202230. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  202231. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  202232. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  202233. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  202234. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  202235. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  202236. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  202237. }
  202238. break;
  202239. }
  202240. }
  202241. CFRelease (cmapTable);
  202242. }
  202243. }
  202244. ~CharToGlyphMapper()
  202245. {
  202246. if (endCode != 0)
  202247. {
  202248. CFRelease (endCode);
  202249. CFRelease (startCode);
  202250. CFRelease (idDelta);
  202251. CFRelease (idRangeOffset);
  202252. CFRelease (glyphIndexes);
  202253. }
  202254. }
  202255. int getGlyphForCharacter (const juce_wchar c) const
  202256. {
  202257. for (int i = 0; i < segCount; ++i)
  202258. {
  202259. if (getValue16 (endCode, i * 2) >= c)
  202260. {
  202261. const int start = getValue16 (startCode, i * 2);
  202262. if (start > c)
  202263. break;
  202264. const int delta = getValue16 (idDelta, i * 2);
  202265. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  202266. if (rangeOffset == 0)
  202267. return delta + c;
  202268. else
  202269. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  202270. }
  202271. }
  202272. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  202273. return jmax (-1, c - 29);
  202274. }
  202275. private:
  202276. int segCount;
  202277. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  202278. static uint16 getValue16 (CFDataRef data, const int index)
  202279. {
  202280. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  202281. }
  202282. static uint32 getValue32 (CFDataRef data, const int index)
  202283. {
  202284. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  202285. }
  202286. };
  202287. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  202288. #endif
  202289. };
  202290. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  202291. {
  202292. return new MacTypeface (font);
  202293. }
  202294. const StringArray Font::findAllTypefaceNames() throw()
  202295. {
  202296. StringArray names;
  202297. const ScopedAutoReleasePool pool;
  202298. #if JUCE_IPHONE
  202299. NSArray* fonts = [UIFont familyNames];
  202300. #else
  202301. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  202302. #endif
  202303. for (unsigned int i = 0; i < [fonts count]; ++i)
  202304. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  202305. names.sort (true);
  202306. return names;
  202307. }
  202308. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  202309. {
  202310. #if JUCE_IPHONE
  202311. defaultSans = "Helvetica";
  202312. defaultSerif = "Times New Roman";
  202313. defaultFixed = "Courier New";
  202314. #else
  202315. defaultSans = "Lucida Grande";
  202316. defaultSerif = "Times New Roman";
  202317. defaultFixed = "Monaco";
  202318. #endif
  202319. }
  202320. #endif
  202321. /*** End of inlined file: juce_mac_Fonts.mm ***/
  202322. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202323. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202324. // compiled on its own).
  202325. #if JUCE_INCLUDED_FILE
  202326. class CoreGraphicsImage : public Image
  202327. {
  202328. public:
  202329. CoreGraphicsImage (const PixelFormat format_,
  202330. const int imageWidth_,
  202331. const int imageHeight_,
  202332. const bool clearImage)
  202333. : Image (format_, imageWidth_, imageHeight_, clearImage)
  202334. {
  202335. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  202336. : CGColorSpaceCreateDeviceRGB();
  202337. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  202338. colourSpace, getCGImageFlags (*this));
  202339. CGColorSpaceRelease (colourSpace);
  202340. }
  202341. ~CoreGraphicsImage()
  202342. {
  202343. CGContextRelease (context);
  202344. }
  202345. LowLevelGraphicsContext* createLowLevelContext();
  202346. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  202347. {
  202348. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  202349. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  202350. {
  202351. return CGBitmapContextCreateImage (nativeImage->context);
  202352. }
  202353. else
  202354. {
  202355. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  202356. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  202357. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  202358. 8, srcData.pixelStride * 8, srcData.lineStride,
  202359. colourSpace, getCGImageFlags (juceImage), provider,
  202360. 0, true, kCGRenderingIntentDefault);
  202361. CGDataProviderRelease (provider);
  202362. return imageRef;
  202363. }
  202364. }
  202365. #if JUCE_MAC
  202366. static NSImage* createNSImage (const Image& image)
  202367. {
  202368. const ScopedAutoReleasePool pool;
  202369. NSImage* im = [[NSImage alloc] init];
  202370. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  202371. [im lockFocus];
  202372. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  202373. CGImageRef imageRef = createImage (image, false, colourSpace);
  202374. CGColorSpaceRelease (colourSpace);
  202375. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  202376. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  202377. CGImageRelease (imageRef);
  202378. [im unlockFocus];
  202379. return im;
  202380. }
  202381. #endif
  202382. CGContextRef context;
  202383. private:
  202384. static CGBitmapInfo getCGImageFlags (const Image& image)
  202385. {
  202386. #if JUCE_BIG_ENDIAN
  202387. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  202388. #else
  202389. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  202390. #endif
  202391. }
  202392. };
  202393. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  202394. {
  202395. #if USE_COREGRAPHICS_RENDERING
  202396. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  202397. #else
  202398. return new Image (format, imageWidth, imageHeight, clearImage);
  202399. #endif
  202400. }
  202401. class CoreGraphicsContext : public LowLevelGraphicsContext
  202402. {
  202403. public:
  202404. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  202405. : context (context_),
  202406. flipHeight (flipHeight_),
  202407. numGradientLookupEntries (0)
  202408. {
  202409. CGContextRetain (context);
  202410. CGContextSaveGState(context);
  202411. CGContextSetShouldSmoothFonts (context, true);
  202412. CGContextSetShouldAntialias (context, true);
  202413. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202414. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  202415. greyColourSpace = CGColorSpaceCreateDeviceGray();
  202416. gradientCallbacks.version = 0;
  202417. gradientCallbacks.evaluate = gradientCallback;
  202418. gradientCallbacks.releaseInfo = 0;
  202419. state = new SavedState();
  202420. }
  202421. ~CoreGraphicsContext()
  202422. {
  202423. CGContextRestoreGState (context);
  202424. CGContextRelease (context);
  202425. CGColorSpaceRelease (rgbColourSpace);
  202426. CGColorSpaceRelease (greyColourSpace);
  202427. }
  202428. bool isVectorDevice() const { return false; }
  202429. void setOrigin (int x, int y)
  202430. {
  202431. CGContextTranslateCTM (context, x, -y);
  202432. }
  202433. bool clipToRectangle (const Rectangle<int>& r)
  202434. {
  202435. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  202436. return ! isClipEmpty();
  202437. }
  202438. bool clipToRectangleList (const RectangleList& clipRegion)
  202439. {
  202440. if (clipRegion.isEmpty())
  202441. {
  202442. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  202443. return false;
  202444. }
  202445. else
  202446. {
  202447. const int numRects = clipRegion.getNumRectangles();
  202448. HeapBlock <CGRect> rects (numRects);
  202449. for (int i = 0; i < numRects; ++i)
  202450. {
  202451. const Rectangle<int>& r = clipRegion.getRectangle(i);
  202452. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202453. }
  202454. CGContextClipToRects (context, rects, numRects);
  202455. return ! isClipEmpty();
  202456. }
  202457. }
  202458. void excludeClipRectangle (const Rectangle<int>& r)
  202459. {
  202460. RectangleList remaining (getClipBounds());
  202461. remaining.subtract (r);
  202462. clipToRectangleList (remaining);
  202463. }
  202464. void clipToPath (const Path& path, const AffineTransform& transform)
  202465. {
  202466. createPath (path, transform);
  202467. CGContextClip (context);
  202468. }
  202469. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  202470. {
  202471. if (! transform.isSingularity())
  202472. {
  202473. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  202474. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  202475. flip();
  202476. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  202477. applyTransform (t);
  202478. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  202479. CGContextClipToMask (context, r, image);
  202480. applyTransform (t.inverted());
  202481. flip();
  202482. CGImageRelease (image);
  202483. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  202484. }
  202485. }
  202486. bool clipRegionIntersects (const Rectangle<int>& r)
  202487. {
  202488. return getClipBounds().intersects (r);
  202489. }
  202490. const Rectangle<int> getClipBounds() const
  202491. {
  202492. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202493. return Rectangle<int> (roundToInt (bounds.origin.x),
  202494. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  202495. roundToInt (bounds.size.width),
  202496. roundToInt (bounds.size.height));
  202497. }
  202498. bool isClipEmpty() const
  202499. {
  202500. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  202501. }
  202502. void saveState()
  202503. {
  202504. CGContextSaveGState (context);
  202505. stateStack.add (new SavedState (*state));
  202506. }
  202507. void restoreState()
  202508. {
  202509. CGContextRestoreGState (context);
  202510. SavedState* const top = stateStack.getLast();
  202511. if (top != 0)
  202512. {
  202513. state = top;
  202514. stateStack.removeLast (1, false);
  202515. }
  202516. else
  202517. {
  202518. jassertfalse // trying to pop with an empty stack!
  202519. }
  202520. }
  202521. void setFill (const FillType& fillType)
  202522. {
  202523. state->fillType = fillType;
  202524. if (fillType.isColour())
  202525. {
  202526. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  202527. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  202528. CGContextSetAlpha (context, 1.0f);
  202529. }
  202530. }
  202531. void setOpacity (float newOpacity)
  202532. {
  202533. state->fillType.setOpacity (newOpacity);
  202534. setFill (state->fillType);
  202535. }
  202536. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  202537. {
  202538. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  202539. ? kCGInterpolationLow
  202540. : kCGInterpolationHigh);
  202541. }
  202542. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  202543. {
  202544. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  202545. if (replaceExistingContents)
  202546. {
  202547. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  202548. CGContextClearRect (context, cgRect);
  202549. #else
  202550. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  202551. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  202552. CGContextClearRect (context, cgRect);
  202553. else
  202554. #endif
  202555. CGContextSetBlendMode (context, kCGBlendModeCopy);
  202556. #endif
  202557. fillRect (r, false);
  202558. CGContextSetBlendMode (context, kCGBlendModeNormal);
  202559. }
  202560. else
  202561. {
  202562. if (state->fillType.isColour())
  202563. {
  202564. CGContextFillRect (context, cgRect);
  202565. }
  202566. else if (state->fillType.isGradient())
  202567. {
  202568. CGContextSaveGState (context);
  202569. CGContextClipToRect (context, cgRect);
  202570. drawGradient();
  202571. CGContextRestoreGState (context);
  202572. }
  202573. else
  202574. {
  202575. CGContextSaveGState (context);
  202576. CGContextClipToRect (context, cgRect);
  202577. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202578. CGContextRestoreGState (context);
  202579. }
  202580. }
  202581. }
  202582. void fillPath (const Path& path, const AffineTransform& transform)
  202583. {
  202584. CGContextSaveGState (context);
  202585. if (state->fillType.isColour())
  202586. {
  202587. flip();
  202588. applyTransform (transform);
  202589. createPath (path);
  202590. if (path.isUsingNonZeroWinding())
  202591. CGContextFillPath (context);
  202592. else
  202593. CGContextEOFillPath (context);
  202594. }
  202595. else
  202596. {
  202597. createPath (path, transform);
  202598. if (path.isUsingNonZeroWinding())
  202599. CGContextClip (context);
  202600. else
  202601. CGContextEOClip (context);
  202602. if (state->fillType.isGradient())
  202603. drawGradient();
  202604. else
  202605. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  202606. }
  202607. CGContextRestoreGState (context);
  202608. }
  202609. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  202610. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  202611. {
  202612. jassert (sourceImage.getBounds().contains (srcClip));
  202613. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  202614. CGImageRef image = fullImage;
  202615. if (srcClip != sourceImage.getBounds())
  202616. {
  202617. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  202618. srcClip.getWidth(), srcClip.getHeight()));
  202619. CGImageRelease (fullImage);
  202620. }
  202621. CGContextSaveGState (context);
  202622. CGContextSetAlpha (context, state->fillType.getOpacity());
  202623. flip();
  202624. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  202625. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  202626. if (fillEntireClipAsTiles)
  202627. {
  202628. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  202629. CGContextDrawTiledImage (context, imageRect, image);
  202630. #else
  202631. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  202632. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  202633. // if it's doing a transformation - it's quicker to just draw lots of images manually
  202634. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  202635. CGContextDrawTiledImage (context, imageRect, image);
  202636. else
  202637. #endif
  202638. {
  202639. // Fallback to manually doing a tiled fill on 10.4
  202640. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  202641. const int iw = srcClip.getWidth();
  202642. const int ih = srcClip.getHeight();
  202643. int x = 0, y = 0;
  202644. while (x > clip.origin.x) x -= iw;
  202645. while (y > clip.origin.y) y -= ih;
  202646. const int right = (int) (clip.origin.x + clip.size.width);
  202647. const int bottom = (int) (clip.origin.y + clip.size.height);
  202648. while (y < bottom)
  202649. {
  202650. for (int x2 = x; x2 < right; x2 += iw)
  202651. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  202652. y += ih;
  202653. }
  202654. }
  202655. #endif
  202656. }
  202657. else
  202658. {
  202659. CGContextDrawImage (context, imageRect, image);
  202660. }
  202661. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  202662. CGContextRestoreGState (context);
  202663. }
  202664. void drawLine (double x1, double y1, double x2, double y2)
  202665. {
  202666. CGContextSetLineCap (context, kCGLineCapSquare);
  202667. CGContextSetLineWidth (context, 1.0f);
  202668. CGContextSetRGBStrokeColor (context,
  202669. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  202670. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  202671. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  202672. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  202673. CGContextStrokeLineSegments (context, line, 1);
  202674. }
  202675. void drawVerticalLine (const int x, double top, double bottom)
  202676. {
  202677. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202678. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  202679. #else
  202680. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202681. // the x co-ord slightly to trick it..
  202682. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  202683. #endif
  202684. }
  202685. void drawHorizontalLine (const int y, double left, double right)
  202686. {
  202687. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  202688. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  202689. #else
  202690. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  202691. // the x co-ord slightly to trick it..
  202692. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  202693. #endif
  202694. }
  202695. void setFont (const Font& newFont)
  202696. {
  202697. if (state->font != newFont)
  202698. {
  202699. state->fontRef = 0;
  202700. state->font = newFont;
  202701. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  202702. if (mf != 0)
  202703. {
  202704. state->fontRef = mf->fontRef;
  202705. CGContextSetFont (context, state->fontRef);
  202706. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  202707. state->fontTransform = mf->renderingTransform;
  202708. state->fontTransform.a *= state->font.getHorizontalScale();
  202709. CGContextSetTextMatrix (context, state->fontTransform);
  202710. }
  202711. }
  202712. }
  202713. const Font getFont()
  202714. {
  202715. return state->font;
  202716. }
  202717. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  202718. {
  202719. if (state->fontRef != 0 && state->fillType.isColour())
  202720. {
  202721. if (transform.isOnlyTranslation())
  202722. {
  202723. CGGlyph g = glyphNumber;
  202724. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  202725. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  202726. }
  202727. else
  202728. {
  202729. CGContextSaveGState (context);
  202730. flip();
  202731. applyTransform (transform);
  202732. CGAffineTransform t = state->fontTransform;
  202733. t.d = -t.d;
  202734. CGContextSetTextMatrix (context, t);
  202735. CGGlyph g = glyphNumber;
  202736. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  202737. CGContextSetTextMatrix (context, state->fontTransform);
  202738. CGContextRestoreGState (context);
  202739. }
  202740. }
  202741. else
  202742. {
  202743. Path p;
  202744. Font& f = state->font;
  202745. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  202746. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  202747. .followedBy (transform));
  202748. }
  202749. }
  202750. private:
  202751. CGContextRef context;
  202752. const float flipHeight;
  202753. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  202754. CGFunctionCallbacks gradientCallbacks;
  202755. struct SavedState
  202756. {
  202757. SavedState()
  202758. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  202759. {
  202760. }
  202761. SavedState (const SavedState& other)
  202762. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  202763. fontTransform (other.fontTransform)
  202764. {
  202765. }
  202766. ~SavedState()
  202767. {
  202768. }
  202769. FillType fillType;
  202770. Font font;
  202771. CGFontRef fontRef;
  202772. CGAffineTransform fontTransform;
  202773. };
  202774. ScopedPointer <SavedState> state;
  202775. OwnedArray <SavedState> stateStack;
  202776. HeapBlock <PixelARGB> gradientLookupTable;
  202777. int numGradientLookupEntries;
  202778. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  202779. {
  202780. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  202781. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  202782. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  202783. colour.unpremultiply();
  202784. outData[0] = colour.getRed() / 255.0f;
  202785. outData[1] = colour.getGreen() / 255.0f;
  202786. outData[2] = colour.getBlue() / 255.0f;
  202787. outData[3] = colour.getAlpha() / 255.0f;
  202788. }
  202789. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  202790. {
  202791. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  202792. --numGradientLookupEntries;
  202793. CGShadingRef result = 0;
  202794. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  202795. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  202796. if (gradient.isRadial)
  202797. {
  202798. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  202799. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  202800. function, true, true);
  202801. }
  202802. else
  202803. {
  202804. result = CGShadingCreateAxial (rgbColourSpace, p1,
  202805. CGPointMake (gradient.x2, gradient.y2),
  202806. function, true, true);
  202807. }
  202808. CGFunctionRelease (function);
  202809. return result;
  202810. }
  202811. void drawGradient()
  202812. {
  202813. flip();
  202814. applyTransform (state->fillType.transform);
  202815. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  202816. // you draw a gradient with high quality interp enabled).
  202817. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  202818. CGContextSetAlpha (context, state->fillType.getOpacity());
  202819. CGContextDrawShading (context, shading);
  202820. CGShadingRelease (shading);
  202821. }
  202822. void createPath (const Path& path) const
  202823. {
  202824. CGContextBeginPath (context);
  202825. Path::Iterator i (path);
  202826. while (i.next())
  202827. {
  202828. switch (i.elementType)
  202829. {
  202830. case Path::Iterator::startNewSubPath:
  202831. CGContextMoveToPoint (context, i.x1, i.y1);
  202832. break;
  202833. case Path::Iterator::lineTo:
  202834. CGContextAddLineToPoint (context, i.x1, i.y1);
  202835. break;
  202836. case Path::Iterator::quadraticTo:
  202837. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  202838. break;
  202839. case Path::Iterator::cubicTo:
  202840. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  202841. break;
  202842. case Path::Iterator::closePath:
  202843. CGContextClosePath (context); break;
  202844. default:
  202845. jassertfalse
  202846. break;
  202847. }
  202848. }
  202849. }
  202850. void createPath (const Path& path, const AffineTransform& transform) const
  202851. {
  202852. CGContextBeginPath (context);
  202853. Path::Iterator i (path);
  202854. while (i.next())
  202855. {
  202856. switch (i.elementType)
  202857. {
  202858. case Path::Iterator::startNewSubPath:
  202859. transform.transformPoint (i.x1, i.y1);
  202860. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  202861. break;
  202862. case Path::Iterator::lineTo:
  202863. transform.transformPoint (i.x1, i.y1);
  202864. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  202865. break;
  202866. case Path::Iterator::quadraticTo:
  202867. transform.transformPoint (i.x1, i.y1);
  202868. transform.transformPoint (i.x2, i.y2);
  202869. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  202870. break;
  202871. case Path::Iterator::cubicTo:
  202872. transform.transformPoint (i.x1, i.y1);
  202873. transform.transformPoint (i.x2, i.y2);
  202874. transform.transformPoint (i.x3, i.y3);
  202875. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  202876. break;
  202877. case Path::Iterator::closePath:
  202878. CGContextClosePath (context); break;
  202879. default:
  202880. jassertfalse
  202881. break;
  202882. }
  202883. }
  202884. }
  202885. static Image* createAlphaChannelImage (const Image& im)
  202886. {
  202887. if (im.getFormat() == Image::SingleChannel)
  202888. return const_cast <Image*> (&im);
  202889. return im.createCopyOfAlphaChannel();
  202890. }
  202891. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  202892. {
  202893. if (im.getFormat() != Image::SingleChannel)
  202894. delete alphaIm;
  202895. }
  202896. void flip() const
  202897. {
  202898. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  202899. }
  202900. void applyTransform (const AffineTransform& transform) const
  202901. {
  202902. CGAffineTransform t;
  202903. t.a = transform.mat00;
  202904. t.b = transform.mat10;
  202905. t.c = transform.mat01;
  202906. t.d = transform.mat11;
  202907. t.tx = transform.mat02;
  202908. t.ty = transform.mat12;
  202909. CGContextConcatCTM (context, t);
  202910. }
  202911. float flipY (float y) const
  202912. {
  202913. return flipHeight - y;
  202914. }
  202915. };
  202916. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  202917. {
  202918. return new CoreGraphicsContext (context, imageHeight);
  202919. }
  202920. #endif
  202921. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  202922. /*** Start of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  202923. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  202924. // compiled on its own).
  202925. #if JUCE_INCLUDED_FILE
  202926. class UIViewComponentPeer;
  202927. END_JUCE_NAMESPACE
  202928. #define JuceUIView MakeObjCClassName(JuceUIView)
  202929. @interface JuceUIView : UIView
  202930. {
  202931. @public
  202932. UIViewComponentPeer* owner;
  202933. }
  202934. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner withFrame: (CGRect) frame;
  202935. - (void) dealloc;
  202936. - (void) drawRect: (CGRect) r;
  202937. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event;
  202938. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event;
  202939. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event;
  202940. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event;
  202941. - (BOOL) becomeFirstResponder;
  202942. - (BOOL) resignFirstResponder;
  202943. - (BOOL) canBecomeFirstResponder;
  202944. - (void) asyncRepaint: (id) rect;
  202945. @end
  202946. #define JuceUIWindow MakeObjCClassName(JuceUIWindow)
  202947. @interface JuceUIWindow : UIWindow
  202948. {
  202949. @private
  202950. UIViewComponentPeer* owner;
  202951. bool isZooming;
  202952. }
  202953. - (void) setOwner: (UIViewComponentPeer*) owner;
  202954. - (void) becomeKeyWindow;
  202955. @end
  202956. BEGIN_JUCE_NAMESPACE
  202957. class UIViewComponentPeer : public ComponentPeer
  202958. {
  202959. public:
  202960. UIViewComponentPeer (Component* const component,
  202961. const int windowStyleFlags,
  202962. UIView* viewToAttachTo);
  202963. ~UIViewComponentPeer();
  202964. void* getNativeHandle() const;
  202965. void setVisible (bool shouldBeVisible);
  202966. void setTitle (const String& title);
  202967. void setPosition (int x, int y);
  202968. void setSize (int w, int h);
  202969. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  202970. const Rectangle<int> getBounds() const;
  202971. const Rectangle<int> getBounds (const bool global) const;
  202972. const Point<int> getScreenPosition() const;
  202973. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  202974. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  202975. void setMinimised (bool shouldBeMinimised);
  202976. bool isMinimised() const;
  202977. void setFullScreen (bool shouldBeFullScreen);
  202978. bool isFullScreen() const;
  202979. bool contains (int x, int y, bool trueIfInAChildWindow) const;
  202980. const BorderSize getFrameSize() const;
  202981. bool setAlwaysOnTop (bool alwaysOnTop);
  202982. void toFront (bool makeActiveWindow);
  202983. void toBehind (ComponentPeer* other);
  202984. void setIcon (const Image& newIcon);
  202985. virtual void drawRect (CGRect r);
  202986. virtual bool canBecomeKeyWindow();
  202987. virtual bool windowShouldClose();
  202988. virtual void redirectMovedOrResized();
  202989. virtual CGRect constrainRect (CGRect r);
  202990. virtual void viewFocusGain();
  202991. virtual void viewFocusLoss();
  202992. bool isFocused() const;
  202993. void grabFocus();
  202994. void textInputRequired (const Point<int>& position);
  202995. void repaint (int x, int y, int w, int h);
  202996. void performAnyPendingRepaintsNow();
  202997. juce_UseDebuggingNewOperator
  202998. UIWindow* window;
  202999. JuceUIView* view;
  203000. bool isSharedWindow, fullScreen, insideDrawRect;
  203001. };
  203002. END_JUCE_NAMESPACE
  203003. @implementation JuceUIView
  203004. - (JuceUIView*) initWithOwner: (UIViewComponentPeer*) owner_
  203005. withFrame: (CGRect) frame
  203006. {
  203007. [super initWithFrame: frame];
  203008. owner = owner_;
  203009. return self;
  203010. }
  203011. - (void) dealloc
  203012. {
  203013. [super dealloc];
  203014. }
  203015. - (void) drawRect: (CGRect) r
  203016. {
  203017. if (owner != 0)
  203018. owner->drawRect (r);
  203019. }
  203020. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  203021. {
  203022. return false;
  203023. }
  203024. static int currentModifiers = 0;
  203025. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  203026. {
  203027. return ModifierKeys (currentModifiers);
  203028. }
  203029. void ModifierKeys::updateCurrentModifiers() throw()
  203030. {
  203031. currentModifierFlags = currentModifiers;
  203032. }
  203033. static int getModifierForButtonNumber (const int num)
  203034. {
  203035. return num == 0 ? ModifierKeys::leftButtonModifier
  203036. : (num == 1 ? ModifierKeys::rightButtonModifier
  203037. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  203038. }
  203039. static int64 getMouseTime (UIEvent* e)
  203040. {
  203041. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  203042. + (int64) ([e timestamp] * 1000.0);
  203043. }
  203044. JUCE_NAMESPACE::Point<int> juce_lastMousePos;
  203045. - (void) touchesBegan: (NSSet*) touches withEvent: (UIEvent*) event
  203046. {
  203047. if (owner == 0)
  203048. return;
  203049. NSArray* const t = [[event touchesForView: self] allObjects];
  203050. switch ([t count])
  203051. {
  203052. case 1: // One finger..
  203053. {
  203054. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203055. const JUCE_NAMESPACE::Point<int> pos ((int) p.x, (int) p.y);
  203056. currentModifiers |= getModifierForButtonNumber (0);
  203057. juce_lastMousePos = pos + owner->getScreenPosition();
  203058. owner->handleMouseMove (pos, getMouseTime (event));
  203059. if (owner != 0)
  203060. owner->handleMouseDown (pos, getMouseTime (event));
  203061. }
  203062. default:
  203063. //xxx multi-touch..
  203064. break;
  203065. }
  203066. }
  203067. - (void) touchesMoved: (NSSet*) touches withEvent: (UIEvent*) event
  203068. {
  203069. if (owner == 0)
  203070. return;
  203071. NSArray* const t = [[event touchesForView: self] allObjects];
  203072. switch ([t count])
  203073. {
  203074. case 1: // One finger..
  203075. {
  203076. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203077. const JUCE_NAMESPACE::Point<int> pos ((int) p.x, (int) p.y);
  203078. juce_lastMousePos = pos + owner->getScreenPosition();
  203079. owner->handleMouseDrag (pos, getMouseTime (event));
  203080. }
  203081. default:
  203082. //xxx multi-touch..
  203083. break;
  203084. }
  203085. }
  203086. - (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
  203087. {
  203088. if (owner == 0)
  203089. return;
  203090. NSArray* const t = [[event touchesForView: self] allObjects];
  203091. switch ([t count])
  203092. {
  203093. case 1: // One finger..
  203094. {
  203095. CGPoint p = [[t objectAtIndex: 0] locationInView: self];
  203096. const JUCE_NAMESPACE::Point<int> pos ((int) p.x, (int) p.y);
  203097. juce_lastMousePos = pos + owner->getScreenPosition();
  203098. const int oldMods = currentModifiers;
  203099. currentModifiers &= ~getModifierForButtonNumber (0);
  203100. owner->handleMouseUp (oldMods, pos, getMouseTime (event));
  203101. }
  203102. default:
  203103. //xxx multi-touch..
  203104. break;
  203105. }
  203106. }
  203107. - (void) touchesCancelled: (NSSet*) touches withEvent: (UIEvent*) event
  203108. {
  203109. [self touchesEnded: touches withEvent: event];
  203110. }
  203111. - (BOOL) becomeFirstResponder
  203112. {
  203113. if (owner != 0)
  203114. owner->viewFocusGain();
  203115. return true;
  203116. }
  203117. - (BOOL) resignFirstResponder
  203118. {
  203119. if (owner != 0)
  203120. owner->viewFocusLoss();
  203121. return true;
  203122. }
  203123. - (BOOL) canBecomeFirstResponder
  203124. {
  203125. return owner != 0 && owner->canBecomeKeyWindow();
  203126. }
  203127. - (void) asyncRepaint: (id) rect
  203128. {
  203129. CGRect* r = (CGRect*) [((NSData*) rect) bytes];
  203130. [self setNeedsDisplayInRect: *r];
  203131. }
  203132. @end
  203133. @implementation JuceUIWindow
  203134. - (void) setOwner: (UIViewComponentPeer*) owner_
  203135. {
  203136. owner = owner_;
  203137. isZooming = false;
  203138. }
  203139. - (void) becomeKeyWindow
  203140. {
  203141. [super becomeKeyWindow];
  203142. if (owner != 0)
  203143. owner->grabFocus();
  203144. }
  203145. @end
  203146. BEGIN_JUCE_NAMESPACE
  203147. UIViewComponentPeer::UIViewComponentPeer (Component* const component,
  203148. const int windowStyleFlags,
  203149. UIView* viewToAttachTo)
  203150. : ComponentPeer (component, windowStyleFlags),
  203151. window (0),
  203152. view (0),
  203153. isSharedWindow (viewToAttachTo != 0),
  203154. fullScreen (false),
  203155. insideDrawRect (false)
  203156. {
  203157. CGRect r;
  203158. r.origin.x = 0;
  203159. r.origin.y = 0;
  203160. r.size.width = (float) component->getWidth();
  203161. r.size.height = (float) component->getHeight();
  203162. view = [[JuceUIView alloc] initWithOwner: this withFrame: r];
  203163. if (isSharedWindow)
  203164. {
  203165. window = [viewToAttachTo window];
  203166. [viewToAttachTo addSubview: view];
  203167. setVisible (component->isVisible());
  203168. }
  203169. else
  203170. {
  203171. r.origin.x = (float) component->getX();
  203172. r.origin.y = (float) component->getY();
  203173. r.origin.y = [[UIScreen mainScreen] bounds].size.height - (r.origin.y + r.size.height);
  203174. window = [[JuceUIWindow alloc] init];
  203175. window.frame = r;
  203176. window.opaque = component->isOpaque();
  203177. view.opaque = component->isOpaque();
  203178. window.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  203179. view.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent: 0];
  203180. [((JuceUIWindow*) window) setOwner: this];
  203181. if (component->isAlwaysOnTop())
  203182. window.windowLevel = UIWindowLevelAlert;
  203183. [window addSubview: view];
  203184. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203185. view.hidden = ! component->isVisible();
  203186. window.hidden = ! component->isVisible();
  203187. }
  203188. setTitle (component->getName());
  203189. }
  203190. UIViewComponentPeer::~UIViewComponentPeer()
  203191. {
  203192. view->owner = 0;
  203193. [view removeFromSuperview];
  203194. [view release];
  203195. if (! isSharedWindow)
  203196. {
  203197. [((JuceUIWindow*) window) setOwner: 0];
  203198. [window release];
  203199. }
  203200. }
  203201. void* UIViewComponentPeer::getNativeHandle() const
  203202. {
  203203. return view;
  203204. }
  203205. void UIViewComponentPeer::setVisible (bool shouldBeVisible)
  203206. {
  203207. view.hidden = ! shouldBeVisible;
  203208. if (! isSharedWindow)
  203209. window.hidden = ! shouldBeVisible;
  203210. }
  203211. void UIViewComponentPeer::setTitle (const String& title)
  203212. {
  203213. // xxx is this possible?
  203214. }
  203215. void UIViewComponentPeer::setPosition (int x, int y)
  203216. {
  203217. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  203218. }
  203219. void UIViewComponentPeer::setSize (int w, int h)
  203220. {
  203221. setBounds (component->getX(), component->getY(), w, h, false);
  203222. }
  203223. void UIViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  203224. {
  203225. fullScreen = isNowFullScreen;
  203226. w = jmax (0, w);
  203227. h = jmax (0, h);
  203228. CGRect r;
  203229. r.origin.x = (float) x;
  203230. r.origin.y = (float) y;
  203231. r.size.width = (float) w;
  203232. r.size.height = (float) h;
  203233. if (isSharedWindow)
  203234. {
  203235. //r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  203236. if ([view frame].size.width != r.size.width
  203237. || [view frame].size.height != r.size.height)
  203238. [view setNeedsDisplay];
  203239. view.frame = r;
  203240. }
  203241. else
  203242. {
  203243. window.frame = r;
  203244. view.frame = CGRectMake (0, 0, r.size.width, r.size.height);
  203245. }
  203246. }
  203247. const Rectangle<int> UIViewComponentPeer::getBounds (const bool global) const
  203248. {
  203249. CGRect r = [view frame];
  203250. if (global && [view window] != 0)
  203251. {
  203252. r = [view convertRect: r toView: nil];
  203253. CGRect wr = [[view window] frame];
  203254. r.origin.x += wr.origin.x;
  203255. r.origin.y += wr.origin.y;
  203256. }
  203257. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y,
  203258. (int) r.size.width, (int) r.size.height);
  203259. }
  203260. const Rectangle<int> UIViewComponentPeer::getBounds() const
  203261. {
  203262. return getBounds (! isSharedWindow);
  203263. }
  203264. const Point<int> UIViewComponentPeer::getScreenPosition() const
  203265. {
  203266. return getBounds (true).getPosition();
  203267. }
  203268. const Point<int> UIViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  203269. {
  203270. return relativePosition + getScreenPosition();
  203271. }
  203272. const Point<int> UIViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  203273. {
  203274. return screenPosition - getScreenPosition();
  203275. }
  203276. CGRect UIViewComponentPeer::constrainRect (CGRect r)
  203277. {
  203278. if (constrainer != 0)
  203279. {
  203280. CGRect current = [window frame];
  203281. current.origin.y = [[UIScreen mainScreen] bounds].size.height - current.origin.y - current.size.height;
  203282. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.origin.y - r.size.height;
  203283. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  203284. (int) r.size.width, (int) r.size.height);
  203285. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  203286. (int) current.size.width, (int) current.size.height);
  203287. constrainer->checkBounds (pos, original,
  203288. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  203289. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  203290. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  203291. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  203292. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  203293. r.origin.x = pos.getX();
  203294. r.origin.y = [[UIScreen mainScreen] bounds].size.height - r.size.height - pos.getY();
  203295. r.size.width = pos.getWidth();
  203296. r.size.height = pos.getHeight();
  203297. }
  203298. return r;
  203299. }
  203300. void UIViewComponentPeer::setMinimised (bool shouldBeMinimised)
  203301. {
  203302. // xxx
  203303. }
  203304. bool UIViewComponentPeer::isMinimised() const
  203305. {
  203306. return false;
  203307. }
  203308. void UIViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  203309. {
  203310. if (! isSharedWindow)
  203311. {
  203312. Rectangle<int> r (lastNonFullscreenBounds);
  203313. setMinimised (false);
  203314. if (fullScreen != shouldBeFullScreen)
  203315. {
  203316. if (shouldBeFullScreen)
  203317. r = Desktop::getInstance().getMainMonitorArea();
  203318. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  203319. if (r != getComponent()->getBounds() && ! r.isEmpty())
  203320. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  203321. }
  203322. }
  203323. }
  203324. bool UIViewComponentPeer::isFullScreen() const
  203325. {
  203326. return fullScreen;
  203327. }
  203328. bool UIViewComponentPeer::contains (int x, int y, bool trueIfInAChildWindow) const
  203329. {
  203330. if (((unsigned int) x) >= (unsigned int) component->getWidth()
  203331. || ((unsigned int) y) >= (unsigned int) component->getHeight())
  203332. return false;
  203333. CGPoint p;
  203334. p.x = (float) x;
  203335. p.y = (float) y;
  203336. UIView* v = [view hitTest: p withEvent: nil];
  203337. if (trueIfInAChildWindow)
  203338. return v != nil;
  203339. return v == view;
  203340. }
  203341. const BorderSize UIViewComponentPeer::getFrameSize() const
  203342. {
  203343. BorderSize b;
  203344. if (! isSharedWindow)
  203345. {
  203346. CGRect v = [view convertRect: [view frame] toView: nil];
  203347. CGRect w = [window frame];
  203348. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  203349. b.setBottom ((int) v.origin.y);
  203350. b.setLeft ((int) v.origin.x);
  203351. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  203352. }
  203353. return b;
  203354. }
  203355. bool UIViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  203356. {
  203357. if (! isSharedWindow)
  203358. window.windowLevel = alwaysOnTop ? UIWindowLevelAlert : UIWindowLevelNormal;
  203359. return true;
  203360. }
  203361. void UIViewComponentPeer::toFront (bool makeActiveWindow)
  203362. {
  203363. if (isSharedWindow)
  203364. [[view superview] bringSubviewToFront: view];
  203365. if (window != 0 && component->isVisible())
  203366. [window makeKeyAndVisible];
  203367. }
  203368. void UIViewComponentPeer::toBehind (ComponentPeer* other)
  203369. {
  203370. UIViewComponentPeer* o = (UIViewComponentPeer*) other;
  203371. if (isSharedWindow)
  203372. {
  203373. [[view superview] insertSubview: view belowSubview: o->view];
  203374. }
  203375. else
  203376. {
  203377. jassertfalse // don't know how to do this
  203378. }
  203379. }
  203380. void UIViewComponentPeer::setIcon (const Image& /*newIcon*/)
  203381. {
  203382. // to do..
  203383. }
  203384. static UIViewComponentPeer* currentlyFocusedPeer = 0;
  203385. void UIViewComponentPeer::viewFocusGain()
  203386. {
  203387. if (currentlyFocusedPeer != this)
  203388. {
  203389. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  203390. currentlyFocusedPeer->handleFocusLoss();
  203391. currentlyFocusedPeer = this;
  203392. handleFocusGain();
  203393. }
  203394. }
  203395. void UIViewComponentPeer::viewFocusLoss()
  203396. {
  203397. if (currentlyFocusedPeer == this)
  203398. {
  203399. currentlyFocusedPeer = 0;
  203400. handleFocusLoss();
  203401. }
  203402. }
  203403. void juce_HandleProcessFocusChange()
  203404. {
  203405. if (UIViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  203406. {
  203407. if (Process::isForegroundProcess())
  203408. {
  203409. currentlyFocusedPeer->handleFocusGain();
  203410. ComponentPeer::bringModalComponentToFront();
  203411. }
  203412. else
  203413. {
  203414. currentlyFocusedPeer->handleFocusLoss();
  203415. // turn kiosk mode off if we lose focus..
  203416. Desktop::getInstance().setKioskModeComponent (0);
  203417. }
  203418. }
  203419. }
  203420. bool UIViewComponentPeer::isFocused() const
  203421. {
  203422. return isSharedWindow ? this == currentlyFocusedPeer
  203423. : (window != 0 && [window isKeyWindow]);
  203424. }
  203425. void UIViewComponentPeer::grabFocus()
  203426. {
  203427. if (window != 0)
  203428. {
  203429. [window makeKeyWindow];
  203430. viewFocusGain();
  203431. }
  203432. }
  203433. void UIViewComponentPeer::textInputRequired (const Point<int>&)
  203434. {
  203435. }
  203436. void UIViewComponentPeer::drawRect (CGRect r)
  203437. {
  203438. if (r.size.width < 1.0f || r.size.height < 1.0f)
  203439. return;
  203440. CGContextRef cg = UIGraphicsGetCurrentContext();
  203441. if (! component->isOpaque())
  203442. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  203443. CGContextConcatCTM (cg, CGAffineTransformMake (1, 0, 0, -1, 0, view.bounds.size.height));
  203444. CoreGraphicsContext g (cg, view.bounds.size.height);
  203445. insideDrawRect = true;
  203446. handlePaint (g);
  203447. insideDrawRect = false;
  203448. }
  203449. bool UIViewComponentPeer::canBecomeKeyWindow()
  203450. {
  203451. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  203452. }
  203453. bool UIViewComponentPeer::windowShouldClose()
  203454. {
  203455. if (! isValidPeer (this))
  203456. return YES;
  203457. handleUserClosingWindow();
  203458. return NO;
  203459. }
  203460. void UIViewComponentPeer::redirectMovedOrResized()
  203461. {
  203462. handleMovedOrResized();
  203463. }
  203464. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  203465. {
  203466. }
  203467. class AsyncRepaintMessage : public CallbackMessage
  203468. {
  203469. public:
  203470. UIViewComponentPeer* const peer;
  203471. const Rectangle<int> rect;
  203472. AsyncRepaintMessage (UIViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  203473. : peer (peer_), rect (rect_)
  203474. {
  203475. }
  203476. void messageCallback()
  203477. {
  203478. if (ComponentPeer::isValidPeer (peer))
  203479. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  203480. }
  203481. };
  203482. void UIViewComponentPeer::repaint (int x, int y, int w, int h)
  203483. {
  203484. if (insideDrawRect || ! MessageManager::getInstance()->isThisTheMessageThread())
  203485. {
  203486. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  203487. }
  203488. else
  203489. {
  203490. [view setNeedsDisplayInRect: CGRectMake ((float) x, (float) y, (float) w, (float) h)];
  203491. }
  203492. }
  203493. void UIViewComponentPeer::performAnyPendingRepaintsNow()
  203494. {
  203495. }
  203496. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  203497. {
  203498. return new UIViewComponentPeer (this, styleFlags, (UIView*) windowToAttachTo);
  203499. }
  203500. Image* juce_createIconForFile (const File& file)
  203501. {
  203502. return 0;
  203503. }
  203504. bool Desktop::canUseSemiTransparentWindows() throw()
  203505. {
  203506. return true;
  203507. }
  203508. const Point<int> Desktop::getMousePosition()
  203509. {
  203510. return juce_lastMousePos;
  203511. }
  203512. void Desktop::setMousePosition (const Point<int>&)
  203513. {
  203514. }
  203515. const int KeyPress::spaceKey = ' ';
  203516. const int KeyPress::returnKey = 0x0d;
  203517. const int KeyPress::escapeKey = 0x1b;
  203518. const int KeyPress::backspaceKey = 0x7f;
  203519. const int KeyPress::leftKey = 0x1000;
  203520. const int KeyPress::rightKey = 0x1001;
  203521. const int KeyPress::upKey = 0x1002;
  203522. const int KeyPress::downKey = 0x1003;
  203523. const int KeyPress::pageUpKey = 0x1004;
  203524. const int KeyPress::pageDownKey = 0x1005;
  203525. const int KeyPress::endKey = 0x1006;
  203526. const int KeyPress::homeKey = 0x1007;
  203527. const int KeyPress::deleteKey = 0x1008;
  203528. const int KeyPress::insertKey = -1;
  203529. const int KeyPress::tabKey = 9;
  203530. const int KeyPress::F1Key = 0x2001;
  203531. const int KeyPress::F2Key = 0x2002;
  203532. const int KeyPress::F3Key = 0x2003;
  203533. const int KeyPress::F4Key = 0x2004;
  203534. const int KeyPress::F5Key = 0x2005;
  203535. const int KeyPress::F6Key = 0x2006;
  203536. const int KeyPress::F7Key = 0x2007;
  203537. const int KeyPress::F8Key = 0x2008;
  203538. const int KeyPress::F9Key = 0x2009;
  203539. const int KeyPress::F10Key = 0x200a;
  203540. const int KeyPress::F11Key = 0x200b;
  203541. const int KeyPress::F12Key = 0x200c;
  203542. const int KeyPress::F13Key = 0x200d;
  203543. const int KeyPress::F14Key = 0x200e;
  203544. const int KeyPress::F15Key = 0x200f;
  203545. const int KeyPress::F16Key = 0x2010;
  203546. const int KeyPress::numberPad0 = 0x30020;
  203547. const int KeyPress::numberPad1 = 0x30021;
  203548. const int KeyPress::numberPad2 = 0x30022;
  203549. const int KeyPress::numberPad3 = 0x30023;
  203550. const int KeyPress::numberPad4 = 0x30024;
  203551. const int KeyPress::numberPad5 = 0x30025;
  203552. const int KeyPress::numberPad6 = 0x30026;
  203553. const int KeyPress::numberPad7 = 0x30027;
  203554. const int KeyPress::numberPad8 = 0x30028;
  203555. const int KeyPress::numberPad9 = 0x30029;
  203556. const int KeyPress::numberPadAdd = 0x3002a;
  203557. const int KeyPress::numberPadSubtract = 0x3002b;
  203558. const int KeyPress::numberPadMultiply = 0x3002c;
  203559. const int KeyPress::numberPadDivide = 0x3002d;
  203560. const int KeyPress::numberPadSeparator = 0x3002e;
  203561. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  203562. const int KeyPress::numberPadEquals = 0x30030;
  203563. const int KeyPress::numberPadDelete = 0x30031;
  203564. const int KeyPress::playKey = 0x30000;
  203565. const int KeyPress::stopKey = 0x30001;
  203566. const int KeyPress::fastForwardKey = 0x30002;
  203567. const int KeyPress::rewindKey = 0x30003;
  203568. #endif
  203569. /*** End of inlined file: juce_iphone_UIViewComponentPeer.mm ***/
  203570. /*** Start of inlined file: juce_iphone_MessageManager.mm ***/
  203571. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203572. // compiled on its own).
  203573. #if JUCE_INCLUDED_FILE
  203574. struct CallbackMessagePayload
  203575. {
  203576. MessageCallbackFunction* function;
  203577. void* parameter;
  203578. void* volatile result;
  203579. bool volatile hasBeenExecuted;
  203580. };
  203581. END_JUCE_NAMESPACE
  203582. using namespace JUCE_NAMESPACE;
  203583. @interface JuceAppDelegate : NSObject <UIApplicationDelegate>
  203584. {
  203585. }
  203586. - (JuceAppDelegate*) init;
  203587. - (void) dealloc;
  203588. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url;
  203589. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  203590. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  203591. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  203592. - (void) customEvent: (id) data;
  203593. - (void) performCallback: (id) info;
  203594. @end
  203595. @implementation JuceAppDelegate
  203596. - (JuceAppDelegate*) init
  203597. {
  203598. [super init];
  203599. [[UIApplication sharedApplication] setDelegate: self];
  203600. return self;
  203601. }
  203602. - (void) dealloc
  203603. {
  203604. [[UIApplication sharedApplication] setDelegate: nil];
  203605. [super dealloc];
  203606. }
  203607. - (BOOL) application: (UIApplication*) application handleOpenURL: (NSURL*) url
  203608. {
  203609. if (JUCEApplication::getInstance() != 0)
  203610. {
  203611. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce ([url absoluteString]));
  203612. return YES;
  203613. }
  203614. return NO;
  203615. }
  203616. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  203617. {
  203618. juce_HandleProcessFocusChange();
  203619. }
  203620. - (void) applicationDidResignActive: (NSNotification*) aNotification
  203621. {
  203622. juce_HandleProcessFocusChange();
  203623. }
  203624. - (void) applicationWillUnhide: (NSNotification*) aNotification
  203625. {
  203626. juce_HandleProcessFocusChange();
  203627. }
  203628. - (void) customEvent: (id) n
  203629. {
  203630. NSData* data = (NSData*) n;
  203631. void* message = 0;
  203632. [data getBytes: &message length: sizeof (message)];
  203633. [data release];
  203634. if (message != 0)
  203635. MessageManager::getInstance()->deliverMessage (message);
  203636. }
  203637. - (void) performCallback: (id) info
  203638. {
  203639. if ([info isKindOfClass: [NSData class]])
  203640. {
  203641. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  203642. if (pl != 0)
  203643. {
  203644. pl->result = (*pl->function) (pl->parameter);
  203645. pl->hasBeenExecuted = true;
  203646. }
  203647. }
  203648. else
  203649. {
  203650. jassertfalse // should never get here!
  203651. }
  203652. }
  203653. @end
  203654. BEGIN_JUCE_NAMESPACE
  203655. static JuceAppDelegate* juceAppDelegate = 0;
  203656. void MessageManager::runDispatchLoop()
  203657. {
  203658. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203659. runDispatchLoopUntil (-1);
  203660. }
  203661. void MessageManager::stopDispatchLoop()
  203662. {
  203663. exit (0); // iPhone apps get no mercy..
  203664. }
  203665. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  203666. {
  203667. const ScopedAutoReleasePool pool;
  203668. jassert (isThisTheMessageThread()); // must only be called by the message thread
  203669. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  203670. NSDate* endDate = [NSDate dateWithTimeIntervalSinceNow: millisecondsToRunFor * 0.001];
  203671. while (! quitMessagePosted)
  203672. {
  203673. const ScopedAutoReleasePool pool;
  203674. [[NSRunLoop currentRunLoop] runMode: NSDefaultRunLoopMode
  203675. beforeDate: endDate];
  203676. if (millisecondsToRunFor >= 0 && Time::getMillisecondCounter() >= endTime)
  203677. break;
  203678. }
  203679. return ! quitMessagePosted;
  203680. }
  203681. static CFRunLoopRef runLoop = 0;
  203682. static CFRunLoopSourceRef runLoopSource = 0;
  203683. static Array <void*, CriticalSection>* pendingMessages = 0;
  203684. static void runLoopSourceCallback (void*)
  203685. {
  203686. if (pendingMessages != 0)
  203687. {
  203688. int numDispatched = 0;
  203689. do
  203690. {
  203691. void* const nextMessage = pendingMessages->remove (0);
  203692. if (nextMessage == 0)
  203693. return;
  203694. const ScopedAutoReleasePool pool;
  203695. MessageManager::getInstance()->deliverMessage (nextMessage);
  203696. } while (++numDispatched <= 4);
  203697. CFRunLoopSourceSignal (runLoopSource);
  203698. CFRunLoopWakeUp (runLoop);
  203699. }
  203700. }
  203701. void MessageManager::doPlatformSpecificInitialisation()
  203702. {
  203703. pendingMessages = new Array <void*, CriticalSection>();
  203704. runLoop = CFRunLoopGetCurrent();
  203705. CFRunLoopSourceContext sourceContext;
  203706. zerostruct (sourceContext);
  203707. sourceContext.perform = runLoopSourceCallback;
  203708. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  203709. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  203710. if (juceAppDelegate == 0)
  203711. juceAppDelegate = [[JuceAppDelegate alloc] init];
  203712. }
  203713. void MessageManager::doPlatformSpecificShutdown()
  203714. {
  203715. CFRunLoopSourceInvalidate (runLoopSource);
  203716. CFRelease (runLoopSource);
  203717. runLoopSource = 0;
  203718. if (pendingMessages != 0)
  203719. {
  203720. while (pendingMessages->size() > 0)
  203721. delete ((Message*) pendingMessages->remove(0));
  203722. deleteAndZero (pendingMessages);
  203723. }
  203724. if (juceAppDelegate != 0)
  203725. {
  203726. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  203727. [juceAppDelegate release];
  203728. juceAppDelegate = 0;
  203729. }
  203730. }
  203731. bool juce_postMessageToSystemQueue (void* message)
  203732. {
  203733. if (pendingMessages != 0)
  203734. {
  203735. pendingMessages->add (message);
  203736. CFRunLoopSourceSignal (runLoopSource);
  203737. CFRunLoopWakeUp (runLoop);
  203738. }
  203739. return true;
  203740. }
  203741. void MessageManager::broadcastMessage (const String& value) throw()
  203742. {
  203743. }
  203744. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  203745. void* data)
  203746. {
  203747. if (isThisTheMessageThread())
  203748. {
  203749. return (*callback) (data);
  203750. }
  203751. else
  203752. {
  203753. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  203754. // deadlock because the message manager is blocked from running, so can never
  203755. // call your function..
  203756. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  203757. const ScopedAutoReleasePool pool;
  203758. CallbackMessagePayload cmp;
  203759. cmp.function = callback;
  203760. cmp.parameter = data;
  203761. cmp.result = 0;
  203762. cmp.hasBeenExecuted = false;
  203763. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  203764. withObject: [NSData dataWithBytesNoCopy: &cmp
  203765. length: sizeof (cmp)
  203766. freeWhenDone: NO]
  203767. waitUntilDone: YES];
  203768. return cmp.result;
  203769. }
  203770. }
  203771. #endif
  203772. /*** End of inlined file: juce_iphone_MessageManager.mm ***/
  203773. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  203774. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203775. // compiled on its own).
  203776. #if JUCE_INCLUDED_FILE
  203777. #if JUCE_MAC
  203778. END_JUCE_NAMESPACE
  203779. using namespace JUCE_NAMESPACE;
  203780. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  203781. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  203782. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  203783. #else
  203784. @interface JuceFileChooserDelegate : NSObject
  203785. #endif
  203786. {
  203787. StringArray* filters;
  203788. }
  203789. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  203790. - (void) dealloc;
  203791. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  203792. @end
  203793. @implementation JuceFileChooserDelegate
  203794. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  203795. {
  203796. [super init];
  203797. filters = filters_;
  203798. return self;
  203799. }
  203800. - (void) dealloc
  203801. {
  203802. delete filters;
  203803. [super dealloc];
  203804. }
  203805. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  203806. {
  203807. const File f (nsStringToJuce (filename));
  203808. for (int i = filters->size(); --i >= 0;)
  203809. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  203810. return true;
  203811. return f.isDirectory();
  203812. }
  203813. @end
  203814. BEGIN_JUCE_NAMESPACE
  203815. void FileChooser::showPlatformDialog (Array<File>& results,
  203816. const String& title,
  203817. const File& currentFileOrDirectory,
  203818. const String& filter,
  203819. bool selectsDirectory,
  203820. bool selectsFiles,
  203821. bool isSaveDialogue,
  203822. bool warnAboutOverwritingExistingFiles,
  203823. bool selectMultipleFiles,
  203824. FilePreviewComponent* extraInfoComponent)
  203825. {
  203826. const ScopedAutoReleasePool pool;
  203827. StringArray* filters = new StringArray();
  203828. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
  203829. filters->trim();
  203830. filters->removeEmptyStrings();
  203831. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  203832. [delegate autorelease];
  203833. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  203834. : [NSOpenPanel openPanel];
  203835. [panel setTitle: juceStringToNS (title)];
  203836. if (! isSaveDialogue)
  203837. {
  203838. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203839. [openPanel setCanChooseDirectories: selectsDirectory];
  203840. [openPanel setCanChooseFiles: selectsFiles];
  203841. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  203842. }
  203843. [panel setDelegate: delegate];
  203844. if (isSaveDialogue || selectsDirectory)
  203845. [panel setCanCreateDirectories: YES];
  203846. String directory, filename;
  203847. if (currentFileOrDirectory.isDirectory())
  203848. {
  203849. directory = currentFileOrDirectory.getFullPathName();
  203850. }
  203851. else
  203852. {
  203853. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  203854. filename = currentFileOrDirectory.getFileName();
  203855. }
  203856. if ([panel runModalForDirectory: juceStringToNS (directory)
  203857. file: juceStringToNS (filename)]
  203858. == NSOKButton)
  203859. {
  203860. if (isSaveDialogue)
  203861. {
  203862. results.add (File (nsStringToJuce ([panel filename])));
  203863. }
  203864. else
  203865. {
  203866. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  203867. NSArray* urls = [openPanel filenames];
  203868. for (unsigned int i = 0; i < [urls count]; ++i)
  203869. {
  203870. NSString* f = [urls objectAtIndex: i];
  203871. results.add (File (nsStringToJuce (f)));
  203872. }
  203873. }
  203874. }
  203875. [panel setDelegate: nil];
  203876. }
  203877. #else
  203878. void FileChooser::showPlatformDialog (Array<File>& results,
  203879. const String& title,
  203880. const File& currentFileOrDirectory,
  203881. const String& filter,
  203882. bool selectsDirectory,
  203883. bool selectsFiles,
  203884. bool isSaveDialogue,
  203885. bool warnAboutOverwritingExistingFiles,
  203886. bool selectMultipleFiles,
  203887. FilePreviewComponent* extraInfoComponent)
  203888. {
  203889. const ScopedAutoReleasePool pool;
  203890. jassertfalse //xxx to do
  203891. }
  203892. #endif
  203893. #endif
  203894. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  203895. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  203896. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  203897. // compiled on its own).
  203898. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  203899. #if JUCE_MAC
  203900. END_JUCE_NAMESPACE
  203901. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  203902. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  203903. {
  203904. CriticalSection* contextLock;
  203905. bool needsUpdate;
  203906. }
  203907. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  203908. - (bool) makeActive;
  203909. - (void) makeInactive;
  203910. - (void) reshape;
  203911. @end
  203912. @implementation ThreadSafeNSOpenGLView
  203913. - (id) initWithFrame: (NSRect) frameRect
  203914. pixelFormat: (NSOpenGLPixelFormat*) format
  203915. {
  203916. contextLock = new CriticalSection();
  203917. self = [super initWithFrame: frameRect pixelFormat: format];
  203918. if (self != nil)
  203919. [[NSNotificationCenter defaultCenter] addObserver: self
  203920. selector: @selector (_surfaceNeedsUpdate:)
  203921. name: NSViewGlobalFrameDidChangeNotification
  203922. object: self];
  203923. return self;
  203924. }
  203925. - (void) dealloc
  203926. {
  203927. [[NSNotificationCenter defaultCenter] removeObserver: self];
  203928. delete contextLock;
  203929. [super dealloc];
  203930. }
  203931. - (bool) makeActive
  203932. {
  203933. const ScopedLock sl (*contextLock);
  203934. if ([self openGLContext] == 0)
  203935. return false;
  203936. [[self openGLContext] makeCurrentContext];
  203937. if (needsUpdate)
  203938. {
  203939. [super update];
  203940. needsUpdate = false;
  203941. }
  203942. return true;
  203943. }
  203944. - (void) makeInactive
  203945. {
  203946. const ScopedLock sl (*contextLock);
  203947. [NSOpenGLContext clearCurrentContext];
  203948. }
  203949. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  203950. {
  203951. const ScopedLock sl (*contextLock);
  203952. needsUpdate = true;
  203953. }
  203954. - (void) update
  203955. {
  203956. const ScopedLock sl (*contextLock);
  203957. needsUpdate = true;
  203958. }
  203959. - (void) reshape
  203960. {
  203961. const ScopedLock sl (*contextLock);
  203962. needsUpdate = true;
  203963. }
  203964. @end
  203965. BEGIN_JUCE_NAMESPACE
  203966. class WindowedGLContext : public OpenGLContext
  203967. {
  203968. public:
  203969. WindowedGLContext (Component* const component,
  203970. const OpenGLPixelFormat& pixelFormat_,
  203971. NSOpenGLContext* sharedContext)
  203972. : renderContext (0),
  203973. pixelFormat (pixelFormat_)
  203974. {
  203975. jassert (component != 0);
  203976. NSOpenGLPixelFormatAttribute attribs [64];
  203977. int n = 0;
  203978. attribs[n++] = NSOpenGLPFADoubleBuffer;
  203979. attribs[n++] = NSOpenGLPFAAccelerated;
  203980. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  203981. attribs[n++] = NSOpenGLPFAColorSize;
  203982. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  203983. pixelFormat.greenBits,
  203984. pixelFormat.blueBits);
  203985. attribs[n++] = NSOpenGLPFAAlphaSize;
  203986. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  203987. attribs[n++] = NSOpenGLPFADepthSize;
  203988. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  203989. attribs[n++] = NSOpenGLPFAStencilSize;
  203990. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  203991. attribs[n++] = NSOpenGLPFAAccumSize;
  203992. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  203993. pixelFormat.accumulationBufferGreenBits,
  203994. pixelFormat.accumulationBufferBlueBits,
  203995. pixelFormat.accumulationBufferAlphaBits);
  203996. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  203997. attribs[n++] = NSOpenGLPFASampleBuffers;
  203998. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  203999. attribs[n++] = NSOpenGLPFAClosestPolicy;
  204000. attribs[n++] = NSOpenGLPFANoRecovery;
  204001. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  204002. NSOpenGLPixelFormat* format
  204003. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  204004. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204005. pixelFormat: format];
  204006. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  204007. shareContext: sharedContext] autorelease];
  204008. const GLint swapInterval = 1;
  204009. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  204010. [view setOpenGLContext: renderContext];
  204011. [renderContext setView: view];
  204012. [format release];
  204013. viewHolder = new NSViewComponentInternal (view, component);
  204014. }
  204015. ~WindowedGLContext()
  204016. {
  204017. makeInactive();
  204018. [renderContext clearDrawable];
  204019. viewHolder = 0;
  204020. }
  204021. bool makeActive() const throw()
  204022. {
  204023. jassert (renderContext != 0);
  204024. [view makeActive];
  204025. return isActive();
  204026. }
  204027. bool makeInactive() const throw()
  204028. {
  204029. [view makeInactive];
  204030. return true;
  204031. }
  204032. bool isActive() const throw()
  204033. {
  204034. return [NSOpenGLContext currentContext] == renderContext;
  204035. }
  204036. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  204037. void* getRawContext() const throw() { return renderContext; }
  204038. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  204039. {
  204040. }
  204041. void swapBuffers()
  204042. {
  204043. [renderContext flushBuffer];
  204044. }
  204045. bool setSwapInterval (const int numFramesPerSwap)
  204046. {
  204047. [renderContext setValues: (const GLint*) &numFramesPerSwap
  204048. forParameter: NSOpenGLCPSwapInterval];
  204049. return true;
  204050. }
  204051. int getSwapInterval() const
  204052. {
  204053. GLint numFrames = 0;
  204054. [renderContext getValues: &numFrames
  204055. forParameter: NSOpenGLCPSwapInterval];
  204056. return numFrames;
  204057. }
  204058. void repaint()
  204059. {
  204060. // we need to invalidate the juce view that holds this gl view, to make it
  204061. // cause a repaint callback
  204062. NSView* v = (NSView*) viewHolder->view;
  204063. NSRect r = [v frame];
  204064. // bit of a bodge here.. if we only invalidate the area of the gl component,
  204065. // it's completely covered by the NSOpenGLView, so the OS throws away the
  204066. // repaint message, thus never causing our paint() callback, and never repainting
  204067. // the comp. So invalidating just a little bit around the edge helps..
  204068. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  204069. }
  204070. void* getNativeWindowHandle() const { return viewHolder->view; }
  204071. juce_UseDebuggingNewOperator
  204072. NSOpenGLContext* renderContext;
  204073. ThreadSafeNSOpenGLView* view;
  204074. private:
  204075. OpenGLPixelFormat pixelFormat;
  204076. ScopedPointer <NSViewComponentInternal> viewHolder;
  204077. WindowedGLContext (const WindowedGLContext&);
  204078. WindowedGLContext& operator= (const WindowedGLContext&);
  204079. };
  204080. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  204081. const OpenGLPixelFormat& pixelFormat,
  204082. const OpenGLContext* const contextToShareWith)
  204083. {
  204084. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  204085. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  204086. return (c->renderContext != 0) ? c.release() : 0;
  204087. }
  204088. void* OpenGLComponent::getNativeWindowHandle() const
  204089. {
  204090. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  204091. : 0;
  204092. }
  204093. void juce_glViewport (const int w, const int h)
  204094. {
  204095. glViewport (0, 0, w, h);
  204096. }
  204097. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  204098. OwnedArray <OpenGLPixelFormat>& results)
  204099. {
  204100. /* GLint attribs [64];
  204101. int n = 0;
  204102. attribs[n++] = AGL_RGBA;
  204103. attribs[n++] = AGL_DOUBLEBUFFER;
  204104. attribs[n++] = AGL_ACCELERATED;
  204105. attribs[n++] = AGL_NO_RECOVERY;
  204106. attribs[n++] = AGL_NONE;
  204107. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  204108. while (p != 0)
  204109. {
  204110. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  204111. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  204112. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  204113. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  204114. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  204115. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  204116. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  204117. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  204118. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  204119. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  204120. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  204121. results.add (pf);
  204122. p = aglNextPixelFormat (p);
  204123. }*/
  204124. //jassertfalse //xxx can't see how you do this in cocoa!
  204125. }
  204126. #else
  204127. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  204128. const OpenGLPixelFormat& pixelFormat,
  204129. const OpenGLContext* const contextToShareWith)
  204130. {
  204131. return 0;
  204132. }
  204133. void juce_glViewport (const int w, const int h)
  204134. {
  204135. //glViewport (0, 0, w, h);
  204136. }
  204137. #endif
  204138. #endif
  204139. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  204140. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  204141. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204142. // compiled on its own).
  204143. #if JUCE_INCLUDED_FILE
  204144. #if JUCE_MAC
  204145. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  204146. {
  204147. NSImage* im = CoreGraphicsImage::createNSImage (image);
  204148. NSCursor* c = [[NSCursor alloc] initWithImage: im
  204149. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  204150. [im release];
  204151. return (void*) c;
  204152. }
  204153. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  204154. {
  204155. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  204156. jassert (im != 0);
  204157. if (im == 0)
  204158. return 0;
  204159. return juce_createMouseCursorFromImage (*im,
  204160. (int) (hx * im->getWidth()),
  204161. (int) (hy * im->getHeight()));
  204162. }
  204163. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  204164. {
  204165. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  204166. MemoryBlock mb;
  204167. if (f.getChildFile (filename).loadFileAsData (mb))
  204168. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  204169. return 0;
  204170. }
  204171. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  204172. {
  204173. const ScopedAutoReleasePool pool;
  204174. NSCursor* c = 0;
  204175. switch (type)
  204176. {
  204177. case MouseCursor::NormalCursor:
  204178. c = [NSCursor arrowCursor];
  204179. break;
  204180. case MouseCursor::NoCursor:
  204181. {
  204182. Image blank (Image::ARGB, 8, 8, true);
  204183. return juce_createMouseCursorFromImage (blank, 0, 0);
  204184. }
  204185. case MouseCursor::DraggingHandCursor:
  204186. c = [NSCursor openHandCursor];
  204187. break;
  204188. case MouseCursor::CopyingCursor:
  204189. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  204190. case MouseCursor::WaitCursor:
  204191. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  204192. break;
  204193. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  204194. case MouseCursor::IBeamCursor:
  204195. c = [NSCursor IBeamCursor];
  204196. break;
  204197. case MouseCursor::PointingHandCursor:
  204198. c = [NSCursor pointingHandCursor];
  204199. break;
  204200. case MouseCursor::LeftRightResizeCursor:
  204201. c = [NSCursor resizeLeftRightCursor];
  204202. break;
  204203. case MouseCursor::LeftEdgeResizeCursor:
  204204. c = [NSCursor resizeLeftCursor];
  204205. break;
  204206. case MouseCursor::RightEdgeResizeCursor:
  204207. c = [NSCursor resizeRightCursor];
  204208. break;
  204209. case MouseCursor::UpDownResizeCursor:
  204210. case MouseCursor::TopEdgeResizeCursor:
  204211. case MouseCursor::BottomEdgeResizeCursor:
  204212. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  204213. case MouseCursor::TopLeftCornerResizeCursor:
  204214. case MouseCursor::BottomRightCornerResizeCursor:
  204215. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  204216. case MouseCursor::TopRightCornerResizeCursor:
  204217. case MouseCursor::BottomLeftCornerResizeCursor:
  204218. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  204219. case MouseCursor::UpDownLeftRightResizeCursor:
  204220. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  204221. case MouseCursor::CrosshairCursor:
  204222. c = [NSCursor crosshairCursor];
  204223. break;
  204224. }
  204225. [c retain];
  204226. return (void*) c;
  204227. }
  204228. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  204229. {
  204230. NSCursor* c = (NSCursor*) cursorHandle;
  204231. [c release];
  204232. }
  204233. void MouseCursor::showInAllWindows() const throw()
  204234. {
  204235. showInWindow (0);
  204236. }
  204237. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  204238. {
  204239. NSCursor* const c = (NSCursor*) getHandle();
  204240. [c set];
  204241. }
  204242. #else
  204243. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  204244. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  204245. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  204246. void MouseCursor::showInAllWindows() const throw() {}
  204247. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  204248. #endif
  204249. #endif
  204250. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  204251. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204252. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204253. // compiled on its own).
  204254. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  204255. #if JUCE_MAC
  204256. END_JUCE_NAMESPACE
  204257. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  204258. @interface DownloadClickDetector : NSObject
  204259. {
  204260. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  204261. }
  204262. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  204263. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204264. request: (NSURLRequest*) request
  204265. frame: (WebFrame*) frame
  204266. decisionListener: (id<WebPolicyDecisionListener>) listener;
  204267. @end
  204268. @implementation DownloadClickDetector
  204269. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  204270. {
  204271. [super init];
  204272. ownerComponent = ownerComponent_;
  204273. return self;
  204274. }
  204275. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  204276. request: (NSURLRequest*) request
  204277. frame: (WebFrame*) frame
  204278. decisionListener: (id <WebPolicyDecisionListener>) listener
  204279. {
  204280. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  204281. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  204282. [listener use];
  204283. else
  204284. [listener ignore];
  204285. }
  204286. @end
  204287. BEGIN_JUCE_NAMESPACE
  204288. class WebBrowserComponentInternal : public NSViewComponent
  204289. {
  204290. public:
  204291. WebBrowserComponentInternal (WebBrowserComponent* owner)
  204292. {
  204293. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  204294. frameName: @""
  204295. groupName: @""];
  204296. setView (webView);
  204297. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  204298. [webView setPolicyDelegate: clickListener];
  204299. }
  204300. ~WebBrowserComponentInternal()
  204301. {
  204302. [webView setPolicyDelegate: nil];
  204303. [clickListener release];
  204304. setView (0);
  204305. }
  204306. void goToURL (const String& url,
  204307. const StringArray* headers,
  204308. const MemoryBlock* postData)
  204309. {
  204310. NSMutableURLRequest* r
  204311. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  204312. cachePolicy: NSURLRequestUseProtocolCachePolicy
  204313. timeoutInterval: 30.0];
  204314. if (postData != 0 && postData->getSize() > 0)
  204315. {
  204316. [r setHTTPMethod: @"POST"];
  204317. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  204318. length: postData->getSize()]];
  204319. }
  204320. if (headers != 0)
  204321. {
  204322. for (int i = 0; i < headers->size(); ++i)
  204323. {
  204324. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  204325. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  204326. [r setValue: juceStringToNS (headerValue)
  204327. forHTTPHeaderField: juceStringToNS (headerName)];
  204328. }
  204329. }
  204330. stop();
  204331. [[webView mainFrame] loadRequest: r];
  204332. }
  204333. void goBack()
  204334. {
  204335. [webView goBack];
  204336. }
  204337. void goForward()
  204338. {
  204339. [webView goForward];
  204340. }
  204341. void stop()
  204342. {
  204343. [webView stopLoading: nil];
  204344. }
  204345. void refresh()
  204346. {
  204347. [webView reload: nil];
  204348. }
  204349. private:
  204350. WebView* webView;
  204351. DownloadClickDetector* clickListener;
  204352. };
  204353. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204354. : browser (0),
  204355. blankPageShown (false),
  204356. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  204357. {
  204358. setOpaque (true);
  204359. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  204360. }
  204361. WebBrowserComponent::~WebBrowserComponent()
  204362. {
  204363. deleteAndZero (browser);
  204364. }
  204365. void WebBrowserComponent::goToURL (const String& url,
  204366. const StringArray* headers,
  204367. const MemoryBlock* postData)
  204368. {
  204369. lastURL = url;
  204370. lastHeaders.clear();
  204371. if (headers != 0)
  204372. lastHeaders = *headers;
  204373. lastPostData.setSize (0);
  204374. if (postData != 0)
  204375. lastPostData = *postData;
  204376. blankPageShown = false;
  204377. browser->goToURL (url, headers, postData);
  204378. }
  204379. void WebBrowserComponent::stop()
  204380. {
  204381. browser->stop();
  204382. }
  204383. void WebBrowserComponent::goBack()
  204384. {
  204385. lastURL = String::empty;
  204386. blankPageShown = false;
  204387. browser->goBack();
  204388. }
  204389. void WebBrowserComponent::goForward()
  204390. {
  204391. lastURL = String::empty;
  204392. browser->goForward();
  204393. }
  204394. void WebBrowserComponent::refresh()
  204395. {
  204396. browser->refresh();
  204397. }
  204398. void WebBrowserComponent::paint (Graphics& g)
  204399. {
  204400. }
  204401. void WebBrowserComponent::checkWindowAssociation()
  204402. {
  204403. if (isShowing())
  204404. {
  204405. if (blankPageShown)
  204406. goBack();
  204407. }
  204408. else
  204409. {
  204410. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  204411. {
  204412. // when the component becomes invisible, some stuff like flash
  204413. // carries on playing audio, so we need to force it onto a blank
  204414. // page to avoid this, (and send it back when it's made visible again).
  204415. blankPageShown = true;
  204416. browser->goToURL ("about:blank", 0, 0);
  204417. }
  204418. }
  204419. }
  204420. void WebBrowserComponent::reloadLastURL()
  204421. {
  204422. if (lastURL.isNotEmpty())
  204423. {
  204424. goToURL (lastURL, &lastHeaders, &lastPostData);
  204425. lastURL = String::empty;
  204426. }
  204427. }
  204428. void WebBrowserComponent::parentHierarchyChanged()
  204429. {
  204430. checkWindowAssociation();
  204431. }
  204432. void WebBrowserComponent::resized()
  204433. {
  204434. browser->setSize (getWidth(), getHeight());
  204435. }
  204436. void WebBrowserComponent::visibilityChanged()
  204437. {
  204438. checkWindowAssociation();
  204439. }
  204440. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204441. {
  204442. return true;
  204443. }
  204444. #else
  204445. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  204446. {
  204447. }
  204448. WebBrowserComponent::~WebBrowserComponent()
  204449. {
  204450. }
  204451. void WebBrowserComponent::goToURL (const String& url,
  204452. const StringArray* headers,
  204453. const MemoryBlock* postData)
  204454. {
  204455. }
  204456. void WebBrowserComponent::stop()
  204457. {
  204458. }
  204459. void WebBrowserComponent::goBack()
  204460. {
  204461. }
  204462. void WebBrowserComponent::goForward()
  204463. {
  204464. }
  204465. void WebBrowserComponent::refresh()
  204466. {
  204467. }
  204468. void WebBrowserComponent::paint (Graphics& g)
  204469. {
  204470. }
  204471. void WebBrowserComponent::checkWindowAssociation()
  204472. {
  204473. }
  204474. void WebBrowserComponent::reloadLastURL()
  204475. {
  204476. }
  204477. void WebBrowserComponent::parentHierarchyChanged()
  204478. {
  204479. }
  204480. void WebBrowserComponent::resized()
  204481. {
  204482. }
  204483. void WebBrowserComponent::visibilityChanged()
  204484. {
  204485. }
  204486. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  204487. {
  204488. return true;
  204489. }
  204490. #endif
  204491. #endif
  204492. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  204493. /*** Start of inlined file: juce_iphone_Audio.cpp ***/
  204494. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204495. // compiled on its own).
  204496. #if JUCE_INCLUDED_FILE
  204497. class IPhoneAudioIODevice : public AudioIODevice
  204498. {
  204499. public:
  204500. IPhoneAudioIODevice (const String& deviceName)
  204501. : AudioIODevice (deviceName, T("Audio")),
  204502. audioUnit (0),
  204503. isRunning (false),
  204504. callback (0),
  204505. actualBufferSize (0),
  204506. floatData (1, 2)
  204507. {
  204508. numInputChannels = 2;
  204509. numOutputChannels = 2;
  204510. preferredBufferSize = 0;
  204511. AudioSessionInitialize (0, 0, interruptionListenerStatic, this);
  204512. updateDeviceInfo();
  204513. }
  204514. ~IPhoneAudioIODevice()
  204515. {
  204516. close();
  204517. }
  204518. const StringArray getOutputChannelNames()
  204519. {
  204520. StringArray s;
  204521. s.add ("Left");
  204522. s.add ("Right");
  204523. return s;
  204524. }
  204525. const StringArray getInputChannelNames()
  204526. {
  204527. StringArray s;
  204528. if (audioInputIsAvailable)
  204529. {
  204530. s.add ("Left");
  204531. s.add ("Right");
  204532. }
  204533. return s;
  204534. }
  204535. int getNumSampleRates()
  204536. {
  204537. return 1;
  204538. }
  204539. double getSampleRate (int index)
  204540. {
  204541. return sampleRate;
  204542. }
  204543. int getNumBufferSizesAvailable()
  204544. {
  204545. return 1;
  204546. }
  204547. int getBufferSizeSamples (int index)
  204548. {
  204549. return getDefaultBufferSize();
  204550. }
  204551. int getDefaultBufferSize()
  204552. {
  204553. return 1024;
  204554. }
  204555. const String open (const BitArray& inputChannels,
  204556. const BitArray& outputChannels,
  204557. double sampleRate,
  204558. int bufferSize)
  204559. {
  204560. close();
  204561. lastError = String::empty;
  204562. preferredBufferSize = (bufferSize <= 0) ? getDefaultBufferSize() : bufferSize;
  204563. // xxx set up channel mapping
  204564. activeOutputChans = outputChannels;
  204565. activeOutputChans.setRange (2, activeOutputChans.getHighestBit(), false);
  204566. numOutputChannels = activeOutputChans.countNumberOfSetBits();
  204567. monoOutputChannelNumber = activeOutputChans.findNextSetBit (0);
  204568. activeInputChans = inputChannels;
  204569. activeInputChans.setRange (2, activeInputChans.getHighestBit(), false);
  204570. numInputChannels = activeInputChans.countNumberOfSetBits();
  204571. monoInputChannelNumber = activeInputChans.findNextSetBit (0);
  204572. AudioSessionSetActive (true);
  204573. UInt32 audioCategory = kAudioSessionCategory_PlayAndRecord;
  204574. AudioSessionSetProperty (kAudioSessionProperty_AudioCategory, sizeof (audioCategory), &audioCategory);
  204575. AudioSessionAddPropertyListener (kAudioSessionProperty_AudioRouteChange, propertyChangedStatic, this);
  204576. fixAudioRouteIfSetToReceiver();
  204577. updateDeviceInfo();
  204578. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204579. AudioSessionSetProperty (kAudioSessionProperty_PreferredHardwareIOBufferDuration, sizeof (bufferDuration), &bufferDuration);
  204580. actualBufferSize = preferredBufferSize;
  204581. prepareFloatBuffers();
  204582. isRunning = true;
  204583. propertyChanged (0, 0, 0); // creates and starts the AU
  204584. lastError = audioUnit != 0 ? String::empty
  204585. : T("Couldn't open the device");
  204586. return lastError;
  204587. }
  204588. void close()
  204589. {
  204590. if (isRunning)
  204591. {
  204592. isRunning = false;
  204593. AudioSessionSetActive (false);
  204594. if (audioUnit != 0)
  204595. {
  204596. AudioComponentInstanceDispose (audioUnit);
  204597. audioUnit = 0;
  204598. }
  204599. }
  204600. }
  204601. bool isOpen()
  204602. {
  204603. return isRunning;
  204604. }
  204605. int getCurrentBufferSizeSamples()
  204606. {
  204607. return actualBufferSize;
  204608. }
  204609. double getCurrentSampleRate()
  204610. {
  204611. return sampleRate;
  204612. }
  204613. int getCurrentBitDepth()
  204614. {
  204615. return 16;
  204616. }
  204617. const BitArray getActiveOutputChannels() const
  204618. {
  204619. return activeOutputChans;
  204620. }
  204621. const BitArray getActiveInputChannels() const
  204622. {
  204623. return activeInputChans;
  204624. }
  204625. int getOutputLatencyInSamples()
  204626. {
  204627. return 0; //xxx
  204628. }
  204629. int getInputLatencyInSamples()
  204630. {
  204631. return 0; //xxx
  204632. }
  204633. void start (AudioIODeviceCallback* callback_)
  204634. {
  204635. if (isRunning && callback != callback_)
  204636. {
  204637. if (callback_ != 0)
  204638. callback_->audioDeviceAboutToStart (this);
  204639. const ScopedLock sl (callbackLock);
  204640. callback = callback_;
  204641. }
  204642. }
  204643. void stop()
  204644. {
  204645. if (isRunning)
  204646. {
  204647. AudioIODeviceCallback* lastCallback;
  204648. {
  204649. const ScopedLock sl (callbackLock);
  204650. lastCallback = callback;
  204651. callback = 0;
  204652. }
  204653. if (lastCallback != 0)
  204654. lastCallback->audioDeviceStopped();
  204655. }
  204656. }
  204657. bool isPlaying()
  204658. {
  204659. return isRunning && callback != 0;
  204660. }
  204661. const String getLastError()
  204662. {
  204663. return lastError;
  204664. }
  204665. private:
  204666. CriticalSection callbackLock;
  204667. Float64 sampleRate;
  204668. int numInputChannels, numOutputChannels;
  204669. int preferredBufferSize;
  204670. int actualBufferSize;
  204671. bool isRunning;
  204672. String lastError;
  204673. AudioStreamBasicDescription format;
  204674. AudioUnit audioUnit;
  204675. UInt32 audioInputIsAvailable;
  204676. AudioIODeviceCallback* callback;
  204677. BitArray activeOutputChans, activeInputChans;
  204678. AudioSampleBuffer floatData;
  204679. float* inputChannels[3];
  204680. float* outputChannels[3];
  204681. bool monoInputChannelNumber, monoOutputChannelNumber;
  204682. void prepareFloatBuffers()
  204683. {
  204684. floatData.setSize (numInputChannels + numOutputChannels, actualBufferSize);
  204685. zerostruct (inputChannels);
  204686. zerostruct (outputChannels);
  204687. for (int i = 0; i < numInputChannels; ++i)
  204688. inputChannels[i] = floatData.getSampleData (i);
  204689. for (int i = 0; i < numOutputChannels; ++i)
  204690. outputChannels[i] = floatData.getSampleData (i + numInputChannels);
  204691. }
  204692. OSStatus process (AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204693. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204694. {
  204695. OSStatus err = noErr;
  204696. if (audioInputIsAvailable)
  204697. err = AudioUnitRender (audioUnit, ioActionFlags, inTimeStamp, 1, inNumberFrames, ioData);
  204698. const ScopedLock sl (callbackLock);
  204699. if (callback != 0)
  204700. {
  204701. if (audioInputIsAvailable && numInputChannels > 0)
  204702. {
  204703. short* shortData = (short*) ioData->mBuffers[0].mData;
  204704. if (numInputChannels >= 2)
  204705. {
  204706. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204707. {
  204708. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204709. inputChannels[1][i] = *shortData++ * (1.0f / 32768.0f);
  204710. }
  204711. }
  204712. else
  204713. {
  204714. if (monoInputChannelNumber > 0)
  204715. ++shortData;
  204716. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204717. {
  204718. inputChannels[0][i] = *shortData++ * (1.0f / 32768.0f);
  204719. ++shortData;
  204720. }
  204721. }
  204722. }
  204723. else
  204724. {
  204725. for (int i = numInputChannels; --i >= 0;)
  204726. zeromem (inputChannels[i], sizeof (float) * inNumberFrames);
  204727. }
  204728. callback->audioDeviceIOCallback ((const float**) inputChannels, numInputChannels,
  204729. outputChannels, numOutputChannels,
  204730. (int) inNumberFrames);
  204731. short* shortData = (short*) ioData->mBuffers[0].mData;
  204732. int n = 0;
  204733. if (numOutputChannels >= 2)
  204734. {
  204735. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204736. {
  204737. shortData [n++] = (short) (outputChannels[0][i] * 32767.0f);
  204738. shortData [n++] = (short) (outputChannels[1][i] * 32767.0f);
  204739. }
  204740. }
  204741. else if (numOutputChannels == 1)
  204742. {
  204743. for (UInt32 i = 0; i < inNumberFrames; ++i)
  204744. {
  204745. const short s = (short) (outputChannels[monoOutputChannelNumber][i] * 32767.0f);
  204746. shortData [n++] = s;
  204747. shortData [n++] = s;
  204748. }
  204749. }
  204750. else
  204751. {
  204752. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204753. }
  204754. }
  204755. else
  204756. {
  204757. zeromem (ioData->mBuffers[0].mData, 2 * sizeof (short) * inNumberFrames);
  204758. }
  204759. return err;
  204760. }
  204761. void updateDeviceInfo()
  204762. {
  204763. UInt32 size = sizeof (sampleRate);
  204764. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareSampleRate, &size, &sampleRate);
  204765. size = sizeof (audioInputIsAvailable);
  204766. AudioSessionGetProperty (kAudioSessionProperty_AudioInputAvailable, &size, &audioInputIsAvailable);
  204767. }
  204768. void propertyChanged (AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204769. {
  204770. if (! isRunning)
  204771. return;
  204772. if (inPropertyValue != 0)
  204773. {
  204774. CFDictionaryRef routeChangeDictionary = (CFDictionaryRef) inPropertyValue;
  204775. CFNumberRef routeChangeReasonRef = (CFNumberRef) CFDictionaryGetValue (routeChangeDictionary,
  204776. CFSTR (kAudioSession_AudioRouteChangeKey_Reason));
  204777. SInt32 routeChangeReason;
  204778. CFNumberGetValue (routeChangeReasonRef, kCFNumberSInt32Type, &routeChangeReason);
  204779. if (routeChangeReason == kAudioSessionRouteChangeReason_OldDeviceUnavailable)
  204780. fixAudioRouteIfSetToReceiver();
  204781. }
  204782. updateDeviceInfo();
  204783. createAudioUnit();
  204784. AudioSessionSetActive (true);
  204785. if (audioUnit != 0)
  204786. {
  204787. UInt32 formatSize = sizeof (format);
  204788. AudioUnitGetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, &formatSize);
  204789. Float32 bufferDuration = preferredBufferSize / sampleRate;
  204790. UInt32 bufferDurationSize = sizeof (bufferDuration);
  204791. AudioSessionGetProperty (kAudioSessionProperty_CurrentHardwareIOBufferDuration, &bufferDurationSize, &bufferDurationSize);
  204792. actualBufferSize = (int) (sampleRate * bufferDuration + 0.5);
  204793. AudioOutputUnitStart (audioUnit);
  204794. }
  204795. }
  204796. void interruptionListener (UInt32 inInterruption)
  204797. {
  204798. if (inInterruption == kAudioSessionEndInterruption)
  204799. {
  204800. isRunning = true;
  204801. AudioSessionSetActive (true);
  204802. AudioOutputUnitStart (audioUnit);
  204803. }
  204804. }
  204805. static OSStatus processStatic (void* inRefCon, AudioUnitRenderActionFlags* ioActionFlags, const AudioTimeStamp* inTimeStamp,
  204806. UInt32 inBusNumber, UInt32 inNumberFrames, AudioBufferList* ioData)
  204807. {
  204808. return ((IPhoneAudioIODevice*) inRefCon)->process (ioActionFlags, inTimeStamp, inBusNumber, inNumberFrames, ioData);
  204809. }
  204810. static void propertyChangedStatic (void* inClientData, AudioSessionPropertyID inID, UInt32 inDataSize, const void* inPropertyValue)
  204811. {
  204812. ((IPhoneAudioIODevice*) inClientData)->propertyChanged (inID, inDataSize, inPropertyValue);
  204813. }
  204814. static void interruptionListenerStatic (void* inClientData, UInt32 inInterruption)
  204815. {
  204816. ((IPhoneAudioIODevice*) inClientData)->interruptionListener (inInterruption);
  204817. }
  204818. void resetFormat (const int numChannels)
  204819. {
  204820. memset (&format, 0, sizeof (format));
  204821. format.mFormatID = kAudioFormatLinearPCM;
  204822. format.mFormatFlags = kLinearPCMFormatFlagIsSignedInteger | kLinearPCMFormatFlagIsPacked;
  204823. format.mBitsPerChannel = 8 * sizeof (short);
  204824. format.mChannelsPerFrame = 2;
  204825. format.mFramesPerPacket = 1;
  204826. format.mBytesPerFrame = format.mBytesPerPacket = 2 * sizeof (short);
  204827. }
  204828. bool createAudioUnit()
  204829. {
  204830. if (audioUnit != 0)
  204831. {
  204832. AudioComponentInstanceDispose (audioUnit);
  204833. audioUnit = 0;
  204834. }
  204835. resetFormat (2);
  204836. AudioComponentDescription desc;
  204837. desc.componentType = kAudioUnitType_Output;
  204838. desc.componentSubType = kAudioUnitSubType_RemoteIO;
  204839. desc.componentManufacturer = kAudioUnitManufacturer_Apple;
  204840. desc.componentFlags = 0;
  204841. desc.componentFlagsMask = 0;
  204842. AudioComponent comp = AudioComponentFindNext (0, &desc);
  204843. AudioComponentInstanceNew (comp, &audioUnit);
  204844. if (audioUnit == 0)
  204845. return false;
  204846. const UInt32 one = 1;
  204847. AudioUnitSetProperty (audioUnit, kAudioOutputUnitProperty_EnableIO, kAudioUnitScope_Input, 1, &one, sizeof (one));
  204848. AudioChannelLayout layout;
  204849. layout.mChannelBitmap = 0;
  204850. layout.mNumberChannelDescriptions = 0;
  204851. layout.mChannelLayoutTag = kAudioChannelLayoutTag_Stereo;
  204852. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Input, 0, &layout, sizeof (layout));
  204853. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_AudioChannelLayout, kAudioUnitScope_Output, 0, &layout, sizeof (layout));
  204854. AURenderCallbackStruct inputProc;
  204855. inputProc.inputProc = processStatic;
  204856. inputProc.inputProcRefCon = this;
  204857. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_SetRenderCallback, kAudioUnitScope_Input, 0, &inputProc, sizeof (inputProc));
  204858. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input, 0, &format, sizeof (format));
  204859. AudioUnitSetProperty (audioUnit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Output, 1, &format, sizeof (format));
  204860. AudioUnitInitialize (audioUnit);
  204861. return true;
  204862. }
  204863. // If the routing is set to go through the receiver (i.e. the speaker, but quiet), this re-routes it
  204864. // to make it loud. Needed because by default when using an input + output, the output is kept quiet.
  204865. static void fixAudioRouteIfSetToReceiver()
  204866. {
  204867. CFStringRef audioRoute = 0;
  204868. UInt32 propertySize = sizeof (audioRoute);
  204869. if (AudioSessionGetProperty (kAudioSessionProperty_AudioRoute, &propertySize, &audioRoute) == noErr)
  204870. {
  204871. NSString* route = (NSString*) audioRoute;
  204872. //DBG ("audio route: " + nsStringToJuce (route));
  204873. if ([route hasPrefix: @"Receiver"])
  204874. {
  204875. UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
  204876. AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute, sizeof (audioRouteOverride), &audioRouteOverride);
  204877. }
  204878. CFRelease (audioRoute);
  204879. }
  204880. }
  204881. IPhoneAudioIODevice (const IPhoneAudioIODevice&);
  204882. IPhoneAudioIODevice& operator= (const IPhoneAudioIODevice&);
  204883. };
  204884. class IPhoneAudioIODeviceType : public AudioIODeviceType
  204885. {
  204886. public:
  204887. IPhoneAudioIODeviceType()
  204888. : AudioIODeviceType (T("iPhone Audio"))
  204889. {
  204890. }
  204891. ~IPhoneAudioIODeviceType()
  204892. {
  204893. }
  204894. void scanForDevices()
  204895. {
  204896. }
  204897. const StringArray getDeviceNames (const bool wantInputNames) const
  204898. {
  204899. StringArray s;
  204900. s.add ("iPhone Audio");
  204901. return s;
  204902. }
  204903. int getDefaultDeviceIndex (const bool forInput) const
  204904. {
  204905. return 0;
  204906. }
  204907. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  204908. {
  204909. return device != 0 ? 0 : -1;
  204910. }
  204911. bool hasSeparateInputsAndOutputs() const { return false; }
  204912. AudioIODevice* createDevice (const String& outputDeviceName,
  204913. const String& inputDeviceName)
  204914. {
  204915. if (outputDeviceName.isNotEmpty() || inputDeviceName.isNotEmpty())
  204916. {
  204917. return new IPhoneAudioIODevice (outputDeviceName.isNotEmpty() ? outputDeviceName
  204918. : inputDeviceName);
  204919. }
  204920. return 0;
  204921. }
  204922. juce_UseDebuggingNewOperator
  204923. private:
  204924. IPhoneAudioIODeviceType (const IPhoneAudioIODeviceType&);
  204925. IPhoneAudioIODeviceType& operator= (const IPhoneAudioIODeviceType&);
  204926. };
  204927. AudioIODeviceType* juce_createAudioIODeviceType_iPhoneAudio()
  204928. {
  204929. return new IPhoneAudioIODeviceType();
  204930. }
  204931. #endif
  204932. /*** End of inlined file: juce_iphone_Audio.cpp ***/
  204933. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  204934. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  204935. // compiled on its own).
  204936. #if JUCE_INCLUDED_FILE
  204937. #if JUCE_MAC
  204938. #undef log
  204939. #define log(a) Logger::writeToLog(a)
  204940. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  204941. {
  204942. if (err == noErr)
  204943. return true;
  204944. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  204945. jassertfalse
  204946. return false;
  204947. }
  204948. #undef OK
  204949. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  204950. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  204951. {
  204952. String result;
  204953. CFStringRef str = 0;
  204954. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  204955. if (str != 0)
  204956. {
  204957. result = PlatformUtilities::cfStringToJuceString (str);
  204958. CFRelease (str);
  204959. str = 0;
  204960. }
  204961. MIDIEntityRef entity = 0;
  204962. MIDIEndpointGetEntity (endpoint, &entity);
  204963. if (entity == 0)
  204964. return result; // probably virtual
  204965. if (result.isEmpty())
  204966. {
  204967. // endpoint name has zero length - try the entity
  204968. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  204969. if (str != 0)
  204970. {
  204971. result += PlatformUtilities::cfStringToJuceString (str);
  204972. CFRelease (str);
  204973. str = 0;
  204974. }
  204975. }
  204976. // now consider the device's name
  204977. MIDIDeviceRef device = 0;
  204978. MIDIEntityGetDevice (entity, &device);
  204979. if (device == 0)
  204980. return result;
  204981. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  204982. if (str != 0)
  204983. {
  204984. const String s (PlatformUtilities::cfStringToJuceString (str));
  204985. CFRelease (str);
  204986. // if an external device has only one entity, throw away
  204987. // the endpoint name and just use the device name
  204988. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  204989. {
  204990. result = s;
  204991. }
  204992. else if (! result.startsWithIgnoreCase (s))
  204993. {
  204994. // prepend the device name to the entity name
  204995. result = (s + T(" ") + result).trimEnd();
  204996. }
  204997. }
  204998. return result;
  204999. }
  205000. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  205001. {
  205002. String result;
  205003. // Does the endpoint have connections?
  205004. CFDataRef connections = 0;
  205005. int numConnections = 0;
  205006. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  205007. if (connections != 0)
  205008. {
  205009. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  205010. if (numConnections > 0)
  205011. {
  205012. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  205013. for (int i = 0; i < numConnections; ++i, ++pid)
  205014. {
  205015. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  205016. MIDIObjectRef connObject;
  205017. MIDIObjectType connObjectType;
  205018. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  205019. if (err == noErr)
  205020. {
  205021. String s;
  205022. if (connObjectType == kMIDIObjectType_ExternalSource
  205023. || connObjectType == kMIDIObjectType_ExternalDestination)
  205024. {
  205025. // Connected to an external device's endpoint (10.3 and later).
  205026. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  205027. }
  205028. else
  205029. {
  205030. // Connected to an external device (10.2) (or something else, catch-all)
  205031. CFStringRef str = 0;
  205032. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  205033. if (str != 0)
  205034. {
  205035. s = PlatformUtilities::cfStringToJuceString (str);
  205036. CFRelease (str);
  205037. }
  205038. }
  205039. if (s.isNotEmpty())
  205040. {
  205041. if (result.isNotEmpty())
  205042. result += (", ");
  205043. result += s;
  205044. }
  205045. }
  205046. }
  205047. }
  205048. CFRelease (connections);
  205049. }
  205050. if (result.isNotEmpty())
  205051. return result;
  205052. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  205053. return getEndpointName (endpoint, false);
  205054. }
  205055. const StringArray MidiOutput::getDevices()
  205056. {
  205057. StringArray s;
  205058. const ItemCount num = MIDIGetNumberOfDestinations();
  205059. for (ItemCount i = 0; i < num; ++i)
  205060. {
  205061. MIDIEndpointRef dest = MIDIGetDestination (i);
  205062. if (dest != 0)
  205063. {
  205064. String name (getConnectedEndpointName (dest));
  205065. if (name.isEmpty())
  205066. name = "<error>";
  205067. s.add (name);
  205068. }
  205069. else
  205070. {
  205071. s.add ("<error>");
  205072. }
  205073. }
  205074. return s;
  205075. }
  205076. int MidiOutput::getDefaultDeviceIndex()
  205077. {
  205078. return 0;
  205079. }
  205080. static MIDIClientRef globalMidiClient;
  205081. static bool hasGlobalClientBeenCreated = false;
  205082. static bool makeSureClientExists()
  205083. {
  205084. if (! hasGlobalClientBeenCreated)
  205085. {
  205086. String name (T("JUCE"));
  205087. if (JUCEApplication::getInstance() != 0)
  205088. name = JUCEApplication::getInstance()->getApplicationName();
  205089. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  205090. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  205091. CFRelease (appName);
  205092. }
  205093. return hasGlobalClientBeenCreated;
  205094. }
  205095. class MidiPortAndEndpoint
  205096. {
  205097. public:
  205098. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  205099. : port (port_), endPoint (endPoint_)
  205100. {
  205101. }
  205102. ~MidiPortAndEndpoint()
  205103. {
  205104. if (port != 0)
  205105. MIDIPortDispose (port);
  205106. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  205107. MIDIEndpointDispose (endPoint);
  205108. }
  205109. MIDIPortRef port;
  205110. MIDIEndpointRef endPoint;
  205111. };
  205112. MidiOutput* MidiOutput::openDevice (int index)
  205113. {
  205114. MidiOutput* mo = 0;
  205115. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  205116. {
  205117. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  205118. CFStringRef pname;
  205119. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205120. {
  205121. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  205122. if (makeSureClientExists())
  205123. {
  205124. MIDIPortRef port;
  205125. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  205126. {
  205127. mo = new MidiOutput();
  205128. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  205129. }
  205130. }
  205131. CFRelease (pname);
  205132. }
  205133. }
  205134. return mo;
  205135. }
  205136. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  205137. {
  205138. MidiOutput* mo = 0;
  205139. if (makeSureClientExists())
  205140. {
  205141. MIDIEndpointRef endPoint;
  205142. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  205143. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  205144. {
  205145. mo = new MidiOutput();
  205146. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  205147. }
  205148. CFRelease (name);
  205149. }
  205150. return mo;
  205151. }
  205152. MidiOutput::~MidiOutput()
  205153. {
  205154. delete (MidiPortAndEndpoint*) internal;
  205155. }
  205156. void MidiOutput::reset()
  205157. {
  205158. }
  205159. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205160. {
  205161. return false;
  205162. }
  205163. void MidiOutput::setVolume (float leftVol, float rightVol)
  205164. {
  205165. }
  205166. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205167. {
  205168. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  205169. if (message.isSysEx())
  205170. {
  205171. const int maxPacketSize = 256;
  205172. int pos = 0, bytesLeft = message.getRawDataSize();
  205173. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  205174. HeapBlock <MIDIPacketList> packets;
  205175. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  205176. packets->numPackets = numPackets;
  205177. MIDIPacket* p = packets->packet;
  205178. for (int i = 0; i < numPackets; ++i)
  205179. {
  205180. p->timeStamp = 0;
  205181. p->length = jmin (maxPacketSize, bytesLeft);
  205182. memcpy (p->data, message.getRawData() + pos, p->length);
  205183. pos += p->length;
  205184. bytesLeft -= p->length;
  205185. p = MIDIPacketNext (p);
  205186. }
  205187. if (mpe->port != 0)
  205188. MIDISend (mpe->port, mpe->endPoint, packets);
  205189. else
  205190. MIDIReceived (mpe->endPoint, packets);
  205191. }
  205192. else
  205193. {
  205194. MIDIPacketList packets;
  205195. packets.numPackets = 1;
  205196. packets.packet[0].timeStamp = 0;
  205197. packets.packet[0].length = message.getRawDataSize();
  205198. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  205199. if (mpe->port != 0)
  205200. MIDISend (mpe->port, mpe->endPoint, &packets);
  205201. else
  205202. MIDIReceived (mpe->endPoint, &packets);
  205203. }
  205204. }
  205205. const StringArray MidiInput::getDevices()
  205206. {
  205207. StringArray s;
  205208. const ItemCount num = MIDIGetNumberOfSources();
  205209. for (ItemCount i = 0; i < num; ++i)
  205210. {
  205211. MIDIEndpointRef source = MIDIGetSource (i);
  205212. if (source != 0)
  205213. {
  205214. String name (getConnectedEndpointName (source));
  205215. if (name.isEmpty())
  205216. name = "<error>";
  205217. s.add (name);
  205218. }
  205219. else
  205220. {
  205221. s.add ("<error>");
  205222. }
  205223. }
  205224. return s;
  205225. }
  205226. int MidiInput::getDefaultDeviceIndex()
  205227. {
  205228. return 0;
  205229. }
  205230. struct MidiPortAndCallback
  205231. {
  205232. MidiInput* input;
  205233. MidiPortAndEndpoint* portAndEndpoint;
  205234. MidiInputCallback* callback;
  205235. MemoryBlock pendingData;
  205236. int pendingBytes;
  205237. double pendingDataTime;
  205238. bool active;
  205239. void processSysex (const uint8*& d, int& size, const double time)
  205240. {
  205241. if (*d == 0xf0)
  205242. {
  205243. pendingBytes = 0;
  205244. pendingDataTime = time;
  205245. }
  205246. pendingData.ensureSize (pendingBytes + size, false);
  205247. uint8* totalMessage = (uint8*) pendingData.getData();
  205248. uint8* dest = totalMessage + pendingBytes;
  205249. while (size > 0)
  205250. {
  205251. if (pendingBytes > 0 && *d >= 0x80)
  205252. {
  205253. if (*d >= 0xfa || *d == 0xf8)
  205254. {
  205255. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  205256. ++d;
  205257. --size;
  205258. }
  205259. else
  205260. {
  205261. if (*d == 0xf7)
  205262. {
  205263. *dest++ = *d++;
  205264. pendingBytes++;
  205265. --size;
  205266. }
  205267. break;
  205268. }
  205269. }
  205270. else
  205271. {
  205272. *dest++ = *d++;
  205273. pendingBytes++;
  205274. --size;
  205275. }
  205276. }
  205277. if (totalMessage [pendingBytes - 1] == 0xf7)
  205278. {
  205279. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  205280. pendingBytes = 0;
  205281. }
  205282. else
  205283. {
  205284. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  205285. }
  205286. }
  205287. };
  205288. namespace CoreMidiCallbacks
  205289. {
  205290. static CriticalSection callbackLock;
  205291. static VoidArray activeCallbacks;
  205292. }
  205293. static void midiInputProc (const MIDIPacketList* pktlist,
  205294. void* readProcRefCon,
  205295. void* srcConnRefCon)
  205296. {
  205297. double time = Time::getMillisecondCounterHiRes() * 0.001;
  205298. const double originalTime = time;
  205299. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  205300. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205301. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  205302. {
  205303. const MIDIPacket* packet = &pktlist->packet[0];
  205304. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  205305. {
  205306. const uint8* d = (const uint8*) (packet->data);
  205307. int size = packet->length;
  205308. while (size > 0)
  205309. {
  205310. time = originalTime;
  205311. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  205312. {
  205313. mpc->processSysex (d, size, time);
  205314. }
  205315. else
  205316. {
  205317. int used = 0;
  205318. const MidiMessage m (d, size, used, 0, time);
  205319. if (used <= 0)
  205320. {
  205321. jassertfalse // malformed midi message
  205322. break;
  205323. }
  205324. else
  205325. {
  205326. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  205327. }
  205328. size -= used;
  205329. d += used;
  205330. }
  205331. }
  205332. packet = MIDIPacketNext (packet);
  205333. }
  205334. }
  205335. }
  205336. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205337. {
  205338. MidiInput* mi = 0;
  205339. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  205340. {
  205341. MIDIEndpointRef endPoint = MIDIGetSource (index);
  205342. if (endPoint != 0)
  205343. {
  205344. CFStringRef pname;
  205345. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  205346. {
  205347. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  205348. if (makeSureClientExists())
  205349. {
  205350. MIDIPortRef port;
  205351. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205352. mpc->active = false;
  205353. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  205354. {
  205355. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  205356. {
  205357. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  205358. mpc->callback = callback;
  205359. mpc->pendingBytes = 0;
  205360. mpc->pendingData.ensureSize (128);
  205361. mi = new MidiInput (getDevices() [index]);
  205362. mpc->input = mi;
  205363. mi->internal = (void*) mpc;
  205364. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205365. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205366. }
  205367. else
  205368. {
  205369. OK (MIDIPortDispose (port));
  205370. }
  205371. }
  205372. }
  205373. }
  205374. CFRelease (pname);
  205375. }
  205376. }
  205377. return mi;
  205378. }
  205379. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  205380. {
  205381. MidiInput* mi = 0;
  205382. if (makeSureClientExists())
  205383. {
  205384. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  205385. mpc->active = false;
  205386. MIDIEndpointRef endPoint;
  205387. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  205388. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  205389. {
  205390. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  205391. mpc->callback = callback;
  205392. mpc->pendingBytes = 0;
  205393. mpc->pendingData.ensureSize (128);
  205394. mi = new MidiInput (deviceName);
  205395. mpc->input = mi;
  205396. mi->internal = (void*) mpc;
  205397. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205398. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  205399. }
  205400. CFRelease (name);
  205401. }
  205402. return mi;
  205403. }
  205404. MidiInput::MidiInput (const String& name_)
  205405. : name (name_)
  205406. {
  205407. }
  205408. MidiInput::~MidiInput()
  205409. {
  205410. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  205411. mpc->active = false;
  205412. {
  205413. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205414. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  205415. }
  205416. if (mpc->portAndEndpoint->port != 0)
  205417. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  205418. delete mpc->portAndEndpoint;
  205419. delete mpc;
  205420. }
  205421. void MidiInput::start()
  205422. {
  205423. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205424. ((MidiPortAndCallback*) internal)->active = true;
  205425. }
  205426. void MidiInput::stop()
  205427. {
  205428. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  205429. ((MidiPortAndCallback*) internal)->active = false;
  205430. }
  205431. #undef log
  205432. #else
  205433. MidiOutput::~MidiOutput()
  205434. {
  205435. }
  205436. void MidiOutput::reset()
  205437. {
  205438. }
  205439. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  205440. {
  205441. return false;
  205442. }
  205443. void MidiOutput::setVolume (float leftVol, float rightVol)
  205444. {
  205445. }
  205446. void MidiOutput::sendMessageNow (const MidiMessage& message)
  205447. {
  205448. }
  205449. const StringArray MidiOutput::getDevices()
  205450. {
  205451. return StringArray();
  205452. }
  205453. MidiOutput* MidiOutput::openDevice (int index)
  205454. {
  205455. return 0;
  205456. }
  205457. const StringArray MidiInput::getDevices()
  205458. {
  205459. return StringArray();
  205460. }
  205461. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  205462. {
  205463. return 0;
  205464. }
  205465. #endif
  205466. #endif
  205467. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  205468. #else
  205469. /*** Start of inlined file: juce_mac_Fonts.mm ***/
  205470. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205471. // compiled on its own).
  205472. #if JUCE_INCLUDED_FILE
  205473. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  205474. #define SUPPORT_10_4_FONTS 1
  205475. #define NEW_CGFONT_FUNCTIONS_UNAVAILABLE (CGFontCreateWithFontName == 0)
  205476. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  205477. #define SUPPORT_ONLY_10_4_FONTS 1
  205478. #endif
  205479. END_JUCE_NAMESPACE
  205480. @interface NSFont (PrivateHack)
  205481. - (NSGlyph) _defaultGlyphForChar: (unichar) theChar;
  205482. @end
  205483. BEGIN_JUCE_NAMESPACE
  205484. #endif
  205485. class MacTypeface : public Typeface
  205486. {
  205487. public:
  205488. MacTypeface (const Font& font)
  205489. : Typeface (font.getTypefaceName())
  205490. {
  205491. const ScopedAutoReleasePool pool;
  205492. renderingTransform = CGAffineTransformIdentity;
  205493. bool needsItalicTransform = false;
  205494. #if JUCE_IPHONE
  205495. NSString* fontName = juceStringToNS (font.getTypefaceName());
  205496. if (font.isItalic() || font.isBold())
  205497. {
  205498. NSArray* familyFonts = [UIFont fontNamesForFamilyName: juceStringToNS (font.getTypefaceName())];
  205499. for (NSString* i in familyFonts)
  205500. {
  205501. const String fn (nsStringToJuce (i));
  205502. const String afterDash (fn.fromFirstOccurrenceOf (T("-"), false, false));
  205503. const bool probablyBold = afterDash.containsIgnoreCase (T("bold")) || fn.endsWithIgnoreCase (T("bold"));
  205504. const bool probablyItalic = afterDash.containsIgnoreCase (T("oblique"))
  205505. || afterDash.containsIgnoreCase (T("italic"))
  205506. || fn.endsWithIgnoreCase (T("oblique"))
  205507. || fn.endsWithIgnoreCase (T("italic"));
  205508. if (probablyBold == font.isBold()
  205509. && probablyItalic == font.isItalic())
  205510. {
  205511. fontName = i;
  205512. needsItalicTransform = false;
  205513. break;
  205514. }
  205515. else if (probablyBold && (! probablyItalic) && probablyBold == font.isBold())
  205516. {
  205517. fontName = i;
  205518. needsItalicTransform = true; // not ideal, so carry on in case we find a better one
  205519. }
  205520. }
  205521. if (needsItalicTransform)
  205522. renderingTransform.c = 0.15f;
  205523. }
  205524. fontRef = CGFontCreateWithFontName ((CFStringRef) fontName);
  205525. const int ascender = abs (CGFontGetAscent (fontRef));
  205526. const float totalHeight = ascender + abs (CGFontGetDescent (fontRef));
  205527. ascent = ascender / totalHeight;
  205528. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205529. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / totalHeight;
  205530. #else
  205531. nsFont = [NSFont fontWithName: juceStringToNS (font.getTypefaceName()) size: 1024];
  205532. if (font.isItalic())
  205533. {
  205534. NSFont* newFont = [[NSFontManager sharedFontManager] convertFont: nsFont
  205535. toHaveTrait: NSItalicFontMask];
  205536. if (newFont == nsFont)
  205537. needsItalicTransform = true; // couldn't find a proper italic version, so fake it with a transform..
  205538. nsFont = newFont;
  205539. }
  205540. if (font.isBold())
  205541. nsFont = [[NSFontManager sharedFontManager] convertFont: nsFont toHaveTrait: NSBoldFontMask];
  205542. [nsFont retain];
  205543. ascent = fabsf ((float) [nsFont ascender]);
  205544. float totalSize = ascent + fabsf ((float) [nsFont descender]);
  205545. ascent /= totalSize;
  205546. pathTransform = AffineTransform::identity.scale (1.0f / totalSize, 1.0f / totalSize);
  205547. if (needsItalicTransform)
  205548. {
  205549. pathTransform = pathTransform.sheared (-0.15f, 0.0f);
  205550. renderingTransform.c = 0.15f;
  205551. }
  205552. #if SUPPORT_ONLY_10_4_FONTS
  205553. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205554. if (atsFont == 0)
  205555. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205556. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205557. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205558. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205559. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205560. #else
  205561. #if SUPPORT_10_4_FONTS
  205562. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205563. {
  205564. ATSFontRef atsFont = ATSFontFindFromName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205565. if (atsFont == 0)
  205566. atsFont = ATSFontFindFromPostScriptName ((CFStringRef) [nsFont fontName], kATSOptionFlagsDefault);
  205567. fontRef = CGFontCreateWithPlatformFont ((void*) &atsFont);
  205568. const float totalHeight = fabsf ([nsFont ascender]) + fabsf([nsFont descender]);
  205569. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205570. fontHeightToCGSizeFactor = 1024.0f / totalHeight;
  205571. }
  205572. else
  205573. #endif
  205574. {
  205575. fontRef = CGFontCreateWithFontName ((CFStringRef) [nsFont fontName]);
  205576. const int totalHeight = abs (CGFontGetAscent (fontRef)) + abs (CGFontGetDescent (fontRef));
  205577. unitsToHeightScaleFactor = 1.0f / totalHeight;
  205578. fontHeightToCGSizeFactor = CGFontGetUnitsPerEm (fontRef) / (float) totalHeight;
  205579. }
  205580. #endif
  205581. #endif
  205582. }
  205583. ~MacTypeface()
  205584. {
  205585. #if ! JUCE_IPHONE
  205586. [nsFont release];
  205587. #endif
  205588. if (fontRef != 0)
  205589. CGFontRelease (fontRef);
  205590. }
  205591. float getAscent() const
  205592. {
  205593. return ascent;
  205594. }
  205595. float getDescent() const
  205596. {
  205597. return 1.0f - ascent;
  205598. }
  205599. float getStringWidth (const String& text)
  205600. {
  205601. if (fontRef == 0 || text.isEmpty())
  205602. return 0;
  205603. const int length = text.length();
  205604. HeapBlock <CGGlyph> glyphs;
  205605. createGlyphsForString (text, length, glyphs);
  205606. float x = 0;
  205607. #if SUPPORT_ONLY_10_4_FONTS
  205608. HeapBlock <NSSize> advances (length);
  205609. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205610. for (int i = 0; i < length; ++i)
  205611. x += advances[i].width;
  205612. #else
  205613. #if SUPPORT_10_4_FONTS
  205614. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205615. {
  205616. HeapBlock <NSSize> advances (length);
  205617. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205618. for (int i = 0; i < length; ++i)
  205619. x += advances[i].width;
  205620. }
  205621. else
  205622. #endif
  205623. {
  205624. HeapBlock <int> advances (length);
  205625. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205626. for (int i = 0; i < length; ++i)
  205627. x += advances[i];
  205628. }
  205629. #endif
  205630. return x * unitsToHeightScaleFactor;
  205631. }
  205632. void getGlyphPositions (const String& text, Array <int>& resultGlyphs, Array <float>& xOffsets)
  205633. {
  205634. xOffsets.add (0);
  205635. if (fontRef == 0 || text.isEmpty())
  205636. return;
  205637. const int length = text.length();
  205638. HeapBlock <CGGlyph> glyphs;
  205639. createGlyphsForString (text, length, glyphs);
  205640. #if SUPPORT_ONLY_10_4_FONTS
  205641. HeapBlock <NSSize> advances (length);
  205642. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205643. int x = 0;
  205644. for (int i = 0; i < length; ++i)
  205645. {
  205646. x += advances[i].width;
  205647. xOffsets.add (x * unitsToHeightScaleFactor);
  205648. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  205649. }
  205650. #else
  205651. #if SUPPORT_10_4_FONTS
  205652. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205653. {
  205654. HeapBlock <NSSize> advances (length);
  205655. [nsFont getAdvancements: advances forGlyphs: (NSGlyph*) glyphs count: length];
  205656. float x = 0;
  205657. for (int i = 0; i < length; ++i)
  205658. {
  205659. x += advances[i].width;
  205660. xOffsets.add (x * unitsToHeightScaleFactor);
  205661. resultGlyphs.add (((NSGlyph*) glyphs)[i]);
  205662. }
  205663. }
  205664. else
  205665. #endif
  205666. {
  205667. HeapBlock <int> advances (length);
  205668. if (CGFontGetGlyphAdvances (fontRef, glyphs, length, advances))
  205669. {
  205670. int x = 0;
  205671. for (int i = 0; i < length; ++i)
  205672. {
  205673. x += advances [i];
  205674. xOffsets.add (x * unitsToHeightScaleFactor);
  205675. resultGlyphs.add (glyphs[i]);
  205676. }
  205677. }
  205678. }
  205679. #endif
  205680. }
  205681. bool getOutlineForGlyph (int glyphNumber, Path& path)
  205682. {
  205683. #if JUCE_IPHONE
  205684. return false;
  205685. #else
  205686. if (nsFont == 0)
  205687. return false;
  205688. // we might need to apply a transform to the path, so it mustn't have anything else in it
  205689. jassert (path.isEmpty());
  205690. const ScopedAutoReleasePool pool;
  205691. NSBezierPath* bez = [NSBezierPath bezierPath];
  205692. [bez moveToPoint: NSMakePoint (0, 0)];
  205693. [bez appendBezierPathWithGlyph: (NSGlyph) glyphNumber
  205694. inFont: nsFont];
  205695. for (int i = 0; i < [bez elementCount]; ++i)
  205696. {
  205697. NSPoint p[3];
  205698. switch ([bez elementAtIndex: i associatedPoints: p])
  205699. {
  205700. case NSMoveToBezierPathElement:
  205701. path.startNewSubPath ((float) p[0].x, (float) -p[0].y);
  205702. break;
  205703. case NSLineToBezierPathElement:
  205704. path.lineTo ((float) p[0].x, (float) -p[0].y);
  205705. break;
  205706. case NSCurveToBezierPathElement:
  205707. 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);
  205708. break;
  205709. case NSClosePathBezierPathElement:
  205710. path.closeSubPath();
  205711. break;
  205712. default:
  205713. jassertfalse
  205714. break;
  205715. }
  205716. }
  205717. path.applyTransform (pathTransform);
  205718. return true;
  205719. #endif
  205720. }
  205721. juce_UseDebuggingNewOperator
  205722. CGFontRef fontRef;
  205723. float fontHeightToCGSizeFactor;
  205724. CGAffineTransform renderingTransform;
  205725. private:
  205726. float ascent, unitsToHeightScaleFactor;
  205727. #if JUCE_IPHONE
  205728. #else
  205729. NSFont* nsFont;
  205730. AffineTransform pathTransform;
  205731. #endif
  205732. void createGlyphsForString (const juce_wchar* const text, const int length, HeapBlock <CGGlyph>& glyphs)
  205733. {
  205734. #if SUPPORT_10_4_FONTS
  205735. #if ! SUPPORT_ONLY_10_4_FONTS
  205736. if (NEW_CGFONT_FUNCTIONS_UNAVAILABLE)
  205737. #endif
  205738. {
  205739. glyphs.malloc (sizeof (NSGlyph) * length, 1);
  205740. NSGlyph* const g = (NSGlyph*) glyphs;
  205741. for (int i = 0; i < length; ++i)
  205742. g[i] = (NSGlyph) [nsFont _defaultGlyphForChar: text[i]];
  205743. return;
  205744. }
  205745. #endif
  205746. #if ! SUPPORT_ONLY_10_4_FONTS
  205747. if (charToGlyphMapper == 0)
  205748. charToGlyphMapper = new CharToGlyphMapper (fontRef);
  205749. glyphs.malloc (length);
  205750. for (int i = 0; i < length; ++i)
  205751. glyphs[i] = (CGGlyph) charToGlyphMapper->getGlyphForCharacter (text[i]);
  205752. #endif
  205753. }
  205754. #if ! SUPPORT_ONLY_10_4_FONTS
  205755. // Reads a CGFontRef's character map table to convert unicode into glyph numbers
  205756. class CharToGlyphMapper
  205757. {
  205758. public:
  205759. CharToGlyphMapper (CGFontRef fontRef)
  205760. : segCount (0), endCode (0), startCode (0), idDelta (0),
  205761. idRangeOffset (0), glyphIndexes (0)
  205762. {
  205763. CFDataRef cmapTable = CGFontCopyTableForTag (fontRef, 'cmap');
  205764. if (cmapTable != 0)
  205765. {
  205766. const int numSubtables = getValue16 (cmapTable, 2);
  205767. for (int i = 0; i < numSubtables; ++i)
  205768. {
  205769. if (getValue16 (cmapTable, i * 8 + 4) == 0) // check for platform ID of 0
  205770. {
  205771. const int offset = getValue32 (cmapTable, i * 8 + 8);
  205772. if (getValue16 (cmapTable, offset) == 4) // check that it's format 4..
  205773. {
  205774. const int length = getValue16 (cmapTable, offset + 2);
  205775. const int segCountX2 = getValue16 (cmapTable, offset + 6);
  205776. segCount = segCountX2 / 2;
  205777. const int endCodeOffset = offset + 14;
  205778. const int startCodeOffset = endCodeOffset + 2 + segCountX2;
  205779. const int idDeltaOffset = startCodeOffset + segCountX2;
  205780. const int idRangeOffsetOffset = idDeltaOffset + segCountX2;
  205781. const int glyphIndexesOffset = idRangeOffsetOffset + segCountX2;
  205782. endCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + endCodeOffset, segCountX2);
  205783. startCode = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + startCodeOffset, segCountX2);
  205784. idDelta = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idDeltaOffset, segCountX2);
  205785. idRangeOffset = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + idRangeOffsetOffset, segCountX2);
  205786. glyphIndexes = CFDataCreate (kCFAllocatorDefault, CFDataGetBytePtr (cmapTable) + glyphIndexesOffset, offset + length - glyphIndexesOffset);
  205787. }
  205788. break;
  205789. }
  205790. }
  205791. CFRelease (cmapTable);
  205792. }
  205793. }
  205794. ~CharToGlyphMapper()
  205795. {
  205796. if (endCode != 0)
  205797. {
  205798. CFRelease (endCode);
  205799. CFRelease (startCode);
  205800. CFRelease (idDelta);
  205801. CFRelease (idRangeOffset);
  205802. CFRelease (glyphIndexes);
  205803. }
  205804. }
  205805. int getGlyphForCharacter (const juce_wchar c) const
  205806. {
  205807. for (int i = 0; i < segCount; ++i)
  205808. {
  205809. if (getValue16 (endCode, i * 2) >= c)
  205810. {
  205811. const int start = getValue16 (startCode, i * 2);
  205812. if (start > c)
  205813. break;
  205814. const int delta = getValue16 (idDelta, i * 2);
  205815. const int rangeOffset = getValue16 (idRangeOffset, i * 2);
  205816. if (rangeOffset == 0)
  205817. return delta + c;
  205818. else
  205819. return getValue16 (glyphIndexes, 2 * ((rangeOffset / 2) + (c - start) - (segCount - i)));
  205820. }
  205821. }
  205822. // If we failed to find it "properly", this dodgy fall-back seems to do the trick for most fonts!
  205823. return jmax (-1, c - 29);
  205824. }
  205825. private:
  205826. int segCount;
  205827. CFDataRef endCode, startCode, idDelta, idRangeOffset, glyphIndexes;
  205828. static uint16 getValue16 (CFDataRef data, const int index)
  205829. {
  205830. return CFSwapInt16BigToHost (*(UInt16*) (CFDataGetBytePtr (data) + index));
  205831. }
  205832. static uint32 getValue32 (CFDataRef data, const int index)
  205833. {
  205834. return CFSwapInt32BigToHost (*(UInt32*) (CFDataGetBytePtr (data) + index));
  205835. }
  205836. };
  205837. ScopedPointer <CharToGlyphMapper> charToGlyphMapper;
  205838. #endif
  205839. };
  205840. const Typeface::Ptr Typeface::createSystemTypefaceFor (const Font& font)
  205841. {
  205842. return new MacTypeface (font);
  205843. }
  205844. const StringArray Font::findAllTypefaceNames() throw()
  205845. {
  205846. StringArray names;
  205847. const ScopedAutoReleasePool pool;
  205848. #if JUCE_IPHONE
  205849. NSArray* fonts = [UIFont familyNames];
  205850. #else
  205851. NSArray* fonts = [[NSFontManager sharedFontManager] availableFontFamilies];
  205852. #endif
  205853. for (unsigned int i = 0; i < [fonts count]; ++i)
  205854. names.add (nsStringToJuce ((NSString*) [fonts objectAtIndex: i]));
  205855. names.sort (true);
  205856. return names;
  205857. }
  205858. void Font::getPlatformDefaultFontNames (String& defaultSans, String& defaultSerif, String& defaultFixed) throw()
  205859. {
  205860. #if JUCE_IPHONE
  205861. defaultSans = "Helvetica";
  205862. defaultSerif = "Times New Roman";
  205863. defaultFixed = "Courier New";
  205864. #else
  205865. defaultSans = "Lucida Grande";
  205866. defaultSerif = "Times New Roman";
  205867. defaultFixed = "Monaco";
  205868. #endif
  205869. }
  205870. #endif
  205871. /*** End of inlined file: juce_mac_Fonts.mm ***/
  205872. // (must go before juce_mac_CoreGraphicsContext.mm)
  205873. /*** Start of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  205874. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  205875. // compiled on its own).
  205876. #if JUCE_INCLUDED_FILE
  205877. class CoreGraphicsImage : public Image
  205878. {
  205879. public:
  205880. CoreGraphicsImage (const PixelFormat format_,
  205881. const int imageWidth_,
  205882. const int imageHeight_,
  205883. const bool clearImage)
  205884. : Image (format_, imageWidth_, imageHeight_, clearImage)
  205885. {
  205886. CGColorSpaceRef colourSpace = format == Image::SingleChannel ? CGColorSpaceCreateDeviceGray()
  205887. : CGColorSpaceCreateDeviceRGB();
  205888. context = CGBitmapContextCreate (imageData, imageWidth, imageHeight, 8, lineStride,
  205889. colourSpace, getCGImageFlags (*this));
  205890. CGColorSpaceRelease (colourSpace);
  205891. }
  205892. ~CoreGraphicsImage()
  205893. {
  205894. CGContextRelease (context);
  205895. }
  205896. LowLevelGraphicsContext* createLowLevelContext();
  205897. static CGImageRef createImage (const Image& juceImage, const bool forAlpha, CGColorSpaceRef colourSpace)
  205898. {
  205899. const CoreGraphicsImage* nativeImage = dynamic_cast <const CoreGraphicsImage*> (&juceImage);
  205900. if (nativeImage != 0 && (juceImage.getFormat() == Image::SingleChannel || ! forAlpha))
  205901. {
  205902. return CGBitmapContextCreateImage (nativeImage->context);
  205903. }
  205904. else
  205905. {
  205906. const Image::BitmapData srcData (juceImage, 0, 0, juceImage.getWidth(), juceImage.getHeight());
  205907. CGDataProviderRef provider = CGDataProviderCreateWithData (0, srcData.data, srcData.lineStride * srcData.height, 0);
  205908. CGImageRef imageRef = CGImageCreate (srcData.width, srcData.height,
  205909. 8, srcData.pixelStride * 8, srcData.lineStride,
  205910. colourSpace, getCGImageFlags (juceImage), provider,
  205911. 0, true, kCGRenderingIntentDefault);
  205912. CGDataProviderRelease (provider);
  205913. return imageRef;
  205914. }
  205915. }
  205916. #if JUCE_MAC
  205917. static NSImage* createNSImage (const Image& image)
  205918. {
  205919. const ScopedAutoReleasePool pool;
  205920. NSImage* im = [[NSImage alloc] init];
  205921. [im setSize: NSMakeSize (image.getWidth(), image.getHeight())];
  205922. [im lockFocus];
  205923. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  205924. CGImageRef imageRef = createImage (image, false, colourSpace);
  205925. CGColorSpaceRelease (colourSpace);
  205926. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  205927. CGContextDrawImage (cg, CGRectMake (0, 0, image.getWidth(), image.getHeight()), imageRef);
  205928. CGImageRelease (imageRef);
  205929. [im unlockFocus];
  205930. return im;
  205931. }
  205932. #endif
  205933. CGContextRef context;
  205934. private:
  205935. static CGBitmapInfo getCGImageFlags (const Image& image)
  205936. {
  205937. #if JUCE_BIG_ENDIAN
  205938. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Big) : kCGBitmapByteOrderDefault;
  205939. #else
  205940. return image.getFormat() == Image::ARGB ? (kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Little) : kCGBitmapByteOrderDefault;
  205941. #endif
  205942. }
  205943. };
  205944. Image* Image::createNativeImage (const PixelFormat format, const int imageWidth, const int imageHeight, const bool clearImage)
  205945. {
  205946. #if USE_COREGRAPHICS_RENDERING
  205947. return new CoreGraphicsImage (format == RGB ? ARGB : format, imageWidth, imageHeight, clearImage);
  205948. #else
  205949. return new Image (format, imageWidth, imageHeight, clearImage);
  205950. #endif
  205951. }
  205952. class CoreGraphicsContext : public LowLevelGraphicsContext
  205953. {
  205954. public:
  205955. CoreGraphicsContext (CGContextRef context_, const float flipHeight_)
  205956. : context (context_),
  205957. flipHeight (flipHeight_),
  205958. numGradientLookupEntries (0)
  205959. {
  205960. CGContextRetain (context);
  205961. CGContextSaveGState(context);
  205962. CGContextSetShouldSmoothFonts (context, true);
  205963. CGContextSetShouldAntialias (context, true);
  205964. CGContextSetBlendMode (context, kCGBlendModeNormal);
  205965. rgbColourSpace = CGColorSpaceCreateDeviceRGB();
  205966. greyColourSpace = CGColorSpaceCreateDeviceGray();
  205967. gradientCallbacks.version = 0;
  205968. gradientCallbacks.evaluate = gradientCallback;
  205969. gradientCallbacks.releaseInfo = 0;
  205970. state = new SavedState();
  205971. }
  205972. ~CoreGraphicsContext()
  205973. {
  205974. CGContextRestoreGState (context);
  205975. CGContextRelease (context);
  205976. CGColorSpaceRelease (rgbColourSpace);
  205977. CGColorSpaceRelease (greyColourSpace);
  205978. }
  205979. bool isVectorDevice() const { return false; }
  205980. void setOrigin (int x, int y)
  205981. {
  205982. CGContextTranslateCTM (context, x, -y);
  205983. }
  205984. bool clipToRectangle (const Rectangle<int>& r)
  205985. {
  205986. CGContextClipToRect (context, CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight()));
  205987. return ! isClipEmpty();
  205988. }
  205989. bool clipToRectangleList (const RectangleList& clipRegion)
  205990. {
  205991. if (clipRegion.isEmpty())
  205992. {
  205993. CGContextClipToRect (context, CGRectMake (0, 0, 0, 0));
  205994. return false;
  205995. }
  205996. else
  205997. {
  205998. const int numRects = clipRegion.getNumRectangles();
  205999. HeapBlock <CGRect> rects (numRects);
  206000. for (int i = 0; i < numRects; ++i)
  206001. {
  206002. const Rectangle<int>& r = clipRegion.getRectangle(i);
  206003. rects[i] = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206004. }
  206005. CGContextClipToRects (context, rects, numRects);
  206006. return ! isClipEmpty();
  206007. }
  206008. }
  206009. void excludeClipRectangle (const Rectangle<int>& r)
  206010. {
  206011. RectangleList remaining (getClipBounds());
  206012. remaining.subtract (r);
  206013. clipToRectangleList (remaining);
  206014. }
  206015. void clipToPath (const Path& path, const AffineTransform& transform)
  206016. {
  206017. createPath (path, transform);
  206018. CGContextClip (context);
  206019. }
  206020. void clipToImageAlpha (const Image& sourceImage, const Rectangle<int>& srcClip, const AffineTransform& transform)
  206021. {
  206022. if (! transform.isSingularity())
  206023. {
  206024. Image* singleChannelImage = createAlphaChannelImage (sourceImage);
  206025. CGImageRef image = CoreGraphicsImage::createImage (*singleChannelImage, true, greyColourSpace);
  206026. flip();
  206027. AffineTransform t (AffineTransform::scale (1.0f, -1.0f).translated (0, sourceImage.getHeight()).followedBy (transform));
  206028. applyTransform (t);
  206029. CGRect r = CGRectMake (0, 0, sourceImage.getWidth(), sourceImage.getHeight());
  206030. CGContextClipToMask (context, r, image);
  206031. applyTransform (t.inverted());
  206032. flip();
  206033. CGImageRelease (image);
  206034. deleteAlphaChannelImage (sourceImage, singleChannelImage);
  206035. }
  206036. }
  206037. bool clipRegionIntersects (const Rectangle<int>& r)
  206038. {
  206039. return getClipBounds().intersects (r);
  206040. }
  206041. const Rectangle<int> getClipBounds() const
  206042. {
  206043. CGRect bounds = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206044. return Rectangle<int> (roundToInt (bounds.origin.x),
  206045. roundToInt (flipHeight - (bounds.origin.y + bounds.size.height)),
  206046. roundToInt (bounds.size.width),
  206047. roundToInt (bounds.size.height));
  206048. }
  206049. bool isClipEmpty() const
  206050. {
  206051. return CGRectIsEmpty (CGContextGetClipBoundingBox (context));
  206052. }
  206053. void saveState()
  206054. {
  206055. CGContextSaveGState (context);
  206056. stateStack.add (new SavedState (*state));
  206057. }
  206058. void restoreState()
  206059. {
  206060. CGContextRestoreGState (context);
  206061. SavedState* const top = stateStack.getLast();
  206062. if (top != 0)
  206063. {
  206064. state = top;
  206065. stateStack.removeLast (1, false);
  206066. }
  206067. else
  206068. {
  206069. jassertfalse // trying to pop with an empty stack!
  206070. }
  206071. }
  206072. void setFill (const FillType& fillType)
  206073. {
  206074. state->fillType = fillType;
  206075. if (fillType.isColour())
  206076. {
  206077. CGContextSetRGBFillColor (context, fillType.colour.getFloatRed(), fillType.colour.getFloatGreen(),
  206078. fillType.colour.getFloatBlue(), fillType.colour.getFloatAlpha());
  206079. CGContextSetAlpha (context, 1.0f);
  206080. }
  206081. }
  206082. void setOpacity (float newOpacity)
  206083. {
  206084. state->fillType.setOpacity (newOpacity);
  206085. setFill (state->fillType);
  206086. }
  206087. void setInterpolationQuality (Graphics::ResamplingQuality quality)
  206088. {
  206089. CGContextSetInterpolationQuality (context, quality == Graphics::lowResamplingQuality
  206090. ? kCGInterpolationLow
  206091. : kCGInterpolationHigh);
  206092. }
  206093. void fillRect (const Rectangle<int>& r, const bool replaceExistingContents)
  206094. {
  206095. CGRect cgRect = CGRectMake (r.getX(), flipHeight - r.getBottom(), r.getWidth(), r.getHeight());
  206096. if (replaceExistingContents)
  206097. {
  206098. #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
  206099. CGContextClearRect (context, cgRect);
  206100. #else
  206101. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206102. if (CGContextDrawLinearGradient == 0) // (just a way of checking whether we're running in 10.5 or later)
  206103. CGContextClearRect (context, cgRect);
  206104. else
  206105. #endif
  206106. CGContextSetBlendMode (context, kCGBlendModeCopy);
  206107. #endif
  206108. fillRect (r, false);
  206109. CGContextSetBlendMode (context, kCGBlendModeNormal);
  206110. }
  206111. else
  206112. {
  206113. if (state->fillType.isColour())
  206114. {
  206115. CGContextFillRect (context, cgRect);
  206116. }
  206117. else if (state->fillType.isGradient())
  206118. {
  206119. CGContextSaveGState (context);
  206120. CGContextClipToRect (context, cgRect);
  206121. drawGradient();
  206122. CGContextRestoreGState (context);
  206123. }
  206124. else
  206125. {
  206126. CGContextSaveGState (context);
  206127. CGContextClipToRect (context, cgRect);
  206128. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206129. CGContextRestoreGState (context);
  206130. }
  206131. }
  206132. }
  206133. void fillPath (const Path& path, const AffineTransform& transform)
  206134. {
  206135. CGContextSaveGState (context);
  206136. if (state->fillType.isColour())
  206137. {
  206138. flip();
  206139. applyTransform (transform);
  206140. createPath (path);
  206141. if (path.isUsingNonZeroWinding())
  206142. CGContextFillPath (context);
  206143. else
  206144. CGContextEOFillPath (context);
  206145. }
  206146. else
  206147. {
  206148. createPath (path, transform);
  206149. if (path.isUsingNonZeroWinding())
  206150. CGContextClip (context);
  206151. else
  206152. CGContextEOClip (context);
  206153. if (state->fillType.isGradient())
  206154. drawGradient();
  206155. else
  206156. drawImage (*(state->fillType.image), state->fillType.image->getBounds(), state->fillType.transform, true);
  206157. }
  206158. CGContextRestoreGState (context);
  206159. }
  206160. void drawImage (const Image& sourceImage, const Rectangle<int>& srcClip,
  206161. const AffineTransform& transform, const bool fillEntireClipAsTiles)
  206162. {
  206163. jassert (sourceImage.getBounds().contains (srcClip));
  206164. CGImageRef fullImage = CoreGraphicsImage::createImage (sourceImage, false, rgbColourSpace);
  206165. CGImageRef image = fullImage;
  206166. if (srcClip != sourceImage.getBounds())
  206167. {
  206168. image = CGImageCreateWithImageInRect (fullImage, CGRectMake (srcClip.getX(), srcClip.getY(),
  206169. srcClip.getWidth(), srcClip.getHeight()));
  206170. CGImageRelease (fullImage);
  206171. }
  206172. CGContextSaveGState (context);
  206173. CGContextSetAlpha (context, state->fillType.getOpacity());
  206174. flip();
  206175. applyTransform (AffineTransform::scale (1.0f, -1.0f).translated (0, srcClip.getHeight()).followedBy (transform));
  206176. CGRect imageRect = CGRectMake (0, 0, srcClip.getWidth(), srcClip.getHeight());
  206177. if (fillEntireClipAsTiles)
  206178. {
  206179. #if JUCE_IPHONE || (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5)
  206180. CGContextDrawTiledImage (context, imageRect, image);
  206181. #else
  206182. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  206183. // There's a bug in CGContextDrawTiledImage that makes it incredibly slow
  206184. // if it's doing a transformation - it's quicker to just draw lots of images manually
  206185. if (CGContextDrawTiledImage != 0 && transform.isOnlyTranslation())
  206186. CGContextDrawTiledImage (context, imageRect, image);
  206187. else
  206188. #endif
  206189. {
  206190. // Fallback to manually doing a tiled fill on 10.4
  206191. CGRect clip = CGRectIntegral (CGContextGetClipBoundingBox (context));
  206192. const int iw = srcClip.getWidth();
  206193. const int ih = srcClip.getHeight();
  206194. int x = 0, y = 0;
  206195. while (x > clip.origin.x) x -= iw;
  206196. while (y > clip.origin.y) y -= ih;
  206197. const int right = (int) (clip.origin.x + clip.size.width);
  206198. const int bottom = (int) (clip.origin.y + clip.size.height);
  206199. while (y < bottom)
  206200. {
  206201. for (int x2 = x; x2 < right; x2 += iw)
  206202. CGContextDrawImage (context, CGRectMake (x2, y, iw, ih), image);
  206203. y += ih;
  206204. }
  206205. }
  206206. #endif
  206207. }
  206208. else
  206209. {
  206210. CGContextDrawImage (context, imageRect, image);
  206211. }
  206212. CGImageRelease (image); // (This causes a memory bug in iPhone sim 3.0 - try upgrading to a later version if you hit this)
  206213. CGContextRestoreGState (context);
  206214. }
  206215. void drawLine (double x1, double y1, double x2, double y2)
  206216. {
  206217. CGContextSetLineCap (context, kCGLineCapSquare);
  206218. CGContextSetLineWidth (context, 1.0f);
  206219. CGContextSetRGBStrokeColor (context,
  206220. state->fillType.colour.getFloatRed(), state->fillType.colour.getFloatGreen(),
  206221. state->fillType.colour.getFloatBlue(), state->fillType.colour.getFloatAlpha());
  206222. CGPoint line[] = { { (float) x1 + 0.5f, flipHeight - ((float) y1 + 0.5f) },
  206223. { (float) x2 + 0.5f, flipHeight - ((float) y2 + 0.5f) } };
  206224. CGContextStrokeLineSegments (context, line, 1);
  206225. }
  206226. void drawVerticalLine (const int x, double top, double bottom)
  206227. {
  206228. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206229. CGContextFillRect (context, CGRectMake (x, flipHeight - (float) bottom, 1.0f, (float) (bottom - top)));
  206230. #else
  206231. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206232. // the x co-ord slightly to trick it..
  206233. CGContextFillRect (context, CGRectMake (x + 1.0f / 256.0f, flipHeight - (float) bottom, 1.0f + 1.0f / 256.0f, (float) (bottom - top)));
  206234. #endif
  206235. }
  206236. void drawHorizontalLine (const int y, double left, double right)
  206237. {
  206238. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_5
  206239. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + 1.0f), (float) (right - left), 1.0f));
  206240. #else
  206241. // On Leopard, unless both co-ordinates are non-integer, it disables anti-aliasing, so nudge
  206242. // the x co-ord slightly to trick it..
  206243. CGContextFillRect (context, CGRectMake ((float) left, flipHeight - (y + (1.0f + 1.0f / 256.0f)), (float) (right - left), 1.0f + 1.0f / 256.0f));
  206244. #endif
  206245. }
  206246. void setFont (const Font& newFont)
  206247. {
  206248. if (state->font != newFont)
  206249. {
  206250. state->fontRef = 0;
  206251. state->font = newFont;
  206252. MacTypeface* mf = dynamic_cast <MacTypeface*> ((Typeface*) state->font.getTypeface());
  206253. if (mf != 0)
  206254. {
  206255. state->fontRef = mf->fontRef;
  206256. CGContextSetFont (context, state->fontRef);
  206257. CGContextSetFontSize (context, state->font.getHeight() * mf->fontHeightToCGSizeFactor);
  206258. state->fontTransform = mf->renderingTransform;
  206259. state->fontTransform.a *= state->font.getHorizontalScale();
  206260. CGContextSetTextMatrix (context, state->fontTransform);
  206261. }
  206262. }
  206263. }
  206264. const Font getFont()
  206265. {
  206266. return state->font;
  206267. }
  206268. void drawGlyph (int glyphNumber, const AffineTransform& transform)
  206269. {
  206270. if (state->fontRef != 0 && state->fillType.isColour())
  206271. {
  206272. if (transform.isOnlyTranslation())
  206273. {
  206274. CGGlyph g = glyphNumber;
  206275. CGContextShowGlyphsAtPoint (context, transform.getTranslationX(),
  206276. flipHeight - roundToInt (transform.getTranslationY()), &g, 1);
  206277. }
  206278. else
  206279. {
  206280. CGContextSaveGState (context);
  206281. flip();
  206282. applyTransform (transform);
  206283. CGAffineTransform t = state->fontTransform;
  206284. t.d = -t.d;
  206285. CGContextSetTextMatrix (context, t);
  206286. CGGlyph g = glyphNumber;
  206287. CGContextShowGlyphsAtPoint (context, 0, 0, &g, 1);
  206288. CGContextSetTextMatrix (context, state->fontTransform);
  206289. CGContextRestoreGState (context);
  206290. }
  206291. }
  206292. else
  206293. {
  206294. Path p;
  206295. Font& f = state->font;
  206296. f.getTypeface()->getOutlineForGlyph (glyphNumber, p);
  206297. fillPath (p, AffineTransform::scale (f.getHeight() * f.getHorizontalScale(), f.getHeight())
  206298. .followedBy (transform));
  206299. }
  206300. }
  206301. private:
  206302. CGContextRef context;
  206303. const float flipHeight;
  206304. CGColorSpaceRef rgbColourSpace, greyColourSpace;
  206305. CGFunctionCallbacks gradientCallbacks;
  206306. struct SavedState
  206307. {
  206308. SavedState()
  206309. : font (1.0f), fontRef (0), fontTransform (CGAffineTransformIdentity)
  206310. {
  206311. }
  206312. SavedState (const SavedState& other)
  206313. : fillType (other.fillType), font (other.font), fontRef (other.fontRef),
  206314. fontTransform (other.fontTransform)
  206315. {
  206316. }
  206317. ~SavedState()
  206318. {
  206319. }
  206320. FillType fillType;
  206321. Font font;
  206322. CGFontRef fontRef;
  206323. CGAffineTransform fontTransform;
  206324. };
  206325. ScopedPointer <SavedState> state;
  206326. OwnedArray <SavedState> stateStack;
  206327. HeapBlock <PixelARGB> gradientLookupTable;
  206328. int numGradientLookupEntries;
  206329. static void gradientCallback (void* info, const CGFloat* inData, CGFloat* outData)
  206330. {
  206331. const CoreGraphicsContext* const g = (const CoreGraphicsContext*) info;
  206332. const int index = roundToInt (g->numGradientLookupEntries * inData[0]);
  206333. PixelARGB colour (g->gradientLookupTable [jlimit (0, g->numGradientLookupEntries, index)]);
  206334. colour.unpremultiply();
  206335. outData[0] = colour.getRed() / 255.0f;
  206336. outData[1] = colour.getGreen() / 255.0f;
  206337. outData[2] = colour.getBlue() / 255.0f;
  206338. outData[3] = colour.getAlpha() / 255.0f;
  206339. }
  206340. CGShadingRef createGradient (const AffineTransform& transform, ColourGradient gradient)
  206341. {
  206342. numGradientLookupEntries = gradient.createLookupTable (transform, gradientLookupTable);
  206343. --numGradientLookupEntries;
  206344. CGShadingRef result = 0;
  206345. CGFunctionRef function = CGFunctionCreate ((void*) this, 1, 0, 4, 0, &gradientCallbacks);
  206346. CGPoint p1 (CGPointMake (gradient.x1, gradient.y1));
  206347. if (gradient.isRadial)
  206348. {
  206349. result = CGShadingCreateRadial (rgbColourSpace, p1, 0,
  206350. p1, hypotf (gradient.x1 - gradient.x2, gradient.y1 - gradient.y2),
  206351. function, true, true);
  206352. }
  206353. else
  206354. {
  206355. result = CGShadingCreateAxial (rgbColourSpace, p1,
  206356. CGPointMake (gradient.x2, gradient.y2),
  206357. function, true, true);
  206358. }
  206359. CGFunctionRelease (function);
  206360. return result;
  206361. }
  206362. void drawGradient()
  206363. {
  206364. flip();
  206365. applyTransform (state->fillType.transform);
  206366. CGContextSetInterpolationQuality (context, kCGInterpolationDefault); // (This is required for 10.4, where there's a crash if
  206367. // you draw a gradient with high quality interp enabled).
  206368. CGShadingRef shading = createGradient (state->fillType.transform, *(state->fillType.gradient));
  206369. CGContextSetAlpha (context, state->fillType.getOpacity());
  206370. CGContextDrawShading (context, shading);
  206371. CGShadingRelease (shading);
  206372. }
  206373. void createPath (const Path& path) const
  206374. {
  206375. CGContextBeginPath (context);
  206376. Path::Iterator i (path);
  206377. while (i.next())
  206378. {
  206379. switch (i.elementType)
  206380. {
  206381. case Path::Iterator::startNewSubPath:
  206382. CGContextMoveToPoint (context, i.x1, i.y1);
  206383. break;
  206384. case Path::Iterator::lineTo:
  206385. CGContextAddLineToPoint (context, i.x1, i.y1);
  206386. break;
  206387. case Path::Iterator::quadraticTo:
  206388. CGContextAddQuadCurveToPoint (context, i.x1, i.y1, i.x2, i.y2);
  206389. break;
  206390. case Path::Iterator::cubicTo:
  206391. CGContextAddCurveToPoint (context, i.x1, i.y1, i.x2, i.y2, i.x3, i.y3);
  206392. break;
  206393. case Path::Iterator::closePath:
  206394. CGContextClosePath (context); break;
  206395. default:
  206396. jassertfalse
  206397. break;
  206398. }
  206399. }
  206400. }
  206401. void createPath (const Path& path, const AffineTransform& transform) const
  206402. {
  206403. CGContextBeginPath (context);
  206404. Path::Iterator i (path);
  206405. while (i.next())
  206406. {
  206407. switch (i.elementType)
  206408. {
  206409. case Path::Iterator::startNewSubPath:
  206410. transform.transformPoint (i.x1, i.y1);
  206411. CGContextMoveToPoint (context, i.x1, flipHeight - i.y1);
  206412. break;
  206413. case Path::Iterator::lineTo:
  206414. transform.transformPoint (i.x1, i.y1);
  206415. CGContextAddLineToPoint (context, i.x1, flipHeight - i.y1);
  206416. break;
  206417. case Path::Iterator::quadraticTo:
  206418. transform.transformPoint (i.x1, i.y1);
  206419. transform.transformPoint (i.x2, i.y2);
  206420. CGContextAddQuadCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2);
  206421. break;
  206422. case Path::Iterator::cubicTo:
  206423. transform.transformPoint (i.x1, i.y1);
  206424. transform.transformPoint (i.x2, i.y2);
  206425. transform.transformPoint (i.x3, i.y3);
  206426. CGContextAddCurveToPoint (context, i.x1, flipHeight - i.y1, i.x2, flipHeight - i.y2, i.x3, flipHeight - i.y3);
  206427. break;
  206428. case Path::Iterator::closePath:
  206429. CGContextClosePath (context); break;
  206430. default:
  206431. jassertfalse
  206432. break;
  206433. }
  206434. }
  206435. }
  206436. static Image* createAlphaChannelImage (const Image& im)
  206437. {
  206438. if (im.getFormat() == Image::SingleChannel)
  206439. return const_cast <Image*> (&im);
  206440. return im.createCopyOfAlphaChannel();
  206441. }
  206442. static void deleteAlphaChannelImage (const Image& im, Image* const alphaIm)
  206443. {
  206444. if (im.getFormat() != Image::SingleChannel)
  206445. delete alphaIm;
  206446. }
  206447. void flip() const
  206448. {
  206449. CGContextConcatCTM (context, CGAffineTransformMake (1, 0, 0, -1, 0, flipHeight));
  206450. }
  206451. void applyTransform (const AffineTransform& transform) const
  206452. {
  206453. CGAffineTransform t;
  206454. t.a = transform.mat00;
  206455. t.b = transform.mat10;
  206456. t.c = transform.mat01;
  206457. t.d = transform.mat11;
  206458. t.tx = transform.mat02;
  206459. t.ty = transform.mat12;
  206460. CGContextConcatCTM (context, t);
  206461. }
  206462. float flipY (float y) const
  206463. {
  206464. return flipHeight - y;
  206465. }
  206466. };
  206467. LowLevelGraphicsContext* CoreGraphicsImage::createLowLevelContext()
  206468. {
  206469. return new CoreGraphicsContext (context, imageHeight);
  206470. }
  206471. #endif
  206472. /*** End of inlined file: juce_mac_CoreGraphicsContext.mm ***/
  206473. /*** Start of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  206474. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  206475. // compiled on its own).
  206476. #if JUCE_INCLUDED_FILE
  206477. class NSViewComponentPeer;
  206478. END_JUCE_NAMESPACE
  206479. #define JuceNSView MakeObjCClassName(JuceNSView)
  206480. @interface JuceNSView : NSView<NSTextInput>
  206481. {
  206482. @public
  206483. NSViewComponentPeer* owner;
  206484. NSNotificationCenter* notificationCenter;
  206485. String* stringBeingComposed;
  206486. bool textWasInserted;
  206487. }
  206488. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner withFrame: (NSRect) frame;
  206489. - (void) dealloc;
  206490. - (BOOL) isOpaque;
  206491. - (void) drawRect: (NSRect) r;
  206492. - (void) mouseDown: (NSEvent*) ev;
  206493. - (void) asyncMouseDown: (NSEvent*) ev;
  206494. - (void) mouseUp: (NSEvent*) ev;
  206495. - (void) asyncMouseUp: (NSEvent*) ev;
  206496. - (void) mouseDragged: (NSEvent*) ev;
  206497. - (void) mouseMoved: (NSEvent*) ev;
  206498. - (void) mouseEntered: (NSEvent*) ev;
  206499. - (void) mouseExited: (NSEvent*) ev;
  206500. - (void) rightMouseDown: (NSEvent*) ev;
  206501. - (void) rightMouseDragged: (NSEvent*) ev;
  206502. - (void) rightMouseUp: (NSEvent*) ev;
  206503. - (void) otherMouseDown: (NSEvent*) ev;
  206504. - (void) otherMouseDragged: (NSEvent*) ev;
  206505. - (void) otherMouseUp: (NSEvent*) ev;
  206506. - (void) scrollWheel: (NSEvent*) ev;
  206507. - (BOOL) acceptsFirstMouse: (NSEvent*) ev;
  206508. - (void) frameChanged: (NSNotification*) n;
  206509. - (void) viewDidMoveToWindow;
  206510. - (void) keyDown: (NSEvent*) ev;
  206511. - (void) keyUp: (NSEvent*) ev;
  206512. // NSTextInput Methods
  206513. - (void) insertText: (id) aString;
  206514. - (void) doCommandBySelector: (SEL) aSelector;
  206515. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selRange;
  206516. - (void) unmarkText;
  206517. - (BOOL) hasMarkedText;
  206518. - (long) conversationIdentifier;
  206519. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange;
  206520. - (NSRange) markedRange;
  206521. - (NSRange) selectedRange;
  206522. - (NSRect) firstRectForCharacterRange: (NSRange) theRange;
  206523. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint;
  206524. - (NSArray*) validAttributesForMarkedText;
  206525. - (void) flagsChanged: (NSEvent*) ev;
  206526. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206527. - (BOOL) performKeyEquivalent: (NSEvent*) ev;
  206528. #endif
  206529. - (BOOL) becomeFirstResponder;
  206530. - (BOOL) resignFirstResponder;
  206531. - (BOOL) acceptsFirstResponder;
  206532. - (void) asyncRepaint: (id) rect;
  206533. - (NSArray*) getSupportedDragTypes;
  206534. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender;
  206535. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender;
  206536. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender;
  206537. - (void) draggingEnded: (id <NSDraggingInfo>) sender;
  206538. - (void) draggingExited: (id <NSDraggingInfo>) sender;
  206539. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender;
  206540. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender;
  206541. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender;
  206542. @end
  206543. #define JuceNSWindow MakeObjCClassName(JuceNSWindow)
  206544. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  206545. @interface JuceNSWindow : NSWindow <NSWindowDelegate>
  206546. #else
  206547. @interface JuceNSWindow : NSWindow
  206548. #endif
  206549. {
  206550. @private
  206551. NSViewComponentPeer* owner;
  206552. bool isZooming;
  206553. }
  206554. - (void) setOwner: (NSViewComponentPeer*) owner;
  206555. - (BOOL) canBecomeKeyWindow;
  206556. - (void) becomeKeyWindow;
  206557. - (BOOL) windowShouldClose: (id) window;
  206558. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen;
  206559. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize;
  206560. - (void) zoom: (id) sender;
  206561. @end
  206562. BEGIN_JUCE_NAMESPACE
  206563. class NSViewComponentPeer : public ComponentPeer
  206564. {
  206565. public:
  206566. NSViewComponentPeer (Component* const component,
  206567. const int windowStyleFlags,
  206568. NSView* viewToAttachTo);
  206569. ~NSViewComponentPeer();
  206570. void* getNativeHandle() const;
  206571. void setVisible (bool shouldBeVisible);
  206572. void setTitle (const String& title);
  206573. void setPosition (int x, int y);
  206574. void setSize (int w, int h);
  206575. void setBounds (int x, int y, int w, int h, const bool isNowFullScreen);
  206576. const Rectangle<int> getBounds (const bool global) const;
  206577. const Rectangle<int> getBounds() const;
  206578. const Point<int> getScreenPosition() const;
  206579. const Point<int> relativePositionToGlobal (const Point<int>& relativePosition);
  206580. const Point<int> globalPositionToRelative (const Point<int>& screenPosition);
  206581. void setMinimised (bool shouldBeMinimised);
  206582. bool isMinimised() const;
  206583. void setFullScreen (bool shouldBeFullScreen);
  206584. bool isFullScreen() const;
  206585. bool contains (int x, int y, bool trueIfInAChildWindow) const;
  206586. const BorderSize getFrameSize() const;
  206587. bool setAlwaysOnTop (bool alwaysOnTop);
  206588. void toFront (bool makeActiveWindow);
  206589. void toBehind (ComponentPeer* other);
  206590. void setIcon (const Image& newIcon);
  206591. const StringArray getAvailableRenderingEngines() throw();
  206592. int getCurrentRenderingEngine() throw();
  206593. void setCurrentRenderingEngine (int index) throw();
  206594. virtual void redirectMouseDown (NSEvent* ev);
  206595. virtual void redirectMouseUp (NSEvent* ev);
  206596. virtual void redirectMouseDrag (NSEvent* ev);
  206597. virtual void redirectMouseMove (NSEvent* ev);
  206598. virtual void redirectMouseEnter (NSEvent* ev);
  206599. virtual void redirectMouseExit (NSEvent* ev);
  206600. virtual void redirectMouseWheel (NSEvent* ev);
  206601. bool handleKeyEvent (NSEvent* ev, bool isKeyDown);
  206602. virtual bool redirectKeyDown (NSEvent* ev);
  206603. virtual bool redirectKeyUp (NSEvent* ev);
  206604. virtual void redirectModKeyChange (NSEvent* ev);
  206605. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206606. virtual bool redirectPerformKeyEquivalent (NSEvent* ev);
  206607. #endif
  206608. virtual BOOL sendDragCallback (int type, id <NSDraggingInfo> sender);
  206609. virtual bool isOpaque();
  206610. virtual void drawRect (NSRect r);
  206611. virtual bool canBecomeKeyWindow();
  206612. virtual bool windowShouldClose();
  206613. virtual void redirectMovedOrResized();
  206614. virtual void viewMovedToWindow();
  206615. virtual NSRect constrainRect (NSRect r);
  206616. static void showArrowCursorIfNeeded();
  206617. static void updateModifiers (NSEvent* e);
  206618. static void updateKeysDown (NSEvent* ev, bool isKeyDown);
  206619. static int getKeyCodeFromEvent (NSEvent* ev)
  206620. {
  206621. const String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  206622. int keyCode = unmodified[0];
  206623. if (keyCode == 0x19) // (backwards-tab)
  206624. keyCode = '\t';
  206625. else if (keyCode == 0x03) // (enter)
  206626. keyCode = '\r';
  206627. return keyCode;
  206628. }
  206629. static int64 getMouseTime (NSEvent* e)
  206630. {
  206631. return (Time::currentTimeMillis() - Time::getMillisecondCounter())
  206632. + (int64) ([e timestamp] * 1000.0);
  206633. }
  206634. static const Point<int> getMousePos (NSEvent* e, NSView* view)
  206635. {
  206636. NSPoint p = [view convertPoint: [e locationInWindow] fromView: nil];
  206637. return Point<int> (roundToInt (p.x), roundToInt ([view frame].size.height - p.y));
  206638. }
  206639. static int getModifierForButtonNumber (const NSInteger num)
  206640. {
  206641. return num == 0 ? ModifierKeys::leftButtonModifier
  206642. : (num == 1 ? ModifierKeys::rightButtonModifier
  206643. : (num == 2 ? ModifierKeys::middleButtonModifier : 0));
  206644. }
  206645. virtual void viewFocusGain();
  206646. virtual void viewFocusLoss();
  206647. bool isFocused() const;
  206648. void grabFocus();
  206649. void textInputRequired (const Point<int>& position);
  206650. void repaint (int x, int y, int w, int h);
  206651. void performAnyPendingRepaintsNow();
  206652. juce_UseDebuggingNewOperator
  206653. NSWindow* window;
  206654. JuceNSView* view;
  206655. bool isSharedWindow, fullScreen, insideDrawRect, usingCoreGraphics, recursiveToFrontCall;
  206656. };
  206657. END_JUCE_NAMESPACE
  206658. @implementation JuceNSView
  206659. - (JuceNSView*) initWithOwner: (NSViewComponentPeer*) owner_
  206660. withFrame: (NSRect) frame
  206661. {
  206662. [super initWithFrame: frame];
  206663. owner = owner_;
  206664. stringBeingComposed = 0;
  206665. textWasInserted = false;
  206666. notificationCenter = [NSNotificationCenter defaultCenter];
  206667. [notificationCenter addObserver: self
  206668. selector: @selector (frameChanged:)
  206669. name: NSViewFrameDidChangeNotification
  206670. object: self];
  206671. if (! owner_->isSharedWindow)
  206672. {
  206673. [notificationCenter addObserver: self
  206674. selector: @selector (frameChanged:)
  206675. name: NSWindowDidMoveNotification
  206676. object: owner_->window];
  206677. }
  206678. [self registerForDraggedTypes: [self getSupportedDragTypes]];
  206679. return self;
  206680. }
  206681. - (void) dealloc
  206682. {
  206683. [notificationCenter removeObserver: self];
  206684. delete stringBeingComposed;
  206685. [super dealloc];
  206686. }
  206687. - (void) drawRect: (NSRect) r
  206688. {
  206689. if (owner != 0)
  206690. owner->drawRect (r);
  206691. }
  206692. - (BOOL) isOpaque
  206693. {
  206694. return owner == 0 || owner->isOpaque();
  206695. }
  206696. - (void) mouseDown: (NSEvent*) ev
  206697. {
  206698. // In some host situations, the host will stop modal loops from working
  206699. // correctly if they're called from a mouse event, so we'll trigger
  206700. // the event asynchronously..
  206701. if (JUCEApplication::getInstance() == 0)
  206702. [self performSelectorOnMainThread: @selector (asyncMouseDown:)
  206703. withObject: ev
  206704. waitUntilDone: NO];
  206705. else
  206706. [self asyncMouseDown: ev];
  206707. }
  206708. - (void) asyncMouseDown: (NSEvent*) ev
  206709. {
  206710. if (owner != 0)
  206711. owner->redirectMouseDown (ev);
  206712. }
  206713. - (void) mouseUp: (NSEvent*) ev
  206714. {
  206715. // In some host situations, the host will stop modal loops from working
  206716. // correctly if they're called from a mouse event, so we'll trigger
  206717. // the event asynchronously..
  206718. if (JUCEApplication::getInstance() == 0)
  206719. [self performSelectorOnMainThread: @selector (asyncMouseUp:)
  206720. withObject: ev
  206721. waitUntilDone: NO];
  206722. else
  206723. [self asyncMouseUp: ev];
  206724. }
  206725. - (void) asyncMouseUp: (NSEvent*) ev
  206726. {
  206727. if (owner != 0)
  206728. owner->redirectMouseUp (ev);
  206729. }
  206730. - (void) mouseDragged: (NSEvent*) ev
  206731. {
  206732. if (owner != 0)
  206733. owner->redirectMouseDrag (ev);
  206734. }
  206735. - (void) mouseMoved: (NSEvent*) ev
  206736. {
  206737. if (owner != 0)
  206738. owner->redirectMouseMove (ev);
  206739. }
  206740. - (void) mouseEntered: (NSEvent*) ev
  206741. {
  206742. if (owner != 0)
  206743. owner->redirectMouseEnter (ev);
  206744. }
  206745. - (void) mouseExited: (NSEvent*) ev
  206746. {
  206747. if (owner != 0)
  206748. owner->redirectMouseExit (ev);
  206749. }
  206750. - (void) rightMouseDown: (NSEvent*) ev
  206751. {
  206752. [self mouseDown: ev];
  206753. }
  206754. - (void) rightMouseDragged: (NSEvent*) ev
  206755. {
  206756. [self mouseDragged: ev];
  206757. }
  206758. - (void) rightMouseUp: (NSEvent*) ev
  206759. {
  206760. [self mouseUp: ev];
  206761. }
  206762. - (void) otherMouseDown: (NSEvent*) ev
  206763. {
  206764. [self mouseDown: ev];
  206765. }
  206766. - (void) otherMouseDragged: (NSEvent*) ev
  206767. {
  206768. [self mouseDragged: ev];
  206769. }
  206770. - (void) otherMouseUp: (NSEvent*) ev
  206771. {
  206772. [self mouseUp: ev];
  206773. }
  206774. - (void) scrollWheel: (NSEvent*) ev
  206775. {
  206776. if (owner != 0)
  206777. owner->redirectMouseWheel (ev);
  206778. }
  206779. - (BOOL) acceptsFirstMouse: (NSEvent*) ev
  206780. {
  206781. return YES;
  206782. }
  206783. - (void) frameChanged: (NSNotification*) n
  206784. {
  206785. if (owner != 0)
  206786. owner->redirectMovedOrResized();
  206787. }
  206788. - (void) viewDidMoveToWindow
  206789. {
  206790. if (owner != 0)
  206791. owner->viewMovedToWindow();
  206792. }
  206793. - (void) asyncRepaint: (id) rect
  206794. {
  206795. NSRect* r = (NSRect*) [((NSData*) rect) bytes];
  206796. [self setNeedsDisplayInRect: *r];
  206797. }
  206798. - (void) keyDown: (NSEvent*) ev
  206799. {
  206800. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206801. textWasInserted = false;
  206802. if (target != 0)
  206803. [self interpretKeyEvents: [NSArray arrayWithObject: ev]];
  206804. else
  206805. deleteAndZero (stringBeingComposed);
  206806. if ((! textWasInserted) && (owner == 0 || ! owner->redirectKeyDown (ev)))
  206807. [super keyDown: ev];
  206808. }
  206809. - (void) keyUp: (NSEvent*) ev
  206810. {
  206811. if (owner == 0 || ! owner->redirectKeyUp (ev))
  206812. [super keyUp: ev];
  206813. }
  206814. - (void) insertText: (id) aString
  206815. {
  206816. // This commits multi-byte text when return is pressed, or after every keypress for western keyboards
  206817. if ([aString length] > 0)
  206818. {
  206819. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206820. if (target != 0)
  206821. {
  206822. target->insertTextAtCaret (nsStringToJuce ([aString isKindOfClass: [NSAttributedString class]] ? [aString string] : aString));
  206823. textWasInserted = true;
  206824. }
  206825. }
  206826. deleteAndZero (stringBeingComposed);
  206827. }
  206828. - (void) doCommandBySelector: (SEL) aSelector
  206829. {
  206830. }
  206831. - (void) setMarkedText: (id) aString selectedRange: (NSRange) selectionRange
  206832. {
  206833. if (stringBeingComposed == 0)
  206834. stringBeingComposed = new String();
  206835. *stringBeingComposed = nsStringToJuce ([aString isKindOfClass:[NSAttributedString class]] ? [aString string] : aString);
  206836. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206837. if (target != 0)
  206838. {
  206839. const Range<int> currentHighlight (target->getHighlightedRegion());
  206840. target->insertTextAtCaret (*stringBeingComposed);
  206841. target->setHighlightedRegion (currentHighlight.withLength (stringBeingComposed->length()));
  206842. textWasInserted = true;
  206843. }
  206844. }
  206845. - (void) unmarkText
  206846. {
  206847. if (stringBeingComposed != 0)
  206848. {
  206849. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206850. if (target != 0)
  206851. {
  206852. target->insertTextAtCaret (*stringBeingComposed);
  206853. textWasInserted = true;
  206854. }
  206855. }
  206856. deleteAndZero (stringBeingComposed);
  206857. }
  206858. - (BOOL) hasMarkedText
  206859. {
  206860. return stringBeingComposed != 0;
  206861. }
  206862. - (long) conversationIdentifier
  206863. {
  206864. return (long) (pointer_sized_int) self;
  206865. }
  206866. - (NSAttributedString*) attributedSubstringFromRange: (NSRange) theRange
  206867. {
  206868. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206869. if (target != 0)
  206870. {
  206871. const Range<int> r ((int) theRange.location,
  206872. (int) (theRange.location + theRange.length));
  206873. return [[[NSAttributedString alloc] initWithString: juceStringToNS (target->getTextInRange (r))] autorelease];
  206874. }
  206875. return nil;
  206876. }
  206877. - (NSRange) markedRange
  206878. {
  206879. return stringBeingComposed != 0 ? NSMakeRange (0, stringBeingComposed->length())
  206880. : NSMakeRange (NSNotFound, 0);
  206881. }
  206882. - (NSRange) selectedRange
  206883. {
  206884. TextInputTarget* const target = owner->findCurrentTextInputTarget();
  206885. if (target != 0)
  206886. {
  206887. const Range<int> highlight (target->getHighlightedRegion());
  206888. if (! highlight.isEmpty())
  206889. return NSMakeRange (highlight.getStart(), highlight.getLength());
  206890. }
  206891. return NSMakeRange (NSNotFound, 0);
  206892. }
  206893. - (NSRect) firstRectForCharacterRange: (NSRange) theRange
  206894. {
  206895. JUCE_NAMESPACE::Component* const comp = dynamic_cast <JUCE_NAMESPACE::Component*> (owner->findCurrentTextInputTarget());
  206896. if (comp == 0)
  206897. return NSMakeRect (0, 0, 0, 0);
  206898. const Rectangle<int> bounds (comp->getScreenBounds());
  206899. return NSMakeRect (bounds.getX(),
  206900. [[[NSScreen screens] objectAtIndex: 0] frame].size.height - bounds.getY(),
  206901. bounds.getWidth(),
  206902. bounds.getHeight());
  206903. }
  206904. - (unsigned int) characterIndexForPoint: (NSPoint) thePoint
  206905. {
  206906. return NSNotFound;
  206907. }
  206908. - (NSArray*) validAttributesForMarkedText
  206909. {
  206910. return [NSArray array];
  206911. }
  206912. - (void) flagsChanged: (NSEvent*) ev
  206913. {
  206914. if (owner != 0)
  206915. owner->redirectModKeyChange (ev);
  206916. }
  206917. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  206918. - (BOOL) performKeyEquivalent: (NSEvent*) ev
  206919. {
  206920. if (owner != 0 && owner->redirectPerformKeyEquivalent (ev))
  206921. return true;
  206922. return [super performKeyEquivalent: ev];
  206923. }
  206924. #endif
  206925. - (BOOL) becomeFirstResponder
  206926. {
  206927. if (owner != 0)
  206928. owner->viewFocusGain();
  206929. return true;
  206930. }
  206931. - (BOOL) resignFirstResponder
  206932. {
  206933. if (owner != 0)
  206934. owner->viewFocusLoss();
  206935. return true;
  206936. }
  206937. - (BOOL) acceptsFirstResponder
  206938. {
  206939. return owner != 0 && owner->canBecomeKeyWindow();
  206940. }
  206941. - (NSArray*) getSupportedDragTypes
  206942. {
  206943. return [NSArray arrayWithObjects: NSFilenamesPboardType, /*NSFilesPromisePboardType, NSStringPboardType,*/ nil];
  206944. }
  206945. - (BOOL) sendDragCallback: (int) type sender: (id <NSDraggingInfo>) sender
  206946. {
  206947. return owner != 0 && owner->sendDragCallback (type, sender);
  206948. }
  206949. - (NSDragOperation) draggingEntered: (id <NSDraggingInfo>) sender
  206950. {
  206951. if ([self sendDragCallback: 0 sender: sender])
  206952. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206953. else
  206954. return NSDragOperationNone;
  206955. }
  206956. - (NSDragOperation) draggingUpdated: (id <NSDraggingInfo>) sender
  206957. {
  206958. if ([self sendDragCallback: 0 sender: sender])
  206959. return NSDragOperationCopy | NSDragOperationMove | NSDragOperationGeneric;
  206960. else
  206961. return NSDragOperationNone;
  206962. }
  206963. - (void) draggingEnded: (id <NSDraggingInfo>) sender
  206964. {
  206965. [self sendDragCallback: 1 sender: sender];
  206966. }
  206967. - (void) draggingExited: (id <NSDraggingInfo>) sender
  206968. {
  206969. [self sendDragCallback: 1 sender: sender];
  206970. }
  206971. - (BOOL) prepareForDragOperation: (id <NSDraggingInfo>) sender
  206972. {
  206973. return YES;
  206974. }
  206975. - (BOOL) performDragOperation: (id <NSDraggingInfo>) sender
  206976. {
  206977. return [self sendDragCallback: 2 sender: sender];
  206978. }
  206979. - (void) concludeDragOperation: (id <NSDraggingInfo>) sender
  206980. {
  206981. }
  206982. @end
  206983. @implementation JuceNSWindow
  206984. - (void) setOwner: (NSViewComponentPeer*) owner_
  206985. {
  206986. owner = owner_;
  206987. isZooming = false;
  206988. }
  206989. - (BOOL) canBecomeKeyWindow
  206990. {
  206991. return owner != 0 && owner->canBecomeKeyWindow();
  206992. }
  206993. - (void) becomeKeyWindow
  206994. {
  206995. [super becomeKeyWindow];
  206996. if (owner != 0)
  206997. owner->grabFocus();
  206998. }
  206999. - (BOOL) windowShouldClose: (id) window
  207000. {
  207001. return owner == 0 || owner->windowShouldClose();
  207002. }
  207003. - (NSRect) constrainFrameRect: (NSRect) frameRect toScreen: (NSScreen*) screen
  207004. {
  207005. if (owner != 0)
  207006. frameRect = owner->constrainRect (frameRect);
  207007. return frameRect;
  207008. }
  207009. - (NSSize) windowWillResize: (NSWindow*) window toSize: (NSSize) proposedFrameSize
  207010. {
  207011. if (isZooming)
  207012. return proposedFrameSize;
  207013. NSRect frameRect = [self frame];
  207014. frameRect.origin.y -= proposedFrameSize.height - frameRect.size.height;
  207015. frameRect.size = proposedFrameSize;
  207016. if (owner != 0)
  207017. frameRect = owner->constrainRect (frameRect);
  207018. return frameRect.size;
  207019. }
  207020. - (void) zoom: (id) sender
  207021. {
  207022. isZooming = true;
  207023. [super zoom: sender];
  207024. isZooming = false;
  207025. }
  207026. - (void) windowWillMove: (NSNotification*) notification
  207027. {
  207028. if (JUCE_NAMESPACE::Component::getCurrentlyModalComponent() != 0
  207029. && owner->getComponent()->isCurrentlyBlockedByAnotherModalComponent()
  207030. && (owner->getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowHasTitleBar) != 0)
  207031. JUCE_NAMESPACE::Component::getCurrentlyModalComponent()->inputAttemptWhenModal();
  207032. }
  207033. @end
  207034. BEGIN_JUCE_NAMESPACE
  207035. static ComponentPeer* currentlyFocusedPeer = 0;
  207036. static VoidArray keysCurrentlyDown;
  207037. bool KeyPress::isKeyCurrentlyDown (const int keyCode) throw()
  207038. {
  207039. if (keysCurrentlyDown.contains ((void*) keyCode))
  207040. return true;
  207041. if (keyCode >= 'A' && keyCode <= 'Z'
  207042. && keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toLowerCase ((tchar) keyCode)))
  207043. return true;
  207044. if (keyCode >= 'a' && keyCode <= 'z'
  207045. && keysCurrentlyDown.contains ((void*) (int) CharacterFunctions::toUpperCase ((tchar) keyCode)))
  207046. return true;
  207047. return false;
  207048. }
  207049. static int currentModifiers = 0;
  207050. void NSViewComponentPeer::updateModifiers (NSEvent* e)
  207051. {
  207052. int m = currentModifiers & ~(ModifierKeys::shiftModifier | ModifierKeys::ctrlModifier
  207053. | ModifierKeys::altModifier | ModifierKeys::commandModifier);
  207054. if (([e modifierFlags] & NSShiftKeyMask) != 0)
  207055. m |= ModifierKeys::shiftModifier;
  207056. if (([e modifierFlags] & NSControlKeyMask) != 0)
  207057. m |= ModifierKeys::ctrlModifier;
  207058. if (([e modifierFlags] & NSAlternateKeyMask) != 0)
  207059. m |= ModifierKeys::altModifier;
  207060. if (([e modifierFlags] & NSCommandKeyMask) != 0)
  207061. m |= ModifierKeys::commandModifier;
  207062. currentModifiers = m;
  207063. }
  207064. void NSViewComponentPeer::updateKeysDown (NSEvent* ev, bool isKeyDown)
  207065. {
  207066. updateModifiers (ev);
  207067. int keyCode = getKeyCodeFromEvent (ev);
  207068. if (keyCode != 0)
  207069. {
  207070. if (isKeyDown)
  207071. keysCurrentlyDown.addIfNotAlreadyThere ((void*) keyCode);
  207072. else
  207073. keysCurrentlyDown.removeValue ((void*) keyCode);
  207074. }
  207075. }
  207076. const ModifierKeys ModifierKeys::getCurrentModifiersRealtime() throw()
  207077. {
  207078. return ModifierKeys (currentModifiers);
  207079. }
  207080. void ModifierKeys::updateCurrentModifiers() throw()
  207081. {
  207082. currentModifierFlags = currentModifiers;
  207083. }
  207084. NSViewComponentPeer::NSViewComponentPeer (Component* const component_,
  207085. const int windowStyleFlags,
  207086. NSView* viewToAttachTo)
  207087. : ComponentPeer (component_, windowStyleFlags),
  207088. window (0),
  207089. view (0),
  207090. isSharedWindow (viewToAttachTo != 0),
  207091. fullScreen (false),
  207092. insideDrawRect (false),
  207093. #if USE_COREGRAPHICS_RENDERING
  207094. usingCoreGraphics (true),
  207095. #else
  207096. usingCoreGraphics (false),
  207097. #endif
  207098. recursiveToFrontCall (false)
  207099. {
  207100. NSRect r;
  207101. r.origin.x = 0;
  207102. r.origin.y = 0;
  207103. r.size.width = (float) component->getWidth();
  207104. r.size.height = (float) component->getHeight();
  207105. view = [[JuceNSView alloc] initWithOwner: this withFrame: r];
  207106. [view setPostsFrameChangedNotifications: YES];
  207107. if (isSharedWindow)
  207108. {
  207109. window = [viewToAttachTo window];
  207110. [viewToAttachTo addSubview: view];
  207111. setVisible (component->isVisible());
  207112. }
  207113. else
  207114. {
  207115. r.origin.x = (float) component->getX();
  207116. r.origin.y = (float) component->getY();
  207117. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207118. unsigned int style = 0;
  207119. if ((windowStyleFlags & windowHasTitleBar) == 0)
  207120. style = NSBorderlessWindowMask;
  207121. else
  207122. style = NSTitledWindowMask;
  207123. if ((windowStyleFlags & windowHasMinimiseButton) != 0)
  207124. style |= NSMiniaturizableWindowMask;
  207125. if ((windowStyleFlags & windowHasCloseButton) != 0)
  207126. style |= NSClosableWindowMask;
  207127. if ((windowStyleFlags & windowIsResizable) != 0)
  207128. style |= NSResizableWindowMask;
  207129. window = [[JuceNSWindow alloc] initWithContentRect: r
  207130. styleMask: style
  207131. backing: NSBackingStoreBuffered
  207132. defer: YES];
  207133. [((JuceNSWindow*) window) setOwner: this];
  207134. [window orderOut: nil];
  207135. [window setDelegate: (JuceNSWindow*) window];
  207136. [window setOpaque: component->isOpaque()];
  207137. [window setHasShadow: ((windowStyleFlags & windowHasDropShadow) != 0)];
  207138. if (component->isAlwaysOnTop())
  207139. [window setLevel: NSFloatingWindowLevel];
  207140. [window setContentView: view];
  207141. [window setAutodisplay: YES];
  207142. [window setAcceptsMouseMovedEvents: YES];
  207143. // We'll both retain and also release this on closing because plugin hosts can unexpectedly
  207144. // close the window for us, and also tend to get cause trouble if setReleasedWhenClosed is NO.
  207145. [window setReleasedWhenClosed: YES];
  207146. [window retain];
  207147. [window setExcludedFromWindowsMenu: (windowStyleFlags & windowIsTemporary) != 0];
  207148. [window setIgnoresMouseEvents: (windowStyleFlags & windowIgnoresMouseClicks) != 0];
  207149. }
  207150. setTitle (component->getName());
  207151. }
  207152. NSViewComponentPeer::~NSViewComponentPeer()
  207153. {
  207154. view->owner = 0;
  207155. [view removeFromSuperview];
  207156. [view release];
  207157. if (! isSharedWindow)
  207158. {
  207159. [((JuceNSWindow*) window) setOwner: 0];
  207160. [window close];
  207161. [window release];
  207162. }
  207163. }
  207164. void* NSViewComponentPeer::getNativeHandle() const
  207165. {
  207166. return view;
  207167. }
  207168. void NSViewComponentPeer::setVisible (bool shouldBeVisible)
  207169. {
  207170. if (isSharedWindow)
  207171. {
  207172. [view setHidden: ! shouldBeVisible];
  207173. }
  207174. else
  207175. {
  207176. if (shouldBeVisible)
  207177. {
  207178. [window orderFront: nil];
  207179. handleBroughtToFront();
  207180. }
  207181. else
  207182. {
  207183. [window orderOut: nil];
  207184. }
  207185. }
  207186. }
  207187. void NSViewComponentPeer::setTitle (const String& title)
  207188. {
  207189. const ScopedAutoReleasePool pool;
  207190. if (! isSharedWindow)
  207191. [window setTitle: juceStringToNS (title)];
  207192. }
  207193. void NSViewComponentPeer::setPosition (int x, int y)
  207194. {
  207195. setBounds (x, y, component->getWidth(), component->getHeight(), false);
  207196. }
  207197. void NSViewComponentPeer::setSize (int w, int h)
  207198. {
  207199. setBounds (component->getX(), component->getY(), w, h, false);
  207200. }
  207201. void NSViewComponentPeer::setBounds (int x, int y, int w, int h, const bool isNowFullScreen)
  207202. {
  207203. fullScreen = isNowFullScreen;
  207204. w = jmax (0, w);
  207205. h = jmax (0, h);
  207206. NSRect r;
  207207. r.origin.x = (float) x;
  207208. r.origin.y = (float) y;
  207209. r.size.width = (float) w;
  207210. r.size.height = (float) h;
  207211. if (isSharedWindow)
  207212. {
  207213. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207214. if ([view frame].size.width != r.size.width
  207215. || [view frame].size.height != r.size.height)
  207216. [view setNeedsDisplay: true];
  207217. [view setFrame: r];
  207218. }
  207219. else
  207220. {
  207221. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - (r.origin.y + r.size.height);
  207222. [window setFrame: [window frameRectForContentRect: r]
  207223. display: true];
  207224. }
  207225. }
  207226. const Rectangle<int> NSViewComponentPeer::getBounds (const bool global) const
  207227. {
  207228. NSRect r = [view frame];
  207229. if (global && [view window] != 0)
  207230. {
  207231. r = [view convertRect: r toView: nil];
  207232. NSRect wr = [[view window] frame];
  207233. r.origin.x += wr.origin.x;
  207234. r.origin.y += wr.origin.y;
  207235. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207236. }
  207237. else
  207238. {
  207239. r.origin.y = [[view superview] frame].size.height - r.origin.y - r.size.height;
  207240. }
  207241. return Rectangle<int> ((int) r.origin.x, (int) r.origin.y, (int) r.size.width, (int) r.size.height);
  207242. }
  207243. const Rectangle<int> NSViewComponentPeer::getBounds() const
  207244. {
  207245. return getBounds (! isSharedWindow);
  207246. }
  207247. const Point<int> NSViewComponentPeer::getScreenPosition() const
  207248. {
  207249. return getBounds (true).getPosition();
  207250. }
  207251. const Point<int> NSViewComponentPeer::relativePositionToGlobal (const Point<int>& relativePosition)
  207252. {
  207253. return relativePosition + getScreenPosition();
  207254. }
  207255. const Point<int> NSViewComponentPeer::globalPositionToRelative (const Point<int>& screenPosition)
  207256. {
  207257. return screenPosition - getScreenPosition();
  207258. }
  207259. NSRect NSViewComponentPeer::constrainRect (NSRect r)
  207260. {
  207261. if (constrainer != 0)
  207262. {
  207263. NSRect current = [window frame];
  207264. current.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - current.origin.y - current.size.height;
  207265. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.origin.y - r.size.height;
  207266. Rectangle<int> pos ((int) r.origin.x, (int) r.origin.y,
  207267. (int) r.size.width, (int) r.size.height);
  207268. Rectangle<int> original ((int) current.origin.x, (int) current.origin.y,
  207269. (int) current.size.width, (int) current.size.height);
  207270. constrainer->checkBounds (pos, original,
  207271. Desktop::getInstance().getAllMonitorDisplayAreas().getBounds(),
  207272. pos.getY() != original.getY() && pos.getBottom() == original.getBottom(),
  207273. pos.getX() != original.getX() && pos.getRight() == original.getRight(),
  207274. pos.getY() == original.getY() && pos.getBottom() != original.getBottom(),
  207275. pos.getX() == original.getX() && pos.getRight() != original.getRight());
  207276. r.origin.x = pos.getX();
  207277. r.origin.y = [[[NSScreen screens] objectAtIndex: 0] frame].size.height - r.size.height - pos.getY();
  207278. r.size.width = pos.getWidth();
  207279. r.size.height = pos.getHeight();
  207280. }
  207281. return r;
  207282. }
  207283. void NSViewComponentPeer::setMinimised (bool shouldBeMinimised)
  207284. {
  207285. if (! isSharedWindow)
  207286. {
  207287. if (shouldBeMinimised)
  207288. [window miniaturize: nil];
  207289. else
  207290. [window deminiaturize: nil];
  207291. }
  207292. }
  207293. bool NSViewComponentPeer::isMinimised() const
  207294. {
  207295. return window != 0 && [window isMiniaturized];
  207296. }
  207297. void NSViewComponentPeer::setFullScreen (bool shouldBeFullScreen)
  207298. {
  207299. if (! isSharedWindow)
  207300. {
  207301. Rectangle<int> r (lastNonFullscreenBounds);
  207302. setMinimised (false);
  207303. if (fullScreen != shouldBeFullScreen)
  207304. {
  207305. if (shouldBeFullScreen && (getStyleFlags() & windowHasTitleBar) != 0)
  207306. {
  207307. fullScreen = true;
  207308. [window performZoom: nil];
  207309. }
  207310. else
  207311. {
  207312. if (shouldBeFullScreen)
  207313. r = Desktop::getInstance().getMainMonitorArea();
  207314. // (can't call the component's setBounds method because that'll reset our fullscreen flag)
  207315. if (r != getComponent()->getBounds() && ! r.isEmpty())
  207316. setBounds (r.getX(), r.getY(), r.getWidth(), r.getHeight(), shouldBeFullScreen);
  207317. }
  207318. }
  207319. }
  207320. }
  207321. bool NSViewComponentPeer::isFullScreen() const
  207322. {
  207323. return fullScreen;
  207324. }
  207325. bool NSViewComponentPeer::contains (int x, int y, bool trueIfInAChildWindow) const
  207326. {
  207327. if (((unsigned int) x) >= (unsigned int) component->getWidth()
  207328. || ((unsigned int) y) >= (unsigned int) component->getHeight())
  207329. return false;
  207330. NSPoint p;
  207331. p.x = (float) x;
  207332. p.y = (float) y;
  207333. NSView* v = [view hitTest: p];
  207334. if (trueIfInAChildWindow)
  207335. return v != nil;
  207336. return v == view;
  207337. }
  207338. const BorderSize NSViewComponentPeer::getFrameSize() const
  207339. {
  207340. BorderSize b;
  207341. if (! isSharedWindow)
  207342. {
  207343. NSRect v = [view convertRect: [view frame] toView: nil];
  207344. NSRect w = [window frame];
  207345. b.setTop ((int) (w.size.height - (v.origin.y + v.size.height)));
  207346. b.setBottom ((int) v.origin.y);
  207347. b.setLeft ((int) v.origin.x);
  207348. b.setRight ((int) (w.size.width - (v.origin.x + v.size.width)));
  207349. }
  207350. return b;
  207351. }
  207352. bool NSViewComponentPeer::setAlwaysOnTop (bool alwaysOnTop)
  207353. {
  207354. if (! isSharedWindow)
  207355. {
  207356. [window setLevel: alwaysOnTop ? NSFloatingWindowLevel
  207357. : NSNormalWindowLevel];
  207358. }
  207359. return true;
  207360. }
  207361. void NSViewComponentPeer::toFront (bool makeActiveWindow)
  207362. {
  207363. if (isSharedWindow)
  207364. {
  207365. [[view superview] addSubview: view
  207366. positioned: NSWindowAbove
  207367. relativeTo: nil];
  207368. }
  207369. if (window != 0 && component->isVisible())
  207370. {
  207371. if (makeActiveWindow)
  207372. [window makeKeyAndOrderFront: nil];
  207373. else
  207374. [window orderFront: nil];
  207375. if (! recursiveToFrontCall)
  207376. {
  207377. recursiveToFrontCall = true;
  207378. handleBroughtToFront();
  207379. recursiveToFrontCall = false;
  207380. }
  207381. }
  207382. }
  207383. void NSViewComponentPeer::toBehind (ComponentPeer* other)
  207384. {
  207385. NSViewComponentPeer* o = (NSViewComponentPeer*) other;
  207386. if (isSharedWindow)
  207387. {
  207388. [[view superview] addSubview: view
  207389. positioned: NSWindowBelow
  207390. relativeTo: o->view];
  207391. }
  207392. else
  207393. {
  207394. [window orderWindow: NSWindowBelow
  207395. relativeTo: o->window != 0 ? [o->window windowNumber]
  207396. : nil ];
  207397. }
  207398. }
  207399. void NSViewComponentPeer::setIcon (const Image& /*newIcon*/)
  207400. {
  207401. // to do..
  207402. }
  207403. void NSViewComponentPeer::viewFocusGain()
  207404. {
  207405. if (currentlyFocusedPeer != this)
  207406. {
  207407. if (ComponentPeer::isValidPeer (currentlyFocusedPeer))
  207408. currentlyFocusedPeer->handleFocusLoss();
  207409. currentlyFocusedPeer = this;
  207410. handleFocusGain();
  207411. }
  207412. }
  207413. void NSViewComponentPeer::viewFocusLoss()
  207414. {
  207415. if (currentlyFocusedPeer == this)
  207416. {
  207417. currentlyFocusedPeer = 0;
  207418. handleFocusLoss();
  207419. }
  207420. }
  207421. void juce_HandleProcessFocusChange()
  207422. {
  207423. keysCurrentlyDown.clear();
  207424. if (NSViewComponentPeer::isValidPeer (currentlyFocusedPeer))
  207425. {
  207426. if (Process::isForegroundProcess())
  207427. {
  207428. currentlyFocusedPeer->handleFocusGain();
  207429. ComponentPeer::bringModalComponentToFront();
  207430. }
  207431. else
  207432. {
  207433. currentlyFocusedPeer->handleFocusLoss();
  207434. // turn kiosk mode off if we lose focus..
  207435. Desktop::getInstance().setKioskModeComponent (0);
  207436. }
  207437. }
  207438. }
  207439. bool NSViewComponentPeer::isFocused() const
  207440. {
  207441. return isSharedWindow ? this == currentlyFocusedPeer
  207442. : (window != 0 && [window isKeyWindow]);
  207443. }
  207444. void NSViewComponentPeer::grabFocus()
  207445. {
  207446. if (window != 0)
  207447. {
  207448. [window makeKeyWindow];
  207449. [window makeFirstResponder: view];
  207450. viewFocusGain();
  207451. }
  207452. }
  207453. void NSViewComponentPeer::textInputRequired (const Point<int>&)
  207454. {
  207455. }
  207456. bool NSViewComponentPeer::handleKeyEvent (NSEvent* ev, bool isKeyDown)
  207457. {
  207458. String unicode (nsStringToJuce ([ev characters]));
  207459. String unmodified (nsStringToJuce ([ev charactersIgnoringModifiers]));
  207460. int keyCode = getKeyCodeFromEvent (ev);
  207461. //DBG ("unicode: " + unicode + " " + String::toHexString ((int) unicode[0]));
  207462. //DBG ("unmodified: " + unmodified + " " + String::toHexString ((int) unmodified[0]));
  207463. if (unicode.isNotEmpty() || keyCode != 0)
  207464. {
  207465. if (isKeyDown)
  207466. {
  207467. bool used = false;
  207468. while (unicode.length() > 0)
  207469. {
  207470. juce_wchar textCharacter = unicode[0];
  207471. unicode = unicode.substring (1);
  207472. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207473. textCharacter = 0;
  207474. used = handleKeyUpOrDown (true) || used;
  207475. used = handleKeyPress (keyCode, textCharacter) || used;
  207476. }
  207477. return used;
  207478. }
  207479. else
  207480. {
  207481. if (handleKeyUpOrDown (false))
  207482. return true;
  207483. }
  207484. }
  207485. return false;
  207486. }
  207487. bool NSViewComponentPeer::redirectKeyDown (NSEvent* ev)
  207488. {
  207489. updateKeysDown (ev, true);
  207490. bool used = handleKeyEvent (ev, true);
  207491. if (([ev modifierFlags] & NSCommandKeyMask) != 0)
  207492. {
  207493. // for command keys, the key-up event is thrown away, so simulate one..
  207494. updateKeysDown (ev, false);
  207495. used = (isValidPeer (this) && handleKeyEvent (ev, false)) || used;
  207496. }
  207497. // (If we're running modally, don't allow unused keystrokes to be passed
  207498. // along to other blocked views..)
  207499. if (Component::getCurrentlyModalComponent() != 0)
  207500. used = true;
  207501. return used;
  207502. }
  207503. bool NSViewComponentPeer::redirectKeyUp (NSEvent* ev)
  207504. {
  207505. updateKeysDown (ev, false);
  207506. return handleKeyEvent (ev, false)
  207507. || Component::getCurrentlyModalComponent() != 0;
  207508. }
  207509. void NSViewComponentPeer::redirectModKeyChange (NSEvent* ev)
  207510. {
  207511. keysCurrentlyDown.clear();
  207512. handleKeyUpOrDown (true);
  207513. updateModifiers (ev);
  207514. handleModifierKeysChange();
  207515. }
  207516. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  207517. bool NSViewComponentPeer::redirectPerformKeyEquivalent (NSEvent* ev)
  207518. {
  207519. if ([ev type] == NSKeyDown)
  207520. return redirectKeyDown (ev);
  207521. else if ([ev type] == NSKeyUp)
  207522. return redirectKeyUp (ev);
  207523. return false;
  207524. }
  207525. #endif
  207526. void NSViewComponentPeer::redirectMouseDown (NSEvent* ev)
  207527. {
  207528. updateModifiers (ev);
  207529. currentModifiers |= getModifierForButtonNumber ([ev buttonNumber]);
  207530. handleMouseDown (getMousePos (ev, view), getMouseTime (ev));
  207531. }
  207532. void NSViewComponentPeer::redirectMouseUp (NSEvent* ev)
  207533. {
  207534. const int oldMods = currentModifiers;
  207535. updateModifiers (ev);
  207536. currentModifiers &= ~getModifierForButtonNumber ([ev buttonNumber]);
  207537. handleMouseUp (oldMods, getMousePos (ev, view), getMouseTime (ev));
  207538. showArrowCursorIfNeeded();
  207539. }
  207540. void NSViewComponentPeer::redirectMouseDrag (NSEvent* ev)
  207541. {
  207542. updateModifiers (ev);
  207543. currentModifiers |= getModifierForButtonNumber ([ev buttonNumber]);
  207544. handleMouseDrag (getMousePos (ev, view), getMouseTime (ev));
  207545. }
  207546. void NSViewComponentPeer::redirectMouseMove (NSEvent* ev)
  207547. {
  207548. updateModifiers (ev);
  207549. handleMouseMove (getMousePos (ev, view), getMouseTime (ev));
  207550. showArrowCursorIfNeeded();
  207551. }
  207552. void NSViewComponentPeer::redirectMouseEnter (NSEvent* ev)
  207553. {
  207554. updateModifiers (ev);
  207555. handleMouseEnter (getMousePos (ev, view), getMouseTime (ev));
  207556. }
  207557. void NSViewComponentPeer::redirectMouseExit (NSEvent* ev)
  207558. {
  207559. updateModifiers (ev);
  207560. handleMouseExit (getMousePos (ev, view), getMouseTime (ev));
  207561. }
  207562. void NSViewComponentPeer::redirectMouseWheel (NSEvent* ev)
  207563. {
  207564. updateModifiers (ev);
  207565. handleMouseWheel (roundToInt ([ev deltaX] * 10.0f),
  207566. roundToInt ([ev deltaY] * 10.0f),
  207567. getMouseTime (ev));
  207568. }
  207569. void NSViewComponentPeer::showArrowCursorIfNeeded()
  207570. {
  207571. if (Component::getComponentUnderMouse() == 0
  207572. && Desktop::getInstance().findComponentAt (Desktop::getInstance().getMousePosition()) == 0)
  207573. {
  207574. [[NSCursor arrowCursor] set];
  207575. }
  207576. }
  207577. BOOL NSViewComponentPeer::sendDragCallback (int type, id <NSDraggingInfo> sender)
  207578. {
  207579. NSString* bestType
  207580. = [[sender draggingPasteboard] availableTypeFromArray: [view getSupportedDragTypes]];
  207581. if (bestType == nil)
  207582. return false;
  207583. NSPoint p = [view convertPoint: [sender draggingLocation] fromView: nil];
  207584. const Point<int> pos ((int) p.x, (int) ([view frame].size.height - p.y));
  207585. StringArray files;
  207586. id list = [[sender draggingPasteboard] propertyListForType: bestType];
  207587. if (list == nil)
  207588. return false;
  207589. if ([list isKindOfClass: [NSArray class]])
  207590. {
  207591. NSArray* items = (NSArray*) list;
  207592. for (unsigned int i = 0; i < [items count]; ++i)
  207593. files.add (nsStringToJuce ((NSString*) [items objectAtIndex: i]));
  207594. }
  207595. if (files.size() == 0)
  207596. return false;
  207597. if (type == 0)
  207598. handleFileDragMove (files, pos);
  207599. else if (type == 1)
  207600. handleFileDragExit (files);
  207601. else if (type == 2)
  207602. handleFileDragDrop (files, pos);
  207603. return true;
  207604. }
  207605. bool NSViewComponentPeer::isOpaque()
  207606. {
  207607. if (! getComponent()->isValidComponent())
  207608. return true;
  207609. return getComponent()->isOpaque();
  207610. }
  207611. void NSViewComponentPeer::drawRect (NSRect r)
  207612. {
  207613. if (r.size.width < 1.0f || r.size.height < 1.0f)
  207614. return;
  207615. CGContextRef cg = (CGContextRef) [[NSGraphicsContext currentContext] graphicsPort];
  207616. if (! component->isOpaque())
  207617. CGContextClearRect (cg, CGContextGetClipBoundingBox (cg));
  207618. #if USE_COREGRAPHICS_RENDERING
  207619. if (usingCoreGraphics)
  207620. {
  207621. CoreGraphicsContext context (cg, (float) [view frame].size.height);
  207622. insideDrawRect = true;
  207623. handlePaint (context);
  207624. insideDrawRect = false;
  207625. }
  207626. else
  207627. #endif
  207628. {
  207629. Image temp (getComponent()->isOpaque() ? Image::RGB : Image::ARGB,
  207630. (int) (r.size.width + 0.5f),
  207631. (int) (r.size.height + 0.5f),
  207632. ! getComponent()->isOpaque());
  207633. LowLevelGraphicsSoftwareRenderer context (temp);
  207634. context.setOrigin (-roundToInt (r.origin.x),
  207635. -roundToInt ([view frame].size.height - (r.origin.y + r.size.height)));
  207636. const NSRect* rects = 0;
  207637. NSInteger numRects = 0;
  207638. [view getRectsBeingDrawn: &rects count: &numRects];
  207639. RectangleList clip;
  207640. for (int i = 0; i < numRects; ++i)
  207641. {
  207642. clip.addWithoutMerging (Rectangle<int> (roundToInt (rects[i].origin.x),
  207643. roundToInt ([view frame].size.height - (rects[i].origin.y + rects[i].size.height)),
  207644. roundToInt (rects[i].size.width),
  207645. roundToInt (rects[i].size.height)));
  207646. }
  207647. if (context.clipToRectangleList (clip))
  207648. {
  207649. insideDrawRect = true;
  207650. handlePaint (context);
  207651. insideDrawRect = false;
  207652. CGColorSpaceRef colourSpace = CGColorSpaceCreateDeviceRGB();
  207653. CGImageRef image = CoreGraphicsImage::createImage (temp, false, colourSpace);
  207654. CGColorSpaceRelease (colourSpace);
  207655. CGContextDrawImage (cg, CGRectMake (r.origin.x, r.origin.y, temp.getWidth(), temp.getHeight()), image);
  207656. CGImageRelease (image);
  207657. }
  207658. }
  207659. }
  207660. const StringArray NSViewComponentPeer::getAvailableRenderingEngines() throw()
  207661. {
  207662. StringArray s;
  207663. s.add ("Software Renderer");
  207664. #if USE_COREGRAPHICS_RENDERING
  207665. s.add ("CoreGraphics Renderer");
  207666. #endif
  207667. return s;
  207668. }
  207669. int NSViewComponentPeer::getCurrentRenderingEngine() throw()
  207670. {
  207671. return usingCoreGraphics ? 1 : 0;
  207672. }
  207673. void NSViewComponentPeer::setCurrentRenderingEngine (int index) throw()
  207674. {
  207675. #if USE_COREGRAPHICS_RENDERING
  207676. if (usingCoreGraphics != (index > 0))
  207677. {
  207678. usingCoreGraphics = index > 0;
  207679. [view setNeedsDisplay: true];
  207680. }
  207681. #endif
  207682. }
  207683. bool NSViewComponentPeer::canBecomeKeyWindow()
  207684. {
  207685. return (getStyleFlags() & JUCE_NAMESPACE::ComponentPeer::windowIgnoresKeyPresses) == 0;
  207686. }
  207687. bool NSViewComponentPeer::windowShouldClose()
  207688. {
  207689. if (! isValidPeer (this))
  207690. return YES;
  207691. handleUserClosingWindow();
  207692. return NO;
  207693. }
  207694. void NSViewComponentPeer::redirectMovedOrResized()
  207695. {
  207696. handleMovedOrResized();
  207697. }
  207698. void NSViewComponentPeer::viewMovedToWindow()
  207699. {
  207700. if (isSharedWindow)
  207701. window = [view window];
  207702. }
  207703. void juce_setKioskComponent (Component* kioskModeComponent, bool enableOrDisable, bool allowMenusAndBars)
  207704. {
  207705. // Very annoyingly, this function has to use the old SetSystemUIMode function,
  207706. // which is in Carbon.framework. But, because there's no Cocoa equivalent, it
  207707. // is apparently still available in 64-bit apps..
  207708. if (enableOrDisable)
  207709. {
  207710. SetSystemUIMode (kUIModeAllSuppressed, allowMenusAndBars ? kUIOptionAutoShowMenuBar : 0);
  207711. kioskModeComponent->setBounds (Desktop::getInstance().getMainMonitorArea (false));
  207712. }
  207713. else
  207714. {
  207715. SetSystemUIMode (kUIModeNormal, 0);
  207716. }
  207717. }
  207718. class AsyncRepaintMessage : public CallbackMessage
  207719. {
  207720. public:
  207721. NSViewComponentPeer* const peer;
  207722. const Rectangle<int> rect;
  207723. AsyncRepaintMessage (NSViewComponentPeer* const peer_, const Rectangle<int>& rect_)
  207724. : peer (peer_), rect (rect_)
  207725. {
  207726. }
  207727. void messageCallback()
  207728. {
  207729. if (ComponentPeer::isValidPeer (peer))
  207730. peer->repaint (rect.getX(), rect.getY(), rect.getWidth(), rect.getHeight());
  207731. }
  207732. };
  207733. void NSViewComponentPeer::repaint (int x, int y, int w, int h)
  207734. {
  207735. if (insideDrawRect)
  207736. {
  207737. (new AsyncRepaintMessage (this, Rectangle<int> (x, y, w, h)))->post();
  207738. }
  207739. else
  207740. {
  207741. [view setNeedsDisplayInRect: NSMakeRect ((float) x, (float) ([view frame].size.height - (y + h)),
  207742. (float) w, (float) h)];
  207743. }
  207744. }
  207745. void NSViewComponentPeer::performAnyPendingRepaintsNow()
  207746. {
  207747. [view displayIfNeeded];
  207748. }
  207749. ComponentPeer* Component::createNewPeer (int styleFlags, void* windowToAttachTo)
  207750. {
  207751. return new NSViewComponentPeer (this, styleFlags, (NSView*) windowToAttachTo);
  207752. }
  207753. Image* juce_createIconForFile (const File& file)
  207754. {
  207755. const ScopedAutoReleasePool pool;
  207756. NSImage* image = [[NSWorkspace sharedWorkspace] iconForFile: juceStringToNS (file.getFullPathName())];
  207757. CoreGraphicsImage* result = new CoreGraphicsImage (Image::ARGB, (int) [image size].width, (int) [image size].height, true);
  207758. [NSGraphicsContext saveGraphicsState];
  207759. [NSGraphicsContext setCurrentContext: [NSGraphicsContext graphicsContextWithGraphicsPort: result->context flipped: false]];
  207760. [image drawAtPoint: NSMakePoint (0, 0)
  207761. fromRect: NSMakeRect (0, 0, [image size].width, [image size].height)
  207762. operation: NSCompositeSourceOver fraction: 1.0f];
  207763. [[NSGraphicsContext currentContext] flushGraphics];
  207764. [NSGraphicsContext restoreGraphicsState];
  207765. return result;
  207766. }
  207767. const int KeyPress::spaceKey = ' ';
  207768. const int KeyPress::returnKey = 0x0d;
  207769. const int KeyPress::escapeKey = 0x1b;
  207770. const int KeyPress::backspaceKey = 0x7f;
  207771. const int KeyPress::leftKey = NSLeftArrowFunctionKey;
  207772. const int KeyPress::rightKey = NSRightArrowFunctionKey;
  207773. const int KeyPress::upKey = NSUpArrowFunctionKey;
  207774. const int KeyPress::downKey = NSDownArrowFunctionKey;
  207775. const int KeyPress::pageUpKey = NSPageUpFunctionKey;
  207776. const int KeyPress::pageDownKey = NSPageDownFunctionKey;
  207777. const int KeyPress::endKey = NSEndFunctionKey;
  207778. const int KeyPress::homeKey = NSHomeFunctionKey;
  207779. const int KeyPress::deleteKey = NSDeleteFunctionKey;
  207780. const int KeyPress::insertKey = -1;
  207781. const int KeyPress::tabKey = 9;
  207782. const int KeyPress::F1Key = NSF1FunctionKey;
  207783. const int KeyPress::F2Key = NSF2FunctionKey;
  207784. const int KeyPress::F3Key = NSF3FunctionKey;
  207785. const int KeyPress::F4Key = NSF4FunctionKey;
  207786. const int KeyPress::F5Key = NSF5FunctionKey;
  207787. const int KeyPress::F6Key = NSF6FunctionKey;
  207788. const int KeyPress::F7Key = NSF7FunctionKey;
  207789. const int KeyPress::F8Key = NSF8FunctionKey;
  207790. const int KeyPress::F9Key = NSF9FunctionKey;
  207791. const int KeyPress::F10Key = NSF10FunctionKey;
  207792. const int KeyPress::F11Key = NSF1FunctionKey;
  207793. const int KeyPress::F12Key = NSF12FunctionKey;
  207794. const int KeyPress::F13Key = NSF13FunctionKey;
  207795. const int KeyPress::F14Key = NSF14FunctionKey;
  207796. const int KeyPress::F15Key = NSF15FunctionKey;
  207797. const int KeyPress::F16Key = NSF16FunctionKey;
  207798. const int KeyPress::numberPad0 = 0x30020;
  207799. const int KeyPress::numberPad1 = 0x30021;
  207800. const int KeyPress::numberPad2 = 0x30022;
  207801. const int KeyPress::numberPad3 = 0x30023;
  207802. const int KeyPress::numberPad4 = 0x30024;
  207803. const int KeyPress::numberPad5 = 0x30025;
  207804. const int KeyPress::numberPad6 = 0x30026;
  207805. const int KeyPress::numberPad7 = 0x30027;
  207806. const int KeyPress::numberPad8 = 0x30028;
  207807. const int KeyPress::numberPad9 = 0x30029;
  207808. const int KeyPress::numberPadAdd = 0x3002a;
  207809. const int KeyPress::numberPadSubtract = 0x3002b;
  207810. const int KeyPress::numberPadMultiply = 0x3002c;
  207811. const int KeyPress::numberPadDivide = 0x3002d;
  207812. const int KeyPress::numberPadSeparator = 0x3002e;
  207813. const int KeyPress::numberPadDecimalPoint = 0x3002f;
  207814. const int KeyPress::numberPadEquals = 0x30030;
  207815. const int KeyPress::numberPadDelete = 0x30031;
  207816. const int KeyPress::playKey = 0x30000;
  207817. const int KeyPress::stopKey = 0x30001;
  207818. const int KeyPress::fastForwardKey = 0x30002;
  207819. const int KeyPress::rewindKey = 0x30003;
  207820. #endif
  207821. /*** End of inlined file: juce_mac_NSViewComponentPeer.mm ***/
  207822. /*** Start of inlined file: juce_mac_MouseCursor.mm ***/
  207823. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207824. // compiled on its own).
  207825. #if JUCE_INCLUDED_FILE
  207826. #if JUCE_MAC
  207827. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw()
  207828. {
  207829. NSImage* im = CoreGraphicsImage::createNSImage (image);
  207830. NSCursor* c = [[NSCursor alloc] initWithImage: im
  207831. hotSpot: NSMakePoint (hotspotX, hotspotY)];
  207832. [im release];
  207833. return (void*) c;
  207834. }
  207835. static void* juce_cursorFromData (const unsigned char* data, const size_t size, float hx, float hy) throw()
  207836. {
  207837. ScopedPointer <Image> im (ImageFileFormat::loadFrom ((const char*) data, (int) size));
  207838. jassert (im != 0);
  207839. if (im == 0)
  207840. return 0;
  207841. return juce_createMouseCursorFromImage (*im,
  207842. (int) (hx * im->getWidth()),
  207843. (int) (hy * im->getHeight()));
  207844. }
  207845. static void* juce_cursorFromWebKitFile (const char* filename, float hx, float hy)
  207846. {
  207847. File f ("/System/Library/Frameworks/WebKit.framework/Frameworks/WebCore.framework/Resources");
  207848. MemoryBlock mb;
  207849. if (f.getChildFile (filename).loadFileAsData (mb))
  207850. return juce_cursorFromData ((const unsigned char*) mb.getData(), mb.getSize(), hx, hy);
  207851. return 0;
  207852. }
  207853. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw()
  207854. {
  207855. const ScopedAutoReleasePool pool;
  207856. NSCursor* c = 0;
  207857. switch (type)
  207858. {
  207859. case MouseCursor::NormalCursor:
  207860. c = [NSCursor arrowCursor];
  207861. break;
  207862. case MouseCursor::NoCursor:
  207863. {
  207864. Image blank (Image::ARGB, 8, 8, true);
  207865. return juce_createMouseCursorFromImage (blank, 0, 0);
  207866. }
  207867. case MouseCursor::DraggingHandCursor:
  207868. c = [NSCursor openHandCursor];
  207869. break;
  207870. case MouseCursor::CopyingCursor:
  207871. return juce_cursorFromWebKitFile ("copyCursor.png", 0, 0);
  207872. case MouseCursor::WaitCursor:
  207873. c = [NSCursor arrowCursor]; // avoid this on the mac, let the OS provide the beachball
  207874. break;
  207875. //return juce_cursorFromWebKitFile ("waitCursor.png", 0.5f, 0.5f);
  207876. case MouseCursor::IBeamCursor:
  207877. c = [NSCursor IBeamCursor];
  207878. break;
  207879. case MouseCursor::PointingHandCursor:
  207880. c = [NSCursor pointingHandCursor];
  207881. break;
  207882. case MouseCursor::LeftRightResizeCursor:
  207883. c = [NSCursor resizeLeftRightCursor];
  207884. break;
  207885. case MouseCursor::LeftEdgeResizeCursor:
  207886. c = [NSCursor resizeLeftCursor];
  207887. break;
  207888. case MouseCursor::RightEdgeResizeCursor:
  207889. c = [NSCursor resizeRightCursor];
  207890. break;
  207891. case MouseCursor::UpDownResizeCursor:
  207892. case MouseCursor::TopEdgeResizeCursor:
  207893. case MouseCursor::BottomEdgeResizeCursor:
  207894. return juce_cursorFromWebKitFile ("northSouthResizeCursor.png", 0.5f, 0.5f);
  207895. case MouseCursor::TopLeftCornerResizeCursor:
  207896. case MouseCursor::BottomRightCornerResizeCursor:
  207897. return juce_cursorFromWebKitFile ("northWestSouthEastResizeCursor.png", 0.5f, 0.5f);
  207898. case MouseCursor::TopRightCornerResizeCursor:
  207899. case MouseCursor::BottomLeftCornerResizeCursor:
  207900. return juce_cursorFromWebKitFile ("northEastSouthWestResizeCursor.png", 0.5f, 0.5f);
  207901. case MouseCursor::UpDownLeftRightResizeCursor:
  207902. return juce_cursorFromWebKitFile ("moveCursor.png", 0.5f, 0.5f);
  207903. case MouseCursor::CrosshairCursor:
  207904. c = [NSCursor crosshairCursor];
  207905. break;
  207906. }
  207907. [c retain];
  207908. return (void*) c;
  207909. }
  207910. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw()
  207911. {
  207912. NSCursor* c = (NSCursor*) cursorHandle;
  207913. [c release];
  207914. }
  207915. void MouseCursor::showInAllWindows() const throw()
  207916. {
  207917. showInWindow (0);
  207918. }
  207919. void MouseCursor::showInWindow (ComponentPeer*) const throw()
  207920. {
  207921. NSCursor* const c = (NSCursor*) getHandle();
  207922. [c set];
  207923. }
  207924. #else
  207925. void* juce_createMouseCursorFromImage (const Image& image, int hotspotX, int hotspotY) throw() { return 0; }
  207926. void* juce_createStandardMouseCursor (MouseCursor::StandardCursorType type) throw() { return 0; }
  207927. void juce_deleteMouseCursor (void* const cursorHandle, const bool isStandard) throw() {}
  207928. void MouseCursor::showInAllWindows() const throw() {}
  207929. void MouseCursor::showInWindow (ComponentPeer*) const throw() {}
  207930. #endif
  207931. #endif
  207932. /*** End of inlined file: juce_mac_MouseCursor.mm ***/
  207933. /*** Start of inlined file: juce_mac_NSViewComponent.mm ***/
  207934. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  207935. // compiled on its own).
  207936. #if JUCE_INCLUDED_FILE
  207937. class NSViewComponentInternal : public ComponentMovementWatcher
  207938. {
  207939. Component* const owner;
  207940. NSViewComponentPeer* currentPeer;
  207941. bool wasShowing;
  207942. public:
  207943. NSView* const view;
  207944. NSViewComponentInternal (NSView* const view_, Component* const owner_)
  207945. : ComponentMovementWatcher (owner_),
  207946. owner (owner_),
  207947. currentPeer (0),
  207948. wasShowing (false),
  207949. view (view_)
  207950. {
  207951. [view_ retain];
  207952. if (owner_->isShowing())
  207953. componentPeerChanged();
  207954. }
  207955. ~NSViewComponentInternal()
  207956. {
  207957. [view removeFromSuperview];
  207958. [view release];
  207959. }
  207960. void componentMovedOrResized (Component& comp, bool wasMoved, bool wasResized)
  207961. {
  207962. ComponentMovementWatcher::componentMovedOrResized (comp, wasMoved, wasResized);
  207963. // The ComponentMovementWatcher version of this method avoids calling
  207964. // us when the top-level comp is resized, but for an NSView we need to know this
  207965. // because with inverted co-ords, we need to update the position even if the
  207966. // top-left pos hasn't changed
  207967. if (comp.isOnDesktop() && wasResized)
  207968. componentMovedOrResized (wasMoved, wasResized);
  207969. }
  207970. void componentMovedOrResized (bool /*wasMoved*/, bool /*wasResized*/)
  207971. {
  207972. Component* const topComp = owner->getTopLevelComponent();
  207973. if (topComp->getPeer() != 0)
  207974. {
  207975. const Point<int> pos (owner->relativePositionToOtherComponent (topComp, Point<int>()));
  207976. NSRect r;
  207977. r.origin.x = (float) pos.getX();
  207978. r.origin.y = (float) pos.getY();
  207979. r.size.width = (float) owner->getWidth();
  207980. r.size.height = (float) owner->getHeight();
  207981. r.origin.y = [[view superview] frame].size.height - (r.origin.y + r.size.height);
  207982. [view setFrame: r];
  207983. }
  207984. }
  207985. void componentPeerChanged()
  207986. {
  207987. NSViewComponentPeer* const peer = dynamic_cast <NSViewComponentPeer*> (owner->getPeer());
  207988. if (currentPeer != peer)
  207989. {
  207990. [view removeFromSuperview];
  207991. currentPeer = peer;
  207992. if (peer != 0)
  207993. {
  207994. [peer->view addSubview: view];
  207995. componentMovedOrResized (false, false);
  207996. }
  207997. }
  207998. [view setHidden: ! owner->isShowing()];
  207999. }
  208000. void componentVisibilityChanged (Component&)
  208001. {
  208002. componentPeerChanged();
  208003. }
  208004. juce_UseDebuggingNewOperator
  208005. private:
  208006. NSViewComponentInternal (const NSViewComponentInternal&);
  208007. NSViewComponentInternal& operator= (const NSViewComponentInternal&);
  208008. };
  208009. NSViewComponent::NSViewComponent()
  208010. {
  208011. }
  208012. NSViewComponent::~NSViewComponent()
  208013. {
  208014. }
  208015. void NSViewComponent::setView (void* view)
  208016. {
  208017. if (view != getView())
  208018. {
  208019. if (view != 0)
  208020. info = new NSViewComponentInternal ((NSView*) view, this);
  208021. else
  208022. info = 0;
  208023. }
  208024. }
  208025. void* NSViewComponent::getView() const
  208026. {
  208027. return info == 0 ? 0 : info->view;
  208028. }
  208029. void NSViewComponent::paint (Graphics& g)
  208030. {
  208031. }
  208032. #endif
  208033. /*** End of inlined file: juce_mac_NSViewComponent.mm ***/
  208034. /*** Start of inlined file: juce_mac_AppleRemote.mm ***/
  208035. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208036. // compiled on its own).
  208037. #if JUCE_INCLUDED_FILE
  208038. AppleRemoteDevice::AppleRemoteDevice()
  208039. : device (0),
  208040. queue (0),
  208041. remoteId (0)
  208042. {
  208043. }
  208044. AppleRemoteDevice::~AppleRemoteDevice()
  208045. {
  208046. stop();
  208047. }
  208048. static io_object_t getAppleRemoteDevice()
  208049. {
  208050. CFMutableDictionaryRef dict = IOServiceMatching ("AppleIRController");
  208051. io_iterator_t iter = 0;
  208052. io_object_t iod = 0;
  208053. if (IOServiceGetMatchingServices (kIOMasterPortDefault, dict, &iter) == kIOReturnSuccess
  208054. && iter != 0)
  208055. {
  208056. iod = IOIteratorNext (iter);
  208057. }
  208058. IOObjectRelease (iter);
  208059. return iod;
  208060. }
  208061. static bool createAppleRemoteInterface (io_object_t iod, void** device)
  208062. {
  208063. jassert (*device == 0);
  208064. io_name_t classname;
  208065. if (IOObjectGetClass (iod, classname) == kIOReturnSuccess)
  208066. {
  208067. IOCFPlugInInterface** cfPlugInInterface = 0;
  208068. SInt32 score = 0;
  208069. if (IOCreatePlugInInterfaceForService (iod,
  208070. kIOHIDDeviceUserClientTypeID,
  208071. kIOCFPlugInInterfaceID,
  208072. &cfPlugInInterface,
  208073. &score) == kIOReturnSuccess)
  208074. {
  208075. HRESULT hr = (*cfPlugInInterface)->QueryInterface (cfPlugInInterface,
  208076. CFUUIDGetUUIDBytes (kIOHIDDeviceInterfaceID),
  208077. device);
  208078. (void) hr;
  208079. (*cfPlugInInterface)->Release (cfPlugInInterface);
  208080. }
  208081. }
  208082. return *device != 0;
  208083. }
  208084. bool AppleRemoteDevice::start (const bool inExclusiveMode)
  208085. {
  208086. if (queue != 0)
  208087. return true;
  208088. stop();
  208089. bool result = false;
  208090. io_object_t iod = getAppleRemoteDevice();
  208091. if (iod != 0)
  208092. {
  208093. if (createAppleRemoteInterface (iod, &device) && open (inExclusiveMode))
  208094. result = true;
  208095. else
  208096. stop();
  208097. IOObjectRelease (iod);
  208098. }
  208099. return result;
  208100. }
  208101. void AppleRemoteDevice::stop()
  208102. {
  208103. if (queue != 0)
  208104. {
  208105. (*(IOHIDQueueInterface**) queue)->stop ((IOHIDQueueInterface**) queue);
  208106. (*(IOHIDQueueInterface**) queue)->dispose ((IOHIDQueueInterface**) queue);
  208107. (*(IOHIDQueueInterface**) queue)->Release ((IOHIDQueueInterface**) queue);
  208108. queue = 0;
  208109. }
  208110. if (device != 0)
  208111. {
  208112. (*(IOHIDDeviceInterface**) device)->close ((IOHIDDeviceInterface**) device);
  208113. (*(IOHIDDeviceInterface**) device)->Release ((IOHIDDeviceInterface**) device);
  208114. device = 0;
  208115. }
  208116. }
  208117. bool AppleRemoteDevice::isActive() const
  208118. {
  208119. return queue != 0;
  208120. }
  208121. static void appleRemoteQueueCallback (void* const target, const IOReturn result, void*, void*)
  208122. {
  208123. if (result == kIOReturnSuccess)
  208124. ((AppleRemoteDevice*) target)->handleCallbackInternal();
  208125. }
  208126. bool AppleRemoteDevice::open (const bool openInExclusiveMode)
  208127. {
  208128. Array <int> cookies;
  208129. CFArrayRef elements;
  208130. IOHIDDeviceInterface122** const device122 = (IOHIDDeviceInterface122**) device;
  208131. if ((*device122)->copyMatchingElements (device122, 0, &elements) != kIOReturnSuccess)
  208132. return false;
  208133. for (int i = 0; i < CFArrayGetCount (elements); ++i)
  208134. {
  208135. CFDictionaryRef element = (CFDictionaryRef) CFArrayGetValueAtIndex (elements, i);
  208136. // get the cookie
  208137. CFTypeRef object = CFDictionaryGetValue (element, CFSTR (kIOHIDElementCookieKey));
  208138. if (object == 0 || CFGetTypeID (object) != CFNumberGetTypeID())
  208139. continue;
  208140. long number;
  208141. if (! CFNumberGetValue ((CFNumberRef) object, kCFNumberLongType, &number))
  208142. continue;
  208143. cookies.add ((int) number);
  208144. }
  208145. CFRelease (elements);
  208146. if ((*(IOHIDDeviceInterface**) device)
  208147. ->open ((IOHIDDeviceInterface**) device,
  208148. openInExclusiveMode ? kIOHIDOptionsTypeSeizeDevice
  208149. : kIOHIDOptionsTypeNone) == KERN_SUCCESS)
  208150. {
  208151. queue = (*(IOHIDDeviceInterface**) device)->allocQueue ((IOHIDDeviceInterface**) device);
  208152. if (queue != 0)
  208153. {
  208154. (*(IOHIDQueueInterface**) queue)->create ((IOHIDQueueInterface**) queue, 0, 12);
  208155. for (int i = 0; i < cookies.size(); ++i)
  208156. {
  208157. IOHIDElementCookie cookie = (IOHIDElementCookie) cookies.getUnchecked(i);
  208158. (*(IOHIDQueueInterface**) queue)->addElement ((IOHIDQueueInterface**) queue, cookie, 0);
  208159. }
  208160. CFRunLoopSourceRef eventSource;
  208161. if ((*(IOHIDQueueInterface**) queue)
  208162. ->createAsyncEventSource ((IOHIDQueueInterface**) queue, &eventSource) == KERN_SUCCESS)
  208163. {
  208164. if ((*(IOHIDQueueInterface**) queue)->setEventCallout ((IOHIDQueueInterface**) queue,
  208165. appleRemoteQueueCallback, this, 0) == KERN_SUCCESS)
  208166. {
  208167. CFRunLoopAddSource (CFRunLoopGetCurrent(), eventSource, kCFRunLoopDefaultMode);
  208168. (*(IOHIDQueueInterface**) queue)->start ((IOHIDQueueInterface**) queue);
  208169. return true;
  208170. }
  208171. }
  208172. }
  208173. }
  208174. return false;
  208175. }
  208176. void AppleRemoteDevice::handleCallbackInternal()
  208177. {
  208178. int totalValues = 0;
  208179. AbsoluteTime nullTime = { 0, 0 };
  208180. char cookies [12];
  208181. int numCookies = 0;
  208182. while (numCookies < numElementsInArray (cookies))
  208183. {
  208184. IOHIDEventStruct e;
  208185. if ((*(IOHIDQueueInterface**) queue)->getNextEvent ((IOHIDQueueInterface**) queue, &e, nullTime, 0) != kIOReturnSuccess)
  208186. break;
  208187. if ((int) e.elementCookie == 19)
  208188. {
  208189. remoteId = e.value;
  208190. buttonPressed (switched, false);
  208191. }
  208192. else
  208193. {
  208194. totalValues += e.value;
  208195. cookies [numCookies++] = (char) (pointer_sized_int) e.elementCookie;
  208196. }
  208197. }
  208198. cookies [numCookies++] = 0;
  208199. //DBG (String::toHexString ((uint8*) cookies, numCookies, 1) + " " + String (totalValues));
  208200. static const char buttonPatterns[] =
  208201. {
  208202. 0x1f, 0x14, 0x12, 0x1f, 0x14, 0x12, 0,
  208203. 0x1f, 0x15, 0x12, 0x1f, 0x15, 0x12, 0,
  208204. 0x1f, 0x1d, 0x1c, 0x12, 0,
  208205. 0x1f, 0x1e, 0x1c, 0x12, 0,
  208206. 0x1f, 0x16, 0x12, 0x1f, 0x16, 0x12, 0,
  208207. 0x1f, 0x17, 0x12, 0x1f, 0x17, 0x12, 0,
  208208. 0x1f, 0x12, 0x04, 0x02, 0,
  208209. 0x1f, 0x12, 0x03, 0x02, 0,
  208210. 0x1f, 0x12, 0x1f, 0x12, 0,
  208211. 0x23, 0x1f, 0x12, 0x23, 0x1f, 0x12, 0,
  208212. 19, 0
  208213. };
  208214. int buttonNum = (int) menuButton;
  208215. int i = 0;
  208216. while (i < numElementsInArray (buttonPatterns))
  208217. {
  208218. if (strcmp (cookies, buttonPatterns + i) == 0)
  208219. {
  208220. buttonPressed ((ButtonType) buttonNum, totalValues > 0);
  208221. break;
  208222. }
  208223. i += (int) strlen (buttonPatterns + i) + 1;
  208224. ++buttonNum;
  208225. }
  208226. }
  208227. #endif
  208228. /*** End of inlined file: juce_mac_AppleRemote.mm ***/
  208229. /*** Start of inlined file: juce_mac_OpenGLComponent.mm ***/
  208230. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208231. // compiled on its own).
  208232. #if JUCE_INCLUDED_FILE && JUCE_OPENGL
  208233. #if JUCE_MAC
  208234. END_JUCE_NAMESPACE
  208235. #define ThreadSafeNSOpenGLView MakeObjCClassName(ThreadSafeNSOpenGLView)
  208236. @interface ThreadSafeNSOpenGLView : NSOpenGLView
  208237. {
  208238. CriticalSection* contextLock;
  208239. bool needsUpdate;
  208240. }
  208241. - (id) initWithFrame: (NSRect) frameRect pixelFormat: (NSOpenGLPixelFormat*) format;
  208242. - (bool) makeActive;
  208243. - (void) makeInactive;
  208244. - (void) reshape;
  208245. @end
  208246. @implementation ThreadSafeNSOpenGLView
  208247. - (id) initWithFrame: (NSRect) frameRect
  208248. pixelFormat: (NSOpenGLPixelFormat*) format
  208249. {
  208250. contextLock = new CriticalSection();
  208251. self = [super initWithFrame: frameRect pixelFormat: format];
  208252. if (self != nil)
  208253. [[NSNotificationCenter defaultCenter] addObserver: self
  208254. selector: @selector (_surfaceNeedsUpdate:)
  208255. name: NSViewGlobalFrameDidChangeNotification
  208256. object: self];
  208257. return self;
  208258. }
  208259. - (void) dealloc
  208260. {
  208261. [[NSNotificationCenter defaultCenter] removeObserver: self];
  208262. delete contextLock;
  208263. [super dealloc];
  208264. }
  208265. - (bool) makeActive
  208266. {
  208267. const ScopedLock sl (*contextLock);
  208268. if ([self openGLContext] == 0)
  208269. return false;
  208270. [[self openGLContext] makeCurrentContext];
  208271. if (needsUpdate)
  208272. {
  208273. [super update];
  208274. needsUpdate = false;
  208275. }
  208276. return true;
  208277. }
  208278. - (void) makeInactive
  208279. {
  208280. const ScopedLock sl (*contextLock);
  208281. [NSOpenGLContext clearCurrentContext];
  208282. }
  208283. - (void) _surfaceNeedsUpdate: (NSNotification*) notification
  208284. {
  208285. const ScopedLock sl (*contextLock);
  208286. needsUpdate = true;
  208287. }
  208288. - (void) update
  208289. {
  208290. const ScopedLock sl (*contextLock);
  208291. needsUpdate = true;
  208292. }
  208293. - (void) reshape
  208294. {
  208295. const ScopedLock sl (*contextLock);
  208296. needsUpdate = true;
  208297. }
  208298. @end
  208299. BEGIN_JUCE_NAMESPACE
  208300. class WindowedGLContext : public OpenGLContext
  208301. {
  208302. public:
  208303. WindowedGLContext (Component* const component,
  208304. const OpenGLPixelFormat& pixelFormat_,
  208305. NSOpenGLContext* sharedContext)
  208306. : renderContext (0),
  208307. pixelFormat (pixelFormat_)
  208308. {
  208309. jassert (component != 0);
  208310. NSOpenGLPixelFormatAttribute attribs [64];
  208311. int n = 0;
  208312. attribs[n++] = NSOpenGLPFADoubleBuffer;
  208313. attribs[n++] = NSOpenGLPFAAccelerated;
  208314. attribs[n++] = NSOpenGLPFAMPSafe; // NSOpenGLPFAAccelerated, NSOpenGLPFAMultiScreen, NSOpenGLPFASingleRenderer
  208315. attribs[n++] = NSOpenGLPFAColorSize;
  208316. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.redBits,
  208317. pixelFormat.greenBits,
  208318. pixelFormat.blueBits);
  208319. attribs[n++] = NSOpenGLPFAAlphaSize;
  208320. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.alphaBits;
  208321. attribs[n++] = NSOpenGLPFADepthSize;
  208322. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.depthBufferBits;
  208323. attribs[n++] = NSOpenGLPFAStencilSize;
  208324. attribs[n++] = (NSOpenGLPixelFormatAttribute) pixelFormat.stencilBufferBits;
  208325. attribs[n++] = NSOpenGLPFAAccumSize;
  208326. attribs[n++] = (NSOpenGLPixelFormatAttribute) jmax (pixelFormat.accumulationBufferRedBits,
  208327. pixelFormat.accumulationBufferGreenBits,
  208328. pixelFormat.accumulationBufferBlueBits,
  208329. pixelFormat.accumulationBufferAlphaBits);
  208330. // xxx not sure how to do fullSceneAntiAliasingNumSamples..
  208331. attribs[n++] = NSOpenGLPFASampleBuffers;
  208332. attribs[n++] = (NSOpenGLPixelFormatAttribute) 1;
  208333. attribs[n++] = NSOpenGLPFAClosestPolicy;
  208334. attribs[n++] = NSOpenGLPFANoRecovery;
  208335. attribs[n++] = (NSOpenGLPixelFormatAttribute) 0;
  208336. NSOpenGLPixelFormat* format
  208337. = [[NSOpenGLPixelFormat alloc] initWithAttributes: attribs];
  208338. view = [[ThreadSafeNSOpenGLView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  208339. pixelFormat: format];
  208340. renderContext = [[[NSOpenGLContext alloc] initWithFormat: format
  208341. shareContext: sharedContext] autorelease];
  208342. const GLint swapInterval = 1;
  208343. [renderContext setValues: &swapInterval forParameter: NSOpenGLCPSwapInterval];
  208344. [view setOpenGLContext: renderContext];
  208345. [renderContext setView: view];
  208346. [format release];
  208347. viewHolder = new NSViewComponentInternal (view, component);
  208348. }
  208349. ~WindowedGLContext()
  208350. {
  208351. makeInactive();
  208352. [renderContext clearDrawable];
  208353. viewHolder = 0;
  208354. }
  208355. bool makeActive() const throw()
  208356. {
  208357. jassert (renderContext != 0);
  208358. [view makeActive];
  208359. return isActive();
  208360. }
  208361. bool makeInactive() const throw()
  208362. {
  208363. [view makeInactive];
  208364. return true;
  208365. }
  208366. bool isActive() const throw()
  208367. {
  208368. return [NSOpenGLContext currentContext] == renderContext;
  208369. }
  208370. const OpenGLPixelFormat getPixelFormat() const { return pixelFormat; }
  208371. void* getRawContext() const throw() { return renderContext; }
  208372. void updateWindowPosition (int x, int y, int w, int h, int outerWindowHeight)
  208373. {
  208374. }
  208375. void swapBuffers()
  208376. {
  208377. [renderContext flushBuffer];
  208378. }
  208379. bool setSwapInterval (const int numFramesPerSwap)
  208380. {
  208381. [renderContext setValues: (const GLint*) &numFramesPerSwap
  208382. forParameter: NSOpenGLCPSwapInterval];
  208383. return true;
  208384. }
  208385. int getSwapInterval() const
  208386. {
  208387. GLint numFrames = 0;
  208388. [renderContext getValues: &numFrames
  208389. forParameter: NSOpenGLCPSwapInterval];
  208390. return numFrames;
  208391. }
  208392. void repaint()
  208393. {
  208394. // we need to invalidate the juce view that holds this gl view, to make it
  208395. // cause a repaint callback
  208396. NSView* v = (NSView*) viewHolder->view;
  208397. NSRect r = [v frame];
  208398. // bit of a bodge here.. if we only invalidate the area of the gl component,
  208399. // it's completely covered by the NSOpenGLView, so the OS throws away the
  208400. // repaint message, thus never causing our paint() callback, and never repainting
  208401. // the comp. So invalidating just a little bit around the edge helps..
  208402. [[v superview] setNeedsDisplayInRect: NSInsetRect (r, -2.0f, -2.0f)];
  208403. }
  208404. void* getNativeWindowHandle() const { return viewHolder->view; }
  208405. juce_UseDebuggingNewOperator
  208406. NSOpenGLContext* renderContext;
  208407. ThreadSafeNSOpenGLView* view;
  208408. private:
  208409. OpenGLPixelFormat pixelFormat;
  208410. ScopedPointer <NSViewComponentInternal> viewHolder;
  208411. WindowedGLContext (const WindowedGLContext&);
  208412. WindowedGLContext& operator= (const WindowedGLContext&);
  208413. };
  208414. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208415. const OpenGLPixelFormat& pixelFormat,
  208416. const OpenGLContext* const contextToShareWith)
  208417. {
  208418. ScopedPointer <WindowedGLContext> c (new WindowedGLContext (component, pixelFormat,
  208419. contextToShareWith != 0 ? (NSOpenGLContext*) contextToShareWith->getRawContext() : 0));
  208420. return (c->renderContext != 0) ? c.release() : 0;
  208421. }
  208422. void* OpenGLComponent::getNativeWindowHandle() const
  208423. {
  208424. return context != 0 ? ((WindowedGLContext*) context)->getNativeWindowHandle()
  208425. : 0;
  208426. }
  208427. void juce_glViewport (const int w, const int h)
  208428. {
  208429. glViewport (0, 0, w, h);
  208430. }
  208431. void OpenGLPixelFormat::getAvailablePixelFormats (Component* /*component*/,
  208432. OwnedArray <OpenGLPixelFormat>& results)
  208433. {
  208434. /* GLint attribs [64];
  208435. int n = 0;
  208436. attribs[n++] = AGL_RGBA;
  208437. attribs[n++] = AGL_DOUBLEBUFFER;
  208438. attribs[n++] = AGL_ACCELERATED;
  208439. attribs[n++] = AGL_NO_RECOVERY;
  208440. attribs[n++] = AGL_NONE;
  208441. AGLPixelFormat p = aglChoosePixelFormat (0, 0, attribs);
  208442. while (p != 0)
  208443. {
  208444. OpenGLPixelFormat* const pf = new OpenGLPixelFormat();
  208445. pf->redBits = getAGLAttribute (p, AGL_RED_SIZE);
  208446. pf->greenBits = getAGLAttribute (p, AGL_GREEN_SIZE);
  208447. pf->blueBits = getAGLAttribute (p, AGL_BLUE_SIZE);
  208448. pf->alphaBits = getAGLAttribute (p, AGL_ALPHA_SIZE);
  208449. pf->depthBufferBits = getAGLAttribute (p, AGL_DEPTH_SIZE);
  208450. pf->stencilBufferBits = getAGLAttribute (p, AGL_STENCIL_SIZE);
  208451. pf->accumulationBufferRedBits = getAGLAttribute (p, AGL_ACCUM_RED_SIZE);
  208452. pf->accumulationBufferGreenBits = getAGLAttribute (p, AGL_ACCUM_GREEN_SIZE);
  208453. pf->accumulationBufferBlueBits = getAGLAttribute (p, AGL_ACCUM_BLUE_SIZE);
  208454. pf->accumulationBufferAlphaBits = getAGLAttribute (p, AGL_ACCUM_ALPHA_SIZE);
  208455. results.add (pf);
  208456. p = aglNextPixelFormat (p);
  208457. }*/
  208458. //jassertfalse //xxx can't see how you do this in cocoa!
  208459. }
  208460. #else
  208461. OpenGLContext* OpenGLContext::createContextForWindow (Component* const component,
  208462. const OpenGLPixelFormat& pixelFormat,
  208463. const OpenGLContext* const contextToShareWith)
  208464. {
  208465. return 0;
  208466. }
  208467. void juce_glViewport (const int w, const int h)
  208468. {
  208469. //glViewport (0, 0, w, h);
  208470. }
  208471. #endif
  208472. #endif
  208473. /*** End of inlined file: juce_mac_OpenGLComponent.mm ***/
  208474. /*** Start of inlined file: juce_mac_MainMenu.mm ***/
  208475. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208476. // compiled on its own).
  208477. #if JUCE_INCLUDED_FILE
  208478. class JuceMainMenuHandler;
  208479. END_JUCE_NAMESPACE
  208480. using namespace JUCE_NAMESPACE;
  208481. #define JuceMenuCallback MakeObjCClassName(JuceMenuCallback)
  208482. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208483. @interface JuceMenuCallback : NSObject <NSMenuDelegate>
  208484. #else
  208485. @interface JuceMenuCallback : NSObject
  208486. #endif
  208487. {
  208488. JuceMainMenuHandler* owner;
  208489. }
  208490. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_;
  208491. - (void) dealloc;
  208492. - (void) menuItemInvoked: (id) menu;
  208493. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208494. @end
  208495. BEGIN_JUCE_NAMESPACE
  208496. class JuceMainMenuHandler : private MenuBarModelListener,
  208497. private DeletedAtShutdown
  208498. {
  208499. public:
  208500. static JuceMainMenuHandler* instance;
  208501. JuceMainMenuHandler()
  208502. : currentModel (0),
  208503. lastUpdateTime (0)
  208504. {
  208505. callback = [[JuceMenuCallback alloc] initWithOwner: this];
  208506. }
  208507. ~JuceMainMenuHandler()
  208508. {
  208509. setMenu (0);
  208510. jassert (instance == this);
  208511. instance = 0;
  208512. [callback release];
  208513. }
  208514. void setMenu (MenuBarModel* const newMenuBarModel)
  208515. {
  208516. if (currentModel != newMenuBarModel)
  208517. {
  208518. if (currentModel != 0)
  208519. currentModel->removeListener (this);
  208520. currentModel = newMenuBarModel;
  208521. if (currentModel != 0)
  208522. currentModel->addListener (this);
  208523. menuBarItemsChanged (0);
  208524. }
  208525. }
  208526. void addSubMenu (NSMenu* parent, const PopupMenu& child,
  208527. const String& name, const int menuId, const int tag)
  208528. {
  208529. NSMenuItem* item = [parent addItemWithTitle: juceStringToNS (name)
  208530. action: nil
  208531. keyEquivalent: @""];
  208532. [item setTag: tag];
  208533. NSMenu* sub = createMenu (child, name, menuId, tag);
  208534. [parent setSubmenu: sub forItem: item];
  208535. [sub setAutoenablesItems: false];
  208536. [sub release];
  208537. }
  208538. void updateSubMenu (NSMenuItem* parentItem, const PopupMenu& menuToCopy,
  208539. const String& name, const int menuId, const int tag)
  208540. {
  208541. [parentItem setTag: tag];
  208542. NSMenu* menu = [parentItem submenu];
  208543. [menu setTitle: juceStringToNS (name)];
  208544. while ([menu numberOfItems] > 0)
  208545. [menu removeItemAtIndex: 0];
  208546. PopupMenu::MenuItemIterator iter (menuToCopy);
  208547. while (iter.next())
  208548. addMenuItem (iter, menu, menuId, tag);
  208549. [menu setAutoenablesItems: false];
  208550. [menu update];
  208551. }
  208552. void menuBarItemsChanged (MenuBarModel*)
  208553. {
  208554. lastUpdateTime = Time::getMillisecondCounter();
  208555. StringArray menuNames;
  208556. if (currentModel != 0)
  208557. menuNames = currentModel->getMenuBarNames();
  208558. NSMenu* menuBar = [NSApp mainMenu];
  208559. while ([menuBar numberOfItems] > 1 + menuNames.size())
  208560. [menuBar removeItemAtIndex: [menuBar numberOfItems] - 1];
  208561. int menuId = 1;
  208562. for (int i = 0; i < menuNames.size(); ++i)
  208563. {
  208564. const PopupMenu menu (currentModel->getMenuForIndex (i, menuNames [i]));
  208565. if (i >= [menuBar numberOfItems] - 1)
  208566. addSubMenu (menuBar, menu, menuNames[i], menuId, i);
  208567. else
  208568. updateSubMenu ([menuBar itemAtIndex: 1 + i], menu, menuNames[i], menuId, i);
  208569. }
  208570. }
  208571. static void flashMenuBar (NSMenu* menu)
  208572. {
  208573. if ([[menu title] isEqualToString: @"Apple"])
  208574. return;
  208575. [menu retain];
  208576. const unichar f35Key = NSF35FunctionKey;
  208577. NSString* f35String = [NSString stringWithCharacters: &f35Key length: 1];
  208578. NSMenuItem* item = [[NSMenuItem alloc] initWithTitle: @"x"
  208579. action: nil
  208580. keyEquivalent: f35String];
  208581. [item setTarget: nil];
  208582. [menu insertItem: item atIndex: [menu numberOfItems]];
  208583. [item release];
  208584. if ([menu indexOfItem: item] >= 0)
  208585. {
  208586. NSEvent* f35Event = [NSEvent keyEventWithType: NSKeyDown
  208587. location: NSZeroPoint
  208588. modifierFlags: NSCommandKeyMask
  208589. timestamp: 0
  208590. windowNumber: 0
  208591. context: [NSGraphicsContext currentContext]
  208592. characters: f35String
  208593. charactersIgnoringModifiers: f35String
  208594. isARepeat: NO
  208595. keyCode: 0];
  208596. [menu performKeyEquivalent: f35Event];
  208597. [menu removeItem: item]; // (this throws if the item isn't actually in the menu)
  208598. }
  208599. [menu release];
  208600. }
  208601. static NSMenuItem* findMenuItem (NSMenu* const menu, const ApplicationCommandTarget::InvocationInfo& info)
  208602. {
  208603. for (NSInteger i = [menu numberOfItems]; --i >= 0;)
  208604. {
  208605. NSMenuItem* m = [menu itemAtIndex: i];
  208606. if ([m tag] == info.commandID)
  208607. return m;
  208608. if ([m submenu] != 0)
  208609. {
  208610. NSMenuItem* found = findMenuItem ([m submenu], info);
  208611. if (found != 0)
  208612. return found;
  208613. }
  208614. }
  208615. return 0;
  208616. }
  208617. void menuCommandInvoked (MenuBarModel*, const ApplicationCommandTarget::InvocationInfo& info)
  208618. {
  208619. NSMenuItem* item = findMenuItem ([NSApp mainMenu], info);
  208620. if (item != 0)
  208621. flashMenuBar ([item menu]);
  208622. }
  208623. void updateMenus()
  208624. {
  208625. if (Time::getMillisecondCounter() > lastUpdateTime + 500)
  208626. menuBarItemsChanged (0);
  208627. }
  208628. void invoke (const int commandId, ApplicationCommandManager* const commandManager, const int topLevelIndex) const
  208629. {
  208630. if (currentModel != 0)
  208631. {
  208632. if (commandManager != 0)
  208633. {
  208634. ApplicationCommandTarget::InvocationInfo info (commandId);
  208635. info.invocationMethod = ApplicationCommandTarget::InvocationInfo::fromMenu;
  208636. commandManager->invoke (info, true);
  208637. }
  208638. currentModel->menuItemSelected (commandId, topLevelIndex);
  208639. }
  208640. }
  208641. MenuBarModel* currentModel;
  208642. uint32 lastUpdateTime;
  208643. void addMenuItem (PopupMenu::MenuItemIterator& iter, NSMenu* menuToAddTo,
  208644. const int topLevelMenuId, const int topLevelIndex)
  208645. {
  208646. NSString* text = juceStringToNS (iter.itemName.upToFirstOccurrenceOf (T("<end>"), false, true));
  208647. if (text == 0)
  208648. text = @"";
  208649. if (iter.isSeparator)
  208650. {
  208651. [menuToAddTo addItem: [NSMenuItem separatorItem]];
  208652. }
  208653. else if (iter.isSectionHeader)
  208654. {
  208655. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208656. action: nil
  208657. keyEquivalent: @""];
  208658. [item setEnabled: false];
  208659. }
  208660. else if (iter.subMenu != 0)
  208661. {
  208662. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208663. action: nil
  208664. keyEquivalent: @""];
  208665. [item setTag: iter.itemId];
  208666. [item setEnabled: iter.isEnabled];
  208667. NSMenu* sub = createMenu (*iter.subMenu, iter.itemName, topLevelMenuId, topLevelIndex);
  208668. [sub setDelegate: nil];
  208669. [menuToAddTo setSubmenu: sub forItem: item];
  208670. [sub release];
  208671. }
  208672. else
  208673. {
  208674. NSMenuItem* item = [menuToAddTo addItemWithTitle: text
  208675. action: @selector (menuItemInvoked:)
  208676. keyEquivalent: @""];
  208677. [item setTag: iter.itemId];
  208678. [item setEnabled: iter.isEnabled];
  208679. [item setState: iter.isTicked ? NSOnState : NSOffState];
  208680. [item setTarget: (id) callback];
  208681. NSMutableArray* info = [NSMutableArray arrayWithObject: [NSNumber numberWithUnsignedLongLong: (pointer_sized_int) (void*) iter.commandManager]];
  208682. [info addObject: [NSNumber numberWithInt: topLevelIndex]];
  208683. [item setRepresentedObject: info];
  208684. if (iter.commandManager != 0)
  208685. {
  208686. const Array <KeyPress> keyPresses (iter.commandManager->getKeyMappings()
  208687. ->getKeyPressesAssignedToCommand (iter.itemId));
  208688. if (keyPresses.size() > 0)
  208689. {
  208690. const KeyPress& kp = keyPresses.getReference(0);
  208691. juce_wchar key = kp.getTextCharacter();
  208692. if (kp.getKeyCode() == KeyPress::backspaceKey)
  208693. key = NSBackspaceCharacter;
  208694. else if (kp.getKeyCode() == KeyPress::deleteKey)
  208695. key = NSDeleteCharacter;
  208696. else if (key == 0)
  208697. key = (juce_wchar) kp.getKeyCode();
  208698. unsigned int mods = 0;
  208699. if (kp.getModifiers().isShiftDown())
  208700. mods |= NSShiftKeyMask;
  208701. if (kp.getModifiers().isCtrlDown())
  208702. mods |= NSControlKeyMask;
  208703. if (kp.getModifiers().isAltDown())
  208704. mods |= NSAlternateKeyMask;
  208705. if (kp.getModifiers().isCommandDown())
  208706. mods |= NSCommandKeyMask;
  208707. [item setKeyEquivalent: juceStringToNS (String::charToString (key))];
  208708. [item setKeyEquivalentModifierMask: mods];
  208709. }
  208710. }
  208711. }
  208712. }
  208713. JuceMenuCallback* callback;
  208714. private:
  208715. NSMenu* createMenu (const PopupMenu menu,
  208716. const String& menuName,
  208717. const int topLevelMenuId,
  208718. const int topLevelIndex)
  208719. {
  208720. NSMenu* m = [[NSMenu alloc] initWithTitle: juceStringToNS (menuName)];
  208721. [m setAutoenablesItems: false];
  208722. [m setDelegate: callback];
  208723. PopupMenu::MenuItemIterator iter (menu);
  208724. while (iter.next())
  208725. addMenuItem (iter, m, topLevelMenuId, topLevelIndex);
  208726. [m update];
  208727. return m;
  208728. }
  208729. };
  208730. JuceMainMenuHandler* JuceMainMenuHandler::instance = 0;
  208731. END_JUCE_NAMESPACE
  208732. @implementation JuceMenuCallback
  208733. - (JuceMenuCallback*) initWithOwner: (JuceMainMenuHandler*) owner_
  208734. {
  208735. [super init];
  208736. owner = owner_;
  208737. return self;
  208738. }
  208739. - (void) dealloc
  208740. {
  208741. [super dealloc];
  208742. }
  208743. - (void) menuItemInvoked: (id) menu
  208744. {
  208745. NSMenuItem* item = (NSMenuItem*) menu;
  208746. if ([[item representedObject] isKindOfClass: [NSArray class]])
  208747. {
  208748. // 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
  208749. // our own components, which may have wanted to intercept it. So, rather than dispatching directly, we'll feed it back
  208750. // into the focused component and let it trigger the menu item indirectly.
  208751. NSEvent* e = [NSApp currentEvent];
  208752. if ([e type] == NSKeyDown || [e type] == NSKeyUp)
  208753. {
  208754. if (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->isValidComponent())
  208755. {
  208756. JUCE_NAMESPACE::NSViewComponentPeer* peer = dynamic_cast <JUCE_NAMESPACE::NSViewComponentPeer*> (JUCE_NAMESPACE::Component::getCurrentlyFocusedComponent()->getPeer());
  208757. if (peer != 0)
  208758. {
  208759. if ([e type] == NSKeyDown)
  208760. peer->redirectKeyDown (e);
  208761. else
  208762. peer->redirectKeyUp (e);
  208763. return;
  208764. }
  208765. }
  208766. }
  208767. NSArray* info = (NSArray*) [item representedObject];
  208768. owner->invoke ((int) [item tag],
  208769. (ApplicationCommandManager*) (pointer_sized_int)
  208770. [((NSNumber*) [info objectAtIndex: 0]) unsignedLongLongValue],
  208771. (int) [((NSNumber*) [info objectAtIndex: 1]) intValue]);
  208772. }
  208773. }
  208774. - (void) menuNeedsUpdate: (NSMenu*) menu;
  208775. {
  208776. if (JuceMainMenuHandler::instance != 0)
  208777. JuceMainMenuHandler::instance->updateMenus();
  208778. }
  208779. @end
  208780. BEGIN_JUCE_NAMESPACE
  208781. static NSMenu* createStandardAppMenu (NSMenu* menu, const String& appName,
  208782. const PopupMenu* extraItems)
  208783. {
  208784. if (extraItems != 0 && JuceMainMenuHandler::instance != 0 && extraItems->getNumItems() > 0)
  208785. {
  208786. PopupMenu::MenuItemIterator iter (*extraItems);
  208787. while (iter.next())
  208788. JuceMainMenuHandler::instance->addMenuItem (iter, menu, 0, -1);
  208789. [menu addItem: [NSMenuItem separatorItem]];
  208790. }
  208791. NSMenuItem* item;
  208792. // Services...
  208793. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Services", nil)
  208794. action: nil keyEquivalent: @""];
  208795. [menu addItem: item];
  208796. [item release];
  208797. NSMenu* servicesMenu = [[NSMenu alloc] initWithTitle: @"Services"];
  208798. [menu setSubmenu: servicesMenu forItem: item];
  208799. [NSApp setServicesMenu: servicesMenu];
  208800. [servicesMenu release];
  208801. [menu addItem: [NSMenuItem separatorItem]];
  208802. // Hide + Show stuff...
  208803. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Hide " + appName)
  208804. action: @selector (hide:) keyEquivalent: @"h"];
  208805. [item setTarget: NSApp];
  208806. [menu addItem: item];
  208807. [item release];
  208808. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Hide Others", nil)
  208809. action: @selector (hideOtherApplications:) keyEquivalent: @"h"];
  208810. [item setKeyEquivalentModifierMask: NSCommandKeyMask | NSAlternateKeyMask];
  208811. [item setTarget: NSApp];
  208812. [menu addItem: item];
  208813. [item release];
  208814. item = [[NSMenuItem alloc] initWithTitle: NSLocalizedString (@"Show All", nil)
  208815. action: @selector (unhideAllApplications:) keyEquivalent: @""];
  208816. [item setTarget: NSApp];
  208817. [menu addItem: item];
  208818. [item release];
  208819. [menu addItem: [NSMenuItem separatorItem]];
  208820. // Quit item....
  208821. item = [[NSMenuItem alloc] initWithTitle: juceStringToNS ("Quit " + appName)
  208822. action: @selector (terminate:) keyEquivalent: @"q"];
  208823. [item setTarget: NSApp];
  208824. [menu addItem: item];
  208825. [item release];
  208826. return menu;
  208827. }
  208828. // Since our app has no NIB, this initialises a standard app menu...
  208829. static void rebuildMainMenu (const PopupMenu* extraItems)
  208830. {
  208831. // this can't be used in a plugin!
  208832. jassert (JUCEApplication::getInstance() != 0);
  208833. if (JUCEApplication::getInstance() != 0)
  208834. {
  208835. const ScopedAutoReleasePool pool;
  208836. NSMenu* mainMenu = [[NSMenu alloc] initWithTitle: @"MainMenu"];
  208837. NSMenuItem* item = [mainMenu addItemWithTitle: @"Apple" action: nil keyEquivalent: @""];
  208838. NSMenu* appMenu = [[NSMenu alloc] initWithTitle: @"Apple"];
  208839. [NSApp performSelector: @selector (setAppleMenu:) withObject: appMenu];
  208840. [mainMenu setSubmenu: appMenu forItem: item];
  208841. [NSApp setMainMenu: mainMenu];
  208842. createStandardAppMenu (appMenu, JUCEApplication::getInstance()->getApplicationName(), extraItems);
  208843. [appMenu release];
  208844. [mainMenu release];
  208845. }
  208846. }
  208847. void MenuBarModel::setMacMainMenu (MenuBarModel* newMenuBarModel,
  208848. const PopupMenu* extraAppleMenuItems)
  208849. {
  208850. if (getMacMainMenu() != newMenuBarModel)
  208851. {
  208852. const ScopedAutoReleasePool pool;
  208853. if (newMenuBarModel == 0)
  208854. {
  208855. delete JuceMainMenuHandler::instance;
  208856. jassert (JuceMainMenuHandler::instance == 0); // should be zeroed in the destructor
  208857. jassert (extraAppleMenuItems == 0); // you can't specify some extra items without also supplying a model
  208858. extraAppleMenuItems = 0;
  208859. }
  208860. else
  208861. {
  208862. if (JuceMainMenuHandler::instance == 0)
  208863. JuceMainMenuHandler::instance = new JuceMainMenuHandler();
  208864. JuceMainMenuHandler::instance->setMenu (newMenuBarModel);
  208865. }
  208866. }
  208867. rebuildMainMenu (extraAppleMenuItems);
  208868. if (newMenuBarModel != 0)
  208869. newMenuBarModel->menuItemsChanged();
  208870. }
  208871. MenuBarModel* MenuBarModel::getMacMainMenu()
  208872. {
  208873. return JuceMainMenuHandler::instance != 0
  208874. ? JuceMainMenuHandler::instance->currentModel : 0;
  208875. }
  208876. void initialiseMainMenu()
  208877. {
  208878. if (JUCEApplication::getInstance() != 0) // only needed in an app
  208879. rebuildMainMenu (0);
  208880. }
  208881. #endif
  208882. /*** End of inlined file: juce_mac_MainMenu.mm ***/
  208883. /*** Start of inlined file: juce_mac_FileChooser.mm ***/
  208884. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  208885. // compiled on its own).
  208886. #if JUCE_INCLUDED_FILE
  208887. #if JUCE_MAC
  208888. END_JUCE_NAMESPACE
  208889. using namespace JUCE_NAMESPACE;
  208890. #define JuceFileChooserDelegate MakeObjCClassName(JuceFileChooserDelegate)
  208891. #if defined (MAC_OS_X_VERSION_10_6) && MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6
  208892. @interface JuceFileChooserDelegate : NSObject <NSOpenSavePanelDelegate>
  208893. #else
  208894. @interface JuceFileChooserDelegate : NSObject
  208895. #endif
  208896. {
  208897. StringArray* filters;
  208898. }
  208899. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_;
  208900. - (void) dealloc;
  208901. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename;
  208902. @end
  208903. @implementation JuceFileChooserDelegate
  208904. - (JuceFileChooserDelegate*) initWithFilters: (StringArray*) filters_
  208905. {
  208906. [super init];
  208907. filters = filters_;
  208908. return self;
  208909. }
  208910. - (void) dealloc
  208911. {
  208912. delete filters;
  208913. [super dealloc];
  208914. }
  208915. - (BOOL) panel: (id) sender shouldShowFilename: (NSString*) filename
  208916. {
  208917. const File f (nsStringToJuce (filename));
  208918. for (int i = filters->size(); --i >= 0;)
  208919. if (f.getFileName().matchesWildcard ((*filters)[i], true))
  208920. return true;
  208921. return f.isDirectory();
  208922. }
  208923. @end
  208924. BEGIN_JUCE_NAMESPACE
  208925. void FileChooser::showPlatformDialog (Array<File>& results,
  208926. const String& title,
  208927. const File& currentFileOrDirectory,
  208928. const String& filter,
  208929. bool selectsDirectory,
  208930. bool selectsFiles,
  208931. bool isSaveDialogue,
  208932. bool warnAboutOverwritingExistingFiles,
  208933. bool selectMultipleFiles,
  208934. FilePreviewComponent* extraInfoComponent)
  208935. {
  208936. const ScopedAutoReleasePool pool;
  208937. StringArray* filters = new StringArray();
  208938. filters->addTokens (filter.replaceCharacters (T(",:"), T(";;")), T(";"), 0);
  208939. filters->trim();
  208940. filters->removeEmptyStrings();
  208941. JuceFileChooserDelegate* delegate = [[JuceFileChooserDelegate alloc] initWithFilters: filters];
  208942. [delegate autorelease];
  208943. NSSavePanel* panel = isSaveDialogue ? [NSSavePanel savePanel]
  208944. : [NSOpenPanel openPanel];
  208945. [panel setTitle: juceStringToNS (title)];
  208946. if (! isSaveDialogue)
  208947. {
  208948. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208949. [openPanel setCanChooseDirectories: selectsDirectory];
  208950. [openPanel setCanChooseFiles: selectsFiles];
  208951. [openPanel setAllowsMultipleSelection: selectMultipleFiles];
  208952. }
  208953. [panel setDelegate: delegate];
  208954. if (isSaveDialogue || selectsDirectory)
  208955. [panel setCanCreateDirectories: YES];
  208956. String directory, filename;
  208957. if (currentFileOrDirectory.isDirectory())
  208958. {
  208959. directory = currentFileOrDirectory.getFullPathName();
  208960. }
  208961. else
  208962. {
  208963. directory = currentFileOrDirectory.getParentDirectory().getFullPathName();
  208964. filename = currentFileOrDirectory.getFileName();
  208965. }
  208966. if ([panel runModalForDirectory: juceStringToNS (directory)
  208967. file: juceStringToNS (filename)]
  208968. == NSOKButton)
  208969. {
  208970. if (isSaveDialogue)
  208971. {
  208972. results.add (File (nsStringToJuce ([panel filename])));
  208973. }
  208974. else
  208975. {
  208976. NSOpenPanel* openPanel = (NSOpenPanel*) panel;
  208977. NSArray* urls = [openPanel filenames];
  208978. for (unsigned int i = 0; i < [urls count]; ++i)
  208979. {
  208980. NSString* f = [urls objectAtIndex: i];
  208981. results.add (File (nsStringToJuce (f)));
  208982. }
  208983. }
  208984. }
  208985. [panel setDelegate: nil];
  208986. }
  208987. #else
  208988. void FileChooser::showPlatformDialog (Array<File>& results,
  208989. const String& title,
  208990. const File& currentFileOrDirectory,
  208991. const String& filter,
  208992. bool selectsDirectory,
  208993. bool selectsFiles,
  208994. bool isSaveDialogue,
  208995. bool warnAboutOverwritingExistingFiles,
  208996. bool selectMultipleFiles,
  208997. FilePreviewComponent* extraInfoComponent)
  208998. {
  208999. const ScopedAutoReleasePool pool;
  209000. jassertfalse //xxx to do
  209001. }
  209002. #endif
  209003. #endif
  209004. /*** End of inlined file: juce_mac_FileChooser.mm ***/
  209005. /*** Start of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209006. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209007. // compiled on its own).
  209008. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME
  209009. #define theMovie ((QTMovie*) movie)
  209010. QuickTimeMovieComponent::QuickTimeMovieComponent()
  209011. : movie (0)
  209012. {
  209013. setOpaque (true);
  209014. setVisible (true);
  209015. QTMovieView* view = [[QTMovieView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)];
  209016. setView (view);
  209017. }
  209018. QuickTimeMovieComponent::~QuickTimeMovieComponent()
  209019. {
  209020. closeMovie();
  209021. setView (0);
  209022. }
  209023. bool QuickTimeMovieComponent::isQuickTimeAvailable() throw()
  209024. {
  209025. return true;
  209026. }
  209027. static QTMovie* openMovieFromStream (InputStream* movieStream, File& movieFile)
  209028. {
  209029. // unfortunately, QTMovie objects can only be created on the main thread..
  209030. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209031. QTMovie* movie = 0;
  209032. FileInputStream* const fin = dynamic_cast <FileInputStream*> (movieStream);
  209033. if (fin != 0)
  209034. {
  209035. movieFile = fin->getFile();
  209036. movie = [QTMovie movieWithFile: juceStringToNS (movieFile.getFullPathName())
  209037. error: nil];
  209038. }
  209039. else
  209040. {
  209041. MemoryBlock temp;
  209042. movieStream->readIntoMemoryBlock (temp);
  209043. const char* const suffixesToTry[] = { ".mov", ".mp3", ".avi", ".m4a" };
  209044. for (int i = 0; i < numElementsInArray (suffixesToTry); ++i)
  209045. {
  209046. movie = [QTMovie movieWithDataReference: [QTDataReference dataReferenceWithReferenceToData: [NSData dataWithBytes: temp.getData()
  209047. length: temp.getSize()]
  209048. name: [NSString stringWithUTF8String: suffixesToTry[i]]
  209049. MIMEType: @""]
  209050. error: nil];
  209051. if (movie != 0)
  209052. break;
  209053. }
  209054. }
  209055. return movie;
  209056. }
  209057. bool QuickTimeMovieComponent::loadMovie (const File& movieFile_,
  209058. const bool isControllerVisible_)
  209059. {
  209060. return loadMovie ((InputStream*) movieFile_.createInputStream(), isControllerVisible_);
  209061. }
  209062. bool QuickTimeMovieComponent::loadMovie (InputStream* movieStream,
  209063. const bool controllerVisible_)
  209064. {
  209065. closeMovie();
  209066. if (getPeer() == 0)
  209067. {
  209068. // To open a movie, this component must be visible inside a functioning window, so that
  209069. // the QT control can be assigned to the window.
  209070. jassertfalse
  209071. return false;
  209072. }
  209073. movie = openMovieFromStream (movieStream, movieFile);
  209074. [theMovie retain];
  209075. QTMovieView* view = (QTMovieView*) getView();
  209076. [view setMovie: theMovie];
  209077. [view setControllerVisible: controllerVisible_];
  209078. setLooping (looping);
  209079. return movie != nil;
  209080. }
  209081. bool QuickTimeMovieComponent::loadMovie (const URL& movieURL,
  209082. const bool isControllerVisible_)
  209083. {
  209084. // unfortunately, QTMovie objects can only be created on the main thread..
  209085. jassert (MessageManager::getInstance()->isThisTheMessageThread());
  209086. closeMovie();
  209087. if (getPeer() == 0)
  209088. {
  209089. // To open a movie, this component must be visible inside a functioning window, so that
  209090. // the QT control can be assigned to the window.
  209091. jassertfalse
  209092. return false;
  209093. }
  209094. NSURL* url = [NSURL URLWithString: juceStringToNS (movieURL.toString (true))];
  209095. NSError* err;
  209096. if ([QTMovie canInitWithURL: url])
  209097. movie = [QTMovie movieWithURL: url error: &err];
  209098. [theMovie retain];
  209099. QTMovieView* view = (QTMovieView*) getView();
  209100. [view setMovie: theMovie];
  209101. [view setControllerVisible: controllerVisible];
  209102. setLooping (looping);
  209103. return movie != nil;
  209104. }
  209105. void QuickTimeMovieComponent::closeMovie()
  209106. {
  209107. stop();
  209108. QTMovieView* view = (QTMovieView*) getView();
  209109. [view setMovie: nil];
  209110. [theMovie release];
  209111. movie = 0;
  209112. movieFile = File::nonexistent;
  209113. }
  209114. bool QuickTimeMovieComponent::isMovieOpen() const
  209115. {
  209116. return movie != nil;
  209117. }
  209118. const File QuickTimeMovieComponent::getCurrentMovieFile() const
  209119. {
  209120. return movieFile;
  209121. }
  209122. void QuickTimeMovieComponent::play()
  209123. {
  209124. [theMovie play];
  209125. }
  209126. void QuickTimeMovieComponent::stop()
  209127. {
  209128. [theMovie stop];
  209129. }
  209130. bool QuickTimeMovieComponent::isPlaying() const
  209131. {
  209132. return movie != 0 && [theMovie rate] != 0;
  209133. }
  209134. void QuickTimeMovieComponent::setPosition (const double seconds)
  209135. {
  209136. if (movie != 0)
  209137. {
  209138. QTTime t;
  209139. t.timeValue = (uint64) (100000.0 * seconds);
  209140. t.timeScale = 100000;
  209141. t.flags = 0;
  209142. [theMovie setCurrentTime: t];
  209143. }
  209144. }
  209145. double QuickTimeMovieComponent::getPosition() const
  209146. {
  209147. if (movie == 0)
  209148. return 0.0;
  209149. QTTime t = [theMovie currentTime];
  209150. return t.timeValue / (double) t.timeScale;
  209151. }
  209152. void QuickTimeMovieComponent::setSpeed (const float newSpeed)
  209153. {
  209154. [theMovie setRate: newSpeed];
  209155. }
  209156. double QuickTimeMovieComponent::getMovieDuration() const
  209157. {
  209158. if (movie == 0)
  209159. return 0.0;
  209160. QTTime t = [theMovie duration];
  209161. return t.timeValue / (double) t.timeScale;
  209162. }
  209163. void QuickTimeMovieComponent::setLooping (const bool shouldLoop)
  209164. {
  209165. looping = shouldLoop;
  209166. [theMovie setAttribute: [NSNumber numberWithBool: shouldLoop]
  209167. forKey: QTMovieLoopsAttribute];
  209168. }
  209169. bool QuickTimeMovieComponent::isLooping() const
  209170. {
  209171. return looping;
  209172. }
  209173. void QuickTimeMovieComponent::setMovieVolume (const float newVolume)
  209174. {
  209175. [theMovie setVolume: newVolume];
  209176. }
  209177. float QuickTimeMovieComponent::getMovieVolume() const
  209178. {
  209179. return movie != 0 ? [theMovie volume] : 0.0f;
  209180. }
  209181. void QuickTimeMovieComponent::getMovieNormalSize (int& width, int& height) const
  209182. {
  209183. width = 0;
  209184. height = 0;
  209185. if (movie != 0)
  209186. {
  209187. NSSize s = [[theMovie attributeForKey: QTMovieNaturalSizeAttribute] sizeValue];
  209188. width = (int) s.width;
  209189. height = (int) s.height;
  209190. }
  209191. }
  209192. void QuickTimeMovieComponent::paint (Graphics& g)
  209193. {
  209194. if (movie == 0)
  209195. g.fillAll (Colours::black);
  209196. }
  209197. bool QuickTimeMovieComponent::isControllerVisible() const
  209198. {
  209199. return controllerVisible;
  209200. }
  209201. void QuickTimeMovieComponent::goToStart()
  209202. {
  209203. setPosition (0.0);
  209204. }
  209205. void QuickTimeMovieComponent::setBoundsWithCorrectAspectRatio (const Rectangle<int>& spaceToFitWithin,
  209206. const RectanglePlacement& placement)
  209207. {
  209208. int normalWidth, normalHeight;
  209209. getMovieNormalSize (normalWidth, normalHeight);
  209210. if (normalWidth > 0 && normalHeight > 0 && ! spaceToFitWithin.isEmpty())
  209211. {
  209212. double x = 0.0, y = 0.0, w = normalWidth, h = normalHeight;
  209213. placement.applyTo (x, y, w, h,
  209214. spaceToFitWithin.getX(), spaceToFitWithin.getY(),
  209215. spaceToFitWithin.getWidth(), spaceToFitWithin.getHeight());
  209216. if (w > 0 && h > 0)
  209217. {
  209218. setBounds (roundToInt (x), roundToInt (y),
  209219. roundToInt (w), roundToInt (h));
  209220. }
  209221. }
  209222. else
  209223. {
  209224. setBounds (spaceToFitWithin);
  209225. }
  209226. }
  209227. #if ! (JUCE_MAC && JUCE_64BIT)
  209228. bool juce_OpenQuickTimeMovieFromStream (InputStream* movieStream, Movie& result, Handle& dataHandle)
  209229. {
  209230. if (movieStream == 0)
  209231. return false;
  209232. File file;
  209233. QTMovie* movie = openMovieFromStream (movieStream, file);
  209234. if (movie != nil)
  209235. result = [movie quickTimeMovie];
  209236. return movie != nil;
  209237. }
  209238. #endif
  209239. #endif
  209240. /*** End of inlined file: juce_mac_QuickTimeMovieComponent.mm ***/
  209241. /*** Start of inlined file: juce_mac_AudioCDBurner.mm ***/
  209242. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209243. // compiled on its own).
  209244. #if JUCE_INCLUDED_FILE && JUCE_USE_CDBURNER
  209245. const int kilobytesPerSecond1x = 176;
  209246. END_JUCE_NAMESPACE
  209247. #define OpenDiskDevice MakeObjCClassName(OpenDiskDevice)
  209248. @interface OpenDiskDevice : NSObject
  209249. {
  209250. @public
  209251. DRDevice* device;
  209252. NSMutableArray* tracks;
  209253. bool underrunProtection;
  209254. }
  209255. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device;
  209256. - (void) dealloc;
  209257. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) numSamples_;
  209258. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209259. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed;
  209260. @end
  209261. #define AudioTrackProducer MakeObjCClassName(AudioTrackProducer)
  209262. @interface AudioTrackProducer : NSObject
  209263. {
  209264. JUCE_NAMESPACE::AudioSource* source;
  209265. int readPosition, lengthInFrames;
  209266. }
  209267. - (AudioTrackProducer*) init: (int) lengthInFrames;
  209268. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source numSamples: (int) lengthInSamples;
  209269. - (void) dealloc;
  209270. - (void) setupTrackProperties: (DRTrack*) track;
  209271. - (void) cleanupTrackAfterBurn: (DRTrack*) track;
  209272. - (BOOL) cleanupTrackAfterVerification:(DRTrack*)track;
  209273. - (uint64_t) estimateLengthOfTrack:(DRTrack*)track;
  209274. - (BOOL) prepareTrack:(DRTrack*)track forBurn:(DRBurn*)burn
  209275. toMedia:(NSDictionary*)mediaInfo;
  209276. - (BOOL) prepareTrackForVerification:(DRTrack*)track;
  209277. - (uint32_t) produceDataForTrack:(DRTrack*)track intoBuffer:(char*)buffer
  209278. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209279. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209280. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209281. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209282. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209283. ioFlags:(uint32_t*)flags;
  209284. - (BOOL) verifyDataForTrack:(DRTrack*)track inBuffer:(const char*)buffer
  209285. length:(uint32_t)bufferLength atAddress:(uint64_t)address
  209286. blockSize:(uint32_t)blockSize ioFlags:(uint32_t*)flags;
  209287. - (uint32_t) producePreGapForTrack:(DRTrack*)track
  209288. intoBuffer:(char*)buffer length:(uint32_t)bufferLength
  209289. atAddress:(uint64_t)address blockSize:(uint32_t)blockSize
  209290. ioFlags:(uint32_t*)flags;
  209291. @end
  209292. @implementation OpenDiskDevice
  209293. - (OpenDiskDevice*) initWithDRDevice: (DRDevice*) device_
  209294. {
  209295. [super init];
  209296. device = device_;
  209297. tracks = [[NSMutableArray alloc] init];
  209298. underrunProtection = true;
  209299. return self;
  209300. }
  209301. - (void) dealloc
  209302. {
  209303. [tracks release];
  209304. [super dealloc];
  209305. }
  209306. - (void) addSourceTrack: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) numSamples_
  209307. {
  209308. AudioTrackProducer* p = [[AudioTrackProducer alloc] initWithAudioSource: source_ numSamples: numSamples_];
  209309. DRTrack* t = [[DRTrack alloc] initWithProducer: p];
  209310. [p setupTrackProperties: t];
  209311. [tracks addObject: t];
  209312. [t release];
  209313. [p release];
  209314. }
  209315. - (void) burn: (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener*) listener errorString: (JUCE_NAMESPACE::String*) error
  209316. ejectAfterwards: (bool) shouldEject isFake: (bool) peformFakeBurnForTesting speed: (int) burnSpeed
  209317. {
  209318. DRBurn* burn = [DRBurn burnForDevice: device];
  209319. if (! [device acquireExclusiveAccess])
  209320. {
  209321. *error = "Couldn't open or write to the CD device";
  209322. return;
  209323. }
  209324. [device acquireMediaReservation];
  209325. NSMutableDictionary* d = [[burn properties] mutableCopy];
  209326. [d autorelease];
  209327. [d setObject: [NSNumber numberWithBool: peformFakeBurnForTesting] forKey: DRBurnTestingKey];
  209328. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnVerifyDiscKey];
  209329. [d setObject: (shouldEject ? DRBurnCompletionActionEject : DRBurnCompletionActionMount) forKey: DRBurnCompletionActionKey];
  209330. if (burnSpeed > 0)
  209331. [d setObject: [NSNumber numberWithFloat: burnSpeed * JUCE_NAMESPACE::kilobytesPerSecond1x] forKey: DRBurnRequestedSpeedKey];
  209332. if (! underrunProtection)
  209333. [d setObject: [NSNumber numberWithBool: false] forKey: DRBurnUnderrunProtectionKey];
  209334. [burn setProperties: d];
  209335. [burn writeLayout: tracks];
  209336. for (;;)
  209337. {
  209338. JUCE_NAMESPACE::Thread::sleep (300);
  209339. float progress = [[[burn status] objectForKey: DRStatusPercentCompleteKey] floatValue];
  209340. if (listener != 0 && listener->audioCDBurnProgress (progress))
  209341. {
  209342. [burn abort];
  209343. *error = "User cancelled the write operation";
  209344. break;
  209345. }
  209346. if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateFailed])
  209347. {
  209348. *error = "Write operation failed";
  209349. break;
  209350. }
  209351. else if ([[[burn status] objectForKey: DRStatusStateKey] isEqualTo: DRStatusStateDone])
  209352. {
  209353. break;
  209354. }
  209355. NSString* err = (NSString*) [[[burn status] objectForKey: DRErrorStatusKey]
  209356. objectForKey: DRErrorStatusErrorStringKey];
  209357. if ([err length] > 0)
  209358. {
  209359. *error = JUCE_NAMESPACE::String::fromUTF8 ([err UTF8String]);
  209360. break;
  209361. }
  209362. }
  209363. [device releaseMediaReservation];
  209364. [device releaseExclusiveAccess];
  209365. }
  209366. @end
  209367. @implementation AudioTrackProducer
  209368. - (AudioTrackProducer*) init: (int) lengthInFrames_
  209369. {
  209370. lengthInFrames = lengthInFrames_;
  209371. readPosition = 0;
  209372. return self;
  209373. }
  209374. - (void) setupTrackProperties: (DRTrack*) track
  209375. {
  209376. NSMutableDictionary* p = [[track properties] mutableCopy];
  209377. [p setObject:[DRMSF msfWithFrames: lengthInFrames] forKey: DRTrackLengthKey];
  209378. [p setObject:[NSNumber numberWithUnsignedShort:2352] forKey: DRBlockSizeKey];
  209379. [p setObject:[NSNumber numberWithInt:0] forKey: DRDataFormKey];
  209380. [p setObject:[NSNumber numberWithInt:0] forKey: DRBlockTypeKey];
  209381. [p setObject:[NSNumber numberWithInt:0] forKey: DRTrackModeKey];
  209382. [p setObject:[NSNumber numberWithInt:0] forKey: DRSessionFormatKey];
  209383. [track setProperties: p];
  209384. [p release];
  209385. }
  209386. - (AudioTrackProducer*) initWithAudioSource: (JUCE_NAMESPACE::AudioSource*) source_ numSamples: (int) lengthInSamples
  209387. {
  209388. AudioTrackProducer* s = [self init: (lengthInSamples + 587) / 588];
  209389. if (s != nil)
  209390. s->source = source_;
  209391. return s;
  209392. }
  209393. - (void) dealloc
  209394. {
  209395. if (source != 0)
  209396. {
  209397. source->releaseResources();
  209398. delete source;
  209399. }
  209400. [super dealloc];
  209401. }
  209402. - (void) cleanupTrackAfterBurn: (DRTrack*) track
  209403. {
  209404. }
  209405. - (BOOL) cleanupTrackAfterVerification: (DRTrack*) track
  209406. {
  209407. return true;
  209408. }
  209409. - (uint64_t) estimateLengthOfTrack: (DRTrack*) track
  209410. {
  209411. return lengthInFrames;
  209412. }
  209413. - (BOOL) prepareTrack: (DRTrack*) track forBurn: (DRBurn*) burn
  209414. toMedia: (NSDictionary*) mediaInfo
  209415. {
  209416. if (source != 0)
  209417. source->prepareToPlay (44100 / 75, 44100);
  209418. readPosition = 0;
  209419. return true;
  209420. }
  209421. - (BOOL) prepareTrackForVerification: (DRTrack*) track
  209422. {
  209423. if (source != 0)
  209424. source->prepareToPlay (44100 / 75, 44100);
  209425. return true;
  209426. }
  209427. - (uint32_t) produceDataForTrack: (DRTrack*) track intoBuffer: (char*) buffer
  209428. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209429. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209430. {
  209431. if (source != 0)
  209432. {
  209433. const int numSamples = JUCE_NAMESPACE::jmin ((int) bufferLength / 4, (lengthInFrames * (44100 / 75)) - readPosition);
  209434. if (numSamples > 0)
  209435. {
  209436. JUCE_NAMESPACE::AudioSampleBuffer tempBuffer (2, numSamples);
  209437. JUCE_NAMESPACE::AudioSourceChannelInfo info;
  209438. info.buffer = &tempBuffer;
  209439. info.startSample = 0;
  209440. info.numSamples = numSamples;
  209441. source->getNextAudioBlock (info);
  209442. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (0),
  209443. buffer, numSamples, 4);
  209444. JUCE_NAMESPACE::AudioDataConverters::convertFloatToInt16LE (tempBuffer.getSampleData (1),
  209445. buffer + 2, numSamples, 4);
  209446. readPosition += numSamples;
  209447. }
  209448. return numSamples * 4;
  209449. }
  209450. return 0;
  209451. }
  209452. - (uint32_t) producePreGapForTrack: (DRTrack*) track
  209453. intoBuffer: (char*) buffer length: (uint32_t) bufferLength
  209454. atAddress: (uint64_t) address blockSize: (uint32_t) blockSize
  209455. ioFlags: (uint32_t*) flags
  209456. {
  209457. zeromem (buffer, bufferLength);
  209458. return bufferLength;
  209459. }
  209460. - (BOOL) verifyDataForTrack: (DRTrack*) track inBuffer: (const char*) buffer
  209461. length: (uint32_t) bufferLength atAddress: (uint64_t) address
  209462. blockSize: (uint32_t) blockSize ioFlags: (uint32_t*) flags
  209463. {
  209464. return true;
  209465. }
  209466. @end
  209467. BEGIN_JUCE_NAMESPACE
  209468. class AudioCDBurner::Pimpl : public Timer
  209469. {
  209470. public:
  209471. Pimpl (AudioCDBurner& owner_, const int deviceIndex)
  209472. : device (0), owner (owner_)
  209473. {
  209474. DRDevice* dev = [[DRDevice devices] objectAtIndex: deviceIndex];
  209475. if (dev != 0)
  209476. {
  209477. device = [[OpenDiskDevice alloc] initWithDRDevice: dev];
  209478. lastState = getDiskState();
  209479. startTimer (1000);
  209480. }
  209481. }
  209482. ~Pimpl()
  209483. {
  209484. stopTimer();
  209485. [device release];
  209486. }
  209487. void timerCallback()
  209488. {
  209489. const DiskState state = getDiskState();
  209490. if (state != lastState)
  209491. {
  209492. lastState = state;
  209493. owner.sendChangeMessage (&owner);
  209494. }
  209495. }
  209496. DiskState getDiskState() const
  209497. {
  209498. if ([device->device isValid])
  209499. {
  209500. NSDictionary* status = [device->device status];
  209501. NSString* state = [status objectForKey: DRDeviceMediaStateKey];
  209502. if ([state isEqualTo: DRDeviceMediaStateNone])
  209503. {
  209504. if ([[status objectForKey: DRDeviceIsTrayOpenKey] boolValue])
  209505. return trayOpen;
  209506. return noDisc;
  209507. }
  209508. if ([state isEqualTo: DRDeviceMediaStateMediaPresent])
  209509. {
  209510. if ([[[status objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceMediaBlocksFreeKey] intValue] > 0)
  209511. return writableDiskPresent;
  209512. else
  209513. return readOnlyDiskPresent;
  209514. }
  209515. }
  209516. return unknown;
  209517. }
  209518. bool openTray() { return [device->device isValid] && [device->device ejectMedia]; }
  209519. const Array<int> getAvailableWriteSpeeds() const
  209520. {
  209521. Array<int> results;
  209522. if ([device->device isValid])
  209523. {
  209524. NSArray* speeds = [[[device->device status] objectForKey: DRDeviceMediaInfoKey] objectForKey: DRDeviceBurnSpeedsKey];
  209525. for (unsigned int i = 0; i < [speeds count]; ++i)
  209526. {
  209527. const int kbPerSec = [[speeds objectAtIndex: i] intValue];
  209528. results.add (kbPerSec / kilobytesPerSecond1x);
  209529. }
  209530. }
  209531. return results;
  209532. }
  209533. bool setBufferUnderrunProtection (const bool shouldBeEnabled)
  209534. {
  209535. if ([device->device isValid])
  209536. {
  209537. device->underrunProtection = shouldBeEnabled;
  209538. return shouldBeEnabled && [[[device->device status] objectForKey: DRDeviceCanUnderrunProtectCDKey] boolValue];
  209539. }
  209540. return false;
  209541. }
  209542. int getNumAvailableAudioBlocks() const
  209543. {
  209544. return [[[[device->device status] objectForKey: DRDeviceMediaInfoKey]
  209545. objectForKey: DRDeviceMediaBlocksFreeKey] intValue];
  209546. }
  209547. OpenDiskDevice* device;
  209548. private:
  209549. DiskState lastState;
  209550. AudioCDBurner& owner;
  209551. };
  209552. AudioCDBurner::AudioCDBurner (const int deviceIndex)
  209553. {
  209554. pimpl = new Pimpl (*this, deviceIndex);
  209555. }
  209556. AudioCDBurner::~AudioCDBurner()
  209557. {
  209558. }
  209559. AudioCDBurner* AudioCDBurner::openDevice (const int deviceIndex)
  209560. {
  209561. ScopedPointer <AudioCDBurner> b (new AudioCDBurner (deviceIndex));
  209562. if (b->pimpl->device == 0)
  209563. b = 0;
  209564. return b.release();
  209565. }
  209566. static NSArray* findDiskBurnerDevices()
  209567. {
  209568. NSMutableArray* results = [NSMutableArray array];
  209569. NSArray* devs = [DRDevice devices];
  209570. if (devs != 0)
  209571. {
  209572. int num = [devs count];
  209573. int i;
  209574. for (i = 0; i < num; ++i)
  209575. {
  209576. NSDictionary* dic = [[devs objectAtIndex: i] info];
  209577. NSString* name = [dic valueForKey: DRDeviceProductNameKey];
  209578. if (name != nil)
  209579. [results addObject: name];
  209580. }
  209581. }
  209582. return results;
  209583. }
  209584. const StringArray AudioCDBurner::findAvailableDevices()
  209585. {
  209586. NSArray* names = findDiskBurnerDevices();
  209587. StringArray s;
  209588. for (unsigned int i = 0; i < [names count]; ++i)
  209589. s.add (String::fromUTF8 ([[names objectAtIndex: i] UTF8String]));
  209590. return s;
  209591. }
  209592. AudioCDBurner::DiskState AudioCDBurner::getDiskState() const
  209593. {
  209594. return pimpl->getDiskState();
  209595. }
  209596. bool AudioCDBurner::isDiskPresent() const
  209597. {
  209598. return getDiskState() == writableDiskPresent;
  209599. }
  209600. bool AudioCDBurner::openTray()
  209601. {
  209602. return pimpl->openTray();
  209603. }
  209604. AudioCDBurner::DiskState AudioCDBurner::waitUntilStateChange (int timeOutMilliseconds)
  209605. {
  209606. const int64 timeout = Time::currentTimeMillis() + timeOutMilliseconds;
  209607. DiskState oldState = getDiskState();
  209608. DiskState newState = oldState;
  209609. while (newState == oldState && Time::currentTimeMillis() < timeout)
  209610. {
  209611. newState = getDiskState();
  209612. Thread::sleep (100);
  209613. }
  209614. return newState;
  209615. }
  209616. const Array<int> AudioCDBurner::getAvailableWriteSpeeds() const
  209617. {
  209618. return pimpl->getAvailableWriteSpeeds();
  209619. }
  209620. bool AudioCDBurner::setBufferUnderrunProtection (const bool shouldBeEnabled)
  209621. {
  209622. return pimpl->setBufferUnderrunProtection (shouldBeEnabled);
  209623. }
  209624. int AudioCDBurner::getNumAvailableAudioBlocks() const
  209625. {
  209626. return pimpl->getNumAvailableAudioBlocks();
  209627. }
  209628. bool AudioCDBurner::addAudioTrack (AudioSource* source, int numSamps)
  209629. {
  209630. if ([pimpl->device->device isValid])
  209631. {
  209632. [pimpl->device addSourceTrack: source numSamples: numSamps];
  209633. return true;
  209634. }
  209635. return false;
  209636. }
  209637. const String AudioCDBurner::burn (JUCE_NAMESPACE::AudioCDBurner::BurnProgressListener* listener,
  209638. bool ejectDiscAfterwards,
  209639. bool performFakeBurnForTesting,
  209640. int writeSpeed)
  209641. {
  209642. String error ("Couldn't open or write to the CD device");
  209643. if ([pimpl->device->device isValid])
  209644. {
  209645. error = String::empty;
  209646. [pimpl->device burn: listener
  209647. errorString: &error
  209648. ejectAfterwards: ejectDiscAfterwards
  209649. isFake: performFakeBurnForTesting
  209650. speed: writeSpeed];
  209651. }
  209652. return error;
  209653. }
  209654. #endif
  209655. #if JUCE_INCLUDED_FILE && JUCE_USE_CDREADER
  209656. void AudioCDReader::ejectDisk()
  209657. {
  209658. const ScopedAutoReleasePool p;
  209659. [[NSWorkspace sharedWorkspace] unmountAndEjectDeviceAtPath: juceStringToNS (volumeDir.getFullPathName())];
  209660. }
  209661. #endif
  209662. /*** End of inlined file: juce_mac_AudioCDBurner.mm ***/
  209663. /*** Start of inlined file: juce_mac_MessageManager.mm ***/
  209664. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  209665. // compiled on its own).
  209666. #if JUCE_INCLUDED_FILE
  209667. struct CallbackMessagePayload
  209668. {
  209669. MessageCallbackFunction* function;
  209670. void* parameter;
  209671. void* volatile result;
  209672. bool volatile hasBeenExecuted;
  209673. };
  209674. class AppDelegateRedirector
  209675. {
  209676. public:
  209677. AppDelegateRedirector()
  209678. {
  209679. #if MAC_OS_X_VERSION_MIN_REQUIRED > MAC_OS_X_VERSION_10_4
  209680. runLoop = CFRunLoopGetMain();
  209681. #else
  209682. runLoop = CFRunLoopGetCurrent();
  209683. #endif
  209684. CFRunLoopSourceContext sourceContext;
  209685. zerostruct (sourceContext);
  209686. sourceContext.info = this;
  209687. sourceContext.perform = runLoopSourceCallback;
  209688. runLoopSource = CFRunLoopSourceCreate (kCFAllocatorDefault, 1, &sourceContext);
  209689. CFRunLoopAddSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209690. }
  209691. virtual ~AppDelegateRedirector()
  209692. {
  209693. CFRunLoopRemoveSource (runLoop, runLoopSource, kCFRunLoopCommonModes);
  209694. CFRunLoopSourceInvalidate (runLoopSource);
  209695. CFRelease (runLoopSource);
  209696. while (messages.size() > 0)
  209697. delete ((Message*) messages.remove(0));
  209698. }
  209699. virtual NSApplicationTerminateReply shouldTerminate()
  209700. {
  209701. if (JUCEApplication::getInstance() != 0)
  209702. {
  209703. JUCEApplication::getInstance()->systemRequestedQuit();
  209704. return NSTerminateCancel;
  209705. }
  209706. return NSTerminateNow;
  209707. }
  209708. virtual BOOL openFile (const NSString* filename)
  209709. {
  209710. if (JUCEApplication::getInstance() != 0)
  209711. {
  209712. JUCEApplication::getInstance()->anotherInstanceStarted (nsStringToJuce (filename));
  209713. return YES;
  209714. }
  209715. return NO;
  209716. }
  209717. virtual void openFiles (NSArray* filenames)
  209718. {
  209719. StringArray files;
  209720. for (unsigned int i = 0; i < [filenames count]; ++i)
  209721. {
  209722. String filename (nsStringToJuce ((NSString*) [filenames objectAtIndex: i]));
  209723. if (filename.containsChar (T(' ')))
  209724. filename = filename.quoted('"');
  209725. files.add (filename);
  209726. }
  209727. if (files.size() > 0 && JUCEApplication::getInstance() != 0)
  209728. {
  209729. JUCEApplication::getInstance()->anotherInstanceStarted (files.joinIntoString (T(" ")));
  209730. }
  209731. }
  209732. virtual void focusChanged()
  209733. {
  209734. juce_HandleProcessFocusChange();
  209735. }
  209736. virtual void performCallback (CallbackMessagePayload* pl)
  209737. {
  209738. pl->result = (*pl->function) (pl->parameter);
  209739. pl->hasBeenExecuted = true;
  209740. }
  209741. virtual void deleteSelf()
  209742. {
  209743. delete this;
  209744. }
  209745. void postMessage (void* m)
  209746. {
  209747. messages.add (m);
  209748. CFRunLoopSourceSignal (runLoopSource);
  209749. CFRunLoopWakeUp (runLoop);
  209750. }
  209751. private:
  209752. CFRunLoopRef runLoop;
  209753. CFRunLoopSourceRef runLoopSource;
  209754. Array <void*, CriticalSection> messages;
  209755. void runLoopCallback()
  209756. {
  209757. int numDispatched = 0;
  209758. do
  209759. {
  209760. void* const nextMessage = messages.remove (0);
  209761. if (nextMessage == 0)
  209762. return;
  209763. const ScopedAutoReleasePool pool;
  209764. MessageManager::getInstance()->deliverMessage (nextMessage);
  209765. } while (++numDispatched <= 4);
  209766. CFRunLoopSourceSignal (runLoopSource);
  209767. CFRunLoopWakeUp (runLoop);
  209768. }
  209769. static void runLoopSourceCallback (void* info)
  209770. {
  209771. ((AppDelegateRedirector*) info)->runLoopCallback();
  209772. }
  209773. };
  209774. END_JUCE_NAMESPACE
  209775. using namespace JUCE_NAMESPACE;
  209776. #define JuceAppDelegate MakeObjCClassName(JuceAppDelegate)
  209777. @interface JuceAppDelegate : NSObject
  209778. {
  209779. @private
  209780. id oldDelegate;
  209781. @public
  209782. AppDelegateRedirector* redirector;
  209783. }
  209784. - (JuceAppDelegate*) init;
  209785. - (void) dealloc;
  209786. - (BOOL) application: (NSApplication*) theApplication openFile: (NSString*) filename;
  209787. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames;
  209788. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app;
  209789. - (void) applicationDidBecomeActive: (NSNotification*) aNotification;
  209790. - (void) applicationDidResignActive: (NSNotification*) aNotification;
  209791. - (void) applicationWillUnhide: (NSNotification*) aNotification;
  209792. - (void) performCallback: (id) info;
  209793. - (void) dummyMethod;
  209794. @end
  209795. @implementation JuceAppDelegate
  209796. - (JuceAppDelegate*) init
  209797. {
  209798. [super init];
  209799. redirector = new AppDelegateRedirector();
  209800. NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
  209801. if (JUCEApplication::getInstance() != 0)
  209802. {
  209803. oldDelegate = [NSApp delegate];
  209804. [NSApp setDelegate: self];
  209805. }
  209806. else
  209807. {
  209808. oldDelegate = 0;
  209809. [center addObserver: self selector: @selector (applicationDidResignActive:)
  209810. name: NSApplicationDidResignActiveNotification object: NSApp];
  209811. [center addObserver: self selector: @selector (applicationDidBecomeActive:)
  209812. name: NSApplicationDidBecomeActiveNotification object: NSApp];
  209813. [center addObserver: self selector: @selector (applicationWillUnhide:)
  209814. name: NSApplicationWillUnhideNotification object: NSApp];
  209815. }
  209816. return self;
  209817. }
  209818. - (void) dealloc
  209819. {
  209820. if (oldDelegate != 0)
  209821. [NSApp setDelegate: oldDelegate];
  209822. redirector->deleteSelf();
  209823. [super dealloc];
  209824. }
  209825. - (NSApplicationTerminateReply) applicationShouldTerminate: (NSApplication*) app
  209826. {
  209827. return redirector->shouldTerminate();
  209828. }
  209829. - (BOOL) application: (NSApplication*) app openFile: (NSString*) filename
  209830. {
  209831. return redirector->openFile (filename);
  209832. }
  209833. - (void) application: (NSApplication*) sender openFiles: (NSArray*) filenames
  209834. {
  209835. return redirector->openFiles (filenames);
  209836. }
  209837. - (void) applicationDidBecomeActive: (NSNotification*) aNotification
  209838. {
  209839. redirector->focusChanged();
  209840. }
  209841. - (void) applicationDidResignActive: (NSNotification*) aNotification
  209842. {
  209843. redirector->focusChanged();
  209844. }
  209845. - (void) applicationWillUnhide: (NSNotification*) aNotification
  209846. {
  209847. redirector->focusChanged();
  209848. }
  209849. - (void) performCallback: (id) info
  209850. {
  209851. if ([info isKindOfClass: [NSData class]])
  209852. {
  209853. CallbackMessagePayload* pl = (CallbackMessagePayload*) [((NSData*) info) bytes];
  209854. if (pl != 0)
  209855. redirector->performCallback (pl);
  209856. }
  209857. else
  209858. {
  209859. jassertfalse // should never get here!
  209860. }
  209861. }
  209862. - (void) dummyMethod {} // (used as a way of running a dummy thread)
  209863. @end
  209864. BEGIN_JUCE_NAMESPACE
  209865. static JuceAppDelegate* juceAppDelegate = 0;
  209866. void MessageManager::runDispatchLoop()
  209867. {
  209868. if (! quitMessagePosted) // check that the quit message wasn't already posted..
  209869. {
  209870. const ScopedAutoReleasePool pool;
  209871. // must only be called by the message thread!
  209872. jassert (isThisTheMessageThread());
  209873. #if JUCE_CATCH_UNHANDLED_EXCEPTIONS
  209874. @try
  209875. {
  209876. [NSApp run];
  209877. }
  209878. @catch (NSException* e)
  209879. {
  209880. // An AppKit exception will kill the app, but at least this provides a chance to log it.,
  209881. std::runtime_error ex (std::string ("NSException: ") + [[e name] UTF8String] + ", Reason:" + [[e reason] UTF8String]);
  209882. JUCEApplication::sendUnhandledException (&ex, __FILE__, __LINE__);
  209883. }
  209884. @finally
  209885. {
  209886. }
  209887. #else
  209888. [NSApp run];
  209889. #endif
  209890. }
  209891. }
  209892. void MessageManager::stopDispatchLoop()
  209893. {
  209894. quitMessagePosted = true;
  209895. [NSApp stop: nil];
  209896. [NSApp activateIgnoringOtherApps: YES]; // (if the app is inactive, it sits there and ignores the quit request until the next time it gets activated)
  209897. [NSEvent startPeriodicEventsAfterDelay: 0 withPeriod: 0.1];
  209898. }
  209899. static bool isEventBlockedByModalComps (NSEvent* e)
  209900. {
  209901. if (Component::getNumCurrentlyModalComponents() == 0)
  209902. return false;
  209903. NSWindow* const w = [e window];
  209904. if (w == 0 || [w worksWhenModal])
  209905. return false;
  209906. bool isKey = false, isInputAttempt = false;
  209907. switch ([e type])
  209908. {
  209909. case NSKeyDown:
  209910. case NSKeyUp:
  209911. isKey = isInputAttempt = true;
  209912. break;
  209913. case NSLeftMouseDown:
  209914. case NSRightMouseDown:
  209915. case NSOtherMouseDown:
  209916. isInputAttempt = true;
  209917. break;
  209918. case NSLeftMouseDragged:
  209919. case NSRightMouseDragged:
  209920. case NSLeftMouseUp:
  209921. case NSRightMouseUp:
  209922. case NSOtherMouseUp:
  209923. case NSOtherMouseDragged:
  209924. if (Component::getComponentUnderMouse() != 0)
  209925. return false;
  209926. break;
  209927. case NSMouseMoved:
  209928. case NSMouseEntered:
  209929. case NSMouseExited:
  209930. case NSCursorUpdate:
  209931. case NSScrollWheel:
  209932. case NSTabletPoint:
  209933. case NSTabletProximity:
  209934. break;
  209935. default:
  209936. return false;
  209937. }
  209938. for (int i = ComponentPeer::getNumPeers(); --i >= 0;)
  209939. {
  209940. ComponentPeer* const peer = ComponentPeer::getPeer (i);
  209941. NSView* const compView = (NSView*) peer->getNativeHandle();
  209942. if ([compView window] == w)
  209943. {
  209944. if (isKey)
  209945. {
  209946. if (compView == [w firstResponder])
  209947. return false;
  209948. }
  209949. else
  209950. {
  209951. if (NSPointInRect ([compView convertPoint: [e locationInWindow] fromView: nil],
  209952. [compView bounds]))
  209953. return false;
  209954. }
  209955. }
  209956. }
  209957. if (isInputAttempt)
  209958. {
  209959. if (! [NSApp isActive])
  209960. [NSApp activateIgnoringOtherApps: YES];
  209961. Component* const modal = Component::getCurrentlyModalComponent (0);
  209962. if (modal != 0)
  209963. modal->inputAttemptWhenModal();
  209964. }
  209965. return true;
  209966. }
  209967. bool MessageManager::runDispatchLoopUntil (int millisecondsToRunFor)
  209968. {
  209969. const ScopedAutoReleasePool pool;
  209970. jassert (isThisTheMessageThread()); // must only be called by the message thread
  209971. uint32 endTime = Time::getMillisecondCounter() + millisecondsToRunFor;
  209972. while (! quitMessagePosted)
  209973. {
  209974. const ScopedAutoReleasePool pool2;
  209975. CFRunLoopRunInMode (kCFRunLoopDefaultMode, 0.001, true);
  209976. NSEvent* e = [NSApp nextEventMatchingMask: NSAnyEventMask
  209977. untilDate: [NSDate dateWithTimeIntervalSinceNow: 0.001]
  209978. inMode: NSDefaultRunLoopMode
  209979. dequeue: YES];
  209980. if (e != 0 && ! isEventBlockedByModalComps (e))
  209981. [NSApp sendEvent: e];
  209982. if (Time::getMillisecondCounter() >= endTime)
  209983. break;
  209984. }
  209985. return ! quitMessagePosted;
  209986. }
  209987. void MessageManager::doPlatformSpecificInitialisation()
  209988. {
  209989. if (juceAppDelegate == 0)
  209990. juceAppDelegate = [[JuceAppDelegate alloc] init];
  209991. // This launches a dummy thread, which forces Cocoa to initialise NSThreads
  209992. // correctly (needed prior to 10.5)
  209993. if (! [NSThread isMultiThreaded])
  209994. [NSThread detachNewThreadSelector: @selector (dummyMethod)
  209995. toTarget: juceAppDelegate
  209996. withObject: nil];
  209997. initialiseMainMenu();
  209998. }
  209999. void MessageManager::doPlatformSpecificShutdown()
  210000. {
  210001. if (juceAppDelegate != 0)
  210002. {
  210003. [[NSRunLoop currentRunLoop] cancelPerformSelectorsWithTarget: juceAppDelegate];
  210004. [[NSNotificationCenter defaultCenter] removeObserver: juceAppDelegate];
  210005. [juceAppDelegate release];
  210006. juceAppDelegate = 0;
  210007. }
  210008. }
  210009. bool juce_postMessageToSystemQueue (void* message)
  210010. {
  210011. juceAppDelegate->redirector->postMessage (message);
  210012. return true;
  210013. }
  210014. void MessageManager::broadcastMessage (const String& value) throw()
  210015. {
  210016. }
  210017. void* MessageManager::callFunctionOnMessageThread (MessageCallbackFunction* callback,
  210018. void* data)
  210019. {
  210020. if (isThisTheMessageThread())
  210021. {
  210022. return (*callback) (data);
  210023. }
  210024. else
  210025. {
  210026. // If a thread has a MessageManagerLock and then tries to call this method, it'll
  210027. // deadlock because the message manager is blocked from running, so can never
  210028. // call your function..
  210029. jassert (! MessageManager::getInstance()->currentThreadHasLockedMessageManager());
  210030. const ScopedAutoReleasePool pool;
  210031. CallbackMessagePayload cmp;
  210032. cmp.function = callback;
  210033. cmp.parameter = data;
  210034. cmp.result = 0;
  210035. cmp.hasBeenExecuted = false;
  210036. [juceAppDelegate performSelectorOnMainThread: @selector (performCallback:)
  210037. withObject: [NSData dataWithBytesNoCopy: &cmp
  210038. length: sizeof (cmp)
  210039. freeWhenDone: NO]
  210040. waitUntilDone: YES];
  210041. return cmp.result;
  210042. }
  210043. }
  210044. #endif
  210045. /*** End of inlined file: juce_mac_MessageManager.mm ***/
  210046. /*** Start of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210047. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210048. // compiled on its own).
  210049. #if JUCE_INCLUDED_FILE && JUCE_WEB_BROWSER
  210050. #if JUCE_MAC
  210051. END_JUCE_NAMESPACE
  210052. #define DownloadClickDetector MakeObjCClassName(DownloadClickDetector)
  210053. @interface DownloadClickDetector : NSObject
  210054. {
  210055. JUCE_NAMESPACE::WebBrowserComponent* ownerComponent;
  210056. }
  210057. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent;
  210058. - (void) webView: (WebView*) webView decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210059. request: (NSURLRequest*) request
  210060. frame: (WebFrame*) frame
  210061. decisionListener: (id<WebPolicyDecisionListener>) listener;
  210062. @end
  210063. @implementation DownloadClickDetector
  210064. - (DownloadClickDetector*) initWithWebBrowserOwner: (JUCE_NAMESPACE::WebBrowserComponent*) ownerComponent_
  210065. {
  210066. [super init];
  210067. ownerComponent = ownerComponent_;
  210068. return self;
  210069. }
  210070. - (void) webView: (WebView*) sender decidePolicyForNavigationAction: (NSDictionary*) actionInformation
  210071. request: (NSURLRequest*) request
  210072. frame: (WebFrame*) frame
  210073. decisionListener: (id <WebPolicyDecisionListener>) listener
  210074. {
  210075. NSURL* url = [actionInformation valueForKey: @"WebActionOriginalURLKey"];
  210076. if (ownerComponent->pageAboutToLoad (nsStringToJuce ([url absoluteString])))
  210077. [listener use];
  210078. else
  210079. [listener ignore];
  210080. }
  210081. @end
  210082. BEGIN_JUCE_NAMESPACE
  210083. class WebBrowserComponentInternal : public NSViewComponent
  210084. {
  210085. public:
  210086. WebBrowserComponentInternal (WebBrowserComponent* owner)
  210087. {
  210088. webView = [[WebView alloc] initWithFrame: NSMakeRect (0, 0, 100.0f, 100.0f)
  210089. frameName: @""
  210090. groupName: @""];
  210091. setView (webView);
  210092. clickListener = [[DownloadClickDetector alloc] initWithWebBrowserOwner: owner];
  210093. [webView setPolicyDelegate: clickListener];
  210094. }
  210095. ~WebBrowserComponentInternal()
  210096. {
  210097. [webView setPolicyDelegate: nil];
  210098. [clickListener release];
  210099. setView (0);
  210100. }
  210101. void goToURL (const String& url,
  210102. const StringArray* headers,
  210103. const MemoryBlock* postData)
  210104. {
  210105. NSMutableURLRequest* r
  210106. = [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
  210107. cachePolicy: NSURLRequestUseProtocolCachePolicy
  210108. timeoutInterval: 30.0];
  210109. if (postData != 0 && postData->getSize() > 0)
  210110. {
  210111. [r setHTTPMethod: @"POST"];
  210112. [r setHTTPBody: [NSData dataWithBytes: postData->getData()
  210113. length: postData->getSize()]];
  210114. }
  210115. if (headers != 0)
  210116. {
  210117. for (int i = 0; i < headers->size(); ++i)
  210118. {
  210119. const String headerName ((*headers)[i].upToFirstOccurrenceOf (T(":"), false, false).trim());
  210120. const String headerValue ((*headers)[i].fromFirstOccurrenceOf (T(":"), false, false).trim());
  210121. [r setValue: juceStringToNS (headerValue)
  210122. forHTTPHeaderField: juceStringToNS (headerName)];
  210123. }
  210124. }
  210125. stop();
  210126. [[webView mainFrame] loadRequest: r];
  210127. }
  210128. void goBack()
  210129. {
  210130. [webView goBack];
  210131. }
  210132. void goForward()
  210133. {
  210134. [webView goForward];
  210135. }
  210136. void stop()
  210137. {
  210138. [webView stopLoading: nil];
  210139. }
  210140. void refresh()
  210141. {
  210142. [webView reload: nil];
  210143. }
  210144. private:
  210145. WebView* webView;
  210146. DownloadClickDetector* clickListener;
  210147. };
  210148. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210149. : browser (0),
  210150. blankPageShown (false),
  210151. unloadPageWhenBrowserIsHidden (unloadPageWhenBrowserIsHidden_)
  210152. {
  210153. setOpaque (true);
  210154. addAndMakeVisible (browser = new WebBrowserComponentInternal (this));
  210155. }
  210156. WebBrowserComponent::~WebBrowserComponent()
  210157. {
  210158. deleteAndZero (browser);
  210159. }
  210160. void WebBrowserComponent::goToURL (const String& url,
  210161. const StringArray* headers,
  210162. const MemoryBlock* postData)
  210163. {
  210164. lastURL = url;
  210165. lastHeaders.clear();
  210166. if (headers != 0)
  210167. lastHeaders = *headers;
  210168. lastPostData.setSize (0);
  210169. if (postData != 0)
  210170. lastPostData = *postData;
  210171. blankPageShown = false;
  210172. browser->goToURL (url, headers, postData);
  210173. }
  210174. void WebBrowserComponent::stop()
  210175. {
  210176. browser->stop();
  210177. }
  210178. void WebBrowserComponent::goBack()
  210179. {
  210180. lastURL = String::empty;
  210181. blankPageShown = false;
  210182. browser->goBack();
  210183. }
  210184. void WebBrowserComponent::goForward()
  210185. {
  210186. lastURL = String::empty;
  210187. browser->goForward();
  210188. }
  210189. void WebBrowserComponent::refresh()
  210190. {
  210191. browser->refresh();
  210192. }
  210193. void WebBrowserComponent::paint (Graphics& g)
  210194. {
  210195. }
  210196. void WebBrowserComponent::checkWindowAssociation()
  210197. {
  210198. if (isShowing())
  210199. {
  210200. if (blankPageShown)
  210201. goBack();
  210202. }
  210203. else
  210204. {
  210205. if (unloadPageWhenBrowserIsHidden && ! blankPageShown)
  210206. {
  210207. // when the component becomes invisible, some stuff like flash
  210208. // carries on playing audio, so we need to force it onto a blank
  210209. // page to avoid this, (and send it back when it's made visible again).
  210210. blankPageShown = true;
  210211. browser->goToURL ("about:blank", 0, 0);
  210212. }
  210213. }
  210214. }
  210215. void WebBrowserComponent::reloadLastURL()
  210216. {
  210217. if (lastURL.isNotEmpty())
  210218. {
  210219. goToURL (lastURL, &lastHeaders, &lastPostData);
  210220. lastURL = String::empty;
  210221. }
  210222. }
  210223. void WebBrowserComponent::parentHierarchyChanged()
  210224. {
  210225. checkWindowAssociation();
  210226. }
  210227. void WebBrowserComponent::resized()
  210228. {
  210229. browser->setSize (getWidth(), getHeight());
  210230. }
  210231. void WebBrowserComponent::visibilityChanged()
  210232. {
  210233. checkWindowAssociation();
  210234. }
  210235. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210236. {
  210237. return true;
  210238. }
  210239. #else
  210240. WebBrowserComponent::WebBrowserComponent (const bool unloadPageWhenBrowserIsHidden_)
  210241. {
  210242. }
  210243. WebBrowserComponent::~WebBrowserComponent()
  210244. {
  210245. }
  210246. void WebBrowserComponent::goToURL (const String& url,
  210247. const StringArray* headers,
  210248. const MemoryBlock* postData)
  210249. {
  210250. }
  210251. void WebBrowserComponent::stop()
  210252. {
  210253. }
  210254. void WebBrowserComponent::goBack()
  210255. {
  210256. }
  210257. void WebBrowserComponent::goForward()
  210258. {
  210259. }
  210260. void WebBrowserComponent::refresh()
  210261. {
  210262. }
  210263. void WebBrowserComponent::paint (Graphics& g)
  210264. {
  210265. }
  210266. void WebBrowserComponent::checkWindowAssociation()
  210267. {
  210268. }
  210269. void WebBrowserComponent::reloadLastURL()
  210270. {
  210271. }
  210272. void WebBrowserComponent::parentHierarchyChanged()
  210273. {
  210274. }
  210275. void WebBrowserComponent::resized()
  210276. {
  210277. }
  210278. void WebBrowserComponent::visibilityChanged()
  210279. {
  210280. }
  210281. bool WebBrowserComponent::pageAboutToLoad (const String& url)
  210282. {
  210283. return true;
  210284. }
  210285. #endif
  210286. #endif
  210287. /*** End of inlined file: juce_mac_WebBrowserComponent.mm ***/
  210288. /*** Start of inlined file: juce_mac_CoreAudio.cpp ***/
  210289. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  210290. // compiled on its own).
  210291. #if JUCE_INCLUDED_FILE
  210292. #ifndef JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210293. #define JUCE_COREAUDIO_ERROR_LOGGING_ENABLED 1
  210294. #endif
  210295. #undef log
  210296. #if JUCE_COREAUDIO_LOGGING_ENABLED
  210297. #define log(a) Logger::writeToLog (a)
  210298. #else
  210299. #define log(a)
  210300. #endif
  210301. #undef OK
  210302. #if JUCE_COREAUDIO_ERROR_LOGGING_ENABLED
  210303. static bool logAnyErrors_CoreAudio (const OSStatus err, const int lineNum)
  210304. {
  210305. if (err == noErr)
  210306. return true;
  210307. Logger::writeToLog (T("CoreAudio error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  210308. jassertfalse
  210309. return false;
  210310. }
  210311. #define OK(a) logAnyErrors_CoreAudio (a, __LINE__)
  210312. #else
  210313. #define OK(a) (a == noErr)
  210314. #endif
  210315. class CoreAudioInternal : public Timer
  210316. {
  210317. public:
  210318. CoreAudioInternal (AudioDeviceID id)
  210319. : inputLatency (0),
  210320. outputLatency (0),
  210321. callback (0),
  210322. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210323. audioProcID (0),
  210324. #endif
  210325. inputDevice (0),
  210326. isSlaveDevice (false),
  210327. deviceID (id),
  210328. started (false),
  210329. sampleRate (0),
  210330. bufferSize (512),
  210331. numInputChans (0),
  210332. numOutputChans (0),
  210333. callbacksAllowed (true),
  210334. numInputChannelInfos (0),
  210335. numOutputChannelInfos (0)
  210336. {
  210337. jassert (deviceID != 0);
  210338. updateDetailsFromDevice();
  210339. AudioObjectPropertyAddress pa;
  210340. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210341. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210342. pa.mElement = kAudioObjectPropertyElementWildcard;
  210343. AudioObjectAddPropertyListener (deviceID, &pa, deviceListenerProc, this);
  210344. }
  210345. ~CoreAudioInternal()
  210346. {
  210347. AudioObjectPropertyAddress pa;
  210348. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  210349. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210350. pa.mElement = kAudioObjectPropertyElementWildcard;
  210351. AudioObjectRemovePropertyListener (deviceID, &pa, deviceListenerProc, this);
  210352. stop (false);
  210353. delete inputDevice;
  210354. }
  210355. void allocateTempBuffers()
  210356. {
  210357. const int tempBufSize = bufferSize + 4;
  210358. audioBuffer.calloc ((numInputChans + numOutputChans) * tempBufSize);
  210359. tempInputBuffers.calloc (numInputChans + 2);
  210360. tempOutputBuffers.calloc (numOutputChans + 2);
  210361. int i, count = 0;
  210362. for (i = 0; i < numInputChans; ++i)
  210363. tempInputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210364. for (i = 0; i < numOutputChans; ++i)
  210365. tempOutputBuffers[i] = audioBuffer + count++ * tempBufSize;
  210366. }
  210367. // returns the number of actual available channels
  210368. void fillInChannelInfo (const bool input)
  210369. {
  210370. int chanNum = 0;
  210371. UInt32 size;
  210372. AudioObjectPropertyAddress pa;
  210373. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  210374. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210375. pa.mElement = kAudioObjectPropertyElementMaster;
  210376. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210377. {
  210378. HeapBlock <AudioBufferList> bufList;
  210379. bufList.calloc (size, 1);
  210380. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  210381. {
  210382. const int numStreams = bufList->mNumberBuffers;
  210383. for (int i = 0; i < numStreams; ++i)
  210384. {
  210385. const AudioBuffer& b = bufList->mBuffers[i];
  210386. for (unsigned int j = 0; j < b.mNumberChannels; ++j)
  210387. {
  210388. String name;
  210389. {
  210390. char channelName [256];
  210391. zerostruct (channelName);
  210392. UInt32 nameSize = sizeof (channelName);
  210393. UInt32 channelNum = chanNum + 1;
  210394. pa.mSelector = kAudioDevicePropertyChannelName;
  210395. if (AudioObjectGetPropertyData (deviceID, &pa, sizeof (channelNum), &channelNum, &nameSize, channelName) == noErr)
  210396. name = String::fromUTF8 (channelName, nameSize);
  210397. }
  210398. if (input)
  210399. {
  210400. if (activeInputChans[chanNum])
  210401. {
  210402. inputChannelInfo [numInputChannelInfos].streamNum = i;
  210403. inputChannelInfo [numInputChannelInfos].dataOffsetSamples = j;
  210404. inputChannelInfo [numInputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210405. ++numInputChannelInfos;
  210406. }
  210407. if (name.isEmpty())
  210408. name << "Input " << (chanNum + 1);
  210409. inChanNames.add (name);
  210410. }
  210411. else
  210412. {
  210413. if (activeOutputChans[chanNum])
  210414. {
  210415. outputChannelInfo [numOutputChannelInfos].streamNum = i;
  210416. outputChannelInfo [numOutputChannelInfos].dataOffsetSamples = j;
  210417. outputChannelInfo [numOutputChannelInfos].dataStrideSamples = b.mNumberChannels;
  210418. ++numOutputChannelInfos;
  210419. }
  210420. if (name.isEmpty())
  210421. name << "Output " << (chanNum + 1);
  210422. outChanNames.add (name);
  210423. }
  210424. ++chanNum;
  210425. }
  210426. }
  210427. }
  210428. }
  210429. }
  210430. void updateDetailsFromDevice()
  210431. {
  210432. stopTimer();
  210433. if (deviceID == 0)
  210434. return;
  210435. const ScopedLock sl (callbackLock);
  210436. Float64 sr;
  210437. UInt32 size = sizeof (Float64);
  210438. AudioObjectPropertyAddress pa;
  210439. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210440. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210441. pa.mElement = kAudioObjectPropertyElementMaster;
  210442. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &sr)))
  210443. sampleRate = sr;
  210444. UInt32 framesPerBuf;
  210445. size = sizeof (framesPerBuf);
  210446. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210447. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &framesPerBuf)))
  210448. {
  210449. bufferSize = framesPerBuf;
  210450. allocateTempBuffers();
  210451. }
  210452. bufferSizes.clear();
  210453. pa.mSelector = kAudioDevicePropertyBufferFrameSizeRange;
  210454. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210455. {
  210456. HeapBlock <AudioValueRange> ranges;
  210457. ranges.calloc (size, 1);
  210458. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210459. {
  210460. bufferSizes.add ((int) ranges[0].mMinimum);
  210461. for (int i = 32; i < 8192; i += 32)
  210462. {
  210463. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210464. {
  210465. if (i >= ranges[j].mMinimum && i <= ranges[j].mMaximum)
  210466. {
  210467. bufferSizes.addIfNotAlreadyThere (i);
  210468. break;
  210469. }
  210470. }
  210471. }
  210472. if (bufferSize > 0)
  210473. bufferSizes.addIfNotAlreadyThere (bufferSize);
  210474. }
  210475. }
  210476. if (bufferSizes.size() == 0 && bufferSize > 0)
  210477. bufferSizes.add (bufferSize);
  210478. sampleRates.clear();
  210479. const double possibleRates[] = { 44100.0, 48000.0, 88200.0, 96000.0, 176400.0, 192000.0 };
  210480. String rates;
  210481. pa.mSelector = kAudioDevicePropertyAvailableNominalSampleRates;
  210482. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210483. {
  210484. HeapBlock <AudioValueRange> ranges;
  210485. ranges.calloc (size, 1);
  210486. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, ranges)))
  210487. {
  210488. for (int i = 0; i < numElementsInArray (possibleRates); ++i)
  210489. {
  210490. bool ok = false;
  210491. for (int j = size / (int) sizeof (AudioValueRange); --j >= 0;)
  210492. if (possibleRates[i] >= ranges[j].mMinimum - 2 && possibleRates[i] <= ranges[j].mMaximum + 2)
  210493. ok = true;
  210494. if (ok)
  210495. {
  210496. sampleRates.add (possibleRates[i]);
  210497. rates << possibleRates[i] << T(" ");
  210498. }
  210499. }
  210500. }
  210501. }
  210502. if (sampleRates.size() == 0 && sampleRate > 0)
  210503. {
  210504. sampleRates.add (sampleRate);
  210505. rates << sampleRate;
  210506. }
  210507. log (T("sr: ") + rates);
  210508. inputLatency = 0;
  210509. outputLatency = 0;
  210510. UInt32 lat;
  210511. size = sizeof (lat);
  210512. pa.mSelector = kAudioDevicePropertyLatency;
  210513. pa.mScope = kAudioDevicePropertyScopeInput;
  210514. //if (AudioDeviceGetProperty (deviceID, 0, true, kAudioDevicePropertyLatency, &size, &lat) == noErr)
  210515. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210516. inputLatency = (int) lat;
  210517. pa.mScope = kAudioDevicePropertyScopeOutput;
  210518. size = sizeof (lat);
  210519. if (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &lat) == noErr)
  210520. outputLatency = (int) lat;
  210521. log (T("lat: ") + String (inputLatency) + T(" ") + String (outputLatency));
  210522. inChanNames.clear();
  210523. outChanNames.clear();
  210524. inputChannelInfo.calloc (numInputChans + 2);
  210525. numInputChannelInfos = 0;
  210526. outputChannelInfo.calloc (numOutputChans + 2);
  210527. numOutputChannelInfos = 0;
  210528. fillInChannelInfo (true);
  210529. fillInChannelInfo (false);
  210530. }
  210531. const StringArray getSources (bool input)
  210532. {
  210533. StringArray s;
  210534. HeapBlock <OSType> types;
  210535. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210536. for (int i = 0; i < num; ++i)
  210537. {
  210538. AudioValueTranslation avt;
  210539. char buffer[256];
  210540. avt.mInputData = (void*) &(types[i]);
  210541. avt.mInputDataSize = sizeof (UInt32);
  210542. avt.mOutputData = buffer;
  210543. avt.mOutputDataSize = 256;
  210544. UInt32 transSize = sizeof (avt);
  210545. AudioObjectPropertyAddress pa;
  210546. pa.mSelector = kAudioDevicePropertyDataSourceNameForID;
  210547. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210548. pa.mElement = kAudioObjectPropertyElementMaster;
  210549. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &transSize, &avt)))
  210550. {
  210551. DBG (buffer);
  210552. s.add (buffer);
  210553. }
  210554. }
  210555. return s;
  210556. }
  210557. int getCurrentSourceIndex (bool input) const
  210558. {
  210559. OSType currentSourceID = 0;
  210560. UInt32 size = sizeof (currentSourceID);
  210561. int result = -1;
  210562. AudioObjectPropertyAddress pa;
  210563. pa.mSelector = kAudioDevicePropertyDataSource;
  210564. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210565. pa.mElement = kAudioObjectPropertyElementMaster;
  210566. if (deviceID != 0)
  210567. {
  210568. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &currentSourceID)))
  210569. {
  210570. HeapBlock <OSType> types;
  210571. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210572. for (int i = 0; i < num; ++i)
  210573. {
  210574. if (types[num] == currentSourceID)
  210575. {
  210576. result = i;
  210577. break;
  210578. }
  210579. }
  210580. }
  210581. }
  210582. return result;
  210583. }
  210584. void setCurrentSourceIndex (int index, bool input)
  210585. {
  210586. if (deviceID != 0)
  210587. {
  210588. HeapBlock <OSType> types;
  210589. const int num = getAllDataSourcesForDevice (deviceID, input, types);
  210590. if (((unsigned int) index) < (unsigned int) num)
  210591. {
  210592. AudioObjectPropertyAddress pa;
  210593. pa.mSelector = kAudioDevicePropertyDataSource;
  210594. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  210595. pa.mElement = kAudioObjectPropertyElementMaster;
  210596. OSType typeId = types[index];
  210597. OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (typeId), &typeId));
  210598. }
  210599. }
  210600. }
  210601. const String reopen (const BitArray& inputChannels,
  210602. const BitArray& outputChannels,
  210603. double newSampleRate,
  210604. int bufferSizeSamples)
  210605. {
  210606. String error;
  210607. log ("CoreAudio reopen");
  210608. callbacksAllowed = false;
  210609. stopTimer();
  210610. stop (false);
  210611. activeInputChans = inputChannels;
  210612. activeInputChans.setRange (inChanNames.size(),
  210613. activeInputChans.getHighestBit() + 1 - inChanNames.size(),
  210614. false);
  210615. activeOutputChans = outputChannels;
  210616. activeOutputChans.setRange (outChanNames.size(),
  210617. activeOutputChans.getHighestBit() + 1 - outChanNames.size(),
  210618. false);
  210619. numInputChans = activeInputChans.countNumberOfSetBits();
  210620. numOutputChans = activeOutputChans.countNumberOfSetBits();
  210621. // set sample rate
  210622. AudioObjectPropertyAddress pa;
  210623. pa.mSelector = kAudioDevicePropertyNominalSampleRate;
  210624. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210625. pa.mElement = kAudioObjectPropertyElementMaster;
  210626. Float64 sr = newSampleRate;
  210627. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (sr), &sr)))
  210628. {
  210629. error = "Couldn't change sample rate";
  210630. }
  210631. else
  210632. {
  210633. // change buffer size
  210634. UInt32 framesPerBuf = bufferSizeSamples;
  210635. pa.mSelector = kAudioDevicePropertyBufferFrameSize;
  210636. if (! OK (AudioObjectSetPropertyData (deviceID, &pa, 0, 0, sizeof (framesPerBuf), &framesPerBuf)))
  210637. {
  210638. error = "Couldn't change buffer size";
  210639. }
  210640. else
  210641. {
  210642. // Annoyingly, after changing the rate and buffer size, some devices fail to
  210643. // correctly report their new settings until some random time in the future, so
  210644. // after calling updateDetailsFromDevice, we need to manually bodge these values
  210645. // to make sure we're using the correct numbers..
  210646. updateDetailsFromDevice();
  210647. sampleRate = newSampleRate;
  210648. bufferSize = bufferSizeSamples;
  210649. if (sampleRates.size() == 0)
  210650. error = "Device has no available sample-rates";
  210651. else if (bufferSizes.size() == 0)
  210652. error = "Device has no available buffer-sizes";
  210653. else if (inputDevice != 0)
  210654. error = inputDevice->reopen (inputChannels,
  210655. outputChannels,
  210656. newSampleRate,
  210657. bufferSizeSamples);
  210658. }
  210659. }
  210660. callbacksAllowed = true;
  210661. return error;
  210662. }
  210663. bool start (AudioIODeviceCallback* cb)
  210664. {
  210665. if (! started)
  210666. {
  210667. callback = 0;
  210668. if (deviceID != 0)
  210669. {
  210670. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210671. if (OK (AudioDeviceAddIOProc (deviceID, audioIOProc, (void*) this)))
  210672. #else
  210673. if (OK (AudioDeviceCreateIOProcID (deviceID, audioIOProc, (void*) this, &audioProcID)))
  210674. #endif
  210675. {
  210676. if (OK (AudioDeviceStart (deviceID, audioIOProc)))
  210677. {
  210678. started = true;
  210679. }
  210680. else
  210681. {
  210682. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210683. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210684. #else
  210685. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210686. audioProcID = 0;
  210687. #endif
  210688. }
  210689. }
  210690. }
  210691. }
  210692. if (started)
  210693. {
  210694. const ScopedLock sl (callbackLock);
  210695. callback = cb;
  210696. }
  210697. if (inputDevice != 0)
  210698. return started && inputDevice->start (cb);
  210699. else
  210700. return started;
  210701. }
  210702. void stop (bool leaveInterruptRunning)
  210703. {
  210704. {
  210705. const ScopedLock sl (callbackLock);
  210706. callback = 0;
  210707. }
  210708. if (started
  210709. && (deviceID != 0)
  210710. && ! leaveInterruptRunning)
  210711. {
  210712. OK (AudioDeviceStop (deviceID, audioIOProc));
  210713. #if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_5
  210714. OK (AudioDeviceRemoveIOProc (deviceID, audioIOProc));
  210715. #else
  210716. OK (AudioDeviceDestroyIOProcID (deviceID, audioProcID));
  210717. audioProcID = 0;
  210718. #endif
  210719. started = false;
  210720. { const ScopedLock sl (callbackLock); }
  210721. // wait until it's definately stopped calling back..
  210722. for (int i = 40; --i >= 0;)
  210723. {
  210724. Thread::sleep (50);
  210725. UInt32 running = 0;
  210726. UInt32 size = sizeof (running);
  210727. AudioObjectPropertyAddress pa;
  210728. pa.mSelector = kAudioDevicePropertyDeviceIsRunning;
  210729. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210730. pa.mElement = kAudioObjectPropertyElementMaster;
  210731. OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, &running));
  210732. if (running == 0)
  210733. break;
  210734. }
  210735. const ScopedLock sl (callbackLock);
  210736. }
  210737. if (inputDevice != 0)
  210738. inputDevice->stop (leaveInterruptRunning);
  210739. }
  210740. double getSampleRate() const
  210741. {
  210742. return sampleRate;
  210743. }
  210744. int getBufferSize() const
  210745. {
  210746. return bufferSize;
  210747. }
  210748. void audioCallback (const AudioBufferList* inInputData,
  210749. AudioBufferList* outOutputData)
  210750. {
  210751. int i;
  210752. const ScopedLock sl (callbackLock);
  210753. if (callback != 0)
  210754. {
  210755. if (inputDevice == 0)
  210756. {
  210757. for (i = numInputChans; --i >= 0;)
  210758. {
  210759. const CallbackDetailsForChannel& info = inputChannelInfo[i];
  210760. float* dest = tempInputBuffers [i];
  210761. const float* src = ((const float*) inInputData->mBuffers[info.streamNum].mData)
  210762. + info.dataOffsetSamples;
  210763. const int stride = info.dataStrideSamples;
  210764. if (stride != 0) // if this is zero, info is invalid
  210765. {
  210766. for (int j = bufferSize; --j >= 0;)
  210767. {
  210768. *dest++ = *src;
  210769. src += stride;
  210770. }
  210771. }
  210772. }
  210773. }
  210774. if (! isSlaveDevice)
  210775. {
  210776. if (inputDevice == 0)
  210777. {
  210778. callback->audioDeviceIOCallback ((const float**) tempInputBuffers,
  210779. numInputChans,
  210780. tempOutputBuffers,
  210781. numOutputChans,
  210782. bufferSize);
  210783. }
  210784. else
  210785. {
  210786. jassert (inputDevice->bufferSize == bufferSize);
  210787. // Sometimes the two linked devices seem to get their callbacks in
  210788. // parallel, so we need to lock both devices to stop the input data being
  210789. // changed while inside our callback..
  210790. const ScopedLock sl2 (inputDevice->callbackLock);
  210791. callback->audioDeviceIOCallback ((const float**) inputDevice->tempInputBuffers,
  210792. inputDevice->numInputChans,
  210793. tempOutputBuffers,
  210794. numOutputChans,
  210795. bufferSize);
  210796. }
  210797. for (i = numOutputChans; --i >= 0;)
  210798. {
  210799. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210800. const float* src = tempOutputBuffers [i];
  210801. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210802. + info.dataOffsetSamples;
  210803. const int stride = info.dataStrideSamples;
  210804. if (stride != 0) // if this is zero, info is invalid
  210805. {
  210806. for (int j = bufferSize; --j >= 0;)
  210807. {
  210808. *dest = *src++;
  210809. dest += stride;
  210810. }
  210811. }
  210812. }
  210813. }
  210814. }
  210815. else
  210816. {
  210817. for (i = jmin (numOutputChans, numOutputChannelInfos); --i >= 0;)
  210818. {
  210819. const CallbackDetailsForChannel& info = outputChannelInfo[i];
  210820. float* dest = ((float*) outOutputData->mBuffers[info.streamNum].mData)
  210821. + info.dataOffsetSamples;
  210822. const int stride = info.dataStrideSamples;
  210823. if (stride != 0) // if this is zero, info is invalid
  210824. {
  210825. for (int j = bufferSize; --j >= 0;)
  210826. {
  210827. *dest = 0.0f;
  210828. dest += stride;
  210829. }
  210830. }
  210831. }
  210832. }
  210833. }
  210834. // called by callbacks
  210835. void deviceDetailsChanged()
  210836. {
  210837. if (callbacksAllowed)
  210838. startTimer (100);
  210839. }
  210840. void timerCallback()
  210841. {
  210842. stopTimer();
  210843. log ("CoreAudio device changed callback");
  210844. const double oldSampleRate = sampleRate;
  210845. const int oldBufferSize = bufferSize;
  210846. updateDetailsFromDevice();
  210847. if (oldBufferSize != bufferSize || oldSampleRate != sampleRate)
  210848. {
  210849. callbacksAllowed = false;
  210850. stop (false);
  210851. updateDetailsFromDevice();
  210852. callbacksAllowed = true;
  210853. }
  210854. }
  210855. CoreAudioInternal* getRelatedDevice() const
  210856. {
  210857. UInt32 size = 0;
  210858. ScopedPointer <CoreAudioInternal> result;
  210859. AudioObjectPropertyAddress pa;
  210860. pa.mSelector = kAudioDevicePropertyRelatedDevices;
  210861. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210862. pa.mElement = kAudioObjectPropertyElementMaster;
  210863. if (deviceID != 0
  210864. && AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size) == noErr
  210865. && size > 0)
  210866. {
  210867. HeapBlock <AudioDeviceID> devs;
  210868. devs.calloc (size, 1);
  210869. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, devs)))
  210870. {
  210871. for (unsigned int i = 0; i < size / sizeof (AudioDeviceID); ++i)
  210872. {
  210873. if (devs[i] != deviceID && devs[i] != 0)
  210874. {
  210875. result = new CoreAudioInternal (devs[i]);
  210876. const bool thisIsInput = inChanNames.size() > 0 && outChanNames.size() == 0;
  210877. const bool otherIsInput = result->inChanNames.size() > 0 && result->outChanNames.size() == 0;
  210878. if (thisIsInput != otherIsInput
  210879. || (inChanNames.size() + outChanNames.size() == 0)
  210880. || (result->inChanNames.size() + result->outChanNames.size()) == 0)
  210881. break;
  210882. result = 0;
  210883. }
  210884. }
  210885. }
  210886. }
  210887. return result.release();
  210888. }
  210889. juce_UseDebuggingNewOperator
  210890. int inputLatency, outputLatency;
  210891. BitArray activeInputChans, activeOutputChans;
  210892. StringArray inChanNames, outChanNames;
  210893. Array <double> sampleRates;
  210894. Array <int> bufferSizes;
  210895. AudioIODeviceCallback* callback;
  210896. #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
  210897. AudioDeviceIOProcID audioProcID;
  210898. #endif
  210899. CoreAudioInternal* inputDevice;
  210900. bool isSlaveDevice;
  210901. private:
  210902. CriticalSection callbackLock;
  210903. AudioDeviceID deviceID;
  210904. bool started;
  210905. double sampleRate;
  210906. int bufferSize;
  210907. HeapBlock <float> audioBuffer;
  210908. int numInputChans, numOutputChans;
  210909. bool callbacksAllowed;
  210910. struct CallbackDetailsForChannel
  210911. {
  210912. int streamNum;
  210913. int dataOffsetSamples;
  210914. int dataStrideSamples;
  210915. };
  210916. int numInputChannelInfos, numOutputChannelInfos;
  210917. HeapBlock <CallbackDetailsForChannel> inputChannelInfo, outputChannelInfo;
  210918. HeapBlock <float*> tempInputBuffers, tempOutputBuffers;
  210919. CoreAudioInternal (const CoreAudioInternal&);
  210920. CoreAudioInternal& operator= (const CoreAudioInternal&);
  210921. static OSStatus audioIOProc (AudioDeviceID inDevice,
  210922. const AudioTimeStamp* inNow,
  210923. const AudioBufferList* inInputData,
  210924. const AudioTimeStamp* inInputTime,
  210925. AudioBufferList* outOutputData,
  210926. const AudioTimeStamp* inOutputTime,
  210927. void* device)
  210928. {
  210929. ((CoreAudioInternal*) device)->audioCallback (inInputData, outOutputData);
  210930. return noErr;
  210931. }
  210932. static OSStatus deviceListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  210933. {
  210934. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  210935. switch (pa->mSelector)
  210936. {
  210937. case kAudioDevicePropertyBufferSize:
  210938. case kAudioDevicePropertyBufferFrameSize:
  210939. case kAudioDevicePropertyNominalSampleRate:
  210940. case kAudioDevicePropertyStreamFormat:
  210941. case kAudioDevicePropertyDeviceIsAlive:
  210942. intern->deviceDetailsChanged();
  210943. break;
  210944. case kAudioDevicePropertyBufferSizeRange:
  210945. case kAudioDevicePropertyVolumeScalar:
  210946. case kAudioDevicePropertyMute:
  210947. case kAudioDevicePropertyPlayThru:
  210948. case kAudioDevicePropertyDataSource:
  210949. case kAudioDevicePropertyDeviceIsRunning:
  210950. break;
  210951. }
  210952. return noErr;
  210953. }
  210954. static int getAllDataSourcesForDevice (AudioDeviceID deviceID, const bool input, HeapBlock <OSType>& types)
  210955. {
  210956. AudioObjectPropertyAddress pa;
  210957. pa.mSelector = kAudioDevicePropertyDataSources;
  210958. pa.mScope = kAudioObjectPropertyScopeWildcard;
  210959. pa.mElement = kAudioObjectPropertyElementMaster;
  210960. UInt32 size = 0;
  210961. if (deviceID != 0
  210962. && OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  210963. {
  210964. types.calloc (size, 1);
  210965. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, types)))
  210966. return size / (int) sizeof (OSType);
  210967. }
  210968. return 0;
  210969. }
  210970. };
  210971. class CoreAudioIODevice : public AudioIODevice
  210972. {
  210973. public:
  210974. CoreAudioIODevice (const String& deviceName,
  210975. AudioDeviceID inputDeviceId,
  210976. const int inputIndex_,
  210977. AudioDeviceID outputDeviceId,
  210978. const int outputIndex_)
  210979. : AudioIODevice (deviceName, "CoreAudio"),
  210980. inputIndex (inputIndex_),
  210981. outputIndex (outputIndex_),
  210982. isOpen_ (false),
  210983. isStarted (false)
  210984. {
  210985. internal = 0;
  210986. CoreAudioInternal* device = 0;
  210987. if (outputDeviceId == 0 || outputDeviceId == inputDeviceId)
  210988. {
  210989. jassert (inputDeviceId != 0);
  210990. device = new CoreAudioInternal (inputDeviceId);
  210991. }
  210992. else
  210993. {
  210994. device = new CoreAudioInternal (outputDeviceId);
  210995. if (inputDeviceId != 0)
  210996. {
  210997. CoreAudioInternal* secondDevice = new CoreAudioInternal (inputDeviceId);
  210998. device->inputDevice = secondDevice;
  210999. secondDevice->isSlaveDevice = true;
  211000. }
  211001. }
  211002. internal = device;
  211003. AudioObjectPropertyAddress pa;
  211004. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211005. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211006. pa.mElement = kAudioObjectPropertyElementWildcard;
  211007. AudioObjectAddPropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211008. }
  211009. ~CoreAudioIODevice()
  211010. {
  211011. AudioObjectPropertyAddress pa;
  211012. pa.mSelector = kAudioObjectPropertySelectorWildcard;
  211013. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211014. pa.mElement = kAudioObjectPropertyElementWildcard;
  211015. AudioObjectRemovePropertyListener (kAudioObjectSystemObject, &pa, hardwareListenerProc, internal);
  211016. delete internal;
  211017. }
  211018. const StringArray getOutputChannelNames()
  211019. {
  211020. return internal->outChanNames;
  211021. }
  211022. const StringArray getInputChannelNames()
  211023. {
  211024. if (internal->inputDevice != 0)
  211025. return internal->inputDevice->inChanNames;
  211026. else
  211027. return internal->inChanNames;
  211028. }
  211029. int getNumSampleRates()
  211030. {
  211031. return internal->sampleRates.size();
  211032. }
  211033. double getSampleRate (int index)
  211034. {
  211035. return internal->sampleRates [index];
  211036. }
  211037. int getNumBufferSizesAvailable()
  211038. {
  211039. return internal->bufferSizes.size();
  211040. }
  211041. int getBufferSizeSamples (int index)
  211042. {
  211043. return internal->bufferSizes [index];
  211044. }
  211045. int getDefaultBufferSize()
  211046. {
  211047. for (int i = 0; i < getNumBufferSizesAvailable(); ++i)
  211048. if (getBufferSizeSamples(i) >= 512)
  211049. return getBufferSizeSamples(i);
  211050. return 512;
  211051. }
  211052. const String open (const BitArray& inputChannels,
  211053. const BitArray& outputChannels,
  211054. double sampleRate,
  211055. int bufferSizeSamples)
  211056. {
  211057. isOpen_ = true;
  211058. if (bufferSizeSamples <= 0)
  211059. bufferSizeSamples = getDefaultBufferSize();
  211060. lastError = internal->reopen (inputChannels, outputChannels, sampleRate, bufferSizeSamples);
  211061. isOpen_ = lastError.isEmpty();
  211062. return lastError;
  211063. }
  211064. void close()
  211065. {
  211066. isOpen_ = false;
  211067. internal->stop (false);
  211068. }
  211069. bool isOpen()
  211070. {
  211071. return isOpen_;
  211072. }
  211073. int getCurrentBufferSizeSamples()
  211074. {
  211075. return internal != 0 ? internal->getBufferSize() : 512;
  211076. }
  211077. double getCurrentSampleRate()
  211078. {
  211079. return internal != 0 ? internal->getSampleRate() : 0;
  211080. }
  211081. int getCurrentBitDepth()
  211082. {
  211083. return 32; // no way to find out, so just assume it's high..
  211084. }
  211085. const BitArray getActiveOutputChannels() const
  211086. {
  211087. return internal != 0 ? internal->activeOutputChans : BitArray();
  211088. }
  211089. const BitArray getActiveInputChannels() const
  211090. {
  211091. BitArray chans;
  211092. if (internal != 0)
  211093. {
  211094. chans = internal->activeInputChans;
  211095. if (internal->inputDevice != 0)
  211096. chans.orWith (internal->inputDevice->activeInputChans);
  211097. }
  211098. return chans;
  211099. }
  211100. int getOutputLatencyInSamples()
  211101. {
  211102. if (internal == 0)
  211103. return 0;
  211104. // this seems like a good guess at getting the latency right - comparing
  211105. // this with a round-trip measurement, it gets it to within a few millisecs
  211106. // for the built-in mac soundcard
  211107. return internal->outputLatency + internal->getBufferSize() * 2;
  211108. }
  211109. int getInputLatencyInSamples()
  211110. {
  211111. if (internal == 0)
  211112. return 0;
  211113. return internal->inputLatency + internal->getBufferSize() * 2;
  211114. }
  211115. void start (AudioIODeviceCallback* callback)
  211116. {
  211117. if (internal != 0 && ! isStarted)
  211118. {
  211119. if (callback != 0)
  211120. callback->audioDeviceAboutToStart (this);
  211121. isStarted = true;
  211122. internal->start (callback);
  211123. }
  211124. }
  211125. void stop()
  211126. {
  211127. if (isStarted && internal != 0)
  211128. {
  211129. AudioIODeviceCallback* const lastCallback = internal->callback;
  211130. isStarted = false;
  211131. internal->stop (true);
  211132. if (lastCallback != 0)
  211133. lastCallback->audioDeviceStopped();
  211134. }
  211135. }
  211136. bool isPlaying()
  211137. {
  211138. if (internal->callback == 0)
  211139. isStarted = false;
  211140. return isStarted;
  211141. }
  211142. const String getLastError()
  211143. {
  211144. return lastError;
  211145. }
  211146. int inputIndex, outputIndex;
  211147. juce_UseDebuggingNewOperator
  211148. private:
  211149. CoreAudioInternal* internal;
  211150. bool isOpen_, isStarted;
  211151. String lastError;
  211152. static OSStatus hardwareListenerProc (AudioDeviceID /*inDevice*/, UInt32 /*inLine*/, const AudioObjectPropertyAddress* pa, void* inClientData)
  211153. {
  211154. CoreAudioInternal* const intern = (CoreAudioInternal*) inClientData;
  211155. switch (pa->mSelector)
  211156. {
  211157. case kAudioHardwarePropertyDevices:
  211158. intern->deviceDetailsChanged();
  211159. break;
  211160. case kAudioHardwarePropertyDefaultOutputDevice:
  211161. case kAudioHardwarePropertyDefaultInputDevice:
  211162. case kAudioHardwarePropertyDefaultSystemOutputDevice:
  211163. break;
  211164. }
  211165. return noErr;
  211166. }
  211167. CoreAudioIODevice (const CoreAudioIODevice&);
  211168. CoreAudioIODevice& operator= (const CoreAudioIODevice&);
  211169. };
  211170. class CoreAudioIODeviceType : public AudioIODeviceType
  211171. {
  211172. public:
  211173. CoreAudioIODeviceType()
  211174. : AudioIODeviceType (T("CoreAudio")),
  211175. hasScanned (false)
  211176. {
  211177. }
  211178. ~CoreAudioIODeviceType()
  211179. {
  211180. }
  211181. void scanForDevices()
  211182. {
  211183. hasScanned = true;
  211184. inputDeviceNames.clear();
  211185. outputDeviceNames.clear();
  211186. inputIds.clear();
  211187. outputIds.clear();
  211188. UInt32 size;
  211189. AudioObjectPropertyAddress pa;
  211190. pa.mSelector = kAudioHardwarePropertyDevices;
  211191. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211192. pa.mElement = kAudioObjectPropertyElementMaster;
  211193. if (OK (AudioObjectGetPropertyDataSize (kAudioObjectSystemObject, &pa, 0, 0, &size)))
  211194. {
  211195. HeapBlock <AudioDeviceID> devs;
  211196. devs.calloc (size, 1);
  211197. if (OK (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, devs)))
  211198. {
  211199. static bool alreadyLogged = false;
  211200. const int num = size / (int) sizeof (AudioDeviceID);
  211201. for (int i = 0; i < num; ++i)
  211202. {
  211203. char name [1024];
  211204. size = sizeof (name);
  211205. pa.mSelector = kAudioDevicePropertyDeviceName;
  211206. if (OK (AudioObjectGetPropertyData (devs[i], &pa, 0, 0, &size, name)))
  211207. {
  211208. const String nameString (String::fromUTF8 (name, (int) strlen (name)));
  211209. if (! alreadyLogged)
  211210. log (T("CoreAudio device: ") + nameString);
  211211. const int numIns = getNumChannels (devs[i], true);
  211212. const int numOuts = getNumChannels (devs[i], false);
  211213. if (numIns > 0)
  211214. {
  211215. inputDeviceNames.add (nameString);
  211216. inputIds.add (devs[i]);
  211217. }
  211218. if (numOuts > 0)
  211219. {
  211220. outputDeviceNames.add (nameString);
  211221. outputIds.add (devs[i]);
  211222. }
  211223. }
  211224. }
  211225. alreadyLogged = true;
  211226. }
  211227. }
  211228. inputDeviceNames.appendNumbersToDuplicates (false, true);
  211229. outputDeviceNames.appendNumbersToDuplicates (false, true);
  211230. }
  211231. const StringArray getDeviceNames (const bool wantInputNames) const
  211232. {
  211233. jassert (hasScanned); // need to call scanForDevices() before doing this
  211234. if (wantInputNames)
  211235. return inputDeviceNames;
  211236. else
  211237. return outputDeviceNames;
  211238. }
  211239. int getDefaultDeviceIndex (const bool forInput) const
  211240. {
  211241. jassert (hasScanned); // need to call scanForDevices() before doing this
  211242. AudioDeviceID deviceID;
  211243. UInt32 size = sizeof (deviceID);
  211244. // if they're asking for any input channels at all, use the default input, so we
  211245. // get the built-in mic rather than the built-in output with no inputs..
  211246. AudioObjectPropertyAddress pa;
  211247. pa.mSelector = forInput ? kAudioHardwarePropertyDefaultInputDevice : kAudioHardwarePropertyDefaultOutputDevice;
  211248. pa.mScope = kAudioObjectPropertyScopeWildcard;
  211249. pa.mElement = kAudioObjectPropertyElementMaster;
  211250. if (AudioObjectGetPropertyData (kAudioObjectSystemObject, &pa, 0, 0, &size, &deviceID) == noErr)
  211251. {
  211252. if (forInput)
  211253. {
  211254. for (int i = inputIds.size(); --i >= 0;)
  211255. if (inputIds[i] == deviceID)
  211256. return i;
  211257. }
  211258. else
  211259. {
  211260. for (int i = outputIds.size(); --i >= 0;)
  211261. if (outputIds[i] == deviceID)
  211262. return i;
  211263. }
  211264. }
  211265. return 0;
  211266. }
  211267. int getIndexOfDevice (AudioIODevice* device, const bool asInput) const
  211268. {
  211269. jassert (hasScanned); // need to call scanForDevices() before doing this
  211270. CoreAudioIODevice* const d = dynamic_cast <CoreAudioIODevice*> (device);
  211271. if (d == 0)
  211272. return -1;
  211273. return asInput ? d->inputIndex
  211274. : d->outputIndex;
  211275. }
  211276. bool hasSeparateInputsAndOutputs() const { return true; }
  211277. AudioIODevice* createDevice (const String& outputDeviceName,
  211278. const String& inputDeviceName)
  211279. {
  211280. jassert (hasScanned); // need to call scanForDevices() before doing this
  211281. const int inputIndex = inputDeviceNames.indexOf (inputDeviceName);
  211282. const int outputIndex = outputDeviceNames.indexOf (outputDeviceName);
  211283. String deviceName (outputDeviceName);
  211284. if (deviceName.isEmpty())
  211285. deviceName = inputDeviceName;
  211286. if (index >= 0)
  211287. return new CoreAudioIODevice (deviceName,
  211288. inputIds [inputIndex],
  211289. inputIndex,
  211290. outputIds [outputIndex],
  211291. outputIndex);
  211292. return 0;
  211293. }
  211294. juce_UseDebuggingNewOperator
  211295. private:
  211296. StringArray inputDeviceNames, outputDeviceNames;
  211297. Array <AudioDeviceID> inputIds, outputIds;
  211298. bool hasScanned;
  211299. static int getNumChannels (AudioDeviceID deviceID, bool input)
  211300. {
  211301. int total = 0;
  211302. UInt32 size;
  211303. AudioObjectPropertyAddress pa;
  211304. pa.mSelector = kAudioDevicePropertyStreamConfiguration;
  211305. pa.mScope = input ? kAudioDevicePropertyScopeInput : kAudioDevicePropertyScopeOutput;
  211306. pa.mElement = kAudioObjectPropertyElementMaster;
  211307. if (OK (AudioObjectGetPropertyDataSize (deviceID, &pa, 0, 0, &size)))
  211308. {
  211309. HeapBlock <AudioBufferList> bufList;
  211310. bufList.calloc (size, 1);
  211311. if (OK (AudioObjectGetPropertyData (deviceID, &pa, 0, 0, &size, bufList)))
  211312. {
  211313. const int numStreams = bufList->mNumberBuffers;
  211314. for (int i = 0; i < numStreams; ++i)
  211315. {
  211316. const AudioBuffer& b = bufList->mBuffers[i];
  211317. total += b.mNumberChannels;
  211318. }
  211319. }
  211320. }
  211321. return total;
  211322. }
  211323. CoreAudioIODeviceType (const CoreAudioIODeviceType&);
  211324. CoreAudioIODeviceType& operator= (const CoreAudioIODeviceType&);
  211325. };
  211326. AudioIODeviceType* juce_createAudioIODeviceType_CoreAudio()
  211327. {
  211328. return new CoreAudioIODeviceType();
  211329. }
  211330. #undef log
  211331. #endif
  211332. /*** End of inlined file: juce_mac_CoreAudio.cpp ***/
  211333. /*** Start of inlined file: juce_mac_CoreMidi.cpp ***/
  211334. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211335. // compiled on its own).
  211336. #if JUCE_INCLUDED_FILE
  211337. #if JUCE_MAC
  211338. #undef log
  211339. #define log(a) Logger::writeToLog(a)
  211340. static bool logAnyErrorsMidi (const OSStatus err, const int lineNum)
  211341. {
  211342. if (err == noErr)
  211343. return true;
  211344. log (T("CoreMidi error: ") + String (lineNum) + T(" - ") + String::toHexString ((int)err));
  211345. jassertfalse
  211346. return false;
  211347. }
  211348. #undef OK
  211349. #define OK(a) logAnyErrorsMidi(a, __LINE__)
  211350. static const String getEndpointName (MIDIEndpointRef endpoint, bool isExternal)
  211351. {
  211352. String result;
  211353. CFStringRef str = 0;
  211354. MIDIObjectGetStringProperty (endpoint, kMIDIPropertyName, &str);
  211355. if (str != 0)
  211356. {
  211357. result = PlatformUtilities::cfStringToJuceString (str);
  211358. CFRelease (str);
  211359. str = 0;
  211360. }
  211361. MIDIEntityRef entity = 0;
  211362. MIDIEndpointGetEntity (endpoint, &entity);
  211363. if (entity == 0)
  211364. return result; // probably virtual
  211365. if (result.isEmpty())
  211366. {
  211367. // endpoint name has zero length - try the entity
  211368. MIDIObjectGetStringProperty (entity, kMIDIPropertyName, &str);
  211369. if (str != 0)
  211370. {
  211371. result += PlatformUtilities::cfStringToJuceString (str);
  211372. CFRelease (str);
  211373. str = 0;
  211374. }
  211375. }
  211376. // now consider the device's name
  211377. MIDIDeviceRef device = 0;
  211378. MIDIEntityGetDevice (entity, &device);
  211379. if (device == 0)
  211380. return result;
  211381. MIDIObjectGetStringProperty (device, kMIDIPropertyName, &str);
  211382. if (str != 0)
  211383. {
  211384. const String s (PlatformUtilities::cfStringToJuceString (str));
  211385. CFRelease (str);
  211386. // if an external device has only one entity, throw away
  211387. // the endpoint name and just use the device name
  211388. if (isExternal && MIDIDeviceGetNumberOfEntities (device) < 2)
  211389. {
  211390. result = s;
  211391. }
  211392. else if (! result.startsWithIgnoreCase (s))
  211393. {
  211394. // prepend the device name to the entity name
  211395. result = (s + T(" ") + result).trimEnd();
  211396. }
  211397. }
  211398. return result;
  211399. }
  211400. static const String getConnectedEndpointName (MIDIEndpointRef endpoint)
  211401. {
  211402. String result;
  211403. // Does the endpoint have connections?
  211404. CFDataRef connections = 0;
  211405. int numConnections = 0;
  211406. MIDIObjectGetDataProperty (endpoint, kMIDIPropertyConnectionUniqueID, &connections);
  211407. if (connections != 0)
  211408. {
  211409. numConnections = (int) (CFDataGetLength (connections) / sizeof (MIDIUniqueID));
  211410. if (numConnections > 0)
  211411. {
  211412. const SInt32* pid = reinterpret_cast <const SInt32*> (CFDataGetBytePtr (connections));
  211413. for (int i = 0; i < numConnections; ++i, ++pid)
  211414. {
  211415. MIDIUniqueID uid = EndianS32_BtoN (*pid);
  211416. MIDIObjectRef connObject;
  211417. MIDIObjectType connObjectType;
  211418. OSStatus err = MIDIObjectFindByUniqueID (uid, &connObject, &connObjectType);
  211419. if (err == noErr)
  211420. {
  211421. String s;
  211422. if (connObjectType == kMIDIObjectType_ExternalSource
  211423. || connObjectType == kMIDIObjectType_ExternalDestination)
  211424. {
  211425. // Connected to an external device's endpoint (10.3 and later).
  211426. s = getEndpointName (static_cast <MIDIEndpointRef> (connObject), true);
  211427. }
  211428. else
  211429. {
  211430. // Connected to an external device (10.2) (or something else, catch-all)
  211431. CFStringRef str = 0;
  211432. MIDIObjectGetStringProperty (connObject, kMIDIPropertyName, &str);
  211433. if (str != 0)
  211434. {
  211435. s = PlatformUtilities::cfStringToJuceString (str);
  211436. CFRelease (str);
  211437. }
  211438. }
  211439. if (s.isNotEmpty())
  211440. {
  211441. if (result.isNotEmpty())
  211442. result += (", ");
  211443. result += s;
  211444. }
  211445. }
  211446. }
  211447. }
  211448. CFRelease (connections);
  211449. }
  211450. if (result.isNotEmpty())
  211451. return result;
  211452. // Here, either the endpoint had no connections, or we failed to obtain names for any of them.
  211453. return getEndpointName (endpoint, false);
  211454. }
  211455. const StringArray MidiOutput::getDevices()
  211456. {
  211457. StringArray s;
  211458. const ItemCount num = MIDIGetNumberOfDestinations();
  211459. for (ItemCount i = 0; i < num; ++i)
  211460. {
  211461. MIDIEndpointRef dest = MIDIGetDestination (i);
  211462. if (dest != 0)
  211463. {
  211464. String name (getConnectedEndpointName (dest));
  211465. if (name.isEmpty())
  211466. name = "<error>";
  211467. s.add (name);
  211468. }
  211469. else
  211470. {
  211471. s.add ("<error>");
  211472. }
  211473. }
  211474. return s;
  211475. }
  211476. int MidiOutput::getDefaultDeviceIndex()
  211477. {
  211478. return 0;
  211479. }
  211480. static MIDIClientRef globalMidiClient;
  211481. static bool hasGlobalClientBeenCreated = false;
  211482. static bool makeSureClientExists()
  211483. {
  211484. if (! hasGlobalClientBeenCreated)
  211485. {
  211486. String name (T("JUCE"));
  211487. if (JUCEApplication::getInstance() != 0)
  211488. name = JUCEApplication::getInstance()->getApplicationName();
  211489. CFStringRef appName = PlatformUtilities::juceStringToCFString (name);
  211490. hasGlobalClientBeenCreated = OK (MIDIClientCreate (appName, 0, 0, &globalMidiClient));
  211491. CFRelease (appName);
  211492. }
  211493. return hasGlobalClientBeenCreated;
  211494. }
  211495. class MidiPortAndEndpoint
  211496. {
  211497. public:
  211498. MidiPortAndEndpoint (MIDIPortRef port_, MIDIEndpointRef endPoint_)
  211499. : port (port_), endPoint (endPoint_)
  211500. {
  211501. }
  211502. ~MidiPortAndEndpoint()
  211503. {
  211504. if (port != 0)
  211505. MIDIPortDispose (port);
  211506. if (port == 0 && endPoint != 0) // if port == 0, it means we created the endpoint, so it's safe to delete it
  211507. MIDIEndpointDispose (endPoint);
  211508. }
  211509. MIDIPortRef port;
  211510. MIDIEndpointRef endPoint;
  211511. };
  211512. MidiOutput* MidiOutput::openDevice (int index)
  211513. {
  211514. MidiOutput* mo = 0;
  211515. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfDestinations())
  211516. {
  211517. MIDIEndpointRef endPoint = MIDIGetDestination (index);
  211518. CFStringRef pname;
  211519. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211520. {
  211521. log (T("CoreMidi - opening out: ") + PlatformUtilities::cfStringToJuceString (pname));
  211522. if (makeSureClientExists())
  211523. {
  211524. MIDIPortRef port;
  211525. if (OK (MIDIOutputPortCreate (globalMidiClient, pname, &port)))
  211526. {
  211527. mo = new MidiOutput();
  211528. mo->internal = (void*) new MidiPortAndEndpoint (port, endPoint);
  211529. }
  211530. }
  211531. CFRelease (pname);
  211532. }
  211533. }
  211534. return mo;
  211535. }
  211536. MidiOutput* MidiOutput::createNewDevice (const String& deviceName)
  211537. {
  211538. MidiOutput* mo = 0;
  211539. if (makeSureClientExists())
  211540. {
  211541. MIDIEndpointRef endPoint;
  211542. CFStringRef name = PlatformUtilities::juceStringToCFString (deviceName);
  211543. if (OK (MIDISourceCreate (globalMidiClient, name, &endPoint)))
  211544. {
  211545. mo = new MidiOutput();
  211546. mo->internal = (void*) new MidiPortAndEndpoint (0, endPoint);
  211547. }
  211548. CFRelease (name);
  211549. }
  211550. return mo;
  211551. }
  211552. MidiOutput::~MidiOutput()
  211553. {
  211554. delete (MidiPortAndEndpoint*) internal;
  211555. }
  211556. void MidiOutput::reset()
  211557. {
  211558. }
  211559. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211560. {
  211561. return false;
  211562. }
  211563. void MidiOutput::setVolume (float leftVol, float rightVol)
  211564. {
  211565. }
  211566. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211567. {
  211568. MidiPortAndEndpoint* const mpe = (MidiPortAndEndpoint*) internal;
  211569. if (message.isSysEx())
  211570. {
  211571. const int maxPacketSize = 256;
  211572. int pos = 0, bytesLeft = message.getRawDataSize();
  211573. const int numPackets = (bytesLeft + maxPacketSize - 1) / maxPacketSize;
  211574. HeapBlock <MIDIPacketList> packets;
  211575. packets.malloc (32 * numPackets + message.getRawDataSize(), 1);
  211576. packets->numPackets = numPackets;
  211577. MIDIPacket* p = packets->packet;
  211578. for (int i = 0; i < numPackets; ++i)
  211579. {
  211580. p->timeStamp = 0;
  211581. p->length = jmin (maxPacketSize, bytesLeft);
  211582. memcpy (p->data, message.getRawData() + pos, p->length);
  211583. pos += p->length;
  211584. bytesLeft -= p->length;
  211585. p = MIDIPacketNext (p);
  211586. }
  211587. if (mpe->port != 0)
  211588. MIDISend (mpe->port, mpe->endPoint, packets);
  211589. else
  211590. MIDIReceived (mpe->endPoint, packets);
  211591. }
  211592. else
  211593. {
  211594. MIDIPacketList packets;
  211595. packets.numPackets = 1;
  211596. packets.packet[0].timeStamp = 0;
  211597. packets.packet[0].length = message.getRawDataSize();
  211598. *(int*) (packets.packet[0].data) = *(const int*) message.getRawData();
  211599. if (mpe->port != 0)
  211600. MIDISend (mpe->port, mpe->endPoint, &packets);
  211601. else
  211602. MIDIReceived (mpe->endPoint, &packets);
  211603. }
  211604. }
  211605. const StringArray MidiInput::getDevices()
  211606. {
  211607. StringArray s;
  211608. const ItemCount num = MIDIGetNumberOfSources();
  211609. for (ItemCount i = 0; i < num; ++i)
  211610. {
  211611. MIDIEndpointRef source = MIDIGetSource (i);
  211612. if (source != 0)
  211613. {
  211614. String name (getConnectedEndpointName (source));
  211615. if (name.isEmpty())
  211616. name = "<error>";
  211617. s.add (name);
  211618. }
  211619. else
  211620. {
  211621. s.add ("<error>");
  211622. }
  211623. }
  211624. return s;
  211625. }
  211626. int MidiInput::getDefaultDeviceIndex()
  211627. {
  211628. return 0;
  211629. }
  211630. struct MidiPortAndCallback
  211631. {
  211632. MidiInput* input;
  211633. MidiPortAndEndpoint* portAndEndpoint;
  211634. MidiInputCallback* callback;
  211635. MemoryBlock pendingData;
  211636. int pendingBytes;
  211637. double pendingDataTime;
  211638. bool active;
  211639. void processSysex (const uint8*& d, int& size, const double time)
  211640. {
  211641. if (*d == 0xf0)
  211642. {
  211643. pendingBytes = 0;
  211644. pendingDataTime = time;
  211645. }
  211646. pendingData.ensureSize (pendingBytes + size, false);
  211647. uint8* totalMessage = (uint8*) pendingData.getData();
  211648. uint8* dest = totalMessage + pendingBytes;
  211649. while (size > 0)
  211650. {
  211651. if (pendingBytes > 0 && *d >= 0x80)
  211652. {
  211653. if (*d >= 0xfa || *d == 0xf8)
  211654. {
  211655. callback->handleIncomingMidiMessage (input, MidiMessage (*d, time));
  211656. ++d;
  211657. --size;
  211658. }
  211659. else
  211660. {
  211661. if (*d == 0xf7)
  211662. {
  211663. *dest++ = *d++;
  211664. pendingBytes++;
  211665. --size;
  211666. }
  211667. break;
  211668. }
  211669. }
  211670. else
  211671. {
  211672. *dest++ = *d++;
  211673. pendingBytes++;
  211674. --size;
  211675. }
  211676. }
  211677. if (totalMessage [pendingBytes - 1] == 0xf7)
  211678. {
  211679. callback->handleIncomingMidiMessage (input, MidiMessage (totalMessage, pendingBytes, pendingDataTime));
  211680. pendingBytes = 0;
  211681. }
  211682. else
  211683. {
  211684. callback->handlePartialSysexMessage (input, totalMessage, pendingBytes, pendingDataTime);
  211685. }
  211686. }
  211687. };
  211688. namespace CoreMidiCallbacks
  211689. {
  211690. static CriticalSection callbackLock;
  211691. static VoidArray activeCallbacks;
  211692. }
  211693. static void midiInputProc (const MIDIPacketList* pktlist,
  211694. void* readProcRefCon,
  211695. void* srcConnRefCon)
  211696. {
  211697. double time = Time::getMillisecondCounterHiRes() * 0.001;
  211698. const double originalTime = time;
  211699. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) readProcRefCon;
  211700. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211701. if (CoreMidiCallbacks::activeCallbacks.contains (mpc) && mpc->active)
  211702. {
  211703. const MIDIPacket* packet = &pktlist->packet[0];
  211704. for (unsigned int i = 0; i < pktlist->numPackets; ++i)
  211705. {
  211706. const uint8* d = (const uint8*) (packet->data);
  211707. int size = packet->length;
  211708. while (size > 0)
  211709. {
  211710. time = originalTime;
  211711. if (mpc->pendingBytes > 0 || d[0] == 0xf0)
  211712. {
  211713. mpc->processSysex (d, size, time);
  211714. }
  211715. else
  211716. {
  211717. int used = 0;
  211718. const MidiMessage m (d, size, used, 0, time);
  211719. if (used <= 0)
  211720. {
  211721. jassertfalse // malformed midi message
  211722. break;
  211723. }
  211724. else
  211725. {
  211726. mpc->callback->handleIncomingMidiMessage (mpc->input, m);
  211727. }
  211728. size -= used;
  211729. d += used;
  211730. }
  211731. }
  211732. packet = MIDIPacketNext (packet);
  211733. }
  211734. }
  211735. }
  211736. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211737. {
  211738. MidiInput* mi = 0;
  211739. if (((unsigned int) index) < (unsigned int) MIDIGetNumberOfSources())
  211740. {
  211741. MIDIEndpointRef endPoint = MIDIGetSource (index);
  211742. if (endPoint != 0)
  211743. {
  211744. CFStringRef pname;
  211745. if (OK (MIDIObjectGetStringProperty (endPoint, kMIDIPropertyName, &pname)))
  211746. {
  211747. log (T("CoreMidi - opening inp: ") + PlatformUtilities::cfStringToJuceString (pname));
  211748. if (makeSureClientExists())
  211749. {
  211750. MIDIPortRef port;
  211751. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211752. mpc->active = false;
  211753. if (OK (MIDIInputPortCreate (globalMidiClient, pname, midiInputProc, mpc, &port)))
  211754. {
  211755. if (OK (MIDIPortConnectSource (port, endPoint, 0)))
  211756. {
  211757. mpc->portAndEndpoint = new MidiPortAndEndpoint (port, endPoint);
  211758. mpc->callback = callback;
  211759. mpc->pendingBytes = 0;
  211760. mpc->pendingData.ensureSize (128);
  211761. mi = new MidiInput (getDevices() [index]);
  211762. mpc->input = mi;
  211763. mi->internal = (void*) mpc;
  211764. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211765. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211766. }
  211767. else
  211768. {
  211769. OK (MIDIPortDispose (port));
  211770. }
  211771. }
  211772. }
  211773. }
  211774. CFRelease (pname);
  211775. }
  211776. }
  211777. return mi;
  211778. }
  211779. MidiInput* MidiInput::createNewDevice (const String& deviceName, MidiInputCallback* callback)
  211780. {
  211781. MidiInput* mi = 0;
  211782. if (makeSureClientExists())
  211783. {
  211784. ScopedPointer <MidiPortAndCallback> mpc (new MidiPortAndCallback());
  211785. mpc->active = false;
  211786. MIDIEndpointRef endPoint;
  211787. CFStringRef name = PlatformUtilities::juceStringToCFString(deviceName);
  211788. if (OK (MIDIDestinationCreate (globalMidiClient, name, midiInputProc, mpc, &endPoint)))
  211789. {
  211790. mpc->portAndEndpoint = new MidiPortAndEndpoint (0, endPoint);
  211791. mpc->callback = callback;
  211792. mpc->pendingBytes = 0;
  211793. mpc->pendingData.ensureSize (128);
  211794. mi = new MidiInput (deviceName);
  211795. mpc->input = mi;
  211796. mi->internal = (void*) mpc;
  211797. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211798. CoreMidiCallbacks::activeCallbacks.add (mpc.release());
  211799. }
  211800. CFRelease (name);
  211801. }
  211802. return mi;
  211803. }
  211804. MidiInput::MidiInput (const String& name_)
  211805. : name (name_)
  211806. {
  211807. }
  211808. MidiInput::~MidiInput()
  211809. {
  211810. MidiPortAndCallback* const mpc = (MidiPortAndCallback*) internal;
  211811. mpc->active = false;
  211812. {
  211813. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211814. CoreMidiCallbacks::activeCallbacks.removeValue (mpc);
  211815. }
  211816. if (mpc->portAndEndpoint->port != 0)
  211817. OK (MIDIPortDisconnectSource (mpc->portAndEndpoint->port, mpc->portAndEndpoint->endPoint));
  211818. delete mpc->portAndEndpoint;
  211819. delete mpc;
  211820. }
  211821. void MidiInput::start()
  211822. {
  211823. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211824. ((MidiPortAndCallback*) internal)->active = true;
  211825. }
  211826. void MidiInput::stop()
  211827. {
  211828. const ScopedLock sl (CoreMidiCallbacks::callbackLock);
  211829. ((MidiPortAndCallback*) internal)->active = false;
  211830. }
  211831. #undef log
  211832. #else
  211833. MidiOutput::~MidiOutput()
  211834. {
  211835. }
  211836. void MidiOutput::reset()
  211837. {
  211838. }
  211839. bool MidiOutput::getVolume (float& leftVol, float& rightVol)
  211840. {
  211841. return false;
  211842. }
  211843. void MidiOutput::setVolume (float leftVol, float rightVol)
  211844. {
  211845. }
  211846. void MidiOutput::sendMessageNow (const MidiMessage& message)
  211847. {
  211848. }
  211849. const StringArray MidiOutput::getDevices()
  211850. {
  211851. return StringArray();
  211852. }
  211853. MidiOutput* MidiOutput::openDevice (int index)
  211854. {
  211855. return 0;
  211856. }
  211857. const StringArray MidiInput::getDevices()
  211858. {
  211859. return StringArray();
  211860. }
  211861. MidiInput* MidiInput::openDevice (int index, MidiInputCallback* callback)
  211862. {
  211863. return 0;
  211864. }
  211865. #endif
  211866. #endif
  211867. /*** End of inlined file: juce_mac_CoreMidi.cpp ***/
  211868. /*** Start of inlined file: juce_mac_CameraDevice.mm ***/
  211869. // (This file gets included by juce_mac_NativeCode.mm, rather than being
  211870. // compiled on its own).
  211871. #if JUCE_INCLUDED_FILE && JUCE_QUICKTIME && JUCE_USE_CAMERA
  211872. #define QTCaptureCallbackDelegate MakeObjCClassName(QTCaptureCallbackDelegate)
  211873. class QTCameraDeviceInteral;
  211874. END_JUCE_NAMESPACE
  211875. @interface QTCaptureCallbackDelegate : NSObject
  211876. {
  211877. @public
  211878. CameraDevice* owner;
  211879. QTCameraDeviceInteral* internal;
  211880. int64 firstPresentationTime;
  211881. int64 averageTimeOffset;
  211882. }
  211883. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner internalDev: (QTCameraDeviceInteral*) d;
  211884. - (void) dealloc;
  211885. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  211886. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  211887. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211888. fromConnection: (QTCaptureConnection*) connection;
  211889. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  211890. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  211891. fromConnection: (QTCaptureConnection*) connection;
  211892. @end
  211893. BEGIN_JUCE_NAMESPACE
  211894. class QTCameraDeviceInteral
  211895. {
  211896. public:
  211897. QTCameraDeviceInteral (CameraDevice* owner, int index)
  211898. {
  211899. const ScopedAutoReleasePool pool;
  211900. session = [[QTCaptureSession alloc] init];
  211901. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  211902. device = (QTCaptureDevice*) [devs objectAtIndex: index];
  211903. input = 0;
  211904. audioInput = 0;
  211905. audioDevice = 0;
  211906. fileOutput = 0;
  211907. imageOutput = 0;
  211908. callbackDelegate = [[QTCaptureCallbackDelegate alloc] initWithOwner: owner
  211909. internalDev: this];
  211910. NSError* err = 0;
  211911. [device retain];
  211912. [device open: &err];
  211913. if (err == 0)
  211914. {
  211915. input = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211916. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: device];
  211917. [session addInput: input error: &err];
  211918. if (err == 0)
  211919. {
  211920. resetFile();
  211921. imageOutput = [[QTCaptureDecompressedVideoOutput alloc] init];
  211922. [imageOutput setDelegate: callbackDelegate];
  211923. if (err == 0)
  211924. {
  211925. [session startRunning];
  211926. return;
  211927. }
  211928. }
  211929. }
  211930. openingError = nsStringToJuce ([err description]);
  211931. DBG (openingError);
  211932. }
  211933. ~QTCameraDeviceInteral()
  211934. {
  211935. [session stopRunning];
  211936. [session removeOutput: imageOutput];
  211937. [session release];
  211938. [input release];
  211939. [device release];
  211940. [audioDevice release];
  211941. [audioInput release];
  211942. [fileOutput release];
  211943. [imageOutput release];
  211944. [callbackDelegate release];
  211945. }
  211946. void resetFile()
  211947. {
  211948. [fileOutput recordToOutputFileURL: nil];
  211949. [session removeOutput: fileOutput];
  211950. [fileOutput release];
  211951. fileOutput = [[QTCaptureMovieFileOutput alloc] init];
  211952. [session removeInput: audioInput];
  211953. [audioInput release];
  211954. audioInput = 0;
  211955. [audioDevice release];
  211956. audioDevice = 0;
  211957. [fileOutput setDelegate: callbackDelegate];
  211958. }
  211959. void addDefaultAudioInput()
  211960. {
  211961. NSError* err = nil;
  211962. audioDevice = [QTCaptureDevice defaultInputDeviceWithMediaType: QTMediaTypeSound];
  211963. if ([audioDevice open: &err])
  211964. [audioDevice retain];
  211965. else
  211966. audioDevice = nil;
  211967. if (audioDevice != 0)
  211968. {
  211969. audioInput = [[QTCaptureDeviceInput alloc] initWithDevice: audioDevice];
  211970. [session addInput: audioInput error: &err];
  211971. }
  211972. }
  211973. void addListener (CameraImageListener* listenerToAdd)
  211974. {
  211975. const ScopedLock sl (listenerLock);
  211976. if (listeners.size() == 0)
  211977. [session addOutput: imageOutput error: nil];
  211978. listeners.addIfNotAlreadyThere (listenerToAdd);
  211979. }
  211980. void removeListener (CameraImageListener* listenerToRemove)
  211981. {
  211982. const ScopedLock sl (listenerLock);
  211983. listeners.removeValue (listenerToRemove);
  211984. if (listeners.size() == 0)
  211985. [session removeOutput: imageOutput];
  211986. }
  211987. void callListeners (CIImage* frame, int w, int h)
  211988. {
  211989. CoreGraphicsImage image (Image::ARGB, w, h, false);
  211990. CIContext* cic = [CIContext contextWithCGContext: image.context options: nil];
  211991. [cic drawImage: frame inRect: CGRectMake (0, 0, w, h) fromRect: CGRectMake (0, 0, w, h)];
  211992. CGContextFlush (image.context);
  211993. const ScopedLock sl (listenerLock);
  211994. for (int i = listeners.size(); --i >= 0;)
  211995. {
  211996. CameraImageListener* l = (CameraImageListener*) listeners[i];
  211997. if (l != 0)
  211998. l->imageReceived (image);
  211999. }
  212000. }
  212001. QTCaptureDevice* device;
  212002. QTCaptureDeviceInput* input;
  212003. QTCaptureDevice* audioDevice;
  212004. QTCaptureDeviceInput* audioInput;
  212005. QTCaptureSession* session;
  212006. QTCaptureMovieFileOutput* fileOutput;
  212007. QTCaptureDecompressedVideoOutput* imageOutput;
  212008. QTCaptureCallbackDelegate* callbackDelegate;
  212009. String openingError;
  212010. VoidArray listeners;
  212011. CriticalSection listenerLock;
  212012. };
  212013. END_JUCE_NAMESPACE
  212014. @implementation QTCaptureCallbackDelegate
  212015. - (QTCaptureCallbackDelegate*) initWithOwner: (CameraDevice*) owner_
  212016. internalDev: (QTCameraDeviceInteral*) d
  212017. {
  212018. [super init];
  212019. owner = owner_;
  212020. internal = d;
  212021. firstPresentationTime = 0;
  212022. averageTimeOffset = 0;
  212023. return self;
  212024. }
  212025. - (void) dealloc
  212026. {
  212027. [super dealloc];
  212028. }
  212029. - (void) captureOutput: (QTCaptureOutput*) captureOutput
  212030. didOutputVideoFrame: (CVImageBufferRef) videoFrame
  212031. withSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212032. fromConnection: (QTCaptureConnection*) connection
  212033. {
  212034. if (internal->listeners.size() > 0)
  212035. {
  212036. const ScopedAutoReleasePool pool;
  212037. internal->callListeners ([CIImage imageWithCVImageBuffer: videoFrame],
  212038. CVPixelBufferGetWidth (videoFrame),
  212039. CVPixelBufferGetHeight (videoFrame));
  212040. }
  212041. }
  212042. - (void) captureOutput: (QTCaptureFileOutput*) captureOutput
  212043. didOutputSampleBuffer: (QTSampleBuffer*) sampleBuffer
  212044. fromConnection: (QTCaptureConnection*) connection
  212045. {
  212046. const Time now (Time::getCurrentTime());
  212047. int64 presentationTime = ([sampleBuffer presentationTime].timeValue * 1000) / [sampleBuffer presentationTime].timeScale;
  212048. #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
  212049. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: QTSampleBufferHostTimeAttribute];
  212050. #else
  212051. NSNumber* hosttime = (NSNumber*) [sampleBuffer attributeForKey: @"hostTime"];
  212052. #endif
  212053. if (hosttime != nil)
  212054. presentationTime = (int64) AudioConvertHostTimeToNanos ([hosttime unsignedLongLongValue]) / 1000000;
  212055. const int64 timeDiff = now.toMilliseconds() - presentationTime - 50;
  212056. if (firstPresentationTime == 0)
  212057. {
  212058. firstPresentationTime = presentationTime;
  212059. averageTimeOffset = timeDiff;
  212060. }
  212061. else
  212062. {
  212063. averageTimeOffset = (averageTimeOffset * 120 + timeDiff * 8) / 128;
  212064. }
  212065. }
  212066. @end
  212067. BEGIN_JUCE_NAMESPACE
  212068. class QTCaptureViewerComp : public NSViewComponent
  212069. {
  212070. public:
  212071. QTCaptureViewerComp (CameraDevice* const cameraDevice, QTCameraDeviceInteral* const internal)
  212072. {
  212073. const ScopedAutoReleasePool pool;
  212074. captureView = [[QTCaptureView alloc] init];
  212075. [captureView setCaptureSession: internal->session];
  212076. setSize (640, 480); // xxx need to somehow get the movie size - how?
  212077. setView (captureView);
  212078. }
  212079. ~QTCaptureViewerComp()
  212080. {
  212081. setView (0);
  212082. [captureView setCaptureSession: nil];
  212083. [captureView release];
  212084. }
  212085. QTCaptureView* captureView;
  212086. };
  212087. CameraDevice::CameraDevice (const String& name_, int index)
  212088. : name (name_)
  212089. {
  212090. isRecording = false;
  212091. QTCameraDeviceInteral* d = new QTCameraDeviceInteral (this, index);
  212092. internal = d;
  212093. }
  212094. CameraDevice::~CameraDevice()
  212095. {
  212096. stopRecording();
  212097. delete (QTCameraDeviceInteral*) internal;
  212098. internal = 0;
  212099. }
  212100. Component* CameraDevice::createViewerComponent()
  212101. {
  212102. return new QTCaptureViewerComp (this, (QTCameraDeviceInteral*) internal);
  212103. }
  212104. const String CameraDevice::getFileExtension()
  212105. {
  212106. return ".mov";
  212107. }
  212108. void CameraDevice::startRecordingToFile (const File& file, int quality)
  212109. {
  212110. stopRecording();
  212111. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212112. d->callbackDelegate->firstPresentationTime = 0;
  212113. file.deleteFile();
  212114. // In some versions of QT (e.g. on 10.5), if you record video without audio, the speed comes
  212115. // out wrong, so we'll put some audio in there too..,
  212116. d->addDefaultAudioInput();
  212117. [d->session addOutput: d->fileOutput error: nil];
  212118. NSEnumerator* connectionEnumerator = [[d->fileOutput connections] objectEnumerator];
  212119. for (;;)
  212120. {
  212121. QTCaptureConnection* connection = [connectionEnumerator nextObject];
  212122. if (connection == 0)
  212123. break;
  212124. QTCompressionOptions* options = 0;
  212125. NSString* mediaType = [connection mediaType];
  212126. if ([mediaType isEqualToString: QTMediaTypeVideo])
  212127. options = [QTCompressionOptions compressionOptionsWithIdentifier:
  212128. quality >= 1 ? @"QTCompressionOptionsSD480SizeH264Video"
  212129. : @"QTCompressionOptions240SizeH264Video"];
  212130. else if ([mediaType isEqualToString: QTMediaTypeSound])
  212131. options = [QTCompressionOptions compressionOptionsWithIdentifier: @"QTCompressionOptionsHighQualityAACAudio"];
  212132. [d->fileOutput setCompressionOptions: options forConnection: connection];
  212133. }
  212134. [d->fileOutput recordToOutputFileURL: [NSURL fileURLWithPath: juceStringToNS (file.getFullPathName())]];
  212135. isRecording = true;
  212136. }
  212137. const Time CameraDevice::getTimeOfFirstRecordedFrame() const
  212138. {
  212139. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212140. if (d->callbackDelegate->firstPresentationTime != 0)
  212141. return Time (d->callbackDelegate->firstPresentationTime + d->callbackDelegate->averageTimeOffset);
  212142. return Time();
  212143. }
  212144. void CameraDevice::stopRecording()
  212145. {
  212146. if (isRecording)
  212147. {
  212148. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212149. d->resetFile();
  212150. isRecording = false;
  212151. }
  212152. }
  212153. void CameraDevice::addListener (CameraImageListener* listenerToAdd)
  212154. {
  212155. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212156. if (listenerToAdd != 0)
  212157. d->addListener (listenerToAdd);
  212158. }
  212159. void CameraDevice::removeListener (CameraImageListener* listenerToRemove)
  212160. {
  212161. QTCameraDeviceInteral* const d = (QTCameraDeviceInteral*) internal;
  212162. if (listenerToRemove != 0)
  212163. d->removeListener (listenerToRemove);
  212164. }
  212165. const StringArray CameraDevice::getAvailableDevices()
  212166. {
  212167. const ScopedAutoReleasePool pool;
  212168. StringArray results;
  212169. NSArray* devs = [QTCaptureDevice inputDevicesWithMediaType: QTMediaTypeVideo];
  212170. for (int i = 0; i < (int) [devs count]; ++i)
  212171. {
  212172. QTCaptureDevice* dev = (QTCaptureDevice*) [devs objectAtIndex: i];
  212173. results.add (nsStringToJuce ([dev localizedDisplayName]));
  212174. }
  212175. return results;
  212176. }
  212177. CameraDevice* CameraDevice::openDevice (int index,
  212178. int minWidth, int minHeight,
  212179. int maxWidth, int maxHeight)
  212180. {
  212181. ScopedPointer <CameraDevice> d (new CameraDevice (getAvailableDevices() [index], index));
  212182. if (((QTCameraDeviceInteral*) (d->internal))->openingError.isEmpty())
  212183. return d.release();
  212184. return 0;
  212185. }
  212186. #endif
  212187. /*** End of inlined file: juce_mac_CameraDevice.mm ***/
  212188. #endif
  212189. #endif
  212190. END_JUCE_NAMESPACE
  212191. /*** End of inlined file: juce_mac_NativeCode.mm ***/
  212192. #endif
  212193. #endif